From 718eaab1236352d0cb1c1eef26ea6cf29a8f725b Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 25 Dec 2022 16:29:10 -0800 Subject: [PATCH 001/709] added func for watchdog name, created watchdog instance class --- org.lflang/src/org/lflang/LinguaFranca.xtext | 8 ++- .../lflang/generator/ReactionInstance.java | 6 ++ .../lflang/generator/WatchdogInstance.java | 59 +++++++++++++++++++ .../generator/c/CReactionGenerator.java | 11 ++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 org.lflang/src/org/lflang/generator/WatchdogInstance.java diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 38dc520c0b..c28f35065e 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -201,7 +201,8 @@ Reaction: ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? code=Code (stp=STP)? - (deadline=Deadline)?; + (deadline=Deadline)? + (watchdog=Watchdog)?; TriggerRef: BuiltinTriggerRef | VarRef; @@ -211,6 +212,9 @@ BuiltinTriggerRef: Deadline: 'deadline' '(' delay=Expression ')' code=Code; + +Watchdog: + 'watchdog' nameID=Expression '(' delay=Expression ')' code=Code; STP: 'STP' '(' value=Expression ')' code=Code; @@ -486,7 +490,7 @@ Token: 'mutable' | 'input' | 'output' | 'timer' | 'action' | 'reaction' | 'startup' | 'shutdown' | 'after' | 'deadline' | 'mutation' | 'preamble' | 'new' | 'federated' | 'at' | 'as' | 'from' | 'widthof' | 'const' | 'method' | - 'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | + 'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' // Other terminals NEGINT | TRUE | FALSE | // Action origins diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index f20962d70d..737d814049 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -223,6 +223,12 @@ public ReactionInstance( */ public DeadlineInstance declaredDeadline; + //FIXME: modif4watchdog + /** + * Watchdog for this reaction instance, if declared. + */ + public WatchdogInstance declaredWatchdog; + /** * Inferred deadline. Defaults to the maximum long value. */ diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java new file mode 100644 index 0000000000..40b02edd66 --- /dev/null +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -0,0 +1,59 @@ +package org.lflang.generator; + +import org.lflang.TimeValue; +import org.lflang.lf.Watchdog; + +/** + * Instance of a watchdog. Upon creation the actual delay is converted into + * a proper time value. If a parameter is referenced, it is looked up in the + * given (grand)parent reactor instance. + * + * @author{Benjamin Asch } + */ +//FIXME: modif4watchdogs +public class WatchdogInstance { + + /** + * Create a new watchdog instance associated with the given reaction + * instance. + */ + public WatchdogInstance(Watchdog definition, ReactionInstance reaction) { + if (definition.getTimeout() != null) { + this.timeout = reaction.parent.getTimeValue(definition.getTimeout()); + } else { + this.timeout = TimeValue.ZERO; + } + + if (definition.getCode() != null) { + this.watchdogHandler = definition.getCode(); + } else { + this.watchdogHandler = new CodeBuilder(); + } + } + + ////////////////////////////////////////////////////// + //// Public fields. + + /** + * The timeout, L, associated with this deadline. The physical timer gets set + * to expire at physical time, P, equal to the current logical time, t, plus the timeout. + * + * In other words, the watchdog condition is met iff P < t + L while the watchdog has not + * been stopped or reset. + */ + public final TimeValue timeout; + + /** + * The code body for the function that is executed upon calling the watchdog. + */ + public final CodeBuilder watchdogHandler; + + ////////////////////////////////////////////////////// + //// Public methods. + + //FIXME: unsure of use or need for watchdogs + @Override + public String toString() { + return "WatchdogInstance " + timeout.toString(); + } +} diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index cac6594edc..3fa09cb494 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1132,6 +1132,17 @@ public static String generateFunction(String header, String init, Code code) { return function.toString(); } + // FIXME: modif4watchdogs + /** + * Returns the name of the watchdog function for reaction. + * @param decl The reactor with the watchdog + * @param reactionIndex The number assigned to this reaction watchdog + * @return Name of the watchdog function for reaction + */ + public static String generateWatchdogFunctionName(ReactorDecl decl, int reactionIndex) { + return decl.getName().toLowerCase() + "_watchdog_function" + reactionIndex; + } + /** * Returns the name of the deadline function for reaction. * @param decl The reactor with the deadline From 43bb491830d62be9c3747aafc17a219a4f1d3fed Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 5 Jan 2023 00:01:10 -0800 Subject: [PATCH 002/709] made some progress on code generation --- .../src/org/lflang/generator/WatchdogInstance.java | 3 +++ org.lflang/src/org/lflang/generator/c/CGenerator.java | 5 +++++ .../src/org/lflang/generator/c/CReactionGenerator.java | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 40b02edd66..290c7144a9 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -11,6 +11,7 @@ * @author{Benjamin Asch } */ //FIXME: modif4watchdogs +//FIXME: functions in constructor not defined public class WatchdogInstance { /** @@ -29,6 +30,8 @@ public WatchdogInstance(Watchdog definition, ReactionInstance reaction) { } else { this.watchdogHandler = new CodeBuilder(); } + + this.name = definition.getName(); } ////////////////////////////////////////////////////// diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index ec2b7986c3..6913d7bed7 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -929,6 +929,11 @@ private boolean hasDeadlines(List reactors) { return false; } + //FIXME: modif4watchdogs + private boolean hasWatchdogs(List reactors) { + + } + /** * Look at the 'reactor' eResource. * If it is an imported .lf file, incorporate it into the current diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 3fa09cb494..5f017e89a2 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -759,6 +759,14 @@ public static void generateReactionAndTriggerStructs( deadlineFunctionPointer = "&" + deadlineFunctionName; } + // FIXME: modif4watchdogs + // FIXME: '.getWatchdog()' not implemented + var watchdogFunctionPointer = "NULL"; + if (reaction.getWatchdog() != null) { + var watchdogFunctionName = generateWatchdogFunctionName(decl, reactionCount); + watchdogFunctionPointer = "&" + watchdogFunctionName; + } + // Assign the STP handler var STPFunctionPointer = "NULL"; if (reaction.getStp() != null) { @@ -780,6 +788,7 @@ public static void generateReactionAndTriggerStructs( "self->_lf__reaction_"+reactionCount+".function = "+ CReactionGenerator.generateReactionFunctionName(decl, reactionCount)+";", "self->_lf__reaction_"+reactionCount+".self = self;", "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", + "self->_lf__reaction_"+reactionCount+".watchdog_handler = "+watchdogFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", (reaction.eContainer() instanceof Mode ? From 20531f07fd21ebbfbf4fa904d347b1858d54e983 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 5 Jan 2023 12:48:54 -0800 Subject: [PATCH 003/709] more functions added for code generation --- org.lflang/src/org/lflang/ASTUtils.java | 13 ++++++++ .../lflang/generator/ReactionInstance.java | 8 +++++ .../org/lflang/generator/c/CGenerator.java | 10 ++++-- .../generator/c/CReactionGenerator.java | 31 +++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index dc15877879..181eb5c81a 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -144,6 +144,19 @@ public static Iterable getAllReactors(Resource resource) { .collect(Collectors.toList()); } + /** + * Get all watchdogs defined in the given resource. + * @param resource the resource to extract watchdogs from + * @return An iterable over all watchdogs found in the resource + */ + //FIXME: modif4watchdogs + public static Iterable getAllWatchdogs(Resource resource) { + return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) + .filter(Watchdog.class::isInstance) + .map(Watchdog.class::cast) + .collect(Collectors.toList()); + } + /** * Find connections in the given resource that have a delay associated with them, * and reroute them via a generated delay reactor. diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index 737d814049..b7fffe132f 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -187,6 +187,14 @@ public ReactionInstance( this.declaredDeadline = new DeadlineInstance( this.definition.getDeadline(), this); } + + //FIXME: modif4watchdogs + // getWatchdog not implemented + // need to implement matching reaction output with watchdog + if (this.definition.getWatchdog() != null) { + this.declaredWatchdog = new WatchdogInstance( + this.definition.getWatchdog(), this); + } } ////////////////////////////////////////////////////// diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 6913d7bed7..d022942dce 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -930,8 +930,14 @@ private boolean hasDeadlines(List reactors) { } //FIXME: modif4watchdogs - private boolean hasWatchdogs(List reactors) { - + //FIXME: getWatchdog() has not been implemented + private boolean hasWatchdogs(Reactor reactor) { + for (Reaction reaction : allReactions(reactor)) { + if (reaction.getWatchdog() != null) { + return true; + } + } + return false; } /** diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 5f017e89a2..97f69baeae 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1005,6 +1005,16 @@ public static String generateLfTriggerStartupReactions(int startupReactionCount, return s.toString(); } + /** + * Generate _lf_initialize_watchdog_mutexes function. + */ + //FIXME: modif4watchdogs + //FIXME: finish implementing + public static String generateLfInitializeWatchdogMutexes(List reactors) { + // need to find way to assign get watchdog from AST + // need to assign watchdog to correct reaction + } + /** * Generate the _lf_trigger_shutdown_reactions function. */ @@ -1122,6 +1132,15 @@ public static String generateReaction( generateDeadlineFunctionHeader(decl, reactionIndex), init, reaction.getDeadline().getCode())); } + + // FIXME:modif4watchdogs + // Now generate code for the watchdog handler function, if there is one. + if (reaction.getWatchdog() != null) { + code.pr(generateFunction( + generateWatchdogFunctionHeader(decl, reactionIndex), + init, reaction.getWatchdog().getCode())); + } + CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(decl), code); code.pr( "#include " + StringUtil.addDoubleQuotes( @@ -1192,6 +1211,18 @@ public static String generateDeadlineFunctionHeader(ReactorDecl decl, return generateFunctionHeader(functionName); } + /** Return the top level C function header for the watchdog function numbered "reactionIndex" in "decl" + * @param decl The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the watchdog function. + */ + //FIXME: modif4watchdogs + public static String generateWatchdogFunctionHeader(ReactorDecl decl, + int reactionIndex) { + String functionName = generateWatchdogFunctionName(decl, reactionIndex); + return generateFunctionHeader(functionName); + } + /** Return the top level C function header for the reaction numbered "reactionIndex" in "decl" * @param decl The reactor declaration * @param reactionIndex The reaction index. From 371385e003015e3670546e23f6ebf3d469d53ffb Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 8 Jan 2023 11:28:32 -0800 Subject: [PATCH 004/709] saving progress before pushing --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++++ org.lflang/src/org/lflang/generator/c/CReactionGenerator.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index d022942dce..af62bd8b8f 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -840,6 +840,10 @@ private void generateCodeForCurrentFederate( // Generate function to schedule timers for all reactors. code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); + //FIXME:modif4watchdogs + // Generate function to initialize mutexes for all reactors with watchdogs. + code.pr(CReactionGenerator.generateLfInitializeWatchdogMutexes()); + // Generate a function that will either do nothing // (if there is only one federate or the coordination // is set to decentralized) or, if there are diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 97f69baeae..06bbaf853c 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1013,6 +1013,9 @@ public static String generateLfTriggerStartupReactions(int startupReactionCount, public static String generateLfInitializeWatchdogMutexes(List reactors) { // need to find way to assign get watchdog from AST // need to assign watchdog to correct reaction + var s = new StringBuilder(); + s.append("void _lf_initialize_watchdog_mutexes() {\n"); + } /** From 86c369d36b0736223789544361fa751d4cabe1bb Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 8 Jan 2023 14:55:02 -0800 Subject: [PATCH 005/709] fixed grammar(added watchdog to 'varreformodetransition', removed watchdog from reaction) --- org.lflang/src/org/lflang/LinguaFranca.xtext | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index c28f35065e..f39eb724cb 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -201,8 +201,7 @@ Reaction: ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? code=Code (stp=STP)? - (deadline=Deadline)? - (watchdog=Watchdog)?; + (deadline=Deadline)?; TriggerRef: BuiltinTriggerRef | VarRef; @@ -214,7 +213,7 @@ Deadline: 'deadline' '(' delay=Expression ')' code=Code; Watchdog: - 'watchdog' nameID=Expression '(' delay=Expression ')' code=Code; + 'watchdog' name=Expression '(' timeout=Expression ')' code=Code; STP: 'STP' '(' value=Expression ')' code=Code; @@ -283,7 +282,7 @@ VarRef: | interleaved?='interleaved' '(' (variable=[Variable] | container=[Instantiation] '.' variable=[Variable]) ')' ; VarRefOrModeTransition returns VarRef: - VarRef | transition=ModeTransition '(' variable=[Mode] ')'; + VarRef | Watchdog | transition=ModeTransition '(' variable=[Mode] ')'; Assignment: (lhs=[Parameter] ( From 15fc495b762139bbf327b2ba1698a695a0b5a453 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 8 Jan 2023 14:58:40 -0800 Subject: [PATCH 006/709] added watchdog grammar to reactor --- org.lflang/src/org/lflang/LinguaFranca.xtext | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index f39eb724cb..718382335d 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -91,6 +91,7 @@ Reactor: | (connections+=Connection) | (reactions+=Reaction) | (modes+=Mode) + (watchdogs+=Watchdog) )* '}'; From 6124cae9328288ce6bf8ee387997b44087681c86 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 12 Jan 2023 15:29:17 -0800 Subject: [PATCH 007/709] making sure updated before push --- org.lflang/src/org/lflang/ASTUtils.java | 28 ++-- org.lflang/src/org/lflang/LinguaFranca.xtext | 4 +- .../lflang/generator/ReactionInstance.java | 16 +- .../org/lflang/generator/ReactorInstance.java | 4 + .../org/lflang/generator/c/CGenerator.java | 19 ++- .../generator/c/CReactionGenerator.java | 89 +++++------ .../generator/c/CWatchdogGenerator.java | 140 ++++++++++++++++++ 7 files changed, 212 insertions(+), 88 deletions(-) create mode 100644 org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 181eb5c81a..b87dc94479 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -122,13 +122,16 @@ public class ASTUtils { /** * A mapping from Reactor features to corresponding Mode features for collecting contained elements. */ + //FIXME: modif4watchdogs + // added 'featurePackage.getReactor_Watchdogs' private static final Map reactorModeFeatureMap = Map.of( featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), - featurePackage.getReactor_Timers(), featurePackage.getMode_Timers() + featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), + featurePackage.getReactor_Watchdogs() ); @@ -144,19 +147,6 @@ public static Iterable getAllReactors(Resource resource) { .collect(Collectors.toList()); } - /** - * Get all watchdogs defined in the given resource. - * @param resource the resource to extract watchdogs from - * @return An iterable over all watchdogs found in the resource - */ - //FIXME: modif4watchdogs - public static Iterable getAllWatchdogs(Resource resource) { - return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) - .filter(Watchdog.class::isInstance) - .map(Watchdog.class::cast) - .collect(Collectors.toList()); - } - /** * Find connections in the given resource that have a delay associated with them, * and reroute them via a generated delay reactor. @@ -686,6 +676,16 @@ public static List allParameters(Reactor definition) { public static List allReactions(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); } + + /** + * Given a reactor class, return a list of all its watchdogs. + * @param definition Reactor class definition + * @return List + */ + // FIXME: modif4watchdogs + public static List allWatchdogs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); + } /** * Given a reactor class, return a list of all its state variables, diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 718382335d..e624e61c53 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -214,7 +214,9 @@ Deadline: 'deadline' '(' delay=Expression ')' code=Code; Watchdog: - 'watchdog' name=Expression '(' timeout=Expression ')' code=Code; + 'watchdog' name=Expression '(' timeout=Expression ')' + ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? + code=Code; STP: 'STP' '(' value=Expression ')' code=Code; diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index b7fffe132f..13dc1e1c52 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -187,14 +187,6 @@ public ReactionInstance( this.declaredDeadline = new DeadlineInstance( this.definition.getDeadline(), this); } - - //FIXME: modif4watchdogs - // getWatchdog not implemented - // need to implement matching reaction output with watchdog - if (this.definition.getWatchdog() != null) { - this.declaredWatchdog = new WatchdogInstance( - this.definition.getWatchdog(), this); - } } ////////////////////////////////////////////////////// @@ -230,13 +222,7 @@ public ReactionInstance( * Deadline for this reaction instance, if declared. */ public DeadlineInstance declaredDeadline; - - //FIXME: modif4watchdog - /** - * Watchdog for this reaction instance, if declared. - */ - public WatchdogInstance declaredWatchdog; - + /** * Inferred deadline. Defaults to the maximum long value. */ diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index ae953e9370..dbed569762 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -150,6 +150,10 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re /** List of reaction instances for this reactor instance. */ public final List reactions = new ArrayList<>(); + /** List of watchdog instances for this reactor instance. */ + //FIXME: modif4watchdogs + public final List watchdogs = new ArrayList<>(); + /** The timer instances belonging to this reactor instance. */ public final List timers = new ArrayList<>(); diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index af62bd8b8f..4579e32534 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -934,12 +934,9 @@ private boolean hasDeadlines(List reactors) { } //FIXME: modif4watchdogs - //FIXME: getWatchdog() has not been implemented private boolean hasWatchdogs(Reactor reactor) { - for (Reaction reaction : allReactions(reactor)) { - if (reaction.getWatchdog() != null) { - return true; - } + if (ASTUtils.allWatchdogs(reactor) != null) { + return true; } return false; } @@ -1532,6 +1529,18 @@ protected void generateSelfStructExtension( // Do nothing } + /** + * Generate watchdog functions definition for a reactor. + * @param decl The reactor + * @param federate The federate, or null if this is not + * federated or not the main reactor and watchdogs should be + * unconditionally generated. + */ + //FIXME: modif4watchdogs + public void generateWatchdogFunctions(ReactorDecl decl, FederateInstance federate) { + + } + /** Generate reaction functions definition for a reactor. * These functions have a single argument that is a void* pointing to * a struct that contains parameters, state variables, inputs (triggering or not), diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 06bbaf853c..f5aff5d55e 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -195,6 +195,15 @@ public static String generateInitializationForReaction(String body, effect.getContainer(), (Input) variable ); + } else if (variable instanceof Watchdog) { + //FIXME: modif4watchdogs + // How does it know if instance of watchdog? + reactionInitialization.pr(generateWatchdogVariablesInReaction( + effect, + decl, + errorReporter, + requiresTypes + )); } else { errorReporter.reportError( reaction, @@ -679,6 +688,31 @@ public static String generateOutputVariablesInReaction( } } + /** + * Generate into the specified string builder the code to + * initialize local variables for watchdogs in a reaction function + * from the "self" struct. + * @param effect The effect declared by the reaction. This must refer to a watchdog. + * @param decl The reactor containing the reaction or the import statement. + */ + //FIXME: modif4watchdogs + // Fine to have watchdog be in reactor self struct? + public static String generateWatchdogVariablesInReaction( + VarRef effect, + ReactorDecl decl, + ErrorReporter errorReporter, + boolean requiresTypes + ) { + Watchdog watchdog = (Watchdog) effect.getVariable(); + String watchdogName = watchdog.getName(); + if (watchdog.getType() == null && requiresTypes) { + errorReporter.reportError(watchdog, "Watchdog is required to have a type: " + watchdogName); + return ""; + } else { + return "watchdog_t* "+watchdogName+" = &self->_lf_watchdog_"+watchdogName+";"; + } + } + /** * Generate the fields of the self struct and statements for the constructor * to create and initialize a reaction_t struct for each reaction in the @@ -759,14 +793,6 @@ public static void generateReactionAndTriggerStructs( deadlineFunctionPointer = "&" + deadlineFunctionName; } - // FIXME: modif4watchdogs - // FIXME: '.getWatchdog()' not implemented - var watchdogFunctionPointer = "NULL"; - if (reaction.getWatchdog() != null) { - var watchdogFunctionName = generateWatchdogFunctionName(decl, reactionCount); - watchdogFunctionPointer = "&" + watchdogFunctionName; - } - // Assign the STP handler var STPFunctionPointer = "NULL"; if (reaction.getStp() != null) { @@ -1005,19 +1031,6 @@ public static String generateLfTriggerStartupReactions(int startupReactionCount, return s.toString(); } - /** - * Generate _lf_initialize_watchdog_mutexes function. - */ - //FIXME: modif4watchdogs - //FIXME: finish implementing - public static String generateLfInitializeWatchdogMutexes(List reactors) { - // need to find way to assign get watchdog from AST - // need to assign watchdog to correct reaction - var s = new StringBuilder(); - s.append("void _lf_initialize_watchdog_mutexes() {\n"); - - } - /** * Generate the _lf_trigger_shutdown_reactions function. */ @@ -1136,14 +1149,6 @@ public static String generateReaction( init, reaction.getDeadline().getCode())); } - // FIXME:modif4watchdogs - // Now generate code for the watchdog handler function, if there is one. - if (reaction.getWatchdog() != null) { - code.pr(generateFunction( - generateWatchdogFunctionHeader(decl, reactionIndex), - init, reaction.getWatchdog().getCode())); - } - CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(decl), code); code.pr( "#include " + StringUtil.addDoubleQuotes( @@ -1163,17 +1168,6 @@ public static String generateFunction(String header, String init, Code code) { return function.toString(); } - // FIXME: modif4watchdogs - /** - * Returns the name of the watchdog function for reaction. - * @param decl The reactor with the watchdog - * @param reactionIndex The number assigned to this reaction watchdog - * @return Name of the watchdog function for reaction - */ - public static String generateWatchdogFunctionName(ReactorDecl decl, int reactionIndex) { - return decl.getName().toLowerCase() + "_watchdog_function" + reactionIndex; - } - /** * Returns the name of the deadline function for reaction. * @param decl The reactor with the deadline @@ -1214,18 +1208,6 @@ public static String generateDeadlineFunctionHeader(ReactorDecl decl, return generateFunctionHeader(functionName); } - /** Return the top level C function header for the watchdog function numbered "reactionIndex" in "decl" - * @param decl The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the watchdog function. - */ - //FIXME: modif4watchdogs - public static String generateWatchdogFunctionHeader(ReactorDecl decl, - int reactionIndex) { - String functionName = generateWatchdogFunctionName(decl, reactionIndex); - return generateFunctionHeader(functionName); - } - /** Return the top level C function header for the reaction numbered "reactionIndex" in "decl" * @param decl The reactor declaration * @param reactionIndex The reaction index. @@ -1243,7 +1225,8 @@ public static String generateStpFunctionHeader(ReactorDecl decl, return generateFunctionHeader(functionName); } - private static String generateFunctionHeader(String functionName) { + //FIXME: modif4watchdogs (changed from private to public to access in CWatchdogGenerator) + public static String generateFunctionHeader(String functionName) { return "void " + functionName + "(void* instance_args)"; } } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java new file mode 100644 index 0000000000..1c31ee5779 --- /dev/null +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -0,0 +1,140 @@ +package org.lflang.generator.c; + +import org.lflang.federated.FederateInstance; +import org.lflang.generator.CodeBuilder; +import org.lflang.lf.ReactorDecl; +import org.lflang.lf.CReactionGenerator; + +/** + * Generates necessary C code for watchdogs. + * + * @author{Benjamin Asch } + */ +//FIXME: modif4watchdogs +public class CWatchdogGenerator { + + /** + * Generate necessary initialization code inside the body of the watchdog that belongs to reactor decl. + * @param decl The reactor that has the watchdog + */ + public static String generateInitializationForWatchdog(Watchdog watchdog, + ReactorDecl decl) { + Reactor reactor = ASTUtils.toDefinition(decl); + + // Construct the reactionInitialization code to go into + // the body of the function before the verbatim code. + CodeBuilder watchdogInitialization = new CodeBuilder(); + + CodeBuilder code = new CodeBuilder(); + + // Define the "self" struct. + String structType = CUtil.selfType(decl); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr(String.join("\n", + structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" + )); + } + + // Declare mode if in effects field of watchdog + if (watchdog.getEffects() != null) { + for (VarRef effect : watchdog.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + watchdogInitialization.pr( + "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" + + "lf_mode_change_type_t _lf_" + name + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY ? + "history_transition" : "reset_transition") + + ";" + ); + } + // FIXME: include error reporter + // else { + // errorReporter.reportError( + // watchdog, + // "In generateWatchdog(): " + name + " not a valid mode of this reactor." + // ); + // } + } + } + } + + // Next generate all the collected setup code. + code.pr(watchdogInitialization.toString()); + return code.toString(); + } + + /** + * Returns the name of the watchdog function for reaction. + * @param decl The reactor with the watchdog + * @param watchdog The watchdog + * @return Name of the watchdog function for reaction + */ + public static String generateWatchdogFunctionName(Watchdog watchdog, ReactorDecl decl) { + return decl.getName().toLowerCase() + "_" + watchdog.getName().toLowerCase() + "_watchdog_function"; + } + + /** Return the top level C function header for the watchdog function in "decl" + * @param decl The reactor declaration + * @param watchdog The watchdog. + * @return The function name for the watchdog function. + */ + public static String generateWatchdogFunctionHeader(Watchdog watchdog, + ReactorDecl decl) { + String functionName = generateWatchdogFunctionName(watchdog, decl); + return CReactionGenerator.generateFunctionHeader(functionName); + } + + /** + * Generate the watchdog function. + */ + public static String generateWatchdogFunction(Watchdog watchdog, + ReactorDecl decl) { + return CReactionGenerator.generateFunction(generateWatchdogFunctionHeader(watchdog, decl), + generateInitializationForWatchdog(watchdog, decl), + watchdog.getCode()); + } + + /** + * Generate a constructor for the specified reactor in the specified federate. + * @param reactor The parsed reactor data structure. + * @param federate A federate name, or null to unconditionally generate. + * @param constructorCode Lines of code previously generated that need to + * go into the constructor. + */ + //FIXME: this is just the old constructor meant for reactors + public static String generateWatchdogConstructor( + ReactorDecl reactor, + FederateInstance federate, + String constructorCode + ) { + var structType = CUtil.selfType(reactor); + var code = new CodeBuilder(); + code.pr(structType+"* new_"+reactor.getName()+"() {"); + code.indent(); + code.pr(structType+"* self = ("+structType+"*)_lf_new_reactor(sizeof("+structType+"));"); + code.pr(constructorCode); + code.pr("return self;"); + code.unindent(); + code.pr("}"); + return code.toString(); + } + + /** + * Generate _lf_initialize_watchdog_mutexes function. + */ + //FIXME: finish implementing + public static String generateLfInitializeWatchdogMutexes(List reactors) { + // need to find way to assign get watchdog from AST + // need to assign watchdog to correct reaction + var s = new StringBuilder(); + s.append("void _lf_initialize_watchdog_mutexes() {\n"); + + } +} From 3798f3a62f73be544e9c82d6a721c74f56a677c8 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 18 Jan 2023 14:20:03 -0800 Subject: [PATCH 008/709] code generation steps (excluding mutex initialization) should be done, I think --- .../org/lflang/generator/ReactorInstance.java | 22 +++++ .../lflang/generator/WatchdogInstance.java | 23 ++--- .../org/lflang/generator/c/CGenerator.java | 40 +++++++++ .../generator/c/CReactionGenerator.java | 5 +- .../generator/c/CWatchdogGenerator.java | 85 +++++++++++++++---- 5 files changed, 144 insertions(+), 31 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index dbed569762..46b34c662f 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -720,6 +720,24 @@ protected void createReactionInstances() { } } + /** + * Create all the watchdog instances of this reactor instance. + */ + // FIXME: modif4watchdogs + protected void createWatchdogInstances() { + List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); + if (watchdogs != null) { + for (Watchdog watchdog : watchdogs) { + // Create the watchdog instance. + var watchdogInstance = new WatchdogInstance(watchdog, this); + + // Add the watchdog instance to the list of watchdogs for this + // reactor. + this.watchdogs.add(watchdogInstance); + } + } + } + /** * Returns the built-in trigger or create a new one if none exists. */ @@ -834,6 +852,10 @@ private ReactorInstance( // Note that this can only happen _after_ the children, // port, action, and timer instances have been created. createReactionInstances(); + + // Create the reaction instances in this reactor instance. + // FIXME: modif4watchdogs + createWatchdogInstances(); // Instantiate modes for this reactor instance // This must come after the child elements (reactions, etc) of this reactor diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 290c7144a9..ff9bc139df 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -18,22 +18,23 @@ public class WatchdogInstance { * Create a new watchdog instance associated with the given reaction * instance. */ - public WatchdogInstance(Watchdog definition, ReactionInstance reaction) { + public WatchdogInstance(Watchdog definition, ReactorInstance reactor) { if (definition.getTimeout() != null) { - this.timeout = reaction.parent.getTimeValue(definition.getTimeout()); + // WATCHDOG QUESTION + // How does this .getTimeValue work? Where is expression coming from + // versus other time parameters? + this.timeout = reactor.getTimeValue(definition.getTimeout()); } else { this.timeout = TimeValue.ZERO; } - if (definition.getCode() != null) { - this.watchdogHandler = definition.getCode(); - } else { - this.watchdogHandler = new CodeBuilder(); - } - this.name = definition.getName(); } + public String getName() { + return this.name; + } + ////////////////////////////////////////////////////// //// Public fields. @@ -46,10 +47,10 @@ public WatchdogInstance(Watchdog definition, ReactionInstance reaction) { */ public final TimeValue timeout; - /** - * The code body for the function that is executed upon calling the watchdog. + /** + * The watchdog name. */ - public final CodeBuilder watchdogHandler; + public final String name; ////////////////////////////////////////////////////// //// Public methods. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 4579e32534..f27c16ecc1 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1213,6 +1213,8 @@ private void generateReactorClass(ReactorDecl reactor) { generateAuxiliaryStructs(reactor); generateSelfStruct(reactor, constructorCode); generateMethods(reactor); + // FIXME: modif4watchdogs + generateWatchdogs(reactor, currentFederate); generateReactions(reactor, currentFederate); generateConstructor(reactor, currentFederate, constructorCode); @@ -1584,6 +1586,42 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio )); } + // FIXME: modif4watchdogs + /** Generate watchdog functions definition for a reactor. + * These functions have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param decl The reactor. + * @param federate The federate, or null if this is not + * federated or not the main reactor and reactions should be + * unconditionally generated. + */ + public void generateWatchdogs(ReactorDecl decl, FederateInstance federate) { + // WATCHDOG QUESTION: A similar question is asked somewhere else for a + // different function - Do we need to check if this federate contains the + // watchdog? This is done in the code generation for reactions. + var reactor = ASTUtils.toDefinition(decl); + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + if (federate == null || federate.contains(watchdog)) { + generateWatchdog(watchdog, decl); + } + } + } + + /** Generate a watchdog function definition for a reactor. + * This function will have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param watchdog The watchdog. + * @param decl The reactor. + */ + protected void generateWatchdog(Watchdog watchdog, ReactorDecl decl) { + code.pr(CWatchdogGenerator.generateWatchdog( + watchdog, + decl + )); + } + /** * Record startup, shutdown, and reset reactions. * @param instance A reactor instance. @@ -2077,6 +2115,8 @@ protected void generateStateVariableInitializations(ReactorInstance instance) { * specified reactor instance. * @param instance The reactor instance. */ + // WATCHDOG QUESTION: Why do we wait to set the deadline instead of defining + // it in the constructor of the reactor? private void generateSetDeadline(ReactorInstance instance) { for (ReactionInstance reaction : instance.reactions) { if (currentFederate.contains(reaction.getDefinition())) { diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index f5aff5d55e..0f1d0ee2fb 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -197,7 +197,6 @@ public static String generateInitializationForReaction(String body, ); } else if (variable instanceof Watchdog) { //FIXME: modif4watchdogs - // How does it know if instance of watchdog? reactionInitialization.pr(generateWatchdogVariablesInReaction( effect, decl, @@ -745,6 +744,9 @@ public static void generateReactionAndTriggerStructs( var startupReactions = new LinkedHashSet(); var shutdownReactions = new LinkedHashSet(); var resetReactions = new LinkedHashSet(); + // WATCHDOG QUESTION: Why need to grab all reactions from reactor only to check + // if it exists in currentFederate? Maybe real question is what is difference between + // currentfederate and reactor? for (Reaction reaction : ASTUtils.allReactions(reactor)) { if (currentFederate.contains(reaction)) { // Create the reaction_t struct. @@ -814,7 +816,6 @@ public static void generateReactionAndTriggerStructs( "self->_lf__reaction_"+reactionCount+".function = "+ CReactionGenerator.generateReactionFunctionName(decl, reactionCount)+";", "self->_lf__reaction_"+reactionCount+".self = self;", "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".watchdog_handler = "+watchdogFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", (reaction.eContainer() instanceof Mode ? diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 1c31ee5779..578e6bc7a5 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -1,5 +1,6 @@ package org.lflang.generator.c; +import org.lflang.ASTUtils; import org.lflang.federated.FederateInstance; import org.lflang.generator.CodeBuilder; import org.lflang.lf.ReactorDecl; @@ -102,27 +103,75 @@ public static String generateWatchdogFunction(Watchdog watchdog, } /** - * Generate a constructor for the specified reactor in the specified federate. - * @param reactor The parsed reactor data structure. - * @param federate A federate name, or null to unconditionally generate. - * @param constructorCode Lines of code previously generated that need to - * go into the constructor. + * Generate watchdog definition in parent struct. */ - //FIXME: this is just the old constructor meant for reactors - public static String generateWatchdogConstructor( - ReactorDecl reactor, - FederateInstance federate, - String constructorCode + public static void generateWatchdogStruct( + FederateInstance currentFederate, + CodeBuilder body, + ReactorDecl decl, + CodeBuilder constructorCode + ) { + var reactor = ASTUtils.toDefinition(decl); + + // WATCHDOG QUESTION 1: I followed similar format to + // `CReactionGenerator.generateReactionAndTriggerStructs` + // but am not sure why we need to check if watchdog exists in the + // current federate. + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + if (currentFederate.contains(watchdog)) { + + String watchdogName = watchdog.getName(); + // Create pointer to the watchdog_t struct + // WATCHDOG QUESTION 2: Why need to put object at beginning of + // `.pr` func call? + + // WATCHDOG QUESTION 3: Is the space for this struct automatically allocated + // through `_lf_new_reactor`? `_lf__startup_reaction` is also a pointer in self struct + // but does not seem to have a separate allocation call. + body.pr(watchdog, "watchdog_t* _lf_watchdog_"+watchdogName+";"); + + // WATCHDOG QUESTION 4: Not sure if this is correct, may need to use + // 'getTargetTime' instead. watchdog timeout is listed as "Expression" + // in the grammar, so I'm not sure if it is reading the timeout as + // a Time class or TimeValue class. + var min_expiration = GeneratorBase.timeInTargetLanguage(watchdog.getTimeout()); + + // watchdog function name + var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); + // Set values of watchdog_t struct in the reactor's constructor + // WATCHDOG QUESTION 5: should I be defining these in the constructor of the reactor? + constructorCode.pr(watchdog, String.join("\n", + "self->_lf_watchdog_"+watchdogName+".self = self;", + "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", + "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", + "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" + )); + + // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? + } + } + } + + /** Generate a watchdog function definition for a reactor. + * This function will have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param watchdog The watchdog. + * @param decl The reactor. + */ + public static String generateWatchdog( + Watchdog watchdog, + ReactorDecl decl ) { - var structType = CUtil.selfType(reactor); var code = new CodeBuilder(); - code.pr(structType+"* new_"+reactor.getName()+"() {"); - code.indent(); - code.pr(structType+"* self = ("+structType+"*)_lf_new_reactor(sizeof("+structType+"));"); - code.pr(constructorCode); - code.pr("return self;"); - code.unindent(); - code.pr("}"); + + // WATCHDOG QUESTION: Do I need this header? What it for? + code.pr( + "#include " + StringUtil.addDoubleQuotes( + CCoreFilesUtils.getCTargetSetHeader())); + + code.pr(generateWatchdogFunction(watchdog, decl)); + return code.toString(); } From bf4fd4cfd5af0e084cc267efa99cdc54f82bdcc1 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 18 Jan 2023 14:54:07 -0800 Subject: [PATCH 009/709] generatewatchdogstruct in generateselfstruct --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 8 ++++++++ .../src/org/lflang/generator/c/CReactionGenerator.java | 3 +-- .../src/org/lflang/generator/c/CWatchdogGenerator.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index f27c16ecc1..9dfffdd039 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1369,6 +1369,14 @@ private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { isFederatedAndDecentralized() ); + // Generate the fields needed for each watchdog. + CWatchdogGenerator.generateWatchdogStruct( + currentFederate, + body, + decl, + constructorCode + ); + // Next, generate fields for modes CModesGenerator.generateDeclarations(reactor, body, constructorCode); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 0f1d0ee2fb..4cebf42a8f 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -745,8 +745,7 @@ public static void generateReactionAndTriggerStructs( var shutdownReactions = new LinkedHashSet(); var resetReactions = new LinkedHashSet(); // WATCHDOG QUESTION: Why need to grab all reactions from reactor only to check - // if it exists in currentFederate? Maybe real question is what is difference between - // currentfederate and reactor? + // if it exists in currentFederate? for (Reaction reaction : ASTUtils.allReactions(reactor)) { if (currentFederate.contains(reaction)) { // Create the reaction_t struct. diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 578e6bc7a5..b8b78803c3 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -113,7 +113,7 @@ public static void generateWatchdogStruct( ) { var reactor = ASTUtils.toDefinition(decl); - // WATCHDOG QUESTION 1: I followed similar format to + // WATCHDOG QUESTION 1: I followed similar structure to // `CReactionGenerator.generateReactionAndTriggerStructs` // but am not sure why we need to check if watchdog exists in the // current federate. From b87327f2c786d112b34951ab8ad006c14f3f0d48 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 1 Feb 2023 10:00:02 -0800 Subject: [PATCH 010/709] save changes to watchdog --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/ASTUtils.java | 4 +- org.lflang/src/org/lflang/LinguaFranca.xtext | 4 +- .../lflang/federated/FederateInstance.java | 18 +++++++ .../org/lflang/generator/ReactorInstance.java | 2 + .../lflang/generator/WatchdogInstance.java | 28 +++++++--- .../org/lflang/generator/c/CGenerator.java | 51 ++++++++++++++----- .../generator/c/CReactionGenerator.java | 4 +- .../generator/c/CWatchdogGenerator.java | 51 ++++++++++++++----- 9 files changed, 124 insertions(+), 40 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 5b772a5322..050abfa4fa 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 5b772a5322b46b0738fcbd31e33f1175fde3c236 +Subproject commit 050abfa4fa2dab3cc7bc078be3556a239312ac16 diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index b87dc94479..eb0ca085cb 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -90,6 +90,8 @@ import org.lflang.lf.TypeParm; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +//FIXME: modif4watchdogs +import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; @@ -131,7 +133,7 @@ public class ASTUtils { featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), - featurePackage.getReactor_Watchdogs() + featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs() ); diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index e624e61c53..7325401322 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -278,14 +278,14 @@ TypedVariable: ; Variable: - TypedVariable | Timer | Mode; + TypedVariable | Timer | Mode | Watchdog; VarRef: variable=[Variable] | container=[Instantiation] '.' variable=[Variable] | interleaved?='interleaved' '(' (variable=[Variable] | container=[Instantiation] '.' variable=[Variable]) ')' ; VarRefOrModeTransition returns VarRef: - VarRef | Watchdog | transition=ModeTransition '(' variable=[Mode] ')'; + VarRef | transition=ModeTransition '(' variable=[Mode] ')'; Assignment: (lhs=[Parameter] ( diff --git a/org.lflang/src/org/lflang/federated/FederateInstance.java b/org.lflang/src/org/lflang/federated/FederateInstance.java index c32095acfb..cb29977d01 100644 --- a/org.lflang/src/org/lflang/federated/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/FederateInstance.java @@ -327,6 +327,24 @@ public boolean contains(Reaction reaction) { return !excludeReactions.contains(reaction); } + + //FIXME: modif4watchdogs + public boolean contains(Watchdog watchdog) { + Reactor reactor = ASTUtils.getEnclosingReactor(watchdog); + if (!reactor.isFederated() || this.isSingleton()) { + return true; + } + + if (!reactor.getWatchdogs().contains(watchdog)) { + return false; + } + + if (networkReactions.contains(watchdog)) { + return true; + } + + return false; + } /** * Return true if the specified reactor instance or any parent diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 46b34c662f..3df4517d55 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -58,6 +58,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; +//FIXME: modif4watchdogs +import org.lflang.lf.Watchdog; /** diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index ff9bc139df..0fb3701ecc 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -28,23 +28,31 @@ public WatchdogInstance(Watchdog definition, ReactorInstance reactor) { this.timeout = TimeValue.ZERO; } - this.name = definition.getName(); + this.name = definition.getName().toString(); + this.definition = definition; + this.reactor = reactor; } public String getName() { return this.name; } + public Watchdog getDefinition() { + return this.definition; + } + + public TimeValue getTimeout() { + return this.timeout; + } + + public ReactorInstance getReactor() { + return this.reactor; + } + ////////////////////////////////////////////////////// //// Public fields. - /** - * The timeout, L, associated with this deadline. The physical timer gets set - * to expire at physical time, P, equal to the current logical time, t, plus the timeout. - * - * In other words, the watchdog condition is met iff P < t + L while the watchdog has not - * been stopped or reset. - */ + public final TimeValue timeout; /** @@ -52,6 +60,10 @@ public String getName() { */ public final String name; + public final Watchdog definition; + + public final ReactorInstance reactor; + ////////////////////////////////////////////////////// //// Public methods. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 9dfffdd039..45657c6e38 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -80,6 +80,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; +// FIXME: modif4watchdogs +import org.lflang.generator.WatchdogInstance; import org.lflang.generator.SubContext; import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; @@ -101,6 +103,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.util.FileUtil; +// FIXME: modif4watchdogs +import org.lflang.lf.Watchdog; import com.google.common.base.Objects; import com.google.common.collect.Iterables; @@ -376,6 +380,8 @@ public class CGenerator extends GeneratorBase { private int resetReactionCount = 0; private int modalReactorCount = 0; private int modalStateResetCount = 0; + // FIXME: modif4watchdogs + private int watchdogCount = 0; // Indicate whether the generator is in Cpp mode or not private final boolean CCppMode; @@ -748,7 +754,9 @@ private void generateCodeForCurrentFederate( "int _lf_tokens_with_ref_count_count = 0;", "SUPPRESS_UNUSED_WARNING(_lf_tokens_with_ref_count_count);", "int bank_index;", - "SUPPRESS_UNUSED_WARNING(bank_index);" + "SUPPRESS_UNUSED_WARNING(bank_index);", + "int _lf_watchdog_number_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);" )); // Add counters for modal initialization initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); @@ -773,6 +781,10 @@ private void generateCodeForCurrentFederate( // If there are reset reactions, create a table of triggers. code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); + //FIXME: modif4watchdogs + // If there are watchdogs, create a table of triggers. + code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); + // If there are modes, create a table of mode state to be checked for transitions. code.pr(CModesGenerator.generateModeStatesTable( hasModalReactors, @@ -842,7 +854,8 @@ private void generateCodeForCurrentFederate( //FIXME:modif4watchdogs // Generate function to initialize mutexes for all reactors with watchdogs. - code.pr(CReactionGenerator.generateLfInitializeWatchdogMutexes()); + // needs to be implemented still + code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); // Generate a function that will either do nothing // (if there is only one federate or the coordination @@ -1370,6 +1383,7 @@ private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { ); // Generate the fields needed for each watchdog. + // FIXME: modif4watchdogs CWatchdogGenerator.generateWatchdogStruct( currentFederate, body, @@ -1539,18 +1553,6 @@ protected void generateSelfStructExtension( // Do nothing } - /** - * Generate watchdog functions definition for a reactor. - * @param decl The reactor - * @param federate The federate, or null if this is not - * federated or not the main reactor and watchdogs should be - * unconditionally generated. - */ - //FIXME: modif4watchdogs - public void generateWatchdogFunctions(ReactorDecl decl, FederateInstance federate) { - - } - /** Generate reaction functions definition for a reactor. * These functions have a single argument that is a void* pointing to * a struct that contains parameters, state variables, inputs (triggering or not), @@ -1676,6 +1678,25 @@ private void recordBuiltinTriggers(ReactorInstance instance) { } } + // FIXME: modif4watchdogs + private void recordWatchdogs(ReactorInstance instance) { + var foundOne = false; + var temp = new CodeBuilder(); + var reactorRef = CUtil.reactorRef(instance); + + for (WatchdogInstance watchdog : instance.watchdogs) { + if (currentFederate.contains(watchdog.getDefinition())) { + temp.pr("_lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); + temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); + temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); + watchdogCount += currentFederate.numRuntimeInstances(reactor); + foundOne = true; + } + } + if (foundOne) { + initializeTriggerObjects.pr(temp.toString()); + } + } /** @@ -1968,6 +1989,8 @@ public void generateReactorInstance(ReactorInstance instance) { initializeOutputMultiports(instance); initializeInputMultiports(instance); recordBuiltinTriggers(instance); + // FIXME: modif4watchdogs + recordWatchdogs(instance); // Next, initialize the "self" struct with state variables. // These values may be expressions that refer to the parameter values defined above. diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 4cebf42a8f..5b765483e0 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -34,6 +34,8 @@ import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.util.StringUtil; +// FIXME: modif4watchdogs +import org.lflang.lf.Watchdog; public class CReactionGenerator { protected static String DISABLE_REACTION_INITIALIZATION_MARKER @@ -708,7 +710,7 @@ public static String generateWatchdogVariablesInReaction( errorReporter.reportError(watchdog, "Watchdog is required to have a type: " + watchdogName); return ""; } else { - return "watchdog_t* "+watchdogName+" = &self->_lf_watchdog_"+watchdogName+";"; + return "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");"; } } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index b8b78803c3..41d8d3addc 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -4,7 +4,15 @@ import org.lflang.federated.FederateInstance; import org.lflang.generator.CodeBuilder; import org.lflang.lf.ReactorDecl; -import org.lflang.lf.CReactionGenerator; +import org.lflang.lf.Reactor; +import org.lflang.lf.VarRef; +import org.lflang.lf.Variable; +import org.lflang.lf.Mode; +import org.lflang.lf.ModeTransition; +import org.lflang.lf.Watchdog; +import org.lflang.generator.GeneratorBase; +import org.lflang.generator.c.CReactionGenerator; +import java.util.List; /** * Generates necessary C code for watchdogs. @@ -140,10 +148,12 @@ public static void generateWatchdogStruct( var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); // Set values of watchdog_t struct in the reactor's constructor // WATCHDOG QUESTION 5: should I be defining these in the constructor of the reactor? + //FIXME: update parameters constructorCode.pr(watchdog, String.join("\n", - "self->_lf_watchdog_"+watchdogName+".self = self;", + "self->_lf_watchdog_"+watchdogName+".base = &(self->base);", "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", - "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", + "self->_lf_watchdog_"+watchdogName+".thread_active = false;", + // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" )); @@ -165,25 +175,40 @@ public static String generateWatchdog( ) { var code = new CodeBuilder(); - // WATCHDOG QUESTION: Do I need this header? What it for? - code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetHeader())); - code.pr(generateWatchdogFunction(watchdog, decl)); return code.toString(); } + public static String generateBuiltinTriggersTable(int count, String name) { + return String.join("\n", List.of( + "// Array of pointers to "+name+" triggers.", + (count > 0 ? + "watchdog_t* _lf_"+name+"s["+count+"]" : + "int _lf_"+name+"_number = "+count+";" + ))); + } + /** * Generate _lf_initialize_watchdog_mutexes function. */ //FIXME: finish implementing - public static String generateLfInitializeWatchdogMutexes(List reactors) { - // need to find way to assign get watchdog from AST - // need to assign watchdog to correct reaction + public static String generateLfInitializeWatchdogMutexes(int watchdogCount) { var s = new StringBuilder(); - s.append("void _lf_initialize_watchdog_mutexes() {\n"); - + s.append("void _lf_initialize_watchdog_mutexes() {"); + if (watchdogCount > 0) { + s.append("\n"); + s.append(String.join("\n", + " for (int i = 0; i < _lf_watchdog_numer; i++) {", + " self_base_t* current_base = _lf_watchdogs[i]->base;", + " if (&(current_base->watchdog_mutex) == NULL) {", + " lf_mutex_init(&(current_base->watchdog_mutex));", + " }", + " }" + )); + } + s.append("\n"); + s.append("}\n"); + return s.toString(); } } From c8c569c596212e1c66d12ee8a8d2f17b42becbfa Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 7 Feb 2023 23:45:57 -0800 Subject: [PATCH 011/709] Added a few missing imports, but plenty compile errors remain --- org.lflang/src/org/lflang/ASTUtils.java | 1 + org.lflang/src/org/lflang/generator/ReactorInstance.java | 1 + org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 + org.lflang/src/org/lflang/generator/c/CReactionGenerator.java | 1 + org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 2 ++ 5 files changed, 6 insertions(+) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index b87dc94479..b281ac1802 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -90,6 +90,7 @@ import org.lflang.lf.TypeParm; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 46b34c662f..d7589910d2 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -57,6 +57,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Timer; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 9dfffdd039..46271e96bf 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -100,6 +100,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.StateVar; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; import com.google.common.base.Objects; diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 4cebf42a8f..9c9ff93d96 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -33,6 +33,7 @@ import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import org.lflang.lf.Watchdog; import org.lflang.util.StringUtil; public class CReactionGenerator { diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index b8b78803c3..ec67a8bed7 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -3,8 +3,10 @@ import org.lflang.ASTUtils; import org.lflang.federated.FederateInstance; import org.lflang.generator.CodeBuilder; +import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.CReactionGenerator; +import org.lflang.lf.Watchdog; /** * Generates necessary C code for watchdogs. From 10cf7411201e75fe601a5b194b0ca5a7c223cbfd Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 8 Feb 2023 12:28:59 -0800 Subject: [PATCH 012/709] saving before merging --- org.lflang/src/org/lflang/LinguaFranca.xtext | 2 +- .../src/org/lflang/federated/generator/FederateInstance.java | 1 + org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index e9af0b7805..9615b538eb 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -280,7 +280,7 @@ TypedVariable: ; Variable: - TypedVariable | Timer | Mode | Watchdog; + TypedVariable | Timer | Mode; VarRef: variable=[Variable] | container=[Instantiation] '.' variable=[Variable] diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 805643b5cb..bf3b144b2b 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -67,6 +67,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import org.lflang.lf.Watchdog; import com.google.common.base.Objects; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index ff40f79786..c622ba64a1 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -71,7 +71,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorUtils; - import org.lflang.generator.DelayBodyGenerator; import org.lflang.generator.LFGeneratorContext; From 90d002fb9ae09bafd05795beb2f4aa5aa2418e47 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 8 Feb 2023 14:28:29 -0800 Subject: [PATCH 013/709] at least it compiles now --- org.lflang/src/org/lflang/LinguaFranca.xtext | 9 +-- .../federated/generator/FederateInstance.java | 32 ++++----- .../lflang/generator/WatchdogInstance.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 21 +++--- .../generator/c/CReactionGenerator.java | 15 +---- .../generator/c/CWatchdogGenerator.java | 67 +++++++++---------- 6 files changed, 64 insertions(+), 82 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 9615b538eb..c0bfa322d8 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -91,7 +91,7 @@ Reactor: | (connections+=Connection) | (reactions+=Reaction) | (modes+=Mode) - (watchdogs+=Watchdog) + | (watchdogs+=Watchdog) )* '}'; @@ -177,7 +177,8 @@ Mode: (actions+=Action) | (instantiations+=Instantiation) | (connections+=Connection) | - (reactions+=Reaction) + (reactions+=Reaction) | + (watchdogs+=Watchdog) )* '}'; // Action that has either a physical or logical origin. @@ -216,7 +217,7 @@ Deadline: 'deadline' '(' delay=Expression ')' code=Code; Watchdog: - 'watchdog' name=Expression '(' timeout=Expression ')' + 'watchdog' name=ID '(' timeout=Expression ')' ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? code=Code; @@ -280,7 +281,7 @@ TypedVariable: ; Variable: - TypedVariable | Timer | Mode; + TypedVariable | Timer | Mode | Watchdog; VarRef: variable=[Variable] | container=[Instantiation] '.' variable=[Variable] diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index bf3b144b2b..f13313b033 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -467,22 +467,22 @@ private boolean contains(Timer timer) { //FIXME:modif4watchdogs - public boolean contains(Watchdog watchdog) { - Reactor reactor = ASTUtils.getEnclosingReactor(watchdog); - if (!reactor.isFederated() || this.isSingleton()) { - return true; - } - - if (!reactor.getWatchdogs().contains(watchdog)) { - return false; - } - - if (networkReactions.contains(watchdog)) { - return true; - } - - return false; - } + // public boolean contains(Watchdog watchdog) { + // Reactor reactor = ASTUtils.getEnclosingReactor(watchdog); + // if (!reactor.isFederated() || this.isSingleton()) { + // return true; + // } + + // if (!reactor.getWatchdogs().contains(watchdog)) { + // return false; + // } + + // if (networkReactions.contains(watchdog)) { + // return true; + // } + + // return false; + // } /** * Return true if the specified reactor instance or any parent diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 0fb3701ecc..780113a80f 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -42,7 +42,7 @@ public Watchdog getDefinition() { } public TimeValue getTimeout() { - return this.timeout; + return (TimeValue) this.timeout; } public ReactorInstance getReactor() { diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index d7268b0ab7..e9cb80c095 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1072,7 +1072,7 @@ private void generateReactorClass(ReactorDecl reactor) { generateMethods(reactor); // FIXME: modif4watchdogs - generateWatchdogs(reactor, currentFederate); + generateWatchdogs(reactor); generateReactions(reactor); generateConstructor(reactor, constructorCode); @@ -1226,7 +1226,6 @@ private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { // Generate the fields needed for each watchdog. // FIXME: modif4watchdogs CWatchdogGenerator.generateWatchdogStruct( - currentFederate, body, decl, constructorCode @@ -1445,15 +1444,13 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio * federated or not the main reactor and reactions should be * unconditionally generated. */ - public void generateWatchdogs(ReactorDecl decl, FederateInstance federate) { + public void generateWatchdogs(ReactorDecl decl) { // WATCHDOG QUESTION: A similar question is asked somewhere else for a // different function - Do we need to check if this federate contains the // watchdog? This is done in the code generation for reactions. var reactor = ASTUtils.toDefinition(decl); for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - if (federate == null || federate.contains(watchdog)) { - generateWatchdog(watchdog, decl); - } + generateWatchdog(watchdog, decl); } } @@ -1522,13 +1519,11 @@ private void recordWatchdogs(ReactorInstance instance) { var reactorRef = CUtil.reactorRef(instance); for (WatchdogInstance watchdog : instance.watchdogs) { - if (currentFederate.contains(watchdog.getDefinition())) { - temp.pr("_lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); - temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); - watchdogCount += currentFederate.numRuntimeInstances(reactor); - foundOne = true; - } + temp.pr("_lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); + temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); + temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); + watchdogCount += 1; + foundOne = true; } if (foundOne) { initializeTriggerObjects.pr(temp.toString()); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index b27f2e7594..6eaa7506b1 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -202,9 +202,7 @@ public static String generateInitializationForReaction(String body, //FIXME: modif4watchdogs reactionInitialization.pr(generateWatchdogVariablesInReaction( effect, - decl, - errorReporter, - requiresTypes + decl )); } else { errorReporter.reportError( @@ -684,18 +682,11 @@ public static String generateOutputVariablesInReaction( // Fine to have watchdog be in reactor self struct? public static String generateWatchdogVariablesInReaction( VarRef effect, - ReactorDecl decl, - ErrorReporter errorReporter, - boolean requiresTypes + ReactorDecl decl ) { Watchdog watchdog = (Watchdog) effect.getVariable(); String watchdogName = watchdog.getName(); - if (watchdog.getType() == null && requiresTypes) { - errorReporter.reportError(watchdog, "Watchdog is required to have a type: " + watchdogName); - return ""; - } else { - return "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");"; - } + return "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");"; } /** diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 842c145a61..8bdf90b3fe 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -1,7 +1,6 @@ package org.lflang.generator.c; import org.lflang.ASTUtils; -import org.lflang.federated.FederateInstance; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; @@ -15,7 +14,6 @@ import org.lflang.generator.GeneratorBase; import org.lflang.generator.c.CReactionGenerator; import java.util.List; -import org.lflang.lf.CReactionGenerator; import org.lflang.lf.Watchdog; /** @@ -118,7 +116,6 @@ public static String generateWatchdogFunction(Watchdog watchdog, * Generate watchdog definition in parent struct. */ public static void generateWatchdogStruct( - FederateInstance currentFederate, CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode @@ -130,39 +127,37 @@ public static void generateWatchdogStruct( // but am not sure why we need to check if watchdog exists in the // current federate. for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - if (currentFederate.contains(watchdog)) { - - String watchdogName = watchdog.getName(); - // Create pointer to the watchdog_t struct - // WATCHDOG QUESTION 2: Why need to put object at beginning of - // `.pr` func call? - - // WATCHDOG QUESTION 3: Is the space for this struct automatically allocated - // through `_lf_new_reactor`? `_lf__startup_reaction` is also a pointer in self struct - // but does not seem to have a separate allocation call. - body.pr(watchdog, "watchdog_t* _lf_watchdog_"+watchdogName+";"); - - // WATCHDOG QUESTION 4: Not sure if this is correct, may need to use - // 'getTargetTime' instead. watchdog timeout is listed as "Expression" - // in the grammar, so I'm not sure if it is reading the timeout as - // a Time class or TimeValue class. - var min_expiration = GeneratorBase.timeInTargetLanguage(watchdog.getTimeout()); - - // watchdog function name - var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); - // Set values of watchdog_t struct in the reactor's constructor - // WATCHDOG QUESTION 5: should I be defining these in the constructor of the reactor? - //FIXME: update parameters - constructorCode.pr(watchdog, String.join("\n", - "self->_lf_watchdog_"+watchdogName+".base = &(self->base);", - "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", - "self->_lf_watchdog_"+watchdogName+".thread_active = false;", - // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", - "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" - )); - - // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? - } + String watchdogName = watchdog.getName(); + // Create pointer to the watchdog_t struct + // WATCHDOG QUESTION 2: Why need to put object at beginning of + // `.pr` func call? + + // WATCHDOG QUESTION 3: Is the space for this struct automatically allocated + // through `_lf_new_reactor`? `_lf__startup_reaction` is also a pointer in self struct + // but does not seem to have a separate allocation call. + body.pr(watchdog, "watchdog_t* _lf_watchdog_"+watchdogName+";"); + + // WATCHDOG QUESTION 4: Not sure if this is correct, may need to use + // 'getTargetTime' instead. watchdog timeout is listed as "Expression" + // in the grammar, so I'm not sure if it is reading the timeout as + // a Time class or TimeValue class. + // var min_expiration = GeneratorBase.timeInTargetLanguage(watchdog.getTimeout()); + + // watchdog function name + var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); + // Set values of watchdog_t struct in the reactor's constructor + // WATCHDOG QUESTION 5: should I be defining these in the constructor of the reactor? + //FIXME: update parameters + constructorCode.pr(watchdog, String.join("\n", + "self->_lf_watchdog_"+watchdogName+".base = &(self->base);", + "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", + "self->_lf_watchdog_"+watchdogName+".thread_active = false;", + // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", + "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" + )); + + // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? + } } From 4db9e0f78db724dc8106658ea225f1c0d187d532 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 13 Feb 2023 11:49:38 -0800 Subject: [PATCH 014/709] fixed build problems --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 92160a8c22..7fd67a5e59 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 92160a8c22d543eb78f7e9815041606a0aef4e23 +Subproject commit 7fd67a5e599f36d65ab21600e228af7c8217ac98 diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 3a38f9c65f..fc4f38c4e3 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 3a38f9c65fafd2d2f11416fef0ddc69c1a16aa77 +Subproject commit fc4f38c4e3988145d2d3b775b79e436f9f7339ec From f7b177e10bb175e97adec3f9a2f7b7b98c3cf63a Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 13 Feb 2023 12:41:19 -0800 Subject: [PATCH 015/709] tried, unsuccessfully, to fix variable grammar error --- org.lflang/src/org/lflang/LinguaFranca.xtext | 6 +++--- org.lflang/src/org/lflang/ast/IsEqual.java | 5 ++++- org.lflang/src/org/lflang/validation/LFValidator.java | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index c0bfa322d8..8b44ac6e1c 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -217,7 +217,7 @@ Deadline: 'deadline' '(' delay=Expression ')' code=Code; Watchdog: - 'watchdog' name=ID '(' timeout=Expression ')' + 'watchdog ' name=ID '(' timeout=Expression ')' ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? code=Code; @@ -456,7 +456,7 @@ SignedFloat: // Just escaping with \ is not a good idea because then every \ has to be escaped \\. // Perhaps the string EQUALS_BRACE could become '=}'? Code: - //{Code} '{=' (tokens+=Token)* '=}' + // {Code} '{=' (tokens+=Token)* '=}' {Code} '{=' body=Body '=}' ; @@ -503,7 +503,7 @@ Token: 'mutable' | 'input' | 'output' | 'timer' | 'action' | 'reaction' | 'startup' | 'shutdown' | 'after' | 'deadline' | 'mutation' | 'preamble' | 'new' | 'federated' | 'at' | 'as' | 'from' | 'widthof' | 'const' | 'method' | - 'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' + 'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' | // Other terminals NEGINT | TRUE | FALSE | // Action origins diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index b4614edcf0..bd1b55026e 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -61,6 +61,8 @@ import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; +//FIXME: modif4watchdogs +import org.lflang.lf.Watchdog; import org.lflang.lf.util.LfSwitch; /** @@ -397,7 +399,8 @@ public Boolean caseTypedVariable(TypedVariable object) { @Override public Boolean caseVariable(Variable object) { - throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class); + //FIXME: modif4watchdogs + throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class); } @Override diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index f53987e2b5..847bd7320d 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -113,6 +113,8 @@ import org.lflang.lf.Visibility; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; +//FIXME: modif4watchdogs +import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; import com.google.inject.Inject; From 0487e8e4df285f08c731649440cfd18189146aa4 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 17 Feb 2023 12:19:17 -0800 Subject: [PATCH 016/709] watchdog example test --- test/C/src/Watchdog.lf | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/C/src/Watchdog.lf diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf new file mode 100644 index 0000000000..9bdec7f63b --- /dev/null +++ b/test/C/src/Watchdog.lf @@ -0,0 +1,32 @@ +target C; + +reactor Watcher { + input x:int; + output d:int; // Produced if the deadline is violated. + + watchdog poodle(10 msec) {= + instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); + printf("Deadline missed! Lag: %lld (too late by %lld nsecs)\n", p, p-500000); + =} + + reaction(x) -> d, poodle {= + lf_watchdog_start(poodle, 0); + printf("Normal reaction.\n"); + =} +} + +main reactor { + logical action a; + w = new Watcher(); + reaction(startup) -> w.x, a {= + lf_set(w.x, 0); + lf_schedule(a, 0); + =} + reaction(a) -> w.x {= + lf_set(w.x, 0); + lf_nanosleep(MSEC(40)); + =} + reaction(w.d) {= + printf("Deadline reactor produced an output.\n"); + =} +} From ca781252c166c17cf3af09b915c268731a5cb592 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 17 Feb 2023 13:38:17 -0800 Subject: [PATCH 017/709] saving reactorc and changes to scopeprovider --- org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index ae268a9327..745345fc52 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -78,6 +78,7 @@ enum RefType { TRIGGER, SOURCE, EFFECT, + WATCHDOG, DEADLINE, CLEFT, CRIGHT @@ -240,6 +241,8 @@ protected IScope getScopeForVarRef(VarRef variable, EReference reference) { candidates.addAll(allActions(reactor)); return Scopes.scopeFor(candidates); } + case WATCHDOG: + return Scopes.scopeFor(allWatchdogs(reactor)); case DEADLINE: case CLEFT: return Scopes.scopeFor(allInputs(reactor)); From c36cc80b711ea6040fd1e9051a3d7e5d318e8759 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 17 Feb 2023 15:13:07 -0800 Subject: [PATCH 018/709] saving changes to scope provider --- org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index ae268a9327..745345fc52 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -78,6 +78,7 @@ enum RefType { TRIGGER, SOURCE, EFFECT, + WATCHDOG, DEADLINE, CLEFT, CRIGHT @@ -240,6 +241,8 @@ protected IScope getScopeForVarRef(VarRef variable, EReference reference) { candidates.addAll(allActions(reactor)); return Scopes.scopeFor(candidates); } + case WATCHDOG: + return Scopes.scopeFor(allWatchdogs(reactor)); case DEADLINE: case CLEFT: return Scopes.scopeFor(allInputs(reactor)); From 94185e7bf134ee747cbb9e52557daa598c20c5b8 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 17 Feb 2023 16:04:53 -0800 Subject: [PATCH 019/709] Fixed the scope provider --- org.lflang/src/org/lflang/LinguaFranca.xtext | 2 +- org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 8b44ac6e1c..55f5fb0a97 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -217,7 +217,7 @@ Deadline: 'deadline' '(' delay=Expression ')' code=Code; Watchdog: - 'watchdog ' name=ID '(' timeout=Expression ')' + 'watchdog' name=ID '(' timeout=Expression ')' ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? code=Code; diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index 745345fc52..c6bd97a622 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -227,6 +227,7 @@ protected IScope getScopeForVarRef(VarRef variable, EReference reference) { candidates.addAll(allInputs(reactor)); candidates.addAll(allActions(reactor)); candidates.addAll(allTimers(reactor)); + candidates.addAll(allWatchdogs(reactor)); return Scopes.scopeFor(candidates); } case SOURCE: @@ -239,10 +240,9 @@ protected IScope getScopeForVarRef(VarRef variable, EReference reference) { } candidates.addAll(allOutputs(reactor)); candidates.addAll(allActions(reactor)); + candidates.addAll(allWatchdogs(reactor)); return Scopes.scopeFor(candidates); } - case WATCHDOG: - return Scopes.scopeFor(allWatchdogs(reactor)); case DEADLINE: case CLEFT: return Scopes.scopeFor(allInputs(reactor)); From 17261240f413f68e1d34b9ee40f46564bb60c0d7 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 20 Feb 2023 15:41:14 -0800 Subject: [PATCH 020/709] fixed trigger table --- .../src/org/lflang/generator/c/CWatchdogGenerator.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 8bdf90b3fe..0ab08229c4 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -135,7 +135,7 @@ public static void generateWatchdogStruct( // WATCHDOG QUESTION 3: Is the space for this struct automatically allocated // through `_lf_new_reactor`? `_lf__startup_reaction` is also a pointer in self struct // but does not seem to have a separate allocation call. - body.pr(watchdog, "watchdog_t* _lf_watchdog_"+watchdogName+";"); + body.pr(watchdog, "watchdog_t _lf_watchdog_"+watchdogName+";"); // WATCHDOG QUESTION 4: Not sure if this is correct, may need to use // 'getTargetTime' instead. watchdog timeout is listed as "Expression" @@ -184,8 +184,9 @@ public static String generateBuiltinTriggersTable(int count, String name) { "// Array of pointers to "+name+" triggers.", (count > 0 ? "watchdog_t* _lf_"+name+"s["+count+"]" : + "watchdog_t* _lf_"+name+"s = NULL") + ";", "int _lf_"+name+"_number = "+count+";" - ))); + )); } /** @@ -198,7 +199,7 @@ public static String generateLfInitializeWatchdogMutexes(int watchdogCount) { if (watchdogCount > 0) { s.append("\n"); s.append(String.join("\n", - " for (int i = 0; i < _lf_watchdog_numer; i++) {", + " for (int i = 0; i < _lf_watchdog_number; i++) {", " self_base_t* current_base = _lf_watchdogs[i]->base;", " if (&(current_base->watchdog_mutex) == NULL) {", " lf_mutex_init(&(current_base->watchdog_mutex));", From 6994d4633605b8b29448c832721ac24475670bb2 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 26 Feb 2023 15:05:32 -0800 Subject: [PATCH 021/709] saved? --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 7fd67a5e59..b97d084109 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 7fd67a5e599f36d65ab21600e228af7c8217ac98 +Subproject commit b97d08410979bdb2466d6714743bca8d1dc24c76 From f74bbb1a75842c29fd9ec95ed527a7551545d9cd Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 28 Feb 2023 13:41:45 -0800 Subject: [PATCH 022/709] Remove unused deps from default package.json --- org.lflang/src/lib/ts/package.json | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 3c368c9481..5636d6d6fd 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,33 +2,18 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "0.3.2", - "@babel/cli": "^7.8.4", - "@babel/core": "^7.8.7", - "@babel/node": "^7.8.7", - "@babel/plugin-proposal-class-properties": "^7.8.3", - "@babel/plugin-proposal-object-rest-spread": "^7.8.3", - "@babel/plugin-proposal-optional-chaining": "^7.8.3", - "@babel/plugin-transform-modules-commonjs": "^7.8.3", - "@babel/preset-env": "^7.8.7", - "@babel/preset-typescript": "^7.8.3", - "command-line-usage": "^6.1.0", - "command-line-args": "^5.1.1", - "rimraf": "^3.0.2" + "@lf-lang/reactor-ts": "^0.3.2" }, "devDependencies": { "@types/command-line-args": "^5.2.0", "@types/command-line-usage": "^5.0.2", - "@types/jest": "^27.0.0", - "@types/microtime": "^2.1.0", - "@types/node": "^16.3.3", "@types/google-protobuf": "^3.7.4", - "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "5.33.0", "@typescript-eslint/parser": "^5.8.1", "eslint": "^8.5.0", "typescript": "~4.8.2", - "ts-protoc-gen": "^0.12.0" + "ts-protoc-gen": "^0.12.0", + "rimraf": "^3.0.2" }, "scripts": { "check-types": "tsc", From d519b41225c2acd00a43575224cf4caefbd2aedc Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 28 Feb 2023 14:08:38 -0800 Subject: [PATCH 023/709] Add back necessary deps --- org.lflang/src/lib/ts/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 5636d6d6fd..f58ab069e5 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,11 +2,11 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "^0.3.2" + "@lf-lang/reactor-ts": "^0.3.2", + "@babel/cli": "^7.21.0", + "@babel/core": "^7.4.3" }, "devDependencies": { - "@types/command-line-args": "^5.2.0", - "@types/command-line-usage": "^5.0.2", "@types/google-protobuf": "^3.7.4", "@typescript-eslint/eslint-plugin": "5.33.0", "@typescript-eslint/parser": "^5.8.1", From 43a11d7f80c34ed38e95dbfcd30cfcd158ecf74d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 28 Feb 2023 15:21:03 -0800 Subject: [PATCH 024/709] Add back command-line-usage and command-line-args --- org.lflang/src/lib/ts/package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index f58ab069e5..bd5f499bdb 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -4,9 +4,13 @@ "dependencies": { "@lf-lang/reactor-ts": "^0.3.2", "@babel/cli": "^7.21.0", - "@babel/core": "^7.4.3" + "@babel/core": "^7.4.3", + "command-line-args": "^5.1.1", + "command-line-usage": "^6.1.3" }, "devDependencies": { + "@types/command-line-args": "^5.2.0", + "@types/command-line-usage": "^5.0.2", "@types/google-protobuf": "^3.7.4", "@typescript-eslint/eslint-plugin": "5.33.0", "@typescript-eslint/parser": "^5.8.1", From 663d8c618d949da058ce870b27f38ac68bbf6677 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 28 Feb 2023 16:33:11 -0800 Subject: [PATCH 025/709] Use tsc to generate js --- org.lflang/src/lib/ts/package.json | 8 ++++---- org.lflang/src/lib/ts/tsconfig.json | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index bd5f499bdb..3424345a8d 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -1,10 +1,8 @@ { "name": "LinguaFrancaDefault", - "type": "commonjs", + "type": "module", "dependencies": { "@lf-lang/reactor-ts": "^0.3.2", - "@babel/cli": "^7.21.0", - "@babel/core": "^7.4.3", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, @@ -12,6 +10,8 @@ "@types/command-line-args": "^5.2.0", "@types/command-line-usage": "^5.0.2", "@types/google-protobuf": "^3.7.4", + "@types/microtime": "^2.1.0", + "@types/node": "^18.14.2", "@typescript-eslint/eslint-plugin": "5.33.0", "@typescript-eslint/parser": "^5.8.1", "eslint": "^8.5.0", @@ -21,6 +21,6 @@ }, "scripts": { "check-types": "tsc", - "build": "npx rimraf dist && npx babel src --out-dir dist --extensions .ts,.js" + "build": "npx rimraf dist && npx tsc --outDir dist" } } diff --git a/org.lflang/src/lib/ts/tsconfig.json b/org.lflang/src/lib/ts/tsconfig.json index b771b75281..71bc2e9f3c 100644 --- a/org.lflang/src/lib/ts/tsconfig.json +++ b/org.lflang/src/lib/ts/tsconfig.json @@ -1,7 +1,6 @@ { "compilerOptions": { "allowJs": true, - "noEmit": true, "target": "esnext", "types": ["node", "@lf-lang/reactor-ts", "ulog", "microtime", "command-line-args", "command-line-usage"], "esModuleInterop": true, From 3393c588b42e34b9c5ddc193c2d558262c1aba80 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 3 Mar 2023 15:40:46 -0800 Subject: [PATCH 026/709] fixed compile issues --- base | 0 org.lflang.tests/.classpath | 19 ++++++------------- org.lflang.tests/.project | 19 ++++++++++++++++++- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/rs/reactor-rs | 2 +- .../src/lib/rs/runtime-version.properties | 2 +- .../org/lflang/generator/c/CGenerator.java | 7 +++---- .../generator/c/CWatchdogGenerator.java | 8 +++++--- thread_active | 0 watchdog_function | 0 10 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 base create mode 100644 thread_active create mode 100644 watchdog_function diff --git a/base b/base new file mode 100644 index 0000000000..e69de29bb2 diff --git a/org.lflang.tests/.classpath b/org.lflang.tests/.classpath index e46db665de..e025b430eb 100644 --- a/org.lflang.tests/.classpath +++ b/org.lflang.tests/.classpath @@ -1,20 +1,13 @@ - - - - - - - - - - - - + + + - + + + diff --git a/org.lflang.tests/.project b/org.lflang.tests/.project index f17ca7cd7c..7acfd6f031 100644 --- a/org.lflang.tests/.project +++ b/org.lflang.tests/.project @@ -5,13 +5,18 @@ + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.xtext.ui.shared.xtextBuilder - org.eclipse.jdt.core.javabuilder + org.eclipse.buildship.core.gradleprojectbuilder @@ -30,5 +35,17 @@ org.eclipse.xtext.ui.shared.xtextNature org.eclipse.jdt.core.javanature org.eclipse.pde.PluginNature + org.eclipse.buildship.core.gradleprojectnature + + + 1677834823336 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c00691a80a..8a8827fa77 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c00691a80a20ff48486bc0c42d5da6ea175c1eed +Subproject commit 8a8827fa77dc935676fbc148ecd83fffd3feb151 diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index 28f9460724..7685764194 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit 28f9460724b266c263f4fdf8146b2029f4ff9d30 +Subproject commit 76857641941aa49c766ba23da63db4f7650a4c77 diff --git a/org.lflang/src/lib/rs/runtime-version.properties b/org.lflang/src/lib/rs/runtime-version.properties index 35b335b731..4449aaf2fd 100644 --- a/org.lflang/src/lib/rs/runtime-version.properties +++ b/org.lflang/src/lib/rs/runtime-version.properties @@ -1 +1 @@ -rs = 28f9460724b266c263f4fdf8146b2029f4ff9d30 +rs = 76857641941aa49c766ba23da63db4f7650a4c77 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index f2a74c3b5b..3e0cbdb590 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1518,11 +1518,10 @@ private void recordWatchdogs(ReactorInstance instance) { var foundOne = false; var temp = new CodeBuilder(); var reactorRef = CUtil.reactorRef(instance); - for (WatchdogInstance watchdog : instance.watchdogs) { - temp.pr("_lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); - temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); + temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); + temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); + temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); watchdogCount += 1; foundOne = true; } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 0ab08229c4..5b0343ecc7 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -182,10 +182,12 @@ public static String generateWatchdog( public static String generateBuiltinTriggersTable(int count, String name) { return String.join("\n", List.of( "// Array of pointers to "+name+" triggers.", + "#ifdef LF_THREADED", (count > 0 ? - "watchdog_t* _lf_"+name+"s["+count+"]" : - "watchdog_t* _lf_"+name+"s = NULL") + ";", - "int _lf_"+name+"_number = "+count+";" + " watchdog_t* _lf_"+name+"s["+count+"]" : + " watchdog_t* _lf_"+name+"s = NULL") + ";", + " int _lf_"+name+"_number = "+count+";", + "#endif" )); } diff --git a/thread_active b/thread_active new file mode 100644 index 0000000000..e69de29bb2 diff --git a/watchdog_function b/watchdog_function new file mode 100644 index 0000000000..e69de29bb2 From d5ed9745f16ff962c6eb3d5817b3a71c555f2bb5 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 00:10:27 -0800 Subject: [PATCH 027/709] Declare output dir --- org.lflang/src/lib/ts/tsconfig.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/tsconfig.json b/org.lflang/src/lib/ts/tsconfig.json index 71bc2e9f3c..c85f98300f 100644 --- a/org.lflang/src/lib/ts/tsconfig.json +++ b/org.lflang/src/lib/ts/tsconfig.json @@ -3,16 +3,19 @@ "allowJs": true, "target": "esnext", "types": ["node", "@lf-lang/reactor-ts", "ulog", "microtime", "command-line-args", "command-line-usage"], + "typeRoots": ["./node_modules/@types/", "./node_modules/@lf-lang/reactor-ts/src/core/@types/"], "esModuleInterop": true, "isolatedModules": true, "lib": ["esnext", "dom"], "sourceMap": true, "strict": true, "moduleResolution": "node", + "skipLibCheck": true, "strictBindCallApply": true, "strictNullChecks": true, "strictFunctionTypes": true, - "typeRoots": ["./node_modules/@types/", "./node_modules/@lf-lang/reactor-ts/src/core/@types/"] + "noImplicitThis": true, + "outDir": "dist" }, "include": [ "src/**/*" From d0aebb00c1e75e9f36e84daa01393b03bd77fdca Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 11:07:37 -0800 Subject: [PATCH 028/709] Do not copy babel conf --- org.lflang/src/org/lflang/generator/ts/TSGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 21ea083e49..98544a4c49 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -70,7 +70,7 @@ class TSGenerator( * Names of the configuration files to check for and copy to the generated * source package root if they cannot be found in the source directory. */ - val CONFIG_FILES = arrayOf("package.json", "tsconfig.json", "babel.config.js", ".eslintrc.json") + val CONFIG_FILES = arrayOf("package.json", "tsconfig.json", ".eslintrc.json") fun timeInTargetLanguage(value: TimeValue): String { return if (value.unit != null) { From 9a9b73949fe948407a89a72c6e92097483be7722 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 11:21:32 -0800 Subject: [PATCH 029/709] Parameterize build env action to let it find the lingua-franca checkout --- .github/actions/prepare-build-env/action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/actions/prepare-build-env/action.yml b/.github/actions/prepare-build-env/action.yml index 4378bd439e..e61c7b883d 100644 --- a/.github/actions/prepare-build-env/action.yml +++ b/.github/actions/prepare-build-env/action.yml @@ -1,5 +1,10 @@ name: Prepare build environment (Linux only) description: Set up Java, Maven, Gradle, etc. +inputs: + lf-dir: + description: 'Relative path from $GITHUB_WORKSPACE to lingua-franca checkout' + required: false + default: '' runs: using: "composite" steps: @@ -17,3 +22,4 @@ runs: shell: bash - name: Gradle Cache uses: burrunan/gradle-cache-action@v1 + build-root-directory: ${{ inputs.lf-dir }} From 3cb96e3f552d365059a21e99efa74d1d901d0c68 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 11:23:59 -0800 Subject: [PATCH 030/709] Indentation --- .github/actions/prepare-build-env/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/prepare-build-env/action.yml b/.github/actions/prepare-build-env/action.yml index e61c7b883d..1bc0bb97fe 100644 --- a/.github/actions/prepare-build-env/action.yml +++ b/.github/actions/prepare-build-env/action.yml @@ -22,4 +22,5 @@ runs: shell: bash - name: Gradle Cache uses: burrunan/gradle-cache-action@v1 - build-root-directory: ${{ inputs.lf-dir }} + with: + build-root-directory: ${{ inputs.lf-dir }} From b3f42f90883d2547f967fa7c43a01baec7600609 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 8 Mar 2023 11:30:13 -0800 Subject: [PATCH 031/709] Use CommonJS, not ES Modules. --- org.lflang/src/lib/ts/package.json | 2 +- org.lflang/src/lib/ts/tsconfig.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 3424345a8d..346c582e36 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -1,6 +1,6 @@ { "name": "LinguaFrancaDefault", - "type": "module", + "type": "commonjs", "dependencies": { "@lf-lang/reactor-ts": "^0.3.2", "command-line-args": "^5.1.1", diff --git a/org.lflang/src/lib/ts/tsconfig.json b/org.lflang/src/lib/ts/tsconfig.json index c85f98300f..3d51d35052 100644 --- a/org.lflang/src/lib/ts/tsconfig.json +++ b/org.lflang/src/lib/ts/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "allowJs": true, "target": "esnext", + "module": "CommonJS", "types": ["node", "@lf-lang/reactor-ts", "ulog", "microtime", "command-line-args", "command-line-usage"], "typeRoots": ["./node_modules/@types/", "./node_modules/@lf-lang/reactor-ts/src/core/@types/"], "esModuleInterop": true, From 86d609dd68e1cda99a817bcb311ac3fb0e40e9ea Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 8 Mar 2023 11:46:08 -0800 Subject: [PATCH 032/709] Do not run checks when doing full compile. Instead, pass the output of the install command through the TSValidator, which parses it. --- .../org/lflang/generator/ts/TSGenerator.kt | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 98544a4c49..dda883d25c 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -145,14 +145,16 @@ class TSGenerator( println("No .proto files have been imported. Skipping protocol buffer compilation.") } val parsingContext = SubContext(context, COLLECTED_DEPENDENCIES_PERCENT_PROGRESS, 100) - if ( - !context.cancelIndicator.isCanceled - && passesChecks(TSValidator(fileConfig, errorReporter, codeMaps), parsingContext) - ) { + val validator = TSValidator(fileConfig, errorReporter, codeMaps) + if (!context.cancelIndicator.isCanceled) { if (context.mode == LFGeneratorContext.Mode.LSP_MEDIUM) { + if (!passesChecks(validator, parsingContext)) { + context.unsuccessfulFinish(); + return; + } context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, codeMaps)) } else { - compile(resource, parsingContext) + compile(validator, resource, parsingContext) concludeCompilation(context, codeMaps) } } else { @@ -263,13 +265,13 @@ class TSGenerator( } - private fun compile(resource: Resource, parsingContext: LFGeneratorContext) { + private fun compile(validator: TSValidator, resource: Resource, parsingContext: LFGeneratorContext) { GeneratorUtils.refreshProject(resource, parsingContext.mode) if (parsingContext.cancelIndicator.isCanceled) return parsingContext.reportProgress("Transpiling to JavaScript...", 70) - transpile(parsingContext.cancelIndicator) + transpile(validator, parsingContext.cancelIndicator) if (parsingContext.cancelIndicator.isCanceled) return } @@ -397,19 +399,19 @@ class TSGenerator( /** * Transpile TypeScript to JavaScript. */ - private fun transpile(cancelIndicator: CancelIndicator) { + private fun transpile(validator: TSValidator, cancelIndicator: CancelIndicator) { println("Compiling") - val babel = commandFactory.createCommand("npm", listOf("run", "build"), fileConfig.srcGenPkgPath) + val tsc = commandFactory.createCommand("npm", listOf("run", "build"), fileConfig.srcGenPkgPath) - if (babel == null) { + if (tsc == null) { errorReporter.reportError(NO_NPM_MESSAGE) return } - if (babel.run(cancelIndicator) == 0) { + if (validator.run(tsc, cancelIndicator) == 0) { println("SUCCESS (compiling generated TypeScript code)") } else { - errorReporter.reportError("Compiler failed with the following errors:\n${babel.errors}") + errorReporter.reportError("Compiler failed with the following errors:\n${tsc.errors}") } } From 976b1026641b525db07b23143f16fb8a4826a0f6 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 8 Mar 2023 16:57:48 -0800 Subject: [PATCH 033/709] added casewatchdogs, still not fixed --- org.lflang/src/org/lflang/ASTUtils.java | 5 +++ org.lflang/src/org/lflang/ast/IsEqual.java | 12 ++++++++ org.lflang/src/org/lflang/ast/ToLf.java | 36 ++++++++++++++++++++++ test/C/src/Watchdog.lf | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index fe1ba25536..896765f459 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -1075,6 +1075,11 @@ public static InferredType getInferredType(Port p) { return getInferredType(p.getType(), null); } + //FIXME: modif4watchdogs + // public static InferredType getInferredType(Watchdog w) { + // return getInferredType(w.getType(), null); + // } + /** diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index bd1b55026e..1af1eed81a 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -394,6 +394,7 @@ public Boolean caseElement(Element object) { @Override public Boolean caseTypedVariable(TypedVariable object) { + //FIXME: modif4watchdogs throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); } @@ -490,6 +491,17 @@ public Boolean caseArraySpec(ArraySpec object) { .conclusion; } + //FIXME: modif4watchdogs + @Override + public Boolean caseWatchdog(Watchdog object) { + return new ComparisonMachine<>(object, Watchdog.class) + .equalAsObjects(Watchdog::getName) + .equivalent(Watchdog::getTimeout) + .listsEquivalent(Watchdog::getEffects) + .equivalent(Watchdog::getCode) + .conclusion; + } + @Override public Boolean caseWidthSpec(WidthSpec object) { return new ComparisonMachine<>(object, WidthSpec.class) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 7582ee3a59..03a08ec4b8 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -73,6 +73,7 @@ import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.Visibility; +import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; import org.lflang.lf.util.LfSwitch; @@ -653,6 +654,41 @@ public MalleableString caseDeadline(Deadline object) { return handler(object, "deadline", Deadline::getDelay, Deadline::getCode); } + //FIXME: modif4watchdogs + @Override + public MalleableString caseWatchdog(Watchdog object) { + // 'watchdog' name=ID '(' timeout=Expression ')' + // ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? + // code=Code; + + Builder msb = new Builder(); + msb.append("watchdog "); + msb.append(object.getName()); + msb.append(list(true, object.getTimeout())); + + if (!object.getEffects().isEmpty()) { + List allModes = ASTUtils.allModes(ASTUtils.getEnclosingReactor(object)); + msb.append(" -> ", " ->\n") + .append( + object.getEffects().stream() + .map( + varRef -> + (allModes.stream() + .anyMatch( + m -> m.getName().equals(varRef.getVariable().getName()))) + ? new Builder() + .append(varRef.getTransition()) + .append("(") + .append(doSwitch(varRef)) + .append(")") + .get() + : doSwitch(varRef)) + .collect(new Joiner(", "))); + } + msb.append(" ").append(doSwitch(object.getCode())); + return msb.get(); + } + @Override public MalleableString caseSTP(STP object) { // 'STP' '(' value=Expression ')' code=Code diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index 9bdec7f63b..3ae61579f8 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -9,7 +9,7 @@ reactor Watcher { printf("Deadline missed! Lag: %lld (too late by %lld nsecs)\n", p, p-500000); =} - reaction(x) -> d, poodle {= + reaction(x) -> poodle, d {= lf_watchdog_start(poodle, 0); printf("Normal reaction.\n"); =} From 0d31103fbe5d0c342b2263a5a02de781fb9837f9 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 18:22:49 -0800 Subject: [PATCH 034/709] Also produce code for watchdogs in reactor definition --- org.lflang/src/org/lflang/ast/ToLf.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 03a08ec4b8..6f9d369dcc 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -391,6 +391,7 @@ public MalleableString caseReactor(Reactor object) { // | (outputs+=Output) // | (timers+=Timer) // | (actions+=Action) + // | (watchdogs+=Watchdog) // | (instantiations+=Instantiation) // | (connections+=Connection) // | (reactions+=Reaction) @@ -408,6 +409,7 @@ public MalleableString caseReactor(Reactor object) { object.getOutputs(), object.getTimers(), object.getActions(), + object.getWatchdogs(), object.getInstantiations(), object.getConnections(), object.getStateVars()), From 59b3737d10fa7353d95a4a577bf6d9e0b8be2856 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 18:29:30 -0800 Subject: [PATCH 035/709] Apply formatter to test --- test/C/src/Watchdog.lf | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index 3ae61579f8..0dd2436478 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -1,8 +1,8 @@ -target C; +target C reactor Watcher { - input x:int; - output d:int; // Produced if the deadline is violated. + input x: int + output d: int // Produced if the deadline is violated. watchdog poodle(10 msec) {= instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); @@ -12,21 +12,22 @@ reactor Watcher { reaction(x) -> poodle, d {= lf_watchdog_start(poodle, 0); printf("Normal reaction.\n"); - =} + =} } main reactor { - logical action a; - w = new Watcher(); + logical action a + w = new Watcher() + reaction(startup) -> w.x, a {= lf_set(w.x, 0); lf_schedule(a, 0); =} + reaction(a) -> w.x {= lf_set(w.x, 0); lf_nanosleep(MSEC(40)); =} - reaction(w.d) {= - printf("Deadline reactor produced an output.\n"); - =} + + reaction(w.d) {= printf("Deadline reactor produced an output.\n"); =} } From 9d83f55b725cedec83e92231eb753e5cec5b5bf7 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 20:46:56 -0800 Subject: [PATCH 036/709] Fix submodule issues and remove files that should not be checked in --- .gitmodules | 3 ++ org.lflang.tests/.classpath | 13 ----- org.lflang.tests/.project | 51 ------------------- org.lflang/src/lib/cpp/reactor-cpp | 1 + org.lflang/src/lib/rs/reactor-rs | 2 +- .../src/lib/rs/runtime-version.properties | 2 +- 6 files changed, 6 insertions(+), 66 deletions(-) delete mode 100644 org.lflang.tests/.classpath delete mode 100644 org.lflang.tests/.project create mode 160000 org.lflang/src/lib/cpp/reactor-cpp diff --git a/.gitmodules b/.gitmodules index fdbf50ba8d..2231bc265a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "org.lflang/src/lib/rs/reactor-rs"] path = org.lflang/src/lib/rs/reactor-rs url = https://github.com/lf-lang/reactor-rs +[submodule "org.lflang/src/lib/cpp/reactor-cpp"] + path = org.lflang/src/lib/cpp/reactor-cpp + url = https://github.com/lf-lang/reactor-cpp.git diff --git a/org.lflang.tests/.classpath b/org.lflang.tests/.classpath deleted file mode 100644 index e025b430eb..0000000000 --- a/org.lflang.tests/.classpath +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/org.lflang.tests/.project b/org.lflang.tests/.project deleted file mode 100644 index 7acfd6f031..0000000000 --- a/org.lflang.tests/.project +++ /dev/null @@ -1,51 +0,0 @@ - - - org.lflang.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.xtext.ui.shared.xtextBuilder - - - - - org.eclipse.buildship.core.gradleprojectbuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.xtext.ui.shared.xtextNature - org.eclipse.jdt.core.javanature - org.eclipse.pde.PluginNature - org.eclipse.buildship.core.gradleprojectnature - - - - 1677834823336 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp new file mode 160000 index 0000000000..e5d7cfd1f8 --- /dev/null +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -0,0 +1 @@ +Subproject commit e5d7cfd1f89846bc928da86c38a33bb17e1c049b diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index 7685764194..28f9460724 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit 76857641941aa49c766ba23da63db4f7650a4c77 +Subproject commit 28f9460724b266c263f4fdf8146b2029f4ff9d30 diff --git a/org.lflang/src/lib/rs/runtime-version.properties b/org.lflang/src/lib/rs/runtime-version.properties index 4449aaf2fd..35b335b731 100644 --- a/org.lflang/src/lib/rs/runtime-version.properties +++ b/org.lflang/src/lib/rs/runtime-version.properties @@ -1 +1 @@ -rs = 76857641941aa49c766ba23da63db4f7650a4c77 +rs = 28f9460724b266c263f4fdf8146b2029f4ff9d30 From ec8afa7cf2f1ecab29b678f15e4263b1003f04c5 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 20:48:07 -0800 Subject: [PATCH 037/709] Remove spurious file --- base | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 base diff --git a/base b/base deleted file mode 100644 index e69de29bb2..0000000000 From da5b43a1182f678e7ed6f52f277592d6b63a6e27 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 20:48:54 -0800 Subject: [PATCH 038/709] Change order of submodules --- .gitmodules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2231bc265a..efb73c9f3d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,9 @@ [submodule "org.lflang/src/lib/py/reactor-c-py"] path = org.lflang/src/lib/py/reactor-c-py url = https://github.com/lf-lang/reactor-c-py.git -[submodule "org.lflang/src/lib/rs/reactor-rs"] - path = org.lflang/src/lib/rs/reactor-rs - url = https://github.com/lf-lang/reactor-rs [submodule "org.lflang/src/lib/cpp/reactor-cpp"] path = org.lflang/src/lib/cpp/reactor-cpp url = https://github.com/lf-lang/reactor-cpp.git +[submodule "org.lflang/src/lib/rs/reactor-rs"] + path = org.lflang/src/lib/rs/reactor-rs + url = https://github.com/lf-lang/reactor-rs From 9460c1a990724fb2d0a35886da65a7643b66cee3 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 20:51:14 -0800 Subject: [PATCH 039/709] Let version of reactor-cpp be the same as in master --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index e5d7cfd1f8..a37f0ade9e 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit e5d7cfd1f89846bc928da86c38a33bb17e1c049b +Subproject commit a37f0ade9ee0f97606528fd7ba67712495948373 From 043cfbcbe06d54b9de0fbd189339ed630913089d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 8 Mar 2023 20:56:48 -0800 Subject: [PATCH 040/709] Make submodule entries uniform --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index efb73c9f3d..274bffab2c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,4 +9,4 @@ url = https://github.com/lf-lang/reactor-cpp.git [submodule "org.lflang/src/lib/rs/reactor-rs"] path = org.lflang/src/lib/rs/reactor-rs - url = https://github.com/lf-lang/reactor-rs + url = https://github.com/lf-lang/reactor-rs.git From 41c543065055e98b36f5b720d8faa4302dc5c678 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 8 Mar 2023 23:03:10 -0800 Subject: [PATCH 041/709] Update org.lflang/src/org/lflang/ast/ToLf.java Co-authored-by: Marten Lohstroh --- org.lflang/src/org/lflang/ast/ToLf.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 6f9d369dcc..637a555a24 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -656,7 +656,6 @@ public MalleableString caseDeadline(Deadline object) { return handler(object, "deadline", Deadline::getDelay, Deadline::getCode); } - //FIXME: modif4watchdogs @Override public MalleableString caseWatchdog(Watchdog object) { // 'watchdog' name=ID '(' timeout=Expression ')' From 89abf744dc967a9ad56098e2deecd6269276063e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 8 Mar 2023 23:03:24 -0800 Subject: [PATCH 042/709] Update org.lflang/src/org/lflang/ast/IsEqual.java Co-authored-by: Marten Lohstroh --- org.lflang/src/org/lflang/ast/IsEqual.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 1af1eed81a..0d2eab148e 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -400,7 +400,6 @@ public Boolean caseTypedVariable(TypedVariable object) { @Override public Boolean caseVariable(Variable object) { - //FIXME: modif4watchdogs throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class); } From e4be4d56a8bfe28095d0d2dd49f8ad390c93533a Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 8 Mar 2023 23:03:30 -0800 Subject: [PATCH 043/709] Update org.lflang/src/org/lflang/ast/IsEqual.java Co-authored-by: Marten Lohstroh --- org.lflang/src/org/lflang/ast/IsEqual.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 0d2eab148e..16312eb73a 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -490,7 +490,6 @@ public Boolean caseArraySpec(ArraySpec object) { .conclusion; } - //FIXME: modif4watchdogs @Override public Boolean caseWatchdog(Watchdog object) { return new ComparisonMachine<>(object, Watchdog.class) From a81d25b66e9649172e1c2042afea9c0bdc974976 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 8 Mar 2023 23:19:42 -0800 Subject: [PATCH 044/709] removed fixmes, updated grammar --- org.lflang/src/org/lflang/ASTUtils.java | 11 ----------- org.lflang/src/org/lflang/LinguaFranca.xtext | 2 +- org.lflang/src/org/lflang/ast/IsEqual.java | 4 ---- org.lflang/src/org/lflang/ast/ToLf.java | 1 - .../federated/generator/FederateInstance.java | 19 ------------------- .../org/lflang/generator/ReactorInstance.java | 4 ---- .../lflang/generator/WatchdogInstance.java | 2 -- .../org/lflang/generator/c/CGenerator.java | 11 ----------- .../generator/c/CReactionGenerator.java | 4 ---- .../generator/c/CWatchdogGenerator.java | 2 +- .../org/lflang/validation/LFValidator.java | 1 - 11 files changed, 2 insertions(+), 59 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 896765f459..e027ad41dc 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -91,7 +91,6 @@ import org.lflang.lf.VarRef; import org.lflang.lf.Variable; -//FIXME: modif4watchdogs import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; @@ -125,8 +124,6 @@ public class ASTUtils { /** * A mapping from Reactor features to corresponding Mode features for collecting contained elements. */ - //FIXME: modif4watchdogs - // added 'featurePackage.getReactor_Watchdogs' private static final Map reactorModeFeatureMap = Map.of( featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), @@ -423,7 +420,6 @@ public static List allReactions(Reactor definition) { * @param definition Reactor class definition * @return List */ - // FIXME: modif4watchdogs public static List allWatchdogs(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); } @@ -1075,13 +1071,6 @@ public static InferredType getInferredType(Port p) { return getInferredType(p.getType(), null); } - //FIXME: modif4watchdogs - // public static InferredType getInferredType(Watchdog w) { - // return getInferredType(w.getType(), null); - // } - - - /** * If the given string can be recognized as a floating-point number that has a leading decimal point, * prepend the string with a zero and return it. Otherwise, return the original string. diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 55f5fb0a97..98dbb77e1e 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -87,11 +87,11 @@ Reactor: | (outputs+=Output) | (timers+=Timer) | (actions+=Action) + | (watchdogs+=Watchdog) | (instantiations+=Instantiation) | (connections+=Connection) | (reactions+=Reaction) | (modes+=Mode) - | (watchdogs+=Watchdog) )* '}'; diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 1af1eed81a..08c54a999b 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -61,7 +61,6 @@ import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; -//FIXME: modif4watchdogs import org.lflang.lf.Watchdog; import org.lflang.lf.util.LfSwitch; @@ -394,13 +393,11 @@ public Boolean caseElement(Element object) { @Override public Boolean caseTypedVariable(TypedVariable object) { - //FIXME: modif4watchdogs throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); } @Override public Boolean caseVariable(Variable object) { - //FIXME: modif4watchdogs throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class); } @@ -491,7 +488,6 @@ public Boolean caseArraySpec(ArraySpec object) { .conclusion; } - //FIXME: modif4watchdogs @Override public Boolean caseWatchdog(Watchdog object) { return new ComparisonMachine<>(object, Watchdog.class) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 6f9d369dcc..637a555a24 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -656,7 +656,6 @@ public MalleableString caseDeadline(Deadline object) { return handler(object, "deadline", Deadline::getDelay, Deadline::getCode); } - //FIXME: modif4watchdogs @Override public MalleableString caseWatchdog(Watchdog object) { // 'watchdog' name=ID '(' timeout=Expression ')' diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index f13313b033..af581cc74d 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -464,25 +464,6 @@ private boolean contains(Timer timer) { } return false; } - - //FIXME:modif4watchdogs - - // public boolean contains(Watchdog watchdog) { - // Reactor reactor = ASTUtils.getEnclosingReactor(watchdog); - // if (!reactor.isFederated() || this.isSingleton()) { - // return true; - // } - - // if (!reactor.getWatchdogs().contains(watchdog)) { - // return false; - // } - - // if (networkReactions.contains(watchdog)) { - // return true; - // } - - // return false; - // } /** * Return true if the specified reactor instance or any parent diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 06acad45dc..19859cb8a0 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -63,7 +63,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Variable; import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; -//FIXME: modif4watchdogs import org.lflang.lf.Watchdog; @@ -148,7 +147,6 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re public final List reactions = new ArrayList<>(); /** List of watchdog instances for this reactor instance. */ - //FIXME: modif4watchdogs public final List watchdogs = new ArrayList<>(); /** The timer instances belonging to this reactor instance. */ @@ -753,7 +751,6 @@ protected void createReactionInstances() { /** * Create all the watchdog instances of this reactor instance. */ - // FIXME: modif4watchdogs protected void createWatchdogInstances() { List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); if (watchdogs != null) { @@ -876,7 +873,6 @@ private ReactorInstance( createReactionInstances(); // Create the reaction instances in this reactor instance. - // FIXME: modif4watchdogs createWatchdogInstances(); // Instantiate modes for this reactor instance diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 780113a80f..2a2e11a3ad 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -10,8 +10,6 @@ * * @author{Benjamin Asch } */ -//FIXME: modif4watchdogs -//FIXME: functions in constructor not defined public class WatchdogInstance { /** diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index aa64cd5fba..d34e58ebfc 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -80,7 +80,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; -// FIXME: modif4watchdogs import org.lflang.generator.WatchdogInstance; import org.lflang.generator.SubContext; @@ -105,7 +104,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; -// FIXME: modif4watchdogs import org.lflang.lf.Watchdog; import org.lflang.util.LFCommand; @@ -365,7 +363,6 @@ public class CGenerator extends GeneratorBase { private int resetReactionCount = 0; private int modalReactorCount = 0; private int modalStateResetCount = 0; - // FIXME: modif4watchdogs private int watchdogCount = 0; // Indicate whether the generator is in Cpp mode or not @@ -709,7 +706,6 @@ private void generateCodeFor( // If there are reset reactions, create a table of triggers. code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); - //FIXME: modif4watchdogs // If there are watchdogs, create a table of triggers. code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); @@ -737,7 +733,6 @@ private void generateCodeFor( // Generate function to schedule timers for all reactors. code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - //FIXME:modif4watchdogs // Generate function to initialize mutexes for all reactors with watchdogs. // needs to be implemented still code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); @@ -827,7 +822,6 @@ private boolean hasDeadlines(List reactors) { return false; } - //FIXME: modif4watchdogs private boolean hasWatchdogs(Reactor reactor) { if (ASTUtils.allWatchdogs(reactor) != null) { return true; @@ -1072,7 +1066,6 @@ private void generateReactorClass(ReactorDecl reactor) { generateSelfStruct(reactor, constructorCode); generateMethods(reactor); - // FIXME: modif4watchdogs generateWatchdogs(reactor); generateReactions(reactor); generateConstructor(reactor, constructorCode); @@ -1225,7 +1218,6 @@ private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { ); // Generate the fields needed for each watchdog. - // FIXME: modif4watchdogs CWatchdogGenerator.generateWatchdogStruct( body, decl, @@ -1435,7 +1427,6 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio )); } - // FIXME: modif4watchdogs /** Generate watchdog functions definition for a reactor. * These functions have a single argument that is a void* pointing to * a struct that contains parameters, state variables, inputs (triggering or not), @@ -1513,7 +1504,6 @@ private void recordBuiltinTriggers(ReactorInstance instance) { } } - // FIXME: modif4watchdogs private void recordWatchdogs(ReactorInstance instance) { var foundOne = false; var temp = new CodeBuilder(); @@ -1774,7 +1764,6 @@ public void generateReactorInstance(ReactorInstance instance) { initializeOutputMultiports(instance); initializeInputMultiports(instance); recordBuiltinTriggers(instance); - // FIXME: modif4watchdogs recordWatchdogs(instance); // Next, initialize the "self" struct with state variables. diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 6eaa7506b1..6959d52937 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -36,7 +36,6 @@ import org.lflang.lf.Variable; import org.lflang.lf.Watchdog; import org.lflang.util.StringUtil; -// FIXME: modif4watchdogs import org.lflang.lf.Watchdog; public class CReactionGenerator { @@ -199,7 +198,6 @@ public static String generateInitializationForReaction(String body, (Input) variable ); } else if (variable instanceof Watchdog) { - //FIXME: modif4watchdogs reactionInitialization.pr(generateWatchdogVariablesInReaction( effect, decl @@ -678,7 +676,6 @@ public static String generateOutputVariablesInReaction( * @param effect The effect declared by the reaction. This must refer to a watchdog. * @param decl The reactor containing the reaction or the import statement. */ - //FIXME: modif4watchdogs // Fine to have watchdog be in reactor self struct? public static String generateWatchdogVariablesInReaction( VarRef effect, @@ -1185,7 +1182,6 @@ public static String generateStpFunctionHeader(ReactorDecl decl, return generateFunctionHeader(functionName); } - //FIXME: modif4watchdogs (changed from private to public to access in CWatchdogGenerator) public static String generateFunctionHeader(String functionName) { return "void " + functionName + "(void* instance_args)"; } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 5b0343ecc7..4078a98688 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -21,7 +21,7 @@ * * @author{Benjamin Asch } */ -//FIXME: modif4watchdogs + public class CWatchdogGenerator { /** diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 847bd7320d..fa6d8b06fc 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -113,7 +113,6 @@ import org.lflang.lf.Visibility; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; -//FIXME: modif4watchdogs import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; From 88dbef7eed634fd02e8a8f0ecd451e91a689a36d Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 8 Mar 2023 23:57:29 -0800 Subject: [PATCH 045/709] fixed ccpp test issue? --- org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 4078a98688..8b536a9ef8 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -153,7 +153,7 @@ public static void generateWatchdogStruct( "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", "self->_lf_watchdog_"+watchdogName+".thread_active = false;", // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", - "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" + "self->_lf_watchdog_"+watchdogName+".watchdog_function = &("+watchdogFunctionName+");" )); // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? From ef489d3cf5ece299019099e3d5c7f8fc378dea6e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 28 Feb 2023 15:41:47 +0100 Subject: [PATCH 046/709] generate a wrapper reactor for enclave --- .../generator/cpp/CppInstanceGenerator.kt | 81 ++++++++++--------- .../generator/cpp/CppReactionGenerator.kt | 3 +- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt index 4aee21202f..5f92d528b8 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt @@ -36,29 +36,54 @@ class CppInstanceGenerator( private val fileConfig: CppFileConfig, private val errorReporter: ErrorReporter ) { - private val Instantiation.isEnclave: Boolean get() = AttributeUtils.isEnclave(this) + companion object { + val Instantiation.isEnclave: Boolean get() = AttributeUtils.isEnclave(this) - private val Instantiation.hasEachParameter: Boolean - get() = AttributeUtils.getBooleanAttributeParameter( - AttributeUtils.getEnclaveAttribute(this), AttributeSpec.EACH_ATTR - ) ?: false + val Instantiation.hasEachParameter: Boolean + get() = AttributeUtils.getBooleanAttributeParameter( + AttributeUtils.getEnclaveAttribute(this), AttributeSpec.EACH_ATTR + ) ?: false - val Instantiation.cppType: String - get() { - return if (reactor.isGeneric) + private val Instantiation.reactorType: String + get() = if (reactor.isGeneric) """${reactor.name}<${typeParms.joinToString(", ") { it.toText() }}>""" else reactor.name - } + + val Instantiation.cppClass: String + get() = if (isEnclave) enclaveWrapperClassName else reactorType + + val Instantiation.enclaveWrapperClassName get() = "EnclaveWrapper_$name" + } + + private fun Instantiation.generateWrapper(): String = """ + |class $enclaveWrapperClassName : public reactor::Reactor { + | private: + | ${if (!hasEachParameter) "inline static " else ""}std::unique_ptr __lf_env{nullptr}; + | std::unique_ptr<$reactorType> __lf_instance{nullptr}; + | + | public: + | EnclaveWrapper_$name(const std::string& name, reactor::Reactor* container, $reactorType::Parameters&& params) + | : Reactor("enclave_wrapper_" + name, container) { + | if (__lf_env == nullptr) { + | __lf_env = std::make_unique(container->fqn() + name, container->environment()); + | } + | __lf_instance = std::make_unique<$reactorType>(name, __lf_env.get(), std::forward<$reactorType::Parameters>(params)); + | } + | + | void assemble() override {} + |}; + """.trimMargin() private fun generateDeclaration(inst: Instantiation): String = with(inst) { - val instance = if (isBank) "std::vector>" else "std::unique_ptr<$cppType>" + val instance = if (isBank) "std::vector>" else "std::unique_ptr<$cppClass>" if (isEnclave) { - val env = if (hasEachParameter) "std::vector>" else "reactor::Environment" - return """ - $env __lf_env_$name; - $instance $name; - """.trimIndent() + return with(PrependOperator) { + """ + ${" |"..inst.generateWrapper()} + |$instance $name; + """.trimMargin() + } } return "$instance $name;" } @@ -91,43 +116,25 @@ class CppInstanceGenerator( // by iterating over the reactor parameters we make sure that the parameters are assigned in declaration order return reactor.parameters.mapNotNull { if (it.name in assignments) ".${it.name} = ${assignments[it.name]}" else null - }.joinToString(", ", "$cppType::Parameters{", "}") + }.joinToString(", ", "$reactorType::Parameters{", "}") } private fun generateInitializer(inst: Instantiation): String? = with(inst) { - when { - !isBank && !isEnclave -> """, $name(std::make_unique<$cppType>("$name", this, ${getParameterStruct()}))""" - !isBank && isEnclave -> """ - , __lf_env_$name(this->fqn() + ".$name", this->environment()) - , $name(std::make_unique<$cppType>("$name", &__lf_env_$name, ${getParameterStruct()})) - """.trimIndent() - - isBank && isEnclave && !hasEachParameter -> """, __lf_env_$name(this->fqn() + ".$name", this->environment())""" - else -> null - } + if (isBank) null else """, $name(std::make_unique<$cppClass>("$name", this, ${getParameterStruct()}))""" } private fun generateConstructorInitializer(inst: Instantiation): String { with(inst) { assert(isBank) - val containerRef = when { - hasEachParameter -> "__lf_env_$name[__lf_idx].get()" - isEnclave -> "&__lf_env_$name" - else -> "this" - } - val width = inst.widthSpec.toCppCode() - return with(PrependOperator) { - """ + return """ |// initialize instance $name |$name.reserve($width); |for (size_t __lf_idx = 0; __lf_idx < $width; __lf_idx++) { | std::string __lf_inst_name = "${name}_" + std::to_string(__lf_idx); - ${"| "..if (hasEachParameter) """__lf_env_$name.emplace_back(std::make_unique(this->fqn() + "." + __lf_inst_name, this->environment()));""" else ""} - | $name.emplace_back(std::make_unique<$cppType>(__lf_inst_name, $containerRef, ${inst.getParameterStruct()})); + | $name.emplace_back(std::make_unique<$cppClass>(__lf_inst_name, this, ${inst.getParameterStruct()})); |} """.trimMargin() - } } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt index c1e66f3632..5baa075fe6 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt @@ -25,6 +25,7 @@ package org.lflang.generator.cpp import org.lflang.generator.PrependOperator +import org.lflang.generator.cpp.CppInstanceGenerator.Companion.cppClass import org.lflang.isBank import org.lflang.joinWithLn import org.lflang.label @@ -172,7 +173,7 @@ class CppReactionGenerator( } private fun generateViewForContainer(r: Reaction, container: Instantiation): String { - val reactorClass = with(instanceGenerator) { container.cppType } + val reactorClass = container.cppClass val viewClass = r.getViewClassName(container) val viewInstance = r.getViewInstanceName(container) From 3eeaf50a36af2f4d45bf8c971968aa1feebd7533 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 9 Mar 2023 14:43:19 +0100 Subject: [PATCH 047/709] use a struct instead of a reactor to wrap enclaves --- .../src/org/lflang/generator/cpp/CppInstanceGenerator.kt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt index 5f92d528b8..98b7a0f2c5 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt @@ -57,21 +57,16 @@ class CppInstanceGenerator( } private fun Instantiation.generateWrapper(): String = """ - |class $enclaveWrapperClassName : public reactor::Reactor { - | private: + |struct $enclaveWrapperClassName { | ${if (!hasEachParameter) "inline static " else ""}std::unique_ptr __lf_env{nullptr}; | std::unique_ptr<$reactorType> __lf_instance{nullptr}; | - | public: - | EnclaveWrapper_$name(const std::string& name, reactor::Reactor* container, $reactorType::Parameters&& params) - | : Reactor("enclave_wrapper_" + name, container) { + | $enclaveWrapperClassName(const std::string& name, reactor::Reactor* container, $reactorType::Parameters&& params) { | if (__lf_env == nullptr) { | __lf_env = std::make_unique(container->fqn() + name, container->environment()); | } | __lf_instance = std::make_unique<$reactorType>(name, __lf_env.get(), std::forward<$reactorType::Parameters>(params)); | } - | - | void assemble() override {} |}; """.trimMargin() From 619a7663e79a3ed6ce761e4397a61328900bd10b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 9 Mar 2023 19:41:41 +0100 Subject: [PATCH 048/709] first support for simple enclave communication --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- .../generator/cpp/CppConnectionGenerator.kt | 37 ++++++++++++++++--- .../org/lflang/generator/cpp/CppExtensions.kt | 8 +++- .../lflang/generator/cpp/CppPortGenerator.kt | 19 ++++++---- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a63a870180..9e11793a8f 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a63a870180137a023b7faf875271775787a56c03 +Subproject commit 9e11793a8f7ed2ff98eff840dd6e6b8d424dca2d diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt index 2ff818b517..3ec27fc571 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt @@ -2,6 +2,8 @@ package org.lflang.generator.cpp import org.lflang.* import org.lflang.generator.cpp.CppConnectionGenerator.Companion.cppType +import org.lflang.generator.cpp.CppConnectionGenerator.Companion.isEnclaveConnection +import org.lflang.generator.cpp.CppInstanceGenerator.Companion.isEnclave import org.lflang.generator.cpp.CppPortGenerator.Companion.dataType import org.lflang.lf.Connection import org.lflang.lf.Port @@ -25,13 +27,33 @@ class CppConnectionGenerator(private val reactor: Reactor) { get() { val leftPort = leftPorts.first() return when { - isPhysical -> "reactor::PhysicalConnection<${leftPort.dataType}>" - delay != null -> "reactor::DelayedConnection<${leftPort.dataType}>" - else -> throw IllegalArgumentException("Connection is neither physical nor delayed") + isEnclaveConnection && !isPhysical && delay == null -> "reactor::EnclaveConnection<${leftPort.dataType}>" + isPhysical -> "reactor::PhysicalConnection<${leftPort.dataType}>" + delay != null -> "reactor::DelayedConnection<${leftPort.dataType}>" + else -> throw IllegalArgumentException("Unsupported connection type") } } - val Connection.requiresConnectionClass: Boolean get() = isPhysical || delay != null + val Connection.isEnclaveConnection: Boolean + get() { + if (leftPorts.size == 1 && rightPorts.size == 1) { + val leftIsEnclave = leftPorts[0].container?.isEnclave == true + val rightIsEnclave = rightPorts[0].container?.isEnclave == true + return when { + leftIsEnclave && rightIsEnclave -> true + !leftIsEnclave && !rightIsEnclave -> false + else -> TODO("Connections between enclaves and normal reactors are not supported") + } + } + for (port in leftPorts + rightPorts) { + if (port.container?.isEnclave == true) { + TODO("Enclaves can only be used in simple connections") + } + } + return false + } + + val Connection.requiresConnectionClass: Boolean get() = isPhysical || delay != null || isEnclaveConnection; } fun generateDeclarations() = @@ -52,8 +74,11 @@ class CppConnectionGenerator(private val reactor: Reactor) { private fun generateConstructorInitializer(connection: Connection): String? = if (connection.requiresConnectionClass && !connection.hasMultipleConnections) { - val delay = connection.delay.toCppTime() val name = connection.name - """, $name{"$name", this, $delay}""" + val delay = connection.delay?.toCppTime() + if (connection.isEnclaveConnection) + """, $name{"$name", ${connection.rightPorts[0].container.name}->__lf_env.get()}""" + else + """, $name{"$name", this, $delay}""" } else null } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt index f2386bf96a..a081bdd551 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt @@ -2,6 +2,7 @@ package org.lflang.generator.cpp import org.eclipse.emf.ecore.resource.Resource import org.lflang.* +import org.lflang.generator.cpp.CppInstanceGenerator.Companion.isEnclave import org.lflang.lf.BuiltinTriggerRef import org.lflang.lf.Expression import org.lflang.lf.Port @@ -111,8 +112,11 @@ val Reactor.templateName: String get() = if (isGeneric) "$name<${typeParms.joinT /** Get a C++ code representation of the given variable */ val VarRef.name: String - get() = if (this.container == null) this.variable.name - else "${this.container.name}->${this.variable.name}" + get() = when { + container == null -> variable.name + container.isEnclave -> "${container.name}->__lf_instance->${variable.name}" + else -> "${container.name}->${variable.name}" + } /** Get a C++ code representation of the given trigger */ val TriggerRef.name: String diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt index 69ca1d27f6..79dd4ad93a 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt @@ -24,6 +24,8 @@ package org.lflang.generator.cpp +import org.lflang.generator.cpp.CppInstanceGenerator.Companion.enclaveWrapperClassName +import org.lflang.generator.cpp.CppInstanceGenerator.Companion.isEnclave import org.lflang.inferredType import org.lflang.isBank import org.lflang.isMultiport @@ -34,7 +36,6 @@ class CppPortGenerator(private val reactor: Reactor) { companion object { private val VarRef.isMultiport get() = (variable as? Port)?.isMultiport == true - private val VarRef.isInBank get() = container?.isBank == true /** * Return the C++ type of a port reference. @@ -44,11 +45,15 @@ class CppPortGenerator(private val reactor: Reactor) { * statement and let the C++ compiler do the job. */ val VarRef.dataType: String - get() = when { - isInBank && isMultiport -> "std::remove_reference${variable.name}[0])>::type::value_type" - isInBank && !isMultiport -> "std::remove_reference${variable.name})>::type::value_type" - !isInBank && isMultiport -> "std::remove_reference::type::value_type" - else -> "std::remove_reference::type::value_type" + get() { + val variableRef = when { + this == null -> "" + container.isBank && container.isEnclave -> "${container.name}[0]->__lf_instance->${variable.name}" + container.isBank && !container.isEnclave -> "${container.name}[0]->${variable.name}" + else -> this.name + } + val multiportRef = if (isMultiport) "$variableRef[0]" else variableRef + return "std::remove_reference::type::value_type" } } @@ -62,7 +67,7 @@ class CppPortGenerator(private val reactor: Reactor) { } /** Get the C++ type for the receiving port. */ - val Port.cppType: String + private val Port.cppType: String get() { val portType = when (this) { is Input -> "reactor::Input" From b1d6dcaeb628abb8afb22f0a6d39db64dda68fdf Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 9 Mar 2023 19:43:16 +0100 Subject: [PATCH 049/709] add test case --- test/Cpp/src/enclave/EnclaveCommunication.lf | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/Cpp/src/enclave/EnclaveCommunication.lf diff --git a/test/Cpp/src/enclave/EnclaveCommunication.lf b/test/Cpp/src/enclave/EnclaveCommunication.lf new file mode 100644 index 0000000000..00cd314e50 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunication.lf @@ -0,0 +1,29 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output out: int + state counter: int(0); + reaction(t) -> out {= + out.set(counter++); + =} +} + +reactor Sink { + input in: int + reaction(in) {= + reactor::log::Info() << "Received " << *in.get(); + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in +} \ No newline at end of file From 62ee371167c01c3d19a92ba40b19972e710ffa1a Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 9 Mar 2023 23:09:09 -0800 Subject: [PATCH 050/709] Pull reactor-ts from GitHub, not NPM --- .github/workflows/ts-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 24e40b7eef..7c617237b5 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,7 +28,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#cleanup-deps - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: From e9c76a8eee6dfd5da5edd94eb43a2d18d4872cc8 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 9 Mar 2023 23:51:31 -0800 Subject: [PATCH 051/709] Add closing quote --- .github/workflows/ts-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 7c617237b5..79c972d744 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,7 +28,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#cleanup-deps + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#cleanup-deps" - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: From 5670e27cc3051381b0becd2f1ec2c3c39b2a81a9 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 13 Mar 2023 11:46:09 -0700 Subject: [PATCH 052/709] saving before pull again --- .github/actions/prepare-build-env/action.yml | 6 +- .github/scripts/test-lfc.sh | 2 +- .github/workflows/c-zephyr-tests.yml | 2 +- org.lflang/src/org/lflang/cli/CliBase.java | 23 +---- org.lflang/src/org/lflang/cli/Lfc.java | 98 ++++++++----------- org.lflang/src/org/lflang/cli/Lff.java | 12 --- .../org/lflang/generator/GeneratorBase.java | 1 - .../org/lflang/generator/GeneratorUtils.java | 68 +------------ .../lflang/generator/c/CCmakeGenerator.java | 5 - .../generator/cpp/CppRos2NodeGenerator.kt | 3 +- .../cpp/CppStandaloneMainGenerator.kt | 4 +- .../org/lflang/validation/LFValidator.java | 15 ++- test/Cpp/src/concurrent/AsyncCallback.lf | 1 - test/Cpp/src/concurrent/AsyncCallback2.lf | 1 - 14 files changed, 66 insertions(+), 175 deletions(-) diff --git a/.github/actions/prepare-build-env/action.yml b/.github/actions/prepare-build-env/action.yml index e0b8f8bfb0..16cfc3c410 100644 --- a/.github/actions/prepare-build-env/action.yml +++ b/.github/actions/prepare-build-env/action.yml @@ -15,12 +15,16 @@ runs: cat gradle.properties echo $JAVA_HOME shell: bash + - name: Create hash of Gradle configuration + run: | + echo "gradle-hash"="$(find . -type f \( -name "gradle.properties" -o -name "gradle-wrapper.properties" \) -exec cat {} + | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_ENV + shell: bash - name: Cache uses: actions/cache@v3 with: path: | ~/.gradle/caches ~/.gradle/wrapper - key: gradle-${{ runner.os }}-${{ hashFiles('**/gradle-wrapper.properties') }} + key: gradle-${{ runner.os }}-${{ env.gradle-hash }} # restore-keys: | # ${{ runner.os }}-gradle- diff --git a/.github/scripts/test-lfc.sh b/.github/scripts/test-lfc.sh index 20c087db81..a59d4acd3b 100755 --- a/.github/scripts/test-lfc.sh +++ b/.github/scripts/test-lfc.sh @@ -50,7 +50,7 @@ bin/lfc --output-path . test/C/src/Minimal.lf # --runtime-version Specify the version of the runtime # library used for compiling LF # programs. -bin/lfc --runtime-version f157be30bbeab0e2a991f29f9c7f388ca39681a7 test/Cpp/src/Minimal.lf +bin/lfc --runtime-version e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 test/Cpp/src/Minimal.lf # -w,--workers Specify the default number of worker threads. bin/lfc -w 2 test/C/src/Minimal.lf diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index cb3b3a4657..21fe4db2c4 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -21,7 +21,7 @@ jobs: run: runs-on: ubuntu-latest container: - image: zephyrprojectrtos/zephyr-build:latest + image: zephyrprojectrtos/zephyr-build:v0.24.13 options: -u root --entrypoint /bin/sh steps: - name: Install Java 17, Maven and set JAVA_HOME diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index 1a8a26b8c6..77581a6410 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -1,22 +1,15 @@ package org.lflang.cli; import java.io.IOException; -import java.io.PrintStream; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; import picocli.CommandLine; -import picocli.CommandLine.Command; -import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; -import picocli.CommandLine.ParseResult; -import picocli.CommandLine.Spec; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; @@ -29,8 +22,6 @@ import org.lflang.ErrorReporter; import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; -import org.lflang.LocalStrings; -import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.util.FileUtil; import com.google.inject.Inject; import com.google.inject.Injector; @@ -45,11 +36,6 @@ * @author Atharva Patil */ public abstract class CliBase implements Runnable { - /** - * Models a command specification, including the options, positional - * parameters and subcommands supported by the command. - */ - @Spec CommandSpec spec; /** * Options and parameters present in both Lfc and Lff. @@ -65,8 +51,8 @@ public abstract class CliBase implements Runnable { defaultValue = "", fallbackValue = "", description = "Specify the root output directory.") - private Path outputPath; + /** * Used to collect all errors that happen during validation/generation. */ @@ -103,13 +89,6 @@ public abstract class CliBase implements Runnable { @Inject private IResourceValidator validator; - /** Name of the program, eg "lfc". */ - private final String toolName; - - protected CliBase(String toolName) { - this.toolName = toolName; - } - protected static void cliMain( String toolName, Class toolClass, Io io, String[] args) { diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index ffafb9d824..489e9cd2f4 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -1,20 +1,12 @@ package org.lflang.cli; -import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; import java.util.List; import java.util.Properties; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import picocli.CommandLine; import picocli.CommandLine.Command; -import picocli.CommandLine.Model.OptionSpec; import picocli.CommandLine.Option; -import picocli.CommandLine.Parameters; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.GeneratorDelegate; import org.eclipse.xtext.generator.JavaIoFileSystemAccess; @@ -54,15 +46,8 @@ public class Lfc extends CliBase { @Inject private JavaIoFileSystemAccess fileAccess; - public Lfc() { - super("lfc"); - } - - /** + /* * Supported CLI options. - * - * @author Marten Lohstroh - * @author Atharva Patil */ @Option( @@ -101,7 +86,7 @@ public Lfc() { @Option( names = {"-l", "--lint"}, arity = "0", - description = "Enable or disable linting of generated code.") + description = "Enable linting of generated code.") private boolean lint; @Option( @@ -143,7 +128,7 @@ public Lfc() { @Option( names = {"-w", "--workers"}, description = "Specify the default number of worker threads.") - private int workers; + private Integer workers; /** * Main function of the stand-alone compiler. @@ -245,47 +230,48 @@ private Path getActualOutputPath(Path root, Path path) { * @return Properties for the code generator. */ protected Properties filterPassOnProps() { - // Parameters corresponding to the options that need to be passed on to - // the generator as properties. - final Set passOnParams = Stream.of( - BuildParm.BUILD_TYPE, - BuildParm.CLEAN, - BuildParm.TARGET_COMPILER, - BuildParm.EXTERNAL_RUNTIME_PATH, - BuildParm.LOGGING, - BuildParm.LINT, - BuildParm.NO_COMPILE, - BuildParm.QUIET, - BuildParm.RTI, - BuildParm.RUNTIME_VERSION, - BuildParm.SCHEDULER, - BuildParm.THREADING, - BuildParm.WORKERS) - .map(param -> param.getKey()) - .collect(Collectors.toUnmodifiableSet()); - Properties props = new Properties(); - for (OptionSpec option : spec.options()) { - String optionName = option.longestName(); - // Check whether this option needs to be passed on to the code - // generator as a property. - if (passOnParams.contains(optionName)) { - String value = ""; - // Boolean or Integer option. - if (option.getValue() instanceof Boolean || - option.getValue() instanceof Integer) { - value = String.valueOf(option.getValue()); - // String option. - } else if (option.getValue() instanceof String) { - value = option.getValue(); - // Path option. - } else if (option.getValue() instanceof Path) { - value = option.getValue().toString(); - } - props.setProperty(optionName, value); - } + if (buildType != null) { + props.setProperty(BuildParm.BUILD_TYPE.getKey(), buildType); + } + if (clean) { + props.setProperty(BuildParm.CLEAN.getKey(), "true"); + } + if (externalRuntimePath != null) { + props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), externalRuntimePath.toString()); + } + if (lint) { + props.setProperty(BuildParm.LINT.getKey(), "true"); + } + if (logging != null) { + props.setProperty(BuildParm.LOGGING.getKey(), logging); + } + if (noCompile) { + props.setProperty(BuildParm.NO_COMPILE.getKey(), "true"); + } + if (targetCompiler != null) { + props.setProperty(BuildParm.TARGET_COMPILER.getKey(), targetCompiler); + } + if (quiet) { + props.setProperty(BuildParm.QUIET.getKey(), "true"); + } + if (rti != null) { + props.setProperty(BuildParm.RTI.getKey(), rti); + } + if (runtimeVersion != null) { + props.setProperty(BuildParm.RUNTIME_VERSION.getKey(), runtimeVersion); + } + if (scheduler != null) { + props.setProperty(BuildParm.SCHEDULER.getKey(), scheduler); + } + if (threading != null) { + props.setProperty(BuildParm.THREADING.getKey(), threading); + } + if (workers != null) { + props.setProperty(BuildParm.WORKERS.getKey(), workers.toString()); } + return props; } } diff --git a/org.lflang/src/org/lflang/cli/Lff.java b/org.lflang/src/org/lflang/cli/Lff.java index 1c93c39d8a..0eeeea6785 100644 --- a/org.lflang/src/org/lflang/cli/Lff.java +++ b/org.lflang/src/org/lflang/cli/Lff.java @@ -3,25 +3,17 @@ import java.io.IOException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; import java.util.List; -import java.util.Properties; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Option; -import picocli.CommandLine.Parameters; import org.eclipse.emf.ecore.resource.Resource; import org.lflang.ast.FormattingUtils; -import org.lflang.LocalStrings; import org.lflang.util.FileUtil; /** @@ -67,10 +59,6 @@ public class Lff extends CliBase { description = "Print more details on files affected.") private boolean verbose = false; - public Lff() { - super("lff"); - } - /** * Main function of the formatter. * Caution: this will invoke System.exit. diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 95427b1175..0a9c2064d7 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -267,7 +267,6 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { // to validate, which happens in setResources(). setReactorsAndInstantiationGraph(context.getMode()); - GeneratorUtils.validate(context, context.getFileConfig(), instantiationGraph, errorReporter); List allResources = GeneratorUtils.getResources(reactors); resources.addAll(allResources.stream() // FIXME: This filter reproduces the behavior of the method it replaces. But why must it be so complicated? Why are we worried about weird corner cases like this? .filter(it -> !Objects.equal(it, context.getFileConfig().resource) || mainDef != null && it == mainDef.getReactorClass().eResource()) diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/src/org/lflang/generator/GeneratorUtils.java index f51439c390..ec6e167ef2 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/GeneratorUtils.java @@ -156,9 +156,9 @@ public static void accommodatePhysicalActionsIfPresent( } for (Resource resource : resources) { for (Action action : findAll(resource, Action.class)) { - if (action.getOrigin() == ActionOrigin.PHYSICAL && + if (action.getOrigin() == ActionOrigin.PHYSICAL && // Check if the user has explicitly set keepalive to false - !targetConfig.setByUser.contains(TargetProperty.KEEPALIVE) && + !targetConfig.setByUser.contains(TargetProperty.KEEPALIVE) && !targetConfig.keepalive ) { // If not, set it to true @@ -214,70 +214,6 @@ public T next() { }; } - /** - * Validate the files containing reactors in the given - * {@code instantiationGraph}. If a file is imported by - * another file in the instantiation graph, propagate the - * resulting errors to the importing file. - * @param context The context providing the cancel - * indicator used by the validator. - * @param fileConfig The file system configuration. - * @param instantiationGraph A DAG containing all - * reactors of interest. - * @param errorReporter An error acceptor. - */ - public static void validate( - IGeneratorContext context, - FileConfig fileConfig, - InstantiationGraph instantiationGraph, - ErrorReporter errorReporter - ) { - // NOTE: This method was previously misnamed validateImports. - // It validates all files, including the main file that does the importing. - // Also, it is now the only invocation of validation during code generation, - // and yet it used to only report errors in the files doing the importing. - IResourceValidator validator = ((XtextResource) fileConfig.resource).getResourceServiceProvider() - .getResourceValidator(); - HashSet bad = new HashSet<>(); - HashSet visited = new HashSet<>(); - // The graph must be traversed in topological order so that errors will propagate through arbitrarily many - // levels. - for (Reactor reactor : instantiationGraph.nodesInTopologicalOrder()) { - Resource resource = reactor.eResource(); - if (visited.contains(resource)) continue; - visited.add(resource); - List issues = validator.validate(resource, CheckMode.ALL, context.getCancelIndicator()); - if ( - bad.contains(resource) || issues.size() > 0 - ) { - // Report the error on this resource. - Path path = null; - try { - path = FileUtil.toPath(resource); - } catch (IOException e) { - path = Paths.get("Unknown file"); // Not sure if this is what we want. - } - for (Issue issue : issues) { - errorReporter.reportError(path, issue.getLineNumber(), issue.getMessage()); - } - - // Report errors on resources that import this one. - for (Reactor downstreamReactor : instantiationGraph.getDownstreamAdjacentNodes(reactor)) { - for (Import importStatement : ((Model) downstreamReactor.eContainer()).getImports()) { - // FIXME: This will report the error on ALL import statements in - // file doing the importing, not just the one importing this resource. - // I have no idea how to determine which import statement is the right one. - errorReporter.reportError(importStatement, String.format( - "Unresolved compilation issues in '%s': " - + issues.toString(), importStatement.getImportURI() - )); - bad.add(downstreamReactor.eResource()); - } - } - } - } - } - /** * Return the resources that provide the given * reactors. diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 3e220e5ad6..f5e7187233 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -194,11 +194,6 @@ CodeBuilder generateCMakeCode( if (targetConfig.platformOptions.platform != Platform.AUTO) { cMakeCode.pr("set(CMAKE_SYSTEM_NAME "+targetConfig.platformOptions.platform.getcMakeName()+")"); } - - cMakeCode.pr("# Target definitions\n"); - targetConfig.compileDefinitions.forEach((key, value) -> cMakeCode.pr( - "add_compile_definitions("+key+"="+value+")\n" - )); cMakeCode.newLine(); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { diff --git a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt index 064f6758f8..22e3c3045a 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt @@ -59,14 +59,13 @@ class CppRos2NodeGenerator( | : Node("$nodeName", node_options) { | unsigned workers = ${if (targetConfig.workers != 0) targetConfig.workers else "std::thread::hardware_concurrency()"}; | bool fast{${targetConfig.fastMode}}; - | bool keepalive{${targetConfig.keepalive}}; | reactor::Duration lf_timeout{${targetConfig.timeout?.toCppCode() ?: "reactor::Duration::max()"}}; | | // provide a globally accessible reference to this node | // FIXME: this is pretty hacky... | lf_node = this; | - | lf_env = std::make_unique(workers, keepalive, fast, lf_timeout); + | lf_env = std::make_unique(workers, fast, lf_timeout); | | // instantiate the main reactor | lf_main_reactor = std::make_unique<${main.name}> ("${main.name}", lf_env.get(), ${main.name}::Parameters{}); diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt index 171b59c485..07cd3f8ba2 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt @@ -60,7 +60,6 @@ class CppStandaloneMainGenerator( | | unsigned workers = ${if (targetConfig.workers != 0) targetConfig.workers else "std::thread::hardware_concurrency()"}; | bool fast{${targetConfig.fastMode}}; - | bool keepalive{${targetConfig.keepalive}}; | reactor::Duration timeout = ${targetConfig.timeout?.toCppCode() ?: "reactor::Duration::max()"}; | | // the timeout variable needs to be tested beyond fitting the Duration-type @@ -69,7 +68,6 @@ class CppStandaloneMainGenerator( | .add_options() | ("w,workers", "the number of worker threads used by the scheduler", cxxopts::value(workers)->default_value(std::to_string(workers)), "'unsigned'") | ("o,timeout", "Time after which the execution is aborted.", cxxopts::value(timeout)->default_value(time_to_string(timeout)), "'FLOAT UNIT'") - | ("k,keepalive", "Continue execution even when there are no events to process.", cxxopts::value(keepalive)->default_value("${targetConfig.keepalive}")) | ("f,fast", "Allow logical time to run faster than physical time.", cxxopts::value(fast)->default_value("${targetConfig.fastMode}")) | ("help", "Print help"); | @@ -91,7 +89,7 @@ class CppStandaloneMainGenerator( | return parse_error ? -1 : 0; | } | - | reactor::Environment e{workers, keepalive, fast, timeout}; + | reactor::Environment e{workers, fast, timeout}; | | // instantiate the main reactor | ${generateMainReactorInstantiation()} diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index fa6d8b06fc..3f1fbef2fc 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -624,7 +624,7 @@ public void checkParameter(Parameter param) { Reactor reactor = (Reactor) container; if (reactor.isMain()) { // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "k", "keepalive", "f", "fast", "help"); + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); if (cliParams.contains(param.getName())) { error("Parameter '" + param.getName() + "' is already in use as command line argument by Lingua Franca,", @@ -1031,11 +1031,12 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { validateClockSyncTargetProperties(targetProperties); validateSchedulerTargetProperties(targetProperties); validateRos2TargetProperties(targetProperties); + validateKeepalive(targetProperties); } private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { List properties = targetProperties.getPairs().stream() - .filter(pair -> pair.getName() == property.description) + .filter(pair -> pair.getName().equals(property.description)) .toList(); assert (properties.size() <= 1); return properties.size() > 0 ? properties.get(0) : null; @@ -1126,10 +1127,18 @@ private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { } } + private void validateKeepalive(KeyValuePairs targetProperties) { + KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); + if (keepalive != null && target == Target.CPP) { + warning("The keepalive property is inferred automatically by the C++ " + + "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); + } + } + private void validateRos2TargetProperties(KeyValuePairs targetProperties) { KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); - if (!ASTUtils.toBoolean(ros2.getValue()) && ros2Dependencies != null) { + if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { warning( "Ignoring ros2-dependencies as ros2 compilation is disabled", ros2Dependencies, diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index 29fedc41e8..984132f133 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -1,7 +1,6 @@ // Test asynchronous callbacks that trigger a physical action. target Cpp { timeout: 2 sec, - keepalive: true, cmake-include: "AsyncCallback.cmake" } diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index ea493a32cd..322413617b 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -1,7 +1,6 @@ // Test asynchronous callbacks that trigger a non-physical action. target Cpp { timeout: 2 sec, - keepalive: true, cmake-include: "AsyncCallback.cmake" } From 0b27dd08cdd6aeaa4d0269fd46a5ca1a50392025 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 13 Mar 2023 12:02:19 -0700 Subject: [PATCH 053/709] save before second pull --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/cpp/reactor-cpp | 2 +- test/Cpp/src/properties/Keepalive.lf | 43 ---------------------------- 3 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 test/Cpp/src/properties/Keepalive.lf diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 8a8827fa77..82afe9b180 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 8a8827fa77dc935676fbc148ecd83fffd3feb151 +Subproject commit 82afe9b180b3537c03284ba7d9ae7073982c5993 diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a37f0ade9e..e80cd36ce5 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a37f0ade9ee0f97606528fd7ba67712495948373 +Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 diff --git a/test/Cpp/src/properties/Keepalive.lf b/test/Cpp/src/properties/Keepalive.lf deleted file mode 100644 index 1fe6c5e1bc..0000000000 --- a/test/Cpp/src/properties/Keepalive.lf +++ /dev/null @@ -1,43 +0,0 @@ -target Cpp { - keepalive: true, - cmake-include: "../concurrent/AsyncCallback.cmake" -} - -main reactor { - public preamble {= - #include - =} - - state thread: std::thread - - physical action a - state success: bool{false} - - reaction(startup) -> a {= - // start new thread - this->thread = std::thread([&] () { - // Simulate time passing before a callback occurs - std::this_thread::sleep_for(1s); - a.schedule(); - }); - =} - - reaction(a) {= - success = true; - environment()->sync_shutdown(); - =} - - reaction(shutdown) {= - if (success) { - std::cout << "SUCCESS!\n"; - } else { - std::cout << "ERROR: reaction was not invoked!\n"; - exit(1); - } - - // make sure to join the thread before shutting down - if(thread.joinable()) { - thread.join(); - } - =} -} From b7f2d008db2c76294bf29315a44cbbaf1d4d64c6 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 14 Mar 2023 14:51:29 +0100 Subject: [PATCH 054/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index e80cd36ce5..08310933bb 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 +Subproject commit 08310933bbf03b3c2b678f7da2d0a69d73384353 From 945bffe3988259961659f3dffd2fe2621b74894c Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 15 Mar 2023 13:43:52 -0700 Subject: [PATCH 055/709] added error reporting for unthreaded w watchdog --- .../org/lflang/generator/c/CGenerator.java | 26 ++++++++++++++++--- .../generator/c/CReactionGenerator.java | 7 ++++- .../generator/c/CWatchdogGenerator.java | 7 ++--- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index d34e58ebfc..2ef5074455 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -445,6 +445,20 @@ protected boolean isOSCompatible() { return true; } + /** Returns false if watchdogs exist and are + * unsupported in this context. + * Otherwise, return true. + */ + protected boolean isWatchdogCompatible() { + if (hasWatchdogs() && !targetConfig.threading) { + errorReporter.reportError( + "Watchdogs are not supported for unthreaded programs." + ); + return false; + } + return true; + } + /** * Generate C code from the Lingua Franca model contained by the * specified resource. This is the main entry point for code @@ -459,6 +473,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { super.doGenerate(resource, context); if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; if (!isOSCompatible()) return; // Incompatible OS and configuration + if (!isWatchdogCompatible()) return; // Perform set up that does not generate code setUpGeneralParameters(); @@ -822,9 +837,11 @@ private boolean hasDeadlines(List reactors) { return false; } - private boolean hasWatchdogs(Reactor reactor) { - if (ASTUtils.allWatchdogs(reactor) != null) { - return true; + private boolean hasWatchdogs() { + for (Reactor reactor : reactors) { + if (ASTUtils.allWatchdogs(reactor) != null) { + return true; + } } return false; } @@ -1432,7 +1449,6 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio * a struct that contains parameters, state variables, inputs (triggering or not), * actions (triggering or produced), and outputs. * @param decl The reactor. - * @param federate The federate, or null if this is not * federated or not the main reactor and reactions should be * unconditionally generated. */ @@ -1508,6 +1524,7 @@ private void recordWatchdogs(ReactorInstance instance) { var foundOne = false; var temp = new CodeBuilder(); var reactorRef = CUtil.reactorRef(instance); + // temp.pr("#ifdef LF_THREADED"); for (WatchdogInstance watchdog : instance.watchdogs) { temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); @@ -1515,6 +1532,7 @@ private void recordWatchdogs(ReactorInstance instance) { watchdogCount += 1; foundOne = true; } + // temp.pr("#endif"); if (foundOne) { initializeTriggerObjects.pr(temp.toString()); } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 6959d52937..152413f10c 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -683,7 +683,12 @@ public static String generateWatchdogVariablesInReaction( ) { Watchdog watchdog = (Watchdog) effect.getVariable(); String watchdogName = watchdog.getName(); - return "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");"; + + return String.join("\n", List.of( + "#ifdef LF_THREADED", + " watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");", + "#endif" + )); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 8b536a9ef8..72892e8e6b 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -122,10 +122,6 @@ public static void generateWatchdogStruct( ) { var reactor = ASTUtils.toDefinition(decl); - // WATCHDOG QUESTION 1: I followed similar structure to - // `CReactionGenerator.generateReactionAndTriggerStructs` - // but am not sure why we need to check if watchdog exists in the - // current federate. for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { String watchdogName = watchdog.getName(); // Create pointer to the watchdog_t struct @@ -148,6 +144,7 @@ public static void generateWatchdogStruct( // Set values of watchdog_t struct in the reactor's constructor // WATCHDOG QUESTION 5: should I be defining these in the constructor of the reactor? //FIXME: update parameters + // constructorCode.pr("#ifdef LF_THREADED"); constructorCode.pr(watchdog, String.join("\n", "self->_lf_watchdog_"+watchdogName+".base = &(self->base);", "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", @@ -155,7 +152,7 @@ public static void generateWatchdogStruct( // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", "self->_lf_watchdog_"+watchdogName+".watchdog_function = &("+watchdogFunctionName+");" )); - + // constructorCode.pr("#endif"); // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? } From 07adeac12214c73c80265b57e08abf952346ab35 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 09:28:00 +0100 Subject: [PATCH 056/709] add simple enclave communication test --- test/Cpp/src/enclave/EnclaveCommunication.lf | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveCommunication.lf b/test/Cpp/src/enclave/EnclaveCommunication.lf index 00cd314e50..c8d0c50c1c 100644 --- a/test/Cpp/src/enclave/EnclaveCommunication.lf +++ b/test/Cpp/src/enclave/EnclaveCommunication.lf @@ -6,7 +6,7 @@ target Cpp { reactor Src { timer t(0, 100ms) output out: int - state counter: int(0); + state counter: int = 0 reaction(t) -> out {= out.set(counter++); =} @@ -14,8 +14,21 @@ reactor Src { reactor Sink { input in: int + state received: bool = false reaction(in) {= - reactor::log::Info() << "Received " << *in.get(); + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } =} } From 9aaa80e99b40014de1ffc6d137ae7528f2acc3e4 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 09:29:58 +0100 Subject: [PATCH 057/709] add test combining simple enclave communication with other events --- .../EnclaveCommunicationLocalEvents.lf | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf diff --git a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf new file mode 100644 index 0000000000..b5b8f43a63 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf @@ -0,0 +1,46 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output out: int + state counter: int = 0 + reaction(t) -> out {= + out.set(counter++); + =} +} + +reactor Sink { + timer t(0, 50ms) + input in: int + state received: bool = false + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in +} \ No newline at end of file From 36fc3612202b71acd0a2e0b6fe5bbd33631bda61 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 10:05:38 +0100 Subject: [PATCH 058/709] updater reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 08310933bb..5e51fc684c 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 08310933bbf03b3c2b678f7da2d0a69d73384353 +Subproject commit 5e51fc684c6c4475b557b36a3d6118ea76ecba8e From 46db0528e40fc37053c6f6f4783584a5b2161f5f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 10:06:05 +0100 Subject: [PATCH 059/709] code generation for delayed and physical enclave connections --- .../generator/cpp/CppConnectionGenerator.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt index 3ec27fc571..2379a4c08d 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt @@ -27,10 +27,15 @@ class CppConnectionGenerator(private val reactor: Reactor) { get() { val leftPort = leftPorts.first() return when { - isEnclaveConnection && !isPhysical && delay == null -> "reactor::EnclaveConnection<${leftPort.dataType}>" - isPhysical -> "reactor::PhysicalConnection<${leftPort.dataType}>" - delay != null -> "reactor::DelayedConnection<${leftPort.dataType}>" - else -> throw IllegalArgumentException("Unsupported connection type") + isEnclaveConnection -> when { + isPhysical -> "reactor::PhysicalEnclaveConnection<${leftPort.dataType}>" + delay != null -> "reactor::DelayedEnclaveConnection<${leftPort.dataType}>" + else -> "reactor::EnclaveConnection<${leftPort.dataType}>" + } + + isPhysical -> "reactor::PhysicalConnection<${leftPort.dataType}>" + delay != null -> "reactor::DelayedConnection<${leftPort.dataType}>" + else -> throw IllegalArgumentException("Unsupported connection type") } } @@ -72,13 +77,14 @@ class CppConnectionGenerator(private val reactor: Reactor) { } } else null - private fun generateConstructorInitializer(connection: Connection): String? = - if (connection.requiresConnectionClass && !connection.hasMultipleConnections) { - val name = connection.name - val delay = connection.delay?.toCppTime() - if (connection.isEnclaveConnection) - """, $name{"$name", ${connection.rightPorts[0].container.name}->__lf_env.get()}""" - else - """, $name{"$name", this, $delay}""" + private fun generateConstructorInitializer(connection: Connection): String? = with(connection) { + if (requiresConnectionClass && !hasMultipleConnections) { + when { + isEnclaveConnection && delay == null -> """, $name{"$name", ${rightPorts[0].container.name}->__lf_env.get()}""" + isEnclaveConnection && delay != null -> """, $name{"$name", ${rightPorts[0].container.name}->__lf_env.get(), ${delay.toCppTime()}}""" + else -> """, $name{"$name", this, ${delay.toCppTime()}}""" + } } else null + } + } From 06f36fd0f0e61fd1200c6efd0389155af377ffe9 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 10:07:06 +0100 Subject: [PATCH 060/709] add tests for physical and delayed enclave connections --- test/Cpp/src/enclave/EnclaveCommunication.lf | 1 + .../enclave/EnclaveCommunicationDelayed.lf | 43 +++++++++++++++++ .../EnclaveCommunicationDelayedLocalEvents.lf | 47 +++++++++++++++++++ .../EnclaveCommunicationLocalEvents.lf | 1 + .../enclave/EnclaveCommunicationPhysical.lf | 42 +++++++++++++++++ ...EnclaveCommunicationPhysicalLocalEvents.lf | 47 +++++++++++++++++++ 6 files changed, 181 insertions(+) create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf diff --git a/test/Cpp/src/enclave/EnclaveCommunication.lf b/test/Cpp/src/enclave/EnclaveCommunication.lf index c8d0c50c1c..81430ea4ac 100644 --- a/test/Cpp/src/enclave/EnclaveCommunication.lf +++ b/test/Cpp/src/enclave/EnclaveCommunication.lf @@ -22,6 +22,7 @@ reactor Sink { auto expected = 100ms * value; if (get_elapsed_logical_time() != expected) { reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); } =} reaction(shutdown) {= diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf new file mode 100644 index 0000000000..eee3ea979e --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf @@ -0,0 +1,43 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output out: int + state counter: int = 0 + reaction(t) -> out {= + out.set(counter++); + =} +} + +reactor Sink { + input in: int + state received: bool = false + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value + 50ms; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in after 50ms +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf new file mode 100644 index 0000000000..966608f390 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf @@ -0,0 +1,47 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output out: int + state counter: int = 0 + reaction(t) -> out {= + out.set(counter++); + =} +} + +reactor Sink { + timer t(0, 50ms) + input in: int + state received: bool = false + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value + 50ms; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in after 50ms +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf index b5b8f43a63..236f262303 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf @@ -23,6 +23,7 @@ reactor Sink { auto expected = 100ms * value; if (get_elapsed_logical_time() != expected) { reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); } =} reaction(shutdown) {= diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf new file mode 100644 index 0000000000..4ba19a68cb --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf @@ -0,0 +1,42 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output out: int + state counter: int = 0 + reaction(t) -> out {= + out.set(counter++); + =} +} + +reactor Sink { + input in: int + state received: bool = false + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expecded value not before " << expected; + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out ~> sink.in +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf new file mode 100644 index 0000000000..00ba3dc720 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf @@ -0,0 +1,47 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output out: int + state counter: int = 0 + reaction(t) -> out {= + out.set(counter++); + =} +} + +reactor Sink { + timer t(0, 50ms) + input in: int + state received: bool = false + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expecded value not before " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out ~> sink.in +} \ No newline at end of file From 3fb05f5fc07d91e3ce0e1ae81a84197b2a7654f7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 12:09:07 +0100 Subject: [PATCH 061/709] first (incomplete) implementation of enclave multiport connections --- org.lflang/src/lib/cpp/lfutil.hh | 2 ++ .../cpp/CppAssembleMethodGenerator.kt | 21 ++++++++++++++++--- .../generator/cpp/CppConnectionGenerator.kt | 16 +++++++------- .../generator/cpp/CppReactorGenerator.kt | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/lib/cpp/lfutil.hh b/org.lflang/src/lib/cpp/lfutil.hh index e95a99f62b..4ed850e571 100644 --- a/org.lflang/src/lib/cpp/lfutil.hh +++ b/org.lflang/src/lib/cpp/lfutil.hh @@ -27,6 +27,8 @@ #include #include +#include + namespace lfutil { template diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index 45f6f10b0a..9ef5aa10ef 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -26,8 +26,10 @@ package org.lflang.generator.cpp import org.lflang.* import org.lflang.generator.PrependOperator +import org.lflang.generator.cpp.CppConnectionGenerator.Companion.isEnclaveConnection import org.lflang.generator.cpp.CppConnectionGenerator.Companion.name import org.lflang.generator.cpp.CppConnectionGenerator.Companion.requiresConnectionClass +import org.lflang.generator.cpp.CppInstanceGenerator.Companion.isEnclave import org.lflang.generator.cpp.CppPortGenerator.Companion.dataType import org.lflang.lf.Action import org.lflang.lf.Connection @@ -86,7 +88,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { // is in a bank, but not a multiport """ |for (auto& __lf_instance : ${container.name}) { - ${" | "..generateCode("__lf_instance->${port.name}")} + ${" | "..generateCode("__lf_instance->${if(container.isEnclave) "__lf_instance->" else ""}${port.name}")} |} """.trimMargin() } else { @@ -182,7 +184,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { // Generate code which adds all left hand ports and all right hand ports to a vector each. If we are handling multiports // within a bank, then we normally iterate over all banks in an outer loop and over all ports in an inner loop. However, - // if the connection is a cross connection, than we change the order on the right side and iterate over ports before banks. + // if the connection is an interleaved connection, than we change the order on the right side and iterate over ports before banks. return with(PrependOperator) { if (!c.requiresConnectionClass) { """ @@ -193,7 +195,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} |lfutil::bind_multiple_ports(__lf_left_ports_$idx, __lf_right_ports_$idx, ${c.isIterated}); """.trimMargin() - } else { + } else if (!c.isEnclaveConnection) { """ |// connection $idx |std::vector<$portType> __lf_left_ports_$idx; @@ -211,6 +213,19 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} |lfutil::bind_multiple_connections_with_ports(__lf_connection_pointers_$idx, __lf_right_ports_$idx, ${c.isIterated}); """.trimMargin() + } else { + """ + |// connection $idx + |std::vector<$portType> __lf_left_ports_$idx; + ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} + |std::vector<$portType> __lf_right_ports_$idx; + ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} + |for(size_t __lf_idx{0}; __lf_idx < std::min(__lf_right_ports_$idx.size(), __lf_left_ports_$idx.size()); __lf_idx++) { + | ${c.name}.emplace_back("${c.name}" + std::to_string(__lf_idx), __lf_right_ports_$idx[__lf_idx]->environment()${if(c.delay != null) ", ${c.delay.toCppTime()}" else ""}); + | ${c.name}.back().bind_upstream_port(__lf_left_ports_$idx[__lf_idx]); + | ${c.name}.back().bind_downstream_port(__lf_right_ports_$idx[__lf_idx]); + |} + """.trimMargin() } } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt index 2379a4c08d..897fe01202 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt @@ -69,13 +69,15 @@ class CppConnectionGenerator(private val reactor: Reactor) { reactor.connections.mapNotNull { generateConstructorInitializer(it) }.joinLn() private fun generateDecleration(connection: Connection): String? = - if (connection.requiresConnectionClass) { - if (connection.hasMultipleConnections) { - "std::vector<${connection.cppType}> ${connection.name};" - } else { - "${connection.cppType} ${connection.name};" - } - } else null + with(connection) { + if (requiresConnectionClass) { + when { + hasMultipleConnections && isEnclaveConnection -> "std::list<${connection.cppType}> ${connection.name};" + hasMultipleConnections && !isEnclaveConnection -> "std::vector<${connection.cppType}> ${connection.name};" + else -> "${connection.cppType} ${connection.name};" + } + } else null + } private fun generateConstructorInitializer(connection: Connection): String? = with(connection) { if (requiresConnectionClass && !hasMultipleConnections) { diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt index 50fff0bdb5..78df4519f2 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt @@ -187,8 +187,8 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi ${" | "..instances.generateInitializers()} ${" | "..timers.generateInitializers()} ${" | "..actions.generateInitializers()} - ${" | "..connections.generateInitializers()} ${" | "..reactions.generateReactionViewInitializers()} + ${" | "..connections.generateInitializers()} |{ ${" | "..ports.generateConstructorInitializers()} ${" | "..instances.generateConstructorInitializers()} From d5f90f2918c6279b2d13e2c90d3d69d7c38771ee Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 12:10:12 +0100 Subject: [PATCH 062/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 5e51fc684c..07e74c307e 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 5e51fc684c6c4475b557b36a3d6118ea76ecba8e +Subproject commit 07e74c307ef4378846265c1490ac8144227c5a4d From 66129104069a06cf8a20626f89decc1eca1858f7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 12:16:42 +0100 Subject: [PATCH 063/709] add various multiport tests --- .../EnclaveCommunicationMultiportToBank.lf | 55 +++++++++++++++++++ ...laveCommunicationMultiportToBankDelayed.lf | 55 +++++++++++++++++++ ...EnclaveCommunicationMultiportToBankEach.lf | 55 +++++++++++++++++++ ...CommunicationMultiportToBankEachDelayed.lf | 55 +++++++++++++++++++ ...ommunicationMultiportToBankEachPhysical.lf | 55 +++++++++++++++++++ ...aveCommunicationMultiportToBankPhysical.lf | 55 +++++++++++++++++++ .../enclave/EnclaveCommunicationPhysical.lf | 1 + 7 files changed, 331 insertions(+) create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf new file mode 100644 index 0000000000..d69d0042db --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf @@ -0,0 +1,55 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output[4] out: int + state counter: int = 0 + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} +} + +reactor Sink(bank_index: std::size_t = 0) { + timer t(0, 50ms) + input in: int + state received: bool = false + state iteration: int = 0 + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new[4] Sink() + + src.out -> sink.in +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf new file mode 100644 index 0000000000..86f7c07aa0 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf @@ -0,0 +1,55 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output[4] out: int + state counter: int = 0 + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} +} + +reactor Sink(bank_index: std::size_t = 0) { + timer t(0, 50ms) + input in: int + state received: bool = false + state iteration: int = 0 + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration + 50ms; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new[4] Sink() + + src.out -> sink.in after 50ms +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf new file mode 100644 index 0000000000..a67f25a384 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf @@ -0,0 +1,55 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output[4] out: int + state counter: int = 0 + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} +} + +reactor Sink(bank_index: std::size_t = 0) { + timer t(0, 50ms) + input in: int + state received: bool = false + state iteration: int = 0 + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave(each=true) + sink = new[4] Sink() + + src.out -> sink.in +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf new file mode 100644 index 0000000000..77569285f2 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf @@ -0,0 +1,55 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output[4] out: int + state counter: int = 0 + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} +} + +reactor Sink(bank_index: std::size_t = 0) { + timer t(0, 50ms) + input in: int + state received: bool = false + state iteration: int = 0 + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration + 50ms; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave(each=true) + sink = new[4] Sink() + + src.out -> sink.in after 50ms +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf new file mode 100644 index 0000000000..d0ab0218ad --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf @@ -0,0 +1,55 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output[4] out: int + state counter: int = 0 + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} +} + +reactor Sink(bank_index: std::size_t = 0) { + timer t(0, 50ms) + input in: int + state received: bool = false + state iteration: int = 0 + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave(each=true) + sink = new[4] Sink() + + src.out ~> sink.in +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf new file mode 100644 index 0000000000..9aa88eb248 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf @@ -0,0 +1,55 @@ +target Cpp { + timeout: 1s, + workers: 1 +} + +reactor Src { + timer t(0, 100ms) + output[4] out: int + state counter: int = 0 + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} +} + +reactor Sink(bank_index: std::size_t = 0) { + timer t(0, 50ms) + input in: int + state received: bool = false + state iteration: int = 0 + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected; + exit(1); + } + =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + reaction(t) {= + reactor::log::Info() << "Tick"; + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new[4] Sink() + + src.out ~> sink.in +} \ No newline at end of file diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf index 4ba19a68cb..539a3c34b7 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf @@ -22,6 +22,7 @@ reactor Sink { auto expected = 100ms * value; if (get_elapsed_logical_time() < expected) { reactor::log::Error() << "Expecded value not before " << expected; + exit(1); } =} reaction(shutdown) {= From bd27e1f917a21d49778387c2c909be49d32a8190 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sat, 18 Mar 2023 12:17:46 +0100 Subject: [PATCH 064/709] formatting --- test/Cpp/src/enclave/EnclaveCommunication.lf | 13 ++++++----- .../enclave/EnclaveCommunicationDelayed.lf | 15 +++++++------ .../EnclaveCommunicationDelayedLocalEvents.lf | 22 +++++++++---------- .../EnclaveCommunicationLocalEvents.lf | 20 ++++++++--------- .../EnclaveCommunicationMultiportToBank.lf | 16 ++++++++------ ...laveCommunicationMultiportToBankDelayed.lf | 18 ++++++++------- ...EnclaveCommunicationMultiportToBankEach.lf | 18 ++++++++------- ...CommunicationMultiportToBankEachDelayed.lf | 20 +++++++++-------- ...ommunicationMultiportToBankEachPhysical.lf | 18 ++++++++------- ...aveCommunicationMultiportToBankPhysical.lf | 16 ++++++++------ .../enclave/EnclaveCommunicationPhysical.lf | 13 ++++++----- ...EnclaveCommunicationPhysicalLocalEvents.lf | 20 ++++++++--------- 12 files changed, 112 insertions(+), 97 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveCommunication.lf b/test/Cpp/src/enclave/EnclaveCommunication.lf index 81430ea4ac..b780dad109 100644 --- a/test/Cpp/src/enclave/EnclaveCommunication.lf +++ b/test/Cpp/src/enclave/EnclaveCommunication.lf @@ -1,20 +1,20 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output out: int state counter: int = 0 - reaction(t) -> out {= - out.set(counter++); - =} + + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { input in: int state received: bool = false + reaction(in) {= received = true; auto value = *in.get(); @@ -25,6 +25,7 @@ reactor Sink { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; @@ -40,4 +41,4 @@ main reactor { sink = new Sink() src.out -> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf index eee3ea979e..6bbab0a700 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf @@ -1,20 +1,20 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output out: int state counter: int = 0 - reaction(t) -> out {= - out.set(counter++); - =} + + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { input in: int state received: bool = false + reaction(in) {= received = true; auto value = *in.get(); @@ -25,6 +25,7 @@ reactor Sink { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; @@ -39,5 +40,5 @@ main reactor { @enclave sink = new Sink() - src.out -> sink.in after 50ms -} \ No newline at end of file + src.out -> sink.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf index 966608f390..fa9c7b25e4 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf @@ -1,21 +1,21 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output out: int state counter: int = 0 - reaction(t) -> out {= - out.set(counter++); - =} + + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false + reaction(in) {= received = true; auto value = *in.get(); @@ -26,15 +26,15 @@ reactor Sink { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @@ -43,5 +43,5 @@ main reactor { @enclave sink = new Sink() - src.out -> sink.in after 50ms -} \ No newline at end of file + src.out -> sink.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf index 236f262303..3a0edfd7e5 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf @@ -1,21 +1,21 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output out: int state counter: int = 0 - reaction(t) -> out {= - out.set(counter++); - =} + + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false + reaction(in) {= received = true; auto value = *in.get(); @@ -26,15 +26,15 @@ reactor Sink { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @@ -44,4 +44,4 @@ main reactor { sink = new Sink() src.out -> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf index d69d0042db..4a74085dbc 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf @@ -1,12 +1,13 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output[4] out: int state counter: int = 0 + reaction(t) -> out {= for (auto& port : out) { port.set(counter++); @@ -15,10 +16,11 @@ reactor Src { } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false state iteration: int = 0 + reaction(in) {= received = true; auto value = *in.get(); @@ -34,15 +36,15 @@ reactor Sink(bank_index: std::size_t = 0) { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @@ -52,4 +54,4 @@ main reactor { sink = new[4] Sink() src.out -> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf index 86f7c07aa0..682b812d4a 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf @@ -1,12 +1,13 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output[4] out: int state counter: int = 0 + reaction(t) -> out {= for (auto& port : out) { port.set(counter++); @@ -15,10 +16,11 @@ reactor Src { } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false state iteration: int = 0 + reaction(in) {= received = true; auto value = *in.get(); @@ -34,15 +36,15 @@ reactor Sink(bank_index: std::size_t = 0) { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @@ -51,5 +53,5 @@ main reactor { @enclave sink = new[4] Sink() - src.out -> sink.in after 50ms -} \ No newline at end of file + src.out -> sink.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf index a67f25a384..e926019572 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf @@ -1,12 +1,13 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output[4] out: int state counter: int = 0 + reaction(t) -> out {= for (auto& port : out) { port.set(counter++); @@ -15,10 +16,11 @@ reactor Src { } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false state iteration: int = 0 + reaction(in) {= received = true; auto value = *in.get(); @@ -34,22 +36,22 @@ reactor Sink(bank_index: std::size_t = 0) { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @enclave src = new Src() - @enclave(each=true) + @enclave(each = true) sink = new[4] Sink() src.out -> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf index 77569285f2..238edf7bfc 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf @@ -1,12 +1,13 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output[4] out: int state counter: int = 0 + reaction(t) -> out {= for (auto& port : out) { port.set(counter++); @@ -15,10 +16,11 @@ reactor Src { } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false state iteration: int = 0 + reaction(in) {= received = true; auto value = *in.get(); @@ -34,22 +36,22 @@ reactor Sink(bank_index: std::size_t = 0) { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @enclave src = new Src() - @enclave(each=true) + @enclave(each = true) sink = new[4] Sink() - src.out -> sink.in after 50ms -} \ No newline at end of file + src.out -> sink.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf index d0ab0218ad..15eb6faf68 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf @@ -1,12 +1,13 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output[4] out: int state counter: int = 0 + reaction(t) -> out {= for (auto& port : out) { port.set(counter++); @@ -15,10 +16,11 @@ reactor Src { } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false state iteration: int = 0 + reaction(in) {= received = true; auto value = *in.get(); @@ -34,22 +36,22 @@ reactor Sink(bank_index: std::size_t = 0) { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @enclave src = new Src() - @enclave(each=true) + @enclave(each = true) sink = new[4] Sink() src.out ~> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf index 9aa88eb248..3867a7a627 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf @@ -1,12 +1,13 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output[4] out: int state counter: int = 0 + reaction(t) -> out {= for (auto& port : out) { port.set(counter++); @@ -15,10 +16,11 @@ reactor Src { } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false state iteration: int = 0 + reaction(in) {= received = true; auto value = *in.get(); @@ -34,15 +36,15 @@ reactor Sink(bank_index: std::size_t = 0) { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @@ -52,4 +54,4 @@ main reactor { sink = new[4] Sink() src.out ~> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf index 539a3c34b7..ee3ab7f80b 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf @@ -1,20 +1,20 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output out: int state counter: int = 0 - reaction(t) -> out {= - out.set(counter++); - =} + + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { input in: int state received: bool = false + reaction(in) {= received = true; auto value = *in.get(); @@ -25,6 +25,7 @@ reactor Sink { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; @@ -40,4 +41,4 @@ main reactor { sink = new Sink() src.out ~> sink.in -} \ No newline at end of file +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf index 00ba3dc720..aa9c042502 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf @@ -1,21 +1,21 @@ target Cpp { - timeout: 1s, + timeout: 1 s, workers: 1 } reactor Src { - timer t(0, 100ms) + timer t(0, 100 ms) output out: int state counter: int = 0 - reaction(t) -> out {= - out.set(counter++); - =} + + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 50ms) + timer t(0, 50 ms) input in: int state received: bool = false + reaction(in) {= received = true; auto value = *in.get(); @@ -26,15 +26,15 @@ reactor Sink { exit(1); } =} + reaction(shutdown) {= if(!received) { reactor::log::Error() << "Nothing received."; exit(1); } =} - reaction(t) {= - reactor::log::Info() << "Tick"; - =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { @@ -44,4 +44,4 @@ main reactor { sink = new Sink() src.out ~> sink.in -} \ No newline at end of file +} From 8228827769fe9d84916e73c3271720b276c0bf08 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 19 Mar 2023 19:33:14 -0700 Subject: [PATCH 065/709] saving before checkout out klighd-workaround --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- org.lflang/src/org/lflang/generator/c/CReactionGenerator.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 2ef5074455..e7ce2439f8 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -473,7 +473,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { super.doGenerate(resource, context); if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; if (!isOSCompatible()) return; // Incompatible OS and configuration - if (!isWatchdogCompatible()) return; + // if (!isWatchdogCompatible()) return; // Perform set up that does not generate code setUpGeneralParameters(); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 152413f10c..5af962c9d9 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -36,7 +36,6 @@ import org.lflang.lf.Variable; import org.lflang.lf.Watchdog; import org.lflang.util.StringUtil; -import org.lflang.lf.Watchdog; public class CReactionGenerator { protected static String DISABLE_REACTION_INITIALIZATION_MARKER From 2af0fa75dcbd61842f58e4bf330c47a67d624545 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Sun, 19 Mar 2023 19:33:38 -0700 Subject: [PATCH 066/709] saving before klighd workaround --- test/C/src/Watchdog.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index 0dd2436478..e3d7f6cb41 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -26,7 +26,7 @@ main reactor { reaction(a) -> w.x {= lf_set(w.x, 0); - lf_nanosleep(MSEC(40)); + lf_nanosleep(MSEC(90)); =} reaction(w.d) {= printf("Deadline reactor produced an output.\n"); =} From 9c114c347424ad0741c88c2487dae85299a30669 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 20 Mar 2023 09:29:03 +0100 Subject: [PATCH 067/709] fix NPE --- .../src/org/lflang/generator/cpp/CppPortGenerator.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt index 79dd4ad93a..990ede56c6 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt @@ -47,10 +47,11 @@ class CppPortGenerator(private val reactor: Reactor) { val VarRef.dataType: String get() { val variableRef = when { - this == null -> "" - container.isBank && container.isEnclave -> "${container.name}[0]->__lf_instance->${variable.name}" - container.isBank && !container.isEnclave -> "${container.name}[0]->${variable.name}" - else -> this.name + this == null -> "" + container == null -> this.name + container.isBank && container.isEnclave -> "${container.name}[0]->__lf_instance->${variable.name}" + container.isBank && !container.isEnclave -> "${container.name}[0]->${variable.name}" + else -> this.name } val multiportRef = if (isMultiport) "$variableRef[0]" else variableRef return "std::remove_reference::type::value_type" From be2a4c9fcd6adf00ff28735b1d08d0411c95ab33 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 20 Mar 2023 13:12:54 -0700 Subject: [PATCH 068/709] some changes to code review --- org.lflang/src/org/lflang/generator/c/CReactionGenerator.java | 4 +--- org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 5af962c9d9..e7e43a903c 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -684,9 +684,7 @@ public static String generateWatchdogVariablesInReaction( String watchdogName = watchdog.getName(); return String.join("\n", List.of( - "#ifdef LF_THREADED", - " watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");", - "#endif" + "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");" )); } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 72892e8e6b..344209c3b8 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -202,6 +202,7 @@ public static String generateLfInitializeWatchdogMutexes(int watchdogCount) { " self_base_t* current_base = _lf_watchdogs[i]->base;", " if (&(current_base->watchdog_mutex) == NULL) {", " lf_mutex_init(&(current_base->watchdog_mutex));", + " current_base->has_watchdog = true;", " }", " }" )); From 85a21efa41692e3d97a1d08b1d085a3d44051c1f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 21 Mar 2023 10:05:51 +0100 Subject: [PATCH 069/709] disable keepalive warning in C++ --- org.lflang/src/org/lflang/Target.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/src/org/lflang/Target.java index c3bfda067a..59398963cd 100644 --- a/org.lflang/src/org/lflang/Target.java +++ b/org.lflang/src/org/lflang/Target.java @@ -527,7 +527,7 @@ public String getSingleLineCommentPrefix() { * program (and keepalive was not explicitly unset by the user). */ public boolean setsKeepAliveOptionAutomatically() { - return this != Rust; + return this != Rust && this != CPP; } /** From e17852da6683fe140480c6b2d2b416daf2719d22 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 21 Mar 2023 11:53:42 +0100 Subject: [PATCH 070/709] update reactor-cpp and add new tests --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- .../EnclaveSparseUpstreamEventsDelayed.lf | 52 +++++++++++++++++++ .../EnclaveSparseUpstreamEventsPhysical.lf | 52 +++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf create mode 100644 test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 07e74c307e..eecfdd22e7 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 07e74c307ef4378846265c1490ac8144227c5a4d +Subproject commit eecfdd22e71f1f6738403fd6c0bbdd6e137e54d4 diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf new file mode 100644 index 0000000000..341b91dfbe --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf @@ -0,0 +1,52 @@ +// The purpose of this test is to check that the downstream enclave respects the +// after delay when aquiring tags from its upstream. +target Cpp { + timeout: 10 s, + workers: 1 +} + +reactor Src { + timer t(0, 2 s) + output out: int + state counter: int = 0 + + reaction(t) -> out {= out.set(counter++); =} +} + +reactor Sink { + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s + 2s * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in after 2 s +} diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf new file mode 100644 index 0000000000..f48445f369 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf @@ -0,0 +1,52 @@ +// The purpose of this test is to check that the downstream enclave advances +// time independenty of the upstraem if the connection is physical. +target Cpp { + timeout: 10 s, + workers: 1 +} + +reactor Src { + timer t(0, 2 s) + output out: int + state counter: int = 0 + + reaction(t) -> out {= out.set(counter++); =} +} + +reactor Sink { + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out ~> sink.in +} From 97632d816cfe0afca7917761166185d4d99a07f2 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 21 Mar 2023 14:18:48 +0100 Subject: [PATCH 071/709] update reactor-cpp and at tests covering sparse upstream events --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- .../enclave/EnclaveSparseUpstreamEvents.lf | 52 +++++++++++++ .../EnclaveSparseUpstreamEventsDelayed.lf | 2 +- .../EnclaveSparseUpstreamEventsPhysical.lf | 2 +- .../enclave/EnclaveUpstreamPhysicalAction.lf | 76 +++++++++++++++++++ 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf create mode 100644 test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index eecfdd22e7..b260ebc83c 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit eecfdd22e71f1f6738403fd6c0bbdd6e137e54d4 +Subproject commit b260ebc83cea97335e984d1eb26d6b581e900280 diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf new file mode 100644 index 0000000000..a65abc3533 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf @@ -0,0 +1,52 @@ +// The purpose of this test is to check that the downstream enclave can progress, even if there +// are only sparse upstream events. +target Cpp { + timeout: 6 s, + workers: 1 +} + +reactor Src { + timer t(0, 2 s) + output out: int + state counter: int = 0 + + reaction(t) -> out {= out.set(counter++); =} +} + +reactor Sink { + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in +} diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf index 341b91dfbe..e299f921ad 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf @@ -1,7 +1,7 @@ // The purpose of this test is to check that the downstream enclave respects the // after delay when aquiring tags from its upstream. target Cpp { - timeout: 10 s, + timeout: 6 s, workers: 1 } diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf index f48445f369..6e1e579bd0 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf @@ -1,7 +1,7 @@ // The purpose of this test is to check that the downstream enclave advances // time independenty of the upstraem if the connection is physical. target Cpp { - timeout: 10 s, + timeout: 6 s, workers: 1 } diff --git a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf new file mode 100644 index 0000000000..2da36c03b6 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf @@ -0,0 +1,76 @@ +// The purpose of this test is to check that the downstream enclave can progress, even if there +// are only sparse upstream events. +target Cpp { + timeout: 10 s, + workers: 1 +} + +reactor Src { + public preamble {= + #include + =} + + state thread: std::thread{} + + physical action a: int + output out: int + + reaction(startup) -> a {= + // start new thread + this->thread = std::thread([&] () { + for (int i{0}; i < 3; i++) { + a.schedule(i); + std::this_thread::sleep_for(2s); + } + }); + =} + + reaction(a) -> out {= + out.set(a.get()); + =} + + reaction(shutdown) {= + // make sure to join the thread before shutting down + if(thread.joinable()) { + thread.join(); + } + =} +} + +reactor Sink { + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in +} From 364230e4ffcbebdf0efae18b0f12a9cd09b63c8f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 20 Mar 2023 18:52:44 -0700 Subject: [PATCH 072/709] Start adding templates to C target. WIP. --- org.lflang/src/org/lflang/ASTUtils.java | 15 ++- .../org/lflang/generator/ReactorInstance.java | 7 ++ .../lflang/generator/c/CActionGenerator.java | 13 +-- .../org/lflang/generator/c/CGenerator.java | 105 +++++++----------- .../lflang/generator/c/CPortGenerator.java | 45 +++----- .../src/org/lflang/generator/c/CUtil.java | 10 +- .../generator/c/TypeParameterizedReactor.java | 41 +++++++ .../generator/python/PythonGenerator.java | 3 +- test/C/src/generics/Template.lf | 13 +++ 9 files changed, 145 insertions(+), 107 deletions(-) create mode 100644 org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java create mode 100644 test/C/src/generics/Template.lf diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 16f3182056..ed9daf5def 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -379,6 +379,15 @@ public static List allInstantiations(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); } + public static List allChildInstances(Reactor definition, ErrorReporter reporter) { + return allInstantiations(definition).stream().map(it -> new ReactorInstance( + it, + null, + reporter, + 0 + )).collect(Collectors.toList()); + } + /** * Given a reactor class, return a list of all its methods, * which includes methods of base classes that it extends. @@ -448,9 +457,9 @@ public static List allModes(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); } - public static List recursiveChildren(ReactorInstance r) { - List ret = new ArrayList<>(); - ret.add(r.reactorDefinition); + public static List recursiveChildren(ReactorInstance r) { + List ret = new ArrayList<>(); + ret.add(r); for (var child: r.children) { ret.addAll(recursiveChildren(child)); } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index a45fb1d1fb..af295818b3 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -42,6 +42,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.ErrorReporter; import org.lflang.TimeValue; import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; @@ -59,10 +60,13 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.Timer; +import org.lflang.lf.Type; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; +import com.google.common.collect.ImmutableMap; + /** * Representation of a compile-time instance of a reactor. @@ -159,6 +163,8 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re /** Indicator that this reactor has itself as a parent, an error condition. */ public final boolean recursive; + public final TypeParameterizedReactor tpr; + ////////////////////////////////////////////////////// //// Public methods. @@ -770,6 +776,7 @@ private ReactorInstance( this.reporter = reporter; this.reactorDeclaration = definition.getReactorClass(); this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); + this.tpr = new TypeParameterizedReactor(definition); // check for recursive instantiation var currentParent = parent; diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index dee3576d03..e381ad9bae 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -91,19 +91,17 @@ public static String generateTokenInitializer( /** * Generate the declarations of actions in the self struct * - * @param reactor The reactor to generate declarations for - * @param decl The reactor's declaration * @param body The content of the self struct * @param constructorCode The constructor code of the reactor */ public static void generateDeclarations( - Reactor reactor, + TypeParameterizedReactor tpr, CodeBuilder body, CodeBuilder constructorCode ) { - for (Action action : ASTUtils.allActions(reactor)) { + for (Action action : ASTUtils.allActions(tpr.r())) { var actionName = action.getName(); - body.pr(action, CGenerator.variableStructType(action, reactor, false)+" _lf_"+actionName+";"); + body.pr(action, CGenerator.variableStructType(action, tpr, false)+" _lf_"+actionName+";"); // Initialize the trigger pointer in the action. constructorCode.pr(action, "self->_lf_"+actionName+".trigger = &self->_lf__"+actionName+";"); } @@ -113,7 +111,6 @@ public static void generateDeclarations( * Generate the struct type definitions for the action of the * reactor * - * @param decl The reactor declaration * @param action The action to generate the struct for * @param target The target of the code generation (C, CCpp or Python) * @param types The helper object for types related stuff @@ -121,7 +118,7 @@ public static void generateDeclarations( * @return The auxiliary struct for the port as a string */ public static String generateAuxiliaryStruct( - Reactor r, + TypeParameterizedReactor tpr, Action action, Target target, CTypes types, @@ -146,7 +143,7 @@ public static String generateAuxiliaryStruct( code.pr(valueDeclaration(action, target, types)); code.pr(federatedExtension.toString()); code.unindent(); - code.pr("} " + variableStructType(action, r, userFacing) + ";"); + code.pr("} " + variableStructType(action, tpr, userFacing) + ";"); return code.toString(); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b45779b7a7..0b5602d9d9 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -43,6 +43,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -96,6 +97,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; +import org.lflang.lf.Type; import org.lflang.lf.Variable; import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; @@ -523,6 +525,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { if (targetConfig.platformOptions.platform != Platform.ARDUINO) { var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; var sources = new HashSet<>(ASTUtils.recursiveChildren(main)).stream() + .map(ReactorInstance::getTypeParameterizedReactor) .map(CUtil::getName).map(it -> it + (CCppMode ? ".cpp" : ".c")) .collect(Collectors.toList()); sources.add(cFilename); @@ -912,9 +915,7 @@ public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { } /** - * Generate code for defining all reactors that belong to the federate, - * including all the child reactors down the hierarchy. Duplicate - * Duplicates are avoided. + * Generate code for defining all instantiated reactors. * * Imported reactors' original .lf file is * incorporated in the following manner: @@ -923,29 +924,12 @@ public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { * - If there are any preambles, add them to the preambles of the reactor. */ private void generateReactorDefinitions() throws IOException { - var generatedReactors = new LinkedHashSet(); + var generatedReactors = new LinkedHashSet(); if (this.main != null) { generateReactorChildren(this.main, generatedReactors); + generateReactorClass(this.main.getTypeParameterizedReactor()); } - - if (this.mainDef != null) { - generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); - } - - if (mainDef == null) { - // Generate code for each reactor that was not instantiated in main or its children. - for (Reactor r : reactors) { - // Get the declarations for reactors that are instantiated somewhere. - // A declaration is either a reactor definition or an import statement.; - var declarations = this.instantiationGraph.getDeclarations(r); - // If the reactor has no instantiations and there is no main reactor, then - // generate code for it anyway (at a minimum, this means that the compiler is invoked - // so that reaction bodies are checked). - if (declarations.isEmpty()) { - generateReactorClass(r); - } - } - } + // do not generate code for reactors that are not instantiated } private void generateHeaders() throws IOException { @@ -975,15 +959,16 @@ private void generateHeaders() throws IOException { */ private void generateReactorChildren( ReactorInstance reactor, - LinkedHashSet generatedReactors + LinkedHashSet generatedReactors ) throws IOException { for (ReactorInstance r : reactor.children) { + var newTpr = r.tpr; if (r.reactorDeclaration != null && - !generatedReactors.contains(r.reactorDefinition)) { - generatedReactors.add(r.reactorDefinition); + !generatedReactors.contains(newTpr)) { + generatedReactors.add(newTpr); generateReactorChildren(r, generatedReactors); inspectReactorEResource(r.reactorDeclaration); - generateReactorClass(r.reactorDefinition); + generateReactorClass(newTpr); } } } @@ -1036,53 +1021,50 @@ protected void copyTargetFiles() throws IOException { * if the main reactor has reactions, these reactions * will not be generated if they are triggered by or send * data to contained reactors that are not in the federate. - * @param reactor The parsed reactor data structure. */ - private void generateReactorClass(Reactor reactor) throws IOException { + private void generateReactorClass(TypeParameterizedReactor tpr) throws IOException { // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. CodeBuilder header = new CodeBuilder(); CodeBuilder src = new CodeBuilder(); - final String headerName = CUtil.getName(reactor) + ".h"; + final String headerName = CUtil.getName(tpr) + ".h"; var guardMacro = headerName.toUpperCase().replace(".", "_"); header.pr("#ifndef " + guardMacro); header.pr("#define " + guardMacro); - generateReactorClassHeaders(reactor, headerName, header, src); - header.pr(generateTopLevelPreambles(reactor)); - generateUserPreamblesForReactor(reactor, src); - generateReactorClassBody(reactor, header, src); + generateReactorClassHeaders(tpr, headerName, header, src); + header.pr(generateTopLevelPreambles(tpr.r())); + generateUserPreamblesForReactor(tpr.r(), src); + generateReactorClassBody(tpr, header, src); header.pr("#endif // " + guardMacro); FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); - var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : (CCppMode ? ".cpp" : ".c"); - FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); + var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" + : (CCppMode ? ".cpp" : ".c"); + FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve( + CUtil.getName(reactor) + extension), true); } - protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { + protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { if (CCppMode) { src.pr("extern \"C\" {"); header.pr("extern \"C\" {"); } + tpr.typeArgs().entrySet().forEach(it -> src.pr("#define " + it.getKey() + " " + ASTUtils.toText(it.getValue()))); header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); - generateIncludes(reactor); + generateIncludes(tpr.r()); if (CCppMode) { src.pr("}"); header.pr("}"); } - src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(fileConfig, reactor) + "\""); + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(fileConfig, tpr.r()) + "\""); src.pr("#include \"" + headerName + "\""); - Stream.concat( - reactor.getInstantiations().stream(), - reactor.getModes().stream().flatMap(it -> it.getInstantiations().stream()) - ) - .collect(Collectors.toSet()).stream() - .map(Instantiation::getReactorClass) - .map(ASTUtils::toDefinition).map(CUtil::getName) + new HashSet<>(ASTUtils.allInstantiations(tpr.r())).stream() + .map(TypeParameterizedReactor::new).map(CUtil::getName) .map(name -> "#include \"" + name + ".h\"") .forEach(header::pr); } - private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { + private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder header, CodeBuilder src) { // Some of the following methods create lines of code that need to // go into the constructor. Collect those lines of code here: var constructorCode = new CodeBuilder(); @@ -1137,7 +1119,7 @@ protected void generateIncludes(Reactor r) { * Generate the struct type definitions for inputs, outputs, and * actions of the specified reactor. */ - protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { + protected void generateAuxiliaryStructs(CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing) { // In the case where there are incoming // p2p logical connections in decentralized // federated execution, there will be an @@ -1155,9 +1137,9 @@ protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean #endif """.formatted(types.getTargetTagType(), types.getTargetTimeType()) ); - for (Port p : allPorts(r)) { + for (Port p : allPorts(tpr.r())) { builder.pr(CPortGenerator.generateAuxiliaryStruct( - r, + tpr, p, getTarget(), errorReporter, @@ -1169,9 +1151,9 @@ protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean // The very first item on this struct needs to be // a trigger_t* because the struct will be cast to (trigger_t*) // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(r)) { + for (Action action : allActions(tpr.r())) { builder.pr(CActionGenerator.generateAuxiliaryStruct( - r, + tpr, action, getTarget(), types, @@ -1184,20 +1166,19 @@ protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean /** * Generate the self struct type definition for the specified reactor * in the specified federate. - * @param decl The parsed reactor data structure. * @param constructorCode Place to put lines of code that need to * go into the constructor. */ - private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { - var reactor = toDefinition(decl); - var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); + private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tpr, CodeBuilder constructorCode) { + var reactor = toDefinition(tpr.r()); + var selfType = CUtil.selfType(tpr); // Construct the typedef for the "self" struct. // Create a type name for the self struct. var body = new CodeBuilder(); // Extensions can add functionality to the CGenerator - generateSelfStructExtension(body, decl, constructorCode); + generateSelfStructExtension(body, reactor, constructorCode); // Next handle parameters. body.pr(CParameterGenerator.generateDeclarations(reactor, types)); @@ -1206,10 +1187,10 @@ private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuild body.pr(CStateGenerator.generateDeclarations(reactor, types)); // Next handle actions. - CActionGenerator.generateDeclarations(reactor, body, constructorCode); + CActionGenerator.generateDeclarations(tpr, body, constructorCode); // Next handle inputs and outputs. - CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); + CPortGenerator.generateDeclarations(tpr, reactor, body, constructorCode); // If there are contained reactors that either receive inputs // from reactions of this reactor or produce outputs that trigger @@ -1387,7 +1368,7 @@ private void generateInteractingContainedReactors( */ protected void generateSelfStructExtension( CodeBuilder body, - ReactorDecl decl, + Reactor reactor, CodeBuilder constructorCode ) { // Do nothing @@ -1666,8 +1647,8 @@ public void processProtoFile(String filename) { * This is required to be the same as the type name returned by * {@link #variableStructType(TriggerInstance)}. */ - public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { - return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) +"_"+variable.getName()+"_t"; + public static String variableStructType(Variable variable, TypeParameterizedReactor tpr, boolean userFacing) { + return (userFacing ? tpr.getName().toLowerCase() : CUtil.getName(tpr)) +"_"+variable.getName()+"_t"; } /** diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index cf6ea06b64..accda01fb1 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -11,6 +11,8 @@ import org.lflang.lf.Port; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; +import org.lflang.lf.Type; + import static org.lflang.generator.c.CGenerator.variableStructType; @@ -24,27 +26,21 @@ public class CPortGenerator { /** * Generate fields in the self struct for input and output ports - * - * @param reactor - * @param decl - * @param body - * @param constructorCode */ public static void generateDeclarations( - Reactor reactor, + TypeParameterizedReactor tpr, ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode ) { - generateInputDeclarations(reactor, decl, body, constructorCode); - generateOutputDeclarations(reactor, decl, body, constructorCode); + generateInputDeclarations(tpr, decl, body, constructorCode); + generateOutputDeclarations(tpr, decl, body, constructorCode); } /** * Generate the struct type definitions for the port of the * reactor * - * @param decl The reactor declaration * @param port The port to generate the struct * @param target The target of the code generation (C, CCpp or Python) * @param errorReporter The error reporter @@ -53,7 +49,7 @@ public static void generateDeclarations( * @return The auxiliary struct for the port as a string */ public static String generateAuxiliaryStruct( - Reactor decl, + TypeParameterizedReactor tpr, Port port, Target target, ErrorReporter errorReporter, @@ -80,7 +76,7 @@ public static String generateAuxiliaryStruct( code.pr(valueDeclaration(port, target, errorReporter, types)); code.pr(federatedExtension.toString()); code.unindent(); - code.pr("} "+variableStructType(port, decl, userFacing)+";"); + code.pr("} "+variableStructType(port, tpr, userFacing)+";"); return code.toString(); } @@ -201,31 +197,31 @@ private static String valueDeclaration( * */ private static void generateInputDeclarations( - Reactor reactor, + TypeParameterizedReactor tpr, ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode ) { - for (Input input : ASTUtils.allInputs(reactor)) { + for (Input input : ASTUtils.allInputs(tpr.r())) { var inputName = input.getName(); if (ASTUtils.isMultiport(input)) { body.pr(input, String.join("\n", "// Multiport input array will be malloc'd later.", - variableStructType(input, reactor, false)+"** _lf_"+inputName+";", + variableStructType(input, tpr, false)+"** _lf_"+inputName+";", "int _lf_"+inputName+"_width;", "// Default input (in case it does not get connected)", - variableStructType(input, reactor, false)+" _lf_default__"+inputName+";", + variableStructType(input, tpr, false)+" _lf_default__"+inputName+";", "// Struct to support efficiently reading sparse inputs.", "lf_sparse_io_record_t* _lf_"+inputName+"__sparse;" )); } else { // input is not a multiport. body.pr(input, String.join("\n", - variableStructType(input, reactor, false)+"* _lf_"+inputName+";", + variableStructType(input, tpr, false)+"* _lf_"+inputName+";", "// width of -2 indicates that it is not a multiport.", "int _lf_"+inputName+"_width;", "// Default input (in case it does not get connected)", - variableStructType(input, reactor, false)+" _lf_default__"+inputName+";" + variableStructType(input, tpr, false)+" _lf_default__"+inputName+";" )); constructorCode.pr(input, String.join("\n", @@ -238,26 +234,21 @@ private static void generateInputDeclarations( /** * Generate fields in the self struct for output ports - * - * @param reactor - * @param decl - * @param body - * @param constructorCode */ private static void generateOutputDeclarations( - Reactor reactor, + TypeParameterizedReactor tpr, ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode ) { - for (Output output : ASTUtils.allOutputs(reactor)) { + for (Output output : ASTUtils.allOutputs(tpr.r())) { // If the port is a multiport, create an array to be allocated // at instantiation. var outputName = output.getName(); if (ASTUtils.isMultiport(output)) { body.pr(output, String.join("\n", "// Array of output ports.", - variableStructType(output, reactor, false)+"* _lf_"+outputName+";", + variableStructType(output, tpr, false)+"* _lf_"+outputName+";", "int _lf_"+outputName+"_width;", "// An array of pointers to the individual ports. Useful", "// for the lf_set macros to work out-of-the-box for", @@ -265,11 +256,11 @@ private static void generateOutputDeclarations( "// value can be accessed via a -> operator (e.g.,foo[i]->value).", "// So we have to handle multiports specially here a construct that", "// array of pointers.", - variableStructType(output, reactor, false)+"** _lf_"+outputName+"_pointers;" + variableStructType(output, tpr, false)+"** _lf_"+outputName+"_pointers;" )); } else { body.pr(output, String.join("\n", - variableStructType(output, reactor, false)+" _lf_"+outputName+";", + variableStructType(output, tpr, false)+" _lf_"+outputName+";", "int _lf_"+outputName+"_width;" )); } diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 69e9ec30ae..b92f93023d 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -147,9 +147,9 @@ public static String channelIndexName(PortInstance port) { * reactor is main (to allow for instantiations that have the same name as * the main reactor or the .lf file). */ - public static String getName(Reactor reactor) { - String name = reactor.getName().toLowerCase() + reactor.hashCode(); - if (reactor.isMain()) { + public static String getName(TypeParameterizedReactor reactor) { + String name = reactor.r().getName().toLowerCase() + reactor.hashCode(); + if (reactor.r().isMain()) { return name + "_main"; } return name; @@ -516,8 +516,8 @@ public static String runtimeIndex(ReactorInstance reactor) { * @param reactor The reactor class. * @return The type of a self struct for the specified reactor class. */ - public static String selfType(Reactor reactor) { - if (reactor.isMain()) { + public static String selfType(TypeParameterizedReactor reactor) { + if (reactor.r().isMain()) { return "_" + CUtil.getName(reactor) + "_main_self_t"; } return "_" + CUtil.getName(reactor) + "_self_t"; diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java new file mode 100644 index 0000000000..9e79a65728 --- /dev/null +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -0,0 +1,41 @@ +package org.lflang.generator.c; + + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import org.lflang.ASTUtils; +import org.lflang.lf.Instantiation; +import org.lflang.lf.Reactor; +import org.lflang.lf.Type; + +import com.google.common.collect.ImmutableMap; + +public record TypeParameterizedReactor(Reactor r, Map typeArgs) { + + public TypeParameterizedReactor(Instantiation i) { + this(ASTUtils.toDefinition(i.getReactorClass()), addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); + } + + private static ImmutableMap addTypeArgs(Instantiation instantiation, Reactor r) { + HashMap ret = new HashMap<>(); + if (instantiation.getTypeArgs() != null) { + for (int i = 0; i < r.getTypeParms().size(); i++) { + ret.put(r.getTypeParms().get(i).getLiteral(), instantiation.getTypeArgs().get(i)); + } + } + return ImmutableMap.copyOf(ret); + } + + public String getName() { + // FIXME: Types that are not just a single token need to be escaped or hashed + return r.getName() + typeArgs.values().stream().map(ASTUtils::toText).collect(Collectors.joining("_")); + } + + @Override + public int hashCode() { + return r.hashCode() * 31 + typeArgs.hashCode(); + } +} diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 7a23b79b21..b20a5d9de2 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -544,10 +544,9 @@ protected void generateReactorInstanceExtension( @Override protected void generateSelfStructExtension( CodeBuilder selfStructBody, - ReactorDecl decl, + Reactor reactor, CodeBuilder constructorCode ) { - Reactor reactor = ASTUtils.toDefinition(decl); // Add the name field selfStructBody.pr("char *_lf_name;"); int reactionIndex = 0; diff --git a/test/C/src/generics/Template.lf b/test/C/src/generics/Template.lf new file mode 100644 index 0000000000..3d483098b9 --- /dev/null +++ b/test/C/src/generics/Template.lf @@ -0,0 +1,13 @@ +target C + +reactor Hello { + state count: T(0) + reaction(startup) {= + self->count = self->count + 1; + printf("Hello World %d\n", (int) self->count); + =} +} + +main reactor Template { + hello = new Hello(); +} From 4d8bf85169673094289ea34340e02ad0035c3d1b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 24 Mar 2023 12:08:03 +0100 Subject: [PATCH 073/709] format tests --- .../src/enclave/EnclaveSparseUpstreamEvents.lf | 4 ++-- .../enclave/EnclaveUpstreamPhysicalAction.lf | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf index a65abc3533..3bade0f63e 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf @@ -1,5 +1,5 @@ -// The purpose of this test is to check that the downstream enclave can progress, even if there -// are only sparse upstream events. +// The purpose of this test is to check that the downstream enclave can +// progress, even if there are only sparse upstream events. target Cpp { timeout: 6 s, workers: 1 diff --git a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf index 2da36c03b6..18ac74b091 100644 --- a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf +++ b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf @@ -1,5 +1,5 @@ -// The purpose of this test is to check that the downstream enclave can progress, even if there -// are only sparse upstream events. +// The purpose of this test is to check that the downstream enclave can +// progress, even if there are only sparse upstream events. target Cpp { timeout: 10 s, workers: 1 @@ -11,11 +11,11 @@ reactor Src { =} state thread: std::thread{} - + physical action a: int output out: int - reaction(startup) -> a {= + reaction(startup) -> a {= // start new thread this->thread = std::thread([&] () { for (int i{0}; i < 3; i++) { @@ -25,9 +25,7 @@ reactor Src { }); =} - reaction(a) -> out {= - out.set(a.get()); - =} + reaction(a) -> out {= out.set(a.get()); =} reaction(shutdown) {= // make sure to join the thread before shutting down @@ -60,7 +58,10 @@ reactor Sink { } =} - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reaction(t) {= + reactor::log::Info() << "Tick - " << "logical time: " << get_elapsed_logical_time() + << "; physical time: " << get_elapsed_physical_time(); + =} deadline(1 s) {= reactor::log::Error() << "Deadline violated."; exit(2); =} From d87274fa43e9efd40636714e4599e5946df066b5 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 10:53:09 +0100 Subject: [PATCH 074/709] Align lingua-franca/watchdogs with reactor-c/watchdogs --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ff3c84c36b..8ca094f356 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ff3c84c36b2d7fbcbe09fafa577ec94f75194e83 +Subproject commit 8ca094f35616f0024534ff9a2d46e6c03440a8ef From aaa73689f641a3fd1ddf9b5a4ab45dc543aa27cc Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:05:24 +0100 Subject: [PATCH 075/709] Merged master in watchdogs --- .github/actions/setup-ros2/action.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- gradle/source-layout.gradle | 20 +- lib/scripts/launch-fedsd.sh | 103 ++++++ org.lflang.tests/build.gradle | 6 +- .../tests/compiler/TargetConfigTests.java | 102 ++++++ org.lflang/build.gradle | 22 +- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/ts/package.json | 2 +- org.lflang/src/org/lflang/TargetConfig.java | 90 ++++- org.lflang/src/org/lflang/TargetProperty.java | 5 +- .../src/org/lflang/ast/FormattingUtils.java | 4 +- .../federated/extensions/CExtension.java | 33 +- .../federated/extensions/CExtensionUtils.java | 14 +- .../extensions/FedTargetExtension.java | 14 +- .../extensions/FedTargetExtensionFactory.java | 4 +- .../federated/extensions/TSExtension.java | 47 ++- .../federated/generator/FedASTUtils.java | 18 +- .../federated/generator/FedEmitter.java | 11 +- .../federated/generator/FedFileConfig.java | 45 ++- .../federated/generator/FedGenerator.java | 267 +++++++-------- .../federated/generator/FedImportEmitter.java | 2 +- .../federated/generator/FedMainEmitter.java | 2 +- .../generator/FedPreambleEmitter.java | 7 +- .../generator/FedReactorEmitter.java | 2 +- .../federated/generator/FedTargetConfig.java | 78 +++++ .../federated/generator/FedTargetEmitter.java | 85 +---- .../federated/generator/FederateInstance.java | 17 +- .../federated/launcher/BuildConfig.java | 60 ++++ .../{FedCLauncher.java => CBuildConfig.java} | 57 +--- .../launcher/FedLauncherFactory.java | 64 ---- ...auncher.java => FedLauncherGenerator.java} | 130 ++++---- .../federated/launcher/FedPyLauncher.java | 83 ----- .../federated/launcher/PyBuildConfig.java | 22 ++ .../lflang/federated/launcher/RtiConfig.java | 92 +++++ ...{FedTSLauncher.java => TsBuildConfig.java} | 37 +-- .../org/lflang/generator/GeneratorUtils.java | 95 +----- .../src/org/lflang/generator/MainContext.java | 4 +- .../org/lflang/generator/ts/TSGenerator.kt | 6 +- org.lflang/src/org/lflang/util/Averager.java | 27 ++ .../SimpleFederatedAuthenticated.lf | 0 util/tracing/README.md | 6 + util/tracing/makefile | 2 + util/tracing/trace_to_chrome.c | 52 ++- util/tracing/trace_to_csv.c | 115 +++++-- util/tracing/trace_to_influxdb.c | 16 +- util/tracing/trace_util.c | 127 +++---- util/tracing/trace_util.h | 31 +- util/tracing/visualization/.gitignore | 1 + util/tracing/visualization/README.md | 25 ++ util/tracing/visualization/fedsd.py | 314 ++++++++++++++++++ util/tracing/visualization/fedsd_helper.py | 241 ++++++++++++++ 52 files changed, 1758 insertions(+), 855 deletions(-) create mode 100755 lib/scripts/launch-fedsd.sh create mode 100644 org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java create mode 100644 org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java create mode 100644 org.lflang/src/org/lflang/federated/launcher/BuildConfig.java rename org.lflang/src/org/lflang/federated/launcher/{FedCLauncher.java => CBuildConfig.java} (56%) delete mode 100644 org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java rename org.lflang/src/org/lflang/federated/launcher/{FedLauncher.java => FedLauncherGenerator.java} (86%) delete mode 100644 org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java create mode 100644 org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java create mode 100644 org.lflang/src/org/lflang/federated/launcher/RtiConfig.java rename org.lflang/src/org/lflang/federated/launcher/{FedTSLauncher.java => TsBuildConfig.java} (68%) create mode 100644 org.lflang/src/org/lflang/util/Averager.java rename test/C/src/federated/{ => failing}/SimpleFederatedAuthenticated.lf (100%) create mode 100644 util/tracing/visualization/.gitignore create mode 100644 util/tracing/visualization/README.md create mode 100644 util/tracing/visualization/fedsd.py create mode 100644 util/tracing/visualization/fedsd_helper.py diff --git a/.github/actions/setup-ros2/action.yml b/.github/actions/setup-ros2/action.yml index ac2a0b0d15..54b77b841a 100644 --- a/.github/actions/setup-ros2/action.yml +++ b/.github/actions/setup-ros2/action.yml @@ -9,6 +9,6 @@ runs: # see https://github.com/ros-tooling/setup-ros/issues/80 and https://github.com/ros2/rmw_cyclonedds/pull/134 run: sed -e 's/azure.archive.ubuntu.com/us.archive.ubuntu.com/g' -e t -e d /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/nonazure.list - name: Setup ROS2 - uses: lhstrh/setup-ros@master + uses: ros-tooling/setup-ros@0.6.1 with: required-ros-distributions: rolling diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 24e40b7eef..83c04d8cf7 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,7 +28,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: diff --git a/gradle/source-layout.gradle b/gradle/source-layout.gradle index 2aab84e0eb..9bbe4b3944 100644 --- a/gradle/source-layout.gradle +++ b/gradle/source-layout.gradle @@ -6,14 +6,8 @@ if (name.endsWith(".tests")) { resources.srcDirs = [] } test { - java { - srcDirs = ['src', 'src-gen'] - exclude "org/lflang/diagram/**" - } - kotlin { - srcDirs = ['src', 'src-gen'] - exclude "org/lflang/diagram/**" - } + java.srcDirs = ['src', 'src-gen'] + kotlin.srcDirs = ['src', 'src-gen'] resources.srcDirs = ['src', 'src-gen'] xtendOutputDir = 'xtend-gen' } @@ -21,14 +15,8 @@ if (name.endsWith(".tests")) { } else { sourceSets { main { - java { - srcDirs = ['src', 'src-gen'] - exclude "org/lflang/diagram/**" - } - kotlin { - srcDirs = ['src', 'src-gen'] - exclude "org/lflang/diagram/**" - } + java.srcDirs = ['src', 'src-gen'] + kotlin.srcDirs = ['src', 'src-gen'] xtendOutputDir = 'xtend-gen' resources { srcDirs = ['src', 'src-gen'] diff --git a/lib/scripts/launch-fedsd.sh b/lib/scripts/launch-fedsd.sh new file mode 100755 index 0000000000..e09c60fc1e --- /dev/null +++ b/lib/scripts/launch-fedsd.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +#============================================================================ +# Description: Visualize federated trace data for RTI-federate interactions. +# Authors: Chadlia Jerad +# Edward A. Lee +# Usage: Usage: fedsd -r [rti.csv] -f [fed.csv ...] +#============================================================================ + +#============================================================================ +# Preamble +#============================================================================ + +# Copied from build.sh FIXME: How to avoid copying + +# Find the directory in which this script resides in a way that is compatible +# with MacOS, which has a `readlink` implementation that does not support the +# necessary `-f` flag to canonicalize by following every symlink in every +# component of the given name recursively. +# This solution, adapted from an example written by Geoff Nixon, is POSIX- +# compliant and robust to symbolic links. If a chain of more than 1000 links +# is encountered, we return. +find_dir() ( + start_dir=$PWD + cd "$(dirname "$1")" + link=$(readlink "$(basename "$1")") + count=0 + while [ "${link}" ]; do + if [[ "${count}" -lt 1000 ]]; then + cd "$(dirname "${link}")" + link=$(readlink "$(basename "$1")") + ((count++)) + else + return + fi + done + real_path="$PWD/$(basename "$1")" + cd "${start_dir}" + echo `dirname "${real_path}"` +) + +# Report fatal error and exit. +function fatal_error() { + 1>&2 echo -e "\e[1mfedsd: \e[31mfatal error: \e[0m$1" + exit 1 +} + +abs_path="$(find_dir "$0")" + +if [[ "${abs_path}" ]]; then + base=`dirname $(dirname ${abs_path})` +else + fatal_error "Unable to determine absolute path to $0." +fi + +# Get the lft files +lft_files_list=$@ + +if [ -z "$lft_files_list" ] +then + echo "Usage: fedsd [lft files]" + exit 1 +fi + +# Initialize variables +csv_files_list='' +extension='.csv' +rti_csv_file='' + +# Iterate over the lft file list to: +# - First, transform into csv +# - Second, construct the csv fiel name +# - Then construct the csv file list +# The csv file list does include the rti, it is put in a separate variable +for each_lft_file in $lft_files_list + do + # Tranform to csv + trace_to_csv $each_lft_file + # Get the file name + csv=${each_lft_file%.*} + if [ $csv == 'rti' ] + then + # Set the rti csv file + rti_csv_file='rti.csv' + else + # Construct the csv file name and add it to the list + csv_files_list="$csv$extension $csv_files_list" + fi + done + +# echo $lft_files_list +# echo $rti_csv_file +# echo $csv_files_list + +# FIXME: Check that python3 is in the path. +if [ $rti_csv_file == '' ] +then + # FIXME: Support the case where no rti file is given + python3 "${base}/util/tracing/visualization/fedsd.py" "-f" $csv_files_list +else + echo Building the communication diagram for the following trace files: $lft_files_list in trace_svg.html + python3 "${base}/util/tracing/visualization/fedsd.py" "-r" "$rti_csv_file" "-f" $csv_files_list +fi diff --git a/org.lflang.tests/build.gradle b/org.lflang.tests/build.gradle index bdb279d61d..020a3a8395 100644 --- a/org.lflang.tests/build.gradle +++ b/org.lflang.tests/build.gradle @@ -1,9 +1,9 @@ repositories { mavenCentral() // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - //maven { - // url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - //} + maven { + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + } } dependencies { implementation project(':org.lflang') diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java new file mode 100644 index 0000000000..593e302d25 --- /dev/null +++ b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java @@ -0,0 +1,102 @@ +package org.lflang.tests.compiler; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import java.nio.file.Files; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.extensions.InjectionExtension; +import org.eclipse.xtext.testing.util.ParseHelper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.lflang.federated.generator.FedFileConfig; +import org.lflang.generator.GeneratorUtils; +import org.lflang.generator.LFGenerator; +import org.lflang.generator.LFGeneratorContext.Mode; +import org.lflang.generator.MainContext; +import org.lflang.lf.Model; +import org.lflang.tests.LFInjectorProvider; + +@ExtendWith(InjectionExtension.class) +@InjectWith(LFInjectorProvider.class) + +/** + * Tests for checking that target properties adequately translate into the target configuration. + */ +class TargetConfigTests { + + @Inject + ParseHelper parser; + + @Inject + LFGenerator generator; + + @Inject + JavaIoFileSystemAccess fileAccess; + + @Inject + Provider resourceSetProvider; + + private void assertHasTargetProperty(Model model, String name) { + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.getTarget().getConfig().getPairs().stream().anyMatch( + p -> p.getName().equals(name) + ) + ); + } + + /** + * Check that tracing target property affects the target configuration. + * @throws Exception + */ + @Test + public void testParsing() throws Exception { + assertHasTargetProperty(parser.parse(""" + target C { + tracing: true + } + """), "tracing"); + } + + /** + * Check that when a federation has the "tracing" target property set, the generated federates + * will also have it set. + * @throws Exception + */ + @Test + public void testFederation() throws Exception { + fileAccess.setOutputPath("src-gen"); + + Model federation = parser.parse(""" + target C { + tracing: true + } + reactor Foo { + + } + federated reactor { + a = new Foo() + b = new Foo() + } + """, URI.createFileURI("tmp/src/Federation.lf"), resourceSetProvider.get()); + assertHasTargetProperty(federation, "tracing"); + + var resource = federation.eResource(); + var context = new MainContext(Mode.STANDALONE, resource, fileAccess, () -> false); + + if (GeneratorUtils.isHostWindows()) return; + + generator.doGenerate(resource, fileAccess, context); + + String lfSrc = Files.readAllLines( + ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("a.lf") + ).stream().reduce("\n", String::concat); + Model federate = parser.parse(lfSrc); + assertHasTargetProperty(federate, "tracing"); + } +} diff --git a/org.lflang/build.gradle b/org.lflang/build.gradle index 5de780bb07..9c6b9bf5d9 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/build.gradle @@ -3,9 +3,9 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar repositories { mavenCentral() // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - //maven { - // url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - //} + maven { + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + } } dependencies { implementation "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}" @@ -20,14 +20,14 @@ dependencies { implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.4' implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.4' implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.4' - //implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:${klighdVersion}") { - // exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' - // exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - //} - //implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:${klighdVersion}") { - // exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' - // exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - //} + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:${klighdVersion}") { + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' + } + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:${klighdVersion}") { + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' + } } configurations { diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 8ca094f356..10c275b99a 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 8ca094f35616f0024534ff9a2d46e6c03440a8ef +Subproject commit 10c275b99a01802f00168b92d4e9068fdf9b34b6 diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 3c368c9481..a1d65a6403 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "0.3.2", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", "@babel/cli": "^7.8.4", "@babel/core": "^7.8.7", "@babel/node": "^7.8.7", diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 446460d5c1..23e99541da 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Properties; import java.util.Set; import org.lflang.TargetProperty.BuildType; @@ -38,7 +39,9 @@ import org.lflang.TargetProperty.LogLevel; import org.lflang.TargetProperty.Platform; import org.lflang.TargetProperty.SchedulerOption; +import org.lflang.TargetProperty.UnionType; import org.lflang.generator.rust.RustTargetConfig; +import org.lflang.lf.KeyValuePair; import org.lflang.lf.TargetDecl; /** @@ -50,12 +53,92 @@ */ public class TargetConfig { + /** + * The target of this configuration (e.g., C, TypeScript, Python). + */ public final Target target; - public TargetConfig(TargetDecl target) { + /** + * Create a new target configuration based on the given target declaration AST node only. + * @param target AST node of a target declaration. + */ + public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can this.target = Target.fromDecl(target); } + /** + * Create a new target configuration based on the given commandline arguments and target + * declaration AST node. + * @param cliArgs Arguments passed on the commandline. + * @param target AST node of a target declaration. + * @param errorReporter An error reporter to report problems. + */ + public TargetConfig( + Properties cliArgs, + TargetDecl target, + ErrorReporter errorReporter + ) { + this(target); + if (target.getConfig() != null) { + List pairs = target.getConfig().getPairs(); + TargetProperty.set(this, pairs != null ? pairs : List.of(), errorReporter); + } + if (cliArgs.containsKey("no-compile")) { + this.noCompile = true; + } + if (cliArgs.containsKey("docker")) { + var arg = cliArgs.getProperty("docker"); + if (Boolean.parseBoolean(arg)) { + this.dockerOptions = new DockerOptions(); + } else { + this.dockerOptions = null; + } + // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. + } + if (cliArgs.containsKey("build-type")) { + this.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); + } + if (cliArgs.containsKey("logging")) { + this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); + } + if (cliArgs.containsKey("workers")) { + this.workers = Integer.parseInt(cliArgs.getProperty("workers")); + } + if (cliArgs.containsKey("threading")) { + this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); + } + if (cliArgs.containsKey("target-compiler")) { + this.compiler = cliArgs.getProperty("target-compiler"); + } + if (cliArgs.containsKey("tracing")) { + this.tracing = new TracingOptions(); + } + if (cliArgs.containsKey("scheduler")) { + this.schedulerType = SchedulerOption.valueOf( + cliArgs.getProperty("scheduler") + ); + this.setByUser.add(TargetProperty.SCHEDULER); + } + if (cliArgs.containsKey("target-flags")) { + this.compilerFlags.clear(); + if (!cliArgs.getProperty("target-flags").isEmpty()) { + this.compilerFlags.addAll(List.of( + cliArgs.getProperty("target-flags").split(" ") + )); + } + } + if (cliArgs.containsKey("runtime-version")) { + this.runtimeVersion = cliArgs.getProperty("runtime-version"); + } + if (cliArgs.containsKey("external-runtime-path")) { + this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); + } + if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { + this.keepalive = Boolean.parseBoolean( + cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); + } + } + /** * Keep track of every target property that is explicitly set by the user. */ @@ -197,9 +280,6 @@ public TargetConfig(TargetDecl target) { * * This is now a wrapped class to account for overloaded definitions * of defining platform (either a string or dictionary of values) - * - * @author Samuel Berkun - * @author Anirudh Rengarajan */ public PlatformOptions platformOptions = new PlatformOptions(); @@ -293,7 +373,7 @@ public static class ClockSyncOptions { public int attenuation = 10; /** - * Whether or not to collect statistics while performing clock synchronization. + * Whether to collect statistics while performing clock synchronization. * This setting is only considered when clock synchronization has been activated. * The default is true. */ diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index f0de831bf4..3f38360d67 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -580,8 +580,7 @@ public enum TargetProperty { }), /** - * Directive to generate a Dockerfile. This is either a boolean, - * true or false, or a dictionary of options. + * Directive to enable tracing. */ TRACING("tracing", UnionType.TRACING_UNION, Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), @@ -974,7 +973,7 @@ public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { * @param config The configuration object to update. * @param properties AST node that holds all the target properties. */ - public static void update(TargetConfig config, List properties,ErrorReporter err) { + public static void update(TargetConfig config, List properties, ErrorReporter err) { properties.forEach(property -> { TargetProperty p = forName(property.getName()); if (p != null) { diff --git a/org.lflang/src/org/lflang/ast/FormattingUtils.java b/org.lflang/src/org/lflang/ast/FormattingUtils.java index bd9fbaf3d8..0e148f218b 100644 --- a/org.lflang/src/org/lflang/ast/FormattingUtils.java +++ b/org.lflang/src/org/lflang/ast/FormattingUtils.java @@ -55,8 +55,8 @@ public static String render(EObject object, int lineLength) { } /** Return a function that renders AST nodes for the given target. */ - public static Function renderer(TargetDecl targetDecl) { - return object -> render(object, DEFAULT_LINE_LENGTH, Target.fromDecl(targetDecl), true); + public static Function renderer(Target target) { + return object -> render(object, DEFAULT_LINE_LENGTH, target, true); } /** diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index d9ed222920..fda727d735 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -45,6 +45,7 @@ import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.generator.CodeBuilder; import org.lflang.generator.GeneratorBase; @@ -83,18 +84,10 @@ public void initializeTargetConfig( int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, - LinkedHashMap federationRTIProperties + RtiConfig rtiConfig ) throws IOException { - if(GeneratorUtils.isHostWindows()) { - errorReporter.reportError( - "Federated LF programs with a C target are currently not supported on Windows. " + - "Exiting code generation." - ); - // Return to avoid compiler errors - return; - } - CExtensionUtils.handleCompileDefinitions(federate, numOfFederates, federationRTIProperties); + CExtensionUtils.handleCompileDefinitions(federate, numOfFederates, rtiConfig); generateCMakeInclude(federate, fileConfig); @@ -488,11 +481,11 @@ public String getNetworkBufferType() { public String generatePreamble( FederateInstance federate, FedFileConfig fileConfig, - LinkedHashMap federationRTIProperties, + RtiConfig rtiConfig, ErrorReporter errorReporter ) throws IOException { // Put the C preamble in a `include/_federate.name + _preamble.h` file - String cPreamble = makePreamble(federate, fileConfig, federationRTIProperties, errorReporter); + String cPreamble = makePreamble(federate, fileConfig, rtiConfig, errorReporter); String relPath = "include" + File.separator + "_" + federate.name + "_preamble.h"; Path fedPreamblePath = fileConfig.getSrcPath().resolve(relPath); Files.createDirectories(fedPreamblePath.getParent()); @@ -509,7 +502,7 @@ public String generatePreamble( protected String makePreamble( FederateInstance federate, FedFileConfig fileConfig, - LinkedHashMap federationRTIProperties, + RtiConfig rtiConfig, ErrorReporter errorReporter) { var code = new CodeBuilder(); @@ -532,7 +525,7 @@ protected String makePreamble( code.pr(generateSerializationPreamble(federate, fileConfig)); - code.pr(generateExecutablePreamble(federate, federationRTIProperties, errorReporter)); + code.pr(generateExecutablePreamble(federate, rtiConfig, errorReporter)); code.pr(generateInitializeTriggers(federate, errorReporter)); @@ -582,12 +575,12 @@ private String generateInitializeTriggers(FederateInstance federate, ErrorReport * Generate code for an executed preamble. * */ - private String generateExecutablePreamble(FederateInstance federate, LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) { + private String generateExecutablePreamble(FederateInstance federate, RtiConfig rtiConfig, ErrorReporter errorReporter) { CodeBuilder code = new CodeBuilder(); code.pr(generateCodeForPhysicalActions(federate, errorReporter)); - code.pr(generateCodeToInitializeFederate(federate, federationRTIProperties)); + code.pr(generateCodeToInitializeFederate(federate, rtiConfig)); code.pr(CExtensionUtils.allocateTriggersForFederate(federate)); @@ -600,10 +593,10 @@ void _lf_executable_preamble() { /** * Generate code to initialize the {@code federate}. - * @param federationRTIProperties Properties related to the RTI. + * @param rtiConfig * @return The generated code */ - private String generateCodeToInitializeFederate(FederateInstance federate, LinkedHashMap federationRTIProperties) { + private String generateCodeToInitializeFederate(FederateInstance federate, RtiConfig rtiConfig) { CodeBuilder code = new CodeBuilder(); code.pr("// ***** Start initializing the federated execution. */"); code.pr(String.join("\n", @@ -672,12 +665,12 @@ private String generateCodeToInitializeFederate(FederateInstance federate, Linke code.pr(String.join("\n", "// Connect to the RTI. This sets _fed.socket_TCP_RTI and _lf_rti_socket_UDP.", - "connect_to_rti("+addDoubleQuotes(federationRTIProperties.get("host").toString())+", "+ federationRTIProperties.get("port")+");" + "connect_to_rti("+addDoubleQuotes(rtiConfig.getHost())+", "+ rtiConfig.getPort()+");" )); // Disable clock synchronization for the federate if it resides on the same host as the RTI, // unless that is overridden with the clock-sync-options target property. - if (CExtensionUtils.clockSyncIsOn(federate, federationRTIProperties)) { + if (CExtensionUtils.clockSyncIsOn(federate, rtiConfig)) { code.pr("synchronize_initial_physical_clock_with_rti(_fed.socket_TCP_RTI);"); } diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index a24bcbae58..aabc77ecd5 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; @@ -17,6 +16,7 @@ import org.lflang.TimeValue; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.CodeBuilder; @@ -239,7 +239,7 @@ static boolean isSharedPtrType(InferredType type, CTypes types) { public static void handleCompileDefinitions( FederateInstance federate, int numOfFederates, - LinkedHashMap federationRTIProperties + RtiConfig rtiConfig ) { federate.targetConfig.setByUser.add(TargetProperty.COMPILE_DEFINITIONS); federate.targetConfig.compileDefinitions.put("FEDERATED", ""); @@ -250,7 +250,7 @@ public static void handleCompileDefinitions( handleAdvanceMessageInterval(federate); - initializeClockSynchronization(federate, federationRTIProperties); + initializeClockSynchronization(federate, rtiConfig); } /** @@ -276,9 +276,9 @@ private static void handleAdvanceMessageInterval(FederateInstance federate) { } } - static boolean clockSyncIsOn(FederateInstance federate, LinkedHashMap federationRTIProperties) { + static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { return federate.targetConfig.clockSync != ClockSyncMode.OFF - && (!federationRTIProperties.get("host").toString().equals(federate.host) + && (!rtiConfig.getHost().equals(federate.host) || federate.targetConfig.clockSyncOptions.localFederatesOn); } @@ -290,10 +290,10 @@ static boolean clockSyncIsOn(FederateInstance federate, LinkedHashMap federationRTIProperties + RtiConfig rtiConfig ) { // Check if clock synchronization should be enabled for this federate in the first place - if (clockSyncIsOn(federate, federationRTIProperties)) { + if (clockSyncIsOn(federate, rtiConfig)) { System.out.println("Initial clock synchronization is enabled for federate " + federate.id ); diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java index 7fb42bf007..7aa13d6cfc 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java @@ -1,21 +1,15 @@ package org.lflang.federated.extensions; import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; import org.lflang.ErrorReporter; -import org.lflang.FileConfig; import org.lflang.InferredType; -import org.lflang.Target; -import org.lflang.TargetConfig; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; -import org.lflang.federated.serialization.SupportedSerializers; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.LFGeneratorContext; import org.lflang.lf.Action; import org.lflang.lf.Reaction; @@ -33,7 +27,7 @@ public interface FedTargetExtension { * @param errorReporter Used to report errors. */ void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, - ErrorReporter errorReporter, LinkedHashMap federationRTIProperties) throws IOException; + ErrorReporter errorReporter, RtiConfig rtiConfig) throws IOException; /** * Generate code for the body of a reaction that handles the @@ -120,13 +114,13 @@ default void annotateReaction(Reaction reaction) {} * Add necessary preamble to the source to set up federated execution. * * @param federate - * @param federationRTIProperties + * @param rtiConfig * @param errorReporter * @return */ String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, - LinkedHashMap federationRTIProperties, + RtiConfig rtiConfig, ErrorReporter errorReporter) throws IOException; } diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java index f3ab17514d..5caafc1c0c 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java @@ -12,8 +12,8 @@ public class FedTargetExtensionFactory { /** * Given a target, return the appropriate extension. */ - public static FedTargetExtension getExtension(TargetDecl target) { - switch (Target.fromDecl(target)) { + public static FedTargetExtension getExtension(Target target) { + switch (target) { case CCPP: case C: return new CExtension(); case Python: return new PythonExtension(); diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index 21b469228e..ca8ce4dd9c 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -3,6 +3,8 @@ import static org.lflang.util.StringUtil.addDoubleQuotes; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.LinkedHashMap; import java.util.stream.Collectors; @@ -16,6 +18,7 @@ import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.GeneratorBase; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactorInstance; @@ -28,7 +31,7 @@ public class TSExtension implements FedTargetExtension { @Override - public void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, LinkedHashMap federationRTIProperties) throws IOException { + public void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, RtiConfig rtiConfig) throws IOException { } @@ -88,9 +91,10 @@ public String getNetworkBufferType() { */ @Override public String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, - LinkedHashMap federationRTIProperties, + RtiConfig rtiConfig, ErrorReporter errorReporter) { var minOutputDelay = getMinOutputDelay(federate, fileConfig, errorReporter); + var upstreamConnectionDelays = getUpstreamConnectionDelays(federate); return """ preamble {= @@ -105,7 +109,8 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf networkMessageActions: [%s], rtiHost: "%s", rtiPort: %d, - sendsTo: [%s] + sendsTo: [%s], + upstreamConnectionDelays: [%s] } =}""".formatted( federate.dependsOn.keySet().stream() @@ -118,11 +123,12 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf .stream() .map(Variable::getName) .collect(Collectors.joining(",", "\"", "\"")), - federationRTIProperties.get("host"), - federationRTIProperties.get("port"), + rtiConfig.getHost(), + rtiConfig.getPort(), federate.sendsTo.keySet().stream() .map(e->String.valueOf(e.id)) - .collect(Collectors.joining(",")) + .collect(Collectors.joining(",")), + upstreamConnectionDelays.stream().collect(Collectors.joining(",")) ); } @@ -167,4 +173,33 @@ private TimeValue getMinOutputDelay(FederateInstance federate, FedFileConfig fil } return null; } + + private List getUpstreamConnectionDelays(FederateInstance federate) { + List candidates = new ArrayList<>(); + if (!federate.dependsOn.keySet().isEmpty()) { + for (FederateInstance upstreamFederate: federate.dependsOn.keySet()) { + String element = "["; + var delays = federate.dependsOn.get(upstreamFederate); + int cnt = 0; + if (delays != null) { + for (Expression delay : delays) { + if (delay == null) { + element += "TimeValue.NEVER()"; + } else { + element += "TimeValue.nsec(" + getNetworkDelayLiteral(delay) + ")"; + } + cnt++; + if (cnt != delays.size()) { + element += ", "; + } + } + } else { + element += "TimeValue.NEVER()"; + } + element += "]"; + candidates.add(element); + } + } + return candidates; + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java index 21fb3a0729..7a7eb1f183 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java +++ b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java @@ -208,7 +208,7 @@ private static Action createNetworkAction(FedConnectionInstance connection) { Type action_type = factory.createType(); action_type.setId( FedTargetExtensionFactory.getExtension( - connection.srcFederate.target + connection.srcFederate.targetConfig.target ).getNetworkBufferType() ); action.setType(action_type); @@ -264,7 +264,7 @@ private static void addNetworkReceiverReaction( setReactionBankIndex(networkReceiverReaction, connection.getDstBank()); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) .annotateReaction(networkReceiverReaction); // The connection is 'physical' if it uses the ~> notation. @@ -298,7 +298,7 @@ private static void addNetworkReceiverReaction( networkReceiverReaction.setCode(factory.createCode()); networkReceiverReaction.getCode().setBody( FedTargetExtensionFactory.getExtension( - connection.dstFederate.target).generateNetworkReceiverBody( + connection.dstFederate.targetConfig.target).generateNetworkReceiverBody( networkAction, sourceRef, destRef, @@ -357,7 +357,7 @@ private static void addNetworkInputControlReaction( setReactionBankIndex(reaction, connection.getDstBank()); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) .annotateReaction(reaction); // Create a new action that will be used to trigger the @@ -397,7 +397,7 @@ private static void addNetworkInputControlReaction( reaction.getCode() .setBody( FedTargetExtensionFactory - .getExtension(connection.dstFederate.target) + .getExtension(connection.dstFederate.targetConfig.target) .generateNetworkInputControlReactionBody( receivingPortID, maxSTP, @@ -721,7 +721,7 @@ private static void addNetworkSenderReaction( Reaction networkSenderReaction = factory.createReaction(); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) .annotateReaction(networkSenderReaction); // If the sender or receiver is in a bank of reactors, then we want @@ -750,7 +750,7 @@ private static void addNetworkSenderReaction( networkSenderReaction.getTriggers().add(sourceRef); networkSenderReaction.setCode(factory.createCode()); networkSenderReaction.getCode().setBody( - FedTargetExtensionFactory.getExtension(connection.srcFederate.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) .generateNetworkSenderBody( sourceRef, destRef, @@ -797,7 +797,7 @@ private static void addNetworkOutputControlReaction(FedConnectionInstance connec setReactionBankIndex(reaction, connection.getSrcBank()); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) .annotateReaction(reaction); // We use an action at the top-level to manually @@ -845,7 +845,7 @@ private static void addNetworkOutputControlReaction(FedConnectionInstance connec reaction.setCode(factory.createCode()); reaction.getCode().setBody( - FedTargetExtensionFactory.getExtension(connection.srcFederate.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) .generateNetworkOutputControlReactionBody(newPortRef, connection)); ASTUtils.addReactionAttribute(reaction, "_unordered"); diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java index e86af3ab77..9ae5c9d2cc 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java @@ -8,6 +8,7 @@ import java.util.Map; import org.lflang.ErrorReporter; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeMap; import org.lflang.generator.LFGeneratorContext; import org.lflang.lf.Reactor; @@ -20,18 +21,18 @@ public class FedEmitter { private final FedFileConfig fileConfig; private final Reactor originalMainReactor; private final ErrorReporter errorReporter; - private final LinkedHashMap federationRTIProperties; + private final RtiConfig rtiConfig; public FedEmitter( FedFileConfig fileConfig, Reactor originalMainReactor, ErrorReporter errorReporter, - LinkedHashMap federationRTIProperties + RtiConfig rtiConfig ) { this.fileConfig = fileConfig; this.originalMainReactor = originalMainReactor; this.errorReporter = errorReporter; - this.federationRTIProperties = federationRTIProperties; + this.rtiConfig = rtiConfig; } /** @@ -55,9 +56,9 @@ Map generateFederate( String federateCode = String.join( "\n", - new FedTargetEmitter().generateTarget(context, numOfFederates, federate, fileConfig, errorReporter, federationRTIProperties), + new FedTargetEmitter().generateTarget(context, numOfFederates, federate, fileConfig, errorReporter, rtiConfig), new FedImportEmitter().generateImports(federate, fileConfig), - new FedPreambleEmitter().generatePreamble(federate, fileConfig, federationRTIProperties, errorReporter), + new FedPreambleEmitter().generatePreamble(federate, fileConfig, rtiConfig, errorReporter), new FedReactorEmitter().generateReactorDefinitions(federate), new FedMainEmitter().generateMainReactor( federate, diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index 8e9df19d6e..42f5c60dc7 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -27,6 +27,8 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import org.eclipse.emf.ecore.resource.Resource; @@ -43,10 +45,12 @@ */ public class FedFileConfig extends FileConfig { - public FedFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { - // FIMXE: It is unclear to me that we need this class. + public FedFileConfig( + Resource resource, + Path srcGenBasePath, + boolean useHierarchicalBin + ) throws IOException { super(resource, srcGenBasePath, useHierarchicalBin); - } public FedFileConfig(FileConfig fileConfig) throws IOException { @@ -89,9 +93,44 @@ public Path getFedGenPath() { return srcPkgPath.resolve("fed-gen").resolve(this.name); } + /** + * Return the path to the directory in which the executables of compiled federates are stored. + */ + public Path getFedBinPath() { return getFedGenPath().resolve("bin"); } + @Override public void doClean() throws IOException { super.doClean(); FileUtil.deleteDirectory(this.getFedGenPath()); } + + /** + * Relativize target properties that involve paths like files and cmake-include to be + * relative to the generated .lf file for the federate. + */ + public void relativizePaths(FedTargetConfig targetConfig) { + relativizePathList(targetConfig.protoFiles); + relativizePathList(targetConfig.fileNames); + relativizePathList(targetConfig.cmakeIncludes); + } + + /** + * Relativize each path in the given list. + * @param paths The paths to relativize. + */ + private void relativizePathList(List paths) { + List tempList = new ArrayList<>(); + paths.forEach(f -> tempList.add(relativizePath(f))); + paths.clear(); + paths.addAll(tempList); + } + + /** + * Relativize a single path. + * @param path The path to relativize. + */ + private String relativizePath(String path) { + Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); + return this.getSrcPath().relativize(resolvedPath).toString(); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index 9a98e90291..18d5770165 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -27,10 +26,7 @@ import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.util.RuntimeIOException; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.lflang.ASTUtils; import org.lflang.ErrorReporter; @@ -39,12 +35,11 @@ import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty.CoordinationType; -import org.lflang.federated.launcher.FedLauncher; -import org.lflang.federated.launcher.FedLauncherFactory; +import org.lflang.federated.launcher.FedLauncherGenerator; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeMap; import org.lflang.generator.DockerData; import org.lflang.generator.FedDockerComposeGenerator; -import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorResult.Status; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.IntegratedBuilder; @@ -61,55 +56,40 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Reactor; -import org.lflang.lf.TargetDecl; +import org.lflang.util.Averager; import com.google.inject.Injector; public class FedGenerator { - /** Average asynchronously reported numbers and do something with them. */ - private static class Averager { - private final int n; - private final int[] reports; - /** Create an averager of reports from {@code n} processes. */ - public Averager(int n) { - this.n = n; - reports = new int[n]; - } - - /** - * Receive {@code x} from process {@code id} and invoke {@code callback} - * on the mean of the numbers most recently reported by the processes. - */ - public synchronized void report(int id, int x, Procedure1 callback) { - assert 0 <= id && id < n; - reports[id] = x; - callback.apply(Arrays.stream(reports).sum() / n); - } - } - - private final FedFileConfig fileConfig; - private final ErrorReporter errorReporter; /** - * The current target configuration. + * */ - private final TargetConfig targetConfig; + private final ErrorReporter errorReporter; + /** * A list of federate instances. */ private final List federates = new ArrayList<>(); + /** - * A map from federate IDs to federate instances. + * File configuration to be used during the LF code generation stage (not the target code + * generation stage of individual federates). */ - private final Map federateByID = new LinkedHashMap<>(); + private final FedFileConfig fileConfig; + /** - * The federation RTI properties, which defaults to 'localhost: 15045'. + * Configuration of the RTI. */ - final LinkedHashMap federationRTIProperties = CollectionLiterals.newLinkedHashMap( - Pair.of("host", "localhost"), - Pair.of("port", 0) // Indicator to use the default port, typically 15045. - ); + final RtiConfig rtiConfig = new RtiConfig(); + + /** + * Target configuration of the federation; drawn from the file + * in which the federated reactor is defined. + */ + private final TargetConfig targetConfig; + /** * A map from instantiations to the federate instances for that * instantiation. @@ -125,12 +105,26 @@ public synchronized void report(int id, int x, Procedure1 callback) { */ private Instantiation mainDef; + /** + * Create a new generator and initialize a file configuration, target configuration, and error + * reporter. + * @param context + */ public FedGenerator(LFGeneratorContext context) { this.fileConfig = (FedFileConfig) context.getFileConfig(); this.targetConfig = context.getTargetConfig(); this.errorReporter = context.getErrorReporter(); } + /** + * Produce LF code for each federate in a separate file, then invoke a target-specific code + * generator for each of those files. + * + * @param resource The resource that has the federated main reactor in it + * @param context The context in which to carry out the code generation. + * @return False if no errors have occurred, true otherwise. + * @throws IOException + */ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException { if (!federatedExecutionIsSupported(resource)) return true; cleanIfNeeded(context); @@ -144,27 +138,26 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws processCLIArguments(context); // Find the federated reactor - Reactor fedReactor = FedASTUtils.findFederatedReactor(resource); + Reactor federation = FedASTUtils.findFederatedReactor(resource); // Extract some useful information about the federation - analyzeFederates(fedReactor); + analyzeFederates(federation, context); // Find all the connections between federates. // For each connection between federates, replace it in the // AST with an action (which inherits the delay) and four reactions. // The action will be physical for physical connections and logical // for logical connections. - replaceFederateConnectionsWithProxies(fedReactor); - - createLauncher(fileConfig, errorReporter, federationRTIProperties); + replaceFederateConnectionsWithProxies(federation); FedEmitter fedEmitter = new FedEmitter( fileConfig, ASTUtils.toDefinition(mainDef.getReactorClass()), errorReporter, - federationRTIProperties + rtiConfig ); - // Generate code for each federate + + // Generate LF code for each federate. Map lf2lfCodeMapMap = new HashMap<>(); for (FederateInstance federate : federates) { lf2lfCodeMapMap.putAll(fedEmitter.generateFederate( @@ -172,45 +165,64 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws )); } + // Do not invoke target code generators if --no-compile flag is used. if (context.getTargetConfig().noCompile) { context.finish(Status.GENERATED, lf2lfCodeMapMap); return false; } Map codeMapMap = compileFederates(context, lf2lfCodeMapMap, subContexts -> { - if (context.getTargetConfig().dockerOptions == null) return; - final List services = new ArrayList<>(); - // 1. create a Dockerfile for each federate - for (SubContext subContext : subContexts) {// Inherit Docker options from main context - subContext.getTargetConfig().dockerOptions = context.getTargetConfig().dockerOptions; - var dockerGenerator = dockerGeneratorFactory(subContext); - var dockerData = dockerGenerator.generateDockerData(); - try { - dockerData.writeDockerFile(); - } catch (IOException e) { - throw new RuntimeIOException(e); - } - services.add(dockerData); - } - // 2. create a docker-compose.yml for the federation - try { - // FIXME: https://issue.lf-lang.org/1559 - // It appears that the rtiHost information should come from federationRTIproperties, - // which is a kludge and not in scope here. - new FedDockerComposeGenerator(context, "localhost").writeDockerComposeFile(services); - } catch (IOException e) { - throw new RuntimeIOException(e); - } + createDockerFiles(context, subContexts); + generateLaunchScript(); }); context.finish(Status.COMPILED, codeMapMap); return false; } + private void generateLaunchScript() { + new FedLauncherGenerator( + this.targetConfig, + this.fileConfig, + this.errorReporter + ).doGenerate(federates, rtiConfig); + } + + /** + * Generate a Dockerfile for each federate and a docker-compose.yml for the federation. + * @param context The main context in which the federation has been compiled. + * @param subContexts The subcontexts in which the federates have been compiled. + */ + private void createDockerFiles(LFGeneratorContext context, List subContexts) { + if (context.getTargetConfig().dockerOptions == null) return; + final List services = new ArrayList<>(); + // 1. create a Dockerfile for each federate + for (SubContext subContext : subContexts) {// Inherit Docker options from main context + subContext.getTargetConfig().dockerOptions = context.getTargetConfig().dockerOptions; + var dockerGenerator = dockerGeneratorFactory(subContext); + var dockerData = dockerGenerator.generateDockerData(); + try { + dockerData.writeDockerFile(); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + services.add(dockerData); + } + // 2. create a docker-compose.yml for the federation + try { + new FedDockerComposeGenerator( + context, + rtiConfig.getHost() + ).writeDockerComposeFile(services); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + } + /** * Check if a clean was requested from the standalone compiler and perform * the clean step. - * @param context + * @param context Context in which the generator operates */ private void cleanIfNeeded(LFGeneratorContext context) { if (context.getArgs().containsKey(BuildParm.CLEAN.getKey())) { @@ -222,54 +234,25 @@ private void cleanIfNeeded(LFGeneratorContext context) { } } - /** - * Create a launcher for the federation. - * @param fileConfig - * @param errorReporter - * @param federationRTIProperties - */ - public void createLauncher( - FedFileConfig fileConfig, - ErrorReporter errorReporter, - LinkedHashMap federationRTIProperties - ) { - FedLauncher launcher; - if (federates.size() == 0) { - // no federates, use target properties of main file - TargetDecl targetDecl = GeneratorUtils.findTarget(fileConfig.resource); - launcher = FedLauncherFactory.getLauncher(Target.fromDecl(targetDecl), - targetConfig, - fileConfig, - errorReporter); - } else { - launcher = FedLauncherFactory.getLauncher( - federates.get(0), // FIXME: This would not work for mixed-target programs. - fileConfig, - errorReporter - ); - } - try { - launcher.createLauncher( - federates, - federationRTIProperties - ); - } catch (IOException e) { - errorReporter.reportError(e.getMessage()); - } - - // System.out.println(PythonInfoGenerator.generateFedRunInfo(fileConfig)); - } - /** Return whether federated execution is supported for {@code resource}. */ private boolean federatedExecutionIsSupported(Resource resource) { - var target = Target.fromDecl(GeneratorUtils.findTarget(resource)); - var ret = List.of(Target.C, Target.Python, Target.TS, Target.CPP, Target.CCPP).contains(target); - if (!ret) { + var target = Target.fromDecl(GeneratorUtils.findTargetDecl(resource)); + var targetOK = List.of( + Target.C, Target.Python, Target.TS, Target.CPP, Target.CCPP + ).contains(target); + if (!targetOK) { errorReporter.reportError( "Federated execution is not supported with target " + target + "." ); } - return ret; + if(target.equals(Target.C) && GeneratorUtils.isHostWindows()) { + errorReporter.reportError( + "Federated LF programs with a C target are currently not supported on Windows." + ); + targetOK = false; + } + + return targetOK; } private Map compileFederates( @@ -295,7 +278,7 @@ private Map compileFederates( var compileThreadPool = Executors.newFixedThreadPool(numOfCompileThreads); System.out.println("******** Using "+numOfCompileThreads+" threads to compile the program."); Map codeMapMap = new ConcurrentHashMap<>(); - List subContexts = Collections.synchronizedList(new ArrayList()); + List subContexts = Collections.synchronizedList(new ArrayList<>()); Averager averager = new Averager(federates.size()); final var threadSafeErrorReporter = new SynchronizedErrorReporter(errorReporter); for (int i = 0; i < federates.size(); i++) { @@ -314,8 +297,8 @@ private Map compileFederates( } props.put("docker", "false"); - TargetConfig subConfig = GeneratorUtils.getTargetConfig( - props, GeneratorUtils.findTarget(subFileConfig.resource), subContextErrorReporter + TargetConfig subConfig = new TargetConfig( + props, GeneratorUtils.findTargetDecl(subFileConfig.resource), subContextErrorReporter ); SubContext subContext = new SubContext(context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, 100) { @Override @@ -393,34 +376,34 @@ private void setFederationRTIProperties(LFGeneratorContext context) { String port = matcher.group(3); if (host != null) { - federationRTIProperties.put("host", host); + rtiConfig.setHost(host); } if (port != null) { - federationRTIProperties.put("port", port); + rtiConfig.setPort(Integer.parseInt(port)); } if (user != null) { - federationRTIProperties.put("user", user); + rtiConfig.setUser(user); } } /** * Analyze the federation and record various properties of it. * - * @param fedReactor The federated reactor that contains all federates' instances. + * @param federation The federated reactor that contains all federates' instances. */ - private void analyzeFederates(Reactor fedReactor) { + private void analyzeFederates(Reactor federation, LFGeneratorContext context) { // Create an instantiation for the fed reactor because there isn't one. // Creating a definition for the main reactor because there isn't one. mainDef = LfFactory.eINSTANCE.createInstantiation(); - mainDef.setName(fedReactor.getName()); - mainDef.setReactorClass(fedReactor); + mainDef.setName(federation.getName()); + mainDef.setReactorClass(federation); // Make sure that if no federation RTI properties were given in the // cmdline, then those specified in the lf file are not lost - if (federationRTIProperties.get("host").equals("localhost") && - fedReactor.getHost() != null && - !fedReactor.getHost().getAddr().equals("localhost")) { - federationRTIProperties.put("host", fedReactor.getHost().getAddr()); + if (rtiConfig.getHost().equals("localhost") && + federation.getHost() != null && + !federation.getHost().getAddr().equals("localhost")) { + rtiConfig.setHost(federation.getHost().getAddr()); } // Since federates are always within the main (federated) reactor, @@ -429,15 +412,15 @@ private void analyzeFederates(Reactor fedReactor) { List mainReactorContext = new ArrayList<>(); mainReactorContext.add(mainDef); - // Create a FederateInstance for each top-level reactor. - for (Instantiation instantiation : ASTUtils.allInstantiations(fedReactor)) { + // Create a FederateInstance for each instance in the top-level reactor. + for (Instantiation instantiation : ASTUtils.allInstantiations(federation)) { int bankWidth = ASTUtils.width(instantiation.getWidthSpec(), mainReactorContext); if (bankWidth < 0) { errorReporter.reportError(instantiation, "Cannot determine bank width! Assuming width of 1."); // Continue with a bank width of 1. bankWidth = 1; } - List federateInstances = getFederateInstances(instantiation, bankWidth); + List federateInstances = getFederateInstances(instantiation, bankWidth, context); if (federatesByInstantiation == null) { federatesByInstantiation = new LinkedHashMap<>(); } @@ -454,17 +437,23 @@ private void analyzeFederates(Reactor fedReactor) { * @param bankWidth The width specified for the instantiation. * @return A list of federate instance (of type @see FederateInstance). */ - private List getFederateInstances(Instantiation instantiation, int bankWidth) { + private List getFederateInstances(Instantiation instantiation, int bankWidth, LFGeneratorContext context) { // Create one federate instance for each instance in a bank of reactors. List federateInstances = new ArrayList<>(bankWidth); + for (int i = 0; i < bankWidth; i++) { // Assign an integer ID to the federate. int federateID = federates.size(); - FederateInstance federateInstance = new FederateInstance(instantiation, federateID, i, errorReporter); - federateInstance.bankIndex = i; + var resource = instantiation.getReactorClass().eResource(); + var federateTargetConfig = new FedTargetConfig(context, resource); + FederateInstance federateInstance = new FederateInstance( + instantiation, + federateID, + i, + federateTargetConfig, + errorReporter); federates.add(federateInstance); federateInstances.add(federateInstance); - federateByID.put(federateID, federateInstance); if (instantiation.getHost() != null) { federateInstance.host = instantiation.getHost().getAddr(); @@ -489,16 +478,16 @@ private List getFederateInstances(Instantiation instantiation, * Replace connections between federates in the AST with proxies that * handle sending and receiving data. * - * @param fedReactor + * @param federation Reactor class of the federation. */ - private void replaceFederateConnectionsWithProxies(Reactor fedReactor) { + private void replaceFederateConnectionsWithProxies(Reactor federation) { // Each connection in the AST may represent more than one connection between - // federate instances because of banks and multiports. We need to generate communication + // federation instances because of banks and multiports. We need to generate communication // for each of these. To do this, we create a ReactorInstance so that we don't have // to duplicate the rather complicated logic in that class. We specify a depth of 1, // so it only creates the reactors immediately within the top level, not reactors // that those contain. - ReactorInstance mainInstance = new ReactorInstance(fedReactor, errorReporter); + ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter); for (ReactorInstance child : mainInstance.children) { for (PortInstance output : child.outputs) { @@ -507,7 +496,7 @@ private void replaceFederateConnectionsWithProxies(Reactor fedReactor) { } // Remove the connections at the top level - fedReactor.getConnections().clear(); + federation.getConnections().clear(); // There will be AST transformations that invalidate some info // cached in ReactorInstance. FIXME: most likely not needed anymore diff --git a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java index 86923c8914..95351237a7 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java @@ -54,7 +54,7 @@ String generateImports(FederateInstance federate, FedFileConfig fileConfig) { ); return new_import; }) - .map(FormattingUtils.renderer(federate.target)) + .map(FormattingUtils.renderer(federate.targetConfig.target)) .collect(Collectors.joining("\n"))); return importStatements.getCode(); diff --git a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java index ee3b64ab4a..54e215264f 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java @@ -41,7 +41,7 @@ String generateMainReactor(FederateInstance federate, Reactor originalMainReacto "Modes at the top level are not supported under federated execution." ); } - var renderer = FormattingUtils.renderer(federate.target); + var renderer = FormattingUtils.renderer(federate.targetConfig.target); return String .join( diff --git a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java index 827a31fe33..20771e7848 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java @@ -8,6 +8,7 @@ import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.federated.extensions.FedTargetExtensionFactory; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Model; import org.lflang.lf.Preamble; @@ -20,7 +21,7 @@ public FedPreambleEmitter() {} * Add necessary code to the source and necessary build support to * enable the requested serializations in 'enabledSerializations' */ - String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) + String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, RtiConfig rtiConfig, ErrorReporter errorReporter) throws IOException { CodeBuilder preambleCode = new CodeBuilder(); @@ -38,8 +39,8 @@ String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, Lin )); } - preambleCode.pr(FedTargetExtensionFactory.getExtension(federate.target).generatePreamble( - federate, fileConfig, federationRTIProperties, errorReporter)); + preambleCode.pr(FedTargetExtensionFactory.getExtension(federate.targetConfig.target).generatePreamble( + federate, fileConfig, rtiConfig, errorReporter)); return preambleCode.getCode(); } diff --git a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java index 066b344417..976049601c 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java @@ -18,7 +18,7 @@ String generateReactorDefinitions(FederateInstance federate) { .getReactors() .stream() .filter(federate::contains) - .map(FormattingUtils.renderer(federate.target)) + .map(FormattingUtils.renderer(federate.targetConfig.target)) .collect(Collectors.joining("\n")); } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java new file mode 100644 index 0000000000..9af20347c2 --- /dev/null +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java @@ -0,0 +1,78 @@ +package org.lflang.federated.generator; + +import static org.lflang.ASTUtils.convertToEmptyListIfNull; + +import org.lflang.ErrorReporter; +import org.lflang.TargetConfig; +import org.lflang.TargetProperty; +import org.lflang.generator.GeneratorUtils; +import org.lflang.generator.LFGeneratorContext; +import org.eclipse.emf.ecore.resource.Resource; + +/** + * Subclass of TargetConfig with a specialized constructor for creating configurations for federates. + * @author Marten Lohstroh + */ +public class FedTargetConfig extends TargetConfig { + + /** + * Create a configuration for a federate given a main context and the resource in which the class + * of the federate is specified. + * @param context The generator context. + * @param federateResource The resource in which to find the reactor class of the federate. + */ + public FedTargetConfig(LFGeneratorContext context, Resource federateResource) { + // Create target config based on the main .lf file + super( + context.getArgs(), + GeneratorUtils.findTargetDecl(context.getFileConfig().resource), + context.getErrorReporter() + ); + + mergeImportedConfig( + federateResource, + context.getFileConfig().resource, + context.getErrorReporter() + ); + + clearPropertiesToIgnore(); + + ((FedFileConfig)context.getFileConfig()).relativizePaths(this); + + } + + /** + * If the federate that target configuration applies to is imported, merge target properties + * declared in the file that it was imported from. + * @param federateResource The resource where the class of the federate is specified. + * @param mainResource The resource in which the federation (i.e., main reactor) is specified. + * @param errorReporter An error reporter to use when problems are encountered. + */ + private void mergeImportedConfig( + Resource federateResource, + Resource mainResource, + ErrorReporter errorReporter) { + // If the federate is imported, then update the configuration based on target properties + // in the imported file. + if (!federateResource.equals(mainResource)) { + var importedTargetDecl = GeneratorUtils.findTargetDecl(federateResource); + var targetProperties = importedTargetDecl.getConfig(); + if (targetProperties != null) { + // Merge properties + TargetProperty.update( + this, + convertToEmptyListIfNull(targetProperties.getPairs()), + errorReporter + ); + } + } + } + + /** + * Method for the removal of things that should not appear in the target config of a federate. + */ + private void clearPropertiesToIgnore() { + this.setByUser.remove(TargetProperty.CLOCK_SYNC); + this.setByUser.remove(TargetProperty.CLOCK_SYNC_OPTIONS); + } +} diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java index 7143eb18c5..1616286048 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java @@ -1,19 +1,12 @@ package org.lflang.federated.generator; -import static org.lflang.ASTUtils.convertToEmptyListIfNull; - import java.io.IOException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; import org.lflang.ErrorReporter; -import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.ast.FormattingUtils; import org.lflang.federated.extensions.FedTargetExtensionFactory; -import org.lflang.generator.GeneratorUtils; +import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.LFGeneratorContext; public class FedTargetEmitter { @@ -24,86 +17,28 @@ String generateTarget( FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, - LinkedHashMap federationRTIProperties + RtiConfig rtiConfig ) throws IOException { - federate.targetConfig = - GeneratorUtils.getTargetConfig( - context.getArgs(), - federate.target, - errorReporter - ); - // FIXME: Should we merge some properties with the main .lf file if the federate is imported? - // https://issue.lf-lang.org/1560 - var fedReactorClass = federate.instantiation.getReactorClass(); - if (!fedReactorClass.eResource().equals(fileConfig.resource)) { - // Merge some target properties of the main .lf file. - var target = GeneratorUtils.findTarget(fileConfig.resource); - if (target.getConfig() != null) { - // Merge properties - TargetProperty.update( - federate.targetConfig, - convertToEmptyListIfNull(target.getConfig().getPairs()), - errorReporter - ); - } - } - - relativizeTargetPaths(federate, fileConfig); - - clearFederatedTargetPropertiesI(federate); - FedTargetExtensionFactory.getExtension(federate.target) + // FIXME: First of all, this is not an initialization; there is all sorts of stuff happening + // in the C implementation of this method. Second, true initialization stuff should happen + // when the target config is constructed, not when we're doing code generation. + // See https://issues.lf-lang.org/1667 + FedTargetExtensionFactory.getExtension(federate.targetConfig.target) .initializeTargetConfig( context, numOfFederates, federate, fileConfig, errorReporter, - federationRTIProperties + rtiConfig ); - return FormattingUtils.renderer(federate.target).apply( + return FormattingUtils.renderer(federate.targetConfig.target).apply( TargetProperty.extractTargetDecl( - Target.fromDecl(federate.target), + federate.targetConfig.target, federate.targetConfig ) ); } - - /** - * Clear target properties that should not end up in the generated .lf file - * for {@code federate}. - */ - private void clearFederatedTargetPropertiesI(FederateInstance federate) { - federate.targetConfig.setByUser.remove(TargetProperty.CLOCK_SYNC); - federate.targetConfig.setByUser.remove(TargetProperty.CLOCK_SYNC_OPTIONS); - } - - - /** - * Relativize target properties that involve paths like files and cmake-include to be - * relative to the generated .lf file for the federate. - */ - private void relativizeTargetPaths(FederateInstance federate, FedFileConfig fileConfig) { - // FIXME: Should we relativize here or calculate absolute paths? - relativizePathList(federate.targetConfig.protoFiles, fileConfig); - - relativizePathList(federate.targetConfig.fileNames, fileConfig); - - relativizePathList(federate.targetConfig.cmakeIncludes, fileConfig); - } - - private void relativizePathList(List paths, FedFileConfig fileConfig) { - List tempList = new ArrayList<>(); - paths.forEach( f -> { - tempList.add(relativizePath(f, fileConfig)); - }); - paths.clear(); - paths.addAll(tempList); - } - - private String relativizePath(String path, FedFileConfig fileConfig) { - Path resolvedPath = fileConfig.srcPath.resolve(path).toAbsolutePath(); - return fileConfig.getSrcPath().relativize(resolvedPath).toString(); - } } diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index af581cc74d..f3768cec7c 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -25,6 +25,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.federated.generator; +import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -39,6 +40,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.ASTUtils; import org.lflang.ErrorReporter; +import org.lflang.FileConfig; +import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TimeValue; import org.lflang.federated.serialization.SupportedSerializers; @@ -47,6 +50,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.SubContext; import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -62,7 +66,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; -import org.lflang.lf.TargetDecl; import org.lflang.lf.Timer; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; @@ -98,15 +101,14 @@ public FederateInstance( Instantiation instantiation, int id, int bankIndex, + TargetConfig targetConfig, ErrorReporter errorReporter) { this.instantiation = instantiation; this.id = id; this.bankIndex = bankIndex; this.errorReporter = errorReporter; - this.target = GeneratorUtils.findTarget( - ASTUtils.toDefinition(instantiation.getReactorClass()).eResource() - ); - this.targetConfig = new TargetConfig(target); // FIXME: this is actually set in FedTargetEmitter. Why? + this.targetConfig = targetConfig; + if (instantiation != null) { this.name = instantiation.getName(); // If the instantiation is in a bank, then we have to append @@ -249,11 +251,6 @@ public Instantiation getInstantiation() { */ public List networkReactions = new ArrayList<>(); - /** - * Target of the federate. - */ - public TargetDecl target; - /** * Parsed target config of the federate. */ diff --git a/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java new file mode 100644 index 0000000000..c1a01bfa47 --- /dev/null +++ b/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java @@ -0,0 +1,60 @@ +package org.lflang.federated.launcher; + +import org.lflang.ErrorReporter; +import org.lflang.federated.generator.FedFileConfig; +import org.lflang.federated.generator.FederateInstance; + +/** + * A collection of methods used for building target code for federates. + */ +public abstract class BuildConfig { + + /** + * The federate that this configuration applies to. + */ + protected final FederateInstance federate; + + /** + * An error reporter to report problems. + */ + protected final ErrorReporter errorReporter; + + /** + * The file configuration of the federation that the federate belongs to. + */ + protected final FedFileConfig fileConfig; + + /** + * Create a new build configuration. + * + * @param federate The federate that this configuration applies to. + * @param fileConfig The file configuration of the federation that the federate belongs to. + * @param errorReporter An error reporter to report problems. + */ + public BuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + this.errorReporter = errorReporter; + this.federate = federate; + this.fileConfig = fileConfig; + } + + /** + * Return the compile command for the federate that this build configuration belongs to. + */ + public String compileCommand() { + throw new UnsupportedOperationException(); + } + + /** + * Return the command that will execute the federate that this build configuration belongs to + * locally, assuming that the current directory is the top-level project folder. + */ + public abstract String localExecuteCommand(); + + /** + * Return the command that will execute the federate that this build configuration belongs to + * remotely, assuming that the current directory is the top-level project folder. + */ + public String remoteExecuteCommand() { + throw new UnsupportedOperationException(); + } +} diff --git a/org.lflang/src/org/lflang/federated/launcher/FedCLauncher.java b/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java similarity index 56% rename from org.lflang/src/org/lflang/federated/launcher/FedCLauncher.java rename to org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java index 0b45444be9..bd88a719b4 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedCLauncher.java +++ b/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java @@ -26,10 +26,8 @@ package org.lflang.federated.launcher; import java.io.File; -import java.io.IOException; import org.lflang.ErrorReporter; -import org.lflang.TargetConfig; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.c.CCompiler; @@ -39,43 +37,25 @@ * that are written in C. * * @author Soroush Bateni + * @author Marten Lohstroh */ -public class FedCLauncher extends FedLauncher { +public class CBuildConfig extends BuildConfig { - /** - * Create an instance of FedCLauncher. - * - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. - * @param errorReporter A error reporter for reporting any errors or warnings during the code generation - */ - public FedCLauncher( - TargetConfig targetConfig, - FedFileConfig fileConfig, - ErrorReporter errorReporter - ) { - super(targetConfig, fileConfig, errorReporter); + public CBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + super(federate, fileConfig, errorReporter); } - /** - * Return the compile command for a federate. - * - * @param federate The federate to compile. - * @throws IOException - */ @Override - protected - String compileCommandForFederate(FederateInstance federate) { - TargetConfig localTargetConfig = targetConfig; + public String compileCommand() { String commandToReturn = ""; // FIXME: Hack to add platform support only for linux systems. // We need to fix the CMake build command for remote federates. String linuxPlatformSupport = "core" + File.separator + "platform" + File.separator + "lf_linux_support.c"; - if (!localTargetConfig.compileAdditionalSources.contains(linuxPlatformSupport)) { - localTargetConfig.compileAdditionalSources.add(linuxPlatformSupport); + if (!federate.targetConfig.compileAdditionalSources.contains(linuxPlatformSupport)) { + federate.targetConfig.compileAdditionalSources.add(linuxPlatformSupport); } - CCompiler cCompiler= new CCompiler(localTargetConfig, fileConfig, errorReporter, false); + CCompiler cCompiler= new CCompiler(federate.targetConfig, fileConfig, errorReporter, false); commandToReturn = String.join(" ", cCompiler.compileCCommand( fileConfig.name+"_"+federate.name, @@ -84,28 +64,13 @@ String compileCommandForFederate(FederateInstance federate) { return commandToReturn; } - /** - * Return the command that will execute a remote federate, assuming that the current - * directory is the top-level project folder. This is used to create a launcher script - * for federates. - * - * @param federate The federate to execute. - */ @Override - protected - String executeCommandForRemoteFederate(FederateInstance federate) { + public String remoteExecuteCommand() { return "bin/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; } - /** - * Return the command that will execute a local federate. - * This is used to create a launcher script for federates. - * - * @param federate The federate to execute. - */ @Override - protected - String executeCommandForLocalFederate(FedFileConfig fileConfig, FederateInstance federate) { - return fileConfig.getGenPath().resolve("bin/"+federate.name)+" -i $FEDERATION_ID"; + public String localExecuteCommand() { + return fileConfig.getFedBinPath().resolve(federate.name)+" -i $FEDERATION_ID"; } } diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java deleted file mode 100644 index c92cea1807..0000000000 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.lflang.federated.launcher; - -import org.lflang.ErrorReporter; -import org.lflang.Target; -import org.lflang.TargetConfig; -import org.lflang.federated.generator.FedFileConfig; -import org.lflang.federated.generator.FederateInstance; - -/** - * Helper class to get the appropriate launcher generator. - * - * FIXME: This architecture needs to be redesigned for multi-target federations. - */ -public class FedLauncherFactory { - - public static FedLauncher getLauncher ( - FederateInstance federate, - FedFileConfig fileConfig, - ErrorReporter errorReporter - ) { - return getLauncher(Target.fromDecl(federate.target), federate.targetConfig, fileConfig, errorReporter); - } - - /** - * Return a launcher generator. - * @param target The target to generate for. - * @param targetConfig The target config of the federate. - * @param fileConfig The file config for the federate. - * @param errorReporter The error reporter to use. - * @return null if not supported, an instance of {@code #FedLauncher} otherwise. - */ - public static FedLauncher getLauncher( - Target target, - TargetConfig targetConfig, - FedFileConfig fileConfig, - ErrorReporter errorReporter - ) { - switch (target) { - case C: - case CCPP: - return new FedCLauncher( - targetConfig, - fileConfig, - errorReporter - ); - case CPP: - case Rust: - return null; - case TS: - return new FedTSLauncher( - targetConfig, - fileConfig, - errorReporter - ); - case Python: - return new FedPyLauncher( - targetConfig, - fileConfig, - errorReporter - ); - } - return null; - } -} diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncher.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java similarity index 86% rename from org.lflang/src/org/lflang/federated/launcher/FedLauncher.java rename to org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 48a7149729..3ad08e2450 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncher.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -26,15 +26,16 @@ package org.lflang.federated.launcher; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import org.lflang.ErrorReporter; +import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.federated.generator.FedFileConfig; @@ -46,8 +47,7 @@ * @author Edward A. Lee * @author Soroush Bateni */ -public class FedLauncher { - +public class FedLauncherGenerator { protected TargetConfig targetConfig; protected FedFileConfig fileConfig; protected ErrorReporter errorReporter; @@ -57,44 +57,12 @@ public class FedLauncher { * @param fileConfig The current file configuration. * @param errorReporter A error reporter for reporting any errors or warnings during the code generation */ - public FedLauncher(TargetConfig targetConfig, FedFileConfig fileConfig, ErrorReporter errorReporter) { + public FedLauncherGenerator(TargetConfig targetConfig, FedFileConfig fileConfig, ErrorReporter errorReporter) { this.targetConfig = targetConfig; this.fileConfig = fileConfig; this.errorReporter = errorReporter; } - /** - * Return the compile command for a federate. - * - * @param federate The federate to compile. - */ - protected String compileCommandForFederate(FederateInstance federate) { - throw new UnsupportedOperationException("Don't know how to compile the federates."); - } - - /** - * Return the command that will execute a remote federate, assuming that the current - * directory is the top-level project folder. This is used to create a launcher script - * for federates. - * - * @param federate The federate to execute. - */ - protected String executeCommandForRemoteFederate(FederateInstance federate) { - throw new UnsupportedOperationException("Don't know how to execute the federates."); - } - - /** - * Return the command that will execute a local federate, assuming that the current - * directory is the top-level project folder. This is used to create a launcher script - * for federates. - * - * @param federate The federate to execute. - */ - protected String executeCommandForLocalFederate(FedFileConfig fileConfig, - FederateInstance federate) { - throw new UnsupportedOperationException("Don't know how to execute the federates."); - } - /** * Create the launcher shell scripts. This will create one or two files * in the output path (bin directory). The first has name equal to @@ -131,13 +99,13 @@ protected String executeCommandForLocalFederate(FedFileConfig fileConfig, * openssl version * * @param federates A list of federate instances in the federation - * @param federationRTIProperties Contains relevant properties of the RTI. + * @param rtiConfig * Can have values for 'host', 'dir', and 'user' */ - public void createLauncher( + public void doGenerate( List federates, - LinkedHashMap federationRTIProperties - ) throws IOException { + RtiConfig rtiConfig + ) { // NOTE: It might be good to use screen when invoking the RTI // or federates remotely, so you can detach and the process keeps running. // However, I was unable to get it working properly. @@ -154,12 +122,10 @@ public void createLauncher( StringBuilder distCode = new StringBuilder(); shCode.append(getSetupCode() + "\n"); String distHeader = getDistHeader(); - Object host = federationRTIProperties.get("host"); - Object target = host; + String host = rtiConfig.getHost(); + String target = host; - Path path = Path.of(federationRTIProperties.get("dir") == null ? "LinguaFrancaRemote" : federationRTIProperties.get("dir").toString()); - - Object user = federationRTIProperties.get("user"); + String user = rtiConfig.getUser(); if (user != null) { target = user + "@" + host; } @@ -199,17 +165,18 @@ public void createLauncher( // Index used for storing pids of federates int federateIndex = 0; for (FederateInstance federate : federates) { + var buildConfig = getBuildConfig(federate, fileConfig, errorReporter); if (federate.isRemote) { Path fedRelSrcGenPath = fileConfig.getOutPath().relativize(fileConfig.getSrcGenPath()).resolve(federate.name); if(distCode.length() == 0) distCode.append(distHeader + "\n"); String logFileName = String.format("log/%s_%s.log", fileConfig.name, federate.name); - String compileCommand = compileCommandForFederate(federate); + String compileCommand = buildConfig.compileCommand(); // FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the remote host? - distCode.append(getDistCode(path, federate, fedRelSrcGenPath, logFileName, fileConfig.getSrcGenPath(), compileCommand) + "\n"); - String executeCommand = executeCommandForRemoteFederate(federate); - shCode.append(getFedRemoteLaunchCode(federate, path, logFileName, executeCommand, federateIndex++) + "\n"); + distCode.append(getDistCode(rtiConfig.getDirectory(), federate, fedRelSrcGenPath, logFileName, fileConfig.getSrcGenPath(), compileCommand) + "\n"); + String executeCommand = buildConfig.remoteExecuteCommand(); + shCode.append(getFedRemoteLaunchCode(federate, rtiConfig.getDirectory(), logFileName, executeCommand, federateIndex++) + "\n"); } else { - String executeCommand = executeCommandForLocalFederate(fileConfig, federate); + String executeCommand = buildConfig.localExecuteCommand(); shCode.append(getFedLocalLaunchCode(federate, executeCommand, federateIndex++) + "\n"); } } @@ -232,7 +199,11 @@ public void createLauncher( // Create bin directory for the script. if (!Files.exists(fileConfig.binPath)) { - Files.createDirectories(fileConfig.binPath); + try { + Files.createDirectories(fileConfig.binPath); + } catch (IOException e) { + errorReporter.reportError("Unable to create directory: " + fileConfig.binPath); + } } System.out.println("##### Generating launcher for federation " @@ -246,9 +217,19 @@ public void createLauncher( file.delete(); } - FileOutputStream fOut = new FileOutputStream(file); - fOut.write(shCode.toString().getBytes()); - fOut.close(); + FileOutputStream fOut = null; + try { + fOut = new FileOutputStream(file); + } catch (FileNotFoundException e) { + errorReporter.reportError("Unable to find file: " + file); + } + try { + fOut.write(shCode.toString().getBytes()); + fOut.close(); + } catch (IOException e) { + errorReporter.reportError("Unable to write to file: " + file); + } + if (!file.setExecutable(true, false)) { errorReporter.reportWarning("Unable to make launcher script executable."); } @@ -260,11 +241,17 @@ public void createLauncher( file.delete(); } if (distCode.length() > 0) { - fOut = new FileOutputStream(file); - fOut.write(distCode.toString().getBytes()); - fOut.close(); - if (!file.setExecutable(true, false)) { - errorReporter.reportWarning("Unable to make distributor script executable."); + try { + fOut = new FileOutputStream(file); + fOut.write(distCode.toString().getBytes()); + fOut.close(); + if (!file.setExecutable(true, false)) { + errorReporter.reportWarning("Unable to make file executable: " + file); + } + } catch (FileNotFoundException e) { + errorReporter.reportError("Unable to find file: " + file); + } catch (IOException e) { + errorReporter.reportError("Unable to write to file " + file); } } } @@ -329,6 +316,9 @@ private String getRtiCommand(List federates, boolean isRemote) if (targetConfig.auth) { commands.add(" -a \\"); } + if (targetConfig.tracing != null) { + commands.add(" -t \\"); + } commands.addAll(List.of( " -n "+federates.size()+" \\", " -c "+targetConfig.clockSync.toString()+" \\" @@ -451,7 +441,7 @@ private String getUserHost(Object user, Object host) { private String getFedRemoteLaunchCode( FederateInstance federate, - Object path, + Path path, String logFileName, String executeCommand, int federateIndex @@ -482,4 +472,24 @@ private String getFedLocalLaunchCode(FederateInstance federate, String executeCo executeCommand, federateIndex); } + + /** + * Create a build configuration of the appropriate target. + * + * @param federate The federate to which the build configuration applies. + * @param fileConfig The file configuration of the federation to which the federate belongs. + * @param errorReporter An error reporter to report problems. + * @return + */ + private BuildConfig getBuildConfig( + FederateInstance federate, + FedFileConfig fileConfig, + ErrorReporter errorReporter) { + return switch(federate.targetConfig.target) { + case C, CCPP -> new CBuildConfig(federate, fileConfig, errorReporter); + case Python -> new PyBuildConfig(federate, fileConfig, errorReporter); + case TS -> new TsBuildConfig(federate, fileConfig, errorReporter); + case CPP, Rust -> throw new UnsupportedOperationException(); + }; + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java b/org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java deleted file mode 100644 index 414caf2ee4..0000000000 --- a/org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java +++ /dev/null @@ -1,83 +0,0 @@ -/************* - * Copyright (c) 2021, The University of California at Berkeley. - * Copyright (c) 2021, The University of Texas at Dallas. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - ***************/ - -package org.lflang.federated.launcher; - -import org.lflang.ErrorReporter; -import org.lflang.TargetConfig; -import org.lflang.federated.generator.FedFileConfig; -import org.lflang.federated.generator.FederateInstance; - -/** - * Utility class that can be used to create a launcher for federated LF programs - * that are written in Python. - * - * @author Soroush Bateni - * - */ -public class FedPyLauncher extends FedLauncher { - /** - * Create an instance of FedPyLauncher. - * - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. - * @param errorReporter A error reporter for reporting any errors or warnings during the code generation - */ - public FedPyLauncher( - TargetConfig targetConfig, - FedFileConfig fileConfig, - ErrorReporter errorReporter - ) { - super(targetConfig, fileConfig, errorReporter); - } - - /** - * Return the command that will execute a remote federate, assuming that the current - * directory is the top-level project folder. This is used to create a launcher script - * for federates. - * - * @param federate The federate to execute. - */ - @Override - protected - String executeCommandForRemoteFederate(FederateInstance federate) { - return "python3 src-gen/"+fileConfig.name+"/"+federate.name+"/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; - } - - /** - * Return the command that will execute a local federate, assuming that the current - * directory is the top-level project folder. This is used to create a launcher script - * for federates. - * - * @param federate The federate to execute. - */ - @Override - protected - String executeCommandForLocalFederate(FedFileConfig fileConfig, FederateInstance federate) { - return "python3 " + fileConfig.getSrcGenPath() + "/" + federate.name + "/" + federate.name+".py -i $FEDERATION_ID"; - } -} diff --git a/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java new file mode 100644 index 0000000000..85d6dc4a0f --- /dev/null +++ b/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java @@ -0,0 +1,22 @@ +package org.lflang.federated.launcher; + +import org.lflang.ErrorReporter; +import org.lflang.federated.generator.FedFileConfig; +import org.lflang.federated.generator.FederateInstance; + +public class PyBuildConfig extends BuildConfig { + + public PyBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + super(federate, fileConfig, errorReporter); + } + + @Override + public String localExecuteCommand() { + return "python3 " + fileConfig.getSrcGenPath() + "/" + federate.name + "/" + federate.name+".py -i $FEDERATION_ID"; + } + + @Override + public String remoteExecuteCommand() { + return "python3 src-gen/"+fileConfig.name+"/"+federate.name+"/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; + } +} diff --git a/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java b/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java new file mode 100644 index 0000000000..81c608d5b3 --- /dev/null +++ b/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java @@ -0,0 +1,92 @@ +package org.lflang.federated.launcher; + +import java.nio.file.Path; + +/** + * Class for storing configuration settings pertaining to the RTI. + * @author Marten Lohstroh + */ +public class RtiConfig { + + private Path directory; + + /** + * The host on which the RTI process is to be spawned. + */ + private String host; + + /** + * The port on which to connect to the RTI process. + */ + private int port; + + /** + * The username used to gain access to the host where the RTI is to be spawned. + */ + private String user; + + /** + * Construct a new RTI configuration with all options set to their defaults. + */ + public RtiConfig() { + this.directory = Path.of("LinguaFrancaRemote"); + this.host = "localhost"; + this.port = 0; + } + + /** + * Return the directory to create on the remote host. + */ + public Path getDirectory() { + return directory; + } + + /** + * Return the host on which the RTI process is to be spawned. + */ + public String getHost() { + return host; + } + + /** + * Return the port on which to connect to the RTI process. + */ + public int getPort() { + return port; + } + + /** + * Return the username used to gain access to the host where the RTI is to be spawned. + */ + public String getUser() { + return user; + } + + /** + * Set the directory to create on the remote host. + */ + public void setDirectory(Path directory) { + this.directory = directory; + } + + /** + * Set the host on which the RTI process is to be spawned. + */ + public void setHost(String host) { + this.host = host; + } + + /** + * Set the port on which to connect to the RTI process. + */ + public void setPort(int port) { + this.port = port; + } + + /** + * Set the username used to gain access to the host where the RTI is to be spawned. + */ + public void setUser(String user) { + this.user = user; + } +} diff --git a/org.lflang/src/org/lflang/federated/launcher/FedTSLauncher.java b/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java similarity index 68% rename from org.lflang/src/org/lflang/federated/launcher/FedTSLauncher.java rename to org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java index 67dbd134fa..87b7ffaeb1 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedTSLauncher.java +++ b/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java @@ -36,35 +36,24 @@ * * @author Soroush Bateni * @author Hokeun Kim + * @author Marten Lohstroh */ -public class FedTSLauncher extends FedLauncher { +public class TsBuildConfig extends BuildConfig { - /** - * Create an instance of FedCLauncher. - * - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. - * @param errorReporter A error reporter for reporting any errors or warnings during the code generation - */ - public FedTSLauncher( - TargetConfig targetConfig, - FedFileConfig fileConfig, - ErrorReporter errorReporter - ) { - super(targetConfig, fileConfig, errorReporter); + + public TsBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + super(federate, fileConfig, errorReporter); + } + + @Override + public String compileCommand() { + return null; } - - /** - * Return the command that will execute a local federate, assuming that the current - * directory is the top-level project folder. This is used to create a launcher script - * for federates. - * - * @param federate The federate to execute. - */ + @Override - protected - String executeCommandForLocalFederate(FedFileConfig fileConfig, FederateInstance federate) { + public String localExecuteCommand() { String jsFilename = federate.name + ".js"; return "node "+fileConfig.getSrcGenPath().resolve(federate.name).resolve("dist").resolve(jsFilename)+" -i $FEDERATION_ID"; } + } diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/src/org/lflang/generator/GeneratorUtils.java index 32ad03e08b..709e1943bd 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/GeneratorUtils.java @@ -1,52 +1,30 @@ package org.lflang.generator; -import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import java.util.List; -import java.util.Properties; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.generator.IGeneratorContext; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.validation.CheckMode; -import org.eclipse.xtext.validation.IResourceValidator; -import org.eclipse.xtext.validation.Issue; import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; -import org.lflang.Target; import org.lflang.TargetConfig; -import org.lflang.TargetConfig.DockerOptions; -import org.lflang.TargetProperty.BuildType; -import org.lflang.TargetProperty.LogLevel; -import org.lflang.TargetProperty.UnionType; import org.lflang.generator.LFGeneratorContext.Mode; import org.lflang.TargetProperty; -import org.lflang.TargetProperty.SchedulerOption; -import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; -import org.lflang.lf.Import; import org.lflang.lf.Instantiation; import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; -import org.lflang.lf.Model; -import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.TargetDecl; -import org.lflang.util.FileUtil; -import org.lflang.util.IteratorUtil; /** * A helper class with functions that may be useful for code @@ -65,81 +43,10 @@ private GeneratorUtils() { /** * Return the target declaration found in the given resource. */ - public static TargetDecl findTarget(Resource resource) { + public static TargetDecl findTargetDecl(Resource resource) { return findAll(resource, TargetDecl.class).iterator().next(); } - /** - * Set the appropriate target properties based on the target properties of - * the main .lf file and the given command-line arguments, if applicable. - * @param args The commandline arguments to process. - * @param target The target properties AST node. - * @param errorReporter The error reporter to which errors should be sent. - */ - public static TargetConfig getTargetConfig( - Properties args, - TargetDecl target, - ErrorReporter errorReporter - ) { - final TargetConfig targetConfig = new TargetConfig(target); // FIXME: why not just do all of this in the constructor? - if (target.getConfig() != null) { - List pairs = target.getConfig().getPairs(); - TargetProperty.set(targetConfig, pairs != null ? pairs : List.of(), errorReporter); - } - if (args.containsKey("no-compile")) { - targetConfig.noCompile = true; - } - if (args.containsKey("docker")) { - var arg = args.getProperty("docker"); - if (Boolean.parseBoolean(arg)) { - targetConfig.dockerOptions = new DockerOptions(); - } else { - targetConfig.dockerOptions = null; - } - // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. - } - if (args.containsKey("build-type")) { - targetConfig.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(args.getProperty("build-type")); - } - if (args.containsKey("logging")) { - targetConfig.logLevel = LogLevel.valueOf(args.getProperty("logging").toUpperCase()); - } - if (args.containsKey("workers")) { - targetConfig.workers = Integer.parseInt(args.getProperty("workers")); - } - if (args.containsKey("threading")) { - targetConfig.threading = Boolean.parseBoolean(args.getProperty("threading")); - } - if (args.containsKey("target-compiler")) { - targetConfig.compiler = args.getProperty("target-compiler"); - } - if (args.containsKey("scheduler")) { - targetConfig.schedulerType = SchedulerOption.valueOf( - args.getProperty("scheduler") - ); - targetConfig.setByUser.add(TargetProperty.SCHEDULER); - } - if (args.containsKey("target-flags")) { - targetConfig.compilerFlags.clear(); - if (!args.getProperty("target-flags").isEmpty()) { - targetConfig.compilerFlags.addAll(List.of( - args.getProperty("target-flags").split(" ") - )); - } - } - if (args.containsKey("runtime-version")) { - targetConfig.runtimeVersion = args.getProperty("runtime-version"); - } - if (args.containsKey("external-runtime-path")) { - targetConfig.externalRuntimePath = args.getProperty("external-runtime-path"); - } - if (args.containsKey(TargetProperty.KEEPALIVE.description)) { - targetConfig.keepalive = Boolean.parseBoolean( - args.getProperty(TargetProperty.KEEPALIVE.description)); - } - return targetConfig; - } - /** * Look for physical actions in 'resource'. * If appropriate, set keepalive to true in diff --git a/org.lflang/src/org/lflang/generator/MainContext.java b/org.lflang/src/org/lflang/generator/MainContext.java index e7d442e1d3..5ee53e5f83 100644 --- a/org.lflang/src/org/lflang/generator/MainContext.java +++ b/org.lflang/src/org/lflang/generator/MainContext.java @@ -163,8 +163,8 @@ public void reportProgress(String message, int percentage) { * reflected in the target configuration. */ public void loadTargetConfig() { - this.targetConfig = GeneratorUtils.getTargetConfig( - args, GeneratorUtils.findTarget(fileConfig.resource), errorReporter + this.targetConfig = new TargetConfig( + args, GeneratorUtils.findTargetDecl(fileConfig.resource), errorReporter ); } } diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 21ea083e49..3fd3675d52 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -301,7 +301,7 @@ class TSGenerator( if (ret != 0) { val errors: String = pnpmInstall.errors.toString() errorReporter.reportError( - GeneratorUtils.findTarget(resource), + GeneratorUtils.findTargetDecl(resource), "ERROR: pnpm install command failed" + if (errors.isBlank()) "." else ":\n$errors") } installProtoBufsIfNeeded(true, path, context.cancelIndicator) @@ -318,10 +318,10 @@ class TSGenerator( if (npmInstall.run(context.cancelIndicator) != 0) { errorReporter.reportError( - GeneratorUtils.findTarget(resource), + GeneratorUtils.findTargetDecl(resource), "ERROR: npm install command failed: " + npmInstall.errors.toString()) errorReporter.reportError( - GeneratorUtils.findTarget(resource), "ERROR: npm install command failed." + + GeneratorUtils.findTargetDecl(resource), "ERROR: npm install command failed." + "\nFor installation instructions, see: https://www.npmjs.com/get-npm") return } diff --git a/org.lflang/src/org/lflang/util/Averager.java b/org.lflang/src/org/lflang/util/Averager.java new file mode 100644 index 0000000000..81349c9db1 --- /dev/null +++ b/org.lflang/src/org/lflang/util/Averager.java @@ -0,0 +1,27 @@ +package org.lflang.util; + +import java.util.Arrays; + +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + +/** Average asynchronously reported numbers and do something with them. */ +public class Averager { + private final int n; + private final int[] reports; + + /** Create an averager of reports from {@code n} processes. */ + public Averager(int n) { + this.n = n; + reports = new int[n]; + } + + /** + * Receive {@code x} from process {@code id} and invoke {@code callback} + * on the mean of the numbers most recently reported by the processes. + */ + public synchronized void report(int id, int x, Procedure1 callback) { + assert 0 <= id && id < n; + reports[id] = x; + callback.apply(Arrays.stream(reports).sum() / n); + } +} diff --git a/test/C/src/federated/SimpleFederatedAuthenticated.lf b/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf similarity index 100% rename from test/C/src/federated/SimpleFederatedAuthenticated.lf rename to test/C/src/federated/failing/SimpleFederatedAuthenticated.lf diff --git a/util/tracing/README.md b/util/tracing/README.md index d189260ef7..28d8db23d7 100644 --- a/util/tracing/README.md +++ b/util/tracing/README.md @@ -3,12 +3,18 @@ This directory contains the source code for utilities that are standalone executables for post-processing tracing data created by the tracing function in Lingua Franca. +Utilities for visualizing the data are contained in the [visualization](visualization/README.md) +directory. + * trace\_to\_csv: Creates a comma-separated values text file from a binary trace file. The resulting file is suitable for analyzing in spreadsheet programs such as Excel. * trace\_to\_chrome: Creates a JSON file suitable for importing into Chrome's trace visualizer. Point Chrome to chrome://tracing/ and load the resulting file. +* trace\_to\_influxdb: A preliminary implementation that takes a binary trace file + and uploads its data into [InfluxDB](https://en.wikipedia.org/wiki/InfluxDB). + ## Installing ``` diff --git a/util/tracing/makefile b/util/tracing/makefile index eb21e42e62..407b153235 100644 --- a/util/tracing/makefile +++ b/util/tracing/makefile @@ -28,6 +28,8 @@ install: trace_to_csv trace_to_chrome trace_to_influxdb mv trace_to_csv ../../bin mv trace_to_chrome ../../bin mv trace_to_influxdb ../../bin + ln -f -s ../lib/scripts/launch-fedsd.sh ../../bin/fedsd + chmod +x ../../bin/fedsd clean: rm -f *.o diff --git a/util/tracing/trace_to_chrome.c b/util/tracing/trace_to_chrome.c index d39f53171e..92eeee71dd 100644 --- a/util/tracing/trace_to_chrome.c +++ b/util/tracing/trace_to_chrome.c @@ -43,6 +43,12 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** Maximum thread ID seen. */ int max_thread_id = 0; +/** File containing the trace binary data. */ +FILE* trace_file = NULL; + +/** File for writing the output data. */ +FILE* output_file = NULL; + /** * Print a usage message. */ @@ -62,17 +68,23 @@ bool physical_time_only = false; /** * Read a trace in the specified file and write it to the specified json file. + * @param trace_file An open trace file. + * @param output_file An open output .json file. * @return The number of records read or 0 upon seeing an EOF. */ -size_t read_and_write_trace() { +size_t read_and_write_trace(FILE* trace_file, FILE* output_file) { int trace_length = read_trace(trace_file); if (trace_length == 0) return 0; // Write each line. for (int i = 0; i < trace_length; i++) { char* reaction_name = "\"UNKNOWN\""; - if (trace[i].reaction_number >= 0) { + + // Ignore federated trace events. + if (trace[i].event_type > federated) continue; + + if (trace[i].dst_id >= 0) { reaction_name = (char*)malloc(4); - snprintf(reaction_name, 4, "%d", trace[i].reaction_number); + snprintf(reaction_name, 4, "%d", trace[i].dst_id); } // printf("DEBUG: Reactor's self struct pointer: %p\n", trace[i].pointer); int reactor_index; @@ -113,7 +125,7 @@ size_t read_and_write_trace() { } // Default thread id is the worker number. - int thread_id = trace[i].worker; + int thread_id = trace[i].src_id; char* args; asprintf(&args, "{" @@ -182,7 +194,7 @@ size_t read_and_write_trace() { phase = "E"; break; default: - fprintf(stderr, "WARNING: Unrecognized event type %d: %s", + fprintf(stderr, "WARNING: Unrecognized event type %d: %s\n", trace[i].event_type, trace_event_names[trace[i].event_type]); pid = PID_FOR_UNKNOWN_EVENT; phase = "i"; @@ -206,8 +218,8 @@ size_t read_and_write_trace() { ); free(args); - if (trace[i].worker > max_thread_id) { - max_thread_id = trace[i].worker; + if (trace[i].src_id > max_thread_id) { + max_thread_id = trace[i].src_id; } // If the event is reaction_starts and physical_time_only is not set, // then also generate an instantaneous @@ -217,13 +229,13 @@ size_t read_and_write_trace() { pid = reactor_index + 1; reaction_name = (char*)malloc(4); char name[13]; - snprintf(name, 13, "reaction %d", trace[i].reaction_number); + snprintf(name, 13, "reaction %d", trace[i].dst_id); // NOTE: If the reactor has more than 1024 timers and actions, then // there will be a collision of thread IDs here. - thread_id = 1024 + trace[i].reaction_number; - if (trace[i].reaction_number > max_reaction_number) { - max_reaction_number = trace[i].reaction_number; + thread_id = 1024 + trace[i].dst_id; + if (trace[i].dst_id > max_reaction_number) { + max_reaction_number = trace[i].dst_id; } fprintf(output_file, "{" @@ -253,8 +265,9 @@ size_t read_and_write_trace() { /** * Write metadata events, which provide names in the renderer. + * @param output_file An open output .json file. */ -void write_metadata_events() { +void write_metadata_events(FILE* output_file) { // Thread 0 is the main thread. fprintf(output_file, "{" "\"name\": \"thread_name\", " @@ -416,13 +429,22 @@ int main(int argc, char* argv[]) { usage(); exit(0); } - open_files(filename, "json"); + + // Open the trace file. + trace_file = open_file(filename, "r"); + + // Construct the name of the csv output file and open it. + char* root = root_name(filename); + char json_filename[strlen(root) + 6]; + strcpy(json_filename, root); + strcat(json_filename, ".json"); + output_file = open_file(json_filename, "w"); if (read_header(trace_file) >= 0) { // Write the opening bracket into the json file. fprintf(output_file, "{ \"traceEvents\": [\n"); - while (read_and_write_trace() != 0) {}; - write_metadata_events(); + while (read_and_write_trace(trace_file, output_file) != 0) {}; + write_metadata_events(output_file); fprintf(output_file, "]}\n"); } } diff --git a/util/tracing/trace_to_csv.c b/util/tracing/trace_to_csv.c index a2bcfd91a2..707cc5f43b 100644 --- a/util/tracing/trace_to_csv.c +++ b/util/tracing/trace_to_csv.c @@ -37,6 +37,15 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define MAX_NUM_REACTIONS 64 // Maximum number of reactions reported in summary stats. #define MAX_NUM_WORKERS 64 +/** File containing the trace binary data. */ +FILE* trace_file = NULL; + +/** File for writing the output data. */ +FILE* output_file = NULL; + +/** File for writing summary statistics. */ +FILE* summary_file = NULL; + /** Size of the stats table is object_table_size plus twice MAX_NUM_WORKERS. */ int table_size; @@ -69,7 +78,7 @@ typedef struct reaction_stats_t { */ typedef struct summary_stats_t { trace_event_t event_type; // Use reaction_ends for reactions. - char* description; // Description in the reaction table (e.g. reactor name). + const char* description; // Description in the reaction table (e.g. reactor name). int occurrences; // Number of occurrences of this description. int num_reactions_seen; reaction_stats_t reactions[MAX_NUM_REACTIONS]; @@ -94,11 +103,6 @@ size_t read_and_write_trace() { if (trace_length == 0) return 0; // Write each line. for (int i = 0; i < trace_length; i++) { - char* reaction_name = "none"; - if (trace[i].reaction_number >= 0) { - reaction_name = (char*)malloc(4); - snprintf(reaction_name, 4, "%d", trace[i].reaction_number); - } // printf("DEBUG: reactor self struct pointer: %p\n", trace[i].pointer); int object_instance = -1; char* reactor_name = get_object_description(trace[i].pointer, &object_instance); @@ -110,11 +114,11 @@ size_t read_and_write_trace() { if (trigger_name == NULL) { trigger_name = "NO TRIGGER"; } - fprintf(output_file, "%s, %s, %s, %d, %lld, %d, %lld, %s, %lld\n", + fprintf(output_file, "%s, %s, %d, %d, %lld, %d, %lld, %s, %lld\n", trace_event_names[trace[i].event_type], reactor_name, - reaction_name, - trace[i].worker, + trace[i].src_id, + trace[i].dst_id, trace[i].logical_time - start_time, trace[i].microstep, trace[i].physical_time - start_time, @@ -125,33 +129,41 @@ size_t read_and_write_trace() { if (trace[i].physical_time > latest_time) { latest_time = trace[i].physical_time; } - if (summary_stats[object_instance] == NULL) { - summary_stats[object_instance] = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); + if (object_instance >= 0 && summary_stats[NUM_EVENT_TYPES + object_instance] == NULL) { + summary_stats[NUM_EVENT_TYPES + object_instance] = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); } - if (trigger_instance >= 0 && summary_stats[trigger_instance] == NULL) { - summary_stats[trigger_instance] = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); + if (trigger_instance >= 0 && summary_stats[NUM_EVENT_TYPES + trigger_instance] == NULL) { + summary_stats[NUM_EVENT_TYPES + trigger_instance] = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); } - summary_stats_t* stats; + summary_stats_t* stats = NULL; interval_t exec_time; reaction_stats_t* rstats; int index; + // Count of event type. + if (summary_stats[trace[i].event_type] == NULL) { + summary_stats[trace[i].event_type] = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); + } + summary_stats[trace[i].event_type]->event_type = trace[i].event_type; + summary_stats[trace[i].event_type]->description = trace_event_names[trace[i].event_type]; + summary_stats[trace[i].event_type]->occurrences++; + switch(trace[i].event_type) { case reaction_starts: case reaction_ends: // This code relies on the mutual exclusion of reactions in a reactor // and the ordering of reaction_starts and reaction_ends events. - if (trace[i].reaction_number >= MAX_NUM_REACTIONS) { + if (trace[i].dst_id >= MAX_NUM_REACTIONS) { fprintf(stderr, "WARNING: Too many reactions. Not all will be shown in summary file.\n"); continue; } - stats = summary_stats[object_instance]; + stats = summary_stats[NUM_EVENT_TYPES + object_instance]; stats->description = reactor_name; - if (trace[i].reaction_number >= stats->num_reactions_seen) { - stats->num_reactions_seen = trace[i].reaction_number + 1; + if (trace[i].dst_id >= stats->num_reactions_seen) { + stats->num_reactions_seen = trace[i].dst_id + 1; } - rstats = &stats->reactions[trace[i].reaction_number]; + rstats = &stats->reactions[trace[i].dst_id]; if (trace[i].event_type == reaction_starts) { rstats->latest_start_time = trace[i].physical_time; } else { @@ -172,19 +184,19 @@ size_t read_and_write_trace() { // No trigger. Do not report. continue; } - stats = summary_stats[trigger_instance]; + stats = summary_stats[NUM_EVENT_TYPES + trigger_instance]; stats->description = trigger_name; break; case user_event: // Although these are not exec times and not reactions, // commandeer the first entry in the reactions array to track values. - stats = summary_stats[object_instance]; + stats = summary_stats[NUM_EVENT_TYPES + object_instance]; stats->description = reactor_name; break; case user_value: // Although these are not exec times and not reactions, // commandeer the first entry in the reactions array to track values. - stats = summary_stats[object_instance]; + stats = summary_stats[NUM_EVENT_TYPES + object_instance]; stats->description = reactor_name; rstats = &stats->reactions[0]; rstats->occurrences++; @@ -205,7 +217,7 @@ size_t read_and_write_trace() { // Use the reactions array to store data. // There will be two entries per worker, one for waits on the // reaction queue and one for waits while advancing time. - index = trace[i].worker * 2; + index = trace[i].src_id * 2; // Even numbered indices are used for waits on reaction queue. // Odd numbered indices for waits for time advancement. if (trace[i].event_type == scheduler_advancing_time_starts @@ -216,10 +228,10 @@ size_t read_and_write_trace() { fprintf(stderr, "WARNING: Too many workers. Not all will be shown in summary file.\n"); continue; } - stats = summary_stats[object_table_size + index]; + stats = summary_stats[NUM_EVENT_TYPES + object_table_size + index]; if (stats == NULL) { stats = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); - summary_stats[object_table_size + index] = stats; + summary_stats[NUM_EVENT_TYPES + object_table_size + index] = stats; } // num_reactions_seen here will be used to store the number of // entries in the reactions array, which is twice the number of workers. @@ -244,10 +256,15 @@ size_t read_and_write_trace() { } } break; + default: + // No special summary statistics for the rest. + break; } // Common stats across event types. - stats->occurrences++; - stats->event_type = trace[i].event_type; + if (stats != NULL) { + stats->occurrences++; + stats->event_type = trace[i].event_type; + } } return trace_length; } @@ -261,11 +278,22 @@ void write_summary_file() { fprintf(summary_file, "End time:, %lld\n", latest_time); fprintf(summary_file, "Total time:, %lld\n", latest_time - start_time); + fprintf(summary_file, "\nTotal Event Occurrences\n"); + for (int i = 0; i < NUM_EVENT_TYPES; i++) { + summary_stats_t* stats = summary_stats[i]; + if (stats != NULL) { + fprintf(summary_file, "%s, %d\n", + stats->description, + stats->occurrences + ); + } + } + // First pass looks for reaction invocations. // First print a header. fprintf(summary_file, "\nReaction Executions\n"); fprintf(summary_file, "Reactor, Reaction, Occurrences, Total Time, Pct Total Time, Avg Time, Max Time, Min Time\n"); - for (int i = 0; i < table_size; i++) { + for (int i = NUM_EVENT_TYPES; i < table_size; i++) { summary_stats_t* stats = summary_stats[i]; if (stats != NULL && stats->num_reactions_seen > 0) { for (int j = 0; j < stats->num_reactions_seen; j++) { @@ -288,7 +316,7 @@ void write_summary_file() { // Next pass looks for calls to schedule. bool first = true; - for (int i = 0; i < table_size; i++) { + for (int i = NUM_EVENT_TYPES; i < table_size; i++) { summary_stats_t* stats = summary_stats[i]; if (stats != NULL && stats->event_type == schedule_called && stats->occurrences > 0) { if (first) { @@ -302,7 +330,7 @@ void write_summary_file() { // Next pass looks for user-defined events. first = true; - for (int i = 0; i < table_size; i++) { + for (int i = NUM_EVENT_TYPES; i < table_size; i++) { summary_stats_t* stats = summary_stats[i]; if (stats != NULL && (stats->event_type == user_event || stats->event_type == user_value) @@ -329,7 +357,7 @@ void write_summary_file() { // Next pass looks for wait events. first = true; - for (int i = 0; i < table_size; i++) { + for (int i = NUM_EVENT_TYPES; i < table_size; i++) { summary_stats_t* stats = summary_stats[i]; if (stats != NULL && ( stats->event_type == worker_wait_ends @@ -369,15 +397,34 @@ int main(int argc, char* argv[]) { usage(); exit(0); } - open_files(argv[1], "csv"); + // Open the trace file. + trace_file = open_file(argv[1], "r"); + if (trace_file == NULL) exit(1); + + // Construct the name of the csv output file and open it. + char* root = root_name(argv[1]); + char csv_filename[strlen(root) + 5]; + strcpy(csv_filename, root); + strcat(csv_filename, ".csv"); + output_file = open_file(csv_filename, "w"); + if (output_file == NULL) exit(1); + + // Construct the name of the summary output file and open it. + char summary_filename[strlen(root) + 13]; + strcpy(summary_filename, root); + strcat(summary_filename, "_summary.csv"); + summary_file = open_file(summary_filename, "w"); + if (summary_file == NULL) exit(1); + + free(root); if (read_header() >= 0) { // Allocate an array for summary statistics. - table_size = object_table_size + (MAX_NUM_WORKERS * 2); + table_size = NUM_EVENT_TYPES + object_table_size + (MAX_NUM_WORKERS * 2); summary_stats = (summary_stats_t**)calloc(table_size, sizeof(summary_stats_t*)); // Write a header line into the CSV file. - fprintf(output_file, "Event, Reactor, Reaction, Worker, Elapsed Logical Time, Microstep, Elapsed Physical Time, Trigger, Extra Delay\n"); + fprintf(output_file, "Event, Reactor, Source, Destination, Elapsed Logical Time, Microstep, Elapsed Physical Time, Trigger, Extra Delay\n"); while (read_and_write_trace() != 0) {}; write_summary_file(); diff --git a/util/tracing/trace_to_influxdb.c b/util/tracing/trace_to_influxdb.c index d8281abd01..a99ae003ec 100644 --- a/util/tracing/trace_to_influxdb.c +++ b/util/tracing/trace_to_influxdb.c @@ -117,6 +117,9 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define MAX_NUM_REACTIONS 64 // Maximum number of reactions reported in summary stats. #define MAX_NUM_WORKERS 64 +/** File containing the trace binary data. */ +FILE* trace_file = NULL; + /** Struct identifying the influx client. */ influx_client_t influx_client; influx_v2_client_t influx_v2_client; @@ -151,10 +154,14 @@ size_t read_and_write_trace() { if (trace_length == 0) return 0; // Write each line. for (int i = 0; i < trace_length; i++) { + + // Ignore federated traces. + if (trace[i].event_type > federated) continue; + char* reaction_name = "none"; - if (trace[i].reaction_number >= 0) { + if (trace[i].dst_id >= 0) { reaction_name = (char*)malloc(4); - snprintf(reaction_name, 4, "%d", trace[i].reaction_number); + snprintf(reaction_name, 4, "%d", trace[i].dst_id); } // printf("DEBUG: reactor self struct pointer: %p\n", trace[i].pointer); int object_instance = -1; @@ -176,7 +183,7 @@ size_t read_and_write_trace() { INFLUX_MEAS(trace_event_names[trace[i].event_type]), INFLUX_TAG("Reactor", reactor_name), INFLUX_TAG("Reaction", reaction_name), - INFLUX_F_INT("Worker", trace[i].worker), + INFLUX_F_INT("Worker", trace[i].src_id), INFLUX_F_INT("Logical Time", trace[i].logical_time), INFLUX_F_INT("Microstep", trace[i].microstep), INFLUX_F_STR("Trigger Name", trigger_name), @@ -259,7 +266,8 @@ int main(int argc, char* argv[]) { exit(1); } - open_files(filename, NULL); + // Open the trace file. + trace_file = open_file(filename, "r"); if (read_header() >= 0) { size_t num_records = 0, result; diff --git a/util/tracing/trace_util.c b/util/tracing/trace_util.c index f688b560d4..0f97b3bdb9 100644 --- a/util/tracing/trace_util.c +++ b/util/tracing/trace_util.c @@ -37,15 +37,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** Buffer for reading object descriptions. Size limit is BUFFER_SIZE bytes. */ char buffer[BUFFER_SIZE]; -/** File containing the trace binary data. */ -FILE* trace_file = NULL; - -/** File for writing the output data. */ -FILE* output_file = NULL; - -/** File for writing summary statistics. */ -FILE* summary_file = NULL; - /** Buffer for reading trace records. */ trace_record_t trace[TRACE_BUFFER_CAPACITY]; @@ -60,6 +51,13 @@ char* top_level = NULL; object_description_t* object_table; int object_table_size = 0; +typedef struct open_file_t open_file_t; +typedef struct open_file_t { + FILE* file; + open_file_t* next; +} open_file_t; +open_file_t* _open_files = NULL; + /** * Function to be invoked upon exiting. */ @@ -68,82 +66,57 @@ void termination() { for (int i = 0; i < object_table_size; i++) { free(object_table[i].description); } - if (trace_file != NULL) { - fclose(trace_file); - } - if (output_file != NULL) { - fclose(output_file); - } - if (summary_file != NULL) { - fclose(summary_file); + while (_open_files != NULL) { + fclose(_open_files->file); + open_file_t* tmp = _open_files->next; + free(_open_files); + _open_files = tmp; } printf("Done!\n"); } -/** - * Open the trace file and the output file using the given filename. - * This leaves the FILE* pointers in the global variables trace_file and output_file. - * If the extension if "csv", then it also opens a summary_file. - * The filename argument can include path information. - * It can include the ".lft" extension or not. - * The output file will have the same path and name except that the - * extension will be given by the second argument. - * The summary_file, if opened, will have the filename with "_summary.csv" appended. - * @param filename The file name. - * @param output_file_extension The extension to put on the output file name (e.g. "csv"). - * @return A pointer to the file. - */ -void open_files(char* filename, char* output_file_extension) { - // Open the input file for reading. - size_t length = strlen(filename); - if (length > 4 && strcmp(&filename[length - 4], ".lft") == 0) { - // The filename includes the .lft extension. - length -= 4; - } - char trace_file_name[length + 4]; - strncpy(trace_file_name, filename, length); - trace_file_name[length] = 0; - strcat(trace_file_name, ".lft"); - trace_file = fopen(trace_file_name, "r"); - if (trace_file == NULL) { - fprintf(stderr, "No trace file named %s.\n", trace_file_name); +const char PATH_SEPARATOR = +#ifdef _WIN32 + '\\'; +#else + '/'; +#endif + +char* root_name(const char* path) { + if (path == NULL) return NULL; + + // Remove any path. + char* last_separator = strrchr(path, PATH_SEPARATOR); + if (last_separator != NULL) path = last_separator + 1; + + // Allocate and copy name without extension. + char* last_period = strrchr(path, '.'); + size_t length = (last_period == NULL) ? + strlen(path) : last_period - path; + char* result = (char*)malloc(length + 1); + if (result == NULL) return NULL; + strncpy(result, path, length); + result[length] = '\0'; + + return result; +} + +FILE* open_file(const char* path, const char* mode) { + FILE* result = fopen(path, mode); + if (result == NULL) { + fprintf(stderr, "No file named %s.\n", path); usage(); exit(2); } - - // Open the output file for writing. - if (output_file_extension) { - char output_file_name[length + strlen(output_file_extension) + 1]; - strncpy(output_file_name, filename, length); - output_file_name[length] = 0; - strcat(output_file_name, "."); - strcat(output_file_name, output_file_extension); - output_file = fopen(output_file_name, "w"); - if (output_file == NULL) { - fprintf(stderr, "Could not create output file named %s.\n", output_file_name); - usage(); - exit(2); - } - - if (strcmp("csv", output_file_extension) == 0) { - // Also open a summary_file. - char *suffix = "_summary.csv"; - char summary_file_name[length + strlen(suffix) + 1]; - strncpy(summary_file_name, filename, length); - summary_file_name[length] = 0; - strcat(summary_file_name, suffix); - summary_file = fopen(summary_file_name, "w"); - if (summary_file == NULL) { - fprintf(stderr, "Could not create summary file named %s.\n", summary_file_name); - usage(); - exit(2); - } - } - } - - if (atexit(termination) != 0) { - fprintf(stderr, "WARNING: Failed to register termination function!"); + open_file_t* record = (open_file_t*)malloc(sizeof(open_file_t)); + if (record == NULL) { + fprintf(stderr, "Out of memory.\n"); + exit(3); } + record->file = result; + record->next = _open_files; + _open_files = record; + return result; } /** diff --git a/util/tracing/trace_util.h b/util/tracing/trace_util.h index 56eb9fe3e8..dab1f5e989 100644 --- a/util/tracing/trace_util.h +++ b/util/tracing/trace_util.h @@ -36,10 +36,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** Macro to use when access to trace file fails. */ #define _LF_TRACE_FAILURE(trace_file) \ do { \ - fprintf(stderr, "WARNING: Access to trace file failed.\n"); \ + fprintf(stderr, "ERROR: Access to trace file failed.\n"); \ fclose(trace_file); \ trace_file = NULL; \ - return -1; \ + exit(1); \ } while(0) /** Buffer for reading object descriptions. Size limit is BUFFER_SIZE bytes. */ @@ -73,18 +73,23 @@ extern int object_table_size; extern char* top_level; /** - * Open the trace file and the output file using the given filename. - * This leaves the FILE* pointers in the global variables trace_file and output_file. - * If the extension if "csv", then it also opens a summary_file. - * The filename argument can include path information. - * It can include the ".lft" extension or not. - * The output file will have the same path and name except that the - * extension will be given by the second argument. - * The summary_file, if opened, will have the filename with "_summary.csv" appended. - * @param filename The file name. - * @param output_file_extension The extension to put on the output file name (e.g. "csv"). + * @brief Return the root file name from the given path. + * Given a path to a file, this function returns a dynamically + * allocated string (which you must free) that points to the root + * filename without the preceding path and without the file extension. + * @param path The path including the full filename. + * @return The root name of the file or NULL for failure. */ -void open_files(char* filename, char* output_file_extension); +char* root_name(const char* path); + +/** + * @brief Open the specified file for reading or writing. + * This function records the file for closing at termination. + * @param path The path to the file. + * @param mode "r" for reading and "w" for writing. + * @return A pointer to the open file or NULL for failure. + */ +FILE* open_file(const char* path, const char* mode); /** * Get the description of the object pointed to by the specified pointer. diff --git a/util/tracing/visualization/.gitignore b/util/tracing/visualization/.gitignore new file mode 100644 index 0000000000..ba0430d26c --- /dev/null +++ b/util/tracing/visualization/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md new file mode 100644 index 0000000000..82861e9b2a --- /dev/null +++ b/util/tracing/visualization/README.md @@ -0,0 +1,25 @@ +# Trace sequence diagram visualiser + +This is a 1st iteration of a prototyping tool for constructing a sequence diagram +out of the traces. +It operates over the csv files generated by `trace_to_csv`. + +# Running + +Once the `.lft` files collected and tranformed into `csv` files, run: +``` +$ python3 sd_gen.py -r -f ... +``` + +The output is an html file with the svg in it. + +# Current problems + +- The collected traces are not complete. They need to be checked for correcteness as well. +- All arrows are horizontal and can be duplicated. Need further processing to derive the connections +for that. +- The scale needs exploration + + + + diff --git a/util/tracing/visualization/fedsd.py b/util/tracing/visualization/fedsd.py new file mode 100644 index 0000000000..3eb13d11bc --- /dev/null +++ b/util/tracing/visualization/fedsd.py @@ -0,0 +1,314 @@ +''' +Define arrows: + (x1, y1) ==> (x2, y2), when unique result (this arrow will be tilted) + (x1, y1) --> (x2, y2), when a possible result (could be not tilted)? +If not arrow, then triangle with text + +In the dataframe, each row will be marked with one op these values: + - 'arrow': draw a non-dashed arrow + - 'dot': draw a dot only + - 'marked': marked, not to be drawn + - 'pending': pending + - 'adv': for reporting logical time advancing, draw a simple dash +''' + +# Styles to determine appearance: +css_style = ' \ +' + +#!/usr/bin/env python3 +import argparse # For arguments parsing +import pandas as pd # For csv manipulation +from os.path import exists +from pathlib import Path +import math +import fedsd_helper as fhlp + +# Define the arguments to pass in the command line +parser = argparse.ArgumentParser(description='Set of the csv trace files to render.') +parser.add_argument('-r','--rti', type=str, default="rti.csv", + help='RTI csv trace file.') +parser.add_argument('-f','--federates', nargs='+', action='append', + help='List of the federates csv trace files.') + + +''' Clock synchronization error ''' +''' FIXME: There should be a value for each communicating pair ''' +clock_sync_error = 0 + +''' Bound on the network latency ''' +''' FIXME: There should be a value for each communicating pair ''' +network_latency = 100000000 # That is 100us + + +def load_and_process_csv_file(csv_file) : + ''' + Loads and processes the csv entries, based on the type of the actor (if RTI + or federate). + + Args: + * csv_file: String file name + Returns: + * The processed dataframe. + ''' + # Load tracepoints, rename the columns and clean non useful data + df = pd.read_csv(csv_file) + df.columns = ['event', 'reactor', 'self_id', 'partner_id', 'logical_time', 'microstep', 'physical_time', 't', 'ed'] + df = df.drop(columns=['reactor', 't', 'ed']) + + # Remove all the lines that do not contain communication information + # which boils up to having 'RTI' in the 'event' column + df = df[df['event'].str.contains('Sending|Receiving|Scheduler advancing time ends') == True] + df = df.astype({'self_id': 'int', 'partner_id': 'int'}) + + # Add an inout column to set the arrow direction + df['inout'] = df['event'].apply(lambda e: 'in' if 'Receiving' in e else 'out') + + # Prune event names + df['event'] = df['event'].apply(lambda e: fhlp.prune_event_name[e]) + return df + + +if __name__ == '__main__': + args = parser.parse_args() + + # Check if the RTI trace file exists + if (not exists(args.rti)): + print('Error: No RTI csv trace file! Specify with -r argument.') + exit(1) + + # The RTI and each of the federates have a fixed x coordinate. They will be + # saved in a dict + x_coor = {} + actors = [] + actors_names = {} + padding = 50 + spacing = 200 # Spacing between federates + + ############################################################################ + #### RTI trace processing + ############################################################################ + trace_df = load_and_process_csv_file(args.rti) + x_coor[-1] = padding * 2 + actors.append(-1) + actors_names[-1] = "RTI" + # Temporary use + trace_df['x1'] = x_coor[-1] + + ############################################################################ + #### Federates trace processing + ############################################################################ + # Loop over the given list of federates trace files + if (args.federates) : + for fed_trace in args.federates[0]: + if (not exists(fed_trace)): + print('Warning: Trace file ' + fed_trace + ' does not exist! Will resume though') + continue + fed_df = load_and_process_csv_file(fed_trace) + if (not fed_df.empty): + # Get the federate id number + fed_id = fed_df.iloc[-1]['self_id'] + # Add to the list of sequence diagram actors and add the name + actors.append(fed_id) + actors_names[fed_id] = Path(fed_trace).stem + # Derive the x coordinate of the actor + x_coor[fed_id] = (padding * 2) + (spacing * (len(actors)-1)) + fed_df['x1'] = x_coor[fed_id] + # Append into trace_df + trace_df = trace_df.append(fed_df, sort=False, ignore_index=True) + fed_df = fed_df[0:0] + + # Sort all traces by physical time and then reset the index + trace_df = trace_df.sort_values(by=['physical_time']) + trace_df = trace_df.reset_index(drop=True) + + # FIXME: For now, we need to remove the rows with negative physical time values... + # Until the reason behinf such values is investigated. The negative physical + # time is when federates are still in the process of joining + # trace_df = trace_df[trace_df['physical_time'] >= 0] + + # Add the Y column and initialize it with the padding value + trace_df['y1'] = math.ceil(padding * 3 / 2) # Or set a small shift + + ############################################################################ + #### Compute the 'y1' coordinates + ############################################################################ + ppt = 0 # Previous physical time + cpt = 0 # Current physical time + py = 0 # Previous y + min = 15 # Minimum spacing between events when time has not advanced. + scale = 1 # Will probably be set manually + first_pass = True + for index, row in trace_df.iterrows(): + if (not first_pass) : + cpt = row['physical_time'] + # print('cpt = '+str(cpt)+' and ppt = '+str(ppt)) + # From the email: + # Y = T_previous + min + log10(1 + (T - T_previous)*scale) + # But rather think it should be: + if (cpt != ppt) : + py = math.ceil(py + min + (1 + math.log10(cpt - ppt) * scale)) + trace_df.at[index, 'y1'] = py + + ppt = row['physical_time'] + py = trace_df.at[index, 'y1'] + first_pass = False + + ############################################################################ + #### Derive arrows that match sided communications + ############################################################################ + # Intialize all rows as pending to be matched + trace_df['arrow'] = 'pending' + trace_df['x2'] = -1 + trace_df['y2'] = -1 + + # Iterate and check possible sides + for index in trace_df.index: + # If the tracepoint is pending, proceed to look for a match + if (trace_df.at[index,'arrow'] == 'pending') : + # Look for a match only if it is not about advancing time + if (trace_df.at[index,'event'] == 'AdvLT') : + trace_df.at[index,'arrow'] = 'adv' + continue + self_id = trace_df.at[index,'self_id'] + partner_id = trace_df.at[index,'partner_id'] + event = trace_df.at[index,'event'] + logical_time = trace_df.at[index, 'logical_time'] + microstep = trace_df.at[index, 'microstep'] + inout = trace_df.at[index, 'inout'] + + # Match tracepoints + matching_df = trace_df[\ + (trace_df['inout'] != inout) & \ + (trace_df['self_id'] == partner_id) & \ + (trace_df['partner_id'] == self_id) & \ + (trace_df['arrow'] == 'pending') & \ + (trace_df['event'] == event) & \ + (trace_df['logical_time'] == logical_time) & \ + (trace_df['microstep'] == microstep) \ + ] + + if (matching_df.empty) : + # If no matching receiver, than set the arrow to 'dot', + # meaning that only a dot will be rendered + trace_df.loc[index, 'arrow'] = 'dot' + else: + # If there is one or more matching rows, then consider + # the first one, since it is an out -> in arrow, and + # since it is the closet in time + # FIXME: What other possible choices to consider? + if (inout == 'out'): + matching_index = matching_df.index[0] + matching_row = matching_df.loc[matching_index] + trace_df.at[index, 'x2'] = matching_row['x1'] + trace_df.at[index, 'y2'] = matching_row['y1'] + else: + matching_index = matching_df.index[-1] + matching_row = matching_df.loc[matching_index] + trace_df.at[index, 'x2'] = trace_df.at[index, 'x1'] + trace_df.at[index, 'y2'] = trace_df.at[index, 'y1'] + trace_df.at[index, 'x1'] = matching_row['x1'] + trace_df.at[index, 'y1'] = matching_row['y1'] + + # Mark it, so not to consider it anymore + trace_df.at[matching_index, 'arrow'] = 'marked' + + trace_df.at[index, 'arrow'] = 'arrow' + + ############################################################################ + #### Write to svg file + ############################################################################ + svg_width = padding * 2 + (len(actors) - 1) * spacing + padding * 2 + 200 + svg_height = padding + trace_df.iloc[-1]['y1'] + + with open('trace_svg.html', 'w', encoding='utf-8') as f: + # Print header + f.write('\n') + f.write('\n') + f.write('\n\n') + + f.write('\n') + + f.write(css_style) + + # Print the circles and the names + for key in x_coor: + title = actors_names[key] + if (key == -1): + f.write(fhlp.svg_string_comment('RTI Actor and line')) + center = 15 + else: + f.write(fhlp.svg_string_comment('Federate '+str(key)+': ' + title + ' Actor and line')) + center = 5 + f.write(fhlp.svg_string_draw_line(x_coor[key], math.ceil(padding/2), x_coor[key], svg_height, False)) + f.write('\t\n') + f.write('\t'+title+'\n') + + # Now, we need to iterate over the traces to draw the lines + f.write(fhlp.svg_string_comment('Draw interactions')) + for index, row in trace_df.iterrows(): + # For time labels, display them on the left for the RTI, right for everthing else. + anchor = 'start' + if (row['self_id'] < 0): + anchor = 'end' + + # formatted physical time. + # FIXME: Using microseconds is hardwired here. + physical_time = f'{int(row["physical_time"]/1000):,}' + + if (row['event'] in {'FED_ID', 'ACK', 'REJECT', 'ADR_RQ', 'ADR_AD', 'MSG', 'P2P_MSG'}): + label = row['event'] + elif (row['logical_time'] == -1678240241788173894) : + # FIXME: This isn't right. NEVER == -9223372036854775808. + label = row['event'] + '(NEVER)' + else: + label = row['event'] + '(' + f'{int(row["logical_time"]):,}' + ', ' + str(row['microstep']) + ')' + + if (row['arrow'] == 'arrow'): + f.write(fhlp.svg_string_draw_arrow(row['x1'], row['y1'], row['x2'], row['y2'], label, row['event'])) + f.write(fhlp.svg_string_draw_side_label(row['x1'], row['y1'], physical_time, anchor)) + elif (row['arrow'] == 'dot'): + if (row['inout'] == 'in'): + label = "(in) from " + str(row['partner_id']) + ' ' + label + else : + label = "(out) to " + str(row['partner_id']) + ' ' + label + + if (anchor == 'end'): + f.write(fhlp.svg_string_draw_side_label(row['x1'], row['y1'], physical_time, anchor)) + f.write(fhlp.svg_string_draw_dot(row['x1'], row['y1'], label)) + else: + f.write(fhlp.svg_string_draw_dot_with_time(row['x1'], row['y1'], physical_time, label)) + + elif (row['arrow'] == 'marked'): + f.write(fhlp.svg_string_draw_side_label(row['x1'], row['y1'], physical_time, anchor)) + + elif (row['arrow'] == 'adv'): + f.write(fhlp.svg_string_draw_adv(row['x1'], row['y1'], label)) + + f.write('\n\n\n') + + # Print footer + f.write('\n') + f.write('\n') + + # Write to a csv file, just to double check + trace_df.to_csv('all.csv', index=True) \ No newline at end of file diff --git a/util/tracing/visualization/fedsd_helper.py b/util/tracing/visualization/fedsd_helper.py new file mode 100644 index 0000000000..804341f117 --- /dev/null +++ b/util/tracing/visualization/fedsd_helper.py @@ -0,0 +1,241 @@ +import math + +# Disctionary for pruning event names. Usefule for tracepoint matching and +# communication rendering +prune_event_name = { + "Sending ACK": "ACK", + "Sending TIMESTAMP": "TIMESTAMP", + "Sending NET": "NET", + "Sending LTC": "LTC", + "Sending STOP_REQ": "STOP_REQ", + "Sending STOP_REQ_REP": "STOP_REQ_REP", + "Sending STOP_GRN": "STOP_GRN", + "Sending FED_ID": "FED_ID", + "Sending PTAG": "PTAG", + "Sending TAG": "TAG", + "Sending REJECT": "REJECT", + "Sending RESIGN": "RESIGN", + "Sending PORT_ABS": "ABS", + "Sending CLOSE_RQ": "CLOSE_RQ", + "Sending TAGGED_MSG": "T_MSG", + "Sending P2P_TAGGED_MSG": "P2P_T_MSG", + "Sending MSG": "MSG", + "Sending P2P_MSG": "P2P_MSG", + "Sending ADR_AD": "ADR_AD", + "Sending ADR_QR": "ADR_QR", + "Receiving ACK": "ACK", + "Receiving TIMESTAMP": "TIMESTAMP", + "Receiving NET": "NET", + "Receiving LTC": "LTC", + "Receiving STOP_REQ": "STOP_REQ", + "Receiving STOP_REQ_REP": "STOP_REQ_REP", + "Receiving STOP_GRN": "STOP_GRN", + "Receiving FED_ID": "FED_ID", + "Receiving PTAG": "PTAG", + "Receiving TAG": "TAG", + "Receiving REJECT": "REJECT", + "Receiving RESIGN": "RESIGN", + "Receiving PORT_ABS": "ABS", + "Receiving CLOSE_RQ": "CLOSE_RQ", + "Receiving TAGGED_MSG": "T_MSG", + "Receiving P2P_TAGGED_MSG": "P2P_T_MSG", + "Receiving MSG": "MSG", + "Receiving P2P_MSG": "P2P_MSG", + "Receiving ADR_AD": "ADR_AD", + "Receiving ADR_QR": "ADR_QR", + "Receiving UNIDENTIFIED": "UNIDENTIFIED", + "Scheduler advancing time ends": "AdvLT" +} + +prune_event_name.setdefault(" ", "UNIDENTIFIED") + +################################################################################ +### Routines to write to csv file +################################################################################ + +def svg_string_draw_line(x1, y1, x2, y2, type=''): + ''' + Constructs the svg html string to draw a line from (x1, y1) to (x2, y2). + + Args: + * x1: Int X coordinate of the source point + * y1: Int Y coordinate of the source point + * x2: Int X coordinate of the sink point + * y2: Int Y coordinate of the sink point + * type: The type of the message (for styling) + Returns: + * String: the svg string of the line© + ''' + str_line = '\t\n' + return str_line + + +def svg_string_draw_arrow_head(x1, y1, x2, y2, type='') : + ''' + Constructs the svg html string to draw the arrow end + + Args: + * x1: Int X coordinate of the source point + * y1: Int Y coordinate of the source point + * x2: Int X coordinate of the sink point + * y2: Int Y coordinate of the sink point + * type: The type (for styling) + Returns: + * String: the svg string of the triangle + ''' + + rotation = - math.ceil(math.atan((x2-x1)/(y2-y1)) * 180 / 3.14) - 90 + style = '' + if (type): + style = ' class="'+type+'"' + + str_line = '' + if (x1 > x2) : + str_line = '\t\n' + else : + str_line = '\t\n' + + return str_line + + +def svg_string_draw_label(x1, y1, x2, y2, label) : + ''' + Computes the rotation angle of the text and then constructs the svg string. + + Args: + * x1: Int X coordinate of the source point + * y1: Int Y coordinate of the source point + * x2: Int X coordinate of the sink point + * y2: Int Y coordinate of the sink point + * label: The label to draw + Returns: + * String: the svg string of the text + ''' + # FIXME: Need further improvement, based of the position of the arrows + # FIXME: Rotation value is not that accurate. + if (x2 < x1) : + # Left-going arrow. + rotation = - math.ceil(math.atan((x2-x1)/(y2-y1)) * 180 / 3.14) - 90 + str_line = '\t'+label+'\n' + else : + # Right-going arrow. + rotation = - math.ceil(math.atan((x1-x2)/(y1-y2)) * 180 / 3.14) + 90 + str_line = '\t'+label+'\n' + #print('rot = '+str(rotation)+' x1='+str(x1)+' y1='+str(y1)+' x2='+str(x2)+' y2='+str(y2)) + return str_line + + +def svg_string_draw_arrow(x1, y1, x2, y2, label, type=''): + ''' + Constructs the svg html string to draw the arrow from (x1, y1) to (x2, y2). + The arrow end is constructed, together with the label + + Args: + * x1: Int X coordinate of the source point + * y1: Int Y coordinate of the source point + * x2: Int X coordinate of the sink point + * y2: Int Y coordinate of the sink point + * label: String Label to draw on top of the arrow + * type: The type of the message + Returns: + * String: the svg string of the arrow + ''' + str_line1 = svg_string_draw_line(x1, y1, x2, y2, type) + str_line2 = svg_string_draw_arrow_head(x1, y1, x2, y2, type) + str_line3 = svg_string_draw_label(x1, y1, x2, y2, label) + return str_line1 + str_line2 + str_line3 + +def svg_string_draw_side_label(x, y, label, anchor="start") : + ''' + Put a label to the right of the x, y point, + unless x is small, in which case put it to the left. + + Args: + * x: Int X coordinate of the source point + * y: Int Y coordinate of the source point + * label: Label to put by the point. + * anchor: One of "start", "middle", or "end" to specify the text-anchor. + Returns: + * String: the svg string of the text + ''' + offset = 5 + if (anchor == 'end'): + offset = -5 + elif (anchor == 'middle'): + offset = 0 + str_line = '\t'+label+'\n' + + return str_line + +def svg_string_comment(comment): + ''' + Constructs the svg html string to write a comment into an svg file. + + Args: + * comment: String Comment to add + Returns: + * String: the svg string of the comment + ''' + str_line = '\n\t\n' + return str_line + + +def svg_string_draw_dot(x, y, label) : + ''' + Constructs the svg html string to draw at a dot. + + Args: + * x: Int X coordinate of the dot + * y: Int Y coordinate of the dot + * label: String to draw + Returns: + * String: the svg string of the triangle + ''' + str_line = '' + str_line = '\t\n' + str_line = str_line + '\t'+label+'\n' + return str_line + +def svg_string_draw_dot_with_time(x, y, time, label) : + ''' + Constructs the svg html string to draw at a dot with a prefixed physical time. + + Args: + * x: Int X coordinate of the dot + * y: Int Y coordinate of the dot + * time: The time + * label: String to draw + Returns: + * String: the svg string of the triangle + ''' + str_line = '' + str_line = '\t\n' + str_line = str_line + '\t '+time+': '+label+'\n' + return str_line + +def svg_string_draw_adv(x, y, label) : + ''' + Constructs the svg html string to draw at a dash, meaning that logical time is advancing there. + + Args: + * x: Int X coordinate of the dash + * y: Int Y coordinate of the dash + * label: String to draw + Returns: + * String: the svg string of the triangle + ''' + str_line1 = svg_string_draw_line(x-5, y, x+5, y, "ADV") + str_line2 = svg_string_draw_side_label(x, y, label) + return str_line1 + str_line2 \ No newline at end of file From e8a1b0522b68c81d8d275390342799378010bc11 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:15:40 +0100 Subject: [PATCH 076/709] Deleted spurious empty files --- thread_active | 0 watchdog_function | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 thread_active delete mode 100644 watchdog_function diff --git a/thread_active b/thread_active deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/watchdog_function b/watchdog_function deleted file mode 100644 index e69de29bb2..0000000000 From 534a003d431eefef1151a31e0ecab9f79a40043e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:37:16 +0100 Subject: [PATCH 077/709] Removed unused imports --- org.lflang/src/org/lflang/ASTUtils.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index fc49242322..19dcc68ca0 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -32,7 +32,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -60,8 +59,6 @@ import org.lflang.generator.InvalidSourceException; import org.lflang.lf.Action; import org.lflang.lf.Assignment; -import org.lflang.lf.AttrParm; -import org.lflang.lf.Attribute; import org.lflang.lf.Code; import org.lflang.lf.Connection; import org.lflang.lf.Element; From cb06dffb64a3115da6edadb8dfc515695a8e9b15 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:37:40 +0100 Subject: [PATCH 078/709] Group watchdog with action --- org.lflang/src/org/lflang/LinguaFranca.xtext | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 870b1ad049..71213d36c2 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -175,10 +175,10 @@ Mode: (stateVars+=StateVar) | (timers+=Timer) | (actions+=Action) | + (watchdogs+=Watchdog) | (instantiations+=Instantiation) | (connections+=Connection) | - (reactions+=Reaction) | - (watchdogs+=Watchdog) + (reactions+=Reaction) )* '}'; // Action that has either a physical or logical origin. From 302f690158d5aa85862650551bbbc8caf583735a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:37:58 +0100 Subject: [PATCH 079/709] Removed unused imports --- .../org/lflang/federated/generator/FederateInstance.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index f3768cec7c..8ed3b63d70 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -25,7 +25,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.federated.generator; -import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -40,17 +39,13 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.ASTUtils; import org.lflang.ErrorReporter; -import org.lflang.FileConfig; -import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TimeValue; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.ActionInstance; -import org.lflang.generator.GeneratorUtils; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.SubContext; import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -70,7 +65,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; -import org.lflang.lf.Watchdog; import com.google.common.base.Objects; From 7b05cd6d7edbf01179e175276187fbef5ecc9eac Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:38:29 +0100 Subject: [PATCH 080/709] Removed non-substantive change --- org.lflang/src/org/lflang/generator/ReactionInstance.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index 3ce7f6ceaa..cf9dce7013 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -221,7 +221,7 @@ public ReactionInstance( * Deadline for this reaction instance, if declared. */ public DeadlineInstance declaredDeadline; - + /** * Sadly, we have no way to mark reaction "unordered" in the AST, * so instead, we use a magic comment at the start of the reaction body. From 673a7fcd58329d2a013ffc748638c6e878ff5eb3 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 11:39:41 +0100 Subject: [PATCH 081/709] Removed unused or redundant imports --- org.lflang/src/org/lflang/generator/ReactorInstance.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index cc049f971c..395bb90d6d 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -35,8 +35,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Map; import java.util.Set; -import org.eclipse.emf.ecore.util.EcoreUtil; - import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; @@ -49,7 +47,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; -import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; import org.lflang.lf.Output; import org.lflang.lf.Parameter; @@ -63,8 +60,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Variable; import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; -import org.lflang.lf.Watchdog; - /** * Representation of a compile-time instance of a reactor. From 91086adfabc0612caa763b7bd4cb034b0456e918 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 15:26:45 +0100 Subject: [PATCH 082/709] Made this a real test --- test/C/src/Watchdog.lf | 65 +++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index e3d7f6cb41..b44a16f22c 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -1,33 +1,64 @@ -target C +/** + * Test watchdog. + * This test starts a watchdog timer of 150ms every 100ms. + * Half the time, it then sleeps after starting the watchdog so that + * the watchdog expires. There should be a total of five watchdog + * expirations. + * @author Benjamin Asch + * @author Edward A. Lee + */ +target C { + timeout: 1100ms +} -reactor Watcher { - input x: int - output d: int // Produced if the deadline is violated. +reactor Watcher(timeout:time(150ms)) { + timer t(100ms, 100ms) // Offset ameliorates startup time. + output d: int // Produced if the watchdog triggers. + state alternating:bool(false) + state count:int(0) - watchdog poodle(10 msec) {= + watchdog poodle(timeout) {= instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); - printf("Deadline missed! Lag: %lld (too late by %lld nsecs)\n", p, p-500000); + lf_print("Watchdog timed out! Lag: %lld (too late by " PRINTF_TIME " ns)", p, p - self->timeout); + self->count++; =} - reaction(x) -> poodle, d {= + reaction(t) -> poodle, d {= lf_watchdog_start(poodle, 0); - printf("Normal reaction.\n"); + lf_print("Watchdog started at physical time " PRINTF_TIME, lf_time_physical_elapsed()); + lf_print("Will expire at " PRINTF_TIME, lf_time_logical_elapsed() + self->timeout); + if (self->alternating) { + lf_sleep(MSEC(160)); + } + self->alternating = !self->alternating; + =} + + reaction(poodle) -> d {= + lf_set(d, 1); + =} + + reaction(shutdown) -> poodle {= + // FIXME: There needs to be an lf_watchdog_stop() defined. + _lf_watchdog_stop(poodle); + if (self->count != 5) { + lf_print_error_and_exit("Watchdog expired %d times. Expected 5.", self->count); + } =} } main reactor { logical action a + state count:int(0) + w = new Watcher() - reaction(startup) -> w.x, a {= - lf_set(w.x, 0); - lf_schedule(a, 0); + reaction(w.d) {= + lf_print("*** Watcher reactor produced an output."); + self->count++; =} - - reaction(a) -> w.x {= - lf_set(w.x, 0); - lf_nanosleep(MSEC(90)); + reaction(shutdown) {= + if (self->count != 4) { + lf_print_error_and_exit("Watchdog produced output %d times. Expected 4.", self->count); + } =} - - reaction(w.d) {= printf("Deadline reactor produced an output.\n"); =} } From c20e711b19a439deee5d88daf46283a555c920ab Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 15:31:04 +0100 Subject: [PATCH 083/709] Made fields private and rearranged --- .../lflang/generator/WatchdogInstance.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 2a2e11a3ad..001246cf2f 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -13,16 +13,15 @@ public class WatchdogInstance { /** - * Create a new watchdog instance associated with the given reaction + * Create a new watchdog instance associated with the given reactor * instance. */ public WatchdogInstance(Watchdog definition, ReactorInstance reactor) { if (definition.getTimeout() != null) { - // WATCHDOG QUESTION - // How does this .getTimeValue work? Where is expression coming from - // versus other time parameters? + // Get the timeout value given in the watchdog declaration. this.timeout = reactor.getTimeValue(definition.getTimeout()); } else { + // NOTE: The grammar does not allow the timeout to be omitted, so this should not occur. this.timeout = TimeValue.ZERO; } @@ -31,6 +30,9 @@ public WatchdogInstance(Watchdog definition, ReactorInstance reactor) { this.reactor = reactor; } + ////////////////////////////////////////////////////// + //// Public methods. + public String getName() { return this.name; } @@ -47,27 +49,19 @@ public ReactorInstance getReactor() { return this.reactor; } - ////////////////////////////////////////////////////// - //// Public fields. - + @Override + public String toString() { + return "WatchdogInstance " + name + "(" + timeout.toString() + ")"; + } - public final TimeValue timeout; + ////////////////////////////////////////////////////// + //// Private fields. - /** - * The watchdog name. - */ - public final String name; + private final TimeValue timeout; - public final Watchdog definition; + private final String name; - public final ReactorInstance reactor; + private final Watchdog definition; - ////////////////////////////////////////////////////// - //// Public methods. - - //FIXME: unsure of use or need for watchdogs - @Override - public String toString() { - return "WatchdogInstance " + timeout.toString(); - } + private final ReactorInstance reactor; } From bb2a21d38e9abfc906d25b00ed64223af2eefdbc Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 15:32:13 +0100 Subject: [PATCH 084/709] Fixed hasWatchdogs, which was always returning true --- .../src/org/lflang/generator/c/CGenerator.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e7ce2439f8..fbaec56d97 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -36,9 +36,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import static org.lflang.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -81,7 +79,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.ReactorInstance; import org.lflang.generator.WatchdogInstance; -import org.lflang.generator.SubContext; import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; @@ -839,7 +836,8 @@ private boolean hasDeadlines(List reactors) { private boolean hasWatchdogs() { for (Reactor reactor : reactors) { - if (ASTUtils.allWatchdogs(reactor) != null) { + List watchdogs = ASTUtils.allWatchdogs(reactor); + if (watchdogs != null && !watchdogs.isEmpty()) { return true; } } @@ -1526,9 +1524,8 @@ private void recordWatchdogs(ReactorInstance instance) { var reactorRef = CUtil.reactorRef(instance); // temp.pr("#ifdef LF_THREADED"); for (WatchdogInstance watchdog : instance.watchdogs) { - temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); + temp.pr("_lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); + temp.pr(reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); watchdogCount += 1; foundOne = true; } @@ -1903,8 +1900,6 @@ protected void generateStateVariableInitializations(ReactorInstance instance) { * specified reactor instance. * @param instance The reactor instance. */ - // WATCHDOG QUESTION: Why do we wait to set the deadline instead of defining - // it in the constructor of the reactor? private void generateSetDeadline(ReactorInstance instance) { for (ReactionInstance reaction : instance.reactions) { var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; From 6d33efc3a61a51e66707749b7e674039a413c2aa Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 15:32:39 +0100 Subject: [PATCH 085/709] Regularized function pointer --- org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 344209c3b8..4193a7c522 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -150,7 +150,7 @@ public static void generateWatchdogStruct( "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", "self->_lf_watchdog_"+watchdogName+".thread_active = false;", // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", - "self->_lf_watchdog_"+watchdogName+".watchdog_function = &("+watchdogFunctionName+");" + "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" )); // constructorCode.pr("#endif"); // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? From 5e31d322765f6bc1706b12b6b016028c4eca6ff1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 25 Mar 2023 15:34:50 +0100 Subject: [PATCH 086/709] Align reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 10c275b99a..24c0dc700b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 10c275b99a01802f00168b92d4e9068fdf9b34b6 +Subproject commit 24c0dc700bfde4ddf8a592fef82a837528006340 From c1eafa7c827b7885ca92a31ca5119dca2515bd73 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Mon, 27 Mar 2023 21:47:39 +0500 Subject: [PATCH 087/709] [C-Generics] - Build Fixes - Allowing Template Types to be defined for in/out ports or state variables - Reordering definitions with includes Signed-off-by: mkhubaibumer --- .../generator/ReactionInstanceGraph.java | 4 +- .../org/lflang/generator/ReactorInstance.java | 14 ++++--- .../generator/c/CConstructorGenerator.java | 10 ++--- .../org/lflang/generator/c/CGenerator.java | 37 +++++++++++-------- .../lflang/generator/c/CMethodGenerator.java | 3 +- .../c/CReactorHeaderFileGenerator.java | 21 ++++++----- .../src/org/lflang/generator/c/CUtil.java | 15 +++++++- .../generator/c/TypeParameterizedReactor.java | 2 +- .../generator/python/PythonGenerator.java | 20 +++++----- 9 files changed, 76 insertions(+), 50 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index 3422ee0d50..a1598bff0c 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -411,7 +411,7 @@ public String toDOT() { var currentLevelNodes = groupedNodes.get(level); for (var node: currentLevelNodes) { // Draw the node - var label = CUtil.getName(node.getReaction().getParent().reactorDefinition) + "." + node.getReaction().getName(); + var label = CUtil.getName(node.getReaction().getParent().tpr) + "." + node.getReaction().getName(); // Need a positive number to name the nodes in GraphViz var labelHashCode = label.hashCode() & 0xfffffff; dotRepresentation.pr(" node_" + labelHashCode + " [label=\""+ label +"\"];"); @@ -419,7 +419,7 @@ public String toDOT() { // Draw the edges var downstreamNodes = getDownstreamAdjacentNodes(node); for (var downstreamNode: downstreamNodes) { - var downstreamLabel = CUtil.getName(downstreamNode.getReaction().getParent().reactorDefinition) + "." + downstreamNode.getReaction().getName(); + var downstreamLabel = CUtil.getName(downstreamNode.getReaction().getParent().tpr) + "." + downstreamNode.getReaction().getName(); edges.append(" node_" + labelHashCode + " -> node_" + (downstreamLabel.hashCode() & 0xfffffff) + ";\n" ); diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index af295818b3..0a5c9e0b85 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -767,11 +767,11 @@ protected TriggerInstance getOrCreateBuiltinTrigger(Buil * @param reporter An error reporter. * @param desiredDepth The depth to which to expand the hierarchy. */ - private ReactorInstance( - Instantiation definition, - ReactorInstance parent, - ErrorReporter reporter, - int desiredDepth) { + public ReactorInstance( + Instantiation definition, + ReactorInstance parent, + ErrorReporter reporter, + int desiredDepth) { super(definition, parent); this.reporter = reporter; this.reactorDeclaration = definition.getReactorClass(); @@ -865,6 +865,10 @@ private ReactorInstance( } } + public TypeParameterizedReactor getTypeParameterizedReactor() { + return this.tpr; + } + ////////////////////////////////////////////////////// //// Private methods. diff --git a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java b/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java index 8944fd0796..41731106c3 100644 --- a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java @@ -15,12 +15,12 @@ public class CConstructorGenerator { * go into the constructor. */ public static String generateConstructor( - Reactor reactor, + TypeParameterizedReactor tpr, String constructorCode ) { - var structType = CUtil.selfType(reactor); + var structType = CUtil.selfType(tpr); var code = new CodeBuilder(); - code.pr(structType+"* new_"+CUtil.getName(reactor)+"() {"); + code.pr(structType+"* new_"+CUtil.getName(tpr)+"() {"); code.indent(); code.pr(structType+"* self = ("+structType+"*)_lf_new_reactor(sizeof("+structType+"));"); code.pr(constructorCode); @@ -30,7 +30,7 @@ public static String generateConstructor( return code.toString(); } - public static String generateConstructorPrototype(Reactor reactor) { - return CUtil.selfType(reactor)+"* new_"+CUtil.getName(reactor)+"();"; + public static String generateConstructorPrototype(TypeParameterizedReactor tpr) { + return CUtil.selfType(tpr)+"* new_"+CUtil.getName(tpr)+"();"; } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 0b5602d9d9..282d73d45d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -939,9 +939,9 @@ private void generateHeaders() throws IOException { fileConfig.getIncludePath(), false ); - for (Reactor r : reactors) { - CReactorHeaderFileGenerator.doGenerate(types, r, fileConfig, this::generateAuxiliaryStructs, this::generateTopLevelPreambles); - } +// for (var r : reactors) { + CReactorHeaderFileGenerator.doGenerate(types, this.main.tpr, fileConfig, this::generateAuxiliaryStructs, this::generateTopLevelPreambles); +// } FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); } @@ -1034,12 +1034,13 @@ private void generateReactorClass(TypeParameterizedReactor tpr) throws IOExcepti header.pr(generateTopLevelPreambles(tpr.r())); generateUserPreamblesForReactor(tpr.r(), src); generateReactorClassBody(tpr, header, src); + tpr.typeArgs().entrySet().forEach(it -> header.pr("#undef " + it.getKey())); header.pr("#endif // " + guardMacro); FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" - : (CCppMode ? ".cpp" : ".c"); + : CCppMode ? ".cpp" : ".c"; FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve( - CUtil.getName(reactor) + extension), true); + CUtil.getName(tpr) + extension), true); } protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { @@ -1047,7 +1048,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("extern \"C\" {"); header.pr("extern \"C\" {"); } - tpr.typeArgs().entrySet().forEach(it -> src.pr("#define " + it.getKey() + " " + ASTUtils.toText(it.getValue()))); + tpr.typeArgs().entrySet().forEach(it -> header.pr("#define " + it.getKey() + " " + ASTUtils.toText(it.getValue()))); header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); @@ -1058,6 +1059,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String } src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(fileConfig, tpr.r()) + "\""); src.pr("#include \"" + headerName + "\""); + tpr.typeArgs().entrySet().forEach(it -> src.pr("#define " + it.getKey() + " " + ASTUtils.toText(it.getValue()))); new HashSet<>(ASTUtils.allInstantiations(tpr.r())).stream() .map(TypeParameterizedReactor::new).map(CUtil::getName) .map(name -> "#include \"" + name + ".h\"") @@ -1068,11 +1070,11 @@ private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder // Some of the following methods create lines of code that need to // go into the constructor. Collect those lines of code here: var constructorCode = new CodeBuilder(); - generateAuxiliaryStructs(header, reactor, false); - generateSelfStruct(header, reactor, constructorCode); - generateMethods(src, reactor); - generateReactions(src, reactor); - generateConstructor(src, header, reactor, constructorCode); + generateAuxiliaryStructs(header, tpr, false); + generateSelfStruct(header, tpr, constructorCode); + generateMethods(src, tpr.r()); + generateReactions(src, tpr.r()); + generateConstructor(src, header, tpr, constructorCode); } /** @@ -1097,16 +1099,16 @@ protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) /** * Generate a constructor for the specified reactor in the specified federate. - * @param reactor The parsed reactor data structure. + * @param tpr The parsed reactor data structure. * @param constructorCode Lines of code previously generated that need to * go into the constructor. */ protected void generateConstructor( - CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode + CodeBuilder src, CodeBuilder header, TypeParameterizedReactor tpr, CodeBuilder constructorCode ) { - header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); + header.pr(CConstructorGenerator.generateConstructorPrototype(tpr)); src.pr(CConstructorGenerator.generateConstructor( - reactor, + tpr, constructorCode.toString() )); } @@ -1363,7 +1365,7 @@ private void generateInteractingContainedReactors( /** * This function is provided to allow extensions of the CGenerator to append the structure of the self struct * @param body The body of the self struct - * @param decl The reactor declaration for the self struct + * @param reactor The reactor declaration for the self struct * @param constructorCode Code that is executed when the reactor is instantiated */ protected void generateSelfStructExtension( @@ -1650,6 +1652,9 @@ public void processProtoFile(String filename) { public static String variableStructType(Variable variable, TypeParameterizedReactor tpr, boolean userFacing) { return (userFacing ? tpr.getName().toLowerCase() : CUtil.getName(tpr)) +"_"+variable.getName()+"_t"; } + public static String variableStructType(Variable variable, Reactor r, boolean userFacing) { + return (userFacing ? r.getName().toLowerCase() : CUtil.getName(r)) +"_"+variable.getName()+"_t"; + } /** * Construct a unique type for the struct of the specified diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index a4e3dba149..5f8a4d6ad1 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -5,6 +5,7 @@ import org.lflang.ASTUtils; import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.ReactorInstance; import org.lflang.lf.Method; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; @@ -67,7 +68,7 @@ public static String generateMethod( code.indent(); // Define the "self" struct. - String structType = CUtil.selfType(ASTUtils.toDefinition(decl)); + String structType = CUtil.selfType((ReactorInstance) ASTUtils.toDefinition(decl)); // A null structType means there are no inputs, state, // or anything else. No need to declare it. if (structType != null) { diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index b947f3ca67..92318c0150 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -16,6 +16,7 @@ import org.lflang.lf.Reactor; import org.lflang.lf.StateVar; import org.lflang.lf.TriggerRef; +import org.lflang.lf.Type; import org.lflang.lf.TypedVariable; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; @@ -24,7 +25,7 @@ public class CReactorHeaderFileGenerator { public interface GenerateAuxiliaryStructs { - void generate(CodeBuilder b, Reactor r, boolean userFacing); + void generate(CodeBuilder b, TypeParameterizedReactor r, boolean userFacing); } public static Path outputPath(CFileConfig fileConfig, Reactor r) { @@ -33,19 +34,19 @@ public static Path outputPath(CFileConfig fileConfig, Reactor r) { .resolve(r.getName() + ".h"); } - public static void doGenerate(CTypes types, Reactor r, CFileConfig fileConfig, GenerateAuxiliaryStructs generator, Function topLevelPreamble) throws IOException { - String contents = generateHeaderFile(types, r, generator, topLevelPreamble.apply(r)); - FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(fileConfig, r))); + public static void doGenerate(CTypes types, TypeParameterizedReactor tpr, CFileConfig fileConfig, GenerateAuxiliaryStructs generator, Function topLevelPreamble) throws IOException { + String contents = generateHeaderFile(types, tpr, generator, topLevelPreamble.apply(tpr.r())); + FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(fileConfig, tpr.r()))); } - private static String generateHeaderFile(CTypes types, Reactor r, GenerateAuxiliaryStructs generator, String topLevelPreamble) { + private static String generateHeaderFile(CTypes types, TypeParameterizedReactor tpr, GenerateAuxiliaryStructs generator, String topLevelPreamble) { CodeBuilder builder = new CodeBuilder(); - appendIncludeGuard(builder, r); + appendIncludeGuard(builder, tpr.r()); builder.pr(topLevelPreamble); appendPoundIncludes(builder); - appendSelfStruct(builder, types, r); - generator.generate(builder, r, true); - for (Reaction reaction : r.getReactions()) { - appendSignature(builder, types, reaction, r); + appendSelfStruct(builder, types, tpr.r()); + generator.generate(builder, tpr, true); + for (Reaction reaction : tpr.r().getReactions()) { + appendSignature(builder, types, reaction, tpr.r()); } builder.pr("#endif"); return builder.getCode(); diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index b92f93023d..15097b6205 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -154,6 +154,13 @@ public static String getName(TypeParameterizedReactor reactor) { } return name; } + public static String getName(Reactor reactor) { + String name = reactor.getName().toLowerCase() + reactor.hashCode(); + if (reactor.isMain()) { + return name + "_main"; + } + return name; + } /** * Return a reference to the specified port. @@ -522,10 +529,16 @@ public static String selfType(TypeParameterizedReactor reactor) { } return "_" + CUtil.getName(reactor) + "_self_t"; } + public static String selfType(Reactor reactor) { + if (reactor.isMain()) { + return "_" + CUtil.getName(reactor) + "_main_self_t"; + } + return "_" + CUtil.getName(reactor) + "_self_t"; + } /** Construct a unique type for the "self" struct of the class of the given reactor. */ public static String selfType(ReactorInstance instance) { - return selfType(ASTUtils.toDefinition(instance.getDefinition().getReactorClass())); + return selfType(instance.tpr); } /** diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 9e79a65728..281139c4af 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -36,6 +36,6 @@ public String getName() { @Override public int hashCode() { - return r.hashCode() * 31 + typeArgs.hashCode(); + return Math.abs(r.hashCode() * 31 + typeArgs.hashCode()); } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index b20a5d9de2..fcb1c19595 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -55,6 +55,7 @@ import org.lflang.generator.c.CCmakeGenerator; import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.Code; import org.lflang.lf.Input; @@ -64,6 +65,7 @@ import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; +import org.lflang.lf.Type; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; @@ -354,16 +356,16 @@ public void processProtoFile(String filename) { */ @Override public void generateAuxiliaryStructs( - CodeBuilder builder, Reactor r, boolean userFacing + CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing ) { - for (Input input : ASTUtils.allInputs(r)) { - generateAuxiliaryStructsForPort(builder, r, input); + for (Input input : ASTUtils.allInputs(tpr.r())) { + generateAuxiliaryStructsForPort(builder, tpr.r(), input); } - for (Output output : ASTUtils.allOutputs(r)) { - generateAuxiliaryStructsForPort(builder, r, output); + for (Output output : ASTUtils.allOutputs(tpr.r())) { + generateAuxiliaryStructsForPort(builder, tpr.r(), output); } - for (Action action : ASTUtils.allActions(r)) { - generateAuxiliaryStructsForAction(builder, r, action); + for (Action action : ASTUtils.allActions(tpr.r())) { + generateAuxiliaryStructsForAction(builder, tpr.r(), action); } } @@ -517,9 +519,9 @@ protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) } @Override - protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { + protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { header.pr(PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors)); - super.generateReactorClassHeaders(reactor, headerName, header, src); + super.generateReactorClassHeaders(tpr, headerName, header, src); } /** From 9cabad27f5c8214af7f4b4b2bf5113ce5fa1d3f5 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 28 Mar 2023 15:00:25 +0200 Subject: [PATCH 088/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index b260ebc83c..fe5e6c2d1c 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit b260ebc83cea97335e984d1eb26d6b581e900280 +Subproject commit fe5e6c2d1cbc38b46b7298facb5f77e5ba6f387c From 1dfb39d49dcd32b116e07f3e8964037d6898176a Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Wed, 29 Mar 2023 15:58:50 +0500 Subject: [PATCH 089/709] [C-Generics] HashCode missmatch bug --- .../src/org/lflang/generator/c/CReactionGenerator.java | 4 ++-- .../org/lflang/generator/python/PythonActionGenerator.java | 5 +++-- .../src/org/lflang/generator/python/PythonGenerator.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 051540bbf6..23818cb2ef 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -758,9 +758,9 @@ public static void generateReactionAndTriggerStructs( "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", - (reaction.eContainer() instanceof Mode ? + reaction.eContainer() instanceof Mode ? "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+reactor.getModes().indexOf((Mode) reaction.eContainer())+"];" : - "self->_lf__reaction_"+reactionCount+".mode = NULL;") + "self->_lf__reaction_"+reactionCount+".mode = NULL;" )); // Increment the reactionCount even if the reaction is not in the federate // so that reaction indices are consistent across federates. diff --git a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java index a2a149f522..13dbed0f0f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java @@ -1,13 +1,14 @@ package org.lflang.generator.python; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.Reactor; import org.lflang.generator.c.CGenerator; public class PythonActionGenerator { - public static String generateAliasTypeDef(Reactor r, Action action, + public static String generateAliasTypeDef(TypeParameterizedReactor tpr, Action action, String genericActionType) { - return "typedef "+genericActionType+" "+CGenerator.variableStructType(action, r, false)+";"; + return "typedef "+genericActionType+" "+CGenerator.variableStructType(action, tpr, false)+";"; } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index fcb1c19595..6a1a6ecd1d 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -365,7 +365,7 @@ public void generateAuxiliaryStructs( generateAuxiliaryStructsForPort(builder, tpr.r(), output); } for (Action action : ASTUtils.allActions(tpr.r())) { - generateAuxiliaryStructsForAction(builder, tpr.r(), action); + generateAuxiliaryStructsForAction(builder, tpr, action); } } @@ -377,9 +377,9 @@ private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, genericPortType)); } - private void generateAuxiliaryStructsForAction(CodeBuilder builder, Reactor r, + private void generateAuxiliaryStructsForAction(CodeBuilder builder, TypeParameterizedReactor tpr, Action action) { - builder.pr(action, PythonActionGenerator.generateAliasTypeDef(r, action, genericActionType)); + builder.pr(action, PythonActionGenerator.generateAliasTypeDef(tpr, action, genericActionType)); } /** From 77109fe92d2e34ea54cb9ffe45ea413b28dac7b4 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Wed, 29 Mar 2023 19:50:41 +0500 Subject: [PATCH 090/709] [C-Generics] Working Generic Code Basic implementation for Generic Reactors in C-Target are done We can run the following Generic Code for demonstration of this feature. These macros will be included to LF for user conveniance ``` target C { keepalive: true, // fast: true } preamble {= /// -- Start // All C-Generic Reactors will probably need these /// -- End =} reactor Connector(latency:int(0)) { input in:I; output out:O; logical action delayed_sch; reaction(in) -> delayed_sch {= lf_schedule(delayed_sch, self->latency); =} reaction(delayed_sch) in -> out {= if (is_same_type(in->value, out->value)) { lf_set(out, in->value); } else { auto_t tmp = CALL_CONVERTOR(I, O, in->value); // If convertor function is defined this will be called lf_set(out, tmp); } =} } reactor A { output Aout:int; logical action post; timer t(0, 1sec); reaction(t) -> post {= lf_schedule(post, 2); =} reaction(post) -> Aout {= lf_set(Aout, rand()); =} } reactor B { input Bin:float; reaction(Bin) {= printf("got %f\n", Bin->value); =} } main reactor { a = new A(); w = new Connector(latency=500); w2 = new Connector(latency=500); b = new B(); a.Aout -> w.in; w.out -> b.Bin; } ``` Signed-off-by: mkhubaibumer --- .../org/lflang/generator/c/CGenerator.java | 55 +++++---- .../lflang/generator/c/CMethodGenerator.java | 48 ++++---- .../generator/c/CReactionGenerator.java | 111 +++++++++--------- .../c/CReactorHeaderFileGenerator.java | 38 +++--- .../src/org/lflang/generator/c/CUtil.java | 6 - .../generator/python/PythonGenerator.java | 24 ++-- .../generator/python/PythonPortGenerator.java | 5 +- .../python/PythonReactionGenerator.java | 10 +- .../python/PythonReactorGenerator.java | 4 +- .../org/lflang/validation/LFValidator.java | 12 +- 10 files changed, 157 insertions(+), 156 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 282d73d45d..b9fc9e57dc 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1052,7 +1052,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); - generateIncludes(tpr.r()); + generateIncludes(tpr); if (CCppMode) { src.pr("}"); header.pr("}"); @@ -1072,16 +1072,16 @@ private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder var constructorCode = new CodeBuilder(); generateAuxiliaryStructs(header, tpr, false); generateSelfStruct(header, tpr, constructorCode); - generateMethods(src, tpr.r()); - generateReactions(src, tpr.r()); + generateMethods(src, tpr); + generateReactions(src, tpr); generateConstructor(src, header, tpr, constructorCode); } /** * Generate methods for {@code reactor}. */ - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { - CMethodGenerator.generateMethods(reactor, src, types); + protected void generateMethods(CodeBuilder src, TypeParameterizedReactor tpr) { + CMethodGenerator.generateMethods(tpr, src, types); } /** @@ -1113,8 +1113,8 @@ protected void generateConstructor( )); } - protected void generateIncludes(Reactor r) { - code.pr("#include \"" + CUtil.getName(r) + ".h\""); + protected void generateIncludes(TypeParameterizedReactor tpr) { + code.pr("#include \"" + CUtil.getName(tpr) + ".h\""); } /** @@ -1201,11 +1201,12 @@ private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tp // struct has a place to hold the data produced by this reactor's // reactions and a place to put pointers to data produced by // the contained reactors. - generateInteractingContainedReactors(reactor, body, constructorCode); + generateInteractingContainedReactors(tpr, reactor, body, constructorCode); // Next, generate the fields needed for each reaction. CReactionGenerator.generateReactionAndTriggerStructs( body, + tpr, reactor, constructorCode, types @@ -1237,11 +1238,13 @@ private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tp * reactions and a place to put pointers to data produced by * the contained reactors. * + * @param tpr The TypeParameterized Reactor * @param reactor The reactor. * @param body The place to put the struct definition for the contained reactors. * @param constructorCode The place to put matching code that goes in the container's constructor. */ private void generateInteractingContainedReactors( + TypeParameterizedReactor tpr, Reactor reactor, CodeBuilder body, CodeBuilder constructorCode @@ -1279,12 +1282,12 @@ private void generateInteractingContainedReactors( // to be malloc'd at initialization. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); + body.pr(port, variableStructType(port, tpr, false)+" "+port.getName()+";"); } else { // Is a multiport. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + variableStructType(port, tpr, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1294,13 +1297,13 @@ private void generateInteractingContainedReactors( // self struct of the container. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); + body.pr(port, variableStructType(port, tpr, false)+"* "+port.getName()+";"); } else { // Is a multiport. // Here, we will use an array of pointers. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + variableStructType(port, tpr, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1308,10 +1311,10 @@ private void generateInteractingContainedReactors( var reactorIndex = ""; if (containedReactor.getWidthSpec() != null) { reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); + constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+tpr.getName()+"_width; reactor_index++) {"); constructorCode.indent(); } - var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); + var portOnSelf = "self->_lf_"+tpr.getName()+reactorIndex+"."+port.getName(); constructorCode.pr( port, @@ -1356,8 +1359,8 @@ private void generateInteractingContainedReactors( } body.unindent(); body.pr(String.join("\n", - "} _lf_"+containedReactor.getName()+array+";", - "int _lf_"+containedReactor.getName()+"_width;" + "} _lf_"+tpr.getName()+array+";", + "int _lf_"+tpr.getName()+"_width;" )); } } @@ -1380,13 +1383,13 @@ protected void generateSelfStructExtension( * These functions have a single argument that is a void* pointing to * a struct that contains parameters, state variables, inputs (triggering or not), * actions (triggering or produced), and outputs. - * @param r The reactor. + * @param tpr The reactor. */ - public void generateReactions(CodeBuilder src, Reactor r) { + public void generateReactions(CodeBuilder src, TypeParameterizedReactor tpr) { var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(r); + var reactor = ASTUtils.toDefinition(tpr.r()); for (Reaction reaction : allReactions(reactor)) { - generateReaction(src, reaction, r, reactionIndex); + generateReaction(src, reaction, tpr, reactionIndex); // Increment reaction index even if the reaction is not in the federate // so that across federates, the reaction indices are consistent. reactionIndex++; @@ -1398,13 +1401,13 @@ public void generateReactions(CodeBuilder src, Reactor r) { * a struct that contains parameters, state variables, inputs (triggering or not), * actions (triggering or produced), and outputs. * @param reaction The reaction. - * @param r The reactor. + * @param tpr The reactor. * @param reactionIndex The position of the reaction within the reactor. */ - protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { src.pr(CReactionGenerator.generateReaction( reaction, - r, + tpr, reactionIndex, mainDef, errorReporter, @@ -1660,12 +1663,12 @@ public static String variableStructType(Variable variable, Reactor r, boolean us * Construct a unique type for the struct of the specified * instance (port or action). * This is required to be the same as the type name returned by - * {@link #variableStructType(Variable, Reactor, boolean)}. + * {@link #variableStructType(Variable, TypeParameterizedReactor, boolean)}. * @param portOrAction The port or action instance. * @return The name of the self struct. */ public static String variableStructType(TriggerInstance portOrAction) { - return CUtil.getName(portOrAction.getParent().reactorDefinition)+"_"+portOrAction.getName()+"_t"; + return CUtil.getName(portOrAction.getParent().tpr)+"_"+portOrAction.getName()+"_t"; } /** @@ -1694,7 +1697,7 @@ public void generateReactorInstance(ReactorInstance instance) { "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); // Generate the instance self struct containing parameters, state variables, // and outputs (the "self" struct). - initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(reactorClass)+"();"); + initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(instance.tpr)+"();"); // Generate code to initialize the "self" struct in the // _lf_initialize_trigger_objects function. generateTraceTableEntries(instance); diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index 5f8a4d6ad1..470bee8011 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -19,15 +19,15 @@ public class CMethodGenerator { /** * Generate macro definitions for methods. - * @param reactor The reactor. + * @param tpr The reactor. * @param body The place to put the macro definitions. */ public static void generateMacrosForMethods( - Reactor reactor, + TypeParameterizedReactor tpr, CodeBuilder body ) { - for (Method method : allMethods(reactor)) { - var functionName = methodFunctionName(reactor, method); + for (Method method : allMethods(tpr.r())) { + var functionName = methodFunctionName(tpr, method); body.pr("#define "+method.getName()+"(...) "+functionName+"(self, ##__VA_ARGS__)"); } } @@ -51,12 +51,12 @@ public static void generateMacroUndefsForMethods( * This function will have a first argument that is a void* pointing to * the self struct, followed by any arguments given in its definition. * @param method The method. - * @param decl The reactor declaration. + * @param tpr The reactor declaration. * @param types The C-specific type conversion functions. */ public static String generateMethod( Method method, - ReactorDecl decl, + TypeParameterizedReactor tpr, CTypes types ) { var code = new CodeBuilder(); @@ -64,11 +64,11 @@ public static String generateMethod( code.prSourceLineNumber(method); code.prComment("Implementation of method "+method.getName()+"()"); - code.pr(generateMethodSignature(method, decl, types) + " {"); + code.pr(generateMethodSignature(method, tpr, types) + " {"); code.indent(); // Define the "self" struct. - String structType = CUtil.selfType((ReactorInstance) ASTUtils.toDefinition(decl)); + String structType = CUtil.selfType(tpr); // A null structType means there are no inputs, state, // or anything else. No need to declare it. if (structType != null) { @@ -89,21 +89,21 @@ public static String generateMethod( * Generate method functions definition for a reactor. * These functions have a first argument that is a void* pointing to * the self struct. - * @param decl The reactor. + * @param tpr The reactor. * @param code The place to put the code. * @param types The C-specific type conversion functions. */ public static void generateMethods( - ReactorDecl decl, + TypeParameterizedReactor tpr, CodeBuilder code, CTypes types ) { - var reactor = ASTUtils.toDefinition(decl); + var reactor = tpr.r(); code.prComment("***** Start of method declarations."); - signatures(decl, code, types); - generateMacrosForMethods(reactor, code); + signatures(tpr, code, types); + generateMacrosForMethods(tpr, code); for (Method method : allMethods(reactor)) { - code.pr(CMethodGenerator.generateMethod(method, decl, types)); + code.pr(CMethodGenerator.generateMethod(method, tpr, types)); } generateMacroUndefsForMethods(reactor, code); code.prComment("***** End of method declarations."); @@ -114,28 +114,28 @@ public static void generateMethods( * This can be used to declare all the methods with signatures only * before giving the full definition so that methods may call each other * (and themselves) regardless of the order of definition. - * @param decl The reactor declaration. + * @param tpr The reactor declaration. * @param types The C-specific type conversion functions. */ public static void signatures( - ReactorDecl decl, + TypeParameterizedReactor tpr, CodeBuilder body, CTypes types ) { - Reactor reactor = ASTUtils.toDefinition(decl); + Reactor reactor = tpr.r(); for (Method method : allMethods(reactor)) { - body.pr(generateMethodSignature(method, decl, types) + ";"); + body.pr(generateMethodSignature(method, tpr, types) + ";"); } } /** * Return the function name for specified method of the specified reactor. - * @param reactor The reactor + * @param tpr The reactor * @param method The method. * @return The function name for the method. */ - private static String methodFunctionName(ReactorDecl reactor, Method method) { - return CUtil.getName(ASTUtils.toDefinition(reactor)) + "_method_" + method.getName(); + private static String methodFunctionName(TypeParameterizedReactor tpr, Method method) { + return CUtil.getName(tpr) + "_method_" + method.getName(); } /** @@ -143,15 +143,15 @@ private static String methodFunctionName(ReactorDecl reactor, Method method) { * This function will have a first argument that is a void* pointing to * the self struct, followed by any arguments given in its definition. * @param method The method. - * @param decl The reactor declaration. + * @param tpr The reactor declaration. * @param types The C-specific type conversion functions. */ public static String generateMethodSignature( Method method, - ReactorDecl decl, + TypeParameterizedReactor tpr, CTypes types ) { - var functionName = methodFunctionName(decl, method); + var functionName = methodFunctionName(tpr, method); StringBuilder result = new StringBuilder(); if (method.getReturn() != null) { diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 23818cb2ef..3630df136f 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -45,18 +45,18 @@ public class CReactionGenerator { * Generate necessary initialization code inside the body of the reaction that belongs to reactor decl. * @param body The body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER. * @param reaction The initialization code will be generated for this specific reaction - * @param decl The reactor that has the reaction + * @param tpr The reactor that has the reaction * @param reactionIndex The index of the reaction relative to other reactions in the reactor, starting from 0 */ public static String generateInitializationForReaction(String body, Reaction reaction, - Reactor decl, + TypeParameterizedReactor tpr, int reactionIndex, CTypes types, ErrorReporter errorReporter, Instantiation mainDef, boolean requiresTypes) { - Reactor reactor = ASTUtils.toDefinition(decl); + Reactor reactor = tpr.r(); // Construct the reactionInitialization code to go into // the body of the function before the verbatim code. @@ -65,7 +65,7 @@ public static String generateInitializationForReaction(String body, CodeBuilder code = new CodeBuilder(); // Define the "self" struct. - String structType = CUtil.selfType(decl); + String structType = CUtil.selfType(tpr); // A null structType means there are no inputs, state, // or anything else. No need to declare it. if (structType != null) { @@ -113,12 +113,12 @@ public static String generateInitializationForReaction(String body, reactionInitialization, fieldsForStructsForContainedReactors, triggerAsVarRef, - decl, + tpr, types); } else if (triggerAsVarRef.getVariable() instanceof Action) { reactionInitialization.pr(generateActionVariablesInReaction( (Action) triggerAsVarRef.getVariable(), - decl, + tpr, types )); actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); @@ -130,19 +130,19 @@ public static String generateInitializationForReaction(String body, // Declare an argument for every input. // NOTE: this does not include contained outputs. for (Input input : reactor.getInputs()) { - reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); + reactionInitialization.pr(generateInputVariablesInReaction(input, tpr, types)); } } // Define argument for non-triggering inputs. for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { if (src.getVariable() instanceof Port) { - generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); + generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, tpr, types); } else if (src.getVariable() instanceof Action) { // It's a bit odd to read but not be triggered by an action, but // OK, I guess we allow it. reactionInitialization.pr(generateActionVariablesInReaction( (Action) src.getVariable(), - decl, + tpr, types )); actionsAsTriggers.add((Action) src.getVariable()); @@ -160,7 +160,7 @@ public static String generateInitializationForReaction(String body, // It is an action, not an output. // If it has already appeared as trigger, do not redefine it. if (!actionsAsTriggers.contains(effect.getVariable())) { - reactionInitialization.pr(CGenerator.variableStructType(variable, decl, false)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); + reactionInitialization.pr(CGenerator.variableStructType(variable, tpr, false)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); } } else if (effect.getVariable() instanceof Mode) { // Mode change effect @@ -184,7 +184,7 @@ public static String generateInitializationForReaction(String body, if (variable instanceof Output) { reactionInitialization.pr(generateOutputVariablesInReaction( effect, - decl, + tpr, errorReporter, requiresTypes )); @@ -414,15 +414,15 @@ private static void generatePortVariablesInReaction( CodeBuilder builder, Map structs, VarRef port, - Reactor r, + TypeParameterizedReactor tpr, CTypes types ) { if (port.getVariable() instanceof Input) { - builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), r, types)); + builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), tpr, types)); } else { // port is an output of a contained reactor. Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, ASTUtils.toDefinition(port.getContainer().getReactorClass()), false); + String portStructType = CGenerator.variableStructType(output, tpr, false); CodeBuilder structBuilder = structs.get(port.getContainer()); if (structBuilder == null) { @@ -476,10 +476,10 @@ private static void generatePortVariablesInReaction( */ private static String generateActionVariablesInReaction( Action action, - Reactor r, + TypeParameterizedReactor tpr, CTypes types ) { - String structType = CGenerator.variableStructType(action, r, false); + String structType = CGenerator.variableStructType(action, tpr, false); // If the action has a type, create variables for accessing the value. InferredType type = ASTUtils.getInferredType(action); // Pointer to the lf_token_t sent as the payload in the trigger. @@ -516,14 +516,14 @@ private static String generateActionVariablesInReaction( * initialize local variables for the specified input port * in a reaction function from the "self" struct. * @param input The input statement from the AST. - * @param r The reactor. + * @param tpr The reactor. */ private static String generateInputVariablesInReaction( Input input, - Reactor r, + TypeParameterizedReactor tpr, CTypes types ) { - String structType = CGenerator.variableStructType(input, r, false); + String structType = CGenerator.variableStructType(input, tpr, false); InferredType inputType = ASTUtils.getInferredType(input); CodeBuilder builder = new CodeBuilder(); String inputName = input.getName(); @@ -624,11 +624,11 @@ private static String generateInputVariablesInReaction( * initialize local variables for outputs in a reaction function * from the "self" struct. * @param effect The effect declared by the reaction. This must refer to an output. - * @param r The reactor containing the reaction. + * @param tpr The reactor containing the reaction. */ public static String generateOutputVariablesInReaction( VarRef effect, - Reactor r, + TypeParameterizedReactor tpr, ErrorReporter errorReporter, boolean requiresTypes ) { @@ -642,7 +642,7 @@ public static String generateOutputVariablesInReaction( // The container of the output may be a contained reactor or // the reactor containing the reaction. String outputStructType = (effect.getContainer() == null) ? - CGenerator.variableStructType(output, r, false) + CGenerator.variableStructType(output, tpr, false) : CGenerator.variableStructType(output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); if (!ASTUtils.isMultiport(output)) { @@ -671,6 +671,7 @@ public static String generateOutputVariablesInReaction( */ public static void generateReactionAndTriggerStructs( CodeBuilder body, + TypeParameterizedReactor tpr, Reactor reactor, CodeBuilder constructorCode, CTypes types @@ -688,7 +689,7 @@ public static void generateReactionAndTriggerStructs( var startupReactions = new LinkedHashSet(); var shutdownReactions = new LinkedHashSet(); var resetReactions = new LinkedHashSet(); - for (Reaction reaction : ASTUtils.allReactions(reactor)) { + for (Reaction reaction : ASTUtils.allReactions(tpr.r())) { // Create the reaction_t struct. body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); @@ -731,7 +732,7 @@ public static void generateReactionAndTriggerStructs( var deadlineFunctionPointer = "NULL"; if (reaction.getDeadline() != null) { // The following has to match the name chosen in generateReactions - var deadlineFunctionName = generateDeadlineFunctionName(reactor, reactionCount); + var deadlineFunctionName = generateDeadlineFunctionName(tpr, reactionCount); deadlineFunctionPointer = "&" + deadlineFunctionName; } @@ -739,7 +740,7 @@ public static void generateReactionAndTriggerStructs( var STPFunctionPointer = "NULL"; if (reaction.getStp() != null) { // The following has to match the name chosen in generateReactions - var STPFunctionName = generateStpFunctionName(reactor, reactionCount); + var STPFunctionName = generateStpFunctionName(tpr, reactionCount); STPFunctionPointer = "&" + STPFunctionName; } @@ -753,7 +754,7 @@ public static void generateReactionAndTriggerStructs( // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; constructorCode.pr(reaction, String.join("\n", "self->_lf__reaction_"+reactionCount+".number = "+reactionCount+";", - "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(reactor, reactionCount)+";", + "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(tpr, reactionCount)+";", "self->_lf__reaction_"+reactionCount+".self = self;", "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", @@ -1031,12 +1032,12 @@ public static String generateLfModeTriggeredReactions( * a struct that contains parameters, state variables, inputs (triggering or not), * actions (triggering or produced), and outputs. * @param reaction The reaction. - * @param r The reactor. + * @param tpr The reactor. * @param reactionIndex The position of the reaction within the reactor. */ public static String generateReaction( Reaction reaction, - Reactor r, + TypeParameterizedReactor tpr, int reactionIndex, Instantiation mainDef, ErrorReporter errorReporter, @@ -1045,9 +1046,9 @@ public static String generateReaction( boolean requiresType ) { var code = new CodeBuilder(); - var body = ASTUtils.toText(getCode(types, reaction, r)); + var body = ASTUtils.toText(getCode(types, reaction, tpr)); String init = generateInitializationForReaction( - body, reaction, ASTUtils.toDefinition(r), reactionIndex, + body, reaction, tpr, reactionIndex, types, errorReporter, mainDef, requiresType); @@ -1055,37 +1056,37 @@ public static String generateReaction( "#include " + StringUtil.addDoubleQuotes( CCoreFilesUtils.getCTargetSetHeader())); - CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(r), code); + CMethodGenerator.generateMacrosForMethods(tpr, code); code.pr(generateFunction( - generateReactionFunctionHeader(r, reactionIndex), - init, getCode(types, reaction, r) + generateReactionFunctionHeader(tpr, reactionIndex), + init, getCode(types, reaction, tpr) )); // Now generate code for the late function, if there is one // Note that this function can only be defined on reactions // in federates that have inputs from a logical connection. if (reaction.getStp() != null) { code.pr(generateFunction( - generateStpFunctionHeader(r, reactionIndex), + generateStpFunctionHeader(tpr, reactionIndex), init, reaction.getStp().getCode())); } // Now generate code for the deadline violation function, if there is one. if (reaction.getDeadline() != null) { code.pr(generateFunction( - generateDeadlineFunctionHeader(r, reactionIndex), + generateDeadlineFunctionHeader(tpr, reactionIndex), init, reaction.getDeadline().getCode())); } - CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(r), code); + CMethodGenerator.generateMacroUndefsForMethods(tpr.r(), code); code.pr( "#include " + StringUtil.addDoubleQuotes( CCoreFilesUtils.getCTargetSetUndefHeader())); return code.toString(); } - private static Code getCode(CTypes types, Reaction r, ReactorDecl container) { + private static Code getCode(CTypes types, Reaction r, TypeParameterizedReactor tpr) { if (r.getCode() != null) return r.getCode(); Code ret = LfFactory.eINSTANCE.createCode(); - ret.setBody(r.getName() + "( " + CReactorHeaderFileGenerator.reactionArguments(types, r, ASTUtils.toDefinition(container)) + " );"); + ret.setBody(r.getName() + "( " + CReactorHeaderFileGenerator.reactionArguments(types, r, tpr) + " );"); return ret; } @@ -1103,58 +1104,58 @@ public static String generateFunction(String header, String init, Code code) { /** * Returns the name of the deadline function for reaction. - * @param r The reactor with the deadline + * @param tpr The reactor with the deadline * @param reactionIndex The number assigned to this reaction deadline */ - public static String generateDeadlineFunctionName(Reactor r, int reactionIndex) { - return CUtil.getName(r).toLowerCase() + "_deadline_function" + reactionIndex; + public static String generateDeadlineFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { + return CUtil.getName(tpr).toLowerCase() + "_deadline_function" + reactionIndex; } /** * Return the function name for specified reaction of the * specified reactor. - * @param reactor The reactor + * @param tpr The reactor * @param reactionIndex The reaction index. * @return The function name for the reaction. */ - public static String generateReactionFunctionName(Reactor reactor, int reactionIndex) { - return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; + public static String generateReactionFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { + return CUtil.getName(tpr).toLowerCase() + "reaction_function_" + reactionIndex; } /** * Returns the name of the stp function for reaction. - * @param r The reactor with the stp + * @param tpr The reactor with the stp * @param reactionIndex The number assigned to this reaction deadline */ - public static String generateStpFunctionName(Reactor r, int reactionIndex) { - return CUtil.getName(r).toLowerCase() + "_STP_function" + reactionIndex; + public static String generateStpFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { + return CUtil.getName(tpr).toLowerCase() + "_STP_function" + reactionIndex; } /** Return the top level C function header for the deadline function numbered "reactionIndex" in "r" - * @param r The reactor declaration + * @param tpr The reactor declaration * @param reactionIndex The reaction index. * @return The function name for the deadline function. */ - public static String generateDeadlineFunctionHeader(Reactor r, + public static String generateDeadlineFunctionHeader(TypeParameterizedReactor tpr, int reactionIndex) { - String functionName = generateDeadlineFunctionName(r, reactionIndex); + String functionName = generateDeadlineFunctionName(tpr, reactionIndex); return generateFunctionHeader(functionName); } /** Return the top level C function header for the reaction numbered "reactionIndex" in "r" - * @param r The reactor declaration + * @param tpr The reactor declaration * @param reactionIndex The reaction index. * @return The function name for the reaction. */ - public static String generateReactionFunctionHeader(Reactor r, + public static String generateReactionFunctionHeader(TypeParameterizedReactor tpr, int reactionIndex) { - String functionName = generateReactionFunctionName(r, reactionIndex); + String functionName = generateReactionFunctionName(tpr, reactionIndex); return generateFunctionHeader(functionName); } - public static String generateStpFunctionHeader(Reactor r, + public static String generateStpFunctionHeader(TypeParameterizedReactor tpr, int reactionIndex) { - String functionName = generateStpFunctionName(r, reactionIndex); + String functionName = generateStpFunctionName(tpr, reactionIndex); return generateFunctionHeader(functionName); } diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 92318c0150..041baab112 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -43,10 +43,10 @@ private static String generateHeaderFile(CTypes types, TypeParameterizedReactor appendIncludeGuard(builder, tpr.r()); builder.pr(topLevelPreamble); appendPoundIncludes(builder); - appendSelfStruct(builder, types, tpr.r()); + appendSelfStruct(builder, types, tpr); generator.generate(builder, tpr, true); for (Reaction reaction : tpr.r().getReactions()) { - appendSignature(builder, types, reaction, tpr.r()); + appendSignature(builder, types, reaction, tpr); } builder.pr("#endif"); return builder.getCode(); @@ -71,40 +71,40 @@ private static void appendPoundIncludes(CodeBuilder builder) { """); } - private static String userFacingSelfType(Reactor r) { - return r.getName().toLowerCase() + "_self_t"; + private static String userFacingSelfType(TypeParameterizedReactor tpr) { + return tpr.getName().toLowerCase() + "_self_t"; } - private static void appendSelfStruct(CodeBuilder builder, CTypes types, Reactor r) { - builder.pr("typedef struct " + userFacingSelfType(r) + "{"); - for (Parameter p : r.getParameters()) { + private static void appendSelfStruct(CodeBuilder builder, CTypes types, TypeParameterizedReactor tpr) { + builder.pr("typedef struct " + userFacingSelfType(tpr) + "{"); + for (Parameter p : tpr.r().getParameters()) { builder.pr(types.getTargetType(p) + " " + p.getName() + ";"); } - for (StateVar s : r.getStateVars()) { + for (StateVar s : tpr.r().getStateVars()) { builder.pr(types.getTargetType(s) + " " + s.getName() + ";"); } builder.pr("int end[0]; // placeholder; MSVC does not compile empty structs"); - builder.pr("} " + userFacingSelfType(r) + ";"); + builder.pr("} " + userFacingSelfType(tpr) + ";"); } - private static void appendSignature(CodeBuilder builder, CTypes types, Reaction r, Reactor reactor) { - if (r.getName() != null) builder.pr("void " + r.getName() + "(" + reactionParameters(types, r, reactor) + ");"); + private static void appendSignature(CodeBuilder builder, CTypes types, Reaction r, TypeParameterizedReactor tpr) { + if (r.getName() != null) builder.pr("void " + r.getName() + "(" + reactionParameters(types, r, tpr) + ");"); } - private static String reactionParameters(CTypes types, Reaction r, Reactor reactor) { - return Stream.concat(Stream.of(userFacingSelfType(reactor) + "* self"), ioTypedVariableStream(r) - .map((tv) -> reactor.getName().toLowerCase() + "_" + tv.getName() + "_t* " + tv.getName())) + private static String reactionParameters(CTypes types, Reaction r, TypeParameterizedReactor tpr) { + return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), ioTypedVariableStream(r) + .map((tv) -> tpr.getName().toLowerCase() + "_" + tv.getName() + "_t* " + tv.getName())) .collect(Collectors.joining(", ")); } - public static String reactionArguments(CTypes types, Reaction r, Reactor reactor) { - return Stream.concat(Stream.of(getApiSelfStruct(reactor)), ioTypedVariableStream(r) - .map(it -> String.format("((%s*) %s)", CGenerator.variableStructType(it, reactor, true), it.getName()))) + public static String reactionArguments(CTypes types, Reaction r, TypeParameterizedReactor tpr) { + return Stream.concat(Stream.of(getApiSelfStruct(tpr)), ioTypedVariableStream(r) + .map(it -> String.format("((%s*) %s)", CGenerator.variableStructType(it, tpr, true), it.getName()))) .collect(Collectors.joining(", ")); } - private static String getApiSelfStruct(Reactor reactor) { - return "(" + userFacingSelfType(reactor) + "*) (((char*) self) + sizeof(self_base_t))"; + private static String getApiSelfStruct(TypeParameterizedReactor tpr) { + return "(" + userFacingSelfType(tpr) + "*) (((char*) self) + sizeof(self_base_t))"; } private static Stream ioTypedVariableStream(Reaction r) { diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 15097b6205..418c87157b 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -529,12 +529,6 @@ public static String selfType(TypeParameterizedReactor reactor) { } return "_" + CUtil.getName(reactor) + "_self_t"; } - public static String selfType(Reactor reactor) { - if (reactor.isMain()) { - return "_" + CUtil.getName(reactor) + "_main_self_t"; - } - return "_" + CUtil.getName(reactor) + "_self_t"; - } /** Construct a unique type for the "self" struct of the class of the given reactor. */ public static String selfType(ReactorInstance instance) { diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 6a1a6ecd1d..e0ef28c192 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -352,28 +352,28 @@ public void processProtoFile(String filename) { /** * Generate the aliases for inputs, outputs, and struct type definitions for * actions of the specified reactor in the specified federate. - * @param r The parsed reactor data structure. + * @param tpr The parsed reactor data structure. */ @Override public void generateAuxiliaryStructs( CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing ) { for (Input input : ASTUtils.allInputs(tpr.r())) { - generateAuxiliaryStructsForPort(builder, tpr.r(), input); + generateAuxiliaryStructsForPort(builder, tpr, input); } for (Output output : ASTUtils.allOutputs(tpr.r())) { - generateAuxiliaryStructsForPort(builder, tpr.r(), output); + generateAuxiliaryStructsForPort(builder, tpr, output); } for (Action action : ASTUtils.allActions(tpr.r())) { generateAuxiliaryStructsForAction(builder, tpr, action); } } - private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, + private void generateAuxiliaryStructsForPort(CodeBuilder builder, TypeParameterizedReactor tpr, Port port) { boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); builder.pr(port, - PythonPortGenerator.generateAliasTypeDef(r, port, isTokenType, + PythonPortGenerator.generateAliasTypeDef(tpr, port, isTokenType, genericPortType)); } @@ -455,19 +455,19 @@ protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { * a struct that contains parameters, state variables, inputs (triggering or not), * actions (triggering or produced), and outputs. * @param reaction The reaction. - * @param r The reactor. + * @param tpr The reactor. * @param reactionIndex The position of the reaction within the reactor. */ @Override - protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { - Reactor reactor = ASTUtils.toDefinition(r); + protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { + Reactor reactor = ASTUtils.toDefinition(tpr.r()); // Reactions marked with a `@_c_body` attribute are generated in C if (AttributeUtils.hasCBody(reaction)) { - super.generateReaction(src, reaction, r, reactionIndex); + super.generateReaction(src, reaction, tpr, reactionIndex); return; } - src.pr(PythonReactionGenerator.generateCReaction(reaction, reactor, reactionIndex, mainDef, errorReporter, types)); + src.pr(PythonReactionGenerator.generateCReaction(reaction, tpr, reactor, reactionIndex, mainDef, errorReporter, types)); } /** @@ -504,7 +504,7 @@ protected void generateParameterInitialization(ReactorInstance instance) { * @see PythonMethodGenerator */ @Override - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { } + protected void generateMethods(CodeBuilder src, TypeParameterizedReactor reactor) { } /** * Generate C preambles defined by user for a given reactor @@ -540,7 +540,7 @@ protected void generateReactorInstanceExtension( /** * This function is provided to allow extensions of the CGenerator to append the structure of the self struct * @param selfStructBody The body of the self struct - * @param decl The reactor declaration for the self struct + * @param reactor The reactor declaration for the self struct * @param constructorCode Code that is executed when the reactor is instantiated */ @Override diff --git a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java index 9e0919b52c..a5308798d6 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java @@ -1,5 +1,6 @@ package org.lflang.generator.python; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; @@ -195,8 +196,8 @@ public static String generatePythonListForContainedBank(String reactorName, Port ); } - public static String generateAliasTypeDef(Reactor r, Port port, boolean isTokenType, String genericPortType) { - return "typedef "+genericPortType+" "+CGenerator.variableStructType(port, r, false)+";"; + public static String generateAliasTypeDef(TypeParameterizedReactor tpr, Port port, boolean isTokenType, String genericPortType) { + return "typedef "+genericPortType+" "+CGenerator.variableStructType(port, tpr, false)+";"; } private static String generateConvertCPortToPy(String port) { diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index bcc1beeaed..62dd65ff5f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -12,6 +12,7 @@ import org.lflang.Target; import org.lflang.generator.c.CReactionGenerator; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; @@ -127,6 +128,7 @@ private static String generateCPythonFunctionCaller(String reactorDeclName, */ public static String generateCReaction( Reaction reaction, + TypeParameterizedReactor tpr, Reactor r, int reactionIndex, Instantiation mainDef, @@ -139,14 +141,14 @@ public static String generateCReaction( CodeBuilder code = new CodeBuilder(); String cPyInit = generateCPythonInitializers(reaction, r, pyObjects, errorReporter); String cInit = CReactionGenerator.generateInitializationForReaction( - "", reaction, r, reactionIndex, + "", reaction, tpr, reactionIndex, types, errorReporter, mainDef, Target.Python.requiresTypes); code.pr( "#include " + StringUtil.addDoubleQuotes( CCoreFilesUtils.getCTargetSetHeader())); code.pr(generateFunction( - CReactionGenerator.generateReactionFunctionHeader(r, reactionIndex), + CReactionGenerator.generateReactionFunctionHeader(tpr, reactionIndex), cInit, reaction.getCode(), generateCPythonReactionCaller(r, reactionIndex, pyObjects, cPyInit) )); @@ -154,7 +156,7 @@ public static String generateCReaction( // Generate code for the STP violation handler, if there is one. if (reaction.getStp() != null) { code.pr(generateFunction( - CReactionGenerator.generateStpFunctionHeader(r, reactionIndex), + CReactionGenerator.generateStpFunctionHeader(tpr, reactionIndex), cInit, reaction.getStp().getCode(), generateCPythonSTPCaller(r, reactionIndex, pyObjects) )); @@ -162,7 +164,7 @@ public static String generateCReaction( // Generate code for the deadline violation function, if there is one. if (reaction.getDeadline() != null) { code.pr(generateFunction( - CReactionGenerator.generateDeadlineFunctionHeader(r, reactionIndex), + CReactionGenerator.generateDeadlineFunctionHeader(tpr, reactionIndex), cInit, reaction.getDeadline().getCode(), generateCPythonDeadlineCaller(r, reactionIndex, pyObjects) )); diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java index fd954ca956..e95e9766bd 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java @@ -34,7 +34,7 @@ public static String generatePythonClass(ReactorInstance instance, CodeBuilder pythonClasses = new CodeBuilder(); ReactorDecl decl = instance.getDefinition().getReactorClass(); Reactor reactor = ASTUtils.toDefinition(decl); - String className = PyUtil.getName(reactor); + String className = PyUtil.getName(instance.tpr); if (instantiatedClasses == null) { return ""; } @@ -113,7 +113,7 @@ public static String generatePythonClassInstantiations(ReactorInstance instance, ReactorInstance main) { CodeBuilder code = new CodeBuilder(); - String className = PyUtil.getName(instance.reactorDefinition); + String className = PyUtil.getName(instance.tpr); if (instance.getWidth() > 0) { // For each reactor instance, create a list regardless of whether it is a bank or not. diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 394250d22c..7af840de3d 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -239,9 +239,9 @@ public void checkConnection(Connection connection) { } else { // Unfortunately, xtext does not generate a suitable equals() // method for AST types, so we have to manually check the types. - if (!sameType(type, ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); - } +// if (!sameType(type, ((Port) port.getVariable()).getType())) { +// error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); +// } } } } @@ -252,9 +252,9 @@ public void checkConnection(Connection connection) { if (type == null) { type = ((Port) port.getVariable()).getType(); } else { - if (!sameType(type, type = ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); - } +// if (!sameType(type, type = ((Port) port.getVariable()).getType())) { +// error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); +// } } } } From 4af90402d6fee68c42828edf1fb086452f2167c1 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Thu, 30 Mar 2023 17:03:09 +0500 Subject: [PATCH 091/709] [C-Generics] Working Generic Code Basic implementation for Generic Reactors in C-Target are done We can run the following Generic Code for demonstration of this feature. ``` target C { keepalive: true, cmake-include: [ "../lib/lib.cmake" ], files: [ "../lib/convertor.h", "../lib/convertor.c" ] } preamble {= =} reactor Connector(latency:int(0)) { input in:I; output out:O; logical action delayed_sch; reaction(in) -> delayed_sch {= lf_schedule(delayed_sch, self->latency); =} reaction(delayed_sch) in -> out {= if (is_same_type(in->value, out->value)) { lf_set(out, in->value); } else { auto_t tmp = CALL_CONVERTOR(I, O, in->value); lf_set(out, tmp); } =} } reactor A { output Aout:int; logical action post; timer t(0, 1sec); reaction(t) -> post {= lf_schedule(post, 2); =} reaction(post) -> Aout {= lf_set(Aout, rand()); =} } reactor B { input Bin:float; reaction(Bin) {= printf("got %f\n", Bin->value); =} } main reactor { a = new A(); w = new Connector(latency=500); b = new B(); a.Aout -> w.in; w.out -> b.Bin; } ``` Complete Working example can be fetched from: https://github.com/MagnitionIO/LF_Collaboration/blob/main/CGenericsProposal/src/CGenerics.lf Signed-off-by: mkhubaibumer --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/org/lflang/generator/c/CCoreFilesUtils.java | 3 ++- org.lflang/src/org/lflang/generator/c/CGenerator.java | 8 +++++--- .../lflang/generator/c/CReactorHeaderFileGenerator.java | 9 +++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index d43e973780..f9dd92f15b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit d43e9737804f2d984d52a99cac20d8e57adad543 +Subproject commit f9dd92f15b89ee57545b983bed45362a53a3375b diff --git a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java index 46503d87cc..6022110943 100644 --- a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java +++ b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java @@ -18,7 +18,8 @@ public static List getCTargetSrc() { public static List getCTargetHeader() { return List.of( - "include/api/api.h" + "include/api/api.h", + "include/api/generics.h" ); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b9fc9e57dc..bb0944d389 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1048,18 +1048,20 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("extern \"C\" {"); header.pr("extern \"C\" {"); } - tpr.typeArgs().entrySet().forEach(it -> header.pr("#define " + it.getKey() + " " + ASTUtils.toText(it.getValue()))); + tpr.typeArgs().forEach((literal, concreteType) -> header.pr( + "#define " + literal + " " + ASTUtils.toText(concreteType))); header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); + src.pr("#include \"include/api/generics.h\""); generateIncludes(tpr); if (CCppMode) { src.pr("}"); header.pr("}"); } - src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(fileConfig, tpr.r()) + "\""); src.pr("#include \"" + headerName + "\""); - tpr.typeArgs().entrySet().forEach(it -> src.pr("#define " + it.getKey() + " " + ASTUtils.toText(it.getValue()))); + tpr.typeArgs().forEach((literal, concreteType) -> src.pr( + "#define " + literal + " " + ASTUtils.toText(concreteType))); new HashSet<>(ASTUtils.allInstantiations(tpr.r())).stream() .map(TypeParameterizedReactor::new).map(CUtil::getName) .map(name -> "#include \"" + name + ".h\"") diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 041baab112..9c820cd87c 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -28,15 +28,15 @@ public interface GenerateAuxiliaryStructs { void generate(CodeBuilder b, TypeParameterizedReactor r, boolean userFacing); } - public static Path outputPath(CFileConfig fileConfig, Reactor r) { - return Path.of(Path.of(r.eResource().getURI().toFileString()) + public static Path outputPath(CFileConfig fileConfig, TypeParameterizedReactor tpr) { + return Path.of(Path.of(tpr.r().eResource().getURI().toFileString()) .getFileName().toString().replaceFirst("[.][^.]+$", "")) - .resolve(r.getName() + ".h"); + .resolve(tpr.getName() + ".h"); } public static void doGenerate(CTypes types, TypeParameterizedReactor tpr, CFileConfig fileConfig, GenerateAuxiliaryStructs generator, Function topLevelPreamble) throws IOException { String contents = generateHeaderFile(types, tpr, generator, topLevelPreamble.apply(tpr.r())); - FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(fileConfig, tpr.r()))); + FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(fileConfig, tpr))); } private static String generateHeaderFile(CTypes types, TypeParameterizedReactor tpr, GenerateAuxiliaryStructs generator, String topLevelPreamble) { CodeBuilder builder = new CodeBuilder(); @@ -64,6 +64,7 @@ private static void appendPoundIncludes(CodeBuilder builder) { #endif #include "../include/api/api.h" #include "../include/api/set.h" + #include "../include/api/generics.h" #include "../include/core/reactor.h" #ifdef __cplusplus } From 60cf911610a09cbbb07a706212b22808b0c5e07d Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 30 Mar 2023 19:15:40 -0700 Subject: [PATCH 092/709] merged changes, fixed inconsistencies, implemented watchdog stop --- org.lflang/src/lib/c/reactor-c | 2 +- .../platform/arduino/Arduino-CMake-Toolchain | 1 + test/C/src/Watchdog.lf | 6 ++- test/C/src/file0.lf | 40 +++++++++++++++++++ test/C/src/file1.lf | 40 +++++++++++++++++++ test/C/src/file2.lf | 40 +++++++++++++++++++ 6 files changed, 126 insertions(+), 3 deletions(-) create mode 160000 org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain create mode 100644 test/C/src/file0.lf create mode 100644 test/C/src/file1.lf create mode 100644 test/C/src/file2.lf diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 10c275b99a..ff3c84c36b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 10c275b99a01802f00168b92d4e9068fdf9b34b6 +Subproject commit ff3c84c36b2d7fbcbe09fafa577ec94f75194e83 diff --git a/org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain b/org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain new file mode 160000 index 0000000000..e745a9bed3 --- /dev/null +++ b/org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain @@ -0,0 +1 @@ +Subproject commit e745a9bed3c3fb83442d55bf05630f31574674f2 diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index e3d7f6cb41..4827637f07 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -1,4 +1,6 @@ -target C +target C { + workers: 100 +}; reactor Watcher { input x: int @@ -6,7 +8,7 @@ reactor Watcher { watchdog poodle(10 msec) {= instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); - printf("Deadline missed! Lag: %lld (too late by %lld nsecs)\n", p, p-500000); + printf("Watchdog missed! Lag: %lld (too late by %lld nsecs)\n", p, p-500000); =} reaction(x) -> poodle, d {= diff --git a/test/C/src/file0.lf b/test/C/src/file0.lf new file mode 100644 index 0000000000..645242845a --- /dev/null +++ b/test/C/src/file0.lf @@ -0,0 +1,40 @@ +target C + +reactor Watcher { + input x: int + // Produced if the + // deadline is + // violated. + output d: int + + reaction(x) -> + d, poodle {= + lf_watchdog_start(poodle, 0); + printf("Normal reaction.\n"); + =} +} + +main reactor { + logical action a + w = new Watcher( + + ) + + reaction( + startup + ) -> + w.x, a {= + lf_set(w.x, 0); + lf_schedule(a, 0); + =} + + reaction(a) -> + w.x {= + lf_set(w.x, 0); + lf_nanosleep(MSEC(40)); + =} + + reaction(w.d) {= + printf("Deadline reactor produced an output.\n"); + =} +} diff --git a/test/C/src/file1.lf b/test/C/src/file1.lf new file mode 100644 index 0000000000..1183364928 --- /dev/null +++ b/test/C/src/file1.lf @@ -0,0 +1,40 @@ +target C + +reactor Watcher { + input x: int + // Produced if the + // deadline is + // violated. + output d: int + + reaction(x) -> + poodle, d {= + lf_watchdog_start(poodle, 0); + printf("Normal reaction.\n"); + =} +} + +main reactor { + logical action a + w = new Watcher( + + ) + + reaction( + startup + ) -> + w.x, a {= + lf_set(w.x, 0); + lf_schedule(a, 0); + =} + + reaction(a) -> + w.x {= + lf_set(w.x, 0); + lf_nanosleep(MSEC(40)); + =} + + reaction(w.d) {= + printf("Deadline reactor produced an output.\n"); + =} +} diff --git a/test/C/src/file2.lf b/test/C/src/file2.lf new file mode 100644 index 0000000000..1183364928 --- /dev/null +++ b/test/C/src/file2.lf @@ -0,0 +1,40 @@ +target C + +reactor Watcher { + input x: int + // Produced if the + // deadline is + // violated. + output d: int + + reaction(x) -> + poodle, d {= + lf_watchdog_start(poodle, 0); + printf("Normal reaction.\n"); + =} +} + +main reactor { + logical action a + w = new Watcher( + + ) + + reaction( + startup + ) -> + w.x, a {= + lf_set(w.x, 0); + lf_schedule(a, 0); + =} + + reaction(a) -> + w.x {= + lf_set(w.x, 0); + lf_nanosleep(MSEC(40)); + =} + + reaction(w.d) {= + printf("Deadline reactor produced an output.\n"); + =} +} From 7fb877be88cf5709758756b4ca1351ec9bace6ef Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 30 Mar 2023 21:04:33 -0700 Subject: [PATCH 093/709] threading error working --- org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain | 1 - org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- test/C/src/Watchdog.lf | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) delete mode 160000 org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain diff --git a/org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain b/org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain deleted file mode 160000 index e745a9bed3..0000000000 --- a/org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e745a9bed3c3fb83442d55bf05630f31574674f2 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e7ce2439f8..2ef5074455 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -473,7 +473,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { super.doGenerate(resource, context); if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; if (!isOSCompatible()) return; // Incompatible OS and configuration - // if (!isWatchdogCompatible()) return; + if (!isWatchdogCompatible()) return; // Perform set up that does not generate code setUpGeneralParameters(); diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index 4827637f07..488ae42acd 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -1,6 +1,6 @@ target C { workers: 100 -}; +} reactor Watcher { input x: int From 8b3b3e3e8ed7e765f2573012ddba1b4c9b5ac60e Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 30 Mar 2023 22:10:38 -0700 Subject: [PATCH 094/709] saving before pull again --- .../tests/compiler/FormattingUnitTests.java | 33 +- .../tests/compiler/LetInferenceTests.java | 2 +- .../compiler/LinguaFrancaValidationTest.java | 2234 ++++++----------- .../lflang/tests/compiler/RoundTripTests.java | 9 +- org.lflang/src/org/lflang/ASTUtils.java | 8 + org.lflang/src/org/lflang/LinguaFranca.xtext | 19 +- org.lflang/src/org/lflang/Target.java | 18 +- org.lflang/src/org/lflang/ast/IsEqual.java | 12 +- org.lflang/src/org/lflang/ast/ToLf.java | 60 +- org.lflang/src/org/lflang/ast/ToText.java | 6 + org.lflang/src/org/lflang/cli/Lff.java | 32 +- .../synthesis/LinguaFrancaSynthesis.java | 11 +- .../federated/extensions/CExtension.java | 13 +- .../federated/extensions/CExtensionUtils.java | 18 +- .../federated/extensions/TSExtension.java | 5 +- .../federated/generator/FederateInstance.java | 6 +- .../src/org/lflang/generator/CodeMap.java | 15 +- .../org/lflang/generator/GeneratorBase.java | 77 - .../org/lflang/generator/GeneratorUtils.java | 2 +- .../lflang/generator/LfExpressionVisitor.java | 160 ++ .../lflang/generator/ParameterInstance.java | 29 +- .../org/lflang/generator/ReactorInstance.java | 81 +- .../src/org/lflang/generator/TargetTypes.java | 14 +- .../lflang/generator/c/CActionGenerator.java | 7 +- .../org/lflang/generator/c/CGenerator.java | 6 +- .../generator/c/CParameterGenerator.java | 50 +- .../lflang/generator/c/CStateGenerator.java | 15 +- .../lflang/generator/c/CTimerGenerator.java | 6 +- .../src/org/lflang/generator/c/CTypes.java | 72 +- .../generator/cpp/CppParameterGenerator.kt | 20 +- .../generator/cpp/CppReactorGenerator.kt | 9 +- .../lflang/generator/cpp/CppStateGenerator.kt | 2 +- .../src/org/lflang/generator/cpp/CppTypes.kt | 21 +- .../org/lflang/generator/python/PyUtil.java | 22 +- .../generator/python/PythonGenerator.java | 2 +- .../python/PythonParameterGenerator.java | 47 +- .../lflang/generator/python/PythonTypes.java | 58 +- .../generator/ts/TSConstructorGenerator.kt | 2 +- .../generator/ts/TSDelayBodyGenerator.kt | 2 +- .../generator/ts/TSDockerGenerator.java | 29 + .../lflang/generator/ts/TSDockerGenerator.kt | 26 - .../org/lflang/generator/ts/TSExtensions.kt | 8 +- .../org/lflang/generator/ts/TSGenerator.kt | 2 +- .../generator/ts/TSInstanceGenerator.kt | 6 +- .../generator/ts/TSParameterGenerator.kt | 2 +- .../ts/TSParameterPreambleGenerator.kt | 4 +- .../generator/ts/TSReactionGenerator.kt | 4 +- .../lflang/generator/ts/TSStateGenerator.kt | 4 +- .../src/org/lflang/generator/ts/TSTypes.java | 75 + .../src/org/lflang/generator/ts/TSTypes.kt | 57 - .../org/lflang/validation/LFValidator.java | 34 +- test/C/src/ActionDelay.lf | 2 +- test/C/src/ActionIsPresent.lf | 4 +- test/C/src/After.lf | 4 +- test/C/src/AfterCycles.lf | 2 +- test/C/src/AfterOverlapped.lf | 4 +- test/C/src/AfterZero.lf | 4 +- test/C/src/Alignment.lf | 8 +- test/C/src/ArrayAsParameter.lf | 10 +- test/C/src/ArrayAsType.lf | 2 +- test/C/src/ArrayFree.lf | 2 +- test/C/src/ArrayFreeMultiple.lf | 4 +- test/C/src/ArrayPrint.lf | 8 +- test/C/src/ArrayScale.lf | 2 +- test/C/src/CharLiteralInitializer.lf | 2 +- test/C/src/Composition.lf | 6 +- test/C/src/CompositionAfter.lf | 8 +- test/C/src/CompositionInheritance.lf | 6 +- test/C/src/CountSelf.lf | 2 +- test/C/src/Deadline.lf | 8 +- test/C/src/DeadlineHandledAbove.lf | 4 +- test/C/src/DeadlineWithBanks.lf | 4 +- test/C/src/DeadlineZero.lf | 2 +- test/C/src/DelayArray.lf | 4 +- test/C/src/DelayArrayWithAfter.lf | 8 +- test/C/src/DelayInt.lf | 6 +- test/C/src/DelayPointer.lf | 6 +- test/C/src/DelayString.lf | 4 +- test/C/src/DelayStruct.lf | 4 +- test/C/src/DelayStructWithAfter.lf | 2 +- test/C/src/DelayStructWithAfterOverlapped.lf | 4 +- test/C/src/DelayedAction.lf | 2 +- test/C/src/DoubleInvocation.lf | 4 +- test/C/src/DoublePort.lf | 2 +- test/C/src/DoubleReaction.lf | 6 +- test/C/src/DoubleTrigger.lf | 2 +- test/C/src/FloatLiteral.lf | 8 +- test/C/src/Gain.lf | 4 +- test/C/src/GetMicroStep.lf | 2 +- test/C/src/Hello.lf | 10 +- test/C/src/HelloWorld.lf | 2 +- test/C/src/Hierarchy2.lf | 4 +- test/C/src/IdentifierLength.lf | 6 +- test/C/src/ImportComposition.lf | 2 +- test/C/src/InheritanceAction.lf | 2 +- test/C/src/ManualDelayedReaction.lf | 2 +- test/C/src/Methods.lf | 2 +- test/C/src/MethodsRecursive.lf | 2 +- test/C/src/MethodsSameName.lf | 4 +- test/C/src/MovingAverage.lf | 8 +- test/C/src/MultipleContained.lf | 2 +- test/C/src/MultipleOutputs.lf | 2 +- test/C/src/NativeListsAndTimes.lf | 22 +- test/C/src/NestedTriggeredReactions.lf | 4 +- test/C/src/ParameterHierarchy.lf | 16 +- test/C/src/ParameterizedState.lf | 4 +- test/C/src/PeriodicDesugared.lf | 2 +- test/C/src/PingPong.lf | 8 +- test/C/src/ReadOutputOfContainedReactor.lf | 2 +- test/C/src/ScheduleLogicalAction.lf | 2 +- test/C/src/SelfLoop.lf | 2 +- test/C/src/SendingInside.lf | 4 +- test/C/src/SendsPointerTest.lf | 2 +- test/C/src/SetArray.lf | 2 +- test/C/src/SetToken.lf | 2 +- test/C/src/SimpleDeadline.lf | 2 +- test/C/src/SlowingClock.lf | 4 +- test/C/src/SlowingClockPhysical.lf | 4 +- test/C/src/Starvation.lf | 6 +- test/C/src/Stop.lf | 2 +- test/C/src/StopZero.lf | 2 +- test/C/src/Stride.lf | 6 +- test/C/src/StructAsState.lf | 2 +- test/C/src/StructAsType.lf | 2 +- test/C/src/StructAsTypeDirect.lf | 2 +- test/C/src/StructParallel.lf | 6 +- test/C/src/StructPrint.lf | 2 +- test/C/src/StructScale.lf | 6 +- test/C/src/SubclassesAndStartup.lf | 6 +- test/C/src/TimeLimit.lf | 8 +- test/C/src/TimeState.lf | 4 +- test/C/src/Timeout.lf | 2 +- test/C/src/TimeoutZero.lf | 2 +- test/C/src/ToReactionNested.lf | 4 +- test/C/src/TriggerDownstreamOnlyIfPresent2.lf | 2 +- test/C/src/UnconnectedInput.lf | 4 +- test/C/src/arduino/DigitalReadSerial.lf | 2 +- test/C/src/arduino/Fade.lf | 6 +- test/C/src/concurrent/AsyncCallback.lf | 8 +- test/C/src/concurrent/AsyncCallbackDrop.lf | 8 +- test/C/src/concurrent/AsyncCallbackReplace.lf | 8 +- test/C/src/concurrent/CompositionThreaded.lf | 6 +- .../DeadlineHandledAboveThreaded.lf | 4 +- test/C/src/concurrent/DeadlineThreaded.lf | 8 +- test/C/src/concurrent/DelayIntThreaded.lf | 6 +- .../src/concurrent/DoubleReactionThreaded.lf | 6 +- test/C/src/concurrent/GainThreaded.lf | 4 +- test/C/src/concurrent/HelloThreaded.lf | 10 +- test/C/src/concurrent/PingPongThreaded.lf | 8 +- test/C/src/concurrent/ScheduleAt.lf | 17 +- test/C/src/concurrent/ScheduleTwice.lf | 2 +- .../C/src/concurrent/ScheduleTwiceThreaded.lf | 2 +- .../C/src/concurrent/SendingInsideThreaded.lf | 4 +- test/C/src/concurrent/StarvationThreaded.lf | 6 +- test/C/src/concurrent/StopThreaded.lf | 2 +- test/C/src/concurrent/StopZeroThreaded.lf | 2 +- test/C/src/concurrent/Threaded.lf | 8 +- test/C/src/concurrent/ThreadedMultiport.lf | 12 +- test/C/src/concurrent/ThreadedThreaded.lf | 8 +- test/C/src/concurrent/TimeLimitThreaded.lf | 8 +- test/C/src/concurrent/TimeoutThreaded.lf | 2 +- test/C/src/concurrent/TimeoutZeroThreaded.lf | 2 +- test/C/src/concurrent/Tracing.lf | 14 +- .../DistributedCountContainerized.lf | 4 +- test/C/src/federated/BroadcastFeedback.lf | 2 +- .../BroadcastFeedbackWithHierarchy.lf | 4 +- test/C/src/federated/CycleDetection.lf | 2 +- test/C/src/federated/DecentralizedP2PComm.lf | 10 +- .../DecentralizedP2PUnbalancedTimeout.lf | 8 +- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 8 +- test/C/src/federated/DistributedBank.lf | 2 +- .../federated/DistributedBankToMultiport.lf | 2 +- test/C/src/federated/DistributedCount.lf | 4 +- .../DistributedCountDecentralized.lf | 2 +- .../DistributedCountDecentralizedLate.lf | 6 +- ...tributedCountDecentralizedLateHierarchy.lf | 8 +- .../src/federated/DistributedCountPhysical.lf | 4 +- .../DistributedCountPhysicalAfterDelay.lf | 2 +- .../DistributedCountPhysicalDecentralized.lf | 4 +- test/C/src/federated/DistributedDoublePort.lf | 2 +- .../DistributedLogicalActionUpstreamLong.lf | 4 +- .../src/federated/DistributedLoopedAction.lf | 11 +- .../DistributedLoopedActionDecentralized.lf | 19 +- .../DistributedLoopedPhysicalAction.lf | 15 +- test/C/src/federated/DistributedMultiport.lf | 4 +- .../federated/DistributedMultiportToBank.lf | 4 +- .../federated/DistributedMultiportToken.lf | 2 +- .../src/federated/DistributedNetworkOrder.lf | 2 +- .../DistributedPhysicalActionUpstream.lf | 2 +- .../DistributedPhysicalActionUpstreamLong.lf | 2 +- test/C/src/federated/DistributedStop.lf | 6 +- test/C/src/federated/DistributedToken.lf | 6 +- test/C/src/federated/FeedbackDelay.lf | 8 +- test/C/src/federated/FeedbackDelaySimple.lf | 2 +- test/C/src/federated/HelloDistributed.lf | 2 +- .../federated/LoopDistributedCentralized.lf | 6 +- .../federated/LoopDistributedCentralized2.lf | 10 +- ...oopDistributedCentralizedPhysicalAction.lf | 6 +- .../LoopDistributedCentralizedPrecedence.lf | 8 +- ...stributedCentralizedPrecedenceHierarchy.lf | 12 +- .../federated/LoopDistributedDecentralized.lf | 6 +- test/C/src/federated/LoopDistributedDouble.lf | 6 +- test/C/src/federated/PhysicalSTP.lf | 4 +- test/C/src/federated/PingPongDistributed.lf | 2 +- .../federated/PingPongDistributedPhysical.lf | 10 +- test/C/src/federated/TopLevelArtifacts.lf | 2 +- test/C/src/federated/failing/ClockSync.lf | 2 +- .../failing/DistributedDoublePortLooped.lf | 4 +- .../failing/DistributedDoublePortLooped2.lf | 4 +- .../DistributedNetworkOrderDecentralized.lf | 2 +- .../LoopDistributedDecentralizedPrecedence.lf | 8 +- ...ributedDecentralizedPrecedenceHierarchy.lf | 38 +- test/C/src/lib/Count.lf | 4 +- test/C/src/lib/InternalDelay.lf | 2 +- test/C/src/lib/LoopedActionSender.lf | 4 +- test/C/src/lib/Test.lf | 4 +- test/C/src/lib/TestCount.lf | 6 +- test/C/src/lib/TestCountMultiport.lf | 12 +- test/C/src/modal_models/ConvertCaseTest.lf | 4 +- test/C/src/modal_models/Count3Modes.lf | 2 +- test/C/src/modal_models/MixedReactions.lf | 4 +- test/C/src/modal_models/ModalAfter.lf | 4 +- test/C/src/modal_models/ModalCycleBreaker.lf | 4 +- test/C/src/modal_models/ModalStateReset.lf | 6 +- .../C/src/modal_models/ModalStateResetAuto.lf | 6 +- .../MultipleOutputFeeder_2Connections.lf | 4 +- ...ultipleOutputFeeder_ReactionConnections.lf | 4 +- test/C/src/modal_models/util/TraceTesting.lf | 16 +- test/C/src/multiport/BankIndexInitializer.lf | 8 +- .../src/multiport/BankMultiportToReaction.lf | 4 +- .../src/multiport/BankReactionsInContainer.lf | 6 +- test/C/src/multiport/BankSelfBroadcast.lf | 4 +- test/C/src/multiport/BankToBank.lf | 10 +- test/C/src/multiport/BankToBankMultiport.lf | 10 +- .../src/multiport/BankToBankMultiportAfter.lf | 10 +- test/C/src/multiport/BankToMultiport.lf | 8 +- test/C/src/multiport/BankToReaction.lf | 2 +- test/C/src/multiport/Broadcast.lf | 4 +- test/C/src/multiport/BroadcastAfter.lf | 4 +- .../C/src/multiport/BroadcastMultipleAfter.lf | 6 +- test/C/src/multiport/DualBanks.lf | 4 +- test/C/src/multiport/DualBanksMultiport.lf | 4 +- test/C/src/multiport/FullyConnected.lf | 6 +- .../multiport/FullyConnectedAddressable.lf | 8 +- .../FullyConnectedAddressableAfter.lf | 2 +- test/C/src/multiport/MultiportFromBank.lf | 8 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../C/src/multiport/MultiportFromHierarchy.lf | 14 +- test/C/src/multiport/MultiportFromReaction.lf | 8 +- test/C/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 6 +- test/C/src/multiport/MultiportMutableInput.lf | 4 +- .../multiport/MultiportMutableInputArray.lf | 4 +- test/C/src/multiport/MultiportOut.lf | 4 +- test/C/src/multiport/MultiportToBank.lf | 8 +- test/C/src/multiport/MultiportToBankAfter.lf | 8 +- test/C/src/multiport/MultiportToBankDouble.lf | 4 +- .../src/multiport/MultiportToBankHierarchy.lf | 10 +- test/C/src/multiport/MultiportToHierarchy.lf | 12 +- test/C/src/multiport/MultiportToMultiport.lf | 10 +- test/C/src/multiport/MultiportToMultiport2.lf | 10 +- .../multiport/MultiportToMultiport2After.lf | 4 +- .../multiport/MultiportToMultiportArray.lf | 4 +- .../MultiportToMultiportParameter.lf | 10 +- test/C/src/multiport/MultiportToPort.lf | 4 +- test/C/src/multiport/MultiportToReaction.lf | 6 +- test/C/src/multiport/NestedBanks.lf | 10 +- .../C/src/multiport/NestedInterleavedBanks.lf | 4 +- .../src/multiport/ReactionToContainedBank.lf | 4 +- .../src/multiport/ReactionToContainedBank2.lf | 6 +- .../ReactionToContainedBankMultiport.lf | 4 +- test/C/src/multiport/ReactionsToNested.lf | 4 +- test/C/src/multiport/Sparse.lf | 8 +- test/C/src/multiport/SparseFallback.lf | 8 +- .../TriggerDownstreamOnlyIfPresent.lf | 2 +- .../serialization/ROSBuiltInSerialization.lf | 4 +- .../ROSBuiltInSerializationSharedPtr.lf | 4 +- test/C/src/target/HelloWorldCCPP.lf | 2 +- test/C/src/token/TokenContainedPrint.lf | 2 +- test/C/src/token/TokenContainedPrintBank.lf | 2 +- test/C/src/token/TokenContainedSource.lf | 6 +- test/C/src/token/TokenContainedSourceBank.lf | 6 +- test/C/src/token/lib/Token.lf | 10 +- test/Cpp/src/ActionDelay.lf | 2 +- test/Cpp/src/ActionIsPresent.lf | 6 +- test/Cpp/src/ActionValues.lf | 4 +- test/Cpp/src/After.lf | 4 +- test/Cpp/src/AfterOverlapped.lf | 2 +- test/Cpp/src/AfterZero.lf | 4 +- test/Cpp/src/Alignment.lf | 2 +- test/Cpp/src/ArrayAsParameter.lf | 8 +- test/Cpp/src/ArrayPrint.lf | 2 +- test/Cpp/src/ArrayScale.lf | 2 +- test/Cpp/src/CharLiteralInitializer.lf | 2 +- test/Cpp/src/Composition.lf | 6 +- test/Cpp/src/CompositionAfter.lf | 8 +- test/Cpp/src/CountTest.lf | 2 +- test/Cpp/src/Deadline.lf | 8 +- test/Cpp/src/DeadlineHandledAbove.lf | 4 +- test/Cpp/src/DelayInt.lf | 2 +- test/Cpp/src/DelayedAction.lf | 2 +- test/Cpp/src/DoubleInvocation.lf | 4 +- test/Cpp/src/DoublePort.lf | 2 +- test/Cpp/src/DoubleReaction.lf | 6 +- test/Cpp/src/DoubleTrigger.lf | 2 +- test/Cpp/src/FloatLiteral.lf | 8 +- test/Cpp/src/Gain.lf | 2 +- test/Cpp/src/GetMicroStep.lf | 2 +- test/Cpp/src/Hello.lf | 11 +- test/Cpp/src/Hierarchy2.lf | 4 +- test/Cpp/src/ImportComposition.lf | 2 +- test/Cpp/src/ManualDelayedReaction.lf | 2 +- test/Cpp/src/Methods.lf | 2 +- test/Cpp/src/MovingAverage.lf | 6 +- test/Cpp/src/NativeListsAndTimes.lf | 20 +- test/Cpp/src/NestedTriggeredReactions.lf | 4 +- test/Cpp/src/ParameterHierarchy.lf | 6 +- test/Cpp/src/ParameterizedState.lf | 4 +- test/Cpp/src/ParametersOutOfOrder.lf | 2 +- test/Cpp/src/PeriodicDesugared.lf | 4 +- test/Cpp/src/Pipeline.lf | 4 +- test/Cpp/src/ReadOutputOfContainedReactor.lf | 2 +- test/Cpp/src/ScheduleLogicalAction.lf | 2 +- test/Cpp/src/SelfLoop.lf | 2 +- test/Cpp/src/SendingInside.lf | 4 +- test/Cpp/src/SimpleDeadline.lf | 2 +- test/Cpp/src/SlowingClock.lf | 4 +- test/Cpp/src/SlowingClockPhysical.lf | 4 +- test/Cpp/src/Stride.lf | 4 +- test/Cpp/src/StructPrint.lf | 4 +- test/Cpp/src/StructScale.lf | 2 +- test/Cpp/src/TimeLimit.lf | 8 +- test/Cpp/src/TimeState.lf | 4 +- test/Cpp/src/Timeout_Test.lf | 2 +- test/Cpp/src/ToReactionNested.lf | 4 +- .../src/TriggerDownstreamOnlyIfPresent2.lf | 2 +- test/Cpp/src/concurrent/AsyncCallback.lf | 6 +- test/Cpp/src/concurrent/AsyncCallback2.lf | 4 +- .../Cpp/src/concurrent/CompositionThreaded.lf | 6 +- .../DeadlineHandledAboveThreaded.lf | 4 +- test/Cpp/src/concurrent/DeadlineThreaded.lf | 8 +- test/Cpp/src/concurrent/DelayIntThreaded.lf | 2 +- .../src/concurrent/DoubleReactionThreaded.lf | 6 +- test/Cpp/src/concurrent/GainThreaded.lf | 2 +- test/Cpp/src/concurrent/HelloThreaded.lf | 11 +- .../src/concurrent/SendingInsideThreaded.lf | 4 +- test/Cpp/src/concurrent/Threaded.lf | 4 +- test/Cpp/src/concurrent/ThreadedThreaded.lf | 4 +- test/Cpp/src/concurrent/TimeLimitThreaded.lf | 8 +- test/Cpp/src/enclave/EnclaveBank.lf | 8 +- test/Cpp/src/enclave/EnclaveBankEach.lf | 8 +- test/Cpp/src/enclave/EnclaveHelloWorld.lf | 4 +- test/Cpp/src/enclave/EnclaveHierarchy.lf | 6 +- test/Cpp/src/enclave/EnclaveShutdown.lf | 6 +- test/Cpp/src/enclave/EnclaveTimeout.lf | 2 +- test/Cpp/src/lib/Count.lf | 2 +- test/Cpp/src/lib/LoopedActionSender.lf | 4 +- test/Cpp/src/multiport/BankSelfBroadcast.lf | 4 +- test/Cpp/src/multiport/BankToBank.lf | 10 +- test/Cpp/src/multiport/BankToBankMultiport.lf | 10 +- .../src/multiport/BankToBankMultiportAfter.lf | 12 +- test/Cpp/src/multiport/BankToMultiport.lf | 4 +- test/Cpp/src/multiport/Broadcast.lf | 2 +- test/Cpp/src/multiport/BroadcastAfter.lf | 4 +- .../src/multiport/BroadcastMultipleAfter.lf | 6 +- test/Cpp/src/multiport/FullyConnected.lf | 6 +- .../multiport/FullyConnectedAddressable.lf | 6 +- .../FullyConnectedAddressableAfter.lf | 2 +- .../src/multiport/IndexIntoMultiportOutput.lf | 10 +- test/Cpp/src/multiport/Multiport.lf | 2 +- test/Cpp/src/multiport/MultiportFromBank.lf | 8 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 4 +- .../src/multiport/MultiportFromHierarchy.lf | 4 +- test/Cpp/src/multiport/MultiportIn.lf | 4 +- test/Cpp/src/multiport/MultiportOut.lf | 4 +- test/Cpp/src/multiport/MultiportToBank.lf | 2 +- .../Cpp/src/multiport/MultiportToBankAfter.lf | 2 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- .../Cpp/src/multiport/MultiportToHierarchy.lf | 12 +- .../Cpp/src/multiport/MultiportToMultiport.lf | 2 +- .../src/multiport/MultiportToMultiport2.lf | 4 +- .../multiport/MultiportToMultiport2After.lf | 4 +- .../multiport/MultiportToMultiportArray.lf | 4 +- test/Cpp/src/multiport/MultiportToPort.lf | 4 +- .../ReadMultiportOutputOfContainedBank.lf | 4 +- .../multiport/ReadOutputOfContainedBank.lf | 4 +- test/Cpp/src/multiport/WidthGivenByCode.lf | 2 +- .../multiport/WriteInputOfContainedBank.lf | 4 +- .../WriteMultiportInputOfContainedBank.lf | 4 +- test/Cpp/src/properties/Fast.lf | 2 +- test/Cpp/src/properties/Timeout.lf | 2 +- test/Cpp/src/properties/TimeoutZero.lf | 2 +- test/Cpp/src/target/AfterVoid.lf | 4 +- .../src/target/BraceAndParenInitialization.lf | 5 +- .../src/target/CliParserGenericArguments.lf | 26 +- test/Cpp/src/target/CombinedTypeNames.lf | 10 +- test/Cpp/src/target/GenericDelay.lf | 2 +- .../src/target/GenericParameterAndState.lf | 4 +- test/Cpp/src/target/InitializerSyntax.lf | 89 + test/Cpp/src/target/PointerParameters.lf | 2 +- test/Python/src/ActionDelay.lf | 2 +- test/Python/src/ActionIsPresent.lf | 6 +- test/Python/src/After.lf | 4 +- test/Python/src/AfterCycles.lf | 2 +- test/Python/src/AfterOverlapped.lf | 4 +- test/Python/src/ArrayAsParameter.lf | 8 +- test/Python/src/ArrayAsType.lf | 2 +- test/Python/src/ArrayFree.lf | 2 +- test/Python/src/ArrayPrint.lf | 2 +- test/Python/src/ArrayScale.lf | 2 +- test/Python/src/Composition.lf | 6 +- test/Python/src/CompositionAfter.lf | 8 +- test/Python/src/CompositionInheritance.lf | 6 +- test/Python/src/CountSelf.lf | 4 +- test/Python/src/CountTest.lf | 2 +- test/Python/src/Deadline.lf | 8 +- test/Python/src/DeadlineHandledAbove.lf | 4 +- test/Python/src/DelayArray.lf | 4 +- test/Python/src/DelayArrayWithAfter.lf | 8 +- test/Python/src/DelayInt.lf | 6 +- test/Python/src/DelayString.lf | 4 +- test/Python/src/DelayStruct.lf | 4 +- test/Python/src/DelayStructWithAfter.lf | 2 +- .../src/DelayStructWithAfterOverlapped.lf | 4 +- test/Python/src/DelayedAction.lf | 2 +- test/Python/src/DoubleInvocation.lf | 4 +- test/Python/src/DoubleReaction.lf | 6 +- test/Python/src/FloatLiteral.lf | 8 +- test/Python/src/Gain.lf | 4 +- test/Python/src/GetMicroStep.lf | 2 +- test/Python/src/Hello.lf | 8 +- test/Python/src/HelloWorld.lf | 2 +- test/Python/src/Hierarchy2.lf | 4 +- test/Python/src/IdentifierLength.lf | 6 +- test/Python/src/ImportComposition.lf | 2 +- test/Python/src/ManualDelayedReaction.lf | 2 +- test/Python/src/Methods.lf | 2 +- test/Python/src/MethodsRecursive.lf | 2 +- test/Python/src/MethodsSameName.lf | 4 +- test/Python/src/MovingAverage.lf | 6 +- test/Python/src/MultipleContained.lf | 2 +- test/Python/src/NativeListsAndTimes.lf | 14 +- test/Python/src/ParameterizedState.lf | 4 +- test/Python/src/PeriodicDesugared.lf | 2 +- test/Python/src/PingPong.lf | 8 +- test/Python/src/Pipeline.lf | 6 +- .../src/ReadOutputOfContainedReactor.lf | 2 +- test/Python/src/ScheduleLogicalAction.lf | 2 +- test/Python/src/SelfLoop.lf | 2 +- test/Python/src/SendingInside.lf | 4 +- test/Python/src/SetArray.lf | 2 +- test/Python/src/SimpleDeadline.lf | 2 +- test/Python/src/SlowingClock.lf | 4 +- test/Python/src/SlowingClockPhysical.lf | 4 +- test/Python/src/Stride.lf | 6 +- test/Python/src/StructAsState.lf | 2 +- test/Python/src/StructAsType.lf | 2 +- test/Python/src/StructAsTypeDirect.lf | 2 +- test/Python/src/StructParallel.lf | 4 +- test/Python/src/StructPrint.lf | 2 +- test/Python/src/StructScale.lf | 4 +- test/Python/src/SubclassesAndStartup.lf | 6 +- test/Python/src/TimeLimit.lf | 8 +- test/Python/src/TimeState.lf | 4 +- test/Python/src/Timers.lf | 2 +- .../src/TriggerDownstreamOnlyIfPresent.lf | 2 +- .../src/TriggerDownstreamOnlyIfPresent2.lf | 2 +- test/Python/src/UnconnectedInput.lf | 4 +- test/Python/src/concurrent/AsyncCallback.lf | 8 +- .../src/concurrent/AsyncCallbackNoTimer.lf | 8 +- .../src/docker/FilesPropertyContainerized.lf | 2 +- .../DistributedCountContainerized.lf | 2 +- .../Python/src/federated/BroadcastFeedback.lf | 2 +- .../BroadcastFeedbackWithHierarchy.lf | 4 +- test/Python/src/federated/CycleDetection.lf | 2 +- .../src/federated/DecentralizedP2PComm.lf | 6 +- .../DecentralizedP2PUnbalancedTimeout.lf | 8 +- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 8 +- test/Python/src/federated/DistributedBank.lf | 2 +- .../federated/DistributedBankToMultiport.lf | 2 +- test/Python/src/federated/DistributedCount.lf | 4 +- .../DistributedCountDecentralized.lf | 2 +- .../DistributedCountDecentralizedLate.lf | 6 +- ...ributedCountDecentralizedLateDownstream.lf | 8 +- ...tributedCountDecentralizedLateHierarchy.lf | 2 +- .../src/federated/DistributedCountPhysical.lf | 4 +- .../DistributedCountPhysicalAfterDelay.lf | 4 +- .../DistributedCountPhysicalDecentralized.lf | 4 +- .../src/federated/DistributedDoublePort.lf | 2 +- .../src/federated/DistributedLoopedAction.lf | 8 +- .../DistributedLoopedPhysicalAction.lf | 12 +- .../src/federated/DistributedMultiport.lf | 4 +- .../federated/DistributedMultiportToBank.lf | 4 +- .../federated/DistributedMultiportToken.lf | 2 +- test/Python/src/federated/DistributedStop.lf | 6 +- test/Python/src/federated/HelloDistributed.lf | 2 +- ...stributedCentralizedPrecedenceHierarchy.lf | 12 +- test/Python/src/federated/PhysicalSTP.lf | 4 +- .../src/federated/PingPongDistributed.lf | 10 +- .../LoopDistributedCentralizedPrecedence.lf | 8 +- .../failing/LoopDistributedDouble.lf | 6 +- test/Python/src/lib/Count.lf | 4 +- test/Python/src/lib/InternalDelay.lf | 2 +- test/Python/src/lib/LoopedActionSender.lf | 4 +- test/Python/src/lib/Test.lf | 2 +- test/Python/src/lib/TestCount.lf | 6 +- test/Python/src/lib/TestCountMultiport.lf | 6 +- .../src/modal_models/ConvertCaseTest.lf | 4 +- test/Python/src/modal_models/Count3Modes.lf | 2 +- test/Python/src/modal_models/ModalAfter.lf | 4 +- .../src/modal_models/ModalCycleBreaker.lf | 4 +- .../src/modal_models/ModalStateReset.lf | 6 +- .../src/modal_models/ModalStateResetAuto.lf | 6 +- .../MultipleOutputFeeder_2Connections.lf | 4 +- ...ultipleOutputFeeder_ReactionConnections.lf | 4 +- .../src/modal_models/util/TraceTesting.lf | 10 +- .../src/multiport/BankIndexInitializer.lf | 8 +- .../src/multiport/BankReactionsInContainer.lf | 6 +- test/Python/src/multiport/BankToBank.lf | 10 +- .../src/multiport/BankToBankMultiport.lf | 10 +- .../src/multiport/BankToBankMultiportAfter.lf | 2 +- test/Python/src/multiport/BankToMultiport.lf | 8 +- test/Python/src/multiport/Broadcast.lf | 6 +- .../src/multiport/BroadcastMultipleAfter.lf | 4 +- .../Python/src/multiport/MultiportFromBank.lf | 4 +- .../multiport/MultiportFromBankHierarchy.lf | 2 +- .../src/multiport/MultiportFromHierarchy.lf | 4 +- .../src/multiport/MultiportFromReaction.lf | 6 +- test/Python/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 6 +- .../src/multiport/MultiportMutableInput.lf | 4 +- .../multiport/MultiportMutableInputArray.lf | 4 +- test/Python/src/multiport/MultiportOut.lf | 4 +- test/Python/src/multiport/MultiportToBank.lf | 4 +- .../src/multiport/MultiportToBankAfter.lf | 4 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- .../src/multiport/MultiportToHierarchy.lf | 8 +- .../src/multiport/MultiportToMultiport.lf | 4 +- .../src/multiport/MultiportToMultiport2.lf | 4 +- .../multiport/MultiportToMultiport2After.lf | 2 +- .../multiport/MultiportToMultiportArray.lf | 4 +- .../MultiportToMultiportParameter.lf | 2 +- test/Python/src/multiport/MultiportToPort.lf | 4 +- .../src/multiport/MultiportToReaction.lf | 6 +- test/Python/src/multiport/NestedBanks.lf | 10 +- .../src/multiport/NestedInterleavedBanks.lf | 4 +- .../Python/src/multiport/ReactionsToNested.lf | 4 +- test/Python/src/target/AfterNoTypes.lf | 4 +- test/Rust/src/ActionDelay.lf | 2 +- test/Rust/src/ActionImplicitDelay.lf | 2 +- test/Rust/src/ActionIsPresent.lf | 4 +- test/Rust/src/ActionScheduleMicrostep.lf | 2 +- test/Rust/src/ActionValues.lf | 4 +- test/Rust/src/ActionValuesCleanup.lf | 2 +- test/Rust/src/CtorParamDefault.lf | 4 +- test/Rust/src/CtorParamMixed.lf | 12 +- test/Rust/src/CtorParamSimple.lf | 4 +- test/Rust/src/DependencyOnChildPort.lf | 2 +- test/Rust/src/DependencyUseOnLogicalAction.lf | 2 +- test/Rust/src/FloatLiteral.lf | 8 +- test/Rust/src/MainReactorParam.lf | 6 +- test/Rust/src/MovingAverage.lf | 9 +- test/Rust/src/NativeListsAndTimes.lf | 14 +- test/Rust/src/PortConnectionInSelfInChild.lf | 2 +- test/Rust/src/PortConnectionInSelfOutSelf.lf | 2 +- .../Rust/src/PortConnectionOutChildOutSelf.lf | 4 +- test/Rust/src/PortRefCleanup.lf | 4 +- test/Rust/src/PortValueCleanup.lf | 4 +- test/Rust/src/ReservedKeywords.lf | 4 +- test/Rust/src/StateInitializerVisibility.lf | 4 +- test/Rust/src/Stop.lf | 10 +- test/Rust/src/StopIdempotence.lf | 2 +- test/Rust/src/StopTimeoutExact.lf | 2 +- test/Rust/src/StructAsState.lf | 2 +- test/Rust/src/StructAsType.lf | 4 +- test/Rust/src/TimeState.lf | 2 +- test/Rust/src/TimerDefaults.lf | 2 +- test/Rust/src/TimerIsPresent.lf | 4 +- test/Rust/src/TimerPeriodic.lf | 2 +- test/Rust/src/Timers.lf | 2 +- test/Rust/src/TypeVarLengthList.lf | 2 +- test/Rust/src/concurrent/AsyncCallback.lf | 10 +- test/Rust/src/generics/CtorParamGeneric.lf | 4 +- .../Rust/src/generics/CtorParamGenericInst.lf | 6 +- test/Rust/src/generics/GenericReactor.lf | 2 +- .../src/multiport/ConnectionToSelfBank.lf | 8 +- .../multiport/ConnectionToSelfMultiport.lf | 6 +- test/Rust/src/multiport/CycledLhs_SelfLoop.lf | 2 +- test/Rust/src/multiport/CycledLhs_Single.lf | 2 +- test/Rust/src/multiport/FullyConnected.lf | 10 +- .../multiport/FullyConnectedAddressable.lf | 10 +- test/Rust/src/multiport/MultiportFromBank.lf | 6 +- .../src/multiport/MultiportFromHierarchy.lf | 4 +- test/Rust/src/multiport/MultiportIn.lf | 4 +- test/Rust/src/multiport/MultiportOut.lf | 4 +- test/Rust/src/multiport/MultiportToBank.lf | 6 +- .../src/multiport/MultiportToBankHierarchy.lf | 6 +- .../src/multiport/MultiportToMultiport2.lf | 4 +- .../multiport/ReadOutputOfContainedBank.lf | 6 +- test/Rust/src/multiport/WidthWithParameter.lf | 2 +- .../multiport/WriteInputOfContainedBank.lf | 6 +- test/Rust/src/target/CliFeature.lf | 2 +- .../target/MainParameterCanBeExpression.lf | 4 +- test/TypeScript/src/ActionDelay.lf | 2 +- test/TypeScript/src/After.lf | 2 +- test/TypeScript/src/ArrayAsParameter.lf | 6 +- test/TypeScript/src/ArrayAsType.lf | 2 +- test/TypeScript/src/ArrayPrint.lf | 2 +- test/TypeScript/src/ArrayScale.lf | 2 +- test/TypeScript/src/Composition.lf | 6 +- test/TypeScript/src/CompositionAfter.lf | 8 +- test/TypeScript/src/CountTest.lf | 2 +- test/TypeScript/src/Deadline.lf | 8 +- test/TypeScript/src/DeadlineHandledAbove.lf | 4 +- test/TypeScript/src/DelayInt.lf | 6 +- test/TypeScript/src/DelayedAction.lf | 2 +- test/TypeScript/src/DoubleInvocation.lf | 4 +- test/TypeScript/src/DoubleReaction.lf | 6 +- test/TypeScript/src/DoubleTrigger.lf | 2 +- test/TypeScript/src/FloatLiteral.lf | 8 +- test/TypeScript/src/Gain.lf | 4 +- test/TypeScript/src/Hello.lf | 10 +- test/TypeScript/src/Hierarchy2.lf | 4 +- test/TypeScript/src/MovingAverage.lf | 8 +- test/TypeScript/src/NativeListsAndTimes.lf | 14 +- test/TypeScript/src/ParameterizedState.lf | 4 +- test/TypeScript/src/PeriodicDesugared.lf | 4 +- .../src/ReadOutputOfContainedReactor.lf | 2 +- test/TypeScript/src/ScheduleLogicalAction.lf | 2 +- test/TypeScript/src/SendingInside.lf | 4 +- test/TypeScript/src/SendsPointerTest.lf | 2 +- test/TypeScript/src/SimpleDeadline.lf | 2 +- test/TypeScript/src/SlowingClock.lf | 4 +- test/TypeScript/src/SlowingClockPhysical.lf | 4 +- test/TypeScript/src/Stop.lf | 2 +- test/TypeScript/src/Stride.lf | 4 +- test/TypeScript/src/StructAsState.lf | 2 +- test/TypeScript/src/StructAsType.lf | 2 +- test/TypeScript/src/StructAsTypeDirect.lf | 2 +- test/TypeScript/src/StructPrint.lf | 2 +- test/TypeScript/src/StructScale.lf | 2 +- test/TypeScript/src/TimeLimit.lf | 8 +- test/TypeScript/src/TimeState.lf | 4 +- .../src/concurrent/AsyncCallback.lf | 6 +- .../DistributedCountContainerized.lf | 2 +- .../src/federated/DistributedCount.lf | 4 +- .../src/federated/DistributedCountPhysical.lf | 6 +- .../DistributedCountPhysicalAfterDelay.lf | 49 + .../src/federated/DistributedDoublePort.lf | 2 +- .../src/federated/DistributedLoopedAction.lf | 8 +- .../DistributedLoopedPhysicalAction.lf | 12 +- .../src/federated/DistributedStop.lf | 6 +- .../src/federated/HelloDistributed.lf | 2 +- .../federated/LoopDistributedCentralized.lf | 6 +- .../src/federated/LoopDistributedDouble.lf | 6 +- .../src/federated/PingPongDistributed.lf | 10 +- .../federated/PingPongDistributedPhysical.lf | 10 +- .../src/federated/TopLevelArtifacts.lf | 2 +- test/TypeScript/src/lib/Count.lf | 4 +- test/TypeScript/src/lib/InternalDelay.lf | 2 +- test/TypeScript/src/lib/LoopedActionSender.lf | 4 +- test/TypeScript/src/lib/TestCount.lf | 10 +- .../src/multiport/BankMultiportToReaction.lf | 4 +- .../src/multiport/BankReactionsInContainer.lf | 4 +- .../src/multiport/BankSelfBroadcast.lf | 2 +- test/TypeScript/src/multiport/BankToBank.lf | 6 +- .../src/multiport/BankToBankMultiport.lf | 10 +- .../src/multiport/BankToBankMultiportAfter.lf | 10 +- .../src/multiport/BankToMultiport.lf | 2 +- .../src/multiport/BankToReaction.lf | 2 +- .../src/multiport/BroadcastAfter.lf | 2 +- .../src/multiport/BroadcastMultipleAfter.lf | 4 +- .../src/multiport/FullyConnected.lf | 6 +- .../src/multiport/MultiportFromBank.lf | 6 +- .../multiport/MultiportFromBankHierarchy.lf | 2 +- .../src/multiport/MultiportFromHierarchy.lf | 14 +- .../src/multiport/MultiportFromReaction.lf | 8 +- test/TypeScript/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 6 +- .../src/multiport/MultiportMutableInput.lf | 4 +- .../multiport/MultiportMutableInputArray.lf | 4 +- test/TypeScript/src/multiport/MultiportOut.lf | 4 +- .../src/multiport/MultiportToBankAfter.lf | 6 +- .../src/multiport/MultiportToBankDouble.lf | 2 +- .../src/multiport/MultiportToBankHierarchy.lf | 2 +- .../src/multiport/MultiportToHierarchy.lf | 12 +- .../src/multiport/MultiportToMultiport.lf | 2 +- .../src/multiport/MultiportToMultiport2.lf | 4 +- .../multiport/MultiportToMultiport2After.lf | 4 +- .../multiport/MultiportToMultiportArray.lf | 4 +- .../MultiportToMultiportParameter.lf | 10 +- .../src/multiport/MultiportToPort.lf | 4 +- .../src/multiport/MultiportToReaction.lf | 6 +- test/TypeScript/src/multiport/NestedBanks.lf | 6 +- .../src/multiport/ReactionToContainedBank.lf | 4 +- .../src/multiport/ReactionsToNested.lf | 4 +- test/TypeScript/src/target/AfterNoTypes.lf | 2 +- 698 files changed, 3285 insertions(+), 3471 deletions(-) create mode 100644 org.lflang/src/org/lflang/generator/LfExpressionVisitor.java create mode 100644 org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java delete mode 100644 org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt create mode 100644 org.lflang/src/org/lflang/generator/ts/TSTypes.java delete mode 100644 org.lflang/src/org/lflang/generator/ts/TSTypes.kt create mode 100644 test/Cpp/src/target/InitializerSyntax.lf create mode 100644 test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java index ae325ab94d..d7862e5d25 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java @@ -34,7 +34,7 @@ public void testSimple() { @Test public void testAssignments() { - assertIsFormatted( + assertFormatsTo( """ target C @@ -43,6 +43,15 @@ public void testAssignments() { input in: int state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) } + """, + """ + target C + + reactor Destination { + input ok: bool + input in: int + state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} + } """ ); } @@ -56,16 +65,34 @@ public void testState() { reactor Destination { state one_init: tag_t( {= NEVER_TAG_INITIALIZER =}) state no_init: tag_t - state list_init(1,2) + state list_init(1,2) // this syntax is deprecated } """, """ target Python + reactor Destination { + state one_init: tag_t = {= NEVER_TAG_INITIALIZER =} + state no_init: tag_t + state list_init(1, 2) # this syntax is deprecated + } + """ + ); + } + + @Test + public void testCppInits() { + assertIsFormatted( + """ + target Cpp + reactor Destination { state one_init: tag_t({= NEVER_TAG_INITIALIZER =}) state no_init: tag_t - state list_init(1, 2) + state assign: int = 0 + state paren: int(0) + state brace: std::vector{1, 2} + state paren_list: std::vector(1, 2) } """ ); diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java index 3e40927de0..a78d41ac4d 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java @@ -101,7 +101,7 @@ public void testLet() throws Exception { )); Assertions.assertNotNull(model); - final var ctypes = new CTypes(new DefaultErrorReporter()); + final var ctypes = CTypes.getInstance(); final var resource = model.eResource(); final var transformation = new DelayedConnectionTransformation(new CDelayBodyGenerator(ctypes), ctypes, resource, true, true); transformation.applyTransformation(ASTUtils.getAllReactors(resource)); diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 4c0d5dee08..67df93ed30 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -1,29 +1,30 @@ /* Scoping unit tests. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + Copyright (c) 2019, The University of California at Berkeley. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ + package org.lflang.tests.compiler; import java.util.LinkedList; @@ -63,7 +64,7 @@ /** * Collection of unit tests to ensure validation is done correctly. - * + * * @author Edward A. Lee * @author Marten Lohstroh * @author Matt Weber @@ -71,7 +72,8 @@ * @author Alexander Schulz-Rosengarten */ public class LinguaFrancaValidationTest { - @Inject + + @Inject ParseHelper parser; @Inject @@ -79,6 +81,7 @@ public class LinguaFrancaValidationTest { /** * Helper function to parse a Lingua Franca program and expect no errors. + * * @return A model representing the parsed string. */ private Model parseWithoutError(String s) throws Exception { @@ -92,6 +95,7 @@ private Model parseWithoutError(String s) throws Exception { /** * Helper function to parse a Lingua Franca program and expect errors. + * * @return A model representing the parsed string. */ private Model parseWithError(String s) throws Exception { @@ -99,105 +103,72 @@ private Model parseWithError(String s) throws Exception { Assertions.assertNotNull(model); Assertions.assertFalse(model.eResource().getErrors().isEmpty()); return model; - } + } /** * Ensure that duplicate identifiers for actions reported. */ @Test public void duplicateVariable() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor Foo { -// logical action bar; -// physical action bar; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor Foo {", - " logical action bar;", - " physical action bar;", - "}"); - validator.assertError(parseWithoutError(testCase), - LfPackage.eINSTANCE.getAction(), - null, - "Duplicate Variable 'bar' in Reactor 'Foo'"); + String testCase = """ + target TypeScript; + main reactor Foo { + logical action bar; + physical action bar; + } + """; + validator.assertError(parseWithoutError(testCase), + LfPackage.eINSTANCE.getAction(), + null, + "Duplicate Variable 'bar' in Reactor 'Foo'"); } /** - * Check that reactors in C++ cannot be named preamble + * Check that reactors in C++ cannot be named preamble */ @Test public void disallowReactorCalledPreamble() throws Exception { -// Java 17: -// Model model_no_errors = """ -// target Cpp; -// main reactor { -// } -// """ -// Java 11: - Model model_no_errors = parser.parse(String.join( - System.getProperty("line.separator"), - "target Cpp;", - "main reactor {", - "}" - )); - -// Java 17: -// Model model_error_1 = """ -// target Cpp; -// main reactor Preamble { -// } -// """ -// Java 11: - Model model_error_1 = parser.parse(String.join( - System.getProperty("line.separator"), - "target Cpp;", - "main reactor Preamble {", - "}" - )); - -// Java 17: -// Model model_error_2 = """ -// target Cpp; -// reactor Preamble { -// } -// main reactor Main { -// } -// """ -// Java 11: - Model model_error_2 = parser.parse(String.join( - System.getProperty("line.separator"), - "target Cpp;", - "reactor Preamble {", - "}", - "main reactor Main {", - "}" - )); - + Model model_no_errors = parser.parse(""" + target Cpp; + main reactor { + } + """); + + Model model_error_1 = parser.parse(""" + target Cpp; + main reactor Preamble { + } + """); + + Model model_error_2 = parser.parse(""" + target Cpp; + reactor Preamble { + } + main reactor Main { + } + """); + Assertions.assertNotNull(model_no_errors); Assertions.assertNotNull(model_error_1); Assertions.assertNotNull(model_error_2); - Assertions.assertTrue(model_no_errors.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + model_no_errors.eResource().getErrors()); - Assertions.assertTrue(model_error_1.eResource().getErrors().isEmpty(), + Assertions.assertTrue(model_no_errors.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + + model_no_errors.eResource().getErrors()); + Assertions.assertTrue(model_error_1.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + model_error_1.eResource().getErrors()); - Assertions.assertTrue(model_error_2.eResource().getErrors().isEmpty(), + Assertions.assertTrue(model_error_2.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + model_error_2.eResource().getErrors()); validator.assertNoIssues(model_no_errors); - validator.assertError(model_error_1, - LfPackage.eINSTANCE.getReactor(), - null, - "Reactor cannot be named 'Preamble'"); - validator.assertError(model_error_2, - LfPackage.eINSTANCE.getReactor(), - null, - "Reactor cannot be named 'Preamble'"); + validator.assertError(model_error_1, + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor cannot be named 'Preamble'"); + validator.assertError(model_error_2, + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor cannot be named 'Preamble'"); } @@ -206,59 +177,39 @@ public void disallowReactorCalledPreamble() throws Exception { */ @Test public void disallowUnderscoreInputs() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor { -// input __bar; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor {", - " input __bar;", - "}"); + String testCase = """ + target TypeScript; + main reactor { + input __bar; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + @Test public void disallowMainWithDifferentNameThanFile() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// main reactor Foo {} -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor Foo {}" - ); + String testCase = """ + target C; + main reactor Foo {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Name of main reactor must match the file name (or be omitted)"); } - + /** * Ensure that "__" is not allowed at the start of an output name. */ @Test public void disallowUnderscoreOutputs() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor Foo { -// output __bar; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor Foo {", - " output __bar;", - "}"); + String testCase = """ + target TypeScript; + main reactor Foo { + output __bar; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); @@ -269,324 +220,207 @@ public void disallowUnderscoreOutputs() throws Exception { */ @Test public void disallowUnderscoreActions() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor Foo { -// logical action __bar; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor Foo {", - " logical action __bar;", - "}"); + String testCase = """ + target TypeScript; + main reactor Foo { + logical action __bar; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of a timer name. */ @Test public void disallowUnderscoreTimers() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor Foo { -// timer __bar(0); -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor Foo {", - " timer __bar(0);", - "}"); + String testCase = """ + target TypeScript; + main reactor Foo { + timer __bar(0); + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of a parameter name. */ @Test public void disallowUnderscoreParameters() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor Foo(__bar) { -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor Foo(__bar) {", - "}"); + String testCase = """ + target TypeScript; + main reactor Foo(__bar) { + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of an state name. */ @Test public void disallowUnderscoreStates() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor Foo { -// state __bar; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor Foo {", - " state __bar;", - "}"); + String testCase = """ + target TypeScript; + main reactor Foo { + state __bar; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of a reactor definition name. */ @Test public void disallowUnderscoreReactorDef() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// main reactor __Foo { -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "main reactor __Foo {", - "}"); + String testCase = """ + target TypeScript; + main reactor __Foo { + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __Foo"); } - + /** * Ensure that "__" is not allowed at the start of a reactor instantiation name. */ @Test public void disallowUnderscoreReactorInstantiation() throws Exception { -// Java 17: -// String testCase = """ -// target TypeScript; -// reactor Foo { -// } -// main reactor Bar { -// __x = new Foo(); -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target TypeScript;", - "reactor Foo {", - "}", - "main reactor Bar {", - " __x = new Foo();", - "}"); + String testCase = """ + target TypeScript; + reactor Foo { + } + main reactor Bar { + __x = new Foo(); + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __x"); } - + /** * Disallow connection to port that is effect of reaction. */ @Test public void connectionToEffectPort() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// reactor Foo { -// output out:int; -// } -// main reactor Bar { -// output out:int; -// x = new Foo(); -// x.out -> out; -// reaction(startup) -> out {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "reactor Foo {", - " output out:int;", - "}", - "main reactor Bar {", - " output out:int;", - " x = new Foo();", - " x.out -> out;", - " reaction(startup) -> out {=", - " =}", - "}"); + String testCase = """ + 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(), null, "Cannot connect: Port named 'out' is already effect of a reaction."); } - + /** * Disallow connection to port that is effect of reaction. */ @Test public void connectionToEffectPort2() throws Exception { -// Java 17: -// String testCase = """ -// 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 {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "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 {=", - " =}", - "}"); + String testCase = """ + 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 {= + =} + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Cannot connect: Port named 'inp' is already effect of a reaction."); } - + /** - * Allow connection to the port of a contained reactor if another port with same name is effect of a reaction. + * Allow connection to the port of a contained reactor if another port with same name is effect + * of a reaction. */ @Test public void connectionToEffectPort3() throws Exception { -// Java 17: -// String testCase = """ -// 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 {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "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 {=", - " =}", - "}"); + String testCase = """ + 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 {= + =} + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } /** - * Allow connection to the port of a contained reactor if another port with same name is effect of a reaction. + * Allow connection to the port of a contained reactor if another port with same name is effect + * of a reaction. */ @Test public void connectionToEffectPort3_5() throws Exception { -// Java 17: -// String testCase = """ -// 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 {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "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 {=", - " =}", - "}"); + String testCase = """ + 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 {= + =} + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getVariable(), null, - "Main reactor cannot have inputs."); + "Main reactor cannot have inputs."); } /** - * Disallow connection to the port of a contained reactor if the same port is effect of a reaction. + * Disallow connection to the port of a contained reactor if the same port is effect of a + * reaction. */ @Test public void connectionToEffectPort4() throws Exception { -// Java 17: -// String testCase = """ -// target C; - -// reactor Foo { -// input in:int; -// } -// main reactor { -// input in:int; -// x1 = new Foo(); -// in -> x1.in; -// reaction(startup) -> x1.in {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "", - "reactor Foo {", - " input in:int;", - "}", - "main reactor {", - " input in:int;", - " x1 = new Foo();", - " in -> x1.in;", - " reaction(startup) -> x1.in {=", - " =}", - "}"); + String testCase = """ + target C; + + 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(), null, "Cannot connect: Port named 'in' is already effect of a reaction."); } @@ -596,39 +430,22 @@ public void connectionToEffectPort4() throws Exception { */ @Test public void multipleConnectionsToInputTest() throws Exception { -// Java 17: -// 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; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "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;", - "}"); + 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; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Cannot connect: Port named 'in' may only appear once on the right side of a connection."); } @@ -638,146 +455,92 @@ public void multipleConnectionsToInputTest() throws Exception { */ @Test public void detectInstantiationCycle() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// reactor Contained { -// x = new Contained(); -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "reactor Contained {", - " x = new Contained();", - "}"); + String testCase = """ + target C; + reactor Contained { + x = new Contained(); + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, "Instantiation is part of a cycle: Contained"); } - - + + /** * Detect cycles in the instantiation graph. */ @Test public void detectInstantiationCycle2() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// reactor Intermediate { -// x = new Contained(); -// } -// -// reactor Contained { -// x = new Intermediate(); -// } -// """ -// Java 11: - Model model = parseWithoutError(String.join( - System.getProperty("line.separator"), - "target C;", - "reactor Intermediate {", - " x = new Contained();", - "}", - "", - "reactor Contained {", - " x = new Intermediate();", - "}" - )); + String testCase = """ + target C; + reactor Intermediate { + x = new Contained(); + } + reactor Contained { + x = new Intermediate(); + } + """; + + Model model = parseWithoutError(testCase); validator.assertError(model, LfPackage.eINSTANCE.getInstantiation(), null, "Instantiation is part of a cycle: Intermediate, Contained."); validator.assertError(model, LfPackage.eINSTANCE.getInstantiation(), null, "Instantiation is part of a cycle: Intermediate, Contained."); } - + /** * Detect causality loop. */ @Test public void detectCausalityLoop() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// -// 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 -// } -// """ -// Java 11: - Model model = parseWithoutError(String.join( - System.getProperty("line.separator"), - "target C;", - "", - "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", - "}" - )); + + String testCase = """ + target C; + + 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 + } + """; + Model model = parseWithoutError(testCase); validator.assertError(model, LfPackage.eINSTANCE.getReaction(), null, "Reaction triggers involved in cyclic dependency in reactor X: x."); validator.assertError(model, LfPackage.eINSTANCE.getReaction(), - null, "Reaction effects involved in cyclic dependency in reactor X: y."); + null, "Reaction effects involved in cyclic dependency in reactor X: y."); } - + /** * Let cyclic dependencies be broken by "after" clauses. */ @Test public void afterBreaksCycle() throws Exception { -// Java 17: -// String testCase = """ -// target C -// -// 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 -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C", - " ", - "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", - "}"); + String testCase = """ + target C + + 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 + } + """; + validator.assertNoErrors(parseWithoutError(testCase)); } @@ -787,42 +550,23 @@ public void afterBreaksCycle() throws Exception { */ @Test public void afterBreaksCycle2() throws Exception { -// Java 17: -// String testCase = """ -// target C -// -// 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 -// } -// """ -// Java 11: - - String testCase = String.join(System.getProperty("line.separator"), - "target C", - " ", - "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", - "}"); + String testCase = """ + target C + + 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 + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -832,41 +576,23 @@ public void afterBreaksCycle2() throws Exception { */ @Test public void afterBreaksCycle3() throws Exception { -// Java 17: -// String testCase = """ -// target C -// -// 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 -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C", - " ", - "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", - "}"); + String testCase = """ + target C + + 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 + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -875,311 +601,198 @@ public void afterBreaksCycle3() throws Exception { */ @Test public void nonzeroAfterMustHaveUnits() throws Exception { -// Java 17: -// String testCase = """ -// target C -// -// 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 -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C", - " ", - "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", - "}"); + String testCase = """ + target C + + 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 + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Missing time unit."); } - /** * Report non-zero time value without units. */ @Test public void nonZeroTimeValueWithoutUnits() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// main reactor { -// timer t(42, 1 sec); -// reaction(t) {= -// printf("Hello World.\\n"); -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " timer t(42, 1 sec);", - " reaction(t) {=", - " printf(\"Hello World.\\n\");", - " =}", - "}"); + String testCase = """ + 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."); - } - + } + /** * Report reference to non-time parameter in time argument. */ @Test public void parameterTypeMismatch() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// main reactor (p:int(0)) { -// timer t(p, 1 sec); -// reaction(t) {= -// printf("Hello World.\\n"); -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor (p:int(0)) {", - " timer t(p, 1 sec);", - " reaction(t) {=", - " printf(\"Hello World.\\n\");", - " =}", - "}"); + String testCase = """ + 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(), null, "Referenced parameter is not of time type."); } - + /** * Report inappropriate literal in time argument. */ @Test public void targetCodeInTimeArgument() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// main reactor { -// timer t({=foo()=}, 1 sec); -// reaction(t) {= -// printf("Hello World.\\n"); -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " timer t({=foo()=}, 1 sec);", - " reaction(t) {=", - " printf(\"Hello World.\\n\");", - " =}", - "}"); + String testCase = """ + 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."); - } - + } + /** * Report overflowing deadline. */ @Test public void overflowingDeadlineC() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// main reactor { -// timer t; -// reaction(t) {= -// printf("Hello World.\\n"); -// =} deadline (40 hours) {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - "timer t;", - " reaction(t) {=", - " printf(\"Hello World.\\n\");", - " =} deadline (40 hours) {=", - " =}", - "}"); + String testCase = """ + target C; + main reactor { + timer t; + reaction(t) {= + printf("Hello World.\\n"); + =} deadline (40 hours) {= + =} + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), null, "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + - " nanoseconds."); - } + " nanoseconds."); + } + - /** * Report overflowing parameter. */ @Test public void overflowingParameterC() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// main reactor(d:time(40 hours)) { -// timer t; -// reaction(t) {= -// printf("Hello World.\\n"); -// =} deadline (d) {= -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor(d:time(40 hours)) {", - "timer t;", - " reaction(t) {=", - " printf(\"Hello World.\\n\");", - " =} deadline (d) {=", - " =}", - "}"); + String testCase = """ + 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(), null, "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } - - + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } + + /** * Report overflowing assignment. */ @Test public void overflowingAssignmentC() throws Exception { -// Java 17: -// 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); -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "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);", - "}"); + 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); + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAssignment(), null, "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } /** * Report missing trigger. */ @Test public void missingTrigger() throws Exception { -// Java 17: -// String testCase = """ -// target C; -// reactor X { -// reaction() {= -// // -// =} -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "reactor X {", - " reaction() {=", - " //", - " =}", - "}"); + String testCase = """ + target C; + reactor X { + reaction() {= + // + =} + } + """; validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), null, "Reaction has no trigger."); } - + /** - * Test warnings and errors for the target dependent preamble visibility qualifiers + * Test warnings and errors for the target dependent preamble visibility qualifiers */ @Test public void testPreambleVisibility() throws Exception { for (Target target : Target.values()) { for (Visibility visibility : Visibility.values()) { -// Java 17: -// Model model_reactor_scope = """ -// target %s; -// reactor Foo { -// %spreamble {==} -// } -// """.formatted(target, visibility != java.beans.Visibility.NONE ? visibility + " " : ""); -// Java 11: - Model model_reactor_scope = parseWithoutError(String.join(System.getProperty("line.separator"), - String.format("target %s;", target), - "reactor Foo {", - String.format(" %spreamble {==}", visibility != Visibility.NONE ? visibility + " " : ""), - "}")); - -// Java 17: -// Model model_file_scope = """ -// target %s; -// %spreamble {==} -// reactor Foo { -// } -// """.formatted(target, visibility != java.beans.Visibility.NONE ? visibility + " " : ""); -// Java 11: - Model model_file_scope = parseWithoutError(String.join(System.getProperty("line.separator"), - String.format("target %s;", target), - String.format(" %spreamble {==}", visibility != Visibility.NONE ? visibility + " " : ""), - "reactor Foo {", - "}")); - -// Java 17: -// Model model_no_preamble = """ -// target %s; -// reactor Foo { -// } -// """.formatted(target); -// Java 11: - Model model_no_preamble = parseWithoutError(String.join(System.getProperty("line.separator"), - String.format("target %s;", target), - "reactor Foo {", - "}")); - + Model model_reactor_scope = parseWithoutError(""" + target %s; + reactor Foo { + %spreamble {==} + } + """.formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); + + Model model_file_scope = parseWithoutError(""" + target %s; + %spreamble {==} + reactor Foo { + } + """.formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); + + Model model_no_preamble = parseWithoutError(""" + target %s; + reactor Foo { + } + """.formatted(target)); + validator.assertNoIssues(model_no_preamble); - + if (target == Target.CPP) { if (visibility == Visibility.NONE) { validator.assertError(model_file_scope, LfPackage.eINSTANCE.getPreamble(), null, "Preambles for the C++ target need a visibility qualifier (private or public)!"); validator.assertError(model_reactor_scope, LfPackage.eINSTANCE.getPreamble(), null, - "Preambles for the C++ target need a visibility qualifier (private or public)!"); + "Preambles for the C++ target need a visibility qualifier (private or public)!"); } else { validator.assertNoIssues(model_file_scope); validator.assertNoIssues(model_reactor_scope); @@ -1198,46 +811,30 @@ public void testPreambleVisibility() throws Exception { } } } - - + + /** * Tests for state and parameter declarations, including native lists. */ @Test public void stateAndParameterDeclarationsInC() throws Exception { -// Java 17: -// 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 list -// 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 -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "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 list", - " y:int(t) // ERROR: init using parameter", - ") {", - " state offset:time(45); // 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", - "}"); + 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 list + 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); @@ -1261,9 +858,9 @@ public void stateAndParameterDeclarationsInC() throws Exception { "Invalid time value."); validator.assertError(model, LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); - } - - + } + + /** * Recognize valid IPV4 addresses, report invalid ones. */ @@ -1275,69 +872,44 @@ public void recognizeIPV4() throws Exception { // Correct IP addresses. for (String addr : correct) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at foo@%s:4242 { -// y = new Y() at %s:2424; -// } -// """.formatted(addr, addr); -// Java 11: + + String testCase = """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """.formatted(addr, addr); parseWithoutError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at foo@%s:4242 {", addr), - String.format(" y = new Y() at %s:2424; ", addr), - "}") + testCase ); } // IP addresses that don't parse. for (String addr : parseError) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at foo@%s:4242 { -// y = new Y() at %s:2424; -// } -// """.formatted(addr, addr); -// Java 11: - parseWithError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at foo@%s:4242 {", addr), - String.format(" y = new Y() at %s:2424; ", addr), - "}") - ); + String testCase = """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """.formatted(addr, addr); + parseWithError(testCase); } // IP addresses that parse but are invalid. for (String addr : validationError) { -// Java 17: -// Model model = """ -// target C; -// reactor Y {} -// federated reactor X at foo@%s:4242 { -// y = new Y() at %s:2424; -// } -// """.formatted(addr, addr); -// Java 11: - Model model = parseWithoutError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at foo@%s:4242 {", addr), - String.format(" y = new Y() at %s:2424; ", addr), - "}") - ); + Model model = parseWithoutError(""" + 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."); } } - + /** * Recognize valid IPV6 addresses, report invalid ones. */ @@ -1355,160 +927,114 @@ public void recognizeIPV6() throws Exception { "::ffff:0.0.0.0", "::ffff:1.2.3.4", "::ffff:10.0.0.1", "1:2:3:4:5:6:77:88", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "2001:db8:3:4::192.0.2.33", "64:ff9b::192.0.2.33", "0:0:0:0:0:0:10.0.0.1"); - + List validationError = List.of("1:2:3:4:5:6:7:8:9", "1:2:3:4:5:6::7:8", "1:2:3:4:5:6:7:8:", "::1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8::", "1:2:3:4:5:6:7:88888", "2001:db8:3:4:5::192.0.2.33", "fe08::7:8interface", "fe08::7:8interface", "fe08::7:8i"); - + List parseError = List.of("fe08::7:8%", ":1:2:3:4:5:6:7:8"); - + // Correct IP addresses. for (String addr : correct) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at [foo@%s]:4242 { -// y = new Y() at [%s]:2424; -// } -// """.formatted(addr, addr); -// Java 11: - Model model = parseWithoutError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor at [foo@%s]:4242 {", addr), - String.format(" y = new Y() at [%s]:2424; ", addr), - "}") - ); + String testCase = """ + 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); } - + // IP addresses that don't parse. for (String addr : parseError) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at [foo@%s]:4242 { -// y = new Y() at [%s]:2424; -// } -// """.formatted(addr, addr); -// Java 11: - parseWithError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at [foo@%s]:4242 {", addr), - String.format(" y = new Y() at [%s]:2424; ", addr), - "}") - ); + String testCase = """ + target C; + reactor Y {} + federated reactor X at [foo@%s]:4242 { + y = new Y() at [%s]:2424; + } + """.formatted(addr, addr); + parseWithError(testCase); } // IP addresses that parse but are invalid. for (String addr : validationError) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at [foo@%s]:4242 { -// y = new Y() at [%s]:2424; -// } -// """.formatted(addr, addr); -// Java 11: + String testCase = """ + target C; + reactor Y {} + federated reactor X at [foo@%s]:4242 { + y = new Y() at [%s]:2424; + } + """.formatted(addr, addr); Model model = parseWithoutError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at [foo@%s]:4242 {", addr), - String.format(" y = new Y() at [%s]:2424; ", addr), - "}") + testCase ); validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); } } - + /** * Recognize valid host names and fully qualified names, report invalid ones. */ @Test public void recognizeHostNames() throws Exception { - + List correct = List.of("localhost"); // FIXME: add more - + List validationError = List.of("x.y.z"); // FIXME: add more - + List parseError = List.of("..xyz"); // FIXME: add more // Correct names. for (String addr : correct) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at foo@%s:4242 { -// y = new Y() at %s:2424; -// } -// """.formatted(addr, addr); -// Java 11: + String testCase = """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """.formatted(addr, addr); parseWithoutError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at foo@%s:4242 {", addr), - String.format(" y = new Y() at %s:2424; ", addr), - "}") + testCase ); } - + // Names that don't parse. for (String addr : parseError) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at foo@%s:4242 { -// y = new Y() at %s:2424; -// } -// """.formatted(addr, addr); -// Java 11: + String testCase = """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """.formatted(addr, addr); parseWithError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at foo@%s:4242 {", addr), - String.format(" y = new Y() at %s:2424; ", addr), - "}") + testCase ); } - + // Names that parse but are invalid. for (String addr : validationError) { -// Java 17: -// String testCase = """ -// target C; -// reactor Y {} -// federated reactor X at foo@%s:4242 { -// y = new Y() at %s:2424; -// } -// """.formatted(addr, addr); -// Java 11: + String testCase = """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """.formatted(addr, addr); Model model = parseWithoutError( - String.join(System.getProperty("line.separator"), - "target C;", - "reactor Y {}", - String.format("federated reactor X at foo@%s:4242 {", addr), - String.format(" y = new Y() at %s:2424; ", addr), - "}") + testCase ); - validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, + validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid host name or fully qualified domain name."); } } - + /** * Maps a type to a list of known good values. */ @@ -1533,7 +1059,7 @@ public void recognizeHostNames() throws Exception { ); /** - * Maps a type to a list, each entry of which represents a list with + * Maps a type to a list, each entry of which represents a list with * three entries: a known wrong value, the suffix to add to the reported * name, and the type that it should be. */ @@ -1575,13 +1101,14 @@ public void recognizeHostNames() throws Exception { List.of("{trace-file-name: [1, 2, 3]}", ".trace-file-name", PrimitiveType.STRING) ) ); - + /** - * Given an array type, return a list of good or bad examples, + * Given an array type, return a list of good or bad examples, * depending on the value of the second parameter. */ private List synthesizeExamples(ArrayType type, boolean correct) { - Map> values = correct ? primitiveTypeToKnownGood : primitiveTypeToKnownBad; + Map> values = correct ? primitiveTypeToKnownGood + : primitiveTypeToKnownBad; List examples = new LinkedList<>(); if (correct) { // Produce an array that has an entry for each value. @@ -1592,9 +1119,9 @@ private List synthesizeExamples(ArrayType type, boolean correct) { } return examples; } - + /** - * Given an union type, return a list of good or bad examples, + * Given an union type, return a list of good or bad examples, * depending on the value of the second parameter. */ private List synthesizeExamples(UnionType type, boolean correct) { @@ -1610,15 +1137,15 @@ private List synthesizeExamples(UnionType type, boolean correct) { } else { // Return some obviously bad examples for the common // case where the options are from an ordinary Enum. - if (!type.options.stream().anyMatch(it -> (it instanceof TargetPropertyType))) { + if (!type.options.stream().anyMatch(it -> it instanceof TargetPropertyType)) { return List.of("foo", "\"bar\"", "1", "-1", "{x: 42}", "[1, 2, 3]"); } } return examples; } - + /** - * Given an union type, return a list of good or bad examples, + * Given an union type, return a list of good or bad examples, * depending on the value of the second parameter. */ private List synthesizeExamples(DictionaryType type, boolean correct) { @@ -1626,7 +1153,8 @@ private List synthesizeExamples(DictionaryType type, boolean correct) { // Produce a set of singleton dictionaries. // If incorrect examples are wanted, garble the key. for (DictionaryElement option : type.options) { - synthesizeExamples(option.getType(), correct).forEach(it -> examples.add("{" + option + (!correct ? "iamwrong: " : ": ") + it + "}")); + synthesizeExamples(option.getType(), correct).forEach(it -> examples.add( + "{" + option + (!correct ? "iamwrong: " : ": ") + it + "}")); } return examples; } @@ -1649,23 +1177,24 @@ private List synthesizeExamples(StringDictionaryType type, boolean corre } return examples; } - + /** * Synthesize a list of values that either conform to the given type or * do not, depending on whether the second argument 'correct' is true. - * Return an empty set if it is too complicated to generate examples + * Return an empty set if it is too complicated to generate examples * (e.g., because the resulting errors are more sophisticated). - * + *

* Not all cases are covered by this function. Currently, the only cases not * covered are known bad examples for composite types, which should be added * to the compositeTypeToKnownBad map. - * + * * @param correct True to synthesize correct examples automatically, otherwise - * synthesize incorrect examples. + * synthesize incorrect examples. */ private List synthesizeExamples(TargetPropertyType type, boolean correct) { if (type instanceof PrimitiveType) { - Map> values = correct ? primitiveTypeToKnownGood : primitiveTypeToKnownBad; + Map> values = correct ? primitiveTypeToKnownGood + : primitiveTypeToKnownBad; List examples = values.get(type); Assertions.assertNotNull(examples); return examples; @@ -1684,29 +1213,21 @@ private List synthesizeExamples(TargetPropertyType type, boolean correct } return new LinkedList<>(); } - + /** * Create an LF program with the given key and value as a target property, * parse it, and return the resulting model. */ private Model createModel(TargetProperty key, String value) throws Exception { String target = key.supportedBy.get(0).getDisplayName(); - System.out.println(String.format("%s: %s", key, value)); -// Java 17: -// Model model = """ -// target %s {%s: %s}; -// reactor Y {} -// main reactor { -// y = new Y() -// } -// """.formatted(target, key, value); -// Java 11: - return parseWithoutError(String.join(System.getProperty("line.separator"), - String.format("target %s {%s: %s};", target, key, value), - "reactor Y {}", - "main reactor {", - " y = new Y() ", - "}")); + System.out.printf("%s: %s%n", key, value); + return parseWithoutError(""" + target %s {%s: %s}; + reactor Y {} + main reactor { + y = new Y() + } + """.formatted(target, key, value)); } /** @@ -1719,21 +1240,21 @@ public void checkTargetProperties() throws Exception { // we test that separately as it has better error messages return; } - System.out.println(String.format("Testing target property %s which is %s", prop, prop.type)); + System.out.printf("Testing target property %s which is %s%n", prop, prop.type); System.out.println("===="); System.out.println("Known good assignments:"); List knownCorrect = synthesizeExamples(prop.type, true); - + for (String it : knownCorrect) { Model model = createModel(prop, it); validator.assertNoErrors(model); // Also make sure warnings are produced when files are not present. if (prop.type == PrimitiveType.FILE) { validator.assertWarning(model, LfPackage.eINSTANCE.getKeyValuePair(), - null, String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); + null, String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); } } - + // Extra checks for filenames. (This piece of code was commented out in the original xtend file) // Temporarily disabled because we need a more sophisticated check that looks for files in different places. // if (prop.type == prop.type == ArrayType.FILE_ARRAY || @@ -1746,35 +1267,35 @@ public void checkTargetProperties() throws Exception { // null, '''Could not find file: '«it.withoutQuotes»'.''') // ] // } - + System.out.println("Known bad assignments:"); List knownIncorrect = synthesizeExamples(prop.type, false); if (!(knownIncorrect == null || knownIncorrect.isEmpty())) { for (String it : knownIncorrect) { if (prop.type instanceof StringDictionaryType) { validator.assertError(createModel(prop, it), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s.", prop), "' is required to be a string."); + LfPackage.eINSTANCE.getKeyValuePair(), null, + String.format("Target property '%s.", prop), "' is required to be a string."); } else { validator.assertError(createModel(prop, it), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s' is required to be %s.", prop.toString(), prop.type)); + LfPackage.eINSTANCE.getKeyValuePair(), null, + String.format("Target property '%s' is required to be %s.", prop, prop.type)); } } } else { // No type was synthesized. It must be a composite type. List> list = compositeTypeToKnownBad.get(prop.type); if (list == null) { - System.out.println(String.format("No known incorrect values provided for target property '%s'. Aborting test.", prop)); - Assertions.assertTrue(false); + System.out.printf("No known incorrect values provided for target property '%s'. Aborting test.%n", prop); + Assertions.fail(); } else { for (List it : list) { validator.assertError(createModel(prop, it.get(0).toString()), LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s%s' is required to be %s.", prop.toString(), it.get(1), it.get(2))); + String.format("Target property '%s%s' is required to be %s.", prop, it.get(1), it.get(2))); } } - } + } System.out.println("===="); } System.out.println("Done!"); @@ -1793,7 +1314,7 @@ public void checkCargoDependencyProperty() throws Exception { validator.assertError(createModel(prop, "{ dep: {/*empty*/} }"), LfPackage.eINSTANCE.getKeyValuePairs(), null, "Must specify one of 'version', 'path', or 'git'" ); - + // vvvvvvvvvvv validator.assertError(createModel(prop, "{ dep: { unknown_key: \"\"} }"), LfPackage.eINSTANCE.getKeyValuePair(), null, "Unknown key: 'unknown_key'" @@ -1884,358 +1405,228 @@ public void testUnusedImport() throws Exception { @Test public void testMissingInputType() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // input i; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " input i;", - "}" - ); + String testCase = """ + target C; + main reactor { + input i; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Input must have a type."); } @Test public void testMissingOutputType() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // output i; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " output i;", - "}" - ); + String testCase = """ + target C; + main reactor { + output i; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Output must have a type."); } @Test public void testMissingStateType() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // state i; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " state i;", - "}" - ); + String testCase = """ + target C; + main reactor { + state i; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "State must have a type."); } @Test public void testListWithParam() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor (A:int(1)) { state i:int(A, 2, 3) } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor (A:int(1)) { state i:int(A, 2, 3) }" - ); + String testCase = """ + target C; + main reactor (A:int(1)) { state i:int(A, 2, 3) } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "List items cannot refer to a parameter."); } @Test public void testCppMutableInput() throws Exception { - // Java 17: - // String testCase = """ - // target Cpp; - // main reactor { - // mutable input i:int; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target Cpp;", - "main reactor {", - " mutable input i:int;", - "}" - ); + String testCase = """ + target Cpp; + main reactor { + mutable input i:int; + } + """; validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "The mutable qualifier has no meaning for the C++ target and should be removed. " + - "In C++, any value can be made mutable by calling get_mutable_copy()."); + "In C++, any value can be made mutable by calling get_mutable_copy()."); } @Test public void testOverflowingSTP() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // reaction(startup) {==} STP(2147483648) {==} - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " reaction(startup) {==} STP(2147483648) {==}", - "}" - ); + String testCase = """ + 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, - // "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + // "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); } @Test public void testOverflowingDeadline() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // reaction(startup) {==} STP(2147483648) {==} - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " reaction(startup) {==} deadline(2147483648) {==}", - "}" - ); + String testCase = """ + 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, - // "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + // "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); } @Test public void testInvalidTargetParam() throws Exception { - // Java 17: - // String testCase = """ - // target C { beefyDesktop: true } - // main reactor {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C { beefyDesktop: true }", - "main reactor {}" - ); + String testCase = """ + target C { beefyDesktop: true } + main reactor {} + """; List issues = validator.validate(parseWithoutError(testCase)); - Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains("Unrecognized target parameter: beefyDesktop")); + Assertions.assertTrue(issues.size() == 1 + && issues.get(0).getMessage().contains("Unrecognized target parameter: beefyDesktop")); } @Test public void testTargetParamNotSupportedForTarget() throws Exception { - // Java 17: - // String testCase = """ - // target Python { build: "" } - // main reactor {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target Python { build: \"\" }", - "main reactor {}" - ); + String testCase = """ + target Python { build: "" } + main reactor {} + """; List issues = validator.validate(parseWithoutError(testCase)); - Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains("The target parameter: build" + - " is not supported by the Python target and will thus be ignored.")); + Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains( + "The target parameter: build" + + " is not supported by the Python target and will thus be ignored.")); } @Test public void testUnnamedReactor() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // reactor {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "reactor {}" - ); + String testCase = """ + target C; + reactor {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Reactor must be named."); } @Test public void testMainHasInput() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // input x:int; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " input x:int;", - "}" - ); + String testCase = """ + target C; + main reactor { + input x:int; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Main reactor cannot have inputs."); } @Test public void testFederatedHasInput() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // federated reactor { - // input x:int; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "federated reactor {", - " input x:int;", - "}" - ); + + String testCase = """ + target C; + federated reactor { + input x:int; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Main reactor cannot have inputs."); } @Test public void testMainHasOutput() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor { - // output x:int; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {", - " output x:int;", - "}" - ); + + String testCase = """ + target C; + main reactor { + output x:int; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Main reactor cannot have outputs."); } @Test public void testFederatedHasOutput() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // federated reactor { - // output x:int; - // } - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "federated reactor {", - " output x:int;", - "}" - ); + + String testCase = """ + target C; + federated reactor { + output x:int; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Main reactor cannot have outputs."); } @Test public void testMultipleMainReactor() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor A {} - // main reactor A {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor A {}", - "main reactor A {}" - ); + + String testCase = """ + target C; + main reactor A {} + main reactor A {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMultipleMainReactorUnnamed() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor {} - // main reactor {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor {}", - "main reactor {}" - ); + + String testCase = """ + target C; + main reactor {} + main reactor {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMultipleFederatedReactor() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // federated reactor A {} - // federated reactor A {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "federated reactor A {}", - "federated reactor A {}" - ); + String testCase = """ + target C; + federated reactor A {} + federated reactor A {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMultipleMainOrFederatedReactor() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // federated reactor A {} - // federated reactor A {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor A {}", - "federated reactor A {}" - ); + + String testCase = """ + target C; + federated reactor A {} + federated reactor A {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMainReactorHasHost() throws Exception { - // Java 17: - // String testCase = """ - // target C; - // main reactor at 127.0.0.1{} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target C;", - "main reactor at 127.0.0.1{}" - ); + String testCase = """ + 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 && @@ -2245,16 +1636,11 @@ public void testMainReactorHasHost() throws Exception { @Test public void testUnrecognizedTarget() throws Exception { - // Java 17: - // String testCase = """ - // target Pjthon; - // main reactor {} - // """ - // Java 11: - String testCase = String.join(System.getProperty("line.separator"), - "target Pjthon;", - "main reactor {}" - ); + + String testCase = """ + target Pjthon; + main reactor {} + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTargetDecl(), null, "Unrecognized target: Pjthon"); } @@ -2296,132 +1682,132 @@ public void testWrongParamType() throws Exception { @Test 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(), null, - "Every modal reactor requires one initial mode."); + "Every modal reactor requires one initial mode."); } @Test 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(), null, - "A modal reactor can only have one initial mode."); + "A modal reactor can only have one initial mode."); } @Test 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(), null, - "Duplicate state variable 's'. (State variables are currently scoped on reactor level not modes)"); + "Duplicate state variable 's'. (State variables are currently scoped on reactor level not modes)"); } @Test 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(), null, - "Duplicate Timer 't'. (Timers are currently scoped on reactor level not modes)"); + "Duplicate Timer 't'. (Timers are currently scoped on reactor level not modes)"); } @Test 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(), null, - "Duplicate Action 'a'. (Actions are currently scoped on reactor level not modes)"); + "Duplicate Action 'a'. (Actions are currently scoped on reactor level not modes)"); } @Test 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(), null, - "Duplicate Instantiation 'r'. (Instantiations are currently scoped on reactor level not modes)"); + "Duplicate Instantiation 'r'. (Instantiations are currently scoped on reactor level not modes)"); } @Test 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(), null, - "State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction."); + "State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction."); } @Test public void testMissingModeStateResetInstance() throws Exception { String testCase = """ - target C; - reactor R { - state s:int(0); - } - main reactor { - initial mode IM { - reaction(startup) -> M {==} + target C; + reactor R { + state s:int(0); } - mode M { - r = new R(); + main reactor { + initial mode IM { + reaction(startup) -> M {==} + } + mode M { + r = new R(); + } } - } - """; + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), null, - "This reactor contains state variables that are not reset upon mode entry: " + "This reactor contains state variables that are not reset upon mode entry: " + "s in R" + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " + "It is usafe to instatiate this reactor inside a mode entered with reset."); @@ -2430,13 +1816,13 @@ public void testMissingModeStateResetInstance() throws Exception { @Test 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(), null, "The state variable can not be automatically reset without an initial value."); } @@ -2444,18 +1830,18 @@ public void testModeStateResetWithoutInitialValue() throws Exception { @Test 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(), null, - "You should specifiy a transition type! " + "You should specifiy a transition type! " + "Reset and history transitions have different effects on this target mode. " + "Currently, a reset type is implicitly assumed."); } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java index d1ea81e5be..24cb3554ff 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java @@ -3,6 +3,7 @@ import static java.util.Collections.emptyList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; import java.nio.file.Files; import java.nio.file.Path; @@ -28,11 +29,15 @@ public class RoundTripTests { @Test - public void roundTripTest() throws Exception { + public void roundTripTest() { for (Target target : Target.values()) { for (TestCategory category : TestCategory.values()) { for (LFTest test : TestRegistry.getRegisteredTests(target, category, false)) { - run(test.getSrcPath()); + try { + run(test.getSrcPath()); + } catch (Throwable thrown) { + fail("Test case " + test.getSrcPath() + " failed", thrown); + } } } } diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index fc49242322..b4c63ac337 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -254,6 +254,14 @@ public static boolean changeTargetName(Resource resource, String newTargetName) return true; } + /** + * Return the target of the file in which the given node lives. + */ + public static Target getTarget(EObject object) { + TargetDecl targetDecl = targetDecl(object.eResource()); + return Target.fromDecl(targetDecl); + } + /** * Add a new target property to the given resource. * diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 870b1ad049..2525f2f710 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -140,7 +140,7 @@ TargetDecl: Initializer: parens?='(' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? ')' | braces?='{' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? '}' -// | assign?='=' exprs+=Expression // todo later + | assign?='=' exprs+=Expression ; @@ -292,13 +292,15 @@ VarRefOrModeTransition returns VarRef: Assignment: lhs=[Parameter] - (equals='=')? rhs=AssignmentInitializer + rhs=AssignmentInitializer ; -// TODO Only allow = based parameter assignment AssignmentInitializer returns Initializer: - exprs+=Expression - | parens?='(' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? ')' + assign?='=' exprs+=Expression + // these syntaxes are legacy and now deprecated + // todo remove in future version. + | '='? parens?='(' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? ')' + // note: the previous syntax `= { expr* }` is now parsed as a BracedListExpression | braces?='{' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? '}' ; @@ -317,6 +319,13 @@ Expression: | Time | ParameterReference | {CodeExpr} code=Code + | BracedListExpression +; + +// A list of expressions within braces. +// In C/C++, this is an array initializer, struct initializer, or std::initializer_list. +BracedListExpression: + '{' {BracedListExpression} (items+=Expression (',' items+=Expression)*)? ','? '}' ; ParameterReference: diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/src/org/lflang/Target.java index 4842bc1672..11247b6648 100644 --- a/org.lflang/src/org/lflang/Target.java +++ b/org.lflang/src/org/lflang/Target.java @@ -486,9 +486,7 @@ public boolean supportsMultiports() { * on constants). */ public boolean supportsParameterizedWidths() { - return switch (this) { - case C, CCPP, CPP, Python, Rust, TS -> true; - }; + return true; } /** @@ -502,6 +500,20 @@ public boolean buildsUsingDocker() { }; } + /** + * Whether the target requires using an equal sign to assign a default value to a parameter, + * or initialize a state variable. All targets mandate an equal sign when passing + * arguments to a reactor constructor call, regardless of this method. + */ + public boolean mandatesEqualsInitializers() { + return this != CPP; + } + + /** Allow expressions of the form {@code {a, b, c}}. */ + public boolean allowsBracedListExpressions() { + return this == C || this == CCPP || this == CPP; + } + /** * Return a string that demarcates the beginning of a single-line comment. */ diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 93c2074829..e18eea02bd 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -16,6 +16,7 @@ import org.lflang.lf.Assignment; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; +import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Code; import org.lflang.lf.CodeExpr; @@ -416,7 +417,6 @@ public Boolean caseVarRef(VarRef object) { public Boolean caseAssignment(Assignment object) { return new ComparisonMachine<>(object, Assignment.class) .equivalent(Assignment::getLhs) - .equalAsObjects(Assignment::getEquals) .equivalent(Assignment::getRhs) .conclusion; } @@ -438,10 +438,18 @@ public Boolean caseExpression(Expression object) { Literal.class, Time.class, ParameterReference.class, - Code.class + Code.class, + BracedListExpression.class ); } + @Override + public Boolean caseBracedListExpression(BracedListExpression object) { + return new ComparisonMachine<>(object, BracedListExpression.class) + .listsEquivalent(BracedListExpression::getItems) + .conclusion; + } + @Override public Boolean caseParameterReference(ParameterReference object) { return new ComparisonMachine<>(object, ParameterReference.class) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 50722d19eb..be8a68cf7d 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -21,6 +21,7 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.xbase.lib.StringExtensions; import org.lflang.ASTUtils; +import org.lflang.Target; import org.lflang.ast.MalleableString.Builder; import org.lflang.ast.MalleableString.Joiner; import org.lflang.lf.Action; @@ -29,6 +30,7 @@ import org.lflang.lf.Assignment; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; +import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Code; import org.lflang.lf.CodeExpr; @@ -46,6 +48,7 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; +import org.lflang.lf.LfFactory; import org.lflang.lf.Literal; import org.lflang.lf.Method; import org.lflang.lf.MethodArgument; @@ -479,7 +482,7 @@ public MalleableString caseStateVar(StateVar object) { } msb.append("state ").append(object.getName()); msb.append(typeAnnotationFor(object.getType())); - msb.append(initializer(object.getInit(), true)); + msb.append(initializer(object.getInit())); return msb.get(); } @@ -794,7 +797,9 @@ public MalleableString caseSerializer(Serializer object) { @Override public MalleableString caseKeyValuePairs(KeyValuePairs object) { // {KeyValuePairs} '{' (pairs+=KeyValuePair (',' (pairs+=KeyValuePair))* ','?)? '}' - if (object.getPairs().isEmpty()) return MalleableString.anyOf(""); + if (object.getPairs().isEmpty()) { + return MalleableString.anyOf(""); + } return new Builder() .append("{\n") .append(list(",\n", "", "\n", true, true, object.getPairs()).indent()) @@ -802,6 +807,16 @@ public MalleableString caseKeyValuePairs(KeyValuePairs object) { .get(); } + @Override + public MalleableString caseBracedListExpression(BracedListExpression object) { + if (object.getItems().isEmpty()) { + return MalleableString.anyOf("{}"); + } + // Note that this strips the trailing comma. There is no way + // to implement trailing commas with the current set of list() methods AFAIU. + return list(", ", "{", "}", false, false, object.getItems()); + } + @Override public MalleableString caseKeyValuePair(KeyValuePair object) { // name=Kebab ':' value=Element @@ -856,35 +871,52 @@ public MalleableString caseAssignment(Assignment object) { // )); Builder msb = new Builder(); msb.append(object.getLhs().getName()); - if (object.getEquals() != null) { - msb.append(" = "); - } - msb.append(initializer(object.getRhs(), false)); + msb.append(initializer(object.getRhs())); return msb.get(); } @Override public MalleableString caseInitializer(Initializer object) { - return initializer(object, false); + return initializer(object); } - private MalleableString initializer(Initializer init, boolean nothingIfEmpty) { + /** + * Return true if the initializer should be output with an equals initializer. + * Old-style assignments with parentheses are also output that + * way to help with the transition. + */ + private boolean shouldOutputAsAssignment(Initializer init) { + return init.isAssign() + || init.getExprs().size() == 1 && ASTUtils.getTarget(init).mandatesEqualsInitializers(); + } + + private MalleableString initializer(Initializer init) { if (init == null) { return MalleableString.anyOf(""); } + if (shouldOutputAsAssignment(init)) { + Expression expr = ASTUtils.asSingleExpr(init); + Objects.requireNonNull(expr); + return new Builder().append(" = ").append(doSwitch(expr)).get(); + } + if (ASTUtils.getTarget(init) == Target.C) { + // This turns C array initializers into a braced expression. + // C++ variants are not converted. + BracedListExpression list = LfFactory.eINSTANCE.createBracedListExpression(); + list.getItems().addAll(init.getExprs()); + return new Builder().append(" = ").append(doSwitch(list)).get(); + } String prefix; String suffix; if (init.isBraces()) { prefix = "{"; suffix = "}"; - } else if (init.isParens()) { + } else { + assert init.isParens(); prefix = "("; suffix = ")"; - } else { - // unparenthesized parameter assignment. - prefix = suffix = ""; } - return list(", ", prefix, suffix, nothingIfEmpty, false, init.getExprs()); + return list(", ", prefix, suffix, false, false, init.getExprs()); } @@ -899,7 +931,7 @@ public MalleableString caseParameter(Parameter object) { return builder .append(object.getName()) .append(typeAnnotationFor(object.getType())) - .append(initializer(object.getInit(), true)) + .append(initializer(object.getInit())) .get(); } diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index ad9a40c95b..0b703ccbe8 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -10,6 +10,7 @@ import org.lflang.ASTUtils; import org.lflang.lf.ArraySpec; +import org.lflang.lf.BracedListExpression; import org.lflang.lf.Code; import org.lflang.lf.CodeExpr; import org.lflang.lf.Host; @@ -78,6 +79,11 @@ public String caseCode(Code code) { return ""; } + @Override + public String caseBracedListExpression(BracedListExpression object) { + return ToLf.instance.caseBracedListExpression(object).toString(); + } + @Override public String caseHost(Host host) { return ToLf.instance.caseHost(host).toString(); diff --git a/org.lflang/src/org/lflang/cli/Lff.java b/org.lflang/src/org/lflang/cli/Lff.java index 0eeeea6785..1efc207128 100644 --- a/org.lflang/src/org/lflang/cli/Lff.java +++ b/org.lflang/src/org/lflang/cli/Lff.java @@ -51,7 +51,7 @@ public class Lff extends CliBase { @Option( names = "--no-recurse", description = "Do not format files in subdirectories of the" - + " specified paths.") + + " specified paths.") private boolean noRecurse = false; @Option( @@ -59,6 +59,11 @@ public class Lff extends CliBase { description = "Print more details on files affected.") private boolean verbose = false; + @Option( + names = {"--ignore-errors"}, + description = "Ignore validation errors in files and format them anyway.") + private boolean ignoreErrors = false; + /** * Main function of the formatter. * Caution: this will invoke System.exit. @@ -147,12 +152,13 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { if (verbose) { reporter.printInfo("Skipped " + path + ": not an LF file"); } - return; + return; } validateResource(resource); - // todo don't abort whole run if one file has errors - exitIfCollectedErrors(); + if (!ignoreErrors) { + exitIfCollectedErrors(); + } final String formattedFileContents = FormattingUtils.render(resource.getContents().get(0), lineLength); @@ -163,24 +169,30 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { FileUtil.writeToFile(formattedFileContents, outputPath, true); } catch (IOException e) { if (e instanceof FileAlreadyExistsException) { - // Only happens if a subdirectory is named with + // Only happens if a subdirectory is named with // ".lf" at the end. reporter.printFatalErrorAndExit( "Error writing to " + outputPath - + ": file already exists. Make sure that no file or" + + ": file already exists. Make sure that no file or" + " directory within provided input paths have the" + " same relative paths."); } } } - exitIfCollectedErrors(); - issueCollector.getAllIssues().forEach(reporter::printIssue); + if (!ignoreErrors) { + exitIfCollectedErrors(); + } + // Only errors are printed. Warnings are not helpful for LFF + // and since they don't prevent the file from being formatted, + // the position of the issue may be wrong in the formatted file. + // issueCollector.getAllIssues().forEach(reporter::printIssue); if (verbose) { String msg = "Formatted " + io.getWd().relativize(path); - if (path != outputPath) msg += - " -> " + io.getWd().relativize(outputPath); + if (path != outputPath) { + msg += " -> " + io.getWd().relativize(outputPath); + } reporter.printInfo(msg); } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index cd013d6c57..1497ee6644 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -66,6 +66,7 @@ import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.ast.FormattingUtils; +import org.lflang.ast.ToText; import org.lflang.diagram.synthesis.action.CollapseAllReactorsAction; import org.lflang.diagram.synthesis.action.ExpandAllReactorsAction; import org.lflang.diagram.synthesis.action.FilterCycleAction; @@ -1187,12 +1188,12 @@ private String createParameterLabel(ParameterInstance param) { b.append(param.getName()); String t = param.type.toOriginalText(); if (!StringExtensions.isNullOrEmpty(t)) { - b.append(":").append(t); + b.append(": ").append(t); } - if (!IterableExtensions.isNullOrEmpty(param.getInitialValue())) { - b.append("("); - b.append(IterableExtensions.join(param.getInitialValue(), ", ", ASTUtils::toOriginalText)); - b.append(")"); + if (param.getOverride() != null) { + b.append(" = "); + var init = param.getActualValue(); + b.append(FormattingUtils.render(init)); } return b.toString(); } diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index fda727d735..a2ac48216f 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -48,19 +48,16 @@ import org.lflang.federated.launcher.RtiConfig; import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CTypes; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.VarRef; -import org.lflang.util.FileUtil; /** * An extension class to the CGenerator that enables certain federated @@ -170,7 +167,7 @@ protected void deserialize( CodeBuilder result, ErrorReporter errorReporter ) { - CTypes types = new CTypes(errorReporter); + CTypes types = new CTypes(); // Adjust the type of the action and the receivingPort. // If it is "string", then change it to "char*". // This string is dynamically allocated, and type 'string' is to be @@ -338,7 +335,7 @@ protected void serializeAndSend( String commonArgs, ErrorReporter errorReporter ) { - CTypes types = new CTypes(errorReporter); + CTypes types = new CTypes(); var lengthExpression = ""; var pointerExpression = ""; switch (connection.getSerializer()) { @@ -424,7 +421,7 @@ public String generateNetworkInputControlReactionBody( // Find the maximum STP for decentralized coordination if(coordination == CoordinationType.DECENTRALIZED) { - result.pr("max_STP = "+ GeneratorBase.timeInTargetLanguage(maxSTP)+";"); + result.pr("max_STP = "+ CTypes.getInstance().getTargetTimeExpr(maxSTP) +";"); } result.pr("// Wait until the port status is known"); result.pr("wait_until_port_status_known("+receivingPortID+", max_STP);"); @@ -617,7 +614,7 @@ private String generateCodeToInitializeFederate(FederateInstance federate, RtiCo if (stpParam.isPresent()) { var globalSTP = ASTUtils.initialValue(stpParam.get(), List.of(federate.instantiation)).get(0); var globalSTPTV = ASTUtils.getLiteralTimeValue(globalSTP); - code.pr("lf_set_stp_offset("+ CGenerator.timeInTargetLanguage(globalSTPTV)+");"); + code.pr("lf_set_stp_offset("+ CTypes.getInstance().getTargetTimeExpr(globalSTPTV) +");"); } } @@ -742,7 +739,7 @@ private String generateCodeForPhysicalActions(FederateInstance federate, ErrorRe } code.pr( "_fed.min_delay_from_physical_action_to_federate_output = " - + GeneratorBase.timeInTargetLanguage(minDelay) + ";"); + + CTypes.getInstance().getTargetTimeExpr(minDelay) + ";"); } } return code.getCode(); diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index aabc77ecd5..124ffefb4f 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -430,16 +430,16 @@ public static String generateFederateNeighborStructure(FederateInstance federate // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { - var delayTime = GeneratorBase.getTargetTime(delay); - if (delay instanceof ParameterReference) { - // The delay is given as a parameter reference. Find its value. - final var param = ((ParameterReference)delay).getParameter(); - delayTime = GeneratorBase.timeInTargetLanguage(ASTUtils.getDefaultAsTimeValue(param)); - } + var delayTime = + delay instanceof ParameterReference + // In that case use the default value. + ? CTypes.getInstance().getTargetTimeExpr(ASTUtils.getDefaultAsTimeValue(((ParameterReference) delay).getParameter())) + : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); + code.pr(String.join("\n", - "if ("+delayTime+" < candidate_tmp) {", - " candidate_tmp = "+delayTime+";", - "}" + "if (" + delayTime + " < candidate_tmp) {", + " candidate_tmp = " + delayTime + ";", + "}" )); } } diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index ca8ce4dd9c..e438b1b866 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -11,7 +11,6 @@ import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; -import org.lflang.Target; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; import org.lflang.federated.generator.FedASTUtils; @@ -22,7 +21,7 @@ import org.lflang.generator.GeneratorBase; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.ts.TSExtensionsKt; +import org.lflang.generator.ts.TSTypes; import org.lflang.lf.Action; import org.lflang.lf.Expression; import org.lflang.lf.Output; @@ -118,7 +117,7 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf .collect(Collectors.joining(",")), federate.id, minOutputDelay == null ? "undefined" - : "%s".formatted(TSExtensionsKt.toTsTime(minOutputDelay)), + : "%s".formatted(TSTypes.getInstance().getTargetTimeExpr(minOutputDelay)), federate.networkMessageActions .stream() .map(Variable::getName) diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index f3768cec7c..14b6320bec 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -75,17 +75,17 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import com.google.common.base.Objects; -/** +/** * Instance of a federate, or marker that no federation has been defined * (if isSingleton() returns true) FIXME: this comment makes no sense. * Every top-level reactor (contained * directly by the main reactor) is a federate, so there will be one * instance of this class for each top-level reactor. - * + * * @author Edward A. Lee * @author Soroush Bateni */ -public class FederateInstance { +public class FederateInstance { // why does this not extend ReactorInstance? /** * Construct a new instance with the specified instantiation of diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/src/org/lflang/generator/CodeMap.java index 12d5ea8f65..d00fe9bc9a 100644 --- a/org.lflang/src/org/lflang/generator/CodeMap.java +++ b/org.lflang/src/org/lflang/generator/CodeMap.java @@ -17,6 +17,7 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.util.LineAndColumn; +import org.lflang.lf.ParameterReference; import org.lflang.lf.impl.ParameterReferenceImpl; /** @@ -147,6 +148,10 @@ public static String tag(EObject astNode, String representation, boolean verbati oneBasedLfLineAndColumn.getLine(), oneBasedLfLineAndColumn.getColumn() ); final URI uri = bestEffortGetEResource(astNode).getURI(); + if (uri == null) { + // no EResource, no correspondence can be found + return representation; + } final Path lfPath = Path.of(uri.isFile() ? uri.toFileString() : uri.path()); if (verbatim) lfStart = lfStart.plus(node.getText().substring(0, indexOf(node.getText(), representation))); return new Correspondence( @@ -162,12 +167,10 @@ public static String tag(EObject astNode, String representation, boolean verbati * This is a dangerous operation which can cause an unrecoverable error. */ private static Resource bestEffortGetEResource(EObject astNode) { - if (astNode instanceof ParameterReferenceImpl pri) return pri.getParameter().eResource(); - Resource ret = astNode.eResource(); - if (ret != null) return ret; - throw new RuntimeException( - "Every non-null AST node should have an EResource, but \"" + astNode + "\" does not." - ); + if (astNode instanceof ParameterReference pri) { + return pri.getParameter().eResource(); + } + return astNode.eResource(); } /** diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ef35d22be1..ba39a94d9f 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -47,19 +47,15 @@ import org.lflang.MainConflictChecker; import org.lflang.Target; import org.lflang.TargetConfig; -import org.lflang.TimeUnit; -import org.lflang.TimeValue; import org.lflang.ast.AstTransformation; import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Connection; -import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; -import org.lflang.lf.Time; import org.lflang.validation.AbstractLFValidator; import com.google.common.base.Objects; @@ -418,33 +414,6 @@ public int getReactionBankIndex(Reaction reaction) { return reactionBankIndices.get(reaction); } - /** - * Given a representation of time that may possibly include units, return - * a string that the target language can recognize as a value. In this base - * class, if units are given, e.g. "msec", then we convert the units to upper - * case and return an expression of the form "MSEC(value)". Particular target - * generators will need to either define functions or macros for each possible - * time unit or override this method to return something acceptable to the - * target language. - * @param time A TimeValue that represents a time. - * @return A string, such as "MSEC(100)" for 100 milliseconds. - */ - public static String timeInTargetLanguage(TimeValue time) { - if (time != null) { - if (time.unit != null) { - return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; - } else { - return Long.valueOf(time.getMagnitude()).toString(); - } - } - return "0"; // FIXME: do this or throw exception? - } - - // note that this is moved out by #544 - public static String cMacroName(TimeUnit unit) { - return unit.getCanonicalName().toUpperCase(); - } - // ////////////////////////////////////////// // // Protected methods. @@ -674,50 +643,4 @@ public void printInfo(LFGeneratorContext.Mode mode) { */ public abstract Target getTarget(); - /** - * Get textual representation of a time in the target language. - * - * @param t A time AST node - * @return A time string in the target language - */ - // FIXME: this should be placed in ExpressionGenerator - public static String getTargetTime(Time t) { - TimeValue value = new TimeValue(t.getInterval(), TimeUnit.fromName(t.getUnit())); - return timeInTargetLanguage(value); - } - - /** - * Get textual representation of a value in the target language. - * - * If the value evaluates to 0, it is interpreted as a normal value. - * - * @param expr An AST node - * @return A string in the target language - */ - // FIXME: this should be placed in ExpressionGenerator - public static String getTargetValue(Expression expr) { - if (expr instanceof Time) { - return getTargetTime((Time)expr); - } - return ASTUtils.toText(expr); - } - - /** - * Get textual representation of a value in the target language. - * - * If the value evaluates to 0, it is interpreted as a time. - * - * @param expr A time AST node - * @return A time string in the target language - */ - // FIXME: this should be placed in ExpressionGenerator - public static String getTargetTime(Expression expr) { - if (expr instanceof Time) { - return getTargetTime((Time)expr); - } else if (ASTUtils.isZero(expr)) { - TimeValue value = TimeValue.ZERO; - return timeInTargetLanguage(value); - } - return ASTUtils.toText(expr); - } } diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/src/org/lflang/generator/GeneratorUtils.java index 709e1943bd..92a57fd424 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/GeneratorUtils.java @@ -16,8 +16,8 @@ import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; -import org.lflang.generator.LFGeneratorContext.Mode; import org.lflang.TargetProperty; +import org.lflang.generator.LFGeneratorContext.Mode; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Instantiation; diff --git a/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java b/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java new file mode 100644 index 0000000000..2bb72789ff --- /dev/null +++ b/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2023, TU Dresden. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.lflang.generator; + +import org.lflang.lf.BracedListExpression; +import org.lflang.lf.Code; +import org.lflang.lf.CodeExpr; +import org.lflang.lf.Expression; +import org.lflang.lf.LfFactory; +import org.lflang.lf.Literal; +import org.lflang.lf.ParameterReference; +import org.lflang.lf.Time; + +/** + * A visitor for expressions in LF. + * + * @author Clément Fournier <clement.fournier@tu-dresden.de> + */ +public interface LfExpressionVisitor { + + + R visitLiteral(Literal expr, P param); + + R visitBracedListExpr(BracedListExpression expr, P param); + + R visitTimeLiteral(Time expr, P param); + + R visitCodeExpr(CodeExpr expr, P param); + + R visitParameterRef(ParameterReference expr, P param); + + /** + * Dispatch the visitor on the given expression type. + * + * @param e An expression that will be visited + * @param arg Argument for the visitor + * @param visitor Visitor + * @param

Type of parameter expected by the visitor + * @param Return type of the visitor + * @return The return value of the visitor + */ + static R dispatch(Expression e, P arg, LfExpressionVisitor visitor) { + if (e instanceof Literal) { + return visitor.visitLiteral((Literal) e, arg); + } else if (e instanceof BracedListExpression) { + return visitor.visitBracedListExpr((BracedListExpression) e, arg); + } else if (e instanceof Time) { + return visitor.visitTimeLiteral((Time) e, arg); + } else if (e instanceof CodeExpr) { + return visitor.visitCodeExpr((CodeExpr) e, arg); + } else if (e instanceof ParameterReference) { + return visitor.visitParameterRef((ParameterReference) e, arg); + } + + throw new IllegalArgumentException("Expression of type " + e.getClass() + " not handled"); + } + + /** Base visitor class where methods are defaulted to a common one. */ + abstract class DefaultLfVisitor implements LfExpressionVisitor { + + abstract R visitExpression(Expression expr, P param); + + @Override + public R visitLiteral(Literal expr, P param) { + return visitExpression(expr, param); + } + + @Override + public R visitBracedListExpr(BracedListExpression expr, P param) { + return visitExpression(expr, param); + } + + @Override + public R visitTimeLiteral(Time expr, P param) { + return visitExpression(expr, param); + } + + @Override + public R visitCodeExpr(CodeExpr expr, P param) { + return visitExpression(expr, param); + } + + @Override + public R visitParameterRef(ParameterReference expr, P param) { + return visitExpression(expr, param); + } + } + + /** + * A visitor that deep copies the expression. Can be extended + * to replace certain expressions during the copy. + * + * @param

Parameter type + */ + class LfExpressionDeepCopyVisitor

implements LfExpressionVisitor { + + @Override + public Expression visitLiteral(Literal expr, P param) { + Literal clone = LfFactory.eINSTANCE.createLiteral(); + clone.setLiteral(expr.getLiteral()); + return clone; + } + + @Override + public Expression visitBracedListExpr(BracedListExpression expr, P param) { + BracedListExpression clone = LfFactory.eINSTANCE.createBracedListExpression(); + for (Expression item : expr.getItems()) { + clone.getItems().add(dispatch(item, param, this)); + } + return clone; + } + + @Override + public Expression visitTimeLiteral(Time expr, P param) { + Time clone = LfFactory.eINSTANCE.createTime(); + clone.setUnit(expr.getUnit()); + clone.setInterval(expr.getInterval()); + return clone; + } + + @Override + public Expression visitParameterRef(ParameterReference expr, P param) { + ParameterReference clone = LfFactory.eINSTANCE.createParameterReference(); + clone.setParameter(expr.getParameter()); + return clone; + } + + @Override + public Expression visitCodeExpr(CodeExpr expr, P param) { + CodeExpr codeExpr = LfFactory.eINSTANCE.createCodeExpr(); + Code code = LfFactory.eINSTANCE.createCode(); + code.setBody(expr.getCode().getBody()); + codeExpr.setCode(code); + return codeExpr; + } + } + +} diff --git a/org.lflang/src/org/lflang/generator/ParameterInstance.java b/org.lflang/src/org/lflang/generator/ParameterInstance.java index 9da4f1f247..9287710e6b 100644 --- a/org.lflang/src/org/lflang/generator/ParameterInstance.java +++ b/org.lflang/src/org/lflang/generator/ParameterInstance.java @@ -30,10 +30,12 @@ import java.util.List; import java.util.Optional; -import org.lflang.InferredType; import org.lflang.ASTUtils; +import org.lflang.InferredType; import org.lflang.lf.Assignment; import org.lflang.lf.Expression; +import org.lflang.lf.Initializer; +import org.lflang.lf.LfFactory; import org.lflang.lf.Parameter; /** @@ -71,13 +73,26 @@ public ParameterInstance(Parameter definition, ReactorInstance parent) { //// Public Methods /** - * Get the initial value(s) of this parameter as a list of - * Value objects, where each Value is either an instance - * of Time, Literal, or Code. That is, references to other - * parameters have been replaced with their initial values. + * Get the initial value of this parameter. */ - public List getInitialValue() { - return parent.initialParameterValue(this.definition); + private Initializer getInitialValue() { + return definition.getInit(); + } + + /** + * Return the (possibly overridden) value of this parameter + * in the containing instance. Parameter references are resolved + * to actual expressions. + */ + public Initializer getActualValue() { + Assignment override = getOverride(); + Initializer init; + if (override != null) { + init = override.getRhs(); + } else { + init = getInitialValue(); + } + return init; } /** diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index cc049f971c..833cd7e934 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -26,6 +26,9 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator; +import static org.lflang.ASTUtils.belongsTo; +import static org.lflang.ASTUtils.getLiteralTimeValue; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -33,6 +36,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -43,10 +47,12 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.TimeValue; import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable; import org.lflang.lf.Action; +import org.lflang.lf.Assignment; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Connection; import org.lflang.lf.Expression; +import org.lflang.lf.Initializer; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; @@ -451,29 +457,50 @@ public boolean hasCycles() { */ public Integer initialIntParameterValue(Parameter parameter) { return ASTUtils.initialValueInt(parameter, instantiations()); - } + } - /** - * Given a parameter definition for this reactor, return the initial value - * of the parameter. If the parameter is overridden when instantiating - * this reactor or any of its containing reactors, use that value. - * Otherwise, use the default value in the reactor definition. - * - * The returned list of Value objects is such that each element is an - * instance of Time, String, or Code, never Parameter. - * For most uses, this list has only one element, but parameter - * values can be lists of elements, so the returned value is a list. - * - * @param parameter The parameter definition (a syntactic object in the AST). - * - * @return A list of Value objects, or null if the parameter is not found. - * Return an empty list if no initial value is given. - * Each value is an instance of Literal if a literal value is given, - * a Time if a time value was given, or a Code, if a code value was - * given (text in the target language delimited by {= ... =} - */ - public List initialParameterValue(Parameter parameter) { - return ASTUtils.initialValue(parameter, instantiations()); + public Expression resolveParameters(Expression e) { + return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); + } + + + private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { + static final ParameterInliner INSTANCE = new ParameterInliner(); + + @Override + public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { + if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { + throw new IllegalArgumentException("Parameter " + + expr.getParameter().getName() + + " is not a parameter of reactor instance " + + instance.getName() + + "." + ); + } + + Optional assignment = + instance.definition.getParameters().stream() + .filter(it -> it.getLhs().equals(expr.getParameter())) + .findAny(); // There is at most one + + if (assignment.isPresent()) { + // replace the parameter with its value. + Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); + // recursively resolve parameters + return instance.getParent().resolveParameters(value); + } else { + // In that case use the default value. Default values + // cannot use parameter values, so they don't need to + // be recursively resolved. + Initializer init = expr.getParameter().getInit(); + Expression defaultValue = ASTUtils.asSingleExpr(init); + if (defaultValue == null) { + // this is a problem + return super.visitParameterRef(expr, instance); + } + return defaultValue; + } + } } /** @@ -686,14 +713,8 @@ public String toString() { * precise time value assigned to this reactor instance. */ public TimeValue getTimeValue(Expression expr) { - if (expr instanceof ParameterReference) { - final var param = ((ParameterReference)expr).getParameter(); - // Avoid a runtime error in validator for invalid programs. - if (lookupParameterInstance(param).getInitialValue().isEmpty()) return null; - return ASTUtils.getLiteralTimeValue(lookupParameterInstance(param).getInitialValue().get(0)); - } else { - return ASTUtils.getLiteralTimeValue(expr); - } + Expression resolved = resolveParameters(expr); + return getLiteralTimeValue(resolved); } ////////////////////////////////////////////////////// diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index fe73bd78cc..8d9788e19e 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -8,6 +8,7 @@ import org.lflang.InferredType; import org.lflang.TimeValue; import org.lflang.lf.Action; +import org.lflang.lf.BracedListExpression; import org.lflang.lf.CodeExpr; import org.lflang.lf.Expression; import org.lflang.lf.Initializer; @@ -68,6 +69,13 @@ default String getTargetParamRef(ParameterReference expr, InferredType typeOrNul return escapeIdentifier(expr.getParameter().getName()); } + /** Translate the braced list expression into target language syntax. */ + default String getTargetBracedListExpr(BracedListExpression expr, InferredType typeOrNull) { + InferredType t = typeOrNull == null ? InferredType.undefined() : typeOrNull; + return expr.getItems().stream().map(e -> getTargetExpr(e, t)) + .collect(Collectors.joining(",", "{", "}")); + } + /** * Return an "undefined" type which is used as a default * when a type cannot be inferred. @@ -231,10 +239,8 @@ default String getTargetInitializer(Initializer init, Type type) { var targetValues = init.getExprs().stream().map(it -> getTargetExpr(it, inferredType)).collect(Collectors.toList()); if (inferredType.isFixedSizeList) { return getFixedSizeListInitExpression(targetValues, inferredType.listSize, init.isBraces()); - } else if (inferredType.isVariableSizeList) { + } else { return getVariableSizeListInitExpression(targetValues, init.isBraces()); - } else { - return getMissingExpr(inferredType); } } @@ -254,6 +260,8 @@ default String getTargetExpr(Expression expr, InferredType type) { return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape } else if (expr instanceof CodeExpr) { return ASTUtils.toText(((CodeExpr) expr).getCode()); + } else if (expr instanceof BracedListExpression) { + return getTargetBracedListExpr((BracedListExpression) expr, type); } else { throw new IllegalStateException("Invalid value " + expr); } diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index e800328e18..1c4a1b45e8 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -4,10 +4,8 @@ import java.util.ArrayList; import org.lflang.ASTUtils; import org.lflang.Target; -import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.GeneratorBase; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Reactor; @@ -40,9 +38,10 @@ public static String generateInitializers( var triggerStructName = CUtil.reactorRef(action.getParent()) + "->_lf__" + action.getName(); var minDelay = action.getMinDelay(); var minSpacing = action.getMinSpacing(); - var offsetInitializer = triggerStructName+".offset = " + GeneratorBase.timeInTargetLanguage(minDelay) + ";"; + var offsetInitializer = triggerStructName+".offset = " + CTypes.getInstance().getTargetTimeExpr(minDelay) + + ";"; var periodInitializer = triggerStructName+".period = " + (minSpacing != null ? - GeneratorBase.timeInTargetLanguage(minSpacing) : + CTypes.getInstance().getTargetTimeExpr(minSpacing) : CGenerator.UNDEFINED_MIN_SPACING) + ";"; code.addAll(List.of( "// Initializing action "+action.getFullName(), diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 2ef5074455..70f76c282e 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -394,9 +394,9 @@ public CGenerator(LFGeneratorContext context, boolean ccppMode) { this( context, ccppMode, - new CTypes(context.getErrorReporter()), + new CTypes(), new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes(context.getErrorReporter())) + new CDelayBodyGenerator(new CTypes()) ); } @@ -1910,7 +1910,7 @@ private void generateSetDeadline(ReactorInstance instance) { var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; if (reaction.declaredDeadline != null) { var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr(selfRef+".deadline = "+GeneratorBase.timeInTargetLanguage(deadline)+";"); + initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); } else { // No deadline. initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index 23906eae73..1534f0ea02 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -1,15 +1,16 @@ package org.lflang.generator.c; -import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; + +import org.lflang.InferredType; import org.lflang.generator.ParameterInstance; import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.GeneratorBase; import org.lflang.lf.Assignment; import org.lflang.lf.Expression; +import org.lflang.lf.Initializer; import org.lflang.lf.Parameter; -import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; /** @@ -32,46 +33,9 @@ public static String getInitializer(ParameterInstance p) { return CUtil.bankIndex(p.getParent()); } - // Handle overrides in the intantiation. - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = null; - for (Assignment assignment: p.getParent().getDefinition().getParameters()) { - if (assignment.getLhs() == p.getDefinition()) { - lastAssignment = assignment; - } - } - List list = new LinkedList<>(); - if (lastAssignment != null) { - // The parameter has an assignment. - // Right hand side can be a list. Collect the entries. - for (Expression expr: lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - // The parameter is being assigned a parameter value. - // Assume that parameter belongs to the parent's parent. - // This should have been checked by the validator. - final var param = ((ParameterReference) expr).getParameter(); - list.add(CUtil.reactorRef(p.getParent().getParent()) + "->" + param.getName()); - } else { - list.add(GeneratorBase.getTargetTime(expr)); - } - } - } else { - // there was no assignment in the instantiation. So just use the - // parameter's initial value. - for (Expression expr : p.getParent().initialParameterValue(p.getDefinition())) { - if (ASTUtils.isOfTimeType(p.getDefinition())) { - list.add(GeneratorBase.getTargetTime(expr)); - } else { - list.add(GeneratorBase.getTargetTime(expr)); - } - } - } - if (list.size() == 1) { - return list.get(0); - } else { - return "{" + String.join(", ", list) + "}"; - } + CTypes ctypes = CTypes.generateParametersIn(p.getParent().getParent()); + Initializer values = p.getActualValue(); + return ctypes.getTargetInitializer(values, p.getDefinition().getType()); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index a0bcf28823..46910f4167 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -3,6 +3,7 @@ import java.util.LinkedList; import org.lflang.ASTUtils; +import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; import org.lflang.generator.GeneratorBase; import org.lflang.generator.ModeInstance; @@ -126,17 +127,7 @@ private static String generateModalReset( * references are replaced with accesses to the self struct of the parent. */ private static String getInitializerExpr(StateVar state, ReactorInstance parent) { - var list = new LinkedList(); - for (Expression expr : state.getInit().getExprs()) { - if (expr instanceof ParameterReference) { - final var param = ((ParameterReference)expr).getParameter(); - list.add(CUtil.reactorRef(parent) + "->" + param.getName()); - } else { - list.add(GeneratorBase.getTargetTime(expr)); - } - } - return list.size() == 1 ? - list.get(0) : - "{" + String.join(", ", list) + "}"; + var ctypes = CTypes.generateParametersIn(parent); + return ctypes.getTargetInitializer(state.getInit(), state.getType()); } } diff --git a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java index e0c2000e87..75623fdfe7 100644 --- a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java @@ -1,7 +1,7 @@ package org.lflang.generator.c; import java.util.List; -import org.lflang.generator.GeneratorBase; + import org.lflang.generator.TimerInstance; /** @@ -18,8 +18,8 @@ public class CTimerGenerator { */ public static String generateInitializer(TimerInstance timer) { var triggerStructName = CUtil.reactorRef(timer.getParent()) + "->_lf__" + timer.getName(); - var offset = GeneratorBase.timeInTargetLanguage(timer.getOffset()); - var period = GeneratorBase.timeInTargetLanguage(timer.getPeriod()); + var offset = CTypes.getInstance().getTargetTimeExpr(timer.getOffset()); + var period = CTypes.getInstance().getTargetTimeExpr(timer.getPeriod()); var mode = timer.getMode(false); var modeRef = mode != null ? "&"+CUtil.reactorRef(mode.getParent())+"->_lf__modes["+mode.getParent().modes.indexOf(mode)+"];" : diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/src/org/lflang/generator/c/CTypes.java index 803d9e8432..ba5b3631a9 100644 --- a/org.lflang/src/org/lflang/generator/c/CTypes.java +++ b/org.lflang/src/org/lflang/generator/c/CTypes.java @@ -1,11 +1,18 @@ package org.lflang.generator.c; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; -import org.lflang.ErrorReporter; import org.lflang.InferredType; +import org.lflang.TimeUnit; +import org.lflang.TimeValue; +import org.lflang.generator.ReactorInstance; import org.lflang.generator.TargetTypes; +import org.lflang.lf.Initializer; +import org.lflang.lf.ParameterReference; +import org.lflang.lf.Type; public class CTypes implements TargetTypes { @@ -13,20 +20,9 @@ public class CTypes implements TargetTypes { // For example, for "foo[10]", the first match will be "foo" and the second "[10]". // For "foo[]", the first match will be "foo" and the second "". static final Pattern arrayPattern = Pattern.compile("^\\s*(?:/\\*.*?\\*/)?\\s*(\\w+)\\s*\\[([0-9]*)]\\s*$"); + private static final CTypes INSTANCE = new CTypes(); - // FIXME: Instead of using the ErrorReporter, perhaps we should be raising assertion errors or - // UnsupportedOperationExceptions or some other non-recoverable errors. - private final ErrorReporter errorReporter; - - /** - * Initializes a {@code CTargetTypes} with the given - * error reporter. - * @param errorReporter The error reporter for any - * errors raised in the code - * generation process. - */ - public CTypes(ErrorReporter errorReporter) { - this.errorReporter = errorReporter; + public CTypes() { } @Override @@ -56,7 +52,7 @@ public String getTargetVariableSizeListType(String baseType) { @Override public String getTargetUndefinedType() { - return String.format("/* %s */", errorReporter.reportError("undefined type")); + return "/*undefined*/"; } /** @@ -78,6 +74,33 @@ public String getTargetType(InferredType type) { return result; } + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + throw new UnsupportedOperationException("No context defined"); + } + + @Override + public String getTargetTimeExpr(TimeValue time) { + if (time != null) { + if (time.unit != null) { + return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; + } else { + return Long.valueOf(time.getMagnitude()).toString(); + } + } + return "0"; // FIXME: do this or throw exception? + } + + @Override + public String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); + } + + @Override + public String getVariableSizeListInitExpression(List contents, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); + } + /** * Return a variable declaration of the form "{@code type name}". * The type is as returned by {@link #getTargetType(InferredType)}, except with @@ -119,4 +142,23 @@ public String getVariableDeclaration( } return declaration; } + + // note that this is moved out by #544 + public static String cMacroName(TimeUnit unit) { + return unit.getCanonicalName().toUpperCase(); + } + + public static CTypes getInstance() { + return INSTANCE; + } + + + public static CTypes generateParametersIn(ReactorInstance instance) { + return new CTypes() { + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return CUtil.reactorRef(instance) + "->" + expr.getParameter().getName(); + } + }; + } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt index a460290287..3c2224e031 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt @@ -40,32 +40,28 @@ class CppParameterGenerator(private val reactor: Reactor) { val Parameter.typeAlias get(): String = "__lf_${name}_t" } - /** Generate all constructor initializers for parameters */ - fun generateInitializers() = - reactor.parameters.joinWithLn(prefix = "// parameters\n") { - ", ${it.name}(parameters.${it.name})" - } - /** Generate all parameter declarations as used in the parameter struct */ fun generateParameterStructDeclarations() = reactor.parameters.joinToString("\n", postfix = "\n") { with(it) { """ using $typeAlias = $targetType; - const $typeAlias $name${ - if (init == null) "" else " = " + typeAlias + CppTypes.getCppInitializer( + $typeAlias $name${ + if (init == null) "" else CppTypes.getCppInitializer( init, - inferredType + inferredType, + typeAlias = typeAlias ) }; """.trimIndent() } } - /** Generate using declarations for each parameter for use in the inner reactor class. - * This is required for C++ to bring templated parameters into scope. + /** Generate alias declarations for each parameter for use in the inner reactor class. + * This is required to bring parameters into scope. */ - fun generateUsingDeclarations() = reactor.parameters.joinToString(separator = "") { "using Parameters::${it.name};\n" } + fun generateInnerAliasDeclarations() = + reactor.parameters.joinToString(separator = "") { "const typename Parameters::${it.typeAlias}& ${it.name} = __lf_parameters.${it.name};\n" } /** Generate alias declarations for each parameter for use in the outer reactor class. * This is required for some code bodies (e.g. target code in parameter initializers) to have access to the local parameters. diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt index de8deb7a4f..50fff0bdb5 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt @@ -94,8 +94,9 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi | private: ${" | "..reactions.generateReactionViewForwardDeclarations()} | - | class Inner: public lfutil::LFScope, public Parameters { - ${" | "..parameters.generateUsingDeclarations()} + | class Inner: public lfutil::LFScope { + | const Parameters __lf_parameters; + ${" | "..parameters.generateInnerAliasDeclarations()} ${" | "..state.generateDeclarations()} ${" | "..methods.generateDeclarations()} ${" | "..reactions.generateBodyDeclarations()} @@ -161,9 +162,9 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi return with(PrependOperator) { """ |${reactor.templateLine} - |${reactor.templateName}::Inner::Inner(::reactor::Reactor* reactor, Parameters&& __lf_parameters) + |${reactor.templateName}::Inner::Inner(::reactor::Reactor* reactor, Parameters&& parameters) | : LFScope(reactor) - ${" | , Parameters(std::forward(__lf_parameters))"} + ${" | , __lf_parameters(std::forward(parameters))"} ${" | "..state.generateInitializers()} |{} """.trimMargin() diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt index 4b26328155..1d5050fee9 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt @@ -42,6 +42,6 @@ class CppStateGenerator(private val reactor: Reactor) { fun generateInitializers(): String = reactor.stateVars.filter { it.isInitialized } .joinWithLn(prefix = "// state variables\n") { - ", " + it.name + CppTypes.getCppInitializer(it.init, it.inferredType) + ", " + it.name + CppTypes.getCppInitializer(it.init, it.inferredType, disableEquals = true) } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt b/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt index e0a7103f20..6a908392ab 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt @@ -28,6 +28,7 @@ import org.lflang.InferredType import org.lflang.TimeUnit import org.lflang.TimeValue import org.lflang.generator.TargetTypes +import org.lflang.joinWithCommas import org.lflang.lf.Initializer import org.lflang.lf.ParameterReference @@ -71,14 +72,24 @@ val TimeUnit?.cppUnit /** * Returns a C++ variable initializer. */ -fun CppTypes.getCppInitializer(init: Initializer?, inferredType: InferredType): String { - return if (init == null) { +fun CppTypes.getCppInitializer( + init: Initializer?, + inferredType: InferredType, + disableEquals: Boolean = false, + typeAlias: String? = null +): String = + if (init == null) { "/*uninitialized*/" + } else if (init.isAssign && !disableEquals) { + val e = init.exprs.single() + " = " + getTargetExpr(e, inferredType) + } else if (init.isParens && typeAlias != null && !disableEquals) { + " = $typeAlias" + init.exprs.joinWithCommas("(", ")", trailing = false) { + getTargetExpr(it, inferredType.componentType) + } } else { - assert(init.isBraces || init.isParens) val (prefix, postfix) = if (init.isBraces) Pair("{", "}") else Pair("(", ")") - init.exprs.joinToString(", ", prefix, postfix) { + init.exprs.joinWithCommas(prefix, postfix, trailing = false) { getTargetExpr(it, inferredType.componentType) } } -} \ No newline at end of file diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index 78375c910a..9ca2f7222f 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -26,6 +26,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator.python; +import org.lflang.InferredType; import org.lflang.generator.ReactorInstance; import org.lflang.generator.GeneratorBase; import org.lflang.generator.c.CUtil; @@ -143,25 +144,6 @@ public static String generateGILReleaseCode() { * @return A value string in the target language */ protected static String getPythonTargetValue(Expression expr) { - String returnValue; - switch (ASTUtils.toOriginalText(expr)) { - case "false": - returnValue = "False"; - break; - case "true": - returnValue = "True"; - break; - default: - returnValue = GeneratorBase.getTargetValue(expr); - } - - // Parameters in Python are always prepended with a 'self.' - // predicate. Therefore, we need to append the returned value - // if it is a parameter. - if (expr instanceof ParameterReference) { - returnValue = "self." + returnValue; - } - - return returnValue; + return PythonTypes.getInstance().getTargetExpr(expr, InferredType.undefined()); } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 46bcc4f811..3f82f20016 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -96,7 +96,7 @@ public class PythonGenerator extends CGenerator { public PythonGenerator(LFGeneratorContext context) { this(context, - new PythonTypes(context.getErrorReporter()), + new PythonTypes(), new CCmakeGenerator( context.getFileConfig(), List.of("lib/python_action.c", diff --git a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java index 5617350062..fe78d8187f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java @@ -8,6 +8,7 @@ import com.google.common.base.Objects; import org.lflang.ASTUtils; +import org.lflang.InferredType; import org.lflang.generator.GeneratorBase; import org.lflang.generator.ParameterInstance; import org.lflang.lf.Expression; @@ -95,8 +96,7 @@ private static List getAllParameters(ReactorDecl decl) { * @return Initialization code */ private static String generatePythonInitializer(Parameter p) { - List values = p.getInit().getExprs().stream().map(PyUtil::getPythonTargetValue).toList(); - return values.size() > 1 ? "(" + String.join(", ", values) + ")" : values.get(0); + return PythonTypes.getInstance().getTargetInitializer(p.getInit(), p.getType()); } /** @@ -110,47 +110,8 @@ private static String generatePythonInitializer(Parameter p) { * @return Initialization code */ public static String generatePythonInitializer(ParameterInstance p) { - // Handle overrides in the instantiation. - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = getLastAssignment(p); - List list = new LinkedList<>(); - if (lastAssignment != null) { - // The parameter has an assignment. - // Right hand side can be a list. Collect the entries. - for (Expression expr : lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - // The parameter is being assigned a parameter value. - // Assume that parameter belongs to the parent's parent. - // This should have been checked by the validator. - final var param = ((ParameterReference) expr).getParameter(); - list.add(PyUtil.reactorRef(p.getParent().getParent()) + "." + param.getName()); - } else { - list.add(GeneratorBase.getTargetTime(expr)); - } - } - } else { - for (Expression expr : p.getParent().initialParameterValue(p.getDefinition())) { - list.add(PyUtil.getPythonTargetValue(expr)); - } - } - return list.size() > 1 ? "(" + String.join(", ", list) + ")" : list.get(0); + PythonTypes pyTypes = PythonTypes.generateParametersIn(p.getParent().getParent()); + return pyTypes.getTargetInitializer(p.getActualValue(), p.getDefinition().getType()); } - /** - * Returns the last assignment to "p" if there is one, - * or null if there is no assignment to "p" - * - * @param p The parameter instance to create initializer for - * @return The last assignment of the parameter instance - */ - private static Assignment getLastAssignment(ParameterInstance p) { - Assignment lastAssignment = null; - for (Assignment assignment : p.getParent().getDefinition().getParameters()) { - if (Objects.equal(assignment.getLhs(), p.getDefinition())) { - lastAssignment = assignment; - } - } - return lastAssignment; - } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonTypes.java b/org.lflang/src/org/lflang/generator/python/PythonTypes.java index c066494047..5b62ee5f97 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonTypes.java +++ b/org.lflang/src/org/lflang/generator/python/PythonTypes.java @@ -1,27 +1,20 @@ package org.lflang.generator.python; +import java.util.List; import java.util.regex.Pattern; +import java.util.stream.Collectors; -import org.lflang.ErrorReporter; import org.lflang.InferredType; +import org.lflang.generator.ReactorInstance; import org.lflang.generator.c.CTypes; +import org.lflang.generator.c.CUtil; +import org.lflang.lf.ParameterReference; public class PythonTypes extends CTypes { // Regular expression pattern for pointer types. The star at the end has to be visible. static final Pattern pointerPatternVariable = Pattern.compile("^\\s*+(\\w+)\\s*\\*\\s*$"); - - /** - * Initializes a {@code CTargetTypes} with the given - * error reporter. - * - * @param errorReporter The error reporter for any - * errors raised in the code - * generation process. - */ - public PythonTypes(ErrorReporter errorReporter) { - super(errorReporter); - } + private static final PythonTypes INSTANCE = new PythonTypes(); @Override public String getTargetUndefinedType() { @@ -39,16 +32,45 @@ public String getTargetUndefinedType() { public String getPythonType(InferredType type) { var result = super.getTargetType(type); - switch(result){ - case "double": result = "float"; - case "string": result = "object"; - } + result = switch (result) { + case "double" -> "float"; + case "string" -> "object"; + default -> result; + }; var matcher = pointerPatternVariable.matcher(result); - if(matcher.find()) { + if (matcher.find()) { return matcher.group(1); } return result; } + + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return "self." + expr.getParameter().getName(); + } + + @Override + public String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); + } + + @Override + public String getVariableSizeListInitExpression(List contents, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); + } + + public static PythonTypes getInstance() { + return INSTANCE; + } + + public static PythonTypes generateParametersIn(ReactorInstance instance) { + return new PythonTypes() { + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return PyUtil.reactorRef(instance) + "." + expr.getParameter().getName(); + } + }; + } } diff --git a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt index c65cd157c5..0075950a1f 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt @@ -23,7 +23,7 @@ class TSConstructorGenerator( ) { private fun initializeParameter(p: Parameter): String = - "${p.name}: ${TSTypes.getTargetType(p)} = ${TSTypes.getTargetInitializer(p)}" + "${p.name}: ${TSTypes.getInstance().getTargetType(p)} = ${TSTypes.getInstance().getTargetInitializer(p)}" private fun generateConstructorArguments(reactor: Reactor): String { val arguments = StringJoiner(", \n") diff --git a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt index b0a011d042..61aac6750e 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt @@ -16,7 +16,7 @@ object TSDelayBodyGenerator : DelayBodyGenerator { */ private fun getActionType(action: Action): String { return if (action.type != null) { - TSTypes.getTargetType(action.type) + TSTypes.getInstance().getTargetType(action.type) } else { "Present" } diff --git a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java new file mode 100644 index 0000000000..cf89596a56 --- /dev/null +++ b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java @@ -0,0 +1,29 @@ +package org.lflang.generator.ts; + +import org.lflang.generator.DockerGenerator; +import org.lflang.generator.LFGeneratorContext; + +/** + * Generates the docker file related code for the Typescript target. + * + * @author Hou Seng Wong + */ +public class TSDockerGenerator extends DockerGenerator { + + /** Construct a new Docker generator. */ + public TSDockerGenerator(LFGeneratorContext context) { + super(context); + } + + /** + * Return the content of the docker file for [tsFileName]. + */ + public String generateDockerFileContent() { + return """ + |FROM node:alpine + |WORKDIR /linguafranca/$name + |COPY . . + |ENTRYPOINT ["node", "dist/%s.js"] + """.formatted(context.getFileConfig().name); + } +} diff --git a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt deleted file mode 100644 index 1ca762340e..0000000000 --- a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.lflang.generator.ts - -import org.lflang.generator.DockerGenerator -import org.lflang.generator.LFGeneratorContext - -/** - * Generates the docker file related code for the Typescript target. - * - * @author Hou Seng Wong - */ -class TSDockerGenerator(context: LFGeneratorContext) : DockerGenerator(context) { - - /** - * Returns the content of the docker file for [tsFileName]. - */ - override fun generateDockerFileContent(): String { - val name = context.fileConfig.name - val dockerFileContent = """ - |FROM node:alpine - |WORKDIR /linguafranca/$name - |COPY . . - |ENTRYPOINT ["node", "dist/$name.js"] - """ - return dockerFileContent.trimMargin() - } -} diff --git a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt index 4ed12daa13..a28e462921 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt @@ -39,7 +39,7 @@ fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") { * @return The TS type. */ val Port.tsPortType: String - get() = type?.let { TSTypes.getTargetType(it) } ?: "Present" + get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "Present" /** * Return a TS type for the specified action. @@ -48,7 +48,7 @@ val Port.tsPortType: String * @return The TS type. */ val Action.tsActionType: String - get() = type?.let { TSTypes.getTargetType(it) } ?: "Present" + get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "Present" -fun Expression.toTsTime(): String = TSTypes.getTargetTimeExpr(this) -fun TimeValue.toTsTime(): String = TSTypes.getTargetTimeExpr(this) +fun Expression.toTsTime(): String = TSTypes.getInstance().getTargetTimeExpr(this) +fun TimeValue.toTsTime(): String = TSTypes.getInstance().getTargetTimeExpr(this) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 3fd3675d52..9262e44e64 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -429,7 +429,7 @@ class TSGenerator( return true } - override fun getTargetTypes(): TargetTypes = TSTypes + override fun getTargetTypes(): TargetTypes = TSTypes.getInstance() override fun getTarget(): Target { return Target.TS diff --git a/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt index 63857c0132..97e753f99b 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt @@ -25,10 +25,10 @@ class TSInstanceGenerator( private fun getTypeParams(typeParms: List): String = if (typeParms.isEmpty()) "" - else typeParms.joinToString(", ", "<", ">") { TSTypes.getTargetType(it) } + else typeParms.joinToString(", ", "<", ">") { TSTypes.getInstance().getTargetType(it) } private fun getReactorParameterList(parameters: List): String = - parameters.joinToString(", ", "[__Reactor, ", "]") { TSTypes.getTargetType(it) } + parameters.joinToString(", ", "[__Reactor, ", "]") { TSTypes.getInstance().getTargetType(it) } fun generateClassProperties(): String = @@ -50,7 +50,7 @@ class TSInstanceGenerator( childReactorArguments.add("this") for (parameter in childReactor.reactorClass.toDefinition().parameters) { - childReactorArguments.add(TSTypes.getTargetInitializer(parameter, childReactor)) + childReactorArguments.add(TSTypes.getInstance().getTargetInitializer(parameter, childReactor)) } if (childReactor.isBank) { childReactorInstantiations.add( diff --git a/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt index 5ded5814b0..838186a6dc 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt @@ -12,7 +12,7 @@ class TSParameterGenerator( fun generateClassProperties(): String = parameters.joinWithLn { - "${it.name}: __Parameter<${TSTypes.getTargetType(it)}>;" + "${it.name}: __Parameter<${TSTypes.getInstance().getTargetType(it)}>;" } fun generateInstantiations(): String = diff --git a/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt index c9fef820f0..305369832e 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt @@ -69,7 +69,7 @@ class TSParameterPreambleGenerator( mainParameters.joinWithLn { parameter -> """ - |let __CL${parameter.name}: ${TSTypes.getTargetType(parameter)} | undefined = undefined; + |let __CL${parameter.name}: ${TSTypes.getInstance().getTargetType(parameter)} | undefined = undefined; |if (__processedCLArgs.${parameter.name} !== undefined) { | if (__processedCLArgs.${parameter.name} !== null) { | __CL${parameter.name} = __processedCLArgs.${parameter.name}; @@ -114,7 +114,7 @@ class TSParameterPreambleGenerator( var customArgType: String? = null var customTypeLabel: String? = null - val paramType = TSTypes.getTargetType(parameter) + val paramType = TSTypes.getInstance().getTargetType(parameter) if (paramType == "string") { mainParameters.add(parameter) customArgType = "String"; diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt index 4354ac1ea9..aca577aad0 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt @@ -358,7 +358,7 @@ class TSReactionGenerator( // Underscores are added to parameter names to prevent conflict with prologue val name = param.name - reactSignature.add("__$name: __Parameter<${TSTypes.getTargetType(param)}>") + reactSignature.add("__$name: __Parameter<${TSTypes.getInstance().getTargetType(param)}>") reactFunctArgs.add("this.$name") reactPrologue.add("let $name = __$name.get();") } @@ -367,7 +367,7 @@ class TSReactionGenerator( for (state in reactor.stateVars) { // Underscores are added to state names to prevent conflict with prologue val name = state.name - reactSignature.add("__$name: __State<${TSTypes.getTargetType(state)}>") + reactSignature.add("__$name: __State<${TSTypes.getInstance().getTargetType(state)}>") reactFunctArgs.add("this.$name") reactPrologue.add("let $name = __$name.get();") reactEpilogue.add( diff --git a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt index 091da1d958..6ac2d8b28a 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt @@ -15,7 +15,7 @@ class TSStateGenerator( fun generateClassProperties(): String { val stateClassProperties = LinkedList() for (stateVar in stateVars) { - stateClassProperties.add("${stateVar.name}: __State<${TSTypes.getTargetType(stateVar)}>;"); + stateClassProperties.add("${stateVar.name}: __State<${TSTypes.getInstance().getTargetType(stateVar)}>;"); } return stateClassProperties.joinToString("\n") } @@ -25,7 +25,7 @@ class TSStateGenerator( // Next handle states. for (stateVar in stateVars) { if (ASTUtils.isInitialized(stateVar)) { - stateInstantiations.add("this.${stateVar.name} = new __State(${TSTypes.getTargetInitializer(stateVar)});"); + stateInstantiations.add("this.${stateVar.name} = new __State(${TSTypes.getInstance().getTargetInitializer(stateVar)});"); } else { stateInstantiations.add("this.${stateVar.name} = new __State(undefined);"); } diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.java b/org.lflang/src/org/lflang/generator/ts/TSTypes.java new file mode 100644 index 0000000000..e89fff00d4 --- /dev/null +++ b/org.lflang/src/org/lflang/generator/ts/TSTypes.java @@ -0,0 +1,75 @@ +package org.lflang.generator.ts; + +import java.util.List; + +import org.lflang.ASTUtils; +import org.lflang.TimeValue; +import org.lflang.generator.TargetTypes; +import org.lflang.generator.UnsupportedGeneratorFeatureException; +import org.lflang.lf.StateVar; + +public class TSTypes implements TargetTypes { + + private static TSTypes INSTANCE = new TSTypes(); + + private TSTypes() { + + } + + @Override + public String getTargetType(StateVar s) { + var type = TargetTypes.super.getTargetType(s); + if (!ASTUtils.isInitialized(s)) { + return "%s | undefined".formatted(type); + } else { + return type; + } + } + + @Override + public boolean supportsGenerics() { + return true; + } + + @Override + public String getTargetTimeType() { + return "TimeValue"; + } + + @Override + public String getTargetTagType() { + return "TimeValue"; + } + + @Override + public String getTargetUndefinedType() { + return "Present"; + } + + public String getTargetTimeExpr(TimeValue value) { + if (value.unit != null) { + return "TimeValue.%s(%s)".formatted(value.unit.getCanonicalName(), value.time); + } else { + // The value must be zero. + return "TimeValue.zero()"; + } + } + + @Override + public String getTargetFixedSizeListType(String baseType, int size) { + throw new UnsupportedGeneratorFeatureException("TypeScript does not support fixed-size array types."); + } + + @Override + public String getTargetVariableSizeListType(String baseType) { + return "Array<%s>".formatted(baseType); // same as "$baseType[]" + } + + public String getVariableSizeListInitExpression(List contents, boolean withBraces) { + return "[" + String.join(", ", contents) + "]"; + } + + public static TSTypes getInstance() { + return INSTANCE; + } +} diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.kt b/org.lflang/src/org/lflang/generator/ts/TSTypes.kt deleted file mode 100644 index 9b7b66f62f..0000000000 --- a/org.lflang/src/org/lflang/generator/ts/TSTypes.kt +++ /dev/null @@ -1,57 +0,0 @@ -package org.lflang.generator.ts - -import org.lflang.ASTUtils -import org.lflang.TimeValue -import org.lflang.generator.TargetTypes -import org.lflang.generator.UnsupportedGeneratorFeatureException -import org.lflang.joinWithCommas -import org.lflang.lf.StateVar - -object TSTypes : TargetTypes { - - override fun getTargetType(s: StateVar): String { - val type = super.getTargetType(s) - return if (!ASTUtils.isInitialized(s)) { - "$type | undefined" - } else { - type - } - } - - override fun supportsGenerics(): Boolean { - return true - } - - override fun getTargetTimeType(): String { - return "TimeValue" - } - - override fun getTargetTagType(): String { - return "TimeValue" - } - - override fun getTargetUndefinedType(): String { - return "Present" - } - - override fun getTargetTimeExpr(value: TimeValue): String { - return if (value.unit != null) { - "TimeValue.${value.unit.canonicalName}(${value.time})" - } else { - // The value must be zero. - "TimeValue.zero()" - } - } - - override fun getTargetFixedSizeListType(baseType: String?, size: Int): String { - throw UnsupportedGeneratorFeatureException("TypeScript does not support fixed-size array types.") - } - - override fun getTargetVariableSizeListType(baseType: String): String { - return "Array<$baseType>" // same as "$baseType[]" - } - - override fun getVariableSizeListInitExpression(contents: MutableList, withBraces: Boolean): String { - return contents.joinWithCommas("[", "]") - } -} diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 3f1fbef2fc..2ea579b753 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -69,6 +69,7 @@ import org.lflang.lf.ActionOrigin; import org.lflang.lf.Assignment; import org.lflang.lf.Attribute; +import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.CodeExpr; @@ -172,6 +173,30 @@ public void checkAction(Action action) { public void checkInitializer(Initializer init) { if (init.isBraces() && target != Target.CPP) { error("Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); + } else if (init.isParens() && target.mandatesEqualsInitializers()) { + var message = "This syntax is deprecated in the " + target + + " target, use an equal sign instead of parentheses for assignment."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, Literals.INITIALIZER__PARENS); + } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { + var feature = init.isBraces() ? Literals.INITIALIZER__BRACES + : Literals.INITIALIZER__PARENS; + var message = "This syntax is deprecated, do not use parentheses or braces but an equal sign."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, feature); + } + } + + @Check(CheckType.FAST) + public void checkBracedExpression(BracedListExpression expr) { + if (!target.allowsBracedListExpressions()) { + var message = "Braced expression lists are not a valid expression for the " + target + + " target."; + error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); } } @@ -1596,9 +1621,12 @@ public void typeCheck(Initializer init, InferredType type, EStructuralFeature fe // list of times var exprs = init.getExprs(); if (exprs.isEmpty()) { - error("Expected exactly one time value.", feature); + error("Expected at least one time value.", feature); return; } + if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { + exprs = ((BracedListExpression) exprs.get(0)).getItems(); + } for (var component : exprs) { checkExpressionIsTime(component, feature); } @@ -1608,7 +1636,7 @@ public void typeCheck(Initializer init, InferredType type, EStructuralFeature fe } } - public void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { + private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { if (init == null) { return; } @@ -1620,7 +1648,7 @@ public void checkExpressionIsTime(Initializer init, EStructuralFeature feature) } } - public void checkExpressionIsTime(Expression value, EStructuralFeature feature) { + private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { if (value == null || value instanceof Time) { return; } diff --git a/test/C/src/ActionDelay.lf b/test/C/src/ActionDelay.lf index 6a4deddda6..86e510080a 100644 --- a/test/C/src/ActionDelay.lf +++ b/test/C/src/ActionDelay.lf @@ -4,7 +4,7 @@ target C reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int(0) + state y_state: int = 0 logical action act(100 msec) reaction(y_in) -> act {= diff --git a/test/C/src/ActionIsPresent.lf b/test/C/src/ActionIsPresent.lf index 4f8164bea8..b94108949e 100644 --- a/test/C/src/ActionIsPresent.lf +++ b/test/C/src/ActionIsPresent.lf @@ -1,9 +1,9 @@ // Tests the is_present variable for actions. target C -main reactor ActionIsPresent(offset: time(1 nsec), period: time(500 msec)) { +main reactor ActionIsPresent(offset: time = 1 nsec, period: time = 500 msec) { logical action a - state success: bool(false) + state success: bool = false reaction(startup, a) -> a {= if (!a->is_present) { diff --git a/test/C/src/After.lf b/test/C/src/After.lf index f354d9d7c8..d3663457e4 100644 --- a/test/C/src/After.lf +++ b/test/C/src/After.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time(10 msec) - state received: int(0) + state expected_time: time = 10 msec + state received: int = 0 input x: int reaction(x) {= diff --git a/test/C/src/AfterCycles.lf b/test/C/src/AfterCycles.lf index 3bc9622944..d7d621046b 100644 --- a/test/C/src/AfterCycles.lf +++ b/test/C/src/AfterCycles.lf @@ -16,7 +16,7 @@ reactor Work { } main reactor AfterCycles { - state count: int(0) + state count: int = 0 s = new Source() w0 = new Work() w1 = new Work() diff --git a/test/C/src/AfterOverlapped.lf b/test/C/src/AfterOverlapped.lf index 49d2c22bd2..0925dc5164 100644 --- a/test/C/src/AfterOverlapped.lf +++ b/test/C/src/AfterOverlapped.lf @@ -8,8 +8,8 @@ import Count from "lib/Count.lf" reactor Test { input c: int - state i: int(0) - state received: int(0) + state i: int = 0 + state received: int = 0 reaction(c) {= self->received++; diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf index 85e1d2e000..378114c730 100644 --- a/test/C/src/AfterZero.lf +++ b/test/C/src/AfterZero.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time(0) - state received: int(0) + state expected_time: time = 0 + state received: int = 0 input x: int reaction(x) {= diff --git a/test/C/src/Alignment.lf b/test/C/src/Alignment.lf index 7420bd51c1..551b7c8342 100644 --- a/test/C/src/Alignment.lf +++ b/test/C/src/Alignment.lf @@ -7,7 +7,7 @@ target C { reactor Source { output out: int - state count: int(1) + state count: int = 1 timer t(0, 100 msec) reaction(t) -> out {= lf_set(out, self->count++); =} @@ -16,8 +16,8 @@ reactor Source { reactor Sieve { input in: int output out: bool - state primes: int*({= NULL =}) - state last_prime: int(0) + state primes: int* = {= NULL =} + state last_prime: int = 0 reaction(startup) {= // There are 1229 primes between 1 and 10,000. @@ -74,7 +74,7 @@ reactor Sieve { reactor Destination { input ok: bool input in: int - state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) + state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} reaction(ok, in) {= if (ok->is_present && in->is_present) { diff --git a/test/C/src/ArrayAsParameter.lf b/test/C/src/ArrayAsParameter.lf index d51778980e..a9df29cb03 100644 --- a/test/C/src/ArrayAsParameter.lf +++ b/test/C/src/ArrayAsParameter.lf @@ -3,9 +3,9 @@ // encode their own length. target C -reactor Source(sequence: int[](0, 1, 2), n_sequence: int(3)) { +reactor Source(sequence: int[] = {0, 1, 2}, n_sequence: int = 3) { output out: int - state count: int(0) + state count: int = 0 logical action next reaction(startup, next) -> out, next {= @@ -19,8 +19,8 @@ reactor Source(sequence: int[](0, 1, 2), n_sequence: int(3)) { reactor Print { input in: int - state count: int(1) - state received: int(0) + state count: int = 1 + state received: int = 0 reaction(in) {= self->received++; @@ -41,7 +41,7 @@ reactor Print { } main reactor ArrayAsParameter { - s = new Source(sequence = (1, 2, 3, 4), n_sequence = 4) + s = new Source(sequence = {1, 2, 3, 4}, n_sequence = 4) p = new Print() s.out -> p.in } diff --git a/test/C/src/ArrayAsType.lf b/test/C/src/ArrayAsType.lf index ad326c9288..c95e5bf385 100644 --- a/test/C/src/ArrayAsType.lf +++ b/test/C/src/ArrayAsType.lf @@ -13,7 +13,7 @@ reactor Source { =} } -reactor Print(scale: int(1)) { // The scale parameter is just for testing. +reactor Print(scale: int = 1) { // The scale parameter is just for testing. input in: int[3] reaction(in) {= diff --git a/test/C/src/ArrayFree.lf b/test/C/src/ArrayFree.lf index eea521aa72..11b31c123f 100644 --- a/test/C/src/ArrayFree.lf +++ b/test/C/src/ArrayFree.lf @@ -10,7 +10,7 @@ target C { import Source, Print from "ArrayPrint.lf" import Scale from "ArrayScale.lf" -reactor Free(scale: int(2), size: int(3)) { +reactor Free(scale: int = 2, size: int = 3) { mutable input in: int[] reaction(in) {= diff --git a/test/C/src/ArrayFreeMultiple.lf b/test/C/src/ArrayFreeMultiple.lf index b82bea9162..7b933ce518 100644 --- a/test/C/src/ArrayFreeMultiple.lf +++ b/test/C/src/ArrayFreeMultiple.lf @@ -12,7 +12,7 @@ import Print from "ArrayPrint.lf" reactor Source { output out: int[] - state c: int(0) + state c: int = 0 timer t(0, 1 sec) reaction(t) -> out {= @@ -26,7 +26,7 @@ reactor Source { =} } -reactor Free(scale: int(2)) { +reactor Free(scale: int = 2) { mutable input in: int[] reaction(in) {= diff --git a/test/C/src/ArrayPrint.lf b/test/C/src/ArrayPrint.lf index 33d75c6455..937bc51bea 100644 --- a/test/C/src/ArrayPrint.lf +++ b/test/C/src/ArrayPrint.lf @@ -6,9 +6,9 @@ target C { fast: true } -reactor Source(size: int(3)) { +reactor Source(size: int = 3) { output out: int[] - state count: int(0) + state count: int = 0 timer t(0, 1 sec) reaction(t) -> out {= @@ -26,9 +26,9 @@ reactor Source(size: int(3)) { } // The scale parameter is just for testing. -reactor Print(scale: int(1), size: int(3)) { +reactor Print(scale: int = 1, size: int = 3) { input in: int[] - state count: int(0) + state count: int = 0 reaction(in) {= bool failed = false; // For testing. diff --git a/test/C/src/ArrayScale.lf b/test/C/src/ArrayScale.lf index 257b0645c3..63edfc421c 100644 --- a/test/C/src/ArrayScale.lf +++ b/test/C/src/ArrayScale.lf @@ -9,7 +9,7 @@ target C { import Print, Source from "ArrayPrint.lf" -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { mutable input in: int[] output out: int[] diff --git a/test/C/src/CharLiteralInitializer.lf b/test/C/src/CharLiteralInitializer.lf index 9ee206efbf..319af0224c 100644 --- a/test/C/src/CharLiteralInitializer.lf +++ b/test/C/src/CharLiteralInitializer.lf @@ -2,7 +2,7 @@ target C main reactor CharLiteralInitializer { - state c: char('x') + state c: char = 'x' reaction(startup) {= if (self->c != 'x') { diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index c450bc0a64..7c024a9eba 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -5,10 +5,10 @@ target C { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= (self->count)++; diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index 43f604de06..cb98ef7d7e 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target C { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= (self->count)++; @@ -30,7 +30,7 @@ reactor Test { =} } -main reactor CompositionAfter(delay: time(5 sec)) { +main reactor CompositionAfter(delay: time = 5 sec) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index f57c1a688e..06221e9788 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -5,11 +5,11 @@ target C { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { input foo: int output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= printf("Hello World. At time %lld, my count is: %d.\n", lf_time_logical_elapsed(), self->count); @@ -30,7 +30,7 @@ reactor SourceExtended extends Source { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= (self->count)++; diff --git a/test/C/src/CountSelf.lf b/test/C/src/CountSelf.lf index 1a7a6d1ff2..1ef27187ae 100644 --- a/test/C/src/CountSelf.lf +++ b/test/C/src/CountSelf.lf @@ -6,7 +6,7 @@ target C { import TestCount from "lib/TestCount.lf" -reactor CountSelf2(delay: time(100 msec)) { +reactor CountSelf2(delay: time = 100 msec) { output out: int logical action a: int diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index 62116353a5..c72dc16dcf 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -5,10 +5,10 @@ target C { timeout: 6 sec } -reactor Source(period: time(3 sec)) { +reactor Source(period: time = 3 sec) { output y: int timer t(0, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= if (2 * (self->count / 2) != self->count) { @@ -22,9 +22,9 @@ reactor Source(period: time(3 sec)) { =} } -reactor Destination(timeout: time(1 sec)) { +reactor Destination(timeout: time = 1 sec) { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= printf("Destination receives: %d\n", x->value); diff --git a/test/C/src/DeadlineHandledAbove.lf b/test/C/src/DeadlineHandledAbove.lf index d186bf9016..92d7e9dac8 100644 --- a/test/C/src/DeadlineHandledAbove.lf +++ b/test/C/src/DeadlineHandledAbove.lf @@ -2,7 +2,7 @@ // container reacts to that output. target C -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time(100 msec)) { } main reactor DeadlineHandledAbove { - state violation_detected: bool(false) + state violation_detected: bool = false d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/C/src/DeadlineWithBanks.lf b/test/C/src/DeadlineWithBanks.lf index 266208cdac..18bc8c3682 100644 --- a/test/C/src/DeadlineWithBanks.lf +++ b/test/C/src/DeadlineWithBanks.lf @@ -11,7 +11,7 @@ target C { preamble {= volatile int global_cnt = 0; =} -reactor Bank(bank_index: int(0)) { +reactor Bank(bank_index: int = 0) { timer t(0, 100 msec) output out: int @@ -46,7 +46,7 @@ reactor Bank(bank_index: int(0)) { =} } -reactor Sink(dead: time(0)) { +reactor Sink(dead: time = 0) { input in: int reaction(in) {= =} deadline(dead) {= =} diff --git a/test/C/src/DeadlineZero.lf b/test/C/src/DeadlineZero.lf index 4e946bb63d..3ae49a9409 100644 --- a/test/C/src/DeadlineZero.lf +++ b/test/C/src/DeadlineZero.lf @@ -5,7 +5,7 @@ target C { reactor Detector { input trigger: int - state cnt: int(0) + state cnt: int = 0 reaction(trigger) {= printf("ERROR: failed to detect zero-duration deadline at iteration %d.\n", self->cnt); diff --git a/test/C/src/DelayArray.lf b/test/C/src/DelayArray.lf index 19e49e2464..72eb734888 100644 --- a/test/C/src/DelayArray.lf +++ b/test/C/src/DelayArray.lf @@ -4,7 +4,7 @@ target C { build-type: RelWithDebInfo } -reactor DelayPointer(delay: time(100 msec)) { +reactor DelayPointer(delay: time = 100 msec) { input in: int[] output out: int[] logical action a: int[] @@ -30,7 +30,7 @@ reactor Source { =} } -reactor Print(scale: int(1)) { // The scale parameter is just for testing. +reactor Print(scale: int = 1) { // The scale parameter is just for testing. input in: int[] reaction(in) {= diff --git a/test/C/src/DelayArrayWithAfter.lf b/test/C/src/DelayArrayWithAfter.lf index 42d7ff5275..c94be3b9a1 100644 --- a/test/C/src/DelayArrayWithAfter.lf +++ b/test/C/src/DelayArrayWithAfter.lf @@ -7,7 +7,7 @@ target C { reactor Source { output out: int[] - state iteration: int(1) + state iteration: int = 1 timer t(0, 1 sec) reaction(t) -> out {= @@ -23,10 +23,10 @@ reactor Source { =} } -reactor Print(scale: int(1)) { // The scale parameter is just for testing. +reactor Print(scale: int = 1) { // The scale parameter is just for testing. input in: int[] - state iteration: int(1) - state inputs_received: int(0) + state iteration: int = 1 + state inputs_received: int = 0 reaction(in) {= self->inputs_received++; diff --git a/test/C/src/DelayInt.lf b/test/C/src/DelayInt.lf index c7c27132bc..78ca793716 100644 --- a/test/C/src/DelayInt.lf +++ b/test/C/src/DelayInt.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target C -reactor Delay(delay: time(100 msec)) { +reactor Delay(delay: time = 100 msec) { input in: int output out: int logical action a: int @@ -18,8 +18,8 @@ reactor Delay(delay: time(100 msec)) { reactor Test { input in: int - state start_time: time(0) - state received_value: bool(false) + state start_time: time = 0 + state received_value: bool = false reaction(startup) {= // Record the logical time at the start. diff --git a/test/C/src/DelayPointer.lf b/test/C/src/DelayPointer.lf index 87455d32ec..c6313c199d 100644 --- a/test/C/src/DelayPointer.lf +++ b/test/C/src/DelayPointer.lf @@ -1,7 +1,7 @@ // Test delaying a pointer type. target C -reactor DelayPointer2(delay: time(100 msec)) { +reactor DelayPointer2(delay: time = 100 msec) { input in: int* output out: int* logical action a: int* @@ -30,8 +30,8 @@ reactor Source { reactor Test { input in: int* - state start_time: time(0) - state received_value: bool(false) + state start_time: time = 0 + state received_value: bool = false reaction(startup) {= // Record the logical time at the start. diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index 1c77190581..b14e680d72 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -2,7 +2,7 @@ // freed. target C -reactor DelayString2(delay: time(100 msec)) { +reactor DelayString2(delay: time = 100 msec) { input in: string output out: string logical action a: string @@ -17,7 +17,7 @@ reactor DelayString2(delay: time(100 msec)) { reactor Test { input in: string - state start_time: time(0) + state start_time: time = 0 reaction(in) {= printf("Received: %s.\n", in->value); diff --git a/test/C/src/DelayStruct.lf b/test/C/src/DelayStruct.lf index a92acdc483..9cd201aa11 100644 --- a/test/C/src/DelayStruct.lf +++ b/test/C/src/DelayStruct.lf @@ -7,7 +7,7 @@ preamble {= #include "hello.h" =} -reactor DelayPointer(delay: time(100 msec)) { +reactor DelayPointer(delay: time = 100 msec) { input in: hello_t* output out: hello_t* logical action a: hello_t* @@ -38,7 +38,7 @@ reactor Source { =} } -reactor Print(expected: int(42)) { // expected parameter is for testing. +reactor Print(expected: int = 42) { // expected parameter is for testing. input in: hello_t* reaction(in) {= diff --git a/test/C/src/DelayStructWithAfter.lf b/test/C/src/DelayStructWithAfter.lf index 14f24aaf88..6693a437e6 100644 --- a/test/C/src/DelayStructWithAfter.lf +++ b/test/C/src/DelayStructWithAfter.lf @@ -20,7 +20,7 @@ reactor Source { =} } -reactor Print(expected: int(42)) { // expected parameter is for testing. +reactor Print(expected: int = 42) { // expected parameter is for testing. input in: hello_t* reaction(in) {= diff --git a/test/C/src/DelayStructWithAfterOverlapped.lf b/test/C/src/DelayStructWithAfterOverlapped.lf index 671b1ca4b3..8161022653 100644 --- a/test/C/src/DelayStructWithAfterOverlapped.lf +++ b/test/C/src/DelayStructWithAfterOverlapped.lf @@ -12,7 +12,7 @@ preamble {= reactor Source { output out: hello_t* timer t(0, 1 sec) - state s: int(0) + state s: int = 0 reaction(t) -> out {= self->s++; @@ -27,7 +27,7 @@ reactor Source { reactor Print { // expected parameter is for testing. input in: hello_t* - state s: int(0) + state s: int = 0 reaction(in) {= self->s++; diff --git a/test/C/src/DelayedAction.lf b/test/C/src/DelayedAction.lf index b37f6b9710..28a3e81ac5 100644 --- a/test/C/src/DelayedAction.lf +++ b/test/C/src/DelayedAction.lf @@ -6,7 +6,7 @@ target C { main reactor DelayedAction { timer t(0, 1 sec) logical action a - state count: int(0) + state count: int = 0 reaction(t) -> a {= lf_schedule(a, MSEC(100)); =} diff --git a/test/C/src/DoubleInvocation.lf b/test/C/src/DoubleInvocation.lf index 4b60f26fa8..973c8b18f6 100644 --- a/test/C/src/DoubleInvocation.lf +++ b/test/C/src/DoubleInvocation.lf @@ -13,7 +13,7 @@ target C { reactor Ball { output position: int output velocity: int - state p: int(200) + state p: int = 200 timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -26,7 +26,7 @@ reactor Ball { reactor Print { input velocity: int input position: int - state previous: int(-1) + state previous: int = -1 reaction(startup) {= printf("####### Print startup\n"); diff --git a/test/C/src/DoublePort.lf b/test/C/src/DoublePort.lf index 97d18f1761..c8bf9811f8 100644 --- a/test/C/src/DoublePort.lf +++ b/test/C/src/DoublePort.lf @@ -13,7 +13,7 @@ target C { import Count from "lib/Count.lf" reactor CountMicrostep { - state count: int(1) + state count: int = 1 output out: int logical action act: int timer t(0, 1 sec) diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index fb6aaaabaa..8da6210825 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int input w: int - state s: int(2) + state s: int = 2 reaction(x, w) {= int sum = 0; diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index 201ac35d7c..68ad603168 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -8,7 +8,7 @@ target C { main reactor DoubleTrigger { timer t1 timer t2 - state s: int(0) + state s: int = 0 reaction(t1, t2) {= self->s++; diff --git a/test/C/src/FloatLiteral.lf b/test/C/src/FloatLiteral.lf index 6d55f6e988..576a20d1ac 100644 --- a/test/C/src/FloatLiteral.lf +++ b/test/C/src/FloatLiteral.lf @@ -6,10 +6,10 @@ main reactor { #include =} - state N: double(6.0221409e+23) - state charge: double(-1.6021766E-19) - state minus_epsilon: double(-.01e0) - state expected: double(.964853323188E5) + state N: double = 6.0221409e+23 + state charge: double = -1.6021766E-19 + state minus_epsilon: double = -.01e0 + state expected: double = .964853323188E5 reaction(startup) {= double F = - self->N * self->charge; diff --git a/test/C/src/Gain.lf b/test/C/src/Gain.lf index 4096ec5973..7cac5eaae6 100644 --- a/test/C/src/Gain.lf +++ b/test/C/src/Gain.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target C -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { input x: int output y: int @@ -10,7 +10,7 @@ reactor Scale(scale: int(2)) { reactor Test { input x: int - state received_value: bool(false) + state received_value: bool = false reaction(x) {= printf("Received %d.\n", x->value); diff --git a/test/C/src/GetMicroStep.lf b/test/C/src/GetMicroStep.lf index 4c7094c42e..0a428fd07d 100644 --- a/test/C/src/GetMicroStep.lf +++ b/test/C/src/GetMicroStep.lf @@ -2,7 +2,7 @@ target C main reactor GetMicroStep { - state s: int(1) + state s: int = 1 logical action l diff --git a/test/C/src/Hello.lf b/test/C/src/Hello.lf index f47b66ecc4..ea37265a23 100644 --- a/test/C/src/Hello.lf +++ b/test/C/src/Hello.lf @@ -8,9 +8,9 @@ target C { fast: true } -reactor Reschedule(period: time(2 sec), message: string("Hello C")) { - state count: int(0) - state previous_time: time(0) +reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { + state count: int = 0 + state previous_time: time = 0 timer t(1 sec, period) logical action a @@ -43,8 +43,8 @@ reactor Reschedule(period: time(2 sec), message: string("Hello C")) { } reactor Inside( - period: time(1 sec), - message: string("Composite default message.") + period: time = 1 sec, + message: string = "Composite default message." ) { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/C/src/HelloWorld.lf b/test/C/src/HelloWorld.lf index dc17cc0626..7de913c8ad 100644 --- a/test/C/src/HelloWorld.lf +++ b/test/C/src/HelloWorld.lf @@ -7,7 +7,7 @@ target C { } reactor HelloWorld2 { - state success: bool(false) + state success: bool = false reaction(startup) {= printf("Hello World.\n"); diff --git a/test/C/src/Hierarchy2.lf b/test/C/src/Hierarchy2.lf index 07fa4c73a0..0a4f20d4bc 100644 --- a/test/C/src/Hierarchy2.lf +++ b/test/C/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out: int timer t(0, 1 sec) - state i: int(0) + state i: int = 0 reaction(t) -> out {= (self->i)++; @@ -37,7 +37,7 @@ reactor Add { reactor Print { input in: int - state expected: int(2) + state expected: int = 2 reaction(in) {= printf("Received: %d.\n", in->value); diff --git a/test/C/src/IdentifierLength.lf b/test/C/src/IdentifierLength.lf index 69f1fcfd75..8fa38b96f0 100644 --- a/test/C/src/IdentifierLength.lf +++ b/test/C/src/IdentifierLength.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor A_Really_Long_Name_For_A_Source(period: time(2 sec)) { +reactor A_Really_Long_Name_For_A_Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor A_Really_Long_Name_For_A_Source(period: time(2 sec)) { reactor Another_Really_Long_Name_For_A_Test_Class { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= (self->count)++; diff --git a/test/C/src/ImportComposition.lf b/test/C/src/ImportComposition.lf index 023c9736b2..22a1bfef87 100644 --- a/test/C/src/ImportComposition.lf +++ b/test/C/src/ImportComposition.lf @@ -6,7 +6,7 @@ import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { a = new ImportedComposition() - state received: bool(false) + state received: bool = false reaction(startup) -> a.x {= lf_set(a.x, 42); =} diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 3941882f2c..680ffe2f75 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -17,7 +17,7 @@ reactor SourceExtended extends Source { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= (self->count)++; diff --git a/test/C/src/ManualDelayedReaction.lf b/test/C/src/ManualDelayedReaction.lf index 1402e00c62..72c57105ce 100644 --- a/test/C/src/ManualDelayedReaction.lf +++ b/test/C/src/ManualDelayedReaction.lf @@ -9,7 +9,7 @@ target C { reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int(0) + state y_state: int = 0 physical action act(0 msec) // TODO: delay in act or the schedule call? diff --git a/test/C/src/Methods.lf b/test/C/src/Methods.lf index 02f1f68c8e..edbdd2f7f6 100644 --- a/test/C/src/Methods.lf +++ b/test/C/src/Methods.lf @@ -1,7 +1,7 @@ target C main reactor { - state foo: int(2) + state foo: int = 2 method getFoo(): int {= return self->foo; =} diff --git a/test/C/src/MethodsRecursive.lf b/test/C/src/MethodsRecursive.lf index 73588e5115..5465e0c92c 100644 --- a/test/C/src/MethodsRecursive.lf +++ b/test/C/src/MethodsRecursive.lf @@ -2,7 +2,7 @@ target C main reactor { - state foo: int(2) + state foo: int = 2 method fib(n: int): int {= // Return the n-th Fibonacci number. if (n <= 1) return 1; diff --git a/test/C/src/MethodsSameName.lf b/test/C/src/MethodsSameName.lf index d2978ba4db..b274d153c8 100644 --- a/test/C/src/MethodsSameName.lf +++ b/test/C/src/MethodsSameName.lf @@ -2,7 +2,7 @@ target C reactor Foo { - state foo: int(2) + state foo: int = 2 method add(x: int) {= self->foo += x; =} @@ -16,7 +16,7 @@ reactor Foo { } main reactor { - state foo: int(2) + state foo: int = 2 a = new Foo() diff --git a/test/C/src/MovingAverage.lf b/test/C/src/MovingAverage.lf index cd135dbd26..a8309aa9d3 100644 --- a/test/C/src/MovingAverage.lf +++ b/test/C/src/MovingAverage.lf @@ -10,7 +10,7 @@ import TestDouble from "lib/Test.lf" reactor MASource { output out: double - state count: int(0) + state count: int = 0 timer clock(0, 200 msec) reaction(clock) -> out {= @@ -20,8 +20,8 @@ reactor MASource { } reactor MovingAverageImpl { - state delay_line: double[](0.0, 0.0, 0.0) - state index: int(0) + state delay_line: double[] = {0.0, 0.0, 0.0} + state index: int = 0 input in: double output out: double @@ -47,7 +47,7 @@ reactor MovingAverageImpl { main reactor MovingAverage { s = new MASource() m = new MovingAverageImpl() - p = new TestDouble(expected = (0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) + p = new TestDouble(expected = {0.0, 0.25, 0.75, 1.5, 2.5, 3.5}) s.out -> m.in m.out -> p.in } diff --git a/test/C/src/MultipleContained.lf b/test/C/src/MultipleContained.lf index f3058c9dd4..540052ba87 100644 --- a/test/C/src/MultipleContained.lf +++ b/test/C/src/MultipleContained.lf @@ -6,7 +6,7 @@ reactor Contained { output trigger: int input in1: int input in2: int - state count: int(0) + state count: int = 0 reaction(startup) -> trigger {= lf_set(trigger, 42); =} diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index 8db9e5e6f9..37b5ddba9f 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -20,7 +20,7 @@ reactor C { main reactor { c = new C() - state triggered: bool(true) + state triggered: bool = true reaction(c.z) {= lf_print("c.z = %d", c.z->value); diff --git a/test/C/src/NativeListsAndTimes.lf b/test/C/src/NativeListsAndTimes.lf index eb3658f8a4..a1d09beb6c 100644 --- a/test/C/src/NativeListsAndTimes.lf +++ b/test/C/src/NativeListsAndTimes.lf @@ -2,22 +2,24 @@ target C // This test passes if it is successfully compiled into valid target code. main reactor( - x: int(0), - y: time(0), // Units are missing but not required - z(1 msec), // Type is missing but not required - p: int[](1, 2, 3, 4), // List of integers - q: interval_t[](1 msec, 2 msec, 3 msec), // list of time values - g: time[](1 msec, 2 msec) // List of time values + x: int = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required + p: int[] = {1, 2, 3, 4}, // List of integers + q: interval_t[] = {1 msec, 2 msec, 3 msec}, // list of time values + g: time[] = {1 msec, 2 msec} // List of time values ) { - state s: time(y) // Reference to explicitly typed time parameter - state t: time(z) // Reference to implicitly typed time parameter + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter state v: bool // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required timer tock(1 sec) // Implicit type time timer toe(z) // Implicit type time - state baz(p) // Implicit type int[] - state period(z) // Implicit type time + state baz = p // Implicit type int[] + state period = z // Implicit type time + + state empty_list: int[] reaction(tick) {= // Target code diff --git a/test/C/src/NestedTriggeredReactions.lf b/test/C/src/NestedTriggeredReactions.lf index 6cc5f911b1..df52d36a14 100644 --- a/test/C/src/NestedTriggeredReactions.lf +++ b/test/C/src/NestedTriggeredReactions.lf @@ -3,7 +3,7 @@ target C reactor Container { input in: bool - state triggered: bool(false) + state triggered: bool = false contained = new Contained() @@ -21,7 +21,7 @@ reactor Container { reactor Contained { input in: bool - state triggered: bool(false) + state triggered: bool = false reaction(in) {= self->triggered = true; =} diff --git a/test/C/src/ParameterHierarchy.lf b/test/C/src/ParameterHierarchy.lf index 433948bd2b..825f9f5a60 100644 --- a/test/C/src/ParameterHierarchy.lf +++ b/test/C/src/ParameterHierarchy.lf @@ -1,24 +1,24 @@ // Test that parameter values pass down a deep hierarchy. target C -reactor Deep(p: int(0)) { +reactor Deep(p0: int = 0) { reaction(startup) {= - if (self->p != 42) { - lf_print_error_and_exit("Parameter value is %d. Should have been 42."); + if (self->p0 != 42) { + lf_print_error_and_exit("Parameter value is %d. Should have been 42.", self->p0); } else { lf_print("Success."); } =} } -reactor Intermediate(p: int(10)) { - a = new Deep(p = p) +reactor Intermediate(p1: int = 10) { + a0 = new Deep(p0 = p1) } -reactor Another(p: int(20)) { - a = new Intermediate(p = p) +reactor Another(p2: int = 20) { + a1 = new Intermediate(p1 = p2) } main reactor ParameterHierarchy { - a = new Intermediate(p = 42) + a2 = new Another(p2 = 42) } diff --git a/test/C/src/ParameterizedState.lf b/test/C/src/ParameterizedState.lf index 1965fa1929..3d92345ca9 100644 --- a/test/C/src/ParameterizedState.lf +++ b/test/C/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target C -reactor Foo(bar: int(42)) { - state baz(bar) +reactor Foo(bar: int = 42) { + state baz = bar reaction(startup) {= printf("Baz: %d\n", self->baz); =} } diff --git a/test/C/src/PeriodicDesugared.lf b/test/C/src/PeriodicDesugared.lf index 6d9f8a8ab4..46eb97db9c 100644 --- a/test/C/src/PeriodicDesugared.lf +++ b/test/C/src/PeriodicDesugared.lf @@ -3,7 +3,7 @@ target C { timeout: 1 sec } -main reactor(offset: time(0), period: time(500 msec)) { +main reactor(offset: time = 0, period: time = 500 msec) { logical action init(offset) logical action recur(period) diff --git a/test/C/src/PingPong.lf b/test/C/src/PingPong.lf index 5ce6caaaaa..2f1699a51d 100644 --- a/test/C/src/PingPong.lf +++ b/test/C/src/PingPong.lf @@ -25,10 +25,10 @@ target C { fast: true } -reactor Ping(count: int(10)) { +reactor Ping(count: int = 10) { input receive: int output send: int - state pingsLeft: int(count) + state pingsLeft: int = count logical action serve reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} @@ -42,10 +42,10 @@ reactor Ping(count: int(10)) { =} } -reactor Pong(expected: int(10)) { +reactor Pong(expected: int = 10) { input receive: int output send: int - state count: int(0) + state count: int = 0 reaction(receive) -> send {= self->count++; diff --git a/test/C/src/ReadOutputOfContainedReactor.lf b/test/C/src/ReadOutputOfContainedReactor.lf index 6b94d4a44b..ce2129069b 100644 --- a/test/C/src/ReadOutputOfContainedReactor.lf +++ b/test/C/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count: int(0) + state count: int = 0 reaction(startup) c.out {= printf("Startup reaction reading output of contained reactor: %d.\n", c.out->value); diff --git a/test/C/src/ScheduleLogicalAction.lf b/test/C/src/ScheduleLogicalAction.lf index e3c898ebb5..762f8c6f52 100644 --- a/test/C/src/ScheduleLogicalAction.lf +++ b/test/C/src/ScheduleLogicalAction.lf @@ -20,7 +20,7 @@ reactor foo { } reactor print { - state expected_time: time(0) + state expected_time: time = 0 input x: int reaction(x) {= diff --git a/test/C/src/SelfLoop.lf b/test/C/src/SelfLoop.lf index 68ca61278e..855be46792 100644 --- a/test/C/src/SelfLoop.lf +++ b/test/C/src/SelfLoop.lf @@ -7,7 +7,7 @@ reactor Self { input x: int output y: int logical action a: int - state expected: int(43) + state expected: int = 43 reaction(a) -> y {= printf("a = %d\n", a->value); diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index fcb495305a..b1e8f25f93 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -7,7 +7,7 @@ target C { reactor Printer { input x: int - state count: int(1) + state count: int = 1 reaction(x) {= printf("Inside reactor received: %d\n", x->value); @@ -20,7 +20,7 @@ reactor Printer { } main reactor SendingInside { - state count: int(0) + state count: int = 0 timer t(0, 1 sec) p = new Printer() diff --git a/test/C/src/SendsPointerTest.lf b/test/C/src/SendsPointerTest.lf index c7336ff91f..1f17bd1388 100644 --- a/test/C/src/SendsPointerTest.lf +++ b/test/C/src/SendsPointerTest.lf @@ -13,7 +13,7 @@ reactor SendsPointer { =} } -reactor Print(expected: int(42)) { // expected parameter is for testing. +reactor Print(expected: int = 42) { // expected parameter is for testing. input in: int_pointer reaction(in) {= diff --git a/test/C/src/SetArray.lf b/test/C/src/SetArray.lf index 605eed4081..f30457f9f8 100644 --- a/test/C/src/SetArray.lf +++ b/test/C/src/SetArray.lf @@ -17,7 +17,7 @@ reactor Source { =} } -reactor Print(scale: int(1)) { // The scale parameter is just for testing. +reactor Print(scale: int = 1) { // The scale parameter is just for testing. input in: int[] reaction(in) {= diff --git a/test/C/src/SetToken.lf b/test/C/src/SetToken.lf index c2295dbaa0..b9af4bff20 100644 --- a/test/C/src/SetToken.lf +++ b/test/C/src/SetToken.lf @@ -10,7 +10,7 @@ reactor Source { reaction(a) -> out {= lf_set_token(out, a->token); =} } -reactor Print(expected: int(42)) { // expected parameter is for testing. +reactor Print(expected: int = 42) { // expected parameter is for testing. input in: int* reaction(in) {= diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index a59a6728e9..3e2d786eec 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ // violation. target C -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: int output deadlineViolation: bool diff --git a/test/C/src/SlowingClock.lf b/test/C/src/SlowingClock.lf index 6655e87014..d4a1e1d5f4 100644 --- a/test/C/src/SlowingClock.lf +++ b/test/C/src/SlowingClock.lf @@ -11,8 +11,8 @@ target C { main reactor SlowingClock { logical action a(100 msec) - state interval: time(100 msec) - state expected_time: time(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec reaction(startup) -> a {= lf_schedule(a, 0); =} diff --git a/test/C/src/SlowingClockPhysical.lf b/test/C/src/SlowingClockPhysical.lf index b3255428c2..0e82730112 100644 --- a/test/C/src/SlowingClockPhysical.lf +++ b/test/C/src/SlowingClockPhysical.lf @@ -11,8 +11,8 @@ target C { main reactor SlowingClockPhysical { physical action a(100 msec) - state interval: time(100 msec) - state expected_time: time(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec reaction(startup) -> a {= self->expected_time = MSEC(100); diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index 38f2a247b6..a1c1167850 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -6,10 +6,10 @@ */ target C -reactor SuperDenseSender(number_of_iterations: int(10)) { +reactor SuperDenseSender(number_of_iterations: int = 10) { logical action loop output out: int - state iterator: int(0) + state iterator: int = 0 reaction(startup, loop) -> out {= if (self->iterator < self->number_of_iterations) { @@ -34,7 +34,7 @@ reactor SuperDenseSender(number_of_iterations: int(10)) { =} } -reactor SuperDenseReceiver(number_of_iterations: int(10)) { +reactor SuperDenseReceiver(number_of_iterations: int = 10) { input in: int reaction(in) {= diff --git a/test/C/src/Stop.lf b/test/C/src/Stop.lf index fcfa407d35..1731bced42 100644 --- a/test/C/src/Stop.lf +++ b/test/C/src/Stop.lf @@ -11,7 +11,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index 316cce5c6c..e845c6de48 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -8,7 +8,7 @@ target C reactor Sender { output out: int - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false timer t(0, 1 usec) logical action act diff --git a/test/C/src/Stride.lf b/test/C/src/Stride.lf index 137855990d..62b9077878 100644 --- a/test/C/src/Stride.lf +++ b/test/C/src/Stride.lf @@ -5,8 +5,8 @@ target C { fast: true } -reactor Count(stride: int(1)) { - state count: int(1) +reactor Count(stride: int = 1) { + state count: int = 1 output y: int timer t(0, 100 msec) @@ -18,7 +18,7 @@ reactor Count(stride: int(1)) { reactor Display { input x: int - state expected: int(1) // for testing. + state expected: int = 1 // for testing. reaction(x) {= printf("Received: %d.\n", x->value); diff --git a/test/C/src/StructAsState.lf b/test/C/src/StructAsState.lf index b57b15d07b..59ae495853 100644 --- a/test/C/src/StructAsState.lf +++ b/test/C/src/StructAsState.lf @@ -10,7 +10,7 @@ main reactor StructAsState { } hello_t; =} // Notice that target code delimiters are no longer necessary. - state s: hello_t("Earth", 42) + state s: hello_t = {"Earth", 42} reaction(startup) {= printf("State s.name=\"%s\", value=%d.\n", self->s.name, self->s.value); diff --git a/test/C/src/StructAsType.lf b/test/C/src/StructAsType.lf index 9e43173110..8674685530 100644 --- a/test/C/src/StructAsType.lf +++ b/test/C/src/StructAsType.lf @@ -23,7 +23,7 @@ reactor Source { =} } -reactor Print(expected: int(42)) { // expected parameter is for testing. +reactor Print(expected: int = 42) { // expected parameter is for testing. input in: hello_t reaction(in) {= diff --git a/test/C/src/StructAsTypeDirect.lf b/test/C/src/StructAsTypeDirect.lf index f9d85799e9..29472f057b 100644 --- a/test/C/src/StructAsTypeDirect.lf +++ b/test/C/src/StructAsTypeDirect.lf @@ -17,7 +17,7 @@ reactor Source { =} } -reactor Print(expected: int(42)) { // expected parameter is for testing. +reactor Print(expected: int = 42) { // expected parameter is for testing. input in: hello_t reaction(in) {= diff --git a/test/C/src/StructParallel.lf b/test/C/src/StructParallel.lf index 0d3e78cc3e..3c8e61a3a2 100644 --- a/test/C/src/StructParallel.lf +++ b/test/C/src/StructParallel.lf @@ -11,9 +11,9 @@ preamble {= #include "hello.h" =} -reactor Check(expected: int(42)) { +reactor Check(expected: int = 42) { input in: hello_t* - state invoked: bool(false) + state invoked: bool = false reaction(in) {= printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); @@ -32,7 +32,7 @@ reactor Check(expected: int(42)) { =} } -reactor Print(scale: int(2)) { +reactor Print(scale: int = 2) { // Mutable keyword indicates that this reactor wants a writable copy of the // input. mutable input in: hello_t* diff --git a/test/C/src/StructPrint.lf b/test/C/src/StructPrint.lf index adaf7fbf24..6af0d60c4f 100644 --- a/test/C/src/StructPrint.lf +++ b/test/C/src/StructPrint.lf @@ -20,7 +20,7 @@ reactor Print { =} } -reactor Check(expected: int(42)) { // expected parameter is for testing. +reactor Check(expected: int = 42) { // expected parameter is for testing. input in: hello_t* reaction(in) {= diff --git a/test/C/src/StructScale.lf b/test/C/src/StructScale.lf index 076d0e7f3f..3b92bab002 100644 --- a/test/C/src/StructScale.lf +++ b/test/C/src/StructScale.lf @@ -22,9 +22,9 @@ reactor Source { =} } -reactor TestInput(expected: int(42)) { // expected parameter is for testing. +reactor TestInput(expected: int = 42) { // expected parameter is for testing. input in: hello_t* - state invoked: bool(false) + state invoked: bool = false reaction(in) {= printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); @@ -43,7 +43,7 @@ reactor TestInput(expected: int(42)) { // expected parameter is for testing. =} } -reactor Print(scale: int(2)) { +reactor Print(scale: int = 2) { // Mutable keyword indicates that this reactor wants a writable copy of the // input. mutable input in: hello_t* diff --git a/test/C/src/SubclassesAndStartup.lf b/test/C/src/SubclassesAndStartup.lf index a8001a907d..2dbc1f688f 100644 --- a/test/C/src/SubclassesAndStartup.lf +++ b/test/C/src/SubclassesAndStartup.lf @@ -1,7 +1,7 @@ target C reactor Super { - state count: int(0) + state count: int = 0 reaction(startup) {= printf("%s(Super) started\n", self->name); @@ -16,7 +16,7 @@ reactor Super { =} } -reactor SubA(name: string("SubA")) extends Super { +reactor SubA(name: string = "SubA") extends Super { reaction(startup) {= printf("%s started\n", self->name); if (self->count == 0) { @@ -26,7 +26,7 @@ reactor SubA(name: string("SubA")) extends Super { =} } -reactor SubB(name: string("SubB")) extends Super { +reactor SubB(name: string = "SubB") extends Super { reaction(startup) {= printf("%s started\n", self->name); if (self->count == 0) { diff --git a/test/C/src/TimeLimit.lf b/test/C/src/TimeLimit.lf index 2497296efd..ae178d53b5 100644 --- a/test/C/src/TimeLimit.lf +++ b/test/C/src/TimeLimit.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int - state s: int(1) + state s: int = 1 reaction(x) {= // printf("%d\n", x->value); @@ -39,7 +39,7 @@ reactor Destination { =} } -main reactor TimeLimit(period: time(1 sec)) { +main reactor TimeLimit(period: time = 1 sec) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/C/src/TimeState.lf b/test/C/src/TimeState.lf index 790679ccda..cb0a9627f3 100644 --- a/test/C/src/TimeState.lf +++ b/test/C/src/TimeState.lf @@ -1,7 +1,7 @@ target C -reactor Foo(bar: int(42)) { - state baz: time(500 msec) +reactor Foo(bar: int = 42) { + state baz: time = 500 msec reaction(startup) {= printf("Baz: %lld\n", self->baz); =} } diff --git a/test/C/src/Timeout.lf b/test/C/src/Timeout.lf index e0bb841b3e..cb13eafba4 100644 --- a/test/C/src/Timeout.lf +++ b/test/C/src/Timeout.lf @@ -11,7 +11,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool(false) + state success: bool = false reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index 36a65d6031..2b146bb57c 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -12,7 +12,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool(false) + state success: bool = false reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/ToReactionNested.lf b/test/C/src/ToReactionNested.lf index 4f89c20e9c..11b3577c84 100644 --- a/test/C/src/ToReactionNested.lf +++ b/test/C/src/ToReactionNested.lf @@ -12,8 +12,8 @@ reactor CountContainer { } main reactor { - state count: int(1) - state received: bool(false) + state count: int = 1 + state received: bool = false s = new CountContainer() diff --git a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf index 544d269242..bc62b214e9 100644 --- a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf @@ -9,7 +9,7 @@ target C { reactor Source { output[2] out: int - state count: int(0) + state count: int = 0 timer t(0, 200 msec) reaction(t) -> out {= diff --git a/test/C/src/UnconnectedInput.lf b/test/C/src/UnconnectedInput.lf index f41524fa01..21e8cc5a69 100644 --- a/test/C/src/UnconnectedInput.lf +++ b/test/C/src/UnconnectedInput.lf @@ -7,7 +7,7 @@ target C { reactor Source { output out: int timer t(0, 1 sec) - state s: int(1) + state s: int = 1 reaction(t) -> out {= lf_set(out, self->s++); =} } @@ -27,7 +27,7 @@ reactor Add { reactor Print { input in: int - state expected: int(1) + state expected: int = 1 reaction(in) {= printf("Received: %d.\n", in->value); diff --git a/test/C/src/arduino/DigitalReadSerial.lf b/test/C/src/arduino/DigitalReadSerial.lf index febc640eb3..d79f86ad9b 100644 --- a/test/C/src/arduino/DigitalReadSerial.lf +++ b/test/C/src/arduino/DigitalReadSerial.lf @@ -11,7 +11,7 @@ target C { main reactor DigitalReadSerial { timer t1(0, 1 msec) - state pushButton: int(2) + state pushButton: int = 2 reaction(startup) {= pinMode(self->pushButton, INPUT); =} diff --git a/test/C/src/arduino/Fade.lf b/test/C/src/arduino/Fade.lf index 0408fb5a1a..d23aabd646 100644 --- a/test/C/src/arduino/Fade.lf +++ b/test/C/src/arduino/Fade.lf @@ -14,9 +14,9 @@ target C { main reactor Fade { timer t1(0, 30 msec) - state led: int(9) - state brightness: int(9) - state fadeAmount: int(5) + state led: int = 9 + state brightness: int = 9 + state fadeAmount: int = 5 reaction(startup) {= pinMode(self->led, OUTPUT); =} diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index 90c300a8b2..ec2beae766 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -33,12 +33,12 @@ main reactor AsyncCallback { lf_thread_t threadId; =} timer t(0, 200 msec) - state thread_id: lf_thread_t(0) - state expected_time: time(100 msec) - state toggle: bool(false) + state thread_id: lf_thread_t = 0 + state expected_time: time = 100 msec + state toggle: bool = false physical action a(100 msec): int - state i: int(0) + state i: int = 0 reaction(t) -> a {= // start new thread, provide callback diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index 17cb113a99..f123bcdbdf 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -28,12 +28,12 @@ main reactor { lf_thread_t threadId; =} timer t(0, 200 msec) - state thread_id: lf_thread_t(0) - state expected_time: time(100 msec) - state toggle: bool(false) + state thread_id: lf_thread_t = 0 + state expected_time: time = 100 msec + state toggle: bool = false physical action a(100 msec, 100 msec, "drop"): int - state i: int(0) + state i: int = 0 reaction(t) -> a {= // start new thread, provide callback diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index 49dc3e75e9..b7afeb2363 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -28,12 +28,12 @@ main reactor { lf_thread_t threadId; =} timer t(0, 200 msec) - state thread_id: lf_thread_t(0) - state expected_time: time(100 msec) - state toggle: bool(false) + state thread_id: lf_thread_t = 0 + state expected_time: time = 100 msec + state toggle: bool = false physical action a(100 msec, 100 msec, "replace"): int - state i: int(0) + state i: int = 0 reaction(t) -> a {= // start new thread, provide callback diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index decf56d687..cf0bafeb82 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -5,10 +5,10 @@ target C { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= (self->count)++; diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index 87359286ed..545206de91 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -2,7 +2,7 @@ // container reacts to that output. target C -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time(100 msec)) { } main reactor { - state violation_detected: bool(false) + state violation_detected: bool = false d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index fccb60001b..ac765fe6f7 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -5,10 +5,10 @@ target C { timeout: 6 sec } -reactor Source(period: time(3000 msec)) { +reactor Source(period: time = 3000 msec) { output y: int timer t(0, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= if (2 * (self->count / 2) != self->count) { @@ -22,9 +22,9 @@ reactor Source(period: time(3000 msec)) { =} } -reactor Destination(timeout: time(1 sec)) { +reactor Destination(timeout: time = 1 sec) { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= printf("Destination receives: %d\n", x->value); diff --git a/test/C/src/concurrent/DelayIntThreaded.lf b/test/C/src/concurrent/DelayIntThreaded.lf index 5c2c983508..449b17eb60 100644 --- a/test/C/src/concurrent/DelayIntThreaded.lf +++ b/test/C/src/concurrent/DelayIntThreaded.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target C -reactor Delay(delay: time(100 msec)) { +reactor Delay(delay: time = 100 msec) { input in: int output out: int logical action a: int @@ -16,8 +16,8 @@ reactor Delay(delay: time(100 msec)) { reactor Test { input in: int - state start_time: time(0) - state received_value: bool(false) + state start_time: time = 0 + state received_value: bool = false reaction(startup) {= // Record the logical time at the start. diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index 66885ab7a0..ba6c38ca19 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int input w: int - state s: int(2) + state s: int = 2 reaction(x, w) {= int sum = 0; diff --git a/test/C/src/concurrent/GainThreaded.lf b/test/C/src/concurrent/GainThreaded.lf index b59d2b00fb..d9d6ec7673 100644 --- a/test/C/src/concurrent/GainThreaded.lf +++ b/test/C/src/concurrent/GainThreaded.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target C -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { input x: int output y: int @@ -10,7 +10,7 @@ reactor Scale(scale: int(2)) { reactor Test { input x: int - state received_value: bool(false) + state received_value: bool = false reaction(x) {= printf("Received %d.\n", x->value); diff --git a/test/C/src/concurrent/HelloThreaded.lf b/test/C/src/concurrent/HelloThreaded.lf index 72c7560ede..a8ea34dd05 100644 --- a/test/C/src/concurrent/HelloThreaded.lf +++ b/test/C/src/concurrent/HelloThreaded.lf @@ -8,9 +8,9 @@ target C { fast: true } -reactor Reschedule(period: time(2 sec), message: string("Hello C")) { - state count: int(0) - state previous_time: time(0) +reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { + state count: int = 0 + state previous_time: time = 0 timer t(1 sec, period) logical action a @@ -43,8 +43,8 @@ reactor Reschedule(period: time(2 sec), message: string("Hello C")) { } reactor Inside( - period: time(1 sec), - message: string("Composite default message.") + period: time = 1 sec, + message: string = "Composite default message." ) { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/C/src/concurrent/PingPongThreaded.lf b/test/C/src/concurrent/PingPongThreaded.lf index 0f2e60f065..4fae17911e 100644 --- a/test/C/src/concurrent/PingPongThreaded.lf +++ b/test/C/src/concurrent/PingPongThreaded.lf @@ -25,10 +25,10 @@ target C { fast: true } -reactor Ping(count: int(10)) { +reactor Ping(count: int = 10) { input receive: int output send: int - state pingsLeft: int(count) + state pingsLeft: int = count logical action serve reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} @@ -42,10 +42,10 @@ reactor Ping(count: int(10)) { =} } -reactor Pong(expected: int(10)) { +reactor Pong(expected: int = 10) { input receive: int output send: int - state count: int(0) + state count: int = 0 reaction(receive) -> send {= self->count++; diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index 7e5e8318b1..e68b3956e8 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -12,7 +12,7 @@ target C { reactor Scheduler { logical action act // List of microsteps. Size = 16 - state microstep_delay_list: uint32_t[]( + state microstep_delay_list: uint32_t[] = { 0, 1, 1, @@ -29,8 +29,9 @@ reactor Scheduler { 4, 4, 5 - ) - state times: int[]( + } + + state times: int[] = { 0, 0, 0, @@ -47,10 +48,10 @@ reactor Scheduler { 900 msec, 900 msec, 900 msec - ) + } // Size = 9 - state action_hit_list_microstep: int[](1, 2, 0, 1, 0, 2, 3, 4, 5) - state action_hit_list_times: int[]( + state action_hit_list_microstep: int[] = {1, 2, 0, 1, 0, 2, 3, 4, 5} + state action_hit_list_times: int[] = { 0, 0, 400 msec, @@ -60,9 +61,9 @@ reactor Scheduler { 800 msec, 900 msec, 900 msec - ) + } // Size = 9 - state action_hit_list_index: int(0) + state action_hit_list_index: int = 0 reaction(startup) -> act {= for (int i=0; i < 16; i++) { diff --git a/test/C/src/concurrent/ScheduleTwice.lf b/test/C/src/concurrent/ScheduleTwice.lf index 41512f3c7d..e19f4d02d5 100644 --- a/test/C/src/concurrent/ScheduleTwice.lf +++ b/test/C/src/concurrent/ScheduleTwice.lf @@ -2,7 +2,7 @@ target C main reactor ScheduleTwice { logical action a: int - state rc_count: int(0) + state rc_count: int = 0 preamble {= #define VERBOSE =} diff --git a/test/C/src/concurrent/ScheduleTwiceThreaded.lf b/test/C/src/concurrent/ScheduleTwiceThreaded.lf index a368bec1ec..499e0e4999 100644 --- a/test/C/src/concurrent/ScheduleTwiceThreaded.lf +++ b/test/C/src/concurrent/ScheduleTwiceThreaded.lf @@ -2,7 +2,7 @@ target C main reactor { logical action a: int - state rc_count: int(0) + state rc_count: int = 0 reaction(startup) -> a {= lf_schedule_int(a, MSEC(100), 42); diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index e08a5dffb5..e5185ecfc8 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -7,7 +7,7 @@ target C { reactor Printer { input x: int - state count: int(1) + state count: int = 1 reaction(x) {= printf("Inside reactor received: %d\n", x->value); @@ -20,7 +20,7 @@ reactor Printer { } main reactor SendingInsideThreaded { - state count: int(0) + state count: int = 0 timer t(0, 1 sec) p = new Printer() diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index 58d063647d..a16b5e46b6 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -7,10 +7,10 @@ */ target C -reactor SuperDenseSender(number_of_iterations: int(10)) { +reactor SuperDenseSender(number_of_iterations: int = 10) { logical action loop output out: int - state iterator: int(0) + state iterator: int = 0 reaction(startup, loop) -> out {= if (self->iterator < self->number_of_iterations) { @@ -35,7 +35,7 @@ reactor SuperDenseSender(number_of_iterations: int(10)) { =} } -reactor SuperDenseReceiver(number_of_iterations: int(10)) { +reactor SuperDenseReceiver(number_of_iterations: int = 10) { input in: int reaction(in) {= diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index aa69bda345..1deb1c4ff6 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -13,7 +13,7 @@ import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { input in: int - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index 051c615566..7afd4b0069 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -8,7 +8,7 @@ target C reactor Sender { output out: int - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false timer t(0, 1 usec) logical action act diff --git a/test/C/src/concurrent/Threaded.lf b/test/C/src/concurrent/Threaded.lf index abfcff2c1b..01f67c1bd4 100644 --- a/test/C/src/concurrent/Threaded.lf +++ b/test/C/src/concurrent/Threaded.lf @@ -16,7 +16,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= lf_set(out, self->s); @@ -40,8 +40,8 @@ reactor TakeTime { =} } -reactor Destination(width: int(4)) { - state s: int(400000000) +reactor Destination(width: int = 4) { + state s: int = 400000000 input[width] in: int reaction(in) {= @@ -58,7 +58,7 @@ reactor Destination(width: int(4)) { =} } -main reactor(width: int(4)) { +main reactor(width: int = 4) { a = new Source() t = new[width] TakeTime() (a.out)+ -> t.in diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index b24ead7cd9..2878393dac 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -5,10 +5,10 @@ target C { flags: "" } -reactor Source(width: int(4)) { +reactor Source(width: int = 4) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -18,7 +18,7 @@ reactor Source(width: int(4)) { =} } -reactor Computation(iterations: int(100000000)) { +reactor Computation(iterations: int = 100000000) { input in: int output out: int @@ -34,8 +34,8 @@ reactor Computation(iterations: int(100000000)) { =} } -reactor Destination(width: int(4), iterations: int(100000000)) { - state s: int(0) +reactor Destination(width: int = 4, iterations: int = 100000000) { + state s: int = 0 input[width] in: int reaction(in) {= @@ -61,7 +61,7 @@ reactor Destination(width: int(4), iterations: int(100000000)) { =} } -main reactor ThreadedMultiport(width: int(4), iterations: int(100000000)) { +main reactor ThreadedMultiport(width: int = 4, iterations: int = 100000000) { a = new Source(width = width) t = new[width] Computation(iterations = iterations) b = new Destination(width = width, iterations = iterations) diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 9db95faaf0..4037e8c193 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -15,7 +15,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= lf_set(out, self->s); @@ -39,8 +39,8 @@ reactor TakeTime { =} } -reactor Destination(width: int(4)) { - state s: int(400000000) +reactor Destination(width: int = 4) { + state s: int = 400000000 input[width] in: int reaction(in) {= @@ -57,7 +57,7 @@ reactor Destination(width: int(4)) { =} } -main reactor ThreadedThreaded(width: int(4)) { +main reactor ThreadedThreaded(width: int = 4) { a = new Source() t = new[width] TakeTime() (a.out)+ -> t.in diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index 97bb9cfec6..8d3824af47 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int - state s: int(1) + state s: int = 1 reaction(x) {= // printf("%d\n", x->value); @@ -38,7 +38,7 @@ reactor Destination { =} } -main reactor(period: time(1 sec)) { +main reactor(period: time = 1 sec) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 993366a2c0..3a7e2181d7 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -12,7 +12,7 @@ import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool(false) + state success: bool = false reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index 4a0bdd62a3..9b24ef080f 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -12,7 +12,7 @@ import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool(false) + state success: bool = false reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index ff2f436e85..71da79c7ef 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -10,7 +10,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= lf_set(out, self->s); @@ -18,10 +18,10 @@ reactor Source { =} } -reactor TakeTime(bank_index: int(0)) { +reactor TakeTime(bank_index: int = 0) { input in: int output out: int - state event: char*("No ID") + state event: char* = "No ID" reaction(startup) {= // Construct an id string for a user trace event. @@ -57,9 +57,9 @@ reactor TakeTime(bank_index: int(0)) { =} } -reactor Destination(width: int(4)) { - state s: int(400000000) - state count: int(0) +reactor Destination(width: int = 4) { + state s: int = 400000000 + state count: int = 0 input[width] in: int reaction(startup) {= @@ -86,7 +86,7 @@ reactor Destination(width: int(4)) { =} } -main reactor(width: int(4)) { +main reactor(width: int = 4) { a = new Source() t = new[width] TakeTime() (a.out)+ -> t.in diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index 9eb6898a9d..4a120c5e1e 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -15,7 +15,9 @@ target C { import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" -federated reactor DistributedCountContainerized(offset: time(200 msec)) at rti { +federated reactor DistributedCountContainerized( + offset: time = 200 msec +) at rti { c = new Count() p = new Print() c.out -> p.in after offset diff --git a/test/C/src/federated/BroadcastFeedback.lf b/test/C/src/federated/BroadcastFeedback.lf index 0c7146b8f7..2bef908d2d 100644 --- a/test/C/src/federated/BroadcastFeedback.lf +++ b/test/C/src/federated/BroadcastFeedback.lf @@ -9,7 +9,7 @@ target C { reactor SenderAndReceiver { output out: int input[2] in: int - state received: bool(false) + state received: bool = false reaction(startup) -> out {= lf_set(out, 42); =} diff --git a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf index 1632f0332a..d9edbc954b 100644 --- a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -8,7 +8,7 @@ target C { reactor SenderAndReceiver { output out: int input[2] in: int - state received: bool(false) + state received: bool = false r = new Receiver() in -> r.in @@ -18,7 +18,7 @@ reactor SenderAndReceiver { reactor Receiver { input[2] in: int - state received: bool(false) + state received: bool = false reaction(in) {= if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { diff --git a/test/C/src/federated/CycleDetection.lf b/test/C/src/federated/CycleDetection.lf index 90ce0faba2..d22837bc1f 100644 --- a/test/C/src/federated/CycleDetection.lf +++ b/test/C/src/federated/CycleDetection.lf @@ -10,7 +10,7 @@ reactor CAReplica { input remote_update: int input query: int - state balance: int(0) + state balance: int = 0 output response: int diff --git a/test/C/src/federated/DecentralizedP2PComm.lf b/test/C/src/federated/DecentralizedP2PComm.lf index 5791ddd8a7..0ca6a10e6f 100644 --- a/test/C/src/federated/DecentralizedP2PComm.lf +++ b/test/C/src/federated/DecentralizedP2PComm.lf @@ -6,15 +6,15 @@ target C { } reactor Platform( - start: int(0), - expected_start: int(0), - stp_offset_param: time(0) + start: int = 0, + expected_start: int = 0, + stp_offset_param: time = 0 ) { input in: int output out: int timer t(0, 100 msec) - state count: int(start) - state expected: int(expected_start) + state count: int = start + state expected: int = expected_start reaction(t) -> out {= lf_set(out, self->count++); =} diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 3b872b8408..fca2149fcf 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -11,10 +11,10 @@ target C { coordination: decentralized } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -29,7 +29,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int - state s: int(1) + state s: int = 1 reaction(x) {= lf_print("Received %d", x->value); @@ -48,7 +48,7 @@ reactor Destination { =} } -federated reactor(period: time(10 usec)) { +federated reactor(period: time = 10 usec) { c = new Clock(period = period) d = new Destination() c.y -> d.x diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 49562c7e77..8468e1dc81 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -12,10 +12,10 @@ target C { coordination: decentralized } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= (self->count)++; @@ -30,7 +30,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int - state s: int(1) + state s: int = 1 reaction(x) {= // printf("%d\n", x->value); @@ -46,7 +46,7 @@ reactor Destination { =} } -federated reactor(period: time(10 usec)) { +federated reactor(period: time = 10 usec) { c = new Clock(period = period) d = new Destination() c.y ~> d.x diff --git a/test/C/src/federated/DistributedBank.lf b/test/C/src/federated/DistributedBank.lf index 9dd1247980..84acb00031 100644 --- a/test/C/src/federated/DistributedBank.lf +++ b/test/C/src/federated/DistributedBank.lf @@ -6,7 +6,7 @@ target C { reactor Node { timer t(0, 100 msec) - state count: int(0) + state count: int = 0 reaction(t) {= lf_print("Hello world %d.", self->count++); =} diff --git a/test/C/src/federated/DistributedBankToMultiport.lf b/test/C/src/federated/DistributedBankToMultiport.lf index b392b3e603..796db0718e 100644 --- a/test/C/src/federated/DistributedBankToMultiport.lf +++ b/test/C/src/federated/DistributedBankToMultiport.lf @@ -7,7 +7,7 @@ import Count from "../lib/Count.lf" reactor Destination { input[2] in: int - state count: int(1) + state count: int = 1 reaction(in) {= for (int i = 0; i < in_width; i++) { diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 7ffd4eb8e2..2ebdda169a 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -14,7 +14,7 @@ import Count from "../lib/Count.lf" reactor Print { input in: int - state c: int(1) + state c: int = 1 reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); @@ -35,7 +35,7 @@ reactor Print { =} } -federated reactor DistributedCount(offset: time(200 msec)) { +federated reactor DistributedCount(offset: time = 200 msec) { c = new Count() p = new Print() c.out -> p.in after offset diff --git a/test/C/src/federated/DistributedCountDecentralized.lf b/test/C/src/federated/DistributedCountDecentralized.lf index e7ee0a7d77..631dfab0c0 100644 --- a/test/C/src/federated/DistributedCountDecentralized.lf +++ b/test/C/src/federated/DistributedCountDecentralized.lf @@ -14,7 +14,7 @@ import Count from "../lib/Count.lf" reactor Print { input in: int - state c: int(1) + state c: int = 1 reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedCountDecentralizedLate.lf b/test/C/src/federated/DistributedCountDecentralizedLate.lf index fa85987e87..9fb6d3b064 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLate.lf @@ -15,12 +15,12 @@ import Count from "../lib/Count.lf" reactor Print { input in: int // STP () - state success: int(0) // STP(in, 30 msec); - state success_stp_violation: int(0) + state success: int = 0 // STP(in, 30 msec); + state success_stp_violation: int = 0 // Force a timer to be invoke periodically to ensure logical time will // advance in the absence of incoming messages. timer t(0, 10 msec) - state c: int(0) + state c: int = 0 reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf index 26c20521e3..31ab87e110 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -17,12 +17,12 @@ import Count from "../lib/Count.lf" reactor ImportantActuator { input in: int - state success: int(0) - state success_stp_violation: int(0) + state success: int = 0 + state success_stp_violation: int = 0 // Force a timer to be invoke periodically timer t(0, 10 msec) // to ensure logical time will advance in the absence of incoming messages. - state c: int(0) + state c: int = 0 reaction(in) {= tag_t current_tag = lf_tag(); @@ -79,7 +79,7 @@ reactor Receiver { // Force a timer to be invoke periodically timer t(0, 10 msec) // to ensure logical time will advance in the absence of incoming messages. - state c: int(0) + state c: int = 0 p = new Print() a = new ImportantActuator() in -> p.in diff --git a/test/C/src/federated/DistributedCountPhysical.lf b/test/C/src/federated/DistributedCountPhysical.lf index 67d90ec4c1..9e1e15f775 100644 --- a/test/C/src/federated/DistributedCountPhysical.lf +++ b/test/C/src/federated/DistributedCountPhysical.lf @@ -13,7 +13,7 @@ target C { reactor Count { timer t(200 msec, 1 sec) - state s: int(0) + state s: int = 0 output out: int reaction(t) -> out {= @@ -24,7 +24,7 @@ reactor Count { reactor Print { input in: int - state c: int(0) + state c: int = 0 reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf index 2d13891bae..b0da42218a 100644 --- a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -12,7 +12,7 @@ import Count from "../lib/Count.lf" reactor Print { input in: int - state c: int(1) + state c: int = 1 reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf index 6bc50fce88..e821e4fb70 100644 --- a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf @@ -14,7 +14,7 @@ target C { reactor Count { timer t(200 msec, 1 sec) - state s: int(0) + state s: int = 0 output out: int reaction(t) -> out {= @@ -25,7 +25,7 @@ reactor Count { reactor Print { input in: int - state c: int(0) + state c: int = 0 reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedDoublePort.lf b/test/C/src/federated/DistributedDoublePort.lf index 2490df67bf..87de1ddb28 100644 --- a/test/C/src/federated/DistributedDoublePort.lf +++ b/test/C/src/federated/DistributedDoublePort.lf @@ -14,7 +14,7 @@ target C { import Count from "../lib/Count.lf" reactor CountMicrostep { - state count: int(1) + state count: int = 1 output out: int logical action act: int timer t(0, 1 sec) diff --git a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf index 078b15ed02..acbbaf4035 100644 --- a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf @@ -11,8 +11,8 @@ import TestCount from "../lib/TestCount.lf" reactor WithLogicalAction { output out: int - state thread_id: lf_thread_t(0) - state counter: int(1) + state thread_id: lf_thread_t = 0 + state counter: int = 1 logical action act(0): int reaction(startup, act) -> act, out {= diff --git a/test/C/src/federated/DistributedLoopedAction.lf b/test/C/src/federated/DistributedLoopedAction.lf index 1a70412696..8218e73646 100644 --- a/test/C/src/federated/DistributedLoopedAction.lf +++ b/test/C/src/federated/DistributedLoopedAction.lf @@ -10,11 +10,14 @@ target C { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver(take_a_break_after: int(10), break_interval: time(400 msec)) { +reactor Receiver( + take_a_break_after: int = 10, + break_interval: time = 400 msec +) { input in: int - state received_messages: int(0) - state total_received_messages: int(0) - state breaks: int(0) + state received_messages: int = 0 + state total_received_messages: int = 0 + state breaks: int = 0 timer t(0, 1 msec) // This will impact the performance // but forces the logical time to advance Comment this line for a more diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index f1addfb63c..17842809fa 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -20,11 +20,14 @@ target C { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver(take_a_break_after: int(10), break_interval: time(400 msec)) { +reactor Receiver( + take_a_break_after: int = 10, + break_interval: time = 400 msec +) { input in: int - state received_messages: int(0) - state total_received_messages: int(0) - state breaks: int(0) + state received_messages: int = 0 + state total_received_messages: int = 0 + state breaks: int = 0 reaction(in) {= tag_t current_tag = lf_tag(); @@ -77,12 +80,12 @@ reactor Receiver(take_a_break_after: int(10), break_interval: time(400 msec)) { } reactor STPReceiver( - take_a_break_after: int(10), - break_interval: time(400 msec), - stp_offset: time(0) + take_a_break_after: int = 10, + break_interval: time = 400 msec, + stp_offset: time = 0 ) { input in: int - state last_time_updated_stp: time(0) + state last_time_updated_stp: time = 0 receiver = new Receiver(take_a_break_after = 10, break_interval = 400 msec) timer t(0, 1 msec) // Force advancement of logical time diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index 7b42628683..454577ff35 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -16,10 +16,10 @@ target C { } } -reactor Sender(take_a_break_after: int(10), break_interval: time(550 msec)) { +reactor Sender(take_a_break_after: int = 10, break_interval: time = 550 msec) { output out: int physical action act - state sent_messages: int(0) + state sent_messages: int = 0 reaction(startup, act) -> act, out {= // Send a message on out @@ -35,11 +35,14 @@ reactor Sender(take_a_break_after: int(10), break_interval: time(550 msec)) { =} } -reactor Receiver(take_a_break_after: int(10), break_interval: time(550 msec)) { +reactor Receiver( + take_a_break_after: int = 10, + break_interval: time = 550 msec +) { input in: int - state received_messages: int(0) - state total_received_messages: int(0) - state breaks: int(0) + state received_messages: int = 0 + state total_received_messages: int = 0 + state breaks: int = 0 timer t(0, 1 msec) // This will impact the performance // but forces the logical time to advance Comment this line for a more diff --git a/test/C/src/federated/DistributedMultiport.lf b/test/C/src/federated/DistributedMultiport.lf index 28156d4b70..3853629731 100644 --- a/test/C/src/federated/DistributedMultiport.lf +++ b/test/C/src/federated/DistributedMultiport.lf @@ -7,7 +7,7 @@ target C { reactor Source { output[4] out: int timer t(0, 100 msec) - state count: int(0) + state count: int = 0 reaction(t) -> out {= for (int i = 0; i < out_width; i++) { @@ -18,7 +18,7 @@ reactor Source { reactor Destination { input[4] in: int - state count: int(0) + state count: int = 0 reaction(in) {= for (int i = 0; i < in_width; i++) { diff --git a/test/C/src/federated/DistributedMultiportToBank.lf b/test/C/src/federated/DistributedMultiportToBank.lf index 503dec692e..0accaf8c60 100644 --- a/test/C/src/federated/DistributedMultiportToBank.lf +++ b/test/C/src/federated/DistributedMultiportToBank.lf @@ -6,7 +6,7 @@ target C { reactor Source { output[2] out: int timer t(0, 100 msec) - state count: int(0) + state count: int = 0 reaction(t) -> out {= for (int i = 0; i < out_width; i++) { @@ -18,7 +18,7 @@ reactor Source { reactor Destination { input in: int - state count: int(0) + state count: int = 0 reaction(in) {= lf_print("Received %d.", in->value); diff --git a/test/C/src/federated/DistributedMultiportToken.lf b/test/C/src/federated/DistributedMultiportToken.lf index 065f480e11..dfb791d861 100644 --- a/test/C/src/federated/DistributedMultiportToken.lf +++ b/test/C/src/federated/DistributedMultiportToken.lf @@ -8,7 +8,7 @@ target C { reactor Source { output[4] out: char* timer t(0, 200 msec) - state count: int(0) + state count: int = 0 reaction(t) -> out {= for (int i = 0; i < out_width; i++) { diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index 0b9ca0cd17..e18ea4ac04 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -32,7 +32,7 @@ reactor Sender { reactor Receiver { input in: int - state success: int(0) + state success: int = 0 reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/federated/DistributedPhysicalActionUpstream.lf b/test/C/src/federated/DistributedPhysicalActionUpstream.lf index 2cc6735884..47280a24b8 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstream.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstream.lf @@ -30,7 +30,7 @@ preamble {= reactor WithPhysicalAction { output out: int - state thread_id: lf_thread_t(0) + state thread_id: lf_thread_t = 0 physical action act(0): int reaction(startup) -> act {= diff --git a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf index 0a6ee31e62..66bbb964e1 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf @@ -30,7 +30,7 @@ preamble {= reactor WithPhysicalAction { output out: int - state thread_id: lf_thread_t(0) + state thread_id: lf_thread_t = 0 physical action act(0): int reaction(startup) -> act {= diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index cf103d8beb..2d4a616664 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -10,7 +10,7 @@ reactor Sender { output out: int timer t(0, 1 usec) logical action act - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false reaction(t, act) -> out, act {= lf_print("Sending 42 at (%lld, %u).", @@ -63,10 +63,10 @@ reactor Sender { } reactor Receiver( - stp_offset: time(10 msec) // Used in the decentralized variant of the test + stp_offset: time = 10 msec // Used in the decentralized variant of the test ) { input in: int - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false reaction(in) {= lf_print("Received %d at (%lld, %u).", diff --git a/test/C/src/federated/DistributedToken.lf b/test/C/src/federated/DistributedToken.lf index c408af6ad2..1068bd5f85 100644 --- a/test/C/src/federated/DistributedToken.lf +++ b/test/C/src/federated/DistributedToken.lf @@ -26,11 +26,11 @@ target C { * @param root The root string. * @output message The message. */ -reactor MessageGenerator(root: string("")) { +reactor MessageGenerator(root: string = "") { // Output type char* instead of string is used for dynamically allocated // character arrays (as opposed to static constant strings). output message: char* - state count: int(1) + state count: int = 1 // Send first message after 1 sec so that the startup reactions do not // factor into the transport time measurement on the first message. timer t(1 sec, 1 sec) @@ -57,7 +57,7 @@ reactor MessageGenerator(root: string("")) { */ reactor PrintMessage { input message: char* - state count: int(0) + state count: int = 0 reaction(message) {= printf("PrintMessage: At (elapsed) logical time %lld, receiver receives: %s\n", diff --git a/test/C/src/federated/FeedbackDelay.lf b/test/C/src/federated/FeedbackDelay.lf index 6495fde8db..997a4ad012 100644 --- a/test/C/src/federated/FeedbackDelay.lf +++ b/test/C/src/federated/FeedbackDelay.lf @@ -7,8 +7,8 @@ reactor PhysicalPlant { input control: double output sensor: double timer t(0, 33 msec) - state last_sensor_time: time(0) - state previous_sensor_time: time(0) + state last_sensor_time: time = 0 + state previous_sensor_time: time = 0 reaction(t) -> sensor {= lf_set(sensor, 42); @@ -27,8 +27,8 @@ reactor Controller { input sensor: double output control: double - state latest_control: double(0.0) - state first: bool(true) + state latest_control: double = 0.0 + state first: bool = true output request_for_planning: double input planning: double diff --git a/test/C/src/federated/FeedbackDelaySimple.lf b/test/C/src/federated/FeedbackDelaySimple.lf index 2f00000e03..0c9b147cda 100644 --- a/test/C/src/federated/FeedbackDelaySimple.lf +++ b/test/C/src/federated/FeedbackDelaySimple.lf @@ -6,7 +6,7 @@ reactor Loop { input in: int output out: int timer t(0, 100 msec) - state count: int(1) + state count: int = 1 reaction(in) {= lf_print("Received %d.", in->value); diff --git a/test/C/src/federated/HelloDistributed.lf b/test/C/src/federated/HelloDistributed.lf index 14b446f26d..6841bf91bc 100644 --- a/test/C/src/federated/HelloDistributed.lf +++ b/test/C/src/federated/HelloDistributed.lf @@ -19,7 +19,7 @@ reactor Source { reactor Destination { input in: string - state received: bool(false) + state received: bool = false reaction(startup) {= lf_print("Destination started."); =} diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index 9643d3f1f3..7fdc972b5a 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -14,11 +14,11 @@ target C { logging: DEBUG } -reactor Looper(incr: int(1), delay: time(0 msec)) { +reactor Looper(incr: int = 1, delay: time = 0 msec) { input in: int output out: int physical action a(delay) - state count: int(0) + state count: int = 0 timer t(0, 1 sec) @@ -42,7 +42,7 @@ reactor Looper(incr: int(1), delay: time(0 msec)) { =} } -federated reactor LoopDistributedCentralized(delay: time(0)) { +federated reactor LoopDistributedCentralized(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralized2.lf b/test/C/src/federated/LoopDistributedCentralized2.lf index c81a0f012e..82412e16fe 100644 --- a/test/C/src/federated/LoopDistributedCentralized2.lf +++ b/test/C/src/federated/LoopDistributedCentralized2.lf @@ -13,11 +13,11 @@ target C { timeout: 4 sec } -reactor Looper(incr: int(1), delay: time(0 msec)) { +reactor Looper(incr: int = 1, delay: time = 0 msec) { input in: int output out: int physical action a(delay) - state count: int(0) + state count: int = 0 timer t(0, 1 sec) @@ -41,11 +41,11 @@ reactor Looper(incr: int(1), delay: time(0 msec)) { =} } -reactor Looper2(incr: int(1), delay: time(0 msec)) { +reactor Looper2(incr: int = 1, delay: time = 0 msec) { input in: int output out: int physical action a(delay) - state count: int(0) + state count: int = 0 timer t(0, 1 sec) @@ -69,7 +69,7 @@ reactor Looper2(incr: int(1), delay: time(0 msec)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper() right = new Looper2(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf index e622e31979..44ce6e1681 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf @@ -27,11 +27,11 @@ preamble {= } =} -reactor Looper(incr: int(1), delay: time(0 msec)) { +reactor Looper(incr: int = 1, delay: time = 0 msec) { input in: int output out: int physical action a(delay) - state count: int(0) + state count: int = 0 reaction(startup) -> a {= // Start the thread that listens for Enter or Return. @@ -62,7 +62,7 @@ reactor Looper(incr: int(1), delay: time(0 msec)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf index a1e6e87b6e..f9b088b7d1 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf @@ -14,11 +14,11 @@ target C { timeout: 5 sec } -reactor Looper(incr: int(1), delay: time(0 msec)) { +reactor Looper(incr: int = 1, delay: time = 0 msec) { input in: int output out: int - state count: int(0) - state received_count: int(0) + state count: int = 0 + state received_count: int = 0 timer t(0, 1 sec) reaction(t) -> out {= @@ -48,7 +48,7 @@ reactor Looper(incr: int(1), delay: time(0 msec)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index ef18cadfbf..17177aadb3 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -15,11 +15,11 @@ target C { timeout: 5 sec } -reactor Contained(incr: int(1)) { +reactor Contained(incr: int = 1) { timer t(0, 1 sec) input in: int - state count: int(0) - state received_count: int(0) + state count: int = 0 + state received_count: int = 0 reaction(t) {= self->count += self->incr; =} @@ -32,10 +32,10 @@ reactor Contained(incr: int(1)) { =} } -reactor Looper(incr: int(1), delay: time(0 msec)) { +reactor Looper(incr: int = 1, delay: time = 0 msec) { input in: int output out: int - state count: int(0) + state count: int = 0 timer t(0, 1 sec) c = new Contained(incr = incr) @@ -62,7 +62,7 @@ reactor Looper(incr: int(1), delay: time(0 msec)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index c2d4bcb297..ae64e6e71a 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -23,11 +23,11 @@ preamble {= } =} -reactor Looper(incr: int(1), delay: time(0 msec), stp_offset: time(0)) { +reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { input in: int output out: int physical action a(stp_offset) - state count: int(0) + state count: int = 0 reaction(startup) -> a {= // Start the thread that listens for Enter or Return. @@ -69,7 +69,7 @@ reactor Looper(incr: int(1), delay: time(0 msec), stp_offset: time(0)) { =} } -federated reactor LoopDistributedDecentralized(delay: time(0)) { +federated reactor LoopDistributedDecentralized(delay: time = 0) { left = new Looper(stp_offset = 900 usec) right = new Looper(incr = -1, stp_offset = 2400 usec) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index bba7c7ffaa..31b7eb0f6e 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -27,13 +27,13 @@ preamble {= } =} -reactor Looper(incr: int(1), delay: time(0 msec)) { +reactor Looper(incr: int = 1, delay: time = 0 msec) { input in: int input in2: int output out: int output out2: int physical action a(delay) - state count: int(0) + state count: int = 0 timer t(0, 1 sec) reaction(startup) -> a {= @@ -82,7 +82,7 @@ reactor Looper(incr: int(1), delay: time(0 msec)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index 1824d9ec93..492cd8875b 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -9,9 +9,9 @@ target C { import Count from "../lib/Count.lf" -reactor Print(STP_offset_param: time(0)) { +reactor Print(STP_offset_param: time = 0) { input in: int - state c: int(1) + state c: int = 1 reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/PingPongDistributed.lf b/test/C/src/federated/PingPongDistributed.lf index a1d321cc6d..e16de50ed2 100644 --- a/test/C/src/federated/PingPongDistributed.lf +++ b/test/C/src/federated/PingPongDistributed.lf @@ -23,7 +23,7 @@ target C import Ping, Pong from "PingPongDistributedPhysical.lf" -federated reactor(count: int(10)) { +federated reactor(count: int = 10) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send -> pong.receive diff --git a/test/C/src/federated/PingPongDistributedPhysical.lf b/test/C/src/federated/PingPongDistributedPhysical.lf index 95427c2a29..d9ba517c59 100644 --- a/test/C/src/federated/PingPongDistributedPhysical.lf +++ b/test/C/src/federated/PingPongDistributedPhysical.lf @@ -26,10 +26,10 @@ */ target C -reactor Ping(count: int(10)) { +reactor Ping(count: int = 10) { input receive: int output send: int - state pingsLeft: int(count) + state pingsLeft: int = count logical action serve reaction(startup, serve) -> send {= @@ -46,10 +46,10 @@ reactor Ping(count: int(10)) { =} } -reactor Pong(expected: int(10)) { +reactor Pong(expected: int = 10) { input receive: int output send: int - state count: int(0) + state count: int = 0 reaction(receive) -> send {= self->count++; @@ -71,7 +71,7 @@ reactor Pong(expected: int(10)) { =} } -federated reactor(count: int(10)) { +federated reactor(count: int = 10) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send ~> pong.receive diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 5fd4b0c376..05932b1937 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -15,7 +15,7 @@ import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - state successes: int(0) + state successes: int = 0 timer t(0, 1 sec) logical action act(0) diff --git a/test/C/src/federated/failing/ClockSync.lf b/test/C/src/federated/failing/ClockSync.lf index e843f0c549..1231ce9cbf 100644 --- a/test/C/src/federated/failing/ClockSync.lf +++ b/test/C/src/federated/failing/ClockSync.lf @@ -29,7 +29,7 @@ target C { } /** Reactor that outputs periodically. */ -reactor Ticker(period: time(1600 msec)) { +reactor Ticker(period: time = 1600 msec) { output out: int timer tick(0, period) diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped.lf b/test/C/src/federated/failing/DistributedDoublePortLooped.lf index 4eca2cee76..67a3300c74 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped.lf @@ -19,7 +19,7 @@ reactor Foo { } reactor Count { - state count: int(1) + state count: int = 1 input in1: int input in2: int input in3: int @@ -37,7 +37,7 @@ reactor Count { } reactor CountMicrostep { - state count: int(1) + state count: int = 1 output out: int logical action act: int timer t(0, 1 msec) diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf index 04ea02c4e8..56a873e1bc 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf @@ -12,7 +12,7 @@ target C { } reactor Count { - state count: int(1) + state count: int = 1 input in: int output out: int timer t(0, 1 msec) @@ -26,7 +26,7 @@ reactor Count { } reactor CountMicrostep { - state count: int(1) + state count: int = 1 output out: int logical action act: int timer t(0, 1 msec) diff --git a/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf b/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf index 19779de3d2..97fa16b016 100644 --- a/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf +++ b/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf @@ -31,7 +31,7 @@ reactor Sender { reactor Receiver { input in: int - state success: int(0) + state success: int = 0 reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf index ee9fc56d83..b991662a05 100644 --- a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf +++ b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf @@ -11,11 +11,11 @@ target C { timeout: 4900 msec } -reactor Looper(incr: int(1), delay: time(0 msec), stp_offset: time(0)) { +reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { input in: int output out: int - state count: int(0) - state received_count: int(0) + state count: int = 0 + state received_count: int = 0 timer t(0, 1 sec) reaction(t) -> out {= @@ -57,7 +57,7 @@ reactor Looper(incr: int(1), delay: time(0 msec), stp_offset: time(0)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper(stp_offset = 5 msec) right = new Looper(incr = -1, stp_offset = 5 msec) left.out -> right.in diff --git a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf index 6cf9236901..357b7f2f2d 100644 --- a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf @@ -1,6 +1,7 @@ /** - * This tests that the precedence order of reaction invocation is kept - * in the hierarchy of reactors when a feedback loop is present in decentralized coordination. + * This tests that the precedence order of reaction invocation is kept in the + * hierarchy of reactors when a feedback loop is present in decentralized + * coordination. * * @author Edward A. Lee * @author Soroush Bateni @@ -11,37 +12,39 @@ target C { timeout: 4900 msec } -import Contained from "../LoopDistributedCentralizedPrecedenceHierarchy.lf"; +import Contained from "../LoopDistributedCentralizedPrecedenceHierarchy.lf" -reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { - input in:int; - output out:int; - state count:int(0); - timer t(0, 1 sec); +reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { + input in: int + output out: int + state count: int = 0 + timer t(0, 1 sec) - c = new Contained(incr = incr); + c = new Contained(incr = incr) + in -> c.in reaction(t) -> out {= lf_set(out, self->count); self->count += self->incr; =} + reaction(in) {= instant_t time_lag = lf_time_physical() - lf_time_logical(); char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 lf_readable_time(time_buffer, time_lag); lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} STP (stp_offset) {= + =} STP(stp_offset) {= instant_t time_lag = lf_time_physical() - lf_time_logical(); char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 lf_readable_time(time_buffer, time_lag); lf_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} deadline (10 msec) {= + =} deadline(10 msec) {= instant_t time_lag = lf_time_physical() - lf_time_logical(); char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 lf_readable_time(time_buffer, time_lag); lf_print("Deadline miss. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); =} - in->c.in; + reaction(shutdown) {= lf_print("******* Shutdown invoked."); if (self->count != 5 * self->incr) { @@ -49,9 +52,10 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { } =} } -federated reactor (delay:time(0)) { - left = new Looper(stp_offset = 5 msec); - right = new Looper(incr = -1, stp_offset = 5 msec); - left.out -> right.in; - right.out -> left.in; + +federated reactor(delay: time = 0) { + left = new Looper(stp_offset = 5 msec) + right = new Looper(incr = -1, stp_offset = 5 msec) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/lib/Count.lf b/test/C/src/lib/Count.lf index fc95ead637..70291e783f 100644 --- a/test/C/src/lib/Count.lf +++ b/test/C/src/lib/Count.lf @@ -1,7 +1,7 @@ target C -reactor Count(offset: time(0), period: time(1 sec)) { - state count: int(1) +reactor Count(offset: time = 0, period: time = 1 sec) { + state count: int = 1 output out: int timer t(offset, period) diff --git a/test/C/src/lib/InternalDelay.lf b/test/C/src/lib/InternalDelay.lf index 013b916ecc..fbbf2f0cb6 100644 --- a/test/C/src/lib/InternalDelay.lf +++ b/test/C/src/lib/InternalDelay.lf @@ -1,6 +1,6 @@ target C -reactor InternalDelay(delay: int(10 msec)) { +reactor InternalDelay(delay: int = 10 msec) { input in: int output out: int logical action d: int diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index 2e24f1677f..b996fe6ac5 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -11,10 +11,10 @@ target C * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after: int(10), break_interval: time(400 msec)) { +reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { output out: int logical action act - state sent_messages: int(0) + state sent_messages: int = 0 reaction(startup, act) -> act, out {= // Send a message on out diff --git a/test/C/src/lib/Test.lf b/test/C/src/lib/Test.lf index ea341ae772..3ad7518d4e 100644 --- a/test/C/src/lib/Test.lf +++ b/test/C/src/lib/Test.lf @@ -1,8 +1,8 @@ target C -reactor TestDouble(expected: double[](1.0, 1.0, 1.0, 1.0)) { +reactor TestDouble(expected: double[] = {1.0, 1.0, 1.0, 1.0}) { input in: double - state count: int(0) + state count: int = 0 reaction(in) {= printf("Received: %f\n", in->value); diff --git a/test/C/src/lib/TestCount.lf b/test/C/src/lib/TestCount.lf index 3db3fbb2fc..d3f29aec6c 100644 --- a/test/C/src/lib/TestCount.lf +++ b/test/C/src/lib/TestCount.lf @@ -9,9 +9,9 @@ */ target C -reactor TestCount(start: int(1), stride: int(1), num_inputs: int(1)) { - state count: int(start) - state inputs_received: int(0) +reactor TestCount(start: int = 1, stride: int = 1, num_inputs: int = 1) { + state count: int = start + state inputs_received: int = 0 input in: int reaction(in) {= diff --git a/test/C/src/lib/TestCountMultiport.lf b/test/C/src/lib/TestCountMultiport.lf index 2a24922ef8..5a2db4b029 100644 --- a/test/C/src/lib/TestCountMultiport.lf +++ b/test/C/src/lib/TestCountMultiport.lf @@ -12,13 +12,13 @@ target C reactor TestCountMultiport( - start: int(1), - stride: int(1), - num_inputs: int(1), - width: int(2) + start: int = 1, + stride: int = 1, + num_inputs: int = 1, + width: int = 2 ) { - state count: int(start) - state inputs_received: int(0) + state count: int = start + state inputs_received: int = 0 input[width] in: int reaction(in) {= diff --git a/test/C/src/modal_models/ConvertCaseTest.lf b/test/C/src/modal_models/ConvertCaseTest.lf index 494a3c273c..5475edaa35 100644 --- a/test/C/src/modal_models/ConvertCaseTest.lf +++ b/test/C/src/modal_models/ConvertCaseTest.lf @@ -83,9 +83,9 @@ reactor Converter { } } -reactor InputFeeder(message: string("")) { +reactor InputFeeder(message: string = "") { output character: char - state idx: int(0) + state idx: int = 0 timer t(0, 250 msec) diff --git a/test/C/src/modal_models/Count3Modes.lf b/test/C/src/modal_models/Count3Modes.lf index 5ef26ccde0..862915abed 100644 --- a/test/C/src/modal_models/Count3Modes.lf +++ b/test/C/src/modal_models/Count3Modes.lf @@ -34,7 +34,7 @@ main reactor { timer stepper(0, 250 msec) counter = new CounterCycle() - state expected_value: int(1) + state expected_value: int = 1 // Trigger reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} diff --git a/test/C/src/modal_models/MixedReactions.lf b/test/C/src/modal_models/MixedReactions.lf index e0c9c7f0f7..78ea39c95c 100644 --- a/test/C/src/modal_models/MixedReactions.lf +++ b/test/C/src/modal_models/MixedReactions.lf @@ -8,8 +8,8 @@ target C { } main reactor { - state x: int(0) - state first: bool(true) + state x: int = 0 + state first: bool = true timer t(0, 100 msec) diff --git a/test/C/src/modal_models/ModalAfter.lf b/test/C/src/modal_models/ModalAfter.lf index 038a368cc9..270fd88d05 100644 --- a/test/C/src/modal_models/ModalAfter.lf +++ b/test/C/src/modal_models/ModalAfter.lf @@ -45,7 +45,7 @@ reactor Modal { } } -reactor Producer(mode_id: int(0)) { +reactor Producer(mode_id: int = 0) { output product: int timer t(0, 750 msec) @@ -56,7 +56,7 @@ reactor Producer(mode_id: int(0)) { =} } -reactor Consumer(mode_id: int(0)) { +reactor Consumer(mode_id: int = 0) { input product: int output report: int diff --git a/test/C/src/modal_models/ModalCycleBreaker.lf b/test/C/src/modal_models/ModalCycleBreaker.lf index 680323a729..cee4fabfec 100644 --- a/test/C/src/modal_models/ModalCycleBreaker.lf +++ b/test/C/src/modal_models/ModalCycleBreaker.lf @@ -42,11 +42,11 @@ reactor Modal { } } -reactor Counter(period: time(1 sec)) { +reactor Counter(period: time = 1 sec) { output value: int timer t(0, period) - state curval: int(0) + state curval: int = 0 reaction(t) -> value {= lf_set(value, self->curval++); =} } diff --git a/test/C/src/modal_models/ModalStateReset.lf b/test/C/src/modal_models/ModalStateReset.lf index cd963cfd8d..61563162b6 100644 --- a/test/C/src/modal_models/ModalStateReset.lf +++ b/test/C/src/modal_models/ModalStateReset.lf @@ -14,7 +14,7 @@ reactor Modal { output count1: int output count2: int - state counter0: int(0) + state counter0: int = 0 reaction(next) -> count0 {= printf("Counter0: %d\n", self->counter0); @@ -22,7 +22,7 @@ reactor Modal { =} initial mode One { - state counter1: int(0) + state counter1: int = 0 timer T1(0 msec, 250 msec) reaction(reset) {= self->counter1 = 0; =} @@ -39,7 +39,7 @@ reactor Modal { } mode Two { - state counter2: int(-2) + state counter2: int = -2 timer T2(0 msec, 250 msec) reaction(reset) {= self->counter2 = -2; =} diff --git a/test/C/src/modal_models/ModalStateResetAuto.lf b/test/C/src/modal_models/ModalStateResetAuto.lf index 24cfe9b187..a2b6b105f0 100644 --- a/test/C/src/modal_models/ModalStateResetAuto.lf +++ b/test/C/src/modal_models/ModalStateResetAuto.lf @@ -14,7 +14,7 @@ reactor Modal { output count1: int output count2: int - state counter0: int(0) + state counter0: int = 0 reaction(next) -> count0 {= printf("Counter0: %d\n", self->counter0); @@ -22,7 +22,7 @@ reactor Modal { =} initial mode One { - state counter1: int(0) + state counter1: int = 0 timer T1(0 msec, 250 msec) reaction(T1) -> count1 {= printf("Counter1: %d\n", self->counter1); @@ -37,7 +37,7 @@ reactor Modal { } mode Two { - reset state counter2: int(-2) + reset state counter2: int = -2 timer T2(0 msec, 250 msec) reaction(T2) -> count2 {= printf("Counter2: %d\n", self->counter2); diff --git a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf index 7e75afec13..60fa76dd1e 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -28,11 +28,11 @@ reactor Modal { } } -reactor Counter(period: time(1 sec)) { +reactor Counter(period: time = 1 sec) { output value: int timer t(0, period) - reset state curval: int(0) + reset state curval: int = 0 reaction(t) -> value {= lf_set(value, self->curval++); =} } diff --git a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 48b335d2b3..dff82c602f 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -31,11 +31,11 @@ reactor Modal { } } -reactor Counter(period: time(1 sec)) { +reactor Counter(period: time = 1 sec) { output value: int timer t(0, period) - reset state curval: int(0) + reset state curval: int = 0 reaction(t) -> value {= lf_set(value, self->curval++); =} } diff --git a/test/C/src/modal_models/util/TraceTesting.lf b/test/C/src/modal_models/util/TraceTesting.lf index 7d5a335db2..247b3f1def 100644 --- a/test/C/src/modal_models/util/TraceTesting.lf +++ b/test/C/src/modal_models/util/TraceTesting.lf @@ -6,17 +6,17 @@ preamble {= =} reactor TraceTesting( - events_size: int(0), - trace_size: int(0), - trace: int[](0), - training: bool(false) + events_size: int = 0, + trace_size: int = 0, + trace: int[] = 0, + training: bool = false ) { input[events_size] events: int - state last_reaction_time: int(0) - state trace_idx: int(0) - state recorded_events: int*(0) - state recorded_events_next: int(0) + state last_reaction_time: int = 0 + state trace_idx: int = 0 + state recorded_events: int* = 0 + state recorded_events_next: int = 0 reaction(startup) {= self->last_reaction_time = lf_time_logical(); =} diff --git a/test/C/src/multiport/BankIndexInitializer.lf b/test/C/src/multiport/BankIndexInitializer.lf index b9b8803943..d8a2c5766e 100644 --- a/test/C/src/multiport/BankIndexInitializer.lf +++ b/test/C/src/multiport/BankIndexInitializer.lf @@ -3,15 +3,15 @@ target C preamble {= int table[] = {4, 3, 2, 1}; =} -reactor Source(bank_index: int(0), value: int(0)) { +reactor Source(bank_index: int = 0, value: int = 0) { output out: int reaction(startup) -> out {= lf_set(out, self->value); =} } -reactor Sink(width: int(4)) { +reactor Sink(width: int = 4) { input[width] in: int - state received: bool(false) + state received: bool = false reaction(in) {= for (int idx = 0; idx < in_width; idx++) { @@ -32,7 +32,7 @@ reactor Sink(width: int(4)) { =} } -main reactor(width: int(4)) { +main reactor(width: int = 4) { source = new[width] Source(value = {= table[bank_index] =}) sink = new Sink(width = width) source.out -> sink.in diff --git a/test/C/src/multiport/BankMultiportToReaction.lf b/test/C/src/multiport/BankMultiportToReaction.lf index c2eff34100..731cd6891b 100644 --- a/test/C/src/multiport/BankMultiportToReaction.lf +++ b/test/C/src/multiport/BankMultiportToReaction.lf @@ -13,8 +13,8 @@ reactor DoubleCount { } main reactor { - state count: int(1) - state received: bool(false) + state count: int = 1 + state received: bool = false s = new[2] DoubleCount() diff --git a/test/C/src/multiport/BankReactionsInContainer.lf b/test/C/src/multiport/BankReactionsInContainer.lf index 6533e7ed0b..98d7cf4e1f 100644 --- a/test/C/src/multiport/BankReactionsInContainer.lf +++ b/test/C/src/multiport/BankReactionsInContainer.lf @@ -5,10 +5,10 @@ target C { timeout: 1 sec } -reactor R(bank_index: int(0)) { +reactor R(bank_index: int = 0) { output[2] out: int input[2] in: int - state received: bool(false) + state received: bool = false reaction(startup) -> out {= for (int i = 0; i < out_width; i++) { @@ -42,7 +42,7 @@ reactor R(bank_index: int(0)) { main reactor { s = new[2] R() - state received: bool(false) + state received: bool = false reaction(startup) -> s.in {= int count = 0; diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index 587087d550..e1ffb4b2dd 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -7,10 +7,10 @@ */ target C -reactor A(bank_index: int(0)) { +reactor A(bank_index: int = 0) { input[4] in: int output out: int - state received: bool(false) + state received: bool = false reaction(startup) -> out {= lf_set(out, self->bank_index); =} diff --git a/test/C/src/multiport/BankToBank.lf b/test/C/src/multiport/BankToBank.lf index 19a784efd4..beb3a32fa8 100644 --- a/test/C/src/multiport/BankToBank.lf +++ b/test/C/src/multiport/BankToBank.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(bank_index: int(0)) { +reactor Source(bank_index: int = 0) { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= lf_set(out, self->s); @@ -15,8 +15,8 @@ reactor Source(bank_index: int(0)) { =} } -reactor Destination(bank_index: int(0)) { - state s: int(0) +reactor Destination(bank_index: int = 0) { + state s: int = 0 input in: int reaction(in) {= @@ -37,7 +37,7 @@ reactor Destination(bank_index: int(0)) { =} } -main reactor BankToBank(width: int(4)) { +main reactor BankToBank(width: int = 4) { a = new[width] Source() b = new[width] Destination() a.out -> b.in diff --git a/test/C/src/multiport/BankToBankMultiport.lf b/test/C/src/multiport/BankToBankMultiport.lf index 22c5821cc6..681538f116 100644 --- a/test/C/src/multiport/BankToBankMultiport.lf +++ b/test/C/src/multiport/BankToBankMultiport.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int(1)) { +reactor Source(width: int = 1) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -16,8 +16,8 @@ reactor Source(width: int(1)) { =} } -reactor Destination(width: int(1)) { - state s: int(6) +reactor Destination(width: int = 1) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -42,7 +42,7 @@ reactor Destination(width: int(1)) { =} } -main reactor BankToBankMultiport(bank_width: int(4)) { +main reactor BankToBankMultiport(bank_width: int = 4) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in diff --git a/test/C/src/multiport/BankToBankMultiportAfter.lf b/test/C/src/multiport/BankToBankMultiportAfter.lf index 38daec6ccf..db0ff7771e 100644 --- a/test/C/src/multiport/BankToBankMultiportAfter.lf +++ b/test/C/src/multiport/BankToBankMultiportAfter.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int(1)) { +reactor Source(width: int = 1) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -16,8 +16,8 @@ reactor Source(width: int(1)) { =} } -reactor Destination(width: int(1)) { - state s: int(6) +reactor Destination(width: int = 1) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -42,7 +42,7 @@ reactor Destination(width: int(1)) { =} } -main reactor(bank_width: int(4)) { +main reactor(bank_width: int = 4) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in after 200 msec diff --git a/test/C/src/multiport/BankToMultiport.lf b/test/C/src/multiport/BankToMultiport.lf index ee0ad53dc3..f72c104df7 100644 --- a/test/C/src/multiport/BankToMultiport.lf +++ b/test/C/src/multiport/BankToMultiport.lf @@ -1,15 +1,15 @@ // Test bank of reactors to multiport input with id parameter in the bank. target C -reactor Source(bank_index: int(0)) { +reactor Source(bank_index: int = 0) { output out: int reaction(startup) -> out {= lf_set(out, self->bank_index); =} } -reactor Sink(width: int(4)) { +reactor Sink(width: int = 4) { input[width] in: int - state received: bool(false) + state received: bool = false reaction(in) {= for (int i = 0; i < in_width; i++) { @@ -32,7 +32,7 @@ reactor Sink(width: int(4)) { =} } -main reactor BankToMultiport(width: int(5)) { +main reactor BankToMultiport(width: int = 5) { source = new[width] Source() sink = new Sink(width = width) source.out -> sink.in diff --git a/test/C/src/multiport/BankToReaction.lf b/test/C/src/multiport/BankToReaction.lf index c5d68cfe41..4e59352bd5 100644 --- a/test/C/src/multiport/BankToReaction.lf +++ b/test/C/src/multiport/BankToReaction.lf @@ -6,7 +6,7 @@ target C { import Count from "../lib/Count.lf" main reactor { - state count: int(1) + state count: int = 1 s = new[2] Count() diff --git a/test/C/src/multiport/Broadcast.lf b/test/C/src/multiport/Broadcast.lf index dee0ad62ed..e3471da5f6 100644 --- a/test/C/src/multiport/Broadcast.lf +++ b/test/C/src/multiport/Broadcast.lf @@ -9,9 +9,9 @@ reactor Source { reaction(startup) -> out {= lf_set(out, 42); =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/BroadcastAfter.lf b/test/C/src/multiport/BroadcastAfter.lf index b66979e182..c1be635e55 100644 --- a/test/C/src/multiport/BroadcastAfter.lf +++ b/test/C/src/multiport/BroadcastAfter.lf @@ -9,9 +9,9 @@ reactor Source { reaction(startup) -> out {= lf_set(out, 42); =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/BroadcastMultipleAfter.lf b/test/C/src/multiport/BroadcastMultipleAfter.lf index b83540e3d4..97d853e4ce 100644 --- a/test/C/src/multiport/BroadcastMultipleAfter.lf +++ b/test/C/src/multiport/BroadcastMultipleAfter.lf @@ -3,15 +3,15 @@ target C { fast: true } -reactor Source(value: int(42)) { +reactor Source(value: int = 42) { output out: int reaction(startup) -> out {= lf_set(out, self->value); =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/DualBanks.lf b/test/C/src/multiport/DualBanks.lf index aa8faf4b75..3cb5d38887 100644 --- a/test/C/src/multiport/DualBanks.lf +++ b/test/C/src/multiport/DualBanks.lf @@ -1,8 +1,8 @@ target C -reactor Base(bank_index: int(0)) { +reactor Base(bank_index: int = 0) { input I: int - state received: bool(false) + state received: bool = false reaction(shutdown) {= if(!self->received) { diff --git a/test/C/src/multiport/DualBanksMultiport.lf b/test/C/src/multiport/DualBanksMultiport.lf index 42c4adb11e..a5c2120a79 100644 --- a/test/C/src/multiport/DualBanksMultiport.lf +++ b/test/C/src/multiport/DualBanksMultiport.lf @@ -1,8 +1,8 @@ target C -reactor Base(bank_index: int(0)) { +reactor Base(bank_index: int = 0) { input[2] I: int - state received: bool(false) + state received: bool = false reaction(shutdown) {= if(!self->received) { diff --git a/test/C/src/multiport/FullyConnected.lf b/test/C/src/multiport/FullyConnected.lf index 8a26fee83f..758ecf1580 100644 --- a/test/C/src/multiport/FullyConnected.lf +++ b/test/C/src/multiport/FullyConnected.lf @@ -1,10 +1,10 @@ target C -reactor Node(num_nodes: size_t(4), bank_index: int(0)) { +reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { input[num_nodes] in: int output out: int - state received: bool(false) + state received: bool = false reaction(startup) -> out {= lf_print("Hello from node %d!", self->bank_index); @@ -35,7 +35,7 @@ reactor Node(num_nodes: size_t(4), bank_index: int(0)) { =} } -main reactor(num_nodes: size_t(4)) { +main reactor(num_nodes: size_t = 4) { nodes = new[num_nodes] Node(num_nodes = num_nodes) (nodes.out)+ -> nodes.in } diff --git a/test/C/src/multiport/FullyConnectedAddressable.lf b/test/C/src/multiport/FullyConnectedAddressable.lf index ae99d5397e..91b0f5caac 100644 --- a/test/C/src/multiport/FullyConnectedAddressable.lf +++ b/test/C/src/multiport/FullyConnectedAddressable.lf @@ -1,12 +1,12 @@ // In this pattern, each node can send direct messages to individual other nodes target C -reactor Node(num_nodes: size_t(4), bank_index: int(0)) { +reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { input[num_nodes] in: int output[num_nodes] out: int - state received: int(0) - state triggered: bool(false) + state received: int = 0 + state triggered: bool = false reaction(startup) -> out {= int outChannel = (self->bank_index + 1) % self->num_nodes; @@ -45,7 +45,7 @@ reactor Node(num_nodes: size_t(4), bank_index: int(0)) { =} } -main reactor(num_nodes: size_t(4)) { +main reactor(num_nodes: size_t = 4) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) diff --git a/test/C/src/multiport/FullyConnectedAddressableAfter.lf b/test/C/src/multiport/FullyConnectedAddressableAfter.lf index cd6dc4cf85..1d30430deb 100644 --- a/test/C/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/C/src/multiport/FullyConnectedAddressableAfter.lf @@ -3,7 +3,7 @@ target C import Node from "FullyConnectedAddressable.lf" -main reactor(num_nodes: size_t(4)) { +main reactor(num_nodes: size_t = 4) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) after 200 msec diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index b8ade7a354..1b49786060 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -5,7 +5,7 @@ target C { fast: true } -reactor Source(check_override: int(0), bank_index: int(0)) { +reactor Source(check_override: int = 0, bank_index: int = 0) { output out: int reaction(startup) -> out {= @@ -13,9 +13,9 @@ reactor Source(check_override: int(0), bank_index: int(0)) { =} } -reactor Destination(port_width: int(3)) { +reactor Destination(port_width: int = 3) { input[port_width] in: int - state received: bool(false) + state received: bool = false reaction(in) {= for (int i = 0; i < in_width; i++) { @@ -37,7 +37,7 @@ reactor Destination(port_width: int(3)) { =} } -main reactor MultiportFromBank(width: int(4)) { +main reactor MultiportFromBank(width: int = 4) { a = new[width] Source(check_override = 1) b = new Destination(port_width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index c38046107c..e8ee6194b5 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -7,13 +7,13 @@ target C { import Source, Destination from "MultiportFromBank.lf" -reactor Container(port_width: int(3)) { +reactor Container(port_width: int = 3) { output[port_width] out: int s = new[port_width] Source(check_override = 1) s.out -> out } -main reactor(width: int(4)) { +main reactor(width: int = 4) { a = new Container(port_width = width) b = new Destination(port_width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index f38661345c..8323210946 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Source(width: int(3)) { +reactor Source(width: int = 3) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -17,8 +17,8 @@ reactor Source(width: int(3)) { =} } -reactor Destination(width: int(3)) { - state s: int(6) +reactor Destination(width: int = 3) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -43,19 +43,19 @@ reactor Destination(width: int(3)) { =} } -reactor Container(width: int(3)) { +reactor Container(width: int = 3) { output[width] out: int src = new InsideContainer(width = width) src.out -> out } -reactor InsideContainer(width: int(3)) { +reactor InsideContainer(width: int = 3) { output[width] out: int src = new Source(width = width) src.out -> out } -main reactor MultiportFromHierarchy(width: int(4)) { +main reactor MultiportFromHierarchy(width: int = 4) { a = new Container(width = width) b = new Destination(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportFromReaction.lf b/test/C/src/multiport/MultiportFromReaction.lf index acaa59e519..33cbfffd83 100644 --- a/test/C/src/multiport/MultiportFromReaction.lf +++ b/test/C/src/multiport/MultiportFromReaction.lf @@ -4,8 +4,8 @@ target C { fast: true } -reactor Destination(width: int(1)) { - state s: int(6) +reactor Destination(width: int = 1) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -30,9 +30,9 @@ reactor Destination(width: int(1)) { =} } -main reactor MultiportFromReaction(width: int(4)) { +main reactor MultiportFromReaction(width: int = 4) { timer t(0, 200 msec) - state s: int(0) + state s: int = 0 b = new Destination(width = width) reaction(t) -> b.in {= diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index 80269896d8..b87a91a79b 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= lf_set(out, self->s); @@ -24,7 +24,7 @@ reactor Computation { } reactor Destination { - state s: int(0) + state s: int = 0 input[4] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportInParameterized.lf b/test/C/src/multiport/MultiportInParameterized.lf index cd9bb27ad2..bf7ec93f6e 100644 --- a/test/C/src/multiport/MultiportInParameterized.lf +++ b/test/C/src/multiport/MultiportInParameterized.lf @@ -8,7 +8,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= lf_set(out, self->s); @@ -23,8 +23,8 @@ reactor Computation { reaction(in) -> out {= lf_set(out, in->value); =} } -reactor Destination(width: int(1)) { - state s: int(0) +reactor Destination(width: int = 1) { + state s: int = 0 input[width] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportMutableInput.lf b/test/C/src/multiport/MultiportMutableInput.lf index d1b0994012..e1f8d579c2 100644 --- a/test/C/src/multiport/MultiportMutableInput.lf +++ b/test/C/src/multiport/MultiportMutableInput.lf @@ -12,7 +12,7 @@ reactor Source { =} } -reactor Print(scale: int(1)) { // The scale parameter is just for testing. +reactor Print(scale: int = 1) { // The scale parameter is just for testing. input[2] in: int reaction(in) {= @@ -27,7 +27,7 @@ reactor Print(scale: int(1)) { // The scale parameter is just for testing. =} } -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { mutable input[2] in: int output[2] out: int diff --git a/test/C/src/multiport/MultiportMutableInputArray.lf b/test/C/src/multiport/MultiportMutableInputArray.lf index cd279bb6a2..90907e4f44 100644 --- a/test/C/src/multiport/MultiportMutableInputArray.lf +++ b/test/C/src/multiport/MultiportMutableInputArray.lf @@ -26,7 +26,7 @@ reactor Source { =} } -reactor Print(scale: int(1)) { // The scale parameter is just for testing. +reactor Print(scale: int = 1) { // The scale parameter is just for testing. input[2] in: int[] reaction(in) {= @@ -52,7 +52,7 @@ reactor Print(scale: int(1)) { // The scale parameter is just for testing. =} } -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { mutable input[2] in: int[] output[2] out: int[] diff --git a/test/C/src/multiport/MultiportOut.lf b/test/C/src/multiport/MultiportOut.lf index c2707d5d33..38365d217a 100644 --- a/test/C/src/multiport/MultiportOut.lf +++ b/test/C/src/multiport/MultiportOut.lf @@ -7,7 +7,7 @@ target C { reactor Source { timer t(0, 200 msec) output[4] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -31,7 +31,7 @@ reactor Computation { } reactor Destination { - state s: int(0) + state s: int = 0 input[4] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportToBank.lf b/test/C/src/multiport/MultiportToBank.lf index c1f19d3553..86146b9818 100644 --- a/test/C/src/multiport/MultiportToBank.lf +++ b/test/C/src/multiport/MultiportToBank.lf @@ -4,7 +4,7 @@ target C { fast: true } -reactor Source(width: int(2)) { +reactor Source(width: int = 2) { output[width] out: int // Connected to a bank of Destination reactors input dummy: int // Not connected to anything @@ -24,9 +24,9 @@ reactor Source(width: int(2)) { =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); @@ -46,7 +46,7 @@ reactor Destination(bank_index: int(0)) { =} } -main reactor MultiportToBank(width: int(3)) { +main reactor MultiportToBank(width: int = 3) { a = new Source(width = width) b = new[width] Destination() a.out -> b.in diff --git a/test/C/src/multiport/MultiportToBankAfter.lf b/test/C/src/multiport/MultiportToBankAfter.lf index 66e0fdf837..ba26142243 100644 --- a/test/C/src/multiport/MultiportToBankAfter.lf +++ b/test/C/src/multiport/MultiportToBankAfter.lf @@ -5,7 +5,7 @@ target C { fast: true } -reactor Source(width: int(2)) { +reactor Source(width: int = 2) { output[width] out: int reaction(startup) -> out {= @@ -15,9 +15,9 @@ reactor Source(width: int(2)) { =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); @@ -41,7 +41,7 @@ reactor Destination(bank_index: int(0)) { =} } -main reactor(width: int(3)) { +main reactor(width: int = 3) { a = new Source(width = width) b = new[width] Destination() a.out -> b.in after 1 sec // Width of the bank of delays will be inferred. diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index a116ef9c00..444f02d170 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -24,9 +24,9 @@ reactor Source { =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index e4f231390f..fbdc531bf0 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -5,7 +5,7 @@ target C { fast: true } -reactor Source(width: int(2)) { +reactor Source(width: int = 2) { output[width] out: int reaction(startup) -> out {= @@ -15,9 +15,9 @@ reactor Source(width: int(2)) { =} } -reactor Destination(bank_index: int(0)) { +reactor Destination(bank_index: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); @@ -37,13 +37,13 @@ reactor Destination(bank_index: int(0)) { =} } -reactor Container(width: int(2)) { +reactor Container(width: int = 2) { input[width] in: int c = new[width] Destination() in -> c.in } -main reactor MultiportToBankHierarchy(width: int(3)) { +main reactor MultiportToBankHierarchy(width: int = 3) { a = new Source(width = width) b = new Container(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index 24290b56a5..41ca505077 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -6,10 +6,10 @@ target C { fast: true } -reactor Source(width: int(2)) { +reactor Source(width: int = 2) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -18,8 +18,8 @@ reactor Source(width: int(2)) { =} } -reactor Destination(width: int(4)) { - state s: int(6) +reactor Destination(width: int = 4) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -44,13 +44,13 @@ reactor Destination(width: int(4)) { =} } -reactor Container(width: int(4)) { +reactor Container(width: int = 4) { input[width] in: int dst = new Destination() in -> dst.in } -main reactor MultiportToHierarchy(width: int(4)) { +main reactor MultiportToHierarchy(width: int = 4) { a = new Source(width = width) b = new Container(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToMultiport.lf b/test/C/src/multiport/MultiportToMultiport.lf index bf4bbefde4..375fa080e2 100644 --- a/test/C/src/multiport/MultiportToMultiport.lf +++ b/test/C/src/multiport/MultiportToMultiport.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int(1)) { +reactor Source(width: int = 1) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -19,8 +19,8 @@ reactor Source(width: int(1)) { =} } -reactor Destination(width: int(1)) { - state s: int(6) +reactor Destination(width: int = 1) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -45,7 +45,7 @@ reactor Destination(width: int(1)) { =} } -main reactor MultiportToMultiport(width: int(4)) { +main reactor MultiportToMultiport(width: int = 4) { a = new Source(width = width) b = new Destination(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToMultiport2.lf b/test/C/src/multiport/MultiportToMultiport2.lf index 29a8632399..76858a2a86 100644 --- a/test/C/src/multiport/MultiportToMultiport2.lf +++ b/test/C/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target C -reactor Source(width: int(2)) { +reactor Source(width: int = 2) { output[width] out: int reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: int(2)) { =} } -reactor Destination(width: int(2)) { +reactor Destination(width: int = 2) { input[width] in: int reaction(in) {= @@ -30,9 +30,9 @@ reactor Destination(width: int(2)) { } main reactor MultiportToMultiport2( - width1: int(3), - width2: int(2), - width3: int(5) + width1: int = 3, + width2: int = 2, + width3: int = 5 ) { a1 = new Source(width = width1) a2 = new Source(width = width2) diff --git a/test/C/src/multiport/MultiportToMultiport2After.lf b/test/C/src/multiport/MultiportToMultiport2After.lf index b6f078a099..49585ea1b0 100644 --- a/test/C/src/multiport/MultiportToMultiport2After.lf +++ b/test/C/src/multiport/MultiportToMultiport2After.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target C -reactor Source(width: int(2)) { +reactor Source(width: int = 2) { output[width] out: int reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: int(2)) { =} } -reactor Destination(width: int(2)) { +reactor Destination(width: int = 2) { input[width] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportToMultiportArray.lf b/test/C/src/multiport/MultiportToMultiportArray.lf index 100a57c393..9d86a4a522 100644 --- a/test/C/src/multiport/MultiportToMultiportArray.lf +++ b/test/C/src/multiport/MultiportToMultiportArray.lf @@ -8,7 +8,7 @@ target C { reactor Source { timer t(0, 200 msec) output[2] out: int[] - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < 2; i++) { @@ -24,7 +24,7 @@ reactor Source { } reactor Destination { - state s: int(15) + state s: int = 15 input[2] in: int[] reaction(in) {= diff --git a/test/C/src/multiport/MultiportToMultiportParameter.lf b/test/C/src/multiport/MultiportToMultiportParameter.lf index 9dc7288a52..d1c96e5ddd 100644 --- a/test/C/src/multiport/MultiportToMultiportParameter.lf +++ b/test/C/src/multiport/MultiportToMultiportParameter.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int(1)) { +reactor Source(width: int = 1) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -19,8 +19,8 @@ reactor Source(width: int(1)) { =} } -reactor Destination(width: int(1)) { - state s: int(6) +reactor Destination(width: int = 1) { + state s: int = 6 input[width] in: int // Width is one larger than that of the source. reaction(in) {= @@ -45,7 +45,7 @@ reactor Destination(width: int(1)) { =} } -main reactor(width: int(4)) { +main reactor(width: int = 4) { a = new Source(width = width) b = new Destination(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToPort.lf b/test/C/src/multiport/MultiportToPort.lf index ccee46566c..1784f2503c 100644 --- a/test/C/src/multiport/MultiportToPort.lf +++ b/test/C/src/multiport/MultiportToPort.lf @@ -16,9 +16,9 @@ reactor Source { =} } -reactor Destination(expected: int(0)) { +reactor Destination(expected: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= printf("Received: %d.\n", in->value); diff --git a/test/C/src/multiport/MultiportToReaction.lf b/test/C/src/multiport/MultiportToReaction.lf index 62e2c302f2..9281633079 100644 --- a/test/C/src/multiport/MultiportToReaction.lf +++ b/test/C/src/multiport/MultiportToReaction.lf @@ -4,9 +4,9 @@ target C { fast: true } -reactor Source(width: int(1)) { +reactor Source(width: int = 1) { timer t(0, 200 msec) - state s: int(0) + state s: int = 0 output[width] out: int reaction(t) -> out {= @@ -18,7 +18,7 @@ reactor Source(width: int(1)) { } main reactor MultiportToReaction { - state s: int(6) + state s: int = 6 b = new Source(width = 4) reaction(b.out) {= diff --git a/test/C/src/multiport/NestedBanks.lf b/test/C/src/multiport/NestedBanks.lf index b80ff2e606..bef08727f3 100644 --- a/test/C/src/multiport/NestedBanks.lf +++ b/test/C/src/multiport/NestedBanks.lf @@ -13,13 +13,13 @@ main reactor { (a.x)+ -> c.z, d.u, e.t } -reactor A(bank_index: int(0)) { +reactor A(bank_index: int = 0) { output[4] x: int b = new[2] B(a_bank_index = bank_index) b.y -> x } -reactor B(a_bank_index: int(0), bank_index: int(0)) { +reactor B(a_bank_index: int = 0, bank_index: int = 0) { output[2] y: int reaction(startup) -> y {= @@ -29,7 +29,7 @@ reactor B(a_bank_index: int(0), bank_index: int(0)) { =} } -reactor C(bank_index: int(0)) { +reactor C(bank_index: int = 0) { input[2] z: int f = new F(c_bank_index = bank_index) g = new G(c_bank_index = bank_index) @@ -59,7 +59,7 @@ reactor E { =} } -reactor F(c_bank_index: int(0)) { +reactor F(c_bank_index: int = 0) { input w: int reaction(w) {= @@ -70,7 +70,7 @@ reactor F(c_bank_index: int(0)) { =} } -reactor G(c_bank_index: int(0)) { +reactor G(c_bank_index: int = 0) { input s: int reaction(s) {= diff --git a/test/C/src/multiport/NestedInterleavedBanks.lf b/test/C/src/multiport/NestedInterleavedBanks.lf index 9f03313972..8e3056bd88 100644 --- a/test/C/src/multiport/NestedInterleavedBanks.lf +++ b/test/C/src/multiport/NestedInterleavedBanks.lf @@ -4,7 +4,7 @@ */ target C -reactor A(bank_index: int(0), outer_bank_index: int(0)) { +reactor A(bank_index: int = 0, outer_bank_index: int = 0) { output[2] p: int reaction(startup) -> p {= @@ -15,7 +15,7 @@ reactor A(bank_index: int(0), outer_bank_index: int(0)) { =} } -reactor B(bank_index: int(0)) { +reactor B(bank_index: int = 0) { output[4] q: int a = new[2] A(outer_bank_index = bank_index) interleaved (a.p) -> q diff --git a/test/C/src/multiport/ReactionToContainedBank.lf b/test/C/src/multiport/ReactionToContainedBank.lf index 3e0afa17d5..30f3f5564c 100644 --- a/test/C/src/multiport/ReactionToContainedBank.lf +++ b/test/C/src/multiport/ReactionToContainedBank.lf @@ -6,9 +6,9 @@ target C { import TestCount from "../lib/TestCount.lf" -main reactor ReactionToContainedBank(width: int(2)) { +main reactor ReactionToContainedBank(width: int = 2) { timer t(0, 100 msec) - state count: int(1) + state count: int = 1 test = new[width] TestCount(num_inputs = 11) diff --git a/test/C/src/multiport/ReactionToContainedBank2.lf b/test/C/src/multiport/ReactionToContainedBank2.lf index b7c7d1cf92..e03e884558 100644 --- a/test/C/src/multiport/ReactionToContainedBank2.lf +++ b/test/C/src/multiport/ReactionToContainedBank2.lf @@ -6,9 +6,9 @@ target C { import TestCount from "../lib/TestCount.lf" -reactor ReactionToContainedBank(width: int(2)) { +reactor ReactionToContainedBank(width: int = 2) { timer t(0, 100 msec) - state count: int(1) + state count: int = 1 test = new[width] TestCount(num_inputs = 11) @@ -20,7 +20,7 @@ reactor ReactionToContainedBank(width: int(2)) { =} } -main reactor(width: int(2)) { +main reactor(width: int = 2) { a = new ReactionToContainedBank(width = width) b = new ReactionToContainedBank(width = 4) } diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index 6a9e067ca1..d84b21c191 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -7,9 +7,9 @@ target C { import TestCountMultiport from "../lib/TestCountMultiport.lf" -main reactor(width: int(2)) { +main reactor(width: int = 2) { timer t(0, 100 msec) - state count: int(1) + state count: int = 1 test = new[width] TestCountMultiport(num_inputs = 11, width = width) diff --git a/test/C/src/multiport/ReactionsToNested.lf b/test/C/src/multiport/ReactionsToNested.lf index 102df10f8b..4270f55c2d 100644 --- a/test/C/src/multiport/ReactionsToNested.lf +++ b/test/C/src/multiport/ReactionsToNested.lf @@ -4,9 +4,9 @@ target C { timeout: 1 sec } -reactor T(expected: int(0)) { +reactor T(expected: int = 0) { input z: int - state received: bool(false) + state received: bool = false reaction(z) {= lf_print("T received %d", z->value); diff --git a/test/C/src/multiport/Sparse.lf b/test/C/src/multiport/Sparse.lf index eaa75782cb..537daabb4b 100644 --- a/test/C/src/multiport/Sparse.lf +++ b/test/C/src/multiport/Sparse.lf @@ -3,9 +3,9 @@ target C { timeout: 20 ms } -reactor SparseSource(width: int(20)) { +reactor SparseSource(width: int = 20) { output[width] out: int - state count: int(0) + state count: int = 0 timer t(0, 1 msec) reaction(t) -> out {= @@ -19,7 +19,7 @@ reactor SparseSource(width: int(20)) { =} } -reactor SparseSink(width: int(20)) { +reactor SparseSink(width: int = 20) { input[width] in: int reaction(in) {= @@ -43,7 +43,7 @@ reactor SparseSink(width: int(20)) { =} } -main reactor(width: int(20)) { +main reactor(width: int = 20) { s = new SparseSource(width = width) d = new SparseSink(width = width) s.out -> d.in diff --git a/test/C/src/multiport/SparseFallback.lf b/test/C/src/multiport/SparseFallback.lf index 195dca1f19..a7788858d8 100644 --- a/test/C/src/multiport/SparseFallback.lf +++ b/test/C/src/multiport/SparseFallback.lf @@ -6,9 +6,9 @@ target C { timeout: 20 ms } -reactor SparseSource(width: int(20)) { +reactor SparseSource(width: int = 20) { output[width] out: int - state count: int(0) + state count: int = 0 timer t(0, 1 msec) reaction(t) -> out {= @@ -22,7 +22,7 @@ reactor SparseSource(width: int(20)) { =} } -reactor SparseSink(width: int(20)) { +reactor SparseSink(width: int = 20) { input[width] in: int reaction(in) {= @@ -46,7 +46,7 @@ reactor SparseSink(width: int(20)) { =} } -main reactor(width: int(10)) { +main reactor(width: int = 10) { s = new SparseSource(width = width) d = new SparseSink(width = width) s.out -> d.in diff --git a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf index c696261db7..917982af39 100644 --- a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf +++ b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf @@ -10,7 +10,7 @@ target C { reactor Source { output a: int output b: int - state count: int(0) + state count: int = 0 timer t(0, 200 msec) reaction(t) -> a, b {= diff --git a/test/C/src/serialization/ROSBuiltInSerialization.lf b/test/C/src/serialization/ROSBuiltInSerialization.lf index d573b23cce..095aadacd2 100644 --- a/test/C/src/serialization/ROSBuiltInSerialization.lf +++ b/test/C/src/serialization/ROSBuiltInSerialization.lf @@ -32,7 +32,7 @@ reactor Sender { output out: std_msgs::msg::Int32 // state serialized_msg_pcl:rclcpp::SerializedMessage({=0u=}); - state count: int(0) + state count: int = 0 timer t(0, 1 sec) @@ -45,7 +45,7 @@ reactor Sender { reactor Receiver { input in: std_msgs::msg::Int32 - state count: int(0) + state count: int = 0 reaction(in) {= // Print the ROS2 message data diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index 4726809c57..97b5a12554 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -31,7 +31,7 @@ preamble {= reactor Sender { output out: std::shared_ptr - state count: int(0) + state count: int = 0 timer t(0, 1 sec) @@ -44,7 +44,7 @@ reactor Sender { reactor Receiver { input in: std::shared_ptr - state count: int(0) + state count: int = 0 reaction(in) {= // Print the ROS2 message data diff --git a/test/C/src/target/HelloWorldCCPP.lf b/test/C/src/target/HelloWorldCCPP.lf index 0b0e54ed52..91d1cd61d1 100644 --- a/test/C/src/target/HelloWorldCCPP.lf +++ b/test/C/src/target/HelloWorldCCPP.lf @@ -11,7 +11,7 @@ reactor HelloWorld { preamble {= #include =} - state success: bool(false) + state success: bool = false reaction(startup) {= std::cout << "Hello World." << std::endl; diff --git a/test/C/src/token/TokenContainedPrint.lf b/test/C/src/token/TokenContainedPrint.lf index 0d4b19379d..29e6005c4c 100644 --- a/test/C/src/token/TokenContainedPrint.lf +++ b/test/C/src/token/TokenContainedPrint.lf @@ -9,7 +9,7 @@ target C { import TokenPrint from "lib/Token.lf" main reactor { - state count: int(0) + state count: int = 0 timer t(0, 1 ms) p = new TokenPrint() diff --git a/test/C/src/token/TokenContainedPrintBank.lf b/test/C/src/token/TokenContainedPrintBank.lf index b23eb1c109..991a94b5a7 100644 --- a/test/C/src/token/TokenContainedPrintBank.lf +++ b/test/C/src/token/TokenContainedPrintBank.lf @@ -10,7 +10,7 @@ target C { import TokenPrint from "lib/Token.lf" main reactor { - state count: int(0) + state count: int = 0 timer t(0, 1 ms) p = new[2] TokenPrint() diff --git a/test/C/src/token/TokenContainedSource.lf b/test/C/src/token/TokenContainedSource.lf index 9bf517bc18..66095b8a0b 100644 --- a/test/C/src/token/TokenContainedSource.lf +++ b/test/C/src/token/TokenContainedSource.lf @@ -9,9 +9,9 @@ target C { import TokenSource from "lib/Token.lf" -main reactor(scale: int(1)) { - state count: int(0) - state input_received: bool(false) +main reactor(scale: int = 1) { + state count: int = 0 + state input_received: bool = false s = new TokenSource() diff --git a/test/C/src/token/TokenContainedSourceBank.lf b/test/C/src/token/TokenContainedSourceBank.lf index f1faee87dd..615695890b 100644 --- a/test/C/src/token/TokenContainedSourceBank.lf +++ b/test/C/src/token/TokenContainedSourceBank.lf @@ -10,9 +10,9 @@ target C { import TokenSource from "lib/Token.lf" -main reactor(scale: int(1)) { - state count: int(0) - state input_received: bool(false) +main reactor(scale: int = 1) { + state count: int = 0 + state input_received: bool = false s = new[2] TokenSource() diff --git a/test/C/src/token/lib/Token.lf b/test/C/src/token/lib/Token.lf index 4e49cd0006..7b8d2a83ee 100644 --- a/test/C/src/token/lib/Token.lf +++ b/test/C/src/token/lib/Token.lf @@ -20,7 +20,7 @@ preamble {= */ reactor TokenSource { output out: int_array_t* - state count: int(0) + state count: int = 0 timer t(0, 1 ms) reaction(startup) -> out {= @@ -42,10 +42,10 @@ reactor TokenSource { * value is a scaled version of the sequence of values produced by the * TokenSource, where the scaling factor is given by the scale parameter. */ -reactor TokenPrint(scale: int(1)) { +reactor TokenPrint(scale: int = 1) { input in: int_array_t* - state count: int(0) - state input_received: bool(false) + state count: int = 0 + state input_received: bool = false reaction(in) {= self->input_received = true; @@ -79,7 +79,7 @@ reactor TokenPrint(scale: int(1)) { * input is declared mutable so, if possible, the input token will be modified * rather than allocating a new token. */ -reactor TokenScale(scale: int(2)) { +reactor TokenScale(scale: int = 2) { mutable input in: int_array_t* output out: int_array_t* diff --git a/test/Cpp/src/ActionDelay.lf b/test/Cpp/src/ActionDelay.lf index 5bb1402e05..14210e1009 100644 --- a/test/Cpp/src/ActionDelay.lf +++ b/test/Cpp/src/ActionDelay.lf @@ -4,7 +4,7 @@ target Cpp reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int{0} + state y_state: int = 0 logical action act(100 msec): void reaction(y_in) -> act {= diff --git a/test/Cpp/src/ActionIsPresent.lf b/test/Cpp/src/ActionIsPresent.lf index 7b8267d606..e98c2a2a32 100644 --- a/test/Cpp/src/ActionIsPresent.lf +++ b/test/Cpp/src/ActionIsPresent.lf @@ -1,10 +1,10 @@ // Tests the is_present variable for actions in cpp target Cpp -main reactor ActionIsPresent(offset: time(1 nsec), period: time(500 msec)) { +main reactor ActionIsPresent(offset: time = 1 nsec, period: time(500 msec)) { logical action a - state success: bool(false) - state zero: time(0 nsec) + state success: bool = false + state zero: time = 0 nsec reaction(startup, a) -> a {= if (!a.is_present()) { diff --git a/test/Cpp/src/ActionValues.lf b/test/Cpp/src/ActionValues.lf index 18d06b7b3c..8d115c60fa 100644 --- a/test/Cpp/src/ActionValues.lf +++ b/test/Cpp/src/ActionValues.lf @@ -2,8 +2,8 @@ target Cpp main reactor ActionValues { - state r1done: bool(false) - state r2done: bool(false) + state r1done: bool = false + state r2done: bool = false logical action act(100 msec): int reaction(startup) -> act {= diff --git a/test/Cpp/src/After.lf b/test/Cpp/src/After.lf index 177ebfbe01..bbcc287b78 100644 --- a/test/Cpp/src/After.lf +++ b/test/Cpp/src/After.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time(10 msec) - state i: int(0) + state expected_time: time = 10 msec + state i: int = 0 input x: int reaction(x) {= diff --git a/test/Cpp/src/AfterOverlapped.lf b/test/Cpp/src/AfterOverlapped.lf index 926c4609c2..6a85eaf5bc 100644 --- a/test/Cpp/src/AfterOverlapped.lf +++ b/test/Cpp/src/AfterOverlapped.lf @@ -8,7 +8,7 @@ import Count from "lib/Count.lf" reactor Test { input c: int - state i: int(0) + state i: int = 0 reaction(c) {= std::cout << "Received " << *c.get() << '\n'; diff --git a/test/Cpp/src/AfterZero.lf b/test/Cpp/src/AfterZero.lf index 8baa157e99..152b87cfc2 100644 --- a/test/Cpp/src/AfterZero.lf +++ b/test/Cpp/src/AfterZero.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time(0) - state i: int(0) + state expected_time: time = 0 + state i: int = 0 input x: int reaction(x) {= diff --git a/test/Cpp/src/Alignment.lf b/test/Cpp/src/Alignment.lf index 45e52cb573..1bd3562f41 100644 --- a/test/Cpp/src/Alignment.lf +++ b/test/Cpp/src/Alignment.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { output out: int - state count: int(1) + state count: int = 1 timer t(0, 100 msec) reaction(t) -> out {= diff --git a/test/Cpp/src/ArrayAsParameter.lf b/test/Cpp/src/ArrayAsParameter.lf index 77795deb56..85cd0630bf 100644 --- a/test/Cpp/src/ArrayAsParameter.lf +++ b/test/Cpp/src/ArrayAsParameter.lf @@ -2,9 +2,9 @@ // passes to Print. target Cpp -reactor Source(sequence: int[]{0, 1, 2}) { +reactor Source(sequence: std::vector = {0, 1, 2}) { output out: size_t - state count: size_t{0} + state count: size_t = 0 logical action next: void reaction(startup, next) -> out, next {= @@ -18,7 +18,7 @@ reactor Source(sequence: int[]{0, 1, 2}) { reactor Print { input in: size_t - state count: size_t{1} + state count: size_t = 1 reaction(in) {= std::cout << "Received: " << *in.get() << '\n'; @@ -38,7 +38,7 @@ reactor Print { } main reactor ArrayAsParameter { - s = new Source(sequence = {= {1, 2, 3, 4} =}) + s = new Source(sequence = {1, 2, 3, 4}) p = new Print() s.out -> p.in } diff --git a/test/Cpp/src/ArrayPrint.lf b/test/Cpp/src/ArrayPrint.lf index 420f7902db..3bdf494107 100644 --- a/test/Cpp/src/ArrayPrint.lf +++ b/test/Cpp/src/ArrayPrint.lf @@ -18,7 +18,7 @@ reactor Source { =} } -reactor Print(scale: int(1)) { +reactor Print(scale: int = 1) { input in: int[3] reaction(in) {= diff --git a/test/Cpp/src/ArrayScale.lf b/test/Cpp/src/ArrayScale.lf index f5b2e56b30..b52e7305b7 100644 --- a/test/Cpp/src/ArrayScale.lf +++ b/test/Cpp/src/ArrayScale.lf @@ -5,7 +5,7 @@ target Cpp import Source, Print from "ArrayPrint.lf" -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { input in: int[3] output out: int[3] diff --git a/test/Cpp/src/CharLiteralInitializer.lf b/test/Cpp/src/CharLiteralInitializer.lf index 2d0edb71b8..e01e5973a6 100644 --- a/test/Cpp/src/CharLiteralInitializer.lf +++ b/test/Cpp/src/CharLiteralInitializer.lf @@ -2,7 +2,7 @@ target Cpp main reactor CharLiteralInitializer { - state c: char('x') + state c: char = 'x' reaction(startup) {= if (c != 'x') { diff --git a/test/Cpp/src/Composition.lf b/test/Cpp/src/Composition.lf index 6ac7364a51..0a341d5e4f 100644 --- a/test/Cpp/src/Composition.lf +++ b/test/Cpp/src/Composition.lf @@ -5,10 +5,10 @@ target Cpp { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= count++; diff --git a/test/Cpp/src/CompositionAfter.lf b/test/Cpp/src/CompositionAfter.lf index 06f71a6fbb..15d68e13ea 100644 --- a/test/Cpp/src/CompositionAfter.lf +++ b/test/Cpp/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target Cpp { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= count++; @@ -38,7 +38,7 @@ reactor Test { =} } -main reactor(delay: time(5 sec)) { +main reactor(delay: time = 5 sec) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/Cpp/src/CountTest.lf b/test/Cpp/src/CountTest.lf index 63a494bc61..838d84a998 100644 --- a/test/Cpp/src/CountTest.lf +++ b/test/Cpp/src/CountTest.lf @@ -7,7 +7,7 @@ import Count from "lib/Count.lf" reactor Test { input c: int - state i: int(0) + state i: int = 0 reaction(c) {= i++; diff --git a/test/Cpp/src/Deadline.lf b/test/Cpp/src/Deadline.lf index 81eab8a004..19a41ff057 100644 --- a/test/Cpp/src/Deadline.lf +++ b/test/Cpp/src/Deadline.lf @@ -5,13 +5,13 @@ target Cpp { timeout: 4 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { private preamble {= #include =} output y: int timer t(0, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= if (count % 2 == 1) { @@ -25,9 +25,9 @@ reactor Source(period: time(2 sec)) { =} } -reactor Destination(timeout: time(1 sec)) { +reactor Destination(timeout: time = 1 sec) { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= std::cout << "Destination receives: " << *x.get() << std::endl; diff --git a/test/Cpp/src/DeadlineHandledAbove.lf b/test/Cpp/src/DeadlineHandledAbove.lf index 76a790fcbf..b2a6c7658a 100644 --- a/test/Cpp/src/DeadlineHandledAbove.lf +++ b/test/Cpp/src/DeadlineHandledAbove.lf @@ -2,7 +2,7 @@ // container reacts to that output. target Cpp -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time(100 msec)) { } main reactor DeadlineHandledAbove { - state violation_detected: bool({= false =}) + state violation_detected: bool = {= false =} d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/Cpp/src/DelayInt.lf b/test/Cpp/src/DelayInt.lf index 379e22a3ec..f58e5ef45b 100644 --- a/test/Cpp/src/DelayInt.lf +++ b/test/Cpp/src/DelayInt.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target Cpp -reactor Delay(delay: time(100 msec)) { +reactor Delay(delay: time = 100 msec) { input in: int output out: int logical action d: int diff --git a/test/Cpp/src/DelayedAction.lf b/test/Cpp/src/DelayedAction.lf index 0b2b748909..1ce1aea63f 100644 --- a/test/Cpp/src/DelayedAction.lf +++ b/test/Cpp/src/DelayedAction.lf @@ -6,7 +6,7 @@ target Cpp { main reactor DelayedAction { timer t(0, 1 sec) logical action a: void - state count: int(0) + state count: int = 0 reaction(t) -> a {= a.schedule(100ms); =} diff --git a/test/Cpp/src/DoubleInvocation.lf b/test/Cpp/src/DoubleInvocation.lf index 3315fafae4..956b54bb17 100644 --- a/test/Cpp/src/DoubleInvocation.lf +++ b/test/Cpp/src/DoubleInvocation.lf @@ -14,7 +14,7 @@ target Cpp { reactor Ball { output position: int output velocity: int - state p: int(200) + state p: int = 200 timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -27,7 +27,7 @@ reactor Ball { reactor Print { input velocity: int input position: int - state previous: int(-1) + state previous: int = -1 reaction(startup) {= reactor::log::Info() << "####### Print startup"; diff --git a/test/Cpp/src/DoublePort.lf b/test/Cpp/src/DoublePort.lf index 00950b1331..faaa474db5 100644 --- a/test/Cpp/src/DoublePort.lf +++ b/test/Cpp/src/DoublePort.lf @@ -13,7 +13,7 @@ target Cpp { import Count from "lib/Count.lf" reactor CountMicrostep { - state count: int(1) + state count: int = 1 output out: int logical action act: int timer t(0, 1 sec) diff --git a/test/Cpp/src/DoubleReaction.lf b/test/Cpp/src/DoubleReaction.lf index d5e8964089..1128d63f97 100644 --- a/test/Cpp/src/DoubleReaction.lf +++ b/test/Cpp/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target Cpp { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int input w: int - state s: int(2) + state s: int = 2 reaction(x, w) {= int sum = 0; diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index c714d83e9c..5db4818048 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -5,7 +5,7 @@ target Cpp main reactor DoubleTrigger { timer t1 timer t2 - state s: int(0) + state s: int = 0 reaction(t1, t2) {= s++; diff --git a/test/Cpp/src/FloatLiteral.lf b/test/Cpp/src/FloatLiteral.lf index a65af798b4..6ad95f9e55 100644 --- a/test/Cpp/src/FloatLiteral.lf +++ b/test/Cpp/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target Cpp // This test verifies that floating-point literals are handled correctly. main reactor { - state N: double(6.0221409e+23) - state charge: double(-1.6021766E-19) - state minus_epsilon: double(-.01e0) - state expected: double(.964853323188E5) + state N: double = 6.0221409e+23 + state charge: double = -1.6021766E-19 + state minus_epsilon: double = -.01e0 + state expected: double = .964853323188E5 reaction(startup) {= auto F = - N * charge; diff --git a/test/Cpp/src/Gain.lf b/test/Cpp/src/Gain.lf index 4a62a62a8e..4b123cc992 100644 --- a/test/Cpp/src/Gain.lf +++ b/test/Cpp/src/Gain.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target Cpp -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { input x: int output y: int diff --git a/test/Cpp/src/GetMicroStep.lf b/test/Cpp/src/GetMicroStep.lf index c8eb89a4fa..8370a21403 100644 --- a/test/Cpp/src/GetMicroStep.lf +++ b/test/Cpp/src/GetMicroStep.lf @@ -2,7 +2,7 @@ target Cpp main reactor GetMicroStep { - state s: {= reactor::mstep_t =}(1) + state s: {= reactor::mstep_t =} = 1 logical action l diff --git a/test/Cpp/src/Hello.lf b/test/Cpp/src/Hello.lf index c63afbabe4..f74acf6688 100644 --- a/test/Cpp/src/Hello.lf +++ b/test/Cpp/src/Hello.lf @@ -8,8 +8,11 @@ target Cpp { fast: true } -reactor HelloCpp(period: time(2 sec), message: {= std::string =}("Hello C++")) { - state count: int(0) +reactor HelloCpp( + period: time = 2 sec, + message: {= std::string =} = "Hello C++" +) { + state count: int = 0 state previous_time: {= reactor::TimePoint =} timer t(1 sec, period) logical action a: void @@ -37,8 +40,8 @@ reactor HelloCpp(period: time(2 sec), message: {= std::string =}("Hello C++")) { } reactor Inside( - period: time(1 sec), - message: std::string("Composite default message.") + period: time = 1 sec, + message: std::string = "Composite default message." ) { third_instance = new HelloCpp(period = period, message = message) } diff --git a/test/Cpp/src/Hierarchy2.lf b/test/Cpp/src/Hierarchy2.lf index 4e78e3406e..db81bf4971 100644 --- a/test/Cpp/src/Hierarchy2.lf +++ b/test/Cpp/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out: int timer t(0, 1 sec) - state i: int(0) + state i: int = 0 reaction(t) -> out {= i++; @@ -37,7 +37,7 @@ reactor Add { reactor Print { input in: int - state expected: int(2) + state expected: int = 2 reaction(in) {= auto value = *in.get(); diff --git a/test/Cpp/src/ImportComposition.lf b/test/Cpp/src/ImportComposition.lf index 4b8649a243..0559edacd1 100644 --- a/test/Cpp/src/ImportComposition.lf +++ b/test/Cpp/src/ImportComposition.lf @@ -16,7 +16,7 @@ main reactor ImportComposition { =} imp_comp = new ImportedComposition() - state received: bool(false) + state received: bool = false reaction(startup) -> imp_comp.x {= imp_comp.x.set(42); =} diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index 2d426bffb7..3c55bdcaf1 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -4,7 +4,7 @@ target Cpp reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int(0) + state y_state: int = 0 logical action act(100 msec): int diff --git a/test/Cpp/src/Methods.lf b/test/Cpp/src/Methods.lf index fc4decbcbd..ff94460b62 100644 --- a/test/Cpp/src/Methods.lf +++ b/test/Cpp/src/Methods.lf @@ -1,7 +1,7 @@ target Cpp main reactor { - state foo: int(2) + state foo: int = 2 const method getFoo(): int {= return foo; =} diff --git a/test/Cpp/src/MovingAverage.lf b/test/Cpp/src/MovingAverage.lf index 160688c2ed..af202ca0a0 100644 --- a/test/Cpp/src/MovingAverage.lf +++ b/test/Cpp/src/MovingAverage.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { output out: double - state count: int{0} + state count: int = 0 timer clock(0, 200 msec) reaction(clock) -> out {= @@ -19,7 +19,7 @@ reactor Source { reactor MovingAverageImpl { state delay_line: double[3]{0.0, 0.0, 0.0} - state index: int{0} + state index: int = 0 input in: double output out: double @@ -44,7 +44,7 @@ reactor MovingAverageImpl { reactor Print { input in: double - state count: int{0} + state count: int = 0 reaction(in) {= std::cout << "Received: " << *in.get() << '\n'; diff --git a/test/Cpp/src/NativeListsAndTimes.lf b/test/Cpp/src/NativeListsAndTimes.lf index 5ec46d2930..5bf67c8fb4 100644 --- a/test/Cpp/src/NativeListsAndTimes.lf +++ b/test/Cpp/src/NativeListsAndTimes.lf @@ -2,27 +2,29 @@ target Cpp // This test passes if it is successfully compiled into valid target code. reactor Foo( - x: int(0), - y: time(0), // Units are missing but not required - z(1 msec), // Type is missing but not required - p: int[]{1, 2, 3, 4}, // List of integers + x: int = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required + p: int[]{1, 2, 3, 4}, // List of integers q: {= // list of time values std::vector =}{1 msec, 2 msec, 3 msec}, - g: time[]{1 msec, 2 msec} // List of time values + g: time[]{1 msec, 2 msec}, // List of time values + g2: int[] = {} ) { - state s: time(y) // Reference to explicitly typed time parameter - state t: time(z) // Reference to implicitly typed time parameter + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter state v: bool // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required timer tock(1 sec) // Implicit type time timer toe(z) // Implicit type time - state baz(p) // Implicit type int[] - state period(z) // Implicit type time + state baz = p // Implicit type int[] + state period = z // Implicit type time state times: std::vector< // a list of lists std::vector<{= reactor::Duration =}> >{q, g} + state empty_list: int[] = {} reaction(tick) {= // Target code diff --git a/test/Cpp/src/NestedTriggeredReactions.lf b/test/Cpp/src/NestedTriggeredReactions.lf index dcaa64b179..783dcefc7e 100644 --- a/test/Cpp/src/NestedTriggeredReactions.lf +++ b/test/Cpp/src/NestedTriggeredReactions.lf @@ -3,7 +3,7 @@ target Cpp reactor Container { input in: void - state triggered: bool{false} + state triggered: bool = false contained = new Contained() @@ -22,7 +22,7 @@ reactor Container { reactor Contained { input in: void - state triggered: bool{false} + state triggered: bool = false reaction(in) {= triggered = true; =} diff --git a/test/Cpp/src/ParameterHierarchy.lf b/test/Cpp/src/ParameterHierarchy.lf index acd051a5ce..c183cbca03 100644 --- a/test/Cpp/src/ParameterHierarchy.lf +++ b/test/Cpp/src/ParameterHierarchy.lf @@ -7,7 +7,7 @@ */ target Cpp -reactor Deep(p: int(0)) { +reactor Deep(p: int = 0) { reaction(startup) {= if(p != 42) { reactor::log::Error() << "Parameter value is: " << p << ". Should have been 42."; @@ -18,11 +18,11 @@ reactor Deep(p: int(0)) { =} } -reactor Intermediate(p: int(10)) { +reactor Intermediate(p: int = 10) { a = new Deep(p = p) } -reactor Another(p: int(20)) { +reactor Another(p: int = 20) { // also test forwarding parameters via target code blocks a = new Intermediate(p = {= p =}) } diff --git a/test/Cpp/src/ParameterizedState.lf b/test/Cpp/src/ParameterizedState.lf index be03a52b9a..1c39043a75 100644 --- a/test/Cpp/src/ParameterizedState.lf +++ b/test/Cpp/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target Cpp -reactor Foo(bar: int(4)) { - state baz(bar) +reactor Foo(bar: int = 4) { + state baz = bar reaction(startup) {= std::cout << "Baz: " << baz << std::endl; diff --git a/test/Cpp/src/ParametersOutOfOrder.lf b/test/Cpp/src/ParametersOutOfOrder.lf index 64dcbc6ef3..7ef28b914a 100644 --- a/test/Cpp/src/ParametersOutOfOrder.lf +++ b/test/Cpp/src/ParametersOutOfOrder.lf @@ -2,7 +2,7 @@ // definition order. Compilation without errors is success. target Cpp -reactor Foo(a: int(0), b: std::string(""), c: float(0.0)) { +reactor Foo(a: int = 0, b: std::string = "", c: float = 0.0) { reaction(startup) {= if (a != 42 || b != "bar" || c < 3.1) { reactor::log::Error() << "received an unexpected parameter!"; diff --git a/test/Cpp/src/PeriodicDesugared.lf b/test/Cpp/src/PeriodicDesugared.lf index 2b6e92c750..2823835687 100644 --- a/test/Cpp/src/PeriodicDesugared.lf +++ b/test/Cpp/src/PeriodicDesugared.lf @@ -3,10 +3,10 @@ target Cpp { timeout: 5 secs } -main reactor(offset: time(50 msec), period: time(500 msec)) { +main reactor(offset: time = 50 msec, period: time = 500 msec) { logical action init(offset): void logical action recur(period): void - state expected(offset) + state expected = offset reaction(startup) -> init {= std::cout << "Hello from Periodic!\n"; diff --git a/test/Cpp/src/Pipeline.lf b/test/Cpp/src/Pipeline.lf index c4300f13c9..cc86ef67a0 100644 --- a/test/Cpp/src/Pipeline.lf +++ b/test/Cpp/src/Pipeline.lf @@ -6,7 +6,7 @@ import Computation from "concurrent/Threaded.lf" reactor Print { input in: int - state count: int(0) + state count: int = 0 reaction(in) {= std::cout << "Received: " << *in.get() << '\n'; @@ -27,7 +27,7 @@ reactor Print { main reactor Pipeline { timer t(0, 200 msec) - state count: int(0) + state count: int = 0 c1 = new Computation() c2 = new Computation() diff --git a/test/Cpp/src/ReadOutputOfContainedReactor.lf b/test/Cpp/src/ReadOutputOfContainedReactor.lf index 6cba642f04..c7e85083b4 100644 --- a/test/Cpp/src/ReadOutputOfContainedReactor.lf +++ b/test/Cpp/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count: int(0) + state count: int = 0 reaction(startup) c.out {= std::cout << "Startup reaction reading output of contained " diff --git a/test/Cpp/src/ScheduleLogicalAction.lf b/test/Cpp/src/ScheduleLogicalAction.lf index c8eaea1a30..96fd5382b7 100644 --- a/test/Cpp/src/ScheduleLogicalAction.lf +++ b/test/Cpp/src/ScheduleLogicalAction.lf @@ -26,7 +26,7 @@ reactor foo { } reactor print { - state expected_time: time(0) + state expected_time: time = 0 input x: int reaction(x) {= diff --git a/test/Cpp/src/SelfLoop.lf b/test/Cpp/src/SelfLoop.lf index be08cc771b..2be47e3d4e 100644 --- a/test/Cpp/src/SelfLoop.lf +++ b/test/Cpp/src/SelfLoop.lf @@ -12,7 +12,7 @@ reactor Self { input x: int output y: int logical action a: int - state expected: int(43) + state expected: int = 43 reaction(a) -> y {= reactor::log::Info() << "a = " << *a.get(); diff --git a/test/Cpp/src/SendingInside.lf b/test/Cpp/src/SendingInside.lf index 2d947f686b..2f73122bc8 100644 --- a/test/Cpp/src/SendingInside.lf +++ b/test/Cpp/src/SendingInside.lf @@ -7,7 +7,7 @@ target Cpp { reactor Printer { input x: int - state count: int(1) + state count: int = 1 reaction(x) {= std::cout << "Inside reactor received: " << *x.get() << std::endl; @@ -20,7 +20,7 @@ reactor Printer { } main reactor SendingInside { - state count: int(0) + state count: int = 0 timer t(0, 1 sec) p = new Printer() diff --git a/test/Cpp/src/SimpleDeadline.lf b/test/Cpp/src/SimpleDeadline.lf index 17c354108a..be10b55d43 100644 --- a/test/Cpp/src/SimpleDeadline.lf +++ b/test/Cpp/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ // violation. target Cpp -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { private preamble {= #include =} diff --git a/test/Cpp/src/SlowingClock.lf b/test/Cpp/src/SlowingClock.lf index 41dda03dba..adbe93e418 100644 --- a/test/Cpp/src/SlowingClock.lf +++ b/test/Cpp/src/SlowingClock.lf @@ -15,8 +15,8 @@ target Cpp { main reactor SlowingClock { logical action a(100 msec) - state interval: time(100 msec) - state expected_time: time(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec reaction(startup) -> a {= a.schedule(0ns); =} diff --git a/test/Cpp/src/SlowingClockPhysical.lf b/test/Cpp/src/SlowingClockPhysical.lf index 24f77cf2be..919f9d6cdf 100644 --- a/test/Cpp/src/SlowingClockPhysical.lf +++ b/test/Cpp/src/SlowingClockPhysical.lf @@ -15,8 +15,8 @@ target Cpp { main reactor SlowingClockPhysical { physical action a - state interval: time(100 msec) - state expected_time: time(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec reaction(startup) -> a {= expected_time=100ms; diff --git a/test/Cpp/src/Stride.lf b/test/Cpp/src/Stride.lf index 8adeaa69b0..5f469e4c70 100644 --- a/test/Cpp/src/Stride.lf +++ b/test/Cpp/src/Stride.lf @@ -5,8 +5,8 @@ target Cpp { fast: true } -reactor Count(stride: int(1)) { - state count: int(0) +reactor Count(stride: int = 1) { + state count: int = 0 output y: int timer t(0, 100 msec) diff --git a/test/Cpp/src/StructPrint.lf b/test/Cpp/src/StructPrint.lf index 9e0bc35d45..4ee404b8bf 100644 --- a/test/Cpp/src/StructPrint.lf +++ b/test/Cpp/src/StructPrint.lf @@ -19,8 +19,8 @@ reactor Source { } reactor Print( - expected_value: int(42), - expected_name: {= std::string =}("Earth") + expected_value: int = 42, + expected_name: {= std::string =} = "Earth" ) { input in: Hello diff --git a/test/Cpp/src/StructScale.lf b/test/Cpp/src/StructScale.lf index cf818f710f..776dad14b1 100644 --- a/test/Cpp/src/StructScale.lf +++ b/test/Cpp/src/StructScale.lf @@ -9,7 +9,7 @@ public preamble {= #include "include/hello.h" =} -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { input in: Hello output out: Hello diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index ec8d43af42..8b33dcd967 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -5,10 +5,10 @@ target Cpp { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int - state s: int(1) + state s: int = 1 reaction(x) {= //std::cout << "Received " << *x.get() << '\n'; @@ -39,7 +39,7 @@ reactor Destination { =} } -main reactor TimeLimit(period: time(1 sec)) { +main reactor TimeLimit(period: time = 1 sec) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/Cpp/src/TimeState.lf b/test/Cpp/src/TimeState.lf index 28228c11ec..aefac79b1c 100644 --- a/test/Cpp/src/TimeState.lf +++ b/test/Cpp/src/TimeState.lf @@ -1,7 +1,7 @@ target Cpp -reactor Foo(bar: time(42 msec)) { - state baz(bar) +reactor Foo(bar: time = 42 msec) { + state baz = bar reaction(startup) {= std::cout << "Baz: " << baz << std::endl; =} } diff --git a/test/Cpp/src/Timeout_Test.lf b/test/Cpp/src/Timeout_Test.lf index 53ff8480dd..c3fe1ffbf9 100644 --- a/test/Cpp/src/Timeout_Test.lf +++ b/test/Cpp/src/Timeout_Test.lf @@ -13,7 +13,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool(false) + state success: bool = false reaction(in) {= auto current{get_elapsed_logical_time()}; diff --git a/test/Cpp/src/ToReactionNested.lf b/test/Cpp/src/ToReactionNested.lf index ff391229a0..5b048bc0a7 100644 --- a/test/Cpp/src/ToReactionNested.lf +++ b/test/Cpp/src/ToReactionNested.lf @@ -12,8 +12,8 @@ reactor CountContainer { } main reactor { - state count: int(1) - state received: bool(false) + state count: int = 1 + state received: bool = false s = new CountContainer() diff --git a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf index d46507fce4..b8c304b164 100644 --- a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf @@ -13,7 +13,7 @@ target Cpp { reactor Source { output[2] out: int - state count: int(0) + state count: int = 0 timer t(0, 200 msec) reaction(t) -> out {= diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index 984132f133..1258f69ce5 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -11,11 +11,11 @@ main reactor AsyncCallback { timer t(0, 200 msec) state thread: {= std::thread =} - state expected_time: time(100 msec) - state toggle: bool(false) + state expected_time: time = 100 msec + state toggle: bool = false physical action a: int - state i: int(0) + state i: int = 0 reaction(t) -> a {= // make sure to join the old thread first diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index 322413617b..c89b8ab712 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -10,10 +10,10 @@ main reactor AsyncCallback2 { =} timer t(0, 200 msec) - state expected_time: time(0) + state expected_time: time = 0 logical action a: int - state i: int(0) + state i: int = 0 reaction(t) -> a {= // start new thread diff --git a/test/Cpp/src/concurrent/CompositionThreaded.lf b/test/Cpp/src/concurrent/CompositionThreaded.lf index 393b08e060..42817e8b1d 100644 --- a/test/Cpp/src/concurrent/CompositionThreaded.lf +++ b/test/Cpp/src/concurrent/CompositionThreaded.lf @@ -5,10 +5,10 @@ target Cpp { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: int timer t(1 sec, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= count++; diff --git a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf index eb88c997eb..bb380fe14c 100644 --- a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -2,7 +2,7 @@ // container reacts to that output. target Cpp -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time(100 msec)) { } main reactor { - state violation_detected: bool({= false =}) + state violation_detected: bool = {= false =} d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/Cpp/src/concurrent/DeadlineThreaded.lf b/test/Cpp/src/concurrent/DeadlineThreaded.lf index ad87c5a052..cb794f5050 100644 --- a/test/Cpp/src/concurrent/DeadlineThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineThreaded.lf @@ -5,13 +5,13 @@ target Cpp { timeout: 4 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { private preamble {= #include =} output y: int timer t(0, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= if (count % 2 == 1) { @@ -25,9 +25,9 @@ reactor Source(period: time(2 sec)) { =} } -reactor Destination(timeout: time(1 sec)) { +reactor Destination(timeout: time = 1 sec) { input x: int - state count: int(0) + state count: int = 0 reaction(x) {= std::cout << "Destination receives: " << *x.get() << std::endl; diff --git a/test/Cpp/src/concurrent/DelayIntThreaded.lf b/test/Cpp/src/concurrent/DelayIntThreaded.lf index d935ae12e5..319cae8b76 100644 --- a/test/Cpp/src/concurrent/DelayIntThreaded.lf +++ b/test/Cpp/src/concurrent/DelayIntThreaded.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target Cpp -reactor Delay(delay: time(100 msec)) { +reactor Delay(delay: time = 100 msec) { input in: int output out: int logical action d: int diff --git a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf index 1c9c3041b6..d68f2e8b60 100644 --- a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf +++ b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf @@ -5,10 +5,10 @@ target Cpp { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int input w: int - state s: int(2) + state s: int = 2 reaction(x, w) {= int sum = 0; diff --git a/test/Cpp/src/concurrent/GainThreaded.lf b/test/Cpp/src/concurrent/GainThreaded.lf index 8e96f44ed1..e88801f5a1 100644 --- a/test/Cpp/src/concurrent/GainThreaded.lf +++ b/test/Cpp/src/concurrent/GainThreaded.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target Cpp -reactor Scale(scale: int(2)) { +reactor Scale(scale: int = 2) { input x: int output y: int diff --git a/test/Cpp/src/concurrent/HelloThreaded.lf b/test/Cpp/src/concurrent/HelloThreaded.lf index 7515d76d38..2c849b94dc 100644 --- a/test/Cpp/src/concurrent/HelloThreaded.lf +++ b/test/Cpp/src/concurrent/HelloThreaded.lf @@ -8,8 +8,11 @@ target Cpp { fast: true } -reactor HelloCpp(period: time(2 sec), message: {= std::string =}("Hello C++")) { - state count: int(0) +reactor HelloCpp( + period: time = 2 sec, + message: {= std::string =} = "Hello C++" +) { + state count: int = 0 state previous_time: {= reactor::TimePoint =} timer t(1 sec, period) logical action a: void @@ -37,8 +40,8 @@ reactor HelloCpp(period: time(2 sec), message: {= std::string =}("Hello C++")) { } reactor Inside( - period: time(1 sec), - message: {= std::string =}("Composite default message.") + period: time = 1 sec, + message: {= std::string =} = "Composite default message." ) { third_instance = new HelloCpp(period = period, message = message) } diff --git a/test/Cpp/src/concurrent/SendingInsideThreaded.lf b/test/Cpp/src/concurrent/SendingInsideThreaded.lf index a0e0fcc250..51ca511e26 100644 --- a/test/Cpp/src/concurrent/SendingInsideThreaded.lf +++ b/test/Cpp/src/concurrent/SendingInsideThreaded.lf @@ -7,7 +7,7 @@ target Cpp { reactor Printer { input x: int - state count: int(1) + state count: int = 1 reaction(x) {= std::cout << "Inside reactor received: " << *x.get() << std::endl; @@ -20,7 +20,7 @@ reactor Printer { } main reactor { - state count: int(0) + state count: int = 0 timer t(0, 1 sec) p = new Printer() diff --git a/test/Cpp/src/concurrent/Threaded.lf b/test/Cpp/src/concurrent/Threaded.lf index 0a0d857030..9ad4fcbe56 100644 --- a/test/Cpp/src/concurrent/Threaded.lf +++ b/test/Cpp/src/concurrent/Threaded.lf @@ -13,7 +13,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= out.set(s); @@ -35,7 +35,7 @@ reactor Computation { } reactor Destination { - state s: int(0) + state s: int = 0 input in1: int input in2: int input in3: int diff --git a/test/Cpp/src/concurrent/ThreadedThreaded.lf b/test/Cpp/src/concurrent/ThreadedThreaded.lf index 2a6680273b..f8b21a6121 100644 --- a/test/Cpp/src/concurrent/ThreadedThreaded.lf +++ b/test/Cpp/src/concurrent/ThreadedThreaded.lf @@ -13,7 +13,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= out.set(s); @@ -35,7 +35,7 @@ reactor Computation { } reactor Destination { - state s: int(0) + state s: int = 0 input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index 5afcf05299..47371f72d7 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -6,10 +6,10 @@ target Cpp { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: int timer t(offset, period) - state count: int(0) + state count: int = 0 reaction(t) -> y {= count++; @@ -20,7 +20,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: int - state s: int(1) + state s: int = 1 reaction(x) {= //std::cout << "Received " << *x.get() << '\n'; @@ -40,7 +40,7 @@ reactor Destination { =} } -main reactor(period: time(1 sec)) { +main reactor(period: time = 1 sec) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/Cpp/src/enclave/EnclaveBank.lf b/test/Cpp/src/enclave/EnclaveBank.lf index b155bd9f57..8894526927 100644 --- a/test/Cpp/src/enclave/EnclaveBank.lf +++ b/test/Cpp/src/enclave/EnclaveBank.lf @@ -4,10 +4,10 @@ target Cpp { } reactor Node( - bank_index: size_t(0), - id: std::string({= "node" + std::to_string(bank_index) =}), - period: time(500 msec), - duration: time(10 msec) + bank_index: size_t = 0, + id: std::string = {= "node" + std::to_string(bank_index) =}, + period: time = 500 msec, + duration: time = 10 msec ) { logical action a: void diff --git a/test/Cpp/src/enclave/EnclaveBankEach.lf b/test/Cpp/src/enclave/EnclaveBankEach.lf index c632d2ae79..c6cdeac564 100644 --- a/test/Cpp/src/enclave/EnclaveBankEach.lf +++ b/test/Cpp/src/enclave/EnclaveBankEach.lf @@ -5,10 +5,10 @@ target Cpp { } reactor Node( - bank_index: size_t(0), - id: std::string({= "node" + std::to_string(bank_index) =}), - period: {= reactor::Duration =}({= 100ms * (bank_index+1) =}), - duration: {= reactor::Duration =}({= 50ms + 100ms * bank_index =}) + bank_index: size_t = 0, + id: std::string = {= "node" + std::to_string(bank_index) =}, + period: {= reactor::Duration =} = {= 100ms * (bank_index+1) =}, + duration: {= reactor::Duration =} = {= 50ms + 100ms * bank_index =} ) { logical action a: void diff --git a/test/Cpp/src/enclave/EnclaveHelloWorld.lf b/test/Cpp/src/enclave/EnclaveHelloWorld.lf index ab28317cf9..7ca051533b 100644 --- a/test/Cpp/src/enclave/EnclaveHelloWorld.lf +++ b/test/Cpp/src/enclave/EnclaveHelloWorld.lf @@ -1,10 +1,10 @@ target Cpp -reactor Hello(msg: std::string("World")) { +reactor Hello(msg: std::string = "World") { reaction(startup) {= reactor::log::Info() << "Hello " << msg << '!'; =} } -main reactor(msg1: std::string("World"), msg2: std::string("Enclave")) { +main reactor(msg1: std::string = "World", msg2: std::string = "Enclave") { hello1 = new Hello(msg = msg1) @enclave diff --git a/test/Cpp/src/enclave/EnclaveHierarchy.lf b/test/Cpp/src/enclave/EnclaveHierarchy.lf index 87c811f859..9063942575 100644 --- a/test/Cpp/src/enclave/EnclaveHierarchy.lf +++ b/test/Cpp/src/enclave/EnclaveHierarchy.lf @@ -4,9 +4,9 @@ target Cpp { } reactor Node( - id: std::string("node"), - period: time(100 msec), - duration: time(50 msec) + id: std::string = "node", + period: time = 100 msec, + duration: time = 50 msec ) { timer t(0, period) diff --git a/test/Cpp/src/enclave/EnclaveShutdown.lf b/test/Cpp/src/enclave/EnclaveShutdown.lf index 7d25a53643..831adcde9c 100644 --- a/test/Cpp/src/enclave/EnclaveShutdown.lf +++ b/test/Cpp/src/enclave/EnclaveShutdown.lf @@ -1,9 +1,9 @@ target Cpp reactor Node( - message: std::string("Hello"), - period: time(1 sec), - stop: time(3 sec) + message: std::string = "Hello", + period: time = 1 sec, + stop: time = 3 sec ) { timer t(0, period) timer s(stop) diff --git a/test/Cpp/src/enclave/EnclaveTimeout.lf b/test/Cpp/src/enclave/EnclaveTimeout.lf index c9dd51498f..dc87acbd26 100644 --- a/test/Cpp/src/enclave/EnclaveTimeout.lf +++ b/test/Cpp/src/enclave/EnclaveTimeout.lf @@ -2,7 +2,7 @@ target Cpp { timeout: 1 sec } -reactor Node(message: std::string("Hello"), period: time(1 sec)) { +reactor Node(message: std::string = "Hello", period: time = 1 sec) { timer t(0, period) reaction(t) {= reactor::log::Info() << message; =} diff --git a/test/Cpp/src/lib/Count.lf b/test/Cpp/src/lib/Count.lf index aaf689b720..7b56233019 100644 --- a/test/Cpp/src/lib/Count.lf +++ b/test/Cpp/src/lib/Count.lf @@ -3,7 +3,7 @@ target Cpp reactor Count { output c: int timer t(0, 1 sec) - state i: int(0) + state i: int = 0 reaction(t) -> c {= i++; diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index db35b7a606..3c1cc13631 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -13,10 +13,10 @@ target Cpp * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after: int(10), break_interval: time(400 msec)) { +reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { output out: int logical action act - state sent_messages: int(0) + state sent_messages: int = 0 reaction(startup, act) -> act, out {= out.set(sent_messages); diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index a32e3a8eac..07da948506 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -8,10 +8,10 @@ */ target Cpp -reactor A(bank_index: size_t(0)) { +reactor A(bank_index: size_t = 0) { input[4] in: size_t output out: size_t - state received: bool(false) + state received: bool = false reaction(startup) -> out {= out.set(bank_index); =} diff --git a/test/Cpp/src/multiport/BankToBank.lf b/test/Cpp/src/multiport/BankToBank.lf index 84fc29ea09..f70cfd83e4 100644 --- a/test/Cpp/src/multiport/BankToBank.lf +++ b/test/Cpp/src/multiport/BankToBank.lf @@ -4,10 +4,10 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t(0)) { +reactor Source(bank_index: size_t = 0) { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= out.set(s); @@ -15,8 +15,8 @@ reactor Source(bank_index: size_t(0)) { =} } -reactor Destination(bank_index: size_t(0)) { - state s: int(0) +reactor Destination(bank_index: size_t = 0) { + state s: int = 0 input in: int reaction(in) {= @@ -37,7 +37,7 @@ reactor Destination(bank_index: size_t(0)) { =} } -main reactor BankToBank(width: int(4)) { +main reactor BankToBank(width: int = 4) { // FIXME: Should set the width to "width" rather than "4". a = new[4] Source() b = new[4] Destination() diff --git a/test/Cpp/src/multiport/BankToBankMultiport.lf b/test/Cpp/src/multiport/BankToBankMultiport.lf index e5c26a4d2b..bdb3e9a880 100644 --- a/test/Cpp/src/multiport/BankToBankMultiport.lf +++ b/test/Cpp/src/multiport/BankToBankMultiport.lf @@ -4,10 +4,10 @@ target Cpp { fast: true } -reactor Source(width: size_t(1)) { +reactor Source(width: size_t = 1) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(size_t i = 0; i < out.size(); i++) { @@ -16,8 +16,8 @@ reactor Source(width: size_t(1)) { =} } -reactor Destination(width: size_t(1)) { - state s: int(6) +reactor Destination(width: size_t = 1) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -44,7 +44,7 @@ reactor Destination(width: size_t(1)) { =} } -main reactor(bank_width: size_t(4)) { +main reactor(bank_width: size_t = 4) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in diff --git a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf index 436a647f94..78d832a5ea 100644 --- a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf @@ -4,10 +4,10 @@ target Cpp { fast: true } -reactor Source(width: size_t(1)) { +reactor Source(width: size_t = 1) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(size_t i = 0; i < out.size(); i++) { @@ -16,9 +16,9 @@ reactor Source(width: size_t(1)) { =} } -reactor Destination(width: size_t(1)) { - state s: int(6) - state iterations: unsigned(0) +reactor Destination(width: size_t = 1) { + state s: int = 6 + state iterations: unsigned = 0 input[width] in: int reaction(in) {= @@ -52,7 +52,7 @@ reactor Destination(width: size_t(1)) { =} } -main reactor(bank_width: size_t(4)) { +main reactor(bank_width: size_t = 4) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in after 200 msec diff --git a/test/Cpp/src/multiport/BankToMultiport.lf b/test/Cpp/src/multiport/BankToMultiport.lf index d8132b2630..6b1acf7591 100644 --- a/test/Cpp/src/multiport/BankToMultiport.lf +++ b/test/Cpp/src/multiport/BankToMultiport.lf @@ -1,7 +1,7 @@ // Test bank of reactors to multiport input with id parameter in the bank. target Cpp -reactor Source(bank_index: size_t(0)) { +reactor Source(bank_index: size_t = 0) { output out: unsigned reaction(startup) -> out {= out.set(bank_index); =} @@ -9,7 +9,7 @@ reactor Source(bank_index: size_t(0)) { reactor Sink { input[4] in: unsigned - state received: bool(false) + state received: bool = false reaction(in) {= for (unsigned i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/Broadcast.lf b/test/Cpp/src/multiport/Broadcast.lf index 471bc92172..077ca75247 100644 --- a/test/Cpp/src/multiport/Broadcast.lf +++ b/test/Cpp/src/multiport/Broadcast.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= out.set(42); =} } -reactor Sink(bank_index: size_t(0)) { +reactor Sink(bank_index: size_t = 0) { input in: unsigned reaction(in) {= diff --git a/test/Cpp/src/multiport/BroadcastAfter.lf b/test/Cpp/src/multiport/BroadcastAfter.lf index 7f0ee66712..6cb7f84f4d 100644 --- a/test/Cpp/src/multiport/BroadcastAfter.lf +++ b/test/Cpp/src/multiport/BroadcastAfter.lf @@ -8,9 +8,9 @@ reactor Source { reaction(startup) -> out {= out.set(42); =} } -reactor Sink(bank_index: size_t(0)) { +reactor Sink(bank_index: size_t = 0) { input in: unsigned - state received: bool{false} + state received: bool = false reaction(in) {= std::cout << bank_index << " received " << *in.get() << '\n'; diff --git a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf index 84051887ca..065e9bf403 100644 --- a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf @@ -2,15 +2,15 @@ target Cpp { fast: true } -reactor Source(value: unsigned(42)) { +reactor Source(value: unsigned = 42) { output out: unsigned reaction(startup) -> out {= out.set(value); =} } -reactor Sink(bank_index: size_t(0)) { +reactor Sink(bank_index: size_t = 0) { input in: unsigned - state received: bool{false} + state received: bool = false reaction(in) {= std::cout << bank_index << " received " << *in.get() << '\n'; diff --git a/test/Cpp/src/multiport/FullyConnected.lf b/test/Cpp/src/multiport/FullyConnected.lf index c925460402..0b0a66405e 100644 --- a/test/Cpp/src/multiport/FullyConnected.lf +++ b/test/Cpp/src/multiport/FullyConnected.lf @@ -1,10 +1,10 @@ target Cpp -reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { +reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { input[num_nodes] in: size_t output out: size_t - state received: bool{false} + state received: bool = false reaction(startup) -> out {= std::cout << "Hello from node " << bank_index << "!\n"; @@ -36,7 +36,7 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { =} } -main reactor(num_nodes: size_t(4)) { +main reactor(num_nodes: size_t = 4) { nodes = new[num_nodes] Node(num_nodes = num_nodes) (nodes.out)+ -> nodes.in } diff --git a/test/Cpp/src/multiport/FullyConnectedAddressable.lf b/test/Cpp/src/multiport/FullyConnectedAddressable.lf index 2a756c328f..5385c44222 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressable.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressable.lf @@ -1,11 +1,11 @@ // In this pattern, each node can send direct messages to individual other nodes target Cpp -reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { +reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { input[num_nodes] in: size_t output[num_nodes] out: size_t - state received: bool{false} + state received: bool = false reaction(startup) -> out {= std::cout << "Hello from node " << bank_index << "!\n"; @@ -41,7 +41,7 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { =} } -main reactor(num_nodes: size_t(4)) { +main reactor(num_nodes: size_t = 4) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) diff --git a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf index e331494b1b..c6fcb4c9e6 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf @@ -3,7 +3,7 @@ target Cpp import Node from "FullyConnectedAddressable.lf" -main reactor(num_nodes: size_t(4)) { +main reactor(num_nodes: size_t = 4) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) after 200 msec diff --git a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf index bf00c15081..964e2e7095 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf @@ -8,7 +8,7 @@ */ target Cpp -reactor ReactorWithMultiport(width: size_t(3)) { +reactor ReactorWithMultiport(width: size_t = 3) { output[width] out: int reaction(startup) -> out {= @@ -18,7 +18,7 @@ reactor ReactorWithMultiport(width: size_t(3)) { =} } -reactor MultiportSplitter(width: size_t(3)) { +reactor MultiportSplitter(width: size_t = 3) { input[width] in: int output out0: int @@ -34,9 +34,9 @@ main reactor IndexIntoMultiportOutput { source.out -> splitter.in - state received0: bool{false} - state received1: bool{false} - state received2: bool{false} + state received0: bool = false + state received1: bool = false + state received2: bool = false reaction(splitter.out0) {= received0 = true; diff --git a/test/Cpp/src/multiport/Multiport.lf b/test/Cpp/src/multiport/Multiport.lf index 946282566f..a63924c67c 100644 --- a/test/Cpp/src/multiport/Multiport.lf +++ b/test/Cpp/src/multiport/Multiport.lf @@ -21,7 +21,7 @@ reactor Test { main reactor Multiport { test = new Test() - state received: bool(false) + state received: bool = false reaction(startup) -> test.sink {= for (auto i = 0; i < 30; i++) { diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index 61d33e2a4c..b7339a9184 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -5,15 +5,15 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t(0)) { +reactor Source(bank_index: size_t = 0) { output out: unsigned reaction(startup) -> out {= out.set(bank_index); =} } -reactor Destination(port_width: size_t(2)) { +reactor Destination(port_width: size_t = 2) { input[port_width] in: unsigned - state received: bool(false) + state received: bool = false reaction(in) {= for (size_t i = 0; i < in.size(); i++) { @@ -35,7 +35,7 @@ reactor Destination(port_width: size_t(2)) { =} } -main reactor(width: size_t(4)) { +main reactor(width: size_t = 4) { a = new[width] Source() b = new Destination(port_width = width) a.out -> b.in diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf index ec75a59be4..673ef6889a 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf @@ -5,7 +5,7 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t(0)) { +reactor Source(bank_index: size_t = 0) { output out: unsigned reaction(startup) -> out {= out.set(bank_index); =} @@ -19,7 +19,7 @@ reactor Container { reactor Destination { input[3] in: unsigned - state received: bool(false) + state received: bool = false reaction(in) {= for (size_t i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index fd0cb4c693..fe27c74f35 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -5,7 +5,7 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t(0)) { +reactor Source(bank_index: size_t = 0) { output out: int reaction(startup) -> out {= out.set(bank_index); =} @@ -19,7 +19,7 @@ reactor Container { reactor Destination { input[3] in: int - state received: bool(false) + state received: bool = false reaction(in) {= for (int i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index c63285af13..fae914b609 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output[4] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s: int(6) + state s: int = 6 input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index 31f06bd956..39fce6f8ff 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= out.set(s++); =} } @@ -21,7 +21,7 @@ reactor Computation { } reactor Destination { - state s: int(0) + state s: int = 0 input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportOut.lf b/test/Cpp/src/multiport/MultiportOut.lf index b4d5e00425..53f2a5bb23 100644 --- a/test/Cpp/src/multiport/MultiportOut.lf +++ b/test/Cpp/src/multiport/MultiportOut.lf @@ -7,7 +7,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output[4] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -31,7 +31,7 @@ reactor Computation { } reactor Destination { - state s: int(0) + state s: int = 0 input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToBank.lf b/test/Cpp/src/multiport/MultiportToBank.lf index 898ccf7b97..fa2f79419f 100644 --- a/test/Cpp/src/multiport/MultiportToBank.lf +++ b/test/Cpp/src/multiport/MultiportToBank.lf @@ -10,7 +10,7 @@ reactor Source { =} } -reactor Sink(bank_index: size_t(0)) { +reactor Sink(bank_index: size_t = 0) { input in: unsigned reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToBankAfter.lf b/test/Cpp/src/multiport/MultiportToBankAfter.lf index 546e569e24..c05730680f 100644 --- a/test/Cpp/src/multiport/MultiportToBankAfter.lf +++ b/test/Cpp/src/multiport/MultiportToBankAfter.lf @@ -10,7 +10,7 @@ reactor Source { =} } -reactor Sink(bank_index: size_t(0)) { +reactor Sink(bank_index: size_t = 0) { input in: unsigned reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf index 11671f98bb..f9cef6a676 100644 --- a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf @@ -15,9 +15,9 @@ reactor Source { =} } -reactor Destination(bank_index: size_t(0)) { +reactor Destination(bank_index: size_t = 0) { input in: unsigned - state received: bool(false) + state received: bool = false reaction(in) {= std::cout << "Destination " << bank_index << " received " << *in.get() << ".\n"; diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index e0daa5a4c0..573a0e06da 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -6,10 +6,10 @@ target Cpp { fast: true } -reactor Source(width: size_t(4)) { +reactor Source(width: size_t = 4) { timer t(0, 200 msec) output[width] out: int - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(size_t i = 0; i < 4; i++) { @@ -18,8 +18,8 @@ reactor Source(width: size_t(4)) { =} } -reactor Destination(width: size_t(4)) { - state s: int(6) +reactor Destination(width: size_t = 4) { + state s: int = 6 input[width] in: int reaction(in) {= @@ -45,13 +45,13 @@ reactor Destination(width: size_t(4)) { =} } -reactor Container(width: size_t(4)) { +reactor Container(width: size_t = 4) { input[width] in: int dst = new Destination() in -> dst.in } -main reactor MultiportToHierarchy(width: size_t(4)) { +main reactor MultiportToHierarchy(width: size_t = 4) { a = new Source(width = width) b = new Container(width = width) a.out -> b.in diff --git a/test/Cpp/src/multiport/MultiportToMultiport.lf b/test/Cpp/src/multiport/MultiportToMultiport.lf index c7b673ea11..37a1ee5222 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport.lf @@ -12,7 +12,7 @@ reactor Source { reactor Sink { input[4] in: unsigned - state received: bool(false) + state received: bool = false reaction(in) {= for (unsigned i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/MultiportToMultiport2.lf b/test/Cpp/src/multiport/MultiportToMultiport2.lf index ac0151731f..165f3201ce 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target Cpp -reactor Source(width: size_t(2)) { +reactor Source(width: size_t = 2) { output[width] out: size_t reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: size_t(2)) { =} } -reactor Destination(width: size_t(2)) { +reactor Destination(width: size_t = 2) { input[width] in: size_t reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToMultiport2After.lf b/test/Cpp/src/multiport/MultiportToMultiport2After.lf index b015bfe827..781275b2f4 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2After.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2After.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target Cpp -reactor Source(width: size_t(2)) { +reactor Source(width: size_t = 2) { output[width] out: size_t reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: size_t(2)) { =} } -reactor Destination(width: size_t(2)) { +reactor Destination(width: size_t = 2) { input[width] in: size_t reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToMultiportArray.lf b/test/Cpp/src/multiport/MultiportToMultiportArray.lf index 077aab0f9d..6c96d17150 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportArray.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportArray.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output[2] out: int[3] - state s: int(0) + state s: int = 0 reaction(t) -> out {= for(int i = 0; i < 2; i++) { @@ -25,7 +25,7 @@ reactor Source { } reactor Destination { - state s: int(15) + state s: int = 15 input[2] in: int[3] reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToPort.lf b/test/Cpp/src/multiport/MultiportToPort.lf index 107198c9cc..c2b0bd66ef 100644 --- a/test/Cpp/src/multiport/MultiportToPort.lf +++ b/test/Cpp/src/multiport/MultiportToPort.lf @@ -16,9 +16,9 @@ reactor Source { =} } -reactor Destination(expected: int(0)) { +reactor Destination(expected: int = 0) { input in: int - state received: bool(false) + state received: bool = false reaction(in) {= std::cout << "Received: " << *in.get() << ".\n"; diff --git a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf index c6bbcf1242..6fa6dbb87b 100644 --- a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf @@ -2,7 +2,7 @@ // multiport target Cpp -reactor Contained(bank_index: size_t(0)) { +reactor Contained(bank_index: size_t = 0) { output[3] out: unsigned reaction(startup) -> out {= @@ -14,7 +14,7 @@ reactor Contained(bank_index: size_t(0)) { main reactor { c = new[3] Contained() - state count: int(0) + state count: int = 0 reaction(startup) c.out {= for (size_t i = 0; i < c.size(); i++) { diff --git a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf index 81deaf91f2..18179b9086 100644 --- a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf @@ -2,7 +2,7 @@ // permutations. target Cpp -reactor Contained(bank_index: size_t(0)) { +reactor Contained(bank_index: size_t = 0) { output out: unsigned reaction(startup) -> out {= out.set(42 * bank_index); =} @@ -10,7 +10,7 @@ reactor Contained(bank_index: size_t(0)) { main reactor { c = new[4] Contained() - state count: int(0) + state count: int = 0 reaction(startup) c.out {= for (size_t i = 0; i < c.size(); i++) { diff --git a/test/Cpp/src/multiport/WidthGivenByCode.lf b/test/Cpp/src/multiport/WidthGivenByCode.lf index 52c2f84b36..10a2a59489 100644 --- a/test/Cpp/src/multiport/WidthGivenByCode.lf +++ b/test/Cpp/src/multiport/WidthGivenByCode.lf @@ -1,6 +1,6 @@ target Cpp -reactor Foo(a: size_t{8}, b: size_t{2}) { +reactor Foo(a: size_t = 8, b: size_t = 2) { input[{= a*b =}] in: size_t output[{= a/b =}] out: size_t diff --git a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf index 3824664e35..b8f8d50958 100644 --- a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf @@ -1,9 +1,9 @@ // Test writing inputs to a contained reactor bank target Cpp -reactor Contained(bank_index: size_t(0)) { +reactor Contained(bank_index: size_t = 0) { input in: unsigned - state count: int(0) + state count: int = 0 reaction(in) {= unsigned result = *in.get(); diff --git a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf index 49e0614842..5ffe567dfb 100644 --- a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf @@ -1,9 +1,9 @@ // Test writing multiport inputs to a contained reactor bank target Cpp -reactor Contained(bank_index: size_t(0)) { +reactor Contained(bank_index: size_t = 0) { input[4] in: unsigned - state count: int(0) + state count: int = 0 reaction(in) {= for (size_t i = 0; i < 3; i++) { diff --git a/test/Cpp/src/properties/Fast.lf b/test/Cpp/src/properties/Fast.lf index a12cbfaf01..1d4ba25d2f 100644 --- a/test/Cpp/src/properties/Fast.lf +++ b/test/Cpp/src/properties/Fast.lf @@ -5,7 +5,7 @@ target Cpp { main reactor { logical action a - state triggered: bool{false} + state triggered: bool = false reaction(startup) -> a {= a.schedule(2s); =} diff --git a/test/Cpp/src/properties/Timeout.lf b/test/Cpp/src/properties/Timeout.lf index 50f647349f..57c55ad24c 100644 --- a/test/Cpp/src/properties/Timeout.lf +++ b/test/Cpp/src/properties/Timeout.lf @@ -5,7 +5,7 @@ target Cpp { main reactor { timer t(1 sec, 1 sec) - state triggered: bool{false} + state triggered: bool = false reaction(t) {= triggered = true; diff --git a/test/Cpp/src/properties/TimeoutZero.lf b/test/Cpp/src/properties/TimeoutZero.lf index 96409f692e..9d04fa8048 100644 --- a/test/Cpp/src/properties/TimeoutZero.lf +++ b/test/Cpp/src/properties/TimeoutZero.lf @@ -5,7 +5,7 @@ target Cpp { main reactor { timer t(0, 1 sec) - state triggered: bool{false} + state triggered: bool = false reaction(t) {= triggered = true; diff --git a/test/Cpp/src/target/AfterVoid.lf b/test/Cpp/src/target/AfterVoid.lf index 0b9beadcff..555e024e6b 100644 --- a/test/Cpp/src/target/AfterVoid.lf +++ b/test/Cpp/src/target/AfterVoid.lf @@ -12,8 +12,8 @@ reactor foo { } reactor print { - state expected_time: time(10 msec) - state i: int(0) + state expected_time: time = 10 msec + state i: int = 0 input x: void reaction(x) {= diff --git a/test/Cpp/src/target/BraceAndParenInitialization.lf b/test/Cpp/src/target/BraceAndParenInitialization.lf index 8838187bc2..003b6d509d 100644 --- a/test/Cpp/src/target/BraceAndParenInitialization.lf +++ b/test/Cpp/src/target/BraceAndParenInitialization.lf @@ -26,8 +26,5 @@ reactor Foo( } main reactor { - foo = new Foo( - param_list_3 = {= std::vector(3, 5) =}, - param_list_4 = {= {3, 5} =} - ) + foo = new Foo(param_list_3 = {= std::vector(3, 5) =}, param_list_4 = {3, 5}) } diff --git a/test/Cpp/src/target/CliParserGenericArguments.lf b/test/Cpp/src/target/CliParserGenericArguments.lf index eb75ac2ef6..9a008ebcab 100644 --- a/test/Cpp/src/target/CliParserGenericArguments.lf +++ b/test/Cpp/src/target/CliParserGenericArguments.lf @@ -43,19 +43,19 @@ private preamble {= =} main reactor CliParserGenericArguments( - int_value: int(10), - signed_value: signed(-10), - unsigned_value: unsigned(11), - long_value: long(-100), - unsigned_long_value: {= unsigned_long =}(42), - long_long_value: {= long_long =}(-42), - ull_value: {= uns_long_long =}(42), - bool_value: bool(false), - char_value: char('T'), - double_value: double(4.2), - long_double_value: {= long_double =}(4.2), - float_value: float(10.5), - string_value: string("This is a testvalue"), + int_value: int = 10, + signed_value: signed = -10, + unsigned_value: unsigned = 11, + long_value: long = -100, + unsigned_long_value: {= unsigned_long =} = 42, + long_long_value: {= long_long =} = -42, + ull_value: {= uns_long_long =} = 42, + bool_value: bool = false, + char_value: char = 'T', + double_value: double = 4.2, + long_double_value: {= long_double =} = 4.2, + float_value: float = 10.5, + string_value: string = "This is a testvalue", custom_class_value: {= CustomClass =}("Peter") ) { reaction(startup) {= std::cout << "Hello World!\n"; =} diff --git a/test/Cpp/src/target/CombinedTypeNames.lf b/test/Cpp/src/target/CombinedTypeNames.lf index 28182b7bf7..d55c70a823 100644 --- a/test/Cpp/src/target/CombinedTypeNames.lf +++ b/test/Cpp/src/target/CombinedTypeNames.lf @@ -3,11 +3,11 @@ target Cpp reactor Foo( - bar: {= unsigned int =}(0), - baz: {= const unsigned int* =}({= nullptr =}) + bar: {= unsigned int =} = 0, + baz: {= const unsigned int* =} = {= nullptr =} ) { - state s_bar: {= unsigned int =}(bar) - state s_baz: {= const unsigned int* =}(baz) + state s_bar: {= unsigned int =} = bar + state s_baz: {= const unsigned int* =} = baz reaction(startup) {= if (bar != 42 || s_bar != 42 || *baz != 42 || *s_baz != 42) { @@ -17,6 +17,6 @@ reactor Foo( =} } -main reactor(bar: {= unsigned int =}(42)) { +main reactor(bar: {= unsigned int =} = 42) { foo = new Foo(bar = bar, baz = {= &bar =}) } diff --git a/test/Cpp/src/target/GenericDelay.lf b/test/Cpp/src/target/GenericDelay.lf index 135c04f417..5efa81b011 100644 --- a/test/Cpp/src/target/GenericDelay.lf +++ b/test/Cpp/src/target/GenericDelay.lf @@ -2,7 +2,7 @@ target Cpp import Test from "../DelayInt.lf" -reactor Delay(delay: time(0)) { +reactor Delay(delay: time = 0) { output out: T input in: T logical action a(delay): T diff --git a/test/Cpp/src/target/GenericParameterAndState.lf b/test/Cpp/src/target/GenericParameterAndState.lf index d259bf3b22..6803eb9509 100644 --- a/test/Cpp/src/target/GenericParameterAndState.lf +++ b/test/Cpp/src/target/GenericParameterAndState.lf @@ -1,7 +1,7 @@ target Cpp -reactor Foo(bar: T(0), expected: T(14542135)) { - state baz: T(bar) +reactor Foo(bar: T = 0, expected: T = 14542135) { + state baz: T = bar reaction(startup) {= if (bar != expected) { diff --git a/test/Cpp/src/target/InitializerSyntax.lf b/test/Cpp/src/target/InitializerSyntax.lf new file mode 100644 index 0000000000..54ae268457 --- /dev/null +++ b/test/Cpp/src/target/InitializerSyntax.lf @@ -0,0 +1,89 @@ +target Cpp + +public preamble {= + #include + struct TestType { + int x; + + // constructor #1 + TestType() : x(42) {} + // constructor #2 + TestType(int x) : x(x) {} + // constructor #3 + TestType(std::initializer_list l) : x(l.size()) {} + // constructor #4 + TestType(const TestType& t) : x(t.x + 10) { } + // constructor #5 + TestType(TestType&& t) : x(t.x + 20) { } + + TestType& operator=(const TestType& t) { + std::cout << "assign\n"; + this->x = t.x + 30; + return *this; + } + TestType& operator=(TestType&& t) { + this->x = t.x + 40; + return *this; + } + + ~TestType() = default; + }; +=} + +reactor TestReactor( + /** + * FIXME: should work without an explicit initialization, see + * https://github.com/lf-lang/lingua-franca/issues/623 + */ + // p_default: TestType, constructor #1 + p_default: TestType(), + p_empty: TestType(), // constructor #1 + p_value: TestType(24), // constructor #2 + p_init_empty: TestType{}, // constructor #1 + p_init_empty2: TestType({}), // constructor #1 + p_init_some: TestType{2, 6, 6, 3, 1}, // constructor #1 + p_assign_init_empty: TestType = {}, // constructor #1 + p_assign_init_some: TestType = {4, 2, 1} // constructor #3 +) { + state s_default: TestType // constructor #1 + state s_empty: TestType() // constructor #1 + state s_value: TestType(24) // constructor #2 + state s_init_empty: TestType{} // constructor #1 + state s_init_empty2: TestType({}) // constructor #3 + state s_init_some: TestType{3, 12, 40} // constructor #3 + state s_assign_init_empty: TestType = {} // constructor #3 + state s_assign_init_some: TestType = {4, 3, 2, 1} // constructor #3 + state s_copy1: TestType(p_default) // constructor #4 + state s_copy2: TestType{p_default} // constructor #4 + state s_copy3: TestType = p_default // constructor #4 + + reaction(startup) {= + reactor::validate(p_default.x == 62, "p_default should be default constructed and then moved"); + reactor::validate(p_empty.x == 62, "p_empty should be default constructed and then moved"); + reactor::validate(p_value.x == 44, "p_value should be constructed from 24 and then moved"); + reactor::validate(p_init_empty.x == 62, "p_init_empty should be default constructed and then moved"); + reactor::validate(p_init_empty2.x == 20, "p_init_empty2 should be constructed with 0 and then moved"); + reactor::validate(p_init_some.x == 25, "p_init_some should be constructed with 3 and then moved"); + reactor::validate(p_assign_init_empty.x == 62, "p_assign_init_empty should be default constructed and then moved"); + reactor::validate(p_assign_init_some.x == 23, "p_assign_init_some should be constructed with 4 and then moved"); + + reactor::validate(s_default.x == 42, "s_default should be default constructed"); + reactor::validate(s_empty.x == 42, "s_empty should be default constructed"); + reactor::validate(s_value.x == 24, "s_value should be constructed with 24"); + reactor::validate(s_init_empty.x == 42, "s_init_empty should be default constructed"); + reactor::validate(s_init_empty2.x == 0, "s_init_empty2 should be constructed with 0"); + reactor::validate(s_init_some.x == 3, "s_init_some should be constructed with 3"); + // NOTE: This is a strange corner case. Since the equal assignment will be translated to a () initializers (e.g. :foo(42)), + // the initialization here in LF behaves differently from what one might expect. When writing `Foo foo = {}`, + // the default constructor would be called instead of the initializer list constructor. + reactor::validate(s_assign_init_empty.x == 0, "s_assign_init_empty should be constructed with 0"); + reactor::validate(s_assign_init_some.x == 4, "s_assign_init_some should be constructed with 4"); + reactor::validate(s_copy1.x == 72, "s_copy1 should be copy constructed from p_default"); + reactor::validate(s_copy2.x == 72, "s_copy1 should be copy constructed from p_default"); + reactor::validate(s_copy3.x == 72, "s_copy1 should be copy constructed from p_default"); + =} +} + +main reactor { + test = new TestReactor() +} diff --git a/test/Cpp/src/target/PointerParameters.lf b/test/Cpp/src/target/PointerParameters.lf index cb8675d014..a769f20da3 100644 --- a/test/Cpp/src/target/PointerParameters.lf +++ b/test/Cpp/src/target/PointerParameters.lf @@ -2,7 +2,7 @@ // Compilation without errors is success. target Cpp -reactor Foo(ptr: int*{{= nullptr =}}) { +reactor Foo(ptr: int* = {= nullptr =}) { reaction(startup) {= if (ptr == nullptr || *ptr != 42) { reactor::log::Error() << "received an unexpected value!"; diff --git a/test/Python/src/ActionDelay.lf b/test/Python/src/ActionDelay.lf index 7c325bb2cb..60efa42f57 100644 --- a/test/Python/src/ActionDelay.lf +++ b/test/Python/src/ActionDelay.lf @@ -4,7 +4,7 @@ target Python reactor GeneratedDelay { input y_in output y_out - state y_state(0) + state y_state = 0 logical action act(100 msec) reaction(y_in) -> act {= diff --git a/test/Python/src/ActionIsPresent.lf b/test/Python/src/ActionIsPresent.lf index 259417110e..ceb52d10b8 100644 --- a/test/Python/src/ActionIsPresent.lf +++ b/test/Python/src/ActionIsPresent.lf @@ -1,10 +1,10 @@ # Tests the is_present variable for actions. target Python -main reactor ActionIsPresent(offset(1 nsec), period(500 msec)) { +main reactor ActionIsPresent(offset = 1 nsec, period = 500 msec) { logical action a - state first_time(True) - state success(False) + state first_time = True + state success = False reaction(startup, a) -> a {= # The is_present field should be initially False diff --git a/test/Python/src/After.lf b/test/Python/src/After.lf index 13b1970d5a..0c8b931543 100644 --- a/test/Python/src/After.lf +++ b/test/Python/src/After.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time(10 msec) - state received(0) + state expected_time = 10 msec + state received = 0 input x reaction(x) {= diff --git a/test/Python/src/AfterCycles.lf b/test/Python/src/AfterCycles.lf index ef1500af27..cd0f0dd98e 100644 --- a/test/Python/src/AfterCycles.lf +++ b/test/Python/src/AfterCycles.lf @@ -16,7 +16,7 @@ reactor Work { } main reactor AfterCycles { - state count(0) + state count = 0 s = new Source() w0 = new Work() w1 = new Work() diff --git a/test/Python/src/AfterOverlapped.lf b/test/Python/src/AfterOverlapped.lf index 2876538189..32657f1cdb 100644 --- a/test/Python/src/AfterOverlapped.lf +++ b/test/Python/src/AfterOverlapped.lf @@ -8,8 +8,8 @@ import Count from "lib/Count.lf" reactor Test { input c - state i(0) - state received(0) + state i = 0 + state received = 0 reaction(c) {= self.received += 1 diff --git a/test/Python/src/ArrayAsParameter.lf b/test/Python/src/ArrayAsParameter.lf index 67af462358..359e38b7a3 100644 --- a/test/Python/src/ArrayAsParameter.lf +++ b/test/Python/src/ArrayAsParameter.lf @@ -3,7 +3,7 @@ target Python reactor Source(sequence(0, 1, 2)) { output out - state count(0) + state count = 0 logical action next reaction(startup, next) -> out, next {= @@ -16,8 +16,8 @@ reactor Source(sequence(0, 1, 2)) { reactor Print { input _in - state count(1) - state received(0) + state count = 1 + state received = 0 reaction(_in) {= self.received+=1 @@ -36,7 +36,7 @@ reactor Print { } main reactor ArrayAsParameter { - s = new Source(sequence = (1, 2, 3, 4)) + s = new Source(sequence(1, 2, 3, 4)) p = new Print() s.out -> p._in } diff --git a/test/Python/src/ArrayAsType.lf b/test/Python/src/ArrayAsType.lf index 2025cecbd1..dc3b2f6e26 100644 --- a/test/Python/src/ArrayAsType.lf +++ b/test/Python/src/ArrayAsType.lf @@ -11,7 +11,7 @@ reactor Source { =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/ArrayFree.lf b/test/Python/src/ArrayFree.lf index 893fbc4358..2ea2777c12 100644 --- a/test/Python/src/ArrayFree.lf +++ b/test/Python/src/ArrayFree.lf @@ -7,7 +7,7 @@ target Python import Source, Print from "ArrayPrint.lf" import Scale from "ArrayScale.lf" -reactor Free(scale(2)) { +reactor Free(scale = 2) { mutable input _in reaction(_in) {= diff --git a/test/Python/src/ArrayPrint.lf b/test/Python/src/ArrayPrint.lf index 039debac0c..4420311b93 100644 --- a/test/Python/src/ArrayPrint.lf +++ b/test/Python/src/ArrayPrint.lf @@ -11,7 +11,7 @@ reactor Source { =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/ArrayScale.lf b/test/Python/src/ArrayScale.lf index 620b63e10f..2b69aebe77 100644 --- a/test/Python/src/ArrayScale.lf +++ b/test/Python/src/ArrayScale.lf @@ -6,7 +6,7 @@ target Python import Print, Source from "ArrayPrint.lf" -reactor Scale(scale(2)) { +reactor Scale(scale = 2) { mutable input _in output out diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index 3a737295bf..d1bef93ed2 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -5,10 +5,10 @@ target Python { timeout: 10 sec } -reactor Source(period(2 sec)) { +reactor Source(period = 2 sec) { output y timer t(1 sec, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -20,7 +20,7 @@ reactor Source(period(2 sec)) { reactor Test { input x - state count(0) + state count = 0 reaction(x) {= self.count += 1 diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index f21b7ae75e..00b95e3ab9 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target Python { timeout: 10 sec } -reactor Source(period(2 sec)) { +reactor Source(period = 2 sec) { output y timer t(1 sec, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -18,7 +18,7 @@ reactor Source(period(2 sec)) { reactor Test { input x - state count(0) + state count = 0 reaction(x) {= self.count += 1 @@ -29,7 +29,7 @@ reactor Test { =} } -main reactor(delay(5 sec)) { +main reactor(delay = 5 sec) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index deac45b05a..4b0e4a38c9 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -5,11 +5,11 @@ target Python { timeout: 10 sec } -reactor Source(period(2 sec)) { +reactor Source(period = 2 sec) { input foo output y timer t(1 sec, period) - state count(0) + state count = 0 reaction(t) -> y {= print("Hello World. My count is: ", self.count) @@ -30,7 +30,7 @@ reactor SourceExtended extends Source { reactor Test { input x - state count(0) + state count = 0 reaction(x) {= self.count += 1 diff --git a/test/Python/src/CountSelf.lf b/test/Python/src/CountSelf.lf index 40f4778c71..74219e6fe0 100644 --- a/test/Python/src/CountSelf.lf +++ b/test/Python/src/CountSelf.lf @@ -4,7 +4,7 @@ target Python { fast: true } -reactor CountSelf2(delay(100 msec)) { +reactor CountSelf2(delay = 100 msec) { output out logical action a @@ -21,7 +21,7 @@ reactor CountSelf2(delay(100 msec)) { reactor Test { input _in - state count(0) + state count = 0 reaction(_in) {= print("Received: {:d}".format(_in.value)) diff --git a/test/Python/src/CountTest.lf b/test/Python/src/CountTest.lf index 2761d22a5b..06c4a6fdb6 100644 --- a/test/Python/src/CountTest.lf +++ b/test/Python/src/CountTest.lf @@ -7,7 +7,7 @@ import Count from "lib/Count.lf" reactor Test { input c - state i(0) + state i = 0 reaction(c) {= print("Received ", c.value) diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index aeed5f0d5e..ceab2b28e2 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -7,10 +7,10 @@ target Python { preamble {= import time =} -reactor Source(period(3 sec)) { +reactor Source(period = 3 sec) { output y timer t(0, period) - state count(0) + state count = 0 reaction(t) -> y {= if self.count % 2 != 0: @@ -24,9 +24,9 @@ reactor Source(period(3 sec)) { =} } -reactor Destination(timeout(1 sec)) { +reactor Destination(timeout = 1 sec) { input x - state count(0) + state count = 0 reaction(x) {= print("Destination receives: ", x.value) diff --git a/test/Python/src/DeadlineHandledAbove.lf b/test/Python/src/DeadlineHandledAbove.lf index d3df675152..1259253cea 100644 --- a/test/Python/src/DeadlineHandledAbove.lf +++ b/test/Python/src/DeadlineHandledAbove.lf @@ -4,7 +4,7 @@ target Python preamble {= import time =} -reactor Deadline(threshold(100 msec)) { +reactor Deadline(threshold = 100 msec) { input x output deadline_violation @@ -18,7 +18,7 @@ reactor Deadline(threshold(100 msec)) { } main reactor DeadlineHandledAbove { - state violation_detected(false) + state violation_detected = False d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/Python/src/DelayArray.lf b/test/Python/src/DelayArray.lf index abcf367d45..945b786cca 100644 --- a/test/Python/src/DelayArray.lf +++ b/test/Python/src/DelayArray.lf @@ -1,7 +1,7 @@ # This tests delaying an array type. target Python -reactor DelayPointer(delay(100 msec)) { +reactor DelayPointer(delay = 100 msec) { # The Python target does not require explicit type allocation for types # other than time mutable input _in @@ -25,7 +25,7 @@ reactor Source { =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/DelayArrayWithAfter.lf b/test/Python/src/DelayArrayWithAfter.lf index e244690ec8..1e6ac1f317 100644 --- a/test/Python/src/DelayArrayWithAfter.lf +++ b/test/Python/src/DelayArrayWithAfter.lf @@ -7,7 +7,7 @@ target Python { reactor Source { output out - state iteration(1) + state iteration = 1 timer t(0, 1 sec) reaction(t) -> out {= @@ -18,10 +18,10 @@ reactor Source { =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input _in - state iteration(1) - state inputs_received(0) + state iteration = 1 + state inputs_received = 0 reaction(_in) {= self.inputs_received += 1 diff --git a/test/Python/src/DelayInt.lf b/test/Python/src/DelayInt.lf index d12c8b968b..fae554bd30 100644 --- a/test/Python/src/DelayInt.lf +++ b/test/Python/src/DelayInt.lf @@ -1,7 +1,7 @@ # This tests actions with payloads by delaying an input by a fixed amount. target Python -reactor Delay(delay(100 msec)) { +reactor Delay(delay = 100 msec) { input _in output out logical action a @@ -16,8 +16,8 @@ reactor Delay(delay(100 msec)) { reactor Test { input _in - state start_time(0) - state received_value(false) + state start_time = 0 + state received_value = False reaction(startup) {= # Record the logical time at the start. diff --git a/test/Python/src/DelayString.lf b/test/Python/src/DelayString.lf index f315b0bec2..d1201dec02 100644 --- a/test/Python/src/DelayString.lf +++ b/test/Python/src/DelayString.lf @@ -2,7 +2,7 @@ # freed. target Python -reactor DelayString2(delay(100 msec)) { +reactor DelayString2(delay = 100 msec) { input _in output out logical action a @@ -14,7 +14,7 @@ reactor DelayString2(delay(100 msec)) { reactor Test { input _in - state start_time(0) + state start_time = 0 reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/DelayStruct.lf b/test/Python/src/DelayStruct.lf index f16aedfe7c..e578a42699 100644 --- a/test/Python/src/DelayStruct.lf +++ b/test/Python/src/DelayStruct.lf @@ -5,7 +5,7 @@ target Python { preamble {= import hello =} -reactor DelayPointer(delay(100 msec)) { +reactor DelayPointer(delay = 100 msec) { input _in output out logical action a @@ -25,7 +25,7 @@ reactor Source { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor Print(expected(42)) { # expected parameter is for testing. +reactor Print(expected = 42) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/DelayStructWithAfter.lf b/test/Python/src/DelayStructWithAfter.lf index 21dafab29e..5bb945cb3c 100644 --- a/test/Python/src/DelayStructWithAfter.lf +++ b/test/Python/src/DelayStructWithAfter.lf @@ -11,7 +11,7 @@ reactor Source { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor Print(expected(42)) { # expected parameter is for testing. +reactor Print(expected = 42) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/DelayStructWithAfterOverlapped.lf b/test/Python/src/DelayStructWithAfterOverlapped.lf index f19c5cd1bd..072012a106 100644 --- a/test/Python/src/DelayStructWithAfterOverlapped.lf +++ b/test/Python/src/DelayStructWithAfterOverlapped.lf @@ -10,7 +10,7 @@ preamble {= import hello =} reactor Source { output out timer t(0, 1 sec) - state s(0) + state s = 0 reaction(t) -> out {= self.s += 1 @@ -20,7 +20,7 @@ reactor Source { reactor Print { # expected parameter is for testing. input _in - state s(0) + state s = 0 reaction(_in) {= self.s += 1 diff --git a/test/Python/src/DelayedAction.lf b/test/Python/src/DelayedAction.lf index 3f6fb70608..06c488b9c5 100644 --- a/test/Python/src/DelayedAction.lf +++ b/test/Python/src/DelayedAction.lf @@ -6,7 +6,7 @@ target Python { main reactor DelayedAction { timer t(0, 1 sec) logical action a - state count(0) + state count = 0 reaction(t) -> a {= a.schedule(MSEC(100)) =} diff --git a/test/Python/src/DoubleInvocation.lf b/test/Python/src/DoubleInvocation.lf index d14edd6332..aaecfa31cb 100644 --- a/test/Python/src/DoubleInvocation.lf +++ b/test/Python/src/DoubleInvocation.lf @@ -13,7 +13,7 @@ target Python { reactor Ball { output position output velocity - state p(200) + state p = 200 timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -26,7 +26,7 @@ reactor Ball { reactor Print { input velocity input position - state previous(-1) + state previous = -1 reaction(startup) {= print("####### Print startup\n") diff --git a/test/Python/src/DoubleReaction.lf b/test/Python/src/DoubleReaction.lf index 2061ab5a1c..c20a032a9a 100644 --- a/test/Python/src/DoubleReaction.lf +++ b/test/Python/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target Python { fast: true } -reactor Clock(offset(0), period(1 sec)) { +reactor Clock(offset = 0, period = 1 sec) { output y timer t(offset, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -19,7 +19,7 @@ reactor Clock(offset(0), period(1 sec)) { reactor Destination { input x input w - state s(2) + state s = 2 reaction(x, w) {= sm = 0 diff --git a/test/Python/src/FloatLiteral.lf b/test/Python/src/FloatLiteral.lf index 5ed6202429..b55953d135 100644 --- a/test/Python/src/FloatLiteral.lf +++ b/test/Python/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target Python # This test verifies that floating-point literals are handled correctly. main reactor { - state N(6.0221409e+23) - state charge(-1.6021766E-19) - state minus_epsilon(-.01e0) - state expected(.964853323188E5) + state N = 6.0221409e+23 + state charge = -1.6021766E-19 + state minus_epsilon = -.01e0 + state expected = .964853323188E5 reaction(startup) {= F = - self.N * self.charge diff --git a/test/Python/src/Gain.lf b/test/Python/src/Gain.lf index 38459a9380..d69d4d2a65 100644 --- a/test/Python/src/Gain.lf +++ b/test/Python/src/Gain.lf @@ -1,7 +1,7 @@ # Example in the Wiki. target Python -reactor Scale(scale(2)) { +reactor Scale(scale = 2) { input x output y @@ -10,7 +10,7 @@ reactor Scale(scale(2)) { reactor Test { input x - state received_value(0) + state received_value = 0 reaction(x) {= print("Received " + str(x.value)) diff --git a/test/Python/src/GetMicroStep.lf b/test/Python/src/GetMicroStep.lf index 7b1da9bb40..124c692ef8 100644 --- a/test/Python/src/GetMicroStep.lf +++ b/test/Python/src/GetMicroStep.lf @@ -5,7 +5,7 @@ target Python { main reactor GetMicroStep { preamble {= import sys =} - state s(1) + state s = 1 logical action l # timer t(0, 1 msec); diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index 0da0d53f47..271ed180ca 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -8,9 +8,9 @@ target Python { fast: true } -reactor Reschedule(period(2 sec), message("Hello Python")) { - state count(0) - state previous_time(0) +reactor Reschedule(period = 2 sec, message = "Hello Python") { + state count = 0 + state previous_time = 0 timer t(1 sec, period) logical action a @@ -38,7 +38,7 @@ reactor Reschedule(period(2 sec), message("Hello Python")) { =} } -reactor Inside(period(1 sec), message("Composite default message.")) { +reactor Inside(period = 1 sec, message = "Composite default message.") { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/Python/src/HelloWorld.lf b/test/Python/src/HelloWorld.lf index 725a73d0ac..523ff9ce2b 100644 --- a/test/Python/src/HelloWorld.lf +++ b/test/Python/src/HelloWorld.lf @@ -3,7 +3,7 @@ target Python { } reactor HelloWorld2 { - state success(False) + state success = False reaction(startup) {= print("Hello World.") diff --git a/test/Python/src/Hierarchy2.lf b/test/Python/src/Hierarchy2.lf index 07e67a765b..a1792712fa 100644 --- a/test/Python/src/Hierarchy2.lf +++ b/test/Python/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out timer t(0, 1 sec) - state i(0) + state i = 0 reaction(t) -> out {= self.i += 1 @@ -39,7 +39,7 @@ reactor Add { reactor Print { input _in - state expected(2) + state expected = 2 reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/IdentifierLength.lf b/test/Python/src/IdentifierLength.lf index 66edf11abf..62b31141a0 100644 --- a/test/Python/src/IdentifierLength.lf +++ b/test/Python/src/IdentifierLength.lf @@ -6,11 +6,11 @@ target Python { } reactor A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_The_Maximum_For_The_Python_Target( - period(2 sec) + period = 2 sec ) { output y timer t(1 sec, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -20,7 +20,7 @@ reactor A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_Th reactor Another_Really_Long_Name_For_A_Test_Class { input x - state count(0) + state count = 0 reaction(x) {= self.count += 1 diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 4e57dc6423..369fbcab44 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -6,7 +6,7 @@ import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { a = new ImportedComposition() - state received(false) + state received = False reaction(startup) -> a.x {= a.x.set(42) =} diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index 0d142405cd..a9e39829eb 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -9,7 +9,7 @@ target Python { reactor GeneratedDelay { input y_in output y_out - state y_state(0) + state y_state = 0 physical action act(0 msec) # TODO: delay in act or the schedule call? diff --git a/test/Python/src/Methods.lf b/test/Python/src/Methods.lf index cc29079dad..5e0023fe8f 100644 --- a/test/Python/src/Methods.lf +++ b/test/Python/src/Methods.lf @@ -2,7 +2,7 @@ target Python main reactor { - state foo(2) + state foo = 2 method getFoo() {= return self.foo =} diff --git a/test/Python/src/MethodsRecursive.lf b/test/Python/src/MethodsRecursive.lf index ca3ea237e7..81afc86bea 100644 --- a/test/Python/src/MethodsRecursive.lf +++ b/test/Python/src/MethodsRecursive.lf @@ -2,7 +2,7 @@ target Python main reactor { - state foo(2) + state foo = 2 method fib(n) {= # Return the n-th Fibonacci number. if n <= 1: diff --git a/test/Python/src/MethodsSameName.lf b/test/Python/src/MethodsSameName.lf index c4d6cdbc4c..a80f521356 100644 --- a/test/Python/src/MethodsSameName.lf +++ b/test/Python/src/MethodsSameName.lf @@ -2,7 +2,7 @@ target Python reactor Foo { - state foo(2) + state foo = 2 method add(x) {= self.foo += x =} @@ -16,7 +16,7 @@ reactor Foo { } main reactor { - state foo(2) + state foo = 2 a = new Foo() diff --git a/test/Python/src/MovingAverage.lf b/test/Python/src/MovingAverage.lf index 505b6a043d..3dbd5636c3 100644 --- a/test/Python/src/MovingAverage.lf +++ b/test/Python/src/MovingAverage.lf @@ -10,7 +10,7 @@ import TestDouble from "lib/Test.lf" reactor MASource { output out - state count(0) + state count = 0 timer clock(0, 200 msec) reaction(clock) -> out {= @@ -21,7 +21,7 @@ reactor MASource { reactor MovingAverageImpl { state delay_line(0.0, 0.0, 0.0) - state index(0) + state index = 0 input m_in output out @@ -45,7 +45,7 @@ reactor MovingAverageImpl { main reactor MovingAverage { s = new MASource() m = new MovingAverageImpl() - p = new TestDouble(expected = (0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) + p = new TestDouble(expected(0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) s.out -> m.m_in m.out -> p.t_in } diff --git a/test/Python/src/MultipleContained.lf b/test/Python/src/MultipleContained.lf index 0b055951c5..27950ccd88 100644 --- a/test/Python/src/MultipleContained.lf +++ b/test/Python/src/MultipleContained.lf @@ -4,7 +4,7 @@ target Python reactor Contained { output trigger - state count(0) + state count = 0 input in1 input in2 diff --git a/test/Python/src/NativeListsAndTimes.lf b/test/Python/src/NativeListsAndTimes.lf index f8b60ed87d..b7b52b3d0a 100644 --- a/test/Python/src/NativeListsAndTimes.lf +++ b/test/Python/src/NativeListsAndTimes.lf @@ -2,22 +2,22 @@ target Python # This test passes if it is successfully compiled into valid target code. main reactor( - x(0), - y(0), # Units are missing but not required - z(1 msec), # Type is missing but not required + x = 0, + y = 0, # Units are missing but not required + z = 1 msec, # Type is missing but not required p(1, 2, 3, 4), # List of integers q(1 msec, 2 msec, 3 msec), # list of time values g(1 msec, 2 msec) # List of time values ) { - state s(y) # Reference to explicitly typed time parameter - state t(z) # Reference to implicitly typed time parameter + state s = y # Reference to explicitly typed time parameter + state t = z # Reference to implicitly typed time parameter state v # Uninitialized boolean state variable state w # Uninitialized time state variable timer tick(0) # Units missing but not required timer tock(1 sec) # Implicit type time timer toe(z) # Implicit type time - state baz(p) # Implicit type int[] - state period(z) # Implicit type time + state baz = p # Implicit type int[] + state period = z # Implicit type time state bar(1 msec, 2 msec, 3 msec) # list of time values state notype(1, 2, 3, 4) diff --git a/test/Python/src/ParameterizedState.lf b/test/Python/src/ParameterizedState.lf index 3511c8d2f5..e8805b027f 100644 --- a/test/Python/src/ParameterizedState.lf +++ b/test/Python/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target Python -reactor Foo(bar(42)) { - state baz(bar) +reactor Foo(bar = 42) { + state baz = bar reaction(startup) {= print("Baz: ", self.baz) =} } diff --git a/test/Python/src/PeriodicDesugared.lf b/test/Python/src/PeriodicDesugared.lf index 5dc7f7bb8f..b003ffc9f8 100644 --- a/test/Python/src/PeriodicDesugared.lf +++ b/test/Python/src/PeriodicDesugared.lf @@ -3,7 +3,7 @@ target Python { timeout: 1 sec } -main reactor(offset(0), period(500 msec)) { +main reactor(offset = 0, period = 500 msec) { logical action init(offset) logical action recur(period) diff --git a/test/Python/src/PingPong.lf b/test/Python/src/PingPong.lf index 25ffdea3a8..f5f80511ae 100644 --- a/test/Python/src/PingPong.lf +++ b/test/Python/src/PingPong.lf @@ -24,10 +24,10 @@ target Python { fast: true } -reactor Ping(count(10)) { +reactor Ping(count = 10) { input receive output send - state pingsLeft(count) + state pingsLeft = count logical action serve reaction(startup, serve) -> send {= @@ -43,10 +43,10 @@ reactor Ping(count(10)) { =} } -reactor Pong(expected(10)) { +reactor Pong(expected = 10) { input receive output send - state count(0) + state count = 0 reaction(receive) -> send {= self.count += 1 diff --git a/test/Python/src/Pipeline.lf b/test/Python/src/Pipeline.lf index 014680e3ca..18436561b8 100644 --- a/test/Python/src/Pipeline.lf +++ b/test/Python/src/Pipeline.lf @@ -17,8 +17,8 @@ reactor TakeTime { reactor Print { input _in - state count(0) - state received(0) + state count = 0 + state received = 0 reaction(_in) {= self.received += 1 @@ -38,7 +38,7 @@ reactor Print { main reactor Pipeline { timer t(0, 200 msec) - state count(0) + state count = 0 c1 = new TakeTime() c2 = new TakeTime() diff --git a/test/Python/src/ReadOutputOfContainedReactor.lf b/test/Python/src/ReadOutputOfContainedReactor.lf index 25c8a1a368..1cb73667ce 100644 --- a/test/Python/src/ReadOutputOfContainedReactor.lf +++ b/test/Python/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count(0) + state count = 0 reaction(startup) c.out {= print("Startup reaction reading output of contained reactor: ", c.out.value) diff --git a/test/Python/src/ScheduleLogicalAction.lf b/test/Python/src/ScheduleLogicalAction.lf index 10f8d4e3cd..3f99c65777 100644 --- a/test/Python/src/ScheduleLogicalAction.lf +++ b/test/Python/src/ScheduleLogicalAction.lf @@ -20,7 +20,7 @@ reactor foo { } reactor print { - state expected_time(0) + state expected_time = 0 input x reaction(x) {= diff --git a/test/Python/src/SelfLoop.lf b/test/Python/src/SelfLoop.lf index 1653b893e3..2b607b09c8 100644 --- a/test/Python/src/SelfLoop.lf +++ b/test/Python/src/SelfLoop.lf @@ -7,7 +7,7 @@ reactor Self { input x output y logical action a - state expected(43) + state expected = 43 reaction(a) -> y {= print("a = ", a.value) diff --git a/test/Python/src/SendingInside.lf b/test/Python/src/SendingInside.lf index 08d05b8ed9..8bcc66c005 100644 --- a/test/Python/src/SendingInside.lf +++ b/test/Python/src/SendingInside.lf @@ -7,7 +7,7 @@ target Python { reactor Printer { input x - state count(1) + state count = 1 reaction(x) {= print("Inside reactor received: ", x.value) @@ -19,7 +19,7 @@ reactor Printer { } main reactor SendingInside { - state count(0) + state count = 0 timer t(0, 1 sec) p = new Printer() diff --git a/test/Python/src/SetArray.lf b/test/Python/src/SetArray.lf index 356899ae8f..4766d529f7 100644 --- a/test/Python/src/SetArray.lf +++ b/test/Python/src/SetArray.lf @@ -9,7 +9,7 @@ reactor Source { reaction(startup) -> out {= out.set([0,1,2]) =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/SimpleDeadline.lf b/test/Python/src/SimpleDeadline.lf index 0385f95f74..a714124129 100644 --- a/test/Python/src/SimpleDeadline.lf +++ b/test/Python/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ # violation. target Python -reactor Deadline(threshold(100 msec)) { +reactor Deadline(threshold = 100 msec) { input x output deadlineViolation diff --git a/test/Python/src/SlowingClock.lf b/test/Python/src/SlowingClock.lf index b566781677..972421437a 100644 --- a/test/Python/src/SlowingClock.lf +++ b/test/Python/src/SlowingClock.lf @@ -10,8 +10,8 @@ target Python { main reactor SlowingClock { logical action a(100 msec) - state interval(100 msec) - state expected_time(100 msec) + state interval = 100 msec + state expected_time = 100 msec reaction(startup) -> a {= a.schedule(0) =} diff --git a/test/Python/src/SlowingClockPhysical.lf b/test/Python/src/SlowingClockPhysical.lf index b2533acf12..dbb9da705f 100644 --- a/test/Python/src/SlowingClockPhysical.lf +++ b/test/Python/src/SlowingClockPhysical.lf @@ -15,8 +15,8 @@ target Python { main reactor SlowingClockPhysical { # first offset and minimum interarrival time. physical action a(100 msec, 100 msec) - state interval(100 msec) - state expected_time(100 msec) + state interval = 100 msec + state expected_time = 100 msec reaction(startup) -> a {= self.expected_time = MSEC(100) diff --git a/test/Python/src/Stride.lf b/test/Python/src/Stride.lf index 95fe379ead..86c68bab5a 100644 --- a/test/Python/src/Stride.lf +++ b/test/Python/src/Stride.lf @@ -5,8 +5,8 @@ target Python { fast: true } -reactor Count(stride(1)) { - state count(1) +reactor Count(stride = 1) { + state count = 1 output y timer t(0, 100 msec) @@ -18,7 +18,7 @@ reactor Count(stride(1)) { reactor Display { input x - state expected(1) # for testing. + state expected = 1 # for testing. reaction(x) {= print("Received: ", x.value) diff --git a/test/Python/src/StructAsState.lf b/test/Python/src/StructAsState.lf index 4fec8dfc0e..b6f38f8589 100644 --- a/test/Python/src/StructAsState.lf +++ b/test/Python/src/StructAsState.lf @@ -9,7 +9,7 @@ main reactor StructAsState { self.name = name self.value = value =} - state s({= self.hello("Earth", 42) =}) + state s = {= self.hello("Earth", 42) =} reaction(startup) {= print("State s.name=\"{:s}\", value={:d}.".format(self.s.name, self.s.value)) diff --git a/test/Python/src/StructAsType.lf b/test/Python/src/StructAsType.lf index d8955d0064..46951ec86a 100644 --- a/test/Python/src/StructAsType.lf +++ b/test/Python/src/StructAsType.lf @@ -13,7 +13,7 @@ reactor Source { =} } -reactor Print(expected(42)) { # expected parameter is for testing. +reactor Print(expected = 42) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/StructAsTypeDirect.lf b/test/Python/src/StructAsTypeDirect.lf index 50f4805a1f..921b7e4390 100644 --- a/test/Python/src/StructAsTypeDirect.lf +++ b/test/Python/src/StructAsTypeDirect.lf @@ -16,7 +16,7 @@ reactor Source { =} } -reactor Print(expected(42)) { # expected parameter is for testing. +reactor Print(expected = 42) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/StructParallel.lf b/test/Python/src/StructParallel.lf index fb34a84981..bac79a6abe 100644 --- a/test/Python/src/StructParallel.lf +++ b/test/Python/src/StructParallel.lf @@ -8,7 +8,7 @@ import Source from "StructScale.lf" preamble {= import hello =} -reactor Check(expected(42)) { +reactor Check(expected = 42) { input _in reaction(_in) {= @@ -19,7 +19,7 @@ reactor Check(expected(42)) { =} } -reactor Print(scale(2)) { +reactor Print(scale = 2) { # Mutable keyword indicates that this reactor wants a writable copy of the # input. mutable input _in diff --git a/test/Python/src/StructPrint.lf b/test/Python/src/StructPrint.lf index f232c07a14..3c0138f937 100644 --- a/test/Python/src/StructPrint.lf +++ b/test/Python/src/StructPrint.lf @@ -12,7 +12,7 @@ reactor Print { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor Check(expected(42)) { # expected parameter is for testing. +reactor Check(expected = 42) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/StructScale.lf b/test/Python/src/StructScale.lf index e9ed86ff5b..120c6fde65 100644 --- a/test/Python/src/StructScale.lf +++ b/test/Python/src/StructScale.lf @@ -12,7 +12,7 @@ reactor Source { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor TestInput(expected(42)) { # expected parameter is for testing. +reactor TestInput(expected = 42) { # expected parameter is for testing. input _in reaction(_in) {= @@ -23,7 +23,7 @@ reactor TestInput(expected(42)) { # expected parameter is for testing. =} } -reactor Print(scale(2)) { +reactor Print(scale = 2) { # Mutable keyword indicates that this reactor wants a writable copy of the # input. mutable input _in diff --git a/test/Python/src/SubclassesAndStartup.lf b/test/Python/src/SubclassesAndStartup.lf index 9dae1495be..a98e580851 100644 --- a/test/Python/src/SubclassesAndStartup.lf +++ b/test/Python/src/SubclassesAndStartup.lf @@ -1,7 +1,7 @@ target Python reactor Super { - state count(0) + state count = 0 reaction(startup) {= print("{:s}(Super) started".format(self.name)) @@ -15,7 +15,7 @@ reactor Super { =} } -reactor SubA(name("SubA")) extends Super { +reactor SubA(name = "SubA") extends Super { reaction(startup) {= print("{:s} started".format(self.name)) if self.count == 0: @@ -24,7 +24,7 @@ reactor SubA(name("SubA")) extends Super { =} } -reactor SubB(name("SubB")) extends Super { +reactor SubB(name = "SubB") extends Super { reaction(startup) {= print("{:s} started".format(self.name)) if self.count == 0: diff --git a/test/Python/src/TimeLimit.lf b/test/Python/src/TimeLimit.lf index 47577e9ed5..beb7602db9 100644 --- a/test/Python/src/TimeLimit.lf +++ b/test/Python/src/TimeLimit.lf @@ -5,10 +5,10 @@ target Python { fast: true } -reactor Clock(offset(0), period(1 sec)) { +reactor Clock(offset = 0, period = 1 sec) { output y timer t(offset, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -19,7 +19,7 @@ reactor Clock(offset(0), period(1 sec)) { reactor Destination { input x - state s(1) + state s = 1 reaction(x) {= # print(x.value) @@ -37,7 +37,7 @@ reactor Destination { =} } -main reactor TimeLimit(period(1 sec)) { +main reactor TimeLimit(period = 1 sec) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/Python/src/TimeState.lf b/test/Python/src/TimeState.lf index c12318400b..72ad9f0ebd 100644 --- a/test/Python/src/TimeState.lf +++ b/test/Python/src/TimeState.lf @@ -1,7 +1,7 @@ target Python -reactor Foo(bar(42)) { - state baz(500 msec) +reactor Foo(bar = 42) { + state baz = 500 msec reaction(startup) {= print("Baz: ", self.baz) =} } diff --git a/test/Python/src/Timers.lf b/test/Python/src/Timers.lf index ad59feca99..f6cbba747a 100644 --- a/test/Python/src/Timers.lf +++ b/test/Python/src/Timers.lf @@ -6,7 +6,7 @@ target Python { main reactor { timer t(0, 1 sec) timer t2(0, 2 sec) - state counter(0) + state counter = 0 reaction(t2) {= self.counter += 2 =} diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf index c436a41cd9..b65f732652 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf @@ -10,7 +10,7 @@ target Python { reactor Source { output a output b - state count(0) + state count = 0 timer t(0, 200 msec) reaction(t) -> a, b {= diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf index 310c1d1d02..b9a9184296 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf @@ -9,7 +9,7 @@ target Python { reactor Source { output[2] out - state count(0) + state count = 0 timer t(0, 200 msec) reaction(t) -> out {= diff --git a/test/Python/src/UnconnectedInput.lf b/test/Python/src/UnconnectedInput.lf index ee40844a99..66f459138b 100644 --- a/test/Python/src/UnconnectedInput.lf +++ b/test/Python/src/UnconnectedInput.lf @@ -7,7 +7,7 @@ target Python { reactor Source { output out timer t(0, 1 sec) - state s(1) + state s = 1 reaction(t) -> out {= out.set(self.s) @@ -32,7 +32,7 @@ reactor Add { reactor Print { input _in - state expected(1) + state expected = 1 reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index 3769f09dc0..5ef4167bed 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -30,12 +30,12 @@ main reactor AsyncCallback { return None =} timer t(0, 200 msec) - state threads({= list() =}) - state expected_time(100 msec) - state toggle(false) + state threads = {= list() =} + state expected_time = 100 msec + state toggle = False physical action a(100 msec) - state i(0) + state i = 0 reaction(t) -> a {= # start new thread, provide callback diff --git a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf index ff9a8613d6..4e481d1d34 100644 --- a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf +++ b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf @@ -34,12 +34,12 @@ main reactor { return None =} - state threads({= list() =}) - state expected_time(100 msec) - state toggle(false) + state threads = {= list() =} + state expected_time = 100 msec + state toggle = False physical action a(100 msec) - state i(0) + state i = 0 reaction(startup) -> a {= # start new thread, provide callback diff --git a/test/Python/src/docker/FilesPropertyContainerized.lf b/test/Python/src/docker/FilesPropertyContainerized.lf index 2b592921e8..c34736af48 100644 --- a/test/Python/src/docker/FilesPropertyContainerized.lf +++ b/test/Python/src/docker/FilesPropertyContainerized.lf @@ -17,7 +17,7 @@ main reactor { except: lf_request_stop() =} - state passed(false) + state passed = False timer t(1 msec) reaction(t) {= self.passed = True =} diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index 50f1f5cb12..5f8a348d24 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -15,7 +15,7 @@ target Python { import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" -federated reactor DistributedCountContainerized(offset(200 msec)) at rti { +federated reactor DistributedCountContainerized(offset = 200 msec) at rti { c = new Count() p = new Print() c.out -> p.in_ after offset diff --git a/test/Python/src/federated/BroadcastFeedback.lf b/test/Python/src/federated/BroadcastFeedback.lf index e7c8dcb527..75d313e61d 100644 --- a/test/Python/src/federated/BroadcastFeedback.lf +++ b/test/Python/src/federated/BroadcastFeedback.lf @@ -8,7 +8,7 @@ target Python { reactor SenderAndReceiver { output out input[2] inp - state received(False) + state received = False reaction(startup) -> out {= out.set(42) =} diff --git a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf index 63cd79ad1f..ad2a11c10c 100644 --- a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -8,7 +8,7 @@ target Python { reactor SenderAndReceiver { output out input[2] in_ - state received(False) + state received = False r = new Receiver() in_ -> r.in_ @@ -19,7 +19,7 @@ reactor SenderAndReceiver { reactor Receiver { preamble {= import sys =} input[2] in_ - state received(False) + state received = False reaction(in_) {= if in_[0].is_present and in_[1].is_present and in_[0].value == 42 and in_[1].value == 42: diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index faba30f7e1..cf9b6d6b54 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -10,7 +10,7 @@ reactor CAReplica { input remote_update input query - state balance(0) + state balance = 0 output response diff --git a/test/Python/src/federated/DecentralizedP2PComm.lf b/test/Python/src/federated/DecentralizedP2PComm.lf index 29aee88ad5..2725386915 100644 --- a/test/Python/src/federated/DecentralizedP2PComm.lf +++ b/test/Python/src/federated/DecentralizedP2PComm.lf @@ -5,13 +5,13 @@ target Python { coordination: decentralized } -reactor Platform(start(0), expected_start(0), stp_offset_param(0)) { +reactor Platform(start = 0, expected_start = 0, stp_offset_param = 0) { preamble {= import sys =} input in_ output out timer t(0, 100 msec) - state count(start) - state expected(expected_start) + state count = start + state expected = expected_start reaction(t) -> out {= out.set(self.count) diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 960a06c650..48ff7a4ca7 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -12,10 +12,10 @@ target Python { } # reason for failing: lf_tag() not supported by the python target -reactor Clock(offset(0), period(1 sec)) { +reactor Clock(offset = 0, period = 1 sec) { output y timer t(offset, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -29,7 +29,7 @@ reactor Clock(offset(0), period(1 sec)) { reactor Destination { preamble {= import sys =} input x - state s(1) + state s = 1 state startup_logical_time reaction(startup) {= self.startup_logical_time = lf.time.logical() =} @@ -50,7 +50,7 @@ reactor Destination { =} } -federated reactor(period(10 usec)) { +federated reactor(period = 10 usec) { c = new Clock(period = period) d = new Destination() c.y -> d.x diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index c9de7270c6..4eb881694f 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -12,10 +12,10 @@ target Python { coordination: decentralized } -reactor Clock(offset(0), period(1 sec)) { +reactor Clock(offset = 0, period = 1 sec) { output y timer t(offset, period) - state count(0) + state count = 0 reaction(t) -> y {= self.count += 1 @@ -28,7 +28,7 @@ reactor Clock(offset(0), period(1 sec)) { reactor Destination { preamble {= import sys =} input x - state s(1) + state s = 1 reaction(x) {= if x.value != self.s: @@ -43,7 +43,7 @@ reactor Destination { =} } -federated reactor(period(10 usec)) { +federated reactor(period = 10 usec) { c = new Clock(period = period) d = new Destination() c.y ~> d.x diff --git a/test/Python/src/federated/DistributedBank.lf b/test/Python/src/federated/DistributedBank.lf index ace6b6b53c..de9ea298e4 100644 --- a/test/Python/src/federated/DistributedBank.lf +++ b/test/Python/src/federated/DistributedBank.lf @@ -7,7 +7,7 @@ target Python { reactor Node { preamble {= import sys =} timer t(0, 100 msec) - state count(0) + state count = 0 reaction(t) {= print("Hello world {}.".format(self.count)) diff --git a/test/Python/src/federated/DistributedBankToMultiport.lf b/test/Python/src/federated/DistributedBankToMultiport.lf index f40a85fc65..493e73a3b1 100644 --- a/test/Python/src/federated/DistributedBankToMultiport.lf +++ b/test/Python/src/federated/DistributedBankToMultiport.lf @@ -8,7 +8,7 @@ import Count from "../lib/Count.lf" reactor Destination { preamble {= import sys =} input[2] in_ - state count(1) + state count = 1 reaction(in_) {= for i in range(len(in_)): diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index eb90b4d672..7713256520 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -15,7 +15,7 @@ import Count from "../lib/Count.lf" reactor Print { preamble {= import sys =} input in_ - state c(1) + state c = 1 reaction(in_) {= elapsed_time = lf.time.logical_elapsed() @@ -36,7 +36,7 @@ reactor Print { =} } -federated reactor DistributedCount(offset(200 msec)) { +federated reactor DistributedCount(offset = 200 msec) { c = new Count() p = new Print() c.out -> p.in_ after offset diff --git a/test/Python/src/federated/DistributedCountDecentralized.lf b/test/Python/src/federated/DistributedCountDecentralized.lf index 232c3ef830..e86adf9946 100644 --- a/test/Python/src/federated/DistributedCountDecentralized.lf +++ b/test/Python/src/federated/DistributedCountDecentralized.lf @@ -16,7 +16,7 @@ import Count from "../lib/Count.lf" reactor Print { preamble {= import sys =} input in_ - state c(1) + state c = 1 reaction(in_) {= print(f"At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), received {in_.value}. " diff --git a/test/Python/src/federated/DistributedCountDecentralizedLate.lf b/test/Python/src/federated/DistributedCountDecentralizedLate.lf index 617673aa0e..e3a6899e78 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLate.lf @@ -18,12 +18,12 @@ reactor Print { # STP () input in_ # STP(in, 30 msec); - state success(0) - state success_stp_violation(0) + state success = 0 + state success_stp_violation = 0 # Force a timer to be invoke periodically timer t(0, 10 usec) # to ensure logical time will advance in the absence of incoming messages. - state c(0) + state c = 0 reaction(in_) {= current_tag = lf.tag() diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf b/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf index 18a55f7e6b..c1c641827f 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf @@ -28,12 +28,12 @@ import Count from "../lib/Count.lf" reactor ImportantActuator { input inp # Count messages that arrive without STP violation. - state success(0) - state success_stp_violation(0) + state success = 0 + state success_stp_violation = 0 # Force a timer to be invoked periodically timer t(0, 10 usec) # to ensure logical time will advance in the absence of incoming messages. - state c(0) + state c = 0 reaction(inp) {= current_tag = lf.tag() @@ -81,7 +81,7 @@ reactor Receiver { # Force a timer to be invoke periodically timer t(0, 10 msec) # to ensure logical time will advance in the absence of incoming messages. - state c(0) + state c = 0 p = new Print() a = new ImportantActuator() diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf index e9a1bec87e..d806ab5453 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -21,7 +21,7 @@ reactor Receiver { # Force a timer to be invoke periodically timer t(0, 10 msec) # to ensure logical time will advance in the absence of incoming messages. - state c(0) + state c = 0 p = new Print() a = new ImportantActuator() inp -> p.inp diff --git a/test/Python/src/federated/DistributedCountPhysical.lf b/test/Python/src/federated/DistributedCountPhysical.lf index b957e06172..69bc2faee9 100644 --- a/test/Python/src/federated/DistributedCountPhysical.lf +++ b/test/Python/src/federated/DistributedCountPhysical.lf @@ -13,7 +13,7 @@ target Python { reactor Count { timer t(200 msec, 1 sec) - state s(0) + state s = 0 output out reaction(t) -> out {= @@ -25,7 +25,7 @@ reactor Count { reactor Print { preamble {= import sys =} input in_ - state c(0) + state c = 0 reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf index 80c931184b..105413d0a0 100644 --- a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -13,7 +13,7 @@ target Python { reactor Count { timer t(200 msec, 1 sec) - state s(0) + state s = 0 output out reaction(t) -> out {= @@ -25,7 +25,7 @@ reactor Count { reactor Print { preamble {= import sys =} input in_ - state c(0) + state c = 0 reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf index 120bb6255c..0008479138 100644 --- a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf @@ -14,7 +14,7 @@ target Python { reactor Count { timer t(200 msec, 1 sec) - state s(0) + state s = 0 output out reaction(t) -> out {= @@ -26,7 +26,7 @@ reactor Count { reactor Print { preamble {= import sys =} input in_ - state c(0) + state c = 0 reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/DistributedDoublePort.lf b/test/Python/src/federated/DistributedDoublePort.lf index 03ad2c4d08..9eb24209e6 100644 --- a/test/Python/src/federated/DistributedDoublePort.lf +++ b/test/Python/src/federated/DistributedDoublePort.lf @@ -14,7 +14,7 @@ target Python { import Count from "../lib/Count.lf" reactor CountMicrostep { - state count(1) + state count = 1 output out logical action act timer t(0, 1 sec) diff --git a/test/Python/src/federated/DistributedLoopedAction.lf b/test/Python/src/federated/DistributedLoopedAction.lf index 83aa1de0a6..8f71d15363 100644 --- a/test/Python/src/federated/DistributedLoopedAction.lf +++ b/test/Python/src/federated/DistributedLoopedAction.lf @@ -10,12 +10,12 @@ target Python { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver(take_a_break_after(10), break_interval(400 msec)) { +reactor Receiver(take_a_break_after = 10, break_interval = 400 msec) { preamble {= import sys =} input in_ - state received_messages(0) - state total_received_messages(0) - state breaks(0) + state received_messages = 0 + state total_received_messages = 0 + state breaks = 0 timer t(0, 1 msec) # This will impact the performance # but forces the logical time to advance Comment this line for a more diff --git a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf index a2cce3742a..d992e3d841 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf @@ -14,10 +14,10 @@ target Python { keepalive: true } -reactor Sender(take_a_break_after(10), break_interval(550 msec)) { +reactor Sender(take_a_break_after = 10, break_interval = 550 msec) { output out physical action act - state sent_messages(0) + state sent_messages = 0 reaction(startup, act) -> act, out {= # Send a message on out @@ -32,12 +32,12 @@ reactor Sender(take_a_break_after(10), break_interval(550 msec)) { =} } -reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { +reactor Receiver(take_a_break_after = 10, break_interval = 550 msec) { preamble {= import sys =} input in_ - state received_messages(0) - state total_received_messages(0) - state breaks(0) + state received_messages = 0 + state total_received_messages = 0 + state breaks = 0 timer t(0, 1 msec) # This will impact the performance # but forces the logical time to advance Comment this line for a more # sensible log output. diff --git a/test/Python/src/federated/DistributedMultiport.lf b/test/Python/src/federated/DistributedMultiport.lf index 729f8697d8..7250f838ef 100644 --- a/test/Python/src/federated/DistributedMultiport.lf +++ b/test/Python/src/federated/DistributedMultiport.lf @@ -7,7 +7,7 @@ target Python { reactor Source { output[4] out timer t(0, 100 msec) - state count(0) + state count = 0 reaction(t) -> out {= for i in range(len(out)): @@ -19,7 +19,7 @@ reactor Source { reactor Destination { preamble {= import sys =} input[4] in_ - state count(0) + state count = 0 reaction(in_) {= for i in range(len(in_)): diff --git a/test/Python/src/federated/DistributedMultiportToBank.lf b/test/Python/src/federated/DistributedMultiportToBank.lf index cbd500394e..69c87b7f0c 100644 --- a/test/Python/src/federated/DistributedMultiportToBank.lf +++ b/test/Python/src/federated/DistributedMultiportToBank.lf @@ -6,7 +6,7 @@ target Python { reactor Source { output[2] out timer t(0, 100 msec) - state count(0) + state count = 0 reaction(t) -> out {= for i in range(len(out)): @@ -18,7 +18,7 @@ reactor Source { reactor Destination { preamble {= import sys =} input in_ - state count(0) + state count = 0 reaction(in_) {= print("Received {}.".format(in_.value)) diff --git a/test/Python/src/federated/DistributedMultiportToken.lf b/test/Python/src/federated/DistributedMultiportToken.lf index fdecd67c32..284e1c21a3 100644 --- a/test/Python/src/federated/DistributedMultiportToken.lf +++ b/test/Python/src/federated/DistributedMultiportToken.lf @@ -8,7 +8,7 @@ target Python { reactor Source { output[4] out timer t(0, 200 msec) - state count(0) + state count = 0 reaction(t) -> out {= for i in range(len(out)): diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index b4a84b8bef..06dfe96c36 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -12,7 +12,7 @@ reactor Sender { output out timer t(0, 1 usec) logical action act - state reaction_invoked_correctly(False) + state reaction_invoked_correctly = False reaction(t, act) -> out, act {= tag = lf.tag() @@ -62,10 +62,10 @@ reactor Sender { } reactor Receiver( - stp_offset(10 msec) # Used in the decentralized variant of the test + stp_offset = 10 msec # Used in the decentralized variant of the test ) { input in_ - state reaction_invoked_correctly(False) + state reaction_invoked_correctly = False reaction(in_) {= tag = lf.tag() diff --git a/test/Python/src/federated/HelloDistributed.lf b/test/Python/src/federated/HelloDistributed.lf index 5b8a2a55e4..ef99c3f793 100644 --- a/test/Python/src/federated/HelloDistributed.lf +++ b/test/Python/src/federated/HelloDistributed.lf @@ -19,7 +19,7 @@ reactor Source { reactor Destination { input _in - state received(false) + state received = False reaction(startup) {= print("Destination started.") =} diff --git a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 9dc86b3c60..2719fd57ba 100644 --- a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -14,11 +14,11 @@ target Python { timeout: 5 sec } -reactor Contained(incr(1)) { +reactor Contained(incr = 1) { timer t(0, 1 sec) input inp - state count(0) - state received_count(0) + state count = 0 + state received_count = 0 reaction(t) {= self.count += self.incr =} @@ -31,10 +31,10 @@ reactor Contained(incr(1)) { =} } -reactor Looper(incr(1), delay(0 msec)) { +reactor Looper(incr = 1, delay = 0 msec) { input inp output out - state count(0) + state count = 0 timer t(0, 1 sec) c = new Contained(incr = incr) @@ -59,7 +59,7 @@ reactor Looper(incr(1), delay(0 msec)) { =} } -federated reactor(delay(0)) { +federated reactor(delay = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.inp diff --git a/test/Python/src/federated/PhysicalSTP.lf b/test/Python/src/federated/PhysicalSTP.lf index 75e5071bca..5edc61df34 100644 --- a/test/Python/src/federated/PhysicalSTP.lf +++ b/test/Python/src/federated/PhysicalSTP.lf @@ -9,10 +9,10 @@ target Python { import Count from "../lib/Count.lf" -reactor Print(STP_offset(0)) { +reactor Print(STP_offset = 0) { preamble {= import sys =} input in_ - state c(1) + state c = 1 reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index a157baa22a..0f58cbf7db 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -21,10 +21,10 @@ */ target Python -reactor Ping(count(10)) { +reactor Ping(count = 10) { input receive output send - state pingsLeft(count) + state pingsLeft = count logical action serve reaction(startup, serve) -> send {= @@ -41,12 +41,12 @@ reactor Ping(count(10)) { =} } -reactor Pong(expected(10)) { +reactor Pong(expected = 10) { preamble {= import sys =} input receive output send - state count(0) + state count = 0 reaction(receive) -> send {= self.count += 1 @@ -64,7 +64,7 @@ reactor Pong(expected(10)) { =} } -federated reactor(count(10)) { +federated reactor(count = 10) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send ~> pong.receive diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf index 9068ebfae8..12367332f4 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf @@ -16,11 +16,11 @@ target Python { timeout: 5 sec } -reactor Looper(incr(1), delay(0 msec)) { +reactor Looper(incr = 1, delay = 0 msec) { input in_ output out - state count(0) - state received_count(0) + state count = 0 + state received_count = 0 timer t(0, 1 sec) reaction(t) -> out {= @@ -50,7 +50,7 @@ reactor Looper(incr(1), delay(0 msec)) { =} } -federated reactor(delay(0)) { +federated reactor(delay = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in_ diff --git a/test/Python/src/federated/failing/LoopDistributedDouble.lf b/test/Python/src/federated/failing/LoopDistributedDouble.lf index 8788d09288..4ccee4acd6 100644 --- a/test/Python/src/federated/failing/LoopDistributedDouble.lf +++ b/test/Python/src/federated/failing/LoopDistributedDouble.lf @@ -24,13 +24,13 @@ preamble {= } =} -reactor Looper(incr(1), delay(0 msec)) { +reactor Looper(incr = 1, delay = 0 msec) { input in_ input in2 output out output out2 physical action a(delay) - state count(0) + state count = 0 timer t(0, 1 sec) reaction(startup) -> a {= @@ -79,7 +79,7 @@ reactor Looper(incr(1), delay(0 msec)) { =} } -federated reactor(delay(0)) { +federated reactor(delay = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in_ diff --git a/test/Python/src/lib/Count.lf b/test/Python/src/lib/Count.lf index bcfae967b6..26b53ce13b 100644 --- a/test/Python/src/lib/Count.lf +++ b/test/Python/src/lib/Count.lf @@ -1,7 +1,7 @@ target Python -reactor Count(offset(0), period(1 sec)) { - state count(1) +reactor Count(offset = 0, period = 1 sec) { + state count = 1 output out timer t(offset, period) diff --git a/test/Python/src/lib/InternalDelay.lf b/test/Python/src/lib/InternalDelay.lf index f2ac5449c0..a9796aa8d9 100644 --- a/test/Python/src/lib/InternalDelay.lf +++ b/test/Python/src/lib/InternalDelay.lf @@ -1,6 +1,6 @@ target Python -reactor InternalDelay(delay(10 msec)) { +reactor InternalDelay(delay = 10 msec) { input in_ output out logical action d diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index 3a01219ec8..9d4048d0ea 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -11,10 +11,10 @@ target Python * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after(10), break_interval(400 msec)) { +reactor Sender(take_a_break_after = 10, break_interval = 400 msec) { output out logical action act - state sent_messages(0) + state sent_messages = 0 reaction(startup, act) -> act, out {= # Send a message on out diff --git a/test/Python/src/lib/Test.lf b/test/Python/src/lib/Test.lf index f6bbf867ee..301ed9c8e6 100644 --- a/test/Python/src/lib/Test.lf +++ b/test/Python/src/lib/Test.lf @@ -2,7 +2,7 @@ target Python reactor TestDouble(expected(1.0, 1.0, 1.0, 1.0)) { input t_in - state count(0) + state count = 0 reaction(t_in) {= print("Received: ", t_in.value) diff --git a/test/Python/src/lib/TestCount.lf b/test/Python/src/lib/TestCount.lf index dfe11cd5b9..de611cbc69 100644 --- a/test/Python/src/lib/TestCount.lf +++ b/test/Python/src/lib/TestCount.lf @@ -9,10 +9,10 @@ */ target Python -reactor TestCount(start(1), stride(1), num_inputs(1)) { +reactor TestCount(start = 1, stride = 1, num_inputs = 1) { preamble {= import sys =} - state count(start) - state inputs_received(0) + state count = start + state inputs_received = 0 input in_ reaction(in_) {= diff --git a/test/Python/src/lib/TestCountMultiport.lf b/test/Python/src/lib/TestCountMultiport.lf index d9b711ce89..c30572e4d5 100644 --- a/test/Python/src/lib/TestCountMultiport.lf +++ b/test/Python/src/lib/TestCountMultiport.lf @@ -11,10 +11,10 @@ */ target Python -reactor TestCountMultiport(start(1), stride(1), num_inputs(1), width(2)) { +reactor TestCountMultiport(start = 1, stride = 1, num_inputs = 1, width = 2) { preamble {= import sys =} - state count(start) - state inputs_received(0) + state count = start + state inputs_received = 0 input[width] inp reaction(inp) {= diff --git a/test/Python/src/modal_models/ConvertCaseTest.lf b/test/Python/src/modal_models/ConvertCaseTest.lf index f391660322..f3bdee59fe 100644 --- a/test/Python/src/modal_models/ConvertCaseTest.lf +++ b/test/Python/src/modal_models/ConvertCaseTest.lf @@ -67,9 +67,9 @@ reactor Converter { } } -reactor InputFeeder(message("")) { +reactor InputFeeder(message = "") { output character - state idx(0) + state idx = 0 timer t(0, 250 msec) diff --git a/test/Python/src/modal_models/Count3Modes.lf b/test/Python/src/modal_models/Count3Modes.lf index e512e7d54a..7e2e9d98e2 100644 --- a/test/Python/src/modal_models/Count3Modes.lf +++ b/test/Python/src/modal_models/Count3Modes.lf @@ -34,7 +34,7 @@ main reactor { timer stepper(0, 250 msec) counter = new CounterCycle() - state expected_value(1) + state expected_value = 1 reaction(stepper) -> counter.next {= counter.next.set(True) =} # Trigger diff --git a/test/Python/src/modal_models/ModalAfter.lf b/test/Python/src/modal_models/ModalAfter.lf index c86002c9fa..19c84f33d5 100644 --- a/test/Python/src/modal_models/ModalAfter.lf +++ b/test/Python/src/modal_models/ModalAfter.lf @@ -45,7 +45,7 @@ reactor Modal { } } -reactor Producer(mode_id(0)) { +reactor Producer(mode_id = 0) { output product timer t(0, 750 msec) @@ -56,7 +56,7 @@ reactor Producer(mode_id(0)) { =} } -reactor Consumer(mode_id(0)) { +reactor Consumer(mode_id = 0) { input product output report diff --git a/test/Python/src/modal_models/ModalCycleBreaker.lf b/test/Python/src/modal_models/ModalCycleBreaker.lf index baafdf8378..1ceb2eb5d0 100644 --- a/test/Python/src/modal_models/ModalCycleBreaker.lf +++ b/test/Python/src/modal_models/ModalCycleBreaker.lf @@ -39,11 +39,11 @@ reactor Modal { } } -reactor Counter(period(1 sec)) { +reactor Counter(period = 1 sec) { output value timer t(0, period) - state curval(0) + state curval = 0 reaction(t) -> value {= value.set(self.curval) diff --git a/test/Python/src/modal_models/ModalStateReset.lf b/test/Python/src/modal_models/ModalStateReset.lf index 9bd969b15c..11b7425b63 100644 --- a/test/Python/src/modal_models/ModalStateReset.lf +++ b/test/Python/src/modal_models/ModalStateReset.lf @@ -14,7 +14,7 @@ reactor Modal { output count1 output count2 - state counter0(0) + state counter0 = 0 reaction(next) -> count0 {= print(f"Counter0: {self.counter0}") @@ -23,7 +23,7 @@ reactor Modal { =} initial mode One { - state counter1(0) + state counter1 = 0 timer T1(0 msec, 250 msec) reaction(reset) {= self.counter1 = 0 =} @@ -41,7 +41,7 @@ reactor Modal { } mode Two { - state counter2(-2) + state counter2 = -2 timer T2(0 msec, 250 msec) reaction(reset) {= self.counter2 = -2 =} diff --git a/test/Python/src/modal_models/ModalStateResetAuto.lf b/test/Python/src/modal_models/ModalStateResetAuto.lf index be664676db..492e12259b 100644 --- a/test/Python/src/modal_models/ModalStateResetAuto.lf +++ b/test/Python/src/modal_models/ModalStateResetAuto.lf @@ -14,7 +14,7 @@ reactor Modal { output count1 output count2 - state counter0(0) + state counter0 = 0 reaction(next) -> count0 {= print(f"Counter0: {self.counter0}") @@ -23,7 +23,7 @@ reactor Modal { =} initial mode One { - state counter1(0) + state counter1 = 0 timer T1(0 msec, 250 msec) reaction(T1) -> count1 {= print(f"Counter1: {self.counter1}") @@ -39,7 +39,7 @@ reactor Modal { } mode Two { - reset state counter2(-2) + reset state counter2 = -2 timer T2(0 msec, 250 msec) reaction(T2) -> count2 {= print(f"Counter2: {self.counter2}") diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index 5654dd9b1e..3dd42f67ce 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -28,11 +28,11 @@ reactor Modal { } } -reactor Counter(period(1 sec)) { +reactor Counter(period = 1 sec) { output value timer t(0, period) - reset state curval(0) + reset state curval = 0 reaction(t) -> value {= value.set(self.curval) diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 80c4247972..86f5668357 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -31,11 +31,11 @@ reactor Modal { } } -reactor Counter(period(1 sec)) { +reactor Counter(period = 1 sec) { output value timer t(0, period) - reset state curval(0) + reset state curval = 0 reaction(t) -> value {= value.set(self.curval) diff --git a/test/Python/src/modal_models/util/TraceTesting.lf b/test/Python/src/modal_models/util/TraceTesting.lf index 1014ac3c8d..305ff31a5b 100644 --- a/test/Python/src/modal_models/util/TraceTesting.lf +++ b/test/Python/src/modal_models/util/TraceTesting.lf @@ -1,13 +1,13 @@ /** Utility reactor to record and test execution traces. */ target Python -reactor TraceTesting(events_size(0), trace({= [] =}), training(False)) { +reactor TraceTesting(events_size = 0, trace = {= [] =}, training = False) { input[events_size] events - state last_reaction_time(0) - state trace_idx(0) - state recorded_events({= [] =}) - state recorded_events_next(0) + state last_reaction_time = 0 + state trace_idx = 0 + state recorded_events = {= [] =} + state recorded_events_next = 0 reaction(startup) {= self.last_reaction_time = lf.time.logical() =} diff --git a/test/Python/src/multiport/BankIndexInitializer.lf b/test/Python/src/multiport/BankIndexInitializer.lf index 6754f31d97..52ef58bb1d 100644 --- a/test/Python/src/multiport/BankIndexInitializer.lf +++ b/test/Python/src/multiport/BankIndexInitializer.lf @@ -3,15 +3,15 @@ target Python preamble {= table = [4, 3, 2, 1] =} -reactor Source(bank_index(0), value(0)) { +reactor Source(bank_index = 0, value = 0) { output out reaction(startup) -> out {= out.set(self.value) =} } -reactor Sink(width(4)) { +reactor Sink(width = 4) { input[width] _in - state received(false) + state received = False reaction(_in) {= for (idx, port) in enumerate(_in): @@ -30,7 +30,7 @@ reactor Sink(width(4)) { =} } -main reactor(width(4)) { +main reactor(width = 4) { source = new[width] Source(value = {= table[bank_index] =}) sink = new Sink(width = width) source.out -> sink._in diff --git a/test/Python/src/multiport/BankReactionsInContainer.lf b/test/Python/src/multiport/BankReactionsInContainer.lf index 3a72418405..7316463c3d 100644 --- a/test/Python/src/multiport/BankReactionsInContainer.lf +++ b/test/Python/src/multiport/BankReactionsInContainer.lf @@ -5,10 +5,10 @@ target Python { timeout: 1 sec } -reactor R(bank_index(0)) { +reactor R(bank_index = 0) { output[2] out input[2] inp - state received(false) + state received = False reaction(startup) -> out {= for (i, p) in enumerate(out): @@ -37,7 +37,7 @@ reactor R(bank_index(0)) { main reactor { s = new[2] R() - state received(false) + state received = False reaction(startup) -> s.inp {= count = 0 diff --git a/test/Python/src/multiport/BankToBank.lf b/test/Python/src/multiport/BankToBank.lf index e94b7dd717..6e3ddc734d 100644 --- a/test/Python/src/multiport/BankToBank.lf +++ b/test/Python/src/multiport/BankToBank.lf @@ -4,10 +4,10 @@ target Python { fast: true } -reactor Source(bank_index(0)) { +reactor Source(bank_index = 0) { timer t(0, 200 msec) output out - state s(0) + state s = 0 reaction(t) -> out {= out.set(self.s) @@ -15,8 +15,8 @@ reactor Source(bank_index(0)) { =} } -reactor Destination(bank_index(0)) { - state s(0) +reactor Destination(bank_index = 0) { + state s = 0 input _in reaction(_in) {= @@ -35,7 +35,7 @@ reactor Destination(bank_index(0)) { =} } -main reactor BankToBank(width(4)) { +main reactor BankToBank(width = 4) { a = new[width] Source() b = new[width] Destination() a.out -> b._in diff --git a/test/Python/src/multiport/BankToBankMultiport.lf b/test/Python/src/multiport/BankToBankMultiport.lf index de2f05a55d..f335e53858 100644 --- a/test/Python/src/multiport/BankToBankMultiport.lf +++ b/test/Python/src/multiport/BankToBankMultiport.lf @@ -4,10 +4,10 @@ target Python { fast: true } -reactor Source(width(1)) { +reactor Source(width = 1) { timer t(0, 200 msec) output[width] out - state s(0) + state s = 0 reaction(t) -> out {= for port in out: @@ -16,8 +16,8 @@ reactor Source(width(1)) { =} } -reactor Destination(width(1)) { - state s(6) +reactor Destination(width = 1) { + state s = 6 input[width] _in reaction(_in) {= @@ -43,7 +43,7 @@ reactor Destination(width(1)) { =} } -main reactor BankToBankMultiport(bank_width(4)) { +main reactor BankToBankMultiport(bank_width = 4) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b._in diff --git a/test/Python/src/multiport/BankToBankMultiportAfter.lf b/test/Python/src/multiport/BankToBankMultiportAfter.lf index eb7f025772..9d6e946122 100644 --- a/test/Python/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Python/src/multiport/BankToBankMultiportAfter.lf @@ -6,7 +6,7 @@ target Python { import Source, Destination from "BankToBankMultiport.lf" -main reactor BankToBankMultiportAfter(bank_width(4)) { +main reactor BankToBankMultiportAfter(bank_width = 4) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b._in after 200 msec diff --git a/test/Python/src/multiport/BankToMultiport.lf b/test/Python/src/multiport/BankToMultiport.lf index 110295400d..769e0ea2fc 100644 --- a/test/Python/src/multiport/BankToMultiport.lf +++ b/test/Python/src/multiport/BankToMultiport.lf @@ -1,15 +1,15 @@ # Test bank of reactors to multiport input with id parameter in the bank. target Python -reactor Source(bank_index(0)) { +reactor Source(bank_index = 0) { output out reaction(startup) -> out {= out.set(self.bank_index) =} } -reactor Sink(width(4)) { +reactor Sink(width = 4) { input[width] _in - state received(false) + state received = False reaction(_in) {= for (idx, port) in enumerate(_in): @@ -28,7 +28,7 @@ reactor Sink(width(4)) { =} } -main reactor BankToMultiport(width(5)) { +main reactor BankToMultiport(width = 5) { source = new[width] Source() sink = new Sink(width = width) source.out -> sink._in diff --git a/test/Python/src/multiport/Broadcast.lf b/test/Python/src/multiport/Broadcast.lf index ebc4de3067..2e507d607f 100644 --- a/test/Python/src/multiport/Broadcast.lf +++ b/test/Python/src/multiport/Broadcast.lf @@ -3,15 +3,15 @@ target Python { fast: true } -reactor Source(value(42)) { +reactor Source(value = 42) { output out reaction(startup) -> out {= out.set(self.value) =} } -reactor Destination(bank_index(0), delay(0)) { +reactor Destination(bank_index = 0, delay = 0) { input _in - state received(false) + state received = False reaction(_in) {= print(f"Destination {self.bank_index} received {_in.value}.") diff --git a/test/Python/src/multiport/BroadcastMultipleAfter.lf b/test/Python/src/multiport/BroadcastMultipleAfter.lf index 7777406c38..9fc327e6fd 100644 --- a/test/Python/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Python/src/multiport/BroadcastMultipleAfter.lf @@ -5,9 +5,9 @@ target Python { import Source from "Broadcast.lf" -reactor Destination(bank_index(0), delay(0)) { +reactor Destination(bank_index = 0, delay = 0) { input _in - state received(false) + state received = False reaction(_in) {= print(f"Destination {self.bank_index} received {_in.value}.") diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 05dc165fa1..92d9363df5 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -5,7 +5,7 @@ target Python { fast: true } -reactor Source(check_override(0), bank_index(0)) { +reactor Source(check_override = 0, bank_index = 0) { output out reaction(startup) -> out {= @@ -15,7 +15,7 @@ reactor Source(check_override(0), bank_index(0)) { reactor Destination { input[3] _in - state received(0) + state received = 0 reaction(_in) {= for (idx, port) in enumerate(_in): diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index ac62f5829f..27ecb3c80b 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -7,7 +7,7 @@ target Python { import Destination from "MultiportFromBank.lf" -reactor Source(bank_index(0)) { +reactor Source(bank_index = 0) { output out reaction(startup) -> out {= out.set(self.bank_index) =} diff --git a/test/Python/src/multiport/MultiportFromHierarchy.lf b/test/Python/src/multiport/MultiportFromHierarchy.lf index dc7a9a2f68..4116587f01 100644 --- a/test/Python/src/multiport/MultiportFromHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromHierarchy.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[4] out - state s(0) + state s = 0 reaction(t) -> out {= for port in out: @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s(6) + state s = 6 input[4] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportFromReaction.lf b/test/Python/src/multiport/MultiportFromReaction.lf index f005711683..05b280b126 100644 --- a/test/Python/src/multiport/MultiportFromReaction.lf +++ b/test/Python/src/multiport/MultiportFromReaction.lf @@ -4,8 +4,8 @@ target Python { fast: true } -reactor Destination(width(1)) { - state s(6) +reactor Destination(width = 1) { + state s = 6 input[width] _in reaction(_in) {= @@ -31,7 +31,7 @@ reactor Destination(width(1)) { main reactor MultiportFromReaction { timer t(0, 200 msec) - state s(0) + state s = 0 b = new Destination(width = 4) reaction(t) -> b._in {= diff --git a/test/Python/src/multiport/MultiportIn.lf b/test/Python/src/multiport/MultiportIn.lf index 146dfa6727..35bdee7341 100644 --- a/test/Python/src/multiport/MultiportIn.lf +++ b/test/Python/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output out - state s(0) + state s = 0 reaction(t) -> out {= out.set(self.s) @@ -24,7 +24,7 @@ reactor Computation { } reactor Destination { - state s(0) + state s = 0 input[4] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportInParameterized.lf b/test/Python/src/multiport/MultiportInParameterized.lf index c4906d7a9c..28b15808e3 100644 --- a/test/Python/src/multiport/MultiportInParameterized.lf +++ b/test/Python/src/multiport/MultiportInParameterized.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output out - state s(0) + state s = 0 reaction(t) -> out {= out.set(self.s) @@ -23,8 +23,8 @@ reactor Computation { reaction(_in) -> out {= out.set(_in.value) =} } -reactor Destination(width(1)) { - state s(0) +reactor Destination(width = 1) { + state s = 0 input[width] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportMutableInput.lf b/test/Python/src/multiport/MultiportMutableInput.lf index d17e1cd8bf..f931900ef7 100644 --- a/test/Python/src/multiport/MultiportMutableInput.lf +++ b/test/Python/src/multiport/MultiportMutableInput.lf @@ -12,7 +12,7 @@ reactor Source { =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input[2] _in reaction(_in) {= @@ -26,7 +26,7 @@ reactor Print(scale(1)) { # The scale parameter is just for testing. =} } -reactor Scale(scale(2)) { +reactor Scale(scale = 2) { mutable input[2] _in output[2] out diff --git a/test/Python/src/multiport/MultiportMutableInputArray.lf b/test/Python/src/multiport/MultiportMutableInputArray.lf index 76fa5203a6..9efa3eeebf 100644 --- a/test/Python/src/multiport/MultiportMutableInputArray.lf +++ b/test/Python/src/multiport/MultiportMutableInputArray.lf @@ -13,7 +13,7 @@ reactor Source { =} } -reactor Print(scale(1)) { # The scale parameter is just for testing. +reactor Print(scale = 1) { # The scale parameter is just for testing. input[2] _in reaction(_in) {= @@ -25,7 +25,7 @@ reactor Print(scale(1)) { # The scale parameter is just for testing. =} } -reactor Scale(scale(2)) { +reactor Scale(scale = 2) { mutable input[2] _in output[2] out diff --git a/test/Python/src/multiport/MultiportOut.lf b/test/Python/src/multiport/MultiportOut.lf index 0a48f355e6..3d29c5188a 100644 --- a/test/Python/src/multiport/MultiportOut.lf +++ b/test/Python/src/multiport/MultiportOut.lf @@ -7,7 +7,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[4] out - state s(0) + state s = 0 reaction(t) -> out {= for port in out: @@ -25,7 +25,7 @@ reactor Computation { } reactor Destination { - state s(0) + state s = 0 input[4] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToBank.lf b/test/Python/src/multiport/MultiportToBank.lf index 61b1cabc8b..12d68d6662 100644 --- a/test/Python/src/multiport/MultiportToBank.lf +++ b/test/Python/src/multiport/MultiportToBank.lf @@ -13,9 +13,9 @@ reactor Source { =} } -reactor Destination(bank_index(0)) { +reactor Destination(bank_index = 0) { input _in - state received(0) + state received = 0 reaction(_in) {= print("Destination " + str(self.bank_index) + " received " + str(_in.value)) diff --git a/test/Python/src/multiport/MultiportToBankAfter.lf b/test/Python/src/multiport/MultiportToBankAfter.lf index aeb8a9d0d7..85fc91e513 100644 --- a/test/Python/src/multiport/MultiportToBankAfter.lf +++ b/test/Python/src/multiport/MultiportToBankAfter.lf @@ -7,9 +7,9 @@ target Python { import Source from "MultiportToBank.lf" -reactor Destination(bank_index(0)) { +reactor Destination(bank_index = 0) { input _in - state received(false) + state received = False reaction(_in) {= print("Destination {:d} received {:d}.".format(self.bank_index, _in.value)) diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index b36ae9b40b..f70fa8ad92 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -7,9 +7,9 @@ target Python { import Source from "MultiportToBank.lf" -reactor Destination(bank_index(0)) { +reactor Destination(bank_index = 0) { input _in - state received(false) + state received = False reaction(_in) {= print("Destination {:d} received {:d}.\n".format(self.bank_index, _in.value)) diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index 6dbf76775f..2a9e25a5e6 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -9,7 +9,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[4] out - state s(0) + state s = 0 reaction(t) -> out {= for port in out: @@ -18,8 +18,8 @@ reactor Source { =} } -reactor Destination(width(4)) { - state s(6) +reactor Destination(width = 4) { + state s = 6 input[width] _in reaction(_in) {= @@ -42,7 +42,7 @@ reactor Destination(width(4)) { =} } -reactor Container(width(4)) { +reactor Container(width = 4) { input[width] _in dst = new Destination() _in -> dst._in diff --git a/test/Python/src/multiport/MultiportToMultiport.lf b/test/Python/src/multiport/MultiportToMultiport.lf index 6fd4bbb231..b16e832e7e 100644 --- a/test/Python/src/multiport/MultiportToMultiport.lf +++ b/test/Python/src/multiport/MultiportToMultiport.lf @@ -6,10 +6,10 @@ target Python { import Destination from "MultiportToHierarchy.lf" -reactor Source(width(1)) { +reactor Source(width = 1) { timer t(0, 200 msec) output[width] out - state s(0) + state s = 0 reaction(t) -> out {= for i in range(len(out)): diff --git a/test/Python/src/multiport/MultiportToMultiport2.lf b/test/Python/src/multiport/MultiportToMultiport2.lf index 5b06d8d7d8..cb6da65f35 100644 --- a/test/Python/src/multiport/MultiportToMultiport2.lf +++ b/test/Python/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ # Test multiport to multiport connections. See also MultiportToMultiport. target Python -reactor Source(width(2)) { +reactor Source(width = 2) { output[width] out reaction(startup) -> out {= @@ -10,7 +10,7 @@ reactor Source(width(2)) { =} } -reactor Destination(width(2)) { +reactor Destination(width = 2) { input[width] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToMultiport2After.lf b/test/Python/src/multiport/MultiportToMultiport2After.lf index d8d85805ce..0e7ee9aef2 100644 --- a/test/Python/src/multiport/MultiportToMultiport2After.lf +++ b/test/Python/src/multiport/MultiportToMultiport2After.lf @@ -3,7 +3,7 @@ target Python import Source from "MultiportToMultiport2.lf" -reactor Destination(width(2)) { +reactor Destination(width = 2) { input[width] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToMultiportArray.lf b/test/Python/src/multiport/MultiportToMultiportArray.lf index e22f3541b0..5eb043570d 100644 --- a/test/Python/src/multiport/MultiportToMultiportArray.lf +++ b/test/Python/src/multiport/MultiportToMultiportArray.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[2] out - state s(0) + state s = 0 reaction(t) -> out {= for port in out: @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s(15) + state s = 15 input[2] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToMultiportParameter.lf b/test/Python/src/multiport/MultiportToMultiportParameter.lf index 933abfd846..b47905bb6e 100644 --- a/test/Python/src/multiport/MultiportToMultiportParameter.lf +++ b/test/Python/src/multiport/MultiportToMultiportParameter.lf @@ -7,7 +7,7 @@ target Python { import Source from "MultiportToMultiport.lf" import Destination from "MultiportToHierarchy.lf" -main reactor MultiportToMultiportParameter(width(4)) { +main reactor MultiportToMultiportParameter(width = 4) { a = new Source(width = width) b = new Destination(width = width) a.out -> b._in diff --git a/test/Python/src/multiport/MultiportToPort.lf b/test/Python/src/multiport/MultiportToPort.lf index 52bb7b7c67..ebfbf81991 100644 --- a/test/Python/src/multiport/MultiportToPort.lf +++ b/test/Python/src/multiport/MultiportToPort.lf @@ -15,9 +15,9 @@ reactor Source { =} } -reactor Destination(expected(0)) { +reactor Destination(expected = 0) { input _in - state received(false) + state received = False reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/multiport/MultiportToReaction.lf b/test/Python/src/multiport/MultiportToReaction.lf index 6d03ba28ee..b45ee9ac9e 100644 --- a/test/Python/src/multiport/MultiportToReaction.lf +++ b/test/Python/src/multiport/MultiportToReaction.lf @@ -4,9 +4,9 @@ target Python { fast: true } -reactor Source(width(1)) { +reactor Source(width = 1) { timer t(0, 200 msec) - state s(0) + state s = 0 output[width] out reaction(t) -> out {= @@ -17,7 +17,7 @@ reactor Source(width(1)) { } main reactor { - state s(6) + state s = 6 b = new Source(width = 4) reaction(b.out) {= diff --git a/test/Python/src/multiport/NestedBanks.lf b/test/Python/src/multiport/NestedBanks.lf index 8e49b76aef..1e863043e6 100644 --- a/test/Python/src/multiport/NestedBanks.lf +++ b/test/Python/src/multiport/NestedBanks.lf @@ -13,13 +13,13 @@ main reactor { (a.x)+ -> c.z, d.u, e.t } -reactor A(bank_index(0)) { +reactor A(bank_index = 0) { output[4] x b = new[2] B(a_bank_index = bank_index) b.y -> x } -reactor B(a_bank_index(0), bank_index(0)) { +reactor B(a_bank_index = 0, bank_index = 0) { output[2] y reaction(startup) -> y {= @@ -29,7 +29,7 @@ reactor B(a_bank_index(0), bank_index(0)) { =} } -reactor C(bank_index(0)) { +reactor C(bank_index = 0) { input[2] z f = new F(c_bank_index = bank_index) g = new G(c_bank_index = bank_index) @@ -57,7 +57,7 @@ reactor E { =} } -reactor F(c_bank_index(0)) { +reactor F(c_bank_index = 0) { input w reaction(w) {= @@ -68,7 +68,7 @@ reactor F(c_bank_index(0)) { =} } -reactor G(c_bank_index(0)) { +reactor G(c_bank_index = 0) { input s reaction(s) {= diff --git a/test/Python/src/multiport/NestedInterleavedBanks.lf b/test/Python/src/multiport/NestedInterleavedBanks.lf index 5d615a3397..9be37badcd 100644 --- a/test/Python/src/multiport/NestedInterleavedBanks.lf +++ b/test/Python/src/multiport/NestedInterleavedBanks.lf @@ -4,7 +4,7 @@ */ target Python -reactor A(bank_index(0), outer_bank_index(0)) { +reactor A(bank_index = 0, outer_bank_index = 0) { output[2] p reaction(startup) -> p {= @@ -14,7 +14,7 @@ reactor A(bank_index(0), outer_bank_index(0)) { =} } -reactor B(bank_index(0)) { +reactor B(bank_index = 0) { output[4] q a = new[2] A(outer_bank_index = bank_index) interleaved (a.p) -> q diff --git a/test/Python/src/multiport/ReactionsToNested.lf b/test/Python/src/multiport/ReactionsToNested.lf index 9870cb1b68..2c207dffb0 100644 --- a/test/Python/src/multiport/ReactionsToNested.lf +++ b/test/Python/src/multiport/ReactionsToNested.lf @@ -4,9 +4,9 @@ target Python { timeout: 1 sec } -reactor T(expected(0)) { +reactor T(expected = 0) { input z - state received(false) + state received = False reaction(z) {= print(f"T received {z.value}.") diff --git a/test/Python/src/target/AfterNoTypes.lf b/test/Python/src/target/AfterNoTypes.lf index 3ff3983da5..44aaa89c73 100644 --- a/test/Python/src/target/AfterNoTypes.lf +++ b/test/Python/src/target/AfterNoTypes.lf @@ -13,8 +13,8 @@ reactor Foo { } reactor Print { - state expected_time(10 msec) - state received(0) + state expected_time = 10 msec + state received = 0 input x reaction(x) {= diff --git a/test/Rust/src/ActionDelay.lf b/test/Rust/src/ActionDelay.lf index 8612eabbb2..75c7ab909f 100644 --- a/test/Rust/src/ActionDelay.lf +++ b/test/Rust/src/ActionDelay.lf @@ -4,7 +4,7 @@ target Rust main reactor ActionDelay { logical action act0 logical action act1(100 msec) - state count: u32(0) + state count: u32 = 0 reaction(startup) -> act0, act1 {= ctx.schedule(act0, after!(100 ms)); diff --git a/test/Rust/src/ActionImplicitDelay.lf b/test/Rust/src/ActionImplicitDelay.lf index 1278472528..9a3a900d93 100644 --- a/test/Rust/src/ActionImplicitDelay.lf +++ b/test/Rust/src/ActionImplicitDelay.lf @@ -3,7 +3,7 @@ target Rust main reactor ActionImplicitDelay { logical action act(40 msec) - state count: u64(1) + state count: u64 = 1 reaction(startup) -> act {= ctx.schedule(act, Asap); =} diff --git a/test/Rust/src/ActionIsPresent.lf b/test/Rust/src/ActionIsPresent.lf index efe6158e43..3a1e556c5a 100644 --- a/test/Rust/src/ActionIsPresent.lf +++ b/test/Rust/src/ActionIsPresent.lf @@ -3,8 +3,8 @@ target Rust main reactor ActionIsPresent { logical action a - state success: bool(false) - state tried: bool(false) + state success: bool = false + state tried: bool = false reaction(startup, a) -> a {= if !ctx.is_present(a) { diff --git a/test/Rust/src/ActionScheduleMicrostep.lf b/test/Rust/src/ActionScheduleMicrostep.lf index 5ded693d2c..53bf8781b9 100644 --- a/test/Rust/src/ActionScheduleMicrostep.lf +++ b/test/Rust/src/ActionScheduleMicrostep.lf @@ -3,7 +3,7 @@ target Rust main reactor ActionScheduleMicrostep { logical action act - state count: u32(1) + state count: u32 = 1 reaction(startup) -> act {= assert_tag_is!(ctx, T0); diff --git a/test/Rust/src/ActionValues.lf b/test/Rust/src/ActionValues.lf index 635516c3d0..007da1fb5a 100644 --- a/test/Rust/src/ActionValues.lf +++ b/test/Rust/src/ActionValues.lf @@ -2,8 +2,8 @@ target Rust main reactor ActionValues { - state r1done: bool(false) - state r2done: bool(false) + state r1done: bool = false + state r2done: bool = false logical action act(100 msec): i32 reaction(startup) -> act {= diff --git a/test/Rust/src/ActionValuesCleanup.lf b/test/Rust/src/ActionValuesCleanup.lf index 615bd68a90..f4bab7a2b5 100644 --- a/test/Rust/src/ActionValuesCleanup.lf +++ b/test/Rust/src/ActionValuesCleanup.lf @@ -20,7 +20,7 @@ main reactor ActionValuesCleanup { =} logical action act: FooDrop - state count: u32(0) + state count: u32 = 0 reaction(startup) -> act {= ctx.schedule_with_v(act, Some(FooDrop { }), Asap) diff --git a/test/Rust/src/CtorParamDefault.lf b/test/Rust/src/CtorParamDefault.lf index 2a4f4b8074..a7d2d868bc 100644 --- a/test/Rust/src/CtorParamDefault.lf +++ b/test/Rust/src/CtorParamDefault.lf @@ -1,7 +1,7 @@ target Rust -reactor Print(value: i32(42)) { - state v: i32(value) +reactor Print(value: i32 = 42) { + state v: i32 = value reaction(startup) {= assert_eq!(42, self.v); diff --git a/test/Rust/src/CtorParamMixed.lf b/test/Rust/src/CtorParamMixed.lf index cb8536fe0a..5de7a3dc4c 100644 --- a/test/Rust/src/CtorParamMixed.lf +++ b/test/Rust/src/CtorParamMixed.lf @@ -1,13 +1,13 @@ target Rust reactor Print( - value: i32(42), - name: String({= "xxx".into() =}), - other: bool(false) + value: i32 = 42, + name: String = {= "xxx".into() =}, + other: bool = false ) { - state value(value) - state name(name) - state other(other) + state value = value + state name = name + state other = other reaction(startup) {= assert_eq!(42, self.value); diff --git a/test/Rust/src/CtorParamSimple.lf b/test/Rust/src/CtorParamSimple.lf index 8594adde3d..bbf38c04a0 100644 --- a/test/Rust/src/CtorParamSimple.lf +++ b/test/Rust/src/CtorParamSimple.lf @@ -1,7 +1,7 @@ target Rust -reactor Print(value: i32(42)) { - state v: i32(value) +reactor Print(value: i32 = 42) { + state v: i32 = value reaction(startup) {= assert_eq!(self.v, 23); diff --git a/test/Rust/src/DependencyOnChildPort.lf b/test/Rust/src/DependencyOnChildPort.lf index e5c9336c11..ed8b6b2120 100644 --- a/test/Rust/src/DependencyOnChildPort.lf +++ b/test/Rust/src/DependencyOnChildPort.lf @@ -9,7 +9,7 @@ reactor Box { } main reactor { - state done: bool(false) + state done: bool = false box0 = new Box() box1 = new Box() diff --git a/test/Rust/src/DependencyUseOnLogicalAction.lf b/test/Rust/src/DependencyUseOnLogicalAction.lf index bf51944c8b..6278ec76f7 100644 --- a/test/Rust/src/DependencyUseOnLogicalAction.lf +++ b/test/Rust/src/DependencyUseOnLogicalAction.lf @@ -10,7 +10,7 @@ main reactor { timer t(0, 2 msec) - state tick: u32(0) + state tick: u32 = 0 reaction(startup) -> clock, a {= ctx.schedule(a, after!(3 ms)); // out of order on purpose diff --git a/test/Rust/src/FloatLiteral.lf b/test/Rust/src/FloatLiteral.lf index 645581c844..b1dd37ca5e 100644 --- a/test/Rust/src/FloatLiteral.lf +++ b/test/Rust/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target Rust // This test verifies that floating-point literals are handled correctly. main reactor { - state N: f64(6.0221409e+23) - state charge: f64(-1.6021766E-19) - state minus_epsilon: f64(-.01e0) - state expected: f64(.964853323188E5) + state N: f64 = 6.0221409e+23 + state charge: f64 = -1.6021766E-19 + state minus_epsilon: f64 = -.01e0 + state expected: f64 = .964853323188E5 reaction(startup) {= let F = - self.N * self.charge; diff --git a/test/Rust/src/MainReactorParam.lf b/test/Rust/src/MainReactorParam.lf index 36a78d7699..0c9f189548 100644 --- a/test/Rust/src/MainReactorParam.lf +++ b/test/Rust/src/MainReactorParam.lf @@ -1,8 +1,8 @@ target Rust -main reactor(one: u64(1152921504606846976), two: u64({= 1 << 60 =})) { - state one(one) - state two(two) +main reactor(one: u64 = 1152921504606846976, two: u64 = {= 1 << 60 =}) { + state one = one + state two = two reaction(startup) {= assert_eq!(self.one, self.two); =} } diff --git a/test/Rust/src/MovingAverage.lf b/test/Rust/src/MovingAverage.lf index 228c69bd17..3dcbb69c98 100644 --- a/test/Rust/src/MovingAverage.lf +++ b/test/Rust/src/MovingAverage.lf @@ -7,7 +7,7 @@ target Rust { reactor Source { output out: f64 - state count: u32(0) + state count: u32 = 0 timer clock(0, 10 msec) reaction(clock) -> out {= @@ -17,9 +17,8 @@ reactor Source { } reactor MovingAverageImpl { - // fixme inaccessible ({=[0.0 ; 4]=}); - state delay_line: f64[4](0.0, 0.0, 0.0, 0.0) - state index: usize(0) + state delay_line: {= [f64 ; 4] =} = {= [ 0.0 ; 4 ] =} + state index: usize = 0 input in_: f64 output out: f64 @@ -39,7 +38,7 @@ reactor MovingAverageImpl { reactor Print { input in_: f64 - state count: usize(0) + state count: usize = 0 preamble {= const EXPECTED: [ f64 ; 6 ] = [0.0, 0.25, 0.75, 1.5, 2.5, 3.5]; diff --git a/test/Rust/src/NativeListsAndTimes.lf b/test/Rust/src/NativeListsAndTimes.lf index 3e378c2e43..79fd56e004 100644 --- a/test/Rust/src/NativeListsAndTimes.lf +++ b/test/Rust/src/NativeListsAndTimes.lf @@ -2,18 +2,18 @@ target Rust // This test passes if it is successfully compiled into valid target code. reactor Foo( - x: i32(0), - y: time(0), // Units are missing but not required - z(1 msec), // Type is missing but not required + x: i32 = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required p: i32[](1, 2, 3, 4), // List of integers - p2: i32[]({= vec![1] =}), // List of integers with single element + p2: i32[] = {= vec![1] =}, // List of integers with single element // todo // p2: i32[](1), // List of integers with single element p3: // i32[](), // Empty list of integers List of time values q: Vec(1 msec, 2 msec, 3 msec), g: time[](1 msec, 2 msec) // List of time values ) { - state s: time(y) // Reference to explicitly typed time parameter - state t: time(z) // Reference to implicitly typed time parameter + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter state v: bool // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required @@ -29,7 +29,7 @@ reactor Foo( */ // state baz(p); // Implicit type i32[] fixme this interplays badly with // syntax for array init Implicit type time - state period(z) + state period = z state times: Vec>(q, g) // a list of lists /** diff --git a/test/Rust/src/PortConnectionInSelfInChild.lf b/test/Rust/src/PortConnectionInSelfInChild.lf index c72b4edae0..7fd66783f1 100644 --- a/test/Rust/src/PortConnectionInSelfInChild.lf +++ b/test/Rust/src/PortConnectionInSelfInChild.lf @@ -3,7 +3,7 @@ target Rust reactor Child { input inp: i32 - state done: bool(false) + state done: bool = false reaction(inp) {= assert_eq!(ctx.get(inp), Some(76600)); diff --git a/test/Rust/src/PortConnectionInSelfOutSelf.lf b/test/Rust/src/PortConnectionInSelfOutSelf.lf index 6d012b3d62..2e33b0e498 100644 --- a/test/Rust/src/PortConnectionInSelfOutSelf.lf +++ b/test/Rust/src/PortConnectionInSelfOutSelf.lf @@ -18,7 +18,7 @@ reactor TestCase { reactor Sink { input inp: i32 - state done: bool(false) + state done: bool = false reaction(inp) {= assert_eq!(ctx.get(inp), Some(76600)); diff --git a/test/Rust/src/PortConnectionOutChildOutSelf.lf b/test/Rust/src/PortConnectionOutChildOutSelf.lf index 54adbb56eb..4d58153d97 100644 --- a/test/Rust/src/PortConnectionOutChildOutSelf.lf +++ b/test/Rust/src/PortConnectionOutChildOutSelf.lf @@ -19,7 +19,7 @@ reactor Parent { reactor Sink { input inp: i32 - state done: bool(false) + state done: bool = false reaction(inp) {= assert_eq!(ctx.get(inp), Some(76600)); @@ -33,7 +33,7 @@ reactor Sink { main reactor { parent = new Parent() - state done: bool(false) + state done: bool = false reaction(parent.out) {= assert_eq!(ctx.get(parent__out), Some(76600)); diff --git a/test/Rust/src/PortRefCleanup.lf b/test/Rust/src/PortRefCleanup.lf index 65a5b415cf..30573ceee9 100644 --- a/test/Rust/src/PortRefCleanup.lf +++ b/test/Rust/src/PortRefCleanup.lf @@ -14,8 +14,8 @@ main reactor { timer t1(0) timer t2(15 msec) - state reaction_num: u32(0) - state done: bool(false) + state reaction_num: u32 = 0 + state done: bool = false reaction(t1) -> boxr.inp {= ctx.set(boxr__inp, 150); diff --git a/test/Rust/src/PortValueCleanup.lf b/test/Rust/src/PortValueCleanup.lf index be837c2908..9a11372cfb 100644 --- a/test/Rust/src/PortValueCleanup.lf +++ b/test/Rust/src/PortValueCleanup.lf @@ -11,8 +11,8 @@ reactor Sink { timer t2(15 msec) input in: u32 - state reaction_num: u32(0) - state done: bool(false) + state reaction_num: u32 = 0 + state done: bool = false reaction(in, t2) {= if self.reaction_num == 0 { diff --git a/test/Rust/src/ReservedKeywords.lf b/test/Rust/src/ReservedKeywords.lf index f1facfe8ea..5d30ba63a4 100644 --- a/test/Rust/src/ReservedKeywords.lf +++ b/test/Rust/src/ReservedKeywords.lf @@ -8,14 +8,14 @@ reactor box { in -> struct - state foo: bool(true) // not escaped + state foo: bool = true // not escaped reaction(in) {= ctx.get(r#in); =} } -main reactor ReservedKeywords(struct: u32(0)) { +main reactor ReservedKeywords(struct: u32 = 0) { box = new box() timer t1(0) diff --git a/test/Rust/src/StateInitializerVisibility.lf b/test/Rust/src/StateInitializerVisibility.lf index cef728ccfa..d192f0ca98 100644 --- a/test/Rust/src/StateInitializerVisibility.lf +++ b/test/Rust/src/StateInitializerVisibility.lf @@ -3,8 +3,8 @@ target Rust main reactor { - state foo: u32(123) - state x: u32({= *&foo =}) + state foo: u32 = 123 + state x: u32 = {= *&foo =} reaction(startup) {= assert_eq!(self.x, self.foo); diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index d2f380f634..c43f8c30ff 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -13,13 +13,13 @@ target Rust { * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after: u32(10), break_interval: time(400 msec)) { +reactor Sender(take_a_break_after: u32 = 10, break_interval: time = 400 msec) { output out: u32 logical action act - state sent_messages: u32(0) + state sent_messages: u32 = 0 - state take_a_break_after(take_a_break_after) - state break_interval(break_interval) + state take_a_break_after = take_a_break_after + state break_interval = break_interval reaction(startup, act) -> act, out {= // Send a message on out @@ -40,7 +40,7 @@ reactor Sender(take_a_break_after: u32(10), break_interval: time(400 msec)) { reactor Consumer { input in_: u32 - state reaction_invoked_correctly: bool(false) + state reaction_invoked_correctly: bool = false reaction(in_) {= let current_tag = ctx.get_tag(); diff --git a/test/Rust/src/StopIdempotence.lf b/test/Rust/src/StopIdempotence.lf index ce9d17514f..1f79347758 100644 --- a/test/Rust/src/StopIdempotence.lf +++ b/test/Rust/src/StopIdempotence.lf @@ -4,7 +4,7 @@ target Rust { } main reactor StopIdempotence { - state count: u32(0) + state count: u32 = 0 reaction(startup) {= ctx.request_stop(Asap); // requested for (T0, 1) diff --git a/test/Rust/src/StopTimeoutExact.lf b/test/Rust/src/StopTimeoutExact.lf index 37e9616fb7..2b9eb85cda 100644 --- a/test/Rust/src/StopTimeoutExact.lf +++ b/test/Rust/src/StopTimeoutExact.lf @@ -9,7 +9,7 @@ target Rust { main reactor StopTimeoutExact { timer t(0, 10 msec) // the fifth triggering will coincide with the timeout - state reacted_on_shutdown: bool(false) + state reacted_on_shutdown: bool = false reaction(t) {= if ctx.get_tag() == tag!(T0 + 50 ms) { diff --git a/test/Rust/src/StructAsState.lf b/test/Rust/src/StructAsState.lf index 955affcc8b..9b35e7a3fb 100644 --- a/test/Rust/src/StructAsState.lf +++ b/test/Rust/src/StructAsState.lf @@ -15,7 +15,7 @@ main reactor StructAsState { * - state s: Hello(name: "Earth".into(), value: 42); * - state s: Hello { name: "Earth".into(), value: 42 }; */ - state s: Hello({= Hello { name: "Earth".into(), value: 42 } =}) + state s: Hello = {= Hello { name: "Earth".into(), value: 42 } =} reaction(startup) {= println!("State s.name=\"{}\", s.value={}.", self.s.name, self.s.value); diff --git a/test/Rust/src/StructAsType.lf b/test/Rust/src/StructAsType.lf index 76cee15f8e..0c8ed51456 100644 --- a/test/Rust/src/StructAsType.lf +++ b/test/Rust/src/StructAsType.lf @@ -18,9 +18,9 @@ reactor Source { =} } -reactor Print(expected: i32(42)) { // expected parameter is for testing. +reactor Print(expected: i32 = 42) { // expected parameter is for testing. input inp: {= super::source::Hello =} - state expected: i32(expected) + state expected: i32 = expected reaction(inp) {= ctx.use_ref_opt(inp, |hello| { diff --git a/test/Rust/src/TimeState.lf b/test/Rust/src/TimeState.lf index bbd80f730f..efffb00c2f 100644 --- a/test/Rust/src/TimeState.lf +++ b/test/Rust/src/TimeState.lf @@ -1,7 +1,7 @@ target Rust reactor Foo { - state baz: time(500 msec) + state baz: time = 500 msec reaction(startup) {= assert_eq!(500, self.baz.as_millis()); =} } diff --git a/test/Rust/src/TimerDefaults.lf b/test/Rust/src/TimerDefaults.lf index 3de189b62b..bbc920bf4a 100644 --- a/test/Rust/src/TimerDefaults.lf +++ b/test/Rust/src/TimerDefaults.lf @@ -1,7 +1,7 @@ target Rust main reactor TimerDefaults { - state i: i32(0) + state i: i32 = 0 timer t reaction(t) {= diff --git a/test/Rust/src/TimerIsPresent.lf b/test/Rust/src/TimerIsPresent.lf index 84327c06a6..1e87c11f51 100644 --- a/test/Rust/src/TimerIsPresent.lf +++ b/test/Rust/src/TimerIsPresent.lf @@ -8,8 +8,8 @@ main reactor { timer b(1 msec, 5 msec) timer c(1 msec) - state success: bool(false) - state tick: u32(0) + state success: bool = false + state tick: u32 = 0 reaction(startup, a, b, c) {= match self.tick { diff --git a/test/Rust/src/TimerPeriodic.lf b/test/Rust/src/TimerPeriodic.lf index fc62900e7c..c6dce10a73 100644 --- a/test/Rust/src/TimerPeriodic.lf +++ b/test/Rust/src/TimerPeriodic.lf @@ -3,7 +3,7 @@ target Rust { } main reactor TimerPeriodic { - state i: i32(0) + state i: i32 = 0 timer t2(0, 3 msec) reaction(t2) {= diff --git a/test/Rust/src/Timers.lf b/test/Rust/src/Timers.lf index 1043aad497..1ef5fc0ae5 100644 --- a/test/Rust/src/Timers.lf +++ b/test/Rust/src/Timers.lf @@ -6,7 +6,7 @@ target Rust { main reactor Timers { timer t(0, 1 sec) timer t2(0, 2 sec) - state counter: i32(0) + state counter: i32 = 0 reaction(t2) {= self.counter += 2; =} diff --git a/test/Rust/src/TypeVarLengthList.lf b/test/Rust/src/TypeVarLengthList.lf index 9dbf082f1f..37ff36df56 100644 --- a/test/Rust/src/TypeVarLengthList.lf +++ b/test/Rust/src/TypeVarLengthList.lf @@ -3,7 +3,7 @@ target Rust // this thing must compile needs to be modified when // https://github.com/lf-lang/lingua-franca/discussions/492 is implemented main reactor TypeVarLengthList { - state l0: i32[]({= Vec::new() =}) // generates l0: Vec::new() + state l0: i32[] = {= Vec::new() =} // generates l0: Vec::new() // generates l1: vec![1, 2] /** * - state l2: i32[](1); // generates l2: 1 // doesn't compile... diff --git a/test/Rust/src/concurrent/AsyncCallback.lf b/test/Rust/src/concurrent/AsyncCallback.lf index 053d8ae33d..dccbcf37c0 100644 --- a/test/Rust/src/concurrent/AsyncCallback.lf +++ b/test/Rust/src/concurrent/AsyncCallback.lf @@ -4,17 +4,17 @@ target Rust { cargo-features: ["cli"] } -main reactor AsyncCallback(period: time(10 msec)) { +main reactor AsyncCallback(period: time = 10 msec) { preamble {= use std::thread; =} timer t(0, period) state thread: Option> - state expected_time: time(period) - state period: time(period) - state toggle: bool(false) + state expected_time: time = period + state period: time = period + state toggle: bool = false physical action act - state i: u32(0) + state i: u32 = 0 reaction(t) -> act {= let act = act.clone(); diff --git a/test/Rust/src/generics/CtorParamGeneric.lf b/test/Rust/src/generics/CtorParamGeneric.lf index 93646e1746..1c8b1cab24 100644 --- a/test/Rust/src/generics/CtorParamGeneric.lf +++ b/test/Rust/src/generics/CtorParamGeneric.lf @@ -2,10 +2,10 @@ target Rust reactor Generic<{= T: Default + Eq + Sync + std::fmt::Debug =}>( - value: T({= Default::default() =}) + value: T = {= Default::default() =} ) { input in: T - state v: T(value) + state v: T = value reaction(in) {= ctx.use_ref_opt(r#in, |i| { diff --git a/test/Rust/src/generics/CtorParamGenericInst.lf b/test/Rust/src/generics/CtorParamGenericInst.lf index 63c38b2e16..86f696185c 100644 --- a/test/Rust/src/generics/CtorParamGenericInst.lf +++ b/test/Rust/src/generics/CtorParamGenericInst.lf @@ -5,10 +5,10 @@ target Rust reactor Generic2< {= T: Default + Eq + Sync + std::fmt::Debug + Send + 'static =} >( - value: T({= Default::default() =}) + value: T = {= Default::default() =} ) { input in: T - state v: T(value) + state v: T = value reaction(in) {= ctx.use_ref_opt(r#in, |i| { @@ -21,7 +21,7 @@ reactor Generic2< reactor Generic< {= T: Default + Eq + Sync + std::fmt::Debug + Copy + Send + 'static =} >( - value: T({= Default::default() =}) + value: T = {= Default::default() =} ) { input in: T diff --git a/test/Rust/src/generics/GenericReactor.lf b/test/Rust/src/generics/GenericReactor.lf index 0bf0675c02..3190524a5b 100644 --- a/test/Rust/src/generics/GenericReactor.lf +++ b/test/Rust/src/generics/GenericReactor.lf @@ -9,7 +9,7 @@ reactor Box<{= T: Sync =}> { } main reactor { - state done: bool(false) + state done: bool = false box0 = new Box() box1 = new Box() diff --git a/test/Rust/src/multiport/ConnectionToSelfBank.lf b/test/Rust/src/multiport/ConnectionToSelfBank.lf index cbdb4ffa5a..c39933de9b 100644 --- a/test/Rust/src/multiport/ConnectionToSelfBank.lf +++ b/test/Rust/src/multiport/ConnectionToSelfBank.lf @@ -1,10 +1,10 @@ target Rust -reactor Node(bank_index: usize(0), num_nodes: usize(4)) { +reactor Node(bank_index: usize = 0, num_nodes: usize = 4) { input[num_nodes] in: usize output out: usize - state bank_index(bank_index) - state num_nodes(num_nodes) + state bank_index = bank_index + state num_nodes = num_nodes reaction(startup) -> out {= ctx.set(out, self.bank_index); =} @@ -15,7 +15,7 @@ reactor Node(bank_index: usize(0), num_nodes: usize(4)) { =} } -main reactor(num_nodes: usize(4)) { +main reactor(num_nodes: usize = 4) { nodes = new[num_nodes] Node(num_nodes = num_nodes) (nodes.out)+ -> nodes.in } diff --git a/test/Rust/src/multiport/ConnectionToSelfMultiport.lf b/test/Rust/src/multiport/ConnectionToSelfMultiport.lf index b29efc3fdf..6042ad7af5 100644 --- a/test/Rust/src/multiport/ConnectionToSelfMultiport.lf +++ b/test/Rust/src/multiport/ConnectionToSelfMultiport.lf @@ -1,10 +1,10 @@ // test a connection from a multiport to another multiport of the same reactor target Rust -reactor Node(num_nodes: usize(4)) { +reactor Node(num_nodes: usize = 4) { input[num_nodes] in: usize output[num_nodes] out: usize - state num_nodes(num_nodes) + state num_nodes = num_nodes reaction(startup) -> out {= for (i, out) in out.into_iter().enumerate() { @@ -19,7 +19,7 @@ reactor Node(num_nodes: usize(4)) { =} } -main reactor(num_nodes: usize(4)) { +main reactor(num_nodes: usize = 4) { nodes = new Node(num_nodes = num_nodes) nodes.out -> nodes.in // todo: (nodes.out)+ -> nodes.in; } diff --git a/test/Rust/src/multiport/CycledLhs_SelfLoop.lf b/test/Rust/src/multiport/CycledLhs_SelfLoop.lf index 5248dcd11e..925fafce21 100644 --- a/test/Rust/src/multiport/CycledLhs_SelfLoop.lf +++ b/test/Rust/src/multiport/CycledLhs_SelfLoop.lf @@ -8,7 +8,7 @@ reactor Test { output out: u32 input[2] in: u32 logical action act: u32 - state last: u32(1) + state last: u32 = 1 reaction(startup) -> act {= ctx.schedule_with_v(act, Some(1), after!(1 us)); diff --git a/test/Rust/src/multiport/CycledLhs_Single.lf b/test/Rust/src/multiport/CycledLhs_Single.lf index 289bd85159..2fdd5c605c 100644 --- a/test/Rust/src/multiport/CycledLhs_Single.lf +++ b/test/Rust/src/multiport/CycledLhs_Single.lf @@ -8,7 +8,7 @@ reactor Test { output[2] out: u32 input[4] in: u32 logical action act: {= (u32, u32) =} - state last: u32(1) + state last: u32 = 1 reaction(startup) -> act {= ctx.schedule_with_v(act, Some((0, 1)), after!(1 us)); diff --git a/test/Rust/src/multiport/FullyConnected.lf b/test/Rust/src/multiport/FullyConnected.lf index 8dc87882ed..c4cd24f908 100644 --- a/test/Rust/src/multiport/FullyConnected.lf +++ b/test/Rust/src/multiport/FullyConnected.lf @@ -1,16 +1,16 @@ // test iterated connection on the left target Rust -reactor Left(bank_index: usize(0)) { +reactor Left(bank_index: usize = 0) { output out: usize - state bank_index(bank_index) + state bank_index = bank_index reaction(startup) -> out {= ctx.set(out, self.bank_index); =} } -reactor Right(bank_index: usize(0), num_nodes: usize(4)) { +reactor Right(bank_index: usize = 0, num_nodes: usize = 4) { input[num_nodes] in: usize - state num_nodes(num_nodes) + state num_nodes = num_nodes reaction(in) {= let count = r#in.iterate_set().count(); @@ -19,7 +19,7 @@ reactor Right(bank_index: usize(0), num_nodes: usize(4)) { =} } -main reactor(num_nodes: usize(4)) { +main reactor(num_nodes: usize = 4) { left = new[num_nodes] Left() right = new[num_nodes] Right(num_nodes = num_nodes) (left.out)+ -> right.in diff --git a/test/Rust/src/multiport/FullyConnectedAddressable.lf b/test/Rust/src/multiport/FullyConnectedAddressable.lf index 63aed7b840..2c8a056ed1 100644 --- a/test/Rust/src/multiport/FullyConnectedAddressable.lf +++ b/test/Rust/src/multiport/FullyConnectedAddressable.lf @@ -1,14 +1,14 @@ // In this pattern, each node can send direct messages to individual other nodes target Rust -reactor Node(bank_index: usize(0), num_nodes: usize(4)) { - state bank_index(bank_index) - state num_nodes(num_nodes) +reactor Node(bank_index: usize = 0, num_nodes: usize = 4) { + state bank_index = bank_index + state num_nodes = num_nodes input[num_nodes] inpt: usize output[num_nodes] out: usize - state received: bool(false) + state received: bool = false reaction(startup) -> out {= println!("Hello from node {}!", self.bank_index); @@ -43,7 +43,7 @@ reactor Node(bank_index: usize(0), num_nodes: usize(4)) { =} } -main reactor(num_nodes: usize(4)) { +main reactor(num_nodes: usize = 4) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.inpt) diff --git a/test/Rust/src/multiport/MultiportFromBank.lf b/test/Rust/src/multiport/MultiportFromBank.lf index f17a4ffa8d..6f0592ec36 100644 --- a/test/Rust/src/multiport/MultiportFromBank.lf +++ b/test/Rust/src/multiport/MultiportFromBank.lf @@ -3,14 +3,14 @@ target Rust { timeout: 2 sec } -reactor Source(bank_index: usize(0)) { +reactor Source(bank_index: usize = 0) { output out: usize - state bank_index(bank_index) + state bank_index = bank_index reaction(startup) -> out {= ctx.set(out, self.bank_index); =} } -reactor Destination(port_width: usize(2)) { +reactor Destination(port_width: usize = 2) { input[port_width] in: usize reaction(in) {= diff --git a/test/Rust/src/multiport/MultiportFromHierarchy.lf b/test/Rust/src/multiport/MultiportFromHierarchy.lf index 2745424e8c..d2af4253c4 100644 --- a/test/Rust/src/multiport/MultiportFromHierarchy.lf +++ b/test/Rust/src/multiport/MultiportFromHierarchy.lf @@ -7,7 +7,7 @@ target Rust { reactor Source { timer t(0, 200 msec) output[4] out: u32 - state s: u32(0) + state s: u32 = 0 reaction(t) -> out {= for chan in out { @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s: u32(6) + state s: u32 = 6 input[4] in: u32 reaction(in) {= diff --git a/test/Rust/src/multiport/MultiportIn.lf b/test/Rust/src/multiport/MultiportIn.lf index bbaeb65dda..4ebf1c56d5 100644 --- a/test/Rust/src/multiport/MultiportIn.lf +++ b/test/Rust/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target Rust { reactor Source { timer t(0, 200 msec) output out: u32 - state s: u32(0) + state s: u32 = 0 reaction(t) -> out {= ctx.set(out, self.s); @@ -26,7 +26,7 @@ reactor Computation { } reactor Destination { - state s: u32(0) + state s: u32 = 0 input[4] in: u32 reaction(in) {= diff --git a/test/Rust/src/multiport/MultiportOut.lf b/test/Rust/src/multiport/MultiportOut.lf index 010b3a9603..5e3b9afe77 100644 --- a/test/Rust/src/multiport/MultiportOut.lf +++ b/test/Rust/src/multiport/MultiportOut.lf @@ -6,7 +6,7 @@ target Rust { reactor Source { timer t(0, 200 msec) output[4] out: u32 - state s: u32(0) + state s: u32 = 0 reaction(t) -> out {= for i in 0..out.len() { @@ -30,7 +30,7 @@ reactor Computation { } reactor Destination { - state s: u32(0) + state s: u32 = 0 input[4] in: u32 reaction(in) {= diff --git a/test/Rust/src/multiport/MultiportToBank.lf b/test/Rust/src/multiport/MultiportToBank.lf index fcfdb8bf5d..445ab94d54 100644 --- a/test/Rust/src/multiport/MultiportToBank.lf +++ b/test/Rust/src/multiport/MultiportToBank.lf @@ -11,11 +11,11 @@ reactor Source { =} } -reactor Sink(bank_index: usize(0)) { +reactor Sink(bank_index: usize = 0) { input in: usize - state bank_index(bank_index) + state bank_index = bank_index - state asserts_done: u32(0) + state asserts_done: u32 = 0 reaction(in) {= assert_eq!(ctx.get(r#in), Some(self.bank_index)); diff --git a/test/Rust/src/multiport/MultiportToBankHierarchy.lf b/test/Rust/src/multiport/MultiportToBankHierarchy.lf index 6a7af77ebf..4d7dce445a 100644 --- a/test/Rust/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Rust/src/multiport/MultiportToBankHierarchy.lf @@ -13,11 +13,11 @@ reactor Source { =} } -reactor Destination(bank_index: usize(0)) { +reactor Destination(bank_index: usize = 0) { input in: usize - state bank_index(bank_index) - state asserts_done: u32(0) + state bank_index = bank_index + state asserts_done: u32 = 0 reaction(in) {= assert_eq!(ctx.get(r#in), Some(self.bank_index)); diff --git a/test/Rust/src/multiport/MultiportToMultiport2.lf b/test/Rust/src/multiport/MultiportToMultiport2.lf index 703c498ab3..a1e2db235d 100644 --- a/test/Rust/src/multiport/MultiportToMultiport2.lf +++ b/test/Rust/src/multiport/MultiportToMultiport2.lf @@ -2,7 +2,7 @@ // disconnected) target Rust -reactor Source(width: usize(2)) { +reactor Source(width: usize = 2) { output[width] out: usize reaction(startup) -> out {= @@ -12,7 +12,7 @@ reactor Source(width: usize(2)) { =} } -reactor Destination(width: usize(2)) { +reactor Destination(width: usize = 2) { input[width] in: usize reaction(in) {= diff --git a/test/Rust/src/multiport/ReadOutputOfContainedBank.lf b/test/Rust/src/multiport/ReadOutputOfContainedBank.lf index 80103366db..21bbdf6967 100644 --- a/test/Rust/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Rust/src/multiport/ReadOutputOfContainedBank.lf @@ -2,8 +2,8 @@ // permutations. target Rust -reactor Contained(bank_index: usize(0)) { - state bank_index(bank_index) +reactor Contained(bank_index: usize = 0) { + state bank_index = bank_index output out: usize @@ -12,7 +12,7 @@ reactor Contained(bank_index: usize(0)) { main reactor { c = new[4] Contained() - state count: usize(0) + state count: usize = 0 reaction(startup) c.out {= for (i, chan) in c__out.iter().enumerate() { diff --git a/test/Rust/src/multiport/WidthWithParameter.lf b/test/Rust/src/multiport/WidthWithParameter.lf index e32f67bec5..03e4617e87 100644 --- a/test/Rust/src/multiport/WidthWithParameter.lf +++ b/test/Rust/src/multiport/WidthWithParameter.lf @@ -1,6 +1,6 @@ target Rust -reactor Some(value: usize(30)) { +reactor Some(value: usize = 30) { output[value] finished: unit reaction(startup) -> finished {= diff --git a/test/Rust/src/multiport/WriteInputOfContainedBank.lf b/test/Rust/src/multiport/WriteInputOfContainedBank.lf index cab6e80e16..f339a3aea1 100644 --- a/test/Rust/src/multiport/WriteInputOfContainedBank.lf +++ b/test/Rust/src/multiport/WriteInputOfContainedBank.lf @@ -1,11 +1,11 @@ // Test writing inputs to a contained reactor bank target Rust -reactor Contained(bank_index: usize(0)) { - state bank_index(bank_index) +reactor Contained(bank_index: usize = 0) { + state bank_index = bank_index input inpt: usize - state count: usize(0) + state count: usize = 0 reaction(inpt) {= let result = ctx.get(inpt).unwrap(); diff --git a/test/Rust/src/target/CliFeature.lf b/test/Rust/src/target/CliFeature.lf index bfa8fb5746..2ef81e76bb 100644 --- a/test/Rust/src/target/CliFeature.lf +++ b/test/Rust/src/target/CliFeature.lf @@ -4,6 +4,6 @@ target Rust { } // todo allow test framework to pass CLI arguments. -main reactor CliFeature(size: u32(4), t: time(4 sec)) { +main reactor CliFeature(size: u32 = 4, t: time = 4 sec) { reaction(startup) {= println!("success"); =} } diff --git a/test/Rust/src/target/MainParameterCanBeExpression.lf b/test/Rust/src/target/MainParameterCanBeExpression.lf index 9e62cb29cb..99ab0d7389 100644 --- a/test/Rust/src/target/MainParameterCanBeExpression.lf +++ b/test/Rust/src/target/MainParameterCanBeExpression.lf @@ -3,8 +3,8 @@ target Rust { cargo-features: ["cli"] } -main reactor(size: u32({= 1u32 << 23 =})) { - state s(size) +main reactor(size: u32 = {= 1u32 << 23 =}) { + state s = size reaction(startup) {= assert_eq!(1u32 << 23, self.s); diff --git a/test/TypeScript/src/ActionDelay.lf b/test/TypeScript/src/ActionDelay.lf index 387e0331de..5882d18962 100644 --- a/test/TypeScript/src/ActionDelay.lf +++ b/test/TypeScript/src/ActionDelay.lf @@ -4,7 +4,7 @@ target TypeScript reactor GeneratedDelay { input y_in: number output y_out: number - state y_state: number(0) + state y_state: number = 0 logical action act(100 msec) reaction(y_in) -> act {= diff --git a/test/TypeScript/src/After.lf b/test/TypeScript/src/After.lf index 24aa2cdb29..8a872103e9 100644 --- a/test/TypeScript/src/After.lf +++ b/test/TypeScript/src/After.lf @@ -13,7 +13,7 @@ reactor Foo { } reactor Print { - state expected_time: time(10 msec) + state expected_time: time = 10 msec input x: number reaction(x) {= diff --git a/test/TypeScript/src/ArrayAsParameter.lf b/test/TypeScript/src/ArrayAsParameter.lf index 7f5e272d46..1fd7e47bb3 100644 --- a/test/TypeScript/src/ArrayAsParameter.lf +++ b/test/TypeScript/src/ArrayAsParameter.lf @@ -1,9 +1,9 @@ // Source has an array as a parameter, the elements of which it passes to Print. target TypeScript -reactor Source(sequence: {= Array =}({= [0, 1, 2] =})) { +reactor Source(sequence: {= Array =} = {= [0, 1, 2] =}) { output out: number - state count: number(0) + state count: number = 0 logical action next reaction(startup, next) -> out, next {= @@ -17,7 +17,7 @@ reactor Source(sequence: {= Array =}({= [0, 1, 2] =})) { reactor Print { input x: number - state count: number(1) + state count: number = 1 reaction(x) {= console.log("Received: " + x + "."); diff --git a/test/TypeScript/src/ArrayAsType.lf b/test/TypeScript/src/ArrayAsType.lf index 651dc37f29..9e30764307 100644 --- a/test/TypeScript/src/ArrayAsType.lf +++ b/test/TypeScript/src/ArrayAsType.lf @@ -15,7 +15,7 @@ reactor Source { =} } -reactor Print(scale: number(1)) { // The scale parameter is just for testing. +reactor Print(scale: number = 1) { // The scale parameter is just for testing. input x: {= Array =} reaction(x) {= diff --git a/test/TypeScript/src/ArrayPrint.lf b/test/TypeScript/src/ArrayPrint.lf index 62312c6a8e..93b6486506 100644 --- a/test/TypeScript/src/ArrayPrint.lf +++ b/test/TypeScript/src/ArrayPrint.lf @@ -15,7 +15,7 @@ reactor Source { =} } -reactor Print(scale: number(1)) { // The scale parameter is just for testing. +reactor Print(scale: number = 1) { // The scale parameter is just for testing. input x: {= Array =} reaction(x) {= diff --git a/test/TypeScript/src/ArrayScale.lf b/test/TypeScript/src/ArrayScale.lf index 0b54e4a4ef..107ef8cf2f 100644 --- a/test/TypeScript/src/ArrayScale.lf +++ b/test/TypeScript/src/ArrayScale.lf @@ -6,7 +6,7 @@ target TypeScript import Source, Print from "ArrayPrint.lf" -reactor Scale(scale: number(2)) { +reactor Scale(scale: number = 2) { mutable input x: {= Array =} output out: {= Array =} diff --git a/test/TypeScript/src/Composition.lf b/test/TypeScript/src/Composition.lf index 35c259d967..e74bbe9aa9 100644 --- a/test/TypeScript/src/Composition.lf +++ b/test/TypeScript/src/Composition.lf @@ -4,10 +4,10 @@ target TypeScript { timeout: 5 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: number timer t(1 sec, period) - state count: number(0) + state count: number = 0 reaction(t) -> y {= count++; @@ -17,7 +17,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: number - state count: number(0) + state count: number = 0 reaction(x) {= count++; diff --git a/test/TypeScript/src/CompositionAfter.lf b/test/TypeScript/src/CompositionAfter.lf index afce86ccfe..8840298c2d 100644 --- a/test/TypeScript/src/CompositionAfter.lf +++ b/test/TypeScript/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target TypeScript { timeout: 10 sec } -reactor Source(period: time(2 sec)) { +reactor Source(period: time = 2 sec) { output y: number timer t(1 sec, period) - state count: number(0) + state count: number = 0 reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time(2 sec)) { reactor Test { input x: number - state count: number(0) + state count: number = 0 reaction(x) {= count++; @@ -29,7 +29,7 @@ reactor Test { =} } -main reactor(delay: time(5 sec)) { +main reactor(delay: time = 5 sec) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/TypeScript/src/CountTest.lf b/test/TypeScript/src/CountTest.lf index 66737a6007..ba9e179b9b 100644 --- a/test/TypeScript/src/CountTest.lf +++ b/test/TypeScript/src/CountTest.lf @@ -6,7 +6,7 @@ import Count from "lib/Count.lf" reactor Test { input c: number - state i: number(0) + state i: number = 0 reaction(c) {= console.log("Received " + c); diff --git a/test/TypeScript/src/Deadline.lf b/test/TypeScript/src/Deadline.lf index 1d639e94f3..9f3086f1f5 100644 --- a/test/TypeScript/src/Deadline.lf +++ b/test/TypeScript/src/Deadline.lf @@ -5,10 +5,10 @@ target TypeScript { timeout: 4 sec } -reactor Source(period: time(2 sec)) { // run = "bin/Deadline -timeout 4 sec" +reactor Source(period: time = 2 sec) { // run = "bin/Deadline -timeout 4 sec" output y: number timer t(0, period) - state count: number(0) + state count: number = 0 reaction(t) -> y {= if (2 * Math.floor(count / 2) != count){ @@ -25,9 +25,9 @@ reactor Source(period: time(2 sec)) { // run = "bin/Deadline -timeout 4 sec" =} } -reactor Destination(timeout: time(1 sec)) { +reactor Destination(timeout: time = 1 sec) { input x: number - state count: number(0) + state count: number = 0 reaction(x) {= console.log("Destination receives: " + x); diff --git a/test/TypeScript/src/DeadlineHandledAbove.lf b/test/TypeScript/src/DeadlineHandledAbove.lf index 83ab279b23..ba47fd7aac 100644 --- a/test/TypeScript/src/DeadlineHandledAbove.lf +++ b/test/TypeScript/src/DeadlineHandledAbove.lf @@ -4,7 +4,7 @@ target TypeScript { timeout: 2 sec } -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: number output deadline_violation: boolean @@ -19,7 +19,7 @@ reactor Deadline(threshold: time(100 msec)) { } main reactor DeadlineHandledAbove { - state violation_detected: boolean(false) + state violation_detected: boolean = false d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/TypeScript/src/DelayInt.lf b/test/TypeScript/src/DelayInt.lf index d38e1103f5..224a7eab4a 100644 --- a/test/TypeScript/src/DelayInt.lf +++ b/test/TypeScript/src/DelayInt.lf @@ -2,7 +2,7 @@ // is a start at handling dynamic memory allocation for such actions. target TypeScript -reactor Delay(delay: time(100 msec)) { +reactor Delay(delay: time = 100 msec) { input x: number output out: number logical action a: number @@ -18,8 +18,8 @@ reactor Delay(delay: time(100 msec)) { reactor Test { input x: number - state start_time: time(0) - state received_value: boolean(false) + state start_time: time = 0 + state received_value: boolean = false reaction(startup) {= // Record the logical time at the start. diff --git a/test/TypeScript/src/DelayedAction.lf b/test/TypeScript/src/DelayedAction.lf index 6b6a155952..53ee33e963 100644 --- a/test/TypeScript/src/DelayedAction.lf +++ b/test/TypeScript/src/DelayedAction.lf @@ -5,7 +5,7 @@ target TypeScript { main reactor DelayedAction { timer t(0, 1 sec) logical action a - state count: number(0) + state count: number = 0 reaction(t) -> a {= actions.a.schedule(TimeValue.msec(100), null); =} diff --git a/test/TypeScript/src/DoubleInvocation.lf b/test/TypeScript/src/DoubleInvocation.lf index e2b61789e4..9557857ee2 100644 --- a/test/TypeScript/src/DoubleInvocation.lf +++ b/test/TypeScript/src/DoubleInvocation.lf @@ -13,7 +13,7 @@ target TypeScript { reactor Ball { output position: number output velocity: number - state p: number(200) + state p: number = 200 timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -26,7 +26,7 @@ reactor Ball { reactor Print { input velocity: number input position: number - state previous: number(-1) + state previous: number = -1 reaction(startup) {= console.log("####### Print startup"); diff --git a/test/TypeScript/src/DoubleReaction.lf b/test/TypeScript/src/DoubleReaction.lf index 26dccb8895..b172166613 100644 --- a/test/TypeScript/src/DoubleReaction.lf +++ b/test/TypeScript/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target TypeScript { fast: true } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: number timer t(offset, period) - state count: number(0) + state count: number = 0 reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: number input w: number - state s: number(2) + state s: number = 2 reaction(x, w) {= let sum = 0; diff --git a/test/TypeScript/src/DoubleTrigger.lf b/test/TypeScript/src/DoubleTrigger.lf index 34c1596325..fc8921622c 100644 --- a/test/TypeScript/src/DoubleTrigger.lf +++ b/test/TypeScript/src/DoubleTrigger.lf @@ -8,7 +8,7 @@ target TypeScript { main reactor DoubleTrigger { timer t1 timer t2 - state s: number(0) + state s: number = 0 reaction(t1, t2) {= s++; diff --git a/test/TypeScript/src/FloatLiteral.lf b/test/TypeScript/src/FloatLiteral.lf index 1d3e688deb..fb50d007d0 100644 --- a/test/TypeScript/src/FloatLiteral.lf +++ b/test/TypeScript/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target TypeScript // This test verifies that floating-point literals are handled correctly. main reactor { - state N: number(6.0221409e+23) - state charge: number(-1.6021766E-19) - state minus_epsilon: number(-.01e0) - state expected: number(.964853323188E5) + state N: number = 6.0221409e+23 + state charge: number = -1.6021766E-19 + state minus_epsilon: number = -.01e0 + state expected: number = .964853323188E5 reaction(startup) {= const F: number = - N * charge; diff --git a/test/TypeScript/src/Gain.lf b/test/TypeScript/src/Gain.lf index 056b15e2d3..23558da9cf 100644 --- a/test/TypeScript/src/Gain.lf +++ b/test/TypeScript/src/Gain.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target TypeScript -reactor Scale(scale: number(2)) { +reactor Scale(scale: number = 2) { input x: number output y: number @@ -10,7 +10,7 @@ reactor Scale(scale: number(2)) { reactor Test { input x: number - state received_value: boolean(false) + state received_value: boolean = false reaction(x) {= console.log("Received " + x + "."); diff --git a/test/TypeScript/src/Hello.lf b/test/TypeScript/src/Hello.lf index d762535149..c2806f83b8 100644 --- a/test/TypeScript/src/Hello.lf +++ b/test/TypeScript/src/Hello.lf @@ -8,9 +8,9 @@ target TypeScript { fast: true } -reactor Reschedule(period: time(2 sec), message: string("Hello TypeScript")) { - state count: number(0) - state previous_time: time(0) +reactor Reschedule(period: time = 2 sec, message: string = "Hello TypeScript") { + state count: number = 0 + state previous_time: time = 0 timer t(1 sec, period) logical action a @@ -38,8 +38,8 @@ reactor Reschedule(period: time(2 sec), message: string("Hello TypeScript")) { } reactor Inside( - period: time(1 sec), - message: string("Composite default message.") + period: time = 1 sec, + message: string = "Composite default message." ) { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/TypeScript/src/Hierarchy2.lf b/test/TypeScript/src/Hierarchy2.lf index bd469242f7..da2db6308f 100644 --- a/test/TypeScript/src/Hierarchy2.lf +++ b/test/TypeScript/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out: number timer t(0, 1 sec) - state i: number(0) + state i: number = 0 reaction(t) -> out {= i++; @@ -37,7 +37,7 @@ reactor Add { reactor Print { input x: number - state expected: number(2) + state expected: number = 2 reaction(x) {= x = x as number; diff --git a/test/TypeScript/src/MovingAverage.lf b/test/TypeScript/src/MovingAverage.lf index b7b11dc7fd..19e767e3e2 100644 --- a/test/TypeScript/src/MovingAverage.lf +++ b/test/TypeScript/src/MovingAverage.lf @@ -8,7 +8,7 @@ target TypeScript { reactor Source { output out: number - state count: number(0) + state count: number = 0 timer clock(0, 200 msec) reaction(clock) -> out {= @@ -18,8 +18,8 @@ reactor Source { } reactor MovingAverageImpl { - state delay_line: {= Array =}({= [0.0, 0.0, 0.0] =}) - state index: number(0) + state delay_line: {= Array =} = {= [0.0, 0.0, 0.0] =} + state index: number = 0 input x: number output out: number @@ -45,7 +45,7 @@ reactor MovingAverageImpl { reactor Print { input x: number - state count: number(0) + state count: number = 0 reaction(x) {= x = x as number; diff --git a/test/TypeScript/src/NativeListsAndTimes.lf b/test/TypeScript/src/NativeListsAndTimes.lf index 4a3751bd09..ad22d67d02 100644 --- a/test/TypeScript/src/NativeListsAndTimes.lf +++ b/test/TypeScript/src/NativeListsAndTimes.lf @@ -2,22 +2,22 @@ target TypeScript // This test passes if it is successfully compiled into valid target code. main reactor( - x: number(0), - y: time(0), // Units are missing but not required - z(1 msec), // Type is missing but not required + x: number = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required p: number[](1, 2, 3, 4), // List of integers q: TimeValue[](1 msec, 2 msec, 3 msec), // list of time values g: time[](1 msec, 2 msec) // List of time values ) { - state s: time(y) // Reference to explicitly typed time parameter - state t: time(z) // Reference to implicitly typed time parameter + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter state v: boolean // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required timer tock(1 sec) // Implicit type time timer toe(z) // Implicit type time - state baz(p) // Implicit type int[] - state period(z) // Implicit type time + state baz = p // Implicit type int[] + state period = z // Implicit type time reaction(tick) {= // Target code diff --git a/test/TypeScript/src/ParameterizedState.lf b/test/TypeScript/src/ParameterizedState.lf index d2ea34da12..1484812489 100644 --- a/test/TypeScript/src/ParameterizedState.lf +++ b/test/TypeScript/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target TypeScript -reactor Foo(bar: number(42)) { - state baz(bar) +reactor Foo(bar: number = 42) { + state baz = bar reaction(startup) {= console.log("Baz: " + baz); =} } diff --git a/test/TypeScript/src/PeriodicDesugared.lf b/test/TypeScript/src/PeriodicDesugared.lf index aaeac0e7d9..b99317e07a 100644 --- a/test/TypeScript/src/PeriodicDesugared.lf +++ b/test/TypeScript/src/PeriodicDesugared.lf @@ -1,9 +1,9 @@ target TypeScript -main reactor(offset: time(0), period: time(500 msec)) { +main reactor(offset: time = 0, period: time = 500 msec) { logical action init(offset) logical action recur(period) - state count: number(0) + state count: number = 0 reaction(startup) -> init, recur {= if (offset.isZero()) { diff --git a/test/TypeScript/src/ReadOutputOfContainedReactor.lf b/test/TypeScript/src/ReadOutputOfContainedReactor.lf index af1c4ed0e0..01b725e181 100644 --- a/test/TypeScript/src/ReadOutputOfContainedReactor.lf +++ b/test/TypeScript/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count: number(0) + state count: number = 0 reaction(startup) c.out {= console.log("Startup reaction reading output of contained reactor: " + c.out); diff --git a/test/TypeScript/src/ScheduleLogicalAction.lf b/test/TypeScript/src/ScheduleLogicalAction.lf index 65fae1a237..84e8fbe1cb 100644 --- a/test/TypeScript/src/ScheduleLogicalAction.lf +++ b/test/TypeScript/src/ScheduleLogicalAction.lf @@ -21,7 +21,7 @@ reactor foo { } reactor print { - state expected_time: time(0) + state expected_time: time = 0 input x: number reaction(x) {= diff --git a/test/TypeScript/src/SendingInside.lf b/test/TypeScript/src/SendingInside.lf index 720ce71e64..ca4b6489b3 100644 --- a/test/TypeScript/src/SendingInside.lf +++ b/test/TypeScript/src/SendingInside.lf @@ -7,7 +7,7 @@ target TypeScript { reactor Printer { input x: number - state count: number(1) + state count: number = 1 reaction(x) {= console.log("Inside reactor received: " + x); @@ -19,7 +19,7 @@ reactor Printer { } main reactor SendingInside { - state count: number(0) + state count: number = 0 timer t(0, 1 sec) p = new Printer() diff --git a/test/TypeScript/src/SendsPointerTest.lf b/test/TypeScript/src/SendsPointerTest.lf index 55eb6eca26..3c80613b52 100644 --- a/test/TypeScript/src/SendsPointerTest.lf +++ b/test/TypeScript/src/SendsPointerTest.lf @@ -12,7 +12,7 @@ reactor SendsPointer { } // expected parameter is for testing. -reactor Print(expected: {= {value: number} =}({= { value: 42 } =})) { +reactor Print(expected: {= {value: number} =} = {= { value: 42 } =}) { input x: {= {value: number} =} reaction(x) {= diff --git a/test/TypeScript/src/SimpleDeadline.lf b/test/TypeScript/src/SimpleDeadline.lf index 7327dab0a3..a518e04e5e 100644 --- a/test/TypeScript/src/SimpleDeadline.lf +++ b/test/TypeScript/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ // violation. target TypeScript -reactor Deadline(threshold: time(100 msec)) { +reactor Deadline(threshold: time = 100 msec) { input x: number output deadlineViolation: boolean diff --git a/test/TypeScript/src/SlowingClock.lf b/test/TypeScript/src/SlowingClock.lf index cc447bcd7c..772d2e2913 100644 --- a/test/TypeScript/src/SlowingClock.lf +++ b/test/TypeScript/src/SlowingClock.lf @@ -5,8 +5,8 @@ target TypeScript { main reactor SlowingClock { logical action a(100 msec) - state interval: time(100 msec) - state expected_time: time(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec reaction(startup) -> a {= actions.a.schedule(0, null); =} diff --git a/test/TypeScript/src/SlowingClockPhysical.lf b/test/TypeScript/src/SlowingClockPhysical.lf index 4fa5907f73..53bc3f9da4 100644 --- a/test/TypeScript/src/SlowingClockPhysical.lf +++ b/test/TypeScript/src/SlowingClockPhysical.lf @@ -14,8 +14,8 @@ target TypeScript { main reactor SlowingClockPhysical { physical action a(100 msec) - state interval: time(100 msec) - state expected_time: time(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec reaction(startup) -> a {= expected_time = TimeValue.msec(100); diff --git a/test/TypeScript/src/Stop.lf b/test/TypeScript/src/Stop.lf index 625cedaac7..6104c418d5 100644 --- a/test/TypeScript/src/Stop.lf +++ b/test/TypeScript/src/Stop.lf @@ -13,7 +13,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in1: number - state reactionInvokedCorrectly: boolean(false) + state reactionInvokedCorrectly: boolean = false reaction(in1) {= const currentTag = util.getCurrentTag(); diff --git a/test/TypeScript/src/Stride.lf b/test/TypeScript/src/Stride.lf index c8afaa63ad..04d7805d0b 100644 --- a/test/TypeScript/src/Stride.lf +++ b/test/TypeScript/src/Stride.lf @@ -5,8 +5,8 @@ target TypeScript { fast: true } -reactor Count(stride: number(1)) { - state count: number(0) +reactor Count(stride: number = 1) { + state count: number = 0 output y: number timer t(0, 100 msec) diff --git a/test/TypeScript/src/StructAsState.lf b/test/TypeScript/src/StructAsState.lf index 10da7b2876..a3b1cb081c 100644 --- a/test/TypeScript/src/StructAsState.lf +++ b/test/TypeScript/src/StructAsState.lf @@ -8,7 +8,7 @@ main reactor StructAsState { value: number; } =} - state s: hello_t({= {name: "Earth", value: 42} =}) + state s: hello_t = {= {name: "Earth", value: 42} =} reaction(startup) {= console.log("State s.name=" + s.name + ", s.value=" + s.value); diff --git a/test/TypeScript/src/StructAsType.lf b/test/TypeScript/src/StructAsType.lf index c9d092c7cb..ed70a46653 100644 --- a/test/TypeScript/src/StructAsType.lf +++ b/test/TypeScript/src/StructAsType.lf @@ -18,7 +18,7 @@ reactor Source { =} } -reactor Print(expected: number(42)) { // expected parameter is for testing. +reactor Print(expected: number = 42) { // expected parameter is for testing. input x: hello_t reaction(x) {= diff --git a/test/TypeScript/src/StructAsTypeDirect.lf b/test/TypeScript/src/StructAsTypeDirect.lf index 079735f108..3f891747fc 100644 --- a/test/TypeScript/src/StructAsTypeDirect.lf +++ b/test/TypeScript/src/StructAsTypeDirect.lf @@ -18,7 +18,7 @@ reactor Source { =} } -reactor Print(expected: number(42)) { // expected parameter is for testing. +reactor Print(expected: number = 42) { // expected parameter is for testing. input x: hello_t reaction(x) {= diff --git a/test/TypeScript/src/StructPrint.lf b/test/TypeScript/src/StructPrint.lf index 400d26b610..e75d9ead37 100644 --- a/test/TypeScript/src/StructPrint.lf +++ b/test/TypeScript/src/StructPrint.lf @@ -17,7 +17,7 @@ reactor Source { =} } -reactor Print(expected: number(42)) { // expected parameter is for testing. +reactor Print(expected: number = 42) { // expected parameter is for testing. input x: hello_t reaction(x) {= diff --git a/test/TypeScript/src/StructScale.lf b/test/TypeScript/src/StructScale.lf index 46bef4bc2d..788fd2fe61 100644 --- a/test/TypeScript/src/StructScale.lf +++ b/test/TypeScript/src/StructScale.lf @@ -6,7 +6,7 @@ target TypeScript import Print, Source from "StructPrint.lf" -reactor Scale(scale: number(2)) { +reactor Scale(scale: number = 2) { // Mutable keyword indicates that this reactor wants a writable copy of the // input. mutable input x: hello_t diff --git a/test/TypeScript/src/TimeLimit.lf b/test/TypeScript/src/TimeLimit.lf index d581c8c8a9..05a2a5a3b3 100644 --- a/test/TypeScript/src/TimeLimit.lf +++ b/test/TypeScript/src/TimeLimit.lf @@ -7,10 +7,10 @@ target TypeScript { logging: INFO } -reactor Clock(offset: time(0), period: time(1 sec)) { +reactor Clock(offset: time = 0, period: time = 1 sec) { output y: number timer t(offset, period) - state count: number(0) + state count: number = 0 reaction(t) -> y {= count++; @@ -20,7 +20,7 @@ reactor Clock(offset: time(0), period: time(1 sec)) { reactor Destination { input x: number - state s: number(1) + state s: number = 1 reaction(x) {= if (x != s) { @@ -30,7 +30,7 @@ reactor Destination { =} } -main reactor TimeLimit(period: time(1 msec)) { // usecs take a little too long +main reactor TimeLimit(period: time = 1 msec) { // usecs take a little too long timer stop(10 sec) c = new Clock(period = period) diff --git a/test/TypeScript/src/TimeState.lf b/test/TypeScript/src/TimeState.lf index 95d21f8f52..1dfa86312f 100644 --- a/test/TypeScript/src/TimeState.lf +++ b/test/TypeScript/src/TimeState.lf @@ -1,7 +1,7 @@ target TypeScript -reactor Foo(bar: number(42)) { - state baz: time(500 msec) +reactor Foo(bar: number = 42) { + state baz: time = 500 msec reaction(startup) {= console.log("Baz: " + baz); =} } diff --git a/test/TypeScript/src/concurrent/AsyncCallback.lf b/test/TypeScript/src/concurrent/AsyncCallback.lf index bedf2a47a8..2154d52533 100644 --- a/test/TypeScript/src/concurrent/AsyncCallback.lf +++ b/test/TypeScript/src/concurrent/AsyncCallback.lf @@ -17,11 +17,11 @@ main reactor AsyncCallback { } =} timer t(0, 200 msec) - state expected_time: time(100 msec) - state toggle: boolean(false) + state expected_time: time = 100 msec + state toggle: boolean = false physical action a(100 msec): number - state i: number(0) + state i: number = 0 reaction(t) -> a {= // set a timeout for the callback diff --git a/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf b/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf index 34813bef73..ee03246c37 100644 --- a/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf +++ b/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf @@ -11,7 +11,7 @@ target TypeScript { import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" -federated reactor(offset: time(200 msec)) at rti { +federated reactor(offset: time = 200 msec) at rti { c = new Count() p = new Print() c.out -> p.inp after offset diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf index 423dadd499..50f510cdcd 100644 --- a/test/TypeScript/src/federated/DistributedCount.lf +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -14,7 +14,7 @@ import Count from "../lib/Count.lf" reactor Print { input inp: number - state c: number(1) + state c: number = 1 reaction(inp) {= const elapsedTime = util.getElapsedLogicalTime(); @@ -35,7 +35,7 @@ reactor Print { =} } -federated reactor DistributedCount(offset: time(200 msec)) { +federated reactor DistributedCount(offset: time = 200 msec) { c = new Count() p = new Print() c.out -> p.inp after offset diff --git a/test/TypeScript/src/federated/DistributedCountPhysical.lf b/test/TypeScript/src/federated/DistributedCountPhysical.lf index c0edeb4c33..9ab549e0d0 100644 --- a/test/TypeScript/src/federated/DistributedCountPhysical.lf +++ b/test/TypeScript/src/federated/DistributedCountPhysical.lf @@ -14,7 +14,7 @@ target TypeScript { reactor Count { timer t(200 msec, 1 sec) - state s: number(0) + state s: number = 0 output out: number reaction(t) -> out {= @@ -25,8 +25,8 @@ reactor Count { reactor Print { input inp: number - state c: number(0) - state compareTime: time(200 msec) + state c: number = 0 + state compareTime: time = 200 msec reaction(inp) {= let elapsedTime = util.getElapsedLogicalTime(); diff --git a/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf new file mode 100644 index 0000000000..5f81d3cc5f --- /dev/null +++ b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -0,0 +1,49 @@ +/** + * Test a distributed system where a federation receives messages only over + * connections that are marked 'physical' (using the ~> arrow) with an after + * delay. The receiver verifies that the after delay is correctly imposed. + * + * @author Edward A. Lee + * @author Soroush Bateni + * @author Byeong-gil Jun + */ +target TypeScript { + logging: debug, + keepalive: true +} + +import Count from "../lib/Count.lf" + +reactor Print { + input inp: number + state c: number = 1 + + reaction(inp) {= + const elapsedTime = util.getElapsedLogicalTime(); + console.log(`At time ${elapsedTime}, received ${inp}`); + if (inp !== c) { + util.requestErrorStop(`ERROR: Expected to receive ${c}.`); + } + if (!elapsedTime.isLaterThan(TimeValue.msec(600))) { + util.requestErrorStop(`ERROR: Expected received time to be strictly greater than ${TimeValue.msec(600)}`); + } + c++; + console.log(`c = ${c}`); + util.requestStop(); + =} + + reaction(shutdown) {= + if (c !== 2) { + util.requestErrorStop(`ERROR: Expected to receive 1 item. Received ${c - 1}.`); + } else { + console.log("SUCCESS: Successfully received 1 item."); + } + =} +} + +federated reactor at localhost { + c = new Count(offset = 200 msec, period = 0) + p = new Print() + // Indicating a 'physical' connection with a 400 msec after delay. + c.out ~> p.inp after 400 msec +} diff --git a/test/TypeScript/src/federated/DistributedDoublePort.lf b/test/TypeScript/src/federated/DistributedDoublePort.lf index d8677d65a4..d3a2636661 100644 --- a/test/TypeScript/src/federated/DistributedDoublePort.lf +++ b/test/TypeScript/src/federated/DistributedDoublePort.lf @@ -17,7 +17,7 @@ target TypeScript { import Count from "../lib/Count.lf" reactor CountMicrostep { - state count: number(1) + state count: number = 1 output out: number logical action act: number timer t(0, 1 sec) diff --git a/test/TypeScript/src/federated/DistributedLoopedAction.lf b/test/TypeScript/src/federated/DistributedLoopedAction.lf index 5e8619395f..02a7f5dc62 100644 --- a/test/TypeScript/src/federated/DistributedLoopedAction.lf +++ b/test/TypeScript/src/federated/DistributedLoopedAction.lf @@ -11,11 +11,11 @@ target TypeScript { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver(takeBreakAfter: number(10), breakInterval: time(400 msec)) { +reactor Receiver(takeBreakAfter: number = 10, breakInterval: time = 400 msec) { input inp: number - state receivedMessages: number(0) - state totalReceivedMessages: number(0) - state breaks: number(0) + state receivedMessages: number = 0 + state totalReceivedMessages: number = 0 + state breaks: number = 0 timer t(0, 1 msec) // This will impact the performance // but forces the logical time to advance Comment this line for a more diff --git a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf index c747061578..842f13f74c 100644 --- a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf @@ -10,10 +10,10 @@ target TypeScript { timeout: 1 sec } -reactor Sender(takeBreakAfter: number(10), breakInterval: time(550 msec)) { +reactor Sender(takeBreakAfter: number = 10, breakInterval: time = 550 msec) { output out: number physical action act - state sentMessages: number(0) + state sentMessages: number = 0 reaction(startup, act) -> act, out {= // Send a message on out @@ -29,11 +29,11 @@ reactor Sender(takeBreakAfter: number(10), breakInterval: time(550 msec)) { =} } -reactor Receiver(takeBreakAfter: number(10), breakInterval: time(550 msec)) { +reactor Receiver(takeBreakAfter: number = 10, breakInterval: time = 550 msec) { input inp: number - state receivedMessages: number(0) - state totalReceivedMessages: number(0) - state breaks: number(0) + state receivedMessages: number = 0 + state totalReceivedMessages: number = 0 + state breaks: number = 0 timer t(0, 1 msec) // This will impact the performance // but forces the logical time to advance Comment this line for a more diff --git a/test/TypeScript/src/federated/DistributedStop.lf b/test/TypeScript/src/federated/DistributedStop.lf index 2983ff3f7a..c0dd04149a 100644 --- a/test/TypeScript/src/federated/DistributedStop.lf +++ b/test/TypeScript/src/federated/DistributedStop.lf @@ -11,7 +11,7 @@ reactor Sender { output out: number timer t(0, 1 usec) logical action act - state reaction_invoked_correctly: boolean(false) + state reaction_invoked_correctly: boolean = false reaction(t, act) -> out, act {= console.log(`Sending 42 at (${util.getElapsedLogicalTime()}, ` @@ -58,10 +58,10 @@ reactor Sender { } reactor Receiver( - stp_offset: time(10 msec) // Used in the decentralized variant of the test + stp_offset: time = 10 msec // Used in the decentralized variant of the test ) { input in1: number - state reaction_invoked_correctly: boolean(false) + state reaction_invoked_correctly: boolean = false reaction(in1) {= console.log(`Received ${in1} at (${util.getElapsedLogicalTime()}, ` diff --git a/test/TypeScript/src/federated/HelloDistributed.lf b/test/TypeScript/src/federated/HelloDistributed.lf index 12533129e4..1189270ab1 100644 --- a/test/TypeScript/src/federated/HelloDistributed.lf +++ b/test/TypeScript/src/federated/HelloDistributed.lf @@ -20,7 +20,7 @@ reactor Source { reactor Destination { input inp: string - state received: boolean(false) + state received: boolean = false reaction(startup) {= console.log("Destination started."); =} diff --git a/test/TypeScript/src/federated/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/LoopDistributedCentralized.lf index d5fdae2635..bb52679489 100644 --- a/test/TypeScript/src/federated/LoopDistributedCentralized.lf +++ b/test/TypeScript/src/federated/LoopDistributedCentralized.lf @@ -9,11 +9,11 @@ target TypeScript { timeout: 5 sec } -reactor Looper(incr: number(1), delay: time(0 msec)) { +reactor Looper(incr: number = 1, delay: time = 0 msec) { input inp: number output out: number physical action a(delay) - state count: number(0) + state count: number = 0 preamble {= let stop = false; @@ -57,7 +57,7 @@ reactor Looper(incr: number(1), delay: time(0 msec)) { =} } -federated reactor LoopDistributedCentralized(delay: time(0)) { +federated reactor LoopDistributedCentralized(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.inp diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf index b86e55feaa..2c791377f7 100644 --- a/test/TypeScript/src/federated/LoopDistributedDouble.lf +++ b/test/TypeScript/src/federated/LoopDistributedDouble.lf @@ -13,13 +13,13 @@ target TypeScript { } } -reactor Looper(incr: number(1), delay: time(0 msec)) { +reactor Looper(incr: number = 1, delay: time = 0 msec) { input inp: number input inp2: number output out: number output out2: number physical action a(delay) - state count: number(0) + state count: number = 0 timer t(0, 1 sec) preamble {= @@ -71,7 +71,7 @@ reactor Looper(incr: number(1), delay: time(0 msec)) { =} } -federated reactor(delay: time(0)) { +federated reactor(delay: time = 0) { left = new Looper() right = new Looper(incr = -1) left.out -> right.inp diff --git a/test/TypeScript/src/federated/PingPongDistributed.lf b/test/TypeScript/src/federated/PingPongDistributed.lf index 0c362b1bf7..34a633aba4 100644 --- a/test/TypeScript/src/federated/PingPongDistributed.lf +++ b/test/TypeScript/src/federated/PingPongDistributed.lf @@ -1,10 +1,10 @@ /** This checks communication between federates */ target TypeScript -reactor Ping(count: number(10)) { +reactor Ping(count: number = 10) { input receive: number output send: number - state pingsLeft: number(count) + state pingsLeft: number = count logical action serve reaction(startup, serve) -> send {= @@ -23,10 +23,10 @@ reactor Ping(count: number(10)) { =} } -reactor Pong(expected: number(10)) { +reactor Pong(expected: number = 10) { input receive: number output send: number - state count: number(0) + state count: number = 0 reaction(receive) -> send {= count += 1; @@ -45,7 +45,7 @@ reactor Pong(expected: number(10)) { =} } -federated reactor PingPongDistributed(count: number(10)) { +federated reactor PingPongDistributed(count: number = 10) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send -> pong.receive diff --git a/test/TypeScript/src/federated/PingPongDistributedPhysical.lf b/test/TypeScript/src/federated/PingPongDistributedPhysical.lf index 1f33964abc..58f55a4747 100644 --- a/test/TypeScript/src/federated/PingPongDistributedPhysical.lf +++ b/test/TypeScript/src/federated/PingPongDistributedPhysical.lf @@ -27,10 +27,10 @@ */ target TypeScript -reactor Ping(count: number(10)) { +reactor Ping(count: number = 10) { input receive: number output send: number - state pingsLeft: number(count) + state pingsLeft: number = count logical action serve reaction(startup, serve) -> send {= @@ -47,10 +47,10 @@ reactor Ping(count: number(10)) { =} } -reactor Pong(expected: number(10)) { +reactor Pong(expected: number = 10) { input receive: number output send: number - state count: number(0) + state count: number = 0 reaction(receive) -> send {= count++; @@ -69,7 +69,7 @@ reactor Pong(expected: number(10)) { =} } -federated reactor(count: number(10)) { +federated reactor(count: number = 10) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send ~> pong.receive diff --git a/test/TypeScript/src/federated/TopLevelArtifacts.lf b/test/TypeScript/src/federated/TopLevelArtifacts.lf index 89bdfd9a68..917da033f5 100644 --- a/test/TypeScript/src/federated/TopLevelArtifacts.lf +++ b/test/TypeScript/src/federated/TopLevelArtifacts.lf @@ -16,7 +16,7 @@ import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - state successes: number(0) + state successes: number = 0 logical action act timer t(0, 1 sec) diff --git a/test/TypeScript/src/lib/Count.lf b/test/TypeScript/src/lib/Count.lf index b61aaa92e3..d848d8e9d4 100644 --- a/test/TypeScript/src/lib/Count.lf +++ b/test/TypeScript/src/lib/Count.lf @@ -1,9 +1,9 @@ target TypeScript -reactor Count(offset: time(0), period: time(1 sec)) { +reactor Count(offset: time = 0, period: time = 1 sec) { output out: number timer t(offset, period) - state count: number(1) + state count: number = 1 reaction(t) -> out {= out = count++; =} } diff --git a/test/TypeScript/src/lib/InternalDelay.lf b/test/TypeScript/src/lib/InternalDelay.lf index ace3c21c12..0f6f109322 100644 --- a/test/TypeScript/src/lib/InternalDelay.lf +++ b/test/TypeScript/src/lib/InternalDelay.lf @@ -1,7 +1,7 @@ /** @author Youri Su */ target TypeScript -reactor InternalDelay(delay: TimeValue(10 msec)) { +reactor InternalDelay(delay: TimeValue = 10 msec) { input inp: number output out: number logical action d: number diff --git a/test/TypeScript/src/lib/LoopedActionSender.lf b/test/TypeScript/src/lib/LoopedActionSender.lf index f72a427bf1..7da4c133b0 100644 --- a/test/TypeScript/src/lib/LoopedActionSender.lf +++ b/test/TypeScript/src/lib/LoopedActionSender.lf @@ -12,10 +12,10 @@ target TypeScript * @param breakInterval: Determines how long the reactor should take a break * after sending takeBreakAfter messages. */ -reactor Sender(takeBreakAfter: number(10), breakInterval: time(400 msec)) { +reactor Sender(takeBreakAfter: number = 10, breakInterval: time = 400 msec) { output out: number logical action act - state sentMessages: number(0) + state sentMessages: number = 0 reaction(startup, act) -> act, out {= // Send a message on out diff --git a/test/TypeScript/src/lib/TestCount.lf b/test/TypeScript/src/lib/TestCount.lf index 5a4b9067df..822b4c64b1 100644 --- a/test/TypeScript/src/lib/TestCount.lf +++ b/test/TypeScript/src/lib/TestCount.lf @@ -9,9 +9,13 @@ */ target TypeScript -reactor TestCount(start: number(1), stride: number(1), numInputs: number(1)) { - state count: number(start) - state inputsReceived: number(0) +reactor TestCount( + start: number = 1, + stride: number = 1, + numInputs: number = 1 +) { + state count: number = start + state inputsReceived: number = 0 input inp: number reaction(inp) {= diff --git a/test/TypeScript/src/multiport/BankMultiportToReaction.lf b/test/TypeScript/src/multiport/BankMultiportToReaction.lf index 0119785cd5..6516749418 100644 --- a/test/TypeScript/src/multiport/BankMultiportToReaction.lf +++ b/test/TypeScript/src/multiport/BankMultiportToReaction.lf @@ -12,8 +12,8 @@ reactor DoubleCount { } main reactor { - state count: number(1) - state received: boolean(false) + state count: number = 1 + state received: boolean = false s = new[2] DoubleCount() diff --git a/test/TypeScript/src/multiport/BankReactionsInContainer.lf b/test/TypeScript/src/multiport/BankReactionsInContainer.lf index 1628dce060..b14ca33f70 100644 --- a/test/TypeScript/src/multiport/BankReactionsInContainer.lf +++ b/test/TypeScript/src/multiport/BankReactionsInContainer.lf @@ -8,7 +8,7 @@ target TypeScript { reactor R { output[2] out: number input[2] inp: number - state received: boolean(false) + state received: boolean = false reaction(startup) -> out {= for (let i = 0; i < out.length; i++) { @@ -41,7 +41,7 @@ reactor R { main reactor { s = new[2] R() - state received: boolean(false) + state received: boolean = false reaction(startup) -> s.inp {= let count = 0; diff --git a/test/TypeScript/src/multiport/BankSelfBroadcast.lf b/test/TypeScript/src/multiport/BankSelfBroadcast.lf index dcd2aa8dfc..cf5af4bee3 100644 --- a/test/TypeScript/src/multiport/BankSelfBroadcast.lf +++ b/test/TypeScript/src/multiport/BankSelfBroadcast.lf @@ -12,7 +12,7 @@ target TypeScript reactor A { input[4] inp: number output out: number - state received: boolean(false) + state received: boolean = false reaction(startup) -> out {= out = this.getBankIndex(); =} diff --git a/test/TypeScript/src/multiport/BankToBank.lf b/test/TypeScript/src/multiport/BankToBank.lf index 0a4583c65a..5258616899 100644 --- a/test/TypeScript/src/multiport/BankToBank.lf +++ b/test/TypeScript/src/multiport/BankToBank.lf @@ -6,7 +6,7 @@ target TypeScript { reactor Source { timer t(0, 200 msec) output out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= out = s; @@ -15,7 +15,7 @@ reactor Source { } reactor Destination { - state s: number(0) + state s: number = 0 input inp: number reaction(inp) {= @@ -34,7 +34,7 @@ reactor Destination { =} } -main reactor BankToBank(width: number(4)) { +main reactor BankToBank(width: number = 4) { // FIXME: Should set the width to "width" rather than "4". a = new[4] Source() b = new[4] Destination() diff --git a/test/TypeScript/src/multiport/BankToBankMultiport.lf b/test/TypeScript/src/multiport/BankToBankMultiport.lf index ce82471f64..ef58c43ead 100644 --- a/test/TypeScript/src/multiport/BankToBankMultiport.lf +++ b/test/TypeScript/src/multiport/BankToBankMultiport.lf @@ -3,10 +3,10 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(1)) { +reactor Source(width: number = 1) { timer t(0, 200 msec) output[width] out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= for(let i = 0; i < out.length; i++) { @@ -15,8 +15,8 @@ reactor Source(width: number(1)) { =} } -reactor Destination(width: number(1)) { - state s: number(6) +reactor Destination(width: number = 1) { + state s: number = 6 input[width] inp: number reaction(inp) {= @@ -40,7 +40,7 @@ reactor Destination(width: number(1)) { =} } -main reactor BankToBankMultiport(bankWidth: number(4)) { +main reactor BankToBankMultiport(bankWidth: number = 4) { a = new[bankWidth] Source(width = 4) b = new[bankWidth] Destination(width = 4) a.out -> b.inp diff --git a/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf b/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf index 8ad676de36..51c095119b 100644 --- a/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf +++ b/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf @@ -3,10 +3,10 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(1)) { +reactor Source(width: number = 1) { timer t(0, 200 msec) output[width] out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= for(let i = 0; i < out.length; i++) { @@ -15,8 +15,8 @@ reactor Source(width: number(1)) { =} } -reactor Destination(width: number(1)) { - state s: number(6) +reactor Destination(width: number = 1) { + state s: number = 6 input[width] inp: number reaction(inp) {= @@ -40,7 +40,7 @@ reactor Destination(width: number(1)) { =} } -main reactor(bankWidth: number(4)) { +main reactor(bankWidth: number = 4) { a = new[bankWidth] Source(width = 4) b = new[bankWidth] Destination(width = 4) a.out -> b.inp after 200 msec diff --git a/test/TypeScript/src/multiport/BankToMultiport.lf b/test/TypeScript/src/multiport/BankToMultiport.lf index ecaacb52df..43dc7ee1bb 100644 --- a/test/TypeScript/src/multiport/BankToMultiport.lf +++ b/test/TypeScript/src/multiport/BankToMultiport.lf @@ -9,7 +9,7 @@ reactor Source { reactor Sink { input[4] inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= for (let i = 0; i < inp.length; i++) { diff --git a/test/TypeScript/src/multiport/BankToReaction.lf b/test/TypeScript/src/multiport/BankToReaction.lf index 89b189748d..df65c3063e 100644 --- a/test/TypeScript/src/multiport/BankToReaction.lf +++ b/test/TypeScript/src/multiport/BankToReaction.lf @@ -5,7 +5,7 @@ target TypeScript { import Count from "../lib/Count.lf" main reactor { - state count: number(1) + state count: number = 1 s = new[2] Count() diff --git a/test/TypeScript/src/multiport/BroadcastAfter.lf b/test/TypeScript/src/multiport/BroadcastAfter.lf index 3cf5eb3850..83cf34ddff 100644 --- a/test/TypeScript/src/multiport/BroadcastAfter.lf +++ b/test/TypeScript/src/multiport/BroadcastAfter.lf @@ -10,7 +10,7 @@ reactor Source { reactor Destination { input inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= console.log("Destination " + this.getBankIndex() + " received " + inp + "."); diff --git a/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf b/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf index 598ec737e6..755cf01107 100644 --- a/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf +++ b/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf @@ -2,7 +2,7 @@ target TypeScript { timeout: 2 sec } -reactor Source(value: number(42)) { +reactor Source(value: number = 42) { output out: number reaction(startup) -> out {= out = value; =} @@ -10,7 +10,7 @@ reactor Source(value: number(42)) { reactor Destination { input inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= console.log("Destination " + this.getBankIndex() + " received " + inp + "."); diff --git a/test/TypeScript/src/multiport/FullyConnected.lf b/test/TypeScript/src/multiport/FullyConnected.lf index cf84e92242..e40009ed90 100644 --- a/test/TypeScript/src/multiport/FullyConnected.lf +++ b/test/TypeScript/src/multiport/FullyConnected.lf @@ -1,10 +1,10 @@ target TypeScript -reactor Node(numNodes: number(4)) { +reactor Node(numNodes: number = 4) { input[numNodes] inp: number output out: number - state received: boolean(false) + state received: boolean = false reaction(startup) -> out {= console.log("Hello from node " + this.getBankIndex() + "!"); @@ -36,7 +36,7 @@ reactor Node(numNodes: number(4)) { =} } -main reactor(numNodes: number(4)) { +main reactor(numNodes: number = 4) { nodes = new[numNodes] Node(numNodes = numNodes) (nodes.out)+ -> nodes.inp } diff --git a/test/TypeScript/src/multiport/MultiportFromBank.lf b/test/TypeScript/src/multiport/MultiportFromBank.lf index 489a9df4a8..18896eed2a 100644 --- a/test/TypeScript/src/multiport/MultiportFromBank.lf +++ b/test/TypeScript/src/multiport/MultiportFromBank.lf @@ -10,9 +10,9 @@ reactor Source { reaction(startup) -> out {= out = this.getBankIndex(); =} } -reactor Destination(portWidth: number(3)) { +reactor Destination(portWidth: number = 3) { input[portWidth] inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= for (let i = 0; i < inp.length; i++) { @@ -32,7 +32,7 @@ reactor Destination(portWidth: number(3)) { =} } -main reactor(width: number(4)) { +main reactor(width: number = 4) { a = new[width] Source() b = new Destination(portWidth = width) a.out -> b.inp diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf index e050682ab6..ffc394b26c 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf @@ -6,7 +6,7 @@ target TypeScript { import Source, Destination from "MultiportFromBank.lf" -reactor Container(portWidth: number(3)) { +reactor Container(portWidth: number = 3) { output[portWidth] out: number s = new[portWidth] Source() s.out -> out diff --git a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf index 5922d2f911..5627652b2f 100644 --- a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf @@ -4,10 +4,10 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(3)) { +reactor Source(width: number = 3) { timer t(0, 200 msec) output[width] out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= for(let i = 0; i < out.length; i++) { @@ -16,8 +16,8 @@ reactor Source(width: number(3)) { =} } -reactor Destination(width: number(3)) { - state s: number(6) +reactor Destination(width: number = 3) { + state s: number = 6 input[width] inp: number reaction(inp) {= @@ -41,19 +41,19 @@ reactor Destination(width: number(3)) { =} } -reactor Container(width: number(3)) { +reactor Container(width: number = 3) { output[width] out: number src = new InsideContainer(width = width) src.out -> out } -reactor InsideContainer(width: number(3)) { +reactor InsideContainer(width: number = 3) { output[width] out: number src = new Source(width = width) src.out -> out } -main reactor MultiportFromHierarchy(width: number(4)) { +main reactor MultiportFromHierarchy(width: number = 4) { a = new Container(width = width) b = new Destination(width = width) a.out -> b.inp diff --git a/test/TypeScript/src/multiport/MultiportFromReaction.lf b/test/TypeScript/src/multiport/MultiportFromReaction.lf index 6670c2aa5a..ba386bd379 100644 --- a/test/TypeScript/src/multiport/MultiportFromReaction.lf +++ b/test/TypeScript/src/multiport/MultiportFromReaction.lf @@ -3,8 +3,8 @@ target TypeScript { timeout: 2 sec } -reactor Destination(width: number(1)) { - state s: number(6) +reactor Destination(width: number = 1) { + state s: number = 6 input[width] inp: number reaction(inp) {= @@ -28,9 +28,9 @@ reactor Destination(width: number(1)) { =} } -main reactor MultiportFromReaction(width: number(4)) { +main reactor MultiportFromReaction(width: number = 4) { timer t(0, 200 msec) - state s: number(0) + state s: number = 0 b = new Destination(width = width) reaction(t) -> b.inp {= diff --git a/test/TypeScript/src/multiport/MultiportIn.lf b/test/TypeScript/src/multiport/MultiportIn.lf index c409969657..97a36c08d2 100644 --- a/test/TypeScript/src/multiport/MultiportIn.lf +++ b/test/TypeScript/src/multiport/MultiportIn.lf @@ -7,7 +7,7 @@ target TypeScript { reactor Source { timer t(0, 200 msec) output out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= out = s++; =} } @@ -20,7 +20,7 @@ reactor Computation { } reactor Destination { - state s: number(0) + state s: number = 0 input[4] inp: number reaction(inp) {= diff --git a/test/TypeScript/src/multiport/MultiportInParameterized.lf b/test/TypeScript/src/multiport/MultiportInParameterized.lf index c189e56ef4..fb11c5e102 100644 --- a/test/TypeScript/src/multiport/MultiportInParameterized.lf +++ b/test/TypeScript/src/multiport/MultiportInParameterized.lf @@ -7,7 +7,7 @@ target TypeScript { reactor Source { timer t(0, 200 msec) output out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= out = s; @@ -22,8 +22,8 @@ reactor Computation { reaction(inp) -> out {= out = inp; =} } -reactor Destination(width: number(1)) { - state s: number(0) +reactor Destination(width: number = 1) { + state s: number = 0 input[width] inp: number reaction(inp) {= diff --git a/test/TypeScript/src/multiport/MultiportMutableInput.lf b/test/TypeScript/src/multiport/MultiportMutableInput.lf index f04131e411..11120e8d30 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInput.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInput.lf @@ -12,7 +12,7 @@ reactor Source { =} } -reactor Print(scale: number(1)) { // The scale parameter is just for testing. +reactor Print(scale: number = 1) { // The scale parameter is just for testing. input[2] inp: number reaction(inp) {= @@ -27,7 +27,7 @@ reactor Print(scale: number(1)) { // The scale parameter is just for testing. =} } -reactor Scale(scale: number(2)) { +reactor Scale(scale: number = 2) { mutable input[2] inp: number output[2] out: number diff --git a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf index 26b5c3b87c..382f444df7 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf @@ -26,7 +26,7 @@ reactor Source { =} } -reactor Print(scale: number(1)) { // The scale parameter is just for testing. +reactor Print(scale: number = 1) { // The scale parameter is just for testing. input[2] inp: {= Array =} reaction(inp) {= @@ -55,7 +55,7 @@ reactor Print(scale: number(1)) { // The scale parameter is just for testing. =} } -reactor Scale(scale: number(2)) { +reactor Scale(scale: number = 2) { mutable input[2] inp: {= Array =} output[2] out: {= Array =} diff --git a/test/TypeScript/src/multiport/MultiportOut.lf b/test/TypeScript/src/multiport/MultiportOut.lf index 9fa72bf3e2..04588b86b5 100644 --- a/test/TypeScript/src/multiport/MultiportOut.lf +++ b/test/TypeScript/src/multiport/MultiportOut.lf @@ -6,7 +6,7 @@ target TypeScript { reactor Source { timer t(0, 200 msec) output[4] out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= for(let i = 0; i < 4; i++) { @@ -27,7 +27,7 @@ reactor Computation { } reactor Destination { - state s: number(0) + state s: number = 0 input[4] inp: number reaction(inp) {= diff --git a/test/TypeScript/src/multiport/MultiportToBankAfter.lf b/test/TypeScript/src/multiport/MultiportToBankAfter.lf index 357dc1d0e1..ee10df94c6 100644 --- a/test/TypeScript/src/multiport/MultiportToBankAfter.lf +++ b/test/TypeScript/src/multiport/MultiportToBankAfter.lf @@ -4,7 +4,7 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(2)) { +reactor Source(width: number = 2) { output[width] out: number reaction(startup) -> out {= @@ -16,7 +16,7 @@ reactor Source(width: number(2)) { reactor Destination { input inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= console.log("Destination " + this.getBankIndex() + " received " + inp + "."); @@ -39,7 +39,7 @@ reactor Destination { =} } -main reactor(width: number(3)) { +main reactor(width: number = 3) { a = new Source(width = width) b = new[width] Destination() a.out -> b.inp after 1 sec // Width of the bank of delays will be inferred. diff --git a/test/TypeScript/src/multiport/MultiportToBankDouble.lf b/test/TypeScript/src/multiport/MultiportToBankDouble.lf index b429a846a4..e618dd898d 100644 --- a/test/TypeScript/src/multiport/MultiportToBankDouble.lf +++ b/test/TypeScript/src/multiport/MultiportToBankDouble.lf @@ -25,7 +25,7 @@ reactor Source { reactor Destination { input inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= console.log("Destination " + this.getBankIndex() + " received " + inp + "."); diff --git a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf index 3e5c499d06..7420704ce1 100644 --- a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf @@ -16,7 +16,7 @@ reactor Source { reactor Destination { input inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= console.log("Destination " + this.getBankIndex() + " received " + inp + "."); diff --git a/test/TypeScript/src/multiport/MultiportToHierarchy.lf b/test/TypeScript/src/multiport/MultiportToHierarchy.lf index 4673ff1e22..c620000872 100644 --- a/test/TypeScript/src/multiport/MultiportToHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToHierarchy.lf @@ -5,10 +5,10 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(4)) { +reactor Source(width: number = 4) { timer t(0, 200 msec) output[width] out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= for(let i = 0; i < 4; i++) { @@ -17,8 +17,8 @@ reactor Source(width: number(4)) { =} } -reactor Destination(width: number(4)) { - state s: number(6) +reactor Destination(width: number = 4) { + state s: number = 6 input[width] inp: number reaction(inp) {= @@ -42,13 +42,13 @@ reactor Destination(width: number(4)) { =} } -reactor Container(width: number(4)) { +reactor Container(width: number = 4) { input[width] inp: number dst = new Destination() inp -> dst.inp } -main reactor MultiportToHierarchy(width: number(4)) { +main reactor MultiportToHierarchy(width: number = 4) { a = new Source(width = width) b = new Container(width = width) a.out -> b.inp diff --git a/test/TypeScript/src/multiport/MultiportToMultiport.lf b/test/TypeScript/src/multiport/MultiportToMultiport.lf index 54bac4fbfb..ecd774e7b6 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiport.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiport.lf @@ -12,7 +12,7 @@ reactor Source { reactor Sink { input[4] inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= for (let i = 0; i < inp.length; i++) { diff --git a/test/TypeScript/src/multiport/MultiportToMultiport2.lf b/test/TypeScript/src/multiport/MultiportToMultiport2.lf index 73b3cfedc5..9e9856af63 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiport2.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target TypeScript -reactor Source(width: number(2)) { +reactor Source(width: number = 2) { output[width] out: number reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: number(2)) { =} } -reactor Destination(width: number(2)) { +reactor Destination(width: number = 2) { input[width] inp: number reaction(inp) {= diff --git a/test/TypeScript/src/multiport/MultiportToMultiport2After.lf b/test/TypeScript/src/multiport/MultiportToMultiport2After.lf index 1bca78675c..04890686ab 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiport2After.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiport2After.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target TypeScript -reactor Source(width: number(2)) { +reactor Source(width: number = 2) { output[width] out: number reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: number(2)) { =} } -reactor Destination(width: number(2)) { +reactor Destination(width: number = 2) { input[width] inp: number reaction(inp) {= diff --git a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf index 8e08494cad..737603a5bd 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf @@ -7,7 +7,7 @@ target TypeScript { reactor Source { timer t(0, 200 msec) output[2] out: {= Array =} - state s: number(0) + state s: number = 0 reaction(t) -> out {= for(let i = 0; i < 2; i++) { @@ -24,7 +24,7 @@ reactor Source { } reactor Destination { - state s: number(15) + state s: number = 15 input[2] inp: {= Array =} reaction(inp) {= diff --git a/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf b/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf index d1be5397dd..5252783498 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf @@ -3,10 +3,10 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(1)) { +reactor Source(width: number = 1) { timer t(0, 200 msec) output[width] out: number - state s: number(0) + state s: number = 0 reaction(t) -> out {= for (let i = 0; i < out.length; i++) { @@ -15,8 +15,8 @@ reactor Source(width: number(1)) { =} } -reactor Destination(width: number(1)) { - state s: number(6) +reactor Destination(width: number = 1) { + state s: number = 6 input[width] inp: number // Width is one larger than that of the source. reaction(inp) {= @@ -39,7 +39,7 @@ reactor Destination(width: number(1)) { =} } -main reactor(width: number(4)) { +main reactor(width: number = 4) { a = new Source(width = width) b = new Destination(width = width) a.out -> b.inp diff --git a/test/TypeScript/src/multiport/MultiportToPort.lf b/test/TypeScript/src/multiport/MultiportToPort.lf index a366089fd9..a00d482fe8 100644 --- a/test/TypeScript/src/multiport/MultiportToPort.lf +++ b/test/TypeScript/src/multiport/MultiportToPort.lf @@ -15,9 +15,9 @@ reactor Source { =} } -reactor Destination(expected: number(0)) { +reactor Destination(expected: number = 0) { input inp: number - state received: boolean(false) + state received: boolean = false reaction(inp) {= console.log("Received " + inp); diff --git a/test/TypeScript/src/multiport/MultiportToReaction.lf b/test/TypeScript/src/multiport/MultiportToReaction.lf index 84d33b642f..e7b5af4c00 100644 --- a/test/TypeScript/src/multiport/MultiportToReaction.lf +++ b/test/TypeScript/src/multiport/MultiportToReaction.lf @@ -3,9 +3,9 @@ target TypeScript { timeout: 2 sec } -reactor Source(width: number(1)) { +reactor Source(width: number = 1) { timer t(0, 200 msec) - state s: number(0) + state s: number = 0 output[width] out: number reaction(t) -> out {= @@ -17,7 +17,7 @@ reactor Source(width: number(1)) { } main reactor MultiportToReaction { - state s: number(6) + state s: number = 6 b = new Source(width = 4) reaction(b.out) {= diff --git a/test/TypeScript/src/multiport/NestedBanks.lf b/test/TypeScript/src/multiport/NestedBanks.lf index fea594d1ea..a5c31d38d9 100644 --- a/test/TypeScript/src/multiport/NestedBanks.lf +++ b/test/TypeScript/src/multiport/NestedBanks.lf @@ -20,7 +20,7 @@ reactor A { b.y -> x } -reactor B(aBankIndex: number(0)) { +reactor B(aBankIndex: number = 0) { output[2] y: number reaction(startup) -> y {= @@ -60,7 +60,7 @@ reactor E { =} } -reactor F(cBankIndex: number(0)) { +reactor F(cBankIndex: number = 0) { input w: number reaction(w) {= @@ -71,7 +71,7 @@ reactor F(cBankIndex: number(0)) { =} } -reactor G(cBankIndex: number(0)) { +reactor G(cBankIndex: number = 0) { input s: number reaction(s) {= diff --git a/test/TypeScript/src/multiport/ReactionToContainedBank.lf b/test/TypeScript/src/multiport/ReactionToContainedBank.lf index 9f54a0123b..9b058671cc 100644 --- a/test/TypeScript/src/multiport/ReactionToContainedBank.lf +++ b/test/TypeScript/src/multiport/ReactionToContainedBank.lf @@ -5,9 +5,9 @@ target TypeScript { import TestCount from "../lib/TestCount.lf" -main reactor ReactionToContainedBank(width: number(2)) { +main reactor ReactionToContainedBank(width: number = 2) { timer t(0, 100 msec) - state count: number(1) + state count: number = 1 test = new[width] TestCount(numInputs = 11) diff --git a/test/TypeScript/src/multiport/ReactionsToNested.lf b/test/TypeScript/src/multiport/ReactionsToNested.lf index dbc20ef8ed..055e08d086 100644 --- a/test/TypeScript/src/multiport/ReactionsToNested.lf +++ b/test/TypeScript/src/multiport/ReactionsToNested.lf @@ -4,9 +4,9 @@ target TypeScript { timeout: 1 sec } -reactor T(expected: number(0)) { +reactor T(expected: number = 0) { input z: number - state received: boolean(false) + state received: boolean = false reaction(z) {= console.log("T received " + z); diff --git a/test/TypeScript/src/target/AfterNoTypes.lf b/test/TypeScript/src/target/AfterNoTypes.lf index 2293faf601..b3477bbf55 100644 --- a/test/TypeScript/src/target/AfterNoTypes.lf +++ b/test/TypeScript/src/target/AfterNoTypes.lf @@ -15,7 +15,7 @@ reactor Foo { } reactor Print { - state expected_time: time(10 msec) + state expected_time: time = 10 msec input x reaction(x) {= From 6c227293396b24cc6075716e3ace57cdd92036c1 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 30 Mar 2023 22:23:57 -0700 Subject: [PATCH 095/709] fixed generator issue --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 70f76c282e..255941e8cd 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1527,7 +1527,7 @@ private void recordWatchdogs(ReactorInstance instance) { // temp.pr("#ifdef LF_THREADED"); for (WatchdogInstance watchdog : instance.watchdogs) { temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+GeneratorBase.timeInTargetLanguage(watchdog.getTimeout())+";"); + temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+watchdog.getTimeout()+";"); temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); watchdogCount += 1; foundOne = true; From 7208c8f2b4bf5056eeddefbf92359125a5f9a65c Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Fri, 31 Mar 2023 15:51:16 +0500 Subject: [PATCH 096/709] [C-Generics] Moved type-converter macro to utils Signed-off-by: mkhubaibumer --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java | 3 ++- org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 + .../org/lflang/generator/c/CReactorHeaderFileGenerator.java | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index f9dd92f15b..c1ba14d32a 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f9dd92f15b89ee57545b983bed45362a53a3375b +Subproject commit c1ba14d32a1288356609d59e9631286da52c9fee diff --git a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java index 6022110943..c2ef81bf1d 100644 --- a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java +++ b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java @@ -19,7 +19,8 @@ public static List getCTargetSrc() { public static List getCTargetHeader() { return List.of( "include/api/api.h", - "include/api/generics.h" + "include/api/generics.h", + "include/utils/type_converter.h" ); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index bb0944d389..6cb187710a 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1054,6 +1054,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); src.pr("#include \"include/api/generics.h\""); + src.pr("#include \"include/utils/type_converter.h\""); generateIncludes(tpr); if (CCppMode) { src.pr("}"); diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 9c820cd87c..6bdb08f5a9 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -65,7 +65,8 @@ private static void appendPoundIncludes(CodeBuilder builder) { #include "../include/api/api.h" #include "../include/api/set.h" #include "../include/api/generics.h" - #include "../include/core/reactor.h" + #include "../include/utils/type_converter.h" + #include "../include/core/reactor.h" #ifdef __cplusplus } #endif From 6477a99bd19260d7f58d4a3e4f88608095e0b063 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Fri, 31 Mar 2023 15:51:16 +0500 Subject: [PATCH 097/709] [C-Generics] Moved type-converter macro to utils Signed-off-by: mkhubaibumer --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java | 3 ++- org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 + .../org/lflang/generator/c/CReactorHeaderFileGenerator.java | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index f9dd92f15b..c1ba14d32a 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f9dd92f15b89ee57545b983bed45362a53a3375b +Subproject commit c1ba14d32a1288356609d59e9631286da52c9fee diff --git a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java index 6022110943..c2ef81bf1d 100644 --- a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java +++ b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java @@ -19,7 +19,8 @@ public static List getCTargetSrc() { public static List getCTargetHeader() { return List.of( "include/api/api.h", - "include/api/generics.h" + "include/api/generics.h", + "include/utils/type_converter.h" ); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index bb0944d389..6cb187710a 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1054,6 +1054,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); src.pr("#include \"include/api/generics.h\""); + src.pr("#include \"include/utils/type_converter.h\""); generateIncludes(tpr); if (CCppMode) { src.pr("}"); diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 9c820cd87c..6bdb08f5a9 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -65,7 +65,8 @@ private static void appendPoundIncludes(CodeBuilder builder) { #include "../include/api/api.h" #include "../include/api/set.h" #include "../include/api/generics.h" - #include "../include/core/reactor.h" + #include "../include/utils/type_converter.h" + #include "../include/core/reactor.h" #ifdef __cplusplus } #endif From 38e0758838320c8bc76dd52de169c96eb99778f8 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Fri, 31 Mar 2023 16:14:48 +0500 Subject: [PATCH 098/709] Update submodule ref --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c1ba14d32a..866b189a4f 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c1ba14d32a1288356609d59e9631286da52c9fee +Subproject commit 866b189a4f04d3fae7a50a256b8ca3686ea1c509 From a7afcee0193ce9b2252f90cae05a56407442fc0c Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 31 Mar 2023 15:25:52 +0200 Subject: [PATCH 099/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index fe5e6c2d1c..6bdf8c9f05 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit fe5e6c2d1cbc38b46b7298facb5f77e5ba6f387c +Subproject commit 6bdf8c9f054e463359f46170eb073928aea33ff9 From 9626826ce83b06b5f3573e03b990372c57a23ceb Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 31 Mar 2023 15:27:17 +0200 Subject: [PATCH 100/709] add tests with cycles --- test/Cpp/src/enclave/EnclaveCycle.lf | 67 ++++++++++++++++ test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf | 70 +++++++++++++++++ .../EnclaveUpstreamPhysicalActionDelayed.lf | 77 +++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 test/Cpp/src/enclave/EnclaveCycle.lf create mode 100644 test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf create mode 100644 test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf diff --git a/test/Cpp/src/enclave/EnclaveCycle.lf b/test/Cpp/src/enclave/EnclaveCycle.lf new file mode 100644 index 0000000000..d073c801c8 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCycle.lf @@ -0,0 +1,67 @@ +target Cpp { + timeout: 1 s, + workers: 1 +} + +reactor Ping { + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false + + reaction(t) -> out {= out.set(counter++); =} + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Ping Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +reactor Pong { + input in: int + output out: int + state received: bool = false + + reaction(in) -> out {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Pong Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + out.set(value); + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + @enclave + ping = new Ping() + @enclave + pong = new Pong() + + ping.out -> pong.in + pong.out -> ping.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf b/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf new file mode 100644 index 0000000000..f347aa53a4 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf @@ -0,0 +1,70 @@ +target Cpp { + timeout: 1 s, + workers: 1 +} + +reactor Ping { + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false + + reaction(t) -> out {= out.set(counter++); =} + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Ping Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +reactor Pong { + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false + + reaction(t) -> out {= out.set(counter++); =} + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Pong Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + @enclave + ping = new Ping() + @enclave + pong = new Pong() + + ping.out -> pong.in after 50 ms + pong.out -> ping.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf new file mode 100644 index 0000000000..f87895f960 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf @@ -0,0 +1,77 @@ +// The purpose of this test is to check that the downstream enclave can +// progress, even if there are only sparse upstream events. +target Cpp { + timeout: 10 s, + workers: 1 +} + +reactor Src { + public preamble {= + #include + =} + + state thread: std::thread{} + + physical action a: int + output out: int + + reaction(startup) -> a {= + // start new thread + this->thread = std::thread([&] () { + for (int i{0}; i < 3; i++) { + a.schedule(i); + std::this_thread::sleep_for(2s); + } + }); + =} + + reaction(a) -> out {= out.set(a.get()); =} + + reaction(shutdown) {= + // make sure to join the thread before shutting down + if(thread.joinable()) { + thread.join(); + } + =} +} + +reactor Sink { + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= + reactor::log::Info() << "Tick - " << "logical time: " << get_elapsed_logical_time() + << "; physical time: " << get_elapsed_physical_time(); + =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} +} + +main reactor { + @enclave + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in after 2 s +} From b59b3b7474caf09d189255fdf41990a7cd5615fb Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 31 Mar 2023 13:44:05 -0700 Subject: [PATCH 101/709] Temporarily remove the generics headers. --- org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java | 4 +--- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java index c2ef81bf1d..46503d87cc 100644 --- a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java +++ b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java @@ -18,9 +18,7 @@ public static List getCTargetSrc() { public static List getCTargetHeader() { return List.of( - "include/api/api.h", - "include/api/generics.h", - "include/utils/type_converter.h" + "include/api/api.h" ); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index acaef65b99..2d3c6e79e7 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1062,8 +1062,6 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); - src.pr("#include \"include/api/generics.h\""); - src.pr("#include \"include/utils/type_converter.h\""); generateIncludes(tpr); if (CCppMode) { src.pr("}"); From a55a886c5dd69d4025f37f7e3d5873d38d3d1097 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 31 Mar 2023 15:12:29 -0700 Subject: [PATCH 102/709] Update submodule. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ac3d19a58a..ac05b8ebc8 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ac3d19a58ad86dd57c14b2505289f64b8c651d79 +Subproject commit ac05b8ebc8aec4d5596ade92e39429846af51d45 From a4740c35ede3e45fcf1887cf04828ec60b3a3403 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 3 Apr 2023 11:47:53 -0700 Subject: [PATCH 103/709] saving before continuing changes --- org.lflang/src/org/lflang/ASTUtils.java | 7 +++++ .../org/lflang/generator/c/CGenerator.java | 2 +- .../generator/c/CWatchdogGenerator.java | 26 ++++++++++++++++--- test/C/src/Watchdog.lf | 1 + 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 4423363fec..f9767e7e9a 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -586,6 +586,13 @@ public static Iterable allElementsOfClass( //////////////////////////////// //// Utility functions for translating AST nodes into text + // public static Code toCode(String text) { + // Code code = null; + // if (text == null) return code; + // code.setBody(text); + // return code; + // } + /** * Translate the given code into its textual representation * with {@code CodeMap.Correspondence} tags inserted, or diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 1d588aa260..33bcab4b70 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1525,7 +1525,7 @@ private void recordWatchdogs(ReactorInstance instance) { // temp.pr("#ifdef LF_THREADED"); for (WatchdogInstance watchdog : instance.watchdogs) { temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+watchdog.getTimeout()+";"); + temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+CTypes.getInstance().getTargetTimeExpr(watchdog.getTimeout())+";"); temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); watchdogCount += 1; foundOne = true; diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 4193a7c522..0c1ce1f762 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -106,12 +106,32 @@ public static String generateWatchdogFunctionHeader(Watchdog watchdog, * Generate the watchdog function. */ public static String generateWatchdogFunction(Watchdog watchdog, - ReactorDecl decl) { - return CReactionGenerator.generateFunction(generateWatchdogFunctionHeader(watchdog, decl), + ReactorDecl decl) { + return generateFunction(generateWatchdogFunctionHeader(watchdog, decl), generateInitializationForWatchdog(watchdog, decl), - watchdog.getCode()); + watchdog); } + /** + * Do heavy lifting to generate above watchdog function + * @param header function name and declaration. + * @param init initialize variable. + * @param watchdog The watchdog. + */ + public static String generateFunction(String header, String init, Watchdog watchdog) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(watchdog.getCode()); + function.pr(ASTUtils.toText(watchdog.getCode())); + function.pr("lf_set("+watchdog.getName()+", 1);"); + function.unindent(); + function.pr("}"); + return function.toString(); + } + + /** * Generate watchdog definition in parent struct. */ diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index b44a16f22c..df88d23d73 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -34,6 +34,7 @@ reactor Watcher(timeout:time(150ms)) { =} reaction(poodle) -> d {= + lf_print("Reaction poodle was called."); lf_set(d, 1); =} From 1af9922b0668c2f32891898b595031e797e9f93f Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 3 Apr 2023 12:38:06 -0700 Subject: [PATCH 104/709] added watchdog to body of itself, started making changes to treat watchdog trigger --- .../src/org/lflang/generator/c/CWatchdogGenerator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 0c1ce1f762..3c9568699c 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -75,6 +75,8 @@ public static String generateInitializationForWatchdog(Watchdog watchdog, } } } + // Add watchdog definition + watchdogInitialization.pr("watchdog_t* "+watchdog.getName()+" = &(self->_lf_watchdog_"+watchdog.getName()+");\n"); // Next generate all the collected setup code. code.pr(watchdogInitialization.toString()); @@ -125,7 +127,8 @@ public static String generateFunction(String header, String init, Watchdog watch function.pr(init); function.prSourceLineNumber(watchdog.getCode()); function.pr(ASTUtils.toText(watchdog.getCode())); - function.pr("lf_set("+watchdog.getName()+", 1);"); + //FIXME: will need to lf_schedule instead + // function.pr("lf_set("+watchdog.getName()+", 1);"); function.unindent(); function.pr("}"); return function.toString(); From 25aace4fe165a7f59967c56420db4fa71ecc1ba6 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Tue, 4 Apr 2023 21:09:09 +0500 Subject: [PATCH 105/709] [C-Generics] Updates for resolving Actions/StateVariables typenames to concrete types Updates to remove COrresponding tags for declerations Signed-off-by: mkhubaibumer --- .../org/lflang/generator/c/CGenerator.java | 34 +++++++++++-------- .../generator/c/CParameterGenerator.java | 8 ++--- .../lflang/generator/c/CPortGenerator.java | 6 ++-- .../generator/c/CReactionGenerator.java | 16 ++++----- .../lflang/generator/c/CStateGenerator.java | 6 ++-- .../src/org/lflang/generator/c/CUtil.java | 18 ++++++++++ .../c/InteractingContainedReactors.java | 1 + .../generator/c/TypeParameterizedReactor.java | 2 +- 8 files changed, 55 insertions(+), 36 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 6cb187710a..611edf7c62 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1048,8 +1048,6 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("extern \"C\" {"); header.pr("extern \"C\" {"); } - tpr.typeArgs().forEach((literal, concreteType) -> header.pr( - "#define " + literal + " " + ASTUtils.toText(concreteType))); header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/api.h\""); src.pr("#include \"include/api/set.h\""); @@ -1062,11 +1060,19 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String } src.pr("#include \"" + headerName + "\""); tpr.typeArgs().forEach((literal, concreteType) -> src.pr( - "#define " + literal + " " + ASTUtils.toText(concreteType))); + "#if defined " + literal + "\n" + + "#undef " + literal + "\n" + + "#endif // " + literal + "\n" + + "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); new HashSet<>(ASTUtils.allInstantiations(tpr.r())).stream() .map(TypeParameterizedReactor::new).map(CUtil::getName) .map(name -> "#include \"" + name + ".h\"") .forEach(header::pr); + tpr.typeArgs().forEach((literal, concreteType) -> header.pr( + "#if defined " + literal + "\n" + + "#undef " + literal + "\n" + + "#endif // " + literal + "\n" + + "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); } private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder header, CodeBuilder src) { @@ -1186,10 +1192,10 @@ private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tp generateSelfStructExtension(body, reactor, constructorCode); // Next handle parameters. - body.pr(CParameterGenerator.generateDeclarations(reactor, types)); + body.pr(CParameterGenerator.generateDeclarations(tpr, types)); // Next handle states. - body.pr(CStateGenerator.generateDeclarations(reactor, types)); + body.pr(CStateGenerator.generateDeclarations(tpr, types)); // Next handle actions. CActionGenerator.generateDeclarations(tpr, body, constructorCode); @@ -1204,13 +1210,12 @@ private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tp // struct has a place to hold the data produced by this reactor's // reactions and a place to put pointers to data produced by // the contained reactors. - generateInteractingContainedReactors(tpr, reactor, body, constructorCode); + generateInteractingContainedReactors(tpr, body, constructorCode); // Next, generate the fields needed for each reaction. CReactionGenerator.generateReactionAndTriggerStructs( body, tpr, - reactor, constructorCode, types ); @@ -1241,20 +1246,18 @@ private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tp * reactions and a place to put pointers to data produced by * the contained reactors. * - * @param tpr The TypeParameterized Reactor - * @param reactor The reactor. + * @param tpr {@link TypeParameterizedReactor} * @param body The place to put the struct definition for the contained reactors. * @param constructorCode The place to put matching code that goes in the container's constructor. */ private void generateInteractingContainedReactors( TypeParameterizedReactor tpr, - Reactor reactor, CodeBuilder body, CodeBuilder constructorCode ) { // The contents of the struct will be collected first so that // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(reactor); + var contained = new InteractingContainedReactors(tpr.r()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); @@ -1285,12 +1288,12 @@ private void generateInteractingContainedReactors( // to be malloc'd at initialization. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, tpr, false)+" "+port.getName()+";"); + body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); } else { // Is a multiport. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, tpr, false)+"** "+port.getName()+";", + variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1300,13 +1303,13 @@ private void generateInteractingContainedReactors( // self struct of the container. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, tpr, false)+"* "+port.getName()+";"); + body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); } else { // Is a multiport. // Here, we will use an array of pointers. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, tpr, false)+"** "+port.getName()+";", + variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1769,6 +1772,7 @@ private void generateInitializeActionToken(ReactorInstance reactor) { if (CUtil.isTokenType(type, types)) { typeStr = CUtil.rootType(typeStr); } + typeStr = CUtil.getConcreteType(reactor.tpr, typeStr); if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { payloadSize = "sizeof("+typeStr+")"; } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index 23906eae73..70038648e9 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -76,14 +76,14 @@ public static String getInitializer(ParameterInstance p) { /** * Generate code for parameters variables of a reactor in the form "parameter.type parameter.name;" - * @param reactor The reactor + * @param reactor {@link TypeParameterizedReactor} * @param types A helper class for types */ - public static String generateDeclarations(Reactor reactor, CTypes types) { + public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { CodeBuilder code = new CodeBuilder(); - for (Parameter parameter : ASTUtils.allParameters(reactor)) { + for (Parameter parameter : ASTUtils.allParameters(reactor.r())) { code.prSourceLineNumber(parameter); - code.pr(types.getTargetType(parameter) + " " + parameter.getName() + ";"); + code.pr(CUtil.getConcreteType(reactor, types.getTargetType(parameter)) + " " + parameter.getName() + ";"); } return code.toString(); } diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index accda01fb1..5e6320dbfb 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -33,8 +33,8 @@ public static void generateDeclarations( CodeBuilder body, CodeBuilder constructorCode ) { - generateInputDeclarations(tpr, decl, body, constructorCode); - generateOutputDeclarations(tpr, decl, body, constructorCode); + generateInputDeclarations(tpr, body, constructorCode); + generateOutputDeclarations(tpr, body, constructorCode); } /** @@ -198,7 +198,6 @@ private static String valueDeclaration( */ private static void generateInputDeclarations( TypeParameterizedReactor tpr, - ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode ) { @@ -237,7 +236,6 @@ private static void generateInputDeclarations( */ private static void generateOutputDeclarations( TypeParameterizedReactor tpr, - ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode ) { diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 3630df136f..a336752280 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -56,8 +56,6 @@ public static String generateInitializationForReaction(String body, ErrorReporter errorReporter, Instantiation mainDef, boolean requiresTypes) { - Reactor reactor = tpr.r(); - // Construct the reactionInitialization code to go into // the body of the function before the verbatim code. CodeBuilder reactionInitialization = new CodeBuilder(); @@ -129,7 +127,7 @@ public static String generateInitializationForReaction(String body, // No triggers are given, which means react to any input. // Declare an argument for every input. // NOTE: this does not include contained outputs. - for (Input input : reactor.getInputs()) { + for (Input input : tpr.r().getInputs()) { reactionInitialization.pr(generateInputVariablesInReaction(input, tpr, types)); } } @@ -164,7 +162,7 @@ public static String generateInitializationForReaction(String body, } } else if (effect.getVariable() instanceof Mode) { // Mode change effect - int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); + int idx = ASTUtils.allModes(tpr.r()).indexOf((Mode)effect.getVariable()); String name = effect.getVariable().getName(); if (idx >= 0) { reactionInitialization.pr( @@ -350,6 +348,7 @@ private static void generateVariablesForSendingToContainedReactors( Instantiation definition, Input input ) { + // TODO: Get reactorInstance or TPR from Instantiation CodeBuilder structBuilder = structs.get(definition); if (structBuilder == null) { structBuilder = new CodeBuilder(); @@ -672,7 +671,6 @@ public static String generateOutputVariablesInReaction( public static void generateReactionAndTriggerStructs( CodeBuilder body, TypeParameterizedReactor tpr, - Reactor reactor, CodeBuilder constructorCode, CTypes types ) { @@ -760,7 +758,7 @@ public static void generateReactionAndTriggerStructs( "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", reaction.eContainer() instanceof Mode ? - "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+reactor.getModes().indexOf((Mode) reaction.eContainer())+"];" : + "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+tpr.r().getModes().indexOf((Mode) reaction.eContainer())+"];" : "self->_lf__reaction_"+reactionCount+".mode = NULL;" )); // Increment the reactionCount even if the reaction is not in the federate @@ -770,7 +768,7 @@ public static void generateReactionAndTriggerStructs( // Next, create and initialize the trigger_t objects. // Start with the timers. - for (Timer timer : ASTUtils.allTimers(reactor)) { + for (Timer timer : ASTUtils.allTimers(tpr.r())) { createTriggerT(body, timer, triggerMap, constructorCode, types); // Since the self struct is allocated using calloc, there is no need to set falsy fields. constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); @@ -791,7 +789,7 @@ public static void generateReactionAndTriggerStructs( } // Next handle actions. - for (Action action : ASTUtils.allActions(reactor)) { + for (Action action : ASTUtils.allActions(tpr.r())) { createTriggerT(body, action, triggerMap, constructorCode, types); var isPhysical = "true"; if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { @@ -821,7 +819,7 @@ public static void generateReactionAndTriggerStructs( } // Next handle inputs. - for (Input input : ASTUtils.allInputs(reactor)) { + for (Input input : ASTUtils.allInputs(tpr.r())) { createTriggerT(body, input, triggerMap, constructorCode, types); } } diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index a0bcf28823..029648844d 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -18,11 +18,11 @@ public class CStateGenerator { * @param reactor The reactor * @param types A helper object for types */ - public static String generateDeclarations(Reactor reactor, CTypes types) { + public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { CodeBuilder code = new CodeBuilder(); - for (StateVar stateVar : ASTUtils.allStateVars(reactor)) { + for (StateVar stateVar : ASTUtils.allStateVars(reactor.r())) { code.prSourceLineNumber(stateVar); - code.pr(types.getTargetType(stateVar) + " " + stateVar.getName() + ";"); + code.pr(CUtil.getConcreteType(reactor, types.getTargetType(stateVar)) + " " + stateVar.getName() + ";"); } return code.toString(); } diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 418c87157b..d5580cefa5 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -882,6 +882,24 @@ public static boolean isTokenType(InferredType type, CTypes types) { return type.isVariableSizeList || targetType.trim().endsWith("*"); } + /** + * Given a type we need to check if the type is Generic Type literal and if + * it is we need to find the corresponding concrete type + * + * @param tpr {@link TypeParameterizedReactor} + * @param type Actual typename + */ + public static String getConcreteType(TypeParameterizedReactor tpr, final String type) { + var wrapper = new Object() { String concreteType = ""; }; + tpr.typeArgs().forEach((literal, concreteType) -> { + if (type.equals(literal)) + { + wrapper.concreteType = String.valueOf(concreteType.getId()); + } + }); + return (wrapper.concreteType.isEmpty()) ? type : wrapper.concreteType; + } + public static String generateWidthVariable(String var) { return var + "_width"; } diff --git a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java index 6fd6175a6f..bc4d6893a1 100644 --- a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java +++ b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java @@ -101,6 +101,7 @@ public InteractingContainedReactors(Reactor reactor) { * @param port The port. */ private List addPort(Instantiation containedReactor, Port port) { + var parent = containedReactor.eContainer(); // Get or create the entry for the containedReactor. var containedReactorEntry = portsByContainedReactor.computeIfAbsent( containedReactor, diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 281139c4af..a903d5e9ae 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -31,7 +31,7 @@ private static ImmutableMap addTypeArgs(Instantiation instantiatio public String getName() { // FIXME: Types that are not just a single token need to be escaped or hashed - return r.getName() + typeArgs.values().stream().map(ASTUtils::toText).collect(Collectors.joining("_")); + return r.getName() + typeArgs.values().stream().map(ASTUtils::toOriginalText).collect(Collectors.joining("_")); } @Override From 03ef8de3a973237bd8b3c1d7cf748e5187303a54 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Wed, 5 Apr 2023 15:17:49 +0500 Subject: [PATCH 106/709] [C-Generics] Contained Reactor type collission Defining template types in header can cause redefinitions in case of contained reactors using `#if defined/#undef/#define` construct can cause type collission as contained reactor can use the same template literals for different types than the parent reactor To solve this issue we decided to go for string substitution in header file to rersolve templated types to their respective concrete types and we'll still be using `#define` in scource files as the template types need to be defined as per instantiation in the source file Signed-off-by: mkhubaibumer --- .../src/org/lflang/generator/c/CActionGenerator.java | 6 ++++-- org.lflang/src/org/lflang/generator/c/CGenerator.java | 7 +------ org.lflang/src/org/lflang/generator/c/CPortGenerator.java | 5 +++-- .../src/org/lflang/generator/c/CReactionGenerator.java | 2 +- org.lflang/src/org/lflang/generator/c/CStateGenerator.java | 7 ++++--- org.lflang/src/org/lflang/generator/c/CTypes.java | 3 ++- org.lflang/src/org/lflang/generator/c/CUtil.java | 4 +++- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index e381ad9bae..2699f276c9 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -140,7 +140,7 @@ public static String generateAuxiliaryStruct( "bool has_value;", // From lf_action_base_t "trigger_t* trigger;" // From lf_action_base_t )); - code.pr(valueDeclaration(action, target, types)); + code.pr(valueDeclaration(tpr, action, target, types)); code.pr(federatedExtension.toString()); code.unindent(); code.pr("} " + variableStructType(action, tpr, userFacing) + ";"); @@ -155,10 +155,12 @@ public static String generateAuxiliaryStruct( * int* value; * ``` * This will return an empty string for an action with no type. + * @param tpr {@link TypeParameterizedReactor} * @param action The action. * @return A string providing the value field of the action struct. */ private static String valueDeclaration( + TypeParameterizedReactor tpr, Action action, Target target, CTypes types @@ -170,6 +172,6 @@ private static String valueDeclaration( // will be a separate field pointing to the token. return action.getType() == null && target.requiresTypes ? "" : - types.getTargetType(action) + " value;"; + CUtil.getConcreteType(tpr, types.getTargetType(action)) + " value;"; } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 611edf7c62..d0791230be 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1068,11 +1068,6 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String .map(TypeParameterizedReactor::new).map(CUtil::getName) .map(name -> "#include \"" + name + ".h\"") .forEach(header::pr); - tpr.typeArgs().forEach((literal, concreteType) -> header.pr( - "#if defined " + literal + "\n" + - "#undef " + literal + "\n" + - "#endif // " + literal + "\n" + - "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); } private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder header, CodeBuilder src) { @@ -1878,7 +1873,7 @@ protected void generateParameterInitialization(ReactorInstance instance) { if (initializer.startsWith("{")) { var temporaryVariableName = parameter.uniqueID(); initializeTriggerObjects.pr(String.join("\n", - "static "+types.getVariableDeclaration(parameter.type, temporaryVariableName, true)+" = "+initializer+";", + "static "+types.getVariableDeclaration(instance.tpr, parameter.type, temporaryVariableName, true)+" = "+initializer+";", selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" )); } else { diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 5e6320dbfb..0177868f1d 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -73,7 +73,7 @@ public static String generateAuxiliaryStruct( "int destination_channel;", // From lf_port_base_t "int num_destinations;" // From lf_port_base_t )); - code.pr(valueDeclaration(port, target, errorReporter, types)); + code.pr(valueDeclaration(tpr, port, target, errorReporter, types)); code.pr(federatedExtension.toString()); code.unindent(); code.pr("} "+variableStructType(port, tpr, userFacing)+";"); @@ -172,6 +172,7 @@ public static String initializeOutputMultiport( * @return A string providing the value field of the port struct. */ private static String valueDeclaration( + TypeParameterizedReactor tpr, Port port, Target target, ErrorReporter errorReporter, @@ -184,7 +185,7 @@ private static String valueDeclaration( } // Do not convert to lf_token_t* using lfTypeToTokenType because there // will be a separate field pointing to the token. - return types.getVariableDeclaration(ASTUtils.getInferredType(port), "value", false) + ";"; + return types.getVariableDeclaration(tpr, ASTUtils.getInferredType(port), "value", false) + ";"; } /** diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index a336752280..d54e54d5ee 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -665,7 +665,7 @@ public static String generateOutputVariablesInReaction( * specified reactor and a trigger_t struct for each trigger (input, action, * timer, or output of a contained reactor). * @param body The place to put the code for the self struct. - * @param reactor The reactor. + * @param tpr {@link TypeParameterizedReactor} * @param constructorCode The place to put the constructor code. */ public static void generateReactionAndTriggerStructs( diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index 029648844d..fc66036511 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -47,7 +47,7 @@ public static String generateInitializer( CTypes types ) { var initExpr = getInitializerExpr(stateVar, instance); - String baseInitializer = generateBaseInitializer(selfRef, stateVar, initExpr, types); + String baseInitializer = generateBaseInitializer(instance.tpr, selfRef, stateVar, initExpr, types); String modalReset = generateModalReset(instance, selfRef, stateVar, initExpr, mode, types); return String.join("\n", baseInitializer, @@ -56,6 +56,7 @@ public static String generateInitializer( } private static String generateBaseInitializer( + TypeParameterizedReactor tpr, String selfRef, StateVar stateVar, String initExpr, @@ -67,7 +68,7 @@ private static String generateBaseInitializer( ) { return selfRef + "->" + stateVar.getName() + " = " + initExpr + ";"; } else { - var declaration = types.getVariableDeclaration( + var declaration = types.getVariableDeclaration(tpr, ASTUtils.getInferredType(stateVar), "_initial", true); return String.join("\n", @@ -103,7 +104,7 @@ private static String generateModalReset( } else { CodeBuilder code = new CodeBuilder(); var source = "_initial"; - var declaration = types.getVariableDeclaration( + var declaration = types.getVariableDeclaration(instance.tpr, ASTUtils.getInferredType(stateVar), source, true); code.pr("{ // For scoping"); diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/src/org/lflang/generator/c/CTypes.java index 803d9e8432..ebb9c894f4 100644 --- a/org.lflang/src/org/lflang/generator/c/CTypes.java +++ b/org.lflang/src/org/lflang/generator/c/CTypes.java @@ -97,11 +97,12 @@ public String getTargetType(InferredType type) { * @param initializer True to return a form usable in a static initializer. */ public String getVariableDeclaration( + TypeParameterizedReactor tpr, InferredType type, String variableName, boolean initializer ) { - String t = TargetTypes.super.getTargetType(type); + String t = CUtil.getConcreteType(tpr, TargetTypes.super.getTargetType(type)); Matcher matcher = arrayPattern.matcher(t); String declaration = String.format("%s %s", t, variableName); if (matcher.find()) { diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index d5580cefa5..87f75133dd 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -878,7 +878,7 @@ private static List multiportWidthTerms(Variable variable) { public static boolean isTokenType(InferredType type, CTypes types) { if (type.isUndefined()) return false; // This is a hacky way to do this. It is now considered to be a bug (#657) - String targetType = types.getVariableDeclaration(type, "", false); + String targetType = types.getVariableDeclaration(null, type, "", false); return type.isVariableSizeList || targetType.trim().endsWith("*"); } @@ -890,6 +890,8 @@ public static boolean isTokenType(InferredType type, CTypes types) { * @param type Actual typename */ public static String getConcreteType(TypeParameterizedReactor tpr, final String type) { + if (tpr == null) + return type; var wrapper = new Object() { String concreteType = ""; }; tpr.typeArgs().forEach((literal, concreteType) -> { if (type.equals(literal)) From b5d6d5891872e840426f2ba8e9ceb9f475c0466e Mon Sep 17 00:00:00 2001 From: Benichiwa Date: Wed, 5 Apr 2023 12:38:30 -0700 Subject: [PATCH 107/709] create triggers save progress --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 + .../src/org/lflang/generator/c/CReactionGenerator.java | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ff3c84c36b..e24e3bca22 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ff3c84c36b2d7fbcbe09fafa577ec94f75194e83 +Subproject commit e24e3bca22c8e2f85be31ec61a1d3e99a72566e2 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 33bcab4b70..b54c77f6ab 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -310,6 +310,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * @author Alexander Schulz-Rosengarten * @author Hou Seng Wong * @author Anirudh Rengarajan + * @author Benjamin Asch */ @SuppressWarnings("StaticPseudoFunctionalStyleMethod") public class CGenerator extends GeneratorBase { diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index e7e43a903c..e58d423d99 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -854,6 +854,11 @@ public static void generateReactionAndTriggerStructs( for (Input input : ASTUtils.allInputs(reactor)) { createTriggerT(body, input, triggerMap, constructorCode, types); } + + // Next handle watchdogs. + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + createTriggerT(body, watchdog, triggerMap, constructorCode, types); + } } /** From 34f96e576eec63f573527e9c1d10efe26e04415c Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Wed, 5 Apr 2023 14:36:35 -0700 Subject: [PATCH 108/709] fixed watchdog test inconsistency? define watchdog trigger --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/org/lflang/generator/c/CReactionGenerator.java | 2 +- .../src/org/lflang/generator/c/CWatchdogGenerator.java | 5 +++-- test/C/src/Watchdog.lf | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index e24e3bca22..ff3c84c36b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e24e3bca22c8e2f85be31ec61a1d3e99a72566e2 +Subproject commit ff3c84c36b2d7fbcbe09fafa577ec94f75194e83 diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index e58d423d99..0a1df14302 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -866,7 +866,7 @@ public static void generateReactionAndTriggerStructs( * reaction_t pointers pointing to reactions triggered by this variable, * and initialize the pointers in the array in the constructor. * @param body The place to write the self struct entries. - * @param variable The trigger variable (Timer, Action, or Input). + * @param variable The trigger variable (Timer, Watchdog, Action, or Input). * @param triggerMap A map from Variables to a list of the reaction indices * triggered by the variable. * @param constructorCode The place to write the constructor code. diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 3c9568699c..ece414ac36 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -128,7 +128,7 @@ public static String generateFunction(String header, String init, Watchdog watch function.prSourceLineNumber(watchdog.getCode()); function.pr(ASTUtils.toText(watchdog.getCode())); //FIXME: will need to lf_schedule instead - // function.pr("lf_set("+watchdog.getName()+", 1);"); + function.pr("_lf_schedule((*"+watchdog.getName()+").trigger, 0, NULL);"); function.unindent(); function.pr("}"); return function.toString(); @@ -173,7 +173,8 @@ public static void generateWatchdogStruct( "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", "self->_lf_watchdog_"+watchdogName+".thread_active = false;", // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", - "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";" + "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";", + "self->_lf_watchdog_"+watchdogName+".trigger = &(self->_lf__"+watchdogName+");" )); // constructorCode.pr("#endif"); // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index df88d23d73..fdac093c49 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -58,8 +58,8 @@ main reactor { self->count++; =} reaction(shutdown) {= - if (self->count != 4) { - lf_print_error_and_exit("Watchdog produced output %d times. Expected 4.", self->count); + if (self->count != 5) { + lf_print_error_and_exit("Watchdog produced output %d times. Expected 5.", self->count); } =} } From ad9a226e83590079fa07d66644da4bce44ca7f8c Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Thu, 6 Apr 2023 21:00:16 +0500 Subject: [PATCH 109/709] [C-Generics] Basic Support for Contained Reactors Signed-off-by: mkhubaibumer --- org.lflang/src/org/lflang/ASTUtils.java | 6 ++- org.lflang/src/org/lflang/cli/Lfc.java | 2 + .../org/lflang/generator/ReactorInstance.java | 43 +++++++++++++--- .../org/lflang/generator/c/CGenerator.java | 26 +++++----- .../generator/c/CReactionGenerator.java | 49 ++++++++++--------- .../lflang/generator/c/CStateGenerator.java | 12 ++--- .../src/org/lflang/generator/c/CTypes.java | 2 +- .../src/org/lflang/generator/c/CUtil.java | 2 +- .../c/InteractingContainedReactors.java | 3 +- 9 files changed, 90 insertions(+), 55 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index ed9daf5def..558e262a59 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -58,7 +58,9 @@ import org.lflang.ast.ToText; import org.lflang.generator.CodeMap; import org.lflang.generator.InvalidSourceException; +import org.lflang.generator.NamedInstance; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.Assignment; import org.lflang.lf.AttrParm; @@ -899,12 +901,12 @@ public static boolean isFloat(String literal) { return true; } - /** + /** * Report whether the given code is an integer number or not. * @param code AST node to inspect. * @return True if the given code is an integer, false otherwise. */ - public static boolean isInteger(Code code) { + public static boolean isInteger(Code code) { return isInteger(toText(code)); } diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index 489e9cd2f4..a510a7f2d5 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -18,6 +18,7 @@ import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.generator.MainContext; +import org.lflang.generator.ReactorInstance; import com.google.inject.Inject; @@ -201,6 +202,7 @@ private void invokeGenerator( try { this.generator.generate(resource, this.fileAccess, context); + ReactorInstance.clearReactorInstanceMap(); } catch (Exception e) { reporter.printFatalErrorAndExit("Error running generator", e); } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 0a5c9e0b85..6252b95a28 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -33,10 +33,9 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; -import org.eclipse.emf.ecore.util.EcoreUtil; - import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; @@ -50,7 +49,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; -import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; import org.lflang.lf.Output; import org.lflang.lf.Parameter; @@ -60,13 +58,10 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.Timer; -import org.lflang.lf.Type; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; -import com.google.common.collect.ImmutableMap; - /** * Representation of a compile-time instance of a reactor. @@ -165,6 +160,39 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re public final TypeParameterizedReactor tpr; + private static final HashMap gReactorInstancesMap = new HashMap<>(); + + ////////////////////////////////////////////////////// + //// Static methods. + + /** Map {@link ReactorInstance} against achievable hashcode from {@link Reactor} */ + public static void mapReactorInstance(Reactor r, ReactorInstance i) { + gReactorInstancesMap.put(computeHash(r, i), i); + } + + /** Get {@link ReactorInstance} for supplied {@link Reactor} */ + public static ReactorInstance getReactorInstance(Reactor r) { + var wrapper = new Object() { + ReactorInstance ins = null; + }; + gReactorInstancesMap.forEach((hash, i) -> { + if (Objects.equals(hash, computeHash(r, i))) { + wrapper.ins = i; + } + }); + return wrapper.ins; + } + + /** Clears out the cache of ReactorInstance for next LF processing */ + public static void clearReactorInstanceMap() { + gReactorInstancesMap.clear(); + } + + /** Calculates Unique HashCode for the key of ReactorInstanceMap*/ + private static Integer computeHash(Reactor r, ReactorInstance i) { + return Math.abs(r.hashCode() * 37 + r.getTypeParms().hashCode() + i.tpr.hashCode()); + } + ////////////////////////////////////////////////////// //// Public methods. @@ -778,6 +806,9 @@ public ReactorInstance( this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); this.tpr = new TypeParameterizedReactor(definition); + // Add ReactorInstance against achievable hashcode from Reactor + ReactorInstance.mapReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), this); + // check for recursive instantiation var currentParent = parent; var foundSelfAsParent = false; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index d0791230be..fb16baa559 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -42,8 +42,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Locale; -import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -86,7 +84,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; -import org.lflang.lf.Code; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Mode; @@ -97,7 +94,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; -import org.lflang.lf.Type; import org.lflang.lf.Variable; import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; @@ -1255,7 +1251,7 @@ private void generateInteractingContainedReactors( var contained = new InteractingContainedReactors(tpr.r()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { - Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); + var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass())); // First define an _width variable in case it is a bank. var array = ""; var width = -2; @@ -1267,11 +1263,11 @@ private void generateInteractingContainedReactors( } // NOTE: The following needs to be done for each instance // so that the width can be parameter, not in the constructor. - // Here, we conservatively use a width that is the largest of all isntances. + // Here, we conservatively use a width that is the largest of all instances. constructorCode.pr(String.join("\n", "// Set the _width variable for all cases. This will be -2", "// if the reactor is not a bank of reactors.", - "self->_lf_"+containedReactor.getName()+"_width = "+width+";" + "self->_lf_"+containedReactorType.tpr.getName()+"_width = "+width+";" )); // Generate one struct for each contained reactor that interacts. @@ -1283,12 +1279,12 @@ private void generateInteractingContainedReactors( // to be malloc'd at initialization. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); + body.pr(port, variableStructType(port, containedReactorType.tpr, false)+" "+port.getName()+";"); } else { // Is a multiport. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + variableStructType(port, containedReactorType.tpr, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1298,13 +1294,13 @@ private void generateInteractingContainedReactors( // self struct of the container. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); + body.pr(port, variableStructType(port, containedReactorType.tpr, false)+"* "+port.getName()+";"); } else { // Is a multiport. // Here, we will use an array of pointers. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + variableStructType(port, containedReactorType.tpr, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1312,10 +1308,10 @@ private void generateInteractingContainedReactors( var reactorIndex = ""; if (containedReactor.getWidthSpec() != null) { reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+tpr.getName()+"_width; reactor_index++) {"); + constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactorType.tpr.getName()+"_width; reactor_index++) {"); constructorCode.indent(); } - var portOnSelf = "self->_lf_"+tpr.getName()+reactorIndex+"."+port.getName(); + var portOnSelf = "self->_lf_"+containedReactorType.tpr.getName()+reactorIndex+"."+port.getName(); constructorCode.pr( port, @@ -1360,8 +1356,8 @@ private void generateInteractingContainedReactors( } body.unindent(); body.pr(String.join("\n", - "} _lf_"+tpr.getName()+array+";", - "int _lf_"+tpr.getName()+"_width;" + "} _lf_"+containedReactorType.tpr.getName()+array+";", + "int _lf_"+containedReactorType.tpr.getName()+"_width;" )); } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index d54e54d5ee..28791b9cd1 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -14,9 +14,9 @@ import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetConfig; -import org.lflang.TargetProperty.Platform; import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.BuiltinTriggerRef; @@ -30,7 +30,6 @@ import org.lflang.lf.Port; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; import org.lflang.lf.Timer; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; @@ -206,18 +205,19 @@ public static String generateInitializationForReaction(String body, // Before the reaction initialization, // generate the structs used for communication to and from contained reactors. for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { + var containedReactorType = ReactorInstance.getReactorInstance((Reactor) containedReactor.getReactorClass()); String array = ""; if (containedReactor.getWidthSpec() != null) { - String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); + String containedReactorWidthVar = generateWidthVariable(containedReactorType.tpr.getName()); code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); // Windows does not support variables in arrays declared on the stack, // so we use the maximum size over all bank members. array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; } code.pr(String.join("\n", - "struct "+containedReactor.getName()+" {", + "struct "+containedReactorType.getName()+" {", " "+fieldsForStructsForContainedReactors.get(containedReactor)+"", - "} "+containedReactor.getName()+array+";" + "} "+containedReactorType.getName()+array+";" )); } // Next generate all the collected setup code. @@ -348,14 +348,15 @@ private static void generateVariablesForSendingToContainedReactors( Instantiation definition, Input input ) { - // TODO: Get reactorInstance or TPR from Instantiation CodeBuilder structBuilder = structs.get(definition); if (structBuilder == null) { structBuilder = new CodeBuilder(); structs.put(definition, structBuilder); } - String inputStructType = CGenerator.variableStructType(input, ASTUtils.toDefinition(definition.getReactorClass()), false); - String defName = definition.getName(); + var reactorInstance = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(definition.getReactorClass())); + String inputStructType = CGenerator.variableStructType(input, reactorInstance.tpr, false); + String defName = reactorInstance.getName(); + String subName = reactorInstance.tpr.getName(); String defWidth = generateWidthVariable(defName); String inputName = input.getName(); String inputWidth = generateWidthVariable(inputName); @@ -366,12 +367,12 @@ private static void generateVariablesForSendingToContainedReactors( // Contained reactor is a bank. builder.pr(String.join("\n", "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", - " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", + " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+subName+"[bankIndex]."+inputName+");", "}" )); } else { // Contained reactor is not a bank. - builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); + builder.pr(defName+"."+inputName+" = &(self->_lf_"+subName+"."+inputName+");"); } } else { // Contained reactor's input is a multiport. @@ -384,14 +385,14 @@ private static void generateVariablesForSendingToContainedReactors( if (definition.getWidthSpec() != null) { builder.pr(String.join("\n", "for (int _i = 0; _i < self->_lf_"+defWidth+"; _i++) {", - " "+defName+"[_i]."+inputName+" = self->_lf_"+defName+"[_i]."+inputName+";", - " "+defName+"[_i]."+inputWidth+" = self->_lf_"+defName+"[_i]."+inputWidth+";", + " "+defName+"[_i]."+inputName+" = self->_lf_"+subName+"[_i]."+inputName+";", + " "+defName+"[_i]."+inputWidth+" = self->_lf_"+subName+"[_i]."+inputWidth+";", "}" )); } else { builder.pr(String.join("\n", - defName+"."+inputName+" = self->_lf_"+defName+"."+inputName+";", - defName+"."+inputWidth+" = self->_lf_"+defName+"."+inputWidth+";" + defName+"."+inputName+" = self->_lf_"+subName+"."+inputName+";", + defName+"."+inputWidth+" = self->_lf_"+subName+"."+inputWidth+";" )); } } @@ -421,14 +422,15 @@ private static void generatePortVariablesInReaction( } else { // port is an output of a contained reactor. Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, tpr, false); + String portStructType = CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass())).getTypeParameterizedReactor(), false); CodeBuilder structBuilder = structs.get(port.getContainer()); if (structBuilder == null) { structBuilder = new CodeBuilder(); structs.put(port.getContainer(), structBuilder); } - String reactorName = port.getContainer().getName(); + String reactorName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass())).tpr.getName(); + String subName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass())).getName(); String reactorWidth = generateWidthVariable(reactorName); String outputName = output.getName(); String outputWidth = generateWidthVariable(outputName); @@ -450,21 +452,21 @@ private static void generatePortVariablesInReaction( // Output is in a bank. builder.pr(String.join("\n", "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+reactorName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", + " "+subName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", "}" )); if (ASTUtils.isMultiport(output)) { builder.pr(String.join("\n", "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+reactorName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", + " "+subName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", "}" )); } } else { // Output is not in a bank. - builder.pr(reactorName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); + builder.pr(subName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); if (ASTUtils.isMultiport(output)) { - builder.pr(reactorName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); + builder.pr(subName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); } } } @@ -641,9 +643,10 @@ public static String generateOutputVariablesInReaction( // The container of the output may be a contained reactor or // the reactor containing the reaction. String outputStructType = (effect.getContainer() == null) ? - CGenerator.variableStructType(output, tpr, false) - : - CGenerator.variableStructType(output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); + CGenerator.variableStructType(output, tpr, false) + : + CGenerator.variableStructType(output, ReactorInstance.getReactorInstance( + ASTUtils.toDefinition(effect.getContainer().getReactorClass())).getTypeParameterizedReactor(), false); if (!ASTUtils.isMultiport(output)) { // Output port is not a multiport. return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index fc66036511..70d21a1f23 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -15,7 +15,7 @@ public class CStateGenerator { /** * Generate code for state variables of a reactor in the form "stateVar.type stateVar.name;" - * @param reactor The reactor + * @param reactor {@link TypeParameterizedReactor} * @param types A helper object for types */ public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { @@ -34,10 +34,10 @@ public static String generateDeclarations(TypeParameterizedReactor reactor, CTyp * this way, and there is no way to tell whether the type of the array * is a struct. * - * @param instance - * @param stateVar - * @param mode - * @return + * @param instance {@link ReactorInstance} + * @param stateVar {@link StateVar} + * @param mode {@link ModeInstance} + * @return String */ public static String generateInitializer( ReactorInstance instance, @@ -92,7 +92,7 @@ private static String generateModalReset( return ""; } var modeRef = "&"+CUtil.reactorRef(mode.getParent())+"->_lf__modes["+mode.getParent().modes.indexOf(mode)+"]"; - var type = types.getTargetType(ASTUtils.getInferredType(stateVar)); + var type = CUtil.getConcreteType(instance.tpr, types.getTargetType(ASTUtils.getInferredType(stateVar))); if (ASTUtils.isOfTimeType(stateVar) || ASTUtils.isParameterized(stateVar) && diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/src/org/lflang/generator/c/CTypes.java index ebb9c894f4..361046c27a 100644 --- a/org.lflang/src/org/lflang/generator/c/CTypes.java +++ b/org.lflang/src/org/lflang/generator/c/CTypes.java @@ -65,7 +65,7 @@ public String getTargetUndefinedType() { * as a type, and {@code int*} must be used instead, except when initializing * a variable using a static initializer, as in {@code int[] foo = {1, 2, 3};}. * When initializing a variable using a static initializer, use - * {@link #getVariableDeclaration(InferredType, String, boolean)} instead. + * {@link #getVariableDeclaration(TypeParameterizedReactor, InferredType, String, boolean)} instead. * @param type The type. */ @Override diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 87f75133dd..3cae52d931 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -469,7 +469,7 @@ public static String reactorRefNested(ReactorInstance reactor) { * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. */ public static String reactorRefNested(ReactorInstance reactor, String runtimeIndex, String bankIndex) { - String result = reactorRef(reactor.getParent(), runtimeIndex) + "->_lf_" + reactor.getName(); + String result = reactorRef(reactor.getParent(), runtimeIndex) + "->_lf_" + reactor.tpr.getName(); if (reactor.isBank()) { // Need the bank index not the runtimeIndex. if (bankIndex == null) bankIndex = bankIndex(reactor); diff --git a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java index bc4d6893a1..ae6b37437f 100644 --- a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java +++ b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java @@ -8,12 +8,14 @@ import org.lflang.ASTUtils; import org.lflang.federated.generator.FederateInstance; +import org.lflang.generator.NamedInstance; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; +import org.lflang.lf.ReactorDecl; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; @@ -101,7 +103,6 @@ public InteractingContainedReactors(Reactor reactor) { * @param port The port. */ private List addPort(Instantiation containedReactor, Port port) { - var parent = containedReactor.eContainer(); // Get or create the entry for the containedReactor. var containedReactorEntry = portsByContainedReactor.computeIfAbsent( containedReactor, From a35208f360e02f4ad4788ba1589d8717ca72f8d8 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 10 Apr 2023 13:52:29 -0700 Subject: [PATCH 110/709] tried removing boolean from self-base_t struct, failed, everything working now --- .../org/lflang/generator/c/CGenerator.java | 5 ++ .../generator/c/CWatchdogGenerator.java | 22 +------ test/Python/src/PyWatchdog.lf | 66 +++++++++++++++++++ 3 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 test/Python/src/PyWatchdog.lf diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b54c77f6ab..5e94fe55fb 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1243,6 +1243,11 @@ private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { // Next, generate fields for modes CModesGenerator.generateDeclarations(reactor, body, constructorCode); + // constructorCode.pr(reactor, String.join("\n", + // "#ifdef LF_THREADED", + // " self->base->watchdog_mutex = NULL;", + // "#endif")); + // The first field has to always be a pointer to the list of // of allocated memory that must be freed when the reactor is freed. // This means that the struct can be safely cast to self_base_t. diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index ece414ac36..9163883962 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -124,11 +124,9 @@ public static String generateFunction(String header, String init, Watchdog watch var function = new CodeBuilder(); function.pr(header + " {"); function.indent(); - function.pr(init); + function.pr(init);function.pr("_lf_schedule((*"+watchdog.getName()+").trigger, 0, NULL);"); function.prSourceLineNumber(watchdog.getCode()); function.pr(ASTUtils.toText(watchdog.getCode())); - //FIXME: will need to lf_schedule instead - function.pr("_lf_schedule((*"+watchdog.getName()+").trigger, 0, NULL);"); function.unindent(); function.pr("}"); return function.toString(); @@ -147,25 +145,12 @@ public static void generateWatchdogStruct( for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { String watchdogName = watchdog.getName(); - // Create pointer to the watchdog_t struct - // WATCHDOG QUESTION 2: Why need to put object at beginning of - // `.pr` func call? - - // WATCHDOG QUESTION 3: Is the space for this struct automatically allocated - // through `_lf_new_reactor`? `_lf__startup_reaction` is also a pointer in self struct - // but does not seem to have a separate allocation call. - body.pr(watchdog, "watchdog_t _lf_watchdog_"+watchdogName+";"); - // WATCHDOG QUESTION 4: Not sure if this is correct, may need to use - // 'getTargetTime' instead. watchdog timeout is listed as "Expression" - // in the grammar, so I'm not sure if it is reading the timeout as - // a Time class or TimeValue class. - // var min_expiration = GeneratorBase.timeInTargetLanguage(watchdog.getTimeout()); + body.pr(watchdog, "watchdog_t _lf_watchdog_"+watchdogName+";"); // watchdog function name var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); // Set values of watchdog_t struct in the reactor's constructor - // WATCHDOG QUESTION 5: should I be defining these in the constructor of the reactor? //FIXME: update parameters // constructorCode.pr("#ifdef LF_THREADED"); constructorCode.pr(watchdog, String.join("\n", @@ -176,8 +161,7 @@ public static void generateWatchdogStruct( "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";", "self->_lf_watchdog_"+watchdogName+".trigger = &(self->_lf__"+watchdogName+");" )); - // constructorCode.pr("#endif"); - // WATCHDOG QUESTION 6: should I be initializing mutex in this constructor? + } } diff --git a/test/Python/src/PyWatchdog.lf b/test/Python/src/PyWatchdog.lf new file mode 100644 index 0000000000..a89cf0d7de --- /dev/null +++ b/test/Python/src/PyWatchdog.lf @@ -0,0 +1,66 @@ +/** + * Test watchdog. + * This test starts a watchdog timer of 150ms every 100ms. + * Half the time, it then sleeps after starting the watchdog so that + * the watchdog expires. There should be a total of five watchdog + * expirations. + * @author Benjamin Asch + * @author Edward A. Lee + */ + +target Python { + timeout: 1100ms, + threading: true +} + +reactor Watcher(timeout(150 ms)) { + timer t(100 ms, 100 ms) // Offset ameliorates startup time. + output d // Produced if watchdog triggers. + state alternating(False) + state count(0) + + watchdog poodle(timeout) {= + p = lf_time_physical_elapsed() - lf_time_logical_elapsed() + lf_print("Watchdog timed out! Lag: "+p+" (too late by "+(p - self.timeout)+" ns)") + self.count += 1 + =} + + reaction(t) -> poodle, d {= + lf_watchdog_start(poodle, 0) + lf_print("Watchdog started at physical time "+lf_time_physical_elapsed()) + lf_print("Will expire at "+lf_time_logical_elapsed() + self.timeout) + if (self.alternating) { + lf_sleep(160 ms) + } + self.alternating = not self.alternating + =} + + reaction(poodle) -> d {= + lf_print("Reaction poodle was called.") + d.set(1) + =} + + reaction(shutdown) -> poodle {= + _lf_watchdog_stop(poodle) + if (self.count != 5) { + lf_print_error_and_exit("Watchdog expired "+self.count+" times. Expected 5.") + } + =} +} + +main reactor { + logical action a + state count(0) + w = new Watcher() + + reaction(w.d) {= + lf_print("*** Watcher reactor produced an output.") + self.count += 1 + =} + + reaction(shutdown) {= + if (self.count != 5) { + lf_print_error_and_exit("Watchdog produced output "+self.count+" times. Expected 5.") + } + =} +} From 9f32cefab1dc30c0ed2f72a3fbf5b5d11089090d Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Tue, 11 Apr 2023 18:51:22 +0500 Subject: [PATCH 111/709] [C-Generic] Contained Generic Reactor This commit fixes the issues with having multiple contained generic reactors Signed-off-by: mkhubaibumer --- .../org/lflang/generator/ReactorInstance.java | 23 +++++++------------ .../org/lflang/generator/c/CGenerator.java | 2 +- .../generator/c/CReactionGenerator.java | 12 +++++----- .../generator/c/TypeParameterizedReactor.java | 1 - 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 6252b95a28..46ff5b1a73 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -166,21 +166,14 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re //// Static methods. /** Map {@link ReactorInstance} against achievable hashcode from {@link Reactor} */ - public static void mapReactorInstance(Reactor r, ReactorInstance i) { - gReactorInstancesMap.put(computeHash(r, i), i); + public static void mapReactorInstance(Reactor r, ReactorInstance i, final String n) { + gReactorInstancesMap.put(computeHash(r, n), i); } /** Get {@link ReactorInstance} for supplied {@link Reactor} */ - public static ReactorInstance getReactorInstance(Reactor r) { - var wrapper = new Object() { - ReactorInstance ins = null; - }; - gReactorInstancesMap.forEach((hash, i) -> { - if (Objects.equals(hash, computeHash(r, i))) { - wrapper.ins = i; - } - }); - return wrapper.ins; + public static ReactorInstance getReactorInstance(Reactor r, final String n) { + var instance = gReactorInstancesMap.get(computeHash(r, n)); + return instance; } /** Clears out the cache of ReactorInstance for next LF processing */ @@ -189,8 +182,8 @@ public static void clearReactorInstanceMap() { } /** Calculates Unique HashCode for the key of ReactorInstanceMap*/ - private static Integer computeHash(Reactor r, ReactorInstance i) { - return Math.abs(r.hashCode() * 37 + r.getTypeParms().hashCode() + i.tpr.hashCode()); + private static Integer computeHash(Reactor r, final String n) { + return Math.abs(r.hashCode() * 37 + r.getTypeParms().hashCode() + n.hashCode()); } ////////////////////////////////////////////////////// @@ -807,7 +800,7 @@ public ReactorInstance( this.tpr = new TypeParameterizedReactor(definition); // Add ReactorInstance against achievable hashcode from Reactor - ReactorInstance.mapReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), this); + ReactorInstance.mapReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), this, definition.getName()); // check for recursive instantiation var currentParent = parent; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index fb16baa559..abbaee4428 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1251,7 +1251,7 @@ private void generateInteractingContainedReactors( var contained = new InteractingContainedReactors(tpr.r()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { - var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass())); + var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass()), containedReactor.getName()); // First define an _width variable in case it is a bank. var array = ""; var width = -2; diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 28791b9cd1..ead750738d 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -205,7 +205,7 @@ public static String generateInitializationForReaction(String body, // Before the reaction initialization, // generate the structs used for communication to and from contained reactors. for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - var containedReactorType = ReactorInstance.getReactorInstance((Reactor) containedReactor.getReactorClass()); + var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass()), containedReactor.getName()); String array = ""; if (containedReactor.getWidthSpec() != null) { String containedReactorWidthVar = generateWidthVariable(containedReactorType.tpr.getName()); @@ -353,7 +353,7 @@ private static void generateVariablesForSendingToContainedReactors( structBuilder = new CodeBuilder(); structs.put(definition, structBuilder); } - var reactorInstance = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(definition.getReactorClass())); + var reactorInstance = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), definition.getName()); String inputStructType = CGenerator.variableStructType(input, reactorInstance.tpr, false); String defName = reactorInstance.getName(); String subName = reactorInstance.tpr.getName(); @@ -422,15 +422,15 @@ private static void generatePortVariablesInReaction( } else { // port is an output of a contained reactor. Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass())).getTypeParameterizedReactor(), false); + String portStructType = CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).getTypeParameterizedReactor(), false); CodeBuilder structBuilder = structs.get(port.getContainer()); if (structBuilder == null) { structBuilder = new CodeBuilder(); structs.put(port.getContainer(), structBuilder); } - String reactorName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass())).tpr.getName(); - String subName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass())).getName(); + String reactorName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).tpr.getName(); + String subName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).getName(); String reactorWidth = generateWidthVariable(reactorName); String outputName = output.getName(); String outputWidth = generateWidthVariable(outputName); @@ -646,7 +646,7 @@ public static String generateOutputVariablesInReaction( CGenerator.variableStructType(output, tpr, false) : CGenerator.variableStructType(output, ReactorInstance.getReactorInstance( - ASTUtils.toDefinition(effect.getContainer().getReactorClass())).getTypeParameterizedReactor(), false); + ASTUtils.toDefinition(effect.getContainer().getReactorClass()), effect.getContainer().getName()).getTypeParameterizedReactor(), false); if (!ASTUtils.isMultiport(output)) { // Output port is not a multiport. return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index a903d5e9ae..df5cd4444b 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -3,7 +3,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.stream.Collectors; import org.lflang.ASTUtils; From 272dbaa15903da0487c097c37fd9795f20d865f1 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Tue, 11 Apr 2023 19:00:42 +0500 Subject: [PATCH 112/709] Update documentation --- .../org/lflang/generator/ReactorInstance.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 46ff5b1a73..f0211ab22e 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -160,20 +160,27 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re public final TypeParameterizedReactor tpr; + /** HashMap containing {@link ReactorInstance} against hashCode achievable from Reactor */ private static final HashMap gReactorInstancesMap = new HashMap<>(); ////////////////////////////////////////////////////// //// Static methods. - /** Map {@link ReactorInstance} against achievable hashcode from {@link Reactor} */ - public static void mapReactorInstance(Reactor r, ReactorInstance i, final String n) { - gReactorInstancesMap.put(computeHash(r, n), i); + /** Map {@link ReactorInstance} against achievable hashcode from {@link Reactor} + * @param reactor The Reactor + * @param reactorInstance The ReactorInstance for the specified Reactor + * @param defName definition Name for the specified Reactor + * */ + public static void mapReactorInstance(Reactor reactor, ReactorInstance reactorInstance, final String defName) { + gReactorInstancesMap.put(computeHash(reactor, defName), reactorInstance); } - /** Get {@link ReactorInstance} for supplied {@link Reactor} */ - public static ReactorInstance getReactorInstance(Reactor r, final String n) { - var instance = gReactorInstancesMap.get(computeHash(r, n)); - return instance; + /** Get {@link ReactorInstance} for supplied {@link Reactor} + * @param reactor The reactor + * @param defName definition Name for the specified reactor + * */ + public static ReactorInstance getReactorInstance(Reactor reactor, final String defName) { + return gReactorInstancesMap.get(computeHash(reactor, defName)); } /** Clears out the cache of ReactorInstance for next LF processing */ @@ -181,7 +188,10 @@ public static void clearReactorInstanceMap() { gReactorInstancesMap.clear(); } - /** Calculates Unique HashCode for the key of ReactorInstanceMap*/ + /** Calculates Unique HashCode for the key of ReactorInstanceMap + * @param r The reactor + * @param n definition Name for the Reactor + * */ private static Integer computeHash(Reactor r, final String n) { return Math.abs(r.hashCode() * 37 + r.getTypeParms().hashCode() + n.hashCode()); } From 571333f75a3270a4840da7c27a713dda94dd7790 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 13 Apr 2023 23:46:38 -0700 Subject: [PATCH 113/709] Add spurious dependency example. --- test/C/src/federated/SpuriousDependency.lf | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/C/src/federated/SpuriousDependency.lf diff --git a/test/C/src/federated/SpuriousDependency.lf b/test/C/src/federated/SpuriousDependency.lf new file mode 100644 index 0000000000..fefadc4617 --- /dev/null +++ b/test/C/src/federated/SpuriousDependency.lf @@ -0,0 +1,33 @@ +target C + +reactor Passthrough { + input in: int + output out: int + reaction(in) -> out {= + lf_print("Hello from passthrough"); + lf_set(out, in->value); + =} +} + +reactor Twisty { + input in0: int + input in1: int + output out0: int + output out1: int + p0 = new Passthrough() + p1 = new Passthrough() + in0 -> p0.in + p0.out -> out0 + in1 -> p1.in + p1.out -> out1 +} + +federated reactor { + t0 = new Twisty() + t1 = new Twisty() + t0.out1 -> t1.in0 + t1.out1 -> t0.in0 + reaction(startup) -> t0.in1 {= + lf_set(t0.in1, 0); + =} +} From 5773b8919f46cb2590adb0516ae4e32696314712 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 14 Apr 2023 00:30:20 -0700 Subject: [PATCH 114/709] created check for runtime, and removed local one for each class --- .../org/lflang/generator/GeneratorBase.java | 24 +++++++++++++++++++ .../org/lflang/generator/c/CGenerator.java | 9 ++++++- .../generator/python/PythonGenerator.java | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ba39a94d9f..ac141b9259 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -165,6 +165,12 @@ public abstract class GeneratorBase extends AbstractLFValidator { */ public boolean hasDeadlines = false; + /** + * Indicates whether the program has any watchdogs. + * This is used to check for support. + */ + public boolean hasWatchdogs = false; + // ////////////////////////////////////////// // // Private fields. @@ -293,6 +299,10 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { // Check for existence and support of modes hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); checkModalReactorSupport(false); + + // Check for the existence and support of watchdogs + hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); + checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); additionalPostProcessingForModes(); } @@ -429,6 +439,20 @@ protected void checkModalReactorSupport(boolean isSupported) { } } + /** + * Checks whether watchdogs are present and are supported. + * @param isSupported indicates whether or not this is a supported target + * and whether or not it is a threaded runtime. + */ + protected void checkWatchdogSupport(boolean isSupported) { + if (hasWatchdogs && !isSupported) { + errorReporter.reportError( + "Watchdogs are currently only supported for threaded programs in the C target." + ); + } + } + + /** * Finds and transforms connections into forwarding reactions iff the connections have the same destination as other * connections or reaction in mutually exclusive modes. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 5e94fe55fb..07d77cdbd5 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -446,6 +446,7 @@ protected boolean isOSCompatible() { /** Returns false if watchdogs exist and are * unsupported in this context. * Otherwise, return true. + * (DEPRECATED) Alternative implemented in GeneratorBase */ protected boolean isWatchdogCompatible() { if (hasWatchdogs() && !targetConfig.threading) { @@ -454,6 +455,12 @@ protected boolean isWatchdogCompatible() { ); return false; } + if (hasWatchdogs() && CCppMode) { + //FIXME: check to see if watchdogs work in CCppMode cases + errorReporter.reportError( + "Watchdogs are not currently supported in the CCpp target." + ); + } return true; } @@ -471,7 +478,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { super.doGenerate(resource, context); if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; if (!isOSCompatible()) return; // Incompatible OS and configuration - if (!isWatchdogCompatible()) return; + // if (!isWatchdogCompatible()) return; // Perform set up that does not generate code setUpGeneralParameters(); diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 3f82f20016..2767a05b9c 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -62,6 +62,7 @@ import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; +import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; From 801a3321e1ad86833de3c695af6133c5e2d55097 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Fri, 14 Apr 2023 17:10:56 +0900 Subject: [PATCH 115/709] Test SimpleFederatedAuthenticatd CI test --- .../C/src/federated/{failing => }/SimpleFederatedAuthenticated.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/federated/{failing => }/SimpleFederatedAuthenticated.lf (100%) diff --git a/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf b/test/C/src/federated/SimpleFederatedAuthenticated.lf similarity index 100% rename from test/C/src/federated/failing/SimpleFederatedAuthenticated.lf rename to test/C/src/federated/SimpleFederatedAuthenticated.lf From ee610f060f679fc74f275888999071e31070ed6b Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Fri, 14 Apr 2023 16:22:25 +0500 Subject: [PATCH 116/709] [C-Generics] Contained Generic Reactor Update to support Templated Initialization of Generic Contained Reactor with `typeArgs` from Parent Reactor Signed-off-by: mkhubaibumer --- org.lflang/src/org/lflang/ASTUtils.java | 16 +++++++ .../org/lflang/generator/ReactorInstance.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 45 ++++++++++++++----- .../c/CReactorHeaderFileGenerator.java | 4 +- .../src/org/lflang/generator/c/CUtil.java | 8 +--- .../generator/c/TypeParameterizedReactor.java | 5 ++- .../python/PythonReactionGenerator.java | 12 ++--- 7 files changed, 63 insertions(+), 29 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 558e262a59..8f3cb710aa 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -60,6 +60,7 @@ import org.lflang.generator.InvalidSourceException; import org.lflang.generator.NamedInstance; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.c.CUtil; import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.Assignment; @@ -381,6 +382,21 @@ public static List allInstantiations(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); } + /** + * Given a reactor Class, returns a set of include names for + * interacting reactors which includes all instantiations of base class that it extends + * + * @param r Reactor Class + * */ + public static HashSet allIncludes(Reactor r) { + var set = new HashSet(); + for (var i : allInstantiations(r)) + { + set.add(CUtil.getName(ReactorInstance.getReactorInstance(ASTUtils.toDefinition(i.getReactorClass()), i.getName()).tpr)); + } + return set; + } + public static List allChildInstances(Reactor definition, ErrorReporter reporter) { return allInstantiations(definition).stream().map(it -> new ReactorInstance( it, diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index f0211ab22e..ccde52a1ff 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -158,7 +158,7 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re /** Indicator that this reactor has itself as a parent, an error condition. */ public final boolean recursive; - public final TypeParameterizedReactor tpr; + public TypeParameterizedReactor tpr; /** HashMap containing {@link ReactorInstance} against hashCode achievable from Reactor */ private static final HashMap gReactorInstancesMap = new HashMap<>(); diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index abbaee4428..0a1c0d69cc 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -39,9 +39,11 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -94,11 +96,13 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; +import org.lflang.lf.Type; import org.lflang.lf.Variable; import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; /** @@ -922,12 +926,39 @@ public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { private void generateReactorDefinitions() throws IOException { var generatedReactors = new LinkedHashSet(); if (this.main != null) { + resolveTemplatedTypes(this.main, this.main.tpr); generateReactorChildren(this.main, generatedReactors); generateReactorClass(this.main.getTypeParameterizedReactor()); } // do not generate code for reactors that are not instantiated } + /** + * Recursively Resolve all Templated Types of child Reactors to their respective + * concrete types + * + * @param reactorInstance The Reactor Class + * @param parentTpr {@link TypeParameterizedReactor} of Parent + * */ + private void resolveTemplatedTypes(ReactorInstance reactorInstance, TypeParameterizedReactor parentTpr) { + for (var child : reactorInstance.children) { + if (parentTpr.typeArgs() != null) { + Map copy = new HashMap<>(); + child.tpr.typeArgs().forEach((literal, typename) -> { + var type = typename.getId(); + if (parentTpr.typeArgs().containsKey(type)) { + var basicType = parentTpr.typeArgs().get(type); + copy.put(literal, basicType); + } + }); + if (!copy.isEmpty()) { // If we found some templated-types update the tpr with new map + child.tpr = new TypeParameterizedReactor(child.tpr.r(), copy); + } + resolveTemplatedTypes(child, child.tpr); + } + } + } + private void generateHeaders() throws IOException { // Cannot delete existing header files directory because this would create a race condition in fed-gen FileUtil.copyDirectoryFromClassPath( @@ -935,9 +966,7 @@ private void generateHeaders() throws IOException { fileConfig.getIncludePath(), false ); -// for (var r : reactors) { - CReactorHeaderFileGenerator.doGenerate(types, this.main.tpr, fileConfig, this::generateAuxiliaryStructs, this::generateTopLevelPreambles); -// } + CReactorHeaderFileGenerator.doGenerate(types, this.main.tpr, fileConfig, this::generateAuxiliaryStructs, this::generateTopLevelPreambles); FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); } @@ -1030,7 +1059,6 @@ private void generateReactorClass(TypeParameterizedReactor tpr) throws IOExcepti header.pr(generateTopLevelPreambles(tpr.r())); generateUserPreamblesForReactor(tpr.r(), src); generateReactorClassBody(tpr, header, src); - tpr.typeArgs().entrySet().forEach(it -> header.pr("#undef " + it.getKey())); header.pr("#endif // " + guardMacro); FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" @@ -1060,10 +1088,8 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String "#undef " + literal + "\n" + "#endif // " + literal + "\n" + "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); - new HashSet<>(ASTUtils.allInstantiations(tpr.r())).stream() - .map(TypeParameterizedReactor::new).map(CUtil::getName) - .map(name -> "#include \"" + name + ".h\"") - .forEach(header::pr); + ASTUtils.allIncludes(tpr.r()).stream().map(name -> "#include \"" + + name + ".h\"").forEach(header::pr); } private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder header, CodeBuilder src) { @@ -1652,9 +1678,6 @@ public void processProtoFile(String filename) { public static String variableStructType(Variable variable, TypeParameterizedReactor tpr, boolean userFacing) { return (userFacing ? tpr.getName().toLowerCase() : CUtil.getName(tpr)) +"_"+variable.getName()+"_t"; } - public static String variableStructType(Variable variable, Reactor r, boolean userFacing) { - return (userFacing ? r.getName().toLowerCase() : CUtil.getName(r)) +"_"+variable.getName()+"_t"; - } /** * Construct a unique type for the struct of the specified diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 6bdb08f5a9..88a9e2e6cb 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -40,7 +40,7 @@ public static void doGenerate(CTypes types, TypeParameterizedReactor tpr, CFileC } private static String generateHeaderFile(CTypes types, TypeParameterizedReactor tpr, GenerateAuxiliaryStructs generator, String topLevelPreamble) { CodeBuilder builder = new CodeBuilder(); - appendIncludeGuard(builder, tpr.r()); + appendIncludeGuard(builder, tpr); builder.pr(topLevelPreamble); appendPoundIncludes(builder); appendSelfStruct(builder, types, tpr); @@ -52,7 +52,7 @@ private static String generateHeaderFile(CTypes types, TypeParameterizedReactor return builder.getCode(); } - private static void appendIncludeGuard(CodeBuilder builder, Reactor r) { + private static void appendIncludeGuard(CodeBuilder builder, TypeParameterizedReactor r) { String macro = CUtil.getName(r) + "_H"; builder.pr("#ifndef " + macro); builder.pr("#define " + macro); diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 3cae52d931..9bfac8e7ba 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -28,6 +28,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.File; import java.io.IOException; +import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -154,13 +155,6 @@ public static String getName(TypeParameterizedReactor reactor) { } return name; } - public static String getName(Reactor reactor) { - String name = reactor.getName().toLowerCase() + reactor.hashCode(); - if (reactor.isMain()) { - return name + "_main"; - } - return name; - } /** * Return a reference to the specified port. diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index df5cd4444b..c04e1ac247 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -18,14 +18,15 @@ public TypeParameterizedReactor(Instantiation i) { this(ASTUtils.toDefinition(i.getReactorClass()), addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); } - private static ImmutableMap addTypeArgs(Instantiation instantiation, Reactor r) { + + private static Map addTypeArgs(Instantiation instantiation, Reactor r) { HashMap ret = new HashMap<>(); if (instantiation.getTypeArgs() != null) { for (int i = 0; i < r.getTypeParms().size(); i++) { ret.put(r.getTypeParms().get(i).getLiteral(), instantiation.getTypeArgs().get(i)); } } - return ImmutableMap.copyOf(ret); + return ret; // ImmutableMap.copyOf(ret); } public String getName() { diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 62dd65ff5f..e7bf570385 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -40,7 +40,7 @@ public class PythonReactionGenerator { * @param reactionIndex The index of the reaction * @param pyObjects CPython related objects */ - public static String generateCPythonReactionCaller(Reactor reactor, + public static String generateCPythonReactionCaller(TypeParameterizedReactor reactor, int reactionIndex, List pyObjects, String inits) { @@ -55,7 +55,7 @@ public static String generateCPythonReactionCaller(Reactor reactor, * @param reactionIndex The index of the reaction * @param pyObjects CPython related objects */ - public static String generateCPythonDeadlineCaller(Reactor r, + public static String generateCPythonDeadlineCaller(TypeParameterizedReactor r, int reactionIndex, List pyObjects) { String pythonFunctionName = generatePythonDeadlineFunctionName(reactionIndex); @@ -69,7 +69,7 @@ public static String generateCPythonDeadlineCaller(Reactor r, * @param reactionIndex The index of the reaction * @param pyObjects CPython related objects */ - public static String generateCPythonSTPCaller(Reactor r, + public static String generateCPythonSTPCaller(TypeParameterizedReactor r, int reactionIndex, List pyObjects) { String pythonFunctionName = generatePythonSTPFunctionName(reactionIndex); @@ -150,7 +150,7 @@ public static String generateCReaction( code.pr(generateFunction( CReactionGenerator.generateReactionFunctionHeader(tpr, reactionIndex), cInit, reaction.getCode(), - generateCPythonReactionCaller(r, reactionIndex, pyObjects, cPyInit) + generateCPythonReactionCaller(tpr, reactionIndex, pyObjects, cPyInit) )); // Generate code for the STP violation handler, if there is one. @@ -158,7 +158,7 @@ public static String generateCReaction( code.pr(generateFunction( CReactionGenerator.generateStpFunctionHeader(tpr, reactionIndex), cInit, reaction.getStp().getCode(), - generateCPythonSTPCaller(r, reactionIndex, pyObjects) + generateCPythonSTPCaller(tpr, reactionIndex, pyObjects) )); } // Generate code for the deadline violation function, if there is one. @@ -166,7 +166,7 @@ public static String generateCReaction( code.pr(generateFunction( CReactionGenerator.generateDeadlineFunctionHeader(tpr, reactionIndex), cInit, reaction.getDeadline().getCode(), - generateCPythonDeadlineCaller(r, reactionIndex, pyObjects) + generateCPythonDeadlineCaller(tpr, reactionIndex, pyObjects) )); } code.pr( From e066c099ecbd2e6746ac528106a3c88b82b031db Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Fri, 14 Apr 2023 17:50:01 +0500 Subject: [PATCH 117/709] Cosmetic Changes and Cleanup --- org.lflang/src/org/lflang/generator/ReactorInstance.java | 5 +---- org.lflang/src/org/lflang/generator/c/CGenerator.java | 8 ++++---- .../src/org/lflang/generator/c/CReactionGenerator.java | 9 ++++----- .../lflang/generator/c/CReactorHeaderFileGenerator.java | 2 +- org.lflang/src/org/lflang/generator/c/CUtil.java | 2 +- .../org/lflang/generator/c/TypeParameterizedReactor.java | 4 +--- .../lflang/generator/python/PythonReactionGenerator.java | 8 +++----- 7 files changed, 15 insertions(+), 23 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index ccde52a1ff..7dcf7ee330 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -1185,9 +1185,6 @@ private void setInitialWidth() { */ public boolean isGeneratedDelay() { // FIXME: hacky string matching again... - if (this.definition.getReactorClass().getName().contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME)) { - return true; - } - return false; + return this.definition.getReactorClass().getName().contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME); } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 0a1c0d69cc..4d628de5b4 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -344,10 +344,10 @@ public class CGenerator extends GeneratorBase { /** * Extra lines that need to go into the generated CMakeLists.txt. */ - private String cMakeExtras = ""; + private final String cMakeExtras = ""; /** Place to collect code to execute at the start of a time step. */ - private CodeBuilder startTimeStep = new CodeBuilder(); + private final CodeBuilder startTimeStep = new CodeBuilder(); /** Count of the number of token pointers that need to have their * reference count decremented in _lf_start_time_step(). @@ -515,7 +515,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { try { var dockerData = getDockerGenerator(context).generateDockerData(); dockerData.writeDockerFile(); - (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + new DockerComposeGenerator(context).writeDockerComposeFile(List.of(dockerData)); } catch (IOException e) { throw new RuntimeException("Error while writing Docker files", e); } @@ -1949,7 +1949,7 @@ protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { // Perform set up that does not generate code protected void setUpGeneralParameters() { accommodatePhysicalActionsIfPresent(); - targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); + targetConfig.compileDefinitions.put("LOG_LEVEL", String.valueOf(targetConfig.logLevel.ordinal())); targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); // Create the main reactor instance if there is a main reactor. createMainReactorInstance(); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index ead750738d..8287fdfc80 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -216,7 +216,7 @@ public static String generateInitializationForReaction(String body, } code.pr(String.join("\n", "struct "+containedReactorType.getName()+" {", - " "+fieldsForStructsForContainedReactors.get(containedReactor)+"", + " "+fieldsForStructsForContainedReactors.get(containedReactor), "} "+containedReactorType.getName()+array+";" )); } @@ -697,8 +697,7 @@ public static void generateReactionAndTriggerStructs( // Create the map of triggers to reactions. for (TriggerRef trigger : reaction.getTriggers()) { // trigger may not be a VarRef (it could be "startup" or "shutdown"). - if (trigger instanceof VarRef) { - var triggerAsVarRef = (VarRef) trigger; + if (trigger instanceof VarRef triggerAsVarRef) { var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); if (reactionList == null) { reactionList = new LinkedList<>(); @@ -811,9 +810,9 @@ public static void generateReactionAndTriggerStructs( // self->_lf__"+action.getName()+".is_timer = false; constructorCode.pr(String.join("\n", "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", - (!(action.getPolicy() == null || action.getPolicy().isEmpty()) ? + !(action.getPolicy() == null || action.getPolicy().isEmpty()) ? "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" : - ""), + "", // Need to set the element_size in the trigger_t and the action struct. "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize + ";", diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 88a9e2e6cb..9cef515dba 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -95,7 +95,7 @@ private static void appendSignature(CodeBuilder builder, CTypes types, Reaction private static String reactionParameters(CTypes types, Reaction r, TypeParameterizedReactor tpr) { return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), ioTypedVariableStream(r) - .map((tv) -> tpr.getName().toLowerCase() + "_" + tv.getName() + "_t* " + tv.getName())) + .map(tv -> tpr.getName().toLowerCase() + "_" + tv.getName() + "_t* " + tv.getName())) .collect(Collectors.joining(", ")); } diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 9bfac8e7ba..b53298d5b9 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -853,7 +853,7 @@ private static List multiportWidthTerms(Variable variable) { if (term.getParameter() != null) { result.add(getTargetReference(term.getParameter())); } else { - result.add("" + term.getWidth()); + result.add(String.valueOf(term.getWidth())); } } } diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index c04e1ac247..1a9ac13761 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -10,8 +10,6 @@ import org.lflang.lf.Reactor; import org.lflang.lf.Type; -import com.google.common.collect.ImmutableMap; - public record TypeParameterizedReactor(Reactor r, Map typeArgs) { public TypeParameterizedReactor(Instantiation i) { @@ -26,7 +24,7 @@ private static Map addTypeArgs(Instantiation instantiation, Reacto ret.put(r.getTypeParms().get(i).getLiteral(), instantiation.getTypeArgs().get(i)); } } - return ret; // ImmutableMap.copyOf(ret); + return ret; } public String getName() { diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index e7bf570385..8ea44b2a2f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -209,8 +209,7 @@ private static String generateCPythonInitializers(Reaction reaction, // Next, add the triggers (input and actions; timers are not needed). // TODO: handle triggers for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef) { - VarRef triggerAsVarRef = (VarRef) trigger; + if (trigger instanceof VarRef triggerAsVarRef) { code.pr(generateVariableToSendPythonReaction(triggerAsVarRef, actionsAsTriggers, decl, pyObjects)); } } @@ -274,14 +273,13 @@ public static void generatePythonReactionParametersAndInitializations(List Date: Fri, 14 Apr 2023 20:55:49 +0500 Subject: [PATCH 118/709] [C-Generics] Resolve Templated-Typed Pointers Converted the Context Manager to Generic This required us to seperate the Templated-Types Pointers from their Tokens( * OR [] ) This commit fixes these issue and the GenericContextManager is now available in our Repo Signed-off-by: mkhubaibumer --- .../src/org/lflang/generator/c/CUtil.java | 30 ++++++-- org.lflang/src/org/lflang/util/Pair.java | 77 +++++++++++++++++++ 2 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 org.lflang/src/org/lflang/util/Pair.java diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index b53298d5b9..49357161a5 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -28,7 +28,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.File; import java.io.IOException; -import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -39,7 +38,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Objects; import java.util.stream.Collectors; -import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.InferredType; @@ -55,12 +53,12 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Parameter; import org.lflang.lf.Port; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthTerm; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; +import org.lflang.util.Pair; /** * A collection of utilities for C code generation. @@ -876,6 +874,21 @@ public static boolean isTokenType(InferredType type, CTypes types) { return type.isVariableSizeList || targetType.trim().endsWith("*"); } + /** + * Given a String str separate the Typename from tokens (* OR []) + * + * @param str Input String + * @return {@link Pair} of Typename and Tokens + * */ + public static Pair separateTokensFromTypes(String str) { + var starIdx = str.indexOf("*"); + if (starIdx == -1) { + var idx = str.indexOf("["); + return idx == -1 ? new Pair<>(str, "") : new Pair<>(str.substring(0, idx), str.substring(idx)); + } + return new Pair<>(str.substring(0, starIdx), str.substring(starIdx)); + } + /** * Given a type we need to check if the type is Generic Type literal and if * it is we need to find the corresponding concrete type @@ -886,14 +899,19 @@ public static boolean isTokenType(InferredType type, CTypes types) { public static String getConcreteType(TypeParameterizedReactor tpr, final String type) { if (tpr == null) return type; - var wrapper = new Object() { String concreteType = ""; }; + + var wrapper = new Object() { + String concreteType = ""; + final Pair inPair = separateTokensFromTypes(type); + }; tpr.typeArgs().forEach((literal, concreteType) -> { - if (type.equals(literal)) + if (wrapper.inPair.getFirst().equals(literal)) { wrapper.concreteType = String.valueOf(concreteType.getId()); } }); - return (wrapper.concreteType.isEmpty()) ? type : wrapper.concreteType; + + return wrapper.concreteType.isEmpty() ? type : wrapper.concreteType + wrapper.inPair.getSecond(); } public static String generateWidthVariable(String var) { diff --git a/org.lflang/src/org/lflang/util/Pair.java b/org.lflang/src/org/lflang/util/Pair.java new file mode 100644 index 0000000000..9e237104d3 --- /dev/null +++ b/org.lflang/src/org/lflang/util/Pair.java @@ -0,0 +1,77 @@ +/** + * @file + * @author Muhammad Khubaib Umer (khubaib@magnition.io) + * + * @section LICENSE +Copyright (c) 2023, MagnitionIO +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * @section DESCRIPTION + * + * This Class provides a Pair of Templated Types + * This provides the same facility as std::pair in C++ + */ + +package org.lflang.util; + +public final class Pair { + private final T first; + private final U second; + public Pair(final T t, final U u) + { + this.first = t; + this.second = u; + } + + public T getFirst() + { + return this.first; + } + + public U getSecond() + { + return this.second; + } + + @Override + public boolean equals(Object other) { + if (other == null) + return false; + if (this == other) + return true; + if (this.getClass().equals(other.getClass())) { + Pair otherPair = (Pair) other; + boolean isEqual = (first == null) ? otherPair.getFirst() == null : first.equals(otherPair.getFirst()); + + if (!isEqual) + return false; + + return (second == null) ? otherPair.getSecond() == null : second.equals(otherPair.getSecond()); + } + return false; + } + + @Override + public int hashCode() { + return first == null ? 0 : first.hashCode() + 27 * (second == null ? 0 : second.hashCode()); + } + + @Override + public String toString() { + return "Pair(" + first + ", " + second + ")"; + } +} From 9e9aac73566ec2903440900b5049121d9e8aff17 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 14 Apr 2023 09:47:47 -0700 Subject: [PATCH 119/709] saving changes before merging --- org.lflang/src/org/lflang/ASTUtils.java | 3278 +++++++------- org.lflang/src/org/lflang/ast/IsEqual.java | 1203 +++-- org.lflang/src/org/lflang/ast/ToLf.java | 6 +- .../federated/generator/FederateInstance.java | 1121 +++-- .../org/lflang/generator/GeneratorBase.java | 1152 +++-- .../org/lflang/generator/ReactorInstance.java | 2108 +++++---- .../lflang/generator/WatchdogInstance.java | 84 +- .../org/lflang/generator/c/CGenerator.java | 3975 ++++++++--------- .../generator/c/CReactionGenerator.java | 2334 +++++----- .../generator/c/CWatchdogGenerator.java | 410 +- .../generator/python/PythonGenerator.java | 1093 +++-- .../lflang/scoping/LFScopeProviderImpl.java | 437 +- .../org/lflang/validation/LFValidator.java | 3343 +++++++------- test/C/src/file0.lf | 40 - test/C/src/file1.lf | 40 - test/C/src/file2.lf | 40 - 16 files changed, 10269 insertions(+), 10395 deletions(-) delete mode 100644 test/C/src/file0.lf delete mode 100644 test/C/src/file1.lf delete mode 100644 test/C/src/file2.lf diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index f9767e7e9a..46b913eee0 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -25,6 +25,9 @@ package org.lflang; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -39,7 +42,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -87,1730 +89,1652 @@ import org.lflang.lf.Type; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; - import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; - /** * A helper class for modifying and analyzing the AST. + * * @author Marten Lohstroh * @author Edward A. Lee * @author Christian Menard */ public class ASTUtils { - /** - * The Lingua Franca factory for creating new AST nodes. - */ - public static final LfFactory factory = LfFactory.eINSTANCE; - - /** - * The Lingua Franca feature package. - */ - public static final LfPackage featurePackage = LfPackage.eINSTANCE; - - /* Match an abbreviated form of a float literal. */ - private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); - - /** - * A mapping from Reactor features to corresponding Mode features for collecting contained elements. - */ - private static final Map reactorModeFeatureMap = Map.of( - featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), - featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), - featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), - featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), - featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), - featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), - featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs() - ); - - - /** - * Get all reactors defined in the given resource. - * @param resource the resource to extract reactors from - * @return An iterable over all reactors found in the resource - */ - public static List getAllReactors(Resource resource) { - return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) - .filter(Reactor.class::isInstance) - .map(Reactor.class::cast) - .collect(Collectors.toList()); - } - - /** - * Find connections in the given resource that would be conflicting writes if they were not located in mutually - * exclusive modes. - * - * @param resource The AST. - * @return a list of connections being able to be transformed - */ - public static Collection findConflictingConnectionsInModalReactors(Resource resource) { - var transform = new HashSet(); - - for (Reactor reactor : getAllReactors(resource)) { - if (!reactor.getModes().isEmpty()) { // Only for modal reactors - var allWriters = HashMultimap., EObject>create(); - - // Collect destinations - for (var rea : allReactions(reactor)) { - for (var eff : rea.getEffects()) { - if (eff.getVariable() instanceof Port) { - allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); - } - } - } - for (var con : ASTUtils.collectElements(reactor, featurePackage.getReactor_Connections(), false, true)) { - for (var port : con.getRightPorts()) { - allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); - } - } - - // Handle conflicting writers - for (var key : allWriters.keySet()) { - var writers = allWriters.get(key); - if (writers.size() > 1) { // has multiple sources - var writerModes = HashMultimap.create(); - // find modes - for (var writer : writers) { - if (writer.eContainer() instanceof Mode) { - writerModes.put((Mode) writer.eContainer(), writer); - } else { - writerModes.put(null, writer); - } - } - // Conflicting connection can only be handled if.. - if (!writerModes.containsKey(null) && // no writer is on root level (outside of modes) and... - writerModes.keySet().stream().map(writerModes::get).allMatch(writersInMode -> // all writers in a mode are either... - writersInMode.size() == 1 || // the only writer or... - writersInMode.stream().allMatch(w -> w instanceof Reaction) // all are reactions and hence ordered - )) { - // Add connections to transform list - writers.stream().filter(w -> w instanceof Connection).forEach(c -> transform.add((Connection) c)); - } - } - } + /** The Lingua Franca factory for creating new AST nodes. */ + public static final LfFactory factory = LfFactory.eINSTANCE; + + /** The Lingua Franca feature package. */ + public static final LfPackage featurePackage = LfPackage.eINSTANCE; + + /* Match an abbreviated form of a float literal. */ + private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); + + /** + * A mapping from Reactor features to corresponding Mode features for collecting contained + * elements. + */ + private static final Map reactorModeFeatureMap = + Map.of( + featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), + featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), + featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), + featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), + featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), + featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), + featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs()); + + /** + * Get all reactors defined in the given resource. + * + * @param resource the resource to extract reactors from + * @return An iterable over all reactors found in the resource + */ + public static List getAllReactors(Resource resource) { + return StreamSupport.stream( + IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) + .filter(Reactor.class::isInstance) + .map(Reactor.class::cast) + .collect(Collectors.toList()); + } + + /** + * Find connections in the given resource that would be conflicting writes if they were not + * located in mutually exclusive modes. + * + * @param resource The AST. + * @return a list of connections being able to be transformed + */ + public static Collection findConflictingConnectionsInModalReactors( + Resource resource) { + var transform = new HashSet(); + + for (Reactor reactor : getAllReactors(resource)) { + if (!reactor.getModes().isEmpty()) { // Only for modal reactors + var allWriters = HashMultimap., EObject>create(); + + // Collect destinations + for (var rea : allReactions(reactor)) { + for (var eff : rea.getEffects()) { + if (eff.getVariable() instanceof Port) { + allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); } + } } - - return transform; - } - - /** - * Return the enclosing reactor of an LF EObject in a reactor or mode. - * @param obj the LF model element - * @return the reactor or null - */ - public static Reactor getEnclosingReactor(EObject obj) { - if (obj.eContainer() instanceof Reactor) { - return (Reactor) obj.eContainer(); - } else if (obj.eContainer() instanceof Mode) { - return (Reactor) obj.eContainer().eContainer(); + for (var con : + ASTUtils.collectElements( + reactor, featurePackage.getReactor_Connections(), false, true)) { + for (var port : con.getRightPorts()) { + allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); + } } - return null; - } - /** - * Return the main reactor in the given resource if there is one, null otherwise. - */ - public static Reactor findMainReactor(Resource resource) { - return IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), - Reactor::isMain - ); - } - - /** - * Find the main reactor and change it to a federated reactor. - * Return true if the transformation was successful (or the given resource - * already had a federated reactor); return false otherwise. - */ - public static boolean makeFederated(Resource resource) { - // Find the main reactor - Reactor r = findMainReactor(resource); - if (r == null) { - return false; - } - r.setMain(false); - r.setFederated(true); - return true; - } - - /** - * Change the target name to 'newTargetName'. - * For example, change C to CCpp. - */ - public static boolean changeTargetName(Resource resource, String newTargetName) { - targetDecl(resource).setName(newTargetName); - return true; - } - - /** - * Return the target of the file in which the given node lives. - */ - public static Target getTarget(EObject object) { - TargetDecl targetDecl = targetDecl(object.eResource()); - return Target.fromDecl(targetDecl); - } - - /** - * Add a new target property to the given resource. - * - * This also creates a config object if the resource does not yey have one. - * - * @param resource The resource to modify - * @param name Name of the property to add - * @param value Value to be assigned to the property - */ - public static boolean addTargetProperty(final Resource resource, final String name, final Element value) { - var config = targetDecl(resource).getConfig(); - if (config == null) { - config = LfFactory.eINSTANCE.createKeyValuePairs(); - targetDecl(resource).setConfig(config); - } - final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); - newProperty.setName(name); - newProperty.setValue(value); - config.getPairs().add(newProperty); - return true; - } - - /** - * Return true if the connection involves multiple ports on the left or right side of the connection, or - * if the port on the left or right of the connection involves a bank of reactors or a multiport. - * @param connection The connection. - */ - public static boolean hasMultipleConnections(Connection connection) { - if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { - return true; - } - VarRef leftPort = connection.getLeftPorts().get(0); - VarRef rightPort = connection.getRightPorts().get(0); - Instantiation leftContainer = leftPort.getContainer(); - Instantiation rightContainer = rightPort.getContainer(); - Port leftPortAsPort = (Port) leftPort.getVariable(); - Port rightPortAsPort = (Port) rightPort.getVariable(); - return leftPortAsPort.getWidthSpec() != null - || leftContainer != null && leftContainer.getWidthSpec() != null - || rightPortAsPort.getWidthSpec() != null - || rightContainer != null && rightContainer.getWidthSpec() != null; - } - - /** - * Produce a unique identifier within a reactor based on a - * given based name. If the name does not exists, it is returned; - * if does exist, an index is appended that makes the name unique. - * @param reactor The reactor to find a unique identifier within. - * @param name The name to base the returned identifier on. - */ - public static String getUniqueIdentifier(Reactor reactor, String name) { - LinkedHashSet vars = new LinkedHashSet<>(); - allActions(reactor).forEach(it -> vars.add(it.getName())); - allTimers(reactor).forEach(it -> vars.add(it.getName())); - allParameters(reactor).forEach(it -> vars.add(it.getName())); - allInputs(reactor).forEach(it -> vars.add(it.getName())); - allOutputs(reactor).forEach(it -> vars.add(it.getName())); - allStateVars(reactor).forEach(it -> vars.add(it.getName())); - allInstantiations(reactor).forEach(it -> vars.add(it.getName())); - - int index = 0; - String suffix = ""; - boolean exists = true; - while (exists) { - String id = name + suffix; - if (IterableExtensions.exists(vars, it -> it.equals(id))) { - suffix = "_" + index; - index++; - } else { - exists = false; + // Handle conflicting writers + for (var key : allWriters.keySet()) { + var writers = allWriters.get(key); + if (writers.size() > 1) { // has multiple sources + var writerModes = HashMultimap.create(); + // find modes + for (var writer : writers) { + if (writer.eContainer() instanceof Mode) { + writerModes.put((Mode) writer.eContainer(), writer); + } else { + writerModes.put(null, writer); + } } - } - return name + suffix; - } - - //////////////////////////////// - //// Utility functions for supporting inheritance and modes - - /** - * Given a reactor class, return a list of all its actions, - * which includes actions of base classes that it extends. - * This also includes actions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allActions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); - } - - /** - * Given a reactor class, return a list of all its connections, - * which includes connections of base classes that it extends. - * This also includes connections in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allConnections(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); - } - - /** - * Given a reactor class, return a list of all its inputs, - * which includes inputs of base classes that it extends. - * If the base classes include a cycle, where X extends Y and Y extends X, - * then return only the input defined in the base class. - * The returned list may be empty. - * @param definition Reactor class definition. - */ - public static List allInputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); - } - - /** - * Given a reactor class, return a list of all its instantiations, - * which includes instantiations of base classes that it extends. - * This also includes instantiations in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allInstantiations(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); - } - - /** - * Given a reactor class, return a list of all its methods, - * which includes methods of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allMethods(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); - } - - /** - * Given a reactor class, return a list of all its outputs, - * which includes outputs of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allOutputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); - } - - /** - * Given a reactor class, return a list of all its parameters, - * which includes parameters of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allParameters(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); - } - - /** - * Given a reactor class, return a list of all its reactions, - * which includes reactions of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allReactions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); - } - - /** - * Given a reactor class, return a list of all its watchdogs. - * @param definition Reactor class definition - * @return List - */ - public static List allWatchdogs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); - } - - /** - * Given a reactor class, return a list of all its state variables, - * which includes state variables of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allStateVars(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); - } - - /** - * Given a reactor class, return a list of all its timers, - * which includes timers of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allTimers(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); - } - - /** - * Given a reactor class, returns a list of all its modes, - * which includes modes of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allModes(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); - } - - /** - * Return all the superclasses of the specified reactor - * in deepest-first order. For example, if A extends B and C, and - * B and C both extend D, this will return the list [D, B, C, A]. - * Duplicates are removed. If the specified reactor does not extend - * any other reactor, then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - */ - public static LinkedHashSet superClasses(Reactor reactor) { - return superClasses(reactor, new LinkedHashSet<>()); - } - - /** - * Collect elements of type T from the class hierarchy and modes - * defined by a given reactor definition. - * @param definition The reactor definition. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - public static List collectElements(Reactor definition, EStructuralFeature feature) { - return ASTUtils.collectElements(definition, feature, true, true); - } - - /** - * Collect elements of type T contained in given reactor definition, including - * modes and the class hierarchy defined depending on configuration. - * @param definition The reactor definition. - * @param feature The structual model elements to collect. - * @param includeSuperClasses Whether to include elements in super classes. - * @param includeModes Whether to include elements in modes. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - @SuppressWarnings("unchecked") - public static List collectElements(Reactor definition, EStructuralFeature feature, boolean includeSuperClasses, boolean includeModes) { - List result = new ArrayList<>(); - - if (includeSuperClasses) { - // Add elements of elements defined in superclasses. - LinkedHashSet s = superClasses(definition); - if (s != null) { - for (Reactor superClass : s) { - result.addAll((EList) superClass.eGet(feature)); - } + // Conflicting connection can only be handled if.. + if (!writerModes.containsKey(null) + && // no writer is on root level (outside of modes) and... + writerModes.keySet().stream() + .map(writerModes::get) + .allMatch( + writersInMode -> // all writers in a mode are either... + writersInMode.size() == 1 + || // the only writer or... + writersInMode.stream() + .allMatch( + w -> + w + instanceof + Reaction) // all are reactions and hence ordered + )) { + // Add connections to transform list + writers.stream() + .filter(w -> w instanceof Connection) + .forEach(c -> transform.add((Connection) c)); } + } } - - // Add elements of the current reactor. - result.addAll((EList) definition.eGet(feature)); - - if (includeModes && reactorModeFeatureMap.containsKey(feature)) { - var modeFeature = reactorModeFeatureMap.get(feature); - // Add elements of elements defined in modes. - for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { - insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); - } + } + } + + return transform; + } + + /** + * Return the enclosing reactor of an LF EObject in a reactor or mode. + * + * @param obj the LF model element + * @return the reactor or null + */ + public static Reactor getEnclosingReactor(EObject obj) { + if (obj.eContainer() instanceof Reactor) { + return (Reactor) obj.eContainer(); + } else if (obj.eContainer() instanceof Mode) { + return (Reactor) obj.eContainer().eContainer(); + } + return null; + } + + /** Return the main reactor in the given resource if there is one, null otherwise. */ + public static Reactor findMainReactor(Resource resource) { + return IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), Reactor::isMain); + } + + /** + * Find the main reactor and change it to a federated reactor. Return true if the transformation + * was successful (or the given resource already had a federated reactor); return false otherwise. + */ + public static boolean makeFederated(Resource resource) { + // Find the main reactor + Reactor r = findMainReactor(resource); + if (r == null) { + return false; + } + r.setMain(false); + r.setFederated(true); + return true; + } + + /** Change the target name to 'newTargetName'. For example, change C to CCpp. */ + public static boolean changeTargetName(Resource resource, String newTargetName) { + targetDecl(resource).setName(newTargetName); + return true; + } + + /** Return the target of the file in which the given node lives. */ + public static Target getTarget(EObject object) { + TargetDecl targetDecl = targetDecl(object.eResource()); + return Target.fromDecl(targetDecl); + } + + /** + * Add a new target property to the given resource. + * + *

This also creates a config object if the resource does not yey have one. + * + * @param resource The resource to modify + * @param name Name of the property to add + * @param value Value to be assigned to the property + */ + public static boolean addTargetProperty( + final Resource resource, final String name, final Element value) { + var config = targetDecl(resource).getConfig(); + if (config == null) { + config = LfFactory.eINSTANCE.createKeyValuePairs(); + targetDecl(resource).setConfig(config); + } + final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); + newProperty.setName(name); + newProperty.setValue(value); + config.getPairs().add(newProperty); + return true; + } + + /** + * Return true if the connection involves multiple ports on the left or right side of the + * connection, or if the port on the left or right of the connection involves a bank of reactors + * or a multiport. + * + * @param connection The connection. + */ + public static boolean hasMultipleConnections(Connection connection) { + if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { + return true; + } + VarRef leftPort = connection.getLeftPorts().get(0); + VarRef rightPort = connection.getRightPorts().get(0); + Instantiation leftContainer = leftPort.getContainer(); + Instantiation rightContainer = rightPort.getContainer(); + Port leftPortAsPort = (Port) leftPort.getVariable(); + Port rightPortAsPort = (Port) rightPort.getVariable(); + return leftPortAsPort.getWidthSpec() != null + || leftContainer != null && leftContainer.getWidthSpec() != null + || rightPortAsPort.getWidthSpec() != null + || rightContainer != null && rightContainer.getWidthSpec() != null; + } + + /** + * Produce a unique identifier within a reactor based on a given based name. If the name does not + * exists, it is returned; if does exist, an index is appended that makes the name unique. + * + * @param reactor The reactor to find a unique identifier within. + * @param name The name to base the returned identifier on. + */ + public static String getUniqueIdentifier(Reactor reactor, String name) { + LinkedHashSet vars = new LinkedHashSet<>(); + allActions(reactor).forEach(it -> vars.add(it.getName())); + allTimers(reactor).forEach(it -> vars.add(it.getName())); + allParameters(reactor).forEach(it -> vars.add(it.getName())); + allInputs(reactor).forEach(it -> vars.add(it.getName())); + allOutputs(reactor).forEach(it -> vars.add(it.getName())); + allStateVars(reactor).forEach(it -> vars.add(it.getName())); + allInstantiations(reactor).forEach(it -> vars.add(it.getName())); + + int index = 0; + String suffix = ""; + boolean exists = true; + while (exists) { + String id = name + suffix; + if (IterableExtensions.exists(vars, it -> it.equals(id))) { + suffix = "_" + index; + index++; + } else { + exists = false; + } + } + return name + suffix; + } + + //////////////////////////////// + //// Utility functions for supporting inheritance and modes + + /** + * Given a reactor class, return a list of all its actions, which includes actions of base classes + * that it extends. This also includes actions in modes, returning a flattened view over all + * modes. + * + * @param definition Reactor class definition. + */ + public static List allActions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); + } + + /** + * Given a reactor class, return a list of all its connections, which includes connections of base + * classes that it extends. This also includes connections in modes, returning a flattened view + * over all modes. + * + * @param definition Reactor class definition. + */ + public static List allConnections(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); + } + + /** + * Given a reactor class, return a list of all its inputs, which includes inputs of base classes + * that it extends. If the base classes include a cycle, where X extends Y and Y extends X, then + * return only the input defined in the base class. The returned list may be empty. + * + * @param definition Reactor class definition. + */ + public static List allInputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); + } + + /** + * Given a reactor class, return a list of all its instantiations, which includes instantiations + * of base classes that it extends. This also includes instantiations in modes, returning a + * flattened view over all modes. + * + * @param definition Reactor class definition. + */ + public static List allInstantiations(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); + } + + /** + * Given a reactor class, return a list of all its methods, which includes methods of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allMethods(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); + } + + /** + * Given a reactor class, return a list of all its outputs, which includes outputs of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allOutputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); + } + + /** + * Given a reactor class, return a list of all its parameters, which includes parameters of base + * classes that it extends. + * + * @param definition Reactor class definition. + */ + public static List allParameters(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); + } + + /** + * Given a reactor class, return a list of all its reactions, which includes reactions of base + * classes that it extends. This also includes reactions in modes, returning a flattened view over + * all modes. + * + * @param definition Reactor class definition. + */ + public static List allReactions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); + } + + /** + * Given a reactor class, return a list of all its watchdogs. + * + * @param definition Reactor class definition + * @return List + */ + public static List allWatchdogs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); + } + + /** + * Given a reactor class, return a list of all its state variables, which includes state variables + * of base classes that it extends. This also includes reactions in modes, returning a flattened + * view over all modes. + * + * @param definition Reactor class definition. + */ + public static List allStateVars(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); + } + + /** + * Given a reactor class, return a list of all its timers, which includes timers of base classes + * that it extends. This also includes reactions in modes, returning a flattened view over all + * modes. + * + * @param definition Reactor class definition. + */ + public static List allTimers(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); + } + + /** + * Given a reactor class, returns a list of all its modes, which includes modes of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allModes(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); + } + + /** + * Return all the superclasses of the specified reactor in deepest-first order. For example, if A + * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates + * are removed. If the specified reactor does not extend any other reactor, then return an empty + * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared + * that is not found, then return null. + * + * @param reactor The specified reactor. + */ + public static LinkedHashSet superClasses(Reactor reactor) { + return superClasses(reactor, new LinkedHashSet<>()); + } + + /** + * Collect elements of type T from the class hierarchy and modes defined by a given reactor + * definition. + * + * @param definition The reactor definition. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + public static List collectElements( + Reactor definition, EStructuralFeature feature) { + return ASTUtils.collectElements(definition, feature, true, true); + } + + /** + * Collect elements of type T contained in given reactor definition, including modes and the class + * hierarchy defined depending on configuration. + * + * @param definition The reactor definition. + * @param feature The structual model elements to collect. + * @param includeSuperClasses Whether to include elements in super classes. + * @param includeModes Whether to include elements in modes. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + @SuppressWarnings("unchecked") + public static List collectElements( + Reactor definition, + EStructuralFeature feature, + boolean includeSuperClasses, + boolean includeModes) { + List result = new ArrayList<>(); + + if (includeSuperClasses) { + // Add elements of elements defined in superclasses. + LinkedHashSet s = superClasses(definition); + if (s != null) { + for (Reactor superClass : s) { + result.addAll((EList) superClass.eGet(feature)); } - - return result; - } - - /** - * Adds the elements into the given list at a location matching to their textual position. - * - * When creating a flat view onto reactor elements including modes, the final list must be ordered according - * to the textual positions. - * - * Example: - * reactor R { - * reaction // -> is R.reactions[0] - * mode M { - * reaction // -> is R.mode[0].reactions[0] - * reaction // -> is R.mode[0].reactions[1] - * } - * reaction // -> is R.reactions[1] - * } - * In this example, it is important that the reactions in the mode are inserted between the top-level - * reactions to retain the correct global reaction ordering, which will be derived from this flattened view. - * - * @param list The list to add the elements into. - * @param elements The elements to add. - * @param mode The mode containing the elements. - * @param The type of elements to add (e.g., Port, Timer, etc.) - */ - private static void insertModeElementsAtTextualPosition(List list, List elements, Mode mode) { - if (elements.isEmpty()) { - return; // Nothing to add - } - - var idx = list.size(); - if (idx > 0) { - // If there are elements in the list, first check if the last element has the same container as the mode. - // I.e. we don't want to compare textual positions of different reactors (super classes) - if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { - var modeAstNode = NodeModelUtils.getNode(mode); - if (modeAstNode != null) { - var modePos = modeAstNode.getOffset(); - // Now move the insertion index from the last element forward as long as this element has a textual - // position after the mode. - do { - var astNode = NodeModelUtils.getNode(list.get(idx - 1)); - if (astNode != null && astNode.getOffset() > modePos) { - idx--; - } else { - break; // Insertion index is ok. - } - } while (idx > 0); - } - } - } - list.addAll(idx, elements); - } - - public static Iterable allElementsOfClass( - Resource resource, - Class elementClass - ) { - //noinspection StaticPseudoFunctionalStyleMethod - return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); - } - - //////////////////////////////// - //// Utility functions for translating AST nodes into text - - // public static Code toCode(String text) { - // Code code = null; - // if (text == null) return code; - // code.setBody(text); - // return code; - // } - - /** - * Translate the given code into its textual representation - * with {@code CodeMap.Correspondence} tags inserted, or - * return the empty string if {@code node} is {@code null}. - * This method should be used to generate code. - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toText(EObject node) { - if (node == null) return ""; - return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); - } - - /** - * Translate the given code into its textual representation - * without {@code CodeMap.Correspondence} tags, or return - * the empty string if {@code node} is {@code null}. - * This method should be used for analyzing AST nodes in - * cases where they are easiest to analyze as strings. - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toOriginalText(EObject node) { - if (node == null) return ""; - return ToText.instance.doSwitch(node); - } - - /** - * Return an integer representation of the given element. - * - * Internally, this method uses Integer.decode, so it will - * also understand hexadecimal, binary, etc. - * - * @param e The element to be rendered as an integer. - */ - public static Integer toInteger(Element e) { - return Integer.decode(e.getLiteral()); - } - - /** - * Return a time value based on the given element. - * - * @param e The element to be rendered as a time value. - */ - public static TimeValue toTimeValue(Element e) { - return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); - } - - /** - * Returns the time value represented by the given AST node. - */ - public static TimeValue toTimeValue(Time e) { - if (!isValidTime(e)) { - // invalid unit, will have been reported by validator - throw new IllegalArgumentException(); - } - return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); - } - - /** - * Return a boolean based on the given element. - * - * @param e The element to be rendered as a boolean. - */ - public static boolean toBoolean(Element e) { - return elementToSingleString(e).equalsIgnoreCase("true"); - } - - /** - * Given the right-hand side of a target property, return a string that - * represents the given value/ - * - * If the given value is not a literal or and id (but for instance and array or dict), - * an empty string is returned. If the element is a string, any quotes are removed. - * - * @param e The right-hand side of a target property. - */ - public static String elementToSingleString(Element e) { - if (e.getLiteral() != null) { - return StringUtil.removeQuotes(e.getLiteral()).trim(); - } else if (e.getId() != null) { - return e.getId(); - } - return ""; - } - - /** - * Given the right-hand side of a target property, return a list with all - * the strings that the property lists. - * - * Arrays are traversed, so strings are collected recursively. Empty strings - * are ignored; they are not added to the list. - * @param value The right-hand side of a target property. - */ - public static List elementToListOfStrings(Element value) { - List elements = new ArrayList<>(); - if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - elements.addAll(elementToListOfStrings(element)); - } - return elements; - } else { - String v = elementToSingleString(value); - if (!v.isEmpty()) { - elements.add(v); - } - } - return elements; - } - - /** - * Convert key-value pairs in an Element to a map, assuming that both the key - * and the value are strings. - */ - public static Map elementToStringMaps(Element value) { - Map elements = new HashMap<>(); - for (var element: value.getKeyvalue().getPairs()) { - elements.put( - element.getName().trim(), - StringUtil.removeQuotes(elementToSingleString(element.getValue())) - ); - } - return elements; - } - - // Various utility methods to convert various data types to Elements - - /** - * Convert a map to key-value pairs in an Element. - */ - public static Element toElement(Map map) { - Element e = LfFactory.eINSTANCE.createElement(); - if (map.size() == 0) return null; - else { - var kv = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var entry : map.entrySet()) { - var pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(entry.getKey()); - var element = LfFactory.eINSTANCE.createElement(); - element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); - pair.setValue(element); - kv.getPairs().add(pair); - } - e.setKeyvalue(kv); - } - - return e; - } - - /** - * Given a single string, convert it into its AST representation. - * {@code addQuotes} controls if the generated representation should be - * accompanied by double quotes ("") or not. - */ - private static Element toElement(String str, boolean addQuotes) { - if (str == null) return null; - var strToReturn = addQuotes? StringUtil.addDoubleQuotes(str):str; - Element e = LfFactory.eINSTANCE.createElement(); - e.setLiteral(strToReturn); - return e; - - } - - /** - * Given a single string, convert it into its AST representation. - */ - public static Element toElement(String str) { - return toElement(str, true); - } - - /** - * Given a list of strings, convert it into its AST representation. - * Stores the list in the Array field of the element, unless the list only has one string, - * in which case it is stored in the Literal field. Returns null if the provided list is empty. - */ - public static Element toElement(List list) { - Element e = LfFactory.eINSTANCE.createElement(); - if (list.size() == 0) return null; - else if (list.size() == 1) { - return toElement(list.get(0)); - } else { - var arr = LfFactory.eINSTANCE.createArray(); - for (String s : list) { - arr.getElements().add(ASTUtils.toElement(s)); - } - e.setArray(arr); - } - return e; - } - - /** - * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit inside an Element. - */ - public static Element toElement(TimeValue tv) { - Element e = LfFactory.eINSTANCE.createElement(); - e.setTime((int)tv.time); - if (tv.unit != null) { - e.setUnit(tv.unit.toString()); - } - return e; - } - - public static Element toElement(boolean val) { - return toElement(Boolean.toString(val), false); - } - - public static Element toElement(int val) { - return toElement(Integer.toString(val), false); - } - - /** - * Translate the given type into its textual representation, but - * do not append any array specifications or type arguments. - * @param type AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String baseType(Type type) { - if (type != null) { - if (type.getCode() != null) { - return toText(type.getCode()); + } + } + + // Add elements of the current reactor. + result.addAll((EList) definition.eGet(feature)); + + if (includeModes && reactorModeFeatureMap.containsKey(feature)) { + var modeFeature = reactorModeFeatureMap.get(feature); + // Add elements of elements defined in modes. + for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { + insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); + } + } + + return result; + } + + /** + * Adds the elements into the given list at a location matching to their textual position. + * + *

When creating a flat view onto reactor elements including modes, the final list must be + * ordered according to the textual positions. + * + *

Example: reactor R { reaction // -> is R.reactions[0] mode M { reaction // -> is + * R.mode[0].reactions[0] reaction // -> is R.mode[0].reactions[1] } reaction // -> is + * R.reactions[1] } In this example, it is important that the reactions in the mode are inserted + * between the top-level reactions to retain the correct global reaction ordering, which will be + * derived from this flattened view. + * + * @param list The list to add the elements into. + * @param elements The elements to add. + * @param mode The mode containing the elements. + * @param The type of elements to add (e.g., Port, Timer, etc.) + */ + private static void insertModeElementsAtTextualPosition( + List list, List elements, Mode mode) { + if (elements.isEmpty()) { + return; // Nothing to add + } + + var idx = list.size(); + if (idx > 0) { + // If there are elements in the list, first check if the last element has the same container + // as the mode. + // I.e. we don't want to compare textual positions of different reactors (super classes) + if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { + var modeAstNode = NodeModelUtils.getNode(mode); + if (modeAstNode != null) { + var modePos = modeAstNode.getOffset(); + // Now move the insertion index from the last element forward as long as this element has + // a textual + // position after the mode. + do { + var astNode = NodeModelUtils.getNode(list.get(idx - 1)); + if (astNode != null && astNode.getOffset() > modePos) { + idx--; } else { - if (type.isTime()) { - return "time"; - } else { - StringBuilder result = new StringBuilder(type.getId()); - - for (String s : convertToEmptyListIfNull(type.getStars())) { - result.append(s); - } - return result.toString(); - } + break; // Insertion index is ok. } + } while (idx > 0); } - return ""; - } - - /** - * Report whether the given literal is zero or not. - * @param literal AST node to inspect. - * @return True if the given literal denotes the constant `0`, false - * otherwise. - */ - public static boolean isZero(String literal) { - try { - if (literal != null && - Integer.parseInt(literal) == 0) { - return true; - } - } catch (NumberFormatException e) { - // Not an int. - } - return false; - } - - /** - * Report whether the given expression is zero or not. - * - * @param expr AST node to inspect. - * @return True if the given value denotes the constant `0`, false otherwise. - */ - public static boolean isZero(Expression expr) { - if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } + } + } + list.addAll(idx, elements); + } + + public static Iterable allElementsOfClass( + Resource resource, Class elementClass) { + //noinspection StaticPseudoFunctionalStyleMethod + return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + + // public static Code toCode(String text) { + // Code code = null; + // if (text == null) return code; + // code.setBody(text); + // return code; + // } + + /** + * Translate the given code into its textual representation with {@code CodeMap.Correspondence} + * tags inserted, or return the empty string if {@code node} is {@code null}. This method should + * be used to generate code. + * + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toText(EObject node) { + if (node == null) return ""; + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); + } + + /** + * Translate the given code into its textual representation without {@code CodeMap.Correspondence} + * tags, or return the empty string if {@code node} is {@code null}. This method should be used + * for analyzing AST nodes in cases where they are easiest to analyze as strings. + * + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toOriginalText(EObject node) { + if (node == null) return ""; + return ToText.instance.doSwitch(node); + } + + /** + * Return an integer representation of the given element. + * + *

Internally, this method uses Integer.decode, so it will also understand hexadecimal, binary, + * etc. + * + * @param e The element to be rendered as an integer. + */ + public static Integer toInteger(Element e) { + return Integer.decode(e.getLiteral()); + } + + /** + * Return a time value based on the given element. + * + * @param e The element to be rendered as a time value. + */ + public static TimeValue toTimeValue(Element e) { + return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); + } + + /** Returns the time value represented by the given AST node. */ + public static TimeValue toTimeValue(Time e) { + if (!isValidTime(e)) { + // invalid unit, will have been reported by validator + throw new IllegalArgumentException(); + } + return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + } + + /** + * Return a boolean based on the given element. + * + * @param e The element to be rendered as a boolean. + */ + public static boolean toBoolean(Element e) { + return elementToSingleString(e).equalsIgnoreCase("true"); + } + + /** + * Given the right-hand side of a target property, return a string that represents the given + * value/ + * + *

If the given value is not a literal or and id (but for instance and array or dict), an empty + * string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String elementToSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } + + /** + * Given the right-hand side of a target property, return a list with all the strings that the + * property lists. + * + *

Arrays are traversed, so strings are collected recursively. Empty strings are ignored; they + * are not added to the list. + * + * @param value The right-hand side of a target property. + */ + public static List elementToListOfStrings(Element value) { + List elements = new ArrayList<>(); + if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + elements.addAll(elementToListOfStrings(element)); + } + return elements; + } else { + String v = elementToSingleString(value); + if (!v.isEmpty()) { + elements.add(v); + } + } + return elements; + } + + /** + * Convert key-value pairs in an Element to a map, assuming that both the key and the value are + * strings. + */ + public static Map elementToStringMaps(Element value) { + Map elements = new HashMap<>(); + for (var element : value.getKeyvalue().getPairs()) { + elements.put( + element.getName().trim(), + StringUtil.removeQuotes(elementToSingleString(element.getValue()))); + } + return elements; + } + + // Various utility methods to convert various data types to Elements + + /** Convert a map to key-value pairs in an Element. */ + public static Element toElement(Map map) { + Element e = LfFactory.eINSTANCE.createElement(); + if (map.size() == 0) return null; + else { + var kv = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var entry : map.entrySet()) { + var pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(entry.getKey()); + var element = LfFactory.eINSTANCE.createElement(); + element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); + pair.setValue(element); + kv.getPairs().add(pair); + } + e.setKeyvalue(kv); + } + + return e; + } + + /** + * Given a single string, convert it into its AST representation. {@code addQuotes} controls if + * the generated representation should be accompanied by double quotes ("") or not. + */ + private static Element toElement(String str, boolean addQuotes) { + if (str == null) return null; + var strToReturn = addQuotes ? StringUtil.addDoubleQuotes(str) : str; + Element e = LfFactory.eINSTANCE.createElement(); + e.setLiteral(strToReturn); + return e; + } + + /** Given a single string, convert it into its AST representation. */ + public static Element toElement(String str) { + return toElement(str, true); + } + + /** + * Given a list of strings, convert it into its AST representation. Stores the list in the Array + * field of the element, unless the list only has one string, in which case it is stored in the + * Literal field. Returns null if the provided list is empty. + */ + public static Element toElement(List list) { + Element e = LfFactory.eINSTANCE.createElement(); + if (list.size() == 0) return null; + else if (list.size() == 1) { + return toElement(list.get(0)); + } else { + var arr = LfFactory.eINSTANCE.createArray(); + for (String s : list) { + arr.getElements().add(ASTUtils.toElement(s)); + } + e.setArray(arr); + } + return e; + } + + /** + * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit + * inside an Element. + */ + public static Element toElement(TimeValue tv) { + Element e = LfFactory.eINSTANCE.createElement(); + e.setTime((int) tv.time); + if (tv.unit != null) { + e.setUnit(tv.unit.toString()); + } + return e; + } + + public static Element toElement(boolean val) { + return toElement(Boolean.toString(val), false); + } + + public static Element toElement(int val) { + return toElement(Integer.toString(val), false); + } + + /** + * Translate the given type into its textual representation, but do not append any array + * specifications or type arguments. + * + * @param type AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String baseType(Type type) { + if (type != null) { + if (type.getCode() != null) { + return toText(type.getCode()); + } else { + if (type.isTime()) { + return "time"; + } else { + StringBuilder result = new StringBuilder(type.getId()); - /** - * Report whether the given string literal is an integer number or not. - * - * @param literal AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Integer.decode(literal); - } catch (NumberFormatException e) { - return false; + for (String s : convertToEmptyListIfNull(type.getStars())) { + result.append(s); + } + return result.toString(); } + } + } + return ""; + } + + /** + * Report whether the given literal is zero or not. + * + * @param literal AST node to inspect. + * @return True if the given literal denotes the constant `0`, false otherwise. + */ + public static boolean isZero(String literal) { + try { + if (literal != null && Integer.parseInt(literal) == 0) { return true; - } - - /** - * Report whether the given string literal is a boolean value or not. - * @param literal AST node to inspect. - * @return True if the given value is a boolean, false otherwise. - */ - public static boolean isBoolean(String literal) { - return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); - } - - /** - * Report whether the given string literal is a float value or not. - * @param literal AST node to inspect. - * @return True if the given value is a float, false otherwise. - */ - public static boolean isFloat(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Float.parseFloat(literal); - } catch (NumberFormatException e) { - return false; + } + } catch (NumberFormatException e) { + // Not an int. + } + return false; + } + + /** + * Report whether the given expression is zero or not. + * + * @param expr AST node to inspect. + * @return True if the given value denotes the constant `0`, false otherwise. + */ + public static boolean isZero(Expression expr) { + if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } + + /** + * Report whether the given string literal is an integer number or not. + * + * @param literal AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Integer.decode(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + /** + * Report whether the given string literal is a boolean value or not. + * + * @param literal AST node to inspect. + * @return True if the given value is a boolean, false otherwise. + */ + public static boolean isBoolean(String literal) { + return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); + } + + /** + * Report whether the given string literal is a float value or not. + * + * @param literal AST node to inspect. + * @return True if the given value is a float, false otherwise. + */ + public static boolean isFloat(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Float.parseFloat(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + /** + * Report whether the given code is an integer number or not. + * + * @param code AST node to inspect. + * @return True if the given code is an integer, false otherwise. + */ + public static boolean isInteger(Code code) { + return isInteger(toText(code)); + } + + /** + * Report whether the given expression is an integer number or not. + * + * @param expr AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(Expression expr) { + if (expr instanceof Literal) { + return isInteger(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isInteger((Code) expr); + } + return false; + } + + /** + * Report whether the given expression denotes a valid time or not. + * + * @param expr AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Expression expr) { + if (expr instanceof ParameterReference) { + return isOfTimeType(((ParameterReference) expr).getParameter()); + } else if (expr instanceof Time) { + return isValidTime((Time) expr); + } else if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } + + /** + * Report whether the given time denotes a valid time or not. + * + * @param t AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Time t) { + if (t == null) return false; + String unit = t.getUnit(); + return t.getInterval() == 0 || TimeUnit.isValidUnit(unit); + } + + /** If the initializer contains exactly one expression, return it. Otherwise, return null. */ + public static Expression asSingleExpr(Initializer init) { + if (init == null) { + return null; + } + var exprs = init.getExprs(); + return exprs.size() == 1 ? exprs.get(0) : null; + } + + public static boolean isSingleExpr(Initializer init) { + // todo expand that to = initialization + if (init == null) { + return false; + } + var exprs = init.getExprs(); + return exprs.size() == 1; + } + + public static boolean isListInitializer(Initializer init) { + return init != null && !isSingleExpr(init); + } + + /** + * Return the type of a declaration with the given (nullable) explicit type, and the given + * (nullable) initializer. If the explicit type is null, then the type is inferred from the + * initializer. Only two types can be inferred: "time" and "timeList". Return the "undefined" type + * if neither can be inferred. + * + * @param type Explicit type declared on the declaration + * @param init The initializer expression + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Type type, Initializer init) { + if (type != null) { + return InferredType.fromAST(type); + } else if (init == null) { + return InferredType.undefined(); + } + + var single = asSingleExpr(init); + if (single != null) { + // If there is a single element in the list, and it is a proper + // time value with units, we infer the type "time". + if (single instanceof ParameterReference) { + return getInferredType(((ParameterReference) single).getParameter()); + } else if (single instanceof Time) { + return InferredType.time(); + } + } else if (init.getExprs().size() > 1) { + // If there are multiple elements in the list, and there is at + // least one proper time value with units, and all other elements + // are valid times (including zero without units), we infer the + // type "time list". + var allValidTime = true; + var foundNonZero = false; + + for (var e : init.getExprs()) { + if (!ASTUtils.isValidTime(e)) { + allValidTime = false; } - return true; - } - - /** - * Report whether the given code is an integer number or not. - * @param code AST node to inspect. - * @return True if the given code is an integer, false otherwise. - */ - public static boolean isInteger(Code code) { - return isInteger(toText(code)); - } - - /** - * Report whether the given expression is an integer number or not. - * @param expr AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(Expression expr) { - if (expr instanceof Literal) { - return isInteger(((Literal) expr).getLiteral()); - } else if (expr instanceof Code) { - return isInteger((Code) expr); + if (!ASTUtils.isZero(e)) { + foundNonZero = true; } - return false; - } - - /** - * Report whether the given expression denotes a valid time or not. - * @param expr AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Expression expr) { - if (expr instanceof ParameterReference) { - return isOfTimeType(((ParameterReference)expr).getParameter()); - } else if (expr instanceof Time) { - return isValidTime((Time) expr); - } else if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } - - /** - * Report whether the given time denotes a valid time or not. - * @param t AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Time t) { - if (t == null) return false; - String unit = t.getUnit(); - return t.getInterval() == 0 || - TimeUnit.isValidUnit(unit); - } - - /** - * If the initializer contains exactly one expression, - * return it. Otherwise, return null. - */ - public static Expression asSingleExpr(Initializer init) { - if (init == null) { - return null; - } - var exprs = init.getExprs(); - return exprs.size() == 1 ? exprs.get(0) : null; - } - - public static boolean isSingleExpr(Initializer init) { - // todo expand that to = initialization - if (init == null) { - return false; - } - var exprs = init.getExprs(); - return exprs.size() == 1; - } - - public static boolean isListInitializer(Initializer init) { - return init != null && !isSingleExpr(init); - } - - /** - * Return the type of a declaration with the given - * (nullable) explicit type, and the given (nullable) - * initializer. If the explicit type is null, then the - * type is inferred from the initializer. Only two types - * can be inferred: "time" and "timeList". Return the - * "undefined" type if neither can be inferred. - * - * @param type Explicit type declared on the declaration - * @param init The initializer expression - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Type type, Initializer init) { - if (type != null) { - return InferredType.fromAST(type); - } else if (init == null) { - return InferredType.undefined(); - } - - var single = asSingleExpr(init); - if (single != null) { - // If there is a single element in the list, and it is a proper - // time value with units, we infer the type "time". - if (single instanceof ParameterReference) { - return getInferredType(((ParameterReference) single).getParameter()); - } else if (single instanceof Time) { - return InferredType.time(); - } - } else if (init.getExprs().size() > 1) { - // If there are multiple elements in the list, and there is at - // least one proper time value with units, and all other elements - // are valid times (including zero without units), we infer the - // type "time list". - var allValidTime = true; - var foundNonZero = false; - - for (var e : init.getExprs()) { - if (!ASTUtils.isValidTime(e)) { - allValidTime = false; - } - if (!ASTUtils.isZero(e)) { - foundNonZero = true; - } - } - - if (allValidTime && foundNonZero) { - // Conservatively, no bounds are inferred; the returned type - // is a variable-size list. - return InferredType.timeList(); - } - } - return InferredType.undefined(); - } - - /** - * Given a parameter, return an inferred type. Only two types can be - * inferred: "time" and "timeList". Return the "undefined" type if - * neither can be inferred. - * - * @param p A parameter to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Parameter p) { - return getInferredType(p.getType(), p.getInit()); - } - - /** - * Given a state variable, return an inferred type. Only two types can be - * inferred: "time" and "timeList". Return the "undefined" type if - * neither can be inferred. - * - * @param s A state variable to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(StateVar s) { - return getInferredType(s.getType(), s.getInit()); - } - - /** - * Construct an inferred type from an "action" AST node based - * on its declared type. If no type is declared, return the "undefined" - * type. - * - * @param a An action to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Action a) { - return getInferredType(a.getType(), null); - } - - /** - * Construct an inferred type from a "port" AST node based on its declared - * type. If no type is declared, return the "undefined" type. - * - * @param p A port to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Port p) { - return getInferredType(p.getType(), null); - } - - /** - * If the given string can be recognized as a floating-point number that has a leading decimal point, - * prepend the string with a zero and return it. Otherwise, return the original string. - * - * @param literal A string might be recognizable as a floating point number with a leading decimal point. - * @return an equivalent representation of literal - * - */ - public static String addZeroToLeadingDot(String literal) { - Matcher m = ABBREVIATED_FLOAT.matcher(literal); - if (m.matches()) { - return literal.replace(".", "0."); - } - return literal; - } - - /** - * Return true if the specified port is a multiport. - * @param port The port. - * @return True if the port is a multiport. - */ - public static boolean isMultiport(Port port) { - return port.getWidthSpec() != null; - } - - //////////////////////////////// - //// Utility functions for translating AST nodes into text - // This is a continuation of a large section of ASTUtils.xtend - // with the same name. - - /** - * Generate code for referencing a port, action, or timer. - * @param reference The reference to the variable. - */ - public static String generateVarRef(VarRef reference) { - var prefix = ""; - if (reference.getContainer() != null) { - prefix = reference.getContainer().getName() + "."; + } + + if (allValidTime && foundNonZero) { + // Conservatively, no bounds are inferred; the returned type + // is a variable-size list. + return InferredType.timeList(); + } + } + return InferredType.undefined(); + } + + /** + * Given a parameter, return an inferred type. Only two types can be inferred: "time" and + * "timeList". Return the "undefined" type if neither can be inferred. + * + * @param p A parameter to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Parameter p) { + return getInferredType(p.getType(), p.getInit()); + } + + /** + * Given a state variable, return an inferred type. Only two types can be inferred: "time" and + * "timeList". Return the "undefined" type if neither can be inferred. + * + * @param s A state variable to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(StateVar s) { + return getInferredType(s.getType(), s.getInit()); + } + + /** + * Construct an inferred type from an "action" AST node based on its declared type. If no type is + * declared, return the "undefined" type. + * + * @param a An action to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Action a) { + return getInferredType(a.getType(), null); + } + + /** + * Construct an inferred type from a "port" AST node based on its declared type. If no type is + * declared, return the "undefined" type. + * + * @param p A port to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Port p) { + return getInferredType(p.getType(), null); + } + + /** + * If the given string can be recognized as a floating-point number that has a leading decimal + * point, prepend the string with a zero and return it. Otherwise, return the original string. + * + * @param literal A string might be recognizable as a floating point number with a leading decimal + * point. + * @return an equivalent representation of literal + * + */ + public static String addZeroToLeadingDot(String literal) { + Matcher m = ABBREVIATED_FLOAT.matcher(literal); + if (m.matches()) { + return literal.replace(".", "0."); + } + return literal; + } + + /** + * Return true if the specified port is a multiport. + * + * @param port The port. + * @return True if the port is a multiport. + */ + public static boolean isMultiport(Port port) { + return port.getWidthSpec() != null; + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + // This is a continuation of a large section of ASTUtils.xtend + // with the same name. + + /** + * Generate code for referencing a port, action, or timer. + * + * @param reference The reference to the variable. + */ + public static String generateVarRef(VarRef reference) { + var prefix = ""; + if (reference.getContainer() != null) { + prefix = reference.getContainer().getName() + "."; + } + return prefix + reference.getVariable().getName(); + } + + /** Assuming that the given expression denotes a valid time literal, return a time value. */ + public static TimeValue getLiteralTimeValue(Expression expr) { + if (expr instanceof Time) { + return toTimeValue((Time) expr); + } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { + return TimeValue.ZERO; + } else { + return null; + } + } + + /** If the parameter is of time type, return its default value. Otherwise, return null. */ + public static TimeValue getDefaultAsTimeValue(Parameter p) { + if (isOfTimeType(p)) { + var init = asSingleExpr(p.getInit()); + if (init != null) { + return getLiteralTimeValue(init); + } + } + return null; + } + + /** Return whether the given state variable is inferred to a time type. */ + public static boolean isOfTimeType(StateVar state) { + InferredType t = getInferredType(state); + return t.isTime && !t.isList; + } + + /** Return whether the given parameter is inferred to a time type. */ + public static boolean isOfTimeType(Parameter param) { + InferredType t = getInferredType(param); + return t.isTime && !t.isList; + } + + /** + * Given a parameter, return its initial value. The initial value is a list of instances of + * Expressions. + * + *

If the instantiations argument is null or an empty list, then the value returned is simply + * the default value given when the parameter is defined. + * + *

If a list of instantiations is given, then the first instantiation is required to be an + * instantiation of the reactor class that is parameterized by the parameter. I.e., ``` + * parameter.eContainer == instantiations.get(0).reactorClass ``` If a second instantiation is + * given, then it is required to be an instantiation of a reactor class that contains the first + * instantiation. That is, ``` instantiations.get(0).eContainer == + * instantiations.get(1).reactorClass ``` More generally, for all 0 <= i < instantiations.size - + * 1, ``` instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass ``` If any of + * these conditions is not satisfied, then an IllegalArgumentException will be thrown. + * + *

Note that this chain of reactions cannot be inferred from the parameter because in each of + * the predicates above, there may be more than one instantiation that can appear on the right + * hand side of the predicate. + * + *

For example, consider the following program: ``` 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); } ``` Notice that there are a total of four instances of reactor class A. Then ``` + * initialValue(x, null) returns 1 initialValue(x, [a1]) returns 2 initialValue(x, [a2]) returns + * -1 initialValue(x, [a1, b1]) returns 3 initialValue(x, [a2, b1]) returns -1 initialValue(x, + * [a1, b2]) returns -2 initialValue(x, [a2, b2]) returns -1 ``` (Actually, in each of the above + * cases, the returned value is a list with one entry, a Literal, e.g. ["1"]). + * + *

There are two instances of reactor class B. ``` initialValue(y, null) returns 2 + * initialValue(y, [a1]) throws an IllegalArgumentException initialValue(y, [b1]) returns 3 + * initialValue(y, [b2]) returns -2 ``` + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * @return The value of the parameter. + * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the + * reactor class that is parameterized by the respective parameter or if the chain of + * instantiations is not nested. + */ + public static List initialValue( + Parameter parameter, List instantiations) { + // If instantiations are given, then check to see whether this parameter gets overridden in + // the first of those instantiations. + if (instantiations != null && instantiations.size() > 0) { + // Check to be sure that the instantiation is in fact an instantiation + // of the reactor class for which this is a parameter. + Instantiation instantiation = instantiations.get(0); + + if (!belongsTo(parameter, instantiation)) { + throw new IllegalArgumentException( + "Parameter " + + parameter.getName() + + " is not a parameter of reactor instance " + + instantiation.getName() + + "."); + } + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = null; + for (Assignment assignment : instantiation.getParameters()) { + if (assignment.getLhs().equals(parameter)) { + lastAssignment = assignment; } - return prefix + reference.getVariable().getName(); - } - - /** - * Assuming that the given expression denotes a valid time literal, - * return a time value. - */ - public static TimeValue getLiteralTimeValue(Expression expr) { - if (expr instanceof Time) { - return toTimeValue((Time)expr); - } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { - return TimeValue.ZERO; - } else { - return null; - } - } - - /** - * If the parameter is of time type, return its default value. - * Otherwise, return null. - */ - public static TimeValue getDefaultAsTimeValue(Parameter p) { - if (isOfTimeType(p)) { - var init = asSingleExpr(p.getInit()); - if (init != null) { - return getLiteralTimeValue(init); - } - } - return null; - } - - /** - * Return whether the given state variable is inferred - * to a time type. - */ - public static boolean isOfTimeType(StateVar state) { - InferredType t = getInferredType(state); - return t.isTime && !t.isList; - } - - /** - * Return whether the given parameter is inferred - * to a time type. - */ - public static boolean isOfTimeType(Parameter param) { - InferredType t = getInferredType(param); - return t.isTime && !t.isList; - } - - /** - * Given a parameter, return its initial value. - * The initial value is a list of instances of Expressions. - * - * If the instantiations argument is null or an empty list, then the - * value returned is simply the default value given when the parameter - * is defined. - * - * If a list of instantiations is given, then the first instantiation - * is required to be an instantiation of the reactor class that is - * parameterized by the parameter. I.e., - * ``` - * parameter.eContainer == instantiations.get(0).reactorClass - * ``` - * If a second instantiation is given, then it is required to be an instantiation of a - * reactor class that contains the first instantiation. That is, - * ``` - * instantiations.get(0).eContainer == instantiations.get(1).reactorClass - * ``` - * More generally, for all 0 <= i < instantiations.size - 1, - * ``` - * instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass - * ``` - * If any of these conditions is not satisfied, then an IllegalArgumentException - * will be thrown. - * - * Note that this chain of reactions cannot be inferred from the parameter because - * in each of the predicates above, there may be more than one instantiation that - * can appear on the right hand side of the predicate. - * - * For example, consider the following program: - * ``` - * 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); - * } - * ``` - * Notice that there are a total of four instances of reactor class A. - * Then - * ``` - * initialValue(x, null) returns 1 - * initialValue(x, [a1]) returns 2 - * initialValue(x, [a2]) returns -1 - * initialValue(x, [a1, b1]) returns 3 - * initialValue(x, [a2, b1]) returns -1 - * initialValue(x, [a1, b2]) returns -2 - * initialValue(x, [a2, b2]) returns -1 - * ``` - * (Actually, in each of the above cases, the returned value is a list with - * one entry, a Literal, e.g. ["1"]). - * - * There are two instances of reactor class B. - * ``` - * initialValue(y, null) returns 2 - * initialValue(y, [a1]) throws an IllegalArgumentException - * initialValue(y, [b1]) returns 3 - * initialValue(y, [b2]) returns -2 - * ``` - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * - * @return The value of the parameter. - * - * @throws IllegalArgumentException If an instantiation provided is not an - * instantiation of the reactor class that is parameterized by the - * respective parameter or if the chain of instantiations is not nested. - */ - public static List initialValue(Parameter parameter, List instantiations) { - // If instantiations are given, then check to see whether this parameter gets overridden in - // the first of those instantiations. - if (instantiations != null && instantiations.size() > 0) { - // Check to be sure that the instantiation is in fact an instantiation - // of the reactor class for which this is a parameter. - Instantiation instantiation = instantiations.get(0); - - if (!belongsTo(parameter, instantiation)) { - throw new IllegalArgumentException("Parameter " - + parameter.getName() - + " is not a parameter of reactor instance " - + instantiation.getName() - + "." - ); - } - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = null; - for (Assignment assignment: instantiation.getParameters()) { - if (assignment.getLhs().equals(parameter)) { - lastAssignment = assignment; - } - } - if (lastAssignment != null) { - // Right hand side can be a list. Collect the entries. - List result = new ArrayList<>(); - for (Expression expr: lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - if (instantiations.size() > 1 - && instantiation.eContainer() != instantiations.get(1).getReactorClass() - ) { - throw new IllegalArgumentException("Reactor instance " - + instantiation.getName() - + " is not contained by instance " - + instantiations.get(1).getName() - + "." - ); - } - result.addAll(initialValue(((ParameterReference)expr).getParameter(), - instantiations.subList(1, instantiations.size()))); - } else { - result.add(expr); - } - } - return result; - } - } - // If we reach here, then either no instantiation was supplied or - // there was no assignment in the instantiation. So just use the - // parameter's initial value. - return parameter.getInit().getExprs(); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) - * belongs to the specified instantiation, meaning that it is defined in - * the reactor class being instantiated or one of its base classes. - * @param eobject The object. - * @param instantiation The instantiation. - */ - public static boolean belongsTo(EObject eobject, Instantiation instantiation) { - Reactor reactor = toDefinition(instantiation.getReactorClass()); - return belongsTo(eobject, reactor); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) - * belongs to the specified reactor, meaning that it is defined in - * reactor class or one of its base classes. - * @param eobject The object. - * @param reactor The reactor. - */ - public static boolean belongsTo(EObject eobject, Reactor reactor) { - if (eobject.eContainer() == reactor) return true; - for (ReactorDecl baseClass : reactor.getSuperClasses()) { - if (belongsTo(eobject, toDefinition(baseClass))) { - return true; - } - } - return false; - } - - /** - * Given a parameter return its integer value or null - * if it does not have an integer value. - * If the value of the parameter is a list of integers, - * return the sum of value in the list. - * The instantiations parameter is as in - * {@link #initialValue(Parameter, List)}. - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * - * @return The integer value of the parameter, or null if it does not have an integer value. - * - * @throws IllegalArgumentException If an instantiation provided is not an - * instantiation of the reactor class that is parameterized by the - * respective parameter or if the chain of instantiations is not nested. - */ - public static Integer initialValueInt(Parameter parameter, List instantiations) { - List expressions = initialValue(parameter, instantiations); - int result = 0; - for (Expression expr: expressions) { - if (!(expr instanceof Literal)) { - return null; - } - try { - result += Integer.decode(((Literal) expr).getLiteral()); - } catch (NumberFormatException ex) { - return null; + } + if (lastAssignment != null) { + // Right hand side can be a list. Collect the entries. + List result = new ArrayList<>(); + for (Expression expr : lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + if (instantiations.size() > 1 + && instantiation.eContainer() != instantiations.get(1).getReactorClass()) { + throw new IllegalArgumentException( + "Reactor instance " + + instantiation.getName() + + " is not contained by instance " + + instantiations.get(1).getName() + + "."); } + result.addAll( + initialValue( + ((ParameterReference) expr).getParameter(), + instantiations.subList(1, instantiations.size()))); + } else { + result.add(expr); + } } return result; - } - - /** - * Given the width specification of port or instantiation - * and an (optional) list of nested instantiations, return - * the width if it can be determined and -1 if not. - * It will not be able to be determined if either the - * width is variable (in which case you should use - * {@link #inferPortWidth(VarRef, Connection, List)} ) - * or the list of instantiations is incomplete or missing. - * If there are parameter references in the width, they are - * evaluated to the extent possible given the instantiations list. - * - * The instantiations list is as in - * {@link #initialValue(Parameter, List)}. - * If the spec belongs to an instantiation (for a bank of reactors), - * then the first element on this list should be the instantiation - * that contains this instantiation. If the spec belongs to a port, - * then the first element on the list should be the instantiation - * of the reactor that contains the port. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * - * @return The width, or -1 if the width could not be determined. - * - * @throws IllegalArgumentException If an instantiation provided is not as - * given above or if the chain of instantiations is not nested. - */ - public static int width(WidthSpec spec, List instantiations) { - if (spec == null) { - return 1; + } + } + // If we reach here, then either no instantiation was supplied or + // there was no assignment in the instantiation. So just use the + // parameter's initial value. + return parameter.getInit().getExprs(); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the + * specified instantiation, meaning that it is defined in the reactor class being instantiated or + * one of its base classes. + * + * @param eobject The object. + * @param instantiation The instantiation. + */ + public static boolean belongsTo(EObject eobject, Instantiation instantiation) { + Reactor reactor = toDefinition(instantiation.getReactorClass()); + return belongsTo(eobject, reactor); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the + * specified reactor, meaning that it is defined in reactor class or one of its base classes. + * + * @param eobject The object. + * @param reactor The reactor. + */ + public static boolean belongsTo(EObject eobject, Reactor reactor) { + if (eobject.eContainer() == reactor) return true; + for (ReactorDecl baseClass : reactor.getSuperClasses()) { + if (belongsTo(eobject, toDefinition(baseClass))) { + return true; + } + } + return false; + } + + /** + * Given a parameter return its integer value or null if it does not have an integer value. If the + * value of the parameter is a list of integers, return the sum of value in the list. The + * instantiations parameter is as in {@link #initialValue(Parameter, List)}. + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * @return The integer value of the parameter, or null if it does not have an integer value. + * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the + * reactor class that is parameterized by the respective parameter or if the chain of + * instantiations is not nested. + */ + public static Integer initialValueInt(Parameter parameter, List instantiations) { + List expressions = initialValue(parameter, instantiations); + int result = 0; + for (Expression expr : expressions) { + if (!(expr instanceof Literal)) { + return null; + } + try { + result += Integer.decode(((Literal) expr).getLiteral()); + } catch (NumberFormatException ex) { + return null; + } + } + return result; + } + + /** + * Given the width specification of port or instantiation and an (optional) list of nested + * instantiations, return the width if it can be determined and -1 if not. It will not be able to + * be determined if either the width is variable (in which case you should use {@link + * #inferPortWidth(VarRef, Connection, List)} ) or the list of instantiations is incomplete or + * missing. If there are parameter references in the width, they are evaluated to the extent + * possible given the instantiations list. + * + *

The instantiations list is as in {@link #initialValue(Parameter, List)}. If the spec belongs + * to an instantiation (for a bank of reactors), then the first element on this list should be the + * instantiation that contains this instantiation. If the spec belongs to a port, then the first + * element on the list should be the instantiation of the reactor that contains the port. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * @return The width, or -1 if the width could not be determined. + * @throws IllegalArgumentException If an instantiation provided is not as given above or if the + * chain of instantiations is not nested. + */ + public static int width(WidthSpec spec, List instantiations) { + if (spec == null) { + return 1; + } + if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { + return inferWidthFromConnections(spec, instantiations); + } + var result = 0; + for (WidthTerm term : spec.getTerms()) { + if (term.getParameter() != null) { + Integer termWidth = initialValueInt(term.getParameter(), instantiations); + if (termWidth != null) { + result += termWidth; + } else { + return -1; } - if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { + } else if (term.getWidth() > 0) { + result += term.getWidth(); + } else { + // If the width cannot be determined because term's width <= 0, which means the term's width + // must be inferred, try to infer the width using connections. + if (spec.eContainer() instanceof Instantiation) { + try { return inferWidthFromConnections(spec, instantiations); + } catch (InvalidSourceException e) { + // If the inference fails, return -1. + return -1; + } } - var result = 0; - for (WidthTerm term: spec.getTerms()) { - if (term.getParameter() != null) { - Integer termWidth = initialValueInt(term.getParameter(), instantiations); - if (termWidth != null) { - result += termWidth; - } else { - return -1; - } - } else if (term.getWidth() > 0) { - result += term.getWidth(); - } else { - // If the width cannot be determined because term's width <= 0, which means the term's width - // must be inferred, try to infer the width using connections. - if (spec.eContainer() instanceof Instantiation) { - try { - return inferWidthFromConnections(spec, instantiations); - } catch (InvalidSourceException e) { - // If the inference fails, return -1. - return -1; - } - } - } + } + } + return result; + } + + /** + * Infer the width of a port reference in a connection. The port reference one or two parts, a + * port and an (optional) container which is an Instantiation that may refer to a bank of + * reactors. The width will be the product of the bank width and the port width. The returned + * value will be 1 if the port is not in a bank and is not a multiport. + * + *

If the width cannot be determined, this will return -1. The width cannot be determined if + * the list of instantiations is missing or incomplete. + * + *

The instantiations list is as in {@link #initialValue(Parameter, List)}. The first element + * on this list should be the instantiation that contains the specified connection. + * + * @param reference A port reference. + * @param connection A connection, or null if not in the context of a connection. + * @param instantiations The (optional) list of instantiations. + * @return The width or -1 if it could not be determined. + * @throws IllegalArgumentException If an instantiation provided is not as given above or if the + * chain of instantiations is not nested. + */ + public static int inferPortWidth( + VarRef reference, Connection connection, List instantiations) { + if (reference.getVariable() instanceof Port) { + // If the port is given as a.b, then we want to prepend a to + // the list of instantiations to determine the width of this port. + List extended = instantiations; + if (reference.getContainer() != null) { + extended = new ArrayList<>(); + extended.add(reference.getContainer()); + if (instantiations != null) { + extended.addAll(instantiations); } - return result; - } - - /** - * Infer the width of a port reference in a connection. - * The port reference one or two parts, a port and an (optional) container - * which is an Instantiation that may refer to a bank of reactors. - * The width will be the product of the bank width and the port width. - * The returned value will be 1 if the port is not in a bank and is not a multiport. - * - * If the width cannot be determined, this will return -1. - * The width cannot be determined if the list of instantiations is - * missing or incomplete. - * - * The instantiations list is as in - * {@link #initialValue(Parameter, List)}. - * The first element on this list should be the instantiation - * that contains the specified connection. - * - * @param reference A port reference. - * @param connection A connection, or null if not in the context of a connection. - * @param instantiations The (optional) list of instantiations. - * - * @return The width or -1 if it could not be determined. - * - * @throws IllegalArgumentException If an instantiation provided is not as - * given above or if the chain of instantiations is not nested. - */ - public static int inferPortWidth( - VarRef reference, Connection connection, List instantiations - ) { - if (reference.getVariable() instanceof Port) { - // If the port is given as a.b, then we want to prepend a to - // the list of instantiations to determine the width of this port. - List extended = instantiations; - if (reference.getContainer() != null) { - extended = new ArrayList<>(); - extended.add(reference.getContainer()); - if (instantiations != null) { - extended.addAll(instantiations); - } - } + } - int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); - if (portWidth < 0) { - // Could not determine port width. - return -1; - } - - // Next determine the bank width. This may be unspecified, in which - // case it has to be inferred using the connection. - int bankWidth = 1; - if (reference.getContainer() != null) { - bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); - if (bankWidth < 0 && connection != null) { - // Try to infer the bank width from the connection. - if (reference.getContainer().getWidthSpec().isOfVariableLength()) { - // This occurs for a bank of delays. - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : connection.getLeftPorts()) { - if (leftPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the left. - leftOrRight = -1; - } else { - // The left port is not the same as this reference. - int otherWidth = inferPortWidth(leftPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; - } - leftWidth += otherWidth; - } - } - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the right. - leftOrRight = 1; - } else { - int otherWidth = inferPortWidth(rightPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; - } - rightWidth += otherWidth; - } - } - int discrepancy = 0; - if (leftOrRight < 0) { - // This port is on the left. - discrepancy = rightWidth - leftWidth; - } else if (leftOrRight > 0) { - // This port is on the right. - discrepancy = leftWidth - rightWidth; - } - // Check that portWidth divides the discrepancy. - if (discrepancy % portWidth != 0) { - // This is an error. - return -1; - } - bankWidth = discrepancy / portWidth; - } else { - // Could not determine the bank width. - return -1; - } - } - } - return portWidth * bankWidth; - } - // Argument is not a port. + int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); + if (portWidth < 0) { + // Could not determine port width. return -1; - } - - /** - * Given an instantiation of a reactor or bank of reactors, return - * the width. This will be 1 if this is not a reactor bank. Otherwise, - * this will attempt to determine the width. If the width is declared - * as a literal constant, it will return that constant. If the width - * is specified as a reference to a parameter, this will throw an - * exception. If the width is variable, this will find - * connections in the enclosing reactor and attempt to infer the - * width. If the width cannot be determined, it will throw an exception. - * - * IMPORTANT: This method should not be used you really need to - * determine the width! It will not evaluate parameter values. - * @see #width(WidthSpec, List) - * - * @param instantiation A reactor instantiation. - * - * @return The width, if it can be determined. - * @deprecated - */ - @Deprecated - public static int widthSpecification(Instantiation instantiation) { - int result = width(instantiation.getWidthSpec(), null); - if (result < 0) { - throw new InvalidSourceException("Cannot determine width for the instance " - + instantiation.getName()); - } - return result; - } - - /** - * Report whether a state variable has been initialized or not. - * @param v The state variable to be checked. - * @return True if the variable was initialized, false otherwise. - */ - public static boolean isInitialized(StateVar v) { - return v != null && v.getInit() != null; - } - - /** - * Report whether the given time state variable is initialized using a - * parameter or not. - * @param s A state variable. - * @return True if the argument is initialized using a parameter, false - * otherwise. - */ - public static boolean isParameterized(StateVar s) { - return s.getInit() != null && - IterableExtensions.exists(s.getInit().getExprs(), it -> it instanceof ParameterReference); - } - - /** - * Check if the reactor class uses generics - * @param r the reactor to check - * @return true if the reactor uses generics - */ - public static boolean isGeneric(Reactor r) { - if (r == null) { - return false; - } - return r.getTypeParms().size() != 0; - } - - /** - * If the specified reactor declaration is an import, then - * return the imported reactor class definition. Otherwise, - * just return the argument. - * @param r A Reactor or an ImportedReactor. - * @return The Reactor class definition or null if no definition is found. - */ - public static Reactor toDefinition(ReactorDecl r) { - if (r == null) - return null; - if (r instanceof Reactor) { - return (Reactor) r; - } else if (r instanceof ImportedReactor) { - return ((ImportedReactor) r).getReactorClass(); - } - return null; - } - - /** - * Return all single-line or multi-line comments immediately preceding the - * given EObject. - */ - public static Stream getPrecedingComments( - ICompositeNode compNode, - Predicate filter - ) { - return getPrecedingCommentNodes(compNode, filter).map(INode::getText); - } - - /** - * Return all single-line or multi-line comments immediately preceding the - * given EObject. - */ - public static Stream getPrecedingCommentNodes( - ICompositeNode compNode, - Predicate filter - ) { - if (compNode == null) return Stream.of(); - List ret = new ArrayList<>(); - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode)) { - if (isComment(node)) { - if (filter.test(node)) ret.add(node); - } else if (!node.getText().isBlank()) { - break; - } - } - } - return ret.stream(); - } - - /** Return whether {@code node} is a comment. */ - public static boolean isComment(INode node) { - return node instanceof HiddenLeafNode hlNode - && hlNode.getGrammarElement() instanceof TerminalRule tRule - && tRule.getName().endsWith("_COMMENT"); - } - - /** - * Return true if the given node starts on the same line as the given other - * node. - */ - public static Predicate sameLine(ICompositeNode compNode) { - return other -> { - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { - return node.getStartLine() == other.getStartLine(); - } - } - return false; - }; - } - - /** - * Find the main reactor and set its name if none was defined. - * @param resource The resource to find the main reactor in. - */ - public static void setMainName(Resource resource, String name) { - Reactor main = IteratorExtensions.findFirst(Iterators.filter(resource.getAllContents(), Reactor.class), - it -> it.isMain() || it.isFederated() - ); - if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { - main.setName(name); - } - } - - /** - * Create a new instantiation node with the given reactor as its defining class. - * @param reactor The reactor class to create an instantiation of. - */ - public static Instantiation createInstantiation(Reactor reactor) { - Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); - inst.setReactorClass(reactor); - // If the reactor is federated or at the top level, then it - // may not have a name. In the generator's doGenerate() - // method, the name gets set using setMainName(). - // But this may be called before that, e.g. during - // diagram synthesis. We assign a temporary name here. - if (reactor.getName() == null) { - if (reactor.isFederated() || reactor.isMain()) { - inst.setName("main"); - } else { - inst.setName(""); - } - - } else { - inst.setName(reactor.getName()); - } - return inst; - } - - /** - * Returns the target declaration in the given model. - * Non-null because it would cause a parse error. - */ - public static TargetDecl targetDecl(Model model) { - return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); - } - - /** - * Returns the target declaration in the given resource. - * Non-null because it would cause a parse error. - */ - public static TargetDecl targetDecl(Resource model) { - return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); - } - - ///////////////////////////////////////////////////////// - //// Private methods - - /** - * Returns the list if it is not null. Otherwise, return an empty list. - */ - public static List convertToEmptyListIfNull(List list) { - return list != null ? list : new ArrayList<>(); - } - - /** - * Return all the superclasses of the specified reactor - * in deepest-first order. For example, if A extends B and C, and - * B and C both extend D, this will return the list [D, B, C, A]. - * Duplicates are removed. If the specified reactor does not extend - * any other reactor, then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - * @param extensions A set of reactors extending the specified reactor - * (used to detect circular extensions). - */ - private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { - LinkedHashSet result = new LinkedHashSet<>(); - for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { - Reactor r = toDefinition(superDecl); - if (r == reactor || r == null) return null; - // If r is in the extensions, then we have a circular inheritance structure. - if (extensions.contains(r)) return null; - extensions.add(r); - LinkedHashSet baseExtends = superClasses(r, extensions); - extensions.remove(r); - if (baseExtends == null) return null; - result.addAll(baseExtends); - result.add(r); - } - return result; - } - - /** - * We may be able to infer the width by examining the connections of - * the enclosing reactor definition. This works, for example, with - * delays between multiports or banks of reactors. - * Attempt to infer the width from connections and return -1 if the width cannot be inferred. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * - * @return The width, or -1 if the width could not be inferred from connections. - */ - private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { - for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + } + + // Next determine the bank width. This may be unspecified, in which + // case it has to be inferred using the connection. + int bankWidth = 1; + if (reference.getContainer() != null) { + bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); + if (bankWidth < 0 && connection != null) { + // Try to infer the bank width from the connection. + if (reference.getContainer().getWidthSpec().isOfVariableLength()) { + // This occurs for a bank of delays. int leftWidth = 0; int rightWidth = 0; int leftOrRight = 0; - for (VarRef leftPort : c.getLeftPorts()) { - if (leftPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the left. - leftOrRight = -1; - } else { - leftWidth += inferPortWidth(leftPort, c, instantiations); + for (VarRef leftPort : connection.getLeftPorts()) { + if (leftPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException( + "Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the left. + leftOrRight = -1; + } else { + // The left port is not the same as this reference. + int otherWidth = inferPortWidth(leftPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; } + leftWidth += otherWidth; + } } - for (VarRef rightPort : c.getRightPorts()) { - if (rightPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the right. - leftOrRight = 1; - } else { - rightWidth += inferPortWidth(rightPort, c, instantiations); + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException( + "Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the right. + leftOrRight = 1; + } else { + int otherWidth = inferPortWidth(rightPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; } + rightWidth += otherWidth; + } } + int discrepancy = 0; if (leftOrRight < 0) { - return rightWidth - leftWidth; + // This port is on the left. + discrepancy = rightWidth - leftWidth; } else if (leftOrRight > 0) { - return leftWidth - rightWidth; + // This port is on the right. + discrepancy = leftWidth - rightWidth; } + // Check that portWidth divides the discrepancy. + if (discrepancy % portWidth != 0) { + // This is an error. + return -1; + } + bankWidth = discrepancy / portWidth; + } else { + // Could not determine the bank width. + return -1; + } } - // A connection was not found with the instantiation. - return -1; - } - - public static void addReactionAttribute(Reaction reaction, String name) { - var fedAttr = factory.createAttribute(); - fedAttr.setAttrName(name); - reaction.getAttributes().add(fedAttr); - } + } + return portWidth * bankWidth; + } + // Argument is not a port. + return -1; + } + + /** + * Given an instantiation of a reactor or bank of reactors, return the width. This will be 1 if + * this is not a reactor bank. Otherwise, this will attempt to determine the width. If the width + * is declared as a literal constant, it will return that constant. If the width is specified as a + * reference to a parameter, this will throw an exception. If the width is variable, this will + * find connections in the enclosing reactor and attempt to infer the width. If the width cannot + * be determined, it will throw an exception. + * + *

IMPORTANT: This method should not be used you really need to determine the width! It will + * not evaluate parameter values. + * + * @see #width(WidthSpec, List) + * @param instantiation A reactor instantiation. + * @return The width, if it can be determined. + * @deprecated + */ + @Deprecated + public static int widthSpecification(Instantiation instantiation) { + int result = width(instantiation.getWidthSpec(), null); + if (result < 0) { + throw new InvalidSourceException( + "Cannot determine width for the instance " + instantiation.getName()); + } + return result; + } + + /** + * Report whether a state variable has been initialized or not. + * + * @param v The state variable to be checked. + * @return True if the variable was initialized, false otherwise. + */ + public static boolean isInitialized(StateVar v) { + return v != null && v.getInit() != null; + } + + /** + * Report whether the given time state variable is initialized using a parameter or not. + * + * @param s A state variable. + * @return True if the argument is initialized using a parameter, false otherwise. + */ + public static boolean isParameterized(StateVar s) { + return s.getInit() != null + && IterableExtensions.exists( + s.getInit().getExprs(), it -> it instanceof ParameterReference); + } + + /** + * Check if the reactor class uses generics + * + * @param r the reactor to check + * @return true if the reactor uses generics + */ + public static boolean isGeneric(Reactor r) { + if (r == null) { + return false; + } + return r.getTypeParms().size() != 0; + } + + /** + * If the specified reactor declaration is an import, then return the imported reactor class + * definition. Otherwise, just return the argument. + * + * @param r A Reactor or an ImportedReactor. + * @return The Reactor class definition or null if no definition is found. + */ + public static Reactor toDefinition(ReactorDecl r) { + if (r == null) return null; + if (r instanceof Reactor) { + return (Reactor) r; + } else if (r instanceof ImportedReactor) { + return ((ImportedReactor) r).getReactorClass(); + } + return null; + } + + /** Return all single-line or multi-line comments immediately preceding the given EObject. */ + public static Stream getPrecedingComments( + ICompositeNode compNode, Predicate filter) { + return getPrecedingCommentNodes(compNode, filter).map(INode::getText); + } + + /** Return all single-line or multi-line comments immediately preceding the given EObject. */ + public static Stream getPrecedingCommentNodes( + ICompositeNode compNode, Predicate filter) { + if (compNode == null) return Stream.of(); + List ret = new ArrayList<>(); + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode)) { + if (isComment(node)) { + if (filter.test(node)) ret.add(node); + } else if (!node.getText().isBlank()) { + break; + } + } + } + return ret.stream(); + } + + /** Return whether {@code node} is a comment. */ + public static boolean isComment(INode node) { + return node instanceof HiddenLeafNode hlNode + && hlNode.getGrammarElement() instanceof TerminalRule tRule + && tRule.getName().endsWith("_COMMENT"); + } + + /** Return true if the given node starts on the same line as the given other node. */ + public static Predicate sameLine(ICompositeNode compNode) { + return other -> { + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { + return node.getStartLine() == other.getStartLine(); + } + } + return false; + }; + } + + /** + * Find the main reactor and set its name if none was defined. + * + * @param resource The resource to find the main reactor in. + */ + public static void setMainName(Resource resource, String name) { + Reactor main = + IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), + it -> it.isMain() || it.isFederated()); + if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { + main.setName(name); + } + } + + /** + * Create a new instantiation node with the given reactor as its defining class. + * + * @param reactor The reactor class to create an instantiation of. + */ + public static Instantiation createInstantiation(Reactor reactor) { + Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); + inst.setReactorClass(reactor); + // If the reactor is federated or at the top level, then it + // may not have a name. In the generator's doGenerate() + // method, the name gets set using setMainName(). + // But this may be called before that, e.g. during + // diagram synthesis. We assign a temporary name here. + if (reactor.getName() == null) { + if (reactor.isFederated() || reactor.isMain()) { + inst.setName("main"); + } else { + inst.setName(""); + } + + } else { + inst.setName(reactor.getName()); + } + return inst; + } + + /** + * Returns the target declaration in the given model. Non-null because it would cause a parse + * error. + */ + public static TargetDecl targetDecl(Model model) { + return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); + } + + /** + * Returns the target declaration in the given resource. Non-null because it would cause a parse + * error. + */ + public static TargetDecl targetDecl(Resource model) { + return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); + } + + ///////////////////////////////////////////////////////// + //// Private methods + + /** Returns the list if it is not null. Otherwise, return an empty list. */ + public static List convertToEmptyListIfNull(List list) { + return list != null ? list : new ArrayList<>(); + } + + /** + * Return all the superclasses of the specified reactor in deepest-first order. For example, if A + * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates + * are removed. If the specified reactor does not extend any other reactor, then return an empty + * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared + * that is not found, then return null. + * + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor (used to detect circular + * extensions). + */ + private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet baseExtends = superClasses(r, extensions); + extensions.remove(r); + if (baseExtends == null) return null; + result.addAll(baseExtends); + result.add(r); + } + return result; + } + + /** + * We may be able to infer the width by examining the connections of the enclosing reactor + * definition. This works, for example, with delays between multiports or banks of reactors. + * Attempt to infer the width from connections and return -1 if the width cannot be inferred. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * @return The width, or -1 if the width could not be inferred from connections. + */ + private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { + for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : c.getLeftPorts()) { + if (leftPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the left. + leftOrRight = -1; + } else { + leftWidth += inferPortWidth(leftPort, c, instantiations); + } + } + for (VarRef rightPort : c.getRightPorts()) { + if (rightPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the right. + leftOrRight = 1; + } else { + rightWidth += inferPortWidth(rightPort, c, instantiations); + } + } + if (leftOrRight < 0) { + return rightWidth - leftWidth; + } else if (leftOrRight > 0) { + return leftWidth - rightWidth; + } + } + // A connection was not found with the instantiation. + return -1; + } + + public static void addReactionAttribute(Reaction reaction, String name) { + var fedAttr = factory.createAttribute(); + fedAttr.setAttrName(name); + reaction.getAttributes().add(fedAttr); + } } diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index e18eea02bd..f4bbc17f6d 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -6,9 +6,7 @@ import java.util.function.BiPredicate; import java.util.function.Function; import java.util.stream.Collectors; - import org.eclipse.emf.ecore.EObject; - import org.lflang.TimeUnit; import org.lflang.lf.Action; import org.lflang.lf.Array; @@ -60,626 +58,609 @@ import org.lflang.lf.TypedVariable; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import org.lflang.lf.Watchdog; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; -import org.lflang.lf.Watchdog; import org.lflang.lf.util.LfSwitch; /** - * Switch class that checks if subtrees of the AST are semantically equivalent - * to each other. Return {@code false} if they are not equivalent; return - * {@code true} or {@code false} (but preferably {@code true}) if they are - * equivalent. + * Switch class that checks if subtrees of the AST are semantically equivalent to each other. Return + * {@code false} if they are not equivalent; return {@code true} or {@code false} (but preferably + * {@code true}) if they are equivalent. */ public class IsEqual extends LfSwitch { - private final EObject otherObject; - - public IsEqual(EObject other) { - this.otherObject = other; - } - - @Override - public Boolean doSwitch(EObject eObject) { - if (otherObject == eObject) return true; - if (eObject == null) return false; - return super.doSwitch(eObject); - } - - @Override - public Boolean caseModel(Model object) { - return new ComparisonMachine<>(object, Model.class) - .equivalent(Model::getTarget) - .listsEquivalent(Model::getImports) - .listsEquivalent(Model::getPreambles) - .listsEquivalent(Model::getReactors).conclusion; - } - - @Override - public Boolean caseImport(Import object) { - return new ComparisonMachine<>(object, Import.class) - .equalAsObjects(Import::getImportURI) - .listsEquivalent(Import::getReactorClasses).conclusion; - } - - @Override - public Boolean caseReactorDecl(ReactorDecl object) { - return new ComparisonMachine<>(object, ReactorDecl.class) - .equalAsObjects(ReactorDecl::getName) - .conclusion; - } - - @Override - public Boolean caseImportedReactor(ImportedReactor object) { - return new ComparisonMachine<>(object, ImportedReactor.class) - .equalAsObjects(ImportedReactor::getName) - .equivalent(ImportedReactor::getReactorClass) - .conclusion; - } - - @Override - public Boolean caseReactor(Reactor object) { - return new ComparisonMachine<>(object, Reactor.class) - .listsEquivalent(Reactor::getAttributes) - .equalAsObjects(Reactor::isFederated) - .equalAsObjects(Reactor::isRealtime) - .equalAsObjects(Reactor::isMain) - .equalAsObjects(Reactor::getName) - .listsEquivalent(Reactor::getTypeParms) - .listsEquivalent(Reactor::getParameters) - .equivalent(Reactor::getHost) - .listsEquivalent(Reactor::getSuperClasses) - .listsEquivalent(Reactor::getPreambles) - .listsEquivalent(Reactor::getInputs) - .listsEquivalent(Reactor::getOutputs) - .listsEquivalent(Reactor::getTimers) - .listsEquivalent(Reactor::getActions) - .listsEquivalent(Reactor::getInstantiations) - .listsEquivalent(Reactor::getConnections) - .listsEquivalent(Reactor::getStateVars) - .listsEquivalent(Reactor::getReactions) - .listsEquivalent(Reactor::getMethods) - .listsEquivalent(Reactor::getModes) - .conclusion; - } - - @Override - public Boolean caseTypeParm(TypeParm object) { - return new ComparisonMachine<>(object, TypeParm.class) - .equalAsObjects(TypeParm::getLiteral) - .equivalent(TypeParm::getCode) - .conclusion; - } - - @Override - public Boolean caseTargetDecl(TargetDecl object) { - return new ComparisonMachine<>(object, TargetDecl.class) - .equalAsObjects(TargetDecl::getName) - .equivalentModulo( - TargetDecl::getConfig, - (KeyValuePairs it) -> it != null && it.getPairs().isEmpty() ? null : it - ) - .conclusion; - } - - @Override - public Boolean caseStateVar(StateVar object) { - return new ComparisonMachine<>(object, StateVar.class) - .listsEquivalent(StateVar::getAttributes) - .equalAsObjects(StateVar::getName) - .equivalent(StateVar::getType) - .equivalent(StateVar::getInit) - .conclusion; - } - - @Override - public Boolean caseInitializer(Initializer object) { - // Empty braces are not equivalent to no init. - return new ComparisonMachine<>(object, Initializer.class) - .equalAsObjects(Initializer::isBraces) - // An initializer with no parens is equivalent to one with parens, - // if the list has a single element. This is probably going to change - // when we introduce equals initializers. - // .equalAsObjects(Initializer::isParens) - .listsEquivalent(Initializer::getExprs) - .conclusion; - } - - @Override - public Boolean caseMethod(Method object) { - return new ComparisonMachine<>(object, Method.class) - .equalAsObjects(Method::isConst) - .equalAsObjects(Method::getName) - .listsEquivalent(Method::getArguments) - .equivalent(Method::getReturn) - .equivalent(Method::getCode) - .conclusion; - } - - @Override - public Boolean caseMethodArgument(MethodArgument object) { - return new ComparisonMachine<>(object, MethodArgument.class) - .equalAsObjects(MethodArgument::getName) - .equivalent(MethodArgument::getType) - .conclusion; - } - - @Override - public Boolean caseInput(Input object) { - return new ComparisonMachine<>(object, Input.class) - .listsEquivalent(Input::getAttributes) - .equalAsObjects(Input::isMutable) - .equivalent(Input::getWidthSpec) - .equivalent(Input::getType) - .conclusion; - } - - @Override - public Boolean caseOutput(Output object) { - return new ComparisonMachine<>(object, Output.class) - .listsEquivalent(Output::getAttributes) - .equivalent(Output::getWidthSpec) - .equalAsObjects(Output::getName) - .equivalent(Output::getType) - .conclusion; - } - - @Override - public Boolean caseTimer(Timer object) { - return new ComparisonMachine<>(object, Timer.class) - .listsEquivalent(Timer::getAttributes) - .equalAsObjects(Timer::getName) - .equivalent(Timer::getOffset) - .equivalent(Timer::getPeriod) - .conclusion; - } - - @Override - public Boolean caseMode(Mode object) { - return new ComparisonMachine<>(object, Mode.class) - .equalAsObjects(Mode::isInitial) - .equalAsObjects(Mode::getName) - .listsEquivalent(Mode::getStateVars) - .listsEquivalent(Mode::getTimers) - .listsEquivalent(Mode::getActions) - .listsEquivalent(Mode::getInstantiations) - .listsEquivalent(Mode::getConnections) - .listsEquivalent(Mode::getReactions) - .conclusion; - } - - @Override - public Boolean caseAction(Action object) { - return new ComparisonMachine<>(object, Action.class) - .listsEquivalent(Action::getAttributes) - .equalAsObjects(Action::getOrigin) // This is an enum - .equalAsObjects(Action::getName) - .equivalent(Action::getMinDelay) - .equivalent(Action::getMinSpacing) - .equalAsObjects(Action::getPolicy) - .equivalent(Action::getType) - .conclusion; - } - - @Override - public Boolean caseAttribute(Attribute object) { - return new ComparisonMachine<>(object, Attribute.class) - .equalAsObjects(Attribute::getAttrName) - .listsEquivalent(Attribute::getAttrParms) - .conclusion; - } - - @Override - public Boolean caseAttrParm(AttrParm object) { - return new ComparisonMachine<>(object, AttrParm.class) - .equalAsObjects(AttrParm::getName) - .equalAsObjects(AttrParm::getValue) - .conclusion; - } - - @Override - public Boolean caseReaction(Reaction object) { - return new ComparisonMachine<>(object, Reaction.class) - .listsEquivalent(Reaction::getAttributes) - .listsEquivalent(Reaction::getTriggers) - .listsEquivalent(Reaction::getSources) - .listsEquivalent(Reaction::getEffects) - .equalAsObjects(Reaction::isMutation) - .equivalent(Reaction::getCode) - .equivalent(Reaction::getStp) - .equivalent(Reaction::getDeadline) - .conclusion; - } - - @Override - public Boolean caseTriggerRef(TriggerRef object) { - throw thereIsAMoreSpecificCase(TriggerRef.class, BuiltinTriggerRef.class, VarRef.class); - } - - @Override - public Boolean caseBuiltinTriggerRef(BuiltinTriggerRef object) { - return new ComparisonMachine<>(object, BuiltinTriggerRef.class) - .equalAsObjects(BuiltinTriggerRef::getType) // This is an enum - .conclusion; - } - - @Override - public Boolean caseDeadline(Deadline object) { - return new ComparisonMachine<>(object, Deadline.class) - .equivalent(Deadline::getDelay) - .equivalent(Deadline::getCode) - .conclusion; - } - - @Override - public Boolean caseSTP(STP object) { - return new ComparisonMachine<>(object, STP.class) - .equivalent(STP::getValue) - .equivalent(STP::getCode) - .conclusion; - } - - - @Override - public Boolean casePreamble(Preamble object) { - return new ComparisonMachine<>(object, Preamble.class) - .equalAsObjects(Preamble::getVisibility) // This is an enum - .equivalent(Preamble::getCode) - .conclusion; - } - - @Override - public Boolean caseInstantiation(Instantiation object) { - return new ComparisonMachine<>(object, Instantiation.class) - .equalAsObjects(Instantiation::getName) - .equivalent(Instantiation::getWidthSpec) - .equivalent(Instantiation::getReactorClass) - .listsEquivalent(Instantiation::getTypeArgs) - .listsEquivalent(Instantiation::getParameters) - .equivalent(Instantiation::getHost) - .conclusion; - } - - @Override - public Boolean caseConnection(Connection object) { - return new ComparisonMachine<>(object, Connection.class) - .listsEquivalent(Connection::getLeftPorts) - .equalAsObjects(Connection::isIterated) - .equalAsObjects(Connection::isPhysical) - .listsEquivalent(Connection::getRightPorts) - .equivalent(Connection::getDelay) - .equivalent(Connection::getSerializer) - .conclusion; - } - - @Override - public Boolean caseSerializer(Serializer object) { - return new ComparisonMachine<>(object, Serializer.class) - .equalAsObjects(Serializer::getType) - .conclusion; - } - - @Override - public Boolean caseKeyValuePairs(KeyValuePairs object) { - return new ComparisonMachine<>(object, KeyValuePairs.class) - .listsEquivalent(KeyValuePairs::getPairs) - .conclusion; - } - - @Override - public Boolean caseKeyValuePair(KeyValuePair object) { - return new ComparisonMachine<>(object, KeyValuePair.class) - .equalAsObjects(KeyValuePair::getName) - .equivalent(KeyValuePair::getValue) - .conclusion; - } - - @Override - public Boolean caseArray(Array object) { - return new ComparisonMachine<>(object, Array.class) - .listsEquivalent(Array::getElements) - .conclusion; - } - - @Override - public Boolean caseElement(Element object) { - return new ComparisonMachine<>(object, Element.class) - .equivalent(Element::getKeyvalue) - .equivalent(Element::getArray) - .equalAsObjects(Element::getLiteral) - .equalAsObjects(Element::getId) - .equalAsObjects(Element::getUnit) - .conclusion; - } - - @Override - public Boolean caseTypedVariable(TypedVariable object) { - throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); - } - - @Override - public Boolean caseVariable(Variable object) { - throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class); - } - - @Override - public Boolean caseVarRef(VarRef object) { - return new ComparisonMachine<>(object, VarRef.class) - .equalAsObjects(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable().getName()) - .equivalent(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable()) - .equalAsObjects(varRef -> varRef.getContainer() == null ? null : varRef.getContainer().getName()) - .equalAsObjects(VarRef::isInterleaved) - .equalAsObjects(VarRef::getTransition) - .conclusion; - } - - @Override - public Boolean caseAssignment(Assignment object) { - return new ComparisonMachine<>(object, Assignment.class) - .equivalent(Assignment::getLhs) - .equivalent(Assignment::getRhs) - .conclusion; - } - - @Override - public Boolean caseParameter(Parameter object) { - return new ComparisonMachine<>(object, Parameter.class) - .listsEquivalent(Parameter::getAttributes) - .equalAsObjects(Parameter::getName) - .equivalent(Parameter::getType) - .equivalent(Parameter::getInit) - .conclusion; - } - - @Override - public Boolean caseExpression(Expression object) { - throw thereIsAMoreSpecificCase( - Expression.class, - Literal.class, - Time.class, - ParameterReference.class, - Code.class, - BracedListExpression.class - ); - } - - @Override - public Boolean caseBracedListExpression(BracedListExpression object) { - return new ComparisonMachine<>(object, BracedListExpression.class) - .listsEquivalent(BracedListExpression::getItems) - .conclusion; - } - - @Override - public Boolean caseParameterReference(ParameterReference object) { - return new ComparisonMachine<>(object, ParameterReference.class) - .equivalent(ParameterReference::getParameter) - .conclusion; - } - - @Override - public Boolean caseTime(Time object) { - return new ComparisonMachine<>(object, Time.class) - .equalAsObjects(Time::getInterval) - .equalAsObjectsModulo( - Time::getUnit, - ((Function) TimeUnit::getCanonicalName) - .compose(TimeUnit::fromName) - ) - .conclusion; - } - - @Override - public Boolean casePort(Port object) { - throw thereIsAMoreSpecificCase(Port.class, Input.class, Output.class); - } - - @Override - public Boolean caseType(Type object) { - return new ComparisonMachine<>(object, Type.class) - .equivalent(Type::getCode) - .equalAsObjects(Type::isTime) - .equivalent(Type::getArraySpec) - .equalAsObjects(Type::getId) - .listsEquivalent(Type::getTypeArgs) - .listsEqualAsObjects(Type::getStars) - .equivalent(Type::getArraySpec) - .equivalent(Type::getCode) - .conclusion; - } - - @Override - public Boolean caseArraySpec(ArraySpec object) { - return new ComparisonMachine<>(object, ArraySpec.class) - .equalAsObjects(ArraySpec::isOfVariableLength) - .equalAsObjects(ArraySpec::getLength) - .conclusion; - } - - @Override - public Boolean caseWatchdog(Watchdog object) { - return new ComparisonMachine<>(object, Watchdog.class) - .equalAsObjects(Watchdog::getName) - .equivalent(Watchdog::getTimeout) - .listsEquivalent(Watchdog::getEffects) - .equivalent(Watchdog::getCode) - .conclusion; - } - - @Override - public Boolean caseWidthSpec(WidthSpec object) { - return new ComparisonMachine<>(object, WidthSpec.class) - .equalAsObjects(WidthSpec::isOfVariableLength) - .listsEquivalent(WidthSpec::getTerms) - .conclusion; - } - - @Override - public Boolean caseWidthTerm(WidthTerm object) { - return new ComparisonMachine<>(object, WidthTerm.class) - .equalAsObjects(WidthTerm::getWidth) - .equivalent(WidthTerm::getParameter) - .equivalent(WidthTerm::getPort) - .equivalent(WidthTerm::getCode) - .conclusion; - } - - @Override - public Boolean caseIPV4Host(IPV4Host object) { - return caseHost(object); - } - - @Override - public Boolean caseIPV6Host(IPV6Host object) { - return caseHost(object); - } - - @Override - public Boolean caseNamedHost(NamedHost object) { - return caseHost(object); - } - - @Override - public Boolean caseHost(Host object) { - return new ComparisonMachine<>(object, Host.class) - .equalAsObjects(Host::getUser) - .equalAsObjects(Host::getAddr) - .equalAsObjects(Host::getPort) - .conclusion; - } - - @Override - public Boolean caseCodeExpr(CodeExpr object) { - return new ComparisonMachine<>(object, CodeExpr.class).equivalent(CodeExpr::getCode).conclusion; - } - - @Override - public Boolean caseCode(Code object) { - return new ComparisonMachine<>(object, Code.class) - .equalAsObjectsModulo( - Code::getBody, - s -> s == null ? null : s.strip().stripIndent() - ) - .conclusion; - } - - @Override - public Boolean caseLiteral(Literal object) { - return new ComparisonMachine<>(object, Literal.class) - .equalAsObjects(Literal::getLiteral) - .conclusion; - } - - @Override - public Boolean defaultCase(EObject object) { - return super.defaultCase(object); - } - - @SafeVarargs - private UnsupportedOperationException thereIsAMoreSpecificCase( - Class thisCase, - Class... moreSpecificCases - ) { - return new UnsupportedOperationException(String.format( + private final EObject otherObject; + + public IsEqual(EObject other) { + this.otherObject = other; + } + + @Override + public Boolean doSwitch(EObject eObject) { + if (otherObject == eObject) return true; + if (eObject == null) return false; + return super.doSwitch(eObject); + } + + @Override + public Boolean caseModel(Model object) { + return new ComparisonMachine<>(object, Model.class) + .equivalent(Model::getTarget) + .listsEquivalent(Model::getImports) + .listsEquivalent(Model::getPreambles) + .listsEquivalent(Model::getReactors) + .conclusion; + } + + @Override + public Boolean caseImport(Import object) { + return new ComparisonMachine<>(object, Import.class) + .equalAsObjects(Import::getImportURI) + .listsEquivalent(Import::getReactorClasses) + .conclusion; + } + + @Override + public Boolean caseReactorDecl(ReactorDecl object) { + return new ComparisonMachine<>(object, ReactorDecl.class) + .equalAsObjects(ReactorDecl::getName) + .conclusion; + } + + @Override + public Boolean caseImportedReactor(ImportedReactor object) { + return new ComparisonMachine<>(object, ImportedReactor.class) + .equalAsObjects(ImportedReactor::getName) + .equivalent(ImportedReactor::getReactorClass) + .conclusion; + } + + @Override + public Boolean caseReactor(Reactor object) { + return new ComparisonMachine<>(object, Reactor.class) + .listsEquivalent(Reactor::getAttributes) + .equalAsObjects(Reactor::isFederated) + .equalAsObjects(Reactor::isRealtime) + .equalAsObjects(Reactor::isMain) + .equalAsObjects(Reactor::getName) + .listsEquivalent(Reactor::getTypeParms) + .listsEquivalent(Reactor::getParameters) + .equivalent(Reactor::getHost) + .listsEquivalent(Reactor::getSuperClasses) + .listsEquivalent(Reactor::getPreambles) + .listsEquivalent(Reactor::getInputs) + .listsEquivalent(Reactor::getOutputs) + .listsEquivalent(Reactor::getTimers) + .listsEquivalent(Reactor::getActions) + .listsEquivalent(Reactor::getInstantiations) + .listsEquivalent(Reactor::getConnections) + .listsEquivalent(Reactor::getStateVars) + .listsEquivalent(Reactor::getReactions) + .listsEquivalent(Reactor::getMethods) + .listsEquivalent(Reactor::getModes) + .conclusion; + } + + @Override + public Boolean caseTypeParm(TypeParm object) { + return new ComparisonMachine<>(object, TypeParm.class) + .equalAsObjects(TypeParm::getLiteral) + .equivalent(TypeParm::getCode) + .conclusion; + } + + @Override + public Boolean caseTargetDecl(TargetDecl object) { + return new ComparisonMachine<>(object, TargetDecl.class) + .equalAsObjects(TargetDecl::getName) + .equivalentModulo( + TargetDecl::getConfig, + (KeyValuePairs it) -> it != null && it.getPairs().isEmpty() ? null : it) + .conclusion; + } + + @Override + public Boolean caseStateVar(StateVar object) { + return new ComparisonMachine<>(object, StateVar.class) + .listsEquivalent(StateVar::getAttributes) + .equalAsObjects(StateVar::getName) + .equivalent(StateVar::getType) + .equivalent(StateVar::getInit) + .conclusion; + } + + @Override + public Boolean caseInitializer(Initializer object) { + // Empty braces are not equivalent to no init. + return new ComparisonMachine<>(object, Initializer.class) + .equalAsObjects(Initializer::isBraces) + // An initializer with no parens is equivalent to one with parens, + // if the list has a single element. This is probably going to change + // when we introduce equals initializers. + // .equalAsObjects(Initializer::isParens) + .listsEquivalent(Initializer::getExprs) + .conclusion; + } + + @Override + public Boolean caseMethod(Method object) { + return new ComparisonMachine<>(object, Method.class) + .equalAsObjects(Method::isConst) + .equalAsObjects(Method::getName) + .listsEquivalent(Method::getArguments) + .equivalent(Method::getReturn) + .equivalent(Method::getCode) + .conclusion; + } + + @Override + public Boolean caseMethodArgument(MethodArgument object) { + return new ComparisonMachine<>(object, MethodArgument.class) + .equalAsObjects(MethodArgument::getName) + .equivalent(MethodArgument::getType) + .conclusion; + } + + @Override + public Boolean caseInput(Input object) { + return new ComparisonMachine<>(object, Input.class) + .listsEquivalent(Input::getAttributes) + .equalAsObjects(Input::isMutable) + .equivalent(Input::getWidthSpec) + .equivalent(Input::getType) + .conclusion; + } + + @Override + public Boolean caseOutput(Output object) { + return new ComparisonMachine<>(object, Output.class) + .listsEquivalent(Output::getAttributes) + .equivalent(Output::getWidthSpec) + .equalAsObjects(Output::getName) + .equivalent(Output::getType) + .conclusion; + } + + @Override + public Boolean caseTimer(Timer object) { + return new ComparisonMachine<>(object, Timer.class) + .listsEquivalent(Timer::getAttributes) + .equalAsObjects(Timer::getName) + .equivalent(Timer::getOffset) + .equivalent(Timer::getPeriod) + .conclusion; + } + + @Override + public Boolean caseMode(Mode object) { + return new ComparisonMachine<>(object, Mode.class) + .equalAsObjects(Mode::isInitial) + .equalAsObjects(Mode::getName) + .listsEquivalent(Mode::getStateVars) + .listsEquivalent(Mode::getTimers) + .listsEquivalent(Mode::getActions) + .listsEquivalent(Mode::getInstantiations) + .listsEquivalent(Mode::getConnections) + .listsEquivalent(Mode::getReactions) + .conclusion; + } + + @Override + public Boolean caseAction(Action object) { + return new ComparisonMachine<>(object, Action.class) + .listsEquivalent(Action::getAttributes) + .equalAsObjects(Action::getOrigin) // This is an enum + .equalAsObjects(Action::getName) + .equivalent(Action::getMinDelay) + .equivalent(Action::getMinSpacing) + .equalAsObjects(Action::getPolicy) + .equivalent(Action::getType) + .conclusion; + } + + @Override + public Boolean caseAttribute(Attribute object) { + return new ComparisonMachine<>(object, Attribute.class) + .equalAsObjects(Attribute::getAttrName) + .listsEquivalent(Attribute::getAttrParms) + .conclusion; + } + + @Override + public Boolean caseAttrParm(AttrParm object) { + return new ComparisonMachine<>(object, AttrParm.class) + .equalAsObjects(AttrParm::getName) + .equalAsObjects(AttrParm::getValue) + .conclusion; + } + + @Override + public Boolean caseReaction(Reaction object) { + return new ComparisonMachine<>(object, Reaction.class) + .listsEquivalent(Reaction::getAttributes) + .listsEquivalent(Reaction::getTriggers) + .listsEquivalent(Reaction::getSources) + .listsEquivalent(Reaction::getEffects) + .equalAsObjects(Reaction::isMutation) + .equivalent(Reaction::getCode) + .equivalent(Reaction::getStp) + .equivalent(Reaction::getDeadline) + .conclusion; + } + + @Override + public Boolean caseTriggerRef(TriggerRef object) { + throw thereIsAMoreSpecificCase(TriggerRef.class, BuiltinTriggerRef.class, VarRef.class); + } + + @Override + public Boolean caseBuiltinTriggerRef(BuiltinTriggerRef object) { + return new ComparisonMachine<>(object, BuiltinTriggerRef.class) + .equalAsObjects(BuiltinTriggerRef::getType) // This is an enum + .conclusion; + } + + @Override + public Boolean caseDeadline(Deadline object) { + return new ComparisonMachine<>(object, Deadline.class) + .equivalent(Deadline::getDelay) + .equivalent(Deadline::getCode) + .conclusion; + } + + @Override + public Boolean caseSTP(STP object) { + return new ComparisonMachine<>(object, STP.class) + .equivalent(STP::getValue) + .equivalent(STP::getCode) + .conclusion; + } + + @Override + public Boolean casePreamble(Preamble object) { + return new ComparisonMachine<>(object, Preamble.class) + .equalAsObjects(Preamble::getVisibility) // This is an enum + .equivalent(Preamble::getCode) + .conclusion; + } + + @Override + public Boolean caseInstantiation(Instantiation object) { + return new ComparisonMachine<>(object, Instantiation.class) + .equalAsObjects(Instantiation::getName) + .equivalent(Instantiation::getWidthSpec) + .equivalent(Instantiation::getReactorClass) + .listsEquivalent(Instantiation::getTypeArgs) + .listsEquivalent(Instantiation::getParameters) + .equivalent(Instantiation::getHost) + .conclusion; + } + + @Override + public Boolean caseConnection(Connection object) { + return new ComparisonMachine<>(object, Connection.class) + .listsEquivalent(Connection::getLeftPorts) + .equalAsObjects(Connection::isIterated) + .equalAsObjects(Connection::isPhysical) + .listsEquivalent(Connection::getRightPorts) + .equivalent(Connection::getDelay) + .equivalent(Connection::getSerializer) + .conclusion; + } + + @Override + public Boolean caseSerializer(Serializer object) { + return new ComparisonMachine<>(object, Serializer.class) + .equalAsObjects(Serializer::getType) + .conclusion; + } + + @Override + public Boolean caseKeyValuePairs(KeyValuePairs object) { + return new ComparisonMachine<>(object, KeyValuePairs.class) + .listsEquivalent(KeyValuePairs::getPairs) + .conclusion; + } + + @Override + public Boolean caseKeyValuePair(KeyValuePair object) { + return new ComparisonMachine<>(object, KeyValuePair.class) + .equalAsObjects(KeyValuePair::getName) + .equivalent(KeyValuePair::getValue) + .conclusion; + } + + @Override + public Boolean caseArray(Array object) { + return new ComparisonMachine<>(object, Array.class) + .listsEquivalent(Array::getElements) + .conclusion; + } + + @Override + public Boolean caseElement(Element object) { + return new ComparisonMachine<>(object, Element.class) + .equivalent(Element::getKeyvalue) + .equivalent(Element::getArray) + .equalAsObjects(Element::getLiteral) + .equalAsObjects(Element::getId) + .equalAsObjects(Element::getUnit) + .conclusion; + } + + @Override + public Boolean caseTypedVariable(TypedVariable object) { + throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); + } + + @Override + public Boolean caseVariable(Variable object) { + throw thereIsAMoreSpecificCase( + Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class); + } + + @Override + public Boolean caseVarRef(VarRef object) { + return new ComparisonMachine<>(object, VarRef.class) + .equalAsObjects( + varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable().getName()) + .equivalent(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable()) + .equalAsObjects( + varRef -> varRef.getContainer() == null ? null : varRef.getContainer().getName()) + .equalAsObjects(VarRef::isInterleaved) + .equalAsObjects(VarRef::getTransition) + .conclusion; + } + + @Override + public Boolean caseAssignment(Assignment object) { + return new ComparisonMachine<>(object, Assignment.class) + .equivalent(Assignment::getLhs) + .equivalent(Assignment::getRhs) + .conclusion; + } + + @Override + public Boolean caseParameter(Parameter object) { + return new ComparisonMachine<>(object, Parameter.class) + .listsEquivalent(Parameter::getAttributes) + .equalAsObjects(Parameter::getName) + .equivalent(Parameter::getType) + .equivalent(Parameter::getInit) + .conclusion; + } + + @Override + public Boolean caseExpression(Expression object) { + throw thereIsAMoreSpecificCase( + Expression.class, + Literal.class, + Time.class, + ParameterReference.class, + Code.class, + BracedListExpression.class); + } + + @Override + public Boolean caseBracedListExpression(BracedListExpression object) { + return new ComparisonMachine<>(object, BracedListExpression.class) + .listsEquivalent(BracedListExpression::getItems) + .conclusion; + } + + @Override + public Boolean caseParameterReference(ParameterReference object) { + return new ComparisonMachine<>(object, ParameterReference.class) + .equivalent(ParameterReference::getParameter) + .conclusion; + } + + @Override + public Boolean caseTime(Time object) { + return new ComparisonMachine<>(object, Time.class) + .equalAsObjects(Time::getInterval) + .equalAsObjectsModulo( + Time::getUnit, + ((Function) TimeUnit::getCanonicalName).compose(TimeUnit::fromName)) + .conclusion; + } + + @Override + public Boolean casePort(Port object) { + throw thereIsAMoreSpecificCase(Port.class, Input.class, Output.class); + } + + @Override + public Boolean caseType(Type object) { + return new ComparisonMachine<>(object, Type.class) + .equivalent(Type::getCode) + .equalAsObjects(Type::isTime) + .equivalent(Type::getArraySpec) + .equalAsObjects(Type::getId) + .listsEquivalent(Type::getTypeArgs) + .listsEqualAsObjects(Type::getStars) + .equivalent(Type::getArraySpec) + .equivalent(Type::getCode) + .conclusion; + } + + @Override + public Boolean caseArraySpec(ArraySpec object) { + return new ComparisonMachine<>(object, ArraySpec.class) + .equalAsObjects(ArraySpec::isOfVariableLength) + .equalAsObjects(ArraySpec::getLength) + .conclusion; + } + + @Override + public Boolean caseWatchdog(Watchdog object) { + return new ComparisonMachine<>(object, Watchdog.class) + .equalAsObjects(Watchdog::getName) + .equivalent(Watchdog::getTimeout) + .listsEquivalent(Watchdog::getEffects) + .equivalent(Watchdog::getCode) + .conclusion; + } + + @Override + public Boolean caseWidthSpec(WidthSpec object) { + return new ComparisonMachine<>(object, WidthSpec.class) + .equalAsObjects(WidthSpec::isOfVariableLength) + .listsEquivalent(WidthSpec::getTerms) + .conclusion; + } + + @Override + public Boolean caseWidthTerm(WidthTerm object) { + return new ComparisonMachine<>(object, WidthTerm.class) + .equalAsObjects(WidthTerm::getWidth) + .equivalent(WidthTerm::getParameter) + .equivalent(WidthTerm::getPort) + .equivalent(WidthTerm::getCode) + .conclusion; + } + + @Override + public Boolean caseIPV4Host(IPV4Host object) { + return caseHost(object); + } + + @Override + public Boolean caseIPV6Host(IPV6Host object) { + return caseHost(object); + } + + @Override + public Boolean caseNamedHost(NamedHost object) { + return caseHost(object); + } + + @Override + public Boolean caseHost(Host object) { + return new ComparisonMachine<>(object, Host.class) + .equalAsObjects(Host::getUser) + .equalAsObjects(Host::getAddr) + .equalAsObjects(Host::getPort) + .conclusion; + } + + @Override + public Boolean caseCodeExpr(CodeExpr object) { + return new ComparisonMachine<>(object, CodeExpr.class).equivalent(CodeExpr::getCode).conclusion; + } + + @Override + public Boolean caseCode(Code object) { + return new ComparisonMachine<>(object, Code.class) + .equalAsObjectsModulo(Code::getBody, s -> s == null ? null : s.strip().stripIndent()) + .conclusion; + } + + @Override + public Boolean caseLiteral(Literal object) { + return new ComparisonMachine<>(object, Literal.class) + .equalAsObjects(Literal::getLiteral) + .conclusion; + } + + @Override + public Boolean defaultCase(EObject object) { + return super.defaultCase(object); + } + + @SafeVarargs + private UnsupportedOperationException thereIsAMoreSpecificCase( + Class thisCase, Class... moreSpecificCases) { + return new UnsupportedOperationException( + String.format( "%ss are %s, so the methods " + "corresponding to those types should be invoked instead.", thisCase.getName(), Arrays.stream(moreSpecificCases) - .map(Class::getName) - .map(it -> it + (it.endsWith("s") ? "es" : "s")) - .collect(Collectors.joining(" or ")) - )); - } - - /** Fluently compare a pair of parse tree nodes for equivalence. */ - private class ComparisonMachine { - private final E object; - private final E other; - private boolean conclusion; - - ComparisonMachine(E object, Class clz) { - this.object = object; - this.conclusion = clz.isInstance(otherObject); - this.other = conclusion ? clz.cast(otherObject) : null; + .map(Class::getName) + .map(it -> it + (it.endsWith("s") ? "es" : "s")) + .collect(Collectors.joining(" or ")))); + } + + /** Fluently compare a pair of parse tree nodes for equivalence. */ + private class ComparisonMachine { + private final E object; + private final E other; + private boolean conclusion; + + ComparisonMachine(E object, Class clz) { + this.object = object; + this.conclusion = clz.isInstance(otherObject); + this.other = conclusion ? clz.cast(otherObject) : null; + } + + /** Conclude false if the two given Lists are different as EObject sequences. Order matters. */ + ComparisonMachine listsEquivalent(Function> listGetter) { + if (conclusion) + conclusion = listsEqualish(listGetter, (T a, T b) -> new IsEqual(a).doSwitch(b)); + return this; + } + + /** Conclude false if the two given Lists are different as object sequences. Order matters. */ + ComparisonMachine listsEqualAsObjects(Function> listGetter) { + if (conclusion) conclusion = listsEqualish(listGetter, Objects::equals); + return this; + } + + boolean listsEqualish( + Function> listGetter, BiPredicate equalish) { + if (!conclusion) return false; + List list0 = listGetter.apply(object); + List list1 = listGetter.apply(other); + if (list0 == list1) return true; // e.g., they are both null + if (list0.size() != list1.size()) return false; + for (int i = 0; i < list0.size(); i++) { + if (!equalish.test(list0.get(i), list1.get(i))) { + return false; } - - /** - * Conclude false if the two given Lists are different as EObject - * sequences. Order matters. - */ - ComparisonMachine listsEquivalent(Function> listGetter) { - if (conclusion) conclusion = listsEqualish(listGetter, (T a, T b) -> new IsEqual(a).doSwitch(b)); - return this; - } - - /** - * Conclude false if the two given Lists are different as object - * sequences. Order matters. - */ - ComparisonMachine listsEqualAsObjects(Function> listGetter) { - if (conclusion) conclusion = listsEqualish(listGetter, Objects::equals); - return this; - } - - boolean listsEqualish(Function> listGetter, BiPredicate equalish) { - if (!conclusion) return false; - List list0 = listGetter.apply(object); - List list1 = listGetter.apply(other); - if (list0 == list1) return true; // e.g., they are both null - if (list0.size() != list1.size()) return false; - for (int i = 0; i < list0.size(); i++) { - if (!equalish.test(list0.get(i), list1.get(i))) { - return false; - } - } - return true; - } - - /** Conclude false if the two properties are not equal as objects. */ - ComparisonMachine equalAsObjects(Function propertyGetter) { - return equalAsObjectsModulo(propertyGetter, Function.identity()); - } - - /** - * Conclude false if the two properties are not equal as objects, - * given that {@code projectionToClassRepresentatives} maps each - * object to some semantically equivalent object. - */ - ComparisonMachine equalAsObjectsModulo( - Function propertyGetter, - Function projectionToClassRepresentatives - ) { - if (propertyGetter.apply(object) instanceof EObject) { - throw new IllegalArgumentException( - "EObjects should be compared for semantic equivalence, not object equality." - ); - } - propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); - if (conclusion) conclusion = Objects.equals(propertyGetter.apply(object), propertyGetter.apply(other)); - return this; - } - - /** - * Conclude false if the two properties are not semantically equivalent - * parse nodes. - */ - ComparisonMachine equivalent(Function propertyGetter) { - return equivalentModulo(propertyGetter, Function.identity()); - } - - /** - * Conclude false if the two properties are not semantically equivalent - * parse nodes, given that {@code projectionToClassRepresentatives} - * maps each parse node to some semantically equivalent node. - */ - ComparisonMachine equivalentModulo( - Function propertyGetter, - Function projectionToClassRepresentatives - ) { - propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); - if (conclusion) conclusion = new IsEqual(propertyGetter.apply(object)) - .doSwitch(propertyGetter.apply(other)); - return this; - } - } + } + return true; + } + + /** Conclude false if the two properties are not equal as objects. */ + ComparisonMachine equalAsObjects(Function propertyGetter) { + return equalAsObjectsModulo(propertyGetter, Function.identity()); + } + + /** + * Conclude false if the two properties are not equal as objects, given that {@code + * projectionToClassRepresentatives} maps each object to some semantically equivalent object. + */ + ComparisonMachine equalAsObjectsModulo( + Function propertyGetter, Function projectionToClassRepresentatives) { + if (propertyGetter.apply(object) instanceof EObject) { + throw new IllegalArgumentException( + "EObjects should be compared for semantic equivalence, not object equality."); + } + propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); + if (conclusion) + conclusion = Objects.equals(propertyGetter.apply(object), propertyGetter.apply(other)); + return this; + } + + /** Conclude false if the two properties are not semantically equivalent parse nodes. */ + ComparisonMachine equivalent(Function propertyGetter) { + return equivalentModulo(propertyGetter, Function.identity()); + } + + /** + * Conclude false if the two properties are not semantically equivalent parse nodes, given that + * {@code projectionToClassRepresentatives} maps each parse node to some semantically equivalent + * node. + */ + ComparisonMachine equivalentModulo( + Function propertyGetter, Function projectionToClassRepresentatives) { + propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); + if (conclusion) + conclusion = + new IsEqual(propertyGetter.apply(object)).doSwitch(propertyGetter.apply(other)); + return this; + } + } } diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index be8a68cf7d..2f0ec76d9b 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -881,9 +881,8 @@ public MalleableString caseInitializer(Initializer object) { } /** - * Return true if the initializer should be output with an equals initializer. - * Old-style assignments with parentheses are also output that - * way to help with the transition. + * Return true if the initializer should be output with an equals initializer. Old-style + * assignments with parentheses are also output that way to help with the transition. */ private boolean shouldOutputAsAssignment(Initializer init) { return init.isAssign() @@ -919,7 +918,6 @@ private MalleableString initializer(Initializer init) { return list(", ", prefix, suffix, false, false, init.getExprs()); } - @Override public MalleableString caseParameter(Parameter object) { // name=ID (':' (type=Type))? diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index c0475ad37d..349ff0fff7 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -1,30 +1,31 @@ -/** Instance of a federate specification. +/** + * Instance of a federate specification. * -Copyright (c) 2020, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ - + *

Copyright (c) 2020, The University of California at Berkeley. + * + *

Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + *

1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + *

2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided with + * the distribution. + * + *

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ************* + */ package org.lflang.federated.generator; +import com.google.common.base.Objects; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -34,9 +35,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.EObject; - import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.TargetConfig; @@ -66,597 +65,557 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.VarRef; import org.lflang.lf.Variable; -import com.google.common.base.Objects; - - /** - * Instance of a federate, or marker that no federation has been defined - * (if isSingleton() returns true) FIXME: this comment makes no sense. - * Every top-level reactor (contained - * directly by the main reactor) is a federate, so there will be one - * instance of this class for each top-level reactor. + * Instance of a federate, or marker that no federation has been defined (if isSingleton() returns + * true) FIXME: this comment makes no sense. Every top-level reactor (contained directly by the main + * reactor) is a federate, so there will be one instance of this class for each top-level reactor. * * @author Edward A. Lee * @author Soroush Bateni */ public class FederateInstance { // why does this not extend ReactorInstance? - /** - * Construct a new instance with the specified instantiation of - * of a top-level reactor. The federate will be given the specified - * integer ID. - * @param instantiation The instantiation of a top-level reactor, - * or null if no federation has been defined. - * @param id The federate ID. - * @param bankIndex If instantiation.widthSpec !== null, this gives the bank position. - * @param errorReporter The error reporter - */ - public FederateInstance( - Instantiation instantiation, - int id, - int bankIndex, - TargetConfig targetConfig, - ErrorReporter errorReporter) { - this.instantiation = instantiation; - this.id = id; - this.bankIndex = bankIndex; - this.errorReporter = errorReporter; - this.targetConfig = targetConfig; - - if (instantiation != null) { - this.name = instantiation.getName(); - // If the instantiation is in a bank, then we have to append - // the bank index to the name. - if (instantiation.getWidthSpec() != null) { - this.name = instantiation.getName() + "__" + bankIndex; - } - } + /** + * Construct a new instance with the specified instantiation of of a top-level reactor. The + * federate will be given the specified integer ID. + * + * @param instantiation The instantiation of a top-level reactor, or null if no federation has + * been defined. + * @param id The federate ID. + * @param bankIndex If instantiation.widthSpec !== null, this gives the bank position. + * @param errorReporter The error reporter + */ + public FederateInstance( + Instantiation instantiation, + int id, + int bankIndex, + TargetConfig targetConfig, + ErrorReporter errorReporter) { + this.instantiation = instantiation; + this.id = id; + this.bankIndex = bankIndex; + this.errorReporter = errorReporter; + this.targetConfig = targetConfig; + + if (instantiation != null) { + this.name = instantiation.getName(); + // If the instantiation is in a bank, then we have to append + // the bank index to the name. + if (instantiation.getWidthSpec() != null) { + this.name = instantiation.getName() + "__" + bankIndex; + } } - - ///////////////////////////////////////////// - //// Public Fields - - /** - * The position within a bank of reactors for this federate. - * This is 0 if the instantiation is not a bank of reactors. - */ - public int bankIndex = 0; - - /** - * A list of outputs that can be triggered directly or indirectly by physical actions. - */ - public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); - - /** - * The host, if specified using the 'at' keyword. - */ - public String host = "localhost"; - - - /** - * The instantiation of the top-level reactor, or null if there is no federation. - */ - public Instantiation instantiation; - public Instantiation getInstantiation() { - return instantiation; + } + + ///////////////////////////////////////////// + //// Public Fields + + /** + * The position within a bank of reactors for this federate. This is 0 if the instantiation is not + * a bank of reactors. + */ + public int bankIndex = 0; + + /** A list of outputs that can be triggered directly or indirectly by physical actions. */ + public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); + + /** The host, if specified using the 'at' keyword. */ + public String host = "localhost"; + + /** The instantiation of the top-level reactor, or null if there is no federation. */ + public Instantiation instantiation; + + public Instantiation getInstantiation() { + return instantiation; + } + + /** A list of individual connections between federates */ + public Set connections = new HashSet<>(); + + /** + * Map from the federates that this federate receives messages from to the delays on connections + * from that federate. The delay set may include null, meaning that there is a connection from the + * federate instance that has no delay. + */ + public Map> dependsOn = new LinkedHashMap<>(); + + /** The directory, if specified using the 'at' keyword. */ + public String dir = null; + + /** The port, if specified using the 'at' keyword. */ + public int port = 0; + + /** + * Map from the federates that this federate sends messages to to the delays on connections to + * that federate. The delay set may may include null, meaning that there is a connection from the + * federate instance that has no delay. + */ + public Map> sendsTo = new LinkedHashMap<>(); + + /** The user, if specified using the 'at' keyword. */ + public String user = null; + + /** The integer ID of this federate. */ + public int id = 0; + + /** + * The name of this federate instance. This will be the instantiation name, possibly appended with + * "__n", where n is the bank position of this instance if the instantiation is of a bank of + * reactors. + */ + public String name = "Unnamed"; + + /** + * List of networkMessage actions. Each of these handles a message received from another federate + * over the network. The ID of receiving port is simply the position of the action in the list. + * The sending federate needs to specify this ID. + */ + public List networkMessageActions = new ArrayList<>(); + + /** + * A set of federates with which this federate has an inbound connection There will only be one + * physical connection even if federate A has defined multiple physical connections to federate B. + * The message handler on federate A will be responsible for including the appropriate information + * in the message header (such as port ID) to help the receiver distinguish different events. + */ + public Set inboundP2PConnections = new LinkedHashSet<>(); + + /** + * A list of federate with which this federate has an outbound physical connection. There will + * only be one physical connection even if federate A has defined multiple physical connections to + * federate B. The message handler on federate B will be responsible for distinguishing the + * incoming messages by parsing their header and scheduling the appropriate action. + */ + public Set outboundP2PConnections = new LinkedHashSet<>(); + + /** + * A list of triggers for network input control reactions. This is used to trigger all the input + * network control reactions that might be nested in a hierarchy. + */ + public List networkInputControlReactionsTriggers = new ArrayList<>(); + + /** + * The trigger that triggers the output control reaction of this federate. + * + *

The network output control reactions send a PORT_ABSENT message for a network output port, + * if it is absent at the current tag, to notify all downstream federates that no value will be + * present on the given network port, allowing input control reactions on those federates to stop + * blocking. + */ + public Variable networkOutputControlReactionsTrigger = null; + + /** Indicates whether the federate is remote or local */ + public boolean isRemote = false; + + /** + * List of generated network reactions (network receivers, network input control reactions, + * network senders, and network output control reactions) that belong to this federate instance. + */ + public List networkReactions = new ArrayList<>(); + + /** Parsed target config of the federate. */ + public TargetConfig targetConfig; + + /** Keep a unique list of enabled serializers */ + public HashSet enabledSerializers = new HashSet<>(); + + /** + * Return true if the specified EObject should be included in the code generated for this + * federate. + * + * @param object An {@code EObject} + * @return True if this federate contains the EObject. + */ + public boolean contains(EObject object) { + if (object instanceof Action) { + return contains((Action) object); + } else if (object instanceof Reaction) { + return contains((Reaction) object); + } else if (object instanceof Timer) { + return contains((Timer) object); + } else if (object instanceof ReactorDecl) { + return contains(this.instantiation, (ReactorDecl) object); + } else if (object instanceof Import) { + return contains((Import) object); + } else if (object instanceof Parameter) { + return contains((Parameter) object); + } else if (object instanceof StateVar) { + return true; // FIXME: Should we disallow state vars at the top level? + } + throw new UnsupportedOperationException( + "EObject class " + object.eClass().getName() + " not supported."); + } + + /** + * Return true if the specified reactor belongs to this federate. + * + * @param instantiation The instantiation to look inside + * @param reactor The reactor declaration to find + */ + private boolean contains(Instantiation instantiation, ReactorDecl reactor) { + if (instantiation.getReactorClass().equals(ASTUtils.toDefinition(reactor))) { + return true; } - /** - * A list of individual connections between federates - */ - public Set connections = new HashSet<>(); - - /** - * Map from the federates that this federate receives messages from - * to the delays on connections from that federate. The delay set - * may include null, meaning that there is a connection - * from the federate instance that has no delay. - */ - public Map> dependsOn = new LinkedHashMap<>(); - - /** - * The directory, if specified using the 'at' keyword. - */ - public String dir = null; - - /** - * The port, if specified using the 'at' keyword. - */ - public int port = 0; - - /** - * Map from the federates that this federate sends messages to - * to the delays on connections to that federate. The delay set - * may may include null, meaning that there is a connection - * from the federate instance that has no delay. - */ - public Map> sendsTo = new LinkedHashMap<>(); - - /** - * The user, if specified using the 'at' keyword. - */ - public String user = null; - - /** - * The integer ID of this federate. - */ - public int id = 0; - - - /** - * The name of this federate instance. This will be the instantiation - * name, possibly appended with "__n", where n is the bank position of - * this instance if the instantiation is of a bank of reactors. - */ - public String name = "Unnamed"; - - /** - * List of networkMessage actions. Each of these handles a message - * received from another federate over the network. The ID of - * receiving port is simply the position of the action in the list. - * The sending federate needs to specify this ID. - */ - public List networkMessageActions = new ArrayList<>(); - - /** - * A set of federates with which this federate has an inbound connection - * There will only be one physical connection even if federate A has defined multiple - * physical connections to federate B. The message handler on federate A will be - * responsible for including the appropriate information in the message header (such as port ID) - * to help the receiver distinguish different events. - */ - public Set inboundP2PConnections = new LinkedHashSet<>(); - - /** - * A list of federate with which this federate has an outbound physical connection. - * There will only be one physical connection even if federate A has defined multiple - * physical connections to federate B. The message handler on federate B will be - * responsible for distinguishing the incoming messages by parsing their header and - * scheduling the appropriate action. - */ - public Set outboundP2PConnections = new LinkedHashSet<>(); - - /** - * A list of triggers for network input control reactions. This is used to trigger - * all the input network control reactions that might be nested in a hierarchy. - */ - public List networkInputControlReactionsTriggers = new ArrayList<>(); - - /** - * The trigger that triggers the output control reaction of this - * federate. - * - * The network output control reactions send a PORT_ABSENT message for a network output port, - * if it is absent at the current tag, to notify all downstream federates that no value will - * be present on the given network port, allowing input control reactions on those federates - * to stop blocking. - */ - public Variable networkOutputControlReactionsTrigger = null; - - /** - * Indicates whether the federate is remote or local - */ - public boolean isRemote = false; - - /** - * List of generated network reactions (network receivers, - * network input control reactions, network senders, and network output control - * reactions) that belong to this federate instance. - */ - public List networkReactions = new ArrayList<>(); - - /** - * Parsed target config of the federate. - */ - public TargetConfig targetConfig; - - /** - * Keep a unique list of enabled serializers - */ - public HashSet enabledSerializers = new HashSet<>(); - - /** - * Return true if the specified EObject should be included in the code - * generated for this federate. - * - * @param object An {@code EObject} - * @return True if this federate contains the EObject. - */ - public boolean contains(EObject object) { - if (object instanceof Action) { - return contains((Action)object); - } else if (object instanceof Reaction) { - return contains((Reaction)object); - } else if (object instanceof Timer) { - return contains((Timer)object); - } else if (object instanceof ReactorDecl) { - return contains(this.instantiation, (ReactorDecl)object); - } else if (object instanceof Import) { - return contains((Import)object); - } else if (object instanceof Parameter) { - return contains((Parameter)object); - } else if (object instanceof StateVar) { - return true; // FIXME: Should we disallow state vars at the top level? - } - throw new UnsupportedOperationException("EObject class "+object.eClass().getName()+" not supported."); + boolean instantiationsCheck = false; + // For a federate, we don't need to look inside imported reactors. + if (instantiation.getReactorClass() instanceof Reactor reactorDef) { + for (Instantiation child : reactorDef.getInstantiations()) { + instantiationsCheck |= contains(child, reactor); + } } - /** - * Return true if the specified reactor belongs to this federate. - * @param instantiation The instantiation to look inside - * @param reactor The reactor declaration to find - */ - private boolean contains( - Instantiation instantiation, - ReactorDecl reactor - ) { - if (instantiation.getReactorClass().equals(ASTUtils.toDefinition(reactor))) { + return instantiationsCheck; + } + + /** + * Return true if the specified import should be included in the code generated for this federate. + * + * @param imp The import + */ + private boolean contains(Import imp) { + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (contains(reactor)) { + return true; + } + } + return false; + } + + /** + * Return true if the specified parameter should be included in the code generated for this + * federate. + * + * @param param The parameter + */ + private boolean contains(Parameter param) { + boolean returnValue = false; + // Check if param is referenced in this federate's instantiation + returnValue = + instantiation.getParameters().stream() + .anyMatch( + assignment -> + assignment.getRhs().getExprs().stream() + .filter(it -> it instanceof ParameterReference) + .map(it -> ((ParameterReference) it).getParameter()) + .toList() + .contains(param)); + // If there are any user-defined top-level reactions, they could access + // the parameters, so we need to include the parameter. + var topLevelUserDefinedReactions = + ((Reactor) instantiation.eContainer()) + .getReactions().stream() + .filter(r -> !networkReactions.contains(r) && contains(r)) + .collect(Collectors.toCollection(ArrayList::new)); + returnValue |= !topLevelUserDefinedReactions.isEmpty(); + return returnValue; + } + + /** + * Return true if the specified action should be included in the code generated for this federate. + * This means that either the action is used as a trigger, a source, or an effect in a top-level + * reaction that belongs to this federate. This returns true if the program is not federated. + * + * @param action The action + * @return True if this federate contains the action. + */ + private boolean contains(Action action) { + Reactor reactor = ASTUtils.getEnclosingReactor(action); + + // If the action is used as a trigger, a source, or an effect for a top-level reaction + // that belongs to this federate, then generate it. + for (Reaction react : ASTUtils.allReactions(reactor)) { + if (contains(react)) { + // Look in triggers + for (TriggerRef trigger : convertToEmptyListIfNull(react.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (Objects.equal(triggerAsVarRef.getVariable(), action)) { + return true; + } + } + } + // Look in sources + for (VarRef source : convertToEmptyListIfNull(react.getSources())) { + if (Objects.equal(source.getVariable(), action)) { return true; + } } - - boolean instantiationsCheck = false; - // For a federate, we don't need to look inside imported reactors. - if (instantiation.getReactorClass() instanceof Reactor reactorDef) { - for (Instantiation child : reactorDef.getInstantiations()) { - instantiationsCheck |= contains(child, reactor); - } + // Look in effects + for (VarRef effect : convertToEmptyListIfNull(react.getEffects())) { + if (Objects.equal(effect.getVariable(), action)) { + return true; + } } + } + } - return instantiationsCheck; + return false; + } + + /** + * Return true if the specified reaction should be included in the code generated for this + * federate at the top-level. This means that if the reaction is triggered by or sends data to a + * port of a contained reactor, then that reaction is in the federate. Otherwise, return false. + * + *

NOTE: This method assumes that it will not be called with reaction arguments that are within + * other federates. It should only be called on reactions that are either at the top level or + * within this federate. For this reason, for any reaction not at the top level, it returns true. + * + * @param reaction The reaction. + */ + private boolean contains(Reaction reaction) { + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + + assert reactor != null; + if (!reactor.getReactions().contains(reaction)) return false; + + if (networkReactions.contains(reaction)) { + // Reaction is a network reaction that belongs to this federate + return true; } - /** - * Return true if the specified import should be included in the code generated for this federate. - * @param imp The import - */ - private boolean contains(Import imp) { - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (contains(reactor)) { - return true; - } - } - return false; + int reactionBankIndex = FedASTUtils.getReactionBankIndex(reaction); + if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { + return false; } - /** - * Return true if the specified parameter should be included in the code generated for this federate. - * @param param The parameter - */ - private boolean contains(Parameter param) { - boolean returnValue = false; - // Check if param is referenced in this federate's instantiation - returnValue = instantiation.getParameters().stream().anyMatch( - assignment -> assignment.getRhs() - .getExprs() - .stream() - .filter( - it -> it instanceof ParameterReference - ) - .map(it -> ((ParameterReference) it).getParameter()) - .toList() - .contains(param) - ); - // If there are any user-defined top-level reactions, they could access - // the parameters, so we need to include the parameter. - var topLevelUserDefinedReactions = ((Reactor) instantiation.eContainer()) - .getReactions().stream().filter( - r -> !networkReactions.contains(r) && contains(r) - ).collect(Collectors.toCollection(ArrayList::new)); - returnValue |= !topLevelUserDefinedReactions.isEmpty(); - return returnValue; + // If this has been called before, then the result of the + // following check is cached. + if (excludeReactions != null) { + return !excludeReactions.contains(reaction); } - /** - * Return true if the specified action should be included in the code generated - * for this federate. This means that either the action is used as a trigger, - * a source, or an effect in a top-level reaction that belongs to this federate. - * This returns true if the program is not federated. - * - * @param action The action - * @return True if this federate contains the action. - */ - private boolean contains(Action action) { - Reactor reactor = ASTUtils.getEnclosingReactor(action); - - // If the action is used as a trigger, a source, or an effect for a top-level reaction - // that belongs to this federate, then generate it. - for (Reaction react : ASTUtils.allReactions(reactor)) { - if (contains(react)) { - // Look in triggers - for (TriggerRef trigger : convertToEmptyListIfNull(react.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (Objects.equal(triggerAsVarRef.getVariable(), action)) { - return true; - } - } - } - // Look in sources - for (VarRef source : convertToEmptyListIfNull(react.getSources())) { - if (Objects.equal(source.getVariable(), action)) { - return true; - } - } - // Look in effects - for (VarRef effect : convertToEmptyListIfNull(react.getEffects())) { - if (Objects.equal(effect.getVariable(), action)) { - return true; - } - } + indexExcludedTopLevelReactions(reactor); + + return !excludeReactions.contains(reaction); + } + + /** + * Return true if the specified timer should be included in the code generated for the federate. + * This means that the timer is used as a trigger in a top-level reaction that belongs to this + * federate. This also returns true if the program is not federated. + * + * @return True if this federate contains the action in the specified reactor + */ + private boolean contains(Timer timer) { + Reactor reactor = ASTUtils.getEnclosingReactor(timer); + + // If the action is used as a trigger, a source, or an effect for a top-level reaction + // that belongs to this federate, then generate it. + for (Reaction r : ASTUtils.allReactions(reactor)) { + if (contains(r)) { + // Look in triggers + for (TriggerRef trigger : convertToEmptyListIfNull(r.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (Objects.equal(triggerAsVarRef.getVariable(), timer)) { + return true; } + } } - - return false; + } } - - /** - * Return true if the specified reaction should be included in the code generated for this - * federate at the top-level. This means that if the reaction is triggered by or - * sends data to a port of a contained reactor, then that reaction - * is in the federate. Otherwise, return false. - * - * NOTE: This method assumes that it will not be called with reaction arguments - * that are within other federates. It should only be called on reactions that are - * either at the top level or within this federate. For this reason, for any reaction - * not at the top level, it returns true. - * - * @param reaction The reaction. - */ - private boolean contains(Reaction reaction) { - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - - assert reactor != null; - if (!reactor.getReactions().contains(reaction)) return false; - - if (networkReactions.contains(reaction)) { - // Reaction is a network reaction that belongs to this federate - return true; - } - - int reactionBankIndex = FedASTUtils.getReactionBankIndex(reaction); - if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { - return false; - } - - // If this has been called before, then the result of the - // following check is cached. - if (excludeReactions != null) { - return !excludeReactions.contains(reaction); - } - - indexExcludedTopLevelReactions(reactor); - - return !excludeReactions.contains(reaction); + return false; + } + + /** + * Return true if the specified reactor instance or any parent reactor instance is contained by + * this federate. If the specified instance is the top-level reactor, return true (the top-level + * reactor belongs to all federates). If this federate instance is a singleton, then return true + * if the instance is non null. + * + *

NOTE: If the instance is bank within the top level, then this returns true even though only + * one of the bank members is in the federate. + * + * @param instance The reactor instance. + * @return True if this federate contains the reactor instance + */ + public boolean contains(ReactorInstance instance) { + if (instance.getParent() == null) { + return true; // Top-level reactor } - - /** - * Return true if the specified timer should be included in the code generated - * for the federate. This means that the timer is used as a trigger - * in a top-level reaction that belongs to this federate. - * This also returns true if the program is not federated. - * - * @return True if this federate contains the action in the specified reactor - */ - private boolean contains(Timer timer) { - Reactor reactor = ASTUtils.getEnclosingReactor(timer); - - // If the action is used as a trigger, a source, or an effect for a top-level reaction - // that belongs to this federate, then generate it. - for (Reaction r : ASTUtils.allReactions(reactor)) { - if (contains(r)) { - // Look in triggers - for (TriggerRef trigger : convertToEmptyListIfNull(r.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (Objects.equal(triggerAsVarRef.getVariable(), timer)) { - return true; - } - } - } - } - } - return false; + // Start with this instance, then check its parents. + ReactorInstance i = instance; + while (i != null) { + if (i.getDefinition() == instantiation) { + return true; + } + i = i.getParent(); } - - /** - * Return true if the specified reactor instance or any parent - * reactor instance is contained by this federate. - * If the specified instance is the top-level reactor, return true - * (the top-level reactor belongs to all federates). - * If this federate instance is a singleton, then return true if the - * instance is non null. - * - * NOTE: If the instance is bank within the top level, then this - * returns true even though only one of the bank members is in the federate. - * - * @param instance The reactor instance. - * @return True if this federate contains the reactor instance - */ - public boolean contains(ReactorInstance instance) { - if (instance.getParent() == null) { - return true; // Top-level reactor - } - // Start with this instance, then check its parents. - ReactorInstance i = instance; - while (i != null) { - if (i.getDefinition() == instantiation) { - return true; - } - i = i.getParent(); - } - return false; + return false; + } + + /** + * Build an index of reactions at the top-level (in the federatedReactor) that don't belong to + * this federate instance. This index is put in the excludeReactions class variable. + * + * @param federatedReactor The top-level federated reactor + */ + private void indexExcludedTopLevelReactions(Reactor federatedReactor) { + boolean inFederate = false; + if (excludeReactions != null) { + throw new IllegalStateException( + "The index for excluded reactions at the top level is already built."); } - /** - * Build an index of reactions at the top-level (in the - * federatedReactor) that don't belong to this federate - * instance. This index is put in the excludeReactions - * class variable. - * - * @param federatedReactor The top-level federated reactor - */ - private void indexExcludedTopLevelReactions(Reactor federatedReactor) { - boolean inFederate = false; - if (excludeReactions != null) { - throw new IllegalStateException("The index for excluded reactions at the top level is already built."); - } - - excludeReactions = new LinkedHashSet<>(); - - // Construct the set of excluded reactions for this federate. - // If a reaction is a network reaction that belongs to this federate, we - // don't need to perform this analysis. - Iterable reactions = ASTUtils.allReactions(federatedReactor).stream().filter(it -> !networkReactions.contains(it)).collect(Collectors.toList()); - for (Reaction react : reactions) { - // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react - // signature that are ports that reference federates. - // We then later check that all these VarRefs reference this federate. If not, we will add this - // react to the list of reactions that have to be excluded (note that mixing VarRefs from - // different federates is not allowed). - List allVarRefsReferencingFederates = new ArrayList<>(); - // Add all the triggers that are outputs - Stream triggersAsVarRef = react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); - allVarRefsReferencingFederates.addAll( - triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList() - ); - // Add all the sources that are outputs - allVarRefsReferencingFederates.addAll( - react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList() - ); - // Add all the effects that are inputs - allVarRefsReferencingFederates.addAll( - react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList() - ); - inFederate = containsAllVarRefs(allVarRefsReferencingFederates); - if (!inFederate) { - excludeReactions.add(react); - } + excludeReactions = new LinkedHashSet<>(); + + // Construct the set of excluded reactions for this federate. + // If a reaction is a network reaction that belongs to this federate, we + // don't need to perform this analysis. + Iterable reactions = + ASTUtils.allReactions(federatedReactor).stream() + .filter(it -> !networkReactions.contains(it)) + .collect(Collectors.toList()); + for (Reaction react : reactions) { + // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react + // signature that are ports that reference federates. + // We then later check that all these VarRefs reference this federate. If not, we will add + // this + // react to the list of reactions that have to be excluded (note that mixing VarRefs from + // different federates is not allowed). + List allVarRefsReferencingFederates = new ArrayList<>(); + // Add all the triggers that are outputs + Stream triggersAsVarRef = + react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); + allVarRefsReferencingFederates.addAll( + triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList()); + // Add all the sources that are outputs + allVarRefsReferencingFederates.addAll( + react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList()); + // Add all the effects that are inputs + allVarRefsReferencingFederates.addAll( + react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList()); + inFederate = containsAllVarRefs(allVarRefsReferencingFederates); + if (!inFederate) { + excludeReactions.add(react); + } + } + } + + /** + * Return true if all members of 'varRefs' belong to this federate. + * + *

As a convenience measure, if some members of 'varRefs' are from different federates, also + * report an error. + * + * @param varRefs A collection of VarRefs + */ + private boolean containsAllVarRefs(Iterable varRefs) { + var referencesFederate = false; + var inFederate = true; + for (VarRef varRef : varRefs) { + if (varRef.getContainer() == this.instantiation) { + referencesFederate = true; + } else { + if (referencesFederate) { + errorReporter.reportError( + varRef, + "Mixed triggers and effects from" + " different federates. This is not permitted"); } + inFederate = false; + } } - - /** - * Return true if all members of 'varRefs' belong to this federate. - * - * As a convenience measure, if some members of 'varRefs' are from - * different federates, also report an error. - * - * @param varRefs A collection of VarRefs - */ - private boolean containsAllVarRefs(Iterable varRefs) { - var referencesFederate = false; - var inFederate = true; - for (VarRef varRef : varRefs) { - if (varRef.getContainer() == this.instantiation) { - referencesFederate = true; - } else { - if (referencesFederate) { - errorReporter.reportError(varRef, - "Mixed triggers and effects from" - + - " different federates. This is not permitted"); - } - inFederate = false; - } + return inFederate; + } + + /** + * Find output ports that are connected to a physical action trigger upstream in the same reactor. + * Return a list of such outputs paired with the minimum delay from the nearest physical action. + * + * @param instance The reactor instance containing the output ports + * @return A LinkedHashMap + */ + public LinkedHashMap findOutputsConnectedToPhysicalActions( + ReactorInstance instance) { + LinkedHashMap physicalActionToOutputMinDelay = new LinkedHashMap<>(); + // Find reactions that write to the output port of the reactor + for (PortInstance output : instance.outputs) { + for (ReactionInstance reaction : output.getDependsOnReactions()) { + TimeValue minDelay = findNearestPhysicalActionTrigger(reaction); + if (!Objects.equal(minDelay, TimeValue.MAX_VALUE)) { + physicalActionToOutputMinDelay.put((Output) output.getDefinition(), minDelay); } - return inFederate; + } } - - /** - * Find output ports that are connected to a physical action trigger upstream - * in the same reactor. Return a list of such outputs paired with the minimum delay - * from the nearest physical action. - * @param instance The reactor instance containing the output ports - * @return A LinkedHashMap - */ - public LinkedHashMap findOutputsConnectedToPhysicalActions(ReactorInstance instance) { - LinkedHashMap physicalActionToOutputMinDelay = new LinkedHashMap<>(); - // Find reactions that write to the output port of the reactor - for (PortInstance output : instance.outputs) { - for (ReactionInstance reaction : output.getDependsOnReactions()) { - TimeValue minDelay = findNearestPhysicalActionTrigger(reaction); - if (!Objects.equal(minDelay, TimeValue.MAX_VALUE)) { - physicalActionToOutputMinDelay.put((Output) output.getDefinition(), minDelay); - } + return physicalActionToOutputMinDelay; + } + + /** + * Return a list of federates that are upstream of this federate and have a zero-delay (direct) + * connection to this federate. + */ + public List getZeroDelayImmediateUpstreamFederates() { + return this.dependsOn.entrySet().stream() + .filter(e -> e.getValue().contains(null)) + .map(Map.Entry::getKey) + .toList(); + } + + @Override + public String toString() { + return "Federate " + + id + + ": " + + ((instantiation != null) ? instantiation.getName() : "no name"); + } + + ///////////////////////////////////////////// + //// Private Fields + + /** Cached result of analysis of which reactions to exclude from main. */ + private Set excludeReactions = null; + + /** An error reporter */ + private final ErrorReporter errorReporter; + + /** + * Find the nearest (shortest) path to a physical action trigger from this 'reaction' in terms of + * minimum delay. + * + * @param reaction The reaction to start with + * @return The minimum delay found to the nearest physical action and TimeValue.MAX_VALUE + * otherwise + */ + public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { + TimeValue minDelay = TimeValue.MAX_VALUE; + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.getDefinition() instanceof Action action) { + ActionInstance actionInstance = (ActionInstance) trigger; + if (action.getOrigin() == ActionOrigin.PHYSICAL) { + if (actionInstance.getMinDelay().isEarlierThan(minDelay)) { + minDelay = actionInstance.getMinDelay(); + } + } else if (action.getOrigin() == ActionOrigin.LOGICAL) { + // Logical action + // Follow it upstream inside the reactor + for (ReactionInstance uReaction : actionInstance.getDependsOnReactions()) { + // Avoid a loop + if (!Objects.equal(uReaction, reaction)) { + TimeValue uMinDelay = + actionInstance.getMinDelay().add(findNearestPhysicalActionTrigger(uReaction)); + if (uMinDelay.isEarlierThan(minDelay)) { + minDelay = uMinDelay; + } } + } } - return physicalActionToOutputMinDelay; - } - - /** - * Return a list of federates that are upstream of this federate and have a - * zero-delay (direct) connection to this federate. - */ - public List getZeroDelayImmediateUpstreamFederates() { - return this.dependsOn.entrySet() - .stream() - .filter(e -> e.getValue().contains(null)) - .map(Map.Entry::getKey).toList(); - } - - @Override - public String toString() { - return "Federate " + id + ": " - + ((instantiation != null) ? instantiation.getName() : "no name"); - } - ///////////////////////////////////////////// - //// Private Fields - - /** - * Cached result of analysis of which reactions to exclude from main. - */ - private Set excludeReactions = null; - - /** - * An error reporter - */ - private final ErrorReporter errorReporter; - - /** - * Find the nearest (shortest) path to a physical action trigger from this - * 'reaction' in terms of minimum delay. - * - * @param reaction The reaction to start with - * @return The minimum delay found to the nearest physical action and - * TimeValue.MAX_VALUE otherwise - */ - public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { - TimeValue minDelay = TimeValue.MAX_VALUE; - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.getDefinition() instanceof Action action) { - ActionInstance actionInstance = (ActionInstance) trigger; - if (action.getOrigin() == ActionOrigin.PHYSICAL) { - if (actionInstance.getMinDelay().isEarlierThan(minDelay)) { - minDelay = actionInstance.getMinDelay(); - } - } else if (action.getOrigin() == ActionOrigin.LOGICAL) { - // Logical action - // Follow it upstream inside the reactor - for (ReactionInstance uReaction: actionInstance.getDependsOnReactions()) { - // Avoid a loop - if (!Objects.equal(uReaction, reaction)) { - TimeValue uMinDelay = actionInstance.getMinDelay().add(findNearestPhysicalActionTrigger(uReaction)); - if (uMinDelay.isEarlierThan(minDelay)) { - minDelay = uMinDelay; - } - } - } - } - - } else if (trigger.getDefinition() instanceof Output) { - // Outputs of contained reactions - PortInstance outputInstance = (PortInstance) trigger; - for (ReactionInstance uReaction: outputInstance.getDependsOnReactions()) { - TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); - if (uMinDelay.isEarlierThan(minDelay)) { - minDelay = uMinDelay; - } - } - } + } else if (trigger.getDefinition() instanceof Output) { + // Outputs of contained reactions + PortInstance outputInstance = (PortInstance) trigger; + for (ReactionInstance uReaction : outputInstance.getDependsOnReactions()) { + TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); + if (uMinDelay.isEarlierThan(minDelay)) { + minDelay = uMinDelay; + } } - return minDelay; - } - - // TODO: Put this function into a utils file instead - private List convertToEmptyListIfNull(List list) { - return list == null ? new ArrayList<>() : list; + } } + return minDelay; + } + + // TODO: Put this function into a utils file instead + private List convertToEmptyListIfNull(List list) { + return list == null ? new ArrayList<>() : list; + } } diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ac141b9259..9ae46ad357 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2019-2020, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -24,23 +24,23 @@ ***************/ package org.lflang.generator; +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; - import org.eclipse.core.resources.IMarker; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; - import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; @@ -53,17 +53,12 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; - import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.validation.AbstractLFValidator; -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; - /** - * Generator base class for specifying core functionality - * that all code generators should have. + * Generator base class for specifying core functionality that all code generators should have. * * @author Edward A. Lee * @author Marten Lohstroh @@ -73,598 +68,595 @@ */ public abstract class GeneratorBase extends AbstractLFValidator { - //////////////////////////////////////////// - //// Public fields. - - /** - * The main (top-level) reactor instance. - */ - public ReactorInstance main; - - /** An error reporter for reporting any errors or warnings during the code generation */ - public ErrorReporter errorReporter; - - //////////////////////////////////////////// - //// Protected fields. - - /** - * The current target configuration. - */ - protected final TargetConfig targetConfig; - - public TargetConfig getTargetConfig() { return this.targetConfig;} - - public final LFGeneratorContext context; - - /** - * A factory for compiler commands. - */ - protected GeneratorCommandFactory commandFactory; - - public GeneratorCommandFactory getCommandFactory() { return commandFactory; } - - /** - * Definition of the main (top-level) reactor. - * This is an automatically generated AST node for the top-level - * reactor. - */ - protected Instantiation mainDef; - public Instantiation getMainDef() { return mainDef; } - - /** - * A list of Reactor definitions in the main resource, including non-main - * reactors defined in imported resources. These are ordered in the list in - * such a way that each reactor is preceded by any reactor that it instantiates - * using a command like `foo = new Foo();` - */ - protected List reactors = new ArrayList<>(); - - /** - * The set of resources referenced reactor classes reside in. - */ - protected Set resources = new LinkedHashSet<>(); // FIXME: Why do we need this? - - /** - * Graph that tracks dependencies between instantiations. - * This is a graph where each node is a Reactor (not a ReactorInstance) - * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement - * like `a = new A();` After creating the graph, - * sort the reactors in topological order and assign them to the reactors class variable. - * Hence, after this method returns, `this.reactors` will be a list of Reactors such that any - * reactor is preceded in the list by reactors that it instantiates. - */ - protected InstantiationGraph instantiationGraph; - - /** - * The set of unordered reactions. An unordered reaction is one that does - * not have any dependency on other reactions in the containing reactor, - * and where no other reaction in the containing reactor depends on it. - * There is currently no way in the syntax of LF to make a reaction - * unordered, deliberately, because it can introduce unexpected - * nondeterminacy. However, certain automatically generated reactions are - * known to be safe to be unordered because they do not interact with the - * state of the containing reactor. To make a reaction unordered, when - * the Reaction instance is created, add that instance to this set. - */ - protected Set unorderedReactions = null; - - /** - * Map from reactions to bank indices - */ - protected Map reactionBankIndices = null; - - /** - * Indicates whether the current Lingua Franca program - * contains model reactors. - */ - public boolean hasModalReactors = false; - - /** - * Indicates whether the program has any deadlines and thus - * needs to propagate deadlines through the reaction instance graph - */ - public boolean hasDeadlines = false; - - /** - * Indicates whether the program has any watchdogs. - * This is used to check for support. - */ - public boolean hasWatchdogs = false; - - // ////////////////////////////////////////// - // // Private fields. - - /** - * A list ot AST transformations to apply before code generation - */ - private final List astTransformations = new ArrayList<>(); - - /** - * Create a new GeneratorBase object. - */ - public GeneratorBase(LFGeneratorContext context) { - this.context = context; - this.targetConfig = context.getTargetConfig(); - this.errorReporter = context.getErrorReporter(); - this.commandFactory = new GeneratorCommandFactory(errorReporter, context.getFileConfig()); + //////////////////////////////////////////// + //// Public fields. + + /** The main (top-level) reactor instance. */ + public ReactorInstance main; + + /** An error reporter for reporting any errors or warnings during the code generation */ + public ErrorReporter errorReporter; + + //////////////////////////////////////////// + //// Protected fields. + + /** The current target configuration. */ + protected final TargetConfig targetConfig; + + public TargetConfig getTargetConfig() { + return this.targetConfig; + } + + public final LFGeneratorContext context; + + /** A factory for compiler commands. */ + protected GeneratorCommandFactory commandFactory; + + public GeneratorCommandFactory getCommandFactory() { + return commandFactory; + } + + /** + * Definition of the main (top-level) reactor. This is an automatically generated AST node for the + * top-level reactor. + */ + protected Instantiation mainDef; + + public Instantiation getMainDef() { + return mainDef; + } + + /** + * A list of Reactor definitions in the main resource, including non-main reactors defined in + * imported resources. These are ordered in the list in such a way that each reactor is preceded + * by any reactor that it instantiates using a command like `foo = new Foo();` + */ + protected List reactors = new ArrayList<>(); + + /** The set of resources referenced reactor classes reside in. */ + protected Set resources = new LinkedHashSet<>(); // FIXME: Why do we need this? + + /** + * Graph that tracks dependencies between instantiations. This is a graph where each node is a + * Reactor (not a ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an + * instance of A, constructed with a statement like `a = new A();` After creating the graph, sort + * the reactors in topological order and assign them to the reactors class variable. Hence, after + * this method returns, `this.reactors` will be a list of Reactors such that any reactor is + * preceded in the list by reactors that it instantiates. + */ + protected InstantiationGraph instantiationGraph; + + /** + * The set of unordered reactions. An unordered reaction is one that does not have any dependency + * on other reactions in the containing reactor, and where no other reaction in the containing + * reactor depends on it. There is currently no way in the syntax of LF to make a reaction + * unordered, deliberately, because it can introduce unexpected nondeterminacy. However, certain + * automatically generated reactions are known to be safe to be unordered because they do not + * interact with the state of the containing reactor. To make a reaction unordered, when the + * Reaction instance is created, add that instance to this set. + */ + protected Set unorderedReactions = null; + + /** Map from reactions to bank indices */ + protected Map reactionBankIndices = null; + + /** Indicates whether the current Lingua Franca program contains model reactors. */ + public boolean hasModalReactors = false; + + /** + * Indicates whether the program has any deadlines and thus needs to propagate deadlines through + * the reaction instance graph + */ + public boolean hasDeadlines = false; + + /** Indicates whether the program has any watchdogs. This is used to check for support. */ + public boolean hasWatchdogs = false; + + // ////////////////////////////////////////// + // // Private fields. + + /** A list ot AST transformations to apply before code generation */ + private final List astTransformations = new ArrayList<>(); + + /** Create a new GeneratorBase object. */ + public GeneratorBase(LFGeneratorContext context) { + this.context = context; + this.targetConfig = context.getTargetConfig(); + this.errorReporter = context.getErrorReporter(); + this.commandFactory = new GeneratorCommandFactory(errorReporter, context.getFileConfig()); + } + + /** + * Register an AST transformation to be applied to the AST. + * + *

The transformations will be applied in the order that they are registered in. + */ + protected void registerTransformation(AstTransformation transformation) { + astTransformations.add(transformation); + } + + // ////////////////////////////////////////// + // // Code generation functions to override for a concrete code generator. + + /** + * If there is a main or federated reactor, then create a synthetic Instantiation for that + * top-level reactor and set the field mainDef to refer to it. + */ + private void createMainInstantiation() { + // Find the main reactor and create an AST node for its instantiation. + Iterable nodes = + IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); + for (Reactor reactor : Iterables.filter(nodes, Reactor.class)) { + if (reactor.isMain()) { + // Creating a definition for the main reactor because there isn't one. + this.mainDef = LfFactory.eINSTANCE.createInstantiation(); + this.mainDef.setName(reactor.getName()); + this.mainDef.setReactorClass(reactor); + } } - - /** - * Register an AST transformation to be applied to the AST. - * - * The transformations will be applied in the order that they are registered in. - */ - protected void registerTransformation(AstTransformation transformation) { - astTransformations.add(transformation); + } + + /** + * Generate code from the Lingua Franca model contained by the specified resource. + * + *

This is the main entry point for code generation. This base class finds all reactor class + * definitions, including any reactors defined in imported .lf files (except any main reactors in + * those imported files), and adds them to the {@link GeneratorBase#reactors reactors} list. If + * errors occur during generation, then a subsequent call to errorsOccurred() will return true. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. In standalone mode, this + * object is also used to relay CLI arguments. + */ + public void doGenerate(Resource resource, LFGeneratorContext context) { + + // FIXME: the signature can be reduced to only take context. + // The constructor also need not take a file config because this is tied to the context as well. + cleanIfNeeded(context); + + printInfo(context.getMode()); + + // Clear any IDE markers that may have been created by a previous build. + // Markers mark problems in the Eclipse IDE when running in integrated mode. + errorReporter.clearHistory(); + + ASTUtils.setMainName(context.getFileConfig().resource, context.getFileConfig().name); + + createMainInstantiation(); + + // Check if there are any conflicting main reactors elsewhere in the package. + if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && mainDef != null) { + for (String conflict : new MainConflictChecker(context.getFileConfig()).conflicts) { + errorReporter.reportError( + this.mainDef.getReactorClass(), "Conflicting main reactor in " + conflict); + } } - // ////////////////////////////////////////// - // // Code generation functions to override for a concrete code generator. - - /** - * If there is a main or federated reactor, then create a synthetic Instantiation - * for that top-level reactor and set the field mainDef to refer to it. - */ - private void createMainInstantiation() { - // Find the main reactor and create an AST node for its instantiation. - Iterable nodes = IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); - for (Reactor reactor : Iterables.filter(nodes, Reactor.class)) { - if (reactor.isMain()) { - // Creating a definition for the main reactor because there isn't one. - this.mainDef = LfFactory.eINSTANCE.createInstantiation(); - this.mainDef.setName(reactor.getName()); - this.mainDef.setReactorClass(reactor); - } - } + // Configure the command factory + commandFactory.setVerbose(); + if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) + && context.getArgs().containsKey("quiet")) { + commandFactory.setQuiet(); } - /** - * Generate code from the Lingua Franca model contained by the specified resource. - * - * This is the main entry point for code generation. This base class finds all - * reactor class definitions, including any reactors defined in imported .lf files - * (except any main reactors in those imported files), and adds them to the - * {@link GeneratorBase#reactors reactors} list. If errors occur during - * generation, then a subsequent call to errorsOccurred() will return true. - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. - * In standalone mode, this object is also used to relay CLI arguments. - */ - public void doGenerate(Resource resource, LFGeneratorContext context) { - - // FIXME: the signature can be reduced to only take context. - // The constructor also need not take a file config because this is tied to the context as well. - cleanIfNeeded(context); - - printInfo(context.getMode()); - - // Clear any IDE markers that may have been created by a previous build. - // Markers mark problems in the Eclipse IDE when running in integrated mode. - errorReporter.clearHistory(); - - ASTUtils.setMainName(context.getFileConfig().resource, context.getFileConfig().name); - - createMainInstantiation(); - - // Check if there are any conflicting main reactors elsewhere in the package. - if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && mainDef != null) { - for (String conflict : new MainConflictChecker(context.getFileConfig()).conflicts) { - errorReporter.reportError(this.mainDef.getReactorClass(), "Conflicting main reactor in " + conflict); - } - } - - // Configure the command factory - commandFactory.setVerbose(); - if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && context.getArgs().containsKey("quiet")) { - commandFactory.setQuiet(); - } - - // Process target files. Copy each of them into the src-gen dir. - // FIXME: Should we do this here? This doesn't make sense for federates the way it is - // done here. - copyUserFiles(this.targetConfig, context.getFileConfig()); - - // Collect reactors and create an instantiation graph. - // These are needed to figure out which resources we need - // to validate, which happens in setResources(). - setReactorsAndInstantiationGraph(context.getMode()); - - List allResources = GeneratorUtils.getResources(reactors); - resources.addAll(allResources.stream() // FIXME: This filter reproduces the behavior of the method it replaces. But why must it be so complicated? Why are we worried about weird corner cases like this? - .filter(it -> !Objects.equal(it, context.getFileConfig().resource) || mainDef != null && it == mainDef.getReactorClass().eResource()) - .map(it -> GeneratorUtils.getLFResource(it, context.getFileConfig().getSrcGenBasePath(), context, errorReporter)) - .toList() - ); - GeneratorUtils.accommodatePhysicalActionsIfPresent( - allResources, - getTarget().setsKeepAliveOptionAutomatically(), - targetConfig, - errorReporter - ); - // FIXME: Should the GeneratorBase pull in `files` from imported - // resources? - - for (AstTransformation transformation : astTransformations) { - transformation.applyTransformation(reactors); - } - - // Transform connections that reside in mutually exclusive modes and are otherwise conflicting - // This should be done before creating the instantiation graph - transformConflictingConnectionsInModalReactors(); - - // Invoke these functions a second time because transformations - // may have introduced new reactors! - setReactorsAndInstantiationGraph(context.getMode()); - - // Check for existence and support of modes - hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); - checkModalReactorSupport(false); - - // Check for the existence and support of watchdogs - hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); - checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); - additionalPostProcessingForModes(); + // Process target files. Copy each of them into the src-gen dir. + // FIXME: Should we do this here? This doesn't make sense for federates the way it is + // done here. + copyUserFiles(this.targetConfig, context.getFileConfig()); + + // Collect reactors and create an instantiation graph. + // These are needed to figure out which resources we need + // to validate, which happens in setResources(). + setReactorsAndInstantiationGraph(context.getMode()); + + List allResources = GeneratorUtils.getResources(reactors); + resources.addAll( + allResources + .stream() // FIXME: This filter reproduces the behavior of the method it replaces. But + // why must it be so complicated? Why are we worried about weird corner cases + // like this? + .filter( + it -> + !Objects.equal(it, context.getFileConfig().resource) + || mainDef != null && it == mainDef.getReactorClass().eResource()) + .map( + it -> + GeneratorUtils.getLFResource( + it, context.getFileConfig().getSrcGenBasePath(), context, errorReporter)) + .toList()); + GeneratorUtils.accommodatePhysicalActionsIfPresent( + allResources, getTarget().setsKeepAliveOptionAutomatically(), targetConfig, errorReporter); + // FIXME: Should the GeneratorBase pull in `files` from imported + // resources? + + for (AstTransformation transformation : astTransformations) { + transformation.applyTransformation(reactors); } - /** - * Check if a clean was requested from the standalone compiler and perform - * the clean step. - */ - protected void cleanIfNeeded(LFGeneratorContext context) { - if (context.getArgs().containsKey("clean")) { - try { - context.getFileConfig().doClean(); - } catch (IOException e) { - System.err.println("WARNING: IO Error during clean"); - } - } + // Transform connections that reside in mutually exclusive modes and are otherwise conflicting + // This should be done before creating the instantiation graph + transformConflictingConnectionsInModalReactors(); + + // Invoke these functions a second time because transformations + // may have introduced new reactors! + setReactorsAndInstantiationGraph(context.getMode()); + + // Check for existence and support of modes + hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); + checkModalReactorSupport(false); + + // Check for the existence and support of watchdogs + hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); + checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); + additionalPostProcessingForModes(); + } + + /** Check if a clean was requested from the standalone compiler and perform the clean step. */ + protected void cleanIfNeeded(LFGeneratorContext context) { + if (context.getArgs().containsKey("clean")) { + try { + context.getFileConfig().doClean(); + } catch (IOException e) { + System.err.println("WARNING: IO Error during clean"); + } } - - /** - * Create a new instantiation graph. This is a graph where each node is a Reactor (not a ReactorInstance) - * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement - * like `a = new A();` After creating the graph, - * sort the reactors in topological order and assign them to the reactors class variable. - * Hence, after this method returns, `this.reactors` will be a list of Reactors such that any - * reactor is preceded in the list by reactors that it instantiates. - */ - protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { - // Build the instantiation graph . - instantiationGraph = new InstantiationGraph(context.getFileConfig().resource, false); - - // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur earlier in - // the sorted list of reactors. This helps the code generator output code in the correct order. - // For example if `reactor Foo {bar = new Bar()}` then the definition of `Bar` has to be generated before - // the definition of `Foo`. - reactors = instantiationGraph.nodesInTopologicalOrder(); - - // If there is no main reactor or if all reactors in the file need to be validated, then make sure the reactors - // list includes even reactors that are not instantiated anywhere. - if (mainDef == null || Objects.equal(mode, LFGeneratorContext.Mode.LSP_MEDIUM)) { - Iterable nodes = IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); - for (Reactor r : IterableExtensions.filter(nodes, Reactor.class)) { - if (!reactors.contains(r)) { - reactors.add(r); - } - } + } + + /** + * Create a new instantiation graph. This is a graph where each node is a Reactor (not a + * ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an instance of A, + * constructed with a statement like `a = new A();` After creating the graph, sort the reactors in + * topological order and assign them to the reactors class variable. Hence, after this method + * returns, `this.reactors` will be a list of Reactors such that any reactor is preceded in the + * list by reactors that it instantiates. + */ + protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { + // Build the instantiation graph . + instantiationGraph = new InstantiationGraph(context.getFileConfig().resource, false); + + // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur + // earlier in + // the sorted list of reactors. This helps the code generator output code in the correct order. + // For example if `reactor Foo {bar = new Bar()}` then the definition of `Bar` has to be + // generated before + // the definition of `Foo`. + reactors = instantiationGraph.nodesInTopologicalOrder(); + + // If there is no main reactor or if all reactors in the file need to be validated, then make + // sure the reactors + // list includes even reactors that are not instantiated anywhere. + if (mainDef == null || Objects.equal(mode, LFGeneratorContext.Mode.LSP_MEDIUM)) { + Iterable nodes = + IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); + for (Reactor r : IterableExtensions.filter(nodes, Reactor.class)) { + if (!reactors.contains(r)) { + reactors.add(r); } + } } - - /** - * Copy user specific files to the src-gen folder. - * - * This should be overridden by the target generators. - * - * @param targetConfig The targetConfig to read the `files` from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {} - - /** - * Return true if errors occurred in the last call to doGenerate(). - * This will return true if any of the reportError methods was called. - * @return True if errors occurred. - */ - public boolean errorsOccurred() { - return errorReporter.getErrorsOccurred(); + } + + /** + * Copy user specific files to the src-gen folder. + * + *

This should be overridden by the target generators. + * + * @param targetConfig The targetConfig to read the `files` from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {} + + /** + * Return true if errors occurred in the last call to doGenerate(). This will return true if any + * of the reportError methods was called. + * + * @return True if errors occurred. + */ + public boolean errorsOccurred() { + return errorReporter.getErrorsOccurred(); + } + + /* + * Return the TargetTypes instance associated with this. + */ + public abstract TargetTypes getTargetTypes(); + + /** + * Mark the reaction unordered. An unordered reaction is one that does not have any dependency on + * other reactions in the containing reactor, and where no other reaction in the containing + * reactor depends on it. There is currently no way in the syntax of LF to make a reaction + * unordered, deliberately, because it can introduce unexpected nondeterminacy. However, certain + * automatically generated reactions are known to be safe to be unordered because they do not + * interact with the state of the containing reactor. To make a reaction unordered, when the + * Reaction instance is created, add that instance to this set. + * + * @param reaction The reaction to make unordered. + */ + public void makeUnordered(Reaction reaction) { + if (unorderedReactions == null) { + unorderedReactions = new LinkedHashSet<>(); } - - /* - * Return the TargetTypes instance associated with this. - */ - public abstract TargetTypes getTargetTypes(); - - /** - * Mark the reaction unordered. An unordered reaction is one that does not - * have any dependency on other reactions in the containing reactor, and - * where no other reaction in the containing reactor depends on it. There - * is currently no way in the syntax of LF to make a reaction unordered, - * deliberately, because it can introduce unexpected nondeterminacy. - * However, certain automatically generated reactions are known to be safe - * to be unordered because they do not interact with the state of the - * containing reactor. To make a reaction unordered, when the Reaction - * instance is created, add that instance to this set. - * @param reaction The reaction to make unordered. - */ - public void makeUnordered(Reaction reaction) { - if (unorderedReactions == null) { - unorderedReactions = new LinkedHashSet<>(); - } - unorderedReactions.add(reaction); + unorderedReactions.add(reaction); + } + + /** + * Mark the specified reaction to belong to only the specified bank index. This is needed because + * reactions cannot declare a specific bank index as an effect or trigger. Reactions that send + * messages between federates, including absent messages, need to be specific to a bank member. + * + * @param reaction The reaction. + * @param bankIndex The bank index, or -1 if there is no bank. + */ + public void setReactionBankIndex(Reaction reaction, int bankIndex) { + if (bankIndex < 0) { + return; } - - /** - * Mark the specified reaction to belong to only the specified - * bank index. This is needed because reactions cannot declare - * a specific bank index as an effect or trigger. Reactions that - * send messages between federates, including absent messages, - * need to be specific to a bank member. - * @param reaction The reaction. - * @param bankIndex The bank index, or -1 if there is no bank. - */ - public void setReactionBankIndex(Reaction reaction, int bankIndex) { - if (bankIndex < 0) { - return; - } - if (reactionBankIndices == null) { - reactionBankIndices = new LinkedHashMap<>(); - } - reactionBankIndices.put(reaction, bankIndex); + if (reactionBankIndices == null) { + reactionBankIndices = new LinkedHashMap<>(); } - - /** - * Return the reaction bank index. - * @see #setReactionBankIndex(Reaction reaction, int bankIndex) - * @param reaction The reaction. - * @return The reaction bank index, if one has been set, and -1 otherwise. - */ - public int getReactionBankIndex(Reaction reaction) { - if (reactionBankIndices == null) return -1; - if (reactionBankIndices.get(reaction) == null) return -1; - return reactionBankIndices.get(reaction); + reactionBankIndices.put(reaction, bankIndex); + } + + /** + * Return the reaction bank index. + * + * @see #setReactionBankIndex(Reaction reaction, int bankIndex) + * @param reaction The reaction. + * @return The reaction bank index, if one has been set, and -1 otherwise. + */ + public int getReactionBankIndex(Reaction reaction) { + if (reactionBankIndices == null) return -1; + if (reactionBankIndices.get(reaction) == null) return -1; + return reactionBankIndices.get(reaction); + } + + // ////////////////////////////////////////// + // // Protected methods. + + /** + * Checks whether modal reactors are present and require appropriate code generation. This will + * set the hasModalReactors variable. + * + * @param isSupported indicates if modes are supported by this code generation. + */ + protected void checkModalReactorSupport(boolean isSupported) { + if (hasModalReactors && !isSupported) { + errorReporter.reportError( + "The currently selected code generation or " + + "target configuration does not support modal reactors!"); } - - // ////////////////////////////////////////// - // // Protected methods. - - /** - * Checks whether modal reactors are present and require appropriate code generation. - * This will set the hasModalReactors variable. - * @param isSupported indicates if modes are supported by this code generation. - */ - protected void checkModalReactorSupport(boolean isSupported) { - if (hasModalReactors && !isSupported) { - errorReporter.reportError("The currently selected code generation or " + - "target configuration does not support modal reactors!"); - } + } + + /** + * Checks whether watchdogs are present and are supported. + * + * @param isSupported indicates whether or not this is a supported target and whether or not it is + * a threaded runtime. + */ + protected void checkWatchdogSupport(boolean isSupported) { + if (hasWatchdogs && !isSupported) { + errorReporter.reportError( + "Watchdogs are currently only supported for threaded programs in the C target."); } - - /** - * Checks whether watchdogs are present and are supported. - * @param isSupported indicates whether or not this is a supported target - * and whether or not it is a threaded runtime. - */ - protected void checkWatchdogSupport(boolean isSupported) { - if (hasWatchdogs && !isSupported) { + } + + /** + * Finds and transforms connections into forwarding reactions iff the connections have the same + * destination as other connections or reaction in mutually exclusive modes. + */ + private void transformConflictingConnectionsInModalReactors() { + for (LFResource r : resources) { + var transform = ASTUtils.findConflictingConnectionsInModalReactors(r.eResource); + if (!transform.isEmpty()) { + var factory = LfFactory.eINSTANCE; + for (Connection connection : transform) { + // Currently only simple transformations are supported + if (connection.isPhysical() + || connection.getDelay() != null + || connection.isIterated() + || connection.getLeftPorts().size() > 1 + || connection.getRightPorts().size() > 1) { errorReporter.reportError( - "Watchdogs are currently only supported for threaded programs in the C target." - ); + connection, + "Cannot transform connection in modal reactor. Connection uses currently not" + + " supported features."); + } else { + var reaction = factory.createReaction(); + ((Mode) connection.eContainer()).getReactions().add(reaction); + + var sourceRef = connection.getLeftPorts().get(0); + var destRef = connection.getRightPorts().get(0); + reaction.getTriggers().add(sourceRef); + reaction.getEffects().add(destRef); + + var code = factory.createCode(); + var source = + (sourceRef.getContainer() != null ? sourceRef.getContainer().getName() + "." : "") + + sourceRef.getVariable().getName(); + var dest = + (destRef.getContainer() != null ? destRef.getContainer().getName() + "." : "") + + destRef.getVariable().getName(); + code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest)); + reaction.setCode(code); + + EcoreUtil.remove(connection); + } } + } } - - - /** - * Finds and transforms connections into forwarding reactions iff the connections have the same destination as other - * connections or reaction in mutually exclusive modes. - */ - private void transformConflictingConnectionsInModalReactors() { - for (LFResource r : resources) { - var transform = ASTUtils.findConflictingConnectionsInModalReactors(r.eResource); - if (!transform.isEmpty()) { - var factory = LfFactory.eINSTANCE; - for (Connection connection : transform) { - // Currently only simple transformations are supported - if (connection.isPhysical() || connection.getDelay() != null || connection.isIterated() || - connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1 - ) { - errorReporter.reportError(connection, "Cannot transform connection in modal reactor. Connection uses currently not supported features."); - } else { - var reaction = factory.createReaction(); - ((Mode)connection.eContainer()).getReactions().add(reaction); - - var sourceRef = connection.getLeftPorts().get(0); - var destRef = connection.getRightPorts().get(0); - reaction.getTriggers().add(sourceRef); - reaction.getEffects().add(destRef); - - var code = factory.createCode(); - var source = (sourceRef.getContainer() != null ? - sourceRef.getContainer().getName() + "." : "") + sourceRef.getVariable().getName(); - var dest = (destRef.getContainer() != null ? - destRef.getContainer().getName() + "." : "") + destRef.getVariable().getName(); - code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest)); - reaction.setCode(code); - - EcoreUtil.remove(connection); - } - } - } - } - } - /** - * Return target code for forwarding reactions iff the connections have the - * same destination as other connections or reaction in mutually exclusive modes. - * - * This method needs to be overridden in target specific code generators that - * support modal reactors. - */ - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - errorReporter.reportError("The currently selected code generation " + - "is missing an implementation for conflicting " + - "transforming connections in modal reactors."); - return "MODAL MODELS NOT SUPPORTED"; + } + /** + * Return target code for forwarding reactions iff the connections have the same destination as + * other connections or reaction in mutually exclusive modes. + * + *

This method needs to be overridden in target specific code generators that support modal + * reactors. + */ + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + errorReporter.reportError( + "The currently selected code generation " + + "is missing an implementation for conflicting " + + "transforming connections in modal reactors."); + return "MODAL MODELS NOT SUPPORTED"; + } + + /** Hook for additional post-processing of the model. */ + protected void additionalPostProcessingForModes() { + // Do nothing + } + + /** Parsed error message from a compiler is returned here. */ + public static class ErrorFileAndLine { + public String filepath = null; + public String line = "1"; + public String character = "0"; + public String message = ""; + public boolean isError = true; // false for a warning. + + @Override + public String toString() { + return (isError ? "Error" : "Non-error") + + " at " + + line + + ":" + + character + + " of file " + + filepath + + ": " + + message; } - - /** - * Hook for additional post-processing of the model. - */ - protected void additionalPostProcessingForModes() { - // Do nothing - } - - /** - * Parsed error message from a compiler is returned here. - */ - public static class ErrorFileAndLine { - public String filepath = null; - public String line = "1"; - public String character = "0"; - public String message = ""; - public boolean isError = true; // false for a warning. - - @Override - public String toString() { - return (isError ? "Error" : "Non-error") + " at " + line + ":" + character + " of file " + filepath + ": " + message; - } - } - - /** - * Given a line of text from the output of a compiler, return - * an instance of ErrorFileAndLine if the line is recognized as - * the first line of an error message. Otherwise, return null. - * This base class simply returns null. - * @param line A line of output from a compiler or other external - * tool that might generate errors. - * @return If the line is recognized as the start of an error message, - * then return a class containing the path to the file on which the - * error occurred (or null if there is none), the line number (or the - * string "1" if there is none), the character position (or the string - * "0" if there is none), and the message (or an empty string if there - * is none). - */ - protected ErrorFileAndLine parseCommandOutput(String line) { - return null; - } - - /** - * Parse the specified string for command errors that can be reported - * using marks in the Eclipse IDE. In this class, we attempt to parse - * the messages to look for file and line information, thereby generating - * marks on the appropriate lines. This should not be called in standalone - * mode. - * - * @param stderr The output on standard error of executing a command. - */ - public void reportCommandErrors(String stderr) { - // NOTE: If the VS Code branch passes code review, then this function, - // parseCommandOutput, and ErrorFileAndLine will be deleted soon after. - // First, split the message into lines. - String[] lines = stderr.split("\\r?\\n"); - StringBuilder message = new StringBuilder(); - Integer lineNumber = null; - Path path = context.getFileConfig().srcFile; - // In case errors occur within an imported file, record the original path. - Path originalPath = path; - - int severity = IMarker.SEVERITY_ERROR; - for (String line : lines) { - ErrorFileAndLine parsed = parseCommandOutput(line); - if (parsed != null) { - // Found a new line number designator. - // If there is a previously accumulated message, report it. - if (message.length() > 0) { - if (severity == IMarker.SEVERITY_ERROR) - errorReporter.reportError(path, lineNumber, message.toString()); - else - errorReporter.reportWarning(path, lineNumber, message.toString()); - - if (!Objects.equal(originalPath.toFile(), path.toFile())) { - // Report an error also in the top-level resource. - // FIXME: It should be possible to descend through the import - // statements to find which one matches and mark all the - // import statements down the chain. But what a pain! - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); - } else { - errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); - } - } - } - if (parsed.isError) { - severity = IMarker.SEVERITY_ERROR; - } else { - severity = IMarker.SEVERITY_WARNING; - } - - // Start accumulating a new message. - message = new StringBuilder(); - // Append the message on the line number designator line. - message.append(parsed.message); - - // Set the new line number. - try { - lineNumber = Integer.decode(parsed.line); - } catch (Exception ex) { - // Set the line number unknown. - lineNumber = null; - } - // FIXME: Ignoring the position within the line. - // Determine the path within which the error occurred. - path = Paths.get(parsed.filepath); - } else { - // No line designator. - if (message.length() > 0) { - message.append("\n"); - } else { - if (!line.toLowerCase().contains("error:")) { - severity = IMarker.SEVERITY_WARNING; - } - } - message.append(line); - } - } + } + + /** + * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if + * the line is recognized as the first line of an error message. Otherwise, return null. This base + * class simply returns null. + * + * @param line A line of output from a compiler or other external tool that might generate errors. + * @return If the line is recognized as the start of an error message, then return a class + * containing the path to the file on which the error occurred (or null if there is none), the + * line number (or the string "1" if there is none), the character position (or the string "0" + * if there is none), and the message (or an empty string if there is none). + */ + protected ErrorFileAndLine parseCommandOutput(String line) { + return null; + } + + /** + * Parse the specified string for command errors that can be reported using marks in the Eclipse + * IDE. In this class, we attempt to parse the messages to look for file and line information, + * thereby generating marks on the appropriate lines. This should not be called in standalone + * mode. + * + * @param stderr The output on standard error of executing a command. + */ + public void reportCommandErrors(String stderr) { + // NOTE: If the VS Code branch passes code review, then this function, + // parseCommandOutput, and ErrorFileAndLine will be deleted soon after. + // First, split the message into lines. + String[] lines = stderr.split("\\r?\\n"); + StringBuilder message = new StringBuilder(); + Integer lineNumber = null; + Path path = context.getFileConfig().srcFile; + // In case errors occur within an imported file, record the original path. + Path originalPath = path; + + int severity = IMarker.SEVERITY_ERROR; + for (String line : lines) { + ErrorFileAndLine parsed = parseCommandOutput(line); + if (parsed != null) { + // Found a new line number designator. + // If there is a previously accumulated message, report it. if (message.length() > 0) { + if (severity == IMarker.SEVERITY_ERROR) + errorReporter.reportError(path, lineNumber, message.toString()); + else errorReporter.reportWarning(path, lineNumber, message.toString()); + + if (!Objects.equal(originalPath.toFile(), path.toFile())) { + // Report an error also in the top-level resource. + // FIXME: It should be possible to descend through the import + // statements to find which one matches and mark all the + // import statements down the chain. But what a pain! if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(path, lineNumber, message.toString()); + errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); } else { - errorReporter.reportWarning(path, lineNumber, message.toString()); + errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); } + } + } + if (parsed.isError) { + severity = IMarker.SEVERITY_ERROR; + } else { + severity = IMarker.SEVERITY_WARNING; + } - if (originalPath.toFile() != path.toFile()) { - // Report an error also in the top-level resource. - // FIXME: It should be possible to descend through the import - // statements to find which one matches and mark all the - // import statements down the chain. But what a pain! - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); - } else { - errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); - } - } + // Start accumulating a new message. + message = new StringBuilder(); + // Append the message on the line number designator line. + message.append(parsed.message); + + // Set the new line number. + try { + lineNumber = Integer.decode(parsed.line); + } catch (Exception ex) { + // Set the line number unknown. + lineNumber = null; + } + // FIXME: Ignoring the position within the line. + // Determine the path within which the error occurred. + path = Paths.get(parsed.filepath); + } else { + // No line designator. + if (message.length() > 0) { + message.append("\n"); + } else { + if (!line.toLowerCase().contains("error:")) { + severity = IMarker.SEVERITY_WARNING; + } } + message.append(line); + } } - - // ////////////////////////////////////////////////// - // // Private functions - - /** - * Print to stdout information about what source file is being generated, - * what mode the generator is in, and where the generated sources are to be put. - */ - public void printInfo(LFGeneratorContext.Mode mode) { - System.out.println("Generating code for: " + context.getFileConfig().resource.getURI().toString()); - System.out.println("******** mode: " + mode); - System.out.println("******** generated sources: " + context.getFileConfig().getSrcGenPath()); + if (message.length() > 0) { + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(path, lineNumber, message.toString()); + } else { + errorReporter.reportWarning(path, lineNumber, message.toString()); + } + + if (originalPath.toFile() != path.toFile()) { + // Report an error also in the top-level resource. + // FIXME: It should be possible to descend through the import + // statements to find which one matches and mark all the + // import statements down the chain. But what a pain! + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); + } else { + errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); + } + } } - - /** - * Get the buffer type used for network messages - */ - public String getNetworkBufferType() { return ""; } - - /** - * Return the Targets enum for the current target - */ - public abstract Target getTarget(); - + } + + // ////////////////////////////////////////////////// + // // Private functions + + /** + * Print to stdout information about what source file is being generated, what mode the generator + * is in, and where the generated sources are to be put. + */ + public void printInfo(LFGeneratorContext.Mode mode) { + System.out.println( + "Generating code for: " + context.getFileConfig().resource.getURI().toString()); + System.out.println("******** mode: " + mode); + System.out.println("******** generated sources: " + context.getFileConfig().getSrcGenPath()); + } + + /** Get the buffer type used for network messages */ + public String getNetworkBufferType() { + return ""; + } + + /** Return the Targets enum for the current target */ + public abstract Target getTarget(); } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 3ab3607b2a..ba85ae8288 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -1,32 +1,31 @@ /** A data structure for a reactor instance. */ /************* -Copyright (c) 2019-2022, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2022, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; -import static org.lflang.ASTUtils.belongsTo; import static org.lflang.ASTUtils.getLiteralTimeValue; import java.util.ArrayList; @@ -38,7 +37,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Map; import java.util.Optional; import java.util.Set; - import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; @@ -68,1121 +66,1087 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.WidthSpec; /** - * Representation of a compile-time instance of a reactor. - * If the reactor is instantiated as a bank of reactors, or if any - * of its parents is instantiated as a bank of reactors, then one instance - * of this ReactorInstance class represents all the runtime instances within - * these banks. The {@link #getTotalWidth()} method returns the number of such - * runtime instances, which is the product of the bank width of this reactor - * instance and the bank widths of all of its parents. - * There is exactly one instance of this ReactorInstance class for each - * graphical rendition of a reactor in the diagram view. - * - * For the main reactor, which has no parent, once constructed, - * this object represents the entire Lingua Franca program. - * If the program has causality loops (a programming error), then - * {@link #hasCycles()} will return true and {@link #getCycles()} will - * return the ports and reaction instances involved in the cycles. + * Representation of a compile-time instance of a reactor. If the reactor is instantiated as a bank + * of reactors, or if any of its parents is instantiated as a bank of reactors, then one instance of + * this ReactorInstance class represents all the runtime instances within these banks. The {@link + * #getTotalWidth()} method returns the number of such runtime instances, which is the product of + * the bank width of this reactor instance and the bank widths of all of its parents. There is + * exactly one instance of this ReactorInstance class for each graphical rendition of a reactor in + * the diagram view. + * + *

For the main reactor, which has no parent, once constructed, this object represents the entire + * Lingua Franca program. If the program has causality loops (a programming error), then {@link + * #hasCycles()} will return true and {@link #getCycles()} will return the ports and reaction + * instances involved in the cycles. * * @author Marten Lohstroh * @author Edward A. Lee */ public class ReactorInstance extends NamedInstance { - /** - * Create a new instantiation hierarchy that starts with the given top-level reactor. - * @param reactor The top-level reactor. - * @param reporter The error reporter. - */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), null, reporter, -1); + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor. + * + * @param reactor The top-level reactor. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), null, reporter, -1); + } + + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor but only + * creates contained reactors up to the specified depth. + * + * @param reactor The top-level reactor. + * @param reporter The error reporter. + * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { + this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); + } + + /** + * Create a new instantiation with the specified parent. This constructor is here to allow for + * unit tests. It should not be used for any other purpose. + * + * @param reactor The top-level reactor. + * @param parent The parent reactor instance. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); + } + + ////////////////////////////////////////////////////// + //// Public fields. + + /** The action instances belonging to this reactor instance. */ + public List actions = new ArrayList<>(); + + /** + * The contained reactor instances, in order of declaration. For banks of reactors, this includes + * both the bank definition Reactor (which has bankIndex == -2) followed by each of the bank + * members (which have bankIndex >= 0). + */ + public final List children = new ArrayList<>(); + + /** The input port instances belonging to this reactor instance. */ + public final List inputs = new ArrayList<>(); + + /** The output port instances belonging to this reactor instance. */ + public final List outputs = new ArrayList<>(); + + /** The parameters of this instance. */ + public final List parameters = new ArrayList<>(); + + /** List of reaction instances for this reactor instance. */ + public final List reactions = new ArrayList<>(); + + /** List of watchdog instances for this reactor instance. */ + public final List watchdogs = new ArrayList<>(); + + /** The timer instances belonging to this reactor instance. */ + public final List timers = new ArrayList<>(); + + /** The mode instances belonging to this reactor instance. */ + public final List modes = new ArrayList<>(); + + /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ + public final ReactorDecl reactorDeclaration; + + /** The reactor after imports are resolve. */ + public final Reactor reactorDefinition; + + /** Indicator that this reactor has itself as a parent, an error condition. */ + public final boolean recursive; + + ////////////////////////////////////////////////////// + //// Public methods. + + /** + * Assign levels to all reactions within the same root as this reactor. The level of a reaction r + * is equal to the length of the longest chain of reactions that must have the opportunity to + * execute before r at each logical tag. This fails and returns false if a causality cycle exists. + * + *

This method uses a variant of Kahn's algorithm, which is linear in V + E, where V is the + * number of vertices (reactions) and E is the number of edges (dependencies between reactions). + * + * @return An empty graph if successful and otherwise a graph with runtime reaction instances that + * form cycles. + */ + public ReactionInstanceGraph assignLevels() { + if (depth != 0) return root().assignLevels(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); } - - /** - * Create a new instantiation hierarchy that starts with the given top-level reactor - * but only creates contained reactors up to the specified depth. - * @param reactor The top-level reactor. - * @param reporter The error reporter. - * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. - */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { - this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); + return cachedReactionLoopGraph; + } + + /** + * This function assigns/propagates deadlines through the Reaction Instance Graph. It performs + * Kahn`s algorithm in reverse, starting from the leaf nodes and propagates deadlines upstream. To + * reduce cost, it should only be invoked when there are user-specified deadlines in the program. + * + * @return + */ + public ReactionInstanceGraph assignDeadlines() { + if (depth != 0) return root().assignDeadlines(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); } - - /** - * Create a new instantiation with the specified parent. - * This constructor is here to allow for unit tests. - * It should not be used for any other purpose. - * @param reactor The top-level reactor. - * @param parent The parent reactor instance. - * @param reporter The error reporter. - */ - public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); - } - - ////////////////////////////////////////////////////// - //// Public fields. - - /** The action instances belonging to this reactor instance. */ - public List actions = new ArrayList<>(); - - /** - * The contained reactor instances, in order of declaration. - * For banks of reactors, this includes both the bank definition - * Reactor (which has bankIndex == -2) followed by each of the - * bank members (which have bankIndex >= 0). - */ - public final List children = new ArrayList<>(); - - /** The input port instances belonging to this reactor instance. */ - public final List inputs = new ArrayList<>(); - - /** The output port instances belonging to this reactor instance. */ - public final List outputs = new ArrayList<>(); - - /** The parameters of this instance. */ - public final List parameters = new ArrayList<>(); - - /** List of reaction instances for this reactor instance. */ - public final List reactions = new ArrayList<>(); - - /** List of watchdog instances for this reactor instance. */ - public final List watchdogs = new ArrayList<>(); - - /** The timer instances belonging to this reactor instance. */ - public final List timers = new ArrayList<>(); - - /** The mode instances belonging to this reactor instance. */ - public final List modes = new ArrayList<>(); - - /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ - public final ReactorDecl reactorDeclaration; - - /** The reactor after imports are resolve. */ - public final Reactor reactorDefinition; - - /** Indicator that this reactor has itself as a parent, an error condition. */ - public final boolean recursive; - - ////////////////////////////////////////////////////// - //// Public methods. - - /** - * Assign levels to all reactions within the same root as this - * reactor. The level of a reaction r is equal to the length of the - * longest chain of reactions that must have the opportunity to - * execute before r at each logical tag. This fails and returns - * false if a causality cycle exists. - * - * This method uses a variant of Kahn's algorithm, which is linear - * in V + E, where V is the number of vertices (reactions) and E - * is the number of edges (dependencies between reactions). - * - * @return An empty graph if successful and otherwise a graph - * with runtime reaction instances that form cycles. - */ - public ReactionInstanceGraph assignLevels() { - if (depth != 0) return root().assignLevels(); - if (cachedReactionLoopGraph == null) { - cachedReactionLoopGraph = new ReactionInstanceGraph(this); - } - return cachedReactionLoopGraph; + cachedReactionLoopGraph.rebuildAndAssignDeadlines(); + return cachedReactionLoopGraph; + } + + /** + * Return the instance of a child rector created by the specified definition or null if there is + * none. + * + * @param definition The definition of the child reactor ("new" statement). + */ + public ReactorInstance getChildReactorInstance(Instantiation definition) { + for (ReactorInstance child : this.children) { + if (child.definition == definition) { + return child; + } } - - /** - * This function assigns/propagates deadlines through the Reaction Instance Graph. - * It performs Kahn`s algorithm in reverse, starting from the leaf nodes and - * propagates deadlines upstream. To reduce cost, it should only be invoked when - * there are user-specified deadlines in the program. - * @return - */ - public ReactionInstanceGraph assignDeadlines() { - if (depth != 0) return root().assignDeadlines(); - if (cachedReactionLoopGraph == null) { - cachedReactionLoopGraph = new ReactionInstanceGraph(this); - } - cachedReactionLoopGraph.rebuildAndAssignDeadlines(); - return cachedReactionLoopGraph; + return null; + } + + /** + * Clear any cached data in this reactor and its children. This is useful if a mutation has been + * realized. + */ + public void clearCaches() { + clearCaches(true); + } + + /** + * Clear any cached data in this reactor and its children. This is useful if a mutation has been + * realized. + * + * @param includingRuntimes If false, leave the runtime instances of reactions intact. This is + * useful for federated execution where levels are computed using the top-level connections, + * but then those connections are discarded. + */ + public void clearCaches(boolean includingRuntimes) { + if (includingRuntimes) cachedReactionLoopGraph = null; + for (ReactorInstance child : children) { + child.clearCaches(includingRuntimes); } - - /** - * Return the instance of a child rector created by the specified - * definition or null if there is none. - * @param definition The definition of the child reactor ("new" statement). - */ - public ReactorInstance getChildReactorInstance(Instantiation definition) { - for (ReactorInstance child : this.children) { - if (child.definition == definition) { - return child; - } - } - return null; + for (PortInstance port : inputs) { + port.clearCaches(); } - - /** - * Clear any cached data in this reactor and its children. - * This is useful if a mutation has been realized. - */ - public void clearCaches() { - clearCaches(true); + for (PortInstance port : outputs) { + port.clearCaches(); } - - /** - * Clear any cached data in this reactor and its children. - * This is useful if a mutation has been realized. - * @param includingRuntimes If false, leave the runtime instances of reactions intact. - * This is useful for federated execution where levels are computed using - * the top-level connections, but then those connections are discarded. - */ - public void clearCaches(boolean includingRuntimes) { - if (includingRuntimes) cachedReactionLoopGraph = null; - for (ReactorInstance child : children) { - child.clearCaches(includingRuntimes); - } - for (PortInstance port : inputs) { - port.clearCaches(); - } - for (PortInstance port : outputs) { - port.clearCaches(); - } - for (ReactionInstance reaction : reactions) { - reaction.clearCaches(includingRuntimes); - } - cachedCycles = null; + for (ReactionInstance reaction : reactions) { + reaction.clearCaches(includingRuntimes); } - - /** - * Return the set of ReactionInstance and PortInstance that form causality - * loops in the topmost parent reactor in the instantiation hierarchy. This will return an - * empty set if there are no causality loops. - */ - public Set> getCycles() { - if (depth != 0) return root().getCycles(); - if (cachedCycles != null) return cachedCycles; - cachedCycles = new LinkedHashSet<>(); - - ReactionInstanceGraph reactionRuntimes = assignLevels(); - if (reactionRuntimes.nodes().size() > 0) { - Set reactions = new LinkedHashSet<>(); - Set ports = new LinkedHashSet<>(); - // There are cycles. But the nodes set includes not - // just the cycles, but also nodes that are downstream of the - // cycles. Use Tarjan's algorithm to get just the cycles. - var cycleNodes = reactionRuntimes.getCycles(); - for (var cycle : cycleNodes) { - for (ReactionInstance.Runtime runtime : cycle) { - reactions.add(runtime.getReaction()); - } - } - // Need to figure out which ports are involved in the cycles. - // It may not be all ports that depend on this reaction. - for (ReactionInstance r : reactions) { - for (TriggerInstance p : r.effects) { - if (p instanceof PortInstance) { - findPaths((PortInstance)p, reactions, ports); - } - } - } - cachedCycles.addAll(reactions); - cachedCycles.addAll(ports); + cachedCycles = null; + } + + /** + * Return the set of ReactionInstance and PortInstance that form causality loops in the topmost + * parent reactor in the instantiation hierarchy. This will return an empty set if there are no + * causality loops. + */ + public Set> getCycles() { + if (depth != 0) return root().getCycles(); + if (cachedCycles != null) return cachedCycles; + cachedCycles = new LinkedHashSet<>(); + + ReactionInstanceGraph reactionRuntimes = assignLevels(); + if (reactionRuntimes.nodes().size() > 0) { + Set reactions = new LinkedHashSet<>(); + Set ports = new LinkedHashSet<>(); + // There are cycles. But the nodes set includes not + // just the cycles, but also nodes that are downstream of the + // cycles. Use Tarjan's algorithm to get just the cycles. + var cycleNodes = reactionRuntimes.getCycles(); + for (var cycle : cycleNodes) { + for (ReactionInstance.Runtime runtime : cycle) { + reactions.add(runtime.getReaction()); } - - return cachedCycles; - } - - /** - * Return the specified input by name or null if there is no such input. - * @param name The input name. - */ - public PortInstance getInput(String name) { - for (PortInstance port: inputs) { - if (port.getName().equals(name)) { - return port; - } + } + // Need to figure out which ports are involved in the cycles. + // It may not be all ports that depend on this reaction. + for (ReactionInstance r : reactions) { + for (TriggerInstance p : r.effects) { + if (p instanceof PortInstance) { + findPaths((PortInstance) p, reactions, ports); + } } - return null; - } - - /** - * Override the base class to append [i_d], where d is the depth, - * if this reactor is in a bank of reactors. - * @return The name of this instance. - */ - @Override - public String getName() { - return this.definition.getName(); + } + cachedCycles.addAll(reactions); + cachedCycles.addAll(ports); } - /** - * @see NamedInstance#uniqueID() - * - * Append `_main` to the name of the main reactor to allow instantiations - * within that reactor to have the same name. - */ - @Override - public String uniqueID() { - if (this.isMainOrFederated()) { - return super.uniqueID() + "_main"; - } - return super.uniqueID(); + return cachedCycles; + } + + /** + * Return the specified input by name or null if there is no such input. + * + * @param name The input name. + */ + public PortInstance getInput(String name) { + for (PortInstance port : inputs) { + if (port.getName().equals(name)) { + return port; + } } - - /** - * Return the specified output by name or null if there is no such output. - * @param name The output name. - */ - public PortInstance getOutput(String name) { - for (PortInstance port: outputs) { - if (port.getName().equals(name)) { - return port; - } - } - return null; + return null; + } + + /** + * Override the base class to append [i_d], where d is the depth, if this reactor is in a bank of + * reactors. + * + * @return The name of this instance. + */ + @Override + public String getName() { + return this.definition.getName(); + } + + /** + * @see NamedInstance#uniqueID() + *

Append `_main` to the name of the main reactor to allow instantiations within that + * reactor to have the same name. + */ + @Override + public String uniqueID() { + if (this.isMainOrFederated()) { + return super.uniqueID() + "_main"; } - - /** - * Return a parameter matching the specified name if the reactor has one - * and otherwise return null. - * @param name The parameter name. - */ - public ParameterInstance getParameter(String name) { - for (ParameterInstance parameter: parameters) { - if (parameter.getName().equals(name)) { - return parameter; - } - } - return null; + return super.uniqueID(); + } + + /** + * Return the specified output by name or null if there is no such output. + * + * @param name The output name. + */ + public PortInstance getOutput(String name) { + for (PortInstance port : outputs) { + if (port.getName().equals(name)) { + return port; + } } - - /** - * Return the startup trigger or null if not used in any reaction. - */ - public TriggerInstance getStartupTrigger() { - return builtinTriggers.get(BuiltinTrigger.STARTUP); + return null; + } + + /** + * Return a parameter matching the specified name if the reactor has one and otherwise return + * null. + * + * @param name The parameter name. + */ + public ParameterInstance getParameter(String name) { + for (ParameterInstance parameter : parameters) { + if (parameter.getName().equals(name)) { + return parameter; + } } - - /** - * Return the shutdown trigger or null if not used in any reaction. - */ - public TriggerInstance getShutdownTrigger() { - return builtinTriggers.get(BuiltinTrigger.SHUTDOWN); + return null; + } + + /** Return the startup trigger or null if not used in any reaction. */ + public TriggerInstance getStartupTrigger() { + return builtinTriggers.get(BuiltinTrigger.STARTUP); + } + + /** Return the shutdown trigger or null if not used in any reaction. */ + public TriggerInstance getShutdownTrigger() { + return builtinTriggers.get(BuiltinTrigger.SHUTDOWN); + } + + /** + * If this reactor is a bank or any of its parents is a bank, return the total number of runtime + * instances, which is the product of the widths of all the parents. Return -1 if the width cannot + * be determined. + */ + public int getTotalWidth() { + return getTotalWidth(0); + } + + /** + * If this reactor is a bank or any of its parents is a bank, return the total number of runtime + * instances, which is the product of the widths of all the parents. Return -1 if the width cannot + * be determined. + * + * @param atDepth The depth at which to determine the width. Use 0 to get the total number of + * instances. Use 1 to get the number of instances within a single top-level bank member (this + * is useful for federates). + */ + public int getTotalWidth(int atDepth) { + if (width <= 0) return -1; + if (depth <= atDepth) return 1; + int result = width; + ReactorInstance p = parent; + while (p != null && p.depth > atDepth) { + if (p.width <= 0) return -1; + result *= p.width; + p = p.parent; } - - /** - * If this reactor is a bank or any of its parents is a bank, - * return the total number of runtime instances, which is the product - * of the widths of all the parents. - * Return -1 if the width cannot be determined. - */ - public int getTotalWidth() { - return getTotalWidth(0); + return result; + } + + /** + * Return the trigger instances (input ports, timers, and actions that trigger reactions) + * belonging to this reactor instance. + */ + public Set> getTriggers() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); } - - /** - * If this reactor is a bank or any of its parents is a bank, - * return the total number of runtime instances, which is the product - * of the widths of all the parents. - * Return -1 if the width cannot be determined. - * @param atDepth The depth at which to determine the width. - * Use 0 to get the total number of instances. - * Use 1 to get the number of instances within a single top-level - * bank member (this is useful for federates). - */ - public int getTotalWidth(int atDepth) { - if (width <= 0) return -1; - if (depth <= atDepth) return 1; - int result = width; - ReactorInstance p = parent; - while (p != null && p.depth > atDepth) { - if (p.width <= 0) return -1; - result *= p.width; - p = p.parent; - } - return result; + return triggers; + } + + /** + * Return the trigger instances (input ports, timers, and actions that trigger reactions) together + * the ports that the reaction reads but that don't trigger it. + * + * @return The trigger instances belonging to this reactor instance. + */ + public Set> getTriggersAndReads() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); + triggers.addAll(reaction.reads); } + return triggers; + } + + /** Return true if the top-level parent of this reactor has causality cycles. */ + public boolean hasCycles() { + return assignLevels().nodeCount() != 0; + } + + /** + * Given a parameter definition for this reactor, return the initial integer value of the + * parameter. If the parameter is overridden when instantiating this reactor or any of its + * containing reactors, use that value. Otherwise, use the default value in the reactor + * definition. If the parameter cannot be found or its value is not an integer, return null. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * @return An integer value or null. + */ + public Integer initialIntParameterValue(Parameter parameter) { + return ASTUtils.initialValueInt(parameter, instantiations()); + } + + public Expression resolveParameters(Expression e) { + return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); + } + + private static final class ParameterInliner + extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { + static final ParameterInliner INSTANCE = new ParameterInliner(); - /** - * Return the trigger instances (input ports, timers, and actions - * that trigger reactions) belonging to this reactor instance. - */ - public Set> getTriggers() { - // FIXME: Cache this. - var triggers = new LinkedHashSet>(); - for (ReactionInstance reaction : this.reactions) { - triggers.addAll(reaction.triggers); + @Override + public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { + if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { + throw new IllegalArgumentException( + "Parameter " + + expr.getParameter().getName() + + " is not a parameter of reactor instance " + + instance.getName() + + "."); + } + + Optional assignment = + instance.definition.getParameters().stream() + .filter(it -> it.getLhs().equals(expr.getParameter())) + .findAny(); // There is at most one + + if (assignment.isPresent()) { + // replace the parameter with its value. + Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); + // recursively resolve parameters + return instance.getParent().resolveParameters(value); + } else { + // In that case use the default value. Default values + // cannot use parameter values, so they don't need to + // be recursively resolved. + Initializer init = expr.getParameter().getInit(); + Expression defaultValue = ASTUtils.asSingleExpr(init); + if (defaultValue == null) { + // this is a problem + return super.visitParameterRef(expr, instance); } - return triggers; + return defaultValue; + } } - - /** - * Return the trigger instances (input ports, timers, and actions - * that trigger reactions) together the ports that the reaction reads - * but that don't trigger it. - * - * @return The trigger instances belonging to this reactor instance. - */ - public Set> getTriggersAndReads() { - // FIXME: Cache this. - var triggers = new LinkedHashSet>(); - for (ReactionInstance reaction : this.reactions) { - triggers.addAll(reaction.triggers); - triggers.addAll(reaction.reads); + } + + /** + * Return a list of Instantiation objects for evaluating parameter values. The first object in the + * list is the AST Instantiation that created this reactor instance, the second is the AST + * instantiation that created the containing reactor instance, and so on until there are no more + * containing reactor instances. This will return an empty list if this reactor instance is at the + * top level (is main). + */ + public List instantiations() { + if (_instantiations == null) { + _instantiations = new ArrayList<>(); + if (definition != null) { + _instantiations.add(definition); + if (parent != null) { + _instantiations.addAll(parent.instantiations()); } - return triggers; + } } - - /** - * Return true if the top-level parent of this reactor has causality cycles. - */ - public boolean hasCycles() { - return assignLevels().nodeCount() != 0; + return _instantiations; + } + + /** + * Returns true if this is a bank of reactors. + * + * @return true if a reactor is a bank, false otherwise + */ + public boolean isBank() { + return definition.getWidthSpec() != null; + } + + /** + * Returns whether this is a main or federated reactor. + * + * @return true if reactor definition is marked as main or federated, false otherwise. + */ + public boolean isMainOrFederated() { + return reactorDefinition != null + && (reactorDefinition.isMain() || reactorDefinition.isFederated()); + } + + /** + * Return true if the specified reactor instance is either equal to this reactor instance or a + * parent of it. + * + * @param r The reactor instance. + */ + public boolean isParent(ReactorInstance r) { + ReactorInstance p = this; + while (p != null) { + if (p == r) return true; + p = p.getParent(); } - - /** - * Given a parameter definition for this reactor, return the initial integer - * value of the parameter. If the parameter is overridden when instantiating - * this reactor or any of its containing reactors, use that value. - * Otherwise, use the default value in the reactor definition. - * If the parameter cannot be found or its value is not an integer, return null. - * - * @param parameter The parameter definition (a syntactic object in the AST). - * - * @return An integer value or null. - */ - public Integer initialIntParameterValue(Parameter parameter) { - return ASTUtils.initialValueInt(parameter, instantiations()); + return false; + } + + /////////////////////////////////////////////////// + //// Methods for finding instances in this reactor given an AST node. + + /** + * Return the action instance within this reactor instance corresponding to the specified action + * reference. + * + * @param action The action as an AST node. + * @return The corresponding action instance or null if the action does not belong to this + * reactor. + */ + public ActionInstance lookupActionInstance(Action action) { + for (ActionInstance actionInstance : actions) { + if (actionInstance.definition == action) { + return actionInstance; + } } - - public Expression resolveParameters(Expression e) { - return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); + return null; + } + + /** + * Given a parameter definition, return the parameter instance corresponding to that definition, + * or null if there is no such instance. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * @return A parameter instance, or null if there is none. + */ + public ParameterInstance lookupParameterInstance(Parameter parameter) { + for (ParameterInstance param : parameters) { + if (param.definition == parameter) { + return param; + } } - - - private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { - static final ParameterInliner INSTANCE = new ParameterInliner(); - - @Override - public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { - if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { - throw new IllegalArgumentException("Parameter " - + expr.getParameter().getName() - + " is not a parameter of reactor instance " - + instance.getName() - + "." - ); - } - - Optional assignment = - instance.definition.getParameters().stream() - .filter(it -> it.getLhs().equals(expr.getParameter())) - .findAny(); // There is at most one - - if (assignment.isPresent()) { - // replace the parameter with its value. - Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); - // recursively resolve parameters - return instance.getParent().resolveParameters(value); - } else { - // In that case use the default value. Default values - // cannot use parameter values, so they don't need to - // be recursively resolved. - Initializer init = expr.getParameter().getInit(); - Expression defaultValue = ASTUtils.asSingleExpr(init); - if (defaultValue == null) { - // this is a problem - return super.visitParameterRef(expr, instance); - } - return defaultValue; - } - } + return null; + } + + /** + * Given a port definition, return the port instance corresponding to that definition, or null if + * there is no such instance. + * + * @param port The port definition (a syntactic object in the AST). + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(Port port) { + // Search one of the inputs and outputs sets. + List ports = null; + if (port instanceof Input) { + ports = this.inputs; + } else if (port instanceof Output) { + ports = this.outputs; } - - /** - * Return a list of Instantiation objects for evaluating parameter - * values. The first object in the list is the AST Instantiation - * that created this reactor instance, the second is the AST instantiation - * that created the containing reactor instance, and so on until there - * are no more containing reactor instances. This will return an empty - * list if this reactor instance is at the top level (is main). - */ - public List instantiations() { - if (_instantiations == null) { - _instantiations = new ArrayList<>(); - if (definition != null) { - _instantiations.add(definition); - if (parent != null) { - _instantiations.addAll(parent.instantiations()); - } - } - } - return _instantiations; + for (PortInstance portInstance : ports) { + if (portInstance.definition == port) { + return portInstance; + } } - - /** - * Returns true if this is a bank of reactors. - * @return true if a reactor is a bank, false otherwise - */ - public boolean isBank() { - return definition.getWidthSpec() != null; + return null; + } + + /** + * Given a reference to a port belonging to this reactor instance, return the port instance. + * Return null if there is no such instance. + * + * @param reference The port reference. + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(VarRef reference) { + if (!(reference.getVariable() instanceof Port)) { + // Trying to resolve something that is not a port + return null; } - - /** - * Returns whether this is a main or federated reactor. - * @return true if reactor definition is marked as main or federated, false otherwise. - */ - public boolean isMainOrFederated() { - return reactorDefinition != null - && (reactorDefinition.isMain() || reactorDefinition.isFederated()); + if (reference.getContainer() == null) { + // Handle local reference + return lookupPortInstance((Port) reference.getVariable()); + } else { + // Handle hierarchical reference + var containerInstance = getChildReactorInstance(reference.getContainer()); + if (containerInstance == null) return null; + return containerInstance.lookupPortInstance((Port) reference.getVariable()); } - - /** - * Return true if the specified reactor instance is either equal to this - * reactor instance or a parent of it. - * @param r The reactor instance. - */ - public boolean isParent(ReactorInstance r) { - ReactorInstance p = this; - while (p != null) { - if (p == r) return true; - p = p.getParent(); - } - return false; + } + + /** + * Return the reaction instance within this reactor instance corresponding to the specified + * reaction. + * + * @param reaction The reaction as an AST node. + * @return The corresponding reaction instance or null if the reaction does not belong to this + * reactor. + */ + public ReactionInstance lookupReactionInstance(Reaction reaction) { + for (ReactionInstance reactionInstance : reactions) { + if (reactionInstance.definition == reaction) { + return reactionInstance; + } } - - /////////////////////////////////////////////////// - //// Methods for finding instances in this reactor given an AST node. - - /** - * Return the action instance within this reactor - * instance corresponding to the specified action reference. - * @param action The action as an AST node. - * @return The corresponding action instance or null if the - * action does not belong to this reactor. - */ - public ActionInstance lookupActionInstance(Action action) { - for (ActionInstance actionInstance : actions) { - if (actionInstance.definition == action) { - return actionInstance; - } - } - return null; + return null; + } + + /** + * Return the reactor instance within this reactor that has the specified instantiation. Note that + * this may be a bank of reactors. Return null if there is no such reactor instance. + */ + public ReactorInstance lookupReactorInstance(Instantiation instantiation) { + for (ReactorInstance reactorInstance : children) { + if (reactorInstance.definition == instantiation) { + return reactorInstance; + } } - - /** - * Given a parameter definition, return the parameter instance - * corresponding to that definition, or null if there is - * no such instance. - * @param parameter The parameter definition (a syntactic object in the AST). - * @return A parameter instance, or null if there is none. - */ - public ParameterInstance lookupParameterInstance(Parameter parameter) { - for (ParameterInstance param : parameters) { - if (param.definition == parameter) { - return param; - } - } - return null; - } - - /** - * Given a port definition, return the port instance - * corresponding to that definition, or null if there is - * no such instance. - * @param port The port definition (a syntactic object in the AST). - * @return A port instance, or null if there is none. - */ - public PortInstance lookupPortInstance(Port port) { - // Search one of the inputs and outputs sets. - List ports = null; - if (port instanceof Input) { - ports = this.inputs; - } else if (port instanceof Output) { - ports = this.outputs; - } - for (PortInstance portInstance : ports) { - if (portInstance.definition == port) { - return portInstance; - } - } - return null; + return null; + } + + /** + * Return the timer instance within this reactor instance corresponding to the specified timer + * reference. + * + * @param timer The timer as an AST node. + * @return The corresponding timer instance or null if the timer does not belong to this reactor. + */ + public TimerInstance lookupTimerInstance(Timer timer) { + for (TimerInstance timerInstance : timers) { + if (timerInstance.definition == timer) { + return timerInstance; + } } - - /** - * Given a reference to a port belonging to this reactor - * instance, return the port instance. - * Return null if there is no such instance. - * @param reference The port reference. - * @return A port instance, or null if there is none. - */ - public PortInstance lookupPortInstance(VarRef reference) { - if (!(reference.getVariable() instanceof Port)) { - // Trying to resolve something that is not a port - return null; - } - if (reference.getContainer() == null) { - // Handle local reference - return lookupPortInstance((Port) reference.getVariable()); - } else { - // Handle hierarchical reference - var containerInstance = getChildReactorInstance(reference.getContainer()); - if (containerInstance == null) return null; - return containerInstance.lookupPortInstance((Port) reference.getVariable()); - } - } - - /** - * Return the reaction instance within this reactor - * instance corresponding to the specified reaction. - * @param reaction The reaction as an AST node. - * @return The corresponding reaction instance or null if the - * reaction does not belong to this reactor. - */ - public ReactionInstance lookupReactionInstance(Reaction reaction) { - for (ReactionInstance reactionInstance : reactions) { - if (reactionInstance.definition == reaction) { - return reactionInstance; - } - } - return null; + return null; + } + + /** + * Returns the mode instance within this reactor instance corresponding to the specified mode + * reference. + * + * @param mode The mode as an AST node. + * @return The corresponding mode instance or null if the mode does not belong to this reactor. + */ + public ModeInstance lookupModeInstance(Mode mode) { + for (ModeInstance modeInstance : modes) { + if (modeInstance.definition == mode) { + return modeInstance; + } } - - /** - * Return the reactor instance within this reactor - * that has the specified instantiation. Note that this - * may be a bank of reactors. Return null if there - * is no such reactor instance. - */ - public ReactorInstance lookupReactorInstance(Instantiation instantiation) { - for (ReactorInstance reactorInstance : children) { - if (reactorInstance.definition == instantiation) { - return reactorInstance; - } + return null; + } + + /** Return a descriptive string. */ + @Override + public String toString() { + return "ReactorInstance " + getFullName(); + } + + /** + * Assuming that the given expression denotes a valid time, return a time value. + * + *

If the value is given as a parameter reference, this will look up the precise time value + * assigned to this reactor instance. + */ + public TimeValue getTimeValue(Expression expr) { + Expression resolved = resolveParameters(expr); + return getLiteralTimeValue(resolved); + } + + ////////////////////////////////////////////////////// + //// Protected fields. + + /** The generator that created this reactor instance. */ + protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references + + /** The map of used built-in triggers. */ + protected Map> builtinTriggers = + new HashMap<>(); + + /** + * The LF syntax does not currently support declaring reactions unordered, but unordered reactions + * are created in the AST transformations handling federated communication and after delays. + * Unordered reactions can execute in any order and concurrently even though they are in the same + * reactor. FIXME: Remove this when the language provides syntax. + */ + protected Set unorderedReactions = new LinkedHashSet<>(); + + /** The nested list of instantiations that created this reactor instance. */ + protected List _instantiations; + + ////////////////////////////////////////////////////// + //// Protected methods. + + /** + * Create all the reaction instances of this reactor instance and record the dependencies and + * antidependencies between ports, actions, and timers and reactions. This also records the + * dependencies between reactions that follows from the order in which they are defined. + */ + protected void createReactionInstances() { + List reactions = ASTUtils.allReactions(reactorDefinition); + if (reactions != null) { + int count = 0; + + // Check for startup and shutdown triggers. + for (Reaction reaction : reactions) { + if (AttributeUtils.isUnordered(reaction)) { + unorderedReactions.add(reaction); } - return null; + // Create the reaction instance. + var reactionInstance = + new ReactionInstance(reaction, this, unorderedReactions.contains(reaction), count++); + + // Add the reaction instance to the map of reactions for this + // reactor. + this.reactions.add(reactionInstance); + } } - - /** - * Return the timer instance within this reactor - * instance corresponding to the specified timer reference. - * @param timer The timer as an AST node. - * @return The corresponding timer instance or null if the - * timer does not belong to this reactor. - */ - public TimerInstance lookupTimerInstance(Timer timer) { - for (TimerInstance timerInstance : timers) { - if (timerInstance.definition == timer) { - return timerInstance; - } - } - return null; + } + + /** Create all the watchdog instances of this reactor instance. */ + protected void createWatchdogInstances() { + List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); + if (watchdogs != null) { + for (Watchdog watchdog : watchdogs) { + // Create the watchdog instance. + var watchdogInstance = new WatchdogInstance(watchdog, this); + + // Add the watchdog instance to the list of watchdogs for this + // reactor. + this.watchdogs.add(watchdogInstance); + } } - - /** Returns the mode instance within this reactor - * instance corresponding to the specified mode reference. - * @param mode The mode as an AST node. - * @return The corresponding mode instance or null if the - * mode does not belong to this reactor. - */ - public ModeInstance lookupModeInstance(Mode mode) { - for (ModeInstance modeInstance : modes) { - if (modeInstance.definition == mode) { - return modeInstance; - } + } + + /** Returns the built-in trigger or create a new one if none exists. */ + protected TriggerInstance getOrCreateBuiltinTrigger( + BuiltinTriggerRef trigger) { + return builtinTriggers.computeIfAbsent( + trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + } + + //////////////////////////////////////// + //// Private constructors + + /** + * Create a runtime instance from the specified definition and with the specified parent that + * instantiated it. + * + * @param definition The instantiation statement in the AST. + * @param parent The parent, or null for the main rector. + * @param reporter An error reporter. + * @param desiredDepth The depth to which to expand the hierarchy. + */ + private ReactorInstance( + Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth) { + super(definition, parent); + this.reporter = reporter; + this.reactorDeclaration = definition.getReactorClass(); + this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); + + // check for recursive instantiation + var currentParent = parent; + var foundSelfAsParent = false; + do { + if (currentParent != null) { + if (currentParent.reactorDefinition == this.reactorDefinition) { + foundSelfAsParent = true; + currentParent = null; // break + } else { + currentParent = currentParent.parent; } - return null; - } + } + } while (currentParent != null); - /** - * Return a descriptive string. - */ - @Override - public String toString() { - return "ReactorInstance " + getFullName(); - } - - /** - * Assuming that the given expression denotes a valid time, return a time value. - * - * If the value is given as a parameter reference, this will look up the - * precise time value assigned to this reactor instance. - */ - public TimeValue getTimeValue(Expression expr) { - Expression resolved = resolveParameters(expr); - return getLiteralTimeValue(resolved); + this.recursive = foundSelfAsParent; + if (recursive) { + reporter.reportError(definition, "Recursive reactor instantiation."); } - - ////////////////////////////////////////////////////// - //// Protected fields. - - /** The generator that created this reactor instance. */ - protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references - - /** The map of used built-in triggers. */ - protected Map> builtinTriggers = new HashMap<>(); - - /** - * The LF syntax does not currently support declaring reactions unordered, - * but unordered reactions are created in the AST transformations handling - * federated communication and after delays. Unordered reactions can execute - * in any order and concurrently even though they are in the same reactor. - * FIXME: Remove this when the language provides syntax. - */ - protected Set unorderedReactions = new LinkedHashSet<>(); - - /** The nested list of instantiations that created this reactor instance. */ - protected List _instantiations; - - ////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Create all the reaction instances of this reactor instance - * and record the dependencies and antidependencies - * between ports, actions, and timers and reactions. - * This also records the dependencies between reactions - * that follows from the order in which they are defined. - */ - protected void createReactionInstances() { - List reactions = ASTUtils.allReactions(reactorDefinition); - if (reactions != null) { - int count = 0; - - // Check for startup and shutdown triggers. - for (Reaction reaction : reactions) { - if (AttributeUtils.isUnordered(reaction)) { - unorderedReactions.add(reaction); - } - // Create the reaction instance. - var reactionInstance = new ReactionInstance(reaction, this, - unorderedReactions.contains(reaction), count++); - - // Add the reaction instance to the map of reactions for this - // reactor. - this.reactions.add(reactionInstance); - } - } + + // If the reactor definition is null, give up here. Otherwise, diagram generation + // will fail an NPE. + if (reactorDefinition == null) { + reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); + return; } - /** - * Create all the watchdog instances of this reactor instance. - */ - protected void createWatchdogInstances() { - List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); - if (watchdogs != null) { - for (Watchdog watchdog : watchdogs) { - // Create the watchdog instance. - var watchdogInstance = new WatchdogInstance(watchdog, this); - - // Add the watchdog instance to the list of watchdogs for this - // reactor. - this.watchdogs.add(watchdogInstance); - } - } + setInitialWidth(); + + // Apply overrides and instantiate parameters for this reactor instance. + for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { + this.parameters.add(new ParameterInstance(parameter, this)); } - /** - * Returns the built-in trigger or create a new one if none exists. - */ - protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { - return builtinTriggers.computeIfAbsent(trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + // Instantiate inputs for this reactor instance + for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { + this.inputs.add(new PortInstance(inputDecl, this, reporter)); } - - //////////////////////////////////////// - //// Private constructors - - /** - * Create a runtime instance from the specified definition - * and with the specified parent that instantiated it. - * @param definition The instantiation statement in the AST. - * @param parent The parent, or null for the main rector. - * @param reporter An error reporter. - * @param desiredDepth The depth to which to expand the hierarchy. - */ - private ReactorInstance( - Instantiation definition, - ReactorInstance parent, - ErrorReporter reporter, - int desiredDepth) { - super(definition, parent); - this.reporter = reporter; - this.reactorDeclaration = definition.getReactorClass(); - this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - - // check for recursive instantiation - var currentParent = parent; - var foundSelfAsParent = false; - do { - if (currentParent != null) { - if (currentParent.reactorDefinition == this.reactorDefinition) { - foundSelfAsParent = true; - currentParent = null; // break - } else { - currentParent = currentParent.parent; - } - } - } while(currentParent != null); - - this.recursive = foundSelfAsParent; - if (recursive) { - reporter.reportError(definition, "Recursive reactor instantiation."); - } - - // If the reactor definition is null, give up here. Otherwise, diagram generation - // will fail an NPE. - if (reactorDefinition == null) { - reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); - return; - } - - setInitialWidth(); - - // Apply overrides and instantiate parameters for this reactor instance. - for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { - this.parameters.add(new ParameterInstance(parameter, this)); - } - // Instantiate inputs for this reactor instance - for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { - this.inputs.add(new PortInstance(inputDecl, this, reporter)); - } + // Instantiate outputs for this reactor instance + for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { + this.outputs.add(new PortInstance(outputDecl, this, reporter)); + } - // Instantiate outputs for this reactor instance - for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { - this.outputs.add(new PortInstance(outputDecl, this, reporter)); + // Do not process content (except interface above) if recursive + if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { + // Instantiate children for this reactor instance. + // While doing this, assign an index offset to each. + for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { + var childInstance = new ReactorInstance(child, this, reporter, desiredDepth); + this.children.add(childInstance); + } + + // Instantiate timers for this reactor instance + for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { + this.timers.add(new TimerInstance(timerDecl, this)); + } + + // Instantiate actions for this reactor instance + for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { + this.actions.add(new ActionInstance(actionDecl, this)); + } + + establishPortConnections(); + + // Create the reaction instances in this reactor instance. + // This also establishes all the implied dependencies. + // Note that this can only happen _after_ the children, + // port, action, and timer instances have been created. + createReactionInstances(); + + // Create the reaction instances in this reactor instance. + createWatchdogInstances(); + + // Instantiate modes for this reactor instance + // This must come after the child elements (reactions, etc) of this reactor + // are created in order to allow their association with modes + for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { + this.modes.add(new ModeInstance(modeDecl, this)); + } + for (ModeInstance mode : this.modes) { + mode.setupTranstions(); + } + } + } + + ////////////////////////////////////////////////////// + //// Private methods. + + /** + * Connect the given left port range to the given right port range. + * + *

NOTE: This method is public to enable its use in unit tests. Otherwise, it should be + * private. This is why it is defined here, in the section labeled "Private methods." + * + * @param src The source range. + * @param dst The destination range. + * @param connection The connection establishing this relationship. + */ + public static void connectPortInstances( + RuntimeRange src, RuntimeRange dst, Connection connection) { + SendRange range = new SendRange(src, dst, src._interleaved, connection); + src.instance.dependentPorts.add(range); + dst.instance.dependsOnPorts.add(src); + } + + /** + * Populate connectivity information in the port instances. Note that this can only happen _after_ + * the children and port instances have been created. Unfortunately, we have to do some + * complicated things here to support multiport-to-multiport, multiport-to-bank, and + * bank-to-multiport communication. The principle being followed is: in each connection statement, + * for each port instance on the left, connect to the next available port on the right. + */ + private void establishPortConnections() { + for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { + List> leftPorts = + listPortInstances(connection.getLeftPorts(), connection); + Iterator> srcRanges = leftPorts.iterator(); + List> rightPorts = + listPortInstances(connection.getRightPorts(), connection); + Iterator> dstRanges = rightPorts.iterator(); + + // Check for empty lists. + if (!srcRanges.hasNext()) { + if (dstRanges.hasNext()) { + reporter.reportWarning(connection, "No sources to provide inputs."); } - - // Do not process content (except interface above) if recursive - if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { - // Instantiate children for this reactor instance. - // While doing this, assign an index offset to each. - for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { - var childInstance = new ReactorInstance( - child, - this, - reporter, - desiredDepth - ); - this.children.add(childInstance); + return; + } else if (!dstRanges.hasNext()) { + reporter.reportWarning(connection, "No destination. Outputs will be lost."); + return; + } + + RuntimeRange src = srcRanges.next(); + RuntimeRange dst = dstRanges.next(); + + while (true) { + if (dst.width == src.width) { + connectPortInstances(src, dst, connection); + if (!dstRanges.hasNext()) { + if (srcRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Source is wider than the destination. Outputs will be lost."); } - - // Instantiate timers for this reactor instance - for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { - this.timers.add(new TimerInstance(timerDecl, this)); - } - - // Instantiate actions for this reactor instance - for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { - this.actions.add(new ActionInstance(actionDecl, this)); - } - - establishPortConnections(); - - // Create the reaction instances in this reactor instance. - // This also establishes all the implied dependencies. - // Note that this can only happen _after_ the children, - // port, action, and timer instances have been created. - createReactionInstances(); - - // Create the reaction instances in this reactor instance. - createWatchdogInstances(); - - // Instantiate modes for this reactor instance - // This must come after the child elements (reactions, etc) of this reactor - // are created in order to allow their association with modes - for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { - this.modes.add(new ModeInstance(modeDecl, this)); + break; + } + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + if (dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Destination is wider than the source. Inputs will be missing."); + } + break; } - for (ModeInstance mode : this.modes) { - mode.setupTranstions(); + } + dst = dstRanges.next(); + src = srcRanges.next(); + } else if (dst.width < src.width) { + // Split the left (src) range in two. + connectPortInstances(src.head(dst.width), dst, connection); + src = src.tail(dst.width); + if (!dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Source is wider than the destination. Outputs will be lost."); + break; + } + dst = dstRanges.next(); + } else if (src.width < dst.width) { + // Split the right (dst) range in two. + connectPortInstances(src, dst.head(src.width), connection); + dst = dst.tail(src.width); + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + reporter.reportWarning( + connection, "Destination is wider than the source. Inputs will be missing."); + break; } + } + src = srcRanges.next(); } + } } - - ////////////////////////////////////////////////////// - //// Private methods. - - /** - * Connect the given left port range to the given right port range. - * - * NOTE: This method is public to enable its use in unit tests. - * Otherwise, it should be private. This is why it is defined here, - * in the section labeled "Private methods." - * - * @param src The source range. - * @param dst The destination range. - * @param connection The connection establishing this relationship. - */ - public static void connectPortInstances( - RuntimeRange src, - RuntimeRange dst, - Connection connection - ) { - SendRange range = new SendRange(src, dst, src._interleaved, connection); - src.instance.dependentPorts.add(range); - dst.instance.dependsOnPorts.add(src); + } + + /** + * If path exists from the specified port to any reaction in the specified set of reactions, then + * add the specified port and all ports along the path to the specified set of ports. + * + * @return True if the specified port was added. + */ + private boolean findPaths( + PortInstance port, Set reactions, Set ports) { + if (ports.contains(port)) return false; + boolean result = false; + for (ReactionInstance d : port.getDependentReactions()) { + if (reactions.contains(d)) ports.add(port); + result = true; } - - /** - * Populate connectivity information in the port instances. - * Note that this can only happen _after_ the children and port instances have been created. - * Unfortunately, we have to do some complicated things here - * to support multiport-to-multiport, multiport-to-bank, - * and bank-to-multiport communication. The principle being followed is: - * in each connection statement, for each port instance on the left, - * connect to the next available port on the right. - */ - private void establishPortConnections() { - for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { - List> leftPorts = listPortInstances(connection.getLeftPorts(), connection); - Iterator> srcRanges = leftPorts.iterator(); - List> rightPorts = listPortInstances(connection.getRightPorts(), connection); - Iterator> dstRanges = rightPorts.iterator(); - - // Check for empty lists. - if (!srcRanges.hasNext()) { - if (dstRanges.hasNext()) { - reporter.reportWarning(connection, "No sources to provide inputs."); - } - return; - } else if (!dstRanges.hasNext()) { - reporter.reportWarning(connection, "No destination. Outputs will be lost."); - return; - } - - RuntimeRange src = srcRanges.next(); - RuntimeRange dst = dstRanges.next(); - - while(true) { - if (dst.width == src.width) { - connectPortInstances(src, dst, connection); - if (!dstRanges.hasNext()) { - if (srcRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Source is wider than the destination. Outputs will be lost."); - } - break; - } - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - if (dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Destination is wider than the source. Inputs will be missing."); - } - break; - } - } - dst = dstRanges.next(); - src = srcRanges.next(); - } else if (dst.width < src.width) { - // Split the left (src) range in two. - connectPortInstances(src.head(dst.width), dst, connection); - src = src.tail(dst.width); - if (!dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Source is wider than the destination. Outputs will be lost."); - break; - } - dst = dstRanges.next(); - } else if (src.width < dst.width) { - // Split the right (dst) range in two. - connectPortInstances(src, dst.head(src.width), connection); - dst = dst.tail(src.width); - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - reporter.reportWarning(connection, - "Destination is wider than the source. Inputs will be missing."); - break; - } - } - src = srcRanges.next(); - } - } + // Perform a depth-first search. + for (SendRange r : port.dependentPorts) { + for (RuntimeRange p : r.destinations) { + boolean added = findPaths(p.instance, reactions, ports); + if (added) { + result = true; + ports.add(port); } + } } - - /** - * If path exists from the specified port to any reaction in the specified - * set of reactions, then add the specified port and all ports along the path - * to the specified set of ports. - * @return True if the specified port was added. - */ - private boolean findPaths( - PortInstance port, - Set reactions, - Set ports - ) { - if (ports.contains(port)) return false; - boolean result = false; - for (ReactionInstance d : port.getDependentReactions()) { - if (reactions.contains(d)) ports.add(port); - result = true; - } - // Perform a depth-first search. - for (SendRange r : port.dependentPorts) { - for (RuntimeRange p : r.destinations) { - boolean added = findPaths(p.instance, reactions, ports); - if (added) { - result = true; - ports.add(port); - } - } - } + return result; + } + + /** + * Given a list of port references, as found on either side of a connection, return a list of the + * port instance ranges referenced. These may be multiports, and may be ports of a contained bank + * (a port representing ports of the bank members) so the returned list includes ranges of banks + * and channels. + * + *

If a given port reference has the form `interleaved(b.m)`, where `b` is a bank and `m` is a + * multiport, then the corresponding range in the returned list is marked interleaved. + * + *

For example, if `b` and `m` have width 2, without the interleaved keyword, the returned + * range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. With the interleaved marking, the + * returned range represents the sequence `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have + * width 4. + * + * @param references The variable references on one side of the connection. + * @param connection The connection. + */ + private List> listPortInstances( + List references, Connection connection) { + List> result = new ArrayList<>(); + List> tails = new LinkedList<>(); + int count = 0; + for (VarRef portRef : references) { + // Simple error checking first. + if (!(portRef.getVariable() instanceof Port)) { + reporter.reportError(portRef, "Not a port."); return result; - } - - /** - * Given a list of port references, as found on either side of a connection, - * return a list of the port instance ranges referenced. These may be multiports, - * and may be ports of a contained bank (a port representing ports of the bank - * members) so the returned list includes ranges of banks and channels. - * - * If a given port reference has the form `interleaved(b.m)`, where `b` is - * a bank and `m` is a multiport, then the corresponding range in the returned - * list is marked interleaved. - * - * For example, if `b` and `m` have width 2, without the interleaved keyword, - * the returned range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. - * With the interleaved marking, the returned range represents the sequence - * `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have width 4. - * - * @param references The variable references on one side of the connection. - * @param connection The connection. - */ - private List> listPortInstances( - List references, Connection connection - ) { - List> result = new ArrayList<>(); - List> tails = new LinkedList<>(); - int count = 0; - for (VarRef portRef : references) { - // Simple error checking first. - if (!(portRef.getVariable() instanceof Port)) { - reporter.reportError(portRef, "Not a port."); - return result; - } - // First, figure out which reactor we are dealing with. - // The reactor we want is the container of the port. - // If the port reference has no container, then the reactor is this one. - var reactor = this; - if (portRef.getContainer() != null) { - reactor = getChildReactorInstance(portRef.getContainer()); - } - // The reactor can be null only if there is an error in the code. - // Skip this portRef so that diagram synthesis can complete. - if (reactor != null) { - PortInstance portInstance = reactor.lookupPortInstance( - (Port) portRef.getVariable()); - - Set interleaved = new LinkedHashSet<>(); - if (portRef.isInterleaved()) { - // NOTE: Here, we are assuming that the interleaved() - // keyword is only allowed on the multiports contained by - // contained reactors. - interleaved.add(portInstance.parent); - } - RuntimeRange range = new RuntimeRange.Port( - portInstance, interleaved); - // If this portRef is not the last one in the references list - // then we have to check whether the range can be incremented at - // the lowest two levels (port and container). If not, - // split the range and add the tail to list to iterate over again. - // The reason for this is that the connection has only local visibility, - // but the range width may be reflective of bank structure higher - // in the hierarchy. - if (count < references.size() - 1) { - int portWidth = portInstance.width; - int portParentWidth = portInstance.parent.width; - // If the port is being connected on the inside and there is - // more than one port in the list, then we can only connect one - // bank member at a time. - if (reactor == this && references.size() > 1) { - portParentWidth = 1; - } - int widthBound = portWidth * portParentWidth; - - // If either of these widths cannot be determined, assume infinite. - if (portWidth < 0) widthBound = Integer.MAX_VALUE; - if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < range.width) { - // Need to split the range. - tails.add(range.tail(widthBound)); - range = range.head(widthBound); - } - } - result.add(range); - } + } + // First, figure out which reactor we are dealing with. + // The reactor we want is the container of the port. + // If the port reference has no container, then the reactor is this one. + var reactor = this; + if (portRef.getContainer() != null) { + reactor = getChildReactorInstance(portRef.getContainer()); + } + // The reactor can be null only if there is an error in the code. + // Skip this portRef so that diagram synthesis can complete. + if (reactor != null) { + PortInstance portInstance = reactor.lookupPortInstance((Port) portRef.getVariable()); + + Set interleaved = new LinkedHashSet<>(); + if (portRef.isInterleaved()) { + // NOTE: Here, we are assuming that the interleaved() + // keyword is only allowed on the multiports contained by + // contained reactors. + interleaved.add(portInstance.parent); } - // Iterate over the tails. - while(tails.size() > 0) { - List> moreTails = new LinkedList<>(); - count = 0; - for (RuntimeRange tail : tails) { - if (count < tails.size() - 1) { - int widthBound = tail.instance.width; - if (tail._interleaved.contains(tail.instance.parent)) { - widthBound = tail.instance.parent.width; - } - // If the width cannot be determined, assume infinite. - if (widthBound < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < tail.width) { - // Need to split the range again - moreTails.add(tail.tail(widthBound)); - tail = tail.head(widthBound); - } - } - result.add(tail); - } - tails = moreTails; + RuntimeRange range = new RuntimeRange.Port(portInstance, interleaved); + // If this portRef is not the last one in the references list + // then we have to check whether the range can be incremented at + // the lowest two levels (port and container). If not, + // split the range and add the tail to list to iterate over again. + // The reason for this is that the connection has only local visibility, + // but the range width may be reflective of bank structure higher + // in the hierarchy. + if (count < references.size() - 1) { + int portWidth = portInstance.width; + int portParentWidth = portInstance.parent.width; + // If the port is being connected on the inside and there is + // more than one port in the list, then we can only connect one + // bank member at a time. + if (reactor == this && references.size() > 1) { + portParentWidth = 1; + } + int widthBound = portWidth * portParentWidth; + + // If either of these widths cannot be determined, assume infinite. + if (portWidth < 0) widthBound = Integer.MAX_VALUE; + if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < range.width) { + // Need to split the range. + tails.add(range.tail(widthBound)); + range = range.head(widthBound); + } } - return result; + result.add(range); + } } - - /** - * If this is a bank of reactors, set the width. - * It will be set to -1 if it cannot be determined. - */ - private void setInitialWidth() { - WidthSpec widthSpec = definition.getWidthSpec(); - if (widthSpec != null) { - // We need the instantiations list of the containing reactor, - // not this one. - width = ASTUtils.width(widthSpec, parent.instantiations()); + // Iterate over the tails. + while (tails.size() > 0) { + List> moreTails = new LinkedList<>(); + count = 0; + for (RuntimeRange tail : tails) { + if (count < tails.size() - 1) { + int widthBound = tail.instance.width; + if (tail._interleaved.contains(tail.instance.parent)) { + widthBound = tail.instance.parent.width; + } + // If the width cannot be determined, assume infinite. + if (widthBound < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < tail.width) { + // Need to split the range again + moreTails.add(tail.tail(widthBound)); + tail = tail.head(widthBound); + } } + result.add(tail); + } + tails = moreTails; } - - ////////////////////////////////////////////////////// - //// Private fields. - - /** - * Cached set of reactions and ports that form a causality loop. - */ - private Set> cachedCycles; - - /** - * Cached reaction graph containing reactions that form a causality loop. - */ - private ReactionInstanceGraph cachedReactionLoopGraph = null; - - /** - * Return true if this is a generated delay reactor that originates from - * an "after" delay on a connection. - * - * @return True if this is a generated delay, false otherwise. - */ - public boolean isGeneratedDelay() { - if (this.definition.getReactorClass().getName().contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME)) { - return true; - } - return false; + return result; + } + + /** + * If this is a bank of reactors, set the width. It will be set to -1 if it cannot be determined. + */ + private void setInitialWidth() { + WidthSpec widthSpec = definition.getWidthSpec(); + if (widthSpec != null) { + // We need the instantiations list of the containing reactor, + // not this one. + width = ASTUtils.width(widthSpec, parent.instantiations()); + } + } + + ////////////////////////////////////////////////////// + //// Private fields. + + /** Cached set of reactions and ports that form a causality loop. */ + private Set> cachedCycles; + + /** Cached reaction graph containing reactions that form a causality loop. */ + private ReactionInstanceGraph cachedReactionLoopGraph = null; + + /** + * Return true if this is a generated delay reactor that originates from an "after" delay on a + * connection. + * + * @return True if this is a generated delay, false otherwise. + */ + public boolean isGeneratedDelay() { + if (this.definition + .getReactorClass() + .getName() + .contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME)) { + return true; } + return false; + } } diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 001246cf2f..ca5cb3d192 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -4,64 +4,60 @@ import org.lflang.lf.Watchdog; /** - * Instance of a watchdog. Upon creation the actual delay is converted into - * a proper time value. If a parameter is referenced, it is looked up in the - * given (grand)parent reactor instance. - * + * Instance of a watchdog. Upon creation the actual delay is converted into a proper time value. If + * a parameter is referenced, it is looked up in the given (grand)parent reactor instance. + * * @author{Benjamin Asch } */ public class WatchdogInstance { - - /** - * Create a new watchdog instance associated with the given reactor - * instance. - */ - public WatchdogInstance(Watchdog definition, ReactorInstance reactor) { - if (definition.getTimeout() != null) { - // Get the timeout value given in the watchdog declaration. - this.timeout = reactor.getTimeValue(definition.getTimeout()); - } else { - // NOTE: The grammar does not allow the timeout to be omitted, so this should not occur. - this.timeout = TimeValue.ZERO; - } - this.name = definition.getName().toString(); - this.definition = definition; - this.reactor = reactor; + /** Create a new watchdog instance associated with the given reactor instance. */ + public WatchdogInstance(Watchdog definition, ReactorInstance reactor) { + if (definition.getTimeout() != null) { + // Get the timeout value given in the watchdog declaration. + this.timeout = reactor.getTimeValue(definition.getTimeout()); + } else { + // NOTE: The grammar does not allow the timeout to be omitted, so this should not occur. + this.timeout = TimeValue.ZERO; } - ////////////////////////////////////////////////////// - //// Public methods. + this.name = definition.getName().toString(); + this.definition = definition; + this.reactor = reactor; + } - public String getName() { - return this.name; - } + ////////////////////////////////////////////////////// + //// Public methods. - public Watchdog getDefinition() { - return this.definition; - } + public String getName() { + return this.name; + } - public TimeValue getTimeout() { - return (TimeValue) this.timeout; - } + public Watchdog getDefinition() { + return this.definition; + } - public ReactorInstance getReactor() { - return this.reactor; - } + public TimeValue getTimeout() { + return (TimeValue) this.timeout; + } - @Override - public String toString() { - return "WatchdogInstance " + name + "(" + timeout.toString() + ")"; - } + public ReactorInstance getReactor() { + return this.reactor; + } + + @Override + public String toString() { + return "WatchdogInstance " + name + "(" + timeout.toString() + ")"; + } - ////////////////////////////////////////////////////// - //// Private fields. + ////////////////////////////////////////////////////// + //// Private fields. - private final TimeValue timeout; + private final TimeValue timeout; - private final String name; + private final String name; - private final Watchdog definition; + private final Watchdog definition; - private final ReactorInstance reactor; + private final ReactorInstance reactor; } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 07d77cdbd5..0ded0e2bc2 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1,26 +1,26 @@ /************* -Copyright (c) 2019-2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator.c; @@ -36,6 +36,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import static org.lflang.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -45,44 +47,36 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; - import org.lflang.ASTUtils; -import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; - -import org.lflang.federated.extensions.CExtensionUtils; - import org.lflang.ast.DelayedConnectionTransformation; - +import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.DelayBodyGenerator; +import org.lflang.generator.DockerComposeGenerator; import org.lflang.generator.DockerGenerator; import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorUtils; -import org.lflang.generator.DelayBodyGenerator; - import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFResource; import org.lflang.generator.ParameterInstance; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; - -import org.lflang.generator.WatchdogInstance; - import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; import org.lflang.generator.TriggerInstance; +import org.lflang.generator.WatchdogInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Input; @@ -97,209 +91,172 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; import org.lflang.lf.Variable; -import org.lflang.util.ArduinoUtil; import org.lflang.lf.Watchdog; +import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; -import org.lflang.lf.Watchdog; -import org.lflang.util.LFCommand; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; - /** - * Generator for C target. This class generates C code defining each reactor - * class given in the input .lf file and imported .lf files. The generated code - * has the following components: + * Generator for C target. This class generates C code defining each reactor class given in the + * input .lf file and imported .lf files. The generated code has the following components: * - * * A typedef for inputs, outputs, and actions of each reactor class. These - * define the types of the variables that reactions use to access inputs and - * action values and to set output values. + *

* A typedef for inputs, outputs, and actions of each reactor class. These define the types of + * the variables that reactions use to access inputs and action values and to set output values. * - * * A typedef for a "self" struct for each reactor class. One instance of this - * struct will be created for each reactor instance. See below for details. + *

* A typedef for a "self" struct for each reactor class. One instance of this struct will be + * created for each reactor instance. See below for details. * - * * A function definition for each reaction in each reactor class. These - * functions take an instance of the self struct as an argument. + *

* A function definition for each reaction in each reactor class. These functions take an + * instance of the self struct as an argument. * - * * A constructor function for each reactor class. This is used to create - * a new instance of the reactor. + *

* A constructor function for each reactor class. This is used to create a new instance of the + * reactor. * - * After these, the main generated function is `_lf_initialize_trigger_objects()`. - * This function creates the instances of reactors (using their constructors) - * and makes connections between them. + *

After these, the main generated function is `_lf_initialize_trigger_objects()`. This function + * creates the instances of reactors (using their constructors) and makes connections between them. * - * A few other smaller functions are also generated. + *

A few other smaller functions are also generated. * - * ## Self Struct + *

## Self Struct * - * The "self" struct has fields for each of the following: + *

The "self" struct has fields for each of the following: * - * * parameter: the field name and type match the parameter. - * * state: the field name and type match the state. - * * action: the field name prepends the action name with "_lf_". - * A second field for the action is also created to house the trigger_t object. - * That second field prepends the action name with "_lf__". - * * output: the field name prepends the output name with "_lf_". - * * input: the field name prepends the output name with "_lf_". - * A second field for the input is also created to house the trigger_t object. - * That second field prepends the input name with "_lf__". + *

* parameter: the field name and type match the parameter. * state: the field name and type + * match the state. * action: the field name prepends the action name with "_lf_". A second field + * for the action is also created to house the trigger_t object. That second field prepends the + * action name with "_lf__". * output: the field name prepends the output name with "_lf_". * input: + * the field name prepends the output name with "_lf_". A second field for the input is also created + * to house the trigger_t object. That second field prepends the input name with "_lf__". * - * If, in addition, the reactor contains other reactors and reacts to their outputs, - * then there will be a struct within the self struct for each such contained reactor. - * The name of that self struct will be the name of the contained reactor prepended with "_lf_". - * That inside struct will contain pointers the outputs of the contained reactors - * that are read together with pointers to booleans indicating whether those outputs are present. + *

If, in addition, the reactor contains other reactors and reacts to their outputs, then there + * will be a struct within the self struct for each such contained reactor. The name of that self + * struct will be the name of the contained reactor prepended with "_lf_". That inside struct will + * contain pointers the outputs of the contained reactors that are read together with pointers to + * booleans indicating whether those outputs are present. * - * If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to - * trigger_t object (see reactor.h) for the shutdown event and an action struct named - * _lf_shutdown on the self struct. + *

If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to + * trigger_t object (see reactor.h) for the shutdown event and an action struct named _lf_shutdown + * on the self struct. * - * ## Reaction Functions + *

## Reaction Functions * - * For each reaction in a reactor class, this generator will produce a C function - * that expects a pointer to an instance of the "self" struct as an argument. - * This function will contain verbatim the C code specified in the reaction, but - * before that C code, the generator inserts a few lines of code that extract from the - * self struct the variables that that code has declared it will use. For example, if - * the reaction declares that it is triggered by or uses an input named "x" of type - * int, the function will contain a line like this: - * ``` - * r_x_t* x = self->_lf_x; - * ``` - * where `r` is the full name of the reactor class and the struct type `r_x_t` - * has fields `is_present` and `value`, where the type of `value` matches the port type. - * If the programmer fails to declare that it uses x, then the absence of the - * above code will trigger a compile error when the verbatim code attempts to read `x`. + *

For each reaction in a reactor class, this generator will produce a C function that expects a + * pointer to an instance of the "self" struct as an argument. This function will contain verbatim + * the C code specified in the reaction, but before that C code, the generator inserts a few lines + * of code that extract from the self struct the variables that that code has declared it will use. + * For example, if the reaction declares that it is triggered by or uses an input named "x" of type + * int, the function will contain a line like this: ``` r_x_t* x = self->_lf_x; ``` where `r` is the + * full name of the reactor class and the struct type `r_x_t` has fields `is_present` and `value`, + * where the type of `value` matches the port type. If the programmer fails to declare that it uses + * x, then the absence of the above code will trigger a compile error when the verbatim code + * attempts to read `x`. * - * ## Constructor + *

## Constructor * - * For each reactor class, this generator will create a constructor function named - * `new_r`, where `r` is the reactor class name. This function will malloc and return - * a pointer to an instance of the "self" struct. This struct initially represents - * an unconnected reactor. To establish connections between reactors, additional - * information needs to be inserted (see below). The self struct is made visible - * to the body of a reaction as a variable named "self". The self struct contains the - * following: + *

For each reactor class, this generator will create a constructor function named `new_r`, where + * `r` is the reactor class name. This function will malloc and return a pointer to an instance of + * the "self" struct. This struct initially represents an unconnected reactor. To establish + * connections between reactors, additional information needs to be inserted (see below). The self + * struct is made visible to the body of a reaction as a variable named "self". The self struct + * contains the following: * - * * Parameters: For each parameter `p` of the reactor, there will be a field `p` - * with the type and value of the parameter. So C code in the body of a reaction - * can access parameter values as `self->p`. + *

* Parameters: For each parameter `p` of the reactor, there will be a field `p` with the type + * and value of the parameter. So C code in the body of a reaction can access parameter values as + * `self->p`. * - * * State variables: For each state variable `s` of the reactor, there will be a field `s` - * with the type and value of the state variable. So C code in the body of a reaction - * can access state variables as `self->s`. + *

* State variables: For each state variable `s` of the reactor, there will be a field `s` with + * the type and value of the state variable. So C code in the body of a reaction can access state + * variables as `self->s`. * - * The self struct also contains various fields that the user is not intended to - * use. The names of these fields begin with at least two underscores. They are: + *

The self struct also contains various fields that the user is not intended to use. The names + * of these fields begin with at least two underscores. They are: * - * * Outputs: For each output named `out`, there will be a field `_lf_out` that is - * a struct containing a value field whose type matches that of the output. - * The output value is stored here. That struct also has a field `is_present` - * that is a boolean indicating whether the output has been set. - * This field is reset to false at the start of every time - * step. There is also a field `num_destinations` whose value matches the - * number of downstream reactors that use this variable. This field must be - * set when connections are made or changed. It is used to determine for - * a mutable input destination whether a copy needs to be made. + *

* Outputs: For each output named `out`, there will be a field `_lf_out` that is a struct + * containing a value field whose type matches that of the output. The output value is stored here. + * That struct also has a field `is_present` that is a boolean indicating whether the output has + * been set. This field is reset to false at the start of every time step. There is also a field + * `num_destinations` whose value matches the number of downstream reactors that use this variable. + * This field must be set when connections are made or changed. It is used to determine for a + * mutable input destination whether a copy needs to be made. * - * * Inputs: For each input named `in` of type T, there is a field named `_lf_in` - * that is a pointer struct with a value field of type T. The struct pointed - * to also has an `is_present` field of type bool that indicates whether the - * input is present. + *

* Inputs: For each input named `in` of type T, there is a field named `_lf_in` that is a + * pointer struct with a value field of type T. The struct pointed to also has an `is_present` field + * of type bool that indicates whether the input is present. * - * * Outputs of contained reactors: If a reactor reacts to outputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields pointing to those outputs. For example, - * if `r` has an output `out` of type T, then there will be field in `_lf_r` - * named `out` that points to a struct containing a value field - * of type T and a field named `is_present` of type bool. + *

* Outputs of contained reactors: If a reactor reacts to outputs of a contained reactor `r`, + * then the self struct will contain a nested struct named `_lf_r` that has fields pointing to those + * outputs. For example, if `r` has an output `out` of type T, then there will be field in `_lf_r` + * named `out` that points to a struct containing a value field of type T and a field named + * `is_present` of type bool. * - * * Inputs of contained reactors: If a reactor sends to inputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields for storing the values provided to those - * inputs. For example, if R has an input `in` of type T, then there will - * be field in _lf_R named `in` that is a struct with a value field - * of type T and a field named `is_present` of type bool. + *

* Inputs of contained reactors: If a reactor sends to inputs of a contained reactor `r`, then + * the self struct will contain a nested struct named `_lf_r` that has fields for storing the values + * provided to those inputs. For example, if R has an input `in` of type T, then there will be field + * in _lf_R named `in` that is a struct with a value field of type T and a field named `is_present` + * of type bool. * - * * Actions: If the reactor has an action a (logical or physical), then there - * will be a field in the self struct named `_lf_a` and another named `_lf__a`. - * The type of the first is specific to the action and contains a `value` - * field with the type and value of the action (if it has a value). That - * struct also has a `has_value` field, an `is_present` field, and a - * `token` field (which is NULL if the action carries no value). - * The `_lf__a` field is of type trigger_t. - * That struct contains various things, including an array of reactions - * sensitive to this trigger and a lf_token_t struct containing the value of - * the action, if it has a value. See reactor.h in the C library for - * details. + *

* Actions: If the reactor has an action a (logical or physical), then there will be a field in + * the self struct named `_lf_a` and another named `_lf__a`. The type of the first is specific to + * the action and contains a `value` field with the type and value of the action (if it has a + * value). That struct also has a `has_value` field, an `is_present` field, and a `token` field + * (which is NULL if the action carries no value). The `_lf__a` field is of type trigger_t. That + * struct contains various things, including an array of reactions sensitive to this trigger and a + * lf_token_t struct containing the value of the action, if it has a value. See reactor.h in the C + * library for details. * - * * Reactions: Each reaction will have several fields in the self struct. - * Each of these has a name that begins with `_lf__reaction_i`, where i is - * the number of the reaction, starting with 0. The fields are: - * * _lf__reaction_i: The struct that is put onto the reaction queue to - * execute the reaction (see reactor.h in the C library). + *

* Reactions: Each reaction will have several fields in the self struct. Each of these has a + * name that begins with `_lf__reaction_i`, where i is the number of the reaction, starting with 0. + * The fields are: * _lf__reaction_i: The struct that is put onto the reaction queue to execute the + * reaction (see reactor.h in the C library). * - * * Timers: For each timer t, there is are two fields in the self struct: - * * _lf__t: The trigger_t struct for this timer (see reactor.h). - * * _lf__t_reactions: An array of reactions (pointers to the - * reaction_t structs on this self struct) sensitive to this timer. + *

* Timers: For each timer t, there is are two fields in the self struct: * _lf__t: The + * trigger_t struct for this timer (see reactor.h). * _lf__t_reactions: An array of reactions + * (pointers to the reaction_t structs on this self struct) sensitive to this timer. * - * * Triggers: For each Timer, Action, Input, and Output of a contained - * reactor that triggers reactions, there will be a trigger_t struct - * on the self struct with name `_lf__t`, where t is the name of the trigger. + *

* Triggers: For each Timer, Action, Input, and Output of a contained reactor that triggers + * reactions, there will be a trigger_t struct on the self struct with name `_lf__t`, where t is the + * name of the trigger. * - * ## Connections Between Reactors + *

## Connections Between Reactors * - * Establishing connections between reactors involves two steps. - * First, each destination (e.g. an input port) must have pointers to - * the source (the output port). As explained above, for an input named - * `in`, the field `_lf_in->value` is a pointer to the output data being read. - * In addition, `_lf_in->is_present` is a pointer to the corresponding - * `out->is_present` field of the output reactor's self struct. + *

Establishing connections between reactors involves two steps. First, each destination (e.g. an + * input port) must have pointers to the source (the output port). As explained above, for an input + * named `in`, the field `_lf_in->value` is a pointer to the output data being read. In addition, + * `_lf_in->is_present` is a pointer to the corresponding `out->is_present` field of the output + * reactor's self struct. * - * In addition, the `reaction_i` struct on the self struct has a `triggers` - * field that records all the trigger_t structs for ports and actions - * that are triggered by the i-th reaction. The triggers field is - * an array of arrays of pointers to trigger_t structs. - * The length of the outer array is the number of output channels - * (single ports plus multiport widths) that the reaction effects - * plus the number of input port channels of contained - * reactors that it effects. Each inner array has a length equal to the - * number of final destinations of that output channel or input channel. - * The reaction_i struct has an array triggered_sizes that indicates - * the sizes of these inner arrays. The num_outputs field of the - * reaction_i struct gives the length of the triggered_sizes and - * (outer) triggers arrays. The num_outputs field is equal to the - * total number of single ports and multiport channels that the reaction - * writes to. + *

In addition, the `reaction_i` struct on the self struct has a `triggers` field that records + * all the trigger_t structs for ports and actions that are triggered by the i-th reaction. The + * triggers field is an array of arrays of pointers to trigger_t structs. The length of the outer + * array is the number of output channels (single ports plus multiport widths) that the reaction + * effects plus the number of input port channels of contained reactors that it effects. Each inner + * array has a length equal to the number of final destinations of that output channel or input + * channel. The reaction_i struct has an array triggered_sizes that indicates the sizes of these + * inner arrays. The num_outputs field of the reaction_i struct gives the length of the + * triggered_sizes and (outer) triggers arrays. The num_outputs field is equal to the total number + * of single ports and multiport channels that the reaction writes to. * - * ## Runtime Tables + *

## Runtime Tables * - * This generator creates an populates the following tables used at run time. - * These tables may have to be resized and adjusted when mutations occur. + *

This generator creates an populates the following tables used at run time. These tables may + * have to be resized and adjusted when mutations occur. * - * * _lf_is_present_fields: An array of pointers to booleans indicating whether an - * event is present. The _lf_start_time_step() function in reactor_common.c uses - * this to mark every event absent at the start of a time step. The size of this - * table is contained in the variable _lf_is_present_fields_size. - * * This table is accompanied by another list, _lf_is_present_fields_abbreviated, - * which only contains the is_present fields that have been set to true in the - * current tag. This list can allow a performance improvement if most ports are - * seldom present because only fields that have been set to true need to be - * reset to false. + *

* _lf_is_present_fields: An array of pointers to booleans indicating whether an event is + * present. The _lf_start_time_step() function in reactor_common.c uses this to mark every event + * absent at the start of a time step. The size of this table is contained in the variable + * _lf_is_present_fields_size. * This table is accompanied by another list, + * _lf_is_present_fields_abbreviated, which only contains the is_present fields that have been set + * to true in the current tag. This list can allow a performance improvement if most ports are + * seldom present because only fields that have been set to true need to be reset to false. * - * * _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown - * reactions. The length of this table is in the _lf_shutdown_triggers_size - * variable. + *

* _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown reactions. The + * length of this table is in the _lf_shutdown_triggers_size variable. * - * * _lf_timer_triggers: An array of pointers to trigger_t structs for timers that - * need to be started when the program runs. The length of this table is in the - * _lf_timer_triggers_size variable. + *

* _lf_timer_triggers: An array of pointers to trigger_t structs for timers that need to be + * started when the program runs. The length of this table is in the _lf_timer_triggers_size + * variable. * - * * _lf_action_table: For a federated execution, each federate will have this table - * that maps port IDs to the corresponding action struct, which can be cast to - * action_base_t. + *

* _lf_action_table: For a federated execution, each federate will have this table that maps + * port IDs to the corresponding action struct, which can be cast to action_base_t. * * @author Edward A. Lee * @author Marten Lohstroh @@ -314,1136 +271,1093 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */ @SuppressWarnings("StaticPseudoFunctionalStyleMethod") public class CGenerator extends GeneratorBase { - // Regular expression pattern for compiler error messages with resource - // and line number information. The first match will a resource URI in the - // form of "file:/path/file.lf". The second match will be a line number. - // The third match is a character position within the line. - // The fourth match will be the error message. - static final Pattern compileErrorPattern = Pattern.compile( - "^(?.*):(?\\d+):(?\\d+):(?.*)$" - ); - - public static int UNDEFINED_MIN_SPACING = -1; - - //////////////////////////////////////////// - //// Protected fields - - /** The main place to put generated code. */ - protected CodeBuilder code = new CodeBuilder(); - - /** Place to collect code to initialize the trigger objects for all reactor instances. */ - protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); - - protected final CFileConfig fileConfig; - - /** - * Count of the number of is_present fields of the self struct that - * need to be reinitialized in _lf_start_time_step(). - */ - protected int startTimeStepIsPresentCount = 0; - - //////////////////////////////////////////// - //// Private fields - /** - * Extra lines that need to go into the generated CMakeLists.txt. - */ - private String cMakeExtras = ""; - - /** Place to collect code to execute at the start of a time step. */ - private CodeBuilder startTimeStep = new CodeBuilder(); - - /** Count of the number of token pointers that need to have their - * reference count decremented in _lf_start_time_step(). - */ - private int timerCount = 0; - private int startupReactionCount = 0; - private int shutdownReactionCount = 0; - private int resetReactionCount = 0; - private int modalReactorCount = 0; - private int modalStateResetCount = 0; - private int watchdogCount = 0; - - // Indicate whether the generator is in Cpp mode or not - private final boolean CCppMode; - - private final CTypes types; - - private final CCmakeGenerator cmakeGenerator; - - protected CGenerator( - LFGeneratorContext context, - boolean CCppMode, - CTypes types, - CCmakeGenerator cmakeGenerator, - DelayBodyGenerator delayBodyGenerator - ) { - super(context); - this.fileConfig = (CFileConfig) context.getFileConfig(); - this.CCppMode = CCppMode; - this.types = types; - this.cmakeGenerator = cmakeGenerator; - - // Register the delayed connection transformation to be applied by GeneratorBase. - // transform both after delays and physical connections - registerTransformation(new DelayedConnectionTransformation(delayBodyGenerator, types, fileConfig.resource, true, true)); + // Regular expression pattern for compiler error messages with resource + // and line number information. The first match will a resource URI in the + // form of "file:/path/file.lf". The second match will be a line number. + // The third match is a character position within the line. + // The fourth match will be the error message. + static final Pattern compileErrorPattern = + Pattern.compile("^(?.*):(?\\d+):(?\\d+):(?.*)$"); + + public static int UNDEFINED_MIN_SPACING = -1; + + //////////////////////////////////////////// + //// Protected fields + + /** The main place to put generated code. */ + protected CodeBuilder code = new CodeBuilder(); + + /** Place to collect code to initialize the trigger objects for all reactor instances. */ + protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); + + protected final CFileConfig fileConfig; + + /** + * Count of the number of is_present fields of the self struct that need to be reinitialized in + * _lf_start_time_step(). + */ + protected int startTimeStepIsPresentCount = 0; + + //////////////////////////////////////////// + //// Private fields + /** Extra lines that need to go into the generated CMakeLists.txt. */ + private String cMakeExtras = ""; + + /** Place to collect code to execute at the start of a time step. */ + private CodeBuilder startTimeStep = new CodeBuilder(); + + /** + * Count of the number of token pointers that need to have their reference count decremented in + * _lf_start_time_step(). + */ + private int timerCount = 0; + + private int startupReactionCount = 0; + private int shutdownReactionCount = 0; + private int resetReactionCount = 0; + private int modalReactorCount = 0; + private int modalStateResetCount = 0; + private int watchdogCount = 0; + + // Indicate whether the generator is in Cpp mode or not + private final boolean CCppMode; + + private final CTypes types; + + private final CCmakeGenerator cmakeGenerator; + + protected CGenerator( + LFGeneratorContext context, + boolean CCppMode, + CTypes types, + CCmakeGenerator cmakeGenerator, + DelayBodyGenerator delayBodyGenerator) { + super(context); + this.fileConfig = (CFileConfig) context.getFileConfig(); + this.CCppMode = CCppMode; + this.types = types; + this.cmakeGenerator = cmakeGenerator; + + // Register the delayed connection transformation to be applied by GeneratorBase. + // transform both after delays and physical connections + registerTransformation( + new DelayedConnectionTransformation( + delayBodyGenerator, types, fileConfig.resource, true, true)); + } + + public CGenerator(LFGeneratorContext context, boolean ccppMode) { + this( + context, + ccppMode, + new CTypes(), + new CCmakeGenerator(context.getFileConfig(), List.of()), + new CDelayBodyGenerator(new CTypes())); + } + + /** + * Look for physical actions in all resources. If found, set threads to be at least one to allow + * asynchronous schedule calls. + */ + public void accommodatePhysicalActionsIfPresent() { + // If there are any physical actions, ensure the threaded engine is used and that + // keepalive is set to true, unless the user has explicitly set it to false. + for (Resource resource : GeneratorUtils.getResources(reactors)) { + for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { + if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { + // If the unthreaded runtime is not requested by the user, use the threaded runtime + // instead + // because it is the only one currently capable of handling asynchronous events. + if (!targetConfig.threading + && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = true; + errorReporter.reportWarning( + action, + "Using the threaded C runtime to allow for asynchronous handling of physical action" + + " " + + action.getName()); + return; + } + } + } } - - public CGenerator(LFGeneratorContext context, boolean ccppMode) { - this( - context, - ccppMode, - new CTypes(), - new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes()) - ); + } + + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + protected boolean isOSCompatible() { + if (GeneratorUtils.isHostWindows()) { + if (CCppMode) { + errorReporter.reportError( + "LF programs with a CCpp target are currently not supported on Windows. " + + "Exiting code generation."); + // FIXME: The incompatibility between our C runtime code and the + // Visual Studio compiler is extensive. + return false; + } } - - /** - * Look for physical actions in all resources. - * If found, set threads to be at least one to allow asynchronous schedule calls. - */ - public void accommodatePhysicalActionsIfPresent() { - // If there are any physical actions, ensure the threaded engine is used and that - // keepalive is set to true, unless the user has explicitly set it to false. - for (Resource resource : GeneratorUtils.getResources(reactors)) { - for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { - if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { - // If the unthreaded runtime is not requested by the user, use the threaded runtime instead - // because it is the only one currently capable of handling asynchronous events. - if (!targetConfig.threading && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = true; - errorReporter.reportWarning( - action, - "Using the threaded C runtime to allow for asynchronous handling of physical action " + - action.getName() - ); - return; - } - } - } - } + return true; + } + + /** + * Returns false if watchdogs exist and are unsupported in this context. Otherwise, return true. + * (DEPRECATED) Alternative implemented in GeneratorBase + */ + protected boolean isWatchdogCompatible() { + if (hasWatchdogs() && !targetConfig.threading) { + errorReporter.reportError("Watchdogs are not supported for unthreaded programs."); + return false; } - - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - protected boolean isOSCompatible() { - if (GeneratorUtils.isHostWindows()) { - if (CCppMode) { - errorReporter.reportError( - "LF programs with a CCpp target are currently not supported on Windows. " + - "Exiting code generation." - ); - // FIXME: The incompatibility between our C runtime code and the - // Visual Studio compiler is extensive. - return false; - } - } - return true; + if (hasWatchdogs() && CCppMode) { + // FIXME: check to see if watchdogs work in CCppMode cases + errorReporter.reportError("Watchdogs are not currently supported in the CCpp target."); } + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context The context in which the generator is invoked, including whether it is cancelled + * and whether it is a standalone context + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + super.doGenerate(resource, context); + if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; + if (!isOSCompatible()) return; // Incompatible OS and configuration + // if (!isWatchdogCompatible()) return; - /** Returns false if watchdogs exist and are - * unsupported in this context. - * Otherwise, return true. - * (DEPRECATED) Alternative implemented in GeneratorBase - */ - protected boolean isWatchdogCompatible() { - if (hasWatchdogs() && !targetConfig.threading) { - errorReporter.reportError( - "Watchdogs are not supported for unthreaded programs." - ); - return false; - } - if (hasWatchdogs() && CCppMode) { - //FIXME: check to see if watchdogs work in CCppMode cases - errorReporter.reportError( - "Watchdogs are not currently supported in the CCpp target." - ); - } - return true; - } + // Perform set up that does not generate code + setUpGeneralParameters(); - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * @param resource The resource containing the source code. - * @param context The context in which the generator is - * invoked, including whether it is cancelled and - * whether it is a standalone context - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - super.doGenerate(resource, context); - if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; - if (!isOSCompatible()) return; // Incompatible OS and configuration - // if (!isWatchdogCompatible()) return; - - // Perform set up that does not generate code - setUpGeneralParameters(); - - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); - handleProtoFiles(); - - var lfModuleName = fileConfig.name; - generateCodeFor(lfModuleName); - - // Derive target filename from the .lf filename. - var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); - var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; - - try { - - String srcPrefix = targetConfig.platformOptions.platform == Platform.ARDUINO ? "src/" : ""; - - // Copy the core lib - FileUtil.copyDirectoryFromClassPath( - "/lib/c/reactor-c/core", - fileConfig.getSrcGenPath().resolve(srcPrefix + "core"), - true - ); - // Copy the C target files - copyTargetFiles(); - - // For the Zephyr target, copy default config and board files. - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - FileUtil.copyDirectoryFromClassPath( - "/lib/platform/zephyr/boards", - fileConfig.getSrcGenPath().resolve("boards"), - false - ); - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/prj_lf.conf", - fileConfig.getSrcGenPath().resolve("prj_lf.conf"), - true - ); - - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/Kconfig", - fileConfig.getSrcGenPath().resolve("Kconfig"), - true - ); - } - - // Write the generated code - code.writeToFile(targetFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); + handleProtoFiles(); - // Create docker file. - if (targetConfig.dockerOptions != null && mainDef != null) { - try { - var dockerData = getDockerGenerator(context).generateDockerData(); - dockerData.writeDockerFile(); - (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); - } catch (IOException e) { - throw new RuntimeException("Error while writing Docker files", e); - } - } + var lfModuleName = fileConfig.name; + generateCodeFor(lfModuleName); - // If cmake is requested, generate the CMakeLists.txt - if (targetConfig.platformOptions.platform != Platform.ARDUINO) { - var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; - var cmakeCode = cmakeGenerator.generateCMakeCode( - List.of(cFilename), - lfModuleName, - errorReporter, - CCppMode, - mainDef != null, - cMakeExtras, - targetConfig - ); - try { - cmakeCode.writeToFile(cmakeFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - } else { - try { - FileUtil.arduinoDeleteHelper(fileConfig.getSrcGenPath().resolve("src/"), targetConfig.threading); - FileUtil.relativeIncludeHelper(fileConfig.getSrcGenPath().resolve("src/")); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - - if (!targetConfig.noCompile) { - ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); - arduinoUtil.buildArduino(fileConfig, targetConfig); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } else { - System.out.println("********"); - System.out.println("To compile your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli compile -b --build-property compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\nTo flash/upload your generated sketch to the board, run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); - // System.out.println("For a list of all boards installed on your computer, you can use the following command:\n\n\tarduino-cli board listall\n"); - context.finish( - GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null) - ); - } - GeneratorUtils.refreshProject(resource, context.getMode()); - return; - } + // Derive target filename from the .lf filename. + var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); + var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; - // Dump the additional compile definitions to a file to keep the generated project - // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can - // take over and do the rest of compilation. - try { - String compileDefs = targetConfig.compileDefinitions.keySet().stream() - .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) - .collect(Collectors.joining("\n")); - FileUtil.writeToFile( - compileDefs, - Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") - ); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + try { - // If this code generator is directly compiling the code, compile it now so that we - // clean it up after, removing the #line directives after errors have been reported. - if ( - !targetConfig.noCompile && targetConfig.dockerOptions == null - && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) - // This code is unreachable in LSP_FAST mode, so that check is omitted. - && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM - ) { - // FIXME: Currently, a lack of main is treated as a request to not produce - // a binary and produce a .o file instead. There should be a way to control - // this. - // Create an anonymous Runnable class and add it to the compileThreadPool - // so that compilation can happen in parallel. - var cleanCode = code.removeLines("#line"); - - var execName = lfModuleName; - var threadFileConfig = fileConfig; - var generator = this; // FIXME: currently only passed to report errors with line numbers in the Eclipse IDE - var CppMode = CCppMode; - // generatingContext.reportProgress( - // String.format("Generated code for %d/%d executables. Compiling...", federateCount, federates.size()), - // 100 * federateCount / federates.size() - // ); // FIXME: Move to FedGenerator - // Create the compiler to be used later - - var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); - try { - if (!cCompiler.runCCompiler(generator, context)) { - // If compilation failed, remove any bin files that may have been created. - CUtil.deleteBinFiles(threadFileConfig); - // If finish has already been called, it is illegal and makes no sense. However, - // if finish has already been called, then this must be a federated execution. - context.unsuccessfulFinish(); - } else { - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - cleanCode.writeToFile(targetFile); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + String srcPrefix = targetConfig.platformOptions.platform == Platform.ARDUINO ? "src/" : ""; - } + // Copy the core lib + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/core", fileConfig.getSrcGenPath().resolve(srcPrefix + "core"), true); + // Copy the C target files + copyTargetFiles(); - // If a build directive has been given, invoke it now. - // Note that the code does not get cleaned in this case. - if (!targetConfig.noCompile) { - if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { - CUtil.runBuildCommand( - fileConfig, - targetConfig, - commandFactory, - errorReporter, - this::reportCommandErrors, - context.getMode() - ); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - System.out.println("Compiled binary is in " + fileConfig.binPath); - } else { - context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); - } - - // In case we are in Eclipse, make sure the generated code is visible. - GeneratorUtils.refreshProject(resource, context.getMode()); + // For the Zephyr target, copy default config and board files. + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyDirectoryFromClassPath( + "/lib/platform/zephyr/boards", fileConfig.getSrcGenPath().resolve("boards"), false); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", + fileConfig.getSrcGenPath().resolve("prj_lf.conf"), + true); + + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath().resolve("Kconfig"), true); + } + + // Write the generated code + code.writeToFile(targetFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); } - private void generateCodeFor( - String lfModuleName - ) { - startTimeStepIsPresentCount = 0; - code.pr(generateDirectives()); - code.pr(generateTopLevelPreambles()); - code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); - // Generate code for each reactor. - generateReactorDefinitions(); - - // Generate main instance, if there is one. - // Note that any main reactors in imported files are ignored. - // Skip generation if there are cycles. - if (main != null) { - initializeTriggerObjects.pr(String.join("\n", - "int _lf_startup_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", - "int _lf_shutdown_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", - "int _lf_reset_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", - "int _lf_timer_triggers_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", - "int bank_index;", - "SUPPRESS_UNUSED_WARNING(bank_index);", - "int _lf_watchdog_number_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);" - )); - // Add counters for modal initialization - initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); - - // Create an array of arrays to store all self structs. - // This is needed because connections cannot be established until - // all reactor instances have self structs because ports that - // receive data reference the self structs of the originating - // reactors, which are arbitarily far away in the program graph. - generateSelfStructs(main); - generateReactorInstance(main); - - // If there are timers, create a table of timers to be initialized. - code.pr(CTimerGenerator.generateDeclarations(timerCount)); - - // If there are startup reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); - - // If there are shutdown reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); - - // If there are reset reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); - - // If there are watchdogs, create a table of triggers. - code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); - - // If there are modes, create a table of mode state to be checked for transitions. - code.pr(CModesGenerator.generateModeStatesTable( - hasModalReactors, - modalReactorCount, - modalStateResetCount - )); - - // Generate function to initialize the trigger objects for all reactors. - code.pr(CTriggerObjectsGenerator.generateInitializeTriggerObjects( - main, - targetConfig, - initializeTriggerObjects, - startTimeStep, - types, - lfModuleName, - startTimeStepIsPresentCount - )); - - // Generate function to trigger startup reactions for all reactors. - code.pr(CReactionGenerator.generateLfTriggerStartupReactions(startupReactionCount, hasModalReactors)); - - // Generate function to schedule timers for all reactors. - code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - - // Generate function to initialize mutexes for all reactors with watchdogs. - // needs to be implemented still - code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); - - // Generate a function that will either do nothing - // (if there is only one federate or the coordination - // is set to decentralized) or, if there are - // downstream federates, will notify the RTI - // that the specified logical time is complete. - if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) code.pr("extern \"C\""); - code.pr(String.join("\n", - "void logical_tag_complete(tag_t tag_to_send) {", - CExtensionUtils.surroundWithIfFederatedCentralized( - " _lf_logical_tag_complete(tag_to_send);" - ), - "}" - )); - - // Generate function to schedule shutdown reactions if any - // reactors have reactions to shutdown. - code.pr(CReactionGenerator.generateLfTriggerShutdownReactions(shutdownReactionCount, hasModalReactors)); - - // Generate an empty termination function for non-federated - // execution. For federated execution, an implementation is - // provided in federate.c. That implementation will resign - // from the federation and close any open sockets. - code.pr(""" - #ifndef FEDERATED - void terminate_execution() {} - #endif""" - ); - - - // Generate functions for modes - code.pr(CModesGenerator.generateLfInitializeModes( - hasModalReactors - )); - code.pr(CModesGenerator.generateLfHandleModeChanges( - hasModalReactors, - modalStateResetCount - )); - code.pr(CReactionGenerator.generateLfModeTriggeredReactions( - startupReactionCount, - resetReactionCount, - hasModalReactors - )); - } + // Create docker file. + if (targetConfig.dockerOptions != null && mainDef != null) { + try { + var dockerData = getDockerGenerator(context).generateDockerData(); + dockerData.writeDockerFile(); + (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + } catch (IOException e) { + throw new RuntimeException("Error while writing Docker files", e); + } } - @Override - public void checkModalReactorSupport(boolean __) { - // Modal reactors are currently only supported for non federated applications - super.checkModalReactorSupport(true); + // If cmake is requested, generate the CMakeLists.txt + if (targetConfig.platformOptions.platform != Platform.ARDUINO) { + var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; + var cmakeCode = + cmakeGenerator.generateCMakeCode( + List.of(cFilename), + lfModuleName, + errorReporter, + CCppMode, + mainDef != null, + cMakeExtras, + targetConfig); + try { + cmakeCode.writeToFile(cmakeFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + } else { + try { + FileUtil.arduinoDeleteHelper( + fileConfig.getSrcGenPath().resolve("src/"), targetConfig.threading); + FileUtil.relativeIncludeHelper(fileConfig.getSrcGenPath().resolve("src/")); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + + if (!targetConfig.noCompile) { + ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); + arduinoUtil.buildArduino(fileConfig, targetConfig); + context.finish(GeneratorResult.Status.COMPILED, null); + } else { + System.out.println("********"); + System.out.println( + "To compile your program, run the following command to see information about the board" + + " you plugged in:\n\n" + + "\tarduino-cli board list\n\n" + + "Grab the FQBN and PORT from the command and run the following command in the" + + " generated sources directory:\n\n" + + "\tarduino-cli compile -b --build-property" + + " compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property" + + " compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\n" + + "To flash/upload your generated sketch to the board, run the following command in" + + " the generated sources directory:\n\n" + + "\tarduino-cli upload -b -p \n"); + // System.out.println("For a list of all boards installed on your computer, you can use the + // following command:\n\n\tarduino-cli board listall\n"); + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + } + GeneratorUtils.refreshProject(resource, context.getMode()); + return; } - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - return String.join("\n", - "// Generated forwarding reaction for connections with the same destination", - "// but located in mutually exclusive modes.", - "lf_set("+dest+", "+source+"->value);" - ); + // Dump the additional compile definitions to a file to keep the generated project + // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can + // take over and do the rest of compilation. + try { + String compileDefs = + targetConfig.compileDefinitions.keySet().stream() + .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) + .collect(Collectors.joining("\n")); + FileUtil.writeToFile( + compileDefs, + Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt")); + } catch (IOException e) { + Exceptions.sneakyThrow(e); } - /** Set the scheduler type in the target config as needed. */ - private void pickScheduler() { - // Don't use a scheduler that does not prioritize reactions based on deadlines - // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. - if (!targetConfig.schedulerType.prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - if (hasDeadlines(reactors)) { - if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { - targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; - } - } + // If this code generator is directly compiling the code, compile it now so that we + // clean it up after, removing the #line directives after errors have been reported. + if (!targetConfig.noCompile + && targetConfig.dockerOptions == null + && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) + // This code is unreachable in LSP_FAST mode, so that check is omitted. + && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM) { + // FIXME: Currently, a lack of main is treated as a request to not produce + // a binary and produce a .o file instead. There should be a way to control + // this. + // Create an anonymous Runnable class and add it to the compileThreadPool + // so that compilation can happen in parallel. + var cleanCode = code.removeLines("#line"); + + var execName = lfModuleName; + var threadFileConfig = fileConfig; + var generator = + this; // FIXME: currently only passed to report errors with line numbers in the Eclipse + // IDE + var CppMode = CCppMode; + // generatingContext.reportProgress( + // String.format("Generated code for %d/%d executables. Compiling...", federateCount, + // federates.size()), + // 100 * federateCount / federates.size() + // ); // FIXME: Move to FedGenerator + // Create the compiler to be used later + + var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); + try { + if (!cCompiler.runCCompiler(generator, context)) { + // If compilation failed, remove any bin files that may have been created. + CUtil.deleteBinFiles(threadFileConfig); + // If finish has already been called, it is illegal and makes no sense. However, + // if finish has already been called, then this must be a federated execution. + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, null); } + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } } - private boolean hasDeadlines(List reactors) { - for (Reactor reactor : reactors) { - for (Reaction reaction : allReactions(reactor)) { - if (reaction.getDeadline() != null) { - return true; - } - } - } - return false; + // If a build directive has been given, invoke it now. + // Note that the code does not get cleaned in this case. + if (!targetConfig.noCompile) { + if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { + CUtil.runBuildCommand( + fileConfig, + targetConfig, + commandFactory, + errorReporter, + this::reportCommandErrors, + context.getMode()); + context.finish(GeneratorResult.Status.COMPILED, null); + } + System.out.println("Compiled binary is in " + fileConfig.binPath); + } else { + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); } - private boolean hasWatchdogs() { - for (Reactor reactor : reactors) { - List watchdogs = ASTUtils.allWatchdogs(reactor); - if (watchdogs != null && !watchdogs.isEmpty()) { - return true; - } - } - return false; + // In case we are in Eclipse, make sure the generated code is visible. + GeneratorUtils.refreshProject(resource, context.getMode()); + } + + private void generateCodeFor(String lfModuleName) { + startTimeStepIsPresentCount = 0; + code.pr(generateDirectives()); + code.pr(generateTopLevelPreambles()); + code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); + // Generate code for each reactor. + generateReactorDefinitions(); + + // Generate main instance, if there is one. + // Note that any main reactors in imported files are ignored. + // Skip generation if there are cycles. + if (main != null) { + initializeTriggerObjects.pr( + String.join( + "\n", + "int _lf_startup_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", + "int _lf_shutdown_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", + "int _lf_reset_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", + "int _lf_timer_triggers_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", + "int bank_index;", + "SUPPRESS_UNUSED_WARNING(bank_index);", + "int _lf_watchdog_number_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);")); + // Add counters for modal initialization + initializeTriggerObjects.pr( + CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); + + // Create an array of arrays to store all self structs. + // This is needed because connections cannot be established until + // all reactor instances have self structs because ports that + // receive data reference the self structs of the originating + // reactors, which are arbitarily far away in the program graph. + generateSelfStructs(main); + generateReactorInstance(main); + + // If there are timers, create a table of timers to be initialized. + code.pr(CTimerGenerator.generateDeclarations(timerCount)); + + // If there are startup reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); + + // If there are shutdown reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); + + // If there are reset reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); + + // If there are watchdogs, create a table of triggers. + code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); + + // If there are modes, create a table of mode state to be checked for transitions. + code.pr( + CModesGenerator.generateModeStatesTable( + hasModalReactors, modalReactorCount, modalStateResetCount)); + + // Generate function to initialize the trigger objects for all reactors. + code.pr( + CTriggerObjectsGenerator.generateInitializeTriggerObjects( + main, + targetConfig, + initializeTriggerObjects, + startTimeStep, + types, + lfModuleName, + startTimeStepIsPresentCount)); + + // Generate function to trigger startup reactions for all reactors. + code.pr( + CReactionGenerator.generateLfTriggerStartupReactions( + startupReactionCount, hasModalReactors)); + + // Generate function to schedule timers for all reactors. + code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); + + // Generate function to initialize mutexes for all reactors with watchdogs. + // needs to be implemented still + code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); + + // Generate a function that will either do nothing + // (if there is only one federate or the coordination + // is set to decentralized) or, if there are + // downstream federates, will notify the RTI + // that the specified logical time is complete. + if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) + code.pr("extern \"C\""); + code.pr( + String.join( + "\n", + "void logical_tag_complete(tag_t tag_to_send) {", + CExtensionUtils.surroundWithIfFederatedCentralized( + " _lf_logical_tag_complete(tag_to_send);"), + "}")); + + // Generate function to schedule shutdown reactions if any + // reactors have reactions to shutdown. + code.pr( + CReactionGenerator.generateLfTriggerShutdownReactions( + shutdownReactionCount, hasModalReactors)); + + // Generate an empty termination function for non-federated + // execution. For federated execution, an implementation is + // provided in federate.c. That implementation will resign + // from the federation and close any open sockets. + code.pr( + """ + #ifndef FEDERATED + void terminate_execution() {} + #endif"""); + + // Generate functions for modes + code.pr(CModesGenerator.generateLfInitializeModes(hasModalReactors)); + code.pr(CModesGenerator.generateLfHandleModeChanges(hasModalReactors, modalStateResetCount)); + code.pr( + CReactionGenerator.generateLfModeTriggeredReactions( + startupReactionCount, resetReactionCount, hasModalReactors)); } - - /** - * Look at the 'reactor' eResource. - * If it is an imported .lf file, incorporate it into the current - * program in the following manner: - * - Merge its target property with `targetConfig` - * - If there are any preambles, add them to the preambles of the reactor. - */ - private void inspectReactorEResource(ReactorDecl reactor) { - // If the reactor is imported, look at the - // target definition of the .lf file in which the reactor is imported from and - // append any cmake-include. - // Check if the reactor definition is imported - if (reactor.eResource() != mainDef.getReactorClass().eResource()) { - // Find the LFResource corresponding to this eResource - LFResource lfResource = null; - for (var resource : resources) { - if (resource.getEResource() == reactor.eResource()) { - lfResource = resource; - break; - } - } - // Copy the user files and cmake-includes to the src-gen path of the main .lf file - if (lfResource != null) { - copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); - } - // Extract the contents of the imported file for the preambles - var contents = toDefinition(reactor).eResource().getContents(); - var model = (Model) contents.get(0); - // Add the preambles from the imported .lf file - toDefinition(reactor).getPreambles().addAll(model.getPreambles()); + } + + @Override + public void checkModalReactorSupport(boolean __) { + // Modal reactors are currently only supported for non federated applications + super.checkModalReactorSupport(true); + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + return String.join( + "\n", + "// Generated forwarding reaction for connections with the same destination", + "// but located in mutually exclusive modes.", + "lf_set(" + dest + ", " + source + "->value);"); + } + + /** Set the scheduler type in the target config as needed. */ + private void pickScheduler() { + // Don't use a scheduler that does not prioritize reactions based on deadlines + // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. + if (!targetConfig.schedulerType.prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (hasDeadlines(reactors)) { + if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { + targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; } + } } + } - /** - * Copy all files or directories listed in the target property `files`, `cmake-include`, - * and `_fed_setup` into the src-gen folder of the main .lf file - * - * @param targetConfig The targetConfig to read the target properties from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - @Override - public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - super.copyUserFiles(targetConfig, fileConfig); - // Make sure the target directory exists. - var targetDir = this.fileConfig.getSrcGenPath(); - try { - Files.createDirectories(targetDir); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - - for (String filename : targetConfig.fileNames) { - var relativeFileName = CUtil.copyFileOrResource( - filename, - fileConfig.srcFile.getParent(), - targetDir); - if (StringExtensions.isNullOrEmpty(relativeFileName)) { - errorReporter.reportError( - "Failed to find file " + filename + " specified in the" + - " files target property." - ); - } else { - targetConfig.filesNamesWithoutPath.add( - relativeFileName - ); - } - } - - for (String filename : targetConfig.cmakeIncludes) { - var relativeCMakeIncludeFileName = - CUtil.copyFileOrResource( - filename, - fileConfig.srcFile.getParent(), - targetDir); - // Check if the file exists - if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { - errorReporter.reportError( - "Failed to find cmake-include file " + filename - ); - } else { - this.targetConfig.cmakeIncludesWithoutPath.add( - relativeCMakeIncludeFileName - ); - } - } - - if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { - try { - FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), - targetDir.resolve(targetConfig.fedSetupPreamble)); - } catch (IOException e) { - errorReporter.reportError("Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); - } + private boolean hasDeadlines(List reactors) { + for (Reactor reactor : reactors) { + for (Reaction reaction : allReactions(reactor)) { + if (reaction.getDeadline() != null) { + return true; } + } } + return false; + } - /** - * Generate code for defining all reactors that belong to the federate, - * including all the child reactors down the hierarchy. Duplicate - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. - */ - private void generateReactorDefinitions() { - var generatedReactorDecls = new LinkedHashSet(); - if (this.main != null) { - generateReactorChildren(this.main, generatedReactorDecls); - } - - if (this.mainDef != null) { - generateReactorClass(this.mainDef.getReactorClass()); - } - - if (mainDef == null) { - // Generate code for each reactor that was not instantiated in main or its children. - for (Reactor r : reactors) { - // Get the declarations for reactors that are instantiated somewhere. - // A declaration is either a reactor definition or an import statement.; - var declarations = this.instantiationGraph.getDeclarations(r); - // If the reactor has no instantiations and there is no main reactor, then - // generate code for it anyway (at a minimum, this means that the compiler is invoked - // so that reaction bodies are checked). - if (declarations.isEmpty()) { - generateReactorClass(r); - } - } - } + private boolean hasWatchdogs() { + for (Reactor reactor : reactors) { + List watchdogs = ASTUtils.allWatchdogs(reactor); + if (watchdogs != null && !watchdogs.isEmpty()) { + return true; + } } - - /** - * Generate code for the children of 'reactor' that belong to 'federate'. - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. - * - * @param reactor Used to extract children from - */ - private void generateReactorChildren( - ReactorInstance reactor, - LinkedHashSet generatedReactorDecls - ) { - for (ReactorInstance r : reactor.children) { - if (r.reactorDeclaration != null && - !generatedReactorDecls.contains(r.reactorDeclaration)) { - generatedReactorDecls.add(r.reactorDeclaration); - generateReactorChildren(r, generatedReactorDecls); - inspectReactorEResource(r.reactorDeclaration); - generateReactorClass(r.reactorDeclaration); - } + return false; + } + + /** + * Look at the 'reactor' eResource. If it is an imported .lf file, incorporate it into the current + * program in the following manner: - Merge its target property with `targetConfig` - If there are + * any preambles, add them to the preambles of the reactor. + */ + private void inspectReactorEResource(ReactorDecl reactor) { + // If the reactor is imported, look at the + // target definition of the .lf file in which the reactor is imported from and + // append any cmake-include. + // Check if the reactor definition is imported + if (reactor.eResource() != mainDef.getReactorClass().eResource()) { + // Find the LFResource corresponding to this eResource + LFResource lfResource = null; + for (var resource : resources) { + if (resource.getEResource() == reactor.eResource()) { + lfResource = resource; + break; } + } + // Copy the user files and cmake-includes to the src-gen path of the main .lf file + if (lfResource != null) { + copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + } + // Extract the contents of the imported file for the preambles + var contents = toDefinition(reactor).eResource().getContents(); + var model = (Model) contents.get(0); + // Add the preambles from the imported .lf file + toDefinition(reactor).getPreambles().addAll(model.getPreambles()); } - - /** - * Choose which platform files to compile with according to the OS. - * If there is no main reactor, then compilation will produce a .o file requiring further linking. - * Also, if useCmake is set to true, we don't need to add platform files. The CMakeLists.txt file - * will detect and use the appropriate platform file based on the platform that cmake is invoked on. - */ - private void pickCompilePlatform() { - var osName = System.getProperty("os.name").toLowerCase(); - // if platform target was set, use given platform instead - if (targetConfig.platformOptions.platform != Platform.AUTO) { - osName = targetConfig.platformOptions.platform.toString(); - } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { - errorReporter.reportError("Platform " + osName + " is not supported"); - } + } + + /** + * Copy all files or directories listed in the target property `files`, `cmake-include`, and + * `_fed_setup` into the src-gen folder of the main .lf file + * + * @param targetConfig The targetConfig to read the target properties from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + @Override + public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + super.copyUserFiles(targetConfig, fileConfig); + // Make sure the target directory exists. + var targetDir = this.fileConfig.getSrcGenPath(); + try { + Files.createDirectories(targetDir); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); } - - /** - * Copy target-specific header file to the src-gen directory. - */ - protected void copyTargetFiles() throws IOException { - - String srcPrefix = targetConfig.platformOptions.platform == Platform.ARDUINO ? "src/" : ""; - - FileUtil.copyDirectoryFromClassPath( - "/lib/c/reactor-c/include", - fileConfig.getSrcGenPath().resolve(srcPrefix + "include"), - false - ); - FileUtil.copyDirectoryFromClassPath( - "/lib/c/reactor-c/lib", - fileConfig.getSrcGenPath().resolve(srcPrefix + "lib"), - false - ); + for (String filename : targetConfig.fileNames) { + var relativeFileName = + CUtil.copyFileOrResource(filename, fileConfig.srcFile.getParent(), targetDir); + if (StringExtensions.isNullOrEmpty(relativeFileName)) { + errorReporter.reportError( + "Failed to find file " + filename + " specified in the" + " files target property."); + } else { + targetConfig.filesNamesWithoutPath.add(relativeFileName); + } } - //////////////////////////////////////////// - //// Code generators. - /** - * Generate a reactor class definition for the specified federate. - * A class definition has four parts: - * - * * Preamble code, if any, specified in the Lingua Franca file. - * * A "self" struct type definition (see the class documentation above). - * * A function for each reaction. - * * A constructor for creating an instance. - * for deleting an instance. - * - * If the reactor is the main reactor, then - * the generated code may be customized. Specifically, - * if the main reactor has reactions, these reactions - * will not be generated if they are triggered by or send - * data to contained reactors that are not in the federate. - * @param reactor The parsed reactor data structure. - */ - private void generateReactorClass(ReactorDecl reactor) { - // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. - - Reactor defn = ASTUtils.toDefinition(reactor); - - if (reactor instanceof Reactor) { - code.pr("// =============== START reactor class " + reactor.getName()); - } else { - code.pr("// =============== START reactor class " + defn.getName() + " as " + reactor.getName()); - } - - // Preamble code contains state declarations with static initializers. - generateUserPreamblesForReactor(defn); - - // Some of the following methods create lines of code that need to - // go into the constructor. Collect those lines of code here: - var constructorCode = new CodeBuilder(); - generateAuxiliaryStructs(reactor); - generateSelfStruct(reactor, constructorCode); - generateMethods(reactor); - - generateWatchdogs(reactor); - generateReactions(reactor); - generateConstructor(reactor, constructorCode); + for (String filename : targetConfig.cmakeIncludes) { + var relativeCMakeIncludeFileName = + CUtil.copyFileOrResource(filename, fileConfig.srcFile.getParent(), targetDir); + // Check if the file exists + if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { + errorReporter.reportError("Failed to find cmake-include file " + filename); + } else { + this.targetConfig.cmakeIncludesWithoutPath.add(relativeCMakeIncludeFileName); + } + } - code.pr("// =============== END reactor class " + reactor.getName()); - code.pr(""); + if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { + try { + FileUtil.copyFile( + fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), + targetDir.resolve(targetConfig.fedSetupPreamble)); + } catch (IOException e) { + errorReporter.reportError( + "Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); + } + } + } + + /** + * Generate code for defining all reactors that belong to the federate, including all the child + * reactors down the hierarchy. Duplicate Duplicates are avoided. + * + *

Imported reactors' original .lf file is incorporated in the following manner: - If there are + * any cmake-include files, add them to the current list of cmake-include files. - If there are + * any preambles, add them to the preambles of the reactor. + */ + private void generateReactorDefinitions() { + var generatedReactorDecls = new LinkedHashSet(); + if (this.main != null) { + generateReactorChildren(this.main, generatedReactorDecls); } - /** - * Generate methods for {@code reactor}. - */ - protected void generateMethods(ReactorDecl reactor) { - CMethodGenerator.generateMethods(reactor, code, types); + if (this.mainDef != null) { + generateReactorClass(this.mainDef.getReactorClass()); } - /** - * Generates preambles defined by user for a given reactor - * @param reactor The given reactor - */ - protected void generateUserPreamblesForReactor(Reactor reactor) { - for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { - code.pr("// *********** From the preamble, verbatim:"); - code.prSourceLineNumber(p.getCode()); - code.pr(toText(p.getCode())); - code.pr("\n// *********** End of preamble."); + if (mainDef == null) { + // Generate code for each reactor that was not instantiated in main or its children. + for (Reactor r : reactors) { + // Get the declarations for reactors that are instantiated somewhere. + // A declaration is either a reactor definition or an import statement.; + var declarations = this.instantiationGraph.getDeclarations(r); + // If the reactor has no instantiations and there is no main reactor, then + // generate code for it anyway (at a minimum, this means that the compiler is invoked + // so that reaction bodies are checked). + if (declarations.isEmpty()) { + generateReactorClass(r); } + } } - - /** - * Generate a constructor for the specified reactor in the specified federate. - * @param reactor The parsed reactor data structure. - * @param constructorCode Lines of code previously generated that need to - * go into the constructor. - */ - protected void generateConstructor( - ReactorDecl reactor, CodeBuilder constructorCode - ) { - code.pr(CConstructorGenerator.generateConstructor( - reactor, - constructorCode.toString() - )); + } + + /** + * Generate code for the children of 'reactor' that belong to 'federate'. Duplicates are avoided. + * + *

Imported reactors' original .lf file is incorporated in the following manner: - If there are + * any cmake-include files, add them to the current list of cmake-include files. - If there are + * any preambles, add them to the preambles of the reactor. + * + * @param reactor Used to extract children from + */ + private void generateReactorChildren( + ReactorInstance reactor, LinkedHashSet generatedReactorDecls) { + for (ReactorInstance r : reactor.children) { + if (r.reactorDeclaration != null && !generatedReactorDecls.contains(r.reactorDeclaration)) { + generatedReactorDecls.add(r.reactorDeclaration); + generateReactorChildren(r, generatedReactorDecls); + inspectReactorEResource(r.reactorDeclaration); + generateReactorClass(r.reactorDeclaration); + } + } + } + + /** + * Choose which platform files to compile with according to the OS. If there is no main reactor, + * then compilation will produce a .o file requiring further linking. Also, if useCmake is set to + * true, we don't need to add platform files. The CMakeLists.txt file will detect and use the + * appropriate platform file based on the platform that cmake is invoked on. + */ + private void pickCompilePlatform() { + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { + errorReporter.reportError("Platform " + osName + " is not supported"); + } + } + + /** Copy target-specific header file to the src-gen directory. */ + protected void copyTargetFiles() throws IOException { + + String srcPrefix = targetConfig.platformOptions.platform == Platform.ARDUINO ? "src/" : ""; + + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/include", + fileConfig.getSrcGenPath().resolve(srcPrefix + "include"), + false); + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/lib", fileConfig.getSrcGenPath().resolve(srcPrefix + "lib"), false); + } + + //////////////////////////////////////////// + //// Code generators. + /** + * Generate a reactor class definition for the specified federate. A class definition has four + * parts: + * + *

* Preamble code, if any, specified in the Lingua Franca file. * A "self" struct type + * definition (see the class documentation above). * A function for each reaction. * A constructor + * for creating an instance. for deleting an instance. + * + *

If the reactor is the main reactor, then the generated code may be customized. Specifically, + * if the main reactor has reactions, these reactions will not be generated if they are triggered + * by or send data to contained reactors that are not in the federate. + * + * @param reactor The parsed reactor data structure. + */ + private void generateReactorClass(ReactorDecl reactor) { + // FIXME: Currently we're not reusing definitions for declarations that point to the same + // definition. + + Reactor defn = ASTUtils.toDefinition(reactor); + + if (reactor instanceof Reactor) { + code.pr("// =============== START reactor class " + reactor.getName()); + } else { + code.pr( + "// =============== START reactor class " + defn.getName() + " as " + reactor.getName()); } - /** - * Generate the struct type definitions for inputs, outputs, and - * actions of the specified reactor. - * @param decl The parsed reactor data structure. - */ - protected void generateAuxiliaryStructs(ReactorDecl decl) { - var reactor = ASTUtils.toDefinition(decl); - // In the case where there are incoming - // p2p logical connections in decentralized - // federated execution, there will be an - // intended_tag field added to accommodate - // the case where a reaction triggered by a - // port or action is late due to network - // latency, etc.. - var federatedExtension = new CodeBuilder(); - federatedExtension.pr(""" + // Preamble code contains state declarations with static initializers. + generateUserPreamblesForReactor(defn); + + // Some of the following methods create lines of code that need to + // go into the constructor. Collect those lines of code here: + var constructorCode = new CodeBuilder(); + generateAuxiliaryStructs(reactor); + generateSelfStruct(reactor, constructorCode); + generateMethods(reactor); + + generateWatchdogs(reactor); + generateReactions(reactor); + generateConstructor(reactor, constructorCode); + + code.pr("// =============== END reactor class " + reactor.getName()); + code.pr(""); + } + + /** Generate methods for {@code reactor}. */ + protected void generateMethods(ReactorDecl reactor) { + CMethodGenerator.generateMethods(reactor, code, types); + } + + /** + * Generates preambles defined by user for a given reactor + * + * @param reactor The given reactor + */ + protected void generateUserPreamblesForReactor(Reactor reactor) { + for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { + code.pr("// *********** From the preamble, verbatim:"); + code.prSourceLineNumber(p.getCode()); + code.pr(toText(p.getCode())); + code.pr("\n// *********** End of preamble."); + } + } + + /** + * Generate a constructor for the specified reactor in the specified federate. + * + * @param reactor The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to go into the constructor. + */ + protected void generateConstructor(ReactorDecl reactor, CodeBuilder constructorCode) { + code.pr(CConstructorGenerator.generateConstructor(reactor, constructorCode.toString())); + } + + /** + * Generate the struct type definitions for inputs, outputs, and actions of the specified reactor. + * + * @param decl The parsed reactor data structure. + */ + protected void generateAuxiliaryStructs(ReactorDecl decl) { + var reactor = ASTUtils.toDefinition(decl); + // In the case where there are incoming + // p2p logical connections in decentralized + // federated execution, there will be an + // intended_tag field added to accommodate + // the case where a reaction triggered by a + // port or action is late due to network + // latency, etc.. + var federatedExtension = new CodeBuilder(); + federatedExtension.pr( + """ #ifdef FEDERATED #ifdef FEDERATED_DECENTRALIZED %s intended_tag; #endif %s physical_time_of_arrival; #endif - """.formatted(types.getTargetTagType(), types.getTargetTimeType()) - ); - // First, handle inputs. - for (Input input : allInputs(reactor)) { - code.pr(CPortGenerator.generateAuxiliaryStruct( - decl, - input, - getTarget(), - errorReporter, - types, - federatedExtension - )); - } - // Next, handle outputs. - for (Output output : allOutputs(reactor)) { - code.pr(CPortGenerator.generateAuxiliaryStruct( - decl, - output, - getTarget(), - errorReporter, - types, - federatedExtension - )); - } - // Finally, handle actions. - // The very first item on this struct needs to be - // a trigger_t* because the struct will be cast to (trigger_t*) - // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(reactor)) { - code.pr(CActionGenerator.generateAuxiliaryStruct( - decl, - action, - getTarget(), - types, - federatedExtension - )); - } + """ + .formatted(types.getTargetTagType(), types.getTargetTimeType())); + // First, handle inputs. + for (Input input : allInputs(reactor)) { + code.pr( + CPortGenerator.generateAuxiliaryStruct( + decl, input, getTarget(), errorReporter, types, federatedExtension)); } - - /** - * Generate the self struct type definition for the specified reactor - * in the specified federate. - * @param decl The parsed reactor data structure. - * @param constructorCode Place to put lines of code that need to - * go into the constructor. - */ - private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { - var reactor = toDefinition(decl); - var selfType = CUtil.selfType(decl); - - // Construct the typedef for the "self" struct. - // Create a type name for the self struct. - var body = new CodeBuilder(); - - // Extensions can add functionality to the CGenerator - generateSelfStructExtension(body, decl, constructorCode); - - // Next handle parameters. - body.pr(CParameterGenerator.generateDeclarations(reactor, types)); - - // Next handle states. - body.pr(CStateGenerator.generateDeclarations(reactor, types)); - - // Next handle actions. - CActionGenerator.generateDeclarations(reactor, decl, body, constructorCode); - - // Next handle inputs and outputs. - CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); - - // If there are contained reactors that either receive inputs - // from reactions of this reactor or produce outputs that trigger - // reactions of this reactor, then we need to create a struct - // inside the self struct for each contained reactor. That - // struct has a place to hold the data produced by this reactor's - // reactions and a place to put pointers to data produced by - // the contained reactors. - generateInteractingContainedReactors(reactor, body, constructorCode); - - // Next, generate the fields needed for each reaction. - CReactionGenerator.generateReactionAndTriggerStructs( - body, - decl, - constructorCode, - types - ); - - // Generate the fields needed for each watchdog. - CWatchdogGenerator.generateWatchdogStruct( - body, - decl, - constructorCode - ); - - // Next, generate fields for modes - CModesGenerator.generateDeclarations(reactor, body, constructorCode); - - // constructorCode.pr(reactor, String.join("\n", - // "#ifdef LF_THREADED", - // " self->base->watchdog_mutex = NULL;", - // "#endif")); - - // The first field has to always be a pointer to the list of - // of allocated memory that must be freed when the reactor is freed. - // This means that the struct can be safely cast to self_base_t. - code.pr("typedef struct {"); - code.indent(); - code.pr("struct self_base_t base;"); - code.pr(body.toString()); - code.unindent(); - code.pr("} " + selfType + ";"); + // Next, handle outputs. + for (Output output : allOutputs(reactor)) { + code.pr( + CPortGenerator.generateAuxiliaryStruct( + decl, output, getTarget(), errorReporter, types, federatedExtension)); } - - /** - * Generate structs and associated code for contained reactors that - * send or receive data to or from the container's reactions. - * - * If there are contained reactors that either receive inputs - * from reactions of this reactor or produce outputs that trigger - * reactions of this reactor, then we need to create a struct - * inside the self struct of the container for each contained reactor. - * That struct has a place to hold the data produced by the container reactor's - * reactions and a place to put pointers to data produced by - * the contained reactors. - * - * @param reactor The reactor. - * @param body The place to put the struct definition for the contained reactors. - * @param constructorCode The place to put matching code that goes in the container's constructor. - */ - private void generateInteractingContainedReactors( - Reactor reactor, - CodeBuilder body, - CodeBuilder constructorCode - ) { - // The contents of the struct will be collected first so that - // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(reactor); - // Next generate the relevant code. - for (Instantiation containedReactor : contained.containedReactors()) { - // First define an _width variable in case it is a bank. - var array = ""; - var width = -2; - // If the instantiation is a bank, find the maximum bank width - // to define an array. - if (containedReactor.getWidthSpec() != null) { - width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); - array = "[" + width + "]"; - } - // NOTE: The following needs to be done for each instance - // so that the width can be parameter, not in the constructor. - // Here, we conservatively use a width that is the largest of all isntances. - constructorCode.pr(String.join("\n", - "// Set the _width variable for all cases. This will be -2", - "// if the reactor is not a bank of reactors.", - "self->_lf_"+containedReactor.getName()+"_width = "+width+";" - )); - - // Generate one struct for each contained reactor that interacts. - body.pr("struct {"); - body.indent(); - for (Port port : contained.portsOfInstance(containedReactor)) { - if (port instanceof Input) { - // If the variable is a multiport, then the place to store the data has - // to be malloc'd at initialization. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedReactor.getReactorClass())+" "+port.getName()+";"); - } else { - // Is a multiport. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedReactor.getReactorClass())+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - } else { - // Must be an output port. - // Outputs of contained reactors are pointers to the source of data on the - // self struct of the container. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedReactor.getReactorClass())+"* "+port.getName()+";"); - } else { - // Is a multiport. - // Here, we will use an array of pointers. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedReactor.getReactorClass())+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - body.pr(port, "trigger_t "+port.getName()+"_trigger;"); - var reactorIndex = ""; - if (containedReactor.getWidthSpec() != null) { - reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); - constructorCode.indent(); - } - var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); - - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederatedDecentralized( - portOnSelf+"_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};" - ) - ); - - var triggered = contained.reactionsTriggered(containedReactor, port); - //noinspection StatementWithEmptyBody - if (triggered.size() > 0) { - body.pr(port, "reaction_t* "+port.getName()+"_reactions["+triggered.size()+"];"); - var triggeredCount = 0; - for (Integer index : triggered) { - constructorCode.pr(port, portOnSelf+"_reactions["+triggeredCount+++"] = &self->_lf__reaction_"+index+";"); - } - constructorCode.pr(port, portOnSelf+"_trigger.reactions = "+portOnSelf+"_reactions;"); - } else { - // Since the self struct is created using calloc, there is no need to set - // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL - } - // Since the self struct is created using calloc, there is no need to set falsy fields. - constructorCode.pr(port, String.join("\n", - portOnSelf+"_trigger.last = NULL;", - portOnSelf+"_trigger.number_of_reactions = "+triggered.size()+";" - )); - - - // Set the physical_time_of_arrival - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederated( - portOnSelf+"_trigger.physical_time_of_arrival = NEVER;" - ) - ); - - if (containedReactor.getWidthSpec() != null) { - constructorCode.unindent(); - constructorCode.pr("}"); - } - } + // Finally, handle actions. + // The very first item on this struct needs to be + // a trigger_t* because the struct will be cast to (trigger_t*) + // by the lf_schedule() functions to get to the trigger. + for (Action action : allActions(reactor)) { + code.pr( + CActionGenerator.generateAuxiliaryStruct( + decl, action, getTarget(), types, federatedExtension)); + } + } + + /** + * Generate the self struct type definition for the specified reactor in the specified federate. + * + * @param decl The parsed reactor data structure. + * @param constructorCode Place to put lines of code that need to go into the constructor. + */ + private void generateSelfStruct(ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = toDefinition(decl); + var selfType = CUtil.selfType(decl); + + // Construct the typedef for the "self" struct. + // Create a type name for the self struct. + var body = new CodeBuilder(); + + // Extensions can add functionality to the CGenerator + generateSelfStructExtension(body, decl, constructorCode); + + // Next handle parameters. + body.pr(CParameterGenerator.generateDeclarations(reactor, types)); + + // Next handle states. + body.pr(CStateGenerator.generateDeclarations(reactor, types)); + + // Next handle actions. + CActionGenerator.generateDeclarations(reactor, decl, body, constructorCode); + + // Next handle inputs and outputs. + CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); + + // If there are contained reactors that either receive inputs + // from reactions of this reactor or produce outputs that trigger + // reactions of this reactor, then we need to create a struct + // inside the self struct for each contained reactor. That + // struct has a place to hold the data produced by this reactor's + // reactions and a place to put pointers to data produced by + // the contained reactors. + generateInteractingContainedReactors(reactor, body, constructorCode); + + // Next, generate the fields needed for each reaction. + CReactionGenerator.generateReactionAndTriggerStructs(body, decl, constructorCode, types); + + // Generate the fields needed for each watchdog. + CWatchdogGenerator.generateWatchdogStruct(body, decl, constructorCode); + + // Next, generate fields for modes + CModesGenerator.generateDeclarations(reactor, body, constructorCode); + + // constructorCode.pr(reactor, String.join("\n", + // "#ifdef LF_THREADED", + // " self->base->watchdog_mutex = NULL;", + // "#endif")); + + // The first field has to always be a pointer to the list of + // of allocated memory that must be freed when the reactor is freed. + // This means that the struct can be safely cast to self_base_t. + code.pr("typedef struct {"); + code.indent(); + code.pr("struct self_base_t base;"); + code.pr(body.toString()); + code.unindent(); + code.pr("} " + selfType + ";"); + } + + /** + * Generate structs and associated code for contained reactors that send or receive data to or + * from the container's reactions. + * + *

If there are contained reactors that either receive inputs from reactions of this reactor or + * produce outputs that trigger reactions of this reactor, then we need to create a struct inside + * the self struct of the container for each contained reactor. That struct has a place to hold + * the data produced by the container reactor's reactions and a place to put pointers to data + * produced by the contained reactors. + * + * @param reactor The reactor. + * @param body The place to put the struct definition for the contained reactors. + * @param constructorCode The place to put matching code that goes in the container's constructor. + */ + private void generateInteractingContainedReactors( + Reactor reactor, CodeBuilder body, CodeBuilder constructorCode) { + // The contents of the struct will be collected first so that + // we avoid duplicate entries and then the struct will be constructed. + var contained = new InteractingContainedReactors(reactor); + // Next generate the relevant code. + for (Instantiation containedReactor : contained.containedReactors()) { + // First define an _width variable in case it is a bank. + var array = ""; + var width = -2; + // If the instantiation is a bank, find the maximum bank width + // to define an array. + if (containedReactor.getWidthSpec() != null) { + width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); + array = "[" + width + "]"; + } + // NOTE: The following needs to be done for each instance + // so that the width can be parameter, not in the constructor. + // Here, we conservatively use a width that is the largest of all isntances. + constructorCode.pr( + String.join( + "\n", + "// Set the _width variable for all cases. This will be -2", + "// if the reactor is not a bank of reactors.", + "self->_lf_" + containedReactor.getName() + "_width = " + width + ";")); + + // Generate one struct for each contained reactor that interacts. + body.pr("struct {"); + body.indent(); + for (Port port : contained.portsOfInstance(containedReactor)) { + if (port instanceof Input) { + // If the variable is a multiport, then the place to store the data has + // to be malloc'd at initialization. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, + variableStructType(port, containedReactor.getReactorClass()) + + " " + + port.getName() + + ";"); + } else { + // Is a multiport. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedReactor.getReactorClass()) + + "** " + + port.getName() + + ";", + "int " + port.getName() + "_width;")); + } + } else { + // Must be an output port. + // Outputs of contained reactors are pointers to the source of data on the + // self struct of the container. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, + variableStructType(port, containedReactor.getReactorClass()) + + "* " + + port.getName() + + ";"); + } else { + // Is a multiport. + // Here, we will use an array of pointers. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedReactor.getReactorClass()) + + "** " + + port.getName() + + ";", + "int " + port.getName() + "_width;")); + } + body.pr(port, "trigger_t " + port.getName() + "_trigger;"); + var reactorIndex = ""; + if (containedReactor.getWidthSpec() != null) { + reactorIndex = "[reactor_index]"; + constructorCode.pr( + "for (int reactor_index = 0; reactor_index < self->_lf_" + + containedReactor.getName() + + "_width; reactor_index++) {"); + constructorCode.indent(); + } + var portOnSelf = + "self->_lf_" + containedReactor.getName() + reactorIndex + "." + port.getName(); + + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederatedDecentralized( + portOnSelf + + "_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + + var triggered = contained.reactionsTriggered(containedReactor, port); + //noinspection StatementWithEmptyBody + if (triggered.size() > 0) { + body.pr( + port, "reaction_t* " + port.getName() + "_reactions[" + triggered.size() + "];"); + var triggeredCount = 0; + for (Integer index : triggered) { + constructorCode.pr( + port, + portOnSelf + + "_reactions[" + + triggeredCount++ + + "] = &self->_lf__reaction_" + + index + + ";"); } - body.unindent(); - body.pr(String.join("\n", - "} _lf_"+containedReactor.getName()+array+";", - "int _lf_"+containedReactor.getName()+"_width;" - )); + constructorCode.pr( + port, portOnSelf + "_trigger.reactions = " + portOnSelf + "_reactions;"); + } else { + // Since the self struct is created using calloc, there is no need to set + // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL + } + // Since the self struct is created using calloc, there is no need to set falsy fields. + constructorCode.pr( + port, + String.join( + "\n", + portOnSelf + "_trigger.last = NULL;", + portOnSelf + "_trigger.number_of_reactions = " + triggered.size() + ";")); + + // Set the physical_time_of_arrival + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederated( + portOnSelf + "_trigger.physical_time_of_arrival = NEVER;")); + + if (containedReactor.getWidthSpec() != null) { + constructorCode.unindent(); + constructorCode.pr("}"); + } } + } + body.unindent(); + body.pr( + String.join( + "\n", + "} _lf_" + containedReactor.getName() + array + ";", + "int _lf_" + containedReactor.getName() + "_width;")); } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param body The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - protected void generateSelfStructExtension( - CodeBuilder body, - ReactorDecl decl, - CodeBuilder constructorCode - ) { - // Do nothing + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param body The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + protected void generateSelfStructExtension( + CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { + // Do nothing + } + + /** + * Generate reaction functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param decl The reactor. + */ + public void generateReactions(ReactorDecl decl) { + var reactionIndex = 0; + var reactor = ASTUtils.toDefinition(decl); + for (Reaction reaction : allReactions(reactor)) { + generateReaction(reaction, decl, reactionIndex); + // Increment reaction index even if the reaction is not in the federate + // so that across federates, the reaction indices are consistent. + reactionIndex++; } - - /** Generate reaction functions definition for a reactor. - * These functions have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param decl The reactor. - */ - public void generateReactions(ReactorDecl decl) { - var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(decl); - for (Reaction reaction : allReactions(reactor)) { - generateReaction(reaction, decl, reactionIndex); - // Increment reaction index even if the reaction is not in the federate - // so that across federates, the reaction indices are consistent. - reactionIndex++; - } - } - - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param decl The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactionIndex) { - - code.pr(CReactionGenerator.generateReaction( + } + + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param decl The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactionIndex) { + + code.pr( + CReactionGenerator.generateReaction( reaction, decl, reactionIndex, @@ -1451,793 +1365,834 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio errorReporter, types, targetConfig, - getTarget().requiresTypes - )); + getTarget().requiresTypes)); + } + + /** + * Generate watchdog functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param decl The reactor. federated or not the main reactor and reactions should be + * unconditionally generated. + */ + public void generateWatchdogs(ReactorDecl decl) { + // WATCHDOG QUESTION: A similar question is asked somewhere else for a + // different function - Do we need to check if this federate contains the + // watchdog? This is done in the code generation for reactions. + var reactor = ASTUtils.toDefinition(decl); + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + generateWatchdog(watchdog, decl); } - - /** Generate watchdog functions definition for a reactor. - * These functions have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param decl The reactor. - * federated or not the main reactor and reactions should be - * unconditionally generated. - */ - public void generateWatchdogs(ReactorDecl decl) { - // WATCHDOG QUESTION: A similar question is asked somewhere else for a - // different function - Do we need to check if this federate contains the - // watchdog? This is done in the code generation for reactions. - var reactor = ASTUtils.toDefinition(decl); - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - generateWatchdog(watchdog, decl); + } + + /** + * Generate a watchdog function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param watchdog The watchdog. + * @param decl The reactor. + */ + protected void generateWatchdog(Watchdog watchdog, ReactorDecl decl) { + code.pr(CWatchdogGenerator.generateWatchdog(watchdog, decl)); + } + + /** + * Record startup, shutdown, and reset reactions. + * + * @param instance A reactor instance. + */ + private void recordBuiltinTriggers(ReactorInstance instance) { + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : instance.reactions) { + var reactor = reaction.getParent(); + var temp = new CodeBuilder(); + var foundOne = false; + + var reactionRef = CUtil.reactionRef(reaction); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.isStartup()) { + temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &" + reactionRef + ";"); + startupReactionCount += reactor.getTotalWidth(); + foundOne = true; + } else if (trigger.isShutdown()) { + temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &" + reactionRef + ";"); + foundOne = true; + shutdownReactionCount += reactor.getTotalWidth(); + + if (targetConfig.tracing != null) { + var description = CUtil.getShortenedName(reactor); + var reactorRef = CUtil.reactorRef(reactor); + temp.pr( + String.join( + "\n", + "_lf_register_trace_event(" + + reactorRef + + ", &(" + + reactorRef + + "->_lf__shutdown),", + "trace_trigger, " + addDoubleQuotes(description + ".shutdown") + ");")); + } + } else if (trigger.isReset()) { + temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &" + reactionRef + ";"); + resetReactionCount += reactor.getTotalWidth(); + foundOne = true; } + } + if (foundOne) initializeTriggerObjects.pr(temp.toString()); } - - /** Generate a watchdog function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param watchdog The watchdog. - * @param decl The reactor. - */ - protected void generateWatchdog(Watchdog watchdog, ReactorDecl decl) { - code.pr(CWatchdogGenerator.generateWatchdog( - watchdog, - decl - )); + } + + private void recordWatchdogs(ReactorInstance instance) { + var foundOne = false; + var temp = new CodeBuilder(); + var reactorRef = CUtil.reactorRef(instance); + // temp.pr("#ifdef LF_THREADED"); + for (WatchdogInstance watchdog : instance.watchdogs) { + temp.pr( + " _lf_watchdogs[_lf_watchdog_number_count++] = &" + + reactorRef + + "->_lf_watchdog_" + + watchdog.getName() + + ";"); + temp.pr( + " " + + reactorRef + + "->_lf_watchdog_" + + watchdog.getName() + + ".min_expiration = " + + CTypes.getInstance().getTargetTimeExpr(watchdog.getTimeout()) + + ";"); + temp.pr(" " + reactorRef + "->_lf_watchdog_" + watchdog.getName() + ".thread_id;"); + watchdogCount += 1; + foundOne = true; } - - /** - * Record startup, shutdown, and reset reactions. - * @param instance A reactor instance. - */ - private void recordBuiltinTriggers(ReactorInstance instance) { - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : instance.reactions) { - var reactor = reaction.getParent(); - var temp = new CodeBuilder(); - var foundOne = false; - - var reactionRef = CUtil.reactionRef(reaction); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.isStartup()) { - temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &"+reactionRef+";"); - startupReactionCount += reactor.getTotalWidth(); - foundOne = true; - } else if (trigger.isShutdown()) { - temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &"+reactionRef+";"); - foundOne = true; - shutdownReactionCount += reactor.getTotalWidth(); - - if (targetConfig.tracing != null) { - var description = CUtil.getShortenedName(reactor); - var reactorRef = CUtil.reactorRef(reactor); - temp.pr(String.join("\n", - "_lf_register_trace_event("+reactorRef+", &("+reactorRef+"->_lf__shutdown),", - "trace_trigger, "+addDoubleQuotes(description+".shutdown")+");" - )); - } - } else if (trigger.isReset()) { - temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &"+reactionRef+";"); - resetReactionCount += reactor.getTotalWidth(); - foundOne = true; - } - } - if (foundOne) initializeTriggerObjects.pr(temp.toString()); - } + // temp.pr("#endif"); + if (foundOne) { + initializeTriggerObjects.pr(temp.toString()); } - - private void recordWatchdogs(ReactorInstance instance) { - var foundOne = false; - var temp = new CodeBuilder(); - var reactorRef = CUtil.reactorRef(instance); - // temp.pr("#ifdef LF_THREADED"); - for (WatchdogInstance watchdog : instance.watchdogs) { - temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+CTypes.getInstance().getTargetTimeExpr(watchdog.getTimeout())+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); - watchdogCount += 1; - foundOne = true; - } - // temp.pr("#endif"); - if (foundOne) { - initializeTriggerObjects.pr(temp.toString()); + } + + /** + * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts + * and mark outputs absent between time steps. This function puts the code into startTimeStep. + */ + private void generateStartTimeStep(ReactorInstance instance) { + // Avoid generating dead code if nothing is relevant. + var foundOne = false; + var temp = new CodeBuilder(); + var containerSelfStructName = CUtil.reactorRef(instance); + + // Handle inputs that get sent data from a reaction rather than from + // another contained reactor and reactions that are triggered by an + // output of a contained reactor. + // Note that there may be more than one reaction reacting to the same + // port so we have to avoid listing the port more than once. + var portsSeen = new LinkedHashSet(); + for (ReactionInstance reaction : instance.reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + portsSeen.add(port); + // This reaction is sending to an input. Must be + // the input of a contained reactor in the federate. + // NOTE: If instance == main and the federate is within a bank, + // this assumes that the reaction writes only to the bank member in the federate. + foundOne = true; + + temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); + + if (!Objects.equal(port.getParent(), instance)) { + // The port belongs to contained reactor, so we also have + // iterate over the instance bank members. + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(instance); + temp.startScopedBankChannelIteration(port, null); + } else { + temp.startScopedBankChannelIteration(port, "count"); + } + var portRef = CUtil.portRefNested(port); + var con = (port.isMultiport()) ? "->" : "."; + + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "is_present;"); + // Intended_tag is only applicable to ports in federated execution. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "intended_tag;")); + + startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); + + if (!Objects.equal(port.getParent(), instance)) { + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + temp.endScopedBankChannelIteration(port, null); + } else { + temp.endScopedBankChannelIteration(port, "count"); + } } + } } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + + for (ActionInstance action : instance.actions) { + foundOne = true; + temp.startScopedBlock(instance); + + temp.pr( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of is_present fields.", + "_lf_is_present_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".is_present;")); + + // Intended_tag is only applicable to actions in federated execution with decentralized + // coordination. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".intended_tag;"))); + + startTimeStepIsPresentCount += action.getParent().getTotalWidth(); + temp.endScopedBlock(); + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + // Next, set up the table to mark each output of each contained reactor absent. + for (ReactorInstance child : instance.children) { + if (child.outputs.size() > 0) { - /** - * Generate code to set up the tables used in _lf_start_time_step to decrement reference - * counts and mark outputs absent between time steps. This function puts the code - * into startTimeStep. - */ - private void generateStartTimeStep(ReactorInstance instance) { - // Avoid generating dead code if nothing is relevant. - var foundOne = false; - var temp = new CodeBuilder(); - var containerSelfStructName = CUtil.reactorRef(instance); - - // Handle inputs that get sent data from a reaction rather than from - // another contained reactor and reactions that are triggered by an - // output of a contained reactor. - // Note that there may be more than one reaction reacting to the same - // port so we have to avoid listing the port more than once. - var portsSeen = new LinkedHashSet(); - for (ReactionInstance reaction : instance.reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - portsSeen.add(port); - // This reaction is sending to an input. Must be - // the input of a contained reactor in the federate. - // NOTE: If instance == main and the federate is within a bank, - // this assumes that the reaction writes only to the bank member in the federate. - foundOne = true; - - temp.pr("// Add port "+port.getFullName()+" to array of is_present fields."); - - if (!Objects.equal(port.getParent(), instance)) { - // The port belongs to contained reactor, so we also have - // iterate over the instance bank members. - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); - temp.startScopedBankChannelIteration(port, null); - } else { - temp.startScopedBankChannelIteration(port, "count"); - } - var portRef = CUtil.portRefNested(port); - var con = (port.isMultiport()) ? "->" : "."; - - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"is_present;"); - // Intended_tag is only applicable to ports in federated execution. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"intended_tag;" - ) - ); - - startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); - - if (!Objects.equal(port.getParent(), instance)) { - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); - temp.endScopedBankChannelIteration(port, null); - } else { - temp.endScopedBankChannelIteration(port, "count"); - } - } - } - } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(child); - for (ActionInstance action : instance.actions) { + var channelCount = 0; + for (PortInstance output : child.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { foundOne = true; - temp.startScopedBlock(instance); - - temp.pr(String.join("\n", - "// Add action "+action.getFullName()+" to array of is_present fields.", - "_lf_is_present_fields["+startTimeStepIsPresentCount+"] ", - " = &"+containerSelfStructName+"->_lf_"+action.getName()+".is_present;" - )); - - // Intended_tag is only applicable to actions in federated execution with decentralized coordination. + temp.pr("// Add port " + output.getFullName() + " to array of is_present fields."); + temp.startChannelIteration(output); + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".is_present;"); + + // Intended_tag is only applicable to ports in federated execution with decentralized + // coordination. temp.pr( CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add action " + action.getFullName() - + " to array of intended_tag fields.", - "_lf_intended_tag_fields[" - + startTimeStepIsPresentCount + "] ", - " = &" + containerSelfStructName - + "->_lf_" + action.getName() - + ".intended_tag;" - ))); - - startTimeStepIsPresentCount += action.getParent().getTotalWidth(); - temp.endScopedBlock(); + String.join( + "\n", + "// Add port " + output.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".intended_tag;"))); + + temp.pr("count++;"); + channelCount += output.getWidth(); + temp.endChannelIteration(output); + } } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; - - // Next, set up the table to mark each output of each contained reactor absent. - for (ReactorInstance child : instance.children) { - if (child.outputs.size() > 0) { - - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(child); - - var channelCount = 0; - for (PortInstance output : child.outputs) { - if (!output.getDependsOnReactions().isEmpty()){ - foundOne = true; - temp.pr("// Add port "+output.getFullName()+" to array of is_present fields."); - temp.startChannelIteration(output); - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".is_present;"); - - // Intended_tag is only applicable to ports in federated execution with decentralized coordination. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add port "+output.getFullName()+" to array of intended_tag fields.", - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".intended_tag;" - ))); - - temp.pr("count++;"); - channelCount += output.getWidth(); - temp.endChannelIteration(output); - } - } - startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); - temp.endScopedBlock(); - temp.endScopedBlock(); - } - } - if (foundOne) startTimeStep.pr(temp.toString()); + startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); + temp.endScopedBlock(); + temp.endScopedBlock(); + } } - - /** - * For each timer in the given reactor, generate initialization code for the offset - * and period fields. - * - * This method will also populate the global _lf_timer_triggers array, which is - * used to start all timers at the start of execution. - * - * @param instance A reactor instance. - */ - private void generateTimerInitializations(ReactorInstance instance) { - for (TimerInstance timer : instance.timers) { - if (!timer.isStartup()) { - initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); - timerCount += timer.getParent().getTotalWidth(); - } - } + if (foundOne) startTimeStep.pr(temp.toString()); + } + + /** + * For each timer in the given reactor, generate initialization code for the offset and period + * fields. + * + *

This method will also populate the global _lf_timer_triggers array, which is used to start + * all timers at the start of execution. + * + * @param instance A reactor instance. + */ + private void generateTimerInitializations(ReactorInstance instance) { + for (TimerInstance timer : instance.timers) { + if (!timer.isStartup()) { + initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); + timerCount += timer.getParent().getTotalWidth(); + } } - - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * @param filename Name of the file to process. - */ - public void processProtoFile(String filename) { - var protoc = commandFactory.createCommand( + } + + /** + * Process a given .proto file. + * + *

Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + public void processProtoFile(String filename) { + var protoc = + commandFactory.createCommand( "protoc-c", - List.of("--c_out="+this.fileConfig.getSrcGenPath(), filename), + List.of("--c_out=" + this.fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); - return; - } - var returnCode = protoc.run(); - if (returnCode == 0) { - var nameSansProto = filename.substring(0, filename.length() - 6); - targetConfig.compileAdditionalSources.add( - fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString() - ); - - targetConfig.compileLibraries.add("-l"); - targetConfig.compileLibraries.add("protobuf-c"); - targetConfig.compilerFlags.add("-lprotobuf-c"); - } else { - errorReporter.reportError("protoc-c returns error code " + returnCode); - } + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); + return; } - - /** - * Construct a unique type for the struct of the specified - * typed variable (port or action) of the specified reactor class. - * This is required to be the same as the type name returned by - * {@link #variableStructType(TriggerInstance)}. - * @param variable The variable. - * @param reactor The reactor class. - * @return The name of the self struct. - */ - public static String variableStructType(Variable variable, ReactorDecl reactor) { - return reactor.getName().toLowerCase()+"_"+variable.getName()+"_t"; + var returnCode = protoc.run(); + if (returnCode == 0) { + var nameSansProto = filename.substring(0, filename.length() - 6); + targetConfig.compileAdditionalSources.add( + fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString()); + + targetConfig.compileLibraries.add("-l"); + targetConfig.compileLibraries.add("protobuf-c"); + targetConfig.compilerFlags.add("-lprotobuf-c"); + } else { + errorReporter.reportError("protoc-c returns error code " + returnCode); } - - /** - * Construct a unique type for the struct of the specified - * instance (port or action). - * This is required to be the same as the type name returned by - * {@link #variableStructType(Variable, ReactorDecl)}. - * @param portOrAction The port or action instance. - * @return The name of the self struct. - */ - public static String variableStructType(TriggerInstance portOrAction) { - return portOrAction.getParent().reactorDeclaration.getName().toLowerCase()+"_"+portOrAction.getName()+"_t"; + } + + /** + * Construct a unique type for the struct of the specified typed variable (port or action) of the + * specified reactor class. This is required to be the same as the type name returned by {@link + * #variableStructType(TriggerInstance)}. + * + * @param variable The variable. + * @param reactor The reactor class. + * @return The name of the self struct. + */ + public static String variableStructType(Variable variable, ReactorDecl reactor) { + return reactor.getName().toLowerCase() + "_" + variable.getName() + "_t"; + } + + /** + * Construct a unique type for the struct of the specified instance (port or action). This is + * required to be the same as the type name returned by {@link #variableStructType(Variable, + * ReactorDecl)}. + * + * @param portOrAction The port or action instance. + * @return The name of the self struct. + */ + public static String variableStructType(TriggerInstance portOrAction) { + return portOrAction.getParent().reactorDeclaration.getName().toLowerCase() + + "_" + + portOrAction.getName() + + "_t"; + } + + /** + * If tracing is turned on, then generate code that records the full name of the specified reactor + * instance in the trace table. If tracing is not turned on, do nothing. + * + * @param instance The reactor instance. + */ + private void generateTraceTableEntries(ReactorInstance instance) { + if (targetConfig.tracing != null) { + initializeTriggerObjects.pr(CTracingGenerator.generateTraceTableEntries(instance)); } - - /** - * If tracing is turned on, then generate code that records - * the full name of the specified reactor instance in the - * trace table. If tracing is not turned on, do nothing. - * @param instance The reactor instance. - */ - private void generateTraceTableEntries(ReactorInstance instance) { - if (targetConfig.tracing != null) { - initializeTriggerObjects.pr( - CTracingGenerator.generateTraceTableEntries(instance) - ); - } + } + + /** + * Generate code to instantiate the specified reactor instance and initialize it. + * + * @param instance A reactor instance. + */ + public void generateReactorInstance(ReactorInstance instance) { + var reactorClass = instance.getDefinition().getReactorClass(); + var fullName = instance.getFullName(); + initializeTriggerObjects.pr( + "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); + // Generate the instance self struct containing parameters, state variables, + // and outputs (the "self" struct). + initializeTriggerObjects.pr( + CUtil.reactorRefName(instance) + + "[" + + CUtil.runtimeIndex(instance) + + "] = new_" + + reactorClass.getName() + + "();"); + // Generate code to initialize the "self" struct in the + // _lf_initialize_trigger_objects function. + generateTraceTableEntries(instance); + generateReactorInstanceExtension(instance); + generateParameterInitialization(instance); + initializeOutputMultiports(instance); + initializeInputMultiports(instance); + recordBuiltinTriggers(instance); + recordWatchdogs(instance); + + // Next, initialize the "self" struct with state variables. + // These values may be expressions that refer to the parameter values defined above. + generateStateVariableInitializations(instance); + + // Generate trigger objects for the instance. + generateTimerInitializations(instance); + generateActionInitializations(instance); + generateInitializeActionToken(instance); + generateSetDeadline(instance); + generateModeStructure(instance); + + // Recursively generate code for the children. + for (ReactorInstance child : instance.children) { + // If this reactor is a placeholder for a bank of reactors, then generate + // an array of instances of reactors and create an enclosing for loop. + // Need to do this for each of the builders into which the code writes. + startTimeStep.startScopedBlock(child); + initializeTriggerObjects.startScopedBlock(child); + generateReactorInstance(child); + initializeTriggerObjects.endScopedBlock(); + startTimeStep.endScopedBlock(); } - /** - * Generate code to instantiate the specified reactor instance and - * initialize it. - * @param instance A reactor instance. - */ - public void generateReactorInstance(ReactorInstance instance) { - var reactorClass = instance.getDefinition().getReactorClass(); - var fullName = instance.getFullName(); - initializeTriggerObjects.pr( - "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); - // Generate the instance self struct containing parameters, state variables, - // and outputs (the "self" struct). - initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+reactorClass.getName()+"();"); - // Generate code to initialize the "self" struct in the - // _lf_initialize_trigger_objects function. - generateTraceTableEntries(instance); - generateReactorInstanceExtension(instance); - generateParameterInitialization(instance); - initializeOutputMultiports(instance); - initializeInputMultiports(instance); - recordBuiltinTriggers(instance); - recordWatchdogs(instance); - - // Next, initialize the "self" struct with state variables. - // These values may be expressions that refer to the parameter values defined above. - generateStateVariableInitializations(instance); - - // Generate trigger objects for the instance. - generateTimerInitializations(instance); - generateActionInitializations(instance); - generateInitializeActionToken(instance); - generateSetDeadline(instance); - generateModeStructure(instance); - - // Recursively generate code for the children. - for (ReactorInstance child : instance.children) { - // If this reactor is a placeholder for a bank of reactors, then generate - // an array of instances of reactors and create an enclosing for loop. - // Need to do this for each of the builders into which the code writes. - startTimeStep.startScopedBlock(child); - initializeTriggerObjects.startScopedBlock(child); - generateReactorInstance(child); - initializeTriggerObjects.endScopedBlock(); - startTimeStep.endScopedBlock(); + // For this instance, define what must be done at the start of + // each time step. This sets up the tables that are used by the + // _lf_start_time_step() function in reactor_common.c. + // Note that this function is also run once at the end + // so that it can deallocate any memory. + generateStartTimeStep(instance); + initializeTriggerObjects.pr("//***** End initializing " + fullName); + } + + /** + * For each action of the specified reactor instance, generate initialization code for the offset + * and period fields. + * + * @param instance The reactor. + */ + private void generateActionInitializations(ReactorInstance instance) { + initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + } + + /** + * Initialize actions by creating a lf_token_t in the self struct. This has the information + * required to allocate memory for the action payload. Skip any action that is not actually used + * as a trigger. + * + * @param reactor The reactor containing the actions. + */ + private void generateInitializeActionToken(ReactorInstance reactor) { + for (ActionInstance action : reactor.actions) { + // Skip this step if the action is not in use. + if (action.getParent().getTriggers().contains(action)) { + var type = getInferredType(action.getDefinition()); + var payloadSize = "0"; + if (!type.isUndefined()) { + var typeStr = types.getTargetType(type); + if (CUtil.isTokenType(type, types)) { + typeStr = CUtil.rootType(typeStr); + } + if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { + payloadSize = "sizeof(" + typeStr + ")"; + } } - // For this instance, define what must be done at the start of - // each time step. This sets up the tables that are used by the - // _lf_start_time_step() function in reactor_common.c. - // Note that this function is also run once at the end - // so that it can deallocate any memory. - generateStartTimeStep(instance); - initializeTriggerObjects.pr("//***** End initializing " + fullName); - } - - /** - * For each action of the specified reactor instance, generate initialization code - * for the offset and period fields. - * @param instance The reactor. - */ - private void generateActionInitializations(ReactorInstance instance) { - initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + var selfStruct = CUtil.reactorRef(action.getParent()); + initializeTriggerObjects.pr( + CActionGenerator.generateTokenInitializer(selfStruct, action.getName(), payloadSize)); + } } - - /** - * Initialize actions by creating a lf_token_t in the self struct. - * This has the information required to allocate memory for the action payload. - * Skip any action that is not actually used as a trigger. - * @param reactor The reactor containing the actions. - */ - private void generateInitializeActionToken(ReactorInstance reactor) { - for (ActionInstance action : reactor.actions) { - // Skip this step if the action is not in use. - if (action.getParent().getTriggers().contains(action) - ) { - var type = getInferredType(action.getDefinition()); - var payloadSize = "0"; - if (!type.isUndefined()) { - var typeStr = types.getTargetType(type); - if (CUtil.isTokenType(type, types)) { - typeStr = CUtil.rootType(typeStr); - } - if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { - payloadSize = "sizeof("+typeStr+")"; - } - } - - var selfStruct = CUtil.reactorRef(action.getParent()); - initializeTriggerObjects.pr( - CActionGenerator.generateTokenInitializer( - selfStruct, action.getName(), payloadSize - ) - ); - } + } + + /** + * Generate code that is executed while the reactor instance is being initialized. This is + * provided as an extension point for subclasses. Normally, the reactions argument is the full + * list of reactions, but for the top-level of a federate, will be a subset of reactions that is + * relevant to the federate. + * + * @param instance The reactor instance. + */ + protected void generateReactorInstanceExtension(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. + * + * @param instance The reactor class instance + */ + protected void generateStateVariableInitializations(ReactorInstance instance) { + var reactorClass = instance.getDefinition().getReactorClass(); + var selfRef = CUtil.reactorRef(instance); + for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { + if (isInitialized(stateVar)) { + var mode = + stateVar.eContainer() instanceof Mode + ? instance.lookupModeInstance((Mode) stateVar.eContainer()) + : instance.getMode(false); + initializeTriggerObjects.pr( + CStateGenerator.generateInitializer(instance, selfRef, stateVar, mode, types)); + if (mode != null && stateVar.isReset()) { + modalStateResetCount += instance.getTotalWidth(); } + } } - - /** - * Generate code that is executed while the reactor instance is being initialized. - * This is provided as an extension point for subclasses. - * Normally, the reactions argument is the full list of reactions, - * but for the top-level of a federate, will be a subset of reactions that - * is relevant to the federate. - * @param instance The reactor instance. - */ - protected void generateReactorInstanceExtension(ReactorInstance instance) { - // Do nothing - } - - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all instances - * of the same reactor. - * @param instance The reactor class instance - */ - protected void generateStateVariableInitializations(ReactorInstance instance) { - var reactorClass = instance.getDefinition().getReactorClass(); - var selfRef = CUtil.reactorRef(instance); - for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { - if (isInitialized(stateVar)) { - var mode = stateVar.eContainer() instanceof Mode ? - instance.lookupModeInstance((Mode) stateVar.eContainer()) : - instance.getMode(false); - initializeTriggerObjects.pr(CStateGenerator.generateInitializer( - instance, - selfRef, - stateVar, - mode, - types - )); - if (mode != null && stateVar.isReset()) { - modalStateResetCount += instance.getTotalWidth(); - } - } - } + } + + /** + * Generate code to set the deadline field of the reactions in the specified reactor instance. + * + * @param instance The reactor instance. + */ + private void generateSetDeadline(ReactorInstance instance) { + for (ReactionInstance reaction : instance.reactions) { + var selfRef = CUtil.reactorRef(reaction.getParent()) + "->_lf__reaction_" + reaction.index; + if (reaction.declaredDeadline != null) { + var deadline = reaction.declaredDeadline.maxDelay; + initializeTriggerObjects.pr( + selfRef + ".deadline = " + types.getTargetTimeExpr(deadline) + ";"); + } else { // No deadline. + initializeTriggerObjects.pr(selfRef + ".deadline = NEVER;"); + } } - - /** - * Generate code to set the deadline field of the reactions in the - * specified reactor instance. - * @param instance The reactor instance. - */ - private void generateSetDeadline(ReactorInstance instance) { - for (ReactionInstance reaction : instance.reactions) { - var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; - if (reaction.declaredDeadline != null) { - var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); - } else { // No deadline. - initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); - } - } + } + + /** + * Generate code to initialize modes. + * + * @param instance The reactor instance. + */ + private void generateModeStructure(ReactorInstance instance) { + CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); + if (!instance.modes.isEmpty()) { + modalReactorCount += instance.getTotalWidth(); } - - /** - * Generate code to initialize modes. - * @param instance The reactor instance. - */ - private void generateModeStructure(ReactorInstance instance) { - CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); - if (!instance.modes.isEmpty()) { - modalReactorCount += instance.getTotalWidth(); - } + } + + /** + * Generate runtime initialization code for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + protected void generateParameterInitialization(ReactorInstance instance) { + var selfRef = CUtil.reactorRef(instance); + // Set the local bank_index variable so that initializers can use it. + initializeTriggerObjects.pr( + "bank_index = " + + CUtil.bankIndex(instance) + + ";" + + " SUPPRESS_UNUSED_WARNING(bank_index);"); + for (ParameterInstance parameter : instance.parameters) { + // NOTE: we now use the resolved literal value. For better efficiency, we could + // store constants in a global array and refer to its elements to avoid duplicate + // memory allocations. + // NOTE: If the parameter is initialized with a static initializer for an array + // or struct (the initialization expression is surrounded by { ... }), then we + // have to declare a static variable to ensure that the memory is put in data space + // and not on the stack. + // FIXME: Is there a better way to determine this than the string comparison? + var initializer = CParameterGenerator.getInitializer(parameter); + if (initializer.startsWith("{")) { + var temporaryVariableName = parameter.uniqueID(); + initializeTriggerObjects.pr( + String.join( + "\n", + "static " + + types.getVariableDeclaration(parameter.type, temporaryVariableName, true) + + " = " + + initializer + + ";", + selfRef + "->" + parameter.getName() + " = " + temporaryVariableName + ";")); + } else { + initializeTriggerObjects.pr( + selfRef + "->" + parameter.getName() + " = " + initializer + ";"); + } } - - /** - * Generate runtime initialization code for parameters of a given reactor instance - * @param instance The reactor instance. - */ - protected void generateParameterInitialization(ReactorInstance instance) { - var selfRef = CUtil.reactorRef(instance); - // Set the local bank_index variable so that initializers can use it. - initializeTriggerObjects.pr("bank_index = "+CUtil.bankIndex(instance)+";" - + " SUPPRESS_UNUSED_WARNING(bank_index);"); - for (ParameterInstance parameter : instance.parameters) { - // NOTE: we now use the resolved literal value. For better efficiency, we could - // store constants in a global array and refer to its elements to avoid duplicate - // memory allocations. - // NOTE: If the parameter is initialized with a static initializer for an array - // or struct (the initialization expression is surrounded by { ... }), then we - // have to declare a static variable to ensure that the memory is put in data space - // and not on the stack. - // FIXME: Is there a better way to determine this than the string comparison? - var initializer = CParameterGenerator.getInitializer(parameter); - if (initializer.startsWith("{")) { - var temporaryVariableName = parameter.uniqueID(); - initializeTriggerObjects.pr(String.join("\n", - "static "+types.getVariableDeclaration(parameter.type, temporaryVariableName, true)+" = "+initializer+";", - selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" - )); - } else { - initializeTriggerObjects.pr(selfRef+"->"+parameter.getName()+" = "+initializer+";"); - } - } + } + + /** + * Generate code that mallocs memory for any output multiports. + * + * @param reactor The reactor instance. + */ + private void initializeOutputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance output : reactor.outputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeOutputMultiport(output, reactorSelfStruct)); } - - /** - * Generate code that mallocs memory for any output multiports. - * @param reactor The reactor instance. - */ - private void initializeOutputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance output : reactor.outputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeOutputMultiport( - output, - reactorSelfStruct - )); - } + } + + /** + * Allocate memory for inputs. + * + * @param reactor The reactor. + */ + private void initializeInputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance input : reactor.inputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeInputMultiport(input, reactorSelfStruct)); } - - /** - * Allocate memory for inputs. - * @param reactor The reactor. - */ - private void initializeInputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance input : reactor.inputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeInputMultiport( - input, - reactorSelfStruct - )); - } + } + + @Override + public TargetTypes getTargetTypes() { + return types; + } + + /** + * @param context + * @return + */ + protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new CDockerGenerator(context); + } + + // ////////////////////////////////////////// + // // Protected methods. + + // Perform set up that does not generate code + protected void setUpGeneralParameters() { + accommodatePhysicalActionsIfPresent(); + targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); + // Create the main reactor instance if there is a main reactor. + createMainReactorInstance(); + if (hasModalReactors) { + // So that each separate compile knows about modal reactors, do this: + targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); } - - @Override - public TargetTypes getTargetTypes() { - return types; + if (targetConfig.threading + && targetConfig.platformOptions.platform == Platform.ARDUINO + && (targetConfig.platformOptions.board == null + || !targetConfig.platformOptions.board.contains("mbed"))) { + // non-MBED boards should not use threading + System.out.println( + "Threading is incompatible on your current Arduino flavor. Setting threading to false."); + targetConfig.threading = false; } - /** - * - * @param context - * @return - */ - protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new CDockerGenerator(context); + if (targetConfig.platformOptions.platform == Platform.ARDUINO + && !targetConfig.noCompile + && targetConfig.platformOptions.board == null) { + System.out.println( + "To enable compilation for the Arduino platform, you must specify the fully-qualified" + + " board name (FQBN) in the target property. For example, platform: {name: arduino," + + " board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target" + + " code only."); + targetConfig.noCompile = true; } - - // ////////////////////////////////////////// - // // Protected methods. - - // Perform set up that does not generate code - protected void setUpGeneralParameters() { - accommodatePhysicalActionsIfPresent(); - targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); - targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); - // Create the main reactor instance if there is a main reactor. - createMainReactorInstance(); - if (hasModalReactors) { - // So that each separate compile knows about modal reactors, do this: - targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); - } - if (targetConfig.threading && targetConfig.platformOptions.platform == Platform.ARDUINO - && (targetConfig.platformOptions.board == null || !targetConfig.platformOptions.board.contains("mbed"))) { - //non-MBED boards should not use threading - System.out.println("Threading is incompatible on your current Arduino flavor. Setting threading to false."); - targetConfig.threading = false; - } - - if (targetConfig.platformOptions.platform == Platform.ARDUINO && !targetConfig.noCompile - && targetConfig.platformOptions.board == null) { - System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); - targetConfig.noCompile = true; - } - if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake - pickScheduler(); - // FIXME: this and pickScheduler should be combined. - targetConfig.compileDefinitions.put( - "SCHEDULER", - targetConfig.schedulerType.name() - ); - targetConfig.compileDefinitions.put( - "NUMBER_OF_WORKERS", - String.valueOf(targetConfig.workers) - ); - } - pickCompilePlatform(); + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake + pickScheduler(); + // FIXME: this and pickScheduler should be combined. + targetConfig.compileDefinitions.put("SCHEDULER", targetConfig.schedulerType.name()); + targetConfig.compileDefinitions.put( + "NUMBER_OF_WORKERS", String.valueOf(targetConfig.workers)); } - - -// // Perform set up that does not generate code -// protected void setUpFederateSpecificParameters(FederateInstance federate, CodeBuilder commonCode) { -// currentFederate = federate; -// if (isFederated) { -// // Reset the cmake-includes and files, to be repopulated for each federate individually. -// // This is done to enable support for separately -// // adding cmake-includes/files for different federates to prevent linking and mixing -// // all federates' supporting libraries/files together. -// targetConfig.cmakeIncludes.clear(); -// targetConfig.cmakeIncludesWithoutPath.clear(); -// targetConfig.fileNames.clear(); -// targetConfig.filesNamesWithoutPath.clear(); -// -// // Re-apply the cmake-include target property of the main .lf file. -// var target = GeneratorUtils.findTarget(mainDef.getReactorClass().eResource()); -// if (target.getConfig() != null) { -// // Update the cmake-include -// TargetProperty.updateOne( -// this.targetConfig, -// TargetProperty.CMAKE_INCLUDE, -// convertToEmptyListIfNull(target.getConfig().getPairs()), -// errorReporter -// ); -// // Update the files -// TargetProperty.updateOne( -// this.targetConfig, -// TargetProperty.FILES, -// convertToEmptyListIfNull(target.getConfig().getPairs()), -// errorReporter -// ); -// } -// // Clear out previously generated code. -// code = new CodeBuilder(commonCode); -// initializeTriggerObjects = new CodeBuilder(); -// // Enable clock synchronization if the federate -// // is not local and clock-sync is enabled -// initializeClockSynchronization(); -// startTimeStep = new CodeBuilder(); -// } -// } - - protected void handleProtoFiles() { - // Handle .proto files. - for (String file : targetConfig.protoFiles) { - this.processProtoFile(file); - var dotIndex = file.lastIndexOf("."); - var rootFilename = file; - if (dotIndex > 0) { - rootFilename = file.substring(0, dotIndex); - } - code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - } + pickCompilePlatform(); + } + + // // Perform set up that does not generate code + // protected void setUpFederateSpecificParameters(FederateInstance federate, CodeBuilder + // commonCode) { + // currentFederate = federate; + // if (isFederated) { + // // Reset the cmake-includes and files, to be repopulated for each federate + // individually. + // // This is done to enable support for separately + // // adding cmake-includes/files for different federates to prevent linking and mixing + // // all federates' supporting libraries/files together. + // targetConfig.cmakeIncludes.clear(); + // targetConfig.cmakeIncludesWithoutPath.clear(); + // targetConfig.fileNames.clear(); + // targetConfig.filesNamesWithoutPath.clear(); + // + // // Re-apply the cmake-include target property of the main .lf file. + // var target = GeneratorUtils.findTarget(mainDef.getReactorClass().eResource()); + // if (target.getConfig() != null) { + // // Update the cmake-include + // TargetProperty.updateOne( + // this.targetConfig, + // TargetProperty.CMAKE_INCLUDE, + // convertToEmptyListIfNull(target.getConfig().getPairs()), + // errorReporter + // ); + // // Update the files + // TargetProperty.updateOne( + // this.targetConfig, + // TargetProperty.FILES, + // convertToEmptyListIfNull(target.getConfig().getPairs()), + // errorReporter + // ); + // } + // // Clear out previously generated code. + // code = new CodeBuilder(commonCode); + // initializeTriggerObjects = new CodeBuilder(); + // // Enable clock synchronization if the federate + // // is not local and clock-sync is enabled + // initializeClockSynchronization(); + // startTimeStep = new CodeBuilder(); + // } + // } + + protected void handleProtoFiles() { + // Handle .proto files. + for (String file : targetConfig.protoFiles) { + this.processProtoFile(file); + var dotIndex = file.lastIndexOf("."); + var rootFilename = file; + if (dotIndex > 0) { + rootFilename = file.substring(0, dotIndex); + } + code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); } - - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(CPreambleGenerator.generateDefineDirectives( - targetConfig, - fileConfig.getSrcGenPath(), - hasModalReactors - )); - code.pr(CPreambleGenerator.generateIncludeStatements( - targetConfig, - CCppMode - )); - return code.toString(); + } + + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + CPreambleGenerator.generateDefineDirectives( + targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); + code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); + return code.toString(); + } + + /** Generate top-level preamble code. */ + protected String generateTopLevelPreambles() { + CodeBuilder code = new CodeBuilder(); + + // preamble for federated execution setup + if (targetConfig.fedSetupPreamble != null) { + if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); + code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); + if (targetLanguageIsCpp()) code.pr("}"); } - /** - * Generate top-level preamble code. - */ - protected String generateTopLevelPreambles() { - CodeBuilder code = new CodeBuilder(); - - // preamble for federated execution setup - if (targetConfig.fedSetupPreamble != null) { - if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); - code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); - if (targetLanguageIsCpp()) code.pr("}"); - } - - // user preambles - if (this.mainDef != null) { - var mainModel = (Model) toDefinition(mainDef.getReactorClass()).eContainer(); - for (Preamble p : mainModel.getPreambles()) { - code.pr(toText(p.getCode())); - } - } - return code.toString(); + // user preambles + if (this.mainDef != null) { + var mainModel = (Model) toDefinition(mainDef.getReactorClass()).eContainer(); + for (Preamble p : mainModel.getPreambles()) { + code.pr(toText(p.getCode())); + } } - - protected boolean targetLanguageIsCpp() { - return CCppMode; + return code.toString(); + } + + protected boolean targetLanguageIsCpp() { + return CCppMode; + } + + /** + * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if + * the line is recognized as the first line of an error message. Otherwise, return null. + * + * @param line A line of output from a compiler or other external tool that might generate errors. + * @return If the line is recognized as the start of an error message, then return a class + * containing the path to the file on which the error occurred (or null if there is none), the + * line number (or the string "1" if there is none), the character position (or the string "0" + * if there is none), and the message (or an empty string if there is none). + */ + @Override + public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + var matcher = compileErrorPattern.matcher(line); + if (matcher.find()) { + var result = new ErrorFileAndLine(); + result.filepath = matcher.group("path"); + result.line = matcher.group("line"); + result.character = matcher.group("column"); + result.message = matcher.group("message"); + + if (!result.message.toLowerCase().contains("error:")) { + result.isError = false; + } + return result; } - - /** Given a line of text from the output of a compiler, return - * an instance of ErrorFileAndLine if the line is recognized as - * the first line of an error message. Otherwise, return null. - * @param line A line of output from a compiler or other external - * tool that might generate errors. - * @return If the line is recognized as the start of an error message, - * then return a class containing the path to the file on which the - * error occurred (or null if there is none), the line number (or the - * string "1" if there is none), the character position (or the string - * "0" if there is none), and the message (or an empty string if there - * is none). - */ - @Override - public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { - var matcher = compileErrorPattern.matcher(line); - if (matcher.find()) { - var result = new ErrorFileAndLine(); - result.filepath = matcher.group("path"); - result.line = matcher.group("line"); - result.character = matcher.group("column"); - result.message = matcher.group("message"); - - if (!result.message.toLowerCase().contains("error:")) { - result.isError = false; - } - return result; + return null; + } + + //////////////////////////////////////////// + //// Private methods. + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.C; + } + + //////////////////////////////////////////////////////////// + //// Private methods + + /** + * If a main or federated reactor has been declared, create a ReactorInstance for this top level. + * This will also assign levels to reactions, then, if the program is federated, perform an AST + * transformation to disconnect connections between federates. + */ + private void createMainReactorInstance() { + if (this.mainDef != null) { + if (this.main == null) { + // Recursively build instances. + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + var reactionInstanceGraph = this.main.assignLevels(); + if (reactionInstanceGraph.nodeCount() > 0) { + errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); + return; } - return null; - } - - //////////////////////////////////////////// - //// Private methods. - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.C; - } - - //////////////////////////////////////////////////////////// - //// Private methods - - /** - * If a main or federated reactor has been declared, create a ReactorInstance - * for this top level. This will also assign levels to reactions, then, - * if the program is federated, perform an AST transformation to disconnect - * connections between federates. - */ - private void createMainReactorInstance() { - if (this.mainDef != null) { - if (this.main == null) { - // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); - var reactionInstanceGraph = this.main.assignLevels(); - if (reactionInstanceGraph.nodeCount() > 0) { - errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); - return; - } - if (hasDeadlines) { - this.main.assignDeadlines(); - } - // Inform the run-time of the breadth/parallelism of the reaction graph - var breadth = reactionInstanceGraph.getBreadth(); - if (breadth == 0) { - errorReporter.reportWarning("The program has no reactions"); - } else { - targetConfig.compileDefinitions.put( - "LF_REACTION_GRAPH_BREADTH", - String.valueOf(reactionInstanceGraph.getBreadth()) - ); - } - } + if (hasDeadlines) { + this.main.assignDeadlines(); } - - } - - /** - * Generate an array of self structs for the reactor - * and one for each of its children. - * @param r The reactor instance. - */ - private void generateSelfStructs(ReactorInstance r) { - initializeTriggerObjects.pr(CUtil.selfType(r)+"* "+CUtil.reactorRefName(r)+"["+r.getTotalWidth()+"];"); - initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING("+CUtil.reactorRefName(r)+");"); - for (ReactorInstance child : r.children) { - generateSelfStructs(child); + // Inform the run-time of the breadth/parallelism of the reaction graph + var breadth = reactionInstanceGraph.getBreadth(); + if (breadth == 0) { + errorReporter.reportWarning("The program has no reactions"); + } else { + targetConfig.compileDefinitions.put( + "LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())); } + } + } + } + + /** + * Generate an array of self structs for the reactor and one for each of its children. + * + * @param r The reactor instance. + */ + private void generateSelfStructs(ReactorInstance r) { + initializeTriggerObjects.pr( + CUtil.selfType(r) + "* " + CUtil.reactorRefName(r) + "[" + r.getTotalWidth() + "];"); + initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING(" + CUtil.reactorRefName(r) + ");"); + for (ReactorInstance child : r.children) { + generateSelfStructs(child); } + } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 0a1df14302..b7f72e216a 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Map; import java.util.Set; - import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; @@ -38,1158 +37,1335 @@ import org.lflang.util.StringUtil; public class CReactionGenerator { - protected static String DISABLE_REACTION_INITIALIZATION_MARKER - = "// **** Do not include initialization code in this reaction."; + protected static String DISABLE_REACTION_INITIALIZATION_MARKER = + "// **** Do not include initialization code in this reaction."; - /** - * Generate necessary initialization code inside the body of the reaction that belongs to reactor decl. - * @param body The body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER. - * @param reaction The initialization code will be generated for this specific reaction - * @param decl The reactor that has the reaction - * @param reactionIndex The index of the reaction relative to other reactions in the reactor, starting from 0 - */ - public static String generateInitializationForReaction(String body, - Reaction reaction, - ReactorDecl decl, - int reactionIndex, - CTypes types, - ErrorReporter errorReporter, - Instantiation mainDef, - boolean requiresTypes) { - Reactor reactor = ASTUtils.toDefinition(decl); + /** + * Generate necessary initialization code inside the body of the reaction that belongs to reactor + * decl. + * + * @param body The body of the reaction. Used to check for the + * DISABLE_REACTION_INITIALIZATION_MARKER. + * @param reaction The initialization code will be generated for this specific reaction + * @param decl The reactor that has the reaction + * @param reactionIndex The index of the reaction relative to other reactions in the reactor, + * starting from 0 + */ + public static String generateInitializationForReaction( + String body, + Reaction reaction, + ReactorDecl decl, + int reactionIndex, + CTypes types, + ErrorReporter errorReporter, + Instantiation mainDef, + boolean requiresTypes) { + Reactor reactor = ASTUtils.toDefinition(decl); - // Construct the reactionInitialization code to go into - // the body of the function before the verbatim code. - CodeBuilder reactionInitialization = new CodeBuilder(); + // Construct the reactionInitialization code to go into + // the body of the function before the verbatim code. + CodeBuilder reactionInitialization = new CodeBuilder(); - CodeBuilder code = new CodeBuilder(); + CodeBuilder code = new CodeBuilder(); - // Define the "self" struct. - String structType = CUtil.selfType(decl); - // A null structType means there are no inputs, state, - // or anything else. No need to declare it. - if (structType != null) { - code.pr(String.join("\n", - structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" - )); - } + // Define the "self" struct. + String structType = CUtil.selfType(decl); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr( + String.join( + "\n", + structType + + "* self = (" + + structType + + "*)instance_args; SUPPRESS_UNUSED_WARNING(self);")); + } - // Do not generate the initialization code if the body is marked - // to not generate it. - if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { - return code.toString(); - } + // Do not generate the initialization code if the body is marked + // to not generate it. + if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { + return code.toString(); + } - // A reaction may send to or receive from multiple ports of - // a contained reactor. The variables for these ports need to - // all be declared as fields of the same struct. Hence, we first - // collect the fields to be defined in the structs and then - // generate the structs. - Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); + // A reaction may send to or receive from multiple ports of + // a contained reactor. The variables for these ports need to + // all be declared as fields of the same struct. Hence, we first + // collect the fields to be defined in the structs and then + // generate the structs. + Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); - // Actions may appear twice, first as a trigger, then with the outputs. - // But we need to declare it only once. Collect in this data structure - // the actions that are declared as triggered so that if they appear - // again with the outputs, they are not defined a second time. - // That second redefinition would trigger a compile error. - Set actionsAsTriggers = new LinkedHashSet<>(); + // Actions may appear twice, first as a trigger, then with the outputs. + // But we need to declare it only once. Collect in this data structure + // the actions that are declared as triggered so that if they appear + // again with the outputs, they are not defined a second time. + // That second redefinition would trigger a compile error. + Set actionsAsTriggers = new LinkedHashSet<>(); - // Next, add the triggers (input and actions; timers are not needed). - // This defines a local variable in the reaction function whose - // name matches that of the trigger. The value of the local variable - // is a struct with a value and is_present field, the latter a boolean - // that indicates whether the input/action is present. - // If the trigger is an output, then it is an output of a - // contained reactor. In this case, a struct with the name - // of the contained reactor is created with one field that is - // a pointer to a struct with a value and is_present field. - // E.g., if the contained reactor is named 'c' and its output - // port is named 'out', then c.out->value c.out->is_present are - // defined so that they can be used in the verbatim code. - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (triggerAsVarRef.getVariable() instanceof Port) { - generatePortVariablesInReaction( - reactionInitialization, - fieldsForStructsForContainedReactors, - triggerAsVarRef, - decl, - types); - } else if (triggerAsVarRef.getVariable() instanceof Action) { - reactionInitialization.pr(generateActionVariablesInReaction( - (Action) triggerAsVarRef.getVariable(), - decl, - types - )); - actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); - } - } - } - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - // No triggers are given, which means react to any input. - // Declare an argument for every input. - // NOTE: this does not include contained outputs. - for (Input input : reactor.getInputs()) { - reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); - } - } - // Define argument for non-triggering inputs. - for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - if (src.getVariable() instanceof Port) { - generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); - } else if (src.getVariable() instanceof Action) { - // It's a bit odd to read but not be triggered by an action, but - // OK, I guess we allow it. - reactionInitialization.pr(generateActionVariablesInReaction( - (Action) src.getVariable(), - decl, - types - )); - actionsAsTriggers.add((Action) src.getVariable()); - } + // Next, add the triggers (input and actions; timers are not needed). + // This defines a local variable in the reaction function whose + // name matches that of the trigger. The value of the local variable + // is a struct with a value and is_present field, the latter a boolean + // that indicates whether the input/action is present. + // If the trigger is an output, then it is an output of a + // contained reactor. In this case, a struct with the name + // of the contained reactor is created with one field that is + // a pointer to a struct with a value and is_present field. + // E.g., if the contained reactor is named 'c' and its output + // port is named 'out', then c.out->value c.out->is_present are + // defined so that they can be used in the verbatim code. + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (triggerAsVarRef.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, + fieldsForStructsForContainedReactors, + triggerAsVarRef, + decl, + types); + } else if (triggerAsVarRef.getVariable() instanceof Action) { + reactionInitialization.pr( + generateActionVariablesInReaction( + (Action) triggerAsVarRef.getVariable(), decl, types)); + actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); } - - // Define variables for each declared output or action. - // In the case of outputs, the variable is a pointer to where the - // output is stored. This gives the reaction code access to any previous - // value that may have been written to that output in an earlier reaction. - if (reaction.getEffects() != null) { - for (VarRef effect : reaction.getEffects()) { - Variable variable = effect.getVariable(); - if (variable instanceof Action) { - // It is an action, not an output. - // If it has already appeared as trigger, do not redefine it. - if (!actionsAsTriggers.contains(effect.getVariable())) { - reactionInitialization.pr(CGenerator.variableStructType(variable, decl)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); - } - } else if (effect.getVariable() instanceof Mode) { - // Mode change effect - int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); - String name = effect.getVariable().getName(); - if (idx >= 0) { - reactionInitialization.pr( - "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" - + "lf_mode_change_type_t _lf_" + name + "_change_type = " - + (effect.getTransition() == ModeTransition.HISTORY ? - "history_transition" : "reset_transition") - + ";" - ); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): " + name + " not a valid mode of this reactor." - ); - } - } else { - if (variable instanceof Output) { - reactionInitialization.pr(generateOutputVariablesInReaction( - effect, - decl, - errorReporter, - requiresTypes - )); - } else if (variable instanceof Input) { - // It is the input of a contained reactor. - generateVariablesForSendingToContainedReactors( - reactionInitialization, - fieldsForStructsForContainedReactors, - effect.getContainer(), - (Input) variable - ); - } else if (variable instanceof Watchdog) { - reactionInitialization.pr(generateWatchdogVariablesInReaction( - effect, - decl - )); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): effect is neither an input nor an output." - ); - } - } - } - } - // Before the reaction initialization, - // generate the structs used for communication to and from contained reactors. - for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - String array = ""; - if (containedReactor.getWidthSpec() != null) { - String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); - code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); - // Windows does not support variables in arrays declared on the stack, - // so we use the maximum size over all bank members. - array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; - } - code.pr(String.join("\n", - "struct "+containedReactor.getName()+" {", - " "+fieldsForStructsForContainedReactors.get(containedReactor)+"", - "} "+containedReactor.getName()+array+";" - )); - } - // Next generate all the collected setup code. - code.pr(reactionInitialization.toString()); - return code.toString(); + } + } + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + // No triggers are given, which means react to any input. + // Declare an argument for every input. + // NOTE: this does not include contained outputs. + for (Input input : reactor.getInputs()) { + reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); + } + } + // Define argument for non-triggering inputs. + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (src.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); + } else if (src.getVariable() instanceof Action) { + // It's a bit odd to read but not be triggered by an action, but + // OK, I guess we allow it. + reactionInitialization.pr( + generateActionVariablesInReaction((Action) src.getVariable(), decl, types)); + actionsAsTriggers.add((Action) src.getVariable()); + } } - /** - * Return the maximum bank width for the given instantiation within all - * instantiations of its parent reactor. - * On the first call to this method, the breadcrumbs should be null and the max - * argument should be zero. On recursive calls, breadcrumbs is a list of nested - * instantiations, the max is the maximum width found so far. The search for - * instances of the parent reactor will begin with the last instantiation - * in the specified list. - * - * This rather complicated method is used when a reaction sends or receives data - * to or from a bank of contained reactors. There will be an array of structs on - * the self struct of the parent, and the size of the array is conservatively set - * to the maximum of all the identified bank widths. This is a bit wasteful of - * memory, but it avoids having to malloc the array for each instance, and in - * typical usage, there will be few instances or instances that are all the same - * width. - * - * @param containedReactor The contained reactor instantiation. - * @param breadcrumbs null on first call (non-recursive). - * @param max 0 on first call. - */ - public static int maxContainedReactorBankWidth( - Instantiation containedReactor, - LinkedList breadcrumbs, - int max, - Instantiation mainDef - ) { - // If the instantiation is not a bank, return 1. - if (containedReactor.getWidthSpec() == null) { - return 1; - } - // If there is no main, then we just use the default width. - if (mainDef == null) { - return ASTUtils.width(containedReactor.getWidthSpec(), null); - } - LinkedList nestedBreadcrumbs = breadcrumbs; - if (nestedBreadcrumbs == null) { - nestedBreadcrumbs = new LinkedList<>(); - nestedBreadcrumbs.add(mainDef); - } - int result = max; - Reactor parent = (Reactor) containedReactor.eContainer(); - if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { - // The parent is main, so there can't be any other instantiations of it. - return ASTUtils.width(containedReactor.getWidthSpec(), null); - } - // Search for instances of the parent within the tail of the breadcrumbs list. - Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); - for (Instantiation instantiation : container.getInstantiations()) { - // Put this new instantiation at the head of the list. - nestedBreadcrumbs.add(0, instantiation); - if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { - // Found a matching instantiation of the parent. - // Evaluate the original width specification in this context. - int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); - if (candidate > result) { - result = candidate; - } - } else { - // Found some other instantiation, not the parent. - // Search within it for instantiations of the parent. - // Note that we assume here that the parent cannot contain - // instances of itself. - int candidate = maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); - if (candidate > result) { - result = candidate; - } - } - nestedBreadcrumbs.remove(); + // Define variables for each declared output or action. + // In the case of outputs, the variable is a pointer to where the + // output is stored. This gives the reaction code access to any previous + // value that may have been written to that output in an earlier reaction. + if (reaction.getEffects() != null) { + for (VarRef effect : reaction.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Action) { + // It is an action, not an output. + // If it has already appeared as trigger, do not redefine it. + if (!actionsAsTriggers.contains(effect.getVariable())) { + reactionInitialization.pr( + CGenerator.variableStructType(variable, decl) + + "* " + + variable.getName() + + " = &self->_lf_" + + variable.getName() + + ";"); + } + } else if (effect.getVariable() instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(reactor).indexOf((Mode) effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + reactionInitialization.pr( + "reactor_mode_t* " + + name + + " = &self->_lf__modes[" + + idx + + "];\n" + + "lf_mode_change_type_t _lf_" + + name + + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY + ? "history_transition" + : "reset_transition") + + ";"); + } else { + errorReporter.reportError( + reaction, "In generateReaction(): " + name + " not a valid mode of this reactor."); + } + } else { + if (variable instanceof Output) { + reactionInitialization.pr( + generateOutputVariablesInReaction(effect, decl, errorReporter, requiresTypes)); + } else if (variable instanceof Input) { + // It is the input of a contained reactor. + generateVariablesForSendingToContainedReactors( + reactionInitialization, + fieldsForStructsForContainedReactors, + effect.getContainer(), + (Input) variable); + } else if (variable instanceof Watchdog) { + reactionInitialization.pr(generateWatchdogVariablesInReaction(effect, decl)); + } else { + errorReporter.reportError( + reaction, "In generateReaction(): effect is neither an input nor an output."); + } } - return result; + } } - - /** - * Generate code for the body of a reaction that takes an input and - * schedules an action with the value of that input. - * @param actionName The action to schedule - */ - public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { - // Note that the action.type set by the base class is actually - // the port type. - return isTokenType ? - String.join("\n", - "if ("+ref+"->is_present) {", - " // Put the whole token on the event queue, not just the payload.", - " // This way, the length and element_size are transported.", - " lf_schedule_token("+actionName+", 0, "+ref+"->token);", - "}" - ) : - "lf_schedule_copy("+actionName+", 0, &"+ref+"->value, 1); // Length is 1."; + // Before the reaction initialization, + // generate the structs used for communication to and from contained reactors. + for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { + String array = ""; + if (containedReactor.getWidthSpec() != null) { + String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); + code.pr( + "int " + containedReactorWidthVar + " = self->_lf_" + containedReactorWidthVar + ";"); + // Windows does not support variables in arrays declared on the stack, + // so we use the maximum size over all bank members. + array = "[" + maxContainedReactorBankWidth(containedReactor, null, 0, mainDef) + "]"; + } + code.pr( + String.join( + "\n", + "struct " + containedReactor.getName() + " {", + " " + fieldsForStructsForContainedReactors.get(containedReactor) + "", + "} " + containedReactor.getName() + array + ";")); } + // Next generate all the collected setup code. + code.pr(reactionInitialization.toString()); + return code.toString(); + } - public static String generateForwardBody(String outputName, String targetType, String actionName, boolean isTokenType) { - return isTokenType ? - String.join("\n", - DISABLE_REACTION_INITIALIZATION_MARKER, - "self->_lf_"+outputName+".value = ("+targetType+")self->_lf__"+actionName+".tmplt.token->value;", - "_lf_replace_template_token((token_template_t*)&self->_lf_"+outputName+", (lf_token_t*)self->_lf__"+actionName+".tmplt.token);", - "self->_lf_"+outputName+".is_present = true;" - ) : - "lf_set("+outputName+", "+actionName+"->value);"; + /** + * Return the maximum bank width for the given instantiation within all instantiations of its + * parent reactor. On the first call to this method, the breadcrumbs should be null and the max + * argument should be zero. On recursive calls, breadcrumbs is a list of nested instantiations, + * the max is the maximum width found so far. The search for instances of the parent reactor will + * begin with the last instantiation in the specified list. + * + *

This rather complicated method is used when a reaction sends or receives data to or from a + * bank of contained reactors. There will be an array of structs on the self struct of the parent, + * and the size of the array is conservatively set to the maximum of all the identified bank + * widths. This is a bit wasteful of memory, but it avoids having to malloc the array for each + * instance, and in typical usage, there will be few instances or instances that are all the same + * width. + * + * @param containedReactor The contained reactor instantiation. + * @param breadcrumbs null on first call (non-recursive). + * @param max 0 on first call. + */ + public static int maxContainedReactorBankWidth( + Instantiation containedReactor, + LinkedList breadcrumbs, + int max, + Instantiation mainDef) { + // If the instantiation is not a bank, return 1. + if (containedReactor.getWidthSpec() == null) { + return 1; } - - /** - * Generate into the specified string builder the code to - * initialize local variables for sending data to an input - * of a contained reactor. This will also, if necessary, - * generate entries for local struct definitions into the - * struct argument. These entries point to where the data - * is stored. - * - * @param builder The string builder. - * @param structs A map from reactor instantiations to a place to write - * struct fields. - * @param definition AST node defining the reactor within which this occurs - * @param input Input of the contained reactor. - */ - private static void generateVariablesForSendingToContainedReactors( - CodeBuilder builder, - Map structs, - Instantiation definition, - Input input - ) { - CodeBuilder structBuilder = structs.get(definition); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(definition, structBuilder); + // If there is no main, then we just use the default width. + if (mainDef == null) { + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + LinkedList nestedBreadcrumbs = breadcrumbs; + if (nestedBreadcrumbs == null) { + nestedBreadcrumbs = new LinkedList<>(); + nestedBreadcrumbs.add(mainDef); + } + int result = max; + Reactor parent = (Reactor) containedReactor.eContainer(); + if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { + // The parent is main, so there can't be any other instantiations of it. + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + // Search for instances of the parent within the tail of the breadcrumbs list. + Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); + for (Instantiation instantiation : container.getInstantiations()) { + // Put this new instantiation at the head of the list. + nestedBreadcrumbs.add(0, instantiation); + if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { + // Found a matching instantiation of the parent. + // Evaluate the original width specification in this context. + int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); + if (candidate > result) { + result = candidate; } - String inputStructType = CGenerator.variableStructType(input, definition.getReactorClass()); - String defName = definition.getName(); - String defWidth = generateWidthVariable(defName); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); - if (!ASTUtils.isMultiport(input)) { - // Contained reactor's input is not a multiport. - structBuilder.pr(inputStructType+"* "+inputName+";"); - if (definition.getWidthSpec() != null) { - // Contained reactor is a bank. - builder.pr(String.join("\n", - "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", - " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", - "}" - )); - } else { - // Contained reactor is not a bank. - builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); - } - } else { - // Contained reactor's input is a multiport. - structBuilder.pr(String.join("\n", - inputStructType+"** "+inputName+";", - "int "+inputWidth+";" - )); - // If the contained reactor is a bank, then we have to set the - // pointer for each element of the bank. - if (definition.getWidthSpec() != null) { - builder.pr(String.join("\n", - "for (int _i = 0; _i < self->_lf_"+defWidth+"; _i++) {", - " "+defName+"[_i]."+inputName+" = self->_lf_"+defName+"[_i]."+inputName+";", - " "+defName+"[_i]."+inputWidth+" = self->_lf_"+defName+"[_i]."+inputWidth+";", - "}" - )); - } else { - builder.pr(String.join("\n", - defName+"."+inputName+" = self->_lf_"+defName+"."+inputName+";", - defName+"."+inputWidth+" = self->_lf_"+defName+"."+inputWidth+";" - )); - } + } else { + // Found some other instantiation, not the parent. + // Search within it for instantiations of the parent. + // Note that we assume here that the parent cannot contain + // instances of itself. + int candidate = + maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); + if (candidate > result) { + result = candidate; } + } + nestedBreadcrumbs.remove(); } + return result; + } - /** - * Generate into the specified string builder the code to - * initialize local variables for ports in a reaction function - * from the "self" struct. The port may be an input of the - * reactor or an output of a contained reactor. The second - * argument provides, for each contained reactor, a place to - * write the declaration of the output of that reactor that - * is triggering reactions. - * @param builder The place into which to write the code. - * @param structs A map from reactor instantiations to a place to write - * struct fields. - * @param port The port. - * @param decl The reactor or import statement. - */ - private static void generatePortVariablesInReaction( - CodeBuilder builder, - Map structs, - VarRef port, - ReactorDecl decl, - CTypes types - ) { - if (port.getVariable() instanceof Input) { - builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), decl, types)); - } else { - // port is an output of a contained reactor. - Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, port.getContainer().getReactorClass()); + /** + * Generate code for the body of a reaction that takes an input and schedules an action with the + * value of that input. + * + * @param actionName The action to schedule + */ + public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { + // Note that the action.type set by the base class is actually + // the port type. + return isTokenType + ? String.join( + "\n", + "if (" + ref + "->is_present) {", + " // Put the whole token on the event queue, not just the payload.", + " // This way, the length and element_size are transported.", + " lf_schedule_token(" + actionName + ", 0, " + ref + "->token);", + "}") + : "lf_schedule_copy(" + actionName + ", 0, &" + ref + "->value, 1); // Length is 1."; + } - CodeBuilder structBuilder = structs.get(port.getContainer()); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(port.getContainer(), structBuilder); - } - String reactorName = port.getContainer().getName(); - String reactorWidth = generateWidthVariable(reactorName); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - // First define the struct containing the output value and indicator - // of its presence. - if (!ASTUtils.isMultiport(output)) { - // Output is not a multiport. - structBuilder.pr(portStructType+"* "+outputName+";"); - } else { - // Output is a multiport. - structBuilder.pr(String.join("\n", - portStructType+"** "+outputName+";", - "int "+outputWidth+";" - )); - } + public static String generateForwardBody( + String outputName, String targetType, String actionName, boolean isTokenType) { + return isTokenType + ? String.join( + "\n", + DISABLE_REACTION_INITIALIZATION_MARKER, + "self->_lf_" + + outputName + + ".value = (" + + targetType + + ")self->_lf__" + + actionName + + ".tmplt.token->value;", + "_lf_replace_template_token((token_template_t*)&self->_lf_" + + outputName + + ", (lf_token_t*)self->_lf__" + + actionName + + ".tmplt.token);", + "self->_lf_" + outputName + ".is_present = true;") + : "lf_set(" + outputName + ", " + actionName + "->value);"; + } - // Next, initialize the struct with the current values. - if (port.getContainer().getWidthSpec() != null) { - // Output is in a bank. - builder.pr(String.join("\n", - "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+reactorName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", - "}" - )); - if (ASTUtils.isMultiport(output)) { - builder.pr(String.join("\n", - "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+reactorName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", - "}" - )); - } - } else { - // Output is not in a bank. - builder.pr(reactorName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); - if (ASTUtils.isMultiport(output)) { - builder.pr(reactorName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); - } - } - } + /** + * Generate into the specified string builder the code to initialize local variables for sending + * data to an input of a contained reactor. This will also, if necessary, generate entries for + * local struct definitions into the struct argument. These entries point to where the data is + * stored. + * + * @param builder The string builder. + * @param structs A map from reactor instantiations to a place to write struct fields. + * @param definition AST node defining the reactor within which this occurs + * @param input Input of the contained reactor. + */ + private static void generateVariablesForSendingToContainedReactors( + CodeBuilder builder, + Map structs, + Instantiation definition, + Input input) { + CodeBuilder structBuilder = structs.get(definition); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(definition, structBuilder); } - - /** Generate action variables for a reaction. - * @param action The action. - * @param decl The reactor. - */ - private static String generateActionVariablesInReaction( - Action action, - ReactorDecl decl, - CTypes types - ) { - String structType = CGenerator.variableStructType(action, decl); - // If the action has a type, create variables for accessing the value. - InferredType type = ASTUtils.getInferredType(action); - // Pointer to the lf_token_t sent as the payload in the trigger. - String tokenPointer = "(self->_lf__"+action.getName()+".tmplt.token)"; - CodeBuilder builder = new CodeBuilder(); - + String inputStructType = CGenerator.variableStructType(input, definition.getReactorClass()); + String defName = definition.getName(); + String defWidth = generateWidthVariable(defName); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); + if (!ASTUtils.isMultiport(input)) { + // Contained reactor's input is not a multiport. + structBuilder.pr(inputStructType + "* " + inputName + ";"); + if (definition.getWidthSpec() != null) { + // Contained reactor is a bank. builder.pr( - String.join("\n", - "// Expose the action struct as a local variable whose name matches the action name.", - structType+"* "+action.getName()+" = &self->_lf_"+action.getName()+";", - "// Set the fields of the action struct to match the current trigger.", - action.getName()+"->is_present = (bool)self->_lf__"+action.getName()+".status;", - action.getName()+"->has_value = ("+tokenPointer+" != NULL && "+tokenPointer+"->value != NULL);", - "_lf_replace_template_token((token_template_t*)"+action.getName()+", "+tokenPointer+");") - ); - // Set the value field only if there is a type. - if (!type.isUndefined()) { - // The value field will either be a copy (for primitive types) - // or a pointer (for types ending in *). - builder.pr("if ("+action.getName()+"->has_value) {"); - builder.indent(); - if (CUtil.isTokenType(type, types)) { - builder.pr(action.getName()+"->value = ("+types.getTargetType(type)+")"+tokenPointer+"->value;"); - } else { - builder.pr(action.getName()+"->value = *("+types.getTargetType(type)+"*)"+tokenPointer+"->value;"); - } - builder.unindent(); - builder.pr("}"); - } - return builder.toString(); + String.join( + "\n", + "for (int bankIndex = 0; bankIndex < self->_lf_" + defWidth + "; bankIndex++) {", + " " + + defName + + "[bankIndex]." + + inputName + + " = &(self->_lf_" + + defName + + "[bankIndex]." + + inputName + + ");", + "}")); + } else { + // Contained reactor is not a bank. + builder.pr( + defName + "." + inputName + " = &(self->_lf_" + defName + "." + inputName + ");"); + } + } else { + // Contained reactor's input is a multiport. + structBuilder.pr( + String.join("\n", inputStructType + "** " + inputName + ";", "int " + inputWidth + ";")); + // If the contained reactor is a bank, then we have to set the + // pointer for each element of the bank. + if (definition.getWidthSpec() != null) { + builder.pr( + String.join( + "\n", + "for (int _i = 0; _i < self->_lf_" + defWidth + "; _i++) {", + " " + + defName + + "[_i]." + + inputName + + " = self->_lf_" + + defName + + "[_i]." + + inputName + + ";", + " " + + defName + + "[_i]." + + inputWidth + + " = self->_lf_" + + defName + + "[_i]." + + inputWidth + + ";", + "}")); + } else { + builder.pr( + String.join( + "\n", + defName + "." + inputName + " = self->_lf_" + defName + "." + inputName + ";", + defName + "." + inputWidth + " = self->_lf_" + defName + "." + inputWidth + ";")); + } } + } - /** Generate into the specified string builder the code to - * initialize local variables for the specified input port - * in a reaction function from the "self" struct. - * @param input The input statement from the AST. - * @param decl The reactor. - */ - private static String generateInputVariablesInReaction( - Input input, - ReactorDecl decl, - CTypes types - ) { - String structType = CGenerator.variableStructType(input, decl); - InferredType inputType = ASTUtils.getInferredType(input); - CodeBuilder builder = new CodeBuilder(); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); - - // Create the local variable whose name matches the input name. - // If the input has not been declared mutable, then this is a pointer - // to the upstream output. Otherwise, it is a copy of the upstream output, - // which nevertheless points to the same token and value (hence, as done - // below, we have to use lf_writable_copy()). There are 8 cases, - // depending on whether the input is mutable, whether it is a multiport, - // and whether it is a token type. - // Easy case first. - if (!input.isMutable() && !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, primitive type. - builder.pr(structType+"* "+inputName+" = self->_lf_"+inputName+";"); - } else if (input.isMutable()&& !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, primitive type. - builder.pr(String.join("\n", - "// Mutable input, so copy the input into a temporary variable.", - "// The input value on the struct is a copy.", - structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", - structType+"* "+inputName+" = &_lf_tmp_"+inputName+";" - )); - } else if (!input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, token type. - builder.pr(String.join("\n", - structType+"* "+inputName+" = self->_lf_"+inputName+";", - "if ("+inputName+"->is_present) {", - " "+inputName+"->length = "+inputName+"->token->length;", - " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", - "} else {", - " "+inputName+"->length = 0;", - "}" - )); - } else if (input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, token type. - builder.pr(String.join("\n", - "// Mutable input, so copy the input struct into a temporary variable.", - structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", - structType+"* "+inputName+" = &_lf_tmp_"+inputName+";", - inputName+"->value = NULL;", // Prevent payload from being freed. - "if ("+inputName+"->is_present) {", - " "+inputName+"->length = "+inputName+"->token->length;", - " "+inputName+"->token = lf_writable_copy((lf_port_base_t*)self->_lf_"+inputName+");", - " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", - "} else {", - " "+inputName+"->length = 0;", - "}" - )); - } else if (!input.isMutable()&& ASTUtils.isMultiport(input)) { - // Non-mutable, multiport, primitive or token type. - builder.pr(structType+"** "+inputName+" = self->_lf_"+inputName+";"); - } else if (CUtil.isTokenType(inputType, types)) { - // Mutable, multiport, token type - builder.pr(String.join("\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", - " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", - " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", - " // If necessary, copy the tokens.", - " if ("+inputName+"[i]->is_present) {", - " "+inputName+"[i]->length = "+inputName+"[i]->token->length;", - " token_template_t* _lf_input = (token_template_t*)self->_lf_"+inputName+"[i];", - " "+inputName+"[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", - " "+inputName+"[i]->value = ("+types.getTargetType(inputType)+")"+inputName+"[i]->token->value;", - " } else {", - " "+inputName+"[i]->length = 0;", - " }", - "}" - )); - } else { - // Mutable, multiport, primitive type - builder.pr(String.join("\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", - " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", - " // Copy the struct, which includes the value.", - " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", - "}" - )); - } - // Set the _width variable for all cases. This will be -1 - // for a variable-width multiport, which is not currently supported. - // It will be -2 if it is not multiport. - builder.pr("int "+inputWidth+" = self->_lf_"+inputWidth+"; SUPPRESS_UNUSED_WARNING("+inputWidth+");"); - return builder.toString(); - } + /** + * Generate into the specified string builder the code to initialize local variables for ports in + * a reaction function from the "self" struct. The port may be an input of the reactor or an + * output of a contained reactor. The second argument provides, for each contained reactor, a + * place to write the declaration of the output of that reactor that is triggering reactions. + * + * @param builder The place into which to write the code. + * @param structs A map from reactor instantiations to a place to write struct fields. + * @param port The port. + * @param decl The reactor or import statement. + */ + private static void generatePortVariablesInReaction( + CodeBuilder builder, + Map structs, + VarRef port, + ReactorDecl decl, + CTypes types) { + if (port.getVariable() instanceof Input) { + builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), decl, types)); + } else { + // port is an output of a contained reactor. + Output output = (Output) port.getVariable(); + String portStructType = + CGenerator.variableStructType(output, port.getContainer().getReactorClass()); - /** - * Generate into the specified string builder the code to - * initialize local variables for outputs in a reaction function - * from the "self" struct. - * @param effect The effect declared by the reaction. This must refer to an output. - * @param decl The reactor containing the reaction or the import statement. - */ - public static String generateOutputVariablesInReaction( - VarRef effect, - ReactorDecl decl, - ErrorReporter errorReporter, - boolean requiresTypes - ) { - Output output = (Output) effect.getVariable(); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - if (output.getType() == null && requiresTypes) { - errorReporter.reportError(output, "Output is required to have a type: " + outputName); - return ""; - } else { - // The container of the output may be a contained reactor or - // the reactor containing the reaction. - String outputStructType = (effect.getContainer() == null) ? - CGenerator.variableStructType(output, decl) - : - CGenerator.variableStructType(output, effect.getContainer().getReactorClass()); - if (!ASTUtils.isMultiport(output)) { - // Output port is not a multiport. - return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; - } else { - // Output port is a multiport. - // Set the _width variable. - return String.join("\n", - "int "+outputWidth+" = self->_lf_"+outputWidth+"; SUPPRESS_UNUSED_WARNING("+outputWidth+");", - outputStructType+"** "+outputName+" = self->_lf_"+outputName+"_pointers;" - ); + CodeBuilder structBuilder = structs.get(port.getContainer()); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(port.getContainer(), structBuilder); + } + String reactorName = port.getContainer().getName(); + String reactorWidth = generateWidthVariable(reactorName); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + // First define the struct containing the output value and indicator + // of its presence. + if (!ASTUtils.isMultiport(output)) { + // Output is not a multiport. + structBuilder.pr(portStructType + "* " + outputName + ";"); + } else { + // Output is a multiport. + structBuilder.pr( + String.join( + "\n", portStructType + "** " + outputName + ";", "int " + outputWidth + ";")); + } - } + // Next, initialize the struct with the current values. + if (port.getContainer().getWidthSpec() != null) { + // Output is in a bank. + builder.pr( + String.join( + "\n", + "for (int i = 0; i < " + reactorWidth + "; i++) {", + " " + + reactorName + + "[i]." + + outputName + + " = self->_lf_" + + reactorName + + "[i]." + + outputName + + ";", + "}")); + if (ASTUtils.isMultiport(output)) { + builder.pr( + String.join( + "\n", + "for (int i = 0; i < " + reactorWidth + "; i++) {", + " " + + reactorName + + "[i]." + + outputWidth + + " = self->_lf_" + + reactorName + + "[i]." + + outputWidth + + ";", + "}")); + } + } else { + // Output is not in a bank. + builder.pr( + reactorName + + "." + + outputName + + " = self->_lf_" + + reactorName + + "." + + outputName + + ";"); + if (ASTUtils.isMultiport(output)) { + builder.pr( + reactorName + + "." + + outputWidth + + " = self->_lf_" + + reactorName + + "." + + outputWidth + + ";"); } + } } + } - /** - * Generate into the specified string builder the code to - * initialize local variables for watchdogs in a reaction function - * from the "self" struct. - * @param effect The effect declared by the reaction. This must refer to a watchdog. - * @param decl The reactor containing the reaction or the import statement. - */ - // Fine to have watchdog be in reactor self struct? - public static String generateWatchdogVariablesInReaction( - VarRef effect, - ReactorDecl decl - ) { - Watchdog watchdog = (Watchdog) effect.getVariable(); - String watchdogName = watchdog.getName(); + /** + * Generate action variables for a reaction. + * + * @param action The action. + * @param decl The reactor. + */ + private static String generateActionVariablesInReaction( + Action action, ReactorDecl decl, CTypes types) { + String structType = CGenerator.variableStructType(action, decl); + // If the action has a type, create variables for accessing the value. + InferredType type = ASTUtils.getInferredType(action); + // Pointer to the lf_token_t sent as the payload in the trigger. + String tokenPointer = "(self->_lf__" + action.getName() + ".tmplt.token)"; + CodeBuilder builder = new CodeBuilder(); - return String.join("\n", List.of( - "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");" - )); + builder.pr( + String.join( + "\n", + "// Expose the action struct as a local variable whose name matches the action name.", + structType + "* " + action.getName() + " = &self->_lf_" + action.getName() + ";", + "// Set the fields of the action struct to match the current trigger.", + action.getName() + "->is_present = (bool)self->_lf__" + action.getName() + ".status;", + action.getName() + + "->has_value = (" + + tokenPointer + + " != NULL && " + + tokenPointer + + "->value != NULL);", + "_lf_replace_template_token((token_template_t*)" + + action.getName() + + ", " + + tokenPointer + + ");")); + // Set the value field only if there is a type. + if (!type.isUndefined()) { + // The value field will either be a copy (for primitive types) + // or a pointer (for types ending in *). + builder.pr("if (" + action.getName() + "->has_value) {"); + builder.indent(); + if (CUtil.isTokenType(type, types)) { + builder.pr( + action.getName() + + "->value = (" + + types.getTargetType(type) + + ")" + + tokenPointer + + "->value;"); + } else { + builder.pr( + action.getName() + + "->value = *(" + + types.getTargetType(type) + + "*)" + + tokenPointer + + "->value;"); + } + builder.unindent(); + builder.pr("}"); } + return builder.toString(); + } - /** - * Generate the fields of the self struct and statements for the constructor - * to create and initialize a reaction_t struct for each reaction in the - * specified reactor and a trigger_t struct for each trigger (input, action, - * timer, or output of a contained reactor). - * @param body The place to put the code for the self struct. - * @param decl The reactor. - * @param constructorCode The place to put the constructor code. - */ - public static void generateReactionAndTriggerStructs( - CodeBuilder body, - ReactorDecl decl, - CodeBuilder constructorCode, - CTypes types - ) { - var reactionCount = 0; - var reactor = ASTUtils.toDefinition(decl); - // Iterate over reactions and create initialize the reaction_t struct - // on the self struct. Also, collect a map from triggers to the reactions - // that are triggered by that trigger. Also, collect a set of sources - // that are read by reactions but do not trigger reactions. - // Finally, collect a set of triggers and sources that are outputs - // of contained reactors. - var triggerMap = new LinkedHashMap>(); - var sourceSet = new LinkedHashSet(); - var outputsOfContainedReactors = new LinkedHashMap(); - var startupReactions = new LinkedHashSet(); - var shutdownReactions = new LinkedHashSet(); - var resetReactions = new LinkedHashSet(); - // WATCHDOG QUESTION: Why need to grab all reactions from reactor only to check - // if it exists in currentFederate? - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create the reaction_t struct. - body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); + /** + * Generate into the specified string builder the code to initialize local variables for the + * specified input port in a reaction function from the "self" struct. + * + * @param input The input statement from the AST. + * @param decl The reactor. + */ + private static String generateInputVariablesInReaction( + Input input, ReactorDecl decl, CTypes types) { + String structType = CGenerator.variableStructType(input, decl); + InferredType inputType = ASTUtils.getInferredType(input); + CodeBuilder builder = new CodeBuilder(); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); - // Create the map of triggers to reactions. - for (TriggerRef trigger : reaction.getTriggers()) { - // trigger may not be a VarRef (it could be "startup" or "shutdown"). - if (trigger instanceof VarRef) { - var triggerAsVarRef = (VarRef) trigger; - var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); - if (reactionList == null) { - reactionList = new LinkedList<>(); - triggerMap.put(triggerAsVarRef.getVariable(), reactionList); - } - reactionList.add(reactionCount); - if (triggerAsVarRef.getContainer() != null) { - outputsOfContainedReactors.put(triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); - } - } else if (trigger instanceof BuiltinTriggerRef) { - switch(((BuiltinTriggerRef) trigger).getType()) { - case STARTUP: - startupReactions.add(reactionCount); - break; - case SHUTDOWN: - shutdownReactions.add(reactionCount); - break; - case RESET: - resetReactions.add(reactionCount); - break; - } - } - } - // Create the set of sources read but not triggering. - for (VarRef source : reaction.getSources()) { - sourceSet.add(source.getVariable()); - if (source.getContainer() != null) { - outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); - } - } + // Create the local variable whose name matches the input name. + // If the input has not been declared mutable, then this is a pointer + // to the upstream output. Otherwise, it is a copy of the upstream output, + // which nevertheless points to the same token and value (hence, as done + // below, we have to use lf_writable_copy()). There are 8 cases, + // depending on whether the input is mutable, whether it is a multiport, + // and whether it is a token type. + // Easy case first. + if (!input.isMutable() + && !CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, primitive type. + builder.pr(structType + "* " + inputName + " = self->_lf_" + inputName + ";"); + } else if (input.isMutable() + && !CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, primitive type. + builder.pr( + String.join( + "\n", + "// Mutable input, so copy the input into a temporary variable.", + "// The input value on the struct is a copy.", + structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", + structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";")); + } else if (!input.isMutable() + && CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, token type. + builder.pr( + String.join( + "\n", + structType + "* " + inputName + " = self->_lf_" + inputName + ";", + "if (" + inputName + "->is_present) {", + " " + inputName + "->length = " + inputName + "->token->length;", + " " + + inputName + + "->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "->token->value;", + "} else {", + " " + inputName + "->length = 0;", + "}")); + } else if (input.isMutable() + && CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, token type. + builder.pr( + String.join( + "\n", + "// Mutable input, so copy the input struct into a temporary variable.", + structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", + structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";", + inputName + "->value = NULL;", // Prevent payload from being freed. + "if (" + inputName + "->is_present) {", + " " + inputName + "->length = " + inputName + "->token->length;", + " " + + inputName + + "->token = lf_writable_copy((lf_port_base_t*)self->_lf_" + + inputName + + ");", + " " + + inputName + + "->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "->token->value;", + "} else {", + " " + inputName + "->length = 0;", + "}")); + } else if (!input.isMutable() && ASTUtils.isMultiport(input)) { + // Non-mutable, multiport, primitive or token type. + builder.pr(structType + "** " + inputName + " = self->_lf_" + inputName + ";"); + } else if (CUtil.isTokenType(inputType, types)) { + // Mutable, multiport, token type + builder.pr( + String.join( + "\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType + + " _lf_tmp_" + + inputName + + "[" + + CUtil.multiportWidthExpression(input) + + "];", + structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", + "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", + " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", + " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", + " // If necessary, copy the tokens.", + " if (" + inputName + "[i]->is_present) {", + " " + inputName + "[i]->length = " + inputName + "[i]->token->length;", + " token_template_t* _lf_input = (token_template_t*)self->_lf_" + + inputName + + "[i];", + " " + inputName + "[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", + " " + + inputName + + "[i]->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "[i]->token->value;", + " } else {", + " " + inputName + "[i]->length = 0;", + " }", + "}")); + } else { + // Mutable, multiport, primitive type + builder.pr( + String.join( + "\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType + + " _lf_tmp_" + + inputName + + "[" + + CUtil.multiportWidthExpression(input) + + "];", + structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", + "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", + " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", + " // Copy the struct, which includes the value.", + " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", + "}")); + } + // Set the _width variable for all cases. This will be -1 + // for a variable-width multiport, which is not currently supported. + // It will be -2 if it is not multiport. + builder.pr( + "int " + + inputWidth + + " = self->_lf_" + + inputWidth + + "; SUPPRESS_UNUSED_WARNING(" + + inputWidth + + ");"); + return builder.toString(); + } - var deadlineFunctionPointer = "NULL"; - if (reaction.getDeadline() != null) { - // The following has to match the name chosen in generateReactions - var deadlineFunctionName = generateDeadlineFunctionName(decl, reactionCount); - deadlineFunctionPointer = "&" + deadlineFunctionName; - } + /** + * Generate into the specified string builder the code to initialize local variables for outputs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to an output. + * @param decl The reactor containing the reaction or the import statement. + */ + public static String generateOutputVariablesInReaction( + VarRef effect, ReactorDecl decl, ErrorReporter errorReporter, boolean requiresTypes) { + Output output = (Output) effect.getVariable(); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + if (output.getType() == null && requiresTypes) { + errorReporter.reportError(output, "Output is required to have a type: " + outputName); + return ""; + } else { + // The container of the output may be a contained reactor or + // the reactor containing the reaction. + String outputStructType = + (effect.getContainer() == null) + ? CGenerator.variableStructType(output, decl) + : CGenerator.variableStructType(output, effect.getContainer().getReactorClass()); + if (!ASTUtils.isMultiport(output)) { + // Output port is not a multiport. + return outputStructType + "* " + outputName + " = &self->_lf_" + outputName + ";"; + } else { + // Output port is a multiport. + // Set the _width variable. + return String.join( + "\n", + "int " + + outputWidth + + " = self->_lf_" + + outputWidth + + "; SUPPRESS_UNUSED_WARNING(" + + outputWidth + + ");", + outputStructType + "** " + outputName + " = self->_lf_" + outputName + "_pointers;"); + } + } + } - // Assign the STP handler - var STPFunctionPointer = "NULL"; - if (reaction.getStp() != null) { - // The following has to match the name chosen in generateReactions - var STPFunctionName = generateStpFunctionName(decl, reactionCount); - STPFunctionPointer = "&" + STPFunctionName; - } + /** + * Generate into the specified string builder the code to initialize local variables for watchdogs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to a watchdog. + * @param decl The reactor containing the reaction or the import statement. + */ + // Fine to have watchdog be in reactor self struct? + public static String generateWatchdogVariablesInReaction(VarRef effect, ReactorDecl decl) { + Watchdog watchdog = (Watchdog) effect.getVariable(); + String watchdogName = watchdog.getName(); - // Set the defaults of the reaction_t struct in the constructor. - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__reaction_"+reactionCount+".index = 0; - // self->_lf__reaction_"+reactionCount+".chain_id = 0; - // self->_lf__reaction_"+reactionCount+".pos = 0; - // self->_lf__reaction_"+reactionCount+".status = inactive; - // self->_lf__reaction_"+reactionCount+".deadline = 0LL; - // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; - constructorCode.pr(reaction, String.join("\n", - "self->_lf__reaction_"+reactionCount+".number = "+reactionCount+";", - "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(decl, reactionCount)+";", - "self->_lf__reaction_"+reactionCount+".self = self;", - "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", - (reaction.eContainer() instanceof Mode ? - "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+reactor.getModes().indexOf((Mode) reaction.eContainer())+"];" : - "self->_lf__reaction_"+reactionCount+".mode = NULL;") - )); - // Increment the reactionCount even if the reaction is not in the federate - // so that reaction indices are consistent across federates. - reactionCount++; - } + return String.join( + "\n", + List.of("watchdog_t* " + watchdogName + " = &(self->_lf_watchdog_" + watchdogName + ");")); + } - // Next, create and initialize the trigger_t objects. - // Start with the timers. - for (Timer timer : ASTUtils.allTimers(reactor)) { - createTriggerT(body, timer, triggerMap, constructorCode, types); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); - constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+timer.getName()+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - } + /** + * Generate the fields of the self struct and statements for the constructor to create and + * initialize a reaction_t struct for each reaction in the specified reactor and a trigger_t + * struct for each trigger (input, action, timer, or output of a contained reactor). + * + * @param body The place to put the code for the self struct. + * @param decl The reactor. + * @param constructorCode The place to put the constructor code. + */ + public static void generateReactionAndTriggerStructs( + CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode, CTypes types) { + var reactionCount = 0; + var reactor = ASTUtils.toDefinition(decl); + // Iterate over reactions and create initialize the reaction_t struct + // on the self struct. Also, collect a map from triggers to the reactions + // that are triggered by that trigger. Also, collect a set of sources + // that are read by reactions but do not trigger reactions. + // Finally, collect a set of triggers and sources that are outputs + // of contained reactors. + var triggerMap = new LinkedHashMap>(); + var sourceSet = new LinkedHashSet(); + var outputsOfContainedReactors = new LinkedHashMap(); + var startupReactions = new LinkedHashSet(); + var shutdownReactions = new LinkedHashSet(); + var resetReactions = new LinkedHashSet(); + // WATCHDOG QUESTION: Why need to grab all reactions from reactor only to check + // if it exists in currentFederate? + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create the reaction_t struct. + body.pr(reaction, "reaction_t _lf__reaction_" + reactionCount + ";"); - // Handle builtin triggers. - if (startupReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); - } - // Handle shutdown triggers. - if (shutdownReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); + // Create the map of triggers to reactions. + for (TriggerRef trigger : reaction.getTriggers()) { + // trigger may not be a VarRef (it could be "startup" or "shutdown"). + if (trigger instanceof VarRef) { + var triggerAsVarRef = (VarRef) trigger; + var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); + if (reactionList == null) { + reactionList = new LinkedList<>(); + triggerMap.put(triggerAsVarRef.getVariable(), reactionList); + } + reactionList.add(reactionCount); + if (triggerAsVarRef.getContainer() != null) { + outputsOfContainedReactors.put( + triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); + } + } else if (trigger instanceof BuiltinTriggerRef) { + switch (((BuiltinTriggerRef) trigger).getType()) { + case STARTUP: + startupReactions.add(reactionCount); + break; + case SHUTDOWN: + shutdownReactions.add(reactionCount); + break; + case RESET: + resetReactions.add(reactionCount); + break; + } } - if (resetReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); + } + // Create the set of sources read but not triggering. + for (VarRef source : reaction.getSources()) { + sourceSet.add(source.getVariable()); + if (source.getContainer() != null) { + outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); } + } - // Next handle actions. - for (Action action : ASTUtils.allActions(reactor)) { - createTriggerT(body, action, triggerMap, constructorCode, types); - var isPhysical = "true"; - if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { - isPhysical = "false"; - } - var elementSize = "0"; - // If the action type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) - : null; - if (rootType != null && !rootType.equals("void")) { - elementSize = "sizeof(" + rootType + ")"; - } + var deadlineFunctionPointer = "NULL"; + if (reaction.getDeadline() != null) { + // The following has to match the name chosen in generateReactions + var deadlineFunctionName = generateDeadlineFunctionName(decl, reactionCount); + deadlineFunctionPointer = "&" + deadlineFunctionName; + } - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__"+action.getName()+".is_timer = false; - constructorCode.pr(String.join("\n", - "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", - (!(action.getPolicy() == null || action.getPolicy().isEmpty()) ? - "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" : - ""), - // Need to set the element_size in the trigger_t and the action struct. - "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize - + ";", - "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";" - )); - } - - // Next handle inputs. - for (Input input : ASTUtils.allInputs(reactor)) { - createTriggerT(body, input, triggerMap, constructorCode, types); - } + // Assign the STP handler + var STPFunctionPointer = "NULL"; + if (reaction.getStp() != null) { + // The following has to match the name chosen in generateReactions + var STPFunctionName = generateStpFunctionName(decl, reactionCount); + STPFunctionPointer = "&" + STPFunctionName; + } - // Next handle watchdogs. - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - createTriggerT(body, watchdog, triggerMap, constructorCode, types); - } + // Set the defaults of the reaction_t struct in the constructor. + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__reaction_"+reactionCount+".index = 0; + // self->_lf__reaction_"+reactionCount+".chain_id = 0; + // self->_lf__reaction_"+reactionCount+".pos = 0; + // self->_lf__reaction_"+reactionCount+".status = inactive; + // self->_lf__reaction_"+reactionCount+".deadline = 0LL; + // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; + constructorCode.pr( + reaction, + String.join( + "\n", + "self->_lf__reaction_" + reactionCount + ".number = " + reactionCount + ";", + "self->_lf__reaction_" + + reactionCount + + ".function = " + + CReactionGenerator.generateReactionFunctionName(decl, reactionCount) + + ";", + "self->_lf__reaction_" + reactionCount + ".self = self;", + "self->_lf__reaction_" + + reactionCount + + ".deadline_violation_handler = " + + deadlineFunctionPointer + + ";", + "self->_lf__reaction_" + reactionCount + ".STP_handler = " + STPFunctionPointer + ";", + "self->_lf__reaction_" + reactionCount + ".name = " + addDoubleQuotes("?") + ";", + (reaction.eContainer() instanceof Mode + ? "self->_lf__reaction_" + + reactionCount + + ".mode = &self->_lf__modes[" + + reactor.getModes().indexOf((Mode) reaction.eContainer()) + + "];" + : "self->_lf__reaction_" + reactionCount + ".mode = NULL;"))); + // Increment the reactionCount even if the reaction is not in the federate + // so that reaction indices are consistent across federates. + reactionCount++; } - /** - * Define the trigger_t object on the self struct, an array of - * reaction_t pointers pointing to reactions triggered by this variable, - * and initialize the pointers in the array in the constructor. - * @param body The place to write the self struct entries. - * @param variable The trigger variable (Timer, Watchdog, Action, or Input). - * @param triggerMap A map from Variables to a list of the reaction indices - * triggered by the variable. - * @param constructorCode The place to write the constructor code. - */ - private static void createTriggerT( - CodeBuilder body, - Variable variable, - LinkedHashMap> triggerMap, - CodeBuilder constructorCode, - CTypes types - ) { - var varName = variable.getName(); - // variable is a port, a timer, or an action. - body.pr(variable, "trigger_t _lf__"+varName+";"); - constructorCode.pr(variable, "self->_lf__"+varName+".last = NULL;"); - constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+varName+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - - // Generate the reactions triggered table. - var reactionsTriggered = triggerMap.get(variable); - if (reactionsTriggered != null) { - body.pr(variable, "reaction_t* _lf__"+varName+"_reactions["+reactionsTriggered.size()+"];"); - var count = 0; - for (Integer reactionTriggered : reactionsTriggered) { - constructorCode.prSourceLineNumber(variable); - constructorCode.pr(variable, "self->_lf__"+varName+"_reactions["+count+"] = &self->_lf__reaction_"+reactionTriggered+";"); - count++; - } - // Set up the trigger_t struct's pointer to the reactions. - constructorCode.pr(variable, String.join("\n", - "self->_lf__"+varName+".reactions = &self->_lf__"+varName+"_reactions[0];", - "self->_lf__"+varName+".number_of_reactions = "+count+";" - )); - - // If federated, set the physical_time_of_arrival - constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederated( - "self->_lf__"+varName+".physical_time_of_arrival = NEVER;")); - } - if (variable instanceof Input) { - var rootType = CUtil.rootType(types.getTargetType((Input) variable)); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - // If the input type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; - - constructorCode.pr("self->_lf__"+varName+".tmplt.type.element_size = "+size+";"); - body.pr( - CExtensionUtils.surroundWithIfFederated( - CExtensionUtils.createPortStatusFieldForInput((Input) variable) - ) - ); - } + // Next, create and initialize the trigger_t objects. + // Start with the timers. + for (Timer timer : ASTUtils.allTimers(reactor)) { + createTriggerT(body, timer, triggerMap, constructorCode, types); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + constructorCode.pr("self->_lf__" + timer.getName() + ".is_timer = true;"); + constructorCode.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + + timer.getName() + + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); } - public static void generateBuiltinTriggeredReactionsArray( - Set reactions, - String name, - CodeBuilder body, - CodeBuilder constructorCode - ) { - body.pr(String.join("\n", - "trigger_t _lf__"+name+";", - "reaction_t* _lf__"+name+"_reactions["+reactions.size()+"];" - )); - constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+name+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - var i = 0; - for (Integer reactionIndex : reactions) { - constructorCode.pr("self->_lf__"+name+"_reactions["+i+++"] = &self->_lf__reaction_"+reactionIndex+";"); - } - constructorCode.pr(String.join("\n", - "self->_lf__"+name+".last = NULL;", - "self->_lf__"+name+".reactions = &self->_lf__"+name+"_reactions[0];", - "self->_lf__"+name+".number_of_reactions = "+reactions.size()+";", - "self->_lf__"+name+".is_timer = false;" - )); + // Handle builtin triggers. + if (startupReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); } - - public static String generateBuiltinTriggersTable(int reactionCount, String name) { - return String.join("\n", List.of( - "// Array of pointers to "+name+" triggers.", - (reactionCount > 0 ? - "reaction_t* _lf_"+name+"_reactions["+reactionCount+"]" : - "reaction_t** _lf_"+name+"_reactions = NULL") + ";", - "int _lf_"+name+"_reactions_size = "+reactionCount+";" - )); + // Handle shutdown triggers. + if (shutdownReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); + } + if (resetReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); } - /** - * Generate the _lf_trigger_startup_reactions function. - */ - public static String generateLfTriggerStartupReactions(int startupReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("void _lf_trigger_startup_reactions() {"); - if (startupReactionCount > 0) { - s.append("\n"); - if (hasModalReactors) { - s.append(String.join("\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " if (_lf_startup_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_startup_reset_reactions(", - " _lf_startup_reactions, _lf_startup_reactions_size,", - " NULL, 0,", - " _lf_modal_reactor_states, _lf_modal_reactor_states_size);" - )); - } else { - s.append(String.join("\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }" - )); - } - s.append("\n"); - } - s.append("}\n"); - return s.toString(); + // Next handle actions. + for (Action action : ASTUtils.allActions(reactor)) { + createTriggerT(body, action, triggerMap, constructorCode, types); + var isPhysical = "true"; + if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { + isPhysical = "false"; + } + var elementSize = "0"; + // If the action type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) : null; + if (rootType != null && !rootType.equals("void")) { + elementSize = "sizeof(" + rootType + ")"; + } + + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__"+action.getName()+".is_timer = false; + constructorCode.pr( + String.join( + "\n", + "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", + (!(action.getPolicy() == null || action.getPolicy().isEmpty()) + ? "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" + : ""), + // Need to set the element_size in the trigger_t and the action struct. + "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize + ";", + "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";")); } - /** - * Generate the _lf_trigger_shutdown_reactions function. - */ - public static String generateLfTriggerShutdownReactions(int shutdownReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("bool _lf_trigger_shutdown_reactions() {\n"); - if (shutdownReactionCount > 0) { - if (hasModalReactors) { - s.append(String.join("\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " if (_lf_shutdown_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions, _lf_shutdown_reactions_size);", - " return true;" - )); - } else { - s.append(String.join("\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " return true;" - )); - } - s.append("\n"); - } else { - s.append(" return false;\n"); - } - s.append("}\n"); - return s.toString(); + // Next handle inputs. + for (Input input : ASTUtils.allInputs(reactor)) { + createTriggerT(body, input, triggerMap, constructorCode, types); } - /** - * Generate the _lf_handle_mode_triggered_reactions function. - */ - public static String generateLfModeTriggeredReactions( - int startupReactionCount, - int resetReactionCount, - boolean hasModalReactors - ) { - if (!hasModalReactors) { - return ""; - } - var s = new StringBuilder(); - s.append("void _lf_handle_mode_triggered_reactions() {\n"); - s.append(" _lf_handle_mode_startup_reset_reactions(\n"); - if (startupReactionCount > 0) { - s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - if (resetReactionCount > 0) { - s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); - s.append("}\n"); - return s.toString(); + // Next handle watchdogs. + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + createTriggerT(body, watchdog, triggerMap, constructorCode, types); } + } - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param decl The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - public static String generateReaction( - Reaction reaction, - ReactorDecl decl, - int reactionIndex, - Instantiation mainDef, - ErrorReporter errorReporter, - CTypes types, - TargetConfig targetConfig, - boolean requiresType - ) { - var code = new CodeBuilder(); - var body = ASTUtils.toText(reaction.getCode()); - String init = generateInitializationForReaction( - body, reaction, decl, reactionIndex, - types, errorReporter, mainDef, - requiresType); - - String srcPrefix = targetConfig.platformOptions.platform == Platform.ARDUINO ? "src/" : ""; - code.pr( - "#include " + StringUtil.addDoubleQuotes( - srcPrefix + CCoreFilesUtils.getCTargetSetHeader())); - - CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(decl), code); - code.pr(generateFunction( - generateReactionFunctionHeader(decl, reactionIndex), - init, reaction.getCode() - )); - // Now generate code for the late function, if there is one - // Note that this function can only be defined on reactions - // in federates that have inputs from a logical connection. - if (reaction.getStp() != null) { - code.pr(generateFunction( - generateStpFunctionHeader(decl, reactionIndex), - init, reaction.getStp().getCode())); - } + /** + * Define the trigger_t object on the self struct, an array of reaction_t pointers pointing to + * reactions triggered by this variable, and initialize the pointers in the array in the + * constructor. + * + * @param body The place to write the self struct entries. + * @param variable The trigger variable (Timer, Watchdog, Action, or Input). + * @param triggerMap A map from Variables to a list of the reaction indices triggered by the + * variable. + * @param constructorCode The place to write the constructor code. + */ + private static void createTriggerT( + CodeBuilder body, + Variable variable, + LinkedHashMap> triggerMap, + CodeBuilder constructorCode, + CTypes types) { + var varName = variable.getName(); + // variable is a port, a timer, or an action. + body.pr(variable, "trigger_t _lf__" + varName + ";"); + constructorCode.pr(variable, "self->_lf__" + varName + ".last = NULL;"); + constructorCode.pr( + variable, + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + + varName + + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - // Now generate code for the deadline violation function, if there is one. - if (reaction.getDeadline() != null) { - code.pr(generateFunction( - generateDeadlineFunctionHeader(decl, reactionIndex), - init, reaction.getDeadline().getCode())); - } + // Generate the reactions triggered table. + var reactionsTriggered = triggerMap.get(variable); + if (reactionsTriggered != null) { + body.pr( + variable, + "reaction_t* _lf__" + varName + "_reactions[" + reactionsTriggered.size() + "];"); + var count = 0; + for (Integer reactionTriggered : reactionsTriggered) { + constructorCode.prSourceLineNumber(variable); + constructorCode.pr( + variable, + "self->_lf__" + + varName + + "_reactions[" + + count + + "] = &self->_lf__reaction_" + + reactionTriggered + + ";"); + count++; + } + // Set up the trigger_t struct's pointer to the reactions. + constructorCode.pr( + variable, + String.join( + "\n", + "self->_lf__" + varName + ".reactions = &self->_lf__" + varName + "_reactions[0];", + "self->_lf__" + varName + ".number_of_reactions = " + count + ";")); - CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(decl), code); - code.pr( - "#include " + StringUtil.addDoubleQuotes( - srcPrefix + CCoreFilesUtils.getCTargetSetUndefHeader())); - return code.toString(); + // If federated, set the physical_time_of_arrival + constructorCode.pr( + variable, + CExtensionUtils.surroundWithIfFederated( + "self->_lf__" + varName + ".physical_time_of_arrival = NEVER;")); } + if (variable instanceof Input) { + var rootType = CUtil.rootType(types.getTargetType((Input) variable)); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + // If the input type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; - public static String generateFunction(String header, String init, Code code) { - var function = new CodeBuilder(); - function.pr(header + " {"); - function.indent(); - function.pr(init); - function.prSourceLineNumber(code); - function.pr(ASTUtils.toText(code)); - function.unindent(); - function.pr("}"); - return function.toString(); + constructorCode.pr("self->_lf__" + varName + ".tmplt.type.element_size = " + size + ";"); + body.pr( + CExtensionUtils.surroundWithIfFederated( + CExtensionUtils.createPortStatusFieldForInput((Input) variable))); } + } - /** - * Returns the name of the deadline function for reaction. - * @param decl The reactor with the deadline - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateDeadlineFunctionName(ReactorDecl decl, int reactionIndex) { - return CUtil.getName(decl).toLowerCase() + "_deadline_function" + reactionIndex; + public static void generateBuiltinTriggeredReactionsArray( + Set reactions, String name, CodeBuilder body, CodeBuilder constructorCode) { + body.pr( + String.join( + "\n", + "trigger_t _lf__" + name + ";", + "reaction_t* _lf__" + name + "_reactions[" + reactions.size() + "];")); + constructorCode.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + name + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + var i = 0; + for (Integer reactionIndex : reactions) { + constructorCode.pr( + "self->_lf__" + + name + + "_reactions[" + + i++ + + "] = &self->_lf__reaction_" + + reactionIndex + + ";"); } + constructorCode.pr( + String.join( + "\n", + "self->_lf__" + name + ".last = NULL;", + "self->_lf__" + name + ".reactions = &self->_lf__" + name + "_reactions[0];", + "self->_lf__" + name + ".number_of_reactions = " + reactions.size() + ";", + "self->_lf__" + name + ".is_timer = false;")); + } - /** - * Return the function name for specified reaction of the - * specified reactor. - * @param reactor The reactor - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionName(ReactorDecl reactor, int reactionIndex) { - return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; - } + public static String generateBuiltinTriggersTable(int reactionCount, String name) { + return String.join( + "\n", + List.of( + "// Array of pointers to " + name + " triggers.", + (reactionCount > 0 + ? "reaction_t* _lf_" + name + "_reactions[" + reactionCount + "]" + : "reaction_t** _lf_" + name + "_reactions = NULL") + + ";", + "int _lf_" + name + "_reactions_size = " + reactionCount + ";")); + } - /** - * Returns the name of the stp function for reaction. - * @param decl The reactor with the stp - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateStpFunctionName(ReactorDecl decl, int reactionIndex) { - return CUtil.getName(decl).toLowerCase() + "_STP_function" + reactionIndex; + /** Generate the _lf_trigger_startup_reactions function. */ + public static String generateLfTriggerStartupReactions( + int startupReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("void _lf_trigger_startup_reactions() {"); + if (startupReactionCount > 0) { + s.append("\n"); + if (hasModalReactors) { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " if (_lf_startup_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_startup_reset_reactions(", + " _lf_startup_reactions, _lf_startup_reactions_size,", + " NULL, 0,", + " _lf_modal_reactor_states, _lf_modal_reactor_states_size);")); + } else { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }")); + } + s.append("\n"); } + s.append("}\n"); + return s.toString(); + } - /** Return the top level C function header for the deadline function numbered "reactionIndex" in "decl" - * @param decl The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the deadline function. - */ - public static String generateDeadlineFunctionHeader(ReactorDecl decl, - int reactionIndex) { - String functionName = generateDeadlineFunctionName(decl, reactionIndex); - return generateFunctionHeader(functionName); + /** Generate the _lf_trigger_shutdown_reactions function. */ + public static String generateLfTriggerShutdownReactions( + int shutdownReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("bool _lf_trigger_shutdown_reactions() {\n"); + if (shutdownReactionCount > 0) { + if (hasModalReactors) { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " if (_lf_shutdown_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions," + + " _lf_shutdown_reactions_size);", + " return true;")); + } else { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " return true;")); + } + s.append("\n"); + } else { + s.append(" return false;\n"); } + s.append("}\n"); + return s.toString(); + } - /** Return the top level C function header for the reaction numbered "reactionIndex" in "decl" - * @param decl The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionHeader(ReactorDecl decl, - int reactionIndex) { - String functionName = generateReactionFunctionName(decl, reactionIndex); - return generateFunctionHeader(functionName); + /** Generate the _lf_handle_mode_triggered_reactions function. */ + public static String generateLfModeTriggeredReactions( + int startupReactionCount, int resetReactionCount, boolean hasModalReactors) { + if (!hasModalReactors) { + return ""; + } + var s = new StringBuilder(); + s.append("void _lf_handle_mode_triggered_reactions() {\n"); + s.append(" _lf_handle_mode_startup_reset_reactions(\n"); + if (startupReactionCount > 0) { + s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); } + if (resetReactionCount > 0) { + s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); + } + s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); + s.append("}\n"); + return s.toString(); + } + + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param decl The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + public static String generateReaction( + Reaction reaction, + ReactorDecl decl, + int reactionIndex, + Instantiation mainDef, + ErrorReporter errorReporter, + CTypes types, + TargetConfig targetConfig, + boolean requiresType) { + var code = new CodeBuilder(); + var body = ASTUtils.toText(reaction.getCode()); + String init = + generateInitializationForReaction( + body, reaction, decl, reactionIndex, types, errorReporter, mainDef, requiresType); + + String srcPrefix = targetConfig.platformOptions.platform == Platform.ARDUINO ? "src/" : ""; + code.pr( + "#include " + + StringUtil.addDoubleQuotes(srcPrefix + CCoreFilesUtils.getCTargetSetHeader())); - public static String generateStpFunctionHeader(ReactorDecl decl, - int reactionIndex) { - String functionName = generateStpFunctionName(decl, reactionIndex); - return generateFunctionHeader(functionName); + CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(decl), code); + code.pr( + generateFunction( + generateReactionFunctionHeader(decl, reactionIndex), init, reaction.getCode())); + // Now generate code for the late function, if there is one + // Note that this function can only be defined on reactions + // in federates that have inputs from a logical connection. + if (reaction.getStp() != null) { + code.pr( + generateFunction( + generateStpFunctionHeader(decl, reactionIndex), init, reaction.getStp().getCode())); } - public static String generateFunctionHeader(String functionName) { - return "void " + functionName + "(void* instance_args)"; + // Now generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr( + generateFunction( + generateDeadlineFunctionHeader(decl, reactionIndex), + init, + reaction.getDeadline().getCode())); } + + CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(decl), code); + code.pr( + "#include " + + StringUtil.addDoubleQuotes(srcPrefix + CCoreFilesUtils.getCTargetSetUndefHeader())); + return code.toString(); + } + + public static String generateFunction(String header, String init, Code code) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(code); + function.pr(ASTUtils.toText(code)); + function.unindent(); + function.pr("}"); + return function.toString(); + } + + /** + * Returns the name of the deadline function for reaction. + * + * @param decl The reactor with the deadline + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateDeadlineFunctionName(ReactorDecl decl, int reactionIndex) { + return CUtil.getName(decl).toLowerCase() + "_deadline_function" + reactionIndex; + } + + /** + * Return the function name for specified reaction of the specified reactor. + * + * @param reactor The reactor + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionName(ReactorDecl reactor, int reactionIndex) { + return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; + } + + /** + * Returns the name of the stp function for reaction. + * + * @param decl The reactor with the stp + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateStpFunctionName(ReactorDecl decl, int reactionIndex) { + return CUtil.getName(decl).toLowerCase() + "_STP_function" + reactionIndex; + } + + /** + * Return the top level C function header for the deadline function numbered "reactionIndex" in + * "decl" + * + * @param decl The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the deadline function. + */ + public static String generateDeadlineFunctionHeader(ReactorDecl decl, int reactionIndex) { + String functionName = generateDeadlineFunctionName(decl, reactionIndex); + return generateFunctionHeader(functionName); + } + + /** + * Return the top level C function header for the reaction numbered "reactionIndex" in "decl" + * + * @param decl The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionHeader(ReactorDecl decl, int reactionIndex) { + String functionName = generateReactionFunctionName(decl, reactionIndex); + return generateFunctionHeader(functionName); + } + + public static String generateStpFunctionHeader(ReactorDecl decl, int reactionIndex) { + String functionName = generateStpFunctionName(decl, reactionIndex); + return generateFunctionHeader(functionName); + } + + public static String generateFunctionHeader(String functionName) { + return "void " + functionName + "(void* instance_args)"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 9163883962..6ad7f405eb 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -1,19 +1,14 @@ package org.lflang.generator.c; +import java.util.List; import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; +import org.lflang.lf.Mode; +import org.lflang.lf.ModeTransition; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; - -import org.lflang.lf.Reactor; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; -import org.lflang.lf.Mode; -import org.lflang.lf.ModeTransition; -import org.lflang.lf.Watchdog; -import org.lflang.generator.GeneratorBase; -import org.lflang.generator.c.CReactionGenerator; -import java.util.List; import org.lflang.lf.Watchdog; /** @@ -21,202 +16,223 @@ * * @author{Benjamin Asch } */ - public class CWatchdogGenerator { - /** - * Generate necessary initialization code inside the body of the watchdog that belongs to reactor decl. - * @param decl The reactor that has the watchdog - */ - public static String generateInitializationForWatchdog(Watchdog watchdog, - ReactorDecl decl) { - Reactor reactor = ASTUtils.toDefinition(decl); - - // Construct the reactionInitialization code to go into - // the body of the function before the verbatim code. - CodeBuilder watchdogInitialization = new CodeBuilder(); - - CodeBuilder code = new CodeBuilder(); - - // Define the "self" struct. - String structType = CUtil.selfType(decl); - // A null structType means there are no inputs, state, - // or anything else. No need to declare it. - if (structType != null) { - code.pr(String.join("\n", - structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" - )); - } - - // Declare mode if in effects field of watchdog - if (watchdog.getEffects() != null) { - for (VarRef effect : watchdog.getEffects()) { - Variable variable = effect.getVariable(); - if (variable instanceof Mode) { - // Mode change effect - int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); - String name = effect.getVariable().getName(); - if (idx >= 0) { - watchdogInitialization.pr( - "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" - + "lf_mode_change_type_t _lf_" + name + "_change_type = " - + (effect.getTransition() == ModeTransition.HISTORY ? - "history_transition" : "reset_transition") - + ";" - ); - } - // FIXME: include error reporter - // else { - // errorReporter.reportError( - // watchdog, - // "In generateWatchdog(): " + name + " not a valid mode of this reactor." - // ); - // } - } - } - } - // Add watchdog definition - watchdogInitialization.pr("watchdog_t* "+watchdog.getName()+" = &(self->_lf_watchdog_"+watchdog.getName()+");\n"); - - // Next generate all the collected setup code. - code.pr(watchdogInitialization.toString()); - return code.toString(); + /** + * Generate necessary initialization code inside the body of the watchdog that belongs to reactor + * decl. + * + * @param decl The reactor that has the watchdog + */ + public static String generateInitializationForWatchdog(Watchdog watchdog, ReactorDecl decl) { + Reactor reactor = ASTUtils.toDefinition(decl); + + // Construct the reactionInitialization code to go into + // the body of the function before the verbatim code. + CodeBuilder watchdogInitialization = new CodeBuilder(); + + CodeBuilder code = new CodeBuilder(); + + // Define the "self" struct. + String structType = CUtil.selfType(decl); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr( + String.join( + "\n", + structType + + "* self = (" + + structType + + "*)instance_args; SUPPRESS_UNUSED_WARNING(self);")); } - /** - * Returns the name of the watchdog function for reaction. - * @param decl The reactor with the watchdog - * @param watchdog The watchdog - * @return Name of the watchdog function for reaction - */ - public static String generateWatchdogFunctionName(Watchdog watchdog, ReactorDecl decl) { - return decl.getName().toLowerCase() + "_" + watchdog.getName().toLowerCase() + "_watchdog_function"; - } - - /** Return the top level C function header for the watchdog function in "decl" - * @param decl The reactor declaration - * @param watchdog The watchdog. - * @return The function name for the watchdog function. - */ - public static String generateWatchdogFunctionHeader(Watchdog watchdog, - ReactorDecl decl) { - String functionName = generateWatchdogFunctionName(watchdog, decl); - return CReactionGenerator.generateFunctionHeader(functionName); - } - - /** - * Generate the watchdog function. - */ - public static String generateWatchdogFunction(Watchdog watchdog, - ReactorDecl decl) { - return generateFunction(generateWatchdogFunctionHeader(watchdog, decl), - generateInitializationForWatchdog(watchdog, decl), - watchdog); - } - - /** - * Do heavy lifting to generate above watchdog function - * @param header function name and declaration. - * @param init initialize variable. - * @param watchdog The watchdog. - */ - public static String generateFunction(String header, String init, Watchdog watchdog) { - var function = new CodeBuilder(); - function.pr(header + " {"); - function.indent(); - function.pr(init);function.pr("_lf_schedule((*"+watchdog.getName()+").trigger, 0, NULL);"); - function.prSourceLineNumber(watchdog.getCode()); - function.pr(ASTUtils.toText(watchdog.getCode())); - function.unindent(); - function.pr("}"); - return function.toString(); - } - - - /** - * Generate watchdog definition in parent struct. - */ - public static void generateWatchdogStruct( - CodeBuilder body, - ReactorDecl decl, - CodeBuilder constructorCode - ) { - var reactor = ASTUtils.toDefinition(decl); - - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - String watchdogName = watchdog.getName(); - - body.pr(watchdog, "watchdog_t _lf_watchdog_"+watchdogName+";"); - - // watchdog function name - var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); - // Set values of watchdog_t struct in the reactor's constructor - //FIXME: update parameters - // constructorCode.pr("#ifdef LF_THREADED"); - constructorCode.pr(watchdog, String.join("\n", - "self->_lf_watchdog_"+watchdogName+".base = &(self->base);", - "self->_lf_watchdog_"+watchdogName+".expiration = NEVER;", - "self->_lf_watchdog_"+watchdogName+".thread_active = false;", - // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", - "self->_lf_watchdog_"+watchdogName+".watchdog_function = "+watchdogFunctionName+";", - "self->_lf_watchdog_"+watchdogName+".trigger = &(self->_lf__"+watchdogName+");" - )); - - + // Declare mode if in effects field of watchdog + if (watchdog.getEffects() != null) { + for (VarRef effect : watchdog.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(reactor).indexOf((Mode) effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + watchdogInitialization.pr( + "reactor_mode_t* " + + name + + " = &self->_lf__modes[" + + idx + + "];\n" + + "lf_mode_change_type_t _lf_" + + name + + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY + ? "history_transition" + : "reset_transition") + + ";"); + } + // FIXME: include error reporter + // else { + // errorReporter.reportError( + // watchdog, + // "In generateWatchdog(): " + name + " not a valid mode of this reactor." + // ); + // } } + } } - - /** Generate a watchdog function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param watchdog The watchdog. - * @param decl The reactor. - */ - public static String generateWatchdog( - Watchdog watchdog, - ReactorDecl decl - ) { - var code = new CodeBuilder(); - - code.pr(generateWatchdogFunction(watchdog, decl)); - - return code.toString(); + // Add watchdog definition + watchdogInitialization.pr( + "watchdog_t* " + + watchdog.getName() + + " = &(self->_lf_watchdog_" + + watchdog.getName() + + ");\n"); + + // Next generate all the collected setup code. + code.pr(watchdogInitialization.toString()); + return code.toString(); + } + + /** + * Returns the name of the watchdog function for reaction. + * + * @param decl The reactor with the watchdog + * @param watchdog The watchdog + * @return Name of the watchdog function for reaction + */ + public static String generateWatchdogFunctionName(Watchdog watchdog, ReactorDecl decl) { + return decl.getName().toLowerCase() + + "_" + + watchdog.getName().toLowerCase() + + "_watchdog_function"; + } + + /** + * Return the top level C function header for the watchdog function in "decl" + * + * @param decl The reactor declaration + * @param watchdog The watchdog. + * @return The function name for the watchdog function. + */ + public static String generateWatchdogFunctionHeader(Watchdog watchdog, ReactorDecl decl) { + String functionName = generateWatchdogFunctionName(watchdog, decl); + return CReactionGenerator.generateFunctionHeader(functionName); + } + + /** Generate the watchdog function. */ + public static String generateWatchdogFunction(Watchdog watchdog, ReactorDecl decl) { + return generateFunction( + generateWatchdogFunctionHeader(watchdog, decl), + generateInitializationForWatchdog(watchdog, decl), + watchdog); + } + + /** + * Do heavy lifting to generate above watchdog function + * + * @param header function name and declaration. + * @param init initialize variable. + * @param watchdog The watchdog. + */ + public static String generateFunction(String header, String init, Watchdog watchdog) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.pr("_lf_schedule((*" + watchdog.getName() + ").trigger, 0, NULL);"); + function.prSourceLineNumber(watchdog.getCode()); + function.pr(ASTUtils.toText(watchdog.getCode())); + function.unindent(); + function.pr("}"); + return function.toString(); + } + + /** Generate watchdog definition in parent struct. */ + public static void generateWatchdogStruct( + CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = ASTUtils.toDefinition(decl); + + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + String watchdogName = watchdog.getName(); + + body.pr(watchdog, "watchdog_t _lf_watchdog_" + watchdogName + ";"); + + // watchdog function name + var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); + // Set values of watchdog_t struct in the reactor's constructor + // FIXME: update parameters + // constructorCode.pr("#ifdef LF_THREADED"); + constructorCode.pr( + watchdog, + String.join( + "\n", + "self->_lf_watchdog_" + watchdogName + ".base = &(self->base);", + "self->_lf_watchdog_" + watchdogName + ".expiration = NEVER;", + "self->_lf_watchdog_" + watchdogName + ".thread_active = false;", + // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", + "self->_lf_watchdog_" + + watchdogName + + ".watchdog_function = " + + watchdogFunctionName + + ";", + "self->_lf_watchdog_" + + watchdogName + + ".trigger = &(self->_lf__" + + watchdogName + + ");")); } - - public static String generateBuiltinTriggersTable(int count, String name) { - return String.join("\n", List.of( - "// Array of pointers to "+name+" triggers.", + } + + /** + * Generate a watchdog function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param watchdog The watchdog. + * @param decl The reactor. + */ + public static String generateWatchdog(Watchdog watchdog, ReactorDecl decl) { + var code = new CodeBuilder(); + + code.pr(generateWatchdogFunction(watchdog, decl)); + + return code.toString(); + } + + public static String generateBuiltinTriggersTable(int count, String name) { + return String.join( + "\n", + List.of( + "// Array of pointers to " + name + " triggers.", "#ifdef LF_THREADED", - (count > 0 ? - " watchdog_t* _lf_"+name+"s["+count+"]" : - " watchdog_t* _lf_"+name+"s = NULL") + ";", - " int _lf_"+name+"_number = "+count+";", - "#endif" - )); - } - - /** - * Generate _lf_initialize_watchdog_mutexes function. - */ - //FIXME: finish implementing - public static String generateLfInitializeWatchdogMutexes(int watchdogCount) { - var s = new StringBuilder(); - s.append("void _lf_initialize_watchdog_mutexes() {"); - if (watchdogCount > 0) { - s.append("\n"); - s.append(String.join("\n", - " for (int i = 0; i < _lf_watchdog_number; i++) {", - " self_base_t* current_base = _lf_watchdogs[i]->base;", - " if (&(current_base->watchdog_mutex) == NULL) {", - " lf_mutex_init(&(current_base->watchdog_mutex));", - " current_base->has_watchdog = true;", - " }", - " }" - )); - } - s.append("\n"); - s.append("}\n"); - return s.toString(); + (count > 0 + ? " watchdog_t* _lf_" + name + "s[" + count + "]" + : " watchdog_t* _lf_" + name + "s = NULL") + + ";", + " int _lf_" + name + "_number = " + count + ";", + "#endif")); + } + + /** Generate _lf_initialize_watchdog_mutexes function. */ + // FIXME: finish implementing + public static String generateLfInitializeWatchdogMutexes(int watchdogCount) { + var s = new StringBuilder(); + s.append("void _lf_initialize_watchdog_mutexes() {"); + if (watchdogCount > 0) { + s.append("\n"); + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_watchdog_number; i++) {", + " self_base_t* current_base = _lf_watchdogs[i]->base;", + " if (&(current_base->watchdog_mutex) == NULL) {", + " lf_mutex_init(&(current_base->watchdog_mutex));", + " current_base->has_watchdog = true;", + " }", + " }")); } + s.append("\n"); + s.append("}\n"); + return s.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 2767a05b9c..442afd79f3 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -34,17 +34,14 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; - import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.generator.CodeBuilder; import org.lflang.generator.CodeMap; - import org.lflang.generator.GeneratorResult; import org.lflang.generator.IntegratedBuilder; import org.lflang.generator.LFGeneratorContext; @@ -62,541 +59,517 @@ import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; -import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; - /** - * Generator for Python target. This class generates Python code defining each - * reactor - * class given in the input .lf file and imported .lf files. + * Generator for Python target. This class generates Python code defining each reactor class given + * in the input .lf file and imported .lf files. * - * Each class will contain all the reaction functions defined by the user in - * order, with the necessary ports/actions given as parameters. - * Moreover, each class will contain all state variables in native Python - * format. + *

Each class will contain all the reaction functions defined by the user in order, with the + * necessary ports/actions given as parameters. Moreover, each class will contain all state + * variables in native Python format. * - * A backend is also generated using the CGenerator that interacts with the C - * code library (see CGenerator.xtend). - * The backend is responsible for passing arguments to the Python reactor + *

A backend is also generated using the CGenerator that interacts with the C code library (see + * CGenerator.xtend). The backend is responsible for passing arguments to the Python reactor * functions. * * @author Soroush Bateni */ public class PythonGenerator extends CGenerator { - // Used to add statements that come before reactor classes and user code - private final CodeBuilder pythonPreamble = new CodeBuilder(); - - // Used to add module requirements to setup.py (delimited with ,) - private final List pythonRequiredModules = new ArrayList<>(); - - private final PythonTypes types; - - public PythonGenerator(LFGeneratorContext context) { - this(context, - new PythonTypes(), - new CCmakeGenerator( - context.getFileConfig(), - List.of("lib/python_action.c", - "lib/python_port.c", - "lib/python_tag.c", - "lib/python_time.c", - "lib/pythontarget.c" - ), - PythonGenerator::setUpMainTarget, - "install(TARGETS)" // No-op - ) - ); - } - - - private PythonGenerator(LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { - super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); - this.targetConfig.compiler = "gcc"; - this.targetConfig.compilerFlags = new ArrayList<>(); - this.targetConfig.linkerFlags = ""; - this.types = types; - } - - /** - * Generic struct for ports with primitive types and - * statically allocated arrays in Lingua Franca. - * This template is defined as - * typedef struct { - * bool is_present; - * lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record. - * int destination_channel; // -1 if there is no destination. - * PyObject* value; - * int num_destinations; - * lf_token_t* token; - * int length; - * void (*destructor) (void* value); - * void* (*copy_constructor) (void* value); - * FEDERATED_GENERIC_EXTENSION - * } generic_port_instance_struct; - * - * See reactor-c-py/lib/pythontarget.h for details. - */ - String genericPortType = "generic_port_instance_struct"; - - /** - * Generic struct for actions. - * This template is defined as - * typedef struct { - * trigger_t* trigger; - * PyObject* value; - * bool is_present; - * bool has_value; - * lf_token_t* token; - * FEDERATED_CAPSULE_EXTENSION - * } generic_action_instance_struct; - * - * See reactor-c-py/lib/pythontarget.h for details. - */ - String genericActionType = "generic_action_instance_struct"; - - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.Python; + // Used to add statements that come before reactor classes and user code + private final CodeBuilder pythonPreamble = new CodeBuilder(); + + // Used to add module requirements to setup.py (delimited with ,) + private final List pythonRequiredModules = new ArrayList<>(); + + private final PythonTypes types; + + public PythonGenerator(LFGeneratorContext context) { + this( + context, + new PythonTypes(), + new CCmakeGenerator( + context.getFileConfig(), + List.of( + "lib/python_action.c", + "lib/python_port.c", + "lib/python_tag.c", + "lib/python_time.c", + "lib/pythontarget.c"), + PythonGenerator::setUpMainTarget, + "install(TARGETS)" // No-op + )); + } + + private PythonGenerator( + LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { + super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); + this.targetConfig.compiler = "gcc"; + this.targetConfig.compilerFlags = new ArrayList<>(); + this.targetConfig.linkerFlags = ""; + this.types = types; + } + + /** + * Generic struct for ports with primitive types and statically allocated arrays in Lingua Franca. + * This template is defined as typedef struct { bool is_present; lf_sparse_io_record_t* + * sparse_record; // NULL if there is no sparse record. int destination_channel; // -1 if there is + * no destination. PyObject* value; int num_destinations; lf_token_t* token; int length; void + * (*destructor) (void* value); void* (*copy_constructor) (void* value); + * FEDERATED_GENERIC_EXTENSION } generic_port_instance_struct; + * + *

See reactor-c-py/lib/pythontarget.h for details. + */ + String genericPortType = "generic_port_instance_struct"; + + /** + * Generic struct for actions. This template is defined as typedef struct { trigger_t* trigger; + * PyObject* value; bool is_present; bool has_value; lf_token_t* token; + * FEDERATED_CAPSULE_EXTENSION } generic_action_instance_struct; + * + *

See reactor-c-py/lib/pythontarget.h for details. + */ + String genericActionType = "generic_action_instance_struct"; + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.Python; + } + + private final Set protoNames = new HashSet<>(); + + // ////////////////////////////////////////// + // // Public methods + @Override + public TargetTypes getTargetTypes() { + return types; + } + + // ////////////////////////////////////////// + // // Protected methods + + /** Generate all Python classes if they have a reaction */ + public String generatePythonReactorClasses() { + CodeBuilder pythonClasses = new CodeBuilder(); + CodeBuilder pythonClassesInstantiation = new CodeBuilder(); + + // Generate reactor classes in Python + pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); + + // Create empty lists to hold reactor instances + pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); + + // Instantiate generated classes + pythonClassesInstantiation.pr( + PythonReactorGenerator.generatePythonClassInstantiations(main, main)); + + return String.join( + "\n", + pythonClasses.toString(), + "", + "# Instantiate classes", + pythonClassesInstantiation.toString()); + } + + /** + * Generate the Python code constructed from reactor classes and user-written classes. + * + * @return the code body + */ + public String generatePythonCode(String pyModuleName) { + return String.join( + "\n", + "import os", + "import sys", + "sys.path.append(os.path.dirname(__file__))", + "# List imported names, but do not use pylint's --extension-pkg-allow-list option", + "# so that these names will be assumed present without having to compile and install.", + "# pylint: disable=no-name-in-module, import-error", + "from " + pyModuleName + " import (", + " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", + ")", + "# pylint: disable=c-extension-no-member", + "import " + pyModuleName + " as lf", + "try:", + " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", + " from LinguaFrancaBase.functions import (", + " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS," + + " USEC,", + " USECS, WEEK, WEEKS", + " )", + " from LinguaFrancaBase.classes import Make", + "except ModuleNotFoundError:", + " print(\"No module named 'LinguaFrancaBase'. \"", + " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", + " sys.exit(1)", + "import copy", + "", + pythonPreamble.toString(), + "", + generatePythonReactorClasses(), + "", + PythonMainFunctionGenerator.generateCode()); + } + + /** Generate the necessary Python files. */ + public Map generatePythonFiles( + String lfModuleName, String pyModuleName, String pyFileName) throws IOException { + Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); + File file = filePath.toFile(); + Files.deleteIfExists(filePath); + // Create the necessary directories + if (!file.getParentFile().exists()) { + if (!file.getParentFile().mkdirs()) { + throw new IOException( + "Failed to create directories required for the Python code generator."); + } } - - private final Set protoNames = new HashSet<>(); - - // ////////////////////////////////////////// - // // Public methods - @Override - public TargetTypes getTargetTypes() { - return types; - } - - // ////////////////////////////////////////// - // // Protected methods - - /** - * Generate all Python classes if they have a reaction - * - */ - public String generatePythonReactorClasses() { - CodeBuilder pythonClasses = new CodeBuilder(); - CodeBuilder pythonClassesInstantiation = new CodeBuilder(); - - // Generate reactor classes in Python - pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); - - // Create empty lists to hold reactor instances - pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); - - // Instantiate generated classes - pythonClassesInstantiation.pr(PythonReactorGenerator.generatePythonClassInstantiations(main, main)); - - return String.join("\n", - pythonClasses.toString(), - "", - "# Instantiate classes", - pythonClassesInstantiation.toString() - ); - } - - /** - * Generate the Python code constructed from reactor classes and - * user-written classes. - * - * @return the code body - */ - public String generatePythonCode(String pyModuleName) { - return String.join("\n", - "import os", - "import sys", - "sys.path.append(os.path.dirname(__file__))", - "# List imported names, but do not use pylint's --extension-pkg-allow-list option", - "# so that these names will be assumed present without having to compile and install.", - "# pylint: disable=no-name-in-module, import-error", - "from "+pyModuleName+" import (", - " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", - ")", - "# pylint: disable=c-extension-no-member", - "import "+pyModuleName+" as lf", - "try:", - " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", - " from LinguaFrancaBase.functions import (", - " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS, USEC,", - " USECS, WEEK, WEEKS", - " )", - " from LinguaFrancaBase.classes import Make", - "except ModuleNotFoundError:", - " print(\"No module named 'LinguaFrancaBase'. \"", - " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", - " sys.exit(1)", - "import copy", - "", - pythonPreamble.toString(), - "", - generatePythonReactorClasses(), - "", - PythonMainFunctionGenerator.generateCode() - ); - } - - /** - * Generate the necessary Python files. - */ - public Map generatePythonFiles( - String lfModuleName, - String pyModuleName, - String pyFileName - ) throws IOException { - Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); - File file = filePath.toFile(); - Files.deleteIfExists(filePath); - // Create the necessary directories - if (!file.getParentFile().exists()) { - if (!file.getParentFile().mkdirs()) { - throw new IOException( - "Failed to create directories required for the Python code generator." - ); - } - } - Map codeMaps = new HashMap<>(); - codeMaps.put(filePath, CodeMap.fromGeneratedCode( - generatePythonCode(pyModuleName))); - FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); - return codeMaps; - } - - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - @Override - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(PythonPreambleGenerator.generateCDefineDirectives( + Map codeMaps = new HashMap<>(); + codeMaps.put(filePath, CodeMap.fromGeneratedCode(generatePythonCode(pyModuleName))); + FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); + return codeMaps; + } + + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + @Override + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + PythonPreambleGenerator.generateCDefineDirectives( targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); - code.pr(PythonPreambleGenerator.generateCIncludeStatements( + code.pr( + PythonPreambleGenerator.generateCIncludeStatements( targetConfig, targetLanguageIsCpp(), hasModalReactors)); - return code.toString(); + return code.toString(); + } + + /** + * Override generate top-level preambles, but put the user preambles in the .py file rather than + * the C file. Also handles including the federated execution setup preamble specified in the + * target config. + */ + @Override + protected String generateTopLevelPreambles() { + // user preambles + Set models = new LinkedHashSet<>(); + for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { + // The following assumes all reactors have a container. + // This means that generated reactors **have** to be + // added to a resource; not doing so will result in a NPE. + models.add((Model) ASTUtils.toDefinition(r).eContainer()); } - - /** - * Override generate top-level preambles, but put the user preambles in the - * .py file rather than the C file. Also handles including the federated - * execution setup preamble specified in the target config. - */ - @Override - protected String generateTopLevelPreambles() { - // user preambles - Set models = new LinkedHashSet<>(); - for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { - // The following assumes all reactors have a container. - // This means that generated reactors **have** to be - // added to a resource; not doing so will result in a NPE. - models.add((Model) ASTUtils.toDefinition(r).eContainer()); - } - // Add the main reactor if it is defined - if (this.mainDef != null) { - models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); - } - for (Model m : models) { - pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); - } - - // C preamble for federated execution setup - String ret = ""; - if (targetConfig.fedSetupPreamble != null) { - ret = "#include \"" + targetConfig.fedSetupPreamble + "\""; - } - return ret; + // Add the main reactor if it is defined + if (this.mainDef != null) { + models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); } - - @Override - protected void handleProtoFiles() { - for (String name : targetConfig.protoFiles) { - this.processProtoFile(name); - int dotIndex = name.lastIndexOf("."); - String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; - pythonPreamble.pr("import "+rootFilename+"_pb2 as "+rootFilename); - protoNames.add(rootFilename); - } + for (Model m : models) { + pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); } - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * - * @param filename Name of the file to process. - */ - @Override - public void processProtoFile(String filename) { - LFCommand protoc = commandFactory.createCommand( - "protoc", List.of("--python_out=" - + fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); - return; - } - int returnCode = protoc.run(); - if (returnCode == 0) { - pythonRequiredModules.add("google-api-python-client"); - } else { - errorReporter.reportError( - "protoc returns error code " + returnCode); - } + // C preamble for federated execution setup + String ret = ""; + if (targetConfig.fedSetupPreamble != null) { + ret = "#include \"" + targetConfig.fedSetupPreamble + "\""; } - - /** - * Generate the aliases for inputs, outputs, and struct type definitions for - * actions of the specified reactor in the specified federate. - * @param decl The parsed reactor data structure. - */ - @Override - public void generateAuxiliaryStructs( - ReactorDecl decl - ) { - Reactor reactor = ASTUtils.toDefinition(decl); - // First, handle inputs. - for (Input input : ASTUtils.allInputs(reactor)) { - generateAuxiliaryStructsForPort(decl, input); - } - // Next, handle outputs. - for (Output output : ASTUtils.allOutputs(reactor)) { - generateAuxiliaryStructsForPort(decl, output); - } - // Finally, handle actions. - for (Action action : ASTUtils.allActions(reactor)) { - generateAuxiliaryStructsForAction(decl, action); - } + return ret; + } + + @Override + protected void handleProtoFiles() { + for (String name : targetConfig.protoFiles) { + this.processProtoFile(name); + int dotIndex = name.lastIndexOf("."); + String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; + pythonPreamble.pr("import " + rootFilename + "_pb2 as " + rootFilename); + protoNames.add(rootFilename); } - - private void generateAuxiliaryStructsForPort(ReactorDecl decl, - Port port) { - boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); - code.pr(port, - PythonPortGenerator.generateAliasTypeDef(decl, port, isTokenType, - genericPortType)); + } + + /** + * Process a given .proto file. + * + *

Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + @Override + public void processProtoFile(String filename) { + LFCommand protoc = + commandFactory.createCommand( + "protoc", + List.of("--python_out=" + fileConfig.getSrcGenPath(), filename), + fileConfig.srcPath); + + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); + return; } - - private void generateAuxiliaryStructsForAction(ReactorDecl decl, - Action action) { - code.pr(action, PythonActionGenerator.generateAliasTypeDef(decl, action, genericActionType)); + int returnCode = protoc.run(); + if (returnCode == 0) { + pythonRequiredModules.add("google-api-python-client"); + } else { + errorReporter.reportError("protoc returns error code " + returnCode); } - - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - @Override - public boolean isOSCompatible() { - return true; + } + + /** + * Generate the aliases for inputs, outputs, and struct type definitions for actions of the + * specified reactor in the specified federate. + * + * @param decl The parsed reactor data structure. + */ + @Override + public void generateAuxiliaryStructs(ReactorDecl decl) { + Reactor reactor = ASTUtils.toDefinition(decl); + // First, handle inputs. + for (Input input : ASTUtils.allInputs(reactor)) { + generateAuxiliaryStructsForPort(decl, input); } - - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - // Set the threading to false by default, unless the user has - // specifically asked for it. - if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = false; - } - int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; - super.doGenerate(resource, new SubContext( - context, - IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, - cGeneratedPercentProgress - )); - - if (errorsOccurred()) { - context.unsuccessfulFinish(); - return; - } - - Map codeMaps = new HashMap<>(); - var lfModuleName = fileConfig.name; - // Don't generate code if there is no main reactor - if (this.main != null) { - try { - Map codeMapsForFederate = generatePythonFiles(lfModuleName, generatePythonModuleName(lfModuleName), generatePythonFileName(lfModuleName)); - codeMaps.putAll(codeMapsForFederate); - copyTargetFiles(); - new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); - if (targetConfig.noCompile) { - System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); - } - } catch (Exception e) { - //noinspection ConstantConditions - throw Exceptions.sneakyThrow(e); - } - - System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); - } - - if (errorReporter.getErrorsOccurred()) { - context.unsuccessfulFinish(); - } else { - context.finish(GeneratorResult.Status.COMPILED, codeMaps); - } + // Next, handle outputs. + for (Output output : ASTUtils.allOutputs(reactor)) { + generateAuxiliaryStructsForPort(decl, output); } - - @Override - protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new PythonDockerGenerator(context); + // Finally, handle actions. + for (Action action : ASTUtils.allActions(reactor)) { + generateAuxiliaryStructsForAction(decl, action); } - - /** Generate a reaction function definition for a reactor. - * This function has a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param decl The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - @Override - protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactionIndex) { - Reactor reactor = ASTUtils.toDefinition(decl); - - // Reactions marked with a `@_c_body` attribute are generated in C - if (AttributeUtils.hasCBody(reaction)) { - super.generateReaction(reaction, decl, reactionIndex); - return; - } - code.pr(PythonReactionGenerator.generateCReaction(reaction, decl, reactionIndex, mainDef, errorReporter, types)); + } + + private void generateAuxiliaryStructsForPort(ReactorDecl decl, Port port) { + boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); + code.pr( + port, PythonPortGenerator.generateAliasTypeDef(decl, port, isTokenType, genericPortType)); + } + + private void generateAuxiliaryStructsForAction(ReactorDecl decl, Action action) { + code.pr(action, PythonActionGenerator.generateAliasTypeDef(decl, action, genericActionType)); + } + + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + @Override + public boolean isOSCompatible() { + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + // Set the threading to false by default, unless the user has + // specifically asked for it. + if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = false; } - - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all - * instances - * of the same reactor. This task is left to Python code to allow for more - * liberal - * state variable assignments. - * - * @param instance The reactor class instance - * @return Initialization code fore state variables of instance - */ - @Override - protected void generateStateVariableInitializations(ReactorInstance instance) { - // Do nothing + int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; + super.doGenerate( + resource, + new SubContext( + context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, cGeneratedPercentProgress)); + + if (errorsOccurred()) { + context.unsuccessfulFinish(); + return; } - /** - * Generate runtime initialization code in C for parameters of a given - * reactor instance - * - * @param instance The reactor instance. - */ - @Override - protected void generateParameterInitialization(ReactorInstance instance) { - // Do nothing - // Parameters are initialized in Python - } + Map codeMaps = new HashMap<>(); + var lfModuleName = fileConfig.name; + // Don't generate code if there is no main reactor + if (this.main != null) { + try { + Map codeMapsForFederate = + generatePythonFiles( + lfModuleName, + generatePythonModuleName(lfModuleName), + generatePythonFileName(lfModuleName)); + codeMaps.putAll(codeMapsForFederate); + copyTargetFiles(); + new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); + if (targetConfig.noCompile) { + System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); + } + } catch (Exception e) { + //noinspection ConstantConditions + throw Exceptions.sneakyThrow(e); + } - /** - * Do nothing. - * Methods are generated in Python not C. - * @see PythonMethodGenerator - */ - @Override - protected void generateMethods(ReactorDecl reactor) { } - - /** - * Generate C preambles defined by user for a given reactor - * Since the Python generator expects preambles written in C, - * this function is overridden and does nothing. - * - * @param reactor The given reactor - */ - @Override - protected void generateUserPreamblesForReactor(Reactor reactor) { - // Do nothing + System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); } - /** - * Generate code that is executed while the reactor instance is being - * initialized. - * This wraps the reaction functions in a Python function. - * @param instance The reactor instance. - */ - @Override - protected void generateReactorInstanceExtension( - ReactorInstance instance - ) { - initializeTriggerObjects.pr(PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); + if (errorReporter.getErrorsOccurred()) { + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, codeMaps); } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param selfStructBody The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - @Override - protected void generateSelfStructExtension( - CodeBuilder selfStructBody, - ReactorDecl decl, - CodeBuilder constructorCode - ) { - Reactor reactor = ASTUtils.toDefinition(decl); - // Add the name field - selfStructBody.pr("char *_lf_name;"); - int reactionIndex = 0; - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create a PyObject for each reaction - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex)+";"); - if (reaction.getStp() != null) { - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex)+";"); - } - if (reaction.getDeadline() != null) { - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex)+";"); - } - reactionIndex++; - } + } + + @Override + protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new PythonDockerGenerator(context); + } + + /** + * Generate a reaction function definition for a reactor. This function has a single argument that + * is a void* pointing to a struct that contains parameters, state variables, inputs (triggering + * or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param decl The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + @Override + protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactionIndex) { + Reactor reactor = ASTUtils.toDefinition(decl); + + // Reactions marked with a `@_c_body` attribute are generated in C + if (AttributeUtils.hasCBody(reaction)) { + super.generateReaction(reaction, decl, reactionIndex); + return; } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - // NOTE: Strangely, a newline is needed at the beginning or indentation - // gets swallowed. - return String.join("\n", - "\n# Generated forwarding reaction for connections with the same destination", - "# but located in mutually exclusive modes.", - dest + ".set(" + source + ".value)\n" - ); + code.pr( + PythonReactionGenerator.generateCReaction( + reaction, decl, reactionIndex, mainDef, errorReporter, types)); + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. This task is + * left to Python code to allow for more liberal state variable assignments. + * + * @param instance The reactor class instance + * @return Initialization code fore state variables of instance + */ + @Override + protected void generateStateVariableInitializations(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate runtime initialization code in C for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + @Override + protected void generateParameterInitialization(ReactorInstance instance) { + // Do nothing + // Parameters are initialized in Python + } + + /** + * Do nothing. Methods are generated in Python not C. + * + * @see PythonMethodGenerator + */ + @Override + protected void generateMethods(ReactorDecl reactor) {} + + /** + * Generate C preambles defined by user for a given reactor Since the Python generator expects + * preambles written in C, this function is overridden and does nothing. + * + * @param reactor The given reactor + */ + @Override + protected void generateUserPreamblesForReactor(Reactor reactor) { + // Do nothing + } + + /** + * Generate code that is executed while the reactor instance is being initialized. This wraps the + * reaction functions in a Python function. + * + * @param instance The reactor instance. + */ + @Override + protected void generateReactorInstanceExtension(ReactorInstance instance) { + initializeTriggerObjects.pr( + PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param selfStructBody The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + @Override + protected void generateSelfStructExtension( + CodeBuilder selfStructBody, ReactorDecl decl, CodeBuilder constructorCode) { + Reactor reactor = ASTUtils.toDefinition(decl); + // Add the name field + selfStructBody.pr("char *_lf_name;"); + int reactionIndex = 0; + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create a PyObject for each reaction + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex) + + ";"); + if (reaction.getStp() != null) { + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex) + + ";"); + } + if (reaction.getDeadline() != null) { + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex) + + ";"); + } + reactionIndex++; } - - @Override - protected void setUpGeneralParameters() { - super.setUpGeneralParameters(); - if (hasModalReactors) { - targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); - } + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + // NOTE: Strangely, a newline is needed at the beginning or indentation + // gets swallowed. + return String.join( + "\n", + "\n# Generated forwarding reaction for connections with the same destination", + "# but located in mutually exclusive modes.", + dest + ".set(" + source + ".value)\n"); + } + + @Override + protected void setUpGeneralParameters() { + super.setUpGeneralParameters(); + if (hasModalReactors) { + targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); } + } - @Override - protected void additionalPostProcessingForModes() { - if (!hasModalReactors) { - return; - } - PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + @Override + protected void additionalPostProcessingForModes() { + if (!hasModalReactors) { + return; } + PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + } - private static String setUpMainTarget(boolean hasMain, String executableName, Stream cSources) { - return ( - """ + private static String setUpMainTarget( + boolean hasMain, String executableName, Stream cSources) { + return (""" set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(_LF_GARBAGE_COLLECTED) add_subdirectory(core) @@ -621,71 +594,61 @@ private static String setUpMainTarget(boolean hasMain, String executableName, St 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)) - .replace("executableName", executableName); - // The use of fileConfig.name will break federated execution, but that's fine - } - - /** - * Generate a (`key`, `val`) tuple pair for the `define_macros` field - * of the Extension class constructor from setuptools. - * - * @param key The key of the macro entry - * @param val The value of the macro entry - * @return A (`key`, `val`) tuple pair as String - */ - private static String generateMacroEntry(String key, String val) { - return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; - } - - /** - * Generate the name of the python module. - * - * Ideally, this function would belong in a class like `PyFileConfig` - * that specifies all the paths to the generated code. - * - * @param lfModuleName The name of the LF module. - * @return The name of the python module. - */ - private static String generatePythonModuleName(String lfModuleName) { - return "LinguaFranca" + lfModuleName; - } - - /** - * Generate the python file name given an `lfModuleName`. - * - * Ideally, this function would belong in a class like `PyFileConfig` - * that specifies all the paths to the generated code. - * - * @param lfModuleName The name of the LF module - * @return The name of the generated python file. - */ - private static String generatePythonFileName(String lfModuleName) { - return lfModuleName + ".py"; - } - - /** - * Copy Python specific target code to the src-gen directory - */ - @Override - protected void copyTargetFiles() throws IOException { - super.copyTargetFiles(); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/include", - fileConfig.getSrcGenPath().resolve("include"), - true - ); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/lib", - fileConfig.getSrcGenPath().resolve("lib"), - true - ); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/LinguaFrancaBase", - fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), - true - ); - } - + """) + .replace("", generatePythonModuleName(executableName)) + .replace("executableName", executableName); + // The use of fileConfig.name will break federated execution, but that's fine + } + + /** + * Generate a (`key`, `val`) tuple pair for the `define_macros` field of the Extension class + * constructor from setuptools. + * + * @param key The key of the macro entry + * @param val The value of the macro entry + * @return A (`key`, `val`) tuple pair as String + */ + private static String generateMacroEntry(String key, String val) { + return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; + } + + /** + * Generate the name of the python module. + * + *

Ideally, this function would belong in a class like `PyFileConfig` that specifies all the + * paths to the generated code. + * + * @param lfModuleName The name of the LF module. + * @return The name of the python module. + */ + private static String generatePythonModuleName(String lfModuleName) { + return "LinguaFranca" + lfModuleName; + } + + /** + * Generate the python file name given an `lfModuleName`. + * + *

Ideally, this function would belong in a class like `PyFileConfig` that specifies all the + * paths to the generated code. + * + * @param lfModuleName The name of the LF module + * @return The name of the generated python file. + */ + private static String generatePythonFileName(String lfModuleName) { + return lfModuleName + ".py"; + } + + /** Copy Python specific target code to the src-gen directory */ + @Override + protected void copyTargetFiles() throws IOException { + super.copyTargetFiles(); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/include", fileConfig.getSrcGenPath().resolve("include"), true); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/lib", fileConfig.getSrcGenPath().resolve("lib"), true); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/LinguaFrancaBase", + fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), + true); + } } diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index a770235b31..32cd8d4a97 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -1,27 +1,27 @@ /************* -Copyright (c) 2020, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.scoping; @@ -29,256 +29,251 @@ import static org.lflang.ASTUtils.*; import com.google.inject.Inject; - import java.util.ArrayList; - import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.xtext.naming.SimpleNameProvider; import org.eclipse.xtext.scoping.IScope; import org.eclipse.xtext.scoping.Scopes; import org.eclipse.xtext.scoping.impl.SelectableBasedScope; - import org.lflang.lf.Assignment; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; import org.lflang.lf.Import; import org.lflang.lf.ImportedReactor; import org.lflang.lf.Instantiation; +import org.lflang.lf.LfPackage; +import org.lflang.lf.Mode; import org.lflang.lf.Model; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; -import org.lflang.lf.LfPackage; -import org.lflang.lf.Mode; /** - * This class enforces custom rules. In particular, it resolves references to - * parameters, ports, actions, and timers. Ports can be referenced across at - * most one level of hierarchy. Parameters, actions, and timers can be - * referenced locally, within the reactor. + * This class enforces custom rules. In particular, it resolves references to parameters, ports, + * actions, and timers. Ports can be referenced across at most one level of hierarchy. Parameters, + * actions, and timers can be referenced locally, within the reactor. * * @author Marten Lohstroh * @see */ public class LFScopeProviderImpl extends AbstractLFScopeProvider { - @Inject - private SimpleNameProvider nameProvider; + @Inject private SimpleNameProvider nameProvider; - @Inject - private LFGlobalScopeProvider scopeProvider; + @Inject private LFGlobalScopeProvider scopeProvider; - /** - * Enumerate of the kinds of references. - */ - enum RefType { - NULL, - TRIGGER, - SOURCE, - EFFECT, - WATCHDOG, - DEADLINE, - CLEFT, - CRIGHT - } + /** Enumerate of the kinds of references. */ + enum RefType { + NULL, + TRIGGER, + SOURCE, + EFFECT, + WATCHDOG, + DEADLINE, + CLEFT, + CRIGHT + } - /** - * Depending on the provided context, construct the appropriate scope - * for the given reference. - * - * @param context The AST node in which a to-be-resolved reference occurs. - * @param reference The reference to resolve. - */ - @Override - public IScope getScope(EObject context, EReference reference) { - if (context instanceof VarRef) { - return getScopeForVarRef((VarRef) context, reference); - } else if (context instanceof Assignment) { - return getScopeForAssignment((Assignment) context, reference); - } else if (context instanceof Instantiation) { - return getScopeForReactorDecl(context, reference); - } else if (context instanceof Reactor) { - return getScopeForReactorDecl(context, reference); - } else if (context instanceof ImportedReactor) { - return getScopeForImportedReactor((ImportedReactor) context, reference); - } - return super.getScope(context, reference); + /** + * Depending on the provided context, construct the appropriate scope for the given reference. + * + * @param context The AST node in which a to-be-resolved reference occurs. + * @param reference The reference to resolve. + */ + @Override + public IScope getScope(EObject context, EReference reference) { + if (context instanceof VarRef) { + return getScopeForVarRef((VarRef) context, reference); + } else if (context instanceof Assignment) { + return getScopeForAssignment((Assignment) context, reference); + } else if (context instanceof Instantiation) { + return getScopeForReactorDecl(context, reference); + } else if (context instanceof Reactor) { + return getScopeForReactorDecl(context, reference); + } else if (context instanceof ImportedReactor) { + return getScopeForImportedReactor((ImportedReactor) context, reference); } + return super.getScope(context, reference); + } - /** - * Filter out candidates that do not originate from the file listed in - * this particular import statement. - */ - protected IScope getScopeForImportedReactor(ImportedReactor context, EReference reference) { - String importURI = ((Import) context.eContainer()).getImportURI(); - var importedURI = scopeProvider.resolve(importURI == null ? "" : importURI, context.eResource()); - if (importedURI != null) { - var uniqueImportURIs = scopeProvider.getImportedUris(context.eResource()); - var descriptions = scopeProvider.getResourceDescriptions(context.eResource(), uniqueImportURIs); - var description = descriptions.getResourceDescription(importedURI); - return SelectableBasedScope.createScope(IScope.NULLSCOPE, description, null, reference.getEReferenceType(), false); - } - return Scopes.scopeFor(emptyList()); + /** + * Filter out candidates that do not originate from the file listed in this particular import + * statement. + */ + protected IScope getScopeForImportedReactor(ImportedReactor context, EReference reference) { + String importURI = ((Import) context.eContainer()).getImportURI(); + var importedURI = + scopeProvider.resolve(importURI == null ? "" : importURI, context.eResource()); + if (importedURI != null) { + var uniqueImportURIs = scopeProvider.getImportedUris(context.eResource()); + var descriptions = + scopeProvider.getResourceDescriptions(context.eResource(), uniqueImportURIs); + var description = descriptions.getResourceDescription(importedURI); + return SelectableBasedScope.createScope( + IScope.NULLSCOPE, description, null, reference.getEReferenceType(), false); } + return Scopes.scopeFor(emptyList()); + } - /** - * @param obj Instantiation or Reactor that has a ReactorDecl to resolve. - * @param reference The reference to link to a ReactorDecl node. - */ - protected IScope getScopeForReactorDecl(EObject obj, EReference reference) { + /** + * @param obj Instantiation or Reactor that has a ReactorDecl to resolve. + * @param reference The reference to link to a ReactorDecl node. + */ + protected IScope getScopeForReactorDecl(EObject obj, EReference reference) { - // Find the local Model - Model model = null; - EObject container = obj; - while(model == null && container != null) { - container = container.eContainer(); - if (container instanceof Model) { - model = (Model)container; - } - } - if (model == null) { - return Scopes.scopeFor(emptyList()); - } + // Find the local Model + Model model = null; + EObject container = obj; + while (model == null && container != null) { + container = container.eContainer(); + if (container instanceof Model) { + model = (Model) container; + } + } + if (model == null) { + return Scopes.scopeFor(emptyList()); + } - // Collect eligible candidates, all of which are local (i.e., not in other files). - var locals = new ArrayList(model.getReactors()); + // Collect eligible candidates, all of which are local (i.e., not in other files). + var locals = new ArrayList(model.getReactors()); - // Either point to the import statement (if it is renamed) - // or directly to the reactor definition. - for (Import it : model.getImports()) { - for (ImportedReactor ir : it.getReactorClasses()) { - if (ir.getName() != null) { - locals.add(ir); - } else if (ir.getReactorClass() != null) { - locals.add(ir.getReactorClass()); - } - } + // Either point to the import statement (if it is renamed) + // or directly to the reactor definition. + for (Import it : model.getImports()) { + for (ImportedReactor ir : it.getReactorClasses()) { + if (ir.getName() != null) { + locals.add(ir); + } else if (ir.getReactorClass() != null) { + locals.add(ir.getReactorClass()); } - return Scopes.scopeFor(locals); + } } + return Scopes.scopeFor(locals); + } - protected IScope getScopeForAssignment(Assignment assignment, EReference reference) { + protected IScope getScopeForAssignment(Assignment assignment, EReference reference) { - if (reference == LfPackage.Literals.ASSIGNMENT__LHS) { - var defn = toDefinition(((Instantiation) assignment.eContainer()).getReactorClass()); - if (defn != null) { - return Scopes.scopeFor(allParameters(defn)); - } - - } - if (reference == LfPackage.Literals.ASSIGNMENT__RHS) { - return Scopes.scopeFor(((Reactor) assignment.eContainer().eContainer()).getParameters()); - } - return Scopes.scopeFor(emptyList()); + if (reference == LfPackage.Literals.ASSIGNMENT__LHS) { + var defn = toDefinition(((Instantiation) assignment.eContainer()).getReactorClass()); + if (defn != null) { + return Scopes.scopeFor(allParameters(defn)); + } + } + if (reference == LfPackage.Literals.ASSIGNMENT__RHS) { + return Scopes.scopeFor(((Reactor) assignment.eContainer().eContainer()).getParameters()); } + return Scopes.scopeFor(emptyList()); + } - protected IScope getScopeForVarRef(VarRef variable, EReference reference) { - if (reference == LfPackage.Literals.VAR_REF__VARIABLE) { - // Resolve hierarchical reference - Reactor reactor; - Mode mode = null; - if (variable.eContainer().eContainer() instanceof Reactor) { - reactor = (Reactor) variable.eContainer().eContainer(); - } else if (variable.eContainer().eContainer() instanceof Mode) { - mode = (Mode) variable.eContainer().eContainer(); - reactor = (Reactor) variable.eContainer().eContainer().eContainer(); - } else { - return Scopes.scopeFor(emptyList()); - } + protected IScope getScopeForVarRef(VarRef variable, EReference reference) { + if (reference == LfPackage.Literals.VAR_REF__VARIABLE) { + // Resolve hierarchical reference + Reactor reactor; + Mode mode = null; + if (variable.eContainer().eContainer() instanceof Reactor) { + reactor = (Reactor) variable.eContainer().eContainer(); + } else if (variable.eContainer().eContainer() instanceof Mode) { + mode = (Mode) variable.eContainer().eContainer(); + reactor = (Reactor) variable.eContainer().eContainer().eContainer(); + } else { + return Scopes.scopeFor(emptyList()); + } - RefType type = getRefType(variable); + RefType type = getRefType(variable); - if (variable.getContainer() != null) { // Resolve hierarchical port reference - var instanceName = nameProvider.getFullyQualifiedName(variable.getContainer()); - var instances = new ArrayList(reactor.getInstantiations()); - if (mode != null) { - instances.addAll(mode.getInstantiations()); - } + if (variable.getContainer() != null) { // Resolve hierarchical port reference + var instanceName = nameProvider.getFullyQualifiedName(variable.getContainer()); + var instances = new ArrayList(reactor.getInstantiations()); + if (mode != null) { + instances.addAll(mode.getInstantiations()); + } - if (instanceName != null) { - for (var instance : instances) { - var defn = toDefinition(instance.getReactorClass()); - if (defn != null && instance.getName().equals(instanceName.toString())) { - switch (type) { - case TRIGGER: - case SOURCE: - case CLEFT: - return Scopes.scopeFor(allOutputs(defn)); - case EFFECT: - case DEADLINE: - case CRIGHT: - return Scopes.scopeFor(allInputs(defn)); - } - } - } - } - return Scopes.scopeFor(emptyList()); - } else { - // Resolve local reference - switch (type) { - case TRIGGER: { - var candidates = new ArrayList(); - if (mode != null) { - candidates.addAll(mode.getActions()); - candidates.addAll(mode.getTimers()); - } - candidates.addAll(allInputs(reactor)); - candidates.addAll(allActions(reactor)); - candidates.addAll(allTimers(reactor)); - candidates.addAll(allWatchdogs(reactor)); - return Scopes.scopeFor(candidates); - } + if (instanceName != null) { + for (var instance : instances) { + var defn = toDefinition(instance.getReactorClass()); + if (defn != null && instance.getName().equals(instanceName.toString())) { + switch (type) { + case TRIGGER: case SOURCE: - return super.getScope(variable, reference); - case EFFECT: { - var candidates = new ArrayList(); - if (mode != null) { - candidates.addAll(mode.getActions()); - candidates.addAll(reactor.getModes()); - } - candidates.addAll(allOutputs(reactor)); - candidates.addAll(allActions(reactor)); - candidates.addAll(allWatchdogs(reactor)); - return Scopes.scopeFor(candidates); - } - case WATCHDOG: - return Scopes.scopeFor(allWatchdogs(reactor)); - case DEADLINE: case CLEFT: - return Scopes.scopeFor(allInputs(reactor)); + return Scopes.scopeFor(allOutputs(defn)); + case EFFECT: + case DEADLINE: case CRIGHT: - return Scopes.scopeFor(allOutputs(reactor)); - default: - return Scopes.scopeFor(emptyList()); - } + return Scopes.scopeFor(allInputs(defn)); + } } - } else { // Resolve instance - return super.getScope(variable, reference); + } } - } - - private RefType getRefType(VarRef variable) { - if (variable.eContainer() instanceof Deadline) { - return RefType.DEADLINE; - } else if (variable.eContainer() instanceof Reaction) { - var reaction = (Reaction) variable.eContainer(); - if (reaction.getTriggers().contains(variable)) { - return RefType.TRIGGER; - } else if (reaction.getSources().contains(variable)) { - return RefType.SOURCE; - } else if (reaction.getEffects().contains(variable)) { - return RefType.EFFECT; + return Scopes.scopeFor(emptyList()); + } else { + // Resolve local reference + switch (type) { + case TRIGGER: + { + var candidates = new ArrayList(); + if (mode != null) { + candidates.addAll(mode.getActions()); + candidates.addAll(mode.getTimers()); + } + candidates.addAll(allInputs(reactor)); + candidates.addAll(allActions(reactor)); + candidates.addAll(allTimers(reactor)); + candidates.addAll(allWatchdogs(reactor)); + return Scopes.scopeFor(candidates); } - } else if (variable.eContainer() instanceof Connection) { - var conn = (Connection) variable.eContainer(); - if (conn.getLeftPorts().contains(variable)) { - return RefType.CLEFT; - } else if (conn.getRightPorts().contains(variable)) { - return RefType.CRIGHT; + case SOURCE: + return super.getScope(variable, reference); + case EFFECT: + { + var candidates = new ArrayList(); + if (mode != null) { + candidates.addAll(mode.getActions()); + candidates.addAll(reactor.getModes()); + } + candidates.addAll(allOutputs(reactor)); + candidates.addAll(allActions(reactor)); + candidates.addAll(allWatchdogs(reactor)); + return Scopes.scopeFor(candidates); } + case WATCHDOG: + return Scopes.scopeFor(allWatchdogs(reactor)); + case DEADLINE: + case CLEFT: + return Scopes.scopeFor(allInputs(reactor)); + case CRIGHT: + return Scopes.scopeFor(allOutputs(reactor)); + default: + return Scopes.scopeFor(emptyList()); } - return RefType.NULL; + } + } else { // Resolve instance + return super.getScope(variable, reference); + } + } + + private RefType getRefType(VarRef variable) { + if (variable.eContainer() instanceof Deadline) { + return RefType.DEADLINE; + } else if (variable.eContainer() instanceof Reaction) { + var reaction = (Reaction) variable.eContainer(); + if (reaction.getTriggers().contains(variable)) { + return RefType.TRIGGER; + } else if (reaction.getSources().contains(variable)) { + return RefType.SOURCE; + } else if (reaction.getEffects().contains(variable)) { + return RefType.EFFECT; + } + } else if (variable.eContainer() instanceof Connection) { + var conn = (Connection) variable.eContainer(); + if (conn.getLeftPorts().contains(variable)) { + return RefType.CLEFT; + } else if (conn.getRightPorts().contains(variable)) { + return RefType.CRIGHT; + } } + return RefType.NULL; + } } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 2ea579b753..2d0d4f332b 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -2,17 +2,17 @@ /************* * Copyright (c) 2019-2020, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -28,12 +28,10 @@ import static org.lflang.ASTUtils.inferPortWidth; import static org.lflang.ASTUtils.isGeneric; -import static org.lflang.ASTUtils.isInteger; -import static org.lflang.ASTUtils.isOfTimeType; -import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; import static org.lflang.ASTUtils.toOriginalText; +import com.google.inject.Inject; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -45,7 +43,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAttribute; @@ -72,7 +69,6 @@ import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; -import org.lflang.lf.CodeExpr; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; import org.lflang.lf.Expression; @@ -114,15 +110,12 @@ import org.lflang.lf.Visibility; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; -import org.lflang.lf.Watchdog; import org.lflang.util.FileUtil; -import com.google.inject.Inject; - /** * Custom validation checks for Lingua Franca programs. * - * Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation + *

Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation * * @author Edward A. Lee * @author Marten Lohstroh @@ -133,1750 +126,1832 @@ */ public class LFValidator extends BaseLFValidator { - ////////////////////////////////////////////////////////////// - //// Public check methods. - - // These methods are automatically invoked on AST nodes matching - // the types of their arguments. - // CheckType.FAST ensures that these checks run whenever a file is modified. - // Alternatives are CheckType.NORMAL (when saving) and - // CheckType.EXPENSIVE (only when right-click, validate). - // FIXME: What is the default when nothing is specified? - - // These methods are listed in alphabetical order, and, although - // it is isn't strictly required, follow a naming convention - // checkClass, where Class is the AST class, where possible. - - @Check(CheckType.FAST) - public void checkAction(Action action) { - checkName(action.getName(), Literals.VARIABLE__NAME); - if (action.getOrigin() == ActionOrigin.NONE) { - error( - "Action must have modifier `logical` or `physical`.", - Literals.ACTION__ORIGIN - ); - } - if (action.getPolicy() != null && - !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { - error( - "Unrecognized spacing violation policy: " + action.getPolicy() + - ". Available policies are: " + - String.join(", ", SPACING_VIOLATION_POLICIES) + ".", - Literals.ACTION__POLICY); - } - checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); - checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); + ////////////////////////////////////////////////////////////// + //// Public check methods. + + // These methods are automatically invoked on AST nodes matching + // the types of their arguments. + // CheckType.FAST ensures that these checks run whenever a file is modified. + // Alternatives are CheckType.NORMAL (when saving) and + // CheckType.EXPENSIVE (only when right-click, validate). + // FIXME: What is the default when nothing is specified? + + // These methods are listed in alphabetical order, and, although + // it is isn't strictly required, follow a naming convention + // checkClass, where Class is the AST class, where possible. + + @Check(CheckType.FAST) + public void checkAction(Action action) { + checkName(action.getName(), Literals.VARIABLE__NAME); + if (action.getOrigin() == ActionOrigin.NONE) { + error("Action must have modifier `logical` or `physical`.", Literals.ACTION__ORIGIN); } - - - @Check(CheckType.FAST) - public void checkInitializer(Initializer init) { - if (init.isBraces() && target != Target.CPP) { - error("Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); - } else if (init.isParens() && target.mandatesEqualsInitializers()) { - var message = "This syntax is deprecated in the " + target - + " target, use an equal sign instead of parentheses for assignment."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, Literals.INITIALIZER__PARENS); - } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { - var feature = init.isBraces() ? Literals.INITIALIZER__BRACES - : Literals.INITIALIZER__PARENS; - var message = "This syntax is deprecated, do not use parentheses or braces but an equal sign."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, feature); - } + if (action.getPolicy() != null && !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { + error( + "Unrecognized spacing violation policy: " + + action.getPolicy() + + ". Available policies are: " + + String.join(", ", SPACING_VIOLATION_POLICIES) + + ".", + Literals.ACTION__POLICY); } - - @Check(CheckType.FAST) - public void checkBracedExpression(BracedListExpression expr) { - if (!target.allowsBracedListExpressions()) { - var message = "Braced expression lists are not a valid expression for the " + target - + " target."; - error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); - } + checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); + checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); + } + + @Check(CheckType.FAST) + public void checkInitializer(Initializer init) { + if (init.isBraces() && target != Target.CPP) { + error( + "Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); + } else if (init.isParens() && target.mandatesEqualsInitializers()) { + var message = + "This syntax is deprecated in the " + + target + + " target, use an equal sign instead of parentheses for assignment."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, Literals.INITIALIZER__PARENS); + } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { + var feature = init.isBraces() ? Literals.INITIALIZER__BRACES : Literals.INITIALIZER__PARENS; + var message = + "This syntax is deprecated, do not use parentheses or braces but an equal sign."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, feature); } - - @Check(CheckType.FAST) - public void checkAssignment(Assignment assignment) { - - // If the left-hand side is a time parameter, make sure the assignment has units - typeCheck(assignment.getRhs(), ASTUtils.getInferredType(assignment.getLhs()), Literals.ASSIGNMENT__RHS); - // If this assignment overrides a parameter that is used in a deadline, - // report possible overflow. - if (isCBasedTarget() && - this.info.overflowingAssignments.contains(assignment)) { - error( - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.ASSIGNMENT__RHS); - } - + } + + @Check(CheckType.FAST) + public void checkBracedExpression(BracedListExpression expr) { + if (!target.allowsBracedListExpressions()) { + var message = + "Braced expression lists are not a valid expression for the " + target + " target."; + error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); } + } + + @Check(CheckType.FAST) + public void checkAssignment(Assignment assignment) { + + // If the left-hand side is a time parameter, make sure the assignment has units + typeCheck( + assignment.getRhs(), + ASTUtils.getInferredType(assignment.getLhs()), + Literals.ASSIGNMENT__RHS); + // If this assignment overrides a parameter that is used in a deadline, + // report possible overflow. + if (isCBasedTarget() && this.info.overflowingAssignments.contains(assignment)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds.", + Literals.ASSIGNMENT__RHS); + } + } - @Check(CheckType.FAST) - public void checkConnection(Connection connection) { - - // Report if connection is part of a cycle. - Set> cycles = this.info.topologyCycles(); - for (VarRef lp : connection.getLeftPorts()) { - for (VarRef rp : connection.getRightPorts()) { - boolean leftInCycle = false; - - for (NamedInstance it : cycles) { - if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) - || (it.getDefinition().equals(lp.getVariable()) && it.getParent().equals(lp.getContainer()))) { - leftInCycle = true; - break; - } - } - - for (NamedInstance it : cycles) { - if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) - || (it.getDefinition().equals(rp.getVariable()) && it.getParent().equals(rp.getContainer()))) { - if (leftInCycle) { - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - String reactorName = reactor.getName(); - error(String.format("Connection in reactor %s creates", reactorName) + - String.format("a cyclic dependency between %s and %s.", toOriginalText(lp), toOriginalText(rp)), - Literals.CONNECTION__DELAY); - } - } - } - } - } + @Check(CheckType.FAST) + public void checkConnection(Connection connection) { - // FIXME: look up all ReactorInstance objects that have a definition equal to the - // container of this connection. For each of those occurrences, the widths have to match. - // For the C target, since C has such a weak type system, check that - // the types on both sides of every connection match. For other languages, - // we leave type compatibility that language's compiler or interpreter. - if (isCBasedTarget()) { - Type type = (Type) null; - for (VarRef port : connection.getLeftPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - // Unfortunately, xtext does not generate a suitable equals() - // method for AST types, so we have to manually check the types. - if (!sameType(type, ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); - } - } - } - } - for (VarRef port : connection.getRightPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - if (!sameType(type, type = ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); - } - } - } - } - } + // Report if connection is part of a cycle. + Set> cycles = this.info.topologyCycles(); + for (VarRef lp : connection.getLeftPorts()) { + for (VarRef rp : connection.getRightPorts()) { + boolean leftInCycle = false; - // Check whether the total width of the left side of the connection - // matches the total width of the right side. This cannot be determined - // here if the width is not given as a constant. In that case, it is up - // to the code generator to check it. - int leftWidth = 0; - for (VarRef port : connection.getLeftPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || leftWidth < 0) { - // Cannot determine the width of the left ports. - leftWidth = -1; - } else { - leftWidth += width; - } - } - int rightWidth = 0; - for (VarRef port : connection.getRightPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || rightWidth < 0) { - // Cannot determine the width of the left ports. - rightWidth = -1; - } else { - rightWidth += width; - } + for (NamedInstance it : cycles) { + if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) + || (it.getDefinition().equals(lp.getVariable()) + && it.getParent().equals(lp.getContainer()))) { + leftInCycle = true; + break; + } } - if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { - if (connection.isIterated()) { - if (leftWidth == 0 || rightWidth % leftWidth != 0) { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning(String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS - ); - } - } else { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning(String.format("Left width %s does not match right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS - ); - } - } + for (NamedInstance it : cycles) { + if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) + || (it.getDefinition().equals(rp.getVariable()) + && it.getParent().equals(rp.getContainer()))) { + if (leftInCycle) { + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + String reactorName = reactor.getName(); + error( + String.format("Connection in reactor %s creates", reactorName) + + String.format( + "a cyclic dependency between %s and %s.", + toOriginalText(lp), toOriginalText(rp)), + Literals.CONNECTION__DELAY); + } + } + } + } + } - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - - // Make sure the right port is not already an effect of a reaction. - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - for (VarRef effect : reaction.getEffects()) { - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort.getVariable().equals(effect.getVariable()) && // Refers to the same variable - rightPort.getContainer() == effect.getContainer() && // Refers to the same instance - ( reaction.eContainer() instanceof Reactor || // Either is not part of a mode - connection.eContainer() instanceof Reactor || - connection.eContainer() == reaction.eContainer() // Or they are in the same mode - )) { - error("Cannot connect: Port named '" + effect.getVariable().getName() + - "' is already effect of a reaction.", - Literals.CONNECTION__RIGHT_PORTS); - } - } - } - } + // FIXME: look up all ReactorInstance objects that have a definition equal to the + // container of this connection. For each of those occurrences, the widths have to match. + // For the C target, since C has such a weak type system, check that + // the types on both sides of every connection match. For other languages, + // we leave type compatibility that language's compiler or interpreter. + if (isCBasedTarget()) { + Type type = (Type) null; + for (VarRef port : connection.getLeftPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + // Unfortunately, xtext does not generate a suitable equals() + // method for AST types, so we have to manually check the types. + if (!sameType(type, ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); + } + } + } + } + for (VarRef port : connection.getRightPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + if (!sameType(type, type = ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } + } - // Check that the right port does not already have some other - // upstream connection. - for (Connection c : reactor.getConnections()) { - if (c != connection) { - for (VarRef thisRightPort : connection.getRightPorts()) { - for (VarRef thatRightPort : c.getRightPorts()) { - if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) && // Refers to the same variable - thisRightPort.getContainer() == thatRightPort.getContainer() && // Refers to the same instance - ( connection.eContainer() instanceof Reactor || // Or either of the connections in not part of a mode - c.eContainer() instanceof Reactor || - connection.eContainer() == c.eContainer() // Or they are in the same mode - )) { - error( - "Cannot connect: Port named '" + thisRightPort.getVariable().getName() + - "' may only appear once on the right side of a connection.", - Literals.CONNECTION__RIGHT_PORTS); - } - } - } - } - } + // Check whether the total width of the left side of the connection + // matches the total width of the right side. This cannot be determined + // here if the width is not given as a constant. In that case, it is up + // to the code generator to check it. + int leftWidth = 0; + for (VarRef port : connection.getLeftPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || leftWidth < 0) { + // Cannot determine the width of the left ports. + leftWidth = -1; + } else { + leftWidth += width; + } + } + int rightWidth = 0; + for (VarRef port : connection.getRightPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || rightWidth < 0) { + // Cannot determine the width of the left ports. + rightWidth = -1; + } else { + rightWidth += width; + } + } - // Check the after delay - if (connection.getDelay() != null) { - final var delay = connection.getDelay(); - if (delay instanceof ParameterReference || delay instanceof Time || delay instanceof Literal) { - checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); - } else { - error("After delays can only be given by time literals or parameters.", - Literals.CONNECTION__DELAY); - } - } + if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { + if (connection.isIterated()) { + if (leftWidth == 0 || rightWidth % leftWidth != 0) { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning( + String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS); + } + } else { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning( + String.format("Left width %s does not match right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS); + } } - @Check(CheckType.FAST) - public void checkDeadline(Deadline deadline) { - if (isCBasedTarget() && - this.info.overflowingDeadlines.contains(deadline)) { + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + + // Make sure the right port is not already an effect of a reaction. + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + for (VarRef effect : reaction.getEffects()) { + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort.getVariable().equals(effect.getVariable()) + && // Refers to the same variable + rightPort.getContainer() == effect.getContainer() + && // Refers to the same instance + (reaction.eContainer() instanceof Reactor + || // Either is not part of a mode + connection.eContainer() instanceof Reactor + || connection.eContainer() + == reaction.eContainer() // Or they are in the same mode + )) { error( - "Deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.DEADLINE__DELAY); + "Cannot connect: Port named '" + + effect.getVariable().getName() + + "' is already effect of a reaction.", + Literals.CONNECTION__RIGHT_PORTS); + } } - checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); + } } - @Check(CheckType.FAST) - public void checkHost(Host host) { - String addr = host.getAddr(); - String user = host.getUser(); - if (user != null && !user.matches(USERNAME_REGEX)) { - warning( - "Invalid user name.", - Literals.HOST__USER - ); - } - if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { - warning( - "Invalid IP address.", - Literals.HOST__ADDR - ); - } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { - warning( - "Invalid IP address.", - Literals.HOST__ADDR - ); - } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { - warning( - "Invalid host name or fully qualified domain name.", - Literals.HOST__ADDR - ); - } + // Check that the right port does not already have some other + // upstream connection. + for (Connection c : reactor.getConnections()) { + if (c != connection) { + for (VarRef thisRightPort : connection.getRightPorts()) { + for (VarRef thatRightPort : c.getRightPorts()) { + if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) + && // Refers to the same variable + thisRightPort.getContainer() == thatRightPort.getContainer() + && // Refers to the same instance + (connection.eContainer() instanceof Reactor + || // Or either of the connections in not part of a mode + c.eContainer() instanceof Reactor + || connection.eContainer() == c.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + + thisRightPort.getVariable().getName() + + "' may only appear once on the right side of a connection.", + Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } } - @Check - public void checkImport(Import imp) { - if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { - error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. - return; - } - - // FIXME: report error if resource cannot be resolved. - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (!isUnused(reactor)) { - return; - } - } - warning("Unused import.", Literals.IMPORT__IMPORT_URI); + // Check the after delay + if (connection.getDelay() != null) { + final var delay = connection.getDelay(); + if (delay instanceof ParameterReference + || delay instanceof Time + || delay instanceof Literal) { + checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); + } else { + error( + "After delays can only be given by time literals or parameters.", + Literals.CONNECTION__DELAY); + } } - - @Check - public void checkImportedReactor(ImportedReactor reactor) { - if (isUnused(reactor)) { - warning("Unused reactor class.", - Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } - - if (info.instantiationGraph.hasCycles()) { - Set cycleSet = new HashSet<>(); - for (Set cycle : info.instantiationGraph.getCycles()) { - cycleSet.addAll(cycle); - } - if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { - error("Imported reactor '" + toDefinition(reactor).getName() + - "' has cyclic instantiation in it.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } - } + } + + @Check(CheckType.FAST) + public void checkDeadline(Deadline deadline) { + if (isCBasedTarget() && this.info.overflowingDeadlines.contains(deadline)) { + error( + "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.DEADLINE__DELAY); } - - @Check(CheckType.FAST) - public void checkInput(Input input) { - Reactor parent = (Reactor)input.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); - } - checkName(input.getName(), Literals.VARIABLE__NAME); - if (target.requiresTypes) { - if (input.getType() == null) { - error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); - } - } - - // mutable has no meaning in C++ - if (input.isMutable() && this.target == Target.CPP) { - warning( - "The mutable qualifier has no meaning for the C++ target and should be removed. " + - "In C++, any value can be made mutable by calling get_mutable_copy().", - Literals.INPUT__MUTABLE - ); - } - - // Variable width multiports are not supported (yet?). - if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } + checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); + } + + @Check(CheckType.FAST) + public void checkHost(Host host) { + String addr = host.getAddr(); + String user = host.getUser(); + if (user != null && !user.matches(USERNAME_REGEX)) { + warning("Invalid user name.", Literals.HOST__USER); } + if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { + warning("Invalid IP address.", Literals.HOST__ADDR); + } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { + warning("Invalid IP address.", Literals.HOST__ADDR); + } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { + warning("Invalid host name or fully qualified domain name.", Literals.HOST__ADDR); + } + } - @Check(CheckType.FAST) - public void checkInstantiation(Instantiation instantiation) { - checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); - Reactor reactor = toDefinition(instantiation.getReactorClass()); - if (reactor.isMain() || reactor.isFederated()) { - error( - "Cannot instantiate a main (or federated) reactor: " + - instantiation.getReactorClass().getName(), - Literals.INSTANTIATION__REACTOR_CLASS - ); - } + @Check + public void checkImport(Import imp) { + if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { + error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. + return; + } - // Report error if this instantiation is part of a cycle. - // FIXME: improve error message. - // FIXME: Also report if there exists a cycle within. - if (this.info.instantiationGraph.getCycles().size() > 0) { - for (Set cycle : this.info.instantiationGraph.getCycles()) { - Reactor container = (Reactor) instantiation.eContainer(); - if (cycle.contains(container) && cycle.contains(reactor)) { - List names = new ArrayList<>(); - for (Reactor r : cycle) { - names.add(r.getName()); - } - - error( - "Instantiation is part of a cycle: " + String.join(", ", names) + ".", - Literals.INSTANTIATION__REACTOR_CLASS - ); - } - } - } - // Variable width multiports are not supported (yet?). - if (instantiation.getWidthSpec() != null - && instantiation.getWidthSpec().isOfVariableLength() - ) { - if (isCBasedTarget()) { - warning("Variable-width banks are for internal use only.", - Literals.INSTANTIATION__WIDTH_SPEC - ); - } else { - error("Variable-width banks are not supported.", - Literals.INSTANTIATION__WIDTH_SPEC - ); - } - } + // FIXME: report error if resource cannot be resolved. + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (!isUnused(reactor)) { + return; + } } + warning("Unused import.", Literals.IMPORT__IMPORT_URI); + } - /** Check target parameters, which are key-value pairs. */ - @Check(CheckType.FAST) - public void checkKeyValuePair(KeyValuePair param) { - // Check only if the container's container is a Target. - if (param.eContainer().eContainer() instanceof TargetDecl) { - TargetProperty prop = TargetProperty.forName(param.getName()); - - // Make sure the key is valid. - if (prop == null) { - String options = TargetProperty.getOptions().stream() - .map(p -> p.description).sorted() - .collect(Collectors.joining(", ")); - warning( - "Unrecognized target parameter: " + param.getName() + - ". Recognized parameters are: " + options, - Literals.KEY_VALUE_PAIR__NAME); - } else { - // Check whether the property is supported by the target. - if (!prop.supportedBy.contains(this.target)) { - warning( - "The target parameter: " + param.getName() + - " is not supported by the " + this.target + - " target and will thus be ignored.", - Literals.KEY_VALUE_PAIR__NAME); - } + @Check + public void checkImportedReactor(ImportedReactor reactor) { + if (isUnused(reactor)) { + warning("Unused reactor class.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } - // Report problem with the assigned value. - prop.type.check(param.getValue(), param.getName(), this); - } - - for (String it : targetPropertyErrors) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyErrors.clear(); - - for (String it : targetPropertyWarnings) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyWarnings.clear(); - } + if (info.instantiationGraph.hasCycles()) { + Set cycleSet = new HashSet<>(); + for (Set cycle : info.instantiationGraph.getCycles()) { + cycleSet.addAll(cycle); + } + if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { + error( + "Imported reactor '" + + toDefinition(reactor).getName() + + "' has cyclic instantiation in it.", + Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } } + } - @Check(CheckType.FAST) - public void checkModel(Model model) { - // Since we're doing a fast check, we only want to update - // if the model info hasn't been initialized yet. If it has, - // we use the old information and update it during a normal - // check (see below). - if (!info.updated) { - info.update(model, errorReporter); - } + @Check(CheckType.FAST) + public void checkInput(Input input) { + Reactor parent = (Reactor) input.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); + } + checkName(input.getName(), Literals.VARIABLE__NAME); + if (target.requiresTypes) { + if (input.getType() == null) { + error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - @Check(CheckType.NORMAL) - public void updateModelInfo(Model model) { - info.update(model, errorReporter); + // mutable has no meaning in C++ + if (input.isMutable() && this.target == Target.CPP) { + warning( + "The mutable qualifier has no meaning for the C++ target and should be removed. " + + "In C++, any value can be made mutable by calling get_mutable_copy().", + Literals.INPUT__MUTABLE); } - @Check(CheckType.FAST) - public void checkOutput(Output output) { - Reactor parent = (Reactor)output.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); - } - checkName(output.getName(), Literals.VARIABLE__NAME); - if (this.target.requiresTypes) { - if (output.getType() == null) { - error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); - } - } + // Variable width multiports are not supported (yet?). + if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } + + @Check(CheckType.FAST) + public void checkInstantiation(Instantiation instantiation) { + checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); + Reactor reactor = toDefinition(instantiation.getReactorClass()); + if (reactor.isMain() || reactor.isFederated()) { + error( + "Cannot instantiate a main (or federated) reactor: " + + instantiation.getReactorClass().getName(), + Literals.INSTANTIATION__REACTOR_CLASS); + } - // Variable width multiports are not supported (yet?). - if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } + // Report error if this instantiation is part of a cycle. + // FIXME: improve error message. + // FIXME: Also report if there exists a cycle within. + if (this.info.instantiationGraph.getCycles().size() > 0) { + for (Set cycle : this.info.instantiationGraph.getCycles()) { + Reactor container = (Reactor) instantiation.eContainer(); + if (cycle.contains(container) && cycle.contains(reactor)) { + List names = new ArrayList<>(); + for (Reactor r : cycle) { + names.add(r.getName()); + } + + error( + "Instantiation is part of a cycle: " + String.join(", ", names) + ".", + Literals.INSTANTIATION__REACTOR_CLASS); + } + } + } + // Variable width multiports are not supported (yet?). + if (instantiation.getWidthSpec() != null && instantiation.getWidthSpec().isOfVariableLength()) { + if (isCBasedTarget()) { + warning( + "Variable-width banks are for internal use only.", Literals.INSTANTIATION__WIDTH_SPEC); + } else { + error("Variable-width banks are not supported.", Literals.INSTANTIATION__WIDTH_SPEC); + } + } + } + + /** Check target parameters, which are key-value pairs. */ + @Check(CheckType.FAST) + public void checkKeyValuePair(KeyValuePair param) { + // Check only if the container's container is a Target. + if (param.eContainer().eContainer() instanceof TargetDecl) { + TargetProperty prop = TargetProperty.forName(param.getName()); + + // Make sure the key is valid. + if (prop == null) { + String options = + TargetProperty.getOptions().stream() + .map(p -> p.description) + .sorted() + .collect(Collectors.joining(", ")); + warning( + "Unrecognized target parameter: " + + param.getName() + + ". Recognized parameters are: " + + options, + Literals.KEY_VALUE_PAIR__NAME); + } else { + // Check whether the property is supported by the target. + if (!prop.supportedBy.contains(this.target)) { + warning( + "The target parameter: " + + param.getName() + + " is not supported by the " + + this.target + + " target and will thus be ignored.", + Literals.KEY_VALUE_PAIR__NAME); + } + + // Report problem with the assigned value. + prop.type.check(param.getValue(), param.getName(), this); + } + + for (String it : targetPropertyErrors) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyErrors.clear(); + + for (String it : targetPropertyWarnings) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyWarnings.clear(); + } + } + + @Check(CheckType.FAST) + public void checkModel(Model model) { + // Since we're doing a fast check, we only want to update + // if the model info hasn't been initialized yet. If it has, + // we use the old information and update it during a normal + // check (see below). + if (!info.updated) { + info.update(model, errorReporter); + } + } + + @Check(CheckType.NORMAL) + public void updateModelInfo(Model model) { + info.update(model, errorReporter); + } + + @Check(CheckType.FAST) + public void checkOutput(Output output) { + Reactor parent = (Reactor) output.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); + } + checkName(output.getName(), Literals.VARIABLE__NAME); + if (this.target.requiresTypes) { + if (output.getType() == null) { + error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - @Check(CheckType.FAST) - public void checkParameter(Parameter param) { - checkName(param.getName(), Literals.PARAMETER__NAME); + // Variable width multiports are not supported (yet?). + if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } - if (param.getInit() == null) { - // todo make initialization non-mandatory - // https://github.com/lf-lang/lingua-franca/issues/623 - error("Parameter must have a default value.", Literals.PARAMETER__INIT); - return; - } + @Check(CheckType.FAST) + public void checkParameter(Parameter param) { + checkName(param.getName(), Literals.PARAMETER__NAME); - if (this.target.requiresTypes) { - // Report missing target type. param.inferredType.undefine - if (ASTUtils.getInferredType(param).isUndefined()) { - error("Type declaration missing.", Literals.PARAMETER__TYPE); - } - } + if (param.getInit() == null) { + // todo make initialization non-mandatory + // https://github.com/lf-lang/lingua-franca/issues/623 + error("Parameter must have a default value.", Literals.PARAMETER__INIT); + return; + } - if (param.getType() != null) { - typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); - } + if (this.target.requiresTypes) { + // Report missing target type. param.inferredType.undefine + if (ASTUtils.getInferredType(param).isUndefined()) { + error("Type declaration missing.", Literals.PARAMETER__TYPE); + } + } - if (param.getInit() != null) { - for (Expression expr : param.getInit().getExprs()) { - if (expr instanceof ParameterReference) { - // Initialization using parameters is forbidden. - error("Parameter cannot be initialized using parameter.", - Literals.PARAMETER__INIT); - } - } - } + if (param.getType() != null) { + typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); + } - if (this.target == Target.CPP) { - EObject container = param.eContainer(); - Reactor reactor = (Reactor) container; - if (reactor.isMain()) { - // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); - if (cliParams.contains(param.getName())) { - error("Parameter '" + param.getName() - + "' is already in use as command line argument by Lingua Franca,", - Literals.PARAMETER__NAME); - } - } + if (param.getInit() != null) { + for (Expression expr : param.getInit().getExprs()) { + if (expr instanceof ParameterReference) { + // Initialization using parameters is forbidden. + error("Parameter cannot be initialized using parameter.", Literals.PARAMETER__INIT); } + } + } - if (isCBasedTarget() && - this.info.overflowingParameters.contains(param)) { - error( - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.PARAMETER__INIT); - } - + if (this.target == Target.CPP) { + EObject container = param.eContainer(); + Reactor reactor = (Reactor) container; + if (reactor.isMain()) { + // we need to check for the cli parameters that are always taken + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); + if (cliParams.contains(param.getName())) { + error( + "Parameter '" + + param.getName() + + "' is already in use as command line argument by Lingua Franca,", + Literals.PARAMETER__NAME); + } + } } - @Check(CheckType.FAST) - public void checkPreamble(Preamble preamble) { - if (this.target == Target.CPP) { - if (preamble.getVisibility() == Visibility.NONE) { - error( - "Preambles for the C++ target need a visibility qualifier (private or public)!", - Literals.PREAMBLE__VISIBILITY - ); - } else if (preamble.getVisibility() == Visibility.PRIVATE) { - EObject container = preamble.eContainer(); - if (container != null && container instanceof Reactor) { - Reactor reactor = (Reactor) container; - if (isGeneric(reactor)) { - warning( - "Private preambles in generic reactors are not truly private. " + - "Since the generated code is placed in a *_impl.hh file, it will " + - "be visible on the public interface. Consider using a public " + - "preamble within the reactor or a private preamble on file scope.", - Literals.PREAMBLE__VISIBILITY); - } - } - } - } else if (preamble.getVisibility() != Visibility.NONE) { + if (isCBasedTarget() && this.info.overflowingParameters.contains(param)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds.", + Literals.PARAMETER__INIT); + } + } + + @Check(CheckType.FAST) + public void checkPreamble(Preamble preamble) { + if (this.target == Target.CPP) { + if (preamble.getVisibility() == Visibility.NONE) { + error( + "Preambles for the C++ target need a visibility qualifier (private or public)!", + Literals.PREAMBLE__VISIBILITY); + } else if (preamble.getVisibility() == Visibility.PRIVATE) { + EObject container = preamble.eContainer(); + if (container != null && container instanceof Reactor) { + Reactor reactor = (Reactor) container; + if (isGeneric(reactor)) { warning( - String.format("The %s qualifier has no meaning for the %s target. It should be removed.", - preamble.getVisibility(), this.target.name()), - Literals.PREAMBLE__VISIBILITY - ); - } + "Private preambles in generic reactors are not truly private. " + + "Since the generated code is placed in a *_impl.hh file, it will " + + "be visible on the public interface. Consider using a public " + + "preamble within the reactor or a private preamble on file scope.", + Literals.PREAMBLE__VISIBILITY); + } + } + } + } else if (preamble.getVisibility() != Visibility.NONE) { + warning( + String.format( + "The %s qualifier has no meaning for the %s target. It should be removed.", + preamble.getVisibility(), this.target.name()), + Literals.PREAMBLE__VISIBILITY); } + } - @Check(CheckType.FAST) - public void checkReaction(Reaction reaction) { - - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); - } - HashSet triggers = new HashSet<>(); - // Make sure input triggers have no container and output sources do. - for (TriggerRef trigger : reaction.getTriggers()) { - if (trigger instanceof VarRef) { - VarRef triggerVarRef = (VarRef) trigger; - triggers.add(triggerVarRef.getVariable()); - if (triggerVarRef instanceof Input) { - if (triggerVarRef.getContainer() != null) { - error(String.format("Cannot have an input of a contained reactor as a trigger: %s.%s", triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } else if (triggerVarRef.getVariable() instanceof Output) { - if (triggerVarRef.getContainer() == null) { - error(String.format("Cannot have an output of this reactor as a trigger: %s", triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } - } - } + @Check(CheckType.FAST) + public void checkReaction(Reaction reaction) { - // Make sure input sources have no container and output sources do. - // Also check that a source is not already listed as a trigger. - for (VarRef source : reaction.getSources()) { - if (triggers.contains(source.getVariable())) { - error(String.format("Source is already listed as a trigger: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - if (source.getVariable() instanceof Input) { - if (source.getContainer() != null) { - error(String.format("Cannot have an input of a contained reactor as a source: %s.%s", source.getContainer().getName(), source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } else if (source.getVariable() instanceof Output) { - if (source.getContainer() == null) { - error(String.format("Cannot have an output of this reactor as a source: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } - } - - // Make sure output effects have no container and input effects do. - for (VarRef effect : reaction.getEffects()) { - if (effect.getVariable() instanceof Input) { - if (effect.getContainer() == null) { - error(String.format("Cannot have an input of this reactor as an effect: %s", effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } else if (effect.getVariable() instanceof Output) { - if (effect.getContainer() != null) { - error(String.format("Cannot have an output of a contained reactor as an effect: %s.%s", effect.getContainer().getName(), effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } - } - - // // Report error if this reaction is part of a cycle. - Set> cycles = this.info.topologyCycles(); - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - boolean reactionInCycle = false; - for (NamedInstance it : cycles) { - if (it.getDefinition().equals(reaction)) { - reactionInCycle = true; - break; - } - } - if (reactionInCycle) { - // Report involved triggers. - List trigs = new ArrayList<>(); - for (TriggerRef t : reaction.getTriggers()) { - if (!(t instanceof VarRef)) { - continue; - } - VarRef tVarRef = (VarRef) t; - boolean triggerExistsInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(tVarRef.getVariable())) { - triggerExistsInCycle = true; - break; - } - } - if (triggerExistsInCycle) { - trigs.add(toOriginalText(tVarRef)); - } - } - if (trigs.size() > 0) { - error(String.format("Reaction triggers involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", trigs)), - Literals.REACTION__TRIGGERS); - } - - // Report involved sources. - List sources = new ArrayList<>(); - for (VarRef t : reaction.getSources()) { - boolean sourceExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - sourceExistInCycle = true; - break; - } - } - if (sourceExistInCycle) { - sources.add(toOriginalText(t)); - } - } - if (sources.size() > 0) { - error(String.format("Reaction sources involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", sources)), - Literals.REACTION__SOURCES); - } - - // Report involved effects. - List effects = new ArrayList<>(); - for (VarRef t : reaction.getEffects()) { - boolean effectExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - effectExistInCycle = true; - break; - } - } - if (effectExistInCycle) { - effects.add(toOriginalText(t)); - } - } - if (effects.size() > 0) { - error(String.format("Reaction effects involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", effects)), - Literals.REACTION__EFFECTS); - } - - if (trigs.size() + sources.size() == 0) { - error( - String.format("Cyclic dependency due to preceding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction) - ); - } else if (effects.size() == 0) { - error( - String.format("Cyclic dependency due to succeeding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction) - ); - } - // Not reporting reactions that are part of cycle _only_ due to reaction ordering. - // Moving them won't help solve the problem. - } - // FIXME: improve error message. + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); } - - @Check(CheckType.FAST) - public void checkReactor(Reactor reactor) throws IOException { - Set superClasses = ASTUtils.superClasses(reactor); - if (superClasses == null) { + HashSet triggers = new HashSet<>(); + // Make sure input triggers have no container and output sources do. + for (TriggerRef trigger : reaction.getTriggers()) { + if (trigger instanceof VarRef) { + VarRef triggerVarRef = (VarRef) trigger; + triggers.add(triggerVarRef.getVariable()); + if (triggerVarRef instanceof Input) { + if (triggerVarRef.getContainer() != null) { error( - "Problem with superclasses: Either they form a cycle or are not defined", - Literals.REACTOR_DECL__NAME - ); - // Continue checks, but without any superclasses. - superClasses = new LinkedHashSet<>(); - } - String name = FileUtil.nameWithoutExtension(reactor.eResource()); - if (reactor.getName() == null) { - if (!reactor.isFederated() && !reactor.isMain()) { - error( - "Reactor must be named.", - Literals.REACTOR_DECL__NAME - ); - // Prevent NPE in tests below. - return; - } - } - TreeIterator iter = reactor.eResource().getAllContents(); - if (reactor.isFederated() || reactor.isMain()) { - if(reactor.getName() != null && !reactor.getName().equals(name)) { - // Make sure that if the name is given, it matches the expected name. - error( - "Name of main reactor must match the file name (or be omitted).", - Literals.REACTOR_DECL__NAME - ); - } - // Do not allow multiple main/federated reactors. - int nMain = countMainOrFederated(iter); - if (nMain > 1) { - EAttribute attribute = Literals.REACTOR__MAIN; - if (reactor.isFederated()) { - attribute = Literals.REACTOR__FEDERATED; - } - error( - "Multiple definitions of main or federated reactor.", - attribute - ); - } - } else { - // Not federated or main. - int nMain = countMainOrFederated(iter); - if (nMain > 0 && reactor.getName().equals(name)) { - error( - "Name conflict with main reactor.", - Literals.REACTOR_DECL__NAME - ); - } - } - - // Check for illegal names. - checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); - - // C++ reactors may not be called 'preamble' - if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { + String.format( + "Cannot have an input of a contained reactor as a trigger: %s.%s", + triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } else if (triggerVarRef.getVariable() instanceof Output) { + if (triggerVarRef.getContainer() == null) { error( - "Reactor cannot be named '" + reactor.getName() + "'", - Literals.REACTOR_DECL__NAME - ); - } - - if (reactor.getHost() != null) { - if (!reactor.isFederated()) { - error( - "Cannot assign a host to reactor '" + reactor.getName() + - "' because it is not federated.", - Literals.REACTOR__HOST - ); - } + String.format( + "Cannot have an output of this reactor as a trigger: %s", + triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } } + } + } - List variables = new ArrayList<>(); - variables.addAll(reactor.getInputs()); - variables.addAll(reactor.getOutputs()); - variables.addAll(reactor.getActions()); - variables.addAll(reactor.getTimers()); - - // Perform checks on super classes. - for (Reactor superClass : superClasses) { - HashSet conflicts = new HashSet<>(); - - // Detect input conflicts - checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); - // Detect conflicts - for (Timer timer : superClass.getTimers()) { - List filteredVariables = new ArrayList<>(variables); - filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); - if (hasNameConflict(timer, filteredVariables)) { - conflicts.add(timer); - } else { - variables.add(timer); - } - } + // Make sure input sources have no container and output sources do. + // Also check that a source is not already listed as a trigger. + for (VarRef source : reaction.getSources()) { + if (triggers.contains(source.getVariable())) { + error( + String.format( + "Source is already listed as a trigger: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + if (source.getVariable() instanceof Input) { + if (source.getContainer() != null) { + error( + String.format( + "Cannot have an input of a contained reactor as a source: %s.%s", + source.getContainer().getName(), source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } else if (source.getVariable() instanceof Output) { + if (source.getContainer() == null) { + error( + String.format( + "Cannot have an output of this reactor as a source: %s", + source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } + } - // Report conflicts. - if (conflicts.size() > 0) { - List names = new ArrayList<>(); - for (Variable it : conflicts) { - names.add(it.getName()); - } - error( - String.format("Cannot extend %s due to the following conflicts: %s.", - superClass.getName(), String.join(",", names)), - Literals.REACTOR__SUPER_CLASSES - ); - } - } + // Make sure output effects have no container and input effects do. + for (VarRef effect : reaction.getEffects()) { + if (effect.getVariable() instanceof Input) { + if (effect.getContainer() == null) { + error( + String.format( + "Cannot have an input of this reactor as an effect: %s", + effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } else if (effect.getVariable() instanceof Output) { + if (effect.getContainer() != null) { + error( + String.format( + "Cannot have an output of a contained reactor as an effect: %s.%s", + effect.getContainer().getName(), effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } + } + // // Report error if this reaction is part of a cycle. + Set> cycles = this.info.topologyCycles(); + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + boolean reactionInCycle = false; + for (NamedInstance it : cycles) { + if (it.getDefinition().equals(reaction)) { + reactionInCycle = true; + break; + } + } + if (reactionInCycle) { + // Report involved triggers. + List trigs = new ArrayList<>(); + for (TriggerRef t : reaction.getTriggers()) { + if (!(t instanceof VarRef)) { + continue; + } + VarRef tVarRef = (VarRef) t; + boolean triggerExistsInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(tVarRef.getVariable())) { + triggerExistsInCycle = true; + break; + } + } + if (triggerExistsInCycle) { + trigs.add(toOriginalText(tVarRef)); + } + } + if (trigs.size() > 0) { + error( + String.format( + "Reaction triggers involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", trigs)), + Literals.REACTION__TRIGGERS); + } + + // Report involved sources. + List sources = new ArrayList<>(); + for (VarRef t : reaction.getSources()) { + boolean sourceExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + sourceExistInCycle = true; + break; + } + } + if (sourceExistInCycle) { + sources.add(toOriginalText(t)); + } + } + if (sources.size() > 0) { + error( + String.format( + "Reaction sources involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", sources)), + Literals.REACTION__SOURCES); + } + + // Report involved effects. + List effects = new ArrayList<>(); + for (VarRef t : reaction.getEffects()) { + boolean effectExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + effectExistInCycle = true; + break; + } + } + if (effectExistInCycle) { + effects.add(toOriginalText(t)); + } + } + if (effects.size() > 0) { + error( + String.format( + "Reaction effects involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", effects)), + Literals.REACTION__EFFECTS); + } + + if (trigs.size() + sources.size() == 0) { + error( + String.format( + "Cyclic dependency due to preceding reaction. Consider reordering reactions within" + + " reactor %s to avoid causality loop.", + reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction)); + } else if (effects.size() == 0) { + error( + String.format( + "Cyclic dependency due to succeeding reaction. Consider reordering reactions within" + + " reactor %s to avoid causality loop.", + reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction)); + } + // Not reporting reactions that are part of cycle _only_ due to reaction ordering. + // Moving them won't help solve the problem. + } + // FIXME: improve error message. + } + + @Check(CheckType.FAST) + public void checkReactor(Reactor reactor) throws IOException { + Set superClasses = ASTUtils.superClasses(reactor); + if (superClasses == null) { + error( + "Problem with superclasses: Either they form a cycle or are not defined", + Literals.REACTOR_DECL__NAME); + // Continue checks, but without any superclasses. + superClasses = new LinkedHashSet<>(); + } + String name = FileUtil.nameWithoutExtension(reactor.eResource()); + if (reactor.getName() == null) { + if (!reactor.isFederated() && !reactor.isMain()) { + error("Reactor must be named.", Literals.REACTOR_DECL__NAME); + // Prevent NPE in tests below. + return; + } + } + TreeIterator iter = reactor.eResource().getAllContents(); + if (reactor.isFederated() || reactor.isMain()) { + if (reactor.getName() != null && !reactor.getName().equals(name)) { + // Make sure that if the name is given, it matches the expected name. + error( + "Name of main reactor must match the file name (or be omitted).", + Literals.REACTOR_DECL__NAME); + } + // Do not allow multiple main/federated reactors. + int nMain = countMainOrFederated(iter); + if (nMain > 1) { + EAttribute attribute = Literals.REACTOR__MAIN; if (reactor.isFederated()) { - FedValidator.validateFederatedReactor(reactor, this.errorReporter); - } + attribute = Literals.REACTOR__FEDERATED; + } + error("Multiple definitions of main or federated reactor.", attribute); + } + } else { + // Not federated or main. + int nMain = countMainOrFederated(iter); + if (nMain > 0 && reactor.getName().equals(name)) { + error("Name conflict with main reactor.", Literals.REACTOR_DECL__NAME); + } } - /** - * Check if the requested serialization is supported. - */ - @Check(CheckType.FAST) - public void checkSerializer(Serializer serializer) { - boolean isValidSerializer = false; - for (SupportedSerializers method : SupportedSerializers.values()) { - if (method.name().equalsIgnoreCase(serializer.getType())){ - isValidSerializer = true; - } - } - - if (!isValidSerializer) { - error( - "Serializer can be " + Arrays.asList(SupportedSerializers.values()), - Literals.SERIALIZER__TYPE - ); - } + // Check for illegal names. + checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); + + // C++ reactors may not be called 'preamble' + if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { + error("Reactor cannot be named '" + reactor.getName() + "'", Literals.REACTOR_DECL__NAME); } - @Check(CheckType.FAST) - public void checkState(StateVar stateVar) { - checkName(stateVar.getName(), Literals.STATE_VAR__NAME); - if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { - typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); - } + if (reactor.getHost() != null) { + if (!reactor.isFederated()) { + error( + "Cannot assign a host to reactor '" + + reactor.getName() + + "' because it is not federated.", + Literals.REACTOR__HOST); + } + } - if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { - // Report if a type is missing - error("State must have a type.", Literals.STATE_VAR__TYPE); - } + List variables = new ArrayList<>(); + variables.addAll(reactor.getInputs()); + variables.addAll(reactor.getOutputs()); + variables.addAll(reactor.getActions()); + variables.addAll(reactor.getTimers()); + + // Perform checks on super classes. + for (Reactor superClass : superClasses) { + HashSet conflicts = new HashSet<>(); + + // Detect input conflicts + checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); + // Detect conflicts + for (Timer timer : superClass.getTimers()) { + List filteredVariables = new ArrayList<>(variables); + filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); + if (hasNameConflict(timer, filteredVariables)) { + conflicts.add(timer); + } else { + variables.add(timer); + } + } + + // Report conflicts. + if (conflicts.size() > 0) { + List names = new ArrayList<>(); + for (Variable it : conflicts) { + names.add(it.getName()); + } + error( + String.format( + "Cannot extend %s due to the following conflicts: %s.", + superClass.getName(), String.join(",", names)), + Literals.REACTOR__SUPER_CLASSES); + } + } - if (isCBasedTarget() - && ASTUtils.isListInitializer(stateVar.getInit()) - && stateVar.getInit().getExprs().stream().anyMatch(it -> it instanceof ParameterReference)) { - // In C, if initialization is done with a list, elements cannot - // refer to parameters. - error("List items cannot refer to a parameter.", - Literals.STATE_VAR__INIT); - } + if (reactor.isFederated()) { + FedValidator.validateFederatedReactor(reactor, this.errorReporter); + } + } + + /** Check if the requested serialization is supported. */ + @Check(CheckType.FAST) + public void checkSerializer(Serializer serializer) { + boolean isValidSerializer = false; + for (SupportedSerializers method : SupportedSerializers.values()) { + if (method.name().equalsIgnoreCase(serializer.getType())) { + isValidSerializer = true; + } + } + if (!isValidSerializer) { + error( + "Serializer can be " + Arrays.asList(SupportedSerializers.values()), + Literals.SERIALIZER__TYPE); } + } - @Check(CheckType.FAST) - public void checkSTPOffset(STP stp) { - if (isCBasedTarget() && - this.info.overflowingSTP.contains(stp)) { - error( - "STP offset exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.STP__VALUE); - } + @Check(CheckType.FAST) + public void checkState(StateVar stateVar) { + checkName(stateVar.getName(), Literals.STATE_VAR__NAME); + if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { + typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); } - @Check(CheckType.FAST) - public void checkTargetDecl(TargetDecl target) throws IOException { - Optional targetOpt = Target.forName(target.getName()); - if (targetOpt.isEmpty()) { - error("Unrecognized target: " + target.getName(), - Literals.TARGET_DECL__NAME); - } else { - this.target = targetOpt.get(); - } - String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); - if (Character.isDigit(lfFileName.charAt(0))) { - errorReporter.reportError("LF file names must not start with a number"); - } + if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { + // Report if a type is missing + error("State must have a type.", Literals.STATE_VAR__TYPE); } - /** - * Check for consistency of the target properties, which are - * defined as KeyValuePairs. - * - * @param targetProperties The target properties defined - * in the current Lingua Franca program. - */ - @Check(CheckType.EXPENSIVE) - public void checkTargetProperties(KeyValuePairs targetProperties) { - validateFastTargetProperty(targetProperties); - validateClockSyncTargetProperties(targetProperties); - validateSchedulerTargetProperties(targetProperties); - validateRos2TargetProperties(targetProperties); - validateKeepalive(targetProperties); - } - - private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { - List properties = targetProperties.getPairs().stream() + if (isCBasedTarget() + && ASTUtils.isListInitializer(stateVar.getInit()) + && stateVar.getInit().getExprs().stream() + .anyMatch(it -> it instanceof ParameterReference)) { + // In C, if initialization is done with a list, elements cannot + // refer to parameters. + error("List items cannot refer to a parameter.", Literals.STATE_VAR__INIT); + } + } + + @Check(CheckType.FAST) + public void checkSTPOffset(STP stp) { + if (isCBasedTarget() && this.info.overflowingSTP.contains(stp)) { + error( + "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.STP__VALUE); + } + } + + @Check(CheckType.FAST) + public void checkTargetDecl(TargetDecl target) throws IOException { + Optional targetOpt = Target.forName(target.getName()); + if (targetOpt.isEmpty()) { + error("Unrecognized target: " + target.getName(), Literals.TARGET_DECL__NAME); + } else { + this.target = targetOpt.get(); + } + String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); + if (Character.isDigit(lfFileName.charAt(0))) { + errorReporter.reportError("LF file names must not start with a number"); + } + } + + /** + * Check for consistency of the target properties, which are defined as KeyValuePairs. + * + * @param targetProperties The target properties defined in the current Lingua Franca program. + */ + @Check(CheckType.EXPENSIVE) + public void checkTargetProperties(KeyValuePairs targetProperties) { + validateFastTargetProperty(targetProperties); + validateClockSyncTargetProperties(targetProperties); + validateSchedulerTargetProperties(targetProperties); + validateRos2TargetProperties(targetProperties); + validateKeepalive(targetProperties); + } + + private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { + List properties = + targetProperties.getPairs().stream() .filter(pair -> pair.getName().equals(property.description)) .toList(); - assert (properties.size() <= 1); - return properties.size() > 0 ? properties.get(0) : null; - } - private void validateFastTargetProperty(KeyValuePairs targetProperties) { - KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); - - if (fastTargetProperty != null) { - // Check for federated - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a federated reactor - if (reactor.isFederated()) { - error( - "The fast target property is incompatible with federated programs.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - break; - } - } - - // Check for physical actions - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a physical action in a reactor - for (Action action : reactor.getActions()) { - if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { - error( - "The fast target property is incompatible with physical actions.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - break; - } - } - } - } - } + assert (properties.size() <= 1); + return properties.size() > 0 ? properties.get(0) : null; + } - private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair clockSyncTargetProperty = getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); + private void validateFastTargetProperty(KeyValuePairs targetProperties) { + KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); - if (clockSyncTargetProperty != null) { - boolean federatedExists = false; - for (Reactor reactor : info.model.getReactors()) { - if (reactor.isFederated()) { - federatedExists = true; - } - } - if (!federatedExists) { - warning( - "The clock-sync target property is incompatible with non-federated programs.", - clockSyncTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - } + if (fastTargetProperty != null) { + // Check for federated + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a federated reactor + if (reactor.isFederated()) { + error( + "The fast target property is incompatible with federated programs.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + break; + } + } + + // Check for physical actions + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a physical action in a reactor + for (Action action : reactor.getActions()) { + if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { + error( + "The fast target property is incompatible with physical actions.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + break; + } } + } } + } - private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair schedulerTargetProperty = getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); - if (schedulerTargetProperty != null) { - String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); - try { - if (!TargetProperty.SchedulerOption.valueOf(schedulerName) - .prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - // Filter reactors that contain at least one reaction that - // has a deadline handler. - if (info.model.getReactors().stream().anyMatch( - // Filter reactors that contain at least one reaction that - // has a deadline handler. - reactor -> ASTUtils.allReactions(reactor).stream().anyMatch( - reaction -> reaction.getDeadline() != null - )) - ) { - warning("This program contains deadlines, but the chosen " - + schedulerName - + " scheduler does not prioritize reaction execution " - + "based on deadlines. This might result in a sub-optimal " - + "scheduling.", schedulerTargetProperty, - Literals.KEY_VALUE_PAIR__VALUE); - } - } - } catch (IllegalArgumentException e) { - // the given scheduler is invalid, but this is already checked by - // checkTargetProperties - } - } - } + private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair clockSyncTargetProperty = + getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); - private void validateKeepalive(KeyValuePairs targetProperties) { - KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); - if (keepalive != null && target == Target.CPP) { - warning("The keepalive property is inferred automatically by the C++ " + - "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); - } + if (clockSyncTargetProperty != null) { + boolean federatedExists = false; + for (Reactor reactor : info.model.getReactors()) { + if (reactor.isFederated()) { + federatedExists = true; + } + } + if (!federatedExists) { + warning( + "The clock-sync target property is incompatible with non-federated programs.", + clockSyncTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + } } - - private void validateRos2TargetProperties(KeyValuePairs targetProperties) { - KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); - KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); - if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { + } + + private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair schedulerTargetProperty = + getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); + if (schedulerTargetProperty != null) { + String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); + try { + if (!TargetProperty.SchedulerOption.valueOf(schedulerName).prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + // Filter reactors that contain at least one reaction that + // has a deadline handler. + if (info.model.getReactors().stream() + .anyMatch( + // Filter reactors that contain at least one reaction that + // has a deadline handler. + reactor -> + ASTUtils.allReactions(reactor).stream() + .anyMatch(reaction -> reaction.getDeadline() != null))) { warning( - "Ignoring ros2-dependencies as ros2 compilation is disabled", - ros2Dependencies, - Literals.KEY_VALUE_PAIR__NAME - ); - } + "This program contains deadlines, but the chosen " + + schedulerName + + " scheduler does not prioritize reaction execution " + + "based on deadlines. This might result in a sub-optimal " + + "scheduling.", + schedulerTargetProperty, + Literals.KEY_VALUE_PAIR__VALUE); + } + } + } catch (IllegalArgumentException e) { + // the given scheduler is invalid, but this is already checked by + // checkTargetProperties + } } - - @Check(CheckType.FAST) - public void checkTimer(Timer timer) { - checkName(timer.getName(), Literals.VARIABLE__NAME); - checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); - checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); + } + + private void validateKeepalive(KeyValuePairs targetProperties) { + KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); + if (keepalive != null && target == Target.CPP) { + warning( + "The keepalive property is inferred automatically by the C++ " + + "runtime and the value given here is ignored", + keepalive, + Literals.KEY_VALUE_PAIR__NAME); } - - @Check(CheckType.FAST) - public void checkType(Type type) { - // FIXME: disallow the use of generics in C - if (this.target == Target.Python) { - if (type != null) { - error( - "Types are not allowed in the Python target", - Literals.TYPE__ID - ); - } - } + } + + private void validateRos2TargetProperties(KeyValuePairs targetProperties) { + KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); + KeyValuePair ros2Dependencies = + getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); + if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { + warning( + "Ignoring ros2-dependencies as ros2 compilation is disabled", + ros2Dependencies, + Literals.KEY_VALUE_PAIR__NAME); } - - @Check(CheckType.FAST) - public void checkVarRef(VarRef varRef) { - // check correct usage of interleaved - if (varRef.isInterleaved()) { - var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); - if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { - error("This target does not support interleaved port references.", Literals.VAR_REF__INTERLEAVED); - } - if (!(varRef.eContainer() instanceof Connection)) { - error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); - } - - if (varRef.getVariable() instanceof Port) { - // This test only works correctly if the variable is actually a port. If it is not a port, other - // validator rules will produce error messages. - if (varRef.getContainer() == null || varRef.getContainer().getWidthSpec() == null || - ((Port) varRef.getVariable()).getWidthSpec() == null - ) { - error("interleaved can only be used for multiports contained within banks.", Literals.VAR_REF__INTERLEAVED); - } - } - } + } + + @Check(CheckType.FAST) + public void checkTimer(Timer timer) { + checkName(timer.getName(), Literals.VARIABLE__NAME); + checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); + checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); + } + + @Check(CheckType.FAST) + public void checkType(Type type) { + // FIXME: disallow the use of generics in C + if (this.target == Target.Python) { + if (type != null) { + error("Types are not allowed in the Python target", Literals.TYPE__ID); + } } - - /** - * Check whether an attribute is supported - * and the validity of the attribute. - * - * @param attr The attribute being checked - */ - @Check(CheckType.FAST) - public void checkAttributes(Attribute attr) { - String name = attr.getAttrName().toString(); - AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); - if (spec == null) { - error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); - return; - } - // Check the validity of the attribute. - spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkVarRef(VarRef varRef) { + // check correct usage of interleaved + if (varRef.isInterleaved()) { + var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); + if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { + error( + "This target does not support interleaved port references.", + Literals.VAR_REF__INTERLEAVED); + } + if (!(varRef.eContainer() instanceof Connection)) { + error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); + } + + if (varRef.getVariable() instanceof Port) { + // This test only works correctly if the variable is actually a port. If it is not a port, + // other + // validator rules will produce error messages. + if (varRef.getContainer() == null + || varRef.getContainer().getWidthSpec() == null + || ((Port) varRef.getVariable()).getWidthSpec() == null) { + error( + "interleaved can only be used for multiports contained within banks.", + Literals.VAR_REF__INTERLEAVED); + } + } } - - @Check(CheckType.FAST) - public void checkWidthSpec(WidthSpec widthSpec) { - if (!this.target.supportsMultiports()) { - error("Multiports and banks are currently not supported by the given target.", + } + + /** + * Check whether an attribute is supported and the validity of the attribute. + * + * @param attr The attribute being checked + */ + @Check(CheckType.FAST) + public void checkAttributes(Attribute attr) { + String name = attr.getAttrName().toString(); + AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); + if (spec == null) { + error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); + return; + } + // Check the validity of the attribute. + spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkWidthSpec(WidthSpec widthSpec) { + if (!this.target.supportsMultiports()) { + error( + "Multiports and banks are currently not supported by the given target.", + Literals.WIDTH_SPEC__TERMS); + } else { + for (WidthTerm term : widthSpec.getTerms()) { + if (term.getParameter() != null) { + if (!this.target.supportsParameterizedWidths()) { + error( + "Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); - } else { - for (WidthTerm term : widthSpec.getTerms()) { - if (term.getParameter() != null) { - if (!this.target.supportsParameterizedWidths()) { - error("Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getPort() != null) { - // Widths given with `widthof()` are not supported (yet?). - // This feature is currently only used for after delays. - error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); - } else if (term.getCode() != null) { - if (this.target != Target.CPP) { - error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getWidth() < 0) { - error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); - } - } - } + } + } else if (term.getPort() != null) { + // Widths given with `widthof()` are not supported (yet?). + // This feature is currently only used for after delays. + error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); + } else if (term.getCode() != null) { + if (this.target != Target.CPP) { + error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getWidth() < 0) { + error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); + } + } } - - @Check(CheckType.FAST) - public void checkReactorIconAttribute(Reactor reactor) { - var path = AttributeUtils.getIconPath(reactor); - if (path != null) { - var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); - // Check file extension - var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); - var extensionStrart = path.lastIndexOf("."); - var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; - if (!validExtensions.contains(extension.toLowerCase())) { - warning("File extension '" + extension + "' is not supported. Provide any of: " + String.join(", ", validExtensions), - param, Literals.ATTR_PARM__VALUE); - return; - } - - // Check file location - var iconLocation = FileUtil.locateFile(path, reactor.eResource()); - if (iconLocation == null) { - warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); - } - if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) && !(new File(iconLocation.getPath()).exists())) { - warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); - } - } + } + + @Check(CheckType.FAST) + public void checkReactorIconAttribute(Reactor reactor) { + var path = AttributeUtils.getIconPath(reactor); + if (path != null) { + var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); + // Check file extension + var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); + var extensionStrart = path.lastIndexOf("."); + var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; + if (!validExtensions.contains(extension.toLowerCase())) { + warning( + "File extension '" + + extension + + "' is not supported. Provide any of: " + + String.join(", ", validExtensions), + param, + Literals.ATTR_PARM__VALUE); + return; + } + + // Check file location + var iconLocation = FileUtil.locateFile(path, reactor.eResource()); + if (iconLocation == null) { + warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); + } + if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) + && !(new File(iconLocation.getPath()).exists())) { + warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); + } } - - @Check(CheckType.FAST) - public void checkInitialMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); - if (initialModesCount == 0) { - error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); - } else if (initialModesCount > 1) { - reactor.getModes().stream().filter(m -> m.isInitial()).skip(1).forEach(m -> { - error("A modal reactor can only have one initial mode.", - Literals.REACTOR__MODES, reactor.getModes().indexOf(m)); + } + + @Check(CheckType.FAST) + public void checkInitialMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); + if (initialModesCount == 0) { + error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); + } else if (initialModesCount > 1) { + reactor.getModes().stream() + .filter(m -> m.isInitial()) + .skip(1) + .forEach( + m -> { + error( + "A modal reactor can only have one initial mode.", + Literals.REACTOR__MODES, + reactor.getModes().indexOf(m)); }); - } - } + } } - - @Check(CheckType.FAST) - public void checkModeStateNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var stateVar : mode.getStateVars()) { - if (names.contains(stateVar.getName())) { - error(String.format("Duplicate state variable '%s'. (State variables are currently scoped on reactor level not modes)", - stateVar.getName()), stateVar, Literals.STATE_VAR__NAME); - } - names.add(stateVar.getName()); - } - } - } + } + + @Check(CheckType.FAST) + public void checkModeStateNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var stateVar : mode.getStateVars()) { + if (names.contains(stateVar.getName())) { + error( + String.format( + "Duplicate state variable '%s'. (State variables are currently scoped on" + + " reactor level not modes)", + stateVar.getName()), + stateVar, + Literals.STATE_VAR__NAME); + } + names.add(stateVar.getName()); + } + } } - - @Check(CheckType.FAST) - public void checkModeTimerNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var timer : mode.getTimers()) { - if (names.contains(timer.getName())) { - error(String.format("Duplicate Timer '%s'. (Timers are currently scoped on reactor level not modes)", - timer.getName()), timer, Literals.VARIABLE__NAME); - } - names.add(timer.getName()); - } - } - } + } + + @Check(CheckType.FAST) + public void checkModeTimerNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var timer : mode.getTimers()) { + if (names.contains(timer.getName())) { + error( + String.format( + "Duplicate Timer '%s'. (Timers are currently scoped on reactor level not" + + " modes)", + timer.getName()), + timer, + Literals.VARIABLE__NAME); + } + names.add(timer.getName()); + } + } } - - @Check(CheckType.FAST) - public void checkModeActionNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var action : mode.getActions()) { - if (names.contains(action.getName())) { - error(String.format("Duplicate Action '%s'. (Actions are currently scoped on reactor level not modes)", - action.getName()), action, Literals.VARIABLE__NAME); - } - names.add(action.getName()); - } - } - } + } + + @Check(CheckType.FAST) + public void checkModeActionNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var action : mode.getActions()) { + if (names.contains(action.getName())) { + error( + String.format( + "Duplicate Action '%s'. (Actions are currently scoped on reactor level not" + + " modes)", + action.getName()), + action, + Literals.VARIABLE__NAME); + } + names.add(action.getName()); + } + } } - - @Check(CheckType.FAST) - public void checkModeInstanceNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var instantiation : mode.getInstantiations()) { - if (names.contains(instantiation.getName())) { - error(String.format("Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor level not modes)", - instantiation.getName()), instantiation, Literals.INSTANTIATION__NAME); - } - names.add(instantiation.getName()); - } - } - } + } + + @Check(CheckType.FAST) + public void checkModeInstanceNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var instantiation : mode.getInstantiations()) { + if (names.contains(instantiation.getName())) { + error( + String.format( + "Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor" + + " level not modes)", + instantiation.getName()), + instantiation, + Literals.INSTANTIATION__NAME); + } + names.add(instantiation.getName()); + } + } } - - @Check(CheckType.FAST) - public void checkMissingStateResetInMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var resetModes = new HashSet(); - // Collect all modes that may be reset - for (var m : reactor.getModes()) { - for (var r : m.getReactions()) { - for (var e : r.getEffects()) { - if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { - resetModes.add((Mode) e.getVariable()); - } - } - } - } - for (var m : resetModes) { - // Check state variables in this mode - if (!m.getStateVars().isEmpty()) { - var hasResetReaction = m.getReactions().stream().anyMatch( - r -> r.getTriggers().stream().anyMatch( - t -> (t instanceof BuiltinTriggerRef && - ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - for (var s : m.getStateVars()) { - if (!s.isReset()) { - error("State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction.", - m, Literals.MODE__STATE_VARS, m.getStateVars().indexOf(s)); - } - } - } + } + + @Check(CheckType.FAST) + public void checkMissingStateResetInMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var resetModes = new HashSet(); + // Collect all modes that may be reset + for (var m : reactor.getModes()) { + for (var r : m.getReactions()) { + for (var e : r.getEffects()) { + if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { + resetModes.add((Mode) e.getVariable()); + } + } + } + } + for (var m : resetModes) { + // Check state variables in this mode + if (!m.getStateVars().isEmpty()) { + var hasResetReaction = + m.getReactions().stream() + .anyMatch( + r -> + r.getTriggers().stream() + .anyMatch( + t -> + (t instanceof BuiltinTriggerRef + && ((BuiltinTriggerRef) t).getType() + == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + for (var s : m.getStateVars()) { + if (!s.isReset()) { + error( + "State variable is not reset upon mode entry. It is neither marked for" + + " automatic reset nor is there a reset reaction.", + m, + Literals.MODE__STATE_VARS, + m.getStateVars().indexOf(s)); + } + } + } + } + // Check state variables in instantiated reactors + if (!m.getInstantiations().isEmpty()) { + for (var i : m.getInstantiations()) { + var error = new LinkedHashSet(); + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty()) { + var check = toCheck.pop(); + checked.add(check); + if (!check.getStateVars().isEmpty()) { + var hasResetReaction = + check.getReactions().stream() + .anyMatch( + r -> + r.getTriggers().stream() + .anyMatch( + t -> + (t instanceof BuiltinTriggerRef + && ((BuiltinTriggerRef) t).getType() + == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + // Add state vars that are not self-resetting to the error + check.getStateVars().stream() + .filter(s -> !s.isReset()) + .forEachOrdered(error::add); } - // Check state variables in instantiated reactors - if (!m.getInstantiations().isEmpty()) { - for (var i : m.getInstantiations()) { - var error = new LinkedHashSet(); - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty()) { - var check = toCheck.pop(); - checked.add(check); - if (!check.getStateVars().isEmpty()) { - var hasResetReaction = check.getReactions().stream().anyMatch( - r -> r.getTriggers().stream().anyMatch( - t -> (t instanceof BuiltinTriggerRef && - ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - // Add state vars that are not self-resetting to the error - check.getStateVars().stream().filter(s -> !s.isReset()).forEachOrdered(error::add); - } - } - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } - } - } - if (!error.isEmpty()) { - error("This reactor contains state variables that are not reset upon mode entry: " - + error.stream().map(e -> e.getName() + " in " - + ASTUtils.getEnclosingReactor(e).getName()).collect(Collectors.joining(", ")) - + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " - + "It is usafe to instatiate this reactor inside a mode entered with reset.", - m, Literals.MODE__INSTANTIATIONS, - m.getInstantiations().indexOf(i)); - } - } + } + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); } - } - } + } + } + if (!error.isEmpty()) { + error( + "This reactor contains state variables that are not reset upon mode entry: " + + error.stream() + .map( + e -> e.getName() + " in " + ASTUtils.getEnclosingReactor(e).getName()) + .collect(Collectors.joining(", ")) + + ".\n" + + "The state variables are neither marked for automatic reset nor have a" + + " dedicated reset reaction. It is usafe to instatiate this reactor inside a" + + " mode entered with reset.", + m, + Literals.MODE__INSTANTIATIONS, + m.getInstantiations().indexOf(i)); + } + } + } + } } - - @Check(CheckType.FAST) - public void checkStateResetWithoutInitialValue(StateVar state) { - if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { - error("The state variable can not be automatically reset without an initial value.", state, Literals.STATE_VAR__RESET); - } + } + + @Check(CheckType.FAST) + public void checkStateResetWithoutInitialValue(StateVar state) { + if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { + error( + "The state variable can not be automatically reset without an initial value.", + state, + Literals.STATE_VAR__RESET); } - - @Check(CheckType.FAST) - public void checkUnspecifiedTransitionType(Reaction reaction) { - for (var effect : reaction.getEffects()) { - var variable = effect.getVariable(); - if (variable instanceof Mode) { - // The transition type is always set to default by Xtext. - // Hence, check if there is an explicit node for the transition type in the AST. - var transitionAssignment = NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); - if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. - var mode = (Mode) variable; - // Check if reset or history transition would make a difference. - var makesDifference = !mode.getStateVars().isEmpty() - || !mode.getTimers().isEmpty() - || !mode.getActions().isEmpty() - || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); - if (!makesDifference && !mode.getInstantiations().isEmpty()) { - // Also check instantiated reactors - for (var i : mode.getInstantiations()) { - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty() && !makesDifference) { - var check = toCheck.pop(); - checked.add(check); - - makesDifference |= !check.getModes().isEmpty() - || !ASTUtils.allStateVars(check).isEmpty() - || !ASTUtils.allTimers(check).isEmpty() - || !ASTUtils.allActions(check).isEmpty() - || ASTUtils.allConnections(check).stream().anyMatch(c -> c.getDelay() != null); - - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } - } - } - } - } - if (makesDifference) { - warning("You should specifiy a transition type! " - + "Reset and history transitions have different effects on this target mode. " - + "Currently, a reset type is implicitly assumed.", - reaction, Literals.REACTION__EFFECTS, reaction.getEffects().indexOf(effect)); - } + } + + @Check(CheckType.FAST) + public void checkUnspecifiedTransitionType(Reaction reaction) { + for (var effect : reaction.getEffects()) { + var variable = effect.getVariable(); + if (variable instanceof Mode) { + // The transition type is always set to default by Xtext. + // Hence, check if there is an explicit node for the transition type in the AST. + var transitionAssignment = + NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); + if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. + var mode = (Mode) variable; + // Check if reset or history transition would make a difference. + var makesDifference = + !mode.getStateVars().isEmpty() + || !mode.getTimers().isEmpty() + || !mode.getActions().isEmpty() + || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); + if (!makesDifference && !mode.getInstantiations().isEmpty()) { + // Also check instantiated reactors + for (var i : mode.getInstantiations()) { + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty() && !makesDifference) { + var check = toCheck.pop(); + checked.add(check); + + makesDifference |= + !check.getModes().isEmpty() + || !ASTUtils.allStateVars(check).isEmpty() + || !ASTUtils.allTimers(check).isEmpty() + || !ASTUtils.allActions(check).isEmpty() + || ASTUtils.allConnections(check).stream() + .anyMatch(c -> c.getDelay() != null); + + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } } + } } - } + } + if (makesDifference) { + warning( + "You should specifiy a transition type! " + + "Reset and history transitions have different effects on this target mode. " + + "Currently, a reset type is implicitly assumed.", + reaction, + Literals.REACTION__EFFECTS, + reaction.getEffects().indexOf(effect)); + } + } + } + } + } + + ////////////////////////////////////////////////////////////// + //// Public methods. + + /** Return the error reporter for this validator. */ + public ValidatorErrorReporter getErrorReporter() { + return this.errorReporter; + } + + /** Implementation required by xtext to report validation errors. */ + @Override + public ValidationMessageAcceptor getMessageAcceptor() { + return messageAcceptor == null ? this : messageAcceptor; + } + + /** Return a list of error messages for the target declaration. */ + public List getTargetPropertyErrors() { + return this.targetPropertyErrors; + } + + ////////////////////////////////////////////////////////////// + //// Protected methods. + + /** Generate an error message for an AST node. */ + @Override + protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature) { + super.error(message, feature); + } + + ////////////////////////////////////////////////////////////// + //// Private methods. + + /** + * For each input, report a conflict if: 1) the input exists and the type doesn't match; or 2) the + * input has a name clash with variable that is not an input. + * + * @param superVars List of typed variables of a particular kind (i.e., inputs, outputs, or + * actions), found in a super class. + * @param sameKind Typed variables of the same kind, found in the subclass. + * @param allOwn Accumulator of non-conflicting variables incorporated in the subclass. + * @param conflicts Set of variables that are in conflict, to be used by this function to report + * conflicts. + */ + private void checkConflict( + EList superVars, EList sameKind, List allOwn, HashSet conflicts) { + for (T superVar : superVars) { + T match = null; + for (T it : sameKind) { + if (it.getName().equals(superVar.getName())) { + match = it; + break; + } + } + List rest = new ArrayList<>(allOwn); + rest.removeIf(it -> sameKind.contains(it)); + + if ((match != null && superVar.getType() != match.getType()) + || hasNameConflict(superVar, rest)) { + conflicts.add(superVar); + } else { + allOwn.add(superVar); + } + } + } + + /** + * Check the name of a feature for illegal substrings such as reserved identifiers and names with + * double leading underscores. + * + * @param name The name. + * @param feature The feature containing the name (for error reporting). + */ + private void checkName(String name, EStructuralFeature feature) { + + // Raises an error if the string starts with two underscores. + if (name.length() >= 2 && name.substring(0, 2).equals("__")) { + error(UNDERSCORE_MESSAGE + name, feature); } - ////////////////////////////////////////////////////////////// - //// Public methods. - - /** - * Return the error reporter for this validator. - */ - public ValidatorErrorReporter getErrorReporter() { - return this.errorReporter; - } - - /** - * Implementation required by xtext to report validation errors. - */ - @Override - public ValidationMessageAcceptor getMessageAcceptor() { - return messageAcceptor == null ? this : messageAcceptor; - } - - /** - * Return a list of error messages for the target declaration. - */ - public List getTargetPropertyErrors() { - return this.targetPropertyErrors; - } - - ////////////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Generate an error message for an AST node. - */ - @Override - protected void error(java.lang.String message, - org.eclipse.emf.ecore.EStructuralFeature feature) { - super.error(message, feature); - } - - ////////////////////////////////////////////////////////////// - //// Private methods. - - /** - * For each input, report a conflict if: - * 1) the input exists and the type doesn't match; or - * 2) the input has a name clash with variable that is not an input. - * @param superVars List of typed variables of a particular kind (i.e., - * inputs, outputs, or actions), found in a super class. - * @param sameKind Typed variables of the same kind, found in the subclass. - * @param allOwn Accumulator of non-conflicting variables incorporated in the - * subclass. - * @param conflicts Set of variables that are in conflict, to be used by this - * function to report conflicts. - */ - private void checkConflict ( - EList superVars, EList sameKind, List allOwn, HashSet conflicts - ) { - for (T superVar : superVars) { - T match = null; - for (T it : sameKind) { - if (it.getName().equals(superVar.getName())) { - match = it; - break; - } - } - List rest = new ArrayList<>(allOwn); - rest.removeIf(it -> sameKind.contains(it)); + if (this.target.isReservedIdent(name)) { + error(RESERVED_MESSAGE + name, feature); + } - if ((match != null && superVar.getType() != match.getType()) || hasNameConflict(superVar, rest)) { - conflicts.add(superVar); - } else { - allOwn.add(superVar); - } - } + if (this.target == Target.TS) { + // "actions" is a reserved word within a TS reaction + if (name.equals("actions")) { + error(ACTIONS_MESSAGE + name, feature); + } + } + } + + /** + * Check that the initializer is compatible with the type. Note that if the type is inferred it + * will necessarily be compatible so this method is not harmful. + */ + public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { + if (init == null) { + return; } - /** - * Check the name of a feature for illegal substrings such as reserved - * identifiers and names with double leading underscores. - * @param name The name. - * @param feature The feature containing the name (for error reporting). - */ - private void checkName(String name, EStructuralFeature feature) { + // TODO: + // type is list => init is list + // type is fixed with size n => init is fixed with size n + // Specifically for C: list can only be literal or time lists - // Raises an error if the string starts with two underscores. - if (name.length() >= 2 && name.substring(0, 2).equals("__")) { - error(UNDERSCORE_MESSAGE + name, feature); + if (type.isTime) { + if (type.isList) { + // list of times + var exprs = init.getExprs(); + if (exprs.isEmpty()) { + error("Expected at least one time value.", feature); + return; } - - if (this.target.isReservedIdent(name)) { - error(RESERVED_MESSAGE + name, feature); + if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { + exprs = ((BracedListExpression) exprs.get(0)).getItems(); } - - if (this.target == Target.TS) { - // "actions" is a reserved word within a TS reaction - if (name.equals("actions")) { - error(ACTIONS_MESSAGE + name, feature); - } + for (var component : exprs) { + checkExpressionIsTime(component, feature); } + } else { + checkExpressionIsTime(init, feature); + } } + } - - /** - * Check that the initializer is compatible with the type. - * Note that if the type is inferred it will necessarily be compatible - * so this method is not harmful. - */ - public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { - if (init == null) { - return; - } - - // TODO: - // type is list => init is list - // type is fixed with size n => init is fixed with size n - // Specifically for C: list can only be literal or time lists - - if (type.isTime) { - if (type.isList) { - // list of times - var exprs = init.getExprs(); - if (exprs.isEmpty()) { - error("Expected at least one time value.", feature); - return; - } - if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { - exprs = ((BracedListExpression) exprs.get(0)).getItems(); - } - for (var component : exprs) { - checkExpressionIsTime(component, feature); - } - } else { - checkExpressionIsTime(init, feature); - } - } + private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { + if (init == null) { + return; } - private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { - if (init == null) { - return; - } - - if (init.getExprs().size() != 1) { - error("Expected exactly one time value.", feature); - } else { - checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); - } + if (init.getExprs().size() != 1) { + error("Expected exactly one time value.", feature); + } else { + checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); } + } - private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { - if (value == null || value instanceof Time) { - return; - } - - if (value instanceof ParameterReference) { - if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) - && target.requiresTypes) { - error("Referenced parameter is not of time type.", feature); - } - return; - } else if (value instanceof Literal) { - if (ASTUtils.isZero(((Literal) value).getLiteral())) { - return; - } - - if (ASTUtils.isInteger(((Literal) value).getLiteral())) { - error("Missing time unit.", feature); - return; - } - // fallthrough - } - - error("Invalid time value.", feature); + private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { + if (value == null || value instanceof Time) { + return; } - /** - * Return the number of main or federated reactors declared. - * - * @param iter An iterator over all objects in the resource. - */ - private int countMainOrFederated(TreeIterator iter) { - int nMain = 0; - while (iter.hasNext()) { - EObject obj = iter.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor r = (Reactor) obj; - if (r.isMain() || r.isFederated()) { - nMain++; - } - } - return nMain; - } - - /** - * Report whether a given reactor has dependencies on a cyclic - * instantiation pattern. This means the reactor has an instantiation - * in it -- directly or in one of its contained reactors -- that is - * self-referential. - * @param reactor The reactor definition to find out whether it has any - * dependencies on cyclic instantiations. - * @param cycleSet The set of all reactors that are part of an - * instantiation cycle. - * @param visited The set of nodes already visited in this graph traversal. - */ - private boolean dependsOnCycle( - Reactor reactor, Set cycleSet, Set visited - ) { - Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); - if (visited.contains(reactor)) { - return false; - } else { - visited.add(reactor); - for (Reactor it : origins) { - if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { - // Reached a cycle. - return true; - } - } - } - return false; - } - - /** - * Report whether the name of the given element matches any variable in - * the ones to check against. - * @param element The element to compare against all variables in the given iterable. - * @param toCheckAgainst Iterable variables to compare the given element against. - */ - private boolean hasNameConflict(Variable element, - Iterable toCheckAgainst) { - int numNameConflicts = 0; - for (Variable it : toCheckAgainst) { - if (it.getName().equals(element.getName())) { - numNameConflicts++; - } - } - return numNameConflicts > 0; + if (value instanceof ParameterReference) { + if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) + && target.requiresTypes) { + error("Referenced parameter is not of time type.", feature); + } + return; + } else if (value instanceof Literal) { + if (ASTUtils.isZero(((Literal) value).getLiteral())) { + return; + } + + if (ASTUtils.isInteger(((Literal) value).getLiteral())) { + error("Missing time unit.", feature); + return; + } + // fallthrough } - /** - * Return true if target is C or a C-based target like CCpp. - */ - private boolean isCBasedTarget() { - return (this.target == Target.C || this.target == Target.CCPP); + error("Invalid time value.", feature); + } + + /** + * Return the number of main or federated reactors declared. + * + * @param iter An iterator over all objects in the resource. + */ + private int countMainOrFederated(TreeIterator iter) { + int nMain = 0; + while (iter.hasNext()) { + EObject obj = iter.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor r = (Reactor) obj; + if (r.isMain() || r.isFederated()) { + nMain++; + } } - - /** - * Report whether a given imported reactor is used in this resource or not. - * @param reactor The imported reactor to check whether it is used. - */ - private boolean isUnused(ImportedReactor reactor) { - TreeIterator instantiations = reactor.eResource().getAllContents(); - TreeIterator subclasses = reactor.eResource().getAllContents(); - - boolean instantiationsCheck = true; - while (instantiations.hasNext() && instantiationsCheck) { - EObject obj = instantiations.next(); - if (!(obj instanceof Instantiation)) { - continue; - } - Instantiation inst = (Instantiation) obj; - instantiationsCheck &= (inst.getReactorClass() != reactor && inst.getReactorClass() != reactor.getReactorClass()); - } - - boolean subclassesCheck = true; - while (subclasses.hasNext() && subclassesCheck) { - EObject obj = subclasses.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor subclass = (Reactor) obj; - for (ReactorDecl decl : subclass.getSuperClasses()) { - subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); - } - } - return instantiationsCheck && subclassesCheck; + return nMain; + } + + /** + * Report whether a given reactor has dependencies on a cyclic instantiation pattern. This means + * the reactor has an instantiation in it -- directly or in one of its contained reactors -- that + * is self-referential. + * + * @param reactor The reactor definition to find out whether it has any dependencies on cyclic + * instantiations. + * @param cycleSet The set of all reactors that are part of an instantiation cycle. + * @param visited The set of nodes already visited in this graph traversal. + */ + private boolean dependsOnCycle(Reactor reactor, Set cycleSet, Set visited) { + Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); + if (visited.contains(reactor)) { + return false; + } else { + visited.add(reactor); + for (Reactor it : origins) { + if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { + // Reached a cycle. + return true; + } + } } - - /** - * Return true if the two types match. Unfortunately, xtext does not - * seem to create a suitable equals() method for Type, so we have to - * do this manually. - */ - private boolean sameType(Type type1, Type type2) { - if (type1 == null) { - return type2 == null; - } - if (type2 == null) { - return type1 == null; - } - // Most common case first. - if (type1.getId() != null) { - if (type1.getStars() != null) { - if (type2.getStars() == null) return false; - if (type1.getStars().size() != type2.getStars().size()) return false; - } - return (type1.getId().equals(type2.getId())); - } - - // Type specification in the grammar is: - // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); - if (type1.isTime()) { - if (!type2.isTime()) return false; - // Ignore the arraySpec because that is checked when connection - // is checked for balance. - return true; - } - // Type must be given in a code body - return type1.getCode().getBody().equals(type2.getCode().getBody()); + return false; + } + + /** + * Report whether the name of the given element matches any variable in the ones to check against. + * + * @param element The element to compare against all variables in the given iterable. + * @param toCheckAgainst Iterable variables to compare the given element against. + */ + private boolean hasNameConflict(Variable element, Iterable toCheckAgainst) { + int numNameConflicts = 0; + for (Variable it : toCheckAgainst) { + if (it.getName().equals(element.getName())) { + numNameConflicts++; + } + } + return numNameConflicts > 0; + } + + /** Return true if target is C or a C-based target like CCpp. */ + private boolean isCBasedTarget() { + return (this.target == Target.C || this.target == Target.CCPP); + } + + /** + * Report whether a given imported reactor is used in this resource or not. + * + * @param reactor The imported reactor to check whether it is used. + */ + private boolean isUnused(ImportedReactor reactor) { + TreeIterator instantiations = reactor.eResource().getAllContents(); + TreeIterator subclasses = reactor.eResource().getAllContents(); + + boolean instantiationsCheck = true; + while (instantiations.hasNext() && instantiationsCheck) { + EObject obj = instantiations.next(); + if (!(obj instanceof Instantiation)) { + continue; + } + Instantiation inst = (Instantiation) obj; + instantiationsCheck &= + (inst.getReactorClass() != reactor + && inst.getReactorClass() != reactor.getReactorClass()); } - ////////////////////////////////////////////////////////////// - //// Private fields. - - /** The error reporter. */ - private ValidatorErrorReporter errorReporter - = new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); - - /** Helper class containing information about the model. */ - private ModelInfo info = new ModelInfo(); - - @Inject(optional = true) - private ValidationMessageAcceptor messageAcceptor; - - /** The declared target. */ - private Target target; - - private List targetPropertyErrors = new ArrayList<>(); - - private List targetPropertyWarnings = new ArrayList<>(); - - ////////////////////////////////////////////////////////////// - //// Private static constants. - - private static String ACTIONS_MESSAGE - = "\"actions\" is a reserved word for the TypeScript target for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " - + "and reactor instantiation): "; - - private static String HOST_OR_FQN_REGEX - = "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; - - /** - * Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). - */ - private static String IPV4_REGEX = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + - "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; - - /** - * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), - * with minor adjustment to allow up to six IPV6 segments (without truncation) in front - * of an embedded IPv4-address. - **/ - private static String IPV6_REGEX = - "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + - "([0-9a-fA-F]{1,4}:){1,7}:|" + - "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + - "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + - "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + - "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + - "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + - "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + - ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + - "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + - "::(ffff(:0{1,4}){0,1}:){0,1}" + IPV4_REGEX + "|" + - "([0-9a-fA-F]{1,4}:){1,4}:" + IPV4_REGEX + "|" + - "([0-9a-fA-F]{1,4}:){1,6}" + IPV4_REGEX + ")"; - - private static String RESERVED_MESSAGE = "Reserved words in the target language are not allowed for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation): "; - - private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); - - private static String UNDERSCORE_MESSAGE = "Names of objects (inputs, outputs, actions, timers, parameters, " - + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; + boolean subclassesCheck = true; + while (subclasses.hasNext() && subclassesCheck) { + EObject obj = subclasses.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor subclass = (Reactor) obj; + for (ReactorDecl decl : subclass.getSuperClasses()) { + subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); + } + } + return instantiationsCheck && subclassesCheck; + } + + /** + * Return true if the two types match. Unfortunately, xtext does not seem to create a suitable + * equals() method for Type, so we have to do this manually. + */ + private boolean sameType(Type type1, Type type2) { + if (type1 == null) { + return type2 == null; + } + if (type2 == null) { + return type1 == null; + } + // Most common case first. + if (type1.getId() != null) { + if (type1.getStars() != null) { + if (type2.getStars() == null) return false; + if (type1.getStars().size() != type2.getStars().size()) return false; + } + return (type1.getId().equals(type2.getId())); + } - private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; - + // Type specification in the grammar is: + // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' + // typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); + if (type1.isTime()) { + if (!type2.isTime()) return false; + // Ignore the arraySpec because that is checked when connection + // is checked for balance. + return true; + } + // Type must be given in a code body + return type1.getCode().getBody().equals(type2.getCode().getBody()); + } + + ////////////////////////////////////////////////////////////// + //// Private fields. + + /** The error reporter. */ + private ValidatorErrorReporter errorReporter = + new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); + + /** Helper class containing information about the model. */ + private ModelInfo info = new ModelInfo(); + + @Inject(optional = true) + private ValidationMessageAcceptor messageAcceptor; + + /** The declared target. */ + private Target target; + + private List targetPropertyErrors = new ArrayList<>(); + + private List targetPropertyWarnings = new ArrayList<>(); + + ////////////////////////////////////////////////////////////// + //// Private static constants. + + private static String ACTIONS_MESSAGE = + "\"actions\" is a reserved word for the TypeScript target for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " + + "and reactor instantiation): "; + + private static String HOST_OR_FQN_REGEX = + "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; + + /** Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). */ + private static String IPV4_REGEX = + "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; + + /** + * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), with minor + * adjustment to allow up to six IPV6 segments (without truncation) in front of an embedded + * IPv4-address. + */ + private static String IPV6_REGEX = + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,7}:|" + + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + + "::(ffff(:0{1,4}){0,1}:){0,1}" + + IPV4_REGEX + + "|" + + "([0-9a-fA-F]{1,4}:){1,4}:" + + IPV4_REGEX + + "|" + + "([0-9a-fA-F]{1,4}:){1,6}" + + IPV4_REGEX + + ")"; + + private static String RESERVED_MESSAGE = + "Reserved words in the target language are not allowed for objects (inputs, outputs, actions," + + " timers, parameters, state, reactor definitions, and reactor instantiation): "; + + private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); + + private static String UNDERSCORE_MESSAGE = + "Names of objects (inputs, outputs, actions, timers, parameters, " + + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; + + private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; } diff --git a/test/C/src/file0.lf b/test/C/src/file0.lf deleted file mode 100644 index 645242845a..0000000000 --- a/test/C/src/file0.lf +++ /dev/null @@ -1,40 +0,0 @@ -target C - -reactor Watcher { - input x: int - // Produced if the - // deadline is - // violated. - output d: int - - reaction(x) -> - d, poodle {= - lf_watchdog_start(poodle, 0); - printf("Normal reaction.\n"); - =} -} - -main reactor { - logical action a - w = new Watcher( - - ) - - reaction( - startup - ) -> - w.x, a {= - lf_set(w.x, 0); - lf_schedule(a, 0); - =} - - reaction(a) -> - w.x {= - lf_set(w.x, 0); - lf_nanosleep(MSEC(40)); - =} - - reaction(w.d) {= - printf("Deadline reactor produced an output.\n"); - =} -} diff --git a/test/C/src/file1.lf b/test/C/src/file1.lf deleted file mode 100644 index 1183364928..0000000000 --- a/test/C/src/file1.lf +++ /dev/null @@ -1,40 +0,0 @@ -target C - -reactor Watcher { - input x: int - // Produced if the - // deadline is - // violated. - output d: int - - reaction(x) -> - poodle, d {= - lf_watchdog_start(poodle, 0); - printf("Normal reaction.\n"); - =} -} - -main reactor { - logical action a - w = new Watcher( - - ) - - reaction( - startup - ) -> - w.x, a {= - lf_set(w.x, 0); - lf_schedule(a, 0); - =} - - reaction(a) -> - w.x {= - lf_set(w.x, 0); - lf_nanosleep(MSEC(40)); - =} - - reaction(w.d) {= - printf("Deadline reactor produced an output.\n"); - =} -} diff --git a/test/C/src/file2.lf b/test/C/src/file2.lf deleted file mode 100644 index 1183364928..0000000000 --- a/test/C/src/file2.lf +++ /dev/null @@ -1,40 +0,0 @@ -target C - -reactor Watcher { - input x: int - // Produced if the - // deadline is - // violated. - output d: int - - reaction(x) -> - poodle, d {= - lf_watchdog_start(poodle, 0); - printf("Normal reaction.\n"); - =} -} - -main reactor { - logical action a - w = new Watcher( - - ) - - reaction( - startup - ) -> - w.x, a {= - lf_set(w.x, 0); - lf_schedule(a, 0); - =} - - reaction(a) -> - w.x {= - lf_set(w.x, 0); - lf_nanosleep(MSEC(40)); - =} - - reaction(w.d) {= - printf("Deadline reactor produced an output.\n"); - =} -} From b7c60da680b48928f6b3ce7d4e9fe1179dbe7435 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 14 Apr 2023 21:19:22 -0700 Subject: [PATCH 120/709] Progress towards addressing #1685 --- org.lflang/src/org/lflang/TargetConfig.java | 10 +- .../federated/generator/FedFileConfig.java | 16 +- .../org/lflang/generator/c/CGenerator.java | 81 ++++--- .../src/org/lflang/generator/c/CUtil.java | 215 +++++++++--------- org.lflang/src/org/lflang/util/FileUtil.java | 41 +++- 5 files changed, 209 insertions(+), 154 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 23e99541da..6f15181172 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -177,6 +177,7 @@ public TargetConfig( * Useful for copying them to remote machines. This is needed because * target cmake-includes can be resources with resource paths. */ + // FIXME: Code smell. This gets populated in CGenerator.copyUserFiles public List cmakeIncludesWithoutPath = new ArrayList<>(); /** @@ -237,14 +238,7 @@ public TargetConfig( /** * List of files to be copied to src-gen. */ - public List fileNames = new ArrayList<>(); - - /** - * List of file names from the files target property with no path info. - * Useful for copying them to remote machines. This is needed because - * target files can be resources with resource paths. - */ - public List filesNamesWithoutPath = new ArrayList<>(); + public List fileNames = new ArrayList<>(); // FIXME: misnamed, these are files or paths, not file names. /** * If true, configure the execution environment to keep executing if there diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index 42f5c60dc7..6ac65236f8 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -120,17 +121,22 @@ public void relativizePaths(FedTargetConfig targetConfig) { */ private void relativizePathList(List paths) { List tempList = new ArrayList<>(); - paths.forEach(f -> tempList.add(relativizePath(f))); + paths.forEach(f -> tempList.add(relativizePath(Paths.get(f)))); paths.clear(); paths.addAll(tempList); } /** - * Relativize a single path. + * Relativize a single path, but only if it points to a local resource in the project (i.e., not + * on the class path). * @param path The path to relativize. */ - private String relativizePath(String path) { - Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); - return this.getSrcPath().relativize(resolvedPath).toString(); + private String relativizePath(Path path) { + if (FileUtil.findInProject(path, this) == null) { + return String.valueOf(path); + } else { + Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); + return this.getSrcPath().relativize(resolvedPath).toString(); + } } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index f598219ddd..93c407a410 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -39,6 +39,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -820,49 +821,55 @@ private void inspectReactorEResource(ReactorDecl reactor) { @Override public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { super.copyUserFiles(targetConfig, fileConfig); - // Make sure the target directory exists. var targetDir = this.fileConfig.getSrcGenPath(); - try { - Files.createDirectories(targetDir); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - + // FIXME: this code probably belongs in the super method. for (String filename : targetConfig.fileNames) { - var relativeFileName = CUtil.copyFileOrResource( - filename, - fileConfig.srcFile.getParent(), - targetDir); - if (StringExtensions.isNullOrEmpty(relativeFileName)) { - errorReporter.reportError( - "Failed to find file " + filename + " specified in the" + - " files target property." - ); + var path = Paths.get(filename); + var copied = false; + var found = FileUtil.findInProject(path, fileConfig); + if (found != null) { + try { + FileUtil.copyFileOrDirectory(found, targetDir); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { - targetConfig.filesNamesWithoutPath.add( - relativeFileName - ); + // Attempt to copy from the classpath instead. + // If the filename is not a directory, it will + // just be copied without further recursion. + try { + FileUtil.copyDirectoryFromClassPath( + filename, + targetDir, + false + ); + } catch (IOException e) { + errorReporter.reportError( + "Failed to find '" + filename + "' specified in the" + + " files target property." + ); + } } } - for (String filename : targetConfig.cmakeIncludes) { - var relativeCMakeIncludeFileName = - CUtil.copyFileOrResource( - filename, - fileConfig.srcFile.getParent(), - targetDir); - // Check if the file exists - if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { - errorReporter.reportError( - "Failed to find cmake-include file " + filename - ); - } else { - this.targetConfig.cmakeIncludesWithoutPath.add( - relativeCMakeIncludeFileName - ); - } - } +// for (String filename : targetConfig.cmakeIncludes) { +// var relativeCMakeIncludeFileName = +// CUtil.copyFileOrResource( +// filename, +// fileConfig.srcFile.getParent(), +// targetDir); +// // Check if the file exists +// if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { +// errorReporter.reportError( +// "Failed to find cmake-include file " + filename +// ); +// } else { +// // FIXME: weird +// this.targetConfig.cmakeIncludesWithoutPath.add( +// relativeCMakeIncludeFileName +// ); +// } +// } if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { try { diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 69e9ec30ae..f59f45eef2 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -575,69 +575,76 @@ public static String triggerRefNested(PortInstance port, String runtimeIndex, St return reactorRefNested(port.getParent(), runtimeIndex, bankIndex) + "." + port.getName() + "_trigger"; } - /** - * Copy the 'fileName' (which also could be a directory name) from the - * 'srcDirectory' to the 'destinationDirectory'. This function has a - * fallback search mechanism, where if `fileName` is not found in the - * `srcDirectory`, it will try to find `fileName` via the following - * procedure: - * 1- Search in LF_CLASSPATH. @see findFile() - * 2- Search in CLASSPATH. @see findFile() - * 3- Search for 'fileName' as a resource. That means the `fileName` - * can be '/path/to/class/resource'. @see java.lang.Class.getResourceAsStream() - * - * @param fileName Name of the file or directory. - * @param srcDir Where the file or directory is currently located. - * @param dstDir Where the file or directory should be placed. - * @return The name of the file or directory in destinationDirectory or an empty string on failure. - */ - public static String copyFileOrResource(String fileName, Path srcDir, - Path dstDir) { - // Try to copy the file or directory from the file system. - Path file = findFileOrDirectory(fileName, srcDir); - if (file != null) { - Path target = dstDir.resolve(file.getFileName()); - try { - if (Files.isDirectory(file)) { - FileUtil.copyDirectory(file, target); - } else if (Files.isRegularFile(file)) { - Files.copy(file, target, - StandardCopyOption.REPLACE_EXISTING); - } - return file.getFileName().toString(); - } catch (IOException e) { - // Failed to copy the file or directory, most likely - // because it doesn't exist. Will try to find it as a - // resource before giving up. - } - } - - String filenameWithoutPath = fileName; - int lastSeparator = fileName.lastIndexOf(File.separator); - if (lastSeparator > 0) { - // FIXME: Brittle. What if the file is in a subdirectory? - filenameWithoutPath = fileName.substring(lastSeparator + 1); - } - // Try to copy the file or directory as a resource. - try { - FileUtil.copyFileFromClassPath(fileName, - dstDir.resolve(filenameWithoutPath)); - return filenameWithoutPath; - } catch (IOException ex) { - // Will try one more time as a directory - } - - try { - FileUtil.copyDirectoryFromClassPath(fileName, - dstDir.resolve(filenameWithoutPath), false); - return filenameWithoutPath; - } catch (IOException ex) { - System.err.println( - "WARNING: Failed to find file or directory " + fileName); - } - - return ""; - } +// /** +// * Copy the 'fileName' (which also could be a directory name) from the +// * 'srcDirectory' to the 'destinationDirectory'. This function has a +// * fallback search mechanism, where if `fileName` is not found in the +// * `srcDirectory`, it will try to find `fileName` via the following +// * procedure: +// * 1- Search in LF_CLASSPATH. @see findFile() +// * 2- Search in CLASSPATH. @see findFile() +// * 3- Search for 'fileName' as a resource. That means the `fileName` +// * can be '/path/to/class/resource'. @see java.lang.Class.getResourceAsStream() +// * +// * @param fileName Name of the file or directory. +// * @param srcDir Where the file or directory is currently located. +// * @param dstDir Where the file or directory should be placed. +// * @return The name of the file or directory in destinationDirectory or an empty string on failure. +// */ +// public static String copyFileOrResource(String fileName, Path srcDir, +// Path dstDir) { +// +// // Check whether file exists +// +// +// // Try to copy the file or directory from the file system. +// Path file = FileUtil.findInProject(fileName, srcDir); +// if (file != null) { +// Path target = dstDir.resolve(file.getFileName()); +// try { +// if (Files.isDirectory(file)) { +// FileUtil.copyDirectory(file, target); +// } else if (Files.isRegularFile(file)) { +// Files.copy(file, target, +// StandardCopyOption.REPLACE_EXISTING); +// } +// return file.getFileName().toString(); +// } catch (IOException e) { +// // Failed to copy the file or directory, most likely +// // because it doesn't exist. Will try to find it as a +// // resource before giving up. +// } +// } +// +// +// +// String filenameWithoutPath = fileName; +// int lastSeparator = fileName.lastIndexOf(File.separator); +// if (lastSeparator > 0) { +// // FIXME: Brittle. What if the file is in a subdirectory? +// filenameWithoutPath = fileName.substring(lastSeparator + 1); +// } +// // Try to copy the file or directory as a resource. +// try { +// System.out.println("Classpath lookup: " + dstDir.resolve(filenameWithoutPath)); +// FileUtil.copyFileFromClassPath(fileName, +// dstDir.resolve(filenameWithoutPath)); +// return filenameWithoutPath; +// } catch (IOException ex) { +// // Will try one more time as a directory +// } +// +// try { +// FileUtil.copyDirectoryFromClassPath(fileName, +// dstDir.resolve(filenameWithoutPath), false); +// return filenameWithoutPath; +// } catch (IOException ex) { +// System.err.println( +// "WARNING: Failed to find file or directory " + fileName); +// } +// +// return ""; +// } ////////////////////////////////////////////////////// //// FIXME: Not clear what the strategy is with the following inner interface. @@ -661,45 +668,49 @@ public interface ReportCommandErrors { void report(String errors); } - /** - * Search for a given file or directory name in the given directory. - * If not found, search in directories in LF_CLASSPATH. - * If there is no LF_CLASSPATH environment variable, use CLASSPATH, - * if it is defined. The first file or directory that is found will - * be returned. Otherwise, null is returned. - * - * @param fileName The file or directory name or relative path + name - * as a String. - * @param directory String representation of the directory to search in. - * @return A Java Path or null if not found. - */ - public static Path findFileOrDirectory(String fileName, Path directory) { - Path foundFile; - - // Check in local directory - foundFile = directory.resolve(fileName); - if (Files.exists(foundFile)) { - return foundFile; - } - - // Check in LF_CLASSPATH - // Load all the resources in LF_CLASSPATH if it is set. - String classpathLF = System.getenv("LF_CLASSPATH"); - if (classpathLF == null) { - classpathLF = System.getenv("CLASSPATH"); - } - if (classpathLF != null) { - String[] paths = classpathLF.split(System.getProperty("path.separator")); - for (String path : paths) { - foundFile = Paths.get(path).resolve(fileName); - if (Files.exists(foundFile)) { - return foundFile; - } - } - } - // Not found. - return null; - } +// /** +// * Search for a given file or directory name in the given directory. +// * If not found, search in directories in LF_CLASSPATH. +// * If there is no LF_CLASSPATH environment variable, use CLASSPATH, +// * if it is defined. The first file or directory that is found will +// * be returned. Otherwise, null is returned. +// * +// * @param fileName The file or directory name or relative path + name +// * as a String. +// * @param directory String representation of the directory to search in. +// * @return A Java Path or null if not found. +// */ +// public static Path findFileOrDirectory(String fileName, Path directory) { +// Path foundFile; +// +// // Check in local directory +// foundFile = directory.resolve(fileName); +// if (Files.exists(foundFile)) { +// System.out.println(">>> File found in filesystem"); +// return foundFile; +// } +// +// // Check in LF_CLASSPATH +// // Load all the resources in LF_CLASSPATH if it is set. +// String classpathLF = System.getenv("LF_CLASSPATH"); +// if (classpathLF == null) { +// classpathLF = System.getenv("CLASSPATH"); +// } +// if (classpathLF != null) { +// String[] paths = classpathLF.split(System.getProperty("path.separator")); +// for (String path : paths) { +// System.out.println("++++Looking in path: " + path); +// foundFile = Paths.get(path).resolve(fileName); +// if (Files.exists(foundFile)) { +// System.out.println(">>> File found on classpath: %s".formatted(foundFile)); +// return foundFile; +// } +// } +// } +// +// // Not found. +// return null; +// } /** diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index d4d34c7b08..8b4a56bc77 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -14,6 +14,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; @@ -239,6 +240,15 @@ public static void copyFile(Path source, Path destination) throws IOException { copyFile(source, destination, false); } + public static void copyFileOrDirectory(Path source, Path destination) throws IOException { + if (Files.isDirectory(source)) { + copyDirectory(source, destination); + } else if (Files.isRegularFile(source)) { + copyFile(source, destination); + } else { + throw new IllegalArgumentException("Source is neither a directory nor a regular file."); + } + } /** * Copy a given input stream to a destination file. * @@ -359,6 +369,7 @@ private static boolean copyDirectoryFromJar(JarURLConnection connection, final P final String connectionEntryName = connection.getEntryName(); boolean copiedFiles = false; + // Iterate all entries in the jar file. for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { final JarEntry entry = e.nextElement(); @@ -366,9 +377,10 @@ private static boolean copyDirectoryFromJar(JarURLConnection connection, final P // Extract files only if they match the given source path. if (entryName.startsWith(connectionEntryName)) { - String filename = entry.getName().substring(connectionEntryName.length() + 1); + String filename = entryName.equals(connectionEntryName) ? + connectionEntryName : + entryName.substring(connectionEntryName.length() + 1); Path currentFile = destination.resolve(filename); - if (entry.isDirectory()) { Files.createDirectories(currentFile); } else { @@ -511,6 +523,31 @@ public static void deleteDirectory(Path dir) throws IOException { } } + public static Path findInProject(Path fileOrDirectory, FileConfig fileConfig) { + if (fileOrDirectory.isAbsolute() && Files.exists(fileOrDirectory)) { + return fileOrDirectory; + } else { + Path relPath; + // Disregard root and interpret as relative path + if (fileOrDirectory.isAbsolute()) { + relPath = Paths.get( + String.valueOf(fileOrDirectory).replaceFirst( + String.valueOf(fileOrDirectory.getRoot()), + "") + ); + } else { + relPath = fileOrDirectory; + } + // Look relative to the source file and relative to the package root. + var locations = List.of(fileConfig.srcFile, fileConfig.srcPkgPath); + var found = locations.stream().filter(loc -> Files.exists(loc.resolve(relPath))).findFirst(); + if (found.isPresent()) { + return found.get(); + } + } + return null; + } + /** * Get the iResource corresponding to the provided resource if it can be * found. From b2d532217ce8b7aa72396d82af67fb7cf100695d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 14 Apr 2023 22:02:47 -0700 Subject: [PATCH 121/709] Fix typo --- org.lflang/src/org/lflang/util/FileUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 8b4a56bc77..8d5518e555 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -539,7 +539,7 @@ public static Path findInProject(Path fileOrDirectory, FileConfig fileConfig) { relPath = fileOrDirectory; } // Look relative to the source file and relative to the package root. - var locations = List.of(fileConfig.srcFile, fileConfig.srcPkgPath); + var locations = List.of(fileConfig.srcPath, fileConfig.srcPkgPath); var found = locations.stream().filter(loc -> Files.exists(loc.resolve(relPath))).findFirst(); if (found.isPresent()) { return found.get(); From 9dfed7f64892a658d4a2a9dd6a9f33766af63e11 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 14 Apr 2023 23:51:21 -0700 Subject: [PATCH 122/709] Fix bug --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 3 +-- org.lflang/src/org/lflang/util/FileUtil.java | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 93c407a410..0f1ababde8 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -825,11 +825,10 @@ public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { // FIXME: this code probably belongs in the super method. for (String filename : targetConfig.fileNames) { var path = Paths.get(filename); - var copied = false; var found = FileUtil.findInProject(path, fileConfig); if (found != null) { try { - FileUtil.copyFileOrDirectory(found, targetDir); + FileUtil.copyFileOrDirectory(found, targetDir.resolve(found.getFileName())); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 8d5518e555..6025400a7d 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -538,11 +538,14 @@ public static Path findInProject(Path fileOrDirectory, FileConfig fileConfig) { } else { relPath = fileOrDirectory; } + // Look relative to the source file and relative to the package root. var locations = List.of(fileConfig.srcPath, fileConfig.srcPkgPath); - var found = locations.stream().filter(loc -> Files.exists(loc.resolve(relPath))).findFirst(); + var found = locations.stream().filter( + loc -> Files.exists(loc.resolve(relPath)) + ).findFirst(); if (found.isPresent()) { - return found.get(); + return found.get().resolve(relPath); } } return null; From aede8750e5ffa1f767df6cc4e90e9c59bf6289e5 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 15 Apr 2023 16:19:27 +0900 Subject: [PATCH 123/709] Add option to add FEDERATED_AUTHENTICATED --- .../src/org/lflang/federated/extensions/CExtensionUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 124ffefb4f..a0b391c4b7 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -244,6 +244,10 @@ public static void handleCompileDefinitions( federate.targetConfig.setByUser.add(TargetProperty.COMPILE_DEFINITIONS); federate.targetConfig.compileDefinitions.put("FEDERATED", ""); federate.targetConfig.compileDefinitions.put("FEDERATED_"+federate.targetConfig.coordination.toString().toUpperCase(), ""); + if (federate.targetConfig.auth) { + System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + federate.targetConfig.compileDefinitions.put("FEDERATED_AUTHENTICATED", ""); + } federate.targetConfig.compileDefinitions.put("NUMBER_OF_FEDERATES", String.valueOf(numOfFederates)); federate.targetConfig.compileDefinitions.put("EXECUTABLE_PREAMBLE", ""); federate.targetConfig.compileDefinitions.put("WORKERS_NEEDED_FOR_FEDERATE", String.valueOf(minThreadsToHandleInputPorts(federate))); From 33452aa4ea64717dcaa2c9ec598bb65a45b3c6a1 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 15 Apr 2023 16:19:41 +0900 Subject: [PATCH 124/709] Match version --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 667a5d702c..6dfa1a0e57 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 667a5d702cbcd0288328417d8c632e6b5af19c04 +Subproject commit 6dfa1a0e573692af48f114c844fddb6de8d2cbab From 057777fa8e6f724178190164db9a00ba30febb17 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 15 Apr 2023 17:30:49 +0900 Subject: [PATCH 125/709] Remove prints. --- .../src/org/lflang/federated/extensions/CExtensionUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index a0b391c4b7..c84bf36197 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -245,7 +245,6 @@ public static void handleCompileDefinitions( federate.targetConfig.compileDefinitions.put("FEDERATED", ""); federate.targetConfig.compileDefinitions.put("FEDERATED_"+federate.targetConfig.coordination.toString().toUpperCase(), ""); if (federate.targetConfig.auth) { - System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); federate.targetConfig.compileDefinitions.put("FEDERATED_AUTHENTICATED", ""); } federate.targetConfig.compileDefinitions.put("NUMBER_OF_FEDERATES", String.valueOf(numOfFederates)); From 9f650b2986d3763aaedfd787f91da1c4b36d047d Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 15 Apr 2023 19:48:38 +0900 Subject: [PATCH 126/709] Change ci.yml point --- .github/workflows/c-tests.yml | 2 ++ .github/workflows/ci.yml | 4 ++-- org.lflang/src/lib/c/reactor-c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 0764128a1b..8c85928ff1 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -45,6 +45,8 @@ jobs: brew install coreutils brew install openssl brew link openssl --force + export LDFLAGS="-L/usr/local/opt/openssl@3/lib" + export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6dd56ae40..64a524ff8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth-fail-test needs: cancel # Run the C Arduino integration tests. @@ -77,7 +77,7 @@ jobs: # Run the CCpp integration tests. ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth-fail-test with: use-cpp: true needs: cancel diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 6dfa1a0e57..4920ead796 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6dfa1a0e573692af48f114c844fddb6de8d2cbab +Subproject commit 4920ead7960d1d30d7b4ba6becfb1bd9362b81e5 From 4c844909d9edb36df7b892d54f5231842b9ca6f3 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 15 Apr 2023 22:08:22 +0900 Subject: [PATCH 127/709] Try removing OPENSSL_ROOT_DIR --- .github/workflows/c-tests.yml | 2 -- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 8c85928ff1..0764128a1b 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -45,8 +45,6 @@ jobs: brew install coreutils brew install openssl brew link openssl --force - export LDFLAGS="-L/usr/local/opt/openssl@3/lib" - export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 3f5eb4a5b7..d8033a8465 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -227,9 +227,9 @@ CodeBuilder generateCMakeCode( if (targetConfig.platformOptions.platform != Platform.AUTO) { osName = targetConfig.platformOptions.platform.toString(); } - if (osName.contains("mac")) { - cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); - } + // if (osName.contains("mac")) { + // cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); + // } cMakeCode.pr("# Find OpenSSL and link to it"); cMakeCode.pr("find_package(OpenSSL REQUIRED)"); cMakeCode.pr("target_link_libraries( ${LF_MAIN_TARGET} PRIVATE OpenSSL::SSL)"); From 381582983e81aa37ca505b2ef239353418aac364 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sun, 16 Apr 2023 00:34:23 +0900 Subject: [PATCH 128/709] Revert "Try removing OPENSSL_ROOT_DIR" This reverts commit 4c844909d9edb36df7b892d54f5231842b9ca6f3. --- .github/workflows/c-tests.yml | 2 ++ org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 0764128a1b..8c85928ff1 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -45,6 +45,8 @@ jobs: brew install coreutils brew install openssl brew link openssl --force + export LDFLAGS="-L/usr/local/opt/openssl@3/lib" + export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index d8033a8465..3f5eb4a5b7 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -227,9 +227,9 @@ CodeBuilder generateCMakeCode( if (targetConfig.platformOptions.platform != Platform.AUTO) { osName = targetConfig.platformOptions.platform.toString(); } - // if (osName.contains("mac")) { - // cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); - // } + if (osName.contains("mac")) { + cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); + } cMakeCode.pr("# Find OpenSSL and link to it"); cMakeCode.pr("find_package(OpenSSL REQUIRED)"); cMakeCode.pr("target_link_libraries( ${LF_MAIN_TARGET} PRIVATE OpenSSL::SSL)"); From 114dd25df58e36230d52c5b906afaf361d4f749e Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sun, 16 Apr 2023 00:44:00 +0900 Subject: [PATCH 129/709] Add library path --- .github/workflows/c-tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 8c85928ff1..9d175941ed 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -45,8 +45,7 @@ jobs: brew install coreutils brew install openssl brew link openssl --force - export LDFLAGS="-L/usr/local/opt/openssl@3/lib" - export CPPFLAGS="-I/usr/local/opt/openssl@3/include" + export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti From c4238ccc0478292c7bd963256f17b8877694fd62 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 15 Apr 2023 23:02:54 -0700 Subject: [PATCH 130/709] Add doc comment. --- test/C/src/federated/SpuriousDependency.lf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/C/src/federated/SpuriousDependency.lf b/test/C/src/federated/SpuriousDependency.lf index fefadc4617..84ad5d94a2 100644 --- a/test/C/src/federated/SpuriousDependency.lf +++ b/test/C/src/federated/SpuriousDependency.lf @@ -1,3 +1,10 @@ +/** + * This checks that a federated program does not deadlock when it is ambiguous, + * given the structure of a federate, whether certain ports should be allowed to + * precede others in the execution of a given tag. The version of LFC that was + * in the master branch on 4/15/2023 resolved the ambiguity in a way that does + * appear to result in deadlock. + */ target C reactor Passthrough { From a1653ac65929ddbb78f7b0b00dba59e88d0f723b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 15 Apr 2023 23:10:55 -0700 Subject: [PATCH 131/709] Format test. --- test/C/src/federated/SpuriousDependency.lf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/C/src/federated/SpuriousDependency.lf b/test/C/src/federated/SpuriousDependency.lf index 84ad5d94a2..05db0fe724 100644 --- a/test/C/src/federated/SpuriousDependency.lf +++ b/test/C/src/federated/SpuriousDependency.lf @@ -10,6 +10,7 @@ target C reactor Passthrough { input in: int output out: int + reaction(in) -> out {= lf_print("Hello from passthrough"); lf_set(out, in->value); @@ -34,7 +35,6 @@ federated reactor { t1 = new Twisty() t0.out1 -> t1.in0 t1.out1 -> t0.in0 - reaction(startup) -> t0.in1 {= - lf_set(t0.in1, 0); - =} + + reaction(startup) -> t0.in1 {= lf_set(t0.in1, 0); =} } From b39a00421a0f2c64e8a6cb78a9b2cc56c54b5641 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 16 Apr 2023 00:16:24 -0700 Subject: [PATCH 132/709] Address comments from review. --- test/C/src/federated/SpuriousDependency.lf | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/C/src/federated/SpuriousDependency.lf b/test/C/src/federated/SpuriousDependency.lf index 05db0fe724..0b9cad6e6c 100644 --- a/test/C/src/federated/SpuriousDependency.lf +++ b/test/C/src/federated/SpuriousDependency.lf @@ -1,11 +1,13 @@ /** * This checks that a federated program does not deadlock when it is ambiguous, - * given the structure of a federate, whether certain ports should be allowed to - * precede others in the execution of a given tag. The version of LFC that was - * in the master branch on 4/15/2023 resolved the ambiguity in a way that does - * appear to result in deadlock. + * given the structure of a federate, whether certain network sender/receiver + * reactions should be allowed to precede others in the execution of a given + * tag. The version of LFC that was in the master branch on 4/15/2023 resolved + * the ambiguity in a way that does appear to result in deadlock. */ -target C +target C { + timeout: 2 sec +} reactor Passthrough { input in: int @@ -35,6 +37,16 @@ federated reactor { t1 = new Twisty() t0.out1 -> t1.in0 t1.out1 -> t0.in0 + state count: int = 0 reaction(startup) -> t0.in1 {= lf_set(t0.in1, 0); =} + + reaction(t1.out0) {= self->count++; =} + + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + if (self->count != 1) { + lf_print_error_and_exit("Failed to receive expected input."); + } + =} } From 622cce6dd6d490f48c538913c936d99d46efa77b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 16 Apr 2023 00:19:02 -0700 Subject: [PATCH 133/709] Update comment again. --- test/C/src/federated/SpuriousDependency.lf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/C/src/federated/SpuriousDependency.lf b/test/C/src/federated/SpuriousDependency.lf index 0b9cad6e6c..a022c3abf4 100644 --- a/test/C/src/federated/SpuriousDependency.lf +++ b/test/C/src/federated/SpuriousDependency.lf @@ -1,9 +1,9 @@ /** * This checks that a federated program does not deadlock when it is ambiguous, - * given the structure of a federate, whether certain network sender/receiver - * reactions should be allowed to precede others in the execution of a given - * tag. The version of LFC that was in the master branch on 4/15/2023 resolved - * the ambiguity in a way that does appear to result in deadlock. + * given the structure of a federate, whether it is permissible to require + * certain network sender/receiver reactions to precede others in the execution + * of a given tag. The version of LFC that was in the master branch on 4/15/2023 + * resolved the ambiguity in a way that does appear to result in deadlock. */ target C { timeout: 2 sec From 145edf9e362d372861717a0138f1d66b1f166d9c Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sun, 16 Apr 2023 18:28:28 +0900 Subject: [PATCH 134/709] Add openssl to runner PATH --- .github/workflows/c-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 9d175941ed..fbb2669090 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -45,7 +45,9 @@ jobs: brew install coreutils brew install openssl brew link openssl --force - export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ + echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/runner/.bash_profile + export LDFLAGS="-L/usr/local/opt/openssl@3/lib" + export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti From 6cfd90a6a62dc23af989f6c5e6fe3eb4f00e0677 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sun, 16 Apr 2023 19:35:27 +0900 Subject: [PATCH 135/709] Update reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 4920ead796..1d573dac67 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 4920ead7960d1d30d7b4ba6becfb1bd9362b81e5 +Subproject commit 1d573dac6775c09bdec92b28a0a5fad5c88476f7 From e00e62e5e1624961f2997b58a65761907fed1443 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sun, 16 Apr 2023 20:39:14 +0900 Subject: [PATCH 136/709] Try brew reinstall openssl --- .github/workflows/c-tests.yml | 8 ++++---- org.lflang/src/lib/c/reactor-c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index fbb2669090..c0539a1c46 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -43,11 +43,11 @@ jobs: - name: Install dependencies OS X run: | brew install coreutils - brew install openssl + brew reinstall openssl brew link openssl --force - echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/runner/.bash_profile - export LDFLAGS="-L/usr/local/opt/openssl@3/lib" - export CPPFLAGS="-I/usr/local/opt/openssl@3/include" + # echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/runner/.bash_profile + # export LDFLAGS="-L/usr/local/opt/openssl@3/lib" + # export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 1d573dac67..8525a1fa27 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 1d573dac6775c09bdec92b28a0a5fad5c88476f7 +Subproject commit 8525a1fa27fdf3b420871ff0121b0f374fc3f053 From 69934f1271b5fb09a586eeb1b06b66257f487989 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sun, 16 Apr 2023 22:31:47 +0900 Subject: [PATCH 137/709] Try add openssl@3 --- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 3f5eb4a5b7..1c7c68f676 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -228,7 +228,7 @@ CodeBuilder generateCMakeCode( osName = targetConfig.platformOptions.platform.toString(); } if (osName.contains("mac")) { - cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); + cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl@3)"); } cMakeCode.pr("# Find OpenSSL and link to it"); cMakeCode.pr("find_package(OpenSSL REQUIRED)"); From f3f99c1727220c3ba1af24a193e2de9995fedc32 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Mon, 17 Apr 2023 10:27:18 +0900 Subject: [PATCH 138/709] Try ssh --- .github/workflows/c-tests.yml | 12 ++++++++---- .../src/org/lflang/generator/c/CCmakeGenerator.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index c0539a1c46..da060ce38a 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -23,6 +23,10 @@ jobs: matrix: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - name: Setup upterm session + uses: lhotari/action-upterm@v1 steps: - name: Check out lingua-franca repository uses: actions/checkout@v3 @@ -43,11 +47,11 @@ jobs: - name: Install dependencies OS X run: | brew install coreutils - brew reinstall openssl + brew install openssl brew link openssl --force - # echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/runner/.bash_profile - # export LDFLAGS="-L/usr/local/opt/openssl@3/lib" - # export CPPFLAGS="-I/usr/local/opt/openssl@3/include" + echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/runner/.bash_profile + export LDFLAGS="-L/usr/local/opt/openssl@3/lib" + export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 1c7c68f676..3f5eb4a5b7 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -228,7 +228,7 @@ CodeBuilder generateCMakeCode( osName = targetConfig.platformOptions.platform.toString(); } if (osName.contains("mac")) { - cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl@3)"); + cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); } cMakeCode.pr("# Find OpenSSL and link to it"); cMakeCode.pr("find_package(OpenSSL REQUIRED)"); From 755ff0984af939c4b9263342639c4de9a2e4ea43 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Mon, 17 Apr 2023 20:07:09 -0700 Subject: [PATCH 139/709] save before reattempting the merge --- .github/actions/prepare-build-env/action.yml | 14 +- .github/workflows/c-arduino-tests.yml | 9 +- .github/workflows/c-zephyr-tests.yml | 7 + .github/workflows/ci.yml | 2 + .github/workflows/cli-tests.yml | 15 +- .github/workflows/unit-tests.yml | 1 + .../org/lflang/tests/cli/issue490.stderr | 24 +- .../src/org/lflang/tests/TestRegistry.java | 70 +- .../src/org/lflang/tests/cli/LfcCliTest.java | 7 +- .../src/org/lflang/tests/cli/LffCliTest.java | 7 +- .../compiler/LinguaFrancaValidationTest.java | 10 +- .../lflang/tests/compiler/RoundTripTests.java | 1 + .../lflang/tests/lsp/MockReportProgress.java | 2 +- .../org/lflang/tests/runtime/CCppTest.java | 1 + org.lflang/src/org/lflang/ASTUtils.java | 332 ++++++ org.lflang/src/org/lflang/LinguaFranca.xtext | 74 +- org.lflang/src/org/lflang/ast/IsEqual.java | 27 +- org.lflang/src/org/lflang/ast/ToLf.java | 12 +- org.lflang/src/org/lflang/cli/CliBase.java | 8 +- .../federated/extensions/CExtension.java | 30 +- .../federated/extensions/TSExtension.java | 31 +- .../federated/generator/FedGenerator.java | 2 +- .../generator/FedPreambleEmitter.java | 9 +- .../generator/ReactionInstanceGraph.java | 76 +- .../org/lflang/generator/ReactorInstance.java | 966 +++++++++++++++ .../src/org/lflang/generator/Validator.java | 2 +- .../lflang/generator/c/CActionGenerator.java | 10 +- .../lflang/generator/c/CCmakeGenerator.java | 1 + .../generator/c/CConstructorGenerator.java | 11 +- .../org/lflang/generator/c/CFileConfig.java | 14 +- .../org/lflang/generator/c/CGenerator.java | 1048 ++++++++++++++++- .../lflang/generator/c/CMethodGenerator.java | 4 +- .../lflang/generator/c/CPortGenerator.java | 34 +- .../generator/c/CPreambleGenerator.java | 34 +- .../generator/c/CReactionGenerator.java | 767 +++++++++++- .../c/CReactorHeaderFileGenerator.java | 208 ++++ .../src/org/lflang/generator/c/CUtil.java | 20 +- .../cpp/CppAssembleMethodGenerator.kt | 16 +- .../org/lflang/generator/cpp/CppExtensions.kt | 2 +- .../generator/cpp/CppReactionGenerator.kt | 24 +- .../python/PythonActionGenerator.java | 6 +- .../generator/python/PythonGenerator.java | 283 +++++ .../generator/python/PythonPortGenerator.java | 5 +- .../python/PythonPreambleGenerator.java | 2 +- .../python/PythonReactionGenerator.java | 47 +- .../python/PythonReactorGenerator.java | 4 +- org.lflang/src/org/lflang/util/FileUtil.java | 13 +- .../org/lflang/validation/LFValidator.java | 944 +++++++++++++++ test/C/.gitignore | 1 + .../bank_multiport_to_reaction_no_inlining.c | 16 + ...nk_multiport_to_reaction_no_inlining.cmake | 1 + test/C/c/bank_to_reaction_no_inlining.c | 11 + test/C/c/bank_to_reaction_no_inlining.cmake | 1 + test/C/c/count.c | 15 + test/C/c/count.cmake | 1 + test/C/c/count_hierarchy.c | 15 + test/C/c/count_hierarchy.cmake | 1 + test/C/c/multiport_to_reaction_no_inlining.c | 14 + .../c/multiport_to_reaction_no_inlining.cmake | 1 + test/C/c/sendreceive.c | 17 + test/C/c/sendreceive.cmake | 1 + test/C/src/Deadline.lf | 12 +- test/C/src/DeadlineHandledAbove.lf | 10 + test/C/src/DeadlineInherited.lf | 3 +- test/C/src/DeadlinePriority.lf | 3 +- test/C/src/DeadlineWithAfterDelay.lf | 4 +- test/C/src/DeadlineWithBanks.lf | 4 +- test/C/src/DelayString.lf | 10 + test/C/src/DelayStruct.lf | 1 + test/C/src/Hello.lf | 4 + test/C/src/ScheduleValue.lf | 11 + test/C/src/SimpleDeadline.lf | 10 + test/C/src/StructAsState.lf | 13 +- test/C/src/TestForPreviousOutput.lf | 10 + test/C/src/Watchdog.lf | 29 +- test/C/src/concurrent/AsyncCallback.lf | 13 +- test/C/src/concurrent/AsyncCallbackDrop.lf | 10 + test/C/src/concurrent/AsyncCallbackReplace.lf | 10 + .../DeadlineHandledAboveThreaded.lf | 12 +- test/C/src/concurrent/DeadlineThreaded.lf | 12 +- test/C/src/concurrent/HelloThreaded.lf | 4 + test/C/src/concurrent/ScheduleAt.lf | 9 + test/C/src/concurrent/Tracing.lf | 4 + .../src/federated/DistributedNetworkOrder.lf | 10 + .../DistributedPhysicalActionUpstream.lf | 32 +- .../DistributedPhysicalActionUpstreamLong.lf | 31 +- test/C/src/federated/HelloDistributed.lf | 4 + ...oopDistributedCentralizedPhysicalAction.lf | 24 +- .../federated/LoopDistributedDecentralized.lf | 24 +- test/C/src/federated/LoopDistributedDouble.lf | 24 +- test/C/src/include/hello.h | 4 +- .../modal_models/BanksCount3ModesComplex.lf | 4 +- .../modal_models/BanksCount3ModesSimple.lf | 4 +- .../src/modal_models/BanksModalStateReset.lf | 4 +- test/C/src/modal_models/ConvertCaseTest.lf | 8 +- test/C/src/modal_models/ModalActions.lf | 4 +- test/C/src/modal_models/ModalAfter.lf | 4 +- test/C/src/modal_models/ModalCycleBreaker.lf | 4 +- .../src/modal_models/ModalStartupShutdown.lf | 4 +- test/C/src/modal_models/ModalStateReset.lf | 4 +- .../C/src/modal_models/ModalStateResetAuto.lf | 4 +- test/C/src/modal_models/ModalTimers.lf | 4 +- .../MultipleOutputFeeder_2Connections.lf | 4 +- ...ultipleOutputFeeder_ReactionConnections.lf | 4 +- test/C/src/modal_models/util/TraceTesting.lf | 4 - test/C/src/multiport/BankIndexInitializer.lf | 4 +- .../BankMultiportToReactionNoInlining.lf | 30 + .../no_inlining/BankToReactionNoInlining.lf | 16 + test/C/src/no_inlining/Count.lf | 16 + test/C/src/no_inlining/CountHierarchy.lf | 23 + test/C/src/no_inlining/IntPrint.lf | 22 + .../MultiportToReactionNoInlining.lf | 35 + test/C/src/token/include/array.h | 6 +- test/Python/.gitignore | 1 + util/tracing/.gitignore | 2 + util/tracing/trace_to_chrome.c | 25 +- util/tracing/trace_to_csv.c | 10 +- util/tracing/trace_to_influxdb.c | 33 +- util/tracing/trace_util.c | 7 +- 119 files changed, 5503 insertions(+), 469 deletions(-) create mode 100644 org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java create mode 100644 test/C/.gitignore create mode 100644 test/C/c/bank_multiport_to_reaction_no_inlining.c create mode 100644 test/C/c/bank_multiport_to_reaction_no_inlining.cmake create mode 100644 test/C/c/bank_to_reaction_no_inlining.c create mode 100644 test/C/c/bank_to_reaction_no_inlining.cmake create mode 100644 test/C/c/count.c create mode 100644 test/C/c/count.cmake create mode 100644 test/C/c/count_hierarchy.c create mode 100644 test/C/c/count_hierarchy.cmake create mode 100644 test/C/c/multiport_to_reaction_no_inlining.c create mode 100644 test/C/c/multiport_to_reaction_no_inlining.cmake create mode 100644 test/C/c/sendreceive.c create mode 100644 test/C/c/sendreceive.cmake create mode 100644 test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf create mode 100644 test/C/src/no_inlining/BankToReactionNoInlining.lf create mode 100644 test/C/src/no_inlining/Count.lf create mode 100644 test/C/src/no_inlining/CountHierarchy.lf create mode 100644 test/C/src/no_inlining/IntPrint.lf create mode 100644 test/C/src/no_inlining/MultiportToReactionNoInlining.lf create mode 100644 test/Python/.gitignore create mode 100644 util/tracing/.gitignore diff --git a/.github/actions/prepare-build-env/action.yml b/.github/actions/prepare-build-env/action.yml index 16cfc3c410..2d0c82c78f 100644 --- a/.github/actions/prepare-build-env/action.yml +++ b/.github/actions/prepare-build-env/action.yml @@ -15,9 +15,15 @@ runs: cat gradle.properties echo $JAVA_HOME shell: bash - - name: Create hash of Gradle configuration + - name: Create hash of Gradle configuration (macOS only) + run: | + echo "gradle-hash"="$(find . -type f \( -name "gradle.properties" -o -name "gradle-wrapper.properties" \) -exec cat {} + | shasum -a 256 | cut -d ' ' -f 1)" >> $GITHUB_ENV + if: ${{ runner.os == 'macOS' }} + shell: bash + - name: Create hash of Gradle configuration (Linux and Windows only) run: | echo "gradle-hash"="$(find . -type f \( -name "gradle.properties" -o -name "gradle-wrapper.properties" \) -exec cat {} + | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_ENV + if: ${{ runner.os == 'Windows' || runner.os == 'Linux' }} shell: bash - name: Cache uses: actions/cache@v3 @@ -28,3 +34,9 @@ runs: key: gradle-${{ runner.os }}-${{ env.gradle-hash }} # restore-keys: | # ${{ runner.os }}-gradle- + - name: Bring down Gradle daemon (Windows) + uses: webiny/action-post-run@3.0.0 + id: post-run-command + with: + run: ./gradlew --stop + if: ${{ runner.os == 'Windows' }} diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index f0f52bd93f..167e8f6f1c 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -59,4 +59,11 @@ jobs: arduino-cli core install arduino:sam arduino-cli core install arduino:mbed - name: Perform Arduino tests for C target with default scheduler - run: ./gradlew test --tests org.lflang.tests.runtime.CArduinoTest.buildArduinoTests \ No newline at end of file + run: ./gradlew test --tests org.lflang.tests.runtime.CArduinoTest.buildArduinoTests + - name: Report to CodeCov + uses: codecov/codecov-action@v3.1.1 + with: + file: org.lflang.tests/build/reports/xml/jacoco + fail_ci_if_error: false + verbose: true + if: ${{ !inputs.runtime-ref && runner.os == 'Linux' }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 87d48f37f1..8af72a2f39 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -61,3 +61,10 @@ jobs: run: | ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.build* util/RunZephyrTests.sh test/C/src-gen + - name: Report to CodeCov + uses: codecov/codecov-action@v3.1.1 + with: + file: org.lflang.tests/build/reports/xml/jacoco + fail_ci_if_error: false + verbose: true + if: ${{ !inputs.runtime-ref && runner.os == 'Linux' }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48110ac926..f6dd56ae40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,8 @@ jobs: uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'C' + benchmarks-ref: main + compiler-ref: master needs: cancel # Run language server tests. diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 9aaced4aba..056e32c04c 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -16,10 +16,6 @@ jobs: fetch-depth: 0 - name: Prepare build environment uses: ./.github/actions/prepare-build-env - # FIXME: reenable once the cli test is fixed - # - name: Run standalone cli tests - # run: | - # ./gradlew :org.lflang.cli:test --stacktrace - name: Test build bash scripts (Linux and macOS only) run: | .github/scripts/test-build.sh @@ -37,3 +33,14 @@ jobs: ./gradlew buildAll bin/lfc.ps1 --help if: ${{ runner.os == 'Windows' }} + - name: Run standalone cli tests + run: | + ./gradlew test --tests org.lflang.tests.cli.* --stacktrace +# NOTE: do not put other invocations for gradlew in between these steps, or coverage reporting will break. + - name: Report to CodeCov + uses: codecov/codecov-action@v3.1.1 + with: + file: org.lflang.tests/build/reports/xml/jacoco + fail_ci_if_error: false + verbose: true + if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 6c2704629e..1caec5c1ac 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -12,6 +12,7 @@ jobs: steps: - uses: actions/checkout@v3 with: + submodules: true fetch-depth: 0 - name: Prepare build environment uses: ./.github/actions/prepare-build-env diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/issue490.stderr b/org.lflang.tests/resources/org/lflang/tests/cli/issue490.stderr index edf3254755..fdaa4f8e0e 100644 --- a/org.lflang.tests/resources/org/lflang/tests/cli/issue490.stderr +++ b/org.lflang.tests/resources/org/lflang/tests/cli/issue490.stderr @@ -6,23 +6,19 @@ lfc: error: Name of main reactor must match the file name (or be omitted). | ^ Name of main reactor must match the file name (or be omitted). | 5 | state liss(2, 3); - -lfc: error: missing '{=' at '{' +lfc: error: no viable alternative at input '{' --> %%%PATH.lf%%%:6:22 | 5 | state liss(2, 3); 6 | reaction (startup) { - | ^ missing '{=' at '{' + | ^ no viable alternative at input '{' | 7 | print(self.liss) - -lfc: error: mismatched input '' expecting '=}' - --> %%%PATH.lf%%%:9:2 - | - 8 | } - | >>>>>>>>>>>>>> - 9 | } -10 | - | < mismatched input '' expecting '=}' -11 | - +lfc: error: no viable alternative at input '(' +--> %%%PATH.lf%%%:7:5 + | +6 | reaction (startup) { +7 | print(self.liss) + | ^^^^^ no viable alternative at input '(' + | +8 | } diff --git a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java index 232e735641..10fa68acaf 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java +++ b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java @@ -32,14 +32,14 @@ /** * A registry to retrieve tests from, organized by target and category. - * + * * @author Marten Lohstroh */ public class TestRegistry { - + static class TestMap { /** - * Registry that maps targets to maps from categories to sets of tests. + * Registry that maps targets to maps from categories to sets of tests. */ protected final Map>> map = new HashMap<>(); @@ -57,7 +57,7 @@ public TestMap() { map.put(target, categories); } } - + /** * Return a set of tests given a target and test category. * @param t The target. @@ -68,26 +68,26 @@ public Set getTests(Target t, TestCategory c) { return this.map.get(t).get(c); } } - + /** * List of directories that should be skipped when indexing test files. Any * test file that has a directory in its path that matches an entry in this * array will not be discovered. */ public static final String[] IGNORED_DIRECTORIES = {"failing", "knownfailed", "failed", "fed-gen"}; - + /** * Path to the root of the repository. */ public static final Path LF_REPO_PATH = Paths.get("").toAbsolutePath(); - + /** * Path to the test directory in the repository. */ public static final Path LF_TEST_PATH = LF_REPO_PATH.resolve("test"); /** - * Internal data structure that stores registered tests. + * Internal data structure that stores registered tests. */ protected static final TestMap registered = new TestMap(); @@ -96,31 +96,31 @@ public Set getTests(Target t, TestCategory c) { * source files with no main reactor are indexed here. */ protected static final TestMap ignored = new TestMap(); - + /** * A map from each test category to a set of tests that is the union of * all registered tests in that category across all targets. */ protected static final Map> allTargets = new HashMap<>(); - + /** * 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 mapped to. Matching is case * insensitive. - * + * * For example, the following files will all map to THREADED: * - C/threaded/Foo.lf - * - C/THREADED/Foo.lf + * - C/THREADED/Foo.lf * - C/Threaded/Foo.lf - * - C/foo/threaded/Bar.lf - * - C/foo/bar/threaded/Threaded.lf + * - C/foo/threaded/Bar.lf + * - C/foo/bar/threaded/Threaded.lf * - C/federated/threaded/bar.lf - * but the following will not: + * but the following will not: * - C/Foo.lf (maps to COMMON) * - C/Threaded.lf (maps to COMMON) * - C/threaded/federated/foo.lf (maps to FEDERATED) - * + * * @author Marten Lohstroh */ public enum TestCategory { @@ -140,7 +140,7 @@ public enum TestCategory { PROPERTIES(true), /** Tests concerning modal reactors */ MODAL_MODELS(true), - + NO_INLINING(false), // non-shared tests DOCKER(true), DOCKER_FEDERATED(true, "docker" + File.separator + "federated"), @@ -155,7 +155,7 @@ public enum TestCategory { public final boolean isCommon; public final String path; public final TestLevel level ; - + /** * Create a new test category. */ @@ -189,14 +189,14 @@ public String getPath() { /** * Return a header associated with the category. - * + * * @return A header to print in the test report. */ public String getHeader() { return TestBase.THICK_LINE + "Category: " + this.name(); } } - + // Static code that performs the file system traversal and discovers // all .lf files to be included in the registry. static { @@ -220,7 +220,7 @@ public String getHeader() { } else { System.out.println("WARNING: No test directory for target " + target + "\n"); } - + } catch (IOException e) { System.err.println( "ERROR: Caught exception while indexing tests for target " + target); @@ -231,7 +231,7 @@ public String getHeader() { c -> allTargets.get(c).addAll(getRegisteredTests(target, c, false))); } } - + /** * Calling this function forces the lazy initialization of the static code * that indexes all files. It is advisable to do this prior to executing @@ -239,10 +239,10 @@ public String getHeader() { * printed while indexing are printed first. */ public static void initialize() {} - + /** * Return the tests that were indexed for a given target and category. - * + * * @param target The target to get indexed tests for. * @param category The category of tests to include in the returned tests. * @param copy Whether to return copies of the indexed tests instead of the indexed tests themselves. @@ -260,7 +260,7 @@ public static Set getRegisteredTests(Target target, return registered.getTests(target, category); } } - + /** * Return the test that were found but not indexed because they did not * have a main reactor. @@ -275,11 +275,11 @@ public static String getCoverageReport(Target target, TestCategory category) { s.append(TestBase.THIN_LINE); s.append("Ignored: ").append(ignored.size()).append("\n"); s.append(TestBase.THIN_LINE); - + for (LFTest test : ignored) { s.append("No main reactor in: ").append(test).append("\n"); } - + Set own = getRegisteredTests(target, category, false); if (category.isCommon) { Set all = allTargets.get(category); @@ -301,17 +301,17 @@ public static String getCoverageReport(Target target, TestCategory category) { /** * FileVisitor implementation that maintains a stack to map found tests to - * the appropriate category and excludes directories that are listed as + * the appropriate category and excludes directories that are listed as * "ignored" from walks. - * + * * Specifically, when a directory is encountered that matches a category, * this category is pushed onto the stack. Similarly, when the DFS leaves * such a directory, its corresponding category is popped from the stack. * Any test (*.lf) file that is encountered will be mapped to the category - * that is on top of the stack. Initially, the stack has one element that + * that is on top of the stack. Initially, the stack has one element that * is TestCategory.COMMON, meaning that test files in the top-level test * directory for a given target will be mapped to that category. - * + * * @author Marten Lohstroh */ public static class TestDirVisitor extends SimpleFileVisitor { @@ -325,7 +325,7 @@ public static class TestDirVisitor extends SimpleFileVisitor { * The target that all encountered tests belong to. */ protected Target target; - + protected ResourceSet rs; protected Path srcBasePath; @@ -342,7 +342,7 @@ public TestDirVisitor(ResourceSet rs, Target target, Path srcBasePath) { this.target = target; this.srcBasePath = srcBasePath; } - + /** * Push categories onto the stack as appropriate and skip directories * that should be ignored. @@ -363,7 +363,7 @@ public FileVisitResult preVisitDirectory(Path dir, } return CONTINUE; } - + /** * Pop categories from the stack as appropriate. */ @@ -377,7 +377,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) { } return CONTINUE; } - + /** * Add test files to the registry if they end with ".lf", but only if they have a main reactor. */ diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java index 477bd26c32..7143ba9375 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java @@ -34,6 +34,7 @@ import com.google.inject.Injector; +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.Properties; @@ -125,7 +126,8 @@ public void testVersion() { .verify(result -> { result.checkOk(); result.checkNoErrorOutput(); - result.checkStdOut(equalTo("lfc " + LocalStrings.VERSION + "\n")); + result.checkStdOut(equalTo( + "lfc " + LocalStrings.VERSION + System.lineSeparator())); }); } @@ -227,7 +229,8 @@ public void verifyGeneratorArgs(Path tempDir, String[] args) { assertEquals(properties.getProperty(BuildParm.LINT.getKey()), "true"); assertEquals(properties.getProperty(BuildParm.NO_COMPILE.getKey()), "true"); assertEquals(properties.getProperty(BuildParm.QUIET.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.RTI.getKey()), "path/to/rti"); + assertEquals(properties.getProperty(BuildParm.RTI.getKey()), + "path" + File.separator + "to" + File.separator + "rti"); assertEquals(properties.getProperty(BuildParm.RUNTIME_VERSION.getKey()), "rs"); assertEquals(properties.getProperty(BuildParm.SCHEDULER.getKey()), "GEDF_NP"); assertEquals(properties.getProperty(BuildParm.THREADING.getKey()), "false"); diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java index 3a34e9cb81..16a4e9b32d 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java @@ -30,6 +30,7 @@ import static org.lflang.tests.TestUtils.TempDirBuilder.dirBuilder; import static org.lflang.tests.TestUtils.TempDirChecker.dirChecker; +import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -76,7 +77,8 @@ public void testVersion() { ExecutionResult result = lffTester.run("--version"); result.checkOk(); result.checkNoErrorOutput(); - result.checkStdOut(equalTo("lff " + LocalStrings.VERSION + "\n")); + result.checkStdOut( + equalTo("lff " + LocalStrings.VERSION + System.lineSeparator())); } @@ -119,7 +121,8 @@ public void testFormatDirectoryVerbose(@TempDir Path tempDir) throws IOException result.checkOk(); - result.checkStdOut(containsString("Formatted src/File.lf")); + result.checkStdOut(containsString( + "Formatted src" + File.separator + "File.lf")); dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index c5ead40cb7..847a364193 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -1150,7 +1150,7 @@ private List synthesizeExamples(UnionType type, boolean correct) { */ private List synthesizeExamples(DictionaryType type, boolean correct) { List examples = new LinkedList<>(); - // Produce a set of singleton dictionaries. + // Produce a set of singleton dictionaries. // If incorrect examples are wanted, garble the key. for (DictionaryElement option : type.options) { synthesizeExamples(option.getType(), correct).forEach(it -> examples.add( @@ -1629,7 +1629,7 @@ public void testMainReactorHasHost() throws Exception { """; // TODO: Uncomment and fix test // List issues = validator.validate(parseWithoutError(testCase)); - // Assertions.assertTrue(issues.size() == 1 && + // Assertions.assertTrue(issues.size() == 1 && // issues.get(0).getMessage().contains("Cannot assign a host to reactor '") && // issues.get(0).getMessage().contains("' because it is not federated.")); } @@ -1810,7 +1810,7 @@ public void testMissingModeStateResetInstance() throws Exception { "This reactor contains state variables that are not reset upon mode entry: " + "s in R" + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " - + "It is usafe to instatiate this reactor inside a mode entered with reset."); + + "It is unsafe to instantiate this reactor inside a mode entered with reset."); } @Test @@ -1841,11 +1841,9 @@ public void testUnspecifiedTransitionType() throws Exception { } """; validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), null, - "You should specifiy a transition type! " + "You should specify a transition type! " + "Reset and history transitions have different effects on this target mode. " + "Currently, a reset type is implicitly assumed."); } } - - diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java index 24cb3554ff..801211be23 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java @@ -45,6 +45,7 @@ public void roundTripTest() { private void run(Path file) throws Exception { Model originalModel = LfParsingUtil.parse(file); + System.out.println(file); assertThat(originalModel.eResource().getErrors(), equalTo(emptyList())); // TODO: Check that the output is a fixed point final int smallLineLength = 20; diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java b/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java index 901f0e6154..014fcc7276 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java @@ -17,7 +17,7 @@ public MockReportProgress() { @Override public void apply(String message, Integer percentage) { - System.out.printf("%s [%d -> %d]%n", message, previousPercentProgress, percentage); + System.out.printf("MockReportProgress: %s [%d -> %d]%n", message, previousPercentProgress, percentage); if (percentage == null) return; if (percentage < previousPercentProgress || percentage < 0 || percentage > 100) failed = true; previousPercentProgress = percentage; diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java index db0ee3431f..17fd386ad8 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java @@ -46,6 +46,7 @@ private static boolean isExcludedFromCCpp(TestCategory category) { excluded |= isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER); excluded |= category == TestCategory.ZEPHYR; excluded |= category == TestCategory.ARDUINO; + excluded |= category == TestCategory.NO_INLINING; return !excluded; } } diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 46b913eee0..0fd819e0e0 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -59,6 +59,7 @@ import org.lflang.ast.ToText; import org.lflang.generator.CodeMap; import org.lflang.generator.InvalidSourceException; +import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Assignment; import org.lflang.lf.Code; @@ -801,6 +802,7 @@ public static Element toElement(boolean val) { return toElement(Boolean.toString(val), false); } +<<<<<<< HEAD public static Element toElement(int val) { return toElement(Integer.toString(val), false); } @@ -819,6 +821,336 @@ public static String baseType(Type type) { } else { if (type.isTime()) { return "time"; +======= + /** A list of all ports of {@code definition}, in an unspecified order. */ + public static List allPorts(Reactor definition) { + return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); + } + + /** + * Given a reactor class, return a list of all its instantiations, + * which includes instantiations of base classes that it extends. + * This also includes instantiations in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allInstantiations(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); + } + + public static Stream allNestedClasses(Reactor definition) { + return new HashSet<>(ASTUtils.allInstantiations(definition)).stream() + .map(Instantiation::getReactorClass) + .map(ASTUtils::toDefinition); + } + + /** + * Given a reactor class, return a list of all its methods, + * which includes methods of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allMethods(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); + } + + /** + * Given a reactor class, return a list of all its outputs, + * which includes outputs of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allOutputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); + } + + /** + * Given a reactor class, return a list of all its parameters, + * which includes parameters of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allParameters(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); + } + + /** + * Given a reactor class, return a list of all its reactions, + * which includes reactions of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allReactions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); + } + + /** + * Given a reactor class, return a list of all its state variables, + * which includes state variables of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allStateVars(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); + } + + /** + * Given a reactor class, return a list of all its timers, + * which includes timers of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allTimers(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); + } + + /** + * Given a reactor class, returns a list of all its modes, + * which includes modes of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allModes(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); + } + + /** A list of all reactors instantiated, transitively or intransitively, by {@code r}. */ + public static List recursiveChildren(ReactorInstance r) { + List ret = new ArrayList<>(); + ret.add(r.reactorDefinition); + for (var child: r.children) { + ret.addAll(recursiveChildren(child)); + } + return ret; + } + + /** + * Return all the superclasses of the specified reactor + * in deepest-first order. For example, if A extends B and C, and + * B and C both extend D, this will return the list [D, B, C, A]. + * Duplicates are removed. If the specified reactor does not extend + * any other reactor, then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + */ + public static LinkedHashSet superClasses(Reactor reactor) { + return superClasses(reactor, new LinkedHashSet<>()); + } + + /** + * Collect elements of type T from the class hierarchy and modes + * defined by a given reactor definition. + * @param definition The reactor definition. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + public static List collectElements(Reactor definition, EStructuralFeature feature) { + return ASTUtils.collectElements(definition, feature, true, true); + } + + /** + * Collect elements of type T contained in given reactor definition, including + * modes and the class hierarchy defined depending on configuration. + * @param definition The reactor definition. + * @param feature The structual model elements to collect. + * @param includeSuperClasses Whether to include elements in super classes. + * @param includeModes Whether to include elements in modes. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + @SuppressWarnings("unchecked") + public static List collectElements(Reactor definition, EStructuralFeature feature, boolean includeSuperClasses, boolean includeModes) { + List result = new ArrayList<>(); + + if (includeSuperClasses) { + // Add elements of elements defined in superclasses. + LinkedHashSet s = superClasses(definition); + if (s != null) { + for (Reactor superClass : s) { + result.addAll((EList) superClass.eGet(feature)); + } + } + } + + // Add elements of the current reactor. + result.addAll((EList) definition.eGet(feature)); + + if (includeModes && reactorModeFeatureMap.containsKey(feature)) { + var modeFeature = reactorModeFeatureMap.get(feature); + // Add elements of elements defined in modes. + for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { + insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); + } + } + + return result; + } + + /** + * Adds the elements into the given list at a location matching to their textual position. + * + * When creating a flat view onto reactor elements including modes, the final list must be ordered according + * to the textual positions. + * + * Example: + * reactor R { + * reaction // -> is R.reactions[0] + * mode M { + * reaction // -> is R.mode[0].reactions[0] + * reaction // -> is R.mode[0].reactions[1] + * } + * reaction // -> is R.reactions[1] + * } + * In this example, it is important that the reactions in the mode are inserted between the top-level + * reactions to retain the correct global reaction ordering, which will be derived from this flattened view. + * + * @param list The list to add the elements into. + * @param elements The elements to add. + * @param mode The mode containing the elements. + * @param The type of elements to add (e.g., Port, Timer, etc.) + */ + private static void insertModeElementsAtTextualPosition(List list, List elements, Mode mode) { + if (elements.isEmpty()) { + return; // Nothing to add + } + + var idx = list.size(); + if (idx > 0) { + // If there are elements in the list, first check if the last element has the same container as the mode. + // I.e. we don't want to compare textual positions of different reactors (super classes) + if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { + var modeAstNode = NodeModelUtils.getNode(mode); + if (modeAstNode != null) { + var modePos = modeAstNode.getOffset(); + // Now move the insertion index from the last element forward as long as this element has a textual + // position after the mode. + do { + var astNode = NodeModelUtils.getNode(list.get(idx - 1)); + if (astNode != null && astNode.getOffset() > modePos) { + idx--; + } else { + break; // Insertion index is ok. + } + } while (idx > 0); + } + } + } + list.addAll(idx, elements); + } + + public static Iterable allElementsOfClass( + Resource resource, + Class elementClass + ) { + //noinspection StaticPseudoFunctionalStyleMethod + return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + + /** + * Translate the given code into its textual representation + * with {@code CodeMap.Correspondence} tags inserted, or + * return the empty string if {@code node} is {@code null}. + * This method should be used to generate code. + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toText(EObject node) { + if (node == null) return ""; + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); + } + + /** + * Translate the given code into its textual representation + * without {@code CodeMap.Correspondence} tags, or return + * the empty string if {@code node} is {@code null}. + * This method should be used for analyzing AST nodes in + * cases where they are easiest to analyze as strings. + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toOriginalText(EObject node) { + if (node == null) return ""; + return ToText.instance.doSwitch(node); + } + + /** + * Return an integer representation of the given element. + * + * Internally, this method uses Integer.decode, so it will + * also understand hexadecimal, binary, etc. + * + * @param e The element to be rendered as an integer. + */ + public static Integer toInteger(Element e) { + return Integer.decode(e.getLiteral()); + } + + /** + * Return a time value based on the given element. + * + * @param e The element to be rendered as a time value. + */ + public static TimeValue toTimeValue(Element e) { + return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); + } + + /** + * Returns the time value represented by the given AST node. + */ + public static TimeValue toTimeValue(Time e) { + if (!isValidTime(e)) { + // invalid unit, will have been reported by validator + throw new IllegalArgumentException(); + } + return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + } + + /** + * Return a boolean based on the given element. + * + * @param e The element to be rendered as a boolean. + */ + public static boolean toBoolean(Element e) { + return elementToSingleString(e).equalsIgnoreCase("true"); + } + + /** + * Given the right-hand side of a target property, return a string that + * represents the given value/ + * + * If the given value is not a literal or and id (but for instance and array or dict), + * an empty string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String elementToSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } + + /** + * Given the right-hand side of a target property, return a list with all + * the strings that the property lists. + * + * Arrays are traversed, so strings are collected recursively. Empty strings + * are ignored; they are not added to the list. + * @param value The right-hand side of a target property. + */ + public static List elementToListOfStrings(Element value) { + List elements = new ArrayList<>(); + if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + elements.addAll(elementToListOfStrings(element)); + } + return elements; +>>>>>>> origin } else { StringBuilder result = new StringBuilder(type.getId()); diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 9ee2cb520d..4e1645e9db 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -13,22 +13,22 @@ are permitted provided that the following conditions are met: this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ -/** +/** * Grammar for Lingua Franca. * A note of caution: extending this grammar with productions that introduce - * new terminals (i.e., anything written between quotes), will require those + * new terminals (i.e., anything written between quotes), will require those * terminals to also be added to the Token production at the bottom of this * file. Failing to do so will cause a parse error whenever a terminal not * listed in the Token production is featured in a segment of target-language @@ -44,7 +44,7 @@ import "http://www.eclipse.org/emf/2002/Ecore" as ecore // Use the package name "lf" for generated files defining the classes // in the metamodel (i.e., the classes representing nodes in the -// abstract syntax tree (AST), i.e., the eCore model). +// abstract syntax tree (AST), i.e., the eCore model). generate lf "https://lf-lang.org" /////////// Overall file @@ -106,7 +106,7 @@ TypeExpr: /** * Specification of the target language. Target properties can be specified in - * YAML format to pass on configuration details to the runtime environment. + * YAML format to pass on configuration details to the runtime environment. */ TargetDecl: 'target' name=ID (config=KeyValuePairs)? ';'?; @@ -115,11 +115,11 @@ TargetDecl: /////////// Statements /** - * Declaration of a state variable. Types are optional, but may be required - * during validation (depending on the target language). Initialization is also + * Declaration of a state variable. Types are optional, but may be required + * during validation (depending on the target language). Initialization is also * optional. A state variable can be initialized by assigning a `Expression` or list * of these. Note that a `Expression` may also be a reference to a parameter. - * The following checks must be carried out during validation: + * The following checks must be carried out during validation: * - if the list of initialization expressions has more than one element in it, a * type must be specified; * - if the `time` type is specified, there can only be a single initialization @@ -182,10 +182,10 @@ Mode: )* '}'; // Action that has either a physical or logical origin. -// +// // If the origin is logical, the minDelay is a minimum logical delay // after the logical time at which schedule() is called that the -// action will occur. If the origin is physical, then the +// action will occur. If the origin is physical, then the // minDelay is a minimum logical delay after the physical time // at which schedule() is called that the action will occur. // @@ -200,12 +200,11 @@ Action: Reaction: (attributes+=Attribute)* (('reaction') | mutation ?= 'mutation') - ('(' (triggers+=TriggerRef (',' triggers+=TriggerRef)*)? ')')? + ('(' (triggers+=TriggerRef (',' triggers+=TriggerRef)*)? ')') (sources+=VarRef (',' sources+=VarRef)*)? ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? - code=Code - (stp=STP)? - (deadline=Deadline)?; + ((('named' name=ID)? code=Code) | 'named' name=ID)(stp=STP)?(deadline=Deadline)? + ; TriggerRef: BuiltinTriggerRef | VarRef; @@ -237,7 +236,7 @@ Instantiation: Connection: ((leftPorts += VarRef (',' leftPorts += VarRef)*) | ( '(' leftPorts += VarRef (',' leftPorts += VarRef)* ')' iterated ?= '+'?)) - ('->' | physical?='~>') + ('->' | physical?='~>') rightPorts += VarRef (',' rightPorts += VarRef)* ('after' delay=Expression)? (serializer=Serializer)? @@ -271,7 +270,7 @@ Array: // todo allow empty array in grammar, replace with validator error Element: keyvalue=KeyValuePairs | array=Array - | literal=Literal + | literal=Literal | (time=INT unit=TimeUnit) | id=Path; @@ -284,8 +283,8 @@ Variable: TypedVariable | Timer | Mode | Watchdog; VarRef: - variable=[Variable] | container=[Instantiation] '.' variable=[Variable] - | interleaved?='interleaved' '(' (variable=[Variable] | container=[Instantiation] '.' variable=[Variable]) ')' + (variable=[Variable] | container=[Instantiation] '.' variable=[Variable] + | interleaved?='interleaved' '(' (variable=[Variable] | container=[Instantiation] '.' variable=[Variable]) ')') ('as' (alias=ID))? ; VarRefOrModeTransition returns VarRef: VarRef | transition=ModeTransition '(' variable=[Mode] ')'; @@ -338,7 +337,7 @@ Time: Port: Input | Output; - + // A type is in the target language, hence either an ID or target code. Type: time?='time' (arraySpec=ArraySpec)? @@ -435,24 +434,24 @@ IPV4Addr: ; IPV6Seg: - // NOTE: This rule is too permissive by design. + // NOTE: This rule is too permissive by design. // Further checking is done during validation. (INT | (INT? ID)) ; IPV6Addr: - // NOTE: This rule is too permissive by design. - // Further checking is done during validation. + // NOTE: This rule is too permissive by design. + // Further checking is done during validation. // IPV6 with truncation. - '::' | ('::' (IPV6Seg (':'))* IPV6Seg) | ((IPV6Seg (':'|'::'))+ IPV6Seg?) | - + '::' | ('::' (IPV6Seg (':'))* IPV6Seg) | ((IPV6Seg (':'|'::'))+ IPV6Seg?) | + // (Link-local IPv6 addresses with zone index) "fe80::7:8%1" (ID '::' IPV6Seg (':' IPV6Seg)* '%' (INT | ID)+) | // IPv4-mapped IPv6 addresses and IPv4-translated addresses ('::' IPV4Addr) | ('::' ID ':' (INT ':')? IPV4Addr) | - + // IPv4-Embedded IPv6 Address (((IPV6Seg (':' IPV6Seg)* '::') | (IPV6Seg (':' IPV6Seg)*) ':') IPV4Addr) ; @@ -469,7 +468,7 @@ Code: {Code} '{=' body=Body '=}' ; -FSName: +FSName: (ID | '.' | '_')+ ; // Absolute or relative directory path in Windows, Linux, or MacOS. @@ -508,11 +507,12 @@ Token: // Non-constant terminals ID | INT | FLOAT_EXP_SUFFIX | LT_ANNOT | STRING | CHAR_LIT | ML_COMMENT | SL_COMMENT | WS | ANY_OTHER | // Keywords - 'target' | 'import' | 'main' | 'realtime' | 'reactor' | 'state' | 'time' | - 'mutable' | 'input' | 'output' | 'timer' | 'action' | 'reaction' | + 'target' | 'import' | 'main' | 'realtime' | 'reactor' | 'state' | 'time' | + 'mutable' | 'input' | 'output' | 'timer' | 'action' | 'reaction' | 'startup' | 'shutdown' | 'after' | 'deadline' | 'mutation' | 'preamble' | 'new' | 'federated' | 'at' | 'as' | 'from' | 'widthof' | 'const' | 'method' | - 'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' | + 'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' | 'named' | + // Other terminals NEGINT | TRUE | FALSE | // Action origins @@ -532,7 +532,7 @@ Token: // Underscore '_' | // Arrow - '->' | + '->' | // Assignment '=' | // Percentage diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index f4bbc17f6d..3a7a5fb2cd 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -275,19 +275,20 @@ public Boolean caseAttrParm(AttrParm object) { .conclusion; } - @Override - public Boolean caseReaction(Reaction object) { - return new ComparisonMachine<>(object, Reaction.class) - .listsEquivalent(Reaction::getAttributes) - .listsEquivalent(Reaction::getTriggers) - .listsEquivalent(Reaction::getSources) - .listsEquivalent(Reaction::getEffects) - .equalAsObjects(Reaction::isMutation) - .equivalent(Reaction::getCode) - .equivalent(Reaction::getStp) - .equivalent(Reaction::getDeadline) - .conclusion; - } + @Override + public Boolean caseReaction(Reaction object) { + return new ComparisonMachine<>(object, Reaction.class) + .listsEquivalent(Reaction::getAttributes) + .listsEquivalent(Reaction::getTriggers) + .listsEquivalent(Reaction::getSources) + .listsEquivalent(Reaction::getEffects) + .equalAsObjects(Reaction::isMutation) + .equalAsObjects(Reaction::getName) + .equivalent(Reaction::getCode) + .equivalent(Reaction::getStp) + .equivalent(Reaction::getDeadline) + .conclusion; + } @Override public Boolean caseTriggerRef(TriggerRef object) { diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 2f0ec76d9b..ce1cdca9fe 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -598,13 +598,12 @@ public MalleableString caseAction(Action object) { @Override public MalleableString caseReaction(Reaction object) { - // ('reaction') - // ('(' (triggers+=TriggerRef (',' triggers+=TriggerRef)*)? ')')? + // (attributes+=Attribute)* + // (('reaction') | mutation ?= 'mutation') + // ('(' (triggers+=TriggerRef (',' triggers+=TriggerRef)*)? ')') // (sources+=VarRef (',' sources+=VarRef)*)? // ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)? - // code=Code - // (stp=STP)? - // (deadline=Deadline)? + // ((('named' name=ID)? code=Code) | 'named' name=ID)(stp=STP)?(deadline=Deadline)? Builder msb = new Builder(); addAttributes(msb, object::getAttributes); if (object.isMutation()) { @@ -633,7 +632,8 @@ public MalleableString caseReaction(Reaction object) { : doSwitch(varRef)) .collect(new Joiner(", "))); } - msb.append(" ").append(doSwitch(object.getCode())); + if (object.getName() != null) msb.append(" named ").append(object.getName()); + if (object.getCode() != null) msb.append(" ").append(doSwitch(object.getCode())); if (object.getStp() != null) msb.append(" ").append(doSwitch(object.getStp())); if (object.getDeadline() != null) msb.append(" ").append(doSwitch(object.getDeadline())); return msb.get(); diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index 4dea30b865..2f4a9d849c 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -157,16 +157,14 @@ public void run() { "No such file: " + topLevelArg.jsonFile); } } - // If args are given in a json string, (1) unpack them into an args - // array, and (2) call cmd.execute on them, which assigns them to their - // correct instance variables, then (3) recurses into run(). + // If args are given in a json string, unpack them and re-run + // picocli argument validation. if (topLevelArg.jsonString != null) { // Unpack args from json string. String[] args = jsonStringToArgs(topLevelArg.jsonString); // Execute application on unpacked args. CommandLine cmd = spec.commandLine(); - int exitCode = cmd.execute(args); - io.callSystemExit(exitCode); + cmd.execute(args); // If args are already unpacked, invoke tool-specific logic. } else { doRun(); diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index a2ac48216f..4698c2eb84 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -38,6 +38,7 @@ import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; +import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; @@ -99,7 +100,7 @@ public void initializeTargetConfig( federate.targetConfig.setByUser.add(TargetProperty.THREADING); // Include the fed setup file for this federate in the target property - String relPath = "include" + File.separator + "_" + federate.name + "_preamble.h"; + String relPath = getPreamblePath(federate); federate.targetConfig.fedSetupPreamble = relPath; federate.targetConfig.setByUser.add(TargetProperty.FED_SETUP); } @@ -471,7 +472,7 @@ public String getNetworkBufferType() { } /** - * Add preamble to a separate file `include/_federateName_preamble.h` to set up federated execution. + * Add preamble to a separate file to set up federated execution. * Return an empty string since no code generated needs to go in the source. */ @Override @@ -483,14 +484,29 @@ public String generatePreamble( ) throws IOException { // Put the C preamble in a `include/_federate.name + _preamble.h` file String cPreamble = makePreamble(federate, fileConfig, rtiConfig, errorReporter); - String relPath = "include" + File.separator + "_" + federate.name + "_preamble.h"; + String relPath = getPreamblePath(federate); Path fedPreamblePath = fileConfig.getSrcPath().resolve(relPath); Files.createDirectories(fedPreamblePath.getParent()); try (var writer = Files.newBufferedWriter(fedPreamblePath)) { writer.write(cPreamble); } + var includes = new CodeBuilder(); + if (federate.targetConfig.target != Target.Python) { + includes.pr("#ifdef __cplusplus\n" + + "extern \"C\" {\n" + + "#endif"); + includes.pr("#include \"core/federated/federate.h\""); + includes.pr("#include \"core/federated/net_common.h\""); + includes.pr("#include \"core/federated/net_util.h\""); + 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\n" + + "}\n" + + "#endif"); + } - return ""; + return includes.toString(); } /** @@ -558,7 +574,7 @@ private String generateInitializeTriggers(FederateInstance federate, ErrorReport code.pr(CExtensionUtils.initializeTriggersForNetworkActions(federate, main)); code.pr(CExtensionUtils.initializeTriggerForControlReactions(main, main, federate)); federatedReactor.setName(oldFederatedReactorName); - + return """ #define initialize_triggers_for_federate() \\ do { \\ @@ -744,5 +760,7 @@ private String generateCodeForPhysicalActions(FederateInstance federate, ErrorRe } return code.getCode(); } - + private String getPreamblePath(FederateInstance f) { + return "include" + File.separator + "_" + f.name + "_preamble.h"; + } } diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index e438b1b866..77d6203a93 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -96,22 +96,21 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf var upstreamConnectionDelays = getUpstreamConnectionDelays(federate); return """ - preamble {= - const defaultFederateConfig: __FederateConfig = { - dependsOn: [%s], - executionTimeout: undefined, - fast: false, - federateID: %d, - federationID: "Unidentified Federation", - keepAlive: false, - minOutputDelay: %s, - networkMessageActions: [%s], - rtiHost: "%s", - rtiPort: %d, - sendsTo: [%s], - upstreamConnectionDelays: [%s] - } - =}""".formatted( + const defaultFederateConfig: __FederateConfig = { + dependsOn: [%s], + executionTimeout: undefined, + fast: false, + federateID: %d, + federationID: "Unidentified Federation", + keepAlive: false, + minOutputDelay: %s, + networkMessageActions: [%s], + rtiHost: "%s", + rtiPort: %d, + sendsTo: [%s], + upstreamConnectionDelays: [%s] + } + """.formatted( federate.dependsOn.keySet().stream() .map(e->String.valueOf(e.id)) .collect(Collectors.joining(",")), diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index 18d5770165..cd9c2e95d0 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -288,7 +288,7 @@ private Map compileFederates( Resource res = rs.getResource(URI.createFileURI( fileConfig.getSrcPath().resolve(fed.name + ".lf").toAbsolutePath().toString() ), true); - FileConfig subFileConfig = LFGenerator.createFileConfig(res, fileConfig.getSrcGenPath(), false); + FileConfig subFileConfig = LFGenerator.createFileConfig(res, fileConfig.getSrcGenPath(), true); ErrorReporter subContextErrorReporter = new LineAdjustingErrorReporter(threadSafeErrorReporter, lf2lfCodeMapMap); var props = new Properties(); diff --git a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java index 20771e7848..354cd33044 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java @@ -39,8 +39,13 @@ String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, Rti )); } - preambleCode.pr(FedTargetExtensionFactory.getExtension(federate.targetConfig.target).generatePreamble( - federate, fileConfig, rtiConfig, errorReporter)); + preambleCode.pr(""" + preamble {= + %s + =}""".formatted(FedTargetExtensionFactory.getExtension(federate.targetConfig.target).generatePreamble( + federate, fileConfig, rtiConfig, errorReporter + )) + ); return preambleCode.getCode(); } diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index 116cbf3046..3422ee0d50 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -44,23 +44,23 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * In the worst case, of these runtime instances may have distinct dependencies, * and hence distinct levels in the graph. Moreover, some of these instances * may be involved in cycles while others are not. - * + * * Upon construction of this class, the runtime instances are created if necessary, * stored each ReactionInstance, and assigned levels (maximum number of * upstream reaction instances), deadlines, and single dominating reactions. - * + * * After creation, the resulting graph will be empty unless there are causality * cycles, in which case, the resulting graph is a graph of runtime reaction * instances that form cycles. - * + * * @author Marten Lohstroh * @author Edward A. Lee */ public class ReactionInstanceGraph extends PrecedenceGraph { - + /** - * Create a new graph by traversing the maps in the named instances - * embedded in the hierarchy of the program. + * Create a new graph by traversing the maps in the named instances + * embedded in the hierarchy of the program. */ public ReactionInstanceGraph(ReactorInstance main) { this.main = main; @@ -74,12 +74,12 @@ public ReactionInstanceGraph(ReactorInstance main) { * The main reactor instance that this graph is associated with. */ public final ReactorInstance main; - + /////////////////////////////////////////////////////////// //// Public methods - + /** - * Rebuild this graph by clearing and repeating the traversal that + * Rebuild this graph by clearing and repeating the traversal that * adds all the nodes and edges. */ public void rebuild() { @@ -89,7 +89,7 @@ public void rebuild() { // FIXME: Use {@link TargetProperty#EXPORT_DEPENDENCY_GRAPH}. // System.out.println(toDOT()); - // Assign a level to each reaction. + // Assign a level to each reaction. // If there are cycles present in the graph, it will be detected here. assignLevels(); if (nodeCount() != 0) { @@ -109,9 +109,9 @@ public void rebuildAndAssignDeadlines() { assignInferredDeadlines(); this.clear(); } - + /* - * Get an array of non-negative integers representing the number of reactions + * Get an array of non-negative integers representing the number of reactions * per each level, where levels are indices of the array. */ public Integer[] getNumReactionsPerLevel() { @@ -133,7 +133,7 @@ public int getBreadth() { /////////////////////////////////////////////////////////// //// Protected methods - + /** * Add to the graph edges between the given reaction and all the reactions * that depend on the specified port. @@ -144,19 +144,19 @@ protected void addDownstreamReactions(PortInstance port, ReactionInstance reacti // Use mixed-radix numbers to increment over the ranges. List srcRuntimes = reaction.getRuntimeInstances(); List eventualDestinations = port.eventualDestinations(); - + int srcDepth = (port.isInput())? 2 : 1; - + for (SendRange sendRange : eventualDestinations) { for (RuntimeRange dstRange : sendRange.destinations) { - + int dstDepth = (dstRange.instance.isOutput())? 2 : 1; MixedRadixInt dstRangePosition = dstRange.startMR(); int dstRangeCount = 0; MixedRadixInt sendRangePosition = sendRange.startMR(); int sendRangeCount = 0; - + while (dstRangeCount++ < dstRange.width) { int srcIndex = sendRangePosition.get(srcDepth); int dstIndex = dstRangePosition.get(dstDepth); @@ -177,7 +177,7 @@ protected void addDownstreamReactions(PortInstance port, ReactionInstance reacti if (srcRuntime.deadline.compareTo(dstRuntime.deadline) > 0) { srcRuntime.deadline = dstRuntime.deadline; } - + // If this seems to be a single dominating reaction, set it. // If another upstream reaction shows up, then this will be // reset to null. @@ -203,7 +203,7 @@ protected void addDownstreamReactions(PortInstance port, ReactionInstance reacti } /** - * Build the graph by adding nodes and edges based on the given reactor + * Build the graph by adding nodes and edges based on the given reactor * instance. * @param reactor The reactor on the basis of which to add nodes and edges. */ @@ -211,12 +211,12 @@ protected void addNodesAndEdges(ReactorInstance reactor) { ReactionInstance previousReaction = null; for (ReactionInstance reaction : reactor.reactions) { List runtimes = reaction.getRuntimeInstances(); - + // Add reactions of this reactor. for (Runtime runtime : runtimes) { - this.addNode(runtime); + this.addNode(runtime); } - + // If this is not an unordered reaction, then create a dependency // on any previously defined reaction. if (!reaction.isUnordered) { @@ -251,12 +251,12 @@ protected void addNodesAndEdges(ReactorInstance reactor) { addNodesAndEdges(child); } } - + /////////////////////////////////////////////////////////// //// Private fields - + /** - * Number of reactions per level, represented as a list of + * Number of reactions per level, represented as a list of * integers where the indices are the levels. */ private List numReactionsPerLevel = new ArrayList<>(List.of(0)); @@ -268,7 +268,7 @@ protected void addNodesAndEdges(ReactorInstance reactor) { * Analyze the dependencies between reactions and assign each reaction * instance a level. This method removes nodes from this graph as it * assigns levels. Any remaining nodes are part of causality cycles. - * + * * This procedure is based on Kahn's algorithm for topological sorting. * Rather than establishing a total order, we establish a partial order. * In this order, the level of each reaction is the least upper bound of @@ -276,13 +276,13 @@ protected void addNodesAndEdges(ReactorInstance reactor) { */ private void assignLevels() { List start = new ArrayList<>(rootNodes()); - + // All root nodes start with level 0. for (Runtime origin : start) { origin.level = 0; } - // No need to do any of this if there are no root nodes; + // No need to do any of this if there are no root nodes; // the graph must be cyclic. while (!start.isEmpty()) { Runtime origin = start.remove(0); @@ -293,7 +293,7 @@ private void assignLevels() { for (Runtime effect : downstreamAdjacentNodes) { // Stage edge between origin and effect for removal. toRemove.add(effect); - + // Update level of downstream node. effect.level = origin.level + 1; } @@ -306,7 +306,7 @@ private void assignLevels() { start.add(effect); } } - + // Remove visited origin. removeNode(origin); @@ -314,16 +314,16 @@ private void assignLevels() { adjustNumReactionsPerLevel(origin.level, 1); } } - + /** * This function assigns inferred deadlines to all the reactions in the graph. * It is modeled after `assignLevels` but it starts at the leaf nodes and uses * Kahns algorithm to build a reverse topologically sorted graph - * + * */ private void assignInferredDeadlines() { List start = new ArrayList<>(leafNodes()); - + // All leaf nodes have deadline initialized to their declared deadline or MAX_VALUE while (!start.isEmpty()) { Runtime origin = start.remove(0); @@ -334,7 +334,7 @@ private void assignInferredDeadlines() { for (Runtime upstream : upstreamAdjacentNodes) { // Stage edge between origin and upstream for removal. toRemove.add(upstream); - + // Update deadline of upstream node if origins deadline is earlier. if (origin.deadline.isEarlierThan(upstream.deadline)) { upstream.deadline = origin.deadline; @@ -349,12 +349,12 @@ private void assignInferredDeadlines() { start.add(upstream); } } - + // Remove visited origin. removeNode(origin); } } - + /** * Adjust {@link #numReactionsPerLevel} at index level by * adding to the previously recorded number valueToAdd. @@ -411,7 +411,7 @@ public String toDOT() { var currentLevelNodes = groupedNodes.get(level); for (var node: currentLevelNodes) { // Draw the node - var label = CUtil.getName(node.getReaction().getParent().reactorDeclaration) + "." + node.getReaction().getName(); + var label = CUtil.getName(node.getReaction().getParent().reactorDefinition) + "." + node.getReaction().getName(); // Need a positive number to name the nodes in GraphViz var labelHashCode = label.hashCode() & 0xfffffff; dotRepresentation.pr(" node_" + labelHashCode + " [label=\""+ label +"\"];"); @@ -419,7 +419,7 @@ public String toDOT() { // Draw the edges var downstreamNodes = getDownstreamAdjacentNodes(node); for (var downstreamNode: downstreamNodes) { - var downstreamLabel = CUtil.getName(downstreamNode.getReaction().getParent().reactorDeclaration) + "." + downstreamNode.getReaction().getName(); + var downstreamLabel = CUtil.getName(downstreamNode.getReaction().getParent().reactorDefinition) + "." + downstreamNode.getReaction().getName(); edges.append(" node_" + labelHashCode + " -> node_" + (downstreamLabel.hashCode() & 0xfffffff) + ";\n" ); diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index ba85ae8288..cb8f67b073 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -66,6 +66,7 @@ import org.lflang.lf.WidthSpec; /** +<<<<<<< HEAD * Representation of a compile-time instance of a reactor. If the reactor is instantiated as a bank * of reactors, or if any of its parents is instantiated as a bank of reactors, then one instance of * this ReactorInstance class represents all the runtime instances within these banks. The {@link @@ -78,6 +79,23 @@ * Lingua Franca program. If the program has causality loops (a programming error), then {@link * #hasCycles()} will return true and {@link #getCycles()} will return the ports and reaction * instances involved in the cycles. +======= + * Representation of a compile-time instance of a reactor. + * If the reactor is instantiated as a bank of reactors, or if any + * of its parents is instantiated as a bank of reactors, then one instance + * of this ReactorInstance class represents all the runtime instances within + * these banks. The {@link #getTotalWidth()} method returns the number of such + * runtime instances, which is the product of the bank width of this reactor + * instance and the bank widths of all of its parents. + * There is exactly one instance of this ReactorInstance class for each + * graphical rendition of a reactor in the diagram view. + * + * For the main reactor, which has no parent, once constructed, + * this object represents the entire Lingua Franca program. + * If the program has causality loops (a programming error), then + * {@link #hasCycles()} will return true and {@link #getCycles()} will + * return the ports and reaction instances involved in the cycles. +>>>>>>> origin * * @author Marten Lohstroh * @author Edward A. Lee @@ -247,6 +265,7 @@ public void clearCaches(boolean includingRuntimes) { cachedCycles = null; } +<<<<<<< HEAD /** * Return the set of ReactionInstance and PortInstance that form causality loops in the topmost * parent reactor in the instantiation hierarchy. This will return an empty set if there are no @@ -268,6 +287,64 @@ public Set> getCycles() { for (var cycle : cycleNodes) { for (ReactionInstance.Runtime runtime : cycle) { reactions.add(runtime.getReaction()); +======= + /** + * The contained reactor instances, in order of declaration. + * For banks of reactors, this includes both the bank definition + * Reactor (which has bankIndex == -2) followed by each of the + * bank members (which have bankIndex >= 0). + */ + public final List children = new ArrayList<>(); + + /** The input port instances belonging to this reactor instance. */ + public final List inputs = new ArrayList<>(); + + /** The output port instances belonging to this reactor instance. */ + public final List outputs = new ArrayList<>(); + + /** The parameters of this instance. */ + public final List parameters = new ArrayList<>(); + + /** List of reaction instances for this reactor instance. */ + public final List reactions = new ArrayList<>(); + + /** The timer instances belonging to this reactor instance. */ + public final List timers = new ArrayList<>(); + + /** The mode instances belonging to this reactor instance. */ + public final List modes = new ArrayList<>(); + + /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ + public final ReactorDecl reactorDeclaration; + + /** The reactor after imports are resolve. */ + public final Reactor reactorDefinition; + + /** Indicator that this reactor has itself as a parent, an error condition. */ + public final boolean recursive; + + ////////////////////////////////////////////////////// + //// Public methods. + + /** + * Assign levels to all reactions within the same root as this + * reactor. The level of a reaction r is equal to the length of the + * longest chain of reactions that must have the opportunity to + * execute before r at each logical tag. This fails and returns + * false if a causality cycle exists. + * + * This method uses a variant of Kahn's algorithm, which is linear + * in V + E, where V is the number of vertices (reactions) and E + * is the number of edges (dependencies between reactions). + * + * @return An empty graph if successful and otherwise a graph + * with runtime reaction instances that form cycles. + */ + public ReactionInstanceGraph assignLevels() { + if (depth != 0) return root().assignLevels(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); +>>>>>>> origin } } // Need to figure out which ports are involved in the cycles. @@ -283,6 +360,7 @@ public Set> getCycles() { cachedCycles.addAll(ports); } +<<<<<<< HEAD return cachedCycles; } @@ -296,6 +374,107 @@ public PortInstance getInput(String name) { if (port.getName().equals(name)) { return port; } +======= + /** + * This function assigns/propagates deadlines through the Reaction Instance Graph. + * It performs Kahn`s algorithm in reverse, starting from the leaf nodes and + * propagates deadlines upstream. To reduce cost, it should only be invoked when + * there are user-specified deadlines in the program. + * @return + */ + public ReactionInstanceGraph assignDeadlines() { + if (depth != 0) return root().assignDeadlines(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); + } + cachedReactionLoopGraph.rebuildAndAssignDeadlines(); + return cachedReactionLoopGraph; + } + + /** + * Return the instance of a child rector created by the specified + * definition or null if there is none. + * @param definition The definition of the child reactor ("new" statement). + */ + public ReactorInstance getChildReactorInstance(Instantiation definition) { + for (ReactorInstance child : this.children) { + if (child.definition == definition) { + return child; + } + } + return null; + } + + /** + * Clear any cached data in this reactor and its children. + * This is useful if a mutation has been realized. + */ + public void clearCaches() { + clearCaches(true); + } + + /** + * Clear any cached data in this reactor and its children. + * This is useful if a mutation has been realized. + * @param includingRuntimes If false, leave the runtime instances of reactions intact. + * This is useful for federated execution where levels are computed using + * the top-level connections, but then those connections are discarded. + */ + public void clearCaches(boolean includingRuntimes) { + if (includingRuntimes) cachedReactionLoopGraph = null; + for (ReactorInstance child : children) { + child.clearCaches(includingRuntimes); + } + for (PortInstance port : inputs) { + port.clearCaches(); + } + for (PortInstance port : outputs) { + port.clearCaches(); + } + for (ReactionInstance reaction : reactions) { + reaction.clearCaches(includingRuntimes); + } + cachedCycles = null; + } + + /** + * Return the set of ReactionInstance and PortInstance that form causality + * loops in the topmost parent reactor in the instantiation hierarchy. This will return an + * empty set if there are no causality loops. + */ + public Set> getCycles() { + if (depth != 0) return root().getCycles(); + if (cachedCycles != null) return cachedCycles; + cachedCycles = new LinkedHashSet<>(); + + ReactionInstanceGraph reactionRuntimes = assignLevels(); + if (reactionRuntimes.nodes().size() > 0) { + Set reactions = new LinkedHashSet<>(); + Set ports = new LinkedHashSet<>(); + // There are cycles. But the nodes set includes not + // just the cycles, but also nodes that are downstream of the + // cycles. Use Tarjan's algorithm to get just the cycles. + var cycleNodes = reactionRuntimes.getCycles(); + for (var cycle : cycleNodes) { + for (ReactionInstance.Runtime runtime : cycle) { + reactions.add(runtime.getReaction()); + } + } + // Need to figure out which ports are involved in the cycles. + // It may not be all ports that depend on this reaction. + for (ReactionInstance r : reactions) { + for (TriggerInstance p : r.effects) { + if (p instanceof PortInstance) { + findPaths((PortInstance)p, reactions, ports); + } + } + } + cachedCycles.addAll(reactions); + cachedCycles.addAll(ports); + } + + return cachedCycles; +>>>>>>> origin } return null; } @@ -321,6 +500,7 @@ public String uniqueID() { if (this.isMainOrFederated()) { return super.uniqueID() + "_main"; } +<<<<<<< HEAD return super.uniqueID(); } @@ -449,6 +629,14 @@ private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { static final ParameterInliner INSTANCE = new ParameterInliner(); +======= + + /** + * Override the base class to append [i_d], where d is the depth, + * if this reactor is in a bank of reactors. + * @return The name of this instance. + */ +>>>>>>> origin @Override public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { @@ -483,6 +671,7 @@ public Expression visitParameterRef(ParameterReference expr, ReactorInstance ins return defaultValue; } } +<<<<<<< HEAD } /** @@ -501,6 +690,28 @@ public List instantiations() { _instantiations.addAll(parent.instantiations()); } } +======= + + /** + * Return a parameter matching the specified name if the reactor has one + * and otherwise return null. + * @param name The parameter name. + */ + public ParameterInstance getParameter(String name) { + for (ParameterInstance parameter: parameters) { + if (parameter.getName().equals(name)) { + return parameter; + } + } + return null; + } + + /** + * Return the startup trigger or null if not used in any reaction. + */ + public TriggerInstance getStartupTrigger() { + return builtinTriggers.get(BuiltinTrigger.STARTUP); +>>>>>>> origin } return _instantiations; } @@ -536,6 +747,7 @@ public boolean isParent(ReactorInstance r) { if (p == r) return true; p = p.getParent(); } +<<<<<<< HEAD return false; } @@ -738,18 +950,65 @@ protected void createReactionInstances() { for (Reaction reaction : reactions) { if (AttributeUtils.isUnordered(reaction)) { unorderedReactions.add(reaction); +======= + + /** + * If this reactor is a bank or any of its parents is a bank, + * return the total number of runtime instances, which is the product + * of the widths of all the parents. + * Return -1 if the width cannot be determined. + */ + public int getTotalWidth() { + return getTotalWidth(0); + } + + /** + * If this reactor is a bank or any of its parents is a bank, + * return the total number of runtime instances, which is the product + * of the widths of all the parents. + * Return -1 if the width cannot be determined. + * @param atDepth The depth at which to determine the width. + * Use 0 to get the total number of instances. + * Use 1 to get the number of instances within a single top-level + * bank member (this is useful for federates). + */ + public int getTotalWidth(int atDepth) { + if (width <= 0) return -1; + if (depth <= atDepth) return 1; + int result = width; + ReactorInstance p = parent; + while (p != null && p.depth > atDepth) { + if (p.width <= 0) return -1; + result *= p.width; + p = p.parent; +>>>>>>> origin } // Create the reaction instance. var reactionInstance = new ReactionInstance(reaction, this, unorderedReactions.contains(reaction), count++); +<<<<<<< HEAD // Add the reaction instance to the map of reactions for this // reactor. this.reactions.add(reactionInstance); } +======= + /** + * Return the trigger instances (input ports, timers, and actions + * that trigger reactions) belonging to this reactor instance. + */ + public Set> getTriggers() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); + } + return triggers; +>>>>>>> origin } } +<<<<<<< HEAD /** Create all the watchdog instances of this reactor instance. */ protected void createWatchdogInstances() { List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); @@ -757,6 +1016,46 @@ protected void createWatchdogInstances() { for (Watchdog watchdog : watchdogs) { // Create the watchdog instance. var watchdogInstance = new WatchdogInstance(watchdog, this); +======= + /** + * Return the trigger instances (input ports, timers, and actions + * that trigger reactions) together the ports that the reaction reads + * but that don't trigger it. + * + * @return The trigger instances belonging to this reactor instance. + */ + public Set> getTriggersAndReads() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); + triggers.addAll(reaction.reads); + } + return triggers; + } + + /** + * Return true if the top-level parent of this reactor has causality cycles. + */ + public boolean hasCycles() { + return assignLevels().nodeCount() != 0; + } + + /** + * Given a parameter definition for this reactor, return the initial integer + * value of the parameter. If the parameter is overridden when instantiating + * this reactor or any of its containing reactors, use that value. + * Otherwise, use the default value in the reactor definition. + * If the parameter cannot be found or its value is not an integer, return null. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * + * @return An integer value or null. + */ + public Integer initialIntParameterValue(Parameter parameter) { + return ASTUtils.initialValueInt(parameter, instantiations()); + } +>>>>>>> origin // Add the watchdog instance to the list of watchdogs for this // reactor. @@ -791,6 +1090,7 @@ private ReactorInstance( this.reactorDeclaration = definition.getReactorClass(); this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); +<<<<<<< HEAD // check for recursive instantiation var currentParent = parent; var foundSelfAsParent = false; @@ -799,6 +1099,158 @@ private ReactorInstance( if (currentParent.reactorDefinition == this.reactorDefinition) { foundSelfAsParent = true; currentParent = null; // break +======= + Optional assignment = + instance.definition.getParameters().stream() + .filter(it -> it.getLhs().equals(expr.getParameter())) + .findAny(); // There is at most one + + if (assignment.isPresent()) { + // replace the parameter with its value. + Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); + // recursively resolve parameters + return instance.getParent().resolveParameters(value); + } else { + // In that case use the default value. Default values + // cannot use parameter values, so they don't need to + // be recursively resolved. + Initializer init = expr.getParameter().getInit(); + Expression defaultValue = ASTUtils.asSingleExpr(init); + if (defaultValue == null) { + // this is a problem + return super.visitParameterRef(expr, instance); + } + return defaultValue; + } + } + } + + /** + * Return a list of Instantiation objects for evaluating parameter + * values. The first object in the list is the AST Instantiation + * that created this reactor instance, the second is the AST instantiation + * that created the containing reactor instance, and so on until there + * are no more containing reactor instances. This will return an empty + * list if this reactor instance is at the top level (is main). + */ + public List instantiations() { + if (_instantiations == null) { + _instantiations = new ArrayList<>(); + if (definition != null) { + _instantiations.add(definition); + if (parent != null) { + _instantiations.addAll(parent.instantiations()); + } + } + } + return _instantiations; + } + + /** + * Returns true if this is a bank of reactors. + * @return true if a reactor is a bank, false otherwise + */ + public boolean isBank() { + return definition.getWidthSpec() != null; + } + + /** + * Returns whether this is a main or federated reactor. + * @return true if reactor definition is marked as main or federated, false otherwise. + */ + public boolean isMainOrFederated() { + return reactorDefinition != null + && (reactorDefinition.isMain() || reactorDefinition.isFederated()); + } + + /** + * Return true if the specified reactor instance is either equal to this + * reactor instance or a parent of it. + * @param r The reactor instance. + */ + public boolean isParent(ReactorInstance r) { + ReactorInstance p = this; + while (p != null) { + if (p == r) return true; + p = p.getParent(); + } + return false; + } + + /////////////////////////////////////////////////// + //// Methods for finding instances in this reactor given an AST node. + + /** + * Return the action instance within this reactor + * instance corresponding to the specified action reference. + * @param action The action as an AST node. + * @return The corresponding action instance or null if the + * action does not belong to this reactor. + */ + public ActionInstance lookupActionInstance(Action action) { + for (ActionInstance actionInstance : actions) { + if (actionInstance.definition == action) { + return actionInstance; + } + } + return null; + } + + /** + * Given a parameter definition, return the parameter instance + * corresponding to that definition, or null if there is + * no such instance. + * @param parameter The parameter definition (a syntactic object in the AST). + * @return A parameter instance, or null if there is none. + */ + public ParameterInstance lookupParameterInstance(Parameter parameter) { + for (ParameterInstance param : parameters) { + if (param.definition == parameter) { + return param; + } + } + return null; + } + + /** + * Given a port definition, return the port instance + * corresponding to that definition, or null if there is + * no such instance. + * @param port The port definition (a syntactic object in the AST). + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(Port port) { + // Search one of the inputs and outputs sets. + List ports = null; + if (port instanceof Input) { + ports = this.inputs; + } else if (port instanceof Output) { + ports = this.outputs; + } + for (PortInstance portInstance : ports) { + if (portInstance.definition == port) { + return portInstance; + } + } + return null; + } + + /** + * Given a reference to a port belonging to this reactor + * instance, return the port instance. + * Return null if there is no such instance. + * @param reference The port reference. + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(VarRef reference) { + if (!(reference.getVariable() instanceof Port)) { + // Trying to resolve something that is not a port + return null; + } + if (reference.getContainer() == null) { + // Handle local reference + return lookupPortInstance((Port) reference.getVariable()); +>>>>>>> origin } else { currentParent = currentParent.parent; } @@ -810,6 +1262,7 @@ private ReactorInstance( reporter.reportError(definition, "Recursive reactor instantiation."); } +<<<<<<< HEAD // If the reactor definition is null, give up here. Otherwise, diagram generation // will fail an NPE. if (reactorDefinition == null) { @@ -916,6 +1369,381 @@ private void establishPortConnections() { if (!srcRanges.hasNext()) { if (dstRanges.hasNext()) { reporter.reportWarning(connection, "No sources to provide inputs."); +======= + /** + * Return the reaction instance within this reactor + * instance corresponding to the specified reaction. + * @param reaction The reaction as an AST node. + * @return The corresponding reaction instance or null if the + * reaction does not belong to this reactor. + */ + public ReactionInstance lookupReactionInstance(Reaction reaction) { + for (ReactionInstance reactionInstance : reactions) { + if (reactionInstance.definition == reaction) { + return reactionInstance; + } + } + return null; + } + + /** + * Return the reactor instance within this reactor + * that has the specified instantiation. Note that this + * may be a bank of reactors. Return null if there + * is no such reactor instance. + */ + public ReactorInstance lookupReactorInstance(Instantiation instantiation) { + for (ReactorInstance reactorInstance : children) { + if (reactorInstance.definition == instantiation) { + return reactorInstance; + } + } + return null; + } + + /** + * Return the timer instance within this reactor + * instance corresponding to the specified timer reference. + * @param timer The timer as an AST node. + * @return The corresponding timer instance or null if the + * timer does not belong to this reactor. + */ + public TimerInstance lookupTimerInstance(Timer timer) { + for (TimerInstance timerInstance : timers) { + if (timerInstance.definition == timer) { + return timerInstance; + } + } + return null; + } + + /** Returns the mode instance within this reactor + * instance corresponding to the specified mode reference. + * @param mode The mode as an AST node. + * @return The corresponding mode instance or null if the + * mode does not belong to this reactor. + */ + public ModeInstance lookupModeInstance(Mode mode) { + for (ModeInstance modeInstance : modes) { + if (modeInstance.definition == mode) { + return modeInstance; + } + } + return null; + } + + /** + * Return a descriptive string. + */ + @Override + public String toString() { + return "ReactorInstance " + getFullName(); + } + + /** + * Assuming that the given expression denotes a valid time, return a time value. + * + * If the value is given as a parameter reference, this will look up the + * precise time value assigned to this reactor instance. + */ + public TimeValue getTimeValue(Expression expr) { + Expression resolved = resolveParameters(expr); + return getLiteralTimeValue(resolved); + } + + ////////////////////////////////////////////////////// + //// Protected fields. + + /** The generator that created this reactor instance. */ + protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references + + /** The map of used built-in triggers. */ + protected Map> builtinTriggers = new HashMap<>(); + + /** + * The LF syntax does not currently support declaring reactions unordered, + * but unordered reactions are created in the AST transformations handling + * federated communication and after delays. Unordered reactions can execute + * in any order and concurrently even though they are in the same reactor. + * FIXME: Remove this when the language provides syntax. + */ + protected Set unorderedReactions = new LinkedHashSet<>(); + + /** The nested list of instantiations that created this reactor instance. */ + protected List _instantiations; + + ////////////////////////////////////////////////////// + //// Protected methods. + + /** + * Create all the reaction instances of this reactor instance + * and record the dependencies and antidependencies + * between ports, actions, and timers and reactions. + * This also records the dependencies between reactions + * that follows from the order in which they are defined. + */ + protected void createReactionInstances() { + List reactions = ASTUtils.allReactions(reactorDefinition); + if (reactions != null) { + int count = 0; + + // Check for startup and shutdown triggers. + for (Reaction reaction : reactions) { + if (AttributeUtils.isUnordered(reaction)) { + unorderedReactions.add(reaction); + } + // Create the reaction instance. + var reactionInstance = new ReactionInstance(reaction, this, + unorderedReactions.contains(reaction), count++); + + // Add the reaction instance to the map of reactions for this + // reactor. + this.reactions.add(reactionInstance); + } + } + } + + /** + * Returns the built-in trigger or create a new one if none exists. + */ + protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { + return builtinTriggers.computeIfAbsent(trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + } + + //////////////////////////////////////// + //// Private constructors + + /** + * Create a runtime instance from the specified definition + * and with the specified parent that instantiated it. + * @param definition The instantiation statement in the AST. + * @param parent The parent, or null for the main rector. + * @param reporter An error reporter. + * @param desiredDepth The depth to which to expand the hierarchy. + */ + private ReactorInstance( + Instantiation definition, + ReactorInstance parent, + ErrorReporter reporter, + int desiredDepth) { + super(definition, parent); + this.reporter = reporter; + this.reactorDeclaration = definition.getReactorClass(); + this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); + + // check for recursive instantiation + var currentParent = parent; + var foundSelfAsParent = false; + do { + if (currentParent != null) { + if (currentParent.reactorDefinition == this.reactorDefinition) { + foundSelfAsParent = true; + currentParent = null; // break + } else { + currentParent = currentParent.parent; + } + } + } while(currentParent != null); + + this.recursive = foundSelfAsParent; + if (recursive) { + reporter.reportError(definition, "Recursive reactor instantiation."); + } + + // If the reactor definition is null, give up here. Otherwise, diagram generation + // will fail an NPE. + if (reactorDefinition == null) { + reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); + return; + } + + setInitialWidth(); + + // Apply overrides and instantiate parameters for this reactor instance. + for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { + this.parameters.add(new ParameterInstance(parameter, this)); + } + + // Instantiate inputs for this reactor instance + for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { + this.inputs.add(new PortInstance(inputDecl, this, reporter)); + } + + // Instantiate outputs for this reactor instance + for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { + this.outputs.add(new PortInstance(outputDecl, this, reporter)); + } + + // Do not process content (except interface above) if recursive + if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { + // Instantiate children for this reactor instance. + // While doing this, assign an index offset to each. + for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { + var childInstance = new ReactorInstance( + child, + this, + reporter, + desiredDepth + ); + this.children.add(childInstance); + } + + // Instantiate timers for this reactor instance + for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { + this.timers.add(new TimerInstance(timerDecl, this)); + } + + // Instantiate actions for this reactor instance + for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { + this.actions.add(new ActionInstance(actionDecl, this)); + } + + establishPortConnections(); + + // Create the reaction instances in this reactor instance. + // This also establishes all the implied dependencies. + // Note that this can only happen _after_ the children, + // port, action, and timer instances have been created. + createReactionInstances(); + + // Instantiate modes for this reactor instance + // This must come after the child elements (reactions, etc) of this reactor + // are created in order to allow their association with modes + for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { + this.modes.add(new ModeInstance(modeDecl, this)); + } + for (ModeInstance mode : this.modes) { + mode.setupTranstions(); + } + } + } + + ////////////////////////////////////////////////////// + //// Private methods. + + /** + * Connect the given left port range to the given right port range. + * + * NOTE: This method is public to enable its use in unit tests. + * Otherwise, it should be private. This is why it is defined here, + * in the section labeled "Private methods." + * + * @param src The source range. + * @param dst The destination range. + * @param connection The connection establishing this relationship. + */ + public static void connectPortInstances( + RuntimeRange src, + RuntimeRange dst, + Connection connection + ) { + SendRange range = new SendRange(src, dst, src._interleaved, connection); + src.instance.dependentPorts.add(range); + dst.instance.dependsOnPorts.add(src); + } + + /** + * Populate connectivity information in the port instances. + * Note that this can only happen _after_ the children and port instances have been created. + * Unfortunately, we have to do some complicated things here + * to support multiport-to-multiport, multiport-to-bank, + * and bank-to-multiport communication. The principle being followed is: + * in each connection statement, for each port instance on the left, + * connect to the next available port on the right. + */ + private void establishPortConnections() { + for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { + List> leftPorts = listPortInstances(connection.getLeftPorts(), connection); + Iterator> srcRanges = leftPorts.iterator(); + List> rightPorts = listPortInstances(connection.getRightPorts(), connection); + Iterator> dstRanges = rightPorts.iterator(); + + // Check for empty lists. + if (!srcRanges.hasNext()) { + if (dstRanges.hasNext()) { + reporter.reportWarning(connection, "No sources to provide inputs."); + } + return; + } else if (!dstRanges.hasNext()) { + reporter.reportWarning(connection, "No destination. Outputs will be lost."); + return; + } + + RuntimeRange src = srcRanges.next(); + RuntimeRange dst = dstRanges.next(); + + while(true) { + if (dst.width == src.width) { + connectPortInstances(src, dst, connection); + if (!dstRanges.hasNext()) { + if (srcRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning(connection, + "Source is wider than the destination. Outputs will be lost."); + } + break; + } + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + if (dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning(connection, + "Destination is wider than the source. Inputs will be missing."); + } + break; + } + } + dst = dstRanges.next(); + src = srcRanges.next(); + } else if (dst.width < src.width) { + // Split the left (src) range in two. + connectPortInstances(src.head(dst.width), dst, connection); + src = src.tail(dst.width); + if (!dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning(connection, + "Source is wider than the destination. Outputs will be lost."); + break; + } + dst = dstRanges.next(); + } else if (src.width < dst.width) { + // Split the right (dst) range in two. + connectPortInstances(src, dst.head(src.width), connection); + dst = dst.tail(src.width); + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + reporter.reportWarning(connection, + "Destination is wider than the source. Inputs will be missing."); + break; + } + } + src = srcRanges.next(); + } + } + } + } + + /** + * If path exists from the specified port to any reaction in the specified + * set of reactions, then add the specified port and all ports along the path + * to the specified set of ports. + * @return True if the specified port was added. + */ + private boolean findPaths( + PortInstance port, + Set reactions, + Set ports + ) { + if (ports.contains(port)) return false; + boolean result = false; + for (ReactionInstance d : port.getDependentReactions()) { + if (reactions.contains(d)) ports.add(port); + result = true; +>>>>>>> origin } return; } else if (!dstRanges.hasNext()) { @@ -1035,6 +1863,7 @@ private List> listPortInstances( if (!(portRef.getVariable() instanceof Port)) { reporter.reportError(portRef, "Not a port."); return result; +<<<<<<< HEAD } // First, figure out which reactor we are dealing with. // The reactor we want is the container of the port. @@ -1047,6 +1876,118 @@ private List> listPortInstances( // Skip this portRef so that diagram synthesis can complete. if (reactor != null) { PortInstance portInstance = reactor.lookupPortInstance((Port) portRef.getVariable()); +======= + } + + /** + * Given a list of port references, as found on either side of a connection, + * return a list of the port instance ranges referenced. These may be multiports, + * and may be ports of a contained bank (a port representing ports of the bank + * members) so the returned list includes ranges of banks and channels. + * + * If a given port reference has the form `interleaved(b.m)`, where `b` is + * a bank and `m` is a multiport, then the corresponding range in the returned + * list is marked interleaved. + * + * For example, if `b` and `m` have width 2, without the interleaved keyword, + * the returned range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. + * With the interleaved marking, the returned range represents the sequence + * `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have width 4. + * + * @param references The variable references on one side of the connection. + * @param connection The connection. + */ + private List> listPortInstances( + List references, Connection connection + ) { + List> result = new ArrayList<>(); + List> tails = new LinkedList<>(); + int count = 0; + for (VarRef portRef : references) { + // Simple error checking first. + if (!(portRef.getVariable() instanceof Port)) { + reporter.reportError(portRef, "Not a port."); + return result; + } + // First, figure out which reactor we are dealing with. + // The reactor we want is the container of the port. + // If the port reference has no container, then the reactor is this one. + var reactor = this; + if (portRef.getContainer() != null) { + reactor = getChildReactorInstance(portRef.getContainer()); + } + // The reactor can be null only if there is an error in the code. + // Skip this portRef so that diagram synthesis can complete. + if (reactor != null) { + PortInstance portInstance = reactor.lookupPortInstance( + (Port) portRef.getVariable()); + + Set interleaved = new LinkedHashSet<>(); + if (portRef.isInterleaved()) { + // NOTE: Here, we are assuming that the interleaved() + // keyword is only allowed on the multiports contained by + // contained reactors. + interleaved.add(portInstance.parent); + } + RuntimeRange range = new RuntimeRange.Port( + portInstance, interleaved); + // If this portRef is not the last one in the references list + // then we have to check whether the range can be incremented at + // the lowest two levels (port and container). If not, + // split the range and add the tail to list to iterate over again. + // The reason for this is that the connection has only local visibility, + // but the range width may be reflective of bank structure higher + // in the hierarchy. + if (count < references.size() - 1) { + int portWidth = portInstance.width; + int portParentWidth = portInstance.parent.width; + // If the port is being connected on the inside and there is + // more than one port in the list, then we can only connect one + // bank member at a time. + if (reactor == this && references.size() > 1) { + portParentWidth = 1; + } + int widthBound = portWidth * portParentWidth; + + // If either of these widths cannot be determined, assume infinite. + if (portWidth < 0) widthBound = Integer.MAX_VALUE; + if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < range.width) { + // Need to split the range. + tails.add(range.tail(widthBound)); + range = range.head(widthBound); + } + } + result.add(range); + } + } + // Iterate over the tails. + while(tails.size() > 0) { + List> moreTails = new LinkedList<>(); + count = 0; + for (RuntimeRange tail : tails) { + if (count < tails.size() - 1) { + int widthBound = tail.instance.width; + if (tail._interleaved.contains(tail.instance.parent)) { + widthBound = tail.instance.parent.width; + } + // If the width cannot be determined, assume infinite. + if (widthBound < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < tail.width) { + // Need to split the range again + moreTails.add(tail.tail(widthBound)); + tail = tail.head(widthBound); + } + } + result.add(tail); + } + tails = moreTails; + } + return result; + } +>>>>>>> origin Set interleaved = new LinkedHashSet<>(); if (portRef.isInterleaved()) { @@ -1055,6 +1996,7 @@ private List> listPortInstances( // contained reactors. interleaved.add(portInstance.parent); } +<<<<<<< HEAD RuntimeRange range = new RuntimeRange.Port(portInstance, interleaved); // If this portRef is not the last one in the references list // then we have to check whether the range can be incremented at @@ -1073,16 +2015,40 @@ private List> listPortInstances( portParentWidth = 1; } int widthBound = portWidth * portParentWidth; +======= + } + + ////////////////////////////////////////////////////// + //// Private fields. +>>>>>>> origin // If either of these widths cannot be determined, assume infinite. if (portWidth < 0) widthBound = Integer.MAX_VALUE; if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; +<<<<<<< HEAD if (widthBound < range.width) { // Need to split the range. tails.add(range.tail(widthBound)); range = range.head(widthBound); } +======= + /** + * Cached reaction graph containing reactions that form a causality loop. + */ + private ReactionInstanceGraph cachedReactionLoopGraph = null; + + /** + * Return true if this is a generated delay reactor that originates from + * an "after" delay on a connection. + * + * @return True if this is a generated delay, false otherwise. + */ + public boolean isGeneratedDelay() { + // FIXME: hacky string matching again... + if (this.definition.getReactorClass().getName().contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME)) { + return true; +>>>>>>> origin } result.add(range); } diff --git a/org.lflang/src/org/lflang/generator/Validator.java b/org.lflang/src/org/lflang/generator/Validator.java index bc11061f0d..7a9b85c453 100644 --- a/org.lflang/src/org/lflang/generator/Validator.java +++ b/org.lflang/src/org/lflang/generator/Validator.java @@ -161,7 +161,7 @@ private List> getValidationStrategies() { */ private Pair getValidationStrategy(Path generatedFile) { List sorted = getPossibleStrategies().stream() - .sorted(Comparator.comparingInt(vs -> -vs.getPriority())).collect(Collectors.toList()); + .sorted(Comparator.comparingInt(vs -> -vs.getPriority())).toList(); for (ValidationStrategy strategy : sorted) { LFCommand validateCommand = strategy.getCommand(generatedFile); if (validateCommand != null) { diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 1c4a1b45e8..af41440641 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -97,13 +97,12 @@ public static String generateTokenInitializer( */ public static void generateDeclarations( Reactor reactor, - ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode ) { for (Action action : ASTUtils.allActions(reactor)) { var actionName = action.getName(); - body.pr(action, CGenerator.variableStructType(action, decl)+" _lf_"+actionName+";"); + body.pr(action, CGenerator.variableStructType(action, reactor, false)+" _lf_"+actionName+";"); // Initialize the trigger pointer in the action. constructorCode.pr(action, "self->_lf_"+actionName+".trigger = &self->_lf__"+actionName+";"); } @@ -121,11 +120,12 @@ public static void generateDeclarations( * @return The auxiliary struct for the port as a string */ public static String generateAuxiliaryStruct( - ReactorDecl decl, + Reactor r, Action action, Target target, CTypes types, - CodeBuilder federatedExtension + CodeBuilder federatedExtension, + boolean userFacing ) { var code = new CodeBuilder(); code.pr("typedef struct {"); @@ -145,7 +145,7 @@ public static String generateAuxiliaryStruct( code.pr(valueDeclaration(action, target, types)); code.pr(federatedExtension.toString()); code.unindent(); - code.pr("} " + variableStructType(action, decl) + ";"); + code.pr("} " + variableStructType(action, r, userFacing) + ";"); return code.toString(); } diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 6710a0eb68..3f5eb4a5b7 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -212,6 +212,7 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE core)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC .)"); cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/)"); cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/api)"); cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core)"); diff --git a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java b/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java index 0cc2199cae..8944fd0796 100644 --- a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java @@ -1,8 +1,7 @@ package org.lflang.generator.c; -import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.CodeBuilder; -import org.lflang.lf.ReactorDecl; +import org.lflang.lf.Reactor; /** * Generates C constructor code for a reactor. @@ -16,12 +15,12 @@ public class CConstructorGenerator { * go into the constructor. */ public static String generateConstructor( - ReactorDecl reactor, + Reactor reactor, String constructorCode ) { var structType = CUtil.selfType(reactor); var code = new CodeBuilder(); - code.pr(structType+"* new_"+reactor.getName()+"() {"); + code.pr(structType+"* new_"+CUtil.getName(reactor)+"() {"); code.indent(); code.pr(structType+"* self = ("+structType+"*)_lf_new_reactor(sizeof("+structType+"));"); code.pr(constructorCode); @@ -30,4 +29,8 @@ public static String generateConstructor( code.pr("}"); return code.toString(); } + + public static String generateConstructorPrototype(Reactor reactor) { + return CUtil.selfType(reactor)+"* new_"+CUtil.getName(reactor)+"();"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CFileConfig.java b/org.lflang/src/org/lflang/generator/c/CFileConfig.java index 8bd70b74c3..362b8645b5 100644 --- a/org.lflang/src/org/lflang/generator/c/CFileConfig.java +++ b/org.lflang/src/org/lflang/generator/c/CFileConfig.java @@ -8,12 +8,18 @@ import org.lflang.FileConfig; public class CFileConfig extends FileConfig { + private final Path includePath; public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { super(resource, srcGenBasePath, useHierarchicalBin); + var includeDir = getOutPath().resolve("include"); + includePath = !useHierarchicalBin ? includeDir : includeDir.resolve(getOutPath().relativize(srcPath)).resolve(srcFile.getFileName().toString().split("\\.")[0]); } -} - - - + public Path getIncludePath() { + return includePath; + } + public String getRuntimeIncludePath() { + return "/lib/c/reactor-c/include"; + } +} diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 0ded0e2bc2..2ed77b27e1 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -25,8 +25,7 @@ package org.lflang.generator.c; import static org.lflang.ASTUtils.allActions; -import static org.lflang.ASTUtils.allInputs; -import static org.lflang.ASTUtils.allOutputs; +import static org.lflang.ASTUtils.allPorts; import static org.lflang.ASTUtils.allReactions; import static org.lflang.ASTUtils.allStateVars; import static org.lflang.ASTUtils.convertToEmptyListIfNull; @@ -36,12 +35,16 @@ import static org.lflang.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; +<<<<<<< HEAD import com.google.common.base.Objects; import com.google.common.collect.Iterables; +======= +>>>>>>> origin import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.regex.Pattern; @@ -83,7 +86,6 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.Mode; import org.lflang.lf.Model; -import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.Preamble; import org.lflang.lf.Reaction; @@ -94,6 +96,12 @@ import org.lflang.lf.Watchdog; import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; +<<<<<<< HEAD +======= + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +>>>>>>> origin /** * Generator for C target. This class generates C code defining each reactor class given in the @@ -584,6 +592,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { // ); // FIXME: Move to FedGenerator // Create the compiler to be used later +<<<<<<< HEAD var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); try { if (!cCompiler.runCCompiler(generator, context)) { @@ -592,6 +601,167 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { // If finish has already been called, it is illegal and makes no sense. However, // if finish has already been called, then this must be a federated execution. context.unsuccessfulFinish(); +======= + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); + handleProtoFiles(); + + // Derive target filename from the .lf filename. + var lfModuleName = fileConfig.name; + var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); + var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; + try { + generateCodeFor(lfModuleName); + copyTargetFiles(); + generateHeaders(); + code.writeToFile(targetFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + + // Create docker file. + if (targetConfig.dockerOptions != null && mainDef != null) { + try { + var dockerData = getDockerGenerator(context).generateDockerData(); + dockerData.writeDockerFile(); + (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + } catch (IOException e) { + throw new RuntimeException("Error while writing Docker files", e); + } + } + + // If cmake is requested, generate the CMakeLists.txt + if (targetConfig.platformOptions.platform != Platform.ARDUINO) { + var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; + var sources = new HashSet<>(ASTUtils.recursiveChildren(main)).stream() + .map(CUtil::getName).map(it -> it + (CCppMode ? ".cpp" : ".c")) + .collect(Collectors.toList()); + sources.add(cFilename); + var cmakeCode = cmakeGenerator.generateCMakeCode( + sources, + lfModuleName, + errorReporter, + CCppMode, + mainDef != null, + cMakeExtras, + targetConfig + ); + try { + cmakeCode.writeToFile(cmakeFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + } else { + try { + Path include = fileConfig.getSrcGenPath().resolve("include/"); + Path src = fileConfig.getSrcGenPath().resolve("src/"); + FileUtil.arduinoDeleteHelper(src, targetConfig.threading); + FileUtil.relativeIncludeHelper(src, include); + FileUtil.relativeIncludeHelper(include, include); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + + if (!targetConfig.noCompile) { + ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); + arduinoUtil.buildArduino(fileConfig, targetConfig); + context.finish( + GeneratorResult.Status.COMPILED, null + ); + } else { + System.out.println("********"); + System.out.println("To compile your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli compile -b --build-property compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\nTo flash/upload your generated sketch to the board, run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); + // System.out.println("For a list of all boards installed on your computer, you can use the following command:\n\n\tarduino-cli board listall\n"); + context.finish( + GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null) + ); + } + GeneratorUtils.refreshProject(resource, context.getMode()); + return; + } + + // Dump the additional compile definitions to a file to keep the generated project + // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can + // take over and do the rest of compilation. + try { + String compileDefs = targetConfig.compileDefinitions.keySet().stream() + .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) + .collect(Collectors.joining("\n")); + FileUtil.writeToFile( + compileDefs, + Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") + ); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + + // If this code generator is directly compiling the code, compile it now so that we + // clean it up after, removing the #line directives after errors have been reported. + if ( + !targetConfig.noCompile && targetConfig.dockerOptions == null + && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) + // This code is unreachable in LSP_FAST mode, so that check is omitted. + && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM + ) { + // FIXME: Currently, a lack of main is treated as a request to not produce + // a binary and produce a .o file instead. There should be a way to control + // this. + // Create an anonymous Runnable class and add it to the compileThreadPool + // so that compilation can happen in parallel. + var cleanCode = code.removeLines("#line"); + + var execName = lfModuleName; + var threadFileConfig = fileConfig; + var generator = this; // FIXME: currently only passed to report errors with line numbers in the Eclipse IDE + var CppMode = CCppMode; + // generatingContext.reportProgress( + // String.format("Generated code for %d/%d executables. Compiling...", federateCount, federates.size()), + // 100 * federateCount / federates.size() + // ); // FIXME: Move to FedGenerator + // Create the compiler to be used later + + var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); + try { + if (!cCompiler.runCCompiler(generator, context)) { + // If compilation failed, remove any bin files that may have been created. + CUtil.deleteBinFiles(threadFileConfig); + // If finish has already been called, it is illegal and makes no sense. However, + // if finish has already been called, then this must be a federated execution. + context.unsuccessfulFinish(); + } else { + context.finish( + GeneratorResult.Status.COMPILED, null + ); + } + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + + } + + // If a build directive has been given, invoke it now. + // Note that the code does not get cleaned in this case. + if (!targetConfig.noCompile) { + if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { + CUtil.runBuildCommand( + fileConfig, + targetConfig, + commandFactory, + errorReporter, + this::reportCommandErrors, + context.getMode() + ); + context.finish( + GeneratorResult.Status.COMPILED, null + ); + } + System.out.println("Compiled binary is in " + fileConfig.binPath); +>>>>>>> origin } else { context.finish(GeneratorResult.Status.COMPILED, null); } @@ -601,6 +771,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { } } +<<<<<<< HEAD // If a build directive has been given, invoke it now. // Note that the code does not get cleaned in this case. if (!targetConfig.noCompile) { @@ -618,6 +789,16 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { } else { context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); } +======= + private void generateCodeFor( + String lfModuleName + ) throws IOException { + startTimeStepIsPresentCount = 0; + code.pr(generateDirectives()); + code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); + // Generate code for each reactor. + generateReactorDefinitions(); +>>>>>>> origin // In case we are in Eclipse, make sure the generated code is visible. GeneratorUtils.refreshProject(resource, context.getMode()); @@ -631,6 +812,7 @@ private void generateCodeFor(String lfModuleName) { // Generate code for each reactor. generateReactorDefinitions(); +<<<<<<< HEAD // Generate main instance, if there is one. // Note that any main reactors in imported files are ignored. // Skip generation if there are cycles. @@ -653,6 +835,16 @@ private void generateCodeFor(String lfModuleName) { // Add counters for modal initialization initializeTriggerObjects.pr( CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); +======= + if (targetConfig.fedSetupPreamble != null) { + if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); + code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); + if (targetLanguageIsCpp()) code.pr("}"); + } + + // If there are timers, create a table of timers to be initialized. + code.pr(CTimerGenerator.generateDeclarations(timerCount)); +>>>>>>> origin // Create an array of arrays to store all self structs. // This is needed because connections cannot be established until @@ -897,6 +1089,7 @@ private void generateReactorDefinitions() { generateReactorClass(this.mainDef.getReactorClass()); } +<<<<<<< HEAD if (mainDef == null) { // Generate code for each reactor that was not instantiated in main or its children. for (Reactor r : reactors) { @@ -908,6 +1101,33 @@ private void generateReactorDefinitions() { // so that reaction bodies are checked). if (declarations.isEmpty()) { generateReactorClass(r); +======= + /** + * Look at the 'reactor' eResource. + * If it is an imported .lf file, incorporate it into the current + * program in the following manner: + * - Merge its target property with `targetConfig` + * - If there are any preambles, add them to the preambles of the reactor. + */ + private void inspectReactorEResource(ReactorDecl reactor) { + // If the reactor is imported, look at the + // target definition of the .lf file in which the reactor is imported from and + // append any cmake-include. + // Check if the reactor definition is imported + if (reactor.eResource() != mainDef.getReactorClass().eResource()) { + // Find the LFResource corresponding to this eResource + LFResource lfResource = null; + for (var resource : resources) { + if (resource.getEResource() == reactor.eResource()) { + lfResource = resource; + break; + } + } + // Copy the user files and cmake-includes to the src-gen path of the main .lf file + if (lfResource != null) { + copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + } +>>>>>>> origin } } } @@ -1029,6 +1249,7 @@ protected void generateUserPreamblesForReactor(Reactor reactor) { } } +<<<<<<< HEAD /** * Generate a constructor for the specified reactor in the specified federate. * @@ -1056,12 +1277,290 @@ protected void generateAuxiliaryStructs(ReactorDecl decl) { var federatedExtension = new CodeBuilder(); federatedExtension.pr( """ +======= + /** + * Generate code for defining all reactors that belong to the federate, + * including all the child reactors down the hierarchy. Duplicate + * Duplicates are avoided. + * + * Imported reactors' original .lf file is + * incorporated in the following manner: + * - If there are any cmake-include files, add them to the current list + * of cmake-include files. + * - If there are any preambles, add them to the preambles of the reactor. + */ + private void generateReactorDefinitions() throws IOException { + var generatedReactors = new LinkedHashSet(); + if (this.main != null) { + generateReactorChildren(this.main, generatedReactors); + } + + if (this.mainDef != null) { + generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); + } + + if (mainDef == null) { + // Generate code for each reactor that was not instantiated in main or its children. + for (Reactor r : reactors) { + // Get the declarations for reactors that are instantiated somewhere. + // A declaration is either a reactor definition or an import statement.; + var declarations = this.instantiationGraph.getDeclarations(r); + // If the reactor has no instantiations and there is no main reactor, then + // generate code for it anyway (at a minimum, this means that the compiler is invoked + // so that reaction bodies are checked). + if (declarations.isEmpty()) { + generateReactorClass(r); + } + } + } + } + + /** Generate user-visible header files for all reactors instantiated. */ + private void generateHeaders() throws IOException { + FileUtil.deleteDirectory(fileConfig.getIncludePath()); + FileUtil.copyDirectoryFromClassPath( + fileConfig.getRuntimeIncludePath(), + fileConfig.getIncludePath(), + false + ); + for (Reactor r : reactors) { + CReactorHeaderFileGenerator.doGenerate( + types, r, fileConfig, + (builder, rr, userFacing) -> { + generateAuxiliaryStructs(builder, rr, userFacing); + if (userFacing) { + ASTUtils.allInstantiations(r).stream().map(Instantiation::getReactorClass).collect(Collectors.toSet()).forEach(it -> { + ASTUtils.allPorts(ASTUtils.toDefinition(it)) + .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( + ASTUtils.toDefinition(it), p, getTarget(), errorReporter, types, new CodeBuilder(), true, it + ))); + }); + } + }, + this::generateTopLevelPreambles); + } + FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + } + + /** + * Generate code for the children of 'reactor' that belong to 'federate'. + * Duplicates are avoided. + * + * Imported reactors' original .lf file is + * incorporated in the following manner: + * - If there are any cmake-include files, add them to the current list + * of cmake-include files. + * - If there are any preambles, add them to the preambles of the reactor. + * + * @param reactor Used to extract children from + */ + private void generateReactorChildren( + ReactorInstance reactor, + LinkedHashSet generatedReactors + ) throws IOException { + for (ReactorInstance r : reactor.children) { + if (r.reactorDeclaration != null && + !generatedReactors.contains(r.reactorDefinition)) { + generatedReactors.add(r.reactorDefinition); + generateReactorChildren(r, generatedReactors); + inspectReactorEResource(r.reactorDeclaration); + generateReactorClass(r.reactorDefinition); + } + } + } + + /** + * Choose which platform files to compile with according to the OS. + * If there is no main reactor, then compilation will produce a .o file requiring further linking. + * Also, if useCmake is set to true, we don't need to add platform files. The CMakeLists.txt file + * will detect and use the appropriate platform file based on the platform that cmake is invoked on. + */ + private void pickCompilePlatform() { + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { + errorReporter.reportError("Platform " + osName + " is not supported"); + } + } + + + /** + * Copy target-specific header file to the src-gen directory. + */ + protected void copyTargetFiles() throws IOException { + // Copy the core lib + String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); + Path dest = fileConfig.getSrcGenPath(); + if (targetConfig.platformOptions.platform == Platform.ARDUINO) dest = dest.resolve("src"); + if (coreLib != null) { + FileUtil.copyDirectory(Path.of(coreLib), dest, true); + } else { + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/core", + dest.resolve("core"), + true + ); + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/lib", + dest.resolve("lib"), + true + ); + } + + // For the Zephyr target, copy default config and board files. + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyDirectoryFromClassPath( + "/lib/platform/zephyr/boards", + fileConfig.getSrcGenPath().resolve("boards"), + false + ); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", + fileConfig.getSrcGenPath().resolve("prj_lf.conf"), + true + ); + + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", + fileConfig.getSrcGenPath().resolve("Kconfig"), + true + ); + } + } + + //////////////////////////////////////////// + //// Code generators. + /** + * Generate a reactor class definition for the specified federate. + * A class definition has four parts: + * + * * Preamble code, if any, specified in the Lingua Franca file. + * * A "self" struct type definition (see the class documentation above). + * * A function for each reaction. + * * A constructor for creating an instance. + * for deleting an instance. + * + * If the reactor is the main reactor, then + * the generated code may be customized. Specifically, + * if the main reactor has reactions, these reactions + * will not be generated if they are triggered by or send + * data to contained reactors that are not in the federate. + * @param reactor The parsed reactor data structure. + */ + private void generateReactorClass(Reactor reactor) throws IOException { + // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. + CodeBuilder header = new CodeBuilder(); + CodeBuilder src = new CodeBuilder(); + final String headerName = CUtil.getName(reactor) + ".h"; + var guardMacro = headerName.toUpperCase().replace(".", "_"); + header.pr("#ifndef " + guardMacro); + header.pr("#define " + guardMacro); + generateReactorClassHeaders(reactor, headerName, header, src); + header.pr(generateTopLevelPreambles(reactor)); + generateUserPreamblesForReactor(reactor, src); + generateReactorClassBody(reactor, header, src); + header.pr("#endif // " + guardMacro); + FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); + var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : + CCppMode ? ".cpp" : ".c"; + FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); + } + + protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { + if (CCppMode) { + src.pr("extern \"C\" {"); + header.pr("extern \"C\" {"); + } + header.pr("#include \"include/core/reactor.h\""); + src.pr("#include \"include/api/api.h\""); + src.pr("#include \"include/api/set.h\""); + generateIncludes(reactor); + if (CCppMode) { + src.pr("}"); + header.pr("}"); + } + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); + src.pr("#include \"" + headerName + "\""); + ASTUtils.allNestedClasses(reactor).map(CUtil::getName) + .map(name -> "#include \"" + name + ".h\"") + .forEach(header::pr); + } + + private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { + // Some of the following methods create lines of code that need to + // go into the constructor. Collect those lines of code here: + var constructorCode = new CodeBuilder(); + generateAuxiliaryStructs(header, reactor, false); + generateSelfStruct(header, reactor, constructorCode); + generateMethods(src, reactor); + generateReactions(src, reactor); + generateConstructor(src, header, reactor, constructorCode); + } + + /** + * Generate methods for {@code reactor}. + */ + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { + CMethodGenerator.generateMethods(reactor, src, types); + } + + /** + * Generates preambles defined by user for a given reactor + * @param reactor The given reactor + */ + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { + src.pr("// *********** From the preamble, verbatim:"); + src.prSourceLineNumber(p.getCode()); + src.pr(toText(p.getCode())); + src.pr("\n// *********** End of preamble."); + } + } + + /** + * Generate a constructor for the specified reactor in the specified federate. + * @param reactor The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to + * go into the constructor. + */ + protected void generateConstructor( + CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode + ) { + header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); + src.pr(CConstructorGenerator.generateConstructor( + reactor, + constructorCode.toString() + )); + } + + protected void generateIncludes(Reactor r) { + code.pr("#include \"" + CUtil.getName(r) + ".h\""); + } + + /** + * Generate the struct type definitions for inputs, outputs, and + * actions of the specified reactor. + */ + protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { + // In the case where there are incoming + // p2p logical connections in decentralized + // federated execution, there will be an + // intended_tag field added to accommodate + // the case where a reaction triggered by a + // port or action is late due to network + // latency, etc.. + var federatedExtension = new CodeBuilder(); + federatedExtension.pr(""" +>>>>>>> origin #ifdef FEDERATED #ifdef FEDERATED_DECENTRALIZED %s intended_tag; #endif %s physical_time_of_arrival; #endif +<<<<<<< HEAD """ .formatted(types.getTargetTagType(), types.getTargetTimeType())); // First, handle inputs. @@ -1075,6 +1574,96 @@ protected void generateAuxiliaryStructs(ReactorDecl decl) { code.pr( CPortGenerator.generateAuxiliaryStruct( decl, output, getTarget(), errorReporter, types, federatedExtension)); +======= + """.formatted(types.getTargetTagType(), types.getTargetTimeType()) + ); + for (Port p : allPorts(r)) { + builder.pr(CPortGenerator.generateAuxiliaryStruct( + r, + p, + getTarget(), + errorReporter, + types, + federatedExtension, + userFacing, + null + )); + } + // The very first item on this struct needs to be + // a trigger_t* because the struct will be cast to (trigger_t*) + // by the lf_schedule() functions to get to the trigger. + for (Action action : allActions(r)) { + builder.pr(CActionGenerator.generateAuxiliaryStruct( + r, + action, + getTarget(), + types, + federatedExtension, + userFacing + )); + } + } + + /** + * Generate the self struct type definition for the specified reactor + * in the specified federate. + * @param decl The parsed reactor data structure. + * @param constructorCode Place to put lines of code that need to + * go into the constructor. + */ + private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = toDefinition(decl); + var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); + + // Construct the typedef for the "self" struct. + // Create a type name for the self struct. + var body = new CodeBuilder(); + + // Extensions can add functionality to the CGenerator + generateSelfStructExtension(body, decl, constructorCode); + + // Next handle parameters. + body.pr(CParameterGenerator.generateDeclarations(reactor, types)); + + // Next handle states. + body.pr(CStateGenerator.generateDeclarations(reactor, types)); + + // Next handle actions. + CActionGenerator.generateDeclarations(reactor, body, constructorCode); + + // Next handle inputs and outputs. + CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); + + // If there are contained reactors that either receive inputs + // from reactions of this reactor or produce outputs that trigger + // reactions of this reactor, then we need to create a struct + // inside the self struct for each contained reactor. That + // struct has a place to hold the data produced by this reactor's + // reactions and a place to put pointers to data produced by + // the contained reactors. + generateInteractingContainedReactors(reactor, body, constructorCode); + + // Next, generate the fields needed for each reaction. + CReactionGenerator.generateReactionAndTriggerStructs( + body, + reactor, + constructorCode, + types + ); + + // Next, generate fields for modes + CModesGenerator.generateDeclarations(reactor, body, constructorCode); + + // The first field has to always be a pointer to the list of + // of allocated memory that must be freed when the reactor is freed. + // This means that the struct can be safely cast to self_base_t. + builder.pr("typedef struct {"); + builder.indent(); + builder.pr("struct self_base_t base;"); + builder.pr(body.toString()); + builder.unindent(); + builder.pr("} " + selfType + ";"); +>>>>>>> origin } // Finally, handle actions. // The very first item on this struct needs to be @@ -1087,6 +1676,7 @@ protected void generateAuxiliaryStructs(ReactorDecl decl) { } } +<<<<<<< HEAD /** * Generate the self struct type definition for the specified reactor in the specified federate. * @@ -1278,6 +1868,43 @@ private void generateInteractingContainedReactors( + "] = &self->_lf__reaction_" + index + ";"); +======= + /** + * Generate structs and associated code for contained reactors that + * send or receive data to or from the container's reactions. + * + * If there are contained reactors that either receive inputs + * from reactions of this reactor or produce outputs that trigger + * reactions of this reactor, then we need to create a struct + * inside the self struct of the container for each contained reactor. + * That struct has a place to hold the data produced by the container reactor's + * reactions and a place to put pointers to data produced by + * the contained reactors. + * + * @param reactor The reactor. + * @param body The place to put the struct definition for the contained reactors. + * @param constructorCode The place to put matching code that goes in the container's constructor. + */ + private void generateInteractingContainedReactors( + Reactor reactor, + CodeBuilder body, + CodeBuilder constructorCode + ) { + // The contents of the struct will be collected first so that + // we avoid duplicate entries and then the struct will be constructed. + var contained = new InteractingContainedReactors(reactor); + // Next generate the relevant code. + for (Instantiation containedReactor : contained.containedReactors()) { + Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); + // First define an _width variable in case it is a bank. + var array = ""; + var width = -2; + // If the instantiation is a bank, find the maximum bank width + // to define an array. + if (containedReactor.getWidthSpec() != null) { + width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); + array = "[" + width + "]"; +>>>>>>> origin } constructorCode.pr( port, portOnSelf + "_trigger.reactions = " + portOnSelf + "_reactions;"); @@ -1293,11 +1920,56 @@ private void generateInteractingContainedReactors( portOnSelf + "_trigger.last = NULL;", portOnSelf + "_trigger.number_of_reactions = " + triggered.size() + ";")); +<<<<<<< HEAD // Set the physical_time_of_arrival constructorCode.pr( port, CExtensionUtils.surroundWithIfFederated( portOnSelf + "_trigger.physical_time_of_arrival = NEVER;")); +======= + // Generate one struct for each contained reactor that interacts. + body.pr("struct {"); + body.indent(); + for (Port port : contained.portsOfInstance(containedReactor)) { + if (port instanceof Input) { + // If the variable is a multiport, then the place to store the data has + // to be malloc'd at initialization. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); + } else { + // Is a multiport. + // Memory will be malloc'd in initialization. + body.pr(port, String.join("\n", + variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + "int "+port.getName()+"_width;" + )); + } + } else { + // Must be an output port. + // Outputs of contained reactors are pointers to the source of data on the + // self struct of the container. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); + } else { + // Is a multiport. + // Here, we will use an array of pointers. + // Memory will be malloc'd in initialization. + body.pr(port, String.join("\n", + variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + "int "+port.getName()+"_width;" + )); + } + body.pr(port, "trigger_t "+port.getName()+"_trigger;"); + var reactorIndex = ""; + if (containedReactor.getWidthSpec() != null) { + reactorIndex = "[reactor_index]"; + constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); + constructorCode.indent(); + } + var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); +>>>>>>> origin if (containedReactor.getWidthSpec() != null) { constructorCode.unindent(); @@ -1345,6 +2017,7 @@ public void generateReactions(ReactorDecl decl) { } } +<<<<<<< HEAD /** * Generate a reaction function definition for a reactor. This function will have a single * argument that is a void* pointing to a struct that contains parameters, state variables, inputs @@ -1358,8 +2031,37 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio code.pr( CReactionGenerator.generateReaction( +======= + /** Generate reaction functions definition for a reactor. + * These functions have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param r The reactor. + */ + public void generateReactions(CodeBuilder src, Reactor r) { + var reactionIndex = 0; + var reactor = ASTUtils.toDefinition(r); + for (Reaction reaction : allReactions(reactor)) { + generateReaction(src, reaction, r, reactionIndex); + // Increment reaction index even if the reaction is not in the federate + // so that across federates, the reaction indices are consistent. + reactionIndex++; + } + } + + /** Generate a reaction function definition for a reactor. + * This function will have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + src.pr(CReactionGenerator.generateReaction( +>>>>>>> origin reaction, - decl, + r, reactionIndex, mainDef, errorReporter, @@ -1820,12 +2522,80 @@ private void generateInitializeActionToken(ReactorInstance reactor) { } } +<<<<<<< HEAD var selfStruct = CUtil.reactorRef(action.getParent()); initializeTriggerObjects.pr( CActionGenerator.generateTokenInitializer(selfStruct, action.getName(), payloadSize)); } } } +======= + targetConfig.compileLibraries.add("-l"); + targetConfig.compileLibraries.add("protobuf-c"); + targetConfig.compilerFlags.add("-lprotobuf-c"); + } else { + errorReporter.reportError("protoc-c returns error code " + returnCode); + } + } + + /** + * Construct a unique type for the struct of the specified + * typed variable (port or action) of the specified reactor class. + * This is required to be the same as the type name returned by + * {@link #variableStructType(TriggerInstance)}. + */ + public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { + return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) +"_"+variable.getName()+"_t"; + } + + /** + * Construct a unique type for the struct of the specified + * instance (port or action). + * This is required to be the same as the type name returned by + * {@link #variableStructType(Variable, Reactor, boolean)}. + * @param portOrAction The port or action instance. + * @return The name of the self struct. + */ + public static String variableStructType(TriggerInstance portOrAction) { + return CUtil.getName(portOrAction.getParent().reactorDefinition)+"_"+portOrAction.getName()+"_t"; + } + + /** + * If tracing is turned on, then generate code that records + * the full name of the specified reactor instance in the + * trace table. If tracing is not turned on, do nothing. + * @param instance The reactor instance. + */ + private void generateTraceTableEntries(ReactorInstance instance) { + if (targetConfig.tracing != null) { + initializeTriggerObjects.pr( + CTracingGenerator.generateTraceTableEntries(instance) + ); + } + } + + /** + * Generate code to instantiate the specified reactor instance and + * initialize it. + * @param instance A reactor instance. + */ + public void generateReactorInstance(ReactorInstance instance) { + var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); + var fullName = instance.getFullName(); + initializeTriggerObjects.pr( + "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); + // Generate the instance self struct containing parameters, state variables, + // and outputs (the "self" struct). + initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(reactorClass)+"();"); + // Generate code to initialize the "self" struct in the + // _lf_initialize_trigger_objects function. + generateTraceTableEntries(instance); + generateReactorInstanceExtension(instance); + generateParameterInitialization(instance); + initializeOutputMultiports(instance); + initializeInputMultiports(instance); + recordBuiltinTriggers(instance); +>>>>>>> origin /** * Generate code that is executed while the reactor instance is being initialized. This is @@ -2182,6 +2952,7 @@ private void createMainReactorInstance() { } } +<<<<<<< HEAD /** * Generate an array of self structs for the reactor and one for each of its children. * @@ -2193,6 +2964,275 @@ private void generateSelfStructs(ReactorInstance r) { initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING(" + CUtil.reactorRefName(r) + ");"); for (ReactorInstance child : r.children) { generateSelfStructs(child); +======= + /** + * Generate code to initialize modes. + * @param instance The reactor instance. + */ + private void generateModeStructure(ReactorInstance instance) { + CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); + if (!instance.modes.isEmpty()) { + modalReactorCount += instance.getTotalWidth(); + } + } + + /** + * Generate runtime initialization code for parameters of a given reactor instance + * @param instance The reactor instance. + */ + protected void generateParameterInitialization(ReactorInstance instance) { + var selfRef = CUtil.reactorRef(instance); + // Set the local bank_index variable so that initializers can use it. + initializeTriggerObjects.pr("bank_index = "+CUtil.bankIndex(instance)+";" + + " SUPPRESS_UNUSED_WARNING(bank_index);"); + for (ParameterInstance parameter : instance.parameters) { + // NOTE: we now use the resolved literal value. For better efficiency, we could + // store constants in a global array and refer to its elements to avoid duplicate + // memory allocations. + // NOTE: If the parameter is initialized with a static initializer for an array + // or struct (the initialization expression is surrounded by { ... }), then we + // have to declare a static variable to ensure that the memory is put in data space + // and not on the stack. + // FIXME: Is there a better way to determine this than the string comparison? + var initializer = CParameterGenerator.getInitializer(parameter); + if (initializer.startsWith("{")) { + var temporaryVariableName = parameter.uniqueID(); + initializeTriggerObjects.pr(String.join("\n", + "static "+types.getVariableDeclaration(parameter.type, temporaryVariableName, true)+" = "+initializer+";", + selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" + )); + } else { + initializeTriggerObjects.pr(selfRef+"->"+parameter.getName()+" = "+initializer+";"); + } + } + } + + /** + * Generate code that mallocs memory for any output multiports. + * @param reactor The reactor instance. + */ + private void initializeOutputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance output : reactor.outputs) { + initializeTriggerObjects.pr(CPortGenerator.initializeOutputMultiport( + output, + reactorSelfStruct + )); + } + } + + /** + * Allocate memory for inputs. + * @param reactor The reactor. + */ + private void initializeInputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance input : reactor.inputs) { + initializeTriggerObjects.pr(CPortGenerator.initializeInputMultiport( + input, + reactorSelfStruct + )); + } + } + + @Override + public TargetTypes getTargetTypes() { + return types; + } + + /** + * + * @param context + * @return + */ + protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new CDockerGenerator(context); + } + + // ////////////////////////////////////////// + // // Protected methods. + + // Perform set up that does not generate code + protected void setUpGeneralParameters() { + accommodatePhysicalActionsIfPresent(); + targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); + // Create the main reactor instance if there is a main reactor. + createMainReactorInstance(); + if (hasModalReactors) { + // So that each separate compile knows about modal reactors, do this: + targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); + } + if (targetConfig.threading && targetConfig.platformOptions.platform == Platform.ARDUINO + && (targetConfig.platformOptions.board == null || !targetConfig.platformOptions.board.contains("mbed"))) { + //non-MBED boards should not use threading + System.out.println("Threading is incompatible on your current Arduino flavor. Setting threading to false."); + targetConfig.threading = false; + } + + if (targetConfig.platformOptions.platform == Platform.ARDUINO && !targetConfig.noCompile + && targetConfig.platformOptions.board == null) { + System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); + targetConfig.noCompile = true; + } + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake + pickScheduler(); + // FIXME: this and pickScheduler should be combined. + targetConfig.compileDefinitions.put( + "SCHEDULER", + targetConfig.schedulerType.name() + ); + targetConfig.compileDefinitions.put( + "NUMBER_OF_WORKERS", + String.valueOf(targetConfig.workers) + ); + } + pickCompilePlatform(); + } + + protected void handleProtoFiles() { + // Handle .proto files. + for (String file : targetConfig.protoFiles) { + this.processProtoFile(file); + } + } + + /** + * Generate code that needs to appear at the top of the generated + * C file, such as #define and #include statements. + */ + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr(CPreambleGenerator.generateDefineDirectives( + targetConfig, + fileConfig.getSrcGenPath(), + hasModalReactors + )); + code.pr(CPreambleGenerator.generateIncludeStatements( + targetConfig, + CCppMode + )); + return code.toString(); + } + + /** + * Generate top-level preamble code. + */ + protected String generateTopLevelPreambles(Reactor reactor) { + CodeBuilder builder = new CodeBuilder(); + var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; + builder.pr("#ifndef " + guard); + builder.pr("#define " + guard); + Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) + .flatMap(it -> ((Model) it.eContainer()).getPreambles().stream()) + .collect(Collectors.toSet()) + .forEach(it -> builder.pr(toText(it.getCode()))); + for (String file : targetConfig.protoFiles) { + var dotIndex = file.lastIndexOf("."); + var rootFilename = file; + if (dotIndex > 0) { + rootFilename = file.substring(0, dotIndex); + } + code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + } + builder.pr("#endif"); + return builder.toString(); + } + + protected boolean targetLanguageIsCpp() { + return CCppMode; + } + + /** Given a line of text from the output of a compiler, return + * an instance of ErrorFileAndLine if the line is recognized as + * the first line of an error message. Otherwise, return null. + * @param line A line of output from a compiler or other external + * tool that might generate errors. + * @return If the line is recognized as the start of an error message, + * then return a class containing the path to the file on which the + * error occurred (or null if there is none), the line number (or the + * string "1" if there is none), the character position (or the string + * "0" if there is none), and the message (or an empty string if there + * is none). + */ + @Override + public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + var matcher = compileErrorPattern.matcher(line); + if (matcher.find()) { + var result = new ErrorFileAndLine(); + result.filepath = matcher.group("path"); + result.line = matcher.group("line"); + result.character = matcher.group("column"); + result.message = matcher.group("message"); + + if (!result.message.toLowerCase().contains("error:")) { + result.isError = false; + } + return result; + } + return null; + } + + //////////////////////////////////////////// + //// Private methods. + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.C; + } + + //////////////////////////////////////////////////////////// + //// Private methods + + /** + * If a main or federated reactor has been declared, create a ReactorInstance + * for this top level. This will also assign levels to reactions, then, + * if the program is federated, perform an AST transformation to disconnect + * connections between federates. + */ + private void createMainReactorInstance() { + if (this.mainDef != null) { + if (this.main == null) { + // Recursively build instances. + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + var reactionInstanceGraph = this.main.assignLevels(); + if (reactionInstanceGraph.nodeCount() > 0) { + errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); + return; + } + if (hasDeadlines) { + this.main.assignDeadlines(); + } + // Inform the run-time of the breadth/parallelism of the reaction graph + var breadth = reactionInstanceGraph.getBreadth(); + if (breadth == 0) { + errorReporter.reportWarning("The program has no reactions"); + } else { + targetConfig.compileDefinitions.put( + "LF_REACTION_GRAPH_BREADTH", + String.valueOf(reactionInstanceGraph.getBreadth()) + ); + } + } + } + + } + + /** + * Generate an array of self structs for the reactor + * and one for each of its children. + * @param r The reactor instance. + */ + private void generateSelfStructs(ReactorInstance r) { + initializeTriggerObjects.pr(CUtil.selfType(r)+"* "+CUtil.reactorRefName(r)+"["+r.getTotalWidth()+"];"); + initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING("+CUtil.reactorRefName(r)+");"); + for (ReactorInstance child : r.children) { + generateSelfStructs(child); + } +>>>>>>> origin } } } diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index febac3362c..8228ce320c 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -72,7 +72,7 @@ public static String generateMethod( code.indent(); // Define the "self" struct. - String structType = CUtil.selfType(decl); + String structType = CUtil.selfType(ASTUtils.toDefinition(decl)); // A null structType means there are no inputs, state, // or anything else. No need to declare it. if (structType != null) { @@ -139,7 +139,7 @@ public static void signatures( * @return The function name for the method. */ private static String methodFunctionName(ReactorDecl reactor, Method method) { - return reactor.getName().toLowerCase() + "_method_" + method.getName(); + return CUtil.getName(ASTUtils.toDefinition(reactor)) + "_method_" + method.getName(); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 0db76a16ff..1b22b41f9a 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -44,22 +44,28 @@ public static void generateDeclarations( * Generate the struct type definitions for the port of the * reactor * - * @param decl The reactor declaration + * @param r The reactor * @param port The port to generate the struct * @param target The target of the code generation (C, CCpp or Python) * @param errorReporter The error reporter * @param types The helper object for types related stuff * @param federatedExtension The code needed to support federated execution + * @param userFacing Whether this struct is to be presented in a user-facing header + * @param decl The reactorDecl if this struct is for the header of this reactor's container; + * null otherwise * @return The auxiliary struct for the port as a string */ public static String generateAuxiliaryStruct( - ReactorDecl decl, + Reactor r, Port port, Target target, ErrorReporter errorReporter, CTypes types, - CodeBuilder federatedExtension + CodeBuilder federatedExtension, + boolean userFacing, + ReactorDecl decl ) { + assert decl == null || userFacing; var code = new CodeBuilder(); code.pr("typedef struct {"); code.indent(); @@ -79,10 +85,16 @@ public static String generateAuxiliaryStruct( code.pr(valueDeclaration(port, target, errorReporter, types)); code.pr(federatedExtension.toString()); code.unindent(); - code.pr("} "+variableStructType(port, decl)+";"); + var name = decl != null ? localPortName(decl, port.getName()) + : variableStructType(port, r, userFacing); + code.pr("} " + name + ";"); return code.toString(); } + public static String localPortName(ReactorDecl decl, String portName) { + return decl.getName().toLowerCase() + "_" + portName + "_t"; + } + /** * Allocate memory for the input port. * @param input The input port @@ -210,21 +222,21 @@ private static void generateInputDeclarations( if (ASTUtils.isMultiport(input)) { body.pr(input, String.join("\n", "// Multiport input array will be malloc'd later.", - variableStructType(input, decl)+"** _lf_"+inputName+";", + variableStructType(input, reactor, false)+"** _lf_"+inputName+";", "int _lf_"+inputName+"_width;", "// Default input (in case it does not get connected)", - variableStructType(input, decl)+" _lf_default__"+inputName+";", + variableStructType(input, reactor, false)+" _lf_default__"+inputName+";", "// Struct to support efficiently reading sparse inputs.", "lf_sparse_io_record_t* _lf_"+inputName+"__sparse;" )); } else { // input is not a multiport. body.pr(input, String.join("\n", - variableStructType(input, decl)+"* _lf_"+inputName+";", + variableStructType(input, reactor, false)+"* _lf_"+inputName+";", "// width of -2 indicates that it is not a multiport.", "int _lf_"+inputName+"_width;", "// Default input (in case it does not get connected)", - variableStructType(input, decl)+" _lf_default__"+inputName+";" + variableStructType(input, reactor, false)+" _lf_default__"+inputName+";" )); constructorCode.pr(input, String.join("\n", @@ -256,7 +268,7 @@ private static void generateOutputDeclarations( if (ASTUtils.isMultiport(output)) { body.pr(output, String.join("\n", "// Array of output ports.", - variableStructType(output, decl)+"* _lf_"+outputName+";", + variableStructType(output, reactor, false)+"* _lf_"+outputName+";", "int _lf_"+outputName+"_width;", "// An array of pointers to the individual ports. Useful", "// for the lf_set macros to work out-of-the-box for", @@ -264,11 +276,11 @@ private static void generateOutputDeclarations( "// value can be accessed via a -> operator (e.g.,foo[i]->value).", "// So we have to handle multiports specially here a construct that", "// array of pointers.", - variableStructType(output, decl)+"** _lf_"+outputName+"_pointers;" + variableStructType(output, reactor, false)+"** _lf_"+outputName+"_pointers;" )); } else { body.pr(output, String.join("\n", - variableStructType(output, decl)+" _lf_"+outputName+";", + variableStructType(output, reactor, false)+" _lf_"+outputName+";", "int _lf_"+outputName+"_width;" )); } diff --git a/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java b/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java index d78456e4ae..8ca0404d75 100644 --- a/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java @@ -36,34 +36,26 @@ public static String generateIncludeStatements( if (cppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) { code.pr("extern \"C\" {"); } - - String relPathHeader = ""; - if (targetConfig.platformOptions.platform == Platform.ARDUINO) { - relPathHeader = "src/include/"; - - CCoreFilesUtils.getCTargetHeader().forEach( - it -> code.pr("#include " + StringUtil.addDoubleQuotes("src/" + it)) - ); - } else { - CCoreFilesUtils.getCTargetHeader().forEach( - it -> code.pr("#include " + StringUtil.addDoubleQuotes(it)) - ); - } - code.pr("#include \"" + relPathHeader + "core/reactor.h\""); - code.pr("#include \"" + relPathHeader + "core/reactor_common.h\""); + code.pr("#include "); + code.pr("#include \"include/core/platform.h\""); + CCoreFilesUtils.getCTargetHeader().forEach( + it -> code.pr("#include " + StringUtil.addDoubleQuotes(it)) + ); + code.pr("#include \"include/core/reactor.h\""); + code.pr("#include \"include/core/reactor_common.h\""); if (targetConfig.threading) { - code.pr("#include \"" + relPathHeader + "core/threaded/scheduler.h\""); + code.pr("#include \"include/core/threaded/scheduler.h\""); } if (tracing != null) { - code.pr("#include \"" + relPathHeader + "core/trace.h\""); + code.pr("#include \"include/core/trace.h\""); } - code.pr("#include \"" + relPathHeader + "core/mixed_radix.h\""); - code.pr("#include \"" + relPathHeader + "core/port.h\""); + code.pr("#include \"include/core/mixed_radix.h\""); + code.pr("#include \"include/core/port.h\""); code.pr("int lf_reactor_c_main(int argc, const char* argv[]);"); if(targetConfig.fedSetupPreamble != null) { - code.pr("#include \"" + relPathHeader + "core/federated/federate.h\""); - code.pr("#include \"" + relPathHeader + "core/federated/net_common.h\""); + code.pr("#include \"include/core/federated/federate.h\""); + code.pr("#include \"include/core/federated/net_common.h\""); } if (cppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) { code.pr("}"); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index b7f72e216a..9625122e2b 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -13,7 +13,6 @@ import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetConfig; -import org.lflang.TargetProperty.Platform; import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Action; @@ -22,6 +21,7 @@ import org.lflang.lf.Code; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; +import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; import org.lflang.lf.ModeTransition; import org.lflang.lf.Output; @@ -37,6 +37,7 @@ import org.lflang.util.StringUtil; public class CReactionGenerator { +<<<<<<< HEAD protected static String DISABLE_REACTION_INITIALIZATION_MARKER = "// **** Do not include initialization code in this reaction."; @@ -61,6 +62,27 @@ public static String generateInitializationForReaction( Instantiation mainDef, boolean requiresTypes) { Reactor reactor = ASTUtils.toDefinition(decl); +======= + protected static String DISABLE_REACTION_INITIALIZATION_MARKER + = "// **** Do not include initialization code in this reaction."; // FIXME: Such markers should not exist (#1687) + + /** + * Generate necessary initialization code inside the body of the reaction that belongs to reactor decl. + * @param body The body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER. + * @param reaction The initialization code will be generated for this specific reaction + * @param decl The reactor that has the reaction + * @param reactionIndex The index of the reaction relative to other reactions in the reactor, starting from 0 + */ + public static String generateInitializationForReaction(String body, + Reaction reaction, + Reactor decl, + int reactionIndex, + CTypes types, + ErrorReporter errorReporter, + Instantiation mainDef, + boolean requiresTypes) { + Reactor reactor = ASTUtils.toDefinition(decl); +>>>>>>> origin // Construct the reactionInitialization code to go into // the body of the function before the verbatim code. @@ -68,6 +90,7 @@ public static String generateInitializationForReaction( CodeBuilder code = new CodeBuilder(); +<<<<<<< HEAD // Define the "self" struct. String structType = CUtil.selfType(decl); // A null structType means there are no inputs, state, @@ -80,6 +103,169 @@ public static String generateInitializationForReaction( + "* self = (" + structType + "*)instance_args; SUPPRESS_UNUSED_WARNING(self);")); +======= + // Define the "self" struct. + String structType = CUtil.selfType(decl); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr(String.join("\n", + structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" + )); + } + + // Do not generate the initialization code if the body is marked + // to not generate it. + if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { + return code.toString(); + } + + // A reaction may send to or receive from multiple ports of + // a contained reactor. The variables for these ports need to + // all be declared as fields of the same struct. Hence, we first + // collect the fields to be defined in the structs and then + // generate the structs. + Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); + + // Actions may appear twice, first as a trigger, then with the outputs. + // But we need to declare it only once. Collect in this data structure + // the actions that are declared as triggered so that if they appear + // again with the outputs, they are not defined a second time. + // That second redefinition would trigger a compile error. + Set actionsAsTriggers = new LinkedHashSet<>(); + + // Next, add the triggers (input and actions; timers are not needed). + // This defines a local variable in the reaction function whose + // name matches that of the trigger. The value of the local variable + // is a struct with a value and is_present field, the latter a boolean + // that indicates whether the input/action is present. + // If the trigger is an output, then it is an output of a + // contained reactor. In this case, a struct with the name + // of the contained reactor is created with one field that is + // a pointer to a struct with a value and is_present field. + // E.g., if the contained reactor is named 'c' and its output + // port is named 'out', then c.out->value c.out->is_present are + // defined so that they can be used in the verbatim code. + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (triggerAsVarRef.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, + fieldsForStructsForContainedReactors, + triggerAsVarRef, + decl, + types); + } else if (triggerAsVarRef.getVariable() instanceof Action) { + reactionInitialization.pr(generateActionVariablesInReaction( + (Action) triggerAsVarRef.getVariable(), + decl, + types + )); + actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); + } + } + } + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + // No triggers are given, which means react to any input. + // Declare an argument for every input. + // NOTE: this does not include contained outputs. + for (Input input : reactor.getInputs()) { + reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); + } + } + // Define argument for non-triggering inputs. + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (src.getVariable() instanceof Port) { + generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); + } else if (src.getVariable() instanceof Action) { + // It's a bit odd to read but not be triggered by an action, but + // OK, I guess we allow it. + reactionInitialization.pr(generateActionVariablesInReaction( + (Action) src.getVariable(), + decl, + types + )); + actionsAsTriggers.add((Action) src.getVariable()); + } + } + + // Define variables for each declared output or action. + // In the case of outputs, the variable is a pointer to where the + // output is stored. This gives the reaction code access to any previous + // value that may have been written to that output in an earlier reaction. + if (reaction.getEffects() != null) { + for (VarRef effect : reaction.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Action) { + // It is an action, not an output. + // If it has already appeared as trigger, do not redefine it. + if (!actionsAsTriggers.contains(effect.getVariable())) { + reactionInitialization.pr(CGenerator.variableStructType(variable, decl, false)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); + } + } else if (effect.getVariable() instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + reactionInitialization.pr( + "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" + + "lf_mode_change_type_t _lf_" + name + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY ? + "history_transition" : "reset_transition") + + ";" + ); + } else { + errorReporter.reportError( + reaction, + "In generateReaction(): " + name + " not a valid mode of this reactor." + ); + } + } else { + if (variable instanceof Output) { + reactionInitialization.pr(generateOutputVariablesInReaction( + effect, + decl, + errorReporter, + requiresTypes + )); + } else if (variable instanceof Input) { + // It is the input of a contained reactor. + generateVariablesForSendingToContainedReactors( + reactionInitialization, + fieldsForStructsForContainedReactors, + effect.getContainer(), + (Input) variable + ); + } else { + errorReporter.reportError( + reaction, + "In generateReaction(): effect is neither an input nor an output." + ); + } + } + } + } + // Before the reaction initialization, + // generate the structs used for communication to and from contained reactors. + for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { + String array = ""; + if (containedReactor.getWidthSpec() != null) { + String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); + code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); + // Windows does not support variables in arrays declared on the stack, + // so we use the maximum size over all bank members. + array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; + } + code.pr(String.join("\n", + "struct "+containedReactor.getName()+" {", + " "+fieldsForStructsForContainedReactors.get(containedReactor)+"", + "} "+containedReactor.getName()+array+";" + )); + } + // Next generate all the collected setup code. + code.pr(reactionInitialization.toString()); + return code.toString(); +>>>>>>> origin } // Do not generate the initialization code if the body is marked @@ -129,6 +315,7 @@ public static String generateInitializationForReaction( (Action) triggerAsVarRef.getVariable(), decl, types)); actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); } +<<<<<<< HEAD } } if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { @@ -194,6 +381,27 @@ public static String generateInitializationForReaction( errorReporter.reportError( reaction, "In generateReaction(): " + name + " not a valid mode of this reactor."); } +======= + String inputStructType = CGenerator.variableStructType(input, ASTUtils.toDefinition(definition.getReactorClass()), false); + String defName = definition.getName(); + String defWidth = generateWidthVariable(defName); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); + if (!ASTUtils.isMultiport(input)) { + // Contained reactor's input is not a multiport. + structBuilder.pr(inputStructType+"* "+inputName+";"); + if (definition.getWidthSpec() != null) { + // Contained reactor is a bank. + builder.pr(String.join("\n", + "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", + " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", + "}" + )); + } else { + // Contained reactor is not a bank. + builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); + } +>>>>>>> origin } else { if (variable instanceof Output) { reactionInitialization.pr( @@ -238,6 +446,7 @@ public static String generateInitializationForReaction( return code.toString(); } +<<<<<<< HEAD /** * Return the maximum bank width for the given instantiation within all instantiations of its * parent reactor. On the first call to this method, the breadcrumbs should be null and the max @@ -291,6 +500,78 @@ public static int maxContainedReactorBankWidth( int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); if (candidate > result) { result = candidate; +======= + /** + * Generate into the specified string builder the code to + * initialize local variables for ports in a reaction function + * from the "self" struct. The port may be an input of the + * reactor or an output of a contained reactor. The second + * argument provides, for each contained reactor, a place to + * write the declaration of the output of that reactor that + * is triggering reactions. + * @param builder The place into which to write the code. + * @param structs A map from reactor instantiations to a place to write + * struct fields. + */ + private static void generatePortVariablesInReaction( + CodeBuilder builder, + Map structs, + VarRef port, + Reactor r, + CTypes types + ) { + if (port.getVariable() instanceof Input) { + builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), r, types)); + } else { + // port is an output of a contained reactor. + Output output = (Output) port.getVariable(); + String portStructType = CGenerator.variableStructType(output, ASTUtils.toDefinition(port.getContainer().getReactorClass()), false); + + CodeBuilder structBuilder = structs.get(port.getContainer()); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(port.getContainer(), structBuilder); + } + String reactorName = port.getContainer().getName(); + String reactorWidth = generateWidthVariable(reactorName); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + // First define the struct containing the output value and indicator + // of its presence. + if (!ASTUtils.isMultiport(output)) { + // Output is not a multiport. + structBuilder.pr(portStructType+"* "+outputName+";"); + } else { + // Output is a multiport. + structBuilder.pr(String.join("\n", + portStructType+"** "+outputName+";", + "int "+outputWidth+";" + )); + } + + // Next, initialize the struct with the current values. + if (port.getContainer().getWidthSpec() != null) { + // Output is in a bank. + builder.pr(String.join("\n", + "for (int i = 0; i < "+reactorWidth+"; i++) {", + " "+reactorName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", + "}" + )); + if (ASTUtils.isMultiport(output)) { + builder.pr(String.join("\n", + "for (int i = 0; i < "+reactorWidth+"; i++) {", + " "+reactorName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", + "}" + )); + } + } else { + // Output is not in a bank. + builder.pr(reactorName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); + if (ASTUtils.isMultiport(output)) { + builder.pr(reactorName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); + } + } +>>>>>>> origin } } else { // Found some other instantiation, not the parent. @@ -308,6 +589,7 @@ public static int maxContainedReactorBankWidth( return result; } +<<<<<<< HEAD /** * Generate code for the body of a reaction that takes an input and schedules an action with the * value of that input. @@ -327,6 +609,22 @@ public static String generateDelayBody(String ref, String actionName, boolean is "}") : "lf_schedule_copy(" + actionName + ", 0, &" + ref + "->value, 1); // Length is 1."; } +======= + /** Generate action variables for a reaction. + * @param action The action. + */ + private static String generateActionVariablesInReaction( + Action action, + Reactor r, + CTypes types + ) { + String structType = CGenerator.variableStructType(action, r, false); + // If the action has a type, create variables for accessing the value. + InferredType type = ASTUtils.getInferredType(action); + // Pointer to the lf_token_t sent as the payload in the trigger. + String tokenPointer = "(self->_lf__"+action.getName()+".tmplt.token)"; + CodeBuilder builder = new CodeBuilder(); +>>>>>>> origin public static String generateForwardBody( String outputName, String targetType, String actionName, boolean isTokenType) { @@ -382,6 +680,7 @@ private static void generateVariablesForSendingToContainedReactors( if (definition.getWidthSpec() != null) { // Contained reactor is a bank. builder.pr( +<<<<<<< HEAD String.join( "\n", "for (int bankIndex = 0; bankIndex < self->_lf_" + defWidth + "; bankIndex++) {", @@ -419,6 +718,335 @@ private static void generateVariablesForSendingToContainedReactors( + defName + "[_i]." + inputName +======= + String.join("\n", + "// Expose the action struct as a local variable whose name matches the action name.", + structType+"* "+action.getName()+" = &self->_lf_"+action.getName()+";", + "// Set the fields of the action struct to match the current trigger.", + action.getName()+"->is_present = (bool)self->_lf__"+action.getName()+".status;", + action.getName()+"->has_value = ("+tokenPointer+" != NULL && "+tokenPointer+"->value != NULL);", + "_lf_replace_template_token((token_template_t*)"+action.getName()+", "+tokenPointer+");") + ); + // Set the value field only if there is a type. + if (!type.isUndefined()) { + // The value field will either be a copy (for primitive types) + // or a pointer (for types ending in *). + builder.pr("if ("+action.getName()+"->has_value) {"); + builder.indent(); + if (CUtil.isTokenType(type, types)) { + builder.pr(action.getName()+"->value = ("+types.getTargetType(type)+")"+tokenPointer+"->value;"); + } else { + builder.pr(action.getName()+"->value = *("+types.getTargetType(type)+"*)"+tokenPointer+"->value;"); + } + builder.unindent(); + builder.pr("}"); + } + return builder.toString(); + } + + /** Generate into the specified string builder the code to + * initialize local variables for the specified input port + * in a reaction function from the "self" struct. + * @param input The input statement from the AST. + * @param r The reactor. + */ + private static String generateInputVariablesInReaction( + Input input, + Reactor r, + CTypes types + ) { + String structType = CGenerator.variableStructType(input, r, false); + InferredType inputType = ASTUtils.getInferredType(input); + CodeBuilder builder = new CodeBuilder(); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); + + // Create the local variable whose name matches the input name. + // If the input has not been declared mutable, then this is a pointer + // to the upstream output. Otherwise, it is a copy of the upstream output, + // which nevertheless points to the same token and value (hence, as done + // below, we have to use lf_writable_copy()). There are 8 cases, + // depending on whether the input is mutable, whether it is a multiport, + // and whether it is a token type. + // Easy case first. + if (!input.isMutable() && !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, primitive type. + builder.pr(structType+"* "+inputName+" = self->_lf_"+inputName+";"); + } else if (input.isMutable()&& !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, primitive type. + builder.pr(String.join("\n", + "// Mutable input, so copy the input into a temporary variable.", + "// The input value on the struct is a copy.", + structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", + structType+"* "+inputName+" = &_lf_tmp_"+inputName+";" + )); + } else if (!input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, token type. + builder.pr(String.join("\n", + structType+"* "+inputName+" = self->_lf_"+inputName+";", + "if ("+inputName+"->is_present) {", + " "+inputName+"->length = "+inputName+"->token->length;", + " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", + "} else {", + " "+inputName+"->length = 0;", + "}" + )); + } else if (input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, token type. + builder.pr(String.join("\n", + "// Mutable input, so copy the input struct into a temporary variable.", + structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", + structType+"* "+inputName+" = &_lf_tmp_"+inputName+";", + inputName+"->value = NULL;", // Prevent payload from being freed. + "if ("+inputName+"->is_present) {", + " "+inputName+"->length = "+inputName+"->token->length;", + " "+inputName+"->token = lf_writable_copy((lf_port_base_t*)self->_lf_"+inputName+");", + " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", + "} else {", + " "+inputName+"->length = 0;", + "}" + )); + } else if (!input.isMutable()&& ASTUtils.isMultiport(input)) { + // Non-mutable, multiport, primitive or token type. + builder.pr(structType+"** "+inputName+" = self->_lf_"+inputName+";"); + } else if (CUtil.isTokenType(inputType, types)) { + // Mutable, multiport, token type + builder.pr(String.join("\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", + " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", + " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", + " // If necessary, copy the tokens.", + " if ("+inputName+"[i]->is_present) {", + " "+inputName+"[i]->length = "+inputName+"[i]->token->length;", + " token_template_t* _lf_input = (token_template_t*)self->_lf_"+inputName+"[i];", + " "+inputName+"[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", + " "+inputName+"[i]->value = ("+types.getTargetType(inputType)+")"+inputName+"[i]->token->value;", + " } else {", + " "+inputName+"[i]->length = 0;", + " }", + "}" + )); + } else { + // Mutable, multiport, primitive type + builder.pr(String.join("\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", + " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", + " // Copy the struct, which includes the value.", + " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", + "}" + )); + } + // Set the _width variable for all cases. This will be -1 + // for a variable-width multiport, which is not currently supported. + // It will be -2 if it is not multiport. + builder.pr("int "+inputWidth+" = self->_lf_"+inputWidth+"; SUPPRESS_UNUSED_WARNING("+inputWidth+");"); + return builder.toString(); + } + + /** + * Generate into the specified string builder the code to + * initialize local variables for outputs in a reaction function + * from the "self" struct. + * @param effect The effect declared by the reaction. This must refer to an output. + * @param r The reactor containing the reaction. + */ + public static String generateOutputVariablesInReaction( + VarRef effect, + Reactor r, + ErrorReporter errorReporter, + boolean requiresTypes + ) { + Output output = (Output) effect.getVariable(); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + if (output.getType() == null && requiresTypes) { + errorReporter.reportError(output, "Output is required to have a type: " + outputName); + return ""; + } else { + // The container of the output may be a contained reactor or + // the reactor containing the reaction. + String outputStructType = (effect.getContainer() == null) ? + CGenerator.variableStructType(output, r, false) + : + CGenerator.variableStructType(output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); + if (!ASTUtils.isMultiport(output)) { + // Output port is not a multiport. + return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; + } else { + // Output port is a multiport. + // Set the _width variable. + return String.join("\n", + "int "+outputWidth+" = self->_lf_"+outputWidth+"; SUPPRESS_UNUSED_WARNING("+outputWidth+");", + outputStructType+"** "+outputName+" = self->_lf_"+outputName+"_pointers;" + ); + + } + } + } + + /** + * Generate the fields of the self struct and statements for the constructor + * to create and initialize a reaction_t struct for each reaction in the + * specified reactor and a trigger_t struct for each trigger (input, action, + * timer, or output of a contained reactor). + * @param body The place to put the code for the self struct. + * @param reactor The reactor. + * @param constructorCode The place to put the constructor code. + */ + public static void generateReactionAndTriggerStructs( + CodeBuilder body, + Reactor reactor, + CodeBuilder constructorCode, + CTypes types + ) { + var reactionCount = 0; + // Iterate over reactions and create initialize the reaction_t struct + // on the self struct. Also, collect a map from triggers to the reactions + // that are triggered by that trigger. Also, collect a set of sources + // that are read by reactions but do not trigger reactions. + // Finally, collect a set of triggers and sources that are outputs + // of contained reactors. + var triggerMap = new LinkedHashMap>(); + var sourceSet = new LinkedHashSet(); + var outputsOfContainedReactors = new LinkedHashMap(); + var startupReactions = new LinkedHashSet(); + var shutdownReactions = new LinkedHashSet(); + var resetReactions = new LinkedHashSet(); + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create the reaction_t struct. + body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); + + // Create the map of triggers to reactions. + for (TriggerRef trigger : reaction.getTriggers()) { + // trigger may not be a VarRef (it could be "startup" or "shutdown"). + if (trigger instanceof VarRef) { + var triggerAsVarRef = (VarRef) trigger; + var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); + if (reactionList == null) { + reactionList = new LinkedList<>(); + triggerMap.put(triggerAsVarRef.getVariable(), reactionList); + } + reactionList.add(reactionCount); + if (triggerAsVarRef.getContainer() != null) { + outputsOfContainedReactors.put(triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); + } + } else if (trigger instanceof BuiltinTriggerRef) { + switch(((BuiltinTriggerRef) trigger).getType()) { + case STARTUP: + startupReactions.add(reactionCount); + break; + case SHUTDOWN: + shutdownReactions.add(reactionCount); + break; + case RESET: + resetReactions.add(reactionCount); + break; + } + } + } + // Create the set of sources read but not triggering. + for (VarRef source : reaction.getSources()) { + sourceSet.add(source.getVariable()); + if (source.getContainer() != null) { + outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); + } + } + + var deadlineFunctionPointer = "NULL"; + if (reaction.getDeadline() != null) { + // The following has to match the name chosen in generateReactions + var deadlineFunctionName = generateDeadlineFunctionName(reactor, reactionCount); + deadlineFunctionPointer = "&" + deadlineFunctionName; + } + + // Assign the STP handler + var STPFunctionPointer = "NULL"; + if (reaction.getStp() != null) { + // The following has to match the name chosen in generateReactions + var STPFunctionName = generateStpFunctionName(reactor, reactionCount); + STPFunctionPointer = "&" + STPFunctionName; + } + + // Set the defaults of the reaction_t struct in the constructor. + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__reaction_"+reactionCount+".index = 0; + // self->_lf__reaction_"+reactionCount+".chain_id = 0; + // self->_lf__reaction_"+reactionCount+".pos = 0; + // self->_lf__reaction_"+reactionCount+".status = inactive; + // self->_lf__reaction_"+reactionCount+".deadline = 0LL; + // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; + constructorCode.pr(reaction, String.join("\n", + "self->_lf__reaction_"+reactionCount+".number = "+reactionCount+";", + "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(reactor, reactionCount)+";", + "self->_lf__reaction_"+reactionCount+".self = self;", + "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", + "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", + "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", + (reaction.eContainer() instanceof Mode ? + "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+reactor.getModes().indexOf((Mode) reaction.eContainer())+"];" : + "self->_lf__reaction_"+reactionCount+".mode = NULL;") + )); + // Increment the reactionCount even if the reaction is not in the federate + // so that reaction indices are consistent across federates. + reactionCount++; + } + + // Next, create and initialize the trigger_t objects. + // Start with the timers. + for (Timer timer : ASTUtils.allTimers(reactor)) { + createTriggerT(body, timer, triggerMap, constructorCode, types); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); + constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__"+timer.getName()+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + } + + // Handle builtin triggers. + if (startupReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); + } + // Handle shutdown triggers. + if (shutdownReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); + } + if (resetReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); + } + + // Next handle actions. + for (Action action : ASTUtils.allActions(reactor)) { + createTriggerT(body, action, triggerMap, constructorCode, types); + var isPhysical = "true"; + if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { + isPhysical = "false"; + } + var elementSize = "0"; + // If the action type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) + : null; + if (rootType != null && !rootType.equals("void")) { + elementSize = "sizeof(" + rootType + ")"; + } + + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__"+action.getName()+".is_timer = false; + constructorCode.pr(String.join("\n", + "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", + (!(action.getPolicy() == null || action.getPolicy().isEmpty()) ? + "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" : + ""), + // Need to set the element_size in the trigger_t and the action struct. + "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize +>>>>>>> origin + ";", " " + defName @@ -1276,6 +1904,7 @@ public static String generateReaction( generateStpFunctionHeader(decl, reactionIndex), init, reaction.getStp().getCode())); } +<<<<<<< HEAD // Now generate code for the deadline violation function, if there is one. if (reaction.getDeadline() != null) { code.pr( @@ -1359,6 +1988,142 @@ public static String generateReactionFunctionHeader(ReactorDecl decl, int reacti String functionName = generateReactionFunctionName(decl, reactionIndex); return generateFunctionHeader(functionName); } +======= + /** Generate a reaction function definition for a reactor. + * This function will have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + public static String generateReaction( + Reaction reaction, + Reactor r, + int reactionIndex, + Instantiation mainDef, + ErrorReporter errorReporter, + CTypes types, + TargetConfig targetConfig, + boolean requiresType + ) { + var code = new CodeBuilder(); + var body = ASTUtils.toText(getCode(types, reaction, r)); + String init = generateInitializationForReaction( + body, reaction, ASTUtils.toDefinition(r), reactionIndex, + types, errorReporter, mainDef, + requiresType); + + code.pr( + "#include " + StringUtil.addDoubleQuotes( + CCoreFilesUtils.getCTargetSetHeader())); + + CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(r), code); + code.pr(generateFunction( + generateReactionFunctionHeader(r, reactionIndex), + init, getCode(types, reaction, r) + )); + // Now generate code for the late function, if there is one + // Note that this function can only be defined on reactions + // in federates that have inputs from a logical connection. + if (reaction.getStp() != null) { + code.pr(generateFunction( + generateStpFunctionHeader(r, reactionIndex), + init, reaction.getStp().getCode())); + } + + // Now generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr(generateFunction( + generateDeadlineFunctionHeader(r, reactionIndex), + init, reaction.getDeadline().getCode())); + } + CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(r), code); + code.pr( + "#include " + StringUtil.addDoubleQuotes( + CCoreFilesUtils.getCTargetSetUndefHeader())); + return code.toString(); + } + + private static Code getCode(CTypes types, Reaction r, ReactorDecl container) { + if (r.getCode() != null) return r.getCode(); + Code ret = LfFactory.eINSTANCE.createCode(); + var reactor = ASTUtils.toDefinition(container); + ret.setBody( + CReactorHeaderFileGenerator.nonInlineInitialization(r, reactor) + "\n" + + r.getName() + "( " + CReactorHeaderFileGenerator.reactionArguments(r, reactor) + " );"); + return ret; + } + + public static String generateFunction(String header, String init, Code code) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(code); + function.pr(ASTUtils.toText(code)); + function.unindent(); + function.pr("}"); + return function.toString(); + } + + /** + * Returns the name of the deadline function for reaction. + * @param r The reactor with the deadline + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateDeadlineFunctionName(Reactor r, int reactionIndex) { + return CUtil.getName(r).toLowerCase() + "_deadline_function" + reactionIndex; + } + + /** + * Return the function name for specified reaction of the + * specified reactor. + * @param reactor The reactor + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionName(Reactor reactor, int reactionIndex) { + return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; + } + + /** + * Returns the name of the stp function for reaction. + * @param r The reactor with the stp + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateStpFunctionName(Reactor r, int reactionIndex) { + return CUtil.getName(r).toLowerCase() + "_STP_function" + reactionIndex; + } + + /** Return the top level C function header for the deadline function numbered "reactionIndex" in "r" + * @param r The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the deadline function. + */ + public static String generateDeadlineFunctionHeader(Reactor r, + int reactionIndex) { + String functionName = generateDeadlineFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } + + /** Return the top level C function header for the reaction numbered "reactionIndex" in "r" + * @param r The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionHeader(Reactor r, + int reactionIndex) { + String functionName = generateReactionFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } + + public static String generateStpFunctionHeader(Reactor r, + int reactionIndex) { + String functionName = generateStpFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } +>>>>>>> origin public static String generateStpFunctionHeader(ReactorDecl decl, int reactionIndex) { String functionName = generateStpFunctionName(decl, reactionIndex); diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java new file mode 100644 index 0000000000..68b05f656a --- /dev/null +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -0,0 +1,208 @@ +package org.lflang.generator.c; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.lflang.ASTUtils; +import org.lflang.generator.CodeBuilder; +import org.lflang.lf.Instantiation; +import org.lflang.lf.LfFactory; +import org.lflang.lf.Parameter; +import org.lflang.lf.Reaction; +import org.lflang.lf.Reactor; +import org.lflang.lf.StateVar; +import org.lflang.lf.TriggerRef; +import org.lflang.lf.TypedVariable; +import org.lflang.lf.VarRef; +import org.lflang.util.FileUtil; + +/** Generate user-visible header files. */ +public class CReactorHeaderFileGenerator { + + /** Functional interface for generating auxiliary structs such as port structs. */ + public interface GenerateAuxiliaryStructs { + void generate(CodeBuilder b, Reactor r, boolean userFacing); + } + + /** Return the path to the user-visible header file that would be generated for {@code r}. */ + public static Path outputPath(Reactor r) { + return Path.of(Path.of(r.eResource().getURI().toFileString()) + .getFileName().toString().replaceFirst("[.][^.]+$", "")) + .resolve(r.getName() + ".h"); + } + + /** Generate the user-visible header file for {@code r}. */ + public static void doGenerate(CTypes types, Reactor r, CFileConfig fileConfig, GenerateAuxiliaryStructs generator, Function topLevelPreamble) throws IOException { + String contents = generateHeaderFile(types, r, generator, topLevelPreamble.apply(r)); + FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(r))); + } + private static String generateHeaderFile(CTypes types, Reactor r, GenerateAuxiliaryStructs generator, String topLevelPreamble) { + CodeBuilder builder = new CodeBuilder(); + appendIncludeGuard(builder, r); + builder.pr(topLevelPreamble); + appendPoundIncludes(builder); + appendSelfStruct(builder, types, r); + generator.generate(builder, r, true); + for (Reaction reaction : r.getReactions()) { + appendSignature(builder, reaction, r); + } + builder.pr("#endif"); + return builder.getCode(); + } + + private static void appendIncludeGuard(CodeBuilder builder, Reactor r) { + String macro = CUtil.getName(r) + "_H"; + builder.pr("#ifndef " + macro); + builder.pr("#define " + macro); + } + private static void appendPoundIncludes(CodeBuilder builder) { + builder.pr(""" + #ifdef __cplusplus + extern "C" { + #endif + #include "../include/api/api.h" + #include "../include/api/set.h" + #include "../include/core/reactor.h" + #ifdef __cplusplus + } + #endif + """); + } + + /** The type name of the user-facing version of the self struct. */ + private static String userFacingSelfType(Reactor r) { + return r.getName().toLowerCase() + "_self_t"; + } + + private static void appendSelfStruct(CodeBuilder builder, CTypes types, Reactor r) { + builder.pr("typedef struct " + userFacingSelfType(r) + "{"); + for (Parameter p : r.getParameters()) { + builder.pr(types.getTargetType(p) + " " + p.getName() + ";"); + } + for (StateVar s : r.getStateVars()) { + builder.pr(types.getTargetType(s) + " " + s.getName() + ";"); + } + builder.pr("int end[0]; // placeholder; MSVC does not compile empty structs"); + builder.pr("} " + userFacingSelfType(r) + ";"); + } + + /** Generate the signature of the reaction function of {@code r}. */ + private static void appendSignature(CodeBuilder builder, Reaction r, Reactor reactor) { + if (r.getName() != null) builder.pr("void " + r.getName() + "(" + reactionParameters(r, reactor) + ");"); + } + /** Return a string representation of the parameters of the reaction function of {@code r}. */ + private static String reactionParameters(Reaction r, Reactor reactor) { + return Stream.concat(Stream.of(userFacingSelfType(reactor) + "* self"), portVariableStream(r, reactor) + .map(it -> it.getType(true) + " " + it.getName())) + .collect(Collectors.joining(", ")); + } + + /** Generate initialization code that is needed if {@code r} is not inlined. */ + public static String nonInlineInitialization(Reaction r, Reactor reactor) { + var mainDef = LfFactory.eINSTANCE.createInstantiation(); + mainDef.setName(reactor.getName()); + mainDef.setReactorClass(ASTUtils.findMainReactor(reactor.eResource())); + return portVariableStream(r, reactor) + .map(it -> it.container == null ? "" : it.getWidth() == null ? + String.format("%s %s = (%s) %s;", 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; + } + """, + it.getType(true).replaceFirst("\\*", ""), + it.getAlias(), + CReactionGenerator.maxContainedReactorBankWidth( + reactor.getInstantiations().stream() + .filter(instantiation -> ASTUtils.toDefinition(instantiation.getReactorClass()).equals(it.r)) + .findAny().orElseThrow(), + null, 0, mainDef), + "self->_lf_"+it.container.getName()+"_width", + it.getAlias(), + it.getType(true).replaceFirst("\\*", ""), + it.container.getName(), + it.getName())) + .collect(Collectors.joining("\n")); + } + + /** Return a string representation of the arguments passed to the function for {@code r}. */ + public static String reactionArguments(Reaction r, Reactor reactor) { + return Stream.concat(Stream.of(getApiSelfStruct(reactor)), portVariableStream(r, reactor) + .map(it -> String.format("((%s) %s)", it.getType(true), it.getAlias()))) + .collect(Collectors.joining(", ")); + } + + /** Return code for extracting the user-facing part of the self struct from the self struct. */ + private static String getApiSelfStruct(Reactor reactor) { + return "(" + userFacingSelfType(reactor) + "*) (((char*) self) + sizeof(self_base_t))"; + } + + /** Return a stream of all ports referenced by the signature of {@code r}. */ + private static Stream portVariableStream(Reaction r, Reactor defaultReactorClass) { + return varRefStream(r) + .map(it -> it.getVariable() instanceof TypedVariable tv ? + new PortVariable( + tv, + ASTUtils.toDefinition(it.getContainer() == null ? defaultReactorClass : it.getContainer().getReactorClass()), + it.getContainer()) + : null) + .filter(Objects::nonNull); + } + + /** + * A variable that refers to a port. + * @param tv The variable of the variable reference. + * @param r The reactor that contains the port. + * @param container The {@code Instantiation} referenced in the obtaining of {@code tv}, if + * applicable; {@code null} otherwise. + */ + private record PortVariable(TypedVariable tv, Reactor r, Instantiation container) { + String getType(boolean userFacing) { + var typeName = container == null ? + CGenerator.variableStructType(tv, r, userFacing) + : CPortGenerator.localPortName(container.getReactorClass(), getName()); + var isMultiport = ASTUtils.isMultiport(ASTUtils.allPorts(r).stream() + .filter(it -> it.getName().equals(tv.getName())) + .findAny().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(); + } + } + + private static Stream inputVarRefStream(Reaction reaction) { + return varRefStream(Stream.concat(reaction.getTriggers().stream(), reaction.getSources().stream())); + } + + private static Stream varRefStream(Stream toFilter) { + return toFilter.map(it -> it instanceof VarRef v ? v : null) + .filter(Objects::nonNull); + } + + private static Stream outputVarRefStream(Reaction reaction) { + return reaction.getEffects().stream(); + } + + private static Stream varRefStream(Reaction reaction) { + return Stream.concat(inputVarRefStream(reaction), outputVarRefStream(reaction)); + } +} diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 411a0a464b..69e9ec30ae 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -38,6 +38,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Objects; import java.util.stream.Collectors; +import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.InferredType; @@ -146,11 +147,12 @@ public static String channelIndexName(PortInstance port) { * reactor is main (to allow for instantiations that have the same name as * the main reactor or the .lf file). */ - public static String getName(ReactorDecl reactor) { - if (reactor instanceof Reactor r && r.isMain()) { - return reactor.getName() + "_main"; + public static String getName(Reactor reactor) { + String name = reactor.getName().toLowerCase() + reactor.hashCode(); + if (reactor.isMain()) { + return name + "_main"; } - return reactor.getName(); + return name; } /** @@ -514,16 +516,16 @@ public static String runtimeIndex(ReactorInstance reactor) { * @param reactor The reactor class. * @return The type of a self struct for the specified reactor class. */ - public static String selfType(ReactorDecl reactor) { - if (reactor instanceof Reactor r && r.isMain()) { - return reactor.getName().toLowerCase() + "_main_self_t"; + public static String selfType(Reactor reactor) { + if (reactor.isMain()) { + return "_" + CUtil.getName(reactor) + "_main_self_t"; } - return reactor.getName().toLowerCase() + "_self_t"; + return "_" + CUtil.getName(reactor) + "_self_t"; } /** Construct a unique type for the "self" struct of the class of the given reactor. */ public static String selfType(ReactorInstance instance) { - return selfType(instance.getDefinition().getReactorClass()); + return selfType(ASTUtils.toDefinition(instance.getDefinition().getReactorClass())); } /** diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index 45f6f10b0a..fb4f8605d2 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -100,41 +100,41 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { private fun declareTrigger(reaction: Reaction, trigger: TriggerRef): String = if (trigger is VarRef && trigger.variable is Port) { // if the trigger is a port, then it could be a multiport or contained in a bank - iterateOverAllPortsAndApply(trigger) { port: String -> "${reaction.name}.declare_trigger(&$port);" } + iterateOverAllPortsAndApply(trigger) { port: String -> "${reaction.codeName}.declare_trigger(&$port);" } } else { // treat as single trigger otherwise - "${reaction.name}.declare_trigger(&${trigger.name});" + "${reaction.codeName}.declare_trigger(&${trigger.name});" } private fun declareDependency(reaction: Reaction, dependency: VarRef): String { assert(dependency.variable is Port) // if the trigger is a port, then it could be a multiport or contained in a bank - return iterateOverAllPortsAndApply(dependency) { port: String -> "${reaction.name}.declare_dependency(&$port);" } + return iterateOverAllPortsAndApply(dependency) { port: String -> "${reaction.codeName}.declare_dependency(&$port);" } } private fun declareAntidependency(reaction: Reaction, antidependency: VarRef): String { val variable = antidependency.variable return if (variable is Port) { // if the trigger is a port, then it could be a multiport or contained in a bank - iterateOverAllPortsAndApply(antidependency) { port: String -> "${reaction.name}.declare_antidependency(&$port);" } + iterateOverAllPortsAndApply(antidependency) { port: String -> "${reaction.codeName}.declare_antidependency(&$port);" } } else { // treat as single antidependency otherwise - if (variable is Action) "${reaction.name}.declare_schedulable_action(&${antidependency.name});" - else "${reaction.name}.declare_antidependency(&${antidependency.name});" + if (variable is Action) "${reaction.codeName}.declare_schedulable_action(&${antidependency.name});" + else "${reaction.codeName}.declare_antidependency(&${antidependency.name});" } } private fun setDeadline(reaction: Reaction): String { val delay = reaction.deadline.delay val value = if (delay is ParameterReference) "__lf_inner.${delay.parameter.name}" else delay.toCppTime() - return "${reaction.name}.set_deadline($value, [this]() { ${reaction.name}_deadline_handler(); });" + return "${reaction.codeName}.set_deadline($value, [this]() { ${reaction.codeName}_deadline_handler(); });" } private fun assembleReaction(reaction: Reaction): String { val sources = reaction.sources.filter { it.variable is Port } return with(PrependOperator) { """ - |// ${reaction.name} + |// ${reaction.codeName} ${" |"..reaction.triggers.joinToString(separator = "\n") { declareTrigger(reaction, it) }} ${" |"..sources.joinToString(separator = "\n") { declareDependency(reaction, it) }} ${" |"..reaction.effects.joinToString(separator = "\n") { declareAntidependency(reaction, it) }} diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt index f2386bf96a..2944cd3b67 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt @@ -45,7 +45,7 @@ import org.lflang.lf.WidthSpec */ /** Get the "name" a reaction is represented with in target code.*/ -val Reaction.name +val Reaction.codeName get(): String = "r$indexInContainer" /* ********************************************************************************************** diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt index c1e66f3632..de34478723 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt @@ -67,8 +67,8 @@ class CppReactionGenerator( private fun Reaction.getAllReferencedVariablesForContainer(container: Instantiation) = allVariableReferences.filter { it.container == container }.distinct() - private fun Reaction.getViewClassName(container: Instantiation) = "__lf_view_of_${name}_on_${container.name}_t" - private fun Reaction.getViewInstanceName(container: Instantiation) = "__lf_view_of_${name}_on_${container.name}" + private fun Reaction.getViewClassName(container: Instantiation) = "__lf_view_of_${codeName}_on_${container.name}_t" + private fun Reaction.getViewInstanceName(container: Instantiation) = "__lf_view_of_${codeName}_on_${container.name}" private val VarRef.cppType get() = @@ -102,20 +102,20 @@ class CppReactionGenerator( allUncontainedSources.map { it.name } + allUncontainedEffects.map { it.name } + allReferencedContainers.map { getViewInstanceName(it) } - val body = "void ${name}_body() { __lf_inner.${name}_body(${parameters.joinToString(", ")}); }" + val body = "void ${codeName}_body() { __lf_inner.${codeName}_body(${parameters.joinToString(", ")}); }" val deadlineHandler = - "void ${name}_deadline_handler() { __lf_inner.${name}_deadline_handler(${parameters.joinToString(", ")}); }" + "void ${codeName}_deadline_handler() { __lf_inner.${codeName}_deadline_handler(${parameters.joinToString(", ")}); }" return if (deadline == null) """ $body - reactor::Reaction $name{"$label", $priority, this, [this]() { ${name}_body(); }}; + reactor::Reaction $codeName{"$label", $priority, this, [this]() { ${codeName}_body(); }}; """.trimIndent() else """ $body $deadlineHandler - reactor::Reaction $name{"$label", $priority, this, [this]() { ${name}_body(); }}; + reactor::Reaction $codeName{"$label", $priority, this, [this]() { ${codeName}_body(); }}; """.trimIndent() } } @@ -123,11 +123,11 @@ class CppReactionGenerator( private fun generateFunctionDeclaration(reaction: Reaction, postfix: String): String { val params = reaction.getBodyParameters() return when (params.size) { - 0 -> "void ${reaction.name}_$postfix();" - 1 -> "void ${reaction.name}_$postfix(${params[0]});" + 0 -> "void ${reaction.codeName}_$postfix();" + 1 -> "void ${reaction.codeName}_$postfix(${params[0]});" else -> with(PrependOperator) { """ - |void ${reaction.name}_$postfix( + |void ${reaction.codeName}_$postfix( ${" | "..params.joinToString(",\n")}); """.trimMargin() } @@ -137,11 +137,11 @@ class CppReactionGenerator( private fun getFunctionDefinitionSignature(reaction: Reaction, postfix: String): String { val params = reaction.getBodyParameters() return when (params.size) { - 0 -> "void ${reactor.templateName}::Inner::${reaction.name}_$postfix()" - 1 -> "void ${reactor.templateName}::Inner::${reaction.name}_$postfix(${params[0]})" + 0 -> "void ${reactor.templateName}::Inner::${reaction.codeName}_$postfix()" + 1 -> "void ${reactor.templateName}::Inner::${reaction.codeName}_$postfix(${params[0]})" else -> with(PrependOperator) { """ - |void ${reactor.templateName}::Inner::${reaction.name}_$postfix( + |void ${reactor.templateName}::Inner::${reaction.codeName}_$postfix( ${" | "..params.joinToString(",\n")}) """.trimMargin() } diff --git a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java index f1a095403f..a2a149f522 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java @@ -1,13 +1,13 @@ package org.lflang.generator.python; import org.lflang.lf.Action; -import org.lflang.lf.ReactorDecl; +import org.lflang.lf.Reactor; import org.lflang.generator.c.CGenerator; public class PythonActionGenerator { - public static String generateAliasTypeDef(ReactorDecl decl, Action action, + public static String generateAliasTypeDef(Reactor r, Action action, String genericActionType) { - return "typedef "+genericActionType+" "+CGenerator.variableStructType(action, decl)+";"; + return "typedef "+genericActionType+" "+CGenerator.variableStructType(action, r, false)+";"; } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 442afd79f3..24e1a4f55b 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -34,6 +34,11 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +<<<<<<< HEAD +======= + +import org.eclipse.emf.ecore.EObject; +>>>>>>> origin import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; import org.lflang.ASTUtils; @@ -52,6 +57,7 @@ import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; +import org.lflang.lf.Code; import org.lflang.lf.Input; import org.lflang.lf.Model; import org.lflang.lf.Output; @@ -246,6 +252,7 @@ public String generateDirectives() { code.pr( PythonPreambleGenerator.generateCDefineDirectives( targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); +<<<<<<< HEAD code.pr( PythonPreambleGenerator.generateCIncludeStatements( targetConfig, targetLanguageIsCpp(), hasModalReactors)); @@ -411,6 +418,34 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { } System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); +======= + return code.toString(); + } + + /** + * Override generate top-level preambles, but put the user preambles in the + * .py file rather than the C file. Also handles including the federated + * execution setup preamble specified in the target config. + */ + @Override + protected String generateTopLevelPreambles(Reactor ignored) { + // user preambles + Set models = new LinkedHashSet<>(); + for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { + // The following assumes all reactors have a container. + // This means that generated reactors **have** to be + // added to a resource; not doing so will result in a NPE. + models.add((Model) ASTUtils.toDefinition(r).eContainer()); + } + // Add the main reactor if it is defined + if (this.mainDef != null) { + models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); + } + for (Model m : models) { + pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); + } + return PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors); +>>>>>>> origin } if (errorReporter.getErrorsOccurred()) { @@ -448,6 +483,7 @@ protected void generateReaction(Reaction reaction, ReactorDecl decl, int reactio reaction, decl, reactionIndex, mainDef, errorReporter, types)); } +<<<<<<< HEAD /** * Generate code that initializes the state variables for a given instance. Unlike parameters, * state variables are uniformly initialized for all instances of the same reactor. This task is @@ -537,9 +573,30 @@ protected void generateSelfStructExtension( + ";"); } reactionIndex++; +======= + /** + * Generate the aliases for inputs, outputs, and struct type definitions for + * actions of the specified reactor in the specified federate. + * @param r The parsed reactor data structure. + */ + @Override + public void generateAuxiliaryStructs( + CodeBuilder builder, Reactor r, boolean userFacing + ) { + for (Input input : ASTUtils.allInputs(r)) { + generateAuxiliaryStructsForPort(builder, r, input); + } + for (Output output : ASTUtils.allOutputs(r)) { + generateAuxiliaryStructsForPort(builder, r, output); + } + for (Action action : ASTUtils.allActions(r)) { + generateAuxiliaryStructsForAction(builder, r, action); + } +>>>>>>> origin } } +<<<<<<< HEAD @Override protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { // NOTE: Strangely, a newline is needed at the beginning or indentation @@ -556,20 +613,246 @@ protected void setUpGeneralParameters() { super.setUpGeneralParameters(); if (hasModalReactors) { targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); +======= + private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, + Port port) { + boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); + builder.pr(port, + PythonPortGenerator.generateAliasTypeDef(r, port, isTokenType, + genericPortType)); +>>>>>>> origin } } +<<<<<<< HEAD @Override protected void additionalPostProcessingForModes() { if (!hasModalReactors) { return; +======= + private void generateAuxiliaryStructsForAction(CodeBuilder builder, Reactor r, + Action action) { + builder.pr(action, PythonActionGenerator.generateAliasTypeDef(r, action, genericActionType)); +>>>>>>> origin } PythonModeGenerator.generateResetReactionsIfNeeded(reactors); } +<<<<<<< HEAD private static String setUpMainTarget( boolean hasMain, String executableName, Stream cSources) { return (""" +======= + /** + * Return true if the host operating system is compatible and + * otherwise report an error and return false. + */ + @Override + public boolean isOSCompatible() { + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the + * specified resource. This is the main entry point for code + * generation. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + // Set the threading to false by default, unless the user has + // specifically asked for it. + if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = false; + } + int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; + code.pr(PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors)); + super.doGenerate(resource, new SubContext( + context, + IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, + cGeneratedPercentProgress + )); + + if (errorsOccurred()) { + context.unsuccessfulFinish(); + return; + } + + Map codeMaps = new HashMap<>(); + var lfModuleName = fileConfig.name; + // Don't generate code if there is no main reactor + if (this.main != null) { + try { + Map codeMapsForFederate = generatePythonFiles(lfModuleName, generatePythonModuleName(lfModuleName), generatePythonFileName(lfModuleName)); + codeMaps.putAll(codeMapsForFederate); + copyTargetFiles(); + new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); + if (targetConfig.noCompile) { + System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); + } + } catch (Exception e) { + //noinspection ConstantConditions + throw Exceptions.sneakyThrow(e); + } + + System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); + } + + if (errorReporter.getErrorsOccurred()) { + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, codeMaps); + } + } + + @Override + protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new PythonDockerGenerator(context); + } + + /** Generate a reaction function definition for a reactor. + * This function has a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + @Override + protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + Reactor reactor = ASTUtils.toDefinition(r); + + // Reactions marked with a `@_c_body` attribute are generated in C + if (AttributeUtils.hasCBody(reaction)) { + super.generateReaction(src, reaction, r, reactionIndex); + return; + } + src.pr(PythonReactionGenerator.generateCReaction(reaction, reactor, reactionIndex, mainDef, errorReporter, types)); + } + + /** + * Generate code that initializes the state variables for a given instance. + * Unlike parameters, state variables are uniformly initialized for all + * instances + * of the same reactor. This task is left to Python code to allow for more + * liberal + * state variable assignments. + * + * @param instance The reactor class instance + * @return Initialization code fore state variables of instance + */ + @Override + protected void generateStateVariableInitializations(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate runtime initialization code in C for parameters of a given + * reactor instance + * + * @param instance The reactor instance. + */ + @Override + protected void generateParameterInitialization(ReactorInstance instance) { + // Do nothing + // Parameters are initialized in Python + } + + /** + * Do nothing. + * Methods are generated in Python not C. + * @see PythonMethodGenerator + */ + @Override + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { } + + /** + * Generate C preambles defined by user for a given reactor + * Since the Python generator expects preambles written in C, + * this function is overridden and does nothing. + * + * @param reactor The given reactor + */ + @Override + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + // Do nothing + } + + /** + * Generate code that is executed while the reactor instance is being + * initialized. + * This wraps the reaction functions in a Python function. + * @param instance The reactor instance. + */ + @Override + protected void generateReactorInstanceExtension( + ReactorInstance instance + ) { + initializeTriggerObjects.pr(PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the self struct + * @param selfStructBody The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + @Override + protected void generateSelfStructExtension( + CodeBuilder selfStructBody, + ReactorDecl decl, + CodeBuilder constructorCode + ) { + Reactor reactor = ASTUtils.toDefinition(decl); + // Add the name field + selfStructBody.pr("char *_lf_name;"); + int reactionIndex = 0; + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create a PyObject for each reaction + selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex)+";"); + if (reaction.getStp() != null) { + selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex)+";"); + } + if (reaction.getDeadline() != null) { + selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex)+";"); + } + reactionIndex++; + } + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + // NOTE: Strangely, a newline is needed at the beginning or indentation + // gets swallowed. + return String.join("\n", + "\n# Generated forwarding reaction for connections with the same destination", + "# but located in mutually exclusive modes.", + dest + ".set(" + source + ".value)\n" + ); + } + + @Override + protected void setUpGeneralParameters() { + super.setUpGeneralParameters(); + if (hasModalReactors) { + targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); + } + } + + @Override + protected void additionalPostProcessingForModes() { + if (!hasModalReactors) { + return; + } + PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + } + + private static String setUpMainTarget(boolean hasMain, String executableName, Stream cSources) { + return ( + """ +>>>>>>> origin set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(_LF_GARBAGE_COLLECTED) add_subdirectory(core) diff --git a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java index 2c7512b499..9e0919b52c 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java @@ -5,6 +5,7 @@ import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.Action; +import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; import java.util.List; @@ -194,8 +195,8 @@ public static String generatePythonListForContainedBank(String reactorName, Port ); } - public static String generateAliasTypeDef(ReactorDecl decl, Port port, boolean isTokenType, String genericPortType) { - return "typedef "+genericPortType+" "+CGenerator.variableStructType(port, decl)+";"; + public static String generateAliasTypeDef(Reactor r, Port port, boolean isTokenType, String genericPortType) { + return "typedef "+genericPortType+" "+CGenerator.variableStructType(port, r, false)+";"; } private static String generateConvertCPortToPy(String port) { diff --git a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java index 5fa8aff84f..e2fd7af86a 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java @@ -55,7 +55,7 @@ public static String generateCIncludeStatements( code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); code.pr("#include \"pythontarget.h\""); if (hasModalReactors) { - code.pr("#include \"modal_models/definitions.h\""); + code.pr("#include \"include/modal_models/definitions.h\""); } return code.toString(); } diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 77f7352f08..bcc1beeaed 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -34,49 +34,46 @@ public class PythonReactionGenerator { /** - * Generate code to call reaction numbered "reactionIndex" in reactor "decl". - * @param decl The reactor containing the reaction + * Generate code to call reaction numbered "reactionIndex" in reactor "reactor". + * @param reactor The reactor containing the reaction * @param reactionIndex The index of the reaction - * @param pyObjectDescriptor CPython related descriptors for each object in "pyObjects". * @param pyObjects CPython related objects */ - public static String generateCPythonReactionCaller(ReactorDecl decl, + public static String generateCPythonReactionCaller(Reactor reactor, int reactionIndex, List pyObjects, String inits) { String pythonFunctionName = generatePythonReactionFunctionName(reactionIndex); String cpythonFunctionName = generateCPythonReactionFunctionName(reactionIndex); - return generateCPythonFunctionCaller(decl.getName(), pythonFunctionName, cpythonFunctionName, pyObjects, inits); + return generateCPythonFunctionCaller(CUtil.getName(reactor), pythonFunctionName, cpythonFunctionName, pyObjects, inits); } /** - * Generate code to call deadline function numbered "reactionIndex" in reactor "decl". - * @param decl The reactor containing the reaction + * Generate code to call deadline function numbered "reactionIndex" in reactor "r". + * @param r The reactor containing the reaction * @param reactionIndex The index of the reaction - * @param pyObjectDescriptor CPython related descriptors for each object in "pyObjects". * @param pyObjects CPython related objects */ - public static String generateCPythonDeadlineCaller(ReactorDecl decl, + public static String generateCPythonDeadlineCaller(Reactor r, int reactionIndex, List pyObjects) { String pythonFunctionName = generatePythonDeadlineFunctionName(reactionIndex); String cpythonFunctionName = generateCPythonDeadlineFunctionName(reactionIndex); - return generateCPythonFunctionCaller(decl.getName(), pythonFunctionName, cpythonFunctionName, pyObjects, ""); + return generateCPythonFunctionCaller(CUtil.getName(r), pythonFunctionName, cpythonFunctionName, pyObjects, ""); } /** - * Generate code to call deadline function numbered "reactionIndex" in reactor "decl". - * @param decl The reactor containing the reaction + * Generate code to call deadline function numbered "reactionIndex" in reactor "r". + * @param r The reactor containing the reaction * @param reactionIndex The index of the reaction - * @param pyObjectDescriptor CPython related descriptors for each object in "pyObjects". * @param pyObjects CPython related objects */ - public static String generateCPythonSTPCaller(ReactorDecl decl, + public static String generateCPythonSTPCaller(Reactor r, int reactionIndex, List pyObjects) { String pythonFunctionName = generatePythonSTPFunctionName(reactionIndex); String cpythonFunctionName = generateCPythonSTPFunctionName(reactionIndex); - return generateCPythonFunctionCaller(decl.getName(), pythonFunctionName, cpythonFunctionName, pyObjects, ""); + return generateCPythonFunctionCaller(CUtil.getName(r), pythonFunctionName, cpythonFunctionName, pyObjects, ""); } /** @@ -122,7 +119,7 @@ private static String generateCPythonFunctionCaller(String reactorDeclName, * Generate the reaction in the .c file, which calls the Python reaction through the CPython interface. * * @param reaction The reaction to generate Python-specific initialization for. - * @param decl The reactor to which reaction belongs to. + * @param r The reactor to which reaction belongs to. * @param reactionIndex The index number of the reaction in decl. * @param mainDef The main reactor. * @param errorReporter An error reporter. @@ -130,7 +127,7 @@ private static String generateCPythonFunctionCaller(String reactorDeclName, */ public static String generateCReaction( Reaction reaction, - ReactorDecl decl, + Reactor r, int reactionIndex, Instantiation mainDef, ErrorReporter errorReporter, @@ -140,34 +137,34 @@ public static String generateCReaction( // Each input must be cast to (PyObject *) (aka their descriptors for Py_BuildValue are "O") List pyObjects = new ArrayList<>(); CodeBuilder code = new CodeBuilder(); - String cPyInit = generateCPythonInitializers(reaction, decl, pyObjects, errorReporter); + String cPyInit = generateCPythonInitializers(reaction, r, pyObjects, errorReporter); String cInit = CReactionGenerator.generateInitializationForReaction( - "", reaction, decl, reactionIndex, + "", reaction, r, reactionIndex, types, errorReporter, mainDef, Target.Python.requiresTypes); code.pr( "#include " + StringUtil.addDoubleQuotes( CCoreFilesUtils.getCTargetSetHeader())); code.pr(generateFunction( - CReactionGenerator.generateReactionFunctionHeader(decl, reactionIndex), + CReactionGenerator.generateReactionFunctionHeader(r, reactionIndex), cInit, reaction.getCode(), - generateCPythonReactionCaller(decl, reactionIndex, pyObjects, cPyInit) + generateCPythonReactionCaller(r, reactionIndex, pyObjects, cPyInit) )); // Generate code for the STP violation handler, if there is one. if (reaction.getStp() != null) { code.pr(generateFunction( - CReactionGenerator.generateStpFunctionHeader(decl, reactionIndex), + CReactionGenerator.generateStpFunctionHeader(r, reactionIndex), cInit, reaction.getStp().getCode(), - generateCPythonSTPCaller(decl, reactionIndex, pyObjects) + generateCPythonSTPCaller(r, reactionIndex, pyObjects) )); } // Generate code for the deadline violation function, if there is one. if (reaction.getDeadline() != null) { code.pr(generateFunction( - CReactionGenerator.generateDeadlineFunctionHeader(decl, reactionIndex), + CReactionGenerator.generateDeadlineFunctionHeader(r, reactionIndex), cInit, reaction.getDeadline().getCode(), - generateCPythonDeadlineCaller(decl, reactionIndex, pyObjects) + generateCPythonDeadlineCaller(r, reactionIndex, pyObjects) )); } code.pr( diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java index 5778791f76..fd954ca956 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java @@ -34,7 +34,7 @@ public static String generatePythonClass(ReactorInstance instance, CodeBuilder pythonClasses = new CodeBuilder(); ReactorDecl decl = instance.getDefinition().getReactorClass(); Reactor reactor = ASTUtils.toDefinition(decl); - String className = PyUtil.getName(decl); + String className = PyUtil.getName(reactor); if (instantiatedClasses == null) { return ""; } @@ -113,7 +113,7 @@ public static String generatePythonClassInstantiations(ReactorInstance instance, ReactorInstance main) { CodeBuilder code = new CodeBuilder(); - String className = PyUtil.getName(instance.reactorDeclaration); + String className = PyUtil.getName(instance.reactorDefinition); if (instance.getWidth() > 0) { // For each reactor instance, create a list regardless of whether it is a bank or not. diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 61fa3d8816..d4d34c7b08 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -455,15 +455,20 @@ public static boolean isCFile(Path path) { * @param dir The folder to search for includes to change. * @throws IOException If the given set of files cannot be relativized. */ - public static void relativeIncludeHelper(Path dir) throws IOException { + public static void relativeIncludeHelper(Path dir, Path includePath) throws IOException { System.out.println("Relativizing all includes in " + dir.toString()); - List allPaths = Files.walk(dir) + List includePaths = Files.walk(includePath) + .filter(Files::isRegularFile) + .filter(FileUtil::isCFile) + .sorted(Comparator.reverseOrder()) + .collect(Collectors.toList()); + List srcPaths = Files.walk(dir) .filter(Files::isRegularFile) .filter(FileUtil::isCFile) .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); Map fileStringToFilePath = new HashMap(); - for (Path path : allPaths) { + for (Path path : includePaths) { String fileName = path.getFileName().toString(); if (path.getFileName().toString().contains("CMakeLists.txt")) continue; if (fileStringToFilePath.put(fileName, path) != null) { @@ -471,7 +476,7 @@ public static void relativeIncludeHelper(Path dir) throws IOException { } } Pattern regexExpression = Pattern.compile("#include\s+[\"]([^\"]+)*[\"]"); - for (Path path : allPaths) { + for (Path path : srcPaths) { String fileName = path.getFileName().toString(); String fileContents = Files.readString(path); Matcher matcher = regexExpression.matcher(fileContents); diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 2d0d4f332b..928466da91 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -196,6 +196,7 @@ public void checkBracedExpression(BracedListExpression expr) { @Check(CheckType.FAST) public void checkAssignment(Assignment assignment) { +<<<<<<< HEAD // If the left-hand side is a time parameter, make sure the assignment has units typeCheck( assignment.getRhs(), @@ -209,6 +210,171 @@ public void checkAssignment(Assignment assignment) { + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", Literals.ASSIGNMENT__RHS); +======= + // Report if connection is part of a cycle. + Set> cycles = this.info.topologyCycles(); + for (VarRef lp : connection.getLeftPorts()) { + for (VarRef rp : connection.getRightPorts()) { + boolean leftInCycle = false; + + for (NamedInstance it : cycles) { + if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) + || (it.getDefinition().equals(lp.getVariable()) && it.getParent().equals(lp.getContainer()))) { + leftInCycle = true; + break; + } + } + + for (NamedInstance it : cycles) { + if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) + || (it.getDefinition().equals(rp.getVariable()) && it.getParent().equals(rp.getContainer()))) { + if (leftInCycle) { + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + String reactorName = reactor.getName(); + error(String.format("Connection in reactor %s creates", reactorName) + + String.format("a cyclic dependency between %s and %s.", toOriginalText(lp), toOriginalText(rp)), + Literals.CONNECTION__DELAY); + } + } + } + } + } + + // FIXME: look up all ReactorInstance objects that have a definition equal to the + // container of this connection. For each of those occurrences, the widths have to match. + // For the C target, since C has such a weak type system, check that + // the types on both sides of every connection match. For other languages, + // we leave type compatibility that language's compiler or interpreter. + if (isCBasedTarget()) { + Type type = (Type) null; + for (VarRef port : connection.getLeftPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + // Unfortunately, xtext does not generate a suitable equals() + // method for AST types, so we have to manually check the types. + if (!sameType(type, ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); + } + } + } + } + for (VarRef port : connection.getRightPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + if (!sameType(type, type = ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } + } + + // Check whether the total width of the left side of the connection + // matches the total width of the right side. This cannot be determined + // here if the width is not given as a constant. In that case, it is up + // to the code generator to check it. + int leftWidth = 0; + for (VarRef port : connection.getLeftPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || leftWidth < 0) { + // Cannot determine the width of the left ports. + leftWidth = -1; + } else { + leftWidth += width; + } + } + int rightWidth = 0; + for (VarRef port : connection.getRightPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || rightWidth < 0) { + // Cannot determine the width of the left ports. + rightWidth = -1; + } else { + rightWidth += width; + } + } + + if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { + if (connection.isIterated()) { + if (leftWidth == 0 || rightWidth % leftWidth != 0) { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning(String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS + ); + } + } else { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning(String.format("Left width %s does not match right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS + ); + } + } + + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + + // Make sure the right port is not already an effect of a reaction. + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + for (VarRef effect : reaction.getEffects()) { + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort.getVariable().equals(effect.getVariable()) && // Refers to the same variable + rightPort.getContainer() == effect.getContainer() && // Refers to the same instance + ( reaction.eContainer() instanceof Reactor || // Either is not part of a mode + connection.eContainer() instanceof Reactor || + connection.eContainer() == reaction.eContainer() // Or they are in the same mode + )) { + error("Cannot connect: Port named '" + effect.getVariable().getName() + + "' is already effect of a reaction.", + Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } + + // Check that the right port does not already have some other + // upstream connection. + for (Connection c : reactor.getConnections()) { + if (c != connection) { + for (VarRef thisRightPort : connection.getRightPorts()) { + for (VarRef thatRightPort : c.getRightPorts()) { + if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) && // Refers to the same variable + thisRightPort.getContainer() == thatRightPort.getContainer() && // Refers to the same instance + ( connection.eContainer() instanceof Reactor || // Or either of the connections in not part of a mode + c.eContainer() instanceof Reactor || + connection.eContainer() == c.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + thisRightPort.getVariable().getName() + + "' may only appear once on the right side of a connection.", + Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } + } + + // Check the after delay + if (connection.getDelay() != null) { + final var delay = connection.getDelay(); + if (delay instanceof ParameterReference || delay instanceof Time || delay instanceof Literal) { + checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); + } else { + error("After delays can only be given by time literals or parameters.", + Literals.CONNECTION__DELAY); + } + } +>>>>>>> origin } } @@ -221,6 +387,348 @@ public void checkConnection(Connection connection) { for (VarRef rp : connection.getRightPorts()) { boolean leftInCycle = false; +<<<<<<< HEAD +======= + @Check + public void checkImport(Import imp) { + if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { + error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. + return; + } + + // FIXME: report error if resource cannot be resolved. + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (!isUnused(reactor)) { + return; + } + } + warning("Unused import.", Literals.IMPORT__IMPORT_URI); + } + + @Check + public void checkImportedReactor(ImportedReactor reactor) { + if (isUnused(reactor)) { + warning("Unused reactor class.", + Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } + + if (info.instantiationGraph.hasCycles()) { + Set cycleSet = new HashSet<>(); + for (Set cycle : info.instantiationGraph.getCycles()) { + cycleSet.addAll(cycle); + } + if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { + error("Imported reactor '" + toDefinition(reactor).getName() + + "' has cyclic instantiation in it.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } + } + } + + @Check(CheckType.FAST) + public void checkInput(Input input) { + Reactor parent = (Reactor)input.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); + } + checkName(input.getName(), Literals.VARIABLE__NAME); + if (target.requiresTypes) { + if (input.getType() == null) { + error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); + } + } + + // mutable has no meaning in C++ + if (input.isMutable() && this.target == Target.CPP) { + warning( + "The mutable qualifier has no meaning for the C++ target and should be removed. " + + "In C++, any value can be made mutable by calling get_mutable_copy().", + Literals.INPUT__MUTABLE + ); + } + + // Variable width multiports are not supported (yet?). + if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } + + @Check(CheckType.FAST) + public void checkInstantiation(Instantiation instantiation) { + checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); + Reactor reactor = toDefinition(instantiation.getReactorClass()); + if (reactor.isMain() || reactor.isFederated()) { + error( + "Cannot instantiate a main (or federated) reactor: " + + instantiation.getReactorClass().getName(), + Literals.INSTANTIATION__REACTOR_CLASS + ); + } + + // Report error if this instantiation is part of a cycle. + // FIXME: improve error message. + // FIXME: Also report if there exists a cycle within. + if (this.info.instantiationGraph.getCycles().size() > 0) { + for (Set cycle : this.info.instantiationGraph.getCycles()) { + Reactor container = (Reactor) instantiation.eContainer(); + if (cycle.contains(container) && cycle.contains(reactor)) { + List names = new ArrayList<>(); + for (Reactor r : cycle) { + names.add(r.getName()); + } + + error( + "Instantiation is part of a cycle: " + String.join(", ", names) + ".", + Literals.INSTANTIATION__REACTOR_CLASS + ); + } + } + } + // Variable width multiports are not supported (yet?). + if (instantiation.getWidthSpec() != null + && instantiation.getWidthSpec().isOfVariableLength() + ) { + if (isCBasedTarget()) { + warning("Variable-width banks are for internal use only.", + Literals.INSTANTIATION__WIDTH_SPEC + ); + } else { + error("Variable-width banks are not supported.", + Literals.INSTANTIATION__WIDTH_SPEC + ); + } + } + } + + /** Check target parameters, which are key-value pairs. */ + @Check(CheckType.FAST) + public void checkKeyValuePair(KeyValuePair param) { + // Check only if the container's container is a Target. + if (param.eContainer().eContainer() instanceof TargetDecl) { + TargetProperty prop = TargetProperty.forName(param.getName()); + + // Make sure the key is valid. + if (prop == null) { + String options = TargetProperty.getOptions().stream() + .map(p -> p.description).sorted() + .collect(Collectors.joining(", ")); + warning( + "Unrecognized target parameter: " + param.getName() + + ". Recognized parameters are: " + options, + Literals.KEY_VALUE_PAIR__NAME); + } else { + // Check whether the property is supported by the target. + if (!prop.supportedBy.contains(this.target)) { + warning( + "The target parameter: " + param.getName() + + " is not supported by the " + this.target + + " target and will thus be ignored.", + Literals.KEY_VALUE_PAIR__NAME); + } + + // Report problem with the assigned value. + prop.type.check(param.getValue(), param.getName(), this); + } + + for (String it : targetPropertyErrors) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyErrors.clear(); + + for (String it : targetPropertyWarnings) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyWarnings.clear(); + } + } + + @Check(CheckType.FAST) + public void checkModel(Model model) { + // Since we're doing a fast check, we only want to update + // if the model info hasn't been initialized yet. If it has, + // we use the old information and update it during a normal + // check (see below). + if (!info.updated) { + info.update(model, errorReporter); + } + } + + @Check(CheckType.NORMAL) + public void updateModelInfo(Model model) { + info.update(model, errorReporter); + } + + @Check(CheckType.FAST) + public void checkOutput(Output output) { + Reactor parent = (Reactor)output.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); + } + checkName(output.getName(), Literals.VARIABLE__NAME); + if (this.target.requiresTypes) { + if (output.getType() == null) { + error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); + } + } + + // Variable width multiports are not supported (yet?). + if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } + + @Check(CheckType.FAST) + public void checkParameter(Parameter param) { + checkName(param.getName(), Literals.PARAMETER__NAME); + + if (param.getInit() == null) { + // todo make initialization non-mandatory + // https://github.com/lf-lang/lingua-franca/issues/623 + error("Parameter must have a default value.", Literals.PARAMETER__INIT); + return; + } + + if (this.target.requiresTypes) { + // Report missing target type. param.inferredType.undefine + if (ASTUtils.getInferredType(param).isUndefined()) { + error("Type declaration missing.", Literals.PARAMETER__TYPE); + } + } + + if (param.getType() != null) { + typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); + } + + if (param.getInit() != null) { + for (Expression expr : param.getInit().getExprs()) { + if (expr instanceof ParameterReference) { + // Initialization using parameters is forbidden. + error("Parameter cannot be initialized using parameter.", + Literals.PARAMETER__INIT); + } + } + } + + if (this.target == Target.CPP) { + EObject container = param.eContainer(); + Reactor reactor = (Reactor) container; + if (reactor.isMain()) { + // we need to check for the cli parameters that are always taken + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); + if (cliParams.contains(param.getName())) { + error("Parameter '" + param.getName() + + "' is already in use as command line argument by Lingua Franca,", + Literals.PARAMETER__NAME); + } + } + } + + if (isCBasedTarget() && + this.info.overflowingParameters.contains(param)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.PARAMETER__INIT); + } + + } + + @Check(CheckType.FAST) + public void checkPreamble(Preamble preamble) { + if (this.target == Target.CPP) { + if (preamble.getVisibility() == Visibility.NONE) { + error( + "Preambles for the C++ target need a visibility qualifier (private or public)!", + Literals.PREAMBLE__VISIBILITY + ); + } else if (preamble.getVisibility() == Visibility.PRIVATE) { + EObject container = preamble.eContainer(); + if (container != null && container instanceof Reactor) { + Reactor reactor = (Reactor) container; + if (isGeneric(reactor)) { + warning( + "Private preambles in generic reactors are not truly private. " + + "Since the generated code is placed in a *_impl.hh file, it will " + + "be visible on the public interface. Consider using a public " + + "preamble within the reactor or a private preamble on file scope.", + Literals.PREAMBLE__VISIBILITY); + } + } + } + } else if (preamble.getVisibility() != Visibility.NONE) { + warning( + String.format("The %s qualifier has no meaning for the %s target. It should be removed.", + preamble.getVisibility(), this.target.name()), + Literals.PREAMBLE__VISIBILITY + ); + } + } + + @Check(CheckType.FAST) + public void checkReaction(Reaction reaction) { + + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); + } + HashSet triggers = new HashSet<>(); + // Make sure input triggers have no container and output sources do. + for (TriggerRef trigger : reaction.getTriggers()) { + if (trigger instanceof VarRef) { + VarRef triggerVarRef = (VarRef) trigger; + triggers.add(triggerVarRef.getVariable()); + if (triggerVarRef instanceof Input) { + if (triggerVarRef.getContainer() != null) { + error(String.format("Cannot have an input of a contained reactor as a trigger: %s.%s", triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } else if (triggerVarRef.getVariable() instanceof Output) { + if (triggerVarRef.getContainer() == null) { + error(String.format("Cannot have an output of this reactor as a trigger: %s", triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } + } + } + + // Make sure input sources have no container and output sources do. + // Also check that a source is not already listed as a trigger. + for (VarRef source : reaction.getSources()) { + if (triggers.contains(source.getVariable())) { + error(String.format("Source is already listed as a trigger: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + if (source.getVariable() instanceof Input) { + if (source.getContainer() != null) { + error(String.format("Cannot have an input of a contained reactor as a source: %s.%s", source.getContainer().getName(), source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } else if (source.getVariable() instanceof Output) { + if (source.getContainer() == null) { + error(String.format("Cannot have an output of this reactor as a source: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } + } + + // Make sure output effects have no container and input effects do. + for (VarRef effect : reaction.getEffects()) { + if (effect.getVariable() instanceof Input) { + if (effect.getContainer() == null) { + error(String.format("Cannot have an input of this reactor as an effect: %s", effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } else if (effect.getVariable() instanceof Output) { + if (effect.getContainer() != null) { + error(String.format("Cannot have an output of a contained reactor as an effect: %s.%s", effect.getContainer().getName(), effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } + } + + // // Report error if this reaction is part of a cycle. + Set> cycles = this.info.topologyCycles(); + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + boolean reactionInCycle = false; +>>>>>>> origin for (NamedInstance it : cycles) { if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) || (it.getDefinition().equals(lp.getVariable()) @@ -927,12 +1435,33 @@ public void checkReactor(Reactor reactor) throws IOException { } } +<<<<<<< HEAD // Check for illegal names. checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); // C++ reactors may not be called 'preamble' if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { error("Reactor cannot be named '" + reactor.getName() + "'", Literals.REACTOR_DECL__NAME); +======= + /** + * Check if the requested serialization is supported. + */ + @Check(CheckType.FAST) + public void checkSerializer(Serializer serializer) { + boolean isValidSerializer = false; + for (SupportedSerializers method : SupportedSerializers.values()) { + if (method.name().equalsIgnoreCase(serializer.getType())){ + isValidSerializer = true; + } + } + + if (!isValidSerializer) { + error( + "Serializer can be " + Arrays.asList(SupportedSerializers.values()), + Literals.SERIALIZER__TYPE + ); + } +>>>>>>> origin } if (reactor.getHost() != null) { @@ -1248,6 +1777,7 @@ public void checkAttributes(Attribute attr) { spec.check(this, attr); } +<<<<<<< HEAD @Check(CheckType.FAST) public void checkWidthSpec(WidthSpec widthSpec) { if (!this.target.supportsMultiports()) { @@ -1272,6 +1802,75 @@ public void checkWidthSpec(WidthSpec widthSpec) { } } else if (term.getWidth() < 0) { error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); +======= + /** + * Check whether an attribute is supported + * and the validity of the attribute. + * + * @param attr The attribute being checked + */ + @Check(CheckType.FAST) + public void checkAttributes(Attribute attr) { + String name = attr.getAttrName().toString(); + AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); + if (spec == null) { + error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); + return; + } + // Check the validity of the attribute. + spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkWidthSpec(WidthSpec widthSpec) { + if (!this.target.supportsMultiports()) { + error("Multiports and banks are currently not supported by the given target.", + Literals.WIDTH_SPEC__TERMS); + } else { + for (WidthTerm term : widthSpec.getTerms()) { + if (term.getParameter() != null) { + if (!this.target.supportsParameterizedWidths()) { + error("Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getPort() != null) { + // Widths given with `widthof()` are not supported (yet?). + // This feature is currently only used for after delays. + error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); + } else if (term.getCode() != null) { + if (this.target != Target.CPP) { + error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getWidth() < 0) { + error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); + } + } + } + } + + @Check(CheckType.FAST) + public void checkReactorIconAttribute(Reactor reactor) { + var path = AttributeUtils.getIconPath(reactor); + if (path != null) { + var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); + // Check file extension + var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); + var extensionStrart = path.lastIndexOf("."); + var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; + if (!validExtensions.contains(extension.toLowerCase())) { + warning("File extension '" + extension + "' is not supported. Provide any of: " + String.join(", ", validExtensions), + param, Literals.ATTR_PARM__VALUE); + return; + } + + // Check file location + var iconLocation = FileUtil.locateFile(path, reactor.eResource()); + if (iconLocation == null) { + warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); + } + if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) && !(new File(iconLocation.getPath()).exists())) { + warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); + } +>>>>>>> origin } } } @@ -1666,6 +2265,7 @@ private void checkName(String name, EStructuralFeature feature) { error(RESERVED_MESSAGE + name, feature); } +<<<<<<< HEAD if (this.target == Target.TS) { // "actions" is a reserved word within a TS reaction if (name.equals("actions")) { @@ -1681,6 +2281,79 @@ private void checkName(String name, EStructuralFeature feature) { public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { if (init == null) { return; +======= + @Check(CheckType.FAST) + public void checkMissingStateResetInMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var resetModes = new HashSet(); + // Collect all modes that may be reset + for (var m : reactor.getModes()) { + for (var r : m.getReactions()) { + for (var e : r.getEffects()) { + if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { + resetModes.add((Mode) e.getVariable()); + } + } + } + } + for (var m : resetModes) { + // Check state variables in this mode + if (!m.getStateVars().isEmpty()) { + var hasResetReaction = m.getReactions().stream().anyMatch( + r -> r.getTriggers().stream().anyMatch( + t -> (t instanceof BuiltinTriggerRef && + ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + for (var s : m.getStateVars()) { + if (!s.isReset()) { + error("State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction.", + m, Literals.MODE__STATE_VARS, m.getStateVars().indexOf(s)); + } + } + } + } + // Check state variables in instantiated reactors + if (!m.getInstantiations().isEmpty()) { + for (var i : m.getInstantiations()) { + var error = new LinkedHashSet(); + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty()) { + var check = toCheck.pop(); + checked.add(check); + if (!check.getStateVars().isEmpty()) { + var hasResetReaction = check.getReactions().stream().anyMatch( + r -> r.getTriggers().stream().anyMatch( + t -> (t instanceof BuiltinTriggerRef && + ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + // Add state vars that are not self-resetting to the error + check.getStateVars().stream().filter(s -> !s.isReset()).forEachOrdered(error::add); + } + } + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } + } + } + if (!error.isEmpty()) { + error("This reactor contains state variables that are not reset upon mode entry: " + + error.stream().map(e -> e.getName() + " in " + + ASTUtils.getEnclosingReactor(e).getName()).collect(Collectors.joining(", ")) + + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " + + "It is unsafe to instantiate this reactor inside a mode entered with reset.", + m, Literals.MODE__INSTANTIATIONS, + m.getInstantiations().indexOf(i)); + } + } + } + } + } +>>>>>>> origin } // TODO: @@ -1713,6 +2386,7 @@ private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) return; } +<<<<<<< HEAD if (init.getExprs().size() != 1) { error("Expected exactly one time value.", feature); } else { @@ -1723,6 +2397,58 @@ private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { if (value == null || value instanceof Time) { return; +======= + @Check(CheckType.FAST) + public void checkUnspecifiedTransitionType(Reaction reaction) { + for (var effect : reaction.getEffects()) { + var variable = effect.getVariable(); + if (variable instanceof Mode) { + // The transition type is always set to default by Xtext. + // Hence, check if there is an explicit node for the transition type in the AST. + var transitionAssignment = NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); + if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. + var mode = (Mode) variable; + // Check if reset or history transition would make a difference. + var makesDifference = !mode.getStateVars().isEmpty() + || !mode.getTimers().isEmpty() + || !mode.getActions().isEmpty() + || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); + if (!makesDifference && !mode.getInstantiations().isEmpty()) { + // Also check instantiated reactors + for (var i : mode.getInstantiations()) { + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty() && !makesDifference) { + var check = toCheck.pop(); + checked.add(check); + + makesDifference |= !check.getModes().isEmpty() + || !ASTUtils.allStateVars(check).isEmpty() + || !ASTUtils.allTimers(check).isEmpty() + || !ASTUtils.allActions(check).isEmpty() + || ASTUtils.allConnections(check).stream().anyMatch(c -> c.getDelay() != null); + + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } + } + } + } + } + if (makesDifference) { + warning("You should specify a transition type! " + + "Reset and history transitions have different effects on this target mode. " + + "Currently, a reset type is implicitly assumed.", + reaction, Literals.REACTION__EFFECTS, reaction.getEffects().indexOf(effect)); + } + } + } + } +>>>>>>> origin } if (value instanceof ParameterReference) { @@ -1953,5 +2679,223 @@ private boolean sameType(Type type1, Type type2) { "Names of objects (inputs, outputs, actions, timers, parameters, " + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; +<<<<<<< HEAD private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; +======= + if (ASTUtils.isInteger(((Literal) value).getLiteral())) { + error("Missing time unit.", feature); + return; + } + // fallthrough + } + + error("Invalid time value.", feature); + } + + /** + * Return the number of main or federated reactors declared. + * + * @param iter An iterator over all objects in the resource. + */ + private int countMainOrFederated(TreeIterator iter) { + int nMain = 0; + while (iter.hasNext()) { + EObject obj = iter.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor r = (Reactor) obj; + if (r.isMain() || r.isFederated()) { + nMain++; + } + } + return nMain; + } + + /** + * Report whether a given reactor has dependencies on a cyclic + * instantiation pattern. This means the reactor has an instantiation + * in it -- directly or in one of its contained reactors -- that is + * self-referential. + * @param reactor The reactor definition to find out whether it has any + * dependencies on cyclic instantiations. + * @param cycleSet The set of all reactors that are part of an + * instantiation cycle. + * @param visited The set of nodes already visited in this graph traversal. + */ + private boolean dependsOnCycle( + Reactor reactor, Set cycleSet, Set visited + ) { + Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); + if (visited.contains(reactor)) { + return false; + } else { + visited.add(reactor); + for (Reactor it : origins) { + if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { + // Reached a cycle. + return true; + } + } + } + return false; + } + + /** + * Report whether the name of the given element matches any variable in + * the ones to check against. + * @param element The element to compare against all variables in the given iterable. + * @param toCheckAgainst Iterable variables to compare the given element against. + */ + private boolean hasNameConflict(Variable element, + Iterable toCheckAgainst) { + int numNameConflicts = 0; + for (Variable it : toCheckAgainst) { + if (it.getName().equals(element.getName())) { + numNameConflicts++; + } + } + return numNameConflicts > 0; + } + + /** + * Return true if target is C or a C-based target like CCpp. + */ + private boolean isCBasedTarget() { + return (this.target == Target.C || this.target == Target.CCPP); + } + + /** + * Report whether a given imported reactor is used in this resource or not. + * @param reactor The imported reactor to check whether it is used. + */ + private boolean isUnused(ImportedReactor reactor) { + TreeIterator instantiations = reactor.eResource().getAllContents(); + TreeIterator subclasses = reactor.eResource().getAllContents(); + + boolean instantiationsCheck = true; + while (instantiations.hasNext() && instantiationsCheck) { + EObject obj = instantiations.next(); + if (!(obj instanceof Instantiation)) { + continue; + } + Instantiation inst = (Instantiation) obj; + instantiationsCheck &= (inst.getReactorClass() != reactor && inst.getReactorClass() != reactor.getReactorClass()); + } + + boolean subclassesCheck = true; + while (subclasses.hasNext() && subclassesCheck) { + EObject obj = subclasses.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor subclass = (Reactor) obj; + for (ReactorDecl decl : subclass.getSuperClasses()) { + subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); + } + } + return instantiationsCheck && subclassesCheck; + } + + /** + * Return true if the two types match. Unfortunately, xtext does not + * seem to create a suitable equals() method for Type, so we have to + * do this manually. + */ + private boolean sameType(Type type1, Type type2) { + if (type1 == null) { + return type2 == null; + } + if (type2 == null) { + return type1 == null; + } + // Most common case first. + if (type1.getId() != null) { + if (type1.getStars() != null) { + if (type2.getStars() == null) return false; + if (type1.getStars().size() != type2.getStars().size()) return false; + } + return (type1.getId().equals(type2.getId())); + } + + // Type specification in the grammar is: + // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); + if (type1.isTime()) { + if (!type2.isTime()) return false; + // Ignore the arraySpec because that is checked when connection + // is checked for balance. + return true; + } + // Type must be given in a code body + return type1.getCode().getBody().equals(type2.getCode().getBody()); + } + + ////////////////////////////////////////////////////////////// + //// Private fields. + + /** The error reporter. */ + private ValidatorErrorReporter errorReporter + = new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); + + /** Helper class containing information about the model. */ + private ModelInfo info = new ModelInfo(); + + @Inject(optional = true) + private ValidationMessageAcceptor messageAcceptor; + + /** The declared target. */ + private Target target; + + private List targetPropertyErrors = new ArrayList<>(); + + private List targetPropertyWarnings = new ArrayList<>(); + + ////////////////////////////////////////////////////////////// + //// Private static constants. + + private static String ACTIONS_MESSAGE + = "\"actions\" is a reserved word for the TypeScript target for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " + + "and reactor instantiation): "; + + private static String HOST_OR_FQN_REGEX + = "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; + + /** + * Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). + */ + private static String IPV4_REGEX = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; + + /** + * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), + * with minor adjustment to allow up to six IPV6 segments (without truncation) in front + * of an embedded IPv4-address. + **/ + private static String IPV6_REGEX = + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,7}:|" + + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + + "::(ffff(:0{1,4}){0,1}:){0,1}" + IPV4_REGEX + "|" + + "([0-9a-fA-F]{1,4}:){1,4}:" + IPV4_REGEX + "|" + + "([0-9a-fA-F]{1,4}:){1,6}" + IPV4_REGEX + ")"; + + private static String RESERVED_MESSAGE = "Reserved words in the target language are not allowed for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation): "; + + private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); + + private static String UNDERSCORE_MESSAGE = "Names of objects (inputs, outputs, actions, timers, parameters, " + + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; + + private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; + +>>>>>>> origin } diff --git a/test/C/.gitignore b/test/C/.gitignore new file mode 100644 index 0000000000..08f514ebc5 --- /dev/null +++ b/test/C/.gitignore @@ -0,0 +1 @@ +include/ diff --git a/test/C/c/bank_multiport_to_reaction_no_inlining.c b/test/C/c/bank_multiport_to_reaction_no_inlining.c new file mode 100644 index 0000000000..ae54c84c2d --- /dev/null +++ b/test/C/c/bank_multiport_to_reaction_no_inlining.c @@ -0,0 +1,16 @@ +#include "../include/BankMultiportToReactionNoInlining/BankMultiportToReactionNoInlining.h" + +void check(bankmultiporttoreactionnoinlining_self_t* self, doublecount_out_t*** out) { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + if (out[i][j]->is_present) { + lf_print("Received %d.", out[i][j]->value); + if (self->count != out[i][j]->value) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->received = true; + } + } + } + self->count++; +} diff --git a/test/C/c/bank_multiport_to_reaction_no_inlining.cmake b/test/C/c/bank_multiport_to_reaction_no_inlining.cmake new file mode 100644 index 0000000000..c433f89d7e --- /dev/null +++ b/test/C/c/bank_multiport_to_reaction_no_inlining.cmake @@ -0,0 +1 @@ +target_sources(${LF_MAIN_TARGET} PRIVATE c/bank_multiport_to_reaction_no_inlining.c) diff --git a/test/C/c/bank_to_reaction_no_inlining.c b/test/C/c/bank_to_reaction_no_inlining.c new file mode 100644 index 0000000000..9cf5b220b9 --- /dev/null +++ b/test/C/c/bank_to_reaction_no_inlining.c @@ -0,0 +1,11 @@ +#include "../include/BankToReactionNoInlining/BankToReactionNoInlining.h" + +void check(banktoreactionnoinlining_self_t* self, count_out_t** out) { + for (int i = 0; i < 2; i++) { + lf_print("Received %d.", out[i]->value); + if (self->count != out[i]->value) { + lf_print_error_and_exit("Expected %d but got %d.", self->count, out[i]->value); + } + } + self->count++; +} diff --git a/test/C/c/bank_to_reaction_no_inlining.cmake b/test/C/c/bank_to_reaction_no_inlining.cmake new file mode 100644 index 0000000000..a4f8d8dfa3 --- /dev/null +++ b/test/C/c/bank_to_reaction_no_inlining.cmake @@ -0,0 +1 @@ +target_sources(${LF_MAIN_TARGET} PRIVATE c/bank_to_reaction_no_inlining.c) diff --git a/test/C/c/count.c b/test/C/c/count.c new file mode 100644 index 0000000000..2bc5378b7d --- /dev/null +++ b/test/C/c/count.c @@ -0,0 +1,15 @@ +#include +#include "../include/Count/Count.h" + +void increment(count_self_t* self) { + printf("in increment, count=%d\n", self->count); + self->count++; +} + +void check_done(count_self_t* self) { + printf("in done, count=%d\n", self->count); + if (self->count > 10) { + printf("%s", "requesting stop\n"); + lf_request_stop(); + } +} diff --git a/test/C/c/count.cmake b/test/C/c/count.cmake new file mode 100644 index 0000000000..a9b364a871 --- /dev/null +++ b/test/C/c/count.cmake @@ -0,0 +1 @@ +target_sources(${LF_MAIN_TARGET} PRIVATE c/count.c) diff --git a/test/C/c/count_hierarchy.c b/test/C/c/count_hierarchy.c new file mode 100644 index 0000000000..999159aab8 --- /dev/null +++ b/test/C/c/count_hierarchy.c @@ -0,0 +1,15 @@ +#include +#include "../include/CountHierarchy/CountHierarchy.h" + +void increment(counthierarchy_self_t* self, timer_out_t* out) { + printf("in increment, count=%d\n", self->count); + self->count++; +} + +void check_done(counthierarchy_self_t* self, timer_out_t* out) { + printf("in done, count=%d\n", self->count); + if (self->count > 10) { + printf("%s", "requesting stop\n"); + lf_request_stop(); + } +} diff --git a/test/C/c/count_hierarchy.cmake b/test/C/c/count_hierarchy.cmake new file mode 100644 index 0000000000..955c07270a --- /dev/null +++ b/test/C/c/count_hierarchy.cmake @@ -0,0 +1 @@ +target_sources(${LF_MAIN_TARGET} PRIVATE c/count_hierarchy.c) diff --git a/test/C/c/multiport_to_reaction_no_inlining.c b/test/C/c/multiport_to_reaction_no_inlining.c new file mode 100644 index 0000000000..5036771cbd --- /dev/null +++ b/test/C/c/multiport_to_reaction_no_inlining.c @@ -0,0 +1,14 @@ +#include "../include/MultiportToReactionNoInlining/MultiportToReactionNoInlining.h" + +void check(multiporttoreactionnoinlining_self_t* self, source_out_t** out) { + int sum = 0; + for (int i = 0; i < 4; i++) { + if (out[i]->is_present) sum += out[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; +} diff --git a/test/C/c/multiport_to_reaction_no_inlining.cmake b/test/C/c/multiport_to_reaction_no_inlining.cmake new file mode 100644 index 0000000000..8f4226aff2 --- /dev/null +++ b/test/C/c/multiport_to_reaction_no_inlining.cmake @@ -0,0 +1 @@ +target_sources(${LF_MAIN_TARGET} PRIVATE c/multiport_to_reaction_no_inlining.c) diff --git a/test/C/c/sendreceive.c b/test/C/c/sendreceive.c new file mode 100644 index 0000000000..95a08176e7 --- /dev/null +++ b/test/C/c/sendreceive.c @@ -0,0 +1,17 @@ +#include + +#include "../include/IntPrint/Print.h" +#include "../include/IntPrint/Check.h" +#include "../include/api/set.h" + +void send(print_self_t* self, print_out_t* out) { + lf_set(out, 42); +} + +void receive(check_self_t* self, check_in_t* in) { + printf("Received: %d\n", in->value); + if (in->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } +} diff --git a/test/C/c/sendreceive.cmake b/test/C/c/sendreceive.cmake new file mode 100644 index 0000000000..acd63f229c --- /dev/null +++ b/test/C/c/sendreceive.cmake @@ -0,0 +1 @@ +target_sources(${LF_MAIN_TARGET} PRIVATE c/sendreceive.c) diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index c72dc16dcf..21ea7df141 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -5,6 +5,16 @@ target C { timeout: 6 sec } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + reactor Source(period: time = 3 sec) { output y: int timer t(0, period) @@ -14,7 +24,7 @@ reactor Source(period: time = 3 sec) { if (2 * (self->count / 2) != self->count) { // The count variable is odd. // Take time to cause a deadline violation. - lf_nanosleep(MSEC(1500)); + lf_sleep(MSEC(1500)); } printf("Source sends: %d.\n", self->count); lf_set(y, self->count); diff --git a/test/C/src/DeadlineHandledAbove.lf b/test/C/src/DeadlineHandledAbove.lf index 92d7e9dac8..3b0dc49198 100644 --- a/test/C/src/DeadlineHandledAbove.lf +++ b/test/C/src/DeadlineHandledAbove.lf @@ -2,6 +2,16 @@ // container reacts to that output. target C +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + reactor Deadline(threshold: time = 100 msec) { input x: int output deadline_violation: bool diff --git a/test/C/src/DeadlineInherited.lf b/test/C/src/DeadlineInherited.lf index eab2f56d9b..3d3c8ac96b 100644 --- a/test/C/src/DeadlineInherited.lf +++ b/test/C/src/DeadlineInherited.lf @@ -4,9 +4,10 @@ target C { threading: false } -preamble {= int global_cnt = 0; =} +preamble {= extern int global_cnt; =} reactor NoDeadline { + preamble {= int global_cnt = 0; =} timer t(0 msec, 100 msec) reaction(t) {= global_cnt++; =} diff --git a/test/C/src/DeadlinePriority.lf b/test/C/src/DeadlinePriority.lf index 723a29b754..2aa5c8136f 100644 --- a/test/C/src/DeadlinePriority.lf +++ b/test/C/src/DeadlinePriority.lf @@ -4,9 +4,10 @@ target C { threading: false } -preamble {= int global_cnt = 0; =} +preamble {= extern int global_cnt; =} reactor NoDeadline { + preamble {= int global_cnt = 0; =} timer t(0 msec, 100 msec) reaction(t) {= global_cnt++; =} diff --git a/test/C/src/DeadlineWithAfterDelay.lf b/test/C/src/DeadlineWithAfterDelay.lf index d1b87860ac..5e33e129e6 100644 --- a/test/C/src/DeadlineWithAfterDelay.lf +++ b/test/C/src/DeadlineWithAfterDelay.lf @@ -4,9 +4,11 @@ target C { threading: false } -preamble {= int global_cnt = 0; =} +preamble {= extern int global_cnt; =} reactor Source { + preamble {= int global_cnt = 0; =} + output out: int timer t(0 msec, 100 msec) diff --git a/test/C/src/DeadlineWithBanks.lf b/test/C/src/DeadlineWithBanks.lf index 18bc8c3682..7a9445ec8d 100644 --- a/test/C/src/DeadlineWithBanks.lf +++ b/test/C/src/DeadlineWithBanks.lf @@ -9,9 +9,11 @@ target C { build-type: Debug } -preamble {= volatile int global_cnt = 0; =} +preamble {= extern volatile int global_cnt; =} reactor Bank(bank_index: int = 0) { + preamble {= volatile int global_cnt = 0; =} + timer t(0, 100 msec) output out: int diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index b14e680d72..80b89020dd 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -2,6 +2,16 @@ // freed. target C +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include + #ifdef __cplusplus + } + #endif +=} + reactor DelayString2(delay: time = 100 msec) { input in: string output out: string diff --git a/test/C/src/DelayStruct.lf b/test/C/src/DelayStruct.lf index 9cd201aa11..0a92171d35 100644 --- a/test/C/src/DelayStruct.lf +++ b/test/C/src/DelayStruct.lf @@ -5,6 +5,7 @@ target C { preamble {= #include "hello.h" + #include =} reactor DelayPointer(delay: time = 100 msec) { diff --git a/test/C/src/Hello.lf b/test/C/src/Hello.lf index ea37265a23..7784e2f86f 100644 --- a/test/C/src/Hello.lf +++ b/test/C/src/Hello.lf @@ -8,6 +8,10 @@ target C { fast: true } +preamble {= + #include +=} + reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { state count: int = 0 state previous_time: time = 0 diff --git a/test/C/src/ScheduleValue.lf b/test/C/src/ScheduleValue.lf index 65e36fbd06..8481d47d61 100644 --- a/test/C/src/ScheduleValue.lf +++ b/test/C/src/ScheduleValue.lf @@ -3,6 +3,17 @@ target C { timeout: 3 sec } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include + #include + #ifdef __cplusplus + } + #endif +=} + main reactor ScheduleValue { logical action a: char* diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index 3e2d786eec..fba3e03cbc 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -3,6 +3,16 @@ // violation. target C +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + reactor Deadline(threshold: time = 100 msec) { input x: int output deadlineViolation: bool diff --git a/test/C/src/StructAsState.lf b/test/C/src/StructAsState.lf index 59ae495853..119762c14c 100644 --- a/test/C/src/StructAsState.lf +++ b/test/C/src/StructAsState.lf @@ -2,13 +2,14 @@ // value. target C +preamble {= + typedef struct hello_t { + char* name; + int value; + } hello_t; +=} + main reactor StructAsState { - preamble {= - typedef struct hello_t { - char* name; - int value; - } hello_t; - =} // Notice that target code delimiters are no longer necessary. state s: hello_t = {"Earth", 42} diff --git a/test/C/src/TestForPreviousOutput.lf b/test/C/src/TestForPreviousOutput.lf index fec3bc54da..583c6cbb74 100644 --- a/test/C/src/TestForPreviousOutput.lf +++ b/test/C/src/TestForPreviousOutput.lf @@ -2,6 +2,16 @@ // a given output. The output should always be 42. target C +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include + #ifdef __cplusplus + } + #endif +=} + reactor Source { output out: int diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index fdac093c49..16d6723f7f 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -1,21 +1,19 @@ /** - * Test watchdog. - * This test starts a watchdog timer of 150ms every 100ms. - * Half the time, it then sleeps after starting the watchdog so that - * the watchdog expires. There should be a total of five watchdog - * expirations. + * Test watchdog. This test starts a watchdog timer of 150ms every 100ms. Half + * the time, it then sleeps after starting the watchdog so that the watchdog + * expires. There should be a total of five watchdog expirations. * @author Benjamin Asch * @author Edward A. Lee */ target C { - timeout: 1100ms + timeout: 1100 ms } -reactor Watcher(timeout:time(150ms)) { - timer t(100ms, 100ms) // Offset ameliorates startup time. - output d: int // Produced if the watchdog triggers. - state alternating:bool(false) - state count:int(0) +reactor Watcher(timeout: time = 150 ms) { + timer t(100 ms, 100 ms) // Offset ameliorates startup time. + output d: int // Produced if the watchdog triggers. + state alternating: bool = false + state count: int = 0 watchdog poodle(timeout) {= instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); @@ -32,12 +30,12 @@ reactor Watcher(timeout:time(150ms)) { } self->alternating = !self->alternating; =} - + reaction(poodle) -> d {= lf_print("Reaction poodle was called."); lf_set(d, 1); =} - + reaction(shutdown) -> poodle {= // FIXME: There needs to be an lf_watchdog_stop() defined. _lf_watchdog_stop(poodle); @@ -49,14 +47,15 @@ reactor Watcher(timeout:time(150ms)) { main reactor { logical action a - state count:int(0) - + state count: int = 0 + w = new Watcher() reaction(w.d) {= lf_print("*** Watcher reactor produced an output."); self->count++; =} + reaction(shutdown) {= if (self->count != 5) { lf_print_error_and_exit("Watchdog produced output %d times. Expected 5.", self->count); diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index ec2beae766..58120446d4 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -9,9 +9,20 @@ */ target C { tracing: true, - timeout: 2 sec + timeout: 2 sec, + keepalive: true } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + main reactor AsyncCallback { preamble {= void callback(void* a) { diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index f123bcdbdf..b0c5c502f2 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -7,6 +7,16 @@ target C { timeout: 2 sec } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + main reactor { preamble {= void callback(void* a) { diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index b7afeb2363..7bac7496b5 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -7,6 +7,16 @@ target C { timeout: 2 sec } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + main reactor { preamble {= void callback(void* a) { diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index 545206de91..ad14879080 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -2,6 +2,16 @@ // container reacts to that output. target C +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + reactor Deadline(threshold: time = 100 msec) { input x: int output deadline_violation: bool @@ -20,7 +30,7 @@ main reactor { d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= - lf_nanosleep(MSEC(200)); + lf_sleep(MSEC(200)); lf_set(d.x, 42); =} diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index ac765fe6f7..ffc1be2701 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -5,6 +5,16 @@ target C { timeout: 6 sec } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif +=} + reactor Source(period: time = 3000 msec) { output y: int timer t(0, period) @@ -14,7 +24,7 @@ reactor Source(period: time = 3000 msec) { if (2 * (self->count / 2) != self->count) { // The count variable is odd. // Take time to cause a deadline violation. - lf_nanosleep(MSEC(210)); + lf_sleep(MSEC(210)); } printf("Source sends: %d.\n", self->count); lf_set(y, self->count); diff --git a/test/C/src/concurrent/HelloThreaded.lf b/test/C/src/concurrent/HelloThreaded.lf index a8ea34dd05..285811a17d 100644 --- a/test/C/src/concurrent/HelloThreaded.lf +++ b/test/C/src/concurrent/HelloThreaded.lf @@ -8,6 +8,10 @@ target C { fast: true } +preamble {= + #include +=} + reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { state count: int = 0 state previous_time: time = 0 diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index e68b3956e8..2ef6af7af6 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -10,6 +10,15 @@ target C { } reactor Scheduler { + preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "include/core/reactor_common.h" + #ifdef __cplusplus + } + #endif + =} logical action act // List of microsteps. Size = 16 state microstep_delay_list: uint32_t[] = { diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index 71da79c7ef..cbc4513732 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -7,6 +7,10 @@ target C { logging: DEBUG } +preamble {= + #include +=} + reactor Source { timer t(0, 200 msec) output out: int diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index e18ea4ac04..ef979a949d 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -13,6 +13,16 @@ target C { build-type: RelWithDebInfo // Release with debug info } +preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "federate.h" + #ifdef __cplusplus + } + #endif +=} + reactor Sender { output out: int timer t(0, 1 msec) diff --git a/test/C/src/federated/DistributedPhysicalActionUpstream.lf b/test/C/src/federated/DistributedPhysicalActionUpstream.lf index 47280a24b8..520142b466 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstream.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstream.lf @@ -13,22 +13,28 @@ import PassThrough from "../lib/PassThrough.lf" import TestCount from "../lib/TestCount.lf" preamble {= - int _counter = 1; - void callback(void *a) { - lf_schedule_int(a, 0, _counter++); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - while (_counter < 15) { - instant_t sleep_time = MSEC(10); - lf_sleep(sleep_time); - callback(a); - } - return NULL; - } + extern int _counter; + void callback(void *a); + void* take_time(void* a); =} reactor WithPhysicalAction { + preamble {= + int _counter = 1; + void callback(void *a) { + lf_schedule_int(a, 0, _counter++); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + while (_counter < 15) { + instant_t sleep_time = MSEC(10); + lf_sleep(sleep_time); + callback(a); + } + return NULL; + } + =} + output out: int state thread_id: lf_thread_t = 0 physical action act(0): int diff --git a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf index 66bbb964e1..5cee1171cc 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf @@ -13,22 +13,27 @@ import PassThrough from "../lib/PassThrough.lf" import TestCount from "../lib/TestCount.lf" preamble {= - int _counter = 1; - void callback(void *a) { - lf_schedule_int(a, 0, _counter++); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - while (_counter < 20) { - instant_t sleep_time = USEC(50); - lf_sleep(sleep_time); - callback(a); - } - return NULL; - } + extern int _counter; + void callback(void *a); + void* take_time(void* a); =} reactor WithPhysicalAction { + preamble {= + int _counter = 1; + void callback(void *a) { + lf_schedule_int(a, 0, _counter++); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + while (_counter < 20) { + instant_t sleep_time = USEC(50); + lf_sleep(sleep_time); + callback(a); + } + return NULL; + } + =} output out: int state thread_id: lf_thread_t = 0 physical action act(0): int diff --git a/test/C/src/federated/HelloDistributed.lf b/test/C/src/federated/HelloDistributed.lf index 6841bf91bc..909ce53b43 100644 --- a/test/C/src/federated/HelloDistributed.lf +++ b/test/C/src/federated/HelloDistributed.lf @@ -7,6 +7,10 @@ */ target C +preamble {= + #include +=} + reactor Source { output out: string diff --git a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf index 44ce6e1681..b4501cd555 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf @@ -15,19 +15,23 @@ target C { preamble {= #include // Defines sleep() - bool stop = false; - // Thread to trigger an action once every second. - void* ping(void* actionref) { - while(!stop) { - lf_print("Scheduling action."); - lf_schedule(actionref, 0); - sleep(1); - } - return NULL; - } + extern bool stop; + void* ping(void* actionref); =} reactor Looper(incr: int = 1, delay: time = 0 msec) { + preamble {= + bool stop = false; + // Thread to trigger an action once every second. + void* ping(void* actionref) { + while(!stop) { + lf_print("Scheduling action."); + lf_schedule(actionref, 0); + sleep(1); + } + return NULL; + } + =} input in: int output out: int physical action a(delay) diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index ae64e6e71a..4350c984b3 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -11,19 +11,23 @@ target C { preamble {= #include // Defines sleep() - bool stop = false; - // Thread to trigger an action once every second. - void* ping(void* actionref) { - while(!stop) { - lf_print("Scheduling action."); - lf_schedule(actionref, 0); - sleep(1); - } - return NULL; - } + extern bool stop; + void* ping(void* actionref); =} reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { + preamble {= + bool stop = false; + // Thread to trigger an action once every second. + void* ping(void* actionref) { + while(!stop) { + lf_print("Scheduling action."); + lf_schedule(actionref, 0); + sleep(1); + } + return NULL; + } + =} input in: int output out: int physical action a(stp_offset) diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 31b7eb0f6e..28723650d7 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -15,19 +15,23 @@ target C { preamble {= #include // Defines sleep() - bool stop = false; - // Thread to trigger an action once every second. - void* ping(void* actionref) { - while(!stop) { - lf_print("Scheduling action."); - lf_schedule(actionref, 0); - sleep(1); - } - return NULL; - } + extern bool stop; + void* ping(void* actionref); =} reactor Looper(incr: int = 1, delay: time = 0 msec) { + preamble {= + bool stop = false; + // Thread to trigger an action once every second. + void* ping(void* actionref) { + while(!stop) { + lf_print("Scheduling action."); + lf_schedule(actionref, 0); + sleep(1); + } + return NULL; + } + =} input in: int input in2: int output out: int diff --git a/test/C/src/include/hello.h b/test/C/src/include/hello.h index 6ee45b62a7..7b290fba89 100644 --- a/test/C/src/include/hello.h +++ b/test/C/src/include/hello.h @@ -18,14 +18,14 @@ typedef struct hello_t { typedef int* int_pointer; -hello_t* hello_constructor(char* name, int value) { +static hello_t* hello_constructor(char* name, int value) { hello_t* val = (hello_t*) malloc(sizeof(hello_t)); val->name = name; val->value = value; return val; } -hello_t* hello_copy_constructor(hello_t v) { +static hello_t* hello_copy_constructor(hello_t v) { hello_t* val = (hello_t*) malloc(sizeof(hello_t)); val->name = v.name; val->value = v.value; diff --git a/test/C/src/modal_models/BanksCount3ModesComplex.lf b/test/C/src/modal_models/BanksCount3ModesComplex.lf index ad08cc7325..47805f1009 100644 --- a/test/C/src/modal_models/BanksCount3ModesComplex.lf +++ b/test/C/src/modal_models/BanksCount3ModesComplex.lf @@ -55,7 +55,7 @@ main reactor { test = new TraceTesting( // keep-format events_size = 16, trace_size = 429, - trace = ( + trace = { 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 250000000,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -69,7 +69,7 @@ main reactor { 250000000,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0 - ), training = false) + }, training = false) counters.always, counters.mode1, counters.mode2, counters.never -> test.events diff --git a/test/C/src/modal_models/BanksCount3ModesSimple.lf b/test/C/src/modal_models/BanksCount3ModesSimple.lf index c03fb7e562..40c2ba50a8 100644 --- a/test/C/src/modal_models/BanksCount3ModesSimple.lf +++ b/test/C/src/modal_models/BanksCount3ModesSimple.lf @@ -13,7 +13,7 @@ main reactor { test = new TraceTesting( events_size = 3, trace_size = 63, - trace = ( // keep-format + trace = { // keep-format 0,1,1,1,1,1,1, 250000000,1,2,1,2,1,2, 250000000,1,3,1,3,1,3, @@ -23,7 +23,7 @@ main reactor { 250000000,1,1,1,1,1,1, 250000000,1,2,1,2,1,2, 250000000,1,3,1,3,1,3 - ), + }, training = false ) diff --git a/test/C/src/modal_models/BanksModalStateReset.lf b/test/C/src/modal_models/BanksModalStateReset.lf index 1dde9c5b97..8e075715c8 100644 --- a/test/C/src/modal_models/BanksModalStateReset.lf +++ b/test/C/src/modal_models/BanksModalStateReset.lf @@ -16,7 +16,7 @@ main reactor { reset1 = new[2] ResetReaction() reset2 = new[2] AutoReset() - test = new TraceTesting(events_size = 16, trace_size = 627, trace = ( // keep-format + test = new TraceTesting(events_size = 16, trace_size = 627, trace = { // keep-format 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, 250000000,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, 250000000,0,0,0,0,0,0,0,0,1,2,1,2,0,0,0,0, 0,0,0,0,0,0,0,0,1,2,1,2,0,0,0,0, @@ -36,7 +36,7 @@ main reactor { 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, 0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, 0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, 250000000,1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2, 1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2 - ), training = false) + }, training = false) reset1.mode_switch, reset1.count0, diff --git a/test/C/src/modal_models/ConvertCaseTest.lf b/test/C/src/modal_models/ConvertCaseTest.lf index 5475edaa35..3f644eb133 100644 --- a/test/C/src/modal_models/ConvertCaseTest.lf +++ b/test/C/src/modal_models/ConvertCaseTest.lf @@ -50,10 +50,6 @@ reactor Converter { input raw: char output converted: int - preamble {= - #include - =} - initial mode Upper { reaction(raw) -> converted, reset(Lower) {= char c = raw->value; @@ -114,7 +110,7 @@ main reactor { test = new TraceTesting( events_size = 2, trace_size = 60, - trace = ( // keep-format + trace = { // keep-format 0,1,72,1,72, 250000000,1,69,1,69, 250000000,1,76,1,76, @@ -127,7 +123,7 @@ main reactor { 250000000,1,76,1,108, 250000000,1,68,1,100, 250000000,1,95,1,95 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalActions.lf b/test/C/src/modal_models/ModalActions.lf index 1d8dff8cb4..e687d4bafd 100644 --- a/test/C/src/modal_models/ModalActions.lf +++ b/test/C/src/modal_models/ModalActions.lf @@ -68,7 +68,7 @@ main reactor { test = new TraceTesting( events_size = 5, trace_size = 165, - trace = ( // keep-format + trace = { // keep-format 0,0,0,1,1,0,0,0,0,0,0, 500000000,0,0,0,1,1,1,0,0,0,0, 250000000,0,0,1,1,0,1,0,0,0,0, @@ -84,7 +84,7 @@ main reactor { 500000000,0,1,0,1,0,1,0,1,1,1, 250000000,0,1,0,1,0,1,1,1,0,1, 250000000,1,1,0,1,0,1,0,1,0,1 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalAfter.lf b/test/C/src/modal_models/ModalAfter.lf index 270fd88d05..f5cc8d229e 100644 --- a/test/C/src/modal_models/ModalAfter.lf +++ b/test/C/src/modal_models/ModalAfter.lf @@ -73,7 +73,7 @@ main reactor { test = new TraceTesting( events_size = 5, trace_size = 165, - trace = ( // keep-format + trace = { // keep-format 0,0,0,1,1,0,0,0,0,0,0, 500000000,0,0,0,1,1,1,0,0,0,0, 250000000,0,0,1,1,0,1,0,0,0,0, @@ -89,7 +89,7 @@ main reactor { 500000000,0,1,0,1,0,1,0,1,1,1, 250000000,0,1,0,1,0,1,1,1,0,1, 250000000,1,1,0,1,0,1,0,1,0,1 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalCycleBreaker.lf b/test/C/src/modal_models/ModalCycleBreaker.lf index cee4fabfec..aae727b23d 100644 --- a/test/C/src/modal_models/ModalCycleBreaker.lf +++ b/test/C/src/modal_models/ModalCycleBreaker.lf @@ -57,7 +57,7 @@ main reactor { test = new TraceTesting( events_size = 1, trace_size = 27, - trace = ( // keep-format + trace = { // keep-format 0,1,0, 100000000,1,1, 100000000,1,2, @@ -67,7 +67,7 @@ main reactor { 100000000,1,7, 100000000,1,8, 100000000,1,9 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalStartupShutdown.lf b/test/C/src/modal_models/ModalStartupShutdown.lf index fa1ebaacdf..d39117882a 100644 --- a/test/C/src/modal_models/ModalStartupShutdown.lf +++ b/test/C/src/modal_models/ModalStartupShutdown.lf @@ -113,7 +113,7 @@ main reactor { test = new TraceTesting( events_size = 11, trace_size = 253, - trace = ( // keep-format + trace = { // keep-format 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 500000000,1,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,2,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -125,7 +125,7 @@ main reactor { 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, 500000000,1,4,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalStateReset.lf b/test/C/src/modal_models/ModalStateReset.lf index 61563162b6..c098f088d5 100644 --- a/test/C/src/modal_models/ModalStateReset.lf +++ b/test/C/src/modal_models/ModalStateReset.lf @@ -63,7 +63,7 @@ main reactor { test = new TraceTesting( events_size = 4, trace_size = 171, - trace = ( // keep-format + trace = { // keep-format 0,0,0,0,0,1,0,0,0, 250000000,0,0,0,0,1,1,0,0, 250000000,0,0,0,0,1,2,0,0, @@ -83,7 +83,7 @@ main reactor { 250000000,0,1,0,2,0,8,1,0, 250000000,0,1,0,2,0,8,1,1, 250000000,1,1,1,3,0,8,1,2 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalStateResetAuto.lf b/test/C/src/modal_models/ModalStateResetAuto.lf index a2b6b105f0..a82fd18212 100644 --- a/test/C/src/modal_models/ModalStateResetAuto.lf +++ b/test/C/src/modal_models/ModalStateResetAuto.lf @@ -59,7 +59,7 @@ main reactor { test = new TraceTesting( events_size = 4, trace_size = 171, - trace = ( // keep-format + trace = { // keep-format 0,0,0,0,0,1,0,0,0, 250000000,0,0,0,0,1,1,0,0, 250000000,0,0,0,0,1,2,0,0, @@ -79,7 +79,7 @@ main reactor { 250000000,0,1,0,2,0,8,1,0, 250000000,0,1,0,2,0,8,1,1, 250000000,1,1,1,3,0,8,1,2 - ), + }, training = false ) diff --git a/test/C/src/modal_models/ModalTimers.lf b/test/C/src/modal_models/ModalTimers.lf index 47fcf5f9e4..954a677de4 100644 --- a/test/C/src/modal_models/ModalTimers.lf +++ b/test/C/src/modal_models/ModalTimers.lf @@ -49,7 +49,7 @@ main reactor { test = new TraceTesting( events_size = 3, trace_size = 77, - trace = ( // keep-format + trace = { // keep-format 0,0,0,1,1,0,0, 750000000,0,0,1,1,0,0, 250000000,1,1,0,1,0,0, @@ -61,7 +61,7 @@ main reactor { 0,0,1,0,1,1,1, 750000000,0,1,0,1,1,1, 250000000,1,1,0,1,0,1 - ), + }, training = false ) diff --git a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf index 60fa76dd1e..31de4fe6bd 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -44,7 +44,7 @@ main reactor { test = new TraceTesting( events_size = 1, trace_size = 51, - trace = ( // keep-format + trace = { // keep-format 0,1,0, 250000000,1,1, 250000000,1,2, @@ -62,7 +62,7 @@ main reactor { 100000000,1,3, 100000000,1,4, 100000000,1,5 - ), + }, training = false ) diff --git a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index dff82c602f..f89073dfc1 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -47,7 +47,7 @@ main reactor { test = new TraceTesting( events_size = 1, trace_size = 51, - trace = ( // keep-format + trace = { // keep-format 0,1,0, 250000000,1,1, 250000000,1,2, @@ -65,7 +65,7 @@ main reactor { 100000000,1,30, 100000000,1,40, 100000000,1,50 - ), + }, training = false ) diff --git a/test/C/src/modal_models/util/TraceTesting.lf b/test/C/src/modal_models/util/TraceTesting.lf index 247b3f1def..c63de35f2a 100644 --- a/test/C/src/modal_models/util/TraceTesting.lf +++ b/test/C/src/modal_models/util/TraceTesting.lf @@ -1,10 +1,6 @@ /** Utility reactor to record and test execution traces. */ target C -preamble {= - #include -=} - reactor TraceTesting( events_size: int = 0, trace_size: int = 0, diff --git a/test/C/src/multiport/BankIndexInitializer.lf b/test/C/src/multiport/BankIndexInitializer.lf index d8a2c5766e..e6c52e8efe 100644 --- a/test/C/src/multiport/BankIndexInitializer.lf +++ b/test/C/src/multiport/BankIndexInitializer.lf @@ -1,9 +1,11 @@ // Test bank of reactors to multiport input with id parameter in the bank. target C -preamble {= int table[] = {4, 3, 2, 1}; =} +preamble {= extern int table[4]; =} reactor Source(bank_index: int = 0, value: int = 0) { + preamble {= int table[] = {4, 3, 2, 1}; =} + output out: int reaction(startup) -> out {= lf_set(out, self->value); =} diff --git a/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf b/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf new file mode 100644 index 0000000000..e69e0af0b4 --- /dev/null +++ b/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf @@ -0,0 +1,30 @@ +target C { + timeout: 5 sec, + fast: true, + cmake-include: ["../../c/bank_multiport_to_reaction_no_inlining.cmake"], + files: ["../../c"] +} + +import Count from "../lib/Count.lf" + +reactor DoubleCount { + output[2] out: int + c1 = new Count() + c2 = new Count() + c1.out, c2.out -> out +} + +main reactor { + state count: int = 1 + state received: bool = false + + s = new[2] DoubleCount() + + reaction(s.out) named check + + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("No inputs present."); + } + =} +} diff --git a/test/C/src/no_inlining/BankToReactionNoInlining.lf b/test/C/src/no_inlining/BankToReactionNoInlining.lf new file mode 100644 index 0000000000..4956bf68cd --- /dev/null +++ b/test/C/src/no_inlining/BankToReactionNoInlining.lf @@ -0,0 +1,16 @@ +target C { + timeout: 5 sec, + fast: true, + cmake-include: ["../../c/bank_to_reaction_no_inlining.cmake"], + files: ["../../c"] +} + +import Count from "../lib/Count.lf" + +main reactor { + state count: int = 1 + + s = new[2] Count() + + reaction(s.out) named check +} diff --git a/test/C/src/no_inlining/Count.lf b/test/C/src/no_inlining/Count.lf new file mode 100644 index 0000000000..f8fd51bec7 --- /dev/null +++ b/test/C/src/no_inlining/Count.lf @@ -0,0 +1,16 @@ +target C { + cmake-include: ["../../c/count.cmake"], + files: ["../../c"] +} + +main reactor Count { + timer t(0, 1 msec) + + state count: int + + reaction(t) named increment + + reaction(t) named check_done + + reaction(shutdown) {= printf("%s", "shutting down\n"); =} +} diff --git a/test/C/src/no_inlining/CountHierarchy.lf b/test/C/src/no_inlining/CountHierarchy.lf new file mode 100644 index 0000000000..771222af2f --- /dev/null +++ b/test/C/src/no_inlining/CountHierarchy.lf @@ -0,0 +1,23 @@ +target C { + cmake-include: ["../../c/count_hierarchy.cmake"], + files: ["../../c"] +} + +reactor Timer(m: time = 0, n: time = 0) { + output out: int + timer t(m, n) + + reaction(t) -> out {= lf_set(out, 0); =} +} + +main reactor { + t = new Timer(m = 0, n = 1 msec) + + state count: int + + reaction(t.out) named increment + + reaction(t.out) named check_done + + reaction(shutdown) {= printf("%s", "shutting down\n"); =} +} diff --git a/test/C/src/no_inlining/IntPrint.lf b/test/C/src/no_inlining/IntPrint.lf new file mode 100644 index 0000000000..fa6ab8c757 --- /dev/null +++ b/test/C/src/no_inlining/IntPrint.lf @@ -0,0 +1,22 @@ +target C { + cmake-include: ["../../c/sendreceive.cmake"], + files: ["../../c"] +} + +reactor Print { + output out: int + + reaction(startup) -> out named send +} + +reactor Check(expected: int = 42) { // expected parameter is for testing. + input in: int + + reaction(in) named receive +} + +main reactor { + s = new Print() + p = new Check() + s.out -> p.in +} diff --git a/test/C/src/no_inlining/MultiportToReactionNoInlining.lf b/test/C/src/no_inlining/MultiportToReactionNoInlining.lf new file mode 100644 index 0000000000..3c5f18d62a --- /dev/null +++ b/test/C/src/no_inlining/MultiportToReactionNoInlining.lf @@ -0,0 +1,35 @@ +// Check reaction to multiport output of a contained reactor. +target C { + timeout: 2 sec, + fast: true, + cmake-include: ["../../c/multiport_to_reaction_no_inlining.cmake"], + files: ["../../c"] +} + +reactor Source(width: int = 1) { + timer t(0, 200 msec) + state s: int = 0 + output[width] out: int + + reaction(t) -> out {= + printf("Sending.\n"); + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s++); + } + =} +} + +main reactor { + state s: int = 6 + b = new Source(width = 4) + + reaction(b.out) named check + + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} +} diff --git a/test/C/src/token/include/array.h b/test/C/src/token/include/array.h index c1fd1b4991..5ea8d5230b 100644 --- a/test/C/src/token/include/array.h +++ b/test/C/src/token/include/array.h @@ -21,7 +21,7 @@ typedef struct int_array_t { * @param length The length. * @return A pointer to the array struct. */ -int_array_t* int_array_constructor(size_t length) { +static inline int_array_t* int_array_constructor(size_t length) { int_array_t* result = (int_array_t*) malloc(sizeof(int_array_t)); result->data = (int*) calloc(length, sizeof(int)); result->length = length; @@ -36,7 +36,7 @@ int_array_t* int_array_constructor(size_t length) { * @param array The array to copy. * @return void* */ -void* int_array_copy_constructor(void* array) { +static inline void* int_array_copy_constructor(void* array) { int_array_t* source = (int_array_t*) array; int_array_t* copy = (int_array_t*) malloc(sizeof(int_array_t)); copy->data = (int*) calloc(source->length, sizeof(int)); @@ -54,7 +54,7 @@ void* int_array_copy_constructor(void* array) { * when their reference count decrements to zero. * @param array The array to free. */ -void int_array_destructor(void* array) { +static inline void int_array_destructor(void* array) { free(((int_array_t*) array)->data); free(array); } diff --git a/test/Python/.gitignore b/test/Python/.gitignore new file mode 100644 index 0000000000..08f514ebc5 --- /dev/null +++ b/test/Python/.gitignore @@ -0,0 +1 @@ +include/ diff --git a/util/tracing/.gitignore b/util/tracing/.gitignore new file mode 100644 index 0000000000..5fe4f5283d --- /dev/null +++ b/util/tracing/.gitignore @@ -0,0 +1,2 @@ +*.o +trace_to_csv diff --git a/util/tracing/trace_to_chrome.c b/util/tracing/trace_to_chrome.c index 92eeee71dd..5cf979227a 100644 --- a/util/tracing/trace_to_chrome.c +++ b/util/tracing/trace_to_chrome.c @@ -31,6 +31,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * point your chrome browser to chrome://tracing/ and the load the .json file. */ #define LF_TRACE +#include #include "reactor.h" #include "trace.h" #include "trace_util.h" @@ -92,7 +93,7 @@ size_t read_and_write_trace(FILE* trace_file, FILE* output_file) { if (reactor_name == NULL) { if (trace[i].event_type == worker_wait_starts || trace[i].event_type == worker_wait_ends) { reactor_name = "WAIT"; - } else if (trace[i].event_type == scheduler_advancing_time_starts + } else if (trace[i].event_type == scheduler_advancing_time_starts || trace[i].event_type == scheduler_advancing_time_starts) { reactor_name = "ADVANCE TIME"; } else { @@ -194,7 +195,7 @@ size_t read_and_write_trace(FILE* trace_file, FILE* output_file) { phase = "E"; break; default: - fprintf(stderr, "WARNING: Unrecognized event type %d: %s\n", + fprintf(stderr, "WARNING: Unrecognized event type %d: %s\n", trace[i].event_type, trace_event_names[trace[i].event_type]); pid = PID_FOR_UNKNOWN_EVENT; phase = "i"; @@ -275,7 +276,7 @@ void write_metadata_events(FILE* output_file) { "\"pid\": 0, " "\"tid\": 0, " "\"args\": {" - "\"name\": \"Main thread\"" + "\"name\": \"Main thread\"" "}},\n" ); @@ -328,7 +329,7 @@ void write_metadata_events(FILE* output_file) { ); } } - + // Write the reactor names for the logical timelines. for (int i = 0; i < object_table_size; i++) { if (object_table[i].type == trace_trigger) { @@ -341,10 +342,10 @@ void write_metadata_events(FILE* output_file) { "\"pid\": %d, " // the "process" to identify by reactor. "\"tid\": %d," // The "thread" to label with action or timer name. "\"args\": {" - "\"name\": \"Trigger %s\"" + "\"name\": \"Trigger %s\"" "}},\n", reactor_index + 1, // Offset of 1 prevents collision with Execution. - i, + i, object_table[i].description); } else if (object_table[i].type == trace_reactor) { fprintf(output_file, "{" @@ -352,7 +353,7 @@ void write_metadata_events(FILE* output_file) { "\"ph\": \"M\", " // mark as metadata. "\"pid\": %d, " // the "process" to label as reactor. "\"args\": {" - "\"name\": \"Reactor %s reactions, actions, and timers in logical time\"" + "\"name\": \"Reactor %s reactions, actions, and timers in logical time\"" "}},\n", i + 1, // Offset of 1 prevents collision with Execution. object_table[i].description); @@ -363,7 +364,7 @@ void write_metadata_events(FILE* output_file) { "\"pid\": %d, " // the "process" to label as reactor. "\"tid\": %d," // The "thread" to label with action or timer name. "\"args\": {" - "\"name\": \"%s\"" + "\"name\": \"%s\"" "}},\n", PID_FOR_USER_EVENT, i, // This is the index in the object table. @@ -376,7 +377,7 @@ void write_metadata_events(FILE* output_file) { "\"ph\": \"M\", " // mark as metadata. "\"pid\": 0, " // the "process" to label "Execution". "\"args\": {" - "\"name\": \"Execution of %s\"" + "\"name\": \"Execution of %s\"" "}},\n", top_level); // Name the "process" for "Worker Waiting" if the PID is not the main execution one. @@ -386,7 +387,7 @@ void write_metadata_events(FILE* output_file) { "\"ph\": \"M\", " // mark as metadata. "\"pid\": %d, " // the "process" to label "Workers waiting for reaction queue". "\"args\": {" - "\"name\": \"Workers waiting for reaction queue\"" + "\"name\": \"Workers waiting for reaction queue\"" "}},\n", PID_FOR_WORKER_WAIT); } @@ -397,7 +398,7 @@ void write_metadata_events(FILE* output_file) { "\"ph\": \"M\", " // mark as metadata. "\"pid\": %d, " // the "process" to label "Workers waiting for reaction queue". "\"args\": {" - "\"name\": \"Workers advancing time\"" + "\"name\": \"Workers advancing time\"" "}},\n", PID_FOR_WORKER_ADVANCING_TIME); } @@ -408,7 +409,7 @@ void write_metadata_events(FILE* output_file) { "\"ph\": \"M\", " // mark as metadata. "\"pid\": %d, " // the "process" to label "User events". "\"args\": {" - "\"name\": \"User events in %s, shown in physical time:\"" + "\"name\": \"User events in %s, shown in physical time:\"" "}}\n", PID_FOR_USER_EVENT, top_level); } diff --git a/util/tracing/trace_to_csv.c b/util/tracing/trace_to_csv.c index 707cc5f43b..1abf08c082 100644 --- a/util/tracing/trace_to_csv.c +++ b/util/tracing/trace_to_csv.c @@ -30,6 +30,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * text file. */ #define LF_TRACE +#include +#include #include "reactor.h" #include "trace.h" #include "trace_util.h" @@ -84,7 +86,7 @@ typedef struct summary_stats_t { reaction_stats_t reactions[MAX_NUM_REACTIONS]; } summary_stats_t; -/** +/** * Sumary stats array. This array has the same size as the * object table. Pointer in the array will be void if there * are no stats for the object table item. @@ -135,7 +137,7 @@ size_t read_and_write_trace() { if (trigger_instance >= 0 && summary_stats[NUM_EVENT_TYPES + trigger_instance] == NULL) { summary_stats[NUM_EVENT_TYPES + trigger_instance] = (summary_stats_t*)calloc(1, sizeof(summary_stats_t)); } - + summary_stats_t* stats = NULL; interval_t exec_time; reaction_stats_t* rstats; @@ -198,7 +200,7 @@ size_t read_and_write_trace() { // commandeer the first entry in the reactions array to track values. stats = summary_stats[NUM_EVENT_TYPES + object_instance]; stats->description = reactor_name; - rstats = &stats->reactions[0]; + rstats = &stats->reactions[0]; rstats->occurrences++; // User values are stored in the "extra_delay" field, which is an interval_t. interval_t value = trace[i].extra_delay; @@ -332,7 +334,7 @@ void write_summary_file() { first = true; for (int i = NUM_EVENT_TYPES; i < table_size; i++) { summary_stats_t* stats = summary_stats[i]; - if (stats != NULL + if (stats != NULL && (stats->event_type == user_event || stats->event_type == user_value) && stats->occurrences > 0) { if (first) { diff --git a/util/tracing/trace_to_influxdb.c b/util/tracing/trace_to_influxdb.c index a99ae003ec..aa50911e5e 100644 --- a/util/tracing/trace_to_influxdb.c +++ b/util/tracing/trace_to_influxdb.c @@ -27,13 +27,13 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @section DESCRIPTION - * + * * Standalone program to send a Lingua Franca trace file to InfluxDB. * InfluxDB is a database server to which data can be posted using HTTP * or sent as a UDP datagram. - * + * * ## Compiling this Program - * + * * To compile this program, simply do this in this source directory: * ``` * make install @@ -41,13 +41,13 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * This will place an executable program `trace_to_influxdb` in the directory `lingua-franca/bin`. * I find it convenient to have this directory in my `PATH` (this is also where the * `lfc` command-line Lingua Franca compiler is located). - * + * * ## Setting up InfluxDB - * + * * To set up InfluxDB, see: - * + * * [https://docs.influxdata.com/influxdb/v2.0/get-started/](https://docs.influxdata.com/influxdb/v2.0/get-started/) - * + * * If you have previously installed InfluxDB and you want a fresh start, do this: * ```shell * rm -rf ~/.influxdbv2/ @@ -58,13 +58,13 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * kill -9 PID * ``` * where 'PID' is replaced with whatever process ID(s) are reported by the `ps` command above. - * + * * To start an InfluxDB server on localhost with port 8087: * ```shell * influxd --http-bind-address :8087 --reporting-disabled * ``` * The 'reporting-disabled' option simply disables notifications to the InfluxDB mother ship. - * + * * You then need to set up at least one user, organization, and bucket. You can do this by pointing your browser to * ``` * http://localhost:8087 @@ -77,9 +77,9 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ``` * The UI in the browser will then give you the options Quick Start or Advanced, either of which you can select. * If you select "Data" on the left, you can browse Buckets to verify that your test bucket was created. - * + * * ## Uploading Trace Data to InfluxDB - * + * * First, generate a trace file by setting a target parameter in a Lingua Franca program: * ``` * target C { @@ -87,7 +87,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * }; * ``` * Then, when you run this program, a binary file with extension `.lft` will be created. - * + * * In your browser, in the InfluxDB UI, select Data on the left, then select the Tokens tab. * Select a token and copy the token string to clipboard. It will looks something like this: * ``` @@ -100,15 +100,16 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ``` * where 'Filename' and the token are replaced with your values. * This will upload the trace data to InfluxDB. - * + * * You can also specify the following command-line options: * * -h, --host: The host name running InfluxDB. If not given, this defaults to "localhost". * * -p, --port: The port for accessing InfluxDB. This defaults to 8086. If you used 8087, as shown above, then you have to give this option. - * + * * The data can then be viewed in the InfluxDB browser, or you can configure an external * tool such as Grafana to visualize it (see https://grafana.com/docs/grafana/latest/datasources/influxdb/). */ #define LF_TRACE +#include #include "reactor.h" #include "trace.h" #include "trace_util.h" @@ -208,7 +209,7 @@ int main(int argc, char* argv[]) { influx_v2_client.token = NULL; influx_v2_client.host = "localhost"; influx_v2_client.port = 8086; - influx_v2_client.org = "iCyPhy"; + influx_v2_client.org = "iCyPhy"; influx_v2_client.bucket = "test"; char* filename = NULL; @@ -277,4 +278,4 @@ int main(int argc, char* argv[]) { printf("***** %zu records written to InfluxDB.\n", num_records); // File closing is handled by termination function. } -} \ No newline at end of file +} diff --git a/util/tracing/trace_util.c b/util/tracing/trace_util.c index 0f97b3bdb9..551ec94473 100644 --- a/util/tracing/trace_util.c +++ b/util/tracing/trace_util.c @@ -30,6 +30,9 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * text file. */ #define LF_TRACE +#include +#include +#include #include "reactor.h" #include "trace.h" #include "trace_util.h" @@ -187,12 +190,12 @@ void print_table() { } else { type = "unknown type"; } - printf("pointer = %p, trigger = %p, type = %s: %s\n", + printf("pointer = %p, trigger = %p, type = %s: %s\n", object_table[i].pointer, object_table[i].trigger, type, object_table[i].description); - } + } printf("-------\n"); } From 40b075a460e5d1ce8ec5a11f5dc8b79b3922ddfa Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Wed, 19 Apr 2023 15:45:25 +0500 Subject: [PATCH 140/709] Update Reactor-C --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 866b189a4f..8523f14b96 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 866b189a4f04d3fae7a50a256b8ca3686ea1c509 +Subproject commit 8523f14b962ae56aad375dde22141a600821fdce From e39e1e9e9c84cb910287b231a4d5de36a1ff0294 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Wed, 19 Apr 2023 21:28:59 +0500 Subject: [PATCH 141/709] [C-Generics] Fix the case where Contained Reactor is initiated with a combination of Templated Types and Concrete Types Signed-off-by: mkhubaibumer --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 4d628de5b4..99540cce83 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -949,6 +949,9 @@ private void resolveTemplatedTypes(ReactorInstance reactorInstance, TypeParamete if (parentTpr.typeArgs().containsKey(type)) { var basicType = parentTpr.typeArgs().get(type); copy.put(literal, basicType); + } else { + // Typename is not inherited from Parent Reactor. Keep As Is! + copy.put(literal, typename); } }); if (!copy.isEmpty()) { // If we found some templated-types update the tpr with new map From 414970ff2c04df9e62d866b1d2b75f4e361f175a Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Thu, 20 Apr 2023 11:17:59 +0900 Subject: [PATCH 142/709] Fix ssh --- .github/workflows/c-tests.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index da060ce38a..ce13f0cee8 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -24,10 +24,8 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v2 - - name: Setup upterm session - uses: lhotari/action-upterm@v1 - steps: + - name: Setup upterm session + uses: lhotari/action-upterm@v1 - name: Check out lingua-franca repository uses: actions/checkout@v3 with: From b63b27546ba93664566963683f5f427813358769 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Thu, 20 Apr 2023 13:56:29 +0900 Subject: [PATCH 143/709] Fix ssh to last --- .github/workflows/c-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index ce13f0cee8..ed1ba0d784 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -24,8 +24,6 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - name: Setup upterm session - uses: lhotari/action-upterm@v1 - name: Check out lingua-franca repository uses: actions/checkout@v3 with: @@ -74,3 +72,5 @@ jobs: fail_ci_if_error: false verbose: true if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + - name: Setup upterm session + uses: lhotari/action-upterm@v1 \ No newline at end of file From b95830e7ae3b0894a54dfe0aeeba62cbc2b0db95 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 20 Apr 2023 11:08:57 -0700 Subject: [PATCH 144/709] issues fixed w watchdog test, seems to be working as expected, not sure why though --- org.lflang/src/org/lflang/ASTUtils.java | 3091 +++++++++-------- .../org/lflang/generator/c/CGenerator.java | 10 +- .../generator/c/CReactionGenerator.java | 2 +- .../generator/c/CWatchdogGenerator.java | 3 +- test/C/src/Watchdog.lf | 4 +- 5 files changed, 1605 insertions(+), 1505 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 996ce1509f..9c3003007e 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -1,16 +1,12 @@ /* Copyright (c) 2020, The University of California at Berkeley. - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,9 +21,6 @@ package org.lflang; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -35,6 +28,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -42,6 +36,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; + import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -62,6 +57,8 @@ import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Assignment; +import org.lflang.lf.AttrParm; +import org.lflang.lf.Attribute; import org.lflang.lf.Code; import org.lflang.lf.Connection; import org.lflang.lf.Element; @@ -95,1640 +92,1740 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; + /** * A helper class for modifying and analyzing the AST. - * * @author Marten Lohstroh * @author Edward A. Lee * @author Christian Menard */ public class ASTUtils { - /** The Lingua Franca factory for creating new AST nodes. */ - public static final LfFactory factory = LfFactory.eINSTANCE; - - /** The Lingua Franca feature package. */ - public static final LfPackage featurePackage = LfPackage.eINSTANCE; - - /* Match an abbreviated form of a float literal. */ - private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); - - /** - * A mapping from Reactor features to corresponding Mode features for collecting contained - * elements. - */ - private static final Map reactorModeFeatureMap = - Map.of( - featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), - featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), - featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), - featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), - featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), - featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), - featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs()); - - /** - * Get all reactors defined in the given resource. - * - * @param resource the resource to extract reactors from - * @return An iterable over all reactors found in the resource - */ - public static List getAllReactors(Resource resource) { - return StreamSupport.stream( - IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) - .filter(Reactor.class::isInstance) - .map(Reactor.class::cast) - .collect(Collectors.toList()); - } + /** + * The Lingua Franca factory for creating new AST nodes. + */ + public static final LfFactory factory = LfFactory.eINSTANCE; + + /** + * The Lingua Franca feature package. + */ + public static final LfPackage featurePackage = LfPackage.eINSTANCE; + + /* Match an abbreviated form of a float literal. */ + private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); + + /** + * A mapping from Reactor features to corresponding Mode features for collecting contained elements. + */ + private static final Map reactorModeFeatureMap = Map.of( + featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), + featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), + featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), + featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), + featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), + featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), + featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs() + ); + + + /** + * Get all reactors defined in the given resource. + * @param resource the resource to extract reactors from + * @return An iterable over all reactors found in the resource + */ + public static List getAllReactors(Resource resource) { + return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) + .filter(Reactor.class::isInstance) + .map(Reactor.class::cast) + .collect(Collectors.toList()); + } + + /** + * Find connections in the given resource that would be conflicting writes if they were not located in mutually + * exclusive modes. + * + * @param resource The AST. + * @return a list of connections being able to be transformed + */ + public static Collection findConflictingConnectionsInModalReactors(Resource resource) { + var transform = new HashSet(); + + for (Reactor reactor : getAllReactors(resource)) { + if (!reactor.getModes().isEmpty()) { // Only for modal reactors + var allWriters = HashMultimap., EObject>create(); + + // Collect destinations + for (var rea : allReactions(reactor)) { + for (var eff : rea.getEffects()) { + if (eff.getVariable() instanceof Port) { + allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); + } + } + } + for (var con : ASTUtils.collectElements(reactor, featurePackage.getReactor_Connections(), false, true)) { + for (var port : con.getRightPorts()) { + allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); + } + } - /** - * Find connections in the given resource that would be conflicting writes if they were not - * located in mutually exclusive modes. - * - * @param resource The AST. - * @return a list of connections being able to be transformed - */ - public static Collection findConflictingConnectionsInModalReactors( - Resource resource) { - var transform = new HashSet(); - - for (Reactor reactor : getAllReactors(resource)) { - if (!reactor.getModes().isEmpty()) { // Only for modal reactors - var allWriters = HashMultimap., EObject>create(); - - // Collect destinations - for (var rea : allReactions(reactor)) { - for (var eff : rea.getEffects()) { - if (eff.getVariable() instanceof Port) { - allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); + // Handle conflicting writers + for (var key : allWriters.keySet()) { + var writers = allWriters.get(key); + if (writers.size() > 1) { // has multiple sources + var writerModes = HashMultimap.create(); + // find modes + for (var writer : writers) { + if (writer.eContainer() instanceof Mode) { + writerModes.put((Mode) writer.eContainer(), writer); + } else { + writerModes.put(null, writer); + } + } + // Conflicting connection can only be handled if.. + if (!writerModes.containsKey(null) && // no writer is on root level (outside of modes) and... + writerModes.keySet().stream().map(writerModes::get).allMatch(writersInMode -> // all writers in a mode are either... + writersInMode.size() == 1 || // the only writer or... + writersInMode.stream().allMatch(w -> w instanceof Reaction) // all are reactions and hence ordered + )) { + // Add connections to transform list + writers.stream().filter(w -> w instanceof Connection).forEach(c -> transform.add((Connection) c)); + } + } + } } - } - } - for (var con : - ASTUtils.collectElements( - reactor, featurePackage.getReactor_Connections(), false, true)) { - for (var port : con.getRightPorts()) { - allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); - } } - // Handle conflicting writers - for (var key : allWriters.keySet()) { - var writers = allWriters.get(key); - if (writers.size() > 1) { // has multiple sources - var writerModes = HashMultimap.create(); - // find modes - for (var writer : writers) { - if (writer.eContainer() instanceof Mode) { - writerModes.put((Mode) writer.eContainer(), writer); - } else { - writerModes.put(null, writer); - } - } - // Conflicting connection can only be handled if.. - if (!writerModes.containsKey(null) - && // no writer is on root level (outside of modes) and... - writerModes.keySet().stream() - .map(writerModes::get) - .allMatch( - writersInMode -> // all writers in a mode are either... - writersInMode.size() == 1 - || // the only writer or... - writersInMode.stream() - .allMatch( - w -> - w - instanceof - Reaction) // all are reactions and hence ordered - )) { - // Add connections to transform list - writers.stream() - .filter(w -> w instanceof Connection) - .forEach(c -> transform.add((Connection) c)); - } - } + return transform; + } + + /** + * Return the enclosing reactor of an LF EObject in a reactor or mode. + * @param obj the LF model element + * @return the reactor or null + */ + public static Reactor getEnclosingReactor(EObject obj) { + if (obj.eContainer() instanceof Reactor) { + return (Reactor) obj.eContainer(); + } else if (obj.eContainer() instanceof Mode) { + return (Reactor) obj.eContainer().eContainer(); } - } + return null; } - return transform; - } + /** + * Return the main reactor in the given resource if there is one, null otherwise. + */ + public static Reactor findMainReactor(Resource resource) { + return IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), + Reactor::isMain + ); + } - /** - * Return the enclosing reactor of an LF EObject in a reactor or mode. - * - * @param obj the LF model element - * @return the reactor or null - */ - public static Reactor getEnclosingReactor(EObject obj) { - if (obj.eContainer() instanceof Reactor) { - return (Reactor) obj.eContainer(); - } else if (obj.eContainer() instanceof Mode) { - return (Reactor) obj.eContainer().eContainer(); - } - return null; - } + /** + * Find the main reactor and change it to a federated reactor. + * Return true if the transformation was successful (or the given resource + * already had a federated reactor); return false otherwise. + */ + public static boolean makeFederated(Resource resource) { + // Find the main reactor + Reactor r = findMainReactor(resource); + if (r == null) { + return false; + } + r.setMain(false); + r.setFederated(true); + return true; + } - /** Return the main reactor in the given resource if there is one, null otherwise. */ - public static Reactor findMainReactor(Resource resource) { - return IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), Reactor::isMain); - } + /** + * Change the target name to 'newTargetName'. + * For example, change C to CCpp. + */ + public static boolean changeTargetName(Resource resource, String newTargetName) { + targetDecl(resource).setName(newTargetName); + return true; + } - /** - * Find the main reactor and change it to a federated reactor. Return true if the transformation - * was successful (or the given resource already had a federated reactor); return false otherwise. - */ - public static boolean makeFederated(Resource resource) { - // Find the main reactor - Reactor r = findMainReactor(resource); - if (r == null) { - return false; - } - r.setMain(false); - r.setFederated(true); - return true; - } + /** + * Return the target of the file in which the given node lives. + */ + public static Target getTarget(EObject object) { + TargetDecl targetDecl = targetDecl(object.eResource()); + return Target.fromDecl(targetDecl); + } - /** Change the target name to 'newTargetName'. For example, change C to CCpp. */ - public static boolean changeTargetName(Resource resource, String newTargetName) { - targetDecl(resource).setName(newTargetName); - return true; - } + /** + * Add a new target property to the given resource. + * + * This also creates a config object if the resource does not yey have one. + * + * @param resource The resource to modify + * @param name Name of the property to add + * @param value Value to be assigned to the property + */ + public static boolean addTargetProperty(final Resource resource, final String name, final Element value) { + var config = targetDecl(resource).getConfig(); + if (config == null) { + config = LfFactory.eINSTANCE.createKeyValuePairs(); + targetDecl(resource).setConfig(config); + } + final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); + newProperty.setName(name); + newProperty.setValue(value); + config.getPairs().add(newProperty); + return true; + } - /** Return the target of the file in which the given node lives. */ - public static Target getTarget(EObject object) { - TargetDecl targetDecl = targetDecl(object.eResource()); - return Target.fromDecl(targetDecl); - } + /** + * Return true if the connection involves multiple ports on the left or right side of the connection, or + * if the port on the left or right of the connection involves a bank of reactors or a multiport. + * @param connection The connection. + */ + public static boolean hasMultipleConnections(Connection connection) { + if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { + return true; + } + VarRef leftPort = connection.getLeftPorts().get(0); + VarRef rightPort = connection.getRightPorts().get(0); + Instantiation leftContainer = leftPort.getContainer(); + Instantiation rightContainer = rightPort.getContainer(); + Port leftPortAsPort = (Port) leftPort.getVariable(); + Port rightPortAsPort = (Port) rightPort.getVariable(); + return leftPortAsPort.getWidthSpec() != null + || leftContainer != null && leftContainer.getWidthSpec() != null + || rightPortAsPort.getWidthSpec() != null + || rightContainer != null && rightContainer.getWidthSpec() != null; + } - /** - * Add a new target property to the given resource. - * - *

This also creates a config object if the resource does not yey have one. - * - * @param resource The resource to modify - * @param name Name of the property to add - * @param value Value to be assigned to the property - */ - public static boolean addTargetProperty( - final Resource resource, final String name, final Element value) { - var config = targetDecl(resource).getConfig(); - if (config == null) { - config = LfFactory.eINSTANCE.createKeyValuePairs(); - targetDecl(resource).setConfig(config); - } - final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); - newProperty.setName(name); - newProperty.setValue(value); - config.getPairs().add(newProperty); - return true; - } + /** + * Produce a unique identifier within a reactor based on a + * given based name. If the name does not exists, it is returned; + * if does exist, an index is appended that makes the name unique. + * @param reactor The reactor to find a unique identifier within. + * @param name The name to base the returned identifier on. + */ + public static String getUniqueIdentifier(Reactor reactor, String name) { + LinkedHashSet vars = new LinkedHashSet<>(); + allActions(reactor).forEach(it -> vars.add(it.getName())); + allTimers(reactor).forEach(it -> vars.add(it.getName())); + allParameters(reactor).forEach(it -> vars.add(it.getName())); + allInputs(reactor).forEach(it -> vars.add(it.getName())); + allOutputs(reactor).forEach(it -> vars.add(it.getName())); + allStateVars(reactor).forEach(it -> vars.add(it.getName())); + allInstantiations(reactor).forEach(it -> vars.add(it.getName())); + + int index = 0; + String suffix = ""; + boolean exists = true; + while (exists) { + String id = name + suffix; + if (IterableExtensions.exists(vars, it -> it.equals(id))) { + suffix = "_" + index; + index++; + } else { + exists = false; + } + } + return name + suffix; + } - /** - * Return true if the connection involves multiple ports on the left or right side of the - * connection, or if the port on the left or right of the connection involves a bank of reactors - * or a multiport. - * - * @param connection The connection. - */ - public static boolean hasMultipleConnections(Connection connection) { - if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { - return true; - } - VarRef leftPort = connection.getLeftPorts().get(0); - VarRef rightPort = connection.getRightPorts().get(0); - Instantiation leftContainer = leftPort.getContainer(); - Instantiation rightContainer = rightPort.getContainer(); - Port leftPortAsPort = (Port) leftPort.getVariable(); - Port rightPortAsPort = (Port) rightPort.getVariable(); - return leftPortAsPort.getWidthSpec() != null - || leftContainer != null && leftContainer.getWidthSpec() != null - || rightPortAsPort.getWidthSpec() != null - || rightContainer != null && rightContainer.getWidthSpec() != null; - } + //////////////////////////////// + //// Utility functions for supporting inheritance and modes + + /** + * Given a reactor class, return a list of all its actions, + * which includes actions of base classes that it extends. + * This also includes actions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allActions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); + } - /** - * Produce a unique identifier within a reactor based on a given based name. If the name does not - * exists, it is returned; if does exist, an index is appended that makes the name unique. - * - * @param reactor The reactor to find a unique identifier within. - * @param name The name to base the returned identifier on. - */ - public static String getUniqueIdentifier(Reactor reactor, String name) { - LinkedHashSet vars = new LinkedHashSet<>(); - allActions(reactor).forEach(it -> vars.add(it.getName())); - allTimers(reactor).forEach(it -> vars.add(it.getName())); - allParameters(reactor).forEach(it -> vars.add(it.getName())); - allInputs(reactor).forEach(it -> vars.add(it.getName())); - allOutputs(reactor).forEach(it -> vars.add(it.getName())); - allStateVars(reactor).forEach(it -> vars.add(it.getName())); - allInstantiations(reactor).forEach(it -> vars.add(it.getName())); - - int index = 0; - String suffix = ""; - boolean exists = true; - while (exists) { - String id = name + suffix; - if (IterableExtensions.exists(vars, it -> it.equals(id))) { - suffix = "_" + index; - index++; - } else { - exists = false; - } - } - return name + suffix; - } + /** + * Given a reactor class, return a list of all its connections, + * which includes connections of base classes that it extends. + * This also includes connections in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allConnections(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); + } - //////////////////////////////// - //// Utility functions for supporting inheritance and modes - - /** - * Given a reactor class, return a list of all its actions, which includes actions of base classes - * that it extends. This also includes actions in modes, returning a flattened view over all - * modes. - * - * @param definition Reactor class definition. - */ - public static List allActions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); - } + /** + * Given a reactor class, return a list of all its inputs, + * which includes inputs of base classes that it extends. + * If the base classes include a cycle, where X extends Y and Y extends X, + * then return only the input defined in the base class. + * The returned list may be empty. + * @param definition Reactor class definition. + */ + public static List allInputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); + } - /** - * Given a reactor class, return a list of all its connections, which includes connections of base - * classes that it extends. This also includes connections in modes, returning a flattened view - * over all modes. - * - * @param definition Reactor class definition. - */ - public static List allConnections(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); - } + /** A list of all ports of {@code definition}, in an unspecified order. */ + public static List allPorts(Reactor definition) { + return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); + } - /** - * Given a reactor class, return a list of all its inputs, which includes inputs of base classes - * that it extends. If the base classes include a cycle, where X extends Y and Y extends X, then - * return only the input defined in the base class. The returned list may be empty. - * - * @param definition Reactor class definition. - */ - public static List allInputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); - } + /** + * Given a reactor class, return a list of all its instantiations, + * which includes instantiations of base classes that it extends. + * This also includes instantiations in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allInstantiations(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); + } - /** - * Given a reactor class, return a list of all its instantiations, which includes instantiations - * of base classes that it extends. This also includes instantiations in modes, returning a - * flattened view over all modes. - * - * @param definition Reactor class definition. - */ - public static List allInstantiations(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); - } + public static Stream allNestedClasses(Reactor definition) { + return new HashSet<>(ASTUtils.allInstantiations(definition)).stream() + .map(Instantiation::getReactorClass) + .map(ASTUtils::toDefinition); + } - /** - * Given a reactor class, return a list of all its methods, which includes methods of base classes - * that it extends. - * - * @param definition Reactor class definition. - */ - public static List allMethods(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); - } + /** + * Given a reactor class, return a list of all its methods, + * which includes methods of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allMethods(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); + } - /** - * Given a reactor class, return a list of all its outputs, which includes outputs of base classes - * that it extends. - * - * @param definition Reactor class definition. - */ - public static List allOutputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); - } + /** + * Given a reactor class, return a list of all its outputs, + * which includes outputs of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allOutputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); + } - /** - * Given a reactor class, return a list of all its parameters, which includes parameters of base - * classes that it extends. - * - * @param definition Reactor class definition. - */ - public static List allParameters(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); - } + /** + * Given a reactor class, return a list of all its parameters, + * which includes parameters of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allParameters(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); + } - /** - * Given a reactor class, return a list of all its reactions, which includes reactions of base - * classes that it extends. This also includes reactions in modes, returning a flattened view over - * all modes. - * - * @param definition Reactor class definition. - */ - public static List allReactions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); - } + /** + * Given a reactor class, return a list of all its reactions, + * which includes reactions of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allReactions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); + } - /** - * Given a reactor class, return a list of all its watchdogs. - * - * @param definition Reactor class definition - * @return List - */ - public static List allWatchdogs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); - } + /** + * Given a reactor class, return a list of all its watchdogs. + * @param definition Reactor class definition + * @return List + */ + public static List allWatchdogs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); + } + + /** + * Given a reactor class, return a list of all its state variables, + * which includes state variables of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allStateVars(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); + } - /** - * Given a reactor class, return a list of all its state variables, which includes state variables - * of base classes that it extends. This also includes reactions in modes, returning a flattened - * view over all modes. - * - * @param definition Reactor class definition. - */ - public static List allStateVars(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); - } + /** + * Given a reactor class, return a list of all its timers, + * which includes timers of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allTimers(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); + } - /** - * Given a reactor class, return a list of all its timers, which includes timers of base classes - * that it extends. This also includes reactions in modes, returning a flattened view over all - * modes. - * - * @param definition Reactor class definition. - */ - public static List allTimers(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); - } + /** + * Given a reactor class, returns a list of all its modes, + * which includes modes of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allModes(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); + } - /** - * Given a reactor class, returns a list of all its modes, which includes modes of base classes - * that it extends. - * - * @param definition Reactor class definition. - */ - public static List allModes(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); - } + /** A list of all reactors instantiated, transitively or intransitively, by {@code r}. */ + public static List recursiveChildren(ReactorInstance r) { + List ret = new ArrayList<>(); + ret.add(r.reactorDefinition); + for (var child: r.children) { + ret.addAll(recursiveChildren(child)); + } + return ret; + } - /** - * Return all the superclasses of the specified reactor in deepest-first order. For example, if A - * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates - * are removed. If the specified reactor does not extend any other reactor, then return an empty - * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared - * that is not found, then return null. - * - * @param reactor The specified reactor. - */ - public static LinkedHashSet superClasses(Reactor reactor) { - return superClasses(reactor, new LinkedHashSet<>()); - } + /** + * Return all the superclasses of the specified reactor + * in deepest-first order. For example, if A extends B and C, and + * B and C both extend D, this will return the list [D, B, C, A]. + * Duplicates are removed. If the specified reactor does not extend + * any other reactor, then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + */ + public static LinkedHashSet superClasses(Reactor reactor) { + return superClasses(reactor, new LinkedHashSet<>()); + } - /** - * Collect elements of type T from the class hierarchy and modes defined by a given reactor - * definition. - * - * @param definition The reactor definition. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - public static List collectElements( - Reactor definition, EStructuralFeature feature) { - return ASTUtils.collectElements(definition, feature, true, true); - } + /** + * Collect elements of type T from the class hierarchy and modes + * defined by a given reactor definition. + * @param definition The reactor definition. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + public static List collectElements(Reactor definition, EStructuralFeature feature) { + return ASTUtils.collectElements(definition, feature, true, true); + } - /** - * Collect elements of type T contained in given reactor definition, including modes and the class - * hierarchy defined depending on configuration. - * - * @param definition The reactor definition. - * @param feature The structual model elements to collect. - * @param includeSuperClasses Whether to include elements in super classes. - * @param includeModes Whether to include elements in modes. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - @SuppressWarnings("unchecked") - public static List collectElements( - Reactor definition, - EStructuralFeature feature, - boolean includeSuperClasses, - boolean includeModes) { - List result = new ArrayList<>(); - - if (includeSuperClasses) { - // Add elements of elements defined in superclasses. - LinkedHashSet s = superClasses(definition); - if (s != null) { - for (Reactor superClass : s) { - result.addAll((EList) superClass.eGet(feature)); + /** + * Collect elements of type T contained in given reactor definition, including + * modes and the class hierarchy defined depending on configuration. + * @param definition The reactor definition. + * @param feature The structual model elements to collect. + * @param includeSuperClasses Whether to include elements in super classes. + * @param includeModes Whether to include elements in modes. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + @SuppressWarnings("unchecked") + public static List collectElements(Reactor definition, EStructuralFeature feature, boolean includeSuperClasses, boolean includeModes) { + List result = new ArrayList<>(); + + if (includeSuperClasses) { + // Add elements of elements defined in superclasses. + LinkedHashSet s = superClasses(definition); + if (s != null) { + for (Reactor superClass : s) { + result.addAll((EList) superClass.eGet(feature)); + } + } } - } - } - // Add elements of the current reactor. - result.addAll((EList) definition.eGet(feature)); + // Add elements of the current reactor. + result.addAll((EList) definition.eGet(feature)); + + if (includeModes && reactorModeFeatureMap.containsKey(feature)) { + var modeFeature = reactorModeFeatureMap.get(feature); + // Add elements of elements defined in modes. + for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { + insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); + } + } - if (includeModes && reactorModeFeatureMap.containsKey(feature)) { - var modeFeature = reactorModeFeatureMap.get(feature); - // Add elements of elements defined in modes. - for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { - insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); - } + return result; } - return result; - } + /** + * Adds the elements into the given list at a location matching to their textual position. + * + * When creating a flat view onto reactor elements including modes, the final list must be ordered according + * to the textual positions. + * + * Example: + * reactor R { + * reaction // -> is R.reactions[0] + * mode M { + * reaction // -> is R.mode[0].reactions[0] + * reaction // -> is R.mode[0].reactions[1] + * } + * reaction // -> is R.reactions[1] + * } + * In this example, it is important that the reactions in the mode are inserted between the top-level + * reactions to retain the correct global reaction ordering, which will be derived from this flattened view. + * + * @param list The list to add the elements into. + * @param elements The elements to add. + * @param mode The mode containing the elements. + * @param The type of elements to add (e.g., Port, Timer, etc.) + */ + private static void insertModeElementsAtTextualPosition(List list, List elements, Mode mode) { + if (elements.isEmpty()) { + return; // Nothing to add + } - /** - * Adds the elements into the given list at a location matching to their textual position. - * - *

When creating a flat view onto reactor elements including modes, the final list must be - * ordered according to the textual positions. - * - *

Example: reactor R { reaction // -> is R.reactions[0] mode M { reaction // -> is - * R.mode[0].reactions[0] reaction // -> is R.mode[0].reactions[1] } reaction // -> is - * R.reactions[1] } In this example, it is important that the reactions in the mode are inserted - * between the top-level reactions to retain the correct global reaction ordering, which will be - * derived from this flattened view. - * - * @param list The list to add the elements into. - * @param elements The elements to add. - * @param mode The mode containing the elements. - * @param The type of elements to add (e.g., Port, Timer, etc.) - */ - private static void insertModeElementsAtTextualPosition( - List list, List elements, Mode mode) { - if (elements.isEmpty()) { - return; // Nothing to add - } - - var idx = list.size(); - if (idx > 0) { - // If there are elements in the list, first check if the last element has the same container - // as the mode. - // I.e. we don't want to compare textual positions of different reactors (super classes) - if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { - var modeAstNode = NodeModelUtils.getNode(mode); - if (modeAstNode != null) { - var modePos = modeAstNode.getOffset(); - // Now move the insertion index from the last element forward as long as this element has - // a textual - // position after the mode. - do { - var astNode = NodeModelUtils.getNode(list.get(idx - 1)); - if (astNode != null && astNode.getOffset() > modePos) { - idx--; - } else { - break; // Insertion index is ok. + var idx = list.size(); + if (idx > 0) { + // If there are elements in the list, first check if the last element has the same container as the mode. + // I.e. we don't want to compare textual positions of different reactors (super classes) + if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { + var modeAstNode = NodeModelUtils.getNode(mode); + if (modeAstNode != null) { + var modePos = modeAstNode.getOffset(); + // Now move the insertion index from the last element forward as long as this element has a textual + // position after the mode. + do { + var astNode = NodeModelUtils.getNode(list.get(idx - 1)); + if (astNode != null && astNode.getOffset() > modePos) { + idx--; + } else { + break; // Insertion index is ok. + } + } while (idx > 0); + } } - } while (idx > 0); } - } + list.addAll(idx, elements); } - list.addAll(idx, elements); - } - - public static Iterable allElementsOfClass( - Resource resource, Class elementClass) { - //noinspection StaticPseudoFunctionalStyleMethod - return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); - } - //////////////////////////////// - //// Utility functions for translating AST nodes into text - - // public static Code toCode(String text) { - // Code code = null; - // if (text == null) return code; - // code.setBody(text); - // return code; - // } - - /** - * Translate the given code into its textual representation with {@code CodeMap.Correspondence} - * tags inserted, or return the empty string if {@code node} is {@code null}. This method should - * be used to generate code. - * - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toText(EObject node) { - if (node == null) return ""; - return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); - } + public static Iterable allElementsOfClass( + Resource resource, + Class elementClass + ) { + //noinspection StaticPseudoFunctionalStyleMethod + return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); + } - /** - * Translate the given code into its textual representation without {@code CodeMap.Correspondence} - * tags, or return the empty string if {@code node} is {@code null}. This method should be used - * for analyzing AST nodes in cases where they are easiest to analyze as strings. - * - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toOriginalText(EObject node) { - if (node == null) return ""; - return ToText.instance.doSwitch(node); - } + //////////////////////////////// + //// Utility functions for translating AST nodes into text + + /** + * Translate the given code into its textual representation + * with {@code CodeMap.Correspondence} tags inserted, or + * return the empty string if {@code node} is {@code null}. + * This method should be used to generate code. + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toText(EObject node) { + if (node == null) return ""; + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); + } - /** - * Return an integer representation of the given element. - * - *

Internally, this method uses Integer.decode, so it will also understand hexadecimal, binary, - * etc. - * - * @param e The element to be rendered as an integer. - */ - public static Integer toInteger(Element e) { - return Integer.decode(e.getLiteral()); - } + /** + * Translate the given code into its textual representation + * without {@code CodeMap.Correspondence} tags, or return + * the empty string if {@code node} is {@code null}. + * This method should be used for analyzing AST nodes in + * cases where they are easiest to analyze as strings. + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toOriginalText(EObject node) { + if (node == null) return ""; + return ToText.instance.doSwitch(node); + } - /** - * Return a time value based on the given element. - * - * @param e The element to be rendered as a time value. - */ - public static TimeValue toTimeValue(Element e) { - return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); - } + /** + * Return an integer representation of the given element. + * + * Internally, this method uses Integer.decode, so it will + * also understand hexadecimal, binary, etc. + * + * @param e The element to be rendered as an integer. + */ + public static Integer toInteger(Element e) { + return Integer.decode(e.getLiteral()); + } - /** Returns the time value represented by the given AST node. */ - public static TimeValue toTimeValue(Time e) { - if (!isValidTime(e)) { - // invalid unit, will have been reported by validator - throw new IllegalArgumentException(); + /** + * Return a time value based on the given element. + * + * @param e The element to be rendered as a time value. + */ + public static TimeValue toTimeValue(Element e) { + return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); } - return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); - } - /** - * Return a boolean based on the given element. - * - * @param e The element to be rendered as a boolean. - */ - public static boolean toBoolean(Element e) { - return elementToSingleString(e).equalsIgnoreCase("true"); - } + /** + * Returns the time value represented by the given AST node. + */ + public static TimeValue toTimeValue(Time e) { + if (!isValidTime(e)) { + // invalid unit, will have been reported by validator + throw new IllegalArgumentException(); + } + return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + } - /** - * Given the right-hand side of a target property, return a string that represents the given - * value/ - * - *

If the given value is not a literal or and id (but for instance and array or dict), an empty - * string is returned. If the element is a string, any quotes are removed. - * - * @param e The right-hand side of a target property. - */ - public static String elementToSingleString(Element e) { - if (e.getLiteral() != null) { - return StringUtil.removeQuotes(e.getLiteral()).trim(); - } else if (e.getId() != null) { - return e.getId(); - } - return ""; - } + /** + * Return a boolean based on the given element. + * + * @param e The element to be rendered as a boolean. + */ + public static boolean toBoolean(Element e) { + return elementToSingleString(e).equalsIgnoreCase("true"); + } - /** - * Given the right-hand side of a target property, return a list with all the strings that the - * property lists. - * - *

Arrays are traversed, so strings are collected recursively. Empty strings are ignored; they - * are not added to the list. - * - * @param value The right-hand side of a target property. - */ - public static List elementToListOfStrings(Element value) { - List elements = new ArrayList<>(); - if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - elements.addAll(elementToListOfStrings(element)); - } - return elements; - } else { - String v = elementToSingleString(value); - if (!v.isEmpty()) { - elements.add(v); - } - } - return elements; - } + /** + * Given the right-hand side of a target property, return a string that + * represents the given value/ + * + * If the given value is not a literal or and id (but for instance and array or dict), + * an empty string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String elementToSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } - /** - * Convert key-value pairs in an Element to a map, assuming that both the key and the value are - * strings. - */ - public static Map elementToStringMaps(Element value) { - Map elements = new HashMap<>(); - for (var element : value.getKeyvalue().getPairs()) { - elements.put( - element.getName().trim(), - StringUtil.removeQuotes(elementToSingleString(element.getValue()))); - } - return elements; - } + /** + * Given the right-hand side of a target property, return a list with all + * the strings that the property lists. + * + * Arrays are traversed, so strings are collected recursively. Empty strings + * are ignored; they are not added to the list. + * @param value The right-hand side of a target property. + */ + public static List elementToListOfStrings(Element value) { + List elements = new ArrayList<>(); + if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + elements.addAll(elementToListOfStrings(element)); + } + return elements; + } else { + String v = elementToSingleString(value); + if (!v.isEmpty()) { + elements.add(v); + } + } + return elements; + } - // Various utility methods to convert various data types to Elements - - /** Convert a map to key-value pairs in an Element. */ - public static Element toElement(Map map) { - Element e = LfFactory.eINSTANCE.createElement(); - if (map.size() == 0) return null; - else { - var kv = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var entry : map.entrySet()) { - var pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(entry.getKey()); - var element = LfFactory.eINSTANCE.createElement(); - element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); - pair.setValue(element); - kv.getPairs().add(pair); - } - e.setKeyvalue(kv); - } - - return e; - } + /** + * Convert key-value pairs in an Element to a map, assuming that both the key + * and the value are strings. + */ + public static Map elementToStringMaps(Element value) { + Map elements = new HashMap<>(); + for (var element: value.getKeyvalue().getPairs()) { + elements.put( + element.getName().trim(), + StringUtil.removeQuotes(elementToSingleString(element.getValue())) + ); + } + return elements; + } - /** - * Given a single string, convert it into its AST representation. {@code addQuotes} controls if - * the generated representation should be accompanied by double quotes ("") or not. - */ - private static Element toElement(String str, boolean addQuotes) { - if (str == null) return null; - var strToReturn = addQuotes ? StringUtil.addDoubleQuotes(str) : str; - Element e = LfFactory.eINSTANCE.createElement(); - e.setLiteral(strToReturn); - return e; - } + // Various utility methods to convert various data types to Elements + + /** + * Convert a map to key-value pairs in an Element. + */ + public static Element toElement(Map map) { + Element e = LfFactory.eINSTANCE.createElement(); + if (map.size() == 0) return null; + else { + var kv = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var entry : map.entrySet()) { + var pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(entry.getKey()); + var element = LfFactory.eINSTANCE.createElement(); + element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); + pair.setValue(element); + kv.getPairs().add(pair); + } + e.setKeyvalue(kv); + } - /** Given a single string, convert it into its AST representation. */ - public static Element toElement(String str) { - return toElement(str, true); - } + return e; + } - /** - * Given a list of strings, convert it into its AST representation. Stores the list in the Array - * field of the element, unless the list only has one string, in which case it is stored in the - * Literal field. Returns null if the provided list is empty. - */ - public static Element toElement(List list) { - Element e = LfFactory.eINSTANCE.createElement(); - if (list.size() == 0) return null; - else if (list.size() == 1) { - return toElement(list.get(0)); - } else { - var arr = LfFactory.eINSTANCE.createArray(); - for (String s : list) { - arr.getElements().add(ASTUtils.toElement(s)); - } - e.setArray(arr); - } - return e; - } + /** + * Given a single string, convert it into its AST representation. + * {@code addQuotes} controls if the generated representation should be + * accompanied by double quotes ("") or not. + */ + private static Element toElement(String str, boolean addQuotes) { + if (str == null) return null; + var strToReturn = addQuotes? StringUtil.addDoubleQuotes(str):str; + Element e = LfFactory.eINSTANCE.createElement(); + e.setLiteral(strToReturn); + return e; - /** - * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit - * inside an Element. - */ - public static Element toElement(TimeValue tv) { - Element e = LfFactory.eINSTANCE.createElement(); - e.setTime((int) tv.time); - if (tv.unit != null) { - e.setUnit(tv.unit.toString()); - } - return e; - } + } - public static Element toElement(boolean val) { - return toElement(Boolean.toString(val), false); - } + /** + * Given a single string, convert it into its AST representation. + */ + public static Element toElement(String str) { + return toElement(str, true); + } - public static Element toElement(int val) { - return toElement(Integer.toString(val), false); - } + /** + * Given a list of strings, convert it into its AST representation. + * Stores the list in the Array field of the element, unless the list only has one string, + * in which case it is stored in the Literal field. Returns null if the provided list is empty. + */ + public static Element toElement(List list) { + Element e = LfFactory.eINSTANCE.createElement(); + if (list.size() == 0) return null; + else if (list.size() == 1) { + return toElement(list.get(0)); + } else { + var arr = LfFactory.eINSTANCE.createArray(); + for (String s : list) { + arr.getElements().add(ASTUtils.toElement(s)); + } + e.setArray(arr); + } + return e; + } - /** - * Translate the given type into its textual representation, but do not append any array - * specifications or type arguments. - * - * @param type AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String baseType(Type type) { - if (type != null) { - if (type.getCode() != null) { - return toText(type.getCode()); - } else { - if (type.isTime()) { - return "time"; + /** + * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit inside an Element. + */ + public static Element toElement(TimeValue tv) { + Element e = LfFactory.eINSTANCE.createElement(); + e.setTime((int)tv.time); + if (tv.unit != null) { + e.setUnit(tv.unit.toString()); } - } + return e; } - return ""; - } - /** - * Report whether the given literal is zero or not. - * - * @param literal AST node to inspect. - * @return True if the given literal denotes the constant `0`, false otherwise. - */ - public static boolean isZero(String literal) { - try { - if (literal != null && Integer.parseInt(literal) == 0) { - return true; - } - } catch (NumberFormatException e) { - // Not an int. + public static Element toElement(boolean val) { + return toElement(Boolean.toString(val), false); } - return false; - } - /** - * Report whether the given expression is zero or not. - * - * @param expr AST node to inspect. - * @return True if the given value denotes the constant `0`, false otherwise. - */ - public static boolean isZero(Expression expr) { - if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } + public static Element toElement(int val) { + return toElement(Integer.toString(val), false); + } - /** - * Report whether the given string literal is an integer number or not. - * - * @param literal AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Integer.decode(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } + /** + * Translate the given type into its textual representation, but + * do not append any array specifications or type arguments. + * @param type AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String baseType(Type type) { + if (type != null) { + if (type.getCode() != null) { + return toText(type.getCode()); + } else { + if (type.isTime()) { + return "time"; + } else { + StringBuilder result = new StringBuilder(type.getId()); + + for (String s : convertToEmptyListIfNull(type.getStars())) { + result.append(s); + } + return result.toString(); + } + } + } + return ""; + } - /** - * Report whether the given string literal is a boolean value or not. - * - * @param literal AST node to inspect. - * @return True if the given value is a boolean, false otherwise. - */ - public static boolean isBoolean(String literal) { - return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); - } + /** + * Report whether the given literal is zero or not. + * @param literal AST node to inspect. + * @return True if the given literal denotes the constant `0`, false + * otherwise. + */ + public static boolean isZero(String literal) { + try { + if (literal != null && + Integer.parseInt(literal) == 0) { + return true; + } + } catch (NumberFormatException e) { + // Not an int. + } + return false; + } - /** - * Report whether the given string literal is a float value or not. - * - * @param literal AST node to inspect. - * @return True if the given value is a float, false otherwise. - */ - public static boolean isFloat(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Float.parseFloat(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } + /** + * Report whether the given expression is zero or not. + * + * @param expr AST node to inspect. + * @return True if the given value denotes the constant `0`, false otherwise. + */ + public static boolean isZero(Expression expr) { + if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } - /** - * Report whether the given code is an integer number or not. - * - * @param code AST node to inspect. - * @return True if the given code is an integer, false otherwise. - */ - public static boolean isInteger(Code code) { - return isInteger(toText(code)); - } + /** + * Report whether the given string literal is an integer number or not. + * + * @param literal AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Integer.decode(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } - /** - * Report whether the given expression is an integer number or not. - * - * @param expr AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(Expression expr) { - if (expr instanceof Literal) { - return isInteger(((Literal) expr).getLiteral()); - } else if (expr instanceof Code) { - return isInteger((Code) expr); - } - return false; - } + /** + * Report whether the given string literal is a boolean value or not. + * @param literal AST node to inspect. + * @return True if the given value is a boolean, false otherwise. + */ + public static boolean isBoolean(String literal) { + return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); + } - /** - * Report whether the given expression denotes a valid time or not. - * - * @param expr AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Expression expr) { - if (expr instanceof ParameterReference) { - return isOfTimeType(((ParameterReference) expr).getParameter()); - } else if (expr instanceof Time) { - return isValidTime((Time) expr); - } else if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } + /** + * Report whether the given string literal is a float value or not. + * @param literal AST node to inspect. + * @return True if the given value is a float, false otherwise. + */ + public static boolean isFloat(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Float.parseFloat(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } - /** - * Report whether the given time denotes a valid time or not. - * - * @param t AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Time t) { - if (t == null) return false; - String unit = t.getUnit(); - return t.getInterval() == 0 || TimeUnit.isValidUnit(unit); - } + /** + * Report whether the given code is an integer number or not. + * @param code AST node to inspect. + * @return True if the given code is an integer, false otherwise. + */ + public static boolean isInteger(Code code) { + return isInteger(toText(code)); + } - /** If the initializer contains exactly one expression, return it. Otherwise, return null. */ - public static Expression asSingleExpr(Initializer init) { - if (init == null) { - return null; + /** + * Report whether the given expression is an integer number or not. + * @param expr AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(Expression expr) { + if (expr instanceof Literal) { + return isInteger(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isInteger((Code) expr); + } + return false; } - var exprs = init.getExprs(); - return exprs.size() == 1 ? exprs.get(0) : null; - } - public static boolean isSingleExpr(Initializer init) { - // todo expand that to = initialization - if (init == null) { - return false; + /** + * Report whether the given expression denotes a valid time or not. + * @param expr AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Expression expr) { + if (expr instanceof ParameterReference) { + return isOfTimeType(((ParameterReference)expr).getParameter()); + } else if (expr instanceof Time) { + return isValidTime((Time) expr); + } else if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; } - var exprs = init.getExprs(); - return exprs.size() == 1; - } - public static boolean isListInitializer(Initializer init) { - return init != null && !isSingleExpr(init); - } + /** + * Report whether the given time denotes a valid time or not. + * @param t AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Time t) { + if (t == null) return false; + String unit = t.getUnit(); + return t.getInterval() == 0 || + TimeUnit.isValidUnit(unit); + } - /** - * Return the type of a declaration with the given (nullable) explicit type, and the given - * (nullable) initializer. If the explicit type is null, then the type is inferred from the - * initializer. Only two types can be inferred: "time" and "timeList". Return the "undefined" type - * if neither can be inferred. - * - * @param type Explicit type declared on the declaration - * @param init The initializer expression - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Type type, Initializer init) { - if (type != null) { - return InferredType.fromAST(type); - } else if (init == null) { - return InferredType.undefined(); - } - - var single = asSingleExpr(init); - if (single != null) { - // If there is a single element in the list, and it is a proper - // time value with units, we infer the type "time". - if (single instanceof ParameterReference) { - return getInferredType(((ParameterReference) single).getParameter()); - } else if (single instanceof Time) { - return InferredType.time(); - } - } else if (init.getExprs().size() > 1) { - // If there are multiple elements in the list, and there is at - // least one proper time value with units, and all other elements - // are valid times (including zero without units), we infer the - // type "time list". - var allValidTime = true; - var foundNonZero = false; - - for (var e : init.getExprs()) { - if (!ASTUtils.isValidTime(e)) { - allValidTime = false; + /** + * If the initializer contains exactly one expression, + * return it. Otherwise, return null. + */ + public static Expression asSingleExpr(Initializer init) { + if (init == null) { + return null; } - if (!ASTUtils.isZero(e)) { - foundNonZero = true; - } - } + var exprs = init.getExprs(); + return exprs.size() == 1 ? exprs.get(0) : null; + } - if (allValidTime && foundNonZero) { - // Conservatively, no bounds are inferred; the returned type - // is a variable-size list. - return InferredType.timeList(); - } + public static boolean isSingleExpr(Initializer init) { + // todo expand that to = initialization + if (init == null) { + return false; + } + var exprs = init.getExprs(); + return exprs.size() == 1; } - return InferredType.undefined(); - } - /** - * Given a parameter, return an inferred type. Only two types can be inferred: "time" and - * "timeList". Return the "undefined" type if neither can be inferred. - * - * @param p A parameter to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Parameter p) { - return getInferredType(p.getType(), p.getInit()); - } + public static boolean isListInitializer(Initializer init) { + return init != null && !isSingleExpr(init); + } - /** - * Given a state variable, return an inferred type. Only two types can be inferred: "time" and - * "timeList". Return the "undefined" type if neither can be inferred. - * - * @param s A state variable to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(StateVar s) { - return getInferredType(s.getType(), s.getInit()); - } + /** + * Return the type of a declaration with the given + * (nullable) explicit type, and the given (nullable) + * initializer. If the explicit type is null, then the + * type is inferred from the initializer. Only two types + * can be inferred: "time" and "timeList". Return the + * "undefined" type if neither can be inferred. + * + * @param type Explicit type declared on the declaration + * @param init The initializer expression + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Type type, Initializer init) { + if (type != null) { + return InferredType.fromAST(type); + } else if (init == null) { + return InferredType.undefined(); + } - /** - * Construct an inferred type from an "action" AST node based on its declared type. If no type is - * declared, return the "undefined" type. - * - * @param a An action to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Action a) { - return getInferredType(a.getType(), null); - } + var single = asSingleExpr(init); + if (single != null) { + // If there is a single element in the list, and it is a proper + // time value with units, we infer the type "time". + if (single instanceof ParameterReference) { + return getInferredType(((ParameterReference) single).getParameter()); + } else if (single instanceof Time) { + return InferredType.time(); + } + } else if (init.getExprs().size() > 1) { + // If there are multiple elements in the list, and there is at + // least one proper time value with units, and all other elements + // are valid times (including zero without units), we infer the + // type "time list". + var allValidTime = true; + var foundNonZero = false; + + for (var e : init.getExprs()) { + if (!ASTUtils.isValidTime(e)) { + allValidTime = false; + } + if (!ASTUtils.isZero(e)) { + foundNonZero = true; + } + } - /** - * Construct an inferred type from a "port" AST node based on its declared type. If no type is - * declared, return the "undefined" type. - * - * @param p A port to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Port p) { - return getInferredType(p.getType(), null); - } + if (allValidTime && foundNonZero) { + // Conservatively, no bounds are inferred; the returned type + // is a variable-size list. + return InferredType.timeList(); + } + } + return InferredType.undefined(); + } - /** - * If the given string can be recognized as a floating-point number that has a leading decimal - * point, prepend the string with a zero and return it. Otherwise, return the original string. - * - * @param literal A string might be recognizable as a floating point number with a leading decimal - * point. - * @return an equivalent representation of literal - * - */ - public static String addZeroToLeadingDot(String literal) { - Matcher m = ABBREVIATED_FLOAT.matcher(literal); - if (m.matches()) { - return literal.replace(".", "0."); - } - return literal; - } + /** + * Given a parameter, return an inferred type. Only two types can be + * inferred: "time" and "timeList". Return the "undefined" type if + * neither can be inferred. + * + * @param p A parameter to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Parameter p) { + return getInferredType(p.getType(), p.getInit()); + } - /** - * Return true if the specified port is a multiport. - * - * @param port The port. - * @return True if the port is a multiport. - */ - public static boolean isMultiport(Port port) { - return port.getWidthSpec() != null; - } + /** + * Given a state variable, return an inferred type. Only two types can be + * inferred: "time" and "timeList". Return the "undefined" type if + * neither can be inferred. + * + * @param s A state variable to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(StateVar s) { + return getInferredType(s.getType(), s.getInit()); + } - //////////////////////////////// - //// Utility functions for translating AST nodes into text - // This is a continuation of a large section of ASTUtils.xtend - // with the same name. - - /** - * Generate code for referencing a port, action, or timer. - * - * @param reference The reference to the variable. - */ - public static String generateVarRef(VarRef reference) { - var prefix = ""; - if (reference.getContainer() != null) { - prefix = reference.getContainer().getName() + "."; - } - return prefix + reference.getVariable().getName(); - } + /** + * Construct an inferred type from an "action" AST node based + * on its declared type. If no type is declared, return the "undefined" + * type. + * + * @param a An action to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Action a) { + return getInferredType(a.getType(), null); + } - /** Assuming that the given expression denotes a valid time literal, return a time value. */ - public static TimeValue getLiteralTimeValue(Expression expr) { - if (expr instanceof Time) { - return toTimeValue((Time) expr); - } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { - return TimeValue.ZERO; - } else { - return null; + /** + * Construct an inferred type from a "port" AST node based on its declared + * type. If no type is declared, return the "undefined" type. + * + * @param p A port to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Port p) { + return getInferredType(p.getType(), null); } - } - /** If the parameter is of time type, return its default value. Otherwise, return null. */ - public static TimeValue getDefaultAsTimeValue(Parameter p) { - if (isOfTimeType(p)) { - var init = asSingleExpr(p.getInit()); - if (init != null) { - return getLiteralTimeValue(init); - } + + + /** + * If the given string can be recognized as a floating-point number that has a leading decimal point, + * prepend the string with a zero and return it. Otherwise, return the original string. + * + * @param literal A string might be recognizable as a floating point number with a leading decimal point. + * @return an equivalent representation of literal + * + */ + public static String addZeroToLeadingDot(String literal) { + Matcher m = ABBREVIATED_FLOAT.matcher(literal); + if (m.matches()) { + return literal.replace(".", "0."); + } + return literal; } - return null; - } - /** Return whether the given state variable is inferred to a time type. */ - public static boolean isOfTimeType(StateVar state) { - InferredType t = getInferredType(state); - return t.isTime && !t.isList; - } + /** + * Return true if the specified port is a multiport. + * @param port The port. + * @return True if the port is a multiport. + */ + public static boolean isMultiport(Port port) { + return port.getWidthSpec() != null; + } - /** Return whether the given parameter is inferred to a time type. */ - public static boolean isOfTimeType(Parameter param) { - InferredType t = getInferredType(param); - return t.isTime && !t.isList; - } + //////////////////////////////// + //// Utility functions for translating AST nodes into text + // This is a continuation of a large section of ASTUtils.xtend + // with the same name. + + /** + * Generate code for referencing a port, action, or timer. + * @param reference The reference to the variable. + */ + public static String generateVarRef(VarRef reference) { + var prefix = ""; + if (reference.getContainer() != null) { + prefix = reference.getContainer().getName() + "."; + } + return prefix + reference.getVariable().getName(); + } - /** - * Given a parameter, return its initial value. The initial value is a list of instances of - * Expressions. - * - *

If the instantiations argument is null or an empty list, then the value returned is simply - * the default value given when the parameter is defined. - * - *

If a list of instantiations is given, then the first instantiation is required to be an - * instantiation of the reactor class that is parameterized by the parameter. I.e., ``` - * parameter.eContainer == instantiations.get(0).reactorClass ``` If a second instantiation is - * given, then it is required to be an instantiation of a reactor class that contains the first - * instantiation. That is, ``` instantiations.get(0).eContainer == - * instantiations.get(1).reactorClass ``` More generally, for all 0 <= i < instantiations.size - - * 1, ``` instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass ``` If any of - * these conditions is not satisfied, then an IllegalArgumentException will be thrown. - * - *

Note that this chain of reactions cannot be inferred from the parameter because in each of - * the predicates above, there may be more than one instantiation that can appear on the right - * hand side of the predicate. - * - *

For example, consider the following program: ``` 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); } ``` Notice that there are a total of four instances of reactor class A. Then ``` - * initialValue(x, null) returns 1 initialValue(x, [a1]) returns 2 initialValue(x, [a2]) returns - * -1 initialValue(x, [a1, b1]) returns 3 initialValue(x, [a2, b1]) returns -1 initialValue(x, - * [a1, b2]) returns -2 initialValue(x, [a2, b2]) returns -1 ``` (Actually, in each of the above - * cases, the returned value is a list with one entry, a Literal, e.g. ["1"]). - * - *

There are two instances of reactor class B. ``` initialValue(y, null) returns 2 - * initialValue(y, [a1]) throws an IllegalArgumentException initialValue(y, [b1]) returns 3 - * initialValue(y, [b2]) returns -2 ``` - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * @return The value of the parameter. - * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the - * reactor class that is parameterized by the respective parameter or if the chain of - * instantiations is not nested. - */ - public static List initialValue( - Parameter parameter, List instantiations) { - // If instantiations are given, then check to see whether this parameter gets overridden in - // the first of those instantiations. - if (instantiations != null && instantiations.size() > 0) { - // Check to be sure that the instantiation is in fact an instantiation - // of the reactor class for which this is a parameter. - Instantiation instantiation = instantiations.get(0); - - if (!belongsTo(parameter, instantiation)) { - throw new IllegalArgumentException( - "Parameter " - + parameter.getName() - + " is not a parameter of reactor instance " - + instantiation.getName() - + "."); - } - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = null; - for (Assignment assignment : instantiation.getParameters()) { - if (assignment.getLhs().equals(parameter)) { - lastAssignment = assignment; + /** + * Assuming that the given expression denotes a valid time literal, + * return a time value. + */ + public static TimeValue getLiteralTimeValue(Expression expr) { + if (expr instanceof Time) { + return toTimeValue((Time)expr); + } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { + return TimeValue.ZERO; + } else { + return null; } - } - if (lastAssignment != null) { - // Right hand side can be a list. Collect the entries. - List result = new ArrayList<>(); - for (Expression expr : lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - if (instantiations.size() > 1 - && instantiation.eContainer() != instantiations.get(1).getReactorClass()) { - throw new IllegalArgumentException( - "Reactor instance " - + instantiation.getName() - + " is not contained by instance " - + instantiations.get(1).getName() - + "."); + } + + /** + * If the parameter is of time type, return its default value. + * Otherwise, return null. + */ + public static TimeValue getDefaultAsTimeValue(Parameter p) { + if (isOfTimeType(p)) { + var init = asSingleExpr(p.getInit()); + if (init != null) { + return getLiteralTimeValue(init); } - result.addAll( - initialValue( - ((ParameterReference) expr).getParameter(), - instantiations.subList(1, instantiations.size()))); - } else { - result.add(expr); - } } - return result; - } + return null; } - // If we reach here, then either no instantiation was supplied or - // there was no assignment in the instantiation. So just use the - // parameter's initial value. - return parameter.getInit().getExprs(); - } - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the - * specified instantiation, meaning that it is defined in the reactor class being instantiated or - * one of its base classes. - * - * @param eobject The object. - * @param instantiation The instantiation. - */ - public static boolean belongsTo(EObject eobject, Instantiation instantiation) { - Reactor reactor = toDefinition(instantiation.getReactorClass()); - return belongsTo(eobject, reactor); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the - * specified reactor, meaning that it is defined in reactor class or one of its base classes. - * - * @param eobject The object. - * @param reactor The reactor. - */ - public static boolean belongsTo(EObject eobject, Reactor reactor) { - if (eobject.eContainer() == reactor) return true; - for (ReactorDecl baseClass : reactor.getSuperClasses()) { - if (belongsTo(eobject, toDefinition(baseClass))) { - return true; - } + /** + * Return whether the given state variable is inferred + * to a time type. + */ + public static boolean isOfTimeType(StateVar state) { + InferredType t = getInferredType(state); + return t.isTime && !t.isList; } - return false; - } - /** - * Given a parameter return its integer value or null if it does not have an integer value. If the - * value of the parameter is a list of integers, return the sum of value in the list. The - * instantiations parameter is as in {@link #initialValue(Parameter, List)}. - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * @return The integer value of the parameter, or null if it does not have an integer value. - * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the - * reactor class that is parameterized by the respective parameter or if the chain of - * instantiations is not nested. - */ - public static Integer initialValueInt(Parameter parameter, List instantiations) { - List expressions = initialValue(parameter, instantiations); - int result = 0; - for (Expression expr : expressions) { - if (!(expr instanceof Literal)) { - return null; - } - try { - result += Integer.decode(((Literal) expr).getLiteral()); - } catch (NumberFormatException ex) { - return null; - } + /** + * Return whether the given parameter is inferred + * to a time type. + */ + public static boolean isOfTimeType(Parameter param) { + InferredType t = getInferredType(param); + return t.isTime && !t.isList; } - return result; - } - /** - * Given the width specification of port or instantiation and an (optional) list of nested - * instantiations, return the width if it can be determined and -1 if not. It will not be able to - * be determined if either the width is variable (in which case you should use {@link - * #inferPortWidth(VarRef, Connection, List)} ) or the list of instantiations is incomplete or - * missing. If there are parameter references in the width, they are evaluated to the extent - * possible given the instantiations list. - * - *

The instantiations list is as in {@link #initialValue(Parameter, List)}. If the spec belongs - * to an instantiation (for a bank of reactors), then the first element on this list should be the - * instantiation that contains this instantiation. If the spec belongs to a port, then the first - * element on the list should be the instantiation of the reactor that contains the port. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * @return The width, or -1 if the width could not be determined. - * @throws IllegalArgumentException If an instantiation provided is not as given above or if the - * chain of instantiations is not nested. - */ - public static int width(WidthSpec spec, List instantiations) { - if (spec == null) { - return 1; - } - if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { - return inferWidthFromConnections(spec, instantiations); - } - var result = 0; - for (WidthTerm term : spec.getTerms()) { - if (term.getParameter() != null) { - Integer termWidth = initialValueInt(term.getParameter(), instantiations); - if (termWidth != null) { - result += termWidth; - } else { - return -1; + /** + * Given a parameter, return its initial value. + * The initial value is a list of instances of Expressions. + * + * If the instantiations argument is null or an empty list, then the + * value returned is simply the default value given when the parameter + * is defined. + * + * If a list of instantiations is given, then the first instantiation + * is required to be an instantiation of the reactor class that is + * parameterized by the parameter. I.e., + * ``` + * parameter.eContainer == instantiations.get(0).reactorClass + * ``` + * If a second instantiation is given, then it is required to be an instantiation of a + * reactor class that contains the first instantiation. That is, + * ``` + * instantiations.get(0).eContainer == instantiations.get(1).reactorClass + * ``` + * More generally, for all 0 <= i < instantiations.size - 1, + * ``` + * instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass + * ``` + * If any of these conditions is not satisfied, then an IllegalArgumentException + * will be thrown. + * + * Note that this chain of reactions cannot be inferred from the parameter because + * in each of the predicates above, there may be more than one instantiation that + * can appear on the right hand side of the predicate. + * + * For example, consider the following program: + * ``` + * 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); + * } + * ``` + * Notice that there are a total of four instances of reactor class A. + * Then + * ``` + * initialValue(x, null) returns 1 + * initialValue(x, [a1]) returns 2 + * initialValue(x, [a2]) returns -1 + * initialValue(x, [a1, b1]) returns 3 + * initialValue(x, [a2, b1]) returns -1 + * initialValue(x, [a1, b2]) returns -2 + * initialValue(x, [a2, b2]) returns -1 + * ``` + * (Actually, in each of the above cases, the returned value is a list with + * one entry, a Literal, e.g. ["1"]). + * + * There are two instances of reactor class B. + * ``` + * initialValue(y, null) returns 2 + * initialValue(y, [a1]) throws an IllegalArgumentException + * initialValue(y, [b1]) returns 3 + * initialValue(y, [b2]) returns -2 + * ``` + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * + * @return The value of the parameter. + * + * @throws IllegalArgumentException If an instantiation provided is not an + * instantiation of the reactor class that is parameterized by the + * respective parameter or if the chain of instantiations is not nested. + */ + public static List initialValue(Parameter parameter, List instantiations) { + // If instantiations are given, then check to see whether this parameter gets overridden in + // the first of those instantiations. + if (instantiations != null && instantiations.size() > 0) { + // Check to be sure that the instantiation is in fact an instantiation + // of the reactor class for which this is a parameter. + Instantiation instantiation = instantiations.get(0); + + if (!belongsTo(parameter, instantiation)) { + throw new IllegalArgumentException("Parameter " + + parameter.getName() + + " is not a parameter of reactor instance " + + instantiation.getName() + + "." + ); + } + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = null; + for (Assignment assignment: instantiation.getParameters()) { + if (assignment.getLhs().equals(parameter)) { + lastAssignment = assignment; + } + } + if (lastAssignment != null) { + // Right hand side can be a list. Collect the entries. + List result = new ArrayList<>(); + for (Expression expr: lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + if (instantiations.size() > 1 + && instantiation.eContainer() != instantiations.get(1).getReactorClass() + ) { + throw new IllegalArgumentException("Reactor instance " + + instantiation.getName() + + " is not contained by instance " + + instantiations.get(1).getName() + + "." + ); + } + result.addAll(initialValue(((ParameterReference)expr).getParameter(), + instantiations.subList(1, instantiations.size()))); + } else { + result.add(expr); + } + } + return result; + } } - } else if (term.getWidth() > 0) { - result += term.getWidth(); - } else { - // If the width cannot be determined because term's width <= 0, which means the term's width - // must be inferred, try to infer the width using connections. - if (spec.eContainer() instanceof Instantiation) { - try { - return inferWidthFromConnections(spec, instantiations); - } catch (InvalidSourceException e) { - // If the inference fails, return -1. - return -1; - } + // If we reach here, then either no instantiation was supplied or + // there was no assignment in the instantiation. So just use the + // parameter's initial value. + return parameter.getInit().getExprs(); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) + * belongs to the specified instantiation, meaning that it is defined in + * the reactor class being instantiated or one of its base classes. + * @param eobject The object. + * @param instantiation The instantiation. + */ + public static boolean belongsTo(EObject eobject, Instantiation instantiation) { + Reactor reactor = toDefinition(instantiation.getReactorClass()); + return belongsTo(eobject, reactor); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) + * belongs to the specified reactor, meaning that it is defined in + * reactor class or one of its base classes. + * @param eobject The object. + * @param reactor The reactor. + */ + public static boolean belongsTo(EObject eobject, Reactor reactor) { + if (eobject.eContainer() == reactor) return true; + for (ReactorDecl baseClass : reactor.getSuperClasses()) { + if (belongsTo(eobject, toDefinition(baseClass))) { + return true; + } } - } + return false; } - return result; - } - /** - * Infer the width of a port reference in a connection. The port reference one or two parts, a - * port and an (optional) container which is an Instantiation that may refer to a bank of - * reactors. The width will be the product of the bank width and the port width. The returned - * value will be 1 if the port is not in a bank and is not a multiport. - * - *

If the width cannot be determined, this will return -1. The width cannot be determined if - * the list of instantiations is missing or incomplete. - * - *

The instantiations list is as in {@link #initialValue(Parameter, List)}. The first element - * on this list should be the instantiation that contains the specified connection. - * - * @param reference A port reference. - * @param connection A connection, or null if not in the context of a connection. - * @param instantiations The (optional) list of instantiations. - * @return The width or -1 if it could not be determined. - * @throws IllegalArgumentException If an instantiation provided is not as given above or if the - * chain of instantiations is not nested. - */ - public static int inferPortWidth( - VarRef reference, Connection connection, List instantiations) { - if (reference.getVariable() instanceof Port) { - // If the port is given as a.b, then we want to prepend a to - // the list of instantiations to determine the width of this port. - List extended = instantiations; - if (reference.getContainer() != null) { - extended = new ArrayList<>(); - extended.add(reference.getContainer()); - if (instantiations != null) { - extended.addAll(instantiations); + /** + * Given a parameter return its integer value or null + * if it does not have an integer value. + * If the value of the parameter is a list of integers, + * return the sum of value in the list. + * The instantiations parameter is as in + * {@link #initialValue(Parameter, List)}. + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * + * @return The integer value of the parameter, or null if it does not have an integer value. + * + * @throws IllegalArgumentException If an instantiation provided is not an + * instantiation of the reactor class that is parameterized by the + * respective parameter or if the chain of instantiations is not nested. + */ + public static Integer initialValueInt(Parameter parameter, List instantiations) { + List expressions = initialValue(parameter, instantiations); + int result = 0; + for (Expression expr: expressions) { + if (!(expr instanceof Literal)) { + return null; + } + try { + result += Integer.decode(((Literal) expr).getLiteral()); + } catch (NumberFormatException ex) { + return null; + } } - } + return result; + } - int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); - if (portWidth < 0) { - // Could not determine port width. - return -1; - } - - // Next determine the bank width. This may be unspecified, in which - // case it has to be inferred using the connection. - int bankWidth = 1; - if (reference.getContainer() != null) { - bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); - if (bankWidth < 0 && connection != null) { - // Try to infer the bank width from the connection. - if (reference.getContainer().getWidthSpec().isOfVariableLength()) { - // This occurs for a bank of delays. - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : connection.getLeftPorts()) { - if (leftPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException( - "Multiple ports with variable width on a connection."); + /** + * Given the width specification of port or instantiation + * and an (optional) list of nested instantiations, return + * the width if it can be determined and -1 if not. + * It will not be able to be determined if either the + * width is variable (in which case you should use + * {@link #inferPortWidth(VarRef, Connection, List)} ) + * or the list of instantiations is incomplete or missing. + * If there are parameter references in the width, they are + * evaluated to the extent possible given the instantiations list. + * + * The instantiations list is as in + * {@link #initialValue(Parameter, List)}. + * If the spec belongs to an instantiation (for a bank of reactors), + * then the first element on this list should be the instantiation + * that contains this instantiation. If the spec belongs to a port, + * then the first element on the list should be the instantiation + * of the reactor that contains the port. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * + * @return The width, or -1 if the width could not be determined. + * + * @throws IllegalArgumentException If an instantiation provided is not as + * given above or if the chain of instantiations is not nested. + */ + public static int width(WidthSpec spec, List instantiations) { + if (spec == null) { + return 1; + } + if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { + return inferWidthFromConnections(spec, instantiations); + } + var result = 0; + for (WidthTerm term: spec.getTerms()) { + if (term.getParameter() != null) { + Integer termWidth = initialValueInt(term.getParameter(), instantiations); + if (termWidth != null) { + result += termWidth; + } else { + return -1; } - // Indicate that this port is on the left. - leftOrRight = -1; - } else { - // The left port is not the same as this reference. - int otherWidth = inferPortWidth(leftPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; + } else if (term.getWidth() > 0) { + result += term.getWidth(); + } else { + // If the width cannot be determined because term's width <= 0, which means the term's width + // must be inferred, try to infer the width using connections. + if (spec.eContainer() instanceof Instantiation) { + try { + return inferWidthFromConnections(spec, instantiations); + } catch (InvalidSourceException e) { + // If the inference fails, return -1. + return -1; + } } - leftWidth += otherWidth; - } } - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException( - "Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the right. - leftOrRight = 1; - } else { - int otherWidth = inferPortWidth(rightPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; + } + return result; + } + + /** + * Infer the width of a port reference in a connection. + * The port reference one or two parts, a port and an (optional) container + * which is an Instantiation that may refer to a bank of reactors. + * The width will be the product of the bank width and the port width. + * The returned value will be 1 if the port is not in a bank and is not a multiport. + * + * If the width cannot be determined, this will return -1. + * The width cannot be determined if the list of instantiations is + * missing or incomplete. + * + * The instantiations list is as in + * {@link #initialValue(Parameter, List)}. + * The first element on this list should be the instantiation + * that contains the specified connection. + * + * @param reference A port reference. + * @param connection A connection, or null if not in the context of a connection. + * @param instantiations The (optional) list of instantiations. + * + * @return The width or -1 if it could not be determined. + * + * @throws IllegalArgumentException If an instantiation provided is not as + * given above or if the chain of instantiations is not nested. + */ + public static int inferPortWidth( + VarRef reference, Connection connection, List instantiations + ) { + if (reference.getVariable() instanceof Port) { + // If the port is given as a.b, then we want to prepend a to + // the list of instantiations to determine the width of this port. + List extended = instantiations; + if (reference.getContainer() != null) { + extended = new ArrayList<>(); + extended.add(reference.getContainer()); + if (instantiations != null) { + extended.addAll(instantiations); } - rightWidth += otherWidth; - } } - int discrepancy = 0; - if (leftOrRight < 0) { - // This port is on the left. - discrepancy = rightWidth - leftWidth; - } else if (leftOrRight > 0) { - // This port is on the right. - discrepancy = leftWidth - rightWidth; + + int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); + if (portWidth < 0) { + // Could not determine port width. + return -1; } - // Check that portWidth divides the discrepancy. - if (discrepancy % portWidth != 0) { - // This is an error. - return -1; + + // Next determine the bank width. This may be unspecified, in which + // case it has to be inferred using the connection. + int bankWidth = 1; + if (reference.getContainer() != null) { + bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); + if (bankWidth < 0 && connection != null) { + // Try to infer the bank width from the connection. + if (reference.getContainer().getWidthSpec().isOfVariableLength()) { + // This occurs for a bank of delays. + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : connection.getLeftPorts()) { + if (leftPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the left. + leftOrRight = -1; + } else { + // The left port is not the same as this reference. + int otherWidth = inferPortWidth(leftPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; + } + leftWidth += otherWidth; + } + } + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the right. + leftOrRight = 1; + } else { + int otherWidth = inferPortWidth(rightPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; + } + rightWidth += otherWidth; + } + } + int discrepancy = 0; + if (leftOrRight < 0) { + // This port is on the left. + discrepancy = rightWidth - leftWidth; + } else if (leftOrRight > 0) { + // This port is on the right. + discrepancy = leftWidth - rightWidth; + } + // Check that portWidth divides the discrepancy. + if (discrepancy % portWidth != 0) { + // This is an error. + return -1; + } + bankWidth = discrepancy / portWidth; + } else { + // Could not determine the bank width. + return -1; + } + } } - bankWidth = discrepancy / portWidth; - } else { - // Could not determine the bank width. - return -1; - } + return portWidth * bankWidth; } - } - return portWidth * bankWidth; + // Argument is not a port. + return -1; } - // Argument is not a port. - return -1; - } - /** - * Given an instantiation of a reactor or bank of reactors, return the width. This will be 1 if - * this is not a reactor bank. Otherwise, this will attempt to determine the width. If the width - * is declared as a literal constant, it will return that constant. If the width is specified as a - * reference to a parameter, this will throw an exception. If the width is variable, this will - * find connections in the enclosing reactor and attempt to infer the width. If the width cannot - * be determined, it will throw an exception. - * - *

IMPORTANT: This method should not be used you really need to determine the width! It will - * not evaluate parameter values. - * - * @see #width(WidthSpec, List) - * @param instantiation A reactor instantiation. - * @return The width, if it can be determined. - * @deprecated - */ - @Deprecated - public static int widthSpecification(Instantiation instantiation) { - int result = width(instantiation.getWidthSpec(), null); - if (result < 0) { - throw new InvalidSourceException( - "Cannot determine width for the instance " + instantiation.getName()); - } - return result; - } + /** + * Given an instantiation of a reactor or bank of reactors, return + * the width. This will be 1 if this is not a reactor bank. Otherwise, + * this will attempt to determine the width. If the width is declared + * as a literal constant, it will return that constant. If the width + * is specified as a reference to a parameter, this will throw an + * exception. If the width is variable, this will find + * connections in the enclosing reactor and attempt to infer the + * width. If the width cannot be determined, it will throw an exception. + * + * IMPORTANT: This method should not be used you really need to + * determine the width! It will not evaluate parameter values. + * @see #width(WidthSpec, List) + * + * @param instantiation A reactor instantiation. + * + * @return The width, if it can be determined. + * @deprecated + */ + @Deprecated + public static int widthSpecification(Instantiation instantiation) { + int result = width(instantiation.getWidthSpec(), null); + if (result < 0) { + throw new InvalidSourceException("Cannot determine width for the instance " + + instantiation.getName()); + } + return result; + } - /** - * Report whether a state variable has been initialized or not. - * - * @param v The state variable to be checked. - * @return True if the variable was initialized, false otherwise. - */ - public static boolean isInitialized(StateVar v) { - return v != null && v.getInit() != null; - } + /** + * Report whether a state variable has been initialized or not. + * @param v The state variable to be checked. + * @return True if the variable was initialized, false otherwise. + */ + public static boolean isInitialized(StateVar v) { + return v != null && v.getInit() != null; + } - /** - * Report whether the given time state variable is initialized using a parameter or not. - * - * @param s A state variable. - * @return True if the argument is initialized using a parameter, false otherwise. - */ - public static boolean isParameterized(StateVar s) { - return s.getInit() != null - && IterableExtensions.exists( - s.getInit().getExprs(), it -> it instanceof ParameterReference); - } + /** + * Report whether the given time state variable is initialized using a + * parameter or not. + * @param s A state variable. + * @return True if the argument is initialized using a parameter, false + * otherwise. + */ + public static boolean isParameterized(StateVar s) { + return s.getInit() != null && + IterableExtensions.exists(s.getInit().getExprs(), it -> it instanceof ParameterReference); + } - /** - * Check if the reactor class uses generics - * - * @param r the reactor to check - * @return true if the reactor uses generics - */ - public static boolean isGeneric(Reactor r) { - if (r == null) { - return false; - } - return r.getTypeParms().size() != 0; - } + /** + * Check if the reactor class uses generics + * @param r the reactor to check + * @return true if the reactor uses generics + */ + public static boolean isGeneric(Reactor r) { + if (r == null) { + return false; + } + return r.getTypeParms().size() != 0; + } - /** - * If the specified reactor declaration is an import, then return the imported reactor class - * definition. Otherwise, just return the argument. - * - * @param r A Reactor or an ImportedReactor. - * @return The Reactor class definition or null if no definition is found. - */ - public static Reactor toDefinition(ReactorDecl r) { - if (r == null) return null; - if (r instanceof Reactor) { - return (Reactor) r; - } else if (r instanceof ImportedReactor) { - return ((ImportedReactor) r).getReactorClass(); - } - return null; - } + /** + * If the specified reactor declaration is an import, then + * return the imported reactor class definition. Otherwise, + * just return the argument. + * @param r A Reactor or an ImportedReactor. + * @return The Reactor class definition or null if no definition is found. + */ + public static Reactor toDefinition(ReactorDecl r) { + if (r == null) + return null; + if (r instanceof Reactor) { + return (Reactor) r; + } else if (r instanceof ImportedReactor) { + return ((ImportedReactor) r).getReactorClass(); + } + return null; + } - /** Return all single-line or multi-line comments immediately preceding the given EObject. */ - public static Stream getPrecedingComments( - ICompositeNode compNode, Predicate filter) { - return getPrecedingCommentNodes(compNode, filter).map(INode::getText); - } + /** + * Return all single-line or multi-line comments immediately preceding the + * given EObject. + */ + public static Stream getPrecedingComments( + ICompositeNode compNode, + Predicate filter + ) { + return getPrecedingCommentNodes(compNode, filter).map(INode::getText); + } - /** Return all single-line or multi-line comments immediately preceding the given EObject. */ - public static Stream getPrecedingCommentNodes( - ICompositeNode compNode, Predicate filter) { - if (compNode == null) return Stream.of(); - List ret = new ArrayList<>(); - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode)) { - if (isComment(node)) { - if (filter.test(node)) ret.add(node); - } else if (!node.getText().isBlank()) { - break; + /** + * Return all single-line or multi-line comments immediately preceding the + * given EObject. + */ + public static Stream getPrecedingCommentNodes( + ICompositeNode compNode, + Predicate filter + ) { + if (compNode == null) return Stream.of(); + List ret = new ArrayList<>(); + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode)) { + if (isComment(node)) { + if (filter.test(node)) ret.add(node); + } else if (!node.getText().isBlank()) { + break; + } + } } - } + return ret.stream(); } - return ret.stream(); - } - /** Return whether {@code node} is a comment. */ - public static boolean isComment(INode node) { - return node instanceof HiddenLeafNode hlNode - && hlNode.getGrammarElement() instanceof TerminalRule tRule - && tRule.getName().endsWith("_COMMENT"); - } + /** Return whether {@code node} is a comment. */ + public static boolean isComment(INode node) { + return node instanceof HiddenLeafNode hlNode + && hlNode.getGrammarElement() instanceof TerminalRule tRule + && tRule.getName().endsWith("_COMMENT"); + } - /** Return true if the given node starts on the same line as the given other node. */ - public static Predicate sameLine(ICompositeNode compNode) { - return other -> { - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { - return node.getStartLine() == other.getStartLine(); - } - } - return false; - }; - } + /** + * Return true if the given node starts on the same line as the given other + * node. + */ + public static Predicate sameLine(ICompositeNode compNode) { + return other -> { + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { + return node.getStartLine() == other.getStartLine(); + } + } + return false; + }; + } - /** - * Find the main reactor and set its name if none was defined. - * - * @param resource The resource to find the main reactor in. - */ - public static void setMainName(Resource resource, String name) { - Reactor main = - IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), - it -> it.isMain() || it.isFederated()); - if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { - main.setName(name); + /** + * Find the main reactor and set its name if none was defined. + * @param resource The resource to find the main reactor in. + */ + public static void setMainName(Resource resource, String name) { + Reactor main = IteratorExtensions.findFirst(Iterators.filter(resource.getAllContents(), Reactor.class), + it -> it.isMain() || it.isFederated() + ); + if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { + main.setName(name); + } } - } - /** - * Create a new instantiation node with the given reactor as its defining class. - * - * @param reactor The reactor class to create an instantiation of. - */ - public static Instantiation createInstantiation(Reactor reactor) { - Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); - inst.setReactorClass(reactor); - // If the reactor is federated or at the top level, then it - // may not have a name. In the generator's doGenerate() - // method, the name gets set using setMainName(). - // But this may be called before that, e.g. during - // diagram synthesis. We assign a temporary name here. - if (reactor.getName() == null) { - if (reactor.isFederated() || reactor.isMain()) { - inst.setName("main"); - } else { - inst.setName(""); - } - - } else { - inst.setName(reactor.getName()); - } - return inst; - } + /** + * Create a new instantiation node with the given reactor as its defining class. + * @param reactor The reactor class to create an instantiation of. + */ + public static Instantiation createInstantiation(Reactor reactor) { + Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); + inst.setReactorClass(reactor); + // If the reactor is federated or at the top level, then it + // may not have a name. In the generator's doGenerate() + // method, the name gets set using setMainName(). + // But this may be called before that, e.g. during + // diagram synthesis. We assign a temporary name here. + if (reactor.getName() == null) { + if (reactor.isFederated() || reactor.isMain()) { + inst.setName("main"); + } else { + inst.setName(""); + } - /** - * Returns the target declaration in the given model. Non-null because it would cause a parse - * error. - */ - public static TargetDecl targetDecl(Model model) { - return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); - } + } else { + inst.setName(reactor.getName()); + } + return inst; + } - /** - * Returns the target declaration in the given resource. Non-null because it would cause a parse - * error. - */ - public static TargetDecl targetDecl(Resource model) { - return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); - } + /** + * Returns the target declaration in the given model. + * Non-null because it would cause a parse error. + */ + public static TargetDecl targetDecl(Model model) { + return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); + } - ///////////////////////////////////////////////////////// - //// Private methods + /** + * Returns the target declaration in the given resource. + * Non-null because it would cause a parse error. + */ + public static TargetDecl targetDecl(Resource model) { + return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); + } - /** Returns the list if it is not null. Otherwise, return an empty list. */ - public static List convertToEmptyListIfNull(List list) { - return list != null ? list : new ArrayList<>(); - } + ///////////////////////////////////////////////////////// + //// Private methods - /** - * Return all the superclasses of the specified reactor in deepest-first order. For example, if A - * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates - * are removed. If the specified reactor does not extend any other reactor, then return an empty - * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared - * that is not found, then return null. - * - * @param reactor The specified reactor. - * @param extensions A set of reactors extending the specified reactor (used to detect circular - * extensions). - */ - private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { - LinkedHashSet result = new LinkedHashSet<>(); - for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { - Reactor r = toDefinition(superDecl); - if (r == reactor || r == null) return null; - // If r is in the extensions, then we have a circular inheritance structure. - if (extensions.contains(r)) return null; - extensions.add(r); - LinkedHashSet baseExtends = superClasses(r, extensions); - extensions.remove(r); - if (baseExtends == null) return null; - result.addAll(baseExtends); - result.add(r); - } - return result; - } + /** + * Returns the list if it is not null. Otherwise, return an empty list. + */ + public static List convertToEmptyListIfNull(List list) { + return list != null ? list : new ArrayList<>(); + } - /** - * We may be able to infer the width by examining the connections of the enclosing reactor - * definition. This works, for example, with delays between multiports or banks of reactors. - * Attempt to infer the width from connections and return -1 if the width cannot be inferred. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * @return The width, or -1 if the width could not be inferred from connections. - */ - private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { - for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : c.getLeftPorts()) { - if (leftPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the left. - leftOrRight = -1; - } else { - leftWidth += inferPortWidth(leftPort, c, instantiations); + /** + * Return all the superclasses of the specified reactor + * in deepest-first order. For example, if A extends B and C, and + * B and C both extend D, this will return the list [D, B, C, A]. + * Duplicates are removed. If the specified reactor does not extend + * any other reactor, then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor + * (used to detect circular extensions). + */ + private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet baseExtends = superClasses(r, extensions); + extensions.remove(r); + if (baseExtends == null) return null; + result.addAll(baseExtends); + result.add(r); } - } - for (VarRef rightPort : c.getRightPorts()) { - if (rightPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the right. - leftOrRight = 1; - } else { - rightWidth += inferPortWidth(rightPort, c, instantiations); + return result; + } + + /** + * We may be able to infer the width by examining the connections of + * the enclosing reactor definition. This works, for example, with + * delays between multiports or banks of reactors. + * Attempt to infer the width from connections and return -1 if the width cannot be inferred. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * + * @return The width, or -1 if the width could not be inferred from connections. + */ + private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { + for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : c.getLeftPorts()) { + if (leftPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the left. + leftOrRight = -1; + } else { + leftWidth += inferPortWidth(leftPort, c, instantiations); + } + } + for (VarRef rightPort : c.getRightPorts()) { + if (rightPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the right. + leftOrRight = 1; + } else { + rightWidth += inferPortWidth(rightPort, c, instantiations); + } + } + if (leftOrRight < 0) { + return rightWidth - leftWidth; + } else if (leftOrRight > 0) { + return leftWidth - rightWidth; + } } - } - if (leftOrRight < 0) { - return rightWidth - leftWidth; - } else if (leftOrRight > 0) { - return leftWidth - rightWidth; - } - } - // A connection was not found with the instantiation. - return -1; - } + // A connection was not found with the instantiation. + return -1; + } - public static void addReactionAttribute(Reaction reaction, String name) { - var fedAttr = factory.createAttribute(); - fedAttr.setAttrName(name); - reaction.getAttributes().add(fedAttr); - } -} + public static void addReactionAttribute(Reaction reaction, String name) { + var fedAttr = factory.createAttribute(); + fedAttr.setAttrName(name); + reaction.getAttributes().add(fedAttr); + } +} \ No newline at end of file diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index bfd89bdc14..e344e9f873 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1110,7 +1110,7 @@ private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeB generateAuxiliaryStructs(header, reactor, false); generateSelfStruct(header, reactor, constructorCode); generateMethods(src, reactor); - generateWatchdogs(reactor); + generateWatchdogs(src, reactor); generateReactions(src, reactor); generateConstructor(src, header, reactor, constructorCode); } @@ -1469,10 +1469,10 @@ protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, i * federated or not the main reactor and reactions should be * unconditionally generated. */ - public void generateWatchdogs(ReactorDecl decl) { + public void generateWatchdogs(CodeBuilder src, ReactorDecl decl) { var reactor = ASTUtils.toDefinition(decl); for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - generateWatchdog(watchdog, decl); + generateWatchdog(src, watchdog, decl); } } @@ -1483,8 +1483,8 @@ public void generateWatchdogs(ReactorDecl decl) { * @param watchdog The watchdog. * @param decl The reactor. */ - protected void generateWatchdog(Watchdog watchdog, ReactorDecl decl) { - code.pr(CWatchdogGenerator.generateWatchdog( + protected void generateWatchdog(CodeBuilder src, Watchdog watchdog, ReactorDecl decl) { + src.pr(CWatchdogGenerator.generateWatchdog( watchdog, decl )); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index f2f9630bea..67a76eb0e2 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1191,7 +1191,7 @@ public static String generateStpFunctionHeader(Reactor r, return generateFunctionHeader(functionName); } - private static String generateFunctionHeader(String functionName) { + public static String generateFunctionHeader(String functionName) { return "void " + functionName + "(void* instance_args)"; } } \ No newline at end of file diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 6ad7f405eb..621077de86 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -1,6 +1,7 @@ package org.lflang.generator.c; import java.util.List; + import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Mode; @@ -34,7 +35,7 @@ public static String generateInitializationForWatchdog(Watchdog watchdog, Reacto CodeBuilder code = new CodeBuilder(); // Define the "self" struct. - String structType = CUtil.selfType(decl); + String structType = CUtil.selfType(reactor); // A null structType means there are no inputs, state, // or anything else. No need to declare it. if (structType != null) { diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index 16d6723f7f..5d2c87b724 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -6,7 +6,8 @@ * @author Edward A. Lee */ target C { - timeout: 1100 ms + timeout: 1100 ms, + fast: false } reactor Watcher(timeout: time = 150 ms) { @@ -18,6 +19,7 @@ reactor Watcher(timeout: time = 150 ms) { watchdog poodle(timeout) {= instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); lf_print("Watchdog timed out! Lag: %lld (too late by " PRINTF_TIME " ns)", p, p - self->timeout); + lf_print("At logical time inside watchdog panic: " PRINTF_TIME, lf_time_logical_elapsed()); self->count++; =} From 3b8e0f7007f0e69c5238df6ee97ad7f57fe910ce Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Thu, 20 Apr 2023 14:02:08 -0700 Subject: [PATCH 145/709] removed fake python test --- org.lflang/src/org/lflang/ASTUtils.java | 3103 +++++++------- org.lflang/src/org/lflang/ast/IsEqual.java | 28 +- .../org/lflang/generator/ReactorInstance.java | 831 ++-- .../org/lflang/generator/c/CGenerator.java | 3815 ++++++++--------- .../generator/c/CReactionGenerator.java | 2346 +++++----- .../generator/c/CWatchdogGenerator.java | 1 - .../generator/python/PythonGenerator.java | 1083 +++-- .../org/lflang/validation/LFValidator.java | 3291 +++++++------- test/Python/src/PyWatchdog.lf | 66 - 9 files changed, 7309 insertions(+), 7255 deletions(-) delete mode 100644 test/Python/src/PyWatchdog.lf diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 9c3003007e..4606b4d35f 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -21,6 +21,9 @@ package org.lflang; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -28,7 +31,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -36,7 +38,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -57,8 +58,6 @@ import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Assignment; -import org.lflang.lf.AttrParm; -import org.lflang.lf.Attribute; import org.lflang.lf.Code; import org.lflang.lf.Connection; import org.lflang.lf.Element; @@ -92,1740 +91,1662 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; - /** * A helper class for modifying and analyzing the AST. + * * @author Marten Lohstroh * @author Edward A. Lee * @author Christian Menard */ public class ASTUtils { - /** - * The Lingua Franca factory for creating new AST nodes. - */ - public static final LfFactory factory = LfFactory.eINSTANCE; - - /** - * The Lingua Franca feature package. - */ - public static final LfPackage featurePackage = LfPackage.eINSTANCE; - - /* Match an abbreviated form of a float literal. */ - private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); - - /** - * A mapping from Reactor features to corresponding Mode features for collecting contained elements. - */ - private static final Map reactorModeFeatureMap = Map.of( - featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), - featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), - featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), - featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), - featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), - featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), - featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs() - ); - - - /** - * Get all reactors defined in the given resource. - * @param resource the resource to extract reactors from - * @return An iterable over all reactors found in the resource - */ - public static List getAllReactors(Resource resource) { - return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) - .filter(Reactor.class::isInstance) - .map(Reactor.class::cast) - .collect(Collectors.toList()); - } - - /** - * Find connections in the given resource that would be conflicting writes if they were not located in mutually - * exclusive modes. - * - * @param resource The AST. - * @return a list of connections being able to be transformed - */ - public static Collection findConflictingConnectionsInModalReactors(Resource resource) { - var transform = new HashSet(); - - for (Reactor reactor : getAllReactors(resource)) { - if (!reactor.getModes().isEmpty()) { // Only for modal reactors - var allWriters = HashMultimap., EObject>create(); - - // Collect destinations - for (var rea : allReactions(reactor)) { - for (var eff : rea.getEffects()) { - if (eff.getVariable() instanceof Port) { - allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); - } - } - } - for (var con : ASTUtils.collectElements(reactor, featurePackage.getReactor_Connections(), false, true)) { - for (var port : con.getRightPorts()) { - allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); - } - } + /** The Lingua Franca factory for creating new AST nodes. */ + public static final LfFactory factory = LfFactory.eINSTANCE; + + /** The Lingua Franca feature package. */ + public static final LfPackage featurePackage = LfPackage.eINSTANCE; + + /* Match an abbreviated form of a float literal. */ + private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); + + /** + * A mapping from Reactor features to corresponding Mode features for collecting contained + * elements. + */ + private static final Map reactorModeFeatureMap = + Map.of( + featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), + featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), + featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), + featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), + featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), + featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), + featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs()); + + /** + * Get all reactors defined in the given resource. + * + * @param resource the resource to extract reactors from + * @return An iterable over all reactors found in the resource + */ + public static List getAllReactors(Resource resource) { + return StreamSupport.stream( + IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) + .filter(Reactor.class::isInstance) + .map(Reactor.class::cast) + .collect(Collectors.toList()); + } - // Handle conflicting writers - for (var key : allWriters.keySet()) { - var writers = allWriters.get(key); - if (writers.size() > 1) { // has multiple sources - var writerModes = HashMultimap.create(); - // find modes - for (var writer : writers) { - if (writer.eContainer() instanceof Mode) { - writerModes.put((Mode) writer.eContainer(), writer); - } else { - writerModes.put(null, writer); - } - } - // Conflicting connection can only be handled if.. - if (!writerModes.containsKey(null) && // no writer is on root level (outside of modes) and... - writerModes.keySet().stream().map(writerModes::get).allMatch(writersInMode -> // all writers in a mode are either... - writersInMode.size() == 1 || // the only writer or... - writersInMode.stream().allMatch(w -> w instanceof Reaction) // all are reactions and hence ordered - )) { - // Add connections to transform list - writers.stream().filter(w -> w instanceof Connection).forEach(c -> transform.add((Connection) c)); - } - } - } + /** + * Find connections in the given resource that would be conflicting writes if they were not + * located in mutually exclusive modes. + * + * @param resource The AST. + * @return a list of connections being able to be transformed + */ + public static Collection findConflictingConnectionsInModalReactors( + Resource resource) { + var transform = new HashSet(); + + for (Reactor reactor : getAllReactors(resource)) { + if (!reactor.getModes().isEmpty()) { // Only for modal reactors + var allWriters = HashMultimap., EObject>create(); + + // Collect destinations + for (var rea : allReactions(reactor)) { + for (var eff : rea.getEffects()) { + if (eff.getVariable() instanceof Port) { + allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); } + } + } + for (var con : + ASTUtils.collectElements( + reactor, featurePackage.getReactor_Connections(), false, true)) { + for (var port : con.getRightPorts()) { + allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); + } } - return transform; - } - - /** - * Return the enclosing reactor of an LF EObject in a reactor or mode. - * @param obj the LF model element - * @return the reactor or null - */ - public static Reactor getEnclosingReactor(EObject obj) { - if (obj.eContainer() instanceof Reactor) { - return (Reactor) obj.eContainer(); - } else if (obj.eContainer() instanceof Mode) { - return (Reactor) obj.eContainer().eContainer(); + // Handle conflicting writers + for (var key : allWriters.keySet()) { + var writers = allWriters.get(key); + if (writers.size() > 1) { // has multiple sources + var writerModes = HashMultimap.create(); + // find modes + for (var writer : writers) { + if (writer.eContainer() instanceof Mode) { + writerModes.put((Mode) writer.eContainer(), writer); + } else { + writerModes.put(null, writer); + } + } + // Conflicting connection can only be handled if.. + if (!writerModes.containsKey(null) + && // no writer is on root level (outside of modes) and... + writerModes.keySet().stream() + .map(writerModes::get) + .allMatch( + writersInMode -> // all writers in a mode are either... + writersInMode.size() == 1 + || // the only writer or... + writersInMode.stream() + .allMatch( + w -> + w + instanceof + Reaction) // all are reactions and hence ordered + )) { + // Add connections to transform list + writers.stream() + .filter(w -> w instanceof Connection) + .forEach(c -> transform.add((Connection) c)); + } + } } - return null; + } } - /** - * Return the main reactor in the given resource if there is one, null otherwise. - */ - public static Reactor findMainReactor(Resource resource) { - return IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), - Reactor::isMain - ); - } + return transform; + } - /** - * Find the main reactor and change it to a federated reactor. - * Return true if the transformation was successful (or the given resource - * already had a federated reactor); return false otherwise. - */ - public static boolean makeFederated(Resource resource) { - // Find the main reactor - Reactor r = findMainReactor(resource); - if (r == null) { - return false; - } - r.setMain(false); - r.setFederated(true); - return true; - } + /** + * Return the enclosing reactor of an LF EObject in a reactor or mode. + * + * @param obj the LF model element + * @return the reactor or null + */ + public static Reactor getEnclosingReactor(EObject obj) { + if (obj.eContainer() instanceof Reactor) { + return (Reactor) obj.eContainer(); + } else if (obj.eContainer() instanceof Mode) { + return (Reactor) obj.eContainer().eContainer(); + } + return null; + } - /** - * Change the target name to 'newTargetName'. - * For example, change C to CCpp. - */ - public static boolean changeTargetName(Resource resource, String newTargetName) { - targetDecl(resource).setName(newTargetName); - return true; - } + /** Return the main reactor in the given resource if there is one, null otherwise. */ + public static Reactor findMainReactor(Resource resource) { + return IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), Reactor::isMain); + } - /** - * Return the target of the file in which the given node lives. - */ - public static Target getTarget(EObject object) { - TargetDecl targetDecl = targetDecl(object.eResource()); - return Target.fromDecl(targetDecl); - } + /** + * Find the main reactor and change it to a federated reactor. Return true if the transformation + * was successful (or the given resource already had a federated reactor); return false otherwise. + */ + public static boolean makeFederated(Resource resource) { + // Find the main reactor + Reactor r = findMainReactor(resource); + if (r == null) { + return false; + } + r.setMain(false); + r.setFederated(true); + return true; + } - /** - * Add a new target property to the given resource. - * - * This also creates a config object if the resource does not yey have one. - * - * @param resource The resource to modify - * @param name Name of the property to add - * @param value Value to be assigned to the property - */ - public static boolean addTargetProperty(final Resource resource, final String name, final Element value) { - var config = targetDecl(resource).getConfig(); - if (config == null) { - config = LfFactory.eINSTANCE.createKeyValuePairs(); - targetDecl(resource).setConfig(config); - } - final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); - newProperty.setName(name); - newProperty.setValue(value); - config.getPairs().add(newProperty); - return true; - } + /** Change the target name to 'newTargetName'. For example, change C to CCpp. */ + public static boolean changeTargetName(Resource resource, String newTargetName) { + targetDecl(resource).setName(newTargetName); + return true; + } - /** - * Return true if the connection involves multiple ports on the left or right side of the connection, or - * if the port on the left or right of the connection involves a bank of reactors or a multiport. - * @param connection The connection. - */ - public static boolean hasMultipleConnections(Connection connection) { - if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { - return true; - } - VarRef leftPort = connection.getLeftPorts().get(0); - VarRef rightPort = connection.getRightPorts().get(0); - Instantiation leftContainer = leftPort.getContainer(); - Instantiation rightContainer = rightPort.getContainer(); - Port leftPortAsPort = (Port) leftPort.getVariable(); - Port rightPortAsPort = (Port) rightPort.getVariable(); - return leftPortAsPort.getWidthSpec() != null - || leftContainer != null && leftContainer.getWidthSpec() != null - || rightPortAsPort.getWidthSpec() != null - || rightContainer != null && rightContainer.getWidthSpec() != null; - } + /** Return the target of the file in which the given node lives. */ + public static Target getTarget(EObject object) { + TargetDecl targetDecl = targetDecl(object.eResource()); + return Target.fromDecl(targetDecl); + } - /** - * Produce a unique identifier within a reactor based on a - * given based name. If the name does not exists, it is returned; - * if does exist, an index is appended that makes the name unique. - * @param reactor The reactor to find a unique identifier within. - * @param name The name to base the returned identifier on. - */ - public static String getUniqueIdentifier(Reactor reactor, String name) { - LinkedHashSet vars = new LinkedHashSet<>(); - allActions(reactor).forEach(it -> vars.add(it.getName())); - allTimers(reactor).forEach(it -> vars.add(it.getName())); - allParameters(reactor).forEach(it -> vars.add(it.getName())); - allInputs(reactor).forEach(it -> vars.add(it.getName())); - allOutputs(reactor).forEach(it -> vars.add(it.getName())); - allStateVars(reactor).forEach(it -> vars.add(it.getName())); - allInstantiations(reactor).forEach(it -> vars.add(it.getName())); - - int index = 0; - String suffix = ""; - boolean exists = true; - while (exists) { - String id = name + suffix; - if (IterableExtensions.exists(vars, it -> it.equals(id))) { - suffix = "_" + index; - index++; - } else { - exists = false; - } - } - return name + suffix; - } + /** + * Add a new target property to the given resource. + * + *

This also creates a config object if the resource does not yey have one. + * + * @param resource The resource to modify + * @param name Name of the property to add + * @param value Value to be assigned to the property + */ + public static boolean addTargetProperty( + final Resource resource, final String name, final Element value) { + var config = targetDecl(resource).getConfig(); + if (config == null) { + config = LfFactory.eINSTANCE.createKeyValuePairs(); + targetDecl(resource).setConfig(config); + } + final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); + newProperty.setName(name); + newProperty.setValue(value); + config.getPairs().add(newProperty); + return true; + } - //////////////////////////////// - //// Utility functions for supporting inheritance and modes - - /** - * Given a reactor class, return a list of all its actions, - * which includes actions of base classes that it extends. - * This also includes actions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allActions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); - } + /** + * Return true if the connection involves multiple ports on the left or right side of the + * connection, or if the port on the left or right of the connection involves a bank of reactors + * or a multiport. + * + * @param connection The connection. + */ + public static boolean hasMultipleConnections(Connection connection) { + if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { + return true; + } + VarRef leftPort = connection.getLeftPorts().get(0); + VarRef rightPort = connection.getRightPorts().get(0); + Instantiation leftContainer = leftPort.getContainer(); + Instantiation rightContainer = rightPort.getContainer(); + Port leftPortAsPort = (Port) leftPort.getVariable(); + Port rightPortAsPort = (Port) rightPort.getVariable(); + return leftPortAsPort.getWidthSpec() != null + || leftContainer != null && leftContainer.getWidthSpec() != null + || rightPortAsPort.getWidthSpec() != null + || rightContainer != null && rightContainer.getWidthSpec() != null; + } - /** - * Given a reactor class, return a list of all its connections, - * which includes connections of base classes that it extends. - * This also includes connections in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allConnections(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); - } + /** + * Produce a unique identifier within a reactor based on a given based name. If the name does not + * exists, it is returned; if does exist, an index is appended that makes the name unique. + * + * @param reactor The reactor to find a unique identifier within. + * @param name The name to base the returned identifier on. + */ + public static String getUniqueIdentifier(Reactor reactor, String name) { + LinkedHashSet vars = new LinkedHashSet<>(); + allActions(reactor).forEach(it -> vars.add(it.getName())); + allTimers(reactor).forEach(it -> vars.add(it.getName())); + allParameters(reactor).forEach(it -> vars.add(it.getName())); + allInputs(reactor).forEach(it -> vars.add(it.getName())); + allOutputs(reactor).forEach(it -> vars.add(it.getName())); + allStateVars(reactor).forEach(it -> vars.add(it.getName())); + allInstantiations(reactor).forEach(it -> vars.add(it.getName())); + + int index = 0; + String suffix = ""; + boolean exists = true; + while (exists) { + String id = name + suffix; + if (IterableExtensions.exists(vars, it -> it.equals(id))) { + suffix = "_" + index; + index++; + } else { + exists = false; + } + } + return name + suffix; + } - /** - * Given a reactor class, return a list of all its inputs, - * which includes inputs of base classes that it extends. - * If the base classes include a cycle, where X extends Y and Y extends X, - * then return only the input defined in the base class. - * The returned list may be empty. - * @param definition Reactor class definition. - */ - public static List allInputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); - } + //////////////////////////////// + //// Utility functions for supporting inheritance and modes + + /** + * Given a reactor class, return a list of all its actions, which includes actions of base classes + * that it extends. This also includes actions in modes, returning a flattened view over all + * modes. + * + * @param definition Reactor class definition. + */ + public static List allActions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); + } - /** A list of all ports of {@code definition}, in an unspecified order. */ - public static List allPorts(Reactor definition) { - return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); - } + /** + * Given a reactor class, return a list of all its connections, which includes connections of base + * classes that it extends. This also includes connections in modes, returning a flattened view + * over all modes. + * + * @param definition Reactor class definition. + */ + public static List allConnections(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); + } - /** - * Given a reactor class, return a list of all its instantiations, - * which includes instantiations of base classes that it extends. - * This also includes instantiations in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allInstantiations(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); - } + /** + * Given a reactor class, return a list of all its inputs, which includes inputs of base classes + * that it extends. If the base classes include a cycle, where X extends Y and Y extends X, then + * return only the input defined in the base class. The returned list may be empty. + * + * @param definition Reactor class definition. + */ + public static List allInputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); + } - public static Stream allNestedClasses(Reactor definition) { - return new HashSet<>(ASTUtils.allInstantiations(definition)).stream() - .map(Instantiation::getReactorClass) - .map(ASTUtils::toDefinition); - } + /** A list of all ports of {@code definition}, in an unspecified order. */ + public static List allPorts(Reactor definition) { + return Stream.concat( + ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()) + .toList(); + } - /** - * Given a reactor class, return a list of all its methods, - * which includes methods of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allMethods(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); - } + /** + * Given a reactor class, return a list of all its instantiations, which includes instantiations + * of base classes that it extends. This also includes instantiations in modes, returning a + * flattened view over all modes. + * + * @param definition Reactor class definition. + */ + public static List allInstantiations(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); + } - /** - * Given a reactor class, return a list of all its outputs, - * which includes outputs of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allOutputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); - } + public static Stream allNestedClasses(Reactor definition) { + return new HashSet<>(ASTUtils.allInstantiations(definition)) + .stream().map(Instantiation::getReactorClass).map(ASTUtils::toDefinition); + } - /** - * Given a reactor class, return a list of all its parameters, - * which includes parameters of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allParameters(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); - } + /** + * Given a reactor class, return a list of all its methods, which includes methods of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allMethods(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); + } - /** - * Given a reactor class, return a list of all its reactions, - * which includes reactions of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allReactions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); - } + /** + * Given a reactor class, return a list of all its outputs, which includes outputs of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allOutputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); + } - /** - * Given a reactor class, return a list of all its watchdogs. - * @param definition Reactor class definition - * @return List - */ - public static List allWatchdogs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); - } - - /** - * Given a reactor class, return a list of all its state variables, - * which includes state variables of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allStateVars(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); - } + /** + * Given a reactor class, return a list of all its parameters, which includes parameters of base + * classes that it extends. + * + * @param definition Reactor class definition. + */ + public static List allParameters(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); + } - /** - * Given a reactor class, return a list of all its timers, - * which includes timers of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allTimers(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); - } + /** + * Given a reactor class, return a list of all its reactions, which includes reactions of base + * classes that it extends. This also includes reactions in modes, returning a flattened view over + * all modes. + * + * @param definition Reactor class definition. + */ + public static List allReactions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); + } - /** - * Given a reactor class, returns a list of all its modes, - * which includes modes of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allModes(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); - } + /** + * Given a reactor class, return a list of all its watchdogs. + * + * @param definition Reactor class definition + * @return List + */ + public static List allWatchdogs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); + } - /** A list of all reactors instantiated, transitively or intransitively, by {@code r}. */ - public static List recursiveChildren(ReactorInstance r) { - List ret = new ArrayList<>(); - ret.add(r.reactorDefinition); - for (var child: r.children) { - ret.addAll(recursiveChildren(child)); - } - return ret; - } + /** + * Given a reactor class, return a list of all its state variables, which includes state variables + * of base classes that it extends. This also includes reactions in modes, returning a flattened + * view over all modes. + * + * @param definition Reactor class definition. + */ + public static List allStateVars(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); + } - /** - * Return all the superclasses of the specified reactor - * in deepest-first order. For example, if A extends B and C, and - * B and C both extend D, this will return the list [D, B, C, A]. - * Duplicates are removed. If the specified reactor does not extend - * any other reactor, then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - */ - public static LinkedHashSet superClasses(Reactor reactor) { - return superClasses(reactor, new LinkedHashSet<>()); - } + /** + * Given a reactor class, return a list of all its timers, which includes timers of base classes + * that it extends. This also includes reactions in modes, returning a flattened view over all + * modes. + * + * @param definition Reactor class definition. + */ + public static List allTimers(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); + } - /** - * Collect elements of type T from the class hierarchy and modes - * defined by a given reactor definition. - * @param definition The reactor definition. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - public static List collectElements(Reactor definition, EStructuralFeature feature) { - return ASTUtils.collectElements(definition, feature, true, true); + /** + * Given a reactor class, returns a list of all its modes, which includes modes of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allModes(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); + } + + /** A list of all reactors instantiated, transitively or intransitively, by {@code r}. */ + public static List recursiveChildren(ReactorInstance r) { + List ret = new ArrayList<>(); + ret.add(r.reactorDefinition); + for (var child : r.children) { + ret.addAll(recursiveChildren(child)); } + return ret; + } - /** - * Collect elements of type T contained in given reactor definition, including - * modes and the class hierarchy defined depending on configuration. - * @param definition The reactor definition. - * @param feature The structual model elements to collect. - * @param includeSuperClasses Whether to include elements in super classes. - * @param includeModes Whether to include elements in modes. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - @SuppressWarnings("unchecked") - public static List collectElements(Reactor definition, EStructuralFeature feature, boolean includeSuperClasses, boolean includeModes) { - List result = new ArrayList<>(); - - if (includeSuperClasses) { - // Add elements of elements defined in superclasses. - LinkedHashSet s = superClasses(definition); - if (s != null) { - for (Reactor superClass : s) { - result.addAll((EList) superClass.eGet(feature)); - } - } - } + /** + * Return all the superclasses of the specified reactor in deepest-first order. For example, if A + * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates + * are removed. If the specified reactor does not extend any other reactor, then return an empty + * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared + * that is not found, then return null. + * + * @param reactor The specified reactor. + */ + public static LinkedHashSet superClasses(Reactor reactor) { + return superClasses(reactor, new LinkedHashSet<>()); + } - // Add elements of the current reactor. - result.addAll((EList) definition.eGet(feature)); + /** + * Collect elements of type T from the class hierarchy and modes defined by a given reactor + * definition. + * + * @param definition The reactor definition. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + public static List collectElements( + Reactor definition, EStructuralFeature feature) { + return ASTUtils.collectElements(definition, feature, true, true); + } - if (includeModes && reactorModeFeatureMap.containsKey(feature)) { - var modeFeature = reactorModeFeatureMap.get(feature); - // Add elements of elements defined in modes. - for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { - insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); - } + /** + * Collect elements of type T contained in given reactor definition, including modes and the class + * hierarchy defined depending on configuration. + * + * @param definition The reactor definition. + * @param feature The structual model elements to collect. + * @param includeSuperClasses Whether to include elements in super classes. + * @param includeModes Whether to include elements in modes. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + @SuppressWarnings("unchecked") + public static List collectElements( + Reactor definition, + EStructuralFeature feature, + boolean includeSuperClasses, + boolean includeModes) { + List result = new ArrayList<>(); + + if (includeSuperClasses) { + // Add elements of elements defined in superclasses. + LinkedHashSet s = superClasses(definition); + if (s != null) { + for (Reactor superClass : s) { + result.addAll((EList) superClass.eGet(feature)); } + } + } - return result; + // Add elements of the current reactor. + result.addAll((EList) definition.eGet(feature)); + + if (includeModes && reactorModeFeatureMap.containsKey(feature)) { + var modeFeature = reactorModeFeatureMap.get(feature); + // Add elements of elements defined in modes. + for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { + insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); + } } - /** - * Adds the elements into the given list at a location matching to their textual position. - * - * When creating a flat view onto reactor elements including modes, the final list must be ordered according - * to the textual positions. - * - * Example: - * reactor R { - * reaction // -> is R.reactions[0] - * mode M { - * reaction // -> is R.mode[0].reactions[0] - * reaction // -> is R.mode[0].reactions[1] - * } - * reaction // -> is R.reactions[1] - * } - * In this example, it is important that the reactions in the mode are inserted between the top-level - * reactions to retain the correct global reaction ordering, which will be derived from this flattened view. - * - * @param list The list to add the elements into. - * @param elements The elements to add. - * @param mode The mode containing the elements. - * @param The type of elements to add (e.g., Port, Timer, etc.) - */ - private static void insertModeElementsAtTextualPosition(List list, List elements, Mode mode) { - if (elements.isEmpty()) { - return; // Nothing to add - } + return result; + } - var idx = list.size(); - if (idx > 0) { - // If there are elements in the list, first check if the last element has the same container as the mode. - // I.e. we don't want to compare textual positions of different reactors (super classes) - if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { - var modeAstNode = NodeModelUtils.getNode(mode); - if (modeAstNode != null) { - var modePos = modeAstNode.getOffset(); - // Now move the insertion index from the last element forward as long as this element has a textual - // position after the mode. - do { - var astNode = NodeModelUtils.getNode(list.get(idx - 1)); - if (astNode != null && astNode.getOffset() > modePos) { - idx--; - } else { - break; // Insertion index is ok. - } - } while (idx > 0); - } + /** + * Adds the elements into the given list at a location matching to their textual position. + * + *

When creating a flat view onto reactor elements including modes, the final list must be + * ordered according to the textual positions. + * + *

Example: reactor R { reaction // -> is R.reactions[0] mode M { reaction // -> is + * R.mode[0].reactions[0] reaction // -> is R.mode[0].reactions[1] } reaction // -> is + * R.reactions[1] } In this example, it is important that the reactions in the mode are inserted + * between the top-level reactions to retain the correct global reaction ordering, which will be + * derived from this flattened view. + * + * @param list The list to add the elements into. + * @param elements The elements to add. + * @param mode The mode containing the elements. + * @param The type of elements to add (e.g., Port, Timer, etc.) + */ + private static void insertModeElementsAtTextualPosition( + List list, List elements, Mode mode) { + if (elements.isEmpty()) { + return; // Nothing to add + } + + var idx = list.size(); + if (idx > 0) { + // If there are elements in the list, first check if the last element has the same container + // as the mode. + // I.e. we don't want to compare textual positions of different reactors (super classes) + if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { + var modeAstNode = NodeModelUtils.getNode(mode); + if (modeAstNode != null) { + var modePos = modeAstNode.getOffset(); + // Now move the insertion index from the last element forward as long as this element has + // a textual + // position after the mode. + do { + var astNode = NodeModelUtils.getNode(list.get(idx - 1)); + if (astNode != null && astNode.getOffset() > modePos) { + idx--; + } else { + break; // Insertion index is ok. } + } while (idx > 0); } - list.addAll(idx, elements); + } } + list.addAll(idx, elements); + } - public static Iterable allElementsOfClass( - Resource resource, - Class elementClass - ) { - //noinspection StaticPseudoFunctionalStyleMethod - return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); - } + public static Iterable allElementsOfClass( + Resource resource, Class elementClass) { + //noinspection StaticPseudoFunctionalStyleMethod + return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); + } - //////////////////////////////// - //// Utility functions for translating AST nodes into text - - /** - * Translate the given code into its textual representation - * with {@code CodeMap.Correspondence} tags inserted, or - * return the empty string if {@code node} is {@code null}. - * This method should be used to generate code. - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toText(EObject node) { - if (node == null) return ""; - return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); - } + //////////////////////////////// + //// Utility functions for translating AST nodes into text + + /** + * Translate the given code into its textual representation with {@code CodeMap.Correspondence} + * tags inserted, or return the empty string if {@code node} is {@code null}. This method should + * be used to generate code. + * + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toText(EObject node) { + if (node == null) return ""; + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); + } - /** - * Translate the given code into its textual representation - * without {@code CodeMap.Correspondence} tags, or return - * the empty string if {@code node} is {@code null}. - * This method should be used for analyzing AST nodes in - * cases where they are easiest to analyze as strings. - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toOriginalText(EObject node) { - if (node == null) return ""; - return ToText.instance.doSwitch(node); - } + /** + * Translate the given code into its textual representation without {@code CodeMap.Correspondence} + * tags, or return the empty string if {@code node} is {@code null}. This method should be used + * for analyzing AST nodes in cases where they are easiest to analyze as strings. + * + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toOriginalText(EObject node) { + if (node == null) return ""; + return ToText.instance.doSwitch(node); + } - /** - * Return an integer representation of the given element. - * - * Internally, this method uses Integer.decode, so it will - * also understand hexadecimal, binary, etc. - * - * @param e The element to be rendered as an integer. - */ - public static Integer toInteger(Element e) { - return Integer.decode(e.getLiteral()); - } + /** + * Return an integer representation of the given element. + * + *

Internally, this method uses Integer.decode, so it will also understand hexadecimal, binary, + * etc. + * + * @param e The element to be rendered as an integer. + */ + public static Integer toInteger(Element e) { + return Integer.decode(e.getLiteral()); + } - /** - * Return a time value based on the given element. - * - * @param e The element to be rendered as a time value. - */ - public static TimeValue toTimeValue(Element e) { - return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); - } + /** + * Return a time value based on the given element. + * + * @param e The element to be rendered as a time value. + */ + public static TimeValue toTimeValue(Element e) { + return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); + } - /** - * Returns the time value represented by the given AST node. - */ - public static TimeValue toTimeValue(Time e) { - if (!isValidTime(e)) { - // invalid unit, will have been reported by validator - throw new IllegalArgumentException(); - } - return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + /** Returns the time value represented by the given AST node. */ + public static TimeValue toTimeValue(Time e) { + if (!isValidTime(e)) { + // invalid unit, will have been reported by validator + throw new IllegalArgumentException(); } + return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + } - /** - * Return a boolean based on the given element. - * - * @param e The element to be rendered as a boolean. - */ - public static boolean toBoolean(Element e) { - return elementToSingleString(e).equalsIgnoreCase("true"); - } + /** + * Return a boolean based on the given element. + * + * @param e The element to be rendered as a boolean. + */ + public static boolean toBoolean(Element e) { + return elementToSingleString(e).equalsIgnoreCase("true"); + } - /** - * Given the right-hand side of a target property, return a string that - * represents the given value/ - * - * If the given value is not a literal or and id (but for instance and array or dict), - * an empty string is returned. If the element is a string, any quotes are removed. - * - * @param e The right-hand side of a target property. - */ - public static String elementToSingleString(Element e) { - if (e.getLiteral() != null) { - return StringUtil.removeQuotes(e.getLiteral()).trim(); - } else if (e.getId() != null) { - return e.getId(); - } - return ""; - } + /** + * Given the right-hand side of a target property, return a string that represents the given + * value/ + * + *

If the given value is not a literal or and id (but for instance and array or dict), an empty + * string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String elementToSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } - /** - * Given the right-hand side of a target property, return a list with all - * the strings that the property lists. - * - * Arrays are traversed, so strings are collected recursively. Empty strings - * are ignored; they are not added to the list. - * @param value The right-hand side of a target property. - */ - public static List elementToListOfStrings(Element value) { - List elements = new ArrayList<>(); - if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - elements.addAll(elementToListOfStrings(element)); - } - return elements; - } else { - String v = elementToSingleString(value); - if (!v.isEmpty()) { - elements.add(v); - } - } - return elements; - } + /** + * Given the right-hand side of a target property, return a list with all the strings that the + * property lists. + * + *

Arrays are traversed, so strings are collected recursively. Empty strings are ignored; they + * are not added to the list. + * + * @param value The right-hand side of a target property. + */ + public static List elementToListOfStrings(Element value) { + List elements = new ArrayList<>(); + if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + elements.addAll(elementToListOfStrings(element)); + } + return elements; + } else { + String v = elementToSingleString(value); + if (!v.isEmpty()) { + elements.add(v); + } + } + return elements; + } - /** - * Convert key-value pairs in an Element to a map, assuming that both the key - * and the value are strings. - */ - public static Map elementToStringMaps(Element value) { - Map elements = new HashMap<>(); - for (var element: value.getKeyvalue().getPairs()) { - elements.put( - element.getName().trim(), - StringUtil.removeQuotes(elementToSingleString(element.getValue())) - ); - } - return elements; - } + /** + * Convert key-value pairs in an Element to a map, assuming that both the key and the value are + * strings. + */ + public static Map elementToStringMaps(Element value) { + Map elements = new HashMap<>(); + for (var element : value.getKeyvalue().getPairs()) { + elements.put( + element.getName().trim(), + StringUtil.removeQuotes(elementToSingleString(element.getValue()))); + } + return elements; + } - // Various utility methods to convert various data types to Elements - - /** - * Convert a map to key-value pairs in an Element. - */ - public static Element toElement(Map map) { - Element e = LfFactory.eINSTANCE.createElement(); - if (map.size() == 0) return null; - else { - var kv = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var entry : map.entrySet()) { - var pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(entry.getKey()); - var element = LfFactory.eINSTANCE.createElement(); - element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); - pair.setValue(element); - kv.getPairs().add(pair); - } - e.setKeyvalue(kv); - } + // Various utility methods to convert various data types to Elements + + /** Convert a map to key-value pairs in an Element. */ + public static Element toElement(Map map) { + Element e = LfFactory.eINSTANCE.createElement(); + if (map.size() == 0) return null; + else { + var kv = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var entry : map.entrySet()) { + var pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(entry.getKey()); + var element = LfFactory.eINSTANCE.createElement(); + element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); + pair.setValue(element); + kv.getPairs().add(pair); + } + e.setKeyvalue(kv); + } + + return e; + } - return e; - } + /** + * Given a single string, convert it into its AST representation. {@code addQuotes} controls if + * the generated representation should be accompanied by double quotes ("") or not. + */ + private static Element toElement(String str, boolean addQuotes) { + if (str == null) return null; + var strToReturn = addQuotes ? StringUtil.addDoubleQuotes(str) : str; + Element e = LfFactory.eINSTANCE.createElement(); + e.setLiteral(strToReturn); + return e; + } - /** - * Given a single string, convert it into its AST representation. - * {@code addQuotes} controls if the generated representation should be - * accompanied by double quotes ("") or not. - */ - private static Element toElement(String str, boolean addQuotes) { - if (str == null) return null; - var strToReturn = addQuotes? StringUtil.addDoubleQuotes(str):str; - Element e = LfFactory.eINSTANCE.createElement(); - e.setLiteral(strToReturn); - return e; + /** Given a single string, convert it into its AST representation. */ + public static Element toElement(String str) { + return toElement(str, true); + } - } + /** + * Given a list of strings, convert it into its AST representation. Stores the list in the Array + * field of the element, unless the list only has one string, in which case it is stored in the + * Literal field. Returns null if the provided list is empty. + */ + public static Element toElement(List list) { + Element e = LfFactory.eINSTANCE.createElement(); + if (list.size() == 0) return null; + else if (list.size() == 1) { + return toElement(list.get(0)); + } else { + var arr = LfFactory.eINSTANCE.createArray(); + for (String s : list) { + arr.getElements().add(ASTUtils.toElement(s)); + } + e.setArray(arr); + } + return e; + } - /** - * Given a single string, convert it into its AST representation. - */ - public static Element toElement(String str) { - return toElement(str, true); - } + /** + * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit + * inside an Element. + */ + public static Element toElement(TimeValue tv) { + Element e = LfFactory.eINSTANCE.createElement(); + e.setTime((int) tv.time); + if (tv.unit != null) { + e.setUnit(tv.unit.toString()); + } + return e; + } + + public static Element toElement(boolean val) { + return toElement(Boolean.toString(val), false); + } - /** - * Given a list of strings, convert it into its AST representation. - * Stores the list in the Array field of the element, unless the list only has one string, - * in which case it is stored in the Literal field. Returns null if the provided list is empty. - */ - public static Element toElement(List list) { - Element e = LfFactory.eINSTANCE.createElement(); - if (list.size() == 0) return null; - else if (list.size() == 1) { - return toElement(list.get(0)); + public static Element toElement(int val) { + return toElement(Integer.toString(val), false); + } + + /** + * Translate the given type into its textual representation, but do not append any array + * specifications or type arguments. + * + * @param type AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String baseType(Type type) { + if (type != null) { + if (type.getCode() != null) { + return toText(type.getCode()); + } else { + if (type.isTime()) { + return "time"; } else { - var arr = LfFactory.eINSTANCE.createArray(); - for (String s : list) { - arr.getElements().add(ASTUtils.toElement(s)); - } - e.setArray(arr); - } - return e; - } + StringBuilder result = new StringBuilder(type.getId()); - /** - * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit inside an Element. - */ - public static Element toElement(TimeValue tv) { - Element e = LfFactory.eINSTANCE.createElement(); - e.setTime((int)tv.time); - if (tv.unit != null) { - e.setUnit(tv.unit.toString()); + for (String s : convertToEmptyListIfNull(type.getStars())) { + result.append(s); + } + return result.toString(); } - return e; + } } + return ""; + } - public static Element toElement(boolean val) { - return toElement(Boolean.toString(val), false); + /** + * Report whether the given literal is zero or not. + * + * @param literal AST node to inspect. + * @return True if the given literal denotes the constant `0`, false otherwise. + */ + public static boolean isZero(String literal) { + try { + if (literal != null && Integer.parseInt(literal) == 0) { + return true; + } + } catch (NumberFormatException e) { + // Not an int. } + return false; + } - public static Element toElement(int val) { - return toElement(Integer.toString(val), false); - } + /** + * Report whether the given expression is zero or not. + * + * @param expr AST node to inspect. + * @return True if the given value denotes the constant `0`, false otherwise. + */ + public static boolean isZero(Expression expr) { + if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } - /** - * Translate the given type into its textual representation, but - * do not append any array specifications or type arguments. - * @param type AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String baseType(Type type) { - if (type != null) { - if (type.getCode() != null) { - return toText(type.getCode()); - } else { - if (type.isTime()) { - return "time"; - } else { - StringBuilder result = new StringBuilder(type.getId()); - - for (String s : convertToEmptyListIfNull(type.getStars())) { - result.append(s); - } - return result.toString(); - } - } - } - return ""; - } + /** + * Report whether the given string literal is an integer number or not. + * + * @param literal AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Integer.decode(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } - /** - * Report whether the given literal is zero or not. - * @param literal AST node to inspect. - * @return True if the given literal denotes the constant `0`, false - * otherwise. - */ - public static boolean isZero(String literal) { - try { - if (literal != null && - Integer.parseInt(literal) == 0) { - return true; - } - } catch (NumberFormatException e) { - // Not an int. - } - return false; - } + /** + * Report whether the given string literal is a boolean value or not. + * + * @param literal AST node to inspect. + * @return True if the given value is a boolean, false otherwise. + */ + public static boolean isBoolean(String literal) { + return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); + } - /** - * Report whether the given expression is zero or not. - * - * @param expr AST node to inspect. - * @return True if the given value denotes the constant `0`, false otherwise. - */ - public static boolean isZero(Expression expr) { - if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } + /** + * Report whether the given string literal is a float value or not. + * + * @param literal AST node to inspect. + * @return True if the given value is a float, false otherwise. + */ + public static boolean isFloat(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Float.parseFloat(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } - /** - * Report whether the given string literal is an integer number or not. - * - * @param literal AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Integer.decode(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } + /** + * Report whether the given code is an integer number or not. + * + * @param code AST node to inspect. + * @return True if the given code is an integer, false otherwise. + */ + public static boolean isInteger(Code code) { + return isInteger(toText(code)); + } - /** - * Report whether the given string literal is a boolean value or not. - * @param literal AST node to inspect. - * @return True if the given value is a boolean, false otherwise. - */ - public static boolean isBoolean(String literal) { - return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); - } + /** + * Report whether the given expression is an integer number or not. + * + * @param expr AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(Expression expr) { + if (expr instanceof Literal) { + return isInteger(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isInteger((Code) expr); + } + return false; + } - /** - * Report whether the given string literal is a float value or not. - * @param literal AST node to inspect. - * @return True if the given value is a float, false otherwise. - */ - public static boolean isFloat(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Float.parseFloat(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } + /** + * Report whether the given expression denotes a valid time or not. + * + * @param expr AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Expression expr) { + if (expr instanceof ParameterReference) { + return isOfTimeType(((ParameterReference) expr).getParameter()); + } else if (expr instanceof Time) { + return isValidTime((Time) expr); + } else if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } - /** - * Report whether the given code is an integer number or not. - * @param code AST node to inspect. - * @return True if the given code is an integer, false otherwise. - */ - public static boolean isInteger(Code code) { - return isInteger(toText(code)); - } + /** + * Report whether the given time denotes a valid time or not. + * + * @param t AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Time t) { + if (t == null) return false; + String unit = t.getUnit(); + return t.getInterval() == 0 || TimeUnit.isValidUnit(unit); + } - /** - * Report whether the given expression is an integer number or not. - * @param expr AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(Expression expr) { - if (expr instanceof Literal) { - return isInteger(((Literal) expr).getLiteral()); - } else if (expr instanceof Code) { - return isInteger((Code) expr); - } - return false; + /** If the initializer contains exactly one expression, return it. Otherwise, return null. */ + public static Expression asSingleExpr(Initializer init) { + if (init == null) { + return null; } + var exprs = init.getExprs(); + return exprs.size() == 1 ? exprs.get(0) : null; + } - /** - * Report whether the given expression denotes a valid time or not. - * @param expr AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Expression expr) { - if (expr instanceof ParameterReference) { - return isOfTimeType(((ParameterReference)expr).getParameter()); - } else if (expr instanceof Time) { - return isValidTime((Time) expr); - } else if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; + public static boolean isSingleExpr(Initializer init) { + // todo expand that to = initialization + if (init == null) { + return false; } + var exprs = init.getExprs(); + return exprs.size() == 1; + } - /** - * Report whether the given time denotes a valid time or not. - * @param t AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Time t) { - if (t == null) return false; - String unit = t.getUnit(); - return t.getInterval() == 0 || - TimeUnit.isValidUnit(unit); - } + public static boolean isListInitializer(Initializer init) { + return init != null && !isSingleExpr(init); + } - /** - * If the initializer contains exactly one expression, - * return it. Otherwise, return null. - */ - public static Expression asSingleExpr(Initializer init) { - if (init == null) { - return null; + /** + * Return the type of a declaration with the given (nullable) explicit type, and the given + * (nullable) initializer. If the explicit type is null, then the type is inferred from the + * initializer. Only two types can be inferred: "time" and "timeList". Return the "undefined" type + * if neither can be inferred. + * + * @param type Explicit type declared on the declaration + * @param init The initializer expression + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Type type, Initializer init) { + if (type != null) { + return InferredType.fromAST(type); + } else if (init == null) { + return InferredType.undefined(); + } + + var single = asSingleExpr(init); + if (single != null) { + // If there is a single element in the list, and it is a proper + // time value with units, we infer the type "time". + if (single instanceof ParameterReference) { + return getInferredType(((ParameterReference) single).getParameter()); + } else if (single instanceof Time) { + return InferredType.time(); + } + } else if (init.getExprs().size() > 1) { + // If there are multiple elements in the list, and there is at + // least one proper time value with units, and all other elements + // are valid times (including zero without units), we infer the + // type "time list". + var allValidTime = true; + var foundNonZero = false; + + for (var e : init.getExprs()) { + if (!ASTUtils.isValidTime(e)) { + allValidTime = false; } - var exprs = init.getExprs(); - return exprs.size() == 1 ? exprs.get(0) : null; - } - - public static boolean isSingleExpr(Initializer init) { - // todo expand that to = initialization - if (init == null) { - return false; + if (!ASTUtils.isZero(e)) { + foundNonZero = true; } - var exprs = init.getExprs(); - return exprs.size() == 1; - } + } - public static boolean isListInitializer(Initializer init) { - return init != null && !isSingleExpr(init); + if (allValidTime && foundNonZero) { + // Conservatively, no bounds are inferred; the returned type + // is a variable-size list. + return InferredType.timeList(); + } } + return InferredType.undefined(); + } - /** - * Return the type of a declaration with the given - * (nullable) explicit type, and the given (nullable) - * initializer. If the explicit type is null, then the - * type is inferred from the initializer. Only two types - * can be inferred: "time" and "timeList". Return the - * "undefined" type if neither can be inferred. - * - * @param type Explicit type declared on the declaration - * @param init The initializer expression - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Type type, Initializer init) { - if (type != null) { - return InferredType.fromAST(type); - } else if (init == null) { - return InferredType.undefined(); - } - - var single = asSingleExpr(init); - if (single != null) { - // If there is a single element in the list, and it is a proper - // time value with units, we infer the type "time". - if (single instanceof ParameterReference) { - return getInferredType(((ParameterReference) single).getParameter()); - } else if (single instanceof Time) { - return InferredType.time(); - } - } else if (init.getExprs().size() > 1) { - // If there are multiple elements in the list, and there is at - // least one proper time value with units, and all other elements - // are valid times (including zero without units), we infer the - // type "time list". - var allValidTime = true; - var foundNonZero = false; - - for (var e : init.getExprs()) { - if (!ASTUtils.isValidTime(e)) { - allValidTime = false; - } - if (!ASTUtils.isZero(e)) { - foundNonZero = true; - } - } - - if (allValidTime && foundNonZero) { - // Conservatively, no bounds are inferred; the returned type - // is a variable-size list. - return InferredType.timeList(); - } - } - return InferredType.undefined(); - } + /** + * Given a parameter, return an inferred type. Only two types can be inferred: "time" and + * "timeList". Return the "undefined" type if neither can be inferred. + * + * @param p A parameter to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Parameter p) { + return getInferredType(p.getType(), p.getInit()); + } - /** - * Given a parameter, return an inferred type. Only two types can be - * inferred: "time" and "timeList". Return the "undefined" type if - * neither can be inferred. - * - * @param p A parameter to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Parameter p) { - return getInferredType(p.getType(), p.getInit()); - } + /** + * Given a state variable, return an inferred type. Only two types can be inferred: "time" and + * "timeList". Return the "undefined" type if neither can be inferred. + * + * @param s A state variable to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(StateVar s) { + return getInferredType(s.getType(), s.getInit()); + } - /** - * Given a state variable, return an inferred type. Only two types can be - * inferred: "time" and "timeList". Return the "undefined" type if - * neither can be inferred. - * - * @param s A state variable to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(StateVar s) { - return getInferredType(s.getType(), s.getInit()); - } + /** + * Construct an inferred type from an "action" AST node based on its declared type. If no type is + * declared, return the "undefined" type. + * + * @param a An action to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Action a) { + return getInferredType(a.getType(), null); + } - /** - * Construct an inferred type from an "action" AST node based - * on its declared type. If no type is declared, return the "undefined" - * type. - * - * @param a An action to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Action a) { - return getInferredType(a.getType(), null); - } + /** + * Construct an inferred type from a "port" AST node based on its declared type. If no type is + * declared, return the "undefined" type. + * + * @param p A port to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Port p) { + return getInferredType(p.getType(), null); + } - /** - * Construct an inferred type from a "port" AST node based on its declared - * type. If no type is declared, return the "undefined" type. - * - * @param p A port to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Port p) { - return getInferredType(p.getType(), null); - } + /** + * If the given string can be recognized as a floating-point number that has a leading decimal + * point, prepend the string with a zero and return it. Otherwise, return the original string. + * + * @param literal A string might be recognizable as a floating point number with a leading decimal + * point. + * @return an equivalent representation of literal + * + */ + public static String addZeroToLeadingDot(String literal) { + Matcher m = ABBREVIATED_FLOAT.matcher(literal); + if (m.matches()) { + return literal.replace(".", "0."); + } + return literal; + } + /** + * Return true if the specified port is a multiport. + * + * @param port The port. + * @return True if the port is a multiport. + */ + public static boolean isMultiport(Port port) { + return port.getWidthSpec() != null; + } + //////////////////////////////// + //// Utility functions for translating AST nodes into text + // This is a continuation of a large section of ASTUtils.xtend + // with the same name. + + /** + * Generate code for referencing a port, action, or timer. + * + * @param reference The reference to the variable. + */ + public static String generateVarRef(VarRef reference) { + var prefix = ""; + if (reference.getContainer() != null) { + prefix = reference.getContainer().getName() + "."; + } + return prefix + reference.getVariable().getName(); + } - /** - * If the given string can be recognized as a floating-point number that has a leading decimal point, - * prepend the string with a zero and return it. Otherwise, return the original string. - * - * @param literal A string might be recognizable as a floating point number with a leading decimal point. - * @return an equivalent representation of literal - * - */ - public static String addZeroToLeadingDot(String literal) { - Matcher m = ABBREVIATED_FLOAT.matcher(literal); - if (m.matches()) { - return literal.replace(".", "0."); - } - return literal; + /** Assuming that the given expression denotes a valid time literal, return a time value. */ + public static TimeValue getLiteralTimeValue(Expression expr) { + if (expr instanceof Time) { + return toTimeValue((Time) expr); + } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { + return TimeValue.ZERO; + } else { + return null; } + } - /** - * Return true if the specified port is a multiport. - * @param port The port. - * @return True if the port is a multiport. - */ - public static boolean isMultiport(Port port) { - return port.getWidthSpec() != null; + /** If the parameter is of time type, return its default value. Otherwise, return null. */ + public static TimeValue getDefaultAsTimeValue(Parameter p) { + if (isOfTimeType(p)) { + var init = asSingleExpr(p.getInit()); + if (init != null) { + return getLiteralTimeValue(init); + } } + return null; + } - //////////////////////////////// - //// Utility functions for translating AST nodes into text - // This is a continuation of a large section of ASTUtils.xtend - // with the same name. - - /** - * Generate code for referencing a port, action, or timer. - * @param reference The reference to the variable. - */ - public static String generateVarRef(VarRef reference) { - var prefix = ""; - if (reference.getContainer() != null) { - prefix = reference.getContainer().getName() + "."; - } - return prefix + reference.getVariable().getName(); - } + /** Return whether the given state variable is inferred to a time type. */ + public static boolean isOfTimeType(StateVar state) { + InferredType t = getInferredType(state); + return t.isTime && !t.isList; + } - /** - * Assuming that the given expression denotes a valid time literal, - * return a time value. - */ - public static TimeValue getLiteralTimeValue(Expression expr) { - if (expr instanceof Time) { - return toTimeValue((Time)expr); - } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { - return TimeValue.ZERO; - } else { - return null; - } - } + /** Return whether the given parameter is inferred to a time type. */ + public static boolean isOfTimeType(Parameter param) { + InferredType t = getInferredType(param); + return t.isTime && !t.isList; + } - /** - * If the parameter is of time type, return its default value. - * Otherwise, return null. - */ - public static TimeValue getDefaultAsTimeValue(Parameter p) { - if (isOfTimeType(p)) { - var init = asSingleExpr(p.getInit()); - if (init != null) { - return getLiteralTimeValue(init); + /** + * Given a parameter, return its initial value. The initial value is a list of instances of + * Expressions. + * + *

If the instantiations argument is null or an empty list, then the value returned is simply + * the default value given when the parameter is defined. + * + *

If a list of instantiations is given, then the first instantiation is required to be an + * instantiation of the reactor class that is parameterized by the parameter. I.e., ``` + * parameter.eContainer == instantiations.get(0).reactorClass ``` If a second instantiation is + * given, then it is required to be an instantiation of a reactor class that contains the first + * instantiation. That is, ``` instantiations.get(0).eContainer == + * instantiations.get(1).reactorClass ``` More generally, for all 0 <= i < instantiations.size - + * 1, ``` instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass ``` If any of + * these conditions is not satisfied, then an IllegalArgumentException will be thrown. + * + *

Note that this chain of reactions cannot be inferred from the parameter because in each of + * the predicates above, there may be more than one instantiation that can appear on the right + * hand side of the predicate. + * + *

For example, consider the following program: ``` 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); } ``` Notice that there are a total of four instances of reactor class A. Then ``` + * initialValue(x, null) returns 1 initialValue(x, [a1]) returns 2 initialValue(x, [a2]) returns + * -1 initialValue(x, [a1, b1]) returns 3 initialValue(x, [a2, b1]) returns -1 initialValue(x, + * [a1, b2]) returns -2 initialValue(x, [a2, b2]) returns -1 ``` (Actually, in each of the above + * cases, the returned value is a list with one entry, a Literal, e.g. ["1"]). + * + *

There are two instances of reactor class B. ``` initialValue(y, null) returns 2 + * initialValue(y, [a1]) throws an IllegalArgumentException initialValue(y, [b1]) returns 3 + * initialValue(y, [b2]) returns -2 ``` + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * @return The value of the parameter. + * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the + * reactor class that is parameterized by the respective parameter or if the chain of + * instantiations is not nested. + */ + public static List initialValue( + Parameter parameter, List instantiations) { + // If instantiations are given, then check to see whether this parameter gets overridden in + // the first of those instantiations. + if (instantiations != null && instantiations.size() > 0) { + // Check to be sure that the instantiation is in fact an instantiation + // of the reactor class for which this is a parameter. + Instantiation instantiation = instantiations.get(0); + + if (!belongsTo(parameter, instantiation)) { + throw new IllegalArgumentException( + "Parameter " + + parameter.getName() + + " is not a parameter of reactor instance " + + instantiation.getName() + + "."); + } + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = null; + for (Assignment assignment : instantiation.getParameters()) { + if (assignment.getLhs().equals(parameter)) { + lastAssignment = assignment; + } + } + if (lastAssignment != null) { + // Right hand side can be a list. Collect the entries. + List result = new ArrayList<>(); + for (Expression expr : lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + if (instantiations.size() > 1 + && instantiation.eContainer() != instantiations.get(1).getReactorClass()) { + throw new IllegalArgumentException( + "Reactor instance " + + instantiation.getName() + + " is not contained by instance " + + instantiations.get(1).getName() + + "."); } + result.addAll( + initialValue( + ((ParameterReference) expr).getParameter(), + instantiations.subList(1, instantiations.size()))); + } else { + result.add(expr); + } } - return null; - } - - /** - * Return whether the given state variable is inferred - * to a time type. - */ - public static boolean isOfTimeType(StateVar state) { - InferredType t = getInferredType(state); - return t.isTime && !t.isList; + return result; + } } + // If we reach here, then either no instantiation was supplied or + // there was no assignment in the instantiation. So just use the + // parameter's initial value. + return parameter.getInit().getExprs(); + } - /** - * Return whether the given parameter is inferred - * to a time type. - */ - public static boolean isOfTimeType(Parameter param) { - InferredType t = getInferredType(param); - return t.isTime && !t.isList; - } + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the + * specified instantiation, meaning that it is defined in the reactor class being instantiated or + * one of its base classes. + * + * @param eobject The object. + * @param instantiation The instantiation. + */ + public static boolean belongsTo(EObject eobject, Instantiation instantiation) { + Reactor reactor = toDefinition(instantiation.getReactorClass()); + return belongsTo(eobject, reactor); + } - /** - * Given a parameter, return its initial value. - * The initial value is a list of instances of Expressions. - * - * If the instantiations argument is null or an empty list, then the - * value returned is simply the default value given when the parameter - * is defined. - * - * If a list of instantiations is given, then the first instantiation - * is required to be an instantiation of the reactor class that is - * parameterized by the parameter. I.e., - * ``` - * parameter.eContainer == instantiations.get(0).reactorClass - * ``` - * If a second instantiation is given, then it is required to be an instantiation of a - * reactor class that contains the first instantiation. That is, - * ``` - * instantiations.get(0).eContainer == instantiations.get(1).reactorClass - * ``` - * More generally, for all 0 <= i < instantiations.size - 1, - * ``` - * instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass - * ``` - * If any of these conditions is not satisfied, then an IllegalArgumentException - * will be thrown. - * - * Note that this chain of reactions cannot be inferred from the parameter because - * in each of the predicates above, there may be more than one instantiation that - * can appear on the right hand side of the predicate. - * - * For example, consider the following program: - * ``` - * 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); - * } - * ``` - * Notice that there are a total of four instances of reactor class A. - * Then - * ``` - * initialValue(x, null) returns 1 - * initialValue(x, [a1]) returns 2 - * initialValue(x, [a2]) returns -1 - * initialValue(x, [a1, b1]) returns 3 - * initialValue(x, [a2, b1]) returns -1 - * initialValue(x, [a1, b2]) returns -2 - * initialValue(x, [a2, b2]) returns -1 - * ``` - * (Actually, in each of the above cases, the returned value is a list with - * one entry, a Literal, e.g. ["1"]). - * - * There are two instances of reactor class B. - * ``` - * initialValue(y, null) returns 2 - * initialValue(y, [a1]) throws an IllegalArgumentException - * initialValue(y, [b1]) returns 3 - * initialValue(y, [b2]) returns -2 - * ``` - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * - * @return The value of the parameter. - * - * @throws IllegalArgumentException If an instantiation provided is not an - * instantiation of the reactor class that is parameterized by the - * respective parameter or if the chain of instantiations is not nested. - */ - public static List initialValue(Parameter parameter, List instantiations) { - // If instantiations are given, then check to see whether this parameter gets overridden in - // the first of those instantiations. - if (instantiations != null && instantiations.size() > 0) { - // Check to be sure that the instantiation is in fact an instantiation - // of the reactor class for which this is a parameter. - Instantiation instantiation = instantiations.get(0); - - if (!belongsTo(parameter, instantiation)) { - throw new IllegalArgumentException("Parameter " - + parameter.getName() - + " is not a parameter of reactor instance " - + instantiation.getName() - + "." - ); - } - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = null; - for (Assignment assignment: instantiation.getParameters()) { - if (assignment.getLhs().equals(parameter)) { - lastAssignment = assignment; - } - } - if (lastAssignment != null) { - // Right hand side can be a list. Collect the entries. - List result = new ArrayList<>(); - for (Expression expr: lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - if (instantiations.size() > 1 - && instantiation.eContainer() != instantiations.get(1).getReactorClass() - ) { - throw new IllegalArgumentException("Reactor instance " - + instantiation.getName() - + " is not contained by instance " - + instantiations.get(1).getName() - + "." - ); - } - result.addAll(initialValue(((ParameterReference)expr).getParameter(), - instantiations.subList(1, instantiations.size()))); - } else { - result.add(expr); - } - } - return result; - } - } - // If we reach here, then either no instantiation was supplied or - // there was no assignment in the instantiation. So just use the - // parameter's initial value. - return parameter.getInit().getExprs(); + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the + * specified reactor, meaning that it is defined in reactor class or one of its base classes. + * + * @param eobject The object. + * @param reactor The reactor. + */ + public static boolean belongsTo(EObject eobject, Reactor reactor) { + if (eobject.eContainer() == reactor) return true; + for (ReactorDecl baseClass : reactor.getSuperClasses()) { + if (belongsTo(eobject, toDefinition(baseClass))) { + return true; + } } + return false; + } - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) - * belongs to the specified instantiation, meaning that it is defined in - * the reactor class being instantiated or one of its base classes. - * @param eobject The object. - * @param instantiation The instantiation. - */ - public static boolean belongsTo(EObject eobject, Instantiation instantiation) { - Reactor reactor = toDefinition(instantiation.getReactorClass()); - return belongsTo(eobject, reactor); + /** + * Given a parameter return its integer value or null if it does not have an integer value. If the + * value of the parameter is a list of integers, return the sum of value in the list. The + * instantiations parameter is as in {@link #initialValue(Parameter, List)}. + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * @return The integer value of the parameter, or null if it does not have an integer value. + * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the + * reactor class that is parameterized by the respective parameter or if the chain of + * instantiations is not nested. + */ + public static Integer initialValueInt(Parameter parameter, List instantiations) { + List expressions = initialValue(parameter, instantiations); + int result = 0; + for (Expression expr : expressions) { + if (!(expr instanceof Literal)) { + return null; + } + try { + result += Integer.decode(((Literal) expr).getLiteral()); + } catch (NumberFormatException ex) { + return null; + } } + return result; + } - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) - * belongs to the specified reactor, meaning that it is defined in - * reactor class or one of its base classes. - * @param eobject The object. - * @param reactor The reactor. - */ - public static boolean belongsTo(EObject eobject, Reactor reactor) { - if (eobject.eContainer() == reactor) return true; - for (ReactorDecl baseClass : reactor.getSuperClasses()) { - if (belongsTo(eobject, toDefinition(baseClass))) { - return true; - } + /** + * Given the width specification of port or instantiation and an (optional) list of nested + * instantiations, return the width if it can be determined and -1 if not. It will not be able to + * be determined if either the width is variable (in which case you should use {@link + * #inferPortWidth(VarRef, Connection, List)} ) or the list of instantiations is incomplete or + * missing. If there are parameter references in the width, they are evaluated to the extent + * possible given the instantiations list. + * + *

The instantiations list is as in {@link #initialValue(Parameter, List)}. If the spec belongs + * to an instantiation (for a bank of reactors), then the first element on this list should be the + * instantiation that contains this instantiation. If the spec belongs to a port, then the first + * element on the list should be the instantiation of the reactor that contains the port. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * @return The width, or -1 if the width could not be determined. + * @throws IllegalArgumentException If an instantiation provided is not as given above or if the + * chain of instantiations is not nested. + */ + public static int width(WidthSpec spec, List instantiations) { + if (spec == null) { + return 1; + } + if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { + return inferWidthFromConnections(spec, instantiations); + } + var result = 0; + for (WidthTerm term : spec.getTerms()) { + if (term.getParameter() != null) { + Integer termWidth = initialValueInt(term.getParameter(), instantiations); + if (termWidth != null) { + result += termWidth; + } else { + return -1; } - return false; - } - - /** - * Given a parameter return its integer value or null - * if it does not have an integer value. - * If the value of the parameter is a list of integers, - * return the sum of value in the list. - * The instantiations parameter is as in - * {@link #initialValue(Parameter, List)}. - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * - * @return The integer value of the parameter, or null if it does not have an integer value. - * - * @throws IllegalArgumentException If an instantiation provided is not an - * instantiation of the reactor class that is parameterized by the - * respective parameter or if the chain of instantiations is not nested. - */ - public static Integer initialValueInt(Parameter parameter, List instantiations) { - List expressions = initialValue(parameter, instantiations); - int result = 0; - for (Expression expr: expressions) { - if (!(expr instanceof Literal)) { - return null; - } - try { - result += Integer.decode(((Literal) expr).getLiteral()); - } catch (NumberFormatException ex) { - return null; - } + } else if (term.getWidth() > 0) { + result += term.getWidth(); + } else { + // If the width cannot be determined because term's width <= 0, which means the term's width + // must be inferred, try to infer the width using connections. + if (spec.eContainer() instanceof Instantiation) { + try { + return inferWidthFromConnections(spec, instantiations); + } catch (InvalidSourceException e) { + // If the inference fails, return -1. + return -1; + } } - return result; + } } + return result; + } - /** - * Given the width specification of port or instantiation - * and an (optional) list of nested instantiations, return - * the width if it can be determined and -1 if not. - * It will not be able to be determined if either the - * width is variable (in which case you should use - * {@link #inferPortWidth(VarRef, Connection, List)} ) - * or the list of instantiations is incomplete or missing. - * If there are parameter references in the width, they are - * evaluated to the extent possible given the instantiations list. - * - * The instantiations list is as in - * {@link #initialValue(Parameter, List)}. - * If the spec belongs to an instantiation (for a bank of reactors), - * then the first element on this list should be the instantiation - * that contains this instantiation. If the spec belongs to a port, - * then the first element on the list should be the instantiation - * of the reactor that contains the port. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * - * @return The width, or -1 if the width could not be determined. - * - * @throws IllegalArgumentException If an instantiation provided is not as - * given above or if the chain of instantiations is not nested. - */ - public static int width(WidthSpec spec, List instantiations) { - if (spec == null) { - return 1; + /** + * Infer the width of a port reference in a connection. The port reference one or two parts, a + * port and an (optional) container which is an Instantiation that may refer to a bank of + * reactors. The width will be the product of the bank width and the port width. The returned + * value will be 1 if the port is not in a bank and is not a multiport. + * + *

If the width cannot be determined, this will return -1. The width cannot be determined if + * the list of instantiations is missing or incomplete. + * + *

The instantiations list is as in {@link #initialValue(Parameter, List)}. The first element + * on this list should be the instantiation that contains the specified connection. + * + * @param reference A port reference. + * @param connection A connection, or null if not in the context of a connection. + * @param instantiations The (optional) list of instantiations. + * @return The width or -1 if it could not be determined. + * @throws IllegalArgumentException If an instantiation provided is not as given above or if the + * chain of instantiations is not nested. + */ + public static int inferPortWidth( + VarRef reference, Connection connection, List instantiations) { + if (reference.getVariable() instanceof Port) { + // If the port is given as a.b, then we want to prepend a to + // the list of instantiations to determine the width of this port. + List extended = instantiations; + if (reference.getContainer() != null) { + extended = new ArrayList<>(); + extended.add(reference.getContainer()); + if (instantiations != null) { + extended.addAll(instantiations); } - if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { - return inferWidthFromConnections(spec, instantiations); - } - var result = 0; - for (WidthTerm term: spec.getTerms()) { - if (term.getParameter() != null) { - Integer termWidth = initialValueInt(term.getParameter(), instantiations); - if (termWidth != null) { - result += termWidth; - } else { - return -1; + } + + int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); + if (portWidth < 0) { + // Could not determine port width. + return -1; + } + + // Next determine the bank width. This may be unspecified, in which + // case it has to be inferred using the connection. + int bankWidth = 1; + if (reference.getContainer() != null) { + bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); + if (bankWidth < 0 && connection != null) { + // Try to infer the bank width from the connection. + if (reference.getContainer().getWidthSpec().isOfVariableLength()) { + // This occurs for a bank of delays. + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : connection.getLeftPorts()) { + if (leftPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException( + "Multiple ports with variable width on a connection."); } - } else if (term.getWidth() > 0) { - result += term.getWidth(); - } else { - // If the width cannot be determined because term's width <= 0, which means the term's width - // must be inferred, try to infer the width using connections. - if (spec.eContainer() instanceof Instantiation) { - try { - return inferWidthFromConnections(spec, instantiations); - } catch (InvalidSourceException e) { - // If the inference fails, return -1. - return -1; - } + // Indicate that this port is on the left. + leftOrRight = -1; + } else { + // The left port is not the same as this reference. + int otherWidth = inferPortWidth(leftPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; } + leftWidth += otherWidth; + } } - } - return result; - } - - /** - * Infer the width of a port reference in a connection. - * The port reference one or two parts, a port and an (optional) container - * which is an Instantiation that may refer to a bank of reactors. - * The width will be the product of the bank width and the port width. - * The returned value will be 1 if the port is not in a bank and is not a multiport. - * - * If the width cannot be determined, this will return -1. - * The width cannot be determined if the list of instantiations is - * missing or incomplete. - * - * The instantiations list is as in - * {@link #initialValue(Parameter, List)}. - * The first element on this list should be the instantiation - * that contains the specified connection. - * - * @param reference A port reference. - * @param connection A connection, or null if not in the context of a connection. - * @param instantiations The (optional) list of instantiations. - * - * @return The width or -1 if it could not be determined. - * - * @throws IllegalArgumentException If an instantiation provided is not as - * given above or if the chain of instantiations is not nested. - */ - public static int inferPortWidth( - VarRef reference, Connection connection, List instantiations - ) { - if (reference.getVariable() instanceof Port) { - // If the port is given as a.b, then we want to prepend a to - // the list of instantiations to determine the width of this port. - List extended = instantiations; - if (reference.getContainer() != null) { - extended = new ArrayList<>(); - extended.add(reference.getContainer()); - if (instantiations != null) { - extended.addAll(instantiations); + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException( + "Multiple ports with variable width on a connection."); } + // Indicate that this port is on the right. + leftOrRight = 1; + } else { + int otherWidth = inferPortWidth(rightPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; + } + rightWidth += otherWidth; + } } - - int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); - if (portWidth < 0) { - // Could not determine port width. - return -1; + int discrepancy = 0; + if (leftOrRight < 0) { + // This port is on the left. + discrepancy = rightWidth - leftWidth; + } else if (leftOrRight > 0) { + // This port is on the right. + discrepancy = leftWidth - rightWidth; } - - // Next determine the bank width. This may be unspecified, in which - // case it has to be inferred using the connection. - int bankWidth = 1; - if (reference.getContainer() != null) { - bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); - if (bankWidth < 0 && connection != null) { - // Try to infer the bank width from the connection. - if (reference.getContainer().getWidthSpec().isOfVariableLength()) { - // This occurs for a bank of delays. - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : connection.getLeftPorts()) { - if (leftPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the left. - leftOrRight = -1; - } else { - // The left port is not the same as this reference. - int otherWidth = inferPortWidth(leftPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; - } - leftWidth += otherWidth; - } - } - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the right. - leftOrRight = 1; - } else { - int otherWidth = inferPortWidth(rightPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; - } - rightWidth += otherWidth; - } - } - int discrepancy = 0; - if (leftOrRight < 0) { - // This port is on the left. - discrepancy = rightWidth - leftWidth; - } else if (leftOrRight > 0) { - // This port is on the right. - discrepancy = leftWidth - rightWidth; - } - // Check that portWidth divides the discrepancy. - if (discrepancy % portWidth != 0) { - // This is an error. - return -1; - } - bankWidth = discrepancy / portWidth; - } else { - // Could not determine the bank width. - return -1; - } - } + // Check that portWidth divides the discrepancy. + if (discrepancy % portWidth != 0) { + // This is an error. + return -1; } - return portWidth * bankWidth; + bankWidth = discrepancy / portWidth; + } else { + // Could not determine the bank width. + return -1; + } } - // Argument is not a port. - return -1; + } + return portWidth * bankWidth; } + // Argument is not a port. + return -1; + } - /** - * Given an instantiation of a reactor or bank of reactors, return - * the width. This will be 1 if this is not a reactor bank. Otherwise, - * this will attempt to determine the width. If the width is declared - * as a literal constant, it will return that constant. If the width - * is specified as a reference to a parameter, this will throw an - * exception. If the width is variable, this will find - * connections in the enclosing reactor and attempt to infer the - * width. If the width cannot be determined, it will throw an exception. - * - * IMPORTANT: This method should not be used you really need to - * determine the width! It will not evaluate parameter values. - * @see #width(WidthSpec, List) - * - * @param instantiation A reactor instantiation. - * - * @return The width, if it can be determined. - * @deprecated - */ - @Deprecated - public static int widthSpecification(Instantiation instantiation) { - int result = width(instantiation.getWidthSpec(), null); - if (result < 0) { - throw new InvalidSourceException("Cannot determine width for the instance " - + instantiation.getName()); - } - return result; - } + /** + * Given an instantiation of a reactor or bank of reactors, return the width. This will be 1 if + * this is not a reactor bank. Otherwise, this will attempt to determine the width. If the width + * is declared as a literal constant, it will return that constant. If the width is specified as a + * reference to a parameter, this will throw an exception. If the width is variable, this will + * find connections in the enclosing reactor and attempt to infer the width. If the width cannot + * be determined, it will throw an exception. + * + *

IMPORTANT: This method should not be used you really need to determine the width! It will + * not evaluate parameter values. + * + * @see #width(WidthSpec, List) + * @param instantiation A reactor instantiation. + * @return The width, if it can be determined. + * @deprecated + */ + @Deprecated + public static int widthSpecification(Instantiation instantiation) { + int result = width(instantiation.getWidthSpec(), null); + if (result < 0) { + throw new InvalidSourceException( + "Cannot determine width for the instance " + instantiation.getName()); + } + return result; + } - /** - * Report whether a state variable has been initialized or not. - * @param v The state variable to be checked. - * @return True if the variable was initialized, false otherwise. - */ - public static boolean isInitialized(StateVar v) { - return v != null && v.getInit() != null; - } + /** + * Report whether a state variable has been initialized or not. + * + * @param v The state variable to be checked. + * @return True if the variable was initialized, false otherwise. + */ + public static boolean isInitialized(StateVar v) { + return v != null && v.getInit() != null; + } - /** - * Report whether the given time state variable is initialized using a - * parameter or not. - * @param s A state variable. - * @return True if the argument is initialized using a parameter, false - * otherwise. - */ - public static boolean isParameterized(StateVar s) { - return s.getInit() != null && - IterableExtensions.exists(s.getInit().getExprs(), it -> it instanceof ParameterReference); - } + /** + * Report whether the given time state variable is initialized using a parameter or not. + * + * @param s A state variable. + * @return True if the argument is initialized using a parameter, false otherwise. + */ + public static boolean isParameterized(StateVar s) { + return s.getInit() != null + && IterableExtensions.exists( + s.getInit().getExprs(), it -> it instanceof ParameterReference); + } - /** - * Check if the reactor class uses generics - * @param r the reactor to check - * @return true if the reactor uses generics - */ - public static boolean isGeneric(Reactor r) { - if (r == null) { - return false; - } - return r.getTypeParms().size() != 0; - } + /** + * Check if the reactor class uses generics + * + * @param r the reactor to check + * @return true if the reactor uses generics + */ + public static boolean isGeneric(Reactor r) { + if (r == null) { + return false; + } + return r.getTypeParms().size() != 0; + } - /** - * If the specified reactor declaration is an import, then - * return the imported reactor class definition. Otherwise, - * just return the argument. - * @param r A Reactor or an ImportedReactor. - * @return The Reactor class definition or null if no definition is found. - */ - public static Reactor toDefinition(ReactorDecl r) { - if (r == null) - return null; - if (r instanceof Reactor) { - return (Reactor) r; - } else if (r instanceof ImportedReactor) { - return ((ImportedReactor) r).getReactorClass(); - } - return null; - } + /** + * If the specified reactor declaration is an import, then return the imported reactor class + * definition. Otherwise, just return the argument. + * + * @param r A Reactor or an ImportedReactor. + * @return The Reactor class definition or null if no definition is found. + */ + public static Reactor toDefinition(ReactorDecl r) { + if (r == null) return null; + if (r instanceof Reactor) { + return (Reactor) r; + } else if (r instanceof ImportedReactor) { + return ((ImportedReactor) r).getReactorClass(); + } + return null; + } - /** - * Return all single-line or multi-line comments immediately preceding the - * given EObject. - */ - public static Stream getPrecedingComments( - ICompositeNode compNode, - Predicate filter - ) { - return getPrecedingCommentNodes(compNode, filter).map(INode::getText); - } + /** Return all single-line or multi-line comments immediately preceding the given EObject. */ + public static Stream getPrecedingComments( + ICompositeNode compNode, Predicate filter) { + return getPrecedingCommentNodes(compNode, filter).map(INode::getText); + } - /** - * Return all single-line or multi-line comments immediately preceding the - * given EObject. - */ - public static Stream getPrecedingCommentNodes( - ICompositeNode compNode, - Predicate filter - ) { - if (compNode == null) return Stream.of(); - List ret = new ArrayList<>(); - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode)) { - if (isComment(node)) { - if (filter.test(node)) ret.add(node); - } else if (!node.getText().isBlank()) { - break; - } - } + /** Return all single-line or multi-line comments immediately preceding the given EObject. */ + public static Stream getPrecedingCommentNodes( + ICompositeNode compNode, Predicate filter) { + if (compNode == null) return Stream.of(); + List ret = new ArrayList<>(); + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode)) { + if (isComment(node)) { + if (filter.test(node)) ret.add(node); + } else if (!node.getText().isBlank()) { + break; } - return ret.stream(); - } - - /** Return whether {@code node} is a comment. */ - public static boolean isComment(INode node) { - return node instanceof HiddenLeafNode hlNode - && hlNode.getGrammarElement() instanceof TerminalRule tRule - && tRule.getName().endsWith("_COMMENT"); + } } + return ret.stream(); + } - /** - * Return true if the given node starts on the same line as the given other - * node. - */ - public static Predicate sameLine(ICompositeNode compNode) { - return other -> { - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { - return node.getStartLine() == other.getStartLine(); - } - } - return false; - }; - } + /** Return whether {@code node} is a comment. */ + public static boolean isComment(INode node) { + return node instanceof HiddenLeafNode hlNode + && hlNode.getGrammarElement() instanceof TerminalRule tRule + && tRule.getName().endsWith("_COMMENT"); + } - /** - * Find the main reactor and set its name if none was defined. - * @param resource The resource to find the main reactor in. - */ - public static void setMainName(Resource resource, String name) { - Reactor main = IteratorExtensions.findFirst(Iterators.filter(resource.getAllContents(), Reactor.class), - it -> it.isMain() || it.isFederated() - ); - if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { - main.setName(name); + /** Return true if the given node starts on the same line as the given other node. */ + public static Predicate sameLine(ICompositeNode compNode) { + return other -> { + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { + return node.getStartLine() == other.getStartLine(); } + } + return false; + }; + } + + /** + * Find the main reactor and set its name if none was defined. + * + * @param resource The resource to find the main reactor in. + */ + public static void setMainName(Resource resource, String name) { + Reactor main = + IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), + it -> it.isMain() || it.isFederated()); + if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { + main.setName(name); } + } - /** - * Create a new instantiation node with the given reactor as its defining class. - * @param reactor The reactor class to create an instantiation of. - */ - public static Instantiation createInstantiation(Reactor reactor) { - Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); - inst.setReactorClass(reactor); - // If the reactor is federated or at the top level, then it - // may not have a name. In the generator's doGenerate() - // method, the name gets set using setMainName(). - // But this may be called before that, e.g. during - // diagram synthesis. We assign a temporary name here. - if (reactor.getName() == null) { - if (reactor.isFederated() || reactor.isMain()) { - inst.setName("main"); - } else { - inst.setName(""); - } + /** + * Create a new instantiation node with the given reactor as its defining class. + * + * @param reactor The reactor class to create an instantiation of. + */ + public static Instantiation createInstantiation(Reactor reactor) { + Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); + inst.setReactorClass(reactor); + // If the reactor is federated or at the top level, then it + // may not have a name. In the generator's doGenerate() + // method, the name gets set using setMainName(). + // But this may be called before that, e.g. during + // diagram synthesis. We assign a temporary name here. + if (reactor.getName() == null) { + if (reactor.isFederated() || reactor.isMain()) { + inst.setName("main"); + } else { + inst.setName(""); + } + + } else { + inst.setName(reactor.getName()); + } + return inst; + } - } else { - inst.setName(reactor.getName()); - } - return inst; - } + /** + * Returns the target declaration in the given model. Non-null because it would cause a parse + * error. + */ + public static TargetDecl targetDecl(Model model) { + return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); + } - /** - * Returns the target declaration in the given model. - * Non-null because it would cause a parse error. - */ - public static TargetDecl targetDecl(Model model) { - return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); - } + /** + * Returns the target declaration in the given resource. Non-null because it would cause a parse + * error. + */ + public static TargetDecl targetDecl(Resource model) { + return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); + } - /** - * Returns the target declaration in the given resource. - * Non-null because it would cause a parse error. - */ - public static TargetDecl targetDecl(Resource model) { - return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); - } + ///////////////////////////////////////////////////////// + //// Private methods - ///////////////////////////////////////////////////////// - //// Private methods + /** Returns the list if it is not null. Otherwise, return an empty list. */ + public static List convertToEmptyListIfNull(List list) { + return list != null ? list : new ArrayList<>(); + } - /** - * Returns the list if it is not null. Otherwise, return an empty list. - */ - public static List convertToEmptyListIfNull(List list) { - return list != null ? list : new ArrayList<>(); - } + /** + * Return all the superclasses of the specified reactor in deepest-first order. For example, if A + * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates + * are removed. If the specified reactor does not extend any other reactor, then return an empty + * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared + * that is not found, then return null. + * + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor (used to detect circular + * extensions). + */ + private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet baseExtends = superClasses(r, extensions); + extensions.remove(r); + if (baseExtends == null) return null; + result.addAll(baseExtends); + result.add(r); + } + return result; + } - /** - * Return all the superclasses of the specified reactor - * in deepest-first order. For example, if A extends B and C, and - * B and C both extend D, this will return the list [D, B, C, A]. - * Duplicates are removed. If the specified reactor does not extend - * any other reactor, then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - * @param extensions A set of reactors extending the specified reactor - * (used to detect circular extensions). - */ - private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { - LinkedHashSet result = new LinkedHashSet<>(); - for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { - Reactor r = toDefinition(superDecl); - if (r == reactor || r == null) return null; - // If r is in the extensions, then we have a circular inheritance structure. - if (extensions.contains(r)) return null; - extensions.add(r); - LinkedHashSet baseExtends = superClasses(r, extensions); - extensions.remove(r); - if (baseExtends == null) return null; - result.addAll(baseExtends); - result.add(r); + /** + * We may be able to infer the width by examining the connections of the enclosing reactor + * definition. This works, for example, with delays between multiports or banks of reactors. + * Attempt to infer the width from connections and return -1 if the width cannot be inferred. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * @return The width, or -1 if the width could not be inferred from connections. + */ + private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { + for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : c.getLeftPorts()) { + if (leftPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the left. + leftOrRight = -1; + } else { + leftWidth += inferPortWidth(leftPort, c, instantiations); } - return result; - } - - /** - * We may be able to infer the width by examining the connections of - * the enclosing reactor definition. This works, for example, with - * delays between multiports or banks of reactors. - * Attempt to infer the width from connections and return -1 if the width cannot be inferred. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * - * @return The width, or -1 if the width could not be inferred from connections. - */ - private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { - for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : c.getLeftPorts()) { - if (leftPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the left. - leftOrRight = -1; - } else { - leftWidth += inferPortWidth(leftPort, c, instantiations); - } - } - for (VarRef rightPort : c.getRightPorts()) { - if (rightPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the right. - leftOrRight = 1; - } else { - rightWidth += inferPortWidth(rightPort, c, instantiations); - } - } - if (leftOrRight < 0) { - return rightWidth - leftWidth; - } else if (leftOrRight > 0) { - return leftWidth - rightWidth; - } + } + for (VarRef rightPort : c.getRightPorts()) { + if (rightPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the right. + leftOrRight = 1; + } else { + rightWidth += inferPortWidth(rightPort, c, instantiations); } - // A connection was not found with the instantiation. - return -1; - } + } + if (leftOrRight < 0) { + return rightWidth - leftWidth; + } else if (leftOrRight > 0) { + return leftWidth - rightWidth; + } + } + // A connection was not found with the instantiation. + return -1; + } - public static void addReactionAttribute(Reaction reaction, String name) { - var fedAttr = factory.createAttribute(); - fedAttr.setAttrName(name); - reaction.getAttributes().add(fedAttr); - } -} \ No newline at end of file + public static void addReactionAttribute(Reaction reaction, String name) { + var fedAttr = factory.createAttribute(); + fedAttr.setAttrName(name); + reaction.getAttributes().add(fedAttr); + } +} diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 3a7a5fb2cd..73cd12916a 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -275,20 +275,20 @@ public Boolean caseAttrParm(AttrParm object) { .conclusion; } - @Override - public Boolean caseReaction(Reaction object) { - return new ComparisonMachine<>(object, Reaction.class) - .listsEquivalent(Reaction::getAttributes) - .listsEquivalent(Reaction::getTriggers) - .listsEquivalent(Reaction::getSources) - .listsEquivalent(Reaction::getEffects) - .equalAsObjects(Reaction::isMutation) - .equalAsObjects(Reaction::getName) - .equivalent(Reaction::getCode) - .equivalent(Reaction::getStp) - .equivalent(Reaction::getDeadline) - .conclusion; - } + @Override + public Boolean caseReaction(Reaction object) { + return new ComparisonMachine<>(object, Reaction.class) + .listsEquivalent(Reaction::getAttributes) + .listsEquivalent(Reaction::getTriggers) + .listsEquivalent(Reaction::getSources) + .listsEquivalent(Reaction::getEffects) + .equalAsObjects(Reaction::isMutation) + .equalAsObjects(Reaction::getName) + .equivalent(Reaction::getCode) + .equivalent(Reaction::getStp) + .equivalent(Reaction::getDeadline) + .conclusion; + } @Override public Boolean caseTriggerRef(TriggerRef object) { diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 52e2a5794b..b3bf51d836 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -66,21 +66,18 @@ import org.lflang.lf.WidthSpec; /** - * Representation of a compile-time instance of a reactor. - * If the reactor is instantiated as a bank of reactors, or if any - * of its parents is instantiated as a bank of reactors, then one instance - * of this ReactorInstance class represents all the runtime instances within - * these banks. The {@link #getTotalWidth()} method returns the number of such - * runtime instances, which is the product of the bank width of this reactor - * instance and the bank widths of all of its parents. - * There is exactly one instance of this ReactorInstance class for each - * graphical rendition of a reactor in the diagram view. + * Representation of a compile-time instance of a reactor. If the reactor is instantiated as a bank + * of reactors, or if any of its parents is instantiated as a bank of reactors, then one instance of + * this ReactorInstance class represents all the runtime instances within these banks. The {@link + * #getTotalWidth()} method returns the number of such runtime instances, which is the product of + * the bank width of this reactor instance and the bank widths of all of its parents. There is + * exactly one instance of this ReactorInstance class for each graphical rendition of a reactor in + * the diagram view. * - * For the main reactor, which has no parent, once constructed, - * this object represents the entire Lingua Franca program. - * If the program has causality loops (a programming error), then - * {@link #hasCycles()} will return true and {@link #getCycles()} will - * return the ports and reaction instances involved in the cycles. + *

For the main reactor, which has no parent, once constructed, this object represents the entire + * Lingua Franca program. If the program has causality loops (a programming error), then {@link + * #hasCycles()} will return true and {@link #getCycles()} will return the ports and reaction + * instances involved in the cycles. * * @author Marten Lohstroh * @author Edward A. Lee @@ -264,45 +261,45 @@ public PortInstance getInput(String name) { return null; } - /** - * Return the set of ReactionInstance and PortInstance that form causality - * loops in the topmost parent reactor in the instantiation hierarchy. This will return an - * empty set if there are no causality loops. - */ - public Set> getCycles() { - if (depth != 0) return root().getCycles(); - if (cachedCycles != null) return cachedCycles; - cachedCycles = new LinkedHashSet<>(); - - ReactionInstanceGraph reactionRuntimes = assignLevels(); - if (reactionRuntimes.nodes().size() > 0) { - Set reactions = new LinkedHashSet<>(); - Set ports = new LinkedHashSet<>(); - // There are cycles. But the nodes set includes not - // just the cycles, but also nodes that are downstream of the - // cycles. Use Tarjan's algorithm to get just the cycles. - var cycleNodes = reactionRuntimes.getCycles(); - for (var cycle : cycleNodes) { - for (ReactionInstance.Runtime runtime : cycle) { - reactions.add(runtime.getReaction()); - } - } - // Need to figure out which ports are involved in the cycles. - // It may not be all ports that depend on this reaction. - for (ReactionInstance r : reactions) { - for (TriggerInstance p : r.effects) { - if (p instanceof PortInstance) { - findPaths((PortInstance)p, reactions, ports); - } - } - } - cachedCycles.addAll(reactions); - cachedCycles.addAll(ports); + /** + * Return the set of ReactionInstance and PortInstance that form causality loops in the topmost + * parent reactor in the instantiation hierarchy. This will return an empty set if there are no + * causality loops. + */ + public Set> getCycles() { + if (depth != 0) return root().getCycles(); + if (cachedCycles != null) return cachedCycles; + cachedCycles = new LinkedHashSet<>(); + + ReactionInstanceGraph reactionRuntimes = assignLevels(); + if (reactionRuntimes.nodes().size() > 0) { + Set reactions = new LinkedHashSet<>(); + Set ports = new LinkedHashSet<>(); + // There are cycles. But the nodes set includes not + // just the cycles, but also nodes that are downstream of the + // cycles. Use Tarjan's algorithm to get just the cycles. + var cycleNodes = reactionRuntimes.getCycles(); + for (var cycle : cycleNodes) { + for (ReactionInstance.Runtime runtime : cycle) { + reactions.add(runtime.getReaction()); } - - return cachedCycles; + } + // Need to figure out which ports are involved in the cycles. + // It may not be all ports that depend on this reaction. + for (ReactionInstance r : reactions) { + for (TriggerInstance p : r.effects) { + if (p instanceof PortInstance) { + findPaths((PortInstance) p, reactions, ports); + } + } + } + cachedCycles.addAll(reactions); + cachedCycles.addAll(ports); } + return cachedCycles; + } + /** * Override the base class to append [i_d], where d is the depth, if this reactor is in a bank of * reactors. @@ -448,51 +445,52 @@ public Expression resolveParameters(Expression e) { return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); } - private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { + private static final class ParameterInliner + extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { static final ParameterInliner INSTANCE = new ParameterInliner(); @Override public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { - if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { - throw new IllegalArgumentException("Parameter " + if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { + throw new IllegalArgumentException( + "Parameter " + expr.getParameter().getName() + " is not a parameter of reactor instance " + instance.getName() - + "." - ); - } - - Optional assignment = - instance.definition.getParameters().stream() - .filter(it -> it.getLhs().equals(expr.getParameter())) - .findAny(); // There is at most one + + "."); + } - if (assignment.isPresent()) { - // replace the parameter with its value. - Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); - // recursively resolve parameters - return instance.getParent().resolveParameters(value); - } else { - // In that case use the default value. Default values - // cannot use parameter values, so they don't need to - // be recursively resolved. - Initializer init = expr.getParameter().getInit(); - Expression defaultValue = ASTUtils.asSingleExpr(init); - if (defaultValue == null) { - // this is a problem - return super.visitParameterRef(expr, instance); - } - return defaultValue; + Optional assignment = + instance.definition.getParameters().stream() + .filter(it -> it.getLhs().equals(expr.getParameter())) + .findAny(); // There is at most one + + if (assignment.isPresent()) { + // replace the parameter with its value. + Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); + // recursively resolve parameters + return instance.getParent().resolveParameters(value); + } else { + // In that case use the default value. Default values + // cannot use parameter values, so they don't need to + // be recursively resolved. + Initializer init = expr.getParameter().getInit(); + Expression defaultValue = ASTUtils.asSingleExpr(init); + if (defaultValue == null) { + // this is a problem + return super.visitParameterRef(expr, instance); } + return defaultValue; + } } -} + } - // /** - // * Return the startup trigger or null if not used in any reaction. - // */ - // public TriggerInstance getStartupTrigger() { - // return _instantiations; - // } + // /** + // * Return the startup trigger or null if not used in any reaction. + // */ + // public TriggerInstance getStartupTrigger() { + // return _instantiations; + // } /////////////////////////////////////////////////// //// Methods for finding instances in this reactor given an AST node. @@ -670,21 +668,21 @@ public TimeValue getTimeValue(Expression expr) { protected void createReactionInstances() { List reactions = ASTUtils.allReactions(reactorDefinition); if (reactions != null) { - int count = 0; + int count = 0; - // Check for startup and shutdown triggers. - for (Reaction reaction : reactions) { - if (AttributeUtils.isUnordered(reaction)) { - unorderedReactions.add(reaction); - } - // Create the reaction instance. - var reactionInstance = new ReactionInstance(reaction, this, - unorderedReactions.contains(reaction), count++); - - // Add the reaction instance to the map of reactions for this - // reactor. - this.reactions.add(reactionInstance); + // Check for startup and shutdown triggers. + for (Reaction reaction : reactions) { + if (AttributeUtils.isUnordered(reaction)) { + unorderedReactions.add(reaction); } + // Create the reaction instance. + var reactionInstance = + new ReactionInstance(reaction, this, unorderedReactions.contains(reaction), count++); + + // Add the reaction instance to the map of reactions for this + // reactor. + this.reactions.add(reactionInstance); + } } } @@ -692,14 +690,14 @@ protected void createReactionInstances() { protected void createWatchdogInstances() { List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); if (watchdogs != null) { - for (Watchdog watchdog : watchdogs) { - // Create the watchdog instance. - var watchdogInstance = new WatchdogInstance(watchdog, this); + for (Watchdog watchdog : watchdogs) { + // Create the watchdog instance. + var watchdogInstance = new WatchdogInstance(watchdog, this); - // Add the watchdog instance to the list of watchdogs for this - // reactor. - this.watchdogs.add(watchdogInstance); - } + // Add the watchdog instance to the list of watchdogs for this + // reactor. + this.watchdogs.add(watchdogInstance); + } } } @@ -716,172 +714,167 @@ protected void createWatchdogInstances() { * @param desiredDepth The depth to which to expand the hierarchy. */ private ReactorInstance( - Instantiation definition, - ReactorInstance parent, - ErrorReporter reporter, - int desiredDepth) { - super(definition, parent); - this.reporter = reporter; - this.reactorDeclaration = definition.getReactorClass(); - this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - - // check for recursive instantiation - var currentParent = parent; - var foundSelfAsParent = false; - do { - if (currentParent != null) { - if (currentParent.reactorDefinition == this.reactorDefinition) { - foundSelfAsParent = true; - currentParent = null; // break - } else { - currentParent = currentParent.parent; - } - } - } while(currentParent != null); - - this.recursive = foundSelfAsParent; - if (recursive) { - reporter.reportError(definition, "Recursive reactor instantiation."); + Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth) { + super(definition, parent); + this.reporter = reporter; + this.reactorDeclaration = definition.getReactorClass(); + this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); + + // check for recursive instantiation + var currentParent = parent; + var foundSelfAsParent = false; + do { + if (currentParent != null) { + if (currentParent.reactorDefinition == this.reactorDefinition) { + foundSelfAsParent = true; + currentParent = null; // break + } else { + currentParent = currentParent.parent; } + } + } while (currentParent != null); - // If the reactor definition is null, give up here. Otherwise, diagram generation - // will fail an NPE. - if (reactorDefinition == null) { - reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); - return; - } + this.recursive = foundSelfAsParent; + if (recursive) { + reporter.reportError(definition, "Recursive reactor instantiation."); + } - setInitialWidth(); + // If the reactor definition is null, give up here. Otherwise, diagram generation + // will fail an NPE. + if (reactorDefinition == null) { + reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); + return; + } - // Apply overrides and instantiate parameters for this reactor instance. - for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { - this.parameters.add(new ParameterInstance(parameter, this)); - } + setInitialWidth(); - // Instantiate inputs for this reactor instance - for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { - this.inputs.add(new PortInstance(inputDecl, this, reporter)); - } + // Apply overrides and instantiate parameters for this reactor instance. + for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { + this.parameters.add(new ParameterInstance(parameter, this)); + } - // Instantiate outputs for this reactor instance - for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { - this.outputs.add(new PortInstance(outputDecl, this, reporter)); - } + // Instantiate inputs for this reactor instance + for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { + this.inputs.add(new PortInstance(inputDecl, this, reporter)); + } - // Do not process content (except interface above) if recursive - if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { - // Instantiate children for this reactor instance. - // While doing this, assign an index offset to each. - for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { - var childInstance = new ReactorInstance( - child, - this, - reporter, - desiredDepth - ); - this.children.add(childInstance); - } + // Instantiate outputs for this reactor instance + for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { + this.outputs.add(new PortInstance(outputDecl, this, reporter)); + } - // Instantiate timers for this reactor instance - for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { - this.timers.add(new TimerInstance(timerDecl, this)); - } + // Do not process content (except interface above) if recursive + if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { + // Instantiate children for this reactor instance. + // While doing this, assign an index offset to each. + for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { + var childInstance = new ReactorInstance(child, this, reporter, desiredDepth); + this.children.add(childInstance); + } - // Instantiate actions for this reactor instance - for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { - this.actions.add(new ActionInstance(actionDecl, this)); - } + // Instantiate timers for this reactor instance + for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { + this.timers.add(new TimerInstance(timerDecl, this)); + } - establishPortConnections(); + // Instantiate actions for this reactor instance + for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { + this.actions.add(new ActionInstance(actionDecl, this)); + } - // Create the reaction instances in this reactor instance. - // This also establishes all the implied dependencies. - // Note that this can only happen _after_ the children, - // port, action, and timer instances have been created. - createReactionInstances(); + establishPortConnections(); - // Instantiate modes for this reactor instance - // This must come after the child elements (reactions, etc) of this reactor - // are created in order to allow their association with modes - for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { - this.modes.add(new ModeInstance(modeDecl, this)); - } - for (ModeInstance mode : this.modes) { - mode.setupTranstions(); - } - } + // Create the reaction instances in this reactor instance. + // This also establishes all the implied dependencies. + // Note that this can only happen _after_ the children, + // port, action, and timer instances have been created. + createReactionInstances(); + + // Instantiate modes for this reactor instance + // This must come after the child elements (reactions, etc) of this reactor + // are created in order to allow their association with modes + for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { + this.modes.add(new ModeInstance(modeDecl, this)); + } + for (ModeInstance mode : this.modes) { + mode.setupTranstions(); + } } + } - /** - * Return a list of Instantiation objects for evaluating parameter - * values. The first object in the list is the AST Instantiation - * that created this reactor instance, the second is the AST instantiation - * that created the containing reactor instance, and so on until there - * are no more containing reactor instances. This will return an empty - * list if this reactor instance is at the top level (is main). - */ - public List instantiations() { - if (_instantiations == null) { - _instantiations = new ArrayList<>(); - if (definition != null) { - _instantiations.add(definition); - if (parent != null) { - _instantiations.addAll(parent.instantiations()); - } - } + /** + * Return a list of Instantiation objects for evaluating parameter values. The first object in the + * list is the AST Instantiation that created this reactor instance, the second is the AST + * instantiation that created the containing reactor instance, and so on until there are no more + * containing reactor instances. This will return an empty list if this reactor instance is at the + * top level (is main). + */ + public List instantiations() { + if (_instantiations == null) { + _instantiations = new ArrayList<>(); + if (definition != null) { + _instantiations.add(definition); + if (parent != null) { + _instantiations.addAll(parent.instantiations()); } - return _instantiations; + } } + return _instantiations; + } - /** - * Returns true if this is a bank of reactors. - * @return true if a reactor is a bank, false otherwise - */ - public boolean isBank() { - return definition.getWidthSpec() != null; - } + /** + * Returns true if this is a bank of reactors. + * + * @return true if a reactor is a bank, false otherwise + */ + public boolean isBank() { + return definition.getWidthSpec() != null; + } - /** - * Returns whether this is a main or federated reactor. - * @return true if reactor definition is marked as main or federated, false otherwise. - */ - public boolean isMainOrFederated() { - return reactorDefinition != null - && (reactorDefinition.isMain() || reactorDefinition.isFederated()); - } + /** + * Returns whether this is a main or federated reactor. + * + * @return true if reactor definition is marked as main or federated, false otherwise. + */ + public boolean isMainOrFederated() { + return reactorDefinition != null + && (reactorDefinition.isMain() || reactorDefinition.isFederated()); + } - /** - * Return true if the specified reactor instance is either equal to this - * reactor instance or a parent of it. - * @param r The reactor instance. - */ - public boolean isParent(ReactorInstance r) { - ReactorInstance p = this; - while (p != null) { - if (p == r) return true; - p = p.getParent(); - } - return false; + /** + * Return true if the specified reactor instance is either equal to this reactor instance or a + * parent of it. + * + * @param r The reactor instance. + */ + public boolean isParent(ReactorInstance r) { + ReactorInstance p = this; + while (p != null) { + if (p == r) return true; + p = p.getParent(); } + return false; + } - /////////////////////////////////////////////////// - //// Methods for finding instances in this reactor given an AST node. - - /** - * Return the action instance within this reactor - * instance corresponding to the specified action reference. - * @param action The action as an AST node. - * @return The corresponding action instance or null if the - * action does not belong to this reactor. - */ - public ActionInstance lookupActionInstance(Action action) { - for (ActionInstance actionInstance : actions) { - if (actionInstance.definition == action) { - return actionInstance; - } - } - return null; + /////////////////////////////////////////////////// + //// Methods for finding instances in this reactor given an AST node. + + /** + * Return the action instance within this reactor instance corresponding to the specified action + * reference. + * + * @param action The action as an AST node. + * @return The corresponding action instance or null if the action does not belong to this + * reactor. + */ + public ActionInstance lookupActionInstance(Action action) { + for (ActionInstance actionInstance : actions) { + if (actionInstance.definition == action) { + return actionInstance; + } } + return null; + } ////////////////////////////////////////////////////// //// Private methods. @@ -903,100 +896,100 @@ public static void connectPortInstances( dst.instance.dependsOnPorts.add(src); } - ////////////////////////////////////////////////////// - //// Protected methods. + ////////////////////////////////////////////////////// + //// Protected methods. - /** - * Returns the built-in trigger or create a new one if none exists. - */ - protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { - return builtinTriggers.computeIfAbsent(trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); - } + /** Returns the built-in trigger or create a new one if none exists. */ + protected TriggerInstance getOrCreateBuiltinTrigger( + BuiltinTriggerRef trigger) { + return builtinTriggers.computeIfAbsent( + trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + } - /** - * Populate connectivity information in the port instances. - * Note that this can only happen _after_ the children and port instances have been created. - * Unfortunately, we have to do some complicated things here - * to support multiport-to-multiport, multiport-to-bank, - * and bank-to-multiport communication. The principle being followed is: - * in each connection statement, for each port instance on the left, - * connect to the next available port on the right. - */ - private void establishPortConnections() { - for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { - List> leftPorts = listPortInstances(connection.getLeftPorts(), connection); - Iterator> srcRanges = leftPorts.iterator(); - List> rightPorts = listPortInstances(connection.getRightPorts(), connection); - Iterator> dstRanges = rightPorts.iterator(); - - // Check for empty lists. - if (!srcRanges.hasNext()) { - if (dstRanges.hasNext()) { - reporter.reportWarning(connection, "No sources to provide inputs."); - } - return; - } else if (!dstRanges.hasNext()) { - reporter.reportWarning(connection, "No destination. Outputs will be lost."); - return; - } + /** + * Populate connectivity information in the port instances. Note that this can only happen _after_ + * the children and port instances have been created. Unfortunately, we have to do some + * complicated things here to support multiport-to-multiport, multiport-to-bank, and + * bank-to-multiport communication. The principle being followed is: in each connection statement, + * for each port instance on the left, connect to the next available port on the right. + */ + private void establishPortConnections() { + for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { + List> leftPorts = + listPortInstances(connection.getLeftPorts(), connection); + Iterator> srcRanges = leftPorts.iterator(); + List> rightPorts = + listPortInstances(connection.getRightPorts(), connection); + Iterator> dstRanges = rightPorts.iterator(); + + // Check for empty lists. + if (!srcRanges.hasNext()) { + if (dstRanges.hasNext()) { + reporter.reportWarning(connection, "No sources to provide inputs."); + } + return; + } else if (!dstRanges.hasNext()) { + reporter.reportWarning(connection, "No destination. Outputs will be lost."); + return; + } - RuntimeRange src = srcRanges.next(); - RuntimeRange dst = dstRanges.next(); - - while(true) { - if (dst.width == src.width) { - connectPortInstances(src, dst, connection); - if (!dstRanges.hasNext()) { - if (srcRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Source is wider than the destination. Outputs will be lost."); - } - break; - } - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - if (dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Destination is wider than the source. Inputs will be missing."); - } - break; - } - } - dst = dstRanges.next(); - src = srcRanges.next(); - } else if (dst.width < src.width) { - // Split the left (src) range in two. - connectPortInstances(src.head(dst.width), dst, connection); - src = src.tail(dst.width); - if (!dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Source is wider than the destination. Outputs will be lost."); - break; - } - dst = dstRanges.next(); - } else if (src.width < dst.width) { - // Split the right (dst) range in two. - connectPortInstances(src, dst.head(src.width), connection); - dst = dst.tail(src.width); - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - reporter.reportWarning(connection, - "Destination is wider than the source. Inputs will be missing."); - break; - } - } - src = srcRanges.next(); - } + RuntimeRange src = srcRanges.next(); + RuntimeRange dst = dstRanges.next(); + + while (true) { + if (dst.width == src.width) { + connectPortInstances(src, dst, connection); + if (!dstRanges.hasNext()) { + if (srcRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Source is wider than the destination. Outputs will be lost."); + } + break; + } + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + if (dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Destination is wider than the source. Inputs will be missing."); + } + break; + } + } + dst = dstRanges.next(); + src = srcRanges.next(); + } else if (dst.width < src.width) { + // Split the left (src) range in two. + connectPortInstances(src.head(dst.width), dst, connection); + src = src.tail(dst.width); + if (!dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Source is wider than the destination. Outputs will be lost."); + break; + } + dst = dstRanges.next(); + } else if (src.width < dst.width) { + // Split the right (dst) range in two. + connectPortInstances(src, dst.head(src.width), connection); + dst = dst.tail(src.width); + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + reporter.reportWarning( + connection, "Destination is wider than the source. Inputs will be missing."); + break; } + } + src = srcRanges.next(); } + } } + } /** * If path exists from the specified port to any reaction in the specified set of reactions, then @@ -1044,93 +1037,91 @@ private boolean findPaths( */ private List> listPortInstances( List references, Connection connection) { - List> result = new ArrayList<>(); - List> tails = new LinkedList<>(); - int count = 0; - for (VarRef portRef : references) { - // Simple error checking first. - if (!(portRef.getVariable() instanceof Port)) { - reporter.reportError(portRef, "Not a port."); - return result; - } - // First, figure out which reactor we are dealing with. - // The reactor we want is the container of the port. - // If the port reference has no container, then the reactor is this one. - var reactor = this; - if (portRef.getContainer() != null) { - reactor = getChildReactorInstance(portRef.getContainer()); - } - // The reactor can be null only if there is an error in the code. - // Skip this portRef so that diagram synthesis can complete. - if (reactor != null) { - PortInstance portInstance = reactor.lookupPortInstance( - (Port) portRef.getVariable()); - - Set interleaved = new LinkedHashSet<>(); - if (portRef.isInterleaved()) { - // NOTE: Here, we are assuming that the interleaved() - // keyword is only allowed on the multiports contained by - // contained reactors. - interleaved.add(portInstance.parent); - } - RuntimeRange range = new RuntimeRange.Port( - portInstance, interleaved); - // If this portRef is not the last one in the references list - // then we have to check whether the range can be incremented at - // the lowest two levels (port and container). If not, - // split the range and add the tail to list to iterate over again. - // The reason for this is that the connection has only local visibility, - // but the range width may be reflective of bank structure higher - // in the hierarchy. - if (count < references.size() - 1) { - int portWidth = portInstance.width; - int portParentWidth = portInstance.parent.width; - // If the port is being connected on the inside and there is - // more than one port in the list, then we can only connect one - // bank member at a time. - if (reactor == this && references.size() > 1) { - portParentWidth = 1; - } - int widthBound = portWidth * portParentWidth; - - // If either of these widths cannot be determined, assume infinite. - if (portWidth < 0) widthBound = Integer.MAX_VALUE; - if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < range.width) { - // Need to split the range. - tails.add(range.tail(widthBound)); - range = range.head(widthBound); - } - } - result.add(range); - } + List> result = new ArrayList<>(); + List> tails = new LinkedList<>(); + int count = 0; + for (VarRef portRef : references) { + // Simple error checking first. + if (!(portRef.getVariable() instanceof Port)) { + reporter.reportError(portRef, "Not a port."); + return result; + } + // First, figure out which reactor we are dealing with. + // The reactor we want is the container of the port. + // If the port reference has no container, then the reactor is this one. + var reactor = this; + if (portRef.getContainer() != null) { + reactor = getChildReactorInstance(portRef.getContainer()); + } + // The reactor can be null only if there is an error in the code. + // Skip this portRef so that diagram synthesis can complete. + if (reactor != null) { + PortInstance portInstance = reactor.lookupPortInstance((Port) portRef.getVariable()); + + Set interleaved = new LinkedHashSet<>(); + if (portRef.isInterleaved()) { + // NOTE: Here, we are assuming that the interleaved() + // keyword is only allowed on the multiports contained by + // contained reactors. + interleaved.add(portInstance.parent); } - // Iterate over the tails. - while(tails.size() > 0) { - List> moreTails = new LinkedList<>(); - count = 0; - for (RuntimeRange tail : tails) { - if (count < tails.size() - 1) { - int widthBound = tail.instance.width; - if (tail._interleaved.contains(tail.instance.parent)) { - widthBound = tail.instance.parent.width; - } - // If the width cannot be determined, assume infinite. - if (widthBound < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < tail.width) { - // Need to split the range again - moreTails.add(tail.tail(widthBound)); - tail = tail.head(widthBound); - } - } - result.add(tail); - } - tails = moreTails; + RuntimeRange range = new RuntimeRange.Port(portInstance, interleaved); + // If this portRef is not the last one in the references list + // then we have to check whether the range can be incremented at + // the lowest two levels (port and container). If not, + // split the range and add the tail to list to iterate over again. + // The reason for this is that the connection has only local visibility, + // but the range width may be reflective of bank structure higher + // in the hierarchy. + if (count < references.size() - 1) { + int portWidth = portInstance.width; + int portParentWidth = portInstance.parent.width; + // If the port is being connected on the inside and there is + // more than one port in the list, then we can only connect one + // bank member at a time. + if (reactor == this && references.size() > 1) { + portParentWidth = 1; + } + int widthBound = portWidth * portParentWidth; + + // If either of these widths cannot be determined, assume infinite. + if (portWidth < 0) widthBound = Integer.MAX_VALUE; + if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < range.width) { + // Need to split the range. + tails.add(range.tail(widthBound)); + range = range.head(widthBound); + } } - return result; + result.add(range); + } + } + // Iterate over the tails. + while (tails.size() > 0) { + List> moreTails = new LinkedList<>(); + count = 0; + for (RuntimeRange tail : tails) { + if (count < tails.size() - 1) { + int widthBound = tail.instance.width; + if (tail._interleaved.contains(tail.instance.parent)) { + widthBound = tail.instance.parent.width; + } + // If the width cannot be determined, assume infinite. + if (widthBound < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < tail.width) { + // Need to split the range again + moreTails.add(tail.tail(widthBound)); + tail = tail.head(widthBound); + } + } + result.add(tail); + } + tails = moreTails; } + return result; + } /** * If this is a bank of reactors, set the width. It will be set to -1 if it cannot be determined. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e344e9f873..b26b3061c0 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1,22 +1,22 @@ /************* -Copyright (c) 2019-2021, The University of California at Berkeley. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2021, The University of California at Berkeley. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator.c; @@ -31,6 +31,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import static org.lflang.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -41,33 +43,26 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; - import org.lflang.ASTUtils; -import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; - -import org.lflang.federated.extensions.CExtensionUtils; - import org.lflang.ast.DelayedConnectionTransformation; - +import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.DelayBodyGenerator; +import org.lflang.generator.DockerComposeGenerator; import org.lflang.generator.DockerGenerator; import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorUtils; - -import org.lflang.generator.DelayBodyGenerator; - import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFResource; import org.lflang.generator.ParameterInstance; @@ -78,7 +73,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.TimerInstance; import org.lflang.generator.TriggerInstance; import org.lflang.generator.WatchdogInstance; - import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Input; @@ -93,206 +87,171 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.StateVar; import org.lflang.lf.Variable; import org.lflang.lf.Watchdog; - import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; - /** - * Generator for C target. This class generates C code defining each reactor - * class given in the input .lf file and imported .lf files. The generated code - * has the following components: + * Generator for C target. This class generates C code defining each reactor class given in the + * input .lf file and imported .lf files. The generated code has the following components: * - * * A typedef for inputs, outputs, and actions of each reactor class. These - * define the types of the variables that reactions use to access inputs and - * action values and to set output values. + *

* A typedef for inputs, outputs, and actions of each reactor class. These define the types of + * the variables that reactions use to access inputs and action values and to set output values. * - * * A typedef for a "self" struct for each reactor class. One instance of this - * struct will be created for each reactor instance. See below for details. + *

* A typedef for a "self" struct for each reactor class. One instance of this struct will be + * created for each reactor instance. See below for details. * - * * A function definition for each reaction in each reactor class. These - * functions take an instance of the self struct as an argument. + *

* A function definition for each reaction in each reactor class. These functions take an + * instance of the self struct as an argument. * - * * A constructor function for each reactor class. This is used to create - * a new instance of the reactor. + *

* A constructor function for each reactor class. This is used to create a new instance of the + * reactor. * - * After these, the main generated function is `_lf_initialize_trigger_objects()`. - * This function creates the instances of reactors (using their constructors) - * and makes connections between them. + *

After these, the main generated function is `_lf_initialize_trigger_objects()`. This function + * creates the instances of reactors (using their constructors) and makes connections between them. * - * A few other smaller functions are also generated. + *

A few other smaller functions are also generated. * - * ## Self Struct + *

## Self Struct * - * The "self" struct has fields for each of the following: + *

The "self" struct has fields for each of the following: * - * * parameter: the field name and type match the parameter. - * * state: the field name and type match the state. - * * action: the field name prepends the action name with "_lf_". - * A second field for the action is also created to house the trigger_t object. - * That second field prepends the action name with "_lf__". - * * output: the field name prepends the output name with "_lf_". - * * input: the field name prepends the output name with "_lf_". - * A second field for the input is also created to house the trigger_t object. - * That second field prepends the input name with "_lf__". + *

* parameter: the field name and type match the parameter. * state: the field name and type + * match the state. * action: the field name prepends the action name with "_lf_". A second field + * for the action is also created to house the trigger_t object. That second field prepends the + * action name with "_lf__". * output: the field name prepends the output name with "_lf_". * input: + * the field name prepends the output name with "_lf_". A second field for the input is also created + * to house the trigger_t object. That second field prepends the input name with "_lf__". * - * If, in addition, the reactor contains other reactors and reacts to their outputs, - * then there will be a struct within the self struct for each such contained reactor. - * The name of that self struct will be the name of the contained reactor prepended with "_lf_". - * That inside struct will contain pointers the outputs of the contained reactors - * that are read together with pointers to booleans indicating whether those outputs are present. + *

If, in addition, the reactor contains other reactors and reacts to their outputs, then there + * will be a struct within the self struct for each such contained reactor. The name of that self + * struct will be the name of the contained reactor prepended with "_lf_". That inside struct will + * contain pointers the outputs of the contained reactors that are read together with pointers to + * booleans indicating whether those outputs are present. * - * If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to - * trigger_t object (see reactor.h) for the shutdown event and an action struct named - * _lf_shutdown on the self struct. + *

If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to + * trigger_t object (see reactor.h) for the shutdown event and an action struct named _lf_shutdown + * on the self struct. * - * ## Reaction Functions + *

## Reaction Functions * - * For each reaction in a reactor class, this generator will produce a C function - * that expects a pointer to an instance of the "self" struct as an argument. - * This function will contain verbatim the C code specified in the reaction, but - * before that C code, the generator inserts a few lines of code that extract from the - * self struct the variables that that code has declared it will use. For example, if - * the reaction declares that it is triggered by or uses an input named "x" of type - * int, the function will contain a line like this: - * ``` - * r_x_t* x = self->_lf_x; - * ``` - * where `r` is the full name of the reactor class and the struct type `r_x_t` - * has fields `is_present` and `value`, where the type of `value` matches the port type. - * If the programmer fails to declare that it uses x, then the absence of the - * above code will trigger a compile error when the verbatim code attempts to read `x`. + *

For each reaction in a reactor class, this generator will produce a C function that expects a + * pointer to an instance of the "self" struct as an argument. This function will contain verbatim + * the C code specified in the reaction, but before that C code, the generator inserts a few lines + * of code that extract from the self struct the variables that that code has declared it will use. + * For example, if the reaction declares that it is triggered by or uses an input named "x" of type + * int, the function will contain a line like this: ``` r_x_t* x = self->_lf_x; ``` where `r` is the + * full name of the reactor class and the struct type `r_x_t` has fields `is_present` and `value`, + * where the type of `value` matches the port type. If the programmer fails to declare that it uses + * x, then the absence of the above code will trigger a compile error when the verbatim code + * attempts to read `x`. * - * ## Constructor + *

## Constructor * - * For each reactor class, this generator will create a constructor function named - * `new_r`, where `r` is the reactor class name. This function will malloc and return - * a pointer to an instance of the "self" struct. This struct initially represents - * an unconnected reactor. To establish connections between reactors, additional - * information needs to be inserted (see below). The self struct is made visible - * to the body of a reaction as a variable named "self". The self struct contains the - * following: + *

For each reactor class, this generator will create a constructor function named `new_r`, where + * `r` is the reactor class name. This function will malloc and return a pointer to an instance of + * the "self" struct. This struct initially represents an unconnected reactor. To establish + * connections between reactors, additional information needs to be inserted (see below). The self + * struct is made visible to the body of a reaction as a variable named "self". The self struct + * contains the following: * - * * Parameters: For each parameter `p` of the reactor, there will be a field `p` - * with the type and value of the parameter. So C code in the body of a reaction - * can access parameter values as `self->p`. + *

* Parameters: For each parameter `p` of the reactor, there will be a field `p` with the type + * and value of the parameter. So C code in the body of a reaction can access parameter values as + * `self->p`. * - * * State variables: For each state variable `s` of the reactor, there will be a field `s` - * with the type and value of the state variable. So C code in the body of a reaction - * can access state variables as `self->s`. + *

* State variables: For each state variable `s` of the reactor, there will be a field `s` with + * the type and value of the state variable. So C code in the body of a reaction can access state + * variables as `self->s`. * - * The self struct also contains various fields that the user is not intended to - * use. The names of these fields begin with at least two underscores. They are: + *

The self struct also contains various fields that the user is not intended to use. The names + * of these fields begin with at least two underscores. They are: * - * * Outputs: For each output named `out`, there will be a field `_lf_out` that is - * a struct containing a value field whose type matches that of the output. - * The output value is stored here. That struct also has a field `is_present` - * that is a boolean indicating whether the output has been set. - * This field is reset to false at the start of every time - * step. There is also a field `num_destinations` whose value matches the - * number of downstream reactors that use this variable. This field must be - * set when connections are made or changed. It is used to determine for - * a mutable input destination whether a copy needs to be made. + *

* Outputs: For each output named `out`, there will be a field `_lf_out` that is a struct + * containing a value field whose type matches that of the output. The output value is stored here. + * That struct also has a field `is_present` that is a boolean indicating whether the output has + * been set. This field is reset to false at the start of every time step. There is also a field + * `num_destinations` whose value matches the number of downstream reactors that use this variable. + * This field must be set when connections are made or changed. It is used to determine for a + * mutable input destination whether a copy needs to be made. * - * * Inputs: For each input named `in` of type T, there is a field named `_lf_in` - * that is a pointer struct with a value field of type T. The struct pointed - * to also has an `is_present` field of type bool that indicates whether the - * input is present. + *

* Inputs: For each input named `in` of type T, there is a field named `_lf_in` that is a + * pointer struct with a value field of type T. The struct pointed to also has an `is_present` field + * of type bool that indicates whether the input is present. * - * * Outputs of contained reactors: If a reactor reacts to outputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields pointing to those outputs. For example, - * if `r` has an output `out` of type T, then there will be field in `_lf_r` - * named `out` that points to a struct containing a value field - * of type T and a field named `is_present` of type bool. + *

* Outputs of contained reactors: If a reactor reacts to outputs of a contained reactor `r`, + * then the self struct will contain a nested struct named `_lf_r` that has fields pointing to those + * outputs. For example, if `r` has an output `out` of type T, then there will be field in `_lf_r` + * named `out` that points to a struct containing a value field of type T and a field named + * `is_present` of type bool. * - * * Inputs of contained reactors: If a reactor sends to inputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields for storing the values provided to those - * inputs. For example, if R has an input `in` of type T, then there will - * be field in _lf_R named `in` that is a struct with a value field - * of type T and a field named `is_present` of type bool. + *

* Inputs of contained reactors: If a reactor sends to inputs of a contained reactor `r`, then + * the self struct will contain a nested struct named `_lf_r` that has fields for storing the values + * provided to those inputs. For example, if R has an input `in` of type T, then there will be field + * in _lf_R named `in` that is a struct with a value field of type T and a field named `is_present` + * of type bool. * - * * Actions: If the reactor has an action a (logical or physical), then there - * will be a field in the self struct named `_lf_a` and another named `_lf__a`. - * The type of the first is specific to the action and contains a `value` - * field with the type and value of the action (if it has a value). That - * struct also has a `has_value` field, an `is_present` field, and a - * `token` field (which is NULL if the action carries no value). - * The `_lf__a` field is of type trigger_t. - * That struct contains various things, including an array of reactions - * sensitive to this trigger and a lf_token_t struct containing the value of - * the action, if it has a value. See reactor.h in the C library for - * details. + *

* Actions: If the reactor has an action a (logical or physical), then there will be a field in + * the self struct named `_lf_a` and another named `_lf__a`. The type of the first is specific to + * the action and contains a `value` field with the type and value of the action (if it has a + * value). That struct also has a `has_value` field, an `is_present` field, and a `token` field + * (which is NULL if the action carries no value). The `_lf__a` field is of type trigger_t. That + * struct contains various things, including an array of reactions sensitive to this trigger and a + * lf_token_t struct containing the value of the action, if it has a value. See reactor.h in the C + * library for details. * - * * Reactions: Each reaction will have several fields in the self struct. - * Each of these has a name that begins with `_lf__reaction_i`, where i is - * the number of the reaction, starting with 0. The fields are: - * * _lf__reaction_i: The struct that is put onto the reaction queue to - * execute the reaction (see reactor.h in the C library). + *

* Reactions: Each reaction will have several fields in the self struct. Each of these has a + * name that begins with `_lf__reaction_i`, where i is the number of the reaction, starting with 0. + * The fields are: * _lf__reaction_i: The struct that is put onto the reaction queue to execute the + * reaction (see reactor.h in the C library). * - * * Timers: For each timer t, there is are two fields in the self struct: - * * _lf__t: The trigger_t struct for this timer (see reactor.h). - * * _lf__t_reactions: An array of reactions (pointers to the - * reaction_t structs on this self struct) sensitive to this timer. + *

* Timers: For each timer t, there is are two fields in the self struct: * _lf__t: The + * trigger_t struct for this timer (see reactor.h). * _lf__t_reactions: An array of reactions + * (pointers to the reaction_t structs on this self struct) sensitive to this timer. * - * * Triggers: For each Timer, Action, Input, and Output of a contained - * reactor that triggers reactions, there will be a trigger_t struct - * on the self struct with name `_lf__t`, where t is the name of the trigger. + *

* Triggers: For each Timer, Action, Input, and Output of a contained reactor that triggers + * reactions, there will be a trigger_t struct on the self struct with name `_lf__t`, where t is the + * name of the trigger. * - * ## Connections Between Reactors + *

## Connections Between Reactors * - * Establishing connections between reactors involves two steps. - * First, each destination (e.g. an input port) must have pointers to - * the source (the output port). As explained above, for an input named - * `in`, the field `_lf_in->value` is a pointer to the output data being read. - * In addition, `_lf_in->is_present` is a pointer to the corresponding - * `out->is_present` field of the output reactor's self struct. + *

Establishing connections between reactors involves two steps. First, each destination (e.g. an + * input port) must have pointers to the source (the output port). As explained above, for an input + * named `in`, the field `_lf_in->value` is a pointer to the output data being read. In addition, + * `_lf_in->is_present` is a pointer to the corresponding `out->is_present` field of the output + * reactor's self struct. * - * In addition, the `reaction_i` struct on the self struct has a `triggers` - * field that records all the trigger_t structs for ports and actions - * that are triggered by the i-th reaction. The triggers field is - * an array of arrays of pointers to trigger_t structs. - * The length of the outer array is the number of output channels - * (single ports plus multiport widths) that the reaction effects - * plus the number of input port channels of contained - * reactors that it effects. Each inner array has a length equal to the - * number of final destinations of that output channel or input channel. - * The reaction_i struct has an array triggered_sizes that indicates - * the sizes of these inner arrays. The num_outputs field of the - * reaction_i struct gives the length of the triggered_sizes and - * (outer) triggers arrays. The num_outputs field is equal to the - * total number of single ports and multiport channels that the reaction - * writes to. + *

In addition, the `reaction_i` struct on the self struct has a `triggers` field that records + * all the trigger_t structs for ports and actions that are triggered by the i-th reaction. The + * triggers field is an array of arrays of pointers to trigger_t structs. The length of the outer + * array is the number of output channels (single ports plus multiport widths) that the reaction + * effects plus the number of input port channels of contained reactors that it effects. Each inner + * array has a length equal to the number of final destinations of that output channel or input + * channel. The reaction_i struct has an array triggered_sizes that indicates the sizes of these + * inner arrays. The num_outputs field of the reaction_i struct gives the length of the + * triggered_sizes and (outer) triggers arrays. The num_outputs field is equal to the total number + * of single ports and multiport channels that the reaction writes to. * - * ## Runtime Tables + *

## Runtime Tables * - * This generator creates an populates the following tables used at run time. - * These tables may have to be resized and adjusted when mutations occur. + *

This generator creates an populates the following tables used at run time. These tables may + * have to be resized and adjusted when mutations occur. * - * * _lf_is_present_fields: An array of pointers to booleans indicating whether an - * event is present. The _lf_start_time_step() function in reactor_common.c uses - * this to mark every event absent at the start of a time step. The size of this - * table is contained in the variable _lf_is_present_fields_size. - * * This table is accompanied by another list, _lf_is_present_fields_abbreviated, - * which only contains the is_present fields that have been set to true in the - * current tag. This list can allow a performance improvement if most ports are - * seldom present because only fields that have been set to true need to be - * reset to false. + *

* _lf_is_present_fields: An array of pointers to booleans indicating whether an event is + * present. The _lf_start_time_step() function in reactor_common.c uses this to mark every event + * absent at the start of a time step. The size of this table is contained in the variable + * _lf_is_present_fields_size. * This table is accompanied by another list, + * _lf_is_present_fields_abbreviated, which only contains the is_present fields that have been set + * to true in the current tag. This list can allow a performance improvement if most ports are + * seldom present because only fields that have been set to true need to be reset to false. * - * * _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown - * reactions. The length of this table is in the _lf_shutdown_triggers_size - * variable. + *

* _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown reactions. The + * length of this table is in the _lf_shutdown_triggers_size variable. * - * * _lf_timer_triggers: An array of pointers to trigger_t structs for timers that - * need to be started when the program runs. The length of this table is in the - * _lf_timer_triggers_size variable. + *

* _lf_timer_triggers: An array of pointers to trigger_t structs for timers that need to be + * started when the program runs. The length of this table is in the _lf_timer_triggers_size + * variable. * - * * _lf_action_table: For a federated execution, each federate will have this table - * that maps port IDs to the corresponding action struct, which can be cast to - * action_base_t. + *

* _lf_action_table: For a federated execution, each federate will have this table that maps + * port IDs to the corresponding action struct, which can be cast to action_base_t. * * @author Edward A. Lee * @author Marten Lohstroh @@ -306,1150 +265,1133 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */ @SuppressWarnings("StaticPseudoFunctionalStyleMethod") public class CGenerator extends GeneratorBase { - // Regular expression pattern for compiler error messages with resource - // and line number information. The first match will a resource URI in the - // form of "file:/path/file.lf". The second match will be a line number. - // The third match is a character position within the line. - // The fourth match will be the error message. - static final Pattern compileErrorPattern = Pattern.compile( - "^(?.*):(?\\d+):(?\\d+):(?.*)$" - ); - - public static int UNDEFINED_MIN_SPACING = -1; - - //////////////////////////////////////////// - //// Protected fields - - /** The main place to put generated code. */ - protected CodeBuilder code = new CodeBuilder(); - - /** Place to collect code to initialize the trigger objects for all reactor instances. */ - protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); - - protected final CFileConfig fileConfig; - - /** - * Count of the number of is_present fields of the self struct that - * need to be reinitialized in _lf_start_time_step(). - */ - protected int startTimeStepIsPresentCount = 0; - - //////////////////////////////////////////// - //// Private fields - /** - * Extra lines that need to go into the generated CMakeLists.txt. - */ - private String cMakeExtras = ""; - - /** Place to collect code to execute at the start of a time step. */ - private CodeBuilder startTimeStep = new CodeBuilder(); - - /** Count of the number of token pointers that need to have their - * reference count decremented in _lf_start_time_step(). - */ - private int timerCount = 0; - private int startupReactionCount = 0; - private int shutdownReactionCount = 0; - private int resetReactionCount = 0; - private int modalReactorCount = 0; - private int modalStateResetCount = 0; - private int watchdogCount = 0; - - // Indicate whether the generator is in Cpp mode or not - private final boolean CCppMode; - - private final CTypes types; - - private final CCmakeGenerator cmakeGenerator; - - protected CGenerator( - LFGeneratorContext context, - boolean CCppMode, - CTypes types, - CCmakeGenerator cmakeGenerator, - DelayBodyGenerator delayBodyGenerator - ) { - super(context); - this.fileConfig = (CFileConfig) context.getFileConfig(); - this.CCppMode = CCppMode; - this.types = types; - this.cmakeGenerator = cmakeGenerator; - - // Register the delayed connection transformation to be applied by GeneratorBase. - // transform both after delays and physical connections - registerTransformation(new DelayedConnectionTransformation(delayBodyGenerator, types, fileConfig.resource, true, true)); - } + // Regular expression pattern for compiler error messages with resource + // and line number information. The first match will a resource URI in the + // form of "file:/path/file.lf". The second match will be a line number. + // The third match is a character position within the line. + // The fourth match will be the error message. + static final Pattern compileErrorPattern = + Pattern.compile("^(?.*):(?\\d+):(?\\d+):(?.*)$"); - public CGenerator(LFGeneratorContext context, boolean ccppMode) { - this( - context, - ccppMode, - new CTypes(), - new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes()) - ); - } + public static int UNDEFINED_MIN_SPACING = -1; - /** - * Look for physical actions in all resources. - * If found, set threads to be at least one to allow asynchronous schedule calls. - */ - public void accommodatePhysicalActionsIfPresent() { - // If there are any physical actions, ensure the threaded engine is used and that - // keepalive is set to true, unless the user has explicitly set it to false. - for (Resource resource : GeneratorUtils.getResources(reactors)) { - for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { - if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { - // If the unthreaded runtime is not requested by the user, use the threaded runtime instead - // because it is the only one currently capable of handling asynchronous events. - if (!targetConfig.threading && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = true; - errorReporter.reportWarning( - action, - "Using the threaded C runtime to allow for asynchronous handling of physical action " + - action.getName() - ); - return; - } - } - } - } - } + //////////////////////////////////////////// + //// Protected fields - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - protected boolean isOSCompatible() { - if (GeneratorUtils.isHostWindows()) { - if (CCppMode) { - errorReporter.reportError( - "LF programs with a CCpp target are currently not supported on Windows. " + - "Exiting code generation." - ); - // FIXME: The incompatibility between our C runtime code and the - // Visual Studio compiler is extensive. - return false; - } - } - return true; - } + /** The main place to put generated code. */ + protected CodeBuilder code = new CodeBuilder(); - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * @param resource The resource containing the source code. - * @param context The context in which the generator is - * invoked, including whether it is cancelled and - * whether it is a standalone context - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - super.doGenerate(resource, context); - if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; - if (!isOSCompatible()) return; // Incompatible OS and configuration - - // Perform set up that does not generate code - setUpGeneralParameters(); - - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); - handleProtoFiles(); - - // Derive target filename from the .lf filename. - var lfModuleName = fileConfig.name; - var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); - var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; - try { - generateCodeFor(lfModuleName); - copyTargetFiles(); - generateHeaders(); - code.writeToFile(targetFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } + /** Place to collect code to initialize the trigger objects for all reactor instances. */ + protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); - // Create docker file. - if (targetConfig.dockerOptions != null && mainDef != null) { - try { - var dockerData = getDockerGenerator(context).generateDockerData(); - dockerData.writeDockerFile(); - (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); - } catch (IOException e) { - throw new RuntimeException("Error while writing Docker files", e); - } - } + protected final CFileConfig fileConfig; - // If cmake is requested, generate the CMakeLists.txt - if (targetConfig.platformOptions.platform != Platform.ARDUINO) { - var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; - var sources = new HashSet<>(ASTUtils.recursiveChildren(main)).stream() - .map(CUtil::getName).map(it -> it + (CCppMode ? ".cpp" : ".c")) - .collect(Collectors.toList()); - sources.add(cFilename); - var cmakeCode = cmakeGenerator.generateCMakeCode( - sources, - lfModuleName, - errorReporter, - CCppMode, - mainDef != null, - cMakeExtras, - targetConfig - ); - try { - cmakeCode.writeToFile(cmakeFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - } else { - try { - Path include = fileConfig.getSrcGenPath().resolve("include/"); - Path src = fileConfig.getSrcGenPath().resolve("src/"); - FileUtil.arduinoDeleteHelper(src, targetConfig.threading); - FileUtil.relativeIncludeHelper(src, include); - FileUtil.relativeIncludeHelper(include, include); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } + /** + * Count of the number of is_present fields of the self struct that need to be reinitialized in + * _lf_start_time_step(). + */ + protected int startTimeStepIsPresentCount = 0; - if (!targetConfig.noCompile) { - ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); - arduinoUtil.buildArduino(fileConfig, targetConfig); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } else { - System.out.println("********"); - System.out.println("To compile your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli compile -b --build-property compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\nTo flash/upload your generated sketch to the board, run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); - // System.out.println("For a list of all boards installed on your computer, you can use the following command:\n\n\tarduino-cli board listall\n"); - context.finish( - GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null) - ); - } - GeneratorUtils.refreshProject(resource, context.getMode()); - return; - } + //////////////////////////////////////////// + //// Private fields + /** Extra lines that need to go into the generated CMakeLists.txt. */ + private String cMakeExtras = ""; - // Dump the additional compile definitions to a file to keep the generated project - // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can - // take over and do the rest of compilation. - try { - String compileDefs = targetConfig.compileDefinitions.keySet().stream() - .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) - .collect(Collectors.joining("\n")); - FileUtil.writeToFile( - compileDefs, - Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") - ); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + /** Place to collect code to execute at the start of a time step. */ + private CodeBuilder startTimeStep = new CodeBuilder(); - // If this code generator is directly compiling the code, compile it now so that we - // clean it up after, removing the #line directives after errors have been reported. - if ( - !targetConfig.noCompile && targetConfig.dockerOptions == null - && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) - // This code is unreachable in LSP_FAST mode, so that check is omitted. - && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM - ) { - // FIXME: Currently, a lack of main is treated as a request to not produce - // a binary and produce a .o file instead. There should be a way to control - // this. - // Create an anonymous Runnable class and add it to the compileThreadPool - // so that compilation can happen in parallel. - var cleanCode = code.removeLines("#line"); - - var execName = lfModuleName; - var threadFileConfig = fileConfig; - var generator = this; // FIXME: currently only passed to report errors with line numbers in the Eclipse IDE - var CppMode = CCppMode; - // generatingContext.reportProgress( - // String.format("Generated code for %d/%d executables. Compiling...", federateCount, federates.size()), - // 100 * federateCount / federates.size() - // ); // FIXME: Move to FedGenerator - // Create the compiler to be used later - - var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); - try { - if (!cCompiler.runCCompiler(generator, context)) { - // If compilation failed, remove any bin files that may have been created. - CUtil.deleteBinFiles(threadFileConfig); - // If finish has already been called, it is illegal and makes no sense. However, - // if finish has already been called, then this must be a federated execution. - context.unsuccessfulFinish(); - } else { - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - cleanCode.writeToFile(targetFile); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + /** + * Count of the number of token pointers that need to have their reference count decremented in + * _lf_start_time_step(). + */ + private int timerCount = 0; + + private int startupReactionCount = 0; + private int shutdownReactionCount = 0; + private int resetReactionCount = 0; + private int modalReactorCount = 0; + private int modalStateResetCount = 0; + private int watchdogCount = 0; + + // Indicate whether the generator is in Cpp mode or not + private final boolean CCppMode; + + private final CTypes types; + + private final CCmakeGenerator cmakeGenerator; + + protected CGenerator( + LFGeneratorContext context, + boolean CCppMode, + CTypes types, + CCmakeGenerator cmakeGenerator, + DelayBodyGenerator delayBodyGenerator) { + super(context); + this.fileConfig = (CFileConfig) context.getFileConfig(); + this.CCppMode = CCppMode; + this.types = types; + this.cmakeGenerator = cmakeGenerator; + + // Register the delayed connection transformation to be applied by GeneratorBase. + // transform both after delays and physical connections + registerTransformation( + new DelayedConnectionTransformation( + delayBodyGenerator, types, fileConfig.resource, true, true)); + } - } + public CGenerator(LFGeneratorContext context, boolean ccppMode) { + this( + context, + ccppMode, + new CTypes(), + new CCmakeGenerator(context.getFileConfig(), List.of()), + new CDelayBodyGenerator(new CTypes())); + } - // If a build directive has been given, invoke it now. - // Note that the code does not get cleaned in this case. - if (!targetConfig.noCompile) { - if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { - CUtil.runBuildCommand( - fileConfig, - targetConfig, - commandFactory, - errorReporter, - this::reportCommandErrors, - context.getMode() - ); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - System.out.println("Compiled binary is in " + fileConfig.binPath); - } else { - context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + /** + * Look for physical actions in all resources. If found, set threads to be at least one to allow + * asynchronous schedule calls. + */ + public void accommodatePhysicalActionsIfPresent() { + // If there are any physical actions, ensure the threaded engine is used and that + // keepalive is set to true, unless the user has explicitly set it to false. + for (Resource resource : GeneratorUtils.getResources(reactors)) { + for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { + if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { + // If the unthreaded runtime is not requested by the user, use the threaded runtime + // instead + // because it is the only one currently capable of handling asynchronous events. + if (!targetConfig.threading + && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = true; + errorReporter.reportWarning( + action, + "Using the threaded C runtime to allow for asynchronous handling of physical action" + + " " + + action.getName()); + return; + } } + } + } + } - // In case we are in Eclipse, make sure the generated code is visible. - GeneratorUtils.refreshProject(resource, context.getMode()); + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + protected boolean isOSCompatible() { + if (GeneratorUtils.isHostWindows()) { + if (CCppMode) { + errorReporter.reportError( + "LF programs with a CCpp target are currently not supported on Windows. " + + "Exiting code generation."); + // FIXME: The incompatibility between our C runtime code and the + // Visual Studio compiler is extensive. + return false; + } } + return true; + } - private void generateCodeFor( - String lfModuleName - ) throws IOException { - startTimeStepIsPresentCount = 0; - code.pr(generateDirectives()); - code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); - // Generate code for each reactor. - generateReactorDefinitions(); - - // Generate main instance, if there is one. - // Note that any main reactors in imported files are ignored. - // Skip generation if there are cycles. - if (main != null) { - initializeTriggerObjects.pr(String.join("\n", - "int _lf_startup_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", - "int _lf_shutdown_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", - "int _lf_reset_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", - "int _lf_timer_triggers_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", - "int bank_index;", - "SUPPRESS_UNUSED_WARNING(bank_index);", - "int _lf_watchdog_number_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);" - )); - // Add counters for modal initialization - initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); - - // Create an array of arrays to store all self structs. - // This is needed because connections cannot be established until - // all reactor instances have self structs because ports that - // receive data reference the self structs of the originating - // reactors, which are arbitarily far away in the program graph. - generateSelfStructs(main); - generateReactorInstance(main); - - if (targetConfig.fedSetupPreamble != null) { - if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); - code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); - if (targetLanguageIsCpp()) code.pr("}"); - } + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context The context in which the generator is invoked, including whether it is cancelled + * and whether it is a standalone context + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + super.doGenerate(resource, context); + if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; + if (!isOSCompatible()) return; // Incompatible OS and configuration - // If there are timers, create a table of timers to be initialized. - code.pr(CTimerGenerator.generateDeclarations(timerCount)); - - // If there are startup reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); - - // If there are shutdown reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); - - // If there are reset reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); - - // If there are watchdogs, create a table of triggers. - code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); - - // If there are modes, create a table of mode state to be checked for transitions. - code.pr(CModesGenerator.generateModeStatesTable( - hasModalReactors, - modalReactorCount, - modalStateResetCount - )); - - // Generate function to initialize the trigger objects for all reactors. - code.pr(CTriggerObjectsGenerator.generateInitializeTriggerObjects( - main, - targetConfig, - initializeTriggerObjects, - startTimeStep, - types, - lfModuleName, - startTimeStepIsPresentCount - )); - - // Generate function to trigger startup reactions for all reactors. - code.pr(CReactionGenerator.generateLfTriggerStartupReactions(startupReactionCount, hasModalReactors)); - - // Generate function to schedule timers for all reactors. - code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - - // Generate function to initialize mutexes for all reactors with watchdogs. - code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); - - // Generate a function that will either do nothing - // (if there is only one federate or the coordination - // is set to decentralized) or, if there are - // downstream federates, will notify the RTI - // that the specified logical time is complete. - if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) code.pr("extern \"C\""); - code.pr(String.join("\n", - "void logical_tag_complete(tag_t tag_to_send) {", - CExtensionUtils.surroundWithIfFederatedCentralized( - " _lf_logical_tag_complete(tag_to_send);" - ), - "}" - )); - - // Generate function to schedule shutdown reactions if any - // reactors have reactions to shutdown. - code.pr(CReactionGenerator.generateLfTriggerShutdownReactions(shutdownReactionCount, hasModalReactors)); - - // Generate an empty termination function for non-federated - // execution. For federated execution, an implementation is - // provided in federate.c. That implementation will resign - // from the federation and close any open sockets. - code.pr(""" - #ifndef FEDERATED - void terminate_execution() {} - #endif""" - ); - - - // Generate functions for modes - code.pr(CModesGenerator.generateLfInitializeModes( - hasModalReactors - )); - code.pr(CModesGenerator.generateLfHandleModeChanges( - hasModalReactors, - modalStateResetCount - )); - code.pr(CReactionGenerator.generateLfModeTriggeredReactions( - startupReactionCount, - resetReactionCount, - hasModalReactors - )); - } + // Perform set up that does not generate code + setUpGeneralParameters(); + + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); + handleProtoFiles(); + + // Derive target filename from the .lf filename. + var lfModuleName = fileConfig.name; + var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); + var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; + try { + generateCodeFor(lfModuleName); + copyTargetFiles(); + generateHeaders(); + code.writeToFile(targetFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); } - @Override - public void checkModalReactorSupport(boolean __) { - // Modal reactors are currently only supported for non federated applications - super.checkModalReactorSupport(true); + // Create docker file. + if (targetConfig.dockerOptions != null && mainDef != null) { + try { + var dockerData = getDockerGenerator(context).generateDockerData(); + dockerData.writeDockerFile(); + (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + } catch (IOException e) { + throw new RuntimeException("Error while writing Docker files", e); + } } - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - return String.join("\n", - "// Generated forwarding reaction for connections with the same destination", - "// but located in mutually exclusive modes.", - "lf_set("+dest+", "+source+"->value);" - ); + // If cmake is requested, generate the CMakeLists.txt + if (targetConfig.platformOptions.platform != Platform.ARDUINO) { + var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; + var sources = + new HashSet<>(ASTUtils.recursiveChildren(main)) + .stream() + .map(CUtil::getName) + .map(it -> it + (CCppMode ? ".cpp" : ".c")) + .collect(Collectors.toList()); + sources.add(cFilename); + var cmakeCode = + cmakeGenerator.generateCMakeCode( + sources, + lfModuleName, + errorReporter, + CCppMode, + mainDef != null, + cMakeExtras, + targetConfig); + try { + cmakeCode.writeToFile(cmakeFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + } else { + try { + Path include = fileConfig.getSrcGenPath().resolve("include/"); + Path src = fileConfig.getSrcGenPath().resolve("src/"); + FileUtil.arduinoDeleteHelper(src, targetConfig.threading); + FileUtil.relativeIncludeHelper(src, include); + FileUtil.relativeIncludeHelper(include, include); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + + if (!targetConfig.noCompile) { + ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); + arduinoUtil.buildArduino(fileConfig, targetConfig); + context.finish(GeneratorResult.Status.COMPILED, null); + } else { + System.out.println("********"); + System.out.println( + "To compile your program, run the following command to see information about the board" + + " you plugged in:\n\n" + + "\tarduino-cli board list\n\n" + + "Grab the FQBN and PORT from the command and run the following command in the" + + " generated sources directory:\n\n" + + "\tarduino-cli compile -b --build-property" + + " compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property" + + " compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\n" + + "To flash/upload your generated sketch to the board, run the following command in" + + " the generated sources directory:\n\n" + + "\tarduino-cli upload -b -p \n"); + // System.out.println("For a list of all boards installed on your computer, you can use the + // following command:\n\n\tarduino-cli board listall\n"); + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + } + GeneratorUtils.refreshProject(resource, context.getMode()); + return; } - /** Set the scheduler type in the target config as needed. */ - private void pickScheduler() { - // Don't use a scheduler that does not prioritize reactions based on deadlines - // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. - if (!targetConfig.schedulerType.prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - if (hasDeadlines(reactors)) { - if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { - targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; - } - } - } + // Dump the additional compile definitions to a file to keep the generated project + // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can + // take over and do the rest of compilation. + try { + String compileDefs = + targetConfig.compileDefinitions.keySet().stream() + .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) + .collect(Collectors.joining("\n")); + FileUtil.writeToFile( + compileDefs, + Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt")); + } catch (IOException e) { + Exceptions.sneakyThrow(e); } - private boolean hasDeadlines(List reactors) { - for (Reactor reactor : reactors) { - for (Reaction reaction : allReactions(reactor)) { - if (reaction.getDeadline() != null) { - return true; - } - } + // If this code generator is directly compiling the code, compile it now so that we + // clean it up after, removing the #line directives after errors have been reported. + if (!targetConfig.noCompile + && targetConfig.dockerOptions == null + && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) + // This code is unreachable in LSP_FAST mode, so that check is omitted. + && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM) { + // FIXME: Currently, a lack of main is treated as a request to not produce + // a binary and produce a .o file instead. There should be a way to control + // this. + // Create an anonymous Runnable class and add it to the compileThreadPool + // so that compilation can happen in parallel. + var cleanCode = code.removeLines("#line"); + + var execName = lfModuleName; + var threadFileConfig = fileConfig; + var generator = + this; // FIXME: currently only passed to report errors with line numbers in the Eclipse + // IDE + var CppMode = CCppMode; + // generatingContext.reportProgress( + // String.format("Generated code for %d/%d executables. Compiling...", federateCount, + // federates.size()), + // 100 * federateCount / federates.size() + // ); // FIXME: Move to FedGenerator + // Create the compiler to be used later + + var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); + try { + if (!cCompiler.runCCompiler(generator, context)) { + // If compilation failed, remove any bin files that may have been created. + CUtil.deleteBinFiles(threadFileConfig); + // If finish has already been called, it is illegal and makes no sense. However, + // if finish has already been called, then this must be a federated execution. + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, null); } - return false; + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } } - private boolean hasWatchdogs() { - for (Reactor reactor : reactors) { - List watchdogs = ASTUtils.allWatchdogs(reactor); - if (watchdogs != null && !watchdogs.isEmpty()) { - return true; - } + // If a build directive has been given, invoke it now. + // Note that the code does not get cleaned in this case. + if (!targetConfig.noCompile) { + if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { + CUtil.runBuildCommand( + fileConfig, + targetConfig, + commandFactory, + errorReporter, + this::reportCommandErrors, + context.getMode()); + context.finish(GeneratorResult.Status.COMPILED, null); } - return false; + System.out.println("Compiled binary is in " + fileConfig.binPath); + } else { + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + } + + // In case we are in Eclipse, make sure the generated code is visible. + GeneratorUtils.refreshProject(resource, context.getMode()); } - /** - * Look at the 'reactor' eResource. - * If it is an imported .lf file, incorporate it into the current - * program in the following manner: - * - Merge its target property with `targetConfig` - * - If there are any preambles, add them to the preambles of the reactor. - */ - private void inspectReactorEResource(ReactorDecl reactor) { - // If the reactor is imported, look at the - // target definition of the .lf file in which the reactor is imported from and - // append any cmake-include. - // Check if the reactor definition is imported - if (reactor.eResource() != mainDef.getReactorClass().eResource()) { - // Find the LFResource corresponding to this eResource - LFResource lfResource = null; - for (var resource : resources) { - if (resource.getEResource() == reactor.eResource()) { - lfResource = resource; - break; - } - } - // Copy the user files and cmake-includes to the src-gen path of the main .lf file - if (lfResource != null) { - copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); - } - } + private void generateCodeFor(String lfModuleName) throws IOException { + startTimeStepIsPresentCount = 0; + code.pr(generateDirectives()); + code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); + // Generate code for each reactor. + generateReactorDefinitions(); + + // Generate main instance, if there is one. + // Note that any main reactors in imported files are ignored. + // Skip generation if there are cycles. + if (main != null) { + initializeTriggerObjects.pr( + String.join( + "\n", + "int _lf_startup_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", + "int _lf_shutdown_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", + "int _lf_reset_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", + "int _lf_timer_triggers_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", + "int bank_index;", + "SUPPRESS_UNUSED_WARNING(bank_index);", + "int _lf_watchdog_number_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);")); + // Add counters for modal initialization + initializeTriggerObjects.pr( + CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); + + // Create an array of arrays to store all self structs. + // This is needed because connections cannot be established until + // all reactor instances have self structs because ports that + // receive data reference the self structs of the originating + // reactors, which are arbitarily far away in the program graph. + generateSelfStructs(main); + generateReactorInstance(main); + + if (targetConfig.fedSetupPreamble != null) { + if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); + code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); + if (targetLanguageIsCpp()) code.pr("}"); + } + + // If there are timers, create a table of timers to be initialized. + code.pr(CTimerGenerator.generateDeclarations(timerCount)); + + // If there are startup reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); + + // If there are shutdown reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); + + // If there are reset reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); + + // If there are watchdogs, create a table of triggers. + code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); + + // If there are modes, create a table of mode state to be checked for transitions. + code.pr( + CModesGenerator.generateModeStatesTable( + hasModalReactors, modalReactorCount, modalStateResetCount)); + + // Generate function to initialize the trigger objects for all reactors. + code.pr( + CTriggerObjectsGenerator.generateInitializeTriggerObjects( + main, + targetConfig, + initializeTriggerObjects, + startTimeStep, + types, + lfModuleName, + startTimeStepIsPresentCount)); + + // Generate function to trigger startup reactions for all reactors. + code.pr( + CReactionGenerator.generateLfTriggerStartupReactions( + startupReactionCount, hasModalReactors)); + + // Generate function to schedule timers for all reactors. + code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); + + // Generate function to initialize mutexes for all reactors with watchdogs. + code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); + + // Generate a function that will either do nothing + // (if there is only one federate or the coordination + // is set to decentralized) or, if there are + // downstream federates, will notify the RTI + // that the specified logical time is complete. + if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) + code.pr("extern \"C\""); + code.pr( + String.join( + "\n", + "void logical_tag_complete(tag_t tag_to_send) {", + CExtensionUtils.surroundWithIfFederatedCentralized( + " _lf_logical_tag_complete(tag_to_send);"), + "}")); + + // Generate function to schedule shutdown reactions if any + // reactors have reactions to shutdown. + code.pr( + CReactionGenerator.generateLfTriggerShutdownReactions( + shutdownReactionCount, hasModalReactors)); + + // Generate an empty termination function for non-federated + // execution. For federated execution, an implementation is + // provided in federate.c. That implementation will resign + // from the federation and close any open sockets. + code.pr( + """ + #ifndef FEDERATED + void terminate_execution() {} + #endif"""); + + // Generate functions for modes + code.pr(CModesGenerator.generateLfInitializeModes(hasModalReactors)); + code.pr(CModesGenerator.generateLfHandleModeChanges(hasModalReactors, modalStateResetCount)); + code.pr( + CReactionGenerator.generateLfModeTriggeredReactions( + startupReactionCount, resetReactionCount, hasModalReactors)); } + } - /** - * Copy all files or directories listed in the target property `files`, `cmake-include`, - * and `_fed_setup` into the src-gen folder of the main .lf file - * - * @param targetConfig The targetConfig to read the target properties from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - @Override - public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - super.copyUserFiles(targetConfig, fileConfig); - // Make sure the target directory exists. - var targetDir = this.fileConfig.getSrcGenPath(); - try { - Files.createDirectories(targetDir); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } + @Override + public void checkModalReactorSupport(boolean __) { + // Modal reactors are currently only supported for non federated applications + super.checkModalReactorSupport(true); + } - for (String filename : targetConfig.fileNames) { - var relativeFileName = CUtil.copyFileOrResource( - filename, - fileConfig.srcFile.getParent(), - targetDir); - if (StringExtensions.isNullOrEmpty(relativeFileName)) { - errorReporter.reportError( - "Failed to find file " + filename + " specified in the" + - " files target property." - ); - } else { - targetConfig.filesNamesWithoutPath.add( - relativeFileName - ); - } - } + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + return String.join( + "\n", + "// Generated forwarding reaction for connections with the same destination", + "// but located in mutually exclusive modes.", + "lf_set(" + dest + ", " + source + "->value);"); + } - for (String filename : targetConfig.cmakeIncludes) { - var relativeCMakeIncludeFileName = - CUtil.copyFileOrResource( - filename, - fileConfig.srcFile.getParent(), - targetDir); - // Check if the file exists - if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { - errorReporter.reportError( - "Failed to find cmake-include file " + filename - ); - } else { - this.targetConfig.cmakeIncludesWithoutPath.add( - relativeCMakeIncludeFileName - ); - } + /** Set the scheduler type in the target config as needed. */ + private void pickScheduler() { + // Don't use a scheduler that does not prioritize reactions based on deadlines + // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. + if (!targetConfig.schedulerType.prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (hasDeadlines(reactors)) { + if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { + targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; } + } + } + } - if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { - try { - FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), - targetDir.resolve(targetConfig.fedSetupPreamble)); - } catch (IOException e) { - errorReporter.reportError("Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); - } + private boolean hasDeadlines(List reactors) { + for (Reactor reactor : reactors) { + for (Reaction reaction : allReactions(reactor)) { + if (reaction.getDeadline() != null) { + return true; } + } } + return false; + } - /** - * Generate code for defining all reactors that belong to the federate, - * including all the child reactors down the hierarchy. Duplicate - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. - */ - private void generateReactorDefinitions() throws IOException { - var generatedReactors = new LinkedHashSet(); - if (this.main != null) { - generateReactorChildren(this.main, generatedReactors); - } + private boolean hasWatchdogs() { + for (Reactor reactor : reactors) { + List watchdogs = ASTUtils.allWatchdogs(reactor); + if (watchdogs != null && !watchdogs.isEmpty()) { + return true; + } + } + return false; + } - if (this.mainDef != null) { - generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); + /** + * Look at the 'reactor' eResource. If it is an imported .lf file, incorporate it into the current + * program in the following manner: - Merge its target property with `targetConfig` - If there are + * any preambles, add them to the preambles of the reactor. + */ + private void inspectReactorEResource(ReactorDecl reactor) { + // If the reactor is imported, look at the + // target definition of the .lf file in which the reactor is imported from and + // append any cmake-include. + // Check if the reactor definition is imported + if (reactor.eResource() != mainDef.getReactorClass().eResource()) { + // Find the LFResource corresponding to this eResource + LFResource lfResource = null; + for (var resource : resources) { + if (resource.getEResource() == reactor.eResource()) { + lfResource = resource; + break; } + } + // Copy the user files and cmake-includes to the src-gen path of the main .lf file + if (lfResource != null) { + copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + } + } + } - if (mainDef == null) { - // Generate code for each reactor that was not instantiated in main or its children. - for (Reactor r : reactors) { - // Get the declarations for reactors that are instantiated somewhere. - // A declaration is either a reactor definition or an import statement.; - var declarations = this.instantiationGraph.getDeclarations(r); - // If the reactor has no instantiations and there is no main reactor, then - // generate code for it anyway (at a minimum, this means that the compiler is invoked - // so that reaction bodies are checked). - if (declarations.isEmpty()) { - generateReactorClass(r); - } - } - } + /** + * Copy all files or directories listed in the target property `files`, `cmake-include`, and + * `_fed_setup` into the src-gen folder of the main .lf file + * + * @param targetConfig The targetConfig to read the target properties from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + @Override + public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + super.copyUserFiles(targetConfig, fileConfig); + // Make sure the target directory exists. + var targetDir = this.fileConfig.getSrcGenPath(); + try { + Files.createDirectories(targetDir); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); } - /** Generate user-visible header files for all reactors instantiated. */ - private void generateHeaders() throws IOException { - FileUtil.deleteDirectory(fileConfig.getIncludePath()); - FileUtil.copyDirectoryFromClassPath( - fileConfig.getRuntimeIncludePath(), - fileConfig.getIncludePath(), - false - ); - for (Reactor r : reactors) { - CReactorHeaderFileGenerator.doGenerate( - types, r, fileConfig, - (builder, rr, userFacing) -> { - generateAuxiliaryStructs(builder, rr, userFacing); - if (userFacing) { - ASTUtils.allInstantiations(r).stream().map(Instantiation::getReactorClass).collect(Collectors.toSet()).forEach(it -> { - ASTUtils.allPorts(ASTUtils.toDefinition(it)) - .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( - ASTUtils.toDefinition(it), p, getTarget(), errorReporter, types, new CodeBuilder(), true, it - ))); - }); - } - }, - this::generateTopLevelPreambles); - } - FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + for (String filename : targetConfig.fileNames) { + var relativeFileName = + CUtil.copyFileOrResource(filename, fileConfig.srcFile.getParent(), targetDir); + if (StringExtensions.isNullOrEmpty(relativeFileName)) { + errorReporter.reportError( + "Failed to find file " + filename + " specified in the" + " files target property."); + } else { + targetConfig.filesNamesWithoutPath.add(relativeFileName); + } } - /** - * Generate code for the children of 'reactor' that belong to 'federate'. - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. - * - * @param reactor Used to extract children from - */ - private void generateReactorChildren( - ReactorInstance reactor, - LinkedHashSet generatedReactors - ) throws IOException { - for (ReactorInstance r : reactor.children) { - if (r.reactorDeclaration != null && - !generatedReactors.contains(r.reactorDefinition)) { - generatedReactors.add(r.reactorDefinition); - generateReactorChildren(r, generatedReactors); - inspectReactorEResource(r.reactorDeclaration); - generateReactorClass(r.reactorDefinition); - } - } + for (String filename : targetConfig.cmakeIncludes) { + var relativeCMakeIncludeFileName = + CUtil.copyFileOrResource(filename, fileConfig.srcFile.getParent(), targetDir); + // Check if the file exists + if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { + errorReporter.reportError("Failed to find cmake-include file " + filename); + } else { + this.targetConfig.cmakeIncludesWithoutPath.add(relativeCMakeIncludeFileName); + } } - /** - * Choose which platform files to compile with according to the OS. - * If there is no main reactor, then compilation will produce a .o file requiring further linking. - * Also, if useCmake is set to true, we don't need to add platform files. The CMakeLists.txt file - * will detect and use the appropriate platform file based on the platform that cmake is invoked on. - */ - private void pickCompilePlatform() { - var osName = System.getProperty("os.name").toLowerCase(); - // if platform target was set, use given platform instead - if (targetConfig.platformOptions.platform != Platform.AUTO) { - osName = targetConfig.platformOptions.platform.toString(); - } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { - errorReporter.reportError("Platform " + osName + " is not supported"); - } + if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { + try { + FileUtil.copyFile( + fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), + targetDir.resolve(targetConfig.fedSetupPreamble)); + } catch (IOException e) { + errorReporter.reportError( + "Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); + } } + } + /** + * Generate code for defining all reactors that belong to the federate, including all the child + * reactors down the hierarchy. Duplicate Duplicates are avoided. + * + *

Imported reactors' original .lf file is incorporated in the following manner: - If there are + * any cmake-include files, add them to the current list of cmake-include files. - If there are + * any preambles, add them to the preambles of the reactor. + */ + private void generateReactorDefinitions() throws IOException { + var generatedReactors = new LinkedHashSet(); + if (this.main != null) { + generateReactorChildren(this.main, generatedReactors); + } - /** - * Copy target-specific header file to the src-gen directory. - */ - protected void copyTargetFiles() throws IOException { - // Copy the core lib - String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); - Path dest = fileConfig.getSrcGenPath(); - if (targetConfig.platformOptions.platform == Platform.ARDUINO) dest = dest.resolve("src"); - if (coreLib != null) { - FileUtil.copyDirectory(Path.of(coreLib), dest, true); - } else { - FileUtil.copyDirectoryFromClassPath( - "/lib/c/reactor-c/core", - dest.resolve("core"), - true - ); - FileUtil.copyDirectoryFromClassPath( - "/lib/c/reactor-c/lib", - dest.resolve("lib"), - true - ); - } + if (this.mainDef != null) { + generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); + } - // For the Zephyr target, copy default config and board files. - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - FileUtil.copyDirectoryFromClassPath( - "/lib/platform/zephyr/boards", - fileConfig.getSrcGenPath().resolve("boards"), - false - ); - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/prj_lf.conf", - fileConfig.getSrcGenPath().resolve("prj_lf.conf"), - true - ); - - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/Kconfig", - fileConfig.getSrcGenPath().resolve("Kconfig"), - true - ); + if (mainDef == null) { + // Generate code for each reactor that was not instantiated in main or its children. + for (Reactor r : reactors) { + // Get the declarations for reactors that are instantiated somewhere. + // A declaration is either a reactor definition or an import statement.; + var declarations = this.instantiationGraph.getDeclarations(r); + // If the reactor has no instantiations and there is no main reactor, then + // generate code for it anyway (at a minimum, this means that the compiler is invoked + // so that reaction bodies are checked). + if (declarations.isEmpty()) { + generateReactorClass(r); } + } } + } - //////////////////////////////////////////// - //// Code generators. - /** - * Generate a reactor class definition for the specified federate. - * A class definition has four parts: - * - * * Preamble code, if any, specified in the Lingua Franca file. - * * A "self" struct type definition (see the class documentation above). - * * A function for each reaction. - * * A constructor for creating an instance. - * for deleting an instance. - * - * If the reactor is the main reactor, then - * the generated code may be customized. Specifically, - * if the main reactor has reactions, these reactions - * will not be generated if they are triggered by or send - * data to contained reactors that are not in the federate. - * @param reactor The parsed reactor data structure. - */ - private void generateReactorClass(Reactor reactor) throws IOException { - // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. - CodeBuilder header = new CodeBuilder(); - CodeBuilder src = new CodeBuilder(); - final String headerName = CUtil.getName(reactor) + ".h"; - var guardMacro = headerName.toUpperCase().replace(".", "_"); - header.pr("#ifndef " + guardMacro); - header.pr("#define " + guardMacro); - generateReactorClassHeaders(reactor, headerName, header, src); - header.pr(generateTopLevelPreambles(reactor)); - generateUserPreamblesForReactor(reactor, src); - generateReactorClassBody(reactor, header, src); - header.pr("#endif // " + guardMacro); - FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); - var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : - CCppMode ? ".cpp" : ".c"; - FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); + /** Generate user-visible header files for all reactors instantiated. */ + private void generateHeaders() throws IOException { + FileUtil.deleteDirectory(fileConfig.getIncludePath()); + FileUtil.copyDirectoryFromClassPath( + fileConfig.getRuntimeIncludePath(), fileConfig.getIncludePath(), false); + for (Reactor r : reactors) { + CReactorHeaderFileGenerator.doGenerate( + types, + r, + fileConfig, + (builder, rr, userFacing) -> { + generateAuxiliaryStructs(builder, rr, userFacing); + if (userFacing) { + ASTUtils.allInstantiations(r).stream() + .map(Instantiation::getReactorClass) + .collect(Collectors.toSet()) + .forEach( + it -> { + ASTUtils.allPorts(ASTUtils.toDefinition(it)) + .forEach( + p -> + builder.pr( + CPortGenerator.generateAuxiliaryStruct( + ASTUtils.toDefinition(it), + p, + getTarget(), + errorReporter, + types, + new CodeBuilder(), + true, + it))); + }); + } + }, + this::generateTopLevelPreambles); } + FileUtil.copyDirectory( + fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + } - protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { - if (CCppMode) { - src.pr("extern \"C\" {"); - header.pr("extern \"C\" {"); - } - header.pr("#include \"include/core/reactor.h\""); - src.pr("#include \"include/api/api.h\""); - src.pr("#include \"include/api/set.h\""); - generateIncludes(reactor); - if (CCppMode) { - src.pr("}"); - header.pr("}"); - } - src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); - src.pr("#include \"" + headerName + "\""); - ASTUtils.allNestedClasses(reactor).map(CUtil::getName) - .map(name -> "#include \"" + name + ".h\"") - .forEach(header::pr); + /** + * Generate code for the children of 'reactor' that belong to 'federate'. Duplicates are avoided. + * + *

Imported reactors' original .lf file is incorporated in the following manner: - If there are + * any cmake-include files, add them to the current list of cmake-include files. - If there are + * any preambles, add them to the preambles of the reactor. + * + * @param reactor Used to extract children from + */ + private void generateReactorChildren( + ReactorInstance reactor, LinkedHashSet generatedReactors) throws IOException { + for (ReactorInstance r : reactor.children) { + if (r.reactorDeclaration != null && !generatedReactors.contains(r.reactorDefinition)) { + generatedReactors.add(r.reactorDefinition); + generateReactorChildren(r, generatedReactors); + inspectReactorEResource(r.reactorDeclaration); + generateReactorClass(r.reactorDefinition); + } } + } - private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { - // Some of the following methods create lines of code that need to - // go into the constructor. Collect those lines of code here: - var constructorCode = new CodeBuilder(); - generateAuxiliaryStructs(header, reactor, false); - generateSelfStruct(header, reactor, constructorCode); - generateMethods(src, reactor); - generateWatchdogs(src, reactor); - generateReactions(src, reactor); - generateConstructor(src, header, reactor, constructorCode); + /** + * Choose which platform files to compile with according to the OS. If there is no main reactor, + * then compilation will produce a .o file requiring further linking. Also, if useCmake is set to + * true, we don't need to add platform files. The CMakeLists.txt file will detect and use the + * appropriate platform file based on the platform that cmake is invoked on. + */ + private void pickCompilePlatform() { + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { + errorReporter.reportError("Platform " + osName + " is not supported"); } + } - /** - * Generate methods for {@code reactor}. - */ - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { - CMethodGenerator.generateMethods(reactor, src, types); + /** Copy target-specific header file to the src-gen directory. */ + protected void copyTargetFiles() throws IOException { + // Copy the core lib + String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); + Path dest = fileConfig.getSrcGenPath(); + if (targetConfig.platformOptions.platform == Platform.ARDUINO) dest = dest.resolve("src"); + if (coreLib != null) { + FileUtil.copyDirectory(Path.of(coreLib), dest, true); + } else { + FileUtil.copyDirectoryFromClassPath("/lib/c/reactor-c/core", dest.resolve("core"), true); + FileUtil.copyDirectoryFromClassPath("/lib/c/reactor-c/lib", dest.resolve("lib"), true); } - /** - * Generates preambles defined by user for a given reactor - * @param reactor The given reactor - */ - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { - src.pr("// *********** From the preamble, verbatim:"); - src.prSourceLineNumber(p.getCode()); - src.pr(toText(p.getCode())); - src.pr("\n// *********** End of preamble."); - } + // For the Zephyr target, copy default config and board files. + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyDirectoryFromClassPath( + "/lib/platform/zephyr/boards", fileConfig.getSrcGenPath().resolve("boards"), false); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", + fileConfig.getSrcGenPath().resolve("prj_lf.conf"), + true); + + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath().resolve("Kconfig"), true); } + } - /** - * Generate a constructor for the specified reactor in the specified federate. - * @param reactor The parsed reactor data structure. - * @param constructorCode Lines of code previously generated that need to - * go into the constructor. - */ - protected void generateConstructor( - CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode - ) { - header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); - src.pr(CConstructorGenerator.generateConstructor( - reactor, - constructorCode.toString() - )); + //////////////////////////////////////////// + //// Code generators. + /** + * Generate a reactor class definition for the specified federate. A class definition has four + * parts: + * + *

* Preamble code, if any, specified in the Lingua Franca file. * A "self" struct type + * definition (see the class documentation above). * A function for each reaction. * A constructor + * for creating an instance. for deleting an instance. + * + *

If the reactor is the main reactor, then the generated code may be customized. Specifically, + * if the main reactor has reactions, these reactions will not be generated if they are triggered + * by or send data to contained reactors that are not in the federate. + * + * @param reactor The parsed reactor data structure. + */ + private void generateReactorClass(Reactor reactor) throws IOException { + // FIXME: Currently we're not reusing definitions for declarations that point to the same + // definition. + CodeBuilder header = new CodeBuilder(); + CodeBuilder src = new CodeBuilder(); + final String headerName = CUtil.getName(reactor) + ".h"; + var guardMacro = headerName.toUpperCase().replace(".", "_"); + header.pr("#ifndef " + guardMacro); + header.pr("#define " + guardMacro); + generateReactorClassHeaders(reactor, headerName, header, src); + header.pr(generateTopLevelPreambles(reactor)); + generateUserPreamblesForReactor(reactor, src); + generateReactorClassBody(reactor, header, src); + header.pr("#endif // " + guardMacro); + FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); + var extension = + targetConfig.platformOptions.platform == Platform.ARDUINO + ? ".ino" + : CCppMode ? ".cpp" : ".c"; + FileUtil.writeToFile( + src.toString(), + fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), + true); + } + + protected void generateReactorClassHeaders( + Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { + if (CCppMode) { + src.pr("extern \"C\" {"); + header.pr("extern \"C\" {"); + } + header.pr("#include \"include/core/reactor.h\""); + src.pr("#include \"include/api/api.h\""); + src.pr("#include \"include/api/set.h\""); + generateIncludes(reactor); + if (CCppMode) { + src.pr("}"); + header.pr("}"); } + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); + src.pr("#include \"" + headerName + "\""); + ASTUtils.allNestedClasses(reactor) + .map(CUtil::getName) + .map(name -> "#include \"" + name + ".h\"") + .forEach(header::pr); + } + + private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { + // Some of the following methods create lines of code that need to + // go into the constructor. Collect those lines of code here: + var constructorCode = new CodeBuilder(); + generateAuxiliaryStructs(header, reactor, false); + generateSelfStruct(header, reactor, constructorCode); + generateMethods(src, reactor); + generateWatchdogs(src, reactor); + generateReactions(src, reactor); + generateConstructor(src, header, reactor, constructorCode); + } + + /** Generate methods for {@code reactor}. */ + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { + CMethodGenerator.generateMethods(reactor, src, types); + } - protected void generateIncludes(Reactor r) { - code.pr("#include \"" + CUtil.getName(r) + ".h\""); + /** + * Generates preambles defined by user for a given reactor + * + * @param reactor The given reactor + */ + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { + src.pr("// *********** From the preamble, verbatim:"); + src.prSourceLineNumber(p.getCode()); + src.pr(toText(p.getCode())); + src.pr("\n// *********** End of preamble."); } + } - /** - * Generate the struct type definitions for inputs, outputs, and - * actions of the specified reactor. - */ - protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { - // In the case where there are incoming - // p2p logical connections in decentralized - // federated execution, there will be an - // intended_tag field added to accommodate - // the case where a reaction triggered by a - // port or action is late due to network - // latency, etc.. - var federatedExtension = new CodeBuilder(); - federatedExtension.pr(""" + /** + * Generate a constructor for the specified reactor in the specified federate. + * + * @param reactor The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to go into the constructor. + */ + protected void generateConstructor( + CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode) { + header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); + src.pr(CConstructorGenerator.generateConstructor(reactor, constructorCode.toString())); + } + + protected void generateIncludes(Reactor r) { + code.pr("#include \"" + CUtil.getName(r) + ".h\""); + } + + /** + * Generate the struct type definitions for inputs, outputs, and actions of the specified reactor. + */ + protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { + // In the case where there are incoming + // p2p logical connections in decentralized + // federated execution, there will be an + // intended_tag field added to accommodate + // the case where a reaction triggered by a + // port or action is late due to network + // latency, etc.. + var federatedExtension = new CodeBuilder(); + federatedExtension.pr( + """ #ifdef FEDERATED #ifdef FEDERATED_DECENTRALIZED %s intended_tag; #endif %s physical_time_of_arrival; #endif - """.formatted(types.getTargetTagType(), types.getTargetTimeType()) - ); - for (Port p : allPorts(r)) { - builder.pr(CPortGenerator.generateAuxiliaryStruct( - r, - p, - getTarget(), - errorReporter, - types, - federatedExtension, - userFacing, - null - )); - } - // The very first item on this struct needs to be - // a trigger_t* because the struct will be cast to (trigger_t*) - // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(r)) { - builder.pr(CActionGenerator.generateAuxiliaryStruct( - r, - action, - getTarget(), - types, - federatedExtension, - userFacing - )); - } + """ + .formatted(types.getTargetTagType(), types.getTargetTimeType())); + for (Port p : allPorts(r)) { + builder.pr( + CPortGenerator.generateAuxiliaryStruct( + r, p, getTarget(), errorReporter, types, federatedExtension, userFacing, null)); } - - /** - * Generate the self struct type definition for the specified reactor - * in the specified federate. - * @param decl The parsed reactor data structure. - * @param constructorCode Place to put lines of code that need to - * go into the constructor. - */ - private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { - var reactor = toDefinition(decl); - var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); - - // Construct the typedef for the "self" struct. - // Create a type name for the self struct. - var body = new CodeBuilder(); - - // Extensions can add functionality to the CGenerator - generateSelfStructExtension(body, decl, constructorCode); - - // Next handle parameters. - body.pr(CParameterGenerator.generateDeclarations(reactor, types)); - - // Next handle states. - body.pr(CStateGenerator.generateDeclarations(reactor, types)); - - // Next handle actions. - CActionGenerator.generateDeclarations(reactor, body, constructorCode); - - // Next handle inputs and outputs. - CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); - - // If there are contained reactors that either receive inputs - // from reactions of this reactor or produce outputs that trigger - // reactions of this reactor, then we need to create a struct - // inside the self struct for each contained reactor. That - // struct has a place to hold the data produced by this reactor's - // reactions and a place to put pointers to data produced by - // the contained reactors. - generateInteractingContainedReactors(reactor, body, constructorCode); - - // Next, generate the fields needed for each reaction. - CReactionGenerator.generateReactionAndTriggerStructs( - body, - reactor, - constructorCode, - types - ); - - // Generate the fields needed for each watchdog. - CWatchdogGenerator.generateWatchdogStruct( - body, - decl, - constructorCode - ); - - // Next, generate fields for modes - CModesGenerator.generateDeclarations(reactor, body, constructorCode); - - // The first field has to always be a pointer to the list of - // of allocated memory that must be freed when the reactor is freed. - // This means that the struct can be safely cast to self_base_t. - builder.pr("typedef struct {"); - builder.indent(); - builder.pr("struct self_base_t base;"); - builder.pr(body.toString()); - builder.unindent(); - builder.pr("} " + selfType + ";"); + // The very first item on this struct needs to be + // a trigger_t* because the struct will be cast to (trigger_t*) + // by the lf_schedule() functions to get to the trigger. + for (Action action : allActions(r)) { + builder.pr( + CActionGenerator.generateAuxiliaryStruct( + r, action, getTarget(), types, federatedExtension, userFacing)); } + } - /** - * Generate structs and associated code for contained reactors that - * send or receive data to or from the container's reactions. - * - * If there are contained reactors that either receive inputs - * from reactions of this reactor or produce outputs that trigger - * reactions of this reactor, then we need to create a struct - * inside the self struct of the container for each contained reactor. - * That struct has a place to hold the data produced by the container reactor's - * reactions and a place to put pointers to data produced by - * the contained reactors. - * - * @param reactor The reactor. - * @param body The place to put the struct definition for the contained reactors. - * @param constructorCode The place to put matching code that goes in the container's constructor. - */ - private void generateInteractingContainedReactors( - Reactor reactor, - CodeBuilder body, - CodeBuilder constructorCode - ) { - // The contents of the struct will be collected first so that - // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(reactor); - // Next generate the relevant code. - for (Instantiation containedReactor : contained.containedReactors()) { - Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); - // First define an _width variable in case it is a bank. - var array = ""; - var width = -2; - // If the instantiation is a bank, find the maximum bank width - // to define an array. - if (containedReactor.getWidthSpec() != null) { - width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); - array = "[" + width + "]"; - } - // NOTE: The following needs to be done for each instance - // so that the width can be parameter, not in the constructor. - // Here, we conservatively use a width that is the largest of all isntances. - constructorCode.pr(String.join("\n", - "// Set the _width variable for all cases. This will be -2", - "// if the reactor is not a bank of reactors.", - "self->_lf_"+containedReactor.getName()+"_width = "+width+";" - )); - - // Generate one struct for each contained reactor that interacts. - body.pr("struct {"); - body.indent(); - for (Port port : contained.portsOfInstance(containedReactor)) { - if (port instanceof Input) { - // If the variable is a multiport, then the place to store the data has - // to be malloc'd at initialization. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); - } else { - // Is a multiport. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - } else { - // Must be an output port. - // Outputs of contained reactors are pointers to the source of data on the - // self struct of the container. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); - } else { - // Is a multiport. - // Here, we will use an array of pointers. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - body.pr(port, "trigger_t "+port.getName()+"_trigger;"); - var reactorIndex = ""; - if (containedReactor.getWidthSpec() != null) { - reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); - constructorCode.indent(); - } - var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); - - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederatedDecentralized( - portOnSelf+"_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};" - ) - ); - - var triggered = contained.reactionsTriggered(containedReactor, port); - //noinspection StatementWithEmptyBody - if (triggered.size() > 0) { - body.pr(port, "reaction_t* "+port.getName()+"_reactions["+triggered.size()+"];"); - var triggeredCount = 0; - for (Integer index : triggered) { - constructorCode.pr(port, portOnSelf+"_reactions["+triggeredCount+++"] = &self->_lf__reaction_"+index+";"); - } - constructorCode.pr(port, portOnSelf+"_trigger.reactions = "+portOnSelf+"_reactions;"); - } else { - // Since the self struct is created using calloc, there is no need to set - // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL - } - // Since the self struct is created using calloc, there is no need to set falsy fields. - constructorCode.pr(port, String.join("\n", - portOnSelf+"_trigger.last = NULL;", - portOnSelf+"_trigger.number_of_reactions = "+triggered.size()+";" - )); - - - // Set the physical_time_of_arrival - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederated( - portOnSelf+"_trigger.physical_time_of_arrival = NEVER;" - ) - ); - - if (containedReactor.getWidthSpec() != null) { - constructorCode.unindent(); - constructorCode.pr("}"); - } - } + /** + * Generate the self struct type definition for the specified reactor in the specified federate. + * + * @param decl The parsed reactor data structure. + * @param constructorCode Place to put lines of code that need to go into the constructor. + */ + private void generateSelfStruct( + CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = toDefinition(decl); + var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); + + // Construct the typedef for the "self" struct. + // Create a type name for the self struct. + var body = new CodeBuilder(); + + // Extensions can add functionality to the CGenerator + generateSelfStructExtension(body, decl, constructorCode); + + // Next handle parameters. + body.pr(CParameterGenerator.generateDeclarations(reactor, types)); + + // Next handle states. + body.pr(CStateGenerator.generateDeclarations(reactor, types)); + + // Next handle actions. + CActionGenerator.generateDeclarations(reactor, body, constructorCode); + + // Next handle inputs and outputs. + CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); + + // If there are contained reactors that either receive inputs + // from reactions of this reactor or produce outputs that trigger + // reactions of this reactor, then we need to create a struct + // inside the self struct for each contained reactor. That + // struct has a place to hold the data produced by this reactor's + // reactions and a place to put pointers to data produced by + // the contained reactors. + generateInteractingContainedReactors(reactor, body, constructorCode); + + // Next, generate the fields needed for each reaction. + CReactionGenerator.generateReactionAndTriggerStructs(body, reactor, constructorCode, types); + + // Generate the fields needed for each watchdog. + CWatchdogGenerator.generateWatchdogStruct(body, decl, constructorCode); + + // Next, generate fields for modes + CModesGenerator.generateDeclarations(reactor, body, constructorCode); + + // The first field has to always be a pointer to the list of + // of allocated memory that must be freed when the reactor is freed. + // This means that the struct can be safely cast to self_base_t. + builder.pr("typedef struct {"); + builder.indent(); + builder.pr("struct self_base_t base;"); + builder.pr(body.toString()); + builder.unindent(); + builder.pr("} " + selfType + ";"); + } + + /** + * Generate structs and associated code for contained reactors that send or receive data to or + * from the container's reactions. + * + *

If there are contained reactors that either receive inputs from reactions of this reactor or + * produce outputs that trigger reactions of this reactor, then we need to create a struct inside + * the self struct of the container for each contained reactor. That struct has a place to hold + * the data produced by the container reactor's reactions and a place to put pointers to data + * produced by the contained reactors. + * + * @param reactor The reactor. + * @param body The place to put the struct definition for the contained reactors. + * @param constructorCode The place to put matching code that goes in the container's constructor. + */ + private void generateInteractingContainedReactors( + Reactor reactor, CodeBuilder body, CodeBuilder constructorCode) { + // The contents of the struct will be collected first so that + // we avoid duplicate entries and then the struct will be constructed. + var contained = new InteractingContainedReactors(reactor); + // Next generate the relevant code. + for (Instantiation containedReactor : contained.containedReactors()) { + Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); + // First define an _width variable in case it is a bank. + var array = ""; + var width = -2; + // If the instantiation is a bank, find the maximum bank width + // to define an array. + if (containedReactor.getWidthSpec() != null) { + width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); + array = "[" + width + "]"; + } + // NOTE: The following needs to be done for each instance + // so that the width can be parameter, not in the constructor. + // Here, we conservatively use a width that is the largest of all isntances. + constructorCode.pr( + String.join( + "\n", + "// Set the _width variable for all cases. This will be -2", + "// if the reactor is not a bank of reactors.", + "self->_lf_" + containedReactor.getName() + "_width = " + width + ";")); + + // Generate one struct for each contained reactor that interacts. + body.pr("struct {"); + body.indent(); + for (Port port : contained.portsOfInstance(containedReactor)) { + if (port instanceof Input) { + // If the variable is a multiport, then the place to store the data has + // to be malloc'd at initialization. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, + variableStructType(port, containedReactorType, false) + " " + port.getName() + ";"); + } else { + // Is a multiport. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedReactorType, false) + + "** " + + port.getName() + + ";", + "int " + port.getName() + "_width;")); + } + } else { + // Must be an output port. + // Outputs of contained reactors are pointers to the source of data on the + // self struct of the container. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, + variableStructType(port, containedReactorType, false) + + "* " + + port.getName() + + ";"); + } else { + // Is a multiport. + // Here, we will use an array of pointers. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedReactorType, false) + + "** " + + port.getName() + + ";", + "int " + port.getName() + "_width;")); + } + body.pr(port, "trigger_t " + port.getName() + "_trigger;"); + var reactorIndex = ""; + if (containedReactor.getWidthSpec() != null) { + reactorIndex = "[reactor_index]"; + constructorCode.pr( + "for (int reactor_index = 0; reactor_index < self->_lf_" + + containedReactor.getName() + + "_width; reactor_index++) {"); + constructorCode.indent(); + } + var portOnSelf = + "self->_lf_" + containedReactor.getName() + reactorIndex + "." + port.getName(); + + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederatedDecentralized( + portOnSelf + + "_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + + var triggered = contained.reactionsTriggered(containedReactor, port); + //noinspection StatementWithEmptyBody + if (triggered.size() > 0) { + body.pr( + port, "reaction_t* " + port.getName() + "_reactions[" + triggered.size() + "];"); + var triggeredCount = 0; + for (Integer index : triggered) { + constructorCode.pr( + port, + portOnSelf + + "_reactions[" + + triggeredCount++ + + "] = &self->_lf__reaction_" + + index + + ";"); } - body.unindent(); - body.pr(String.join("\n", - "} _lf_"+containedReactor.getName()+array+";", - "int _lf_"+containedReactor.getName()+"_width;" - )); + constructorCode.pr( + port, portOnSelf + "_trigger.reactions = " + portOnSelf + "_reactions;"); + } else { + // Since the self struct is created using calloc, there is no need to set + // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL + } + // Since the self struct is created using calloc, there is no need to set falsy fields. + constructorCode.pr( + port, + String.join( + "\n", + portOnSelf + "_trigger.last = NULL;", + portOnSelf + "_trigger.number_of_reactions = " + triggered.size() + ";")); + + // Set the physical_time_of_arrival + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederated( + portOnSelf + "_trigger.physical_time_of_arrival = NEVER;")); + + if (containedReactor.getWidthSpec() != null) { + constructorCode.unindent(); + constructorCode.pr("}"); + } } + } + body.unindent(); + body.pr( + String.join( + "\n", + "} _lf_" + containedReactor.getName() + array + ";", + "int _lf_" + containedReactor.getName() + "_width;")); } + } - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param body The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - protected void generateSelfStructExtension( - CodeBuilder body, - ReactorDecl decl, - CodeBuilder constructorCode - ) { - // Do nothing - } + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param body The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + protected void generateSelfStructExtension( + CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { + // Do nothing + } - /** Generate reaction functions definition for a reactor. - * These functions have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param r The reactor. - */ - public void generateReactions(CodeBuilder src, Reactor r) { - var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(r); - for (Reaction reaction : allReactions(reactor)) { - generateReaction(src, reaction, r, reactionIndex); - // Increment reaction index even if the reaction is not in the federate - // so that across federates, the reaction indices are consistent. - reactionIndex++; - } + /** + * Generate reaction functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param r The reactor. + */ + public void generateReactions(CodeBuilder src, Reactor r) { + var reactionIndex = 0; + var reactor = ASTUtils.toDefinition(r); + for (Reaction reaction : allReactions(reactor)) { + generateReaction(src, reaction, r, reactionIndex); + // Increment reaction index even if the reaction is not in the federate + // so that across federates, the reaction indices are consistent. + reactionIndex++; } + } - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { - src.pr(CReactionGenerator.generateReaction( + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + protected void generateReaction( + CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + src.pr( + CReactionGenerator.generateReaction( reaction, r, reactionIndex, @@ -1457,740 +1399,783 @@ protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, i errorReporter, types, targetConfig, - getTarget().requiresTypes - )); - } + getTarget().requiresTypes)); + } - /** Generate watchdog functions definition for a reactor. - * These functions have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param decl The reactor. - * federated or not the main reactor and reactions should be - * unconditionally generated. - */ - public void generateWatchdogs(CodeBuilder src, ReactorDecl decl) { - var reactor = ASTUtils.toDefinition(decl); - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - generateWatchdog(src, watchdog, decl); - } + /** + * Generate watchdog functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param decl The reactor. federated or not the main reactor and reactions should be + * unconditionally generated. + */ + public void generateWatchdogs(CodeBuilder src, ReactorDecl decl) { + var reactor = ASTUtils.toDefinition(decl); + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + generateWatchdog(src, watchdog, decl); + } } - /** Generate a watchdog function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param watchdog The watchdog. - * @param decl The reactor. + /** + * Generate a watchdog function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param watchdog The watchdog. + * @param decl The reactor. */ protected void generateWatchdog(CodeBuilder src, Watchdog watchdog, ReactorDecl decl) { - src.pr(CWatchdogGenerator.generateWatchdog( - watchdog, - decl - )); + src.pr(CWatchdogGenerator.generateWatchdog(watchdog, decl)); } - /** - * Record startup, shutdown, and reset reactions. - * @param instance A reactor instance. - */ - private void recordBuiltinTriggers(ReactorInstance instance) { - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : instance.reactions) { - var reactor = reaction.getParent(); - var temp = new CodeBuilder(); - var foundOne = false; - - var reactionRef = CUtil.reactionRef(reaction); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.isStartup()) { - temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &"+reactionRef+";"); - startupReactionCount += reactor.getTotalWidth(); - foundOne = true; - } else if (trigger.isShutdown()) { - temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &"+reactionRef+";"); - foundOne = true; - shutdownReactionCount += reactor.getTotalWidth(); - - if (targetConfig.tracing != null) { - var description = CUtil.getShortenedName(reactor); - var reactorRef = CUtil.reactorRef(reactor); - temp.pr(String.join("\n", - "_lf_register_trace_event("+reactorRef+", &("+reactorRef+"->_lf__shutdown),", - "trace_trigger, "+addDoubleQuotes(description+".shutdown")+");" - )); - } - } else if (trigger.isReset()) { - temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &"+reactionRef+";"); - resetReactionCount += reactor.getTotalWidth(); - foundOne = true; - } - } - if (foundOne) initializeTriggerObjects.pr(temp.toString()); - } - } - - private void recordWatchdogs(ReactorInstance instance) { - var foundOne = false; + /** + * Record startup, shutdown, and reset reactions. + * + * @param instance A reactor instance. + */ + private void recordBuiltinTriggers(ReactorInstance instance) { + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : instance.reactions) { + var reactor = reaction.getParent(); var temp = new CodeBuilder(); - var reactorRef = CUtil.reactorRef(instance); - // temp.pr("#ifdef LF_THREADED"); - for (WatchdogInstance watchdog : instance.watchdogs) { - temp.pr(" _lf_watchdogs[_lf_watchdog_number_count++] = &"+reactorRef+"->_lf_watchdog_"+watchdog.getName()+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".min_expiration = "+CTypes.getInstance().getTargetTimeExpr(watchdog.getTimeout())+";"); - temp.pr(" " + reactorRef+"->_lf_watchdog_"+watchdog.getName()+".thread_id;"); - watchdogCount += 1; + var foundOne = false; + + var reactionRef = CUtil.reactionRef(reaction); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.isStartup()) { + temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &" + reactionRef + ";"); + startupReactionCount += reactor.getTotalWidth(); foundOne = true; + } else if (trigger.isShutdown()) { + temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &" + reactionRef + ";"); + foundOne = true; + shutdownReactionCount += reactor.getTotalWidth(); + + if (targetConfig.tracing != null) { + var description = CUtil.getShortenedName(reactor); + var reactorRef = CUtil.reactorRef(reactor); + temp.pr( + String.join( + "\n", + "_lf_register_trace_event(" + + reactorRef + + ", &(" + + reactorRef + + "->_lf__shutdown),", + "trace_trigger, " + addDoubleQuotes(description + ".shutdown") + ");")); + } + } else if (trigger.isReset()) { + temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &" + reactionRef + ";"); + resetReactionCount += reactor.getTotalWidth(); + foundOne = true; + } } - // temp.pr("#endif"); - if (foundOne) { - initializeTriggerObjects.pr(temp.toString()); - } + if (foundOne) initializeTriggerObjects.pr(temp.toString()); + } } - /** - * Generate code to set up the tables used in _lf_start_time_step to decrement reference - * counts and mark outputs absent between time steps. This function puts the code - * into startTimeStep. - */ - private void generateStartTimeStep(ReactorInstance instance) { - // Avoid generating dead code if nothing is relevant. - var foundOne = false; - var temp = new CodeBuilder(); - var containerSelfStructName = CUtil.reactorRef(instance); - - // Handle inputs that get sent data from a reaction rather than from - // another contained reactor and reactions that are triggered by an - // output of a contained reactor. - // Note that there may be more than one reaction reacting to the same - // port so we have to avoid listing the port more than once. - var portsSeen = new LinkedHashSet(); - for (ReactionInstance reaction : instance.reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - portsSeen.add(port); - // This reaction is sending to an input. Must be - // the input of a contained reactor in the federate. - // NOTE: If instance == main and the federate is within a bank, - // this assumes that the reaction writes only to the bank member in the federate. - foundOne = true; - - temp.pr("// Add port "+port.getFullName()+" to array of is_present fields."); - - if (!Objects.equal(port.getParent(), instance)) { - // The port belongs to contained reactor, so we also have - // iterate over the instance bank members. - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); - temp.startScopedBankChannelIteration(port, null); - } else { - temp.startScopedBankChannelIteration(port, "count"); - } - var portRef = CUtil.portRefNested(port); - var con = (port.isMultiport()) ? "->" : "."; - - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"is_present;"); - // Intended_tag is only applicable to ports in federated execution. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"intended_tag;" - ) - ); - - startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); - - if (!Objects.equal(port.getParent(), instance)) { - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); - temp.endScopedBankChannelIteration(port, null); - } else { - temp.endScopedBankChannelIteration(port, "count"); - } - } - } - } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; + private void recordWatchdogs(ReactorInstance instance) { + var foundOne = false; + var temp = new CodeBuilder(); + var reactorRef = CUtil.reactorRef(instance); + // temp.pr("#ifdef LF_THREADED"); + for (WatchdogInstance watchdog : instance.watchdogs) { + temp.pr( + " _lf_watchdogs[_lf_watchdog_number_count++] = &" + + reactorRef + + "->_lf_watchdog_" + + watchdog.getName() + + ";"); + temp.pr( + " " + + reactorRef + + "->_lf_watchdog_" + + watchdog.getName() + + ".min_expiration = " + + CTypes.getInstance().getTargetTimeExpr(watchdog.getTimeout()) + + ";"); + temp.pr(" " + reactorRef + "->_lf_watchdog_" + watchdog.getName() + ".thread_id;"); + watchdogCount += 1; + foundOne = true; + } + // temp.pr("#endif"); + if (foundOne) { + initializeTriggerObjects.pr(temp.toString()); + } + } - for (ActionInstance action : instance.actions) { - foundOne = true; + /** + * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts + * and mark outputs absent between time steps. This function puts the code into startTimeStep. + */ + private void generateStartTimeStep(ReactorInstance instance) { + // Avoid generating dead code if nothing is relevant. + var foundOne = false; + var temp = new CodeBuilder(); + var containerSelfStructName = CUtil.reactorRef(instance); + + // Handle inputs that get sent data from a reaction rather than from + // another contained reactor and reactions that are triggered by an + // output of a contained reactor. + // Note that there may be more than one reaction reacting to the same + // port so we have to avoid listing the port more than once. + var portsSeen = new LinkedHashSet(); + for (ReactionInstance reaction : instance.reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + portsSeen.add(port); + // This reaction is sending to an input. Must be + // the input of a contained reactor in the federate. + // NOTE: If instance == main and the federate is within a bank, + // this assumes that the reaction writes only to the bank member in the federate. + foundOne = true; + + temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); + + if (!Objects.equal(port.getParent(), instance)) { + // The port belongs to contained reactor, so we also have + // iterate over the instance bank members. + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); temp.startScopedBlock(instance); + temp.startScopedBankChannelIteration(port, null); + } else { + temp.startScopedBankChannelIteration(port, "count"); + } + var portRef = CUtil.portRefNested(port); + var con = (port.isMultiport()) ? "->" : "."; + + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "is_present;"); + // Intended_tag is only applicable to ports in federated execution. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "intended_tag;")); + + startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); + + if (!Objects.equal(port.getParent(), instance)) { + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + temp.endScopedBankChannelIteration(port, null); + } else { + temp.endScopedBankChannelIteration(port, "count"); + } + } + } + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + + for (ActionInstance action : instance.actions) { + foundOne = true; + temp.startScopedBlock(instance); + + temp.pr( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of is_present fields.", + "_lf_is_present_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".is_present;")); + + // Intended_tag is only applicable to actions in federated execution with decentralized + // coordination. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".intended_tag;"))); + + startTimeStepIsPresentCount += action.getParent().getTotalWidth(); + temp.endScopedBlock(); + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + + // Next, set up the table to mark each output of each contained reactor absent. + for (ReactorInstance child : instance.children) { + if (child.outputs.size() > 0) { - temp.pr(String.join("\n", - "// Add action "+action.getFullName()+" to array of is_present fields.", - "_lf_is_present_fields["+startTimeStepIsPresentCount+"] ", - " = &"+containerSelfStructName+"->_lf_"+action.getName()+".is_present;" - )); + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(child); - // Intended_tag is only applicable to actions in federated execution with decentralized coordination. + var channelCount = 0; + for (PortInstance output : child.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { + foundOne = true; + temp.pr("// Add port " + output.getFullName() + " to array of is_present fields."); + temp.startChannelIteration(output); + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".is_present;"); + + // Intended_tag is only applicable to ports in federated execution with decentralized + // coordination. temp.pr( CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add action " + action.getFullName() - + " to array of intended_tag fields.", - "_lf_intended_tag_fields[" - + startTimeStepIsPresentCount + "] ", - " = &" + containerSelfStructName - + "->_lf_" + action.getName() - + ".intended_tag;" - ))); - - startTimeStepIsPresentCount += action.getParent().getTotalWidth(); - temp.endScopedBlock(); - } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; - - // Next, set up the table to mark each output of each contained reactor absent. - for (ReactorInstance child : instance.children) { - if (child.outputs.size() > 0) { - - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(child); - - var channelCount = 0; - for (PortInstance output : child.outputs) { - if (!output.getDependsOnReactions().isEmpty()){ - foundOne = true; - temp.pr("// Add port "+output.getFullName()+" to array of is_present fields."); - temp.startChannelIteration(output); - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".is_present;"); - - // Intended_tag is only applicable to ports in federated execution with decentralized coordination. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add port "+output.getFullName()+" to array of intended_tag fields.", - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".intended_tag;" - ))); - - temp.pr("count++;"); - channelCount += output.getWidth(); - temp.endChannelIteration(output); - } - } - startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); - temp.endScopedBlock(); - temp.endScopedBlock(); - } + String.join( + "\n", + "// Add port " + output.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".intended_tag;"))); + + temp.pr("count++;"); + channelCount += output.getWidth(); + temp.endChannelIteration(output); + } } - if (foundOne) startTimeStep.pr(temp.toString()); + startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); + temp.endScopedBlock(); + temp.endScopedBlock(); + } } + if (foundOne) startTimeStep.pr(temp.toString()); + } - /** - * For each timer in the given reactor, generate initialization code for the offset - * and period fields. - * - * This method will also populate the global _lf_timer_triggers array, which is - * used to start all timers at the start of execution. - * - * @param instance A reactor instance. - */ - private void generateTimerInitializations(ReactorInstance instance) { - for (TimerInstance timer : instance.timers) { - if (!timer.isStartup()) { - initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); - timerCount += timer.getParent().getTotalWidth(); - } - } + /** + * For each timer in the given reactor, generate initialization code for the offset and period + * fields. + * + *

This method will also populate the global _lf_timer_triggers array, which is used to start + * all timers at the start of execution. + * + * @param instance A reactor instance. + */ + private void generateTimerInitializations(ReactorInstance instance) { + for (TimerInstance timer : instance.timers) { + if (!timer.isStartup()) { + initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); + timerCount += timer.getParent().getTotalWidth(); + } } + } - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * @param filename Name of the file to process. - */ - public void processProtoFile(String filename) { - var protoc = commandFactory.createCommand( + /** + * Process a given .proto file. + * + *

Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + public void processProtoFile(String filename) { + var protoc = + commandFactory.createCommand( "protoc-c", - List.of("--c_out="+this.fileConfig.getSrcGenPath(), filename), + List.of("--c_out=" + this.fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); - return; - } - var returnCode = protoc.run(); - if (returnCode == 0) { - var nameSansProto = filename.substring(0, filename.length() - 6); - targetConfig.compileAdditionalSources.add( - fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString() - ); - - targetConfig.compileLibraries.add("-l"); - targetConfig.compileLibraries.add("protobuf-c"); - targetConfig.compilerFlags.add("-lprotobuf-c"); - } else { - errorReporter.reportError("protoc-c returns error code " + returnCode); - } + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); + return; } - - /** - * Construct a unique type for the struct of the specified - * typed variable (port or action) of the specified reactor class. - * This is required to be the same as the type name returned by - * {@link #variableStructType(TriggerInstance)}. - */ - public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { - return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) +"_"+variable.getName()+"_t"; - } - - /** - * Construct a unique type for the struct of the specified - * instance (port or action). - * This is required to be the same as the type name returned by - * {@link #variableStructType(Variable, Reactor, boolean)}. - * @param portOrAction The port or action instance. - * @return The name of the self struct. - */ - public static String variableStructType(TriggerInstance portOrAction) { - return CUtil.getName(portOrAction.getParent().reactorDefinition)+"_"+portOrAction.getName()+"_t"; + var returnCode = protoc.run(); + if (returnCode == 0) { + var nameSansProto = filename.substring(0, filename.length() - 6); + targetConfig.compileAdditionalSources.add( + fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString()); + + targetConfig.compileLibraries.add("-l"); + targetConfig.compileLibraries.add("protobuf-c"); + targetConfig.compilerFlags.add("-lprotobuf-c"); + } else { + errorReporter.reportError("protoc-c returns error code " + returnCode); } + } - /** - * If tracing is turned on, then generate code that records - * the full name of the specified reactor instance in the - * trace table. If tracing is not turned on, do nothing. - * @param instance The reactor instance. - */ - private void generateTraceTableEntries(ReactorInstance instance) { - if (targetConfig.tracing != null) { - initializeTriggerObjects.pr( - CTracingGenerator.generateTraceTableEntries(instance) - ); - } - } + /** + * Construct a unique type for the struct of the specified typed variable (port or action) of the + * specified reactor class. This is required to be the same as the type name returned by {@link + * #variableStructType(TriggerInstance)}. + */ + public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { + return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) + + "_" + + variable.getName() + + "_t"; + } - /** - * Generate code to instantiate the specified reactor instance and - * initialize it. - * @param instance A reactor instance. - */ - public void generateReactorInstance(ReactorInstance instance) { - var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); - var fullName = instance.getFullName(); - initializeTriggerObjects.pr( - "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); - // Generate the instance self struct containing parameters, state variables, - // and outputs (the "self" struct). - initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(reactorClass)+"();"); - // Generate code to initialize the "self" struct in the - // _lf_initialize_trigger_objects function. - generateTraceTableEntries(instance); - generateReactorInstanceExtension(instance); - generateParameterInitialization(instance); - initializeOutputMultiports(instance); - initializeInputMultiports(instance); - recordBuiltinTriggers(instance); - recordWatchdogs(instance); - - // Next, initialize the "self" struct with state variables. - // These values may be expressions that refer to the parameter values defined above. - generateStateVariableInitializations(instance); - - // Generate trigger objects for the instance. - generateTimerInitializations(instance); - generateActionInitializations(instance); - generateInitializeActionToken(instance); - generateSetDeadline(instance); - generateModeStructure(instance); - - // Recursively generate code for the children. - for (ReactorInstance child : instance.children) { - // If this reactor is a placeholder for a bank of reactors, then generate - // an array of instances of reactors and create an enclosing for loop. - // Need to do this for each of the builders into which the code writes. - startTimeStep.startScopedBlock(child); - initializeTriggerObjects.startScopedBlock(child); - generateReactorInstance(child); - initializeTriggerObjects.endScopedBlock(); - startTimeStep.endScopedBlock(); - } + /** + * Construct a unique type for the struct of the specified instance (port or action). This is + * required to be the same as the type name returned by {@link #variableStructType(Variable, + * Reactor, boolean)}. + * + * @param portOrAction The port or action instance. + * @return The name of the self struct. + */ + public static String variableStructType(TriggerInstance portOrAction) { + return CUtil.getName(portOrAction.getParent().reactorDefinition) + + "_" + + portOrAction.getName() + + "_t"; + } - // For this instance, define what must be done at the start of - // each time step. This sets up the tables that are used by the - // _lf_start_time_step() function in reactor_common.c. - // Note that this function is also run once at the end - // so that it can deallocate any memory. - generateStartTimeStep(instance); - initializeTriggerObjects.pr("//***** End initializing " + fullName); + /** + * If tracing is turned on, then generate code that records the full name of the specified reactor + * instance in the trace table. If tracing is not turned on, do nothing. + * + * @param instance The reactor instance. + */ + private void generateTraceTableEntries(ReactorInstance instance) { + if (targetConfig.tracing != null) { + initializeTriggerObjects.pr(CTracingGenerator.generateTraceTableEntries(instance)); } + } - /** - * For each action of the specified reactor instance, generate initialization code - * for the offset and period fields. - * @param instance The reactor. - */ - private void generateActionInitializations(ReactorInstance instance) { - initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + /** + * Generate code to instantiate the specified reactor instance and initialize it. + * + * @param instance A reactor instance. + */ + public void generateReactorInstance(ReactorInstance instance) { + var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); + var fullName = instance.getFullName(); + initializeTriggerObjects.pr( + "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); + // Generate the instance self struct containing parameters, state variables, + // and outputs (the "self" struct). + initializeTriggerObjects.pr( + CUtil.reactorRefName(instance) + + "[" + + CUtil.runtimeIndex(instance) + + "] = new_" + + CUtil.getName(reactorClass) + + "();"); + // Generate code to initialize the "self" struct in the + // _lf_initialize_trigger_objects function. + generateTraceTableEntries(instance); + generateReactorInstanceExtension(instance); + generateParameterInitialization(instance); + initializeOutputMultiports(instance); + initializeInputMultiports(instance); + recordBuiltinTriggers(instance); + recordWatchdogs(instance); + + // Next, initialize the "self" struct with state variables. + // These values may be expressions that refer to the parameter values defined above. + generateStateVariableInitializations(instance); + + // Generate trigger objects for the instance. + generateTimerInitializations(instance); + generateActionInitializations(instance); + generateInitializeActionToken(instance); + generateSetDeadline(instance); + generateModeStructure(instance); + + // Recursively generate code for the children. + for (ReactorInstance child : instance.children) { + // If this reactor is a placeholder for a bank of reactors, then generate + // an array of instances of reactors and create an enclosing for loop. + // Need to do this for each of the builders into which the code writes. + startTimeStep.startScopedBlock(child); + initializeTriggerObjects.startScopedBlock(child); + generateReactorInstance(child); + initializeTriggerObjects.endScopedBlock(); + startTimeStep.endScopedBlock(); } - /** - * Initialize actions by creating a lf_token_t in the self struct. - * This has the information required to allocate memory for the action payload. - * Skip any action that is not actually used as a trigger. - * @param reactor The reactor containing the actions. - */ - private void generateInitializeActionToken(ReactorInstance reactor) { - for (ActionInstance action : reactor.actions) { - // Skip this step if the action is not in use. - if (action.getParent().getTriggers().contains(action) - ) { - var type = getInferredType(action.getDefinition()); - var payloadSize = "0"; - if (!type.isUndefined()) { - var typeStr = types.getTargetType(type); - if (CUtil.isTokenType(type, types)) { - typeStr = CUtil.rootType(typeStr); - } - if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { - payloadSize = "sizeof("+typeStr+")"; - } - } - - var selfStruct = CUtil.reactorRef(action.getParent()); - initializeTriggerObjects.pr( - CActionGenerator.generateTokenInitializer( - selfStruct, action.getName(), payloadSize - ) - ); - } - } - } + // For this instance, define what must be done at the start of + // each time step. This sets up the tables that are used by the + // _lf_start_time_step() function in reactor_common.c. + // Note that this function is also run once at the end + // so that it can deallocate any memory. + generateStartTimeStep(instance); + initializeTriggerObjects.pr("//***** End initializing " + fullName); + } - /** - * Generate code that is executed while the reactor instance is being initialized. - * This is provided as an extension point for subclasses. - * Normally, the reactions argument is the full list of reactions, - * but for the top-level of a federate, will be a subset of reactions that - * is relevant to the federate. - * @param instance The reactor instance. - */ - protected void generateReactorInstanceExtension(ReactorInstance instance) { - // Do nothing - } + /** + * For each action of the specified reactor instance, generate initialization code for the offset + * and period fields. + * + * @param instance The reactor. + */ + private void generateActionInitializations(ReactorInstance instance) { + initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + } - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all instances - * of the same reactor. - * @param instance The reactor class instance - */ - protected void generateStateVariableInitializations(ReactorInstance instance) { - var reactorClass = instance.getDefinition().getReactorClass(); - var selfRef = CUtil.reactorRef(instance); - for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { - if (isInitialized(stateVar)) { - var mode = stateVar.eContainer() instanceof Mode ? - instance.lookupModeInstance((Mode) stateVar.eContainer()) : - instance.getMode(false); - initializeTriggerObjects.pr(CStateGenerator.generateInitializer( - instance, - selfRef, - stateVar, - mode, - types - )); - if (mode != null && stateVar.isReset()) { - modalStateResetCount += instance.getTotalWidth(); - } - } + /** + * Initialize actions by creating a lf_token_t in the self struct. This has the information + * required to allocate memory for the action payload. Skip any action that is not actually used + * as a trigger. + * + * @param reactor The reactor containing the actions. + */ + private void generateInitializeActionToken(ReactorInstance reactor) { + for (ActionInstance action : reactor.actions) { + // Skip this step if the action is not in use. + if (action.getParent().getTriggers().contains(action)) { + var type = getInferredType(action.getDefinition()); + var payloadSize = "0"; + if (!type.isUndefined()) { + var typeStr = types.getTargetType(type); + if (CUtil.isTokenType(type, types)) { + typeStr = CUtil.rootType(typeStr); + } + if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { + payloadSize = "sizeof(" + typeStr + ")"; + } } - } - /** - * Generate code to set the deadline field of the reactions in the - * specified reactor instance. - * @param instance The reactor instance. - */ - private void generateSetDeadline(ReactorInstance instance) { - for (ReactionInstance reaction : instance.reactions) { - var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; - if (reaction.declaredDeadline != null) { - var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); - } else { // No deadline. - initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); - } - } + var selfStruct = CUtil.reactorRef(action.getParent()); + initializeTriggerObjects.pr( + CActionGenerator.generateTokenInitializer(selfStruct, action.getName(), payloadSize)); + } } + } - /** - * Generate code to initialize modes. - * @param instance The reactor instance. - */ - private void generateModeStructure(ReactorInstance instance) { - CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); - if (!instance.modes.isEmpty()) { - modalReactorCount += instance.getTotalWidth(); + /** + * Generate code that is executed while the reactor instance is being initialized. This is + * provided as an extension point for subclasses. Normally, the reactions argument is the full + * list of reactions, but for the top-level of a federate, will be a subset of reactions that is + * relevant to the federate. + * + * @param instance The reactor instance. + */ + protected void generateReactorInstanceExtension(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. + * + * @param instance The reactor class instance + */ + protected void generateStateVariableInitializations(ReactorInstance instance) { + var reactorClass = instance.getDefinition().getReactorClass(); + var selfRef = CUtil.reactorRef(instance); + for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { + if (isInitialized(stateVar)) { + var mode = + stateVar.eContainer() instanceof Mode + ? instance.lookupModeInstance((Mode) stateVar.eContainer()) + : instance.getMode(false); + initializeTriggerObjects.pr( + CStateGenerator.generateInitializer(instance, selfRef, stateVar, mode, types)); + if (mode != null && stateVar.isReset()) { + modalStateResetCount += instance.getTotalWidth(); } + } } + } - /** - * Generate runtime initialization code for parameters of a given reactor instance - * @param instance The reactor instance. - */ - protected void generateParameterInitialization(ReactorInstance instance) { - var selfRef = CUtil.reactorRef(instance); - // Set the local bank_index variable so that initializers can use it. - initializeTriggerObjects.pr("bank_index = "+CUtil.bankIndex(instance)+";" - + " SUPPRESS_UNUSED_WARNING(bank_index);"); - for (ParameterInstance parameter : instance.parameters) { - // NOTE: we now use the resolved literal value. For better efficiency, we could - // store constants in a global array and refer to its elements to avoid duplicate - // memory allocations. - // NOTE: If the parameter is initialized with a static initializer for an array - // or struct (the initialization expression is surrounded by { ... }), then we - // have to declare a static variable to ensure that the memory is put in data space - // and not on the stack. - // FIXME: Is there a better way to determine this than the string comparison? - var initializer = CParameterGenerator.getInitializer(parameter); - if (initializer.startsWith("{")) { - var temporaryVariableName = parameter.uniqueID(); - initializeTriggerObjects.pr(String.join("\n", - "static "+types.getVariableDeclaration(parameter.type, temporaryVariableName, true)+" = "+initializer+";", - selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" - )); - } else { - initializeTriggerObjects.pr(selfRef+"->"+parameter.getName()+" = "+initializer+";"); - } - } + /** + * Generate code to set the deadline field of the reactions in the specified reactor instance. + * + * @param instance The reactor instance. + */ + private void generateSetDeadline(ReactorInstance instance) { + for (ReactionInstance reaction : instance.reactions) { + var selfRef = CUtil.reactorRef(reaction.getParent()) + "->_lf__reaction_" + reaction.index; + if (reaction.declaredDeadline != null) { + var deadline = reaction.declaredDeadline.maxDelay; + initializeTriggerObjects.pr( + selfRef + ".deadline = " + types.getTargetTimeExpr(deadline) + ";"); + } else { // No deadline. + initializeTriggerObjects.pr(selfRef + ".deadline = NEVER;"); + } } + } - /** - * Generate code that mallocs memory for any output multiports. - * @param reactor The reactor instance. - */ - private void initializeOutputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance output : reactor.outputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeOutputMultiport( - output, - reactorSelfStruct - )); - } + /** + * Generate code to initialize modes. + * + * @param instance The reactor instance. + */ + private void generateModeStructure(ReactorInstance instance) { + CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); + if (!instance.modes.isEmpty()) { + modalReactorCount += instance.getTotalWidth(); } + } - /** - * Allocate memory for inputs. - * @param reactor The reactor. - */ - private void initializeInputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance input : reactor.inputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeInputMultiport( - input, - reactorSelfStruct - )); - } + /** + * Generate runtime initialization code for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + protected void generateParameterInitialization(ReactorInstance instance) { + var selfRef = CUtil.reactorRef(instance); + // Set the local bank_index variable so that initializers can use it. + initializeTriggerObjects.pr( + "bank_index = " + + CUtil.bankIndex(instance) + + ";" + + " SUPPRESS_UNUSED_WARNING(bank_index);"); + for (ParameterInstance parameter : instance.parameters) { + // NOTE: we now use the resolved literal value. For better efficiency, we could + // store constants in a global array and refer to its elements to avoid duplicate + // memory allocations. + // NOTE: If the parameter is initialized with a static initializer for an array + // or struct (the initialization expression is surrounded by { ... }), then we + // have to declare a static variable to ensure that the memory is put in data space + // and not on the stack. + // FIXME: Is there a better way to determine this than the string comparison? + var initializer = CParameterGenerator.getInitializer(parameter); + if (initializer.startsWith("{")) { + var temporaryVariableName = parameter.uniqueID(); + initializeTriggerObjects.pr( + String.join( + "\n", + "static " + + types.getVariableDeclaration(parameter.type, temporaryVariableName, true) + + " = " + + initializer + + ";", + selfRef + "->" + parameter.getName() + " = " + temporaryVariableName + ";")); + } else { + initializeTriggerObjects.pr( + selfRef + "->" + parameter.getName() + " = " + initializer + ";"); + } } + } - @Override - public TargetTypes getTargetTypes() { - return types; + /** + * Generate code that mallocs memory for any output multiports. + * + * @param reactor The reactor instance. + */ + private void initializeOutputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance output : reactor.outputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeOutputMultiport(output, reactorSelfStruct)); } + } - /** - * - * @param context - * @return - */ - protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new CDockerGenerator(context); + /** + * Allocate memory for inputs. + * + * @param reactor The reactor. + */ + private void initializeInputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance input : reactor.inputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeInputMultiport(input, reactorSelfStruct)); } + } - // ////////////////////////////////////////// - // // Protected methods. + @Override + public TargetTypes getTargetTypes() { + return types; + } - // Perform set up that does not generate code - protected void setUpGeneralParameters() { - accommodatePhysicalActionsIfPresent(); - targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); - targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); - // Create the main reactor instance if there is a main reactor. - createMainReactorInstance(); - if (hasModalReactors) { - // So that each separate compile knows about modal reactors, do this: - targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); - } - if (targetConfig.threading && targetConfig.platformOptions.platform == Platform.ARDUINO - && (targetConfig.platformOptions.board == null || !targetConfig.platformOptions.board.contains("mbed"))) { - //non-MBED boards should not use threading - System.out.println("Threading is incompatible on your current Arduino flavor. Setting threading to false."); - targetConfig.threading = false; - } + /** + * @param context + * @return + */ + protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new CDockerGenerator(context); + } - if (targetConfig.platformOptions.platform == Platform.ARDUINO && !targetConfig.noCompile - && targetConfig.platformOptions.board == null) { - System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); - targetConfig.noCompile = true; - } - if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake - pickScheduler(); - // FIXME: this and pickScheduler should be combined. - targetConfig.compileDefinitions.put( - "SCHEDULER", - targetConfig.schedulerType.name() - ); - targetConfig.compileDefinitions.put( - "NUMBER_OF_WORKERS", - String.valueOf(targetConfig.workers) - ); - } - pickCompilePlatform(); + // ////////////////////////////////////////// + // // Protected methods. + + // Perform set up that does not generate code + protected void setUpGeneralParameters() { + accommodatePhysicalActionsIfPresent(); + targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); + // Create the main reactor instance if there is a main reactor. + createMainReactorInstance(); + if (hasModalReactors) { + // So that each separate compile knows about modal reactors, do this: + targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); } - - protected void handleProtoFiles() { - // Handle .proto files. - for (String file : targetConfig.protoFiles) { - this.processProtoFile(file); - } + if (targetConfig.threading + && targetConfig.platformOptions.platform == Platform.ARDUINO + && (targetConfig.platformOptions.board == null + || !targetConfig.platformOptions.board.contains("mbed"))) { + // non-MBED boards should not use threading + System.out.println( + "Threading is incompatible on your current Arduino flavor. Setting threading to false."); + targetConfig.threading = false; } - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(CPreambleGenerator.generateDefineDirectives( - targetConfig, - fileConfig.getSrcGenPath(), - hasModalReactors - )); - code.pr(CPreambleGenerator.generateIncludeStatements( - targetConfig, - CCppMode - )); - return code.toString(); + if (targetConfig.platformOptions.platform == Platform.ARDUINO + && !targetConfig.noCompile + && targetConfig.platformOptions.board == null) { + System.out.println( + "To enable compilation for the Arduino platform, you must specify the fully-qualified" + + " board name (FQBN) in the target property. For example, platform: {name: arduino," + + " board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target" + + " code only."); + targetConfig.noCompile = true; } - - /** - * Generate top-level preamble code. - */ - protected String generateTopLevelPreambles(Reactor reactor) { - CodeBuilder builder = new CodeBuilder(); - var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; - builder.pr("#ifndef " + guard); - builder.pr("#define " + guard); - Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) - .flatMap(it -> ((Model) it.eContainer()).getPreambles().stream()) - .collect(Collectors.toSet()) - .forEach(it -> builder.pr(toText(it.getCode()))); - for (String file : targetConfig.protoFiles) { - var dotIndex = file.lastIndexOf("."); - var rootFilename = file; - if (dotIndex > 0) { - rootFilename = file.substring(0, dotIndex); - } - code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - } - builder.pr("#endif"); - return builder.toString(); + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake + pickScheduler(); + // FIXME: this and pickScheduler should be combined. + targetConfig.compileDefinitions.put("SCHEDULER", targetConfig.schedulerType.name()); + targetConfig.compileDefinitions.put( + "NUMBER_OF_WORKERS", String.valueOf(targetConfig.workers)); } + pickCompilePlatform(); + } - protected boolean targetLanguageIsCpp() { - return CCppMode; + protected void handleProtoFiles() { + // Handle .proto files. + for (String file : targetConfig.protoFiles) { + this.processProtoFile(file); } + } - /** Given a line of text from the output of a compiler, return - * an instance of ErrorFileAndLine if the line is recognized as - * the first line of an error message. Otherwise, return null. - * @param line A line of output from a compiler or other external - * tool that might generate errors. - * @return If the line is recognized as the start of an error message, - * then return a class containing the path to the file on which the - * error occurred (or null if there is none), the line number (or the - * string "1" if there is none), the character position (or the string - * "0" if there is none), and the message (or an empty string if there - * is none). - */ - @Override - public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { - var matcher = compileErrorPattern.matcher(line); - if (matcher.find()) { - var result = new ErrorFileAndLine(); - result.filepath = matcher.group("path"); - result.line = matcher.group("line"); - result.character = matcher.group("column"); - result.message = matcher.group("message"); - - if (!result.message.toLowerCase().contains("error:")) { - result.isError = false; - } - return result; - } - return null; - } + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + CPreambleGenerator.generateDefineDirectives( + targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); + code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); + return code.toString(); + } - //////////////////////////////////////////// - //// Private methods. - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.C; + /** Generate top-level preamble code. */ + protected String generateTopLevelPreambles(Reactor reactor) { + CodeBuilder builder = new CodeBuilder(); + var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; + builder.pr("#ifndef " + guard); + builder.pr("#define " + guard); + Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) + .flatMap(it -> ((Model) it.eContainer()).getPreambles().stream()) + .collect(Collectors.toSet()) + .forEach(it -> builder.pr(toText(it.getCode()))); + for (String file : targetConfig.protoFiles) { + var dotIndex = file.lastIndexOf("."); + var rootFilename = file; + if (dotIndex > 0) { + rootFilename = file.substring(0, dotIndex); + } + code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); } + builder.pr("#endif"); + return builder.toString(); + } - //////////////////////////////////////////////////////////// - //// Private methods - - /** - * If a main or federated reactor has been declared, create a ReactorInstance - * for this top level. This will also assign levels to reactions, then, - * if the program is federated, perform an AST transformation to disconnect - * connections between federates. - */ - private void createMainReactorInstance() { - if (this.mainDef != null) { - if (this.main == null) { - // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); - var reactionInstanceGraph = this.main.assignLevels(); - if (reactionInstanceGraph.nodeCount() > 0) { - errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); - return; - } - if (hasDeadlines) { - this.main.assignDeadlines(); - } - // Inform the run-time of the breadth/parallelism of the reaction graph - var breadth = reactionInstanceGraph.getBreadth(); - if (breadth == 0) { - errorReporter.reportWarning("The program has no reactions"); - } else { - targetConfig.compileDefinitions.put( - "LF_REACTION_GRAPH_BREADTH", - String.valueOf(reactionInstanceGraph.getBreadth()) - ); - } - } - } + protected boolean targetLanguageIsCpp() { + return CCppMode; + } + /** + * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if + * the line is recognized as the first line of an error message. Otherwise, return null. + * + * @param line A line of output from a compiler or other external tool that might generate errors. + * @return If the line is recognized as the start of an error message, then return a class + * containing the path to the file on which the error occurred (or null if there is none), the + * line number (or the string "1" if there is none), the character position (or the string "0" + * if there is none), and the message (or an empty string if there is none). + */ + @Override + public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + var matcher = compileErrorPattern.matcher(line); + if (matcher.find()) { + var result = new ErrorFileAndLine(); + result.filepath = matcher.group("path"); + result.line = matcher.group("line"); + result.character = matcher.group("column"); + result.message = matcher.group("message"); + + if (!result.message.toLowerCase().contains("error:")) { + result.isError = false; + } + return result; } + return null; + } + + //////////////////////////////////////////// + //// Private methods. + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.C; + } + + //////////////////////////////////////////////////////////// + //// Private methods - /** - * Generate an array of self structs for the reactor - * and one for each of its children. - * @param r The reactor instance. - */ - private void generateSelfStructs(ReactorInstance r) { - initializeTriggerObjects.pr(CUtil.selfType(r)+"* "+CUtil.reactorRefName(r)+"["+r.getTotalWidth()+"];"); - initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING("+CUtil.reactorRefName(r)+");"); - for (ReactorInstance child : r.children) { - generateSelfStructs(child); + /** + * If a main or federated reactor has been declared, create a ReactorInstance for this top level. + * This will also assign levels to reactions, then, if the program is federated, perform an AST + * transformation to disconnect connections between federates. + */ + private void createMainReactorInstance() { + if (this.mainDef != null) { + if (this.main == null) { + // Recursively build instances. + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + var reactionInstanceGraph = this.main.assignLevels(); + if (reactionInstanceGraph.nodeCount() > 0) { + errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); + return; + } + if (hasDeadlines) { + this.main.assignDeadlines(); } + // Inform the run-time of the breadth/parallelism of the reaction graph + var breadth = reactionInstanceGraph.getBreadth(); + if (breadth == 0) { + errorReporter.reportWarning("The program has no reactions"); + } else { + targetConfig.compileDefinitions.put( + "LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())); + } + } } -} \ No newline at end of file + } + + /** + * Generate an array of self structs for the reactor and one for each of its children. + * + * @param r The reactor instance. + */ + private void generateSelfStructs(ReactorInstance r) { + initializeTriggerObjects.pr( + CUtil.selfType(r) + "* " + CUtil.reactorRefName(r) + "[" + r.getTotalWidth() + "];"); + initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING(" + CUtil.reactorRefName(r) + ");"); + for (ReactorInstance child : r.children) { + generateSelfStructs(child); + } + } +} diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 67a76eb0e2..dae1f01230 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Map; import java.util.Set; - import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; @@ -38,1160 +37,1347 @@ import org.lflang.util.StringUtil; 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) + protected static String DISABLE_REACTION_INITIALIZATION_MARKER = + "// **** Do not include initialization code in this reaction."; // FIXME: Such markers should + // not exist (#1687) - /** - * Generate necessary initialization code inside the body of the reaction that belongs to reactor decl. - * @param body The body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER. - * @param reaction The initialization code will be generated for this specific reaction - * @param decl The reactor that has the reaction - * @param reactionIndex The index of the reaction relative to other reactions in the reactor, starting from 0 - */ - public static String generateInitializationForReaction(String body, - Reaction reaction, - Reactor decl, - int reactionIndex, - CTypes types, - ErrorReporter errorReporter, - Instantiation mainDef, - boolean requiresTypes) { - Reactor reactor = ASTUtils.toDefinition(decl); + /** + * Generate necessary initialization code inside the body of the reaction that belongs to reactor + * decl. + * + * @param body The body of the reaction. Used to check for the + * DISABLE_REACTION_INITIALIZATION_MARKER. + * @param reaction The initialization code will be generated for this specific reaction + * @param decl The reactor that has the reaction + * @param reactionIndex The index of the reaction relative to other reactions in the reactor, + * starting from 0 + */ + public static String generateInitializationForReaction( + String body, + Reaction reaction, + Reactor decl, + int reactionIndex, + CTypes types, + ErrorReporter errorReporter, + Instantiation mainDef, + boolean requiresTypes) { + Reactor reactor = ASTUtils.toDefinition(decl); - // Construct the reactionInitialization code to go into - // the body of the function before the verbatim code. - CodeBuilder reactionInitialization = new CodeBuilder(); + // Construct the reactionInitialization code to go into + // the body of the function before the verbatim code. + CodeBuilder reactionInitialization = new CodeBuilder(); - CodeBuilder code = new CodeBuilder(); + CodeBuilder code = new CodeBuilder(); - // Define the "self" struct. - String structType = CUtil.selfType(decl); - // A null structType means there are no inputs, state, - // or anything else. No need to declare it. - if (structType != null) { - code.pr(String.join("\n", - structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" - )); - } + // Define the "self" struct. + String structType = CUtil.selfType(decl); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr( + String.join( + "\n", + structType + + "* self = (" + + structType + + "*)instance_args; SUPPRESS_UNUSED_WARNING(self);")); + } - // Do not generate the initialization code if the body is marked - // to not generate it. - if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { - return code.toString(); - } + // Do not generate the initialization code if the body is marked + // to not generate it. + if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { + return code.toString(); + } - // A reaction may send to or receive from multiple ports of - // a contained reactor. The variables for these ports need to - // all be declared as fields of the same struct. Hence, we first - // collect the fields to be defined in the structs and then - // generate the structs. - Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); + // A reaction may send to or receive from multiple ports of + // a contained reactor. The variables for these ports need to + // all be declared as fields of the same struct. Hence, we first + // collect the fields to be defined in the structs and then + // generate the structs. + Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); - // Actions may appear twice, first as a trigger, then with the outputs. - // But we need to declare it only once. Collect in this data structure - // the actions that are declared as triggered so that if they appear - // again with the outputs, they are not defined a second time. - // That second redefinition would trigger a compile error. - Set actionsAsTriggers = new LinkedHashSet<>(); + // Actions may appear twice, first as a trigger, then with the outputs. + // But we need to declare it only once. Collect in this data structure + // the actions that are declared as triggered so that if they appear + // again with the outputs, they are not defined a second time. + // That second redefinition would trigger a compile error. + Set actionsAsTriggers = new LinkedHashSet<>(); - // Next, add the triggers (input and actions; timers are not needed). - // This defines a local variable in the reaction function whose - // name matches that of the trigger. The value of the local variable - // is a struct with a value and is_present field, the latter a boolean - // that indicates whether the input/action is present. - // If the trigger is an output, then it is an output of a - // contained reactor. In this case, a struct with the name - // of the contained reactor is created with one field that is - // a pointer to a struct with a value and is_present field. - // E.g., if the contained reactor is named 'c' and its output - // port is named 'out', then c.out->value c.out->is_present are - // defined so that they can be used in the verbatim code. - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (triggerAsVarRef.getVariable() instanceof Port) { - generatePortVariablesInReaction( - reactionInitialization, - fieldsForStructsForContainedReactors, - triggerAsVarRef, - decl, - types); - } else if (triggerAsVarRef.getVariable() instanceof Action) { - reactionInitialization.pr(generateActionVariablesInReaction( - (Action) triggerAsVarRef.getVariable(), - decl, - types - )); - actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); - } - } - } - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - // No triggers are given, which means react to any input. - // Declare an argument for every input. - // NOTE: this does not include contained outputs. - for (Input input : reactor.getInputs()) { - reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); - } + // Next, add the triggers (input and actions; timers are not needed). + // This defines a local variable in the reaction function whose + // name matches that of the trigger. The value of the local variable + // is a struct with a value and is_present field, the latter a boolean + // that indicates whether the input/action is present. + // If the trigger is an output, then it is an output of a + // contained reactor. In this case, a struct with the name + // of the contained reactor is created with one field that is + // a pointer to a struct with a value and is_present field. + // E.g., if the contained reactor is named 'c' and its output + // port is named 'out', then c.out->value c.out->is_present are + // defined so that they can be used in the verbatim code. + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (triggerAsVarRef.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, + fieldsForStructsForContainedReactors, + triggerAsVarRef, + decl, + types); + } else if (triggerAsVarRef.getVariable() instanceof Action) { + reactionInitialization.pr( + generateActionVariablesInReaction( + (Action) triggerAsVarRef.getVariable(), decl, types)); + actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); } - // Define argument for non-triggering inputs. - for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - if (src.getVariable() instanceof Port) { - generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); - } else if (src.getVariable() instanceof Action) { - // It's a bit odd to read but not be triggered by an action, but - // OK, I guess we allow it. - reactionInitialization.pr(generateActionVariablesInReaction( - (Action) src.getVariable(), - decl, - types - )); - actionsAsTriggers.add((Action) src.getVariable()); - } - } - - // Define variables for each declared output or action. - // In the case of outputs, the variable is a pointer to where the - // output is stored. This gives the reaction code access to any previous - // value that may have been written to that output in an earlier reaction. - if (reaction.getEffects() != null) { - for (VarRef effect : reaction.getEffects()) { - Variable variable = effect.getVariable(); - if (variable instanceof Action) { - // It is an action, not an output. - // If it has already appeared as trigger, do not redefine it. - if (!actionsAsTriggers.contains(effect.getVariable())) { - reactionInitialization.pr(CGenerator.variableStructType(variable, decl, false)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); - } - } else if (effect.getVariable() instanceof Mode) { - // Mode change effect - int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); - String name = effect.getVariable().getName(); - if (idx >= 0) { - reactionInitialization.pr( - "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" - + "lf_mode_change_type_t _lf_" + name + "_change_type = " - + (effect.getTransition() == ModeTransition.HISTORY ? - "history_transition" : "reset_transition") - + ";" - ); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): " + name + " not a valid mode of this reactor." - ); - } - } else { - if (variable instanceof Output) { - reactionInitialization.pr(generateOutputVariablesInReaction( - effect, - decl, - errorReporter, - requiresTypes - )); - } else if (variable instanceof Input) { - // It is the input of a contained reactor. - generateVariablesForSendingToContainedReactors( - reactionInitialization, - fieldsForStructsForContainedReactors, - effect.getContainer(), - (Input) variable - ); - } else if (variable instanceof Watchdog) { - reactionInitialization.pr(generateWatchdogVariablesInReaction( - effect, - decl - )); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): effect is neither an input nor an output." - ); - } - } - } - } - // Before the reaction initialization, - // generate the structs used for communication to and from contained reactors. - for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - String array = ""; - if (containedReactor.getWidthSpec() != null) { - String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); - code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); - // Windows does not support variables in arrays declared on the stack, - // so we use the maximum size over all bank members. - array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; - } - code.pr(String.join("\n", - "struct "+containedReactor.getName()+" {", - " "+fieldsForStructsForContainedReactors.get(containedReactor)+"", - "} "+containedReactor.getName()+array+";" - )); - } - // Next generate all the collected setup code. - code.pr(reactionInitialization.toString()); - return code.toString(); + } + } + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + // No triggers are given, which means react to any input. + // Declare an argument for every input. + // NOTE: this does not include contained outputs. + for (Input input : reactor.getInputs()) { + reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); + } + } + // Define argument for non-triggering inputs. + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (src.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); + } else if (src.getVariable() instanceof Action) { + // It's a bit odd to read but not be triggered by an action, but + // OK, I guess we allow it. + reactionInitialization.pr( + generateActionVariablesInReaction((Action) src.getVariable(), decl, types)); + actionsAsTriggers.add((Action) src.getVariable()); + } } - /** - * Return the maximum bank width for the given instantiation within all - * instantiations of its parent reactor. - * On the first call to this method, the breadcrumbs should be null and the max - * argument should be zero. On recursive calls, breadcrumbs is a list of nested - * instantiations, the max is the maximum width found so far. The search for - * instances of the parent reactor will begin with the last instantiation - * in the specified list. - * - * This rather complicated method is used when a reaction sends or receives data - * to or from a bank of contained reactors. There will be an array of structs on - * the self struct of the parent, and the size of the array is conservatively set - * to the maximum of all the identified bank widths. This is a bit wasteful of - * memory, but it avoids having to malloc the array for each instance, and in - * typical usage, there will be few instances or instances that are all the same - * width. - * - * @param containedReactor The contained reactor instantiation. - * @param breadcrumbs null on first call (non-recursive). - * @param max 0 on first call. - */ - public static int maxContainedReactorBankWidth( - Instantiation containedReactor, - LinkedList breadcrumbs, - int max, - Instantiation mainDef - ) { - // If the instantiation is not a bank, return 1. - if (containedReactor.getWidthSpec() == null) { - return 1; - } - // If there is no main, then we just use the default width. - if (mainDef == null) { - return ASTUtils.width(containedReactor.getWidthSpec(), null); - } - LinkedList nestedBreadcrumbs = breadcrumbs; - if (nestedBreadcrumbs == null) { - nestedBreadcrumbs = new LinkedList<>(); - nestedBreadcrumbs.add(mainDef); - } - int result = max; - Reactor parent = (Reactor) containedReactor.eContainer(); - if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { - // The parent is main, so there can't be any other instantiations of it. - return ASTUtils.width(containedReactor.getWidthSpec(), null); - } - // Search for instances of the parent within the tail of the breadcrumbs list. - Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); - for (Instantiation instantiation : container.getInstantiations()) { - // Put this new instantiation at the head of the list. - nestedBreadcrumbs.add(0, instantiation); - if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { - // Found a matching instantiation of the parent. - // Evaluate the original width specification in this context. - int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); - if (candidate > result) { - result = candidate; - } - } else { - // Found some other instantiation, not the parent. - // Search within it for instantiations of the parent. - // Note that we assume here that the parent cannot contain - // instances of itself. - int candidate = maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); - if (candidate > result) { - result = candidate; - } - } - nestedBreadcrumbs.remove(); + // Define variables for each declared output or action. + // In the case of outputs, the variable is a pointer to where the + // output is stored. This gives the reaction code access to any previous + // value that may have been written to that output in an earlier reaction. + if (reaction.getEffects() != null) { + for (VarRef effect : reaction.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Action) { + // It is an action, not an output. + // If it has already appeared as trigger, do not redefine it. + if (!actionsAsTriggers.contains(effect.getVariable())) { + reactionInitialization.pr( + CGenerator.variableStructType(variable, decl, false) + + "* " + + variable.getName() + + " = &self->_lf_" + + variable.getName() + + ";"); + } + } else if (effect.getVariable() instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(reactor).indexOf((Mode) effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + reactionInitialization.pr( + "reactor_mode_t* " + + name + + " = &self->_lf__modes[" + + idx + + "];\n" + + "lf_mode_change_type_t _lf_" + + name + + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY + ? "history_transition" + : "reset_transition") + + ";"); + } else { + errorReporter.reportError( + reaction, "In generateReaction(): " + name + " not a valid mode of this reactor."); + } + } else { + if (variable instanceof Output) { + reactionInitialization.pr( + generateOutputVariablesInReaction(effect, decl, errorReporter, requiresTypes)); + } else if (variable instanceof Input) { + // It is the input of a contained reactor. + generateVariablesForSendingToContainedReactors( + reactionInitialization, + fieldsForStructsForContainedReactors, + effect.getContainer(), + (Input) variable); + } else if (variable instanceof Watchdog) { + reactionInitialization.pr(generateWatchdogVariablesInReaction(effect, decl)); + } else { + errorReporter.reportError( + reaction, "In generateReaction(): effect is neither an input nor an output."); + } } - return result; + } } - - /** - * Generate code for the body of a reaction that takes an input and - * schedules an action with the value of that input. - * @param actionName The action to schedule - */ - public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { - // Note that the action.type set by the base class is actually - // the port type. - return isTokenType ? - String.join("\n", - "if ("+ref+"->is_present) {", - " // Put the whole token on the event queue, not just the payload.", - " // This way, the length and element_size are transported.", - " lf_schedule_token("+actionName+", 0, "+ref+"->token);", - "}" - ) : - "lf_schedule_copy("+actionName+", 0, &"+ref+"->value, 1); // Length is 1."; + // Before the reaction initialization, + // generate the structs used for communication to and from contained reactors. + for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { + String array = ""; + if (containedReactor.getWidthSpec() != null) { + String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); + code.pr( + "int " + containedReactorWidthVar + " = self->_lf_" + containedReactorWidthVar + ";"); + // Windows does not support variables in arrays declared on the stack, + // so we use the maximum size over all bank members. + array = "[" + maxContainedReactorBankWidth(containedReactor, null, 0, mainDef) + "]"; + } + code.pr( + String.join( + "\n", + "struct " + containedReactor.getName() + " {", + " " + fieldsForStructsForContainedReactors.get(containedReactor) + "", + "} " + containedReactor.getName() + array + ";")); } + // Next generate all the collected setup code. + code.pr(reactionInitialization.toString()); + return code.toString(); + } - public static String generateForwardBody(String outputName, String targetType, String actionName, boolean isTokenType) { - return isTokenType ? - String.join("\n", - DISABLE_REACTION_INITIALIZATION_MARKER, - "self->_lf_"+outputName+".value = ("+targetType+")self->_lf__"+actionName+".tmplt.token->value;", - "_lf_replace_template_token((token_template_t*)&self->_lf_"+outputName+", (lf_token_t*)self->_lf__"+actionName+".tmplt.token);", - "self->_lf_"+outputName+".is_present = true;" - ) : - "lf_set("+outputName+", "+actionName+"->value);"; + /** + * Return the maximum bank width for the given instantiation within all instantiations of its + * parent reactor. On the first call to this method, the breadcrumbs should be null and the max + * argument should be zero. On recursive calls, breadcrumbs is a list of nested instantiations, + * the max is the maximum width found so far. The search for instances of the parent reactor will + * begin with the last instantiation in the specified list. + * + *

This rather complicated method is used when a reaction sends or receives data to or from a + * bank of contained reactors. There will be an array of structs on the self struct of the parent, + * and the size of the array is conservatively set to the maximum of all the identified bank + * widths. This is a bit wasteful of memory, but it avoids having to malloc the array for each + * instance, and in typical usage, there will be few instances or instances that are all the same + * width. + * + * @param containedReactor The contained reactor instantiation. + * @param breadcrumbs null on first call (non-recursive). + * @param max 0 on first call. + */ + public static int maxContainedReactorBankWidth( + Instantiation containedReactor, + LinkedList breadcrumbs, + int max, + Instantiation mainDef) { + // If the instantiation is not a bank, return 1. + if (containedReactor.getWidthSpec() == null) { + return 1; } - - /** - * Generate into the specified string builder the code to - * initialize local variables for sending data to an input - * of a contained reactor. This will also, if necessary, - * generate entries for local struct definitions into the - * struct argument. These entries point to where the data - * is stored. - * - * @param builder The string builder. - * @param structs A map from reactor instantiations to a place to write - * struct fields. - * @param definition AST node defining the reactor within which this occurs - * @param input Input of the contained reactor. - */ - private static void generateVariablesForSendingToContainedReactors( - CodeBuilder builder, - Map structs, - Instantiation definition, - Input input - ) { - CodeBuilder structBuilder = structs.get(definition); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(definition, structBuilder); + // If there is no main, then we just use the default width. + if (mainDef == null) { + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + LinkedList nestedBreadcrumbs = breadcrumbs; + if (nestedBreadcrumbs == null) { + nestedBreadcrumbs = new LinkedList<>(); + nestedBreadcrumbs.add(mainDef); + } + int result = max; + Reactor parent = (Reactor) containedReactor.eContainer(); + if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { + // The parent is main, so there can't be any other instantiations of it. + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + // Search for instances of the parent within the tail of the breadcrumbs list. + Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); + for (Instantiation instantiation : container.getInstantiations()) { + // Put this new instantiation at the head of the list. + nestedBreadcrumbs.add(0, instantiation); + if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { + // Found a matching instantiation of the parent. + // Evaluate the original width specification in this context. + int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); + if (candidate > result) { + result = candidate; } - String inputStructType = CGenerator.variableStructType(input, ASTUtils.toDefinition(definition.getReactorClass()), false); - String defName = definition.getName(); - String defWidth = generateWidthVariable(defName); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); - if (!ASTUtils.isMultiport(input)) { - // Contained reactor's input is not a multiport. - structBuilder.pr(inputStructType+"* "+inputName+";"); - if (definition.getWidthSpec() != null) { - // Contained reactor is a bank. - builder.pr(String.join("\n", - "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", - " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", - "}" - )); - } else { - // Contained reactor is not a bank. - builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); - } - } else { - // Contained reactor's input is a multiport. - structBuilder.pr(String.join("\n", - inputStructType+"** "+inputName+";", - "int "+inputWidth+";" - )); - // If the contained reactor is a bank, then we have to set the - // pointer for each element of the bank. - if (definition.getWidthSpec() != null) { - builder.pr(String.join("\n", - "for (int _i = 0; _i < self->_lf_"+defWidth+"; _i++) {", - " "+defName+"[_i]."+inputName+" = self->_lf_"+defName+"[_i]."+inputName+";", - " "+defName+"[_i]."+inputWidth+" = self->_lf_"+defName+"[_i]."+inputWidth+";", - "}" - )); - } else { - builder.pr(String.join("\n", - defName+"."+inputName+" = self->_lf_"+defName+"."+inputName+";", - defName+"."+inputWidth+" = self->_lf_"+defName+"."+inputWidth+";" - )); - } + } else { + // Found some other instantiation, not the parent. + // Search within it for instantiations of the parent. + // Note that we assume here that the parent cannot contain + // instances of itself. + int candidate = + maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); + if (candidate > result) { + result = candidate; } + } + nestedBreadcrumbs.remove(); } + return result; + } - /** - * Generate into the specified string builder the code to - * initialize local variables for ports in a reaction function - * from the "self" struct. The port may be an input of the - * reactor or an output of a contained reactor. The second - * argument provides, for each contained reactor, a place to - * write the declaration of the output of that reactor that - * is triggering reactions. - * @param builder The place into which to write the code. - * @param structs A map from reactor instantiations to a place to write - * struct fields. - */ - private static void generatePortVariablesInReaction( - CodeBuilder builder, - Map structs, - VarRef port, - Reactor r, - CTypes types - ) { - if (port.getVariable() instanceof Input) { - builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), r, types)); - } else { - // port is an output of a contained reactor. - Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, ASTUtils.toDefinition(port.getContainer().getReactorClass()), false); + /** + * Generate code for the body of a reaction that takes an input and schedules an action with the + * value of that input. + * + * @param actionName The action to schedule + */ + public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { + // Note that the action.type set by the base class is actually + // the port type. + return isTokenType + ? String.join( + "\n", + "if (" + ref + "->is_present) {", + " // Put the whole token on the event queue, not just the payload.", + " // This way, the length and element_size are transported.", + " lf_schedule_token(" + actionName + ", 0, " + ref + "->token);", + "}") + : "lf_schedule_copy(" + actionName + ", 0, &" + ref + "->value, 1); // Length is 1."; + } - CodeBuilder structBuilder = structs.get(port.getContainer()); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(port.getContainer(), structBuilder); - } - String reactorName = port.getContainer().getName(); - String reactorWidth = generateWidthVariable(reactorName); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - // First define the struct containing the output value and indicator - // of its presence. - if (!ASTUtils.isMultiport(output)) { - // Output is not a multiport. - structBuilder.pr(portStructType+"* "+outputName+";"); - } else { - // Output is a multiport. - structBuilder.pr(String.join("\n", - portStructType+"** "+outputName+";", - "int "+outputWidth+";" - )); - } + public static String generateForwardBody( + String outputName, String targetType, String actionName, boolean isTokenType) { + return isTokenType + ? String.join( + "\n", + DISABLE_REACTION_INITIALIZATION_MARKER, + "self->_lf_" + + outputName + + ".value = (" + + targetType + + ")self->_lf__" + + actionName + + ".tmplt.token->value;", + "_lf_replace_template_token((token_template_t*)&self->_lf_" + + outputName + + ", (lf_token_t*)self->_lf__" + + actionName + + ".tmplt.token);", + "self->_lf_" + outputName + ".is_present = true;") + : "lf_set(" + outputName + ", " + actionName + "->value);"; + } - // Next, initialize the struct with the current values. - if (port.getContainer().getWidthSpec() != null) { - // Output is in a bank. - builder.pr(String.join("\n", - "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+reactorName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", - "}" - )); - if (ASTUtils.isMultiport(output)) { - builder.pr(String.join("\n", - "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+reactorName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", - "}" - )); - } - } else { - // Output is not in a bank. - builder.pr(reactorName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); - if (ASTUtils.isMultiport(output)) { - builder.pr(reactorName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); - } - } - } + /** + * Generate into the specified string builder the code to initialize local variables for sending + * data to an input of a contained reactor. This will also, if necessary, generate entries for + * local struct definitions into the struct argument. These entries point to where the data is + * stored. + * + * @param builder The string builder. + * @param structs A map from reactor instantiations to a place to write struct fields. + * @param definition AST node defining the reactor within which this occurs + * @param input Input of the contained reactor. + */ + private static void generateVariablesForSendingToContainedReactors( + CodeBuilder builder, + Map structs, + Instantiation definition, + Input input) { + CodeBuilder structBuilder = structs.get(definition); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(definition, structBuilder); } - - /** Generate action variables for a reaction. - * @param action The action. - */ - private static String generateActionVariablesInReaction( - Action action, - Reactor r, - CTypes types - ) { - String structType = CGenerator.variableStructType(action, r, false); - // If the action has a type, create variables for accessing the value. - InferredType type = ASTUtils.getInferredType(action); - // Pointer to the lf_token_t sent as the payload in the trigger. - String tokenPointer = "(self->_lf__"+action.getName()+".tmplt.token)"; - CodeBuilder builder = new CodeBuilder(); - + String inputStructType = + CGenerator.variableStructType( + input, ASTUtils.toDefinition(definition.getReactorClass()), false); + String defName = definition.getName(); + String defWidth = generateWidthVariable(defName); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); + if (!ASTUtils.isMultiport(input)) { + // Contained reactor's input is not a multiport. + structBuilder.pr(inputStructType + "* " + inputName + ";"); + if (definition.getWidthSpec() != null) { + // Contained reactor is a bank. builder.pr( - String.join("\n", - "// Expose the action struct as a local variable whose name matches the action name.", - structType+"* "+action.getName()+" = &self->_lf_"+action.getName()+";", - "// Set the fields of the action struct to match the current trigger.", - action.getName()+"->is_present = (bool)self->_lf__"+action.getName()+".status;", - action.getName()+"->has_value = ("+tokenPointer+" != NULL && "+tokenPointer+"->value != NULL);", - "_lf_replace_template_token((token_template_t*)"+action.getName()+", "+tokenPointer+");") - ); - // Set the value field only if there is a type. - if (!type.isUndefined()) { - // The value field will either be a copy (for primitive types) - // or a pointer (for types ending in *). - builder.pr("if ("+action.getName()+"->has_value) {"); - builder.indent(); - if (CUtil.isTokenType(type, types)) { - builder.pr(action.getName()+"->value = ("+types.getTargetType(type)+")"+tokenPointer+"->value;"); - } else { - builder.pr(action.getName()+"->value = *("+types.getTargetType(type)+"*)"+tokenPointer+"->value;"); - } - builder.unindent(); - builder.pr("}"); - } - return builder.toString(); + String.join( + "\n", + "for (int bankIndex = 0; bankIndex < self->_lf_" + defWidth + "; bankIndex++) {", + " " + + defName + + "[bankIndex]." + + inputName + + " = &(self->_lf_" + + defName + + "[bankIndex]." + + inputName + + ");", + "}")); + } else { + // Contained reactor is not a bank. + builder.pr( + defName + "." + inputName + " = &(self->_lf_" + defName + "." + inputName + ");"); + } + } else { + // Contained reactor's input is a multiport. + structBuilder.pr( + String.join("\n", inputStructType + "** " + inputName + ";", "int " + inputWidth + ";")); + // If the contained reactor is a bank, then we have to set the + // pointer for each element of the bank. + if (definition.getWidthSpec() != null) { + builder.pr( + String.join( + "\n", + "for (int _i = 0; _i < self->_lf_" + defWidth + "; _i++) {", + " " + + defName + + "[_i]." + + inputName + + " = self->_lf_" + + defName + + "[_i]." + + inputName + + ";", + " " + + defName + + "[_i]." + + inputWidth + + " = self->_lf_" + + defName + + "[_i]." + + inputWidth + + ";", + "}")); + } else { + builder.pr( + String.join( + "\n", + defName + "." + inputName + " = self->_lf_" + defName + "." + inputName + ";", + defName + "." + inputWidth + " = self->_lf_" + defName + "." + inputWidth + ";")); + } } + } - /** Generate into the specified string builder the code to - * initialize local variables for the specified input port - * in a reaction function from the "self" struct. - * @param input The input statement from the AST. - * @param r The reactor. - */ - private static String generateInputVariablesInReaction( - Input input, - Reactor r, - CTypes types - ) { - String structType = CGenerator.variableStructType(input, r, false); - InferredType inputType = ASTUtils.getInferredType(input); - CodeBuilder builder = new CodeBuilder(); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); + /** + * Generate into the specified string builder the code to initialize local variables for ports in + * a reaction function from the "self" struct. The port may be an input of the reactor or an + * output of a contained reactor. The second argument provides, for each contained reactor, a + * place to write the declaration of the output of that reactor that is triggering reactions. + * + * @param builder The place into which to write the code. + * @param structs A map from reactor instantiations to a place to write struct fields. + */ + private static void generatePortVariablesInReaction( + CodeBuilder builder, + Map structs, + VarRef port, + Reactor r, + CTypes types) { + if (port.getVariable() instanceof Input) { + builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), r, types)); + } else { + // port is an output of a contained reactor. + Output output = (Output) port.getVariable(); + String portStructType = + CGenerator.variableStructType( + output, ASTUtils.toDefinition(port.getContainer().getReactorClass()), false); - // Create the local variable whose name matches the input name. - // If the input has not been declared mutable, then this is a pointer - // to the upstream output. Otherwise, it is a copy of the upstream output, - // which nevertheless points to the same token and value (hence, as done - // below, we have to use lf_writable_copy()). There are 8 cases, - // depending on whether the input is mutable, whether it is a multiport, - // and whether it is a token type. - // Easy case first. - if (!input.isMutable() && !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, primitive type. - builder.pr(structType+"* "+inputName+" = self->_lf_"+inputName+";"); - } else if (input.isMutable()&& !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, primitive type. - builder.pr(String.join("\n", - "// Mutable input, so copy the input into a temporary variable.", - "// The input value on the struct is a copy.", - structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", - structType+"* "+inputName+" = &_lf_tmp_"+inputName+";" - )); - } else if (!input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, token type. - builder.pr(String.join("\n", - structType+"* "+inputName+" = self->_lf_"+inputName+";", - "if ("+inputName+"->is_present) {", - " "+inputName+"->length = "+inputName+"->token->length;", - " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", - "} else {", - " "+inputName+"->length = 0;", - "}" - )); - } else if (input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, token type. - builder.pr(String.join("\n", - "// Mutable input, so copy the input struct into a temporary variable.", - structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", - structType+"* "+inputName+" = &_lf_tmp_"+inputName+";", - inputName+"->value = NULL;", // Prevent payload from being freed. - "if ("+inputName+"->is_present) {", - " "+inputName+"->length = "+inputName+"->token->length;", - " "+inputName+"->token = lf_writable_copy((lf_port_base_t*)self->_lf_"+inputName+");", - " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", - "} else {", - " "+inputName+"->length = 0;", - "}" - )); - } else if (!input.isMutable()&& ASTUtils.isMultiport(input)) { - // Non-mutable, multiport, primitive or token type. - builder.pr(structType+"** "+inputName+" = self->_lf_"+inputName+";"); - } else if (CUtil.isTokenType(inputType, types)) { - // Mutable, multiport, token type - builder.pr(String.join("\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", - " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", - " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", - " // If necessary, copy the tokens.", - " if ("+inputName+"[i]->is_present) {", - " "+inputName+"[i]->length = "+inputName+"[i]->token->length;", - " token_template_t* _lf_input = (token_template_t*)self->_lf_"+inputName+"[i];", - " "+inputName+"[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", - " "+inputName+"[i]->value = ("+types.getTargetType(inputType)+")"+inputName+"[i]->token->value;", - " } else {", - " "+inputName+"[i]->length = 0;", - " }", - "}" - )); - } else { - // Mutable, multiport, primitive type - builder.pr(String.join("\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", - " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", - " // Copy the struct, which includes the value.", - " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", - "}" - )); + CodeBuilder structBuilder = structs.get(port.getContainer()); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(port.getContainer(), structBuilder); + } + String reactorName = port.getContainer().getName(); + String reactorWidth = generateWidthVariable(reactorName); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + // First define the struct containing the output value and indicator + // of its presence. + if (!ASTUtils.isMultiport(output)) { + // Output is not a multiport. + structBuilder.pr(portStructType + "* " + outputName + ";"); + } else { + // Output is a multiport. + structBuilder.pr( + String.join( + "\n", portStructType + "** " + outputName + ";", "int " + outputWidth + ";")); + } + + // Next, initialize the struct with the current values. + if (port.getContainer().getWidthSpec() != null) { + // Output is in a bank. + builder.pr( + String.join( + "\n", + "for (int i = 0; i < " + reactorWidth + "; i++) {", + " " + + reactorName + + "[i]." + + outputName + + " = self->_lf_" + + reactorName + + "[i]." + + outputName + + ";", + "}")); + if (ASTUtils.isMultiport(output)) { + builder.pr( + String.join( + "\n", + "for (int i = 0; i < " + reactorWidth + "; i++) {", + " " + + reactorName + + "[i]." + + outputWidth + + " = self->_lf_" + + reactorName + + "[i]." + + outputWidth + + ";", + "}")); + } + } else { + // Output is not in a bank. + builder.pr( + reactorName + + "." + + outputName + + " = self->_lf_" + + reactorName + + "." + + outputName + + ";"); + if (ASTUtils.isMultiport(output)) { + builder.pr( + reactorName + + "." + + outputWidth + + " = self->_lf_" + + reactorName + + "." + + outputWidth + + ";"); } - // Set the _width variable for all cases. This will be -1 - // for a variable-width multiport, which is not currently supported. - // It will be -2 if it is not multiport. - builder.pr("int "+inputWidth+" = self->_lf_"+inputWidth+"; SUPPRESS_UNUSED_WARNING("+inputWidth+");"); - return builder.toString(); + } } + } - /** - * Generate into the specified string builder the code to - * initialize local variables for outputs in a reaction function - * from the "self" struct. - * @param effect The effect declared by the reaction. This must refer to an output. - * @param r The reactor containing the reaction. - */ - public static String generateOutputVariablesInReaction( - VarRef effect, - Reactor r, - ErrorReporter errorReporter, - boolean requiresTypes - ) { - Output output = (Output) effect.getVariable(); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - if (output.getType() == null && requiresTypes) { - errorReporter.reportError(output, "Output is required to have a type: " + outputName); - return ""; - } else { - // The container of the output may be a contained reactor or - // the reactor containing the reaction. - String outputStructType = (effect.getContainer() == null) ? - CGenerator.variableStructType(output, r, false) - : - CGenerator.variableStructType(output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); - if (!ASTUtils.isMultiport(output)) { - // Output port is not a multiport. - return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; - } else { - // Output port is a multiport. - // Set the _width variable. - return String.join("\n", - "int "+outputWidth+" = self->_lf_"+outputWidth+"; SUPPRESS_UNUSED_WARNING("+outputWidth+");", - outputStructType+"** "+outputName+" = self->_lf_"+outputName+"_pointers;" - ); + /** + * Generate action variables for a reaction. + * + * @param action The action. + */ + private static String generateActionVariablesInReaction(Action action, Reactor r, CTypes types) { + String structType = CGenerator.variableStructType(action, r, false); + // If the action has a type, create variables for accessing the value. + InferredType type = ASTUtils.getInferredType(action); + // Pointer to the lf_token_t sent as the payload in the trigger. + String tokenPointer = "(self->_lf__" + action.getName() + ".tmplt.token)"; + CodeBuilder builder = new CodeBuilder(); - } - } + builder.pr( + String.join( + "\n", + "// Expose the action struct as a local variable whose name matches the action name.", + structType + "* " + action.getName() + " = &self->_lf_" + action.getName() + ";", + "// Set the fields of the action struct to match the current trigger.", + action.getName() + "->is_present = (bool)self->_lf__" + action.getName() + ".status;", + action.getName() + + "->has_value = (" + + tokenPointer + + " != NULL && " + + tokenPointer + + "->value != NULL);", + "_lf_replace_template_token((token_template_t*)" + + action.getName() + + ", " + + tokenPointer + + ");")); + // Set the value field only if there is a type. + if (!type.isUndefined()) { + // The value field will either be a copy (for primitive types) + // or a pointer (for types ending in *). + builder.pr("if (" + action.getName() + "->has_value) {"); + builder.indent(); + if (CUtil.isTokenType(type, types)) { + builder.pr( + action.getName() + + "->value = (" + + types.getTargetType(type) + + ")" + + tokenPointer + + "->value;"); + } else { + builder.pr( + action.getName() + + "->value = *(" + + types.getTargetType(type) + + "*)" + + tokenPointer + + "->value;"); + } + builder.unindent(); + builder.pr("}"); } + return builder.toString(); + } - /** - * Generate into the specified string builder the code to - * initialize local variables for watchdogs in a reaction function - * from the "self" struct. - * @param effect The effect declared by the reaction. This must refer to a watchdog. - * @param decl The reactor containing the reaction or the import statement. - */ - // Fine to have watchdog be in reactor self struct? - public static String generateWatchdogVariablesInReaction( - VarRef effect, - ReactorDecl decl - ) { - Watchdog watchdog = (Watchdog) effect.getVariable(); - String watchdogName = watchdog.getName(); + /** + * Generate into the specified string builder the code to initialize local variables for the + * specified input port in a reaction function from the "self" struct. + * + * @param input The input statement from the AST. + * @param r The reactor. + */ + private static String generateInputVariablesInReaction(Input input, Reactor r, CTypes types) { + String structType = CGenerator.variableStructType(input, r, false); + InferredType inputType = ASTUtils.getInferredType(input); + CodeBuilder builder = new CodeBuilder(); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); - return String.join("\n", List.of( - "watchdog_t* "+watchdogName+" = &(self->_lf_watchdog_"+watchdogName+");" - )); + // Create the local variable whose name matches the input name. + // If the input has not been declared mutable, then this is a pointer + // to the upstream output. Otherwise, it is a copy of the upstream output, + // which nevertheless points to the same token and value (hence, as done + // below, we have to use lf_writable_copy()). There are 8 cases, + // depending on whether the input is mutable, whether it is a multiport, + // and whether it is a token type. + // Easy case first. + if (!input.isMutable() + && !CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, primitive type. + builder.pr(structType + "* " + inputName + " = self->_lf_" + inputName + ";"); + } else if (input.isMutable() + && !CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, primitive type. + builder.pr( + String.join( + "\n", + "// Mutable input, so copy the input into a temporary variable.", + "// The input value on the struct is a copy.", + structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", + structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";")); + } else if (!input.isMutable() + && CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, token type. + builder.pr( + String.join( + "\n", + structType + "* " + inputName + " = self->_lf_" + inputName + ";", + "if (" + inputName + "->is_present) {", + " " + inputName + "->length = " + inputName + "->token->length;", + " " + + inputName + + "->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "->token->value;", + "} else {", + " " + inputName + "->length = 0;", + "}")); + } else if (input.isMutable() + && CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, token type. + builder.pr( + String.join( + "\n", + "// Mutable input, so copy the input struct into a temporary variable.", + structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", + structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";", + inputName + "->value = NULL;", // Prevent payload from being freed. + "if (" + inputName + "->is_present) {", + " " + inputName + "->length = " + inputName + "->token->length;", + " " + + inputName + + "->token = lf_writable_copy((lf_port_base_t*)self->_lf_" + + inputName + + ");", + " " + + inputName + + "->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "->token->value;", + "} else {", + " " + inputName + "->length = 0;", + "}")); + } else if (!input.isMutable() && ASTUtils.isMultiport(input)) { + // Non-mutable, multiport, primitive or token type. + builder.pr(structType + "** " + inputName + " = self->_lf_" + inputName + ";"); + } else if (CUtil.isTokenType(inputType, types)) { + // Mutable, multiport, token type + builder.pr( + String.join( + "\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType + + " _lf_tmp_" + + inputName + + "[" + + CUtil.multiportWidthExpression(input) + + "];", + structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", + "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", + " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", + " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", + " // If necessary, copy the tokens.", + " if (" + inputName + "[i]->is_present) {", + " " + inputName + "[i]->length = " + inputName + "[i]->token->length;", + " token_template_t* _lf_input = (token_template_t*)self->_lf_" + + inputName + + "[i];", + " " + inputName + "[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", + " " + + inputName + + "[i]->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "[i]->token->value;", + " } else {", + " " + inputName + "[i]->length = 0;", + " }", + "}")); + } else { + // Mutable, multiport, primitive type + builder.pr( + String.join( + "\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType + + " _lf_tmp_" + + inputName + + "[" + + CUtil.multiportWidthExpression(input) + + "];", + structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", + "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", + " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", + " // Copy the struct, which includes the value.", + " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", + "}")); } + // Set the _width variable for all cases. This will be -1 + // for a variable-width multiport, which is not currently supported. + // It will be -2 if it is not multiport. + builder.pr( + "int " + + inputWidth + + " = self->_lf_" + + inputWidth + + "; SUPPRESS_UNUSED_WARNING(" + + inputWidth + + ");"); + return builder.toString(); + } - /** - * Generate the fields of the self struct and statements for the constructor - * to create and initialize a reaction_t struct for each reaction in the - * specified reactor and a trigger_t struct for each trigger (input, action, - * timer, or output of a contained reactor). - * @param body The place to put the code for the self struct. - * @param reactor The reactor. - * @param constructorCode The place to put the constructor code. - */ - public static void generateReactionAndTriggerStructs( - CodeBuilder body, - Reactor reactor, - CodeBuilder constructorCode, - CTypes types - ) { - var reactionCount = 0; - // Iterate over reactions and create initialize the reaction_t struct - // on the self struct. Also, collect a map from triggers to the reactions - // that are triggered by that trigger. Also, collect a set of sources - // that are read by reactions but do not trigger reactions. - // Finally, collect a set of triggers and sources that are outputs - // of contained reactors. - var triggerMap = new LinkedHashMap>(); - var sourceSet = new LinkedHashSet(); - var outputsOfContainedReactors = new LinkedHashMap(); - var startupReactions = new LinkedHashSet(); - var shutdownReactions = new LinkedHashSet(); - var resetReactions = new LinkedHashSet(); - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create the reaction_t struct. - body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); + /** + * Generate into the specified string builder the code to initialize local variables for outputs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to an output. + * @param r The reactor containing the reaction. + */ + public static String generateOutputVariablesInReaction( + VarRef effect, Reactor r, ErrorReporter errorReporter, boolean requiresTypes) { + Output output = (Output) effect.getVariable(); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + if (output.getType() == null && requiresTypes) { + errorReporter.reportError(output, "Output is required to have a type: " + outputName); + return ""; + } else { + // The container of the output may be a contained reactor or + // the reactor containing the reaction. + String outputStructType = + (effect.getContainer() == null) + ? CGenerator.variableStructType(output, r, false) + : CGenerator.variableStructType( + output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); + if (!ASTUtils.isMultiport(output)) { + // Output port is not a multiport. + return outputStructType + "* " + outputName + " = &self->_lf_" + outputName + ";"; + } else { + // Output port is a multiport. + // Set the _width variable. + return String.join( + "\n", + "int " + + outputWidth + + " = self->_lf_" + + outputWidth + + "; SUPPRESS_UNUSED_WARNING(" + + outputWidth + + ");", + outputStructType + "** " + outputName + " = self->_lf_" + outputName + "_pointers;"); + } + } + } - // Create the map of triggers to reactions. - for (TriggerRef trigger : reaction.getTriggers()) { - // trigger may not be a VarRef (it could be "startup" or "shutdown"). - if (trigger instanceof VarRef) { - var triggerAsVarRef = (VarRef) trigger; - var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); - if (reactionList == null) { - reactionList = new LinkedList<>(); - triggerMap.put(triggerAsVarRef.getVariable(), reactionList); - } - reactionList.add(reactionCount); - if (triggerAsVarRef.getContainer() != null) { - outputsOfContainedReactors.put(triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); - } - } else if (trigger instanceof BuiltinTriggerRef) { - switch(((BuiltinTriggerRef) trigger).getType()) { - case STARTUP: - startupReactions.add(reactionCount); - break; - case SHUTDOWN: - shutdownReactions.add(reactionCount); - break; - case RESET: - resetReactions.add(reactionCount); - break; - } - } - } - // Create the set of sources read but not triggering. - for (VarRef source : reaction.getSources()) { - sourceSet.add(source.getVariable()); - if (source.getContainer() != null) { - outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); - } - } + /** + * Generate into the specified string builder the code to initialize local variables for watchdogs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to a watchdog. + * @param decl The reactor containing the reaction or the import statement. + */ + // Fine to have watchdog be in reactor self struct? + public static String generateWatchdogVariablesInReaction(VarRef effect, ReactorDecl decl) { + Watchdog watchdog = (Watchdog) effect.getVariable(); + String watchdogName = watchdog.getName(); - var deadlineFunctionPointer = "NULL"; - if (reaction.getDeadline() != null) { - // The following has to match the name chosen in generateReactions - var deadlineFunctionName = generateDeadlineFunctionName(reactor, reactionCount); - deadlineFunctionPointer = "&" + deadlineFunctionName; - } + return String.join( + "\n", + List.of("watchdog_t* " + watchdogName + " = &(self->_lf_watchdog_" + watchdogName + ");")); + } - // Assign the STP handler - var STPFunctionPointer = "NULL"; - if (reaction.getStp() != null) { - // The following has to match the name chosen in generateReactions - var STPFunctionName = generateStpFunctionName(reactor, reactionCount); - STPFunctionPointer = "&" + STPFunctionName; - } + /** + * Generate the fields of the self struct and statements for the constructor to create and + * initialize a reaction_t struct for each reaction in the specified reactor and a trigger_t + * struct for each trigger (input, action, timer, or output of a contained reactor). + * + * @param body The place to put the code for the self struct. + * @param reactor The reactor. + * @param constructorCode The place to put the constructor code. + */ + public static void generateReactionAndTriggerStructs( + CodeBuilder body, Reactor reactor, CodeBuilder constructorCode, CTypes types) { + var reactionCount = 0; + // Iterate over reactions and create initialize the reaction_t struct + // on the self struct. Also, collect a map from triggers to the reactions + // that are triggered by that trigger. Also, collect a set of sources + // that are read by reactions but do not trigger reactions. + // Finally, collect a set of triggers and sources that are outputs + // of contained reactors. + var triggerMap = new LinkedHashMap>(); + var sourceSet = new LinkedHashSet(); + var outputsOfContainedReactors = new LinkedHashMap(); + var startupReactions = new LinkedHashSet(); + var shutdownReactions = new LinkedHashSet(); + var resetReactions = new LinkedHashSet(); + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create the reaction_t struct. + body.pr(reaction, "reaction_t _lf__reaction_" + reactionCount + ";"); - // Set the defaults of the reaction_t struct in the constructor. - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__reaction_"+reactionCount+".index = 0; - // self->_lf__reaction_"+reactionCount+".chain_id = 0; - // self->_lf__reaction_"+reactionCount+".pos = 0; - // self->_lf__reaction_"+reactionCount+".status = inactive; - // self->_lf__reaction_"+reactionCount+".deadline = 0LL; - // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; - constructorCode.pr(reaction, String.join("\n", - "self->_lf__reaction_"+reactionCount+".number = "+reactionCount+";", - "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(reactor, reactionCount)+";", - "self->_lf__reaction_"+reactionCount+".self = self;", - "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", - (reaction.eContainer() instanceof Mode ? - "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+reactor.getModes().indexOf((Mode) reaction.eContainer())+"];" : - "self->_lf__reaction_"+reactionCount+".mode = NULL;") - )); - // Increment the reactionCount even if the reaction is not in the federate - // so that reaction indices are consistent across federates. - reactionCount++; + // Create the map of triggers to reactions. + for (TriggerRef trigger : reaction.getTriggers()) { + // trigger may not be a VarRef (it could be "startup" or "shutdown"). + if (trigger instanceof VarRef) { + var triggerAsVarRef = (VarRef) trigger; + var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); + if (reactionList == null) { + reactionList = new LinkedList<>(); + triggerMap.put(triggerAsVarRef.getVariable(), reactionList); + } + reactionList.add(reactionCount); + if (triggerAsVarRef.getContainer() != null) { + outputsOfContainedReactors.put( + triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); + } + } else if (trigger instanceof BuiltinTriggerRef) { + switch (((BuiltinTriggerRef) trigger).getType()) { + case STARTUP: + startupReactions.add(reactionCount); + break; + case SHUTDOWN: + shutdownReactions.add(reactionCount); + break; + case RESET: + resetReactions.add(reactionCount); + break; + } } - - // Next, create and initialize the trigger_t objects. - // Start with the timers. - for (Timer timer : ASTUtils.allTimers(reactor)) { - createTriggerT(body, timer, triggerMap, constructorCode, types); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); - constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+timer.getName()+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + } + // Create the set of sources read but not triggering. + for (VarRef source : reaction.getSources()) { + sourceSet.add(source.getVariable()); + if (source.getContainer() != null) { + outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); } + } - // Handle builtin triggers. - if (startupReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); - } - // Handle shutdown triggers. - if (shutdownReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); - } - if (resetReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); - } + var deadlineFunctionPointer = "NULL"; + if (reaction.getDeadline() != null) { + // The following has to match the name chosen in generateReactions + var deadlineFunctionName = generateDeadlineFunctionName(reactor, reactionCount); + deadlineFunctionPointer = "&" + deadlineFunctionName; + } - // Next handle actions. - for (Action action : ASTUtils.allActions(reactor)) { - createTriggerT(body, action, triggerMap, constructorCode, types); - var isPhysical = "true"; - if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { - isPhysical = "false"; - } - var elementSize = "0"; - // If the action type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) - : null; - if (rootType != null && !rootType.equals("void")) { - elementSize = "sizeof(" + rootType + ")"; - } + // Assign the STP handler + var STPFunctionPointer = "NULL"; + if (reaction.getStp() != null) { + // The following has to match the name chosen in generateReactions + var STPFunctionName = generateStpFunctionName(reactor, reactionCount); + STPFunctionPointer = "&" + STPFunctionName; + } - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__"+action.getName()+".is_timer = false; - constructorCode.pr(String.join("\n", - "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", - (!(action.getPolicy() == null || action.getPolicy().isEmpty()) ? - "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" : - ""), - // Need to set the element_size in the trigger_t and the action struct. - "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize - + ";", - "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";" - )); - } + // Set the defaults of the reaction_t struct in the constructor. + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__reaction_"+reactionCount+".index = 0; + // self->_lf__reaction_"+reactionCount+".chain_id = 0; + // self->_lf__reaction_"+reactionCount+".pos = 0; + // self->_lf__reaction_"+reactionCount+".status = inactive; + // self->_lf__reaction_"+reactionCount+".deadline = 0LL; + // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; + constructorCode.pr( + reaction, + String.join( + "\n", + "self->_lf__reaction_" + reactionCount + ".number = " + reactionCount + ";", + "self->_lf__reaction_" + + reactionCount + + ".function = " + + CReactionGenerator.generateReactionFunctionName(reactor, reactionCount) + + ";", + "self->_lf__reaction_" + reactionCount + ".self = self;", + "self->_lf__reaction_" + + reactionCount + + ".deadline_violation_handler = " + + deadlineFunctionPointer + + ";", + "self->_lf__reaction_" + reactionCount + ".STP_handler = " + STPFunctionPointer + ";", + "self->_lf__reaction_" + reactionCount + ".name = " + addDoubleQuotes("?") + ";", + (reaction.eContainer() instanceof Mode + ? "self->_lf__reaction_" + + reactionCount + + ".mode = &self->_lf__modes[" + + reactor.getModes().indexOf((Mode) reaction.eContainer()) + + "];" + : "self->_lf__reaction_" + reactionCount + ".mode = NULL;"))); + // Increment the reactionCount even if the reaction is not in the federate + // so that reaction indices are consistent across federates. + reactionCount++; + } - // Next handle inputs. - for (Input input : ASTUtils.allInputs(reactor)) { - createTriggerT(body, input, triggerMap, constructorCode, types); - } + // Next, create and initialize the trigger_t objects. + // Start with the timers. + for (Timer timer : ASTUtils.allTimers(reactor)) { + createTriggerT(body, timer, triggerMap, constructorCode, types); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + constructorCode.pr("self->_lf__" + timer.getName() + ".is_timer = true;"); + constructorCode.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + + timer.getName() + + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + } - // Next handle watchdogs. - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - createTriggerT(body, watchdog, triggerMap, constructorCode, types); - } + // Handle builtin triggers. + if (startupReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); + } + // Handle shutdown triggers. + if (shutdownReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); + } + if (resetReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); } - /** - * Define the trigger_t object on the self struct, an array of - * reaction_t pointers pointing to reactions triggered by this variable, - * and initialize the pointers in the array in the constructor. - * @param body The place to write the self struct entries. - * @param variable The trigger variable (Timer, Action, Watchdog, or Input). - * @param triggerMap A map from Variables to a list of the reaction indices - * triggered by the variable. - * @param constructorCode The place to write the constructor code. - */ - private static void createTriggerT( - CodeBuilder body, - Variable variable, - LinkedHashMap> triggerMap, - CodeBuilder constructorCode, - CTypes types - ) { - var varName = variable.getName(); - // variable is a port, a timer, or an action. - body.pr(variable, "trigger_t _lf__"+varName+";"); - constructorCode.pr(variable, "self->_lf__"+varName+".last = NULL;"); - constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+varName+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + // Next handle actions. + for (Action action : ASTUtils.allActions(reactor)) { + createTriggerT(body, action, triggerMap, constructorCode, types); + var isPhysical = "true"; + if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { + isPhysical = "false"; + } + var elementSize = "0"; + // If the action type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) : null; + if (rootType != null && !rootType.equals("void")) { + elementSize = "sizeof(" + rootType + ")"; + } - // Generate the reactions triggered table. - var reactionsTriggered = triggerMap.get(variable); - if (reactionsTriggered != null) { - body.pr(variable, "reaction_t* _lf__"+varName+"_reactions["+reactionsTriggered.size()+"];"); - var count = 0; - for (Integer reactionTriggered : reactionsTriggered) { - constructorCode.prSourceLineNumber(variable); - constructorCode.pr(variable, "self->_lf__"+varName+"_reactions["+count+"] = &self->_lf__reaction_"+reactionTriggered+";"); - count++; - } - // Set up the trigger_t struct's pointer to the reactions. - constructorCode.pr(variable, String.join("\n", - "self->_lf__"+varName+".reactions = &self->_lf__"+varName+"_reactions[0];", - "self->_lf__"+varName+".number_of_reactions = "+count+";" - )); + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__"+action.getName()+".is_timer = false; + constructorCode.pr( + String.join( + "\n", + "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", + (!(action.getPolicy() == null || action.getPolicy().isEmpty()) + ? "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" + : ""), + // Need to set the element_size in the trigger_t and the action struct. + "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize + ";", + "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";")); + } - // If federated, set the physical_time_of_arrival - constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederated( - "self->_lf__"+varName+".physical_time_of_arrival = NEVER;")); - } - if (variable instanceof Input) { - var rootType = CUtil.rootType(types.getTargetType((Input) variable)); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - // If the input type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; + // Next handle inputs. + for (Input input : ASTUtils.allInputs(reactor)) { + createTriggerT(body, input, triggerMap, constructorCode, types); + } - constructorCode.pr("self->_lf__"+varName+".tmplt.type.element_size = "+size+";"); - body.pr( - CExtensionUtils.surroundWithIfFederated( - CExtensionUtils.createPortStatusFieldForInput((Input) variable) - ) - ); - } + // Next handle watchdogs. + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + createTriggerT(body, watchdog, triggerMap, constructorCode, types); } + } - public static void generateBuiltinTriggeredReactionsArray( - Set reactions, - String name, - CodeBuilder body, - CodeBuilder constructorCode - ) { - body.pr(String.join("\n", - "trigger_t _lf__"+name+";", - "reaction_t* _lf__"+name+"_reactions["+reactions.size()+"];" - )); - constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+name+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - var i = 0; - for (Integer reactionIndex : reactions) { - constructorCode.pr("self->_lf__"+name+"_reactions["+i+++"] = &self->_lf__reaction_"+reactionIndex+";"); - } - constructorCode.pr(String.join("\n", - "self->_lf__"+name+".last = NULL;", - "self->_lf__"+name+".reactions = &self->_lf__"+name+"_reactions[0];", - "self->_lf__"+name+".number_of_reactions = "+reactions.size()+";", - "self->_lf__"+name+".is_timer = false;" - )); + /** + * Define the trigger_t object on the self struct, an array of reaction_t pointers pointing to + * reactions triggered by this variable, and initialize the pointers in the array in the + * constructor. + * + * @param body The place to write the self struct entries. + * @param variable The trigger variable (Timer, Action, Watchdog, or Input). + * @param triggerMap A map from Variables to a list of the reaction indices triggered by the + * variable. + * @param constructorCode The place to write the constructor code. + */ + private static void createTriggerT( + CodeBuilder body, + Variable variable, + LinkedHashMap> triggerMap, + CodeBuilder constructorCode, + CTypes types) { + var varName = variable.getName(); + // variable is a port, a timer, or an action. + body.pr(variable, "trigger_t _lf__" + varName + ";"); + constructorCode.pr(variable, "self->_lf__" + varName + ".last = NULL;"); + constructorCode.pr( + variable, + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + + varName + + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + + // Generate the reactions triggered table. + var reactionsTriggered = triggerMap.get(variable); + if (reactionsTriggered != null) { + body.pr( + variable, + "reaction_t* _lf__" + varName + "_reactions[" + reactionsTriggered.size() + "];"); + var count = 0; + for (Integer reactionTriggered : reactionsTriggered) { + constructorCode.prSourceLineNumber(variable); + constructorCode.pr( + variable, + "self->_lf__" + + varName + + "_reactions[" + + count + + "] = &self->_lf__reaction_" + + reactionTriggered + + ";"); + count++; + } + // Set up the trigger_t struct's pointer to the reactions. + constructorCode.pr( + variable, + String.join( + "\n", + "self->_lf__" + varName + ".reactions = &self->_lf__" + varName + "_reactions[0];", + "self->_lf__" + varName + ".number_of_reactions = " + count + ";")); + + // If federated, set the physical_time_of_arrival + constructorCode.pr( + variable, + CExtensionUtils.surroundWithIfFederated( + "self->_lf__" + varName + ".physical_time_of_arrival = NEVER;")); } + if (variable instanceof Input) { + var rootType = CUtil.rootType(types.getTargetType((Input) variable)); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + // If the input type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; - public static String generateBuiltinTriggersTable(int reactionCount, String name) { - return String.join("\n", List.of( - "// Array of pointers to "+name+" triggers.", - (reactionCount > 0 ? - "reaction_t* _lf_"+name+"_reactions["+reactionCount+"]" : - "reaction_t** _lf_"+name+"_reactions = NULL") + ";", - "int _lf_"+name+"_reactions_size = "+reactionCount+";" - )); + constructorCode.pr("self->_lf__" + varName + ".tmplt.type.element_size = " + size + ";"); + body.pr( + CExtensionUtils.surroundWithIfFederated( + CExtensionUtils.createPortStatusFieldForInput((Input) variable))); } + } - /** - * Generate the _lf_trigger_startup_reactions function. - */ - public static String generateLfTriggerStartupReactions(int startupReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("void _lf_trigger_startup_reactions() {"); - if (startupReactionCount > 0) { - s.append("\n"); - if (hasModalReactors) { - s.append(String.join("\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " if (_lf_startup_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_startup_reset_reactions(", - " _lf_startup_reactions, _lf_startup_reactions_size,", - " NULL, 0,", - " _lf_modal_reactor_states, _lf_modal_reactor_states_size);" - )); - } else { - s.append(String.join("\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }" - )); - } - s.append("\n"); - } - s.append("}\n"); - return s.toString(); + public static void generateBuiltinTriggeredReactionsArray( + Set reactions, String name, CodeBuilder body, CodeBuilder constructorCode) { + body.pr( + String.join( + "\n", + "trigger_t _lf__" + name + ";", + "reaction_t* _lf__" + name + "_reactions[" + reactions.size() + "];")); + constructorCode.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + name + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + var i = 0; + for (Integer reactionIndex : reactions) { + constructorCode.pr( + "self->_lf__" + + name + + "_reactions[" + + i++ + + "] = &self->_lf__reaction_" + + reactionIndex + + ";"); } + constructorCode.pr( + String.join( + "\n", + "self->_lf__" + name + ".last = NULL;", + "self->_lf__" + name + ".reactions = &self->_lf__" + name + "_reactions[0];", + "self->_lf__" + name + ".number_of_reactions = " + reactions.size() + ";", + "self->_lf__" + name + ".is_timer = false;")); + } - /** - * Generate the _lf_trigger_shutdown_reactions function. - */ - public static String generateLfTriggerShutdownReactions(int shutdownReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("bool _lf_trigger_shutdown_reactions() {\n"); - if (shutdownReactionCount > 0) { - if (hasModalReactors) { - s.append(String.join("\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " if (_lf_shutdown_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions, _lf_shutdown_reactions_size);", - " return true;" - )); - } else { - s.append(String.join("\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " return true;" - )); - } - s.append("\n"); - } else { - s.append(" return false;\n"); - } - s.append("}\n"); - return s.toString(); + public static String generateBuiltinTriggersTable(int reactionCount, String name) { + return String.join( + "\n", + List.of( + "// Array of pointers to " + name + " triggers.", + (reactionCount > 0 + ? "reaction_t* _lf_" + name + "_reactions[" + reactionCount + "]" + : "reaction_t** _lf_" + name + "_reactions = NULL") + + ";", + "int _lf_" + name + "_reactions_size = " + reactionCount + ";")); + } + + /** Generate the _lf_trigger_startup_reactions function. */ + public static String generateLfTriggerStartupReactions( + int startupReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("void _lf_trigger_startup_reactions() {"); + if (startupReactionCount > 0) { + s.append("\n"); + if (hasModalReactors) { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " if (_lf_startup_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_startup_reset_reactions(", + " _lf_startup_reactions, _lf_startup_reactions_size,", + " NULL, 0,", + " _lf_modal_reactor_states, _lf_modal_reactor_states_size);")); + } else { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }")); + } + s.append("\n"); } + s.append("}\n"); + return s.toString(); + } - /** - * Generate the _lf_handle_mode_triggered_reactions function. - */ - public static String generateLfModeTriggeredReactions( - int startupReactionCount, - int resetReactionCount, - boolean hasModalReactors - ) { - if (!hasModalReactors) { - return ""; - } - var s = new StringBuilder(); - s.append("void _lf_handle_mode_triggered_reactions() {\n"); - s.append(" _lf_handle_mode_startup_reset_reactions(\n"); - if (startupReactionCount > 0) { - s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - if (resetReactionCount > 0) { - s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); - s.append("}\n"); - return s.toString(); + /** Generate the _lf_trigger_shutdown_reactions function. */ + public static String generateLfTriggerShutdownReactions( + int shutdownReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("bool _lf_trigger_shutdown_reactions() {\n"); + if (shutdownReactionCount > 0) { + if (hasModalReactors) { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " if (_lf_shutdown_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions," + + " _lf_shutdown_reactions_size);", + " return true;")); + } else { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " return true;")); + } + s.append("\n"); + } else { + s.append(" return false;\n"); } + s.append("}\n"); + return s.toString(); + } - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - public static String generateReaction( - Reaction reaction, - Reactor r, - int reactionIndex, - Instantiation mainDef, - ErrorReporter errorReporter, - CTypes types, - TargetConfig targetConfig, - boolean requiresType - ) { - var code = new CodeBuilder(); - var body = ASTUtils.toText(getCode(types, reaction, r)); - String init = generateInitializationForReaction( - body, reaction, ASTUtils.toDefinition(r), reactionIndex, - types, errorReporter, mainDef, - requiresType); + /** Generate the _lf_handle_mode_triggered_reactions function. */ + public static String generateLfModeTriggeredReactions( + int startupReactionCount, int resetReactionCount, boolean hasModalReactors) { + if (!hasModalReactors) { + return ""; + } + var s = new StringBuilder(); + s.append("void _lf_handle_mode_triggered_reactions() {\n"); + s.append(" _lf_handle_mode_startup_reset_reactions(\n"); + if (startupReactionCount > 0) { + s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); + } + if (resetReactionCount > 0) { + s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); + } + s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); + s.append("}\n"); + return s.toString(); + } - code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetHeader())); + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + public static String generateReaction( + Reaction reaction, + Reactor r, + int reactionIndex, + Instantiation mainDef, + ErrorReporter errorReporter, + CTypes types, + TargetConfig targetConfig, + boolean requiresType) { + var code = new CodeBuilder(); + var body = ASTUtils.toText(getCode(types, reaction, r)); + String init = + generateInitializationForReaction( + body, + reaction, + ASTUtils.toDefinition(r), + reactionIndex, + types, + errorReporter, + mainDef, + requiresType); - CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(r), code); - code.pr(generateFunction( - generateReactionFunctionHeader(r, reactionIndex), - init, getCode(types, reaction, r) - )); - // Now generate code for the late function, if there is one - // Note that this function can only be defined on reactions - // in federates that have inputs from a logical connection. - if (reaction.getStp() != null) { - code.pr(generateFunction( - generateStpFunctionHeader(r, reactionIndex), - init, reaction.getStp().getCode())); - } + code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetHeader())); - // Now generate code for the deadline violation function, if there is one. - if (reaction.getDeadline() != null) { - code.pr(generateFunction( - generateDeadlineFunctionHeader(r, reactionIndex), - init, reaction.getDeadline().getCode())); - } - CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(r), code); - code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetUndefHeader())); - return code.toString(); + CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(r), code); + code.pr( + generateFunction( + generateReactionFunctionHeader(r, reactionIndex), init, getCode(types, reaction, r))); + // Now generate code for the late function, if there is one + // Note that this function can only be defined on reactions + // in federates that have inputs from a logical connection. + if (reaction.getStp() != null) { + code.pr( + generateFunction( + generateStpFunctionHeader(r, reactionIndex), init, reaction.getStp().getCode())); } - private static Code getCode(CTypes types, Reaction r, ReactorDecl container) { - if (r.getCode() != null) return r.getCode(); - Code ret = LfFactory.eINSTANCE.createCode(); - var reactor = ASTUtils.toDefinition(container); - ret.setBody( - CReactorHeaderFileGenerator.nonInlineInitialization(r, reactor) + "\n" - + r.getName() + "( " + CReactorHeaderFileGenerator.reactionArguments(r, reactor) + " );"); - return ret; + // Now generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr( + generateFunction( + generateDeadlineFunctionHeader(r, reactionIndex), + init, + reaction.getDeadline().getCode())); } + CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(r), code); + code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetUndefHeader())); + return code.toString(); + } - public static String generateFunction(String header, String init, Code code) { - var function = new CodeBuilder(); - function.pr(header + " {"); - function.indent(); - function.pr(init); - function.prSourceLineNumber(code); - function.pr(ASTUtils.toText(code)); - function.unindent(); - function.pr("}"); - return function.toString(); - } + private static Code getCode(CTypes types, Reaction r, ReactorDecl container) { + if (r.getCode() != null) return r.getCode(); + Code ret = LfFactory.eINSTANCE.createCode(); + var reactor = ASTUtils.toDefinition(container); + ret.setBody( + CReactorHeaderFileGenerator.nonInlineInitialization(r, reactor) + + "\n" + + r.getName() + + "( " + + CReactorHeaderFileGenerator.reactionArguments(r, reactor) + + " );"); + return ret; + } - /** - * Returns the name of the deadline function for reaction. - * @param r The reactor with the deadline - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateDeadlineFunctionName(Reactor r, int reactionIndex) { - return CUtil.getName(r).toLowerCase() + "_deadline_function" + reactionIndex; - } + public static String generateFunction(String header, String init, Code code) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(code); + function.pr(ASTUtils.toText(code)); + function.unindent(); + function.pr("}"); + return function.toString(); + } - /** - * Return the function name for specified reaction of the - * specified reactor. - * @param reactor The reactor - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionName(Reactor reactor, int reactionIndex) { - return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; - } + /** + * Returns the name of the deadline function for reaction. + * + * @param r The reactor with the deadline + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateDeadlineFunctionName(Reactor r, int reactionIndex) { + return CUtil.getName(r).toLowerCase() + "_deadline_function" + reactionIndex; + } - /** - * Returns the name of the stp function for reaction. - * @param r The reactor with the stp - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateStpFunctionName(Reactor r, int reactionIndex) { - return CUtil.getName(r).toLowerCase() + "_STP_function" + reactionIndex; - } + /** + * Return the function name for specified reaction of the specified reactor. + * + * @param reactor The reactor + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionName(Reactor reactor, int reactionIndex) { + return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; + } - /** Return the top level C function header for the deadline function numbered "reactionIndex" in "r" - * @param r The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the deadline function. - */ - public static String generateDeadlineFunctionHeader(Reactor r, - int reactionIndex) { - String functionName = generateDeadlineFunctionName(r, reactionIndex); - return generateFunctionHeader(functionName); - } + /** + * Returns the name of the stp function for reaction. + * + * @param r The reactor with the stp + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateStpFunctionName(Reactor r, int reactionIndex) { + return CUtil.getName(r).toLowerCase() + "_STP_function" + reactionIndex; + } - /** Return the top level C function header for the reaction numbered "reactionIndex" in "r" - * @param r The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionHeader(Reactor r, - int reactionIndex) { - String functionName = generateReactionFunctionName(r, reactionIndex); - return generateFunctionHeader(functionName); - } + /** + * Return the top level C function header for the deadline function numbered "reactionIndex" in + * "r" + * + * @param r The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the deadline function. + */ + public static String generateDeadlineFunctionHeader(Reactor r, int reactionIndex) { + String functionName = generateDeadlineFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } - public static String generateStpFunctionHeader(Reactor r, - int reactionIndex) { - String functionName = generateStpFunctionName(r, reactionIndex); - return generateFunctionHeader(functionName); - } + /** + * Return the top level C function header for the reaction numbered "reactionIndex" in "r" + * + * @param r The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionHeader(Reactor r, int reactionIndex) { + String functionName = generateReactionFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } - public static String generateFunctionHeader(String functionName) { - return "void " + functionName + "(void* instance_args)"; - } -} \ No newline at end of file + public static String generateStpFunctionHeader(Reactor r, int reactionIndex) { + String functionName = generateStpFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } + + public static String generateFunctionHeader(String functionName) { + return "void " + functionName + "(void* instance_args)"; + } +} diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 621077de86..5a6f1dc3ba 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -1,7 +1,6 @@ package org.lflang.generator.c; import java.util.List; - import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Mode; diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 2cf96e0d68..f1f0e9b59d 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -34,18 +34,14 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; - import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.generator.CodeBuilder; import org.lflang.generator.CodeMap; - import org.lflang.generator.GeneratorResult; import org.lflang.generator.IntegratedBuilder; import org.lflang.generator.LFGeneratorContext; @@ -56,7 +52,6 @@ import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; -import org.lflang.lf.Code; import org.lflang.lf.Input; import org.lflang.lf.Model; import org.lflang.lf.Output; @@ -68,525 +63,505 @@ import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; - /** - * Generator for Python target. This class generates Python code defining each - * reactor - * class given in the input .lf file and imported .lf files. + * Generator for Python target. This class generates Python code defining each reactor class given + * in the input .lf file and imported .lf files. * - * Each class will contain all the reaction functions defined by the user in - * order, with the necessary ports/actions given as parameters. - * Moreover, each class will contain all state variables in native Python - * format. + *

Each class will contain all the reaction functions defined by the user in order, with the + * necessary ports/actions given as parameters. Moreover, each class will contain all state + * variables in native Python format. * - * A backend is also generated using the CGenerator that interacts with the C - * code library (see CGenerator.xtend). - * The backend is responsible for passing arguments to the Python reactor + *

A backend is also generated using the CGenerator that interacts with the C code library (see + * CGenerator.xtend). The backend is responsible for passing arguments to the Python reactor * functions. * * @author Soroush Bateni */ public class PythonGenerator extends CGenerator { - // Used to add statements that come before reactor classes and user code - private final CodeBuilder pythonPreamble = new CodeBuilder(); - - // Used to add module requirements to setup.py (delimited with ,) - private final List pythonRequiredModules = new ArrayList<>(); - - private final PythonTypes types; - - public PythonGenerator(LFGeneratorContext context) { - this(context, - new PythonTypes(), - new CCmakeGenerator( - context.getFileConfig(), - List.of("lib/python_action.c", - "lib/python_port.c", - "lib/python_tag.c", - "lib/python_time.c", - "lib/pythontarget.c" - ), - PythonGenerator::setUpMainTarget, - "install(TARGETS)" // No-op - ) - ); - } - - - private PythonGenerator(LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { - super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); - this.targetConfig.compiler = "gcc"; - this.targetConfig.compilerFlags = new ArrayList<>(); - this.targetConfig.linkerFlags = ""; - this.types = types; - } - - /** - * Generic struct for ports with primitive types and - * statically allocated arrays in Lingua Franca. - * This template is defined as - * typedef struct { - * bool is_present; - * lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record. - * int destination_channel; // -1 if there is no destination. - * PyObject* value; - * int num_destinations; - * lf_token_t* token; - * int length; - * void (*destructor) (void* value); - * void* (*copy_constructor) (void* value); - * FEDERATED_GENERIC_EXTENSION - * } generic_port_instance_struct; - * - * See reactor-c-py/lib/pythontarget.h for details. - */ - String genericPortType = "generic_port_instance_struct"; - - /** - * Generic struct for actions. - * This template is defined as - * typedef struct { - * trigger_t* trigger; - * PyObject* value; - * bool is_present; - * bool has_value; - * lf_token_t* token; - * FEDERATED_CAPSULE_EXTENSION - * } generic_action_instance_struct; - * - * See reactor-c-py/lib/pythontarget.h for details. - */ - String genericActionType = "generic_action_instance_struct"; - - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.Python; + // Used to add statements that come before reactor classes and user code + private final CodeBuilder pythonPreamble = new CodeBuilder(); + + // Used to add module requirements to setup.py (delimited with ,) + private final List pythonRequiredModules = new ArrayList<>(); + + private final PythonTypes types; + + public PythonGenerator(LFGeneratorContext context) { + this( + context, + new PythonTypes(), + new CCmakeGenerator( + context.getFileConfig(), + List.of( + "lib/python_action.c", + "lib/python_port.c", + "lib/python_tag.c", + "lib/python_time.c", + "lib/pythontarget.c"), + PythonGenerator::setUpMainTarget, + "install(TARGETS)" // No-op + )); + } + + private PythonGenerator( + LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { + super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); + this.targetConfig.compiler = "gcc"; + this.targetConfig.compilerFlags = new ArrayList<>(); + this.targetConfig.linkerFlags = ""; + this.types = types; + } + + /** + * Generic struct for ports with primitive types and statically allocated arrays in Lingua Franca. + * This template is defined as typedef struct { bool is_present; lf_sparse_io_record_t* + * sparse_record; // NULL if there is no sparse record. int destination_channel; // -1 if there is + * no destination. PyObject* value; int num_destinations; lf_token_t* token; int length; void + * (*destructor) (void* value); void* (*copy_constructor) (void* value); + * FEDERATED_GENERIC_EXTENSION } generic_port_instance_struct; + * + *

See reactor-c-py/lib/pythontarget.h for details. + */ + String genericPortType = "generic_port_instance_struct"; + + /** + * Generic struct for actions. This template is defined as typedef struct { trigger_t* trigger; + * PyObject* value; bool is_present; bool has_value; lf_token_t* token; + * FEDERATED_CAPSULE_EXTENSION } generic_action_instance_struct; + * + *

See reactor-c-py/lib/pythontarget.h for details. + */ + String genericActionType = "generic_action_instance_struct"; + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.Python; + } + + private final Set protoNames = new HashSet<>(); + + // ////////////////////////////////////////// + // // Public methods + @Override + public TargetTypes getTargetTypes() { + return types; + } + + // ////////////////////////////////////////// + // // Protected methods + + /** Generate all Python classes if they have a reaction */ + public String generatePythonReactorClasses() { + CodeBuilder pythonClasses = new CodeBuilder(); + CodeBuilder pythonClassesInstantiation = new CodeBuilder(); + + // Generate reactor classes in Python + pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); + + // Create empty lists to hold reactor instances + pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); + + // Instantiate generated classes + pythonClassesInstantiation.pr( + PythonReactorGenerator.generatePythonClassInstantiations(main, main)); + + return String.join( + "\n", + pythonClasses.toString(), + "", + "# Instantiate classes", + pythonClassesInstantiation.toString()); + } + + /** + * Generate the Python code constructed from reactor classes and user-written classes. + * + * @return the code body + */ + public String generatePythonCode(String pyModuleName) { + return String.join( + "\n", + "import os", + "import sys", + "sys.path.append(os.path.dirname(__file__))", + "# List imported names, but do not use pylint's --extension-pkg-allow-list option", + "# so that these names will be assumed present without having to compile and install.", + "# pylint: disable=no-name-in-module, import-error", + "from " + pyModuleName + " import (", + " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", + ")", + "# pylint: disable=c-extension-no-member", + "import " + pyModuleName + " as lf", + "try:", + " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", + " from LinguaFrancaBase.functions import (", + " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS," + + " USEC,", + " USECS, WEEK, WEEKS", + " )", + " from LinguaFrancaBase.classes import Make", + "except ModuleNotFoundError:", + " print(\"No module named 'LinguaFrancaBase'. \"", + " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", + " sys.exit(1)", + "import copy", + "", + pythonPreamble.toString(), + "", + generatePythonReactorClasses(), + "", + PythonMainFunctionGenerator.generateCode()); + } + + /** Generate the necessary Python files. */ + public Map generatePythonFiles( + String lfModuleName, String pyModuleName, String pyFileName) throws IOException { + Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); + File file = filePath.toFile(); + Files.deleteIfExists(filePath); + // Create the necessary directories + if (!file.getParentFile().exists()) { + if (!file.getParentFile().mkdirs()) { + throw new IOException( + "Failed to create directories required for the Python code generator."); + } } - - private final Set protoNames = new HashSet<>(); - - // ////////////////////////////////////////// - // // Public methods - @Override - public TargetTypes getTargetTypes() { - return types; - } - - // ////////////////////////////////////////// - // // Protected methods - - /** - * Generate all Python classes if they have a reaction - * - */ - public String generatePythonReactorClasses() { - CodeBuilder pythonClasses = new CodeBuilder(); - CodeBuilder pythonClassesInstantiation = new CodeBuilder(); - - // Generate reactor classes in Python - pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); - - // Create empty lists to hold reactor instances - pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); - - // Instantiate generated classes - pythonClassesInstantiation.pr(PythonReactorGenerator.generatePythonClassInstantiations(main, main)); - - return String.join("\n", - pythonClasses.toString(), - "", - "# Instantiate classes", - pythonClassesInstantiation.toString() - ); - } - - /** - * Generate the Python code constructed from reactor classes and - * user-written classes. - * - * @return the code body - */ - public String generatePythonCode(String pyModuleName) { - return String.join("\n", - "import os", - "import sys", - "sys.path.append(os.path.dirname(__file__))", - "# List imported names, but do not use pylint's --extension-pkg-allow-list option", - "# so that these names will be assumed present without having to compile and install.", - "# pylint: disable=no-name-in-module, import-error", - "from "+pyModuleName+" import (", - " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", - ")", - "# pylint: disable=c-extension-no-member", - "import "+pyModuleName+" as lf", - "try:", - " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", - " from LinguaFrancaBase.functions import (", - " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS, USEC,", - " USECS, WEEK, WEEKS", - " )", - " from LinguaFrancaBase.classes import Make", - "except ModuleNotFoundError:", - " print(\"No module named 'LinguaFrancaBase'. \"", - " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", - " sys.exit(1)", - "import copy", - "", - pythonPreamble.toString(), - "", - generatePythonReactorClasses(), - "", - PythonMainFunctionGenerator.generateCode() - ); - } - - /** - * Generate the necessary Python files. - */ - public Map generatePythonFiles( - String lfModuleName, - String pyModuleName, - String pyFileName - ) throws IOException { - Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); - File file = filePath.toFile(); - Files.deleteIfExists(filePath); - // Create the necessary directories - if (!file.getParentFile().exists()) { - if (!file.getParentFile().mkdirs()) { - throw new IOException( - "Failed to create directories required for the Python code generator." - ); - } - } - Map codeMaps = new HashMap<>(); - codeMaps.put(filePath, CodeMap.fromGeneratedCode( - generatePythonCode(pyModuleName))); - FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); - return codeMaps; - } - - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - @Override - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(PythonPreambleGenerator.generateCDefineDirectives( + Map codeMaps = new HashMap<>(); + codeMaps.put(filePath, CodeMap.fromGeneratedCode(generatePythonCode(pyModuleName))); + FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); + return codeMaps; + } + + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + @Override + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + PythonPreambleGenerator.generateCDefineDirectives( targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); - return code.toString(); - } - - /** - * Override generate top-level preambles, but put the user preambles in the - * .py file rather than the C file. Also handles including the federated - * execution setup preamble specified in the target config. - */ - @Override - protected String generateTopLevelPreambles(Reactor ignored) { - // user preambles - Set models = new LinkedHashSet<>(); - for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { - // The following assumes all reactors have a container. - // This means that generated reactors **have** to be - // added to a resource; not doing so will result in a NPE. - models.add((Model) ASTUtils.toDefinition(r).eContainer()); - } - // Add the main reactor if it is defined - if (this.mainDef != null) { - models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); - } - for (Model m : models) { - pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); - } - return PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors); + return code.toString(); + } + + /** + * Override generate top-level preambles, but put the user preambles in the .py file rather than + * the C file. Also handles including the federated execution setup preamble specified in the + * target config. + */ + @Override + protected String generateTopLevelPreambles(Reactor ignored) { + // user preambles + Set models = new LinkedHashSet<>(); + for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { + // The following assumes all reactors have a container. + // This means that generated reactors **have** to be + // added to a resource; not doing so will result in a NPE. + models.add((Model) ASTUtils.toDefinition(r).eContainer()); } - - @Override - protected void handleProtoFiles() { - for (String name : targetConfig.protoFiles) { - this.processProtoFile(name); - int dotIndex = name.lastIndexOf("."); - String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; - pythonPreamble.pr("import "+rootFilename+"_pb2 as "+rootFilename); - protoNames.add(rootFilename); - } + // Add the main reactor if it is defined + if (this.mainDef != null) { + models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); } - - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * - * @param filename Name of the file to process. - */ - @Override - public void processProtoFile(String filename) { - LFCommand protoc = commandFactory.createCommand( - "protoc", List.of("--python_out=" - + fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); - return; - } - int returnCode = protoc.run(); - if (returnCode == 0) { - pythonRequiredModules.add("google-api-python-client"); - } else { - errorReporter.reportError( - "protoc returns error code " + returnCode); - } + for (Model m : models) { + pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); } - - /** - * Generate the aliases for inputs, outputs, and struct type definitions for - * actions of the specified reactor in the specified federate. - * @param r The parsed reactor data structure. - */ - @Override - public void generateAuxiliaryStructs( - CodeBuilder builder, Reactor r, boolean userFacing - ) { - for (Input input : ASTUtils.allInputs(r)) { - generateAuxiliaryStructsForPort(builder, r, input); - } - for (Output output : ASTUtils.allOutputs(r)) { - generateAuxiliaryStructsForPort(builder, r, output); - } - for (Action action : ASTUtils.allActions(r)) { - generateAuxiliaryStructsForAction(builder, r, action); - } + return PythonPreambleGenerator.generateCIncludeStatements( + targetConfig, targetLanguageIsCpp(), hasModalReactors); + } + + @Override + protected void handleProtoFiles() { + for (String name : targetConfig.protoFiles) { + this.processProtoFile(name); + int dotIndex = name.lastIndexOf("."); + String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; + pythonPreamble.pr("import " + rootFilename + "_pb2 as " + rootFilename); + protoNames.add(rootFilename); } - - private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, - Port port) { - boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); - builder.pr(port, - PythonPortGenerator.generateAliasTypeDef(r, port, isTokenType, - genericPortType)); + } + + /** + * Process a given .proto file. + * + *

Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + @Override + public void processProtoFile(String filename) { + LFCommand protoc = + commandFactory.createCommand( + "protoc", + List.of("--python_out=" + fileConfig.getSrcGenPath(), filename), + fileConfig.srcPath); + + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); + return; } - - private void generateAuxiliaryStructsForAction(CodeBuilder builder, Reactor r, - Action action) { - builder.pr(action, PythonActionGenerator.generateAliasTypeDef(r, action, genericActionType)); + int returnCode = protoc.run(); + if (returnCode == 0) { + pythonRequiredModules.add("google-api-python-client"); + } else { + errorReporter.reportError("protoc returns error code " + returnCode); } - - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - @Override - public boolean isOSCompatible() { - return true; + } + + /** + * Generate the aliases for inputs, outputs, and struct type definitions for actions of the + * specified reactor in the specified federate. + * + * @param r The parsed reactor data structure. + */ + @Override + public void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { + for (Input input : ASTUtils.allInputs(r)) { + generateAuxiliaryStructsForPort(builder, r, input); } - - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - // Set the threading to false by default, unless the user has - // specifically asked for it. - if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = false; - } - int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; - code.pr(PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors)); - super.doGenerate(resource, new SubContext( - context, - IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, - cGeneratedPercentProgress - )); - - if (errorsOccurred()) { - context.unsuccessfulFinish(); - return; - } - - Map codeMaps = new HashMap<>(); - var lfModuleName = fileConfig.name; - // Don't generate code if there is no main reactor - if (this.main != null) { - try { - Map codeMapsForFederate = generatePythonFiles(lfModuleName, generatePythonModuleName(lfModuleName), generatePythonFileName(lfModuleName)); - codeMaps.putAll(codeMapsForFederate); - copyTargetFiles(); - new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); - if (targetConfig.noCompile) { - System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); - } - } catch (Exception e) { - //noinspection ConstantConditions - throw Exceptions.sneakyThrow(e); - } - - System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); - } - - if (errorReporter.getErrorsOccurred()) { - context.unsuccessfulFinish(); - } else { - context.finish(GeneratorResult.Status.COMPILED, codeMaps); - } + for (Output output : ASTUtils.allOutputs(r)) { + generateAuxiliaryStructsForPort(builder, r, output); } - - @Override - protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new PythonDockerGenerator(context); + for (Action action : ASTUtils.allActions(r)) { + generateAuxiliaryStructsForAction(builder, r, action); } - - /** Generate a reaction function definition for a reactor. - * This function has a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - @Override - protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { - Reactor reactor = ASTUtils.toDefinition(r); - - // Reactions marked with a `@_c_body` attribute are generated in C - if (AttributeUtils.hasCBody(reaction)) { - super.generateReaction(src, reaction, r, reactionIndex); - return; - } - src.pr(PythonReactionGenerator.generateCReaction(reaction, reactor, reactionIndex, mainDef, errorReporter, types)); + } + + private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, Port port) { + boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); + builder.pr( + port, PythonPortGenerator.generateAliasTypeDef(r, port, isTokenType, genericPortType)); + } + + private void generateAuxiliaryStructsForAction(CodeBuilder builder, Reactor r, Action action) { + builder.pr(action, PythonActionGenerator.generateAliasTypeDef(r, action, genericActionType)); + } + + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + @Override + public boolean isOSCompatible() { + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + // Set the threading to false by default, unless the user has + // specifically asked for it. + if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = false; } - - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all - * instances - * of the same reactor. This task is left to Python code to allow for more - * liberal - * state variable assignments. - * - * @param instance The reactor class instance - * @return Initialization code fore state variables of instance - */ - @Override - protected void generateStateVariableInitializations(ReactorInstance instance) { - // Do nothing + int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; + code.pr( + PythonPreambleGenerator.generateCIncludeStatements( + targetConfig, targetLanguageIsCpp(), hasModalReactors)); + super.doGenerate( + resource, + new SubContext( + context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, cGeneratedPercentProgress)); + + if (errorsOccurred()) { + context.unsuccessfulFinish(); + return; } - /** - * Generate runtime initialization code in C for parameters of a given - * reactor instance - * - * @param instance The reactor instance. - */ - @Override - protected void generateParameterInitialization(ReactorInstance instance) { - // Do nothing - // Parameters are initialized in Python - } + Map codeMaps = new HashMap<>(); + var lfModuleName = fileConfig.name; + // Don't generate code if there is no main reactor + if (this.main != null) { + try { + Map codeMapsForFederate = + generatePythonFiles( + lfModuleName, + generatePythonModuleName(lfModuleName), + generatePythonFileName(lfModuleName)); + codeMaps.putAll(codeMapsForFederate); + copyTargetFiles(); + new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); + if (targetConfig.noCompile) { + System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); + } + } catch (Exception e) { + //noinspection ConstantConditions + throw Exceptions.sneakyThrow(e); + } - /** - * Do nothing. - * Methods are generated in Python not C. - * @see PythonMethodGenerator - */ - @Override - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { } - - /** - * Generate C preambles defined by user for a given reactor - * Since the Python generator expects preambles written in C, - * this function is overridden and does nothing. - * - * @param reactor The given reactor - */ - @Override - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - // Do nothing + System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); } - /** - * Generate code that is executed while the reactor instance is being - * initialized. - * This wraps the reaction functions in a Python function. - * @param instance The reactor instance. - */ - @Override - protected void generateReactorInstanceExtension( - ReactorInstance instance - ) { - initializeTriggerObjects.pr(PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); + if (errorReporter.getErrorsOccurred()) { + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, codeMaps); } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param selfStructBody The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - @Override - protected void generateSelfStructExtension( - CodeBuilder selfStructBody, - ReactorDecl decl, - CodeBuilder constructorCode - ) { - Reactor reactor = ASTUtils.toDefinition(decl); - // Add the name field - selfStructBody.pr("char *_lf_name;"); - int reactionIndex = 0; - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create a PyObject for each reaction - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex)+";"); - if (reaction.getStp() != null) { - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex)+";"); - } - if (reaction.getDeadline() != null) { - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex)+";"); - } - reactionIndex++; - } + } + + @Override + protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new PythonDockerGenerator(context); + } + + /** + * Generate a reaction function definition for a reactor. This function has a single argument that + * is a void* pointing to a struct that contains parameters, state variables, inputs (triggering + * or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + @Override + protected void generateReaction( + CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + Reactor reactor = ASTUtils.toDefinition(r); + + // Reactions marked with a `@_c_body` attribute are generated in C + if (AttributeUtils.hasCBody(reaction)) { + super.generateReaction(src, reaction, r, reactionIndex); + return; } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - // NOTE: Strangely, a newline is needed at the beginning or indentation - // gets swallowed. - return String.join("\n", - "\n# Generated forwarding reaction for connections with the same destination", - "# but located in mutually exclusive modes.", - dest + ".set(" + source + ".value)\n" - ); + src.pr( + PythonReactionGenerator.generateCReaction( + reaction, reactor, reactionIndex, mainDef, errorReporter, types)); + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. This task is + * left to Python code to allow for more liberal state variable assignments. + * + * @param instance The reactor class instance + * @return Initialization code fore state variables of instance + */ + @Override + protected void generateStateVariableInitializations(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate runtime initialization code in C for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + @Override + protected void generateParameterInitialization(ReactorInstance instance) { + // Do nothing + // Parameters are initialized in Python + } + + /** + * Do nothing. Methods are generated in Python not C. + * + * @see PythonMethodGenerator + */ + @Override + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) {} + + /** + * Generate C preambles defined by user for a given reactor Since the Python generator expects + * preambles written in C, this function is overridden and does nothing. + * + * @param reactor The given reactor + */ + @Override + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + // Do nothing + } + + /** + * Generate code that is executed while the reactor instance is being initialized. This wraps the + * reaction functions in a Python function. + * + * @param instance The reactor instance. + */ + @Override + protected void generateReactorInstanceExtension(ReactorInstance instance) { + initializeTriggerObjects.pr( + PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param selfStructBody The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + @Override + protected void generateSelfStructExtension( + CodeBuilder selfStructBody, ReactorDecl decl, CodeBuilder constructorCode) { + Reactor reactor = ASTUtils.toDefinition(decl); + // Add the name field + selfStructBody.pr("char *_lf_name;"); + int reactionIndex = 0; + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create a PyObject for each reaction + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex) + + ";"); + if (reaction.getStp() != null) { + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex) + + ";"); + } + if (reaction.getDeadline() != null) { + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex) + + ";"); + } + reactionIndex++; } - - @Override - protected void setUpGeneralParameters() { - super.setUpGeneralParameters(); - if (hasModalReactors) { - targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); - } + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + // NOTE: Strangely, a newline is needed at the beginning or indentation + // gets swallowed. + return String.join( + "\n", + "\n# Generated forwarding reaction for connections with the same destination", + "# but located in mutually exclusive modes.", + dest + ".set(" + source + ".value)\n"); + } + + @Override + protected void setUpGeneralParameters() { + super.setUpGeneralParameters(); + if (hasModalReactors) { + targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); } + } - @Override - protected void additionalPostProcessingForModes() { - if (!hasModalReactors) { - return; - } - PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + @Override + protected void additionalPostProcessingForModes() { + if (!hasModalReactors) { + return; } + PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + } - private static String setUpMainTarget(boolean hasMain, String executableName, Stream cSources) { - return ( - """ + private static String setUpMainTarget( + boolean hasMain, String executableName, Stream cSources) { + return (""" set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(_LF_GARBAGE_COLLECTED) add_subdirectory(core) @@ -611,71 +586,61 @@ private static String setUpMainTarget(boolean hasMain, String executableName, St 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)) - .replace("executableName", executableName); - // The use of fileConfig.name will break federated execution, but that's fine - } - - /** - * Generate a (`key`, `val`) tuple pair for the `define_macros` field - * of the Extension class constructor from setuptools. - * - * @param key The key of the macro entry - * @param val The value of the macro entry - * @return A (`key`, `val`) tuple pair as String - */ - private static String generateMacroEntry(String key, String val) { - return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; - } - - /** - * Generate the name of the python module. - * - * Ideally, this function would belong in a class like `PyFileConfig` - * that specifies all the paths to the generated code. - * - * @param lfModuleName The name of the LF module. - * @return The name of the python module. - */ - private static String generatePythonModuleName(String lfModuleName) { - return "LinguaFranca" + lfModuleName; - } - - /** - * Generate the python file name given an `lfModuleName`. - * - * Ideally, this function would belong in a class like `PyFileConfig` - * that specifies all the paths to the generated code. - * - * @param lfModuleName The name of the LF module - * @return The name of the generated python file. - */ - private static String generatePythonFileName(String lfModuleName) { - return lfModuleName + ".py"; - } - - /** - * Copy Python specific target code to the src-gen directory - */ - @Override - protected void copyTargetFiles() throws IOException { - super.copyTargetFiles(); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/include", - fileConfig.getSrcGenPath().resolve("include"), - true - ); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/lib", - fileConfig.getSrcGenPath().resolve("lib"), - true - ); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/LinguaFrancaBase", - fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), - true - ); - } - -} \ No newline at end of file + """) + .replace("", generatePythonModuleName(executableName)) + .replace("executableName", executableName); + // The use of fileConfig.name will break federated execution, but that's fine + } + + /** + * Generate a (`key`, `val`) tuple pair for the `define_macros` field of the Extension class + * constructor from setuptools. + * + * @param key The key of the macro entry + * @param val The value of the macro entry + * @return A (`key`, `val`) tuple pair as String + */ + private static String generateMacroEntry(String key, String val) { + return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; + } + + /** + * Generate the name of the python module. + * + *

Ideally, this function would belong in a class like `PyFileConfig` that specifies all the + * paths to the generated code. + * + * @param lfModuleName The name of the LF module. + * @return The name of the python module. + */ + private static String generatePythonModuleName(String lfModuleName) { + return "LinguaFranca" + lfModuleName; + } + + /** + * Generate the python file name given an `lfModuleName`. + * + *

Ideally, this function would belong in a class like `PyFileConfig` that specifies all the + * paths to the generated code. + * + * @param lfModuleName The name of the LF module + * @return The name of the generated python file. + */ + private static String generatePythonFileName(String lfModuleName) { + return lfModuleName + ".py"; + } + + /** Copy Python specific target code to the src-gen directory */ + @Override + protected void copyTargetFiles() throws IOException { + super.copyTargetFiles(); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/include", fileConfig.getSrcGenPath().resolve("include"), true); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/lib", fileConfig.getSrcGenPath().resolve("lib"), true); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/LinguaFrancaBase", + fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), + true); + } +} diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 99e0a5bab4..b0555dc4e0 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1,6 +1,3 @@ - - - /* Validation checks for Lingua Franca code. */ /************* @@ -27,12 +24,10 @@ import static org.lflang.ASTUtils.inferPortWidth; import static org.lflang.ASTUtils.isGeneric; -import static org.lflang.ASTUtils.isInteger; -import static org.lflang.ASTUtils.isOfTimeType; -import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; import static org.lflang.ASTUtils.toOriginalText; +import com.google.inject.Inject; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -44,7 +39,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAttribute; @@ -71,7 +65,6 @@ import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; -import org.lflang.lf.CodeExpr; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; import org.lflang.lf.Expression; @@ -115,12 +108,10 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.FileUtil; -import com.google.inject.Inject; - /** * Custom validation checks for Lingua Franca programs. * - * Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation + *

Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation * * @author Edward A. Lee * @author Marten Lohstroh @@ -131,1750 +122,1832 @@ */ public class LFValidator extends BaseLFValidator { - ////////////////////////////////////////////////////////////// - //// Public check methods. - - // These methods are automatically invoked on AST nodes matching - // the types of their arguments. - // CheckType.FAST ensures that these checks run whenever a file is modified. - // Alternatives are CheckType.NORMAL (when saving) and - // CheckType.EXPENSIVE (only when right-click, validate). - // FIXME: What is the default when nothing is specified? - - // These methods are listed in alphabetical order, and, although - // it is isn't strictly required, follow a naming convention - // checkClass, where Class is the AST class, where possible. - - @Check(CheckType.FAST) - public void checkAction(Action action) { - checkName(action.getName(), Literals.VARIABLE__NAME); - if (action.getOrigin() == ActionOrigin.NONE) { - error( - "Action must have modifier `logical` or `physical`.", - Literals.ACTION__ORIGIN - ); - } - if (action.getPolicy() != null && - !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { - error( - "Unrecognized spacing violation policy: " + action.getPolicy() + - ". Available policies are: " + - String.join(", ", SPACING_VIOLATION_POLICIES) + ".", - Literals.ACTION__POLICY); - } - checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); - checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); + ////////////////////////////////////////////////////////////// + //// Public check methods. + + // These methods are automatically invoked on AST nodes matching + // the types of their arguments. + // CheckType.FAST ensures that these checks run whenever a file is modified. + // Alternatives are CheckType.NORMAL (when saving) and + // CheckType.EXPENSIVE (only when right-click, validate). + // FIXME: What is the default when nothing is specified? + + // These methods are listed in alphabetical order, and, although + // it is isn't strictly required, follow a naming convention + // checkClass, where Class is the AST class, where possible. + + @Check(CheckType.FAST) + public void checkAction(Action action) { + checkName(action.getName(), Literals.VARIABLE__NAME); + if (action.getOrigin() == ActionOrigin.NONE) { + error("Action must have modifier `logical` or `physical`.", Literals.ACTION__ORIGIN); } - - - @Check(CheckType.FAST) - public void checkInitializer(Initializer init) { - if (init.isBraces() && target != Target.CPP) { - error("Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); - } else if (init.isParens() && target.mandatesEqualsInitializers()) { - var message = "This syntax is deprecated in the " + target - + " target, use an equal sign instead of parentheses for assignment."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, Literals.INITIALIZER__PARENS); - } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { - var feature = init.isBraces() ? Literals.INITIALIZER__BRACES - : Literals.INITIALIZER__PARENS; - var message = "This syntax is deprecated, do not use parentheses or braces but an equal sign."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, feature); - } + if (action.getPolicy() != null && !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { + error( + "Unrecognized spacing violation policy: " + + action.getPolicy() + + ". Available policies are: " + + String.join(", ", SPACING_VIOLATION_POLICIES) + + ".", + Literals.ACTION__POLICY); } - - @Check(CheckType.FAST) - public void checkBracedExpression(BracedListExpression expr) { - if (!target.allowsBracedListExpressions()) { - var message = "Braced expression lists are not a valid expression for the " + target - + " target."; - error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); - } + checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); + checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); + } + + @Check(CheckType.FAST) + public void checkInitializer(Initializer init) { + if (init.isBraces() && target != Target.CPP) { + error( + "Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); + } else if (init.isParens() && target.mandatesEqualsInitializers()) { + var message = + "This syntax is deprecated in the " + + target + + " target, use an equal sign instead of parentheses for assignment."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, Literals.INITIALIZER__PARENS); + } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { + var feature = init.isBraces() ? Literals.INITIALIZER__BRACES : Literals.INITIALIZER__PARENS; + var message = + "This syntax is deprecated, do not use parentheses or braces but an equal sign."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, feature); } - - @Check(CheckType.FAST) - public void checkAssignment(Assignment assignment) { - - // If the left-hand side is a time parameter, make sure the assignment has units - typeCheck(assignment.getRhs(), ASTUtils.getInferredType(assignment.getLhs()), Literals.ASSIGNMENT__RHS); - // If this assignment overrides a parameter that is used in a deadline, - // report possible overflow. - if (isCBasedTarget() && - this.info.overflowingAssignments.contains(assignment)) { - error( - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.ASSIGNMENT__RHS); - } - + } + + @Check(CheckType.FAST) + public void checkBracedExpression(BracedListExpression expr) { + if (!target.allowsBracedListExpressions()) { + var message = + "Braced expression lists are not a valid expression for the " + target + " target."; + error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); } + } + + @Check(CheckType.FAST) + public void checkAssignment(Assignment assignment) { + + // If the left-hand side is a time parameter, make sure the assignment has units + typeCheck( + assignment.getRhs(), + ASTUtils.getInferredType(assignment.getLhs()), + Literals.ASSIGNMENT__RHS); + // If this assignment overrides a parameter that is used in a deadline, + // report possible overflow. + if (isCBasedTarget() && this.info.overflowingAssignments.contains(assignment)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds.", + Literals.ASSIGNMENT__RHS); + } + } - @Check(CheckType.FAST) - public void checkConnection(Connection connection) { - - // Report if connection is part of a cycle. - Set> cycles = this.info.topologyCycles(); - for (VarRef lp : connection.getLeftPorts()) { - for (VarRef rp : connection.getRightPorts()) { - boolean leftInCycle = false; - - for (NamedInstance it : cycles) { - if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) - || (it.getDefinition().equals(lp.getVariable()) && it.getParent().equals(lp.getContainer()))) { - leftInCycle = true; - break; - } - } + @Check(CheckType.FAST) + public void checkConnection(Connection connection) { - for (NamedInstance it : cycles) { - if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) - || (it.getDefinition().equals(rp.getVariable()) && it.getParent().equals(rp.getContainer()))) { - if (leftInCycle) { - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - String reactorName = reactor.getName(); - error(String.format("Connection in reactor %s creates", reactorName) + - String.format("a cyclic dependency between %s and %s.", toOriginalText(lp), toOriginalText(rp)), - Literals.CONNECTION__DELAY); - } - } - } - } - } - - // FIXME: look up all ReactorInstance objects that have a definition equal to the - // container of this connection. For each of those occurrences, the widths have to match. - // For the C target, since C has such a weak type system, check that - // the types on both sides of every connection match. For other languages, - // we leave type compatibility that language's compiler or interpreter. - if (isCBasedTarget()) { - Type type = (Type) null; - for (VarRef port : connection.getLeftPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - // Unfortunately, xtext does not generate a suitable equals() - // method for AST types, so we have to manually check the types. - if (!sameType(type, ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); - } - } - } - } - for (VarRef port : connection.getRightPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - if (!sameType(type, type = ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); - } - } - } - } - } + // Report if connection is part of a cycle. + Set> cycles = this.info.topologyCycles(); + for (VarRef lp : connection.getLeftPorts()) { + for (VarRef rp : connection.getRightPorts()) { + boolean leftInCycle = false; - // Check whether the total width of the left side of the connection - // matches the total width of the right side. This cannot be determined - // here if the width is not given as a constant. In that case, it is up - // to the code generator to check it. - int leftWidth = 0; - for (VarRef port : connection.getLeftPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || leftWidth < 0) { - // Cannot determine the width of the left ports. - leftWidth = -1; - } else { - leftWidth += width; - } - } - int rightWidth = 0; - for (VarRef port : connection.getRightPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || rightWidth < 0) { - // Cannot determine the width of the left ports. - rightWidth = -1; - } else { - rightWidth += width; - } - } - - if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { - if (connection.isIterated()) { - if (leftWidth == 0 || rightWidth % leftWidth != 0) { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning(String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS - ); - } - } else { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning(String.format("Left width %s does not match right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS - ); - } + for (NamedInstance it : cycles) { + if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) + || (it.getDefinition().equals(lp.getVariable()) + && it.getParent().equals(lp.getContainer()))) { + leftInCycle = true; + break; + } } - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - - // Make sure the right port is not already an effect of a reaction. - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - for (VarRef effect : reaction.getEffects()) { - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort.getVariable().equals(effect.getVariable()) && // Refers to the same variable - rightPort.getContainer() == effect.getContainer() && // Refers to the same instance - ( reaction.eContainer() instanceof Reactor || // Either is not part of a mode - connection.eContainer() instanceof Reactor || - connection.eContainer() == reaction.eContainer() // Or they are in the same mode - )) { - error("Cannot connect: Port named '" + effect.getVariable().getName() + - "' is already effect of a reaction.", - Literals.CONNECTION__RIGHT_PORTS); - } - } + for (NamedInstance it : cycles) { + if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) + || (it.getDefinition().equals(rp.getVariable()) + && it.getParent().equals(rp.getContainer()))) { + if (leftInCycle) { + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + String reactorName = reactor.getName(); + error( + String.format("Connection in reactor %s creates", reactorName) + + String.format( + "a cyclic dependency between %s and %s.", + toOriginalText(lp), toOriginalText(rp)), + Literals.CONNECTION__DELAY); } + } } + } + } - // Check that the right port does not already have some other - // upstream connection. - for (Connection c : reactor.getConnections()) { - if (c != connection) { - for (VarRef thisRightPort : connection.getRightPorts()) { - for (VarRef thatRightPort : c.getRightPorts()) { - if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) && // Refers to the same variable - thisRightPort.getContainer() == thatRightPort.getContainer() && // Refers to the same instance - ( connection.eContainer() instanceof Reactor || // Or either of the connections in not part of a mode - c.eContainer() instanceof Reactor || - connection.eContainer() == c.eContainer() // Or they are in the same mode - )) { - error( - "Cannot connect: Port named '" + thisRightPort.getVariable().getName() + - "' may only appear once on the right side of a connection.", - Literals.CONNECTION__RIGHT_PORTS); - } - } - } + // FIXME: look up all ReactorInstance objects that have a definition equal to the + // container of this connection. For each of those occurrences, the widths have to match. + // For the C target, since C has such a weak type system, check that + // the types on both sides of every connection match. For other languages, + // we leave type compatibility that language's compiler or interpreter. + if (isCBasedTarget()) { + Type type = (Type) null; + for (VarRef port : connection.getLeftPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + // Unfortunately, xtext does not generate a suitable equals() + // method for AST types, so we have to manually check the types. + if (!sameType(type, ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); } + } } - - // Check the after delay - if (connection.getDelay() != null) { - final var delay = connection.getDelay(); - if (delay instanceof ParameterReference || delay instanceof Time || delay instanceof Literal) { - checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); - } else { - error("After delays can only be given by time literals or parameters.", - Literals.CONNECTION__DELAY); + } + for (VarRef port : connection.getRightPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + if (!sameType(type, type = ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); } + } } + } } - @Check(CheckType.FAST) - public void checkDeadline(Deadline deadline) { - if (isCBasedTarget() && - this.info.overflowingDeadlines.contains(deadline)) { - error( - "Deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.DEADLINE__DELAY); - } - checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); + // Check whether the total width of the left side of the connection + // matches the total width of the right side. This cannot be determined + // here if the width is not given as a constant. In that case, it is up + // to the code generator to check it. + int leftWidth = 0; + for (VarRef port : connection.getLeftPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || leftWidth < 0) { + // Cannot determine the width of the left ports. + leftWidth = -1; + } else { + leftWidth += width; + } + } + int rightWidth = 0; + for (VarRef port : connection.getRightPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || rightWidth < 0) { + // Cannot determine the width of the left ports. + rightWidth = -1; + } else { + rightWidth += width; + } } - @Check(CheckType.FAST) - public void checkHost(Host host) { - String addr = host.getAddr(); - String user = host.getUser(); - if (user != null && !user.matches(USERNAME_REGEX)) { - warning( - "Invalid user name.", - Literals.HOST__USER - ); - } - if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { - warning( - "Invalid IP address.", - Literals.HOST__ADDR - ); - } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { - warning( - "Invalid IP address.", - Literals.HOST__ADDR - ); - } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { - warning( - "Invalid host name or fully qualified domain name.", - Literals.HOST__ADDR - ); - } + if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { + if (connection.isIterated()) { + if (leftWidth == 0 || rightWidth % leftWidth != 0) { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning( + String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS); + } + } else { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning( + String.format("Left width %s does not match right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS); + } } - @Check - public void checkImport(Import imp) { - if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { - error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. - return; + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + + // Make sure the right port is not already an effect of a reaction. + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + for (VarRef effect : reaction.getEffects()) { + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort.getVariable().equals(effect.getVariable()) + && // Refers to the same variable + rightPort.getContainer() == effect.getContainer() + && // Refers to the same instance + (reaction.eContainer() instanceof Reactor + || // Either is not part of a mode + connection.eContainer() instanceof Reactor + || connection.eContainer() + == reaction.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + + effect.getVariable().getName() + + "' is already effect of a reaction.", + Literals.CONNECTION__RIGHT_PORTS); + } } + } + } - // FIXME: report error if resource cannot be resolved. - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (!isUnused(reactor)) { - return; + // Check that the right port does not already have some other + // upstream connection. + for (Connection c : reactor.getConnections()) { + if (c != connection) { + for (VarRef thisRightPort : connection.getRightPorts()) { + for (VarRef thatRightPort : c.getRightPorts()) { + if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) + && // Refers to the same variable + thisRightPort.getContainer() == thatRightPort.getContainer() + && // Refers to the same instance + (connection.eContainer() instanceof Reactor + || // Or either of the connections in not part of a mode + c.eContainer() instanceof Reactor + || connection.eContainer() == c.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + + thisRightPort.getVariable().getName() + + "' may only appear once on the right side of a connection.", + Literals.CONNECTION__RIGHT_PORTS); } + } } - warning("Unused import.", Literals.IMPORT__IMPORT_URI); + } } - @Check - public void checkImportedReactor(ImportedReactor reactor) { - if (isUnused(reactor)) { - warning("Unused reactor class.", - Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } - - if (info.instantiationGraph.hasCycles()) { - Set cycleSet = new HashSet<>(); - for (Set cycle : info.instantiationGraph.getCycles()) { - cycleSet.addAll(cycle); - } - if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { - error("Imported reactor '" + toDefinition(reactor).getName() + - "' has cyclic instantiation in it.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } - } + // Check the after delay + if (connection.getDelay() != null) { + final var delay = connection.getDelay(); + if (delay instanceof ParameterReference + || delay instanceof Time + || delay instanceof Literal) { + checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); + } else { + error( + "After delays can only be given by time literals or parameters.", + Literals.CONNECTION__DELAY); + } + } + } + + @Check(CheckType.FAST) + public void checkDeadline(Deadline deadline) { + if (isCBasedTarget() && this.info.overflowingDeadlines.contains(deadline)) { + error( + "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.DEADLINE__DELAY); + } + checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); + } + + @Check(CheckType.FAST) + public void checkHost(Host host) { + String addr = host.getAddr(); + String user = host.getUser(); + if (user != null && !user.matches(USERNAME_REGEX)) { + warning("Invalid user name.", Literals.HOST__USER); } + if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { + warning("Invalid IP address.", Literals.HOST__ADDR); + } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { + warning("Invalid IP address.", Literals.HOST__ADDR); + } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { + warning("Invalid host name or fully qualified domain name.", Literals.HOST__ADDR); + } + } - @Check(CheckType.FAST) - public void checkInput(Input input) { - Reactor parent = (Reactor)input.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); - } - checkName(input.getName(), Literals.VARIABLE__NAME); - if (target.requiresTypes) { - if (input.getType() == null) { - error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); - } - } + @Check + public void checkImport(Import imp) { + if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { + error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. + return; + } - // mutable has no meaning in C++ - if (input.isMutable() && this.target == Target.CPP) { - warning( - "The mutable qualifier has no meaning for the C++ target and should be removed. " + - "In C++, any value can be made mutable by calling get_mutable_copy().", - Literals.INPUT__MUTABLE - ); - } + // FIXME: report error if resource cannot be resolved. + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (!isUnused(reactor)) { + return; + } + } + warning("Unused import.", Literals.IMPORT__IMPORT_URI); + } - // Variable width multiports are not supported (yet?). - if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } + @Check + public void checkImportedReactor(ImportedReactor reactor) { + if (isUnused(reactor)) { + warning("Unused reactor class.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); } - @Check(CheckType.FAST) - public void checkInstantiation(Instantiation instantiation) { - checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); - Reactor reactor = toDefinition(instantiation.getReactorClass()); - if (reactor.isMain() || reactor.isFederated()) { - error( - "Cannot instantiate a main (or federated) reactor: " + - instantiation.getReactorClass().getName(), - Literals.INSTANTIATION__REACTOR_CLASS - ); - } + if (info.instantiationGraph.hasCycles()) { + Set cycleSet = new HashSet<>(); + for (Set cycle : info.instantiationGraph.getCycles()) { + cycleSet.addAll(cycle); + } + if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { + error( + "Imported reactor '" + + toDefinition(reactor).getName() + + "' has cyclic instantiation in it.", + Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } + } + } - // Report error if this instantiation is part of a cycle. - // FIXME: improve error message. - // FIXME: Also report if there exists a cycle within. - if (this.info.instantiationGraph.getCycles().size() > 0) { - for (Set cycle : this.info.instantiationGraph.getCycles()) { - Reactor container = (Reactor) instantiation.eContainer(); - if (cycle.contains(container) && cycle.contains(reactor)) { - List names = new ArrayList<>(); - for (Reactor r : cycle) { - names.add(r.getName()); - } - - error( - "Instantiation is part of a cycle: " + String.join(", ", names) + ".", - Literals.INSTANTIATION__REACTOR_CLASS - ); - } - } - } - // Variable width multiports are not supported (yet?). - if (instantiation.getWidthSpec() != null - && instantiation.getWidthSpec().isOfVariableLength() - ) { - if (isCBasedTarget()) { - warning("Variable-width banks are for internal use only.", - Literals.INSTANTIATION__WIDTH_SPEC - ); - } else { - error("Variable-width banks are not supported.", - Literals.INSTANTIATION__WIDTH_SPEC - ); - } - } + @Check(CheckType.FAST) + public void checkInput(Input input) { + Reactor parent = (Reactor) input.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); + } + checkName(input.getName(), Literals.VARIABLE__NAME); + if (target.requiresTypes) { + if (input.getType() == null) { + error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - /** Check target parameters, which are key-value pairs. */ - @Check(CheckType.FAST) - public void checkKeyValuePair(KeyValuePair param) { - // Check only if the container's container is a Target. - if (param.eContainer().eContainer() instanceof TargetDecl) { - TargetProperty prop = TargetProperty.forName(param.getName()); - - // Make sure the key is valid. - if (prop == null) { - String options = TargetProperty.getOptions().stream() - .map(p -> p.description).sorted() - .collect(Collectors.joining(", ")); - warning( - "Unrecognized target parameter: " + param.getName() + - ". Recognized parameters are: " + options, - Literals.KEY_VALUE_PAIR__NAME); - } else { - // Check whether the property is supported by the target. - if (!prop.supportedBy.contains(this.target)) { - warning( - "The target parameter: " + param.getName() + - " is not supported by the " + this.target + - " target and will thus be ignored.", - Literals.KEY_VALUE_PAIR__NAME); - } + // mutable has no meaning in C++ + if (input.isMutable() && this.target == Target.CPP) { + warning( + "The mutable qualifier has no meaning for the C++ target and should be removed. " + + "In C++, any value can be made mutable by calling get_mutable_copy().", + Literals.INPUT__MUTABLE); + } - // Report problem with the assigned value. - prop.type.check(param.getValue(), param.getName(), this); - } + // Variable width multiports are not supported (yet?). + if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } + + @Check(CheckType.FAST) + public void checkInstantiation(Instantiation instantiation) { + checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); + Reactor reactor = toDefinition(instantiation.getReactorClass()); + if (reactor.isMain() || reactor.isFederated()) { + error( + "Cannot instantiate a main (or federated) reactor: " + + instantiation.getReactorClass().getName(), + Literals.INSTANTIATION__REACTOR_CLASS); + } - for (String it : targetPropertyErrors) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyErrors.clear(); + // Report error if this instantiation is part of a cycle. + // FIXME: improve error message. + // FIXME: Also report if there exists a cycle within. + if (this.info.instantiationGraph.getCycles().size() > 0) { + for (Set cycle : this.info.instantiationGraph.getCycles()) { + Reactor container = (Reactor) instantiation.eContainer(); + if (cycle.contains(container) && cycle.contains(reactor)) { + List names = new ArrayList<>(); + for (Reactor r : cycle) { + names.add(r.getName()); + } - for (String it : targetPropertyWarnings) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyWarnings.clear(); + error( + "Instantiation is part of a cycle: " + String.join(", ", names) + ".", + Literals.INSTANTIATION__REACTOR_CLASS); } + } } - - @Check(CheckType.FAST) - public void checkModel(Model model) { - // Since we're doing a fast check, we only want to update - // if the model info hasn't been initialized yet. If it has, - // we use the old information and update it during a normal - // check (see below). - if (!info.updated) { - info.update(model, errorReporter); - } + // Variable width multiports are not supported (yet?). + if (instantiation.getWidthSpec() != null && instantiation.getWidthSpec().isOfVariableLength()) { + if (isCBasedTarget()) { + warning( + "Variable-width banks are for internal use only.", Literals.INSTANTIATION__WIDTH_SPEC); + } else { + error("Variable-width banks are not supported.", Literals.INSTANTIATION__WIDTH_SPEC); + } + } + } + + /** Check target parameters, which are key-value pairs. */ + @Check(CheckType.FAST) + public void checkKeyValuePair(KeyValuePair param) { + // Check only if the container's container is a Target. + if (param.eContainer().eContainer() instanceof TargetDecl) { + TargetProperty prop = TargetProperty.forName(param.getName()); + + // Make sure the key is valid. + if (prop == null) { + String options = + TargetProperty.getOptions().stream() + .map(p -> p.description) + .sorted() + .collect(Collectors.joining(", ")); + warning( + "Unrecognized target parameter: " + + param.getName() + + ". Recognized parameters are: " + + options, + Literals.KEY_VALUE_PAIR__NAME); + } else { + // Check whether the property is supported by the target. + if (!prop.supportedBy.contains(this.target)) { + warning( + "The target parameter: " + + param.getName() + + " is not supported by the " + + this.target + + " target and will thus be ignored.", + Literals.KEY_VALUE_PAIR__NAME); + } + + // Report problem with the assigned value. + prop.type.check(param.getValue(), param.getName(), this); + } + + for (String it : targetPropertyErrors) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyErrors.clear(); + + for (String it : targetPropertyWarnings) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyWarnings.clear(); + } + } + + @Check(CheckType.FAST) + public void checkModel(Model model) { + // Since we're doing a fast check, we only want to update + // if the model info hasn't been initialized yet. If it has, + // we use the old information and update it during a normal + // check (see below). + if (!info.updated) { + info.update(model, errorReporter); + } + } + + @Check(CheckType.NORMAL) + public void updateModelInfo(Model model) { + info.update(model, errorReporter); + } + + @Check(CheckType.FAST) + public void checkOutput(Output output) { + Reactor parent = (Reactor) output.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); + } + checkName(output.getName(), Literals.VARIABLE__NAME); + if (this.target.requiresTypes) { + if (output.getType() == null) { + error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - @Check(CheckType.NORMAL) - public void updateModelInfo(Model model) { - info.update(model, errorReporter); + // Variable width multiports are not supported (yet?). + if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); } + } - @Check(CheckType.FAST) - public void checkOutput(Output output) { - Reactor parent = (Reactor)output.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); - } - checkName(output.getName(), Literals.VARIABLE__NAME); - if (this.target.requiresTypes) { - if (output.getType() == null) { - error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); - } - } + @Check(CheckType.FAST) + public void checkParameter(Parameter param) { + checkName(param.getName(), Literals.PARAMETER__NAME); - // Variable width multiports are not supported (yet?). - if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } + if (param.getInit() == null) { + // todo make initialization non-mandatory + // https://github.com/lf-lang/lingua-franca/issues/623 + error("Parameter must have a default value.", Literals.PARAMETER__INIT); + return; } - @Check(CheckType.FAST) - public void checkParameter(Parameter param) { - checkName(param.getName(), Literals.PARAMETER__NAME); + if (this.target.requiresTypes) { + // Report missing target type. param.inferredType.undefine + if (ASTUtils.getInferredType(param).isUndefined()) { + error("Type declaration missing.", Literals.PARAMETER__TYPE); + } + } - if (param.getInit() == null) { - // todo make initialization non-mandatory - // https://github.com/lf-lang/lingua-franca/issues/623 - error("Parameter must have a default value.", Literals.PARAMETER__INIT); - return; - } + if (param.getType() != null) { + typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); + } - if (this.target.requiresTypes) { - // Report missing target type. param.inferredType.undefine - if (ASTUtils.getInferredType(param).isUndefined()) { - error("Type declaration missing.", Literals.PARAMETER__TYPE); - } + if (param.getInit() != null) { + for (Expression expr : param.getInit().getExprs()) { + if (expr instanceof ParameterReference) { + // Initialization using parameters is forbidden. + error("Parameter cannot be initialized using parameter.", Literals.PARAMETER__INIT); } + } + } - if (param.getType() != null) { - typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); - } + if (this.target == Target.CPP) { + EObject container = param.eContainer(); + Reactor reactor = (Reactor) container; + if (reactor.isMain()) { + // we need to check for the cli parameters that are always taken + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); + if (cliParams.contains(param.getName())) { + error( + "Parameter '" + + param.getName() + + "' is already in use as command line argument by Lingua Franca,", + Literals.PARAMETER__NAME); + } + } + } - if (param.getInit() != null) { - for (Expression expr : param.getInit().getExprs()) { - if (expr instanceof ParameterReference) { - // Initialization using parameters is forbidden. - error("Parameter cannot be initialized using parameter.", - Literals.PARAMETER__INIT); - } - } + if (isCBasedTarget() && this.info.overflowingParameters.contains(param)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds.", + Literals.PARAMETER__INIT); + } + } + + @Check(CheckType.FAST) + public void checkPreamble(Preamble preamble) { + if (this.target == Target.CPP) { + if (preamble.getVisibility() == Visibility.NONE) { + error( + "Preambles for the C++ target need a visibility qualifier (private or public)!", + Literals.PREAMBLE__VISIBILITY); + } else if (preamble.getVisibility() == Visibility.PRIVATE) { + EObject container = preamble.eContainer(); + if (container != null && container instanceof Reactor) { + Reactor reactor = (Reactor) container; + if (isGeneric(reactor)) { + warning( + "Private preambles in generic reactors are not truly private. " + + "Since the generated code is placed in a *_impl.hh file, it will " + + "be visible on the public interface. Consider using a public " + + "preamble within the reactor or a private preamble on file scope.", + Literals.PREAMBLE__VISIBILITY); + } } + } + } else if (preamble.getVisibility() != Visibility.NONE) { + warning( + String.format( + "The %s qualifier has no meaning for the %s target. It should be removed.", + preamble.getVisibility(), this.target.name()), + Literals.PREAMBLE__VISIBILITY); + } + } - if (this.target == Target.CPP) { - EObject container = param.eContainer(); - Reactor reactor = (Reactor) container; - if (reactor.isMain()) { - // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); - if (cliParams.contains(param.getName())) { - error("Parameter '" + param.getName() - + "' is already in use as command line argument by Lingua Franca,", - Literals.PARAMETER__NAME); - } - } - } + @Check(CheckType.FAST) + public void checkReaction(Reaction reaction) { - if (isCBasedTarget() && - this.info.overflowingParameters.contains(param)) { + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); + } + HashSet triggers = new HashSet<>(); + // Make sure input triggers have no container and output sources do. + for (TriggerRef trigger : reaction.getTriggers()) { + if (trigger instanceof VarRef) { + VarRef triggerVarRef = (VarRef) trigger; + triggers.add(triggerVarRef.getVariable()); + if (triggerVarRef instanceof Input) { + if (triggerVarRef.getContainer() != null) { + error( + String.format( + "Cannot have an input of a contained reactor as a trigger: %s.%s", + triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } else if (triggerVarRef.getVariable() instanceof Output) { + if (triggerVarRef.getContainer() == null) { error( - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.PARAMETER__INIT); + String.format( + "Cannot have an output of this reactor as a trigger: %s", + triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } } - + } } - @Check(CheckType.FAST) - public void checkPreamble(Preamble preamble) { - if (this.target == Target.CPP) { - if (preamble.getVisibility() == Visibility.NONE) { - error( - "Preambles for the C++ target need a visibility qualifier (private or public)!", - Literals.PREAMBLE__VISIBILITY - ); - } else if (preamble.getVisibility() == Visibility.PRIVATE) { - EObject container = preamble.eContainer(); - if (container != null && container instanceof Reactor) { - Reactor reactor = (Reactor) container; - if (isGeneric(reactor)) { - warning( - "Private preambles in generic reactors are not truly private. " + - "Since the generated code is placed in a *_impl.hh file, it will " + - "be visible on the public interface. Consider using a public " + - "preamble within the reactor or a private preamble on file scope.", - Literals.PREAMBLE__VISIBILITY); - } - } - } - } else if (preamble.getVisibility() != Visibility.NONE) { - warning( - String.format("The %s qualifier has no meaning for the %s target. It should be removed.", - preamble.getVisibility(), this.target.name()), - Literals.PREAMBLE__VISIBILITY - ); - } + // Make sure input sources have no container and output sources do. + // Also check that a source is not already listed as a trigger. + for (VarRef source : reaction.getSources()) { + if (triggers.contains(source.getVariable())) { + error( + String.format( + "Source is already listed as a trigger: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + if (source.getVariable() instanceof Input) { + if (source.getContainer() != null) { + error( + String.format( + "Cannot have an input of a contained reactor as a source: %s.%s", + source.getContainer().getName(), source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } else if (source.getVariable() instanceof Output) { + if (source.getContainer() == null) { + error( + String.format( + "Cannot have an output of this reactor as a source: %s", + source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } } - @Check(CheckType.FAST) - public void checkReaction(Reaction reaction) { - - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); - } - HashSet triggers = new HashSet<>(); - // Make sure input triggers have no container and output sources do. - for (TriggerRef trigger : reaction.getTriggers()) { - if (trigger instanceof VarRef) { - VarRef triggerVarRef = (VarRef) trigger; - triggers.add(triggerVarRef.getVariable()); - if (triggerVarRef instanceof Input) { - if (triggerVarRef.getContainer() != null) { - error(String.format("Cannot have an input of a contained reactor as a trigger: %s.%s", triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } else if (triggerVarRef.getVariable() instanceof Output) { - if (triggerVarRef.getContainer() == null) { - error(String.format("Cannot have an output of this reactor as a trigger: %s", triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } - } - } - - // Make sure input sources have no container and output sources do. - // Also check that a source is not already listed as a trigger. - for (VarRef source : reaction.getSources()) { - if (triggers.contains(source.getVariable())) { - error(String.format("Source is already listed as a trigger: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - if (source.getVariable() instanceof Input) { - if (source.getContainer() != null) { - error(String.format("Cannot have an input of a contained reactor as a source: %s.%s", source.getContainer().getName(), source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } else if (source.getVariable() instanceof Output) { - if (source.getContainer() == null) { - error(String.format("Cannot have an output of this reactor as a source: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } - } + // Make sure output effects have no container and input effects do. + for (VarRef effect : reaction.getEffects()) { + if (effect.getVariable() instanceof Input) { + if (effect.getContainer() == null) { + error( + String.format( + "Cannot have an input of this reactor as an effect: %s", + effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } else if (effect.getVariable() instanceof Output) { + if (effect.getContainer() != null) { + error( + String.format( + "Cannot have an output of a contained reactor as an effect: %s.%s", + effect.getContainer().getName(), effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } + } - // Make sure output effects have no container and input effects do. - for (VarRef effect : reaction.getEffects()) { - if (effect.getVariable() instanceof Input) { - if (effect.getContainer() == null) { - error(String.format("Cannot have an input of this reactor as an effect: %s", effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } else if (effect.getVariable() instanceof Output) { - if (effect.getContainer() != null) { - error(String.format("Cannot have an output of a contained reactor as an effect: %s.%s", effect.getContainer().getName(), effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } + // // Report error if this reaction is part of a cycle. + Set> cycles = this.info.topologyCycles(); + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + boolean reactionInCycle = false; + for (NamedInstance it : cycles) { + if (it.getDefinition().equals(reaction)) { + reactionInCycle = true; + break; + } + } + if (reactionInCycle) { + // Report involved triggers. + List trigs = new ArrayList<>(); + for (TriggerRef t : reaction.getTriggers()) { + if (!(t instanceof VarRef)) { + continue; + } + VarRef tVarRef = (VarRef) t; + boolean triggerExistsInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(tVarRef.getVariable())) { + triggerExistsInCycle = true; + break; + } } - - // // Report error if this reaction is part of a cycle. - Set> cycles = this.info.topologyCycles(); - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - boolean reactionInCycle = false; - for (NamedInstance it : cycles) { - if (it.getDefinition().equals(reaction)) { - reactionInCycle = true; - break; - } + if (triggerExistsInCycle) { + trigs.add(toOriginalText(tVarRef)); + } + } + if (trigs.size() > 0) { + error( + String.format( + "Reaction triggers involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", trigs)), + Literals.REACTION__TRIGGERS); + } + + // Report involved sources. + List sources = new ArrayList<>(); + for (VarRef t : reaction.getSources()) { + boolean sourceExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + sourceExistInCycle = true; + break; + } } - if (reactionInCycle) { - // Report involved triggers. - List trigs = new ArrayList<>(); - for (TriggerRef t : reaction.getTriggers()) { - if (!(t instanceof VarRef)) { - continue; - } - VarRef tVarRef = (VarRef) t; - boolean triggerExistsInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(tVarRef.getVariable())) { - triggerExistsInCycle = true; - break; - } - } - if (triggerExistsInCycle) { - trigs.add(toOriginalText(tVarRef)); - } - } - if (trigs.size() > 0) { - error(String.format("Reaction triggers involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", trigs)), - Literals.REACTION__TRIGGERS); - } - - // Report involved sources. - List sources = new ArrayList<>(); - for (VarRef t : reaction.getSources()) { - boolean sourceExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - sourceExistInCycle = true; - break; - } - } - if (sourceExistInCycle) { - sources.add(toOriginalText(t)); - } - } - if (sources.size() > 0) { - error(String.format("Reaction sources involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", sources)), - Literals.REACTION__SOURCES); - } - - // Report involved effects. - List effects = new ArrayList<>(); - for (VarRef t : reaction.getEffects()) { - boolean effectExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - effectExistInCycle = true; - break; - } - } - if (effectExistInCycle) { - effects.add(toOriginalText(t)); - } - } - if (effects.size() > 0) { - error(String.format("Reaction effects involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", effects)), - Literals.REACTION__EFFECTS); - } - - if (trigs.size() + sources.size() == 0) { - error( - String.format("Cyclic dependency due to preceding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction) - ); - } else if (effects.size() == 0) { - error( - String.format("Cyclic dependency due to succeeding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction) - ); - } - // Not reporting reactions that are part of cycle _only_ due to reaction ordering. - // Moving them won't help solve the problem. + if (sourceExistInCycle) { + sources.add(toOriginalText(t)); + } + } + if (sources.size() > 0) { + error( + String.format( + "Reaction sources involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", sources)), + Literals.REACTION__SOURCES); + } + + // Report involved effects. + List effects = new ArrayList<>(); + for (VarRef t : reaction.getEffects()) { + boolean effectExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + effectExistInCycle = true; + break; + } } + if (effectExistInCycle) { + effects.add(toOriginalText(t)); + } + } + if (effects.size() > 0) { + error( + String.format( + "Reaction effects involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", effects)), + Literals.REACTION__EFFECTS); + } + + if (trigs.size() + sources.size() == 0) { + error( + String.format( + "Cyclic dependency due to preceding reaction. Consider reordering reactions within" + + " reactor %s to avoid causality loop.", + reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction)); + } else if (effects.size() == 0) { + error( + String.format( + "Cyclic dependency due to succeeding reaction. Consider reordering reactions within" + + " reactor %s to avoid causality loop.", + reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction)); + } + // Not reporting reactions that are part of cycle _only_ due to reaction ordering. + // Moving them won't help solve the problem. + } // FIXME: improve error message. + } + + @Check(CheckType.FAST) + public void checkReactor(Reactor reactor) throws IOException { + Set superClasses = ASTUtils.superClasses(reactor); + if (superClasses == null) { + error( + "Problem with superclasses: Either they form a cycle or are not defined", + Literals.REACTOR_DECL__NAME); + // Continue checks, but without any superclasses. + superClasses = new LinkedHashSet<>(); } - - @Check(CheckType.FAST) - public void checkReactor(Reactor reactor) throws IOException { - Set superClasses = ASTUtils.superClasses(reactor); - if (superClasses == null) { - error( - "Problem with superclasses: Either they form a cycle or are not defined", - Literals.REACTOR_DECL__NAME - ); - // Continue checks, but without any superclasses. - superClasses = new LinkedHashSet<>(); - } - String name = FileUtil.nameWithoutExtension(reactor.eResource()); - if (reactor.getName() == null) { - if (!reactor.isFederated() && !reactor.isMain()) { - error( - "Reactor must be named.", - Literals.REACTOR_DECL__NAME - ); - // Prevent NPE in tests below. - return; - } - } - TreeIterator iter = reactor.eResource().getAllContents(); - if (reactor.isFederated() || reactor.isMain()) { - if(reactor.getName() != null && !reactor.getName().equals(name)) { - // Make sure that if the name is given, it matches the expected name. - error( - "Name of main reactor must match the file name (or be omitted).", - Literals.REACTOR_DECL__NAME - ); - } - // Do not allow multiple main/federated reactors. - int nMain = countMainOrFederated(iter); - if (nMain > 1) { - EAttribute attribute = Literals.REACTOR__MAIN; - if (reactor.isFederated()) { - attribute = Literals.REACTOR__FEDERATED; - } - error( - "Multiple definitions of main or federated reactor.", - attribute - ); - } - } else { - // Not federated or main. - int nMain = countMainOrFederated(iter); - if (nMain > 0 && reactor.getName().equals(name)) { - error( - "Name conflict with main reactor.", - Literals.REACTOR_DECL__NAME - ); - } - } - - // Check for illegal names. - checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); - - // C++ reactors may not be called 'preamble' - if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { - error( - "Reactor cannot be named '" + reactor.getName() + "'", - Literals.REACTOR_DECL__NAME - ); - } - - if (reactor.getHost() != null) { - if (!reactor.isFederated()) { - error( - "Cannot assign a host to reactor '" + reactor.getName() + - "' because it is not federated.", - Literals.REACTOR__HOST - ); - } - } - - List variables = new ArrayList<>(); - variables.addAll(reactor.getInputs()); - variables.addAll(reactor.getOutputs()); - variables.addAll(reactor.getActions()); - variables.addAll(reactor.getTimers()); - - // Perform checks on super classes. - for (Reactor superClass : superClasses) { - HashSet conflicts = new HashSet<>(); - - // Detect input conflicts - checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); - // Detect conflicts - for (Timer timer : superClass.getTimers()) { - List filteredVariables = new ArrayList<>(variables); - filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); - if (hasNameConflict(timer, filteredVariables)) { - conflicts.add(timer); - } else { - variables.add(timer); - } - } - - // Report conflicts. - if (conflicts.size() > 0) { - List names = new ArrayList<>(); - for (Variable it : conflicts) { - names.add(it.getName()); - } - error( - String.format("Cannot extend %s due to the following conflicts: %s.", - superClass.getName(), String.join(",", names)), - Literals.REACTOR__SUPER_CLASSES - ); - } - } - + String name = FileUtil.nameWithoutExtension(reactor.eResource()); + if (reactor.getName() == null) { + if (!reactor.isFederated() && !reactor.isMain()) { + error("Reactor must be named.", Literals.REACTOR_DECL__NAME); + // Prevent NPE in tests below. + return; + } + } + TreeIterator iter = reactor.eResource().getAllContents(); + if (reactor.isFederated() || reactor.isMain()) { + if (reactor.getName() != null && !reactor.getName().equals(name)) { + // Make sure that if the name is given, it matches the expected name. + error( + "Name of main reactor must match the file name (or be omitted).", + Literals.REACTOR_DECL__NAME); + } + // Do not allow multiple main/federated reactors. + int nMain = countMainOrFederated(iter); + if (nMain > 1) { + EAttribute attribute = Literals.REACTOR__MAIN; if (reactor.isFederated()) { - FedValidator.validateFederatedReactor(reactor, this.errorReporter); - } + attribute = Literals.REACTOR__FEDERATED; + } + error("Multiple definitions of main or federated reactor.", attribute); + } + } else { + // Not federated or main. + int nMain = countMainOrFederated(iter); + if (nMain > 0 && reactor.getName().equals(name)) { + error("Name conflict with main reactor.", Literals.REACTOR_DECL__NAME); + } } - /** - * Check if the requested serialization is supported. - */ - @Check(CheckType.FAST) - public void checkSerializer(Serializer serializer) { - boolean isValidSerializer = false; - for (SupportedSerializers method : SupportedSerializers.values()) { - if (method.name().equalsIgnoreCase(serializer.getType())){ - isValidSerializer = true; - } - } + // Check for illegal names. + checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); - if (!isValidSerializer) { - error( - "Serializer can be " + Arrays.asList(SupportedSerializers.values()), - Literals.SERIALIZER__TYPE - ); - } + // C++ reactors may not be called 'preamble' + if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { + error("Reactor cannot be named '" + reactor.getName() + "'", Literals.REACTOR_DECL__NAME); } - @Check(CheckType.FAST) - public void checkState(StateVar stateVar) { - checkName(stateVar.getName(), Literals.STATE_VAR__NAME); - if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { - typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); - } + if (reactor.getHost() != null) { + if (!reactor.isFederated()) { + error( + "Cannot assign a host to reactor '" + + reactor.getName() + + "' because it is not federated.", + Literals.REACTOR__HOST); + } + } - if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { - // Report if a type is missing - error("State must have a type.", Literals.STATE_VAR__TYPE); - } + List variables = new ArrayList<>(); + variables.addAll(reactor.getInputs()); + variables.addAll(reactor.getOutputs()); + variables.addAll(reactor.getActions()); + variables.addAll(reactor.getTimers()); + + // Perform checks on super classes. + for (Reactor superClass : superClasses) { + HashSet conflicts = new HashSet<>(); + + // Detect input conflicts + checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); + // Detect conflicts + for (Timer timer : superClass.getTimers()) { + List filteredVariables = new ArrayList<>(variables); + filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); + if (hasNameConflict(timer, filteredVariables)) { + conflicts.add(timer); + } else { + variables.add(timer); + } + } + + // Report conflicts. + if (conflicts.size() > 0) { + List names = new ArrayList<>(); + for (Variable it : conflicts) { + names.add(it.getName()); + } + error( + String.format( + "Cannot extend %s due to the following conflicts: %s.", + superClass.getName(), String.join(",", names)), + Literals.REACTOR__SUPER_CLASSES); + } + } - if (isCBasedTarget() - && ASTUtils.isListInitializer(stateVar.getInit()) - && stateVar.getInit().getExprs().stream().anyMatch(it -> it instanceof ParameterReference)) { - // In C, if initialization is done with a list, elements cannot - // refer to parameters. - error("List items cannot refer to a parameter.", - Literals.STATE_VAR__INIT); - } + if (reactor.isFederated()) { + FedValidator.validateFederatedReactor(reactor, this.errorReporter); + } + } + + /** Check if the requested serialization is supported. */ + @Check(CheckType.FAST) + public void checkSerializer(Serializer serializer) { + boolean isValidSerializer = false; + for (SupportedSerializers method : SupportedSerializers.values()) { + if (method.name().equalsIgnoreCase(serializer.getType())) { + isValidSerializer = true; + } + } + if (!isValidSerializer) { + error( + "Serializer can be " + Arrays.asList(SupportedSerializers.values()), + Literals.SERIALIZER__TYPE); } + } - @Check(CheckType.FAST) - public void checkSTPOffset(STP stp) { - if (isCBasedTarget() && - this.info.overflowingSTP.contains(stp)) { - error( - "STP offset exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.STP__VALUE); - } + @Check(CheckType.FAST) + public void checkState(StateVar stateVar) { + checkName(stateVar.getName(), Literals.STATE_VAR__NAME); + if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { + typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); } - @Check(CheckType.FAST) - public void checkTargetDecl(TargetDecl target) throws IOException { - Optional targetOpt = Target.forName(target.getName()); - if (targetOpt.isEmpty()) { - error("Unrecognized target: " + target.getName(), - Literals.TARGET_DECL__NAME); - } else { - this.target = targetOpt.get(); - } - String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); - if (Character.isDigit(lfFileName.charAt(0))) { - errorReporter.reportError("LF file names must not start with a number"); - } + if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { + // Report if a type is missing + error("State must have a type.", Literals.STATE_VAR__TYPE); } - /** - * Check for consistency of the target properties, which are - * defined as KeyValuePairs. - * - * @param targetProperties The target properties defined - * in the current Lingua Franca program. - */ - @Check(CheckType.EXPENSIVE) - public void checkTargetProperties(KeyValuePairs targetProperties) { - validateFastTargetProperty(targetProperties); - validateClockSyncTargetProperties(targetProperties); - validateSchedulerTargetProperties(targetProperties); - validateRos2TargetProperties(targetProperties); - validateKeepalive(targetProperties); - } - - private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { - List properties = targetProperties.getPairs().stream() + if (isCBasedTarget() + && ASTUtils.isListInitializer(stateVar.getInit()) + && stateVar.getInit().getExprs().stream() + .anyMatch(it -> it instanceof ParameterReference)) { + // In C, if initialization is done with a list, elements cannot + // refer to parameters. + error("List items cannot refer to a parameter.", Literals.STATE_VAR__INIT); + } + } + + @Check(CheckType.FAST) + public void checkSTPOffset(STP stp) { + if (isCBasedTarget() && this.info.overflowingSTP.contains(stp)) { + error( + "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.STP__VALUE); + } + } + + @Check(CheckType.FAST) + public void checkTargetDecl(TargetDecl target) throws IOException { + Optional targetOpt = Target.forName(target.getName()); + if (targetOpt.isEmpty()) { + error("Unrecognized target: " + target.getName(), Literals.TARGET_DECL__NAME); + } else { + this.target = targetOpt.get(); + } + String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); + if (Character.isDigit(lfFileName.charAt(0))) { + errorReporter.reportError("LF file names must not start with a number"); + } + } + + /** + * Check for consistency of the target properties, which are defined as KeyValuePairs. + * + * @param targetProperties The target properties defined in the current Lingua Franca program. + */ + @Check(CheckType.EXPENSIVE) + public void checkTargetProperties(KeyValuePairs targetProperties) { + validateFastTargetProperty(targetProperties); + validateClockSyncTargetProperties(targetProperties); + validateSchedulerTargetProperties(targetProperties); + validateRos2TargetProperties(targetProperties); + validateKeepalive(targetProperties); + } + + private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { + List properties = + targetProperties.getPairs().stream() .filter(pair -> pair.getName().equals(property.description)) .toList(); - assert (properties.size() <= 1); - return properties.size() > 0 ? properties.get(0) : null; - } - private void validateFastTargetProperty(KeyValuePairs targetProperties) { - KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); - - if (fastTargetProperty != null) { - // Check for federated - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a federated reactor - if (reactor.isFederated()) { - error( - "The fast target property is incompatible with federated programs.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - break; - } - } - - // Check for physical actions - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a physical action in a reactor - for (Action action : reactor.getActions()) { - if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { - error( - "The fast target property is incompatible with physical actions.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - break; - } - } - } - } - } + assert (properties.size() <= 1); + return properties.size() > 0 ? properties.get(0) : null; + } - private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair clockSyncTargetProperty = getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); + private void validateFastTargetProperty(KeyValuePairs targetProperties) { + KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); - if (clockSyncTargetProperty != null) { - boolean federatedExists = false; - for (Reactor reactor : info.model.getReactors()) { - if (reactor.isFederated()) { - federatedExists = true; - } - } - if (!federatedExists) { - warning( - "The clock-sync target property is incompatible with non-federated programs.", - clockSyncTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - } + if (fastTargetProperty != null) { + // Check for federated + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a federated reactor + if (reactor.isFederated()) { + error( + "The fast target property is incompatible with federated programs.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + break; + } + } + + // Check for physical actions + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a physical action in a reactor + for (Action action : reactor.getActions()) { + if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { + error( + "The fast target property is incompatible with physical actions.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + break; + } } + } } + } - private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair schedulerTargetProperty = getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); - if (schedulerTargetProperty != null) { - String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); - try { - if (!TargetProperty.SchedulerOption.valueOf(schedulerName) - .prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - // Filter reactors that contain at least one reaction that - // has a deadline handler. - if (info.model.getReactors().stream().anyMatch( - // Filter reactors that contain at least one reaction that - // has a deadline handler. - reactor -> ASTUtils.allReactions(reactor).stream().anyMatch( - reaction -> reaction.getDeadline() != null - )) - ) { - warning("This program contains deadlines, but the chosen " - + schedulerName - + " scheduler does not prioritize reaction execution " - + "based on deadlines. This might result in a sub-optimal " - + "scheduling.", schedulerTargetProperty, - Literals.KEY_VALUE_PAIR__VALUE); - } - } - } catch (IllegalArgumentException e) { - // the given scheduler is invalid, but this is already checked by - // checkTargetProperties - } - } - } + private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair clockSyncTargetProperty = + getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); - private void validateKeepalive(KeyValuePairs targetProperties) { - KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); - if (keepalive != null && target == Target.CPP) { - warning("The keepalive property is inferred automatically by the C++ " + - "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); - } + if (clockSyncTargetProperty != null) { + boolean federatedExists = false; + for (Reactor reactor : info.model.getReactors()) { + if (reactor.isFederated()) { + federatedExists = true; + } + } + if (!federatedExists) { + warning( + "The clock-sync target property is incompatible with non-federated programs.", + clockSyncTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + } } - - private void validateRos2TargetProperties(KeyValuePairs targetProperties) { - KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); - KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); - if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { + } + + private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair schedulerTargetProperty = + getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); + if (schedulerTargetProperty != null) { + String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); + try { + if (!TargetProperty.SchedulerOption.valueOf(schedulerName).prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + // Filter reactors that contain at least one reaction that + // has a deadline handler. + if (info.model.getReactors().stream() + .anyMatch( + // Filter reactors that contain at least one reaction that + // has a deadline handler. + reactor -> + ASTUtils.allReactions(reactor).stream() + .anyMatch(reaction -> reaction.getDeadline() != null))) { warning( - "Ignoring ros2-dependencies as ros2 compilation is disabled", - ros2Dependencies, - Literals.KEY_VALUE_PAIR__NAME - ); + "This program contains deadlines, but the chosen " + + schedulerName + + " scheduler does not prioritize reaction execution " + + "based on deadlines. This might result in a sub-optimal " + + "scheduling.", + schedulerTargetProperty, + Literals.KEY_VALUE_PAIR__VALUE); + } } + } catch (IllegalArgumentException e) { + // the given scheduler is invalid, but this is already checked by + // checkTargetProperties + } } - - @Check(CheckType.FAST) - public void checkTimer(Timer timer) { - checkName(timer.getName(), Literals.VARIABLE__NAME); - checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); - checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); + } + + private void validateKeepalive(KeyValuePairs targetProperties) { + KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); + if (keepalive != null && target == Target.CPP) { + warning( + "The keepalive property is inferred automatically by the C++ " + + "runtime and the value given here is ignored", + keepalive, + Literals.KEY_VALUE_PAIR__NAME); } - - @Check(CheckType.FAST) - public void checkType(Type type) { - // FIXME: disallow the use of generics in C - if (this.target == Target.Python) { - if (type != null) { - error( - "Types are not allowed in the Python target", - Literals.TYPE__ID - ); - } - } + } + + private void validateRos2TargetProperties(KeyValuePairs targetProperties) { + KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); + KeyValuePair ros2Dependencies = + getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); + if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { + warning( + "Ignoring ros2-dependencies as ros2 compilation is disabled", + ros2Dependencies, + Literals.KEY_VALUE_PAIR__NAME); } - - @Check(CheckType.FAST) - public void checkVarRef(VarRef varRef) { - // check correct usage of interleaved - if (varRef.isInterleaved()) { - var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); - if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { - error("This target does not support interleaved port references.", Literals.VAR_REF__INTERLEAVED); - } - if (!(varRef.eContainer() instanceof Connection)) { - error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); - } - - if (varRef.getVariable() instanceof Port) { - // This test only works correctly if the variable is actually a port. If it is not a port, other - // validator rules will produce error messages. - if (varRef.getContainer() == null || varRef.getContainer().getWidthSpec() == null || - ((Port) varRef.getVariable()).getWidthSpec() == null - ) { - error("interleaved can only be used for multiports contained within banks.", Literals.VAR_REF__INTERLEAVED); - } - } - } + } + + @Check(CheckType.FAST) + public void checkTimer(Timer timer) { + checkName(timer.getName(), Literals.VARIABLE__NAME); + checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); + checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); + } + + @Check(CheckType.FAST) + public void checkType(Type type) { + // FIXME: disallow the use of generics in C + if (this.target == Target.Python) { + if (type != null) { + error("Types are not allowed in the Python target", Literals.TYPE__ID); + } } - - /** - * Check whether an attribute is supported - * and the validity of the attribute. - * - * @param attr The attribute being checked - */ - @Check(CheckType.FAST) - public void checkAttributes(Attribute attr) { - String name = attr.getAttrName().toString(); - AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); - if (spec == null) { - error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); - return; - } - // Check the validity of the attribute. - spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkVarRef(VarRef varRef) { + // check correct usage of interleaved + if (varRef.isInterleaved()) { + var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); + if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { + error( + "This target does not support interleaved port references.", + Literals.VAR_REF__INTERLEAVED); + } + if (!(varRef.eContainer() instanceof Connection)) { + error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); + } + + if (varRef.getVariable() instanceof Port) { + // This test only works correctly if the variable is actually a port. If it is not a port, + // other + // validator rules will produce error messages. + if (varRef.getContainer() == null + || varRef.getContainer().getWidthSpec() == null + || ((Port) varRef.getVariable()).getWidthSpec() == null) { + error( + "interleaved can only be used for multiports contained within banks.", + Literals.VAR_REF__INTERLEAVED); + } + } } - - @Check(CheckType.FAST) - public void checkWidthSpec(WidthSpec widthSpec) { - if (!this.target.supportsMultiports()) { - error("Multiports and banks are currently not supported by the given target.", + } + + /** + * Check whether an attribute is supported and the validity of the attribute. + * + * @param attr The attribute being checked + */ + @Check(CheckType.FAST) + public void checkAttributes(Attribute attr) { + String name = attr.getAttrName().toString(); + AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); + if (spec == null) { + error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); + return; + } + // Check the validity of the attribute. + spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkWidthSpec(WidthSpec widthSpec) { + if (!this.target.supportsMultiports()) { + error( + "Multiports and banks are currently not supported by the given target.", + Literals.WIDTH_SPEC__TERMS); + } else { + for (WidthTerm term : widthSpec.getTerms()) { + if (term.getParameter() != null) { + if (!this.target.supportsParameterizedWidths()) { + error( + "Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); - } else { - for (WidthTerm term : widthSpec.getTerms()) { - if (term.getParameter() != null) { - if (!this.target.supportsParameterizedWidths()) { - error("Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getPort() != null) { - // Widths given with `widthof()` are not supported (yet?). - // This feature is currently only used for after delays. - error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); - } else if (term.getCode() != null) { - if (this.target != Target.CPP) { - error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getWidth() < 0) { - error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); - } - } + } + } else if (term.getPort() != null) { + // Widths given with `widthof()` are not supported (yet?). + // This feature is currently only used for after delays. + error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); + } else if (term.getCode() != null) { + if (this.target != Target.CPP) { + error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getWidth() < 0) { + error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); } + } } - - @Check(CheckType.FAST) - public void checkReactorIconAttribute(Reactor reactor) { - var path = AttributeUtils.getIconPath(reactor); - if (path != null) { - var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); - // Check file extension - var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); - var extensionStrart = path.lastIndexOf("."); - var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; - if (!validExtensions.contains(extension.toLowerCase())) { - warning("File extension '" + extension + "' is not supported. Provide any of: " + String.join(", ", validExtensions), - param, Literals.ATTR_PARM__VALUE); - return; - } - - // Check file location - var iconLocation = FileUtil.locateFile(path, reactor.eResource()); - if (iconLocation == null) { - warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); - } - if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) && !(new File(iconLocation.getPath()).exists())) { - warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); - } - } + } + + @Check(CheckType.FAST) + public void checkReactorIconAttribute(Reactor reactor) { + var path = AttributeUtils.getIconPath(reactor); + if (path != null) { + var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); + // Check file extension + var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); + var extensionStrart = path.lastIndexOf("."); + var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; + if (!validExtensions.contains(extension.toLowerCase())) { + warning( + "File extension '" + + extension + + "' is not supported. Provide any of: " + + String.join(", ", validExtensions), + param, + Literals.ATTR_PARM__VALUE); + return; + } + + // Check file location + var iconLocation = FileUtil.locateFile(path, reactor.eResource()); + if (iconLocation == null) { + warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); + } + if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) + && !(new File(iconLocation.getPath()).exists())) { + warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); + } } - - @Check(CheckType.FAST) - public void checkInitialMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); - if (initialModesCount == 0) { - error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); - } else if (initialModesCount > 1) { - reactor.getModes().stream().filter(m -> m.isInitial()).skip(1).forEach(m -> { - error("A modal reactor can only have one initial mode.", - Literals.REACTOR__MODES, reactor.getModes().indexOf(m)); + } + + @Check(CheckType.FAST) + public void checkInitialMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); + if (initialModesCount == 0) { + error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); + } else if (initialModesCount > 1) { + reactor.getModes().stream() + .filter(m -> m.isInitial()) + .skip(1) + .forEach( + m -> { + error( + "A modal reactor can only have one initial mode.", + Literals.REACTOR__MODES, + reactor.getModes().indexOf(m)); }); - } + } + } + } + + @Check(CheckType.FAST) + public void checkModeStateNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var stateVar : mode.getStateVars()) { + if (names.contains(stateVar.getName())) { + error( + String.format( + "Duplicate state variable '%s'. (State variables are currently scoped on" + + " reactor level not modes)", + stateVar.getName()), + stateVar, + Literals.STATE_VAR__NAME); + } + names.add(stateVar.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeStateNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var stateVar : mode.getStateVars()) { - if (names.contains(stateVar.getName())) { - error(String.format("Duplicate state variable '%s'. (State variables are currently scoped on reactor level not modes)", - stateVar.getName()), stateVar, Literals.STATE_VAR__NAME); - } - names.add(stateVar.getName()); - } - } + } + + @Check(CheckType.FAST) + public void checkModeTimerNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var timer : mode.getTimers()) { + if (names.contains(timer.getName())) { + error( + String.format( + "Duplicate Timer '%s'. (Timers are currently scoped on reactor level not" + + " modes)", + timer.getName()), + timer, + Literals.VARIABLE__NAME); + } + names.add(timer.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeTimerNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var timer : mode.getTimers()) { - if (names.contains(timer.getName())) { - error(String.format("Duplicate Timer '%s'. (Timers are currently scoped on reactor level not modes)", - timer.getName()), timer, Literals.VARIABLE__NAME); - } - names.add(timer.getName()); - } - } + } + + @Check(CheckType.FAST) + public void checkModeActionNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var action : mode.getActions()) { + if (names.contains(action.getName())) { + error( + String.format( + "Duplicate Action '%s'. (Actions are currently scoped on reactor level not" + + " modes)", + action.getName()), + action, + Literals.VARIABLE__NAME); + } + names.add(action.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeActionNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var action : mode.getActions()) { - if (names.contains(action.getName())) { - error(String.format("Duplicate Action '%s'. (Actions are currently scoped on reactor level not modes)", - action.getName()), action, Literals.VARIABLE__NAME); - } - names.add(action.getName()); - } - } + } + + @Check(CheckType.FAST) + public void checkModeInstanceNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var instantiation : mode.getInstantiations()) { + if (names.contains(instantiation.getName())) { + error( + String.format( + "Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor" + + " level not modes)", + instantiation.getName()), + instantiation, + Literals.INSTANTIATION__NAME); + } + names.add(instantiation.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeInstanceNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var instantiation : mode.getInstantiations()) { - if (names.contains(instantiation.getName())) { - error(String.format("Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor level not modes)", - instantiation.getName()), instantiation, Literals.INSTANTIATION__NAME); - } - names.add(instantiation.getName()); - } + } + + @Check(CheckType.FAST) + public void checkMissingStateResetInMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var resetModes = new HashSet(); + // Collect all modes that may be reset + for (var m : reactor.getModes()) { + for (var r : m.getReactions()) { + for (var e : r.getEffects()) { + if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { + resetModes.add((Mode) e.getVariable()); } + } } - } - - @Check(CheckType.FAST) - public void checkMissingStateResetInMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var resetModes = new HashSet(); - // Collect all modes that may be reset - for (var m : reactor.getModes()) { - for (var r : m.getReactions()) { - for (var e : r.getEffects()) { - if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { - resetModes.add((Mode) e.getVariable()); - } - } - } + } + for (var m : resetModes) { + // Check state variables in this mode + if (!m.getStateVars().isEmpty()) { + var hasResetReaction = + m.getReactions().stream() + .anyMatch( + r -> + r.getTriggers().stream() + .anyMatch( + t -> + (t instanceof BuiltinTriggerRef + && ((BuiltinTriggerRef) t).getType() + == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + for (var s : m.getStateVars()) { + if (!s.isReset()) { + error( + "State variable is not reset upon mode entry. It is neither marked for" + + " automatic reset nor is there a reset reaction.", + m, + Literals.MODE__STATE_VARS, + m.getStateVars().indexOf(s)); + } } - for (var m : resetModes) { - // Check state variables in this mode - if (!m.getStateVars().isEmpty()) { - var hasResetReaction = m.getReactions().stream().anyMatch( - r -> r.getTriggers().stream().anyMatch( - t -> (t instanceof BuiltinTriggerRef && - ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - for (var s : m.getStateVars()) { - if (!s.isReset()) { - error("State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction.", - m, Literals.MODE__STATE_VARS, m.getStateVars().indexOf(s)); - } - } - } + } + } + // Check state variables in instantiated reactors + if (!m.getInstantiations().isEmpty()) { + for (var i : m.getInstantiations()) { + var error = new LinkedHashSet(); + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty()) { + var check = toCheck.pop(); + checked.add(check); + if (!check.getStateVars().isEmpty()) { + var hasResetReaction = + check.getReactions().stream() + .anyMatch( + r -> + r.getTriggers().stream() + .anyMatch( + t -> + (t instanceof BuiltinTriggerRef + && ((BuiltinTriggerRef) t).getType() + == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + // Add state vars that are not self-resetting to the error + check.getStateVars().stream() + .filter(s -> !s.isReset()) + .forEachOrdered(error::add); } - // Check state variables in instantiated reactors - if (!m.getInstantiations().isEmpty()) { - for (var i : m.getInstantiations()) { - var error = new LinkedHashSet(); - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty()) { - var check = toCheck.pop(); - checked.add(check); - if (!check.getStateVars().isEmpty()) { - var hasResetReaction = check.getReactions().stream().anyMatch( - r -> r.getTriggers().stream().anyMatch( - t -> (t instanceof BuiltinTriggerRef && - ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - // Add state vars that are not self-resetting to the error - check.getStateVars().stream().filter(s -> !s.isReset()).forEachOrdered(error::add); - } - } - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } - } - } - if (!error.isEmpty()) { - error("This reactor contains state variables that are not reset upon mode entry: " - + error.stream().map(e -> e.getName() + " in " - + ASTUtils.getEnclosingReactor(e).getName()).collect(Collectors.joining(", ")) - + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " - + "It is unsafe to instantiate this reactor inside a mode entered with reset.", - m, Literals.MODE__INSTANTIATIONS, - m.getInstantiations().indexOf(i)); - } - } + } + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); } + } + } + if (!error.isEmpty()) { + error( + "This reactor contains state variables that are not reset upon mode entry: " + + error.stream() + .map( + e -> e.getName() + " in " + ASTUtils.getEnclosingReactor(e).getName()) + .collect(Collectors.joining(", ")) + + ".\n" + + "The state variables are neither marked for automatic reset nor have a" + + " dedicated reset reaction. It is unsafe to instantiate this reactor inside" + + " a mode entered with reset.", + m, + Literals.MODE__INSTANTIATIONS, + m.getInstantiations().indexOf(i)); } + } } + } } - - @Check(CheckType.FAST) - public void checkStateResetWithoutInitialValue(StateVar state) { - if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { - error("The state variable can not be automatically reset without an initial value.", state, Literals.STATE_VAR__RESET); - } + } + + @Check(CheckType.FAST) + public void checkStateResetWithoutInitialValue(StateVar state) { + if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { + error( + "The state variable can not be automatically reset without an initial value.", + state, + Literals.STATE_VAR__RESET); } - - @Check(CheckType.FAST) - public void checkUnspecifiedTransitionType(Reaction reaction) { - for (var effect : reaction.getEffects()) { - var variable = effect.getVariable(); - if (variable instanceof Mode) { - // The transition type is always set to default by Xtext. - // Hence, check if there is an explicit node for the transition type in the AST. - var transitionAssignment = NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); - if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. - var mode = (Mode) variable; - // Check if reset or history transition would make a difference. - var makesDifference = !mode.getStateVars().isEmpty() - || !mode.getTimers().isEmpty() - || !mode.getActions().isEmpty() - || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); - if (!makesDifference && !mode.getInstantiations().isEmpty()) { - // Also check instantiated reactors - for (var i : mode.getInstantiations()) { - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty() && !makesDifference) { - var check = toCheck.pop(); - checked.add(check); - - makesDifference |= !check.getModes().isEmpty() - || !ASTUtils.allStateVars(check).isEmpty() - || !ASTUtils.allTimers(check).isEmpty() - || !ASTUtils.allActions(check).isEmpty() - || ASTUtils.allConnections(check).stream().anyMatch(c -> c.getDelay() != null); - - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } - } - } - } - } - if (makesDifference) { - warning("You should specify a transition type! " - + "Reset and history transitions have different effects on this target mode. " - + "Currently, a reset type is implicitly assumed.", - reaction, Literals.REACTION__EFFECTS, reaction.getEffects().indexOf(effect)); - } + } + + @Check(CheckType.FAST) + public void checkUnspecifiedTransitionType(Reaction reaction) { + for (var effect : reaction.getEffects()) { + var variable = effect.getVariable(); + if (variable instanceof Mode) { + // The transition type is always set to default by Xtext. + // Hence, check if there is an explicit node for the transition type in the AST. + var transitionAssignment = + NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); + if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. + var mode = (Mode) variable; + // Check if reset or history transition would make a difference. + var makesDifference = + !mode.getStateVars().isEmpty() + || !mode.getTimers().isEmpty() + || !mode.getActions().isEmpty() + || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); + if (!makesDifference && !mode.getInstantiations().isEmpty()) { + // Also check instantiated reactors + for (var i : mode.getInstantiations()) { + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty() && !makesDifference) { + var check = toCheck.pop(); + checked.add(check); + + makesDifference |= + !check.getModes().isEmpty() + || !ASTUtils.allStateVars(check).isEmpty() + || !ASTUtils.allTimers(check).isEmpty() + || !ASTUtils.allActions(check).isEmpty() + || ASTUtils.allConnections(check).stream() + .anyMatch(c -> c.getDelay() != null); + + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } } + } } + } + if (makesDifference) { + warning( + "You should specify a transition type! " + + "Reset and history transitions have different effects on this target mode. " + + "Currently, a reset type is implicitly assumed.", + reaction, + Literals.REACTION__EFFECTS, + reaction.getEffects().indexOf(effect)); + } } + } + } + } + + ////////////////////////////////////////////////////////////// + //// Public methods. + + /** Return the error reporter for this validator. */ + public ValidatorErrorReporter getErrorReporter() { + return this.errorReporter; + } + + /** Implementation required by xtext to report validation errors. */ + @Override + public ValidationMessageAcceptor getMessageAcceptor() { + return messageAcceptor == null ? this : messageAcceptor; + } + + /** Return a list of error messages for the target declaration. */ + public List getTargetPropertyErrors() { + return this.targetPropertyErrors; + } + + ////////////////////////////////////////////////////////////// + //// Protected methods. + + /** Generate an error message for an AST node. */ + @Override + protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature) { + super.error(message, feature); + } + + ////////////////////////////////////////////////////////////// + //// Private methods. + + /** + * For each input, report a conflict if: 1) the input exists and the type doesn't match; or 2) the + * input has a name clash with variable that is not an input. + * + * @param superVars List of typed variables of a particular kind (i.e., inputs, outputs, or + * actions), found in a super class. + * @param sameKind Typed variables of the same kind, found in the subclass. + * @param allOwn Accumulator of non-conflicting variables incorporated in the subclass. + * @param conflicts Set of variables that are in conflict, to be used by this function to report + * conflicts. + */ + private void checkConflict( + EList superVars, EList sameKind, List allOwn, HashSet conflicts) { + for (T superVar : superVars) { + T match = null; + for (T it : sameKind) { + if (it.getName().equals(superVar.getName())) { + match = it; + break; + } + } + List rest = new ArrayList<>(allOwn); + rest.removeIf(it -> sameKind.contains(it)); + + if ((match != null && superVar.getType() != match.getType()) + || hasNameConflict(superVar, rest)) { + conflicts.add(superVar); + } else { + allOwn.add(superVar); + } + } + } + + /** + * Check the name of a feature for illegal substrings such as reserved identifiers and names with + * double leading underscores. + * + * @param name The name. + * @param feature The feature containing the name (for error reporting). + */ + private void checkName(String name, EStructuralFeature feature) { + + // Raises an error if the string starts with two underscores. + if (name.length() >= 2 && name.substring(0, 2).equals("__")) { + error(UNDERSCORE_MESSAGE + name, feature); } - ////////////////////////////////////////////////////////////// - //// Public methods. - - /** - * Return the error reporter for this validator. - */ - public ValidatorErrorReporter getErrorReporter() { - return this.errorReporter; - } - - /** - * Implementation required by xtext to report validation errors. - */ - @Override - public ValidationMessageAcceptor getMessageAcceptor() { - return messageAcceptor == null ? this : messageAcceptor; - } - - /** - * Return a list of error messages for the target declaration. - */ - public List getTargetPropertyErrors() { - return this.targetPropertyErrors; - } - - ////////////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Generate an error message for an AST node. - */ - @Override - protected void error(java.lang.String message, - org.eclipse.emf.ecore.EStructuralFeature feature) { - super.error(message, feature); - } - - ////////////////////////////////////////////////////////////// - //// Private methods. - - /** - * For each input, report a conflict if: - * 1) the input exists and the type doesn't match; or - * 2) the input has a name clash with variable that is not an input. - * @param superVars List of typed variables of a particular kind (i.e., - * inputs, outputs, or actions), found in a super class. - * @param sameKind Typed variables of the same kind, found in the subclass. - * @param allOwn Accumulator of non-conflicting variables incorporated in the - * subclass. - * @param conflicts Set of variables that are in conflict, to be used by this - * function to report conflicts. - */ - private void checkConflict ( - EList superVars, EList sameKind, List allOwn, HashSet conflicts - ) { - for (T superVar : superVars) { - T match = null; - for (T it : sameKind) { - if (it.getName().equals(superVar.getName())) { - match = it; - break; - } - } - List rest = new ArrayList<>(allOwn); - rest.removeIf(it -> sameKind.contains(it)); + if (this.target.isReservedIdent(name)) { + error(RESERVED_MESSAGE + name, feature); + } - if ((match != null && superVar.getType() != match.getType()) || hasNameConflict(superVar, rest)) { - conflicts.add(superVar); - } else { - allOwn.add(superVar); - } - } + if (this.target == Target.TS) { + // "actions" is a reserved word within a TS reaction + if (name.equals("actions")) { + error(ACTIONS_MESSAGE + name, feature); + } + } + } + + /** + * Check that the initializer is compatible with the type. Note that if the type is inferred it + * will necessarily be compatible so this method is not harmful. + */ + public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { + if (init == null) { + return; } - /** - * Check the name of a feature for illegal substrings such as reserved - * identifiers and names with double leading underscores. - * @param name The name. - * @param feature The feature containing the name (for error reporting). - */ - private void checkName(String name, EStructuralFeature feature) { + // TODO: + // type is list => init is list + // type is fixed with size n => init is fixed with size n + // Specifically for C: list can only be literal or time lists - // Raises an error if the string starts with two underscores. - if (name.length() >= 2 && name.substring(0, 2).equals("__")) { - error(UNDERSCORE_MESSAGE + name, feature); + if (type.isTime) { + if (type.isList) { + // list of times + var exprs = init.getExprs(); + if (exprs.isEmpty()) { + error("Expected at least one time value.", feature); + return; } - - if (this.target.isReservedIdent(name)) { - error(RESERVED_MESSAGE + name, feature); + if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { + exprs = ((BracedListExpression) exprs.get(0)).getItems(); } - - if (this.target == Target.TS) { - // "actions" is a reserved word within a TS reaction - if (name.equals("actions")) { - error(ACTIONS_MESSAGE + name, feature); - } + for (var component : exprs) { + checkExpressionIsTime(component, feature); } + } else { + checkExpressionIsTime(init, feature); + } } + } - - /** - * Check that the initializer is compatible with the type. - * Note that if the type is inferred it will necessarily be compatible - * so this method is not harmful. - */ - public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { - if (init == null) { - return; - } - - // TODO: - // type is list => init is list - // type is fixed with size n => init is fixed with size n - // Specifically for C: list can only be literal or time lists - - if (type.isTime) { - if (type.isList) { - // list of times - var exprs = init.getExprs(); - if (exprs.isEmpty()) { - error("Expected at least one time value.", feature); - return; - } - if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { - exprs = ((BracedListExpression) exprs.get(0)).getItems(); - } - for (var component : exprs) { - checkExpressionIsTime(component, feature); - } - } else { - checkExpressionIsTime(init, feature); - } - } + private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { + if (init == null) { + return; } - private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { - if (init == null) { - return; - } - - if (init.getExprs().size() != 1) { - error("Expected exactly one time value.", feature); - } else { - checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); - } + if (init.getExprs().size() != 1) { + error("Expected exactly one time value.", feature); + } else { + checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); } + } - private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { - if (value == null || value instanceof Time) { - return; - } - - if (value instanceof ParameterReference) { - if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) - && target.requiresTypes) { - error("Referenced parameter is not of time type.", feature); - } - return; - } else if (value instanceof Literal) { - if (ASTUtils.isZero(((Literal) value).getLiteral())) { - return; - } - - if (ASTUtils.isInteger(((Literal) value).getLiteral())) { - error("Missing time unit.", feature); - return; - } - // fallthrough - } - - error("Invalid time value.", feature); + private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { + if (value == null || value instanceof Time) { + return; } - /** - * Return the number of main or federated reactors declared. - * - * @param iter An iterator over all objects in the resource. - */ - private int countMainOrFederated(TreeIterator iter) { - int nMain = 0; - while (iter.hasNext()) { - EObject obj = iter.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor r = (Reactor) obj; - if (r.isMain() || r.isFederated()) { - nMain++; - } - } - return nMain; - } - - /** - * Report whether a given reactor has dependencies on a cyclic - * instantiation pattern. This means the reactor has an instantiation - * in it -- directly or in one of its contained reactors -- that is - * self-referential. - * @param reactor The reactor definition to find out whether it has any - * dependencies on cyclic instantiations. - * @param cycleSet The set of all reactors that are part of an - * instantiation cycle. - * @param visited The set of nodes already visited in this graph traversal. - */ - private boolean dependsOnCycle( - Reactor reactor, Set cycleSet, Set visited - ) { - Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); - if (visited.contains(reactor)) { - return false; - } else { - visited.add(reactor); - for (Reactor it : origins) { - if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { - // Reached a cycle. - return true; - } - } - } - return false; - } - - /** - * Report whether the name of the given element matches any variable in - * the ones to check against. - * @param element The element to compare against all variables in the given iterable. - * @param toCheckAgainst Iterable variables to compare the given element against. - */ - private boolean hasNameConflict(Variable element, - Iterable toCheckAgainst) { - int numNameConflicts = 0; - for (Variable it : toCheckAgainst) { - if (it.getName().equals(element.getName())) { - numNameConflicts++; - } - } - return numNameConflicts > 0; + if (value instanceof ParameterReference) { + if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) + && target.requiresTypes) { + error("Referenced parameter is not of time type.", feature); + } + return; + } else if (value instanceof Literal) { + if (ASTUtils.isZero(((Literal) value).getLiteral())) { + return; + } + + if (ASTUtils.isInteger(((Literal) value).getLiteral())) { + error("Missing time unit.", feature); + return; + } + // fallthrough } - /** - * Return true if target is C or a C-based target like CCpp. - */ - private boolean isCBasedTarget() { - return (this.target == Target.C || this.target == Target.CCPP); + error("Invalid time value.", feature); + } + + /** + * Return the number of main or federated reactors declared. + * + * @param iter An iterator over all objects in the resource. + */ + private int countMainOrFederated(TreeIterator iter) { + int nMain = 0; + while (iter.hasNext()) { + EObject obj = iter.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor r = (Reactor) obj; + if (r.isMain() || r.isFederated()) { + nMain++; + } } - - /** - * Report whether a given imported reactor is used in this resource or not. - * @param reactor The imported reactor to check whether it is used. - */ - private boolean isUnused(ImportedReactor reactor) { - TreeIterator instantiations = reactor.eResource().getAllContents(); - TreeIterator subclasses = reactor.eResource().getAllContents(); - - boolean instantiationsCheck = true; - while (instantiations.hasNext() && instantiationsCheck) { - EObject obj = instantiations.next(); - if (!(obj instanceof Instantiation)) { - continue; - } - Instantiation inst = (Instantiation) obj; - instantiationsCheck &= (inst.getReactorClass() != reactor && inst.getReactorClass() != reactor.getReactorClass()); - } - - boolean subclassesCheck = true; - while (subclasses.hasNext() && subclassesCheck) { - EObject obj = subclasses.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor subclass = (Reactor) obj; - for (ReactorDecl decl : subclass.getSuperClasses()) { - subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); - } - } - return instantiationsCheck && subclassesCheck; + return nMain; + } + + /** + * Report whether a given reactor has dependencies on a cyclic instantiation pattern. This means + * the reactor has an instantiation in it -- directly or in one of its contained reactors -- that + * is self-referential. + * + * @param reactor The reactor definition to find out whether it has any dependencies on cyclic + * instantiations. + * @param cycleSet The set of all reactors that are part of an instantiation cycle. + * @param visited The set of nodes already visited in this graph traversal. + */ + private boolean dependsOnCycle(Reactor reactor, Set cycleSet, Set visited) { + Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); + if (visited.contains(reactor)) { + return false; + } else { + visited.add(reactor); + for (Reactor it : origins) { + if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { + // Reached a cycle. + return true; + } + } } - - /** - * Return true if the two types match. Unfortunately, xtext does not - * seem to create a suitable equals() method for Type, so we have to - * do this manually. - */ - private boolean sameType(Type type1, Type type2) { - if (type1 == null) { - return type2 == null; - } - if (type2 == null) { - return type1 == null; - } - // Most common case first. - if (type1.getId() != null) { - if (type1.getStars() != null) { - if (type2.getStars() == null) return false; - if (type1.getStars().size() != type2.getStars().size()) return false; - } - return (type1.getId().equals(type2.getId())); - } - - // Type specification in the grammar is: - // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); - if (type1.isTime()) { - if (!type2.isTime()) return false; - // Ignore the arraySpec because that is checked when connection - // is checked for balance. - return true; - } - // Type must be given in a code body - return type1.getCode().getBody().equals(type2.getCode().getBody()); + return false; + } + + /** + * Report whether the name of the given element matches any variable in the ones to check against. + * + * @param element The element to compare against all variables in the given iterable. + * @param toCheckAgainst Iterable variables to compare the given element against. + */ + private boolean hasNameConflict(Variable element, Iterable toCheckAgainst) { + int numNameConflicts = 0; + for (Variable it : toCheckAgainst) { + if (it.getName().equals(element.getName())) { + numNameConflicts++; + } + } + return numNameConflicts > 0; + } + + /** Return true if target is C or a C-based target like CCpp. */ + private boolean isCBasedTarget() { + return (this.target == Target.C || this.target == Target.CCPP); + } + + /** + * Report whether a given imported reactor is used in this resource or not. + * + * @param reactor The imported reactor to check whether it is used. + */ + private boolean isUnused(ImportedReactor reactor) { + TreeIterator instantiations = reactor.eResource().getAllContents(); + TreeIterator subclasses = reactor.eResource().getAllContents(); + + boolean instantiationsCheck = true; + while (instantiations.hasNext() && instantiationsCheck) { + EObject obj = instantiations.next(); + if (!(obj instanceof Instantiation)) { + continue; + } + Instantiation inst = (Instantiation) obj; + instantiationsCheck &= + (inst.getReactorClass() != reactor + && inst.getReactorClass() != reactor.getReactorClass()); } - ////////////////////////////////////////////////////////////// - //// Private fields. - - /** The error reporter. */ - private ValidatorErrorReporter errorReporter - = new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); - - /** Helper class containing information about the model. */ - private ModelInfo info = new ModelInfo(); - - @Inject(optional = true) - private ValidationMessageAcceptor messageAcceptor; - - /** The declared target. */ - private Target target; - - private List targetPropertyErrors = new ArrayList<>(); - - private List targetPropertyWarnings = new ArrayList<>(); - - ////////////////////////////////////////////////////////////// - //// Private static constants. - - private static String ACTIONS_MESSAGE - = "\"actions\" is a reserved word for the TypeScript target for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " - + "and reactor instantiation): "; - - private static String HOST_OR_FQN_REGEX - = "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; - - /** - * Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). - */ - private static String IPV4_REGEX = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + - "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; - - /** - * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), - * with minor adjustment to allow up to six IPV6 segments (without truncation) in front - * of an embedded IPv4-address. - **/ - private static String IPV6_REGEX = - "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + - "([0-9a-fA-F]{1,4}:){1,7}:|" + - "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + - "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + - "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + - "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + - "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + - "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + - ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + - "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + - "::(ffff(:0{1,4}){0,1}:){0,1}" + IPV4_REGEX + "|" + - "([0-9a-fA-F]{1,4}:){1,4}:" + IPV4_REGEX + "|" + - "([0-9a-fA-F]{1,4}:){1,6}" + IPV4_REGEX + ")"; - - private static String RESERVED_MESSAGE = "Reserved words in the target language are not allowed for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation): "; - - private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); - - private static String UNDERSCORE_MESSAGE = "Names of objects (inputs, outputs, actions, timers, parameters, " - + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; - - private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; + boolean subclassesCheck = true; + while (subclasses.hasNext() && subclassesCheck) { + EObject obj = subclasses.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor subclass = (Reactor) obj; + for (ReactorDecl decl : subclass.getSuperClasses()) { + subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); + } + } + return instantiationsCheck && subclassesCheck; + } + + /** + * Return true if the two types match. Unfortunately, xtext does not seem to create a suitable + * equals() method for Type, so we have to do this manually. + */ + private boolean sameType(Type type1, Type type2) { + if (type1 == null) { + return type2 == null; + } + if (type2 == null) { + return type1 == null; + } + // Most common case first. + if (type1.getId() != null) { + if (type1.getStars() != null) { + if (type2.getStars() == null) return false; + if (type1.getStars().size() != type2.getStars().size()) return false; + } + return (type1.getId().equals(type2.getId())); + } -} \ No newline at end of file + // Type specification in the grammar is: + // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' + // typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); + if (type1.isTime()) { + if (!type2.isTime()) return false; + // Ignore the arraySpec because that is checked when connection + // is checked for balance. + return true; + } + // Type must be given in a code body + return type1.getCode().getBody().equals(type2.getCode().getBody()); + } + + ////////////////////////////////////////////////////////////// + //// Private fields. + + /** The error reporter. */ + private ValidatorErrorReporter errorReporter = + new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); + + /** Helper class containing information about the model. */ + private ModelInfo info = new ModelInfo(); + + @Inject(optional = true) + private ValidationMessageAcceptor messageAcceptor; + + /** The declared target. */ + private Target target; + + private List targetPropertyErrors = new ArrayList<>(); + + private List targetPropertyWarnings = new ArrayList<>(); + + ////////////////////////////////////////////////////////////// + //// Private static constants. + + private static String ACTIONS_MESSAGE = + "\"actions\" is a reserved word for the TypeScript target for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " + + "and reactor instantiation): "; + + private static String HOST_OR_FQN_REGEX = + "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; + + /** Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). */ + private static String IPV4_REGEX = + "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; + + /** + * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), with minor + * adjustment to allow up to six IPV6 segments (without truncation) in front of an embedded + * IPv4-address. + */ + private static String IPV6_REGEX = + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,7}:|" + + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + + "::(ffff(:0{1,4}){0,1}:){0,1}" + + IPV4_REGEX + + "|" + + "([0-9a-fA-F]{1,4}:){1,4}:" + + IPV4_REGEX + + "|" + + "([0-9a-fA-F]{1,4}:){1,6}" + + IPV4_REGEX + + ")"; + + private static String RESERVED_MESSAGE = + "Reserved words in the target language are not allowed for objects (inputs, outputs, actions," + + " timers, parameters, state, reactor definitions, and reactor instantiation): "; + + private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); + + private static String UNDERSCORE_MESSAGE = + "Names of objects (inputs, outputs, actions, timers, parameters, " + + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; + + private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; +} diff --git a/test/Python/src/PyWatchdog.lf b/test/Python/src/PyWatchdog.lf deleted file mode 100644 index a89cf0d7de..0000000000 --- a/test/Python/src/PyWatchdog.lf +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Test watchdog. - * This test starts a watchdog timer of 150ms every 100ms. - * Half the time, it then sleeps after starting the watchdog so that - * the watchdog expires. There should be a total of five watchdog - * expirations. - * @author Benjamin Asch - * @author Edward A. Lee - */ - -target Python { - timeout: 1100ms, - threading: true -} - -reactor Watcher(timeout(150 ms)) { - timer t(100 ms, 100 ms) // Offset ameliorates startup time. - output d // Produced if watchdog triggers. - state alternating(False) - state count(0) - - watchdog poodle(timeout) {= - p = lf_time_physical_elapsed() - lf_time_logical_elapsed() - lf_print("Watchdog timed out! Lag: "+p+" (too late by "+(p - self.timeout)+" ns)") - self.count += 1 - =} - - reaction(t) -> poodle, d {= - lf_watchdog_start(poodle, 0) - lf_print("Watchdog started at physical time "+lf_time_physical_elapsed()) - lf_print("Will expire at "+lf_time_logical_elapsed() + self.timeout) - if (self.alternating) { - lf_sleep(160 ms) - } - self.alternating = not self.alternating - =} - - reaction(poodle) -> d {= - lf_print("Reaction poodle was called.") - d.set(1) - =} - - reaction(shutdown) -> poodle {= - _lf_watchdog_stop(poodle) - if (self.count != 5) { - lf_print_error_and_exit("Watchdog expired "+self.count+" times. Expected 5.") - } - =} -} - -main reactor { - logical action a - state count(0) - w = new Watcher() - - reaction(w.d) {= - lf_print("*** Watcher reactor produced an output.") - self.count += 1 - =} - - reaction(shutdown) {= - if (self.count != 5) { - lf_print_error_and_exit("Watchdog produced output "+self.count+" times. Expected 5.") - } - =} -} From 02b02e56af7a952a903dc9e85091c57c6c1952b2 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Fri, 21 Apr 2023 17:01:03 +0900 Subject: [PATCH 146/709] Revert ci test changes --- .github/workflows/c-tests.yml | 3 --- .github/workflows/ci.yml | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index ed1ba0d784..79c66d8ab4 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -45,9 +45,6 @@ jobs: brew install coreutils brew install openssl brew link openssl --force - echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/runner/.bash_profile - export LDFLAGS="-L/usr/local/opt/openssl@3/lib" - export CPPFLAGS="-I/usr/local/opt/openssl@3/include" if: ${{ runner.os == 'macOS' }} - name: Install RTI uses: ./.github/actions/install-rti diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64a524ff8f..f6dd56ae40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth-fail-test + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master needs: cancel # Run the C Arduino integration tests. @@ -77,7 +77,7 @@ jobs: # Run the CCpp integration tests. ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth-fail-test + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master with: use-cpp: true needs: cancel From 37936c5072359955b1dbc040039147975d64e657 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Fri, 21 Apr 2023 17:01:56 +0900 Subject: [PATCH 147/709] Delete ssh --- .github/workflows/c-tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 79c66d8ab4..b02775ad65 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -69,5 +69,4 @@ jobs: fail_ci_if_error: false verbose: true if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI - - name: Setup upterm session - uses: lhotari/action-upterm@v1 \ No newline at end of file + \ No newline at end of file From 42cc3fd9e3a70b86262edfaa752920ead5935e5b Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Fri, 21 Apr 2023 17:02:44 +0900 Subject: [PATCH 148/709] Remove unneeded line --- .github/workflows/c-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index b02775ad65..0764128a1b 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -69,4 +69,3 @@ jobs: fail_ci_if_error: false verbose: true if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI - \ No newline at end of file From f2b3eadaca7d82be3f6829eeb1345ff38dcbb2b1 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Fri, 21 Apr 2023 17:12:00 +0900 Subject: [PATCH 149/709] Checkout reactor-c auth-fail-test branch --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 9d939578e0..6d0854a9eb 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 9d939578e095029deab5153326362555fad0382b +Subproject commit 6d0854a9ebb0ff06a774e28a12dcef0118037f06 From 604a697cf3a29f62643beabf95897ab2df6e53b7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 21 Apr 2023 11:49:36 +0200 Subject: [PATCH 150/709] delete build-lfc --- bin/build-lfc | 1 - 1 file changed, 1 deletion(-) delete mode 120000 bin/build-lfc diff --git a/bin/build-lfc b/bin/build-lfc deleted file mode 120000 index 55c54a4b7a..0000000000 --- a/bin/build-lfc +++ /dev/null @@ -1 +0,0 @@ -../lib/scripts/build.sh \ No newline at end of file From 520d5330bee0cd4b93fa7eb2e96b37a7635d561b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 21 Apr 2023 11:50:27 +0200 Subject: [PATCH 151/709] remove buildLfc gradle task --- org.lflang/build.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/org.lflang/build.gradle b/org.lflang/build.gradle index 00410d16f5..5155c0a6e2 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/build.gradle @@ -174,12 +174,6 @@ task buildAll() { mainClassName = 'org.lflang.cli.Lfc' } -// define buildLfc as an alias to buildAll -task buildLfc { - dependsOn buildAll - doFirst({{logger.warn("The buildLfc task is deprecated! Please use buildAll instead.")}}) -} - task jarCliTools(type: ShadowJar) { manifest { attributes('Main-Class': 'org.lflang.cli.Lfc') From 57a1bbaf71de0fcde144fcdc805cc6bf1fc32c41 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 21 Apr 2023 18:06:41 +0200 Subject: [PATCH 152/709] Added LF_SOURCE_DIRECTORY and LF_FILE_SEPARATOR --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 06095f553d..43a3568631 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -25,6 +25,7 @@ package org.lflang.generator.c; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -230,6 +231,8 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f fileConfig.binPath ) ), + "-DLF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\"", // Do not convert to Unix path. + "-DLF_FILE_SEPARATOR=\"" + File.separator + "\"", FileUtil.toUnixString(fileConfig.getSrcGenPath()) )); From 1f86008ea9b321e057af51b9aa5256590c578515 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 21 Apr 2023 10:36:36 -0700 Subject: [PATCH 153/709] updating reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ff3c84c36b..7dcdb7dfdb 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ff3c84c36b2d7fbcbe09fafa577ec94f75194e83 +Subproject commit 7dcdb7dfdbc065c59fe1372779d5e0606dccda30 From 1493800e22e4aa007e6ffadb25706696bd08d7d3 Mon Sep 17 00:00:00 2001 From: Benjamin Asch Date: Fri, 21 Apr 2023 10:38:51 -0700 Subject: [PATCH 154/709] fixed invocation of watchdog_stop in watchdog test --- test/C/src/Watchdog.lf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index 5d2c87b724..e40157a9e6 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -6,8 +6,7 @@ * @author Edward A. Lee */ target C { - timeout: 1100 ms, - fast: false + timeout: 1100 ms } reactor Watcher(timeout: time = 150 ms) { @@ -39,8 +38,7 @@ reactor Watcher(timeout: time = 150 ms) { =} reaction(shutdown) -> poodle {= - // FIXME: There needs to be an lf_watchdog_stop() defined. - _lf_watchdog_stop(poodle); + lf_watchdog_stop(poodle); if (self->count != 5) { lf_print_error_and_exit("Watchdog expired %d times. Expected 5.", self->count); } From dd934257cefa42c268c15d51bed3d0477ef33cc3 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 22 Apr 2023 01:06:49 +0200 Subject: [PATCH 155/709] Align to reactor-c file-access branch --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 42a87b1b9c..c75d29ec9e 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 42a87b1b9cb678ab9170dbf800019bcbeb80c61f +Subproject commit c75d29ec9e600b428db78dc5ead63b49722cd7b9 From fad460269503802f255a857802591b38b4b8e7c2 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 22 Apr 2023 14:06:11 +0900 Subject: [PATCH 156/709] Check if os.type is working --- .github/workflows/c-tests.yml | 2 ++ org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 0764128a1b..37f0c2bed3 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -49,6 +49,8 @@ jobs: - name: Install RTI uses: ./.github/actions/install-rti if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} + - name: Setup upterm session + uses: lhotari/action-upterm@v1 - name: Perform tests for C target with default scheduler run: | ./gradlew test --tests org.lflang.tests.runtime.CTest.* diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 3f5eb4a5b7..0028064641 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -223,6 +223,8 @@ CodeBuilder generateCMakeCode( if(targetConfig.auth) { // If security is requested, add the auth option. var osName = System.getProperty("os.name").toLowerCase(); + System.out.println(osName); + System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); // if platform target was set, use given platform instead if (targetConfig.platformOptions.platform != Platform.AUTO) { osName = targetConfig.platformOptions.platform.toString(); From 9e67b93c131aa49011fcad840f3f3d42c372fb98 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 22 Apr 2023 14:19:13 +0900 Subject: [PATCH 157/709] Change pointing ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6dd56ae40..7f3da5fe92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth-fail-test needs: cancel # Run the C Arduino integration tests. From 6b9eed2718eee0add7e006d86a74a4a32ec83a59 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 22 Apr 2023 07:38:19 +0200 Subject: [PATCH 158/709] Escape Windows file separator --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 43a3568631..507c4f45d3 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -223,6 +223,8 @@ static Stream cmakeCompileDefinitions(TargetConfig targetConfig) { private static List cmakeOptions(TargetConfig targetConfig, FileConfig fileConfig) { List arguments = new ArrayList<>(); cmakeCompileDefinitions(targetConfig).forEachOrdered(arguments::add); + String separator = File.separator; + if (separator.equals("\\")) separator = "\\\\"; arguments.addAll(List.of( "-DCMAKE_BUILD_TYPE=" + ((targetConfig.cmakeBuildType!=null) ? targetConfig.cmakeBuildType.toString() : "Release"), "-DCMAKE_INSTALL_PREFIX=" + FileUtil.toUnixString(fileConfig.getOutPath()), @@ -232,7 +234,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f ) ), "-DLF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\"", // Do not convert to Unix path. - "-DLF_FILE_SEPARATOR=\"" + File.separator + "\"", + "-DLF_FILE_SEPARATOR=\"" + separator + "\"", FileUtil.toUnixString(fileConfig.getSrcGenPath()) )); From 68b0090184593e0aa286a3589d3a639f9cae272b Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Sat, 22 Apr 2023 14:47:46 +0900 Subject: [PATCH 159/709] Remove ci test changes --- .github/workflows/c-tests.yml | 2 -- .github/workflows/ci.yml | 2 +- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 2 -- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 37f0c2bed3..0764128a1b 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -49,8 +49,6 @@ jobs: - name: Install RTI uses: ./.github/actions/install-rti if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - - name: Setup upterm session - uses: lhotari/action-upterm@v1 - name: Perform tests for C target with default scheduler run: | ./gradlew test --tests org.lflang.tests.runtime.CTest.* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f3da5fe92..f6dd56ae40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth-fail-test + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master needs: cancel # Run the C Arduino integration tests. diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 6d0854a9eb..f344f55e67 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6d0854a9ebb0ff06a774e28a12dcef0118037f06 +Subproject commit f344f55e678d2eb4d7a40eb4725ea2dcc3baf897 diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 0028064641..3f5eb4a5b7 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -223,8 +223,6 @@ CodeBuilder generateCMakeCode( if(targetConfig.auth) { // If security is requested, add the auth option. var osName = System.getProperty("os.name").toLowerCase(); - System.out.println(osName); - System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); // if platform target was set, use given platform instead if (targetConfig.platformOptions.platform != Platform.AUTO) { osName = targetConfig.platformOptions.platform.toString(); From 483bffe088454dae5d74d5bc23ad24556bf042e1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 23 Apr 2023 08:45:43 +0200 Subject: [PATCH 160/709] Put LF_SOURCE_DIRECTORY definition in cmake file for federations --- .../org/lflang/federated/extensions/CExtensionUtils.java | 5 +++++ org.lflang/src/org/lflang/generator/c/CCompiler.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 124ffefb4f..2bf74c3176 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -358,6 +358,11 @@ public static void generateCMakeInclude( CodeBuilder cmakeIncludeCode = new CodeBuilder(); cmakeIncludeCode.pr(generateSerializationCMakeExtension(federate)); + cmakeIncludeCode.pr( + "add_compile_definitions(LF_SOURCE_DIRECTORY=\"" + + fileConfig.srcPath + + "\")" + ); try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) { srcWriter.write(cmakeIncludeCode.getCode()); diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 507c4f45d3..93d3ea3244 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -233,10 +233,16 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f fileConfig.binPath ) ), - "-DLF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\"", // Do not convert to Unix path. "-DLF_FILE_SEPARATOR=\"" + separator + "\"", FileUtil.toUnixString(fileConfig.getSrcGenPath()) )); + // Add #define for source file directory. + // Do not do this for federated programs because for those, the definition is put + // into the cmake file (and fileConfig.srcPath is the wrong directory anyway). + if (!fileConfig.srcPath.toString().contains("fed-gen")) { + // Do not convert to Unix path + arguments.add("-DLF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\""); + } if (GeneratorUtils.isHostWindows()) { arguments.add("-DCMAKE_SYSTEM_VERSION=\"10.0\""); From ddacb09bae7273d7cec3c77bcbcd7758467053f1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 23 Apr 2023 08:46:49 +0200 Subject: [PATCH 161/709] Align reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c75d29ec9e..2c4ee46d63 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c75d29ec9e600b428db78dc5ead63b49722cd7b9 +Subproject commit 2c4ee46d63da73afb1516233120651560d5458d1 From c0657d34751b848f2d23591b59cf1360eb233226 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 23 Apr 2023 09:00:21 +0200 Subject: [PATCH 162/709] Include clock-sync.h so target parameters are supported --- org.lflang/src/org/lflang/federated/extensions/CExtension.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index 4698c2eb84..8a69e979c6 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -498,6 +498,7 @@ public String generatePreamble( includes.pr("#include \"core/federated/federate.h\""); includes.pr("#include \"core/federated/net_common.h\""); includes.pr("#include \"core/federated/net_util.h\""); + includes.pr("#include \"core/federated/clock-sync.h\""); includes.pr("#include \"core/threaded/reactor_threaded.h\""); includes.pr("#include \"core/utils/util.h\""); includes.pr("extern federate_instance_t _fed;"); From 729a2a44b53d0d42f0de4a15c002a26ac4c4e230 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Wed, 26 Apr 2023 11:02:52 +0200 Subject: [PATCH 163/709] Made a proper test --- test/C/src/FileReader.lf | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/C/src/FileReader.lf diff --git a/test/C/src/FileReader.lf b/test/C/src/FileReader.lf new file mode 100644 index 0000000000..b1a1d177c7 --- /dev/null +++ b/test/C/src/FileReader.lf @@ -0,0 +1,44 @@ +/** + * Test reading a file at a location relative to the source file. + */ +target C +reactor Source { + output out:char* // Use char*, not string, so memory is freed. + reaction(startup) -> out {= + char* file_path = + LF_SOURCE_DIRECTORY + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + lf_set(out, buffer); + =} +} +main reactor { + preamble {= + #include + =} + s = new Source() + reaction(s.out) {= + printf("Received: %s\n", s.out->value); + if (strcmp("Hello World", s.out->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} +} \ No newline at end of file From fdf1b896986ac4faae18bc2abe2d565e2def626b Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Wed, 26 Apr 2023 11:04:39 +0200 Subject: [PATCH 164/709] Aligned reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- test/C/src/federated/FederatedFileReader.lf | 54 +++++++++++++++++++++ test/C/src/lib/FileReader.txt | 1 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 test/C/src/federated/FederatedFileReader.lf create mode 100644 test/C/src/lib/FileReader.txt diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 2c4ee46d63..2f0fdad753 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2c4ee46d63da73afb1516233120651560d5458d1 +Subproject commit 2f0fdad7535a7f639f421ac8bc5eec2a159df34c diff --git a/test/C/src/federated/FederatedFileReader.lf b/test/C/src/federated/FederatedFileReader.lf new file mode 100644 index 0000000000..15eb451c27 --- /dev/null +++ b/test/C/src/federated/FederatedFileReader.lf @@ -0,0 +1,54 @@ +/** + * Test reading a file at a location relative to the source file. + */ +target C { + timeout: 0s +} +reactor Source { + output out:char* // Use char*, not string, so memory is freed. + reaction(startup) -> out {= + char* file_path = + LF_SOURCE_DIRECTORY + LF_FILE_SEPARATOR ".." + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + // For federated version, have to use lf_set_array so array size is know + // to the serializer. + lf_set_array(out, buffer, file_size + 1); + =} +} +reactor Check { + preamble {= + #include + =} + input in:char* + reaction(in) {= + printf("Received: %s\n", in->value); + if (strcmp("Hello World", in->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} +} +federated reactor { + s = new Source() + c = new Check() + s.out -> c.in +} \ No newline at end of file diff --git a/test/C/src/lib/FileReader.txt b/test/C/src/lib/FileReader.txt new file mode 100644 index 0000000000..5e1c309dae --- /dev/null +++ b/test/C/src/lib/FileReader.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file From c33a75b9492b841910025d1d700db1efceb2d0e3 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Wed, 26 Apr 2023 11:19:23 +0200 Subject: [PATCH 165/709] Formatted tests --- test/C/src/FileReader.lf | 16 +++++++++------- test/C/src/federated/FederatedFileReader.lf | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/test/C/src/FileReader.lf b/test/C/src/FileReader.lf index b1a1d177c7..10be772fb7 100644 --- a/test/C/src/FileReader.lf +++ b/test/C/src/FileReader.lf @@ -1,15 +1,15 @@ -/** - * Test reading a file at a location relative to the source file. - */ +/** Test reading a file at a location relative to the source file. */ target C + reactor Source { - output out:char* // Use char*, not string, so memory is freed. + output out: char* // Use char*, not string, so memory is freed. + reaction(startup) -> out {= char* file_path = LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; - + FILE* file = fopen(file_path, "rb"); if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); @@ -26,19 +26,21 @@ reactor Source { fread(buffer, file_size, 1, file); buffer[file_size] = '\0'; fclose(file); - + lf_set(out, buffer); =} } + main reactor { preamble {= #include =} s = new Source() + reaction(s.out) {= printf("Received: %s\n", s.out->value); if (strcmp("Hello World", s.out->value) != 0) { lf_print_error_and_exit("Expected 'Hello World'"); } =} -} \ No newline at end of file +} diff --git a/test/C/src/federated/FederatedFileReader.lf b/test/C/src/federated/FederatedFileReader.lf index 15eb451c27..6ba2da763f 100644 --- a/test/C/src/federated/FederatedFileReader.lf +++ b/test/C/src/federated/FederatedFileReader.lf @@ -1,18 +1,18 @@ -/** - * Test reading a file at a location relative to the source file. - */ +/** Test reading a file at a location relative to the source file. */ target C { - timeout: 0s + timeout: 0 s } + reactor Source { - output out:char* // Use char*, not string, so memory is freed. + output out: char* // Use char*, not string, so memory is freed. + reaction(startup) -> out {= char* file_path = LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR ".." LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; - + FILE* file = fopen(file_path, "rb"); if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); @@ -29,17 +29,19 @@ reactor Source { fread(buffer, file_size, 1, file); buffer[file_size] = '\0'; fclose(file); - + // For federated version, have to use lf_set_array so array size is know // to the serializer. lf_set_array(out, buffer, file_size + 1); =} } + reactor Check { preamble {= #include =} - input in:char* + input in: char* + reaction(in) {= printf("Received: %s\n", in->value); if (strcmp("Hello World", in->value) != 0) { @@ -47,8 +49,9 @@ reactor Check { } =} } + federated reactor { s = new Source() c = new Check() s.out -> c.in -} \ No newline at end of file +} From 6f3dd1fde2743691c807d853a3a5e185c60bbb0e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 05:57:24 +0200 Subject: [PATCH 166/709] Extra quoting attempt to make Windows work --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 93d3ea3244..248a4b929a 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -224,7 +224,11 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f List arguments = new ArrayList<>(); cmakeCompileDefinitions(targetConfig).forEachOrdered(arguments::add); String separator = File.separator; - if (separator.equals("\\")) separator = "\\\\"; + String maybeQuote = ""; // Windows seems to require extra level of quoting. + if (separator.equals("\\")) { + separator = "\\\\"; + maybeQuote = "\\\""; + } arguments.addAll(List.of( "-DCMAKE_BUILD_TYPE=" + ((targetConfig.cmakeBuildType!=null) ? targetConfig.cmakeBuildType.toString() : "Release"), "-DCMAKE_INSTALL_PREFIX=" + FileUtil.toUnixString(fileConfig.getOutPath()), @@ -233,7 +237,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f fileConfig.binPath ) ), - "-DLF_FILE_SEPARATOR=\"" + separator + "\"", + "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"", FileUtil.toUnixString(fileConfig.getSrcGenPath()) )); // Add #define for source file directory. @@ -241,7 +245,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f // into the cmake file (and fileConfig.srcPath is the wrong directory anyway). if (!fileConfig.srcPath.toString().contains("fed-gen")) { // Do not convert to Unix path - arguments.add("-DLF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\""); + arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + fileConfig.srcPath + maybeQuote + "\""); } if (GeneratorUtils.isHostWindows()) { From c9fbd4622ce0e0ab595968e870850f729aa5a975 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 06:07:59 +0200 Subject: [PATCH 167/709] Align to reactor-c main --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index f344f55e67..e363b14648 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f344f55e678d2eb4d7a40eb4725ea2dcc3baf897 +Subproject commit e363b146486e07d1593ba05746cc9b8b5c4df643 From 8c91a380cd4297fce6624d536707f2bbd4b3daab Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 06:49:30 +0200 Subject: [PATCH 168/709] Aligned to reactor-c/main --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 2f0fdad753..75ddd1d4a9 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2f0fdad7535a7f639f421ac8bc5eec2a159df34c +Subproject commit 75ddd1d4a9cfab83639730863f9d31eb245cb61f From 78b028e36879e46c631fda275308c45d5f287bde Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 08:08:15 +0200 Subject: [PATCH 169/709] Next attempt to get Windows to work --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 248a4b929a..64e92bb65a 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -238,7 +238,6 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f ) ), "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"", - FileUtil.toUnixString(fileConfig.getSrcGenPath()) )); // Add #define for source file directory. // Do not do this for federated programs because for those, the definition is put @@ -247,6 +246,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f // Do not convert to Unix path arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + fileConfig.srcPath + maybeQuote + "\""); } + arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); if (GeneratorUtils.isHostWindows()) { arguments.add("-DCMAKE_SYSTEM_VERSION=\"10.0\""); From 2e986dce1e756be4e58793b57bdaaede847abee6 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 08:37:37 +0200 Subject: [PATCH 170/709] Aligned to reactor-c/watchdogs --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 7dcdb7dfdb..abe2485cca 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 7dcdb7dfdbc065c59fe1372779d5e0606dccda30 +Subproject commit abe2485cca3299d9e056cc7f9a55d306295f00ee From 134b97046adcd20c994d8660d35f530623a63e1a Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 27 Apr 2023 10:43:01 +0200 Subject: [PATCH 171/709] Skip FileReader for Zephyr --- util/RunZephyrTests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index 66dcd10ffa..cabbbec0b2 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -9,7 +9,7 @@ num_failures=0 failed_tests="" # Skip -skip=() +skip=("FileReader") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From e32c9ff4f0b620eee7d2831a1511862ed0881a2e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 13:29:24 +0200 Subject: [PATCH 172/709] First pass a refactoring --- org.lflang/src/lib/c/reactor-c | 2 +- .../org/lflang/generator/c/CGenerator.java | 6 +---- .../generator/c/CWatchdogGenerator.java | 23 ------------------- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index abe2485cca..5c0ba3b435 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit abe2485cca3299d9e056cc7f9a55d306295f00ee +Subproject commit 5c0ba3b43545758a8f96dc168e6947afc767626b diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b26b3061c0..7dbabf8aee 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -670,9 +670,6 @@ private void generateCodeFor(String lfModuleName) throws IOException { // Generate function to schedule timers for all reactors. code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - // Generate function to initialize mutexes for all reactors with watchdogs. - code.pr(CWatchdogGenerator.generateLfInitializeWatchdogMutexes(watchdogCount)); - // Generate a function that will either do nothing // (if there is only one federate or the coordination // is set to decentralized) or, if there are @@ -1175,8 +1172,7 @@ private void generateSelfStruct( // Next, generate fields for modes CModesGenerator.generateDeclarations(reactor, body, constructorCode); - // The first field has to always be a pointer to the list of - // of allocated memory that must be freed when the reactor is freed. + // The first field has to always be a pointer to be struct_base_t. // This means that the struct can be safely cast to self_base_t. builder.pr("typedef struct {"); builder.indent(); diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 5a6f1dc3ba..50428910f5 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -212,27 +212,4 @@ public static String generateBuiltinTriggersTable(int count, String name) { " int _lf_" + name + "_number = " + count + ";", "#endif")); } - - /** Generate _lf_initialize_watchdog_mutexes function. */ - // FIXME: finish implementing - public static String generateLfInitializeWatchdogMutexes(int watchdogCount) { - var s = new StringBuilder(); - s.append("void _lf_initialize_watchdog_mutexes() {"); - if (watchdogCount > 0) { - s.append("\n"); - s.append( - String.join( - "\n", - " for (int i = 0; i < _lf_watchdog_number; i++) {", - " self_base_t* current_base = _lf_watchdogs[i]->base;", - " if (&(current_base->watchdog_mutex) == NULL) {", - " lf_mutex_init(&(current_base->watchdog_mutex));", - " current_base->has_watchdog = true;", - " }", - " }")); - } - s.append("\n"); - s.append("}\n"); - return s.toString(); - } } From 0b68ed468edf8535c0d1675aed02170aa374776b Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 13:30:50 +0200 Subject: [PATCH 173/709] Align reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 75ddd1d4a9..2f0fdad753 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 75ddd1d4a9cfab83639730863f9d31eb245cb61f +Subproject commit 2f0fdad7535a7f639f421ac8bc5eec2a159df34c From 2910f0ad45ac7c036881a751e4e7d622c5504d06 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 13:34:01 +0200 Subject: [PATCH 174/709] Typo --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 64e92bb65a..0cae84982e 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -237,7 +237,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f fileConfig.binPath ) ), - "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"", + "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"" )); // Add #define for source file directory. // Do not do this for federated programs because for those, the definition is put From 23309f9e8a4e02393d827f1d74011995a02c272d Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 16:16:01 +0200 Subject: [PATCH 175/709] Flailing to try one last time for Windows --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 0cae84982e..527b5d0168 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -226,7 +226,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f String separator = File.separator; String maybeQuote = ""; // Windows seems to require extra level of quoting. if (separator.equals("\\")) { - separator = "\\\\"; + separator = "\\\\\\\\"; maybeQuote = "\\\""; } arguments.addAll(List.of( From 6f9873967b1827cb60dd6299ef06b63fb403e44f Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 17:23:25 +0200 Subject: [PATCH 176/709] Align reactor-c-py to main --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 14146b2f7b..80c24aa2e5 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 14146b2f7be6db8261b6a45724e18e0693f1f822 +Subproject commit 80c24aa2e5bc814434893e9b6e4b183b4827c36a From b6ef20dba5d3f8fa3433d1a97e6cd79324d8a057 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 17:57:47 +0200 Subject: [PATCH 177/709] Aligned reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 5c0ba3b435..4aef0ef54c 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 5c0ba3b43545758a8f96dc168e6947afc767626b +Subproject commit 4aef0ef54ca233b3cd9ff43863d0ffa715b91e8b From 0564a9f139d332ab90642323a6c1746a410e9afb Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 19:36:29 +0200 Subject: [PATCH 178/709] Yet another attempt at a Windows fix --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 527b5d0168..26b7716ab2 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -225,9 +225,11 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f cmakeCompileDefinitions(targetConfig).forEachOrdered(arguments::add); String separator = File.separator; String maybeQuote = ""; // Windows seems to require extra level of quoting. + String srcPath = fileConfig.srcPath.toString(); // Windows requires escaping the backslashes. if (separator.equals("\\")) { separator = "\\\\\\\\"; maybeQuote = "\\\""; + srcPath = srcPath.replaceAll("\\\\", "\\\\"); } arguments.addAll(List.of( "-DCMAKE_BUILD_TYPE=" + ((targetConfig.cmakeBuildType!=null) ? targetConfig.cmakeBuildType.toString() : "Release"), @@ -244,7 +246,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f // into the cmake file (and fileConfig.srcPath is the wrong directory anyway). if (!fileConfig.srcPath.toString().contains("fed-gen")) { // Do not convert to Unix path - arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + fileConfig.srcPath + maybeQuote + "\""); + arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\""); } arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); From 2b1b4c2477c82bd5040dfa0053a3427c4375401a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 27 Apr 2023 22:26:54 +0200 Subject: [PATCH 179/709] More fumbling to try to get Windows to work --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 26b7716ab2..f0860a0e91 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -229,7 +229,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f if (separator.equals("\\")) { separator = "\\\\\\\\"; maybeQuote = "\\\""; - srcPath = srcPath.replaceAll("\\\\", "\\\\"); + srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\"); } arguments.addAll(List.of( "-DCMAKE_BUILD_TYPE=" + ((targetConfig.cmakeBuildType!=null) ? targetConfig.cmakeBuildType.toString() : "Release"), From 3b6600aa2249c2b2208db684c26b312d4cc33aa0 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 17:07:04 -0700 Subject: [PATCH 180/709] Update org.lflang/src/lib/ts/package.json --- org.lflang/src/lib/ts/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 88999eb785..d994f27145 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -20,7 +20,6 @@ "rimraf": "^3.0.2" }, "scripts": { - "check-types": "tsc", "build": "npx rimraf dist && npx tsc --outDir dist" } } From 2e986ad454560cf0e91a01c805879ec287f9f14e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 22:03:43 -0700 Subject: [PATCH 181/709] Fix copying of CMake files --- org.lflang/src/org/lflang/FileConfig.java | 4 +- org.lflang/src/org/lflang/TargetConfig.java | 8 -- .../federated/generator/FedFileConfig.java | 2 +- .../org/lflang/generator/GeneratorBase.java | 7 +- .../lflang/generator/c/CCmakeGenerator.java | 5 +- .../org/lflang/generator/c/CGenerator.java | 52 +------- .../src/org/lflang/generator/c/CUtil.java | 121 ------------------ org.lflang/src/org/lflang/util/FileUtil.java | 38 +++++- 8 files changed, 50 insertions(+), 187 deletions(-) diff --git a/org.lflang/src/org/lflang/FileConfig.java b/org.lflang/src/org/lflang/FileConfig.java index ed0f663ee9..91d681046a 100644 --- a/org.lflang/src/org/lflang/FileConfig.java +++ b/org.lflang/src/org/lflang/FileConfig.java @@ -1,6 +1,5 @@ package org.lflang; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -15,7 +14,6 @@ import org.eclipse.xtext.generator.IFileSystemAccess2; -import org.lflang.federated.generator.FedFileConfig; import org.lflang.generator.GeneratorUtils; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; @@ -308,7 +306,7 @@ public LFCommand getCommand() { * Return the extension used for binaries on the platform on which compilation takes place. */ protected String getExecutableExtension() { - return (GeneratorUtils.isHostWindows() ? ".exe" : ""); + return GeneratorUtils.isHostWindows() ? ".exe" : ""; } /** diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 6f15181172..58b6e9ae2c 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -172,14 +172,6 @@ public TargetConfig( */ public List cmakeIncludes = new ArrayList<>(); - /** - * List of cmake-includes from the cmake-include target property with no path info. - * Useful for copying them to remote machines. This is needed because - * target cmake-includes can be resources with resource paths. - */ - // FIXME: Code smell. This gets populated in CGenerator.copyUserFiles - public List cmakeIncludesWithoutPath = new ArrayList<>(); - /** * The compiler to invoke, unless a build command has been specified. */ diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index 6ac65236f8..07c8bfdf9a 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -132,7 +132,7 @@ private void relativizePathList(List paths) { * @param path The path to relativize. */ private String relativizePath(Path path) { - if (FileUtil.findInProject(path, this) == null) { + if (FileUtil.findInPackage(path, this) == null) { return String.valueOf(path); } else { Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ba39a94d9f..c9f80293db 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -56,6 +56,7 @@ import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; +import org.lflang.util.FileUtil; import org.lflang.validation.AbstractLFValidator; import com.google.common.base.Objects; @@ -348,7 +349,11 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param targetConfig The targetConfig to read the `files` from. * @param fileConfig The fileConfig used to make the copy and resolve paths. */ - protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {} + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + var targetDir = fileConfig.getSrcGenPath(); + + FileUtil.copyFiles(targetConfig.fileNames, targetDir, context); + } /** * Return true if errors occurred in the last call to doGenerate(). diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 3f5eb4a5b7..d158f7491b 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -25,6 +25,7 @@ package org.lflang.generator.c; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -313,8 +314,8 @@ CodeBuilder generateCMakeCode( cMakeCode.newLine(); // Add the include file - for (String includeFile : targetConfig.cmakeIncludesWithoutPath) { - cMakeCode.pr("include(\""+includeFile+"\")"); + for (String includeFile : targetConfig.cmakeIncludes) { + cMakeCode.pr("include(\""+ Path.of(includeFile).getFileName()+"\")"); } cMakeCode.newLine(); diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 0f1ababde8..5ae2cbd58e 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -819,57 +819,13 @@ private void inspectReactorEResource(ReactorDecl reactor) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ @Override - public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { super.copyUserFiles(targetConfig, fileConfig); - var targetDir = this.fileConfig.getSrcGenPath(); - // FIXME: this code probably belongs in the super method. - for (String filename : targetConfig.fileNames) { - var path = Paths.get(filename); - var found = FileUtil.findInProject(path, fileConfig); - if (found != null) { - try { - FileUtil.copyFileOrDirectory(found, targetDir.resolve(found.getFileName())); - } catch (IOException e) { - throw new RuntimeException(e); - } - } else { - // Attempt to copy from the classpath instead. - // If the filename is not a directory, it will - // just be copied without further recursion. - try { - FileUtil.copyDirectoryFromClassPath( - filename, - targetDir, - false - ); - } catch (IOException e) { - errorReporter.reportError( - "Failed to find '" + filename + "' specified in the" + - " files target property." - ); - } - } - } + var targetDir = fileConfig.getSrcGenPath(); -// for (String filename : targetConfig.cmakeIncludes) { -// var relativeCMakeIncludeFileName = -// CUtil.copyFileOrResource( -// filename, -// fileConfig.srcFile.getParent(), -// targetDir); -// // Check if the file exists -// if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { -// errorReporter.reportError( -// "Failed to find cmake-include file " + filename -// ); -// } else { -// // FIXME: weird -// this.targetConfig.cmakeIncludesWithoutPath.add( -// relativeCMakeIncludeFileName -// ); -// } -// } + FileUtil.copyFiles(targetConfig.cmakeIncludes, targetDir, context); + // FIXME: Unclear what the following does, but it does not appear to belong here. if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { try { FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index f59f45eef2..ce1c83d87d 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -26,12 +26,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator.c; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -54,7 +49,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Parameter; import org.lflang.lf.Port; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthTerm; @@ -575,76 +569,6 @@ public static String triggerRefNested(PortInstance port, String runtimeIndex, St return reactorRefNested(port.getParent(), runtimeIndex, bankIndex) + "." + port.getName() + "_trigger"; } -// /** -// * Copy the 'fileName' (which also could be a directory name) from the -// * 'srcDirectory' to the 'destinationDirectory'. This function has a -// * fallback search mechanism, where if `fileName` is not found in the -// * `srcDirectory`, it will try to find `fileName` via the following -// * procedure: -// * 1- Search in LF_CLASSPATH. @see findFile() -// * 2- Search in CLASSPATH. @see findFile() -// * 3- Search for 'fileName' as a resource. That means the `fileName` -// * can be '/path/to/class/resource'. @see java.lang.Class.getResourceAsStream() -// * -// * @param fileName Name of the file or directory. -// * @param srcDir Where the file or directory is currently located. -// * @param dstDir Where the file or directory should be placed. -// * @return The name of the file or directory in destinationDirectory or an empty string on failure. -// */ -// public static String copyFileOrResource(String fileName, Path srcDir, -// Path dstDir) { -// -// // Check whether file exists -// -// -// // Try to copy the file or directory from the file system. -// Path file = FileUtil.findInProject(fileName, srcDir); -// if (file != null) { -// Path target = dstDir.resolve(file.getFileName()); -// try { -// if (Files.isDirectory(file)) { -// FileUtil.copyDirectory(file, target); -// } else if (Files.isRegularFile(file)) { -// Files.copy(file, target, -// StandardCopyOption.REPLACE_EXISTING); -// } -// return file.getFileName().toString(); -// } catch (IOException e) { -// // Failed to copy the file or directory, most likely -// // because it doesn't exist. Will try to find it as a -// // resource before giving up. -// } -// } -// -// -// -// String filenameWithoutPath = fileName; -// int lastSeparator = fileName.lastIndexOf(File.separator); -// if (lastSeparator > 0) { -// // FIXME: Brittle. What if the file is in a subdirectory? -// filenameWithoutPath = fileName.substring(lastSeparator + 1); -// } -// // Try to copy the file or directory as a resource. -// try { -// System.out.println("Classpath lookup: " + dstDir.resolve(filenameWithoutPath)); -// FileUtil.copyFileFromClassPath(fileName, -// dstDir.resolve(filenameWithoutPath)); -// return filenameWithoutPath; -// } catch (IOException ex) { -// // Will try one more time as a directory -// } -// -// try { -// FileUtil.copyDirectoryFromClassPath(fileName, -// dstDir.resolve(filenameWithoutPath), false); -// return filenameWithoutPath; -// } catch (IOException ex) { -// System.err.println( -// "WARNING: Failed to find file or directory " + fileName); -// } -// -// return ""; -// } ////////////////////////////////////////////////////// //// FIXME: Not clear what the strategy is with the following inner interface. @@ -668,51 +592,6 @@ public interface ReportCommandErrors { void report(String errors); } -// /** -// * Search for a given file or directory name in the given directory. -// * If not found, search in directories in LF_CLASSPATH. -// * If there is no LF_CLASSPATH environment variable, use CLASSPATH, -// * if it is defined. The first file or directory that is found will -// * be returned. Otherwise, null is returned. -// * -// * @param fileName The file or directory name or relative path + name -// * as a String. -// * @param directory String representation of the directory to search in. -// * @return A Java Path or null if not found. -// */ -// public static Path findFileOrDirectory(String fileName, Path directory) { -// Path foundFile; -// -// // Check in local directory -// foundFile = directory.resolve(fileName); -// if (Files.exists(foundFile)) { -// System.out.println(">>> File found in filesystem"); -// return foundFile; -// } -// -// // Check in LF_CLASSPATH -// // Load all the resources in LF_CLASSPATH if it is set. -// String classpathLF = System.getenv("LF_CLASSPATH"); -// if (classpathLF == null) { -// classpathLF = System.getenv("CLASSPATH"); -// } -// if (classpathLF != null) { -// String[] paths = classpathLF.split(System.getProperty("path.separator")); -// for (String path : paths) { -// System.out.println("++++Looking in path: " + path); -// foundFile = Paths.get(path).resolve(fileName); -// if (Files.exists(foundFile)) { -// System.out.println(">>> File found on classpath: %s".formatted(foundFile)); -// return foundFile; -// } -// } -// } -// -// // Not found. -// return null; -// } - - /** * Run the custom build command specified with the "build" parameter. * This command is executed in the same directory as the source file. diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 6025400a7d..62cb5c8e20 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -14,7 +14,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; @@ -38,6 +37,7 @@ import org.eclipse.xtext.util.RuntimeIOException; import org.lflang.FileConfig; +import org.lflang.generator.LFGeneratorContext; public class FileUtil { @@ -151,7 +151,7 @@ public static java.net.URI locateFile(String path, Resource resource) { sourceURI = iFile != null ? iFile.getRawLocation().toFile().getParentFile().toURI() : null; } if (sourceURI != null) { - return sourceURI.resolve(path.toString()); + return sourceURI.resolve(path); } } catch (Exception e) { // nothing @@ -240,6 +240,38 @@ public static void copyFile(Path source, Path destination) throws IOException { copyFile(source, destination, false); } + public static void copyFiles(List filesOrDirectories, Path destination, LFGeneratorContext context) { + for (String fileOrDirectory : filesOrDirectories) { + System.out.println("****Copying " + fileOrDirectory + " to " + destination); + var path = Paths.get(fileOrDirectory); + var found = FileUtil.findInPackage(path, context.getFileConfig()); + if (found != null) { + try { + FileUtil.copyFileOrDirectory(found, destination.resolve(found.getFileName())); + } catch (IOException e) { + context.getErrorReporter().reportError( + "Unable to copy '" + fileOrDirectory + "' from the file system." + ); + } + } else { + // Attempt to copy from the classpath instead. + // If the filename is not a directory, it will + // just be copied without further recursion. + try { + FileUtil.copyDirectoryFromClassPath( + fileOrDirectory, + destination, + false + ); + } catch (IOException e) { + context.getErrorReporter().reportError( + "Unable to copy '" + fileOrDirectory + "' from the class path." + ); + } + } + } + } + public static void copyFileOrDirectory(Path source, Path destination) throws IOException { if (Files.isDirectory(source)) { copyDirectory(source, destination); @@ -523,7 +555,7 @@ public static void deleteDirectory(Path dir) throws IOException { } } - public static Path findInProject(Path fileOrDirectory, FileConfig fileConfig) { + public static Path findInPackage(Path fileOrDirectory, FileConfig fileConfig) { if (fileOrDirectory.isAbsolute() && Files.exists(fileOrDirectory)) { return fileOrDirectory; } else { From ab054f0e9b45b8cf9b9e853e0b525cd2d90f9d36 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 22:18:12 -0700 Subject: [PATCH 182/709] Comments --- .../org/lflang/generator/GeneratorBase.java | 4 +--- org.lflang/src/org/lflang/util/FileUtil.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index c9f80293db..ef083cbbda 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,9 +350,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - var targetDir = fileConfig.getSrcGenPath(); - - FileUtil.copyFiles(targetConfig.fileNames, targetDir, context); + FileUtil.copyFiles(targetConfig.fileNames, fileConfig.getSrcGenPath(), context); } /** diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 62cb5c8e20..8805d0c1f1 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -272,6 +272,13 @@ public static void copyFiles(List filesOrDirectories, Path destination, } } + /** + * If the source is a directory, then copy the contents of the directory to the destination. + * If the source is a file, then copy the file to the destination. + * @param source A file or directory to copy to the destination. + * @param destination A directory to copy the file(s) at the source to. + * @throws IOException + */ public static void copyFileOrDirectory(Path source, Path destination) throws IOException { if (Files.isDirectory(source)) { copyDirectory(source, destination); @@ -555,6 +562,17 @@ public static void deleteDirectory(Path dir) throws IOException { } } + /** + * Return an absolute path to the given file or directory if it can be found within the package. + * Otherwise, return null. + * + * NOTE: If the given file or directory is given as an absolute path but cannot be found, it is + * interpreted as a relative path with respect to the project root. + * + * @param fileOrDirectory The file or directory to look for. + * @param fileConfig A file configuration that determines where the package is located. + * @return An absolute path of the file or directory was found; null otherwise. + */ public static Path findInPackage(Path fileOrDirectory, FileConfig fileConfig) { if (fileOrDirectory.isAbsolute() && Files.exists(fileOrDirectory)) { return fileOrDirectory; From f9dff176f0d4b841ab658b565ee0091ac085252e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 22:22:39 -0700 Subject: [PATCH 183/709] More comments --- org.lflang/src/org/lflang/util/FileUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 8805d0c1f1..beaf5e7ea9 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -240,9 +240,15 @@ public static void copyFile(Path source, Path destination) throws IOException { copyFile(source, destination, false); } + /** + * Given a list of files or directories, attempt to find them based on the given generator + * context, and copy then to the destination. + * @param filesOrDirectories The files or directories to copy. + * @param destination The location to copy them to. + * @param context The generator context that specifies where the files must be found. + */ public static void copyFiles(List filesOrDirectories, Path destination, LFGeneratorContext context) { for (String fileOrDirectory : filesOrDirectories) { - System.out.println("****Copying " + fileOrDirectory + " to " + destination); var path = Paths.get(fileOrDirectory); var found = FileUtil.findInPackage(path, context.getFileConfig()); if (found != null) { From 23d08fd622c9d8101a1e2becee510902f860cfce Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 22:24:55 -0700 Subject: [PATCH 184/709] Clarification --- org.lflang/src/org/lflang/util/FileUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index beaf5e7ea9..6f9a90d868 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -242,7 +242,9 @@ public static void copyFile(Path source, Path destination) throws IOException { /** * Given a list of files or directories, attempt to find them based on the given generator - * context, and copy then to the destination. + * context, and copy then to the destination. Files are searched for in the file system first. + * Files that cannot be found in the file system are looked for on the class path. + * * @param filesOrDirectories The files or directories to copy. * @param destination The location to copy them to. * @param context The generator context that specifies where the files must be found. From 4e4986746fc7ff0c1f312f5eef08721f371b6a49 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 22:26:25 -0700 Subject: [PATCH 185/709] Address FIXME --- org.lflang/src/org/lflang/TargetConfig.java | 2 +- org.lflang/src/org/lflang/TargetProperty.java | 6 +++--- .../src/org/lflang/federated/generator/FedFileConfig.java | 2 +- org.lflang/src/org/lflang/generator/GeneratorBase.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 58b6e9ae2c..845f214ec8 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -230,7 +230,7 @@ public TargetConfig( /** * List of files to be copied to src-gen. */ - public List fileNames = new ArrayList<>(); // FIXME: misnamed, these are files or paths, not file names. + public List files = new ArrayList<>(); /** * If true, configure the execution environment to keep executing if there diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 1bacb1f75e..61cda14431 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -276,16 +276,16 @@ public enum TargetProperty { * processed by the code generator. */ FILES("files", UnionType.FILE_OR_FILE_ARRAY, List.of(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.fileNames), + (config) -> ASTUtils.toElement(config.files), (config, value, err) -> { - config.fileNames = ASTUtils.elementToListOfStrings(value); + config.files = ASTUtils.elementToListOfStrings(value); }, // FIXME: This merging of lists is potentially dangerous since // the incoming list of files can belong to a .lf file that is // located in a different location, and keeping just filename // strings like this without absolute paths is incorrect. (config, value, err) -> { - config.fileNames.addAll(ASTUtils.elementToListOfStrings(value)); + config.files.addAll(ASTUtils.elementToListOfStrings(value)); }), /** diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index 07c8bfdf9a..e434501825 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -111,7 +111,7 @@ public void doClean() throws IOException { */ public void relativizePaths(FedTargetConfig targetConfig) { relativizePathList(targetConfig.protoFiles); - relativizePathList(targetConfig.fileNames); + relativizePathList(targetConfig.files); relativizePathList(targetConfig.cmakeIncludes); } diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ef083cbbda..ecb09dfbf9 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,7 +350,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - FileUtil.copyFiles(targetConfig.fileNames, fileConfig.getSrcGenPath(), context); + FileUtil.copyFiles(targetConfig.files, fileConfig.getSrcGenPath(), context); } /** From 927be22a496ba0deb68daf95b8794718bcfa817e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 22:40:24 -0700 Subject: [PATCH 186/709] Fix #1719 --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 5ae2cbd58e..8ae50498c9 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -611,7 +611,9 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { GeneratorResult.Status.COMPILED, null ); } - System.out.println("Compiled binary is in " + fileConfig.binPath); + if (!errorsOccurred()){ + System.out.println("Compiled binary is in " + fileConfig.binPath); + } } else { context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); } From d8ff9a698b07f14f2210172ece3fe852f0f4440f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 27 Apr 2023 23:15:25 -0700 Subject: [PATCH 187/709] Bugfix --- .../src/org/lflang/generator/GeneratorBase.java | 2 +- .../src/org/lflang/generator/c/CGenerator.java | 9 ++++----- org.lflang/src/org/lflang/util/FileUtil.java | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ecb09dfbf9..15d703bcbf 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,7 +350,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - FileUtil.copyFiles(targetConfig.files, fileConfig.getSrcGenPath(), context); + FileUtil.copyFiles(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 8ae50498c9..e52eae4db5 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -37,9 +37,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.File; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -823,15 +821,16 @@ private void inspectReactorEResource(ReactorDecl reactor) { @Override protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { super.copyUserFiles(targetConfig, fileConfig); - var targetDir = fileConfig.getSrcGenPath(); + // Must use class variable to determine destination! + var destination = this.fileConfig.getSrcGenPath(); - FileUtil.copyFiles(targetConfig.cmakeIncludes, targetDir, context); + FileUtil.copyFiles(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); // FIXME: Unclear what the following does, but it does not appear to belong here. if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { try { FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), - targetDir.resolve(targetConfig.fedSetupPreamble)); + destination.resolve(targetConfig.fedSetupPreamble)); } catch (IOException e) { errorReporter.reportError("Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 6f9a90d868..a2cfb81e4d 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -36,6 +36,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.util.RuntimeIOException; +import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.generator.LFGeneratorContext; @@ -247,17 +248,23 @@ public static void copyFile(Path source, Path destination) throws IOException { * * @param filesOrDirectories The files or directories to copy. * @param destination The location to copy them to. - * @param context The generator context that specifies where the files must be found. + * @param fileConfig The file configuration that specifies where the files must be found. + * @param errorReporter An error reporter to report problems. */ - public static void copyFiles(List filesOrDirectories, Path destination, LFGeneratorContext context) { + public static void copyFiles( + List filesOrDirectories, + Path destination, + FileConfig fileConfig, + ErrorReporter errorReporter + ) { for (String fileOrDirectory : filesOrDirectories) { var path = Paths.get(fileOrDirectory); - var found = FileUtil.findInPackage(path, context.getFileConfig()); + var found = FileUtil.findInPackage(path, fileConfig); if (found != null) { try { FileUtil.copyFileOrDirectory(found, destination.resolve(found.getFileName())); } catch (IOException e) { - context.getErrorReporter().reportError( + errorReporter.reportError( "Unable to copy '" + fileOrDirectory + "' from the file system." ); } @@ -272,7 +279,7 @@ public static void copyFiles(List filesOrDirectories, Path destination, false ); } catch (IOException e) { - context.getErrorReporter().reportError( + errorReporter.reportError( "Unable to copy '" + fileOrDirectory + "' from the class path." ); } From a6487556e9f5ae075ae9fc14dff4efcbb01007ef Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 28 Apr 2023 08:28:02 +0200 Subject: [PATCH 188/709] Align reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 2f0fdad753..75ddd1d4a9 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2f0fdad7535a7f639f421ac8bc5eec2a159df34c +Subproject commit 75ddd1d4a9cfab83639730863f9d31eb245cb61f From 3333bcbd84ffd88db09f987193c12aeca812e9ca Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 28 Apr 2023 09:35:58 +0200 Subject: [PATCH 189/709] Added LF_PROJECT_DIRECTORY --- org.lflang/src/lib/c/reactor-c | 2 +- .../federated/extensions/CExtensionUtils.java | 5 ++ .../generator/GeneratorCommandFactory.java | 1 + .../src/org/lflang/generator/c/CCompiler.java | 3 + .../src/org/lflang/generator/c/CUtil.java | 1 + test/C/src/FilePkgReader.lf | 47 +++++++++++++++ .../C/src/federated/FederatedFilePkgReader.lf | 57 +++++++++++++++++++ util/RunZephyrTests.sh | 2 +- 8 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 test/C/src/FilePkgReader.lf create mode 100644 test/C/src/federated/FederatedFilePkgReader.lf diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 75ddd1d4a9..c6c549d43a 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 75ddd1d4a9cfab83639730863f9d31eb245cb61f +Subproject commit c6c549d43aa5144e5c1d4eea4feb16a410c40fd3 diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 2ad19c64cc..f1fc4423e8 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -366,6 +366,11 @@ public static void generateCMakeInclude( + fileConfig.srcPath + "\")" ); + cmakeIncludeCode.pr( + "add_compile_definitions(LF_PROJECT_DIRECTORY=\"" + + fileConfig.srcPkgPath + + "\")" + ); try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) { srcWriter.write(cmakeIncludeCode.getCode()); diff --git a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java b/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java index 4868542afe..93026bf069 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java +++ b/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java @@ -128,6 +128,7 @@ public LFCommand createCommand(String cmd, List args, Path dir, boolean if (command != null) { command.setEnvironmentVariable("LF_CURRENT_WORKING_DIRECTORY", dir.toString()); command.setEnvironmentVariable("LF_SOURCE_DIRECTORY", fileConfig.srcPath.toString()); + command.setEnvironmentVariable("LF_PROJECT_DIRECTORY", fileConfig.srcPkgPath.toString()); command.setEnvironmentVariable("LF_SOURCE_GEN_DIRECTORY", fileConfig.getSrcGenPath().toString()); command.setEnvironmentVariable("LF_BIN_DIRECTORY", fileConfig.binPath.toString()); } else { diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index f0860a0e91..d9be4268bd 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -226,10 +226,12 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f String separator = File.separator; String maybeQuote = ""; // Windows seems to require extra level of quoting. String srcPath = fileConfig.srcPath.toString(); // Windows requires escaping the backslashes. + String rootPath = fileConfig.srcPkgPath.toString(); if (separator.equals("\\")) { separator = "\\\\\\\\"; maybeQuote = "\\\""; srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\"); + rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\"); } arguments.addAll(List.of( "-DCMAKE_BUILD_TYPE=" + ((targetConfig.cmakeBuildType!=null) ? targetConfig.cmakeBuildType.toString() : "Release"), @@ -247,6 +249,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f if (!fileConfig.srcPath.toString().contains("fed-gen")) { // Do not convert to Unix path arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\""); + arguments.add("-DLF_PROJECT_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\""); } arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 69e9ec30ae..856849218b 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -710,6 +710,7 @@ public static Path findFileOrDirectory(String fileName, Path directory) { * * * LF_CURRENT_WORKING_DIRECTORY: The directory in which the command is invoked. * * LF_SOURCE_DIRECTORY: The directory containing the .lf file being compiled. + * * LF_PACKAGE_DIRECTORY: The directory for the root of the project. * * LF_SOURCE_GEN_DIRECTORY: The directory in which generated files are placed. * * LF_BIN_DIRECTORY: The directory into which to put binaries. * diff --git a/test/C/src/FilePkgReader.lf b/test/C/src/FilePkgReader.lf new file mode 100644 index 0000000000..e1dce78c8f --- /dev/null +++ b/test/C/src/FilePkgReader.lf @@ -0,0 +1,47 @@ +/** Test reading a file at a location relative to the source file. */ +target C + +reactor Source { + output out: char* // Use char*, not string, so memory is freed. + + reaction(startup) -> out {= + char* file_path = + LF_PROJECT_DIRECTORY + LF_FILE_SEPARATOR "src" + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + lf_set(out, buffer); + =} +} + +main reactor { + preamble {= + #include + =} + s = new Source() + + reaction(s.out) {= + printf("Received: %s\n", s.out->value); + if (strcmp("Hello World", s.out->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} +} diff --git a/test/C/src/federated/FederatedFilePkgReader.lf b/test/C/src/federated/FederatedFilePkgReader.lf new file mode 100644 index 0000000000..b553ec5ee1 --- /dev/null +++ b/test/C/src/federated/FederatedFilePkgReader.lf @@ -0,0 +1,57 @@ +/** Test reading a file at a location relative to the source file. */ +target C { + timeout: 0 s +} + +reactor Source { + output out: char* // Use char*, not string, so memory is freed. + + reaction(startup) -> out {= + char* file_path = + LF_PROJECT_DIRECTORY + LF_FILE_SEPARATOR "src" + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + // For federated version, have to use lf_set_array so array size is know + // to the serializer. + lf_set_array(out, buffer, file_size + 1); + =} +} + +reactor Check { + preamble {= + #include + =} + input in: char* + + reaction(in) {= + printf("Received: %s\n", in->value); + if (strcmp("Hello World", in->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} +} + +federated reactor { + s = new Source() + c = new Check() + s.out -> c.in +} diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index cabbbec0b2..25f5c12c58 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -9,7 +9,7 @@ num_failures=0 failed_tests="" # Skip -skip=("FileReader") +skip=("FileReader", "FilePkgReader") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From 5c3114e46b3cbf29fde1ef0b621dd8b3b066321c Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 28 Apr 2023 11:51:57 +0200 Subject: [PATCH 190/709] Continued refactoring --- org.lflang/src/lib/c/reactor-c | 2 +- .../org/lflang/generator/c/CGenerator.java | 49 +++---------- .../generator/c/CWatchdogGenerator.java | 72 ++++++++++++------- 3 files changed, 54 insertions(+), 69 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 4aef0ef54c..5d58c62cb1 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 4aef0ef54ca233b3cd9ff43863d0ffa715b91e8b +Subproject commit 5d58c62cb141e13c423cdadd11dbf97c8edd2d75 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 7dbabf8aee..44691e773b 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -644,7 +644,7 @@ private void generateCodeFor(String lfModuleName) throws IOException { code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); // If there are watchdogs, create a table of triggers. - code.pr(CWatchdogGenerator.generateBuiltinTriggersTable(watchdogCount, "watchdog")); + code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); // If there are modes, create a table of mode state to be checked for transitions. code.pr( @@ -750,16 +750,6 @@ private boolean hasDeadlines(List reactors) { return false; } - private boolean hasWatchdogs() { - for (Reactor reactor : reactors) { - List watchdogs = ASTUtils.allWatchdogs(reactor); - if (watchdogs != null && !watchdogs.isEmpty()) { - return true; - } - } - return false; - } - /** * Look at the 'reactor' eResource. If it is an imported .lf file, incorporate it into the current * program in the following manner: - Merge its target property with `targetConfig` - If there are @@ -1045,9 +1035,10 @@ private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeB // go into the constructor. Collect those lines of code here: var constructorCode = new CodeBuilder(); generateAuxiliaryStructs(header, reactor, false); + // The following must go before the self struct so the #include watchdog.h ends up in the header. + CWatchdogGenerator.generateWatchdogs(src, header, reactor); generateSelfStruct(header, reactor, constructorCode); generateMethods(src, reactor); - generateWatchdogs(src, reactor); generateReactions(src, reactor); generateConstructor(src, header, reactor, constructorCode); } @@ -1074,6 +1065,8 @@ protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) /** * Generate a constructor for the specified reactor in the specified federate. * + * @param src Where to put the assembled code. + * @param header Where to put header code. * @param reactor The parsed reactor data structure. * @param constructorCode Lines of code previously generated that need to go into the constructor. */ @@ -1398,33 +1391,6 @@ protected void generateReaction( getTarget().requiresTypes)); } - /** - * Generate watchdog functions definition for a reactor. These functions have a single argument - * that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. - * - * @param decl The reactor. federated or not the main reactor and reactions should be - * unconditionally generated. - */ - public void generateWatchdogs(CodeBuilder src, ReactorDecl decl) { - var reactor = ASTUtils.toDefinition(decl); - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - generateWatchdog(src, watchdog, decl); - } - } - - /** - * Generate a watchdog function definition for a reactor. This function will have a single - * argument that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. - * - * @param watchdog The watchdog. - * @param decl The reactor. - */ - protected void generateWatchdog(CodeBuilder src, Watchdog watchdog, ReactorDecl decl) { - src.pr(CWatchdogGenerator.generateWatchdog(watchdog, decl)); - } - /** * Record startup, shutdown, and reset reactions. * @@ -1480,7 +1446,8 @@ private void recordWatchdogs(ReactorInstance instance) { var temp = new CodeBuilder(); var reactorRef = CUtil.reactorRef(instance); // temp.pr("#ifdef LF_THREADED"); - for (WatchdogInstance watchdog : instance.watchdogs) { + for (Watchdog watchdog + : ASTUtils.allWatchdogs(ASTUtils.toDefinition(instance.getDefinition().getReactorClass()))) { temp.pr( " _lf_watchdogs[_lf_watchdog_number_count++] = &" + reactorRef @@ -1493,7 +1460,7 @@ private void recordWatchdogs(ReactorInstance instance) { + "->_lf_watchdog_" + watchdog.getName() + ".min_expiration = " - + CTypes.getInstance().getTargetTimeExpr(watchdog.getTimeout()) + + CTypes.getInstance().getTargetTimeExpr(instance.getTimeValue(watchdog.getTimeout())) + ";"); temp.pr(" " + reactorRef + "->_lf_watchdog_" + watchdog.getName() + ".thread_id;"); watchdogCount += 1; diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 50428910f5..5bd0fe648d 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -18,6 +18,36 @@ */ public class CWatchdogGenerator { + /** + * Generate watchdog functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param src The place to put the code. + * @param header The place to put header code. + * @param decl The reactor declaration. + */ + public static void generateWatchdogs(CodeBuilder src, CodeBuilder header, ReactorDecl decl) { + var reactor = ASTUtils.toDefinition(decl); + if (hasWatchdogs(reactor)) { + header.pr("#include \"core/threaded/watchdog.h\""); + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + src.pr(generateWatchdogFunction(watchdog, decl)); + } + } + } + + /** + * Return true if the given reactor has one or more watchdogs. + * @param reactor The reactor. + * @return True if the given reactor has watchdogs. + */ + public static boolean hasWatchdogs(Reactor reactor) { + List watchdogs = ASTUtils.allWatchdogs(reactor); + if (watchdogs != null && !watchdogs.isEmpty()) return true; + return false; + } + /** * Generate necessary initialization code inside the body of the watchdog that belongs to reactor * decl. @@ -147,7 +177,7 @@ public static String generateFunction(String header, String init, Watchdog watch return function.toString(); } - /** Generate watchdog definition in parent struct. */ + /** Generate watchdog definition in the reactor's self struct. */ public static void generateWatchdogStruct( CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { var reactor = ASTUtils.toDefinition(decl); @@ -161,7 +191,6 @@ public static void generateWatchdogStruct( var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); // Set values of watchdog_t struct in the reactor's constructor // FIXME: update parameters - // constructorCode.pr("#ifdef LF_THREADED"); constructorCode.pr( watchdog, String.join( @@ -169,7 +198,6 @@ public static void generateWatchdogStruct( "self->_lf_watchdog_" + watchdogName + ".base = &(self->base);", "self->_lf_watchdog_" + watchdogName + ".expiration = NEVER;", "self->_lf_watchdog_" + watchdogName + ".thread_active = false;", - // "self->_lf_watchdog_"+watchdogName+".min_expiration = "+min_expiration+";", "self->_lf_watchdog_" + watchdogName + ".watchdog_function = " @@ -179,37 +207,27 @@ public static void generateWatchdogStruct( + watchdogName + ".trigger = &(self->_lf__" + watchdogName - + ");")); + + ");" + ) + ); } } /** - * Generate a watchdog function definition for a reactor. This function will have a single - * argument that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. - * - * @param watchdog The watchdog. - * @param decl The reactor. + * Generate a global table of watchdog structs. + * @param count The number of watchdogs found. + * @return The code that defines the table or a comment if count is 0. */ - public static String generateWatchdog(Watchdog watchdog, ReactorDecl decl) { - var code = new CodeBuilder(); - - code.pr(generateWatchdogFunction(watchdog, decl)); - - return code.toString(); - } - - public static String generateBuiltinTriggersTable(int count, String name) { + public static String generateWatchdogTable(int count) { + if (count == 0) { + return "// No watchdogs found."; + } return String.join( "\n", List.of( - "// Array of pointers to " + name + " triggers.", - "#ifdef LF_THREADED", - (count > 0 - ? " watchdog_t* _lf_" + name + "s[" + count + "]" - : " watchdog_t* _lf_" + name + "s = NULL") - + ";", - " int _lf_" + name + "_number = " + count + ";", - "#endif")); + "// Array of pointers to watchdog structs.", + " watchdog_t* _lf_watchdogs[" + count + "];", + " int _lf_watchdog_number = " + count + ";" + )); } } From af103df9737ec9d98efc28d79c88d7f91b1b8ebe Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 28 Apr 2023 13:51:48 +0200 Subject: [PATCH 191/709] Attempt to exclude FilePkgReader --- util/RunZephyrTests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index cabbbec0b2..25f5c12c58 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -9,7 +9,7 @@ num_failures=0 failed_tests="" # Skip -skip=("FileReader") +skip=("FileReader", "FilePkgReader") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From 2db62e8c0e95d942528ef9ff2daababe17644872 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Fri, 28 Apr 2023 17:26:13 +0200 Subject: [PATCH 192/709] Make USER_THREADS possible to specify as a target property in platform options --- org.lflang/src/org/lflang/TargetConfig.java | 5 +++++ org.lflang/src/org/lflang/TargetProperty.java | 9 ++++++++- org.lflang/src/org/lflang/generator/c/CGenerator.java | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 23e99541da..9a34529124 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -478,6 +478,11 @@ public static class PlatformOptions { * port values depending on the infrastructure you use to flash the boards. */ public boolean flash = false; + + /** + * The int value is used to determine the number of needed threads for the user application in Zephyr. + */ + public int userThreads = 0; } /** diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 1bacb1f75e..d8058009bb 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -432,6 +432,9 @@ public enum TargetProperty { case PORT: pair.setValue(ASTUtils.toElement(config.platformOptions.port)); break; + case USERTHREADS: + pair.setValue(ASTUtils.toElement(config.platformOptions.userThreads)); + break; } kvp.getPairs().add(pair); } @@ -472,6 +475,9 @@ public enum TargetProperty { case PORT: config.platformOptions.port = ASTUtils.elementToSingleString(entry.getValue()); break; + case USERTHREADS: + config.platformOptions.userThreads = ASTUtils.toInteger(entry.getValue()); + break; default: break; } @@ -1659,7 +1665,8 @@ public enum PlatformOption implements DictionaryElement { BAUDRATE("baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), BOARD("board", PrimitiveType.STRING), FLASH("flash", PrimitiveType.BOOLEAN), - PORT("port", PrimitiveType.STRING); + PORT("port", PrimitiveType.STRING), + USERTHREADS("user_threads", PrimitiveType.NON_NEGATIVE_INTEGER); public final PrimitiveType type; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index f598219ddd..2bec8857bf 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1962,6 +1962,14 @@ protected void setUpGeneralParameters() { System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); targetConfig.noCompile = true; } + + if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.platformOptions.userThreads >= 0) { + targetConfig.compileDefinitions.put( + "USER_THREADS", + String.valueOf(targetConfig.platformOptions.userThreads) + ); + } + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake pickScheduler(); // FIXME: this and pickScheduler should be combined. From f81a8fdafa5ed36825d99753cbc778c48de3ccf7 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 09:11:29 -0700 Subject: [PATCH 193/709] Fix a failing test and add a test that was failing but had already been fixed --- .../src/org/lflang/generator/c/CGenerator.java | 8 +++++++- test/C/src/target/FederatedFiles.lf | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/C/src/target/FederatedFiles.lf diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e52eae4db5..c01a85925d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -804,9 +804,15 @@ private void inspectReactorEResource(ReactorDecl reactor) { break; } } - // Copy the user files and cmake-includes to the src-gen path of the main .lf file if (lfResource != null) { + // Copy the user files and cmake-includes to the src-gen path of the main .lf file copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + // Merge the CMake includes from the imported file into the target config + lfResource.getTargetConfig().cmakeIncludes.stream().forEach(incl -> { + if (!this.targetConfig.cmakeIncludes.contains(incl)) { + this.targetConfig.cmakeIncludes.add(incl); + } + }); } } } diff --git a/test/C/src/target/FederatedFiles.lf b/test/C/src/target/FederatedFiles.lf new file mode 100644 index 0000000000..ebc1ff210e --- /dev/null +++ b/test/C/src/target/FederatedFiles.lf @@ -0,0 +1,14 @@ +// This test references a header file in reactor-c, which has to be obtained +// from the class path. This test is successful if it compiles. +target C { + files: "/lib/c/reactor-c/util/sensor_simulator.h", + timeout: 1 s +} + +reactor Foo { + reaction(startup) {= lf_print("Hello World"); =} +} + +federated reactor { + f = new Foo() +} From e3703397980f71a7b3814543fbbaba59b448acae Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 09:33:18 -0700 Subject: [PATCH 194/709] Update .github/workflows/ts-tests.yml --- .github/workflows/ts-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 79c972d744..83c04d8cf7 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,7 +28,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#cleanup-deps" + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: From 9d665e6d288150971bb175c5e92b3e1599c6b3ac Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 09:33:43 -0700 Subject: [PATCH 195/709] Update action.yml --- .github/actions/prepare-build-env/action.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/actions/prepare-build-env/action.yml b/.github/actions/prepare-build-env/action.yml index 1ac9d0a813..2d0c82c78f 100644 --- a/.github/actions/prepare-build-env/action.yml +++ b/.github/actions/prepare-build-env/action.yml @@ -1,10 +1,5 @@ name: Prepare build environment (Linux only) description: Set up Java, Maven, Gradle, etc. -inputs: - lf-dir: - description: 'Relative path from $GITHUB_WORKSPACE to lingua-franca checkout' - required: false - default: '' runs: using: "composite" steps: From d7846a6330330b163154005342a0a1b5cd26bca5 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 09:36:17 -0700 Subject: [PATCH 196/709] Remove Babel config --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/cpp/reactor-cpp | 2 +- org.lflang/src/lib/py/reactor-c-py | 2 +- org.lflang/src/lib/ts/babel.config.js | 19 ------------------- 4 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 org.lflang/src/lib/ts/babel.config.js diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 42a87b1b9c..4f78b42ac8 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 42a87b1b9cb678ab9170dbf800019bcbeb80c61f +Subproject commit 4f78b42ac806c113aed0ecd6510e56a20c049b61 diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index e80cd36ce5..a37f0ade9e 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 +Subproject commit a37f0ade9ee0f97606528fd7ba67712495948373 diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 9f82617589..14146b2f7b 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 9f82617589994ce5f71c88a091b32f5a4ac431f0 +Subproject commit 14146b2f7be6db8261b6a45724e18e0693f1f822 diff --git a/org.lflang/src/lib/ts/babel.config.js b/org.lflang/src/lib/ts/babel.config.js deleted file mode 100644 index 9fd078c1b2..0000000000 --- a/org.lflang/src/lib/ts/babel.config.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = function (api) { - api.cache(true); - - const presets = [ - "@babel/typescript" - ]; - - const plugins = [ - "@babel/proposal-class-properties", - "@babel/proposal-object-rest-spread", - "@babel/plugin-proposal-optional-chaining", - "@babel/plugin-transform-modules-commonjs" - ]; - - return { - presets, - plugins - }; -} From 97e53b6c9dea50ea0785d75c81a569f6365d150c Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 29 Apr 2023 06:23:01 +0200 Subject: [PATCH 197/709] Another attempt to exclude FileReader --- util/RunZephyrTests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index 25f5c12c58..742a23ef18 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -9,7 +9,7 @@ num_failures=0 failed_tests="" # Skip -skip=("FileReader", "FilePkgReader") +skip=("FileReader" "FilePkgReader") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From 4c1197584294843049785156ddc5a7d1bc027344 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 29 Apr 2023 06:43:39 +0200 Subject: [PATCH 198/709] Another attempt to exclude FileReader --- util/RunZephyrTests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index 25f5c12c58..742a23ef18 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -9,7 +9,7 @@ num_failures=0 failed_tests="" # Skip -skip=("FileReader", "FilePkgReader") +skip=("FileReader" "FilePkgReader") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From ac2fef8e861601a3bee1c42da145a9a7f81c5331 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 29 Apr 2023 06:51:26 +0200 Subject: [PATCH 199/709] LF_PROJECT_DIRECTORY to LF_PACKAGE_DIRECTORY --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/org/lflang/federated/extensions/CExtensionUtils.java | 2 +- .../src/org/lflang/generator/GeneratorCommandFactory.java | 2 +- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- test/C/src/FilePkgReader.lf | 2 +- test/C/src/federated/FederatedFilePkgReader.lf | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c6c549d43a..8eaf16fdc4 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c6c549d43aa5144e5c1d4eea4feb16a410c40fd3 +Subproject commit 8eaf16fdc46df596cf85f7be7e901988cabcd873 diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index f1fc4423e8..55a489ce51 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -367,7 +367,7 @@ public static void generateCMakeInclude( + "\")" ); cmakeIncludeCode.pr( - "add_compile_definitions(LF_PROJECT_DIRECTORY=\"" + "add_compile_definitions(LF_PACKAGE_DIRECTORY=\"" + fileConfig.srcPkgPath + "\")" ); diff --git a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java b/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java index 93026bf069..081f07320b 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java +++ b/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java @@ -128,7 +128,7 @@ public LFCommand createCommand(String cmd, List args, Path dir, boolean if (command != null) { command.setEnvironmentVariable("LF_CURRENT_WORKING_DIRECTORY", dir.toString()); command.setEnvironmentVariable("LF_SOURCE_DIRECTORY", fileConfig.srcPath.toString()); - command.setEnvironmentVariable("LF_PROJECT_DIRECTORY", fileConfig.srcPkgPath.toString()); + command.setEnvironmentVariable("LF_PACKAGE_DIRECTORY", fileConfig.srcPkgPath.toString()); command.setEnvironmentVariable("LF_SOURCE_GEN_DIRECTORY", fileConfig.getSrcGenPath().toString()); command.setEnvironmentVariable("LF_BIN_DIRECTORY", fileConfig.binPath.toString()); } else { diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index d9be4268bd..e609144b62 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -249,7 +249,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f if (!fileConfig.srcPath.toString().contains("fed-gen")) { // Do not convert to Unix path arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\""); - arguments.add("-DLF_PROJECT_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\""); + arguments.add("-DLF_PACKAGE_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\""); } arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); diff --git a/test/C/src/FilePkgReader.lf b/test/C/src/FilePkgReader.lf index e1dce78c8f..df2c03ab78 100644 --- a/test/C/src/FilePkgReader.lf +++ b/test/C/src/FilePkgReader.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_PROJECT_DIRECTORY + LF_PACKAGE_DIRECTORY LF_FILE_SEPARATOR "src" LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/federated/FederatedFilePkgReader.lf b/test/C/src/federated/FederatedFilePkgReader.lf index b553ec5ee1..597ebbf96a 100644 --- a/test/C/src/federated/FederatedFilePkgReader.lf +++ b/test/C/src/federated/FederatedFilePkgReader.lf @@ -8,7 +8,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_PROJECT_DIRECTORY + LF_PACKAGE_DIRECTORY LF_FILE_SEPARATOR "src" LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; From b81f3a8fd3350eb81b1a8985e8d8307434325531 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 21:56:29 -0700 Subject: [PATCH 200/709] Address npm not properly building reactor-ts from GitHub dependency --- org.lflang/src/lib/ts/package.json | 2 +- .../org/lflang/generator/ts/TSGenerator.kt | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index d994f27145..fc063d791e 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -16,7 +16,7 @@ "@typescript-eslint/parser": "^5.8.1", "eslint": "^8.5.0", "typescript": "~4.8.2", - "ts-protoc-gen": "^0.12.0", + "ts-protoc-gen": "^0.15.0", "rimraf": "^3.0.2" }, "scripts": { diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index fa9012d74d..8f36fbace4 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -61,8 +61,10 @@ class TSGenerator( val fileConfig: TSFileConfig = context.fileConfig as TSFileConfig + var devMode = false; companion object { + /** Path to the TS lib directory (relative to class path) */ const val LIB_PATH = "/lib/ts" @@ -72,6 +74,8 @@ class TSGenerator( */ val CONFIG_FILES = arrayOf("package.json", "tsconfig.json", ".eslintrc.json") + const val RUNTIME_URL = "git://github.com/lf-lang/reactor-ts.git" + fun timeInTargetLanguage(value: TimeValue): String { return if (value.unit != null) { "TimeValue.${value.unit.canonicalName}(${value.magnitude})" @@ -186,12 +190,18 @@ class TSGenerator( if (rtPath != null) rtPath = formatRuntimePath(rtPath) // FIXME: do better CLI arg validation upstream // https://github.com/lf-lang/lingua-franca/issues/1429 + if (rtPath != null || rtVersion != null) { + devMode = true; + } manifest.toFile().forEachLine { var line = it.replace("\"LinguaFrancaDefault\"", "\"${fileConfig.name}\""); + if (line.matches(rtRegex) && line.contains(RUNTIME_URL)) { + devMode = true; + } if (rtPath != null) { line = line.replace(rtRegex, "$1: \"$rtPath\",") } else if (rtVersion != null) { - line = line.replace(rtRegex, "$1: \"git://github.com/lf-lang/reactor-ts.git#$rtVersion\",") + line = line.replace(rtRegex, "$1: \"$RUNTIME_URL#$rtVersion\",") } sb.appendLine(line) } @@ -311,6 +321,7 @@ class TSGenerator( errorReporter.reportWarning( "Falling back on npm. To prevent an accumulation of replicated dependencies, " + "it is highly recommended to install pnpm globally (npm install -g pnpm).") + val npmInstall = commandFactory.createCommand("npm", if (production) listOf("install", "--production") else listOf("install"), path) if (npmInstall == null) { @@ -318,6 +329,18 @@ class TSGenerator( return } + // If reactor-ts is pulled from GitHub and building is done using npm, + // first build reactor-ts (pnpm does this automatically). + if (devMode) { + val rtPath = path.resolve("node_modules").resolve("@lf-lang").resolve("reactor-ts") + val buildRuntime = commandFactory.createCommand("npm", listOf("prepublish"), rtPath) + if (buildRuntime.run(context.cancelIndicator) != 0) { + errorReporter.reportError( + GeneratorUtils.findTargetDecl(resource), + "ERROR: unable to build runtime in dev mode: " + buildRuntime.errors.toString()) + } + } + if (npmInstall.run(context.cancelIndicator) != 0) { errorReporter.reportError( GeneratorUtils.findTargetDecl(resource), From 1b5d1dc781e0564d0cdb54eb48440b229b78798d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 21:59:47 -0700 Subject: [PATCH 201/709] Undo unintended submodule update --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 4f78b42ac8..75ddd1d4a9 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 4f78b42ac806c113aed0ecd6510e56a20c049b61 +Subproject commit 75ddd1d4a9cfab83639730863f9d31eb245cb61f From a2339df9f86ab11715aa697edf51ead899fe6c70 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 29 Apr 2023 07:20:00 +0200 Subject: [PATCH 202/709] Added test for resource-based file include for federated --- test/C/src/federated/FederatedFileInclude.lf | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/C/src/federated/FederatedFileInclude.lf diff --git a/test/C/src/federated/FederatedFileInclude.lf b/test/C/src/federated/FederatedFileInclude.lf new file mode 100644 index 0000000000..02b2d261bf --- /dev/null +++ b/test/C/src/federated/FederatedFileInclude.lf @@ -0,0 +1,13 @@ +/** Success here is just successfully compiling. */ +target C { + files: "/lib/c/reactor-c/util/sensor_simulator.h", + timeout: 1s +} +reactor Foo { + reaction(startup) {= + lf_print("Hello World"); + =} +} +federated reactor { + f = new Foo() +} \ No newline at end of file From 4f3be0b740334f753fac3c294321ce3f15b765b6 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 22:46:10 -0700 Subject: [PATCH 203/709] Fix detection of dev mode --- .../org/lflang/generator/ts/TSGenerator.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 8f36fbace4..bd92a144ce 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -195,7 +195,7 @@ class TSGenerator( } manifest.toFile().forEachLine { var line = it.replace("\"LinguaFrancaDefault\"", "\"${fileConfig.name}\""); - if (line.matches(rtRegex) && line.contains(RUNTIME_URL)) { + if (line.contains(rtRegex) && line.contains(RUNTIME_URL)) { devMode = true; } if (rtPath != null) { @@ -329,11 +329,21 @@ class TSGenerator( return } + if (npmInstall.run(context.cancelIndicator) != 0) { + errorReporter.reportError( + GeneratorUtils.findTargetDecl(resource), + "ERROR: npm install command failed: " + npmInstall.errors.toString()) + errorReporter.reportError( + GeneratorUtils.findTargetDecl(resource), "ERROR: npm install command failed." + + "\nFor installation instructions, see: https://www.npmjs.com/get-npm") + return + } + // If reactor-ts is pulled from GitHub and building is done using npm, // first build reactor-ts (pnpm does this automatically). if (devMode) { val rtPath = path.resolve("node_modules").resolve("@lf-lang").resolve("reactor-ts") - val buildRuntime = commandFactory.createCommand("npm", listOf("prepublish"), rtPath) + val buildRuntime = commandFactory.createCommand("npm", listOf("run", "prepublish"), rtPath) if (buildRuntime.run(context.cancelIndicator) != 0) { errorReporter.reportError( GeneratorUtils.findTargetDecl(resource), @@ -341,15 +351,6 @@ class TSGenerator( } } - if (npmInstall.run(context.cancelIndicator) != 0) { - errorReporter.reportError( - GeneratorUtils.findTargetDecl(resource), - "ERROR: npm install command failed: " + npmInstall.errors.toString()) - errorReporter.reportError( - GeneratorUtils.findTargetDecl(resource), "ERROR: npm install command failed." + - "\nFor installation instructions, see: https://www.npmjs.com/get-npm") - return - } installProtoBufsIfNeeded(false, path, context.cancelIndicator) } } From 35d39a3b5dcfc4682ea6d08799a4680604abe564 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 22:51:17 -0700 Subject: [PATCH 204/709] Undo more unintended submodule updates --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- org.lflang/src/lib/py/reactor-c-py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a37f0ade9e..e80cd36ce5 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a37f0ade9ee0f97606528fd7ba67712495948373 +Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 14146b2f7b..9f82617589 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 14146b2f7be6db8261b6a45724e18e0693f1f822 +Subproject commit 9f82617589994ce5f71c88a091b32f5a4ac431f0 From 9020ccada00c4004dd753c7ec42d0c4ec544ed50 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 09:15:45 -0700 Subject: [PATCH 205/709] Minor simplification --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index c01a85925d..fbedb23253 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -808,7 +808,7 @@ private void inspectReactorEResource(ReactorDecl reactor) { // Copy the user files and cmake-includes to the src-gen path of the main .lf file copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); // Merge the CMake includes from the imported file into the target config - lfResource.getTargetConfig().cmakeIncludes.stream().forEach(incl -> { + lfResource.getTargetConfig().cmakeIncludes.forEach(incl -> { if (!this.targetConfig.cmakeIncludes.contains(incl)) { this.targetConfig.cmakeIncludes.add(incl); } From 8c5cab94ac365f302018e1cfbf0c6f55216fb2d1 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 28 Apr 2023 23:19:51 -0700 Subject: [PATCH 206/709] Revert "Added test for resource-based file include for federated" This reverts commit a2339df9f86ab11715aa697edf51ead899fe6c70. --- test/C/src/federated/FederatedFileInclude.lf | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 test/C/src/federated/FederatedFileInclude.lf diff --git a/test/C/src/federated/FederatedFileInclude.lf b/test/C/src/federated/FederatedFileInclude.lf deleted file mode 100644 index 02b2d261bf..0000000000 --- a/test/C/src/federated/FederatedFileInclude.lf +++ /dev/null @@ -1,13 +0,0 @@ -/** Success here is just successfully compiling. */ -target C { - files: "/lib/c/reactor-c/util/sensor_simulator.h", - timeout: 1s -} -reactor Foo { - reaction(startup) {= - lf_print("Hello World"); - =} -} -federated reactor { - f = new Foo() -} \ No newline at end of file From 49d3ba9fd15de7bcb354cb0db93f0bc67b843cdf Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 29 Apr 2023 11:28:53 +0200 Subject: [PATCH 207/709] Watcher cannot watch its own reactions --- test/C/src/Watchdog.lf | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index e40157a9e6..a836c93c3f 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -11,14 +11,13 @@ target C { reactor Watcher(timeout: time = 150 ms) { timer t(100 ms, 100 ms) // Offset ameliorates startup time. + // Period has to be smaller than watchdog timeout. output d: int // Produced if the watchdog triggers. - state alternating: bool = false state count: int = 0 watchdog poodle(timeout) {= - instant_t p = lf_time_physical_elapsed() - lf_time_logical_elapsed(); - lf_print("Watchdog timed out! Lag: %lld (too late by " PRINTF_TIME " ns)", p, p - self->timeout); - lf_print("At logical time inside watchdog panic: " PRINTF_TIME, lf_time_logical_elapsed()); + instant_t p = lf_time_physical_elapsed(); + lf_print("******** Watchdog timed out at elapsed physical time: " PRINTF_TIME, p); self->count++; =} @@ -26,10 +25,7 @@ reactor Watcher(timeout: time = 150 ms) { lf_watchdog_start(poodle, 0); lf_print("Watchdog started at physical time " PRINTF_TIME, lf_time_physical_elapsed()); lf_print("Will expire at " PRINTF_TIME, lf_time_logical_elapsed() + self->timeout); - if (self->alternating) { - lf_sleep(MSEC(160)); - } - self->alternating = !self->alternating; + lf_set(d, 42); =} reaction(poodle) -> d {= @@ -39,8 +35,8 @@ reactor Watcher(timeout: time = 150 ms) { reaction(shutdown) -> poodle {= lf_watchdog_stop(poodle); - if (self->count != 5) { - lf_print_error_and_exit("Watchdog expired %d times. Expected 5.", self->count); + if (self->count != 2) { + lf_print_error_and_exit("Watchdog expired %d times. Expected 2.", self->count); } =} } @@ -52,13 +48,17 @@ main reactor { w = new Watcher() reaction(w.d) {= - lf_print("*** Watcher reactor produced an output."); + lf_print("Watcher reactor produced an output. %d", self->count % 2); self->count++; + if (self->count % 4 == 0) { + lf_print(">>>>>> Taking a long time to process that output!"); + lf_sleep(MSEC(160)); + } =} reaction(shutdown) {= - if (self->count != 5) { - lf_print_error_and_exit("Watchdog produced output %d times. Expected 5.", self->count); + if (self->count != 12) { + lf_print_error_and_exit("Watchdog produced output %d times. Expected 12.", self->count); } =} } From 661df8802900db14666b8b5134495b681768852a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 29 Apr 2023 11:29:34 +0200 Subject: [PATCH 208/709] Continued refactoring and docs --- org.lflang/src/lib/c/reactor-c | 2 +- .../org/lflang/generator/c/CGenerator.java | 35 +-- .../generator/c/CReactionGenerator.java | 6 + .../generator/c/CWatchdogGenerator.java | 272 +++++++++++------- 4 files changed, 177 insertions(+), 138 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 5d58c62cb1..68e2c14fab 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 5d58c62cb141e13c423cdadd11dbf97c8edd2d75 +Subproject commit 68e2c14fabf124f280e656e23f1954df1fd80657 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 44691e773b..3a3352aa03 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -72,7 +72,6 @@ import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; import org.lflang.generator.TriggerInstance; -import org.lflang.generator.WatchdogInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Input; @@ -86,7 +85,6 @@ import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; import org.lflang.lf.Variable; -import org.lflang.lf.Watchdog; import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; @@ -1441,37 +1439,6 @@ private void recordBuiltinTriggers(ReactorInstance instance) { } } - private void recordWatchdogs(ReactorInstance instance) { - var foundOne = false; - var temp = new CodeBuilder(); - var reactorRef = CUtil.reactorRef(instance); - // temp.pr("#ifdef LF_THREADED"); - for (Watchdog watchdog - : ASTUtils.allWatchdogs(ASTUtils.toDefinition(instance.getDefinition().getReactorClass()))) { - temp.pr( - " _lf_watchdogs[_lf_watchdog_number_count++] = &" - + reactorRef - + "->_lf_watchdog_" - + watchdog.getName() - + ";"); - temp.pr( - " " - + reactorRef - + "->_lf_watchdog_" - + watchdog.getName() - + ".min_expiration = " - + CTypes.getInstance().getTargetTimeExpr(instance.getTimeValue(watchdog.getTimeout())) - + ";"); - temp.pr(" " + reactorRef + "->_lf_watchdog_" + watchdog.getName() + ".thread_id;"); - watchdogCount += 1; - foundOne = true; - } - // temp.pr("#endif"); - if (foundOne) { - initializeTriggerObjects.pr(temp.toString()); - } - } - /** * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts * and mark outputs absent between time steps. This function puts the code into startTimeStep. @@ -1746,7 +1713,7 @@ public void generateReactorInstance(ReactorInstance instance) { initializeOutputMultiports(instance); initializeInputMultiports(instance); recordBuiltinTriggers(instance); - recordWatchdogs(instance); + watchdogCount += CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); // Next, initialize the "self" struct with state variables. // These values may be expressions that refer to the parameter values defined above. diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index dae1f01230..a203f9ee3c 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1377,6 +1377,12 @@ public static String generateStpFunctionHeader(Reactor r, int reactionIndex) { return generateFunctionHeader(functionName); } + /** + * Return the start of a function declaration for a function that takes + * a `void*` argument and returns void. + * @param functionName + * @return + */ public static String generateFunctionHeader(String functionName) { return "void " + functionName + "(void* instance_args)"; } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 5bd0fe648d..695bd5eefa 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -1,8 +1,17 @@ +/** + * @file + * @author Benjamin Asch + * @author Edward A. Lee + * @copyright (c) 2023, The University of California at Berkeley. + * License: BSD 2-clause + * @brief Code generation methods for watchdogs in C. + */ package org.lflang.generator.c; import java.util.List; import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.ReactorInstance; import org.lflang.lf.Mode; import org.lflang.lf.ModeTransition; import org.lflang.lf.Reactor; @@ -12,22 +21,77 @@ import org.lflang.lf.Watchdog; /** - * Generates necessary C code for watchdogs. + * @brief Generate C code for watchdogs. + * This class contains a collection of static methods supporting code generation in C + * for watchdogs. These methods are protected because they are intended to be used + * only within the same package. * - * @author{Benjamin Asch } + * @author Benjamin Asch + * @author Edward A. Lee */ public class CWatchdogGenerator { + /** + * Return true if the given reactor has one or more watchdogs. + * @param reactor The reactor. + * @return True if the given reactor has watchdogs. + */ + public static boolean hasWatchdogs(Reactor reactor) { + List watchdogs = ASTUtils.allWatchdogs(reactor); + if (watchdogs != null && !watchdogs.isEmpty()) return true; + return false; + } + + ///////////////////////////////////////////////////////////////// + // Protected methods + + /** + * For the specified reactor instance, generate initialization code for each watchdog + * in the reactor. This code initializes the watchdog-related fields on the self struct + * of the reactor instance. + * @param code The place to put the code + * @param instance The reactor instance + * @return The count of watchdogs found in the reactor + */ + protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstance instance) { + var foundOne = false; + var temp = new CodeBuilder(); + var reactorRef = CUtil.reactorRef(instance); + int watchdogCount = 0; + for (Watchdog watchdog + : ASTUtils.allWatchdogs(ASTUtils.toDefinition(instance.getDefinition().getReactorClass()))) { + var watchdogField = reactorRef + "->_lf_watchdog_" + watchdog.getName(); + temp.pr(String.join("\n", + "_lf_watchdogs[_lf_watchdog_number_count++] = &" + watchdogField + ";", + watchdogField + ".min_expiration = " + + CTypes.getInstance().getTargetTimeExpr(instance.getTimeValue(watchdog.getTimeout())) + + ";", + watchdogField + ".thread_active = false;", + "if (" + watchdogField + ".base->reactor_mutex == NULL) {", + " " + watchdogField + ".base->reactor_mutex = (lf_mutex_t*)calloc(1, sizeof(lf_mutex_t));", + "}" + )); + watchdogCount += 1; + foundOne = true; + } + // temp.pr("#endif"); + if (foundOne) { + code.pr(temp.toString()); + } + code.pr("SUPPRESS_UNUSED_WARNING(_lf_watchdog_number);"); + return watchdogCount; + } + /** * Generate watchdog functions definition for a reactor. These functions have a single argument - * that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. + * that is a void* pointing to the self struct of the reactor, which contains parameters, state + * variables, inputs (triggering or not), actions (triggering or produced), and outputs. * - * @param src The place to put the code. - * @param header The place to put header code. - * @param decl The reactor declaration. + * @param src The place to put the code + * @param header The place to put header code + * @param decl The reactor declaration */ - public static void generateWatchdogs(CodeBuilder src, CodeBuilder header, ReactorDecl decl) { + protected static void generateWatchdogs(CodeBuilder src, CodeBuilder header, ReactorDecl decl) { var reactor = ASTUtils.toDefinition(decl); if (hasWatchdogs(reactor)) { header.pr("#include \"core/threaded/watchdog.h\""); @@ -38,23 +102,78 @@ public static void generateWatchdogs(CodeBuilder src, CodeBuilder header, Reacto } /** - * Return true if the given reactor has one or more watchdogs. - * @param reactor The reactor. - * @return True if the given reactor has watchdogs. + * Generate watchdog definitions in the reactor's self struct. + * @param body The place to put the definitions + * @param decl The reactor declaration + * @param constructorCode The place to put initialization code. */ - public static boolean hasWatchdogs(Reactor reactor) { - List watchdogs = ASTUtils.allWatchdogs(reactor); - if (watchdogs != null && !watchdogs.isEmpty()) return true; - return false; + protected static void generateWatchdogStruct( + CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = ASTUtils.toDefinition(decl); + + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + String watchdogName = watchdog.getName(); + + body.pr(watchdog, "watchdog_t _lf_watchdog_" + watchdogName + ";"); + + // watchdog function name + var watchdogFunctionName = watchdogFunctionName(watchdog, decl); + // Set values of watchdog_t struct in the reactor's constructor. + constructorCode.pr( + watchdog, + String.join( + "\n", + "self->_lf_watchdog_" + watchdogName + ".base = &(self->base);", + "self->_lf_watchdog_" + watchdogName + ".expiration = NEVER;", + "self->_lf_watchdog_" + watchdogName + ".thread_active = false;", + "self->_lf_watchdog_" + + watchdogName + + ".watchdog_function = " + + watchdogFunctionName + + ";", + "self->_lf_watchdog_" + + watchdogName + + ".trigger = &(self->_lf__" + + watchdogName + + ");" + ) + ); + } } /** - * Generate necessary initialization code inside the body of the watchdog that belongs to reactor - * decl. + * Generate a global table of watchdog structs. + * @param count The number of watchdogs found. + * @return The code that defines the table or a comment if count is 0. + */ + protected static String generateWatchdogTable(int count) { + if (count == 0) { + return String.join("\n", + "// No watchdogs found.", + "watchdog_t* _lf_watchdogs = NULL;", + "int _lf_watchdog_number = 0;" + ); + } + return String.join( + "\n", + List.of( + "// Array of pointers to watchdog structs.", + "watchdog_t* _lf_watchdogs[" + count + "];", + "int _lf_watchdog_number = " + count + ";" + ) + ); + } + + ///////////////////////////////////////////////////////////////// + // Private methods + + /** + * Generate necessary initialization code inside the body of a watchdog handler. * - * @param decl The reactor that has the watchdog + * @param watchdog The wotchdog + * @param decl The declaration for the reactor that has the watchdog */ - public static String generateInitializationForWatchdog(Watchdog watchdog, ReactorDecl decl) { + private static String generateInitializationForWatchdog(Watchdog watchdog, ReactorDecl decl) { Reactor reactor = ASTUtils.toDefinition(decl); // Construct the reactionInitialization code to go into @@ -96,8 +215,8 @@ public static String generateInitializationForWatchdog(Watchdog watchdog, Reacto + name + "_change_type = " + (effect.getTransition() == ModeTransition.HISTORY - ? "history_transition" - : "reset_transition") + ? "history_transition" + : "reset_transition") + ";"); } // FIXME: include error reporter @@ -124,47 +243,13 @@ public static String generateInitializationForWatchdog(Watchdog watchdog, Reacto } /** - * Returns the name of the watchdog function for reaction. - * - * @param decl The reactor with the watchdog - * @param watchdog The watchdog - * @return Name of the watchdog function for reaction - */ - public static String generateWatchdogFunctionName(Watchdog watchdog, ReactorDecl decl) { - return decl.getName().toLowerCase() - + "_" - + watchdog.getName().toLowerCase() - + "_watchdog_function"; - } - - /** - * Return the top level C function header for the watchdog function in "decl" - * - * @param decl The reactor declaration - * @param watchdog The watchdog. - * @return The function name for the watchdog function. - */ - public static String generateWatchdogFunctionHeader(Watchdog watchdog, ReactorDecl decl) { - String functionName = generateWatchdogFunctionName(watchdog, decl); - return CReactionGenerator.generateFunctionHeader(functionName); - } - - /** Generate the watchdog function. */ - public static String generateWatchdogFunction(Watchdog watchdog, ReactorDecl decl) { - return generateFunction( - generateWatchdogFunctionHeader(watchdog, decl), - generateInitializationForWatchdog(watchdog, decl), - watchdog); - } - - /** - * Do heavy lifting to generate above watchdog function + * Do heavy lifting to generate the watchdog handler function * * @param header function name and declaration. * @param init initialize variable. * @param watchdog The watchdog. */ - public static String generateFunction(String header, String init, Watchdog watchdog) { + private static String generateFunction(String header, String init, Watchdog watchdog) { var function = new CodeBuilder(); function.pr(header + " {"); function.indent(); @@ -177,57 +262,38 @@ public static String generateFunction(String header, String init, Watchdog watch return function.toString(); } - /** Generate watchdog definition in the reactor's self struct. */ - public static void generateWatchdogStruct( - CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { - var reactor = ASTUtils.toDefinition(decl); - - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - String watchdogName = watchdog.getName(); - body.pr(watchdog, "watchdog_t _lf_watchdog_" + watchdogName + ";"); + /** Generate the watchdog handler function. */ + private static String generateWatchdogFunction(Watchdog watchdog, ReactorDecl decl) { + return generateFunction( + generateWatchdogFunctionHeader(watchdog, decl), + generateInitializationForWatchdog(watchdog, decl), + watchdog); + } - // watchdog function name - var watchdogFunctionName = generateWatchdogFunctionName(watchdog, decl); - // Set values of watchdog_t struct in the reactor's constructor - // FIXME: update parameters - constructorCode.pr( - watchdog, - String.join( - "\n", - "self->_lf_watchdog_" + watchdogName + ".base = &(self->base);", - "self->_lf_watchdog_" + watchdogName + ".expiration = NEVER;", - "self->_lf_watchdog_" + watchdogName + ".thread_active = false;", - "self->_lf_watchdog_" - + watchdogName - + ".watchdog_function = " - + watchdogFunctionName - + ";", - "self->_lf_watchdog_" - + watchdogName - + ".trigger = &(self->_lf__" - + watchdogName - + ");" - ) - ); - } + /** + * Return the start of a C function definition for a watchdog. + * + * @param watchdog The watchdog + * @param decl The reactor declaration + * @return The function name for the watchdog function. + */ + private static String generateWatchdogFunctionHeader(Watchdog watchdog, ReactorDecl decl) { + String functionName = watchdogFunctionName(watchdog, decl); + return CReactionGenerator.generateFunctionHeader(functionName); } /** - * Generate a global table of watchdog structs. - * @param count The number of watchdogs found. - * @return The code that defines the table or a comment if count is 0. + * Return the name of the watchdog expiration handler function. + * + * @param watchdog The watchdog + * @param decl The reactor with the watchdog + * @return Name of the watchdog handler function */ - public static String generateWatchdogTable(int count) { - if (count == 0) { - return "// No watchdogs found."; - } - return String.join( - "\n", - List.of( - "// Array of pointers to watchdog structs.", - " watchdog_t* _lf_watchdogs[" + count + "];", - " int _lf_watchdog_number = " + count + ";" - )); + private static String watchdogFunctionName(Watchdog watchdog, ReactorDecl decl) { + return decl.getName().toLowerCase() + + "_" + + watchdog.getName().toLowerCase() + + "_watchdog_function"; } } From 95a7116ee548a0781efdd384b871cd564f679eff Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 30 Apr 2023 09:37:12 +0200 Subject: [PATCH 209/709] Aligned reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 68e2c14fab..97466da394 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 68e2c14fabf124f280e656e23f1954df1fd80657 +Subproject commit 97466da394d9572e4ba905b2706759bef73c0af0 From 4a5582524869a886a76fcde0159bcd37283eb1e2 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 30 Apr 2023 10:45:32 +0200 Subject: [PATCH 210/709] Manually reverted formatting changes. --- org.lflang/src/org/lflang/ASTUtils.java | 3312 ++++++++++++----------- 1 file changed, 1696 insertions(+), 1616 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 4606b4d35f..f8c436727c 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -1,12 +1,16 @@ /* Copyright (c) 2020, The University of California at Berkeley. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -21,9 +25,6 @@ package org.lflang; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -31,6 +32,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -38,6 +40,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; + import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -58,6 +61,8 @@ import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Assignment; +import org.lflang.lf.AttrParm; +import org.lflang.lf.Attribute; import org.lflang.lf.Code; import org.lflang.lf.Connection; import org.lflang.lf.Element; @@ -91,1662 +96,1737 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; + /** * A helper class for modifying and analyzing the AST. - * * @author Marten Lohstroh * @author Edward A. Lee * @author Christian Menard */ public class ASTUtils { - /** The Lingua Franca factory for creating new AST nodes. */ - public static final LfFactory factory = LfFactory.eINSTANCE; - - /** The Lingua Franca feature package. */ - public static final LfPackage featurePackage = LfPackage.eINSTANCE; - - /* Match an abbreviated form of a float literal. */ - private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); - - /** - * A mapping from Reactor features to corresponding Mode features for collecting contained - * elements. - */ - private static final Map reactorModeFeatureMap = - Map.of( - featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), - featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), - featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), - featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), - featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), - featurePackage.getReactor_Timers(), featurePackage.getMode_Timers(), - featurePackage.getReactor_Watchdogs(), featurePackage.getMode_Watchdogs()); - - /** - * Get all reactors defined in the given resource. - * - * @param resource the resource to extract reactors from - * @return An iterable over all reactors found in the resource - */ - public static List getAllReactors(Resource resource) { - return StreamSupport.stream( - IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) - .filter(Reactor.class::isInstance) - .map(Reactor.class::cast) - .collect(Collectors.toList()); - } - - /** - * Find connections in the given resource that would be conflicting writes if they were not - * located in mutually exclusive modes. - * - * @param resource The AST. - * @return a list of connections being able to be transformed - */ - public static Collection findConflictingConnectionsInModalReactors( - Resource resource) { - var transform = new HashSet(); - - for (Reactor reactor : getAllReactors(resource)) { - if (!reactor.getModes().isEmpty()) { // Only for modal reactors - var allWriters = HashMultimap., EObject>create(); - - // Collect destinations - for (var rea : allReactions(reactor)) { - for (var eff : rea.getEffects()) { - if (eff.getVariable() instanceof Port) { - allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); + /** + * The Lingua Franca factory for creating new AST nodes. + */ + public static final LfFactory factory = LfFactory.eINSTANCE; + + /** + * The Lingua Franca feature package. + */ + public static final LfPackage featurePackage = LfPackage.eINSTANCE; + + /* Match an abbreviated form of a float literal. */ + private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); + + /** + * A mapping from Reactor features to corresponding Mode features for collecting contained elements. + */ + private static final Map reactorModeFeatureMap = Map.of( + featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), + featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), + featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), + featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), + featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), + featurePackage.getReactor_Timers(), featurePackage.getMode_Timers() + ); + + + /** + * Get all reactors defined in the given resource. + * @param resource the resource to extract reactors from + * @return An iterable over all reactors found in the resource + */ + public static List getAllReactors(Resource resource) { + return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) + .filter(Reactor.class::isInstance) + .map(Reactor.class::cast) + .collect(Collectors.toList()); + } + + /** + * Find connections in the given resource that would be conflicting writes if they were not located in mutually + * exclusive modes. + * + * @param resource The AST. + * @return a list of connections being able to be transformed + */ + public static Collection findConflictingConnectionsInModalReactors(Resource resource) { + var transform = new HashSet(); + + for (Reactor reactor : getAllReactors(resource)) { + if (!reactor.getModes().isEmpty()) { // Only for modal reactors + var allWriters = HashMultimap., EObject>create(); + + // Collect destinations + for (var rea : allReactions(reactor)) { + for (var eff : rea.getEffects()) { + if (eff.getVariable() instanceof Port) { + allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); + } + } + } + for (var con : ASTUtils.collectElements(reactor, featurePackage.getReactor_Connections(), false, true)) { + for (var port : con.getRightPorts()) { + allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); + } + } + + // Handle conflicting writers + for (var key : allWriters.keySet()) { + var writers = allWriters.get(key); + if (writers.size() > 1) { // has multiple sources + var writerModes = HashMultimap.create(); + // find modes + for (var writer : writers) { + if (writer.eContainer() instanceof Mode) { + writerModes.put((Mode) writer.eContainer(), writer); + } else { + writerModes.put(null, writer); + } + } + // Conflicting connection can only be handled if.. + if (!writerModes.containsKey(null) && // no writer is on root level (outside of modes) and... + writerModes.keySet().stream().map(writerModes::get).allMatch(writersInMode -> // all writers in a mode are either... + writersInMode.size() == 1 || // the only writer or... + writersInMode.stream().allMatch(w -> w instanceof Reaction) // all are reactions and hence ordered + )) { + // Add connections to transform list + writers.stream().filter(w -> w instanceof Connection).forEach(c -> transform.add((Connection) c)); + } + } + } } - } } - for (var con : - ASTUtils.collectElements( - reactor, featurePackage.getReactor_Connections(), false, true)) { - for (var port : con.getRightPorts()) { - allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); - } + + return transform; + } + + /** + * Return the enclosing reactor of an LF EObject in a reactor or mode. + * @param obj the LF model element + * @return the reactor or null + */ + public static Reactor getEnclosingReactor(EObject obj) { + if (obj.eContainer() instanceof Reactor) { + return (Reactor) obj.eContainer(); + } else if (obj.eContainer() instanceof Mode) { + return (Reactor) obj.eContainer().eContainer(); + } + return null; + } + + /** + * Return the main reactor in the given resource if there is one, null otherwise. + */ + public static Reactor findMainReactor(Resource resource) { + return IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), + Reactor::isMain + ); + } + + /** + * Find the main reactor and change it to a federated reactor. + * Return true if the transformation was successful (or the given resource + * already had a federated reactor); return false otherwise. + */ + public static boolean makeFederated(Resource resource) { + // Find the main reactor + Reactor r = findMainReactor(resource); + if (r == null) { + return false; + } + r.setMain(false); + r.setFederated(true); + return true; + } + + /** + * Change the target name to 'newTargetName'. + * For example, change C to CCpp. + */ + public static boolean changeTargetName(Resource resource, String newTargetName) { + targetDecl(resource).setName(newTargetName); + return true; + } + + /** + * Return the target of the file in which the given node lives. + */ + public static Target getTarget(EObject object) { + TargetDecl targetDecl = targetDecl(object.eResource()); + return Target.fromDecl(targetDecl); + } + + /** + * Add a new target property to the given resource. + * + * This also creates a config object if the resource does not yey have one. + * + * @param resource The resource to modify + * @param name Name of the property to add + * @param value Value to be assigned to the property + */ + public static boolean addTargetProperty(final Resource resource, final String name, final Element value) { + var config = targetDecl(resource).getConfig(); + if (config == null) { + config = LfFactory.eINSTANCE.createKeyValuePairs(); + targetDecl(resource).setConfig(config); + } + final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); + newProperty.setName(name); + newProperty.setValue(value); + config.getPairs().add(newProperty); + return true; + } + + /** + * Return true if the connection involves multiple ports on the left or right side of the connection, or + * if the port on the left or right of the connection involves a bank of reactors or a multiport. + * @param connection The connection. + */ + public static boolean hasMultipleConnections(Connection connection) { + if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { + return true; } + VarRef leftPort = connection.getLeftPorts().get(0); + VarRef rightPort = connection.getRightPorts().get(0); + Instantiation leftContainer = leftPort.getContainer(); + Instantiation rightContainer = rightPort.getContainer(); + Port leftPortAsPort = (Port) leftPort.getVariable(); + Port rightPortAsPort = (Port) rightPort.getVariable(); + return leftPortAsPort.getWidthSpec() != null + || leftContainer != null && leftContainer.getWidthSpec() != null + || rightPortAsPort.getWidthSpec() != null + || rightContainer != null && rightContainer.getWidthSpec() != null; + } + + /** + * Produce a unique identifier within a reactor based on a + * given based name. If the name does not exists, it is returned; + * if does exist, an index is appended that makes the name unique. + * @param reactor The reactor to find a unique identifier within. + * @param name The name to base the returned identifier on. + */ + public static String getUniqueIdentifier(Reactor reactor, String name) { + LinkedHashSet vars = new LinkedHashSet<>(); + allActions(reactor).forEach(it -> vars.add(it.getName())); + allTimers(reactor).forEach(it -> vars.add(it.getName())); + allParameters(reactor).forEach(it -> vars.add(it.getName())); + allInputs(reactor).forEach(it -> vars.add(it.getName())); + allOutputs(reactor).forEach(it -> vars.add(it.getName())); + allStateVars(reactor).forEach(it -> vars.add(it.getName())); + allInstantiations(reactor).forEach(it -> vars.add(it.getName())); + + int index = 0; + String suffix = ""; + boolean exists = true; + while (exists) { + String id = name + suffix; + if (IterableExtensions.exists(vars, it -> it.equals(id))) { + suffix = "_" + index; + index++; + } else { + exists = false; + } + } + return name + suffix; + } + + //////////////////////////////// + //// Utility functions for supporting inheritance and modes + + /** + * Given a reactor class, return a list of all its actions, + * which includes actions of base classes that it extends. + * This also includes actions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allActions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); + } + + /** + * Given a reactor class, return a list of all its connections, + * which includes connections of base classes that it extends. + * This also includes connections in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allConnections(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); + } + + /** + * Given a reactor class, return a list of all its inputs, + * which includes inputs of base classes that it extends. + * If the base classes include a cycle, where X extends Y and Y extends X, + * then return only the input defined in the base class. + * The returned list may be empty. + * @param definition Reactor class definition. + */ + public static List allInputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); + } + + /** A list of all ports of {@code definition}, in an unspecified order. */ + public static List allPorts(Reactor definition) { + return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); + } + + /** + * Given a reactor class, return a list of all its instantiations, + * which includes instantiations of base classes that it extends. + * This also includes instantiations in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allInstantiations(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); + } + + public static Stream allNestedClasses(Reactor definition) { + return new HashSet<>(ASTUtils.allInstantiations(definition)).stream() + .map(Instantiation::getReactorClass) + .map(ASTUtils::toDefinition); + } + + /** + * Given a reactor class, return a list of all its methods, + * which includes methods of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allMethods(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); + } + + /** + * Given a reactor class, return a list of all its outputs, + * which includes outputs of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allOutputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); + } + + /** + * Given a reactor class, return a list of all its parameters, + * which includes parameters of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allParameters(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); + } + + /** + * Given a reactor class, return a list of all its reactions, + * which includes reactions of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allReactions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); + } + + /** + * Given a reactor class, return a list of all its watchdogs. + * + * @param definition Reactor class definition + * @return List + */ + public static List allWatchdogs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); + } + + /** + * Given a reactor class, return a list of all its state variables, + * which includes state variables of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allStateVars(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); + } + + /** + * Given a reactor class, return a list of all its timers, + * which includes timers of base classes that it extends. + * This also includes reactions in modes, returning a flattened + * view over all modes. + * @param definition Reactor class definition. + */ + public static List allTimers(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); + } + + /** + * Given a reactor class, returns a list of all its modes, + * which includes modes of base classes that it extends. + * @param definition Reactor class definition. + */ + public static List allModes(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); + } + + /** A list of all reactors instantiated, transitively or intransitively, by {@code r}. */ + public static List recursiveChildren(ReactorInstance r) { + List ret = new ArrayList<>(); + ret.add(r.reactorDefinition); + for (var child : r.children) { + ret.addAll(recursiveChildren(child)); + } + return ret; + } + + /** + * Return all the superclasses of the specified reactor + * in deepest-first order. For example, if A extends B and C, and + * B and C both extend D, this will return the list [D, B, C, A]. + * Duplicates are removed. If the specified reactor does not extend + * any other reactor, then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + */ + public static LinkedHashSet superClasses(Reactor reactor) { + return superClasses(reactor, new LinkedHashSet<>()); + } - // Handle conflicting writers - for (var key : allWriters.keySet()) { - var writers = allWriters.get(key); - if (writers.size() > 1) { // has multiple sources - var writerModes = HashMultimap.create(); - // find modes - for (var writer : writers) { - if (writer.eContainer() instanceof Mode) { - writerModes.put((Mode) writer.eContainer(), writer); - } else { - writerModes.put(null, writer); - } + /** + * Collect elements of type T from the class hierarchy and modes + * defined by a given reactor definition. + * @param definition The reactor definition. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + public static List collectElements(Reactor definition, EStructuralFeature feature) { + return ASTUtils.collectElements(definition, feature, true, true); + } + + /** + * Collect elements of type T contained in given reactor definition, including + * modes and the class hierarchy defined depending on configuration. + * @param definition The reactor definition. + * @param feature The structual model elements to collect. + * @param includeSuperClasses Whether to include elements in super classes. + * @param includeModes Whether to include elements in modes. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + @SuppressWarnings("unchecked") + public static List collectElements(Reactor definition, EStructuralFeature feature, boolean includeSuperClasses, boolean includeModes) { + List result = new ArrayList<>(); + + if (includeSuperClasses) { + // Add elements of elements defined in superclasses. + LinkedHashSet s = superClasses(definition); + if (s != null) { + for (Reactor superClass : s) { + result.addAll((EList) superClass.eGet(feature)); + } } - // Conflicting connection can only be handled if.. - if (!writerModes.containsKey(null) - && // no writer is on root level (outside of modes) and... - writerModes.keySet().stream() - .map(writerModes::get) - .allMatch( - writersInMode -> // all writers in a mode are either... - writersInMode.size() == 1 - || // the only writer or... - writersInMode.stream() - .allMatch( - w -> - w - instanceof - Reaction) // all are reactions and hence ordered - )) { - // Add connections to transform list - writers.stream() - .filter(w -> w instanceof Connection) - .forEach(c -> transform.add((Connection) c)); + } + + // Add elements of the current reactor. + result.addAll((EList) definition.eGet(feature)); + + if (includeModes && reactorModeFeatureMap.containsKey(feature)) { + var modeFeature = reactorModeFeatureMap.get(feature); + // Add elements of elements defined in modes. + for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { + insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); } - } } - } - } - - return transform; - } - - /** - * Return the enclosing reactor of an LF EObject in a reactor or mode. - * - * @param obj the LF model element - * @return the reactor or null - */ - public static Reactor getEnclosingReactor(EObject obj) { - if (obj.eContainer() instanceof Reactor) { - return (Reactor) obj.eContainer(); - } else if (obj.eContainer() instanceof Mode) { - return (Reactor) obj.eContainer().eContainer(); - } - return null; - } - - /** Return the main reactor in the given resource if there is one, null otherwise. */ - public static Reactor findMainReactor(Resource resource) { - return IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), Reactor::isMain); - } - - /** - * Find the main reactor and change it to a federated reactor. Return true if the transformation - * was successful (or the given resource already had a federated reactor); return false otherwise. - */ - public static boolean makeFederated(Resource resource) { - // Find the main reactor - Reactor r = findMainReactor(resource); - if (r == null) { - return false; - } - r.setMain(false); - r.setFederated(true); - return true; - } - - /** Change the target name to 'newTargetName'. For example, change C to CCpp. */ - public static boolean changeTargetName(Resource resource, String newTargetName) { - targetDecl(resource).setName(newTargetName); - return true; - } - - /** Return the target of the file in which the given node lives. */ - public static Target getTarget(EObject object) { - TargetDecl targetDecl = targetDecl(object.eResource()); - return Target.fromDecl(targetDecl); - } - - /** - * Add a new target property to the given resource. - * - *

This also creates a config object if the resource does not yey have one. - * - * @param resource The resource to modify - * @param name Name of the property to add - * @param value Value to be assigned to the property - */ - public static boolean addTargetProperty( - final Resource resource, final String name, final Element value) { - var config = targetDecl(resource).getConfig(); - if (config == null) { - config = LfFactory.eINSTANCE.createKeyValuePairs(); - targetDecl(resource).setConfig(config); - } - final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); - newProperty.setName(name); - newProperty.setValue(value); - config.getPairs().add(newProperty); - return true; - } - - /** - * Return true if the connection involves multiple ports on the left or right side of the - * connection, or if the port on the left or right of the connection involves a bank of reactors - * or a multiport. - * - * @param connection The connection. - */ - public static boolean hasMultipleConnections(Connection connection) { - if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { - return true; - } - VarRef leftPort = connection.getLeftPorts().get(0); - VarRef rightPort = connection.getRightPorts().get(0); - Instantiation leftContainer = leftPort.getContainer(); - Instantiation rightContainer = rightPort.getContainer(); - Port leftPortAsPort = (Port) leftPort.getVariable(); - Port rightPortAsPort = (Port) rightPort.getVariable(); - return leftPortAsPort.getWidthSpec() != null - || leftContainer != null && leftContainer.getWidthSpec() != null - || rightPortAsPort.getWidthSpec() != null - || rightContainer != null && rightContainer.getWidthSpec() != null; - } - - /** - * Produce a unique identifier within a reactor based on a given based name. If the name does not - * exists, it is returned; if does exist, an index is appended that makes the name unique. - * - * @param reactor The reactor to find a unique identifier within. - * @param name The name to base the returned identifier on. - */ - public static String getUniqueIdentifier(Reactor reactor, String name) { - LinkedHashSet vars = new LinkedHashSet<>(); - allActions(reactor).forEach(it -> vars.add(it.getName())); - allTimers(reactor).forEach(it -> vars.add(it.getName())); - allParameters(reactor).forEach(it -> vars.add(it.getName())); - allInputs(reactor).forEach(it -> vars.add(it.getName())); - allOutputs(reactor).forEach(it -> vars.add(it.getName())); - allStateVars(reactor).forEach(it -> vars.add(it.getName())); - allInstantiations(reactor).forEach(it -> vars.add(it.getName())); - - int index = 0; - String suffix = ""; - boolean exists = true; - while (exists) { - String id = name + suffix; - if (IterableExtensions.exists(vars, it -> it.equals(id))) { - suffix = "_" + index; - index++; - } else { - exists = false; - } - } - return name + suffix; - } - - //////////////////////////////// - //// Utility functions for supporting inheritance and modes - - /** - * Given a reactor class, return a list of all its actions, which includes actions of base classes - * that it extends. This also includes actions in modes, returning a flattened view over all - * modes. - * - * @param definition Reactor class definition. - */ - public static List allActions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); - } - - /** - * Given a reactor class, return a list of all its connections, which includes connections of base - * classes that it extends. This also includes connections in modes, returning a flattened view - * over all modes. - * - * @param definition Reactor class definition. - */ - public static List allConnections(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); - } - - /** - * Given a reactor class, return a list of all its inputs, which includes inputs of base classes - * that it extends. If the base classes include a cycle, where X extends Y and Y extends X, then - * return only the input defined in the base class. The returned list may be empty. - * - * @param definition Reactor class definition. - */ - public static List allInputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); - } - - /** A list of all ports of {@code definition}, in an unspecified order. */ - public static List allPorts(Reactor definition) { - return Stream.concat( - ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()) - .toList(); - } - - /** - * Given a reactor class, return a list of all its instantiations, which includes instantiations - * of base classes that it extends. This also includes instantiations in modes, returning a - * flattened view over all modes. - * - * @param definition Reactor class definition. - */ - public static List allInstantiations(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); - } - - public static Stream allNestedClasses(Reactor definition) { - return new HashSet<>(ASTUtils.allInstantiations(definition)) - .stream().map(Instantiation::getReactorClass).map(ASTUtils::toDefinition); - } - - /** - * Given a reactor class, return a list of all its methods, which includes methods of base classes - * that it extends. - * - * @param definition Reactor class definition. - */ - public static List allMethods(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); - } - - /** - * Given a reactor class, return a list of all its outputs, which includes outputs of base classes - * that it extends. - * - * @param definition Reactor class definition. - */ - public static List allOutputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); - } - - /** - * Given a reactor class, return a list of all its parameters, which includes parameters of base - * classes that it extends. - * - * @param definition Reactor class definition. - */ - public static List allParameters(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); - } - - /** - * Given a reactor class, return a list of all its reactions, which includes reactions of base - * classes that it extends. This also includes reactions in modes, returning a flattened view over - * all modes. - * - * @param definition Reactor class definition. - */ - public static List allReactions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); - } - - /** - * Given a reactor class, return a list of all its watchdogs. - * - * @param definition Reactor class definition - * @return List - */ - public static List allWatchdogs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); - } - - /** - * Given a reactor class, return a list of all its state variables, which includes state variables - * of base classes that it extends. This also includes reactions in modes, returning a flattened - * view over all modes. - * - * @param definition Reactor class definition. - */ - public static List allStateVars(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); - } - - /** - * Given a reactor class, return a list of all its timers, which includes timers of base classes - * that it extends. This also includes reactions in modes, returning a flattened view over all - * modes. - * - * @param definition Reactor class definition. - */ - public static List allTimers(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); - } - - /** - * Given a reactor class, returns a list of all its modes, which includes modes of base classes - * that it extends. - * - * @param definition Reactor class definition. - */ - public static List allModes(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); - } - - /** A list of all reactors instantiated, transitively or intransitively, by {@code r}. */ - public static List recursiveChildren(ReactorInstance r) { - List ret = new ArrayList<>(); - ret.add(r.reactorDefinition); - for (var child : r.children) { - ret.addAll(recursiveChildren(child)); - } - return ret; - } - - /** - * Return all the superclasses of the specified reactor in deepest-first order. For example, if A - * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates - * are removed. If the specified reactor does not extend any other reactor, then return an empty - * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared - * that is not found, then return null. - * - * @param reactor The specified reactor. - */ - public static LinkedHashSet superClasses(Reactor reactor) { - return superClasses(reactor, new LinkedHashSet<>()); - } - - /** - * Collect elements of type T from the class hierarchy and modes defined by a given reactor - * definition. - * - * @param definition The reactor definition. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - public static List collectElements( - Reactor definition, EStructuralFeature feature) { - return ASTUtils.collectElements(definition, feature, true, true); - } - - /** - * Collect elements of type T contained in given reactor definition, including modes and the class - * hierarchy defined depending on configuration. - * - * @param definition The reactor definition. - * @param feature The structual model elements to collect. - * @param includeSuperClasses Whether to include elements in super classes. - * @param includeModes Whether to include elements in modes. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - @SuppressWarnings("unchecked") - public static List collectElements( - Reactor definition, - EStructuralFeature feature, - boolean includeSuperClasses, - boolean includeModes) { - List result = new ArrayList<>(); - - if (includeSuperClasses) { - // Add elements of elements defined in superclasses. - LinkedHashSet s = superClasses(definition); - if (s != null) { - for (Reactor superClass : s) { - result.addAll((EList) superClass.eGet(feature)); + + return result; + } + + /** + * Adds the elements into the given list at a location matching to their textual position. + * + * When creating a flat view onto reactor elements including modes, the final list must be ordered according + * to the textual positions. + * + * Example: + * reactor R { + * reaction // -> is R.reactions[0] + * mode M { + * reaction // -> is R.mode[0].reactions[0] + * reaction // -> is R.mode[0].reactions[1] + * } + * reaction // -> is R.reactions[1] + * } + * In this example, it is important that the reactions in the mode are inserted between the top-level + * reactions to retain the correct global reaction ordering, which will be derived from this flattened view. + * + * @param list The list to add the elements into. + * @param elements The elements to add. + * @param mode The mode containing the elements. + * @param The type of elements to add (e.g., Port, Timer, etc.) + */ + private static void insertModeElementsAtTextualPosition(List list, List elements, Mode mode) { + if (elements.isEmpty()) { + return; // Nothing to add } - } - } - - // Add elements of the current reactor. - result.addAll((EList) definition.eGet(feature)); - - if (includeModes && reactorModeFeatureMap.containsKey(feature)) { - var modeFeature = reactorModeFeatureMap.get(feature); - // Add elements of elements defined in modes. - for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { - insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); - } - } - - return result; - } - - /** - * Adds the elements into the given list at a location matching to their textual position. - * - *

When creating a flat view onto reactor elements including modes, the final list must be - * ordered according to the textual positions. - * - *

Example: reactor R { reaction // -> is R.reactions[0] mode M { reaction // -> is - * R.mode[0].reactions[0] reaction // -> is R.mode[0].reactions[1] } reaction // -> is - * R.reactions[1] } In this example, it is important that the reactions in the mode are inserted - * between the top-level reactions to retain the correct global reaction ordering, which will be - * derived from this flattened view. - * - * @param list The list to add the elements into. - * @param elements The elements to add. - * @param mode The mode containing the elements. - * @param The type of elements to add (e.g., Port, Timer, etc.) - */ - private static void insertModeElementsAtTextualPosition( - List list, List elements, Mode mode) { - if (elements.isEmpty()) { - return; // Nothing to add - } - - var idx = list.size(); - if (idx > 0) { - // If there are elements in the list, first check if the last element has the same container - // as the mode. - // I.e. we don't want to compare textual positions of different reactors (super classes) - if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { - var modeAstNode = NodeModelUtils.getNode(mode); - if (modeAstNode != null) { - var modePos = modeAstNode.getOffset(); - // Now move the insertion index from the last element forward as long as this element has - // a textual - // position after the mode. - do { - var astNode = NodeModelUtils.getNode(list.get(idx - 1)); - if (astNode != null && astNode.getOffset() > modePos) { - idx--; - } else { - break; // Insertion index is ok. + + var idx = list.size(); + if (idx > 0) { + // If there are elements in the list, first check if the last element has the same container as the mode. + // I.e. we don't want to compare textual positions of different reactors (super classes) + if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { + var modeAstNode = NodeModelUtils.getNode(mode); + if (modeAstNode != null) { + var modePos = modeAstNode.getOffset(); + // Now move the insertion index from the last element forward as long as this element has a textual + // position after the mode. + do { + var astNode = NodeModelUtils.getNode(list.get(idx - 1)); + if (astNode != null && astNode.getOffset() > modePos) { + idx--; + } else { + break; // Insertion index is ok. + } + } while (idx > 0); + } } - } while (idx > 0); } - } - } - list.addAll(idx, elements); - } - - public static Iterable allElementsOfClass( - Resource resource, Class elementClass) { - //noinspection StaticPseudoFunctionalStyleMethod - return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); - } - - //////////////////////////////// - //// Utility functions for translating AST nodes into text - - /** - * Translate the given code into its textual representation with {@code CodeMap.Correspondence} - * tags inserted, or return the empty string if {@code node} is {@code null}. This method should - * be used to generate code. - * - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toText(EObject node) { - if (node == null) return ""; - return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); - } - - /** - * Translate the given code into its textual representation without {@code CodeMap.Correspondence} - * tags, or return the empty string if {@code node} is {@code null}. This method should be used - * for analyzing AST nodes in cases where they are easiest to analyze as strings. - * - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toOriginalText(EObject node) { - if (node == null) return ""; - return ToText.instance.doSwitch(node); - } - - /** - * Return an integer representation of the given element. - * - *

Internally, this method uses Integer.decode, so it will also understand hexadecimal, binary, - * etc. - * - * @param e The element to be rendered as an integer. - */ - public static Integer toInteger(Element e) { - return Integer.decode(e.getLiteral()); - } - - /** - * Return a time value based on the given element. - * - * @param e The element to be rendered as a time value. - */ - public static TimeValue toTimeValue(Element e) { - return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); - } - - /** Returns the time value represented by the given AST node. */ - public static TimeValue toTimeValue(Time e) { - if (!isValidTime(e)) { - // invalid unit, will have been reported by validator - throw new IllegalArgumentException(); - } - return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); - } - - /** - * Return a boolean based on the given element. - * - * @param e The element to be rendered as a boolean. - */ - public static boolean toBoolean(Element e) { - return elementToSingleString(e).equalsIgnoreCase("true"); - } - - /** - * Given the right-hand side of a target property, return a string that represents the given - * value/ - * - *

If the given value is not a literal or and id (but for instance and array or dict), an empty - * string is returned. If the element is a string, any quotes are removed. - * - * @param e The right-hand side of a target property. - */ - public static String elementToSingleString(Element e) { - if (e.getLiteral() != null) { - return StringUtil.removeQuotes(e.getLiteral()).trim(); - } else if (e.getId() != null) { - return e.getId(); - } - return ""; - } - - /** - * Given the right-hand side of a target property, return a list with all the strings that the - * property lists. - * - *

Arrays are traversed, so strings are collected recursively. Empty strings are ignored; they - * are not added to the list. - * - * @param value The right-hand side of a target property. - */ - public static List elementToListOfStrings(Element value) { - List elements = new ArrayList<>(); - if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - elements.addAll(elementToListOfStrings(element)); - } - return elements; - } else { - String v = elementToSingleString(value); - if (!v.isEmpty()) { - elements.add(v); - } - } - return elements; - } - - /** - * Convert key-value pairs in an Element to a map, assuming that both the key and the value are - * strings. - */ - public static Map elementToStringMaps(Element value) { - Map elements = new HashMap<>(); - for (var element : value.getKeyvalue().getPairs()) { - elements.put( - element.getName().trim(), - StringUtil.removeQuotes(elementToSingleString(element.getValue()))); - } - return elements; - } - - // Various utility methods to convert various data types to Elements - - /** Convert a map to key-value pairs in an Element. */ - public static Element toElement(Map map) { - Element e = LfFactory.eINSTANCE.createElement(); - if (map.size() == 0) return null; - else { - var kv = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var entry : map.entrySet()) { - var pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(entry.getKey()); - var element = LfFactory.eINSTANCE.createElement(); - element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); - pair.setValue(element); - kv.getPairs().add(pair); - } - e.setKeyvalue(kv); - } - - return e; - } - - /** - * Given a single string, convert it into its AST representation. {@code addQuotes} controls if - * the generated representation should be accompanied by double quotes ("") or not. - */ - private static Element toElement(String str, boolean addQuotes) { - if (str == null) return null; - var strToReturn = addQuotes ? StringUtil.addDoubleQuotes(str) : str; - Element e = LfFactory.eINSTANCE.createElement(); - e.setLiteral(strToReturn); - return e; - } - - /** Given a single string, convert it into its AST representation. */ - public static Element toElement(String str) { - return toElement(str, true); - } - - /** - * Given a list of strings, convert it into its AST representation. Stores the list in the Array - * field of the element, unless the list only has one string, in which case it is stored in the - * Literal field. Returns null if the provided list is empty. - */ - public static Element toElement(List list) { - Element e = LfFactory.eINSTANCE.createElement(); - if (list.size() == 0) return null; - else if (list.size() == 1) { - return toElement(list.get(0)); - } else { - var arr = LfFactory.eINSTANCE.createArray(); - for (String s : list) { - arr.getElements().add(ASTUtils.toElement(s)); - } - e.setArray(arr); - } - return e; - } - - /** - * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit - * inside an Element. - */ - public static Element toElement(TimeValue tv) { - Element e = LfFactory.eINSTANCE.createElement(); - e.setTime((int) tv.time); - if (tv.unit != null) { - e.setUnit(tv.unit.toString()); - } - return e; - } - - public static Element toElement(boolean val) { - return toElement(Boolean.toString(val), false); - } - - public static Element toElement(int val) { - return toElement(Integer.toString(val), false); - } - - /** - * Translate the given type into its textual representation, but do not append any array - * specifications or type arguments. - * - * @param type AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String baseType(Type type) { - if (type != null) { - if (type.getCode() != null) { - return toText(type.getCode()); - } else { - if (type.isTime()) { - return "time"; + list.addAll(idx, elements); + } + + public static Iterable allElementsOfClass( + Resource resource, + Class elementClass + ) { + //noinspection StaticPseudoFunctionalStyleMethod + return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + + /** + * Translate the given code into its textual representation + * with {@code CodeMap.Correspondence} tags inserted, or + * return the empty string if {@code node} is {@code null}. + * This method should be used to generate code. + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toText(EObject node) { + if (node == null) return ""; + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); + } + + /** + * Translate the given code into its textual representation + * without {@code CodeMap.Correspondence} tags, or return + * the empty string if {@code node} is {@code null}. + * This method should be used for analyzing AST nodes in + * cases where they are easiest to analyze as strings. + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toOriginalText(EObject node) { + if (node == null) return ""; + return ToText.instance.doSwitch(node); + } + + /** + * Return an integer representation of the given element. + * + * Internally, this method uses Integer.decode, so it will + * also understand hexadecimal, binary, etc. + * + * @param e The element to be rendered as an integer. + */ + public static Integer toInteger(Element e) { + return Integer.decode(e.getLiteral()); + } + + /** + * Return a time value based on the given element. + * + * @param e The element to be rendered as a time value. + */ + public static TimeValue toTimeValue(Element e) { + return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); + } + + /** + * Returns the time value represented by the given AST node. + */ + public static TimeValue toTimeValue(Time e) { + if (!isValidTime(e)) { + // invalid unit, will have been reported by validator + throw new IllegalArgumentException(); + } + return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + } + + /** + * Return a boolean based on the given element. + * + * @param e The element to be rendered as a boolean. + */ + public static boolean toBoolean(Element e) { + return elementToSingleString(e).equalsIgnoreCase("true"); + } + + /** + * Given the right-hand side of a target property, return a string that + * represents the given value/ + * + * If the given value is not a literal or and id (but for instance and array or dict), + * an empty string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String elementToSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } + + /** + * Given the right-hand side of a target property, return a list with all + * the strings that the property lists. + * + * Arrays are traversed, so strings are collected recursively. Empty strings + * are ignored; they are not added to the list. + * @param value The right-hand side of a target property. + */ + public static List elementToListOfStrings(Element value) { + List elements = new ArrayList<>(); + if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + elements.addAll(elementToListOfStrings(element)); + } + return elements; } else { - StringBuilder result = new StringBuilder(type.getId()); + String v = elementToSingleString(value); + if (!v.isEmpty()) { + elements.add(v); + } + } + return elements; + } - for (String s : convertToEmptyListIfNull(type.getStars())) { - result.append(s); - } - return result.toString(); + /** + * Convert key-value pairs in an Element to a map, assuming that both the key + * and the value are strings. + */ + public static Map elementToStringMaps(Element value) { + Map elements = new HashMap<>(); + for (var element: value.getKeyvalue().getPairs()) { + elements.put( + element.getName().trim(), + StringUtil.removeQuotes(elementToSingleString(element.getValue())) + ); } - } - } - return ""; - } - - /** - * Report whether the given literal is zero or not. - * - * @param literal AST node to inspect. - * @return True if the given literal denotes the constant `0`, false otherwise. - */ - public static boolean isZero(String literal) { - try { - if (literal != null && Integer.parseInt(literal) == 0) { - return true; - } - } catch (NumberFormatException e) { - // Not an int. - } - return false; - } - - /** - * Report whether the given expression is zero or not. - * - * @param expr AST node to inspect. - * @return True if the given value denotes the constant `0`, false otherwise. - */ - public static boolean isZero(Expression expr) { - if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } - - /** - * Report whether the given string literal is an integer number or not. - * - * @param literal AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Integer.decode(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } - - /** - * Report whether the given string literal is a boolean value or not. - * - * @param literal AST node to inspect. - * @return True if the given value is a boolean, false otherwise. - */ - public static boolean isBoolean(String literal) { - return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); - } - - /** - * Report whether the given string literal is a float value or not. - * - * @param literal AST node to inspect. - * @return True if the given value is a float, false otherwise. - */ - public static boolean isFloat(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Float.parseFloat(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } - - /** - * Report whether the given code is an integer number or not. - * - * @param code AST node to inspect. - * @return True if the given code is an integer, false otherwise. - */ - public static boolean isInteger(Code code) { - return isInteger(toText(code)); - } - - /** - * Report whether the given expression is an integer number or not. - * - * @param expr AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(Expression expr) { - if (expr instanceof Literal) { - return isInteger(((Literal) expr).getLiteral()); - } else if (expr instanceof Code) { - return isInteger((Code) expr); - } - return false; - } - - /** - * Report whether the given expression denotes a valid time or not. - * - * @param expr AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Expression expr) { - if (expr instanceof ParameterReference) { - return isOfTimeType(((ParameterReference) expr).getParameter()); - } else if (expr instanceof Time) { - return isValidTime((Time) expr); - } else if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } - - /** - * Report whether the given time denotes a valid time or not. - * - * @param t AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Time t) { - if (t == null) return false; - String unit = t.getUnit(); - return t.getInterval() == 0 || TimeUnit.isValidUnit(unit); - } - - /** If the initializer contains exactly one expression, return it. Otherwise, return null. */ - public static Expression asSingleExpr(Initializer init) { - if (init == null) { - return null; - } - var exprs = init.getExprs(); - return exprs.size() == 1 ? exprs.get(0) : null; - } - - public static boolean isSingleExpr(Initializer init) { - // todo expand that to = initialization - if (init == null) { - return false; - } - var exprs = init.getExprs(); - return exprs.size() == 1; - } - - public static boolean isListInitializer(Initializer init) { - return init != null && !isSingleExpr(init); - } - - /** - * Return the type of a declaration with the given (nullable) explicit type, and the given - * (nullable) initializer. If the explicit type is null, then the type is inferred from the - * initializer. Only two types can be inferred: "time" and "timeList". Return the "undefined" type - * if neither can be inferred. - * - * @param type Explicit type declared on the declaration - * @param init The initializer expression - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Type type, Initializer init) { - if (type != null) { - return InferredType.fromAST(type); - } else if (init == null) { - return InferredType.undefined(); - } - - var single = asSingleExpr(init); - if (single != null) { - // If there is a single element in the list, and it is a proper - // time value with units, we infer the type "time". - if (single instanceof ParameterReference) { - return getInferredType(((ParameterReference) single).getParameter()); - } else if (single instanceof Time) { - return InferredType.time(); - } - } else if (init.getExprs().size() > 1) { - // If there are multiple elements in the list, and there is at - // least one proper time value with units, and all other elements - // are valid times (including zero without units), we infer the - // type "time list". - var allValidTime = true; - var foundNonZero = false; - - for (var e : init.getExprs()) { - if (!ASTUtils.isValidTime(e)) { - allValidTime = false; + return elements; + } + + // Various utility methods to convert various data types to Elements + + /** + * Convert a map to key-value pairs in an Element. + */ + public static Element toElement(Map map) { + Element e = LfFactory.eINSTANCE.createElement(); + if (map.size() == 0) return null; + else { + var kv = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var entry : map.entrySet()) { + var pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(entry.getKey()); + var element = LfFactory.eINSTANCE.createElement(); + element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); + pair.setValue(element); + kv.getPairs().add(pair); + } + e.setKeyvalue(kv); } - if (!ASTUtils.isZero(e)) { - foundNonZero = true; + + return e; + } + + /** + * Given a single string, convert it into its AST representation. + * {@code addQuotes} controls if the generated representation should be + * accompanied by double quotes ("") or not. + */ + private static Element toElement(String str, boolean addQuotes) { + if (str == null) return null; + var strToReturn = addQuotes? StringUtil.addDoubleQuotes(str):str; + Element e = LfFactory.eINSTANCE.createElement(); + e.setLiteral(strToReturn); + return e; + } + + /** + * Given a single string, convert it into its AST representation. + */ + public static Element toElement(String str) { + return toElement(str, true); + } + + /** + * Given a list of strings, convert it into its AST representation. + * Stores the list in the Array field of the element, unless the list only has one string, + * in which case it is stored in the Literal field. Returns null if the provided list is empty. + */ + public static Element toElement(List list) { + Element e = LfFactory.eINSTANCE.createElement(); + if (list.size() == 0) return null; + else if (list.size() == 1) { + return toElement(list.get(0)); + } else { + var arr = LfFactory.eINSTANCE.createArray(); + for (String s : list) { + arr.getElements().add(ASTUtils.toElement(s)); + } + e.setArray(arr); } - } - - if (allValidTime && foundNonZero) { - // Conservatively, no bounds are inferred; the returned type - // is a variable-size list. - return InferredType.timeList(); - } - } - return InferredType.undefined(); - } - - /** - * Given a parameter, return an inferred type. Only two types can be inferred: "time" and - * "timeList". Return the "undefined" type if neither can be inferred. - * - * @param p A parameter to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Parameter p) { - return getInferredType(p.getType(), p.getInit()); - } - - /** - * Given a state variable, return an inferred type. Only two types can be inferred: "time" and - * "timeList". Return the "undefined" type if neither can be inferred. - * - * @param s A state variable to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(StateVar s) { - return getInferredType(s.getType(), s.getInit()); - } - - /** - * Construct an inferred type from an "action" AST node based on its declared type. If no type is - * declared, return the "undefined" type. - * - * @param a An action to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Action a) { - return getInferredType(a.getType(), null); - } - - /** - * Construct an inferred type from a "port" AST node based on its declared type. If no type is - * declared, return the "undefined" type. - * - * @param p A port to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Port p) { - return getInferredType(p.getType(), null); - } - - /** - * If the given string can be recognized as a floating-point number that has a leading decimal - * point, prepend the string with a zero and return it. Otherwise, return the original string. - * - * @param literal A string might be recognizable as a floating point number with a leading decimal - * point. - * @return an equivalent representation of literal - * - */ - public static String addZeroToLeadingDot(String literal) { - Matcher m = ABBREVIATED_FLOAT.matcher(literal); - if (m.matches()) { - return literal.replace(".", "0."); - } - return literal; - } - - /** - * Return true if the specified port is a multiport. - * - * @param port The port. - * @return True if the port is a multiport. - */ - public static boolean isMultiport(Port port) { - return port.getWidthSpec() != null; - } - - //////////////////////////////// - //// Utility functions for translating AST nodes into text - // This is a continuation of a large section of ASTUtils.xtend - // with the same name. - - /** - * Generate code for referencing a port, action, or timer. - * - * @param reference The reference to the variable. - */ - public static String generateVarRef(VarRef reference) { - var prefix = ""; - if (reference.getContainer() != null) { - prefix = reference.getContainer().getName() + "."; - } - return prefix + reference.getVariable().getName(); - } - - /** Assuming that the given expression denotes a valid time literal, return a time value. */ - public static TimeValue getLiteralTimeValue(Expression expr) { - if (expr instanceof Time) { - return toTimeValue((Time) expr); - } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { - return TimeValue.ZERO; - } else { - return null; - } - } - - /** If the parameter is of time type, return its default value. Otherwise, return null. */ - public static TimeValue getDefaultAsTimeValue(Parameter p) { - if (isOfTimeType(p)) { - var init = asSingleExpr(p.getInit()); - if (init != null) { - return getLiteralTimeValue(init); - } - } - return null; - } - - /** Return whether the given state variable is inferred to a time type. */ - public static boolean isOfTimeType(StateVar state) { - InferredType t = getInferredType(state); - return t.isTime && !t.isList; - } - - /** Return whether the given parameter is inferred to a time type. */ - public static boolean isOfTimeType(Parameter param) { - InferredType t = getInferredType(param); - return t.isTime && !t.isList; - } - - /** - * Given a parameter, return its initial value. The initial value is a list of instances of - * Expressions. - * - *

If the instantiations argument is null or an empty list, then the value returned is simply - * the default value given when the parameter is defined. - * - *

If a list of instantiations is given, then the first instantiation is required to be an - * instantiation of the reactor class that is parameterized by the parameter. I.e., ``` - * parameter.eContainer == instantiations.get(0).reactorClass ``` If a second instantiation is - * given, then it is required to be an instantiation of a reactor class that contains the first - * instantiation. That is, ``` instantiations.get(0).eContainer == - * instantiations.get(1).reactorClass ``` More generally, for all 0 <= i < instantiations.size - - * 1, ``` instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass ``` If any of - * these conditions is not satisfied, then an IllegalArgumentException will be thrown. - * - *

Note that this chain of reactions cannot be inferred from the parameter because in each of - * the predicates above, there may be more than one instantiation that can appear on the right - * hand side of the predicate. - * - *

For example, consider the following program: ``` 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); } ``` Notice that there are a total of four instances of reactor class A. Then ``` - * initialValue(x, null) returns 1 initialValue(x, [a1]) returns 2 initialValue(x, [a2]) returns - * -1 initialValue(x, [a1, b1]) returns 3 initialValue(x, [a2, b1]) returns -1 initialValue(x, - * [a1, b2]) returns -2 initialValue(x, [a2, b2]) returns -1 ``` (Actually, in each of the above - * cases, the returned value is a list with one entry, a Literal, e.g. ["1"]). - * - *

There are two instances of reactor class B. ``` initialValue(y, null) returns 2 - * initialValue(y, [a1]) throws an IllegalArgumentException initialValue(y, [b1]) returns 3 - * initialValue(y, [b2]) returns -2 ``` - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * @return The value of the parameter. - * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the - * reactor class that is parameterized by the respective parameter or if the chain of - * instantiations is not nested. - */ - public static List initialValue( - Parameter parameter, List instantiations) { - // If instantiations are given, then check to see whether this parameter gets overridden in - // the first of those instantiations. - if (instantiations != null && instantiations.size() > 0) { - // Check to be sure that the instantiation is in fact an instantiation - // of the reactor class for which this is a parameter. - Instantiation instantiation = instantiations.get(0); - - if (!belongsTo(parameter, instantiation)) { - throw new IllegalArgumentException( - "Parameter " - + parameter.getName() - + " is not a parameter of reactor instance " - + instantiation.getName() - + "."); - } - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = null; - for (Assignment assignment : instantiation.getParameters()) { - if (assignment.getLhs().equals(parameter)) { - lastAssignment = assignment; + return e; + } + + /** + * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit inside an Element. + */ + public static Element toElement(TimeValue tv) { + Element e = LfFactory.eINSTANCE.createElement(); + e.setTime((int)tv.time); + if (tv.unit != null) { + e.setUnit(tv.unit.toString()); } - } - if (lastAssignment != null) { - // Right hand side can be a list. Collect the entries. - List result = new ArrayList<>(); - for (Expression expr : lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - if (instantiations.size() > 1 - && instantiation.eContainer() != instantiations.get(1).getReactorClass()) { - throw new IllegalArgumentException( - "Reactor instance " - + instantiation.getName() - + " is not contained by instance " - + instantiations.get(1).getName() - + "."); + return e; + } + + public static Element toElement(boolean val) { + return toElement(Boolean.toString(val), false); + } + + public static Element toElement(int val) { + return toElement(Integer.toString(val), false); + } + + /** + * Translate the given type into its textual representation, but + * do not append any array specifications or type arguments. + * @param type AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String baseType(Type type) { + if (type != null) { + if (type.getCode() != null) { + return toText(type.getCode()); + } else { + if (type.isTime()) { + return "time"; + } else { + StringBuilder result = new StringBuilder(type.getId()); + + for (String s : convertToEmptyListIfNull(type.getStars())) { + result.append(s); + } + return result.toString(); + } } - result.addAll( - initialValue( - ((ParameterReference) expr).getParameter(), - instantiations.subList(1, instantiations.size()))); - } else { - result.add(expr); - } } - return result; - } - } - // If we reach here, then either no instantiation was supplied or - // there was no assignment in the instantiation. So just use the - // parameter's initial value. - return parameter.getInit().getExprs(); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the - * specified instantiation, meaning that it is defined in the reactor class being instantiated or - * one of its base classes. - * - * @param eobject The object. - * @param instantiation The instantiation. - */ - public static boolean belongsTo(EObject eobject, Instantiation instantiation) { - Reactor reactor = toDefinition(instantiation.getReactorClass()); - return belongsTo(eobject, reactor); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the - * specified reactor, meaning that it is defined in reactor class or one of its base classes. - * - * @param eobject The object. - * @param reactor The reactor. - */ - public static boolean belongsTo(EObject eobject, Reactor reactor) { - if (eobject.eContainer() == reactor) return true; - for (ReactorDecl baseClass : reactor.getSuperClasses()) { - if (belongsTo(eobject, toDefinition(baseClass))) { + return ""; + } + + /** + * Report whether the given literal is zero or not. + * @param literal AST node to inspect. + * @return True if the given literal denotes the constant `0`, false + * otherwise. + */ + public static boolean isZero(String literal) { + try { + if (literal != null && + Integer.parseInt(literal) == 0) { + return true; + } + } catch (NumberFormatException e) { + // Not an int. + } + return false; + } + + /** + * Report whether the given expression is zero or not. + * + * @param expr AST node to inspect. + * @return True if the given value denotes the constant `0`, false otherwise. + */ + public static boolean isZero(Expression expr) { + if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } + + /** + * Report whether the given string literal is an integer number or not. + * + * @param literal AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Integer.decode(literal); + } catch (NumberFormatException e) { + return false; + } return true; - } - } - return false; - } - - /** - * Given a parameter return its integer value or null if it does not have an integer value. If the - * value of the parameter is a list of integers, return the sum of value in the list. The - * instantiations parameter is as in {@link #initialValue(Parameter, List)}. - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * @return The integer value of the parameter, or null if it does not have an integer value. - * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the - * reactor class that is parameterized by the respective parameter or if the chain of - * instantiations is not nested. - */ - public static Integer initialValueInt(Parameter parameter, List instantiations) { - List expressions = initialValue(parameter, instantiations); - int result = 0; - for (Expression expr : expressions) { - if (!(expr instanceof Literal)) { - return null; - } - try { - result += Integer.decode(((Literal) expr).getLiteral()); - } catch (NumberFormatException ex) { - return null; - } - } - return result; - } - - /** - * Given the width specification of port or instantiation and an (optional) list of nested - * instantiations, return the width if it can be determined and -1 if not. It will not be able to - * be determined if either the width is variable (in which case you should use {@link - * #inferPortWidth(VarRef, Connection, List)} ) or the list of instantiations is incomplete or - * missing. If there are parameter references in the width, they are evaluated to the extent - * possible given the instantiations list. - * - *

The instantiations list is as in {@link #initialValue(Parameter, List)}. If the spec belongs - * to an instantiation (for a bank of reactors), then the first element on this list should be the - * instantiation that contains this instantiation. If the spec belongs to a port, then the first - * element on the list should be the instantiation of the reactor that contains the port. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * @return The width, or -1 if the width could not be determined. - * @throws IllegalArgumentException If an instantiation provided is not as given above or if the - * chain of instantiations is not nested. - */ - public static int width(WidthSpec spec, List instantiations) { - if (spec == null) { - return 1; - } - if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { - return inferWidthFromConnections(spec, instantiations); - } - var result = 0; - for (WidthTerm term : spec.getTerms()) { - if (term.getParameter() != null) { - Integer termWidth = initialValueInt(term.getParameter(), instantiations); - if (termWidth != null) { - result += termWidth; - } else { - return -1; + } + + /** + * Report whether the given string literal is a boolean value or not. + * @param literal AST node to inspect. + * @return True if the given value is a boolean, false otherwise. + */ + public static boolean isBoolean(String literal) { + return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); + } + + /** + * Report whether the given string literal is a float value or not. + * @param literal AST node to inspect. + * @return True if the given value is a float, false otherwise. + */ + public static boolean isFloat(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Float.parseFloat(literal); + } catch (NumberFormatException e) { + return false; } - } else if (term.getWidth() > 0) { - result += term.getWidth(); - } else { - // If the width cannot be determined because term's width <= 0, which means the term's width - // must be inferred, try to infer the width using connections. - if (spec.eContainer() instanceof Instantiation) { - try { - return inferWidthFromConnections(spec, instantiations); - } catch (InvalidSourceException e) { - // If the inference fails, return -1. - return -1; - } + return true; + } + + /** + * Report whether the given code is an integer number or not. + * @param code AST node to inspect. + * @return True if the given code is an integer, false otherwise. + */ + public static boolean isInteger(Code code) { + return isInteger(toText(code)); + } + + /** + * Report whether the given expression is an integer number or not. + * @param expr AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(Expression expr) { + if (expr instanceof Literal) { + return isInteger(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isInteger((Code) expr); } - } - } - return result; - } - - /** - * Infer the width of a port reference in a connection. The port reference one or two parts, a - * port and an (optional) container which is an Instantiation that may refer to a bank of - * reactors. The width will be the product of the bank width and the port width. The returned - * value will be 1 if the port is not in a bank and is not a multiport. - * - *

If the width cannot be determined, this will return -1. The width cannot be determined if - * the list of instantiations is missing or incomplete. - * - *

The instantiations list is as in {@link #initialValue(Parameter, List)}. The first element - * on this list should be the instantiation that contains the specified connection. - * - * @param reference A port reference. - * @param connection A connection, or null if not in the context of a connection. - * @param instantiations The (optional) list of instantiations. - * @return The width or -1 if it could not be determined. - * @throws IllegalArgumentException If an instantiation provided is not as given above or if the - * chain of instantiations is not nested. - */ - public static int inferPortWidth( - VarRef reference, Connection connection, List instantiations) { - if (reference.getVariable() instanceof Port) { - // If the port is given as a.b, then we want to prepend a to - // the list of instantiations to determine the width of this port. - List extended = instantiations; - if (reference.getContainer() != null) { - extended = new ArrayList<>(); - extended.add(reference.getContainer()); - if (instantiations != null) { - extended.addAll(instantiations); + return false; + } + + /** + * Report whether the given expression denotes a valid time or not. + * @param expr AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Expression expr) { + if (expr instanceof ParameterReference) { + return isOfTimeType(((ParameterReference) expr).getParameter()); + } else if (expr instanceof Time) { + return isValidTime((Time) expr); + } else if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); } - } + return false; + } - int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); - if (portWidth < 0) { - // Could not determine port width. - return -1; - } - - // Next determine the bank width. This may be unspecified, in which - // case it has to be inferred using the connection. - int bankWidth = 1; - if (reference.getContainer() != null) { - bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); - if (bankWidth < 0 && connection != null) { - // Try to infer the bank width from the connection. - if (reference.getContainer().getWidthSpec().isOfVariableLength()) { - // This occurs for a bank of delays. - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : connection.getLeftPorts()) { - if (leftPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException( - "Multiple ports with variable width on a connection."); + /** + * Report whether the given time denotes a valid time or not. + * @param t AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Time t) { + if (t == null) return false; + String unit = t.getUnit(); + return t.getInterval() == 0 || + TimeUnit.isValidUnit(unit); + } + + /** + * If the initializer contains exactly one expression, + * return it. Otherwise, return null. + */ + public static Expression asSingleExpr(Initializer init) { + if (init == null) { + return null; + } + var exprs = init.getExprs(); + return exprs.size() == 1 ? exprs.get(0) : null; + } + + public static boolean isSingleExpr(Initializer init) { + // todo expand that to = initialization + if (init == null) { + return false; + } + var exprs = init.getExprs(); + return exprs.size() == 1; + } + + public static boolean isListInitializer(Initializer init) { + return init != null && !isSingleExpr(init); + } + + /** + * Return the type of a declaration with the given + * (nullable) explicit type, and the given (nullable) + * initializer. If the explicit type is null, then the + * type is inferred from the initializer. Only two types + * can be inferred: "time" and "timeList". Return the + * "undefined" type if neither can be inferred. + * + * @param type Explicit type declared on the declaration + * @param init The initializer expression + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Type type, Initializer init) { + if (type != null) { + return InferredType.fromAST(type); + } else if (init == null) { + return InferredType.undefined(); + } + + var single = asSingleExpr(init); + if (single != null) { + // If there is a single element in the list, and it is a proper + // time value with units, we infer the type "time". + if (single instanceof ParameterReference) { + return getInferredType(((ParameterReference) single).getParameter()); + } else if (single instanceof Time) { + return InferredType.time(); + } + } else if (init.getExprs().size() > 1) { + // If there are multiple elements in the list, and there is at + // least one proper time value with units, and all other elements + // are valid times (including zero without units), we infer the + // type "time list". + var allValidTime = true; + var foundNonZero = false; + + for (var e : init.getExprs()) { + if (!ASTUtils.isValidTime(e)) { + allValidTime = false; } - // Indicate that this port is on the left. - leftOrRight = -1; - } else { - // The left port is not the same as this reference. - int otherWidth = inferPortWidth(leftPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; + if (!ASTUtils.isZero(e)) { + foundNonZero = true; } - leftWidth += otherWidth; - } } - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException( - "Multiple ports with variable width on a connection."); + + if (allValidTime && foundNonZero) { + // Conservatively, no bounds are inferred; the returned type + // is a variable-size list. + return InferredType.timeList(); + } + } + return InferredType.undefined(); + } + + /** + * Given a parameter, return an inferred type. Only two types can be + * inferred: "time" and "timeList". Return the "undefined" type if + * neither can be inferred. + * + * @param p A parameter to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Parameter p) { + return getInferredType(p.getType(), p.getInit()); + } + + /** + * Given a state variable, return an inferred type. Only two types can be + * inferred: "time" and "timeList". Return the "undefined" type if + * neither can be inferred. + * + * @param s A state variable to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(StateVar s) { + return getInferredType(s.getType(), s.getInit()); + } + + /** + * Construct an inferred type from an "action" AST node based + * on its declared type. If no type is declared, return the "undefined" + * type. + * + * @param a An action to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Action a) { + return getInferredType(a.getType(), null); + } + + /** + * Construct an inferred type from a "port" AST node based on its declared + * type. If no type is declared, return the "undefined" type. + * + * @param p A port to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Port p) { + return getInferredType(p.getType(), null); + } + + /** + * If the given string can be recognized as a floating-point number that has a leading decimal point, + * prepend the string with a zero and return it. Otherwise, return the original string. + * + * @param literal A string might be recognizable as a floating point number with a leading decimal point. + * @return an equivalent representation of literal + * + */ + public static String addZeroToLeadingDot(String literal) { + Matcher m = ABBREVIATED_FLOAT.matcher(literal); + if (m.matches()) { + return literal.replace(".", "0."); + } + return literal; + } + + /** + * Return true if the specified port is a multiport. + * @param port The port. + * @return True if the port is a multiport. + */ + public static boolean isMultiport(Port port) { + return port.getWidthSpec() != null; + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + // This is a continuation of a large section of ASTUtils.xtend + // with the same name. + + /** + * Generate code for referencing a port, action, or timer. + * @param reference The reference to the variable. + */ + public static String generateVarRef(VarRef reference) { + var prefix = ""; + if (reference.getContainer() != null) { + prefix = reference.getContainer().getName() + "."; + } + return prefix + reference.getVariable().getName(); + } + + /** + * Assuming that the given expression denotes a valid time literal, + * return a time value. + */ + public static TimeValue getLiteralTimeValue(Expression expr) { + if (expr instanceof Time) { + return toTimeValue((Time)expr); + } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { + return TimeValue.ZERO; + } else { + return null; + } + } + + /** + * If the parameter is of time type, return its default value. + * Otherwise, return null. + */ + public static TimeValue getDefaultAsTimeValue(Parameter p) { + if (isOfTimeType(p)) { + var init = asSingleExpr(p.getInit()); + if (init != null) { + return getLiteralTimeValue(init); + } + } + return null; + } + + /** + * Return whether the given state variable is inferred + * to a time type. + */ + public static boolean isOfTimeType(StateVar state) { + InferredType t = getInferredType(state); + return t.isTime && !t.isList; + } + + /** + * Return whether the given parameter is inferred + * to a time type. + */ + public static boolean isOfTimeType(Parameter param) { + InferredType t = getInferredType(param); + return t.isTime && !t.isList; + } + + /** + * Given a parameter, return its initial value. + * The initial value is a list of instances of Expressions. + * + * If the instantiations argument is null or an empty list, then the + * value returned is simply the default value given when the parameter + * is defined. + * + * If a list of instantiations is given, then the first instantiation + * is required to be an instantiation of the reactor class that is + * parameterized by the parameter. I.e., + * ``` + * parameter.eContainer == instantiations.get(0).reactorClass + * ``` + * If a second instantiation is given, then it is required to be an instantiation of a + * reactor class that contains the first instantiation. That is, + * ``` + * instantiations.get(0).eContainer == instantiations.get(1).reactorClass + * ``` + * More generally, for all 0 <= i < instantiations.size - 1, + * ``` + * instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass + * ``` + * If any of these conditions is not satisfied, then an IllegalArgumentException + * will be thrown. + * + * Note that this chain of reactions cannot be inferred from the parameter because + * in each of the predicates above, there may be more than one instantiation that + * can appear on the right hand side of the predicate. + * + * For example, consider the following program: + * ``` + * 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); + * } + * ``` + * Notice that there are a total of four instances of reactor class A. + * Then + * ``` + * initialValue(x, null) returns 1 + * initialValue(x, [a1]) returns 2 + * initialValue(x, [a2]) returns -1 + * initialValue(x, [a1, b1]) returns 3 + * initialValue(x, [a2, b1]) returns -1 + * initialValue(x, [a1, b2]) returns -2 + * initialValue(x, [a2, b2]) returns -1 + * ``` + * (Actually, in each of the above cases, the returned value is a list with + * one entry, a Literal, e.g. ["1"]). + * + * There are two instances of reactor class B. + * ``` + * initialValue(y, null) returns 2 + * initialValue(y, [a1]) throws an IllegalArgumentException + * initialValue(y, [b1]) returns 3 + * initialValue(y, [b2]) returns -2 + * ``` + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * + * @return The value of the parameter. + * + * @throws IllegalArgumentException If an instantiation provided is not an + * instantiation of the reactor class that is parameterized by the + * respective parameter or if the chain of instantiations is not nested. + */ + public static List initialValue(Parameter parameter, List instantiations) { + // If instantiations are given, then check to see whether this parameter gets overridden in + // the first of those instantiations. + if (instantiations != null && instantiations.size() > 0) { + // Check to be sure that the instantiation is in fact an instantiation + // of the reactor class for which this is a parameter. + Instantiation instantiation = instantiations.get(0); + + if (!belongsTo(parameter, instantiation)) { + throw new IllegalArgumentException("Parameter " + + parameter.getName() + + " is not a parameter of reactor instance " + + instantiation.getName() + + "." + ); + } + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = null; + for (Assignment assignment: instantiation.getParameters()) { + if (assignment.getLhs().equals(parameter)) { + lastAssignment = assignment; } - // Indicate that this port is on the right. - leftOrRight = 1; - } else { - int otherWidth = inferPortWidth(rightPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; + } + if (lastAssignment != null) { + // Right hand side can be a list. Collect the entries. + List result = new ArrayList<>(); + for (Expression expr: lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + if (instantiations.size() > 1 + && instantiation.eContainer() != instantiations.get(1).getReactorClass() + ) { + throw new IllegalArgumentException("Reactor instance " + + instantiation.getName() + + " is not contained by instance " + + instantiations.get(1).getName() + + "." + ); + } + result.addAll(initialValue(((ParameterReference)expr).getParameter(), + instantiations.subList(1, instantiations.size()))); + } else { + result.add(expr); + } } - rightWidth += otherWidth; - } + return result; } - int discrepancy = 0; - if (leftOrRight < 0) { - // This port is on the left. - discrepancy = rightWidth - leftWidth; - } else if (leftOrRight > 0) { - // This port is on the right. - discrepancy = leftWidth - rightWidth; + } + // If we reach here, then either no instantiation was supplied or + // there was no assignment in the instantiation. So just use the + // parameter's initial value. + return parameter.getInit().getExprs(); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) + * belongs to the specified instantiation, meaning that it is defined in + * the reactor class being instantiated or one of its base classes. + * @param eobject The object. + * @param instantiation The instantiation. + */ + public static boolean belongsTo(EObject eobject, Instantiation instantiation) { + Reactor reactor = toDefinition(instantiation.getReactorClass()); + return belongsTo(eobject, reactor); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) + * belongs to the specified reactor, meaning that it is defined in + * reactor class or one of its base classes. + * @param eobject The object. + * @param reactor The reactor. + */ + public static boolean belongsTo(EObject eobject, Reactor reactor) { + if (eobject.eContainer() == reactor) return true; + for (ReactorDecl baseClass : reactor.getSuperClasses()) { + if (belongsTo(eobject, toDefinition(baseClass))) { + return true; } - // Check that portWidth divides the discrepancy. - if (discrepancy % portWidth != 0) { - // This is an error. - return -1; + } + return false; + } + + /** + * Given a parameter return its integer value or null + * if it does not have an integer value. + * If the value of the parameter is a list of integers, + * return the sum of value in the list. + * The instantiations parameter is as in + * {@link #initialValue(Parameter, List)}. + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * + * @return The integer value of the parameter, or null if it does not have an integer value. + * + * @throws IllegalArgumentException If an instantiation provided is not an + * instantiation of the reactor class that is parameterized by the + * respective parameter or if the chain of instantiations is not nested. + */ + public static Integer initialValueInt(Parameter parameter, List instantiations) { + List expressions = initialValue(parameter, instantiations); + int result = 0; + for (Expression expr: expressions) { + if (!(expr instanceof Literal)) { + return null; + } + try { + result += Integer.decode(((Literal) expr).getLiteral()); + } catch (NumberFormatException ex) { + return null; } - bankWidth = discrepancy / portWidth; - } else { - // Could not determine the bank width. - return -1; - } } - } - return portWidth * bankWidth; - } - // Argument is not a port. - return -1; - } - - /** - * Given an instantiation of a reactor or bank of reactors, return the width. This will be 1 if - * this is not a reactor bank. Otherwise, this will attempt to determine the width. If the width - * is declared as a literal constant, it will return that constant. If the width is specified as a - * reference to a parameter, this will throw an exception. If the width is variable, this will - * find connections in the enclosing reactor and attempt to infer the width. If the width cannot - * be determined, it will throw an exception. - * - *

IMPORTANT: This method should not be used you really need to determine the width! It will - * not evaluate parameter values. - * - * @see #width(WidthSpec, List) - * @param instantiation A reactor instantiation. - * @return The width, if it can be determined. - * @deprecated - */ - @Deprecated - public static int widthSpecification(Instantiation instantiation) { - int result = width(instantiation.getWidthSpec(), null); - if (result < 0) { - throw new InvalidSourceException( - "Cannot determine width for the instance " + instantiation.getName()); - } - return result; - } - - /** - * Report whether a state variable has been initialized or not. - * - * @param v The state variable to be checked. - * @return True if the variable was initialized, false otherwise. - */ - public static boolean isInitialized(StateVar v) { - return v != null && v.getInit() != null; - } - - /** - * Report whether the given time state variable is initialized using a parameter or not. - * - * @param s A state variable. - * @return True if the argument is initialized using a parameter, false otherwise. - */ - public static boolean isParameterized(StateVar s) { - return s.getInit() != null - && IterableExtensions.exists( - s.getInit().getExprs(), it -> it instanceof ParameterReference); - } - - /** - * Check if the reactor class uses generics - * - * @param r the reactor to check - * @return true if the reactor uses generics - */ - public static boolean isGeneric(Reactor r) { - if (r == null) { - return false; - } - return r.getTypeParms().size() != 0; - } - - /** - * If the specified reactor declaration is an import, then return the imported reactor class - * definition. Otherwise, just return the argument. - * - * @param r A Reactor or an ImportedReactor. - * @return The Reactor class definition or null if no definition is found. - */ - public static Reactor toDefinition(ReactorDecl r) { - if (r == null) return null; - if (r instanceof Reactor) { - return (Reactor) r; - } else if (r instanceof ImportedReactor) { - return ((ImportedReactor) r).getReactorClass(); - } - return null; - } - - /** Return all single-line or multi-line comments immediately preceding the given EObject. */ - public static Stream getPrecedingComments( - ICompositeNode compNode, Predicate filter) { - return getPrecedingCommentNodes(compNode, filter).map(INode::getText); - } - - /** Return all single-line or multi-line comments immediately preceding the given EObject. */ - public static Stream getPrecedingCommentNodes( - ICompositeNode compNode, Predicate filter) { - if (compNode == null) return Stream.of(); - List ret = new ArrayList<>(); - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode)) { - if (isComment(node)) { - if (filter.test(node)) ret.add(node); - } else if (!node.getText().isBlank()) { - break; + return result; + } + + /** + * Given the width specification of port or instantiation + * and an (optional) list of nested instantiations, return + * the width if it can be determined and -1 if not. + * It will not be able to be determined if either the + * width is variable (in which case you should use + * {@link #inferPortWidth(VarRef, Connection, List)} ) + * or the list of instantiations is incomplete or missing. + * If there are parameter references in the width, they are + * evaluated to the extent possible given the instantiations list. + * + * The instantiations list is as in + * {@link #initialValue(Parameter, List)}. + * If the spec belongs to an instantiation (for a bank of reactors), + * then the first element on this list should be the instantiation + * that contains this instantiation. If the spec belongs to a port, + * then the first element on the list should be the instantiation + * of the reactor that contains the port. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * + * @return The width, or -1 if the width could not be determined. + * + * @throws IllegalArgumentException If an instantiation provided is not as + * given above or if the chain of instantiations is not nested. + */ + public static int width(WidthSpec spec, List instantiations) { + if (spec == null) { + return 1; } - } - } - return ret.stream(); - } - - /** Return whether {@code node} is a comment. */ - public static boolean isComment(INode node) { - return node instanceof HiddenLeafNode hlNode - && hlNode.getGrammarElement() instanceof TerminalRule tRule - && tRule.getName().endsWith("_COMMENT"); - } - - /** Return true if the given node starts on the same line as the given other node. */ - public static Predicate sameLine(ICompositeNode compNode) { - return other -> { - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { - return node.getStartLine() == other.getStartLine(); + if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { + return inferWidthFromConnections(spec, instantiations); } - } - return false; - }; - } - - /** - * Find the main reactor and set its name if none was defined. - * - * @param resource The resource to find the main reactor in. - */ - public static void setMainName(Resource resource, String name) { - Reactor main = - IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), - it -> it.isMain() || it.isFederated()); - if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { - main.setName(name); - } - } - - /** - * Create a new instantiation node with the given reactor as its defining class. - * - * @param reactor The reactor class to create an instantiation of. - */ - public static Instantiation createInstantiation(Reactor reactor) { - Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); - inst.setReactorClass(reactor); - // If the reactor is federated or at the top level, then it - // may not have a name. In the generator's doGenerate() - // method, the name gets set using setMainName(). - // But this may be called before that, e.g. during - // diagram synthesis. We assign a temporary name here. - if (reactor.getName() == null) { - if (reactor.isFederated() || reactor.isMain()) { - inst.setName("main"); - } else { - inst.setName(""); - } - - } else { - inst.setName(reactor.getName()); - } - return inst; - } - - /** - * Returns the target declaration in the given model. Non-null because it would cause a parse - * error. - */ - public static TargetDecl targetDecl(Model model) { - return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); - } - - /** - * Returns the target declaration in the given resource. Non-null because it would cause a parse - * error. - */ - public static TargetDecl targetDecl(Resource model) { - return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); - } - - ///////////////////////////////////////////////////////// - //// Private methods - - /** Returns the list if it is not null. Otherwise, return an empty list. */ - public static List convertToEmptyListIfNull(List list) { - return list != null ? list : new ArrayList<>(); - } - - /** - * Return all the superclasses of the specified reactor in deepest-first order. For example, if A - * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates - * are removed. If the specified reactor does not extend any other reactor, then return an empty - * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared - * that is not found, then return null. - * - * @param reactor The specified reactor. - * @param extensions A set of reactors extending the specified reactor (used to detect circular - * extensions). - */ - private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { - LinkedHashSet result = new LinkedHashSet<>(); - for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { - Reactor r = toDefinition(superDecl); - if (r == reactor || r == null) return null; - // If r is in the extensions, then we have a circular inheritance structure. - if (extensions.contains(r)) return null; - extensions.add(r); - LinkedHashSet baseExtends = superClasses(r, extensions); - extensions.remove(r); - if (baseExtends == null) return null; - result.addAll(baseExtends); - result.add(r); - } - return result; - } - - /** - * We may be able to infer the width by examining the connections of the enclosing reactor - * definition. This works, for example, with delays between multiports or banks of reactors. - * Attempt to infer the width from connections and return -1 if the width cannot be inferred. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * @return The width, or -1 if the width could not be inferred from connections. - */ - private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { - for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : c.getLeftPorts()) { - if (leftPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the left. - leftOrRight = -1; - } else { - leftWidth += inferPortWidth(leftPort, c, instantiations); + var result = 0; + for (WidthTerm term: spec.getTerms()) { + if (term.getParameter() != null) { + Integer termWidth = initialValueInt(term.getParameter(), instantiations); + if (termWidth != null) { + result += termWidth; + } else { + return -1; + } + } else if (term.getWidth() > 0) { + result += term.getWidth(); + } else { + // If the width cannot be determined because term's width <= 0, which means the term's width + // must be inferred, try to infer the width using connections. + if (spec.eContainer() instanceof Instantiation) { + try { + return inferWidthFromConnections(spec, instantiations); + } catch (InvalidSourceException e) { + // If the inference fails, return -1. + return -1; + } + } + } + } + return result; + } + + /** + * Infer the width of a port reference in a connection. + * The port reference one or two parts, a port and an (optional) container + * which is an Instantiation that may refer to a bank of reactors. + * The width will be the product of the bank width and the port width. + * The returned value will be 1 if the port is not in a bank and is not a multiport. + * + * If the width cannot be determined, this will return -1. + * The width cannot be determined if the list of instantiations is + * missing or incomplete. + * + * The instantiations list is as in + * {@link #initialValue(Parameter, List)}. + * The first element on this list should be the instantiation + * that contains the specified connection. + * + * @param reference A port reference. + * @param connection A connection, or null if not in the context of a connection. + * @param instantiations The (optional) list of instantiations. + * + * @return The width or -1 if it could not be determined. + * + * @throws IllegalArgumentException If an instantiation provided is not as + * given above or if the chain of instantiations is not nested. + */ + public static int inferPortWidth( + VarRef reference, Connection connection, List instantiations + ) { + if (reference.getVariable() instanceof Port) { + // If the port is given as a.b, then we want to prepend a to + // the list of instantiations to determine the width of this port. + List extended = instantiations; + if (reference.getContainer() != null) { + extended = new ArrayList<>(); + extended.add(reference.getContainer()); + if (instantiations != null) { + extended.addAll(instantiations); + } + } + + int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); + if (portWidth < 0) { + // Could not determine port width. + return -1; + } + + // Next determine the bank width. This may be unspecified, in which + // case it has to be inferred using the connection. + int bankWidth = 1; + if (reference.getContainer() != null) { + bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); + if (bankWidth < 0 && connection != null) { + // Try to infer the bank width from the connection. + if (reference.getContainer().getWidthSpec().isOfVariableLength()) { + // This occurs for a bank of delays. + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : connection.getLeftPorts()) { + if (leftPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the left. + leftOrRight = -1; + } else { + // The left port is not the same as this reference. + int otherWidth = inferPortWidth(leftPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; + } + leftWidth += otherWidth; + } + } + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the right. + leftOrRight = 1; + } else { + int otherWidth = inferPortWidth(rightPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; + } + rightWidth += otherWidth; + } + } + int discrepancy = 0; + if (leftOrRight < 0) { + // This port is on the left. + discrepancy = rightWidth - leftWidth; + } else if (leftOrRight > 0) { + // This port is on the right. + discrepancy = leftWidth - rightWidth; + } + // Check that portWidth divides the discrepancy. + if (discrepancy % portWidth != 0) { + // This is an error. + return -1; + } + bankWidth = discrepancy / portWidth; + } else { + // Could not determine the bank width. + return -1; + } + } + } + return portWidth * bankWidth; + } + // Argument is not a port. + return -1; + } + + /** + * Given an instantiation of a reactor or bank of reactors, return + * the width. This will be 1 if this is not a reactor bank. Otherwise, + * this will attempt to determine the width. If the width is declared + * as a literal constant, it will return that constant. If the width + * is specified as a reference to a parameter, this will throw an + * exception. If the width is variable, this will find + * connections in the enclosing reactor and attempt to infer the + * width. If the width cannot be determined, it will throw an exception. + * + * IMPORTANT: This method should not be used you really need to + * determine the width! It will not evaluate parameter values. + * @see #width(WidthSpec, List) + * + * @param instantiation A reactor instantiation. + * + * @return The width, if it can be determined. + * @deprecated + */ + @Deprecated + public static int widthSpecification(Instantiation instantiation) { + int result = width(instantiation.getWidthSpec(), null); + if (result < 0) { + throw new InvalidSourceException("Cannot determine width for the instance " + + instantiation.getName()); + } + return result; + } + + /** + * Report whether a state variable has been initialized or not. + * @param v The state variable to be checked. + * @return True if the variable was initialized, false otherwise. + */ + public static boolean isInitialized(StateVar v) { + return v != null && v.getInit() != null; + } + + /** + * Report whether the given time state variable is initialized using a + * parameter or not. + * @param s A state variable. + * @return True if the argument is initialized using a parameter, false + * otherwise. + */ + public static boolean isParameterized(StateVar s) { + return s.getInit() != null && + IterableExtensions.exists(s.getInit().getExprs(), it -> it instanceof ParameterReference); + } + + /** + * Check if the reactor class uses generics + * @param r the reactor to check + * @return true if the reactor uses generics + */ + public static boolean isGeneric(Reactor r) { + if (r == null) { + return false; + } + return r.getTypeParms().size() != 0; + } + + /** + * If the specified reactor declaration is an import, then + * return the imported reactor class definition. Otherwise, + * just return the argument. + * @param r A Reactor or an ImportedReactor. + * @return The Reactor class definition or null if no definition is found. + */ + public static Reactor toDefinition(ReactorDecl r) { + if (r == null) + return null; + if (r instanceof Reactor) { + return (Reactor) r; + } else if (r instanceof ImportedReactor) { + return ((ImportedReactor) r).getReactorClass(); + } + return null; + } + + /** + * Return all single-line or multi-line comments immediately preceding the + * given EObject. + */ + public static Stream getPrecedingComments( + ICompositeNode compNode, + Predicate filter + ) { + return getPrecedingCommentNodes(compNode, filter).map(INode::getText); + } + + /** + * Return all single-line or multi-line comments immediately preceding the + * given EObject. + */ + public static Stream getPrecedingCommentNodes( + ICompositeNode compNode, + Predicate filter + ) { + if (compNode == null) return Stream.of(); + List ret = new ArrayList<>(); + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode)) { + if (isComment(node)) { + if (filter.test(node)) ret.add(node); + } else if (!node.getText().isBlank()) { + break; + } + } + } + return ret.stream(); + } + + /** Return whether {@code node} is a comment. */ + public static boolean isComment(INode node) { + return node instanceof HiddenLeafNode hlNode + && hlNode.getGrammarElement() instanceof TerminalRule tRule + && tRule.getName().endsWith("_COMMENT"); + } + + /** + * Return true if the given node starts on the same line as the given other + * node. + */ + public static Predicate sameLine(ICompositeNode compNode) { + return other -> { + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { + return node.getStartLine() == other.getStartLine(); + } + } + return false; + }; + } + + /** + * Find the main reactor and set its name if none was defined. + * @param resource The resource to find the main reactor in. + */ + public static void setMainName(Resource resource, String name) { + Reactor main = IteratorExtensions.findFirst(Iterators.filter(resource.getAllContents(), Reactor.class), + it -> it.isMain() || it.isFederated() + ); + if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { + main.setName(name); } - } - for (VarRef rightPort : c.getRightPorts()) { - if (rightPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the right. - leftOrRight = 1; + } + + /** + * Create a new instantiation node with the given reactor as its defining class. + * @param reactor The reactor class to create an instantiation of. + */ + public static Instantiation createInstantiation(Reactor reactor) { + Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); + inst.setReactorClass(reactor); + // If the reactor is federated or at the top level, then it + // may not have a name. In the generator's doGenerate() + // method, the name gets set using setMainName(). + // But this may be called before that, e.g. during + // diagram synthesis. We assign a temporary name here. + if (reactor.getName() == null) { + if (reactor.isFederated() || reactor.isMain()) { + inst.setName("main"); + } else { + inst.setName(""); + } + } else { - rightWidth += inferPortWidth(rightPort, c, instantiations); + inst.setName(reactor.getName()); } - } - if (leftOrRight < 0) { - return rightWidth - leftWidth; - } else if (leftOrRight > 0) { - return leftWidth - rightWidth; - } - } - // A connection was not found with the instantiation. - return -1; - } - - public static void addReactionAttribute(Reaction reaction, String name) { - var fedAttr = factory.createAttribute(); - fedAttr.setAttrName(name); - reaction.getAttributes().add(fedAttr); - } + return inst; + } + + /** + * Returns the target declaration in the given model. + * Non-null because it would cause a parse error. + */ + public static TargetDecl targetDecl(Model model) { + return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); + } + + /** + * Returns the target declaration in the given resource. + * Non-null because it would cause a parse error. + */ + public static TargetDecl targetDecl(Resource model) { + return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); + } + + ///////////////////////////////////////////////////////// + //// Private methods + + /** + * Returns the list if it is not null. Otherwise, return an empty list. + */ + public static List convertToEmptyListIfNull(List list) { + return list != null ? list : new ArrayList<>(); + } + + /** + * Return all the superclasses of the specified reactor + * in deepest-first order. For example, if A extends B and C, and + * B and C both extend D, this will return the list [D, B, C, A]. + * Duplicates are removed. If the specified reactor does not extend + * any other reactor, then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor + * (used to detect circular extensions). + */ + private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet baseExtends = superClasses(r, extensions); + extensions.remove(r); + if (baseExtends == null) return null; + result.addAll(baseExtends); + result.add(r); + } + return result; + } + + /** + * We may be able to infer the width by examining the connections of + * the enclosing reactor definition. This works, for example, with + * delays between multiports or banks of reactors. + * Attempt to infer the width from connections and return -1 if the width cannot be inferred. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * + * @return The width, or -1 if the width could not be inferred from connections. + */ + private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { + for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : c.getLeftPorts()) { + if (leftPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the left. + leftOrRight = -1; + } else { + leftWidth += inferPortWidth(leftPort, c, instantiations); + } + } + for (VarRef rightPort : c.getRightPorts()) { + if (rightPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the right. + leftOrRight = 1; + } else { + rightWidth += inferPortWidth(rightPort, c, instantiations); + } + } + if (leftOrRight < 0) { + return rightWidth - leftWidth; + } else if (leftOrRight > 0) { + return leftWidth - rightWidth; + } + } + // A connection was not found with the instantiation. + return -1; + } + + public static void addReactionAttribute(Reaction reaction, String name) { + var fedAttr = factory.createAttribute(); + fedAttr.setAttrName(name); + reaction.getAttributes().add(fedAttr); + } } From c25c8b7f01017437780596a174a8c609c76a1f03 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 30 Apr 2023 10:54:44 +0200 Subject: [PATCH 211/709] Removed unused imports --- org.lflang/src/org/lflang/ASTUtils.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index f8c436727c..23b799dd53 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -32,7 +32,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -61,8 +60,6 @@ import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Assignment; -import org.lflang.lf.AttrParm; -import org.lflang.lf.Attribute; import org.lflang.lf.Code; import org.lflang.lf.Connection; import org.lflang.lf.Element; @@ -263,7 +260,6 @@ public static Target getTarget(EObject object) { /** * Add a new target property to the given resource. - * * This also creates a config object if the resource does not yey have one. * * @param resource The resource to modify From 592e2c0180b88ff809595145580d2bfde0bc41bb Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 30 Apr 2023 10:58:28 +0200 Subject: [PATCH 212/709] Revert formatting changes --- org.lflang/src/org/lflang/ast/IsEqual.java | 1202 ++++++++++---------- 1 file changed, 610 insertions(+), 592 deletions(-) diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 73cd12916a..af0274ea2a 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -6,7 +6,9 @@ import java.util.function.BiPredicate; import java.util.function.Function; import java.util.stream.Collectors; + import org.eclipse.emf.ecore.EObject; + import org.lflang.TimeUnit; import org.lflang.lf.Action; import org.lflang.lf.Array; @@ -64,604 +66,620 @@ import org.lflang.lf.util.LfSwitch; /** - * Switch class that checks if subtrees of the AST are semantically equivalent to each other. Return - * {@code false} if they are not equivalent; return {@code true} or {@code false} (but preferably - * {@code true}) if they are equivalent. + * Switch class that checks if subtrees of the AST are semantically equivalent + * to each other. Return {@code false} if they are not equivalent; return + * {@code true} or {@code false} (but preferably {@code true}) if they are + * equivalent. */ public class IsEqual extends LfSwitch { - private final EObject otherObject; - - public IsEqual(EObject other) { - this.otherObject = other; - } - - @Override - public Boolean doSwitch(EObject eObject) { - if (otherObject == eObject) return true; - if (eObject == null) return false; - return super.doSwitch(eObject); - } - - @Override - public Boolean caseModel(Model object) { - return new ComparisonMachine<>(object, Model.class) - .equivalent(Model::getTarget) - .listsEquivalent(Model::getImports) - .listsEquivalent(Model::getPreambles) - .listsEquivalent(Model::getReactors) - .conclusion; - } - - @Override - public Boolean caseImport(Import object) { - return new ComparisonMachine<>(object, Import.class) - .equalAsObjects(Import::getImportURI) - .listsEquivalent(Import::getReactorClasses) - .conclusion; - } - - @Override - public Boolean caseReactorDecl(ReactorDecl object) { - return new ComparisonMachine<>(object, ReactorDecl.class) - .equalAsObjects(ReactorDecl::getName) - .conclusion; - } - - @Override - public Boolean caseImportedReactor(ImportedReactor object) { - return new ComparisonMachine<>(object, ImportedReactor.class) - .equalAsObjects(ImportedReactor::getName) - .equivalent(ImportedReactor::getReactorClass) - .conclusion; - } - - @Override - public Boolean caseReactor(Reactor object) { - return new ComparisonMachine<>(object, Reactor.class) - .listsEquivalent(Reactor::getAttributes) - .equalAsObjects(Reactor::isFederated) - .equalAsObjects(Reactor::isRealtime) - .equalAsObjects(Reactor::isMain) - .equalAsObjects(Reactor::getName) - .listsEquivalent(Reactor::getTypeParms) - .listsEquivalent(Reactor::getParameters) - .equivalent(Reactor::getHost) - .listsEquivalent(Reactor::getSuperClasses) - .listsEquivalent(Reactor::getPreambles) - .listsEquivalent(Reactor::getInputs) - .listsEquivalent(Reactor::getOutputs) - .listsEquivalent(Reactor::getTimers) - .listsEquivalent(Reactor::getActions) - .listsEquivalent(Reactor::getInstantiations) - .listsEquivalent(Reactor::getConnections) - .listsEquivalent(Reactor::getStateVars) - .listsEquivalent(Reactor::getReactions) - .listsEquivalent(Reactor::getMethods) - .listsEquivalent(Reactor::getModes) - .conclusion; - } - - @Override - public Boolean caseTypeParm(TypeParm object) { - return new ComparisonMachine<>(object, TypeParm.class) - .equalAsObjects(TypeParm::getLiteral) - .equivalent(TypeParm::getCode) - .conclusion; - } - - @Override - public Boolean caseTargetDecl(TargetDecl object) { - return new ComparisonMachine<>(object, TargetDecl.class) - .equalAsObjects(TargetDecl::getName) - .equivalentModulo( - TargetDecl::getConfig, - (KeyValuePairs it) -> it != null && it.getPairs().isEmpty() ? null : it) - .conclusion; - } - - @Override - public Boolean caseStateVar(StateVar object) { - return new ComparisonMachine<>(object, StateVar.class) - .listsEquivalent(StateVar::getAttributes) - .equalAsObjects(StateVar::getName) - .equivalent(StateVar::getType) - .equivalent(StateVar::getInit) - .conclusion; - } - - @Override - public Boolean caseInitializer(Initializer object) { - // Empty braces are not equivalent to no init. - return new ComparisonMachine<>(object, Initializer.class) - .equalAsObjects(Initializer::isBraces) - // An initializer with no parens is equivalent to one with parens, - // if the list has a single element. This is probably going to change - // when we introduce equals initializers. - // .equalAsObjects(Initializer::isParens) - .listsEquivalent(Initializer::getExprs) - .conclusion; - } - - @Override - public Boolean caseMethod(Method object) { - return new ComparisonMachine<>(object, Method.class) - .equalAsObjects(Method::isConst) - .equalAsObjects(Method::getName) - .listsEquivalent(Method::getArguments) - .equivalent(Method::getReturn) - .equivalent(Method::getCode) - .conclusion; - } - - @Override - public Boolean caseMethodArgument(MethodArgument object) { - return new ComparisonMachine<>(object, MethodArgument.class) - .equalAsObjects(MethodArgument::getName) - .equivalent(MethodArgument::getType) - .conclusion; - } - - @Override - public Boolean caseInput(Input object) { - return new ComparisonMachine<>(object, Input.class) - .listsEquivalent(Input::getAttributes) - .equalAsObjects(Input::isMutable) - .equivalent(Input::getWidthSpec) - .equivalent(Input::getType) - .conclusion; - } - - @Override - public Boolean caseOutput(Output object) { - return new ComparisonMachine<>(object, Output.class) - .listsEquivalent(Output::getAttributes) - .equivalent(Output::getWidthSpec) - .equalAsObjects(Output::getName) - .equivalent(Output::getType) - .conclusion; - } - - @Override - public Boolean caseTimer(Timer object) { - return new ComparisonMachine<>(object, Timer.class) - .listsEquivalent(Timer::getAttributes) - .equalAsObjects(Timer::getName) - .equivalent(Timer::getOffset) - .equivalent(Timer::getPeriod) - .conclusion; - } - - @Override - public Boolean caseMode(Mode object) { - return new ComparisonMachine<>(object, Mode.class) - .equalAsObjects(Mode::isInitial) - .equalAsObjects(Mode::getName) - .listsEquivalent(Mode::getStateVars) - .listsEquivalent(Mode::getTimers) - .listsEquivalent(Mode::getActions) - .listsEquivalent(Mode::getInstantiations) - .listsEquivalent(Mode::getConnections) - .listsEquivalent(Mode::getReactions) - .conclusion; - } - - @Override - public Boolean caseAction(Action object) { - return new ComparisonMachine<>(object, Action.class) - .listsEquivalent(Action::getAttributes) - .equalAsObjects(Action::getOrigin) // This is an enum - .equalAsObjects(Action::getName) - .equivalent(Action::getMinDelay) - .equivalent(Action::getMinSpacing) - .equalAsObjects(Action::getPolicy) - .equivalent(Action::getType) - .conclusion; - } - - @Override - public Boolean caseAttribute(Attribute object) { - return new ComparisonMachine<>(object, Attribute.class) - .equalAsObjects(Attribute::getAttrName) - .listsEquivalent(Attribute::getAttrParms) - .conclusion; - } - - @Override - public Boolean caseAttrParm(AttrParm object) { - return new ComparisonMachine<>(object, AttrParm.class) - .equalAsObjects(AttrParm::getName) - .equalAsObjects(AttrParm::getValue) - .conclusion; - } - - @Override - public Boolean caseReaction(Reaction object) { - return new ComparisonMachine<>(object, Reaction.class) - .listsEquivalent(Reaction::getAttributes) - .listsEquivalent(Reaction::getTriggers) - .listsEquivalent(Reaction::getSources) - .listsEquivalent(Reaction::getEffects) - .equalAsObjects(Reaction::isMutation) - .equalAsObjects(Reaction::getName) - .equivalent(Reaction::getCode) - .equivalent(Reaction::getStp) - .equivalent(Reaction::getDeadline) - .conclusion; - } - - @Override - public Boolean caseTriggerRef(TriggerRef object) { - throw thereIsAMoreSpecificCase(TriggerRef.class, BuiltinTriggerRef.class, VarRef.class); - } - - @Override - public Boolean caseBuiltinTriggerRef(BuiltinTriggerRef object) { - return new ComparisonMachine<>(object, BuiltinTriggerRef.class) - .equalAsObjects(BuiltinTriggerRef::getType) // This is an enum - .conclusion; - } - - @Override - public Boolean caseDeadline(Deadline object) { - return new ComparisonMachine<>(object, Deadline.class) - .equivalent(Deadline::getDelay) - .equivalent(Deadline::getCode) - .conclusion; - } - - @Override - public Boolean caseSTP(STP object) { - return new ComparisonMachine<>(object, STP.class) - .equivalent(STP::getValue) - .equivalent(STP::getCode) - .conclusion; - } - - @Override - public Boolean casePreamble(Preamble object) { - return new ComparisonMachine<>(object, Preamble.class) - .equalAsObjects(Preamble::getVisibility) // This is an enum - .equivalent(Preamble::getCode) - .conclusion; - } - - @Override - public Boolean caseInstantiation(Instantiation object) { - return new ComparisonMachine<>(object, Instantiation.class) - .equalAsObjects(Instantiation::getName) - .equivalent(Instantiation::getWidthSpec) - .equivalent(Instantiation::getReactorClass) - .listsEquivalent(Instantiation::getTypeArgs) - .listsEquivalent(Instantiation::getParameters) - .equivalent(Instantiation::getHost) - .conclusion; - } - - @Override - public Boolean caseConnection(Connection object) { - return new ComparisonMachine<>(object, Connection.class) - .listsEquivalent(Connection::getLeftPorts) - .equalAsObjects(Connection::isIterated) - .equalAsObjects(Connection::isPhysical) - .listsEquivalent(Connection::getRightPorts) - .equivalent(Connection::getDelay) - .equivalent(Connection::getSerializer) - .conclusion; - } - - @Override - public Boolean caseSerializer(Serializer object) { - return new ComparisonMachine<>(object, Serializer.class) - .equalAsObjects(Serializer::getType) - .conclusion; - } - - @Override - public Boolean caseKeyValuePairs(KeyValuePairs object) { - return new ComparisonMachine<>(object, KeyValuePairs.class) - .listsEquivalent(KeyValuePairs::getPairs) - .conclusion; - } - - @Override - public Boolean caseKeyValuePair(KeyValuePair object) { - return new ComparisonMachine<>(object, KeyValuePair.class) - .equalAsObjects(KeyValuePair::getName) - .equivalent(KeyValuePair::getValue) - .conclusion; - } - - @Override - public Boolean caseArray(Array object) { - return new ComparisonMachine<>(object, Array.class) - .listsEquivalent(Array::getElements) - .conclusion; - } - - @Override - public Boolean caseElement(Element object) { - return new ComparisonMachine<>(object, Element.class) - .equivalent(Element::getKeyvalue) - .equivalent(Element::getArray) - .equalAsObjects(Element::getLiteral) - .equalAsObjects(Element::getId) - .equalAsObjects(Element::getUnit) - .conclusion; - } - - @Override - public Boolean caseTypedVariable(TypedVariable object) { - throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); - } - - @Override - public Boolean caseVariable(Variable object) { - throw thereIsAMoreSpecificCase( - Variable.class, TypedVariable.class, Timer.class, Mode.class, Watchdog.class); - } - - @Override - public Boolean caseVarRef(VarRef object) { - return new ComparisonMachine<>(object, VarRef.class) - .equalAsObjects( - varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable().getName()) - .equivalent(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable()) - .equalAsObjects( - varRef -> varRef.getContainer() == null ? null : varRef.getContainer().getName()) - .equalAsObjects(VarRef::isInterleaved) - .equalAsObjects(VarRef::getTransition) - .conclusion; - } - - @Override - public Boolean caseAssignment(Assignment object) { - return new ComparisonMachine<>(object, Assignment.class) - .equivalent(Assignment::getLhs) - .equivalent(Assignment::getRhs) - .conclusion; - } - - @Override - public Boolean caseParameter(Parameter object) { - return new ComparisonMachine<>(object, Parameter.class) - .listsEquivalent(Parameter::getAttributes) - .equalAsObjects(Parameter::getName) - .equivalent(Parameter::getType) - .equivalent(Parameter::getInit) - .conclusion; - } - - @Override - public Boolean caseExpression(Expression object) { - throw thereIsAMoreSpecificCase( - Expression.class, - Literal.class, - Time.class, - ParameterReference.class, - Code.class, - BracedListExpression.class); - } - - @Override - public Boolean caseBracedListExpression(BracedListExpression object) { - return new ComparisonMachine<>(object, BracedListExpression.class) - .listsEquivalent(BracedListExpression::getItems) - .conclusion; - } - - @Override - public Boolean caseParameterReference(ParameterReference object) { - return new ComparisonMachine<>(object, ParameterReference.class) - .equivalent(ParameterReference::getParameter) - .conclusion; - } - - @Override - public Boolean caseTime(Time object) { - return new ComparisonMachine<>(object, Time.class) - .equalAsObjects(Time::getInterval) - .equalAsObjectsModulo( - Time::getUnit, - ((Function) TimeUnit::getCanonicalName).compose(TimeUnit::fromName)) - .conclusion; - } - - @Override - public Boolean casePort(Port object) { - throw thereIsAMoreSpecificCase(Port.class, Input.class, Output.class); - } - - @Override - public Boolean caseType(Type object) { - return new ComparisonMachine<>(object, Type.class) - .equivalent(Type::getCode) - .equalAsObjects(Type::isTime) - .equivalent(Type::getArraySpec) - .equalAsObjects(Type::getId) - .listsEquivalent(Type::getTypeArgs) - .listsEqualAsObjects(Type::getStars) - .equivalent(Type::getArraySpec) - .equivalent(Type::getCode) - .conclusion; - } - - @Override - public Boolean caseArraySpec(ArraySpec object) { - return new ComparisonMachine<>(object, ArraySpec.class) - .equalAsObjects(ArraySpec::isOfVariableLength) - .equalAsObjects(ArraySpec::getLength) - .conclusion; - } - - @Override - public Boolean caseWatchdog(Watchdog object) { - return new ComparisonMachine<>(object, Watchdog.class) - .equalAsObjects(Watchdog::getName) - .equivalent(Watchdog::getTimeout) - .listsEquivalent(Watchdog::getEffects) - .equivalent(Watchdog::getCode) - .conclusion; - } - - @Override - public Boolean caseWidthSpec(WidthSpec object) { - return new ComparisonMachine<>(object, WidthSpec.class) - .equalAsObjects(WidthSpec::isOfVariableLength) - .listsEquivalent(WidthSpec::getTerms) - .conclusion; - } - - @Override - public Boolean caseWidthTerm(WidthTerm object) { - return new ComparisonMachine<>(object, WidthTerm.class) - .equalAsObjects(WidthTerm::getWidth) - .equivalent(WidthTerm::getParameter) - .equivalent(WidthTerm::getPort) - .equivalent(WidthTerm::getCode) - .conclusion; - } - - @Override - public Boolean caseIPV4Host(IPV4Host object) { - return caseHost(object); - } - - @Override - public Boolean caseIPV6Host(IPV6Host object) { - return caseHost(object); - } - - @Override - public Boolean caseNamedHost(NamedHost object) { - return caseHost(object); - } - - @Override - public Boolean caseHost(Host object) { - return new ComparisonMachine<>(object, Host.class) - .equalAsObjects(Host::getUser) - .equalAsObjects(Host::getAddr) - .equalAsObjects(Host::getPort) - .conclusion; - } - - @Override - public Boolean caseCodeExpr(CodeExpr object) { - return new ComparisonMachine<>(object, CodeExpr.class).equivalent(CodeExpr::getCode).conclusion; - } - - @Override - public Boolean caseCode(Code object) { - return new ComparisonMachine<>(object, Code.class) - .equalAsObjectsModulo(Code::getBody, s -> s == null ? null : s.strip().stripIndent()) - .conclusion; - } - - @Override - public Boolean caseLiteral(Literal object) { - return new ComparisonMachine<>(object, Literal.class) - .equalAsObjects(Literal::getLiteral) - .conclusion; - } - - @Override - public Boolean defaultCase(EObject object) { - return super.defaultCase(object); - } - - @SafeVarargs - private UnsupportedOperationException thereIsAMoreSpecificCase( - Class thisCase, Class... moreSpecificCases) { - return new UnsupportedOperationException( - String.format( + private final EObject otherObject; + + public IsEqual(EObject other) { + this.otherObject = other; + } + + @Override + public Boolean doSwitch(EObject eObject) { + if (otherObject == eObject) return true; + if (eObject == null) return false; + return super.doSwitch(eObject); + } + + @Override + public Boolean caseModel(Model object) { + return new ComparisonMachine<>(object, Model.class) + .equivalent(Model::getTarget) + .listsEquivalent(Model::getImports) + .listsEquivalent(Model::getPreambles) + .listsEquivalent(Model::getReactors).conclusion; + } + + @Override + public Boolean caseImport(Import object) { + return new ComparisonMachine<>(object, Import.class) + .equalAsObjects(Import::getImportURI) + .listsEquivalent(Import::getReactorClasses).conclusion; + } + + @Override + public Boolean caseReactorDecl(ReactorDecl object) { + return new ComparisonMachine<>(object, ReactorDecl.class) + .equalAsObjects(ReactorDecl::getName) + .conclusion; + } + + @Override + public Boolean caseImportedReactor(ImportedReactor object) { + return new ComparisonMachine<>(object, ImportedReactor.class) + .equalAsObjects(ImportedReactor::getName) + .equivalent(ImportedReactor::getReactorClass) + .conclusion; + } + + @Override + public Boolean caseReactor(Reactor object) { + return new ComparisonMachine<>(object, Reactor.class) + .listsEquivalent(Reactor::getAttributes) + .equalAsObjects(Reactor::isFederated) + .equalAsObjects(Reactor::isRealtime) + .equalAsObjects(Reactor::isMain) + .equalAsObjects(Reactor::getName) + .listsEquivalent(Reactor::getTypeParms) + .listsEquivalent(Reactor::getParameters) + .equivalent(Reactor::getHost) + .listsEquivalent(Reactor::getSuperClasses) + .listsEquivalent(Reactor::getPreambles) + .listsEquivalent(Reactor::getInputs) + .listsEquivalent(Reactor::getOutputs) + .listsEquivalent(Reactor::getTimers) + .listsEquivalent(Reactor::getActions) + .listsEquivalent(Reactor::getInstantiations) + .listsEquivalent(Reactor::getConnections) + .listsEquivalent(Reactor::getStateVars) + .listsEquivalent(Reactor::getReactions) + .listsEquivalent(Reactor::getMethods) + .listsEquivalent(Reactor::getModes) + .conclusion; + } + + @Override + public Boolean caseTypeParm(TypeParm object) { + return new ComparisonMachine<>(object, TypeParm.class) + .equalAsObjects(TypeParm::getLiteral) + .equivalent(TypeParm::getCode) + .conclusion; + } + + @Override + public Boolean caseTargetDecl(TargetDecl object) { + return new ComparisonMachine<>(object, TargetDecl.class) + .equalAsObjects(TargetDecl::getName) + .equivalentModulo( + TargetDecl::getConfig, + (KeyValuePairs it) -> it != null && it.getPairs().isEmpty() ? null : it + ) + .conclusion; + } + + @Override + public Boolean caseStateVar(StateVar object) { + return new ComparisonMachine<>(object, StateVar.class) + .listsEquivalent(StateVar::getAttributes) + .equalAsObjects(StateVar::getName) + .equivalent(StateVar::getType) + .equivalent(StateVar::getInit) + .conclusion; + } + + @Override + public Boolean caseInitializer(Initializer object) { + // Empty braces are not equivalent to no init. + return new ComparisonMachine<>(object, Initializer.class) + .equalAsObjects(Initializer::isBraces) + // An initializer with no parens is equivalent to one with parens, + // if the list has a single element. This is probably going to change + // when we introduce equals initializers. + // .equalAsObjects(Initializer::isParens) + .listsEquivalent(Initializer::getExprs) + .conclusion; + } + + @Override + public Boolean caseMethod(Method object) { + return new ComparisonMachine<>(object, Method.class) + .equalAsObjects(Method::isConst) + .equalAsObjects(Method::getName) + .listsEquivalent(Method::getArguments) + .equivalent(Method::getReturn) + .equivalent(Method::getCode) + .conclusion; + } + + @Override + public Boolean caseMethodArgument(MethodArgument object) { + return new ComparisonMachine<>(object, MethodArgument.class) + .equalAsObjects(MethodArgument::getName) + .equivalent(MethodArgument::getType) + .conclusion; + } + + @Override + public Boolean caseInput(Input object) { + return new ComparisonMachine<>(object, Input.class) + .listsEquivalent(Input::getAttributes) + .equalAsObjects(Input::isMutable) + .equivalent(Input::getWidthSpec) + .equivalent(Input::getType) + .conclusion; + } + + @Override + public Boolean caseOutput(Output object) { + return new ComparisonMachine<>(object, Output.class) + .listsEquivalent(Output::getAttributes) + .equivalent(Output::getWidthSpec) + .equalAsObjects(Output::getName) + .equivalent(Output::getType) + .conclusion; + } + + @Override + public Boolean caseTimer(Timer object) { + return new ComparisonMachine<>(object, Timer.class) + .listsEquivalent(Timer::getAttributes) + .equalAsObjects(Timer::getName) + .equivalent(Timer::getOffset) + .equivalent(Timer::getPeriod) + .conclusion; + } + + @Override + public Boolean caseMode(Mode object) { + return new ComparisonMachine<>(object, Mode.class) + .equalAsObjects(Mode::isInitial) + .equalAsObjects(Mode::getName) + .listsEquivalent(Mode::getStateVars) + .listsEquivalent(Mode::getTimers) + .listsEquivalent(Mode::getActions) + .listsEquivalent(Mode::getInstantiations) + .listsEquivalent(Mode::getConnections) + .listsEquivalent(Mode::getReactions) + .conclusion; + } + + @Override + public Boolean caseAction(Action object) { + return new ComparisonMachine<>(object, Action.class) + .listsEquivalent(Action::getAttributes) + .equalAsObjects(Action::getOrigin) // This is an enum + .equalAsObjects(Action::getName) + .equivalent(Action::getMinDelay) + .equivalent(Action::getMinSpacing) + .equalAsObjects(Action::getPolicy) + .equivalent(Action::getType) + .conclusion; + } + + @Override + public Boolean caseAttribute(Attribute object) { + return new ComparisonMachine<>(object, Attribute.class) + .equalAsObjects(Attribute::getAttrName) + .listsEquivalent(Attribute::getAttrParms) + .conclusion; + } + + @Override + public Boolean caseAttrParm(AttrParm object) { + return new ComparisonMachine<>(object, AttrParm.class) + .equalAsObjects(AttrParm::getName) + .equalAsObjects(AttrParm::getValue) + .conclusion; + } + + @Override + public Boolean caseReaction(Reaction object) { + return new ComparisonMachine<>(object, Reaction.class) + .listsEquivalent(Reaction::getAttributes) + .listsEquivalent(Reaction::getTriggers) + .listsEquivalent(Reaction::getSources) + .listsEquivalent(Reaction::getEffects) + .equalAsObjects(Reaction::isMutation) + .equalAsObjects(Reaction::getName) + .equivalent(Reaction::getCode) + .equivalent(Reaction::getStp) + .equivalent(Reaction::getDeadline) + .conclusion; + } + + @Override + public Boolean caseTriggerRef(TriggerRef object) { + throw thereIsAMoreSpecificCase(TriggerRef.class, BuiltinTriggerRef.class, VarRef.class); + } + + @Override + public Boolean caseBuiltinTriggerRef(BuiltinTriggerRef object) { + return new ComparisonMachine<>(object, BuiltinTriggerRef.class) + .equalAsObjects(BuiltinTriggerRef::getType) // This is an enum + .conclusion; + } + + @Override + public Boolean caseDeadline(Deadline object) { + return new ComparisonMachine<>(object, Deadline.class) + .equivalent(Deadline::getDelay) + .equivalent(Deadline::getCode) + .conclusion; + } + + @Override + public Boolean caseSTP(STP object) { + return new ComparisonMachine<>(object, STP.class) + .equivalent(STP::getValue) + .equivalent(STP::getCode) + .conclusion; + } + + @Override + public Boolean casePreamble(Preamble object) { + return new ComparisonMachine<>(object, Preamble.class) + .equalAsObjects(Preamble::getVisibility) // This is an enum + .equivalent(Preamble::getCode) + .conclusion; + } + + @Override + public Boolean caseInstantiation(Instantiation object) { + return new ComparisonMachine<>(object, Instantiation.class) + .equalAsObjects(Instantiation::getName) + .equivalent(Instantiation::getWidthSpec) + .equivalent(Instantiation::getReactorClass) + .listsEquivalent(Instantiation::getTypeArgs) + .listsEquivalent(Instantiation::getParameters) + .equivalent(Instantiation::getHost) + .conclusion; + } + + @Override + public Boolean caseConnection(Connection object) { + return new ComparisonMachine<>(object, Connection.class) + .listsEquivalent(Connection::getLeftPorts) + .equalAsObjects(Connection::isIterated) + .equalAsObjects(Connection::isPhysical) + .listsEquivalent(Connection::getRightPorts) + .equivalent(Connection::getDelay) + .equivalent(Connection::getSerializer) + .conclusion; + } + + @Override + public Boolean caseSerializer(Serializer object) { + return new ComparisonMachine<>(object, Serializer.class) + .equalAsObjects(Serializer::getType) + .conclusion; + } + + @Override + public Boolean caseKeyValuePairs(KeyValuePairs object) { + return new ComparisonMachine<>(object, KeyValuePairs.class) + .listsEquivalent(KeyValuePairs::getPairs) + .conclusion; + } + + @Override + public Boolean caseKeyValuePair(KeyValuePair object) { + return new ComparisonMachine<>(object, KeyValuePair.class) + .equalAsObjects(KeyValuePair::getName) + .equivalent(KeyValuePair::getValue) + .conclusion; + } + + @Override + public Boolean caseArray(Array object) { + return new ComparisonMachine<>(object, Array.class) + .listsEquivalent(Array::getElements) + .conclusion; + } + + @Override + public Boolean caseElement(Element object) { + return new ComparisonMachine<>(object, Element.class) + .equivalent(Element::getKeyvalue) + .equivalent(Element::getArray) + .equalAsObjects(Element::getLiteral) + .equalAsObjects(Element::getId) + .equalAsObjects(Element::getUnit) + .conclusion; + } + + @Override + public Boolean caseTypedVariable(TypedVariable object) { + throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); + } + + @Override + public Boolean caseVariable(Variable object) { + throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class); + } + + @Override + public Boolean caseVarRef(VarRef object) { + return new ComparisonMachine<>(object, VarRef.class) + .equalAsObjects(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable().getName()) + .equivalent(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable()) + .equalAsObjects(varRef -> varRef.getContainer() == null ? null : varRef.getContainer().getName()) + .equalAsObjects(VarRef::isInterleaved) + .equalAsObjects(VarRef::getTransition) + .conclusion; + } + + @Override + public Boolean caseAssignment(Assignment object) { + return new ComparisonMachine<>(object, Assignment.class) + .equivalent(Assignment::getLhs) + .equivalent(Assignment::getRhs) + .conclusion; + } + + @Override + public Boolean caseParameter(Parameter object) { + return new ComparisonMachine<>(object, Parameter.class) + .listsEquivalent(Parameter::getAttributes) + .equalAsObjects(Parameter::getName) + .equivalent(Parameter::getType) + .equivalent(Parameter::getInit) + .conclusion; + } + + @Override + public Boolean caseExpression(Expression object) { + throw thereIsAMoreSpecificCase( + Expression.class, + Literal.class, + Time.class, + ParameterReference.class, + Code.class, + BracedListExpression.class + ); + } + + @Override + public Boolean caseBracedListExpression(BracedListExpression object) { + return new ComparisonMachine<>(object, BracedListExpression.class) + .listsEquivalent(BracedListExpression::getItems) + .conclusion; + } + + @Override + public Boolean caseParameterReference(ParameterReference object) { + return new ComparisonMachine<>(object, ParameterReference.class) + .equivalent(ParameterReference::getParameter) + .conclusion; + } + + @Override + public Boolean caseTime(Time object) { + return new ComparisonMachine<>(object, Time.class) + .equalAsObjects(Time::getInterval) + .equalAsObjectsModulo( + Time::getUnit, + ((Function) TimeUnit::getCanonicalName) + .compose(TimeUnit::fromName) + ) + .conclusion; + } + + @Override + public Boolean casePort(Port object) { + throw thereIsAMoreSpecificCase(Port.class, Input.class, Output.class); + } + + @Override + public Boolean caseType(Type object) { + return new ComparisonMachine<>(object, Type.class) + .equivalent(Type::getCode) + .equalAsObjects(Type::isTime) + .equivalent(Type::getArraySpec) + .equalAsObjects(Type::getId) + .listsEquivalent(Type::getTypeArgs) + .listsEqualAsObjects(Type::getStars) + .equivalent(Type::getArraySpec) + .equivalent(Type::getCode) + .conclusion; + } + + @Override + public Boolean caseArraySpec(ArraySpec object) { + return new ComparisonMachine<>(object, ArraySpec.class) + .equalAsObjects(ArraySpec::isOfVariableLength) + .equalAsObjects(ArraySpec::getLength) + .conclusion; + } + + @Override + public Boolean caseWatchdog(Watchdog object) { + return new ComparisonMachine<>(object, Watchdog.class) + .equalAsObjects(Watchdog::getName) + .equivalent(Watchdog::getTimeout) + .listsEquivalent(Watchdog::getEffects) + .equivalent(Watchdog::getCode) + .conclusion; + } + + @Override + public Boolean caseWidthSpec(WidthSpec object) { + return new ComparisonMachine<>(object, WidthSpec.class) + .equalAsObjects(WidthSpec::isOfVariableLength) + .listsEquivalent(WidthSpec::getTerms) + .conclusion; + } + + @Override + public Boolean caseWidthTerm(WidthTerm object) { + return new ComparisonMachine<>(object, WidthTerm.class) + .equalAsObjects(WidthTerm::getWidth) + .equivalent(WidthTerm::getParameter) + .equivalent(WidthTerm::getPort) + .equivalent(WidthTerm::getCode) + .conclusion; + } + + @Override + public Boolean caseIPV4Host(IPV4Host object) { + return caseHost(object); + } + + @Override + public Boolean caseIPV6Host(IPV6Host object) { + return caseHost(object); + } + + @Override + public Boolean caseNamedHost(NamedHost object) { + return caseHost(object); + } + + @Override + public Boolean caseHost(Host object) { + return new ComparisonMachine<>(object, Host.class) + .equalAsObjects(Host::getUser) + .equalAsObjects(Host::getAddr) + .equalAsObjects(Host::getPort) + .conclusion; + } + + @Override + public Boolean caseCodeExpr(CodeExpr object) { + return new ComparisonMachine<>(object, CodeExpr.class).equivalent(CodeExpr::getCode).conclusion; + } + + @Override + public Boolean caseCode(Code object) { + return new ComparisonMachine<>(object, Code.class) + .equalAsObjectsModulo( + Code::getBody, + s -> s == null ? null : s.strip().stripIndent() + ) + .conclusion; + } + + @Override + public Boolean caseLiteral(Literal object) { + return new ComparisonMachine<>(object, Literal.class) + .equalAsObjects(Literal::getLiteral) + .conclusion; + } + + @Override + public Boolean defaultCase(EObject object) { + return super.defaultCase(object); + } + + @SafeVarargs + private UnsupportedOperationException thereIsAMoreSpecificCase( + Class thisCase, + Class... moreSpecificCases + ) { + return new UnsupportedOperationException(String.format( "%ss are %s, so the methods " + "corresponding to those types should be invoked instead.", thisCase.getName(), Arrays.stream(moreSpecificCases) - .map(Class::getName) - .map(it -> it + (it.endsWith("s") ? "es" : "s")) - .collect(Collectors.joining(" or ")))); - } - - /** Fluently compare a pair of parse tree nodes for equivalence. */ - private class ComparisonMachine { - private final E object; - private final E other; - private boolean conclusion; - - ComparisonMachine(E object, Class clz) { - this.object = object; - this.conclusion = clz.isInstance(otherObject); - this.other = conclusion ? clz.cast(otherObject) : null; - } - - /** Conclude false if the two given Lists are different as EObject sequences. Order matters. */ - ComparisonMachine listsEquivalent(Function> listGetter) { - if (conclusion) - conclusion = listsEqualish(listGetter, (T a, T b) -> new IsEqual(a).doSwitch(b)); - return this; - } - - /** Conclude false if the two given Lists are different as object sequences. Order matters. */ - ComparisonMachine listsEqualAsObjects(Function> listGetter) { - if (conclusion) conclusion = listsEqualish(listGetter, Objects::equals); - return this; - } - - boolean listsEqualish( - Function> listGetter, BiPredicate equalish) { - if (!conclusion) return false; - List list0 = listGetter.apply(object); - List list1 = listGetter.apply(other); - if (list0 == list1) return true; // e.g., they are both null - if (list0.size() != list1.size()) return false; - for (int i = 0; i < list0.size(); i++) { - if (!equalish.test(list0.get(i), list1.get(i))) { - return false; + .map(Class::getName) + .map(it -> it + (it.endsWith("s") ? "es" : "s")) + .collect(Collectors.joining(" or ")) + )); + } + + /** Fluently compare a pair of parse tree nodes for equivalence. */ + private class ComparisonMachine { + private final E object; + private final E other; + private boolean conclusion; + + ComparisonMachine(E object, Class clz) { + this.object = object; + this.conclusion = clz.isInstance(otherObject); + this.other = conclusion ? clz.cast(otherObject) : null; + } + + /** + * Conclude false if the two given Lists are different as EObject + * sequences. Order matters. + */ + ComparisonMachine listsEquivalent(Function> listGetter) { + if (conclusion) conclusion = listsEqualish(listGetter, (T a, T b) -> new IsEqual(a).doSwitch(b)); + return this; + } + + /** + * Conclude false if the two given Lists are different as object + * sequences. Order matters. + */ + ComparisonMachine listsEqualAsObjects(Function> listGetter) { + if (conclusion) conclusion = listsEqualish(listGetter, Objects::equals); + return this; + } + + boolean listsEqualish(Function> listGetter, BiPredicate equalish) { + if (!conclusion) return false; + List list0 = listGetter.apply(object); + List list1 = listGetter.apply(other); + if (list0 == list1) return true; // e.g., they are both null + if (list0.size() != list1.size()) return false; + for (int i = 0; i < list0.size(); i++) { + if (!equalish.test(list0.get(i), list1.get(i))) { + return false; + } + } + return true; + } + + /** Conclude false if the two properties are not equal as objects. */ + ComparisonMachine equalAsObjects(Function propertyGetter) { + return equalAsObjectsModulo(propertyGetter, Function.identity()); + } + + /** + * Conclude false if the two properties are not equal as objects, + * given that {@code projectionToClassRepresentatives} maps each + * object to some semantically equivalent object. + */ + ComparisonMachine equalAsObjectsModulo( + Function propertyGetter, + Function projectionToClassRepresentatives + ) { + if (propertyGetter.apply(object) instanceof EObject) { + throw new IllegalArgumentException( + "EObjects should be compared for semantic equivalence, not object equality." + ); + } + propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); + if (conclusion) conclusion = Objects.equals(propertyGetter.apply(object), propertyGetter.apply(other)); + return this; + } + + /** + * Conclude false if the two properties are not semantically equivalent + * parse nodes. + */ + ComparisonMachine equivalent(Function propertyGetter) { + return equivalentModulo(propertyGetter, Function.identity()); + } + + /** + * Conclude false if the two properties are not semantically equivalent + * parse nodes, given that {@code projectionToClassRepresentatives} + * maps each parse node to some semantically equivalent node. + */ + ComparisonMachine equivalentModulo( + Function propertyGetter, + Function projectionToClassRepresentatives + ) { + propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); + if (conclusion) conclusion = new IsEqual(propertyGetter.apply(object)) + .doSwitch(propertyGetter.apply(other)); + return this; } - } - return true; - } - - /** Conclude false if the two properties are not equal as objects. */ - ComparisonMachine equalAsObjects(Function propertyGetter) { - return equalAsObjectsModulo(propertyGetter, Function.identity()); - } - - /** - * Conclude false if the two properties are not equal as objects, given that {@code - * projectionToClassRepresentatives} maps each object to some semantically equivalent object. - */ - ComparisonMachine equalAsObjectsModulo( - Function propertyGetter, Function projectionToClassRepresentatives) { - if (propertyGetter.apply(object) instanceof EObject) { - throw new IllegalArgumentException( - "EObjects should be compared for semantic equivalence, not object equality."); - } - propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); - if (conclusion) - conclusion = Objects.equals(propertyGetter.apply(object), propertyGetter.apply(other)); - return this; - } - - /** Conclude false if the two properties are not semantically equivalent parse nodes. */ - ComparisonMachine equivalent(Function propertyGetter) { - return equivalentModulo(propertyGetter, Function.identity()); - } - - /** - * Conclude false if the two properties are not semantically equivalent parse nodes, given that - * {@code projectionToClassRepresentatives} maps each parse node to some semantically equivalent - * node. - */ - ComparisonMachine equivalentModulo( - Function propertyGetter, Function projectionToClassRepresentatives) { - propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); - if (conclusion) - conclusion = - new IsEqual(propertyGetter.apply(object)).doSwitch(propertyGetter.apply(other)); - return this; - } - } + } } From b7e902b4918a8ccb489037c7fc8ed3e2798831c2 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 30 Apr 2023 11:17:06 +0200 Subject: [PATCH 213/709] Merge master changes in --- org.lflang/src/org/lflang/TargetConfig.java | 16 +-- org.lflang/src/org/lflang/util/FileUtil.java | 111 ++++++++++++++++++- 2 files changed, 109 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 23e99541da..845f214ec8 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -172,13 +172,6 @@ public TargetConfig( */ public List cmakeIncludes = new ArrayList<>(); - /** - * List of cmake-includes from the cmake-include target property with no path info. - * Useful for copying them to remote machines. This is needed because - * target cmake-includes can be resources with resource paths. - */ - public List cmakeIncludesWithoutPath = new ArrayList<>(); - /** * The compiler to invoke, unless a build command has been specified. */ @@ -237,14 +230,7 @@ public TargetConfig( /** * List of files to be copied to src-gen. */ - public List fileNames = new ArrayList<>(); - - /** - * List of file names from the files target property with no path info. - * Useful for copying them to remote machines. This is needed because - * target files can be resources with resource paths. - */ - public List filesNamesWithoutPath = new ArrayList<>(); + public List files = new ArrayList<>(); /** * If true, configure the execution environment to keep executing if there diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index d4d34c7b08..a2cfb81e4d 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -36,7 +36,9 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.util.RuntimeIOException; +import org.lflang.ErrorReporter; import org.lflang.FileConfig; +import org.lflang.generator.LFGeneratorContext; public class FileUtil { @@ -150,7 +152,7 @@ public static java.net.URI locateFile(String path, Resource resource) { sourceURI = iFile != null ? iFile.getRawLocation().toFile().getParentFile().toURI() : null; } if (sourceURI != null) { - return sourceURI.resolve(path.toString()); + return sourceURI.resolve(path); } } catch (Exception e) { // nothing @@ -239,6 +241,68 @@ public static void copyFile(Path source, Path destination) throws IOException { copyFile(source, destination, false); } + /** + * Given a list of files or directories, attempt to find them based on the given generator + * context, and copy then to the destination. Files are searched for in the file system first. + * Files that cannot be found in the file system are looked for on the class path. + * + * @param filesOrDirectories The files or directories to copy. + * @param destination The location to copy them to. + * @param fileConfig The file configuration that specifies where the files must be found. + * @param errorReporter An error reporter to report problems. + */ + public static void copyFiles( + List filesOrDirectories, + Path destination, + FileConfig fileConfig, + ErrorReporter errorReporter + ) { + for (String fileOrDirectory : filesOrDirectories) { + var path = Paths.get(fileOrDirectory); + var found = FileUtil.findInPackage(path, fileConfig); + if (found != null) { + try { + FileUtil.copyFileOrDirectory(found, destination.resolve(found.getFileName())); + } catch (IOException e) { + errorReporter.reportError( + "Unable to copy '" + fileOrDirectory + "' from the file system." + ); + } + } else { + // Attempt to copy from the classpath instead. + // If the filename is not a directory, it will + // just be copied without further recursion. + try { + FileUtil.copyDirectoryFromClassPath( + fileOrDirectory, + destination, + false + ); + } catch (IOException e) { + errorReporter.reportError( + "Unable to copy '" + fileOrDirectory + "' from the class path." + ); + } + } + } + } + + /** + * If the source is a directory, then copy the contents of the directory to the destination. + * If the source is a file, then copy the file to the destination. + * @param source A file or directory to copy to the destination. + * @param destination A directory to copy the file(s) at the source to. + * @throws IOException + */ + public static void copyFileOrDirectory(Path source, Path destination) throws IOException { + if (Files.isDirectory(source)) { + copyDirectory(source, destination); + } else if (Files.isRegularFile(source)) { + copyFile(source, destination); + } else { + throw new IllegalArgumentException("Source is neither a directory nor a regular file."); + } + } /** * Copy a given input stream to a destination file. * @@ -359,6 +423,7 @@ private static boolean copyDirectoryFromJar(JarURLConnection connection, final P final String connectionEntryName = connection.getEntryName(); boolean copiedFiles = false; + // Iterate all entries in the jar file. for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { final JarEntry entry = e.nextElement(); @@ -366,9 +431,10 @@ private static boolean copyDirectoryFromJar(JarURLConnection connection, final P // Extract files only if they match the given source path. if (entryName.startsWith(connectionEntryName)) { - String filename = entry.getName().substring(connectionEntryName.length() + 1); + String filename = entryName.equals(connectionEntryName) ? + connectionEntryName : + entryName.substring(connectionEntryName.length() + 1); Path currentFile = destination.resolve(filename); - if (entry.isDirectory()) { Files.createDirectories(currentFile); } else { @@ -511,6 +577,45 @@ public static void deleteDirectory(Path dir) throws IOException { } } + /** + * Return an absolute path to the given file or directory if it can be found within the package. + * Otherwise, return null. + * + * NOTE: If the given file or directory is given as an absolute path but cannot be found, it is + * interpreted as a relative path with respect to the project root. + * + * @param fileOrDirectory The file or directory to look for. + * @param fileConfig A file configuration that determines where the package is located. + * @return An absolute path of the file or directory was found; null otherwise. + */ + public static Path findInPackage(Path fileOrDirectory, FileConfig fileConfig) { + if (fileOrDirectory.isAbsolute() && Files.exists(fileOrDirectory)) { + return fileOrDirectory; + } else { + Path relPath; + // Disregard root and interpret as relative path + if (fileOrDirectory.isAbsolute()) { + relPath = Paths.get( + String.valueOf(fileOrDirectory).replaceFirst( + String.valueOf(fileOrDirectory.getRoot()), + "") + ); + } else { + relPath = fileOrDirectory; + } + + // Look relative to the source file and relative to the package root. + var locations = List.of(fileConfig.srcPath, fileConfig.srcPkgPath); + var found = locations.stream().filter( + loc -> Files.exists(loc.resolve(relPath)) + ).findFirst(); + if (found.isPresent()) { + return found.get().resolve(relPath); + } + } + return null; + } + /** * Get the iResource corresponding to the provided resource if it can be * found. From 5159e0a7cc0aa96b7ad64fe595f50b6f6f3bf3ae Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 30 Apr 2023 11:17:15 +0200 Subject: [PATCH 214/709] Undo formatting changes --- .../org/lflang/generator/GeneratorBase.java | 1144 +++++++++-------- 1 file changed, 576 insertions(+), 568 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 9ae46ad357..4cae3f7cf1 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -24,23 +24,23 @@ ***************/ package org.lflang.generator; -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; + import org.eclipse.core.resources.IMarker; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; + import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; @@ -53,12 +53,18 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; + import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; +import org.lflang.util.FileUtil; import org.lflang.validation.AbstractLFValidator; +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; + /** - * Generator base class for specifying core functionality that all code generators should have. + * Generator base class for specifying core functionality + * that all code generators should have. * * @author Edward A. Lee * @author Marten Lohstroh @@ -68,595 +74,597 @@ */ public abstract class GeneratorBase extends AbstractLFValidator { - //////////////////////////////////////////// - //// Public fields. - - /** The main (top-level) reactor instance. */ - public ReactorInstance main; - - /** An error reporter for reporting any errors or warnings during the code generation */ - public ErrorReporter errorReporter; - - //////////////////////////////////////////// - //// Protected fields. - - /** The current target configuration. */ - protected final TargetConfig targetConfig; - - public TargetConfig getTargetConfig() { - return this.targetConfig; - } - - public final LFGeneratorContext context; - - /** A factory for compiler commands. */ - protected GeneratorCommandFactory commandFactory; - - public GeneratorCommandFactory getCommandFactory() { - return commandFactory; - } - - /** - * Definition of the main (top-level) reactor. This is an automatically generated AST node for the - * top-level reactor. - */ - protected Instantiation mainDef; - - public Instantiation getMainDef() { - return mainDef; - } - - /** - * A list of Reactor definitions in the main resource, including non-main reactors defined in - * imported resources. These are ordered in the list in such a way that each reactor is preceded - * by any reactor that it instantiates using a command like `foo = new Foo();` - */ - protected List reactors = new ArrayList<>(); - - /** The set of resources referenced reactor classes reside in. */ - protected Set resources = new LinkedHashSet<>(); // FIXME: Why do we need this? - - /** - * Graph that tracks dependencies between instantiations. This is a graph where each node is a - * Reactor (not a ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an - * instance of A, constructed with a statement like `a = new A();` After creating the graph, sort - * the reactors in topological order and assign them to the reactors class variable. Hence, after - * this method returns, `this.reactors` will be a list of Reactors such that any reactor is - * preceded in the list by reactors that it instantiates. - */ - protected InstantiationGraph instantiationGraph; - - /** - * The set of unordered reactions. An unordered reaction is one that does not have any dependency - * on other reactions in the containing reactor, and where no other reaction in the containing - * reactor depends on it. There is currently no way in the syntax of LF to make a reaction - * unordered, deliberately, because it can introduce unexpected nondeterminacy. However, certain - * automatically generated reactions are known to be safe to be unordered because they do not - * interact with the state of the containing reactor. To make a reaction unordered, when the - * Reaction instance is created, add that instance to this set. - */ - protected Set unorderedReactions = null; - - /** Map from reactions to bank indices */ - protected Map reactionBankIndices = null; - - /** Indicates whether the current Lingua Franca program contains model reactors. */ - public boolean hasModalReactors = false; - - /** - * Indicates whether the program has any deadlines and thus needs to propagate deadlines through - * the reaction instance graph - */ - public boolean hasDeadlines = false; - - /** Indicates whether the program has any watchdogs. This is used to check for support. */ - public boolean hasWatchdogs = false; - - // ////////////////////////////////////////// - // // Private fields. - - /** A list ot AST transformations to apply before code generation */ - private final List astTransformations = new ArrayList<>(); - - /** Create a new GeneratorBase object. */ - public GeneratorBase(LFGeneratorContext context) { - this.context = context; - this.targetConfig = context.getTargetConfig(); - this.errorReporter = context.getErrorReporter(); - this.commandFactory = new GeneratorCommandFactory(errorReporter, context.getFileConfig()); - } - - /** - * Register an AST transformation to be applied to the AST. - * - *

The transformations will be applied in the order that they are registered in. - */ - protected void registerTransformation(AstTransformation transformation) { - astTransformations.add(transformation); - } - - // ////////////////////////////////////////// - // // Code generation functions to override for a concrete code generator. - - /** - * If there is a main or federated reactor, then create a synthetic Instantiation for that - * top-level reactor and set the field mainDef to refer to it. - */ - private void createMainInstantiation() { - // Find the main reactor and create an AST node for its instantiation. - Iterable nodes = - IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); - for (Reactor reactor : Iterables.filter(nodes, Reactor.class)) { - if (reactor.isMain()) { - // Creating a definition for the main reactor because there isn't one. - this.mainDef = LfFactory.eINSTANCE.createInstantiation(); - this.mainDef.setName(reactor.getName()); - this.mainDef.setReactorClass(reactor); - } + //////////////////////////////////////////// + //// Public fields. + + /** + * The main (top-level) reactor instance. + */ + public ReactorInstance main; + + /** An error reporter for reporting any errors or warnings during the code generation */ + public ErrorReporter errorReporter; + + //////////////////////////////////////////// + //// Protected fields. + + /** + * The current target configuration. + */ + protected final TargetConfig targetConfig; + + public TargetConfig getTargetConfig() { return this.targetConfig;} + + public final LFGeneratorContext context; + + /** + * A factory for compiler commands. + */ + protected GeneratorCommandFactory commandFactory; + + public GeneratorCommandFactory getCommandFactory() { return commandFactory; } + + /** + * Definition of the main (top-level) reactor. + * This is an automatically generated AST node for the top-level + * reactor. + */ + protected Instantiation mainDef; + public Instantiation getMainDef() { return mainDef; } + + /** + * A list of Reactor definitions in the main resource, including non-main + * reactors defined in imported resources. These are ordered in the list in + * such a way that each reactor is preceded by any reactor that it instantiates + * using a command like `foo = new Foo();` + */ + protected List reactors = new ArrayList<>(); + + /** + * The set of resources referenced reactor classes reside in. + */ + protected Set resources = new LinkedHashSet<>(); // FIXME: Why do we need this? + + /** + * Graph that tracks dependencies between instantiations. + * This is a graph where each node is a Reactor (not a ReactorInstance) + * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement + * like `a = new A();` After creating the graph, + * sort the reactors in topological order and assign them to the reactors class variable. + * Hence, after this method returns, `this.reactors` will be a list of Reactors such that any + * reactor is preceded in the list by reactors that it instantiates. + */ + protected InstantiationGraph instantiationGraph; + + /** + * The set of unordered reactions. An unordered reaction is one that does + * not have any dependency on other reactions in the containing reactor, + * and where no other reaction in the containing reactor depends on it. + * There is currently no way in the syntax of LF to make a reaction + * unordered, deliberately, because it can introduce unexpected + * nondeterminacy. However, certain automatically generated reactions are + * known to be safe to be unordered because they do not interact with the + * state of the containing reactor. To make a reaction unordered, when + * the Reaction instance is created, add that instance to this set. + */ + protected Set unorderedReactions = null; + + /** + * Map from reactions to bank indices + */ + protected Map reactionBankIndices = null; + + /** + * Indicates whether the current Lingua Franca program + * contains model reactors. + */ + public boolean hasModalReactors = false; + + /** + * Indicates whether the program has any deadlines and thus + * needs to propagate deadlines through the reaction instance graph + */ + public boolean hasDeadlines = false; + + /** Indicates whether the program has any watchdogs. This is used to check for support. */ + public boolean hasWatchdogs = false; + + // ////////////////////////////////////////// + // // Private fields. + + /** + * A list ot AST transformations to apply before code generation + */ + private final List astTransformations = new ArrayList<>(); + + /** + * Create a new GeneratorBase object. + */ + public GeneratorBase(LFGeneratorContext context) { + this.context = context; + this.targetConfig = context.getTargetConfig(); + this.errorReporter = context.getErrorReporter(); + this.commandFactory = new GeneratorCommandFactory(errorReporter, context.getFileConfig()); } - } - - /** - * Generate code from the Lingua Franca model contained by the specified resource. - * - *

This is the main entry point for code generation. This base class finds all reactor class - * definitions, including any reactors defined in imported .lf files (except any main reactors in - * those imported files), and adds them to the {@link GeneratorBase#reactors reactors} list. If - * errors occur during generation, then a subsequent call to errorsOccurred() will return true. - * - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. In standalone mode, this - * object is also used to relay CLI arguments. - */ - public void doGenerate(Resource resource, LFGeneratorContext context) { - - // FIXME: the signature can be reduced to only take context. - // The constructor also need not take a file config because this is tied to the context as well. - cleanIfNeeded(context); - - printInfo(context.getMode()); - - // Clear any IDE markers that may have been created by a previous build. - // Markers mark problems in the Eclipse IDE when running in integrated mode. - errorReporter.clearHistory(); - - ASTUtils.setMainName(context.getFileConfig().resource, context.getFileConfig().name); - - createMainInstantiation(); - - // Check if there are any conflicting main reactors elsewhere in the package. - if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && mainDef != null) { - for (String conflict : new MainConflictChecker(context.getFileConfig()).conflicts) { - errorReporter.reportError( - this.mainDef.getReactorClass(), "Conflicting main reactor in " + conflict); - } + + /** + * Register an AST transformation to be applied to the AST. + * + * The transformations will be applied in the order that they are registered in. + */ + protected void registerTransformation(AstTransformation transformation) { + astTransformations.add(transformation); } - // Configure the command factory - commandFactory.setVerbose(); - if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) - && context.getArgs().containsKey("quiet")) { - commandFactory.setQuiet(); + // ////////////////////////////////////////// + // // Code generation functions to override for a concrete code generator. + + /** + * If there is a main or federated reactor, then create a synthetic Instantiation + * for that top-level reactor and set the field mainDef to refer to it. + */ + private void createMainInstantiation() { + // Find the main reactor and create an AST node for its instantiation. + Iterable nodes = IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); + for (Reactor reactor : Iterables.filter(nodes, Reactor.class)) { + if (reactor.isMain()) { + // Creating a definition for the main reactor because there isn't one. + this.mainDef = LfFactory.eINSTANCE.createInstantiation(); + this.mainDef.setName(reactor.getName()); + this.mainDef.setReactorClass(reactor); + } + } } - // Process target files. Copy each of them into the src-gen dir. - // FIXME: Should we do this here? This doesn't make sense for federates the way it is - // done here. - copyUserFiles(this.targetConfig, context.getFileConfig()); - - // Collect reactors and create an instantiation graph. - // These are needed to figure out which resources we need - // to validate, which happens in setResources(). - setReactorsAndInstantiationGraph(context.getMode()); - - List allResources = GeneratorUtils.getResources(reactors); - resources.addAll( - allResources - .stream() // FIXME: This filter reproduces the behavior of the method it replaces. But - // why must it be so complicated? Why are we worried about weird corner cases - // like this? - .filter( - it -> - !Objects.equal(it, context.getFileConfig().resource) - || mainDef != null && it == mainDef.getReactorClass().eResource()) - .map( - it -> - GeneratorUtils.getLFResource( - it, context.getFileConfig().getSrcGenBasePath(), context, errorReporter)) - .toList()); - GeneratorUtils.accommodatePhysicalActionsIfPresent( - allResources, getTarget().setsKeepAliveOptionAutomatically(), targetConfig, errorReporter); - // FIXME: Should the GeneratorBase pull in `files` from imported - // resources? - - for (AstTransformation transformation : astTransformations) { - transformation.applyTransformation(reactors); + /** + * Generate code from the Lingua Franca model contained by the specified resource. + * + * This is the main entry point for code generation. This base class finds all + * reactor class definitions, including any reactors defined in imported .lf files + * (except any main reactors in those imported files), and adds them to the + * {@link GeneratorBase#reactors reactors} list. If errors occur during + * generation, then a subsequent call to errorsOccurred() will return true. + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. + * In standalone mode, this object is also used to relay CLI arguments. + */ + public void doGenerate(Resource resource, LFGeneratorContext context) { + + // FIXME: the signature can be reduced to only take context. + // The constructor also need not take a file config because this is tied to the context as well. + cleanIfNeeded(context); + + printInfo(context.getMode()); + + // Clear any IDE markers that may have been created by a previous build. + // Markers mark problems in the Eclipse IDE when running in integrated mode. + errorReporter.clearHistory(); + + ASTUtils.setMainName(context.getFileConfig().resource, context.getFileConfig().name); + + createMainInstantiation(); + + // Check if there are any conflicting main reactors elsewhere in the package. + if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && mainDef != null) { + for (String conflict : new MainConflictChecker(context.getFileConfig()).conflicts) { + errorReporter.reportError(this.mainDef.getReactorClass(), "Conflicting main reactor in " + conflict); + } + } + + // Configure the command factory + commandFactory.setVerbose(); + if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && context.getArgs().containsKey("quiet")) { + commandFactory.setQuiet(); + } + + // Process target files. Copy each of them into the src-gen dir. + // FIXME: Should we do this here? This doesn't make sense for federates the way it is + // done here. + copyUserFiles(this.targetConfig, context.getFileConfig()); + + // Collect reactors and create an instantiation graph. + // These are needed to figure out which resources we need + // to validate, which happens in setResources(). + setReactorsAndInstantiationGraph(context.getMode()); + + List allResources = GeneratorUtils.getResources(reactors); + resources.addAll(allResources.stream() // FIXME: This filter reproduces the behavior of the method it replaces. But why must it be so complicated? Why are we worried about weird corner cases like this? + .filter(it -> !Objects.equal(it, context.getFileConfig().resource) || mainDef != null && it == mainDef.getReactorClass().eResource()) + .map(it -> GeneratorUtils.getLFResource(it, context.getFileConfig().getSrcGenBasePath(), context, errorReporter)) + .toList() + ); + GeneratorUtils.accommodatePhysicalActionsIfPresent( + allResources, + getTarget().setsKeepAliveOptionAutomatically(), + targetConfig, + errorReporter + ); + // FIXME: Should the GeneratorBase pull in `files` from imported + // resources? + + for (AstTransformation transformation : astTransformations) { + transformation.applyTransformation(reactors); + } + + // Transform connections that reside in mutually exclusive modes and are otherwise conflicting + // This should be done before creating the instantiation graph + transformConflictingConnectionsInModalReactors(); + + // Invoke these functions a second time because transformations + // may have introduced new reactors! + setReactorsAndInstantiationGraph(context.getMode()); + + // Check for existence and support of modes + hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); + checkModalReactorSupport(false); + + // Check for the existence and support of watchdogs + hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); + checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); + additionalPostProcessingForModes(); } - // Transform connections that reside in mutually exclusive modes and are otherwise conflicting - // This should be done before creating the instantiation graph - transformConflictingConnectionsInModalReactors(); - - // Invoke these functions a second time because transformations - // may have introduced new reactors! - setReactorsAndInstantiationGraph(context.getMode()); - - // Check for existence and support of modes - hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); - checkModalReactorSupport(false); - - // Check for the existence and support of watchdogs - hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); - checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); - additionalPostProcessingForModes(); - } - - /** Check if a clean was requested from the standalone compiler and perform the clean step. */ - protected void cleanIfNeeded(LFGeneratorContext context) { - if (context.getArgs().containsKey("clean")) { - try { - context.getFileConfig().doClean(); - } catch (IOException e) { - System.err.println("WARNING: IO Error during clean"); - } + /** + * Check if a clean was requested from the standalone compiler and perform + * the clean step. + */ + protected void cleanIfNeeded(LFGeneratorContext context) { + if (context.getArgs().containsKey("clean")) { + try { + context.getFileConfig().doClean(); + } catch (IOException e) { + System.err.println("WARNING: IO Error during clean"); + } + } } - } - - /** - * Create a new instantiation graph. This is a graph where each node is a Reactor (not a - * ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an instance of A, - * constructed with a statement like `a = new A();` After creating the graph, sort the reactors in - * topological order and assign them to the reactors class variable. Hence, after this method - * returns, `this.reactors` will be a list of Reactors such that any reactor is preceded in the - * list by reactors that it instantiates. - */ - protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { - // Build the instantiation graph . - instantiationGraph = new InstantiationGraph(context.getFileConfig().resource, false); - - // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur - // earlier in - // the sorted list of reactors. This helps the code generator output code in the correct order. - // For example if `reactor Foo {bar = new Bar()}` then the definition of `Bar` has to be - // generated before - // the definition of `Foo`. - reactors = instantiationGraph.nodesInTopologicalOrder(); - - // If there is no main reactor or if all reactors in the file need to be validated, then make - // sure the reactors - // list includes even reactors that are not instantiated anywhere. - if (mainDef == null || Objects.equal(mode, LFGeneratorContext.Mode.LSP_MEDIUM)) { - Iterable nodes = - IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); - for (Reactor r : IterableExtensions.filter(nodes, Reactor.class)) { - if (!reactors.contains(r)) { - reactors.add(r); + + /** + * Create a new instantiation graph. This is a graph where each node is a Reactor (not a ReactorInstance) + * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement + * like `a = new A();` After creating the graph, + * sort the reactors in topological order and assign them to the reactors class variable. + * Hence, after this method returns, `this.reactors` will be a list of Reactors such that any + * reactor is preceded in the list by reactors that it instantiates. + */ + protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { + // Build the instantiation graph . + instantiationGraph = new InstantiationGraph(context.getFileConfig().resource, false); + + // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur earlier in + // the sorted list of reactors. This helps the code generator output code in the correct order. + // For example if `reactor Foo {bar = new Bar()}` then the definition of `Bar` has to be generated before + // the definition of `Foo`. + reactors = instantiationGraph.nodesInTopologicalOrder(); + + // If there is no main reactor or if all reactors in the file need to be validated, then make sure the reactors + // list includes even reactors that are not instantiated anywhere. + if (mainDef == null || Objects.equal(mode, LFGeneratorContext.Mode.LSP_MEDIUM)) { + Iterable nodes = IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); + for (Reactor r : IterableExtensions.filter(nodes, Reactor.class)) { + if (!reactors.contains(r)) { + reactors.add(r); + } + } } - } } - } - - /** - * Copy user specific files to the src-gen folder. - * - *

This should be overridden by the target generators. - * - * @param targetConfig The targetConfig to read the `files` from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {} - - /** - * Return true if errors occurred in the last call to doGenerate(). This will return true if any - * of the reportError methods was called. - * - * @return True if errors occurred. - */ - public boolean errorsOccurred() { - return errorReporter.getErrorsOccurred(); - } - - /* - * Return the TargetTypes instance associated with this. - */ - public abstract TargetTypes getTargetTypes(); - - /** - * Mark the reaction unordered. An unordered reaction is one that does not have any dependency on - * other reactions in the containing reactor, and where no other reaction in the containing - * reactor depends on it. There is currently no way in the syntax of LF to make a reaction - * unordered, deliberately, because it can introduce unexpected nondeterminacy. However, certain - * automatically generated reactions are known to be safe to be unordered because they do not - * interact with the state of the containing reactor. To make a reaction unordered, when the - * Reaction instance is created, add that instance to this set. - * - * @param reaction The reaction to make unordered. - */ - public void makeUnordered(Reaction reaction) { - if (unorderedReactions == null) { - unorderedReactions = new LinkedHashSet<>(); + + /** + * Copy user specific files to the src-gen folder. + * + * This should be overridden by the target generators. + * + * @param targetConfig The targetConfig to read the `files` from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + FileUtil.copyFiles(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); + } + + /** + * Return true if errors occurred in the last call to doGenerate(). + * This will return true if any of the reportError methods was called. + * @return True if errors occurred. + */ + public boolean errorsOccurred() { + return errorReporter.getErrorsOccurred(); } - unorderedReactions.add(reaction); - } - - /** - * Mark the specified reaction to belong to only the specified bank index. This is needed because - * reactions cannot declare a specific bank index as an effect or trigger. Reactions that send - * messages between federates, including absent messages, need to be specific to a bank member. - * - * @param reaction The reaction. - * @param bankIndex The bank index, or -1 if there is no bank. - */ - public void setReactionBankIndex(Reaction reaction, int bankIndex) { - if (bankIndex < 0) { - return; + + /* + * Return the TargetTypes instance associated with this. + */ + public abstract TargetTypes getTargetTypes(); + + /** + * Mark the reaction unordered. An unordered reaction is one that does not + * have any dependency on other reactions in the containing reactor, and + * where no other reaction in the containing reactor depends on it. There + * is currently no way in the syntax of LF to make a reaction unordered, + * deliberately, because it can introduce unexpected nondeterminacy. + * However, certain automatically generated reactions are known to be safe + * to be unordered because they do not interact with the state of the + * containing reactor. To make a reaction unordered, when the Reaction + * instance is created, add that instance to this set. + * @param reaction The reaction to make unordered. + */ + public void makeUnordered(Reaction reaction) { + if (unorderedReactions == null) { + unorderedReactions = new LinkedHashSet<>(); + } + unorderedReactions.add(reaction); } - if (reactionBankIndices == null) { - reactionBankIndices = new LinkedHashMap<>(); + + /** + * Mark the specified reaction to belong to only the specified + * bank index. This is needed because reactions cannot declare + * a specific bank index as an effect or trigger. Reactions that + * send messages between federates, including absent messages, + * need to be specific to a bank member. + * @param reaction The reaction. + * @param bankIndex The bank index, or -1 if there is no bank. + */ + public void setReactionBankIndex(Reaction reaction, int bankIndex) { + if (bankIndex < 0) { + return; + } + if (reactionBankIndices == null) { + reactionBankIndices = new LinkedHashMap<>(); + } + reactionBankIndices.put(reaction, bankIndex); } - reactionBankIndices.put(reaction, bankIndex); - } - - /** - * Return the reaction bank index. - * - * @see #setReactionBankIndex(Reaction reaction, int bankIndex) - * @param reaction The reaction. - * @return The reaction bank index, if one has been set, and -1 otherwise. - */ - public int getReactionBankIndex(Reaction reaction) { - if (reactionBankIndices == null) return -1; - if (reactionBankIndices.get(reaction) == null) return -1; - return reactionBankIndices.get(reaction); - } - - // ////////////////////////////////////////// - // // Protected methods. - - /** - * Checks whether modal reactors are present and require appropriate code generation. This will - * set the hasModalReactors variable. - * - * @param isSupported indicates if modes are supported by this code generation. - */ - protected void checkModalReactorSupport(boolean isSupported) { - if (hasModalReactors && !isSupported) { - errorReporter.reportError( - "The currently selected code generation or " - + "target configuration does not support modal reactors!"); + + /** + * Return the reaction bank index. + * @see #setReactionBankIndex(Reaction reaction, int bankIndex) + * @param reaction The reaction. + * @return The reaction bank index, if one has been set, and -1 otherwise. + */ + public int getReactionBankIndex(Reaction reaction) { + if (reactionBankIndices == null) return -1; + if (reactionBankIndices.get(reaction) == null) return -1; + return reactionBankIndices.get(reaction); } - } - - /** - * Checks whether watchdogs are present and are supported. - * - * @param isSupported indicates whether or not this is a supported target and whether or not it is - * a threaded runtime. - */ - protected void checkWatchdogSupport(boolean isSupported) { - if (hasWatchdogs && !isSupported) { - errorReporter.reportError( - "Watchdogs are currently only supported for threaded programs in the C target."); + + // ////////////////////////////////////////// + // // Protected methods. + + /** + * Checks whether modal reactors are present and require appropriate code generation. + * This will set the hasModalReactors variable. + * @param isSupported indicates if modes are supported by this code generation. + */ + protected void checkModalReactorSupport(boolean isSupported) { + if (hasModalReactors && !isSupported) { + errorReporter.reportError("The currently selected code generation or " + + "target configuration does not support modal reactors!"); + } } - } - - /** - * Finds and transforms connections into forwarding reactions iff the connections have the same - * destination as other connections or reaction in mutually exclusive modes. - */ - private void transformConflictingConnectionsInModalReactors() { - for (LFResource r : resources) { - var transform = ASTUtils.findConflictingConnectionsInModalReactors(r.eResource); - if (!transform.isEmpty()) { - var factory = LfFactory.eINSTANCE; - for (Connection connection : transform) { - // Currently only simple transformations are supported - if (connection.isPhysical() - || connection.getDelay() != null - || connection.isIterated() - || connection.getLeftPorts().size() > 1 - || connection.getRightPorts().size() > 1) { + + /** + * Check whether watchdogs are present and are supported. + * + * @param isSupported indicates whether or not this is a supported target and whether or not it + * is + * a threaded runtime. + */ + protected void checkWatchdogSupport(boolean isSupported) { + if (hasWatchdogs && !isSupported) { errorReporter.reportError( - connection, - "Cannot transform connection in modal reactor. Connection uses currently not" - + " supported features."); - } else { - var reaction = factory.createReaction(); - ((Mode) connection.eContainer()).getReactions().add(reaction); - - var sourceRef = connection.getLeftPorts().get(0); - var destRef = connection.getRightPorts().get(0); - reaction.getTriggers().add(sourceRef); - reaction.getEffects().add(destRef); - - var code = factory.createCode(); - var source = - (sourceRef.getContainer() != null ? sourceRef.getContainer().getName() + "." : "") - + sourceRef.getVariable().getName(); - var dest = - (destRef.getContainer() != null ? destRef.getContainer().getName() + "." : "") - + destRef.getVariable().getName(); - code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest)); - reaction.setCode(code); - - EcoreUtil.remove(connection); - } + "Watchdogs are currently only supported for threaded programs in the C target."); } - } - } - } - /** - * Return target code for forwarding reactions iff the connections have the same destination as - * other connections or reaction in mutually exclusive modes. - * - *

This method needs to be overridden in target specific code generators that support modal - * reactors. - */ - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - errorReporter.reportError( - "The currently selected code generation " - + "is missing an implementation for conflicting " - + "transforming connections in modal reactors."); - return "MODAL MODELS NOT SUPPORTED"; - } - - /** Hook for additional post-processing of the model. */ - protected void additionalPostProcessingForModes() { - // Do nothing - } - - /** Parsed error message from a compiler is returned here. */ - public static class ErrorFileAndLine { - public String filepath = null; - public String line = "1"; - public String character = "0"; - public String message = ""; - public boolean isError = true; // false for a warning. - - @Override - public String toString() { - return (isError ? "Error" : "Non-error") - + " at " - + line - + ":" - + character - + " of file " - + filepath - + ": " - + message; } - } - - /** - * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if - * the line is recognized as the first line of an error message. Otherwise, return null. This base - * class simply returns null. - * - * @param line A line of output from a compiler or other external tool that might generate errors. - * @return If the line is recognized as the start of an error message, then return a class - * containing the path to the file on which the error occurred (or null if there is none), the - * line number (or the string "1" if there is none), the character position (or the string "0" - * if there is none), and the message (or an empty string if there is none). - */ - protected ErrorFileAndLine parseCommandOutput(String line) { - return null; - } - - /** - * Parse the specified string for command errors that can be reported using marks in the Eclipse - * IDE. In this class, we attempt to parse the messages to look for file and line information, - * thereby generating marks on the appropriate lines. This should not be called in standalone - * mode. - * - * @param stderr The output on standard error of executing a command. - */ - public void reportCommandErrors(String stderr) { - // NOTE: If the VS Code branch passes code review, then this function, - // parseCommandOutput, and ErrorFileAndLine will be deleted soon after. - // First, split the message into lines. - String[] lines = stderr.split("\\r?\\n"); - StringBuilder message = new StringBuilder(); - Integer lineNumber = null; - Path path = context.getFileConfig().srcFile; - // In case errors occur within an imported file, record the original path. - Path originalPath = path; - - int severity = IMarker.SEVERITY_ERROR; - for (String line : lines) { - ErrorFileAndLine parsed = parseCommandOutput(line); - if (parsed != null) { - // Found a new line number designator. - // If there is a previously accumulated message, report it. - if (message.length() > 0) { - if (severity == IMarker.SEVERITY_ERROR) - errorReporter.reportError(path, lineNumber, message.toString()); - else errorReporter.reportWarning(path, lineNumber, message.toString()); - - if (!Objects.equal(originalPath.toFile(), path.toFile())) { - // Report an error also in the top-level resource. - // FIXME: It should be possible to descend through the import - // statements to find which one matches and mark all the - // import statements down the chain. But what a pain! - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); - } else { - errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); + + /** + * Finds and transforms connections into forwarding reactions iff the connections have the same + * destination as other connections or reaction in mutually exclusive modes. + */ + private void transformConflictingConnectionsInModalReactors() { + for (LFResource r : resources) { + var transform = ASTUtils.findConflictingConnectionsInModalReactors(r.eResource); + if (!transform.isEmpty()) { + var factory = LfFactory.eINSTANCE; + for (Connection connection : transform) { + // Currently only simple transformations are supported + if (connection.isPhysical() || connection.getDelay() != null || connection.isIterated() || + connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1 + ) { + errorReporter.reportError(connection, "Cannot transform connection in modal reactor. Connection uses currently not supported features."); + } else { + var reaction = factory.createReaction(); + ((Mode)connection.eContainer()).getReactions().add(reaction); + + var sourceRef = connection.getLeftPorts().get(0); + var destRef = connection.getRightPorts().get(0); + reaction.getTriggers().add(sourceRef); + reaction.getEffects().add(destRef); + + var code = factory.createCode(); + var source = (sourceRef.getContainer() != null ? + sourceRef.getContainer().getName() + "." : "") + sourceRef.getVariable().getName(); + var dest = (destRef.getContainer() != null ? + destRef.getContainer().getName() + "." : "") + destRef.getVariable().getName(); + code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest)); + reaction.setCode(code); + + EcoreUtil.remove(connection); + } + } } - } } - if (parsed.isError) { - severity = IMarker.SEVERITY_ERROR; - } else { - severity = IMarker.SEVERITY_WARNING; + } + + /** + * Return target code for forwarding reactions iff the connections have the + * same destination as other connections or reaction in mutually exclusive modes. + * + * This method needs to be overridden in target specific code generators that + * support modal reactors. + */ + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + errorReporter.reportError("The currently selected code generation " + + "is missing an implementation for conflicting " + + "transforming connections in modal reactors."); + return "MODAL MODELS NOT SUPPORTED"; + } + + /** + * Hook for additional post-processing of the model. + */ + protected void additionalPostProcessingForModes() { + // Do nothing + } + + /** + * Parsed error message from a compiler is returned here. + */ + public static class ErrorFileAndLine { + public String filepath = null; + public String line = "1"; + public String character = "0"; + public String message = ""; + public boolean isError = true; // false for a warning. + + @Override + public String toString() { + return (isError ? "Error" : "Non-error") + " at " + line + ":" + character + " of file " + filepath + ": " + message; } + } + + /** + * Given a line of text from the output of a compiler, return + * an instance of ErrorFileAndLine if the line is recognized as + * the first line of an error message. Otherwise, return null. + * This base class simply returns null. + * @param line A line of output from a compiler or other external + * tool that might generate errors. + * @return If the line is recognized as the start of an error message, + * then return a class containing the path to the file on which the + * error occurred (or null if there is none), the line number (or the + * string "1" if there is none), the character position (or the string + * "0" if there is none), and the message (or an empty string if there + * is none). + */ + protected ErrorFileAndLine parseCommandOutput(String line) { + return null; + } - // Start accumulating a new message. - message = new StringBuilder(); - // Append the message on the line number designator line. - message.append(parsed.message); - - // Set the new line number. - try { - lineNumber = Integer.decode(parsed.line); - } catch (Exception ex) { - // Set the line number unknown. - lineNumber = null; + /** + * Parse the specified string for command errors that can be reported + * using marks in the Eclipse IDE. In this class, we attempt to parse + * the messages to look for file and line information, thereby generating + * marks on the appropriate lines. This should not be called in standalone + * mode. + * + * @param stderr The output on standard error of executing a command. + */ + public void reportCommandErrors(String stderr) { + // NOTE: If the VS Code branch passes code review, then this function, + // parseCommandOutput, and ErrorFileAndLine will be deleted soon after. + // First, split the message into lines. + String[] lines = stderr.split("\\r?\\n"); + StringBuilder message = new StringBuilder(); + Integer lineNumber = null; + Path path = context.getFileConfig().srcFile; + // In case errors occur within an imported file, record the original path. + Path originalPath = path; + + int severity = IMarker.SEVERITY_ERROR; + for (String line : lines) { + ErrorFileAndLine parsed = parseCommandOutput(line); + if (parsed != null) { + // Found a new line number designator. + // If there is a previously accumulated message, report it. + if (message.length() > 0) { + if (severity == IMarker.SEVERITY_ERROR) + errorReporter.reportError(path, lineNumber, message.toString()); + else + errorReporter.reportWarning(path, lineNumber, message.toString()); + + if (!Objects.equal(originalPath.toFile(), path.toFile())) { + // Report an error also in the top-level resource. + // FIXME: It should be possible to descend through the import + // statements to find which one matches and mark all the + // import statements down the chain. But what a pain! + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); + } else { + errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); + } + } + } + if (parsed.isError) { + severity = IMarker.SEVERITY_ERROR; + } else { + severity = IMarker.SEVERITY_WARNING; + } + + // Start accumulating a new message. + message = new StringBuilder(); + // Append the message on the line number designator line. + message.append(parsed.message); + + // Set the new line number. + try { + lineNumber = Integer.decode(parsed.line); + } catch (Exception ex) { + // Set the line number unknown. + lineNumber = null; + } + // FIXME: Ignoring the position within the line. + // Determine the path within which the error occurred. + path = Paths.get(parsed.filepath); + } else { + // No line designator. + if (message.length() > 0) { + message.append("\n"); + } else { + if (!line.toLowerCase().contains("error:")) { + severity = IMarker.SEVERITY_WARNING; + } + } + message.append(line); + } } - // FIXME: Ignoring the position within the line. - // Determine the path within which the error occurred. - path = Paths.get(parsed.filepath); - } else { - // No line designator. if (message.length() > 0) { - message.append("\n"); - } else { - if (!line.toLowerCase().contains("error:")) { - severity = IMarker.SEVERITY_WARNING; - } + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(path, lineNumber, message.toString()); + } else { + errorReporter.reportWarning(path, lineNumber, message.toString()); + } + + if (originalPath.toFile() != path.toFile()) { + // Report an error also in the top-level resource. + // FIXME: It should be possible to descend through the import + // statements to find which one matches and mark all the + // import statements down the chain. But what a pain! + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); + } else { + errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); + } + } } - message.append(line); - } } - if (message.length() > 0) { - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(path, lineNumber, message.toString()); - } else { - errorReporter.reportWarning(path, lineNumber, message.toString()); - } - - if (originalPath.toFile() != path.toFile()) { - // Report an error also in the top-level resource. - // FIXME: It should be possible to descend through the import - // statements to find which one matches and mark all the - // import statements down the chain. But what a pain! - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); - } else { - errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); - } - } + + // ////////////////////////////////////////////////// + // // Private functions + + /** + * Print to stdout information about what source file is being generated, + * what mode the generator is in, and where the generated sources are to be put. + */ + public void printInfo(LFGeneratorContext.Mode mode) { + System.out.println("Generating code for: " + context.getFileConfig().resource.getURI().toString()); + System.out.println("******** mode: " + mode); + System.out.println("******** generated sources: " + context.getFileConfig().getSrcGenPath()); } - } - - // ////////////////////////////////////////////////// - // // Private functions - - /** - * Print to stdout information about what source file is being generated, what mode the generator - * is in, and where the generated sources are to be put. - */ - public void printInfo(LFGeneratorContext.Mode mode) { - System.out.println( - "Generating code for: " + context.getFileConfig().resource.getURI().toString()); - System.out.println("******** mode: " + mode); - System.out.println("******** generated sources: " + context.getFileConfig().getSrcGenPath()); - } - - /** Get the buffer type used for network messages */ - public String getNetworkBufferType() { - return ""; - } - - /** Return the Targets enum for the current target */ - public abstract Target getTarget(); + + /** + * Get the buffer type used for network messages + */ + public String getNetworkBufferType() { return ""; } + + /** + * Return the Targets enum for the current target + */ + public abstract Target getTarget(); } From 6463813cf99c97f0e534bec59e8321aa1c6e6f65 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 07:33:50 +0200 Subject: [PATCH 215/709] Undid formatting --- .../org/lflang/generator/c/CGenerator.java | 3764 ++++++++--------- 1 file changed, 1876 insertions(+), 1888 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 3a3352aa03..7bc579ac0f 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1,22 +1,26 @@ /************* - * Copyright (c) 2019-2021, The University of California at Berkeley. - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ***************/ +Copyright (c) 2019-2021, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ package org.lflang.generator.c; @@ -31,11 +35,8 @@ import static org.lflang.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; import java.io.File; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.HashSet; import java.util.LinkedHashSet; @@ -43,26 +44,33 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; + import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; + import org.lflang.ASTUtils; +import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; -import org.lflang.ast.DelayedConnectionTransformation; + import org.lflang.federated.extensions.CExtensionUtils; + +import org.lflang.ast.DelayedConnectionTransformation; + import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.DelayBodyGenerator; -import org.lflang.generator.DockerComposeGenerator; import org.lflang.generator.DockerGenerator; import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorUtils; + +import org.lflang.generator.DelayBodyGenerator; + import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFResource; import org.lflang.generator.ParameterInstance; @@ -88,168 +96,201 @@ import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; +import com.google.common.collect.Iterables; + /** - * Generator for C target. This class generates C code defining each reactor class given in the - * input .lf file and imported .lf files. The generated code has the following components: + * Generator for C target. This class generates C code defining each reactor + * class given in the input .lf file and imported .lf files. The generated code + * has the following components: * - *

* A typedef for inputs, outputs, and actions of each reactor class. These define the types of - * the variables that reactions use to access inputs and action values and to set output values. + * * A typedef for inputs, outputs, and actions of each reactor class. These + * define the types of the variables that reactions use to access inputs and + * action values and to set output values. * - *

* A typedef for a "self" struct for each reactor class. One instance of this struct will be - * created for each reactor instance. See below for details. + * * A typedef for a "self" struct for each reactor class. One instance of this + * struct will be created for each reactor instance. See below for details. * - *

* A function definition for each reaction in each reactor class. These functions take an - * instance of the self struct as an argument. + * * A function definition for each reaction in each reactor class. These + * functions take an instance of the self struct as an argument. * - *

* A constructor function for each reactor class. This is used to create a new instance of the - * reactor. + * * A constructor function for each reactor class. This is used to create + * a new instance of the reactor. * - *

After these, the main generated function is `_lf_initialize_trigger_objects()`. This function - * creates the instances of reactors (using their constructors) and makes connections between them. + * After these, the main generated function is `_lf_initialize_trigger_objects()`. + * This function creates the instances of reactors (using their constructors) + * and makes connections between them. * - *

A few other smaller functions are also generated. + * A few other smaller functions are also generated. * - *

## Self Struct + * ## Self Struct * - *

The "self" struct has fields for each of the following: + * The "self" struct has fields for each of the following: * - *

* parameter: the field name and type match the parameter. * state: the field name and type - * match the state. * action: the field name prepends the action name with "_lf_". A second field - * for the action is also created to house the trigger_t object. That second field prepends the - * action name with "_lf__". * output: the field name prepends the output name with "_lf_". * input: - * the field name prepends the output name with "_lf_". A second field for the input is also created - * to house the trigger_t object. That second field prepends the input name with "_lf__". + * * parameter: the field name and type match the parameter. + * * state: the field name and type match the state. + * * action: the field name prepends the action name with "_lf_". + * A second field for the action is also created to house the trigger_t object. + * That second field prepends the action name with "_lf__". + * * output: the field name prepends the output name with "_lf_". + * * input: the field name prepends the output name with "_lf_". + * A second field for the input is also created to house the trigger_t object. + * That second field prepends the input name with "_lf__". * - *

If, in addition, the reactor contains other reactors and reacts to their outputs, then there - * will be a struct within the self struct for each such contained reactor. The name of that self - * struct will be the name of the contained reactor prepended with "_lf_". That inside struct will - * contain pointers the outputs of the contained reactors that are read together with pointers to - * booleans indicating whether those outputs are present. + * If, in addition, the reactor contains other reactors and reacts to their outputs, + * then there will be a struct within the self struct for each such contained reactor. + * The name of that self struct will be the name of the contained reactor prepended with "_lf_". + * That inside struct will contain pointers the outputs of the contained reactors + * that are read together with pointers to booleans indicating whether those outputs are present. * - *

If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to - * trigger_t object (see reactor.h) for the shutdown event and an action struct named _lf_shutdown - * on the self struct. + * If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to + * trigger_t object (see reactor.h) for the shutdown event and an action struct named + * _lf_shutdown on the self struct. * - *

## Reaction Functions + * ## Reaction Functions * - *

For each reaction in a reactor class, this generator will produce a C function that expects a - * pointer to an instance of the "self" struct as an argument. This function will contain verbatim - * the C code specified in the reaction, but before that C code, the generator inserts a few lines - * of code that extract from the self struct the variables that that code has declared it will use. - * For example, if the reaction declares that it is triggered by or uses an input named "x" of type - * int, the function will contain a line like this: ``` r_x_t* x = self->_lf_x; ``` where `r` is the - * full name of the reactor class and the struct type `r_x_t` has fields `is_present` and `value`, - * where the type of `value` matches the port type. If the programmer fails to declare that it uses - * x, then the absence of the above code will trigger a compile error when the verbatim code - * attempts to read `x`. + * For each reaction in a reactor class, this generator will produce a C function + * that expects a pointer to an instance of the "self" struct as an argument. + * This function will contain verbatim the C code specified in the reaction, but + * before that C code, the generator inserts a few lines of code that extract from the + * self struct the variables that that code has declared it will use. For example, if + * the reaction declares that it is triggered by or uses an input named "x" of type + * int, the function will contain a line like this: + * ``` + * r_x_t* x = self->_lf_x; + * ``` + * where `r` is the full name of the reactor class and the struct type `r_x_t` + * has fields `is_present` and `value`, where the type of `value` matches the port type. + * If the programmer fails to declare that it uses x, then the absence of the + * above code will trigger a compile error when the verbatim code attempts to read `x`. * - *

## Constructor + * ## Constructor * - *

For each reactor class, this generator will create a constructor function named `new_r`, where - * `r` is the reactor class name. This function will malloc and return a pointer to an instance of - * the "self" struct. This struct initially represents an unconnected reactor. To establish - * connections between reactors, additional information needs to be inserted (see below). The self - * struct is made visible to the body of a reaction as a variable named "self". The self struct - * contains the following: + * For each reactor class, this generator will create a constructor function named + * `new_r`, where `r` is the reactor class name. This function will malloc and return + * a pointer to an instance of the "self" struct. This struct initially represents + * an unconnected reactor. To establish connections between reactors, additional + * information needs to be inserted (see below). The self struct is made visible + * to the body of a reaction as a variable named "self". The self struct contains the + * following: * - *

* Parameters: For each parameter `p` of the reactor, there will be a field `p` with the type - * and value of the parameter. So C code in the body of a reaction can access parameter values as - * `self->p`. + * * Parameters: For each parameter `p` of the reactor, there will be a field `p` + * with the type and value of the parameter. So C code in the body of a reaction + * can access parameter values as `self->p`. * - *

* State variables: For each state variable `s` of the reactor, there will be a field `s` with - * the type and value of the state variable. So C code in the body of a reaction can access state - * variables as `self->s`. + * * State variables: For each state variable `s` of the reactor, there will be a field `s` + * with the type and value of the state variable. So C code in the body of a reaction + * can access state variables as `self->s`. * - *

The self struct also contains various fields that the user is not intended to use. The names - * of these fields begin with at least two underscores. They are: + * The self struct also contains various fields that the user is not intended to + * use. The names of these fields begin with at least two underscores. They are: * - *

* Outputs: For each output named `out`, there will be a field `_lf_out` that is a struct - * containing a value field whose type matches that of the output. The output value is stored here. - * That struct also has a field `is_present` that is a boolean indicating whether the output has - * been set. This field is reset to false at the start of every time step. There is also a field - * `num_destinations` whose value matches the number of downstream reactors that use this variable. - * This field must be set when connections are made or changed. It is used to determine for a - * mutable input destination whether a copy needs to be made. + * * Outputs: For each output named `out`, there will be a field `_lf_out` that is + * a struct containing a value field whose type matches that of the output. + * The output value is stored here. That struct also has a field `is_present` + * that is a boolean indicating whether the output has been set. + * This field is reset to false at the start of every time + * step. There is also a field `num_destinations` whose value matches the + * number of downstream reactors that use this variable. This field must be + * set when connections are made or changed. It is used to determine for + * a mutable input destination whether a copy needs to be made. * - *

* Inputs: For each input named `in` of type T, there is a field named `_lf_in` that is a - * pointer struct with a value field of type T. The struct pointed to also has an `is_present` field - * of type bool that indicates whether the input is present. + * * Inputs: For each input named `in` of type T, there is a field named `_lf_in` + * that is a pointer struct with a value field of type T. The struct pointed + * to also has an `is_present` field of type bool that indicates whether the + * input is present. * - *

* Outputs of contained reactors: If a reactor reacts to outputs of a contained reactor `r`, - * then the self struct will contain a nested struct named `_lf_r` that has fields pointing to those - * outputs. For example, if `r` has an output `out` of type T, then there will be field in `_lf_r` - * named `out` that points to a struct containing a value field of type T and a field named - * `is_present` of type bool. + * * Outputs of contained reactors: If a reactor reacts to outputs of a + * contained reactor `r`, then the self struct will contain a nested struct + * named `_lf_r` that has fields pointing to those outputs. For example, + * if `r` has an output `out` of type T, then there will be field in `_lf_r` + * named `out` that points to a struct containing a value field + * of type T and a field named `is_present` of type bool. * - *

* Inputs of contained reactors: If a reactor sends to inputs of a contained reactor `r`, then - * the self struct will contain a nested struct named `_lf_r` that has fields for storing the values - * provided to those inputs. For example, if R has an input `in` of type T, then there will be field - * in _lf_R named `in` that is a struct with a value field of type T and a field named `is_present` - * of type bool. + * * Inputs of contained reactors: If a reactor sends to inputs of a + * contained reactor `r`, then the self struct will contain a nested struct + * named `_lf_r` that has fields for storing the values provided to those + * inputs. For example, if R has an input `in` of type T, then there will + * be field in _lf_R named `in` that is a struct with a value field + * of type T and a field named `is_present` of type bool. * - *

* Actions: If the reactor has an action a (logical or physical), then there will be a field in - * the self struct named `_lf_a` and another named `_lf__a`. The type of the first is specific to - * the action and contains a `value` field with the type and value of the action (if it has a - * value). That struct also has a `has_value` field, an `is_present` field, and a `token` field - * (which is NULL if the action carries no value). The `_lf__a` field is of type trigger_t. That - * struct contains various things, including an array of reactions sensitive to this trigger and a - * lf_token_t struct containing the value of the action, if it has a value. See reactor.h in the C - * library for details. + * * Actions: If the reactor has an action a (logical or physical), then there + * will be a field in the self struct named `_lf_a` and another named `_lf__a`. + * The type of the first is specific to the action and contains a `value` + * field with the type and value of the action (if it has a value). That + * struct also has a `has_value` field, an `is_present` field, and a + * `token` field (which is NULL if the action carries no value). + * The `_lf__a` field is of type trigger_t. + * That struct contains various things, including an array of reactions + * sensitive to this trigger and a lf_token_t struct containing the value of + * the action, if it has a value. See reactor.h in the C library for + * details. * - *

* Reactions: Each reaction will have several fields in the self struct. Each of these has a - * name that begins with `_lf__reaction_i`, where i is the number of the reaction, starting with 0. - * The fields are: * _lf__reaction_i: The struct that is put onto the reaction queue to execute the - * reaction (see reactor.h in the C library). + * * Reactions: Each reaction will have several fields in the self struct. + * Each of these has a name that begins with `_lf__reaction_i`, where i is + * the number of the reaction, starting with 0. The fields are: + * * _lf__reaction_i: The struct that is put onto the reaction queue to + * execute the reaction (see reactor.h in the C library). * - *

* Timers: For each timer t, there is are two fields in the self struct: * _lf__t: The - * trigger_t struct for this timer (see reactor.h). * _lf__t_reactions: An array of reactions - * (pointers to the reaction_t structs on this self struct) sensitive to this timer. + * * Timers: For each timer t, there is are two fields in the self struct: + * * _lf__t: The trigger_t struct for this timer (see reactor.h). + * * _lf__t_reactions: An array of reactions (pointers to the + * reaction_t structs on this self struct) sensitive to this timer. * - *

* Triggers: For each Timer, Action, Input, and Output of a contained reactor that triggers - * reactions, there will be a trigger_t struct on the self struct with name `_lf__t`, where t is the - * name of the trigger. + * * Triggers: For each Timer, Action, Input, and Output of a contained + * reactor that triggers reactions, there will be a trigger_t struct + * on the self struct with name `_lf__t`, where t is the name of the trigger. * - *

## Connections Between Reactors + * ## Connections Between Reactors * - *

Establishing connections between reactors involves two steps. First, each destination (e.g. an - * input port) must have pointers to the source (the output port). As explained above, for an input - * named `in`, the field `_lf_in->value` is a pointer to the output data being read. In addition, - * `_lf_in->is_present` is a pointer to the corresponding `out->is_present` field of the output - * reactor's self struct. + * Establishing connections between reactors involves two steps. + * First, each destination (e.g. an input port) must have pointers to + * the source (the output port). As explained above, for an input named + * `in`, the field `_lf_in->value` is a pointer to the output data being read. + * In addition, `_lf_in->is_present` is a pointer to the corresponding + * `out->is_present` field of the output reactor's self struct. * - *

In addition, the `reaction_i` struct on the self struct has a `triggers` field that records - * all the trigger_t structs for ports and actions that are triggered by the i-th reaction. The - * triggers field is an array of arrays of pointers to trigger_t structs. The length of the outer - * array is the number of output channels (single ports plus multiport widths) that the reaction - * effects plus the number of input port channels of contained reactors that it effects. Each inner - * array has a length equal to the number of final destinations of that output channel or input - * channel. The reaction_i struct has an array triggered_sizes that indicates the sizes of these - * inner arrays. The num_outputs field of the reaction_i struct gives the length of the - * triggered_sizes and (outer) triggers arrays. The num_outputs field is equal to the total number - * of single ports and multiport channels that the reaction writes to. + * In addition, the `reaction_i` struct on the self struct has a `triggers` + * field that records all the trigger_t structs for ports and actions + * that are triggered by the i-th reaction. The triggers field is + * an array of arrays of pointers to trigger_t structs. + * The length of the outer array is the number of output channels + * (single ports plus multiport widths) that the reaction effects + * plus the number of input port channels of contained + * reactors that it effects. Each inner array has a length equal to the + * number of final destinations of that output channel or input channel. + * The reaction_i struct has an array triggered_sizes that indicates + * the sizes of these inner arrays. The num_outputs field of the + * reaction_i struct gives the length of the triggered_sizes and + * (outer) triggers arrays. The num_outputs field is equal to the + * total number of single ports and multiport channels that the reaction + * writes to. * - *

## Runtime Tables + * ## Runtime Tables * - *

This generator creates an populates the following tables used at run time. These tables may - * have to be resized and adjusted when mutations occur. + * This generator creates an populates the following tables used at run time. + * These tables may have to be resized and adjusted when mutations occur. * - *

* _lf_is_present_fields: An array of pointers to booleans indicating whether an event is - * present. The _lf_start_time_step() function in reactor_common.c uses this to mark every event - * absent at the start of a time step. The size of this table is contained in the variable - * _lf_is_present_fields_size. * This table is accompanied by another list, - * _lf_is_present_fields_abbreviated, which only contains the is_present fields that have been set - * to true in the current tag. This list can allow a performance improvement if most ports are - * seldom present because only fields that have been set to true need to be reset to false. + * * _lf_is_present_fields: An array of pointers to booleans indicating whether an + * event is present. The _lf_start_time_step() function in reactor_common.c uses + * this to mark every event absent at the start of a time step. The size of this + * table is contained in the variable _lf_is_present_fields_size. + * * This table is accompanied by another list, _lf_is_present_fields_abbreviated, + * which only contains the is_present fields that have been set to true in the + * current tag. This list can allow a performance improvement if most ports are + * seldom present because only fields that have been set to true need to be + * reset to false. * - *

* _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown reactions. The - * length of this table is in the _lf_shutdown_triggers_size variable. + * * _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown + * reactions. The length of this table is in the _lf_shutdown_triggers_size + * variable. * - *

* _lf_timer_triggers: An array of pointers to trigger_t structs for timers that need to be - * started when the program runs. The length of this table is in the _lf_timer_triggers_size - * variable. + * * _lf_timer_triggers: An array of pointers to trigger_t structs for timers that + * need to be started when the program runs. The length of this table is in the + * _lf_timer_triggers_size variable. * - *

* _lf_action_table: For a federated execution, each federate will have this table that maps - * port IDs to the corresponding action struct, which can be cast to action_base_t. + * * _lf_action_table: For a federated execution, each federate will have this table + * that maps port IDs to the corresponding action struct, which can be cast to + * action_base_t. * * @author Edward A. Lee * @author Marten Lohstroh @@ -263,1122 +304,1102 @@ */ @SuppressWarnings("StaticPseudoFunctionalStyleMethod") public class CGenerator extends GeneratorBase { - // Regular expression pattern for compiler error messages with resource - // and line number information. The first match will a resource URI in the - // form of "file:/path/file.lf". The second match will be a line number. - // The third match is a character position within the line. - // The fourth match will be the error message. - static final Pattern compileErrorPattern = - Pattern.compile("^(?.*):(?\\d+):(?\\d+):(?.*)$"); - - public static int UNDEFINED_MIN_SPACING = -1; - - //////////////////////////////////////////// - //// Protected fields - - /** The main place to put generated code. */ - protected CodeBuilder code = new CodeBuilder(); - - /** Place to collect code to initialize the trigger objects for all reactor instances. */ - protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); - - protected final CFileConfig fileConfig; - - /** - * Count of the number of is_present fields of the self struct that need to be reinitialized in - * _lf_start_time_step(). - */ - protected int startTimeStepIsPresentCount = 0; - - //////////////////////////////////////////// - //// Private fields - /** Extra lines that need to go into the generated CMakeLists.txt. */ - private String cMakeExtras = ""; - - /** Place to collect code to execute at the start of a time step. */ - private CodeBuilder startTimeStep = new CodeBuilder(); - - /** - * Count of the number of token pointers that need to have their reference count decremented in - * _lf_start_time_step(). - */ - private int timerCount = 0; - - private int startupReactionCount = 0; - private int shutdownReactionCount = 0; - private int resetReactionCount = 0; - private int modalReactorCount = 0; - private int modalStateResetCount = 0; - private int watchdogCount = 0; - - // Indicate whether the generator is in Cpp mode or not - private final boolean CCppMode; - - private final CTypes types; - - private final CCmakeGenerator cmakeGenerator; - - protected CGenerator( - LFGeneratorContext context, - boolean CCppMode, - CTypes types, - CCmakeGenerator cmakeGenerator, - DelayBodyGenerator delayBodyGenerator) { - super(context); - this.fileConfig = (CFileConfig) context.getFileConfig(); - this.CCppMode = CCppMode; - this.types = types; - this.cmakeGenerator = cmakeGenerator; - - // Register the delayed connection transformation to be applied by GeneratorBase. - // transform both after delays and physical connections - registerTransformation( - new DelayedConnectionTransformation( - delayBodyGenerator, types, fileConfig.resource, true, true)); - } - - public CGenerator(LFGeneratorContext context, boolean ccppMode) { - this( - context, - ccppMode, - new CTypes(), - new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes())); - } - - /** - * Look for physical actions in all resources. If found, set threads to be at least one to allow - * asynchronous schedule calls. - */ - public void accommodatePhysicalActionsIfPresent() { - // If there are any physical actions, ensure the threaded engine is used and that - // keepalive is set to true, unless the user has explicitly set it to false. - for (Resource resource : GeneratorUtils.getResources(reactors)) { - for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { - if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { - // If the unthreaded runtime is not requested by the user, use the threaded runtime - // instead - // because it is the only one currently capable of handling asynchronous events. - if (!targetConfig.threading - && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = true; - errorReporter.reportWarning( - action, - "Using the threaded C runtime to allow for asynchronous handling of physical action" - + " " - + action.getName()); - return; - } - } - } + + // Regular expression pattern for compiler error messages with resource + // and line number information. The first match will a resource URI in the + // form of "file:/path/file.lf". The second match will be a line number. + // The third match is a character position within the line. + // The fourth match will be the error message. + static final Pattern compileErrorPattern = Pattern.compile( + "^(?.*):(?\\d+):(?\\d+):(?.*)$" + ); + + public static int UNDEFINED_MIN_SPACING = -1; + + //////////////////////////////////////////// + //// Protected fields + + /** The main place to put generated code. */ + protected CodeBuilder code = new CodeBuilder(); + + /** Place to collect code to initialize the trigger objects for all reactor instances. */ + protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); + + protected final CFileConfig fileConfig; + + /** + * Count of the number of is_present fields of the self struct that + * need to be reinitialized in _lf_start_time_step(). + */ + protected int startTimeStepIsPresentCount = 0; + + //////////////////////////////////////////// + //// Private fields + /** + * Extra lines that need to go into the generated CMakeLists.txt. + */ + private String cMakeExtras = ""; + + /** Place to collect code to execute at the start of a time step. */ + private CodeBuilder startTimeStep = new CodeBuilder(); + + /** Count of the number of token pointers that need to have their + * reference count decremented in _lf_start_time_step(). + */ + private int timerCount = 0; + private int startupReactionCount = 0; + private int shutdownReactionCount = 0; + private int resetReactionCount = 0; + private int modalReactorCount = 0; + private int modalStateResetCount = 0; + private int watchdogCount = 0; + + // Indicate whether the generator is in Cpp mode or not + private final boolean CCppMode; + + private final CTypes types; + + private final CCmakeGenerator cmakeGenerator; + + protected CGenerator( + LFGeneratorContext context, + boolean CCppMode, + CTypes types, + CCmakeGenerator cmakeGenerator, + DelayBodyGenerator delayBodyGenerator + ) { + super(context); + this.fileConfig = (CFileConfig) context.getFileConfig(); + this.CCppMode = CCppMode; + this.types = types; + this.cmakeGenerator = cmakeGenerator; + + // Register the delayed connection transformation to be applied by GeneratorBase. + // transform both after delays and physical connections + registerTransformation(new DelayedConnectionTransformation(delayBodyGenerator, types, fileConfig.resource, true, true)); } - } - - /** - * Return true if the host operating system is compatible and otherwise report an error and return - * false. - */ - protected boolean isOSCompatible() { - if (GeneratorUtils.isHostWindows()) { - if (CCppMode) { - errorReporter.reportError( - "LF programs with a CCpp target are currently not supported on Windows. " - + "Exiting code generation."); - // FIXME: The incompatibility between our C runtime code and the - // Visual Studio compiler is extensive. - return false; - } + + public CGenerator(LFGeneratorContext context, boolean ccppMode) { + this( + context, + ccppMode, + new CTypes(), + new CCmakeGenerator(context.getFileConfig(), List.of()), + new CDelayBodyGenerator(new CTypes()) + ); } - return true; - } - - /** - * Generate C code from the Lingua Franca model contained by the specified resource. This is the - * main entry point for code generation. - * - * @param resource The resource containing the source code. - * @param context The context in which the generator is invoked, including whether it is cancelled - * and whether it is a standalone context - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - super.doGenerate(resource, context); - if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; - if (!isOSCompatible()) return; // Incompatible OS and configuration - // Perform set up that does not generate code - setUpGeneralParameters(); - - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); - handleProtoFiles(); - - // Derive target filename from the .lf filename. - var lfModuleName = fileConfig.name; - var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); - var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; - try { - generateCodeFor(lfModuleName); - copyTargetFiles(); - generateHeaders(); - code.writeToFile(targetFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); + /** + * Look for physical actions in all resources. + * If found, set threads to be at least one to allow asynchronous schedule calls. + */ + public void accommodatePhysicalActionsIfPresent() { + // If there are any physical actions, ensure the threaded engine is used and that + // keepalive is set to true, unless the user has explicitly set it to false. + for (Resource resource : GeneratorUtils.getResources(reactors)) { + for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { + if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { + // If the unthreaded runtime is not requested by the user, use the threaded runtime instead + // because it is the only one currently capable of handling asynchronous events. + if (!targetConfig.threading && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = true; + errorReporter.reportWarning( + action, + "Using the threaded C runtime to allow for asynchronous handling of physical action " + + action.getName() + ); + return; + } + } + } + } } - // Create docker file. - if (targetConfig.dockerOptions != null && mainDef != null) { - try { - var dockerData = getDockerGenerator(context).generateDockerData(); - dockerData.writeDockerFile(); - (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); - } catch (IOException e) { - throw new RuntimeException("Error while writing Docker files", e); - } + /** + * Return true if the host operating system is compatible and + * otherwise report an error and return false. + */ + protected boolean isOSCompatible() { + if (GeneratorUtils.isHostWindows()) { + if (CCppMode) { + errorReporter.reportError( + "LF programs with a CCpp target are currently not supported on Windows. " + + "Exiting code generation." + ); + // FIXME: The incompatibility between our C runtime code and the + // Visual Studio compiler is extensive. + return false; + } + } + return true; } - // If cmake is requested, generate the CMakeLists.txt - if (targetConfig.platformOptions.platform != Platform.ARDUINO) { - var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; - var sources = - new HashSet<>(ASTUtils.recursiveChildren(main)) - .stream() - .map(CUtil::getName) - .map(it -> it + (CCppMode ? ".cpp" : ".c")) - .collect(Collectors.toList()); - sources.add(cFilename); - var cmakeCode = - cmakeGenerator.generateCMakeCode( - sources, - lfModuleName, - errorReporter, - CCppMode, - mainDef != null, - cMakeExtras, - targetConfig); - try { - cmakeCode.writeToFile(cmakeFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - } else { - try { - Path include = fileConfig.getSrcGenPath().resolve("include/"); - Path src = fileConfig.getSrcGenPath().resolve("src/"); - FileUtil.arduinoDeleteHelper(src, targetConfig.threading); - FileUtil.relativeIncludeHelper(src, include); - FileUtil.relativeIncludeHelper(include, include); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } + /** + * Generate C code from the Lingua Franca model contained by the + * specified resource. This is the main entry point for code + * generation. + * @param resource The resource containing the source code. + * @param context The context in which the generator is + * invoked, including whether it is cancelled and + * whether it is a standalone context + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + super.doGenerate(resource, context); + if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; + if (!isOSCompatible()) return; // Incompatible OS and configuration + + // Perform set up that does not generate code + setUpGeneralParameters(); + + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); + handleProtoFiles(); + + // Derive target filename from the .lf filename. + var lfModuleName = fileConfig.name; + var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); + var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; + try { + generateCodeFor(lfModuleName); + copyTargetFiles(); + generateHeaders(); + code.writeToFile(targetFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } - if (!targetConfig.noCompile) { - ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); - arduinoUtil.buildArduino(fileConfig, targetConfig); - context.finish(GeneratorResult.Status.COMPILED, null); - } else { - System.out.println("********"); - System.out.println( - "To compile your program, run the following command to see information about the board" - + " you plugged in:\n\n" - + "\tarduino-cli board list\n\n" - + "Grab the FQBN and PORT from the command and run the following command in the" - + " generated sources directory:\n\n" - + "\tarduino-cli compile -b --build-property" - + " compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" - + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property" - + " compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" - + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\n" - + "To flash/upload your generated sketch to the board, run the following command in" - + " the generated sources directory:\n\n" - + "\tarduino-cli upload -b -p \n"); - // System.out.println("For a list of all boards installed on your computer, you can use the - // following command:\n\n\tarduino-cli board listall\n"); - context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); - } - GeneratorUtils.refreshProject(resource, context.getMode()); - return; - } + // Create docker file. + if (targetConfig.dockerOptions != null && mainDef != null) { + try { + var dockerData = getDockerGenerator(context).generateDockerData(); + dockerData.writeDockerFile(); + (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + } catch (IOException e) { + throw new RuntimeException("Error while writing Docker files", e); + } + } - // Dump the additional compile definitions to a file to keep the generated project - // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can - // take over and do the rest of compilation. - try { - String compileDefs = - targetConfig.compileDefinitions.keySet().stream() - .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) - .collect(Collectors.joining("\n")); - FileUtil.writeToFile( - compileDefs, - Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt")); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + // If cmake is requested, generate the CMakeLists.txt + if (targetConfig.platformOptions.platform != Platform.ARDUINO) { + var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; + var sources = new HashSet<>(ASTUtils.recursiveChildren(main)).stream() + .map(CUtil::getName).map(it -> it + (CCppMode ? ".cpp" : ".c")) + .collect(Collectors.toList()); + sources.add(cFilename); + var cmakeCode = cmakeGenerator.generateCMakeCode( + sources, + lfModuleName, + errorReporter, + CCppMode, + mainDef != null, + cMakeExtras, + targetConfig + ); + try { + cmakeCode.writeToFile(cmakeFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + } else { + try { + Path include = fileConfig.getSrcGenPath().resolve("include/"); + Path src = fileConfig.getSrcGenPath().resolve("src/"); + FileUtil.arduinoDeleteHelper(src, targetConfig.threading); + FileUtil.relativeIncludeHelper(src, include); + FileUtil.relativeIncludeHelper(include, include); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + + if (!targetConfig.noCompile) { + ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); + arduinoUtil.buildArduino(fileConfig, targetConfig); + context.finish( + GeneratorResult.Status.COMPILED, null + ); + } else { + System.out.println("********"); + System.out.println("To compile your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli compile -b --build-property compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\nTo flash/upload your generated sketch to the board, run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); + // System.out.println("For a list of all boards installed on your computer, you can use the following command:\n\n\tarduino-cli board listall\n"); + context.finish( + GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null) + ); + } + GeneratorUtils.refreshProject(resource, context.getMode()); + return; + } - // If this code generator is directly compiling the code, compile it now so that we - // clean it up after, removing the #line directives after errors have been reported. - if (!targetConfig.noCompile - && targetConfig.dockerOptions == null - && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) - // This code is unreachable in LSP_FAST mode, so that check is omitted. - && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM) { - // FIXME: Currently, a lack of main is treated as a request to not produce - // a binary and produce a .o file instead. There should be a way to control - // this. - // Create an anonymous Runnable class and add it to the compileThreadPool - // so that compilation can happen in parallel. - var cleanCode = code.removeLines("#line"); - - var execName = lfModuleName; - var threadFileConfig = fileConfig; - var generator = - this; // FIXME: currently only passed to report errors with line numbers in the Eclipse - // IDE - var CppMode = CCppMode; - // generatingContext.reportProgress( - // String.format("Generated code for %d/%d executables. Compiling...", federateCount, - // federates.size()), - // 100 * federateCount / federates.size() - // ); // FIXME: Move to FedGenerator - // Create the compiler to be used later - - var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); - try { - if (!cCompiler.runCCompiler(generator, context)) { - // If compilation failed, remove any bin files that may have been created. - CUtil.deleteBinFiles(threadFileConfig); - // If finish has already been called, it is illegal and makes no sense. However, - // if finish has already been called, then this must be a federated execution. - context.unsuccessfulFinish(); + // Dump the additional compile definitions to a file to keep the generated project + // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can + // take over and do the rest of compilation. + try { + String compileDefs = targetConfig.compileDefinitions.keySet().stream() + .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) + .collect(Collectors.joining("\n")); + FileUtil.writeToFile( + compileDefs, + Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") + ); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + + // If this code generator is directly compiling the code, compile it now so that we + // clean it up after, removing the #line directives after errors have been reported. + if ( + !targetConfig.noCompile && targetConfig.dockerOptions == null + && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) + // This code is unreachable in LSP_FAST mode, so that check is omitted. + && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM + ) { + // FIXME: Currently, a lack of main is treated as a request to not produce + // a binary and produce a .o file instead. There should be a way to control + // this. + // Create an anonymous Runnable class and add it to the compileThreadPool + // so that compilation can happen in parallel. + var cleanCode = code.removeLines("#line"); + + var execName = lfModuleName; + var threadFileConfig = fileConfig; + var generator = this; // FIXME: currently only passed to report errors with line numbers in the Eclipse IDE + var CppMode = CCppMode; + // generatingContext.reportProgress( + // String.format("Generated code for %d/%d executables. Compiling...", federateCount, federates.size()), + // 100 * federateCount / federates.size() + // ); // FIXME: Move to FedGenerator + // Create the compiler to be used later + + var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); + try { + if (!cCompiler.runCCompiler(generator, context)) { + // If compilation failed, remove any bin files that may have been created. + CUtil.deleteBinFiles(threadFileConfig); + // If finish has already been called, it is illegal and makes no sense. However, + // if finish has already been called, then this must be a federated execution. + context.unsuccessfulFinish(); + } else { + context.finish( + GeneratorResult.Status.COMPILED, null + ); + } + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + } + + // If a build directive has been given, invoke it now. + // Note that the code does not get cleaned in this case. + if (!targetConfig.noCompile) { + if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { + CUtil.runBuildCommand( + fileConfig, + targetConfig, + commandFactory, + errorReporter, + this::reportCommandErrors, + context.getMode() + ); + context.finish( + GeneratorResult.Status.COMPILED, null + ); + } + if (!errorsOccurred()){ + System.out.println("Compiled binary is in " + fileConfig.binPath); + } } else { - context.finish(GeneratorResult.Status.COMPILED, null); + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); } - cleanCode.writeToFile(targetFile); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } - } - // If a build directive has been given, invoke it now. - // Note that the code does not get cleaned in this case. - if (!targetConfig.noCompile) { - if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { - CUtil.runBuildCommand( - fileConfig, - targetConfig, - commandFactory, - errorReporter, - this::reportCommandErrors, - context.getMode()); - context.finish(GeneratorResult.Status.COMPILED, null); - } - System.out.println("Compiled binary is in " + fileConfig.binPath); - } else { - context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + // In case we are in Eclipse, make sure the generated code is visible. + GeneratorUtils.refreshProject(resource, context.getMode()); } - // In case we are in Eclipse, make sure the generated code is visible. - GeneratorUtils.refreshProject(resource, context.getMode()); - } - - private void generateCodeFor(String lfModuleName) throws IOException { - startTimeStepIsPresentCount = 0; - code.pr(generateDirectives()); - code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); - // Generate code for each reactor. - generateReactorDefinitions(); - - // Generate main instance, if there is one. - // Note that any main reactors in imported files are ignored. - // Skip generation if there are cycles. - if (main != null) { - initializeTriggerObjects.pr( - String.join( - "\n", - "int _lf_startup_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", - "int _lf_shutdown_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", - "int _lf_reset_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", - "int _lf_timer_triggers_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", - "int bank_index;", - "SUPPRESS_UNUSED_WARNING(bank_index);", - "int _lf_watchdog_number_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);")); - // Add counters for modal initialization - initializeTriggerObjects.pr( - CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); - - // Create an array of arrays to store all self structs. - // This is needed because connections cannot be established until - // all reactor instances have self structs because ports that - // receive data reference the self structs of the originating - // reactors, which are arbitarily far away in the program graph. - generateSelfStructs(main); - generateReactorInstance(main); - - if (targetConfig.fedSetupPreamble != null) { - if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); - code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); - if (targetLanguageIsCpp()) code.pr("}"); - } + private void generateCodeFor( + String lfModuleName + ) throws IOException { + startTimeStepIsPresentCount = 0; + code.pr(generateDirectives()); + code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); + // Generate code for each reactor. + generateReactorDefinitions(); + + // Generate main instance, if there is one. + // Note that any main reactors in imported files are ignored. + // Skip generation if there are cycles. + if (main != null) { + initializeTriggerObjects.pr(String.join("\n", + "int _lf_startup_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", + "int _lf_shutdown_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", + "int _lf_reset_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", + "int _lf_timer_triggers_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", + "int bank_index;", + "SUPPRESS_UNUSED_WARNING(bank_index);", + "int _lf_watchdog_number_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);")); + // Add counters for modal initialization + initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); + + // Create an array of arrays to store all self structs. + // This is needed because connections cannot be established until + // all reactor instances have self structs because ports that + // receive data reference the self structs of the originating + // reactors, which are arbitarily far away in the program graph. + generateSelfStructs(main); + generateReactorInstance(main); + + if (targetConfig.fedSetupPreamble != null) { + if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); + code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); + if (targetLanguageIsCpp()) code.pr("}"); + } - // If there are timers, create a table of timers to be initialized. - code.pr(CTimerGenerator.generateDeclarations(timerCount)); - - // If there are startup reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); - - // If there are shutdown reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); - - // If there are reset reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); - - // If there are watchdogs, create a table of triggers. - code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); - - // If there are modes, create a table of mode state to be checked for transitions. - code.pr( - CModesGenerator.generateModeStatesTable( - hasModalReactors, modalReactorCount, modalStateResetCount)); - - // Generate function to initialize the trigger objects for all reactors. - code.pr( - CTriggerObjectsGenerator.generateInitializeTriggerObjects( - main, - targetConfig, - initializeTriggerObjects, - startTimeStep, - types, - lfModuleName, - startTimeStepIsPresentCount)); - - // Generate function to trigger startup reactions for all reactors. - code.pr( - CReactionGenerator.generateLfTriggerStartupReactions( - startupReactionCount, hasModalReactors)); - - // Generate function to schedule timers for all reactors. - code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - - // Generate a function that will either do nothing - // (if there is only one federate or the coordination - // is set to decentralized) or, if there are - // downstream federates, will notify the RTI - // that the specified logical time is complete. - if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) - code.pr("extern \"C\""); - code.pr( - String.join( - "\n", - "void logical_tag_complete(tag_t tag_to_send) {", - CExtensionUtils.surroundWithIfFederatedCentralized( - " _lf_logical_tag_complete(tag_to_send);"), - "}")); - - // Generate function to schedule shutdown reactions if any - // reactors have reactions to shutdown. - code.pr( - CReactionGenerator.generateLfTriggerShutdownReactions( - shutdownReactionCount, hasModalReactors)); - - // Generate an empty termination function for non-federated - // execution. For federated execution, an implementation is - // provided in federate.c. That implementation will resign - // from the federation and close any open sockets. - code.pr( - """ + // If there are timers, create a table of timers to be initialized. + code.pr(CTimerGenerator.generateDeclarations(timerCount)); + + // If there are startup reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); + + // If there are shutdown reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); + + // If there are reset reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); + + // If there are watchdogs, create a table of triggers. + code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); + + // If there are modes, create a table of mode state to be checked for transitions. + code.pr(CModesGenerator.generateModeStatesTable( + hasModalReactors, + modalReactorCount, + modalStateResetCount + )); + + // Generate function to initialize the trigger objects for all reactors. + code.pr(CTriggerObjectsGenerator.generateInitializeTriggerObjects( + main, + targetConfig, + initializeTriggerObjects, + startTimeStep, + types, + lfModuleName, + startTimeStepIsPresentCount + )); + + // Generate function to trigger startup reactions for all reactors. + code.pr(CReactionGenerator.generateLfTriggerStartupReactions(startupReactionCount, hasModalReactors)); + + // Generate function to schedule timers for all reactors. + code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); + + // Generate a function that will either do nothing + // (if there is only one federate or the coordination + // is set to decentralized) or, if there are + // downstream federates, will notify the RTI + // that the specified logical time is complete. + if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) code.pr("extern \"C\""); + code.pr(String.join("\n", + "void logical_tag_complete(tag_t tag_to_send) {", + CExtensionUtils.surroundWithIfFederatedCentralized( + " _lf_logical_tag_complete(tag_to_send);" + ), + "}" + )); + + // Generate function to schedule shutdown reactions if any + // reactors have reactions to shutdown. + code.pr(CReactionGenerator.generateLfTriggerShutdownReactions(shutdownReactionCount, hasModalReactors)); + + // Generate an empty termination function for non-federated + // execution. For federated execution, an implementation is + // provided in federate.c. That implementation will resign + // from the federation and close any open sockets. + code.pr(""" #ifndef FEDERATED void terminate_execution() {} - #endif"""); - - // Generate functions for modes - code.pr(CModesGenerator.generateLfInitializeModes(hasModalReactors)); - code.pr(CModesGenerator.generateLfHandleModeChanges(hasModalReactors, modalStateResetCount)); - code.pr( - CReactionGenerator.generateLfModeTriggeredReactions( - startupReactionCount, resetReactionCount, hasModalReactors)); - } - } - - @Override - public void checkModalReactorSupport(boolean __) { - // Modal reactors are currently only supported for non federated applications - super.checkModalReactorSupport(true); - } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - return String.join( - "\n", - "// Generated forwarding reaction for connections with the same destination", - "// but located in mutually exclusive modes.", - "lf_set(" + dest + ", " + source + "->value);"); - } - - /** Set the scheduler type in the target config as needed. */ - private void pickScheduler() { - // Don't use a scheduler that does not prioritize reactions based on deadlines - // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. - if (!targetConfig.schedulerType.prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - if (hasDeadlines(reactors)) { - if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { - targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; + #endif""" + ); + + + // Generate functions for modes + code.pr(CModesGenerator.generateLfInitializeModes( + hasModalReactors + )); + code.pr(CModesGenerator.generateLfHandleModeChanges( + hasModalReactors, + modalStateResetCount + )); + code.pr(CReactionGenerator.generateLfModeTriggeredReactions( + startupReactionCount, + resetReactionCount, + hasModalReactors + )); } - } } - } - private boolean hasDeadlines(List reactors) { - for (Reactor reactor : reactors) { - for (Reaction reaction : allReactions(reactor)) { - if (reaction.getDeadline() != null) { - return true; - } - } - } - return false; - } - - /** - * Look at the 'reactor' eResource. If it is an imported .lf file, incorporate it into the current - * program in the following manner: - Merge its target property with `targetConfig` - If there are - * any preambles, add them to the preambles of the reactor. - */ - private void inspectReactorEResource(ReactorDecl reactor) { - // If the reactor is imported, look at the - // target definition of the .lf file in which the reactor is imported from and - // append any cmake-include. - // Check if the reactor definition is imported - if (reactor.eResource() != mainDef.getReactorClass().eResource()) { - // Find the LFResource corresponding to this eResource - LFResource lfResource = null; - for (var resource : resources) { - if (resource.getEResource() == reactor.eResource()) { - lfResource = resource; - break; - } - } - // Copy the user files and cmake-includes to the src-gen path of the main .lf file - if (lfResource != null) { - copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); - } + @Override + public void checkModalReactorSupport(boolean __) { + // Modal reactors are currently only supported for non federated applications + super.checkModalReactorSupport(true); } - } - - /** - * Copy all files or directories listed in the target property `files`, `cmake-include`, and - * `_fed_setup` into the src-gen folder of the main .lf file - * - * @param targetConfig The targetConfig to read the target properties from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - @Override - public void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - super.copyUserFiles(targetConfig, fileConfig); - // Make sure the target directory exists. - var targetDir = this.fileConfig.getSrcGenPath(); - try { - Files.createDirectories(targetDir); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + return String.join("\n", + "// Generated forwarding reaction for connections with the same destination", + "// but located in mutually exclusive modes.", + "lf_set("+dest+", "+source+"->value);" + ); } - for (String filename : targetConfig.fileNames) { - var relativeFileName = - CUtil.copyFileOrResource(filename, fileConfig.srcFile.getParent(), targetDir); - if (StringExtensions.isNullOrEmpty(relativeFileName)) { - errorReporter.reportError( - "Failed to find file " + filename + " specified in the" + " files target property."); - } else { - targetConfig.filesNamesWithoutPath.add(relativeFileName); - } + /** Set the scheduler type in the target config as needed. */ + private void pickScheduler() { + // Don't use a scheduler that does not prioritize reactions based on deadlines + // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. + if (!targetConfig.schedulerType.prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (hasDeadlines(reactors)) { + if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { + targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; + } + } + } } - for (String filename : targetConfig.cmakeIncludes) { - var relativeCMakeIncludeFileName = - CUtil.copyFileOrResource(filename, fileConfig.srcFile.getParent(), targetDir); - // Check if the file exists - if (StringExtensions.isNullOrEmpty(relativeCMakeIncludeFileName)) { - errorReporter.reportError("Failed to find cmake-include file " + filename); - } else { - this.targetConfig.cmakeIncludesWithoutPath.add(relativeCMakeIncludeFileName); - } + private boolean hasDeadlines(List reactors) { + for (Reactor reactor : reactors) { + for (Reaction reaction : allReactions(reactor)) { + if (reaction.getDeadline() != null) { + return true; + } + } + } + return false; } - if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { - try { - FileUtil.copyFile( - fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), - targetDir.resolve(targetConfig.fedSetupPreamble)); - } catch (IOException e) { - errorReporter.reportError( - "Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); - } + /** + * Look at the 'reactor' eResource. + * If it is an imported .lf file, incorporate it into the current + * program in the following manner: + * - Merge its target property with `targetConfig` + * - If there are any preambles, add them to the preambles of the reactor. + */ + private void inspectReactorEResource(ReactorDecl reactor) { + // If the reactor is imported, look at the + // target definition of the .lf file in which the reactor is imported from and + // append any cmake-include. + // Check if the reactor definition is imported + if (reactor.eResource() != mainDef.getReactorClass().eResource()) { + // Find the LFResource corresponding to this eResource + LFResource lfResource = null; + for (var resource : resources) { + if (resource.getEResource() == reactor.eResource()) { + lfResource = resource; + break; + } + } + if (lfResource != null) { + // Copy the user files and cmake-includes to the src-gen path of the main .lf file + copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + // Merge the CMake includes from the imported file into the target config + lfResource.getTargetConfig().cmakeIncludes.forEach(incl -> { + if (!this.targetConfig.cmakeIncludes.contains(incl)) { + this.targetConfig.cmakeIncludes.add(incl); + } + }); + } + } } - } - - /** - * Generate code for defining all reactors that belong to the federate, including all the child - * reactors down the hierarchy. Duplicate Duplicates are avoided. - * - *

Imported reactors' original .lf file is incorporated in the following manner: - If there are - * any cmake-include files, add them to the current list of cmake-include files. - If there are - * any preambles, add them to the preambles of the reactor. - */ - private void generateReactorDefinitions() throws IOException { - var generatedReactors = new LinkedHashSet(); - if (this.main != null) { - generateReactorChildren(this.main, generatedReactors); + + /** + * Copy all files or directories listed in the target property `files`, `cmake-include`, + * and `_fed_setup` into the src-gen folder of the main .lf file + * + * @param targetConfig The targetConfig to read the target properties from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + @Override + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + super.copyUserFiles(targetConfig, fileConfig); + // Must use class variable to determine destination! + var destination = this.fileConfig.getSrcGenPath(); + + FileUtil.copyFiles(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); + + // FIXME: Unclear what the following does, but it does not appear to belong here. + if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { + try { + FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), + destination.resolve(targetConfig.fedSetupPreamble)); + } catch (IOException e) { + errorReporter.reportError("Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); + } + } } - if (this.mainDef != null) { - generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); + /** + * Generate code for defining all reactors that belong to the federate, + * including all the child reactors down the hierarchy. Duplicate + * Duplicates are avoided. + * + * Imported reactors' original .lf file is + * incorporated in the following manner: + * - If there are any cmake-include files, add them to the current list + * of cmake-include files. + * - If there are any preambles, add them to the preambles of the reactor. + */ + private void generateReactorDefinitions() throws IOException { + var generatedReactors = new LinkedHashSet(); + if (this.main != null) { + generateReactorChildren(this.main, generatedReactors); + } + + if (this.mainDef != null) { + generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); + } + + if (mainDef == null) { + // Generate code for each reactor that was not instantiated in main or its children. + for (Reactor r : reactors) { + // Get the declarations for reactors that are instantiated somewhere. + // A declaration is either a reactor definition or an import statement.; + var declarations = this.instantiationGraph.getDeclarations(r); + // If the reactor has no instantiations and there is no main reactor, then + // generate code for it anyway (at a minimum, this means that the compiler is invoked + // so that reaction bodies are checked). + if (declarations.isEmpty()) { + generateReactorClass(r); + } + } + } } - if (mainDef == null) { - // Generate code for each reactor that was not instantiated in main or its children. - for (Reactor r : reactors) { - // Get the declarations for reactors that are instantiated somewhere. - // A declaration is either a reactor definition or an import statement.; - var declarations = this.instantiationGraph.getDeclarations(r); - // If the reactor has no instantiations and there is no main reactor, then - // generate code for it anyway (at a minimum, this means that the compiler is invoked - // so that reaction bodies are checked). - if (declarations.isEmpty()) { - generateReactorClass(r); + /** Generate user-visible header files for all reactors instantiated. */ + private void generateHeaders() throws IOException { + FileUtil.deleteDirectory(fileConfig.getIncludePath()); + FileUtil.copyDirectoryFromClassPath( + fileConfig.getRuntimeIncludePath(), + fileConfig.getIncludePath(), + false + ); + for (Reactor r : reactors) { + CReactorHeaderFileGenerator.doGenerate( + types, r, fileConfig, + (builder, rr, userFacing) -> { + generateAuxiliaryStructs(builder, rr, userFacing); + if (userFacing) { + ASTUtils.allInstantiations(r).stream().map(Instantiation::getReactorClass).collect(Collectors.toSet()).forEach(it -> { + ASTUtils.allPorts(ASTUtils.toDefinition(it)) + .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( + ASTUtils.toDefinition(it), p, getTarget(), errorReporter, types, new CodeBuilder(), true, it + ))); + }); + } + }, + this::generateTopLevelPreambles); } - } + FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); } - } - - /** Generate user-visible header files for all reactors instantiated. */ - private void generateHeaders() throws IOException { - FileUtil.deleteDirectory(fileConfig.getIncludePath()); - FileUtil.copyDirectoryFromClassPath( - fileConfig.getRuntimeIncludePath(), fileConfig.getIncludePath(), false); - for (Reactor r : reactors) { - CReactorHeaderFileGenerator.doGenerate( - types, - r, - fileConfig, - (builder, rr, userFacing) -> { - generateAuxiliaryStructs(builder, rr, userFacing); - if (userFacing) { - ASTUtils.allInstantiations(r).stream() - .map(Instantiation::getReactorClass) - .collect(Collectors.toSet()) - .forEach( - it -> { - ASTUtils.allPorts(ASTUtils.toDefinition(it)) - .forEach( - p -> - builder.pr( - CPortGenerator.generateAuxiliaryStruct( - ASTUtils.toDefinition(it), - p, - getTarget(), - errorReporter, - types, - new CodeBuilder(), - true, - it))); - }); + + /** + * Generate code for the children of 'reactor' that belong to 'federate'. + * Duplicates are avoided. + * + * Imported reactors' original .lf file is + * incorporated in the following manner: + * - If there are any cmake-include files, add them to the current list + * of cmake-include files. + * - If there are any preambles, add them to the preambles of the reactor. + * + * @param reactor Used to extract children from + */ + private void generateReactorChildren( + ReactorInstance reactor, + LinkedHashSet generatedReactors + ) throws IOException { + for (ReactorInstance r : reactor.children) { + if (r.reactorDeclaration != null && + !generatedReactors.contains(r.reactorDefinition)) { + generatedReactors.add(r.reactorDefinition); + generateReactorChildren(r, generatedReactors); + inspectReactorEResource(r.reactorDeclaration); + generateReactorClass(r.reactorDefinition); } - }, - this::generateTopLevelPreambles); + } + } + + /** + * Choose which platform files to compile with according to the OS. + * If there is no main reactor, then compilation will produce a .o file requiring further linking. + * Also, if useCmake is set to true, we don't need to add platform files. The CMakeLists.txt file + * will detect and use the appropriate platform file based on the platform that cmake is invoked on. + */ + private void pickCompilePlatform() { + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { + errorReporter.reportError("Platform " + osName + " is not supported"); + } } - FileUtil.copyDirectory( - fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); - } - - /** - * Generate code for the children of 'reactor' that belong to 'federate'. Duplicates are avoided. - * - *

Imported reactors' original .lf file is incorporated in the following manner: - If there are - * any cmake-include files, add them to the current list of cmake-include files. - If there are - * any preambles, add them to the preambles of the reactor. - * - * @param reactor Used to extract children from - */ - private void generateReactorChildren( - ReactorInstance reactor, LinkedHashSet generatedReactors) throws IOException { - for (ReactorInstance r : reactor.children) { - if (r.reactorDeclaration != null && !generatedReactors.contains(r.reactorDefinition)) { - generatedReactors.add(r.reactorDefinition); - generateReactorChildren(r, generatedReactors); - inspectReactorEResource(r.reactorDeclaration); - generateReactorClass(r.reactorDefinition); + + /** + * Copy target-specific header file to the src-gen directory. + */ + protected void copyTargetFiles() throws IOException { + // Copy the core lib + String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); + Path dest = fileConfig.getSrcGenPath(); + if (targetConfig.platformOptions.platform == Platform.ARDUINO) { + dest = dest.resolve("src"); } + if (coreLib != null) { + FileUtil.copyDirectory(Path.of(coreLib), dest, true); + } else { + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/core", + dest.resolve("core"), + true + ); + FileUtil.copyDirectoryFromClassPath( + "/lib/c/reactor-c/lib", + dest.resolve("lib"), + true + ); + } + + // For the Zephyr target, copy default config and board files. + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyDirectoryFromClassPath( + "/lib/platform/zephyr/boards", + fileConfig.getSrcGenPath().resolve("boards"), + false + ); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", + fileConfig.getSrcGenPath().resolve("prj_lf.conf"), + true + ); + + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", + fileConfig.getSrcGenPath().resolve("Kconfig"), + true + ); + } + } + + //////////////////////////////////////////// + //// Code generators. + + /** + * Generate a reactor class definition for the specified federate. + * A class definition has four parts: + * + * * Preamble code, if any, specified in the Lingua Franca file. + * * A "self" struct type definition (see the class documentation above). + * * A function for each reaction. + * * A constructor for creating an instance. + * for deleting an instance. + * + * If the reactor is the main reactor, then + * the generated code may be customized. Specifically, + * if the main reactor has reactions, these reactions + * will not be generated if they are triggered by or send + * data to contained reactors that are not in the federate. + * @param reactor The parsed reactor data structure. + */ + private void generateReactorClass(Reactor reactor) throws IOException { + // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. + CodeBuilder header = new CodeBuilder(); + CodeBuilder src = new CodeBuilder(); + final String headerName = CUtil.getName(reactor) + ".h"; + var guardMacro = headerName.toUpperCase().replace(".", "_"); + header.pr("#ifndef " + guardMacro); + header.pr("#define " + guardMacro); + generateReactorClassHeaders(reactor, headerName, header, src); + header.pr(generateTopLevelPreambles(reactor)); + generateUserPreamblesForReactor(reactor, src); + generateReactorClassBody(reactor, header, src); + header.pr("#endif // " + guardMacro); + FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); + var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : + CCppMode ? ".cpp" : ".c"; + FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); } - } - - /** - * Choose which platform files to compile with according to the OS. If there is no main reactor, - * then compilation will produce a .o file requiring further linking. Also, if useCmake is set to - * true, we don't need to add platform files. The CMakeLists.txt file will detect and use the - * appropriate platform file based on the platform that cmake is invoked on. - */ - private void pickCompilePlatform() { - var osName = System.getProperty("os.name").toLowerCase(); - // if platform target was set, use given platform instead - if (targetConfig.platformOptions.platform != Platform.AUTO) { - osName = targetConfig.platformOptions.platform.toString(); - } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { - errorReporter.reportError("Platform " + osName + " is not supported"); + + protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { + if (CCppMode) { + src.pr("extern \"C\" {"); + header.pr("extern \"C\" {"); + } + header.pr("#include \"include/core/reactor.h\""); + src.pr("#include \"include/api/api.h\""); + src.pr("#include \"include/api/set.h\""); + generateIncludes(reactor); + if (CCppMode) { + src.pr("}"); + header.pr("}"); + } + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); + src.pr("#include \"" + headerName + "\""); + ASTUtils.allNestedClasses(reactor).map(CUtil::getName) + .map(name -> "#include \"" + name + ".h\"") + .forEach(header::pr); } - } - - /** Copy target-specific header file to the src-gen directory. */ - protected void copyTargetFiles() throws IOException { - // Copy the core lib - String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); - Path dest = fileConfig.getSrcGenPath(); - if (targetConfig.platformOptions.platform == Platform.ARDUINO) dest = dest.resolve("src"); - if (coreLib != null) { - FileUtil.copyDirectory(Path.of(coreLib), dest, true); - } else { - FileUtil.copyDirectoryFromClassPath("/lib/c/reactor-c/core", dest.resolve("core"), true); - FileUtil.copyDirectoryFromClassPath("/lib/c/reactor-c/lib", dest.resolve("lib"), true); + + private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { + // Some of the following methods create lines of code that need to + // go into the constructor. Collect those lines of code here: + var constructorCode = new CodeBuilder(); + generateAuxiliaryStructs(header, reactor, false); + // The following must go before the self struct so the #include watchdog.h ends up in the header. + CWatchdogGenerator.generateWatchdogs(src, header, reactor); + generateSelfStruct(header, reactor, constructorCode); + generateMethods(src, reactor); + generateReactions(src, reactor); + generateConstructor(src, header, reactor, constructorCode); } - // For the Zephyr target, copy default config and board files. - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - FileUtil.copyDirectoryFromClassPath( - "/lib/platform/zephyr/boards", fileConfig.getSrcGenPath().resolve("boards"), false); - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/prj_lf.conf", - fileConfig.getSrcGenPath().resolve("prj_lf.conf"), - true); - - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath().resolve("Kconfig"), true); + /** + * Generate methods for {@code reactor}. + */ + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { + CMethodGenerator.generateMethods(reactor, src, types); } - } - - //////////////////////////////////////////// - //// Code generators. - /** - * Generate a reactor class definition for the specified federate. A class definition has four - * parts: - * - *

* Preamble code, if any, specified in the Lingua Franca file. * A "self" struct type - * definition (see the class documentation above). * A function for each reaction. * A constructor - * for creating an instance. for deleting an instance. - * - *

If the reactor is the main reactor, then the generated code may be customized. Specifically, - * if the main reactor has reactions, these reactions will not be generated if they are triggered - * by or send data to contained reactors that are not in the federate. - * - * @param reactor The parsed reactor data structure. - */ - private void generateReactorClass(Reactor reactor) throws IOException { - // FIXME: Currently we're not reusing definitions for declarations that point to the same - // definition. - CodeBuilder header = new CodeBuilder(); - CodeBuilder src = new CodeBuilder(); - final String headerName = CUtil.getName(reactor) + ".h"; - var guardMacro = headerName.toUpperCase().replace(".", "_"); - header.pr("#ifndef " + guardMacro); - header.pr("#define " + guardMacro); - generateReactorClassHeaders(reactor, headerName, header, src); - header.pr(generateTopLevelPreambles(reactor)); - generateUserPreamblesForReactor(reactor, src); - generateReactorClassBody(reactor, header, src); - header.pr("#endif // " + guardMacro); - FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); - var extension = - targetConfig.platformOptions.platform == Platform.ARDUINO - ? ".ino" - : CCppMode ? ".cpp" : ".c"; - FileUtil.writeToFile( - src.toString(), - fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), - true); - } - - protected void generateReactorClassHeaders( - Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { - if (CCppMode) { - src.pr("extern \"C\" {"); - header.pr("extern \"C\" {"); + + /** + * Generates preambles defined by user for a given reactor + * @param reactor The given reactor + */ + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { + src.pr("// *********** From the preamble, verbatim:"); + src.prSourceLineNumber(p.getCode()); + src.pr(toText(p.getCode())); + src.pr("\n// *********** End of preamble."); + } } - header.pr("#include \"include/core/reactor.h\""); - src.pr("#include \"include/api/api.h\""); - src.pr("#include \"include/api/set.h\""); - generateIncludes(reactor); - if (CCppMode) { - src.pr("}"); - header.pr("}"); + + /** + * Generate a constructor for the specified reactor in the specified federate. + * @param reactor The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to + * go into the constructor. + */ + protected void generateConstructor( + CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode + ) { + header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); + src.pr(CConstructorGenerator.generateConstructor( + reactor, + constructorCode.toString() + )); } - src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); - src.pr("#include \"" + headerName + "\""); - ASTUtils.allNestedClasses(reactor) - .map(CUtil::getName) - .map(name -> "#include \"" + name + ".h\"") - .forEach(header::pr); - } - - private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { - // Some of the following methods create lines of code that need to - // go into the constructor. Collect those lines of code here: - var constructorCode = new CodeBuilder(); - generateAuxiliaryStructs(header, reactor, false); - // The following must go before the self struct so the #include watchdog.h ends up in the header. - CWatchdogGenerator.generateWatchdogs(src, header, reactor); - generateSelfStruct(header, reactor, constructorCode); - generateMethods(src, reactor); - generateReactions(src, reactor); - generateConstructor(src, header, reactor, constructorCode); - } - - /** Generate methods for {@code reactor}. */ - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { - CMethodGenerator.generateMethods(reactor, src, types); - } - - /** - * Generates preambles defined by user for a given reactor - * - * @param reactor The given reactor - */ - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { - src.pr("// *********** From the preamble, verbatim:"); - src.prSourceLineNumber(p.getCode()); - src.pr(toText(p.getCode())); - src.pr("\n// *********** End of preamble."); + + protected void generateIncludes(Reactor r) { + code.pr("#include \"" + CUtil.getName(r) + ".h\""); } - } - - /** - * Generate a constructor for the specified reactor in the specified federate. - * - * @param src Where to put the assembled code. - * @param header Where to put header code. - * @param reactor The parsed reactor data structure. - * @param constructorCode Lines of code previously generated that need to go into the constructor. - */ - protected void generateConstructor( - CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode) { - header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); - src.pr(CConstructorGenerator.generateConstructor(reactor, constructorCode.toString())); - } - - protected void generateIncludes(Reactor r) { - code.pr("#include \"" + CUtil.getName(r) + ".h\""); - } - - /** - * Generate the struct type definitions for inputs, outputs, and actions of the specified reactor. - */ - protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { - // In the case where there are incoming - // p2p logical connections in decentralized - // federated execution, there will be an - // intended_tag field added to accommodate - // the case where a reaction triggered by a - // port or action is late due to network - // latency, etc.. - var federatedExtension = new CodeBuilder(); - federatedExtension.pr( - """ + + /** + * Generate the struct type definitions for inputs, outputs, and + * actions of the specified reactor. + */ + protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { + // In the case where there are incoming + // p2p logical connections in decentralized + // federated execution, there will be an + // intended_tag field added to accommodate + // the case where a reaction triggered by a + // port or action is late due to network + // latency, etc.. + var federatedExtension = new CodeBuilder(); + federatedExtension.pr(""" #ifdef FEDERATED #ifdef FEDERATED_DECENTRALIZED %s intended_tag; #endif %s physical_time_of_arrival; #endif - """ - .formatted(types.getTargetTagType(), types.getTargetTimeType())); - for (Port p : allPorts(r)) { - builder.pr( - CPortGenerator.generateAuxiliaryStruct( - r, p, getTarget(), errorReporter, types, federatedExtension, userFacing, null)); + """.formatted(types.getTargetTagType(), types.getTargetTimeType()) + ); + for (Port p : allPorts(r)) { + builder.pr(CPortGenerator.generateAuxiliaryStruct( + r, + p, + getTarget(), + errorReporter, + types, + federatedExtension, + userFacing, + null + )); + } + // The very first item on this struct needs to be + // a trigger_t* because the struct will be cast to (trigger_t*) + // by the lf_schedule() functions to get to the trigger. + for (Action action : allActions(r)) { + builder.pr(CActionGenerator.generateAuxiliaryStruct( + r, + action, + getTarget(), + types, + federatedExtension, + userFacing + )); + } } - // The very first item on this struct needs to be - // a trigger_t* because the struct will be cast to (trigger_t*) - // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(r)) { - builder.pr( - CActionGenerator.generateAuxiliaryStruct( - r, action, getTarget(), types, federatedExtension, userFacing)); + + /** + * Generate the self struct type definition for the specified reactor + * in the specified federate. + * @param decl The parsed reactor data structure. + * @param constructorCode Place to put lines of code that need to + * go into the constructor. + */ + private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = toDefinition(decl); + var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); + + // Construct the typedef for the "self" struct. + // Create a type name for the self struct. + var body = new CodeBuilder(); + + // Extensions can add functionality to the CGenerator + generateSelfStructExtension(body, decl, constructorCode); + + // Next handle parameters. + body.pr(CParameterGenerator.generateDeclarations(reactor, types)); + + // Next handle states. + body.pr(CStateGenerator.generateDeclarations(reactor, types)); + + // Next handle actions. + CActionGenerator.generateDeclarations(reactor, body, constructorCode); + + // Next handle inputs and outputs. + CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); + + // If there are contained reactors that either receive inputs + // from reactions of this reactor or produce outputs that trigger + // reactions of this reactor, then we need to create a struct + // inside the self struct for each contained reactor. That + // struct has a place to hold the data produced by this reactor's + // reactions and a place to put pointers to data produced by + // the contained reactors. + generateInteractingContainedReactors(reactor, body, constructorCode); + + // Next, generate the fields needed for each reaction. + CReactionGenerator.generateReactionAndTriggerStructs( + body, + reactor, + constructorCode, + types + ); + + // Next, generate fields for modes + CModesGenerator.generateDeclarations(reactor, body, constructorCode); + + // The first field has to always be a pointer to the list of + // of allocated memory that must be freed when the reactor is freed. + // This means that the struct can be safely cast to self_base_t. + builder.pr("typedef struct {"); + builder.indent(); + builder.pr("struct self_base_t base;"); + builder.pr(body.toString()); + builder.unindent(); + builder.pr("} " + selfType + ";"); } - } - - /** - * Generate the self struct type definition for the specified reactor in the specified federate. - * - * @param decl The parsed reactor data structure. - * @param constructorCode Place to put lines of code that need to go into the constructor. - */ - private void generateSelfStruct( - CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { - var reactor = toDefinition(decl); - var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); - - // Construct the typedef for the "self" struct. - // Create a type name for the self struct. - var body = new CodeBuilder(); - - // Extensions can add functionality to the CGenerator - generateSelfStructExtension(body, decl, constructorCode); - - // Next handle parameters. - body.pr(CParameterGenerator.generateDeclarations(reactor, types)); - - // Next handle states. - body.pr(CStateGenerator.generateDeclarations(reactor, types)); - - // Next handle actions. - CActionGenerator.generateDeclarations(reactor, body, constructorCode); - - // Next handle inputs and outputs. - CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); - - // If there are contained reactors that either receive inputs - // from reactions of this reactor or produce outputs that trigger - // reactions of this reactor, then we need to create a struct - // inside the self struct for each contained reactor. That - // struct has a place to hold the data produced by this reactor's - // reactions and a place to put pointers to data produced by - // the contained reactors. - generateInteractingContainedReactors(reactor, body, constructorCode); - - // Next, generate the fields needed for each reaction. - CReactionGenerator.generateReactionAndTriggerStructs(body, reactor, constructorCode, types); - - // Generate the fields needed for each watchdog. - CWatchdogGenerator.generateWatchdogStruct(body, decl, constructorCode); - - // Next, generate fields for modes - CModesGenerator.generateDeclarations(reactor, body, constructorCode); - - // The first field has to always be a pointer to be struct_base_t. - // This means that the struct can be safely cast to self_base_t. - builder.pr("typedef struct {"); - builder.indent(); - builder.pr("struct self_base_t base;"); - builder.pr(body.toString()); - builder.unindent(); - builder.pr("} " + selfType + ";"); - } - - /** - * Generate structs and associated code for contained reactors that send or receive data to or - * from the container's reactions. - * - *

If there are contained reactors that either receive inputs from reactions of this reactor or - * produce outputs that trigger reactions of this reactor, then we need to create a struct inside - * the self struct of the container for each contained reactor. That struct has a place to hold - * the data produced by the container reactor's reactions and a place to put pointers to data - * produced by the contained reactors. - * - * @param reactor The reactor. - * @param body The place to put the struct definition for the contained reactors. - * @param constructorCode The place to put matching code that goes in the container's constructor. - */ - private void generateInteractingContainedReactors( - Reactor reactor, CodeBuilder body, CodeBuilder constructorCode) { - // The contents of the struct will be collected first so that - // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(reactor); - // Next generate the relevant code. - for (Instantiation containedReactor : contained.containedReactors()) { - Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); - // First define an _width variable in case it is a bank. - var array = ""; - var width = -2; - // If the instantiation is a bank, find the maximum bank width - // to define an array. - if (containedReactor.getWidthSpec() != null) { - width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); - array = "[" + width + "]"; - } - // NOTE: The following needs to be done for each instance - // so that the width can be parameter, not in the constructor. - // Here, we conservatively use a width that is the largest of all isntances. - constructorCode.pr( - String.join( - "\n", - "// Set the _width variable for all cases. This will be -2", - "// if the reactor is not a bank of reactors.", - "self->_lf_" + containedReactor.getName() + "_width = " + width + ";")); - - // Generate one struct for each contained reactor that interacts. - body.pr("struct {"); - body.indent(); - for (Port port : contained.portsOfInstance(containedReactor)) { - if (port instanceof Input) { - // If the variable is a multiport, then the place to store the data has - // to be malloc'd at initialization. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr( - port, - variableStructType(port, containedReactorType, false) + " " + port.getName() + ";"); - } else { - // Is a multiport. - // Memory will be malloc'd in initialization. - body.pr( - port, - String.join( - "\n", - variableStructType(port, containedReactorType, false) - + "** " - + port.getName() - + ";", - "int " + port.getName() + "_width;")); - } - } else { - // Must be an output port. - // Outputs of contained reactors are pointers to the source of data on the - // self struct of the container. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr( - port, - variableStructType(port, containedReactorType, false) - + "* " - + port.getName() - + ";"); - } else { - // Is a multiport. - // Here, we will use an array of pointers. - // Memory will be malloc'd in initialization. - body.pr( - port, - String.join( - "\n", - variableStructType(port, containedReactorType, false) - + "** " - + port.getName() - + ";", - "int " + port.getName() + "_width;")); - } - body.pr(port, "trigger_t " + port.getName() + "_trigger;"); - var reactorIndex = ""; - if (containedReactor.getWidthSpec() != null) { - reactorIndex = "[reactor_index]"; - constructorCode.pr( - "for (int reactor_index = 0; reactor_index < self->_lf_" - + containedReactor.getName() - + "_width; reactor_index++) {"); - constructorCode.indent(); - } - var portOnSelf = - "self->_lf_" + containedReactor.getName() + reactorIndex + "." + port.getName(); - - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederatedDecentralized( - portOnSelf - + "_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - - var triggered = contained.reactionsTriggered(containedReactor, port); - //noinspection StatementWithEmptyBody - if (triggered.size() > 0) { - body.pr( - port, "reaction_t* " + port.getName() + "_reactions[" + triggered.size() + "];"); - var triggeredCount = 0; - for (Integer index : triggered) { - constructorCode.pr( - port, - portOnSelf - + "_reactions[" - + triggeredCount++ - + "] = &self->_lf__reaction_" - + index - + ";"); + + /** + * Generate structs and associated code for contained reactors that + * send or receive data to or from the container's reactions. + * + * If there are contained reactors that either receive inputs + * from reactions of this reactor or produce outputs that trigger + * reactions of this reactor, then we need to create a struct + * inside the self struct of the container for each contained reactor. + * That struct has a place to hold the data produced by the container reactor's + * reactions and a place to put pointers to data produced by + * the contained reactors. + * + * @param reactor The reactor. + * @param body The place to put the struct definition for the contained reactors. + * @param constructorCode The place to put matching code that goes in the container's constructor. + */ + private void generateInteractingContainedReactors( + Reactor reactor, + CodeBuilder body, + CodeBuilder constructorCode + ) { + // The contents of the struct will be collected first so that + // we avoid duplicate entries and then the struct will be constructed. + var contained = new InteractingContainedReactors(reactor); + // Next generate the relevant code. + for (Instantiation containedReactor : contained.containedReactors()) { + Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); + // First define an _width variable in case it is a bank. + var array = ""; + var width = -2; + // If the instantiation is a bank, find the maximum bank width + // to define an array. + if (containedReactor.getWidthSpec() != null) { + width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); + array = "[" + width + "]"; } - constructorCode.pr( - port, portOnSelf + "_trigger.reactions = " + portOnSelf + "_reactions;"); - } else { - // Since the self struct is created using calloc, there is no need to set - // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL - } - // Since the self struct is created using calloc, there is no need to set falsy fields. - constructorCode.pr( - port, - String.join( - "\n", - portOnSelf + "_trigger.last = NULL;", - portOnSelf + "_trigger.number_of_reactions = " + triggered.size() + ";")); - - // Set the physical_time_of_arrival - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederated( - portOnSelf + "_trigger.physical_time_of_arrival = NEVER;")); - - if (containedReactor.getWidthSpec() != null) { - constructorCode.unindent(); - constructorCode.pr("}"); - } + // NOTE: The following needs to be done for each instance + // so that the width can be parameter, not in the constructor. + // Here, we conservatively use a width that is the largest of all isntances. + constructorCode.pr(String.join("\n", + "// Set the _width variable for all cases. This will be -2", + "// if the reactor is not a bank of reactors.", + "self->_lf_"+containedReactor.getName()+"_width = "+width+";" + )); + + // Generate one struct for each contained reactor that interacts. + body.pr("struct {"); + body.indent(); + for (Port port : contained.portsOfInstance(containedReactor)) { + if (port instanceof Input) { + // If the variable is a multiport, then the place to store the data has + // to be malloc'd at initialization. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); + } else { + // Is a multiport. + // Memory will be malloc'd in initialization. + body.pr(port, String.join("\n", + variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + "int "+port.getName()+"_width;" + )); + } + } else { + // Must be an output port. + // Outputs of contained reactors are pointers to the source of data on the + // self struct of the container. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); + } else { + // Is a multiport. + // Here, we will use an array of pointers. + // Memory will be malloc'd in initialization. + body.pr(port, String.join("\n", + variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", + "int "+port.getName()+"_width;" + )); + } + body.pr(port, "trigger_t "+port.getName()+"_trigger;"); + var reactorIndex = ""; + if (containedReactor.getWidthSpec() != null) { + reactorIndex = "[reactor_index]"; + constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); + constructorCode.indent(); + } + var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); + + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederatedDecentralized( + portOnSelf+"_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};" + ) + ); + + var triggered = contained.reactionsTriggered(containedReactor, port); + //noinspection StatementWithEmptyBody + if (triggered.size() > 0) { + body.pr(port, "reaction_t* "+port.getName()+"_reactions["+triggered.size()+"];"); + var triggeredCount = 0; + for (Integer index : triggered) { + constructorCode.pr(port, portOnSelf+"_reactions["+triggeredCount+++"] = &self->_lf__reaction_"+index+";"); + } + constructorCode.pr(port, portOnSelf+"_trigger.reactions = "+portOnSelf+"_reactions;"); + } else { + // Since the self struct is created using calloc, there is no need to set + // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL + } + // Since the self struct is created using calloc, there is no need to set falsy fields. + constructorCode.pr(port, String.join("\n", + portOnSelf+"_trigger.last = NULL;", + portOnSelf+"_trigger.number_of_reactions = "+triggered.size()+";" + )); + + + // Set the physical_time_of_arrival + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederated( + portOnSelf+"_trigger.physical_time_of_arrival = NEVER;" + ) + ); + + if (containedReactor.getWidthSpec() != null) { + constructorCode.unindent(); + constructorCode.pr("}"); + } + } + } + body.unindent(); + body.pr(String.join("\n", + "} _lf_"+containedReactor.getName()+array+";", + "int _lf_"+containedReactor.getName()+"_width;" + )); } - } - body.unindent(); - body.pr( - String.join( - "\n", - "} _lf_" + containedReactor.getName() + array + ";", - "int _lf_" + containedReactor.getName() + "_width;")); } - } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the - * self struct - * - * @param body The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - protected void generateSelfStructExtension( - CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { - // Do nothing - } - - /** - * Generate reaction functions definition for a reactor. These functions have a single argument - * that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. - * - * @param r The reactor. - */ - public void generateReactions(CodeBuilder src, Reactor r) { - var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(r); - for (Reaction reaction : allReactions(reactor)) { - generateReaction(src, reaction, r, reactionIndex); - // Increment reaction index even if the reaction is not in the federate - // so that across federates, the reaction indices are consistent. - reactionIndex++; + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the self struct + * @param body The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + protected void generateSelfStructExtension( + CodeBuilder body, + ReactorDecl decl, + CodeBuilder constructorCode + ) { + // Do nothing + } + + /** Generate reaction functions definition for a reactor. + * These functions have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param r The reactor. + */ + public void generateReactions(CodeBuilder src, Reactor r) { + var reactionIndex = 0; + var reactor = ASTUtils.toDefinition(r); + for (Reaction reaction : allReactions(reactor)) { + generateReaction(src, reaction, r, reactionIndex); + // Increment reaction index even if the reaction is not in the federate + // so that across federates, the reaction indices are consistent. + reactionIndex++; + } } - } - - /** - * Generate a reaction function definition for a reactor. This function will have a single - * argument that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. - * - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - protected void generateReaction( - CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { - src.pr( - CReactionGenerator.generateReaction( + + /** Generate a reaction function definition for a reactor. + * This function will have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + src.pr(CReactionGenerator.generateReaction( reaction, r, reactionIndex, @@ -1386,726 +1407,693 @@ protected void generateReaction( errorReporter, types, targetConfig, - getTarget().requiresTypes)); - } - - /** - * Record startup, shutdown, and reset reactions. - * - * @param instance A reactor instance. - */ - private void recordBuiltinTriggers(ReactorInstance instance) { - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : instance.reactions) { - var reactor = reaction.getParent(); - var temp = new CodeBuilder(); - var foundOne = false; - - var reactionRef = CUtil.reactionRef(reaction); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.isStartup()) { - temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &" + reactionRef + ";"); - startupReactionCount += reactor.getTotalWidth(); - foundOne = true; - } else if (trigger.isShutdown()) { - temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &" + reactionRef + ";"); - foundOne = true; - shutdownReactionCount += reactor.getTotalWidth(); - - if (targetConfig.tracing != null) { - var description = CUtil.getShortenedName(reactor); - var reactorRef = CUtil.reactorRef(reactor); - temp.pr( - String.join( - "\n", - "_lf_register_trace_event(" - + reactorRef - + ", &(" - + reactorRef - + "->_lf__shutdown),", - "trace_trigger, " + addDoubleQuotes(description + ".shutdown") + ");")); - } - } else if (trigger.isReset()) { - temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &" + reactionRef + ";"); - resetReactionCount += reactor.getTotalWidth(); - foundOne = true; - } - } - if (foundOne) initializeTriggerObjects.pr(temp.toString()); + getTarget().requiresTypes + )); } - } - - /** - * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts - * and mark outputs absent between time steps. This function puts the code into startTimeStep. - */ - private void generateStartTimeStep(ReactorInstance instance) { - // Avoid generating dead code if nothing is relevant. - var foundOne = false; - var temp = new CodeBuilder(); - var containerSelfStructName = CUtil.reactorRef(instance); - - // Handle inputs that get sent data from a reaction rather than from - // another contained reactor and reactions that are triggered by an - // output of a contained reactor. - // Note that there may be more than one reaction reacting to the same - // port so we have to avoid listing the port more than once. - var portsSeen = new LinkedHashSet(); - for (ReactionInstance reaction : instance.reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - portsSeen.add(port); - // This reaction is sending to an input. Must be - // the input of a contained reactor in the federate. - // NOTE: If instance == main and the federate is within a bank, - // this assumes that the reaction writes only to the bank member in the federate. - foundOne = true; - - temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); - - if (!Objects.equal(port.getParent(), instance)) { - // The port belongs to contained reactor, so we also have - // iterate over the instance bank members. - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); - temp.startScopedBankChannelIteration(port, null); - } else { - temp.startScopedBankChannelIteration(port, "count"); - } - var portRef = CUtil.portRefNested(port); - var con = (port.isMultiport()) ? "->" : "."; - - temp.pr( - "_lf_is_present_fields[" - + startTimeStepIsPresentCount - + " + count] = &" - + portRef - + con - + "is_present;"); - // Intended_tag is only applicable to ports in federated execution. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "_lf_intended_tag_fields[" - + startTimeStepIsPresentCount - + " + count] = &" - + portRef - + con - + "intended_tag;")); - - startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); - - if (!Objects.equal(port.getParent(), instance)) { - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); - temp.endScopedBankChannelIteration(port, null); - } else { - temp.endScopedBankChannelIteration(port, "count"); - } + + /** + * Record startup, shutdown, and reset reactions. + * @param instance A reactor instance. + */ + private void recordBuiltinTriggers(ReactorInstance instance) { + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : instance.reactions) { + var reactor = reaction.getParent(); + var temp = new CodeBuilder(); + var foundOne = false; + + var reactionRef = CUtil.reactionRef(reaction); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.isStartup()) { + temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &"+reactionRef+";"); + startupReactionCount += reactor.getTotalWidth(); + foundOne = true; + } else if (trigger.isShutdown()) { + temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &"+reactionRef+";"); + foundOne = true; + shutdownReactionCount += reactor.getTotalWidth(); + + if (targetConfig.tracing != null) { + var description = CUtil.getShortenedName(reactor); + var reactorRef = CUtil.reactorRef(reactor); + temp.pr(String.join("\n", + "_lf_register_trace_event("+reactorRef+", &("+reactorRef+"->_lf__shutdown),", + "trace_trigger, "+addDoubleQuotes(description+".shutdown")+");" + )); + } + } else if (trigger.isReset()) { + temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &"+reactionRef+";"); + resetReactionCount += reactor.getTotalWidth(); + foundOne = true; + } + } + if (foundOne) initializeTriggerObjects.pr(temp.toString()); } - } } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; - - for (ActionInstance action : instance.actions) { - foundOne = true; - temp.startScopedBlock(instance); - - temp.pr( - String.join( - "\n", - "// Add action " + action.getFullName() + " to array of is_present fields.", - "_lf_is_present_fields[" + startTimeStepIsPresentCount + "] ", - " = &" - + containerSelfStructName - + "->_lf_" - + action.getName() - + ".is_present;")); - - // Intended_tag is only applicable to actions in federated execution with decentralized - // coordination. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join( - "\n", - "// Add action " + action.getFullName() + " to array of intended_tag fields.", - "_lf_intended_tag_fields[" + startTimeStepIsPresentCount + "] ", - " = &" - + containerSelfStructName - + "->_lf_" - + action.getName() - + ".intended_tag;"))); - - startTimeStepIsPresentCount += action.getParent().getTotalWidth(); - temp.endScopedBlock(); - } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; - - // Next, set up the table to mark each output of each contained reactor absent. - for (ReactorInstance child : instance.children) { - if (child.outputs.size() > 0) { - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(child); + /** + * Generate code to set up the tables used in _lf_start_time_step to decrement reference + * counts and mark outputs absent between time steps. This function puts the code + * into startTimeStep. + */ + private void generateStartTimeStep(ReactorInstance instance) { + // Avoid generating dead code if nothing is relevant. + var foundOne = false; + var temp = new CodeBuilder(); + var containerSelfStructName = CUtil.reactorRef(instance); + + // Handle inputs that get sent data from a reaction rather than from + // another contained reactor and reactions that are triggered by an + // output of a contained reactor. + // Note that there may be more than one reaction reacting to the same + // port so we have to avoid listing the port more than once. + var portsSeen = new LinkedHashSet(); + for (ReactionInstance reaction : instance.reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + portsSeen.add(port); + // This reaction is sending to an input. Must be + // the input of a contained reactor in the federate. + // NOTE: If instance == main and the federate is within a bank, + // this assumes that the reaction writes only to the bank member in the federate. + foundOne = true; + + temp.pr("// Add port "+port.getFullName()+" to array of is_present fields."); + + if (!Objects.equal(port.getParent(), instance)) { + // The port belongs to contained reactor, so we also have + // iterate over the instance bank members. + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(instance); + temp.startScopedBankChannelIteration(port, null); + } else { + temp.startScopedBankChannelIteration(port, "count"); + } + var portRef = CUtil.portRefNested(port); + var con = (port.isMultiport()) ? "->" : "."; + + temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"is_present;"); + // Intended_tag is only applicable to ports in federated execution. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"intended_tag;" + ) + ); + + startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); + + if (!Objects.equal(port.getParent(), instance)) { + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + temp.endScopedBankChannelIteration(port, null); + } else { + temp.endScopedBankChannelIteration(port, "count"); + } + } + } + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; - var channelCount = 0; - for (PortInstance output : child.outputs) { - if (!output.getDependsOnReactions().isEmpty()) { + for (ActionInstance action : instance.actions) { foundOne = true; - temp.pr("// Add port " + output.getFullName() + " to array of is_present fields."); - temp.startChannelIteration(output); - temp.pr( - "_lf_is_present_fields[" - + startTimeStepIsPresentCount - + " + count] = &" - + CUtil.portRef(output) - + ".is_present;"); - - // Intended_tag is only applicable to ports in federated execution with decentralized - // coordination. + temp.startScopedBlock(instance); + + temp.pr(String.join("\n", + "// Add action "+action.getFullName()+" to array of is_present fields.", + "_lf_is_present_fields["+startTimeStepIsPresentCount+"] ", + " = &"+containerSelfStructName+"->_lf_"+action.getName()+".is_present;" + )); + + // Intended_tag is only applicable to actions in federated execution with decentralized coordination. temp.pr( CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join( - "\n", - "// Add port " + output.getFullName() + " to array of intended_tag fields.", - "_lf_intended_tag_fields[" - + startTimeStepIsPresentCount - + " + count] = &" - + CUtil.portRef(output) - + ".intended_tag;"))); - - temp.pr("count++;"); - channelCount += output.getWidth(); - temp.endChannelIteration(output); - } + String.join("\n", + "// Add action " + action.getFullName() + + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + "] ", + " = &" + containerSelfStructName + + "->_lf_" + action.getName() + + ".intended_tag;" + ))); + + startTimeStepIsPresentCount += action.getParent().getTotalWidth(); + temp.endScopedBlock(); } - startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); - temp.endScopedBlock(); - temp.endScopedBlock(); - } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + + // Next, set up the table to mark each output of each contained reactor absent. + for (ReactorInstance child : instance.children) { + if (child.outputs.size() > 0) { + + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(child); + + var channelCount = 0; + for (PortInstance output : child.outputs) { + if (!output.getDependsOnReactions().isEmpty()){ + foundOne = true; + temp.pr("// Add port "+output.getFullName()+" to array of is_present fields."); + temp.startChannelIteration(output); + temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".is_present;"); + + // Intended_tag is only applicable to ports in federated execution with decentralized coordination. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + String.join("\n", + "// Add port "+output.getFullName()+" to array of intended_tag fields.", + "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".intended_tag;" + ))); + + temp.pr("count++;"); + channelCount += output.getWidth(); + temp.endChannelIteration(output); + } + } + startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); + temp.endScopedBlock(); + temp.endScopedBlock(); + } + } + if (foundOne) startTimeStep.pr(temp.toString()); } - if (foundOne) startTimeStep.pr(temp.toString()); - } - - /** - * For each timer in the given reactor, generate initialization code for the offset and period - * fields. - * - *

This method will also populate the global _lf_timer_triggers array, which is used to start - * all timers at the start of execution. - * - * @param instance A reactor instance. - */ - private void generateTimerInitializations(ReactorInstance instance) { - for (TimerInstance timer : instance.timers) { - if (!timer.isStartup()) { - initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); - timerCount += timer.getParent().getTotalWidth(); - } + + /** + * For each timer in the given reactor, generate initialization code for the offset + * and period fields. + * + * This method will also populate the global _lf_timer_triggers array, which is + * used to start all timers at the start of execution. + * + * @param instance A reactor instance. + */ + private void generateTimerInitializations(ReactorInstance instance) { + for (TimerInstance timer : instance.timers) { + if (!timer.isStartup()) { + initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); + timerCount += timer.getParent().getTotalWidth(); + } + } } - } - - /** - * Process a given .proto file. - * - *

Run, if possible, the proto-c protocol buffer code generator to produce the required .h and - * .c files. - * - * @param filename Name of the file to process. - */ - public void processProtoFile(String filename) { - var protoc = - commandFactory.createCommand( + + /** + * Process a given .proto file. + * + * Run, if possible, the proto-c protocol buffer code generator to produce + * the required .h and .c files. + * @param filename Name of the file to process. + */ + public void processProtoFile(String filename) { + var protoc = commandFactory.createCommand( "protoc-c", - List.of("--c_out=" + this.fileConfig.getSrcGenPath(), filename), + List.of("--c_out="+this.fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); - return; - } - var returnCode = protoc.run(); - if (returnCode == 0) { - var nameSansProto = filename.substring(0, filename.length() - 6); - targetConfig.compileAdditionalSources.add( - fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString()); - - targetConfig.compileLibraries.add("-l"); - targetConfig.compileLibraries.add("protobuf-c"); - targetConfig.compilerFlags.add("-lprotobuf-c"); - } else { - errorReporter.reportError("protoc-c returns error code " + returnCode); + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); + return; + } + var returnCode = protoc.run(); + if (returnCode == 0) { + var nameSansProto = filename.substring(0, filename.length() - 6); + targetConfig.compileAdditionalSources.add( + fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString() + ); + + targetConfig.compileLibraries.add("-l"); + targetConfig.compileLibraries.add("protobuf-c"); + targetConfig.compilerFlags.add("-lprotobuf-c"); + } else { + errorReporter.reportError("protoc-c returns error code " + returnCode); + } } - } - - /** - * Construct a unique type for the struct of the specified typed variable (port or action) of the - * specified reactor class. This is required to be the same as the type name returned by {@link - * #variableStructType(TriggerInstance)}. - */ - public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { - return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) - + "_" - + variable.getName() - + "_t"; - } - - /** - * Construct a unique type for the struct of the specified instance (port or action). This is - * required to be the same as the type name returned by {@link #variableStructType(Variable, - * Reactor, boolean)}. - * - * @param portOrAction The port or action instance. - * @return The name of the self struct. - */ - public static String variableStructType(TriggerInstance portOrAction) { - return CUtil.getName(portOrAction.getParent().reactorDefinition) - + "_" - + portOrAction.getName() - + "_t"; - } - - /** - * If tracing is turned on, then generate code that records the full name of the specified reactor - * instance in the trace table. If tracing is not turned on, do nothing. - * - * @param instance The reactor instance. - */ - private void generateTraceTableEntries(ReactorInstance instance) { - if (targetConfig.tracing != null) { - initializeTriggerObjects.pr(CTracingGenerator.generateTraceTableEntries(instance)); + + /** + * Construct a unique type for the struct of the specified + * typed variable (port or action) of the specified reactor class. + * This is required to be the same as the type name returned by + * {@link #variableStructType(TriggerInstance)}. + */ + public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { + return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) +"_"+variable.getName()+"_t"; } - } - - /** - * Generate code to instantiate the specified reactor instance and initialize it. - * - * @param instance A reactor instance. - */ - public void generateReactorInstance(ReactorInstance instance) { - var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); - var fullName = instance.getFullName(); - initializeTriggerObjects.pr( - "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); - // Generate the instance self struct containing parameters, state variables, - // and outputs (the "self" struct). - initializeTriggerObjects.pr( - CUtil.reactorRefName(instance) - + "[" - + CUtil.runtimeIndex(instance) - + "] = new_" - + CUtil.getName(reactorClass) - + "();"); - // Generate code to initialize the "self" struct in the - // _lf_initialize_trigger_objects function. - generateTraceTableEntries(instance); - generateReactorInstanceExtension(instance); - generateParameterInitialization(instance); - initializeOutputMultiports(instance); - initializeInputMultiports(instance); - recordBuiltinTriggers(instance); - watchdogCount += CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); - - // Next, initialize the "self" struct with state variables. - // These values may be expressions that refer to the parameter values defined above. - generateStateVariableInitializations(instance); - - // Generate trigger objects for the instance. - generateTimerInitializations(instance); - generateActionInitializations(instance); - generateInitializeActionToken(instance); - generateSetDeadline(instance); - generateModeStructure(instance); - - // Recursively generate code for the children. - for (ReactorInstance child : instance.children) { - // If this reactor is a placeholder for a bank of reactors, then generate - // an array of instances of reactors and create an enclosing for loop. - // Need to do this for each of the builders into which the code writes. - startTimeStep.startScopedBlock(child); - initializeTriggerObjects.startScopedBlock(child); - generateReactorInstance(child); - initializeTriggerObjects.endScopedBlock(); - startTimeStep.endScopedBlock(); + + /** + * Construct a unique type for the struct of the specified + * instance (port or action). + * This is required to be the same as the type name returned by + * {@link #variableStructType(Variable, Reactor, boolean)}. + * @param portOrAction The port or action instance. + * @return The name of the self struct. + */ + public static String variableStructType(TriggerInstance portOrAction) { + return CUtil.getName(portOrAction.getParent().reactorDefinition)+"_"+portOrAction.getName()+"_t"; } - // For this instance, define what must be done at the start of - // each time step. This sets up the tables that are used by the - // _lf_start_time_step() function in reactor_common.c. - // Note that this function is also run once at the end - // so that it can deallocate any memory. - generateStartTimeStep(instance); - initializeTriggerObjects.pr("//***** End initializing " + fullName); - } - - /** - * For each action of the specified reactor instance, generate initialization code for the offset - * and period fields. - * - * @param instance The reactor. - */ - private void generateActionInitializations(ReactorInstance instance) { - initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); - } - - /** - * Initialize actions by creating a lf_token_t in the self struct. This has the information - * required to allocate memory for the action payload. Skip any action that is not actually used - * as a trigger. - * - * @param reactor The reactor containing the actions. - */ - private void generateInitializeActionToken(ReactorInstance reactor) { - for (ActionInstance action : reactor.actions) { - // Skip this step if the action is not in use. - if (action.getParent().getTriggers().contains(action)) { - var type = getInferredType(action.getDefinition()); - var payloadSize = "0"; - if (!type.isUndefined()) { - var typeStr = types.getTargetType(type); - if (CUtil.isTokenType(type, types)) { - typeStr = CUtil.rootType(typeStr); - } - if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { - payloadSize = "sizeof(" + typeStr + ")"; - } + /** + * If tracing is turned on, then generate code that records + * the full name of the specified reactor instance in the + * trace table. If tracing is not turned on, do nothing. + * @param instance The reactor instance. + */ + private void generateTraceTableEntries(ReactorInstance instance) { + if (targetConfig.tracing != null) { + initializeTriggerObjects.pr( + CTracingGenerator.generateTraceTableEntries(instance) + ); } + } - var selfStruct = CUtil.reactorRef(action.getParent()); + /** + * Generate code to instantiate the specified reactor instance and + * initialize it. + * @param instance A reactor instance. + */ + public void generateReactorInstance(ReactorInstance instance) { + var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); + var fullName = instance.getFullName(); initializeTriggerObjects.pr( - CActionGenerator.generateTokenInitializer(selfStruct, action.getName(), payloadSize)); - } + "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); + // Generate the instance self struct containing parameters, state variables, + // and outputs (the "self" struct). + initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(reactorClass)+"();"); + // Generate code to initialize the "self" struct in the + // _lf_initialize_trigger_objects function. + generateTraceTableEntries(instance); + generateReactorInstanceExtension(instance); + generateParameterInitialization(instance); + initializeOutputMultiports(instance); + initializeInputMultiports(instance); + recordBuiltinTriggers(instance); + watchdogCount += CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); + + // Next, initialize the "self" struct with state variables. + // These values may be expressions that refer to the parameter values defined above. + generateStateVariableInitializations(instance); + + // Generate trigger objects for the instance. + generateTimerInitializations(instance); + generateActionInitializations(instance); + generateInitializeActionToken(instance); + generateSetDeadline(instance); + generateModeStructure(instance); + + // Recursively generate code for the children. + for (ReactorInstance child : instance.children) { + // If this reactor is a placeholder for a bank of reactors, then generate + // an array of instances of reactors and create an enclosing for loop. + // Need to do this for each of the builders into which the code writes. + startTimeStep.startScopedBlock(child); + initializeTriggerObjects.startScopedBlock(child); + generateReactorInstance(child); + initializeTriggerObjects.endScopedBlock(); + startTimeStep.endScopedBlock(); + } + + // For this instance, define what must be done at the start of + // each time step. This sets up the tables that are used by the + // _lf_start_time_step() function in reactor_common.c. + // Note that this function is also run once at the end + // so that it can deallocate any memory. + generateStartTimeStep(instance); + initializeTriggerObjects.pr("//***** End initializing " + fullName); } - } - - /** - * Generate code that is executed while the reactor instance is being initialized. This is - * provided as an extension point for subclasses. Normally, the reactions argument is the full - * list of reactions, but for the top-level of a federate, will be a subset of reactions that is - * relevant to the federate. - * - * @param instance The reactor instance. - */ - protected void generateReactorInstanceExtension(ReactorInstance instance) { - // Do nothing - } - - /** - * Generate code that initializes the state variables for a given instance. Unlike parameters, - * state variables are uniformly initialized for all instances of the same reactor. - * - * @param instance The reactor class instance - */ - protected void generateStateVariableInitializations(ReactorInstance instance) { - var reactorClass = instance.getDefinition().getReactorClass(); - var selfRef = CUtil.reactorRef(instance); - for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { - if (isInitialized(stateVar)) { - var mode = - stateVar.eContainer() instanceof Mode - ? instance.lookupModeInstance((Mode) stateVar.eContainer()) - : instance.getMode(false); - initializeTriggerObjects.pr( - CStateGenerator.generateInitializer(instance, selfRef, stateVar, mode, types)); - if (mode != null && stateVar.isReset()) { - modalStateResetCount += instance.getTotalWidth(); + + /** + * For each action of the specified reactor instance, generate initialization code + * for the offset and period fields. + * @param instance The reactor. + */ + private void generateActionInitializations(ReactorInstance instance) { + initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + } + + /** + * Initialize actions by creating a lf_token_t in the self struct. + * This has the information required to allocate memory for the action payload. + * Skip any action that is not actually used as a trigger. + * @param reactor The reactor containing the actions. + */ + private void generateInitializeActionToken(ReactorInstance reactor) { + for (ActionInstance action : reactor.actions) { + // Skip this step if the action is not in use. + if (action.getParent().getTriggers().contains(action) + ) { + var type = getInferredType(action.getDefinition()); + var payloadSize = "0"; + if (!type.isUndefined()) { + var typeStr = types.getTargetType(type); + if (CUtil.isTokenType(type, types)) { + typeStr = CUtil.rootType(typeStr); + } + if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { + payloadSize = "sizeof("+typeStr+")"; + } + } + + var selfStruct = CUtil.reactorRef(action.getParent()); + initializeTriggerObjects.pr( + CActionGenerator.generateTokenInitializer( + selfStruct, action.getName(), payloadSize + ) + ); + } } - } } - } - - /** - * Generate code to set the deadline field of the reactions in the specified reactor instance. - * - * @param instance The reactor instance. - */ - private void generateSetDeadline(ReactorInstance instance) { - for (ReactionInstance reaction : instance.reactions) { - var selfRef = CUtil.reactorRef(reaction.getParent()) + "->_lf__reaction_" + reaction.index; - if (reaction.declaredDeadline != null) { - var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr( - selfRef + ".deadline = " + types.getTargetTimeExpr(deadline) + ";"); - } else { // No deadline. - initializeTriggerObjects.pr(selfRef + ".deadline = NEVER;"); - } + + /** + * Generate code that is executed while the reactor instance is being initialized. + * This is provided as an extension point for subclasses. + * Normally, the reactions argument is the full list of reactions, + * but for the top-level of a federate, will be a subset of reactions that + * is relevant to the federate. + * @param instance The reactor instance. + */ + protected void generateReactorInstanceExtension(ReactorInstance instance) { + // Do nothing } - } - - /** - * Generate code to initialize modes. - * - * @param instance The reactor instance. - */ - private void generateModeStructure(ReactorInstance instance) { - CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); - if (!instance.modes.isEmpty()) { - modalReactorCount += instance.getTotalWidth(); + + /** + * Generate code that initializes the state variables for a given instance. + * Unlike parameters, state variables are uniformly initialized for all instances + * of the same reactor. + * @param instance The reactor class instance + */ + protected void generateStateVariableInitializations(ReactorInstance instance) { + var reactorClass = instance.getDefinition().getReactorClass(); + var selfRef = CUtil.reactorRef(instance); + for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { + if (isInitialized(stateVar)) { + var mode = stateVar.eContainer() instanceof Mode ? + instance.lookupModeInstance((Mode) stateVar.eContainer()) : + instance.getMode(false); + initializeTriggerObjects.pr(CStateGenerator.generateInitializer( + instance, + selfRef, + stateVar, + mode, + types + )); + if (mode != null && stateVar.isReset()) { + modalStateResetCount += instance.getTotalWidth(); + } + } + } } - } - - /** - * Generate runtime initialization code for parameters of a given reactor instance - * - * @param instance The reactor instance. - */ - protected void generateParameterInitialization(ReactorInstance instance) { - var selfRef = CUtil.reactorRef(instance); - // Set the local bank_index variable so that initializers can use it. - initializeTriggerObjects.pr( - "bank_index = " - + CUtil.bankIndex(instance) - + ";" - + " SUPPRESS_UNUSED_WARNING(bank_index);"); - for (ParameterInstance parameter : instance.parameters) { - // NOTE: we now use the resolved literal value. For better efficiency, we could - // store constants in a global array and refer to its elements to avoid duplicate - // memory allocations. - // NOTE: If the parameter is initialized with a static initializer for an array - // or struct (the initialization expression is surrounded by { ... }), then we - // have to declare a static variable to ensure that the memory is put in data space - // and not on the stack. - // FIXME: Is there a better way to determine this than the string comparison? - var initializer = CParameterGenerator.getInitializer(parameter); - if (initializer.startsWith("{")) { - var temporaryVariableName = parameter.uniqueID(); - initializeTriggerObjects.pr( - String.join( - "\n", - "static " - + types.getVariableDeclaration(parameter.type, temporaryVariableName, true) - + " = " - + initializer - + ";", - selfRef + "->" + parameter.getName() + " = " + temporaryVariableName + ";")); - } else { - initializeTriggerObjects.pr( - selfRef + "->" + parameter.getName() + " = " + initializer + ";"); - } + + /** + * Generate code to set the deadline field of the reactions in the + * specified reactor instance. + * @param instance The reactor instance. + */ + private void generateSetDeadline(ReactorInstance instance) { + for (ReactionInstance reaction : instance.reactions) { + var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; + if (reaction.declaredDeadline != null) { + var deadline = reaction.declaredDeadline.maxDelay; + initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); + } else { // No deadline. + initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); + } + } } - } - - /** - * Generate code that mallocs memory for any output multiports. - * - * @param reactor The reactor instance. - */ - private void initializeOutputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance output : reactor.outputs) { - initializeTriggerObjects.pr( - CPortGenerator.initializeOutputMultiport(output, reactorSelfStruct)); + + /** + * Generate code to initialize modes. + * @param instance The reactor instance. + */ + private void generateModeStructure(ReactorInstance instance) { + CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); + if (!instance.modes.isEmpty()) { + modalReactorCount += instance.getTotalWidth(); + } } - } - - /** - * Allocate memory for inputs. - * - * @param reactor The reactor. - */ - private void initializeInputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance input : reactor.inputs) { - initializeTriggerObjects.pr( - CPortGenerator.initializeInputMultiport(input, reactorSelfStruct)); + + /** + * Generate runtime initialization code for parameters of a given reactor instance + * @param instance The reactor instance. + */ + protected void generateParameterInitialization(ReactorInstance instance) { + var selfRef = CUtil.reactorRef(instance); + // Set the local bank_index variable so that initializers can use it. + initializeTriggerObjects.pr("bank_index = "+CUtil.bankIndex(instance)+";" + + " SUPPRESS_UNUSED_WARNING(bank_index);"); + for (ParameterInstance parameter : instance.parameters) { + // NOTE: we now use the resolved literal value. For better efficiency, we could + // store constants in a global array and refer to its elements to avoid duplicate + // memory allocations. + // NOTE: If the parameter is initialized with a static initializer for an array + // or struct (the initialization expression is surrounded by { ... }), then we + // have to declare a static variable to ensure that the memory is put in data space + // and not on the stack. + // FIXME: Is there a better way to determine this than the string comparison? + var initializer = CParameterGenerator.getInitializer(parameter); + if (initializer.startsWith("{")) { + var temporaryVariableName = parameter.uniqueID(); + initializeTriggerObjects.pr(String.join("\n", + "static "+types.getVariableDeclaration(parameter.type, temporaryVariableName, true)+" = "+initializer+";", + selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" + )); + } else { + initializeTriggerObjects.pr(selfRef+"->"+parameter.getName()+" = "+initializer+";"); + } + } } - } - - @Override - public TargetTypes getTargetTypes() { - return types; - } - - /** - * @param context - * @return - */ - protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new CDockerGenerator(context); - } - - // ////////////////////////////////////////// - // // Protected methods. - - // Perform set up that does not generate code - protected void setUpGeneralParameters() { - accommodatePhysicalActionsIfPresent(); - targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); - targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); - // Create the main reactor instance if there is a main reactor. - createMainReactorInstance(); - if (hasModalReactors) { - // So that each separate compile knows about modal reactors, do this: - targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); + + /** + * Generate code that mallocs memory for any output multiports. + * @param reactor The reactor instance. + */ + private void initializeOutputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance output : reactor.outputs) { + initializeTriggerObjects.pr(CPortGenerator.initializeOutputMultiport( + output, + reactorSelfStruct + )); + } } - if (targetConfig.threading - && targetConfig.platformOptions.platform == Platform.ARDUINO - && (targetConfig.platformOptions.board == null - || !targetConfig.platformOptions.board.contains("mbed"))) { - // non-MBED boards should not use threading - System.out.println( - "Threading is incompatible on your current Arduino flavor. Setting threading to false."); - targetConfig.threading = false; + + /** + * Allocate memory for inputs. + * @param reactor The reactor. + */ + private void initializeInputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance input : reactor.inputs) { + initializeTriggerObjects.pr(CPortGenerator.initializeInputMultiport( + input, + reactorSelfStruct + )); + } } - if (targetConfig.platformOptions.platform == Platform.ARDUINO - && !targetConfig.noCompile - && targetConfig.platformOptions.board == null) { - System.out.println( - "To enable compilation for the Arduino platform, you must specify the fully-qualified" - + " board name (FQBN) in the target property. For example, platform: {name: arduino," - + " board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target" - + " code only."); - targetConfig.noCompile = true; + @Override + public TargetTypes getTargetTypes() { + return types; } - if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake - pickScheduler(); - // FIXME: this and pickScheduler should be combined. - targetConfig.compileDefinitions.put("SCHEDULER", targetConfig.schedulerType.name()); - targetConfig.compileDefinitions.put( - "NUMBER_OF_WORKERS", String.valueOf(targetConfig.workers)); + + /** + * Get the Docker generator. + * @param context + * @return + */ + protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new CDockerGenerator(context); } - pickCompilePlatform(); - } - protected void handleProtoFiles() { - // Handle .proto files. - for (String file : targetConfig.protoFiles) { - this.processProtoFile(file); + // ////////////////////////////////////////// + // // Protected methods. + + // Perform set up that does not generate code + protected void setUpGeneralParameters() { + accommodatePhysicalActionsIfPresent(); + targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); + // Create the main reactor instance if there is a main reactor. + createMainReactorInstance(); + if (hasModalReactors) { + // So that each separate compile knows about modal reactors, do this: + targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); + } + if (targetConfig.threading && targetConfig.platformOptions.platform == Platform.ARDUINO + && (targetConfig.platformOptions.board == null || !targetConfig.platformOptions.board.contains("mbed"))) { + //non-MBED boards should not use threading + System.out.println("Threading is incompatible on your current Arduino flavor. Setting threading to false."); + targetConfig.threading = false; + } + + if (targetConfig.platformOptions.platform == Platform.ARDUINO && !targetConfig.noCompile + && targetConfig.platformOptions.board == null) { + System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); + targetConfig.noCompile = true; + } + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake + pickScheduler(); + // FIXME: this and pickScheduler should be combined. + targetConfig.compileDefinitions.put( + "SCHEDULER", + targetConfig.schedulerType.name() + ); + targetConfig.compileDefinitions.put( + "NUMBER_OF_WORKERS", + String.valueOf(targetConfig.workers) + ); + } + pickCompilePlatform(); } - } - - /** - * Generate code that needs to appear at the top of the generated C file, such as #define and - * #include statements. - */ - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr( - CPreambleGenerator.generateDefineDirectives( - targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); - code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); - return code.toString(); - } - - /** Generate top-level preamble code. */ - protected String generateTopLevelPreambles(Reactor reactor) { - CodeBuilder builder = new CodeBuilder(); - var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; - builder.pr("#ifndef " + guard); - builder.pr("#define " + guard); - Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) - .flatMap(it -> ((Model) it.eContainer()).getPreambles().stream()) - .collect(Collectors.toSet()) - .forEach(it -> builder.pr(toText(it.getCode()))); - for (String file : targetConfig.protoFiles) { - var dotIndex = file.lastIndexOf("."); - var rootFilename = file; - if (dotIndex > 0) { - rootFilename = file.substring(0, dotIndex); - } - code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + + protected void handleProtoFiles() { + // Handle .proto files. + for (String file : targetConfig.protoFiles) { + this.processProtoFile(file); + } } - builder.pr("#endif"); - return builder.toString(); - } - - protected boolean targetLanguageIsCpp() { - return CCppMode; - } - - /** - * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if - * the line is recognized as the first line of an error message. Otherwise, return null. - * - * @param line A line of output from a compiler or other external tool that might generate errors. - * @return If the line is recognized as the start of an error message, then return a class - * containing the path to the file on which the error occurred (or null if there is none), the - * line number (or the string "1" if there is none), the character position (or the string "0" - * if there is none), and the message (or an empty string if there is none). - */ - @Override - public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { - var matcher = compileErrorPattern.matcher(line); - if (matcher.find()) { - var result = new ErrorFileAndLine(); - result.filepath = matcher.group("path"); - result.line = matcher.group("line"); - result.character = matcher.group("column"); - result.message = matcher.group("message"); - - if (!result.message.toLowerCase().contains("error:")) { - result.isError = false; - } - return result; + + /** + * Generate code that needs to appear at the top of the generated + * C file, such as #define and #include statements. + */ + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr(CPreambleGenerator.generateDefineDirectives( + targetConfig, + fileConfig.getSrcGenPath(), + hasModalReactors + )); + code.pr(CPreambleGenerator.generateIncludeStatements( + targetConfig, + CCppMode + )); + return code.toString(); } - return null; - } - - //////////////////////////////////////////// - //// Private methods. - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.C; - } - - //////////////////////////////////////////////////////////// - //// Private methods - - /** - * If a main or federated reactor has been declared, create a ReactorInstance for this top level. - * This will also assign levels to reactions, then, if the program is federated, perform an AST - * transformation to disconnect connections between federates. - */ - private void createMainReactorInstance() { - if (this.mainDef != null) { - if (this.main == null) { - // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); - var reactionInstanceGraph = this.main.assignLevels(); - if (reactionInstanceGraph.nodeCount() > 0) { - errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); - return; + + /** + * Generate top-level preamble code. + */ + protected String generateTopLevelPreambles(Reactor reactor) { + CodeBuilder builder = new CodeBuilder(); + var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; + builder.pr("#ifndef " + guard); + builder.pr("#define " + guard); + Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) + .flatMap(it -> ((Model) it.eContainer()).getPreambles().stream()) + .collect(Collectors.toSet()) + .forEach(it -> builder.pr(toText(it.getCode()))); + for (String file : targetConfig.protoFiles) { + var dotIndex = file.lastIndexOf("."); + var rootFilename = file; + if (dotIndex > 0) { + rootFilename = file.substring(0, dotIndex); + } + code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); } - if (hasDeadlines) { - this.main.assignDeadlines(); + builder.pr("#endif"); + return builder.toString(); + } + + protected boolean targetLanguageIsCpp() { + return CCppMode; + } + + /** Given a line of text from the output of a compiler, return + * an instance of ErrorFileAndLine if the line is recognized as + * the first line of an error message. Otherwise, return null. + * @param line A line of output from a compiler or other external + * tool that might generate errors. + * @return If the line is recognized as the start of an error message, + * then return a class containing the path to the file on which the + * error occurred (or null if there is none), the line number (or the + * string "1" if there is none), the character position (or the string + * "0" if there is none), and the message (or an empty string if there + * is none). + */ + @Override + public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + var matcher = compileErrorPattern.matcher(line); + if (matcher.find()) { + var result = new ErrorFileAndLine(); + result.filepath = matcher.group("path"); + result.line = matcher.group("line"); + result.character = matcher.group("column"); + result.message = matcher.group("message"); + + if (!result.message.toLowerCase().contains("error:")) { + result.isError = false; + } + return result; } - // Inform the run-time of the breadth/parallelism of the reaction graph - var breadth = reactionInstanceGraph.getBreadth(); - if (breadth == 0) { - errorReporter.reportWarning("The program has no reactions"); - } else { - targetConfig.compileDefinitions.put( - "LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())); + return null; + } + + //////////////////////////////////////////// + //// Private methods. + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.C; + } + + //////////////////////////////////////////////////////////// + //// Private methods + + /** + * If a main or federated reactor has been declared, create a ReactorInstance + * for this top level. This will also assign levels to reactions, then, + * if the program is federated, perform an AST transformation to disconnect + * connections between federates. + */ + private void createMainReactorInstance() { + if (this.mainDef != null) { + if (this.main == null) { + // Recursively build instances. + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + var reactionInstanceGraph = this.main.assignLevels(); + if (reactionInstanceGraph.nodeCount() > 0) { + errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); + return; + } + if (hasDeadlines) { + this.main.assignDeadlines(); + } + // Inform the run-time of the breadth/parallelism of the reaction graph + var breadth = reactionInstanceGraph.getBreadth(); + if (breadth == 0) { + errorReporter.reportWarning("The program has no reactions"); + } else { + targetConfig.compileDefinitions.put( + "LF_REACTION_GRAPH_BREADTH", + String.valueOf(reactionInstanceGraph.getBreadth()) + ); + } + } } - } } - } - - /** - * Generate an array of self structs for the reactor and one for each of its children. - * - * @param r The reactor instance. - */ - private void generateSelfStructs(ReactorInstance r) { - initializeTriggerObjects.pr( - CUtil.selfType(r) + "* " + CUtil.reactorRefName(r) + "[" + r.getTotalWidth() + "];"); - initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING(" + CUtil.reactorRefName(r) + ");"); - for (ReactorInstance child : r.children) { - generateSelfStructs(child); + + /** + * Generate an array of self structs for the reactor + * and one for each of its children. + * @param r The reactor instance. + */ + private void generateSelfStructs(ReactorInstance r) { + initializeTriggerObjects.pr(CUtil.selfType(r)+"* "+CUtil.reactorRefName(r)+"["+r.getTotalWidth()+"];"); + initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING("+CUtil.reactorRefName(r)+");"); + for (ReactorInstance child : r.children) { + generateSelfStructs(child); + } } - } } From 11ccfad20c2e7fcd150de800e8e1e29d466b6843 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 07:43:05 +0200 Subject: [PATCH 216/709] Removed the advice to run the formatter --- CONTRIBUTING.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 13d24c957c..55716f5b17 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,8 +25,7 @@ Test categories are declared in the [TestCategory enum in TestRegistry.java](htt ### Workflow All code contributions must go through a pull request (PR), pass all tests run in CI, and get an approving review before it is merged. Pushing to the `master` branch is restricted. All code review is conducted using the Github review system on PRs. Before requesting a code review, ensure that you have: -- applied the [code formatter](#code-style-and-formatting); -- [documented](#code-style-and-formatting) your code; +- documented your code; - written [tests](#writing-tests) that cover your code; and - accompanied any remaining `TODO`s or `FIXME`s with a link to an active [issue](#reporting-issues). @@ -73,18 +72,6 @@ Perform merges to bring your feature branch up-to-date with master locally (do n #### Addressing reviews To address feedback from code review, implement changes and push to your feature branch. If you are certain that a reviewer's concern has been addressed by your new changes, hit the `Resolve conversation` button. If you are unsure, ask for follow up in the conversation and let the reviewer determine whether the feedback was addressed accordingly. -### Code style and formatting -The Lingua Franca compiler is implemented in Java and Kotlin. The overarching advice is to use each language's most widely used idioms and conventions, which are fortunately very similar. The code base is shipped with a [Spotless](https://github.com/diffplug/spotless) configuration to check and enforce style compliance. Lingua Franca code (e.g., tests) in this repository is also automatically formatted via Spotless. - -- To check that modified files are formatted correctly, run: -``` -./gradlew spotlessCheck -``` -- To apply the changes recommended by the formatter, run: -``` -./gradlew spotlessApply -``` - #### General guidelines - _Do not copy-paste code._ If you want to reuse code, factor it out into a method and call it. - _Keep methods concise._ As a rule of thumb, a method should fit on your screen so that it can be read without scrolling. We impose no hard limit on method length, but anything above 40 lines should be considered for breaking up. From e3d967bc1daf29089aa8a4ab7234c57cd0dc1945 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 08:28:41 +0200 Subject: [PATCH 217/709] Merge single file with master --- org.lflang/src/org/lflang/TargetProperty.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 1bacb1f75e..61cda14431 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -276,16 +276,16 @@ public enum TargetProperty { * processed by the code generator. */ FILES("files", UnionType.FILE_OR_FILE_ARRAY, List.of(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.fileNames), + (config) -> ASTUtils.toElement(config.files), (config, value, err) -> { - config.fileNames = ASTUtils.elementToListOfStrings(value); + config.files = ASTUtils.elementToListOfStrings(value); }, // FIXME: This merging of lists is potentially dangerous since // the incoming list of files can belong to a .lf file that is // located in a different location, and keeping just filename // strings like this without absolute paths is incorrect. (config, value, err) -> { - config.fileNames.addAll(ASTUtils.elementToListOfStrings(value)); + config.files.addAll(ASTUtils.elementToListOfStrings(value)); }), /** From eae9ebda5927974068e1641ad93d4a7642b21b37 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 08:29:20 +0200 Subject: [PATCH 218/709] Merge single file with master --- .../federated/generator/FedFileConfig.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index 42f5c60dc7..e434501825 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -110,7 +111,7 @@ public void doClean() throws IOException { */ public void relativizePaths(FedTargetConfig targetConfig) { relativizePathList(targetConfig.protoFiles); - relativizePathList(targetConfig.fileNames); + relativizePathList(targetConfig.files); relativizePathList(targetConfig.cmakeIncludes); } @@ -120,17 +121,22 @@ public void relativizePaths(FedTargetConfig targetConfig) { */ private void relativizePathList(List paths) { List tempList = new ArrayList<>(); - paths.forEach(f -> tempList.add(relativizePath(f))); + paths.forEach(f -> tempList.add(relativizePath(Paths.get(f)))); paths.clear(); paths.addAll(tempList); } /** - * Relativize a single path. + * Relativize a single path, but only if it points to a local resource in the project (i.e., not + * on the class path). * @param path The path to relativize. */ - private String relativizePath(String path) { - Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); - return this.getSrcPath().relativize(resolvedPath).toString(); + private String relativizePath(Path path) { + if (FileUtil.findInPackage(path, this) == null) { + return String.valueOf(path); + } else { + Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); + return this.getSrcPath().relativize(resolvedPath).toString(); + } } } From 92ce015a0f99c4768bca01f27cdcbce27aae149a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 08:29:55 +0200 Subject: [PATCH 219/709] Merge single file with master --- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 3f5eb4a5b7..d158f7491b 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -25,6 +25,7 @@ package org.lflang.generator.c; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -313,8 +314,8 @@ CodeBuilder generateCMakeCode( cMakeCode.newLine(); // Add the include file - for (String includeFile : targetConfig.cmakeIncludesWithoutPath) { - cMakeCode.pr("include(\""+includeFile+"\")"); + for (String includeFile : targetConfig.cmakeIncludes) { + cMakeCode.pr("include(\""+ Path.of(includeFile).getFileName()+"\")"); } cMakeCode.newLine(); From a4365c867db012be21fab28336231195846ed246 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 08:30:36 +0200 Subject: [PATCH 220/709] Remove use of Google Objects class --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 7bc579ac0f..590cdb167c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -398,7 +398,7 @@ public void accommodatePhysicalActionsIfPresent() { // keepalive is set to true, unless the user has explicitly set it to false. for (Resource resource : GeneratorUtils.getResources(reactors)) { for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { - if (Objects.equal(action.getOrigin(), ActionOrigin.PHYSICAL)) { + if (ActionOrigin.PHYSICAL.equals(action.getOrigin())) { // If the unthreaded runtime is not requested by the user, use the threaded runtime instead // because it is the only one currently capable of handling asynchronous events. if (!targetConfig.threading && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { @@ -1484,7 +1484,7 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("// Add port "+port.getFullName()+" to array of is_present fields."); - if (!Objects.equal(port.getParent(), instance)) { + if (!instance.equals(port.getParent())) { // The port belongs to contained reactor, so we also have // iterate over the instance bank members. temp.startScopedBlock(); @@ -1507,7 +1507,7 @@ private void generateStartTimeStep(ReactorInstance instance) { startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); - if (!Objects.equal(port.getParent(), instance)) { + if (!instance.equals(port.getParent())) { temp.pr("count++;"); temp.endScopedBlock(); temp.endScopedBlock(); From e71ffdf9bc350781777aba85b193f4dc15e79c57 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 08:45:20 +0200 Subject: [PATCH 221/709] Restored accidentally removed watchdog line --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 590cdb167c..b7ce5ff1fb 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1208,6 +1208,9 @@ private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuild types ); + // Generate the fields needed for each watchdog. + CWatchdogGenerator.generateWatchdogStruct(body, decl, constructorCode); + // Next, generate fields for modes CModesGenerator.generateDeclarations(reactor, body, constructorCode); From 45f728620d6930515c874ed19bbec4b4c69904eb Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 08:50:17 +0200 Subject: [PATCH 222/709] Merge single file with master --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 274bffab2c..3ccd9f3a7f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/lf-lang/reactor-c-py.git [submodule "org.lflang/src/lib/cpp/reactor-cpp"] path = org.lflang/src/lib/cpp/reactor-cpp - url = https://github.com/lf-lang/reactor-cpp.git + url = https://github.com/lf-lang/reactor-cpp [submodule "org.lflang/src/lib/rs/reactor-rs"] path = org.lflang/src/lib/rs/reactor-rs - url = https://github.com/lf-lang/reactor-rs.git + url = https://github.com/lf-lang/reactor-rs From 442f80869c7d7f486aa2be52e8addb211573f694 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 09:06:15 +0200 Subject: [PATCH 223/709] Restored file to unformatted version --- .../federated/generator/FederateInstance.java | 1127 +++++++++-------- 1 file changed, 587 insertions(+), 540 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 349ff0fff7..7ca5a19bca 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -1,31 +1,31 @@ -/** - * Instance of a federate specification. - * - *

Copyright (c) 2020, The University of California at Berkeley. - * - *

Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - *

1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. +/** Instance of a federate specification. * - *

2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - *

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ************* - */ +Copyright (c) 2020, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ + package org.lflang.federated.generator; -import com.google.common.base.Objects; +import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -35,16 +35,22 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; + import org.eclipse.emf.ecore.EObject; + import org.lflang.ASTUtils; import org.lflang.ErrorReporter; +import org.lflang.FileConfig; +import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TimeValue; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.ActionInstance; +import org.lflang.generator.GeneratorUtils; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.SubContext; import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -65,557 +71,598 @@ import org.lflang.lf.VarRef; import org.lflang.lf.Variable; +import com.google.common.base.Objects; + + /** - * Instance of a federate, or marker that no federation has been defined (if isSingleton() returns - * true) FIXME: this comment makes no sense. Every top-level reactor (contained directly by the main - * reactor) is a federate, so there will be one instance of this class for each top-level reactor. + * Instance of a federate, or marker that no federation has been defined + * (if isSingleton() returns true) FIXME: this comment makes no sense. + * Every top-level reactor (contained + * directly by the main reactor) is a federate, so there will be one + * instance of this class for each top-level reactor. * * @author Edward A. Lee * @author Soroush Bateni */ public class FederateInstance { // why does this not extend ReactorInstance? - /** - * Construct a new instance with the specified instantiation of of a top-level reactor. The - * federate will be given the specified integer ID. - * - * @param instantiation The instantiation of a top-level reactor, or null if no federation has - * been defined. - * @param id The federate ID. - * @param bankIndex If instantiation.widthSpec !== null, this gives the bank position. - * @param errorReporter The error reporter - */ - public FederateInstance( - Instantiation instantiation, - int id, - int bankIndex, - TargetConfig targetConfig, - ErrorReporter errorReporter) { - this.instantiation = instantiation; - this.id = id; - this.bankIndex = bankIndex; - this.errorReporter = errorReporter; - this.targetConfig = targetConfig; - - if (instantiation != null) { - this.name = instantiation.getName(); - // If the instantiation is in a bank, then we have to append - // the bank index to the name. - if (instantiation.getWidthSpec() != null) { - this.name = instantiation.getName() + "__" + bankIndex; - } - } - } - - ///////////////////////////////////////////// - //// Public Fields - - /** - * The position within a bank of reactors for this federate. This is 0 if the instantiation is not - * a bank of reactors. - */ - public int bankIndex = 0; - - /** A list of outputs that can be triggered directly or indirectly by physical actions. */ - public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); - - /** The host, if specified using the 'at' keyword. */ - public String host = "localhost"; - - /** The instantiation of the top-level reactor, or null if there is no federation. */ - public Instantiation instantiation; - - public Instantiation getInstantiation() { - return instantiation; - } - - /** A list of individual connections between federates */ - public Set connections = new HashSet<>(); - - /** - * Map from the federates that this federate receives messages from to the delays on connections - * from that federate. The delay set may include null, meaning that there is a connection from the - * federate instance that has no delay. - */ - public Map> dependsOn = new LinkedHashMap<>(); - - /** The directory, if specified using the 'at' keyword. */ - public String dir = null; - - /** The port, if specified using the 'at' keyword. */ - public int port = 0; - - /** - * Map from the federates that this federate sends messages to to the delays on connections to - * that federate. The delay set may may include null, meaning that there is a connection from the - * federate instance that has no delay. - */ - public Map> sendsTo = new LinkedHashMap<>(); - - /** The user, if specified using the 'at' keyword. */ - public String user = null; - - /** The integer ID of this federate. */ - public int id = 0; - - /** - * The name of this federate instance. This will be the instantiation name, possibly appended with - * "__n", where n is the bank position of this instance if the instantiation is of a bank of - * reactors. - */ - public String name = "Unnamed"; - - /** - * List of networkMessage actions. Each of these handles a message received from another federate - * over the network. The ID of receiving port is simply the position of the action in the list. - * The sending federate needs to specify this ID. - */ - public List networkMessageActions = new ArrayList<>(); - - /** - * A set of federates with which this federate has an inbound connection There will only be one - * physical connection even if federate A has defined multiple physical connections to federate B. - * The message handler on federate A will be responsible for including the appropriate information - * in the message header (such as port ID) to help the receiver distinguish different events. - */ - public Set inboundP2PConnections = new LinkedHashSet<>(); - - /** - * A list of federate with which this federate has an outbound physical connection. There will - * only be one physical connection even if federate A has defined multiple physical connections to - * federate B. The message handler on federate B will be responsible for distinguishing the - * incoming messages by parsing their header and scheduling the appropriate action. - */ - public Set outboundP2PConnections = new LinkedHashSet<>(); - - /** - * A list of triggers for network input control reactions. This is used to trigger all the input - * network control reactions that might be nested in a hierarchy. - */ - public List networkInputControlReactionsTriggers = new ArrayList<>(); - - /** - * The trigger that triggers the output control reaction of this federate. - * - *

The network output control reactions send a PORT_ABSENT message for a network output port, - * if it is absent at the current tag, to notify all downstream federates that no value will be - * present on the given network port, allowing input control reactions on those federates to stop - * blocking. - */ - public Variable networkOutputControlReactionsTrigger = null; - - /** Indicates whether the federate is remote or local */ - public boolean isRemote = false; - - /** - * List of generated network reactions (network receivers, network input control reactions, - * network senders, and network output control reactions) that belong to this federate instance. - */ - public List networkReactions = new ArrayList<>(); - - /** Parsed target config of the federate. */ - public TargetConfig targetConfig; - - /** Keep a unique list of enabled serializers */ - public HashSet enabledSerializers = new HashSet<>(); - - /** - * Return true if the specified EObject should be included in the code generated for this - * federate. - * - * @param object An {@code EObject} - * @return True if this federate contains the EObject. - */ - public boolean contains(EObject object) { - if (object instanceof Action) { - return contains((Action) object); - } else if (object instanceof Reaction) { - return contains((Reaction) object); - } else if (object instanceof Timer) { - return contains((Timer) object); - } else if (object instanceof ReactorDecl) { - return contains(this.instantiation, (ReactorDecl) object); - } else if (object instanceof Import) { - return contains((Import) object); - } else if (object instanceof Parameter) { - return contains((Parameter) object); - } else if (object instanceof StateVar) { - return true; // FIXME: Should we disallow state vars at the top level? - } - throw new UnsupportedOperationException( - "EObject class " + object.eClass().getName() + " not supported."); - } - - /** - * Return true if the specified reactor belongs to this federate. - * - * @param instantiation The instantiation to look inside - * @param reactor The reactor declaration to find - */ - private boolean contains(Instantiation instantiation, ReactorDecl reactor) { - if (instantiation.getReactorClass().equals(ASTUtils.toDefinition(reactor))) { - return true; + /** + * Construct a new instance with the specified instantiation of + * of a top-level reactor. The federate will be given the specified + * integer ID. + * @param instantiation The instantiation of a top-level reactor, + * or null if no federation has been defined. + * @param id The federate ID. + * @param bankIndex If instantiation.widthSpec !== null, this gives the bank position. + * @param errorReporter The error reporter + */ + public FederateInstance( + Instantiation instantiation, + int id, + int bankIndex, + TargetConfig targetConfig, + ErrorReporter errorReporter) { + this.instantiation = instantiation; + this.id = id; + this.bankIndex = bankIndex; + this.errorReporter = errorReporter; + this.targetConfig = targetConfig; + + if (instantiation != null) { + this.name = instantiation.getName(); + // If the instantiation is in a bank, then we have to append + // the bank index to the name. + if (instantiation.getWidthSpec() != null) { + this.name = instantiation.getName() + "__" + bankIndex; + } + } } - boolean instantiationsCheck = false; - // For a federate, we don't need to look inside imported reactors. - if (instantiation.getReactorClass() instanceof Reactor reactorDef) { - for (Instantiation child : reactorDef.getInstantiations()) { - instantiationsCheck |= contains(child, reactor); - } + ///////////////////////////////////////////// + //// Public Fields + + /** + * The position within a bank of reactors for this federate. + * This is 0 if the instantiation is not a bank of reactors. + */ + public int bankIndex = 0; + + /** + * A list of outputs that can be triggered directly or indirectly by physical actions. + */ + public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); + + /** + * The host, if specified using the 'at' keyword. + */ + public String host = "localhost"; + + + /** + * The instantiation of the top-level reactor, or null if there is no federation. + */ + public Instantiation instantiation; + public Instantiation getInstantiation() { + return instantiation; } - return instantiationsCheck; - } - - /** - * Return true if the specified import should be included in the code generated for this federate. - * - * @param imp The import - */ - private boolean contains(Import imp) { - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (contains(reactor)) { - return true; - } - } - return false; - } - - /** - * Return true if the specified parameter should be included in the code generated for this - * federate. - * - * @param param The parameter - */ - private boolean contains(Parameter param) { - boolean returnValue = false; - // Check if param is referenced in this federate's instantiation - returnValue = - instantiation.getParameters().stream() - .anyMatch( - assignment -> - assignment.getRhs().getExprs().stream() - .filter(it -> it instanceof ParameterReference) - .map(it -> ((ParameterReference) it).getParameter()) - .toList() - .contains(param)); - // If there are any user-defined top-level reactions, they could access - // the parameters, so we need to include the parameter. - var topLevelUserDefinedReactions = - ((Reactor) instantiation.eContainer()) - .getReactions().stream() - .filter(r -> !networkReactions.contains(r) && contains(r)) - .collect(Collectors.toCollection(ArrayList::new)); - returnValue |= !topLevelUserDefinedReactions.isEmpty(); - return returnValue; - } - - /** - * Return true if the specified action should be included in the code generated for this federate. - * This means that either the action is used as a trigger, a source, or an effect in a top-level - * reaction that belongs to this federate. This returns true if the program is not federated. - * - * @param action The action - * @return True if this federate contains the action. - */ - private boolean contains(Action action) { - Reactor reactor = ASTUtils.getEnclosingReactor(action); - - // If the action is used as a trigger, a source, or an effect for a top-level reaction - // that belongs to this federate, then generate it. - for (Reaction react : ASTUtils.allReactions(reactor)) { - if (contains(react)) { - // Look in triggers - for (TriggerRef trigger : convertToEmptyListIfNull(react.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (Objects.equal(triggerAsVarRef.getVariable(), action)) { - return true; - } - } + /** + * A list of individual connections between federates + */ + public Set connections = new HashSet<>(); + + /** + * Map from the federates that this federate receives messages from + * to the delays on connections from that federate. The delay set + * may include null, meaning that there is a connection + * from the federate instance that has no delay. + */ + public Map> dependsOn = new LinkedHashMap<>(); + + /** + * The directory, if specified using the 'at' keyword. + */ + public String dir = null; + + /** + * The port, if specified using the 'at' keyword. + */ + public int port = 0; + + /** + * Map from the federates that this federate sends messages to + * to the delays on connections to that federate. The delay set + * may may include null, meaning that there is a connection + * from the federate instance that has no delay. + */ + public Map> sendsTo = new LinkedHashMap<>(); + + /** + * The user, if specified using the 'at' keyword. + */ + public String user = null; + + /** + * The integer ID of this federate. + */ + public int id = 0; + + + /** + * The name of this federate instance. This will be the instantiation + * name, possibly appended with "__n", where n is the bank position of + * this instance if the instantiation is of a bank of reactors. + */ + public String name = "Unnamed"; + + /** + * List of networkMessage actions. Each of these handles a message + * received from another federate over the network. The ID of + * receiving port is simply the position of the action in the list. + * The sending federate needs to specify this ID. + */ + public List networkMessageActions = new ArrayList<>(); + + /** + * A set of federates with which this federate has an inbound connection + * There will only be one physical connection even if federate A has defined multiple + * physical connections to federate B. The message handler on federate A will be + * responsible for including the appropriate information in the message header (such as port ID) + * to help the receiver distinguish different events. + */ + public Set inboundP2PConnections = new LinkedHashSet<>(); + + /** + * A list of federate with which this federate has an outbound physical connection. + * There will only be one physical connection even if federate A has defined multiple + * physical connections to federate B. The message handler on federate B will be + * responsible for distinguishing the incoming messages by parsing their header and + * scheduling the appropriate action. + */ + public Set outboundP2PConnections = new LinkedHashSet<>(); + + /** + * A list of triggers for network input control reactions. This is used to trigger + * all the input network control reactions that might be nested in a hierarchy. + */ + public List networkInputControlReactionsTriggers = new ArrayList<>(); + + /** + * The trigger that triggers the output control reaction of this + * federate. + * + * The network output control reactions send a PORT_ABSENT message for a network output port, + * if it is absent at the current tag, to notify all downstream federates that no value will + * be present on the given network port, allowing input control reactions on those federates + * to stop blocking. + */ + public Variable networkOutputControlReactionsTrigger = null; + + /** + * Indicates whether the federate is remote or local + */ + public boolean isRemote = false; + + /** + * List of generated network reactions (network receivers, + * network input control reactions, network senders, and network output control + * reactions) that belong to this federate instance. + */ + public List networkReactions = new ArrayList<>(); + + /** + * Parsed target config of the federate. + */ + public TargetConfig targetConfig; + + /** + * Keep a unique list of enabled serializers + */ + public HashSet enabledSerializers = new HashSet<>(); + + /** + * Return true if the specified EObject should be included in the code + * generated for this federate. + * + * @param object An {@code EObject} + * @return True if this federate contains the EObject. + */ + public boolean contains(EObject object) { + if (object instanceof Action) { + return contains((Action)object); + } else if (object instanceof Reaction) { + return contains((Reaction)object); + } else if (object instanceof Timer) { + return contains((Timer)object); + } else if (object instanceof ReactorDecl) { + return contains(this.instantiation, (ReactorDecl)object); + } else if (object instanceof Import) { + return contains((Import)object); + } else if (object instanceof Parameter) { + return contains((Parameter)object); + } else if (object instanceof StateVar) { + return true; // FIXME: Should we disallow state vars at the top level? } - // Look in sources - for (VarRef source : convertToEmptyListIfNull(react.getSources())) { - if (Objects.equal(source.getVariable(), action)) { + throw new UnsupportedOperationException("EObject class "+object.eClass().getName()+" not supported."); + } + + /** + * Return true if the specified reactor belongs to this federate. + * @param instantiation The instantiation to look inside + * @param reactor The reactor declaration to find + */ + private boolean contains( + Instantiation instantiation, + ReactorDecl reactor + ) { + if (instantiation.getReactorClass().equals(ASTUtils.toDefinition(reactor))) { return true; - } } - // Look in effects - for (VarRef effect : convertToEmptyListIfNull(react.getEffects())) { - if (Objects.equal(effect.getVariable(), action)) { - return true; - } + + boolean instantiationsCheck = false; + // For a federate, we don't need to look inside imported reactors. + if (instantiation.getReactorClass() instanceof Reactor reactorDef) { + for (Instantiation child : reactorDef.getInstantiations()) { + instantiationsCheck |= contains(child, reactor); + } } - } - } - return false; - } - - /** - * Return true if the specified reaction should be included in the code generated for this - * federate at the top-level. This means that if the reaction is triggered by or sends data to a - * port of a contained reactor, then that reaction is in the federate. Otherwise, return false. - * - *

NOTE: This method assumes that it will not be called with reaction arguments that are within - * other federates. It should only be called on reactions that are either at the top level or - * within this federate. For this reason, for any reaction not at the top level, it returns true. - * - * @param reaction The reaction. - */ - private boolean contains(Reaction reaction) { - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - - assert reactor != null; - if (!reactor.getReactions().contains(reaction)) return false; - - if (networkReactions.contains(reaction)) { - // Reaction is a network reaction that belongs to this federate - return true; + return instantiationsCheck; } - int reactionBankIndex = FedASTUtils.getReactionBankIndex(reaction); - if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { - return false; + /** + * Return true if the specified import should be included in the code generated for this federate. + * @param imp The import + */ + private boolean contains(Import imp) { + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (contains(reactor)) { + return true; + } + } + return false; } - // If this has been called before, then the result of the - // following check is cached. - if (excludeReactions != null) { - return !excludeReactions.contains(reaction); + /** + * Return true if the specified parameter should be included in the code generated for this federate. + * @param param The parameter + */ + private boolean contains(Parameter param) { + boolean returnValue = false; + // Check if param is referenced in this federate's instantiation + returnValue = instantiation.getParameters().stream().anyMatch( + assignment -> assignment.getRhs() + .getExprs() + .stream() + .filter( + it -> it instanceof ParameterReference + ) + .map(it -> ((ParameterReference) it).getParameter()) + .toList() + .contains(param) + ); + // If there are any user-defined top-level reactions, they could access + // the parameters, so we need to include the parameter. + var topLevelUserDefinedReactions = ((Reactor) instantiation.eContainer()) + .getReactions().stream().filter( + r -> !networkReactions.contains(r) && contains(r) + ).collect(Collectors.toCollection(ArrayList::new)); + returnValue |= !topLevelUserDefinedReactions.isEmpty(); + return returnValue; } - indexExcludedTopLevelReactions(reactor); - - return !excludeReactions.contains(reaction); - } - - /** - * Return true if the specified timer should be included in the code generated for the federate. - * This means that the timer is used as a trigger in a top-level reaction that belongs to this - * federate. This also returns true if the program is not federated. - * - * @return True if this federate contains the action in the specified reactor - */ - private boolean contains(Timer timer) { - Reactor reactor = ASTUtils.getEnclosingReactor(timer); - - // If the action is used as a trigger, a source, or an effect for a top-level reaction - // that belongs to this federate, then generate it. - for (Reaction r : ASTUtils.allReactions(reactor)) { - if (contains(r)) { - // Look in triggers - for (TriggerRef trigger : convertToEmptyListIfNull(r.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (Objects.equal(triggerAsVarRef.getVariable(), timer)) { - return true; + /** + * Return true if the specified action should be included in the code generated + * for this federate. This means that either the action is used as a trigger, + * a source, or an effect in a top-level reaction that belongs to this federate. + * This returns true if the program is not federated. + * + * @param action The action + * @return True if this federate contains the action. + */ + private boolean contains(Action action) { + Reactor reactor = ASTUtils.getEnclosingReactor(action); + + // If the action is used as a trigger, a source, or an effect for a top-level reaction + // that belongs to this federate, then generate it. + for (Reaction react : ASTUtils.allReactions(reactor)) { + if (contains(react)) { + // Look in triggers + for (TriggerRef trigger : convertToEmptyListIfNull(react.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (Objects.equal(triggerAsVarRef.getVariable(), action)) { + return true; + } + } + } + // Look in sources + for (VarRef source : convertToEmptyListIfNull(react.getSources())) { + if (Objects.equal(source.getVariable(), action)) { + return true; + } + } + // Look in effects + for (VarRef effect : convertToEmptyListIfNull(react.getEffects())) { + if (Objects.equal(effect.getVariable(), action)) { + return true; + } + } } - } } - } + + return false; } - return false; - } - - /** - * Return true if the specified reactor instance or any parent reactor instance is contained by - * this federate. If the specified instance is the top-level reactor, return true (the top-level - * reactor belongs to all federates). If this federate instance is a singleton, then return true - * if the instance is non null. - * - *

NOTE: If the instance is bank within the top level, then this returns true even though only - * one of the bank members is in the federate. - * - * @param instance The reactor instance. - * @return True if this federate contains the reactor instance - */ - public boolean contains(ReactorInstance instance) { - if (instance.getParent() == null) { - return true; // Top-level reactor - } - // Start with this instance, then check its parents. - ReactorInstance i = instance; - while (i != null) { - if (i.getDefinition() == instantiation) { - return true; - } - i = i.getParent(); + + /** + * Return true if the specified reaction should be included in the code generated for this + * federate at the top-level. This means that if the reaction is triggered by or + * sends data to a port of a contained reactor, then that reaction + * is in the federate. Otherwise, return false. + * + * NOTE: This method assumes that it will not be called with reaction arguments + * that are within other federates. It should only be called on reactions that are + * either at the top level or within this federate. For this reason, for any reaction + * not at the top level, it returns true. + * + * @param reaction The reaction. + */ + private boolean contains(Reaction reaction) { + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + + assert reactor != null; + if (!reactor.getReactions().contains(reaction)) return false; + + if (networkReactions.contains(reaction)) { + // Reaction is a network reaction that belongs to this federate + return true; + } + + int reactionBankIndex = FedASTUtils.getReactionBankIndex(reaction); + if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { + return false; + } + + // If this has been called before, then the result of the + // following check is cached. + if (excludeReactions != null) { + return !excludeReactions.contains(reaction); + } + + indexExcludedTopLevelReactions(reactor); + + return !excludeReactions.contains(reaction); } - return false; - } - - /** - * Build an index of reactions at the top-level (in the federatedReactor) that don't belong to - * this federate instance. This index is put in the excludeReactions class variable. - * - * @param federatedReactor The top-level federated reactor - */ - private void indexExcludedTopLevelReactions(Reactor federatedReactor) { - boolean inFederate = false; - if (excludeReactions != null) { - throw new IllegalStateException( - "The index for excluded reactions at the top level is already built."); + + /** + * Return true if the specified timer should be included in the code generated + * for the federate. This means that the timer is used as a trigger + * in a top-level reaction that belongs to this federate. + * This also returns true if the program is not federated. + * + * @return True if this federate contains the action in the specified reactor + */ + private boolean contains(Timer timer) { + Reactor reactor = ASTUtils.getEnclosingReactor(timer); + + // If the action is used as a trigger, a source, or an effect for a top-level reaction + // that belongs to this federate, then generate it. + for (Reaction r : ASTUtils.allReactions(reactor)) { + if (contains(r)) { + // Look in triggers + for (TriggerRef trigger : convertToEmptyListIfNull(r.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (Objects.equal(triggerAsVarRef.getVariable(), timer)) { + return true; + } + } + } + } + } + + return false; } - excludeReactions = new LinkedHashSet<>(); - - // Construct the set of excluded reactions for this federate. - // If a reaction is a network reaction that belongs to this federate, we - // don't need to perform this analysis. - Iterable reactions = - ASTUtils.allReactions(federatedReactor).stream() - .filter(it -> !networkReactions.contains(it)) - .collect(Collectors.toList()); - for (Reaction react : reactions) { - // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react - // signature that are ports that reference federates. - // We then later check that all these VarRefs reference this federate. If not, we will add - // this - // react to the list of reactions that have to be excluded (note that mixing VarRefs from - // different federates is not allowed). - List allVarRefsReferencingFederates = new ArrayList<>(); - // Add all the triggers that are outputs - Stream triggersAsVarRef = - react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); - allVarRefsReferencingFederates.addAll( - triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList()); - // Add all the sources that are outputs - allVarRefsReferencingFederates.addAll( - react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList()); - // Add all the effects that are inputs - allVarRefsReferencingFederates.addAll( - react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList()); - inFederate = containsAllVarRefs(allVarRefsReferencingFederates); - if (!inFederate) { - excludeReactions.add(react); - } + /** + * Return true if the specified reactor instance or any parent + * reactor instance is contained by this federate. + * If the specified instance is the top-level reactor, return true + * (the top-level reactor belongs to all federates). + * If this federate instance is a singleton, then return true if the + * instance is non null. + * + * NOTE: If the instance is bank within the top level, then this + * returns true even though only one of the bank members is in the federate. + * + * @param instance The reactor instance. + * @return True if this federate contains the reactor instance + */ + public boolean contains(ReactorInstance instance) { + if (instance.getParent() == null) { + return true; // Top-level reactor + } + // Start with this instance, then check its parents. + ReactorInstance i = instance; + while (i != null) { + if (i.getDefinition() == instantiation) { + return true; + } + i = i.getParent(); + } + return false; } - } - - /** - * Return true if all members of 'varRefs' belong to this federate. - * - *

As a convenience measure, if some members of 'varRefs' are from different federates, also - * report an error. - * - * @param varRefs A collection of VarRefs - */ - private boolean containsAllVarRefs(Iterable varRefs) { - var referencesFederate = false; - var inFederate = true; - for (VarRef varRef : varRefs) { - if (varRef.getContainer() == this.instantiation) { - referencesFederate = true; - } else { - if (referencesFederate) { - errorReporter.reportError( - varRef, - "Mixed triggers and effects from" + " different federates. This is not permitted"); + + /** + * Build an index of reactions at the top-level (in the + * federatedReactor) that don't belong to this federate + * instance. This index is put in the excludeReactions + * class variable. + * + * @param federatedReactor The top-level federated reactor + */ + private void indexExcludedTopLevelReactions(Reactor federatedReactor) { + boolean inFederate = false; + if (excludeReactions != null) { + throw new IllegalStateException("The index for excluded reactions at the top level is already built."); + } + + excludeReactions = new LinkedHashSet<>(); + + // Construct the set of excluded reactions for this federate. + // If a reaction is a network reaction that belongs to this federate, we + // don't need to perform this analysis. + Iterable reactions = ASTUtils.allReactions(federatedReactor).stream().filter(it -> !networkReactions.contains(it)).collect(Collectors.toList()); + for (Reaction react : reactions) { + // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react + // signature that are ports that reference federates. + // We then later check that all these VarRefs reference this federate. If not, we will add this + // react to the list of reactions that have to be excluded (note that mixing VarRefs from + // different federates is not allowed). + List allVarRefsReferencingFederates = new ArrayList<>(); + // Add all the triggers that are outputs + Stream triggersAsVarRef = react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); + allVarRefsReferencingFederates.addAll( + triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList() + ); + // Add all the sources that are outputs + allVarRefsReferencingFederates.addAll( + react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList() + ); + // Add all the effects that are inputs + allVarRefsReferencingFederates.addAll( + react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList() + ); + inFederate = containsAllVarRefs(allVarRefsReferencingFederates); + if (!inFederate) { + excludeReactions.add(react); + } } - inFederate = false; - } } - return inFederate; - } - - /** - * Find output ports that are connected to a physical action trigger upstream in the same reactor. - * Return a list of such outputs paired with the minimum delay from the nearest physical action. - * - * @param instance The reactor instance containing the output ports - * @return A LinkedHashMap - */ - public LinkedHashMap findOutputsConnectedToPhysicalActions( - ReactorInstance instance) { - LinkedHashMap physicalActionToOutputMinDelay = new LinkedHashMap<>(); - // Find reactions that write to the output port of the reactor - for (PortInstance output : instance.outputs) { - for (ReactionInstance reaction : output.getDependsOnReactions()) { - TimeValue minDelay = findNearestPhysicalActionTrigger(reaction); - if (!Objects.equal(minDelay, TimeValue.MAX_VALUE)) { - physicalActionToOutputMinDelay.put((Output) output.getDefinition(), minDelay); + + /** + * Return true if all members of 'varRefs' belong to this federate. + * + * As a convenience measure, if some members of 'varRefs' are from + * different federates, also report an error. + * + * @param varRefs A collection of VarRefs + */ + private boolean containsAllVarRefs(Iterable varRefs) { + var referencesFederate = false; + var inFederate = true; + for (VarRef varRef : varRefs) { + if (varRef.getContainer() == this.instantiation) { + referencesFederate = true; + } else { + if (referencesFederate) { + errorReporter.reportError(varRef, + "Mixed triggers and effects from" + + + " different federates. This is not permitted"); + } + inFederate = false; + } } - } + return inFederate; } - return physicalActionToOutputMinDelay; - } - - /** - * Return a list of federates that are upstream of this federate and have a zero-delay (direct) - * connection to this federate. - */ - public List getZeroDelayImmediateUpstreamFederates() { - return this.dependsOn.entrySet().stream() - .filter(e -> e.getValue().contains(null)) - .map(Map.Entry::getKey) - .toList(); - } - - @Override - public String toString() { - return "Federate " - + id - + ": " - + ((instantiation != null) ? instantiation.getName() : "no name"); - } - - ///////////////////////////////////////////// - //// Private Fields - - /** Cached result of analysis of which reactions to exclude from main. */ - private Set excludeReactions = null; - - /** An error reporter */ - private final ErrorReporter errorReporter; - - /** - * Find the nearest (shortest) path to a physical action trigger from this 'reaction' in terms of - * minimum delay. - * - * @param reaction The reaction to start with - * @return The minimum delay found to the nearest physical action and TimeValue.MAX_VALUE - * otherwise - */ - public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { - TimeValue minDelay = TimeValue.MAX_VALUE; - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.getDefinition() instanceof Action action) { - ActionInstance actionInstance = (ActionInstance) trigger; - if (action.getOrigin() == ActionOrigin.PHYSICAL) { - if (actionInstance.getMinDelay().isEarlierThan(minDelay)) { - minDelay = actionInstance.getMinDelay(); - } - } else if (action.getOrigin() == ActionOrigin.LOGICAL) { - // Logical action - // Follow it upstream inside the reactor - for (ReactionInstance uReaction : actionInstance.getDependsOnReactions()) { - // Avoid a loop - if (!Objects.equal(uReaction, reaction)) { - TimeValue uMinDelay = - actionInstance.getMinDelay().add(findNearestPhysicalActionTrigger(uReaction)); - if (uMinDelay.isEarlierThan(minDelay)) { - minDelay = uMinDelay; - } + + /** + * Find output ports that are connected to a physical action trigger upstream + * in the same reactor. Return a list of such outputs paired with the minimum delay + * from the nearest physical action. + * @param instance The reactor instance containing the output ports + * @return A LinkedHashMap + */ + public LinkedHashMap findOutputsConnectedToPhysicalActions(ReactorInstance instance) { + LinkedHashMap physicalActionToOutputMinDelay = new LinkedHashMap<>(); + // Find reactions that write to the output port of the reactor + for (PortInstance output : instance.outputs) { + for (ReactionInstance reaction : output.getDependsOnReactions()) { + TimeValue minDelay = findNearestPhysicalActionTrigger(reaction); + if (!Objects.equal(minDelay, TimeValue.MAX_VALUE)) { + physicalActionToOutputMinDelay.put((Output) output.getDefinition(), minDelay); + } } - } } + return physicalActionToOutputMinDelay; + } - } else if (trigger.getDefinition() instanceof Output) { - // Outputs of contained reactions - PortInstance outputInstance = (PortInstance) trigger; - for (ReactionInstance uReaction : outputInstance.getDependsOnReactions()) { - TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); - if (uMinDelay.isEarlierThan(minDelay)) { - minDelay = uMinDelay; - } - } - } + /** + * Return a list of federates that are upstream of this federate and have a + * zero-delay (direct) connection to this federate. + */ + public List getZeroDelayImmediateUpstreamFederates() { + return this.dependsOn.entrySet() + .stream() + .filter(e -> e.getValue().contains(null)) + .map(Map.Entry::getKey).toList(); + } + + @Override + public String toString() { + return "Federate " + id + ": " + + ((instantiation != null) ? instantiation.getName() : "no name"); } - return minDelay; - } - // TODO: Put this function into a utils file instead - private List convertToEmptyListIfNull(List list) { - return list == null ? new ArrayList<>() : list; - } + ///////////////////////////////////////////// + //// Private Fields + + /** + * Cached result of analysis of which reactions to exclude from main. + */ + private Set excludeReactions = null; + + /** + * An error reporter + */ + private final ErrorReporter errorReporter; + + /** + * Find the nearest (shortest) path to a physical action trigger from this + * 'reaction' in terms of minimum delay. + * + * @param reaction The reaction to start with + * @return The minimum delay found to the nearest physical action and + * TimeValue.MAX_VALUE otherwise + */ + public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { + TimeValue minDelay = TimeValue.MAX_VALUE; + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.getDefinition() instanceof Action action) { + ActionInstance actionInstance = (ActionInstance) trigger; + if (action.getOrigin() == ActionOrigin.PHYSICAL) { + if (actionInstance.getMinDelay().isEarlierThan(minDelay)) { + minDelay = actionInstance.getMinDelay(); + } + } else if (action.getOrigin() == ActionOrigin.LOGICAL) { + // Logical action + // Follow it upstream inside the reactor + for (ReactionInstance uReaction: actionInstance.getDependsOnReactions()) { + // Avoid a loop + if (!Objects.equal(uReaction, reaction)) { + TimeValue uMinDelay = actionInstance.getMinDelay().add(findNearestPhysicalActionTrigger(uReaction)); + if (uMinDelay.isEarlierThan(minDelay)) { + minDelay = uMinDelay; + } + } + } + } + + } else if (trigger.getDefinition() instanceof Output) { + // Outputs of contained reactions + PortInstance outputInstance = (PortInstance) trigger; + for (ReactionInstance uReaction: outputInstance.getDependsOnReactions()) { + TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); + if (uMinDelay.isEarlierThan(minDelay)) { + minDelay = uMinDelay; + } + } + } + } + return minDelay; + } + + // TODO: Put this function into a utils file instead + private List convertToEmptyListIfNull(List list) { + return list == null ? new ArrayList<>() : list; + } } From 17f5071b8b351979178be7750d8d6f5bccd258ff Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:05:09 +0200 Subject: [PATCH 224/709] Added file docs --- org.lflang/src/org/lflang/generator/WatchdogInstance.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index ca5cb3d192..78c0c9bc81 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -1,3 +1,11 @@ +/** + * @file + * @author Benjamin Asch + * @author Edward A. Lee + * @copyright (c) 2023, The University of California at Berkeley + * License in [BSD 2-clause](https://github.com/lf-lang/lingua-franca/blob/master/LICENSE) + * @brief Instance of a watchdog + */ package org.lflang.generator; import org.lflang.TimeValue; From 0867ec87dbf44e5eb31e3d9ce3f4d0b1c803f802 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:05:30 +0200 Subject: [PATCH 225/709] Revert formatting --- .../org/lflang/generator/ReactorInstance.java | 2105 +++++++-------- .../generator/c/CReactionGenerator.java | 2345 ++++++++--------- 2 files changed, 2140 insertions(+), 2310 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index b3bf51d836..0d6154c1bb 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -1,31 +1,32 @@ /** A data structure for a reactor instance. */ /************* - * Copyright (c) 2019-2022, The University of California at Berkeley. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ***************/ +Copyright (c) 2019-2022, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ package org.lflang.generator; +import static org.lflang.ASTUtils.belongsTo; import static org.lflang.ASTUtils.getLiteralTimeValue; import java.util.ArrayList; @@ -37,6 +38,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; + import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; @@ -51,6 +53,7 @@ import org.lflang.lf.Initializer; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; +import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; import org.lflang.lf.Output; import org.lflang.lf.Parameter; @@ -66,1097 +69,1117 @@ import org.lflang.lf.WidthSpec; /** - * Representation of a compile-time instance of a reactor. If the reactor is instantiated as a bank - * of reactors, or if any of its parents is instantiated as a bank of reactors, then one instance of - * this ReactorInstance class represents all the runtime instances within these banks. The {@link - * #getTotalWidth()} method returns the number of such runtime instances, which is the product of - * the bank width of this reactor instance and the bank widths of all of its parents. There is - * exactly one instance of this ReactorInstance class for each graphical rendition of a reactor in - * the diagram view. + * Representation of a compile-time instance of a reactor. + * If the reactor is instantiated as a bank of reactors, or if any + * of its parents is instantiated as a bank of reactors, then one instance + * of this ReactorInstance class represents all the runtime instances within + * these banks. The {@link #getTotalWidth()} method returns the number of such + * runtime instances, which is the product of the bank width of this reactor + * instance and the bank widths of all of its parents. + * There is exactly one instance of this ReactorInstance class for each + * graphical rendition of a reactor in the diagram view. * - *

For the main reactor, which has no parent, once constructed, this object represents the entire - * Lingua Franca program. If the program has causality loops (a programming error), then {@link - * #hasCycles()} will return true and {@link #getCycles()} will return the ports and reaction - * instances involved in the cycles. + * For the main reactor, which has no parent, once constructed, + * this object represents the entire Lingua Franca program. + * If the program has causality loops (a programming error), then + * {@link #hasCycles()} will return true and {@link #getCycles()} will + * return the ports and reaction instances involved in the cycles. * * @author Marten Lohstroh * @author Edward A. Lee */ public class ReactorInstance extends NamedInstance { - /** - * Create a new instantiation hierarchy that starts with the given top-level reactor. - * - * @param reactor The top-level reactor. - * @param reporter The error reporter. - */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), null, reporter, -1); - } - - /** - * Create a new instantiation hierarchy that starts with the given top-level reactor but only - * creates contained reactors up to the specified depth. - * - * @param reactor The top-level reactor. - * @param reporter The error reporter. - * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. - */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { - this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); - } - - /** - * Create a new instantiation with the specified parent. This constructor is here to allow for - * unit tests. It should not be used for any other purpose. - * - * @param reactor The top-level reactor. - * @param parent The parent reactor instance. - * @param reporter The error reporter. - */ - public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); - } - - ////////////////////////////////////////////////////// - //// Public fields. - - /** The action instances belonging to this reactor instance. */ - public List actions = new ArrayList<>(); - - /** - * The contained reactor instances, in order of declaration. For banks of reactors, this includes - * both the bank definition Reactor (which has bankIndex == -2) followed by each of the bank - * members (which have bankIndex >= 0). - */ - public final List children = new ArrayList<>(); - - /** The input port instances belonging to this reactor instance. */ - public final List inputs = new ArrayList<>(); - - /** The output port instances belonging to this reactor instance. */ - public final List outputs = new ArrayList<>(); - - /** The parameters of this instance. */ - public final List parameters = new ArrayList<>(); - - /** List of reaction instances for this reactor instance. */ - public final List reactions = new ArrayList<>(); - - /** List of watchdog instances for this reactor instance. */ - public final List watchdogs = new ArrayList<>(); - - /** The timer instances belonging to this reactor instance. */ - public final List timers = new ArrayList<>(); - - /** The mode instances belonging to this reactor instance. */ - public final List modes = new ArrayList<>(); - - /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ - public final ReactorDecl reactorDeclaration; - - /** The reactor after imports are resolve. */ - public final Reactor reactorDefinition; - - /** Indicator that this reactor has itself as a parent, an error condition. */ - public final boolean recursive; - - ////////////////////////////////////////////////////// - //// Public methods. - - /** - * Assign levels to all reactions within the same root as this reactor. The level of a reaction r - * is equal to the length of the longest chain of reactions that must have the opportunity to - * execute before r at each logical tag. This fails and returns false if a causality cycle exists. - * - *

This method uses a variant of Kahn's algorithm, which is linear in V + E, where V is the - * number of vertices (reactions) and E is the number of edges (dependencies between reactions). - * - * @return An empty graph if successful and otherwise a graph with runtime reaction instances that - * form cycles. - */ - public ReactionInstanceGraph assignLevels() { - if (depth != 0) return root().assignLevels(); - if (cachedReactionLoopGraph == null) { - cachedReactionLoopGraph = new ReactionInstanceGraph(this); + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor. + * @param reactor The top-level reactor. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), null, reporter, -1); } - return cachedReactionLoopGraph; - } - - /** - * This function assigns/propagates deadlines through the Reaction Instance Graph. It performs - * Kahn`s algorithm in reverse, starting from the leaf nodes and propagates deadlines upstream. To - * reduce cost, it should only be invoked when there are user-specified deadlines in the program. - * - * @return - */ - public ReactionInstanceGraph assignDeadlines() { - if (depth != 0) return root().assignDeadlines(); - if (cachedReactionLoopGraph == null) { - cachedReactionLoopGraph = new ReactionInstanceGraph(this); + + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor + * but only creates contained reactors up to the specified depth. + * @param reactor The top-level reactor. + * @param reporter The error reporter. + * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { + this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); } - cachedReactionLoopGraph.rebuildAndAssignDeadlines(); - return cachedReactionLoopGraph; - } - - /** - * Return the instance of a child rector created by the specified definition or null if there is - * none. - * - * @param definition The definition of the child reactor ("new" statement). - */ - public ReactorInstance getChildReactorInstance(Instantiation definition) { - for (ReactorInstance child : this.children) { - if (child.definition == definition) { - return child; - } + + /** + * Create a new instantiation with the specified parent. + * This constructor is here to allow for unit tests. + * It should not be used for any other purpose. + * @param reactor The top-level reactor. + * @param parent The parent reactor instance. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); } - return null; - } - - /** - * Clear any cached data in this reactor and its children. This is useful if a mutation has been - * realized. - */ - public void clearCaches() { - clearCaches(true); - } - - /** - * Clear any cached data in this reactor and its children. This is useful if a mutation has been - * realized. - * - * @param includingRuntimes If false, leave the runtime instances of reactions intact. This is - * useful for federated execution where levels are computed using the top-level connections, - * but then those connections are discarded. - */ - public void clearCaches(boolean includingRuntimes) { - if (includingRuntimes) cachedReactionLoopGraph = null; - for (ReactorInstance child : children) { - child.clearCaches(includingRuntimes); + + ////////////////////////////////////////////////////// + //// Public fields. + + /** The action instances belonging to this reactor instance. */ + public List actions = new ArrayList<>(); + + /** + * The contained reactor instances, in order of declaration. + * For banks of reactors, this includes both the bank definition + * Reactor (which has bankIndex == -2) followed by each of the + * bank members (which have bankIndex >= 0). + */ + public final List children = new ArrayList<>(); + + /** The input port instances belonging to this reactor instance. */ + public final List inputs = new ArrayList<>(); + + /** The output port instances belonging to this reactor instance. */ + public final List outputs = new ArrayList<>(); + + /** The parameters of this instance. */ + public final List parameters = new ArrayList<>(); + + /** List of reaction instances for this reactor instance. */ + public final List reactions = new ArrayList<>(); + + /** List of watchdog instances for this reactor instance. */ + public final List watchdogs = new ArrayList<>(); + + /** The timer instances belonging to this reactor instance. */ + public final List timers = new ArrayList<>(); + + /** The mode instances belonging to this reactor instance. */ + public final List modes = new ArrayList<>(); + + /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ + public final ReactorDecl reactorDeclaration; + + /** The reactor after imports are resolve. */ + public final Reactor reactorDefinition; + + /** Indicator that this reactor has itself as a parent, an error condition. */ + public final boolean recursive; + + ////////////////////////////////////////////////////// + //// Public methods. + + /** + * Assign levels to all reactions within the same root as this + * reactor. The level of a reaction r is equal to the length of the + * longest chain of reactions that must have the opportunity to + * execute before r at each logical tag. This fails and returns + * false if a causality cycle exists. + * + * This method uses a variant of Kahn's algorithm, which is linear + * in V + E, where V is the number of vertices (reactions) and E + * is the number of edges (dependencies between reactions). + * + * @return An empty graph if successful and otherwise a graph + * with runtime reaction instances that form cycles. + */ + public ReactionInstanceGraph assignLevels() { + if (depth != 0) return root().assignLevels(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); + } + return cachedReactionLoopGraph; } - for (PortInstance port : inputs) { - port.clearCaches(); + + /** + * This function assigns/propagates deadlines through the Reaction Instance Graph. + * It performs Kahn`s algorithm in reverse, starting from the leaf nodes and + * propagates deadlines upstream. To reduce cost, it should only be invoked when + * there are user-specified deadlines in the program. + * @return + */ + public ReactionInstanceGraph assignDeadlines() { + if (depth != 0) return root().assignDeadlines(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); + } + cachedReactionLoopGraph.rebuildAndAssignDeadlines(); + return cachedReactionLoopGraph; } - for (PortInstance port : outputs) { - port.clearCaches(); + + /** + * Return the instance of a child rector created by the specified + * definition or null if there is none. + * @param definition The definition of the child reactor ("new" statement). + */ + public ReactorInstance getChildReactorInstance(Instantiation definition) { + for (ReactorInstance child : this.children) { + if (child.definition == definition) { + return child; + } + } + return null; } - for (ReactionInstance reaction : reactions) { - reaction.clearCaches(includingRuntimes); + + /** + * Clear any cached data in this reactor and its children. + * This is useful if a mutation has been realized. + */ + public void clearCaches() { + clearCaches(true); } - cachedCycles = null; - } - - /** - * Return the specified input by name or null if there is no such input. - * - * @param name The input name. - */ - public PortInstance getInput(String name) { - for (PortInstance port : inputs) { - if (port.getName().equals(name)) { - return port; - } + + /** + * Clear any cached data in this reactor and its children. + * This is useful if a mutation has been realized. + * @param includingRuntimes If false, leave the runtime instances of reactions intact. + * This is useful for federated execution where levels are computed using + * the top-level connections, but then those connections are discarded. + */ + public void clearCaches(boolean includingRuntimes) { + if (includingRuntimes) cachedReactionLoopGraph = null; + for (ReactorInstance child : children) { + child.clearCaches(includingRuntimes); + } + for (PortInstance port : inputs) { + port.clearCaches(); + } + for (PortInstance port : outputs) { + port.clearCaches(); + } + for (ReactionInstance reaction : reactions) { + reaction.clearCaches(includingRuntimes); + } + cachedCycles = null; } - return null; - } - - /** - * Return the set of ReactionInstance and PortInstance that form causality loops in the topmost - * parent reactor in the instantiation hierarchy. This will return an empty set if there are no - * causality loops. - */ - public Set> getCycles() { - if (depth != 0) return root().getCycles(); - if (cachedCycles != null) return cachedCycles; - cachedCycles = new LinkedHashSet<>(); - - ReactionInstanceGraph reactionRuntimes = assignLevels(); - if (reactionRuntimes.nodes().size() > 0) { - Set reactions = new LinkedHashSet<>(); - Set ports = new LinkedHashSet<>(); - // There are cycles. But the nodes set includes not - // just the cycles, but also nodes that are downstream of the - // cycles. Use Tarjan's algorithm to get just the cycles. - var cycleNodes = reactionRuntimes.getCycles(); - for (var cycle : cycleNodes) { - for (ReactionInstance.Runtime runtime : cycle) { - reactions.add(runtime.getReaction()); + + /** + * Return the set of ReactionInstance and PortInstance that form causality + * loops in the topmost parent reactor in the instantiation hierarchy. This will return an + * empty set if there are no causality loops. + */ + public Set> getCycles() { + if (depth != 0) return root().getCycles(); + if (cachedCycles != null) return cachedCycles; + cachedCycles = new LinkedHashSet<>(); + + ReactionInstanceGraph reactionRuntimes = assignLevels(); + if (reactionRuntimes.nodes().size() > 0) { + Set reactions = new LinkedHashSet<>(); + Set ports = new LinkedHashSet<>(); + // There are cycles. But the nodes set includes not + // just the cycles, but also nodes that are downstream of the + // cycles. Use Tarjan's algorithm to get just the cycles. + var cycleNodes = reactionRuntimes.getCycles(); + for (var cycle : cycleNodes) { + for (ReactionInstance.Runtime runtime : cycle) { + reactions.add(runtime.getReaction()); + } + } + // Need to figure out which ports are involved in the cycles. + // It may not be all ports that depend on this reaction. + for (ReactionInstance r : reactions) { + for (TriggerInstance p : r.effects) { + if (p instanceof PortInstance) { + findPaths((PortInstance)p, reactions, ports); + } + } + } + cachedCycles.addAll(reactions); + cachedCycles.addAll(ports); } - } - // Need to figure out which ports are involved in the cycles. - // It may not be all ports that depend on this reaction. - for (ReactionInstance r : reactions) { - for (TriggerInstance p : r.effects) { - if (p instanceof PortInstance) { - findPaths((PortInstance) p, reactions, ports); - } + + return cachedCycles; + } + + /** + * Return the specified input by name or null if there is no such input. + * @param name The input name. + */ + public PortInstance getInput(String name) { + for (PortInstance port: inputs) { + if (port.getName().equals(name)) { + return port; + } } - } - cachedCycles.addAll(reactions); - cachedCycles.addAll(ports); + return null; } - return cachedCycles; - } - - /** - * Override the base class to append [i_d], where d is the depth, if this reactor is in a bank of - * reactors. - * - * @return The name of this instance. - */ - @Override - public String getName() { - return this.definition.getName(); - } - - /** - * @see NamedInstance#uniqueID() - *

Append `_main` to the name of the main reactor to allow instantiations within that - * reactor to have the same name. - */ - @Override - public String uniqueID() { - if (this.isMainOrFederated()) { - return super.uniqueID() + "_main"; + /** + * Override the base class to append [i_d], where d is the depth, + * if this reactor is in a bank of reactors. + * @return The name of this instance. + */ + @Override + public String getName() { + return this.definition.getName(); } - return super.uniqueID(); - } - - /** - * Return the specified output by name or null if there is no such output. - * - * @param name The output name. - */ - public PortInstance getOutput(String name) { - for (PortInstance port : outputs) { - if (port.getName().equals(name)) { - return port; - } + + /** + * @see NamedInstance#uniqueID() + * + * Append `_main` to the name of the main reactor to allow instantiations + * within that reactor to have the same name. + */ + @Override + public String uniqueID() { + if (this.isMainOrFederated()) { + return super.uniqueID() + "_main"; + } + return super.uniqueID(); } - return null; - } - - /** - * Return a parameter matching the specified name if the reactor has one and otherwise return - * null. - * - * @param name The parameter name. - */ - public ParameterInstance getParameter(String name) { - for (ParameterInstance parameter : parameters) { - if (parameter.getName().equals(name)) { - return parameter; - } + + /** + * Return the specified output by name or null if there is no such output. + * @param name The output name. + */ + public PortInstance getOutput(String name) { + for (PortInstance port: outputs) { + if (port.getName().equals(name)) { + return port; + } + } + return null; } - return null; - } - - /** Return the startup trigger or null if not used in any reaction. */ - public TriggerInstance getStartupTrigger() { - return builtinTriggers.get(BuiltinTrigger.STARTUP); - } - - /** Return the shutdown trigger or null if not used in any reaction. */ - public TriggerInstance getShutdownTrigger() { - return builtinTriggers.get(BuiltinTrigger.SHUTDOWN); - } - - /** - * If this reactor is a bank or any of its parents is a bank, return the total number of runtime - * instances, which is the product of the widths of all the parents. Return -1 if the width cannot - * be determined. - */ - public int getTotalWidth() { - return getTotalWidth(0); - } - - /** - * If this reactor is a bank or any of its parents is a bank, return the total number of runtime - * instances, which is the product of the widths of all the parents. Return -1 if the width cannot - * be determined. - * - * @param atDepth The depth at which to determine the width. Use 0 to get the total number of - * instances. Use 1 to get the number of instances within a single top-level bank member (this - * is useful for federates). - */ - public int getTotalWidth(int atDepth) { - if (width <= 0) return -1; - if (depth <= atDepth) return 1; - int result = width; - ReactorInstance p = parent; - while (p != null && p.depth > atDepth) { - if (p.width <= 0) return -1; - result *= p.width; - p = p.parent; + + /** + * Return a parameter matching the specified name if the reactor has one + * and otherwise return null. + * @param name The parameter name. + */ + public ParameterInstance getParameter(String name) { + for (ParameterInstance parameter: parameters) { + if (parameter.getName().equals(name)) { + return parameter; + } + } + return null; } - return result; - } - - /** - * Return the trigger instances (input ports, timers, and actions that trigger reactions) - * belonging to this reactor instance. - */ - public Set> getTriggers() { - // FIXME: Cache this. - var triggers = new LinkedHashSet>(); - for (ReactionInstance reaction : this.reactions) { - triggers.addAll(reaction.triggers); + + /** + * Return the startup trigger or null if not used in any reaction. + */ + public TriggerInstance getStartupTrigger() { + return builtinTriggers.get(BuiltinTrigger.STARTUP); } - return triggers; - } - - /** - * Return the trigger instances (input ports, timers, and actions that trigger reactions) together - * the ports that the reaction reads but that don't trigger it. - * - * @return The trigger instances belonging to this reactor instance. - */ - public Set> getTriggersAndReads() { - // FIXME: Cache this. - var triggers = new LinkedHashSet>(); - for (ReactionInstance reaction : this.reactions) { - triggers.addAll(reaction.triggers); - triggers.addAll(reaction.reads); + + /** + * Return the shutdown trigger or null if not used in any reaction. + */ + public TriggerInstance getShutdownTrigger() { + return builtinTriggers.get(BuiltinTrigger.SHUTDOWN); } - return triggers; - } - - /** Return true if the top-level parent of this reactor has causality cycles. */ - public boolean hasCycles() { - return assignLevels().nodeCount() != 0; - } - - /** - * Given a parameter definition for this reactor, return the initial integer value of the - * parameter. If the parameter is overridden when instantiating this reactor or any of its - * containing reactors, use that value. Otherwise, use the default value in the reactor - * definition. If the parameter cannot be found or its value is not an integer, return null. - * - * @param parameter The parameter definition (a syntactic object in the AST). - * @return An integer value or null. - */ - public Integer initialIntParameterValue(Parameter parameter) { - return ASTUtils.initialValueInt(parameter, instantiations()); - } - - public Expression resolveParameters(Expression e) { - return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); - } - - private static final class ParameterInliner - extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { - static final ParameterInliner INSTANCE = new ParameterInliner(); - @Override - public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { - if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { - throw new IllegalArgumentException( - "Parameter " - + expr.getParameter().getName() - + " is not a parameter of reactor instance " - + instance.getName() - + "."); - } - - Optional assignment = - instance.definition.getParameters().stream() - .filter(it -> it.getLhs().equals(expr.getParameter())) - .findAny(); // There is at most one - - if (assignment.isPresent()) { - // replace the parameter with its value. - Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); - // recursively resolve parameters - return instance.getParent().resolveParameters(value); - } else { - // In that case use the default value. Default values - // cannot use parameter values, so they don't need to - // be recursively resolved. - Initializer init = expr.getParameter().getInit(); - Expression defaultValue = ASTUtils.asSingleExpr(init); - if (defaultValue == null) { - // this is a problem - return super.visitParameterRef(expr, instance); + /** + * If this reactor is a bank or any of its parents is a bank, + * return the total number of runtime instances, which is the product + * of the widths of all the parents. + * Return -1 if the width cannot be determined. + */ + public int getTotalWidth() { + return getTotalWidth(0); + } + + /** + * If this reactor is a bank or any of its parents is a bank, + * return the total number of runtime instances, which is the product + * of the widths of all the parents. + * Return -1 if the width cannot be determined. + * @param atDepth The depth at which to determine the width. + * Use 0 to get the total number of instances. + * Use 1 to get the number of instances within a single top-level + * bank member (this is useful for federates). + */ + public int getTotalWidth(int atDepth) { + if (width <= 0) return -1; + if (depth <= atDepth) return 1; + int result = width; + ReactorInstance p = parent; + while (p != null && p.depth > atDepth) { + if (p.width <= 0) return -1; + result *= p.width; + p = p.parent; } - return defaultValue; - } + return result; } - } - - // /** - // * Return the startup trigger or null if not used in any reaction. - // */ - // public TriggerInstance getStartupTrigger() { - // return _instantiations; - // } - - /////////////////////////////////////////////////// - //// Methods for finding instances in this reactor given an AST node. - - /** - * Given a parameter definition, return the parameter instance corresponding to that definition, - * or null if there is no such instance. - * - * @param parameter The parameter definition (a syntactic object in the AST). - * @return A parameter instance, or null if there is none. - */ - public ParameterInstance lookupParameterInstance(Parameter parameter) { - for (ParameterInstance param : parameters) { - if (param.definition == parameter) { - return param; - } + + /** + * Return the trigger instances (input ports, timers, and actions + * that trigger reactions) belonging to this reactor instance. + */ + public Set> getTriggers() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); + } + return triggers; } - return null; - } - - /** - * Given a port definition, return the port instance corresponding to that definition, or null if - * there is no such instance. - * - * @param port The port definition (a syntactic object in the AST). - * @return A port instance, or null if there is none. - */ - public PortInstance lookupPortInstance(Port port) { - // Search one of the inputs and outputs sets. - List ports = null; - if (port instanceof Input) { - ports = this.inputs; - } else if (port instanceof Output) { - ports = this.outputs; + + /** + * Return the trigger instances (input ports, timers, and actions + * that trigger reactions) together the ports that the reaction reads + * but that don't trigger it. + * + * @return The trigger instances belonging to this reactor instance. + */ + public Set> getTriggersAndReads() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); + triggers.addAll(reaction.reads); + } + return triggers; } - for (PortInstance portInstance : ports) { - if (portInstance.definition == port) { - return portInstance; - } + + /** + * Return true if the top-level parent of this reactor has causality cycles. + */ + public boolean hasCycles() { + return assignLevels().nodeCount() != 0; } - return null; - } - - /** - * Given a reference to a port belonging to this reactor instance, return the port instance. - * Return null if there is no such instance. - * - * @param reference The port reference. - * @return A port instance, or null if there is none. - */ - public PortInstance lookupPortInstance(VarRef reference) { - if (!(reference.getVariable() instanceof Port)) { - // Trying to resolve something that is not a port - return null; + + /** + * Given a parameter definition for this reactor, return the initial integer + * value of the parameter. If the parameter is overridden when instantiating + * this reactor or any of its containing reactors, use that value. + * Otherwise, use the default value in the reactor definition. + * If the parameter cannot be found or its value is not an integer, return null. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * + * @return An integer value or null. + */ + public Integer initialIntParameterValue(Parameter parameter) { + return ASTUtils.initialValueInt(parameter, instantiations()); } - if (reference.getContainer() == null) { - // Handle local reference - return lookupPortInstance((Port) reference.getVariable()); - } else { - // Handle hierarchical reference - var containerInstance = getChildReactorInstance(reference.getContainer()); - if (containerInstance == null) return null; - return containerInstance.lookupPortInstance((Port) reference.getVariable()); + + public Expression resolveParameters(Expression e) { + return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); } - } - - /** - * Return the reaction instance within this reactor instance corresponding to the specified - * reaction. - * - * @param reaction The reaction as an AST node. - * @return The corresponding reaction instance or null if the reaction does not belong to this - * reactor. - */ - public ReactionInstance lookupReactionInstance(Reaction reaction) { - for (ReactionInstance reactionInstance : reactions) { - if (reactionInstance.definition == reaction) { - return reactionInstance; - } + + + private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { + static final ParameterInliner INSTANCE = new ParameterInliner(); + + @Override + public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { + if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { + throw new IllegalArgumentException("Parameter " + + expr.getParameter().getName() + + " is not a parameter of reactor instance " + + instance.getName() + + "." + ); + } + + Optional assignment = + instance.definition.getParameters().stream() + .filter(it -> it.getLhs().equals(expr.getParameter())) + .findAny(); // There is at most one + + if (assignment.isPresent()) { + // replace the parameter with its value. + Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); + // recursively resolve parameters + return instance.getParent().resolveParameters(value); + } else { + // In that case use the default value. Default values + // cannot use parameter values, so they don't need to + // be recursively resolved. + Initializer init = expr.getParameter().getInit(); + Expression defaultValue = ASTUtils.asSingleExpr(init); + if (defaultValue == null) { + // this is a problem + return super.visitParameterRef(expr, instance); + } + return defaultValue; + } + } } - return null; - } - - /** - * Return the reactor instance within this reactor that has the specified instantiation. Note that - * this may be a bank of reactors. Return null if there is no such reactor instance. - */ - public ReactorInstance lookupReactorInstance(Instantiation instantiation) { - for (ReactorInstance reactorInstance : children) { - if (reactorInstance.definition == instantiation) { - return reactorInstance; - } + + /** + * Return a list of Instantiation objects for evaluating parameter + * values. The first object in the list is the AST Instantiation + * that created this reactor instance, the second is the AST instantiation + * that created the containing reactor instance, and so on until there + * are no more containing reactor instances. This will return an empty + * list if this reactor instance is at the top level (is main). + */ + public List instantiations() { + if (_instantiations == null) { + _instantiations = new ArrayList<>(); + if (definition != null) { + _instantiations.add(definition); + if (parent != null) { + _instantiations.addAll(parent.instantiations()); + } + } + } + return _instantiations; } - return null; - } - - /** - * Return the timer instance within this reactor instance corresponding to the specified timer - * reference. - * - * @param timer The timer as an AST node. - * @return The corresponding timer instance or null if the timer does not belong to this reactor. - */ - public TimerInstance lookupTimerInstance(Timer timer) { - for (TimerInstance timerInstance : timers) { - if (timerInstance.definition == timer) { - return timerInstance; - } + + /** + * Returns true if this is a bank of reactors. + * @return true if a reactor is a bank, false otherwise + */ + public boolean isBank() { + return definition.getWidthSpec() != null; } - return null; - } - - /** - * Returns the mode instance within this reactor instance corresponding to the specified mode - * reference. - * - * @param mode The mode as an AST node. - * @return The corresponding mode instance or null if the mode does not belong to this reactor. - */ - public ModeInstance lookupModeInstance(Mode mode) { - for (ModeInstance modeInstance : modes) { - if (modeInstance.definition == mode) { - return modeInstance; - } + + /** + * Returns whether this is a main or federated reactor. + * @return true if reactor definition is marked as main or federated, false otherwise. + */ + public boolean isMainOrFederated() { + return reactorDefinition != null + && (reactorDefinition.isMain() || reactorDefinition.isFederated()); } - return null; - } - - /** Return a descriptive string. */ - @Override - public String toString() { - return "ReactorInstance " + getFullName(); - } - - /** - * Assuming that the given expression denotes a valid time, return a time value. - * - *

If the value is given as a parameter reference, this will look up the precise time value - * assigned to this reactor instance. - */ - public TimeValue getTimeValue(Expression expr) { - Expression resolved = resolveParameters(expr); - return getLiteralTimeValue(resolved); - } - - ////////////////////////////////////////////////////// - //// Protected fields. - - /** The generator that created this reactor instance. */ - protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references - - /** The map of used built-in triggers. */ - protected Map> builtinTriggers = - new HashMap<>(); - - /** - * The LF syntax does not currently support declaring reactions unordered, but unordered reactions - * are created in the AST transformations handling federated communication and after delays. - * Unordered reactions can execute in any order and concurrently even though they are in the same - * reactor. FIXME: Remove this when the language provides syntax. - */ - protected Set unorderedReactions = new LinkedHashSet<>(); - - /** The nested list of instantiations that created this reactor instance. */ - protected List _instantiations; - - ////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Create all the reaction instances of this reactor instance and record the dependencies and - * antidependencies between ports, actions, and timers and reactions. This also records the - * dependencies between reactions that follows from the order in which they are defined. - */ - protected void createReactionInstances() { - List reactions = ASTUtils.allReactions(reactorDefinition); - if (reactions != null) { - int count = 0; - - // Check for startup and shutdown triggers. - for (Reaction reaction : reactions) { - if (AttributeUtils.isUnordered(reaction)) { - unorderedReactions.add(reaction); + + /** + * Return true if the specified reactor instance is either equal to this + * reactor instance or a parent of it. + * @param r The reactor instance. + */ + public boolean isParent(ReactorInstance r) { + ReactorInstance p = this; + while (p != null) { + if (p == r) return true; + p = p.getParent(); } - // Create the reaction instance. - var reactionInstance = - new ReactionInstance(reaction, this, unorderedReactions.contains(reaction), count++); - - // Add the reaction instance to the map of reactions for this - // reactor. - this.reactions.add(reactionInstance); - } + return false; } - } - - /** Create all the watchdog instances of this reactor instance. */ - protected void createWatchdogInstances() { - List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); - if (watchdogs != null) { - for (Watchdog watchdog : watchdogs) { - // Create the watchdog instance. - var watchdogInstance = new WatchdogInstance(watchdog, this); - - // Add the watchdog instance to the list of watchdogs for this - // reactor. - this.watchdogs.add(watchdogInstance); - } + + /////////////////////////////////////////////////// + //// Methods for finding instances in this reactor given an AST node. + + /** + * Return the action instance within this reactor + * instance corresponding to the specified action reference. + * @param action The action as an AST node. + * @return The corresponding action instance or null if the + * action does not belong to this reactor. + */ + public ActionInstance lookupActionInstance(Action action) { + for (ActionInstance actionInstance : actions) { + if (actionInstance.definition == action) { + return actionInstance; + } + } + return null; } - } - - //////////////////////////////////////// - //// Private constructors - - /** - * Create a runtime instance from the specified definition and with the specified parent that - * instantiated it. - * - * @param definition The instantiation statement in the AST. - * @param parent The parent, or null for the main rector. - * @param reporter An error reporter. - * @param desiredDepth The depth to which to expand the hierarchy. - */ - private ReactorInstance( - Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth) { - super(definition, parent); - this.reporter = reporter; - this.reactorDeclaration = definition.getReactorClass(); - this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - - // check for recursive instantiation - var currentParent = parent; - var foundSelfAsParent = false; - do { - if (currentParent != null) { - if (currentParent.reactorDefinition == this.reactorDefinition) { - foundSelfAsParent = true; - currentParent = null; // break - } else { - currentParent = currentParent.parent; + + /** + * Given a parameter definition, return the parameter instance + * corresponding to that definition, or null if there is + * no such instance. + * @param parameter The parameter definition (a syntactic object in the AST). + * @return A parameter instance, or null if there is none. + */ + public ParameterInstance lookupParameterInstance(Parameter parameter) { + for (ParameterInstance param : parameters) { + if (param.definition == parameter) { + return param; + } } - } - } while (currentParent != null); + return null; + } - this.recursive = foundSelfAsParent; - if (recursive) { - reporter.reportError(definition, "Recursive reactor instantiation."); + /** + * Given a port definition, return the port instance + * corresponding to that definition, or null if there is + * no such instance. + * @param port The port definition (a syntactic object in the AST). + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(Port port) { + // Search one of the inputs and outputs sets. + List ports = null; + if (port instanceof Input) { + ports = this.inputs; + } else if (port instanceof Output) { + ports = this.outputs; + } + for (PortInstance portInstance : ports) { + if (portInstance.definition == port) { + return portInstance; + } + } + return null; } - // If the reactor definition is null, give up here. Otherwise, diagram generation - // will fail an NPE. - if (reactorDefinition == null) { - reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); - return; + /** + * Given a reference to a port belonging to this reactor + * instance, return the port instance. + * Return null if there is no such instance. + * @param reference The port reference. + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(VarRef reference) { + if (!(reference.getVariable() instanceof Port)) { + // Trying to resolve something that is not a port + return null; + } + if (reference.getContainer() == null) { + // Handle local reference + return lookupPortInstance((Port) reference.getVariable()); + } else { + // Handle hierarchical reference + var containerInstance = getChildReactorInstance(reference.getContainer()); + if (containerInstance == null) return null; + return containerInstance.lookupPortInstance((Port) reference.getVariable()); + } } - setInitialWidth(); + /** + * Return the reaction instance within this reactor + * instance corresponding to the specified reaction. + * @param reaction The reaction as an AST node. + * @return The corresponding reaction instance or null if the + * reaction does not belong to this reactor. + */ + public ReactionInstance lookupReactionInstance(Reaction reaction) { + for (ReactionInstance reactionInstance : reactions) { + if (reactionInstance.definition == reaction) { + return reactionInstance; + } + } + return null; + } - // Apply overrides and instantiate parameters for this reactor instance. - for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { - this.parameters.add(new ParameterInstance(parameter, this)); + /** + * Return the reactor instance within this reactor + * that has the specified instantiation. Note that this + * may be a bank of reactors. Return null if there + * is no such reactor instance. + */ + public ReactorInstance lookupReactorInstance(Instantiation instantiation) { + for (ReactorInstance reactorInstance : children) { + if (reactorInstance.definition == instantiation) { + return reactorInstance; + } + } + return null; } - // Instantiate inputs for this reactor instance - for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { - this.inputs.add(new PortInstance(inputDecl, this, reporter)); + /** + * Return the timer instance within this reactor + * instance corresponding to the specified timer reference. + * @param timer The timer as an AST node. + * @return The corresponding timer instance or null if the + * timer does not belong to this reactor. + */ + public TimerInstance lookupTimerInstance(Timer timer) { + for (TimerInstance timerInstance : timers) { + if (timerInstance.definition == timer) { + return timerInstance; + } + } + return null; } - // Instantiate outputs for this reactor instance - for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { - this.outputs.add(new PortInstance(outputDecl, this, reporter)); + /** Returns the mode instance within this reactor + * instance corresponding to the specified mode reference. + * @param mode The mode as an AST node. + * @return The corresponding mode instance or null if the + * mode does not belong to this reactor. + */ + public ModeInstance lookupModeInstance(Mode mode) { + for (ModeInstance modeInstance : modes) { + if (modeInstance.definition == mode) { + return modeInstance; + } + } + return null; } - // Do not process content (except interface above) if recursive - if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { - // Instantiate children for this reactor instance. - // While doing this, assign an index offset to each. - for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { - var childInstance = new ReactorInstance(child, this, reporter, desiredDepth); - this.children.add(childInstance); - } - - // Instantiate timers for this reactor instance - for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { - this.timers.add(new TimerInstance(timerDecl, this)); - } - - // Instantiate actions for this reactor instance - for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { - this.actions.add(new ActionInstance(actionDecl, this)); - } - - establishPortConnections(); - - // Create the reaction instances in this reactor instance. - // This also establishes all the implied dependencies. - // Note that this can only happen _after_ the children, - // port, action, and timer instances have been created. - createReactionInstances(); - - // Instantiate modes for this reactor instance - // This must come after the child elements (reactions, etc) of this reactor - // are created in order to allow their association with modes - for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { - this.modes.add(new ModeInstance(modeDecl, this)); - } - for (ModeInstance mode : this.modes) { - mode.setupTranstions(); - } + /** + * Return a descriptive string. + */ + @Override + public String toString() { + return "ReactorInstance " + getFullName(); } - } - - /** - * Return a list of Instantiation objects for evaluating parameter values. The first object in the - * list is the AST Instantiation that created this reactor instance, the second is the AST - * instantiation that created the containing reactor instance, and so on until there are no more - * containing reactor instances. This will return an empty list if this reactor instance is at the - * top level (is main). - */ - public List instantiations() { - if (_instantiations == null) { - _instantiations = new ArrayList<>(); - if (definition != null) { - _instantiations.add(definition); - if (parent != null) { - _instantiations.addAll(parent.instantiations()); + + /** + * Assuming that the given expression denotes a valid time, return a time value. + * + * If the value is given as a parameter reference, this will look up the + * precise time value assigned to this reactor instance. + */ + public TimeValue getTimeValue(Expression expr) { + Expression resolved = resolveParameters(expr); + return getLiteralTimeValue(resolved); + } + + ////////////////////////////////////////////////////// + //// Protected fields. + + /** The generator that created this reactor instance. */ + protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references + + /** The map of used built-in triggers. */ + protected Map> builtinTriggers = new HashMap<>(); + + /** + * The LF syntax does not currently support declaring reactions unordered, + * but unordered reactions are created in the AST transformations handling + * federated communication and after delays. Unordered reactions can execute + * in any order and concurrently even though they are in the same reactor. + * FIXME: Remove this when the language provides syntax. + */ + protected Set unorderedReactions = new LinkedHashSet<>(); + + /** The nested list of instantiations that created this reactor instance. */ + protected List _instantiations; + + ////////////////////////////////////////////////////// + //// Protected methods. + + /** + * Create all the reaction instances of this reactor instance + * and record the dependencies and antidependencies + * between ports, actions, and timers and reactions. + * This also records the dependencies between reactions + * that follows from the order in which they are defined. + */ + protected void createReactionInstances() { + List reactions = ASTUtils.allReactions(reactorDefinition); + if (reactions != null) { + int count = 0; + + // Check for startup and shutdown triggers. + for (Reaction reaction : reactions) { + if (AttributeUtils.isUnordered(reaction)) { + unorderedReactions.add(reaction); + } + // Create the reaction instance. + var reactionInstance = new ReactionInstance(reaction, this, + unorderedReactions.contains(reaction), count++); + + // Add the reaction instance to the map of reactions for this + // reactor. + this.reactions.add(reactionInstance); + } } - } } - return _instantiations; - } - - /** - * Returns true if this is a bank of reactors. - * - * @return true if a reactor is a bank, false otherwise - */ - public boolean isBank() { - return definition.getWidthSpec() != null; - } - - /** - * Returns whether this is a main or federated reactor. - * - * @return true if reactor definition is marked as main or federated, false otherwise. - */ - public boolean isMainOrFederated() { - return reactorDefinition != null - && (reactorDefinition.isMain() || reactorDefinition.isFederated()); - } - - /** - * Return true if the specified reactor instance is either equal to this reactor instance or a - * parent of it. - * - * @param r The reactor instance. - */ - public boolean isParent(ReactorInstance r) { - ReactorInstance p = this; - while (p != null) { - if (p == r) return true; - p = p.getParent(); + + /** + * Returns the built-in trigger or create a new one if none exists. + */ + protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { + return builtinTriggers.computeIfAbsent(trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); } - return false; - } - - /////////////////////////////////////////////////// - //// Methods for finding instances in this reactor given an AST node. - - /** - * Return the action instance within this reactor instance corresponding to the specified action - * reference. - * - * @param action The action as an AST node. - * @return The corresponding action instance or null if the action does not belong to this - * reactor. - */ - public ActionInstance lookupActionInstance(Action action) { - for (ActionInstance actionInstance : actions) { - if (actionInstance.definition == action) { - return actionInstance; - } + + /** Create all the watchdog instances of this reactor instance. */ + protected void createWatchdogInstances() { + List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); + if (watchdogs != null) { + for (Watchdog watchdog : watchdogs) { + // Create the watchdog instance. + var watchdogInstance = new WatchdogInstance(watchdog, this); + + // Add the watchdog instance to the list of watchdogs for this + // reactor. + this.watchdogs.add(watchdogInstance); + } + } } - return null; - } - - ////////////////////////////////////////////////////// - //// Private methods. - - /** - * Connect the given left port range to the given right port range. - * - *

NOTE: This method is public to enable its use in unit tests. Otherwise, it should be - * private. This is why it is defined here, in the section labeled "Private methods." - * - * @param src The source range. - * @param dst The destination range. - * @param connection The connection establishing this relationship. - */ - public static void connectPortInstances( - RuntimeRange src, RuntimeRange dst, Connection connection) { - SendRange range = new SendRange(src, dst, src._interleaved, connection); - src.instance.dependentPorts.add(range); - dst.instance.dependsOnPorts.add(src); - } - - ////////////////////////////////////////////////////// - //// Protected methods. - - /** Returns the built-in trigger or create a new one if none exists. */ - protected TriggerInstance getOrCreateBuiltinTrigger( - BuiltinTriggerRef trigger) { - return builtinTriggers.computeIfAbsent( - trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); - } - - /** - * Populate connectivity information in the port instances. Note that this can only happen _after_ - * the children and port instances have been created. Unfortunately, we have to do some - * complicated things here to support multiport-to-multiport, multiport-to-bank, and - * bank-to-multiport communication. The principle being followed is: in each connection statement, - * for each port instance on the left, connect to the next available port on the right. - */ - private void establishPortConnections() { - for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { - List> leftPorts = - listPortInstances(connection.getLeftPorts(), connection); - Iterator> srcRanges = leftPorts.iterator(); - List> rightPorts = - listPortInstances(connection.getRightPorts(), connection); - Iterator> dstRanges = rightPorts.iterator(); - - // Check for empty lists. - if (!srcRanges.hasNext()) { - if (dstRanges.hasNext()) { - reporter.reportWarning(connection, "No sources to provide inputs."); + + //////////////////////////////////////// + //// Private constructors + + /** + * Create a runtime instance from the specified definition + * and with the specified parent that instantiated it. + * @param definition The instantiation statement in the AST. + * @param parent The parent, or null for the main rector. + * @param reporter An error reporter. + * @param desiredDepth The depth to which to expand the hierarchy. + */ + private ReactorInstance( + Instantiation definition, + ReactorInstance parent, + ErrorReporter reporter, + int desiredDepth) { + super(definition, parent); + this.reporter = reporter; + this.reactorDeclaration = definition.getReactorClass(); + this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); + + // check for recursive instantiation + var currentParent = parent; + var foundSelfAsParent = false; + do { + if (currentParent != null) { + if (currentParent.reactorDefinition == this.reactorDefinition) { + foundSelfAsParent = true; + currentParent = null; // break + } else { + currentParent = currentParent.parent; + } + } + } while(currentParent != null); + + this.recursive = foundSelfAsParent; + if (recursive) { + reporter.reportError(definition, "Recursive reactor instantiation."); + } + + // If the reactor definition is null, give up here. Otherwise, diagram generation + // will fail an NPE. + if (reactorDefinition == null) { + reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); + return; + } + + setInitialWidth(); + + // Apply overrides and instantiate parameters for this reactor instance. + for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { + this.parameters.add(new ParameterInstance(parameter, this)); + } + + // Instantiate inputs for this reactor instance + for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { + this.inputs.add(new PortInstance(inputDecl, this, reporter)); + } + + // Instantiate outputs for this reactor instance + for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { + this.outputs.add(new PortInstance(outputDecl, this, reporter)); } - return; - } else if (!dstRanges.hasNext()) { - reporter.reportWarning(connection, "No destination. Outputs will be lost."); - return; - } - - RuntimeRange src = srcRanges.next(); - RuntimeRange dst = dstRanges.next(); - - while (true) { - if (dst.width == src.width) { - connectPortInstances(src, dst, connection); - if (!dstRanges.hasNext()) { - if (srcRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning( - connection, "Source is wider than the destination. Outputs will be lost."); + + // Do not process content (except interface above) if recursive + if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { + // Instantiate children for this reactor instance. + // While doing this, assign an index offset to each. + for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { + var childInstance = new ReactorInstance( + child, + this, + reporter, + desiredDepth + ); + this.children.add(childInstance); } - break; - } - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - if (dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning( - connection, "Destination is wider than the source. Inputs will be missing."); - } - break; + + // Instantiate timers for this reactor instance + for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { + this.timers.add(new TimerInstance(timerDecl, this)); } - } - dst = dstRanges.next(); - src = srcRanges.next(); - } else if (dst.width < src.width) { - // Split the left (src) range in two. - connectPortInstances(src.head(dst.width), dst, connection); - src = src.tail(dst.width); - if (!dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning( - connection, "Source is wider than the destination. Outputs will be lost."); - break; - } - dst = dstRanges.next(); - } else if (src.width < dst.width) { - // Split the right (dst) range in two. - connectPortInstances(src, dst.head(src.width), connection); - dst = dst.tail(src.width); - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - reporter.reportWarning( - connection, "Destination is wider than the source. Inputs will be missing."); - break; + + // Instantiate actions for this reactor instance + for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { + this.actions.add(new ActionInstance(actionDecl, this)); + } + + establishPortConnections(); + + // Create the reaction instances in this reactor instance. + // This also establishes all the implied dependencies. + // Note that this can only happen _after_ the children, + // port, action, and timer instances have been created. + createReactionInstances(); + + // Instantiate modes for this reactor instance + // This must come after the child elements (reactions, etc) of this reactor + // are created in order to allow their association with modes + for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { + this.modes.add(new ModeInstance(modeDecl, this)); + } + for (ModeInstance mode : this.modes) { + mode.setupTranstions(); } - } - src = srcRanges.next(); } - } } - } - - /** - * If path exists from the specified port to any reaction in the specified set of reactions, then - * add the specified port and all ports along the path to the specified set of ports. - * - * @return True if the specified port was added. - */ - private boolean findPaths( - PortInstance port, Set reactions, Set ports) { - if (ports.contains(port)) return false; - boolean result = false; - for (ReactionInstance d : port.getDependentReactions()) { - if (reactions.contains(d)) ports.add(port); - result = true; + + ////////////////////////////////////////////////////// + //// Private methods. + + /** + * Connect the given left port range to the given right port range. + * + * NOTE: This method is public to enable its use in unit tests. + * Otherwise, it should be private. This is why it is defined here, + * in the section labeled "Private methods." + * + * @param src The source range. + * @param dst The destination range. + * @param connection The connection establishing this relationship. + */ + public static void connectPortInstances( + RuntimeRange src, + RuntimeRange dst, + Connection connection + ) { + SendRange range = new SendRange(src, dst, src._interleaved, connection); + src.instance.dependentPorts.add(range); + dst.instance.dependsOnPorts.add(src); } - // Perform a depth-first search. - for (SendRange r : port.dependentPorts) { - for (RuntimeRange p : r.destinations) { - boolean added = findPaths(p.instance, reactions, ports); - if (added) { - result = true; - ports.add(port); + + /** + * Populate connectivity information in the port instances. + * Note that this can only happen _after_ the children and port instances have been created. + * Unfortunately, we have to do some complicated things here + * to support multiport-to-multiport, multiport-to-bank, + * and bank-to-multiport communication. The principle being followed is: + * in each connection statement, for each port instance on the left, + * connect to the next available port on the right. + */ + private void establishPortConnections() { + for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { + List> leftPorts = listPortInstances(connection.getLeftPorts(), connection); + Iterator> srcRanges = leftPorts.iterator(); + List> rightPorts = listPortInstances(connection.getRightPorts(), connection); + Iterator> dstRanges = rightPorts.iterator(); + + // Check for empty lists. + if (!srcRanges.hasNext()) { + if (dstRanges.hasNext()) { + reporter.reportWarning(connection, "No sources to provide inputs."); + } + return; + } else if (!dstRanges.hasNext()) { + reporter.reportWarning(connection, "No destination. Outputs will be lost."); + return; + } + + RuntimeRange src = srcRanges.next(); + RuntimeRange dst = dstRanges.next(); + + while(true) { + if (dst.width == src.width) { + connectPortInstances(src, dst, connection); + if (!dstRanges.hasNext()) { + if (srcRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning(connection, + "Source is wider than the destination. Outputs will be lost."); + } + break; + } + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + if (dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning(connection, + "Destination is wider than the source. Inputs will be missing."); + } + break; + } + } + dst = dstRanges.next(); + src = srcRanges.next(); + } else if (dst.width < src.width) { + // Split the left (src) range in two. + connectPortInstances(src.head(dst.width), dst, connection); + src = src.tail(dst.width); + if (!dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning(connection, + "Source is wider than the destination. Outputs will be lost."); + break; + } + dst = dstRanges.next(); + } else if (src.width < dst.width) { + // Split the right (dst) range in two. + connectPortInstances(src, dst.head(src.width), connection); + dst = dst.tail(src.width); + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + reporter.reportWarning(connection, + "Destination is wider than the source. Inputs will be missing."); + break; + } + } + src = srcRanges.next(); + } + } } - } } - return result; - } - - /** - * Given a list of port references, as found on either side of a connection, return a list of the - * port instance ranges referenced. These may be multiports, and may be ports of a contained bank - * (a port representing ports of the bank members) so the returned list includes ranges of banks - * and channels. - * - *

If a given port reference has the form `interleaved(b.m)`, where `b` is a bank and `m` is a - * multiport, then the corresponding range in the returned list is marked interleaved. - * - *

For example, if `b` and `m` have width 2, without the interleaved keyword, the returned - * range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. With the interleaved marking, the - * returned range represents the sequence `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have - * width 4. - * - * @param references The variable references on one side of the connection. - * @param connection The connection. - */ - private List> listPortInstances( - List references, Connection connection) { - List> result = new ArrayList<>(); - List> tails = new LinkedList<>(); - int count = 0; - for (VarRef portRef : references) { - // Simple error checking first. - if (!(portRef.getVariable() instanceof Port)) { - reporter.reportError(portRef, "Not a port."); - return result; - } - // First, figure out which reactor we are dealing with. - // The reactor we want is the container of the port. - // If the port reference has no container, then the reactor is this one. - var reactor = this; - if (portRef.getContainer() != null) { - reactor = getChildReactorInstance(portRef.getContainer()); - } - // The reactor can be null only if there is an error in the code. - // Skip this portRef so that diagram synthesis can complete. - if (reactor != null) { - PortInstance portInstance = reactor.lookupPortInstance((Port) portRef.getVariable()); - - Set interleaved = new LinkedHashSet<>(); - if (portRef.isInterleaved()) { - // NOTE: Here, we are assuming that the interleaved() - // keyword is only allowed on the multiports contained by - // contained reactors. - interleaved.add(portInstance.parent); + + /** + * If path exists from the specified port to any reaction in the specified + * set of reactions, then add the specified port and all ports along the path + * to the specified set of ports. + * @return True if the specified port was added. + */ + private boolean findPaths( + PortInstance port, + Set reactions, + Set ports + ) { + if (ports.contains(port)) return false; + boolean result = false; + for (ReactionInstance d : port.getDependentReactions()) { + if (reactions.contains(d)) ports.add(port); + result = true; } - RuntimeRange range = new RuntimeRange.Port(portInstance, interleaved); - // If this portRef is not the last one in the references list - // then we have to check whether the range can be incremented at - // the lowest two levels (port and container). If not, - // split the range and add the tail to list to iterate over again. - // The reason for this is that the connection has only local visibility, - // but the range width may be reflective of bank structure higher - // in the hierarchy. - if (count < references.size() - 1) { - int portWidth = portInstance.width; - int portParentWidth = portInstance.parent.width; - // If the port is being connected on the inside and there is - // more than one port in the list, then we can only connect one - // bank member at a time. - if (reactor == this && references.size() > 1) { - portParentWidth = 1; - } - int widthBound = portWidth * portParentWidth; - - // If either of these widths cannot be determined, assume infinite. - if (portWidth < 0) widthBound = Integer.MAX_VALUE; - if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < range.width) { - // Need to split the range. - tails.add(range.tail(widthBound)); - range = range.head(widthBound); - } + // Perform a depth-first search. + for (SendRange r : port.dependentPorts) { + for (RuntimeRange p : r.destinations) { + boolean added = findPaths(p.instance, reactions, ports); + if (added) { + result = true; + ports.add(port); + } + } } - result.add(range); - } + return result; } - // Iterate over the tails. - while (tails.size() > 0) { - List> moreTails = new LinkedList<>(); - count = 0; - for (RuntimeRange tail : tails) { - if (count < tails.size() - 1) { - int widthBound = tail.instance.width; - if (tail._interleaved.contains(tail.instance.parent)) { - widthBound = tail.instance.parent.width; - } - // If the width cannot be determined, assume infinite. - if (widthBound < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < tail.width) { - // Need to split the range again - moreTails.add(tail.tail(widthBound)); - tail = tail.head(widthBound); - } + + /** + * Given a list of port references, as found on either side of a connection, + * return a list of the port instance ranges referenced. These may be multiports, + * and may be ports of a contained bank (a port representing ports of the bank + * members) so the returned list includes ranges of banks and channels. + * + * If a given port reference has the form `interleaved(b.m)`, where `b` is + * a bank and `m` is a multiport, then the corresponding range in the returned + * list is marked interleaved. + * + * For example, if `b` and `m` have width 2, without the interleaved keyword, + * the returned range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. + * With the interleaved marking, the returned range represents the sequence + * `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have width 4. + * + * @param references The variable references on one side of the connection. + * @param connection The connection. + */ + private List> listPortInstances( + List references, Connection connection + ) { + List> result = new ArrayList<>(); + List> tails = new LinkedList<>(); + int count = 0; + for (VarRef portRef : references) { + // Simple error checking first. + if (!(portRef.getVariable() instanceof Port)) { + reporter.reportError(portRef, "Not a port."); + return result; + } + // First, figure out which reactor we are dealing with. + // The reactor we want is the container of the port. + // If the port reference has no container, then the reactor is this one. + var reactor = this; + if (portRef.getContainer() != null) { + reactor = getChildReactorInstance(portRef.getContainer()); + } + // The reactor can be null only if there is an error in the code. + // Skip this portRef so that diagram synthesis can complete. + if (reactor != null) { + PortInstance portInstance = reactor.lookupPortInstance( + (Port) portRef.getVariable()); + + Set interleaved = new LinkedHashSet<>(); + if (portRef.isInterleaved()) { + // NOTE: Here, we are assuming that the interleaved() + // keyword is only allowed on the multiports contained by + // contained reactors. + interleaved.add(portInstance.parent); + } + RuntimeRange range = new RuntimeRange.Port( + portInstance, interleaved); + // If this portRef is not the last one in the references list + // then we have to check whether the range can be incremented at + // the lowest two levels (port and container). If not, + // split the range and add the tail to list to iterate over again. + // The reason for this is that the connection has only local visibility, + // but the range width may be reflective of bank structure higher + // in the hierarchy. + if (count < references.size() - 1) { + int portWidth = portInstance.width; + int portParentWidth = portInstance.parent.width; + // If the port is being connected on the inside and there is + // more than one port in the list, then we can only connect one + // bank member at a time. + if (reactor == this && references.size() > 1) { + portParentWidth = 1; + } + int widthBound = portWidth * portParentWidth; + + // If either of these widths cannot be determined, assume infinite. + if (portWidth < 0) widthBound = Integer.MAX_VALUE; + if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < range.width) { + // Need to split the range. + tails.add(range.tail(widthBound)); + range = range.head(widthBound); + } + } + result.add(range); + } + } + // Iterate over the tails. + while(tails.size() > 0) { + List> moreTails = new LinkedList<>(); + count = 0; + for (RuntimeRange tail : tails) { + if (count < tails.size() - 1) { + int widthBound = tail.instance.width; + if (tail._interleaved.contains(tail.instance.parent)) { + widthBound = tail.instance.parent.width; + } + // If the width cannot be determined, assume infinite. + if (widthBound < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < tail.width) { + // Need to split the range again + moreTails.add(tail.tail(widthBound)); + tail = tail.head(widthBound); + } + } + result.add(tail); + } + tails = moreTails; } - result.add(tail); - } - tails = moreTails; + return result; } - return result; - } - - /** - * If this is a bank of reactors, set the width. It will be set to -1 if it cannot be determined. - */ - private void setInitialWidth() { - WidthSpec widthSpec = definition.getWidthSpec(); - if (widthSpec != null) { - // We need the instantiations list of the containing reactor, - // not this one. - width = ASTUtils.width(widthSpec, parent.instantiations()); + + /** + * If this is a bank of reactors, set the width. + * It will be set to -1 if it cannot be determined. + */ + private void setInitialWidth() { + WidthSpec widthSpec = definition.getWidthSpec(); + if (widthSpec != null) { + // We need the instantiations list of the containing reactor, + // not this one. + width = ASTUtils.width(widthSpec, parent.instantiations()); + } } - } - - ////////////////////////////////////////////////////// - //// Private fields. - - /** Cached set of reactions and ports that form a causality loop. */ - private Set> cachedCycles; - - /** Cached reaction graph containing reactions that form a causality loop. */ - private ReactionInstanceGraph cachedReactionLoopGraph = null; - - /** - * Return true if this is a generated delay reactor that originates from an "after" delay on a - * connection. - * - * @return True if this is a generated delay, false otherwise. - */ - public boolean isGeneratedDelay() { - if (this.definition - .getReactorClass() - .getName() - .contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME)) { - return true; + + ////////////////////////////////////////////////////// + //// Private fields. + + /** + * Cached set of reactions and ports that form a causality loop. + */ + private Set> cachedCycles; + + /** + * Cached reaction graph containing reactions that form a causality loop. + */ + private ReactionInstanceGraph cachedReactionLoopGraph = null; + + /** + * Return true if this is a generated delay reactor that originates from + * an "after" delay on a connection. + * + * @return True if this is a generated delay, false otherwise. + */ + public boolean isGeneratedDelay() { + // FIXME: hacky string matching again... + if (this.definition.getReactorClass().getName().contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME)) { + return true; + } + return false; } - return false; - } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index a203f9ee3c..3dd1aef157 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.Set; + import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; @@ -37,1353 +38,1159 @@ import org.lflang.util.StringUtil; 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) + protected static String DISABLE_REACTION_INITIALIZATION_MARKER + = "// **** Do not include initialization code in this reaction."; // FIXME: Such markers should not exist (#1687) - /** - * Generate necessary initialization code inside the body of the reaction that belongs to reactor - * decl. - * - * @param body The body of the reaction. Used to check for the - * DISABLE_REACTION_INITIALIZATION_MARKER. - * @param reaction The initialization code will be generated for this specific reaction - * @param decl The reactor that has the reaction - * @param reactionIndex The index of the reaction relative to other reactions in the reactor, - * starting from 0 - */ - public static String generateInitializationForReaction( - String body, - Reaction reaction, - Reactor decl, - int reactionIndex, - CTypes types, - ErrorReporter errorReporter, - Instantiation mainDef, - boolean requiresTypes) { - Reactor reactor = ASTUtils.toDefinition(decl); + /** + * Generate necessary initialization code inside the body of the reaction that belongs to reactor decl. + * @param body The body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER. + * @param reaction The initialization code will be generated for this specific reaction + * @param decl The reactor that has the reaction + * @param reactionIndex The index of the reaction relative to other reactions in the reactor, starting from 0 + */ + public static String generateInitializationForReaction(String body, + Reaction reaction, + Reactor decl, + int reactionIndex, + CTypes types, + ErrorReporter errorReporter, + Instantiation mainDef, + boolean requiresTypes) { + Reactor reactor = ASTUtils.toDefinition(decl); - // Construct the reactionInitialization code to go into - // the body of the function before the verbatim code. - CodeBuilder reactionInitialization = new CodeBuilder(); + // Construct the reactionInitialization code to go into + // the body of the function before the verbatim code. + CodeBuilder reactionInitialization = new CodeBuilder(); - CodeBuilder code = new CodeBuilder(); + CodeBuilder code = new CodeBuilder(); - // Define the "self" struct. - String structType = CUtil.selfType(decl); - // A null structType means there are no inputs, state, - // or anything else. No need to declare it. - if (structType != null) { - code.pr( - String.join( - "\n", - structType - + "* self = (" - + structType - + "*)instance_args; SUPPRESS_UNUSED_WARNING(self);")); - } + // Define the "self" struct. + String structType = CUtil.selfType(decl); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr(String.join("\n", + structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" + )); + } - // Do not generate the initialization code if the body is marked - // to not generate it. - if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { - return code.toString(); - } + // Do not generate the initialization code if the body is marked + // to not generate it. + if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { + return code.toString(); + } - // A reaction may send to or receive from multiple ports of - // a contained reactor. The variables for these ports need to - // all be declared as fields of the same struct. Hence, we first - // collect the fields to be defined in the structs and then - // generate the structs. - Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); + // A reaction may send to or receive from multiple ports of + // a contained reactor. The variables for these ports need to + // all be declared as fields of the same struct. Hence, we first + // collect the fields to be defined in the structs and then + // generate the structs. + Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); - // Actions may appear twice, first as a trigger, then with the outputs. - // But we need to declare it only once. Collect in this data structure - // the actions that are declared as triggered so that if they appear - // again with the outputs, they are not defined a second time. - // That second redefinition would trigger a compile error. - Set actionsAsTriggers = new LinkedHashSet<>(); + // Actions may appear twice, first as a trigger, then with the outputs. + // But we need to declare it only once. Collect in this data structure + // the actions that are declared as triggered so that if they appear + // again with the outputs, they are not defined a second time. + // That second redefinition would trigger a compile error. + Set actionsAsTriggers = new LinkedHashSet<>(); - // Next, add the triggers (input and actions; timers are not needed). - // This defines a local variable in the reaction function whose - // name matches that of the trigger. The value of the local variable - // is a struct with a value and is_present field, the latter a boolean - // that indicates whether the input/action is present. - // If the trigger is an output, then it is an output of a - // contained reactor. In this case, a struct with the name - // of the contained reactor is created with one field that is - // a pointer to a struct with a value and is_present field. - // E.g., if the contained reactor is named 'c' and its output - // port is named 'out', then c.out->value c.out->is_present are - // defined so that they can be used in the verbatim code. - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (triggerAsVarRef.getVariable() instanceof Port) { - generatePortVariablesInReaction( - reactionInitialization, - fieldsForStructsForContainedReactors, - triggerAsVarRef, - decl, - types); - } else if (triggerAsVarRef.getVariable() instanceof Action) { - reactionInitialization.pr( - generateActionVariablesInReaction( - (Action) triggerAsVarRef.getVariable(), decl, types)); - actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); + // Next, add the triggers (input and actions; timers are not needed). + // This defines a local variable in the reaction function whose + // name matches that of the trigger. The value of the local variable + // is a struct with a value and is_present field, the latter a boolean + // that indicates whether the input/action is present. + // If the trigger is an output, then it is an output of a + // contained reactor. In this case, a struct with the name + // of the contained reactor is created with one field that is + // a pointer to a struct with a value and is_present field. + // E.g., if the contained reactor is named 'c' and its output + // port is named 'out', then c.out->value c.out->is_present are + // defined so that they can be used in the verbatim code. + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (triggerAsVarRef.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, + fieldsForStructsForContainedReactors, + triggerAsVarRef, + decl, + types); + } else if (triggerAsVarRef.getVariable() instanceof Action) { + reactionInitialization.pr(generateActionVariablesInReaction( + (Action) triggerAsVarRef.getVariable(), + decl, + types + )); + actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); + } + } + } + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + // No triggers are given, which means react to any input. + // Declare an argument for every input. + // NOTE: this does not include contained outputs. + for (Input input : reactor.getInputs()) { + reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); + } + } + // Define argument for non-triggering inputs. + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (src.getVariable() instanceof Port) { + generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); + } else if (src.getVariable() instanceof Action) { + // It's a bit odd to read but not be triggered by an action, but + // OK, I guess we allow it. + reactionInitialization.pr(generateActionVariablesInReaction( + (Action) src.getVariable(), + decl, + types + )); + actionsAsTriggers.add((Action) src.getVariable()); + } } - } - } - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - // No triggers are given, which means react to any input. - // Declare an argument for every input. - // NOTE: this does not include contained outputs. - for (Input input : reactor.getInputs()) { - reactionInitialization.pr(generateInputVariablesInReaction(input, decl, types)); - } - } - // Define argument for non-triggering inputs. - for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - if (src.getVariable() instanceof Port) { - generatePortVariablesInReaction( - reactionInitialization, fieldsForStructsForContainedReactors, src, decl, types); - } else if (src.getVariable() instanceof Action) { - // It's a bit odd to read but not be triggered by an action, but - // OK, I guess we allow it. - reactionInitialization.pr( - generateActionVariablesInReaction((Action) src.getVariable(), decl, types)); - actionsAsTriggers.add((Action) src.getVariable()); - } - } - // Define variables for each declared output or action. - // In the case of outputs, the variable is a pointer to where the - // output is stored. This gives the reaction code access to any previous - // value that may have been written to that output in an earlier reaction. - if (reaction.getEffects() != null) { - for (VarRef effect : reaction.getEffects()) { - Variable variable = effect.getVariable(); - if (variable instanceof Action) { - // It is an action, not an output. - // If it has already appeared as trigger, do not redefine it. - if (!actionsAsTriggers.contains(effect.getVariable())) { - reactionInitialization.pr( - CGenerator.variableStructType(variable, decl, false) - + "* " - + variable.getName() - + " = &self->_lf_" - + variable.getName() - + ";"); - } - } else if (effect.getVariable() instanceof Mode) { - // Mode change effect - int idx = ASTUtils.allModes(reactor).indexOf((Mode) effect.getVariable()); - String name = effect.getVariable().getName(); - if (idx >= 0) { - reactionInitialization.pr( - "reactor_mode_t* " - + name - + " = &self->_lf__modes[" - + idx - + "];\n" - + "lf_mode_change_type_t _lf_" - + name - + "_change_type = " - + (effect.getTransition() == ModeTransition.HISTORY - ? "history_transition" - : "reset_transition") - + ";"); - } else { - errorReporter.reportError( - reaction, "In generateReaction(): " + name + " not a valid mode of this reactor."); - } - } else { - if (variable instanceof Output) { - reactionInitialization.pr( - generateOutputVariablesInReaction(effect, decl, errorReporter, requiresTypes)); - } else if (variable instanceof Input) { - // It is the input of a contained reactor. - generateVariablesForSendingToContainedReactors( - reactionInitialization, - fieldsForStructsForContainedReactors, - effect.getContainer(), - (Input) variable); - } else if (variable instanceof Watchdog) { - reactionInitialization.pr(generateWatchdogVariablesInReaction(effect, decl)); - } else { - errorReporter.reportError( - reaction, "In generateReaction(): effect is neither an input nor an output."); - } + // Define variables for each declared output or action. + // In the case of outputs, the variable is a pointer to where the + // output is stored. This gives the reaction code access to any previous + // value that may have been written to that output in an earlier reaction. + if (reaction.getEffects() != null) { + for (VarRef effect : reaction.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Action) { + // It is an action, not an output. + // If it has already appeared as trigger, do not redefine it. + if (!actionsAsTriggers.contains(effect.getVariable())) { + reactionInitialization.pr(CGenerator.variableStructType(variable, decl, false)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); + } + } else if (effect.getVariable() instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(reactor).indexOf((Mode)effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + reactionInitialization.pr( + "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" + + "lf_mode_change_type_t _lf_" + name + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY ? + "history_transition" : "reset_transition") + + ";" + ); + } else { + errorReporter.reportError( + reaction, + "In generateReaction(): " + name + " not a valid mode of this reactor." + ); + } + } else { + if (variable instanceof Output) { + reactionInitialization.pr(generateOutputVariablesInReaction( + effect, + decl, + errorReporter, + requiresTypes + )); + } else if (variable instanceof Input) { + // It is the input of a contained reactor. + generateVariablesForSendingToContainedReactors( + reactionInitialization, + fieldsForStructsForContainedReactors, + effect.getContainer(), + (Input) variable); + } else if (variable instanceof Watchdog) { + reactionInitialization.pr(generateWatchdogVariablesInReaction(effect, decl)); + } else { + errorReporter.reportError( + reaction, + "In generateReaction(): effect is not an input, output, or watchdog." + ); + } + } + } } - } - } - // Before the reaction initialization, - // generate the structs used for communication to and from contained reactors. - for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - String array = ""; - if (containedReactor.getWidthSpec() != null) { - String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); - code.pr( - "int " + containedReactorWidthVar + " = self->_lf_" + containedReactorWidthVar + ";"); - // Windows does not support variables in arrays declared on the stack, - // so we use the maximum size over all bank members. - array = "[" + maxContainedReactorBankWidth(containedReactor, null, 0, mainDef) + "]"; - } - code.pr( - String.join( - "\n", - "struct " + containedReactor.getName() + " {", - " " + fieldsForStructsForContainedReactors.get(containedReactor) + "", - "} " + containedReactor.getName() + array + ";")); + // Before the reaction initialization, + // generate the structs used for communication to and from contained reactors. + for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { + String array = ""; + if (containedReactor.getWidthSpec() != null) { + String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); + code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); + // Windows does not support variables in arrays declared on the stack, + // so we use the maximum size over all bank members. + array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; + } + code.pr(String.join("\n", + "struct "+containedReactor.getName()+" {", + " "+fieldsForStructsForContainedReactors.get(containedReactor)+"", + "} "+containedReactor.getName()+array+";" + )); + } + // Next generate all the collected setup code. + code.pr(reactionInitialization.toString()); + return code.toString(); } - // Next generate all the collected setup code. - code.pr(reactionInitialization.toString()); - return code.toString(); - } - /** - * Return the maximum bank width for the given instantiation within all instantiations of its - * parent reactor. On the first call to this method, the breadcrumbs should be null and the max - * argument should be zero. On recursive calls, breadcrumbs is a list of nested instantiations, - * the max is the maximum width found so far. The search for instances of the parent reactor will - * begin with the last instantiation in the specified list. - * - *

This rather complicated method is used when a reaction sends or receives data to or from a - * bank of contained reactors. There will be an array of structs on the self struct of the parent, - * and the size of the array is conservatively set to the maximum of all the identified bank - * widths. This is a bit wasteful of memory, but it avoids having to malloc the array for each - * instance, and in typical usage, there will be few instances or instances that are all the same - * width. - * - * @param containedReactor The contained reactor instantiation. - * @param breadcrumbs null on first call (non-recursive). - * @param max 0 on first call. - */ - public static int maxContainedReactorBankWidth( - Instantiation containedReactor, - LinkedList breadcrumbs, - int max, - Instantiation mainDef) { - // If the instantiation is not a bank, return 1. - if (containedReactor.getWidthSpec() == null) { - return 1; - } - // If there is no main, then we just use the default width. - if (mainDef == null) { - return ASTUtils.width(containedReactor.getWidthSpec(), null); + /** + * Return the maximum bank width for the given instantiation within all + * instantiations of its parent reactor. + * On the first call to this method, the breadcrumbs should be null and the max + * argument should be zero. On recursive calls, breadcrumbs is a list of nested + * instantiations, the max is the maximum width found so far. The search for + * instances of the parent reactor will begin with the last instantiation + * in the specified list. + * + * This rather complicated method is used when a reaction sends or receives data + * to or from a bank of contained reactors. There will be an array of structs on + * the self struct of the parent, and the size of the array is conservatively set + * to the maximum of all the identified bank widths. This is a bit wasteful of + * memory, but it avoids having to malloc the array for each instance, and in + * typical usage, there will be few instances or instances that are all the same + * width. + * + * @param containedReactor The contained reactor instantiation. + * @param breadcrumbs null on first call (non-recursive). + * @param max 0 on first call. + */ + public static int maxContainedReactorBankWidth( + Instantiation containedReactor, + LinkedList breadcrumbs, + int max, + Instantiation mainDef + ) { + // If the instantiation is not a bank, return 1. + if (containedReactor.getWidthSpec() == null) { + return 1; + } + // If there is no main, then we just use the default width. + if (mainDef == null) { + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + LinkedList nestedBreadcrumbs = breadcrumbs; + if (nestedBreadcrumbs == null) { + nestedBreadcrumbs = new LinkedList<>(); + nestedBreadcrumbs.add(mainDef); + } + int result = max; + Reactor parent = (Reactor) containedReactor.eContainer(); + if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { + // The parent is main, so there can't be any other instantiations of it. + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + // Search for instances of the parent within the tail of the breadcrumbs list. + Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); + for (Instantiation instantiation : container.getInstantiations()) { + // Put this new instantiation at the head of the list. + nestedBreadcrumbs.add(0, instantiation); + if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { + // Found a matching instantiation of the parent. + // Evaluate the original width specification in this context. + int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); + if (candidate > result) { + result = candidate; + } + } else { + // Found some other instantiation, not the parent. + // Search within it for instantiations of the parent. + // Note that we assume here that the parent cannot contain + // instances of itself. + int candidate = maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); + if (candidate > result) { + result = candidate; + } + } + nestedBreadcrumbs.remove(); + } + return result; } - LinkedList nestedBreadcrumbs = breadcrumbs; - if (nestedBreadcrumbs == null) { - nestedBreadcrumbs = new LinkedList<>(); - nestedBreadcrumbs.add(mainDef); + + /** + * Generate code for the body of a reaction that takes an input and + * schedules an action with the value of that input. + * @param actionName The action to schedule + */ + public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { + // Note that the action.type set by the base class is actually + // the port type. + return isTokenType ? + String.join("\n", + "if ("+ref+"->is_present) {", + " // Put the whole token on the event queue, not just the payload.", + " // This way, the length and element_size are transported.", + " lf_schedule_token("+actionName+", 0, "+ref+"->token);", + "}" + ) : + "lf_schedule_copy("+actionName+", 0, &"+ref+"->value, 1); // Length is 1."; } - int result = max; - Reactor parent = (Reactor) containedReactor.eContainer(); - if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { - // The parent is main, so there can't be any other instantiations of it. - return ASTUtils.width(containedReactor.getWidthSpec(), null); + + public static String generateForwardBody(String outputName, String targetType, String actionName, boolean isTokenType) { + return isTokenType ? + String.join("\n", + DISABLE_REACTION_INITIALIZATION_MARKER, + "self->_lf_"+outputName+".value = ("+targetType+")self->_lf__"+actionName+".tmplt.token->value;", + "_lf_replace_template_token((token_template_t*)&self->_lf_"+outputName+", (lf_token_t*)self->_lf__"+actionName+".tmplt.token);", + "self->_lf_"+outputName+".is_present = true;" + ) : + "lf_set("+outputName+", "+actionName+"->value);"; } - // Search for instances of the parent within the tail of the breadcrumbs list. - Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); - for (Instantiation instantiation : container.getInstantiations()) { - // Put this new instantiation at the head of the list. - nestedBreadcrumbs.add(0, instantiation); - if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { - // Found a matching instantiation of the parent. - // Evaluate the original width specification in this context. - int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); - if (candidate > result) { - result = candidate; + + /** + * Generate into the specified string builder the code to + * initialize local variables for sending data to an input + * of a contained reactor. This will also, if necessary, + * generate entries for local struct definitions into the + * struct argument. These entries point to where the data + * is stored. + * + * @param builder The string builder. + * @param structs A map from reactor instantiations to a place to write + * struct fields. + * @param definition AST node defining the reactor within which this occurs + * @param input Input of the contained reactor. + */ + private static void generateVariablesForSendingToContainedReactors( + CodeBuilder builder, + Map structs, + Instantiation definition, + Input input + ) { + CodeBuilder structBuilder = structs.get(definition); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(definition, structBuilder); } - } else { - // Found some other instantiation, not the parent. - // Search within it for instantiations of the parent. - // Note that we assume here that the parent cannot contain - // instances of itself. - int candidate = - maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); - if (candidate > result) { - result = candidate; + String inputStructType = CGenerator.variableStructType(input, ASTUtils.toDefinition(definition.getReactorClass()), false); + String defName = definition.getName(); + String defWidth = generateWidthVariable(defName); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); + if (!ASTUtils.isMultiport(input)) { + // Contained reactor's input is not a multiport. + structBuilder.pr(inputStructType+"* "+inputName+";"); + if (definition.getWidthSpec() != null) { + // Contained reactor is a bank. + builder.pr(String.join("\n", + "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", + " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", + "}" + )); + } else { + // Contained reactor is not a bank. + builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); + } + } else { + // Contained reactor's input is a multiport. + structBuilder.pr(String.join("\n", + inputStructType+"** "+inputName+";", + "int "+inputWidth+";" + )); + // If the contained reactor is a bank, then we have to set the + // pointer for each element of the bank. + if (definition.getWidthSpec() != null) { + builder.pr(String.join("\n", + "for (int _i = 0; _i < self->_lf_"+defWidth+"; _i++) {", + " "+defName+"[_i]."+inputName+" = self->_lf_"+defName+"[_i]."+inputName+";", + " "+defName+"[_i]."+inputWidth+" = self->_lf_"+defName+"[_i]."+inputWidth+";", + "}" + )); + } else { + builder.pr(String.join("\n", + defName+"."+inputName+" = self->_lf_"+defName+"."+inputName+";", + defName+"."+inputWidth+" = self->_lf_"+defName+"."+inputWidth+";" + )); + } } - } - nestedBreadcrumbs.remove(); } - return result; - } - /** - * Generate code for the body of a reaction that takes an input and schedules an action with the - * value of that input. - * - * @param actionName The action to schedule - */ - public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { - // Note that the action.type set by the base class is actually - // the port type. - return isTokenType - ? String.join( - "\n", - "if (" + ref + "->is_present) {", - " // Put the whole token on the event queue, not just the payload.", - " // This way, the length and element_size are transported.", - " lf_schedule_token(" + actionName + ", 0, " + ref + "->token);", - "}") - : "lf_schedule_copy(" + actionName + ", 0, &" + ref + "->value, 1); // Length is 1."; - } + /** + * Generate into the specified string builder the code to + * initialize local variables for ports in a reaction function + * from the "self" struct. The port may be an input of the + * reactor or an output of a contained reactor. The second + * argument provides, for each contained reactor, a place to + * write the declaration of the output of that reactor that + * is triggering reactions. + * @param builder The place into which to write the code. + * @param structs A map from reactor instantiations to a place to write + * struct fields. + */ + private static void generatePortVariablesInReaction( + CodeBuilder builder, + Map structs, + VarRef port, + Reactor r, + CTypes types + ) { + if (port.getVariable() instanceof Input) { + builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), r, types)); + } else { + // port is an output of a contained reactor. + Output output = (Output) port.getVariable(); + String portStructType = CGenerator.variableStructType(output, ASTUtils.toDefinition(port.getContainer().getReactorClass()), false); - public static String generateForwardBody( - String outputName, String targetType, String actionName, boolean isTokenType) { - return isTokenType - ? String.join( - "\n", - DISABLE_REACTION_INITIALIZATION_MARKER, - "self->_lf_" - + outputName - + ".value = (" - + targetType - + ")self->_lf__" - + actionName - + ".tmplt.token->value;", - "_lf_replace_template_token((token_template_t*)&self->_lf_" - + outputName - + ", (lf_token_t*)self->_lf__" - + actionName - + ".tmplt.token);", - "self->_lf_" + outputName + ".is_present = true;") - : "lf_set(" + outputName + ", " + actionName + "->value);"; - } + CodeBuilder structBuilder = structs.get(port.getContainer()); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(port.getContainer(), structBuilder); + } + String reactorName = port.getContainer().getName(); + String reactorWidth = generateWidthVariable(reactorName); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + // First define the struct containing the output value and indicator + // of its presence. + if (!ASTUtils.isMultiport(output)) { + // Output is not a multiport. + structBuilder.pr(portStructType+"* "+outputName+";"); + } else { + // Output is a multiport. + structBuilder.pr(String.join("\n", + portStructType+"** "+outputName+";", + "int "+outputWidth+";" + )); + } - /** - * Generate into the specified string builder the code to initialize local variables for sending - * data to an input of a contained reactor. This will also, if necessary, generate entries for - * local struct definitions into the struct argument. These entries point to where the data is - * stored. - * - * @param builder The string builder. - * @param structs A map from reactor instantiations to a place to write struct fields. - * @param definition AST node defining the reactor within which this occurs - * @param input Input of the contained reactor. - */ - private static void generateVariablesForSendingToContainedReactors( - CodeBuilder builder, - Map structs, - Instantiation definition, - Input input) { - CodeBuilder structBuilder = structs.get(definition); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(definition, structBuilder); - } - String inputStructType = - CGenerator.variableStructType( - input, ASTUtils.toDefinition(definition.getReactorClass()), false); - String defName = definition.getName(); - String defWidth = generateWidthVariable(defName); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); - if (!ASTUtils.isMultiport(input)) { - // Contained reactor's input is not a multiport. - structBuilder.pr(inputStructType + "* " + inputName + ";"); - if (definition.getWidthSpec() != null) { - // Contained reactor is a bank. - builder.pr( - String.join( - "\n", - "for (int bankIndex = 0; bankIndex < self->_lf_" + defWidth + "; bankIndex++) {", - " " - + defName - + "[bankIndex]." - + inputName - + " = &(self->_lf_" - + defName - + "[bankIndex]." - + inputName - + ");", - "}")); - } else { - // Contained reactor is not a bank. - builder.pr( - defName + "." + inputName + " = &(self->_lf_" + defName + "." + inputName + ");"); - } - } else { - // Contained reactor's input is a multiport. - structBuilder.pr( - String.join("\n", inputStructType + "** " + inputName + ";", "int " + inputWidth + ";")); - // If the contained reactor is a bank, then we have to set the - // pointer for each element of the bank. - if (definition.getWidthSpec() != null) { - builder.pr( - String.join( - "\n", - "for (int _i = 0; _i < self->_lf_" + defWidth + "; _i++) {", - " " - + defName - + "[_i]." - + inputName - + " = self->_lf_" - + defName - + "[_i]." - + inputName - + ";", - " " - + defName - + "[_i]." - + inputWidth - + " = self->_lf_" - + defName - + "[_i]." - + inputWidth - + ";", - "}")); - } else { - builder.pr( - String.join( - "\n", - defName + "." + inputName + " = self->_lf_" + defName + "." + inputName + ";", - defName + "." + inputWidth + " = self->_lf_" + defName + "." + inputWidth + ";")); - } + // Next, initialize the struct with the current values. + if (port.getContainer().getWidthSpec() != null) { + // Output is in a bank. + builder.pr(String.join("\n", + "for (int i = 0; i < "+reactorWidth+"; i++) {", + " "+reactorName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", + "}" + )); + if (ASTUtils.isMultiport(output)) { + builder.pr(String.join("\n", + "for (int i = 0; i < "+reactorWidth+"; i++) {", + " "+reactorName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", + "}" + )); + } + } else { + // Output is not in a bank. + builder.pr(reactorName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); + if (ASTUtils.isMultiport(output)) { + builder.pr(reactorName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); + } + } + } } - } - - /** - * Generate into the specified string builder the code to initialize local variables for ports in - * a reaction function from the "self" struct. The port may be an input of the reactor or an - * output of a contained reactor. The second argument provides, for each contained reactor, a - * place to write the declaration of the output of that reactor that is triggering reactions. - * - * @param builder The place into which to write the code. - * @param structs A map from reactor instantiations to a place to write struct fields. - */ - private static void generatePortVariablesInReaction( - CodeBuilder builder, - Map structs, - VarRef port, - Reactor r, - CTypes types) { - if (port.getVariable() instanceof Input) { - builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), r, types)); - } else { - // port is an output of a contained reactor. - Output output = (Output) port.getVariable(); - String portStructType = - CGenerator.variableStructType( - output, ASTUtils.toDefinition(port.getContainer().getReactorClass()), false); - CodeBuilder structBuilder = structs.get(port.getContainer()); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(port.getContainer(), structBuilder); - } - String reactorName = port.getContainer().getName(); - String reactorWidth = generateWidthVariable(reactorName); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - // First define the struct containing the output value and indicator - // of its presence. - if (!ASTUtils.isMultiport(output)) { - // Output is not a multiport. - structBuilder.pr(portStructType + "* " + outputName + ";"); - } else { - // Output is a multiport. - structBuilder.pr( - String.join( - "\n", portStructType + "** " + outputName + ";", "int " + outputWidth + ";")); - } + /** Generate action variables for a reaction. + * @param action The action. + */ + private static String generateActionVariablesInReaction( + Action action, + Reactor r, + CTypes types + ) { + String structType = CGenerator.variableStructType(action, r, false); + // If the action has a type, create variables for accessing the value. + InferredType type = ASTUtils.getInferredType(action); + // Pointer to the lf_token_t sent as the payload in the trigger. + String tokenPointer = "(self->_lf__"+action.getName()+".tmplt.token)"; + CodeBuilder builder = new CodeBuilder(); - // Next, initialize the struct with the current values. - if (port.getContainer().getWidthSpec() != null) { - // Output is in a bank. - builder.pr( - String.join( - "\n", - "for (int i = 0; i < " + reactorWidth + "; i++) {", - " " - + reactorName - + "[i]." - + outputName - + " = self->_lf_" - + reactorName - + "[i]." - + outputName - + ";", - "}")); - if (ASTUtils.isMultiport(output)) { - builder.pr( - String.join( - "\n", - "for (int i = 0; i < " + reactorWidth + "; i++) {", - " " - + reactorName - + "[i]." - + outputWidth - + " = self->_lf_" - + reactorName - + "[i]." - + outputWidth - + ";", - "}")); - } - } else { - // Output is not in a bank. builder.pr( - reactorName - + "." - + outputName - + " = self->_lf_" - + reactorName - + "." - + outputName - + ";"); - if (ASTUtils.isMultiport(output)) { - builder.pr( - reactorName - + "." - + outputWidth - + " = self->_lf_" - + reactorName - + "." - + outputWidth - + ";"); + String.join("\n", + "// Expose the action struct as a local variable whose name matches the action name.", + structType+"* "+action.getName()+" = &self->_lf_"+action.getName()+";", + "// Set the fields of the action struct to match the current trigger.", + action.getName()+"->is_present = (bool)self->_lf__"+action.getName()+".status;", + action.getName()+"->has_value = ("+tokenPointer+" != NULL && "+tokenPointer+"->value != NULL);", + "_lf_replace_template_token((token_template_t*)"+action.getName()+", "+tokenPointer+");") + ); + // Set the value field only if there is a type. + if (!type.isUndefined()) { + // The value field will either be a copy (for primitive types) + // or a pointer (for types ending in *). + builder.pr("if ("+action.getName()+"->has_value) {"); + builder.indent(); + if (CUtil.isTokenType(type, types)) { + builder.pr(action.getName()+"->value = ("+types.getTargetType(type)+")"+tokenPointer+"->value;"); + } else { + builder.pr(action.getName()+"->value = *("+types.getTargetType(type)+"*)"+tokenPointer+"->value;"); + } + builder.unindent(); + builder.pr("}"); } - } + return builder.toString(); } - } - /** - * Generate action variables for a reaction. - * - * @param action The action. - */ - private static String generateActionVariablesInReaction(Action action, Reactor r, CTypes types) { - String structType = CGenerator.variableStructType(action, r, false); - // If the action has a type, create variables for accessing the value. - InferredType type = ASTUtils.getInferredType(action); - // Pointer to the lf_token_t sent as the payload in the trigger. - String tokenPointer = "(self->_lf__" + action.getName() + ".tmplt.token)"; - CodeBuilder builder = new CodeBuilder(); + /** Generate into the specified string builder the code to + * initialize local variables for the specified input port + * in a reaction function from the "self" struct. + * @param input The input statement from the AST. + * @param r The reactor. + */ + private static String generateInputVariablesInReaction( + Input input, + Reactor r, + CTypes types + ) { + String structType = CGenerator.variableStructType(input, r, false); + InferredType inputType = ASTUtils.getInferredType(input); + CodeBuilder builder = new CodeBuilder(); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); - builder.pr( - String.join( - "\n", - "// Expose the action struct as a local variable whose name matches the action name.", - structType + "* " + action.getName() + " = &self->_lf_" + action.getName() + ";", - "// Set the fields of the action struct to match the current trigger.", - action.getName() + "->is_present = (bool)self->_lf__" + action.getName() + ".status;", - action.getName() - + "->has_value = (" - + tokenPointer - + " != NULL && " - + tokenPointer - + "->value != NULL);", - "_lf_replace_template_token((token_template_t*)" - + action.getName() - + ", " - + tokenPointer - + ");")); - // Set the value field only if there is a type. - if (!type.isUndefined()) { - // The value field will either be a copy (for primitive types) - // or a pointer (for types ending in *). - builder.pr("if (" + action.getName() + "->has_value) {"); - builder.indent(); - if (CUtil.isTokenType(type, types)) { - builder.pr( - action.getName() - + "->value = (" - + types.getTargetType(type) - + ")" - + tokenPointer - + "->value;"); - } else { - builder.pr( - action.getName() - + "->value = *(" - + types.getTargetType(type) - + "*)" - + tokenPointer - + "->value;"); - } - builder.unindent(); - builder.pr("}"); + // Create the local variable whose name matches the input name. + // If the input has not been declared mutable, then this is a pointer + // to the upstream output. Otherwise, it is a copy of the upstream output, + // which nevertheless points to the same token and value (hence, as done + // below, we have to use lf_writable_copy()). There are 8 cases, + // depending on whether the input is mutable, whether it is a multiport, + // and whether it is a token type. + // Easy case first. + if (!input.isMutable() && !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, primitive type. + builder.pr(structType+"* "+inputName+" = self->_lf_"+inputName+";"); + } else if (input.isMutable()&& !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, primitive type. + builder.pr(String.join("\n", + "// Mutable input, so copy the input into a temporary variable.", + "// The input value on the struct is a copy.", + structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", + structType+"* "+inputName+" = &_lf_tmp_"+inputName+";" + )); + } else if (!input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, token type. + builder.pr(String.join("\n", + structType+"* "+inputName+" = self->_lf_"+inputName+";", + "if ("+inputName+"->is_present) {", + " "+inputName+"->length = "+inputName+"->token->length;", + " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", + "} else {", + " "+inputName+"->length = 0;", + "}" + )); + } else if (input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, token type. + builder.pr(String.join("\n", + "// Mutable input, so copy the input struct into a temporary variable.", + structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", + structType+"* "+inputName+" = &_lf_tmp_"+inputName+";", + inputName+"->value = NULL;", // Prevent payload from being freed. + "if ("+inputName+"->is_present) {", + " "+inputName+"->length = "+inputName+"->token->length;", + " "+inputName+"->token = lf_writable_copy((lf_port_base_t*)self->_lf_"+inputName+");", + " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", + "} else {", + " "+inputName+"->length = 0;", + "}" + )); + } else if (!input.isMutable()&& ASTUtils.isMultiport(input)) { + // Non-mutable, multiport, primitive or token type. + builder.pr(structType+"** "+inputName+" = self->_lf_"+inputName+";"); + } else if (CUtil.isTokenType(inputType, types)) { + // Mutable, multiport, token type + builder.pr(String.join("\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", + " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", + " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", + " // If necessary, copy the tokens.", + " if ("+inputName+"[i]->is_present) {", + " "+inputName+"[i]->length = "+inputName+"[i]->token->length;", + " token_template_t* _lf_input = (token_template_t*)self->_lf_"+inputName+"[i];", + " "+inputName+"[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", + " "+inputName+"[i]->value = ("+types.getTargetType(inputType)+")"+inputName+"[i]->token->value;", + " } else {", + " "+inputName+"[i]->length = 0;", + " }", + "}" + )); + } else { + // Mutable, multiport, primitive type + builder.pr(String.join("\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", + "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", + " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", + " // Copy the struct, which includes the value.", + " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", + "}" + )); + } + // Set the _width variable for all cases. This will be -1 + // for a variable-width multiport, which is not currently supported. + // It will be -2 if it is not multiport. + builder.pr("int "+inputWidth+" = self->_lf_"+inputWidth+"; SUPPRESS_UNUSED_WARNING("+inputWidth+");"); + return builder.toString(); } - return builder.toString(); - } - /** - * Generate into the specified string builder the code to initialize local variables for the - * specified input port in a reaction function from the "self" struct. - * - * @param input The input statement from the AST. - * @param r The reactor. - */ - private static String generateInputVariablesInReaction(Input input, Reactor r, CTypes types) { - String structType = CGenerator.variableStructType(input, r, false); - InferredType inputType = ASTUtils.getInferredType(input); - CodeBuilder builder = new CodeBuilder(); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); + /** + * Generate into the specified string builder the code to + * initialize local variables for outputs in a reaction function + * from the "self" struct. + * @param effect The effect declared by the reaction. This must refer to an output. + * @param r The reactor containing the reaction. + */ + public static String generateOutputVariablesInReaction( + VarRef effect, + Reactor r, + ErrorReporter errorReporter, + boolean requiresTypes + ) { + Output output = (Output) effect.getVariable(); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + if (output.getType() == null && requiresTypes) { + errorReporter.reportError(output, "Output is required to have a type: " + outputName); + return ""; + } else { + // The container of the output may be a contained reactor or + // the reactor containing the reaction. + String outputStructType = (effect.getContainer() == null) ? + CGenerator.variableStructType(output, r, false) + : + CGenerator.variableStructType(output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); + if (!ASTUtils.isMultiport(output)) { + // Output port is not a multiport. + return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; + } else { + // Output port is a multiport. + // Set the _width variable. + return String.join("\n", + "int "+outputWidth+" = self->_lf_"+outputWidth+"; SUPPRESS_UNUSED_WARNING("+outputWidth+");", + outputStructType+"** "+outputName+" = self->_lf_"+outputName+"_pointers;" + ); - // Create the local variable whose name matches the input name. - // If the input has not been declared mutable, then this is a pointer - // to the upstream output. Otherwise, it is a copy of the upstream output, - // which nevertheless points to the same token and value (hence, as done - // below, we have to use lf_writable_copy()). There are 8 cases, - // depending on whether the input is mutable, whether it is a multiport, - // and whether it is a token type. - // Easy case first. - if (!input.isMutable() - && !CUtil.isTokenType(inputType, types) - && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, primitive type. - builder.pr(structType + "* " + inputName + " = self->_lf_" + inputName + ";"); - } else if (input.isMutable() - && !CUtil.isTokenType(inputType, types) - && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, primitive type. - builder.pr( - String.join( - "\n", - "// Mutable input, so copy the input into a temporary variable.", - "// The input value on the struct is a copy.", - structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", - structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";")); - } else if (!input.isMutable() - && CUtil.isTokenType(inputType, types) - && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, token type. - builder.pr( - String.join( - "\n", - structType + "* " + inputName + " = self->_lf_" + inputName + ";", - "if (" + inputName + "->is_present) {", - " " + inputName + "->length = " + inputName + "->token->length;", - " " - + inputName - + "->value = (" - + types.getTargetType(inputType) - + ")" - + inputName - + "->token->value;", - "} else {", - " " + inputName + "->length = 0;", - "}")); - } else if (input.isMutable() - && CUtil.isTokenType(inputType, types) - && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, token type. - builder.pr( - String.join( - "\n", - "// Mutable input, so copy the input struct into a temporary variable.", - structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", - structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";", - inputName + "->value = NULL;", // Prevent payload from being freed. - "if (" + inputName + "->is_present) {", - " " + inputName + "->length = " + inputName + "->token->length;", - " " - + inputName - + "->token = lf_writable_copy((lf_port_base_t*)self->_lf_" - + inputName - + ");", - " " - + inputName - + "->value = (" - + types.getTargetType(inputType) - + ")" - + inputName - + "->token->value;", - "} else {", - " " + inputName + "->length = 0;", - "}")); - } else if (!input.isMutable() && ASTUtils.isMultiport(input)) { - // Non-mutable, multiport, primitive or token type. - builder.pr(structType + "** " + inputName + " = self->_lf_" + inputName + ";"); - } else if (CUtil.isTokenType(inputType, types)) { - // Mutable, multiport, token type - builder.pr( - String.join( - "\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType - + " _lf_tmp_" - + inputName - + "[" - + CUtil.multiportWidthExpression(input) - + "];", - structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", - "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", - " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", - " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", - " // If necessary, copy the tokens.", - " if (" + inputName + "[i]->is_present) {", - " " + inputName + "[i]->length = " + inputName + "[i]->token->length;", - " token_template_t* _lf_input = (token_template_t*)self->_lf_" - + inputName - + "[i];", - " " + inputName + "[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", - " " - + inputName - + "[i]->value = (" - + types.getTargetType(inputType) - + ")" - + inputName - + "[i]->token->value;", - " } else {", - " " + inputName + "[i]->length = 0;", - " }", - "}")); - } else { - // Mutable, multiport, primitive type - builder.pr( - String.join( - "\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType - + " _lf_tmp_" - + inputName - + "[" - + CUtil.multiportWidthExpression(input) - + "];", - structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", - "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", - " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", - " // Copy the struct, which includes the value.", - " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", - "}")); + } + } } - // Set the _width variable for all cases. This will be -1 - // for a variable-width multiport, which is not currently supported. - // It will be -2 if it is not multiport. - builder.pr( - "int " - + inputWidth - + " = self->_lf_" - + inputWidth - + "; SUPPRESS_UNUSED_WARNING(" - + inputWidth - + ");"); - return builder.toString(); - } - /** - * Generate into the specified string builder the code to initialize local variables for outputs - * in a reaction function from the "self" struct. - * - * @param effect The effect declared by the reaction. This must refer to an output. - * @param r The reactor containing the reaction. - */ - public static String generateOutputVariablesInReaction( - VarRef effect, Reactor r, ErrorReporter errorReporter, boolean requiresTypes) { - Output output = (Output) effect.getVariable(); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - if (output.getType() == null && requiresTypes) { - errorReporter.reportError(output, "Output is required to have a type: " + outputName); - return ""; - } else { - // The container of the output may be a contained reactor or - // the reactor containing the reaction. - String outputStructType = - (effect.getContainer() == null) - ? CGenerator.variableStructType(output, r, false) - : CGenerator.variableStructType( - output, ASTUtils.toDefinition(effect.getContainer().getReactorClass()), false); - if (!ASTUtils.isMultiport(output)) { - // Output port is not a multiport. - return outputStructType + "* " + outputName + " = &self->_lf_" + outputName + ";"; - } else { - // Output port is a multiport. - // Set the _width variable. + /** + * Generate into the specified string builder the code to initialize local variables for watchdogs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to a watchdog. + * @param decl The reactor containing the reaction or the import statement. + */ + public static String generateWatchdogVariablesInReaction(VarRef effect, ReactorDecl decl) { + Watchdog watchdog = (Watchdog) effect.getVariable(); + String watchdogName = watchdog.getName(); return String.join( "\n", - "int " - + outputWidth - + " = self->_lf_" - + outputWidth - + "; SUPPRESS_UNUSED_WARNING(" - + outputWidth - + ");", - outputStructType + "** " + outputName + " = self->_lf_" + outputName + "_pointers;"); - } + List.of("watchdog_t* " + watchdogName + " = &(self->_lf_watchdog_" + watchdogName + ");") + ); } - } - /** - * Generate into the specified string builder the code to initialize local variables for watchdogs - * in a reaction function from the "self" struct. - * - * @param effect The effect declared by the reaction. This must refer to a watchdog. - * @param decl The reactor containing the reaction or the import statement. - */ - // Fine to have watchdog be in reactor self struct? - public static String generateWatchdogVariablesInReaction(VarRef effect, ReactorDecl decl) { - Watchdog watchdog = (Watchdog) effect.getVariable(); - String watchdogName = watchdog.getName(); + /** + * Generate the fields of the self struct and statements for the constructor + * to create and initialize a reaction_t struct for each reaction in the + * specified reactor and a trigger_t struct for each trigger (input, action, + * timer, or output of a contained reactor). + * @param body The place to put the code for the self struct. + * @param reactor The reactor. + * @param constructorCode The place to put the constructor code. + */ + public static void generateReactionAndTriggerStructs( + CodeBuilder body, + Reactor reactor, + CodeBuilder constructorCode, + CTypes types + ) { + var reactionCount = 0; + // Iterate over reactions and create initialize the reaction_t struct + // on the self struct. Also, collect a map from triggers to the reactions + // that are triggered by that trigger. Also, collect a set of sources + // that are read by reactions but do not trigger reactions. + // Finally, collect a set of triggers and sources that are outputs + // of contained reactors. + var triggerMap = new LinkedHashMap>(); + var sourceSet = new LinkedHashSet(); + var outputsOfContainedReactors = new LinkedHashMap(); + var startupReactions = new LinkedHashSet(); + var shutdownReactions = new LinkedHashSet(); + var resetReactions = new LinkedHashSet(); + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create the reaction_t struct. + body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); - return String.join( - "\n", - List.of("watchdog_t* " + watchdogName + " = &(self->_lf_watchdog_" + watchdogName + ");")); - } + // Create the map of triggers to reactions. + for (TriggerRef trigger : reaction.getTriggers()) { + // trigger may not be a VarRef (it could be "startup" or "shutdown"). + if (trigger instanceof VarRef) { + var triggerAsVarRef = (VarRef) trigger; + var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); + if (reactionList == null) { + reactionList = new LinkedList<>(); + triggerMap.put(triggerAsVarRef.getVariable(), reactionList); + } + reactionList.add(reactionCount); + if (triggerAsVarRef.getContainer() != null) { + outputsOfContainedReactors.put(triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); + } + } else if (trigger instanceof BuiltinTriggerRef) { + switch(((BuiltinTriggerRef) trigger).getType()) { + case STARTUP: + startupReactions.add(reactionCount); + break; + case SHUTDOWN: + shutdownReactions.add(reactionCount); + break; + case RESET: + resetReactions.add(reactionCount); + break; + } + } + } + // Create the set of sources read but not triggering. + for (VarRef source : reaction.getSources()) { + sourceSet.add(source.getVariable()); + if (source.getContainer() != null) { + outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); + } + } - /** - * Generate the fields of the self struct and statements for the constructor to create and - * initialize a reaction_t struct for each reaction in the specified reactor and a trigger_t - * struct for each trigger (input, action, timer, or output of a contained reactor). - * - * @param body The place to put the code for the self struct. - * @param reactor The reactor. - * @param constructorCode The place to put the constructor code. - */ - public static void generateReactionAndTriggerStructs( - CodeBuilder body, Reactor reactor, CodeBuilder constructorCode, CTypes types) { - var reactionCount = 0; - // Iterate over reactions and create initialize the reaction_t struct - // on the self struct. Also, collect a map from triggers to the reactions - // that are triggered by that trigger. Also, collect a set of sources - // that are read by reactions but do not trigger reactions. - // Finally, collect a set of triggers and sources that are outputs - // of contained reactors. - var triggerMap = new LinkedHashMap>(); - var sourceSet = new LinkedHashSet(); - var outputsOfContainedReactors = new LinkedHashMap(); - var startupReactions = new LinkedHashSet(); - var shutdownReactions = new LinkedHashSet(); - var resetReactions = new LinkedHashSet(); - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create the reaction_t struct. - body.pr(reaction, "reaction_t _lf__reaction_" + reactionCount + ";"); + var deadlineFunctionPointer = "NULL"; + if (reaction.getDeadline() != null) { + // The following has to match the name chosen in generateReactions + var deadlineFunctionName = generateDeadlineFunctionName(reactor, reactionCount); + deadlineFunctionPointer = "&" + deadlineFunctionName; + } - // Create the map of triggers to reactions. - for (TriggerRef trigger : reaction.getTriggers()) { - // trigger may not be a VarRef (it could be "startup" or "shutdown"). - if (trigger instanceof VarRef) { - var triggerAsVarRef = (VarRef) trigger; - var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); - if (reactionList == null) { - reactionList = new LinkedList<>(); - triggerMap.put(triggerAsVarRef.getVariable(), reactionList); - } - reactionList.add(reactionCount); - if (triggerAsVarRef.getContainer() != null) { - outputsOfContainedReactors.put( - triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); - } - } else if (trigger instanceof BuiltinTriggerRef) { - switch (((BuiltinTriggerRef) trigger).getType()) { - case STARTUP: - startupReactions.add(reactionCount); - break; - case SHUTDOWN: - shutdownReactions.add(reactionCount); - break; - case RESET: - resetReactions.add(reactionCount); - break; - } + // Assign the STP handler + var STPFunctionPointer = "NULL"; + if (reaction.getStp() != null) { + // The following has to match the name chosen in generateReactions + var STPFunctionName = generateStpFunctionName(reactor, reactionCount); + STPFunctionPointer = "&" + STPFunctionName; + } + + // Set the defaults of the reaction_t struct in the constructor. + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__reaction_"+reactionCount+".index = 0; + // self->_lf__reaction_"+reactionCount+".chain_id = 0; + // self->_lf__reaction_"+reactionCount+".pos = 0; + // self->_lf__reaction_"+reactionCount+".status = inactive; + // self->_lf__reaction_"+reactionCount+".deadline = 0LL; + // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; + constructorCode.pr(reaction, String.join("\n", + "self->_lf__reaction_"+reactionCount+".number = "+reactionCount+";", + "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(reactor, reactionCount)+";", + "self->_lf__reaction_"+reactionCount+".self = self;", + "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", + "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", + "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", + (reaction.eContainer() instanceof Mode ? + "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+reactor.getModes().indexOf((Mode) reaction.eContainer())+"];" : + "self->_lf__reaction_"+reactionCount+".mode = NULL;") + )); + // Increment the reactionCount even if the reaction is not in the federate + // so that reaction indices are consistent across federates. + reactionCount++; } - } - // Create the set of sources read but not triggering. - for (VarRef source : reaction.getSources()) { - sourceSet.add(source.getVariable()); - if (source.getContainer() != null) { - outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); + + // Next, create and initialize the trigger_t objects. + // Start with the timers. + for (Timer timer : ASTUtils.allTimers(reactor)) { + createTriggerT(body, timer, triggerMap, constructorCode, types); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); + constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__"+timer.getName()+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); } - } - var deadlineFunctionPointer = "NULL"; - if (reaction.getDeadline() != null) { - // The following has to match the name chosen in generateReactions - var deadlineFunctionName = generateDeadlineFunctionName(reactor, reactionCount); - deadlineFunctionPointer = "&" + deadlineFunctionName; - } + // Handle builtin triggers. + if (startupReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); + } + // Handle shutdown triggers. + if (shutdownReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); + } + if (resetReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); + } - // Assign the STP handler - var STPFunctionPointer = "NULL"; - if (reaction.getStp() != null) { - // The following has to match the name chosen in generateReactions - var STPFunctionName = generateStpFunctionName(reactor, reactionCount); - STPFunctionPointer = "&" + STPFunctionName; - } + // Next handle actions. + for (Action action : ASTUtils.allActions(reactor)) { + createTriggerT(body, action, triggerMap, constructorCode, types); + var isPhysical = "true"; + if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { + isPhysical = "false"; + } + var elementSize = "0"; + // If the action type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) + : null; + if (rootType != null && !rootType.equals("void")) { + elementSize = "sizeof(" + rootType + ")"; + } - // Set the defaults of the reaction_t struct in the constructor. - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__reaction_"+reactionCount+".index = 0; - // self->_lf__reaction_"+reactionCount+".chain_id = 0; - // self->_lf__reaction_"+reactionCount+".pos = 0; - // self->_lf__reaction_"+reactionCount+".status = inactive; - // self->_lf__reaction_"+reactionCount+".deadline = 0LL; - // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; - constructorCode.pr( - reaction, - String.join( - "\n", - "self->_lf__reaction_" + reactionCount + ".number = " + reactionCount + ";", - "self->_lf__reaction_" - + reactionCount - + ".function = " - + CReactionGenerator.generateReactionFunctionName(reactor, reactionCount) - + ";", - "self->_lf__reaction_" + reactionCount + ".self = self;", - "self->_lf__reaction_" - + reactionCount - + ".deadline_violation_handler = " - + deadlineFunctionPointer - + ";", - "self->_lf__reaction_" + reactionCount + ".STP_handler = " + STPFunctionPointer + ";", - "self->_lf__reaction_" + reactionCount + ".name = " + addDoubleQuotes("?") + ";", - (reaction.eContainer() instanceof Mode - ? "self->_lf__reaction_" - + reactionCount - + ".mode = &self->_lf__modes[" - + reactor.getModes().indexOf((Mode) reaction.eContainer()) - + "];" - : "self->_lf__reaction_" + reactionCount + ".mode = NULL;"))); - // Increment the reactionCount even if the reaction is not in the federate - // so that reaction indices are consistent across federates. - reactionCount++; - } + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__"+action.getName()+".is_timer = false; + constructorCode.pr(String.join("\n", + "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", + (!(action.getPolicy() == null || action.getPolicy().isEmpty()) ? + "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" : + ""), + // Need to set the element_size in the trigger_t and the action struct. + "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize + + ";", + "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";" + )); + } - // Next, create and initialize the trigger_t objects. - // Start with the timers. - for (Timer timer : ASTUtils.allTimers(reactor)) { - createTriggerT(body, timer, triggerMap, constructorCode, types); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - constructorCode.pr("self->_lf__" + timer.getName() + ".is_timer = true;"); - constructorCode.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__" - + timer.getName() - + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - } + // Next handle inputs. + for (Input input : ASTUtils.allInputs(reactor)) { + createTriggerT(body, input, triggerMap, constructorCode, types); + } - // Handle builtin triggers. - if (startupReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); - } - // Handle shutdown triggers. - if (shutdownReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); - } - if (resetReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); + // Next handle watchdogs. + for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { + createTriggerT(body, watchdog, triggerMap, constructorCode, types); + } } - // Next handle actions. - for (Action action : ASTUtils.allActions(reactor)) { - createTriggerT(body, action, triggerMap, constructorCode, types); - var isPhysical = "true"; - if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { - isPhysical = "false"; - } - var elementSize = "0"; - // If the action type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) : null; - if (rootType != null && !rootType.equals("void")) { - elementSize = "sizeof(" + rootType + ")"; - } + /** + * Define the trigger_t object on the self struct, an array of + * reaction_t pointers pointing to reactions triggered by this variable, + * and initialize the pointers in the array in the constructor. + * @param body The place to write the self struct entries. + * @param variable The trigger variable (Timer, Action, Watchdog, or Input). + * @param triggerMap A map from Variables to a list of the reaction indices triggered by the + * variable. + * @param constructorCode The place to write the constructor code. + */ + private static void createTriggerT( + CodeBuilder body, + Variable variable, + LinkedHashMap> triggerMap, + CodeBuilder constructorCode, + CTypes types + ) { + var varName = variable.getName(); + // variable is a port, a timer, or an action. + body.pr(variable, "trigger_t _lf__"+varName+";"); + constructorCode.pr(variable, "self->_lf__"+varName+".last = NULL;"); + constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__"+varName+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__"+action.getName()+".is_timer = false; - constructorCode.pr( - String.join( - "\n", - "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", - (!(action.getPolicy() == null || action.getPolicy().isEmpty()) - ? "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" - : ""), - // Need to set the element_size in the trigger_t and the action struct. - "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize + ";", - "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";")); - } + // Generate the reactions triggered table. + var reactionsTriggered = triggerMap.get(variable); + if (reactionsTriggered != null) { + body.pr(variable, "reaction_t* _lf__"+varName+"_reactions["+reactionsTriggered.size()+"];"); + var count = 0; + for (Integer reactionTriggered : reactionsTriggered) { + constructorCode.prSourceLineNumber(variable); + constructorCode.pr(variable, "self->_lf__"+varName+"_reactions["+count+"] = &self->_lf__reaction_"+reactionTriggered+";"); + count++; + } + // Set up the trigger_t struct's pointer to the reactions. + constructorCode.pr(variable, String.join("\n", + "self->_lf__"+varName+".reactions = &self->_lf__"+varName+"_reactions[0];", + "self->_lf__"+varName+".number_of_reactions = "+count+";" + )); - // Next handle inputs. - for (Input input : ASTUtils.allInputs(reactor)) { - createTriggerT(body, input, triggerMap, constructorCode, types); - } + // If federated, set the physical_time_of_arrival + constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederated( + "self->_lf__"+varName+".physical_time_of_arrival = NEVER;")); + } + if (variable instanceof Input) { + var rootType = CUtil.rootType(types.getTargetType((Input) variable)); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + // If the input type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; - // Next handle watchdogs. - for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - createTriggerT(body, watchdog, triggerMap, constructorCode, types); + constructorCode.pr("self->_lf__"+varName+".tmplt.type.element_size = "+size+";"); + body.pr( + CExtensionUtils.surroundWithIfFederated( + CExtensionUtils.createPortStatusFieldForInput((Input) variable) + ) + ); + } } - } - - /** - * Define the trigger_t object on the self struct, an array of reaction_t pointers pointing to - * reactions triggered by this variable, and initialize the pointers in the array in the - * constructor. - * - * @param body The place to write the self struct entries. - * @param variable The trigger variable (Timer, Action, Watchdog, or Input). - * @param triggerMap A map from Variables to a list of the reaction indices triggered by the - * variable. - * @param constructorCode The place to write the constructor code. - */ - private static void createTriggerT( - CodeBuilder body, - Variable variable, - LinkedHashMap> triggerMap, - CodeBuilder constructorCode, - CTypes types) { - var varName = variable.getName(); - // variable is a port, a timer, or an action. - body.pr(variable, "trigger_t _lf__" + varName + ";"); - constructorCode.pr(variable, "self->_lf__" + varName + ".last = NULL;"); - constructorCode.pr( - variable, - CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__" - + varName - + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - - // Generate the reactions triggered table. - var reactionsTriggered = triggerMap.get(variable); - if (reactionsTriggered != null) { - body.pr( - variable, - "reaction_t* _lf__" + varName + "_reactions[" + reactionsTriggered.size() + "];"); - var count = 0; - for (Integer reactionTriggered : reactionsTriggered) { - constructorCode.prSourceLineNumber(variable); - constructorCode.pr( - variable, - "self->_lf__" - + varName - + "_reactions[" - + count - + "] = &self->_lf__reaction_" - + reactionTriggered - + ";"); - count++; - } - // Set up the trigger_t struct's pointer to the reactions. - constructorCode.pr( - variable, - String.join( - "\n", - "self->_lf__" + varName + ".reactions = &self->_lf__" + varName + "_reactions[0];", - "self->_lf__" + varName + ".number_of_reactions = " + count + ";")); - // If federated, set the physical_time_of_arrival - constructorCode.pr( - variable, - CExtensionUtils.surroundWithIfFederated( - "self->_lf__" + varName + ".physical_time_of_arrival = NEVER;")); + public static void generateBuiltinTriggeredReactionsArray( + Set reactions, + String name, + CodeBuilder body, + CodeBuilder constructorCode + ) { + body.pr(String.join("\n", + "trigger_t _lf__"+name+";", + "reaction_t* _lf__"+name+"_reactions["+reactions.size()+"];" + )); + constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__"+name+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + var i = 0; + for (Integer reactionIndex : reactions) { + constructorCode.pr("self->_lf__"+name+"_reactions["+i+++"] = &self->_lf__reaction_"+reactionIndex+";"); + } + constructorCode.pr(String.join("\n", + "self->_lf__"+name+".last = NULL;", + "self->_lf__"+name+".reactions = &self->_lf__"+name+"_reactions[0];", + "self->_lf__"+name+".number_of_reactions = "+reactions.size()+";", + "self->_lf__"+name+".is_timer = false;" + )); } - if (variable instanceof Input) { - var rootType = CUtil.rootType(types.getTargetType((Input) variable)); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - // If the input type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; - constructorCode.pr("self->_lf__" + varName + ".tmplt.type.element_size = " + size + ";"); - body.pr( - CExtensionUtils.surroundWithIfFederated( - CExtensionUtils.createPortStatusFieldForInput((Input) variable))); + public static String generateBuiltinTriggersTable(int reactionCount, String name) { + return String.join("\n", List.of( + "// Array of pointers to "+name+" triggers.", + (reactionCount > 0 ? + "reaction_t* _lf_"+name+"_reactions["+reactionCount+"]" : + "reaction_t** _lf_"+name+"_reactions = NULL") + ";", + "int _lf_"+name+"_reactions_size = "+reactionCount+";" + )); } - } - public static void generateBuiltinTriggeredReactionsArray( - Set reactions, String name, CodeBuilder body, CodeBuilder constructorCode) { - body.pr( - String.join( - "\n", - "trigger_t _lf__" + name + ";", - "reaction_t* _lf__" + name + "_reactions[" + reactions.size() + "];")); - constructorCode.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__" + name + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - var i = 0; - for (Integer reactionIndex : reactions) { - constructorCode.pr( - "self->_lf__" - + name - + "_reactions[" - + i++ - + "] = &self->_lf__reaction_" - + reactionIndex - + ";"); + /** + * Generate the _lf_trigger_startup_reactions function. + */ + public static String generateLfTriggerStartupReactions(int startupReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("void _lf_trigger_startup_reactions() {"); + if (startupReactionCount > 0) { + s.append("\n"); + if (hasModalReactors) { + s.append(String.join("\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " if (_lf_startup_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_startup_reset_reactions(", + " _lf_startup_reactions, _lf_startup_reactions_size,", + " NULL, 0,", + " _lf_modal_reactor_states, _lf_modal_reactor_states_size);" + )); + } else { + s.append(String.join("\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }" + )); + } + s.append("\n"); + } + s.append("}\n"); + return s.toString(); } - constructorCode.pr( - String.join( - "\n", - "self->_lf__" + name + ".last = NULL;", - "self->_lf__" + name + ".reactions = &self->_lf__" + name + "_reactions[0];", - "self->_lf__" + name + ".number_of_reactions = " + reactions.size() + ";", - "self->_lf__" + name + ".is_timer = false;")); - } - - public static String generateBuiltinTriggersTable(int reactionCount, String name) { - return String.join( - "\n", - List.of( - "// Array of pointers to " + name + " triggers.", - (reactionCount > 0 - ? "reaction_t* _lf_" + name + "_reactions[" + reactionCount + "]" - : "reaction_t** _lf_" + name + "_reactions = NULL") - + ";", - "int _lf_" + name + "_reactions_size = " + reactionCount + ";")); - } - /** Generate the _lf_trigger_startup_reactions function. */ - public static String generateLfTriggerStartupReactions( - int startupReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("void _lf_trigger_startup_reactions() {"); - if (startupReactionCount > 0) { - s.append("\n"); - if (hasModalReactors) { - s.append( - String.join( - "\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " if (_lf_startup_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_startup_reset_reactions(", - " _lf_startup_reactions, _lf_startup_reactions_size,", - " NULL, 0,", - " _lf_modal_reactor_states, _lf_modal_reactor_states_size);")); - } else { - s.append( - String.join( - "\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }")); - } - s.append("\n"); + /** + * Generate the _lf_trigger_shutdown_reactions function. + */ + public static String generateLfTriggerShutdownReactions(int shutdownReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("bool _lf_trigger_shutdown_reactions() {\n"); + if (shutdownReactionCount > 0) { + if (hasModalReactors) { + s.append(String.join("\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " if (_lf_shutdown_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions, _lf_shutdown_reactions_size);", + " return true;" + )); + } else { + s.append(String.join("\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " return true;" + )); + } + s.append("\n"); + } else { + s.append(" return false;\n"); + } + s.append("}\n"); + return s.toString(); } - s.append("}\n"); - return s.toString(); - } - /** Generate the _lf_trigger_shutdown_reactions function. */ - public static String generateLfTriggerShutdownReactions( - int shutdownReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("bool _lf_trigger_shutdown_reactions() {\n"); - if (shutdownReactionCount > 0) { - if (hasModalReactors) { - s.append( - String.join( - "\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " if (_lf_shutdown_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions," - + " _lf_shutdown_reactions_size);", - " return true;")); - } else { - s.append( - String.join( - "\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " return true;")); - } - s.append("\n"); - } else { - s.append(" return false;\n"); + /** + * Generate the _lf_handle_mode_triggered_reactions function. + */ + public static String generateLfModeTriggeredReactions( + int startupReactionCount, + int resetReactionCount, + boolean hasModalReactors + ) { + if (!hasModalReactors) { + return ""; + } + var s = new StringBuilder(); + s.append("void _lf_handle_mode_triggered_reactions() {\n"); + s.append(" _lf_handle_mode_startup_reset_reactions(\n"); + if (startupReactionCount > 0) { + s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); + } + if (resetReactionCount > 0) { + s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); + } + s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); + s.append("}\n"); + return s.toString(); } - s.append("}\n"); - return s.toString(); - } - /** Generate the _lf_handle_mode_triggered_reactions function. */ - public static String generateLfModeTriggeredReactions( - int startupReactionCount, int resetReactionCount, boolean hasModalReactors) { - if (!hasModalReactors) { - return ""; - } - var s = new StringBuilder(); - s.append("void _lf_handle_mode_triggered_reactions() {\n"); - s.append(" _lf_handle_mode_startup_reset_reactions(\n"); - if (startupReactionCount > 0) { - s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - if (resetReactionCount > 0) { - s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); - s.append("}\n"); - return s.toString(); - } + /** Generate a reaction function definition for a reactor. + * This function will have a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + public static String generateReaction( + Reaction reaction, + Reactor r, + int reactionIndex, + Instantiation mainDef, + ErrorReporter errorReporter, + CTypes types, + TargetConfig targetConfig, + boolean requiresType + ) { + var code = new CodeBuilder(); + var body = ASTUtils.toText(getCode(types, reaction, r)); + String init = generateInitializationForReaction( + body, reaction, ASTUtils.toDefinition(r), reactionIndex, + types, errorReporter, mainDef, + requiresType); - /** - * Generate a reaction function definition for a reactor. This function will have a single - * argument that is a void* pointing to a struct that contains parameters, state variables, inputs - * (triggering or not), actions (triggering or produced), and outputs. - * - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - public static String generateReaction( - Reaction reaction, - Reactor r, - int reactionIndex, - Instantiation mainDef, - ErrorReporter errorReporter, - CTypes types, - TargetConfig targetConfig, - boolean requiresType) { - var code = new CodeBuilder(); - var body = ASTUtils.toText(getCode(types, reaction, r)); - String init = - generateInitializationForReaction( - body, - reaction, - ASTUtils.toDefinition(r), - reactionIndex, - types, - errorReporter, - mainDef, - requiresType); + code.pr( + "#include " + StringUtil.addDoubleQuotes( + CCoreFilesUtils.getCTargetSetHeader())); - code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetHeader())); + CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(r), code); + code.pr(generateFunction( + generateReactionFunctionHeader(r, reactionIndex), + init, getCode(types, reaction, r) + )); + // Now generate code for the late function, if there is one + // Note that this function can only be defined on reactions + // in federates that have inputs from a logical connection. + if (reaction.getStp() != null) { + code.pr(generateFunction( + generateStpFunctionHeader(r, reactionIndex), + init, reaction.getStp().getCode())); + } - CMethodGenerator.generateMacrosForMethods(ASTUtils.toDefinition(r), code); - code.pr( - generateFunction( - generateReactionFunctionHeader(r, reactionIndex), init, getCode(types, reaction, r))); - // Now generate code for the late function, if there is one - // Note that this function can only be defined on reactions - // in federates that have inputs from a logical connection. - if (reaction.getStp() != null) { - code.pr( - generateFunction( - generateStpFunctionHeader(r, reactionIndex), init, reaction.getStp().getCode())); + // Now generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr(generateFunction( + generateDeadlineFunctionHeader(r, reactionIndex), + init, reaction.getDeadline().getCode())); + } + CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(r), code); + code.pr( + "#include " + StringUtil.addDoubleQuotes( + CCoreFilesUtils.getCTargetSetUndefHeader())); + return code.toString(); } - // Now generate code for the deadline violation function, if there is one. - if (reaction.getDeadline() != null) { - code.pr( - generateFunction( - generateDeadlineFunctionHeader(r, reactionIndex), - init, - reaction.getDeadline().getCode())); + private static Code getCode(CTypes types, Reaction r, ReactorDecl container) { + if (r.getCode() != null) return r.getCode(); + Code ret = LfFactory.eINSTANCE.createCode(); + var reactor = ASTUtils.toDefinition(container); + ret.setBody( + CReactorHeaderFileGenerator.nonInlineInitialization(r, reactor) + "\n" + + r.getName() + "( " + CReactorHeaderFileGenerator.reactionArguments(r, reactor) + " );"); + return ret; } - CMethodGenerator.generateMacroUndefsForMethods(ASTUtils.toDefinition(r), code); - code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetUndefHeader())); - return code.toString(); - } - private static Code getCode(CTypes types, Reaction r, ReactorDecl container) { - if (r.getCode() != null) return r.getCode(); - Code ret = LfFactory.eINSTANCE.createCode(); - var reactor = ASTUtils.toDefinition(container); - ret.setBody( - CReactorHeaderFileGenerator.nonInlineInitialization(r, reactor) - + "\n" - + r.getName() - + "( " - + CReactorHeaderFileGenerator.reactionArguments(r, reactor) - + " );"); - return ret; - } - - public static String generateFunction(String header, String init, Code code) { - var function = new CodeBuilder(); - function.pr(header + " {"); - function.indent(); - function.pr(init); - function.prSourceLineNumber(code); - function.pr(ASTUtils.toText(code)); - function.unindent(); - function.pr("}"); - return function.toString(); - } + public static String generateFunction(String header, String init, Code code) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(code); + function.pr(ASTUtils.toText(code)); + function.unindent(); + function.pr("}"); + return function.toString(); + } - /** - * Returns the name of the deadline function for reaction. - * - * @param r The reactor with the deadline - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateDeadlineFunctionName(Reactor r, int reactionIndex) { - return CUtil.getName(r).toLowerCase() + "_deadline_function" + reactionIndex; - } + /** + * Returns the name of the deadline function for reaction. + * @param r The reactor with the deadline + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateDeadlineFunctionName(Reactor r, int reactionIndex) { + return CUtil.getName(r).toLowerCase() + "_deadline_function" + reactionIndex; + } - /** - * Return the function name for specified reaction of the specified reactor. - * - * @param reactor The reactor - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionName(Reactor reactor, int reactionIndex) { - return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; - } + /** + * Return the function name for specified reaction of the + * specified reactor. + * @param reactor The reactor + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionName(Reactor reactor, int reactionIndex) { + return CUtil.getName(reactor).toLowerCase() + "reaction_function_" + reactionIndex; + } - /** - * Returns the name of the stp function for reaction. - * - * @param r The reactor with the stp - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateStpFunctionName(Reactor r, int reactionIndex) { - return CUtil.getName(r).toLowerCase() + "_STP_function" + reactionIndex; - } + /** + * Returns the name of the stp function for reaction. + * @param r The reactor with the stp + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateStpFunctionName(Reactor r, int reactionIndex) { + return CUtil.getName(r).toLowerCase() + "_STP_function" + reactionIndex; + } - /** - * Return the top level C function header for the deadline function numbered "reactionIndex" in - * "r" - * - * @param r The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the deadline function. - */ - public static String generateDeadlineFunctionHeader(Reactor r, int reactionIndex) { - String functionName = generateDeadlineFunctionName(r, reactionIndex); - return generateFunctionHeader(functionName); - } + /** Return the top level C function header for the deadline function numbered "reactionIndex" in "r" + * @param r The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the deadline function. + */ + public static String generateDeadlineFunctionHeader(Reactor r, + int reactionIndex) { + String functionName = generateDeadlineFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } - /** - * Return the top level C function header for the reaction numbered "reactionIndex" in "r" - * - * @param r The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionHeader(Reactor r, int reactionIndex) { - String functionName = generateReactionFunctionName(r, reactionIndex); - return generateFunctionHeader(functionName); - } + /** Return the top level C function header for the reaction numbered "reactionIndex" in "r" + * @param r The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionHeader(Reactor r, + int reactionIndex) { + String functionName = generateReactionFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } - public static String generateStpFunctionHeader(Reactor r, int reactionIndex) { - String functionName = generateStpFunctionName(r, reactionIndex); - return generateFunctionHeader(functionName); - } + public static String generateStpFunctionHeader(Reactor r, + int reactionIndex) { + String functionName = generateStpFunctionName(r, reactionIndex); + return generateFunctionHeader(functionName); + } - /** - * Return the start of a function declaration for a function that takes - * a `void*` argument and returns void. - * @param functionName - * @return - */ - public static String generateFunctionHeader(String functionName) { - return "void " + functionName + "(void* instance_args)"; - } + /** + * Return the start of a function declaration for a function that takes + * a `void*` argument and returns void. + * + * @param functionName + * @return + */ + public static String generateFunctionHeader(String functionName) { + return "void " + functionName + "(void* instance_args)"; + } } From e6a0ed03a3a8087b377bb41bf02f641bbf8a6daa Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:09:39 +0200 Subject: [PATCH 226/709] Revert to master version (reverse formatting) --- .../generator/python/PythonGenerator.java | 1081 +++++++++-------- 1 file changed, 558 insertions(+), 523 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index f1f0e9b59d..020954be80 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -34,14 +34,18 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; + +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; + import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.generator.CodeBuilder; import org.lflang.generator.CodeMap; + import org.lflang.generator.GeneratorResult; import org.lflang.generator.IntegratedBuilder; import org.lflang.generator.LFGeneratorContext; @@ -52,6 +56,7 @@ import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; +import org.lflang.lf.Code; import org.lflang.lf.Input; import org.lflang.lf.Model; import org.lflang.lf.Output; @@ -63,505 +68,525 @@ import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; + /** - * Generator for Python target. This class generates Python code defining each reactor class given - * in the input .lf file and imported .lf files. + * Generator for Python target. This class generates Python code defining each + * reactor + * class given in the input .lf file and imported .lf files. * - *

Each class will contain all the reaction functions defined by the user in order, with the - * necessary ports/actions given as parameters. Moreover, each class will contain all state - * variables in native Python format. + * Each class will contain all the reaction functions defined by the user in + * order, with the necessary ports/actions given as parameters. + * Moreover, each class will contain all state variables in native Python + * format. * - *

A backend is also generated using the CGenerator that interacts with the C code library (see - * CGenerator.xtend). The backend is responsible for passing arguments to the Python reactor + * A backend is also generated using the CGenerator that interacts with the C + * code library (see CGenerator.xtend). + * The backend is responsible for passing arguments to the Python reactor * functions. * * @author Soroush Bateni */ public class PythonGenerator extends CGenerator { - // Used to add statements that come before reactor classes and user code - private final CodeBuilder pythonPreamble = new CodeBuilder(); - - // Used to add module requirements to setup.py (delimited with ,) - private final List pythonRequiredModules = new ArrayList<>(); - - private final PythonTypes types; - - public PythonGenerator(LFGeneratorContext context) { - this( - context, - new PythonTypes(), - new CCmakeGenerator( - context.getFileConfig(), - List.of( - "lib/python_action.c", - "lib/python_port.c", - "lib/python_tag.c", - "lib/python_time.c", - "lib/pythontarget.c"), - PythonGenerator::setUpMainTarget, - "install(TARGETS)" // No-op - )); - } - - private PythonGenerator( - LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { - super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); - this.targetConfig.compiler = "gcc"; - this.targetConfig.compilerFlags = new ArrayList<>(); - this.targetConfig.linkerFlags = ""; - this.types = types; - } - - /** - * Generic struct for ports with primitive types and statically allocated arrays in Lingua Franca. - * This template is defined as typedef struct { bool is_present; lf_sparse_io_record_t* - * sparse_record; // NULL if there is no sparse record. int destination_channel; // -1 if there is - * no destination. PyObject* value; int num_destinations; lf_token_t* token; int length; void - * (*destructor) (void* value); void* (*copy_constructor) (void* value); - * FEDERATED_GENERIC_EXTENSION } generic_port_instance_struct; - * - *

See reactor-c-py/lib/pythontarget.h for details. - */ - String genericPortType = "generic_port_instance_struct"; - - /** - * Generic struct for actions. This template is defined as typedef struct { trigger_t* trigger; - * PyObject* value; bool is_present; bool has_value; lf_token_t* token; - * FEDERATED_CAPSULE_EXTENSION } generic_action_instance_struct; - * - *

See reactor-c-py/lib/pythontarget.h for details. - */ - String genericActionType = "generic_action_instance_struct"; - - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.Python; - } - - private final Set protoNames = new HashSet<>(); - - // ////////////////////////////////////////// - // // Public methods - @Override - public TargetTypes getTargetTypes() { - return types; - } - - // ////////////////////////////////////////// - // // Protected methods - - /** Generate all Python classes if they have a reaction */ - public String generatePythonReactorClasses() { - CodeBuilder pythonClasses = new CodeBuilder(); - CodeBuilder pythonClassesInstantiation = new CodeBuilder(); - - // Generate reactor classes in Python - pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); - - // Create empty lists to hold reactor instances - pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); - - // Instantiate generated classes - pythonClassesInstantiation.pr( - PythonReactorGenerator.generatePythonClassInstantiations(main, main)); - - return String.join( - "\n", - pythonClasses.toString(), - "", - "# Instantiate classes", - pythonClassesInstantiation.toString()); - } - - /** - * Generate the Python code constructed from reactor classes and user-written classes. - * - * @return the code body - */ - public String generatePythonCode(String pyModuleName) { - return String.join( - "\n", - "import os", - "import sys", - "sys.path.append(os.path.dirname(__file__))", - "# List imported names, but do not use pylint's --extension-pkg-allow-list option", - "# so that these names will be assumed present without having to compile and install.", - "# pylint: disable=no-name-in-module, import-error", - "from " + pyModuleName + " import (", - " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", - ")", - "# pylint: disable=c-extension-no-member", - "import " + pyModuleName + " as lf", - "try:", - " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", - " from LinguaFrancaBase.functions import (", - " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS," - + " USEC,", - " USECS, WEEK, WEEKS", - " )", - " from LinguaFrancaBase.classes import Make", - "except ModuleNotFoundError:", - " print(\"No module named 'LinguaFrancaBase'. \"", - " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", - " sys.exit(1)", - "import copy", - "", - pythonPreamble.toString(), - "", - generatePythonReactorClasses(), - "", - PythonMainFunctionGenerator.generateCode()); - } - - /** Generate the necessary Python files. */ - public Map generatePythonFiles( - String lfModuleName, String pyModuleName, String pyFileName) throws IOException { - Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); - File file = filePath.toFile(); - Files.deleteIfExists(filePath); - // Create the necessary directories - if (!file.getParentFile().exists()) { - if (!file.getParentFile().mkdirs()) { - throw new IOException( - "Failed to create directories required for the Python code generator."); - } + // Used to add statements that come before reactor classes and user code + private final CodeBuilder pythonPreamble = new CodeBuilder(); + + // Used to add module requirements to setup.py (delimited with ,) + private final List pythonRequiredModules = new ArrayList<>(); + + private final PythonTypes types; + + public PythonGenerator(LFGeneratorContext context) { + this(context, + new PythonTypes(), + new CCmakeGenerator( + context.getFileConfig(), + List.of("lib/python_action.c", + "lib/python_port.c", + "lib/python_tag.c", + "lib/python_time.c", + "lib/pythontarget.c" + ), + PythonGenerator::setUpMainTarget, + "install(TARGETS)" // No-op + ) + ); } - Map codeMaps = new HashMap<>(); - codeMaps.put(filePath, CodeMap.fromGeneratedCode(generatePythonCode(pyModuleName))); - FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); - return codeMaps; - } - - /** - * Generate code that needs to appear at the top of the generated C file, such as #define and - * #include statements. - */ - @Override - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr( - PythonPreambleGenerator.generateCDefineDirectives( - targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); - return code.toString(); - } - - /** - * Override generate top-level preambles, but put the user preambles in the .py file rather than - * the C file. Also handles including the federated execution setup preamble specified in the - * target config. - */ - @Override - protected String generateTopLevelPreambles(Reactor ignored) { - // user preambles - Set models = new LinkedHashSet<>(); - for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { - // The following assumes all reactors have a container. - // This means that generated reactors **have** to be - // added to a resource; not doing so will result in a NPE. - models.add((Model) ASTUtils.toDefinition(r).eContainer()); + + + private PythonGenerator(LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { + super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); + this.targetConfig.compiler = "gcc"; + this.targetConfig.compilerFlags = new ArrayList<>(); + this.targetConfig.linkerFlags = ""; + this.types = types; } - // Add the main reactor if it is defined - if (this.mainDef != null) { - models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); + + /** + * Generic struct for ports with primitive types and + * statically allocated arrays in Lingua Franca. + * This template is defined as + * typedef struct { + * bool is_present; + * lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record. + * int destination_channel; // -1 if there is no destination. + * PyObject* value; + * int num_destinations; + * lf_token_t* token; + * int length; + * void (*destructor) (void* value); + * void* (*copy_constructor) (void* value); + * FEDERATED_GENERIC_EXTENSION + * } generic_port_instance_struct; + * + * See reactor-c-py/lib/pythontarget.h for details. + */ + String genericPortType = "generic_port_instance_struct"; + + /** + * Generic struct for actions. + * This template is defined as + * typedef struct { + * trigger_t* trigger; + * PyObject* value; + * bool is_present; + * bool has_value; + * lf_token_t* token; + * FEDERATED_CAPSULE_EXTENSION + * } generic_action_instance_struct; + * + * See reactor-c-py/lib/pythontarget.h for details. + */ + String genericActionType = "generic_action_instance_struct"; + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.Python; } - for (Model m : models) { - pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); + + private final Set protoNames = new HashSet<>(); + + // ////////////////////////////////////////// + // // Public methods + @Override + public TargetTypes getTargetTypes() { + return types; } - return PythonPreambleGenerator.generateCIncludeStatements( - targetConfig, targetLanguageIsCpp(), hasModalReactors); - } - - @Override - protected void handleProtoFiles() { - for (String name : targetConfig.protoFiles) { - this.processProtoFile(name); - int dotIndex = name.lastIndexOf("."); - String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; - pythonPreamble.pr("import " + rootFilename + "_pb2 as " + rootFilename); - protoNames.add(rootFilename); + + // ////////////////////////////////////////// + // // Protected methods + + /** + * Generate all Python classes if they have a reaction + * + */ + public String generatePythonReactorClasses() { + CodeBuilder pythonClasses = new CodeBuilder(); + CodeBuilder pythonClassesInstantiation = new CodeBuilder(); + + // Generate reactor classes in Python + pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); + + // Create empty lists to hold reactor instances + pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); + + // Instantiate generated classes + pythonClassesInstantiation.pr(PythonReactorGenerator.generatePythonClassInstantiations(main, main)); + + return String.join("\n", + pythonClasses.toString(), + "", + "# Instantiate classes", + pythonClassesInstantiation.toString() + ); } - } - - /** - * Process a given .proto file. - * - *

Run, if possible, the proto-c protocol buffer code generator to produce the required .h and - * .c files. - * - * @param filename Name of the file to process. - */ - @Override - public void processProtoFile(String filename) { - LFCommand protoc = - commandFactory.createCommand( - "protoc", - List.of("--python_out=" + fileConfig.getSrcGenPath(), filename), - fileConfig.srcPath); - - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); - return; + + /** + * Generate the Python code constructed from reactor classes and + * user-written classes. + * + * @return the code body + */ + public String generatePythonCode(String pyModuleName) { + return String.join("\n", + "import os", + "import sys", + "sys.path.append(os.path.dirname(__file__))", + "# List imported names, but do not use pylint's --extension-pkg-allow-list option", + "# so that these names will be assumed present without having to compile and install.", + "# pylint: disable=no-name-in-module, import-error", + "from "+pyModuleName+" import (", + " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", + ")", + "# pylint: disable=c-extension-no-member", + "import "+pyModuleName+" as lf", + "try:", + " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", + " from LinguaFrancaBase.functions import (", + " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS, USEC,", + " USECS, WEEK, WEEKS", + " )", + " from LinguaFrancaBase.classes import Make", + "except ModuleNotFoundError:", + " print(\"No module named 'LinguaFrancaBase'. \"", + " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", + " sys.exit(1)", + "import copy", + "", + pythonPreamble.toString(), + "", + generatePythonReactorClasses(), + "", + PythonMainFunctionGenerator.generateCode() + ); } - int returnCode = protoc.run(); - if (returnCode == 0) { - pythonRequiredModules.add("google-api-python-client"); - } else { - errorReporter.reportError("protoc returns error code " + returnCode); + + /** + * Generate the necessary Python files. + */ + public Map generatePythonFiles( + String lfModuleName, + String pyModuleName, + String pyFileName + ) throws IOException { + Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); + File file = filePath.toFile(); + Files.deleteIfExists(filePath); + // Create the necessary directories + if (!file.getParentFile().exists()) { + if (!file.getParentFile().mkdirs()) { + throw new IOException( + "Failed to create directories required for the Python code generator." + ); + } + } + Map codeMaps = new HashMap<>(); + codeMaps.put(filePath, CodeMap.fromGeneratedCode( + generatePythonCode(pyModuleName))); + FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); + return codeMaps; + } + + /** + * Generate code that needs to appear at the top of the generated + * C file, such as #define and #include statements. + */ + @Override + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr(PythonPreambleGenerator.generateCDefineDirectives( + targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); + return code.toString(); + } + + /** + * Override generate top-level preambles, but put the user preambles in the + * .py file rather than the C file. Also handles including the federated + * execution setup preamble specified in the target config. + */ + @Override + protected String generateTopLevelPreambles(Reactor ignored) { + // user preambles + Set models = new LinkedHashSet<>(); + for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { + // The following assumes all reactors have a container. + // This means that generated reactors **have** to be + // added to a resource; not doing so will result in a NPE. + models.add((Model) ASTUtils.toDefinition(r).eContainer()); + } + // Add the main reactor if it is defined + if (this.mainDef != null) { + models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); + } + for (Model m : models) { + pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); + } + return PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors); + } + + @Override + protected void handleProtoFiles() { + for (String name : targetConfig.protoFiles) { + this.processProtoFile(name); + int dotIndex = name.lastIndexOf("."); + String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; + pythonPreamble.pr("import "+rootFilename+"_pb2 as "+rootFilename); + protoNames.add(rootFilename); + } + } + + /** + * Process a given .proto file. + * + * Run, if possible, the proto-c protocol buffer code generator to produce + * the required .h and .c files. + * + * @param filename Name of the file to process. + */ + @Override + public void processProtoFile(String filename) { + LFCommand protoc = commandFactory.createCommand( + "protoc", List.of("--python_out=" + + fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); + + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); + return; + } + int returnCode = protoc.run(); + if (returnCode == 0) { + pythonRequiredModules.add("google-api-python-client"); + } else { + errorReporter.reportError( + "protoc returns error code " + returnCode); + } + } + + /** + * Generate the aliases for inputs, outputs, and struct type definitions for + * actions of the specified reactor in the specified federate. + * @param r The parsed reactor data structure. + */ + @Override + public void generateAuxiliaryStructs( + CodeBuilder builder, Reactor r, boolean userFacing + ) { + for (Input input : ASTUtils.allInputs(r)) { + generateAuxiliaryStructsForPort(builder, r, input); + } + for (Output output : ASTUtils.allOutputs(r)) { + generateAuxiliaryStructsForPort(builder, r, output); + } + for (Action action : ASTUtils.allActions(r)) { + generateAuxiliaryStructsForAction(builder, r, action); + } } - } - - /** - * Generate the aliases for inputs, outputs, and struct type definitions for actions of the - * specified reactor in the specified federate. - * - * @param r The parsed reactor data structure. - */ - @Override - public void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { - for (Input input : ASTUtils.allInputs(r)) { - generateAuxiliaryStructsForPort(builder, r, input); + + private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, + Port port) { + boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); + builder.pr(port, + PythonPortGenerator.generateAliasTypeDef(r, port, isTokenType, + genericPortType)); } - for (Output output : ASTUtils.allOutputs(r)) { - generateAuxiliaryStructsForPort(builder, r, output); + + private void generateAuxiliaryStructsForAction(CodeBuilder builder, Reactor r, + Action action) { + builder.pr(action, PythonActionGenerator.generateAliasTypeDef(r, action, genericActionType)); } - for (Action action : ASTUtils.allActions(r)) { - generateAuxiliaryStructsForAction(builder, r, action); + + /** + * Return true if the host operating system is compatible and + * otherwise report an error and return false. + */ + @Override + public boolean isOSCompatible() { + return true; } - } - - private void generateAuxiliaryStructsForPort(CodeBuilder builder, Reactor r, Port port) { - boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); - builder.pr( - port, PythonPortGenerator.generateAliasTypeDef(r, port, isTokenType, genericPortType)); - } - - private void generateAuxiliaryStructsForAction(CodeBuilder builder, Reactor r, Action action) { - builder.pr(action, PythonActionGenerator.generateAliasTypeDef(r, action, genericActionType)); - } - - /** - * Return true if the host operating system is compatible and otherwise report an error and return - * false. - */ - @Override - public boolean isOSCompatible() { - return true; - } - - /** - * Generate C code from the Lingua Franca model contained by the specified resource. This is the - * main entry point for code generation. - * - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - // Set the threading to false by default, unless the user has - // specifically asked for it. - if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = false; + + /** + * Generate C code from the Lingua Franca model contained by the + * specified resource. This is the main entry point for code + * generation. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + // Set the threading to false by default, unless the user has + // specifically asked for it. + if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = false; + } + int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; + code.pr(PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors)); + super.doGenerate(resource, new SubContext( + context, + IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, + cGeneratedPercentProgress + )); + + if (errorsOccurred()) { + context.unsuccessfulFinish(); + return; + } + + Map codeMaps = new HashMap<>(); + var lfModuleName = fileConfig.name; + // Don't generate code if there is no main reactor + if (this.main != null) { + try { + Map codeMapsForFederate = generatePythonFiles(lfModuleName, generatePythonModuleName(lfModuleName), generatePythonFileName(lfModuleName)); + codeMaps.putAll(codeMapsForFederate); + copyTargetFiles(); + new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); + if (targetConfig.noCompile) { + System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); + } + } catch (Exception e) { + //noinspection ConstantConditions + throw Exceptions.sneakyThrow(e); + } + + System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); + } + + if (errorReporter.getErrorsOccurred()) { + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, codeMaps); + } } - int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; - code.pr( - PythonPreambleGenerator.generateCIncludeStatements( - targetConfig, targetLanguageIsCpp(), hasModalReactors)); - super.doGenerate( - resource, - new SubContext( - context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, cGeneratedPercentProgress)); - - if (errorsOccurred()) { - context.unsuccessfulFinish(); - return; + + @Override + protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new PythonDockerGenerator(context); } - Map codeMaps = new HashMap<>(); - var lfModuleName = fileConfig.name; - // Don't generate code if there is no main reactor - if (this.main != null) { - try { - Map codeMapsForFederate = - generatePythonFiles( - lfModuleName, - generatePythonModuleName(lfModuleName), - generatePythonFileName(lfModuleName)); - codeMaps.putAll(codeMapsForFederate); - copyTargetFiles(); - new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); - if (targetConfig.noCompile) { - System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); + /** Generate a reaction function definition for a reactor. + * This function has a single argument that is a void* pointing to + * a struct that contains parameters, state variables, inputs (triggering or not), + * actions (triggering or produced), and outputs. + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + @Override + protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + Reactor reactor = ASTUtils.toDefinition(r); + + // Reactions marked with a `@_c_body` attribute are generated in C + if (AttributeUtils.hasCBody(reaction)) { + super.generateReaction(src, reaction, r, reactionIndex); + return; } - } catch (Exception e) { - //noinspection ConstantConditions - throw Exceptions.sneakyThrow(e); - } + src.pr(PythonReactionGenerator.generateCReaction(reaction, reactor, reactionIndex, mainDef, errorReporter, types)); + } - System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); + /** + * Generate code that initializes the state variables for a given instance. + * Unlike parameters, state variables are uniformly initialized for all + * instances + * of the same reactor. This task is left to Python code to allow for more + * liberal + * state variable assignments. + * + * @param instance The reactor class instance + * @return Initialization code fore state variables of instance + */ + @Override + protected void generateStateVariableInitializations(ReactorInstance instance) { + // Do nothing } - if (errorReporter.getErrorsOccurred()) { - context.unsuccessfulFinish(); - } else { - context.finish(GeneratorResult.Status.COMPILED, codeMaps); + /** + * Generate runtime initialization code in C for parameters of a given + * reactor instance + * + * @param instance The reactor instance. + */ + @Override + protected void generateParameterInitialization(ReactorInstance instance) { + // Do nothing + // Parameters are initialized in Python } - } - - @Override - protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new PythonDockerGenerator(context); - } - - /** - * Generate a reaction function definition for a reactor. This function has a single argument that - * is a void* pointing to a struct that contains parameters, state variables, inputs (triggering - * or not), actions (triggering or produced), and outputs. - * - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - @Override - protected void generateReaction( - CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { - Reactor reactor = ASTUtils.toDefinition(r); - - // Reactions marked with a `@_c_body` attribute are generated in C - if (AttributeUtils.hasCBody(reaction)) { - super.generateReaction(src, reaction, r, reactionIndex); - return; + + /** + * Do nothing. + * Methods are generated in Python not C. + * @see PythonMethodGenerator + */ + @Override + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { } + + /** + * Generate C preambles defined by user for a given reactor + * Since the Python generator expects preambles written in C, + * this function is overridden and does nothing. + * + * @param reactor The given reactor + */ + @Override + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + // Do nothing } - src.pr( - PythonReactionGenerator.generateCReaction( - reaction, reactor, reactionIndex, mainDef, errorReporter, types)); - } - - /** - * Generate code that initializes the state variables for a given instance. Unlike parameters, - * state variables are uniformly initialized for all instances of the same reactor. This task is - * left to Python code to allow for more liberal state variable assignments. - * - * @param instance The reactor class instance - * @return Initialization code fore state variables of instance - */ - @Override - protected void generateStateVariableInitializations(ReactorInstance instance) { - // Do nothing - } - - /** - * Generate runtime initialization code in C for parameters of a given reactor instance - * - * @param instance The reactor instance. - */ - @Override - protected void generateParameterInitialization(ReactorInstance instance) { - // Do nothing - // Parameters are initialized in Python - } - - /** - * Do nothing. Methods are generated in Python not C. - * - * @see PythonMethodGenerator - */ - @Override - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) {} - - /** - * Generate C preambles defined by user for a given reactor Since the Python generator expects - * preambles written in C, this function is overridden and does nothing. - * - * @param reactor The given reactor - */ - @Override - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - // Do nothing - } - - /** - * Generate code that is executed while the reactor instance is being initialized. This wraps the - * reaction functions in a Python function. - * - * @param instance The reactor instance. - */ - @Override - protected void generateReactorInstanceExtension(ReactorInstance instance) { - initializeTriggerObjects.pr( - PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); - } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the - * self struct - * - * @param selfStructBody The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - @Override - protected void generateSelfStructExtension( - CodeBuilder selfStructBody, ReactorDecl decl, CodeBuilder constructorCode) { - Reactor reactor = ASTUtils.toDefinition(decl); - // Add the name field - selfStructBody.pr("char *_lf_name;"); - int reactionIndex = 0; - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create a PyObject for each reaction - selfStructBody.pr( - "PyObject* " - + PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex) - + ";"); - if (reaction.getStp() != null) { - selfStructBody.pr( - "PyObject* " - + PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex) - + ";"); - } - if (reaction.getDeadline() != null) { - selfStructBody.pr( - "PyObject* " - + PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex) - + ";"); - } - reactionIndex++; + + /** + * Generate code that is executed while the reactor instance is being + * initialized. + * This wraps the reaction functions in a Python function. + * @param instance The reactor instance. + */ + @Override + protected void generateReactorInstanceExtension( + ReactorInstance instance + ) { + initializeTriggerObjects.pr(PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); } - } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - // NOTE: Strangely, a newline is needed at the beginning or indentation - // gets swallowed. - return String.join( - "\n", - "\n# Generated forwarding reaction for connections with the same destination", - "# but located in mutually exclusive modes.", - dest + ".set(" + source + ".value)\n"); - } - - @Override - protected void setUpGeneralParameters() { - super.setUpGeneralParameters(); - if (hasModalReactors) { - targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the self struct + * @param selfStructBody The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + @Override + protected void generateSelfStructExtension( + CodeBuilder selfStructBody, + ReactorDecl decl, + CodeBuilder constructorCode + ) { + Reactor reactor = ASTUtils.toDefinition(decl); + // Add the name field + selfStructBody.pr("char *_lf_name;"); + int reactionIndex = 0; + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create a PyObject for each reaction + selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex)+";"); + if (reaction.getStp() != null) { + selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex)+";"); + } + if (reaction.getDeadline() != null) { + selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex)+";"); + } + reactionIndex++; + } } - } - @Override - protected void additionalPostProcessingForModes() { - if (!hasModalReactors) { - return; + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + // NOTE: Strangely, a newline is needed at the beginning or indentation + // gets swallowed. + return String.join("\n", + "\n# Generated forwarding reaction for connections with the same destination", + "# but located in mutually exclusive modes.", + dest + ".set(" + source + ".value)\n" + ); } - PythonModeGenerator.generateResetReactionsIfNeeded(reactors); - } - private static String setUpMainTarget( - boolean hasMain, String executableName, Stream cSources) { - return (""" + @Override + protected void setUpGeneralParameters() { + super.setUpGeneralParameters(); + if (hasModalReactors) { + targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); + } + } + + @Override + protected void additionalPostProcessingForModes() { + if (!hasModalReactors) { + return; + } + PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + } + + private static String setUpMainTarget(boolean hasMain, String executableName, Stream cSources) { + return ( + """ set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(_LF_GARBAGE_COLLECTED) add_subdirectory(core) @@ -586,61 +611,71 @@ private static String setUpMainTarget( 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)) - .replace("executableName", executableName); - // The use of fileConfig.name will break federated execution, but that's fine - } - - /** - * Generate a (`key`, `val`) tuple pair for the `define_macros` field of the Extension class - * constructor from setuptools. - * - * @param key The key of the macro entry - * @param val The value of the macro entry - * @return A (`key`, `val`) tuple pair as String - */ - private static String generateMacroEntry(String key, String val) { - return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; - } - - /** - * Generate the name of the python module. - * - *

Ideally, this function would belong in a class like `PyFileConfig` that specifies all the - * paths to the generated code. - * - * @param lfModuleName The name of the LF module. - * @return The name of the python module. - */ - private static String generatePythonModuleName(String lfModuleName) { - return "LinguaFranca" + lfModuleName; - } - - /** - * Generate the python file name given an `lfModuleName`. - * - *

Ideally, this function would belong in a class like `PyFileConfig` that specifies all the - * paths to the generated code. - * - * @param lfModuleName The name of the LF module - * @return The name of the generated python file. - */ - private static String generatePythonFileName(String lfModuleName) { - return lfModuleName + ".py"; - } - - /** Copy Python specific target code to the src-gen directory */ - @Override - protected void copyTargetFiles() throws IOException { - super.copyTargetFiles(); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/include", fileConfig.getSrcGenPath().resolve("include"), true); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/lib", fileConfig.getSrcGenPath().resolve("lib"), true); - FileUtil.copyDirectoryFromClassPath( - "/lib/py/reactor-c-py/LinguaFrancaBase", - fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), - true); - } + """ + ).replace("", generatePythonModuleName(executableName)) + .replace("executableName", executableName); + // The use of fileConfig.name will break federated execution, but that's fine + } + + /** + * Generate a (`key`, `val`) tuple pair for the `define_macros` field + * of the Extension class constructor from setuptools. + * + * @param key The key of the macro entry + * @param val The value of the macro entry + * @return A (`key`, `val`) tuple pair as String + */ + private static String generateMacroEntry(String key, String val) { + return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; + } + + /** + * Generate the name of the python module. + * + * Ideally, this function would belong in a class like `PyFileConfig` + * that specifies all the paths to the generated code. + * + * @param lfModuleName The name of the LF module. + * @return The name of the python module. + */ + private static String generatePythonModuleName(String lfModuleName) { + return "LinguaFranca" + lfModuleName; + } + + /** + * Generate the python file name given an `lfModuleName`. + * + * Ideally, this function would belong in a class like `PyFileConfig` + * that specifies all the paths to the generated code. + * + * @param lfModuleName The name of the LF module + * @return The name of the generated python file. + */ + private static String generatePythonFileName(String lfModuleName) { + return lfModuleName + ".py"; + } + + /** + * Copy Python specific target code to the src-gen directory + */ + @Override + protected void copyTargetFiles() throws IOException { + super.copyTargetFiles(); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/include", + fileConfig.getSrcGenPath().resolve("include"), + true + ); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/lib", + fileConfig.getSrcGenPath().resolve("lib"), + true + ); + FileUtil.copyDirectoryFromClassPath( + "/lib/py/reactor-c-py/LinguaFrancaBase", + fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), + true + ); + } + } From e52a3bc220212b19d23cfd31cbc124242415bc02 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:16:13 +0200 Subject: [PATCH 227/709] Revert formatting --- .../lflang/scoping/LFScopeProviderImpl.java | 425 +-- .../org/lflang/validation/LFValidator.java | 3290 ++++++++--------- 2 files changed, 1823 insertions(+), 1892 deletions(-) diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index 32cd8d4a97..70a05a40f7 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -1,27 +1,27 @@ /************* - * Copyright (c) 2020, The University of California at Berkeley. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ***************/ +Copyright (c) 2020, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ package org.lflang.scoping; @@ -29,13 +29,16 @@ import static org.lflang.ASTUtils.*; import com.google.inject.Inject; + import java.util.ArrayList; + import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.xtext.naming.SimpleNameProvider; import org.eclipse.xtext.scoping.IScope; import org.eclipse.xtext.scoping.Scopes; import org.eclipse.xtext.scoping.impl.SelectableBasedScope; + import org.lflang.lf.Assignment; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; @@ -60,220 +63,220 @@ */ public class LFScopeProviderImpl extends AbstractLFScopeProvider { - @Inject private SimpleNameProvider nameProvider; + @Inject + private SimpleNameProvider nameProvider; - @Inject private LFGlobalScopeProvider scopeProvider; + @Inject + private LFGlobalScopeProvider scopeProvider; - /** Enumerate of the kinds of references. */ - enum RefType { - NULL, - TRIGGER, - SOURCE, - EFFECT, - WATCHDOG, - DEADLINE, - CLEFT, - CRIGHT - } + /** + * Enumerate of the kinds of references. + */ + enum RefType { + NULL, + TRIGGER, + SOURCE, + EFFECT, + WATCHDOG, + DEADLINE, + CLEFT, + CRIGHT + } - /** - * Depending on the provided context, construct the appropriate scope for the given reference. - * - * @param context The AST node in which a to-be-resolved reference occurs. - * @param reference The reference to resolve. - */ - @Override - public IScope getScope(EObject context, EReference reference) { - if (context instanceof VarRef) { - return getScopeForVarRef((VarRef) context, reference); - } else if (context instanceof Assignment) { - return getScopeForAssignment((Assignment) context, reference); - } else if (context instanceof Instantiation) { - return getScopeForReactorDecl(context, reference); - } else if (context instanceof Reactor) { - return getScopeForReactorDecl(context, reference); - } else if (context instanceof ImportedReactor) { - return getScopeForImportedReactor((ImportedReactor) context, reference); + /** + * Depending on the provided context, construct the appropriate scope + * for the given reference. + * + * @param context The AST node in which a to-be-resolved reference occurs. + * @param reference The reference to resolve. + */ + @Override + public IScope getScope(EObject context, EReference reference) { + if (context instanceof VarRef) { + return getScopeForVarRef((VarRef) context, reference); + } else if (context instanceof Assignment) { + return getScopeForAssignment((Assignment) context, reference); + } else if (context instanceof Instantiation) { + return getScopeForReactorDecl(context, reference); + } else if (context instanceof Reactor) { + return getScopeForReactorDecl(context, reference); + } else if (context instanceof ImportedReactor) { + return getScopeForImportedReactor((ImportedReactor) context, reference); + } + return super.getScope(context, reference); } - return super.getScope(context, reference); - } - /** - * Filter out candidates that do not originate from the file listed in this particular import - * statement. - */ - protected IScope getScopeForImportedReactor(ImportedReactor context, EReference reference) { - String importURI = ((Import) context.eContainer()).getImportURI(); - var importedURI = - scopeProvider.resolve(importURI == null ? "" : importURI, context.eResource()); - if (importedURI != null) { - var uniqueImportURIs = scopeProvider.getImportedUris(context.eResource()); - var descriptions = - scopeProvider.getResourceDescriptions(context.eResource(), uniqueImportURIs); - var description = descriptions.getResourceDescription(importedURI); - return SelectableBasedScope.createScope( - IScope.NULLSCOPE, description, null, reference.getEReferenceType(), false); + /** + * Filter out candidates that do not originate from the file listed in + * this particular import statement. + */ + protected IScope getScopeForImportedReactor(ImportedReactor context, EReference reference) { + String importURI = ((Import) context.eContainer()).getImportURI(); + var importedURI = scopeProvider.resolve(importURI == null ? "" : importURI, context.eResource()); + if (importedURI != null) { + var uniqueImportURIs = scopeProvider.getImportedUris(context.eResource()); + var descriptions = scopeProvider.getResourceDescriptions(context.eResource(), uniqueImportURIs); + var description = descriptions.getResourceDescription(importedURI); + return SelectableBasedScope.createScope(IScope.NULLSCOPE, description, null, reference.getEReferenceType(), false); + } + return Scopes.scopeFor(emptyList()); } - return Scopes.scopeFor(emptyList()); - } - /** - * @param obj Instantiation or Reactor that has a ReactorDecl to resolve. - * @param reference The reference to link to a ReactorDecl node. - */ - protected IScope getScopeForReactorDecl(EObject obj, EReference reference) { + /** + * @param obj Instantiation or Reactor that has a ReactorDecl to resolve. + * @param reference The reference to link to a ReactorDecl node. + */ + protected IScope getScopeForReactorDecl(EObject obj, EReference reference) { - // Find the local Model - Model model = null; - EObject container = obj; - while (model == null && container != null) { - container = container.eContainer(); - if (container instanceof Model) { - model = (Model) container; - } - } - if (model == null) { - return Scopes.scopeFor(emptyList()); - } + // Find the local Model + Model model = null; + EObject container = obj; + while(model == null && container != null) { + container = container.eContainer(); + if (container instanceof Model) { + model = (Model)container; + } + } + if (model == null) { + return Scopes.scopeFor(emptyList()); + } - // Collect eligible candidates, all of which are local (i.e., not in other files). - var locals = new ArrayList(model.getReactors()); + // Collect eligible candidates, all of which are local (i.e., not in other files). + var locals = new ArrayList(model.getReactors()); - // Either point to the import statement (if it is renamed) - // or directly to the reactor definition. - for (Import it : model.getImports()) { - for (ImportedReactor ir : it.getReactorClasses()) { - if (ir.getName() != null) { - locals.add(ir); - } else if (ir.getReactorClass() != null) { - locals.add(ir.getReactorClass()); + // Either point to the import statement (if it is renamed) + // or directly to the reactor definition. + for (Import it : model.getImports()) { + for (ImportedReactor ir : it.getReactorClasses()) { + if (ir.getName() != null) { + locals.add(ir); + } else if (ir.getReactorClass() != null) { + locals.add(ir.getReactorClass()); + } + } } - } + return Scopes.scopeFor(locals); } - return Scopes.scopeFor(locals); - } - protected IScope getScopeForAssignment(Assignment assignment, EReference reference) { + protected IScope getScopeForAssignment(Assignment assignment, EReference reference) { - if (reference == LfPackage.Literals.ASSIGNMENT__LHS) { - var defn = toDefinition(((Instantiation) assignment.eContainer()).getReactorClass()); - if (defn != null) { - return Scopes.scopeFor(allParameters(defn)); - } - } - if (reference == LfPackage.Literals.ASSIGNMENT__RHS) { - return Scopes.scopeFor(((Reactor) assignment.eContainer().eContainer()).getParameters()); + if (reference == LfPackage.Literals.ASSIGNMENT__LHS) { + var defn = toDefinition(((Instantiation) assignment.eContainer()).getReactorClass()); + if (defn != null) { + return Scopes.scopeFor(allParameters(defn)); + } + } + if (reference == LfPackage.Literals.ASSIGNMENT__RHS) { + return Scopes.scopeFor(((Reactor) assignment.eContainer().eContainer()).getParameters()); + } + return Scopes.scopeFor(emptyList()); } - return Scopes.scopeFor(emptyList()); - } - protected IScope getScopeForVarRef(VarRef variable, EReference reference) { - if (reference == LfPackage.Literals.VAR_REF__VARIABLE) { - // Resolve hierarchical reference - Reactor reactor; - Mode mode = null; - if (variable.eContainer().eContainer() instanceof Reactor) { - reactor = (Reactor) variable.eContainer().eContainer(); - } else if (variable.eContainer().eContainer() instanceof Mode) { - mode = (Mode) variable.eContainer().eContainer(); - reactor = (Reactor) variable.eContainer().eContainer().eContainer(); - } else { - return Scopes.scopeFor(emptyList()); - } + protected IScope getScopeForVarRef(VarRef variable, EReference reference) { + if (reference == LfPackage.Literals.VAR_REF__VARIABLE) { + // Resolve hierarchical reference + Reactor reactor; + Mode mode = null; + if (variable.eContainer().eContainer() instanceof Reactor) { + reactor = (Reactor) variable.eContainer().eContainer(); + } else if (variable.eContainer().eContainer() instanceof Mode) { + mode = (Mode) variable.eContainer().eContainer(); + reactor = (Reactor) variable.eContainer().eContainer().eContainer(); + } else { + return Scopes.scopeFor(emptyList()); + } - RefType type = getRefType(variable); + RefType type = getRefType(variable); - if (variable.getContainer() != null) { // Resolve hierarchical port reference - var instanceName = nameProvider.getFullyQualifiedName(variable.getContainer()); - var instances = new ArrayList(reactor.getInstantiations()); - if (mode != null) { - instances.addAll(mode.getInstantiations()); - } + if (variable.getContainer() != null) { // Resolve hierarchical port reference + var instanceName = nameProvider.getFullyQualifiedName(variable.getContainer()); + var instances = new ArrayList(reactor.getInstantiations()); + if (mode != null) { + instances.addAll(mode.getInstantiations()); + } - if (instanceName != null) { - for (var instance : instances) { - var defn = toDefinition(instance.getReactorClass()); - if (defn != null && instance.getName().equals(instanceName.toString())) { - switch (type) { - case TRIGGER: + if (instanceName != null) { + for (var instance : instances) { + var defn = toDefinition(instance.getReactorClass()); + if (defn != null && instance.getName().equals(instanceName.toString())) { + switch (type) { + case TRIGGER: + case SOURCE: + case CLEFT: + return Scopes.scopeFor(allOutputs(defn)); + case EFFECT: + case DEADLINE: + case CRIGHT: + return Scopes.scopeFor(allInputs(defn)); + } + } + } + } + return Scopes.scopeFor(emptyList()); + } else { + // Resolve local reference + switch (type) { + case TRIGGER: { + var candidates = new ArrayList(); + if (mode != null) { + candidates.addAll(mode.getActions()); + candidates.addAll(mode.getTimers()); + } + candidates.addAll(allInputs(reactor)); + candidates.addAll(allActions(reactor)); + candidates.addAll(allTimers(reactor)); + candidates.addAll(allWatchdogs(reactor)); + return Scopes.scopeFor(candidates); + } case SOURCE: - case CLEFT: - return Scopes.scopeFor(allOutputs(defn)); - case EFFECT: + return super.getScope(variable, reference); + case EFFECT: { + var candidates = new ArrayList(); + if (mode != null) { + candidates.addAll(mode.getActions()); + candidates.addAll(reactor.getModes()); + } + candidates.addAll(allOutputs(reactor)); + candidates.addAll(allActions(reactor)); + candidates.addAll(allWatchdogs(reactor)); + return Scopes.scopeFor(candidates); + } + case WATCHDOG: + return Scopes.scopeFor(allWatchdogs(reactor)); case DEADLINE: + case CLEFT: + return Scopes.scopeFor(allInputs(reactor)); case CRIGHT: - return Scopes.scopeFor(allInputs(defn)); - } - } - } - } - return Scopes.scopeFor(emptyList()); - } else { - // Resolve local reference - switch (type) { - case TRIGGER: - { - var candidates = new ArrayList(); - if (mode != null) { - candidates.addAll(mode.getActions()); - candidates.addAll(mode.getTimers()); - } - candidates.addAll(allInputs(reactor)); - candidates.addAll(allActions(reactor)); - candidates.addAll(allTimers(reactor)); - candidates.addAll(allWatchdogs(reactor)); - return Scopes.scopeFor(candidates); + return Scopes.scopeFor(allOutputs(reactor)); + default: + return Scopes.scopeFor(emptyList()); + } } - case SOURCE: + } else { // Resolve instance return super.getScope(variable, reference); - case EFFECT: - { - var candidates = new ArrayList(); - if (mode != null) { - candidates.addAll(mode.getActions()); - candidates.addAll(reactor.getModes()); - } - candidates.addAll(allOutputs(reactor)); - candidates.addAll(allActions(reactor)); - candidates.addAll(allWatchdogs(reactor)); - return Scopes.scopeFor(candidates); - } - case WATCHDOG: - return Scopes.scopeFor(allWatchdogs(reactor)); - case DEADLINE: - case CLEFT: - return Scopes.scopeFor(allInputs(reactor)); - case CRIGHT: - return Scopes.scopeFor(allOutputs(reactor)); - default: - return Scopes.scopeFor(emptyList()); } - } - } else { // Resolve instance - return super.getScope(variable, reference); } - } - private RefType getRefType(VarRef variable) { - if (variable.eContainer() instanceof Deadline) { - return RefType.DEADLINE; - } else if (variable.eContainer() instanceof Reaction) { - var reaction = (Reaction) variable.eContainer(); - if (reaction.getTriggers().contains(variable)) { - return RefType.TRIGGER; - } else if (reaction.getSources().contains(variable)) { - return RefType.SOURCE; - } else if (reaction.getEffects().contains(variable)) { - return RefType.EFFECT; - } - } else if (variable.eContainer() instanceof Connection) { - var conn = (Connection) variable.eContainer(); - if (conn.getLeftPorts().contains(variable)) { - return RefType.CLEFT; - } else if (conn.getRightPorts().contains(variable)) { - return RefType.CRIGHT; - } + private RefType getRefType(VarRef variable) { + if (variable.eContainer() instanceof Deadline) { + return RefType.DEADLINE; + } else if (variable.eContainer() instanceof Reaction) { + var reaction = (Reaction) variable.eContainer(); + if (reaction.getTriggers().contains(variable)) { + return RefType.TRIGGER; + } else if (reaction.getSources().contains(variable)) { + return RefType.SOURCE; + } else if (reaction.getEffects().contains(variable)) { + return RefType.EFFECT; + } + } else if (variable.eContainer() instanceof Connection) { + var conn = (Connection) variable.eContainer(); + if (conn.getLeftPorts().contains(variable)) { + return RefType.CLEFT; + } else if (conn.getRightPorts().contains(variable)) { + return RefType.CRIGHT; + } + } + return RefType.NULL; } - return RefType.NULL; - } } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index b0555dc4e0..7f1aa5c808 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -2,13 +2,17 @@ /************* * Copyright (c) 2019-2020, The University of California at Berkeley. + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -24,10 +28,12 @@ import static org.lflang.ASTUtils.inferPortWidth; import static org.lflang.ASTUtils.isGeneric; +import static org.lflang.ASTUtils.isInteger; +import static org.lflang.ASTUtils.isOfTimeType; +import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; import static org.lflang.ASTUtils.toOriginalText; -import com.google.inject.Inject; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -39,6 +45,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; + import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAttribute; @@ -65,6 +72,7 @@ import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; +import org.lflang.lf.CodeExpr; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; import org.lflang.lf.Expression; @@ -108,10 +116,12 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.FileUtil; +import com.google.inject.Inject; + /** * Custom validation checks for Lingua Franca programs. * - *

Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation + * Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation * * @author Edward A. Lee * @author Marten Lohstroh @@ -122,1832 +132,1750 @@ */ public class LFValidator extends BaseLFValidator { - ////////////////////////////////////////////////////////////// - //// Public check methods. - - // These methods are automatically invoked on AST nodes matching - // the types of their arguments. - // CheckType.FAST ensures that these checks run whenever a file is modified. - // Alternatives are CheckType.NORMAL (when saving) and - // CheckType.EXPENSIVE (only when right-click, validate). - // FIXME: What is the default when nothing is specified? - - // These methods are listed in alphabetical order, and, although - // it is isn't strictly required, follow a naming convention - // checkClass, where Class is the AST class, where possible. - - @Check(CheckType.FAST) - public void checkAction(Action action) { - checkName(action.getName(), Literals.VARIABLE__NAME); - if (action.getOrigin() == ActionOrigin.NONE) { - error("Action must have modifier `logical` or `physical`.", Literals.ACTION__ORIGIN); - } - if (action.getPolicy() != null && !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { - error( - "Unrecognized spacing violation policy: " - + action.getPolicy() - + ". Available policies are: " - + String.join(", ", SPACING_VIOLATION_POLICIES) - + ".", - Literals.ACTION__POLICY); + ////////////////////////////////////////////////////////////// + //// Public check methods. + + // These methods are automatically invoked on AST nodes matching + // the types of their arguments. + // CheckType.FAST ensures that these checks run whenever a file is modified. + // Alternatives are CheckType.NORMAL (when saving) and + // CheckType.EXPENSIVE (only when right-click, validate). + // FIXME: What is the default when nothing is specified? + + // These methods are listed in alphabetical order, and, although + // it is isn't strictly required, follow a naming convention + // checkClass, where Class is the AST class, where possible. + + @Check(CheckType.FAST) + public void checkAction(Action action) { + checkName(action.getName(), Literals.VARIABLE__NAME); + if (action.getOrigin() == ActionOrigin.NONE) { + error( + "Action must have modifier `logical` or `physical`.", + Literals.ACTION__ORIGIN + ); + } + if (action.getPolicy() != null && + !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { + error( + "Unrecognized spacing violation policy: " + action.getPolicy() + + ". Available policies are: " + + String.join(", ", SPACING_VIOLATION_POLICIES) + ".", + Literals.ACTION__POLICY); + } + checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); + checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); } - checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); - checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); - } - - @Check(CheckType.FAST) - public void checkInitializer(Initializer init) { - if (init.isBraces() && target != Target.CPP) { - error( - "Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); - } else if (init.isParens() && target.mandatesEqualsInitializers()) { - var message = - "This syntax is deprecated in the " - + target - + " target, use an equal sign instead of parentheses for assignment."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, Literals.INITIALIZER__PARENS); - } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { - var feature = init.isBraces() ? Literals.INITIALIZER__BRACES : Literals.INITIALIZER__PARENS; - var message = - "This syntax is deprecated, do not use parentheses or braces but an equal sign."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, feature); + + + @Check(CheckType.FAST) + public void checkInitializer(Initializer init) { + if (init.isBraces() && target != Target.CPP) { + error("Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); + } else if (init.isParens() && target.mandatesEqualsInitializers()) { + var message = "This syntax is deprecated in the " + target + + " target, use an equal sign instead of parentheses for assignment."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, Literals.INITIALIZER__PARENS); + } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { + var feature = init.isBraces() ? Literals.INITIALIZER__BRACES + : Literals.INITIALIZER__PARENS; + var message = "This syntax is deprecated, do not use parentheses or braces but an equal sign."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, feature); + } } - } - - @Check(CheckType.FAST) - public void checkBracedExpression(BracedListExpression expr) { - if (!target.allowsBracedListExpressions()) { - var message = - "Braced expression lists are not a valid expression for the " + target + " target."; - error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); + + @Check(CheckType.FAST) + public void checkBracedExpression(BracedListExpression expr) { + if (!target.allowsBracedListExpressions()) { + var message = "Braced expression lists are not a valid expression for the " + target + + " target."; + error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); + } } - } - - @Check(CheckType.FAST) - public void checkAssignment(Assignment assignment) { - - // If the left-hand side is a time parameter, make sure the assignment has units - typeCheck( - assignment.getRhs(), - ASTUtils.getInferredType(assignment.getLhs()), - Literals.ASSIGNMENT__RHS); - // If this assignment overrides a parameter that is used in a deadline, - // report possible overflow. - if (isCBasedTarget() && this.info.overflowingAssignments.contains(assignment)) { - error( - "Time value used to specify a deadline exceeds the maximum of " - + TimeValue.MAX_LONG_DEADLINE - + " nanoseconds.", - Literals.ASSIGNMENT__RHS); + + @Check(CheckType.FAST) + public void checkAssignment(Assignment assignment) { + + // If the left-hand side is a time parameter, make sure the assignment has units + typeCheck(assignment.getRhs(), ASTUtils.getInferredType(assignment.getLhs()), Literals.ASSIGNMENT__RHS); + // If this assignment overrides a parameter that is used in a deadline, + // report possible overflow. + if (isCBasedTarget() && + this.info.overflowingAssignments.contains(assignment)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.ASSIGNMENT__RHS); + } + } - } - @Check(CheckType.FAST) - public void checkConnection(Connection connection) { + @Check(CheckType.FAST) + public void checkConnection(Connection connection) { - // Report if connection is part of a cycle. - Set> cycles = this.info.topologyCycles(); - for (VarRef lp : connection.getLeftPorts()) { - for (VarRef rp : connection.getRightPorts()) { - boolean leftInCycle = false; + // Report if connection is part of a cycle. + Set> cycles = this.info.topologyCycles(); + for (VarRef lp : connection.getLeftPorts()) { + for (VarRef rp : connection.getRightPorts()) { + boolean leftInCycle = false; - for (NamedInstance it : cycles) { - if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) - || (it.getDefinition().equals(lp.getVariable()) - && it.getParent().equals(lp.getContainer()))) { - leftInCycle = true; - break; - } + for (NamedInstance it : cycles) { + if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) + || (it.getDefinition().equals(lp.getVariable()) && it.getParent().equals(lp.getContainer()))) { + leftInCycle = true; + break; + } + } + + for (NamedInstance it : cycles) { + if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) + || (it.getDefinition().equals(rp.getVariable()) && it.getParent().equals(rp.getContainer()))) { + if (leftInCycle) { + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + String reactorName = reactor.getName(); + error(String.format("Connection in reactor %s creates", reactorName) + + String.format("a cyclic dependency between %s and %s.", toOriginalText(lp), toOriginalText(rp)), + Literals.CONNECTION__DELAY); + } + } + } + } } - for (NamedInstance it : cycles) { - if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) - || (it.getDefinition().equals(rp.getVariable()) - && it.getParent().equals(rp.getContainer()))) { - if (leftInCycle) { - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - String reactorName = reactor.getName(); - error( - String.format("Connection in reactor %s creates", reactorName) - + String.format( - "a cyclic dependency between %s and %s.", - toOriginalText(lp), toOriginalText(rp)), - Literals.CONNECTION__DELAY); + // FIXME: look up all ReactorInstance objects that have a definition equal to the + // container of this connection. For each of those occurrences, the widths have to match. + // For the C target, since C has such a weak type system, check that + // the types on both sides of every connection match. For other languages, + // we leave type compatibility that language's compiler or interpreter. + if (isCBasedTarget()) { + Type type = (Type) null; + for (VarRef port : connection.getLeftPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + // Unfortunately, xtext does not generate a suitable equals() + // method for AST types, so we have to manually check the types. + if (!sameType(type, ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); + } + } + } + } + for (VarRef port : connection.getRightPorts()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + if (!sameType(type, type = ((Port) port.getVariable()).getType())) { + error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); + } + } + } } - } } - } - } - // FIXME: look up all ReactorInstance objects that have a definition equal to the - // container of this connection. For each of those occurrences, the widths have to match. - // For the C target, since C has such a weak type system, check that - // the types on both sides of every connection match. For other languages, - // we leave type compatibility that language's compiler or interpreter. - if (isCBasedTarget()) { - Type type = (Type) null; - for (VarRef port : connection.getLeftPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - // Unfortunately, xtext does not generate a suitable equals() - // method for AST types, so we have to manually check the types. - if (!sameType(type, ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); + // Check whether the total width of the left side of the connection + // matches the total width of the right side. This cannot be determined + // here if the width is not given as a constant. In that case, it is up + // to the code generator to check it. + int leftWidth = 0; + for (VarRef port : connection.getLeftPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || leftWidth < 0) { + // Cannot determine the width of the left ports. + leftWidth = -1; + } else { + leftWidth += width; } - } } - } - for (VarRef port : connection.getRightPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - if (!sameType(type, type = ((Port) port.getVariable()).getType())) { - error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); + int rightWidth = 0; + for (VarRef port : connection.getRightPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || rightWidth < 0) { + // Cannot determine the width of the left ports. + rightWidth = -1; + } else { + rightWidth += width; } - } } - } - } - // Check whether the total width of the left side of the connection - // matches the total width of the right side. This cannot be determined - // here if the width is not given as a constant. In that case, it is up - // to the code generator to check it. - int leftWidth = 0; - for (VarRef port : connection.getLeftPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || leftWidth < 0) { - // Cannot determine the width of the left ports. - leftWidth = -1; - } else { - leftWidth += width; - } - } - int rightWidth = 0; - for (VarRef port : connection.getRightPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || rightWidth < 0) { - // Cannot determine the width of the left ports. - rightWidth = -1; - } else { - rightWidth += width; - } - } + if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { + if (connection.isIterated()) { + if (leftWidth == 0 || rightWidth % leftWidth != 0) { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning(String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS + ); + } + } else { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning(String.format("Left width %s does not match right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS + ); + } + } - if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { - if (connection.isIterated()) { - if (leftWidth == 0 || rightWidth % leftWidth != 0) { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning( - String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS); - } - } else { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning( - String.format("Left width %s does not match right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS); - } - } + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + + // Make sure the right port is not already an effect of a reaction. + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + for (VarRef effect : reaction.getEffects()) { + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort.getVariable().equals(effect.getVariable()) && // Refers to the same variable + rightPort.getContainer() == effect.getContainer() && // Refers to the same instance + ( reaction.eContainer() instanceof Reactor || // Either is not part of a mode + connection.eContainer() instanceof Reactor || + connection.eContainer() == reaction.eContainer() // Or they are in the same mode + )) { + error("Cannot connect: Port named '" + effect.getVariable().getName() + + "' is already effect of a reaction.", + Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - - // Make sure the right port is not already an effect of a reaction. - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - for (VarRef effect : reaction.getEffects()) { - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort.getVariable().equals(effect.getVariable()) - && // Refers to the same variable - rightPort.getContainer() == effect.getContainer() - && // Refers to the same instance - (reaction.eContainer() instanceof Reactor - || // Either is not part of a mode - connection.eContainer() instanceof Reactor - || connection.eContainer() - == reaction.eContainer() // Or they are in the same mode - )) { - error( - "Cannot connect: Port named '" - + effect.getVariable().getName() - + "' is already effect of a reaction.", - Literals.CONNECTION__RIGHT_PORTS); - } + // Check that the right port does not already have some other + // upstream connection. + for (Connection c : reactor.getConnections()) { + if (c != connection) { + for (VarRef thisRightPort : connection.getRightPorts()) { + for (VarRef thatRightPort : c.getRightPorts()) { + if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) && // Refers to the same variable + thisRightPort.getContainer() == thatRightPort.getContainer() && // Refers to the same instance + ( connection.eContainer() instanceof Reactor || // Or either of the connections in not part of a mode + c.eContainer() instanceof Reactor || + connection.eContainer() == c.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + thisRightPort.getVariable().getName() + + "' may only appear once on the right side of a connection.", + Literals.CONNECTION__RIGHT_PORTS); + } + } + } + } } - } - } - // Check that the right port does not already have some other - // upstream connection. - for (Connection c : reactor.getConnections()) { - if (c != connection) { - for (VarRef thisRightPort : connection.getRightPorts()) { - for (VarRef thatRightPort : c.getRightPorts()) { - if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) - && // Refers to the same variable - thisRightPort.getContainer() == thatRightPort.getContainer() - && // Refers to the same instance - (connection.eContainer() instanceof Reactor - || // Or either of the connections in not part of a mode - c.eContainer() instanceof Reactor - || connection.eContainer() == c.eContainer() // Or they are in the same mode - )) { - error( - "Cannot connect: Port named '" - + thisRightPort.getVariable().getName() - + "' may only appear once on the right side of a connection.", - Literals.CONNECTION__RIGHT_PORTS); + // Check the after delay + if (connection.getDelay() != null) { + final var delay = connection.getDelay(); + if (delay instanceof ParameterReference || delay instanceof Time || delay instanceof Literal) { + checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); + } else { + error("After delays can only be given by time literals or parameters.", + Literals.CONNECTION__DELAY); } - } } - } } - // Check the after delay - if (connection.getDelay() != null) { - final var delay = connection.getDelay(); - if (delay instanceof ParameterReference - || delay instanceof Time - || delay instanceof Literal) { - checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); - } else { - error( - "After delays can only be given by time literals or parameters.", - Literals.CONNECTION__DELAY); - } - } - } - - @Check(CheckType.FAST) - public void checkDeadline(Deadline deadline) { - if (isCBasedTarget() && this.info.overflowingDeadlines.contains(deadline)) { - error( - "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.DEADLINE__DELAY); - } - checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); - } - - @Check(CheckType.FAST) - public void checkHost(Host host) { - String addr = host.getAddr(); - String user = host.getUser(); - if (user != null && !user.matches(USERNAME_REGEX)) { - warning("Invalid user name.", Literals.HOST__USER); - } - if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { - warning("Invalid IP address.", Literals.HOST__ADDR); - } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { - warning("Invalid IP address.", Literals.HOST__ADDR); - } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { - warning("Invalid host name or fully qualified domain name.", Literals.HOST__ADDR); + @Check(CheckType.FAST) + public void checkDeadline(Deadline deadline) { + if (isCBasedTarget() && + this.info.overflowingDeadlines.contains(deadline)) { + error( + "Deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.DEADLINE__DELAY); + } + checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); } - } - @Check - public void checkImport(Import imp) { - if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { - error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. - return; + @Check(CheckType.FAST) + public void checkHost(Host host) { + String addr = host.getAddr(); + String user = host.getUser(); + if (user != null && !user.matches(USERNAME_REGEX)) { + warning( + "Invalid user name.", + Literals.HOST__USER + ); + } + if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { + warning( + "Invalid IP address.", + Literals.HOST__ADDR + ); + } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { + warning( + "Invalid IP address.", + Literals.HOST__ADDR + ); + } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { + warning( + "Invalid host name or fully qualified domain name.", + Literals.HOST__ADDR + ); + } } - // FIXME: report error if resource cannot be resolved. - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (!isUnused(reactor)) { - return; - } - } - warning("Unused import.", Literals.IMPORT__IMPORT_URI); - } + @Check + public void checkImport(Import imp) { + if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { + error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. + return; + } - @Check - public void checkImportedReactor(ImportedReactor reactor) { - if (isUnused(reactor)) { - warning("Unused reactor class.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); + // FIXME: report error if resource cannot be resolved. + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (!isUnused(reactor)) { + return; + } + } + warning("Unused import.", Literals.IMPORT__IMPORT_URI); } - if (info.instantiationGraph.hasCycles()) { - Set cycleSet = new HashSet<>(); - for (Set cycle : info.instantiationGraph.getCycles()) { - cycleSet.addAll(cycle); - } - if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { - error( - "Imported reactor '" - + toDefinition(reactor).getName() - + "' has cyclic instantiation in it.", - Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } - } - } + @Check + public void checkImportedReactor(ImportedReactor reactor) { + if (isUnused(reactor)) { + warning("Unused reactor class.", + Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } - @Check(CheckType.FAST) - public void checkInput(Input input) { - Reactor parent = (Reactor) input.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); - } - checkName(input.getName(), Literals.VARIABLE__NAME); - if (target.requiresTypes) { - if (input.getType() == null) { - error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); - } + if (info.instantiationGraph.hasCycles()) { + Set cycleSet = new HashSet<>(); + for (Set cycle : info.instantiationGraph.getCycles()) { + cycleSet.addAll(cycle); + } + if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { + error("Imported reactor '" + toDefinition(reactor).getName() + + "' has cyclic instantiation in it.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } + } } - // mutable has no meaning in C++ - if (input.isMutable() && this.target == Target.CPP) { - warning( - "The mutable qualifier has no meaning for the C++ target and should be removed. " - + "In C++, any value can be made mutable by calling get_mutable_copy().", - Literals.INPUT__MUTABLE); - } + @Check(CheckType.FAST) + public void checkInput(Input input) { + Reactor parent = (Reactor)input.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); + } + checkName(input.getName(), Literals.VARIABLE__NAME); + if (target.requiresTypes) { + if (input.getType() == null) { + error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); + } + } - // Variable width multiports are not supported (yet?). - if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } - } - - @Check(CheckType.FAST) - public void checkInstantiation(Instantiation instantiation) { - checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); - Reactor reactor = toDefinition(instantiation.getReactorClass()); - if (reactor.isMain() || reactor.isFederated()) { - error( - "Cannot instantiate a main (or federated) reactor: " - + instantiation.getReactorClass().getName(), - Literals.INSTANTIATION__REACTOR_CLASS); + // mutable has no meaning in C++ + if (input.isMutable() && this.target == Target.CPP) { + warning( + "The mutable qualifier has no meaning for the C++ target and should be removed. " + + "In C++, any value can be made mutable by calling get_mutable_copy().", + Literals.INPUT__MUTABLE + ); + } + + // Variable width multiports are not supported (yet?). + if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } } - // Report error if this instantiation is part of a cycle. - // FIXME: improve error message. - // FIXME: Also report if there exists a cycle within. - if (this.info.instantiationGraph.getCycles().size() > 0) { - for (Set cycle : this.info.instantiationGraph.getCycles()) { - Reactor container = (Reactor) instantiation.eContainer(); - if (cycle.contains(container) && cycle.contains(reactor)) { - List names = new ArrayList<>(); - for (Reactor r : cycle) { - names.add(r.getName()); - } + @Check(CheckType.FAST) + public void checkInstantiation(Instantiation instantiation) { + checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); + Reactor reactor = toDefinition(instantiation.getReactorClass()); + if (reactor.isMain() || reactor.isFederated()) { + error( + "Cannot instantiate a main (or federated) reactor: " + + instantiation.getReactorClass().getName(), + Literals.INSTANTIATION__REACTOR_CLASS + ); + } - error( - "Instantiation is part of a cycle: " + String.join(", ", names) + ".", - Literals.INSTANTIATION__REACTOR_CLASS); + // Report error if this instantiation is part of a cycle. + // FIXME: improve error message. + // FIXME: Also report if there exists a cycle within. + if (this.info.instantiationGraph.getCycles().size() > 0) { + for (Set cycle : this.info.instantiationGraph.getCycles()) { + Reactor container = (Reactor) instantiation.eContainer(); + if (cycle.contains(container) && cycle.contains(reactor)) { + List names = new ArrayList<>(); + for (Reactor r : cycle) { + names.add(r.getName()); + } + + error( + "Instantiation is part of a cycle: " + String.join(", ", names) + ".", + Literals.INSTANTIATION__REACTOR_CLASS + ); + } + } + } + // Variable width multiports are not supported (yet?). + if (instantiation.getWidthSpec() != null + && instantiation.getWidthSpec().isOfVariableLength() + ) { + if (isCBasedTarget()) { + warning("Variable-width banks are for internal use only.", + Literals.INSTANTIATION__WIDTH_SPEC + ); + } else { + error("Variable-width banks are not supported.", + Literals.INSTANTIATION__WIDTH_SPEC + ); + } } - } - } - // Variable width multiports are not supported (yet?). - if (instantiation.getWidthSpec() != null && instantiation.getWidthSpec().isOfVariableLength()) { - if (isCBasedTarget()) { - warning( - "Variable-width banks are for internal use only.", Literals.INSTANTIATION__WIDTH_SPEC); - } else { - error("Variable-width banks are not supported.", Literals.INSTANTIATION__WIDTH_SPEC); - } - } - } - - /** Check target parameters, which are key-value pairs. */ - @Check(CheckType.FAST) - public void checkKeyValuePair(KeyValuePair param) { - // Check only if the container's container is a Target. - if (param.eContainer().eContainer() instanceof TargetDecl) { - TargetProperty prop = TargetProperty.forName(param.getName()); - - // Make sure the key is valid. - if (prop == null) { - String options = - TargetProperty.getOptions().stream() - .map(p -> p.description) - .sorted() - .collect(Collectors.joining(", ")); - warning( - "Unrecognized target parameter: " - + param.getName() - + ". Recognized parameters are: " - + options, - Literals.KEY_VALUE_PAIR__NAME); - } else { - // Check whether the property is supported by the target. - if (!prop.supportedBy.contains(this.target)) { - warning( - "The target parameter: " - + param.getName() - + " is not supported by the " - + this.target - + " target and will thus be ignored.", - Literals.KEY_VALUE_PAIR__NAME); - } - - // Report problem with the assigned value. - prop.type.check(param.getValue(), param.getName(), this); - } - - for (String it : targetPropertyErrors) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyErrors.clear(); - - for (String it : targetPropertyWarnings) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyWarnings.clear(); - } - } - - @Check(CheckType.FAST) - public void checkModel(Model model) { - // Since we're doing a fast check, we only want to update - // if the model info hasn't been initialized yet. If it has, - // we use the old information and update it during a normal - // check (see below). - if (!info.updated) { - info.update(model, errorReporter); - } - } - - @Check(CheckType.NORMAL) - public void updateModelInfo(Model model) { - info.update(model, errorReporter); - } - - @Check(CheckType.FAST) - public void checkOutput(Output output) { - Reactor parent = (Reactor) output.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); - } - checkName(output.getName(), Literals.VARIABLE__NAME); - if (this.target.requiresTypes) { - if (output.getType() == null) { - error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); - } } - // Variable width multiports are not supported (yet?). - if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } - } + /** Check target parameters, which are key-value pairs. */ + @Check(CheckType.FAST) + public void checkKeyValuePair(KeyValuePair param) { + // Check only if the container's container is a Target. + if (param.eContainer().eContainer() instanceof TargetDecl) { + TargetProperty prop = TargetProperty.forName(param.getName()); + + // Make sure the key is valid. + if (prop == null) { + String options = TargetProperty.getOptions().stream() + .map(p -> p.description).sorted() + .collect(Collectors.joining(", ")); + warning( + "Unrecognized target parameter: " + param.getName() + + ". Recognized parameters are: " + options, + Literals.KEY_VALUE_PAIR__NAME); + } else { + // Check whether the property is supported by the target. + if (!prop.supportedBy.contains(this.target)) { + warning( + "The target parameter: " + param.getName() + + " is not supported by the " + this.target + + " target and will thus be ignored.", + Literals.KEY_VALUE_PAIR__NAME); + } - @Check(CheckType.FAST) - public void checkParameter(Parameter param) { - checkName(param.getName(), Literals.PARAMETER__NAME); + // Report problem with the assigned value. + prop.type.check(param.getValue(), param.getName(), this); + } - if (param.getInit() == null) { - // todo make initialization non-mandatory - // https://github.com/lf-lang/lingua-franca/issues/623 - error("Parameter must have a default value.", Literals.PARAMETER__INIT); - return; + for (String it : targetPropertyErrors) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyErrors.clear(); + + for (String it : targetPropertyWarnings) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyWarnings.clear(); + } } - if (this.target.requiresTypes) { - // Report missing target type. param.inferredType.undefine - if (ASTUtils.getInferredType(param).isUndefined()) { - error("Type declaration missing.", Literals.PARAMETER__TYPE); - } + @Check(CheckType.FAST) + public void checkModel(Model model) { + // Since we're doing a fast check, we only want to update + // if the model info hasn't been initialized yet. If it has, + // we use the old information and update it during a normal + // check (see below). + if (!info.updated) { + info.update(model, errorReporter); + } } - if (param.getType() != null) { - typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); + @Check(CheckType.NORMAL) + public void updateModelInfo(Model model) { + info.update(model, errorReporter); } - if (param.getInit() != null) { - for (Expression expr : param.getInit().getExprs()) { - if (expr instanceof ParameterReference) { - // Initialization using parameters is forbidden. - error("Parameter cannot be initialized using parameter.", Literals.PARAMETER__INIT); + @Check(CheckType.FAST) + public void checkOutput(Output output) { + Reactor parent = (Reactor)output.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); + } + checkName(output.getName(), Literals.VARIABLE__NAME); + if (this.target.requiresTypes) { + if (output.getType() == null) { + error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - } - } - if (this.target == Target.CPP) { - EObject container = param.eContainer(); - Reactor reactor = (Reactor) container; - if (reactor.isMain()) { - // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); - if (cliParams.contains(param.getName())) { - error( - "Parameter '" - + param.getName() - + "' is already in use as command line argument by Lingua Franca,", - Literals.PARAMETER__NAME); - } - } + // Variable width multiports are not supported (yet?). + if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } } - if (isCBasedTarget() && this.info.overflowingParameters.contains(param)) { - error( - "Time value used to specify a deadline exceeds the maximum of " - + TimeValue.MAX_LONG_DEADLINE - + " nanoseconds.", - Literals.PARAMETER__INIT); - } - } - - @Check(CheckType.FAST) - public void checkPreamble(Preamble preamble) { - if (this.target == Target.CPP) { - if (preamble.getVisibility() == Visibility.NONE) { - error( - "Preambles for the C++ target need a visibility qualifier (private or public)!", - Literals.PREAMBLE__VISIBILITY); - } else if (preamble.getVisibility() == Visibility.PRIVATE) { - EObject container = preamble.eContainer(); - if (container != null && container instanceof Reactor) { - Reactor reactor = (Reactor) container; - if (isGeneric(reactor)) { - warning( - "Private preambles in generic reactors are not truly private. " - + "Since the generated code is placed in a *_impl.hh file, it will " - + "be visible on the public interface. Consider using a public " - + "preamble within the reactor or a private preamble on file scope.", - Literals.PREAMBLE__VISIBILITY); - } + @Check(CheckType.FAST) + public void checkParameter(Parameter param) { + checkName(param.getName(), Literals.PARAMETER__NAME); + + if (param.getInit() == null) { + // todo make initialization non-mandatory + // https://github.com/lf-lang/lingua-franca/issues/623 + error("Parameter must have a default value.", Literals.PARAMETER__INIT); + return; + } + + if (this.target.requiresTypes) { + // Report missing target type. param.inferredType.undefine + if (ASTUtils.getInferredType(param).isUndefined()) { + error("Type declaration missing.", Literals.PARAMETER__TYPE); + } } - } - } else if (preamble.getVisibility() != Visibility.NONE) { - warning( - String.format( - "The %s qualifier has no meaning for the %s target. It should be removed.", - preamble.getVisibility(), this.target.name()), - Literals.PREAMBLE__VISIBILITY); - } - } - @Check(CheckType.FAST) - public void checkReaction(Reaction reaction) { + if (param.getType() != null) { + typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); + } - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); - } - HashSet triggers = new HashSet<>(); - // Make sure input triggers have no container and output sources do. - for (TriggerRef trigger : reaction.getTriggers()) { - if (trigger instanceof VarRef) { - VarRef triggerVarRef = (VarRef) trigger; - triggers.add(triggerVarRef.getVariable()); - if (triggerVarRef instanceof Input) { - if (triggerVarRef.getContainer() != null) { - error( - String.format( - "Cannot have an input of a contained reactor as a trigger: %s.%s", - triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } else if (triggerVarRef.getVariable() instanceof Output) { - if (triggerVarRef.getContainer() == null) { + if (param.getInit() != null) { + for (Expression expr : param.getInit().getExprs()) { + if (expr instanceof ParameterReference) { + // Initialization using parameters is forbidden. + error("Parameter cannot be initialized using parameter.", + Literals.PARAMETER__INIT); + } + } + } + + if (this.target == Target.CPP) { + EObject container = param.eContainer(); + Reactor reactor = (Reactor) container; + if (reactor.isMain()) { + // we need to check for the cli parameters that are always taken + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); + if (cliParams.contains(param.getName())) { + error("Parameter '" + param.getName() + + "' is already in use as command line argument by Lingua Franca,", + Literals.PARAMETER__NAME); + } + } + } + + if (isCBasedTarget() && + this.info.overflowingParameters.contains(param)) { error( - String.format( - "Cannot have an output of this reactor as a trigger: %s", - triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.PARAMETER__INIT); } - } - } - // Make sure input sources have no container and output sources do. - // Also check that a source is not already listed as a trigger. - for (VarRef source : reaction.getSources()) { - if (triggers.contains(source.getVariable())) { - error( - String.format( - "Source is already listed as a trigger: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - if (source.getVariable() instanceof Input) { - if (source.getContainer() != null) { - error( - String.format( - "Cannot have an input of a contained reactor as a source: %s.%s", - source.getContainer().getName(), source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } else if (source.getVariable() instanceof Output) { - if (source.getContainer() == null) { - error( - String.format( - "Cannot have an output of this reactor as a source: %s", - source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } } - // Make sure output effects have no container and input effects do. - for (VarRef effect : reaction.getEffects()) { - if (effect.getVariable() instanceof Input) { - if (effect.getContainer() == null) { - error( - String.format( - "Cannot have an input of this reactor as an effect: %s", - effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } else if (effect.getVariable() instanceof Output) { - if (effect.getContainer() != null) { - error( - String.format( - "Cannot have an output of a contained reactor as an effect: %s.%s", - effect.getContainer().getName(), effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } + @Check(CheckType.FAST) + public void checkPreamble(Preamble preamble) { + if (this.target == Target.CPP) { + if (preamble.getVisibility() == Visibility.NONE) { + error( + "Preambles for the C++ target need a visibility qualifier (private or public)!", + Literals.PREAMBLE__VISIBILITY + ); + } else if (preamble.getVisibility() == Visibility.PRIVATE) { + EObject container = preamble.eContainer(); + if (container != null && container instanceof Reactor) { + Reactor reactor = (Reactor) container; + if (isGeneric(reactor)) { + warning( + "Private preambles in generic reactors are not truly private. " + + "Since the generated code is placed in a *_impl.hh file, it will " + + "be visible on the public interface. Consider using a public " + + "preamble within the reactor or a private preamble on file scope.", + Literals.PREAMBLE__VISIBILITY); + } + } + } + } else if (preamble.getVisibility() != Visibility.NONE) { + warning( + String.format("The %s qualifier has no meaning for the %s target. It should be removed.", + preamble.getVisibility(), this.target.name()), + Literals.PREAMBLE__VISIBILITY + ); + } } - // // Report error if this reaction is part of a cycle. - Set> cycles = this.info.topologyCycles(); - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - boolean reactionInCycle = false; - for (NamedInstance it : cycles) { - if (it.getDefinition().equals(reaction)) { - reactionInCycle = true; - break; - } - } - if (reactionInCycle) { - // Report involved triggers. - List trigs = new ArrayList<>(); - for (TriggerRef t : reaction.getTriggers()) { - if (!(t instanceof VarRef)) { - continue; - } - VarRef tVarRef = (VarRef) t; - boolean triggerExistsInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(tVarRef.getVariable())) { - triggerExistsInCycle = true; - break; - } + @Check(CheckType.FAST) + public void checkReaction(Reaction reaction) { + + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); } - if (triggerExistsInCycle) { - trigs.add(toOriginalText(tVarRef)); - } - } - if (trigs.size() > 0) { - error( - String.format( - "Reaction triggers involved in cyclic dependency in reactor %s: %s.", - reactor.getName(), String.join(", ", trigs)), - Literals.REACTION__TRIGGERS); - } - - // Report involved sources. - List sources = new ArrayList<>(); - for (VarRef t : reaction.getSources()) { - boolean sourceExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - sourceExistInCycle = true; - break; - } + HashSet triggers = new HashSet<>(); + // Make sure input triggers have no container and output sources do. + for (TriggerRef trigger : reaction.getTriggers()) { + if (trigger instanceof VarRef) { + VarRef triggerVarRef = (VarRef) trigger; + triggers.add(triggerVarRef.getVariable()); + if (triggerVarRef instanceof Input) { + if (triggerVarRef.getContainer() != null) { + error(String.format("Cannot have an input of a contained reactor as a trigger: %s.%s", triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } else if (triggerVarRef.getVariable() instanceof Output) { + if (triggerVarRef.getContainer() == null) { + error(String.format("Cannot have an output of this reactor as a trigger: %s", triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } + } } - if (sourceExistInCycle) { - sources.add(toOriginalText(t)); - } - } - if (sources.size() > 0) { - error( - String.format( - "Reaction sources involved in cyclic dependency in reactor %s: %s.", - reactor.getName(), String.join(", ", sources)), - Literals.REACTION__SOURCES); - } - - // Report involved effects. - List effects = new ArrayList<>(); - for (VarRef t : reaction.getEffects()) { - boolean effectExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - effectExistInCycle = true; - break; - } + + // Make sure input sources have no container and output sources do. + // Also check that a source is not already listed as a trigger. + for (VarRef source : reaction.getSources()) { + if (triggers.contains(source.getVariable())) { + error(String.format("Source is already listed as a trigger: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + if (source.getVariable() instanceof Input) { + if (source.getContainer() != null) { + error(String.format("Cannot have an input of a contained reactor as a source: %s.%s", source.getContainer().getName(), source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } else if (source.getVariable() instanceof Output) { + if (source.getContainer() == null) { + error(String.format("Cannot have an output of this reactor as a source: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } + } + + // Make sure output effects have no container and input effects do. + for (VarRef effect : reaction.getEffects()) { + if (effect.getVariable() instanceof Input) { + if (effect.getContainer() == null) { + error(String.format("Cannot have an input of this reactor as an effect: %s", effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } else if (effect.getVariable() instanceof Output) { + if (effect.getContainer() != null) { + error(String.format("Cannot have an output of a contained reactor as an effect: %s.%s", effect.getContainer().getName(), effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } + } + + // // Report error if this reaction is part of a cycle. + Set> cycles = this.info.topologyCycles(); + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + boolean reactionInCycle = false; + for (NamedInstance it : cycles) { + if (it.getDefinition().equals(reaction)) { + reactionInCycle = true; + break; + } + } + if (reactionInCycle) { + // Report involved triggers. + List trigs = new ArrayList<>(); + for (TriggerRef t : reaction.getTriggers()) { + if (!(t instanceof VarRef)) { + continue; + } + VarRef tVarRef = (VarRef) t; + boolean triggerExistsInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(tVarRef.getVariable())) { + triggerExistsInCycle = true; + break; + } + } + if (triggerExistsInCycle) { + trigs.add(toOriginalText(tVarRef)); + } + } + if (trigs.size() > 0) { + error(String.format("Reaction triggers involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", trigs)), + Literals.REACTION__TRIGGERS); + } + + // Report involved sources. + List sources = new ArrayList<>(); + for (VarRef t : reaction.getSources()) { + boolean sourceExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + sourceExistInCycle = true; + break; + } + } + if (sourceExistInCycle) { + sources.add(toOriginalText(t)); + } + } + if (sources.size() > 0) { + error(String.format("Reaction sources involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", sources)), + Literals.REACTION__SOURCES); + } + + // Report involved effects. + List effects = new ArrayList<>(); + for (VarRef t : reaction.getEffects()) { + boolean effectExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + effectExistInCycle = true; + break; + } + } + if (effectExistInCycle) { + effects.add(toOriginalText(t)); + } + } + if (effects.size() > 0) { + error(String.format("Reaction effects involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", effects)), + Literals.REACTION__EFFECTS); + } + + if (trigs.size() + sources.size() == 0) { + error( + String.format("Cyclic dependency due to preceding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction) + ); + } else if (effects.size() == 0) { + error( + String.format("Cyclic dependency due to succeeding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction) + ); + } + // Not reporting reactions that are part of cycle _only_ due to reaction ordering. + // Moving them won't help solve the problem. } - if (effectExistInCycle) { - effects.add(toOriginalText(t)); - } - } - if (effects.size() > 0) { - error( - String.format( - "Reaction effects involved in cyclic dependency in reactor %s: %s.", - reactor.getName(), String.join(", ", effects)), - Literals.REACTION__EFFECTS); - } - - if (trigs.size() + sources.size() == 0) { - error( - String.format( - "Cyclic dependency due to preceding reaction. Consider reordering reactions within" - + " reactor %s to avoid causality loop.", - reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction)); - } else if (effects.size() == 0) { - error( - String.format( - "Cyclic dependency due to succeeding reaction. Consider reordering reactions within" - + " reactor %s to avoid causality loop.", - reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction)); - } - // Not reporting reactions that are part of cycle _only_ due to reaction ordering. - // Moving them won't help solve the problem. - } // FIXME: improve error message. - } - - @Check(CheckType.FAST) - public void checkReactor(Reactor reactor) throws IOException { - Set superClasses = ASTUtils.superClasses(reactor); - if (superClasses == null) { - error( - "Problem with superclasses: Either they form a cycle or are not defined", - Literals.REACTOR_DECL__NAME); - // Continue checks, but without any superclasses. - superClasses = new LinkedHashSet<>(); - } - String name = FileUtil.nameWithoutExtension(reactor.eResource()); - if (reactor.getName() == null) { - if (!reactor.isFederated() && !reactor.isMain()) { - error("Reactor must be named.", Literals.REACTOR_DECL__NAME); - // Prevent NPE in tests below. - return; - } } - TreeIterator iter = reactor.eResource().getAllContents(); - if (reactor.isFederated() || reactor.isMain()) { - if (reactor.getName() != null && !reactor.getName().equals(name)) { - // Make sure that if the name is given, it matches the expected name. - error( - "Name of main reactor must match the file name (or be omitted).", - Literals.REACTOR_DECL__NAME); - } - // Do not allow multiple main/federated reactors. - int nMain = countMainOrFederated(iter); - if (nMain > 1) { - EAttribute attribute = Literals.REACTOR__MAIN; + + @Check(CheckType.FAST) + public void checkReactor(Reactor reactor) throws IOException { + Set superClasses = ASTUtils.superClasses(reactor); + if (superClasses == null) { + error( + "Problem with superclasses: Either they form a cycle or are not defined", + Literals.REACTOR_DECL__NAME + ); + // Continue checks, but without any superclasses. + superClasses = new LinkedHashSet<>(); + } + String name = FileUtil.nameWithoutExtension(reactor.eResource()); + if (reactor.getName() == null) { + if (!reactor.isFederated() && !reactor.isMain()) { + error( + "Reactor must be named.", + Literals.REACTOR_DECL__NAME + ); + // Prevent NPE in tests below. + return; + } + } + TreeIterator iter = reactor.eResource().getAllContents(); + if (reactor.isFederated() || reactor.isMain()) { + if(reactor.getName() != null && !reactor.getName().equals(name)) { + // Make sure that if the name is given, it matches the expected name. + error( + "Name of main reactor must match the file name (or be omitted).", + Literals.REACTOR_DECL__NAME + ); + } + // Do not allow multiple main/federated reactors. + int nMain = countMainOrFederated(iter); + if (nMain > 1) { + EAttribute attribute = Literals.REACTOR__MAIN; + if (reactor.isFederated()) { + attribute = Literals.REACTOR__FEDERATED; + } + error( + "Multiple definitions of main or federated reactor.", + attribute + ); + } + } else { + // Not federated or main. + int nMain = countMainOrFederated(iter); + if (nMain > 0 && reactor.getName().equals(name)) { + error( + "Name conflict with main reactor.", + Literals.REACTOR_DECL__NAME + ); + } + } + + // Check for illegal names. + checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); + + // C++ reactors may not be called 'preamble' + if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { + error( + "Reactor cannot be named '" + reactor.getName() + "'", + Literals.REACTOR_DECL__NAME + ); + } + + if (reactor.getHost() != null) { + if (!reactor.isFederated()) { + error( + "Cannot assign a host to reactor '" + reactor.getName() + + "' because it is not federated.", + Literals.REACTOR__HOST + ); + } + } + + List variables = new ArrayList<>(); + variables.addAll(reactor.getInputs()); + variables.addAll(reactor.getOutputs()); + variables.addAll(reactor.getActions()); + variables.addAll(reactor.getTimers()); + + // Perform checks on super classes. + for (Reactor superClass : superClasses) { + HashSet conflicts = new HashSet<>(); + + // Detect input conflicts + checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); + // Detect conflicts + for (Timer timer : superClass.getTimers()) { + List filteredVariables = new ArrayList<>(variables); + filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); + if (hasNameConflict(timer, filteredVariables)) { + conflicts.add(timer); + } else { + variables.add(timer); + } + } + + // Report conflicts. + if (conflicts.size() > 0) { + List names = new ArrayList<>(); + for (Variable it : conflicts) { + names.add(it.getName()); + } + error( + String.format("Cannot extend %s due to the following conflicts: %s.", + superClass.getName(), String.join(",", names)), + Literals.REACTOR__SUPER_CLASSES + ); + } + } + if (reactor.isFederated()) { - attribute = Literals.REACTOR__FEDERATED; - } - error("Multiple definitions of main or federated reactor.", attribute); - } - } else { - // Not federated or main. - int nMain = countMainOrFederated(iter); - if (nMain > 0 && reactor.getName().equals(name)) { - error("Name conflict with main reactor.", Literals.REACTOR_DECL__NAME); - } + FedValidator.validateFederatedReactor(reactor, this.errorReporter); + } } - // Check for illegal names. - checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); + /** + * Check if the requested serialization is supported. + */ + @Check(CheckType.FAST) + public void checkSerializer(Serializer serializer) { + boolean isValidSerializer = false; + for (SupportedSerializers method : SupportedSerializers.values()) { + if (method.name().equalsIgnoreCase(serializer.getType())){ + isValidSerializer = true; + } + } - // C++ reactors may not be called 'preamble' - if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { - error("Reactor cannot be named '" + reactor.getName() + "'", Literals.REACTOR_DECL__NAME); + if (!isValidSerializer) { + error( + "Serializer can be " + Arrays.asList(SupportedSerializers.values()), + Literals.SERIALIZER__TYPE + ); + } } - if (reactor.getHost() != null) { - if (!reactor.isFederated()) { - error( - "Cannot assign a host to reactor '" - + reactor.getName() - + "' because it is not federated.", - Literals.REACTOR__HOST); - } - } + @Check(CheckType.FAST) + public void checkState(StateVar stateVar) { + checkName(stateVar.getName(), Literals.STATE_VAR__NAME); + if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { + typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); + } - List variables = new ArrayList<>(); - variables.addAll(reactor.getInputs()); - variables.addAll(reactor.getOutputs()); - variables.addAll(reactor.getActions()); - variables.addAll(reactor.getTimers()); - - // Perform checks on super classes. - for (Reactor superClass : superClasses) { - HashSet conflicts = new HashSet<>(); - - // Detect input conflicts - checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); - // Detect conflicts - for (Timer timer : superClass.getTimers()) { - List filteredVariables = new ArrayList<>(variables); - filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); - if (hasNameConflict(timer, filteredVariables)) { - conflicts.add(timer); - } else { - variables.add(timer); - } - } - - // Report conflicts. - if (conflicts.size() > 0) { - List names = new ArrayList<>(); - for (Variable it : conflicts) { - names.add(it.getName()); - } - error( - String.format( - "Cannot extend %s due to the following conflicts: %s.", - superClass.getName(), String.join(",", names)), - Literals.REACTOR__SUPER_CLASSES); - } - } + if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { + // Report if a type is missing + error("State must have a type.", Literals.STATE_VAR__TYPE); + } - if (reactor.isFederated()) { - FedValidator.validateFederatedReactor(reactor, this.errorReporter); - } - } - - /** Check if the requested serialization is supported. */ - @Check(CheckType.FAST) - public void checkSerializer(Serializer serializer) { - boolean isValidSerializer = false; - for (SupportedSerializers method : SupportedSerializers.values()) { - if (method.name().equalsIgnoreCase(serializer.getType())) { - isValidSerializer = true; - } - } + if (isCBasedTarget() + && ASTUtils.isListInitializer(stateVar.getInit()) + && stateVar.getInit().getExprs().stream().anyMatch(it -> it instanceof ParameterReference)) { + // In C, if initialization is done with a list, elements cannot + // refer to parameters. + error("List items cannot refer to a parameter.", + Literals.STATE_VAR__INIT); + } - if (!isValidSerializer) { - error( - "Serializer can be " + Arrays.asList(SupportedSerializers.values()), - Literals.SERIALIZER__TYPE); } - } - @Check(CheckType.FAST) - public void checkState(StateVar stateVar) { - checkName(stateVar.getName(), Literals.STATE_VAR__NAME); - if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { - typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); + @Check(CheckType.FAST) + public void checkSTPOffset(STP stp) { + if (isCBasedTarget() && + this.info.overflowingSTP.contains(stp)) { + error( + "STP offset exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.STP__VALUE); + } } - if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { - // Report if a type is missing - error("State must have a type.", Literals.STATE_VAR__TYPE); + @Check(CheckType.FAST) + public void checkTargetDecl(TargetDecl target) throws IOException { + Optional targetOpt = Target.forName(target.getName()); + if (targetOpt.isEmpty()) { + error("Unrecognized target: " + target.getName(), + Literals.TARGET_DECL__NAME); + } else { + this.target = targetOpt.get(); + } + String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); + if (Character.isDigit(lfFileName.charAt(0))) { + errorReporter.reportError("LF file names must not start with a number"); + } } - if (isCBasedTarget() - && ASTUtils.isListInitializer(stateVar.getInit()) - && stateVar.getInit().getExprs().stream() - .anyMatch(it -> it instanceof ParameterReference)) { - // In C, if initialization is done with a list, elements cannot - // refer to parameters. - error("List items cannot refer to a parameter.", Literals.STATE_VAR__INIT); - } - } - - @Check(CheckType.FAST) - public void checkSTPOffset(STP stp) { - if (isCBasedTarget() && this.info.overflowingSTP.contains(stp)) { - error( - "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.STP__VALUE); - } - } - - @Check(CheckType.FAST) - public void checkTargetDecl(TargetDecl target) throws IOException { - Optional targetOpt = Target.forName(target.getName()); - if (targetOpt.isEmpty()) { - error("Unrecognized target: " + target.getName(), Literals.TARGET_DECL__NAME); - } else { - this.target = targetOpt.get(); - } - String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); - if (Character.isDigit(lfFileName.charAt(0))) { - errorReporter.reportError("LF file names must not start with a number"); - } - } - - /** - * Check for consistency of the target properties, which are defined as KeyValuePairs. - * - * @param targetProperties The target properties defined in the current Lingua Franca program. - */ - @Check(CheckType.EXPENSIVE) - public void checkTargetProperties(KeyValuePairs targetProperties) { - validateFastTargetProperty(targetProperties); - validateClockSyncTargetProperties(targetProperties); - validateSchedulerTargetProperties(targetProperties); - validateRos2TargetProperties(targetProperties); - validateKeepalive(targetProperties); - } - - private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { - List properties = - targetProperties.getPairs().stream() + /** + * Check for consistency of the target properties, which are + * defined as KeyValuePairs. + * + * @param targetProperties The target properties defined + * in the current Lingua Franca program. + */ + @Check(CheckType.EXPENSIVE) + public void checkTargetProperties(KeyValuePairs targetProperties) { + validateFastTargetProperty(targetProperties); + validateClockSyncTargetProperties(targetProperties); + validateSchedulerTargetProperties(targetProperties); + validateRos2TargetProperties(targetProperties); + validateKeepalive(targetProperties); + } + + private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { + List properties = targetProperties.getPairs().stream() .filter(pair -> pair.getName().equals(property.description)) .toList(); - assert (properties.size() <= 1); - return properties.size() > 0 ? properties.get(0) : null; - } + assert (properties.size() <= 1); + return properties.size() > 0 ? properties.get(0) : null; + } + private void validateFastTargetProperty(KeyValuePairs targetProperties) { + KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); + + if (fastTargetProperty != null) { + // Check for federated + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a federated reactor + if (reactor.isFederated()) { + error( + "The fast target property is incompatible with federated programs.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME + ); + break; + } + } + + // Check for physical actions + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a physical action in a reactor + for (Action action : reactor.getActions()) { + if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { + error( + "The fast target property is incompatible with physical actions.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME + ); + break; + } + } + } + } + } - private void validateFastTargetProperty(KeyValuePairs targetProperties) { - KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); + private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair clockSyncTargetProperty = getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); - if (fastTargetProperty != null) { - // Check for federated - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a federated reactor - if (reactor.isFederated()) { - error( - "The fast target property is incompatible with federated programs.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME); - break; - } - } - - // Check for physical actions - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a physical action in a reactor - for (Action action : reactor.getActions()) { - if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { - error( - "The fast target property is incompatible with physical actions.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME); - break; - } + if (clockSyncTargetProperty != null) { + boolean federatedExists = false; + for (Reactor reactor : info.model.getReactors()) { + if (reactor.isFederated()) { + federatedExists = true; + } + } + if (!federatedExists) { + warning( + "The clock-sync target property is incompatible with non-federated programs.", + clockSyncTargetProperty, + Literals.KEY_VALUE_PAIR__NAME + ); + } } - } } - } - private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair clockSyncTargetProperty = - getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); + private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair schedulerTargetProperty = getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); + if (schedulerTargetProperty != null) { + String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); + try { + if (!TargetProperty.SchedulerOption.valueOf(schedulerName) + .prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + // Filter reactors that contain at least one reaction that + // has a deadline handler. + if (info.model.getReactors().stream().anyMatch( + // Filter reactors that contain at least one reaction that + // has a deadline handler. + reactor -> ASTUtils.allReactions(reactor).stream().anyMatch( + reaction -> reaction.getDeadline() != null + )) + ) { + warning("This program contains deadlines, but the chosen " + + schedulerName + + " scheduler does not prioritize reaction execution " + + "based on deadlines. This might result in a sub-optimal " + + "scheduling.", schedulerTargetProperty, + Literals.KEY_VALUE_PAIR__VALUE); + } + } + } catch (IllegalArgumentException e) { + // the given scheduler is invalid, but this is already checked by + // checkTargetProperties + } + } + } - if (clockSyncTargetProperty != null) { - boolean federatedExists = false; - for (Reactor reactor : info.model.getReactors()) { - if (reactor.isFederated()) { - federatedExists = true; - } - } - if (!federatedExists) { - warning( - "The clock-sync target property is incompatible with non-federated programs.", - clockSyncTargetProperty, - Literals.KEY_VALUE_PAIR__NAME); - } + private void validateKeepalive(KeyValuePairs targetProperties) { + KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); + if (keepalive != null && target == Target.CPP) { + warning("The keepalive property is inferred automatically by the C++ " + + "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); + } } - } - - private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair schedulerTargetProperty = - getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); - if (schedulerTargetProperty != null) { - String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); - try { - if (!TargetProperty.SchedulerOption.valueOf(schedulerName).prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - // Filter reactors that contain at least one reaction that - // has a deadline handler. - if (info.model.getReactors().stream() - .anyMatch( - // Filter reactors that contain at least one reaction that - // has a deadline handler. - reactor -> - ASTUtils.allReactions(reactor).stream() - .anyMatch(reaction -> reaction.getDeadline() != null))) { + + private void validateRos2TargetProperties(KeyValuePairs targetProperties) { + KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); + KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); + if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { warning( - "This program contains deadlines, but the chosen " - + schedulerName - + " scheduler does not prioritize reaction execution " - + "based on deadlines. This might result in a sub-optimal " - + "scheduling.", - schedulerTargetProperty, - Literals.KEY_VALUE_PAIR__VALUE); - } + "Ignoring ros2-dependencies as ros2 compilation is disabled", + ros2Dependencies, + Literals.KEY_VALUE_PAIR__NAME + ); } - } catch (IllegalArgumentException e) { - // the given scheduler is invalid, but this is already checked by - // checkTargetProperties - } - } - } - - private void validateKeepalive(KeyValuePairs targetProperties) { - KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); - if (keepalive != null && target == Target.CPP) { - warning( - "The keepalive property is inferred automatically by the C++ " - + "runtime and the value given here is ignored", - keepalive, - Literals.KEY_VALUE_PAIR__NAME); } - } - - private void validateRos2TargetProperties(KeyValuePairs targetProperties) { - KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); - KeyValuePair ros2Dependencies = - getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); - if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { - warning( - "Ignoring ros2-dependencies as ros2 compilation is disabled", - ros2Dependencies, - Literals.KEY_VALUE_PAIR__NAME); + + @Check(CheckType.FAST) + public void checkTimer(Timer timer) { + checkName(timer.getName(), Literals.VARIABLE__NAME); + checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); + checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); } - } - - @Check(CheckType.FAST) - public void checkTimer(Timer timer) { - checkName(timer.getName(), Literals.VARIABLE__NAME); - checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); - checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); - } - - @Check(CheckType.FAST) - public void checkType(Type type) { - // FIXME: disallow the use of generics in C - if (this.target == Target.Python) { - if (type != null) { - error("Types are not allowed in the Python target", Literals.TYPE__ID); - } + + @Check(CheckType.FAST) + public void checkType(Type type) { + // FIXME: disallow the use of generics in C + if (this.target == Target.Python) { + if (type != null) { + error( + "Types are not allowed in the Python target", + Literals.TYPE__ID + ); + } + } } - } - - @Check(CheckType.FAST) - public void checkVarRef(VarRef varRef) { - // check correct usage of interleaved - if (varRef.isInterleaved()) { - var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); - if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { - error( - "This target does not support interleaved port references.", - Literals.VAR_REF__INTERLEAVED); - } - if (!(varRef.eContainer() instanceof Connection)) { - error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); - } - - if (varRef.getVariable() instanceof Port) { - // This test only works correctly if the variable is actually a port. If it is not a port, - // other - // validator rules will produce error messages. - if (varRef.getContainer() == null - || varRef.getContainer().getWidthSpec() == null - || ((Port) varRef.getVariable()).getWidthSpec() == null) { - error( - "interleaved can only be used for multiports contained within banks.", - Literals.VAR_REF__INTERLEAVED); - } - } + + @Check(CheckType.FAST) + public void checkVarRef(VarRef varRef) { + // check correct usage of interleaved + if (varRef.isInterleaved()) { + var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); + if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { + error("This target does not support interleaved port references.", Literals.VAR_REF__INTERLEAVED); + } + if (!(varRef.eContainer() instanceof Connection)) { + error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); + } + + if (varRef.getVariable() instanceof Port) { + // This test only works correctly if the variable is actually a port. If it is not a port, other + // validator rules will produce error messages. + if (varRef.getContainer() == null || varRef.getContainer().getWidthSpec() == null || + ((Port) varRef.getVariable()).getWidthSpec() == null + ) { + error("interleaved can only be used for multiports contained within banks.", Literals.VAR_REF__INTERLEAVED); + } + } + } } - } - - /** - * Check whether an attribute is supported and the validity of the attribute. - * - * @param attr The attribute being checked - */ - @Check(CheckType.FAST) - public void checkAttributes(Attribute attr) { - String name = attr.getAttrName().toString(); - AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); - if (spec == null) { - error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); - return; + + /** + * Check whether an attribute is supported + * and the validity of the attribute. + * + * @param attr The attribute being checked + */ + @Check(CheckType.FAST) + public void checkAttributes(Attribute attr) { + String name = attr.getAttrName().toString(); + AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); + if (spec == null) { + error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); + return; + } + // Check the validity of the attribute. + spec.check(this, attr); } - // Check the validity of the attribute. - spec.check(this, attr); - } - - @Check(CheckType.FAST) - public void checkWidthSpec(WidthSpec widthSpec) { - if (!this.target.supportsMultiports()) { - error( - "Multiports and banks are currently not supported by the given target.", - Literals.WIDTH_SPEC__TERMS); - } else { - for (WidthTerm term : widthSpec.getTerms()) { - if (term.getParameter() != null) { - if (!this.target.supportsParameterizedWidths()) { - error( - "Parameterized widths are not supported by this target.", + + @Check(CheckType.FAST) + public void checkWidthSpec(WidthSpec widthSpec) { + if (!this.target.supportsMultiports()) { + error("Multiports and banks are currently not supported by the given target.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getPort() != null) { - // Widths given with `widthof()` are not supported (yet?). - // This feature is currently only used for after delays. - error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); - } else if (term.getCode() != null) { - if (this.target != Target.CPP) { - error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getWidth() < 0) { - error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); + } else { + for (WidthTerm term : widthSpec.getTerms()) { + if (term.getParameter() != null) { + if (!this.target.supportsParameterizedWidths()) { + error("Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getPort() != null) { + // Widths given with `widthof()` are not supported (yet?). + // This feature is currently only used for after delays. + error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); + } else if (term.getCode() != null) { + if (this.target != Target.CPP) { + error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getWidth() < 0) { + error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); + } + } } - } } - } - - @Check(CheckType.FAST) - public void checkReactorIconAttribute(Reactor reactor) { - var path = AttributeUtils.getIconPath(reactor); - if (path != null) { - var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); - // Check file extension - var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); - var extensionStrart = path.lastIndexOf("."); - var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; - if (!validExtensions.contains(extension.toLowerCase())) { - warning( - "File extension '" - + extension - + "' is not supported. Provide any of: " - + String.join(", ", validExtensions), - param, - Literals.ATTR_PARM__VALUE); - return; - } - - // Check file location - var iconLocation = FileUtil.locateFile(path, reactor.eResource()); - if (iconLocation == null) { - warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); - } - if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) - && !(new File(iconLocation.getPath()).exists())) { - warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); - } + + @Check(CheckType.FAST) + public void checkReactorIconAttribute(Reactor reactor) { + var path = AttributeUtils.getIconPath(reactor); + if (path != null) { + var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); + // Check file extension + var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); + var extensionStrart = path.lastIndexOf("."); + var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; + if (!validExtensions.contains(extension.toLowerCase())) { + warning("File extension '" + extension + "' is not supported. Provide any of: " + String.join(", ", validExtensions), + param, Literals.ATTR_PARM__VALUE); + return; + } + + // Check file location + var iconLocation = FileUtil.locateFile(path, reactor.eResource()); + if (iconLocation == null) { + warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); + } + if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) && !(new File(iconLocation.getPath()).exists())) { + warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); + } + } } - } - - @Check(CheckType.FAST) - public void checkInitialMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); - if (initialModesCount == 0) { - error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); - } else if (initialModesCount > 1) { - reactor.getModes().stream() - .filter(m -> m.isInitial()) - .skip(1) - .forEach( - m -> { - error( - "A modal reactor can only have one initial mode.", - Literals.REACTOR__MODES, - reactor.getModes().indexOf(m)); + + @Check(CheckType.FAST) + public void checkInitialMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); + if (initialModesCount == 0) { + error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); + } else if (initialModesCount > 1) { + reactor.getModes().stream().filter(m -> m.isInitial()).skip(1).forEach(m -> { + error("A modal reactor can only have one initial mode.", + Literals.REACTOR__MODES, reactor.getModes().indexOf(m)); }); - } - } - } - - @Check(CheckType.FAST) - public void checkModeStateNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var stateVar : mode.getStateVars()) { - if (names.contains(stateVar.getName())) { - error( - String.format( - "Duplicate state variable '%s'. (State variables are currently scoped on" - + " reactor level not modes)", - stateVar.getName()), - stateVar, - Literals.STATE_VAR__NAME); - } - names.add(stateVar.getName()); + } } - } } - } - - @Check(CheckType.FAST) - public void checkModeTimerNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var timer : mode.getTimers()) { - if (names.contains(timer.getName())) { - error( - String.format( - "Duplicate Timer '%s'. (Timers are currently scoped on reactor level not" - + " modes)", - timer.getName()), - timer, - Literals.VARIABLE__NAME); - } - names.add(timer.getName()); + + @Check(CheckType.FAST) + public void checkModeStateNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var stateVar : mode.getStateVars()) { + if (names.contains(stateVar.getName())) { + error(String.format("Duplicate state variable '%s'. (State variables are currently scoped on reactor level not modes)", + stateVar.getName()), stateVar, Literals.STATE_VAR__NAME); + } + names.add(stateVar.getName()); + } + } } - } } - } - - @Check(CheckType.FAST) - public void checkModeActionNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var action : mode.getActions()) { - if (names.contains(action.getName())) { - error( - String.format( - "Duplicate Action '%s'. (Actions are currently scoped on reactor level not" - + " modes)", - action.getName()), - action, - Literals.VARIABLE__NAME); - } - names.add(action.getName()); + + @Check(CheckType.FAST) + public void checkModeTimerNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var timer : mode.getTimers()) { + if (names.contains(timer.getName())) { + error(String.format("Duplicate Timer '%s'. (Timers are currently scoped on reactor level not modes)", + timer.getName()), timer, Literals.VARIABLE__NAME); + } + names.add(timer.getName()); + } + } } - } } - } - - @Check(CheckType.FAST) - public void checkModeInstanceNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var instantiation : mode.getInstantiations()) { - if (names.contains(instantiation.getName())) { - error( - String.format( - "Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor" - + " level not modes)", - instantiation.getName()), - instantiation, - Literals.INSTANTIATION__NAME); - } - names.add(instantiation.getName()); + + @Check(CheckType.FAST) + public void checkModeActionNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var action : mode.getActions()) { + if (names.contains(action.getName())) { + error(String.format("Duplicate Action '%s'. (Actions are currently scoped on reactor level not modes)", + action.getName()), action, Literals.VARIABLE__NAME); + } + names.add(action.getName()); + } + } } - } } - } - - @Check(CheckType.FAST) - public void checkMissingStateResetInMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var resetModes = new HashSet(); - // Collect all modes that may be reset - for (var m : reactor.getModes()) { - for (var r : m.getReactions()) { - for (var e : r.getEffects()) { - if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { - resetModes.add((Mode) e.getVariable()); + + @Check(CheckType.FAST) + public void checkModeInstanceNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var instantiation : mode.getInstantiations()) { + if (names.contains(instantiation.getName())) { + error(String.format("Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor level not modes)", + instantiation.getName()), instantiation, Literals.INSTANTIATION__NAME); + } + names.add(instantiation.getName()); + } } - } } - } - for (var m : resetModes) { - // Check state variables in this mode - if (!m.getStateVars().isEmpty()) { - var hasResetReaction = - m.getReactions().stream() - .anyMatch( - r -> - r.getTriggers().stream() - .anyMatch( - t -> - (t instanceof BuiltinTriggerRef - && ((BuiltinTriggerRef) t).getType() - == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - for (var s : m.getStateVars()) { - if (!s.isReset()) { - error( - "State variable is not reset upon mode entry. It is neither marked for" - + " automatic reset nor is there a reset reaction.", - m, - Literals.MODE__STATE_VARS, - m.getStateVars().indexOf(s)); - } + } + + @Check(CheckType.FAST) + public void checkMissingStateResetInMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var resetModes = new HashSet(); + // Collect all modes that may be reset + for (var m : reactor.getModes()) { + for (var r : m.getReactions()) { + for (var e : r.getEffects()) { + if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { + resetModes.add((Mode) e.getVariable()); + } + } + } } - } - } - // Check state variables in instantiated reactors - if (!m.getInstantiations().isEmpty()) { - for (var i : m.getInstantiations()) { - var error = new LinkedHashSet(); - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty()) { - var check = toCheck.pop(); - checked.add(check); - if (!check.getStateVars().isEmpty()) { - var hasResetReaction = - check.getReactions().stream() - .anyMatch( - r -> - r.getTriggers().stream() - .anyMatch( - t -> - (t instanceof BuiltinTriggerRef - && ((BuiltinTriggerRef) t).getType() - == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - // Add state vars that are not self-resetting to the error - check.getStateVars().stream() - .filter(s -> !s.isReset()) - .forEachOrdered(error::add); + for (var m : resetModes) { + // Check state variables in this mode + if (!m.getStateVars().isEmpty()) { + var hasResetReaction = m.getReactions().stream().anyMatch( + r -> r.getTriggers().stream().anyMatch( + t -> (t instanceof BuiltinTriggerRef && + ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + for (var s : m.getStateVars()) { + if (!s.isReset()) { + error("State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction.", + m, Literals.MODE__STATE_VARS, m.getStateVars().indexOf(s)); + } + } + } } - } - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); + // Check state variables in instantiated reactors + if (!m.getInstantiations().isEmpty()) { + for (var i : m.getInstantiations()) { + var error = new LinkedHashSet(); + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty()) { + var check = toCheck.pop(); + checked.add(check); + if (!check.getStateVars().isEmpty()) { + var hasResetReaction = check.getReactions().stream().anyMatch( + r -> r.getTriggers().stream().anyMatch( + t -> (t instanceof BuiltinTriggerRef && + ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + // Add state vars that are not self-resetting to the error + check.getStateVars().stream().filter(s -> !s.isReset()).forEachOrdered(error::add); + } + } + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } + } + } + if (!error.isEmpty()) { + error("This reactor contains state variables that are not reset upon mode entry: " + + error.stream().map(e -> e.getName() + " in " + + ASTUtils.getEnclosingReactor(e).getName()).collect(Collectors.joining(", ")) + + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " + + "It is unsafe to instantiate this reactor inside a mode entered with reset.", + m, Literals.MODE__INSTANTIATIONS, + m.getInstantiations().indexOf(i)); + } + } } - } - } - if (!error.isEmpty()) { - error( - "This reactor contains state variables that are not reset upon mode entry: " - + error.stream() - .map( - e -> e.getName() + " in " + ASTUtils.getEnclosingReactor(e).getName()) - .collect(Collectors.joining(", ")) - + ".\n" - + "The state variables are neither marked for automatic reset nor have a" - + " dedicated reset reaction. It is unsafe to instantiate this reactor inside" - + " a mode entered with reset.", - m, - Literals.MODE__INSTANTIATIONS, - m.getInstantiations().indexOf(i)); } - } } - } } - } - - @Check(CheckType.FAST) - public void checkStateResetWithoutInitialValue(StateVar state) { - if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { - error( - "The state variable can not be automatically reset without an initial value.", - state, - Literals.STATE_VAR__RESET); + + @Check(CheckType.FAST) + public void checkStateResetWithoutInitialValue(StateVar state) { + if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { + error("The state variable can not be automatically reset without an initial value.", state, Literals.STATE_VAR__RESET); + } } - } - - @Check(CheckType.FAST) - public void checkUnspecifiedTransitionType(Reaction reaction) { - for (var effect : reaction.getEffects()) { - var variable = effect.getVariable(); - if (variable instanceof Mode) { - // The transition type is always set to default by Xtext. - // Hence, check if there is an explicit node for the transition type in the AST. - var transitionAssignment = - NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); - if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. - var mode = (Mode) variable; - // Check if reset or history transition would make a difference. - var makesDifference = - !mode.getStateVars().isEmpty() - || !mode.getTimers().isEmpty() - || !mode.getActions().isEmpty() - || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); - if (!makesDifference && !mode.getInstantiations().isEmpty()) { - // Also check instantiated reactors - for (var i : mode.getInstantiations()) { - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty() && !makesDifference) { - var check = toCheck.pop(); - checked.add(check); - - makesDifference |= - !check.getModes().isEmpty() - || !ASTUtils.allStateVars(check).isEmpty() - || !ASTUtils.allTimers(check).isEmpty() - || !ASTUtils.allActions(check).isEmpty() - || ASTUtils.allConnections(check).stream() - .anyMatch(c -> c.getDelay() != null); - - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } + + @Check(CheckType.FAST) + public void checkUnspecifiedTransitionType(Reaction reaction) { + for (var effect : reaction.getEffects()) { + var variable = effect.getVariable(); + if (variable instanceof Mode) { + // The transition type is always set to default by Xtext. + // Hence, check if there is an explicit node for the transition type in the AST. + var transitionAssignment = NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); + if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. + var mode = (Mode) variable; + // Check if reset or history transition would make a difference. + var makesDifference = !mode.getStateVars().isEmpty() + || !mode.getTimers().isEmpty() + || !mode.getActions().isEmpty() + || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); + if (!makesDifference && !mode.getInstantiations().isEmpty()) { + // Also check instantiated reactors + for (var i : mode.getInstantiations()) { + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty() && !makesDifference) { + var check = toCheck.pop(); + checked.add(check); + + makesDifference |= !check.getModes().isEmpty() + || !ASTUtils.allStateVars(check).isEmpty() + || !ASTUtils.allTimers(check).isEmpty() + || !ASTUtils.allActions(check).isEmpty() + || ASTUtils.allConnections(check).stream().anyMatch(c -> c.getDelay() != null); + + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } + } + } + } + } + if (makesDifference) { + warning("You should specify a transition type! " + + "Reset and history transitions have different effects on this target mode. " + + "Currently, a reset type is implicitly assumed.", + reaction, Literals.REACTION__EFFECTS, reaction.getEffects().indexOf(effect)); + } } - } } - } - if (makesDifference) { - warning( - "You should specify a transition type! " - + "Reset and history transitions have different effects on this target mode. " - + "Currently, a reset type is implicitly assumed.", - reaction, - Literals.REACTION__EFFECTS, - reaction.getEffects().indexOf(effect)); - } } - } - } - } - - ////////////////////////////////////////////////////////////// - //// Public methods. - - /** Return the error reporter for this validator. */ - public ValidatorErrorReporter getErrorReporter() { - return this.errorReporter; - } - - /** Implementation required by xtext to report validation errors. */ - @Override - public ValidationMessageAcceptor getMessageAcceptor() { - return messageAcceptor == null ? this : messageAcceptor; - } - - /** Return a list of error messages for the target declaration. */ - public List getTargetPropertyErrors() { - return this.targetPropertyErrors; - } - - ////////////////////////////////////////////////////////////// - //// Protected methods. - - /** Generate an error message for an AST node. */ - @Override - protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature) { - super.error(message, feature); - } - - ////////////////////////////////////////////////////////////// - //// Private methods. - - /** - * For each input, report a conflict if: 1) the input exists and the type doesn't match; or 2) the - * input has a name clash with variable that is not an input. - * - * @param superVars List of typed variables of a particular kind (i.e., inputs, outputs, or - * actions), found in a super class. - * @param sameKind Typed variables of the same kind, found in the subclass. - * @param allOwn Accumulator of non-conflicting variables incorporated in the subclass. - * @param conflicts Set of variables that are in conflict, to be used by this function to report - * conflicts. - */ - private void checkConflict( - EList superVars, EList sameKind, List allOwn, HashSet conflicts) { - for (T superVar : superVars) { - T match = null; - for (T it : sameKind) { - if (it.getName().equals(superVar.getName())) { - match = it; - break; - } - } - List rest = new ArrayList<>(allOwn); - rest.removeIf(it -> sameKind.contains(it)); - - if ((match != null && superVar.getType() != match.getType()) - || hasNameConflict(superVar, rest)) { - conflicts.add(superVar); - } else { - allOwn.add(superVar); - } - } - } - - /** - * Check the name of a feature for illegal substrings such as reserved identifiers and names with - * double leading underscores. - * - * @param name The name. - * @param feature The feature containing the name (for error reporting). - */ - private void checkName(String name, EStructuralFeature feature) { - - // Raises an error if the string starts with two underscores. - if (name.length() >= 2 && name.substring(0, 2).equals("__")) { - error(UNDERSCORE_MESSAGE + name, feature); } - if (this.target.isReservedIdent(name)) { - error(RESERVED_MESSAGE + name, feature); - } + ////////////////////////////////////////////////////////////// + //// Public methods. + + /** + * Return the error reporter for this validator. + */ + public ValidatorErrorReporter getErrorReporter() { + return this.errorReporter; + } + + /** + * Implementation required by xtext to report validation errors. + */ + @Override + public ValidationMessageAcceptor getMessageAcceptor() { + return messageAcceptor == null ? this : messageAcceptor; + } + + /** + * Return a list of error messages for the target declaration. + */ + public List getTargetPropertyErrors() { + return this.targetPropertyErrors; + } + + ////////////////////////////////////////////////////////////// + //// Protected methods. + + /** + * Generate an error message for an AST node. + */ + @Override + protected void error(java.lang.String message, + org.eclipse.emf.ecore.EStructuralFeature feature) { + super.error(message, feature); + } + + ////////////////////////////////////////////////////////////// + //// Private methods. + + /** + * For each input, report a conflict if: + * 1) the input exists and the type doesn't match; or + * 2) the input has a name clash with variable that is not an input. + * @param superVars List of typed variables of a particular kind (i.e., + * inputs, outputs, or actions), found in a super class. + * @param sameKind Typed variables of the same kind, found in the subclass. + * @param allOwn Accumulator of non-conflicting variables incorporated in the + * subclass. + * @param conflicts Set of variables that are in conflict, to be used by this + * function to report conflicts. + */ + private void checkConflict ( + EList superVars, EList sameKind, List allOwn, HashSet conflicts + ) { + for (T superVar : superVars) { + T match = null; + for (T it : sameKind) { + if (it.getName().equals(superVar.getName())) { + match = it; + break; + } + } + List rest = new ArrayList<>(allOwn); + rest.removeIf(it -> sameKind.contains(it)); - if (this.target == Target.TS) { - // "actions" is a reserved word within a TS reaction - if (name.equals("actions")) { - error(ACTIONS_MESSAGE + name, feature); - } - } - } - - /** - * Check that the initializer is compatible with the type. Note that if the type is inferred it - * will necessarily be compatible so this method is not harmful. - */ - public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { - if (init == null) { - return; + if ((match != null && superVar.getType() != match.getType()) || hasNameConflict(superVar, rest)) { + conflicts.add(superVar); + } else { + allOwn.add(superVar); + } + } } - // TODO: - // type is list => init is list - // type is fixed with size n => init is fixed with size n - // Specifically for C: list can only be literal or time lists + /** + * Check the name of a feature for illegal substrings such as reserved + * identifiers and names with double leading underscores. + * @param name The name. + * @param feature The feature containing the name (for error reporting). + */ + private void checkName(String name, EStructuralFeature feature) { - if (type.isTime) { - if (type.isList) { - // list of times - var exprs = init.getExprs(); - if (exprs.isEmpty()) { - error("Expected at least one time value.", feature); - return; + // Raises an error if the string starts with two underscores. + if (name.length() >= 2 && name.substring(0, 2).equals("__")) { + error(UNDERSCORE_MESSAGE + name, feature); } - if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { - exprs = ((BracedListExpression) exprs.get(0)).getItems(); + + if (this.target.isReservedIdent(name)) { + error(RESERVED_MESSAGE + name, feature); } - for (var component : exprs) { - checkExpressionIsTime(component, feature); + + if (this.target == Target.TS) { + // "actions" is a reserved word within a TS reaction + if (name.equals("actions")) { + error(ACTIONS_MESSAGE + name, feature); + } } - } else { - checkExpressionIsTime(init, feature); - } } - } - private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { - if (init == null) { - return; - } - if (init.getExprs().size() != 1) { - error("Expected exactly one time value.", feature); - } else { - checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); - } - } + /** + * Check that the initializer is compatible with the type. + * Note that if the type is inferred it will necessarily be compatible + * so this method is not harmful. + */ + public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { + if (init == null) { + return; + } - private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { - if (value == null || value instanceof Time) { - return; + // TODO: + // type is list => init is list + // type is fixed with size n => init is fixed with size n + // Specifically for C: list can only be literal or time lists + + if (type.isTime) { + if (type.isList) { + // list of times + var exprs = init.getExprs(); + if (exprs.isEmpty()) { + error("Expected at least one time value.", feature); + return; + } + if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { + exprs = ((BracedListExpression) exprs.get(0)).getItems(); + } + for (var component : exprs) { + checkExpressionIsTime(component, feature); + } + } else { + checkExpressionIsTime(init, feature); + } + } } - if (value instanceof ParameterReference) { - if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) - && target.requiresTypes) { - error("Referenced parameter is not of time type.", feature); - } - return; - } else if (value instanceof Literal) { - if (ASTUtils.isZero(((Literal) value).getLiteral())) { - return; - } - - if (ASTUtils.isInteger(((Literal) value).getLiteral())) { - error("Missing time unit.", feature); - return; - } - // fallthrough - } + private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { + if (init == null) { + return; + } - error("Invalid time value.", feature); - } - - /** - * Return the number of main or federated reactors declared. - * - * @param iter An iterator over all objects in the resource. - */ - private int countMainOrFederated(TreeIterator iter) { - int nMain = 0; - while (iter.hasNext()) { - EObject obj = iter.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor r = (Reactor) obj; - if (r.isMain() || r.isFederated()) { - nMain++; - } - } - return nMain; - } - - /** - * Report whether a given reactor has dependencies on a cyclic instantiation pattern. This means - * the reactor has an instantiation in it -- directly or in one of its contained reactors -- that - * is self-referential. - * - * @param reactor The reactor definition to find out whether it has any dependencies on cyclic - * instantiations. - * @param cycleSet The set of all reactors that are part of an instantiation cycle. - * @param visited The set of nodes already visited in this graph traversal. - */ - private boolean dependsOnCycle(Reactor reactor, Set cycleSet, Set visited) { - Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); - if (visited.contains(reactor)) { - return false; - } else { - visited.add(reactor); - for (Reactor it : origins) { - if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { - // Reached a cycle. - return true; - } - } - } - return false; - } - - /** - * Report whether the name of the given element matches any variable in the ones to check against. - * - * @param element The element to compare against all variables in the given iterable. - * @param toCheckAgainst Iterable variables to compare the given element against. - */ - private boolean hasNameConflict(Variable element, Iterable toCheckAgainst) { - int numNameConflicts = 0; - for (Variable it : toCheckAgainst) { - if (it.getName().equals(element.getName())) { - numNameConflicts++; - } - } - return numNameConflicts > 0; - } - - /** Return true if target is C or a C-based target like CCpp. */ - private boolean isCBasedTarget() { - return (this.target == Target.C || this.target == Target.CCPP); - } - - /** - * Report whether a given imported reactor is used in this resource or not. - * - * @param reactor The imported reactor to check whether it is used. - */ - private boolean isUnused(ImportedReactor reactor) { - TreeIterator instantiations = reactor.eResource().getAllContents(); - TreeIterator subclasses = reactor.eResource().getAllContents(); - - boolean instantiationsCheck = true; - while (instantiations.hasNext() && instantiationsCheck) { - EObject obj = instantiations.next(); - if (!(obj instanceof Instantiation)) { - continue; - } - Instantiation inst = (Instantiation) obj; - instantiationsCheck &= - (inst.getReactorClass() != reactor - && inst.getReactorClass() != reactor.getReactorClass()); + if (init.getExprs().size() != 1) { + error("Expected exactly one time value.", feature); + } else { + checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); + } } - boolean subclassesCheck = true; - while (subclasses.hasNext() && subclassesCheck) { - EObject obj = subclasses.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor subclass = (Reactor) obj; - for (ReactorDecl decl : subclass.getSuperClasses()) { - subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); - } + private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { + if (value == null || value instanceof Time) { + return; + } + + if (value instanceof ParameterReference) { + if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) + && target.requiresTypes) { + error("Referenced parameter is not of time type.", feature); + } + return; + } else if (value instanceof Literal) { + if (ASTUtils.isZero(((Literal) value).getLiteral())) { + return; + } + + if (ASTUtils.isInteger(((Literal) value).getLiteral())) { + error("Missing time unit.", feature); + return; + } + // fallthrough + } + + error("Invalid time value.", feature); } - return instantiationsCheck && subclassesCheck; - } - - /** - * Return true if the two types match. Unfortunately, xtext does not seem to create a suitable - * equals() method for Type, so we have to do this manually. - */ - private boolean sameType(Type type1, Type type2) { - if (type1 == null) { - return type2 == null; + + /** + * Return the number of main or federated reactors declared. + * + * @param iter An iterator over all objects in the resource. + */ + private int countMainOrFederated(TreeIterator iter) { + int nMain = 0; + while (iter.hasNext()) { + EObject obj = iter.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor r = (Reactor) obj; + if (r.isMain() || r.isFederated()) { + nMain++; + } + } + return nMain; + } + + /** + * Report whether a given reactor has dependencies on a cyclic + * instantiation pattern. This means the reactor has an instantiation + * in it -- directly or in one of its contained reactors -- that is + * self-referential. + * @param reactor The reactor definition to find out whether it has any + * dependencies on cyclic instantiations. + * @param cycleSet The set of all reactors that are part of an + * instantiation cycle. + * @param visited The set of nodes already visited in this graph traversal. + */ + private boolean dependsOnCycle( + Reactor reactor, Set cycleSet, Set visited + ) { + Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); + if (visited.contains(reactor)) { + return false; + } else { + visited.add(reactor); + for (Reactor it : origins) { + if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { + // Reached a cycle. + return true; + } + } + } + return false; + } + + /** + * Report whether the name of the given element matches any variable in + * the ones to check against. + * @param element The element to compare against all variables in the given iterable. + * @param toCheckAgainst Iterable variables to compare the given element against. + */ + private boolean hasNameConflict(Variable element, + Iterable toCheckAgainst) { + int numNameConflicts = 0; + for (Variable it : toCheckAgainst) { + if (it.getName().equals(element.getName())) { + numNameConflicts++; + } + } + return numNameConflicts > 0; } - if (type2 == null) { - return type1 == null; + + /** + * Return true if target is C or a C-based target like CCpp. + */ + private boolean isCBasedTarget() { + return (this.target == Target.C || this.target == Target.CCPP); } - // Most common case first. - if (type1.getId() != null) { - if (type1.getStars() != null) { - if (type2.getStars() == null) return false; - if (type1.getStars().size() != type2.getStars().size()) return false; - } - return (type1.getId().equals(type2.getId())); + + /** + * Report whether a given imported reactor is used in this resource or not. + * @param reactor The imported reactor to check whether it is used. + */ + private boolean isUnused(ImportedReactor reactor) { + TreeIterator instantiations = reactor.eResource().getAllContents(); + TreeIterator subclasses = reactor.eResource().getAllContents(); + + boolean instantiationsCheck = true; + while (instantiations.hasNext() && instantiationsCheck) { + EObject obj = instantiations.next(); + if (!(obj instanceof Instantiation)) { + continue; + } + Instantiation inst = (Instantiation) obj; + instantiationsCheck &= (inst.getReactorClass() != reactor && inst.getReactorClass() != reactor.getReactorClass()); + } + + boolean subclassesCheck = true; + while (subclasses.hasNext() && subclassesCheck) { + EObject obj = subclasses.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor subclass = (Reactor) obj; + for (ReactorDecl decl : subclass.getSuperClasses()) { + subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); + } + } + return instantiationsCheck && subclassesCheck; } - // Type specification in the grammar is: - // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' - // typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); - if (type1.isTime()) { - if (!type2.isTime()) return false; - // Ignore the arraySpec because that is checked when connection - // is checked for balance. - return true; + /** + * Return true if the two types match. Unfortunately, xtext does not + * seem to create a suitable equals() method for Type, so we have to + * do this manually. + */ + private boolean sameType(Type type1, Type type2) { + if (type1 == null) { + return type2 == null; + } + if (type2 == null) { + return type1 == null; + } + // Most common case first. + if (type1.getId() != null) { + if (type1.getStars() != null) { + if (type2.getStars() == null) return false; + if (type1.getStars().size() != type2.getStars().size()) return false; + } + return (type1.getId().equals(type2.getId())); + } + + // Type specification in the grammar is: + // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); + if (type1.isTime()) { + if (!type2.isTime()) return false; + // Ignore the arraySpec because that is checked when connection + // is checked for balance. + return true; + } + // Type must be given in a code body + return type1.getCode().getBody().equals(type2.getCode().getBody()); } - // Type must be given in a code body - return type1.getCode().getBody().equals(type2.getCode().getBody()); - } - - ////////////////////////////////////////////////////////////// - //// Private fields. - - /** The error reporter. */ - private ValidatorErrorReporter errorReporter = - new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); - - /** Helper class containing information about the model. */ - private ModelInfo info = new ModelInfo(); - - @Inject(optional = true) - private ValidationMessageAcceptor messageAcceptor; - - /** The declared target. */ - private Target target; - - private List targetPropertyErrors = new ArrayList<>(); - - private List targetPropertyWarnings = new ArrayList<>(); - - ////////////////////////////////////////////////////////////// - //// Private static constants. - - private static String ACTIONS_MESSAGE = - "\"actions\" is a reserved word for the TypeScript target for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " - + "and reactor instantiation): "; - - private static String HOST_OR_FQN_REGEX = - "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; - - /** Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). */ - private static String IPV4_REGEX = - "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" - + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; - - /** - * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), with minor - * adjustment to allow up to six IPV6 segments (without truncation) in front of an embedded - * IPv4-address. - */ - private static String IPV6_REGEX = - "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" - + "([0-9a-fA-F]{1,4}:){1,7}:|" - + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" - + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" - + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" - + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" - + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" - + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" - + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" - + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" - + "::(ffff(:0{1,4}){0,1}:){0,1}" - + IPV4_REGEX - + "|" - + "([0-9a-fA-F]{1,4}:){1,4}:" - + IPV4_REGEX - + "|" - + "([0-9a-fA-F]{1,4}:){1,6}" - + IPV4_REGEX - + ")"; - - private static String RESERVED_MESSAGE = - "Reserved words in the target language are not allowed for objects (inputs, outputs, actions," - + " timers, parameters, state, reactor definitions, and reactor instantiation): "; - - private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); - - private static String UNDERSCORE_MESSAGE = - "Names of objects (inputs, outputs, actions, timers, parameters, " - + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; - - private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; + + ////////////////////////////////////////////////////////////// + //// Private fields. + + /** The error reporter. */ + private ValidatorErrorReporter errorReporter + = new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); + + /** Helper class containing information about the model. */ + private ModelInfo info = new ModelInfo(); + + @Inject(optional = true) + private ValidationMessageAcceptor messageAcceptor; + + /** The declared target. */ + private Target target; + + private List targetPropertyErrors = new ArrayList<>(); + + private List targetPropertyWarnings = new ArrayList<>(); + + ////////////////////////////////////////////////////////////// + //// Private static constants. + + private static String ACTIONS_MESSAGE + = "\"actions\" is a reserved word for the TypeScript target for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " + + "and reactor instantiation): "; + + private static String HOST_OR_FQN_REGEX + = "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; + + /** + * Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). + */ + private static String IPV4_REGEX = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; + + /** + * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), + * with minor adjustment to allow up to six IPV6 segments (without truncation) in front + * of an embedded IPv4-address. + **/ + private static String IPV6_REGEX = + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,7}:|" + + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + + "::(ffff(:0{1,4}){0,1}:){0,1}" + IPV4_REGEX + "|" + + "([0-9a-fA-F]{1,4}:){1,4}:" + IPV4_REGEX + "|" + + "([0-9a-fA-F]{1,4}:){1,6}" + IPV4_REGEX + ")"; + + private static String RESERVED_MESSAGE = "Reserved words in the target language are not allowed for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation): "; + + private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); + + private static String UNDERSCORE_MESSAGE = "Names of objects (inputs, outputs, actions, timers, parameters, " + + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; + + private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; + } From bf91bbd134ec26d0dca73962c8caa353821e817e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:23:38 +0200 Subject: [PATCH 228/709] Aligned reactor-c to main --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 8eaf16fdc4..f762f01902 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 8eaf16fdc46df596cf85f7be7e901988cabcd873 +Subproject commit f762f01902745dff40b9170dce273d29b6df5212 From a42a6f079a5b7c1e0a4a4e464f131e6dd17bb84d Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:25:22 +0200 Subject: [PATCH 229/709] Formatted test --- test/C/src/Watchdog.lf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/C/src/Watchdog.lf b/test/C/src/Watchdog.lf index a836c93c3f..3ee48afe9c 100644 --- a/test/C/src/Watchdog.lf +++ b/test/C/src/Watchdog.lf @@ -11,8 +11,9 @@ target C { reactor Watcher(timeout: time = 150 ms) { timer t(100 ms, 100 ms) // Offset ameliorates startup time. - // Period has to be smaller than watchdog timeout. - output d: int // Produced if the watchdog triggers. + // Period has to be smaller than watchdog timeout. Produced if the watchdog + // triggers. + output d: int state count: int = 0 watchdog poodle(timeout) {= From 47e99f78c12fda332aa0a0de918a49e983937119 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 10:31:15 +0200 Subject: [PATCH 230/709] Placeholder for when there are no watchdogs --- org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 695bd5eefa..311fe365fd 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -150,6 +150,7 @@ protected static String generateWatchdogTable(int count) { if (count == 0) { return String.join("\n", "// No watchdogs found.", + "typedef void watchdog_t;", "watchdog_t* _lf_watchdogs = NULL;", "int _lf_watchdog_number = 0;" ); From 2687e42d96fb71d7f5c1d40e6dc4cba26dd652f5 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 1 May 2023 11:03:09 +0200 Subject: [PATCH 231/709] Align reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 97466da394..ffe9a6a2e2 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 97466da394d9572e4ba905b2706759bef73c0af0 +Subproject commit ffe9a6a2e2bf79f45c1019d48f17b1b92eaf01a5 From 61f6d678bc2530ce14d2e7697b51ec04d8b5ab52 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 2 May 2023 11:17:38 +0200 Subject: [PATCH 232/709] CI: do not hardcode compiler version in c benchmark tests --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6dd56ae40..48110ac926 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,6 @@ jobs: uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'C' - benchmarks-ref: main - compiler-ref: master needs: cancel # Run language server tests. From c605eeaf9bca94fb0c6c037f75d81bd8dea5b99f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 2 May 2023 15:18:31 -0700 Subject: [PATCH 233/709] Bugfixes --- .github/workflows/ci.yml | 1 - .../org/lflang/generator/c/CGenerator.java | 12 +-- .../org/lflang/generator/cpp/CppGenerator.kt | 7 +- .../generator/python/PythonGenerator.java | 8 +- .../org/lflang/generator/ts/TSGenerator.kt | 2 +- org.lflang/src/org/lflang/util/FileUtil.java | 94 +++++++------------ 6 files changed, 45 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6dd56ae40..c2e1513fe7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,6 @@ jobs: with: target: 'C' benchmarks-ref: main - compiler-ref: master needs: cancel # Run language server tests. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index fbedb23253..bbd0007961 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -883,7 +883,7 @@ private void generateReactorDefinitions() throws IOException { /** Generate user-visible header files for all reactors instantiated. */ private void generateHeaders() throws IOException { FileUtil.deleteDirectory(fileConfig.getIncludePath()); - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( fileConfig.getRuntimeIncludePath(), fileConfig.getIncludePath(), false @@ -962,12 +962,12 @@ protected void copyTargetFiles() throws IOException { if (coreLib != null) { FileUtil.copyDirectory(Path.of(coreLib), dest, true); } else { - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "/lib/c/reactor-c/core", dest.resolve("core"), true ); - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "/lib/c/reactor-c/lib", dest.resolve("lib"), true @@ -976,18 +976,18 @@ protected void copyTargetFiles() throws IOException { // For the Zephyr target, copy default config and board files. if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "/lib/platform/zephyr/boards", fileConfig.getSrcGenPath().resolve("boards"), false ); - FileUtil.copyFileFromClassPath( + FileUtil.copyFromClassPath( "/lib/platform/zephyr/prj_lf.conf", fileConfig.getSrcGenPath().resolve("prj_lf.conf"), true ); - FileUtil.copyFileFromClassPath( + FileUtil.copyFromClassPath( "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath().resolve("Kconfig"), true diff --git a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt index 5001fe9ac7..805846caec 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt @@ -27,7 +27,6 @@ package org.lflang.generator.cpp import org.eclipse.emf.ecore.resource.Resource -import org.lflang.ErrorReporter import org.lflang.Target import org.lflang.generator.CodeMap import org.lflang.generator.GeneratorBase @@ -127,9 +126,9 @@ class CppGenerator( // copy static library files over to the src-gen directory val genIncludeDir = srcGenPath.resolve("__include__") listOf("lfutil.hh", "time_parser.hh").forEach { - FileUtil.copyFileFromClassPath("$libDir/$it", genIncludeDir.resolve(it), true) + FileUtil.copyFromClassPath("$libDir/$it", genIncludeDir.resolve(it), true) } - FileUtil.copyFileFromClassPath( + FileUtil.copyFromClassPath( "$libDir/3rd-party/cxxopts.hpp", genIncludeDir.resolve("CLI").resolve("cxxopts.hpp"), true @@ -140,7 +139,7 @@ class CppGenerator( if (targetConfig.runtimeVersion != null) { fetchReactorCpp() } else { - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "$libDir/reactor-cpp", fileConfig.srcGenBasePath.resolve("reactor-cpp-default"), true diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 020954be80..361e06e285 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -35,7 +35,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; @@ -56,7 +55,6 @@ import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; -import org.lflang.lf.Code; import org.lflang.lf.Input; import org.lflang.lf.Model; import org.lflang.lf.Output; @@ -661,17 +659,17 @@ private static String generatePythonFileName(String lfModuleName) { @Override protected void copyTargetFiles() throws IOException { super.copyTargetFiles(); - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "/lib/py/reactor-c-py/include", fileConfig.getSrcGenPath().resolve("include"), true ); - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "/lib/py/reactor-c-py/lib", fileConfig.getSrcGenPath().resolve("lib"), true ); - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( "/lib/py/reactor-c-py/LinguaFrancaBase", fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), true diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index bd92a144ce..0514a46a9c 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -235,7 +235,7 @@ class TSGenerator( "No '" + configFile + "' exists in " + fileConfig.srcPath + ". Using default configuration." ) - FileUtil.copyFileFromClassPath("$LIB_PATH/$configFile", configFileDest) + FileUtil.copyFromClassPath("$LIB_PATH/$configFile", configFileDest, true) } } } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index a2cfb81e4d..746835f7cb 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -38,7 +38,6 @@ import org.lflang.ErrorReporter; import org.lflang.FileConfig; -import org.lflang.generator.LFGeneratorContext; public class FileUtil { @@ -262,27 +261,26 @@ public static void copyFiles( var found = FileUtil.findInPackage(path, fileConfig); if (found != null) { try { - FileUtil.copyFileOrDirectory(found, destination.resolve(found.getFileName())); + FileUtil.copyFromFileSystem(found, destination.resolve(path.getFileName())); + System.out.println("Copied '" + fileOrDirectory + "' from the file system."); } catch (IOException e) { errorReporter.reportError( "Unable to copy '" + fileOrDirectory + "' from the file system." ); } } else { - // Attempt to copy from the classpath instead. - // If the filename is not a directory, it will - // just be copied without further recursion. try { - FileUtil.copyDirectoryFromClassPath( + FileUtil.copyFromClassPath( fileOrDirectory, destination, false ); - } catch (IOException e) { + } catch(IOException e) { errorReporter.reportError( "Unable to copy '" + fileOrDirectory + "' from the class path." ); } + System.out.println("Copied '" + fileOrDirectory + "' from the class path."); } } } @@ -294,7 +292,7 @@ public static void copyFiles( * @param destination A directory to copy the file(s) at the source to. * @throws IOException */ - public static void copyFileOrDirectory(Path source, Path destination) throws IOException { + public static void copyFromFileSystem(Path source, Path destination) throws IOException { if (Files.isDirectory(source)) { copyDirectory(source, destination); } else if (Files.isRegularFile(source)) { @@ -315,60 +313,26 @@ public static void copyFileOrDirectory(Path source, Path destination) throws IOE * @throws IOException if copy fails. */ private static void copyInputStream(InputStream source, Path destination, boolean skipIfUnchanged) throws IOException { - Files.createDirectories(destination.getParent()); - // Read the stream once and keep a copy of all bytes. This is required as a stream cannot be read twice. final var bytes = source.readAllBytes(); - // abort if the destination file does not change - if(skipIfUnchanged && Files.isRegularFile(destination)) { - if (Arrays.equals(bytes, Files.readAllBytes(destination))) { - return; + final var parent = destination.getParent(); + if (Files.isRegularFile(destination)) { + if (skipIfUnchanged) { + if (Arrays.equals(bytes, Files.readAllBytes(destination))) { + // Abort if the file contents are the same. + return; + } + } else { + // Delete the file exists but the contents don't match. + Files.delete(destination); } + } else if (!Files.exists(parent)) { + Files.createDirectories(parent); } Files.write(destination, bytes); } - /** - * Lookup a file in the classpath and copy its contents to a destination path - * in the filesystem. - * - * This also creates new directories for any directories on the destination - * path that do not yet exist. - * - * @param source The source file as a path relative to the classpath. - * @param destination The file system path that the source file is copied to. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed - * @throws IOException If the given source cannot be copied. - */ - public static void copyFileFromClassPath(final String source, final Path destination, final boolean skipIfUnchanged) throws IOException { - InputStream sourceStream = FileConfig.class.getResourceAsStream(source); - - // Copy the file. - if (sourceStream == null) { - throw new TargetResourceNotFoundException(source); - } else { - try (sourceStream) { - copyInputStream(sourceStream, destination, skipIfUnchanged); - } - } - } - - /** - * Lookup a file in the classpath and copy its contents to a destination path - * in the filesystem. - * - * This also creates new directories for any directories on the destination - * path that do not yet exist. - * - * @param source The source file as a path relative to the classpath. - * @param destination The file system path that the source file is copied to. - * @throws IOException If the given source cannot be copied. - */ - public static void copyFileFromClassPath(final String source, final Path destination) throws IOException { - copyFileFromClassPath(source, destination, false); - } - /** * Lookup a directory in the classpath and copy its contents to a destination path * in the filesystem. @@ -381,22 +345,27 @@ public static void copyFileFromClassPath(final String source, final Path destina * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed * @throws IOException If the given source cannot be copied. */ - public static void copyDirectoryFromClassPath(final String source, final Path destination, final boolean skipIfUnchanged) throws IOException { + public static void copyFromClassPath(final String source, final Path destination, final boolean skipIfUnchanged) throws IOException { final URL resource = FileConfig.class.getResource(source); + if (resource == null) { throw new TargetResourceNotFoundException(source); } final URLConnection connection = resource.openConnection(); if (connection instanceof JarURLConnection) { - boolean copiedFiles = copyDirectoryFromJar((JarURLConnection) connection, destination, skipIfUnchanged); + boolean copiedFiles = copyFromJar((JarURLConnection) connection, destination, skipIfUnchanged); if (!copiedFiles) { throw new TargetResourceNotFoundException(source); } } else { try { Path dir = Paths.get(FileLocator.toFileURL(resource).toURI()); - copyDirectory(dir, destination, skipIfUnchanged); + if (dir.toFile().isDirectory()) { + copyFile(dir, destination, skipIfUnchanged); + } else { + copyDirectory(dir, destination, skipIfUnchanged); + } } catch(URISyntaxException e) { // This should never happen as toFileURL should always return a valid URL throw new IOException("Unexpected error while resolving " + source + " on the classpath"); @@ -418,7 +387,7 @@ public static void copyDirectoryFromClassPath(final String source, final Path de * @return true if any files were copied * @throws IOException If the given source cannot be copied. */ - private static boolean copyDirectoryFromJar(JarURLConnection connection, final Path destination, final boolean skipIfUnchanged) throws IOException { + private static boolean copyFromJar(JarURLConnection connection, final Path destination, final boolean skipIfUnchanged) throws IOException { final JarFile jar = connection.getJarFile(); final String connectionEntryName = connection.getEntryName(); @@ -431,9 +400,10 @@ private static boolean copyDirectoryFromJar(JarURLConnection connection, final P // Extract files only if they match the given source path. if (entryName.startsWith(connectionEntryName)) { - String filename = entryName.equals(connectionEntryName) ? - connectionEntryName : - entryName.substring(connectionEntryName.length() + 1); + // Gobble up the separator only if there is one. + String filename = entryName.equals(connectionEntryName) ? entryName : + entry.getName().substring(connectionEntryName.length() + 1); + Path currentFile = destination.resolve(filename); if (entry.isDirectory()) { Files.createDirectories(currentFile); @@ -610,7 +580,7 @@ public static Path findInPackage(Path fileOrDirectory, FileConfig fileConfig) { loc -> Files.exists(loc.resolve(relPath)) ).findFirst(); if (found.isPresent()) { - return found.get().resolve(relPath); + return found.get().resolve(relPath).toAbsolutePath(); } } return null; From c8c2bf08dd6209dad3da2cb88c33225879f81d1f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 2 May 2023 23:24:20 -0700 Subject: [PATCH 234/709] More fixes --- org.lflang/src/org/lflang/util/FileUtil.java | 48 ++++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 746835f7cb..2cb66d6c67 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -261,7 +261,7 @@ public static void copyFiles( var found = FileUtil.findInPackage(path, fileConfig); if (found != null) { try { - FileUtil.copyFromFileSystem(found, destination.resolve(path.getFileName())); + FileUtil.copyFromFileSystem(found, destination); System.out.println("Copied '" + fileOrDirectory + "' from the file system."); } catch (IOException e) { errorReporter.reportError( @@ -296,7 +296,7 @@ public static void copyFromFileSystem(Path source, Path destination) throws IOEx if (Files.isDirectory(source)) { copyDirectory(source, destination); } else if (Files.isRegularFile(source)) { - copyFile(source, destination); + copyFile(source, destination.resolve(source.getFileName())); // FIXME: should copyFile have the same API and have a directory as the second argument? } else { throw new IllegalArgumentException("Source is neither a directory nor a regular file."); } @@ -360,11 +360,11 @@ public static void copyFromClassPath(final String source, final Path destination } } else { try { - Path dir = Paths.get(FileLocator.toFileURL(resource).toURI()); - if (dir.toFile().isDirectory()) { - copyFile(dir, destination, skipIfUnchanged); + Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); + if (path.toFile().isDirectory()) { + copyDirectory(path, destination, skipIfUnchanged); } else { - copyDirectory(dir, destination, skipIfUnchanged); + copyFile(path, destination.resolve(path.getFileName()), skipIfUnchanged); } } catch(URISyntaxException e) { // This should never happen as toFileURL should always return a valid URL @@ -373,6 +373,26 @@ public static void copyFromClassPath(final String source, final Path destination } } + /** + * Return true if the given connection points to a file. + * @param connection A connection to a JAR file. + * @throws IOException If the connection is faulty. + */ + private static boolean isFileInJar(JarURLConnection connection) throws IOException { + return connection.getJarFile().stream().filter( + it -> it.getName().equals(connection.getEntryName()) + ).findFirst().isPresent(); + } + + private static void copyFileFromJar(JarFile jar, String source, Path destination, boolean skipIfUnchanged) throws IOException { + var entry = jar.getJarEntry(source); + var filename = Paths.get(entry.getName()).getFileName(); + InputStream is = jar.getInputStream(entry); + try (is) { + copyInputStream(is, destination.resolve(filename), skipIfUnchanged); + } + } + /** * Copy a directory from a jar to a destination path in the filesystem. * @@ -389,7 +409,12 @@ public static void copyFromClassPath(final String source, final Path destination */ private static boolean copyFromJar(JarURLConnection connection, final Path destination, final boolean skipIfUnchanged) throws IOException { final JarFile jar = connection.getJarFile(); - final String connectionEntryName = connection.getEntryName(); + final String source = connection.getEntryName(); + + if (isFileInJar(connection)) { + copyFileFromJar(jar, source, destination, skipIfUnchanged); + return true; + } boolean copiedFiles = false; @@ -397,13 +422,8 @@ private static boolean copyFromJar(JarURLConnection connection, final Path desti for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { final JarEntry entry = e.nextElement(); final String entryName = entry.getName(); - - // Extract files only if they match the given source path. - if (entryName.startsWith(connectionEntryName)) { - // Gobble up the separator only if there is one. - String filename = entryName.equals(connectionEntryName) ? entryName : - entry.getName().substring(connectionEntryName.length() + 1); - + if (entryName.startsWith(source)) { + String filename = entry.getName().substring(source.length() + 1); Path currentFile = destination.resolve(filename); if (entry.isDirectory()) { Files.createDirectories(currentFile); From e28065cf09021920b92dce929e1db733a11567b2 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Wed, 3 May 2023 19:45:28 +0500 Subject: [PATCH 235/709] Update in SubModule & Minor Changes in Pair<> --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/util/Pair.java | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 8523f14b96..1d762fd8b3 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 8523f14b962ae56aad375dde22141a600821fdce +Subproject commit 1d762fd8b367c84cb92e6314591b3bcd650bae8b diff --git a/org.lflang/src/org/lflang/util/Pair.java b/org.lflang/src/org/lflang/util/Pair.java index 9e237104d3..ef2ac123c4 100644 --- a/org.lflang/src/org/lflang/util/Pair.java +++ b/org.lflang/src/org/lflang/util/Pair.java @@ -23,26 +23,26 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * @section DESCRIPTION * * This Class provides a Pair of Templated Types - * This provides the same facility as std::pair in C++ + * This provides the same facility as std::pair in C++ */ package org.lflang.util; -public final class Pair { - private final T first; - private final U second; - public Pair(final T t, final U u) +public final class Pair { + private final T1 first; + private final T2 second; + public Pair(final T1 t1, final T2 t2) { - this.first = t; - this.second = u; + this.first = t1; + this.second = t2; } - public T getFirst() + public T1 getFirst() { return this.first; } - public U getSecond() + public T2 getSecond() { return this.second; } @@ -54,7 +54,7 @@ public boolean equals(Object other) { if (this == other) return true; if (this.getClass().equals(other.getClass())) { - Pair otherPair = (Pair) other; + var otherPair = (Pair) other; boolean isEqual = (first == null) ? otherPair.getFirst() == null : first.equals(otherPair.getFirst()); if (!isEqual) @@ -72,6 +72,6 @@ public int hashCode() { @Override public String toString() { - return "Pair(" + first + ", " + second + ")"; + return "Pair<" + first + ", " + second + ">"; } } From b0de39de9b16a4d6e92b20ee105eea13e484ef65 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 3 May 2023 12:49:27 -0700 Subject: [PATCH 236/709] Clarifications in docs and API --- .../org/lflang/generator/GeneratorBase.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 6 +- .../org/lflang/generator/rust/RustEmitter.kt | 2 +- org.lflang/src/org/lflang/util/FileUtil.java | 77 ++++++++++--------- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 15d703bcbf..992ce5e1a5 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,7 +350,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - FileUtil.copyFiles(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); + FileUtil.copyFilesOrDirectories(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index bbd0007961..8bc7566608 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -830,7 +830,7 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { // Must use class variable to determine destination! var destination = this.fileConfig.getSrcGenPath(); - FileUtil.copyFiles(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); + FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); // FIXME: Unclear what the following does, but it does not appear to belong here. if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { @@ -904,7 +904,7 @@ private void generateHeaders() throws IOException { }, this::generateTopLevelPreambles); } - FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + FileUtil.copyDirectoryContents(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); } /** @@ -960,7 +960,7 @@ protected void copyTargetFiles() throws IOException { Path dest = fileConfig.getSrcGenPath(); if (targetConfig.platformOptions.platform == Platform.ARDUINO) dest = dest.resolve("src"); if (coreLib != null) { - FileUtil.copyDirectory(Path.of(coreLib), dest, true); + FileUtil.copyDirectoryContents(Path.of(coreLib), dest, true); } else { FileUtil.copyFromClassPath( "/lib/c/reactor-c/core", diff --git a/org.lflang/src/org/lflang/generator/rust/RustEmitter.kt b/org.lflang/src/org/lflang/generator/rust/RustEmitter.kt index 7a36bce23e..525acd3dc3 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustEmitter.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustEmitter.kt @@ -73,7 +73,7 @@ object RustEmitter : RustEmitterBase() { for (modPath in gen.crate.modulesToIncludeInMain) { val target = fileConfig.srcGenPath.resolve("src").resolve(modPath.fileName) if (Files.isDirectory(modPath)) { - FileUtil.copyDirectory(modPath, target) + FileUtil.copyDirectoryContents(modPath, target) } else { FileUtil.copyFile(modPath, target) } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 2cb66d6c67..bec2118ecf 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -163,17 +163,16 @@ public static java.net.URI locateFile(String path, Resource resource) { } /** - * Recursively copies the contents of the given 'src' - * directory to 'dest'. Existing files of the destination - * may be overwritten. + * Recursively copy the contents of the given 'srcDir' into the given 'dstDir'. + * Existing files of the destination may be overwritten. * - * @param src The source directory path. - * @param dest The destination directory path. + * @param srcDir The source directory path. + * @param dstDir The destination directory path. * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed * @throws IOException if copy fails. */ - public static void copyDirectory(final Path src, final Path dest, final boolean skipIfUnchanged) throws IOException { - try (Stream stream = Files.walk(src)) { + public static void copyDirectoryContents(final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + try (Stream stream = Files.walk(srcDir)) { stream.forEach(source -> { // Handling checked exceptions in lambda expressions is // hard. See @@ -182,7 +181,7 @@ public static void copyDirectory(final Path src, final Path dest, final boolean // here. if (Files.isRegularFile(source)) { // do not copy directories try { - Path target = dest.resolve(src.relativize(source)); + Path target = dstDir.resolve(srcDir.relativize(source)); Files.createDirectories(target.getParent()); copyFile(source, target, skipIfUnchanged); } catch (IOException e) { @@ -195,68 +194,72 @@ public static void copyDirectory(final Path src, final Path dest, final boolean } } + public static void copyDirectory(final Path srcDir, final Path dstDir) throws IOException { + copyDirectoryContents(srcDir, dstDir.resolve(srcDir.getFileName()), false); + } + /** - * Recursively copies the contents of the given 'src' - * directory to 'dest'. Existing files of the destination - * may be overwritten. + * Recursively copy the contents of the given 'srcDir' + * to 'dstDir'. + * Existing files of the destination may be overwritten. * - * @param src The source directory path. - * @param dest The destination directory path. + * @param srcDir The directory to copy files from. + * @param dstDir The directory to copy files to. * @throws IOException if copy fails. */ - public static void copyDirectory(final Path src, final Path dest) throws IOException { - copyDirectory(src, dest, false); + public static void copyDirectoryContents(final Path srcDir, final Path dstDir) throws IOException { + copyDirectoryContents(srcDir, dstDir, false); } /** - * Copy a given file from 'source' to 'destination'. + * Copy a given file from 'srcFile' to 'dstFile'. * - * This also creates new directories for any directories on the destination - * path that do not yet exist. + * This also creates new directories for any directories + * on the path to `dstFile` that do not yet exist. * - * @param source The source file path. - * @param destination The destination file path. + * @param srcFile The source file path. + * @param dstFile The destination file path. * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed * @throws IOException if copy fails. */ - public static void copyFile(Path source, Path destination, boolean skipIfUnchanged) throws IOException { - BufferedInputStream stream = new BufferedInputStream(new FileInputStream(source.toFile())); + public static void copyFile(Path srcFile, Path dstFile, boolean skipIfUnchanged) throws IOException { + BufferedInputStream stream = new BufferedInputStream(new FileInputStream(srcFile.toFile())); try (stream) { - copyInputStream(stream, destination, skipIfUnchanged); + copyInputStream(stream, dstFile, skipIfUnchanged); } } /** - * Copy a given file from 'source' to 'destination'. + * Copy a 'srcFile' to 'dstFile'. * - * This also creates new directories for any directories on the destination - * path that do not yet exist. + * This also creates new directories for any directories + * on the path to `dstFile` that do not yet exist. * - * @param source The source file path. - * @param destination The destination file path. + * @param srcFile The source file path. + * @param dstFile The destination file path. * @throws IOException if copy fails. */ - public static void copyFile(Path source, Path destination) throws IOException { - copyFile(source, destination, false); + public static void copyFile(Path srcFile, Path dstFile) throws IOException { + copyFile(srcFile, dstFile, false); } /** * Given a list of files or directories, attempt to find them based on the given generator - * context, and copy then to the destination. Files are searched for in the file system first. - * Files that cannot be found in the file system are looked for on the class path. + * context, and copy them to the destination. Entries are searched for in the file system first. + * Entries that cannot be found in the file system are looked for on the class path. * - * @param filesOrDirectories The files or directories to copy. + * @param entries The files or directories to copy. * @param destination The location to copy them to. * @param fileConfig The file configuration that specifies where the files must be found. * @param errorReporter An error reporter to report problems. */ - public static void copyFiles( - List filesOrDirectories, + public static void copyFilesOrDirectories( + List entries, Path destination, FileConfig fileConfig, ErrorReporter errorReporter ) { - for (String fileOrDirectory : filesOrDirectories) { + for (String fileOrDirectory : entries) { var path = Paths.get(fileOrDirectory); var found = FileUtil.findInPackage(path, fileConfig); if (found != null) { @@ -362,7 +365,7 @@ public static void copyFromClassPath(final String source, final Path destination try { Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); if (path.toFile().isDirectory()) { - copyDirectory(path, destination, skipIfUnchanged); + copyDirectoryContents(path, destination, skipIfUnchanged); } else { copyFile(path, destination.resolve(path.getFileName()), skipIfUnchanged); } From 931ed6c003b9dd2d9b5b7a835997f215207e0284 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 3 May 2023 13:26:15 -0700 Subject: [PATCH 237/709] Fix and simplify TS file dealings --- .../org/lflang/generator/ts/TSGenerator.kt | 29 ++++--------------- org.lflang/src/org/lflang/util/FileUtil.java | 24 +++++++-------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 0514a46a9c..7e11b6597a 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -38,7 +38,6 @@ import org.lflang.scoping.LFGlobalScopeProvider import org.lflang.util.FileUtil import java.nio.file.Files import java.nio.file.Path -import java.nio.file.StandardCopyOption import java.util.* private const val NO_NPM_MESSAGE = "The TypeScript target requires npm >= 6.14.4. " + @@ -61,19 +60,13 @@ class TSGenerator( val fileConfig: TSFileConfig = context.fileConfig as TSFileConfig - var devMode = false; + private var devMode = false companion object { /** Path to the TS lib directory (relative to class path) */ const val LIB_PATH = "/lib/ts" - /** - * Names of the configuration files to check for and copy to the generated - * source package root if they cannot be found in the source directory. - */ - val CONFIG_FILES = arrayOf("package.json", "tsconfig.json", ".eslintrc.json") - const val RUNTIME_URL = "git://github.com/lf-lang/reactor-ts.git" fun timeInTargetLanguage(value: TimeValue): String { @@ -223,21 +216,11 @@ class TSGenerator( * as the source file, copy a default version from $LIB_PATH/. */ private fun copyConfigFiles() { - for (configFile in CONFIG_FILES) { - val configFileDest = fileConfig.srcGenPath.resolve(configFile) - val configFileInSrc = fileConfig.srcPath.resolve(configFile) - if (configFileInSrc.toFile().exists()) { - println("Copying $configFileInSrc to $configFileDest") - Files.createDirectories(configFileDest.parent) - Files.copy(configFileInSrc, configFileDest, StandardCopyOption.REPLACE_EXISTING) - } else { - println( - "No '" + configFile + "' exists in " + fileConfig.srcPath + - ". Using default configuration." - ) - FileUtil.copyFromClassPath("$LIB_PATH/$configFile", configFileDest, true) - } - } + FileUtil.copyFromClassPath( + LIB_PATH, + fileConfig.srcGenPath, + true + ) } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index bec2118ecf..aff553c28e 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -337,41 +337,41 @@ private static void copyInputStream(InputStream source, Path destination, boolea } /** - * Lookup a directory in the classpath and copy its contents to a destination path - * in the filesystem. + * Look up the given entry in the classpath. If it is a file, copy it into the destination + * directory. If it is a directory, copy its contents to the destination directory. * * This also creates new directories for any directories on the destination * path that do not yet exist. * - * @param source The source directory as a path relative to the classpath. - * @param destination The file system path that the source directory is copied to. + * @param entry The entry to be found on the class path and copied to the given destination. + * @param dstDir The file system path that found files are to be copied to. * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed * @throws IOException If the given source cannot be copied. */ - public static void copyFromClassPath(final String source, final Path destination, final boolean skipIfUnchanged) throws IOException { - final URL resource = FileConfig.class.getResource(source); + public static void copyFromClassPath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + final URL resource = FileConfig.class.getResource(entry); if (resource == null) { - throw new TargetResourceNotFoundException(source); + throw new TargetResourceNotFoundException(entry); } final URLConnection connection = resource.openConnection(); if (connection instanceof JarURLConnection) { - boolean copiedFiles = copyFromJar((JarURLConnection) connection, destination, skipIfUnchanged); + boolean copiedFiles = copyFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged); if (!copiedFiles) { - throw new TargetResourceNotFoundException(source); + throw new TargetResourceNotFoundException(entry); } } else { try { Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); if (path.toFile().isDirectory()) { - copyDirectoryContents(path, destination, skipIfUnchanged); + copyDirectoryContents(path, dstDir, skipIfUnchanged); } else { - copyFile(path, destination.resolve(path.getFileName()), skipIfUnchanged); + copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); } } catch(URISyntaxException e) { // This should never happen as toFileURL should always return a valid URL - throw new IOException("Unexpected error while resolving " + source + " on the classpath"); + throw new IOException("Unexpected error while resolving " + entry + " on the classpath"); } } } From d2e09ae8ea8203bf1462965f2702a9e2969b1990 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 3 May 2023 13:28:06 -0700 Subject: [PATCH 238/709] Remove FIXME associated with closed issue --- org.lflang/src/org/lflang/generator/ts/TSGenerator.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 7e11b6597a..7776c21d76 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -181,8 +181,6 @@ class TSGenerator( val manifest = fileConfig.srcGenPath.resolve("package.json"); val rtRegex = Regex("(\"@lf-lang/reactor-ts\")(.+)") if (rtPath != null) rtPath = formatRuntimePath(rtPath) - // FIXME: do better CLI arg validation upstream - // https://github.com/lf-lang/lingua-franca/issues/1429 if (rtPath != null || rtVersion != null) { devMode = true; } From 02311338f630d0eb839119a387e120375091b27e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 3 May 2023 16:04:12 -0700 Subject: [PATCH 239/709] Get the Cpp tests to compile again --- .../org/lflang/generator/GeneratorBase.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 2 +- .../org/lflang/generator/cpp/CppGenerator.kt | 4 ++-- org.lflang/src/org/lflang/util/FileUtil.java | 23 ++++++++++++++----- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 992ce5e1a5..01a86b6d96 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,7 +350,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - FileUtil.copyFilesOrDirectories(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); + FileUtil.copyFilesOrDirectoryContents(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 8bc7566608..79349efe6d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -830,7 +830,7 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { // Must use class variable to determine destination! var destination = this.fileConfig.getSrcGenPath(); - FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); + FileUtil.copyFilesOrDirectoryContents(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); // FIXME: Unclear what the following does, but it does not appear to belong here. if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { diff --git a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt index 805846caec..de600900bb 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt @@ -126,11 +126,11 @@ class CppGenerator( // copy static library files over to the src-gen directory val genIncludeDir = srcGenPath.resolve("__include__") listOf("lfutil.hh", "time_parser.hh").forEach { - FileUtil.copyFromClassPath("$libDir/$it", genIncludeDir.resolve(it), true) + FileUtil.copyFromClassPath("$libDir/$it", genIncludeDir, true) } FileUtil.copyFromClassPath( "$libDir/3rd-party/cxxopts.hpp", - genIncludeDir.resolve("CLI").resolve("cxxopts.hpp"), + genIncludeDir.resolve("CLI"), true ) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index aff553c28e..ed945a5a37 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -253,7 +253,7 @@ public static void copyFile(Path srcFile, Path dstFile) throws IOException { * @param fileConfig The file configuration that specifies where the files must be found. * @param errorReporter An error reporter to report problems. */ - public static void copyFilesOrDirectories( + public static void copyFilesOrDirectoryContents( List entries, Path destination, FileConfig fileConfig, @@ -297,9 +297,9 @@ public static void copyFilesOrDirectories( */ public static void copyFromFileSystem(Path source, Path destination) throws IOException { if (Files.isDirectory(source)) { - copyDirectory(source, destination); + copyDirectoryContents(source, destination); } else if (Files.isRegularFile(source)) { - copyFile(source, destination.resolve(source.getFileName())); // FIXME: should copyFile have the same API and have a directory as the second argument? + copyFile(source, destination.resolve(source.getFileName())); } else { throw new IllegalArgumentException("Source is neither a directory nor a regular file."); } @@ -329,6 +329,8 @@ private static void copyInputStream(InputStream source, Path destination, boolea // Delete the file exists but the contents don't match. Files.delete(destination); } + } else if (Files.isDirectory(destination)) { + deleteDirectory(destination); } else if (!Files.exists(parent)) { Files.createDirectories(parent); } @@ -387,12 +389,12 @@ private static boolean isFileInJar(JarURLConnection connection) throws IOExcepti ).findFirst().isPresent(); } - private static void copyFileFromJar(JarFile jar, String source, Path destination, boolean skipIfUnchanged) throws IOException { - var entry = jar.getJarEntry(source); + private static void copyFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { + var entry = jar.getJarEntry(srcFile); var filename = Paths.get(entry.getName()).getFileName(); InputStream is = jar.getInputStream(entry); try (is) { - copyInputStream(is, destination.resolve(filename), skipIfUnchanged); + copyInputStream(is, dstDir.resolve(filename), skipIfUnchanged); } } @@ -553,6 +555,15 @@ public static void relativeIncludeHelper(Path dir, Path includePath) throws IOEx } } + public static void delete(Path fileOrDirectory) throws IOException { + if (Files.isRegularFile(fileOrDirectory)) { + Files.deleteIfExists(fileOrDirectory); + } + if (Files.isDirectory(fileOrDirectory)) { + deleteDirectory(fileOrDirectory); + } + } + /** * Recursively delete a directory if it exists. * From c77388e9d5a88e8acd5b16c279d7b81a5e505a5d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 3 May 2023 16:22:54 -0700 Subject: [PATCH 240/709] Fix Zephyr tests --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 79349efe6d..962ba6cfda 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -983,13 +983,13 @@ protected void copyTargetFiles() throws IOException { ); FileUtil.copyFromClassPath( "/lib/platform/zephyr/prj_lf.conf", - fileConfig.getSrcGenPath().resolve("prj_lf.conf"), + fileConfig.getSrcGenPath(), true ); FileUtil.copyFromClassPath( "/lib/platform/zephyr/Kconfig", - fileConfig.getSrcGenPath().resolve("Kconfig"), + fileConfig.getSrcGenPath(), true ); } From feb0d86001038e7e8df4a9abf628ebe940a24b9d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 4 May 2023 13:22:39 +0200 Subject: [PATCH 241/709] produce an error if 'extends' is used in a target that does not support it --- org.lflang/src/org/lflang/Target.java | 10 ++++++++++ org.lflang/src/org/lflang/validation/LFValidator.java | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/src/org/lflang/Target.java index 11247b6648..6a5c87c6f6 100644 --- a/org.lflang/src/org/lflang/Target.java +++ b/org.lflang/src/org/lflang/Target.java @@ -462,6 +462,16 @@ public boolean isReservedIdent(String ident) { return this.keywords.contains(ident); } + /** + * Return true if the target supports reactor inheritance (extends keyword). + */ + public boolean supportsInheritance() { + return switch (this) { + case C, CCPP, Python -> true; + default -> false; + }; + } + /** * Return true if the target supports multiports and banks * of reactors. diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 7f1aa5c808..77922c472e 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -971,6 +971,11 @@ public void checkReactor(Reactor reactor) throws IOException { if (reactor.isFederated()) { FedValidator.validateFederatedReactor(reactor, this.errorReporter); } + + if (!reactor.getSuperClasses().isEmpty() && !target.supportsInheritance()) { + error("The " + target.name() + " target does not support reactor inheritance.", + Literals.REACTOR__SUPER_CLASSES); + } } /** From ae20b1c1fd9fe2070892cf9202df0a3db5f69fed Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 4 May 2023 13:29:45 +0200 Subject: [PATCH 242/709] produce an error if 'federated' is used in a target that does not support it --- org.lflang/src/org/lflang/Target.java | 10 ++++++++++ org.lflang/src/org/lflang/validation/LFValidator.java | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/src/org/lflang/Target.java index 6a5c87c6f6..70dbe9d661 100644 --- a/org.lflang/src/org/lflang/Target.java +++ b/org.lflang/src/org/lflang/Target.java @@ -462,6 +462,16 @@ public boolean isReservedIdent(String ident) { return this.keywords.contains(ident); } + /** + * Return true if the target supports federated execution. + */ + public boolean supportsFederated() { + return switch (this) { + case C, CCPP, Python, TS -> true; + default -> false; + }; + } + /** * Return true if the target supports reactor inheritance (extends keyword). */ diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 77922c472e..db219e516f 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -969,11 +969,16 @@ public void checkReactor(Reactor reactor) throws IOException { } if (reactor.isFederated()) { + if(!target.supportsFederated()) { + error("The " + target.getDisplayName() + " target does not support federated execution.", + Literals.REACTOR__FEDERATED); + } + FedValidator.validateFederatedReactor(reactor, this.errorReporter); } if (!reactor.getSuperClasses().isEmpty() && !target.supportsInheritance()) { - error("The " + target.name() + " target does not support reactor inheritance.", + error("The " + target.getDisplayName() + " target does not support reactor inheritance.", Literals.REACTOR__SUPER_CLASSES); } } From f7c55f3bc94f4451d9735d12658012906b4b99a3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 4 May 2023 14:29:28 +0200 Subject: [PATCH 243/709] add validation tests --- .../compiler/LinguaFrancaValidationTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 847a364193..e3ca78aaf2 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -812,6 +812,41 @@ public void testPreambleVisibility() throws Exception { } } + @Test + public void testInheritanceSupport() throws Exception { + for (Target target : Target.values()) { + Model model = parseWithoutError(""" + target %s + reactor A{} + reactor B extends A{} + """.formatted(target)); + + if(target.supportsInheritance()) { + validator.assertNoIssues(model); + } else { + validator.assertError(model, LfPackage.eINSTANCE.getReactor(), null, + "The " + target.getDisplayName() + " target does not support reactor inheritance."); + } + } + } + + @Test + public void testFederationSupport() throws Exception { + for (Target target : Target.values()) { + Model model = parseWithoutError(""" + target %s + federated reactor {} + """.formatted(target)); + + if(target.supportsFederated()) { + validator.assertNoIssues(model); + } else { + validator.assertError(model, LfPackage.eINSTANCE.getReactor(), null, + "The " + target.getDisplayName() + " target does not support federated execution."); + } + } + } + /** * Tests for state and parameter declarations, including native lists. From 6cb545448a827d098140acbec381f2a184351606 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 4 May 2023 14:30:08 +0200 Subject: [PATCH 244/709] fix exception during reactor validation --- .../org/lflang/validation/LFValidator.java | 86 +++++++++++-------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index db219e516f..74a54f7435 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -852,29 +852,22 @@ public void checkReaction(Reaction reaction) { // FIXME: improve error message. } - @Check(CheckType.FAST) - public void checkReactor(Reactor reactor) throws IOException { - Set superClasses = ASTUtils.superClasses(reactor); - if (superClasses == null) { - error( - "Problem with superclasses: Either they form a cycle or are not defined", - Literals.REACTOR_DECL__NAME - ); - // Continue checks, but without any superclasses. - superClasses = new LinkedHashSet<>(); - } + public void checkReactorName(Reactor reactor) throws IOException { String name = FileUtil.nameWithoutExtension(reactor.eResource()); - if (reactor.getName() == null) { - if (!reactor.isFederated() && !reactor.isMain()) { + + // Check for illegal names. + if(reactor.getName() != null) { + checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); + + // C++ reactors may not be called 'preamble' + if (this.target == Target.CPP && name.equalsIgnoreCase("preamble")) { error( - "Reactor must be named.", + "Reactor cannot be named '" + name + "'", Literals.REACTOR_DECL__NAME ); - // Prevent NPE in tests below. - return; } } - TreeIterator iter = reactor.eResource().getAllContents(); + if (reactor.isFederated() || reactor.isMain()) { if(reactor.getName() != null && !reactor.getName().equals(name)) { // Make sure that if the name is given, it matches the expected name. @@ -883,38 +876,55 @@ public void checkReactor(Reactor reactor) throws IOException { Literals.REACTOR_DECL__NAME ); } + } else { + // Not federated or main. + if (reactor.getName() == null) { + error( + "Reactor must be named.", + Literals.REACTOR_DECL__NAME + ); + } else { + TreeIterator iter = reactor.eResource().getAllContents(); + int nMain = countMainOrFederated(iter); + if (nMain > 0 && reactor.getName().equals(name)) { + error( + "Name conflict with main reactor.", + Literals.REACTOR_DECL__NAME + ); + } + } + } + } + + @Check(CheckType.FAST) + public void checkReactor(Reactor reactor) throws IOException { + checkReactorName(reactor); + + if (reactor.isFederated() || reactor.isMain()) { // Do not allow multiple main/federated reactors. + TreeIterator iter = reactor.eResource().getAllContents(); int nMain = countMainOrFederated(iter); if (nMain > 1) { EAttribute attribute = Literals.REACTOR__MAIN; if (reactor.isFederated()) { - attribute = Literals.REACTOR__FEDERATED; + attribute = Literals.REACTOR__FEDERATED; } error( "Multiple definitions of main or federated reactor.", attribute ); } - } else { - // Not federated or main. - int nMain = countMainOrFederated(iter); - if (nMain > 0 && reactor.getName().equals(name)) { - error( - "Name conflict with main reactor.", - Literals.REACTOR_DECL__NAME - ); - } } - // Check for illegal names. - checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); - // C++ reactors may not be called 'preamble' - if (this.target == Target.CPP && reactor.getName().equalsIgnoreCase("preamble")) { + Set superClasses = ASTUtils.superClasses(reactor); + if (superClasses == null) { error( - "Reactor cannot be named '" + reactor.getName() + "'", - Literals.REACTOR_DECL__NAME + "Problem with superclasses: Either they form a cycle or are not defined", + Literals.REACTOR_DECL__NAME ); + // Continue checks, but without any superclasses. + superClasses = new LinkedHashSet<>(); } if (reactor.getHost() != null) { @@ -933,6 +943,11 @@ public void checkReactor(Reactor reactor) throws IOException { variables.addAll(reactor.getActions()); variables.addAll(reactor.getTimers()); + if (!reactor.getSuperClasses().isEmpty() && !target.supportsInheritance()) { + error("The " + target.getDisplayName() + " target does not support reactor inheritance.", + Literals.REACTOR__SUPER_CLASSES); + } + // Perform checks on super classes. for (Reactor superClass : superClasses) { HashSet conflicts = new HashSet<>(); @@ -976,11 +991,6 @@ public void checkReactor(Reactor reactor) throws IOException { FedValidator.validateFederatedReactor(reactor, this.errorReporter); } - - if (!reactor.getSuperClasses().isEmpty() && !target.supportsInheritance()) { - error("The " + target.getDisplayName() + " target does not support reactor inheritance.", - Literals.REACTOR__SUPER_CLASSES); - } } /** From 71ed7af63749a03d06b5247161fe80c9fe61f00f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 13:40:26 -0700 Subject: [PATCH 245/709] Ready for CI run. Docs and cleanup will follow --- .../org/lflang/generator/GeneratorBase.java | 7 +- .../org/lflang/generator/c/CGenerator.java | 23 ++- .../org/lflang/generator/cpp/CppGenerator.kt | 8 +- .../generator/python/PythonGenerator.java | 15 +- .../org/lflang/generator/ts/TSGenerator.kt | 1 + org.lflang/src/org/lflang/util/FileUtil.java | 155 +++++++++++++----- 6 files changed, 149 insertions(+), 60 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 01a86b6d96..407b1c501a 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,7 +350,12 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - FileUtil.copyFilesOrDirectoryContents(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter); + FileUtil.copyFilesOrDirectories( + targetConfig.files, + this.context.getFileConfig().getSrcGenPath(), + fileConfig, + errorReporter, + false); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 962ba6cfda..6ec5e80226 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -830,7 +830,8 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { // Must use class variable to determine destination! var destination = this.fileConfig.getSrcGenPath(); - FileUtil.copyFilesOrDirectoryContents(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter); + // NOTE: All entries should be files, but we are not checking this. + FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true); // FIXME: Unclear what the following does, but it does not appear to belong here. if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { @@ -886,7 +887,8 @@ private void generateHeaders() throws IOException { FileUtil.copyFromClassPath( fileConfig.getRuntimeIncludePath(), fileConfig.getIncludePath(), - false + false, + true ); for (Reactor r : reactors) { CReactorHeaderFileGenerator.doGenerate( @@ -964,13 +966,15 @@ protected void copyTargetFiles() throws IOException { } else { FileUtil.copyFromClassPath( "/lib/c/reactor-c/core", - dest.resolve("core"), - true + dest, + true, + false ); FileUtil.copyFromClassPath( "/lib/c/reactor-c/lib", - dest.resolve("lib"), - true + dest, + true, + false ); } @@ -978,16 +982,17 @@ protected void copyTargetFiles() throws IOException { if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { FileUtil.copyFromClassPath( "/lib/platform/zephyr/boards", - fileConfig.getSrcGenPath().resolve("boards"), + fileConfig.getSrcGenPath(), + false, false ); - FileUtil.copyFromClassPath( + FileUtil.copySingleFileFromClasspath( "/lib/platform/zephyr/prj_lf.conf", fileConfig.getSrcGenPath(), true ); - FileUtil.copyFromClassPath( + FileUtil.copySingleFileFromClasspath( "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath(), true diff --git a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt index de600900bb..60b450d2c2 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt @@ -126,13 +126,12 @@ class CppGenerator( // copy static library files over to the src-gen directory val genIncludeDir = srcGenPath.resolve("__include__") listOf("lfutil.hh", "time_parser.hh").forEach { - FileUtil.copyFromClassPath("$libDir/$it", genIncludeDir, true) + FileUtil.copySingleFileFromClasspath("$libDir/$it", genIncludeDir, true) } - FileUtil.copyFromClassPath( + FileUtil.copySingleFileFromClasspath( "$libDir/3rd-party/cxxopts.hpp", genIncludeDir.resolve("CLI"), - true - ) + true) // copy or download reactor-cpp if (targetConfig.externalRuntimePath == null) { @@ -142,6 +141,7 @@ class CppGenerator( FileUtil.copyFromClassPath( "$libDir/reactor-cpp", fileConfig.srcGenBasePath.resolve("reactor-cpp-default"), + true, true ) } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 361e06e285..2686c98539 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -661,18 +661,21 @@ protected void copyTargetFiles() throws IOException { super.copyTargetFiles(); FileUtil.copyFromClassPath( "/lib/py/reactor-c-py/include", - fileConfig.getSrcGenPath().resolve("include"), - true + fileConfig.getSrcGenPath(), + true, + false ); FileUtil.copyFromClassPath( "/lib/py/reactor-c-py/lib", - fileConfig.getSrcGenPath().resolve("lib"), - true + fileConfig.getSrcGenPath(), + true, + false ); FileUtil.copyFromClassPath( "/lib/py/reactor-c-py/LinguaFrancaBase", - fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"), - true + fileConfig.getSrcGenPath(), + true, + false ); } diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 7776c21d76..49dd3444e1 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -217,6 +217,7 @@ class TSGenerator( FileUtil.copyFromClassPath( LIB_PATH, fileConfig.srcGenPath, + true, true ) } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index ed945a5a37..bbd4a5439f 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -194,8 +194,8 @@ public static void copyDirectoryContents(final Path srcDir, final Path dstDir, f } } - public static void copyDirectory(final Path srcDir, final Path dstDir) throws IOException { - copyDirectoryContents(srcDir, dstDir.resolve(srcDir.getFileName()), false); + public static void copyDirectory(final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + copyDirectoryContents(srcDir, dstDir.resolve(srcDir.getFileName()), skipIfUnchanged); } /** @@ -243,28 +243,30 @@ public static void copyFile(Path srcFile, Path dstFile) throws IOException { copyFile(srcFile, dstFile, false); } + /** - * Given a list of files or directories, attempt to find them based on the given generator + * Given a list of files or directories, attempt to find them using the given generator * context, and copy them to the destination. Entries are searched for in the file system first. * Entries that cannot be found in the file system are looked for on the class path. * - * @param entries The files or directories to copy. - * @param destination The location to copy them to. + * @param entries The files or directory contents to copy. + * @param dstDir The location to copy the files to. * @param fileConfig The file configuration that specifies where the files must be found. * @param errorReporter An error reporter to report problems. */ - public static void copyFilesOrDirectoryContents( + public static void copyFilesOrDirectories( List entries, - Path destination, + Path dstDir, FileConfig fileConfig, - ErrorReporter errorReporter + ErrorReporter errorReporter, + boolean contentsOnly ) { for (String fileOrDirectory : entries) { var path = Paths.get(fileOrDirectory); var found = FileUtil.findInPackage(path, fileConfig); if (found != null) { try { - FileUtil.copyFromFileSystem(found, destination); + FileUtil.copyFromFileSystem(found, dstDir, contentsOnly); System.out.println("Copied '" + fileOrDirectory + "' from the file system."); } catch (IOException e) { errorReporter.reportError( @@ -275,8 +277,9 @@ public static void copyFilesOrDirectoryContents( try { FileUtil.copyFromClassPath( fileOrDirectory, - destination, - false + dstDir, + false, + contentsOnly ); } catch(IOException e) { errorReporter.reportError( @@ -295,11 +298,15 @@ public static void copyFilesOrDirectoryContents( * @param destination A directory to copy the file(s) at the source to. * @throws IOException */ - public static void copyFromFileSystem(Path source, Path destination) throws IOException { + public static void copyFromFileSystem(Path source, Path destination, boolean contentsOnly) throws IOException { if (Files.isDirectory(source)) { - copyDirectoryContents(source, destination); + if (contentsOnly) { + copyDirectoryContents(source, destination); + } else { + copyDirectory(source, destination, false); + } } else if (Files.isRegularFile(source)) { - copyFile(source, destination.resolve(source.getFileName())); + FileUtil.copyFile(source, destination.resolve(source.getFileName())); } else { throw new IllegalArgumentException("Source is neither a directory nor a regular file."); } @@ -338,19 +345,46 @@ private static void copyInputStream(InputStream source, Path destination, boolea Files.write(destination, bytes); } + public static void copySingleFileFromClasspath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + final URL resource = FileConfig.class.getResource(entry); + + if (resource == null) { + throw new TargetResourceNotFoundException(entry); + } + + final URLConnection connection = resource.openConnection(); + if (connection instanceof JarURLConnection) { + copySingleFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged); + } else { + try { + Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); + copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); + } catch(URISyntaxException e) { + // This should never happen as toFileURL should always return a valid URL + throw new IOException("Unexpected error while resolving " + entry + " on the classpath"); + } + } + } + /** - * Look up the given entry in the classpath. If it is a file, copy it into the destination - * directory. If it is a directory, copy its contents to the destination directory. + * Look up the given entry in the classpath. If it is a file, copy it into the destination + * directory. If it is a directory, copy its contents to the destination directory. * - * This also creates new directories for any directories on the destination - * path that do not yet exist. + * This also creates new directories for any directories on the destination + * path that do not yet exist. * - * @param entry The entry to be found on the class path and copied to the given destination. - * @param dstDir The file system path that found files are to be copied to. - * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed - * @throws IOException If the given source cannot be copied. + * @param entry The entry to be found on the class path and copied to the given destination. + * @param dstDir The file system path that found files are to be copied to. + * @param skipIfUnchanged If true, don't overwrite the file or directory if its content would not be changed + * @param contentsOnly If true and the entry is a directory, then copy its contents but not the directory itself. + * @throws IOException If the given source cannot be copied. */ - public static void copyFromClassPath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + public static void copyFromClassPath( + final String entry, + final Path dstDir, + final boolean skipIfUnchanged, + final boolean contentsOnly + ) throws IOException { final URL resource = FileConfig.class.getResource(entry); if (resource == null) { @@ -359,7 +393,7 @@ public static void copyFromClassPath(final String entry, final Path dstDir, fina final URLConnection connection = resource.openConnection(); if (connection instanceof JarURLConnection) { - boolean copiedFiles = copyFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged); + boolean copiedFiles = copyFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged, contentsOnly); if (!copiedFiles) { throw new TargetResourceNotFoundException(entry); } @@ -367,7 +401,12 @@ public static void copyFromClassPath(final String entry, final Path dstDir, fina try { Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); if (path.toFile().isDirectory()) { - copyDirectoryContents(path, dstDir, skipIfUnchanged); + if (contentsOnly) { + copyDirectoryContents(path, dstDir, skipIfUnchanged); + } else { + copyDirectory(path, dstDir, skipIfUnchanged); + } + } else { copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); } @@ -389,7 +428,7 @@ private static boolean isFileInJar(JarURLConnection connection) throws IOExcepti ).findFirst().isPresent(); } - private static void copyFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { + private static void copySingleFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { var entry = jar.getJarEntry(srcFile); var filename = Paths.get(entry.getName()).getFileName(); InputStream is = jar.getInputStream(entry); @@ -399,37 +438,57 @@ private static void copyFileFromJar(JarFile jar, String srcFile, Path dstDir, bo } /** - * Copy a directory from a jar to a destination path in the filesystem. + * Copy the contents from an entry in a JAR to destination directory in the filesystem. The entry + * may be a file, in which case it will be copied under the same name into the destination + * directory. If the entry is a directory, then if the 'contentsOnly' flag is set, only the + * contents of the directory will be copied into the destination directory (not the directory + * itself). A directory will be copied as a whole, including its contents, if 'contentsOnly' is + * set to false. * * This method should only be used in standalone mode (lfc). * - * This also creates new directories for any directories on the destination - * path that do not yet exist + * This also creates new directories for any directories on + * the destination path that do not yet exist. * - * @param connection a URLConnection to the source directory within the jar - * @param destination The file system path that the source directory is copied to. - * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed + * @param connection a URLConnection to the source entry within the jar + * @param dstDir The file system path that entries are copied to. + * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed. + * @param contentsOnly If true, and the connection points to a directory, copy its contents only + * (not the directory itself). * @return true if any files were copied * @throws IOException If the given source cannot be copied. */ - private static boolean copyFromJar(JarURLConnection connection, final Path destination, final boolean skipIfUnchanged) throws IOException { - final JarFile jar = connection.getJarFile(); - final String source = connection.getEntryName(); - - if (isFileInJar(connection)) { - copyFileFromJar(jar, source, destination, skipIfUnchanged); + private static boolean copyFromJar( + JarURLConnection connection, + Path dstDir, + final boolean skipIfUnchanged, + final boolean contentsOnly + ) throws IOException { + + if (copySingleFileFromJar(connection, dstDir, skipIfUnchanged)) { return true; } + return copyMultipleFilesFromJar(connection, dstDir, skipIfUnchanged, contentsOnly); + } - boolean copiedFiles = false; + private static boolean copyMultipleFilesFromJar(JarURLConnection connection, + Path dstDir, + final boolean skipIfUnchanged, + final boolean contentsOnly) throws IOException { + final JarFile jar = connection.getJarFile(); + final String source = connection.getEntryName(); + boolean copiedFiles = false; + if (!contentsOnly) { + dstDir = dstDir.resolve(Paths.get(source).getFileName()); + } // Iterate all entries in the jar file. for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { final JarEntry entry = e.nextElement(); final String entryName = entry.getName(); if (entryName.startsWith(source)) { String filename = entry.getName().substring(source.length() + 1); - Path currentFile = destination.resolve(filename); + Path currentFile = dstDir.resolve(filename); if (entry.isDirectory()) { Files.createDirectories(currentFile); } else { @@ -444,6 +503,22 @@ private static boolean copyFromJar(JarURLConnection connection, final Path desti return copiedFiles; } + private static boolean copySingleFileFromJar( + JarURLConnection connection, + Path dstDir, + final boolean skipIfUnchanged + ) throws IOException { + final JarFile jar = connection.getJarFile(); + final String source = connection.getEntryName(); + + if (!isFileInJar(connection)) { + return false; + } + copySingleFileFromJar(jar, source, dstDir, skipIfUnchanged); + + return true; + } + /** * Delete unused Files from Arduino-CLI based compilation. * From 5f2c187bccffe6c282d9ecda865d8d473f176063 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 18:05:14 -0700 Subject: [PATCH 246/709] Again, mostly comments --- .../org/lflang/generator/GeneratorBase.java | 8 +- .../org/lflang/generator/c/CGenerator.java | 2 +- org.lflang/src/org/lflang/util/FileUtil.java | 161 +++++++++++++----- 3 files changed, 124 insertions(+), 47 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 407b1c501a..461f571333 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -350,12 +350,8 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - FileUtil.copyFilesOrDirectories( - targetConfig.files, - this.context.getFileConfig().getSrcGenPath(), - fileConfig, - errorReporter, - false); + var dst = this.context.getFileConfig().getSrcGenPath(); + FileUtil.copyFilesOrDirectories(targetConfig.files, dst, fileConfig, errorReporter, false); } /** diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 6ec5e80226..cdf6e4d2f6 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -906,7 +906,7 @@ private void generateHeaders() throws IOException { }, this::generateTopLevelPreambles); } - FileUtil.copyDirectoryContents(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath(), false); } /** diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index bbd4a5439f..a876e90940 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -163,13 +163,14 @@ public static java.net.URI locateFile(String path, Resource resource) { } /** - * Recursively copy the contents of the given 'srcDir' into the given 'dstDir'. - * Existing files of the destination may be overwritten. + * Recursively copy the contents of the given source directory into the given destination + * directory. Existing files of the destination may be overwritten. * * @param srcDir The source directory path. * @param dstDir The destination directory path. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed - * @throws IOException if copy fails. + * @param skipIfUnchanged If true, don't overwrite anything in the destination if its content + * would not be changed. + * @throws IOException If the operation fails. */ public static void copyDirectoryContents(final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { try (Stream stream = Files.walk(srcDir)) { @@ -194,14 +195,24 @@ public static void copyDirectoryContents(final Path srcDir, final Path dstDir, f } } - public static void copyDirectory(final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + /** + * Copy the given source directory into the given destination directory. For example, if the + * source directory is {@code foo/bar} and the destination is {@code baz}, then copies of the + * contents of {@code foo/bar} will be located in {@code baz/bar}. + * @param srcDir The source directory path. + * @param dstDir The destination directory path. + * @param skipIfUnchanged If true, don't overwrite anything in the destination if its content + * would not be changed. + * @throws IOException If the operation fails. + */ + public static void copyDirectory( + final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { copyDirectoryContents(srcDir, dstDir.resolve(srcDir.getFileName()), skipIfUnchanged); } /** - * Recursively copy the contents of the given 'srcDir' - * to 'dstDir'. - * Existing files of the destination may be overwritten. + * Recursively copy the contents of the given source directory into the given destination + * directory. Existing files of the destination may be overwritten. * * @param srcDir The directory to copy files from. * @param dstDir The directory to copy files to. @@ -212,15 +223,15 @@ public static void copyDirectoryContents(final Path srcDir, final Path dstDir) t } /** - * Copy a given file from 'srcFile' to 'dstFile'. + * Copy a given source file to a given destination file. * - * This also creates new directories for any directories - * on the path to `dstFile` that do not yet exist. + * This also creates new directories on the path to {@code dstFile} that do not yet exist. * * @param srcFile The source file path. * @param dstFile The destination file path. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed - * @throws IOException if copy fails. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content + * would not be changed. + * @throws IOException If the operation fails. */ public static void copyFile(Path srcFile, Path dstFile, boolean skipIfUnchanged) throws IOException { BufferedInputStream stream = new BufferedInputStream(new FileInputStream(srcFile.toFile())); @@ -230,10 +241,10 @@ public static void copyFile(Path srcFile, Path dstFile, boolean skipIfUnchanged) } /** - * Copy a 'srcFile' to 'dstFile'. + * Copy a given source file to a given destination file. * * This also creates new directories for any directories - * on the path to `dstFile` that do not yet exist. + * on the path to {@code dstFile} that do not yet exist. * * @param srcFile The source file path. * @param dstFile The destination file path. @@ -245,13 +256,21 @@ public static void copyFile(Path srcFile, Path dstFile) throws IOException { /** - * Given a list of files or directories, attempt to find them using the given generator - * context, and copy them to the destination. Entries are searched for in the file system first. - * Entries that cannot be found in the file system are looked for on the class path. + * Given a list of files or directories, attempt to find each entry based on the given generator + * context and copy it to the destination directory. Entries are searched for in the file system + * first, relative to the source file and relative to the package root. Entries that cannot be + * found in the file system are looked for on the class path. + *

+ * If {@code contentsOnly} is true, then for each entry that is a directory, only its contents + * are copied, not the directory itself. + * For example, if the entry is a directory {@code foo/bar} and the destination is {@code baz}, + * then copies of the contents of {@code foo/bar} will be located directly in {@code baz}. + * If {@code contentsOnly} is false, then copies of the contents of {@code foo/bar} will be + * located in {@code baz/bar}. * - * @param entries The files or directory contents to copy. + * @param entries The files or directories to copy from. * @param dstDir The location to copy the files to. - * @param fileConfig The file configuration that specifies where the files must be found. + * @param fileConfig The file configuration that specifies where the find entries the given entries. * @param errorReporter An error reporter to report problems. */ public static void copyFilesOrDirectories( @@ -292,21 +311,26 @@ public static void copyFilesOrDirectories( } /** - * If the source is a directory, then copy the contents of the directory to the destination. - * If the source is a file, then copy the file to the destination. - * @param source A file or directory to copy to the destination. - * @param destination A directory to copy the file(s) at the source to. - * @throws IOException + * If the given {@code entry} is a file, then copy it into the destination. If the {@code entry} + * is a directory and {@code contentsOnly} is true, then copy its contents to the destination + * directory. If the {@code entry} is a directory and {@code contentsOnly} is true, then copy it + * including its contents to the destination directory. + * + * @param entry A file or directory to copy to the destination directory. + * @param dstDir A directory to copy the entry or its contents to. + * @param contentsOnly If true and {@code entry} is a directory, then copy its contents but not + * the directory itself. + * @throws IOException If the operation fails. */ - public static void copyFromFileSystem(Path source, Path destination, boolean contentsOnly) throws IOException { - if (Files.isDirectory(source)) { + public static void copyFromFileSystem(Path entry, Path dstDir, boolean contentsOnly) throws IOException { + if (Files.isDirectory(entry)) { if (contentsOnly) { - copyDirectoryContents(source, destination); + copyDirectoryContents(entry, dstDir); } else { - copyDirectory(source, destination, false); + copyDirectory(entry, dstDir, false); } - } else if (Files.isRegularFile(source)) { - FileUtil.copyFile(source, destination.resolve(source.getFileName())); + } else if (Files.isRegularFile(entry)) { + FileUtil.copyFile(entry, dstDir.resolve(entry.getFileName())); } else { throw new IllegalArgumentException("Source is neither a directory nor a regular file."); } @@ -319,8 +343,9 @@ public static void copyFromFileSystem(Path source, Path destination, boolean con * * @param source The source input stream. * @param destination The destination file path. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed - * @throws IOException if copy fails. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would + * not be changed. + * @throws IOException If the operation fails. */ private static void copyInputStream(InputStream source, Path destination, boolean skipIfUnchanged) throws IOException { // Read the stream once and keep a copy of all bytes. This is required as a stream cannot be read twice. @@ -345,6 +370,16 @@ private static void copyInputStream(InputStream source, Path destination, boolea Files.write(destination, bytes); } + /** + * Look up the given {@code entry} in the classpath. If it is found and is a file, copy it into + * the destination directory. If the entry is not found or not a file, throw an exception. + * + * @param entry A file copy to the destination directory. + * @param dstDir A directory to copy the entry to. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would + * not be changed. + * @throws IOException If the operation failed. + */ public static void copySingleFileFromClasspath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { final URL resource = FileConfig.class.getResource(entry); @@ -354,7 +389,9 @@ public static void copySingleFileFromClasspath(final String entry, final Path ds final URLConnection connection = resource.openConnection(); if (connection instanceof JarURLConnection) { - copySingleFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged); + if (!copySingleFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged)) { + throw new IOException("'" + entry + "' is not a file"); + } } else { try { Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); @@ -367,8 +404,11 @@ public static void copySingleFileFromClasspath(final String entry, final Path ds } /** - * Look up the given entry in the classpath. If it is a file, copy it into the destination - * directory. If it is a directory, copy its contents to the destination directory. + * Look up the given {@code entry} in the classpath. If it is a file, copy it into the destination + * directory. + * If the {@code entry} is a directory and {@code contentsOnly} is true, then copy its contents + * to the destination directory. If the {@code entry} is a directory and {@code contentsOnly} is + * true, then copy it including its contents to the destination directory. * * This also creates new directories for any directories on the destination * path that do not yet exist. @@ -377,7 +417,7 @@ public static void copySingleFileFromClasspath(final String entry, final Path ds * @param dstDir The file system path that found files are to be copied to. * @param skipIfUnchanged If true, don't overwrite the file or directory if its content would not be changed * @param contentsOnly If true and the entry is a directory, then copy its contents but not the directory itself. - * @throws IOException If the given source cannot be copied. + * @throws IOException If the operation failed. */ public static void copyFromClassPath( final String entry, @@ -428,6 +468,16 @@ private static boolean isFileInJar(JarURLConnection connection) throws IOExcepti ).findFirst().isPresent(); } + /** + * Given a JAR file and a {@code srcFile} entry, copy it into the given destination directory. + * + * @param jar The JAR file from which to copy {@code srcFile}. + * @param srcFile The source file to copy from the given {@code jar}. + * @param dstDir The directory to top the source file into. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would + * * not be changed. + * @throws IOException If the operation fails. + */ private static void copySingleFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { var entry = jar.getJarEntry(srcFile); var filename = Paths.get(entry.getName()).getFileName(); @@ -440,10 +490,10 @@ private static void copySingleFileFromJar(JarFile jar, String srcFile, Path dstD /** * Copy the contents from an entry in a JAR to destination directory in the filesystem. The entry * may be a file, in which case it will be copied under the same name into the destination - * directory. If the entry is a directory, then if the 'contentsOnly' flag is set, only the + * directory. If the entry is a directory, then if {@code contentsOnly} is true, only the * contents of the directory will be copied into the destination directory (not the directory - * itself). A directory will be copied as a whole, including its contents, if 'contentsOnly' is - * set to false. + * itself). A directory will be copied as a whole, including its contents, if + * {@code contentsOnly} is false. * * This method should only be used in standalone mode (lfc). * @@ -471,6 +521,20 @@ private static boolean copyFromJar( return copyMultipleFilesFromJar(connection, dstDir, skipIfUnchanged, contentsOnly); } + /** + * Given a connection to a JAR file that points to an entry that is a directory, copy all entries + * located in that directory or its subdirectories into the given {@code dstDir}. + *

+ * If {@code contentsOnly} is true, only the contents of the directory will be copied into the + * destination directory (not the directory itself). The directory will be copied as a whole, + * including its contents, if {@code contentsOnly} is false. + * @param connection A connection to a JAR file that points to a directory entry. + * @param dstDir The destination directory to copy the matching entries to. + * @param skipIfUnchanged + * @param contentsOnly + * @return + * @throws IOException + */ private static boolean copyMultipleFilesFromJar(JarURLConnection connection, Path dstDir, final boolean skipIfUnchanged, @@ -503,6 +567,16 @@ private static boolean copyMultipleFilesFromJar(JarURLConnection connection, return copiedFiles; } + /** + * Given a connection to a JAR file that points to an entry that is a file, copy the file into the + * given {@code dstDir}. + * @param connection A connection to a JAR file that points to a directory entry. + * @param dstDir The destination directory to copy the file to. + * @param skipIfUnchanged + * @return {@code true} the connection entry is a file, and it was copied successfully; + * {@code false} if the connection entry is not a file and the copy operation was aborted. + * @throws IOException If the operation failed. + */ private static boolean copySingleFileFromJar( JarURLConnection connection, Path dstDir, @@ -630,6 +704,13 @@ public static void relativeIncludeHelper(Path dir, Path includePath) throws IOEx } } + /** + * Delete the given file or directory if it exists. If {@code fileOrDirectory} is a directory, + * deletion is recursive. + * + * @param fileOrDirectory The file or directory to delete. + * @throws IOException If the operation failed. + */ public static void delete(Path fileOrDirectory) throws IOException { if (Files.isRegularFile(fileOrDirectory)) { Files.deleteIfExists(fileOrDirectory); From d4d96662492f48d2372af88b11c50d66b8ae8fb2 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 18:32:39 -0700 Subject: [PATCH 247/709] Revert suspicious change --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index cdf6e4d2f6..6ec5e80226 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -906,7 +906,7 @@ private void generateHeaders() throws IOException { }, this::generateTopLevelPreambles); } - FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath(), false); + FileUtil.copyDirectoryContents(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); } /** From bf00460022b53df54d108f3defff01215811e780 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 18:36:37 -0700 Subject: [PATCH 248/709] Remove FIXME that is not a FIXME --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 6ec5e80226..259d146da5 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -425,8 +425,6 @@ protected boolean isOSCompatible() { "LF programs with a CCpp target are currently not supported on Windows. " + "Exiting code generation." ); - // FIXME: The incompatibility between our C runtime code and the - // Visual Studio compiler is extensive. return false; } } From 0a23a7615a2b0c838b6d660a6cb5888b82f33cef Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 19:30:08 -0700 Subject: [PATCH 249/709] Only allow files for cmake-include entries --- .../org/lflang/generator/c/CGenerator.java | 1 - org.lflang/src/org/lflang/util/FileUtil.java | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 259d146da5..b5c82b5d3b 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -828,7 +828,6 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { // Must use class variable to determine destination! var destination = this.fileConfig.getSrcGenPath(); - // NOTE: All entries should be files, but we are not checking this. FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true); // FIXME: Unclear what the following does, but it does not appear to belong here. diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index a876e90940..2bd01cc6a9 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -278,31 +278,40 @@ public static void copyFilesOrDirectories( Path dstDir, FileConfig fileConfig, ErrorReporter errorReporter, - boolean contentsOnly + boolean fileEntriesOnly ) { for (String fileOrDirectory : entries) { var path = Paths.get(fileOrDirectory); var found = FileUtil.findInPackage(path, fileConfig); if (found != null) { try { - FileUtil.copyFromFileSystem(found, dstDir, contentsOnly); + if (fileEntriesOnly) { + FileUtil.copyFile(found, dstDir.resolve(path.getFileName())); + } else { + FileUtil.copyFromFileSystem(found, dstDir, false); + } System.out.println("Copied '" + fileOrDirectory + "' from the file system."); } catch (IOException e) { errorReporter.reportError( - "Unable to copy '" + fileOrDirectory + "' from the file system." + "Unable to copy '" + fileOrDirectory + "' from the file system. Reason: " + e.toString() ); } } else { try { - FileUtil.copyFromClassPath( - fileOrDirectory, - dstDir, - false, - contentsOnly - ); + if (fileEntriesOnly) { + copySingleFileFromClasspath(fileOrDirectory, dstDir, false); + } else { + FileUtil.copyFromClassPath( + fileOrDirectory, + dstDir, + false, + false + ); + } + } catch(IOException e) { errorReporter.reportError( - "Unable to copy '" + fileOrDirectory + "' from the class path." + "Unable to copy '" + fileOrDirectory + "' from the class path. Reason: " + e.toString() ); } System.out.println("Copied '" + fileOrDirectory + "' from the class path."); From d674900b0f1651f3ca3911ba5defb204955ca21b Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 19:49:59 -0700 Subject: [PATCH 250/709] Undo unncessary rename --- org.lflang/src/org/lflang/util/FileUtil.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 2bd01cc6a9..3ee2e6ce2d 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -398,7 +398,7 @@ public static void copySingleFileFromClasspath(final String entry, final Path ds final URLConnection connection = resource.openConnection(); if (connection instanceof JarURLConnection) { - if (!copySingleFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged)) { + if (!copyFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged)) { throw new IOException("'" + entry + "' is not a file"); } } else { @@ -487,7 +487,7 @@ private static boolean isFileInJar(JarURLConnection connection) throws IOExcepti * * not be changed. * @throws IOException If the operation fails. */ - private static void copySingleFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { + private static void copyFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { var entry = jar.getJarEntry(srcFile); var filename = Paths.get(entry.getName()).getFileName(); InputStream is = jar.getInputStream(entry); @@ -524,10 +524,10 @@ private static boolean copyFromJar( final boolean contentsOnly ) throws IOException { - if (copySingleFileFromJar(connection, dstDir, skipIfUnchanged)) { + if (copyFileFromJar(connection, dstDir, skipIfUnchanged)) { return true; } - return copyMultipleFilesFromJar(connection, dstDir, skipIfUnchanged, contentsOnly); + return copyDirectoryFromJar(connection, dstDir, skipIfUnchanged, contentsOnly); } /** @@ -544,7 +544,7 @@ private static boolean copyFromJar( * @return * @throws IOException */ - private static boolean copyMultipleFilesFromJar(JarURLConnection connection, + private static boolean copyDirectoryFromJar(JarURLConnection connection, Path dstDir, final boolean skipIfUnchanged, final boolean contentsOnly) throws IOException { @@ -586,7 +586,7 @@ private static boolean copyMultipleFilesFromJar(JarURLConnection connection, * {@code false} if the connection entry is not a file and the copy operation was aborted. * @throws IOException If the operation failed. */ - private static boolean copySingleFileFromJar( + private static boolean copyFileFromJar( JarURLConnection connection, Path dstDir, final boolean skipIfUnchanged @@ -597,7 +597,7 @@ private static boolean copySingleFileFromJar( if (!isFileInJar(connection)) { return false; } - copySingleFileFromJar(jar, source, dstDir, skipIfUnchanged); + copyFileFromJar(jar, source, dstDir, skipIfUnchanged); return true; } From 6fcad58151dd0441089227681b8f10a0a99b3a8c Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 20:11:13 -0700 Subject: [PATCH 251/709] Another rename undone --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++-- org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt | 4 ++-- org.lflang/src/org/lflang/util/FileUtil.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b5c82b5d3b..14af96038d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -983,13 +983,13 @@ protected void copyTargetFiles() throws IOException { false, false ); - FileUtil.copySingleFileFromClasspath( + FileUtil.copyFileFromClasspath( "/lib/platform/zephyr/prj_lf.conf", fileConfig.getSrcGenPath(), true ); - FileUtil.copySingleFileFromClasspath( + FileUtil.copyFileFromClasspath( "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath(), true diff --git a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt index 60b450d2c2..d624cfac9d 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt @@ -126,9 +126,9 @@ class CppGenerator( // copy static library files over to the src-gen directory val genIncludeDir = srcGenPath.resolve("__include__") listOf("lfutil.hh", "time_parser.hh").forEach { - FileUtil.copySingleFileFromClasspath("$libDir/$it", genIncludeDir, true) + FileUtil.copyFileFromClasspath("$libDir/$it", genIncludeDir, true) } - FileUtil.copySingleFileFromClasspath( + FileUtil.copyFileFromClasspath( "$libDir/3rd-party/cxxopts.hpp", genIncludeDir.resolve("CLI"), true) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 3ee2e6ce2d..b2995950c2 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -299,7 +299,7 @@ public static void copyFilesOrDirectories( } else { try { if (fileEntriesOnly) { - copySingleFileFromClasspath(fileOrDirectory, dstDir, false); + copyFileFromClasspath(fileOrDirectory, dstDir, false); } else { FileUtil.copyFromClassPath( fileOrDirectory, @@ -389,7 +389,7 @@ private static void copyInputStream(InputStream source, Path destination, boolea * not be changed. * @throws IOException If the operation failed. */ - public static void copySingleFileFromClasspath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + public static void copyFileFromClasspath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { final URL resource = FileConfig.class.getResource(entry); if (resource == null) { From 6438a2c22e2771e32278ba6f1d46cf4b517713fb Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 20:19:41 -0700 Subject: [PATCH 252/709] Use proper camelCase --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++-- org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt | 4 ++-- org.lflang/src/org/lflang/util/FileUtil.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 14af96038d..c7e585e1ab 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -983,13 +983,13 @@ protected void copyTargetFiles() throws IOException { false, false ); - FileUtil.copyFileFromClasspath( + FileUtil.copyFileFromClassPath( "/lib/platform/zephyr/prj_lf.conf", fileConfig.getSrcGenPath(), true ); - FileUtil.copyFileFromClasspath( + FileUtil.copyFileFromClassPath( "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath(), true diff --git a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt index d624cfac9d..e739560ba8 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt @@ -126,9 +126,9 @@ class CppGenerator( // copy static library files over to the src-gen directory val genIncludeDir = srcGenPath.resolve("__include__") listOf("lfutil.hh", "time_parser.hh").forEach { - FileUtil.copyFileFromClasspath("$libDir/$it", genIncludeDir, true) + FileUtil.copyFileFromClassPath("$libDir/$it", genIncludeDir, true) } - FileUtil.copyFileFromClasspath( + FileUtil.copyFileFromClassPath( "$libDir/3rd-party/cxxopts.hpp", genIncludeDir.resolve("CLI"), true) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index b2995950c2..348bcd6658 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -299,7 +299,7 @@ public static void copyFilesOrDirectories( } else { try { if (fileEntriesOnly) { - copyFileFromClasspath(fileOrDirectory, dstDir, false); + copyFileFromClassPath(fileOrDirectory, dstDir, false); } else { FileUtil.copyFromClassPath( fileOrDirectory, @@ -389,7 +389,7 @@ private static void copyInputStream(InputStream source, Path destination, boolea * not be changed. * @throws IOException If the operation failed. */ - public static void copyFileFromClasspath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + public static void copyFileFromClassPath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { final URL resource = FileConfig.class.getResource(entry); if (resource == null) { From 93c9e5b524b1eaf487e70377ba2a23cd1c87b5ef Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 20:24:30 -0700 Subject: [PATCH 253/709] Fix comment --- org.lflang/src/org/lflang/util/FileUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index 348bcd6658..a0f2e8eccc 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -531,8 +531,8 @@ private static boolean copyFromJar( } /** - * Given a connection to a JAR file that points to an entry that is a directory, copy all entries - * located in that directory or its subdirectories into the given {@code dstDir}. + * Given a connection to a JAR file that points to an entry that is a directory, recursively copy + * all entries located in that directory into the given {@code dstDir}. *

* If {@code contentsOnly} is true, only the contents of the directory will be copied into the * destination directory (not the directory itself). The directory will be copied as a whole, From 2a74c450449c7668b98b8932dea34d1f1ca4f07d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 20:51:05 -0700 Subject: [PATCH 254/709] Revive feature for copying user-specified config files --- .../org/lflang/generator/ts/TSGenerator.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 49dd3444e1..9aae97d175 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -38,6 +38,7 @@ import org.lflang.scoping.LFGlobalScopeProvider import org.lflang.util.FileUtil import java.nio.file.Files import java.nio.file.Path +import java.nio.file.StandardCopyOption import java.util.* private const val NO_NPM_MESSAGE = "The TypeScript target requires npm >= 6.14.4. " + @@ -67,6 +68,12 @@ class TSGenerator( /** Path to the TS lib directory (relative to class path) */ const val LIB_PATH = "/lib/ts" + /** + * Names of the configuration files to check for and copy to the generated + * source package root if they cannot be found in the source directory. + */ + val CONFIG_FILES = arrayOf("package.json", "tsconfig.json", ".eslintrc.json") + const val RUNTIME_URL = "git://github.com/lf-lang/reactor-ts.git" fun timeInTargetLanguage(value: TimeValue): String { @@ -220,6 +227,20 @@ class TSGenerator( true, true ) + for (configFile in CONFIG_FILES) { + val configFileInSrc = fileConfig.srcPath.resolve(configFile) + if (configFileInSrc.toFile().exists()) { + val configFileDest = fileConfig.srcGenPath.resolve(configFile) + println("Copying $configFileInSrc to $configFileDest") + Files.copy(configFileInSrc, configFileDest, StandardCopyOption.REPLACE_EXISTING) + } else { + println( + "No '" + configFile + "' exists in " + fileConfig.srcPath + + ". Using default configuration." + ) + FileUtil.copyFileFromClassPath("$LIB_PATH/$configFile", fileConfig.srcGenPath, true) + } + } } From d4b8238cf0b3851b2f3e16d78bc40c9b9f21d14b Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 22:28:04 -0700 Subject: [PATCH 255/709] Nicer implementation of user-provided config files for TS and cleanups --- .../org/lflang/generator/ts/TSGenerator.kt | 15 ++----- org.lflang/src/org/lflang/util/FileUtil.java | 43 +++++++++++++++---- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 9aae97d175..db5eb267a2 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -38,7 +38,6 @@ import org.lflang.scoping.LFGlobalScopeProvider import org.lflang.util.FileUtil import java.nio.file.Files import java.nio.file.Path -import java.nio.file.StandardCopyOption import java.util.* private const val NO_NPM_MESSAGE = "The TypeScript target requires npm >= 6.14.4. " + @@ -228,17 +227,11 @@ class TSGenerator( true ) for (configFile in CONFIG_FILES) { - val configFileInSrc = fileConfig.srcPath.resolve(configFile) - if (configFileInSrc.toFile().exists()) { - val configFileDest = fileConfig.srcGenPath.resolve(configFile) - println("Copying $configFileInSrc to $configFileDest") - Files.copy(configFileInSrc, configFileDest, StandardCopyOption.REPLACE_EXISTING) + var override = FileUtil.findAndCopyFile(configFile, fileConfig.srcGenPath, fileConfig); + if (override != null) { + System.out.println("Using user-provided '" + override + "'"); } else { - println( - "No '" + configFile + "' exists in " + fileConfig.srcPath + - ". Using default configuration." - ) - FileUtil.copyFileFromClassPath("$LIB_PATH/$configFile", fileConfig.srcGenPath, true) + System.out.println("Using default '" + configFile + "'"); } } } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index a0f2e8eccc..eb2550127e 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -254,6 +254,33 @@ public static void copyFile(Path srcFile, Path dstFile) throws IOException { copyFile(srcFile, dstFile, false); } + /** + * Find the given {@code file} in the package and return the path to the file that was found; null + * if it was not found. + * + * @param file The file to look for. + * @param dstDir The directory to copy it to. + * @param fileConfig The file configuration that specifies where look for the file. + * @return The path to the file that was found, or null if it was not found. + */ + public static Path findAndCopyFile( + String file, + Path dstDir, + FileConfig fileConfig + ) { + var path = Paths.get(file); + var found = FileUtil.findInPackage(path, fileConfig); + if (found != null) { + try { + FileUtil.copyFile(found, dstDir.resolve(path.getFileName())); + return found; + } catch (IOException e) { + return null; + } + } else { + return null; + } + } /** * Given a list of files or directories, attempt to find each entry based on the given generator @@ -307,14 +334,13 @@ public static void copyFilesOrDirectories( false, false ); + System.out.println("Copied '" + fileOrDirectory + "' from the class path."); } - } catch(IOException e) { errorReporter.reportError( "Unable to copy '" + fileOrDirectory + "' from the class path. Reason: " + e.toString() ); } - System.out.println("Copied '" + fileOrDirectory + "' from the class path."); } } } @@ -472,9 +498,9 @@ public static void copyFromClassPath( * @throws IOException If the connection is faulty. */ private static boolean isFileInJar(JarURLConnection connection) throws IOException { - return connection.getJarFile().stream().filter( + return connection.getJarFile().stream().anyMatch( it -> it.getName().equals(connection.getEntryName()) - ).findFirst().isPresent(); + ); } /** @@ -625,7 +651,7 @@ public static void arduinoDeleteHelper(Path dir, boolean threadingOn) throws IOE List allPaths = Files.walk(dir) .sorted(Comparator.reverseOrder()) - .collect(Collectors.toList()); + .toList(); for (Path path : allPaths) { String toCheck = path.toString().toLowerCase(); if (toCheck.contains("cmake")) { @@ -680,12 +706,12 @@ public static void relativeIncludeHelper(Path dir, Path includePath) throws IOEx .filter(Files::isRegularFile) .filter(FileUtil::isCFile) .sorted(Comparator.reverseOrder()) - .collect(Collectors.toList()); + .toList(); List srcPaths = Files.walk(dir) .filter(Files::isRegularFile) .filter(FileUtil::isCFile) .sorted(Comparator.reverseOrder()) - .collect(Collectors.toList()); + .toList(); Map fileStringToFilePath = new HashMap(); for (Path path : includePaths) { String fileName = path.getFileName().toString(); @@ -696,7 +722,6 @@ public static void relativeIncludeHelper(Path dir, Path includePath) throws IOEx } Pattern regexExpression = Pattern.compile("#include\s+[\"]([^\"]+)*[\"]"); for (Path path : srcPaths) { - String fileName = path.getFileName().toString(); String fileContents = Files.readString(path); Matcher matcher = regexExpression.matcher(fileContents); int lastIndex = 0; @@ -739,7 +764,7 @@ public static void deleteDirectory(Path dir) throws IOException { System.out.println("Cleaning " + dir); List pathsToDelete = Files.walk(dir) .sorted(Comparator.reverseOrder()) - .collect(Collectors.toList()); + .toList(); for (Path path : pathsToDelete) { Files.deleteIfExists(path); } From d8a48c8b1380615dbfbddb08939a54b3e6d1c7b2 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 22:52:56 -0700 Subject: [PATCH 256/709] Minor formatting --- org.lflang/src/org/lflang/generator/ts/TSGenerator.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index db5eb267a2..6bd0813531 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -220,12 +220,7 @@ class TSGenerator( * as the source file, copy a default version from $LIB_PATH/. */ private fun copyConfigFiles() { - FileUtil.copyFromClassPath( - LIB_PATH, - fileConfig.srcGenPath, - true, - true - ) + FileUtil.copyFromClassPath(LIB_PATH, fileConfig.srcGenPath, true, true) for (configFile in CONFIG_FILES) { var override = FileUtil.findAndCopyFile(configFile, fileConfig.srcGenPath, fileConfig); if (override != null) { From a42e04153729e73b751da10da4121014945cea2c Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 23:03:02 -0700 Subject: [PATCH 257/709] Update CUtil.java --- org.lflang/src/org/lflang/generator/c/CUtil.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 5e06881316..412f21b234 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -595,15 +595,15 @@ public interface ReportCommandErrors { /** * Run the custom build command specified with the "build" parameter. * This command is executed in the same directory as the source file. - * + *

* The following environment variables will be available to the command: - * - * * LF_CURRENT_WORKING_DIRECTORY: The directory in which the command is invoked. - * * LF_SOURCE_DIRECTORY: The directory containing the .lf file being compiled. - * * LF_PACKAGE_DIRECTORY: The directory for the root of the project. - * * LF_SOURCE_GEN_DIRECTORY: The directory in which generated files are placed. - * * LF_BIN_DIRECTORY: The directory into which to put binaries. - * + *

    + *
  • {@code: LF_CURRENT_WORKING_DIRECTORY}: The directory in which the command is invoked. + *
  • {@code:LF_SOURCE_DIRECTORY}: The directory containing the .lf file being compiled. + *
  • {@code:LF_PACKAGE_DIRECTORY}: The directory for the root of the project. + *
  • {@code:LF_SOURCE_GEN_DIRECTORY}: The directory in which generated files are placed. + *
  • {@code:LF_BIN_DIRECTORY}: The directory into which to put binaries. + *
*/ public static void runBuildCommand( FileConfig fileConfig, From 75976779c402251376cd961fbb93f9096a6969e0 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 23:04:32 -0700 Subject: [PATCH 258/709] Update org.lflang/src/org/lflang/generator/c/CUtil.java --- org.lflang/src/org/lflang/generator/c/CUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 412f21b234..b5949f660b 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -600,7 +600,7 @@ public interface ReportCommandErrors { *
    *
  • {@code: LF_CURRENT_WORKING_DIRECTORY}: The directory in which the command is invoked. *
  • {@code:LF_SOURCE_DIRECTORY}: The directory containing the .lf file being compiled. - *
  • {@code:LF_PACKAGE_DIRECTORY}: The directory for the root of the project. + *
  • {@code:LF_PACKAGE_DIRECTORY}: The directory that is the root of the package. *
  • {@code:LF_SOURCE_GEN_DIRECTORY}: The directory in which generated files are placed. *
  • {@code:LF_BIN_DIRECTORY}: The directory into which to put binaries. *
From ea017aaec1198ab96605dfb9e7af3ab8355960ae Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 4 May 2023 23:10:44 -0700 Subject: [PATCH 259/709] Apply suggestions from code review --- .../org/lflang/tests/compiler/LinguaFrancaValidationTest.java | 4 ++-- org.lflang/src/org/lflang/validation/LFValidator.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index e3ca78aaf2..3ae350d5fb 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -821,7 +821,7 @@ public void testInheritanceSupport() throws Exception { reactor B extends A{} """.formatted(target)); - if(target.supportsInheritance()) { + if (target.supportsInheritance()) { validator.assertNoIssues(model); } else { validator.assertError(model, LfPackage.eINSTANCE.getReactor(), null, @@ -838,7 +838,7 @@ public void testFederationSupport() throws Exception { federated reactor {} """.formatted(target)); - if(target.supportsFederated()) { + if (target.supportsFederated()) { validator.assertNoIssues(model); } else { validator.assertError(model, LfPackage.eINSTANCE.getReactor(), null, diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 74a54f7435..06d0010a88 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -984,7 +984,7 @@ public void checkReactor(Reactor reactor) throws IOException { } if (reactor.isFederated()) { - if(!target.supportsFederated()) { + if (!target.supportsFederated()) { error("The " + target.getDisplayName() + " target does not support federated execution.", Literals.REACTOR__FEDERATED); } From 128be9da3531ceed78c5ad7056f8dfed626dcf06 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 5 May 2023 15:26:50 +0200 Subject: [PATCH 260/709] fix unit tests --- .../compiler/LinguaFrancaValidationTest.java | 4 +- .../org/lflang/validation/LFValidator.java | 71 ++++++++++--------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 3ae350d5fb..8c6fa81759 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -137,7 +137,7 @@ public void disallowReactorCalledPreamble() throws Exception { Model model_error_1 = parser.parse(""" target Cpp; - main reactor Preamble { + reactor Preamble { } """); @@ -145,7 +145,7 @@ public void disallowReactorCalledPreamble() throws Exception { target Cpp; reactor Preamble { } - main reactor Main { + main reactor { } """); diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 06d0010a88..5f9d4764ac 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -852,30 +852,52 @@ public void checkReaction(Reaction reaction) { // FIXME: improve error message. } - public void checkReactorName(Reactor reactor) throws IOException { - String name = FileUtil.nameWithoutExtension(reactor.eResource()); - + public void checkReactorName(String name) throws IOException { // Check for illegal names. - if(reactor.getName() != null) { - checkName(reactor.getName(), Literals.REACTOR_DECL__NAME); + checkName(name, Literals.REACTOR_DECL__NAME); + + // C++ reactors may not be called 'preamble' + if (this.target == Target.CPP && name.equalsIgnoreCase("preamble")) { + error( + "Reactor cannot be named '" + name + "'", + Literals.REACTOR_DECL__NAME + ); + } + } - // C++ reactors may not be called 'preamble' - if (this.target == Target.CPP && name.equalsIgnoreCase("preamble")) { + @Check(CheckType.FAST) + public void checkReactor(Reactor reactor) throws IOException { + String fileName = FileUtil.nameWithoutExtension(reactor.eResource()); + + if (reactor.isFederated() || reactor.isMain()) { + // Do not allow multiple main/federated reactors. + TreeIterator iter = reactor.eResource().getAllContents(); + int nMain = countMainOrFederated(iter); + if (nMain > 1) { + EAttribute attribute = Literals.REACTOR__MAIN; + if (reactor.isFederated()) { + attribute = Literals.REACTOR__FEDERATED; + } error( - "Reactor cannot be named '" + name + "'", - Literals.REACTOR_DECL__NAME + "Multiple definitions of main or federated reactor.", + attribute ); } - } - if (reactor.isFederated() || reactor.isMain()) { - if(reactor.getName() != null && !reactor.getName().equals(name)) { + if(reactor.getName() != null && !reactor.getName().equals(fileName)) { // Make sure that if the name is given, it matches the expected name. error( "Name of main reactor must match the file name (or be omitted).", Literals.REACTOR_DECL__NAME ); } + + // check the reactor name indicated by the file name + // Skip this check if the file is named __synthetic0. This Name is used during testing, + // and we would get an unexpected error due to the '__' prefix otherwise. + if (!fileName.equals("__synthetic0")) { + checkReactorName(fileName); + } } else { // Not federated or main. if (reactor.getName() == null) { @@ -884,9 +906,11 @@ public void checkReactorName(Reactor reactor) throws IOException { Literals.REACTOR_DECL__NAME ); } else { + checkReactorName(reactor.getName()); + TreeIterator iter = reactor.eResource().getAllContents(); int nMain = countMainOrFederated(iter); - if (nMain > 0 && reactor.getName().equals(name)) { + if (nMain > 0 && reactor.getName().equals(fileName)) { error( "Name conflict with main reactor.", Literals.REACTOR_DECL__NAME @@ -894,27 +918,6 @@ public void checkReactorName(Reactor reactor) throws IOException { } } } - } - - @Check(CheckType.FAST) - public void checkReactor(Reactor reactor) throws IOException { - checkReactorName(reactor); - - if (reactor.isFederated() || reactor.isMain()) { - // Do not allow multiple main/federated reactors. - TreeIterator iter = reactor.eResource().getAllContents(); - int nMain = countMainOrFederated(iter); - if (nMain > 1) { - EAttribute attribute = Literals.REACTOR__MAIN; - if (reactor.isFederated()) { - attribute = Literals.REACTOR__FEDERATED; - } - error( - "Multiple definitions of main or federated reactor.", - attribute - ); - } - } Set superClasses = ASTUtils.superClasses(reactor); From 37abf64eb807aa05226f64988b05ae4bc2bd8508 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 5 May 2023 15:40:30 +0200 Subject: [PATCH 261/709] fix unit tests --- .../org/lflang/tests/compiler/LinguaFrancaValidationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 8c6fa81759..aa285a2e32 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -281,7 +281,7 @@ public void disallowUnderscoreStates() throws Exception { public void disallowUnderscoreReactorDef() throws Exception { String testCase = """ target TypeScript; - main reactor __Foo { + reactor __Foo { } """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, From 7547acf9da075a52eedf98dddab568161776db7b Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 5 May 2023 10:36:35 -0700 Subject: [PATCH 262/709] Move watchdog test into concurrent --- test/C/src/{ => concurrent}/Watchdog.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/{ => concurrent}/Watchdog.lf (100%) diff --git a/test/C/src/Watchdog.lf b/test/C/src/concurrent/Watchdog.lf similarity index 100% rename from test/C/src/Watchdog.lf rename to test/C/src/concurrent/Watchdog.lf From c54def7e9e162f0f78df813dd806a6138b1b04e1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 5 May 2023 12:21:48 -0700 Subject: [PATCH 263/709] More lenient test --- test/C/src/concurrent/Watchdog.lf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/C/src/concurrent/Watchdog.lf b/test/C/src/concurrent/Watchdog.lf index 3ee48afe9c..18250f89dc 100644 --- a/test/C/src/concurrent/Watchdog.lf +++ b/test/C/src/concurrent/Watchdog.lf @@ -36,7 +36,8 @@ reactor Watcher(timeout: time = 150 ms) { reaction(shutdown) -> poodle {= lf_watchdog_stop(poodle); - if (self->count != 2) { + // Watchdog may expire in tests even without the sleep, but it should at least expire twice. + if (self->count < 2) { lf_print_error_and_exit("Watchdog expired %d times. Expected 2.", self->count); } =} From 54fa3d00383f9158e35fa58d3cdc443df16616e9 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 6 May 2023 06:10:44 -0700 Subject: [PATCH 264/709] Aligned reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ffe9a6a2e2..618fa07480 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ffe9a6a2e2bf79f45c1019d48f17b1b92eaf01a5 +Subproject commit 618fa07480964d82ebd88e28378bbfd335adb27c From 836bb3ee41e07762f4409a50bc296dd06037883c Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 6 May 2023 07:00:34 -0700 Subject: [PATCH 265/709] Made test timing lenient. --- test/C/src/concurrent/Watchdog.lf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/C/src/concurrent/Watchdog.lf b/test/C/src/concurrent/Watchdog.lf index 18250f89dc..bc8ab1387b 100644 --- a/test/C/src/concurrent/Watchdog.lf +++ b/test/C/src/concurrent/Watchdog.lf @@ -38,7 +38,7 @@ reactor Watcher(timeout: time = 150 ms) { lf_watchdog_stop(poodle); // Watchdog may expire in tests even without the sleep, but it should at least expire twice. if (self->count < 2) { - lf_print_error_and_exit("Watchdog expired %d times. Expected 2.", self->count); + lf_print_error_and_exit("Watchdog expired %d times. Expected at least 2.", self->count); } =} } @@ -59,8 +59,8 @@ main reactor { =} reaction(shutdown) {= - if (self->count != 12) { - lf_print_error_and_exit("Watchdog produced output %d times. Expected 12.", self->count); + if (self->count < 12) { + lf_print_error_and_exit("Watchdog produced output %d times. Expected at least 12.", self->count); } =} } From eb4272086856a7f3054883e2b178991f2ffb7dd6 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 6 May 2023 14:16:09 -0700 Subject: [PATCH 266/709] Inherit preambles --- org.lflang/src/org/lflang/ASTUtils.java | 13 +++++++++++++ .../src/org/lflang/generator/c/CGenerator.java | 2 +- test/C/src/PreambleInherited.lf | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/C/src/PreambleInherited.lf diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index afda11bb46..0129dfc1b0 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -81,6 +81,7 @@ import org.lflang.lf.Parameter; import org.lflang.lf.ParameterReference; import org.lflang.lf.Port; +import org.lflang.lf.Preamble; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; @@ -377,6 +378,18 @@ public static List allPorts(Reactor definition) { return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); } + /** + * Given a reactor class, return a list of all its preambles, + * which includes preambles of base classes that it extends. + * If the base classes include a cycle, where X extends Y and Y extends X, + * then return only the input defined in the base class. + * The returned list may be empty. + * @param definition Reactor class definition. + */ + public static List allPreambles(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Preambles()); + } + /** * Given a reactor class, return a list of all its instantiations, * which includes instantiations of base classes that it extends. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index c7e585e1ab..b6e51876b0 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1078,7 +1078,7 @@ protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { * @param reactor The given reactor */ protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { + for (Preamble p : ASTUtils.allPreambles(reactor)) { src.pr("// *********** From the preamble, verbatim:"); src.prSourceLineNumber(p.getCode()); src.pr(toText(p.getCode())); diff --git a/test/C/src/PreambleInherited.lf b/test/C/src/PreambleInherited.lf new file mode 100644 index 0000000000..1f2e9e1cb5 --- /dev/null +++ b/test/C/src/PreambleInherited.lf @@ -0,0 +1,17 @@ +/** + * Check that preamble is inherited. + * Success is just compiling and running. + */ +target C +reactor A { + preamble {= + #define FOO 2 + =} + reaction(startup) {= + printf("FOO: %d\n", FOO); + =} +} +reactor B extends A {} +main reactor { + b = new B() +} From 7651e8c03a595a504835cbcd980242de831381a7 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 6 May 2023 14:29:02 -0700 Subject: [PATCH 267/709] Formated test --- test/C/src/PreambleInherited.lf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/C/src/PreambleInherited.lf b/test/C/src/PreambleInherited.lf index 1f2e9e1cb5..c7db161962 100644 --- a/test/C/src/PreambleInherited.lf +++ b/test/C/src/PreambleInherited.lf @@ -1,17 +1,17 @@ -/** - * Check that preamble is inherited. - * Success is just compiling and running. - */ +/** Check that preamble is inherited. Success is just compiling and running. */ target C + reactor A { preamble {= #define FOO 2 =} - reaction(startup) {= - printf("FOO: %d\n", FOO); - =} + + reaction(startup) {= printf("FOO: %d\n", FOO); =} +} + +reactor B extends A { } -reactor B extends A {} + main reactor { b = new B() } From 5ef1eda9a12e7faec1fb9422782f744820e361ad Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 6 May 2023 16:03:09 -0700 Subject: [PATCH 268/709] Include file-level preambles for base classes --- org.lflang/src/org/lflang/ASTUtils.java | 46 +++++++++++++++++++ .../org/lflang/generator/c/CGenerator.java | 5 +- test/C/src/PreambleFileLevel.lf | 14 ++++++ test/C/src/lib/FileLevelPreamble.lf | 13 ++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/C/src/PreambleFileLevel.lf create mode 100644 test/C/src/lib/FileLevelPreamble.lf diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 0129dfc1b0..2cb9dad397 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -401,6 +401,11 @@ public static List allInstantiations(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); } + /** + * Given a reactor class, return a stream of reactor classes that it instantiates. + * @param definition Reactor class definition. + * @return A stream of reactor classes. + */ public static Stream allNestedClasses(Reactor definition) { return new HashSet<>(ASTUtils.allInstantiations(definition)).stream() .map(Instantiation::getReactorClass) @@ -500,6 +505,19 @@ public static LinkedHashSet superClasses(Reactor reactor) { return superClasses(reactor, new LinkedHashSet<>()); } + /** + * Return all the file-level preambles in the files that define the + * specified class and its superclasses in deepest-first order. + * Duplicates are removed. If there are no file-level preambles, + * then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + */ + public static LinkedHashSet allFileLevelPreambles(Reactor reactor) { + return allFileLevelPreambles(reactor, new LinkedHashSet<>()); + } + /** * Collect elements of type T from the class hierarchy and modes * defined by a given reactor definition. @@ -1781,6 +1799,34 @@ private static LinkedHashSet superClasses(Reactor reactor, Set return result; } + /** + * Return all the file-level preambles in the files that define the + * specified class and its superclasses in deepest-first order. + * Duplicates are removed. If there are no file-level preambles, + * then return an empty list. + * If a cycle is found, where X extends Y and Y extends X, or if + * a superclass is declared that is not found, then return null. + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor + * (used to detect circular extensions). + */ + private static LinkedHashSet allFileLevelPreambles(Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet basePreambles = allFileLevelPreambles(r, extensions); + extensions.remove(r); + if (basePreambles == null) return null; + result.addAll(basePreambles); + } + result.addAll(((Model) reactor.eContainer()).getPreambles()); + return result; + } + /** * We may be able to infer the width by examining the connections of * the enclosing reactor definition. This works, for example, with diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b6e51876b0..be931153f8 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1983,8 +1983,11 @@ protected String generateTopLevelPreambles(Reactor reactor) { var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; builder.pr("#ifndef " + guard); builder.pr("#define " + guard); + // Reactors that are instantiated by the specified reactor need to have + // their file-level preambles included. This needs to also include file-level + // preambles of base classes of those reactors. Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) - .flatMap(it -> ((Model) it.eContainer()).getPreambles().stream()) + .flatMap(it -> ASTUtils.allFileLevelPreambles(it).stream()) .collect(Collectors.toSet()) .forEach(it -> builder.pr(toText(it.getCode()))); for (String file : targetConfig.protoFiles) { diff --git a/test/C/src/PreambleFileLevel.lf b/test/C/src/PreambleFileLevel.lf new file mode 100644 index 0000000000..ed2def967a --- /dev/null +++ b/test/C/src/PreambleFileLevel.lf @@ -0,0 +1,14 @@ +/** + * Test for ensuring that file-level preambles are inherited when a file is + * imported. + */ +target C + +import FileLevelPreamble from "lib/FileLevelPreamble.lf" + +reactor B extends FileLevelPreamble { +} + +main reactor { + b = new B() +} diff --git a/test/C/src/lib/FileLevelPreamble.lf b/test/C/src/lib/FileLevelPreamble.lf new file mode 100644 index 0000000000..846ed66163 --- /dev/null +++ b/test/C/src/lib/FileLevelPreamble.lf @@ -0,0 +1,13 @@ +/** + * Test for ensuring that file-level preambles are inherited when a file is + * imported. + */ +target C + +preamble {= + #define FOO 2 +=} + +reactor FileLevelPreamble { + reaction(startup) {= printf("FOO: %d\n", FOO); =} +} From a36d8a3e872d95b80dadecb0113d9c8575029cfc Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 8 May 2023 14:08:27 +0200 Subject: [PATCH 269/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 6bdf8c9f05..4e75aec034 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 6bdf8c9f054e463359f46170eb073928aea33ff9 +Subproject commit 4e75aec034f709de1236381ac9dcd7dbd3c8affe From de0af0c4314bec1c06f6cef9aaa6235831fbde1b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 8 May 2023 16:29:48 +0200 Subject: [PATCH 270/709] unify connection generation using a lambda function this simplifies the connection procedure. Instead of generating different code for normal, enclaved, or just delayed connections, we use the same code for all and insert a lambda that is called to instantiate the concrete connection. --- org.lflang/src/lib/cpp/lfutil.hh | 53 +++----------- .../cpp/CppAssembleMethodGenerator.kt | 73 ++++++++----------- .../generator/cpp/CppConnectionGenerator.kt | 30 ++++---- test/Cpp/src/enclave/EnclaveBroadcast.lf | 37 ++++++++++ .../Cpp/src/enclave/EnclaveMultiportToPort.lf | 49 +++++++++++++ test/Cpp/src/multiport/Broadcast.lf | 9 +++ 6 files changed, 151 insertions(+), 100 deletions(-) create mode 100644 test/Cpp/src/enclave/EnclaveBroadcast.lf create mode 100644 test/Cpp/src/enclave/EnclaveMultiportToPort.lf diff --git a/org.lflang/src/lib/cpp/lfutil.hh b/org.lflang/src/lib/cpp/lfutil.hh index 4ed850e571..292bd1db5e 100644 --- a/org.lflang/src/lib/cpp/lfutil.hh +++ b/org.lflang/src/lib/cpp/lfutil.hh @@ -65,12 +65,13 @@ class LFScope { void request_stop() const { return environment()->sync_shutdown(); } }; -template +template void bind_multiple_ports( - std::vector*>& left_ports, - std::vector*>& right_ports, - bool repeat_left) { - + std::vector& left_ports, + std::vector& right_ports, + bool repeat_left, + std::function connect) +{ if (repeat_left) { auto l_size = left_ports.size(); auto r_size = right_ports.size(); @@ -94,50 +95,14 @@ void bind_multiple_ports( << "Not all ports will be connected!"; } + std::size_t idx{0}; while (left_it != left_ports.end() && right_it != right_ports.end()) { auto left = *left_it; auto right = *right_it; - left->bind_to(right); - left_it++; - right_it++; - } -} - -template -void bind_multiple_connections_with_ports( - std::vector*>& connections, - std::vector*>& ports, - bool repeat_left) { - - if (repeat_left) { - auto l_size = connections.size(); - auto r_size = ports.size(); - // divide and round up - auto repetitions = r_size / l_size + (r_size % l_size != 0); - // repeat repetitions-1 times - connections.reserve(repetitions * l_size); - for (std::size_t i{1}; i < repetitions; i++) { - std::copy_n(connections.begin(), l_size, std::back_inserter(connections)); - } - } - - auto left_it = connections.begin(); - auto right_it = ports.begin(); - - if (connections.size() < ports.size()) { - reactor::log::Warn() << "There are more right ports than left ports. " - << "Not all ports will be connected!"; - } else if (connections.size() > ports.size()) { - reactor::log::Warn() << "There are more left ports than right ports. " - << "Not all ports will be connected!"; - } - - while (left_it != connections.end() && right_it != ports.end()) { - auto left = *left_it; - auto right = *right_it; - left->bind_downstream_port(right); + connect(left, right, idx); left_it++; right_it++; + idx++; } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index 45112487bd..60f2ff62a7 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -186,47 +186,38 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { // within a bank, then we normally iterate over all banks in an outer loop and over all ports in an inner loop. However, // if the connection is an interleaved connection, than we change the order on the right side and iterate over ports before banks. return with(PrependOperator) { - if (!c.requiresConnectionClass) { - """ - |// connection $idx - |std::vector<$portType> __lf_left_ports_$idx; - ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} - |std::vector<$portType> __lf_right_ports_$idx; - ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} - |lfutil::bind_multiple_ports(__lf_left_ports_$idx, __lf_right_ports_$idx, ${c.isIterated}); - """.trimMargin() - } else if (!c.isEnclaveConnection) { - """ - |// connection $idx - |std::vector<$portType> __lf_left_ports_$idx; - ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} - |${c.name}.reserve(__lf_left_ports_$idx.size()); - |for(size_t __lf_idx{0}; __lf_idx < __lf_left_ports_$idx.size(); __lf_idx++) { - | ${c.name}.emplace_back("${c.name}" + std::to_string(__lf_idx), this, ${c.delay.toCppTime()}); - | ${c.name}.back().bind_upstream_port(__lf_left_ports_$idx[__lf_idx]); - |} - |std::vector*> __lf_connection_pointers_$idx; - |for (auto& connection : ${c.name}) { - | __lf_connection_pointers_$idx.push_back(&connection); - |} - |std::vector<$portType> __lf_right_ports_$idx; - ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} - |lfutil::bind_multiple_connections_with_ports(__lf_connection_pointers_$idx, __lf_right_ports_$idx, ${c.isIterated}); - """.trimMargin() - } else { - """ - |// connection $idx - |std::vector<$portType> __lf_left_ports_$idx; - ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} - |std::vector<$portType> __lf_right_ports_$idx; - ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} - |for(size_t __lf_idx{0}; __lf_idx < std::min(__lf_right_ports_$idx.size(), __lf_left_ports_$idx.size()); __lf_idx++) { - | ${c.name}.emplace_back("${c.name}" + std::to_string(__lf_idx), __lf_right_ports_$idx[__lf_idx]->environment()${if(c.delay != null) ", ${c.delay.toCppTime()}" else ""}); - | ${c.name}.back().bind_upstream_port(__lf_left_ports_$idx[__lf_idx]); - | ${c.name}.back().bind_downstream_port(__lf_right_ports_$idx[__lf_idx]); - |} - """.trimMargin() - } + """ + |// connection $idx + |std::vector<$portType> __lf_left_ports_$idx; + ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} + |std::vector<$portType> __lf_right_ports_$idx; + ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} + |lfutil::bind_multiple_ports<$portType>(__lf_left_ports_$idx, __lf_right_ports_$idx, ${c.isIterated}, + ${" |"..c.getConnectionLambda(portType)} + |); + """.trimMargin() + } + } + + private fun Connection.getConnectionLambda(portType: String): String { + return when { + isEnclaveConnection -> """ + [this]($portType left, $portType right, std::size_t idx) { + $name.emplace_back("$name" + std::to_string(idx), right->environment()${if (delay != null) ", ${delay.toCppTime()}" else ""}); + $name.back().bind_upstream_port(left); + $name.back().bind_downstream_port(right); + } + """.trimIndent() + + requiresConnectionClass -> """ + [this]($portType left, $portType right, std::size_t idx) { + $name.emplace_back("$name" + std::to_string(idx), this, ${delay.toCppTime()}); + $name.back().bind_upstream_port(left); + $name.back().bind_downstream_port(right); + } + """.trimIndent() + + else -> "[]($portType left, $portType right, [[maybe_unused]]std::size_t idx) { left->bind_to(right); }" } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt index 897fe01202..4be190314d 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt @@ -41,21 +41,19 @@ class CppConnectionGenerator(private val reactor: Reactor) { val Connection.isEnclaveConnection: Boolean get() { - if (leftPorts.size == 1 && rightPorts.size == 1) { - val leftIsEnclave = leftPorts[0].container?.isEnclave == true - val rightIsEnclave = rightPorts[0].container?.isEnclave == true - return when { - leftIsEnclave && rightIsEnclave -> true - !leftIsEnclave && !rightIsEnclave -> false - else -> TODO("Connections between enclaves and normal reactors are not supported") - } - } + var foundEnclave = false + var allEnclave = true for (port in leftPorts + rightPorts) { if (port.container?.isEnclave == true) { - TODO("Enclaves can only be used in simple connections") + foundEnclave = true + } else { + allEnclave = false } } - return false + if (foundEnclave && !allEnclave) { + TODO("Connections between enclaves and normal reactors are not supported") + } + return foundEnclave } val Connection.requiresConnectionClass: Boolean get() = isPhysical || delay != null || isEnclaveConnection; @@ -71,10 +69,12 @@ class CppConnectionGenerator(private val reactor: Reactor) { private fun generateDecleration(connection: Connection): String? = with(connection) { if (requiresConnectionClass) { - when { - hasMultipleConnections && isEnclaveConnection -> "std::list<${connection.cppType}> ${connection.name};" - hasMultipleConnections && !isEnclaveConnection -> "std::vector<${connection.cppType}> ${connection.name};" - else -> "${connection.cppType} ${connection.name};" + if (hasMultipleConnections) { + // We use an std::list here as connections currently cannot be safely moved and std::vector requires + // objects to be movable. + "std::list<${connection.cppType}> ${connection.name};" + } else { + "${connection.cppType} ${connection.name};" } } else null } diff --git a/test/Cpp/src/enclave/EnclaveBroadcast.lf b/test/Cpp/src/enclave/EnclaveBroadcast.lf new file mode 100644 index 0000000000..d00fbbf059 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveBroadcast.lf @@ -0,0 +1,37 @@ +target Cpp{timeout: 1 sec} + +reactor Source { + output out: unsigned + + reaction(startup) -> out {= out.set(42); =} +} + +reactor Sink(bank_index: size_t = 0) { + input in: unsigned + + state received: bool = false + + reaction(in) {= + received = true; + std::cout << "Received " << *in.get() << '\n'; + if (*in.get() != 42) { + std::cerr << "Error: expected " << 42 << "!\n"; + exit(1); + } + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: Sink " << bank_index << " didn't receive anything.\n"; + exit(2); + } + =} +} + +main reactor { + @enclave + source = new Source() + @enclave(each=true) + sink = new[4] Sink() + (source.out)+ -> sink.in +} diff --git a/test/Cpp/src/enclave/EnclaveMultiportToPort.lf b/test/Cpp/src/enclave/EnclaveMultiportToPort.lf new file mode 100644 index 0000000000..027de94bfb --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveMultiportToPort.lf @@ -0,0 +1,49 @@ +// Check multiport output to multiport input. Destination port is wider than +// sending port. +target Cpp { + timeout: 2 sec, + fast: true +} + +reactor Source { + output[2] out: int + + reaction(startup) -> out {= + for(int i = 0; i < out.size(); i++) { + std::cout << "Source sending " << i << ".\n"; + out[i].set(i); + } + =} +} + +reactor Destination(expected: int = 0) { + input in: int + state received: bool = false + + reaction(in) {= + std::cout << "Received: " << *in.get() << ".\n"; + received = true; + if (*in.get() != expected) { + std::cerr << "ERROR: Expected " << expected << ".\n"; + exit(1); + } + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} +} + +main reactor { + @enclave + a = new Source() + @enclave + b1 = new Destination() + @enclave + b2 = new Destination(expected = 1) + a.out -> b1.in, b2.in +} diff --git a/test/Cpp/src/multiport/Broadcast.lf b/test/Cpp/src/multiport/Broadcast.lf index 077ca75247..202a30c5f7 100644 --- a/test/Cpp/src/multiport/Broadcast.lf +++ b/test/Cpp/src/multiport/Broadcast.lf @@ -8,14 +8,23 @@ reactor Source { reactor Sink(bank_index: size_t = 0) { input in: unsigned + state received: bool = false reaction(in) {= + received = true; std::cout << "Received " << *in.get() << '\n'; if (*in.get() != 42) { std::cerr << "Error: expected " << 42 << "!\n"; exit(1); } =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: Sink " << bank_index << " didn't receive anything.\n"; + exit(2); + } + =} } main reactor { From d6c4e5afa06ec8e143eec5d1e8452d3fee8ed132 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 8 May 2023 16:54:04 +0200 Subject: [PATCH 271/709] allow connections where not all ports belong to enclaves --- .../generator/cpp/CppConnectionGenerator.kt | 11 +--- test/Cpp/src/enclave/EnclaveCommunication2.lf | 43 ++++++++++++ .../enclave/EnclaveCommunicationDelayed2.lf | 43 ++++++++++++ test/Cpp/src/enclave/EnclaveCycle2lf | 66 +++++++++++++++++++ .../src/enclave/EnclaveMultiportToPort2.lf | 48 ++++++++++++++ 5 files changed, 202 insertions(+), 9 deletions(-) create mode 100644 test/Cpp/src/enclave/EnclaveCommunication2.lf create mode 100644 test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf create mode 100644 test/Cpp/src/enclave/EnclaveCycle2lf create mode 100644 test/Cpp/src/enclave/EnclaveMultiportToPort2.lf diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt index 4be190314d..83c3f5554a 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt @@ -41,19 +41,12 @@ class CppConnectionGenerator(private val reactor: Reactor) { val Connection.isEnclaveConnection: Boolean get() { - var foundEnclave = false - var allEnclave = true for (port in leftPorts + rightPorts) { if (port.container?.isEnclave == true) { - foundEnclave = true - } else { - allEnclave = false + return true } } - if (foundEnclave && !allEnclave) { - TODO("Connections between enclaves and normal reactors are not supported") - } - return foundEnclave + return false } val Connection.requiresConnectionClass: Boolean get() = isPhysical || delay != null || isEnclaveConnection; diff --git a/test/Cpp/src/enclave/EnclaveCommunication2.lf b/test/Cpp/src/enclave/EnclaveCommunication2.lf new file mode 100644 index 0000000000..648223fb0b --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunication2.lf @@ -0,0 +1,43 @@ +target Cpp { + timeout: 1 s, + workers: 1 +} + +reactor Src { + timer t(0, 100 ms) + output out: int + state counter: int = 0 + + reaction(t) -> out {= out.set(counter++); =} +} + +reactor Sink { + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in +} diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf new file mode 100644 index 0000000000..9cfa3f0a11 --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf @@ -0,0 +1,43 @@ +target Cpp { + timeout: 1 s, + workers: 1 +} + +reactor Src { + timer t(0, 100 ms) + output out: int + state counter: int = 0 + + reaction(t) -> out {= out.set(counter++); =} +} + +reactor Sink { + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value + 50ms; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + src = new Src() + @enclave + sink = new Sink() + + src.out -> sink.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveCycle2lf b/test/Cpp/src/enclave/EnclaveCycle2lf new file mode 100644 index 0000000000..34e0b2bdfa --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveCycle2lf @@ -0,0 +1,66 @@ +target Cpp { + timeout: 1 s, + workers: 1 +} + +reactor Ping { + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false + + reaction(t) -> out {= out.set(counter++); =} + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Ping Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +reactor Pong { + input in: int + output out: int + state received: bool = false + + reaction(in) -> out {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Pong Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + out.set(value); + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} +} + +main reactor { + ping = new Ping() + @enclave + pong = new Pong() + + ping.out -> pong.in + pong.out -> ping.in after 50 ms +} diff --git a/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf b/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf new file mode 100644 index 0000000000..5d8d72494d --- /dev/null +++ b/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf @@ -0,0 +1,48 @@ +// Check multiport output to multiport input. Destination port is wider than +// sending port. +target Cpp { + timeout: 2 sec, + fast: true +} + +reactor Source { + output[2] out: int + + reaction(startup) -> out {= + for(int i = 0; i < out.size(); i++) { + std::cout << "Source sending " << i << ".\n"; + out[i].set(i); + } + =} +} + +reactor Destination(expected: int = 0) { + input in: int + state received: bool = false + + reaction(in) {= + std::cout << "Received: " << *in.get() << ".\n"; + received = true; + if (*in.get() != expected) { + std::cerr << "ERROR: Expected " << expected << ".\n"; + exit(1); + } + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} +} + +main reactor { + @enclave + a = new Source() + @enclave + b1 = new Destination() + b2 = new Destination(expected = 1) + a.out -> b1.in, b2.in +} From 814e0bfec29c4d958f9a92b83fa0550709fd5fb6 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 8 May 2023 17:17:57 +0200 Subject: [PATCH 272/709] use vector of unique pointers to store connections --- org.lflang/src/lib/cpp/lfutil.hh | 2 -- .../generator/cpp/CppAssembleMethodGenerator.kt | 17 ++++++++++------- .../generator/cpp/CppConnectionGenerator.kt | 4 +--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/org.lflang/src/lib/cpp/lfutil.hh b/org.lflang/src/lib/cpp/lfutil.hh index 292bd1db5e..77116dcbe1 100644 --- a/org.lflang/src/lib/cpp/lfutil.hh +++ b/org.lflang/src/lib/cpp/lfutil.hh @@ -27,8 +27,6 @@ #include #include -#include - namespace lfutil { template diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index 60f2ff62a7..0aef4a9b65 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -26,6 +26,7 @@ package org.lflang.generator.cpp import org.lflang.* import org.lflang.generator.PrependOperator +import org.lflang.generator.cpp.CppConnectionGenerator.Companion.cppType import org.lflang.generator.cpp.CppConnectionGenerator.Companion.isEnclaveConnection import org.lflang.generator.cpp.CppConnectionGenerator.Companion.name import org.lflang.generator.cpp.CppConnectionGenerator.Companion.requiresConnectionClass @@ -172,7 +173,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { * complex logic for finding the actual type, we return a decltype statement and let the C++ compiler do the job. */ private val VarRef.portType: String - get() = "reactor::Port<${dataType}>*" + get() = "reactor::Port*" private fun declareMultiportConnection(c: Connection, idx: Int): String { // It should be safe to assume that all ports have the same type. Thus we just pick the @@ -192,6 +193,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} |std::vector<$portType> __lf_right_ports_$idx; ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} + |${c.name}.reserve(std::max(__lf_left_ports_$idx.size(), __lf_right_ports_$idx.size())); |lfutil::bind_multiple_ports<$portType>(__lf_left_ports_$idx, __lf_right_ports_$idx, ${c.isIterated}, ${" |"..c.getConnectionLambda(portType)} |); @@ -203,17 +205,18 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { return when { isEnclaveConnection -> """ [this]($portType left, $portType right, std::size_t idx) { - $name.emplace_back("$name" + std::to_string(idx), right->environment()${if (delay != null) ", ${delay.toCppTime()}" else ""}); - $name.back().bind_upstream_port(left); - $name.back().bind_downstream_port(right); + $name.push_back(std::make_unique<$cppType>( + "$name" + std::to_string(idx), right->environment()${if (delay != null) ", ${delay.toCppTime()}" else ""})); + $name.back()->bind_upstream_port(left); + $name.back()->bind_downstream_port(right); } """.trimIndent() requiresConnectionClass -> """ [this]($portType left, $portType right, std::size_t idx) { - $name.emplace_back("$name" + std::to_string(idx), this, ${delay.toCppTime()}); - $name.back().bind_upstream_port(left); - $name.back().bind_downstream_port(right); + $name.push_back(std::make_unique<$cppType>("$name" + std::to_string(idx), this, ${delay.toCppTime()})}); + $name.back()->bind_upstream_port(left); + $name.back()->bind_downstream_port(right); } """.trimIndent() diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt index 83c3f5554a..c9af656291 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt @@ -63,9 +63,7 @@ class CppConnectionGenerator(private val reactor: Reactor) { with(connection) { if (requiresConnectionClass) { if (hasMultipleConnections) { - // We use an std::list here as connections currently cannot be safely moved and std::vector requires - // objects to be movable. - "std::list<${connection.cppType}> ${connection.name};" + "std::vector> ${connection.name};" } else { "${connection.cppType} ${connection.name};" } From 3d84b6c9fd4ea781d9e5085ce7c453c79f84f0f7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 8 May 2023 17:27:17 +0200 Subject: [PATCH 273/709] format test --- test/Cpp/src/enclave/EnclaveBroadcast.lf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveBroadcast.lf b/test/Cpp/src/enclave/EnclaveBroadcast.lf index d00fbbf059..04a2a77941 100644 --- a/test/Cpp/src/enclave/EnclaveBroadcast.lf +++ b/test/Cpp/src/enclave/EnclaveBroadcast.lf @@ -1,4 +1,6 @@ -target Cpp{timeout: 1 sec} +target Cpp { + timeout: 1 sec +} reactor Source { output out: unsigned @@ -31,7 +33,7 @@ reactor Sink(bank_index: size_t = 0) { main reactor { @enclave source = new Source() - @enclave(each=true) + @enclave(each = true) sink = new[4] Sink() (source.out)+ -> sink.in } From c0b51270dbe41cfa468b951f69ae909c2d2e2562 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 10 May 2023 12:42:52 +0200 Subject: [PATCH 274/709] only reserve if we have a dedicated connection vector --- .../org/lflang/generator/cpp/CppAssembleMethodGenerator.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index 0aef4a9b65..f944af8d90 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -180,9 +180,6 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { // first left port to determine the type of the entire connection val portType = c.leftPorts[0].portType - val leftPort = c.leftPorts[0].variable as Port - val dataType = leftPort.inferredType.cppType - // Generate code which adds all left hand ports and all right hand ports to a vector each. If we are handling multiports // within a bank, then we normally iterate over all banks in an outer loop and over all ports in an inner loop. However, // if the connection is an interleaved connection, than we change the order on the right side and iterate over ports before banks. @@ -193,7 +190,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} |std::vector<$portType> __lf_right_ports_$idx; ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} - |${c.name}.reserve(std::max(__lf_left_ports_$idx.size(), __lf_right_ports_$idx.size())); + ${" |"..if (c.requiresConnectionClass) "{c.name}.reserve(std::max(__lf_left_ports_$idx.size(), __lf_right_ports_$idx.size()))" else ""} |lfutil::bind_multiple_ports<$portType>(__lf_left_ports_$idx, __lf_right_ports_$idx, ${c.isIterated}, ${" |"..c.getConnectionLambda(portType)} |); From 3b49f12e5bd26419411de0d6e299e47e44c15300 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 10 May 2023 13:20:57 +0200 Subject: [PATCH 275/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 4e75aec034..b4c6963ea6 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 4e75aec034f709de1236381ac9dcd7dbd3c8affe +Subproject commit b4c6963ea6a5d951a5cf71b947f550117bd9f688 From fa0e05806e429cc1d8a0250b2d9a37c775a93376 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 10 May 2023 13:22:08 +0200 Subject: [PATCH 276/709] bugfix --- .../src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index f944af8d90..503f5c950c 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -190,7 +190,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { ${" |"..c.leftPorts.joinWithLn { addAllPortsToVector(it, "__lf_left_ports_$idx") }} |std::vector<$portType> __lf_right_ports_$idx; ${" |"..c.rightPorts.joinWithLn { addAllPortsToVector(it, "__lf_right_ports_$idx") }} - ${" |"..if (c.requiresConnectionClass) "{c.name}.reserve(std::max(__lf_left_ports_$idx.size(), __lf_right_ports_$idx.size()))" else ""} + ${" |"..if (c.requiresConnectionClass) "${c.name}.reserve(std::max(__lf_left_ports_$idx.size(), __lf_right_ports_$idx.size()));" else ""} |lfutil::bind_multiple_ports<$portType>(__lf_left_ports_$idx, __lf_right_ports_$idx, ${c.isIterated}, ${" |"..c.getConnectionLambda(portType)} |); From f7261ea522426b4f0136ad895ef0523ea1e57042 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 10 May 2023 14:08:44 +0200 Subject: [PATCH 277/709] another C++ syntax fix --- .../src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt index 503f5c950c..0bb63e24c3 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt @@ -211,7 +211,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) { requiresConnectionClass -> """ [this]($portType left, $portType right, std::size_t idx) { - $name.push_back(std::make_unique<$cppType>("$name" + std::to_string(idx), this, ${delay.toCppTime()})}); + $name.push_back(std::make_unique<$cppType>("$name" + std::to_string(idx), this, ${delay.toCppTime()})); $name.back()->bind_upstream_port(left); $name.back()->bind_downstream_port(right); } From aae5cae30fbf753ef74d76eb0825d4bb9d497d04 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 10 May 2023 15:04:11 +0200 Subject: [PATCH 278/709] relax deadline --- test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf index 3bade0f63e..58bd641387 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf @@ -1,12 +1,12 @@ // The purpose of this test is to check that the downstream enclave can // progress, even if there are only sparse upstream events. target Cpp { - timeout: 6 s, + timeout: 12 s, workers: 1 } -reactor Src { - timer t(0, 2 s) +reactor Src {s + timer t(0, 4 s) output out: int state counter: int = 0 @@ -36,7 +36,7 @@ reactor Sink { } =} - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= reactor::log::Error() << "Deadline violated."; exit(2); =} From aa409f84f8a59d2124790dc2d71932dee93d0486 Mon Sep 17 00:00:00 2001 From: mkhubaibumer Date: Thu, 11 May 2023 19:27:40 +0500 Subject: [PATCH 279/709] Update Reactor-C --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 1d762fd8b3..f1d41011e4 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 1d762fd8b367c84cb92e6314591b3bcd650bae8b +Subproject commit f1d41011e454a026741beb68bd9a3ec80101c8ee From 0554c99f93cf5176a4322844cf593e9a1164ff49 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 12 May 2023 09:55:48 +0200 Subject: [PATCH 280/709] fix test file --- test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf index 58bd641387..73a90dbd21 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf @@ -5,7 +5,7 @@ target Cpp { workers: 1 } -reactor Src {s +reactor Src { timer t(0, 4 s) output out: int state counter: int = 0 From a3055968837d34d8f8600adefdd0b65588bf5615 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 12 May 2023 10:37:30 +0200 Subject: [PATCH 281/709] relax more deadlines and update timings --- test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf | 2 +- .../Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf | 8 ++++---- .../src/enclave/EnclaveSparseUpstreamEventsPhysical.lf | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf index 73a90dbd21..431c2cd60a 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf @@ -22,7 +22,7 @@ reactor Sink { received = true; auto value = *in.get(); reactor::log::Info() << "Received " << value; - auto expected = 2s * value; + auto expected = 4s * value; if (get_elapsed_logical_time() != expected) { reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); exit(1); diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf index e299f921ad..691e80f4bf 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf @@ -1,12 +1,12 @@ // The purpose of this test is to check that the downstream enclave respects the // after delay when aquiring tags from its upstream. target Cpp { - timeout: 6 s, + timeout: 12 s, workers: 1 } reactor Src { - timer t(0, 2 s) + timer t(0, 4 s) output out: int state counter: int = 0 @@ -22,7 +22,7 @@ reactor Sink { received = true; auto value = *in.get(); reactor::log::Info() << "Received " << value; - auto expected = 2s + 2s * value; + auto expected = 2s + 4s * value; if (get_elapsed_logical_time() != expected) { reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); exit(1); @@ -36,7 +36,7 @@ reactor Sink { } =} - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= reactor::log::Error() << "Deadline violated."; exit(2); =} diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf index 6e1e579bd0..10b5a8c4af 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf @@ -1,12 +1,12 @@ // The purpose of this test is to check that the downstream enclave advances // time independenty of the upstraem if the connection is physical. target Cpp { - timeout: 6 s, + timeout: 12 s, workers: 1 } reactor Src { - timer t(0, 2 s) + timer t(0, 4 s) output out: int state counter: int = 0 @@ -22,7 +22,7 @@ reactor Sink { received = true; auto value = *in.get(); reactor::log::Info() << "Received " << value; - auto expected = 2s * value; + auto expected = 4s * value; if (get_elapsed_logical_time() < expected) { reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); exit(1); @@ -36,7 +36,7 @@ reactor Sink { } =} - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(1 s) {= + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= reactor::log::Error() << "Deadline violated."; exit(2); =} From d311497fb1444041ee263d82daa47a76945f2855 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Fri, 12 May 2023 22:04:02 +0200 Subject: [PATCH 282/709] Fix enum name after naming convention --- org.lflang/src/org/lflang/TargetProperty.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index d8058009bb..6dcb81ebe1 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -432,7 +432,7 @@ public enum TargetProperty { case PORT: pair.setValue(ASTUtils.toElement(config.platformOptions.port)); break; - case USERTHREADS: + case USER_THREADS: pair.setValue(ASTUtils.toElement(config.platformOptions.userThreads)); break; } @@ -475,7 +475,7 @@ public enum TargetProperty { case PORT: config.platformOptions.port = ASTUtils.elementToSingleString(entry.getValue()); break; - case USERTHREADS: + case USER_THREADS: config.platformOptions.userThreads = ASTUtils.toInteger(entry.getValue()); break; default: @@ -1666,7 +1666,7 @@ public enum PlatformOption implements DictionaryElement { BOARD("board", PrimitiveType.STRING), FLASH("flash", PrimitiveType.BOOLEAN), PORT("port", PrimitiveType.STRING), - USERTHREADS("user_threads", PrimitiveType.NON_NEGATIVE_INTEGER); + USER_THREADS("user-threads", PrimitiveType.NON_NEGATIVE_INTEGER); public final PrimitiveType type; From 62c39cd609accef0b1629623ef8731455a3d1385 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Fri, 12 May 2023 22:04:36 +0200 Subject: [PATCH 283/709] Use enum for setting compile definition --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 2bec8857bf..d53b39a6fa 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -58,6 +58,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; +import org.lflang.TargetProperty.PlatformOption; import org.lflang.federated.extensions.CExtensionUtils; @@ -1965,11 +1966,15 @@ protected void setUpGeneralParameters() { if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.platformOptions.userThreads >= 0) { targetConfig.compileDefinitions.put( - "USER_THREADS", + PlatformOption.USER_THREADS.name(), String.valueOf(targetConfig.platformOptions.userThreads) ); } + if (targetConfig.platformOptions.platform != Platform.ZEPHYR && targetConfig.platformOptions.userThreads >= 0) { + System.out.println("Specifying user threads is only for the Zephyr platform. This option will be ignored."); + } + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake pickScheduler(); // FIXME: this and pickScheduler should be combined. From 166227a453dfb763b24a2cf7403b93525e192fd9 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Fri, 12 May 2023 22:05:01 +0200 Subject: [PATCH 284/709] Add user thread test for Zephyr --- test/C/src/zephyr/UserThreads.lf | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/C/src/zephyr/UserThreads.lf diff --git a/test/C/src/zephyr/UserThreads.lf b/test/C/src/zephyr/UserThreads.lf new file mode 100644 index 0000000000..dc54c9f3f6 --- /dev/null +++ b/test/C/src/zephyr/UserThreads.lf @@ -0,0 +1,36 @@ +// Test user threads platform option for Zephyr. The application should be able +// to create exactly three threads. +target C { + platform: { + name: Zephyr, + user-threads: 3 + }, + threading: true, + workers: 2, +} + +main reactor { + preamble {= + void func() {} + =} + reaction(startup) {= + int res; + int thread_id; + + for (int i = 0; i < 3; i++) { + res = lf_thread_create(&thread_id, &func, NULL); + if (res != 0) { + printf("FAILURE: Expected to be able to create thread.\n"); + exit(1); + } + } + + res = lf_thread_create(&thread_id, &func, NULL); + if (res == 0) { + printf("FAILURE: Expected to not be able to create thread.\n"); + exit(2); + } else { + printf("SUCCESS: Created exactly three user threads.\n"); + } + =} +} \ No newline at end of file From 48898a273cacaaee9360da69268c2da5bd3b9332 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 12 May 2023 14:02:54 +0200 Subject: [PATCH 285/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index b4c6963ea6..1b6b996af5 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit b4c6963ea6a5d951a5cf71b947f550117bd9f688 +Subproject commit 1b6b996af5a33e16665113d52311316e37825520 From 5bf8a003ba918426901a7bcf1561fdd1c42021f0 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Mon, 15 May 2023 10:04:30 +0200 Subject: [PATCH 286/709] Fix error and warning reports --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 3 +-- test/C/src/zephyr/UserThreads.lf | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index dfcdf1f445..401b380687 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1943,8 +1943,7 @@ protected void setUpGeneralParameters() { } if (targetConfig.platformOptions.platform != Platform.ZEPHYR && targetConfig.platformOptions.userThreads >= 0) { - System.out.println("Specifying user threads is only for the Zephyr platform. This option will be ignored."); - } + errorReporter.reportWarning("Specifying user threads is only for the Zephyr platform. This option will be ignored."); } if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake pickScheduler(); diff --git a/test/C/src/zephyr/UserThreads.lf b/test/C/src/zephyr/UserThreads.lf index dc54c9f3f6..105da11d01 100644 --- a/test/C/src/zephyr/UserThreads.lf +++ b/test/C/src/zephyr/UserThreads.lf @@ -20,15 +20,13 @@ main reactor { for (int i = 0; i < 3; i++) { res = lf_thread_create(&thread_id, &func, NULL); if (res != 0) { - printf("FAILURE: Expected to be able to create thread.\n"); - exit(1); + lf_print_error_and_exit("Could not create thread"); } } res = lf_thread_create(&thread_id, &func, NULL); if (res == 0) { - printf("FAILURE: Expected to not be able to create thread.\n"); - exit(2); + lf_print_error_and_exit("Could create more threads than specified."); } else { printf("SUCCESS: Created exactly three user threads.\n"); } From 1a3c07378fad0b959b65efc97d2bc6822a02cef5 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 15 May 2023 07:20:34 -0700 Subject: [PATCH 287/709] Include string.h --- util/tracing/trace_to_chrome.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/tracing/trace_to_chrome.c b/util/tracing/trace_to_chrome.c index 5cf979227a..8e0c29dba8 100644 --- a/util/tracing/trace_to_chrome.c +++ b/util/tracing/trace_to_chrome.c @@ -32,6 +32,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define LF_TRACE #include +#include #include "reactor.h" #include "trace.h" #include "trace_util.h" From f8d38f0413d2aa324b3f1522e96fe480cfcb390e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 15 May 2023 07:32:00 -0700 Subject: [PATCH 288/709] Align to watchdogs-eal2 of reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 618fa07480..cc3795695b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 618fa07480964d82ebd88e28378bbfd335adb27c +Subproject commit cc3795695b18638512d5fe3c8ae8c021f044de9a From b7d0cd1b820c154ceebb80cf4fa9e0099258c51f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 15 May 2023 17:43:45 +0200 Subject: [PATCH 289/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 1b6b996af5..1d17d9c543 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 1b6b996af5a33e16665113d52311316e37825520 +Subproject commit 1d17d9c5439d57e00145798e4dbd87d18342b891 From 749e332de1fb2e365909e52534803556427f71a7 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 15 May 2023 13:39:09 -0700 Subject: [PATCH 290/709] Closes #1701. --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index be931153f8..3c5d872f96 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -28,7 +28,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import static org.lflang.ASTUtils.allPorts; import static org.lflang.ASTUtils.allReactions; import static org.lflang.ASTUtils.allStateVars; -import static org.lflang.ASTUtils.convertToEmptyListIfNull; import static org.lflang.ASTUtils.getInferredType; import static org.lflang.ASTUtils.isInitialized; import static org.lflang.ASTUtils.toDefinition; @@ -51,6 +50,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.eclipse.xtext.xbase.lib.StringExtensions; import org.lflang.ASTUtils; +import org.lflang.generator.CodeMap; import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; import org.lflang.Target; @@ -1029,10 +1029,10 @@ private void generateReactorClass(Reactor reactor) throws IOException { generateUserPreamblesForReactor(reactor, src); generateReactorClassBody(reactor, header, src); header.pr("#endif // " + guardMacro); - FileUtil.writeToFile(header.toString(), fileConfig.getSrcGenPath().resolve(headerName), true); + FileUtil.writeToFile(CodeMap.fromGeneratedCode(header.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(headerName), true); var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : CCppMode ? ".cpp" : ".c"; - FileUtil.writeToFile(src.toString(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); + FileUtil.writeToFile(CodeMap.fromGeneratedCode(src.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); } protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { From 036625c6a9759e40fb73e061d34455b0763562b0 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 16 May 2023 09:23:13 +0200 Subject: [PATCH 291/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 1d17d9c543..10a8055a65 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 1d17d9c5439d57e00145798e4dbd87d18342b891 +Subproject commit 10a8055a65ce4aec8b4c560b363046f08d46342f From 46a3738605d35bf73cf233e2b918bd0c9463f8ba Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 16 May 2023 18:31:07 +0200 Subject: [PATCH 292/709] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 10a8055a65..9a7b0a91ad 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 10a8055a65ce4aec8b4c560b363046f08d46342f +Subproject commit 9a7b0a91ad72bbf87702f2392ed2bebba528e831 From a84070a0a127e8b16471ee9434eb0dfe214019e1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 16 May 2023 13:43:20 -0700 Subject: [PATCH 293/709] In response to review, renamed variables --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++-- .../src/org/lflang/generator/c/CWatchdogGenerator.java | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index cc3795695b..c2c6a54fa0 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit cc3795695b18638512d5fe3c8ae8c021f044de9a +Subproject commit c2c6a54fa023c638122a73a7c7f311cf381cea1e diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 4a7f29dabe..be6307943c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -642,8 +642,8 @@ private void generateCodeFor( "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", "int bank_index;", "SUPPRESS_UNUSED_WARNING(bank_index);", - "int _lf_watchdog_number_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_watchdog_number_count);")); + "int watchdog_number = 0;", + "SUPPRESS_UNUSED_WARNING(watchdog_number);")); // Add counters for modal initialization initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 311fe365fd..28d9223ea8 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -62,7 +62,7 @@ protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstan : ASTUtils.allWatchdogs(ASTUtils.toDefinition(instance.getDefinition().getReactorClass()))) { var watchdogField = reactorRef + "->_lf_watchdog_" + watchdog.getName(); temp.pr(String.join("\n", - "_lf_watchdogs[_lf_watchdog_number_count++] = &" + watchdogField + ";", + "_lf_watchdogs[watchdog_number++] = &" + watchdogField + ";", watchdogField + ".min_expiration = " + CTypes.getInstance().getTargetTimeExpr(instance.getTimeValue(watchdog.getTimeout())) + ";", @@ -78,7 +78,7 @@ protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstan if (foundOne) { code.pr(temp.toString()); } - code.pr("SUPPRESS_UNUSED_WARNING(_lf_watchdog_number);"); + code.pr("SUPPRESS_UNUSED_WARNING(_lf_watchdog_count);"); return watchdogCount; } @@ -152,7 +152,7 @@ protected static String generateWatchdogTable(int count) { "// No watchdogs found.", "typedef void watchdog_t;", "watchdog_t* _lf_watchdogs = NULL;", - "int _lf_watchdog_number = 0;" + "int _lf_watchdog_count = 0;" ); } return String.join( @@ -160,7 +160,7 @@ protected static String generateWatchdogTable(int count) { List.of( "// Array of pointers to watchdog structs.", "watchdog_t* _lf_watchdogs[" + count + "];", - "int _lf_watchdog_number = " + count + ";" + "int _lf_watchdog_count = " + count + ";" ) ); } From 029f825201694b30a16156a0d352dd1cba20d6c0 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 19:43:46 -0700 Subject: [PATCH 294/709] "fix" naming collision in fed-gen files. This is not really a fix because we still have the problem that we consider reactor classes to have distinct names using a **case-sensitive** comparison, but we want to generate files corresponding to the reactor classes that will be compared **case-insensitively** on macOS. However, it does make our generated code "less wrong." --- org.lflang/src/org/lflang/federated/generator/FedEmitter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java index 9ae5c9d2cc..9cbffdbae2 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java @@ -52,7 +52,7 @@ Map generateFederate( + fileConfig.getSrcPath()); Path lfFilePath = fileConfig.getSrcPath().resolve( - fedName + ".lf"); + "__" + fedName + ".lf"); String federateCode = String.join( "\n", From c11dd2e9d5759cf9f780c1c4549aef0dfd09be4e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 20:05:43 -0700 Subject: [PATCH 295/709] Check for case-insensitive name collisions. --- org.lflang/src/org/lflang/ModelInfo.java | 38 +++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index 45e9995045..c447d381ac 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -11,15 +11,15 @@ this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ @@ -28,6 +28,7 @@ import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter; import static org.eclipse.xtext.xbase.lib.IteratorExtensions.toIterable; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -81,7 +82,7 @@ public class ModelInfo { * interval. */ public Set overflowingDeadlines; - + /** * The set of STP offsets that use a too-large constant to specify their time * interval. @@ -137,6 +138,23 @@ public void update(Model model, ErrorReporter reporter) { if (target == Target.C) { this.collectOverflowingNodes(); } + + checkCaseInsensitiveNameCollisions(model, reporter); + } + + public void checkCaseInsensitiveNameCollisions(Model model, ErrorReporter reporter) { + var reactorNames = new HashSet<>(); + var bad = new ArrayList<>(); + for (var reactor : model.getReactors()) { + var lowerName = reactor.getName().toLowerCase(); + if (reactorNames.contains(lowerName)) bad.add(lowerName); + reactorNames.add(lowerName); + } + for (var badName : bad) { + model.getReactors().stream().filter(it -> it.getName() + .toLowerCase().equals(badName)) + .forEach(it -> reporter.reportError(it, "Multiple reactors have the same name up to case differences.")); + } } public Set> topologyCycles() { @@ -223,7 +241,7 @@ private boolean detectOverflow(Set visited, Parameter current) { // Check for overflow in the referenced parameter. overflow = detectOverflow(visited, ((ParameterReference)expr).getParameter()) || overflow; } else { - // The right-hand side of the assignment is a + // The right-hand side of the assignment is a // constant; check whether it is too large. if (isTooLarge(ASTUtils.getLiteralTimeValue(expr))) { this.overflowingAssignments.add(assignment); From 4f85c270b64e0fa4634add3f92860def23100f54 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 20:23:02 -0700 Subject: [PATCH 296/709] Refactor a bit. The file name of the fed-gen file should be specified in one place (DRY). --- .../src/org/lflang/federated/generator/FedEmitter.java | 9 ++++++--- .../src/org/lflang/federated/generator/FedGenerator.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java index 9cbffdbae2..ee44002306 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java @@ -51,9 +51,6 @@ Map generateFederate( + " in directory " + fileConfig.getSrcPath()); - Path lfFilePath = fileConfig.getSrcPath().resolve( - "__" + fedName + ".lf"); - String federateCode = String.join( "\n", new FedTargetEmitter().generateTarget(context, numOfFederates, federate, fileConfig, errorReporter, rtiConfig), @@ -67,6 +64,7 @@ Map generateFederate( ) ); Map codeMapMap = new HashMap<>(); + var lfFilePath = lfFilePath(fileConfig, federate); try (var srcWriter = Files.newBufferedWriter(lfFilePath)) { var codeMap = CodeMap.fromGeneratedCode(federateCode); codeMapMap.put(lfFilePath, codeMap); @@ -74,4 +72,9 @@ Map generateFederate( } return codeMapMap; } + + public static Path lfFilePath(FedFileConfig fileConfig, FederateInstance federate) { + return fileConfig.getSrcPath().resolve( + "__" + federate.name + ".lf"); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index cd9c2e95d0..dddae562f7 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -286,7 +286,7 @@ private Map compileFederates( final int id = i; compileThreadPool.execute(() -> { Resource res = rs.getResource(URI.createFileURI( - fileConfig.getSrcPath().resolve(fed.name + ".lf").toAbsolutePath().toString() + FedEmitter.lfFilePath(fileConfig, fed).toAbsolutePath().toString() ), true); FileConfig subFileConfig = LFGenerator.createFileConfig(res, fileConfig.getSrcGenPath(), true); ErrorReporter subContextErrorReporter = new LineAdjustingErrorReporter(threadSafeErrorReporter, lf2lfCodeMapMap); From 0cbbacd36c424b21bca42b5711396fb9367d26a5 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 21:13:03 -0700 Subject: [PATCH 297/709] Fix NPE in getting name of reactor. --- org.lflang/src/org/lflang/ModelInfo.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index c447d381ac..22caf4a0dc 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -28,6 +28,7 @@ import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter; import static org.eclipse.xtext.xbase.lib.IteratorExtensions.toIterable; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; @@ -47,6 +48,7 @@ import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; import org.lflang.lf.STP; +import org.lflang.util.FileUtil; /** @@ -146,17 +148,21 @@ public void checkCaseInsensitiveNameCollisions(Model model, ErrorReporter report var reactorNames = new HashSet<>(); var bad = new ArrayList<>(); for (var reactor : model.getReactors()) { - var lowerName = reactor.getName().toLowerCase(); + var lowerName = getName(reactor).toLowerCase(); if (reactorNames.contains(lowerName)) bad.add(lowerName); reactorNames.add(lowerName); } for (var badName : bad) { - model.getReactors().stream().filter(it -> it.getName() - .toLowerCase().equals(badName)) + model.getReactors().stream() + .filter(it -> getName(it).toLowerCase().equals(badName)) .forEach(it -> reporter.reportError(it, "Multiple reactors have the same name up to case differences.")); } } + private String getName(Reactor r) { + return r.getName() == null ? r.getName() : FileUtil.nameWithoutExtension(Path.of(model.eResource().getURI().toFileString())); + } + public Set> topologyCycles() { return this.topologyCycles; } From e1652694045e73f49c4d70d24003fb97846e4e7d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 21:25:27 -0700 Subject: [PATCH 298/709] Update unit test. --- .../src/org/lflang/tests/compiler/TargetConfigTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java index 593e302d25..12b86996cb 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java @@ -94,7 +94,7 @@ public void testFederation() throws Exception { generator.doGenerate(resource, fileAccess, context); String lfSrc = Files.readAllLines( - ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("a.lf") + ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("__a.lf") ).stream().reduce("\n", String::concat); Model federate = parser.parse(lfSrc); assertHasTargetProperty(federate, "tracing"); From 47eb5c8ab58bce0e971f86c8c77d8d4541239a04 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 21:28:15 -0700 Subject: [PATCH 299/709] Fix logical error. --- org.lflang/src/org/lflang/ModelInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index 22caf4a0dc..fbe5c2047c 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -160,7 +160,7 @@ public void checkCaseInsensitiveNameCollisions(Model model, ErrorReporter report } private String getName(Reactor r) { - return r.getName() == null ? r.getName() : FileUtil.nameWithoutExtension(Path.of(model.eResource().getURI().toFileString())); + return r.getName() != null ? r.getName() : FileUtil.nameWithoutExtension(Path.of(model.eResource().getURI().toFileString())); } public Set> topologyCycles() { From 05827f1119a9e2b9ab9f6eb42ea80e9b0f5a1473 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 16 May 2023 23:28:14 -0700 Subject: [PATCH 300/709] Attempt to pass failing TS docker tests. --- org.lflang/src/org/lflang/generator/DockerGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/DockerGenerator.java b/org.lflang/src/org/lflang/generator/DockerGenerator.java index 902d664631..851ee6c0be 100644 --- a/org.lflang/src/org/lflang/generator/DockerGenerator.java +++ b/org.lflang/src/org/lflang/generator/DockerGenerator.java @@ -43,7 +43,7 @@ public DockerData generateDockerData() { var dockerFilePath = context.getFileConfig().getSrcGenPath().resolve("Dockerfile"); var dockerFileContent = generateDockerFileContent(); - return new DockerData(name, dockerFilePath, dockerFileContent); + return new DockerData(name.replace("_", ""), dockerFilePath, dockerFileContent); } public static DockerGenerator dockerGeneratorFactory(LFGeneratorContext context) { From 3c52f30f82c2863a47eb980ea799b7fd0c7abef2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 11:02:16 -0700 Subject: [PATCH 301/709] Bugfix. The problem here is that we use the uniqueID of the federate both before and after we transform it into separate programs. After we transform it, the name of the instance depends on the name of the main reactor, which might be different (indeed, it must be different in order for us to eliminate the possibility of name collisions with other parts of the program). So this is a bit of a hack, but I'm not sure what else to do. --- org.lflang/src/org/lflang/generator/ReactorInstance.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index eb5163ade6..92d7d9ea3d 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -323,7 +323,8 @@ public String getName() { @Override public String uniqueID() { if (this.isMainOrFederated()) { - return super.uniqueID() + "_main"; + if (reactorDefinition.isFederated()) return "__" + super.uniqueID() + "_main"; + return super.uniqueID() + "_main"; } return super.uniqueID(); } From 2551a52142474be7a1c04183f4485b3e43595482 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 15:08:11 -0700 Subject: [PATCH 302/709] Address federated test failures. It is bad that in order to make this change it is necessary to edit code in several places. But it isn't clear how to fix this because different parts of the code operate on the program at different stages in the compilation process, either before or after it has been split into many programs. --- .../federated/generator/FederateInstance.java | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 7ca5a19bca..6dd7dc1de2 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -97,8 +97,8 @@ public class FederateInstance { // why does this not extend ReactorInstance? * @param errorReporter The error reporter */ public FederateInstance( - Instantiation instantiation, - int id, + Instantiation instantiation, + int id, int bankIndex, TargetConfig targetConfig, ErrorReporter errorReporter) { @@ -107,9 +107,9 @@ public FederateInstance( this.bankIndex = bankIndex; this.errorReporter = errorReporter; this.targetConfig = targetConfig; - + if (instantiation != null) { - this.name = instantiation.getName(); + this.name = "__" + instantiation.getName(); // If the instantiation is in a bank, then we have to append // the bank index to the name. if (instantiation.getWidthSpec() != null) { @@ -120,18 +120,18 @@ public FederateInstance( ///////////////////////////////////////////// //// Public Fields - + /** * The position within a bank of reactors for this federate. * This is 0 if the instantiation is not a bank of reactors. */ public int bankIndex = 0; - + /** * A list of outputs that can be triggered directly or indirectly by physical actions. */ public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); - + /** * The host, if specified using the 'at' keyword. */ @@ -150,7 +150,7 @@ public Instantiation getInstantiation() { * A list of individual connections between federates */ public Set connections = new HashSet<>(); - + /** * Map from the federates that this federate receives messages from * to the delays on connections from that federate. The delay set @@ -158,17 +158,17 @@ public Instantiation getInstantiation() { * from the federate instance that has no delay. */ public Map> dependsOn = new LinkedHashMap<>(); - + /** * The directory, if specified using the 'at' keyword. */ public String dir = null; - + /** * The port, if specified using the 'at' keyword. */ public int port = 0; - + /** * Map from the federates that this federate sends messages to * to the delays on connections to that federate. The delay set @@ -176,12 +176,12 @@ public Instantiation getInstantiation() { * from the federate instance that has no delay. */ public Map> sendsTo = new LinkedHashMap<>(); - + /** * The user, if specified using the 'at' keyword. */ public String user = null; - + /** * The integer ID of this federate. */ @@ -194,7 +194,7 @@ public Instantiation getInstantiation() { * this instance if the instantiation is of a bank of reactors. */ public String name = "Unnamed"; - + /** * List of networkMessage actions. Each of these handles a message * received from another federate over the network. The ID of @@ -202,7 +202,7 @@ public Instantiation getInstantiation() { * The sending federate needs to specify this ID. */ public List networkMessageActions = new ArrayList<>(); - + /** * A set of federates with which this federate has an inbound connection * There will only be one physical connection even if federate A has defined multiple @@ -211,7 +211,7 @@ public Instantiation getInstantiation() { * to help the receiver distinguish different events. */ public Set inboundP2PConnections = new LinkedHashSet<>(); - + /** * A list of federate with which this federate has an outbound physical connection. * There will only be one physical connection even if federate A has defined multiple @@ -220,29 +220,29 @@ public Instantiation getInstantiation() { * scheduling the appropriate action. */ public Set outboundP2PConnections = new LinkedHashSet<>(); - + /** * A list of triggers for network input control reactions. This is used to trigger * all the input network control reactions that might be nested in a hierarchy. */ public List networkInputControlReactionsTriggers = new ArrayList<>(); - + /** * The trigger that triggers the output control reaction of this * federate. - * + * * The network output control reactions send a PORT_ABSENT message for a network output port, * if it is absent at the current tag, to notify all downstream federates that no value will * be present on the given network port, allowing input control reactions on those federates * to stop blocking. */ public Variable networkOutputControlReactionsTrigger = null; - + /** * Indicates whether the federate is remote or local */ public boolean isRemote = false; - + /** * List of generated network reactions (network receivers, * network input control reactions, network senders, and network output control @@ -389,16 +389,16 @@ private boolean contains(Action action) { } } } - - return false; + + return false; } - /** + /** * Return true if the specified reaction should be included in the code generated for this * federate at the top-level. This means that if the reaction is triggered by or * sends data to a port of a contained reactor, then that reaction * is in the federate. Otherwise, return false. - * + * * NOTE: This method assumes that it will not be called with reaction arguments * that are within other federates. It should only be called on reactions that are * either at the top level or within this federate. For this reason, for any reaction @@ -411,7 +411,7 @@ private boolean contains(Reaction reaction) { assert reactor != null; if (!reactor.getReactions().contains(reaction)) return false; - + if (networkReactions.contains(reaction)) { // Reaction is a network reaction that belongs to this federate return true; @@ -421,15 +421,15 @@ private boolean contains(Reaction reaction) { if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { return false; } - + // If this has been called before, then the result of the // following check is cached. if (excludeReactions != null) { return !excludeReactions.contains(reaction); } - + indexExcludedTopLevelReactions(reactor); - + return !excludeReactions.contains(reaction); } @@ -462,17 +462,17 @@ private boolean contains(Timer timer) { return false; } - /** + /** * Return true if the specified reactor instance or any parent * reactor instance is contained by this federate. * If the specified instance is the top-level reactor, return true * (the top-level reactor belongs to all federates). * If this federate instance is a singleton, then return true if the * instance is non null. - * + * * NOTE: If the instance is bank within the top level, then this * returns true even though only one of the bank members is in the federate. - * + * * @param instance The reactor instance. * @return True if this federate contains the reactor instance */ @@ -496,7 +496,7 @@ public boolean contains(ReactorInstance instance) { * federatedReactor) that don't belong to this federate * instance. This index is put in the excludeReactions * class variable. - * + * * @param federatedReactor The top-level federated reactor */ private void indexExcludedTopLevelReactions(Reactor federatedReactor) { @@ -537,7 +537,7 @@ private void indexExcludedTopLevelReactions(Reactor federatedReactor) { } } } - + /** * Return true if all members of 'varRefs' belong to this federate. * @@ -564,7 +564,7 @@ private boolean containsAllVarRefs(Iterable varRefs) { } return inFederate; } - + /** * Find output ports that are connected to a physical action trigger upstream * in the same reactor. Return a list of such outputs paired with the minimum delay @@ -596,7 +596,7 @@ public List getZeroDelayImmediateUpstreamFederates() { .filter(e -> e.getValue().contains(null)) .map(Map.Entry::getKey).toList(); } - + @Override public String toString() { return "Federate " + id + ": " @@ -605,21 +605,21 @@ public String toString() { ///////////////////////////////////////////// //// Private Fields - + /** * Cached result of analysis of which reactions to exclude from main. */ private Set excludeReactions = null; - + /** * An error reporter */ private final ErrorReporter errorReporter; - + /** * Find the nearest (shortest) path to a physical action trigger from this * 'reaction' in terms of minimum delay. - * + * * @param reaction The reaction to start with * @return The minimum delay found to the nearest physical action and * TimeValue.MAX_VALUE otherwise @@ -646,7 +646,7 @@ public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { } } } - + } else if (trigger.getDefinition() instanceof Output) { // Outputs of contained reactions PortInstance outputInstance = (PortInstance) trigger; @@ -660,7 +660,7 @@ public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { } return minDelay; } - + // TODO: Put this function into a utils file instead private List convertToEmptyListIfNull(List list) { return list == null ? new ArrayList<>() : list; From 13e9b291c9336779482f9fcf9fa50d59d690f199 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 16:40:14 -0700 Subject: [PATCH 303/709] Do not doubly mark as federated. This is hacky. The problem is that the generated code does not have a federated reactor, but we do an AST transformation so that we can pretend that it is (I do not want to know why). So we end up running the code generator on a federated program, even though it is supposed to result on code for a single federate. So if the federate had its name prefixed once in the main run of the code generator, its name will be prefixed again in the nested run of the code generator. --- .../src/org/lflang/federated/generator/FedEmitter.java | 3 +-- .../org/lflang/federated/generator/FederateInstance.java | 7 +------ org.lflang/src/org/lflang/generator/ReactorInstance.java | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java index ee44002306..2c9f32aad8 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java @@ -74,7 +74,6 @@ Map generateFederate( } public static Path lfFilePath(FedFileConfig fileConfig, FederateInstance federate) { - return fileConfig.getSrcPath().resolve( - "__" + federate.name + ".lf"); + return fileConfig.getSrcPath().resolve(federate.name + ".lf"); } } diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 6dd7dc1de2..835ecca4dd 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -25,7 +25,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.federated.generator; -import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -40,17 +39,13 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.ASTUtils; import org.lflang.ErrorReporter; -import org.lflang.FileConfig; -import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TimeValue; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.ActionInstance; -import org.lflang.generator.GeneratorUtils; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.SubContext; import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -109,12 +104,12 @@ public FederateInstance( this.targetConfig = targetConfig; if (instantiation != null) { - this.name = "__" + instantiation.getName(); // If the instantiation is in a bank, then we have to append // the bank index to the name. if (instantiation.getWidthSpec() != null) { this.name = instantiation.getName() + "__" + bankIndex; } + name = "federate__" + name; } } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 92d7d9ea3d..20f9718aea 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -323,7 +323,7 @@ public String getName() { @Override public String uniqueID() { if (this.isMainOrFederated()) { - if (reactorDefinition.isFederated()) return "__" + super.uniqueID() + "_main"; + if (reactorDefinition.isFederated() && !super.uniqueID().startsWith("federate__")) return "federate__" + super.uniqueID() + "_main"; return super.uniqueID() + "_main"; } return super.uniqueID(); From d4968e8800258ea19b0377b4e80683a91369f02e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 16:53:35 -0700 Subject: [PATCH 304/709] More bugfixes. --- .../src/org/lflang/tests/compiler/TargetConfigTests.java | 2 +- .../src/org/lflang/federated/generator/FederateInstance.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java index 12b86996cb..eede6a6831 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java @@ -94,7 +94,7 @@ public void testFederation() throws Exception { generator.doGenerate(resource, fileAccess, context); String lfSrc = Files.readAllLines( - ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("__a.lf") + ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("federate__a.lf") ).stream().reduce("\n", String::concat); Model federate = parser.parse(lfSrc); assertHasTargetProperty(federate, "tracing"); diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 835ecca4dd..cdd64f03b2 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -107,9 +107,10 @@ public FederateInstance( // If the instantiation is in a bank, then we have to append // the bank index to the name. if (instantiation.getWidthSpec() != null) { - this.name = instantiation.getName() + "__" + bankIndex; + this.name = "federate__" + instantiation.getName() + "__" + bankIndex; + } else { + this.name = "federate__" + instantiation.getName(); } - name = "federate__" + name; } } From def5022b94e2f145eda84c9ba40acc3612fc9907 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Thu, 18 May 2023 10:00:07 +0200 Subject: [PATCH 305/709] Format test --- test/C/src/zephyr/UserThreads.lf | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/C/src/zephyr/UserThreads.lf b/test/C/src/zephyr/UserThreads.lf index 105da11d01..c16be556fc 100644 --- a/test/C/src/zephyr/UserThreads.lf +++ b/test/C/src/zephyr/UserThreads.lf @@ -1,18 +1,17 @@ -// Test user threads platform option for Zephyr. The application should be able +// Test user threads platform option for Zephyr. The application should be able // to create exactly three threads. target C { platform: { name: Zephyr, user-threads: 3 - }, - threading: true, - workers: 2, + }, + threading: true, + workers: 2 } main reactor { - preamble {= - void func() {} - =} + preamble {= void func() {} =} + reaction(startup) {= int res; int thread_id; @@ -31,4 +30,4 @@ main reactor { printf("SUCCESS: Created exactly three user threads.\n"); } =} -} \ No newline at end of file +} From 9e075e9456fcb179ad4f671646b2f32af1526b9e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 22:03:54 -0700 Subject: [PATCH 306/709] Delete unnecessary complexity from build-lf-cli. --- lib/scripts/build.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/scripts/build.sh b/lib/scripts/build.sh index d342aa45cd..52cc403851 100755 --- a/lib/scripts/build.sh +++ b/lib/scripts/build.sh @@ -114,18 +114,4 @@ if [ "${OSTYPE}" = "msys" ]; then fi jar_path="$(get_jar_path)" - -if [ ! -f "${jar_path}" ] || ! "${find_cmd}" "${base}" \ - -path "${src_pkg_path}" \ - -prune -o \ - -type f \ - -newer "${jar_path}" \ - -exec false {} +; then - # Rebuild. - 1>&2 echo "Jar file is missing or out-of-date; starting rebuild..." - "${base}/gradlew" ${flags} -p "${base}" buildAll - # Update the timestamp in case the jar was not touched by Gradle. - touch -c -- "${jar_path}" -else - echo "Already up-to-date." -fi +"${base}/gradlew" ${flags} -p "${base}" buildAll From 73c52a510a92c19de9485024d18573b57a17550a Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 17 May 2023 13:05:33 +0200 Subject: [PATCH 307/709] Mechanism for printing execution statistics This adds the `print-statistics` target property and pulls in https://github.com/lf-lang/reactor-cpp/pull/47. If `print-statistics` is true, the compiled program will print an output like the following when the program terminates. ``` [INFO] ----------------------------------------------------------- [INFO] Program statistics: [INFO] - number of reactors: 4 [INFO] - number of connections: 4 [INFO] - number of reactions 9 [INFO] - number of actions: 11 [INFO] - number of ports: 8 [INFO] Execution statistics: [INFO] - processed events: 12000015 [INFO] - triggered actions: 12000021 [INFO] - processed reactions: 36000039 [INFO] - set ports: 24000024 [INFO] - scheduled actions: 12000021 [INFO] ----------------------------------------------------------- ``` --- .../src/org/lflang/tests/cli/LfcCliTest.java | 3 +++ org.lflang/src/lib/cpp/reactor-cpp | 2 +- org.lflang/src/org/lflang/TargetConfig.java | 9 +++++++++ org.lflang/src/org/lflang/TargetProperty.java | 10 ++++++++++ org.lflang/src/org/lflang/cli/Lfc.java | 10 ++++++++++ .../src/org/lflang/generator/LFGeneratorContext.java | 4 +--- .../org/lflang/generator/cpp/CppStandaloneGenerator.kt | 1 + 7 files changed, 35 insertions(+), 4 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java index 7143ba9375..d16193faad 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java @@ -76,6 +76,7 @@ public class LfcCliTest { "logging": "info", "lint": true, "no-compile": true, + "print-statistics": true, "quiet": true, "rti": "path/to/rti", "runtime-version": "rs", @@ -228,6 +229,7 @@ public void verifyGeneratorArgs(Path tempDir, String[] args) { assertEquals(properties.getProperty(BuildParm.LOGGING.getKey()), "info"); assertEquals(properties.getProperty(BuildParm.LINT.getKey()), "true"); assertEquals(properties.getProperty(BuildParm.NO_COMPILE.getKey()), "true"); + assertEquals(properties.getProperty(BuildParm.PRINT_STATISTICS.getKey()), "true"); assertEquals(properties.getProperty(BuildParm.QUIET.getKey()), "true"); assertEquals(properties.getProperty(BuildParm.RTI.getKey()), "path" + File.separator + "to" + File.separator + "rti"); @@ -256,6 +258,7 @@ public void testGeneratorArgs(@TempDir Path tempDir) "--logging", "info", "--lint", "--no-compile", + "--print-statistics", "--quiet", "--rti", "path/to/rti", "--runtime-version", "rs", diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 9a7b0a91ad..a13eda638f 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 9a7b0a91ad72bbf87702f2392ed2bebba528e831 +Subproject commit a13eda638fd5a4a71c8d42ef5fa20ef692370f87 diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 845f214ec8..84770be5d1 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -40,6 +40,7 @@ import org.lflang.TargetProperty.Platform; import org.lflang.TargetProperty.SchedulerOption; import org.lflang.TargetProperty.UnionType; +import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.generator.rust.RustTargetConfig; import org.lflang.lf.KeyValuePair; import org.lflang.lf.TargetDecl; @@ -137,6 +138,9 @@ public TargetConfig( this.keepalive = Boolean.parseBoolean( cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); } + if (cliArgs.containsKey(BuildParm.PRINT_STATISTICS.getKey())) { + this.printStatistics = true; + } } /** @@ -269,6 +273,11 @@ public TargetConfig( */ public PlatformOptions platformOptions = new PlatformOptions(); + /** + * If true, instruct the runtime to collect and print execution statistics. + */ + public boolean printStatistics = false; + /** * List of proto files to be processed by the code generator. */ diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 61cda14431..25445a3e37 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -479,6 +479,16 @@ public enum TargetProperty { } }), + /** + * Directive to instruct the runtime to collect and print execution statistics. + */ + PRINT_STATISTICS("print-statistics", PrimitiveType.BOOLEAN, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.printStatistics), + (config, value, err) -> { + config.printStatistics = ASTUtils.toBoolean(value); + }), + /** * Directive for specifying .proto files that need to be compiled and their * code included in the sources. diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index f0e88aef93..eb67768beb 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -97,6 +97,12 @@ public class Lfc extends CliBase { description = "Do not invoke target compiler.") private boolean noCompile; + @Option( + names = {"--print-statistics"}, + arity = "0", + description = "Instruct the runtime to collect and print statistics.") + private boolean printStatistics; + @Option( names = {"-q", "--quiet"}, arity = "0", @@ -265,6 +271,10 @@ public Properties getGeneratorArgs() { props.setProperty(BuildParm.LOGGING.getKey(), logging); } + if(printStatistics) { + props.setProperty(BuildParm.PRINT_STATISTICS.getKey(), "true"); + } + if (noCompile) { props.setProperty(BuildParm.NO_COMPILE.getKey(), "true"); } diff --git a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java b/org.lflang/src/org/lflang/generator/LFGeneratorContext.java index 65ea702c39..5a5eddf178 100644 --- a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java +++ b/org.lflang/src/org/lflang/generator/LFGeneratorContext.java @@ -1,15 +1,12 @@ package org.lflang.generator; -import java.io.IOException; import java.nio.file.Path; import java.util.Map; -import java.util.Objects; import java.util.Properties; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.IFileSystemAccess2; import org.eclipse.xtext.generator.IGeneratorContext; -import org.eclipse.xtext.util.RuntimeIOException; import org.lflang.ErrorReporter; import org.lflang.FileConfig; @@ -37,6 +34,7 @@ enum BuildParm { LINT("Enable or disable linting of generated code."), NO_COMPILE("Do not invoke target compiler."), OUTPUT_PATH("Specify the root output directory."), + PRINT_STATISTICS("Instruct the runtime to collect and print statistics."), QUIET("Suppress output of the target compiler and other commands"), RTI("Specify the location of the RTI."), RUNTIME_VERSION("Specify the version of the runtime library used for compiling LF programs."), diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneGenerator.kt index bd4b58f3cd..f307559d9e 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneGenerator.kt @@ -165,6 +165,7 @@ class CppStandaloneGenerator(generator: CppGenerator) : "-DCMAKE_INSTALL_PREFIX=${outPath.toUnixString()}", "-DCMAKE_INSTALL_BINDIR=${outPath.relativize(fileConfig.binPath).toUnixString()}", "-DREACTOR_CPP_VALIDATE=${if (targetConfig.noRuntimeValidation) "OFF" else "ON"}", + "-DREACTOR_CPP_PRINT_STATISTICS=${if (targetConfig.printStatistics) "ON" else "OFF"}", "-DREACTOR_CPP_TRACE=${if (targetConfig.tracing != null) "ON" else "OFF"}", "-DREACTOR_CPP_LOG_LEVEL=${targetConfig.logLevel.severity}", "-DLF_SRC_PKG_PATH=${fileConfig.srcPkgPath}", From 917ea837ea3be135c132c53f5453797807fcfb81 Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Thu, 18 May 2023 10:57:18 +0200 Subject: [PATCH 308/709] Fix always getting user thread warning --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 4215f015fa..a5dc78c2b0 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1942,7 +1942,7 @@ protected void setUpGeneralParameters() { ); } - if (targetConfig.platformOptions.platform != Platform.ZEPHYR && targetConfig.platformOptions.userThreads >= 0) { + if (targetConfig.platformOptions.platform != Platform.ZEPHYR && targetConfig.platformOptions.userThreads > 0) { errorReporter.reportWarning("Specifying user threads is only for the Zephyr platform. This option will be ignored."); } if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake From 2ef47cd3b82d9c99d2185d30f301bdb4d738070c Mon Sep 17 00:00:00 2001 From: erling Date: Thu, 18 May 2023 12:07:09 -0700 Subject: [PATCH 309/709] Zephyr CI fix (#1740) Fix current test failure in master. --- .github/actions/setup-zephyr/action.yml | 34 +++++++++++++++++++++++++ .github/workflows/c-zephyr-tests.yml | 22 ++-------------- 2 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 .github/actions/setup-zephyr/action.yml diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml new file mode 100644 index 0000000000..64d85ec0f2 --- /dev/null +++ b/.github/actions/setup-zephyr/action.yml @@ -0,0 +1,34 @@ +name: Install Zephyr and dependencies (Linux only) +description: Install Zephyr and dependencies (Linux only) +runs: + using: "composite" + steps: + - name: Dependencies + run: | + sudo apt install -y --no-install-recommends git cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler wget \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 + shell: bash + - name: Install West + run: pip install west + shell: bash + - name: Install Zephyr SDK + run : | + wget -q https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing + sudo tar xf zephyr-sdk-0.15.2_linux-x86_64.tar.gz --directory /opt/ + cd /opt/zephyr-sdk-0.15.2 + sudo ./setup.sh -t all -h -c + shell: bash + - name: Download and install Zephyr RTOS + run: | + cd $HOME + west init zephyrproject --mr v3.2.0 + cd zephyrproject + west update + west zephyr-export + pip install -r zephyr/scripts/requirements.txt + echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-0.15.2/" >> $GITHUB_ENV + shell: bash \ No newline at end of file diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 8af72a2f39..3b7a76feee 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -20,23 +20,7 @@ on: jobs: run: runs-on: ubuntu-latest - container: - image: zephyrprojectrtos/zephyr-build:v0.24.13 - options: -u root --entrypoint /bin/sh steps: - - name: Install Java 17, Maven and set JAVA_HOME - run: | - sudo apt-get update - sudo apt-get install -y openjdk-17-jdk - sudo apt-get install -y maven - echo "JAVA_HOME_17_X64=/usr/lib/jvm/java-17-openjdk-amd64" >> $GITHUB_ENV - - name: Initialize zephyr - run: | - west init /workdir/zephyrproject --mr v3.2.0 - cd /workdir/zephyrproject - west update - echo "ZEPHYR_BASE=/workdir/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.15.2/" >> $GITHUB_ENV - name: Check out lingua-franca repository uses: actions/checkout@v3 with: @@ -44,12 +28,10 @@ jobs: submodules: true ref: ${{ inputs.compiler-ref }} fetch-depth: 0 - - name: Try to get around git safe issues - run: | - git config --global --add safe.directory '/__w/lingua-franca/lingua-franca' - git config --global --add safe.directory '/__w/reactor-c/reactor-c' - name: Prepare build environment uses: ./.github/actions/prepare-build-env + - name: Setup Zephyr + uses: ./.github/actions/setup-zephyr - name: Check out specific ref of reactor-c uses: actions/checkout@v3 with: From 68afbc24bed2f11995ff32de8e550a08b19c3feb Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 18 May 2023 16:51:13 -0700 Subject: [PATCH 310/709] Address remaining FIXME to include errorReporter --- .../org/lflang/generator/c/CGenerator.java | 2 +- .../generator/c/CWatchdogGenerator.java | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e5e27c952a..32174be22c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1067,7 +1067,7 @@ private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeB var constructorCode = new CodeBuilder(); generateAuxiliaryStructs(header, reactor, false); // The following must go before the self struct so the #include watchdog.h ends up in the header. - CWatchdogGenerator.generateWatchdogs(src, header, reactor); + CWatchdogGenerator.generateWatchdogs(src, header, reactor, errorReporter); generateSelfStruct(header, reactor, constructorCode); generateMethods(src, reactor); generateReactions(src, reactor); diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 28d9223ea8..9ab15ea98e 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -10,6 +10,7 @@ import java.util.List; import org.lflang.ASTUtils; +import org.lflang.ErrorReporter; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Mode; @@ -91,12 +92,14 @@ protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstan * @param header The place to put header code * @param decl The reactor declaration */ - protected static void generateWatchdogs(CodeBuilder src, CodeBuilder header, ReactorDecl decl) { + protected static void generateWatchdogs( + CodeBuilder src, CodeBuilder header, ReactorDecl decl, ErrorReporter errorReporter + ) { var reactor = ASTUtils.toDefinition(decl); if (hasWatchdogs(reactor)) { header.pr("#include \"core/threaded/watchdog.h\""); for (Watchdog watchdog : ASTUtils.allWatchdogs(reactor)) { - src.pr(generateWatchdogFunction(watchdog, decl)); + src.pr(generateWatchdogFunction(watchdog, decl, errorReporter)); } } } @@ -174,7 +177,11 @@ protected static String generateWatchdogTable(int count) { * @param watchdog The wotchdog * @param decl The declaration for the reactor that has the watchdog */ - private static String generateInitializationForWatchdog(Watchdog watchdog, ReactorDecl decl) { + private static String generateInitializationForWatchdog( + Watchdog watchdog, + ReactorDecl decl, + ErrorReporter errorReporter + ) { Reactor reactor = ASTUtils.toDefinition(decl); // Construct the reactionInitialization code to go into @@ -219,14 +226,12 @@ private static String generateInitializationForWatchdog(Watchdog watchdog, React ? "history_transition" : "reset_transition") + ";"); + } else { + errorReporter.reportError( + watchdog, + "In generateInitializationForWatchdog(): " + name + " not a valid mode of this reactor." + ); } - // FIXME: include error reporter - // else { - // errorReporter.reportError( - // watchdog, - // "In generateWatchdog(): " + name + " not a valid mode of this reactor." - // ); - // } } } } @@ -265,10 +270,12 @@ private static String generateFunction(String header, String init, Watchdog watc /** Generate the watchdog handler function. */ - private static String generateWatchdogFunction(Watchdog watchdog, ReactorDecl decl) { + private static String generateWatchdogFunction( + Watchdog watchdog, ReactorDecl decl, ErrorReporter errorReporter + ) { return generateFunction( generateWatchdogFunctionHeader(watchdog, decl), - generateInitializationForWatchdog(watchdog, decl), + generateInitializationForWatchdog(watchdog, decl, errorReporter), watchdog); } From 31d4b4dd2b3f86b8f51971b5a742d942a2134556 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 18 May 2023 16:53:48 -0700 Subject: [PATCH 311/709] Align to reactor-c main --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c2c6a54fa0..843e147128 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c2c6a54fa023c638122a73a7c7f311cf381cea1e +Subproject commit 843e147128315ffa5216fffd6cba36396c3cd084 From f0174827cc2cf92f322487b096f07a497ff23b5a Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Fri, 19 May 2023 09:33:30 +0200 Subject: [PATCH 312/709] Add threading check to validation of property --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index a5dc78c2b0..371581331b 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1935,16 +1935,16 @@ protected void setUpGeneralParameters() { targetConfig.noCompile = true; } - if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.platformOptions.userThreads >= 0) { + if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.threading + && targetConfig.platformOptions.userThreads >= 0) { targetConfig.compileDefinitions.put( PlatformOption.USER_THREADS.name(), String.valueOf(targetConfig.platformOptions.userThreads) ); + } else if (targetConfig.platformOptions.userThreads > 0) { + errorReporter.reportWarning("Specifying user threads is only for threaded Lingua Franca on the Zephyr platform. This option will be ignored."); } - if (targetConfig.platformOptions.platform != Platform.ZEPHYR && targetConfig.platformOptions.userThreads > 0) { - errorReporter.reportWarning("Specifying user threads is only for the Zephyr platform. This option will be ignored."); } - if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake pickScheduler(); // FIXME: this and pickScheduler should be combined. From 69258c4aada5669e1205d74a22bbc339c3b1c7fc Mon Sep 17 00:00:00 2001 From: Silje Susort Date: Fri, 19 May 2023 09:35:28 +0200 Subject: [PATCH 313/709] Add threaded Zephyr test functionality --- .../src/org/lflang/tests/Configurators.java | 11 ++++++++++- .../src/org/lflang/tests/runtime/CZephyrTest.java | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index e3fe6c5508..eaf7001f8c 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -65,7 +65,7 @@ public static boolean disableThreading(LFTest test) { return true; } - public static boolean makeZephyrCompatible(LFTest test) { + public static boolean makeZephyrCompatibleUnthreaded(LFTest test) { test.getContext().getArgs().setProperty("tracing", "false"); test.getContext().getTargetConfig().threading = false; test.getContext().getTargetConfig().setByUser.add(TargetProperty.THREADING); @@ -74,6 +74,15 @@ public static boolean makeZephyrCompatible(LFTest test) { test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; return true; } + + public static boolean makeZephyrCompatible(LFTest test) { + test.getContext().getArgs().setProperty("tracing", "false"); + test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; + test.getContext().getTargetConfig().platformOptions.flash = false; + test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + return true; + } + /** * Make no changes to the configuration. * diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index afe1646829..c1e2e5e3f5 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -62,7 +62,7 @@ public void buildGenericTests() { super.runTestsFor(List.of(Target.C), Message.DESC_GENERIC, TestCategory.GENERIC::equals, - Configurators::makeZephyrCompatible, + Configurators::makeZephyrCompatibleUnthreaded, TestLevel.BUILD, false); } From c8d7bb52cdabcc780ca4430701f2656945f92d2e Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Fri, 19 May 2023 16:56:20 +0900 Subject: [PATCH 314/709] Exit with 1 if the RTI is not installed --- .../org/lflang/federated/launcher/FedLauncherGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 3ad08e2450..d5873c1e05 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -342,7 +342,7 @@ private String getLaunchCode(String rtiLaunchCode) { "then", " echo \"RTI could not be found.\"", " echo \"The source code can be obtained from https://github.com/lf-lang/reactor-c/tree/main/core/federated/RTI\"", - " exit", + " exit 1", "fi ", "# The RTI is started first to allow proper boot-up", "# before federates will try to connect.", @@ -375,7 +375,7 @@ private String getRemoteLaunchCode(Object host, Object target, String logFileNam " then", " echo \"RTI could not be found.\"", " echo \"The source code can be found in org.lflang/src/lib/core/federated/RTI\"", - " exit", + " exit 1", " fi", " " + rtiLaunchString + " 2>&1 | tee -a " + logFileName + "' &", "# Store the PID of the channel to RTI", From ba3a8bc492b63ed1507366bc525247ade2223bdf Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Fri, 19 May 2023 17:05:19 +0900 Subject: [PATCH 315/709] Move failed tests to the failing folder --- test/TypeScript/src/federated/{ => failing}/ChainWithDelay.lf | 0 test/TypeScript/src/federated/{ => failing}/DistributedCount.lf | 0 .../src/federated/{ => failing}/DistributedCountPhysical.lf | 0 .../federated/{ => failing}/DistributedCountPhysicalAfterDelay.lf | 0 .../src/federated/{ => failing}/DistributedDoublePort.lf | 0 .../src/federated/{ => failing}/DistributedLoopedAction.lf | 0 .../federated/{ => failing}/DistributedLoopedPhysicalAction.lf | 0 test/TypeScript/src/federated/{ => failing}/DistributedStop.lf | 0 .../TypeScript/src/federated/{ => failing}/DistributedStopZero.lf | 0 test/TypeScript/src/federated/{ => failing}/HelloDistributed.lf | 0 .../src/federated/{ => failing}/LoopDistributedCentralized.lf | 0 .../src/federated/{ => failing}/LoopDistributedDouble.lf | 0 .../TypeScript/src/federated/{ => failing}/PingPongDistributed.lf | 0 .../src/federated/{ => failing}/PingPongDistributedPhysical.lf | 0 test/TypeScript/src/federated/{ => failing}/SimpleFederated.lf | 0 test/TypeScript/src/federated/{ => failing}/StopAtShutdown.lf | 0 test/TypeScript/src/federated/{ => failing}/TopLevelArtifacts.lf | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename test/TypeScript/src/federated/{ => failing}/ChainWithDelay.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedCount.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedCountPhysical.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedCountPhysicalAfterDelay.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedDoublePort.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedLoopedAction.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedLoopedPhysicalAction.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedStop.lf (100%) rename test/TypeScript/src/federated/{ => failing}/DistributedStopZero.lf (100%) rename test/TypeScript/src/federated/{ => failing}/HelloDistributed.lf (100%) rename test/TypeScript/src/federated/{ => failing}/LoopDistributedCentralized.lf (100%) rename test/TypeScript/src/federated/{ => failing}/LoopDistributedDouble.lf (100%) rename test/TypeScript/src/federated/{ => failing}/PingPongDistributed.lf (100%) rename test/TypeScript/src/federated/{ => failing}/PingPongDistributedPhysical.lf (100%) rename test/TypeScript/src/federated/{ => failing}/SimpleFederated.lf (100%) rename test/TypeScript/src/federated/{ => failing}/StopAtShutdown.lf (100%) rename test/TypeScript/src/federated/{ => failing}/TopLevelArtifacts.lf (100%) diff --git a/test/TypeScript/src/federated/ChainWithDelay.lf b/test/TypeScript/src/federated/failing/ChainWithDelay.lf similarity index 100% rename from test/TypeScript/src/federated/ChainWithDelay.lf rename to test/TypeScript/src/federated/failing/ChainWithDelay.lf diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/failing/DistributedCount.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedCount.lf rename to test/TypeScript/src/federated/failing/DistributedCount.lf diff --git a/test/TypeScript/src/federated/DistributedCountPhysical.lf b/test/TypeScript/src/federated/failing/DistributedCountPhysical.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedCountPhysical.lf rename to test/TypeScript/src/federated/failing/DistributedCountPhysical.lf diff --git a/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf rename to test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf diff --git a/test/TypeScript/src/federated/DistributedDoublePort.lf b/test/TypeScript/src/federated/failing/DistributedDoublePort.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedDoublePort.lf rename to test/TypeScript/src/federated/failing/DistributedDoublePort.lf diff --git a/test/TypeScript/src/federated/DistributedLoopedAction.lf b/test/TypeScript/src/federated/failing/DistributedLoopedAction.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedLoopedAction.lf rename to test/TypeScript/src/federated/failing/DistributedLoopedAction.lf diff --git a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf b/test/TypeScript/src/federated/failing/DistributedLoopedPhysicalAction.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf rename to test/TypeScript/src/federated/failing/DistributedLoopedPhysicalAction.lf diff --git a/test/TypeScript/src/federated/DistributedStop.lf b/test/TypeScript/src/federated/failing/DistributedStop.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedStop.lf rename to test/TypeScript/src/federated/failing/DistributedStop.lf diff --git a/test/TypeScript/src/federated/DistributedStopZero.lf b/test/TypeScript/src/federated/failing/DistributedStopZero.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedStopZero.lf rename to test/TypeScript/src/federated/failing/DistributedStopZero.lf diff --git a/test/TypeScript/src/federated/HelloDistributed.lf b/test/TypeScript/src/federated/failing/HelloDistributed.lf similarity index 100% rename from test/TypeScript/src/federated/HelloDistributed.lf rename to test/TypeScript/src/federated/failing/HelloDistributed.lf diff --git a/test/TypeScript/src/federated/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf similarity index 100% rename from test/TypeScript/src/federated/LoopDistributedCentralized.lf rename to test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/failing/LoopDistributedDouble.lf similarity index 100% rename from test/TypeScript/src/federated/LoopDistributedDouble.lf rename to test/TypeScript/src/federated/failing/LoopDistributedDouble.lf diff --git a/test/TypeScript/src/federated/PingPongDistributed.lf b/test/TypeScript/src/federated/failing/PingPongDistributed.lf similarity index 100% rename from test/TypeScript/src/federated/PingPongDistributed.lf rename to test/TypeScript/src/federated/failing/PingPongDistributed.lf diff --git a/test/TypeScript/src/federated/PingPongDistributedPhysical.lf b/test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf similarity index 100% rename from test/TypeScript/src/federated/PingPongDistributedPhysical.lf rename to test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf diff --git a/test/TypeScript/src/federated/SimpleFederated.lf b/test/TypeScript/src/federated/failing/SimpleFederated.lf similarity index 100% rename from test/TypeScript/src/federated/SimpleFederated.lf rename to test/TypeScript/src/federated/failing/SimpleFederated.lf diff --git a/test/TypeScript/src/federated/StopAtShutdown.lf b/test/TypeScript/src/federated/failing/StopAtShutdown.lf similarity index 100% rename from test/TypeScript/src/federated/StopAtShutdown.lf rename to test/TypeScript/src/federated/failing/StopAtShutdown.lf diff --git a/test/TypeScript/src/federated/TopLevelArtifacts.lf b/test/TypeScript/src/federated/failing/TopLevelArtifacts.lf similarity index 100% rename from test/TypeScript/src/federated/TopLevelArtifacts.lf rename to test/TypeScript/src/federated/failing/TopLevelArtifacts.lf From 67def09df97d649ee1ca7c77f4657678bf6030d1 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Fri, 19 May 2023 17:54:06 +0900 Subject: [PATCH 316/709] Make the CI installs the RTI while tests reactor-ts --- .github/workflows/ts-tests.yml | 3 +++ test/TypeScript/src/federated/{failing => }/ChainWithDelay.lf | 0 .../TypeScript/src/federated/{failing => }/DistributedCount.lf | 0 .../src/federated/{failing => }/DistributedCountPhysical.lf | 0 .../{failing => }/DistributedCountPhysicalAfterDelay.lf | 0 .../src/federated/{failing => }/DistributedDoublePort.lf | 0 .../src/federated/{failing => }/DistributedLoopedAction.lf | 0 .../federated/{failing => }/DistributedLoopedPhysicalAction.lf | 0 test/TypeScript/src/federated/{failing => }/DistributedStop.lf | 0 .../src/federated/{failing => }/DistributedStopZero.lf | 0 .../TypeScript/src/federated/{failing => }/HelloDistributed.lf | 0 .../src/federated/{failing => }/LoopDistributedCentralized.lf | 0 .../src/federated/{failing => }/LoopDistributedDouble.lf | 0 .../src/federated/{failing => }/PingPongDistributed.lf | 0 .../src/federated/{failing => }/PingPongDistributedPhysical.lf | 0 test/TypeScript/src/federated/{failing => }/SimpleFederated.lf | 0 test/TypeScript/src/federated/{failing => }/StopAtShutdown.lf | 0 .../src/federated/{failing => }/TopLevelArtifacts.lf | 0 18 files changed, 3 insertions(+) rename test/TypeScript/src/federated/{failing => }/ChainWithDelay.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedCount.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedCountPhysical.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedCountPhysicalAfterDelay.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedDoublePort.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedLoopedAction.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedLoopedPhysicalAction.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedStop.lf (100%) rename test/TypeScript/src/federated/{failing => }/DistributedStopZero.lf (100%) rename test/TypeScript/src/federated/{failing => }/HelloDistributed.lf (100%) rename test/TypeScript/src/federated/{failing => }/LoopDistributedCentralized.lf (100%) rename test/TypeScript/src/federated/{failing => }/LoopDistributedDouble.lf (100%) rename test/TypeScript/src/federated/{failing => }/PingPongDistributed.lf (100%) rename test/TypeScript/src/federated/{failing => }/PingPongDistributedPhysical.lf (100%) rename test/TypeScript/src/federated/{failing => }/SimpleFederated.lf (100%) rename test/TypeScript/src/federated/{failing => }/StopAtShutdown.lf (100%) rename test/TypeScript/src/federated/{failing => }/TopLevelArtifacts.lf (100%) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 83c04d8cf7..7a49192c14 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -26,6 +26,9 @@ jobs: run: | brew install coreutils if: ${{ runner.os == 'macOS' }} + - name: Install RTI + uses: ./.github/actions/install-rti + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform TypeScript tests run: | ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" diff --git a/test/TypeScript/src/federated/failing/ChainWithDelay.lf b/test/TypeScript/src/federated/ChainWithDelay.lf similarity index 100% rename from test/TypeScript/src/federated/failing/ChainWithDelay.lf rename to test/TypeScript/src/federated/ChainWithDelay.lf diff --git a/test/TypeScript/src/federated/failing/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedCount.lf rename to test/TypeScript/src/federated/DistributedCount.lf diff --git a/test/TypeScript/src/federated/failing/DistributedCountPhysical.lf b/test/TypeScript/src/federated/DistributedCountPhysical.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedCountPhysical.lf rename to test/TypeScript/src/federated/DistributedCountPhysical.lf diff --git a/test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf rename to test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf diff --git a/test/TypeScript/src/federated/failing/DistributedDoublePort.lf b/test/TypeScript/src/federated/DistributedDoublePort.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedDoublePort.lf rename to test/TypeScript/src/federated/DistributedDoublePort.lf diff --git a/test/TypeScript/src/federated/failing/DistributedLoopedAction.lf b/test/TypeScript/src/federated/DistributedLoopedAction.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedLoopedAction.lf rename to test/TypeScript/src/federated/DistributedLoopedAction.lf diff --git a/test/TypeScript/src/federated/failing/DistributedLoopedPhysicalAction.lf b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedLoopedPhysicalAction.lf rename to test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf diff --git a/test/TypeScript/src/federated/failing/DistributedStop.lf b/test/TypeScript/src/federated/DistributedStop.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedStop.lf rename to test/TypeScript/src/federated/DistributedStop.lf diff --git a/test/TypeScript/src/federated/failing/DistributedStopZero.lf b/test/TypeScript/src/federated/DistributedStopZero.lf similarity index 100% rename from test/TypeScript/src/federated/failing/DistributedStopZero.lf rename to test/TypeScript/src/federated/DistributedStopZero.lf diff --git a/test/TypeScript/src/federated/failing/HelloDistributed.lf b/test/TypeScript/src/federated/HelloDistributed.lf similarity index 100% rename from test/TypeScript/src/federated/failing/HelloDistributed.lf rename to test/TypeScript/src/federated/HelloDistributed.lf diff --git a/test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/LoopDistributedCentralized.lf similarity index 100% rename from test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf rename to test/TypeScript/src/federated/LoopDistributedCentralized.lf diff --git a/test/TypeScript/src/federated/failing/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf similarity index 100% rename from test/TypeScript/src/federated/failing/LoopDistributedDouble.lf rename to test/TypeScript/src/federated/LoopDistributedDouble.lf diff --git a/test/TypeScript/src/federated/failing/PingPongDistributed.lf b/test/TypeScript/src/federated/PingPongDistributed.lf similarity index 100% rename from test/TypeScript/src/federated/failing/PingPongDistributed.lf rename to test/TypeScript/src/federated/PingPongDistributed.lf diff --git a/test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf b/test/TypeScript/src/federated/PingPongDistributedPhysical.lf similarity index 100% rename from test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf rename to test/TypeScript/src/federated/PingPongDistributedPhysical.lf diff --git a/test/TypeScript/src/federated/failing/SimpleFederated.lf b/test/TypeScript/src/federated/SimpleFederated.lf similarity index 100% rename from test/TypeScript/src/federated/failing/SimpleFederated.lf rename to test/TypeScript/src/federated/SimpleFederated.lf diff --git a/test/TypeScript/src/federated/failing/StopAtShutdown.lf b/test/TypeScript/src/federated/StopAtShutdown.lf similarity index 100% rename from test/TypeScript/src/federated/failing/StopAtShutdown.lf rename to test/TypeScript/src/federated/StopAtShutdown.lf diff --git a/test/TypeScript/src/federated/failing/TopLevelArtifacts.lf b/test/TypeScript/src/federated/TopLevelArtifacts.lf similarity index 100% rename from test/TypeScript/src/federated/failing/TopLevelArtifacts.lf rename to test/TypeScript/src/federated/TopLevelArtifacts.lf From c461cd70c531d7510769187651d9cb51af43c424 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 22:03:54 -0700 Subject: [PATCH 317/709] Delete unnecessary complexity from build-lf-cli. --- lib/scripts/build.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/scripts/build.sh b/lib/scripts/build.sh index d342aa45cd..52cc403851 100755 --- a/lib/scripts/build.sh +++ b/lib/scripts/build.sh @@ -114,18 +114,4 @@ if [ "${OSTYPE}" = "msys" ]; then fi jar_path="$(get_jar_path)" - -if [ ! -f "${jar_path}" ] || ! "${find_cmd}" "${base}" \ - -path "${src_pkg_path}" \ - -prune -o \ - -type f \ - -newer "${jar_path}" \ - -exec false {} +; then - # Rebuild. - 1>&2 echo "Jar file is missing or out-of-date; starting rebuild..." - "${base}/gradlew" ${flags} -p "${base}" buildAll - # Update the timestamp in case the jar was not touched by Gradle. - touch -c -- "${jar_path}" -else - echo "Already up-to-date." -fi +"${base}/gradlew" ${flags} -p "${base}" buildAll From 4fac0fe10d7383c2f988f51cda469ff9953439a8 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 12:53:40 -0700 Subject: [PATCH 318/709] More cleanups after merge. --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.java | 2 +- .../generator/c/CReactorHeaderFileGenerator.java | 11 ++--------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 04193a7d9c..f1d41011e4 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 04193a7d9cf2e6b39aab652bef47ce583a84be2c +Subproject commit f1d41011e454a026741beb68bd9a3ec80101c8ee diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 80031c4cd9..be689cecd7 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1069,7 +1069,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("}"); header.pr("}"); } - src.pr("#include \"include/" + headerName + "\""); + src.pr("#include \"" + headerName + "\""); tpr.typeArgs().forEach((literal, concreteType) -> src.pr( "#if defined " + literal + "\n" + "#undef " + literal + "\n" + diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index cf9f719967..33f652a8a4 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -94,8 +94,8 @@ private static void appendSignature(CodeBuilder builder, CTypes types, Reaction } private static String reactionParameters(CTypes types, Reaction r, TypeParameterizedReactor tpr) { - return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), inputVarRefStream(r) - .map(tv -> tpr.getName().toLowerCase() + "_" + tv.getVariable().getName() + "_t* " + tv.getVariable().getName())) + return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), portVariableStream(r, tpr) + .map(tv -> tpr.getName().toLowerCase() + "_" + tv.getName() + "_t* " + tv.getName())) .collect(Collectors.joining(", ")); } @@ -109,13 +109,6 @@ private static String getApiSelfStruct(TypeParameterizedReactor tpr) { return "(" + userFacingSelfType(tpr) + "*) (((char*) self) + sizeof(self_base_t))"; } - /** Return a string representation of the parameters of the reaction function of {@code r}. */ - private static String reactionParameters(Reaction r, TypeParameterizedReactor tpr) { - return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), portVariableStream(r, tpr) - .map(it -> it.getType(true) + " " + it.getName())) - .collect(Collectors.joining(", ")); - } - /** Generate initialization code that is needed if {@code r} is not inlined. */ public static String nonInlineInitialization(Reaction r, TypeParameterizedReactor reactor) { var mainDef = LfFactory.eINSTANCE.createInstantiation(); From 172b01fc6487954643ac12d17bee743de1195be0 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 13:02:04 -0700 Subject: [PATCH 319/709] Add back missing include. I'm not sure how this one disappeared from this branch, but it is in master already. --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index be689cecd7..a3bb69a702 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1069,6 +1069,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("}"); header.pr("}"); } + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); src.pr("#include \"" + headerName + "\""); tpr.typeArgs().forEach((literal, concreteType) -> src.pr( "#if defined " + literal + "\n" + From c56adefae298898c39a80d95e8730d819f905b6f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 13:58:05 -0700 Subject: [PATCH 320/709] Don't make ReactorInstance from insufficient data. --- org.lflang/src/org/lflang/ASTUtils.java | 9 --------- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index c138aba4f5..d1fdb1b34d 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -419,15 +419,6 @@ public static HashSet allIncludes(Reactor r) { return set; } - public static List allChildInstances(Reactor definition, ErrorReporter reporter) { - return allInstantiations(definition).stream().map(it -> new ReactorInstance( - it, - null, - reporter, - 0 - )).collect(Collectors.toList()); - } - /* * Given a reactor class, return a stream of reactor classes that it instantiates. * @param definition Reactor class definition. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index a3bb69a702..ffacf25e99 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -913,8 +913,8 @@ private void generateHeaders() throws IOException { (builder, rr, userFacing) -> { generateAuxiliaryStructs(builder, tpr, userFacing); if (userFacing) { - ASTUtils.allChildInstances(tpr.r(), errorReporter).stream() - .map(it -> new TypeParameterizedReactorWithDecl(it.tpr, it.reactorDeclaration)).collect(Collectors.toSet()).forEach(it -> { + tpr.r().getInstantiations().stream() + .map(it -> new TypeParameterizedReactorWithDecl(new TypeParameterizedReactor(it), it.getReactorClass())).collect(Collectors.toSet()).forEach(it -> { ASTUtils.allPorts(it.tpr.r()) .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( it.tpr, p, getTarget(), errorReporter, types, new CodeBuilder(), true, it.decl() From ec41b353f75e20e32025ccca7075dd2093c2d3e9 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 13:58:56 -0700 Subject: [PATCH 321/709] Self struct members are named after instance vars. Not after reactor classes. --- .../org/lflang/generator/c/CGenerator.java | 10 +++---- .../generator/c/CReactionGenerator.java | 26 +++++++++---------- .../src/org/lflang/generator/c/CUtil.java | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index ffacf25e99..c1d227087f 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1282,7 +1282,7 @@ private void generateInteractingContainedReactors( constructorCode.pr(String.join("\n", "// Set the _width variable for all cases. This will be -2", "// if the reactor is not a bank of reactors.", - "self->_lf_"+containedReactorType.tpr.getName()+"_width = "+width+";" + "self->_lf_"+containedReactor.getName()+"_width = "+width+";" )); // Generate one struct for each contained reactor that interacts. @@ -1323,10 +1323,10 @@ private void generateInteractingContainedReactors( var reactorIndex = ""; if (containedReactor.getWidthSpec() != null) { reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactorType.tpr.getName()+"_width; reactor_index++) {"); + constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); constructorCode.indent(); } - var portOnSelf = "self->_lf_"+containedReactorType.tpr.getName()+reactorIndex+"."+port.getName(); + var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); constructorCode.pr( port, @@ -1371,8 +1371,8 @@ private void generateInteractingContainedReactors( } body.unindent(); body.pr(String.join("\n", - "} _lf_"+containedReactorType.tpr.getName()+array+";", - "int _lf_"+containedReactorType.tpr.getName()+"_width;" + "} _lf_"+containedReactor.getName()+array+";", + "int _lf_"+containedReactor.getName()+"_width;" )); } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index a3da1f8462..2b7b08790b 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -208,7 +208,7 @@ public static String generateInitializationForReaction(String body, var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass()), containedReactor.getName()); String array = ""; if (containedReactor.getWidthSpec() != null) { - String containedReactorWidthVar = generateWidthVariable(containedReactorType.tpr.getName()); + String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); // Windows does not support variables in arrays declared on the stack, // so we use the maximum size over all bank members. @@ -356,7 +356,6 @@ private static void generateVariablesForSendingToContainedReactors( var reactorInstance = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), definition.getName()); String inputStructType = CGenerator.variableStructType(input, reactorInstance.tpr, false); String defName = reactorInstance.getName(); - String subName = reactorInstance.tpr.getName(); String defWidth = generateWidthVariable(defName); String inputName = input.getName(); String inputWidth = generateWidthVariable(inputName); @@ -367,12 +366,12 @@ private static void generateVariablesForSendingToContainedReactors( // Contained reactor is a bank. builder.pr(String.join("\n", "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", - " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+subName+"[bankIndex]."+inputName+");", + " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", "}" )); } else { // Contained reactor is not a bank. - builder.pr(defName+"."+inputName+" = &(self->_lf_"+subName+"."+inputName+");"); + builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); } } else { // Contained reactor's input is a multiport. @@ -385,14 +384,14 @@ private static void generateVariablesForSendingToContainedReactors( if (definition.getWidthSpec() != null) { builder.pr(String.join("\n", "for (int _i = 0; _i < self->_lf_"+defWidth+"; _i++) {", - " "+defName+"[_i]."+inputName+" = self->_lf_"+subName+"[_i]."+inputName+";", - " "+defName+"[_i]."+inputWidth+" = self->_lf_"+subName+"[_i]."+inputWidth+";", + " "+defName+"[_i]."+inputName+" = self->_lf_"+defName+"[_i]."+inputName+";", + " "+defName+"[_i]."+inputWidth+" = self->_lf_"+defName+"[_i]."+inputWidth+";", "}" )); } else { builder.pr(String.join("\n", - defName+"."+inputName+" = self->_lf_"+subName+"."+inputName+";", - defName+"."+inputWidth+" = self->_lf_"+subName+"."+inputWidth+";" + defName+"."+inputName+" = self->_lf_"+defName+"."+inputName+";", + defName+"."+inputWidth+" = self->_lf_"+defName+"."+inputWidth+";" )); } } @@ -429,9 +428,8 @@ private static void generatePortVariablesInReaction( structBuilder = new CodeBuilder(); structs.put(port.getContainer(), structBuilder); } - String reactorName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).tpr.getName(); String subName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).getName(); - String reactorWidth = generateWidthVariable(reactorName); + String reactorWidth = generateWidthVariable(subName); String outputName = output.getName(); String outputWidth = generateWidthVariable(outputName); // First define the struct containing the output value and indicator @@ -452,21 +450,21 @@ private static void generatePortVariablesInReaction( // Output is in a bank. builder.pr(String.join("\n", "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+subName+"[i]."+outputName+" = self->_lf_"+reactorName+"[i]."+outputName+";", + " "+subName+"[i]."+outputName+" = self->_lf_"+subName+"[i]."+outputName+";", "}" )); if (ASTUtils.isMultiport(output)) { builder.pr(String.join("\n", "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+subName+"[i]."+outputWidth+" = self->_lf_"+reactorName+"[i]."+outputWidth+";", + " "+subName+"[i]."+outputWidth+" = self->_lf_"+subName+"[i]."+outputWidth+";", "}" )); } } else { // Output is not in a bank. - builder.pr(subName+"."+outputName+" = self->_lf_"+reactorName+"."+outputName+";"); + builder.pr(subName+"."+outputName+" = self->_lf_"+subName+"."+outputName+";"); if (ASTUtils.isMultiport(output)) { - builder.pr(subName+"."+outputWidth+" = self->_lf_"+reactorName+"."+outputWidth+";"); + builder.pr(subName+"."+outputWidth+" = self->_lf_"+subName+"."+outputWidth+";"); } } } diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index bfa1a1b712..e06fcdfc3f 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -456,7 +456,7 @@ public static String reactorRefNested(ReactorInstance reactor) { * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. */ public static String reactorRefNested(ReactorInstance reactor, String runtimeIndex, String bankIndex) { - String result = reactorRef(reactor.getParent(), runtimeIndex) + "->_lf_" + reactor.tpr.getName(); + String result = reactorRef(reactor.getParent(), runtimeIndex) + "->_lf_" + reactor.getName(); if (reactor.isBank()) { // Need the bank index not the runtimeIndex. if (bankIndex == null) bankIndex = bankIndex(reactor); From 8fa20b8e75ae4302427d92fdb21de970ff558a95 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 14:20:45 -0700 Subject: [PATCH 322/709] Update tests according to new test categories. --- .../src/org/lflang/tests/RuntimeTest.java | 23 ++++++++++---- .../src/org/lflang/tests/runtime/CTest.java | 30 +++++++++++-------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java b/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java index 1cbb799046..7011b5ed96 100644 --- a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java +++ b/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java @@ -11,7 +11,7 @@ /** * A collection of JUnit tests to perform on a given set of targets. - * + * * @author Marten Lohstroh * */ @@ -135,12 +135,23 @@ public void runFederatedTests() { @Test public void runModalTests() { runTestsForTargets(Message.DESC_MODAL, - TestCategory.MODAL_MODELS::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); + TestCategory.MODAL_MODELS::equals, Configurators::noChanges, + TestLevel.EXECUTION, + false); } - /** + /** + * Run the tests for non-inlined reaction bodies. + */ + @Test + public void runNoInliningTests() { + runTestsForTargets(Message.DESC_MODAL, + TestCategory.NO_INLINING::equals, Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + /** * Run docker tests, provided that the platform is Linux and the target supports Docker. * Skip if platform is not Linux or target does not support Docker. */ @@ -154,7 +165,7 @@ public void runDockerTests() { false); } - /** + /** * Run federated docker tests, provided that the platform is Linux, the target supports Docker, * and the target supports federated execution. If any of these requirements are not met, skip * the tests. diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index bc906b0d95..eba4f7bc71 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -11,29 +11,25 @@ this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.tests.runtime; -import java.util.List; - import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.lflang.Target; -import org.lflang.tests.Configurators; import org.lflang.tests.RuntimeTest; -import org.lflang.tests.TestRegistry.TestCategory; /** * Collection of tests for the C target. @@ -112,6 +108,16 @@ public void runFederatedTests() { super.runFederatedTests(); } + @Test + public void runModalTests() { + super.runModalTests(); + } + + @Test + public void runNoInliningTests() { + super.runNoInliningTests(); + } + @Test @Override public void runDockerTests() { From d9b56726b22265a7143986f9228154d4a4f3086c Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 14:21:25 -0700 Subject: [PATCH 323/709] Update py-tests.yml --- .github/workflows/py-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 3f6e521fd1..f21c5e69aa 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -29,6 +29,9 @@ jobs: fetch-depth: 0 - name: Prepare build environment uses: ./.github/actions/prepare-build-env + - name: Install RTI + uses: ./.github/actions/install-rti + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Setup Python uses: actions/setup-python@v4 with: From 48542d3cf9094166657209c6118a2ed6e97083d9 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 14:21:55 -0700 Subject: [PATCH 324/709] Format test. --- test/C/src/generics/Template.lf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/C/src/generics/Template.lf b/test/C/src/generics/Template.lf index 3d483098b9..5b735ce4f4 100644 --- a/test/C/src/generics/Template.lf +++ b/test/C/src/generics/Template.lf @@ -1,7 +1,8 @@ target C reactor Hello { - state count: T(0) + state count: T = 0 + reaction(startup) {= self->count = self->count + 1; printf("Hello World %d\n", (int) self->count); @@ -9,5 +10,5 @@ reactor Hello { } main reactor Template { - hello = new Hello(); + hello = new Hello() } From b68cf1943d7035c81789931448675e8906f42b55 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 14:24:10 -0700 Subject: [PATCH 325/709] Update serialization-tests.yml --- .github/workflows/serialization-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 89f1ad735c..a2cd8f6fe0 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -20,6 +20,9 @@ jobs: fetch-depth: 0 - name: Prepare build environment uses: ./.github/actions/prepare-build-env + - name: Install RTI + uses: ./.github/actions/install-rti + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Setup ROS2 uses: ./.github/actions/setup-ros2 - name: Install Protobuf Ubuntu From 9c3aa67823e1b2d369531a46cd08210d1ecb2abe Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 14:25:46 -0700 Subject: [PATCH 326/709] Merge in changes from reactor-c/main. This does not include the latest watchdog-related changes, which are not compatible with the current lingua-franca master. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index f1d41011e4..a520d996a3 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f1d41011e454a026741beb68bd9a3ec80101c8ee +Subproject commit a520d996a3c13c081b591aa67bf06afc39a7176d From e6c72685e3e719aee0dad09b88fa110863f99e6e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 14:28:44 -0700 Subject: [PATCH 327/709] Update ts-tests.yml --- .github/workflows/ts-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 7a49192c14..8e5576ced9 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -27,8 +27,8 @@ jobs: brew install coreutils if: ${{ runner.os == 'macOS' }} - name: Install RTI - uses: ./.github/actions/install-rti - if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} + uses: ./.github/actions/install-rti + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform TypeScript tests run: | ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" From fadbf03f4919f0877eac7f098607969b63ae6263 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 19 May 2023 15:01:15 -0700 Subject: [PATCH 328/709] Added parent pointer to action structs --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/org/lflang/generator/c/CActionGenerator.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 843e147128..10281fb32d 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 843e147128315ffa5216fffd6cba36396c3cd084 +Subproject commit 10281fb32d8636df0c6e571f3c27b1da9d45ade5 diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index af41440641..59f990ea47 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -104,7 +104,7 @@ public static void generateDeclarations( var actionName = action.getName(); body.pr(action, CGenerator.variableStructType(action, reactor, false)+" _lf_"+actionName+";"); // Initialize the trigger pointer in the action. - constructorCode.pr(action, "self->_lf_"+actionName+".trigger = &self->_lf__"+actionName+";"); + constructorCode.pr(action, "self->_lf_"+actionName+"._base.trigger = &self->_lf__"+actionName+";"); } } @@ -138,9 +138,10 @@ public static String generateAuxiliaryStruct( "token_type_t type;", // From token_template_t "lf_token_t* token;", // From token_template_t "size_t length;", // From token_template_t - "bool is_present;", // From lf_action_base_t - "bool has_value;", // From lf_action_base_t - "trigger_t* trigger;" // From lf_action_base_t + "bool is_present;", // From lf_port_or_action_t + "self_base_t* parent;",// From lf_port_or_action_t + "lf_action_internal_t _base;", // internal substruct + "bool has_value;" // From lf_action_base_t )); code.pr(valueDeclaration(action, target, types)); code.pr(federatedExtension.toString()); From 1dd92ebfb1d268c879f33a0c19c886e3337d4a94 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 15:13:42 -0700 Subject: [PATCH 329/709] Address failing no_inlining tests. --- .../c/CReactorHeaderFileGenerator.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 33f652a8a4..b98b5b959c 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -90,18 +90,12 @@ private static void appendSelfStruct(CodeBuilder builder, CTypes types, TypePara } private static void appendSignature(CodeBuilder builder, CTypes types, Reaction r, TypeParameterizedReactor tpr) { - if (r.getName() != null) builder.pr("void " + r.getName() + "(" + reactionParameters(types, r, tpr) + ");"); + if (r.getName() != null) builder.pr("void " + r.getName() + "(" + reactionParameters(r, tpr) + ");"); } - private static String reactionParameters(CTypes types, Reaction r, TypeParameterizedReactor tpr) { + private static String reactionParameters(Reaction r, TypeParameterizedReactor tpr) { return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), portVariableStream(r, tpr) - .map(tv -> tpr.getName().toLowerCase() + "_" + tv.getName() + "_t* " + tv.getName())) - .collect(Collectors.joining(", ")); - } - - public static String reactionArguments(CTypes types, Reaction r, TypeParameterizedReactor tpr) { - return Stream.concat(Stream.of(getApiSelfStruct(tpr)), inputVarRefStream(r) - .map(it -> String.format("((%s*) %s)", CGenerator.variableStructType(it.getVariable(), tpr, true), it.getVariable().getName()))) + .map(tv -> tv.getType(true) + tv.getName())) .collect(Collectors.joining(", ")); } @@ -146,12 +140,12 @@ public static String reactionArguments(Reaction r, TypeParameterizedReactor reac } /** Return a stream of all ports referenced by the signature of {@code r}. */ - private static Stream portVariableStream(Reaction r, TypeParameterizedReactor reactor) { + private static Stream portVariableStream(Reaction r, TypeParameterizedReactor reactorOfReaction) { return varRefStream(r) .map(it -> it.getVariable() instanceof TypedVariable tv ? new PortVariable( tv, - reactor, + it.getContainer() != null ? new TypeParameterizedReactor(it.getContainer()) : reactorOfReaction, it.getContainer()) : null) .filter(Objects::nonNull); @@ -160,7 +154,7 @@ private static Stream portVariableStream(Reaction r, TypeParameter /** * A variable that refers to a port. * @param tv The variable of the variable reference. - * @param r The reactor that contains the port. + * @param r The reactor in which the port is being used. * @param container The {@code Instantiation} referenced in the obtaining of {@code tv}, if * applicable; {@code null} otherwise. */ From 6bbee5cc1a0ec856280fd80b3891be4e35ebdbf4 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 15:16:35 -0700 Subject: [PATCH 330/709] Fix another mismatch between reactor and tpr. --- .../src/org/lflang/generator/c/CReactorHeaderFileGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index b98b5b959c..8fc60b78d7 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -121,7 +121,7 @@ public static String nonInlineInitialization(Reaction r, TypeParameterizedReacto it.getAlias(), CReactionGenerator.maxContainedReactorBankWidth( reactor.r().getInstantiations().stream() - .filter(instantiation -> ASTUtils.toDefinition(instantiation.getReactorClass()).equals(it.r)) + .filter(instantiation -> new TypeParameterizedReactor(instantiation).equals(it.r)) .findAny().orElseThrow(), null, 0, mainDef), "self->_lf_"+it.container.getName()+"_width", From 0e1285cab467980f8832bfab143d84c82de897ee Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 15:18:34 -0700 Subject: [PATCH 331/709] Update ci.yml --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48110ac926..457e231297 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@fix-ts-federated-tests needs: cancel # Run the Rust integration tests. @@ -116,10 +116,10 @@ jobs: # Run the TypeScript integration tests. ts-tests: - uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@fix-ts-federated-tests needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@fix-ts-federated-tests needs: cancel From 8958cc55baed8f378f3b0ba9591f21f9b0b40005 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 19 May 2023 15:35:48 -0700 Subject: [PATCH 332/709] Added parent pointer for ports --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CPortGenerator.java | 7 +++---- .../org/lflang/generator/c/CTriggerObjectsGenerator.java | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 10281fb32d..c5fd4b2741 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 10281fb32d8636df0c6e571f3c27b1da9d45ade5 +Subproject commit c5fd4b2741a3409d853658e82f1537190b2eeb37 diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 1b22b41f9a..247bdc803e 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -77,10 +77,9 @@ public static String generateAuxiliaryStruct( "token_type_t type;", // From token_template_t "lf_token_t* token;", // From token_template_t "size_t length;", // From token_template_t - "bool is_present;", // From lf_port_base_t - "lf_sparse_io_record_t* sparse_record;", // From lf_port_base_t - "int destination_channel;", // From lf_port_base_t - "int num_destinations;" // From lf_port_base_t + "bool is_present;", // From lf_port_or_action_t + "self_base_t* parent;",// From lf_port_or_action_t + "lf_port_internal_t _base;" )); code.pr(valueDeclaration(port, target, errorReporter, types)); code.pr(federatedExtension.toString()); diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index f653d3f997..d7be245cb1 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -664,7 +664,7 @@ private static String deferredInputNumDestinations( code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); // Syntax is slightly different for a multiport output vs. single port. var connector = (port.isMultiport())? "->" : "."; - code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); + code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"_base.num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); // Initialize token types. var type = ASTUtils.getInferredType(port.getDefinition()); @@ -716,7 +716,7 @@ private static String deferredOutputNumDestinations( for (SendRange sendingRange : output.eventualDestinations()) { code.pr("// For reference counting, set num_destinations for port " + output.getFullName() + "."); code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); - code.pr(CUtil.portRef(output, sr, sb, sc)+".num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); + code.pr(CUtil.portRef(output, sr, sb, sc)+"._base.num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); code.endScopedRangeBlock(sendingRange); } } From d548f1987d765019c7504539c8af4ede2b89307e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 16:17:54 -0700 Subject: [PATCH 333/709] Update reactor-c to include watchdogs. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index a520d996a3..abc273ec0e 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit a520d996a3c13c081b591aa67bf06afc39a7176d +Subproject commit abc273ec0ec0930252c55e2a106529d7cc4dc277 From 2a3095b1d3ca84381e4fe0418d253ecf4e1e5ffb Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 16:49:14 -0700 Subject: [PATCH 334/709] Fix error in serialization tests in master --- org.lflang/src/org/lflang/generator/ts/TSGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 6bd0813531..111a6d5b9a 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -334,7 +334,7 @@ class TSGenerator( // first build reactor-ts (pnpm does this automatically). if (devMode) { val rtPath = path.resolve("node_modules").resolve("@lf-lang").resolve("reactor-ts") - val buildRuntime = commandFactory.createCommand("npm", listOf("run", "prepublish"), rtPath) + val buildRuntime = commandFactory.createCommand("npm", listOf("run", "build"), rtPath) if (buildRuntime.run(context.cancelIndicator) != 0) { errorReporter.reportError( GeneratorUtils.findTargetDecl(resource), From 34c8bcb367cc9cea78be331322827e7fc840503d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 17:10:35 -0700 Subject: [PATCH 335/709] Fix ROS serialization. The problem was that the relevant #includes were behind an extern "C". --- .../src/org/lflang/federated/extensions/CExtension.java | 9 +++------ .../org/lflang/federated/extensions/CExtensionUtils.java | 3 +-- .../org/lflang/federated/extensions/PythonExtension.java | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index 8a69e979c6..a86d6fd1f0 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -32,7 +32,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.LinkedHashMap; import java.util.List; import org.lflang.ASTUtils; @@ -49,7 +48,6 @@ import org.lflang.federated.launcher.RtiConfig; import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; @@ -505,6 +503,7 @@ public String generatePreamble( includes.pr("#ifdef __cplusplus\n" + "}\n" + "#endif"); + includes.pr(generateSerializationIncludes(federate, fileConfig)); } return includes.toString(); @@ -537,8 +536,6 @@ protected String makePreamble( size_t _lf_action_table_size = %1$s; """.formatted(numOfNetworkActions)); - code.pr(generateSerializationPreamble(federate, fileConfig)); - code.pr(generateExecutablePreamble(federate, rtiConfig, errorReporter)); code.pr(generateInitializeTriggers(federate, errorReporter)); @@ -551,8 +548,8 @@ protected String makePreamble( /** * Generate preamble code needed for enabled serializers of the federate. */ - protected String generateSerializationPreamble(FederateInstance federate, FedFileConfig fileConfig) { - return CExtensionUtils.generateSerializationPreamble(federate, fileConfig); + protected String generateSerializationIncludes(FederateInstance federate, FedFileConfig fileConfig) { + return CExtensionUtils.generateSerializationIncludes(federate, fileConfig); } /** diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 55a489ce51..7a03655923 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -20,7 +20,6 @@ import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.GeneratorBase; import org.lflang.generator.ReactorInstance; import org.lflang.generator.c.CTypes; import org.lflang.generator.c.CUtil; @@ -547,7 +546,7 @@ public static String surroundWithIfFederatedDecentralized(String code) { /** * Generate preamble code needed for enabled serializers of the federate. */ - public static String generateSerializationPreamble( + public static String generateSerializationIncludes( FederateInstance federate, FedFileConfig fileConfig ) { diff --git a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java b/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java index 73bed06f7b..c533a1f765 100644 --- a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java @@ -57,7 +57,7 @@ public class PythonExtension extends CExtension { protected void generateCMakeInclude(FederateInstance federate, FedFileConfig fileConfig) throws IOException {} @Override - protected String generateSerializationPreamble(FederateInstance federate, FedFileConfig fileConfig) { + protected String generateSerializationIncludes(FederateInstance federate, FedFileConfig fileConfig) { CodeBuilder code = new CodeBuilder(); for (SupportedSerializers serialization : federate.enabledSerializers) { switch (serialization) { From 4281e7f16358b5ffef394652405c0439ec54c7ca Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 19 May 2023 17:19:28 -0700 Subject: [PATCH 336/709] Fixed trigger reference --- org.lflang/src/lib/c/reactor-c | 2 +- test/C/src/concurrent/ScheduleAt.lf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c5fd4b2741..78534983da 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c5fd4b2741a3409d853658e82f1537190b2eeb37 +Subproject commit 78534983da36552822e8ba6f09af4923cd6d58cd diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index 2ef6af7af6..5c266cfc29 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -76,7 +76,7 @@ reactor Scheduler { reaction(startup) -> act {= for (int i=0; i < 16; i++) { - _lf_schedule_at_tag(act->trigger, + _lf_schedule_at_tag(act->_base.trigger, (tag_t) { .time = self->times[i] + lf_time_logical(), .microstep = self->microstep_delay_list[i]}, NULL); } From 54cbe37e5416c8e6ccbff63f11ce851884014835 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 19 May 2023 17:21:49 -0700 Subject: [PATCH 337/709] Aligned reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 78534983da..d9b9571a02 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 78534983da36552822e8ba6f09af4923cd6d58cd +Subproject commit d9b9571a0204550b316e365ed7e7dc83a6a71b72 From 1cb092fe5dd71d91a9f0288a27b83b697837663f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 18:10:04 -0700 Subject: [PATCH 338/709] Update ts-tests.yml --- .github/workflows/ts-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 83c04d8cf7..4342082868 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,7 +28,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: From 36e985e92f3df10822d98b99b0506ae53c325363 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 18:10:37 -0700 Subject: [PATCH 339/709] Update package.json --- org.lflang/src/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index fc063d791e..75c880bbc3 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#minor-reorg", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From af208478fb79587d9f0417108a037c45cb97426a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 19 May 2023 18:24:34 -0700 Subject: [PATCH 340/709] Initialize the action's parent pointer --- org.lflang/src/org/lflang/generator/c/CActionGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 59f990ea47..fd75df296b 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -105,6 +105,7 @@ public static void generateDeclarations( body.pr(action, CGenerator.variableStructType(action, reactor, false)+" _lf_"+actionName+";"); // Initialize the trigger pointer in the action. constructorCode.pr(action, "self->_lf_"+actionName+"._base.trigger = &self->_lf__"+actionName+";"); + constructorCode.pr(action, "self->_lf_"+actionName+".parent = (self_base_t*)self;"); } } From 96abdfeda847a3c21dc8b35ccc3a4e049678fdb1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 18:31:17 -0700 Subject: [PATCH 341/709] Silence warning. The line I deleted here was doing nothing according to the compiler. --- org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt index 990ede56c6..a6bd81f548 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt @@ -47,7 +47,6 @@ class CppPortGenerator(private val reactor: Reactor) { val VarRef.dataType: String get() { val variableRef = when { - this == null -> "" container == null -> this.name container.isBank && container.isEnclave -> "${container.name}[0]->__lf_instance->${variable.name}" container.isBank && !container.isEnclave -> "${container.name}[0]->${variable.name}" From fed3e14b79a13a8c704612d0e546e378778ed306 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 18:31:44 -0700 Subject: [PATCH 342/709] Pass failing template test. There is only one test, so this is easy. I think that adding a more thorough test suite and getting it to pass should be left outside the scope of this PR since this PR has lingered too long already and already provides useful functionality. --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 6 +----- .../lflang/generator/c/CReactorHeaderFileGenerator.java | 1 + .../org/lflang/generator/c/TypeParameterizedReactor.java | 9 +++++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index aa34ddcdb5..cd89c36fd7 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1078,11 +1078,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String } src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); src.pr("#include \"" + headerName + "\""); - tpr.typeArgs().forEach((literal, concreteType) -> src.pr( - "#if defined " + literal + "\n" + - "#undef " + literal + "\n" + - "#endif // " + literal + "\n" + - "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); + tpr.doDefines(src); ASTUtils.allIncludes(tpr.r()).stream().map(name -> "#include \"" + name + ".h\"").forEach(header::pr); } diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 8fc60b78d7..20d951b271 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -45,6 +45,7 @@ private static String generateHeaderFile(CTypes types, TypeParameterizedReactor appendIncludeGuard(builder, tpr); builder.pr(topLevelPreamble); appendPoundIncludes(builder); + tpr.doDefines(builder); appendSelfStruct(builder, types, tpr); generator.generate(builder, tpr, true); for (Reaction reaction : tpr.r().getReactions()) { diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 1a9ac13761..2b2e3e571c 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import org.lflang.ASTUtils; +import org.lflang.generator.CodeBuilder; import org.lflang.lf.Instantiation; import org.lflang.lf.Reactor; import org.lflang.lf.Type; @@ -32,6 +33,14 @@ public String getName() { return r.getName() + typeArgs.values().stream().map(ASTUtils::toOriginalText).collect(Collectors.joining("_")); } + public void doDefines(CodeBuilder b) { + typeArgs.forEach((literal, concreteType) -> b.pr( + "#if defined " + literal + "\n" + + "#undef " + literal + "\n" + + "#endif // " + literal + "\n" + + "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); + } + @Override public int hashCode() { return Math.abs(r.hashCode() * 31 + typeArgs.hashCode()); From a31f8f8485ef8618a5019895ce6d1bb074fa2edc Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 22:21:21 -0700 Subject: [PATCH 343/709] See if PR in reactor-c-py addresses test failure --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 80c24aa2e5..269c8184fb 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 80c24aa2e5bc814434893e9b6e4b183b4827c36a +Subproject commit 269c8184fbcae4700774fd04aaaa052c976f005b From 48f9c3932acfcadc9a58e73071f0802956d9fafc Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 19 May 2023 23:09:32 -0700 Subject: [PATCH 344/709] Update ts-tests.yml --- .github/workflows/ts-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index fc43143177..888610917b 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -14,6 +14,7 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 + submodules: true - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Setup Node.js environment From ce31b706946455670dadc4061e2554fdf85930ca Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 23:24:25 -0700 Subject: [PATCH 345/709] Do not use hashcodes as keys. There are a few reasons for this change * the key is everywhere being computed from an Instantiation, so this change reduces the total amount of code * hash codes can occasionally collide, and I was not sure that this particular hashcode was very effective at minimizing collision probability. * but more importantly, the hash codes were being computed from information that does not uniquely identify the Instantiation. It was being computed from the name of the variable that holds the instance and from the name of the reactor class being instantiated. So if the same reactor class were instantiated and stored in a variable of the same name in multiple places, this could result in bugs. This change means that we are using physical equality to check the keys to the hashmap because we don't have our own IR and we can't override the hashcode and equals functions of Instantiation. But I think that's OK. After AST transformations, which should happen as upstream as possible, we are working with one single object representation of the program. --- org.lflang/src/org/lflang/ASTUtils.java | 2 +- .../src/org/lflang/generator/ReactorInstance.java | 14 +++++--------- .../src/org/lflang/generator/c/CGenerator.java | 2 +- .../org/lflang/generator/c/CReactionGenerator.java | 11 +++++------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 9da1c4fdd3..3072c19148 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -411,7 +411,7 @@ public static HashSet allIncludes(Reactor r) { var set = new HashSet(); for (var i : allInstantiations(r)) { - set.add(CUtil.getName(ReactorInstance.getReactorInstance(ASTUtils.toDefinition(i.getReactorClass()), i.getName()).tpr)); + set.add(CUtil.getName(ReactorInstance.getReactorInstance(i).tpr)); } return set; } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index d6c02eca64..dc5e8487b4 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -26,7 +26,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator; -import static org.lflang.ASTUtils.belongsTo; import static org.lflang.ASTUtils.getLiteralTimeValue; import java.util.ArrayList; @@ -170,7 +169,7 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re public TypeParameterizedReactor tpr; /** HashMap containing {@link ReactorInstance} against hashCode achievable from Reactor */ - private static final HashMap gReactorInstancesMap = new HashMap<>(); + private static final HashMap gReactorInstancesMap = new HashMap<>(); ////////////////////////////////////////////////////// //// Static methods. @@ -181,15 +180,12 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re * @param defName definition Name for the specified Reactor * */ public static void mapReactorInstance(Reactor reactor, ReactorInstance reactorInstance, final String defName) { - gReactorInstancesMap.put(computeHash(reactor, defName), reactorInstance); + gReactorInstancesMap.put(reactorInstance.definition, reactorInstance); } - /** Get {@link ReactorInstance} for supplied {@link Reactor} - * @param reactor The reactor - * @param defName definition Name for the specified reactor - * */ - public static ReactorInstance getReactorInstance(Reactor reactor, final String defName) { - return gReactorInstancesMap.get(computeHash(reactor, defName)); + /** Get {@link ReactorInstance} for supplied {@link Reactor} */ + public static ReactorInstance getReactorInstance(Instantiation i) { + return gReactorInstancesMap.get(i); } /** Clears out the cache of ReactorInstance for next LF processing */ diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index cd89c36fd7..d6c28fc08d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1274,7 +1274,7 @@ private void generateInteractingContainedReactors( var contained = new InteractingContainedReactors(tpr.r()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { - var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass()), containedReactor.getName()); + var containedReactorType = ReactorInstance.getReactorInstance(containedReactor); // First define an _width variable in case it is a bank. var array = ""; var width = -2; diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 760f1134d2..5a627055cc 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -207,7 +207,7 @@ public static String generateInitializationForReaction(String body, // Before the reaction initialization, // generate the structs used for communication to and from contained reactors. for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - var containedReactorType = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(containedReactor.getReactorClass()), containedReactor.getName()); + var containedReactorType = ReactorInstance.getReactorInstance(containedReactor); String array = ""; if (containedReactor.getWidthSpec() != null) { String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); @@ -355,7 +355,7 @@ private static void generateVariablesForSendingToContainedReactors( structBuilder = new CodeBuilder(); structs.put(definition, structBuilder); } - var reactorInstance = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), definition.getName()); + var reactorInstance = ReactorInstance.getReactorInstance(definition); String inputStructType = CGenerator.variableStructType(input, reactorInstance.tpr, false); String defName = reactorInstance.getName(); String defWidth = generateWidthVariable(defName); @@ -423,14 +423,14 @@ private static void generatePortVariablesInReaction( } else { // port is an output of a contained reactor. Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).getTypeParameterizedReactor(), false); + String portStructType = CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(port.getContainer()).getTypeParameterizedReactor(), false); CodeBuilder structBuilder = structs.get(port.getContainer()); if (structBuilder == null) { structBuilder = new CodeBuilder(); structs.put(port.getContainer(), structBuilder); } - String subName = ReactorInstance.getReactorInstance(ASTUtils.toDefinition(port.getContainer().getReactorClass()), port.getContainer().getName()).getName(); + String subName = ReactorInstance.getReactorInstance(port.getContainer()).getName(); String reactorWidth = generateWidthVariable(subName); String outputName = output.getName(); String outputWidth = generateWidthVariable(outputName); @@ -645,8 +645,7 @@ public static String generateOutputVariablesInReaction( String outputStructType = (effect.getContainer() == null) ? CGenerator.variableStructType(output, tpr, false) : - CGenerator.variableStructType(output, ReactorInstance.getReactorInstance( - ASTUtils.toDefinition(effect.getContainer().getReactorClass()), effect.getContainer().getName()).getTypeParameterizedReactor(), false); + CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(effect.getContainer()).getTypeParameterizedReactor(), false); if (!ASTUtils.isMultiport(output)) { // Output port is not a multiport. return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; From 4b5a7c5f9653a9f6ded7bd778c25945b311bd705 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 19 May 2023 23:53:46 -0700 Subject: [PATCH 346/709] Bugfix in CGenerator.java. The tests were all passing, but it looked wrong as-is. Maybe the tests were passing because we were not using the feature that lets the user use types in a reaction body that relate to contained reactors. --- org.lflang/src/org/lflang/ASTUtils.java | 2 +- .../src/org/lflang/generator/ReactorInstance.java | 1 - org.lflang/src/org/lflang/generator/c/CGenerator.java | 11 +++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 3072c19148..e251557d1d 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -375,7 +375,7 @@ public static List allInputs(Reactor definition) { /** A list of all ports of {@code definition}, in an unspecified order. */ public static List allPorts(Reactor definition) { - return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).collect(Collectors.toList()); + return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); } /** diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index dc5e8487b4..432a1e7ee4 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -35,7 +35,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Set; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index d6c28fc08d..13af7e9dc7 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -37,9 +37,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -88,7 +86,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Mode; -import org.lflang.lf.Model; import org.lflang.lf.Port; import org.lflang.lf.Preamble; import org.lflang.lf.Reaction; @@ -100,8 +97,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; /** @@ -492,7 +487,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { var sources = allTypeParameterizedReactors() .map(CUtil::getName) .map(it -> it + (CCppMode ? ".cpp" : ".c")) - .collect(Collectors.toCollection(ArrayList::new)); + .toList(); sources.add(cFilename); var cmakeCode = cmakeGenerator.generateCMakeCode( sources, @@ -916,9 +911,9 @@ private void generateHeaders() throws IOException { CReactorHeaderFileGenerator.doGenerate( types, tpr, fileConfig, (builder, rr, userFacing) -> { - generateAuxiliaryStructs(builder, tpr, userFacing); + generateAuxiliaryStructs(builder, rr, userFacing); if (userFacing) { - tpr.r().getInstantiations().stream() + rr.r().getInstantiations().stream() .map(it -> new TypeParameterizedReactorWithDecl(new TypeParameterizedReactor(it), it.getReactorClass())).collect(Collectors.toSet()).forEach(it -> { ASTUtils.allPorts(it.tpr.r()) .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( From 0c0157b78e8bd4d47400d91d0d62184aae6f14fc Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Sat, 20 May 2023 18:10:24 +0900 Subject: [PATCH 347/709] Minor fix to TS test PingPongDistributed.lf --- test/TypeScript/src/federated/PingPongDistributed.lf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/TypeScript/src/federated/PingPongDistributed.lf b/test/TypeScript/src/federated/PingPongDistributed.lf index 34a633aba4..1e121edba3 100644 --- a/test/TypeScript/src/federated/PingPongDistributed.lf +++ b/test/TypeScript/src/federated/PingPongDistributed.lf @@ -8,13 +8,13 @@ reactor Ping(count: number = 10) { logical action serve reaction(startup, serve) -> send {= - console.log(`At lo${util.getElapsedLogicalTime()}, Ping sending ${pingsLeft}`); + console.log(`At logical time ${util.getElapsedLogicalTime()}, Ping sending ${pingsLeft}`); send = pingsLeft; pingsLeft = pingsLeft - 1; =} reaction(receive) -> serve {= - if(pingsLeft > 0){ + if (pingsLeft > 0){ actions.serve.schedule(0, null); } else{ From 3b1ad06262bfbccb88a3088d1fa630b28a6af7d4 Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Sat, 20 May 2023 18:19:10 +0900 Subject: [PATCH 348/709] Do not overwrite keepAlive of federateConfig with the app parameter (possibly coming from the TargetProperty). --- org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt index 0075950a1f..a1ec96c9ac 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt @@ -59,7 +59,6 @@ class TSConstructorGenerator( | } | federateConfig.federationID = __federationID; | federateConfig.fast = __fast; - | federateConfig.keepAlive = __keepAlive; | super(federateConfig, success, fail); """.trimMargin() } else { From 946ef5b4513a7c198ffd3cfeef586bc57cb19c83 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sat, 20 May 2023 18:41:51 +0900 Subject: [PATCH 349/709] Set the default keepAlive of federation to true --- org.lflang/src/org/lflang/federated/extensions/TSExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index 77d6203a93..8a9ef49e0d 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -102,7 +102,7 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf fast: false, federateID: %d, federationID: "Unidentified Federation", - keepAlive: false, + keepAlive: true, minOutputDelay: %s, networkMessageActions: [%s], rtiHost: "%s", From ddc654942e310b40275d87f83bae769d84543a09 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sat, 20 May 2023 22:18:42 +0900 Subject: [PATCH 350/709] Minor fix to TS TestCount.lf --- test/TypeScript/src/lib/TestCount.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TypeScript/src/lib/TestCount.lf b/test/TypeScript/src/lib/TestCount.lf index 822b4c64b1..01cc5271bf 100644 --- a/test/TypeScript/src/lib/TestCount.lf +++ b/test/TypeScript/src/lib/TestCount.lf @@ -30,7 +30,7 @@ reactor TestCount( reaction(shutdown) {= console.log("Shutdown invoked."); if (inputsReceived != numInputs) { - console.log("ERROR: Expected to receive " + numInputs + " inputs, but got " + inputsReceived + "."); + util.requestErrorStop("ERROR: Expected to receive " + numInputs + " inputs, but got " + inputsReceived + "."); } =} } From 30689b64b3f27f5d609febec36c6537b006786fd Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 20 May 2023 08:43:32 -0700 Subject: [PATCH 351/709] Removed parent pointer from port because it is not the right parent --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CActionGenerator.java | 2 +- org.lflang/src/org/lflang/generator/c/CPortGenerator.java | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index d9b9571a02..01f7957d02 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit d9b9571a0204550b316e365ed7e7dc83a6a71b72 +Subproject commit 01f7957d025306fb48a1d092f228467fd4acb722 diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index fd75df296b..5b85365c2b 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -140,8 +140,8 @@ public static String generateAuxiliaryStruct( "lf_token_t* token;", // From token_template_t "size_t length;", // From token_template_t "bool is_present;", // From lf_port_or_action_t - "self_base_t* parent;",// From lf_port_or_action_t "lf_action_internal_t _base;", // internal substruct + "self_base_t* parent;",// From lf_port_or_action_t "bool has_value;" // From lf_action_base_t )); code.pr(valueDeclaration(action, target, types)); diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 247bdc803e..f7e3abc673 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -77,8 +77,7 @@ public static String generateAuxiliaryStruct( "token_type_t type;", // From token_template_t "lf_token_t* token;", // From token_template_t "size_t length;", // From token_template_t - "bool is_present;", // From lf_port_or_action_t - "self_base_t* parent;",// From lf_port_or_action_t + "bool is_present;", "lf_port_internal_t _base;" )); code.pr(valueDeclaration(port, target, errorReporter, types)); From e39792810ff7586157208dad237cd156e7cd61f0 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 20 May 2023 08:57:02 -0700 Subject: [PATCH 352/709] Marked src/federated/SimpleFederatedAuthenticated.lf as failing --- .../C/src/federated/{ => failing}/SimpleFederatedAuthenticated.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/federated/{ => failing}/SimpleFederatedAuthenticated.lf (100%) diff --git a/test/C/src/federated/SimpleFederatedAuthenticated.lf b/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf similarity index 100% rename from test/C/src/federated/SimpleFederatedAuthenticated.lf rename to test/C/src/federated/failing/SimpleFederatedAuthenticated.lf From 6c59e70c9f86741c572014a4432f4b795d066766 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 20 May 2023 14:26:45 -0700 Subject: [PATCH 353/709] Aligned reactor-c-py --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 80c24aa2e5..a61f6474c8 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 80c24aa2e5bc814434893e9b6e4b183b4827c36a +Subproject commit a61f6474c845d5b5c0ac4f312093a474a8ff2a7d From dd6fd0c97d6bf6cc18598da8bc4fa8102622bfc2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 20 May 2023 14:30:04 -0700 Subject: [PATCH 354/709] Fix bug introduced by previous commit. --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 13af7e9dc7..03b76b804b 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -37,6 +37,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.File; import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; @@ -487,7 +488,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { var sources = allTypeParameterizedReactors() .map(CUtil::getName) .map(it -> it + (CCppMode ? ".cpp" : ".c")) - .toList(); + .collect(Collectors.toCollection(ArrayList::new)); sources.add(cFilename); var cmakeCode = cmakeGenerator.generateCMakeCode( sources, From cc0a86555824fe6e5439a249efa7e940189543c5 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 20 May 2023 17:47:43 -0700 Subject: [PATCH 355/709] Added generation of .vscode/settings.json file --- .../org/lflang/generator/c/CGenerator.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 32174be22c..adff5bc903 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -36,6 +36,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.HashSet; import java.util.LinkedHashSet; @@ -538,7 +539,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { try { String compileDefs = targetConfig.compileDefinitions.keySet().stream() .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) - .collect(Collectors.joining("\n")); + .collect(Collectors.joining("\n")) + "\n"; FileUtil.writeToFile( compileDefs, Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") @@ -547,6 +548,29 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { Exceptions.sneakyThrow(e); } + // Create a .vscode/settings.json file in the target directory so that VSCode can + // immediately compile the generated code. + try { + String compileDefs = targetConfig.compileDefinitions.keySet().stream() + .map(key -> "\"-D" + key + "=" + targetConfig.compileDefinitions.get(key) + "\"") + .collect(Collectors.joining(",\n")); + String settings = "{\n" + + "\"cmake.configureArgs\": [\n" + + compileDefs + + "\n]\n}\n"; + Path vscodePath = Path.of(fileConfig.getSrcGenPath() + File.separator + ".vscode"); + if (!Files.exists(vscodePath)) + Files.createDirectory(vscodePath); + FileUtil.writeToFile( + settings, + Path.of(fileConfig.getSrcGenPath() + + File.separator + ".vscode" + + File.separator + "settings.json") + ); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + // If this code generator is directly compiling the code, compile it now so that we // clean it up after, removing the #line directives after errors have been reported. if ( From 6c3ce2517c29b333722983cb5a4da60dfd0c8740 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 20 May 2023 18:41:57 -0700 Subject: [PATCH 356/709] C files for Python support retrieved from reactor-c repo (#1757) * Adjust paths * Update submodules --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/py/reactor-c-py | 2 +- .../src/org/lflang/generator/python/PythonGenerator.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 843e147128..dc6b138746 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 843e147128315ffa5216fffd6cba36396c3cd084 +Subproject commit dc6b13874697315859cd75e26ddd82f9c0d83643 diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 80c24aa2e5..d9fc25f24e 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 80c24aa2e5bc814434893e9b6e4b183b4827c36a +Subproject commit d9fc25f24eca93e581bcf9d5734d80e69243574d diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 2686c98539..0c0dfc5a38 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -660,13 +660,13 @@ private static String generatePythonFileName(String lfModuleName) { protected void copyTargetFiles() throws IOException { super.copyTargetFiles(); FileUtil.copyFromClassPath( - "/lib/py/reactor-c-py/include", + "/lib/c/reactor-c/python/include", fileConfig.getSrcGenPath(), true, false ); FileUtil.copyFromClassPath( - "/lib/py/reactor-c-py/lib", + "/lib/c/reactor-c/python/lib", fileConfig.getSrcGenPath(), true, false From e34cab762aeef29083b0c0300c46380c6e2ec595 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 20 May 2023 19:32:42 -0700 Subject: [PATCH 357/709] Update org.lflang/src/org/lflang/generator/c/CActionGenerator.java Co-authored-by: erling --- org.lflang/src/org/lflang/generator/c/CActionGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 5b85365c2b..72647f5c0e 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -103,7 +103,7 @@ public static void generateDeclarations( for (Action action : ASTUtils.allActions(reactor)) { var actionName = action.getName(); body.pr(action, CGenerator.variableStructType(action, reactor, false)+" _lf_"+actionName+";"); - // Initialize the trigger pointer in the action. + // Initialize the trigger pointer and the parent pointer in the action. constructorCode.pr(action, "self->_lf_"+actionName+"._base.trigger = &self->_lf__"+actionName+";"); constructorCode.pr(action, "self->_lf_"+actionName+".parent = (self_base_t*)self;"); } From 87b0be59da6963dfe40b9ea120c102dde249f9f3 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sun, 21 May 2023 14:23:40 +0900 Subject: [PATCH 358/709] Update package.json --- org.lflang/src/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 75c880bbc3..fc063d791e 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#minor-reorg", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From 3d51b1bc269e733ec8eeba0341305da3fb30d11a Mon Sep 17 00:00:00 2001 From: erling Date: Sat, 20 May 2023 23:07:46 -0700 Subject: [PATCH 359/709] Zephyr ci4 (#1758) * Update & upgrade before zephyr installation --- .github/actions/setup-zephyr/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 64d85ec0f2..7d835049dc 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -5,7 +5,8 @@ runs: steps: - name: Dependencies run: | - sudo apt install -y --no-install-recommends git cmake ninja-build gperf \ + sudo apt-get update && sudo apt-get upgrade + sudo apt-get install -y --no-install-recommends git cmake ninja-build gperf \ ccache dfu-util device-tree-compiler wget \ python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 From 959ab3cd79bbbf5fa4a7680e254cc320e093f8eb Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sun, 21 May 2023 16:17:11 +0900 Subject: [PATCH 360/709] Point to the branch 'fix-federation' of reactor-ts --- .github/workflows/ts-tests.yml | 2 +- org.lflang/src/lib/ts/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 888610917b..788a0695b7 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -32,7 +32,7 @@ jobs: if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#fix-federation" - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index fc063d791e..cdb127813a 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#fix-federation", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From c44f91e234300b7a089145b8adf519d8d08d1ac6 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 09:16:04 -0700 Subject: [PATCH 361/709] Fix line adjustment logic for federated programs. It is bad that I had to modify ToLf to do this since the logic isn't really in ToLf. The problem was that the line adjustment relies on tagging the target code (without the fat braces), and the target code is not recorded separately from the fat braces if they are entered into the MalleableString machinery as all one string. --- org.lflang/src/org/lflang/ast/ToLf.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index ce1cdca9fe..763ae8266c 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -219,7 +219,11 @@ public MalleableString caseCode(Code code) { .map(String::stripTrailing) .collect(Collectors.joining("\n")); MalleableString singleLineRepresentation = - MalleableString.anyOf(String.format("{= %s =}", content.strip())); + new Builder() + .append("{= ") + .append(content.strip()) + .append(" =}") + .get(); MalleableString multilineRepresentation = new Builder() .append(String.format("{=%n")) From e30dd0cbab503a50cdd1a8af233f1cc1baa5fb1e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 21 May 2023 15:30:38 -0700 Subject: [PATCH 362/709] Rename submodule to match repo name --- .gitmodules | 4 ++-- org.lflang/src/lib/py/{reactor-c-py => lf-python-support} | 0 .../src/org/lflang/generator/python/PythonGenerator.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename org.lflang/src/lib/py/{reactor-c-py => lf-python-support} (100%) diff --git a/.gitmodules b/.gitmodules index 3ccd9f3a7f..b2b2916982 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,8 +2,8 @@ path = org.lflang/src/lib/c/reactor-c url = https://github.com/lf-lang/reactor-c.git [submodule "org.lflang/src/lib/py/reactor-c-py"] - path = org.lflang/src/lib/py/reactor-c-py - url = https://github.com/lf-lang/reactor-c-py.git + path = org.lflang/src/lib/py/lf-python-support + url = https://github.com/lf-lang/lf-python-support.git [submodule "org.lflang/src/lib/cpp/reactor-cpp"] path = org.lflang/src/lib/cpp/reactor-cpp url = https://github.com/lf-lang/reactor-cpp diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/lf-python-support similarity index 100% rename from org.lflang/src/lib/py/reactor-c-py rename to org.lflang/src/lib/py/lf-python-support diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 0c0dfc5a38..3f8181d764 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -137,7 +137,7 @@ private PythonGenerator(LFGeneratorContext context, PythonTypes types, CCmakeGen * FEDERATED_GENERIC_EXTENSION * } generic_port_instance_struct; * - * See reactor-c-py/lib/pythontarget.h for details. + * See reactor-c/python/lib/pythontarget.h for details. */ String genericPortType = "generic_port_instance_struct"; @@ -153,7 +153,7 @@ private PythonGenerator(LFGeneratorContext context, PythonTypes types, CCmakeGen * FEDERATED_CAPSULE_EXTENSION * } generic_action_instance_struct; * - * See reactor-c-py/lib/pythontarget.h for details. + * See reactor-c/python/lib/pythontarget.h for details. */ String genericActionType = "generic_action_instance_struct"; @@ -672,7 +672,7 @@ protected void copyTargetFiles() throws IOException { false ); FileUtil.copyFromClassPath( - "/lib/py/reactor-c-py/LinguaFrancaBase", + "/lib/py/lf-python-support/LinguaFrancaBase", fileConfig.getSrcGenPath(), true, false From 4ec327ebbf930ad9ca5acbf963a688fbeb634e00 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 21 May 2023 16:04:17 -0700 Subject: [PATCH 363/709] Fix submodule config --- .gitmodules | 3 +++ org.lflang/src/lib/lf-python-support | 1 + org.lflang/src/lib/py/reactor-c-py | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) create mode 160000 org.lflang/src/lib/lf-python-support delete mode 160000 org.lflang/src/lib/py/reactor-c-py diff --git a/.gitmodules b/.gitmodules index c67b03b7fb..ee9c36f08f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "org.lflang/src/lib/rs/reactor-rs"] path = org.lflang/src/lib/rs/reactor-rs url = https://github.com/lf-lang/reactor-rs +[submodule "org.lflang/src/lib/lf-python-support"] + path = org.lflang/src/lib/lf-python-support + url = https://github.com/lf-lang/lf-python-support.git diff --git a/org.lflang/src/lib/lf-python-support b/org.lflang/src/lib/lf-python-support new file mode 160000 index 0000000000..f7be0cd729 --- /dev/null +++ b/org.lflang/src/lib/lf-python-support @@ -0,0 +1 @@ +Subproject commit f7be0cd729c840667a39c9b2087db4f7ec82ec3a diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py deleted file mode 160000 index a61f6474c8..0000000000 --- a/org.lflang/src/lib/py/reactor-c-py +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a61f6474c845d5b5c0ac4f312093a474a8ff2a7d From c75e818782170fc4bdbdf7eebc54f068a2252f44 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 21 May 2023 16:07:57 -0700 Subject: [PATCH 364/709] Update .gitmodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index b2b2916982..3d26f4317d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ [submodule "org.lflang/src/lib/c/reactor-c"] path = org.lflang/src/lib/c/reactor-c url = https://github.com/lf-lang/reactor-c.git -[submodule "org.lflang/src/lib/py/reactor-c-py"] +[submodule "org.lflang/src/lib/py/lf-python-support"] path = org.lflang/src/lib/py/lf-python-support url = https://github.com/lf-lang/lf-python-support.git [submodule "org.lflang/src/lib/cpp/reactor-cpp"] From 331a3151b1e7d9249453a8577b883def9e14a761 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 17:23:50 -0700 Subject: [PATCH 365/709] Entirely delete the map from ReactorInstance. We do not need it. We can obtain a TPR from an Instantiation when all the concrete types are immediately available, and when they are not immediately available, we the map does not help us. --- org.lflang/src/org/lflang/ASTUtils.java | 2 +- org.lflang/src/org/lflang/cli/Lfc.java | 7 ++-- .../org/lflang/generator/ReactorInstance.java | 36 ------------------- .../org/lflang/generator/c/CGenerator.java | 10 +++--- .../generator/c/CReactionGenerator.java | 16 ++++----- 5 files changed, 16 insertions(+), 55 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index e251557d1d..b9cacd8f48 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -411,7 +411,7 @@ public static HashSet allIncludes(Reactor r) { var set = new HashSet(); for (var i : allInstantiations(r)) { - set.add(CUtil.getName(ReactorInstance.getReactorInstance(i).tpr)); + set.add(CUtil.getName(new TypeParameterizedReactor(i))); } return set; } diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index 38795137d5..74d9eac8da 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -107,7 +107,7 @@ public class Lfc extends CliBase { @Option( names = {"-q", "--quiet"}, arity = "0", - description = + description = "Suppress output of the target compiler and other commands") private boolean quiet; @@ -189,7 +189,7 @@ private void invokeGenerator( final Resource resource = getResource(path); if (resource == null) { - reporter.printFatalErrorAndExit(path + reporter.printFatalErrorAndExit(path + " is not an LF file. Use the .lf file extension to" + " denote LF files."); } else if (federated) { @@ -210,7 +210,6 @@ private void invokeGenerator( try { this.generator.generate(resource, this.fileAccess, context); - ReactorInstance.clearReactorInstanceMap(); } catch (Exception e) { reporter.printFatalErrorAndExit("Error running generator", e); } @@ -318,7 +317,7 @@ public Properties getGeneratorArgs() { if (workers != null) { props.setProperty(BuildParm.WORKERS.getKey(), workers.toString()); } - + return props; } } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 432a1e7ee4..80629b81a0 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -167,39 +167,6 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re public TypeParameterizedReactor tpr; - /** HashMap containing {@link ReactorInstance} against hashCode achievable from Reactor */ - private static final HashMap gReactorInstancesMap = new HashMap<>(); - - ////////////////////////////////////////////////////// - //// Static methods. - - /** Map {@link ReactorInstance} against achievable hashcode from {@link Reactor} - * @param reactor The Reactor - * @param reactorInstance The ReactorInstance for the specified Reactor - * @param defName definition Name for the specified Reactor - * */ - public static void mapReactorInstance(Reactor reactor, ReactorInstance reactorInstance, final String defName) { - gReactorInstancesMap.put(reactorInstance.definition, reactorInstance); - } - - /** Get {@link ReactorInstance} for supplied {@link Reactor} */ - public static ReactorInstance getReactorInstance(Instantiation i) { - return gReactorInstancesMap.get(i); - } - - /** Clears out the cache of ReactorInstance for next LF processing */ - public static void clearReactorInstanceMap() { - gReactorInstancesMap.clear(); - } - - /** Calculates Unique HashCode for the key of ReactorInstanceMap - * @param r The reactor - * @param n definition Name for the Reactor - * */ - private static Integer computeHash(Reactor r, final String n) { - return Math.abs(r.hashCode() * 37 + r.getTypeParms().hashCode() + n.hashCode()); - } - ////////////////////////////////////////////////////// //// Public methods. @@ -844,9 +811,6 @@ public ReactorInstance( this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); this.tpr = new TypeParameterizedReactor(definition); - // Add ReactorInstance against achievable hashcode from Reactor - ReactorInstance.mapReactorInstance(ASTUtils.toDefinition(definition.getReactorClass()), this, definition.getName()); - // check for recursive instantiation var currentParent = parent; var foundSelfAsParent = false; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 03b76b804b..b3bdac45bb 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1270,7 +1270,7 @@ private void generateInteractingContainedReactors( var contained = new InteractingContainedReactors(tpr.r()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { - var containedReactorType = ReactorInstance.getReactorInstance(containedReactor); + var containedTpr = new TypeParameterizedReactor(containedReactor); // First define an _width variable in case it is a bank. var array = ""; var width = -2; @@ -1298,12 +1298,12 @@ private void generateInteractingContainedReactors( // to be malloc'd at initialization. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType.tpr, false)+" "+port.getName()+";"); + body.pr(port, variableStructType(port, containedTpr, false)+" "+port.getName()+";"); } else { // Is a multiport. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, containedReactorType.tpr, false)+"** "+port.getName()+";", + variableStructType(port, containedTpr, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } @@ -1313,13 +1313,13 @@ private void generateInteractingContainedReactors( // self struct of the container. if (!ASTUtils.isMultiport(port)) { // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType.tpr, false)+"* "+port.getName()+";"); + body.pr(port, variableStructType(port, containedTpr, false)+"* "+port.getName()+";"); } else { // Is a multiport. // Here, we will use an array of pointers. // Memory will be malloc'd in initialization. body.pr(port, String.join("\n", - variableStructType(port, containedReactorType.tpr, false)+"** "+port.getName()+";", + variableStructType(port, containedTpr, false)+"** "+port.getName()+";", "int "+port.getName()+"_width;" )); } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 5a627055cc..95ea818c49 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -207,7 +207,6 @@ public static String generateInitializationForReaction(String body, // Before the reaction initialization, // generate the structs used for communication to and from contained reactors. for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - var containedReactorType = ReactorInstance.getReactorInstance(containedReactor); String array = ""; if (containedReactor.getWidthSpec() != null) { String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); @@ -217,9 +216,9 @@ public static String generateInitializationForReaction(String body, array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; } code.pr(String.join("\n", - "struct "+containedReactorType.getName()+" {", + "struct "+containedReactor.getName()+" {", " "+fieldsForStructsForContainedReactors.get(containedReactor), - "} "+containedReactorType.getName()+array+";" + "} "+containedReactor.getName()+array+";" )); } // Next generate all the collected setup code. @@ -355,9 +354,8 @@ private static void generateVariablesForSendingToContainedReactors( structBuilder = new CodeBuilder(); structs.put(definition, structBuilder); } - var reactorInstance = ReactorInstance.getReactorInstance(definition); - String inputStructType = CGenerator.variableStructType(input, reactorInstance.tpr, false); - String defName = reactorInstance.getName(); + String inputStructType = CGenerator.variableStructType(input, new TypeParameterizedReactor(definition), false); + String defName = definition.getName(); String defWidth = generateWidthVariable(defName); String inputName = input.getName(); String inputWidth = generateWidthVariable(inputName); @@ -423,14 +421,14 @@ private static void generatePortVariablesInReaction( } else { // port is an output of a contained reactor. Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(port.getContainer()).getTypeParameterizedReactor(), false); + String portStructType = CGenerator.variableStructType(output, new TypeParameterizedReactor(port.getContainer()), false); CodeBuilder structBuilder = structs.get(port.getContainer()); if (structBuilder == null) { structBuilder = new CodeBuilder(); structs.put(port.getContainer(), structBuilder); } - String subName = ReactorInstance.getReactorInstance(port.getContainer()).getName(); + String subName = port.getContainer().getName(); String reactorWidth = generateWidthVariable(subName); String outputName = output.getName(); String outputWidth = generateWidthVariable(outputName); @@ -645,7 +643,7 @@ public static String generateOutputVariablesInReaction( String outputStructType = (effect.getContainer() == null) ? CGenerator.variableStructType(output, tpr, false) : - CGenerator.variableStructType(output, ReactorInstance.getReactorInstance(effect.getContainer()).getTypeParameterizedReactor(), false); + CGenerator.variableStructType(output, new TypeParameterizedReactor(effect.getContainer()), false); if (!ASTUtils.isMultiport(output)) { // Output port is not a multiport. return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; From f497c2a027161738f54ab08265f7aaca128507ad Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 17:30:01 -0700 Subject: [PATCH 366/709] Switch submodule ref to main. I am still not sure that we want to maintain this generics-related utility file. Let us not worry about it until later. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index abc273ec0e..dc6b138746 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit abc273ec0ec0930252c55e2a106529d7cc4dc277 +Subproject commit dc6b13874697315859cd75e26ddd82f9c0d83643 From 40f007e14c70a7ac5067849daefda83dc9f351f2 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 21 May 2023 18:40:41 -0700 Subject: [PATCH 367/709] Moved submodule to the right location --- .gitmodules | 4 ++-- org.lflang/src/lib/{ => py}/lf-python-support | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename org.lflang/src/lib/{ => py}/lf-python-support (100%) diff --git a/.gitmodules b/.gitmodules index 9a655f8d1c..0fb2c73374 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,6 @@ [submodule "org.lflang/src/lib/rs/reactor-rs"] path = org.lflang/src/lib/rs/reactor-rs url = https://github.com/lf-lang/reactor-rs -[submodule "org.lflang/src/lib/lf-python-support"] - path = org.lflang/src/lib/lf-python-support +[submodule "org.lflang/src/lib/py/lf-python-support"] + path = org.lflang/src/lib/py/lf-python-support url = https://github.com/lf-lang/lf-python-support.git diff --git a/org.lflang/src/lib/lf-python-support b/org.lflang/src/lib/py/lf-python-support similarity index 100% rename from org.lflang/src/lib/lf-python-support rename to org.lflang/src/lib/py/lf-python-support From 1cf725be4647441bc6671af942295464a4c1532c Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 21 May 2023 18:42:45 -0700 Subject: [PATCH 368/709] Remove redundant submodule from .gitmodules --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 0fb2c73374..c66506c2af 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "org.lflang/src/lib/c/reactor-c"] path = org.lflang/src/lib/c/reactor-c url = https://github.com/lf-lang/reactor-c.git -[submodule "org.lflang/src/lib/py/lf-python-support"] - path = org.lflang/src/lib/py/lf-python-support - url = https://github.com/lf-lang/lf-python-support.git [submodule "org.lflang/src/lib/cpp/reactor-cpp"] path = org.lflang/src/lib/cpp/reactor-cpp url = https://github.com/lf-lang/reactor-cpp From c6f1a6366bc800e09ae06853cef5038acaa40157 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 18:55:19 -0700 Subject: [PATCH 369/709] Update validator. --- .../generator/c/CReactionGenerator.java | 1 - .../generator/c/TypeParameterizedReactor.java | 6 ++++ .../org/lflang/validation/LFValidator.java | 28 ++++++++----------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 95ea818c49..2dbb1a1801 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -16,7 +16,6 @@ import org.lflang.TargetConfig; import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.BuiltinTriggerRef; diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 2b2e3e571c..69b245c36f 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -41,6 +41,12 @@ public void doDefines(CodeBuilder b) { "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); } + public Type resolveType(Type t) { + var arg = typeArgs.get(t.getCode().getBody()); + if (arg != null) return arg; + return t; + } + @Override public int hashCode() { return Math.abs(r.hashCode() * 31 + typeArgs.hashCode()); diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index c0e2a46e59..94fb578f72 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -45,6 +45,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.TreeIterator; @@ -65,6 +66,7 @@ import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.federated.validation.FedValidator; import org.lflang.generator.NamedInstance; +import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Assignment; @@ -255,7 +257,10 @@ public void checkConnection(Connection connection) { // we leave type compatibility that language's compiler or interpreter. if (isCBasedTarget()) { Type type = (Type) null; - for (VarRef port : connection.getLeftPorts()) { + for (VarRef port : (Iterable) () -> Stream.concat( + connection.getLeftPorts().stream(), + connection.getRightPorts().stream() + ).iterator()) { // If the variable is not a port, then there is some other // error. Avoid a class cast exception. if (port.getVariable() instanceof Port) { @@ -264,22 +269,11 @@ public void checkConnection(Connection connection) { } else { // Unfortunately, xtext does not generate a suitable equals() // method for AST types, so we have to manually check the types. -// if (!sameType(type, ((Port) port.getVariable()).getType())) { -// error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); -// } - } - } - } - for (VarRef port : connection.getRightPorts()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { -// if (!sameType(type, type = ((Port) port.getVariable()).getType())) { -// error("Types do not match.", Literals.CONNECTION__RIGHT_PORTS); -// } + var portType = ((Port) port.getVariable()).getType(); + portType = port.getContainer() == null ? portType : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); + if (!sameType(type, portType)) { + error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); + } } } } From f13966ac008bf9e3036ac42ce94f49980ef50855 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 22:17:10 -0700 Subject: [PATCH 370/709] Fix NPE. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 69b245c36f..0ae657ed5c 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -42,6 +42,7 @@ public void doDefines(CodeBuilder b) { } public Type resolveType(Type t) { + if (t.getCode() == null) return t; var arg = typeArgs.get(t.getCode().getBody()); if (arg != null) return arg; return t; From 441ee025b63725c788ede03502b3ba257c15684c Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Mon, 22 May 2023 15:53:02 +0900 Subject: [PATCH 371/709] Move failed test to the failing folder --- .../federated/{ => failing}/DistributedCountPhysicalAfterDelay.lf | 0 .../src/federated/{ => failing}/LoopDistributedCentralized.lf | 0 .../src/federated/{ => failing}/LoopDistributedDouble.lf | 0 .../TypeScript/src/federated/{ => failing}/PingPongDistributed.lf | 0 .../src/federated/{ => failing}/PingPongDistributedPhysical.lf | 0 test/TypeScript/src/federated/{ => failing}/SimpleFederated.lf | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename test/TypeScript/src/federated/{ => failing}/DistributedCountPhysicalAfterDelay.lf (100%) rename test/TypeScript/src/federated/{ => failing}/LoopDistributedCentralized.lf (100%) rename test/TypeScript/src/federated/{ => failing}/LoopDistributedDouble.lf (100%) rename test/TypeScript/src/federated/{ => failing}/PingPongDistributed.lf (100%) rename test/TypeScript/src/federated/{ => failing}/PingPongDistributedPhysical.lf (100%) rename test/TypeScript/src/federated/{ => failing}/SimpleFederated.lf (100%) diff --git a/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf similarity index 100% rename from test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf rename to test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf diff --git a/test/TypeScript/src/federated/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf similarity index 100% rename from test/TypeScript/src/federated/LoopDistributedCentralized.lf rename to test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/failing/LoopDistributedDouble.lf similarity index 100% rename from test/TypeScript/src/federated/LoopDistributedDouble.lf rename to test/TypeScript/src/federated/failing/LoopDistributedDouble.lf diff --git a/test/TypeScript/src/federated/PingPongDistributed.lf b/test/TypeScript/src/federated/failing/PingPongDistributed.lf similarity index 100% rename from test/TypeScript/src/federated/PingPongDistributed.lf rename to test/TypeScript/src/federated/failing/PingPongDistributed.lf diff --git a/test/TypeScript/src/federated/PingPongDistributedPhysical.lf b/test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf similarity index 100% rename from test/TypeScript/src/federated/PingPongDistributedPhysical.lf rename to test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf diff --git a/test/TypeScript/src/federated/SimpleFederated.lf b/test/TypeScript/src/federated/failing/SimpleFederated.lf similarity index 100% rename from test/TypeScript/src/federated/SimpleFederated.lf rename to test/TypeScript/src/federated/failing/SimpleFederated.lf From dd823e2bb6531fc7690c42c884e4a64fb30ab363 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 00:17:14 -0700 Subject: [PATCH 372/709] Update reactor-c submodule --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index dc6b138746..845daae394 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit dc6b13874697315859cd75e26ddd82f9c0d83643 +Subproject commit 845daae39479b8c06d15c1215aca575a4728a599 From f3c8ffa64cd47198cfaea6f746170311b79040bf Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 00:37:04 -0700 Subject: [PATCH 373/709] Remove getConcreteType. Prefer to work on InferredTypes or Types rather than raw strings. Our code base, esp. the C generator, has had multiple problems involving ad hoc matching of raw strings. --- .../lflang/generator/c/CActionGenerator.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 3 +-- .../generator/c/CParameterGenerator.java | 2 +- .../lflang/generator/c/CStateGenerator.java | 4 +-- .../src/org/lflang/generator/c/CTypes.java | 2 +- .../src/org/lflang/generator/c/CUtil.java | 25 ------------------- .../generator/c/TypeParameterizedReactor.java | 6 +++++ 7 files changed, 12 insertions(+), 32 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index bc14c402a7..0fa79e94ca 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -171,6 +171,6 @@ private static String valueDeclaration( // will be a separate field pointing to the token. return action.getType() == null && target.requiresTypes ? "" : - CUtil.getConcreteType(tpr, types.getTargetType(action)) + " value;"; + types.getTargetType(tpr.resolveType(action.getType())) + " value;"; } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b3bdac45bb..ea9de156e0 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1771,14 +1771,13 @@ private void generateInitializeActionToken(ReactorInstance reactor) { // Skip this step if the action is not in use. if (action.getParent().getTriggers().contains(action) ) { - var type = getInferredType(action.getDefinition()); + var type = reactor.tpr.resolveType(getInferredType(action.getDefinition())); var payloadSize = "0"; if (!type.isUndefined()) { var typeStr = types.getTargetType(type); if (CUtil.isTokenType(type, types)) { typeStr = CUtil.rootType(typeStr); } - typeStr = CUtil.getConcreteType(reactor.tpr, typeStr); if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { payloadSize = "sizeof("+typeStr+")"; } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index fb6a46bace..fc74f76d78 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -47,7 +47,7 @@ public static String generateDeclarations(TypeParameterizedReactor reactor, CTyp CodeBuilder code = new CodeBuilder(); for (Parameter parameter : ASTUtils.allParameters(reactor.r())) { code.prSourceLineNumber(parameter); - code.pr(CUtil.getConcreteType(reactor, types.getTargetType(parameter)) + " " + parameter.getName() + ";"); + code.pr(types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(parameter))) + " " + parameter.getName() + ";"); } return code.toString(); } diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index d3ced7fc65..1b75a73ab8 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -23,7 +23,7 @@ public static String generateDeclarations(TypeParameterizedReactor reactor, CTyp CodeBuilder code = new CodeBuilder(); for (StateVar stateVar : ASTUtils.allStateVars(reactor.r())) { code.prSourceLineNumber(stateVar); - code.pr(CUtil.getConcreteType(reactor, types.getTargetType(stateVar)) + " " + stateVar.getName() + ";"); + code.pr(types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(stateVar))) + " " + stateVar.getName() + ";"); } return code.toString(); } @@ -93,7 +93,7 @@ private static String generateModalReset( return ""; } var modeRef = "&"+CUtil.reactorRef(mode.getParent())+"->_lf__modes["+mode.getParent().modes.indexOf(mode)+"]"; - var type = CUtil.getConcreteType(instance.tpr, types.getTargetType(ASTUtils.getInferredType(stateVar))); + var type = types.getTargetType(instance.tpr.resolveType(ASTUtils.getInferredType(stateVar))); if (ASTUtils.isOfTimeType(stateVar) || ASTUtils.isParameterized(stateVar) && diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/src/org/lflang/generator/c/CTypes.java index 1081912f24..45edd59bd5 100644 --- a/org.lflang/src/org/lflang/generator/c/CTypes.java +++ b/org.lflang/src/org/lflang/generator/c/CTypes.java @@ -125,7 +125,7 @@ public String getVariableDeclaration( String variableName, boolean initializer ) { - String t = CUtil.getConcreteType(tpr, TargetTypes.super.getTargetType(type)); + String t = TargetTypes.super.getTargetType(tpr.resolveType(type)); Matcher matcher = arrayPattern.matcher(t); String declaration = String.format("%s %s", t, variableName); if (matcher.find()) { diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index e06fcdfc3f..b4e88b42ad 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -781,31 +781,6 @@ public static Pair separateTokensFromTypes(String str) { return new Pair<>(str.substring(0, starIdx), str.substring(starIdx)); } - /** - * Given a type we need to check if the type is Generic Type literal and if - * it is we need to find the corresponding concrete type - * - * @param tpr {@link TypeParameterizedReactor} - * @param type Actual typename - */ - public static String getConcreteType(TypeParameterizedReactor tpr, final String type) { - if (tpr == null) - return type; - - var wrapper = new Object() { - String concreteType = ""; - final Pair inPair = separateTokensFromTypes(type); - }; - tpr.typeArgs().forEach((literal, concreteType) -> { - if (wrapper.inPair.getFirst().equals(literal)) - { - wrapper.concreteType = String.valueOf(concreteType.getId()); - } - }); - - return wrapper.concreteType.isEmpty() ? type : wrapper.concreteType + wrapper.inPair.getSecond(); - } - public static String generateWidthVariable(String var) { return var + "_width"; } diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 0ae657ed5c..2f70b10825 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import org.lflang.ASTUtils; +import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Instantiation; import org.lflang.lf.Reactor; @@ -48,6 +49,11 @@ public Type resolveType(Type t) { return t; } + public InferredType resolveType(InferredType t) { + if (t.astType.getCode() != null) return InferredType.fromAST(resolveType(t.astType)); + return t; + } + @Override public int hashCode() { return Math.abs(r.hashCode() * 31 + typeArgs.hashCode()); From 957500d3fd4e458dfbae998ffdbacaa259c8a202 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 00:41:31 -0700 Subject: [PATCH 374/709] Delete Pair.java. It is usually recommended in the Java community to create objects specifically for the purpose at hand rather than using general tuple types. --- .../src/org/lflang/generator/c/CUtil.java | 16 ---- org.lflang/src/org/lflang/util/Pair.java | 77 ------------------- 2 files changed, 93 deletions(-) delete mode 100644 org.lflang/src/org/lflang/util/Pair.java diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index b4e88b42ad..aed904d0e6 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -53,7 +53,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.WidthTerm; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; -import org.lflang.util.Pair; /** * A collection of utilities for C code generation. @@ -766,21 +765,6 @@ public static boolean isTokenType(InferredType type, CTypes types) { return type.isVariableSizeList || targetType.trim().endsWith("*"); } - /** - * Given a String str separate the Typename from tokens (* OR []) - * - * @param str Input String - * @return {@link Pair} of Typename and Tokens - * */ - public static Pair separateTokensFromTypes(String str) { - var starIdx = str.indexOf("*"); - if (starIdx == -1) { - var idx = str.indexOf("["); - return idx == -1 ? new Pair<>(str, "") : new Pair<>(str.substring(0, idx), str.substring(idx)); - } - return new Pair<>(str.substring(0, starIdx), str.substring(starIdx)); - } - public static String generateWidthVariable(String var) { return var + "_width"; } diff --git a/org.lflang/src/org/lflang/util/Pair.java b/org.lflang/src/org/lflang/util/Pair.java deleted file mode 100644 index ef2ac123c4..0000000000 --- a/org.lflang/src/org/lflang/util/Pair.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file - * @author Muhammad Khubaib Umer (khubaib@magnition.io) - * - * @section LICENSE -Copyright (c) 2023, MagnitionIO -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @section DESCRIPTION - * - * This Class provides a Pair of Templated Types - * This provides the same facility as std::pair in C++ - */ - -package org.lflang.util; - -public final class Pair { - private final T1 first; - private final T2 second; - public Pair(final T1 t1, final T2 t2) - { - this.first = t1; - this.second = t2; - } - - public T1 getFirst() - { - return this.first; - } - - public T2 getSecond() - { - return this.second; - } - - @Override - public boolean equals(Object other) { - if (other == null) - return false; - if (this == other) - return true; - if (this.getClass().equals(other.getClass())) { - var otherPair = (Pair) other; - boolean isEqual = (first == null) ? otherPair.getFirst() == null : first.equals(otherPair.getFirst()); - - if (!isEqual) - return false; - - return (second == null) ? otherPair.getSecond() == null : second.equals(otherPair.getSecond()); - } - return false; - } - - @Override - public int hashCode() { - return first == null ? 0 : first.hashCode() + 27 * (second == null ? 0 : second.hashCode()); - } - - @Override - public String toString() { - return "Pair<" + first + ", " + second + ">"; - } -} From fa738b10b494c5fb35c5444c04610144be4da8f6 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 00:45:16 -0700 Subject: [PATCH 375/709] Impl of equals must match impl of hashcode. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 2f70b10825..689a2dcc72 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -58,4 +58,9 @@ public InferredType resolveType(InferredType t) { public int hashCode() { return Math.abs(r.hashCode() * 31 + typeArgs.hashCode()); } + + @Override + public boolean equals(Object obj) { + return obj instanceof TypeParameterizedReactor other && r.equals(other.r) && typeArgs.equals(other.typeArgs); + } } From 5f52ca9ffa1af04c4489d6c40cc38117c4f80580 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 00:54:06 -0700 Subject: [PATCH 376/709] Fix NPE and (slightly) dignify a hack. --- org.lflang/src/org/lflang/generator/c/CUtil.java | 3 +-- .../org/lflang/generator/c/InteractingContainedReactors.java | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index aed904d0e6..2c10edccf7 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -761,8 +761,7 @@ private static List multiportWidthTerms(Variable variable) { public static boolean isTokenType(InferredType type, CTypes types) { if (type.isUndefined()) return false; // This is a hacky way to do this. It is now considered to be a bug (#657) - String targetType = types.getVariableDeclaration(null, type, "", false); - return type.isVariableSizeList || targetType.trim().endsWith("*"); + return type.isVariableSizeList || !type.astType.getStars().isEmpty(); } public static String generateWidthVariable(String var) { diff --git a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java index ae6b37437f..26925b7486 100644 --- a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java +++ b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java @@ -7,15 +7,12 @@ import java.util.Set; import org.lflang.ASTUtils; -import org.lflang.federated.generator.FederateInstance; -import org.lflang.generator.NamedInstance; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; @@ -154,4 +151,3 @@ public List reactionsTriggered(Instantiation containedReactor, Port por return new LinkedList<>(); } } - From 5299ca5481e3514f37d613d179826e22e7d473e7 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 01:14:01 -0700 Subject: [PATCH 377/709] Fix another NPE. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 689a2dcc72..9a7a0758e4 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -50,7 +50,7 @@ public Type resolveType(Type t) { } public InferredType resolveType(InferredType t) { - if (t.astType.getCode() != null) return InferredType.fromAST(resolveType(t.astType)); + if (t.astType != null && t.astType.getCode() != null) return InferredType.fromAST(resolveType(t.astType)); return t; } From 7d7abec62fecb7e7b597aae9545e0d19ee257015 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 22 May 2023 06:02:25 -0700 Subject: [PATCH 378/709] Increased times by 10x to attempt to fix flaky tests --- test/C/src/concurrent/Watchdog.lf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/C/src/concurrent/Watchdog.lf b/test/C/src/concurrent/Watchdog.lf index bc8ab1387b..e49b2fcec7 100644 --- a/test/C/src/concurrent/Watchdog.lf +++ b/test/C/src/concurrent/Watchdog.lf @@ -1,16 +1,16 @@ /** - * Test watchdog. This test starts a watchdog timer of 150ms every 100ms. Half + * Test watchdog. This test starts a watchdog timer of 1500ms every 1s. Half * the time, it then sleeps after starting the watchdog so that the watchdog - * expires. There should be a total of five watchdog expirations. + * expires. There should be a total of two watchdog expirations. * @author Benjamin Asch * @author Edward A. Lee */ target C { - timeout: 1100 ms + timeout: 11000 ms } -reactor Watcher(timeout: time = 150 ms) { - timer t(100 ms, 100 ms) // Offset ameliorates startup time. +reactor Watcher(timeout: time = 1500 ms) { + timer t(1s, 1s) // Offset ameliorates startup time. // Period has to be smaller than watchdog timeout. Produced if the watchdog // triggers. output d: int @@ -54,7 +54,7 @@ main reactor { self->count++; if (self->count % 4 == 0) { lf_print(">>>>>> Taking a long time to process that output!"); - lf_sleep(MSEC(160)); + lf_sleep(MSEC(1600)); } =} From 4e1076a89ab822013bc839bf93fbd15f025f7192 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 22 May 2023 06:03:35 -0700 Subject: [PATCH 379/709] Align to reactor-c main --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 843e147128..845daae394 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 843e147128315ffa5216fffd6cba36396c3cd084 +Subproject commit 845daae39479b8c06d15c1215aca575a4728a599 From 093bb69b29ab9d62a3f19a0cb4172fd00147e877 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 22 May 2023 06:06:23 -0700 Subject: [PATCH 380/709] Moved test that fails on mac to failing --- .../C/src/federated/{ => failing}/SimpleFederatedAuthenticated.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/federated/{ => failing}/SimpleFederatedAuthenticated.lf (100%) diff --git a/test/C/src/federated/SimpleFederatedAuthenticated.lf b/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf similarity index 100% rename from test/C/src/federated/SimpleFederatedAuthenticated.lf rename to test/C/src/federated/failing/SimpleFederatedAuthenticated.lf From cccf2aa63526ca0bca4ce8d7e3dda04d44e4730a Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 08:02:57 -0700 Subject: [PATCH 381/709] Fix passing generics test. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 9a7a0758e4..9c0a8787ab 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -43,6 +43,7 @@ public void doDefines(CodeBuilder b) { } public Type resolveType(Type t) { + if (t.getId() != null) return typeArgs.get(t.getId()); if (t.getCode() == null) return t; var arg = typeArgs.get(t.getCode().getBody()); if (arg != null) return arg; @@ -50,8 +51,8 @@ public Type resolveType(Type t) { } public InferredType resolveType(InferredType t) { - if (t.astType != null && t.astType.getCode() != null) return InferredType.fromAST(resolveType(t.astType)); - return t; + if (t.astType == null) return t; + return InferredType.fromAST(resolveType(t.astType)); } @Override From 0093be73441655298bc70c4c99604a0a4f700455 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 08:13:55 -0700 Subject: [PATCH 382/709] Fix NPE. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 9c0a8787ab..9145b70e6d 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -43,7 +43,7 @@ public void doDefines(CodeBuilder b) { } public Type resolveType(Type t) { - if (t.getId() != null) return typeArgs.get(t.getId()); + if (t.getId() != null && typeArgs.get(t.getId()) != null) return typeArgs.get(t.getId()); if (t.getCode() == null) return t; var arg = typeArgs.get(t.getCode().getBody()); if (arg != null) return arg; From 76c048c5c3f83c85c371ef945de34d2b108d1d61 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 08:58:06 -0700 Subject: [PATCH 383/709] More of the stars hack. --- org.lflang/src/org/lflang/generator/c/CUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 2c10edccf7..c09f8c63ef 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -761,7 +761,8 @@ private static List multiportWidthTerms(Variable variable) { public static boolean isTokenType(InferredType type, CTypes types) { if (type.isUndefined()) return false; // This is a hacky way to do this. It is now considered to be a bug (#657) - return type.isVariableSizeList || !type.astType.getStars().isEmpty(); + return type.isVariableSizeList || type.astType != null && (!type.astType.getStars().isEmpty() || + type.astType.getCode() != null && type.astType.getCode().getBody().stripTrailing().endsWith("*")); } public static String generateWidthVariable(String var) { From 47e97d8222919196085abb42afb4e17d2395a901 Mon Sep 17 00:00:00 2001 From: Peter Donovan <33707478+petervdonovan@users.noreply.github.com> Date: Mon, 22 May 2023 12:29:58 -0700 Subject: [PATCH 384/709] Apply suggestions from code review Co-authored-by: Marten Lohstroh --- org.lflang/src/org/lflang/ASTUtils.java | 4 ++-- org.lflang/src/org/lflang/generator/c/CMethodGenerator.java | 2 +- org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 4 ++-- .../src/org/lflang/generator/python/PythonGenerator.java | 2 +- org.lflang/src/org/lflang/validation/LFValidator.java | 2 -- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index b9cacd8f48..7b747b0adb 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -402,8 +402,8 @@ public static List allInstantiations(Reactor definition) { } /** - * Given a reactor Class, returns a set of include names for - * interacting reactors which includes all instantiations of base class that it extends + * Given a reactor Class, return a set of include names for + * interacting reactors which includes all instantiations of base class that it extends. * * @param r Reactor Class * */ diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index 67576f4324..cac2eff8cb 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -56,7 +56,7 @@ public static void generateMacroUndefsForMethods( * This function will have a first argument that is a void* pointing to * the self struct, followed by any arguments given in its definition. * @param method The method. - * @param tpr The reactor declaration. + * @param tpr The concrete reactor class. * @param types The C-specific type conversion functions. */ public static String generateMethod( diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 1dac9d13a9..0f38c82c04 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -280,7 +280,7 @@ private static String generateWatchdogFunction( * Return the start of a C function definition for a watchdog. * * @param watchdog The watchdog - * @param tpr The reactor declaration + * @param tpr The concrete reactor class * @return The function name for the watchdog function. */ private static String generateWatchdogFunctionHeader(Watchdog watchdog, TypeParameterizedReactor tpr) { @@ -292,7 +292,7 @@ private static String generateWatchdogFunctionHeader(Watchdog watchdog, TypePara * Return the name of the watchdog expiration handler function. * * @param watchdog The watchdog - * @param tpr The reactor with the watchdog + * @param tpr The concrete reactor class that has the watchdog * @return Name of the watchdog handler function */ private static String watchdogFunctionName(Watchdog watchdog, TypeParameterizedReactor tpr) { diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index d71be3ebd1..4e41b700ed 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -348,7 +348,7 @@ public void processProtoFile(String filename) { /** * Generate the aliases for inputs, outputs, and struct type definitions for * actions of the specified reactor in the specified federate. - * @param tpr The parsed reactor data structure. + * @param tpr The concrete reactor class. */ @Override public void generateAuxiliaryStructs( diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 94fb578f72..fd37e5a3a7 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -267,8 +267,6 @@ public void checkConnection(Connection connection) { if (type == null) { type = ((Port) port.getVariable()).getType(); } else { - // Unfortunately, xtext does not generate a suitable equals() - // method for AST types, so we have to manually check the types. var portType = ((Port) port.getVariable()).getType(); portType = port.getContainer() == null ? portType : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); if (!sameType(type, portType)) { From 882dd8382f3eed94d8d227b0ea99968a77234b0d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 12:30:55 -0700 Subject: [PATCH 385/709] Add comments. --- .../generator/c/TypeParameterizedReactor.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 9145b70e6d..a1375c61bb 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -12,7 +12,12 @@ import org.lflang.lf.Reactor; import org.lflang.lf.Type; -public record TypeParameterizedReactor(Reactor r, Map typeArgs) { +/** + * A reactor class combined with concrete type arguments bound to its type parameters. + * @param reactor The syntactic reactor class definition + * @param typeArgs The type arguments associated with this particular variant of the reactor class. + */ +public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { public TypeParameterizedReactor(Instantiation i) { this(ASTUtils.toDefinition(i.getReactorClass()), addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); @@ -29,11 +34,13 @@ private static Map addTypeArgs(Instantiation instantiation, Reacto return ret; } + /** Return the name of the reactor given its type arguments. */ public String getName() { // FIXME: Types that are not just a single token need to be escaped or hashed - return r.getName() + typeArgs.values().stream().map(ASTUtils::toOriginalText).collect(Collectors.joining("_")); + return reactor.getName() + typeArgs.values().stream().map(ASTUtils::toOriginalText).collect(Collectors.joining("_")); } + /** #define type names as concrete types. */ public void doDefines(CodeBuilder b) { typeArgs.forEach((literal, concreteType) -> b.pr( "#if defined " + literal + "\n" + @@ -42,6 +49,7 @@ public void doDefines(CodeBuilder b) { "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); } + /** Resolve type arguments if the given type is defined in terms of generics. */ public Type resolveType(Type t) { if (t.getId() != null && typeArgs.get(t.getId()) != null) return typeArgs.get(t.getId()); if (t.getCode() == null) return t; @@ -50,6 +58,7 @@ public Type resolveType(Type t) { return t; } + /** Resolve type arguments if the given type is defined in terms of generics. */ public InferredType resolveType(InferredType t) { if (t.astType == null) return t; return InferredType.fromAST(resolveType(t.astType)); @@ -57,11 +66,11 @@ public InferredType resolveType(InferredType t) { @Override public int hashCode() { - return Math.abs(r.hashCode() * 31 + typeArgs.hashCode()); + return Math.abs(reactor.hashCode() * 31 + typeArgs.hashCode()); } @Override public boolean equals(Object obj) { - return obj instanceof TypeParameterizedReactor other && r.equals(other.r) && typeArgs.equals(other.typeArgs); + return obj instanceof TypeParameterizedReactor other && reactor.equals(other.reactor) && typeArgs.equals(other.typeArgs); } } From 2138d7da8f7985022ceee1d29a00e942e6f67a35 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 12:33:20 -0700 Subject: [PATCH 386/709] Rename tpr.r() -> tpr.reactor(). --- .../lflang/generator/c/CActionGenerator.java | 5 ++--- .../org/lflang/generator/c/CGenerator.java | 22 +++++++++---------- .../lflang/generator/c/CMethodGenerator.java | 8 +++---- .../generator/c/CParameterGenerator.java | 9 +------- .../lflang/generator/c/CPortGenerator.java | 6 ++--- .../generator/c/CReactionGenerator.java | 18 +++++++-------- .../c/CReactorHeaderFileGenerator.java | 17 +++++++------- .../lflang/generator/c/CStateGenerator.java | 9 +------- .../src/org/lflang/generator/c/CUtil.java | 6 ++--- .../generator/c/CWatchdogGenerator.java | 9 ++++---- .../generator/python/PythonGenerator.java | 10 ++++----- 11 files changed, 48 insertions(+), 71 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 0fa79e94ca..600100b41d 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -8,8 +8,7 @@ import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; -import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; + import static org.lflang.generator.c.CGenerator.variableStructType; /** * Generates code for actions (logical or physical) for the C and CCpp target. @@ -98,7 +97,7 @@ public static void generateDeclarations( CodeBuilder body, CodeBuilder constructorCode ) { - for (Action action : ASTUtils.allActions(tpr.r())) { + for (Action action : ASTUtils.allActions(tpr.reactor())) { var actionName = action.getName(); body.pr(action, CGenerator.variableStructType(action, tpr, false)+" _lf_"+actionName+";"); // Initialize the trigger pointer in the action. diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index ea9de156e0..9d17c6bc14 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -888,7 +888,7 @@ private void resolveTemplatedTypes(ReactorInstance reactorInstance, TypeParamete } }); if (!copy.isEmpty()) { // If we found some templated-types update the tpr with new map - child.tpr = new TypeParameterizedReactor(child.tpr.r(), copy); + child.tpr = new TypeParameterizedReactor(child.tpr.reactor(), copy); } resolveTemplatedTypes(child, child.tpr); } @@ -914,9 +914,9 @@ private void generateHeaders() throws IOException { (builder, rr, userFacing) -> { generateAuxiliaryStructs(builder, rr, userFacing); if (userFacing) { - rr.r().getInstantiations().stream() + rr.reactor().getInstantiations().stream() .map(it -> new TypeParameterizedReactorWithDecl(new TypeParameterizedReactor(it), it.getReactorClass())).collect(Collectors.toSet()).forEach(it -> { - ASTUtils.allPorts(it.tpr.r()) + ASTUtils.allPorts(it.tpr.reactor()) .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( it.tpr, p, getTarget(), errorReporter, types, new CodeBuilder(), true, it.decl() ))); @@ -1049,8 +1049,8 @@ private void generateReactorClass(TypeParameterizedReactor tpr) throws IOExcepti header.pr("#ifndef " + guardMacro); header.pr("#define " + guardMacro); generateReactorClassHeaders(tpr, headerName, header, src); - header.pr(generateTopLevelPreambles(tpr.r())); - generateUserPreamblesForReactor(tpr.r(), src); + header.pr(generateTopLevelPreambles(tpr.reactor())); + generateUserPreamblesForReactor(tpr.reactor(), src); generateReactorClassBody(tpr, header, src); header.pr("#endif // " + guardMacro); FileUtil.writeToFile(CodeMap.fromGeneratedCode(header.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(headerName), true); @@ -1075,7 +1075,7 @@ protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); src.pr("#include \"" + headerName + "\""); tpr.doDefines(src); - ASTUtils.allIncludes(tpr.r()).stream().map(name -> "#include \"" + ASTUtils.allIncludes(tpr.reactor()).stream().map(name -> "#include \"" + name + ".h\"").forEach(header::pr); } @@ -1154,7 +1154,7 @@ protected void generateAuxiliaryStructs(CodeBuilder builder, TypeParameterizedRe #endif """, types.getTargetTagType(), types.getTargetTimeType()) ); - for (Port p : allPorts(tpr.r())) { + for (Port p : allPorts(tpr.reactor())) { builder.pr(CPortGenerator.generateAuxiliaryStruct( tpr, p, @@ -1169,7 +1169,7 @@ protected void generateAuxiliaryStructs(CodeBuilder builder, TypeParameterizedRe // The very first item on this struct needs to be // a trigger_t* because the struct will be cast to (trigger_t*) // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(tpr.r())) { + for (Action action : allActions(tpr.reactor())) { builder.pr(CActionGenerator.generateAuxiliaryStruct( tpr, action, @@ -1188,7 +1188,7 @@ protected void generateAuxiliaryStructs(CodeBuilder builder, TypeParameterizedRe * go into the constructor. */ private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tpr, CodeBuilder constructorCode) { - var reactor = toDefinition(tpr.r()); + var reactor = toDefinition(tpr.reactor()); var selfType = CUtil.selfType(tpr); // Construct the typedef for the "self" struct. @@ -1267,7 +1267,7 @@ private void generateInteractingContainedReactors( ) { // The contents of the struct will be collected first so that // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(tpr.r()); + var contained = new InteractingContainedReactors(tpr.reactor()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { var containedTpr = new TypeParameterizedReactor(containedReactor); @@ -1403,7 +1403,7 @@ protected void generateSelfStructExtension( */ public void generateReactions(CodeBuilder src, TypeParameterizedReactor tpr) { var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(tpr.r()); + var reactor = ASTUtils.toDefinition(tpr.reactor()); for (Reaction reaction : allReactions(reactor)) { generateReaction(src, reaction, tpr, reactionIndex); // Increment reaction index even if the reaction is not in the federate diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index cac2eff8cb..691019b160 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -5,10 +5,8 @@ import org.lflang.ASTUtils; import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.ReactorInstance; import org.lflang.lf.Method; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; /** * Collection of functions to generate C code to declare methods. @@ -26,7 +24,7 @@ public static void generateMacrosForMethods( TypeParameterizedReactor tpr, CodeBuilder body ) { - for (Method method : allMethods(tpr.r())) { + for (Method method : allMethods(tpr.reactor())) { var functionName = methodFunctionName(tpr, method); // If the method has no arguments. Do not pass it any variadic arguments. if (method.getArguments().size() > 0) { @@ -103,7 +101,7 @@ public static void generateMethods( CodeBuilder code, CTypes types ) { - var reactor = tpr.r(); + var reactor = tpr.reactor(); code.prComment("***** Start of method declarations."); signatures(tpr, code, types); generateMacrosForMethods(tpr, code); @@ -127,7 +125,7 @@ public static void signatures( CodeBuilder body, CTypes types ) { - Reactor reactor = tpr.r(); + Reactor reactor = tpr.reactor(); for (Method method : allMethods(reactor)) { body.pr(generateMethodSignature(method, tpr, types) + ";"); } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index fc74f76d78..1d563b5de9 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -1,17 +1,10 @@ package org.lflang.generator.c; -import java.util.List; -import java.util.stream.Collectors; - -import org.lflang.InferredType; import org.lflang.generator.ParameterInstance; import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; -import org.lflang.lf.Assignment; -import org.lflang.lf.Expression; import org.lflang.lf.Initializer; import org.lflang.lf.Parameter; -import org.lflang.lf.Reactor; /** * Generates C code to declare and initialize parameters. @@ -45,7 +38,7 @@ public static String getInitializer(ParameterInstance p) { */ public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { CodeBuilder code = new CodeBuilder(); - for (Parameter parameter : ASTUtils.allParameters(reactor.r())) { + for (Parameter parameter : ASTUtils.allParameters(reactor.reactor())) { code.prSourceLineNumber(parameter); code.pr(types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(parameter))) + " " + parameter.getName() + ";"); } diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 51ff72d919..9cdc20db8f 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -9,9 +9,7 @@ import org.lflang.lf.Input; import org.lflang.lf.Output; import org.lflang.lf.Port; -import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; -import org.lflang.lf.Type; import static org.lflang.generator.c.CGenerator.variableStructType; @@ -213,7 +211,7 @@ private static void generateInputDeclarations( CodeBuilder body, CodeBuilder constructorCode ) { - for (Input input : ASTUtils.allInputs(tpr.r())) { + for (Input input : ASTUtils.allInputs(tpr.reactor())) { var inputName = input.getName(); if (ASTUtils.isMultiport(input)) { body.pr(input, String.join("\n", @@ -251,7 +249,7 @@ private static void generateOutputDeclarations( CodeBuilder body, CodeBuilder constructorCode ) { - for (Output output : ASTUtils.allOutputs(tpr.r())) { + for (Output output : ASTUtils.allOutputs(tpr.reactor())) { // If the port is a multiport, create an array to be allocated // at instantiation. var outputName = output.getName(); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 2dbb1a1801..797ab93beb 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -126,7 +126,7 @@ public static String generateInitializationForReaction(String body, // No triggers are given, which means react to any input. // Declare an argument for every input. // NOTE: this does not include contained outputs. - for (Input input : tpr.r().getInputs()) { + for (Input input : tpr.reactor().getInputs()) { reactionInitialization.pr(generateInputVariablesInReaction(input, tpr, types)); } } @@ -161,7 +161,7 @@ public static String generateInitializationForReaction(String body, } } else if (effect.getVariable() instanceof Mode) { // Mode change effect - int idx = ASTUtils.allModes(tpr.r()).indexOf((Mode)effect.getVariable()); + int idx = ASTUtils.allModes(tpr.reactor()).indexOf((Mode)effect.getVariable()); String name = effect.getVariable().getName(); if (idx >= 0) { reactionInitialization.pr( @@ -701,7 +701,7 @@ public static void generateReactionAndTriggerStructs( var startupReactions = new LinkedHashSet(); var shutdownReactions = new LinkedHashSet(); var resetReactions = new LinkedHashSet(); - for (Reaction reaction : ASTUtils.allReactions(tpr.r())) { + for (Reaction reaction : ASTUtils.allReactions(tpr.reactor())) { // Create the reaction_t struct. body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); @@ -771,7 +771,7 @@ public static void generateReactionAndTriggerStructs( "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", reaction.eContainer() instanceof Mode ? - "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+tpr.r().getModes().indexOf((Mode) reaction.eContainer())+"];" : + "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+tpr.reactor().getModes().indexOf((Mode) reaction.eContainer())+"];" : "self->_lf__reaction_"+reactionCount+".mode = NULL;" )); // Increment the reactionCount even if the reaction is not in the federate @@ -781,7 +781,7 @@ public static void generateReactionAndTriggerStructs( // Next, create and initialize the trigger_t objects. // Start with the timers. - for (Timer timer : ASTUtils.allTimers(tpr.r())) { + for (Timer timer : ASTUtils.allTimers(tpr.reactor())) { createTriggerT(body, timer, triggerMap, constructorCode, types); // Since the self struct is allocated using calloc, there is no need to set falsy fields. constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); @@ -802,7 +802,7 @@ public static void generateReactionAndTriggerStructs( } // Next handle actions. - for (Action action : ASTUtils.allActions(tpr.r())) { + for (Action action : ASTUtils.allActions(tpr.reactor())) { createTriggerT(body, action, triggerMap, constructorCode, types); var isPhysical = "true"; if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { @@ -832,12 +832,12 @@ public static void generateReactionAndTriggerStructs( } // Next handle inputs. - for (Input input : ASTUtils.allInputs(tpr.r())) { + for (Input input : ASTUtils.allInputs(tpr.reactor())) { createTriggerT(body, input, triggerMap, constructorCode, types); } // Next handle watchdogs. - for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.r())) { + for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.reactor())) { createTriggerT(body, watchdog, triggerMap, constructorCode, types); } } @@ -1092,7 +1092,7 @@ init, getCode(types, reaction, tpr) generateDeadlineFunctionHeader(tpr, reactionIndex), init, reaction.getDeadline().getCode())); } - CMethodGenerator.generateMacroUndefsForMethods(tpr.r(), code); + CMethodGenerator.generateMacroUndefsForMethods(tpr.reactor(), code); code.pr( "#include " + StringUtil.addDoubleQuotes( CCoreFilesUtils.getCTargetSetUndefHeader())); diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 20d951b271..00ef4c0faa 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -16,7 +16,6 @@ import org.lflang.lf.Reactor; import org.lflang.lf.StateVar; import org.lflang.lf.TriggerRef; -import org.lflang.lf.Type; import org.lflang.lf.TypedVariable; import org.lflang.lf.VarRef; import org.lflang.util.FileUtil; @@ -31,13 +30,13 @@ public interface GenerateAuxiliaryStructs { /** Return the path to the user-visible header file that would be generated for {@code r}. */ public static Path outputPath(TypeParameterizedReactor tpr) { - return Path.of(Path.of(tpr.r().eResource().getURI().toFileString()) + return Path.of(Path.of(tpr.reactor().eResource().getURI().toFileString()) .getFileName().toString().replaceFirst("[.][^.]+$", "")) .resolve(tpr.getName() + ".h"); } public static void doGenerate(CTypes types, TypeParameterizedReactor tpr, CFileConfig fileConfig, GenerateAuxiliaryStructs generator, Function topLevelPreamble) throws IOException { - String contents = generateHeaderFile(types, tpr, generator, topLevelPreamble.apply(tpr.r())); + String contents = generateHeaderFile(types, tpr, generator, topLevelPreamble.apply(tpr.reactor())); FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(tpr))); } private static String generateHeaderFile(CTypes types, TypeParameterizedReactor tpr, GenerateAuxiliaryStructs generator, String topLevelPreamble) { @@ -48,7 +47,7 @@ private static String generateHeaderFile(CTypes types, TypeParameterizedReactor tpr.doDefines(builder); appendSelfStruct(builder, types, tpr); generator.generate(builder, tpr, true); - for (Reaction reaction : tpr.r().getReactions()) { + for (Reaction reaction : tpr.reactor().getReactions()) { appendSignature(builder, types, reaction, tpr); } builder.pr("#endif"); @@ -80,10 +79,10 @@ private static String userFacingSelfType(TypeParameterizedReactor tpr) { private static void appendSelfStruct(CodeBuilder builder, CTypes types, TypeParameterizedReactor tpr) { builder.pr("typedef struct " + userFacingSelfType(tpr) + "{"); - for (Parameter p : tpr.r().getParameters()) { + for (Parameter p : tpr.reactor().getParameters()) { builder.pr(types.getTargetType(p) + " " + p.getName() + ";"); } - for (StateVar s : tpr.r().getStateVars()) { + for (StateVar s : tpr.reactor().getStateVars()) { builder.pr(types.getTargetType(s) + " " + s.getName() + ";"); } builder.pr("int end[0]; // placeholder; MSVC does not compile empty structs"); @@ -108,7 +107,7 @@ private static String getApiSelfStruct(TypeParameterizedReactor tpr) { public static String nonInlineInitialization(Reaction r, TypeParameterizedReactor reactor) { var mainDef = LfFactory.eINSTANCE.createInstantiation(); mainDef.setName(reactor.getName()); - mainDef.setReactorClass(ASTUtils.findMainReactor(reactor.r().eResource())); + mainDef.setReactorClass(ASTUtils.findMainReactor(reactor.reactor().eResource())); return portVariableStream(r, reactor) .map(it -> it.container == null ? "" : it.getWidth() == null ? String.format("%s %s = (%s) %s;", it.getType(false), it.getAlias(), it.getType(false), it.getRvalue()) @@ -121,7 +120,7 @@ public static String nonInlineInitialization(Reaction r, TypeParameterizedReacto it.getType(true).replaceFirst("\\*", ""), it.getAlias(), CReactionGenerator.maxContainedReactorBankWidth( - reactor.r().getInstantiations().stream() + reactor.reactor().getInstantiations().stream() .filter(instantiation -> new TypeParameterizedReactor(instantiation).equals(it.r)) .findAny().orElseThrow(), null, 0, mainDef), @@ -164,7 +163,7 @@ String getType(boolean userFacing) { var typeName = container == null ? CGenerator.variableStructType(tv, r, userFacing) : CPortGenerator.localPortName(container.getReactorClass(), getName()); - var isMultiport = ASTUtils.isMultiport(ASTUtils.allPorts(r.r()).stream() + var isMultiport = ASTUtils.isMultiport(ASTUtils.allPorts(r.reactor()).stream() .filter(it -> it.getName().equals(tv.getName())) .findAny().orElseThrow()); return typeName + "*" + (getWidth() != null ? "*" : "") + (isMultiport ? "*" : ""); diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index 1b75a73ab8..d2e2a56ed8 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -1,16 +1,9 @@ package org.lflang.generator.c; -import java.util.LinkedList; - import org.lflang.ASTUtils; -import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.GeneratorBase; import org.lflang.generator.ModeInstance; import org.lflang.generator.ReactorInstance; -import org.lflang.lf.Expression; -import org.lflang.lf.ParameterReference; -import org.lflang.lf.Reactor; import org.lflang.lf.StateVar; public class CStateGenerator { @@ -21,7 +14,7 @@ public class CStateGenerator { */ public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { CodeBuilder code = new CodeBuilder(); - for (StateVar stateVar : ASTUtils.allStateVars(reactor.r())) { + for (StateVar stateVar : ASTUtils.allStateVars(reactor.reactor())) { code.prSourceLineNumber(stateVar); code.pr(types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(stateVar))) + " " + stateVar.getName() + ";"); } diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index c09f8c63ef..e6f6cbe990 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -141,8 +141,8 @@ public static String channelIndexName(PortInstance port) { * the main reactor or the .lf file). */ public static String getName(TypeParameterizedReactor reactor) { - String name = reactor.r().getName().toLowerCase() + reactor.hashCode(); - if (reactor.r().isMain()) { + String name = reactor.reactor().getName().toLowerCase() + reactor.hashCode(); + if (reactor.reactor().isMain()) { return name + "_main"; } return name; @@ -510,7 +510,7 @@ public static String runtimeIndex(ReactorInstance reactor) { * @return The type of a self struct for the specified reactor class. */ public static String selfType(TypeParameterizedReactor reactor) { - if (reactor.r().isMain()) { + if (reactor.reactor().isMain()) { return "_" + CUtil.getName(reactor) + "_main_self_t"; } return "_" + CUtil.getName(reactor) + "_self_t"; diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 0f38c82c04..856111b559 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -16,7 +16,6 @@ import org.lflang.lf.Mode; import org.lflang.lf.ModeTransition; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.Watchdog; @@ -95,9 +94,9 @@ protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstan protected static void generateWatchdogs( CodeBuilder src, CodeBuilder header, TypeParameterizedReactor tpr, ErrorReporter errorReporter ) { - if (hasWatchdogs(tpr.r())) { + if (hasWatchdogs(tpr.reactor())) { header.pr("#include \"core/threaded/watchdog.h\""); - for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.r())) { + for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.reactor())) { src.pr(generateWatchdogFunction(watchdog, tpr, errorReporter)); } } @@ -112,7 +111,7 @@ protected static void generateWatchdogs( protected static void generateWatchdogStruct( CodeBuilder body, TypeParameterizedReactor tpr, CodeBuilder constructorCode) { - for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.r())) { + for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.reactor())) { String watchdogName = watchdog.getName(); body.pr(watchdog, "watchdog_t _lf_watchdog_" + watchdogName + ";"); @@ -207,7 +206,7 @@ private static String generateInitializationForWatchdog( Variable variable = effect.getVariable(); if (variable instanceof Mode) { // Mode change effect - int idx = ASTUtils.allModes(tpr.r()).indexOf((Mode) effect.getVariable()); + int idx = ASTUtils.allModes(tpr.reactor()).indexOf((Mode) effect.getVariable()); String name = effect.getVariable().getName(); if (idx >= 0) { watchdogInitialization.pr( diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 4e41b700ed..0a10338d56 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -62,8 +62,6 @@ import org.lflang.lf.Port; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; -import org.lflang.lf.Type; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; @@ -354,13 +352,13 @@ public void processProtoFile(String filename) { public void generateAuxiliaryStructs( CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing ) { - for (Input input : ASTUtils.allInputs(tpr.r())) { + for (Input input : ASTUtils.allInputs(tpr.reactor())) { generateAuxiliaryStructsForPort(builder, tpr, input); } - for (Output output : ASTUtils.allOutputs(tpr.r())) { + for (Output output : ASTUtils.allOutputs(tpr.reactor())) { generateAuxiliaryStructsForPort(builder, tpr, output); } - for (Action action : ASTUtils.allActions(tpr.r())) { + for (Action action : ASTUtils.allActions(tpr.reactor())) { generateAuxiliaryStructsForAction(builder, tpr, action); } } @@ -457,7 +455,7 @@ protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { */ @Override protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { - Reactor reactor = ASTUtils.toDefinition(tpr.r()); + Reactor reactor = ASTUtils.toDefinition(tpr.reactor()); // Reactions marked with a `@_c_body` attribute are generated in C if (AttributeUtils.hasCBody(reaction)) { From a5536587595035303d271b2653b153782d6d8592 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 12:35:47 -0700 Subject: [PATCH 387/709] Revert "Align to reactor-c main" This reverts commit 4e1076a89ab822013bc839bf93fbd15f025f7192. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 845daae394..843e147128 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 845daae39479b8c06d15c1215aca575a4728a599 +Subproject commit 843e147128315ffa5216fffd6cba36396c3cd084 From 46b3ace3087b4f7c3f07967b99e04346aee0c325 Mon Sep 17 00:00:00 2001 From: Peter Donovan <33707478+petervdonovan@users.noreply.github.com> Date: Mon, 22 May 2023 12:37:07 -0700 Subject: [PATCH 388/709] Apply suggestions from code review Co-authored-by: Marten Lohstroh --- org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java | 4 ++-- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index 856111b559..b629684bf7 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -105,7 +105,7 @@ protected static void generateWatchdogs( /** * Generate watchdog definitions in the reactor's self struct. * @param body The place to put the definitions - * @param tpr The reactor declaration + * @param tpr The concrete reactor class * @param constructorCode The place to put initialization code. */ protected static void generateWatchdogStruct( @@ -172,7 +172,7 @@ protected static String generateWatchdogTable(int count) { * Generate necessary initialization code inside the body of a watchdog handler. * * @param watchdog The wotchdog - * @param tpr The declaration for the reactor that has the watchdog + * @param tpr The concrete reactor class that has the watchdog */ private static String generateInitializationForWatchdog( Watchdog watchdog, diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index a1375c61bb..0de272b7bf 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -23,7 +23,6 @@ public TypeParameterizedReactor(Instantiation i) { this(ASTUtils.toDefinition(i.getReactorClass()), addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); } - private static Map addTypeArgs(Instantiation instantiation, Reactor r) { HashMap ret = new HashMap<>(); if (instantiation.getTypeArgs() != null) { From 1fef9e6d19b6ca2d1f881fe95589538ae5cd65ac Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 14:42:13 -0700 Subject: [PATCH 389/709] Fix formatting --- test/C/src/concurrent/Watchdog.lf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/C/src/concurrent/Watchdog.lf b/test/C/src/concurrent/Watchdog.lf index e49b2fcec7..a3c9609503 100644 --- a/test/C/src/concurrent/Watchdog.lf +++ b/test/C/src/concurrent/Watchdog.lf @@ -1,6 +1,6 @@ /** - * Test watchdog. This test starts a watchdog timer of 1500ms every 1s. Half - * the time, it then sleeps after starting the watchdog so that the watchdog + * Test watchdog. This test starts a watchdog timer of 1500ms every 1s. Half the + * time, it then sleeps after starting the watchdog so that the watchdog * expires. There should be a total of two watchdog expirations. * @author Benjamin Asch * @author Edward A. Lee @@ -10,7 +10,7 @@ target C { } reactor Watcher(timeout: time = 1500 ms) { - timer t(1s, 1s) // Offset ameliorates startup time. + timer t(1 s, 1 s) // Offset ameliorates startup time. // Period has to be smaller than watchdog timeout. Produced if the watchdog // triggers. output d: int From 779a08cac8d924dd2326488427336ba242bdfccd Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 14:45:13 -0700 Subject: [PATCH 390/709] Move SpuriousDependency.lf to failing. --- test/C/src/federated/{ => failing}/SpuriousDependency.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/federated/{ => failing}/SpuriousDependency.lf (100%) diff --git a/test/C/src/federated/SpuriousDependency.lf b/test/C/src/federated/failing/SpuriousDependency.lf similarity index 100% rename from test/C/src/federated/SpuriousDependency.lf rename to test/C/src/federated/failing/SpuriousDependency.lf From 553e9227a5782990afcc15561daa7ba8295c1b31 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 22 May 2023 15:05:53 -0700 Subject: [PATCH 391/709] Added source_reactor pointer to port structs --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CPortGenerator.java | 4 ++++ .../src/org/lflang/generator/c/CTriggerObjectsGenerator.java | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 1784274083..72da1e1e33 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 17842740830b1fa92eb012a6d007cc78653115b6 +Subproject commit 72da1e1e331a2c27adc53c5ac8739c172c68dfd3 diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index f7e3abc673..d315536139 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -242,6 +242,10 @@ private static void generateInputDeclarations( "self->_lf_"+inputName+" = &self->_lf_default__"+inputName+";" )); } + constructorCode.pr(input, String.join("\n", + "// Set the default source reactor pointer", + "self->_lf_default__"+inputName+"._base.source_reactor = (self_base_t*)self;" + )); } } diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index d7be245cb1..0767b33bff 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -717,6 +717,7 @@ private static String deferredOutputNumDestinations( code.pr("// For reference counting, set num_destinations for port " + output.getFullName() + "."); code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); code.pr(CUtil.portRef(output, sr, sb, sc)+"._base.num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); + code.pr(CUtil.portRef(output, sr, sb, sc)+"._base.source_reactor = (self_base_t*)"+CUtil.reactorRef(reactor, sb)+";"); code.endScopedRangeBlock(sendingRange); } } From af0613df01492393020cdf1fd98b674083a99660 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 15:17:24 -0700 Subject: [PATCH 392/709] Fix JavaDoc in CUtil.java --- .../src/org/lflang/generator/c/CUtil.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index e6f6cbe990..51348915b9 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -152,23 +152,24 @@ public static String getName(TypeParameterizedReactor reactor) { * Return a reference to the specified port. * * The returned string will have one of the following forms: + *
    + *
  • {@code selfStructs[k]->_lf_portName}
  • + *
  • {@code selfStructs[k]->_lf_portName}
  • + *
  • {@code selfStructs[k]->_lf_portName[i]}
  • + *
  • {@code selfStructs[k]->_lf_parent.portName}
  • + *
  • {@code selfStructs[k]->_lf_parent.portName[i]}
  • + *
  • {@code selfStructs[k]->_lf_parent[j].portName}
  • + *
  • {@code selfStructs[k]->_lf_parent[j].portName[i]}
  • + *
* - * * selfStructs[k]->_lf_portName - * * selfStructs[k]->_lf_portName - * * selfStructs[k]->_lf_portName[i] - * * selfStructs[k]->_lf_parent.portName - * * selfStructs[k]->_lf_parent.portName[i] - * * selfStructs[k]->_lf_parent[j].portName - * * selfStructs[k]->_lf_parent[j].portName[i] - * - * where k is the runtime index of either the port's parent - * or the port's parent's parent, the latter when isNested is true. - * The index j is present if the parent is a bank, and - * the index i is present if the port is a multiport. + * where {@code k} is the runtime index of either the port's parent + * or the port's parent's parent, the latter when isNested is {@code true}. + * The index {@code j} is present if the parent is a bank, and + * the index {@code i} is present if the port is a multiport. * * The first two forms are used if isNested is false, * and the remaining four are used if isNested is true. - * Set isNested to true when referencing a port belonging + * Set {@code isNested} to {@code true} when referencing a port belonging * to a contained reactor. * * @param port The port. From d6417278ef983d781ae9b447b3c54d52e628a342 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 15:30:02 -0700 Subject: [PATCH 393/709] Fix JavaDoc in RuntimeRange.java --- .../org/lflang/generator/RuntimeRange.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/RuntimeRange.java b/org.lflang/src/org/lflang/generator/RuntimeRange.java index 219d24eb67..449e6dedf9 100644 --- a/org.lflang/src/org/lflang/generator/RuntimeRange.java +++ b/org.lflang/src/org/lflang/generator/RuntimeRange.java @@ -36,10 +36,11 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (port channels, reactors, reactions, etc.). This class and its derived classes * have the most detailed information about the structure of a Lingua Franca * program. There are three levels of detail: - * - * * The abstract syntax tree (AST). - * * The compile-time instance graph (CIG). - * * The runtime instance graph (RIG). + *
    + *
  • The abstract syntax tree (AST).
  • + *
  • The compile-time instance graph (CIG).
  • + *
  • The runtime instance graph (RIG).
  • + *
* * In the AST, each reactor class is represented once. * In the CIG, each reactor class is represented as many times as it is @@ -340,38 +341,35 @@ public boolean overlaps(RuntimeRange range) { /** * Return a set of identifiers for runtime instances of a parent of this - * RuntimeRange's instance n levels above this RuntimeRange's instance. If n == 1, for + * {@link RuntimeRange}'s instance {@code n} levels above this {@link RuntimeRange}'s instance. If {@code n == 1}, for * example, then this return the identifiers for the parent ReactorInstance. * - * This returns a list of **natural identifiers**, + * This returns a list of natural identifiers, * as defined below, for the instances within the range. * * The resulting list can be used to count the number of distinct - * runtime instances of this RuntimeRange's instance (using n == 0) or any of its parents that + * runtime instances of this RuntimeRange's instance (using {@code n == 0}) or any of its parents that * lie within the range and to provide an index into an array of runtime * instances. * - * Each **natural identifier** is the integer value of a mixed-radix number + * Each natural identifier is the integer value of a mixed-radix number * defined as follows: - * - * * The low-order digit is the index of the runtime instance of i - * within its container. If the NamedInstance - * is a PortInstance, this will be the multiport channel or 0 if it is not a + *
    + *
  • The low-order digit is the index of the runtime instance of {@code i} within its container. + * If the {@link NamedInstance} is a {@code PortInstance}, this will be the multiport channel or {@code 0} if it is not a * multiport. If the NamedInstance is a ReactorInstance, then it will be the bank - * index or 0 if the reactor is not a bank. The radix for this digit will be + * index or {@code 0} if the reactor is not a bank. The radix for this digit will be * the multiport width or bank width or 1 if the NamedInstance is neither a - * multiport nor a bank. - * - * * The next digit will be the bank index of the container of the specified - * NamedInstance or 0 if it is not a bank. - * - * * The remaining digits will be bank indices of containers up to but not - * including the top-level reactor (there is no point in including the top-level - * reactor because it is never a bank). - * - * Each index that is returned can be used as an index into an array of - * runtime instances that is assumed to be in a **natural order**. - * + * multiport nor a bank.
  • + *
  • The next digit will be the bank index of the container of the specified + * {@link NamedInstance} or {@code 0} if it is not a bank.
  • + *
  • The remaining digits will be bank indices of containers up to but not + * including the top-level reactor (there is no point in including the top-level + * reactor because it is never a bank).
  • + *
  • Each index that is returned can be used as an index into an array of + * runtime instances that is assumed to be in a natural order.
  • + *
+ * * @param n The number of levels up of the parent. This is required to be * less than the depth of this RuntimeRange's instance or an exception will be thrown. */ From 3001a6816e16bdc171f231137e44bad47251d92d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 15:32:26 -0700 Subject: [PATCH 394/709] Fix JavaDoc in ReactionInstance.java --- .../src/org/lflang/generator/ReactionInstance.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index cf9dce7013..c904a39127 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -416,18 +416,18 @@ public String getName() { /** * Return an array of runtime instances of this reaction in a - * **natural order**, defined as follows. The position within the + * natural order, defined as follows. The position within the * returned list of the runtime instance is given by a mixed-radix * number where the low-order digit is the bank index within the - * container reactor (or 0 if it is not a bank), the second low order - * digit is the bank index of the container's container (or 0 if + * container reactor (or {@code 0} if it is not a bank), the second low order + * digit is the bank index of the container's container (or {@code 0} if * it is not a bank), etc., until the container that is directly * contained by the top level (the top-level reactor need not be - * included because its index is always 0). + * included because its index is always {@code 0}). * * The size of the returned array is the product of the widths of all of the - * container ReactorInstance objects. If none of these is a bank, - * then the size will be 1. + * container {@link ReactorInstance} objects. If none of these is a bank, + * then the size will be {@code 1}. * * This method creates this array the first time it is called, but then * holds on to it. The array is used by {@link ReactionInstanceGraph} From 0a02978ba0728b12302216911a0da3fd5d90ba0e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 15:32:46 -0700 Subject: [PATCH 395/709] Move AstUtils and AstExtensions. Edit JavaDoc in CGeneraor, CodeBuilder. --- .../src/org/lflang/tests/RuntimeTest.java | 2 +- .../tests/compiler/LetInferenceTests.java | 4 +- .../compiler/LinguaFrancaASTUtilsTest.java | 56 +-- .../LinguaFrancaDependencyAnalysisTest.java | 45 +- .../org/lflang/tests/runtime/CCppTest.java | 2 +- .../org/lflang/tests/runtime/CppRos2Test.java | 3 +- org.lflang/src/org/lflang/AttributeUtils.java | 1 + org.lflang/src/org/lflang/InferredType.java | 17 +- org.lflang/src/org/lflang/ModelInfo.java | 1 + org.lflang/src/org/lflang/TargetProperty.java | 3 +- .../src/org/lflang/{ => ast}/ASTUtils.java | 9 +- .../src/org/lflang/{ => ast}/AstExtensions.kt | 1 + .../ast/DelayedConnectionTransformation.java | 3 - .../src/org/lflang/ast/FormattingUtils.java | 2 - org.lflang/src/org/lflang/ast/ToLf.java | 2 +- org.lflang/src/org/lflang/ast/ToText.java | 4 - org.lflang/src/org/lflang/cli/Lfc.java | 3 +- .../synthesis/LinguaFrancaSynthesis.java | 397 +++++++++--------- .../styles/LinguaFrancaShapeExtensions.java | 384 ++++++++--------- .../federated/extensions/CExtension.java | 2 +- .../federated/extensions/CExtensionUtils.java | 2 +- .../federated/extensions/PythonExtension.java | 2 +- .../federated/extensions/TSExtension.java | 4 +- .../federated/generator/FedASTUtils.java | 2 +- .../federated/generator/FedGenerator.java | 2 +- .../federated/generator/FedMainEmitter.java | 11 +- .../generator/FedPreambleEmitter.java | 5 +- .../federated/generator/FedTargetConfig.java | 2 +- .../federated/generator/FederateInstance.java | 2 +- .../federated/validation/FedValidator.java | 2 +- .../src/org/lflang/generator/CodeBuilder.java | 33 +- .../org/lflang/generator/GeneratorBase.java | 2 +- .../org/lflang/generator/GeneratorUtils.java | 2 +- .../src/org/lflang/generator/LFGenerator.java | 2 +- .../lflang/generator/ParameterInstance.java | 42 +- .../lflang/generator/ReactionInstance.java | 54 +-- .../org/lflang/generator/ReactorInstance.java | 4 +- .../src/org/lflang/generator/TargetTypes.java | 2 +- .../lflang/generator/c/CActionGenerator.java | 2 +- .../generator/c/CDelayBodyGenerator.java | 4 +- .../org/lflang/generator/c/CGenerator.java | 311 ++++++-------- .../lflang/generator/c/CMethodGenerator.java | 4 +- .../lflang/generator/c/CModesGenerator.java | 2 +- .../generator/c/CParameterGenerator.java | 2 +- .../lflang/generator/c/CPortGenerator.java | 2 +- .../generator/c/CReactionGenerator.java | 2 +- .../c/CReactorHeaderFileGenerator.java | 2 +- .../lflang/generator/c/CStateGenerator.java | 2 +- .../generator/c/CTriggerObjectsGenerator.java | 5 +- .../generator/c/CWatchdogGenerator.java | 2 +- .../c/InteractingContainedReactors.java | 2 +- .../generator/c/TypeParameterizedReactor.java | 2 +- .../org/lflang/generator/python/PyUtil.java | 3 - .../python/PythonDelayBodyGenerator.java | 3 +- .../generator/python/PythonGenerator.java | 2 +- .../python/PythonMethodGenerator.java | 2 +- .../python/PythonParameterGenerator.java | 11 +- .../generator/python/PythonPortGenerator.java | 3 +- .../python/PythonPreambleGenerator.java | 2 +- .../python/PythonReactionGenerator.java | 3 +- .../python/PythonReactorGenerator.java | 4 +- .../python/PythonStateGenerator.java | 3 +- .../generator/rust/CargoDependencySpec.java | 2 +- .../org/lflang/generator/rust/RustModel.kt | 3 +- .../org/lflang/generator/rust/RustTypes.kt | 2 +- .../generator/ts/TSDelayBodyGenerator.kt | 3 +- .../generator/ts/TSReactionGenerator.kt | 6 +- .../lflang/generator/ts/TSStateGenerator.kt | 2 +- .../src/org/lflang/generator/ts/TSTypes.java | 2 +- .../org/lflang/graph/InstantiationGraph.java | 2 +- .../lflang/scoping/LFScopeProviderImpl.java | 2 +- .../org/lflang/validation/AttributeSpec.java | 2 +- .../lflang/validation/BaseLFValidator.java | 12 +- .../org/lflang/validation/LFValidator.java | 17 +- 74 files changed, 739 insertions(+), 812 deletions(-) rename org.lflang/src/org/lflang/{ => ast}/ASTUtils.java (99%) rename org.lflang/src/org/lflang/{ => ast}/AstExtensions.kt (99%) diff --git a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java b/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java index 7011b5ed96..77bc6d8034 100644 --- a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java +++ b/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.Target; import org.lflang.tests.TestRegistry.TestCategory; diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java index a78d41ac4d..b3e7814f96 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ -import static org.lflang.ASTUtils.toDefinition; +import static org.lflang.ast.ASTUtils.toDefinition; import javax.inject.Inject; @@ -38,7 +38,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.DefaultErrorReporter; import org.lflang.TimeUnit; import org.lflang.TimeValue; diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java index 918c2c56c2..9c020c0afa 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -13,21 +13,21 @@ this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.tests.compiler; -import static org.lflang.ASTUtils.isInitialized; +import static org.lflang.ast.ASTUtils.isInitialized; import static org.lflang.util.IteratorUtil.asStream; import java.util.List; @@ -42,7 +42,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Instantiation; import org.lflang.lf.Literal; import org.lflang.lf.Model; @@ -52,7 +52,7 @@ /** * Collection of unit tests on the ASTutils. - * + * * @author Christian Menard */ @@ -62,7 +62,7 @@ class LinguaFrancaASTUtilsTest { @Inject ParseHelper parser; - + /** * Test that isInititialized returns true for inititialized state variables */ @@ -82,7 +82,7 @@ public void initializedState() throws Exception { // Java 11: Model model = parser.parse(String.join( System.getProperty("line.separator"), - "target Cpp;", + "target Cpp;", "main reactor {", " state a();", " state b:int(3);", @@ -91,21 +91,21 @@ public void initializedState() throws Exception { " state e(1 sec, 2 sec, 3 sec);", "}" )); - + Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + model.eResource().getErrors()); - + model.eAllContents().forEachRemaining((obj) -> { if (obj instanceof StateVar) { Assertions.assertTrue(isInitialized((StateVar)obj)); } }); } - + /** * Test that isInititialized returns false for uninititialized state variables */ @@ -125,7 +125,7 @@ public void uninitializedState() throws Exception { // Java 11: Model model = parser.parse(String.join( System.getProperty("line.separator"), - "target Cpp;", + "target Cpp;", "main reactor {", " state a;", " state b:int;", @@ -134,7 +134,7 @@ public void uninitializedState() throws Exception { " state e:time;", "}" )); - + Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + @@ -149,7 +149,7 @@ public void uninitializedState() throws Exception { } /** * Return a map from strings to instantiations given a model. - * + * * @param model The model to discover instantiations in. */ private Map getInsts(Model model) { @@ -158,7 +158,7 @@ private Map getInsts(Model model) { .map(obj -> (Instantiation) obj) .collect(Collectors.toMap(Instantiation::getName, it -> it)); } - + /** * Test reading initial values of parameters. * This checks that the example given in the documentation of the @@ -167,7 +167,7 @@ private Map getInsts(Model model) { @Test public void initialValue() throws Exception { -// Java 17: +// Java 17: // Model model = parser.parse(""" // target C; // reactor A(x:int(1)) {} @@ -181,11 +181,11 @@ public void initialValue() throws Exception { // } // """ // Java 11: - + Model model = parser.parse(String.join( System.getProperty("line.separator"), "target C;", - "reactor A(x:int(1)) {}", + "reactor A(x:int(1)) {}", "reactor B(y:int(2)) {", " a1 = new A(x = y);", " a2 = new A(x = -1);", @@ -195,14 +195,14 @@ public void initialValue() throws Exception { " b2 = new B(y = -2);", "}" )); - + Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + model.eResource().getErrors()); - + var map = getInsts(model); - + /* Check for this: * initialValue(x, null) returns 1 * initialValue(x, [a1]) returns 2 @@ -211,13 +211,13 @@ public void initialValue() throws Exception { * initialValue(x, [a2, b1]) returns -1 * initialValue(x, [a1, b2]) returns -2 * initialValue(x, [a2, b2]) returns -1 - * + * * initialValue(y, null) returns 2 * initialValue(y, [a1]) throws an IllegalArgumentException * initialValue(y, [b1]) returns 3 * initialValue(y, [b2]) returns -2 */ - + model.eAllContents().forEachRemaining((obj) -> { if (obj instanceof Parameter) { Parameter parameter = (Parameter)obj; diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java index ef41bd521b..d7e2af48fc 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java @@ -13,15 +13,15 @@ this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.tests.compiler; @@ -30,7 +30,6 @@ import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.EOF; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; @@ -45,7 +44,7 @@ import org.lflang.lf.Model; import org.lflang.lf.Reactor; import org.lflang.tests.LFInjectorProvider; -import static org.lflang.ASTUtils.*; +import static org.lflang.ast.ASTUtils.*; @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) @@ -57,7 +56,7 @@ class LinguaFrancaDependencyAnalysisTest { @Inject ParseHelper parser; - + /** * Check that circular dependencies between reactions are detected. */ @@ -66,27 +65,27 @@ public void cyclicDependency() throws Exception { // Java 17: // String testCase = """ // target C; -// +// // reactor Clock { // timer t(0, 10 msec); // input x:int; // output y:int; // reaction(t) -> y {= -// +// // =} // reaction(x) -> y {= -// +// // =} // } -// +// // reactor A { // input x:int; // output y:int; // reaction(x) -> y {= -// +// // =} // } -// +// // main reactor Loop { // c = new Clock(); // a = new A(); @@ -126,7 +125,7 @@ public void cyclicDependency() throws Exception { "}" ); Model model = parser.parse(testCase); - + Assertions.assertNotNull(model); Instantiation mainDef = null; TreeIterator it = model.eResource().getAllContents(); @@ -137,7 +136,7 @@ public void cyclicDependency() throws Exception { } Reactor reactor = (Reactor) obj; if (reactor.isMain()) { - // Creating an definition for the main reactor because + // Creating an definition for the main reactor because // there isn't one. mainDef = LfFactory.eINSTANCE.createInstantiation(); mainDef.setName(reactor.getName()); @@ -169,13 +168,13 @@ public void circularInstantiation() throws Exception { } """; Model model = parser.parse(testCase); - + Assertions.assertNotNull(model); - + ModelInfo info = new ModelInfo(); info.update(model, new DefaultErrorReporter()); - Assertions.assertTrue(info.instantiationGraph.hasCycles() == true, + Assertions.assertTrue(info.instantiationGraph.hasCycles() == true, "Did not detect cyclic instantiation."); } - + } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java index 17fd386ad8..c8c2fc5b93 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java @@ -2,7 +2,7 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.Target; import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java b/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java index f3b20ee36f..2e4f6b78d3 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java @@ -3,12 +3,11 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.Target; import org.lflang.lf.Element; import org.lflang.lf.LfFactory; import org.lflang.tests.TestBase; -import org.lflang.tests.TestRegistry.TestCategory; /** * Run C++ tests using the ROS2 platform. diff --git a/org.lflang/src/org/lflang/AttributeUtils.java b/org.lflang/src/org/lflang/AttributeUtils.java index ec5edc4b9d..f5077f2d13 100644 --- a/org.lflang/src/org/lflang/AttributeUtils.java +++ b/org.lflang/src/org/lflang/AttributeUtils.java @@ -33,6 +33,7 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Action; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; diff --git a/org.lflang/src/org/lflang/InferredType.java b/org.lflang/src/org/lflang/InferredType.java index 3a9a8712aa..41931e0e32 100644 --- a/org.lflang/src/org/lflang/InferredType.java +++ b/org.lflang/src/org/lflang/InferredType.java @@ -11,15 +11,15 @@ this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ @@ -29,6 +29,7 @@ import org.eclipse.emf.ecore.EObject; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Type; /** diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index fbe5c2047c..24d5c447c2 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Set; +import org.lflang.ast.ASTUtils; import org.lflang.generator.NamedInstance; import org.lflang.generator.ReactorInstance; import org.lflang.graph.InstantiationGraph; diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 25445a3e37..ac3c183e3c 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -38,6 +38,7 @@ import org.lflang.TargetConfig.DockerOptions; import org.lflang.TargetConfig.PlatformOptions; import org.lflang.TargetConfig.TracingOptions; +import org.lflang.ast.ASTUtils; import org.lflang.generator.InvalidLfSourceException; import org.lflang.generator.rust.CargoDependencySpec; import org.lflang.generator.rust.CargoDependencySpec.CargoDependenciesPropertyType; @@ -407,7 +408,7 @@ public enum TargetProperty { /** * Directive to specify the platform for cross code generation. This is either a string of the platform - * or a dictionary of options that includes the string name. + * or a dictionary of options that includes the string name. */ PLATFORM("platform", UnionType.PLATFORM_STRING_OR_DICTIONARY, Target.ALL, (config) -> { diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ast/ASTUtils.java similarity index 99% rename from org.lflang/src/org/lflang/ASTUtils.java rename to org.lflang/src/org/lflang/ast/ASTUtils.java index 7b747b0adb..f6dba5bf4d 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ast/ASTUtils.java @@ -23,7 +23,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.lflang; +package org.lflang.ast; import java.util.ArrayList; import java.util.Collection; @@ -54,10 +54,13 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ast.ToText; + +import org.lflang.InferredType; +import org.lflang.Target; +import org.lflang.TimeUnit; +import org.lflang.TimeValue; import org.lflang.generator.CodeMap; import org.lflang.generator.InvalidSourceException; -import org.lflang.generator.NamedInstance; import org.lflang.generator.ReactorInstance; import org.lflang.generator.c.CUtil; import org.lflang.generator.c.TypeParameterizedReactor; diff --git a/org.lflang/src/org/lflang/AstExtensions.kt b/org.lflang/src/org/lflang/ast/AstExtensions.kt similarity index 99% rename from org.lflang/src/org/lflang/AstExtensions.kt rename to org.lflang/src/org/lflang/ast/AstExtensions.kt index 8f065d530f..26678a2273 100644 --- a/org.lflang/src/org/lflang/AstExtensions.kt +++ b/org.lflang/src/org/lflang/ast/AstExtensions.kt @@ -27,6 +27,7 @@ package org.lflang import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.resource.Resource import org.eclipse.xtext.nodemodel.util.NodeModelUtils +import org.lflang.ast.ASTUtils import org.lflang.lf.* /** diff --git a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java index 85793084d3..9a39b803a9 100644 --- a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java +++ b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java @@ -12,9 +12,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ASTUtils; import org.lflang.InferredType; import org.lflang.generator.DelayBodyGenerator; import org.lflang.generator.TargetTypes; @@ -23,7 +21,6 @@ import org.lflang.lf.Assignment; import org.lflang.lf.Code; import org.lflang.lf.Connection; -import org.lflang.lf.Expression; import org.lflang.lf.Initializer; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; diff --git a/org.lflang/src/org/lflang/ast/FormattingUtils.java b/org.lflang/src/org/lflang/ast/FormattingUtils.java index 0e148f218b..860e3d6bb2 100644 --- a/org.lflang/src/org/lflang/ast/FormattingUtils.java +++ b/org.lflang/src/org/lflang/ast/FormattingUtils.java @@ -11,10 +11,8 @@ import org.eclipse.emf.ecore.EObject; -import org.lflang.ASTUtils; import org.lflang.Target; import org.lflang.lf.Model; -import org.lflang.lf.TargetDecl; /** * Utility functions that determine the specific behavior of the LF formatter. diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 763ae8266c..7ecf04684f 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -20,7 +20,7 @@ import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ASTUtils; + import org.lflang.Target; import org.lflang.ast.MalleableString.Builder; import org.lflang.ast.MalleableString.Joiner; diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 0b703ccbe8..4d02d4ed08 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -1,14 +1,10 @@ package org.lflang.ast; -import java.util.regex.Pattern; - import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.nodemodel.ICompositeNode; import org.eclipse.xtext.nodemodel.ILeafNode; -import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.lflang.ASTUtils; import org.lflang.lf.ArraySpec; import org.lflang.lf.BracedListExpression; import org.lflang.lf.Code; diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index 74d9eac8da..3ef52e54a0 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -13,14 +13,13 @@ import org.eclipse.xtext.generator.JavaIoFileSystemAccess; import org.eclipse.xtext.util.CancelIndicator; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.FileConfig; import org.lflang.TargetProperty.UnionType; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.generator.MainContext; -import org.lflang.generator.ReactorInstance; import com.google.inject.Inject; diff --git a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index 1497ee6644..2b1a2a1bf6 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -11,15 +11,15 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.diagram.synthesis; @@ -62,11 +62,10 @@ import org.eclipse.xtext.xbase.lib.ListExtensions; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.ast.FormattingUtils; -import org.lflang.ast.ToText; import org.lflang.diagram.synthesis.action.CollapseAllReactorsAction; import org.lflang.diagram.synthesis.action.ExpandAllReactorsAction; import org.lflang.diagram.synthesis.action.FilterCycleAction; @@ -136,7 +135,7 @@ /** * Diagram synthesis for Lingua Franca programs. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared @@ -157,9 +156,9 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis { @Inject @Extension private ReactorIcons _reactorIcons; @Inject @Extension private ModeDiagrams _modeDiagrams; @Inject @Extension private LayoutPostProcessing _layoutPostProcessing; - + // ------------------------------------------------------------------------- - + public static final String ID = "org.lflang.diagram.synthesis.LinguaFrancaSynthesis"; // -- INTERNAL -- @@ -168,10 +167,10 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis { public static final Property REACTOR_INPUT = new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.input", false); public static final Property REACTOR_OUTPUT = new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.output", false); public static final Property REACTION_SPECIAL_TRIGGER = new Property<>("org.lflang.linguafranca.diagram.synthesis.reaction.special.trigger", false); - - // -- STYLE -- + + // -- STYLE -- public static final List ALTERNATIVE_DASH_PATTERN = List.of(3.0f); - + // -- TEXT -- public static final String TEXT_ERROR_RECURSIVE = "Recursive reactor instantiation!"; public static final String TEXT_ERROR_CONTAINS_RECURSION = "Reactor contains recursive instantiation!"; @@ -184,18 +183,18 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis { public static final String TEXT_REACTOR_NULL = "Reactor is null"; public static final String TEXT_HIDE_ACTION = "[Hide]"; public static final String TEXT_SHOW_ACTION = "[Details]"; - + // ------------------------------------------------------------------------- - + /** Synthesis category */ public static final SynthesisOption APPEARANCE = SynthesisOption.createCategory("Appearance", true); public static final SynthesisOption EXPERIMENTAL = SynthesisOption.createCategory("Experimental", true); public static final SynthesisOption LAYOUT = SynthesisOption.createCategory("Layout", false).setCategory(LinguaFrancaSynthesis.APPEARANCE); - + /** Synthesis options */ public static final SynthesisOption SHOW_ALL_REACTORS = SynthesisOption.createCheckOption("All Reactors", false); public static final SynthesisOption CYCLE_DETECTION = SynthesisOption.createCheckOption("Dependency Cycle Detection", true); - + public static final SynthesisOption SHOW_USER_LABELS = SynthesisOption.createCheckOption("User Labels (@label in JavaDoc)", true).setCategory(APPEARANCE); public static final SynthesisOption SHOW_HYPERLINKS = SynthesisOption.createCheckOption("Expand/Collapse Hyperlinks", false).setCategory(APPEARANCE); public static final SynthesisOption REACTIONS_USE_HYPEREDGES = SynthesisOption.createCheckOption("Bundled Dependencies", false).setCategory(APPEARANCE); @@ -210,13 +209,13 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis { public static final SynthesisOption REACTOR_PARAMETER_MODE = SynthesisOption.createChoiceOption("Reactor Parameters", ((List)Conversions.doWrapArray(ReactorParameterDisplayModes.values())), ReactorParameterDisplayModes.NONE).setCategory(APPEARANCE); public static final SynthesisOption SHOW_STATE_VARIABLES = SynthesisOption.createCheckOption("Reactor State Variables", false).setCategory(APPEARANCE); public static final SynthesisOption REACTOR_BODY_TABLE_COLS = SynthesisOption.createRangeOption("Reactor Parameter/Variable Columns", 1, 10, 1).setCategory(APPEARANCE); - + public static final SynthesisOption SPACING = SynthesisOption.createRangeOption("Spacing (%)", 0, 150, 5, 75).setCategory(LAYOUT); - + /** Synthesis actions */ public static final DisplayedActionData COLLAPSE_ALL = DisplayedActionData.create(CollapseAllReactorsAction.ID, "Hide all Details"); public static final DisplayedActionData EXPAND_ALL = DisplayedActionData.create(ExpandAllReactorsAction.ID, "Show all Details"); - + @Override public List getDisplayedSynthesisOptions() { return List.of( @@ -247,14 +246,14 @@ public List getDisplayedSynthesisOptions() { SPACING ); } - + @Override public List getDisplayedActions() { return List.of(COLLAPSE_ALL, EXPAND_ALL); } - + // ------------------------------------------------------------------------- - + @Override public KNode transform(final Model model) { KNode rootNode = _kNodeExtensions.createNode(); @@ -273,22 +272,22 @@ public KNode transform(final Model model) { _linguaFrancaShapeExtensions.addErrorMessage(messageNode, TEXT_NO_MAIN_REACTOR, null); rootNode.getChildren().add(messageNode); } - + // Show all reactors if (main == null || getBooleanValue(SHOW_ALL_REACTORS)) { List reactorNodes = new ArrayList<>(); for (Reactor reactor : model.getReactors()) { if (reactor == main) continue; ReactorInstance reactorInstance = new ReactorInstance(reactor, new SynthesisErrorReporter()); - reactorNodes.addAll(createReactorNode(reactorInstance, main == null, - HashBasedTable.create(), - HashBasedTable.create(), + reactorNodes.addAll(createReactorNode(reactorInstance, main == null, + HashBasedTable.create(), + HashBasedTable.create(), new HashMap<>())); } if (!reactorNodes.isEmpty()) { // To allow ordering, we need box layout but we also need layered layout for ports thus wrap all node reactorNodes.add(0, IterableExtensions.head(rootNode.getChildren())); - + int index = 0; for (KNode node : reactorNodes) { // Element could be null if there is no main reactor and Show All Reactors is checked. @@ -310,23 +309,23 @@ public KNode transform(final Model model) { rootNode.getChildren().add(child); index++; } - + setLayoutOption(rootNode, CoreOptions.ALGORITHM, BoxLayouterOptions.ALGORITHM_ID); setLayoutOption(rootNode, CoreOptions.SPACING_NODE_NODE, 25.0); } } } catch (Exception e) { e.printStackTrace(); - + KNode messageNode = _kNodeExtensions.createNode(); - _linguaFrancaShapeExtensions.addErrorMessage(messageNode, "Error in Diagram Synthesis", + _linguaFrancaShapeExtensions.addErrorMessage(messageNode, "Error in Diagram Synthesis", e.getClass().getSimpleName() + " occurred. Could not create diagram."); rootNode.getChildren().add(messageNode); } return rootNode; } - + private Collection createReactorNode( ReactorInstance reactorInstance, boolean expandDefault, @@ -341,7 +340,7 @@ private Collection createReactorNode( _utilityExtensions.setID(node, reactorInstance.uniqueID()); // save to distinguish nodes associated with the same reactor NamedInstanceUtil.linkInstance(node, reactorInstance); - + List nodes = new ArrayList<>(); nodes.add(node); String label = createReactorLabel(reactorInstance); @@ -352,28 +351,28 @@ private Collection createReactorNode( // Mark root allReactorNodes.get(reactorInstance.root()).setProperty(REACTOR_RECURSIVE_INSTANTIATION, true); } - + if (reactor == null) { _linguaFrancaShapeExtensions.addErrorMessage(node, TEXT_REACTOR_NULL, null); } else if (reactorInstance.isMainOrFederated()) { KRoundedRectangle figure = _linguaFrancaShapeExtensions.addMainReactorFigure(node, reactorInstance, label); - - if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE + + if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE && !reactorInstance.parameters.isEmpty() ) { KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(figure); _kRenderingExtensions.setInvisible(rectangle, true); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 6, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 6, 0, _kRenderingExtensions.BOTTOM, 4, 0); _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); addParameterList(rectangle, reactorInstance.parameters); } - + if (getBooleanValue(SHOW_STATE_VARIABLES)) { var variables = ASTUtils.collectElements(reactor, LfPackage.eINSTANCE.getReactor_StateVars(), true, false); if (!variables.isEmpty()) { @@ -381,10 +380,10 @@ private Collection createReactorNode( _kRenderingExtensions.setInvisible(rectangle, true); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 6, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 6, 0, _kRenderingExtensions.BOTTOM, 4, 0); _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); addStateVariableList(rectangle, variables); @@ -396,9 +395,9 @@ private Collection createReactorNode( _linguaFrancaStyleExtensions.errorStyle(figure); } else { _kContainerRenderingExtensions.addChildArea(figure); - node.getChildren().addAll(transformReactorNetwork(reactorInstance, - new HashMap<>(), - new HashMap<>(), + node.getChildren().addAll(transformReactorNetwork(reactorInstance, + new HashMap<>(), + new HashMap<>(), allReactorNodes)); } Iterables.addAll(nodes, createUserComments(reactor, node)); @@ -406,7 +405,7 @@ private Collection createReactorNode( _layoutPostProcessing.configureMainReactor(node); } else { ReactorInstance instance = reactorInstance; - + // Expanded Rectangle ReactorFigureComponents comps = _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label); comps.getOuter().setProperty(KlighdProperties.EXPANDED_RENDERING, true); @@ -415,46 +414,46 @@ private Collection createReactorNode( _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID); } _reactorIcons.handleIcon(comps.getReactor(), reactor, false); - + if (getBooleanValue(SHOW_HYPERLINKS)) { // Collapse button KText button = _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_HIDE_ACTION); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(button), - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 8, 0, + _kRenderingExtensions.setGridPlacementData(button), + _kRenderingExtensions.LEFT, 8, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 0, 0); _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID); _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID); } - - if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE + + if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE && !instance.parameters.isEmpty()) { KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(comps.getReactor()); _kRenderingExtensions.setInvisible(rectangle, true); if (!getBooleanValue(SHOW_HYPERLINKS)) { _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 6, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 6, 0, _kRenderingExtensions.BOTTOM, 4, 0); } else { _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 4, 0), - _kRenderingExtensions.RIGHT, 6, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 6, 0, + _kRenderingExtensions.TOP, 4, 0), + _kRenderingExtensions.RIGHT, 6, 0, _kRenderingExtensions.BOTTOM, 0, 0); } _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); addParameterList(rectangle, instance.parameters); } - + if (getBooleanValue(SHOW_STATE_VARIABLES)) { var variables = ASTUtils.collectElements(reactor, LfPackage.eINSTANCE.getReactor_StateVars(), true, false); if (!variables.isEmpty()) { @@ -463,25 +462,25 @@ private Collection createReactorNode( if (!getBooleanValue(SHOW_HYPERLINKS)) { _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 6, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 6, 0, _kRenderingExtensions.BOTTOM, 4, 0); } else { _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 4, 0), - _kRenderingExtensions.RIGHT, 6, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 6, 0, + _kRenderingExtensions.TOP, 4, 0), + _kRenderingExtensions.RIGHT, 6, 0, _kRenderingExtensions.BOTTOM, 0, 0); } _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); addStateVariableList(rectangle, variables); } } - + if (instance.recursive) { comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle); } else { @@ -498,28 +497,28 @@ private Collection createReactorNode( } } _reactorIcons.handleIcon(comps.getReactor(), reactor, true); - + if (getBooleanValue(SHOW_HYPERLINKS)) { // Expand button if (_utilityExtensions.hasContent(instance) && !instance.recursive) { KText button = _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_SHOW_ACTION); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(button), - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 8, 0, + _kRenderingExtensions.setGridPlacementData(button), + _kRenderingExtensions.LEFT, 8, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 8, 0); _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID); _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID); } } - + if (instance.recursive) { comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle); } - - + + // Create ports Map inputPorts = new HashMap<>(); Map outputPorts = new HashMap<>(); @@ -541,7 +540,7 @@ private Collection createReactorNode( if (_utilityExtensions.hasContent(instance) && !instance.recursive) { node.getChildren().addAll(transformReactorNetwork(instance, inputPorts, outputPorts, allReactorNodes)); } - + // Pass port to given tables if (!_utilityExtensions.isRoot(instance)) { if (inputPortsReg != null) { @@ -555,17 +554,17 @@ private Collection createReactorNode( } } } - + if (instance.recursive) { setLayoutOption(node, KlighdProperties.EXPAND, false); nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE)); } else { setLayoutOption(node, KlighdProperties.EXPAND, expandDefault); - + // Interface Dependencies _interfaceDependenciesVisualization.addInterfaceDependencies(node, expandDefault); } - + if (!_utilityExtensions.isRoot(instance)) { // If all reactors are being shown, then only put the label on // the reactor definition, not on its instances. Otherwise, @@ -581,7 +580,7 @@ private Collection createReactorNode( } // Find and annotate cycles - if (getBooleanValue(CYCLE_DETECTION) && + if (getBooleanValue(CYCLE_DETECTION) && _utilityExtensions.isRoot(reactorInstance)) { KNode errNode = detectAndAnnotateCycles(node, reactorInstance, allReactorNodes); if (errNode != null) { @@ -591,7 +590,7 @@ private Collection createReactorNode( return nodes; } - + public KNode configureReactorNodeLayout(KNode node, boolean main) { // Set layered algorithm setLayoutOption(node, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); @@ -599,12 +598,12 @@ public KNode configureReactorNodeLayout(KNode node, boolean main) { setLayoutOption(node, CoreOptions.DIRECTION, Direction.RIGHT); // Center free floating children setLayoutOption(node, CoreOptions.CONTENT_ALIGNMENT, ContentAlignment.centerCenter()); - + // Balanced placement with straight long edges. setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.NETWORK_SIMPLEX); // Do not shrink nodes below content setLayoutOption(node, CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.PORTS)); - + // Allows to freely shuffle ports on each side setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); // Adjust port label spacing to be closer to edge but not overlap with port figure @@ -612,18 +611,18 @@ public KNode configureReactorNodeLayout(KNode node, boolean main) { setLayoutOption(node, CoreOptions.PORT_LABELS_PLACEMENT, EnumSet.of(PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE)); setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_HORIZONTAL, 2.0); setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_VERTICAL, -3.0); - + // Configure spacing if (!getBooleanValue(SHOW_HYPERLINKS)) { // Hyperlink version is more relaxed in terms of space var factor = (double) getIntValue(SPACING) / 100; - + setLayoutOption(node, LayeredOptions.SPACING_COMPONENT_COMPONENT, LayeredOptions.SPACING_COMPONENT_COMPONENT.getDefault() * factor); - + setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE, LayeredOptions.SPACING_NODE_NODE.getDefault() * factor); setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS.getDefault() * factor); setLayoutOption(node, LayeredOptions.SPACING_PORT_PORT, LayeredOptions.SPACING_PORT_PORT.getDefault() * factor); - + setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE, LayeredOptions.SPACING_EDGE_NODE.getDefault() * factor); setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * factor); setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE, LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor); @@ -631,7 +630,7 @@ public KNode configureReactorNodeLayout(KNode node, boolean main) { setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE, LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor); setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor); setLayoutOption(node, LayeredOptions.SPACING_EDGE_LABEL, LayeredOptions.SPACING_EDGE_LABEL.getDefault() * factor); - + // Padding for sub graph if (main) { // Special handing for main reactors setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(-1, 6, 6, 6)); @@ -639,17 +638,17 @@ public KNode configureReactorNodeLayout(KNode node, boolean main) { setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(2, 6, 6, 6)); } } - + return node; } - + private KNode detectAndAnnotateCycles(KNode node, ReactorInstance reactorInstance, Map allReactorNodes) { if (node.getProperty(REACTOR_RECURSIVE_INSTANTIATION)) { _filterCycleAction.resetCycleFiltering(node); return addErrorComment(node, TEXT_ERROR_CONTAINS_RECURSION); } else { // only detect dependency cycles if not recursive try { - boolean hasCycle = _cycleVisualization.detectAndHighlightCycles(reactorInstance, + boolean hasCycle = _cycleVisualization.detectAndHighlightCycles(reactorInstance, allReactorNodes, it -> { if (it instanceof KNode) { List renderings = IterableExtensions.toList( @@ -662,75 +661,75 @@ private KNode detectAndAnnotateCycles(KNode node, ReactorInstance reactorInstanc }).forEach(_linguaFrancaStyleExtensions::errorStyle); } } else if (it instanceof KEdge) { - Iterables.filter(((KEdge) it).getData(), + Iterables.filter(((KEdge) it).getData(), KRendering.class).forEach(_linguaFrancaStyleExtensions::errorStyle); // TODO initiallyHide does not work with incremental (https://github.com/kieler/KLighD/issues/37) // cycleEgde.initiallyShow() // Show hidden order dependencies _kRenderingExtensions.setInvisible(_kRenderingExtensions.getKRendering(it), false); } else if (it instanceof KPort) { - Iterables.filter(((KPort) it).getData(), + Iterables.filter(((KPort) it).getData(), KRendering.class).forEach(_linguaFrancaStyleExtensions::errorStyle); //it.reverseTrianglePort() } }); - + if (hasCycle) { KNode err = addErrorComment(node, TEXT_ERROR_CONTAINS_CYCLE); - + // Add to existing figure KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(_kRenderingExtensions.getKContainerRendering(err)); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 3, 0, + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, 3, 0, _kRenderingExtensions.TOP, (-1), 0), - _kRenderingExtensions.RIGHT, 3, 0, + _kRenderingExtensions.RIGHT, 3, 0, _kRenderingExtensions.BOTTOM, 3, 0); _linguaFrancaStyleExtensions.noSelectionStyle(rectangle); _kRenderingExtensions.setInvisible(rectangle, true); _kContainerRenderingExtensions.setGridPlacement(rectangle, 2); - + KRectangle subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(subrectangle), - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 2, 0, + _kRenderingExtensions.setGridPlacementData(subrectangle), + _kRenderingExtensions.LEFT, 0, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 2, 0, _kRenderingExtensions.BOTTOM, 0, 0); _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle); _kRenderingExtensions.addSingleClickAction(subrectangle, ShowCycleAction.ID); - + KText subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, TEXT_ERROR_CYCLE_BTN_SHOW); // Copy text style List styles = ListExtensions.map( IterableExtensions.head( - _kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), + _kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), EcoreUtil::copy); subrectangleText.getStyles().addAll(styles); _kRenderingExtensions.setFontSize(subrectangleText, 5); _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0); _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText); _kRenderingExtensions.addSingleClickAction(subrectangleText, ShowCycleAction.ID); - + subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle); _kRenderingExtensions.to( _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(subrectangle), - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 0, 0, + _kRenderingExtensions.setGridPlacementData(subrectangle), + _kRenderingExtensions.LEFT, 0, 0, + _kRenderingExtensions.TOP, 0, 0), + _kRenderingExtensions.RIGHT, 0, 0, _kRenderingExtensions.BOTTOM, 0, 0); _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle); _kRenderingExtensions.addSingleClickAction(subrectangle, FilterCycleAction.ID); - - subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, - _filterCycleAction.isCycleFiltered(node) ? + + subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, + _filterCycleAction.isCycleFiltered(node) ? TEXT_ERROR_CYCLE_BTN_UNFILTER : TEXT_ERROR_CYCLE_BTN_FILTER); // Copy text style styles = ListExtensions.map( IterableExtensions.head( - _kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), + _kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), EcoreUtil::copy); subrectangleText.getStyles().addAll(styles); _kRenderingExtensions.setFontSize(subrectangleText, 5); @@ -738,7 +737,7 @@ private KNode detectAndAnnotateCycles(KNode node, ReactorInstance reactorInstanc _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText); _kRenderingExtensions.addSingleClickAction(subrectangleText, FilterCycleAction.ID); _filterCycleAction.markCycleFilterText(subrectangleText, err); - + // if user interactively requested a filtered diagram keep it filtered during updates if (_filterCycleAction.isCycleFiltered(node)) { _filterCycleAction.filterCycle(node); @@ -780,15 +779,15 @@ private Collection transformReactorNetwork( for (ReactorInstance child : reactorInstance.children) { Boolean expansionState = MemorizingExpandCollapseAction.getExpansionState(child); Collection rNodes = createReactorNode( - child, - expansionState != null ? expansionState : false, - inputPorts, - outputPorts, + child, + expansionState != null ? expansionState : false, + inputPorts, + outputPorts, allReactorNodes); nodes.addAll(rNodes); index++; } - + // Create timers for (TimerInstance timer : reactorInstance.timers) { KNode node = associateWith(_kNodeExtensions.createNode(), timer.getDefinition()); @@ -810,11 +809,11 @@ private Collection transformReactorNetwork( nodes.add(node); Iterables.addAll(nodes, createUserComments(reaction.getDefinition(), node)); reactionNodes.put(reaction, node); - + setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); _layoutPostProcessing.configureReaction(node); setLayoutOption(node, LayeredOptions.POSITION, new KVector(0, idx + 1)); // try order reactions vertically if in one layer (+1 to account for startup) - + var figure = _linguaFrancaShapeExtensions.addReactionFigure(node, reaction); int inputSize = Stream.concat(reaction.triggers.stream(), reaction.sources.stream()).collect(Collectors.toSet()).size(); @@ -824,7 +823,7 @@ private Collection transformReactorNetwork( // pointy shape. However, this is only possible after the layout. ReactionPortAdjustment.apply(node, figure); } - + // connect input KPort port = null; for (TriggerInstance trigger : reaction.triggers) { @@ -832,27 +831,27 @@ private Collection transformReactorNetwork( if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { port = addInvisiblePort(node); setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); - + if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || inputSize == 1) { // manual adjustment disabling automatic one setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS); } } - + if (trigger.isStartup()) { - connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), - startupNode, + connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), + startupNode, port); startup = trigger; } else if (trigger.isShutdown()) { - connect(createDelayEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), - shutdownNode, + connect(createDelayEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), + shutdownNode, port); shutdown = trigger; } else if (trigger.isReset()) { - connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), - resetNode, + connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), + resetNode, port); reset = trigger; } else if (trigger instanceof ActionInstance) { @@ -875,7 +874,7 @@ private Collection transformReactorNetwork( } } } - + // connect dependencies for (TriggerInstance dep : reaction.sources) { if (reaction.triggers.contains(dep)) continue; // skip @@ -884,14 +883,14 @@ private Collection transformReactorNetwork( if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { port = addInvisiblePort(node); setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); - + if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || inputSize == 1) { // manual adjustment disabling automatic one - setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, + setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS); } } - + if (dep instanceof PortInstance) { KPort src = null; PortInstance depAsPort = (PortInstance) dep; @@ -905,7 +904,7 @@ private Collection transformReactorNetwork( } } } - + // connect outputs port = null; // enforce new ports for outputs Set> iterSet = reaction.effects != null ? reaction.effects : new HashSet<>(); @@ -915,7 +914,7 @@ private Collection transformReactorNetwork( port = addInvisiblePort(node); setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST); } - + if (effect instanceof ActionInstance) { actionSources.put((ActionInstance) effect, port); } else if (effect instanceof PortInstance) { @@ -932,12 +931,12 @@ private Collection transformReactorNetwork( } } } - + // Connect actions Set actions = new HashSet<>(); actions.addAll(actionSources.keySet()); actions.addAll(actionDestinations.keySet()); - + for (ActionInstance action : actions) { KNode node = associateWith(_kNodeExtensions.createNode(), action.getDefinition()); NamedInstanceUtil.linkInstance(node, action); @@ -947,23 +946,23 @@ private Collection transformReactorNetwork( setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); _layoutPostProcessing.configureAction(node); Pair ports = _linguaFrancaShapeExtensions.addActionFigureAndPorts( - node, + node, action.isPhysical() ? "P" : "L"); // TODO handle variables? if (action.getMinDelay() != null && action.getMinDelay() != ActionInstance.DEFAULT_MIN_DELAY) { _kLabelExtensions.addOutsideBottomCenteredNodeLabel( - node, - String.format("min delay: %s", action.getMinDelay().toString()), + node, + String.format("min delay: %s", action.getMinDelay().toString()), 7); } // TODO default value? if (action.getDefinition().getMinSpacing() != null) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, + _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, String.format("min spacing: %s", action.getMinSpacing().toString()), 7); } if (!StringExtensions.isNullOrEmpty(action.getDefinition().getPolicy())) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, + _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, String.format("policy: %s", action.getPolicy().toString()), 7); } @@ -971,13 +970,13 @@ private Collection transformReactorNetwork( for (KPort source : actionSources.get(action)) { connect(createDelayEdge(action), source, ports.getKey()); } - + // connect targets for (KPort target : actionDestinations.get(action)) { connect(createDelayEdge(action), ports.getValue(), target); } } - + // Transform connections. // First, collect all the source ports. List sourcePorts = new LinkedList<>(reactorInstance.inputs); @@ -986,15 +985,15 @@ private Collection transformReactorNetwork( } for (PortInstance leftPort : sourcePorts) { - KPort source = leftPort.getParent() == reactorInstance ? - parentInputPorts.get(leftPort) : + KPort source = leftPort.getParent() == reactorInstance ? + parentInputPorts.get(leftPort) : outputPorts.get(leftPort.getParent(), leftPort); - + for (SendRange sendRange : leftPort.getDependentPorts()) { for (RuntimeRange rightRange : sendRange.destinations) { PortInstance rightPort = rightRange.instance; - KPort target = rightPort.getParent() == reactorInstance ? - parentOutputPorts.get(rightPort) : + KPort target = rightPort.getParent() == reactorInstance ? + parentOutputPorts.get(rightPort) : inputPorts.get(rightPort.getParent(), rightPort); // There should be a connection, but skip if not. Connection connection = sendRange.connection; @@ -1004,14 +1003,14 @@ private Collection transformReactorNetwork( KLabel delayLabel = _kLabelExtensions.addCenterEdgeLabel(edge, ASTUtils.toOriginalText(connection.getDelay())); associateWith(delayLabel, connection.getDelay()); if (connection.isPhysical()) { - _linguaFrancaStyleExtensions.applyOnEdgePysicalDelayStyle(delayLabel, + _linguaFrancaStyleExtensions.applyOnEdgePysicalDelayStyle(delayLabel, reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95); } else { _linguaFrancaStyleExtensions.applyOnEdgeDelayStyle(delayLabel); } } else if (connection.isPhysical()) { KLabel physicalConnectionLabel = _kLabelExtensions.addCenterEdgeLabel(edge, "---"); - _linguaFrancaStyleExtensions.applyOnEdgePysicalStyle(physicalConnectionLabel, + _linguaFrancaStyleExtensions.applyOnEdgePysicalStyle(physicalConnectionLabel, reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95); } if (source != null && target != null) { @@ -1028,7 +1027,7 @@ private Collection transformReactorNetwork( directConnectionDummyNodes.put(target, dummy); _kRenderingExtensions.addInvisibleContainerRendering(dummy); _kNodeExtensions.setNodeSize(dummy, 0, 0); - KEdge extraEdge = createIODependencyEdge(null, + KEdge extraEdge = createIODependencyEdge(null, (leftPort.isMultiport() || rightPort.isMultiport())); connect(extraEdge, dummy, target); } @@ -1053,7 +1052,7 @@ private Collection transformReactorNetwork( setLayoutOption(startupNode, LayeredOptions.POSITION, new KVector(0, 0)); setLayoutOption(startupNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); _layoutPostProcessing.configureAction(startupNode); - + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { KPort port = addInvisiblePort(startupNode); startupNode.getOutgoingEdges().forEach(it -> { @@ -1070,7 +1069,7 @@ private Collection transformReactorNetwork( // try to order with reactions vertically if in one layer _layoutPostProcessing.configureShutDown(shutdownNode); setLayoutOption(shutdownNode, LayeredOptions.POSITION, new KVector(0, reactorInstance.reactions.size() + 1)); - + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port KPort port = addInvisiblePort(shutdownNode); shutdownNode.getOutgoingEdges().forEach(it -> { @@ -1087,7 +1086,7 @@ private Collection transformReactorNetwork( // try to order with reactions vertically if in one layer setLayoutOption(resetNode, LayeredOptions.POSITION, new KVector(0, 0.5)); setLayoutOption(resetNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); - + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port KPort port = addInvisiblePort(resetNode); resetNode.getOutgoingEdges().forEach(it -> { @@ -1095,7 +1094,7 @@ private Collection transformReactorNetwork( }); } } - + // Postprocess timer nodes if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port for (KNode timerNode : timerNodes.values()) { @@ -1105,36 +1104,36 @@ private Collection transformReactorNetwork( }); } } - + // Add reaction order edges (add last to have them on top of other edges) if (reactorInstance.reactions.size() > 1) { KNode prevNode = reactionNodes.get(IterableExtensions.head(reactorInstance.reactions)); Iterable iterList = IterableExtensions.map( - IterableExtensions.drop(reactorInstance.reactions, 1), + IterableExtensions.drop(reactorInstance.reactions, 1), reactionNodes::get); for (KNode node : iterList) { KEdge edge = createOrderEdge(); edge.setSource(prevNode); edge.setTarget(node); edge.setProperty(CoreOptions.NO_LAYOUT, true); - + // Do not remove them, as they are needed for cycle detection KRendering edgeRendering = _kRenderingExtensions.getKRendering(edge); _kRenderingExtensions.setInvisible(edgeRendering, !getBooleanValue(SHOW_REACTION_ORDER_EDGES)); _kRenderingExtensions.getInvisible(edgeRendering).setPropagateToChildren(true); // TODO this does not work work with incremental update (https://github.com/kieler/KLighD/issues/37) // if (!getBooleanValue(SHOW_REACTION_ORDER_EDGES)) edge.initiallyHide() - + prevNode = node; } } _layoutPostProcessing.orderChildren(nodes); _modeDiagrams.handleModes(nodes, reactorInstance); - + return nodes; } - + private String createReactorLabel(ReactorInstance reactorInstance) { StringBuilder b = new StringBuilder(); if (getBooleanValue(SHOW_INSTANCE_NAMES) && !_utilityExtensions.isRoot(reactorInstance)) { @@ -1158,7 +1157,7 @@ private String createReactorLabel(ReactorInstance reactorInstance) { if (reactorInstance.parameters.isEmpty()) { b.append("()"); } else { - b.append(IterableExtensions.join(reactorInstance.parameters, "(", ", ", ")", + b.append(IterableExtensions.join(reactorInstance.parameters, "(", ", ", ")", it -> { return createParameterLabel(it); })); @@ -1166,7 +1165,7 @@ private String createReactorLabel(ReactorInstance reactorInstance) { } return b.toString(); } - + private void addParameterList(KContainerRendering container, List parameters) { int cols = 1; try { @@ -1182,7 +1181,7 @@ private void addParameterList(KContainerRendering container, List variables) { int cols = 1; try { @@ -1213,7 +1212,7 @@ public void addStateVariableList(KContainerRendering container, List v _kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT); } } - + private String createStateVariableLabel(StateVar variable) { StringBuilder b = new StringBuilder(); b.append(variable.getName()); @@ -1226,7 +1225,7 @@ private String createStateVariableLabel(StateVar variable) { } return b.toString(); } - + private KEdge createDelayEdge(Object associate) { KEdge edge = _kEdgeExtensions.createEdge(); associateWith(edge, associate); @@ -1241,7 +1240,7 @@ private KEdge createDelayEdge(Object associate) { } return edge; } - + private KEdge createIODependencyEdge(Object associate, boolean multiport) { KEdge edge = _kEdgeExtensions.createEdge(); if (associate != null) { @@ -1259,7 +1258,7 @@ private KEdge createIODependencyEdge(Object associate, boolean multiport) { } return edge; } - + private KEdge createDependencyEdge(Object associate) { KEdge edge = _kEdgeExtensions.createEdge(); if (associate != null) { @@ -1276,7 +1275,7 @@ private KEdge createDependencyEdge(Object associate) { } return edge; } - + private KEdge createOrderEdge() { KEdge edge = _kEdgeExtensions.createEdge(); KPolyline line = _kEdgeExtensions.addPolyline(edge); @@ -1288,27 +1287,27 @@ private KEdge createOrderEdge() { _kPolylineExtensions.addHeadArrowDecorator(line); return edge; } - + private KEdge connect(KEdge edge, KNode src, KNode dst) { edge.setSource(src); edge.setTarget(dst); return edge; } - + private KEdge connect(KEdge edge, KNode src, KPort dst) { edge.setSource(src); edge.setTargetPort(dst); edge.setTarget(dst != null ? dst.getNode() : null); return edge; } - + private KEdge connect(KEdge edge, KPort src, KNode dst) { edge.setSourcePort(src); edge.setSource(src != null ? src.getNode() : null); edge.setTarget(dst); return edge; } - + private KEdge connect(KEdge edge, KPort src, KPort dst) { edge.setSourcePort(src); edge.setSource(src != null ? src.getNode() : null); @@ -1316,7 +1315,7 @@ private KEdge connect(KEdge edge, KPort src, KPort dst) { edge.setTarget(dst != null ? dst.getNode() : null); return edge; } - + /** * Translate an input/output into a port. */ @@ -1326,7 +1325,7 @@ private KPort addIOPort(KNode node, PortInstance lfPort, boolean input, boolean associateWith(port, lfPort.getDefinition()); NamedInstanceUtil.linkInstance(port, lfPort); _kPortExtensions.setPortSize(port, 6, 6); - + if (input) { // multiports are smaller by an offset at the right, hence compensate in inputs double offset = multiport ? -3.4 : -3.3; @@ -1338,23 +1337,23 @@ private KPort addIOPort(KNode node, PortInstance lfPort, boolean input, boolean setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST); setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset); } - + if (bank && !node.getProperty(REACTOR_HAS_BANK_PORT_OFFSET)) {// compensate bank figure height // https://github.com/eclipse/elk/issues/693 _utilityExtensions.getPortMarginsInitIfAbsent(node).add( new ElkMargin(0, 0, LinguaFrancaShapeExtensions.BANK_FIGURE_Y_OFFSET_SUM, 0)); node.setProperty(REACTOR_HAS_BANK_PORT_OFFSET, true); // only once } - + _linguaFrancaShapeExtensions.addTrianglePort(port, multiport); - + String label = lfPort.getName(); if (!getBooleanValue(SHOW_PORT_NAMES)) { label = ""; } if (getBooleanValue(SHOW_MULTIPORT_WIDTH)) { if (lfPort.isMultiport()) { - label += (lfPort.getWidth() >= 0) ? + label += (lfPort.getWidth() >= 0) ? "[" + lfPort.getWidth() + "]" : "[?]"; } @@ -1369,14 +1368,14 @@ private KPort addInvisiblePort(KNode node) { port.setSize(0, 0); // invisible return port; } - + private KNode addErrorComment(KNode node, String message) { KNode comment = _kNodeExtensions.createNode(); setLayoutOption(comment, CoreOptions.COMMENT_BOX, true); KRoundedRectangle commentFigure = _linguaFrancaShapeExtensions.addCommentFigure(comment, message); _linguaFrancaStyleExtensions.errorStyle(commentFigure); _kRenderingExtensions.setBackground(commentFigure, Colors.PEACH_PUFF_2); - + // connect KEdge edge = _kEdgeExtensions.createEdge(); edge.setSource(comment); @@ -1384,23 +1383,23 @@ private KNode addErrorComment(KNode node, String message) { _linguaFrancaStyleExtensions.errorStyle(_linguaFrancaShapeExtensions.addCommentPolyline(edge)); return comment; } - + private Iterable createUserComments(EObject element, KNode targetNode) { if (getBooleanValue(SHOW_USER_LABELS)) { String commentText = AttributeUtils.getLabel(element); - + if (!StringExtensions.isNullOrEmpty(commentText)) { KNode comment = _kNodeExtensions.createNode(); setLayoutOption(comment, CoreOptions.COMMENT_BOX, true); KRoundedRectangle commentFigure = _linguaFrancaShapeExtensions.addCommentFigure(comment, commentText); _linguaFrancaStyleExtensions.commentStyle(commentFigure); - + // connect KEdge edge = _kEdgeExtensions.createEdge(); edge.setSource(comment); edge.setTarget(targetNode); _linguaFrancaStyleExtensions.commentStyle(_linguaFrancaShapeExtensions.addCommentPolyline(edge)); - + return List.of(comment); } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java b/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java index 8dc4afd2d3..260e2c98db 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java @@ -11,15 +11,15 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.diagram.synthesis.styles; @@ -42,7 +42,7 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; import org.lflang.diagram.synthesis.LinguaFrancaSynthesis; import org.lflang.diagram.synthesis.util.UtilityExtensions; @@ -90,17 +90,17 @@ /** * Extension class that provides shapes and figures for the Lingua France diagram synthesis. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class LinguaFrancaShapeExtensions extends AbstractSynthesisExtensions { - - public static final float REACTION_POINTINESS = 6; // arrow point length + + public static final float REACTION_POINTINESS = 6; // arrow point length // Property for marking the KContainterRendering in Reactor figures that is supposed to hold the content public static final Property REACTOR_CONTENT_CONTAINER = new Property<>( "org.lflang.diagram.synthesis.shapes.reactor.content", false); - + @Inject @Extension private KNodeExtensions _kNodeExtensions; @@ -133,7 +133,7 @@ public class LinguaFrancaShapeExtensions extends AbstractSynthesisExtensions { private UtilityExtensions _utilityExtensions; @Extension private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; - + public static final float BANK_FIGURE_X_OFFSET_SUM = 6.0f; public static final float BANK_FIGURE_Y_OFFSET_SUM = 9.0f; @@ -148,7 +148,7 @@ public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reacto _kRenderingExtensions.setForeground(figure, Colors.GRAY); _kRenderingExtensions.setBackground(figure, Colors.WHITE); _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - + // Create parent container KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure); _kRenderingExtensions.setInvisible(parentContainer, true); @@ -156,22 +156,22 @@ public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reacto LEFT, padding, 0, TOP, padding, 0, RIGHT, padding, 0, BOTTOM, 4, 0 ); - + // Create child container KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer); _kRenderingExtensions.setInvisible(childContainer, true); - _kRenderingExtensions.setPointPlacementData(childContainer, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, + _kRenderingExtensions.setPointPlacementData(childContainer, + _kRenderingExtensions.LEFT, 0, 0.5f, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0); KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1); - + // Add text to the child container KText childText = _kContainerRenderingExtensions.addText(childContainer, text); DiagramSyntheses.suppressSelectability(childText); _linguaFrancaStyleExtensions.underlineSelectionStyle(childText); - + if (reactorInstance.reactorDefinition.isFederated()) { KContainerRendering cloudIcon = _linguaFrancaStyleExtensions.addCloudIcon(childContainer); setGridPlacementDataFromPointToPoint(cloudIcon, @@ -179,10 +179,10 @@ public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reacto RIGHT, 0, 0, BOTTOM, 0, 0 ); placement.setNumColumns(2); - - if (reactorInstance.reactorDefinition.getHost() != null && + + if (reactorInstance.reactorDefinition.getHost() != null && getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { - KText hostNameText = _kContainerRenderingExtensions.addText(childContainer, + KText hostNameText = _kContainerRenderingExtensions.addText(childContainer, ASTUtils.toOriginalText(reactorInstance.reactorDefinition.getHost())); DiagramSyntheses.suppressSelectability(hostNameText); _linguaFrancaStyleExtensions.underlineSelectionStyle(hostNameText); @@ -192,7 +192,7 @@ public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reacto ); placement.setNumColumns(3); } - } + } return figure; } @@ -201,14 +201,14 @@ public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reacto */ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reactorInstance, String text) { int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; - + Function1 style = r -> { _kRenderingExtensions.setLineWidth(r, 1); _kRenderingExtensions.setForeground(r, Colors.GRAY); _kRenderingExtensions.setBackground(r, Colors.GRAY_95); return _linguaFrancaStyleExtensions.boldLineSelectionStyle(r); }; - + KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1); _kContainerRenderingExtensions.setGridPlacement(figure, 1); style.apply(figure); @@ -217,32 +217,32 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac // minimal node size is necessary if no text will be added List minSize = List.of(2 * figure.getCornerWidth(), 2 * figure.getCornerHeight()); _kNodeExtensions.setMinimalNodeSize(node, minSize.get(0), minSize.get(1)); - + // Add parent container KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure); _kRenderingExtensions.setInvisible(parentContainer, true); setGridPlacementDataFromPointToPoint(parentContainer, - LEFT, padding, 0, + LEFT, padding, 0, TOP, padding, 0, - RIGHT, padding, 0, BOTTOM, + RIGHT, padding, 0, BOTTOM, _utilityExtensions.hasContent(reactorInstance) ? 4 : padding, 0 ); - + // Add centered child container KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer); _kRenderingExtensions.setInvisible(childContainer, true); - _kRenderingExtensions.setPointPlacementData(childContainer, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, + _kRenderingExtensions.setPointPlacementData(childContainer, + _kRenderingExtensions.LEFT, 0, 0.5f, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0); KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1); - + KText childText = _kContainerRenderingExtensions.addText(childContainer, text); DiagramSyntheses.suppressSelectability(childText); _linguaFrancaStyleExtensions.underlineSelectionStyle(childText); - - if (!_utilityExtensions.isRoot(reactorInstance) && + + if (!_utilityExtensions.isRoot(reactorInstance) && reactorInstance.getDefinition().getHost() != null) { KRendering cloudUploadIcon = _linguaFrancaStyleExtensions.addCloudUploadIcon(childContainer); setGridPlacementDataFromPointToPoint(cloudUploadIcon, @@ -250,9 +250,9 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac RIGHT, 0, 0, BOTTOM, 0, 0 ); placement.setNumColumns(2); - + if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { - KText reactorHostText = _kContainerRenderingExtensions.addText(childContainer, + KText reactorHostText = _kContainerRenderingExtensions.addText(childContainer, ASTUtils.toOriginalText(reactorInstance.getDefinition().getHost())); DiagramSyntheses.suppressSelectability(reactorHostText); _linguaFrancaStyleExtensions.underlineSelectionStyle(reactorHostText); @@ -263,7 +263,7 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac placement.setNumColumns(3); } } - + if (reactorInstance.isBank()) { List bank = new ArrayList<>(); KContainerRendering container = _kRenderingExtensions.addInvisibleContainerRendering(node); @@ -289,7 +289,7 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac LEFT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 3, 0 ); - + banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); style.apply(banks); setGridPlacementDataFromPointToPoint(banks, @@ -297,14 +297,14 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac RIGHT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0 ); } - + container.getChildren().add(figure); setGridPlacementDataFromPointToPoint(figure, LEFT, 0, 0, TOP, 0, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM, 0 ); bank.addAll(container.getChildren()); - + KRectangle widthLabelContainer = _kContainerRenderingExtensions.addRectangle(container); _kRenderingExtensions.setInvisible(widthLabelContainer, true); setGridPlacementDataFromPointToPoint(widthLabelContainer, @@ -324,7 +324,7 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac return new ReactorFigureComponents(figure, figure, List.of(figure)); } } - + /** * Creates the visual representation of a reaction node */ @@ -333,7 +333,7 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { int minWidth = 45; ReactorInstance reactor = reaction.getParent(); _kNodeExtensions.setMinimalNodeSize(node, minWidth, minHeight); - + // Create base shape KPolygon baseShape = _kRenderingExtensions.addPolygon(node); associateWith(baseShape, reaction); @@ -351,19 +351,19 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { _kRenderingExtensions.createKPosition(LEFT, REACTION_POINTINESS, 0, BOTTOM, 0, 0.5f) ) ); - + KRectangle contentContainer = _kContainerRenderingExtensions.addRectangle(baseShape); associateWith(contentContainer, reaction); _kRenderingExtensions.setInvisible(contentContainer, true); - _kRenderingExtensions.setPointPlacementData(contentContainer, - _kRenderingExtensions.LEFT, REACTION_POINTINESS, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, REACTION_POINTINESS, + _kRenderingExtensions.setPointPlacementData(contentContainer, + _kRenderingExtensions.LEFT, REACTION_POINTINESS, 0, + _kRenderingExtensions.TOP, 0, 0, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, REACTION_POINTINESS, 0, minWidth - REACTION_POINTINESS * 2, minHeight); _kContainerRenderingExtensions.setGridPlacement(contentContainer, 1); - + if (reactor.reactions.size() > 1) { - KText textToAdd = _kContainerRenderingExtensions.addText(contentContainer, + KText textToAdd = _kContainerRenderingExtensions.addText(contentContainer, Integer.toString(reactor.reactions.indexOf(reaction) + 1)); _kRenderingExtensions.setFontBold(textToAdd, true); _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); @@ -387,10 +387,10 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { } // optional code content - boolean hasCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && + boolean hasCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && !StringExtensions.isNullOrEmpty(reaction.getDefinition().getCode().getBody()); if (hasCode) { - KText hasCodeText = _kContainerRenderingExtensions.addText(contentContainer, + KText hasCodeText = _kContainerRenderingExtensions.addText(contentContainer, _utilityExtensions.trimCode(reaction.getDefinition().getCode())); associateWith(hasCodeText, reaction); _kRenderingExtensions.setFontSize(hasCodeText, 6); @@ -399,26 +399,26 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { _kRenderingExtensions.setHorizontalAlignment(hasCodeText, HorizontalAlignment.LEFT); _kRenderingExtensions.setVerticalAlignment(hasCodeText, VerticalAlignment.TOP); setGridPlacementDataFromPointToPoint(hasCodeText, - _kRenderingExtensions.LEFT, 5, 0, + _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 5, 0, - _kRenderingExtensions.RIGHT, 5, 0, + _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 5, 0 ); } - + if (reaction.declaredDeadline != null) { - boolean hasDeadlineCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && + boolean hasDeadlineCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && !StringExtensions.isNullOrEmpty(reaction.getDefinition().getDeadline().getCode().getBody()); if (hasCode || hasDeadlineCode) { KPolyline line = _kContainerRenderingExtensions.addHorizontalLine(contentContainer, 0); setGridPlacementDataFromPointToPoint(line, - _kRenderingExtensions.LEFT, 5, 0, + _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 3, 0, - _kRenderingExtensions.RIGHT, 5, 0, + _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 6, 0 ); } - + // delay with stopwatch KRectangle labelContainer = _kContainerRenderingExtensions.addRectangle(contentContainer); _kRenderingExtensions.setInvisible(labelContainer, true); @@ -429,11 +429,11 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { _kRenderingExtensions.BOTTOM, 0, 0 ); _kRenderingExtensions.setHorizontalAlignment(placement, HorizontalAlignment.LEFT); - + KRectangle stopWatchFigure = addStopwatchFigure(labelContainer); _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchFigure, 0, 0, 0, 0); - - KText stopWatchText = _kContainerRenderingExtensions.addText(labelContainer, + + KText stopWatchText = _kContainerRenderingExtensions.addText(labelContainer, reaction.declaredDeadline.maxDelay.toString()); associateWith(stopWatchText, reaction.getDefinition().getDeadline().getDelay()); _kRenderingExtensions.setForeground(stopWatchText, Colors.BROWN); @@ -441,19 +441,19 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { _kRenderingExtensions.setFontSize(stopWatchText, 7); _linguaFrancaStyleExtensions.underlineSelectionStyle(stopWatchText); _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchText, 15, 0, 0, 0); - + // optional code content if (hasDeadlineCode) { - KText contentContainerText = _kContainerRenderingExtensions.addText(contentContainer, + KText contentContainerText = _kContainerRenderingExtensions.addText(contentContainer, _utilityExtensions.trimCode(reaction.getDefinition().getDeadline().getCode())); associateWith(contentContainerText, reaction.declaredDeadline); _kRenderingExtensions.setForeground(contentContainerText, Colors.BROWN); _kRenderingExtensions.setFontSize(contentContainerText, 6); _kRenderingExtensions.setFontName(contentContainerText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME); setGridPlacementDataFromPointToPoint(contentContainerText, - _kRenderingExtensions.LEFT, 5, 0, + _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.RIGHT, 5, 0, + _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 5, 0 ); _kRenderingExtensions.setHorizontalAlignment(contentContainerText, HorizontalAlignment.LEFT); @@ -463,7 +463,7 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { return baseShape; } - + /** * Stopwatch figure for deadlines. */ @@ -471,21 +471,21 @@ public KRectangle addStopwatchFigure(KContainerRendering parent) { final int size = 12; KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); _kRenderingExtensions.setInvisible(container, true); - _kRenderingExtensions.setPointPlacementData(container, - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, + _kRenderingExtensions.setPointPlacementData(container, + _kRenderingExtensions.LEFT, 0, 0, + _kRenderingExtensions.TOP, 0, 0, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, size, size); - - KPolyline polyline = _kContainerRenderingExtensions.addPolyline(container, 2, + + KPolyline polyline = _kContainerRenderingExtensions.addPolyline(container, 2, List.of( _kRenderingExtensions.createKPosition(LEFT, 3, 0.5f, TOP, (-2), 0), _kRenderingExtensions.createKPosition(LEFT, (-3), 0.5f, TOP, (-2), 0) ) ); _kRenderingExtensions.setForeground(polyline, Colors.BROWN); - - polyline = _kContainerRenderingExtensions.addPolyline(container, 2, + + polyline = _kContainerRenderingExtensions.addPolyline(container, 2, List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, (-2), 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 1, 0) @@ -496,41 +496,41 @@ public KRectangle addStopwatchFigure(KContainerRendering parent) { KEllipse body = _kContainerRenderingExtensions.addEllipse(container); _kRenderingExtensions.setLineWidth(body, 1); _kRenderingExtensions.setForeground(body, Colors.BROWN); - _kRenderingExtensions.setPointPlacementData(body, - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, + _kRenderingExtensions.setPointPlacementData(body, + _kRenderingExtensions.LEFT, 0, 0, + _kRenderingExtensions.TOP, 0, 0, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, size, size); _linguaFrancaStyleExtensions.noSelectionStyle(body); - + KArc arc = _kContainerRenderingExtensions.addArc(body); arc.setStartAngle((-20)); arc.setArcAngle(110); arc.setArcType(Arc.PIE); _kRenderingExtensions.setLineWidth(arc, 0); _kRenderingExtensions.setBackground(arc, Colors.BROWN); - _kRenderingExtensions.setPointPlacementData(arc, - _kRenderingExtensions.LEFT, 2, 0, - _kRenderingExtensions.TOP, 2, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 2, + _kRenderingExtensions.setPointPlacementData(arc, + _kRenderingExtensions.LEFT, 2, 0, + _kRenderingExtensions.TOP, 2, 0, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 2, 2, size - 4, size - 4); _linguaFrancaStyleExtensions.noSelectionStyle(arc); - + return container; } - + /** * Creates the visual representation of a timer node */ public KEllipse addTimerFigure(KNode node, TimerInstance timer) { _kNodeExtensions.setMinimalNodeSize(node, 30, 30); - + KEllipse figure = _kRenderingExtensions.addEllipse(node); _kRenderingExtensions.setBackground(figure, Colors.GRAY_95); _linguaFrancaStyleExtensions.noSelectionStyle(figure); _kRenderingExtensions.setLineWidth(figure, 1); _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - + List polylinePoints = List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.1f), _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.5f), @@ -538,7 +538,7 @@ public KEllipse addTimerFigure(KNode node, TimerInstance timer) { ); KPolyline polyline = _kContainerRenderingExtensions.addPolyline(figure, 1, polylinePoints); _linguaFrancaStyleExtensions.boldLineSelectionStyle(polyline); - + List labelParts = new ArrayList<>(); if (timer.getOffset() != TimerInstance.DEFAULT_OFFSET && timer.getOffset() != null) { labelParts.add(timer.getOffset().toString()); @@ -550,12 +550,12 @@ public KEllipse addTimerFigure(KNode node, TimerInstance timer) { labelParts.add(timer.getPeriod().toString()); } if (!labelParts.isEmpty()) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, + _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, "(" + String.join(", ", labelParts) + ")", 8); } return figure; } - + /** * Creates the visual representation of a startup trigger. */ @@ -568,7 +568,7 @@ public KEllipse addStartupFigure(KNode node) { _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); return figure; } - + /** * Creates the visual representation of a shutdown trigger. */ @@ -579,18 +579,18 @@ public KPolygon addShutdownFigure(KNode node) { _kRenderingExtensions.setBackground(figure, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(figure); _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - + List pointsToAdd = List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(RIGHT, 0, 0.5f, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0.5f) ); - + figure.getPoints().addAll(pointsToAdd); return figure; } - + /** * Creates the visual representation of a shutdown trigger. */ @@ -601,13 +601,13 @@ public KEllipse addResetFigure(KNode node) { _kRenderingExtensions.setBackground(figure, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(figure); _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - + KEllipse resetCircle = _kContainerRenderingExtensions.addEllipse(figure); _kRenderingExtensions.setSurroundingSpace(resetCircle, 3f, 0); _kRenderingExtensions.setLineWidth(resetCircle, 1.5f); _kRenderingExtensions.setBackground(resetCircle, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(resetCircle); - + var resetCycleGap = _kContainerRenderingExtensions.addPolygon(resetCircle); resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0)); resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.0f, 0)); @@ -617,12 +617,12 @@ public KEllipse addResetFigure(KNode node) { _kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE); _kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap); - _kRenderingExtensions.setPointPlacementData(resetCycleGap, - _kRenderingExtensions.LEFT, -2, 0.5f, + _kRenderingExtensions.setPointPlacementData(resetCycleGap, + _kRenderingExtensions.LEFT, -2, 0.5f, _kRenderingExtensions.TOP, 1.5f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 4.0f, 3.0f); - + var resetArrow = _kContainerRenderingExtensions.addPolygon(resetCircle); resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f)); resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0)); @@ -630,35 +630,35 @@ public KEllipse addResetFigure(KNode node) { _kRenderingExtensions.setLineWidth(resetArrow, 0.3f); _kRenderingExtensions.setBackground(resetArrow, Colors.BLACK); _linguaFrancaStyleExtensions.noSelectionStyle(resetArrow); - _kRenderingExtensions.setPointPlacementData(resetArrow, - _kRenderingExtensions.LEFT, 1.0f, 0.5f, - _kRenderingExtensions.TOP, 1.8f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(resetArrow, + _kRenderingExtensions.LEFT, 1.0f, 0.5f, + _kRenderingExtensions.TOP, 1.8f, 0, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 3.2f, 3.2f); - + return figure; } - + /** * Creates the visual representation of a reactor port. */ public KPolygon addTrianglePort(KPort port, boolean multiport) { port.setSize(8, 8); - + // Create triangle port KPolygon trianglePort = _kRenderingExtensions.addPolygon(port); - + // Set line width and background color according to multiport or not float lineWidth = multiport ? 2.2f : 1; _kRenderingExtensions.setLineWidth(trianglePort, lineWidth); _linguaFrancaStyleExtensions.boldLineSelectionStyle(trianglePort); Colors background = multiport ? Colors.WHITE : Colors.BLACK; _kRenderingExtensions.setBackground(trianglePort, background); - + List pointsToAdd; if (multiport) { // Compensate for line width by making triangle smaller - // Do not adjust by port size because this will affect port distribution and cause offsets between parallel connections + // Do not adjust by port size because this will affect port distribution and cause offsets between parallel connections pointsToAdd = List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0.6f, 0), _kRenderingExtensions.createKPosition(RIGHT, 1.2f, 0, TOP, 0, 0.5f), @@ -674,7 +674,7 @@ public KPolygon addTrianglePort(KPort port, boolean multiport) { trianglePort.getPoints().addAll(pointsToAdd); return trianglePort; } - + /** * Added a text as collapse expand button. */ @@ -685,13 +685,13 @@ public KText addTextButton(KContainerRendering container, String text) { _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); return textToAdd; } - - /** + + /** * Creates the triangular line decorator with text. */ public KPolygon addActionDecorator(KPolyline line, String text) { final float size = 18; - + // Create action decorator KPolygon actionDecorator = _kContainerRenderingExtensions.addPolygon(line); _kRenderingExtensions.setBackground(actionDecorator, Colors.WHITE); @@ -701,7 +701,7 @@ public KPolygon addActionDecorator(KPolyline line, String text) { _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0) ); actionDecorator.getPoints().addAll(pointsToAdd); - + // Set placement data of the action decorator KDecoratorPlacementData placementData = _kRenderingFactory.createKDecoratorPlacementData(); placementData.setRelative(0.5f); @@ -711,21 +711,21 @@ public KPolygon addActionDecorator(KPolyline line, String text) { placementData.setYOffset(-size * 0.66f); placementData.setRotateWithLine(true); actionDecorator.setPlacementData(placementData); - + // Add text to the action decorator KText textToAdd = _kContainerRenderingExtensions.addText(actionDecorator, text); _kRenderingExtensions.setFontSize(textToAdd, 8); _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); DiagramSyntheses.suppressSelectability(textToAdd); - _kRenderingExtensions.setPointPlacementData(textToAdd, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, size * 0.15f, 0.5f, + _kRenderingExtensions.setPointPlacementData(textToAdd, + _kRenderingExtensions.LEFT, 0, 0.5f, + _kRenderingExtensions.TOP, size * 0.15f, 0.5f, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, size, size); - + return actionDecorator; } - + /** * Creates the triangular action node with text and ports. */ @@ -735,25 +735,25 @@ public Pair addActionFigureAndPorts(KNode node, String text) { KPolygon figure = _kRenderingExtensions.addPolygon(node); _kRenderingExtensions.setBackground(figure, Colors.WHITE); _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - + List pointsToAdd = List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0) ); figure.getPoints().addAll(pointsToAdd); - + // Add text to the action figure KText textToAdd = _kContainerRenderingExtensions.addText(figure, text); _kRenderingExtensions.setFontSize(textToAdd, 8); _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); DiagramSyntheses.suppressSelectability(textToAdd); - _kRenderingExtensions.setPointPlacementData(textToAdd, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, (size * 0.15f), 0.5f, - _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.setPointPlacementData(textToAdd, + _kRenderingExtensions.LEFT, 0, 0.5f, + _kRenderingExtensions.TOP, (size * 0.15f), 0.5f, + _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, size, size); - + // Add input port KPort in = _kPortExtensions.createPort(); node.getPorts().add(in); @@ -768,7 +768,7 @@ public Pair addActionFigureAndPorts(KNode node, String text) { DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4)); return new Pair(in, out); } - + /** * Creates and adds an error message figure */ @@ -776,13 +776,13 @@ public KRectangle addErrorMessage(KNode node, String title, String message) { // Create figure for error message KRectangle figure = _kRenderingExtensions.addRectangle(node); _kRenderingExtensions.setInvisible(figure, true); - + // Add error message box KRoundedRectangle errMsgBox = _kContainerRenderingExtensions.addRoundedRectangle(figure, 7, 7); _kContainerRenderingExtensions.setGridPlacement(errMsgBox, 1); _kRenderingExtensions.setLineWidth(errMsgBox, 2); _linguaFrancaStyleExtensions.noSelectionStyle(errMsgBox); - + if (title != null) { // Add title to error message box KText titleText = _kContainerRenderingExtensions.addText(errMsgBox, title); @@ -790,126 +790,126 @@ public KRectangle addErrorMessage(KNode node, String title, String message) { _kRenderingExtensions.setFontBold(titleText, true); _kRenderingExtensions.setForeground(titleText, Colors.RED); setGridPlacementDataFromPointToPoint(titleText, - _kRenderingExtensions.LEFT, 8, 0, + _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 8, 0, - _kRenderingExtensions.RIGHT, 8, 0, + _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 4, 0); DiagramSyntheses.suppressSelectability(titleText); _linguaFrancaStyleExtensions.noSelectionStyle(titleText); } - + if (message != null) { // Add message to error message box KText msgText = _kContainerRenderingExtensions.addText(errMsgBox, message); if (title != null) { setGridPlacementDataFromPointToPoint(msgText, - _kRenderingExtensions.LEFT, 8, 0, + _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.RIGHT, 8, 0, + _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 4, 0); } else { setGridPlacementDataFromPointToPoint(msgText, - _kRenderingExtensions.LEFT, 8, 0, + _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 8, 0, - _kRenderingExtensions.RIGHT, 8, 0, + _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 8, 0); } _linguaFrancaStyleExtensions.noSelectionStyle(msgText); } return figure; } - + public KRoundedRectangle addCommentFigure(KNode node, String message) { // Create rectangle for comment figure KRoundedRectangle commentFigure = _kRenderingExtensions.addRoundedRectangle(node, 1, 1, 1); _kContainerRenderingExtensions.setGridPlacement(commentFigure, 1); - + // Add message KText text = _kContainerRenderingExtensions.addText(commentFigure, message); _kRenderingExtensions.setFontSize(text, 6); setGridPlacementDataFromPointToPoint(text, _kRenderingExtensions.LEFT, 3, 0, _kRenderingExtensions.TOP, 3, 0, - _kRenderingExtensions.RIGHT, 3, 0, + _kRenderingExtensions.RIGHT, 3, 0, _kRenderingExtensions.BOTTOM, 3, 0); _linguaFrancaStyleExtensions.noSelectionStyle(text); return commentFigure; } - + private KRendering setGridPlacementDataFromPointToPoint(KRendering rendering, PositionReferenceX fPx, float fAbsoluteLR, float fRelativeLR, PositionReferenceY fPy, float fAbsoluteTB, float fRelativeTB, PositionReferenceX tPx, float tAbsoluteLR, float tRelativeLR, PositionReferenceY tPy, float tAbsoluteTB, float tRelativeTB) { KAreaPlacementData fromPoint = _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rendering), + _kRenderingExtensions.setGridPlacementData(rendering), fPx, fAbsoluteLR, fRelativeLR, fPy, fAbsoluteTB, fRelativeTB); - return _kRenderingExtensions.to(fromPoint, - tPx, tAbsoluteLR, tRelativeLR, + return _kRenderingExtensions.to(fromPoint, + tPx, tAbsoluteLR, tRelativeLR, tPy, tAbsoluteTB, tRelativeTB); } - - + + public KPolyline addCommentPolyline(KEdge edge) { KPolyline polyline = _kEdgeExtensions.addPolyline(edge); _kRenderingExtensions.setLineWidth(polyline, 1); _kRenderingExtensions.setLineStyle(polyline, LineStyle.DOT); return polyline; } - + public KContainerRendering addParameterEntry(KContainerRendering parent, Parameter associate, String text) { KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); _kRenderingExtensions.setInvisible(container, true); var ktext = _kContainerRenderingExtensions.addText(container, text); _kRenderingExtensions.setFontSize(ktext, 8); - _kRenderingExtensions.setPointPlacementData(ktext, - _kRenderingExtensions.LEFT, 10, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(ktext, + _kRenderingExtensions.LEFT, 10, 0, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0); associateWith(ktext, associate); - + var dot = _kContainerRenderingExtensions.addEllipse(container); _kRenderingExtensions.setLineWidth(dot, 1); _linguaFrancaStyleExtensions.noSelectionStyle(dot); - _kRenderingExtensions.setPointPlacementData(dot, - _kRenderingExtensions.LEFT, 2, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(dot, + _kRenderingExtensions.LEFT, 2, 0, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 5, 5); return container; } - - + + public KContainerRendering addStateEntry(KContainerRendering parent, StateVar associate, String text, boolean reset) { KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); _kRenderingExtensions.setInvisible(container, true); var ktext = _kContainerRenderingExtensions.addText(container, text); _kRenderingExtensions.setFontSize(ktext, 8); - _kRenderingExtensions.setPointPlacementData(ktext, - _kRenderingExtensions.LEFT, 10, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(ktext, + _kRenderingExtensions.LEFT, 10, 0, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0); associateWith(ktext, associate); - + KEllipse outerCircle; - + if (reset) { outerCircle = _kContainerRenderingExtensions.addEllipse(container); _kRenderingExtensions.setLineWidth(outerCircle, 0.9f); _kRenderingExtensions.setBackground(outerCircle, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(outerCircle); - _kRenderingExtensions.setPointPlacementData(outerCircle, - _kRenderingExtensions.LEFT, 1.5f, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(outerCircle, + _kRenderingExtensions.LEFT, 1.5f, 0, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 6.3f, 6.3f); - + var resetCycleGap = _kContainerRenderingExtensions.addPolygon(outerCircle); resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.26f, 0)); resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0)); @@ -922,12 +922,12 @@ public KContainerRendering addStateEntry(KContainerRendering parent, StateVar as _kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE); _kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap); - _kRenderingExtensions.setPointPlacementData(resetCycleGap, - _kRenderingExtensions.LEFT, -1.2f, 0.5f, + _kRenderingExtensions.setPointPlacementData(resetCycleGap, + _kRenderingExtensions.LEFT, -1.2f, 0.5f, _kRenderingExtensions.TOP, 0.75f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 2.5f, 1.3f); - + var resetArrow = _kContainerRenderingExtensions.addPolygon(outerCircle); resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f)); resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0)); @@ -935,31 +935,31 @@ public KContainerRendering addStateEntry(KContainerRendering parent, StateVar as _kRenderingExtensions.setLineWidth(resetArrow, 0.3f); _kRenderingExtensions.setBackground(resetArrow, Colors.BLACK); _linguaFrancaStyleExtensions.noSelectionStyle(resetArrow); - _kRenderingExtensions.setPointPlacementData(resetArrow, - _kRenderingExtensions.LEFT, 0.8f, 0.5f, - _kRenderingExtensions.TOP, 1.1f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(resetArrow, + _kRenderingExtensions.LEFT, 0.8f, 0.5f, + _kRenderingExtensions.TOP, 1.1f, 0, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 1.5f, 1.5f); } else { outerCircle = _kContainerRenderingExtensions.addEllipse(container); _kRenderingExtensions.setLineWidth(outerCircle, 1); _kRenderingExtensions.setBackground(outerCircle, Colors.WHITE); _linguaFrancaStyleExtensions.noSelectionStyle(outerCircle); - _kRenderingExtensions.setPointPlacementData(outerCircle, - _kRenderingExtensions.LEFT, 1.5f, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(outerCircle, + _kRenderingExtensions.LEFT, 1.5f, 0, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, 0, 0, 6, 6); } - + var innerDot = _kContainerRenderingExtensions.addEllipse(outerCircle); _kRenderingExtensions.setLineWidth(innerDot, 0.5f); _kRenderingExtensions.setBackground(innerDot, Colors.BLACK); _linguaFrancaStyleExtensions.noSelectionStyle(innerDot); - _kRenderingExtensions.setPointPlacementData(innerDot, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, + _kRenderingExtensions.setPointPlacementData(innerDot, + _kRenderingExtensions.LEFT, 0, 0.5f, + _kRenderingExtensions.TOP, 0, 0.5f, + _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 2.5f, 2.5f); return container; diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index a86d6fd1f0..9252e93210 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -34,7 +34,7 @@ import java.nio.file.Path; import java.util.List; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.Target; diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 7a03655923..c6f62fc8d6 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.regex.Pattern; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.TargetConfig.ClockSyncOptions; import org.lflang.TargetProperty; diff --git a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java b/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java index c533a1f765..15606c6fa0 100644 --- a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java @@ -28,7 +28,7 @@ import java.io.IOException; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetProperty.CoordinationType; diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index 77d6203a93..4a70f4cc6b 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -5,10 +5,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.LinkedHashMap; import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetProperty.CoordinationType; @@ -18,7 +17,6 @@ import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; import org.lflang.federated.launcher.RtiConfig; -import org.lflang.generator.GeneratorBase; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactorInstance; import org.lflang.generator.ts.TSTypes; diff --git a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java index 7a7eb1f183..cedb9da017 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java +++ b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java @@ -43,7 +43,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.ModelInfo; diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index dddae562f7..595a721c93 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -28,7 +28,7 @@ import org.eclipse.xtext.util.RuntimeIOException; import org.eclipse.xtext.xbase.lib.Exceptions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.LFStandaloneSetup; diff --git a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java index 54e215264f..65b9d4cd15 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java @@ -1,22 +1,13 @@ package org.lflang.federated.generator; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import org.eclipse.emf.ecore.EObject; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.ast.FormattingUtils; -import org.lflang.generator.CodeBuilder; -import org.lflang.generator.ReactorInstance; -import org.lflang.lf.Instantiation; import org.lflang.lf.Reactor; import org.lflang.lf.Variable; diff --git a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java index 354cd33044..154919c816 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java @@ -1,11 +1,10 @@ package org.lflang.federated.generator; -import static org.lflang.ASTUtils.toText; +import static org.lflang.ast.ASTUtils.toText; import java.io.IOException; -import java.util.LinkedHashMap; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.federated.extensions.FedTargetExtensionFactory; import org.lflang.federated.launcher.RtiConfig; diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java index 9af20347c2..af83d1f919 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java @@ -1,6 +1,6 @@ package org.lflang.federated.generator; -import static org.lflang.ASTUtils.convertToEmptyListIfNull; +import static org.lflang.ast.ASTUtils.convertToEmptyListIfNull; import org.lflang.ErrorReporter; import org.lflang.TargetConfig; diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index cdd64f03b2..0669b4f9dc 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -37,7 +37,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.eclipse.emf.ecore.EObject; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.TargetConfig; import org.lflang.TimeValue; diff --git a/org.lflang/src/org/lflang/federated/validation/FedValidator.java b/org.lflang/src/org/lflang/federated/validation/FedValidator.java index ce03b18964..49add78557 100644 --- a/org.lflang/src/org/lflang/federated/validation/FedValidator.java +++ b/org.lflang/src/org/lflang/federated/validation/FedValidator.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.stream.Stream; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; diff --git a/org.lflang/src/org/lflang/generator/CodeBuilder.java b/org.lflang/src/org/lflang/generator/CodeBuilder.java index a921a47239..2b77239680 100644 --- a/org.lflang/src/org/lflang/generator/CodeBuilder.java +++ b/org.lflang/src/org/lflang/generator/CodeBuilder.java @@ -333,27 +333,30 @@ public void startScopedRangeBlock( * source range is reused until the destination range is filled. * The following integer variables will be defined within the scoped block: * - * * src_channel: The channel index for the source. - * * src_bank: The bank index of the source port's parent. - * * src_runtime: The runtime index of the source port's parent or - * the parent's parent (if the source is an input). + *
    + *
  • src_channel: The channel index for the source.
  • + *
  • src_bank: The bank index of the source port's parent.
  • + *
  • src_runtime: The runtime index of the source port's parent or + * the parent's parent (if the source is an input).
  • + *
+ *
    + *
  • dst_channel: The channel index for the destination.
  • + *
  • dst_bank: The bank index of the destination port's parent.
  • + *
  • dst_runtime: The runtime index of the destination port's parent or + * the parent's parent (if destination is an output).
  • + *
* - * * dst_channel: The channel index for the destination. - * * dst_bank: The bank index of the destination port's parent. - * * dst_runtime: The runtime index of the destination port's parent or - * the parent's parent (if destination is an output). + *

For convenience, the above variable names are defined in the private + * class variables sc, sb, sr, and dc, db, dr.

* - * For convenience, the above variable names are defined in the private - * class variables sc, sb, sr, and dc, db, dr. - * - * This block should NOT be nested, where each block is + *

This block should NOT be nested, where each block is * put within a similar block for the reactor's parent. * Within the created block, every use of * {@link CUtil#reactorRef(ReactorInstance, String)} - * and related functions must provide the above variable names. + * and related functions must provide the above variable names.

* - * This must be followed by a call to - * {@link #endScopedRangeBlock(SendRange, RuntimeRange)}. + *

This must be followed by a call to + * {@link #endScopedRangeBlock(SendRange, RuntimeRange)}.

x * * @param srcRange The send range. * @param dstRange The destination range. diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 16eb901676..2243729e09 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -41,7 +41,7 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.MainConflictChecker; diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/src/org/lflang/generator/GeneratorUtils.java index 92a57fd424..b4563a6165 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/GeneratorUtils.java @@ -12,7 +12,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; diff --git a/org.lflang/src/org/lflang/generator/LFGenerator.java b/org.lflang/src/org/lflang/generator/LFGenerator.java index 0c9a45dd7c..c8d985e80c 100644 --- a/org.lflang/src/org/lflang/generator/LFGenerator.java +++ b/org.lflang/src/org/lflang/generator/LFGenerator.java @@ -10,7 +10,7 @@ import org.eclipse.xtext.generator.IGeneratorContext; import org.eclipse.xtext.util.RuntimeIOException; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.Target; diff --git a/org.lflang/src/org/lflang/generator/ParameterInstance.java b/org.lflang/src/org/lflang/generator/ParameterInstance.java index 9287710e6b..851fcb627e 100644 --- a/org.lflang/src/org/lflang/generator/ParameterInstance.java +++ b/org.lflang/src/org/lflang/generator/ParameterInstance.java @@ -13,15 +13,15 @@ this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ @@ -30,17 +30,15 @@ import java.util.List; import java.util.Optional; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.lf.Assignment; -import org.lflang.lf.Expression; import org.lflang.lf.Initializer; -import org.lflang.lf.LfFactory; import org.lflang.lf.Parameter; -/** +/** * Representation of a compile-time instance of a parameter. - * Upon creation, it is checked whether this parameter is overridden by an + * Upon creation, it is checked whether this parameter is overridden by an * assignment in the instantiation that this parameter instance is a result of. * If it is overridden, the parameter gets initialized using the value looked up * in the instantiation hierarchy. @@ -48,8 +46,8 @@ * @author Edward A. Lee */ public class ParameterInstance extends NamedInstance { - - /** + + /** * Create a runtime instance from the specified definition * and with the specified parent that instantiated it. * @param definition The declaration in the AST. @@ -60,15 +58,15 @@ public ParameterInstance(Parameter definition, ReactorInstance parent) { if (parent == null) { throw new InvalidSourceException("Cannot create a ParameterInstance with no parent."); } - + this.type = ASTUtils.getInferredType(definition); } ///////////////////////////////////////////// //// Public Fields - + public InferredType type; - + ///////////////////////////////////////////// //// Public Methods @@ -94,15 +92,15 @@ public Initializer getActualValue() { } return init; } - + /** - * Return the name of this parameter. + * Return the name of this parameter. * @return The name of this parameter. */ public String getName() { return this.definition.getName(); } - + /** * Return the assignment that overrides this parameter in * the parent's instantiation or null if there is no override. @@ -114,7 +112,7 @@ public Assignment getOverride() { ).findFirst(); return assignment.orElse(null); } - + /** Return a descriptive string. */ @Override public String toString() { diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index c904a39127..98e26c03de 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -32,7 +32,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.List; import java.util.Set; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.TimeValue; import org.lflang.lf.Action; import org.lflang.lf.BuiltinTriggerRef; @@ -52,7 +52,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * inner class {@link ReactionInstance.Runtime}. Each runtime instance has a "level", which is * its depth an acyclic precedence graph representing the dependencies between * reactions at a tag. - * + * * @author Edward A. Lee * @author Marten Lohstroh */ @@ -69,15 +69,15 @@ public class ReactionInstance extends NamedInstance { * first reaction, 1 for the second, etc.). */ public ReactionInstance( - Reaction definition, - ReactorInstance parent, - boolean isUnordered, + Reaction definition, + ReactorInstance parent, + boolean isUnordered, int index ) { super(definition, parent); this.index = index; this.isUnordered = isUnordered; - + // If the reaction body starts with the magic string // UNORDERED_REACTION_MARKER, then mark it unordered, // overriding the argument. @@ -85,7 +85,7 @@ public ReactionInstance( if (body.contains(UNORDERED_REACTION_MARKER)) { this.isUnordered = true; } - + // Identify the dependencies for this reaction. // First handle the triggers. for (TriggerRef trigger : definition.getTriggers()) { @@ -102,7 +102,7 @@ public ReactionInstance( this.triggers.add(portInstance); } else if (((VarRef)trigger).getContainer() != null) { // Port belongs to a contained reactor or bank. - ReactorInstance containedReactor + ReactorInstance containedReactor = parent.lookupReactorInstance(((VarRef)trigger).getContainer()); if (containedReactor != null) { portInstance = containedReactor.lookupPortInstance((Port)variable); @@ -135,7 +135,7 @@ public ReactionInstance( Variable variable = source.getVariable(); if (variable instanceof Port) { var portInstance = parent.lookupPortInstance((Port)variable); - + // If the trigger is the port of a contained bank, then the // portInstance will be null and we have to instead search for // each port instance in the bank. @@ -157,7 +157,7 @@ public ReactionInstance( } } } - + // Finally, handle the effects. for (VarRef effect : definition.getEffects()) { Variable variable = effect.getVariable(); @@ -191,7 +191,7 @@ public ReactionInstance( ////////////////////////////////////////////////////// //// Public fields. - /** + /** * Indicates the chain this reaction is a part of. It is constructed * through a bit-wise or among all upstream chains. Each fork in the * dependency graph setting a new, unused bit to true in order to @@ -216,7 +216,7 @@ public ReactionInstance( // "sources" are only the inputs a reaction reads without being // triggered by them. The name "reads" used here would be a better // choice in the grammar. - + /** * Deadline for this reaction instance, if declared. */ @@ -269,7 +269,7 @@ public void clearCaches(boolean includingRuntimes) { dependsOnReactionsCache = null; if (includingRuntimes) runtimeInstances = null; } - + /** * Return the set of immediate downstream reactions, which are reactions * that receive data produced by this reaction plus @@ -280,13 +280,13 @@ public Set dependentReactions() { // Cache the result. if (dependentReactionsCache != null) return dependentReactionsCache; dependentReactionsCache = new LinkedHashSet<>(); - + // First, add the next lexical reaction, if appropriate. if (!isUnordered && parent.reactions.size() > index + 1) { // Find the next reaction in the parent's reaction list. dependentReactionsCache.add(parent.reactions.get(index + 1)); } - + // Next, add reactions that get data from this one via a port. for (TriggerInstance effect : effects) { if (effect instanceof PortInstance) { @@ -302,7 +302,7 @@ public Set dependentReactions() { } return dependentReactionsCache; } - + /** * Return the set of immediate upstream reactions, which are reactions * that send data to this one plus at most one reaction in the same @@ -313,7 +313,7 @@ public Set dependsOnReactions() { // Cache the result. if (dependsOnReactionsCache != null) return dependsOnReactionsCache; dependsOnReactionsCache = new LinkedHashSet<>(); - + // First, add the previous lexical reaction, if appropriate. if (!isUnordered && index > 0) { // Find the previous ordered reaction in the parent's reaction list. @@ -326,7 +326,7 @@ public Set dependsOnReactions() { dependsOnReactionsCache.add(parent.reactions.get(index - 1)); } } - + // Next, add reactions that send data to this one. for (TriggerInstance source : sources) { if (source instanceof PortInstance) { @@ -358,7 +358,7 @@ public Set getLevels() { } return result; } - + /** * Return a set of deadlines that runtime instances of this reaction have. * A ReactionInstance may have more than one deadline if it lies within. @@ -370,7 +370,7 @@ public Set getInferredDeadlines() { } return result; } - + /** * Return a list of levels that runtime instances of this reaction have. @@ -389,7 +389,7 @@ public List getLevelsList() { } return result; } - + /** * Return a list of the deadlines that runtime instances of this reaction have. * The size of this list is the total number of runtime instances. @@ -406,14 +406,14 @@ public List getInferredDeadlinesList() { /** * Return the name of this reaction, which is 'reaction_n', - * where n is replaced by the reaction index. + * where n is replaced by the reaction index. * @return The name of this reaction. */ @Override public String getName() { return "reaction_" + this.index; } - + /** * Return an array of runtime instances of this reaction in a * natural order, defined as follows. The position within the @@ -464,7 +464,7 @@ public void removePortInstance(PortInstance portInstance) { clearCaches(false); portInstance.clearCaches(); } - + /** * Return a descriptive string. */ @@ -500,7 +500,7 @@ public TimeValue assignLogicalExecutionTime() { return false; }).map(c -> c.actions.get(0).getMinDelay()) .min(TimeValue::compare); - + if (afters.isPresent()) { if (let == null) { let = afters.get(); @@ -532,7 +532,7 @@ public TimeValue assignLogicalExecutionTime() { /** Cache of the set of upstream reactions. */ private Set dependsOnReactionsCache; - + /** * Array of runtime instances of this reaction. * This has length 1 unless the reaction is contained @@ -563,7 +563,7 @@ public class Runtime { /** ID ranging from 0 to parent.getTotalWidth() - 1. */ public int id; public int level; - + public ReactionInstance getReaction() { return ReactionInstance.this; } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 80629b81a0..ae5324fa3d 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -26,7 +26,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator; -import static org.lflang.ASTUtils.getLiteralTimeValue; +import static org.lflang.ast.ASTUtils.getLiteralTimeValue; import java.util.ArrayList; import java.util.HashMap; @@ -38,7 +38,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Optional; import java.util.Set; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; import org.lflang.TimeValue; diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index 8d9788e19e..585d65c96a 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -4,7 +4,7 @@ import java.util.Objects; import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.TimeValue; import org.lflang.lf.Action; diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 600100b41d..6e4688af8c 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -2,7 +2,7 @@ import java.util.List; import java.util.ArrayList; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.Target; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; diff --git a/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java b/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java index 72d4939714..f5aa244e60 100644 --- a/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java @@ -1,8 +1,8 @@ package org.lflang.generator.c; -import static org.lflang.ASTUtils.getInferredType; +import static org.lflang.ast.ASTUtils.getInferredType; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.DelayBodyGenerator; import org.lflang.lf.Action; import org.lflang.lf.VarRef; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 31a285af5e..06fbb41427 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -24,14 +24,14 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator.c; -import static org.lflang.ASTUtils.allActions; -import static org.lflang.ASTUtils.allPorts; -import static org.lflang.ASTUtils.allReactions; -import static org.lflang.ASTUtils.allStateVars; -import static org.lflang.ASTUtils.getInferredType; -import static org.lflang.ASTUtils.isInitialized; -import static org.lflang.ASTUtils.toDefinition; -import static org.lflang.ASTUtils.toText; +import static org.lflang.ast.ASTUtils.allActions; +import static org.lflang.ast.ASTUtils.allPorts; +import static org.lflang.ast.ASTUtils.allReactions; +import static org.lflang.ast.ASTUtils.allStateVars; +import static org.lflang.ast.ASTUtils.getInferredType; +import static org.lflang.ast.ASTUtils.isInitialized; +import static org.lflang.ast.ASTUtils.toDefinition; +import static org.lflang.ast.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; import java.io.File; @@ -52,7 +52,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeMap; import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; @@ -105,154 +105,123 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * Generator for C target. This class generates C code defining each reactor * class given in the input .lf file and imported .lf files. The generated code * has the following components: - * - * * A typedef for inputs, outputs, and actions of each reactor class. These - * define the types of the variables that reactions use to access inputs and - * action values and to set output values. - * - * * A typedef for a "self" struct for each reactor class. One instance of this - * struct will be created for each reactor instance. See below for details. - * - * * A function definition for each reaction in each reactor class. These - * functions take an instance of the self struct as an argument. - * - * * A constructor function for each reactor class. This is used to create - * a new instance of the reactor. - * - * After these, the main generated function is `_lf_initialize_trigger_objects()`. + *
    + *
  • A typedef for inputs, outputs, and actions of each reactor class. These + * define the types of the variables that reactions use to access inputs and + * action values and to set output values.
  • + *
  • A typedef for a "self" struct for each reactor class. One instance of this + * struct will be created for each reactor instance. See below for details.
  • + *
  • A function definition for each reaction in each reactor class. These + * functions take an instance of the self struct as an argument.
  • + *
  • A constructor function for each reactor class. This is used to create + * a new instance of the reactor. + * After these, the main generated function is _lf_initialize_trigger_objects(). * This function creates the instances of reactors (using their constructors) * and makes connections between them. - * - * A few other smaller functions are also generated. - * - * ## Self Struct - * - * The "self" struct has fields for each of the following: - * - * * parameter: the field name and type match the parameter. - * * state: the field name and type match the state. - * * action: the field name prepends the action name with "_lf_". - * A second field for the action is also created to house the trigger_t object. - * That second field prepends the action name with "_lf__". - * * output: the field name prepends the output name with "_lf_". - * * input: the field name prepends the output name with "_lf_". - * A second field for the input is also created to house the trigger_t object. - * That second field prepends the input name with "_lf__". - * + * A few other smaller functions are also generated.

    Self Struct

    + * The "self" struct has fields for each of the following:
  • + *
  • parameter: the field name and type match the parameter.
  • + *
  • state: the field name and type match the state.
  • + *
  • action: the field name prepends the action name with "lf". + * A second field for the action is also created to house the trigger_t object. + * That second field prepends the action name with "_lf__".
  • + *
  • output: the field name prepends the output name with "lf".
  • + *
  • input: the field name prepends the output name with "lf". + * A second field for the input is also created to house the trigger_t object. + * That second field prepends the input name with "_lf__". * If, in addition, the reactor contains other reactors and reacts to their outputs, * then there will be a struct within the self struct for each such contained reactor. - * The name of that self struct will be the name of the contained reactor prepended with "_lf_". + * The name of that self struct will be the name of the contained reactor prepended with "lf". * That inside struct will contain pointers the outputs of the contained reactors * that are read together with pointers to booleans indicating whether those outputs are present. - * * If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to * trigger_t object (see reactor.h) for the shutdown event and an action struct named - * _lf_shutdown on the self struct. - * - * ## Reaction Functions - * + * _lf_shutdown on the self struct.

    Reaction Functions

    * For each reaction in a reactor class, this generator will produce a C function - * that expects a pointer to an instance of the "self" struct as an argument. + * that expects a pointer to an instance of the "self" struct as an argument. * This function will contain verbatim the C code specified in the reaction, but * before that C code, the generator inserts a few lines of code that extract from the * self struct the variables that that code has declared it will use. For example, if - * the reaction declares that it is triggered by or uses an input named "x" of type - * int, the function will contain a line like this: - * ``` - * r_x_t* x = self->_lf_x; - * ``` - * where `r` is the full name of the reactor class and the struct type `r_x_t` - * has fields `is_present` and `value`, where the type of `value` matches the port type. + * the reaction declares that it is triggered by or uses an input named "x" of type + * int, the function will contain a line like this:
      r_x_t* x = self->_lf_x;
    + * 
    where r is the full name of the reactor class and the struct type r_x_t + * has fields is_present and value, where the type of value matches the port type. * If the programmer fails to declare that it uses x, then the absence of the - * above code will trigger a compile error when the verbatim code attempts to read `x`. - * - * ## Constructor - * + * above code will trigger a compile error when the verbatim code attempts to read x.

    Constructor

    * For each reactor class, this generator will create a constructor function named - * `new_r`, where `r` is the reactor class name. This function will malloc and return - * a pointer to an instance of the "self" struct. This struct initially represents + * new_r, where r is the reactor class name. This function will malloc and return + * a pointer to an instance of the "self" struct. This struct initially represents * an unconnected reactor. To establish connections between reactors, additional * information needs to be inserted (see below). The self struct is made visible - * to the body of a reaction as a variable named "self". The self struct contains the - * following: - * - * * Parameters: For each parameter `p` of the reactor, there will be a field `p` - * with the type and value of the parameter. So C code in the body of a reaction - * can access parameter values as `self->p`. - * - * * State variables: For each state variable `s` of the reactor, there will be a field `s` - * with the type and value of the state variable. So C code in the body of a reaction - * can access state variables as `self->s`. - * + * to the body of a reaction as a variable named "self". The self struct contains the + * following:
  • + *
  • Parameters: For each parameter p of the reactor, there will be a field p + * with the type and value of the parameter. So C code in the body of a reaction + * can access parameter values as self->p.
  • + *
  • State variables: For each state variable s of the reactor, there will be a field s + * with the type and value of the state variable. So C code in the body of a reaction + * can access state variables as self->s. * The self struct also contains various fields that the user is not intended to - * use. The names of these fields begin with at least two underscores. They are: - * - * * Outputs: For each output named `out`, there will be a field `_lf_out` that is - * a struct containing a value field whose type matches that of the output. - * The output value is stored here. That struct also has a field `is_present` - * that is a boolean indicating whether the output has been set. - * This field is reset to false at the start of every time - * step. There is also a field `num_destinations` whose value matches the - * number of downstream reactors that use this variable. This field must be - * set when connections are made or changed. It is used to determine for - * a mutable input destination whether a copy needs to be made. - * - * * Inputs: For each input named `in` of type T, there is a field named `_lf_in` - * that is a pointer struct with a value field of type T. The struct pointed - * to also has an `is_present` field of type bool that indicates whether the - * input is present. - * - * * Outputs of contained reactors: If a reactor reacts to outputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields pointing to those outputs. For example, - * if `r` has an output `out` of type T, then there will be field in `_lf_r` - * named `out` that points to a struct containing a value field - * of type T and a field named `is_present` of type bool. - * - * * Inputs of contained reactors: If a reactor sends to inputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields for storing the values provided to those - * inputs. For example, if R has an input `in` of type T, then there will - * be field in _lf_R named `in` that is a struct with a value field - * of type T and a field named `is_present` of type bool. - * - * * Actions: If the reactor has an action a (logical or physical), then there - * will be a field in the self struct named `_lf_a` and another named `_lf__a`. - * The type of the first is specific to the action and contains a `value` - * field with the type and value of the action (if it has a value). That - * struct also has a `has_value` field, an `is_present` field, and a - * `token` field (which is NULL if the action carries no value). - * The `_lf__a` field is of type trigger_t. - * That struct contains various things, including an array of reactions - * sensitive to this trigger and a lf_token_t struct containing the value of - * the action, if it has a value. See reactor.h in the C library for - * details. - * - * * Reactions: Each reaction will have several fields in the self struct. - * Each of these has a name that begins with `_lf__reaction_i`, where i is - * the number of the reaction, starting with 0. The fields are: - * * _lf__reaction_i: The struct that is put onto the reaction queue to - * execute the reaction (see reactor.h in the C library). - * - * * Timers: For each timer t, there is are two fields in the self struct: - * * _lf__t: The trigger_t struct for this timer (see reactor.h). - * * _lf__t_reactions: An array of reactions (pointers to the - * reaction_t structs on this self struct) sensitive to this timer. - * - * * Triggers: For each Timer, Action, Input, and Output of a contained - * reactor that triggers reactions, there will be a trigger_t struct - * on the self struct with name `_lf__t`, where t is the name of the trigger. - * - * ## Connections Between Reactors - * + * use. The names of these fields begin with at least two underscores. They are:
  • + *
  • Outputs: For each output named out, there will be a field _lf_out that is + * a struct containing a value field whose type matches that of the output. + * The output value is stored here. That struct also has a field is_present + * that is a boolean indicating whether the output has been set. + * This field is reset to false at the start of every time + * step. There is also a field num_destinations whose value matches the + * number of downstream reactors that use this variable. This field must be + * set when connections are made or changed. It is used to determine for + * a mutable input destination whether a copy needs to be made.
  • + *
  • Inputs: For each input named in of type T, there is a field named _lf_in + * that is a pointer struct with a value field of type T. The struct pointed + * to also has an is_present field of type bool that indicates whether the + * input is present.
  • + *
  • Outputs of contained reactors: If a reactor reacts to outputs of a + * contained reactor r, then the self struct will contain a nested struct + * named _lf_r that has fields pointing to those outputs. For example, + * if r has an output out of type T, then there will be field in _lf_r + * named out that points to a struct containing a value field + * of type T and a field named is_present of type bool.
  • + *
  • Inputs of contained reactors: If a reactor sends to inputs of a + * contained reactor r, then the self struct will contain a nested struct + * named _lf_r that has fields for storing the values provided to those + * inputs. For example, if R has an input in of type T, then there will + * be field in _lf_R named in that is a struct with a value field + * of type T and a field named is_present of type bool.
  • + *
  • Actions: If the reactor has an action a (logical or physical), then there + * will be a field in the self struct named _lf_a and another named _lf__a. + * The type of the first is specific to the action and contains a value + * field with the type and value of the action (if it has a value). That + * struct also has a has_value field, an is_present field, and a + * token field (which is NULL if the action carries no value). + * The _lf__a field is of type trigger_t. + * That struct contains various things, including an array of reactions + * sensitive to this trigger and a lf_token_t struct containing the value of + * the action, if it has a value. See reactor.h in the C library for + * details.
  • + *
  • Reactions: Each reaction will have several fields in the self struct. + * Each of these has a name that begins with _lf__reaction_i, where i is + * the number of the reaction, starting with 0. The fields are:
      + *
    • _lf__reaction_i: The struct that is put onto the reaction queue to + * execute the reaction (see reactor.h in the C library).
    • + *
    • Timers: For each timer t, there is are two fields in the self struct:
        + *
      • _lf__t: The trigger_t struct for this timer (see reactor.h).
      • + *
      • _lf__t_reactions: An array of reactions (pointers to the + * reaction_t structs on this self struct) sensitive to this timer.
      • + *
      + *
    • + *
    + *
  • + *
  • Triggers: For each Timer, Action, Input, and Output of a contained + * reactor that triggers reactions, there will be a trigger_t struct + * on the self struct with name _lf__t, where t is the name of the trigger.

    Connections Between Reactors

    * Establishing connections between reactors involves two steps. * First, each destination (e.g. an input port) must have pointers to * the source (the output port). As explained above, for an input named - * `in`, the field `_lf_in->value` is a pointer to the output data being read. - * In addition, `_lf_in->is_present` is a pointer to the corresponding - * `out->is_present` field of the output reactor's self struct. - * - * In addition, the `reaction_i` struct on the self struct has a `triggers` + * in, the field _lf_in->value is a pointer to the output data being read. + * In addition, _lf_in->is_present is a pointer to the corresponding + * out->is_present field of the output reactor's self struct. + * In addition, the reaction_i struct on the self struct has a triggers * field that records all the trigger_t structs for ports and actions * that are triggered by the i-th reaction. The triggers field is * an array of arrays of pointers to trigger_t structs. @@ -266,34 +235,30 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * reaction_i struct gives the length of the triggered_sizes and * (outer) triggers arrays. The num_outputs field is equal to the * total number of single ports and multiport channels that the reaction - * writes to. - * - * ## Runtime Tables - * + * writes to.

    Runtime Tables

    * This generator creates an populates the following tables used at run time. - * These tables may have to be resized and adjusted when mutations occur. - * - * * _lf_is_present_fields: An array of pointers to booleans indicating whether an - * event is present. The _lf_start_time_step() function in reactor_common.c uses - * this to mark every event absent at the start of a time step. The size of this - * table is contained in the variable _lf_is_present_fields_size. - * * This table is accompanied by another list, _lf_is_present_fields_abbreviated, - * which only contains the is_present fields that have been set to true in the - * current tag. This list can allow a performance improvement if most ports are - * seldom present because only fields that have been set to true need to be - * reset to false. - * - * * _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown - * reactions. The length of this table is in the _lf_shutdown_triggers_size - * variable. - * - * * _lf_timer_triggers: An array of pointers to trigger_t structs for timers that - * need to be started when the program runs. The length of this table is in the - * _lf_timer_triggers_size variable. - * - * * _lf_action_table: For a federated execution, each federate will have this table - * that maps port IDs to the corresponding action struct, which can be cast to - * action_base_t. + * These tables may have to be resized and adjusted when mutations occur.
  • + *
  • _lf_is_present_fields: An array of pointers to booleans indicating whether an + * event is present. The _lf_start_time_step() function in reactor_common.c uses + * this to mark every event absent at the start of a time step. The size of this + * table is contained in the variable _lf_is_present_fields_size.
      + *
    • This table is accompanied by another list, _lf_is_present_fields_abbreviated, + * which only contains the is_present fields that have been set to true in the + * current tag. This list can allow a performance improvement if most ports are + * seldom present because only fields that have been set to true need to be + * reset to false.
    • + *
    + *
  • + *
  • _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown + * reactions. The length of this table is in the _lf_shutdown_triggers_size + * variable.
  • + *
  • _lf_timer_triggers: An array of pointers to trigger_t structs for timers that + * need to be started when the program runs. The length of this table is in the + * _lf_timer_triggers_size variable.
  • + *
  • _lf_action_table: For a federated execution, each federate will have this table + * that maps port IDs to the corresponding action struct, which can be cast to + * action_base_t.
  • + *
* * @author Edward A. Lee * @author Marten Lohstroh @@ -896,7 +861,7 @@ private void generateReactorDefinitions() throws IOException { * * @param reactorInstance The Reactor Class * @param parentTpr {@link TypeParameterizedReactor} of Parent - * */ + */ private void resolveTemplatedTypes(ReactorInstance reactorInstance, TypeParameterizedReactor parentTpr) { for (var child : reactorInstance.children) { if (parentTpr.typeArgs() != null) { @@ -1052,17 +1017,19 @@ protected void copyTargetFiles() throws IOException { * Generate a reactor class definition for the specified federate. * A class definition has four parts: * - * * Preamble code, if any, specified in the Lingua Franca file. - * * A "self" struct type definition (see the class documentation above). - * * A function for each reaction. - * * A constructor for creating an instance. - * for deleting an instance. + *
    + *
  • Preamble code, if any, specified in the Lingua Franca file.
  • + *
  • A "self" struct type definition (see the class documentation above).
  • + *
  • A function for each reaction.
  • + *
  • A constructor for creating an instance. + * for deleting an instance.
  • + *
* - * If the reactor is the main reactor, then + *

If the reactor is the main reactor, then * the generated code may be customized. Specifically, * if the main reactor has reactions, these reactions * will not be generated if they are triggered by or send - * data to contained reactors that are not in the federate. + * data to contained reactors that are not in the federate.

*/ private void generateReactorClass(TypeParameterizedReactor tpr) throws IOException { // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index 691019b160..5da00ac70e 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -1,8 +1,8 @@ package org.lflang.generator.c; -import static org.lflang.ASTUtils.allMethods; +import static org.lflang.ast.ASTUtils.allMethods; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Method; diff --git a/org.lflang/src/org/lflang/generator/c/CModesGenerator.java b/org.lflang/src/org/lflang/generator/c/CModesGenerator.java index 48198bbf09..6ff682d49f 100644 --- a/org.lflang/src/org/lflang/generator/c/CModesGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CModesGenerator.java @@ -2,7 +2,7 @@ import java.util.List; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index 1d563b5de9..786b4701de 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -1,7 +1,7 @@ package org.lflang.generator.c; import org.lflang.generator.ParameterInstance; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Initializer; import org.lflang.lf.Parameter; diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 9cdc20db8f..619a2bd134 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -1,6 +1,6 @@ package org.lflang.generator.c; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; import org.lflang.Target; diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 797ab93beb..4b2d6678b0 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -10,7 +10,7 @@ import java.util.Map; import java.util.Set; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetConfig; diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 00ef4c0faa..993168cad9 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -7,7 +7,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index d2e2a56ed8..f43d975632 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -1,6 +1,6 @@ package org.lflang.generator.c; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ModeInstance; import org.lflang.generator.ReactorInstance; diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index f653d3f997..3a0b1b88de 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -10,10 +10,9 @@ import java.util.Arrays; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.TargetConfig; @@ -685,7 +684,7 @@ private static String deferredInputNumDestinations( )); code.endChannelIteration(port); } - + code.endScopedRangeBlock(sendingRange); } } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index b629684bf7..d403c1cddc 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -9,7 +9,7 @@ package org.lflang.generator.c; import java.util.List; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactorInstance; diff --git a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java index 26925b7486..20ed65687b 100644 --- a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java +++ b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Set; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 0de272b7bf..5f832e692a 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Instantiation; diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index 9ca2f7222f..48cc8f9e10 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -28,11 +28,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.InferredType; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.GeneratorBase; import org.lflang.generator.c.CUtil; import org.lflang.lf.Expression; -import org.lflang.lf.ParameterReference; -import org.lflang.ASTUtils; /** diff --git a/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java index fd47c4b66e..b69cfc7da0 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java @@ -1,8 +1,7 @@ package org.lflang.generator.python; -import org.lflang.ASTUtils; -import org.lflang.federated.generator.FedASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.c.CDelayBodyGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index afa33ac46a..d72f6d4dcd 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -38,7 +38,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.Target; import org.lflang.TargetProperty; diff --git a/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java index 7daba8d542..a2d1e240d1 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java @@ -2,7 +2,7 @@ import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Method; import org.lflang.lf.MethodArgument; import org.lflang.lf.Reactor; diff --git a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java index fe78d8187f..838e7a27a3 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java @@ -1,20 +1,11 @@ package org.lflang.generator.python; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; -import com.google.common.base.Objects; - -import org.lflang.ASTUtils; -import org.lflang.InferredType; -import org.lflang.generator.GeneratorBase; +import org.lflang.ast.ASTUtils; import org.lflang.generator.ParameterInstance; -import org.lflang.lf.Expression; -import org.lflang.lf.ParameterReference; import org.lflang.lf.ReactorDecl; -import org.lflang.lf.Assignment; import org.lflang.lf.Parameter; diff --git a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java index a5308798d6..0c0c9b6cad 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java @@ -6,11 +6,10 @@ import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.Action; -import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; import java.util.List; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.c.CGenerator; import static org.lflang.generator.c.CUtil.generateWidthVariable; diff --git a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java index e2fd7af86a..b69320f6af 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java @@ -3,7 +3,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.TargetConfig; import org.lflang.generator.CodeBuilder; import org.lflang.generator.c.CPreambleGenerator; diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 8ea44b2a2f..99f1b5c180 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -4,9 +4,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; import org.lflang.Target; diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java index e95e9766bd..49d95e4be9 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java @@ -2,10 +2,8 @@ import java.util.ArrayList; import java.util.List; -import org.lflang.ASTUtils; -import org.lflang.federated.generator.FederateInstance; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.DelayBodyGenerator; import org.lflang.generator.ParameterInstance; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Reaction; diff --git a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java index c8c973f896..e318a8812c 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java @@ -2,9 +2,8 @@ import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; diff --git a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java index 7fc1c899a2..69efcd3fab 100644 --- a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java +++ b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java @@ -31,7 +31,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.TargetProperty; import org.lflang.TargetProperty.TargetPropertyType; import org.lflang.generator.InvalidLfSourceException; diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 521d6fd2ea..82c0080d6e 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -27,6 +27,7 @@ package org.lflang.generator.rust import org.lflang.* import org.lflang.TargetProperty.BuildType +import org.lflang.ast.ASTUtils import org.lflang.generator.* import org.lflang.inBlock import org.lflang.indexInContainer @@ -34,12 +35,10 @@ import org.lflang.inferredType import org.lflang.isBank import org.lflang.isInput import org.lflang.isLogical -import org.lflang.isMultiport import org.lflang.lf.* import org.lflang.lf.Timer import java.nio.file.Path import java.util.* -import kotlin.text.capitalize private typealias Ident = String const val PARALLEL_RT_FEATURE = "parallel-runtime" diff --git a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt index 4ff7c0593f..b45a67fcc3 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt @@ -24,7 +24,7 @@ package org.lflang.generator.rust -import org.lflang.ASTUtils.toText +import org.lflang.ast.ASTUtils.toText import org.lflang.InferredType import org.lflang.TimeValue import org.lflang.generator.TargetCode diff --git a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt index 61aac6750e..e561696524 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt @@ -1,7 +1,6 @@ package org.lflang.generator.ts -import org.lflang.ASTUtils -import org.lflang.Target +import org.lflang.ast.ASTUtils import org.lflang.generator.DelayBodyGenerator import org.lflang.lf.Action import org.lflang.lf.VarRef diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt index aca577aad0..b82e1d20af 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt @@ -1,10 +1,8 @@ package org.lflang.generator.ts import org.lflang.ErrorReporter -import org.lflang.ASTUtils -import org.lflang.federated.generator.FederateInstance +import org.lflang.ast.ASTUtils import org.lflang.generator.PrependOperator -import org.lflang.generator.getTargetTimeExpr import org.lflang.isBank import org.lflang.isMultiport import org.lflang.joinWithCommas @@ -12,7 +10,7 @@ import org.lflang.lf.* import org.lflang.lf.Timer import org.lflang.toText import kotlin.collections.HashSet -import java.util.StringJoiner +import java.util.StringJoiner import java.util.LinkedList diff --git a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt index 6ac2d8b28a..6ac0d7b321 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt @@ -1,6 +1,6 @@ package org.lflang.generator.ts -import org.lflang.ASTUtils +import org.lflang.ast.ASTUtils import org.lflang.generator.getTargetInitializer import org.lflang.lf.StateVar import java.util.* diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.java b/org.lflang/src/org/lflang/generator/ts/TSTypes.java index e89fff00d4..2e2c6a6dff 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSTypes.java +++ b/org.lflang/src/org/lflang/generator/ts/TSTypes.java @@ -2,7 +2,7 @@ import java.util.List; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.TimeValue; import org.lflang.generator.TargetTypes; import org.lflang.generator.UnsupportedGeneratorFeatureException; diff --git a/org.lflang/src/org/lflang/graph/InstantiationGraph.java b/org.lflang/src/org/lflang/graph/InstantiationGraph.java index 993ae21b2a..53b59cbbb5 100644 --- a/org.lflang/src/org/lflang/graph/InstantiationGraph.java +++ b/org.lflang/src/org/lflang/graph/InstantiationGraph.java @@ -31,7 +31,7 @@ import java.util.Set; import org.eclipse.emf.ecore.resource.Resource; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Instantiation; import org.lflang.lf.Model; import org.lflang.lf.Reactor; diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index 70a05a40f7..0e521e8cc4 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -26,7 +26,7 @@ package org.lflang.scoping; import static java.util.Collections.emptyList; -import static org.lflang.ASTUtils.*; +import static org.lflang.ast.ASTUtils.*; import com.google.inject.Inject; diff --git a/org.lflang/src/org/lflang/validation/AttributeSpec.java b/org.lflang/src/org/lflang/validation/AttributeSpec.java index c5a530581b..48b10a140a 100644 --- a/org.lflang/src/org/lflang/validation/AttributeSpec.java +++ b/org.lflang/src/org/lflang/validation/AttributeSpec.java @@ -32,7 +32,7 @@ import java.util.Set; import java.util.stream.Collectors; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; import org.lflang.lf.LfPackage.Literals; diff --git a/org.lflang/src/org/lflang/validation/BaseLFValidator.java b/org.lflang/src/org/lflang/validation/BaseLFValidator.java index 02b321bf10..34e184a720 100644 --- a/org.lflang/src/org/lflang/validation/BaseLFValidator.java +++ b/org.lflang/src/org/lflang/validation/BaseLFValidator.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2021, TU Dresden. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -34,7 +34,7 @@ import org.eclipse.xtext.validation.Check; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.CheckType; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.TimeUnit; import org.lflang.lf.LfPackage.Literals; import org.lflang.lf.Time; @@ -45,7 +45,7 @@ public class BaseLFValidator extends AbstractLFValidator { public void checkTime(Time time) { if (!ASTUtils.isValidTime(time)) { error("Invalid time unit. " + - "Should be one of " + + "Should be one of " + TimeUnit.list() + ".", Literals.TIME__UNIT); } } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index fd37e5a3a7..d64eb5dc35 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -26,13 +26,13 @@ ***************/ package org.lflang.validation; -import static org.lflang.ASTUtils.inferPortWidth; -import static org.lflang.ASTUtils.isGeneric; -import static org.lflang.ASTUtils.isInteger; -import static org.lflang.ASTUtils.isOfTimeType; -import static org.lflang.ASTUtils.isZero; -import static org.lflang.ASTUtils.toDefinition; -import static org.lflang.ASTUtils.toOriginalText; +import static org.lflang.ast.ASTUtils.inferPortWidth; +import static org.lflang.ast.ASTUtils.isGeneric; +import static org.lflang.ast.ASTUtils.isInteger; +import static org.lflang.ast.ASTUtils.isOfTimeType; +import static org.lflang.ast.ASTUtils.isZero; +import static org.lflang.ast.ASTUtils.toDefinition; +import static org.lflang.ast.ASTUtils.toOriginalText; import java.io.File; import java.io.IOException; @@ -56,7 +56,7 @@ import org.eclipse.xtext.validation.Check; import org.eclipse.xtext.validation.CheckType; import org.eclipse.xtext.validation.ValidationMessageAcceptor; -import org.lflang.ASTUtils; +import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.ModelInfo; @@ -74,7 +74,6 @@ import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; -import org.lflang.lf.CodeExpr; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; import org.lflang.lf.Expression; From bcbfa449c4de745151bd26081d85ec1d0fdd4a1c Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 15:39:00 -0700 Subject: [PATCH 396/709] Fix JavaDoc in PortInstance.java --- .../src/org/lflang/generator/PortInstance.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/PortInstance.java b/org.lflang/src/org/lflang/generator/PortInstance.java index 15383b7676..57dbdcf73d 100644 --- a/org.lflang/src/org/lflang/generator/PortInstance.java +++ b/org.lflang/src/org/lflang/generator/PortInstance.java @@ -131,12 +131,14 @@ public void clearCaches() { * on the returned list. * * Each item in the returned list has the following fields: - * * startRange The starting channel index of this port. - * * rangeWidth The number of channels sent to the destinations. - * * destinations A list of port ranges for destination ports, each - * of which has the same width as rangeWidth. - * - * Each item also has a method, getNumberOfDestinationReactors(), + *
    + *
  • {@code startRange}: The starting channel index of this port.
  • + *
  • {@code rangeWidth}: The number of channels sent to the destinations.
  • + *
  • {@code destinations}: A list of port ranges for destination ports, each + * of which has the same width as {@code rangeWidth}.
  • + *
+ * + * Each item also has a method, {@link SendRange#getNumberOfDestinationReactors()}, * that returns the total number of unique destination reactors for * its range. This is not necessarily the same as the number * of ports in its destinations field because some of the ports may From 96aebff26d6c15a814cb36d1d7164a9cfff8ccaa Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 15:41:19 -0700 Subject: [PATCH 397/709] More MarkDown -> HTML. --- org.lflang/src/org/lflang/generator/ReactionInstance.java | 2 +- org.lflang/src/org/lflang/generator/RuntimeRange.java | 2 +- .../src/org/lflang/generator/c/CTriggerObjectsGenerator.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index 98e26c03de..1d7cbab52a 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -543,7 +543,7 @@ public TimeValue assignLogicalExecutionTime() { * of the containing reactors are w0, w1, and w2, and * we are interested in the instance at bank indexes * b0, b1, and b2. That instance is in this array at - * location given by the **natural ordering**, which + * location given by the natural ordering, which * is the mixed radix number b2%w2; b1%w1. */ private List runtimeInstances; diff --git a/org.lflang/src/org/lflang/generator/RuntimeRange.java b/org.lflang/src/org/lflang/generator/RuntimeRange.java index 449e6dedf9..36f132b27e 100644 --- a/org.lflang/src/org/lflang/generator/RuntimeRange.java +++ b/org.lflang/src/org/lflang/generator/RuntimeRange.java @@ -273,7 +273,7 @@ public RuntimeRange head(int newWidth) { } /** - * Return the list of **natural identifiers** for the runtime instances + * Return the list of natural identifiers for the runtime instances * in this range. Each returned identifier is an integer representation * of the mixed-radix number [d0, ... , dn] with radices [w0, ... , wn], * where d0 is the bank or channel index of this RuntimeRange's instance, which diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index 3a0b1b88de..2871dbab96 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -178,7 +178,7 @@ public static String generateSchedulerInitializer( } /** - * * Set the reaction priorities based on dependency analysis. + * Set the reaction priorities based on dependency analysis. * * @param reactor The reactor on which to do this. */ @@ -191,7 +191,7 @@ private static String setReactionPriorities( } /** - * * Set the reaction priorities based on dependency analysis. + * Set the reaction priorities based on dependency analysis. * * @param reactor The reactor on which to do this. * @param builder Where to write the code. From e0dc33abd715e140c965b21ff3bd0a9743731425 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 15:42:51 -0700 Subject: [PATCH 398/709] Revert "Removed the advice to run the formatter" This reverts commit 11ccfad20c2e7fcd150de800e8e1e29d466b6843. --- CONTRIBUTING.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 55716f5b17..13d24c957c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,8 @@ Test categories are declared in the [TestCategory enum in TestRegistry.java](htt ### Workflow All code contributions must go through a pull request (PR), pass all tests run in CI, and get an approving review before it is merged. Pushing to the `master` branch is restricted. All code review is conducted using the Github review system on PRs. Before requesting a code review, ensure that you have: -- documented your code; +- applied the [code formatter](#code-style-and-formatting); +- [documented](#code-style-and-formatting) your code; - written [tests](#writing-tests) that cover your code; and - accompanied any remaining `TODO`s or `FIXME`s with a link to an active [issue](#reporting-issues). @@ -72,6 +73,18 @@ Perform merges to bring your feature branch up-to-date with master locally (do n #### Addressing reviews To address feedback from code review, implement changes and push to your feature branch. If you are certain that a reviewer's concern has been addressed by your new changes, hit the `Resolve conversation` button. If you are unsure, ask for follow up in the conversation and let the reviewer determine whether the feedback was addressed accordingly. +### Code style and formatting +The Lingua Franca compiler is implemented in Java and Kotlin. The overarching advice is to use each language's most widely used idioms and conventions, which are fortunately very similar. The code base is shipped with a [Spotless](https://github.com/diffplug/spotless) configuration to check and enforce style compliance. Lingua Franca code (e.g., tests) in this repository is also automatically formatted via Spotless. + +- To check that modified files are formatted correctly, run: +``` +./gradlew spotlessCheck +``` +- To apply the changes recommended by the formatter, run: +``` +./gradlew spotlessApply +``` + #### General guidelines - _Do not copy-paste code._ If you want to reuse code, factor it out into a method and call it. - _Keep methods concise._ As a rule of thumb, a method should fit on your screen so that it can be read without scrolling. We impose no hard limit on method length, but anything above 40 lines should be considered for breaking up. From d591db946429d4294b95650400f61bffcaebfc3e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 15:49:37 -0700 Subject: [PATCH 399/709] More MarkDown -> HTML. --- .../src/org/lflang/tests/TestRegistry.java | 22 ++++++++++-------- .../federated/extensions/CExtension.java | 8 ++++--- .../org/lflang/generator/c/CGenerator.java | 23 ++++++++++++------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java index 10fa68acaf..1249ea25be 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java +++ b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java @@ -110,16 +110,18 @@ public Set getTests(Target t, TestCategory c) { * insensitive. * * For example, the following files will all map to THREADED: - * - C/threaded/Foo.lf - * - C/THREADED/Foo.lf - * - C/Threaded/Foo.lf - * - C/foo/threaded/Bar.lf - * - C/foo/bar/threaded/Threaded.lf - * - C/federated/threaded/bar.lf - * but the following will not: - * - C/Foo.lf (maps to COMMON) - * - C/Threaded.lf (maps to COMMON) - * - C/threaded/federated/foo.lf (maps to FEDERATED) + *
    + *
  • C/threaded/Foo.lf
  • + *
  • C/THREADED/Foo.lf
  • + *
  • C/Threaded/Foo.lf
  • + *
  • C/foo/threaded/Bar.lf
  • + *
  • C/foo/bar/threaded/Threaded.lf
  • + *
  • C/federated/threaded/bar.lf + * but the following will not:
  • + *
  • C/Foo.lf (maps to COMMON)
  • + *
  • C/Threaded.lf (maps to COMMON)
  • + *
  • C/threaded/federated/foo.lf (maps to FEDERATED)
  • + *
* * @author Marten Lohstroh */ diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index 9252e93210..32f06c71bc 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -62,10 +62,12 @@ * An extension class to the CGenerator that enables certain federated * functionalities. Currently, this class offers the following features: * - * - Allocating and initializing C structures for federated communication - - * Creating status field for network input ports that help the receiver logic in + *
    + *
  • Allocating and initializing C structures for federated communication
  • + *
  • Creating status field for network input ports that help the receiver logic in * federate.c communicate the status of a network input port with network input - * control reactions. + * control reactions.
  • + *
* * @author {Soroush Bateni } * @author {Hou Seng Wong } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 06fbb41427..9997b62302 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -780,8 +780,11 @@ private boolean hasDeadlines(List reactors) { * Look at the 'reactor' eResource. * If it is an imported .lf file, incorporate it into the current * program in the following manner: - * - Merge its target property with `targetConfig` - * - If there are any preambles, add them to the preambles of the reactor. + *
    + *
  • Merge its target property with {@code targetConfig}
  • + *
  • If there are any preambles, add them to the preambles of the reactor.
  • + *
+ * */ private void inspectReactorEResource(ReactorDecl reactor) { // If the reactor is imported, look at the @@ -841,9 +844,11 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { * * Imported reactors' original .lf file is * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. + *
    + *
  • If there are any cmake-include files, add them to the current list + * of cmake-include files.
  • + *
  • If there are any preambles, add them to the preambles of the reactor.
  • + *
*/ private void generateReactorDefinitions() throws IOException { var generatedReactors = new LinkedHashSet(); @@ -923,9 +928,11 @@ it.tpr, p, getTarget(), errorReporter, types, new CodeBuilder(), true, it.decl() * * Imported reactors' original .lf file is * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. + *
    + *
  • If there are any cmake-include files, add them to the current list + * of cmake-include files.
  • + *
  • If there are any preambles, add them to the preambles of the reactor.
  • + *
* * @param reactor Used to extract children from */ From fe6b71aeebc940361c8725eefa5ea6231c7e9f8c Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 15:52:24 -0700 Subject: [PATCH 400/709] More MarkDown -> HTML. --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 8 +++++--- .../org/lflang/generator/python/PythonModeGenerator.java | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index e609144b62..80df63fd0e 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -333,9 +333,11 @@ public LFCommand buildWestFlashCommand() { * is shown. * * Errors currently detected: - * - C++ compiler used to compile C files: This error shows up as - * '#error "The CMAKE_C_COMPILER is set to a C++ compiler"' in - * the 'CMakeOutput' string. + *
    + *
  • C++ compiler used to compile C files: This error shows up as + * '#error "The CMAKE_C_COMPILER is set to a C++ compiler"' in + * the 'CMakeOutput' string.
  • + *
* * @param CMakeOutput The captured output from CMake. * @return true if the provided 'CMakeOutput' contains a known error. diff --git a/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java index 638af02eff..90af635727 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java @@ -31,8 +31,10 @@ public static void generateResetReactionsIfNeeded(List reactors) { /** * Generate reset reactions that reset state variables in - * - the reactor, and, - * - the modes within the reactor. + *
    + *
  • the reactor, and,
  • + *
  • the modes within the reactor.
  • + *
* * @param reactor The reactor. */ From af4cabb89bf30cd6ba22c4b9f69b20c56cb78f10 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 15:57:03 -0700 Subject: [PATCH 401/709] More MarkDown -> HTML. --- org.lflang/src/org/lflang/TargetProperty.java | 8 +++++--- .../lflang/federated/extensions/CExtensionUtils.java | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index ac3c183e3c..a974e17f03 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1421,9 +1421,11 @@ public String toString() { /** * Enumeration of clock synchronization modes. * - * - OFF: The clock synchronization is universally off. - * - STARTUP: Clock synchronization occurs at startup only. - * - ON: Clock synchronization occurs at startup and at runtime. + *
    + *
  • OFF: The clock synchronization is universally off.
  • + *
  • STARTUP: Clock synchronization occurs at startup only.
  • + *
  • ON: Clock synchronization occurs at startup and at runtime.
  • + *
* * @author Edward A. Lee */ diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index c6f62fc8d6..a924403c08 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -39,15 +39,17 @@ public class CExtensionUtils { /** * Generate C code that allocates sufficient memory for the following two * critical data structures that support network control reactions: - * - triggers_for_network_input_control_reactions: These are triggers that + *
    + *
  • triggers_for_network_input_control_reactions: These are triggers that * are * used at runtime to insert network input control reactions into the - * reaction queue. - * - trigger_for_network_output_control_reactions: Triggers for + * reaction queue.
  • + *
  • trigger_for_network_output_control_reactions: Triggers for * network output control reactions, which are unique per each output port. * There could be multiple network output control reactions for each * network - * output port if it is connected to multiple downstream federates. + * output port if it is connected to multiple downstream federates.
  • + *
* * @param federate The top-level federate instance * @return A string that allocates memory for the aforementioned three From a4e9117bebebdd4bc2c6b8a32b45f0cc6c56d2e1 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 15:50:01 -0700 Subject: [PATCH 402/709] Fix JavaDoc in CExtensionUtils.java --- .../org/lflang/federated/extensions/CExtensionUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index a924403c08..3eeee4b5cb 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -40,11 +40,10 @@ public class CExtensionUtils { * Generate C code that allocates sufficient memory for the following two * critical data structures that support network control reactions: *
    - *
  • triggers_for_network_input_control_reactions: These are triggers that - * are - * used at runtime to insert network input control reactions into the - * reaction queue.
  • - *
  • trigger_for_network_output_control_reactions: Triggers for + *
  • {@code triggers_for_network_input_control_reactions}: These are triggers that + * are used at runtime to insert network input control reactions into the + * reaction queue.
  • + *
  • {@code trigger_for_network_output_control_reactions}: Triggers for * network output control reactions, which are unique per each output port. * There could be multiple network output control reactions for each * network From f906cb5fee48f9273829b5336dc1c677f3a88abe Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:01:36 -0700 Subject: [PATCH 403/709] Backticks -> {@code } --- org.lflang/src/org/lflang/AttributeUtils.java | 4 ++-- org.lflang/src/org/lflang/FileConfig.java | 8 ++++---- org.lflang/src/org/lflang/TargetProperty.java | 2 +- org.lflang/src/org/lflang/ast/ASTUtils.java | 4 ++-- .../lflang/ast/DelayedConnectionTransformation.java | 4 ++-- .../federated/extensions/FedTargetExtension.java | 2 +- org.lflang/src/org/lflang/generator/GeneratorBase.java | 8 ++++---- .../src/org/lflang/generator/LFGeneratorContext.java | 2 +- .../org/lflang/generator/ReactionInstanceGraph.java | 2 +- .../src/org/lflang/generator/ReactorInstance.java | 8 ++++---- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.java | 4 ++-- .../org/lflang/generator/c/CMainFunctionGenerator.java | 6 +++--- .../src/org/lflang/generator/c/CModesGenerator.java | 4 ++-- .../src/org/lflang/generator/c/CTimerGenerator.java | 2 +- .../org/lflang/generator/python/PythonGenerator.java | 10 +++++----- org.lflang/src/org/lflang/graph/PrecedenceGraph.java | 4 ++-- org.lflang/src/org/lflang/util/LFCommand.java | 2 +- org.lflang/src/org/lflang/util/StringUtil.java | 2 +- org.lflang/src/org/lflang/validation/LFValidator.java | 2 +- 20 files changed, 41 insertions(+), 41 deletions(-) diff --git a/org.lflang/src/org/lflang/AttributeUtils.java b/org.lflang/src/org/lflang/AttributeUtils.java index f5077f2d13..b6fddf0b0e 100644 --- a/org.lflang/src/org/lflang/AttributeUtils.java +++ b/org.lflang/src/org/lflang/AttributeUtils.java @@ -134,12 +134,12 @@ public static String getAttributeValue(EObject node, String attrName) { /** * Retrieve a specific annotation in a comment associated with the given model element in the AST. * - * This will look for a comment. If one is found, it searches for the given annotation `key`. + * This will look for a comment. If one is found, it searches for the given annotation {@code key}. * and extracts any string that follows the annotation marker. * * @param object the AST model element to search a comment for * @param key the specific annotation key to be extracted - * @return `null` if no JavaDoc style comment was found or if it does not contain the given key. + * @return {@code null} if no JavaDoc style comment was found or if it does not contain the given key. * The string immediately following the annotation marker otherwise. */ public static String findAnnotationInComments(EObject object, String key) { diff --git a/org.lflang/src/org/lflang/FileConfig.java b/org.lflang/src/org/lflang/FileConfig.java index 91d681046a..3628d1bde0 100644 --- a/org.lflang/src/org/lflang/FileConfig.java +++ b/org.lflang/src/org/lflang/FileConfig.java @@ -57,8 +57,8 @@ public abstract class FileConfig { * The directory that is the root of the package in which the .lf source file resides. This path is determined * differently depending on whether the compiler is invoked through the IDE or from the command line. In the former * case, the package is the project root that the source resides in. In the latter case, it is the parent directory - * of the nearest `src` directory up the hierarchy, if there is one, or just the `outPath` if there is none. It is - * recommended to always keep the sources in a `src` directory regardless of the workflow, in which case the + * of the nearest {@code src} directory up the hierarchy, if there is one, or just the {@code outPath} if there is none. It is + * recommended to always keep the sources in a {@code src} directory regardless of the workflow, in which case the * output behavior will be identical irrespective of the way the compiler is invoked. */ public final Path srcPkgPath; @@ -117,7 +117,7 @@ public abstract class FileConfig { /** * The parent of the directory designated for placing generated sources into (`./src-gen` by default). Additional - * directories (such as `bin` or `build`) should be created as siblings of the directory for generated sources, + * directories (such as {@code bin} or {@code build}) should be created as siblings of the directory for generated sources, * which means that such directories should be created relative to the path assigned to this class variable. *

    * The generated source directory is specified in the IDE (Project Properties->LF->Compiler->Output Folder). When @@ -164,7 +164,7 @@ public Path getDirectory(Resource r) throws IOException { /** * The parent of the directory designated for placing generated sources into (`./src-gen` by default). Additional - * directories (such as `bin` or `build`) should be created as siblings of the directory for generated sources, + * directories (such as {@code bin} or {@code build}) should be created as siblings of the directory for generated sources, * which means that such directories should be created relative to the path assigned to this class variable. *

    * The generated source directory is specified in the IDE (Project Properties->LF->Compiler->Output Folder). When diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index a974e17f03..e2f193cecd 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -886,7 +886,7 @@ private interface PropertyGetter { /** * Private constructor for target properties. This will take an additional - * `updater`, which will be used to merge target properties from imported resources. + * {@code updater}, which will be used to merge target properties from imported resources. * * @param description String representation of this property. * @param type The type that values assigned to this property diff --git a/org.lflang/src/org/lflang/ast/ASTUtils.java b/org.lflang/src/org/lflang/ast/ASTUtils.java index f6dba5bf4d..bf4efed8f7 100644 --- a/org.lflang/src/org/lflang/ast/ASTUtils.java +++ b/org.lflang/src/org/lflang/ast/ASTUtils.java @@ -895,7 +895,7 @@ public static String baseType(Type type) { /** * Report whether the given literal is zero or not. * @param literal AST node to inspect. - * @return True if the given literal denotes the constant `0`, false + * @return True if the given literal denotes the constant {@code 0}, false * otherwise. */ public static boolean isZero(String literal) { @@ -914,7 +914,7 @@ public static boolean isZero(String literal) { * Report whether the given expression is zero or not. * * @param expr AST node to inspect. - * @return True if the given value denotes the constant `0`, false otherwise. + * @return True if the given value denotes the constant {@code 0}, false otherwise. */ public static boolean isZero(Expression expr) { if (expr instanceof Literal) { diff --git a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java index 9a39b803a9..953b9bdfdb 100644 --- a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java +++ b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java @@ -42,7 +42,7 @@ /** This class implements AST transformations for delayed connections. There are two types of delayed connections: - 1) Connections with `after`-delays + 1) Connections with {@code after}-delays 2) Physical connections */ public class DelayedConnectionTransformation implements AstTransformation { @@ -396,7 +396,7 @@ private void addDelayClass(Reactor generatedDelay) { /** * Return the generated delay reactor that corresponds to the given class - * name if it had been created already, `null` otherwise. + * name if it had been created already, {@code null} otherwise. */ private Reactor findDelayClass(String className) { return IterableExtensions.findFirst(delayClasses, it -> it.getName().equals(className)); diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java index 7aa13d6cfc..d50a801617 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java @@ -104,7 +104,7 @@ String generateNetworkOutputControlReactionBody( default void annotateReaction(Reaction reaction) {} /** - * Return the type for the raw network buffer in the target language (e.g., `uint_8` in C). This would be the type of the + * Return the type for the raw network buffer in the target language (e.g., {@code uint_8} in C). This would be the type of the * network messages after serialization and before deserialization. It is primarily used to determine the type for the * network action at the receiver. */ diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 2243729e09..087f4272e2 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -279,7 +279,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { targetConfig, errorReporter ); - // FIXME: Should the GeneratorBase pull in `files` from imported + // FIXME: Should the GeneratorBase pull in {@code files} from imported // resources? for (AstTransformation transformation : astTransformations) { @@ -332,8 +332,8 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur earlier in // the sorted list of reactors. This helps the code generator output code in the correct order. - // For example if `reactor Foo {bar = new Bar()}` then the definition of `Bar` has to be generated before - // the definition of `Foo`. + // For example if `reactor Foo {bar = new Bar()}` then the definition of {@code Bar} has to be generated before + // the definition of {@code Foo}. reactors = instantiationGraph.nodesInTopologicalOrder(); // If there is no main reactor or if all reactors in the file need to be validated, then make sure the reactors @@ -353,7 +353,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { * * This should be overridden by the target generators. * - * @param targetConfig The targetConfig to read the `files` from. + * @param targetConfig The targetConfig to read the {@code files} from. * @param fileConfig The fileConfig used to make the copy and resolve paths. */ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { diff --git a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java b/org.lflang/src/org/lflang/generator/LFGeneratorContext.java index 5a5eddf178..84032ecdc6 100644 --- a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java +++ b/org.lflang/src/org/lflang/generator/LFGeneratorContext.java @@ -58,7 +58,7 @@ public String getKey() { } /** - * Return the value corresponding to this parameter or `null` if there is none. + * Return the value corresponding to this parameter or {@code null} if there is none. * @param context The context passed to the code generator. */ public String getValue(LFGeneratorContext context) { diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index a1598bff0c..4c5f3ec292 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -317,7 +317,7 @@ private void assignLevels() { /** * This function assigns inferred deadlines to all the reactions in the graph. - * It is modeled after `assignLevels` but it starts at the leaf nodes and uses + * It is modeled after {@code assignLevels} but it starts at the leaf nodes and uses * Kahns algorithm to build a reverse topologically sorted graph * */ diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index ae5324fa3d..b2f5de66c2 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -319,7 +319,7 @@ public String getName() { /** * @see NamedInstance#uniqueID() * - * Append `_main` to the name of the main reactor to allow instantiations + * Append {@code _main} to the name of the main reactor to allow instantiations * within that reactor to have the same name. */ @Override @@ -1047,11 +1047,11 @@ private boolean findPaths( * and may be ports of a contained bank (a port representing ports of the bank * members) so the returned list includes ranges of banks and channels. * - * If a given port reference has the form `interleaved(b.m)`, where `b` is - * a bank and `m` is a multiport, then the corresponding range in the returned + * If a given port reference has the form `interleaved(b.m)`, where {@code b} is + * a bank and {@code m} is a multiport, then the corresponding range in the returned * list is marked interleaved. * - * For example, if `b` and `m` have width 2, without the interleaved keyword, + * For example, if {@code b} and {@code m} have width 2, without the interleaved keyword, * the returned range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. * With the interleaved marking, the returned range represents the sequence * `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have width 4. diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 80df63fd0e..586cd05dfb 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -414,7 +414,7 @@ public LFCommand compileCCommand( } // If there is no main reactor, then use the -c flag to prevent linking from occurring. - // FIXME: we could add a `-c` flag to `lfc` to make this explicit in stand-alone mode. + // FIXME: we could add a `-c` flag to {@code lfc} to make this explicit in stand-alone mode. // Then again, I think this only makes sense when we can do linking. if (noBinary) { compileArgs.add("-c"); // FIXME: revisit diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 9997b62302..b25a8af87d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -814,8 +814,8 @@ private void inspectReactorEResource(ReactorDecl reactor) { } /** - * Copy all files or directories listed in the target property `files`, `cmake-include`, - * and `_fed_setup` into the src-gen folder of the main .lf file + * Copy all files or directories listed in the target property {@code files}, `cmake-include`, + * and {@code _fed_setup} into the src-gen folder of the main .lf file * * @param targetConfig The targetConfig to read the target properties from. * @param fileConfig The fileConfig used to make the copy and resolve paths. diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java index 6261686b8b..db40a88932 100644 --- a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java @@ -34,7 +34,7 @@ public String generateCode() { } /** - * Generate the `main` function. + * Generate the {@code main} function. */ private String generateMainFunction() { if (targetConfig.platformOptions.platform == Platform.ARDUINO) { @@ -59,7 +59,7 @@ private String generateMainFunction() { ); } else if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { // The Zephyr "runtime" does not terminate when main returns. - // Rather, `exit` should be called explicitly. + // Rather, {@code exit} should be called explicitly. return String.join("\n", "void main(void) {", " int res = lf_reactor_c_main(0, NULL);", @@ -77,7 +77,7 @@ private String generateMainFunction() { /** * Generate code that is used to override the - * command line options to the `main` function + * command line options to the {@code main} function */ private String generateSetDefaultCliOption() { // Generate function to set default command-line options. diff --git a/org.lflang/src/org/lflang/generator/c/CModesGenerator.java b/org.lflang/src/org/lflang/generator/c/CModesGenerator.java index 6ff682d49f..2a6217de64 100644 --- a/org.lflang/src/org/lflang/generator/c/CModesGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CModesGenerator.java @@ -173,7 +173,7 @@ public static String generateStateResetStructure( } /** - * Generate code to call `_lf_process_mode_changes`. + * Generate code to call {@code _lf_process_mode_changes}. * * @param hasModalReactors True if there is modal model reactors, false otherwise * @param modalStateResetCount The number of modal model state resets @@ -200,7 +200,7 @@ public static String generateLfHandleModeChanges( } /** - * Generate code to call `_lf_initialize_modes`. + * Generate code to call {@code _lf_initialize_modes}. * * @param hasModalReactors True if there is modal model reactors, false otherwise */ diff --git a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java index 75623fdfe7..57e7556dfe 100644 --- a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java @@ -50,7 +50,7 @@ public static String generateDeclarations(int timerCount) { } /** - * Generate code to call `_lf_initialize_timer` on each timer. + * Generate code to call {@code _lf_initialize_timer} on each timer. * * @param timerCount The total number of timers in the program */ diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index d72f6d4dcd..3a37ef238b 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -621,12 +621,12 @@ private static String setUpMainTarget(boolean hasMain, String executableName, St } /** - * Generate a (`key`, `val`) tuple pair for the `define_macros` field + * Generate a ({@code key}, {@code val}) tuple pair for the {@code define_macros} field * of the Extension class constructor from setuptools. * * @param key The key of the macro entry * @param val The value of the macro entry - * @return A (`key`, `val`) tuple pair as String + * @return A ({@code key}, {@code val}) tuple pair as String */ private static String generateMacroEntry(String key, String val) { return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; @@ -635,7 +635,7 @@ private static String generateMacroEntry(String key, String val) { /** * Generate the name of the python module. * - * Ideally, this function would belong in a class like `PyFileConfig` + * Ideally, this function would belong in a class like {@code PyFileConfig} * that specifies all the paths to the generated code. * * @param lfModuleName The name of the LF module. @@ -646,9 +646,9 @@ private static String generatePythonModuleName(String lfModuleName) { } /** - * Generate the python file name given an `lfModuleName`. + * Generate the python file name given an {@code lfModuleName}. * - * Ideally, this function would belong in a class like `PyFileConfig` + * Ideally, this function would belong in a class like {@code PyFileConfig} * that specifies all the paths to the generated code. * * @param lfModuleName The name of the LF module diff --git a/org.lflang/src/org/lflang/graph/PrecedenceGraph.java b/org.lflang/src/org/lflang/graph/PrecedenceGraph.java index 6763fd1cb3..03fd266f6a 100644 --- a/org.lflang/src/org/lflang/graph/PrecedenceGraph.java +++ b/org.lflang/src/org/lflang/graph/PrecedenceGraph.java @@ -34,7 +34,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.ArrayList; /** - * Elaboration of `DirectedGraph` that is capable of identifying strongly + * Elaboration of {@code DirectedGraph} that is capable of identifying strongly * connected components and topologically sorting its nodes. * * @author Marten Lohstroh @@ -147,7 +147,7 @@ private void visit(T node) { /** * Run Tarjan's algorithm for finding strongly connected components. * After invoking this method, the detected cycles with be listed - * in the class variable `cycles`. + * in the class variable {@code cycles}. */ public void detectCycles() { if (!this.cycleAnalysisDone) { diff --git a/org.lflang/src/org/lflang/util/LFCommand.java b/org.lflang/src/org/lflang/util/LFCommand.java index 32e157e775..1d7fdf4aaf 100644 --- a/org.lflang/src/org/lflang/util/LFCommand.java +++ b/org.lflang/src/org/lflang/util/LFCommand.java @@ -276,7 +276,7 @@ public static LFCommand get(final String cmd, final List args, boolean q * This will check first if the command can actually be found and executed. If the command is not found, null is * returned. In order to find the command, different methods are applied in the following order: *

    - * 1. Check if the given command `cmd` is an executable file within `dir`. + * 1. Check if the given command {@code cmd} is an executable file within {@code dir}. * 2. If the above fails 'which ' (or 'where ' on Windows) is executed to see if the command is available * on the PATH. * 3. If both points above fail, a third attempt is started using bash to indirectly execute the command (see below diff --git a/org.lflang/src/org/lflang/util/StringUtil.java b/org.lflang/src/org/lflang/util/StringUtil.java index 9be21d46e8..31beef8a9b 100644 --- a/org.lflang/src/org/lflang/util/StringUtil.java +++ b/org.lflang/src/org/lflang/util/StringUtil.java @@ -48,7 +48,7 @@ private StringUtil() { /** * Convert a string in Camel case to snake case. E.g. - * `MinimalReactor` will be converted to `minimal_reactor`. + * {@code MinimalReactor} will be converted to {@code minimal_reactor}. * The string is assumed to be a single camel case identifier * (no whitespace). */ diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index d64eb5dc35..1586eb63d0 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -152,7 +152,7 @@ public void checkAction(Action action) { checkName(action.getName(), Literals.VARIABLE__NAME); if (action.getOrigin() == ActionOrigin.NONE) { error( - "Action must have modifier `logical` or `physical`.", + "Action must have modifier {@code logical} or {@code physical}.", Literals.ACTION__ORIGIN ); } From 617ca21b9ce3ba39967749b90150bc8a0def0977 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:05:00 -0700 Subject: [PATCH 404/709] More backticks -> {@code } --- org.lflang.tests/src/org/lflang/tests/TestBase.java | 2 +- org.lflang/src/org/lflang/FileConfig.java | 8 ++++---- org.lflang/src/org/lflang/TargetProperty.java | 4 ++-- .../org/lflang/federated/extensions/CExtension.java | 2 +- .../federated/launcher/FedLauncherGenerator.java | 2 +- .../src/org/lflang/generator/GeneratorBase.java | 12 ++++++------ .../src/org/lflang/generator/ReactorInstance.java | 6 +++--- org.lflang/src/org/lflang/generator/c/CCompiler.java | 4 ++-- .../src/org/lflang/generator/c/CGenerator.java | 2 +- .../lflang/generator/c/CMainFunctionGenerator.java | 2 +- .../org/lflang/generator/c/CReactionGenerator.java | 2 +- .../lflang/generator/c/CTriggerObjectsGenerator.java | 2 +- org.lflang/src/org/lflang/generator/c/CUtil.java | 12 ++++++------ .../org/lflang/generator/python/PythonGenerator.java | 2 +- .../generator/python/PythonReactionGenerator.java | 4 ++-- .../src/org/lflang/graph/InstantiationGraph.java | 4 ++-- org.lflang/src/org/lflang/util/LFCommand.java | 2 +- .../src/org/lflang/validation/LFValidator.java | 2 +- 18 files changed, 37 insertions(+), 37 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 101df920f0..192a531828 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -381,7 +381,7 @@ private static void checkAndReportFailures(Set tests) { /** * Configure a test by applying the given configurator and return a * generator context. Also, if the given level is less than - * `TestLevel.BUILD`, add a `no-compile` flag to the generator context. If + * {@code TestLevel.BUILD}, add a {@code no-compile} flag to the generator context. If * the configurator was not applied successfully, throw an AssertionError. * * @param test the test to configure. diff --git a/org.lflang/src/org/lflang/FileConfig.java b/org.lflang/src/org/lflang/FileConfig.java index 3628d1bde0..e2d3313a61 100644 --- a/org.lflang/src/org/lflang/FileConfig.java +++ b/org.lflang/src/org/lflang/FileConfig.java @@ -116,12 +116,12 @@ public abstract class FileConfig { // private fields /** - * The parent of the directory designated for placing generated sources into (`./src-gen` by default). Additional + * The parent of the directory designated for placing generated sources into ({@code ./src-gen} by default). Additional * directories (such as {@code bin} or {@code build}) should be created as siblings of the directory for generated sources, * which means that such directories should be created relative to the path assigned to this class variable. *

    * The generated source directory is specified in the IDE (Project Properties->LF->Compiler->Output Folder). When - * invoking the standalone compiler, the output path is specified directly using the `-o` or `--output-path` option. + * invoking the standalone compiler, the output path is specified directly using the {@code -o} or {@code --output-path} option. */ private final Path outPath; @@ -163,12 +163,12 @@ public Path getDirectory(Resource r) throws IOException { } /** - * The parent of the directory designated for placing generated sources into (`./src-gen` by default). Additional + * The parent of the directory designated for placing generated sources into ({@code ./src-gen} by default). Additional * directories (such as {@code bin} or {@code build}) should be created as siblings of the directory for generated sources, * which means that such directories should be created relative to the path assigned to this class variable. *

    * The generated source directory is specified in the IDE (Project Properties->LF->Compiler->Output Folder). When - * invoking the standalone compiler, the output path is specified directly using the `-o` or `--output-path` option. + * invoking the standalone compiler, the output path is specified directly using the {@code -o} or {@code --output-path} option. */ public Path getOutPath() { return outPath; diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index e2f193cecd..fe5c7dd0b2 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -666,8 +666,8 @@ public enum TargetProperty { * List of module files to link into the crate as top-level. * For instance, a {@code target Rust { rust-modules: [ "foo.rs" ] }} * will cause the file to be copied into the generated project, - * and the generated `main.rs` will include it with a `mod foo;`. - * If one of the paths is a directory, it must contain a `mod.rs` + * and the generated {@code main.rs} will include it with a {@code mod foo;}. + * If one of the paths is a directory, it must contain a {@code mod.rs} * file, and all its contents are copied. */ RUST_INCLUDE("rust-include", diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index 32f06c71bc..18b5d9615a 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -482,7 +482,7 @@ public String generatePreamble( RtiConfig rtiConfig, ErrorReporter errorReporter ) throws IOException { - // Put the C preamble in a `include/_federate.name + _preamble.h` file + // Put the C preamble in a {@code include/_federate.name + _preamble.h} file String cPreamble = makePreamble(federate, fileConfig, rtiConfig, errorReporter); String relPath = getPreamblePath(federate); Path fedPreamblePath = fileConfig.getSrcPath().resolve(relPath); diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 3ad08e2450..4f544c5653 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -291,7 +291,7 @@ private String getSetupCode() { "", "# Create a random 48-byte text ID for this federation.", "# The likelihood of two federations having the same ID is 1/16,777,216 (1/2^24).", - "FEDERATION_ID=`openssl rand -hex 24`", + "FEDERATION_ID={@code openssl rand -hex 24}", "echo \"Federate " + fileConfig.name + " in Federation ID '$FEDERATION_ID'\"", "# Launch the federates:" ); diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 087f4272e2..8d57e4c522 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -116,7 +116,7 @@ public abstract class GeneratorBase extends AbstractLFValidator { * A list of Reactor definitions in the main resource, including non-main * reactors defined in imported resources. These are ordered in the list in * such a way that each reactor is preceded by any reactor that it instantiates - * using a command like `foo = new Foo();` + * using a command like {@code foo = new Foo();} */ protected List reactors = new ArrayList<>(); @@ -129,9 +129,9 @@ public abstract class GeneratorBase extends AbstractLFValidator { * Graph that tracks dependencies between instantiations. * This is a graph where each node is a Reactor (not a ReactorInstance) * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement - * like `a = new A();` After creating the graph, + * like {@code a = new A();} After creating the graph, * sort the reactors in topological order and assign them to the reactors class variable. - * Hence, after this method returns, `this.reactors` will be a list of Reactors such that any + * Hence, after this method returns, {@code this.reactors} will be a list of Reactors such that any * reactor is preceded in the list by reactors that it instantiates. */ protected InstantiationGraph instantiationGraph; @@ -321,9 +321,9 @@ protected void cleanIfNeeded(LFGeneratorContext context) { /** * Create a new instantiation graph. This is a graph where each node is a Reactor (not a ReactorInstance) * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement - * like `a = new A();` After creating the graph, + * like {@code a = new A();} After creating the graph, * sort the reactors in topological order and assign them to the reactors class variable. - * Hence, after this method returns, `this.reactors` will be a list of Reactors such that any + * Hence, after this method returns, {@code this.reactors} will be a list of Reactors such that any * reactor is preceded in the list by reactors that it instantiates. */ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { @@ -332,7 +332,7 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur earlier in // the sorted list of reactors. This helps the code generator output code in the correct order. - // For example if `reactor Foo {bar = new Bar()}` then the definition of {@code Bar} has to be generated before + // For example if {@code reactor Foo {bar = new Bar()}} then the definition of {@code Bar} has to be generated before // the definition of {@code Foo}. reactors = instantiationGraph.nodesInTopologicalOrder(); diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index b2f5de66c2..332c48b73f 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -1047,14 +1047,14 @@ private boolean findPaths( * and may be ports of a contained bank (a port representing ports of the bank * members) so the returned list includes ranges of banks and channels. * - * If a given port reference has the form `interleaved(b.m)`, where {@code b} is + * If a given port reference has the form {@code interleaved(b.m)}, where {@code b} is * a bank and {@code m} is a multiport, then the corresponding range in the returned * list is marked interleaved. * * For example, if {@code b} and {@code m} have width 2, without the interleaved keyword, - * the returned range represents the sequence `[b0.m0, b0.m1, b1.m0, b1.m1]`. + * the returned range represents the sequence {@code [b0.m0, b0.m1, b1.m0, b1.m1]}. * With the interleaved marking, the returned range represents the sequence - * `[b0.m0, b1.m0, b0.m1, b1.m1]`. Both ranges will have width 4. + * {@code [b0.m0, b1.m0, b0.m1, b1.m1]}. Both ranges will have width 4. * * @param references The variable references on one side of the connection. * @param connection The connection. diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 586cd05dfb..9fcb72b4a6 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -304,7 +304,7 @@ public LFCommand buildCmakeCommand() { * Return a flash/emulate command using west. * If board is null (defaults to qemu_cortex_m3) or qemu_* * Return a flash command which runs the target as an emulation - * If ordinary target, return `west flash` + * If ordinary target, return {@code west flash} */ public LFCommand buildWestFlashCommand() { // Set the build directory to be "build" @@ -414,7 +414,7 @@ public LFCommand compileCCommand( } // If there is no main reactor, then use the -c flag to prevent linking from occurring. - // FIXME: we could add a `-c` flag to {@code lfc} to make this explicit in stand-alone mode. + // FIXME: we could add a {@code -c} flag to {@code lfc} to make this explicit in stand-alone mode. // Then again, I think this only makes sense when we can do linking. if (noBinary) { compileArgs.add("-c"); // FIXME: revisit diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b25a8af87d..fce667067c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -814,7 +814,7 @@ private void inspectReactorEResource(ReactorDecl reactor) { } /** - * Copy all files or directories listed in the target property {@code files}, `cmake-include`, + * Copy all files or directories listed in the target property {@code files}, {@code cmake-include}, * and {@code _fed_setup} into the src-gen folder of the main .lf file * * @param targetConfig The targetConfig to read the target properties from. diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java index db40a88932..533611368a 100644 --- a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java @@ -22,7 +22,7 @@ public CMainFunctionGenerator(TargetConfig targetConfig) { * Generate the code that is the entry point * of the program. * - * Ideally, this code would belong to its own `main.c` + * Ideally, this code would belong to its own {@code main.c} * file, but it currently lives in the same file * as all the code generated for reactors. */ diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 4b2d6678b0..26e6c8ab6f 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1179,7 +1179,7 @@ public static String generateStpFunctionHeader(TypeParameterizedReactor tpr, /** * Return the start of a function declaration for a function that takes - * a `void*` argument and returns void. + * a {@code void*} argument and returns void. * * @param functionName * @return diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index 2871dbab96..99df04e9d3 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -966,7 +966,7 @@ private static String deferredReactionMemory( * to a contained reactor, then generate code to allocate * memory to store the data produced by those reactions. * The allocated memory is pointed to by a field called - * `_lf_containername.portname` on the self struct of the reactor. + * {@code _lf_containername.portname} on the self struct of the reactor. * @param reactor The reactor. */ private static String deferredAllocationForEffectsOnInputs( diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 51348915b9..b2a34790b2 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -208,7 +208,7 @@ public static String portRef( * port's parent. This is used when an input port triggers a reaction * in the port's parent or when an output port is written to by * a reaction in the port's parent. - * This is equivalent to calling `portRef(port, false, true, null, null)`. + * This is equivalent to calling {@code portRef(port, false, true, null, null)}. * @param port An instance of the port to be referenced. */ public static String portRef(PortInstance port) { @@ -221,7 +221,7 @@ public static String portRef(PortInstance port) { * This is used when an input port triggers a reaction * in the port's parent or when an output port is written to by * a reaction in the port's parent. - * This is equivalent to calling `portRef(port, false, true, bankIndex, channelIndex)`. + * This is equivalent to calling {@code portRef(port, false, true, bankIndex, channelIndex)}. * @param port An instance of the port to be referenced. * @param runtimeIndex A variable name to use to index the runtime instance or * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. @@ -269,7 +269,7 @@ public static String portRefName( * is written to by a reaction in the parent of the port's parent, * or when an output port triggers a reaction in the parent of the * port's parent. This is equivalent to calling - * `portRef(port, true, true, null, null, null)`. + * {@code portRef(port, true, true, null, null, null)}. * * @param port The port. */ @@ -283,7 +283,7 @@ public static String portRefNested(PortInstance port) { * is written to by a reaction in the parent of the port's parent, * or when an output port triggers a reaction in the parent of the * port's parent. This is equivalent to calling - * `portRef(port, true, true, runtimeIndex, bankIndex, channelIndex)`. + * {@code portRef(port, true, true, runtimeIndex, bankIndex, channelIndex)}. * * @param port The port. * @param runtimeIndex A variable name to use to index the runtime instance or @@ -306,7 +306,7 @@ public static String portRefNested( * is written to by a reaction in the parent of the port's parent, * or when an output port triggers a reaction in the parent of the * port's parent. - * This is equivalent to calling `portRef(port, true, false, null, null, null)`. + * This is equivalent to calling {@code portRef(port, true, false, null, null, null)}. * * @param port The port. */ @@ -321,7 +321,7 @@ public static String portRefNestedName(PortInstance port) { * is written to by a reaction in the parent of the port's parent, * or when an output port triggers a reaction in the parent of the * port's parent. This is equivalent to calling - * `portRefNested(port, true, false, runtimeIndex, bankIndex, channelIndex)`. + * {@code portRefNested(port, true, false, runtimeIndex, bankIndex, channelIndex)}. * * @param port The port. * @param runtimeIndex A variable name to use to index the runtime instance or diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 3a37ef238b..83053d6897 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -457,7 +457,7 @@ protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { Reactor reactor = ASTUtils.toDefinition(tpr.reactor()); - // Reactions marked with a `@_c_body` attribute are generated in C + // Reactions marked with a {@code @_c_body} attribute are generated in C if (AttributeUtils.hasCBody(reaction)) { super.generateReaction(src, reaction, tpr, reactionIndex); return; diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 99f1b5c180..3d307b6b52 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -380,7 +380,7 @@ public static String generateCPythonReactionLinkers( code.pr(nameOfSelfStruct+"->_lf_name = \""+instance.uniqueID()+"_lf\";"); for (ReactionInstance reaction : instance.reactions) { - // Reactions marked with a `@_c_body` attribute are generated in C + // Reactions marked with a {@code @_c_body} attribute are generated in C if (AttributeUtils.hasCBody(reaction.getDefinition())) continue; // Create a PyObject for each reaction code.pr(generateCPythonReactionLinker(instance, reaction, nameOfSelfStruct)); @@ -479,7 +479,7 @@ public static String generatePythonReactions(Reactor reactor, List rea * @param reaction The reaction of reactor */ public static String generatePythonReaction(Reactor reactor, Reaction reaction, int reactionIndex) { - // Reactions marked with a `@_c_body` attribute are generated in C + // Reactions marked with a {@code @_c_body} attribute are generated in C if (AttributeUtils.hasCBody(reaction)) return ""; CodeBuilder code = new CodeBuilder(); diff --git a/org.lflang/src/org/lflang/graph/InstantiationGraph.java b/org.lflang/src/org/lflang/graph/InstantiationGraph.java index 53b59cbbb5..b32c97e2f2 100644 --- a/org.lflang/src/org/lflang/graph/InstantiationGraph.java +++ b/org.lflang/src/org/lflang/graph/InstantiationGraph.java @@ -49,12 +49,12 @@ * confusing and subtle distinction here between an "instantiation" * and an "instance". They are not the same thing at all. An * "instantiation" is an AST node representing a statement like - * `a = new A();`. This can result in many instances of reactor + * {@code a = new A();}. This can result in many instances of reactor * class A (if the containing reactor class is instantiated multiple times). * * In addition to the graph, this class keeps track of the instantiations * that induce the dependencies. These can be retrieved using the method - * `getInstantiations(Reactor)`. + * {@code getInstantiations(Reactor)}. * * @author Marten Lohstroh */ diff --git a/org.lflang/src/org/lflang/util/LFCommand.java b/org.lflang/src/org/lflang/util/LFCommand.java index 1d7fdf4aaf..4f6927dcf0 100644 --- a/org.lflang/src/org/lflang/util/LFCommand.java +++ b/org.lflang/src/org/lflang/util/LFCommand.java @@ -156,7 +156,7 @@ private void poll(Process process, CancelIndicator cancelIndicator) { /** * Execute the command. *

    - * Executing a process directly with `processBuilder.start()` could + * Executing a process directly with {@code processBuilder.start()} could * lead to a deadlock as the subprocess blocks when output or error * buffers are full. This method ensures that output and error messages * are continuously read and forwards them to the system output and diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 1586eb63d0..36c09cf678 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1259,7 +1259,7 @@ public void checkWidthSpec(WidthSpec widthSpec) { error("Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); } } else if (term.getPort() != null) { - // Widths given with `widthof()` are not supported (yet?). + // Widths given with {@code widthof()} are not supported (yet?). // This feature is currently only used for after delays. error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); } else if (term.getCode() != null) { From d58b27c23faa1b4fcb82f890c22883c1d8464e24 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:12:40 -0700 Subject: [PATCH 405/709] More backticks/triple backticks -> JavaDoc. --- org.lflang/src/org/lflang/ast/ASTUtils.java | 107 ++++++++---------- .../org/lflang/generator/ReactorInstance.java | 2 +- .../lflang/generator/c/CActionGenerator.java | 4 +- .../lflang/generator/c/CPortGenerator.java | 4 +- .../src/org/lflang/generator/c/CUtil.java | 2 +- 5 files changed, 52 insertions(+), 67 deletions(-) diff --git a/org.lflang/src/org/lflang/ast/ASTUtils.java b/org.lflang/src/org/lflang/ast/ASTUtils.java index bf4efed8f7..26d4e0d6b0 100644 --- a/org.lflang/src/org/lflang/ast/ASTUtils.java +++ b/org.lflang/src/org/lflang/ast/ASTUtils.java @@ -1229,69 +1229,54 @@ public static boolean isOfTimeType(Parameter param) { } /** - * Given a parameter, return its initial value. - * The initial value is a list of instances of Expressions. + * Given a parameter, return its initial value. + * The initial value is a list of instances of Expressions. * - * If the instantiations argument is null or an empty list, then the - * value returned is simply the default value given when the parameter - * is defined. - * - * If a list of instantiations is given, then the first instantiation - * is required to be an instantiation of the reactor class that is - * parameterized by the parameter. I.e., - * ``` - * parameter.eContainer == instantiations.get(0).reactorClass - * ``` - * If a second instantiation is given, then it is required to be an instantiation of a - * reactor class that contains the first instantiation. That is, - * ``` - * instantiations.get(0).eContainer == instantiations.get(1).reactorClass - * ``` - * More generally, for all 0 <= i < instantiations.size - 1, - * ``` - * instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass - * ``` - * If any of these conditions is not satisfied, then an IllegalArgumentException - * will be thrown. - * - * Note that this chain of reactions cannot be inferred from the parameter because - * in each of the predicates above, there may be more than one instantiation that - * can appear on the right hand side of the predicate. - * - * For example, consider the following program: - * ``` - * 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); - * } - * ``` - * Notice that there are a total of four instances of reactor class A. - * Then - * ``` - * initialValue(x, null) returns 1 - * initialValue(x, [a1]) returns 2 - * initialValue(x, [a2]) returns -1 - * initialValue(x, [a1, b1]) returns 3 - * initialValue(x, [a2, b1]) returns -1 - * initialValue(x, [a1, b2]) returns -2 - * initialValue(x, [a2, b2]) returns -1 - * ``` - * (Actually, in each of the above cases, the returned value is a list with - * one entry, a Literal, e.g. ["1"]). - * - * There are two instances of reactor class B. - * ``` - * initialValue(y, null) returns 2 - * initialValue(y, [a1]) throws an IllegalArgumentException - * initialValue(y, [b1]) returns 3 - * initialValue(y, [b2]) returns -2 - * ``` + * If the instantiations argument is null or an empty list, then the + * value returned is simply the default value given when the parameter + * is defined. * + * If a list of instantiations is given, then the first instantiation + * is required to be an instantiation of the reactor class that is + * parameterized by the parameter. I.e., + *

         parameter.eContainer == instantiations.get(0).reactorClass
    +     * 

    If a second instantiation is given, then it is required to be an instantiation of a + * reactor class that contains the first instantiation. That is,

    + *
         instantiations.get(0).eContainer == instantiations.get(1).reactorClass
    +     * 

    More generally, for all 0 <= i < instantiations.size - 1,

    + *
         instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass
    +     * 

    If any of these conditions is not satisfied, then an IllegalArgumentException + * will be thrown.

    + *

    Note that this chain of reactions cannot be inferred from the parameter because + * in each of the predicates above, there may be more than one instantiation that + * can appear on the right hand side of the predicate.

    + *

    For example, consider the following program:

    + *
         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);
    +     *      }
    +     * 

    Notice that there are a total of four instances of reactor class A. + * Then

    + *
         initialValue(x, null) returns 1
    +     *      initialValue(x, [a1]) returns 2
    +     *      initialValue(x, [a2]) returns -1
    +     *      initialValue(x, [a1, b1]) returns 3
    +     *      initialValue(x, [a2, b1]) returns -1
    +     *      initialValue(x, [a1, b2]) returns -2
    +     *      initialValue(x, [a2, b2]) returns -1
    +     * 

    (Actually, in each of the above cases, the returned value is a list with + * one entry, a Literal, e.g. ["1"]).

    + *

    There are two instances of reactor class B.

    + *
         initialValue(y, null) returns 2
    +     *      initialValue(y, [a1]) throws an IllegalArgumentException
    +     *      initialValue(y, [b1]) returns 3
    +     *      initialValue(y, [b2]) returns -2
    +     * 
    * @param parameter The parameter. * @param instantiations The (optional) list of instantiations. * diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 332c48b73f..e40c3f988a 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -194,7 +194,7 @@ public ReactionInstanceGraph assignLevels() { /** * This function assigns/propagates deadlines through the Reaction Instance Graph. - * It performs Kahn`s algorithm in reverse, starting from the leaf nodes and + * It performs Kahn's algorithm in reverse, starting from the leaf nodes and * propagates deadlines upstream. To reduce cost, it should only be invoked when * there are user-specified deadlines in the program. * @return diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 6e4688af8c..5f81de89aa 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -149,9 +149,9 @@ public static String generateAuxiliaryStruct( * For the specified action, return a declaration for action struct to * contain the value of the action. An action of * type int[10], for example, will result in this: - * ``` + *
    
          *     int* value;
    -     * ```
    +     * 
    * This will return an empty string for an action with no type. * @param tpr {@link TypeParameterizedReactor} * @param action The action. diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index 619a2bd134..f82bad661c 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -172,9 +172,9 @@ public static String initializeOutputMultiport( * For the specified port, return a declaration for port struct to * contain the value of the port. A multiport output with width 4 and * type int[10], for example, will result in this: - * ``` + *
    
          *     int value[10];
    -     * ```
    +     * 
    * There will be an array of size 4 of structs, each containing this value * array. * @param port The port. diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index b2a34790b2..c598822bf8 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -136,7 +136,7 @@ public static String channelIndexName(PortInstance port) { } /** - * Return the name of the reactor. A '_main` is appended to the name if the + * Return the name of the reactor. A {@code _main} is appended to the name if the * reactor is main (to allow for instantiations that have the same name as * the main reactor or the .lf file). */ From 8e9ef2850e9beed4571ffd017f9793327f2b05b1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:37:42 -0700 Subject: [PATCH 406/709] Undo changes to bash generator. --- .../src/org/lflang/federated/launcher/FedLauncherGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 4f544c5653..3ad08e2450 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -291,7 +291,7 @@ private String getSetupCode() { "", "# Create a random 48-byte text ID for this federation.", "# The likelihood of two federations having the same ID is 1/16,777,216 (1/2^24).", - "FEDERATION_ID={@code openssl rand -hex 24}", + "FEDERATION_ID=`openssl rand -hex 24`", "echo \"Federate " + fileConfig.name + " in Federation ID '$FEDERATION_ID'\"", "# Launch the federates:" ); From 3c87482ee62372a48343ed6962f2008a775fe0e2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:38:07 -0700 Subject: [PATCH 407/709] More MarkDown -> HTML. --- .../src/org/lflang/generator/python/PythonPortGenerator.java | 2 +- org.lflang/src/org/lflang/util/CollectionUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java index 0c0c9b6cad..5109c322c3 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java @@ -65,7 +65,7 @@ public static void generateOutputVariablesToSendToPythonReaction( Output output ) { // Unfortunately, for the lf_set macros to work out-of-the-box for - // multiports, we need an array of *pointers* to the output structs, + // multiports, we need an array of pointers to the output structs, // but what we have on the self struct is an array of output structs. // So we have to handle multiports specially here a construct that // array of pointers. diff --git a/org.lflang/src/org/lflang/util/CollectionUtil.java b/org.lflang/src/org/lflang/util/CollectionUtil.java index 11e642b095..221cbc68ec 100644 --- a/org.lflang/src/org/lflang/util/CollectionUtil.java +++ b/org.lflang/src/org/lflang/util/CollectionUtil.java @@ -81,7 +81,7 @@ public static Map plus(Map map, K k, V v) { * not just as a key, but it also needs to be removed * from the neighbors sets of any other keys that may contain it. * - * @param map A *modifiable* map + * @param map A modifiable map * @param valueToRemove Value to remove */ public static void removeFromValues(Map> map, V valueToRemove) { From 816265387870b456385ceb1c37a00b2865f4db29 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:49:47 -0700 Subject: [PATCH 408/709] More misc code cleanups. --- .../compiler/LinguaFrancaASTUtilsTest.java | 106 ++++++------------ .../lflang/generator/WatchdogInstance.java | 2 +- .../src/org/lflang/generator/c/CUtil.java | 2 + .../python/PythonReactorGenerator.java | 2 +- 4 files changed, 36 insertions(+), 76 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java index 9c020c0afa..dde0eba23f 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -68,29 +68,16 @@ class LinguaFrancaASTUtilsTest { */ @Test public void initializedState() throws Exception { -// Java 17: -// 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); -// } -// """); -// Java 11: - Model model = parser.parse(String.join( - System.getProperty("line.separator"), - "target Cpp;", - "main reactor {", - " state a();", - " state b:int(3);", - " state c:int[](1,2,3);", - " state d(1 sec);", - " state e(1 sec, 2 sec, 3 sec);", - "}" - )); + 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); + } + """); @@ -111,29 +98,16 @@ public void initializedState() throws Exception { */ @Test public void uninitializedState() throws Exception { -// Java 17: -// Model model = parser.parse(""" -// target Cpp; -// main reactor Foo { -// state a; -// state b:int; -// state c:int[]; -// state d:time; -// state e:time[]; -// } -// ''' -// Java 11: - Model model = parser.parse(String.join( - System.getProperty("line.separator"), - "target Cpp;", - "main reactor {", - " state a;", - " state b:int;", - " state c:int[];", - " state d:time;", - " state e:time;", - "}" - )); + Model model = parser.parse(""" + target Cpp; + main reactor Foo { + state a; + state b:int; + state c:int[]; + state d:time; + state e:time[]; + } + """ Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), @@ -167,34 +141,18 @@ private Map getInsts(Model model) { @Test public void initialValue() throws Exception { -// Java 17: -// 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); -// } -// """ -// Java 11: - - Model model = parser.parse(String.join( - System.getProperty("line.separator"), - "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);", - "}" - )); + 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); + } + """ Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 78c0c9bc81..90823102d6 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -3,7 +3,7 @@ * @author Benjamin Asch * @author Edward A. Lee * @copyright (c) 2023, The University of California at Berkeley - * License in [BSD 2-clause](https://github.com/lf-lang/lingua-franca/blob/master/LICENSE) + * License in BSD 2-clause * @brief Instance of a watchdog */ package org.lflang.generator; diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index c598822bf8..dbb365e189 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -478,7 +478,9 @@ public static String reactorRefNested(ReactorInstance reactor, String runtimeInd * by {@link #bankIndexName(ReactorInstance)} if the parent is a bank. * The returned expression, when evaluated, will yield the following value: * + *
          *     d0 + w0 * (d1 + w1 * ( ... (dn-1 + wn-1 * dn) ... )
    +     * 
    * * @param reactor The reactor. */ diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java index 49d95e4be9..6e1a7f0183 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java @@ -115,7 +115,7 @@ public static String generatePythonClassInstantiations(ReactorInstance instance, if (instance.getWidth() > 0) { // For each reactor instance, create a list regardless of whether it is a bank or not. - // Non-bank reactor instances will be a list of size 1. var reactorClass = instance.definition.reactorClass + // Non-bank reactor instances will be a list of size 1. String fullName = instance.getFullName(); code.pr(String.join("\n", "# Start initializing "+fullName+" of class "+className, From 206ea18a2a1db108055a209254c66488ca82f516 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 16:57:16 -0700 Subject: [PATCH 409/709] Clean up syntax error from previous commit. --- build.gradle | 2 -- .../org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index fe3b8fca21..348949c01e 100644 --- a/build.gradle +++ b/build.gradle @@ -89,8 +89,6 @@ spotless { repositories { mavenCentral() } - // optional: limit format enforcement to just the files changed by this feature branch - ratchetFrom 'origin/master' format 'misc', { // define the files to apply `misc` to diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java index dde0eba23f..0122e03d8d 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -107,7 +107,7 @@ public void uninitializedState() throws Exception { state d:time; state e:time[]; } - """ + """); Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), @@ -152,7 +152,7 @@ reactor C(z:int(3)) { b1 = new B(y = z); b2 = new B(y = -2); } - """ + """); Assertions.assertNotNull(model); Assertions.assertTrue(model.eResource().getErrors().isEmpty(), From ed0472ae2002adf2393baf5c86d5487258a8d168 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 16:58:24 -0700 Subject: [PATCH 410/709] Google autoformatter applied to all files --- .../src/org/lflang/tests/Configurators.java | 107 +- .../src/org/lflang/tests/LFParsingTest.java | 227 +- .../src/org/lflang/tests/LFTest.java | 480 +- .../src/org/lflang/tests/LfParsingUtil.java | 129 +- .../org/lflang/tests/RunSingleTestMain.java | 77 +- .../src/org/lflang/tests/RuntimeTest.java | 391 +- .../src/org/lflang/tests/TestBase.java | 1193 ++--- .../src/org/lflang/tests/TestError.java | 44 +- .../src/org/lflang/tests/TestRegistry.java | 647 ++- .../src/org/lflang/tests/TestUtils.java | 242 +- .../lflang/tests/cli/CliToolTestFixture.java | 186 +- .../src/org/lflang/tests/cli/LfcCliTest.java | 439 +- .../src/org/lflang/tests/cli/LffCliTest.java | 167 +- .../tests/compiler/EquivalenceUnitTests.java | 97 +- .../tests/compiler/FormattingUnitTests.java | 89 +- .../tests/compiler/LetInferenceTests.java | 205 +- .../compiler/LinguaFrancaASTUtilsTest.java | 301 +- .../LinguaFrancaDependencyAnalysisTest.java | 206 +- .../compiler/LinguaFrancaParsingTest.java | 126 +- .../compiler/LinguaFrancaScopingTest.java | 302 +- .../compiler/LinguaFrancaValidationTest.java | 2665 ++++++----- .../tests/compiler/MixedRadixIntTest.java | 191 +- .../tests/compiler/PortInstanceTests.java | 398 +- .../org/lflang/tests/compiler/RangeTests.java | 169 +- .../lflang/tests/compiler/RoundTripTests.java | 74 +- .../tests/compiler/TargetConfigTests.java | 125 +- .../org/lflang/tests/lsp/ErrorInserter.java | 616 +-- .../src/org/lflang/tests/lsp/LspTests.java | 385 +- .../lflang/tests/lsp/MockLanguageClient.java | 79 +- .../lflang/tests/lsp/MockReportProgress.java | 43 +- .../lflang/tests/runtime/CArduinoTest.java | 28 +- .../org/lflang/tests/runtime/CCppTest.java | 64 +- .../lflang/tests/runtime/CSchedulerTest.java | 103 +- .../src/org/lflang/tests/runtime/CTest.java | 230 +- .../org/lflang/tests/runtime/CZephyrTest.java | 99 +- .../org/lflang/tests/runtime/CppRos2Test.java | 35 +- .../src/org/lflang/tests/runtime/CppTest.java | 138 +- .../org/lflang/tests/runtime/PythonTest.java | 213 +- .../org/lflang/tests/runtime/RustTest.java | 20 +- .../lflang/tests/runtime/TypeScriptTest.java | 110 +- .../serialization/SerializationTest.java | 59 +- .../org/lflang/tests/util/StringUtilTest.java | 38 +- org.lflang/src/org/lflang/AttributeUtils.java | 365 +- .../src/org/lflang/DefaultErrorReporter.java | 104 +- org.lflang/src/org/lflang/ErrorReporter.java | 311 +- org.lflang/src/org/lflang/FileConfig.java | 545 ++- org.lflang/src/org/lflang/InferredType.java | 349 +- .../lflang/LFResourceDescriptionStrategy.java | 118 +- .../src/org/lflang/LFResourceProvider.java | 30 +- .../src/org/lflang/LFRuntimeModule.java | 72 +- .../src/org/lflang/LFStandaloneSetup.java | 31 +- .../lflang/LFSyntaxErrorMessageProvider.java | 124 +- org.lflang/src/org/lflang/LocalStrings.java | 8 +- .../src/org/lflang/MainConflictChecker.java | 147 +- org.lflang/src/org/lflang/ModelInfo.java | 422 +- org.lflang/src/org/lflang/Target.java | 1131 +++-- org.lflang/src/org/lflang/TargetConfig.java | 716 ++- org.lflang/src/org/lflang/TargetProperty.java | 3332 +++++++------- org.lflang/src/org/lflang/TimeUnit.java | 127 +- org.lflang/src/org/lflang/TimeValue.java | 340 +- org.lflang/src/org/lflang/ast/ASTUtils.java | 3468 ++++++++------- .../src/org/lflang/ast/AstTransformation.java | 11 +- .../ast/DelayedConnectionTransformation.java | 690 +-- .../src/org/lflang/ast/FormattingUtils.java | 427 +- org.lflang/src/org/lflang/ast/IsEqual.java | 1201 +++-- org.lflang/src/org/lflang/ast/ToLf.java | 7 +- org.lflang/src/org/lflang/ast/ToText.java | 204 +- org.lflang/src/org/lflang/cli/CliBase.java | 582 ++- .../org/lflang/cli/LFStandaloneModule.java | 58 +- org.lflang/src/org/lflang/cli/Lfc.java | 515 +-- org.lflang/src/org/lflang/cli/Lff.java | 306 +- .../lflang/cli/StandaloneErrorReporter.java | 143 +- .../lflang/cli/StandaloneIssueAcceptor.java | 186 +- .../src/org/lflang/cli/VersionProvider.java | 30 +- .../lflang/diagram/lsp/LFLanguageServer.java | 36 +- .../lsp/LFLanguageServerExtension.java | 196 +- .../diagram/lsp/LanguageDiagramServer.java | 162 +- .../src/org/lflang/diagram/lsp/Progress.java | 156 +- .../AbstractSynthesisExtensions.java | 98 +- .../synthesis/LinguaFrancaSynthesis.java | 2773 ++++++------ .../ReactorParameterDisplayModes.java | 76 +- .../synthesis/SynthesisRegistration.java | 69 +- .../synthesis/action/AbstractAction.java | 79 +- .../action/CollapseAllReactorsAction.java | 88 +- .../action/ExpandAllReactorsAction.java | 84 +- .../synthesis/action/FilterCycleAction.java | 238 +- .../MemorizingExpandCollapseAction.java | 204 +- .../synthesis/action/ShowCycleAction.java | 131 +- .../postprocessor/ReactionPortAdjustment.java | 315 +- .../styles/LinguaFrancaShapeExtensions.java | 2091 +++++---- .../styles/LinguaFrancaStyleExtensions.java | 862 ++-- .../styles/ReactorFigureComponents.java | 170 +- .../synthesis/util/CycleVisualization.java | 243 +- .../InterfaceDependenciesVisualization.java | 340 +- .../synthesis/util/LayoutPostProcessing.java | 697 +-- .../diagram/synthesis/util/ModeDiagrams.java | 1206 ++--- .../synthesis/util/NamedInstanceUtil.java | 78 +- .../diagram/synthesis/util/ReactorIcons.java | 254 +- .../util/SynthesisErrorReporter.java | 138 +- .../synthesis/util/UtilityExtensions.java | 311 +- .../federated/extensions/CExtension.java | 1348 +++--- .../federated/extensions/CExtensionUtils.java | 1043 ++--- .../extensions/FedTargetExtension.java | 199 +- .../extensions/FedTargetExtensionFactory.java | 26 +- .../federated/extensions/PythonExtension.java | 279 +- .../federated/extensions/TSExtension.java | 277 +- .../federated/generator/FedASTUtils.java | 1436 +++--- .../generator/FedConnectionInstance.java | 140 +- .../federated/generator/FedEmitter.java | 104 +- .../federated/generator/FedFileConfig.java | 196 +- .../federated/generator/FedGenerator.java | 1049 +++-- .../federated/generator/FedImportEmitter.java | 77 +- .../federated/generator/FedMainEmitter.java | 131 +- .../generator/FedPreambleEmitter.java | 62 +- .../generator/FedReactorEmitter.java | 20 +- .../federated/generator/FedTargetConfig.java | 104 +- .../federated/generator/FedTargetEmitter.java | 48 +- .../lflang/federated/generator/FedUtils.java | 46 +- .../federated/generator/FederateInstance.java | 1123 +++-- .../generator/LineAdjustingErrorReporter.java | 210 +- .../generator/SynchronizedErrorReporter.java | 144 +- .../federated/launcher/BuildConfig.java | 93 +- .../federated/launcher/CBuildConfig.java | 68 +- .../launcher/FedLauncherGenerator.java | 898 ++-- .../federated/launcher/PyBuildConfig.java | 37 +- .../lflang/federated/launcher/RtiConfig.java | 115 +- .../federated/launcher/TsBuildConfig.java | 64 +- .../FedNativePythonSerialization.java | 172 +- .../FedROS2CPPSerialization.java | 348 +- .../serialization/FedSerialization.java | 133 +- .../serialization/SupportedSerializers.java | 32 +- .../federated/validation/FedValidator.java | 95 +- .../org/lflang/formatting2/LFFormatter.java | 48 +- .../org/lflang/generator/ActionInstance.java | 150 +- .../src/org/lflang/generator/CodeBuilder.java | 1018 ++--- .../src/org/lflang/generator/CodeMap.java | 554 ++- .../lflang/generator/DeadlineInstance.java | 100 +- .../lflang/generator/DelayBodyGenerator.java | 93 +- .../lflang/generator/DiagnosticReporting.java | 89 +- .../generator/DockerComposeGenerator.java | 156 +- .../src/org/lflang/generator/DockerData.java | 55 +- .../org/lflang/generator/DockerGenerator.java | 82 +- .../generator/FedDockerComposeGenerator.java | 79 +- .../lflang/generator/GenerationException.java | 68 +- .../org/lflang/generator/GeneratorBase.java | 1150 +++-- .../generator/GeneratorCommandFactory.java | 260 +- .../org/lflang/generator/GeneratorResult.java | 188 +- .../org/lflang/generator/GeneratorUtils.java | 299 +- .../HumanReadableReportingStrategy.java | 282 +- .../lflang/generator/IntegratedBuilder.java | 248 +- .../generator/InvalidLfSourceException.java | 37 +- .../generator/InvalidSourceException.java | 18 +- .../src/org/lflang/generator/LFGenerator.java | 320 +- .../lflang/generator/LFGeneratorContext.java | 258 +- .../src/org/lflang/generator/LFResource.java | 65 +- .../LanguageServerErrorReporter.java | 349 +- .../lflang/generator/LfExpressionVisitor.java | 209 +- .../src/org/lflang/generator/MainContext.java | 290 +- .../org/lflang/generator/MixedRadixInt.java | 418 +- .../org/lflang/generator/ModeInstance.java | 365 +- .../org/lflang/generator/NamedInstance.java | 600 ++- .../lflang/generator/ParameterInstance.java | 193 +- .../org/lflang/generator/PortInstance.java | 801 ++-- .../src/org/lflang/generator/Position.java | 435 +- .../src/org/lflang/generator/Range.java | 223 +- .../lflang/generator/ReactionInstance.java | 1033 +++-- .../generator/ReactionInstanceGraph.java | 755 ++-- .../org/lflang/generator/ReactorInstance.java | 2105 +++++---- .../org/lflang/generator/RuntimeRange.java | 839 ++-- .../src/org/lflang/generator/SendRange.java | 491 +-- .../src/org/lflang/generator/SubContext.java | 148 +- .../src/org/lflang/generator/TargetTypes.java | 457 +- .../org/lflang/generator/TimerInstance.java | 129 +- .../org/lflang/generator/TriggerInstance.java | 299 +- .../UnsupportedGeneratorFeatureException.java | 17 +- .../lflang/generator/ValidationStrategy.java | 67 +- .../src/org/lflang/generator/Validator.java | 329 +- .../lflang/generator/WatchdogInstance.java | 4 +- .../lflang/generator/c/CActionGenerator.java | 290 +- .../lflang/generator/c/CCmakeGenerator.java | 672 +-- .../src/org/lflang/generator/c/CCompiler.java | 729 ++- .../generator/c/CConstructorGenerator.java | 52 +- .../lflang/generator/c/CCoreFilesUtils.java | 34 +- .../generator/c/CDelayBodyGenerator.java | 97 +- .../lflang/generator/c/CDockerGenerator.java | 112 +- .../org/lflang/generator/c/CFileConfig.java | 33 +- .../org/lflang/generator/c/CGenerator.java | 3907 +++++++++-------- .../generator/c/CMainFunctionGenerator.java | 203 +- .../lflang/generator/c/CMethodGenerator.java | 280 +- .../generator/c/CMixedRadixGenerator.java | 24 +- .../lflang/generator/c/CModesGenerator.java | 386 +- .../generator/c/CParameterGenerator.java | 61 +- .../lflang/generator/c/CPortGenerator.java | 496 ++- .../generator/c/CPreambleGenerator.java | 137 +- .../generator/c/CReactionGenerator.java | 2326 +++++----- .../c/CReactorHeaderFileGenerator.java | 376 +- .../lflang/generator/c/CStateGenerator.java | 213 +- .../lflang/generator/c/CTimerGenerator.java | 111 +- .../lflang/generator/c/CTracingGenerator.java | 92 +- .../generator/c/CTriggerObjectsGenerator.java | 2005 +++++---- .../src/org/lflang/generator/c/CTypes.java | 286 +- .../src/org/lflang/generator/c/CUtil.java | 1510 ++++--- .../generator/c/CWatchdogGenerator.java | 98 +- .../c/InteractingContainedReactors.java | 229 +- .../generator/c/TypeParameterizedReactor.java | 111 +- .../lflang/generator/python/PyFileConfig.java | 38 +- .../org/lflang/generator/python/PyUtil.java | 262 +- .../python/PythonActionGenerator.java | 15 +- .../python/PythonDelayBodyGenerator.java | 126 +- .../python/PythonDockerGenerator.java | 41 +- .../generator/python/PythonGenerator.java | 1142 +++-- .../generator/python/PythonInfoGenerator.java | 90 +- .../python/PythonMainFunctionGenerator.java | 37 +- .../python/PythonMethodGenerator.java | 58 +- .../generator/python/PythonModeGenerator.java | 147 +- .../python/PythonParameterGenerator.java | 170 +- .../generator/python/PythonPortGenerator.java | 443 +- .../python/PythonPreambleGenerator.java | 71 +- .../python/PythonReactionGenerator.java | 1100 ++--- .../python/PythonReactorGenerator.java | 273 +- .../python/PythonStateGenerator.java | 50 +- .../lflang/generator/python/PythonTypes.java | 104 +- .../generator/python/PythonValidator.java | 647 +-- .../generator/rust/CargoDependencySpec.java | 16 +- .../generator/rust/RustTargetConfig.java | 142 +- .../generator/ts/TSDockerGenerator.java | 21 +- .../src/org/lflang/generator/ts/TSTypes.java | 118 +- .../src/org/lflang/graph/DirectedGraph.java | 556 ++- org.lflang/src/org/lflang/graph/Graph.java | 101 +- .../org/lflang/graph/InstantiationGraph.java | 251 +- .../src/org/lflang/graph/NodeAnnotation.java | 100 +- .../src/org/lflang/graph/NodeAnnotations.java | 52 +- .../src/org/lflang/graph/PrecedenceGraph.java | 413 +- .../src/org/lflang/graph/TopologyGraph.java | 244 +- .../src/org/lflang/ide/LFIdeModule.java | 8 +- org.lflang/src/org/lflang/ide/LFIdeSetup.java | 17 +- .../lflang/scoping/LFGlobalScopeProvider.java | 207 +- .../org/lflang/scoping/LFScopeProvider.java | 11 +- .../lflang/scoping/LFScopeProviderImpl.java | 425 +- .../src/org/lflang/util/ArduinoUtil.java | 224 +- org.lflang/src/org/lflang/util/Averager.java | 33 +- .../src/org/lflang/util/CollectionUtil.java | 307 +- org.lflang/src/org/lflang/util/FileUtil.java | 1744 ++++---- .../src/org/lflang/util/IteratorUtil.java | 96 +- org.lflang/src/org/lflang/util/LFCommand.java | 715 ++- .../src/org/lflang/util/StringUtil.java | 234 +- .../util/TargetResourceNotFoundException.java | 13 +- .../org/lflang/validation/AttributeSpec.java | 345 +- .../lflang/validation/BaseLFValidator.java | 64 +- .../LFNamesAreUniqueValidationHelper.java | 33 +- .../org/lflang/validation/LFValidator.java | 3325 +++++++------- .../validation/ValidatorErrorReporter.java | 297 +- 252 files changed, 47689 insertions(+), 47129 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index e3fe6c5508..24ee6f38f3 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -26,7 +26,6 @@ import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; -import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -37,62 +36,60 @@ */ public class Configurators { - /** Test configuration function. */ - @FunctionalInterface - public interface Configurator { - - /** - * Apply a side effect to the given test case to change its default configuration. - * Return true if configuration succeeded, false otherwise. - */ - boolean configure(LFTest test); - } + /** Test configuration function. */ + @FunctionalInterface + public interface Configurator { /** - * Configure the given test to use single-threaded execution. - * - * For targets that provide a threaded and an unthreaded runtime, - * this configures using the unthreaded runtime. For targets that - * do not distinguish threaded and unthreaded runtime, the number - * of workers is set to 1. - * - * @param test The test to configure. - * @return True if successful, false otherwise. + * Apply a side effect to the given test case to change its default configuration. Return true + * if configuration succeeded, false otherwise. */ - public static boolean disableThreading(LFTest test) { - test.getContext().getArgs().setProperty("threading", "false"); - test.getContext().getArgs().setProperty("workers", "1"); - return true; - } + boolean configure(LFTest test); + } - public static boolean makeZephyrCompatible(LFTest test) { - test.getContext().getArgs().setProperty("tracing", "false"); - test.getContext().getTargetConfig().threading = false; - test.getContext().getTargetConfig().setByUser.add(TargetProperty.THREADING); - test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; - test.getContext().getTargetConfig().platformOptions.flash = false; - test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; - return true; - } - /** - * Make no changes to the configuration. - * - * @param ignoredTest The test to configure. - * @return True - */ - public static boolean noChanges(LFTest ignoredTest) { - return true; - } + /** + * Configure the given test to use single-threaded execution. + * + *

    For targets that provide a threaded and an unthreaded runtime, this configures using the + * unthreaded runtime. For targets that do not distinguish threaded and unthreaded runtime, the + * number of workers is set to 1. + * + * @param test The test to configure. + * @return True if successful, false otherwise. + */ + public static boolean disableThreading(LFTest test) { + test.getContext().getArgs().setProperty("threading", "false"); + test.getContext().getArgs().setProperty("workers", "1"); + return true; + } - /** - * Given a test category, return true if it is compatible with single-threaded execution. - */ - public static boolean compatibleWithThreadingOff(TestCategory category) { + public static boolean makeZephyrCompatible(LFTest test) { + test.getContext().getArgs().setProperty("tracing", "false"); + test.getContext().getTargetConfig().threading = false; + test.getContext().getTargetConfig().setByUser.add(TargetProperty.THREADING); + test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; + test.getContext().getTargetConfig().platformOptions.flash = false; + test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + return true; + } + /** + * Make no changes to the configuration. + * + * @param ignoredTest The test to configure. + * @return True + */ + public static boolean noChanges(LFTest ignoredTest) { + return true; + } + + /** Given a test category, return true if it is compatible with single-threaded execution. */ + public static boolean compatibleWithThreadingOff(TestCategory category) { - // CONCURRENT, FEDERATED, DOCKER_FEDERATED, DOCKER - // are not compatible with single-threaded execution. - // ARDUINO and ZEPHYR have their own test suites, so we don't need to rerun. - boolean excluded = category == TestCategory.CONCURRENT + // CONCURRENT, FEDERATED, DOCKER_FEDERATED, DOCKER + // are not compatible with single-threaded execution. + // ARDUINO and ZEPHYR have their own test suites, so we don't need to rerun. + boolean excluded = + category == TestCategory.CONCURRENT || category == TestCategory.SERIALIZATION || category == TestCategory.FEDERATED || category == TestCategory.DOCKER_FEDERATED @@ -100,8 +97,8 @@ public static boolean compatibleWithThreadingOff(TestCategory category) { || category == TestCategory.ARDUINO || category == TestCategory.ZEPHYR; - // SERIALIZATION and TARGET tests are excluded on Windows. - excluded |= TestBase.isWindows() && (category == TestCategory.TARGET); - return !excluded; - } + // SERIALIZATION and TARGET tests are excluded on Windows. + excluded |= TestBase.isWindows() && (category == TestCategory.TARGET); + return !excluded; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java index 487c3b21e5..f0e96ee7d0 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java @@ -3,8 +3,8 @@ */ package org.lflang.tests; +import com.google.inject.Inject; import java.util.List; - import org.eclipse.emf.ecore.resource.Resource.Diagnostic; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; @@ -13,127 +13,118 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.lf.Model; -import com.google.inject.Inject; - @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) public class LFParsingTest { - @Inject - private ParseHelper parseHelper; - - - @Test - public void testLexingEmptyTargetProperties() throws Exception { - assertNoParsingErrorsIn("target C { }; \nreactor Foo {}"); - assertNoParsingErrorsIn("target C {a:b,}; \nreactor Foo {}"); - expectParsingErrorIn("target C {,}; \nreactor Foo {}"); - - // array elements - // assertNoParsingErrorsIn("target C {x:[ ]}; \nreactor Foo {}"); - // assertNoParsingErrorsIn("target C {x:[]}; \nreactor Foo {}"); - // assertNoParsingErrorsIn("target C {x:[,]}; \nreactor Foo {}"); - } - - @Test - public void testLexingLifetimeAnnots() throws Exception { - assertNoParsingErrorsIn(makeLfTargetCode("Rust", - " struct Hello<'a> { \n" - + " r: &'a str,\n" - + " r2: &'a Box>,\n" - + " }")); - } - - - @Test - public void testLexingSingleLifetimeAnnot() throws Exception { - // just to be sure, have a single lifetime annot. - assertNoParsingErrorsIn(makeLfTargetCode("Rust", - " struct Hello { \n" - + " r: &'static str,\n" - + " }")); - } - - - @Test - public void testLexingNewlineCont() throws Exception { - /* - This example looks like this: - "a\ - bcde" - - This is valid C++ to escape a newline. - */ - - assertNoParsingErrorsIn(makeLfTargetCode("Cpp", - " \"a\\\n" - + " bcde\"\n" - )); - } - - - @Test - public void testLexingSquotedString() throws Exception { - // we can't do that anymore - expectParsingErrorIn(makeLfTargetCode("Python", "a = ' a string '")); - } - - - @Test - public void testLexingDquotedString() throws Exception { - assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \" a string \"")); - } - - @Test - public void testLexingMultilineString() throws Exception { - assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \"\"\" a 'string' \"\"\"")); - assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \"\"\" a 'strin\ng' \"\"\"")); - assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \"\"\" \na 'string'\n \"\"\"")); - } - - @Test - public void testLexingDquotedStringWithEscape() throws Exception { - assertNoParsingErrorsIn(makeLfTargetCode("C", "printf(\"Hello World.\\n\");\n")); - } - - - @Test - public void testLexingCharLiteral() throws Exception { - assertNoParsingErrorsIn(makeLfTargetCode("C", "char c0 = 'c';")); - } - - @Test - public void testLexingEscapedCharLiteral() throws Exception { - assertNoParsingErrorsIn(makeLfTargetCode("C", "char c0 = '\\n';")); - } - - private String makeLfTargetCode(final String target, final String code) { - return "target " + target + ";\n" - + "reactor Foo {\n" - + " preamble {=\n" - + " " + code + "\n" - + " =}\n" - + "}"; - } - - private void assertNoParsingErrorsIn(String source) throws Exception { - List errors = doParse(source); - Assertions.assertTrue(errors.isEmpty(), "Unexpected errors: " + IterableExtensions.join(errors, ", ")); - } - - - private void expectParsingErrorIn(String source) throws Exception { - List errors = doParse(source); - Assertions.assertFalse(errors.isEmpty(), "Expected a parsing error, none occurred"); - } - - - private List doParse(String source) throws Exception { - Model result = parseHelper.parse(source); - Assertions.assertNotNull(result); - return result.eResource().getErrors(); - } + @Inject private ParseHelper parseHelper; + + @Test + public void testLexingEmptyTargetProperties() throws Exception { + assertNoParsingErrorsIn("target C { }; \nreactor Foo {}"); + assertNoParsingErrorsIn("target C {a:b,}; \nreactor Foo {}"); + expectParsingErrorIn("target C {,}; \nreactor Foo {}"); + + // array elements + // assertNoParsingErrorsIn("target C {x:[ ]}; \nreactor Foo {}"); + // assertNoParsingErrorsIn("target C {x:[]}; \nreactor Foo {}"); + // assertNoParsingErrorsIn("target C {x:[,]}; \nreactor Foo {}"); + } + + @Test + public void testLexingLifetimeAnnots() throws Exception { + assertNoParsingErrorsIn( + makeLfTargetCode( + "Rust", + " struct Hello<'a> { \n" + + " r: &'a str,\n" + + " r2: &'a Box>,\n" + + " }")); + } + + @Test + public void testLexingSingleLifetimeAnnot() throws Exception { + // just to be sure, have a single lifetime annot. + assertNoParsingErrorsIn( + makeLfTargetCode( + "Rust", " struct Hello { \n" + " r: &'static str,\n" + " }")); + } + + @Test + public void testLexingNewlineCont() throws Exception { + /* + This example looks like this: + "a\ + bcde" + + This is valid C++ to escape a newline. + */ + + assertNoParsingErrorsIn(makeLfTargetCode("Cpp", " \"a\\\n" + " bcde\"\n")); + } + + @Test + public void testLexingSquotedString() throws Exception { + // we can't do that anymore + expectParsingErrorIn(makeLfTargetCode("Python", "a = ' a string '")); + } + + @Test + public void testLexingDquotedString() throws Exception { + assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \" a string \"")); + } + + @Test + public void testLexingMultilineString() throws Exception { + assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \"\"\" a 'string' \"\"\"")); + assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \"\"\" a 'strin\ng' \"\"\"")); + assertNoParsingErrorsIn(makeLfTargetCode("Python", "a = \"\"\" \na 'string'\n \"\"\"")); + } + + @Test + public void testLexingDquotedStringWithEscape() throws Exception { + assertNoParsingErrorsIn(makeLfTargetCode("C", "printf(\"Hello World.\\n\");\n")); + } + + @Test + public void testLexingCharLiteral() throws Exception { + assertNoParsingErrorsIn(makeLfTargetCode("C", "char c0 = 'c';")); + } + + @Test + public void testLexingEscapedCharLiteral() throws Exception { + assertNoParsingErrorsIn(makeLfTargetCode("C", "char c0 = '\\n';")); + } + + private String makeLfTargetCode(final String target, final String code) { + return "target " + + target + + ";\n" + + "reactor Foo {\n" + + " preamble {=\n" + + " " + + code + + "\n" + + " =}\n" + + "}"; + } + + private void assertNoParsingErrorsIn(String source) throws Exception { + List errors = doParse(source); + Assertions.assertTrue( + errors.isEmpty(), "Unexpected errors: " + IterableExtensions.join(errors, ", ")); + } + + private void expectParsingErrorIn(String source) throws Exception { + List errors = doParse(source); + Assertions.assertFalse(errors.isEmpty(), "Expected a parsing error, none occurred"); + } + + private List doParse(String source) throws Exception { + Model result = parseHelper.parse(source); + Assertions.assertNotNull(result); + return result.eResource().getErrors(); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index cc69dea77a..58b3cbf846 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -8,286 +8,286 @@ import java.io.Reader; import java.nio.file.Path; import java.nio.file.Paths; - import org.eclipse.xtext.util.RuntimeIOException; - import org.lflang.FileConfig; import org.lflang.Target; import org.lflang.generator.LFGeneratorContext; /** * Information about an indexed Lingua Franca test program. - * - * @author Marten Lohstroh * + * @author Marten Lohstroh */ public class LFTest implements Comparable { - /** The path to the test. */ - private final Path srcPath; - - /** The name of the test. */ - private final String name; - - /** The result of the test. */ - private Result result = Result.UNKNOWN; - - /** Context provided to the code generators */ - private LFGeneratorContext context; - - /** Path of the test program relative to the package root. */ - private final Path relativePath; - - /** Records compilation stdout/stderr. */ - private final ByteArrayOutputStream compilationLog = new ByteArrayOutputStream(); - - /** Specialized object for capturing output streams while executing the test. */ - private final ExecutionLogger execLog = new ExecutionLogger(); - - /** String builder for collecting issues encountered during test execution. */ - private final StringBuilder issues = new StringBuilder(); - - /** The target of the test program. */ - private final Target target; - - /** - * Create a new test. - * - * @param target The target of the test program. - * @param srcFile The path to the file of the test program. - */ - public LFTest(Target target, Path srcFile) { - this.target = target; - this.srcPath = srcFile; - this.name = FileConfig.findPackageRoot(srcFile, s -> {}).relativize(srcFile).toString(); - this.relativePath = Paths.get(name); + /** The path to the test. */ + private final Path srcPath; + + /** The name of the test. */ + private final String name; + + /** The result of the test. */ + private Result result = Result.UNKNOWN; + + /** Context provided to the code generators */ + private LFGeneratorContext context; + + /** Path of the test program relative to the package root. */ + private final Path relativePath; + + /** Records compilation stdout/stderr. */ + private final ByteArrayOutputStream compilationLog = new ByteArrayOutputStream(); + + /** Specialized object for capturing output streams while executing the test. */ + private final ExecutionLogger execLog = new ExecutionLogger(); + + /** String builder for collecting issues encountered during test execution. */ + private final StringBuilder issues = new StringBuilder(); + + /** The target of the test program. */ + private final Target target; + + /** + * Create a new test. + * + * @param target The target of the test program. + * @param srcFile The path to the file of the test program. + */ + public LFTest(Target target, Path srcFile) { + this.target = target; + this.srcPath = srcFile; + this.name = FileConfig.findPackageRoot(srcFile, s -> {}).relativize(srcFile).toString(); + this.relativePath = Paths.get(name); + } + + /** Copy constructor */ + public LFTest(LFTest test) { + this(test.target, test.srcPath); + } + + /** Stream object for capturing standard and error output. */ + public OutputStream getOutputStream() { + return compilationLog; + } + + public FileConfig getFileConfig() { + return context.getFileConfig(); + } + + public LFGeneratorContext getContext() { + return context; + } + + public Path getSrcPath() { + return srcPath; + } + + /** + * Comparison implementation to allow for tests to be sorted (e.g., when added to a tree set) + * based on their path (relative to the root of the test directory). + */ + public int compareTo(LFTest t) { + return this.relativePath.compareTo(t.relativePath); + } + + /** + * Return true if the given object is an LFTest instance with a name identical to this test. + * + * @param o The object to test for equality with respect to this one. + * @return True if the given object is equal to this one, false otherwise. + */ + @Override + public boolean equals(Object o) { + return o instanceof LFTest && ((LFTest) o).name.equals(this.name); + } + + /** + * Return a string representing the name of this test. + * + * @return The name of this test. + */ + @Override + public String toString() { + return this.name; + } + + /** + * Identify tests uniquely on the basis of their name. + * + * @return The hash code of the name of this test. + */ + @Override + public int hashCode() { + return this.name.hashCode(); + } + + /** + * Report whether this test has failed. + * + * @return True if the test has failed, false otherwise. + */ + public boolean hasFailed() { + return result != Result.TEST_PASS; + } + + public boolean hasPassed() { + return result == Result.TEST_PASS; + } + + /** + * Compile a string that contains all collected errors and return it. + * + * @return A string that contains all collected errors. + */ + public void reportErrors() { + if (this.hasFailed()) { + System.out.println( + "+---------------------------------------------------------------------------+"); + System.out.println("Failed: " + this); + System.out.println( + "-----------------------------------------------------------------------------"); + System.out.println("Reason: " + this.result.message); + printIfNotEmpty("Reported issues", this.issues.toString()); + printIfNotEmpty("Compilation output", this.compilationLog.toString()); + printIfNotEmpty("Execution output", this.execLog.toString()); + System.out.println( + "+---------------------------------------------------------------------------+"); } + } - /** Copy constructor */ - public LFTest(LFTest test) { - this(test.target, test.srcPath); + public void handleTestError(TestError e) { + result = e.getResult(); + if (e.getMessage() != null) { + issues.append(e.getMessage()); } - - /** Stream object for capturing standard and error output. */ - public OutputStream getOutputStream() { - return compilationLog; + if (e.getException() != null) { + issues.append(System.lineSeparator()); + issues.append(TestBase.stackTraceToString(e.getException())); } - - public FileConfig getFileConfig() { return context.getFileConfig(); } - - public LFGeneratorContext getContext() { return context; } - - public Path getSrcPath() { return srcPath; } - - /** - * Comparison implementation to allow for tests to be sorted (e.g., when added to a - * tree set) based on their path (relative to the root of the test directory). - */ - public int compareTo(LFTest t) { - return this.relativePath.compareTo(t.relativePath); + } + + public void markPassed() { + result = Result.TEST_PASS; + // clear the execution log to free memory + execLog.clear(); + } + + void configure(LFGeneratorContext context) { + this.context = context; + } + + /** + * Print the message to the system output, but only if the message is not empty. + * + * @param header Header for the message to be printed. + * @param message The log message to print. + */ + private static void printIfNotEmpty(String header, String message) { + if (!message.isEmpty()) { + System.out.println(header + ":"); + System.out.println(message); } + } + + /** Enumeration of test outcomes. */ + public enum Result { + UNKNOWN("No information available."), + CONFIG_FAIL("Could not apply configuration."), + PARSE_FAIL("Unable to parse test."), + VALIDATE_FAIL("Unable to validate test."), + CODE_GEN_FAIL("Error while generating code for test."), + NO_EXEC_FAIL("Did not execute test."), + TEST_FAIL("Test did not pass."), + TEST_EXCEPTION("Test exited with an exception."), + TEST_TIMEOUT("Test timed out."), + TEST_PASS("Test passed."); + + /** Description of the outcome. */ + public final String message; /** - * Return true if the given object is an LFTest instance with a name identical to this test. - * @param o The object to test for equality with respect to this one. - * @return True if the given object is equal to this one, false otherwise. - */ - @Override - public boolean equals(Object o) { - return o instanceof LFTest && ((LFTest) o).name.equals(this.name); - } - - /** - * Return a string representing the name of this test. - * @return The name of this test. - */ - @Override - public String toString() { - return this.name; - } - - /** - * Identify tests uniquely on the basis of their name. + * Private constructor. * - * @return The hash code of the name of this test. + * @param message Description of the test outcome. */ - @Override - public int hashCode() { - return this.name.hashCode(); + Result(String message) { + this.message = message; } + } - /** - * Report whether this test has failed. - * @return True if the test has failed, false otherwise. - */ - public boolean hasFailed() { - return result != Result.TEST_PASS; - } - - public boolean hasPassed() { - return result == Result.TEST_PASS; - } + /** + * Inner class for capturing streams during execution of a test, capable of recording output + * streams up until the moment that a test is interrupted upon timing out. + * + * @author Marten Lohstroh + */ + public static final class ExecutionLogger { /** - * Compile a string that contains all collected errors and return it. - * @return A string that contains all collected errors. + * String buffer used to record the standard output and error streams from the input process. */ - public void reportErrors() { - if (this.hasFailed()) { - System.out.println("+---------------------------------------------------------------------------+"); - System.out.println("Failed: " + this); - System.out.println("-----------------------------------------------------------------------------"); - System.out.println("Reason: " + this.result.message); - printIfNotEmpty("Reported issues", this.issues.toString()); - printIfNotEmpty("Compilation output", this.compilationLog.toString()); - printIfNotEmpty("Execution output", this.execLog.toString()); - System.out.println("+---------------------------------------------------------------------------+"); - } - } - - public void handleTestError(TestError e) { - result = e.getResult(); - if (e.getMessage() != null) { - issues.append(e.getMessage()); - } - if (e.getException() != null) { - issues.append(System.lineSeparator()); - issues.append(TestBase.stackTraceToString(e.getException())); - } - } - - public void markPassed() { - result = Result.TEST_PASS; - // clear the execution log to free memory - execLog.clear(); - } - - void configure(LFGeneratorContext context) { - this.context = context; - } + StringBuffer buffer = new StringBuffer(); /** - * Print the message to the system output, but only if the message is not empty. - * - * @param header Header for the message to be printed. - * @param message The log message to print. + * Return a thread responsible for recording the standard output stream of the given process. A + * separate thread is used so that the activity can be preempted. */ - private static void printIfNotEmpty(String header, String message) { - if (!message.isEmpty()) { - System.out.println(header + ":"); - System.out.println(message); - } + public Thread recordStdOut(Process process) { + return recordStream(buffer, process.getInputStream()); } /** - * Enumeration of test outcomes. + * Return a thread responsible for recording the error stream of the given process. A separate + * thread is used so that the activity can be preempted. */ - public enum Result { - UNKNOWN("No information available."), - CONFIG_FAIL("Could not apply configuration."), - PARSE_FAIL("Unable to parse test."), - VALIDATE_FAIL("Unable to validate test."), - CODE_GEN_FAIL("Error while generating code for test."), - NO_EXEC_FAIL("Did not execute test."), - TEST_FAIL("Test did not pass."), - TEST_EXCEPTION("Test exited with an exception."), - TEST_TIMEOUT("Test timed out."), - TEST_PASS("Test passed."); - - /** - * Description of the outcome. - */ - public final String message; - - /** - * Private constructor. - * @param message Description of the test outcome. - */ - Result(String message) { - this.message = message; - } + public Thread recordStdErr(Process process) { + return recordStream(buffer, process.getErrorStream()); } - /** - * Inner class for capturing streams during execution of a test, capable of - * recording output streams up until the moment that a test is interrupted - * upon timing out. - * - * @author Marten Lohstroh + * Return a thread responsible for recording the given stream. * + * @param builder The builder to append to. + * @param inputStream The stream to read from. */ - public static final class ExecutionLogger { - - /** - * String buffer used to record the standard output and error - * streams from the input process. - */ - StringBuffer buffer = new StringBuffer(); - - /** - * Return a thread responsible for recording the standard output stream - * of the given process. - * A separate thread is used so that the activity can be preempted. - */ - public Thread recordStdOut(Process process) { - return recordStream(buffer, process.getInputStream()); - } - - /** - * Return a thread responsible for recording the error stream of the - * given process. - * A separate thread is used so that the activity can be preempted. - */ - public Thread recordStdErr(Process process) { - return recordStream(buffer, process.getErrorStream()); - } - - /** - * Return a thread responsible for recording the given stream. - * - * @param builder The builder to append to. - * @param inputStream The stream to read from. - */ - private Thread recordStream(StringBuffer builder, InputStream inputStream) { - return new Thread(() -> { - try (Reader reader = new InputStreamReader(inputStream)) { - int len; - char[] buf = new char[1024]; - while ((len = reader.read(buf)) > 0) { - builder.append(buf, 0, len); - } - } catch (IOException e) { - throw new RuntimeIOException(e); - } - - }); - } - - @Override - public String toString() { - return buffer.toString(); - } - - public void clear() { - buffer = null; - } + private Thread recordStream(StringBuffer builder, InputStream inputStream) { + return new Thread( + () -> { + try (Reader reader = new InputStreamReader(inputStream)) { + int len; + char[] buf = new char[1024]; + while ((len = reader.read(buf)) > 0) { + builder.append(buf, 0, len); + } + } catch (IOException e) { + throw new RuntimeIOException(e); + } + }); } - - /** - * Return a thread responsible for recording the standard output stream of the given process. - * A separate thread is used so that the activity can be preempted. - */ - public Thread recordStdOut(Process process) { - return execLog.recordStdOut(process); + @Override + public String toString() { + return buffer.toString(); } - /** - * Return a thread responsible for recording the error stream of the given process. - * A separate thread is used so that the activity can be preempted. - */ - public Thread recordStdErr(Process process) { - return execLog.recordStdErr(process); + public void clear() { + buffer = null; } + } + + /** + * Return a thread responsible for recording the standard output stream of the given process. A + * separate thread is used so that the activity can be preempted. + */ + public Thread recordStdOut(Process process) { + return execLog.recordStdOut(process); + } + + /** + * Return a thread responsible for recording the error stream of the given process. A separate + * thread is used so that the activity can be preempted. + */ + public Thread recordStdErr(Process process) { + return execLog.recordStdErr(process); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/LfParsingUtil.java b/org.lflang.tests/src/org/lflang/tests/LfParsingUtil.java index fd9ffa2a2e..ae45bf4e7c 100644 --- a/org.lflang.tests/src/org/lflang/tests/LfParsingUtil.java +++ b/org.lflang.tests/src/org/lflang/tests/LfParsingUtil.java @@ -1,100 +1,87 @@ package org.lflang.tests; +import com.google.inject.Injector; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; import org.junit.jupiter.api.Assertions; - import org.lflang.LFStandaloneSetup; import org.lflang.lf.Model; -import com.google.inject.Injector; - /** * @author Clément Fournier */ public class LfParsingUtil { - /** - * Parse the given file, asserts that there are no parsing errors. - */ - public static Model parseValidModel( - String fileName, - String reformattedTestCase - ) { - Model resultingModel = parse(reformattedTestCase); - checkValid(fileName, resultingModel); - return resultingModel; - } + /** Parse the given file, asserts that there are no parsing errors. */ + public static Model parseValidModel(String fileName, String reformattedTestCase) { + Model resultingModel = parse(reformattedTestCase); + checkValid(fileName, resultingModel); + return resultingModel; + } - private static void checkValid(String fileName, Model resultingModel) { - Assertions.assertNotNull(resultingModel); - if (!resultingModel.eResource().getErrors().isEmpty()) { - resultingModel.eResource().getErrors().forEach(System.err::println); - Assertions.assertTrue(resultingModel.eResource().getErrors().isEmpty(), - "Parsing errors in " + fileName); - } + private static void checkValid(String fileName, Model resultingModel) { + Assertions.assertNotNull(resultingModel); + if (!resultingModel.eResource().getErrors().isEmpty()) { + resultingModel.eResource().getErrors().forEach(System.err::println); + Assertions.assertTrue( + resultingModel.eResource().getErrors().isEmpty(), "Parsing errors in " + fileName); } + } - public static Model parseSourceAsIfInDirectory( - Path directory, - String sourceText - ) { - int num = 0; - while (Files.exists(directory.resolve("file" + num + ".lf"))) { - num++; - } - Path file = directory.resolve("file" + num + ".lf"); - try { - Files.writeString(file, sourceText); - Model resultingModel = parse(file); - checkValid("file in " + directory, resultingModel); - return resultingModel; - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - try { - Files.deleteIfExists(file); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - + public static Model parseSourceAsIfInDirectory(Path directory, String sourceText) { + int num = 0; + while (Files.exists(directory.resolve("file" + num + ".lf"))) { + num++; + } + Path file = directory.resolve("file" + num + ".lf"); + try { + Files.writeString(file, sourceText); + Model resultingModel = parse(file); + checkValid("file in " + directory, resultingModel); + return resultingModel; + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + Files.deleteIfExists(file); + } catch (IOException e) { + throw new RuntimeException(e); + } } + } - public static Model parse(String fileContents) { - Path file = null; + public static Model parse(String fileContents) { + Path file = null; + try { + file = Files.createTempFile("lftests", ".lf"); + Files.writeString(file, fileContents); + return parse(file); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (file != null) { try { - file = Files.createTempFile("lftests", ".lf"); - Files.writeString(file, fileContents); - return parse(file); + Files.deleteIfExists(file); } catch (IOException e) { - throw new RuntimeException(e); - } finally { - if (file != null) { - try { - Files.deleteIfExists(file); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); } + } } + } - public static Model parse(Path file) { - // Source: https://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application_.3F - Injector injector = new LFStandaloneSetup().createInjectorAndDoEMFRegistration(); - XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); - resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); - Resource resource = resourceSet.getResource( - URI.createFileURI(file.toFile().getAbsolutePath()), - true - ); - return (Model) resource.getContents().get(0); - } + public static Model parse(Path file) { + // Source: + // https://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application_.3F + Injector injector = new LFStandaloneSetup().createInjectorAndDoEMFRegistration(); + XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); + resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); + Resource resource = + resourceSet.getResource(URI.createFileURI(file.toFile().getAbsolutePath()), true); + return (Model) resource.getContents().get(0); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java b/org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java index 0f7e919174..fdb26de7f5 100644 --- a/org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java +++ b/org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java @@ -29,7 +29,6 @@ import java.nio.file.Paths; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.lflang.Target; import org.lflang.tests.runtime.CCppTest; import org.lflang.tests.runtime.CTest; @@ -39,55 +38,55 @@ import org.lflang.tests.runtime.TypeScriptTest; /** - * Execute a single test case. Use it with the gradle task - * {@code gradle runSingleTest --args test/Python/src/Minimal.lf} + * Execute a single test case. Use it with the gradle task {@code gradle runSingleTest --args + * test/Python/src/Minimal.lf} * * @author Clément Fournier */ public class RunSingleTestMain { + private static final Pattern TEST_FILE_PATTERN = + Pattern.compile("(test/(\\w+))/src/([^/]++/)*(\\w+.lf)"); - private static final Pattern TEST_FILE_PATTERN = Pattern.compile("(test/(\\w+))/src/([^/]++/)*(\\w+.lf)"); - - public static void main(String[] args) throws FileNotFoundException { - if (args.length != 1) { - throw new IllegalArgumentException("Expected 1 path to an LF file"); - } - var path = Paths.get(args[0]); - if (!Files.exists(path)) { - throw new FileNotFoundException("No such test file: " + path); - } + public static void main(String[] args) throws FileNotFoundException { + if (args.length != 1) { + throw new IllegalArgumentException("Expected 1 path to an LF file"); + } + var path = Paths.get(args[0]); + if (!Files.exists(path)) { + throw new FileNotFoundException("No such test file: " + path); + } - Matcher matcher = TEST_FILE_PATTERN.matcher(args[0]); - if (!matcher.matches()) { - throw new FileNotFoundException("Not a test: " + path); - } + Matcher matcher = TEST_FILE_PATTERN.matcher(args[0]); + if (!matcher.matches()) { + throw new FileNotFoundException("Not a test: " + path); + } - Target target = Target.forName(matcher.group(2)).get(); + Target target = Target.forName(matcher.group(2)).get(); - Class testClass = getTestInstance(target); + Class testClass = getTestInstance(target); - LFTest testCase = new LFTest(target, path.toAbsolutePath()); + LFTest testCase = new LFTest(target, path.toAbsolutePath()); - TestBase.runSingleTestAndPrintResults(testCase, testClass, TestBase.pathToLevel(path)); - } + TestBase.runSingleTestAndPrintResults(testCase, testClass, TestBase.pathToLevel(path)); + } - private static Class getTestInstance(Target target) { - switch (target) { - case C: - return CTest.class; - case CCPP: - return CCppTest.class; - case CPP: - return CppTest.class; - case TS: - return TypeScriptTest.class; - case Python: - return PythonTest.class; - case Rust: - return RustTest.class; - default: - throw new IllegalArgumentException(); - } + private static Class getTestInstance(Target target) { + switch (target) { + case C: + return CTest.class; + case CCPP: + return CCppTest.class; + case CPP: + return CppTest.class; + case TS: + return TypeScriptTest.class; + case Python: + return PythonTest.class; + case Rust: + return RustTest.class; + default: + throw new IllegalArgumentException(); } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java b/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java index 77bc6d8034..2dfd42d38b 100644 --- a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java +++ b/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java @@ -2,207 +2,216 @@ import java.util.EnumSet; import java.util.List; - import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; -import org.lflang.ast.ASTUtils; import org.lflang.Target; +import org.lflang.ast.ASTUtils; import org.lflang.tests.TestRegistry.TestCategory; /** * A collection of JUnit tests to perform on a given set of targets. * * @author Marten Lohstroh - * */ public abstract class RuntimeTest extends TestBase { - /** - * Construct a test instance that runs tests for a single target. - * - * @param target The target to run tests for. - */ - protected RuntimeTest(Target target) { - super(target); - } - - /** - * Construct a test instance that runs tests for a list of targets. - * @param targets The targets to run tests for. - */ - protected RuntimeTest(List targets) { - super(targets); - } - - /** - * Whether to enable {@link #runEnclaveTests()}. - */ - protected boolean supportsEnclaves() { return false; } - - /** - * Whether to enable {@link #runFederatedTests()}. - */ - protected boolean supportsFederatedExecution() { - return false; - } - - /** - * Whether to enable {@link #runTypeParameterTests()}. - */ - protected boolean supportsGenericTypes() { - return false; - } - - /** - * Whether to enable {@link #runDockerTests()} and {@link #runDockerFederatedTests()}. - */ - protected boolean supportsDockerOption() { - return false; - } - - @Test - public void runGenericTests() { - runTestsForTargets(Message.DESC_GENERIC, - TestCategory.GENERIC::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - @Test - public void runTargetSpecificTests() { - runTestsForTargets(Message.DESC_TARGET_SPECIFIC, - TestCategory.TARGET::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - @Test - public void runMultiportTests() { - runTestsForTargets(Message.DESC_MULTIPORT, - TestCategory.MULTIPORT::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - @Test - public void runTypeParameterTests() { - Assumptions.assumeTrue(supportsGenericTypes(), Message.NO_GENERICS_SUPPORT); - runTestsForTargets(Message.DESC_TYPE_PARMS, - TestCategory.GENERICS::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - @Test - public void runAsFederated() { - Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); - - EnumSet categories = EnumSet.allOf(TestCategory.class); - categories.removeAll(EnumSet.of(TestCategory.CONCURRENT, - TestCategory.FEDERATED, - // FIXME: also run the multiport tests once these are supported. - TestCategory.MULTIPORT)); - - runTestsFor(List.of(Target.C), - Message.DESC_AS_FEDERATED, - categories::contains, - it -> ASTUtils.makeFederated(it.getFileConfig().resource), - TestLevel.EXECUTION, - true); - } - - @Test - public void runConcurrentTests() { - runTestsForTargets(Message.DESC_CONCURRENT, - TestCategory.CONCURRENT::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - - } - - @Test - public void runFederatedTests() { - Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); - runTestsForTargets(Message.DESC_FEDERATED, - TestCategory.FEDERATED::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - /** - * Run the tests for modal reactors. - */ - @Test - public void runModalTests() { - runTestsForTargets(Message.DESC_MODAL, - TestCategory.MODAL_MODELS::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - /** - * Run the tests for non-inlined reaction bodies. - */ - @Test - public void runNoInliningTests() { - runTestsForTargets(Message.DESC_MODAL, - TestCategory.NO_INLINING::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - /** - * Run docker tests, provided that the platform is Linux and the target supports Docker. - * Skip if platform is not Linux or target does not support Docker. - */ - @Test - public void runDockerTests() { - Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); - Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); - runTestsForTargets(Message.DESC_DOCKER, - TestCategory.DOCKER::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - /** - * Run federated docker tests, provided that the platform is Linux, the target supports Docker, - * and the target supports federated execution. If any of these requirements are not met, skip - * the tests. - */ - @Test - public void runDockerFederatedTests() { - Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); - Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); - Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); - runTestsForTargets(Message.DESC_DOCKER_FEDERATED, - TestCategory.DOCKER_FEDERATED::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - - @Test - public void runWithThreadingOff() { - Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); - this.runTestsForTargets( - Message.DESC_SINGLE_THREADED, - Configurators::compatibleWithThreadingOff, - Configurators::disableThreading, - TestLevel.EXECUTION, - true - ); - } - - /** - * Run enclave tests if the target supports enclaves. - */ - @Test - public void runEnclaveTests() { - Assumptions.assumeTrue(supportsEnclaves(), Message.NO_ENCLAVE_SUPPORT); - runTestsForTargets(Message.DESC_ENCLAVE, - TestCategory.ENCLAVE::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - + /** + * Construct a test instance that runs tests for a single target. + * + * @param target The target to run tests for. + */ + protected RuntimeTest(Target target) { + super(target); + } + + /** + * Construct a test instance that runs tests for a list of targets. + * + * @param targets The targets to run tests for. + */ + protected RuntimeTest(List targets) { + super(targets); + } + + /** Whether to enable {@link #runEnclaveTests()}. */ + protected boolean supportsEnclaves() { + return false; + } + + /** Whether to enable {@link #runFederatedTests()}. */ + protected boolean supportsFederatedExecution() { + return false; + } + + /** Whether to enable {@link #runTypeParameterTests()}. */ + protected boolean supportsGenericTypes() { + return false; + } + + /** Whether to enable {@link #runDockerTests()} and {@link #runDockerFederatedTests()}. */ + protected boolean supportsDockerOption() { + return false; + } + + @Test + public void runGenericTests() { + runTestsForTargets( + Message.DESC_GENERIC, + TestCategory.GENERIC::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + @Test + public void runTargetSpecificTests() { + runTestsForTargets( + Message.DESC_TARGET_SPECIFIC, + TestCategory.TARGET::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + @Test + public void runMultiportTests() { + runTestsForTargets( + Message.DESC_MULTIPORT, + TestCategory.MULTIPORT::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + @Test + public void runTypeParameterTests() { + Assumptions.assumeTrue(supportsGenericTypes(), Message.NO_GENERICS_SUPPORT); + runTestsForTargets( + Message.DESC_TYPE_PARMS, + TestCategory.GENERICS::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + @Test + public void runAsFederated() { + Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); + + EnumSet categories = EnumSet.allOf(TestCategory.class); + categories.removeAll( + EnumSet.of( + TestCategory.CONCURRENT, + TestCategory.FEDERATED, + // FIXME: also run the multiport tests once these are supported. + TestCategory.MULTIPORT)); + + runTestsFor( + List.of(Target.C), + Message.DESC_AS_FEDERATED, + categories::contains, + it -> ASTUtils.makeFederated(it.getFileConfig().resource), + TestLevel.EXECUTION, + true); + } + + @Test + public void runConcurrentTests() { + runTestsForTargets( + Message.DESC_CONCURRENT, + TestCategory.CONCURRENT::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + @Test + public void runFederatedTests() { + Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); + runTestsForTargets( + Message.DESC_FEDERATED, + TestCategory.FEDERATED::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + /** Run the tests for modal reactors. */ + @Test + public void runModalTests() { + runTestsForTargets( + Message.DESC_MODAL, + TestCategory.MODAL_MODELS::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + /** Run the tests for non-inlined reaction bodies. */ + @Test + public void runNoInliningTests() { + runTestsForTargets( + Message.DESC_MODAL, + TestCategory.NO_INLINING::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + /** + * Run docker tests, provided that the platform is Linux and the target supports Docker. Skip if + * platform is not Linux or target does not support Docker. + */ + @Test + public void runDockerTests() { + Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); + Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); + runTestsForTargets( + Message.DESC_DOCKER, + TestCategory.DOCKER::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + /** + * Run federated docker tests, provided that the platform is Linux, the target supports Docker, + * and the target supports federated execution. If any of these requirements are not met, skip the + * tests. + */ + @Test + public void runDockerFederatedTests() { + Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); + Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); + Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); + runTestsForTargets( + Message.DESC_DOCKER_FEDERATED, + TestCategory.DOCKER_FEDERATED::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + + @Test + public void runWithThreadingOff() { + Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); + this.runTestsForTargets( + Message.DESC_SINGLE_THREADED, + Configurators::compatibleWithThreadingOff, + Configurators::disableThreading, + TestLevel.EXECUTION, + true); + } + + /** Run enclave tests if the target supports enclaves. */ + @Test + public void runEnclaveTests() { + Assumptions.assumeTrue(supportsEnclaves(), Message.NO_ENCLAVE_SUPPORT); + runTestsForTargets( + Message.DESC_ENCLAVE, + TestCategory.ENCLAVE::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 192a531828..9ae075780a 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -3,7 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.FileWriter; +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.google.inject.Provider; +import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; @@ -12,8 +16,6 @@ import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Path; -import java.io.File; -import java.io.BufferedWriter; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -24,7 +26,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import java.util.stream.Collectors; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource.Diagnostic; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -37,7 +38,6 @@ import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.DefaultErrorReporter; import org.lflang.FileConfig; import org.lflang.LFRuntimeModule; @@ -48,18 +48,11 @@ import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.generator.MainContext; -import org.lflang.generator.GeneratorCommandFactory; import org.lflang.tests.Configurators.Configurator; import org.lflang.tests.LFTest.Result; import org.lflang.tests.TestRegistry.TestCategory; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; -import org.lflang.util.ArduinoUtil; - - -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Provider; /** * Base class for test classes that define JUnit tests. @@ -70,501 +63,518 @@ @InjectWith(LFInjectorProvider.class) public abstract class TestBase { - @Inject - IResourceValidator validator; - @Inject - LFGenerator generator; - @Inject - JavaIoFileSystemAccess fileAccess; - @Inject - Provider resourceSetProvider; - - - /** Reference to System.out. */ - private static final PrintStream out = System.out; - - /** Reference to System.err. */ - private static final PrintStream err = System.err; - - /** Execution timeout enforced for all tests. */ - private static final long MAX_EXECUTION_TIME_SECONDS = 180; - - /** Content separator used in test output, 78 characters wide. */ - public static final String THIN_LINE = - "------------------------------------------------------------------------------" + - System.lineSeparator(); - - /** Content separator used in test output, 78 characters wide. */ - public static final String THICK_LINE = - "==============================================================================" + - System.lineSeparator(); - - /** The targets for which to run the tests. */ - private final List targets; - - /** - * An enumeration of test levels. - * @author Marten Lohstroh - * - */ - public enum TestLevel {VALIDATION, CODE_GEN, BUILD, EXECUTION} - - /** - * Static function for converting a path to its associated test level. - * @author Anirudh Rengarajan - */ - public static TestLevel pathToLevel(Path path) { - while(path.getParent() != null) { - String name = path.getFileName().toString(); - for (var category: TestCategory.values()) { - if (category.name().equalsIgnoreCase(name)) { - return category.level; - } - } - path = path.getParent(); + @Inject IResourceValidator validator; + @Inject LFGenerator generator; + @Inject JavaIoFileSystemAccess fileAccess; + @Inject Provider resourceSetProvider; + + /** Reference to System.out. */ + private static final PrintStream out = System.out; + + /** Reference to System.err. */ + private static final PrintStream err = System.err; + + /** Execution timeout enforced for all tests. */ + private static final long MAX_EXECUTION_TIME_SECONDS = 180; + + /** Content separator used in test output, 78 characters wide. */ + public static final String THIN_LINE = + "------------------------------------------------------------------------------" + + System.lineSeparator(); + + /** Content separator used in test output, 78 characters wide. */ + public static final String THICK_LINE = + "==============================================================================" + + System.lineSeparator(); + + /** The targets for which to run the tests. */ + private final List targets; + + /** + * An enumeration of test levels. + * + * @author Marten Lohstroh + */ + public enum TestLevel { + VALIDATION, + CODE_GEN, + BUILD, + EXECUTION + } + + /** + * Static function for converting a path to its associated test level. + * + * @author Anirudh Rengarajan + */ + public static TestLevel pathToLevel(Path path) { + while (path.getParent() != null) { + String name = path.getFileName().toString(); + for (var category : TestCategory.values()) { + if (category.name().equalsIgnoreCase(name)) { + return category.level; } - return TestLevel.EXECUTION; + } + path = path.getParent(); } - - /** - * A collection messages often used throughout the test package. - * - * @author Marten Lohstroh - * - */ - public static class Message { - /* Reasons for not running tests. */ - public static final String NO_WINDOWS_SUPPORT = "Not (yet) supported on Windows."; - public static final String NO_SINGLE_THREADED_SUPPORT = "Target does not support single-threaded execution."; - public static final String NO_FEDERATION_SUPPORT = "Target does not support federated execution."; - public static final String NO_ENCLAVE_SUPPORT = "Targeet does not support the enclave feature."; - public static final String NO_DOCKER_SUPPORT = "Target does not support the 'docker' property."; - public static final String NO_DOCKER_TEST_SUPPORT = "Docker tests are only supported on Linux."; - public static final String NO_GENERICS_SUPPORT = "Target does not support generic types."; - - /* Descriptions of collections of tests. */ - public static final String DESC_SERIALIZATION = "Run serialization tests."; - public static final String DESC_GENERIC = "Run generic tests."; - public static final String DESC_TYPE_PARMS = "Run tests for reactors with type parameters."; - public static final String DESC_MULTIPORT = "Run multiport tests."; - public static final String DESC_AS_FEDERATED = "Run non-federated tests in federated mode."; - public static final String DESC_FEDERATED = "Run federated tests."; - public static final String DESC_DOCKER = "Run docker tests."; - public static final String DESC_DOCKER_FEDERATED = "Run docker federated tests."; - public static final String DESC_ENCLAVE = "Run enclave tests."; - public static final String DESC_CONCURRENT = "Run concurrent tests."; - public static final String DESC_TARGET_SPECIFIC = "Run target-specific tests"; - public static final String DESC_ARDUINO = "Running Arduino tests."; - public static final String DESC_ZEPHYR = "Running Zephyr tests."; - public static final String DESC_AS_CCPP = "Running C tests as CCpp."; - public static final String DESC_SINGLE_THREADED = "Run non-concurrent and non-federated tests with threading = off."; - public static final String DESC_SCHED_SWAPPING = "Running with non-default runtime scheduler "; - public static final String DESC_ROS2 = "Running tests using ROS2."; - public static final String DESC_MODAL = "Run modal reactor tests."; - - /* Missing dependency messages */ - public static final String MISSING_DOCKER = "Executable 'docker' not found or 'docker' daemon thread not running"; - public static final String MISSING_ARDUINO_CLI = "Executable 'arduino-cli' not found"; + return TestLevel.EXECUTION; + } + + /** + * A collection messages often used throughout the test package. + * + * @author Marten Lohstroh + */ + public static class Message { + /* Reasons for not running tests. */ + public static final String NO_WINDOWS_SUPPORT = "Not (yet) supported on Windows."; + public static final String NO_SINGLE_THREADED_SUPPORT = + "Target does not support single-threaded execution."; + public static final String NO_FEDERATION_SUPPORT = + "Target does not support federated execution."; + public static final String NO_ENCLAVE_SUPPORT = "Targeet does not support the enclave feature."; + public static final String NO_DOCKER_SUPPORT = "Target does not support the 'docker' property."; + public static final String NO_DOCKER_TEST_SUPPORT = "Docker tests are only supported on Linux."; + public static final String NO_GENERICS_SUPPORT = "Target does not support generic types."; + + /* Descriptions of collections of tests. */ + public static final String DESC_SERIALIZATION = "Run serialization tests."; + public static final String DESC_GENERIC = "Run generic tests."; + public static final String DESC_TYPE_PARMS = "Run tests for reactors with type parameters."; + public static final String DESC_MULTIPORT = "Run multiport tests."; + public static final String DESC_AS_FEDERATED = "Run non-federated tests in federated mode."; + public static final String DESC_FEDERATED = "Run federated tests."; + public static final String DESC_DOCKER = "Run docker tests."; + public static final String DESC_DOCKER_FEDERATED = "Run docker federated tests."; + public static final String DESC_ENCLAVE = "Run enclave tests."; + public static final String DESC_CONCURRENT = "Run concurrent tests."; + public static final String DESC_TARGET_SPECIFIC = "Run target-specific tests"; + public static final String DESC_ARDUINO = "Running Arduino tests."; + public static final String DESC_ZEPHYR = "Running Zephyr tests."; + public static final String DESC_AS_CCPP = "Running C tests as CCpp."; + public static final String DESC_SINGLE_THREADED = + "Run non-concurrent and non-federated tests with threading = off."; + public static final String DESC_SCHED_SWAPPING = "Running with non-default runtime scheduler "; + public static final String DESC_ROS2 = "Running tests using ROS2."; + public static final String DESC_MODAL = "Run modal reactor tests."; + + /* Missing dependency messages */ + public static final String MISSING_DOCKER = + "Executable 'docker' not found or 'docker' daemon thread not running"; + public static final String MISSING_ARDUINO_CLI = "Executable 'arduino-cli' not found"; + } + + /** Constructor for test classes that test a single target. */ + protected TestBase(Target first) { + this(Collections.singletonList(first)); + } + + /** Special ctor for the code coverage test */ + protected TestBase(List targets) { + assertFalse(targets.isEmpty(), "empty target list"); + this.targets = Collections.unmodifiableList(targets); + TestRegistry.initialize(); + } + + /** + * Run selected tests for a given target and configurator up to the specified level. + * + * @param target The target to run tests for. + * @param selected A predicate that given a test category returns whether it should be included in + * this test run or not. + * @param configurator A procedure for configuring the tests. + * @param copy Whether or not to work on copies of tests in the test. registry. + */ + protected final void runTestsAndPrintResults( + Target target, + Predicate selected, + TestLevel level, + Configurator configurator, + boolean copy) { + var categories = Arrays.stream(TestCategory.values()).filter(selected).toList(); + for (var category : categories) { + System.out.println(category.getHeader()); + var tests = TestRegistry.getRegisteredTests(target, category, copy); + try { + validateAndRun(tests, configurator, level); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + System.out.println(TestRegistry.getCoverageReport(target, category)); + checkAndReportFailures(tests); } - - /** Constructor for test classes that test a single target. */ - protected TestBase(Target first) { - this(Collections.singletonList(first)); + } + + /** + * Run tests in the given selection for all targets enabled in this class. + * + * @param description A string that describes the collection of tests. + * @param selected A predicate that given a test category returns whether it should be included in + * this test run or not. + * @param configurator A procedure for configuring the tests. + * @param copy Whether or not to work on copies of tests in the test. registry. + */ + protected void runTestsForTargets( + String description, + Predicate selected, + Configurator configurator, + TestLevel level, + boolean copy) { + for (Target target : this.targets) { + runTestsFor(List.of(target), description, selected, configurator, level, copy); } - - /** Special ctor for the code coverage test */ - protected TestBase(List targets) { - assertFalse(targets.isEmpty(), "empty target list"); - this.targets = Collections.unmodifiableList(targets); - TestRegistry.initialize(); + } + + /** + * Run tests in the given selection for a subset of given targets. + * + * @param subset The subset of targets to run the selected tests for. + * @param description A string that describes the collection of tests. + * @param selected A predicate that given a test category returns whether it should be included in + * this test run or not. + * @param configurator A procedure for configuring the tests. + * @param copy Whether to work on copies of tests in the test. registry. + */ + protected void runTestsFor( + List subset, + String description, + Predicate selected, + Configurator configurator, + TestLevel level, + boolean copy) { + for (Target target : subset) { + printTestHeader(target, description); + runTestsAndPrintResults(target, selected, level, configurator, copy); } - - /** - * Run selected tests for a given target and configurator up to the specified level. - * - * @param target The target to run tests for. - * @param selected A predicate that given a test category returns whether - * it should be included in this test run or not. - * @param configurator A procedure for configuring the tests. - * @param copy Whether or not to work on copies of tests in the test. - * registry. - */ - protected final void runTestsAndPrintResults(Target target, - Predicate selected, - TestLevel level, - Configurator configurator, - boolean copy) { - var categories = Arrays.stream(TestCategory.values()).filter(selected).toList(); - for (var category : categories) { - System.out.println(category.getHeader()); - var tests = TestRegistry.getRegisteredTests(target, category, copy); - try { - validateAndRun(tests, configurator, level); - } catch (IOException e) { - throw new RuntimeIOException(e); - } - System.out.println(TestRegistry.getCoverageReport(target, category)); - checkAndReportFailures(tests); - } + } + + /** Whether to enable threading. */ + protected boolean supportsSingleThreadedExecution() { + return false; + } + + /** + * Determine whether the current platform is Windows. + * + * @return true if the current platform is Windwos, false otherwise. + */ + protected static boolean isWindows() { + String OS = System.getProperty("os.name").toLowerCase(); + return OS.contains("win"); + } + + /** + * Determine whether the current platform is MacOS. + * + * @return true if the current platform is MacOS, false otherwise. + */ + protected static boolean isMac() { + String OS = System.getProperty("os.name").toLowerCase(); + return OS.contains("mac"); + } + + /** + * Determine whether the current platform is Linux. + * + * @return true if the current platform is Linux, false otherwise. + */ + protected static boolean isLinux() { + String OS = System.getProperty("os.name").toLowerCase(); + return OS.contains("linux"); + } + + /** End output redirection. */ + private static void restoreOutputs() { + System.out.flush(); + System.err.flush(); + System.setOut(out); + System.setErr(err); + } + + /** + * Redirect outputs to the given tests for recording. + * + * @param test The test to redirect outputs to. + */ + private static void redirectOutputs(LFTest test) { + System.setOut(new PrintStream(test.getOutputStream())); + System.setErr(new PrintStream(test.getOutputStream())); + } + + /** + * Run a test, print results on stderr. + * + * @param test Test case. + * @param testClass The test class that will execute the test. This is target-specific, it may + * provide some target-specific configuration. We pass a class and not a new instance because + * this method needs to ensure the object is properly injected, and so, it needs to control + * its entire lifecycle. + * @param level Level to which to run the test. + */ + public static void runSingleTestAndPrintResults( + LFTest test, Class testClass, TestLevel level) { + Injector injector = + new LFStandaloneSetup(new LFRuntimeModule()).createInjectorAndDoEMFRegistration(); + TestBase runner; + try { + @SuppressWarnings("unchecked") + Constructor constructor = + (Constructor) testClass.getConstructors()[0]; + runner = constructor.newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException(e); } + injector.injectMembers(runner); - /** - * Run tests in the given selection for all targets enabled in this class. - * - * @param description A string that describes the collection of tests. - * @param selected A predicate that given a test category returns whether - * it should be included in this test run or not. - * @param configurator A procedure for configuring the tests. - * @param copy Whether or not to work on copies of tests in the test. - * registry. - */ - protected void runTestsForTargets(String description, - Predicate selected, - Configurator configurator, - TestLevel level, - boolean copy) { - for (Target target : this.targets) { - runTestsFor(List.of(target), description, selected, - configurator, level, copy); - } + Set tests = Set.of(test); + try { + runner.validateAndRun(tests, t -> true, level); + } catch (IOException e) { + throw new RuntimeIOException(e); } - - /** - * Run tests in the given selection for a subset of given targets. - * - * @param subset The subset of targets to run the selected tests for. - * @param description A string that describes the collection of tests. - * @param selected A predicate that given a test category returns whether - * it should be included in this test run or not. - * @param configurator A procedure for configuring the tests. - * @param copy Whether to work on copies of tests in the test. - * registry. - */ - protected void runTestsFor(List subset, - String description, - Predicate selected, - Configurator configurator, - TestLevel level, - boolean copy) { - for (Target target : subset) { - printTestHeader(target, description); - runTestsAndPrintResults(target, selected, level, configurator, copy); - } + checkAndReportFailures(tests); + } + + /** + * Print a header that describes a collection of tests. + * + * @param target The target for which the tests are being performed. + * @param description A string the describes the collection of tests. + */ + protected static void printTestHeader(Target target, String description) { + System.out.print(TestBase.THICK_LINE); + System.out.println("Target: " + target); + if (description.startsWith("Description: ")) { + System.out.println(description); + } else { + System.out.println("Description: " + description); } - - /** - * Whether to enable threading. - */ - protected boolean supportsSingleThreadedExecution() { - return false; + System.out.println(TestBase.THICK_LINE); + } + + /** + * Iterate over given tests and evaluate their outcome, report errors if there are any. + * + * @param tests The tests to inspect the results of. + */ + private static void checkAndReportFailures(Set tests) { + var passed = tests.stream().filter(it -> it.hasPassed()).collect(Collectors.toList()); + var s = new StringBuffer(); + s.append(THIN_LINE); + s.append("Passing: " + passed.size() + "/" + tests.size() + "\n"); + s.append(THIN_LINE); + passed.forEach(test -> s.append("Passed: ").append(test).append("\n")); + s.append(THIN_LINE); + System.out.print(s.toString()); + + for (var test : tests) { + test.reportErrors(); } - - /** - * Determine whether the current platform is Windows. - * @return true if the current platform is Windwos, false otherwise. - */ - protected static boolean isWindows() { - String OS = System.getProperty("os.name").toLowerCase(); - return OS.contains("win"); - } - - /** - * Determine whether the current platform is MacOS. - * @return true if the current platform is MacOS, false otherwise. - */ - protected static boolean isMac() { - String OS = System.getProperty("os.name").toLowerCase(); - return OS.contains("mac"); - } - - /** - * Determine whether the current platform is Linux. - * @return true if the current platform is Linux, false otherwise. - */ - protected static boolean isLinux() { - String OS = System.getProperty("os.name").toLowerCase(); - return OS.contains("linux"); + for (LFTest lfTest : tests) { + assertTrue(lfTest.hasPassed()); } - - /** - * End output redirection. - */ - private static void restoreOutputs() { - System.out.flush(); - System.err.flush(); - System.setOut(out); - System.setErr(err); + } + + /** + * Configure a test by applying the given configurator and return a generator context. Also, if + * the given level is less than {@code TestLevel.BUILD}, add a {@code no-compile} flag to the + * generator context. If the configurator was not applied successfully, throw an AssertionError. + * + * @param test the test to configure. + * @param configurator The configurator to apply to the test. + * @param level The level of testing in which the generator context will be used. + */ + private void configure(LFTest test, Configurator configurator, TestLevel level) + throws IOException, TestError { + var props = new Properties(); + props.setProperty("hierarchical-bin", "true"); + addExtraLfcArgs(props); + + var sysProps = System.getProperties(); + // Set the external-runtime-path property if it was specified. + if (sysProps.containsKey("runtime")) { + var rt = sysProps.get("runtime").toString(); + if (!rt.isEmpty()) { + props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), rt); + System.out.println("Using runtime: " + sysProps.get("runtime").toString()); + } + } else { + System.out.println("Using default runtime."); } - /** - * Redirect outputs to the given tests for recording. - * - * @param test The test to redirect outputs to. - */ - private static void redirectOutputs(LFTest test) { - System.setOut(new PrintStream(test.getOutputStream())); - System.setErr(new PrintStream(test.getOutputStream())); + var r = + resourceSetProvider + .get() + .getResource(URI.createFileURI(test.getSrcPath().toFile().getAbsolutePath()), true); + + if (r.getErrors().size() > 0) { + String message = + r.getErrors().stream() + .map(Diagnostic::toString) + .collect(Collectors.joining(System.lineSeparator())); + throw new TestError(message, Result.PARSE_FAIL); } - - /** - * Run a test, print results on stderr. - * - * @param test Test case. - * @param testClass The test class that will execute the test. This is target-specific, - * it may provide some target-specific configuration. We pass a class - * and not a new instance because this method needs to ensure the object - * is properly injected, and so, it needs to control its entire lifecycle. - * @param level Level to which to run the test. - */ - public static void runSingleTestAndPrintResults(LFTest test, Class testClass, TestLevel level) { - Injector injector = new LFStandaloneSetup(new LFRuntimeModule()).createInjectorAndDoEMFRegistration(); - TestBase runner; - try { - @SuppressWarnings("unchecked") - Constructor constructor = (Constructor) testClass.getConstructors()[0]; - runner = constructor.newInstance(); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new IllegalStateException(e); - } - injector.injectMembers(runner); - - Set tests = Set.of(test); - try { - runner.validateAndRun(tests, t -> true, level); - } catch (IOException e) { - throw new RuntimeIOException(e); - } - checkAndReportFailures(tests); + fileAccess.setOutputPath( + FileConfig.findPackageRoot(test.getSrcPath(), s -> {}) + .resolve(FileConfig.DEFAULT_SRC_GEN_DIR) + .toString()); + var context = + new MainContext( + LFGeneratorContext.Mode.STANDALONE, + CancelIndicator.NullImpl, + (m, p) -> {}, + props, + r, + fileAccess, + fileConfig -> new DefaultErrorReporter()); + + test.configure(context); + + // Set the no-compile flag the test is not supposed to reach the build stage. + if (level.compareTo(TestLevel.BUILD) < 0) { + context.getArgs().setProperty("no-compile", ""); } - /** - * Print a header that describes a collection of tests. - * @param target The target for which the tests are being performed. - * @param description A string the describes the collection of tests. - */ - protected static void printTestHeader(Target target, String description) { - System.out.print(TestBase.THICK_LINE); - System.out.println("Target: " + target); - if (description.startsWith("Description: ")) { - System.out.println(description); - } else { - System.out.println("Description: " + description); - } - System.out.println(TestBase.THICK_LINE); + // Reload in case target properties have changed. + context.loadTargetConfig(); + // Update the test by applying the configuration. E.g., to carry out an AST transformation. + if (configurator != null) { + if (!configurator.configure(test)) { + throw new TestError("Test configuration unsuccessful.", Result.CONFIG_FAIL); + } } - - /** - * Iterate over given tests and evaluate their outcome, report errors if - * there are any. - * - * @param tests The tests to inspect the results of. - */ - private static void checkAndReportFailures(Set tests) { - var passed = tests.stream().filter(it -> it.hasPassed()).collect(Collectors.toList()); - var s = new StringBuffer(); - s.append(THIN_LINE); - s.append("Passing: " + passed.size() + "/" + tests.size() + "\n"); - s.append(THIN_LINE); - passed.forEach(test -> s.append("Passed: ").append(test).append("\n")); - s.append(THIN_LINE); - System.out.print(s.toString()); - - for (var test : tests) { - test.reportErrors(); - } - for (LFTest lfTest : tests) { - assertTrue(lfTest.hasPassed()); + } + + /** Validate the given test. Throw an TestError if validation failed. */ + private void validate(LFTest test) throws TestError { + // Validate the resource and store issues in the test object. + try { + var context = test.getContext(); + var issues = + validator.validate( + context.getFileConfig().resource, CheckMode.ALL, context.getCancelIndicator()); + if (issues != null && !issues.isEmpty()) { + if (issues.stream().anyMatch(it -> it.getSeverity() == Severity.ERROR)) { + String message = + issues.stream() + .map(Objects::toString) + .collect(Collectors.joining(System.lineSeparator())); + throw new TestError(message, Result.VALIDATE_FAIL); } + } + } catch (TestError e) { + throw e; + } catch (Throwable e) { + throw new TestError("Exception during validation.", Result.VALIDATE_FAIL, e); } - - /** - * Configure a test by applying the given configurator and return a - * generator context. Also, if the given level is less than - * {@code TestLevel.BUILD}, add a {@code no-compile} flag to the generator context. If - * the configurator was not applied successfully, throw an AssertionError. - * - * @param test the test to configure. - * @param configurator The configurator to apply to the test. - * @param level The level of testing in which the generator context will be - * used. - */ - private void configure(LFTest test, Configurator configurator, TestLevel level) throws IOException, TestError { - var props = new Properties(); - props.setProperty("hierarchical-bin", "true"); - addExtraLfcArgs(props); - - var sysProps = System.getProperties(); - // Set the external-runtime-path property if it was specified. - if (sysProps.containsKey("runtime")) { - var rt = sysProps.get("runtime").toString(); - if (!rt.isEmpty()) { - props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), rt); - System.out.println("Using runtime: " + sysProps.get("runtime").toString()); - } - } else { - System.out.println("Using default runtime."); - } - - var r = resourceSetProvider.get().getResource( - URI.createFileURI(test.getSrcPath().toFile().getAbsolutePath()), - true); - - if (r.getErrors().size() > 0) { - String message = r.getErrors().stream().map(Diagnostic::toString).collect(Collectors.joining(System.lineSeparator())); - throw new TestError(message, Result.PARSE_FAIL); - } - - fileAccess.setOutputPath(FileConfig.findPackageRoot(test.getSrcPath(), s -> {}).resolve(FileConfig.DEFAULT_SRC_GEN_DIR).toString()); - var context = new MainContext( - LFGeneratorContext.Mode.STANDALONE, CancelIndicator.NullImpl, (m, p) -> {}, props, r, fileAccess, - fileConfig -> new DefaultErrorReporter() - ); - - test.configure(context); - - // Set the no-compile flag the test is not supposed to reach the build stage. - if (level.compareTo(TestLevel.BUILD) < 0) { - context.getArgs().setProperty("no-compile", ""); - } - - // Reload in case target properties have changed. - context.loadTargetConfig(); - // Update the test by applying the configuration. E.g., to carry out an AST transformation. - if (configurator != null) { - if (!configurator.configure(test)) { - throw new TestError("Test configuration unsuccessful.", Result.CONFIG_FAIL); - } - } + } + + /** Override to add some LFC arguments to all runs of this test class. */ + protected void addExtraLfcArgs(Properties args) { + args.setProperty("build-type", "Test"); + args.setProperty("logging", "Debug"); + } + + /** + * Invoke the code generator for the given test. + * + * @param test The test to generate code for. + */ + private GeneratorResult generateCode(LFTest test) throws TestError { + if (test.getFileConfig().resource == null) { + return GeneratorResult.NOTHING; } - - /** - * Validate the given test. Throw an TestError if validation failed. - */ - private void validate(LFTest test) throws TestError { - // Validate the resource and store issues in the test object. - try { - var context = test.getContext(); - var issues = validator.validate(context.getFileConfig().resource, - CheckMode.ALL, context.getCancelIndicator()); - if (issues != null && !issues.isEmpty()) { - if (issues.stream().anyMatch(it -> it.getSeverity() == Severity.ERROR)) { - String message = issues.stream().map(Objects::toString).collect(Collectors.joining(System.lineSeparator())); - throw new TestError(message, Result.VALIDATE_FAIL); - } - } - } catch (TestError e) { - throw e; - } catch (Throwable e) { - throw new TestError("Exception during validation.", Result.VALIDATE_FAIL, e); - } + try { + generator.doGenerate(test.getFileConfig().resource, fileAccess, test.getContext()); + } catch (Throwable e) { + throw new TestError("Code generation unsuccessful.", Result.CODE_GEN_FAIL, e); } - - - /** - * Override to add some LFC arguments to all runs of this test class. - */ - protected void addExtraLfcArgs(Properties args) { - args.setProperty("build-type", "Test"); - args.setProperty("logging", "Debug"); + if (generator.errorsOccurred()) { + throw new TestError("Code generation unsuccessful.", Result.CODE_GEN_FAIL); } - /** - * Invoke the code generator for the given test. - * - * @param test The test to generate code for. - */ - private GeneratorResult generateCode(LFTest test) throws TestError { - if (test.getFileConfig().resource == null) { - return GeneratorResult.NOTHING; - } - try { - generator.doGenerate(test.getFileConfig().resource, fileAccess, test.getContext()); - } catch (Throwable e) { - throw new TestError("Code generation unsuccessful.", Result.CODE_GEN_FAIL, e); - } - if (generator.errorsOccurred()) { - throw new TestError("Code generation unsuccessful.", Result.CODE_GEN_FAIL); + return test.getContext().getResult(); + } + + /** + * Given an indexed test, execute it and label the test as failing if it did not execute, took too + * long to execute, or executed but exited with an error code. + */ + private void execute(LFTest test) throws TestError { + final var pb = getExecCommand(test); + try { + var p = pb.start(); + var stdout = test.recordStdOut(p); + var stderr = test.recordStdErr(p); + + var stdoutException = new AtomicReference(null); + var stderrException = new AtomicReference(null); + + stdout.setUncaughtExceptionHandler((thread, throwable) -> stdoutException.set(throwable)); + stderr.setUncaughtExceptionHandler((thread, throwable) -> stderrException.set(throwable)); + + stderr.start(); + stdout.start(); + + if (!p.waitFor(MAX_EXECUTION_TIME_SECONDS, TimeUnit.SECONDS)) { + stdout.interrupt(); + stderr.interrupt(); + p.destroyForcibly(); + throw new TestError(Result.TEST_TIMEOUT); + } else { + if (stdoutException.get() != null || stderrException.get() != null) { + StringBuffer sb = new StringBuffer(); + if (stdoutException.get() != null) { + sb.append("Error during stdout handling:" + System.lineSeparator()); + sb.append(stackTraceToString(stdoutException.get())); + } + if (stderrException.get() != null) { + sb.append("Error during stderr handling:" + System.lineSeparator()); + sb.append(stackTraceToString(stderrException.get())); + } + throw new TestError(sb.toString(), Result.TEST_EXCEPTION); } - - return test.getContext().getResult(); - } - - - /** - * Given an indexed test, execute it and label the test as failing if it - * did not execute, took too long to execute, or executed but exited with - * an error code. - */ - private void execute(LFTest test) throws TestError { - final var pb = getExecCommand(test); - try { - var p = pb.start(); - var stdout = test.recordStdOut(p); - var stderr = test.recordStdErr(p); - - var stdoutException = new AtomicReference(null); - var stderrException = new AtomicReference(null); - - stdout.setUncaughtExceptionHandler((thread, throwable) -> stdoutException.set(throwable)); - stderr.setUncaughtExceptionHandler((thread, throwable) -> stderrException.set(throwable)); - - stderr.start(); - stdout.start(); - - if (!p.waitFor(MAX_EXECUTION_TIME_SECONDS, TimeUnit.SECONDS)) { - stdout.interrupt(); - stderr.interrupt(); - p.destroyForcibly(); - throw new TestError(Result.TEST_TIMEOUT); - } else { - if (stdoutException.get() != null || stderrException.get() != null) { - StringBuffer sb = new StringBuffer(); - if (stdoutException.get() != null) { - sb.append("Error during stdout handling:" + System.lineSeparator()); - sb.append(stackTraceToString(stdoutException.get())); - } - if (stderrException.get() != null) { - sb.append("Error during stderr handling:" + System.lineSeparator()); - sb.append(stackTraceToString(stderrException.get())); - } - throw new TestError(sb.toString(), Result.TEST_EXCEPTION); - } - if (p.exitValue() != 0) { - String message = "Exit code: " + p.exitValue(); - if (p.exitValue() == 139) { - // The java ProcessBuilder and Process interface does not allow us to reliably retrieve stderr and stdout - // from a process that segfaults. We can only print a message indicating that the putput is incomplete. - message += System.lineSeparator() + - "This exit code typically indicates a segfault. In this case, the execution output is likely missing or incomplete."; - } - throw new TestError(message, Result.TEST_FAIL); - } - } - } catch (TestError e) { - throw e; - } catch (Throwable e) { - e.printStackTrace(); - throw new TestError("Exception during test execution.", Result.TEST_EXCEPTION, e); + if (p.exitValue() != 0) { + String message = "Exit code: " + p.exitValue(); + if (p.exitValue() == 139) { + // The java ProcessBuilder and Process interface does not allow us to reliably retrieve + // stderr and stdout + // from a process that segfaults. We can only print a message indicating that the putput + // is incomplete. + message += + System.lineSeparator() + + "This exit code typically indicates a segfault. In this case, the execution" + + " output is likely missing or incomplete."; + } + throw new TestError(message, Result.TEST_FAIL); } + } + } catch (TestError e) { + throw e; + } catch (Throwable e) { + e.printStackTrace(); + throw new TestError("Exception during test execution.", Result.TEST_EXCEPTION, e); } - - static public String stackTraceToString(Throwable t) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - pw.flush(); - pw.close(); - return sw.toString(); - } - - /** Bash script that is used to execute docker tests. */ - static private String DOCKER_RUN_SCRIPT = """ + } + + public static String stackTraceToString(Throwable t) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + pw.flush(); + pw.close(); + return sw.toString(); + } + + /** Bash script that is used to execute docker tests. */ + private static String DOCKER_RUN_SCRIPT = + """ #!/bin/bash # 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 @@ -583,129 +593,128 @@ static public String stackTraceToString(Throwable t) { exit 0 """; - /** - * Path to a bash script containing DOCKER_RUN_SCRIPT. - */ - private static Path dockerRunScript = null; - - /** - * Return the path to a bash script containing DOCKER_RUN_SCRIPT. - * - * If the script does not yet exist, it is created. - */ - private Path getDockerRunScript() throws TestError { - if (dockerRunScript != null) { - return dockerRunScript; - } - - try { - var file = File.createTempFile("run_docker_test", "sh"); - file.deleteOnExit(); - file.setExecutable(true); - var path = file.toPath(); - try (BufferedWriter writer = Files.newBufferedWriter(path)) { - writer.write(DOCKER_RUN_SCRIPT); - } - dockerRunScript = path; - } catch (IOException e) { - throw new TestError("IO Error during test preparation.", Result.TEST_EXCEPTION, e); - } - - return dockerRunScript; + /** Path to a bash script containing DOCKER_RUN_SCRIPT. */ + private static Path dockerRunScript = null; + + /** + * Return the path to a bash script containing DOCKER_RUN_SCRIPT. + * + *

    If the script does not yet exist, it is created. + */ + private Path getDockerRunScript() throws TestError { + if (dockerRunScript != null) { + return dockerRunScript; } - /** - * Throws TestError if docker does not exist. Does nothing otherwise. - */ - private void checkDockerExists() throws TestError { - if (LFCommand.get("docker", List.of()) == null) { - throw new TestError("Executable 'docker' not found" , Result.NO_EXEC_FAIL); - } - if (LFCommand.get("docker-compose", List.of()) == null) { - throw new TestError("Executable 'docker-compose' not found" , Result.NO_EXEC_FAIL); - } + try { + var file = File.createTempFile("run_docker_test", "sh"); + file.deleteOnExit(); + file.setExecutable(true); + var path = file.toPath(); + try (BufferedWriter writer = Files.newBufferedWriter(path)) { + writer.write(DOCKER_RUN_SCRIPT); + } + dockerRunScript = path; + } catch (IOException e) { + throw new TestError("IO Error during test preparation.", Result.TEST_EXCEPTION, e); } - /** - * Return a ProcessBuilder used to test the docker execution. - * @param test The test to get the execution command for. - */ - private ProcessBuilder getDockerExecCommand(LFTest test) throws TestError { - checkDockerExists(); - var srcGenPath = test.getFileConfig().getSrcGenPath(); - var dockerComposeFile = FileUtil.globFilesEndsWith(srcGenPath, "docker-compose.yml").get(0); - return new ProcessBuilder(getDockerRunScript().toString(), dockerComposeFile.toString()); - } + return dockerRunScript; + } - /** - * Return a preconfigured ProcessBuilder for executing the test program. - * @param test The test to get the execution command for. - */ - private ProcessBuilder getExecCommand(LFTest test) throws TestError { - - var srcBasePath = test.getFileConfig().srcPkgPath.resolve("src"); - var relativePathName = srcBasePath.relativize(test.getFileConfig().srcPath).toString(); - - // special case to test docker file generation - if (relativePathName.equalsIgnoreCase(TestCategory.DOCKER.getPath()) || - relativePathName.equalsIgnoreCase(TestCategory.DOCKER_FEDERATED.getPath())) { - return getDockerExecCommand(test); - } else { - LFCommand command = test.getFileConfig().getCommand(); - if (command == null) { - throw new TestError("File: " + test.getFileConfig().getExecutable(), Result.NO_EXEC_FAIL); - } - return new ProcessBuilder(command.command()).directory(command.directory()); - } + /** Throws TestError if docker does not exist. Does nothing otherwise. */ + private void checkDockerExists() throws TestError { + if (LFCommand.get("docker", List.of()) == null) { + throw new TestError("Executable 'docker' not found", Result.NO_EXEC_FAIL); } - - /** - * Validate and run the given tests, using the specified configuratator and level. - * - * While performing tests, this method prints a header that reaches completion - * once all tests have been run. - * - * @param tests A set of tests to run. - * @param configurator A procedure for configuring the tests. - * @param level The level of testing. - * @throws IOException If initial file configuration fails - */ - private void validateAndRun(Set tests, Configurator configurator, TestLevel level) throws IOException { - final var x = 78f / tests.size(); - var marks = 0; - var done = 0; - - for (var test : tests) { - try { - redirectOutputs(test); - configure(test, configurator, level); - validate(test); - if (level.compareTo(TestLevel.CODE_GEN) >= 0) { - generateCode(test); - } - if (level == TestLevel.EXECUTION) { - execute(test); - } - test.markPassed(); - } catch (TestError e) { - test.handleTestError(e); - } catch (Throwable e) { - test.handleTestError(new TestError( - "Unknown exception during test execution", Result.TEST_EXCEPTION, e)); - } finally { - restoreOutputs(); - } - done++; - while (Math.floor(done * x) >= marks && marks < 78) { - System.out.print("="); - marks++; - } + if (LFCommand.get("docker-compose", List.of()) == null) { + throw new TestError("Executable 'docker-compose' not found", Result.NO_EXEC_FAIL); + } + } + + /** + * Return a ProcessBuilder used to test the docker execution. + * + * @param test The test to get the execution command for. + */ + private ProcessBuilder getDockerExecCommand(LFTest test) throws TestError { + checkDockerExists(); + var srcGenPath = test.getFileConfig().getSrcGenPath(); + var dockerComposeFile = FileUtil.globFilesEndsWith(srcGenPath, "docker-compose.yml").get(0); + return new ProcessBuilder(getDockerRunScript().toString(), dockerComposeFile.toString()); + } + + /** + * Return a preconfigured ProcessBuilder for executing the test program. + * + * @param test The test to get the execution command for. + */ + private ProcessBuilder getExecCommand(LFTest test) throws TestError { + + var srcBasePath = test.getFileConfig().srcPkgPath.resolve("src"); + var relativePathName = srcBasePath.relativize(test.getFileConfig().srcPath).toString(); + + // special case to test docker file generation + if (relativePathName.equalsIgnoreCase(TestCategory.DOCKER.getPath()) + || relativePathName.equalsIgnoreCase(TestCategory.DOCKER_FEDERATED.getPath())) { + return getDockerExecCommand(test); + } else { + LFCommand command = test.getFileConfig().getCommand(); + if (command == null) { + throw new TestError("File: " + test.getFileConfig().getExecutable(), Result.NO_EXEC_FAIL); + } + return new ProcessBuilder(command.command()).directory(command.directory()); + } + } + + /** + * Validate and run the given tests, using the specified configuratator and level. + * + *

    While performing tests, this method prints a header that reaches completion once all tests + * have been run. + * + * @param tests A set of tests to run. + * @param configurator A procedure for configuring the tests. + * @param level The level of testing. + * @throws IOException If initial file configuration fails + */ + private void validateAndRun(Set tests, Configurator configurator, TestLevel level) + throws IOException { + final var x = 78f / tests.size(); + var marks = 0; + var done = 0; + + for (var test : tests) { + try { + redirectOutputs(test); + configure(test, configurator, level); + validate(test); + if (level.compareTo(TestLevel.CODE_GEN) >= 0) { + generateCode(test); } - while (marks < 78) { - System.out.print("="); - marks++; + if (level == TestLevel.EXECUTION) { + execute(test); } - - System.out.print(System.lineSeparator()); + test.markPassed(); + } catch (TestError e) { + test.handleTestError(e); + } catch (Throwable e) { + test.handleTestError( + new TestError("Unknown exception during test execution", Result.TEST_EXCEPTION, e)); + } finally { + restoreOutputs(); + } + done++; + while (Math.floor(done * x) >= marks && marks < 78) { + System.out.print("="); + marks++; + } } + while (marks < 78) { + System.out.print("="); + marks++; + } + + System.out.print(System.lineSeparator()); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/TestError.java b/org.lflang.tests/src/org/lflang/tests/TestError.java index 0c261c6865..efb7d50048 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestError.java +++ b/org.lflang.tests/src/org/lflang/tests/TestError.java @@ -5,24 +5,28 @@ /// Indicates an error during test execution public class TestError extends Exception { - private Throwable exception; - private Result result; - - public TestError(String errorMessage, Result result, Throwable exception) { - super(errorMessage); - this.exception = exception; - this.result = result; - } - - public TestError(String errorMessage, Result result) { - this(errorMessage, result, null); - } - - public TestError(Result result) { - this(null, result, null); - } - - public Result getResult() {return result;} - - public Throwable getException() {return exception;} + private Throwable exception; + private Result result; + + public TestError(String errorMessage, Result result, Throwable exception) { + super(errorMessage); + this.exception = exception; + this.result = result; + } + + public TestError(String errorMessage, Result result) { + this(errorMessage, result, null); + } + + public TestError(Result result) { + this(null, result, null); + } + + public Result getResult() { + return result; + } + + public Throwable getException() { + return exception; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java index 1249ea25be..2c59740e0a 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java +++ b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java @@ -18,12 +18,10 @@ import java.util.Set; import java.util.Stack; import java.util.TreeSet; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.xtext.xbase.lib.IteratorExtensions; - import org.lflang.LFResourceProvider; import org.lflang.LFStandaloneSetup; import org.lflang.Target; @@ -37,378 +35,349 @@ */ public class TestRegistry { - static class TestMap { - /** - * Registry that maps targets to maps from categories to sets of tests. - */ - protected final Map>> map = new HashMap<>(); - - /** - * Create a new test map. - */ - public TestMap() { - // Populate the internal datastructures. - for (Target target : Target.values()) { - Map> categories = new HashMap<>(); - for (TestCategory cat : TestCategory.values()) { - categories.put(cat, new TreeSet<>()); - } - map.put(target, categories); - } - } - - /** - * Return a set of tests given a target and test category. - * @param t The target. - * @param c The test category. - * @return A set of tests for the given target and test category. - */ - public Set getTests(Target t, TestCategory c) { - return this.map.get(t).get(c); + static class TestMap { + /** Registry that maps targets to maps from categories to sets of tests. */ + protected final Map>> map = new HashMap<>(); + + /** Create a new test map. */ + public TestMap() { + // Populate the internal datastructures. + for (Target target : Target.values()) { + Map> categories = new HashMap<>(); + for (TestCategory cat : TestCategory.values()) { + categories.put(cat, new TreeSet<>()); } + map.put(target, categories); + } } /** - * List of directories that should be skipped when indexing test files. Any - * test file that has a directory in its path that matches an entry in this - * array will not be discovered. - */ - public static final String[] IGNORED_DIRECTORIES = {"failing", "knownfailed", "failed", "fed-gen"}; - - /** - * Path to the root of the repository. - */ - public static final Path LF_REPO_PATH = Paths.get("").toAbsolutePath(); - - /** - * Path to the test directory in the repository. + * Return a set of tests given a target and test category. + * + * @param t The target. + * @param c The test category. + * @return A set of tests for the given target and test category. */ - public static final Path LF_TEST_PATH = LF_REPO_PATH.resolve("test"); + public Set getTests(Target t, TestCategory c) { + return this.map.get(t).get(c); + } + } + + /** + * List of directories that should be skipped when indexing test files. Any test file that has a + * directory in its path that matches an entry in this array will not be discovered. + */ + public static final String[] IGNORED_DIRECTORIES = { + "failing", "knownfailed", "failed", "fed-gen" + }; + + /** Path to the root of the repository. */ + public static final Path LF_REPO_PATH = Paths.get("").toAbsolutePath(); + + /** Path to the test directory in the repository. */ + public static final Path LF_TEST_PATH = LF_REPO_PATH.resolve("test"); + + /** Internal data structure that stores registered tests. */ + protected static final TestMap registered = new TestMap(); + + /** + * Internal data structure that stores ignored tests. For instance, source files with no main + * reactor are indexed here. + */ + protected static final TestMap ignored = new TestMap(); + + /** + * A map from each test category to a set of tests that is the union of all registered tests in + * that category across all targets. + */ + protected static final Map> allTargets = new HashMap<>(); + + /** + * 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 + * mapped to. Matching is case insensitive. + * + *

    For example, the following files will all map to THREADED: + * + *

      + *
    • C/threaded/Foo.lf + *
    • C/THREADED/Foo.lf + *
    • C/Threaded/Foo.lf + *
    • C/foo/threaded/Bar.lf + *
    • C/foo/bar/threaded/Threaded.lf + *
    • C/federated/threaded/bar.lf but the following will not: + *
    • C/Foo.lf (maps to COMMON) + *
    • C/Threaded.lf (maps to COMMON) + *
    • C/threaded/federated/foo.lf (maps to FEDERATED) + *
    + * + * @author Marten Lohstroh + */ + public enum TestCategory { + /** Tests about concurrent execution. */ + CONCURRENT(true), + /** Test about enclaves */ + ENCLAVE(false), + /** Generic tests, ie, tests that all targets are supposed to implement. */ + GENERIC(true), + /** Tests about generics, not to confuse with {@link #GENERIC}. */ + GENERICS(true), + /** Tests about multiports and banks of reactors. */ + MULTIPORT(true), + /** Tests about federated execution. */ + FEDERATED(true), + /** Tests about specific target properties. */ + PROPERTIES(true), + /** Tests concerning modal reactors */ + MODAL_MODELS(true), + NO_INLINING(false), + // non-shared tests + DOCKER(true), + DOCKER_FEDERATED(true, "docker" + File.separator + "federated"), + SERIALIZATION(false), + ARDUINO(false, TestLevel.BUILD), + ZEPHYR(false, TestLevel.BUILD), + TARGET(false); + + /** Whether we should compare coverage against other targets. */ + public final boolean isCommon; + + public final String path; + public final TestLevel level; + + /** Create a new test category. */ + TestCategory(boolean isCommon) { + this.isCommon = isCommon; + this.path = this.name().toLowerCase(); + this.level = TestLevel.EXECUTION; + } - /** - * Internal data structure that stores registered tests. - */ - protected static final TestMap registered = new TestMap(); + /** Create a new test category. */ + TestCategory(boolean isCommon, TestLevel level) { + this.isCommon = isCommon; + this.path = this.name().toLowerCase(); + this.level = level; + } - /** - * Internal data structure that stores ignored tests. For instance, - * source files with no main reactor are indexed here. - */ - protected static final TestMap ignored = new TestMap(); + /** Create a new test category. */ + TestCategory(boolean isCommon, String path) { + this.isCommon = isCommon; + this.path = path; + this.level = TestLevel.EXECUTION; + } - /** - * A map from each test category to a set of tests that is the union of - * all registered tests in that category across all targets. - */ - protected static final Map> allTargets = new HashMap<>(); + public String getPath() { + return path; + } /** - * 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 mapped to. Matching is case - * insensitive. - * - * For example, the following files will all map to THREADED: - *
      - *
    • C/threaded/Foo.lf
    • - *
    • C/THREADED/Foo.lf
    • - *
    • C/Threaded/Foo.lf
    • - *
    • C/foo/threaded/Bar.lf
    • - *
    • C/foo/bar/threaded/Threaded.lf
    • - *
    • C/federated/threaded/bar.lf - * but the following will not:
    • - *
    • C/Foo.lf (maps to COMMON)
    • - *
    • C/Threaded.lf (maps to COMMON)
    • - *
    • C/threaded/federated/foo.lf (maps to FEDERATED)
    • - *
    + * Return a header associated with the category. * - * @author Marten Lohstroh + * @return A header to print in the test report. */ - public enum TestCategory { - /** Tests about concurrent execution. */ - CONCURRENT(true), - /** Test about enclaves */ - ENCLAVE(false), - /** Generic tests, ie, tests that all targets are supposed to implement. */ - GENERIC(true), - /** Tests about generics, not to confuse with {@link #GENERIC}. */ - GENERICS(true), - /** Tests about multiports and banks of reactors. */ - MULTIPORT(true), - /** Tests about federated execution. */ - FEDERATED(true), - /** Tests about specific target properties. */ - PROPERTIES(true), - /** Tests concerning modal reactors */ - MODAL_MODELS(true), - NO_INLINING(false), - // non-shared tests - DOCKER(true), - DOCKER_FEDERATED(true, "docker" + File.separator + "federated"), - SERIALIZATION(false), - ARDUINO(false, TestLevel.BUILD), - ZEPHYR(false, TestLevel.BUILD), - TARGET(false); - - /** - * Whether we should compare coverage against other targets. - */ - public final boolean isCommon; - public final String path; - public final TestLevel level ; - - /** - * Create a new test category. - */ - TestCategory(boolean isCommon) { - this.isCommon = isCommon; - this.path = this.name().toLowerCase(); - this.level = TestLevel.EXECUTION; - } - - /** - * Create a new test category. - */ - TestCategory(boolean isCommon, TestLevel level) { - this.isCommon = isCommon; - this.path = this.name().toLowerCase(); - this.level = level; - } - - /** - * Create a new test category. - */ - TestCategory(boolean isCommon, String path) { - this.isCommon = isCommon; - this.path = path; - this.level = TestLevel.EXECUTION; - } - - public String getPath() { - return path; - } - - /** - * Return a header associated with the category. - * - * @return A header to print in the test report. - */ - public String getHeader() { - return TestBase.THICK_LINE + "Category: " + this.name(); - } + public String getHeader() { + return TestBase.THICK_LINE + "Category: " + this.name(); } - - // Static code that performs the file system traversal and discovers - // all .lf files to be included in the registry. - static { - System.out.println("Indexing..."); - ResourceSet rs = new LFStandaloneSetup() + } + + // Static code that performs the file system traversal and discovers + // all .lf files to be included in the registry. + static { + System.out.println("Indexing..."); + ResourceSet rs = + new LFStandaloneSetup() .createInjectorAndDoEMFRegistration() - .getInstance(LFResourceProvider.class).getResourceSet(); + .getInstance(LFResourceProvider.class) + .getResourceSet(); - // Prepare for the collection of tests per category. - for (TestCategory t: TestCategory.values()) { - allTargets.put(t, new TreeSet<>()); - } - // Populate the registry. - for (Target target : Target.values()) { - - // Walk the tree. - try { - Path dir = LF_TEST_PATH.resolve(target.getDirectoryName()).resolve("src"); - if (Files.exists(dir)) { - new TestDirVisitor(rs, target, dir).walk(); - } else { - System.out.println("WARNING: No test directory for target " + target + "\n"); - } - - } catch (IOException e) { - System.err.println( - "ERROR: Caught exception while indexing tests for target " + target); - e.printStackTrace(); - } - // Record the tests for later use when reporting coverage. - Arrays.asList(TestCategory.values()).forEach( - c -> allTargets.get(c).addAll(getRegisteredTests(target, c, false))); + // Prepare for the collection of tests per category. + for (TestCategory t : TestCategory.values()) { + allTargets.put(t, new TreeSet<>()); + } + // Populate the registry. + for (Target target : Target.values()) { + + // Walk the tree. + try { + Path dir = LF_TEST_PATH.resolve(target.getDirectoryName()).resolve("src"); + if (Files.exists(dir)) { + new TestDirVisitor(rs, target, dir).walk(); + } else { + System.out.println("WARNING: No test directory for target " + target + "\n"); } + + } catch (IOException e) { + System.err.println("ERROR: Caught exception while indexing tests for target " + target); + e.printStackTrace(); + } + // Record the tests for later use when reporting coverage. + Arrays.asList(TestCategory.values()) + .forEach(c -> allTargets.get(c).addAll(getRegisteredTests(target, c, false))); + } + } + + /** + * Calling this function forces the lazy initialization of the static code that indexes all files. + * It is advisable to do this prior to executing other code that prints to standard out so that + * any error messages printed while indexing are printed first. + */ + public static void initialize() {} + + /** + * Return the tests that were indexed for a given target and category. + * + * @param target The target to get indexed tests for. + * @param category The category of tests to include in the returned tests. + * @param copy Whether to return copies of the indexed tests instead of the indexed tests + * themselves. + * @return A set of tests for the given target/category. + */ + public static Set getRegisteredTests(Target target, TestCategory category, boolean copy) { + if (copy) { + Set copies = new TreeSet<>(); + for (LFTest test : registered.getTests(target, category)) { + copies.add(new LFTest(test)); + } + return copies; + } else { + return registered.getTests(target, category); + } + } + + /** Return the test that were found but not indexed because they did not have a main reactor. */ + public static Set getIgnoredTests(Target target, TestCategory category) { + return ignored.getTests(target, category); + } + + public static String getCoverageReport(Target target, TestCategory category) { + StringBuilder s = new StringBuilder(); + Set ignored = TestRegistry.getIgnoredTests(target, category); + s.append(TestBase.THIN_LINE); + s.append("Ignored: ").append(ignored.size()).append("\n"); + s.append(TestBase.THIN_LINE); + + for (LFTest test : ignored) { + s.append("No main reactor in: ").append(test).append("\n"); } - /** - * Calling this function forces the lazy initialization of the static code - * that indexes all files. It is advisable to do this prior to executing - * other code that prints to standard out so that any error messages - * printed while indexing are printed first. - */ - public static void initialize() {} + Set own = getRegisteredTests(target, category, false); + if (category.isCommon) { + Set all = allTargets.get(category); + s.append("\n").append(TestBase.THIN_LINE); + s.append("Covered: ").append(own.size()).append("/").append(all.size()).append("\n"); + s.append(TestBase.THIN_LINE); + int missing = all.size() - own.size(); + if (missing > 0) { + all.stream() + .filter(test -> !own.contains(test)) + .forEach(test -> s.append("Missing: ").append(test).append("\n")); + } + } else { + s.append("\n").append(TestBase.THIN_LINE); + s.append("Covered: ").append(own.size()).append("/").append(own.size()).append("\n"); + s.append(TestBase.THIN_LINE); + } + return s.toString(); + } + + /** + * FileVisitor implementation that maintains a stack to map found tests to the appropriate + * category and excludes directories that are listed as "ignored" from walks. + * + *

    Specifically, when a directory is encountered that matches a category, this category is + * pushed onto the stack. Similarly, when the DFS leaves such a directory, its corresponding + * category is popped from the stack. Any test (*.lf) file that is encountered will be mapped to + * the category that is on top of the stack. Initially, the stack has one element that is + * TestCategory.COMMON, meaning that test files in the top-level test directory for a given target + * will be mapped to that category. + * + * @author Marten Lohstroh + */ + public static class TestDirVisitor extends SimpleFileVisitor { + + /** The stack of which the top element indicates the "current" category. */ + protected Stack stack = new Stack<>(); + + /** The target that all encountered tests belong to. */ + protected Target target; + + protected ResourceSet rs; + + protected Path srcBasePath; /** - * Return the tests that were indexed for a given target and category. + * Create a new file visitor based on a given target. * - * @param target The target to get indexed tests for. - * @param category The category of tests to include in the returned tests. - * @param copy Whether to return copies of the indexed tests instead of the indexed tests themselves. - * @return A set of tests for the given target/category. + * @param target The target that all encountered tests belong to. + * @param srcBasePath The test sources directory */ - public static Set getRegisteredTests(Target target, - TestCategory category, boolean copy) { - if (copy) { - Set copies = new TreeSet<>(); - for (LFTest test : registered.getTests(target, category)) { - copies.add(new LFTest(test)); - } - return copies; - } else { - return registered.getTests(target, category); - } + public TestDirVisitor(ResourceSet rs, Target target, Path srcBasePath) { + stack.push(TestCategory.GENERIC); + this.rs = rs; + this.target = target; + this.srcBasePath = srcBasePath; } /** - * Return the test that were found but not indexed because they did not - * have a main reactor. + * Push categories onto the stack as appropriate and skip directories that should be ignored. */ - public static Set getIgnoredTests(Target target, TestCategory category) { - return ignored.getTests(target, category); - } - - public static String getCoverageReport(Target target, TestCategory category) { - StringBuilder s = new StringBuilder(); - Set ignored = TestRegistry.getIgnoredTests(target, category); - s.append(TestBase.THIN_LINE); - s.append("Ignored: ").append(ignored.size()).append("\n"); - s.append(TestBase.THIN_LINE); - - for (LFTest test : ignored) { - s.append("No main reactor in: ").append(test).append("\n"); + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { + for (String ignored : IGNORED_DIRECTORIES) { + if (dir.getFileName().toString().equalsIgnoreCase(ignored)) { + return SKIP_SUBTREE; } + } + for (TestCategory category : TestCategory.values()) { + var relativePathName = srcBasePath.relativize(dir).toString(); + if (relativePathName.equalsIgnoreCase(category.getPath())) { + stack.push(category); + } + } + return CONTINUE; + } - Set own = getRegisteredTests(target, category, false); - if (category.isCommon) { - Set all = allTargets.get(category); - s.append("\n").append(TestBase.THIN_LINE); - s.append("Covered: ").append(own.size()).append("/").append(all.size()).append("\n"); - s.append(TestBase.THIN_LINE); - int missing = all.size() - own.size(); - if (missing > 0) { - all.stream().filter(test -> !own.contains(test)) - .forEach(test -> s.append("Missing: ").append(test).append("\n")); - } - } else { - s.append("\n").append(TestBase.THIN_LINE); - s.append("Covered: ").append(own.size()).append("/").append(own.size()).append("\n"); - s.append(TestBase.THIN_LINE); + /** Pop categories from the stack as appropriate. */ + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) { + for (TestCategory category : TestCategory.values()) { + var relativePathName = srcBasePath.relativize(dir).toString(); + if (relativePathName.equalsIgnoreCase(category.getPath())) { + this.stack.pop(); } - return s.toString(); + } + return CONTINUE; } /** - * FileVisitor implementation that maintains a stack to map found tests to - * the appropriate category and excludes directories that are listed as - * "ignored" from walks. - * - * Specifically, when a directory is encountered that matches a category, - * this category is pushed onto the stack. Similarly, when the DFS leaves - * such a directory, its corresponding category is popped from the stack. - * Any test (*.lf) file that is encountered will be mapped to the category - * that is on top of the stack. Initially, the stack has one element that - * is TestCategory.COMMON, meaning that test files in the top-level test - * directory for a given target will be mapped to that category. - * - * @author Marten Lohstroh + * Add test files to the registry if they end with ".lf", but only if they have a main reactor. */ - public static class TestDirVisitor extends SimpleFileVisitor { - - /** - * The stack of which the top element indicates the "current" category. - */ - protected Stack stack = new Stack<>(); - - /** - * The target that all encountered tests belong to. - */ - protected Target target; - - protected ResourceSet rs; - - protected Path srcBasePath; - - /** - * Create a new file visitor based on a given target. - * - * @param target The target that all encountered tests belong to. - * @param srcBasePath The test sources directory - */ - public TestDirVisitor(ResourceSet rs, Target target, Path srcBasePath) { - stack.push(TestCategory.GENERIC); - this.rs = rs; - this.target = target; - this.srcBasePath = srcBasePath; + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attr) { + if (attr.isRegularFile() && path.toString().endsWith(".lf")) { + // Try to parse the file. + Resource r = rs.getResource(URI.createFileURI(path.toFile().getAbsolutePath()), true); + // FIXME: issue warning if target doesn't match! + LFTest test = new LFTest(target, path); + + Iterator reactors = IteratorExtensions.filter(r.getAllContents(), Reactor.class); + + if (r.getErrors().isEmpty() + && !IteratorExtensions.exists(reactors, it -> it.isMain() || it.isFederated())) { + // If the test compiles but doesn't have a main reactor, + // _do not add the file_. We assume it is a library + // file. + ignored.getTests(this.target, this.stack.peek()).add(test); + return CONTINUE; } - /** - * Push categories onto the stack as appropriate and skip directories - * that should be ignored. - */ - @Override - public FileVisitResult preVisitDirectory(Path dir, - BasicFileAttributes attrs) { - for (String ignored : IGNORED_DIRECTORIES) { - if (dir.getFileName().toString().equalsIgnoreCase(ignored)) { - return SKIP_SUBTREE; - } - } - for (TestCategory category : TestCategory.values()) { - var relativePathName = srcBasePath.relativize(dir).toString(); - if (relativePathName.equalsIgnoreCase(category.getPath())) { - stack.push(category); - } - } - return CONTINUE; - } - - /** - * Pop categories from the stack as appropriate. - */ - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) { - for (TestCategory category : TestCategory.values()) { - var relativePathName = srcBasePath.relativize(dir).toString(); - if (relativePathName.equalsIgnoreCase(category.getPath())) { - this.stack.pop(); - } - } - return CONTINUE; - } - - /** - * Add test files to the registry if they end with ".lf", but only if they have a main reactor. - */ - @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attr) { - if (attr.isRegularFile() && path.toString().endsWith(".lf")) { - // Try to parse the file. - Resource r = rs.getResource(URI.createFileURI(path.toFile().getAbsolutePath()),true); - // FIXME: issue warning if target doesn't match! - LFTest test = new LFTest(target, path); - - Iterator reactors = IteratorExtensions.filter(r.getAllContents(), Reactor.class); - - if (r.getErrors().isEmpty() && !IteratorExtensions.exists(reactors, - it -> it.isMain() || it.isFederated())) { - // If the test compiles but doesn't have a main reactor, - // _do not add the file_. We assume it is a library - // file. - ignored.getTests(this.target, this.stack.peek()).add(test); - return CONTINUE; - } - - registered.getTests(this.target, this.stack.peek()).add(test); - } - return CONTINUE; - } + registered.getTests(this.target, this.stack.peek()).add(test); + } + return CONTINUE; + } - public void walk() throws IOException { - Files.walkFileTree(srcBasePath, this); - } + public void walk() throws IOException { + Files.walkFileTree(srcBasePath, this); } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/TestUtils.java b/org.lflang.tests/src/org/lflang/tests/TestUtils.java index c868acb771..9e7cb4218a 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestUtils.java +++ b/org.lflang.tests/src/org/lflang/tests/TestUtils.java @@ -31,7 +31,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.function.Predicate; - import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; @@ -41,139 +40,136 @@ */ public class TestUtils { - private static Matcher pathMatcher(String description, Predicate predicate) { - return new BaseMatcher<>() { - @Override - public boolean matches(Object item) { - return item instanceof Path && predicate.test((Path) item); - } - - @Override - public void describeTo(Description describer) { - describer.appendText(description); - } - }; + private static Matcher pathMatcher(String description, Predicate predicate) { + return new BaseMatcher<>() { + @Override + public boolean matches(Object item) { + return item instanceof Path && predicate.test((Path) item); + } + + @Override + public void describeTo(Description describer) { + describer.appendText(description); + } + }; + } + + public static Matcher isDirectory() { + return pathMatcher("is a directory", Files::isDirectory); + } + + public static Matcher isRegularFile() { + return pathMatcher("is a regular file", Files::isRegularFile); + } + + public static Matcher exists() { + return pathMatcher("exists", Files::exists); + } + + /** Builder for a directory. Useful to create a fake LF project. */ + public static class TempDirBuilder { + + private final Path curDir; + + private TempDirBuilder(Path path) { + this.curDir = path; + if (!Files.isDirectory(path)) { + throw new IllegalArgumentException("Not a directory: " + path); + } } - public static Matcher isDirectory() { - return pathMatcher("is a directory", Files::isDirectory); + public static TempDirBuilder dirBuilder(Path path) { + return new TempDirBuilder(path); } - public static Matcher isRegularFile() { - return pathMatcher("is a regular file", Files::isRegularFile); + /** Create a directory at the given path. Return a new temp dir builder for that subdir. */ + public TempDirBuilder cd(String relativePath) throws IOException { + Path relPath = Paths.get(relativePath); + if (relPath.isAbsolute()) { + throw new IllegalArgumentException("Should be a relative path: " + relativePath); + } + Path dir = curDir.resolve(relPath); + Files.createDirectories(dir); + return new TempDirBuilder(dir); } - public static Matcher exists() { - return pathMatcher("exists", Files::exists); + /** Create a directory at the given path. Return this instance. */ + public TempDirBuilder mkdirs(String relativePath) throws IOException { + Path relPath = Paths.get(relativePath); + if (relPath.isAbsolute()) { + throw new IllegalArgumentException("Should be a relative path: " + relativePath); + } + Path dir = curDir.resolve(relPath); + Files.createDirectories(dir); + return this; } - /** - * Builder for a directory. Useful to create a fake LF project. - */ - public static class TempDirBuilder { - - private final Path curDir; - - private TempDirBuilder(Path path) { - this.curDir = path; - if (!Files.isDirectory(path)) { - throw new IllegalArgumentException("Not a directory: " + path); - } - } - - public static TempDirBuilder dirBuilder(Path path) { - return new TempDirBuilder(path); - } - - /** Create a directory at the given path. Return a new temp dir builder for that subdir. */ - public TempDirBuilder cd(String relativePath) throws IOException { - Path relPath = Paths.get(relativePath); - if (relPath.isAbsolute()) { - throw new IllegalArgumentException("Should be a relative path: " + relativePath); - } - Path dir = curDir.resolve(relPath); - Files.createDirectories(dir); - return new TempDirBuilder(dir); - } - - /** Create a directory at the given path. Return this instance. */ - public TempDirBuilder mkdirs(String relativePath) throws IOException { - Path relPath = Paths.get(relativePath); - if (relPath.isAbsolute()) { - throw new IllegalArgumentException("Should be a relative path: " + relativePath); - } - Path dir = curDir.resolve(relPath); - Files.createDirectories(dir); - return this; - } - - /** Create a file in the given subpath. Return this instance. */ - public TempDirBuilder file(String relativePath, String contents) throws IOException { - Path relPath = Paths.get(relativePath); - if (relPath.isAbsolute()) { - throw new IllegalArgumentException("Should be a relative path: " + relativePath); - } - Path filePath = curDir.resolve(relPath); - Files.createDirectories(filePath.getParent()); - Files.writeString(filePath, contents); - return this; - } + /** Create a file in the given subpath. Return this instance. */ + public TempDirBuilder file(String relativePath, String contents) throws IOException { + Path relPath = Paths.get(relativePath); + if (relPath.isAbsolute()) { + throw new IllegalArgumentException("Should be a relative path: " + relativePath); + } + Path filePath = curDir.resolve(relPath); + Files.createDirectories(filePath.getParent()); + Files.writeString(filePath, contents); + return this; + } + } + + /** Builder for a directory. Useful to create a fake LF project. */ + public static class TempDirChecker { + + private final Path curDir; + + private TempDirChecker(Path path) { + this.curDir = path; + if (!Files.isDirectory(path)) { + throw new IllegalArgumentException("Not a directory: " + path); + } + } + + public static TempDirChecker dirChecker(Path path) { + return new TempDirChecker(path); + } + + /** Create a directory at the given path. Return a new temp dir builder for that subdir. */ + public TempDirBuilder cd(String relativePath) throws IOException { + Path relPath = Paths.get(relativePath); + if (relPath.isAbsolute()) { + throw new IllegalArgumentException("Should be a relative path: " + relativePath); + } + Path dir = curDir.resolve(relPath); + Files.createDirectories(dir); + return new TempDirBuilder(dir); } /** - * Builder for a directory. Useful to create a fake LF project. + * Check the contents of the file match the matcher. The file should be a UTF-8 encoded text + * file. Return this instance. */ - public static class TempDirChecker { - - private final Path curDir; - - private TempDirChecker(Path path) { - this.curDir = path; - if (!Files.isDirectory(path)) { - throw new IllegalArgumentException("Not a directory: " + path); - } - } - - public static TempDirChecker dirChecker(Path path) { - return new TempDirChecker(path); - } - - /** Create a directory at the given path. Return a new temp dir builder for that subdir. */ - public TempDirBuilder cd(String relativePath) throws IOException { - Path relPath = Paths.get(relativePath); - if (relPath.isAbsolute()) { - throw new IllegalArgumentException("Should be a relative path: " + relativePath); - } - Path dir = curDir.resolve(relPath); - Files.createDirectories(dir); - return new TempDirBuilder(dir); - } - - /** - * Check the contents of the file match the matcher. - * The file should be a UTF-8 encoded text file. Return - * this instance. - */ - public TempDirChecker checkContentsOf(String relativePath, Matcher contentsMatcher) throws IOException { - Path relPath = Paths.get(relativePath); - if (relPath.isAbsolute()) { - throw new IllegalArgumentException("Should be a relative path: " + relativePath); - } - Path filePath = curDir.resolve(relPath); - - assertThat(Files.readString(filePath), contentsMatcher); - return this; - } - - public TempDirChecker check(String relativePath, Matcher pathMatcher) throws IOException { - Path relPath = Paths.get(relativePath); - if (relPath.isAbsolute()) { - throw new IllegalArgumentException("Should be a relative path: " + relativePath); - } - Path filePath = curDir.resolve(relPath); - - assertThat(filePath, pathMatcher); - return this; - } + public TempDirChecker checkContentsOf( + String relativePath, Matcher contentsMatcher) throws IOException { + Path relPath = Paths.get(relativePath); + if (relPath.isAbsolute()) { + throw new IllegalArgumentException("Should be a relative path: " + relativePath); + } + Path filePath = curDir.resolve(relPath); + + assertThat(Files.readString(filePath), contentsMatcher); + return this; + } + + public TempDirChecker check(String relativePath, Matcher pathMatcher) + throws IOException { + Path relPath = Paths.get(relativePath); + if (relPath.isAbsolute()) { + throw new IllegalArgumentException("Should be a relative path: " + relativePath); + } + Path filePath = curDir.resolve(relPath); + + assertThat(filePath, pathMatcher); + return this; } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java b/org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java index 83e7817618..257da7ad06 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java @@ -32,130 +32,108 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.nio.file.Path; -import java.util.concurrent.Callable; -import java.util.function.Consumer; - import org.hamcrest.Matcher; -import org.opentest4j.AssertionFailedError; - import org.lflang.cli.Io; +import org.opentest4j.AssertionFailedError; /** - * Test utilities for a CLI tool, eg {@link org.lflang.cli.Lfc}, - * {@link org.lflang.cli.Lff}. + * Test utilities for a CLI tool, eg {@link org.lflang.cli.Lfc}, {@link org.lflang.cli.Lff}. * * @author Clément Fournier */ abstract class CliToolTestFixture { - /** - * Override to call the relevant main. - */ - protected abstract void runCliProgram(Io io, String[] args); - - - /** - * Run the tool with the given arguments, in the system - * working directory. - * - * @param args Arguments - * @return The execution result - */ - public ExecutionResult run(String... args) { - return run(Io.SYSTEM.getWd(), args); + /** Override to call the relevant main. */ + protected abstract void runCliProgram(Io io, String[] args); + + /** + * Run the tool with the given arguments, in the system working directory. + * + * @param args Arguments + * @return The execution result + */ + public ExecutionResult run(String... args) { + return run(Io.SYSTEM.getWd(), args); + } + + /** + * Run the tool with the given arguments, in the given working directory. + * + * @param wd working directory + * @param args Arguments + * @return The execution result + */ + public ExecutionResult run(Path wd, String... args) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + + Io testIo = new Io(new PrintStream(err), new PrintStream(out), wd); + int exitCode = testIo.fakeSystemExit(io -> runCliProgram(io, args)); + + return new ExecutionResult(out, err, exitCode); + } + + /** + * The result of an execution of a CLI program like LFC. + * + * @param out Output stream + * @param err Error stream + * @param exitCode Exit code of the process + */ + record ExecutionResult(ByteArrayOutputStream out, ByteArrayOutputStream err, int exitCode) { + + public String getOut() { + return out.toString(); } - /** - * Run the tool with the given arguments, in the given - * working directory. - * - * @param wd working directory - * @param args Arguments - * @return The execution result - */ - public ExecutionResult run(Path wd, String... args) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ByteArrayOutputStream err = new ByteArrayOutputStream(); - - Io testIo = new Io( - new PrintStream(err), - new PrintStream(out), - wd - ); - int exitCode = testIo.fakeSystemExit(io -> runCliProgram(io, args)); - - return new ExecutionResult(out, err, exitCode); + public String getErr() { + return err.toString(); } - /** - * The result of an execution of a CLI program like LFC. - * - * @param out Output stream - * @param err Error stream - * @param exitCode Exit code of the process - */ - record ExecutionResult( - ByteArrayOutputStream out, - ByteArrayOutputStream err, - int exitCode - ) { - - public String getOut() { - return out.toString(); - } - - public String getErr() { - return err.toString(); - } - - - public void checkOk() { - assertEquals(0, exitCode); - } + public void checkOk() { + assertEquals(0, exitCode); + } - public void checkFailed() { - assertTrue(exitCode > 0); - } + public void checkFailed() { + assertTrue(exitCode > 0); + } - public void checkNoErrorOutput() { - checkStdErr(equalTo("")); - } + public void checkNoErrorOutput() { + checkStdErr(equalTo("")); + } - public void checkStdOut(Matcher matcher) { - assertThat(getOut(), matcher); - } + public void checkStdOut(Matcher matcher) { + assertThat(getOut(), matcher); + } - public void checkStdErr(Matcher matcher) { - assertThat(getErr(), matcher); - } + public void checkStdErr(Matcher matcher) { + assertThat(getErr(), matcher); + } - /** - * Use this method to wrap assertions. - */ - public void verify(ThrowingConsumer actions) { - try { - actions.accept(this); - } catch (Exception | AssertionFailedError e) { - System.out.println("TEST FAILED"); - System.out.println("> Return code: " + exitCode); - System.out.println("> Standard output -------------------------"); - System.err.println(out.toString()); - System.out.println("> Standard error --------------------------"); - System.err.println(err.toString()); - System.out.println("> -----------------------------------------"); - - if (e instanceof Exception) { - throw new AssertionFailedError("Expected no exception to be thrown", e); - } - throw (AssertionFailedError) e; - } + /** Use this method to wrap assertions. */ + public void verify(ThrowingConsumer actions) { + try { + actions.accept(this); + } catch (Exception | AssertionFailedError e) { + System.out.println("TEST FAILED"); + System.out.println("> Return code: " + exitCode); + System.out.println("> Standard output -------------------------"); + System.err.println(out.toString()); + System.out.println("> Standard error --------------------------"); + System.err.println(err.toString()); + System.out.println("> -----------------------------------------"); + + if (e instanceof Exception) { + throw new AssertionFailedError("Expected no exception to be thrown", e); } + throw (AssertionFailedError) e; + } + } + @FunctionalInterface + interface ThrowingConsumer { - @FunctionalInterface - interface ThrowingConsumer { - - void accept(T t) throws Exception; - } + void accept(T t) throws Exception; } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java index d16193faad..d9e81a0e68 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java @@ -33,15 +33,12 @@ import static org.lflang.tests.TestUtils.isRegularFile; import com.google.inject.Injector; - import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.Properties; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - import org.lflang.LocalStrings; import org.lflang.cli.Io; import org.lflang.cli.Lfc; @@ -54,16 +51,18 @@ */ public class LfcCliTest { - LfcTestFixture lfcTester = new LfcTestFixture(); + LfcTestFixture lfcTester = new LfcTestFixture(); - static final String LF_PYTHON_FILE = """ + static final String LF_PYTHON_FILE = + """ target Python main reactor { reaction(startup) {==} } """; - static final String JSON_STRING = """ + static final String JSON_STRING = + """ { "src": "src/File.lf", "out": "src", @@ -87,230 +86,262 @@ public class LfcCliTest { } """; - @Test - public void testHelpArg() { - lfcTester.run("--help", "--version") - .verify(result -> { - result.checkOk(); - result.checkNoErrorOutput(); - result.checkStdOut(containsString("Usage: lfc")); + @Test + public void testHelpArg() { + lfcTester + .run("--help", "--version") + .verify( + result -> { + result.checkOk(); + result.checkNoErrorOutput(); + result.checkStdOut(containsString("Usage: lfc")); }); - } - - @Test - public void testMutuallyExclusiveCliArgs() { - lfcTester.run("File.lf", "--json", JSON_STRING) - .verify(result -> { - result.checkStdErr(containsString( - "are mutually exclusive (specify only one)")); - result.checkFailed(); + } + + @Test + public void testMutuallyExclusiveCliArgs() { + lfcTester + .run("File.lf", "--json", JSON_STRING) + .verify( + result -> { + result.checkStdErr(containsString("are mutually exclusive (specify only one)")); + result.checkFailed(); }); - lfcTester.run("File.lf", "--json-file", "test.json") - .verify(result -> { - result.checkStdErr(containsString( - "are mutually exclusive (specify only one)")); - result.checkFailed(); + lfcTester + .run("File.lf", "--json-file", "test.json") + .verify( + result -> { + result.checkStdErr(containsString("are mutually exclusive (specify only one)")); + result.checkFailed(); }); - lfcTester.run("--json", JSON_STRING, "--json-file", "test.json") - .verify(result -> { - result.checkStdErr(containsString( - "are mutually exclusive (specify only one)")); - result.checkFailed(); + lfcTester + .run("--json", JSON_STRING, "--json-file", "test.json") + .verify( + result -> { + result.checkStdErr(containsString("are mutually exclusive (specify only one)")); + result.checkFailed(); }); - } - - @Test - public void testVersion() { - lfcTester.run("--version") - .verify(result -> { - result.checkOk(); - result.checkNoErrorOutput(); - result.checkStdOut(equalTo( - "lfc " + LocalStrings.VERSION + System.lineSeparator())); + } + + @Test + public void testVersion() { + lfcTester + .run("--version") + .verify( + result -> { + result.checkOk(); + result.checkNoErrorOutput(); + result.checkStdOut(equalTo("lfc " + LocalStrings.VERSION + System.lineSeparator())); }); - } - - - @Test - public void testWrongCliArg() { - lfcTester.run("--notanargument", "File.lf") - .verify(result -> { - result.checkStdErr(containsString("Unknown option: '--notanargument'")); - result.checkFailed(); + } + + @Test + public void testWrongCliArg() { + lfcTester + .run("--notanargument", "File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Unknown option: '--notanargument'")); + result.checkFailed(); }); - } - - @Test - public void testInvalidArgs(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir).file("src/File.lf", LF_PYTHON_FILE); - LfcOneShotTestFixture fixture = new LfcOneShotTestFixture(); - - // Invalid src file. - fixture.run(tempDir, "unknown.lf") - .verify(result -> { - result.checkStdErr(containsString("No such file or directory.")); - result.checkFailed(); + } + + @Test + public void testInvalidArgs(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/File.lf", LF_PYTHON_FILE); + LfcOneShotTestFixture fixture = new LfcOneShotTestFixture(); + + // Invalid src file. + fixture + .run(tempDir, "unknown.lf") + .verify( + result -> { + result.checkStdErr(containsString("No such file or directory.")); + result.checkFailed(); }); - // Invalid output path. - fixture.run(tempDir, "--output-path", "unknown/output/path", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Output location does not exist.")); - result.checkFailed(); + // Invalid output path. + fixture + .run(tempDir, "--output-path", "unknown/output/path", "src/File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Output location does not exist.")); + result.checkFailed(); }); - // Invalid build type. - fixture.run(tempDir, "--build-type", "unknown-build-type", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid build type.")); - result.checkFailed(); + // Invalid build type. + fixture + .run(tempDir, "--build-type", "unknown-build-type", "src/File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Invalid build type.")); + result.checkFailed(); }); - // Invalid logging level. - fixture.run(tempDir, "--logging", "unknown_level", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid log level.")); - result.checkFailed(); + // Invalid logging level. + fixture + .run(tempDir, "--logging", "unknown_level", "src/File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Invalid log level.")); + result.checkFailed(); }); - // Invalid RTI path. - fixture.run(tempDir, "--rti", "unknown/rti/path", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid RTI path.")); - result.checkFailed(); + // Invalid RTI path. + fixture + .run(tempDir, "--rti", "unknown/rti/path", "src/File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Invalid RTI path.")); + result.checkFailed(); }); - // Invalid scheduler. - fixture.run(tempDir, "--scheduler", "unknown-scheduler", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid scheduler.")); - result.checkFailed(); + // Invalid scheduler. + fixture + .run(tempDir, "--scheduler", "unknown-scheduler", "src/File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Invalid scheduler.")); + result.checkFailed(); }); - // Invalid workers. - fixture.run(tempDir, "--workers", "notaninteger", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid value for option '--workers'")); - result.checkStdErr(containsString("is not an int")); - result.checkFailed(); + // Invalid workers. + fixture + .run(tempDir, "--workers", "notaninteger", "src/File.lf") + .verify( + result -> { + result.checkStdErr(containsString("Invalid value for option '--workers'")); + result.checkStdErr(containsString("is not an int")); + result.checkFailed(); }); - - } - - @Test - public void testGenInSrcDir(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir).file("src/File.lf", LF_PYTHON_FILE); - - lfcTester.run(tempDir, "src/File.lf", "--no-compile") - .verify(result -> { - result.checkOk(); - dirChecker(tempDir) - .check("src-gen", isDirectory()) - .check("bin", isDirectory()) - .check("src-gen/File/File.py", isRegularFile()); + } + + @Test + public void testGenInSrcDir(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/File.lf", LF_PYTHON_FILE); + + lfcTester + .run(tempDir, "src/File.lf", "--no-compile") + .verify( + result -> { + result.checkOk(); + dirChecker(tempDir) + .check("src-gen", isDirectory()) + .check("bin", isDirectory()) + .check("src-gen/File/File.py", isRegularFile()); }); - } - - // Helper method for comparing argument values in tests testGeneratorArgs, - // testGeneratorArgsJsonString and testGeneratorArgsJsonFile. - public void verifyGeneratorArgs(Path tempDir, String[] args) { - LfcOneShotTestFixture fixture = new LfcOneShotTestFixture(); - - fixture.run(tempDir, args) - .verify(result -> { - // Don't validate execution because args are dummy args. - Properties properties = fixture.lfc.getGeneratorArgs(); - assertEquals(properties.getProperty(BuildParm.BUILD_TYPE.getKey()), "Release"); - assertEquals(properties.getProperty(BuildParm.CLEAN.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.TARGET_COMPILER.getKey()), "gcc"); - assertEquals(properties.getProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey()), "src"); - assertEquals(properties.getProperty(BuildParm.LOGGING.getKey()), "info"); - assertEquals(properties.getProperty(BuildParm.LINT.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.NO_COMPILE.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.PRINT_STATISTICS.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.QUIET.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.RTI.getKey()), - "path" + File.separator + "to" + File.separator + "rti"); - assertEquals(properties.getProperty(BuildParm.RUNTIME_VERSION.getKey()), "rs"); - assertEquals(properties.getProperty(BuildParm.SCHEDULER.getKey()), "GEDF_NP"); - assertEquals(properties.getProperty(BuildParm.THREADING.getKey()), "false"); - assertEquals(properties.getProperty(BuildParm.WORKERS.getKey()), "1"); + } + + // Helper method for comparing argument values in tests testGeneratorArgs, + // testGeneratorArgsJsonString and testGeneratorArgsJsonFile. + public void verifyGeneratorArgs(Path tempDir, String[] args) { + LfcOneShotTestFixture fixture = new LfcOneShotTestFixture(); + + fixture + .run(tempDir, args) + .verify( + result -> { + // Don't validate execution because args are dummy args. + Properties properties = fixture.lfc.getGeneratorArgs(); + assertEquals(properties.getProperty(BuildParm.BUILD_TYPE.getKey()), "Release"); + assertEquals(properties.getProperty(BuildParm.CLEAN.getKey()), "true"); + assertEquals(properties.getProperty(BuildParm.TARGET_COMPILER.getKey()), "gcc"); + assertEquals(properties.getProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey()), "src"); + assertEquals(properties.getProperty(BuildParm.LOGGING.getKey()), "info"); + assertEquals(properties.getProperty(BuildParm.LINT.getKey()), "true"); + assertEquals(properties.getProperty(BuildParm.NO_COMPILE.getKey()), "true"); + assertEquals(properties.getProperty(BuildParm.PRINT_STATISTICS.getKey()), "true"); + assertEquals(properties.getProperty(BuildParm.QUIET.getKey()), "true"); + assertEquals( + properties.getProperty(BuildParm.RTI.getKey()), + "path" + File.separator + "to" + File.separator + "rti"); + assertEquals(properties.getProperty(BuildParm.RUNTIME_VERSION.getKey()), "rs"); + assertEquals(properties.getProperty(BuildParm.SCHEDULER.getKey()), "GEDF_NP"); + assertEquals(properties.getProperty(BuildParm.THREADING.getKey()), "false"); + assertEquals(properties.getProperty(BuildParm.WORKERS.getKey()), "1"); }); + } + + @Test + public void testGeneratorArgs(@TempDir Path tempDir) throws IOException { + TempDirBuilder dir = dirBuilder(tempDir); + dir.file("src/File.lf", LF_PYTHON_FILE); + dir.mkdirs("path//to/rti"); + + String[] args = { + "src/File.lf", + "--output-path", + "src", + "--build-type", + "Release", + "--clean", + "--target-compiler", + "gcc", + "--external-runtime-path", + "src", + "--federated", + "--logging", + "info", + "--lint", + "--no-compile", + "--print-statistics", + "--quiet", + "--rti", + "path/to/rti", + "--runtime-version", + "rs", + "--scheduler", + "GEDF_NP", + "--threading", + "false", + "--workers", + "1", + }; + verifyGeneratorArgs(tempDir, args); + } + + @Test + public void testGeneratorArgsJsonString(@TempDir Path tempDir) throws IOException { + TempDirBuilder dir = dirBuilder(tempDir); + dir.file("src/File.lf", LF_PYTHON_FILE); + dir.mkdirs("path/to/rti"); + + String[] args = {"--json", JSON_STRING}; + verifyGeneratorArgs(tempDir, args); + } + + @Test + public void testGeneratorArgsJsonFile(@TempDir Path tempDir) throws IOException { + TempDirBuilder dir = dirBuilder(tempDir); + dir.file("src/File.lf", LF_PYTHON_FILE); + dir.file("src/test.json", JSON_STRING); + dir.mkdirs("path/to/rti"); + + String[] args = {"--json-file", "src/test.json"}; + verifyGeneratorArgs(tempDir, args); + } + + static class LfcTestFixture extends CliToolTestFixture { + + @Override + protected void runCliProgram(Io io, String[] args) { + Lfc.main(io, args); } + } - @Test - public void testGeneratorArgs(@TempDir Path tempDir) - throws IOException { - TempDirBuilder dir = dirBuilder(tempDir); - dir.file("src/File.lf", LF_PYTHON_FILE); - dir.mkdirs("path//to/rti"); - - String[] args = { - "src/File.lf", - "--output-path", "src", - "--build-type", "Release", - "--clean", - "--target-compiler", "gcc", - "--external-runtime-path", "src", - "--federated", - "--logging", "info", - "--lint", - "--no-compile", - "--print-statistics", - "--quiet", - "--rti", "path/to/rti", - "--runtime-version", "rs", - "--scheduler", "GEDF_NP", - "--threading", "false", - "--workers", "1", - }; - verifyGeneratorArgs(tempDir, args); - } - - @Test - public void testGeneratorArgsJsonString(@TempDir Path tempDir) - throws IOException { - TempDirBuilder dir = dirBuilder(tempDir); - dir.file("src/File.lf", LF_PYTHON_FILE); - dir.mkdirs("path/to/rti"); + static class LfcOneShotTestFixture extends CliToolTestFixture { - String[] args = {"--json", JSON_STRING}; - verifyGeneratorArgs(tempDir, args); - } - - @Test - public void testGeneratorArgsJsonFile(@TempDir Path tempDir) - throws IOException { - TempDirBuilder dir = dirBuilder(tempDir); - dir.file("src/File.lf", LF_PYTHON_FILE); - dir.file("src/test.json", JSON_STRING); - dir.mkdirs("path/to/rti"); - - String[] args = {"--json-file", "src/test.json"}; - verifyGeneratorArgs(tempDir, args); - } + private Lfc lfc; - static class LfcTestFixture extends CliToolTestFixture { - - @Override - protected void runCliProgram(Io io, String[] args) { - Lfc.main(io, args); - } - } - - static class LfcOneShotTestFixture extends CliToolTestFixture { - - private Lfc lfc; - - @Override - protected void runCliProgram(Io io, String[] args) { - // Injector used to obtain Main instance. - final Injector injector = Lfc.getInjector("lfc", io); - // Main instance. - this.lfc = injector.getInstance(Lfc.class); - lfc.doExecute(io, args); - } + @Override + protected void runCliProgram(Io io, String[] args) { + // Injector used to obtain Main instance. + final Injector injector = Lfc.getInjector("lfc", io); + // Main instance. + this.lfc = injector.getInstance(Lfc.class); + lfc.doExecute(io, args); } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java index 16a4e9b32d..a9da20239f 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java @@ -26,153 +26,136 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; import static org.lflang.tests.TestUtils.TempDirBuilder.dirBuilder; import static org.lflang.tests.TestUtils.TempDirChecker.dirChecker; import java.io.File; import java.io.IOException; import java.nio.file.Path; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - import org.lflang.LocalStrings; -import org.lflang.tests.cli.CliToolTestFixture.ExecutionResult; import org.lflang.cli.Io; import org.lflang.cli.Lff; +import org.lflang.tests.cli.CliToolTestFixture.ExecutionResult; /** * @author Clément Fournier */ public class LffCliTest { - private static final String FILE_BEFORE_REFORMAT = """ + private static final String FILE_BEFORE_REFORMAT = + """ target Python; main reactor { reaction(startup) {= =} } """; - private static final String FILE_AFTER_REFORMAT = """ + private static final String FILE_AFTER_REFORMAT = + """ target Python - + main reactor { reaction(startup) {= =} } """; - LffTestFixture lffTester = new LffTestFixture(); + LffTestFixture lffTester = new LffTestFixture(); + @Test + public void testHelpArg() { + ExecutionResult result = lffTester.run("--help", "--version"); + result.checkOk(); + result.checkNoErrorOutput(); + result.checkStdOut(containsString("Usage: lff")); + } - @Test - public void testHelpArg() { - ExecutionResult result = lffTester.run("--help", "--version"); - result.checkOk(); - result.checkNoErrorOutput(); - result.checkStdOut(containsString("Usage: lff")); - } + @Test + public void testVersion() { + ExecutionResult result = lffTester.run("--version"); + result.checkOk(); + result.checkNoErrorOutput(); + result.checkStdOut(equalTo("lff " + LocalStrings.VERSION + System.lineSeparator())); + } - @Test - public void testVersion() { - ExecutionResult result = lffTester.run("--version"); - result.checkOk(); - result.checkNoErrorOutput(); - result.checkStdOut( - equalTo("lff " + LocalStrings.VERSION + System.lineSeparator())); - } + @Test + public void testWrongCliArg() { + ExecutionResult result = lffTester.run("--notanargument", "File.lf"); + result.checkStdErr(containsString("Unknown option: '--notanargument'")); + result.checkFailed(); + } + @Test + public void testFormatSingleFileInPlace(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/File.lf", FILE_BEFORE_REFORMAT); - @Test - public void testWrongCliArg() { - ExecutionResult result = lffTester.run("--notanargument", "File.lf"); - result.checkStdErr(containsString("Unknown option: '--notanargument'")); - result.checkFailed(); - } + ExecutionResult result = lffTester.run(tempDir, "src/File.lf"); - @Test - public void testFormatSingleFileInPlace(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir).file("src/File.lf", FILE_BEFORE_REFORMAT); + result.checkOk(); - ExecutionResult result = lffTester.run(tempDir, "src/File.lf"); + dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); + } - result.checkOk(); + @Test + public void testFormatDirectory(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/File.lf", FILE_BEFORE_REFORMAT); - dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); - } + ExecutionResult result = lffTester.run(tempDir, "src"); + result.checkOk(); - @Test - public void testFormatDirectory(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir).file("src/File.lf", FILE_BEFORE_REFORMAT); + dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); + } - ExecutionResult result = lffTester.run(tempDir, "src"); + @Test + public void testFormatDirectoryVerbose(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/File.lf", FILE_BEFORE_REFORMAT); - result.checkOk(); + ExecutionResult result = lffTester.run(tempDir, "-v", "src"); - dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); - } + result.checkOk(); + result.checkStdOut(containsString("Formatted src" + File.separator + "File.lf")); + dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); + } - @Test - public void testFormatDirectoryVerbose(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir).file("src/File.lf", FILE_BEFORE_REFORMAT); + @Test + public void testNoSuchFile(@TempDir Path tempDir) { + ExecutionResult result = lffTester.run(tempDir, "-v", "nosuchdir"); - ExecutionResult result = lffTester.run(tempDir, "-v", "src"); + result.checkFailed(); - result.checkOk(); + result.checkStdErr( + containsString(tempDir.resolve("nosuchdir") + ": No such file or directory.")); + } - result.checkStdOut(containsString( - "Formatted src" + File.separator + "File.lf")); - dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT)); - } + @Test + public void testOutputPathWithDirArg(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/a/File.lf", FILE_BEFORE_REFORMAT).mkdirs("out/"); - @Test - public void testNoSuchFile(@TempDir Path tempDir) { - ExecutionResult result = lffTester.run(tempDir, "-v", "nosuchdir"); + ExecutionResult result = lffTester.run(tempDir, "src", "--output-path", "out"); - result.checkFailed(); + result.checkOk(); - result.checkStdErr(containsString( - tempDir.resolve("nosuchdir") + ": No such file or directory.")); - } + dirChecker(tempDir).checkContentsOf("out/a/File.lf", equalTo(FILE_AFTER_REFORMAT)); + } + @Test + public void testOutputPathWithFileArg(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/a/File.lf", FILE_BEFORE_REFORMAT).mkdirs("out/"); - @Test - public void testOutputPathWithDirArg(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir) - .file("src/a/File.lf", FILE_BEFORE_REFORMAT) - .mkdirs("out/"); + ExecutionResult result = lffTester.run(tempDir, "src/a/File.lf", "--output-path", "out"); - ExecutionResult result = lffTester.run(tempDir, "src", "--output-path", "out"); + result.checkOk(); - result.checkOk(); + dirChecker(tempDir).checkContentsOf("out/File.lf", equalTo(FILE_AFTER_REFORMAT)); + } - dirChecker(tempDir) - .checkContentsOf("out/a/File.lf", equalTo(FILE_AFTER_REFORMAT)); - } - - @Test - public void testOutputPathWithFileArg(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir) - .file("src/a/File.lf", FILE_BEFORE_REFORMAT) - .mkdirs("out/"); - - ExecutionResult result = lffTester.run(tempDir, "src/a/File.lf", "--output-path", "out"); + static class LffTestFixture extends CliToolTestFixture { - result.checkOk(); - - dirChecker(tempDir) - .checkContentsOf("out/File.lf", equalTo(FILE_AFTER_REFORMAT)); + @Override + protected void runCliProgram(Io io, String[] args) { + Lff.main(io, args); } - - - static class LffTestFixture extends CliToolTestFixture { - - - @Override - protected void runCliProgram(Io io, String[] args) { - Lff.main(io, args); - } - } - + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/EquivalenceUnitTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/EquivalenceUnitTests.java index 931a0edae0..5d4fe9940c 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/EquivalenceUnitTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/EquivalenceUnitTests.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.ast.IsEqual; import org.lflang.lf.Model; import org.lflang.tests.LFInjectorProvider; @@ -15,10 +14,10 @@ @InjectWith(LFInjectorProvider.class) public class EquivalenceUnitTests { - @Test - public void testSimple() { - assertSelfEquivalence( - """ + @Test + public void testSimple() { + assertSelfEquivalence( + """ target C reactor Destination { @@ -26,14 +25,13 @@ public void testSimple() { input in: int state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) } - """ - ); - } + """); + } - @Test - public void testCodeExprEqItselfModuloIndent() { - assertEquivalent( - """ + @Test + public void testCodeExprEqItselfModuloIndent() { + assertEquivalent( + """ target C reactor Destination { state s: tag_t({= @@ -41,67 +39,56 @@ public void testCodeExprEqItselfModuloIndent() { =}) } """, - """ + """ target C reactor Destination { state s: tag_t({= NEVER_TAG_INITIALIZER =}) } - """ - ); - } + """); + } - @Test - public void testInitializerParensAreIrrelevantInAssignment() { - assertEquivalent( - """ + @Test + public void testInitializerParensAreIrrelevantInAssignment() { + assertEquivalent( + """ target C reactor A(a: int(0)) {} main reactor { a = new A(a = 1) } """, - """ + """ target C reactor A(a: int(0)) {} main reactor { a = new A(a = (1)) // mind the parens here. } - """ - ); - } - - private void assertSelfEquivalence(String input) { - Model inputModel = LfParsingUtil.parseValidModel("test input", input); - // need to parse twice otherwise they are trivially equivalent - // because they're the same object. - Model otherModel = LfParsingUtil.parseValidModel("other", input); - - // test equivalence of the models. - Assertions.assertTrue( - new IsEqual(inputModel).doSwitch(otherModel), - String.format( - "Model is not equivalent to itself. Source:%n%s", - input - ) - ); - } + """); + } - private void assertEquivalent(String input, String other) { - Model inputModel = LfParsingUtil.parseValidModel("test input", input); - Model outputModel = LfParsingUtil.parseValidModel("other", other); + private void assertSelfEquivalence(String input) { + Model inputModel = LfParsingUtil.parseValidModel("test input", input); + // need to parse twice otherwise they are trivially equivalent + // because they're the same object. + Model otherModel = LfParsingUtil.parseValidModel("other", input); - // test equivalence of the models. - Assertions.assertTrue( - new IsEqual(inputModel).doSwitch(outputModel), - String.format( - "The reformatted model is not equivalent to the original file.%n" - + "Input file:%n%s%n%n" - + "Comparand file:%n%s%n%n", - input, - other - ) - ); - } + // test equivalence of the models. + Assertions.assertTrue( + new IsEqual(inputModel).doSwitch(otherModel), + String.format("Model is not equivalent to itself. Source:%n%s", input)); + } + private void assertEquivalent(String input, String other) { + Model inputModel = LfParsingUtil.parseValidModel("test input", input); + Model outputModel = LfParsingUtil.parseValidModel("other", other); + // test equivalence of the models. + Assertions.assertTrue( + new IsEqual(inputModel).doSwitch(outputModel), + String.format( + "The reformatted model is not equivalent to the original file.%n" + + "Input file:%n%s%n%n" + + "Comparand file:%n%s%n%n", + input, other)); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java index d7862e5d25..79aa6ac1f2 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java @@ -5,9 +5,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.ast.FormattingUtils; -import org.lflang.ast.IsEqual; import org.lflang.lf.Model; import org.lflang.tests.LFInjectorProvider; import org.lflang.tests.LfParsingUtil; @@ -16,26 +14,25 @@ @InjectWith(LFInjectorProvider.class) public class FormattingUnitTests { - @Test - public void testSimple() { - assertFormatsTo( - """ + @Test + public void testSimple() { + assertFormatsTo( + """ target C reactor Main{ } """, - """ + """ target C - + reactor Main { } - """ - ); - } + """); + } - @Test - public void testAssignments() { - assertFormatsTo( - """ + @Test + public void testAssignments() { + assertFormatsTo( + """ target C reactor Destination { @@ -44,7 +41,7 @@ public void testAssignments() { state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) } """, - """ + """ target C reactor Destination { @@ -52,14 +49,13 @@ public void testAssignments() { input in: int state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} } - """ - ); - } + """); + } - @Test - public void testState() { - assertFormatsTo( - """ + @Test + public void testState() { + assertFormatsTo( + """ target Python reactor Destination { @@ -68,7 +64,7 @@ public void testState() { state list_init(1,2) // this syntax is deprecated } """, - """ + """ target Python reactor Destination { @@ -76,14 +72,13 @@ state list_init(1,2) // this syntax is deprecated state no_init: tag_t state list_init(1, 2) # this syntax is deprecated } - """ - ); - } + """); + } - @Test - public void testCppInits() { - assertIsFormatted( - """ + @Test + public void testCppInits() { + assertIsFormatted( + """ target Cpp reactor Destination { @@ -94,23 +89,17 @@ public void testCppInits() { state brace: std::vector{1, 2} state paren_list: std::vector(1, 2) } - """ - ); - } - - private void assertIsFormatted(String input) { - assertFormatsTo(input, input); - } - - private void assertFormatsTo(String input, String expectedOutput) { - Model inputModel = LfParsingUtil.parseValidModel("test input", input); - String formattedString = FormattingUtils.render(inputModel); - Assertions.assertEquals( - expectedOutput, - formattedString, - "Formatted output is different from what was expected" - ); - } - - + """); + } + + private void assertIsFormatted(String input) { + assertFormatsTo(input, input); + } + + private void assertFormatsTo(String input, String expectedOutput) { + Model inputModel = LfParsingUtil.parseValidModel("test input", input); + String formattedString = FormattingUtils.render(inputModel); + Assertions.assertEquals( + expectedOutput, formattedString, "Formatted output is different from what was expected"); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java index b3e7814f96..38387ac8a4 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java @@ -1,34 +1,33 @@ -package org.lflang.tests.compiler;/* Parsing unit tests. */ +package org.lflang.tests.compiler; /* Parsing unit tests. */ /************* - Copyright (c) 2022, The University of California at Berkeley. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2022, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ import static org.lflang.ast.ASTUtils.toDefinition; import javax.inject.Inject; - import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.testing.InjectWith; @@ -37,11 +36,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - -import org.lflang.ast.ASTUtils; import org.lflang.DefaultErrorReporter; import org.lflang.TimeUnit; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.ast.DelayedConnectionTransformation; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; @@ -49,7 +47,6 @@ import org.lflang.generator.c.CTypes; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; - import org.lflang.lf.Model; import org.lflang.lf.Reactor; import org.lflang.tests.LFInjectorProvider; @@ -58,89 +55,93 @@ @InjectWith(LFInjectorProvider.class) /** - * Test for getting minimum delay in reactions. - * Checking the actions and port's delay,then get the minimum reaction delay. + * Test for getting minimum delay in reactions. Checking the actions and port's delay,then get the + * minimum reaction delay. + * * @author Wonseo Choi * @author Yunsang Cho * @author Marten Lohstroh * @author Hokeun Kim */ -class LetInferenceTest { - - @Inject - ParseHelper parser; - - - @Test - public void testLet() throws Exception { - Model model = parser.parse(String.join( - System.getProperty("line.separator"), - "target C;", - "main reactor {", - " ramp = new Ramp();", - " print = new Print();", - " print2 = new Print();", - " ramp.y -> print.x after 20 msec;", - " ramp.y -> print2.x after 30 msec;", - "}", - "reactor Ramp {", - " logical action a(60 msec):int;", - " logical action b(100 msec):int;", - " input x:int;", - " output y:int;", - " output z:int;", - " reaction(startup) -> y, z, a, b{=", - " =}", - "}", - "reactor Print {", - " input x:int;", - " output z:int;", - " reaction(x) -> z {=", - " =}", - "}" - )); - - Assertions.assertNotNull(model); - final var ctypes = CTypes.getInstance(); - final var resource = model.eResource(); - final var transformation = new DelayedConnectionTransformation(new CDelayBodyGenerator(ctypes), ctypes, resource, true, true); - transformation.applyTransformation(ASTUtils.getAllReactors(resource)); - - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + - model.eResource().getErrors()); +class LetInferenceTest { + + @Inject ParseHelper parser; + + @Test + public void testLet() throws Exception { + Model model = + parser.parse( + String.join( + System.getProperty("line.separator"), + "target C;", + "main reactor {", + " ramp = new Ramp();", + " print = new Print();", + " print2 = new Print();", + " ramp.y -> print.x after 20 msec;", + " ramp.y -> print2.x after 30 msec;", + "}", + "reactor Ramp {", + " logical action a(60 msec):int;", + " logical action b(100 msec):int;", + " input x:int;", + " output y:int;", + " output z:int;", + " reaction(startup) -> y, z, a, b{=", + " =}", + "}", + "reactor Print {", + " input x:int;", + " output z:int;", + " reaction(x) -> z {=", + " =}", + "}")); + + Assertions.assertNotNull(model); + final var ctypes = CTypes.getInstance(); + final var resource = model.eResource(); + final var transformation = + new DelayedConnectionTransformation( + new CDelayBodyGenerator(ctypes), ctypes, resource, true, true); + transformation.applyTransformation(ASTUtils.getAllReactors(resource)); + + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model.eResource().getErrors()); + + Instantiation mainDef = null; + + TreeIterator it = model.eResource().getAllContents(); + while (it.hasNext()) { + EObject obj = it.next(); + if (!(obj instanceof Reactor reactor)) { + continue; + } + if (reactor.isMain()) { + mainDef = LfFactory.eINSTANCE.createInstantiation(); + mainDef.setName(reactor.getName()); + mainDef.setReactorClass(reactor); + } + } - Instantiation mainDef = null; + ReactorInstance mainInstance = + new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter()); - TreeIterator it = model.eResource().getAllContents(); - while (it.hasNext()) { - EObject obj = it.next(); - if (!(obj instanceof Reactor reactor)) { - continue; - } - if (reactor.isMain()) { - mainDef = LfFactory.eINSTANCE.createInstantiation(); - mainDef.setName(reactor.getName()); - mainDef.setReactorClass(reactor); - } + for (ReactorInstance reactorInstance : mainInstance.children) { + if (reactorInstance.isGeneratedDelay()) { + for (ReactionInstance reactionInstance : reactorInstance.reactions) { + Assertions.assertEquals(reactionInstance.assignLogicalExecutionTime(), TimeValue.ZERO); } - - ReactorInstance mainInstance = new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter()); - - for (ReactorInstance reactorInstance : mainInstance.children) { - if (reactorInstance.isGeneratedDelay()) { - for (ReactionInstance reactionInstance : reactorInstance.reactions) { - Assertions.assertEquals(reactionInstance.assignLogicalExecutionTime(), TimeValue.ZERO); - } - } else if (reactorInstance.getName().contains("ramp")) { - for (ReactionInstance reactionInstance : reactorInstance.reactions) { - Assertions.assertEquals(new TimeValue(20L, TimeUnit.MILLI), reactionInstance.assignLogicalExecutionTime()); - } - } else if (reactorInstance.getName().contains("print")) { - for (ReactionInstance reactionInstance : reactorInstance.reactions) { - Assertions.assertEquals(TimeValue.ZERO, reactionInstance.assignLogicalExecutionTime()); - } - } + } else if (reactorInstance.getName().contains("ramp")) { + for (ReactionInstance reactionInstance : reactorInstance.reactions) { + Assertions.assertEquals( + new TimeValue(20L, TimeUnit.MILLI), reactionInstance.assignLogicalExecutionTime()); + } + } else if (reactorInstance.getName().contains("print")) { + for (ReactionInstance reactionInstance : reactorInstance.reactions) { + Assertions.assertEquals(TimeValue.ZERO, reactionInstance.assignLogicalExecutionTime()); } + } } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java index 0122e03d8d..61fcf74328 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -1,29 +1,29 @@ /* ASTUtils Unit Tests. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.compiler; @@ -34,14 +34,12 @@ import java.util.Map; import java.util.stream.Collectors; import javax.inject.Inject; - import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.ast.ASTUtils; import org.lflang.lf.Instantiation; import org.lflang.lf.Literal; @@ -55,20 +53,17 @@ * * @author Christian Menard */ - @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) - class LinguaFrancaASTUtilsTest { - @Inject - ParseHelper parser; - - /** - * Test that isInititialized returns true for inititialized state variables - */ - @Test - public void initializedState() throws Exception { - Model model = parser.parse(""" + @Inject ParseHelper parser; + + /** Test that isInititialized returns true for inititialized state variables */ + @Test + public void initializedState() throws Exception { + Model model = + parser.parse( + """ target Cpp; main reactor Foo { state a(); @@ -79,26 +74,27 @@ public void initializedState() throws Exception { } """); - - - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + - model.eResource().getErrors()); - - model.eAllContents().forEachRemaining((obj) -> { - if (obj instanceof StateVar) { - Assertions.assertTrue(isInitialized((StateVar)obj)); - } - }); - } - - /** - * Test that isInititialized returns false for uninititialized state variables - */ - @Test - public void uninitializedState() throws Exception { - Model model = parser.parse(""" + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model.eResource().getErrors()); + + model + .eAllContents() + .forEachRemaining( + (obj) -> { + if (obj instanceof StateVar) { + Assertions.assertTrue(isInitialized((StateVar) obj)); + } + }); + } + + /** Test that isInititialized returns false for uninititialized state variables */ + @Test + public void uninitializedState() throws Exception { + Model model = + parser.parse( + """ target Cpp; main reactor Foo { state a; @@ -109,39 +105,42 @@ public void uninitializedState() throws Exception { } """); - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + - model.eResource().getErrors()); - - model.eAllContents().forEachRemaining((obj) -> { - if (obj instanceof StateVar) { - Assertions.assertFalse(isInitialized((StateVar)obj)); - } - }); - - } - /** - * Return a map from strings to instantiations given a model. - * - * @param model The model to discover instantiations in. - */ - private Map getInsts(Model model) { - return asStream(model.eAllContents()) - .filter(obj -> obj instanceof Instantiation) - .map(obj -> (Instantiation) obj) - .collect(Collectors.toMap(Instantiation::getName, it -> it)); - } - - /** - * Test reading initial values of parameters. - * This checks that the example given in the documentation of the - * ASTUtils.initialValue() function behaves as stated in the docs. - */ - @Test - public void initialValue() throws Exception { - - Model model = parser.parse(""" + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model.eResource().getErrors()); + + model + .eAllContents() + .forEachRemaining( + (obj) -> { + if (obj instanceof StateVar) { + Assertions.assertFalse(isInitialized((StateVar) obj)); + } + }); + } + /** + * Return a map from strings to instantiations given a model. + * + * @param model The model to discover instantiations in. + */ + private Map getInsts(Model model) { + return asStream(model.eAllContents()) + .filter(obj -> obj instanceof Instantiation) + .map(obj -> (Instantiation) obj) + .collect(Collectors.toMap(Instantiation::getName, it -> it)); + } + + /** + * Test reading initial values of parameters. This checks that the example given in the + * documentation of the ASTUtils.initialValue() function behaves as stated in the docs. + */ + @Test + public void initialValue() throws Exception { + + Model model = + parser.parse( + """ target C; reactor A(x:int(1)) {} reactor B(y:int(2)) { @@ -154,76 +153,80 @@ reactor C(z:int(3)) { } """); - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + - model.eResource().getErrors()); - - var map = getInsts(model); - - /* Check for this: - * initialValue(x, null) returns 1 - * initialValue(x, [a1]) returns 2 - * initialValue(x, [a2]) returns -1 - * initialValue(x, [a1, b1]) returns 3 - * initialValue(x, [a2, b1]) returns -1 - * initialValue(x, [a1, b2]) returns -2 - * initialValue(x, [a2, b2]) returns -1 - * - * initialValue(y, null) returns 2 - * initialValue(y, [a1]) throws an IllegalArgumentException - * initialValue(y, [b1]) returns 3 - * initialValue(y, [b2]) returns -2 - */ - - model.eAllContents().forEachRemaining((obj) -> { - if (obj instanceof Parameter) { - Parameter parameter = (Parameter)obj; + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model.eResource().getErrors()); + + var map = getInsts(model); + + /* Check for this: + * initialValue(x, null) returns 1 + * initialValue(x, [a1]) returns 2 + * initialValue(x, [a2]) returns -1 + * initialValue(x, [a1, b1]) returns 3 + * initialValue(x, [a2, b1]) returns -1 + * initialValue(x, [a1, b2]) returns -2 + * initialValue(x, [a2, b2]) returns -1 + * + * initialValue(y, null) returns 2 + * initialValue(y, [a1]) throws an IllegalArgumentException + * initialValue(y, [b1]) returns 3 + * initialValue(y, [b2]) returns -2 + */ + + model + .eAllContents() + .forEachRemaining( + (obj) -> { + if (obj instanceof Parameter) { + Parameter parameter = (Parameter) obj; if (parameter.getName() == "x") { - var values = ASTUtils.initialValue(parameter, null); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "1"); + var values = ASTUtils.initialValue(parameter, null); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "1"); - values = ASTUtils.initialValue(parameter, List.of(map.get("a1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "2"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "2"); - values = ASTUtils.initialValue(parameter, List.of(map.get("a2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-1"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1"); - values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "3"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "3"); - values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-1"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1"); - values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-2"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-2"); - values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-1"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1"); } else if (parameter.getName() == "y") { - var values = ASTUtils.initialValue(parameter, null); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "2"); + var values = ASTUtils.initialValue(parameter, null); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "2"); - Assertions.assertThrows(IllegalArgumentException.class, - () -> ASTUtils.initialValue(parameter, List.of(map.get("a1")))); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> ASTUtils.initialValue(parameter, List.of(map.get("a1")))); - values = ASTUtils.initialValue(parameter, List.of(map.get("b1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "3"); + values = ASTUtils.initialValue(parameter, List.of(map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "3"); - values = ASTUtils.initialValue(parameter, List.of(map.get("b2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-2"); + values = ASTUtils.initialValue(parameter, List.of(map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-2"); } - } - }); - } + } + }); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java index d7e2af48fc..516c712498 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java @@ -1,33 +1,34 @@ /* Dependency analysis unit tests. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.compiler; -import com.google.inject.Inject; +import static org.lflang.ast.ASTUtils.*; +import com.google.inject.Inject; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.testing.InjectWith; @@ -44,57 +45,56 @@ import org.lflang.lf.Model; import org.lflang.lf.Reactor; import org.lflang.tests.LFInjectorProvider; -import static org.lflang.ast.ASTUtils.*; @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) /** * A collection of tests to ensure dependency analysis is done correctly. + * * @author Marten Lohstroh */ class LinguaFrancaDependencyAnalysisTest { - @Inject - ParseHelper parser; - - /** - * Check that circular dependencies between reactions are detected. - */ - @Test - public void cyclicDependency() throws Exception { - // Java 17: -// String testCase = """ -// target C; -// -// reactor Clock { -// timer t(0, 10 msec); -// input x:int; -// output y:int; -// reaction(t) -> y {= -// -// =} -// reaction(x) -> y {= -// -// =} -// } -// -// reactor A { -// input x:int; -// output y:int; -// reaction(x) -> y {= -// -// =} -// } -// -// main reactor Loop { -// c = new Clock(); -// a = new A(); -// c.y -> a.x; -// a.y -> c.x; -// } -// """ -// Java 11: - String testCase = String.join(System.getProperty("line.separator"), + @Inject ParseHelper parser; + + /** Check that circular dependencies between reactions are detected. */ + @Test + public void cyclicDependency() throws Exception { + // Java 17: + // String testCase = """ + // target C; + // + // reactor Clock { + // timer t(0, 10 msec); + // input x:int; + // output y:int; + // reaction(t) -> y {= + // + // =} + // reaction(x) -> y {= + // + // =} + // } + // + // reactor A { + // input x:int; + // output y:int; + // reaction(x) -> y {= + // + // =} + // } + // + // main reactor Loop { + // c = new Clock(); + // a = new A(); + // c.y -> a.x; + // a.y -> c.x; + // } + // """ + // Java 11: + String testCase = + String.join( + System.getProperty("line.separator"), "target C;", "", "reactor Clock {", @@ -122,38 +122,37 @@ public void cyclicDependency() throws Exception { " a = new A();", " c.y -> a.x;", " a.y -> c.x;", - "}" - ); - Model model = parser.parse(testCase); - - Assertions.assertNotNull(model); - Instantiation mainDef = null; - TreeIterator it = model.eResource().getAllContents(); - while (it.hasNext()) { - EObject obj = it.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor reactor = (Reactor) obj; - if (reactor.isMain()) { - // Creating an definition for the main reactor because - // there isn't one. - mainDef = LfFactory.eINSTANCE.createInstantiation(); - mainDef.setName(reactor.getName()); - mainDef.setReactorClass(reactor); - } - } - - ReactorInstance instance = new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter()); - Assertions.assertFalse(instance.getCycles().isEmpty()); + "}"); + Model model = parser.parse(testCase); + + Assertions.assertNotNull(model); + Instantiation mainDef = null; + TreeIterator it = model.eResource().getAllContents(); + while (it.hasNext()) { + EObject obj = it.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor reactor = (Reactor) obj; + if (reactor.isMain()) { + // Creating an definition for the main reactor because + // there isn't one. + mainDef = LfFactory.eINSTANCE.createInstantiation(); + mainDef.setName(reactor.getName()); + mainDef.setReactorClass(reactor); + } } - /** - * Check that circular instantiations are detected. - */ - @Test - public void circularInstantiation() throws Exception { - String testCase = """ + ReactorInstance instance = + new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter()); + Assertions.assertFalse(instance.getCycles().isEmpty()); + } + + /** Check that circular instantiations are detected. */ + @Test + public void circularInstantiation() throws Exception { + String testCase = + """ target C; reactor X { @@ -167,14 +166,13 @@ public void circularInstantiation() throws Exception { q = new X(); } """; - Model model = parser.parse(testCase); - - Assertions.assertNotNull(model); + Model model = parser.parse(testCase); - ModelInfo info = new ModelInfo(); - info.update(model, new DefaultErrorReporter()); - Assertions.assertTrue(info.instantiationGraph.hasCycles() == true, - "Did not detect cyclic instantiation."); - } + Assertions.assertNotNull(model); + ModelInfo info = new ModelInfo(); + info.update(model, new DefaultErrorReporter()); + Assertions.assertTrue( + info.instantiationGraph.hasCycles() == true, "Did not detect cyclic instantiation."); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java index fc66c7ed57..377e3e7a32 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java @@ -1,66 +1,63 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.compiler; +import com.google.inject.Inject; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.lf.Model; import org.lflang.tests.LFInjectorProvider; -import com.google.inject.Inject; - -/** - * Test harness for ensuring that grammar captures - * all corner cases. - */ +/** Test harness for ensuring that grammar captures all corner cases. */ @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) class LinguaFrancaParsingTest { - @Inject - ParseHelper parser; + @Inject ParseHelper parser; - @Test - public void checkForTarget() throws Exception { - String testCase = """ + @Test + public void checkForTarget() throws Exception { + String testCase = + """ targett C; reactor Foo { } """; - Model result = parser.parse(testCase); - Assertions.assertNotNull(result); - Assertions.assertFalse(result.eResource().getErrors().isEmpty(), "Failed to catch misspelled target keyword."); - } + Model result = parser.parse(testCase); + Assertions.assertNotNull(result); + Assertions.assertFalse( + result.eResource().getErrors().isEmpty(), "Failed to catch misspelled target keyword."); + } - @Test - public void testAttributes() throws Exception { - String testCase = """ + @Test + public void testAttributes() throws Exception { + String testCase = + """ target C; @label("somethign", "else") @ohio() @@ -74,16 +71,17 @@ public void testAttributes() throws Exception { } """; - parseWithoutError(testCase); - } + parseWithoutError(testCase); + } - @Test - public void testAttributeContexts() throws Exception { - String testCase = """ + @Test + public void testAttributeContexts() throws Exception { + String testCase = + """ target C; @a main reactor(@b parm: int) { - + @ohio reaction() {==} @ohio logical action f; @ohio timer t; @@ -91,28 +89,28 @@ main reactor(@b parm: int) { @ohio output q2: int; } """; - parseWithoutError(testCase); - } + parseWithoutError(testCase); + } - @Test - public void testTokenizeEmptyWidth() throws Exception { - String testCase = """ + @Test + public void testTokenizeEmptyWidth() throws Exception { + String testCase = + """ target C; main reactor { state foo: int[]; state foo: int[ ]; //spaces are allowed } """; - parseWithoutError(testCase); - } - - private Model parseWithoutError(String s) throws Exception { - Model model = parser.parse(s); - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + - model.eResource().getErrors()); - return model; - } + parseWithoutError(testCase); + } + private Model parseWithoutError(String s) throws Exception { + Model model = parser.parse(s); + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model.eResource().getErrors()); + return model; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaScopingTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaScopingTest.java index 8587675479..404d948264 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaScopingTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaScopingTest.java @@ -1,129 +1,125 @@ /* Scoping unit tests. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.compiler; import com.google.inject.Inject; +import com.google.inject.Provider; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; -import org.lflang.lf.Model; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; import org.eclipse.xtext.testing.validation.ValidationTestHelper; -import org.lflang.lf.LfPackage; -import org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic; -import org.lflang.tests.LFInjectorProvider; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.lflang.generator.LFGenerator; -import com.google.inject.Provider; +import org.lflang.lf.LfPackage; +import org.lflang.lf.Model; +import org.lflang.tests.LFInjectorProvider; @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) /** - * Test harness for ensuring that cross-references are - * established correctly and reported when faulty. + * Test harness for ensuring that cross-references are established correctly and reported when + * faulty. */ public class LinguaFrancaScopingTest { - @Inject - ParseHelper parser; - - @Inject - LFGenerator generator; - - @Inject - JavaIoFileSystemAccess fileAccess; - - @Inject - Provider resourceSetProvider; - - @Inject - ValidationTestHelper validator; - - /** - * Ensure that invalid references to contained reactors are reported. - */ - @Test - public void unresolvedReactorReference() throws Exception { -// Java 17: -// Model model = """ -// target C; -// reactor From { -// output y:int; -// } -// reactor To { -// input x:int; -// } -// -// main reactor { -// a = new From(); -// d = new To(); -// s.y -> d.x; -// } -// """; -// Java 11: - Model model = parser.parse(String.join( - System.getProperty("line.separator"), - "target C;", - "reactor From {", - " output y:int;", - "}", - "reactor To {", - " input x:int;", - "}", - "", - "main reactor {", - " a = new From();", - " d = new To();", - " s.y -> d.x;", - "}" - )); - - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing."); - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Instantiation 's'"); - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Variable 'y'"); - } - - - /** - * Ensure that invalid references to ports - * of contained reactors are reported. - */ - @Test - public void unresolvedHierarchicalPortReference() throws Exception { - Model model = parser.parse(""" + @Inject ParseHelper parser; + + @Inject LFGenerator generator; + + @Inject JavaIoFileSystemAccess fileAccess; + + @Inject Provider resourceSetProvider; + + @Inject ValidationTestHelper validator; + + /** Ensure that invalid references to contained reactors are reported. */ + @Test + public void unresolvedReactorReference() throws Exception { + // Java 17: + // Model model = """ + // target C; + // reactor From { + // output y:int; + // } + // reactor To { + // input x:int; + // } + // + // main reactor { + // a = new From(); + // d = new To(); + // s.y -> d.x; + // } + // """; + // Java 11: + Model model = + parser.parse( + String.join( + System.getProperty("line.separator"), + "target C;", + "reactor From {", + " output y:int;", + "}", + "reactor To {", + " input x:int;", + "}", + "", + "main reactor {", + " a = new From();", + " d = new To();", + " s.y -> d.x;", + "}")); + + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing."); + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Instantiation 's'"); + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Variable 'y'"); + } + + /** Ensure that invalid references to ports of contained reactors are reported. */ + @Test + public void unresolvedHierarchicalPortReference() throws Exception { + Model model = + parser.parse( + """ target C; reactor From { output y:int; @@ -138,59 +134,73 @@ public void unresolvedHierarchicalPortReference() throws Exception { a.x -> d.y; } """); - - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing."); - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Variable 'x'"); - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Variable 'y'"); - } - - @Test - public void unresolvedReferenceInTriggerClause() throws Exception { - Model model = parser.parse(""" + + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing."); + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Variable 'x'"); + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Variable 'y'"); + } + + @Test + public void unresolvedReferenceInTriggerClause() throws Exception { + Model model = + parser.parse( + """ target C; main reactor { reaction(unknown) {==} } """); - - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Variable 'unknown'."); - } - - @Test - public void unresolvedReferenceInUseClause() throws Exception { - Model model = parser.parse(""" + + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Variable 'unknown'."); + } + + @Test + public void unresolvedReferenceInUseClause() throws Exception { + Model model = + parser.parse( + """ target C; main reactor { reaction() unknown {==} } """); - - - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Variable 'unknown'."); - } - - @Test - public void unresolvedReferenceInEffectsClause() throws Exception { - Model model = parser.parse(""" + + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Variable 'unknown'."); + } + + @Test + public void unresolvedReferenceInEffectsClause() throws Exception { + Model model = + parser.parse( + """ target C; main reactor { reaction() -> unknown {==} } """); - validator.assertError(model, LfPackage.eINSTANCE.getVarRef(), - XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, - "Couldn't resolve reference to Variable 'unknown'."); - } - + validator.assertError( + model, + LfPackage.eINSTANCE.getVarRef(), + XtextLinkingDiagnostic.LINKING_DIAGNOSTIC, + "Couldn't resolve reference to Variable 'unknown'."); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index aa285a2e32..72e3574b33 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -1,36 +1,36 @@ /* Scoping unit tests. */ /************* - Copyright (c) 2019, The University of California at Berkeley. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.tests.compiler; +import com.google.inject.Inject; import java.util.LinkedList; import java.util.List; import java.util.Map; - import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; @@ -39,7 +39,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.TargetProperty.ArrayType; @@ -56,12 +55,9 @@ import org.lflang.tests.LFInjectorProvider; import org.lflang.util.StringUtil; -import com.google.inject.Inject; - @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) - /** * Collection of unit tests to ensure validation is done correctly. * @@ -73,75 +69,76 @@ */ public class LinguaFrancaValidationTest { - @Inject - ParseHelper parser; - - @Inject - ValidationTestHelper validator; - - /** - * Helper function to parse a Lingua Franca program and expect no errors. - * - * @return A model representing the parsed string. - */ - private Model parseWithoutError(String s) throws Exception { - Model model = parser.parse(s); - Assertions.assertNotNull(model); - Assertions.assertTrue(model.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + - model.eResource().getErrors()); - return model; - } - - /** - * Helper function to parse a Lingua Franca program and expect errors. - * - * @return A model representing the parsed string. - */ - private Model parseWithError(String s) throws Exception { - Model model = parser.parse(s); - Assertions.assertNotNull(model); - Assertions.assertFalse(model.eResource().getErrors().isEmpty()); - return model; - } - - /** - * Ensure that duplicate identifiers for actions reported. - */ - @Test - public void duplicateVariable() throws Exception { - String testCase = """ + @Inject ParseHelper parser; + + @Inject ValidationTestHelper validator; + + /** + * Helper function to parse a Lingua Franca program and expect no errors. + * + * @return A model representing the parsed string. + */ + private Model parseWithoutError(String s) throws Exception { + Model model = parser.parse(s); + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model.eResource().getErrors()); + return model; + } + + /** + * Helper function to parse a Lingua Franca program and expect errors. + * + * @return A model representing the parsed string. + */ + private Model parseWithError(String s) throws Exception { + Model model = parser.parse(s); + Assertions.assertNotNull(model); + Assertions.assertFalse(model.eResource().getErrors().isEmpty()); + return model; + } + + /** Ensure that duplicate identifiers for actions reported. */ + @Test + public void duplicateVariable() throws Exception { + String testCase = + """ target TypeScript; main reactor Foo { logical action bar; physical action bar; } """; - validator.assertError(parseWithoutError(testCase), - LfPackage.eINSTANCE.getAction(), - null, - "Duplicate Variable 'bar' in Reactor 'Foo'"); - } - + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAction(), + null, + "Duplicate Variable 'bar' in Reactor 'Foo'"); + } - /** - * Check that reactors in C++ cannot be named preamble - */ - @Test - public void disallowReactorCalledPreamble() throws Exception { - Model model_no_errors = parser.parse(""" + /** Check that reactors in C++ cannot be named preamble */ + @Test + public void disallowReactorCalledPreamble() throws Exception { + Model model_no_errors = + parser.parse( + """ target Cpp; main reactor { } """); - Model model_error_1 = parser.parse(""" + Model model_error_1 = + parser.parse( + """ target Cpp; reactor Preamble { } """); - Model model_error_2 = parser.parse(""" + Model model_error_2 = + parser.parse( + """ target Cpp; reactor Preamble { } @@ -149,151 +146,177 @@ public void disallowReactorCalledPreamble() throws Exception { } """); - Assertions.assertNotNull(model_no_errors); - Assertions.assertNotNull(model_error_1); - Assertions.assertNotNull(model_error_2); - Assertions.assertTrue(model_no_errors.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " - + model_no_errors.eResource().getErrors()); - Assertions.assertTrue(model_error_1.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + model_error_1.eResource().getErrors()); - Assertions.assertTrue(model_error_2.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " + model_error_2.eResource().getErrors()); - - validator.assertNoIssues(model_no_errors); - validator.assertError(model_error_1, - LfPackage.eINSTANCE.getReactor(), - null, - "Reactor cannot be named 'Preamble'"); - validator.assertError(model_error_2, - LfPackage.eINSTANCE.getReactor(), - null, - "Reactor cannot be named 'Preamble'"); - } - - - /** - * Ensure that "__" is not allowed at the start of an input name. - */ - @Test - public void disallowUnderscoreInputs() throws Exception { - String testCase = """ + Assertions.assertNotNull(model_no_errors); + Assertions.assertNotNull(model_error_1); + Assertions.assertNotNull(model_error_2); + Assertions.assertTrue( + model_no_errors.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model_no_errors.eResource().getErrors()); + Assertions.assertTrue( + model_error_1.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model_error_1.eResource().getErrors()); + Assertions.assertTrue( + model_error_2.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model_error_2.eResource().getErrors()); + + validator.assertNoIssues(model_no_errors); + validator.assertError( + model_error_1, + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor cannot be named 'Preamble'"); + validator.assertError( + model_error_2, + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor cannot be named 'Preamble'"); + } + + /** Ensure that "__" is not allowed at the start of an input name. */ + @Test + public void disallowUnderscoreInputs() throws Exception { + String testCase = + """ target TypeScript; main reactor { input __bar; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInput(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __bar"); + } - @Test - public void disallowMainWithDifferentNameThanFile() throws Exception { - String testCase = """ + @Test + public void disallowMainWithDifferentNameThanFile() throws Exception { + String testCase = + """ target C; main reactor Foo {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Name of main reactor must match the file name (or be omitted)"); - } - + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Name of main reactor must match the file name (or be omitted)"); + } - /** - * Ensure that "__" is not allowed at the start of an output name. - */ - @Test - public void disallowUnderscoreOutputs() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of an output name. */ + @Test + public void disallowUnderscoreOutputs() throws Exception { + String testCase = + """ target TypeScript; main reactor Foo { output __bar; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getOutput(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __bar"); + } - /** - * Ensure that "__" is not allowed at the start of an action name. - */ - @Test - public void disallowUnderscoreActions() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of an action name. */ + @Test + public void disallowUnderscoreActions() throws Exception { + String testCase = + """ target TypeScript; main reactor Foo { logical action __bar; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAction(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __bar"); + } - /** - * Ensure that "__" is not allowed at the start of a timer name. - */ - @Test - public void disallowUnderscoreTimers() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of a timer name. */ + @Test + public void disallowUnderscoreTimers() throws Exception { + String testCase = + """ target TypeScript; main reactor Foo { timer __bar(0); } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getTimer(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __bar"); + } - /** - * Ensure that "__" is not allowed at the start of a parameter name. - */ - @Test - public void disallowUnderscoreParameters() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of a parameter name. */ + @Test + public void disallowUnderscoreParameters() throws Exception { + String testCase = + """ target TypeScript; main reactor Foo(__bar) { } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getParameter(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __bar"); + } - /** - * Ensure that "__" is not allowed at the start of an state name. - */ - @Test - public void disallowUnderscoreStates() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of an state name. */ + @Test + public void disallowUnderscoreStates() throws Exception { + String testCase = + """ target TypeScript; main reactor Foo { state __bar; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getStateVar(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __bar"); + } - /** - * Ensure that "__" is not allowed at the start of a reactor definition name. - */ - @Test - public void disallowUnderscoreReactorDef() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of a reactor definition name. */ + @Test + public void disallowUnderscoreReactorDef() throws Exception { + String testCase = + """ target TypeScript; reactor __Foo { } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __Foo"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __Foo"); + } - /** - * Ensure that "__" is not allowed at the start of a reactor instantiation name. - */ - @Test - public void disallowUnderscoreReactorInstantiation() throws Exception { - String testCase = """ + /** Ensure that "__" is not allowed at the start of a reactor instantiation name. */ + @Test + public void disallowUnderscoreReactorInstantiation() throws Exception { + String testCase = + """ target TypeScript; reactor Foo { } @@ -301,16 +324,19 @@ public void disallowUnderscoreReactorInstantiation() throws Exception { __x = new Foo(); } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __x"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInstantiation(), + null, + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor" + + " definitions, and reactor instantiation) may not start with \"__\": __x"); + } - /** - * Disallow connection to port that is effect of reaction. - */ - @Test - public void connectionToEffectPort() throws Exception { - String testCase = """ + /** Disallow connection to port that is effect of reaction. */ + @Test + public void connectionToEffectPort() throws Exception { + String testCase = + """ target C; reactor Foo { output out:int; @@ -319,20 +345,22 @@ public void connectionToEffectPort() throws Exception { output out:int; x = new Foo(); x.out -> out; - reaction(startup) -> out {= + reaction(startup) -> out {= =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, - "Cannot connect: Port named 'out' is already effect of a reaction."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getConnection(), + null, + "Cannot connect: Port named 'out' is already effect of a reaction."); + } - /** - * Disallow connection to port that is effect of reaction. - */ - @Test - public void connectionToEffectPort2() throws Exception { - String testCase = """ + /** Disallow connection to port that is effect of reaction. */ + @Test + public void connectionToEffectPort2() throws Exception { + String testCase = + """ target C; reactor Foo { input inp:int; @@ -344,21 +372,25 @@ public void connectionToEffectPort2() throws Exception { y = new Foo(); y.out -> x.inp; - reaction(startup) -> x.inp {= + reaction(startup) -> x.inp {= =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, - "Cannot connect: Port named 'inp' is already effect of a reaction."); - } - - /** - * Allow connection to the port of a contained reactor if another port with same name is effect - * of a reaction. - */ - @Test - public void connectionToEffectPort3() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getConnection(), + null, + "Cannot connect: Port named 'inp' is already effect of a reaction."); + } + + /** + * Allow connection to the port of a contained reactor if another port with same name is effect of + * a reaction. + */ + @Test + public void connectionToEffectPort3() throws Exception { + String testCase = + """ target C; reactor Foo { @@ -373,16 +405,17 @@ public void connectionToEffectPort3() throws Exception { =} } """; - validator.assertNoErrors(parseWithoutError(testCase)); - } + validator.assertNoErrors(parseWithoutError(testCase)); + } - /** - * Allow connection to the port of a contained reactor if another port with same name is effect - * of a reaction. - */ - @Test - public void connectionToEffectPort3_5() throws Exception { - String testCase = """ + /** + * Allow connection to the port of a contained reactor if another port with same name is effect of + * a reaction. + */ + @Test + public void connectionToEffectPort3_5() throws Exception { + String testCase = + """ target C; reactor Foo { @@ -397,19 +430,23 @@ public void connectionToEffectPort3_5() throws Exception { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getVariable(), null, - "Main reactor cannot have inputs."); - } - - /** - * Disallow connection to the port of a contained reactor if the same port is effect of a - * reaction. - */ - @Test - public void connectionToEffectPort4() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getVariable(), + null, + "Main reactor cannot have inputs."); + } + + /** + * Disallow connection to the port of a contained reactor if the same port is effect of a + * reaction. + */ + @Test + public void connectionToEffectPort4() throws Exception { + String testCase = + """ target C; - + reactor Foo { input in:int; } @@ -421,16 +458,18 @@ public void connectionToEffectPort4() throws Exception { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, - "Cannot connect: Port named 'in' is already effect of a reaction."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getConnection(), + null, + "Cannot connect: Port named 'in' is already effect of a reaction."); + } - /** - * Disallow connection of multiple ports to the same input port. - */ - @Test - public void multipleConnectionsToInputTest() throws Exception { - String testCase = """ + /** Disallow connection of multiple ports to the same input port. */ + @Test + public void multipleConnectionsToInputTest() throws Exception { + String testCase = + """ target C; reactor Source { output out:int; @@ -446,32 +485,35 @@ public void multipleConnectionsToInputTest() throws Exception { src.out -> sink.in; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, - "Cannot connect: Port named 'in' may only appear once on the right side of a connection."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getConnection(), + null, + "Cannot connect: Port named 'in' may only appear once on the right side of a connection."); + } - /** - * Detect cycles in the instantiation graph. - */ - @Test - public void detectInstantiationCycle() throws Exception { - String testCase = """ + /** Detect cycles in the instantiation graph. */ + @Test + public void detectInstantiationCycle() throws Exception { + String testCase = + """ target C; reactor Contained { x = new Contained(); } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), - null, "Instantiation is part of a cycle: Contained"); - } - + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInstantiation(), + null, + "Instantiation is part of a cycle: Contained"); + } - /** - * Detect cycles in the instantiation graph. - */ - @Test - public void detectInstantiationCycle2() throws Exception { - String testCase = """ + /** Detect cycles in the instantiation graph. */ + @Test + public void detectInstantiationCycle2() throws Exception { + String testCase = + """ target C; reactor Intermediate { x = new Contained(); @@ -481,20 +523,25 @@ public void detectInstantiationCycle2() throws Exception { } """; - Model model = parseWithoutError(testCase); - validator.assertError(model, LfPackage.eINSTANCE.getInstantiation(), - null, "Instantiation is part of a cycle: Intermediate, Contained."); - validator.assertError(model, LfPackage.eINSTANCE.getInstantiation(), - null, "Instantiation is part of a cycle: Intermediate, Contained."); - } + Model model = parseWithoutError(testCase); + validator.assertError( + model, + LfPackage.eINSTANCE.getInstantiation(), + null, + "Instantiation is part of a cycle: Intermediate, Contained."); + validator.assertError( + model, + LfPackage.eINSTANCE.getInstantiation(), + null, + "Instantiation is part of a cycle: Intermediate, Contained."); + } - /** - * Detect causality loop. - */ - @Test - public void detectCausalityLoop() throws Exception { + /** Detect causality loop. */ + @Test + public void detectCausalityLoop() throws Exception { - String testCase = """ + String testCase = + """ target C; reactor X { @@ -511,19 +558,24 @@ public void detectCausalityLoop() throws Exception { b.y -> a.x } """; - Model model = parseWithoutError(testCase); - validator.assertError(model, LfPackage.eINSTANCE.getReaction(), - null, "Reaction triggers involved in cyclic dependency in reactor X: x."); - validator.assertError(model, LfPackage.eINSTANCE.getReaction(), - null, "Reaction effects involved in cyclic dependency in reactor X: y."); - } - - /** - * Let cyclic dependencies be broken by "after" clauses. - */ - @Test - public void afterBreaksCycle() throws Exception { - String testCase = """ + Model model = parseWithoutError(testCase); + validator.assertError( + model, + LfPackage.eINSTANCE.getReaction(), + null, + "Reaction triggers involved in cyclic dependency in reactor X: x."); + validator.assertError( + model, + LfPackage.eINSTANCE.getReaction(), + null, + "Reaction effects involved in cyclic dependency in reactor X: y."); + } + + /** Let cyclic dependencies be broken by "after" clauses. */ + @Test + public void afterBreaksCycle() throws Exception { + String testCase = + """ target C reactor X { @@ -541,16 +593,14 @@ public void afterBreaksCycle() throws Exception { } """; - validator.assertNoErrors(parseWithoutError(testCase)); - } - + validator.assertNoErrors(parseWithoutError(testCase)); + } - /** - * Let cyclic dependencies be broken by "after" clauses with zero delay. - */ - @Test - public void afterBreaksCycle2() throws Exception { - String testCase = """ + /** Let cyclic dependencies be broken by "after" clauses with zero delay. */ + @Test + public void afterBreaksCycle2() throws Exception { + String testCase = + """ target C reactor X { @@ -567,16 +617,14 @@ public void afterBreaksCycle2() throws Exception { b.y -> a.x } """; - validator.assertNoErrors(parseWithoutError(testCase)); - } + validator.assertNoErrors(parseWithoutError(testCase)); + } - - /** - * Let cyclic dependencies be broken by "after" clauses with zero delay and no units. - */ - @Test - public void afterBreaksCycle3() throws Exception { - String testCase = """ + /** Let cyclic dependencies be broken by "after" clauses with zero delay and no units. */ + @Test + public void afterBreaksCycle3() throws Exception { + String testCase = + """ target C reactor X { @@ -593,15 +641,14 @@ public void afterBreaksCycle3() throws Exception { b.y -> a.x } """; - validator.assertNoErrors(parseWithoutError(testCase)); - } + validator.assertNoErrors(parseWithoutError(testCase)); + } - /** - * Detect missing units in "after" clauses with delay greater than zero. - */ - @Test - public void nonzeroAfterMustHaveUnits() throws Exception { - String testCase = """ + /** Detect missing units in "after" clauses with delay greater than zero. */ + @Test + public void nonzeroAfterMustHaveUnits() throws Exception { + String testCase = + """ target C reactor X { @@ -617,17 +664,18 @@ public void nonzeroAfterMustHaveUnits() throws Exception { a.y -> b.x after 1 } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), - null, "Missing time unit."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getConnection(), + null, + "Missing time unit."); + } - - /** - * Report non-zero time value without units. - */ - @Test - public void nonZeroTimeValueWithoutUnits() throws Exception { - String testCase = """ + /** Report non-zero time value without units. */ + @Test + public void nonZeroTimeValueWithoutUnits() throws Exception { + String testCase = + """ target C; main reactor { timer t(42, 1 sec); @@ -636,15 +684,15 @@ public void nonZeroTimeValueWithoutUnits() throws Exception { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); - } + validator.assertError( + parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); + } - /** - * Report reference to non-time parameter in time argument. - */ - @Test - public void parameterTypeMismatch() throws Exception { - String testCase = """ + /** Report reference to non-time parameter in time argument. */ + @Test + public void parameterTypeMismatch() throws Exception { + String testCase = + """ target C; main reactor (p:int(0)) { timer t(p, 1 sec); @@ -653,16 +701,18 @@ main reactor (p:int(0)) { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), - null, "Referenced parameter is not of time type."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getTimer(), + null, + "Referenced parameter is not of time type."); + } - /** - * Report inappropriate literal in time argument. - */ - @Test - public void targetCodeInTimeArgument() throws Exception { - String testCase = """ + /** Report inappropriate literal in time argument. */ + @Test + public void targetCodeInTimeArgument() throws Exception { + String testCase = + """ target C; main reactor { timer t({=foo()=}, 1 sec); @@ -671,17 +721,15 @@ public void targetCodeInTimeArgument() throws Exception { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), - null, "Invalid time value."); - } - + validator.assertError( + parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Invalid time value."); + } - /** - * Report overflowing deadline. - */ - @Test - public void overflowingDeadlineC() throws Exception { - String testCase = """ + /** Report overflowing deadline. */ + @Test + public void overflowingDeadlineC() throws Exception { + String testCase = + """ target C; main reactor { timer t; @@ -691,18 +739,18 @@ public void overflowingDeadlineC() throws Exception { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), null, - "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + - " nanoseconds."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getDeadline(), + null, + "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } - - /** - * Report overflowing parameter. - */ - @Test - public void overflowingParameterC() throws Exception { - String testCase = """ + /** Report overflowing parameter. */ + @Test + public void overflowingParameterC() throws Exception { + String testCase = + """ target C; main reactor(d:time(40 hours)) { timer t; @@ -712,18 +760,20 @@ main reactor(d:time(40 hours)) { =} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), null, - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } - - - /** - * Report overflowing assignment. - */ - @Test - public void overflowingAssignmentC() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getParameter(), + null, + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds."); + } + + /** Report overflowing assignment. */ + @Test + public void overflowingAssignmentC() throws Exception { + String testCase = + """ target C; reactor Print(d:time(39 hours)) { timer t; @@ -736,17 +786,20 @@ reactor Print(d:time(39 hours)) { p = new Print(d=40 hours); } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAssignment(), null, - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } - - /** - * Report missing trigger. - */ - @Test - public void missingTrigger() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAssignment(), + null, + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds."); + } + + /** Report missing trigger. */ + @Test + public void missingTrigger() throws Exception { + String testCase = + """ target C; reactor X { reaction() {= @@ -754,112 +807,148 @@ public void missingTrigger() throws Exception { =} } """; - validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), null, - "Reaction has no trigger."); - } + validator.assertWarning( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReaction(), + null, + "Reaction has no trigger."); + } - /** - * Test warnings and errors for the target dependent preamble visibility qualifiers - */ - @Test - public void testPreambleVisibility() throws Exception { - for (Target target : Target.values()) { - for (Visibility visibility : Visibility.values()) { - Model model_reactor_scope = parseWithoutError(""" + /** Test warnings and errors for the target dependent preamble visibility qualifiers */ + @Test + public void testPreambleVisibility() throws Exception { + for (Target target : Target.values()) { + for (Visibility visibility : Visibility.values()) { + Model model_reactor_scope = + parseWithoutError( + """ target %s; reactor Foo { %spreamble {==} } - """.formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); + """ + .formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); - Model model_file_scope = parseWithoutError(""" + Model model_file_scope = + parseWithoutError( + """ target %s; %spreamble {==} reactor Foo { } - """.formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); + """ + .formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); - Model model_no_preamble = parseWithoutError(""" + Model model_no_preamble = + parseWithoutError( + """ target %s; reactor Foo { } - """.formatted(target)); - - validator.assertNoIssues(model_no_preamble); - - if (target == Target.CPP) { - if (visibility == Visibility.NONE) { - validator.assertError(model_file_scope, LfPackage.eINSTANCE.getPreamble(), null, - "Preambles for the C++ target need a visibility qualifier (private or public)!"); - validator.assertError(model_reactor_scope, LfPackage.eINSTANCE.getPreamble(), null, - "Preambles for the C++ target need a visibility qualifier (private or public)!"); - } else { - validator.assertNoIssues(model_file_scope); - validator.assertNoIssues(model_reactor_scope); - } - } else { - if (visibility == Visibility.NONE) { - validator.assertNoIssues(model_file_scope); - validator.assertNoIssues(model_reactor_scope); - } else { - validator.assertWarning(model_file_scope, LfPackage.eINSTANCE.getPreamble(), null, - String.format("The %s qualifier has no meaning for the %s target. It should be removed.", visibility, target.name())); - validator.assertWarning(model_reactor_scope, LfPackage.eINSTANCE.getPreamble(), null, - String.format("The %s qualifier has no meaning for the %s target. It should be removed.", visibility, target.name())); - } - } - } + """ + .formatted(target)); + + validator.assertNoIssues(model_no_preamble); + + if (target == Target.CPP) { + if (visibility == Visibility.NONE) { + validator.assertError( + model_file_scope, + LfPackage.eINSTANCE.getPreamble(), + null, + "Preambles for the C++ target need a visibility qualifier (private or public)!"); + validator.assertError( + model_reactor_scope, + LfPackage.eINSTANCE.getPreamble(), + null, + "Preambles for the C++ target need a visibility qualifier (private or public)!"); + } else { + validator.assertNoIssues(model_file_scope); + validator.assertNoIssues(model_reactor_scope); + } + } else { + if (visibility == Visibility.NONE) { + validator.assertNoIssues(model_file_scope); + validator.assertNoIssues(model_reactor_scope); + } else { + validator.assertWarning( + model_file_scope, + LfPackage.eINSTANCE.getPreamble(), + null, + String.format( + "The %s qualifier has no meaning for the %s target. It should be removed.", + visibility, target.name())); + validator.assertWarning( + model_reactor_scope, + LfPackage.eINSTANCE.getPreamble(), + null, + String.format( + "The %s qualifier has no meaning for the %s target. It should be removed.", + visibility, target.name())); + } } + } } + } - @Test - public void testInheritanceSupport() throws Exception { - for (Target target : Target.values()) { - Model model = parseWithoutError(""" + @Test + public void testInheritanceSupport() throws Exception { + for (Target target : Target.values()) { + Model model = + parseWithoutError( + """ target %s reactor A{} reactor B extends A{} - """.formatted(target)); - - if (target.supportsInheritance()) { - validator.assertNoIssues(model); - } else { - validator.assertError(model, LfPackage.eINSTANCE.getReactor(), null, - "The " + target.getDisplayName() + " target does not support reactor inheritance."); - } - } + """ + .formatted(target)); + + if (target.supportsInheritance()) { + validator.assertNoIssues(model); + } else { + validator.assertError( + model, + LfPackage.eINSTANCE.getReactor(), + null, + "The " + target.getDisplayName() + " target does not support reactor inheritance."); + } } + } - @Test - public void testFederationSupport() throws Exception { - for (Target target : Target.values()) { - Model model = parseWithoutError(""" + @Test + public void testFederationSupport() throws Exception { + for (Target target : Target.values()) { + Model model = + parseWithoutError( + """ target %s federated reactor {} - """.formatted(target)); - - if (target.supportsFederated()) { - validator.assertNoIssues(model); - } else { - validator.assertError(model, LfPackage.eINSTANCE.getReactor(), null, - "The " + target.getDisplayName() + " target does not support federated execution."); - } - } + """ + .formatted(target)); + + if (target.supportsFederated()) { + validator.assertNoIssues(model); + } else { + validator.assertError( + model, + LfPackage.eINSTANCE.getReactor(), + null, + "The " + target.getDisplayName() + " target does not support federated execution."); + } } + } - - /** - * Tests for state and parameter declarations, including native lists. - */ - @Test - public void stateAndParameterDeclarationsInC() throws Exception { - String testCase = """ + /** Tests for state and parameter declarations, including native lists. */ + @Test + 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 + h:time = "bla", // ERROR: not a type q:time(1 msec, 2 msec), // ERROR: not a list y:int = t // ERROR: init using parameter ) { @@ -870,878 +959,1039 @@ reactor Bar(a(0), // ERROR: type missing } """; - Model model = parseWithoutError(testCase); - - - validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, - "Type declaration missing."); - validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, - "Parameter must have a default value."); - validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, - "Missing time unit."); - validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, - "Invalid time value."); - validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, - "Expected exactly one time value."); - validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, - "Parameter cannot be initialized using parameter."); - validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, - "Missing time unit."); - validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, - "Referenced parameter is not of time type."); - validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, - "Invalid time value."); - validator.assertError(model, LfPackage.eINSTANCE.getTimer(), null, - "Missing time unit."); - } - - - /** - * Recognize valid IPV4 addresses, report invalid ones. - */ - @Test - public void recognizeIPV4() throws Exception { - List correct = List.of("127.0.0.1", "10.0.0.1", "192.168.1.1", "0.0.0.0", "192.168.1.1"); - List parseError = List.of("10002.3.4", "1.2.3.4.5"); - List validationError = List.of("256.0.0.0", "260.0.0.0"); - - // Correct IP addresses. - for (String addr : correct) { - - String testCase = """ + Model model = parseWithoutError(testCase); + + validator.assertError( + model, LfPackage.eINSTANCE.getParameter(), null, "Type declaration missing."); + validator.assertError( + model, LfPackage.eINSTANCE.getParameter(), null, "Parameter must have a default value."); + validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Missing time unit."); + validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Invalid time value."); + validator.assertError( + model, LfPackage.eINSTANCE.getParameter(), null, "Expected exactly one time value."); + validator.assertError( + model, + LfPackage.eINSTANCE.getParameter(), + null, + "Parameter cannot be initialized using parameter."); + validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, "Missing time unit."); + validator.assertError( + model, + LfPackage.eINSTANCE.getStateVar(), + null, + "Referenced parameter is not of time type."); + validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, "Invalid time value."); + validator.assertError(model, LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); + } + + /** Recognize valid IPV4 addresses, report invalid ones. */ + @Test + public void recognizeIPV4() throws Exception { + List correct = + List.of("127.0.0.1", "10.0.0.1", "192.168.1.1", "0.0.0.0", "192.168.1.1"); + List parseError = List.of("10002.3.4", "1.2.3.4.5"); + List validationError = List.of("256.0.0.0", "260.0.0.0"); + + // Correct IP addresses. + for (String addr : correct) { + + String testCase = + """ target C; reactor Y {} federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; + y = new Y() at %s:2424; } - """.formatted(addr, addr); - parseWithoutError( - testCase - ); - } + """ + .formatted(addr, addr); + parseWithoutError(testCase); + } - // IP addresses that don't parse. - for (String addr : parseError) { - String testCase = """ + // IP addresses that don't parse. + for (String addr : parseError) { + String testCase = + """ target C; reactor Y {} federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; + y = new Y() at %s:2424; } - """.formatted(addr, addr); - parseWithError(testCase); - } + """ + .formatted(addr, addr); + parseWithError(testCase); + } - // IP addresses that parse but are invalid. - for (String addr : validationError) { - Model model = parseWithoutError(""" + // IP addresses that parse but are invalid. + for (String addr : validationError) { + Model model = + parseWithoutError( + """ target C; reactor Y {} federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; + y = new Y() at %s:2424; } - """.formatted(addr, addr)); - validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); - } - } - - /** - * Recognize valid IPV6 addresses, report invalid ones. - */ - @Test - public void recognizeIPV6() throws Exception { - List correct = List.of("1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7::", "1:2:3:4:5:6::8", - "1:2:3:4:5::8", "1:2:3:4::8", "1:2:3::8", "1:2::8", "1::8", "::8", - "::", "1::3:4:5:6:7:8", "1::4:5:6:7:8", "1::5:6:7:8", "1::6:7:8", - "1::7:8", "1::8", "1::", "1:2:3:4:5::7:8", "1:2:3:4::6:7:8", - "1:2:3::5:6:7:8", "1:2::4:5:6:7:8", "1::3:4:5:6:7:8", - "::2:3:4:5:6:7:8", "fe80::7:8", "fe80::7:8%eth0", "fe80::7:8%1", - "::255.255.255.255", "::ffff:255.255.255.255", - "::ffff:0:255.255.255.0", "::ffff:00:255.255.255.0", - "::ffff:000:255.255.255.0", "::ffff:0000:255.255.255.0", - "::ffff:0.0.0.0", "::ffff:1.2.3.4", "::ffff:10.0.0.1", - "1:2:3:4:5:6:77:88", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", - "2001:db8:3:4::192.0.2.33", "64:ff9b::192.0.2.33", "0:0:0:0:0:0:10.0.0.1"); - - List validationError = List.of("1:2:3:4:5:6:7:8:9", "1:2:3:4:5:6::7:8", - "1:2:3:4:5:6:7:8:", "::1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8::", - "1:2:3:4:5:6:7:88888", "2001:db8:3:4:5::192.0.2.33", - "fe08::7:8interface", "fe08::7:8interface", "fe08::7:8i"); - - List parseError = List.of("fe08::7:8%", ":1:2:3:4:5:6:7:8"); - - // Correct IP addresses. - for (String addr : correct) { - String testCase = """ + """ + .formatted(addr, addr)); + validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); + } + } + + /** Recognize valid IPV6 addresses, report invalid ones. */ + @Test + public void recognizeIPV6() throws Exception { + List correct = + List.of( + "1:2:3:4:5:6:7:8", + "1:2:3:4:5:6:7::", + "1:2:3:4:5:6::8", + "1:2:3:4:5::8", + "1:2:3:4::8", + "1:2:3::8", + "1:2::8", + "1::8", + "::8", + "::", + "1::3:4:5:6:7:8", + "1::4:5:6:7:8", + "1::5:6:7:8", + "1::6:7:8", + "1::7:8", + "1::8", + "1::", + "1:2:3:4:5::7:8", + "1:2:3:4::6:7:8", + "1:2:3::5:6:7:8", + "1:2::4:5:6:7:8", + "1::3:4:5:6:7:8", + "::2:3:4:5:6:7:8", + "fe80::7:8", + "fe80::7:8%eth0", + "fe80::7:8%1", + "::255.255.255.255", + "::ffff:255.255.255.255", + "::ffff:0:255.255.255.0", + "::ffff:00:255.255.255.0", + "::ffff:000:255.255.255.0", + "::ffff:0000:255.255.255.0", + "::ffff:0.0.0.0", + "::ffff:1.2.3.4", + "::ffff:10.0.0.1", + "1:2:3:4:5:6:77:88", + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", + "2001:db8:3:4::192.0.2.33", + "64:ff9b::192.0.2.33", + "0:0:0:0:0:0:10.0.0.1"); + + List validationError = + List.of( + "1:2:3:4:5:6:7:8:9", + "1:2:3:4:5:6::7:8", + "1:2:3:4:5:6:7:8:", + "::1:2:3:4:5:6:7:8", + "1:2:3:4:5:6:7:8::", + "1:2:3:4:5:6:7:88888", + "2001:db8:3:4:5::192.0.2.33", + "fe08::7:8interface", + "fe08::7:8interface", + "fe08::7:8i"); + + List parseError = List.of("fe08::7:8%", ":1:2:3:4:5:6:7:8"); + + // Correct IP addresses. + for (String addr : correct) { + String testCase = + """ target C; reactor Y {} federated reactor at [foo@%s]:4242 { - y = new Y() at [%s]:2424; + y = new Y() at [%s]:2424; } - """.formatted(addr, addr); - Model model = parseWithoutError(testCase); - validator.assertNoIssues(model); - } - + """ + .formatted(addr, addr); + Model model = parseWithoutError(testCase); + validator.assertNoIssues(model); + } - // IP addresses that don't parse. - for (String addr : parseError) { - String testCase = """ + // IP addresses that don't parse. + for (String addr : parseError) { + String testCase = + """ target C; reactor Y {} federated reactor X at [foo@%s]:4242 { - y = new Y() at [%s]:2424; + y = new Y() at [%s]:2424; } - """.formatted(addr, addr); - parseWithError(testCase); - } + """ + .formatted(addr, addr); + parseWithError(testCase); + } - // IP addresses that parse but are invalid. - for (String addr : validationError) { - String testCase = """ + // IP addresses that parse but are invalid. + for (String addr : validationError) { + String testCase = + """ target C; reactor Y {} federated reactor X at [foo@%s]:4242 { - y = new Y() at [%s]:2424; + y = new Y() at [%s]:2424; } - """.formatted(addr, addr); - Model model = parseWithoutError( - testCase - ); - validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); - } + """ + .formatted(addr, addr); + Model model = parseWithoutError(testCase); + validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); } + } - /** - * Recognize valid host names and fully qualified names, report invalid ones. - */ - @Test - public void recognizeHostNames() throws Exception { - - List correct = List.of("localhost"); // FIXME: add more + /** Recognize valid host names and fully qualified names, report invalid ones. */ + @Test + public void recognizeHostNames() throws Exception { - List validationError = List.of("x.y.z"); // FIXME: add more + List correct = List.of("localhost"); // FIXME: add more - List parseError = List.of("..xyz"); // FIXME: add more + List validationError = List.of("x.y.z"); // FIXME: add more + List parseError = List.of("..xyz"); // FIXME: add more - // Correct names. - for (String addr : correct) { - String testCase = """ + // Correct names. + for (String addr : correct) { + String testCase = + """ target C; reactor Y {} federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; + y = new Y() at %s:2424; } - """.formatted(addr, addr); - parseWithoutError( - testCase - ); - } + """ + .formatted(addr, addr); + parseWithoutError(testCase); + } - // Names that don't parse. - for (String addr : parseError) { - String testCase = """ + // Names that don't parse. + for (String addr : parseError) { + String testCase = + """ target C; reactor Y {} federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; + y = new Y() at %s:2424; } - """.formatted(addr, addr); - parseWithError( - testCase - ); - } + """ + .formatted(addr, addr); + parseWithError(testCase); + } - // Names that parse but are invalid. - for (String addr : validationError) { - String testCase = """ + // Names that parse but are invalid. + for (String addr : validationError) { + String testCase = + """ target C; reactor Y {} federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; + y = new Y() at %s:2424; } - """.formatted(addr, addr); - Model model = parseWithoutError( - testCase - ); - validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, - "Invalid host name or fully qualified domain name."); - } - } - - /** - * Maps a type to a list of known good values. - */ - Map> primitiveTypeToKnownGood = Map.of( - PrimitiveType.BOOLEAN, List.of("true", "\"true\"", "false", "\"false\""), - PrimitiveType.INTEGER, List.of("0", "1", "\"42\"", "\"-1\"", "-2"), - PrimitiveType.NON_NEGATIVE_INTEGER, List.of("0", "1", "42"), - PrimitiveType.TIME_VALUE, List.of("1 msec", "2 sec"), - PrimitiveType.STRING, List.of("1", "\"foo\"", "bar"), - PrimitiveType.FILE, List.of("valid.file", "something.json", "\"foobar.proto\"") - ); - - /** - * Maps a type to a list of known bad values. - */ - Map> primitiveTypeToKnownBad = Map.of( - PrimitiveType.BOOLEAN, List.of("1 sec", "foo", "\"foo\"", "[1]", "{baz: 42}", "'c'"), - PrimitiveType.INTEGER, List.of("foo", "\"bar\"", "1 sec", "[1, 2]", "{foo: \"bar\"}", "'c'"), - PrimitiveType.NON_NEGATIVE_INTEGER, List.of("-42", "foo", "\"bar\"", "1 sec", "[1, 2]", "{foo: \"bar\"}", "'c'"), - PrimitiveType.TIME_VALUE, List.of("foo", "\"bar\"", "\"3 sec\"", "\"4 weeks\"", "[1, 2]", "{foo: \"bar\"}", "'c'"), - PrimitiveType.STRING, List.of("1 msec", "[1, 2]", "{foo: \"bar\"}", "'c'") - ); - - /** - * Maps a type to a list, each entry of which represents a list with - * three entries: a known wrong value, the suffix to add to the reported - * name, and the type that it should be. - */ - Map>> compositeTypeToKnownBad = Map.of( - ArrayType.STRING_ARRAY, List.of( - List.of("[1 msec]", "[0]", PrimitiveType.STRING), - List.of("[foo, {bar: baz}]", "[1]", PrimitiveType.STRING), - List.of("{bar: baz}", "", ArrayType.STRING_ARRAY) - ), - UnionType.STRING_OR_STRING_ARRAY, List.of( - List.of("[1 msec]", "[0]", PrimitiveType.STRING), - List.of("[foo, {bar: baz}]", "[1]", PrimitiveType.STRING), - List.of("{bar: baz}", "", UnionType.STRING_OR_STRING_ARRAY) - ), - UnionType.PLATFORM_STRING_OR_DICTIONARY, List.of( - List.of("[bar, baz]", "", UnionType.PLATFORM_STRING_OR_DICTIONARY), - List.of("{name: [1, 2, 3]}", ".name", PrimitiveType.STRING), - List.of("{name: {bar: baz}}", ".name", PrimitiveType.STRING), - List.of("{board: [1, 2, 3]}", ".board", PrimitiveType.STRING), - List.of("{board: {bar: baz}}", ".board", PrimitiveType.STRING), - List.of("{baud-rate: [1, 2, 3]}", ".baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), - List.of("{baud-rate: {bar: baz}}", ".baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER) - ), - UnionType.FILE_OR_FILE_ARRAY, List.of( - List.of("[1 msec]", "[0]", PrimitiveType.FILE), - List.of("[foo, {bar: baz}]", "[1]", PrimitiveType.FILE), - List.of("{bar: baz}", "", UnionType.FILE_OR_FILE_ARRAY) - ), - UnionType.DOCKER_UNION, List.of( - List.of("foo", "", UnionType.DOCKER_UNION), - List.of("[1]", "", UnionType.DOCKER_UNION), - List.of("{bar: baz}", "", DictionaryType.DOCKER_DICT), - List.of("{FROM: [1, 2, 3]}", ".FROM", PrimitiveType.STRING) - ), - UnionType.TRACING_UNION, List.of( - List.of("foo", "", UnionType.TRACING_UNION), - List.of("[1]", "", UnionType.TRACING_UNION), - List.of("{bar: baz}", "", DictionaryType.TRACING_DICT), - List.of("{trace-file-name: [1, 2, 3]}", ".trace-file-name", PrimitiveType.STRING) - ) - ); - - /** - * Given an array type, return a list of good or bad examples, - * depending on the value of the second parameter. - */ - private List synthesizeExamples(ArrayType type, boolean correct) { - Map> values = correct ? primitiveTypeToKnownGood - : primitiveTypeToKnownBad; - List examples = new LinkedList<>(); - if (correct) { - // Produce an array that has an entry for each value. - List entries = values.get(type.type); - if (!(entries == null || entries.isEmpty())) { - examples.add(String.format("[%s]", String.join(", ", entries))); - } - } - return examples; - } - - /** - * Given an union type, return a list of good or bad examples, - * depending on the value of the second parameter. - */ - private List synthesizeExamples(UnionType type, boolean correct) { - List examples = new LinkedList<>(); - if (correct) { - for (Enum it : type.options) { - if (it instanceof TargetPropertyType) { - synthesizeExamples((TargetPropertyType) it, correct).forEach(ex -> examples.add(ex)); - } else { - examples.add(it.toString()); - } - } - } else { - // Return some obviously bad examples for the common - // case where the options are from an ordinary Enum. - if (!type.options.stream().anyMatch(it -> it instanceof TargetPropertyType)) { - return List.of("foo", "\"bar\"", "1", "-1", "{x: 42}", "[1, 2, 3]"); - } - } - return examples; - } - - /** - * Given an union type, return a list of good or bad examples, - * depending on the value of the second parameter. - */ - private List synthesizeExamples(DictionaryType type, boolean correct) { - List examples = new LinkedList<>(); - // Produce a set of singleton dictionaries. - // If incorrect examples are wanted, garble the key. - for (DictionaryElement option : type.options) { - synthesizeExamples(option.getType(), correct).forEach(it -> examples.add( - "{" + option + (!correct ? "iamwrong: " : ": ") + it + "}")); - } - return examples; - } - - private List synthesizeExamples(StringDictionaryType type, boolean correct) { - List examples = new LinkedList<>(); - // Produce a set of singleton dictionaries. - // If incorrect examples are wanted, use non-strings for values. - List goodStrs = synthesizeExamples(PrimitiveType.STRING, true); - List badStrs = synthesizeExamples(PrimitiveType.STRING, false); - List goodIDs = List.of("foo", "Bar", "__ab0_9fC", "f1o_O2B_a3r"); - if (correct) { - for (String gs : goodStrs) { - goodIDs.forEach(it -> examples.add("{" + it + ": " + gs + "}")); - } - } else { - for (String bs : badStrs) { - goodIDs.forEach(it -> examples.add("{" + it + ": " + bs + "}")); - } - } - return examples; - } - - /** - * Synthesize a list of values that either conform to the given type or - * do not, depending on whether the second argument 'correct' is true. - * Return an empty set if it is too complicated to generate examples - * (e.g., because the resulting errors are more sophisticated). - *

    - * Not all cases are covered by this function. Currently, the only cases not - * covered are known bad examples for composite types, which should be added - * to the compositeTypeToKnownBad map. - * - * @param correct True to synthesize correct examples automatically, otherwise - * synthesize incorrect examples. - */ - private List synthesizeExamples(TargetPropertyType type, boolean correct) { - if (type instanceof PrimitiveType) { - Map> values = correct ? primitiveTypeToKnownGood - : primitiveTypeToKnownBad; - List examples = values.get(type); - Assertions.assertNotNull(examples); - return examples; + """ + .formatted(addr, addr); + Model model = parseWithoutError(testCase); + validator.assertWarning( + model, + LfPackage.eINSTANCE.getHost(), + null, + "Invalid host name or fully qualified domain name."); + } + } + + /** Maps a type to a list of known good values. */ + Map> primitiveTypeToKnownGood = + Map.of( + PrimitiveType.BOOLEAN, List.of("true", "\"true\"", "false", "\"false\""), + PrimitiveType.INTEGER, List.of("0", "1", "\"42\"", "\"-1\"", "-2"), + PrimitiveType.NON_NEGATIVE_INTEGER, List.of("0", "1", "42"), + PrimitiveType.TIME_VALUE, List.of("1 msec", "2 sec"), + PrimitiveType.STRING, List.of("1", "\"foo\"", "bar"), + PrimitiveType.FILE, List.of("valid.file", "something.json", "\"foobar.proto\"")); + + /** Maps a type to a list of known bad values. */ + Map> primitiveTypeToKnownBad = + Map.of( + PrimitiveType.BOOLEAN, List.of("1 sec", "foo", "\"foo\"", "[1]", "{baz: 42}", "'c'"), + PrimitiveType.INTEGER, + List.of("foo", "\"bar\"", "1 sec", "[1, 2]", "{foo: \"bar\"}", "'c'"), + PrimitiveType.NON_NEGATIVE_INTEGER, + List.of("-42", "foo", "\"bar\"", "1 sec", "[1, 2]", "{foo: \"bar\"}", "'c'"), + PrimitiveType.TIME_VALUE, + List.of( + "foo", "\"bar\"", "\"3 sec\"", "\"4 weeks\"", "[1, 2]", "{foo: \"bar\"}", "'c'"), + PrimitiveType.STRING, List.of("1 msec", "[1, 2]", "{foo: \"bar\"}", "'c'")); + + /** + * Maps a type to a list, each entry of which represents a list with three entries: a known wrong + * value, the suffix to add to the reported name, and the type that it should be. + */ + Map>> compositeTypeToKnownBad = + Map.of( + ArrayType.STRING_ARRAY, + List.of( + List.of("[1 msec]", "[0]", PrimitiveType.STRING), + List.of("[foo, {bar: baz}]", "[1]", PrimitiveType.STRING), + List.of("{bar: baz}", "", ArrayType.STRING_ARRAY)), + UnionType.STRING_OR_STRING_ARRAY, + List.of( + List.of("[1 msec]", "[0]", PrimitiveType.STRING), + List.of("[foo, {bar: baz}]", "[1]", PrimitiveType.STRING), + List.of("{bar: baz}", "", UnionType.STRING_OR_STRING_ARRAY)), + UnionType.PLATFORM_STRING_OR_DICTIONARY, + List.of( + List.of("[bar, baz]", "", UnionType.PLATFORM_STRING_OR_DICTIONARY), + List.of("{name: [1, 2, 3]}", ".name", PrimitiveType.STRING), + List.of("{name: {bar: baz}}", ".name", PrimitiveType.STRING), + List.of("{board: [1, 2, 3]}", ".board", PrimitiveType.STRING), + List.of("{board: {bar: baz}}", ".board", PrimitiveType.STRING), + List.of( + "{baud-rate: [1, 2, 3]}", ".baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), + List.of( + "{baud-rate: {bar: baz}}", ".baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER)), + UnionType.FILE_OR_FILE_ARRAY, + List.of( + List.of("[1 msec]", "[0]", PrimitiveType.FILE), + List.of("[foo, {bar: baz}]", "[1]", PrimitiveType.FILE), + List.of("{bar: baz}", "", UnionType.FILE_OR_FILE_ARRAY)), + UnionType.DOCKER_UNION, + List.of( + List.of("foo", "", UnionType.DOCKER_UNION), + List.of("[1]", "", UnionType.DOCKER_UNION), + List.of("{bar: baz}", "", DictionaryType.DOCKER_DICT), + List.of("{FROM: [1, 2, 3]}", ".FROM", PrimitiveType.STRING)), + UnionType.TRACING_UNION, + List.of( + List.of("foo", "", UnionType.TRACING_UNION), + List.of("[1]", "", UnionType.TRACING_UNION), + List.of("{bar: baz}", "", DictionaryType.TRACING_DICT), + List.of( + "{trace-file-name: [1, 2, 3]}", ".trace-file-name", PrimitiveType.STRING))); + + /** + * Given an array type, return a list of good or bad examples, depending on the value of the + * second parameter. + */ + private List synthesizeExamples(ArrayType type, boolean correct) { + Map> values = + correct ? primitiveTypeToKnownGood : primitiveTypeToKnownBad; + List examples = new LinkedList<>(); + if (correct) { + // Produce an array that has an entry for each value. + List entries = values.get(type.type); + if (!(entries == null || entries.isEmpty())) { + examples.add(String.format("[%s]", String.join(", ", entries))); + } + } + return examples; + } + + /** + * Given an union type, return a list of good or bad examples, depending on the value of the + * second parameter. + */ + private List synthesizeExamples(UnionType type, boolean correct) { + List examples = new LinkedList<>(); + if (correct) { + for (Enum it : type.options) { + if (it instanceof TargetPropertyType) { + synthesizeExamples((TargetPropertyType) it, correct).forEach(ex -> examples.add(ex)); } else { - if (type instanceof UnionType) { - return synthesizeExamples((UnionType) type, correct); - } else if (type instanceof ArrayType) { - return synthesizeExamples((ArrayType) type, correct); - } else if (type instanceof DictionaryType) { - return synthesizeExamples((DictionaryType) type, correct); - } else if (type instanceof StringDictionaryType) { - return synthesizeExamples((StringDictionaryType) type, correct); - } else { - Assertions.fail("Encountered an unknown type: " + type); - } + examples.add(it.toString()); } - return new LinkedList<>(); - } - - /** - * Create an LF program with the given key and value as a target property, - * parse it, and return the resulting model. - */ - private Model createModel(TargetProperty key, String value) throws Exception { - String target = key.supportedBy.get(0).getDisplayName(); - System.out.printf("%s: %s%n", key, value); - return parseWithoutError(""" + } + } else { + // Return some obviously bad examples for the common + // case where the options are from an ordinary Enum. + if (!type.options.stream().anyMatch(it -> it instanceof TargetPropertyType)) { + return List.of("foo", "\"bar\"", "1", "-1", "{x: 42}", "[1, 2, 3]"); + } + } + return examples; + } + + /** + * Given an union type, return a list of good or bad examples, depending on the value of the + * second parameter. + */ + private List synthesizeExamples(DictionaryType type, boolean correct) { + List examples = new LinkedList<>(); + // Produce a set of singleton dictionaries. + // If incorrect examples are wanted, garble the key. + for (DictionaryElement option : type.options) { + synthesizeExamples(option.getType(), correct) + .forEach(it -> examples.add("{" + option + (!correct ? "iamwrong: " : ": ") + it + "}")); + } + return examples; + } + + private List synthesizeExamples(StringDictionaryType type, boolean correct) { + List examples = new LinkedList<>(); + // Produce a set of singleton dictionaries. + // If incorrect examples are wanted, use non-strings for values. + List goodStrs = synthesizeExamples(PrimitiveType.STRING, true); + List badStrs = synthesizeExamples(PrimitiveType.STRING, false); + List goodIDs = List.of("foo", "Bar", "__ab0_9fC", "f1o_O2B_a3r"); + if (correct) { + for (String gs : goodStrs) { + goodIDs.forEach(it -> examples.add("{" + it + ": " + gs + "}")); + } + } else { + for (String bs : badStrs) { + goodIDs.forEach(it -> examples.add("{" + it + ": " + bs + "}")); + } + } + return examples; + } + + /** + * Synthesize a list of values that either conform to the given type or do not, depending on + * whether the second argument 'correct' is true. Return an empty set if it is too complicated to + * generate examples (e.g., because the resulting errors are more sophisticated). + * + *

    Not all cases are covered by this function. Currently, the only cases not covered are known + * bad examples for composite types, which should be added to the compositeTypeToKnownBad map. + * + * @param correct True to synthesize correct examples automatically, otherwise synthesize + * incorrect examples. + */ + private List synthesizeExamples(TargetPropertyType type, boolean correct) { + if (type instanceof PrimitiveType) { + Map> values = + correct ? primitiveTypeToKnownGood : primitiveTypeToKnownBad; + List examples = values.get(type); + Assertions.assertNotNull(examples); + return examples; + } else { + if (type instanceof UnionType) { + return synthesizeExamples((UnionType) type, correct); + } else if (type instanceof ArrayType) { + return synthesizeExamples((ArrayType) type, correct); + } else if (type instanceof DictionaryType) { + return synthesizeExamples((DictionaryType) type, correct); + } else if (type instanceof StringDictionaryType) { + return synthesizeExamples((StringDictionaryType) type, correct); + } else { + Assertions.fail("Encountered an unknown type: " + type); + } + } + return new LinkedList<>(); + } + + /** + * Create an LF program with the given key and value as a target property, parse it, and return + * the resulting model. + */ + private Model createModel(TargetProperty key, String value) throws Exception { + String target = key.supportedBy.get(0).getDisplayName(); + System.out.printf("%s: %s%n", key, value); + return parseWithoutError( + """ target %s {%s: %s}; reactor Y {} main reactor { - y = new Y() - } - """.formatted(target, key, value)); - } - - /** - * Perform checks on target properties. - */ - @Test - public void checkTargetProperties() throws Exception { - for (TargetProperty prop : TargetProperty.getOptions()) { - if (prop == TargetProperty.CARGO_DEPENDENCIES) { - // we test that separately as it has better error messages - return; - } - System.out.printf("Testing target property %s which is %s%n", prop, prop.type); - System.out.println("===="); - System.out.println("Known good assignments:"); - List knownCorrect = synthesizeExamples(prop.type, true); - - for (String it : knownCorrect) { - Model model = createModel(prop, it); - validator.assertNoErrors(model); - // Also make sure warnings are produced when files are not present. - if (prop.type == PrimitiveType.FILE) { - validator.assertWarning(model, LfPackage.eINSTANCE.getKeyValuePair(), - null, String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); - } - } - - // Extra checks for filenames. (This piece of code was commented out in the original xtend file) - // Temporarily disabled because we need a more sophisticated check that looks for files in different places. -// if (prop.type == prop.type == ArrayType.FILE_ARRAY || -// prop.type == UnionType.FILE_OR_FILE_ARRAY) { -// val model = prop.createModel( -// synthesizeExamples(ArrayType.FILE_ARRAY, true).get(0)) -// primitiveTypeToKnownGood.get(PrimitiveType.FILE).forEach [ -// model.assertWarning( -// LfPackage.eINSTANCE.keyValuePair, -// null, '''Could not find file: '«it.withoutQuotes»'.''') -// ] -// } - - System.out.println("Known bad assignments:"); - List knownIncorrect = synthesizeExamples(prop.type, false); - if (!(knownIncorrect == null || knownIncorrect.isEmpty())) { - for (String it : knownIncorrect) { - if (prop.type instanceof StringDictionaryType) { - validator.assertError(createModel(prop, it), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s.", prop), "' is required to be a string."); - } else { - validator.assertError(createModel(prop, it), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s' is required to be %s.", prop, prop.type)); - } - } - } else { - // No type was synthesized. It must be a composite type. - List> list = compositeTypeToKnownBad.get(prop.type); - if (list == null) { - System.out.printf("No known incorrect values provided for target property '%s'. Aborting test.%n", prop); - Assertions.fail(); - } else { - for (List it : list) { - validator.assertError(createModel(prop, it.get(0).toString()), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s%s' is required to be %s.", prop, it.get(1), it.get(2))); - } - } - } - System.out.println("===="); + y = new Y() + } + """ + .formatted(target, key, value)); + } + + /** Perform checks on target properties. */ + @Test + public void checkTargetProperties() throws Exception { + for (TargetProperty prop : TargetProperty.getOptions()) { + if (prop == TargetProperty.CARGO_DEPENDENCIES) { + // we test that separately as it has better error messages + return; + } + System.out.printf("Testing target property %s which is %s%n", prop, prop.type); + System.out.println("===="); + System.out.println("Known good assignments:"); + List knownCorrect = synthesizeExamples(prop.type, true); + + for (String it : knownCorrect) { + Model model = createModel(prop, it); + validator.assertNoErrors(model); + // Also make sure warnings are produced when files are not present. + if (prop.type == PrimitiveType.FILE) { + validator.assertWarning( + model, + LfPackage.eINSTANCE.getKeyValuePair(), + null, + String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); } - System.out.println("Done!"); - } - - - @Test - public void checkCargoDependencyProperty() throws Exception { - TargetProperty prop = TargetProperty.CARGO_DEPENDENCIES; - List knownCorrect = List.of("{}", "{ dep: \"8.2\" }", "{ dep: { version: \"8.2\"} }", "{ dep: { version: \"8.2\", features: [\"foo\"]} }"); - for (String it : knownCorrect) { - validator.assertNoErrors(createModel(prop, it)); + } + + // Extra checks for filenames. (This piece of code was commented out in the original xtend + // file) + // Temporarily disabled because we need a more sophisticated check that looks for files in + // different places. + // if (prop.type == prop.type == ArrayType.FILE_ARRAY || + // prop.type == UnionType.FILE_OR_FILE_ARRAY) { + // val model = prop.createModel( + // synthesizeExamples(ArrayType.FILE_ARRAY, true).get(0)) + // primitiveTypeToKnownGood.get(PrimitiveType.FILE).forEach [ + // model.assertWarning( + // LfPackage.eINSTANCE.keyValuePair, + // null, '''Could not find file: '«it.withoutQuotes»'.''') + // ] + // } + + System.out.println("Known bad assignments:"); + List knownIncorrect = synthesizeExamples(prop.type, false); + if (!(knownIncorrect == null || knownIncorrect.isEmpty())) { + for (String it : knownIncorrect) { + if (prop.type instanceof StringDictionaryType) { + validator.assertError( + createModel(prop, it), + LfPackage.eINSTANCE.getKeyValuePair(), + null, + String.format("Target property '%s.", prop), + "' is required to be a string."); + } else { + validator.assertError( + createModel(prop, it), + LfPackage.eINSTANCE.getKeyValuePair(), + null, + String.format("Target property '%s' is required to be %s.", prop, prop.type)); + } } - - // vvvvvvvvvvv - validator.assertError(createModel(prop, "{ dep: {/*empty*/} }"), - LfPackage.eINSTANCE.getKeyValuePairs(), null, "Must specify one of 'version', 'path', or 'git'" - ); - - // vvvvvvvvvvv - validator.assertError(createModel(prop, "{ dep: { unknown_key: \"\"} }"), - LfPackage.eINSTANCE.getKeyValuePair(), null, "Unknown key: 'unknown_key'" - ); - - // vvvv - validator.assertError(createModel(prop, "{ dep: { features: \"\" } }"), - LfPackage.eINSTANCE.getElement(), null, "Expected an array of strings for key 'features'" - ); - } - - @Test - public void testImportedCyclicReactor() throws Exception { - // File tempFile = File.createTempFile("lf-validation", ".lf"); - // tempFile.deleteOnExit(); - // // Java 17: - // // String fileToBeImported = """ - // // target C; - // // reactor A { - // // a = new A(); - // // } - // // """ - // // Java 11: - // String fileToBeImported = String.join(System.getProperty("line.separator"), - // "target C;", - // "reactor A {", - // " a = new A();", - // "}" - // ); - // BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); - // writer.write(fileToBeImported); - // writer.close(); - - // // Java 17: - // // String testCase = """ - // // target C; - // // import A from ... - // // main reactor { - // // } - // // """ - // // Java 11: - // String testCase = String.join(System.getProperty("line.separator"), - // "target C;", - // String.format("import A from \"%s\"", tempFile.getAbsolutePath()), - // "main reactor {", - // "}" - // ); - // Model model = parseWithoutError(testCase); - // TODO: Uncomment the lines below and resolve the weird error. (java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base) - // validator.assertError(model, LfPackage.eINSTANCE.getImportedReactor(), null, "Imported reactor 'A' has cyclic instantiation in it."); - } - - @Test - public void testUnusedImport() throws Exception { - // File tempFile = File.createTempFile("lf-validation", ".lf"); - // tempFile.deleteOnExit(); - // // Java 17: - // // String fileToBeImported = """ - // // target C; - // // reactor A {} - // // """ - // // Java 11: - // String fileToBeImported = String.join(System.getProperty("line.separator"), - // "target C;", - // "reactor A{}" - // ); - // BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); - // writer.write(fileToBeImported); - // writer.close(); - - // // Java 17: - // // String testCase = """ - // // target C; - // // import A from ... - // // main reactor {} - // // """ - // // Java 11: - // String testCase = String.join(System.getProperty("line.separator"), - // "target C;", - // String.format("import A from \"%s\"", tempFile.getAbsolutePath()), - // "main reactor{}" - // ); - // Model model = parseWithoutError(testCase); - // TODO: Uncomment the lines below and resolve the weird error. (java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base) - // validator.assertWarning(model, LfPackage.eINSTANCE.getImport(), null, "Unused import."); - // validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getImportedReactor(), null, "Unused reactor class."); - } - - @Test - public void testMissingInputType() throws Exception { - String testCase = """ + } else { + // No type was synthesized. It must be a composite type. + List> list = compositeTypeToKnownBad.get(prop.type); + if (list == null) { + System.out.printf( + "No known incorrect values provided for target property '%s'. Aborting test.%n", + prop); + Assertions.fail(); + } else { + for (List it : list) { + validator.assertError( + createModel(prop, it.get(0).toString()), + LfPackage.eINSTANCE.getKeyValuePair(), + null, + String.format( + "Target property '%s%s' is required to be %s.", prop, it.get(1), it.get(2))); + } + } + } + System.out.println("===="); + } + System.out.println("Done!"); + } + + @Test + public void checkCargoDependencyProperty() throws Exception { + TargetProperty prop = TargetProperty.CARGO_DEPENDENCIES; + List knownCorrect = + List.of( + "{}", + "{ dep: \"8.2\" }", + "{ dep: { version: \"8.2\"} }", + "{ dep: { version: \"8.2\", features: [\"foo\"]} }"); + for (String it : knownCorrect) { + validator.assertNoErrors(createModel(prop, it)); + } + + // vvvvvvvvvvv + validator.assertError( + createModel(prop, "{ dep: {/*empty*/} }"), + LfPackage.eINSTANCE.getKeyValuePairs(), + null, + "Must specify one of 'version', 'path', or 'git'"); + + // vvvvvvvvvvv + validator.assertError( + createModel(prop, "{ dep: { unknown_key: \"\"} }"), + LfPackage.eINSTANCE.getKeyValuePair(), + null, + "Unknown key: 'unknown_key'"); + + // vvvv + validator.assertError( + createModel(prop, "{ dep: { features: \"\" } }"), + LfPackage.eINSTANCE.getElement(), + null, + "Expected an array of strings for key 'features'"); + } + + @Test + public void testImportedCyclicReactor() throws Exception { + // File tempFile = File.createTempFile("lf-validation", ".lf"); + // tempFile.deleteOnExit(); + // // Java 17: + // // String fileToBeImported = """ + // // target C; + // // reactor A { + // // a = new A(); + // // } + // // """ + // // Java 11: + // String fileToBeImported = String.join(System.getProperty("line.separator"), + // "target C;", + // "reactor A {", + // " a = new A();", + // "}" + // ); + // BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + // writer.write(fileToBeImported); + // writer.close(); + + // // Java 17: + // // String testCase = """ + // // target C; + // // import A from ... + // // main reactor { + // // } + // // """ + // // Java 11: + // String testCase = String.join(System.getProperty("line.separator"), + // "target C;", + // String.format("import A from \"%s\"", tempFile.getAbsolutePath()), + // "main reactor {", + // "}" + // ); + // Model model = parseWithoutError(testCase); + // TODO: Uncomment the lines below and resolve the weird error. + // (java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base) + // validator.assertError(model, LfPackage.eINSTANCE.getImportedReactor(), null, "Imported + // reactor 'A' has cyclic instantiation in it."); + } + + @Test + public void testUnusedImport() throws Exception { + // File tempFile = File.createTempFile("lf-validation", ".lf"); + // tempFile.deleteOnExit(); + // // Java 17: + // // String fileToBeImported = """ + // // target C; + // // reactor A {} + // // """ + // // Java 11: + // String fileToBeImported = String.join(System.getProperty("line.separator"), + // "target C;", + // "reactor A{}" + // ); + // BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + // writer.write(fileToBeImported); + // writer.close(); + + // // Java 17: + // // String testCase = """ + // // target C; + // // import A from ... + // // main reactor {} + // // """ + // // Java 11: + // String testCase = String.join(System.getProperty("line.separator"), + // "target C;", + // String.format("import A from \"%s\"", tempFile.getAbsolutePath()), + // "main reactor{}" + // ); + // Model model = parseWithoutError(testCase); + // TODO: Uncomment the lines below and resolve the weird error. + // (java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base) + // validator.assertWarning(model, LfPackage.eINSTANCE.getImport(), null, "Unused import."); + // validator.assertWarning(parseWithoutError(testCase), + // LfPackage.eINSTANCE.getImportedReactor(), null, "Unused reactor class."); + } + + @Test + public void testMissingInputType() throws Exception { + String testCase = + """ target C; main reactor { input i; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, - "Input must have a type."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInput(), + null, + "Input must have a type."); + } - @Test - public void testMissingOutputType() throws Exception { - String testCase = """ + @Test + public void testMissingOutputType() throws Exception { + String testCase = + """ target C; main reactor { output i; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, - "Output must have a type."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getOutput(), + null, + "Output must have a type."); + } - @Test - public void testMissingStateType() throws Exception { - String testCase = """ + @Test + public void testMissingStateType() throws Exception { + String testCase = + """ target C; main reactor { state i; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, - "State must have a type."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getStateVar(), + null, + "State must have a type."); + } - @Test - public void testListWithParam() throws Exception { - String testCase = """ + @Test + public void testListWithParam() throws Exception { + String testCase = + """ target C; main reactor (A:int(1)) { state i:int(A, 2, 3) } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, - "List items cannot refer to a parameter."); - } - - @Test - public void testCppMutableInput() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getStateVar(), + null, + "List items cannot refer to a parameter."); + } + + @Test + public void testCppMutableInput() throws Exception { + String testCase = + """ target Cpp; main reactor { mutable input i:int; } """; - validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, - "The mutable qualifier has no meaning for the C++ target and should be removed. " + - "In C++, any value can be made mutable by calling get_mutable_copy()."); - } + validator.assertWarning( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInput(), + null, + "The mutable qualifier has no meaning for the C++ target and should be removed. " + + "In C++, any value can be made mutable by calling get_mutable_copy()."); + } - @Test - public void testOverflowingSTP() throws Exception { - String testCase = """ + @Test + public void testOverflowingSTP() throws Exception { + String testCase = + """ 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, - // "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } + // TODO: Uncomment and fix failing test. See issue #903 on Github. + // validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getSTP(), null, + // "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } - @Test - public void testOverflowingDeadline() throws Exception { - String testCase = """ + @Test + public void testOverflowingDeadline() throws Exception { + String testCase = + """ 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, - // "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } + // TODO: Uncomment and fix failing test. See issue #903 on Github. + // validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), null, + // "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } - @Test - public void testInvalidTargetParam() throws Exception { - String testCase = """ + @Test + public void testInvalidTargetParam() throws Exception { + String testCase = + """ target C { beefyDesktop: true } main reactor {} """; - List issues = validator.validate(parseWithoutError(testCase)); - Assertions.assertTrue(issues.size() == 1 + List issues = validator.validate(parseWithoutError(testCase)); + Assertions.assertTrue( + issues.size() == 1 && issues.get(0).getMessage().contains("Unrecognized target parameter: beefyDesktop")); - } + } - @Test - public void testTargetParamNotSupportedForTarget() throws Exception { - String testCase = """ + @Test + public void testTargetParamNotSupportedForTarget() throws Exception { + String testCase = + """ target Python { build: "" } main reactor {} """; - List issues = validator.validate(parseWithoutError(testCase)); - Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains( - "The target parameter: build" + - " is not supported by the Python target and will thus be ignored.")); - } - - @Test - public void testUnnamedReactor() throws Exception { - String testCase = """ + List issues = validator.validate(parseWithoutError(testCase)); + Assertions.assertTrue( + issues.size() == 1 + && issues + .get(0) + .getMessage() + .contains( + "The target parameter: build" + + " is not supported by the Python target and will thus be ignored.")); + } + + @Test + public void testUnnamedReactor() throws Exception { + String testCase = """ target C; reactor {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Reactor must be named."); - } - - @Test - public void testMainHasInput() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor must be named."); + } + + @Test + public void testMainHasInput() throws Exception { + String testCase = + """ target C; main reactor { input x:int; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, - "Main reactor cannot have inputs."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInput(), + null, + "Main reactor cannot have inputs."); + } - @Test - public void testFederatedHasInput() throws Exception { + @Test + public void testFederatedHasInput() throws Exception { - String testCase = """ + String testCase = + """ target C; federated reactor { input x:int; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, - "Main reactor cannot have inputs."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInput(), + null, + "Main reactor cannot have inputs."); + } - @Test - public void testMainHasOutput() throws Exception { + @Test + public void testMainHasOutput() throws Exception { - String testCase = """ + String testCase = + """ target C; main reactor { output x:int; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, - "Main reactor cannot have outputs."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getOutput(), + null, + "Main reactor cannot have outputs."); + } - @Test - public void testFederatedHasOutput() throws Exception { + @Test + public void testFederatedHasOutput() throws Exception { - String testCase = """ + String testCase = + """ target C; federated reactor { output x:int; } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, - "Main reactor cannot have outputs."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getOutput(), + null, + "Main reactor cannot have outputs."); + } - @Test - public void testMultipleMainReactor() throws Exception { + @Test + public void testMultipleMainReactor() throws Exception { - String testCase = """ + String testCase = + """ target C; main reactor A {} main reactor A {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Multiple definitions of main or federated reactor."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Multiple definitions of main or federated reactor."); + } - @Test - public void testMultipleMainReactorUnnamed() throws Exception { + @Test + public void testMultipleMainReactorUnnamed() throws Exception { - String testCase = """ + String testCase = + """ target C; main reactor {} main reactor {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Multiple definitions of main or federated reactor."); - } - - @Test - public void testMultipleFederatedReactor() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Multiple definitions of main or federated reactor."); + } + + @Test + public void testMultipleFederatedReactor() throws Exception { + String testCase = + """ target C; federated reactor A {} federated reactor A {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Multiple definitions of main or federated reactor."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Multiple definitions of main or federated reactor."); + } - @Test - public void testMultipleMainOrFederatedReactor() throws Exception { + @Test + public void testMultipleMainOrFederatedReactor() throws Exception { - String testCase = """ + String testCase = + """ target C; federated reactor A {} federated reactor A {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Multiple definitions of main or federated reactor."); - } - - @Test - public void testMainReactorHasHost() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Multiple definitions of main or federated reactor."); + } + + @Test + public void testMainReactorHasHost() throws Exception { + String testCase = + """ 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 && - // issues.get(0).getMessage().contains("Cannot assign a host to reactor '") && - // issues.get(0).getMessage().contains("' because it is not federated.")); - } + // TODO: Uncomment and fix test + // List issues = validator.validate(parseWithoutError(testCase)); + // Assertions.assertTrue(issues.size() == 1 && + // issues.get(0).getMessage().contains("Cannot assign a host to reactor '") && + // issues.get(0).getMessage().contains("' because it is not federated.")); + } - @Test - public void testUnrecognizedTarget() throws Exception { + @Test + public void testUnrecognizedTarget() throws Exception { - String testCase = """ + String testCase = + """ target Pjthon; main reactor {} """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTargetDecl(), null, - "Unrecognized target: Pjthon"); - } - - - @Test - public void testWrongStructureForLabelAttribute() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getTargetDecl(), + null, + "Unrecognized target: Pjthon"); + } + + @Test + public void testWrongStructureForLabelAttribute() throws Exception { + String testCase = + """ target C; @label(name="something") main reactor { } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAttribute(), null, - "Unknown attribute parameter."); - } - - @Test - public void testMissingName() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAttribute(), + null, + "Unknown attribute parameter."); + } + + @Test + public void testMissingName() throws Exception { + String testCase = + """ target C; @label("something", "else") main reactor { } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAttribute(), null, - "Missing name for attribute parameter."); - } - - @Test - public void testWrongParamType() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAttribute(), + null, + "Missing name for attribute parameter."); + } + + @Test + public void testWrongParamType() throws Exception { + String testCase = + """ target C; @label(value=1) main reactor { } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAttribute(), null, - "Incorrect type: \"value\" should have type String."); - } - - @Test - public void testInitialMode() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAttribute(), + null, + "Incorrect type: \"value\" should have type String."); + } + + @Test + public void testInitialMode() throws Exception { + String testCase = + """ target C; main reactor { mode M {} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Every modal reactor requires one initial mode."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "Every modal reactor requires one initial mode."); + } - @Test - public void testInitialModes() throws Exception { - String testCase = """ + @Test + public void testInitialModes() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM1 {} initial mode IM2 {} } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "A modal reactor can only have one initial mode."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReactor(), + null, + "A modal reactor can only have one initial mode."); + } - @Test - public void testModeStateNamespace() throws Exception { - String testCase = """ + @Test + public void testModeStateNamespace() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM { @@ -1752,13 +2002,18 @@ public void testModeStateNamespace() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, - "Duplicate state variable 's'. (State variables are currently scoped on reactor level not modes)"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getStateVar(), + null, + "Duplicate state variable 's'. (State variables are currently scoped on reactor level not" + + " modes)"); + } - @Test - public void testModeTimerNamespace() throws Exception { - String testCase = """ + @Test + public void testModeTimerNamespace() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM { @@ -1769,13 +2024,17 @@ public void testModeTimerNamespace() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, - "Duplicate Timer 't'. (Timers are currently scoped on reactor level not modes)"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getTimer(), + null, + "Duplicate Timer 't'. (Timers are currently scoped on reactor level not modes)"); + } - @Test - public void testModeActionNamespace() throws Exception { - String testCase = """ + @Test + public void testModeActionNamespace() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM { @@ -1786,13 +2045,17 @@ public void testModeActionNamespace() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), null, - "Duplicate Action 'a'. (Actions are currently scoped on reactor level not modes)"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getAction(), + null, + "Duplicate Action 'a'. (Actions are currently scoped on reactor level not modes)"); + } - @Test - public void testModeInstanceNamespace() throws Exception { - String testCase = """ + @Test + public void testModeInstanceNamespace() throws Exception { + String testCase = + """ target C; reactor R {} main reactor { @@ -1804,13 +2067,18 @@ public void testModeInstanceNamespace() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, - "Duplicate Instantiation 'r'. (Instantiations are currently scoped on reactor level not modes)"); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getInstantiation(), + null, + "Duplicate Instantiation 'r'. (Instantiations are currently scoped on reactor level not" + + " modes)"); + } - @Test - public void testMissingModeStateReset() throws Exception { - String testCase = """ + @Test + public void testMissingModeStateReset() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM { @@ -1821,13 +2089,18 @@ public void testMissingModeStateReset() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), null, - "State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getMode(), + null, + "State variable is not reset upon mode entry. It is neither marked for automatic reset nor" + + " is there a reset reaction."); + } - @Test - public void testMissingModeStateResetInstance() throws Exception { - String testCase = """ + @Test + public void testMissingModeStateResetInstance() throws Exception { + String testCase = + """ target C; reactor R { state s:int = 0; @@ -1841,16 +2114,20 @@ public void testMissingModeStateResetInstance() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), null, - "This reactor contains state variables that are not reset upon mode entry: " - + "s in R" - + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " - + "It is unsafe to instantiate this reactor inside a mode entered with reset."); - } - - @Test - public void testModeStateResetWithoutInitialValue() throws Exception { - String testCase = """ + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getMode(), + null, + "This reactor contains state variables that are not reset upon mode entry: s in R.\n" + + "The state variables are neither marked for automatic reset nor have a dedicated" + + " reset reaction. It is unsafe to instantiate this reactor inside a mode entered with" + + " reset."); + } + + @Test + public void testModeStateResetWithoutInitialValue() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM { @@ -1858,13 +2135,17 @@ public void testModeStateResetWithoutInitialValue() throws Exception { } } """; - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, - "The state variable can not be automatically reset without an initial value."); - } + validator.assertError( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getStateVar(), + null, + "The state variable can not be automatically reset without an initial value."); + } - @Test - public void testUnspecifiedTransitionType() throws Exception { - String testCase = """ + @Test + public void testUnspecifiedTransitionType() throws Exception { + String testCase = + """ target C; main reactor { initial mode IM { @@ -1875,10 +2156,12 @@ public void testUnspecifiedTransitionType() throws Exception { } } """; - validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), null, - "You should specify a transition type! " - + "Reset and history transitions have different effects on this target mode. " - + "Currently, a reset type is implicitly assumed."); - } - + validator.assertWarning( + parseWithoutError(testCase), + LfPackage.eINSTANCE.getReaction(), + null, + "You should specify a transition type! " + + "Reset and history transitions have different effects on this target mode. " + + "Currently, a reset type is implicitly assumed."); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/MixedRadixIntTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/MixedRadixIntTest.java index 2cee2468c8..b119da05c2 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/MixedRadixIntTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/MixedRadixIntTest.java @@ -2,111 +2,110 @@ import java.util.Arrays; import java.util.List; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.lflang.generator.MixedRadixInt; public class MixedRadixIntTest { - - // Constants used many times below. - List radixes = Arrays.asList(2, 3, 4, 5); - List digits = Arrays.asList(1, 2, 3, 4); - @Test - public void create() throws Exception { - MixedRadixInt num = new MixedRadixInt(digits, radixes, null); - Assertions.assertEquals("1%2, 2%3, 3%4, 4%5", num.toString()); - Assertions.assertEquals(1 + 2*2 + 3*6 + 4*24, num.get()); - - List altDigits = List.of(1, 2, 1); - MixedRadixInt altNum = new MixedRadixInt(altDigits, radixes, null); - Assertions.assertEquals(11, altNum.get()); - } + // Constants used many times below. + List radixes = Arrays.asList(2, 3, 4, 5); + List digits = Arrays.asList(1, 2, 3, 4); - @Test - public void createWithInfinity() throws Exception { - List radixes = List.of(2, 3, 4, 10000); - MixedRadixInt num = new MixedRadixInt(digits, radixes, null); - Assertions.assertEquals(1 + 2*2 + 3*6 + 4*24, num.get()); - } + @Test + public void create() throws Exception { + MixedRadixInt num = new MixedRadixInt(digits, radixes, null); + Assertions.assertEquals("1%2, 2%3, 3%4, 4%5", num.toString()); + Assertions.assertEquals(1 + 2 * 2 + 3 * 6 + 4 * 24, num.get()); - @Test - public void createWithError() throws Exception { - List radixes = List.of(2, 3); - try { - new MixedRadixInt(digits, radixes, null); - } catch (IllegalArgumentException ex) { - Assertions.assertTrue(ex.getMessage().startsWith("Invalid")); - return; - } - Assertions.assertTrue(false, "Expected exception did not occur."); - } - - @Test - public void createWithNullAndSet() throws Exception { - MixedRadixInt num = new MixedRadixInt(null, radixes, null); - Assertions.assertEquals(0, num.get()); - Assertions.assertEquals("0%2", num.toString()); - num.set(1 + 2*2 + 3*6 + 4*24); - Assertions.assertEquals(1 + 2*2 + 3*6 + 4*24, num.get()); - int mag = num.magnitude(); - Assertions.assertEquals(1 + 2*2 + 3*6 + 4*24, mag); - num.increment(); // wrap to zero. - Assertions.assertEquals(0, num.get()); - Assertions.assertEquals(0, num.magnitude()); - - num = new MixedRadixInt(null, radixes, null); - num.setMagnitude(mag); - Assertions.assertEquals(mag, num.magnitude()); - } - - @Test - public void testPermutation() throws Exception { - List radixes = Arrays.asList(2, 5); - List digits = Arrays.asList(1, 2); - List permutation = Arrays.asList(1, 0); - MixedRadixInt num = new MixedRadixInt(digits, radixes, permutation); - Assertions.assertEquals(5, num.get()); - Assertions.assertEquals(2, num.get(1)); - Assertions.assertEquals(7, num.magnitude()); - num.increment(); - Assertions.assertEquals(7, num.get()); - Assertions.assertEquals(8, num.magnitude()); - - num = new MixedRadixInt(null, radixes, permutation); - num.setMagnitude(8); - Assertions.assertEquals(8, num.magnitude()); - Assertions.assertEquals(7, num.get()); + List altDigits = List.of(1, 2, 1); + MixedRadixInt altNum = new MixedRadixInt(altDigits, radixes, null); + Assertions.assertEquals(11, altNum.get()); + } - // Test radix infinity digit (effectively). - digits = Arrays.asList(1, 2, 1); - radixes = Arrays.asList(2, 5, 1000000); - num = new MixedRadixInt(digits, radixes, null); - Assertions.assertEquals(15, num.get()); - Assertions.assertEquals(7, num.get(1)); - Assertions.assertEquals(15, num.magnitude()); - - permutation = Arrays.asList(1, 0, 2); - num = new MixedRadixInt(digits, radixes, permutation); - num.increment(); - Assertions.assertEquals(17, num.get()); - Assertions.assertEquals(18, num.magnitude()); + @Test + public void createWithInfinity() throws Exception { + List radixes = List.of(2, 3, 4, 10000); + MixedRadixInt num = new MixedRadixInt(digits, radixes, null); + Assertions.assertEquals(1 + 2 * 2 + 3 * 6 + 4 * 24, num.get()); + } - num = new MixedRadixInt(null, radixes, permutation); - num.setMagnitude(18); - Assertions.assertEquals(18, num.magnitude()); - Assertions.assertEquals(17, num.get()); - } - - @Test - public void testIncrement() throws Exception { - List radixes = Arrays.asList(2, 3); - List digits = Arrays.asList(0, 2); - MixedRadixInt num = new MixedRadixInt(digits, radixes, null); - num.increment(); - Assertions.assertEquals(5, num.get()); - num.increment(); // Wrap around to zero. - Assertions.assertEquals(0, num.get()); + @Test + public void createWithError() throws Exception { + List radixes = List.of(2, 3); + try { + new MixedRadixInt(digits, radixes, null); + } catch (IllegalArgumentException ex) { + Assertions.assertTrue(ex.getMessage().startsWith("Invalid")); + return; } + Assertions.assertTrue(false, "Expected exception did not occur."); + } + + @Test + public void createWithNullAndSet() throws Exception { + MixedRadixInt num = new MixedRadixInt(null, radixes, null); + Assertions.assertEquals(0, num.get()); + Assertions.assertEquals("0%2", num.toString()); + num.set(1 + 2 * 2 + 3 * 6 + 4 * 24); + Assertions.assertEquals(1 + 2 * 2 + 3 * 6 + 4 * 24, num.get()); + int mag = num.magnitude(); + Assertions.assertEquals(1 + 2 * 2 + 3 * 6 + 4 * 24, mag); + num.increment(); // wrap to zero. + Assertions.assertEquals(0, num.get()); + Assertions.assertEquals(0, num.magnitude()); + + num = new MixedRadixInt(null, radixes, null); + num.setMagnitude(mag); + Assertions.assertEquals(mag, num.magnitude()); + } + + @Test + public void testPermutation() throws Exception { + List radixes = Arrays.asList(2, 5); + List digits = Arrays.asList(1, 2); + List permutation = Arrays.asList(1, 0); + MixedRadixInt num = new MixedRadixInt(digits, radixes, permutation); + Assertions.assertEquals(5, num.get()); + Assertions.assertEquals(2, num.get(1)); + Assertions.assertEquals(7, num.magnitude()); + num.increment(); + Assertions.assertEquals(7, num.get()); + Assertions.assertEquals(8, num.magnitude()); + + num = new MixedRadixInt(null, radixes, permutation); + num.setMagnitude(8); + Assertions.assertEquals(8, num.magnitude()); + Assertions.assertEquals(7, num.get()); + + // Test radix infinity digit (effectively). + digits = Arrays.asList(1, 2, 1); + radixes = Arrays.asList(2, 5, 1000000); + num = new MixedRadixInt(digits, radixes, null); + Assertions.assertEquals(15, num.get()); + Assertions.assertEquals(7, num.get(1)); + Assertions.assertEquals(15, num.magnitude()); + + permutation = Arrays.asList(1, 0, 2); + num = new MixedRadixInt(digits, radixes, permutation); + num.increment(); + Assertions.assertEquals(17, num.get()); + Assertions.assertEquals(18, num.magnitude()); + + num = new MixedRadixInt(null, radixes, permutation); + num.setMagnitude(18); + Assertions.assertEquals(18, num.magnitude()); + Assertions.assertEquals(17, num.get()); + } + + @Test + public void testIncrement() throws Exception { + List radixes = Arrays.asList(2, 3); + List digits = Arrays.asList(0, 2); + MixedRadixInt num = new MixedRadixInt(digits, radixes, null); + num.increment(); + Assertions.assertEquals(5, num.get()); + num.increment(); // Wrap around to zero. + Assertions.assertEquals(0, num.get()); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/PortInstanceTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/PortInstanceTests.java index f5f2ba387b..8b8ef52a8f 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/PortInstanceTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/PortInstanceTests.java @@ -1,15 +1,14 @@ package org.lflang.tests.compiler; import java.util.List; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.lflang.DefaultErrorReporter; import org.lflang.ErrorReporter; import org.lflang.generator.PortInstance; -import org.lflang.generator.RuntimeRange; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.RuntimeRange; import org.lflang.generator.SendRange; import org.lflang.lf.LfFactory; import org.lflang.lf.Port; @@ -18,204 +17,205 @@ public class PortInstanceTests { - private ErrorReporter reporter = new DefaultErrorReporter(); - private static LfFactory factory = LfFactory.eINSTANCE; - - @Test - public void createRange() throws Exception { - Reactor main = factory.createReactor(); - ReactorInstance maini = new ReactorInstance(main, reporter); - - ReactorInstance a = newReactor("A", maini); - ReactorInstance b = newReactor("B", maini); - ReactorInstance c = newReactor("C", maini); - - PortInstance p = newOutputPort("p", a); - PortInstance q = newInputPort("q", b); - PortInstance r = newInputPort("r", c); - - Assertions.assertEquals(".A.p", p.getFullName()); - - connect(p, q); - connect(p, r); - - List sr = p.eventualDestinations(); - // Destinations should be empty because there are no reactions. - Assertions.assertEquals("[]", sr.toString()); - - // Clear caches to make a mutation. - maini.clearCaches(); - newReaction(q); - // Re-retrieve destinations. - sr = p.eventualDestinations(); - Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,1)]]", sr.toString()); - - maini.clearCaches(); - newReaction(r); - // Re-retrieve destinations. - sr = p.eventualDestinations(); - Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,1), .C.r(0,1)]]", sr.toString()); - - // Now test multiports. - p.setWidth(3); - r.setWidth(2); - // Have to redo the connections. - clearConnections(maini); - maini.clearCaches(); - connect(p, 0, 1, q, 0, 1); - connect(p, 1, 2, r, 0, 2); - - // Re-retrieve destinations. - sr = p.eventualDestinations(); - Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,1)], .A.p(1,2)->[.C.r(0,2)]]", sr.toString()); - - // More complicated multiport connection. - clearConnections(maini); - maini.clearCaches(); - - ReactorInstance d = newReactor("D", maini); - PortInstance v = newOutputPort("v", d); - v.setWidth(2); - q.setWidth(3); - connect(v, 0, 2, q, 0, 2); - connect(p, 0, 1, q, 2, 1); - connect(p, 1, 2, r, 0, 2); - - sr = p.eventualDestinations(); - Assertions.assertEquals("[.A.p(0,1)->[.B.q(2,1)], .A.p(1,2)->[.C.r(0,2)]]", sr.toString()); - - // Additional multicast connection. - maini.clearCaches(); - ReactorInstance e = newReactor("E", maini); - PortInstance s = newPort("s", e); - s.setWidth(3); - newReaction(s); - connect(p, s); - - sr = p.eventualDestinations(); - Assertions.assertEquals("[.A.p(0,1)->[.B.q(2,1), .E.s(0,1)], .A.p(1,2)->[.C.r(0,2), .E.s(1,2)]]", sr.toString()); - - // Add hierarchical reactors that further split the ranges. - maini.clearCaches(); - ReactorInstance f = newReactor("F", e); - PortInstance t = newPort("t", f); - newReaction(t); - ReactorInstance g = newReactor("G", e); - PortInstance u = newPort("u", g); - u.setWidth(2); - newReaction(u); - connect(s, 0, 1, t, 0, 1); - connect(s, 1, 2, u, 0, 2); - - sr = p.eventualDestinations(); - // FIXME: Multicast destinations should be able to be reported in arbitrary order. - Assertions.assertEquals("[.A.p(0,1)->[.E.F.t(0,1), .E.s(0,1), .B.q(2,1)], .A.p(1,2)->[.E.G.u(0,2), .E.s(1,2), .C.r(0,2)]]", sr.toString()); - } - - @Test - public void multiportDestination() throws Exception { - Reactor main = factory.createReactor(); - ReactorInstance maini = new ReactorInstance(main, reporter); - - ReactorInstance a = newReactor("A", maini); - ReactorInstance b = newReactor("B", maini); - b.setWidth(4); - - PortInstance p = newOutputPort("p", a); - PortInstance q = newInputPort("q", b); - - connect(p, 0, 1, q, 0, 4); - - List sr = p.eventualDestinations(); - // Destination has no reactions, so empty list is right. - Assertions.assertEquals("[]", sr.toString()); - - maini.clearCaches(); - newReaction(q); - sr = p.eventualDestinations(); - Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,4)]]", sr.toString()); -} - - /** - * Clear connections. This recursively clears them for all contained reactors. - */ - protected void clearConnections(ReactorInstance r) { - for (PortInstance p: r.inputs) { - p.getDependentPorts().clear(); - } - for (PortInstance p: r.outputs) { - p.getDependentPorts().clear(); - } - for (ReactorInstance child: r.children) { - clearConnections(child); - } - } - - /** - * Simple connection of two ports. This should be used only - * for connections that would be allowed in the syntax (i.e., no - * cross-hierarchy connections), but this is not checked. - * @param src The sending port. - * @param dst The receiving port. - */ - protected void connect(PortInstance src, PortInstance dst) { - RuntimeRange srcRange = new RuntimeRange.Port(src); - RuntimeRange dstRange = new RuntimeRange.Port(dst); - ReactorInstance.connectPortInstances(srcRange, dstRange, null); + private ErrorReporter reporter = new DefaultErrorReporter(); + private static LfFactory factory = LfFactory.eINSTANCE; + + @Test + public void createRange() throws Exception { + Reactor main = factory.createReactor(); + ReactorInstance maini = new ReactorInstance(main, reporter); + + ReactorInstance a = newReactor("A", maini); + ReactorInstance b = newReactor("B", maini); + ReactorInstance c = newReactor("C", maini); + + PortInstance p = newOutputPort("p", a); + PortInstance q = newInputPort("q", b); + PortInstance r = newInputPort("r", c); + + Assertions.assertEquals(".A.p", p.getFullName()); + + connect(p, q); + connect(p, r); + + List sr = p.eventualDestinations(); + // Destinations should be empty because there are no reactions. + Assertions.assertEquals("[]", sr.toString()); + + // Clear caches to make a mutation. + maini.clearCaches(); + newReaction(q); + // Re-retrieve destinations. + sr = p.eventualDestinations(); + Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,1)]]", sr.toString()); + + maini.clearCaches(); + newReaction(r); + // Re-retrieve destinations. + sr = p.eventualDestinations(); + Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,1), .C.r(0,1)]]", sr.toString()); + + // Now test multiports. + p.setWidth(3); + r.setWidth(2); + // Have to redo the connections. + clearConnections(maini); + maini.clearCaches(); + connect(p, 0, 1, q, 0, 1); + connect(p, 1, 2, r, 0, 2); + + // Re-retrieve destinations. + sr = p.eventualDestinations(); + Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,1)], .A.p(1,2)->[.C.r(0,2)]]", sr.toString()); + + // More complicated multiport connection. + clearConnections(maini); + maini.clearCaches(); + + ReactorInstance d = newReactor("D", maini); + PortInstance v = newOutputPort("v", d); + v.setWidth(2); + q.setWidth(3); + connect(v, 0, 2, q, 0, 2); + connect(p, 0, 1, q, 2, 1); + connect(p, 1, 2, r, 0, 2); + + sr = p.eventualDestinations(); + Assertions.assertEquals("[.A.p(0,1)->[.B.q(2,1)], .A.p(1,2)->[.C.r(0,2)]]", sr.toString()); + + // Additional multicast connection. + maini.clearCaches(); + ReactorInstance e = newReactor("E", maini); + PortInstance s = newPort("s", e); + s.setWidth(3); + newReaction(s); + connect(p, s); + + sr = p.eventualDestinations(); + Assertions.assertEquals( + "[.A.p(0,1)->[.B.q(2,1), .E.s(0,1)], .A.p(1,2)->[.C.r(0,2), .E.s(1,2)]]", sr.toString()); + + // Add hierarchical reactors that further split the ranges. + maini.clearCaches(); + ReactorInstance f = newReactor("F", e); + PortInstance t = newPort("t", f); + newReaction(t); + ReactorInstance g = newReactor("G", e); + PortInstance u = newPort("u", g); + u.setWidth(2); + newReaction(u); + connect(s, 0, 1, t, 0, 1); + connect(s, 1, 2, u, 0, 2); + + sr = p.eventualDestinations(); + // FIXME: Multicast destinations should be able to be reported in arbitrary order. + Assertions.assertEquals( + "[.A.p(0,1)->[.E.F.t(0,1), .E.s(0,1), .B.q(2,1)], .A.p(1,2)->[.E.G.u(0,2), .E.s(1,2)," + + " .C.r(0,2)]]", + sr.toString()); + } + + @Test + public void multiportDestination() throws Exception { + Reactor main = factory.createReactor(); + ReactorInstance maini = new ReactorInstance(main, reporter); + + ReactorInstance a = newReactor("A", maini); + ReactorInstance b = newReactor("B", maini); + b.setWidth(4); + + PortInstance p = newOutputPort("p", a); + PortInstance q = newInputPort("q", b); + + connect(p, 0, 1, q, 0, 4); + + List sr = p.eventualDestinations(); + // Destination has no reactions, so empty list is right. + Assertions.assertEquals("[]", sr.toString()); + + maini.clearCaches(); + newReaction(q); + sr = p.eventualDestinations(); + Assertions.assertEquals("[.A.p(0,1)->[.B.q(0,4)]]", sr.toString()); + } + + /** Clear connections. This recursively clears them for all contained reactors. */ + protected void clearConnections(ReactorInstance r) { + for (PortInstance p : r.inputs) { + p.getDependentPorts().clear(); } - - /** - * Connection between multiports. This should be used only - * for connections that would be allowed in the syntax (i.e., no - * cross-hierarchy connections), but this is not checked. - * @param src The sending port. - * @param dst The receiving port. - */ - protected void connect( - PortInstance src, int srcStart, int srcWidth, - PortInstance dst, int dstStart, int dstWidth - ) { - RuntimeRange srcRange = new RuntimeRange.Port(src, srcStart, srcWidth, null); - RuntimeRange dstRange = new RuntimeRange.Port(dst, dstStart, dstWidth, null); - ReactorInstance.connectPortInstances(srcRange, dstRange, null); + for (PortInstance p : r.outputs) { + p.getDependentPorts().clear(); } - - protected PortInstance newPort(String name, ReactorInstance container) { - Port p = factory.createPort(); - p.setName(name); - return new PortInstance(p, container, reporter); - } - - protected PortInstance newInputPort(String name, ReactorInstance container) { - PortInstance pi = newPort(name, container); - container.inputs.add(pi); - return pi; - } - - protected PortInstance newOutputPort(String name, ReactorInstance container) { - PortInstance pi = newPort(name, container); - container.outputs.add(pi); - return pi; - } - - /** - * Return a new reaction triggered by the specified port. - * @param trigger The triggering port. - */ - protected ReactionInstance newReaction(PortInstance trigger) { - Reaction r = factory.createReaction(); - ReactionInstance result = new ReactionInstance( - r, trigger.getParent(), false, trigger.getDependentReactions().size()); - trigger.getDependentReactions().add(result); - trigger.getParent().reactions.add(result); - return result; - } - - protected ReactorInstance newReactor(String name, ReactorInstance container) { - Reactor r = factory.createReactor(); - r.setName(name); - ReactorInstance ri = new ReactorInstance(r, container, reporter); - container.children.add(ri); - return ri; + for (ReactorInstance child : r.children) { + clearConnections(child); } + } + + /** + * Simple connection of two ports. This should be used only for connections that would be allowed + * in the syntax (i.e., no cross-hierarchy connections), but this is not checked. + * + * @param src The sending port. + * @param dst The receiving port. + */ + protected void connect(PortInstance src, PortInstance dst) { + RuntimeRange srcRange = new RuntimeRange.Port(src); + RuntimeRange dstRange = new RuntimeRange.Port(dst); + ReactorInstance.connectPortInstances(srcRange, dstRange, null); + } + + /** + * Connection between multiports. This should be used only for connections that would be allowed + * in the syntax (i.e., no cross-hierarchy connections), but this is not checked. + * + * @param src The sending port. + * @param dst The receiving port. + */ + protected void connect( + PortInstance src, int srcStart, int srcWidth, PortInstance dst, int dstStart, int dstWidth) { + RuntimeRange srcRange = new RuntimeRange.Port(src, srcStart, srcWidth, null); + RuntimeRange dstRange = new RuntimeRange.Port(dst, dstStart, dstWidth, null); + ReactorInstance.connectPortInstances(srcRange, dstRange, null); + } + + protected PortInstance newPort(String name, ReactorInstance container) { + Port p = factory.createPort(); + p.setName(name); + return new PortInstance(p, container, reporter); + } + + protected PortInstance newInputPort(String name, ReactorInstance container) { + PortInstance pi = newPort(name, container); + container.inputs.add(pi); + return pi; + } + + protected PortInstance newOutputPort(String name, ReactorInstance container) { + PortInstance pi = newPort(name, container); + container.outputs.add(pi); + return pi; + } + + /** + * Return a new reaction triggered by the specified port. + * + * @param trigger The triggering port. + */ + protected ReactionInstance newReaction(PortInstance trigger) { + Reaction r = factory.createReaction(); + ReactionInstance result = + new ReactionInstance(r, trigger.getParent(), false, trigger.getDependentReactions().size()); + trigger.getDependentReactions().add(result); + trigger.getParent().reactions.add(result); + return result; + } + + protected ReactorInstance newReactor(String name, ReactorInstance container) { + Reactor r = factory.createReactor(); + r.setName(name); + ReactorInstance ri = new ReactorInstance(r, container, reporter); + container.children.add(ri); + return ri; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RangeTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/RangeTests.java index 5cd489d0f7..2c17145aaa 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/RangeTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/RangeTests.java @@ -2,14 +2,13 @@ import java.util.List; import java.util.Set; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.lflang.DefaultErrorReporter; import org.lflang.ErrorReporter; import org.lflang.generator.PortInstance; -import org.lflang.generator.RuntimeRange; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.RuntimeRange; import org.lflang.generator.SendRange; import org.lflang.lf.LfFactory; import org.lflang.lf.Port; @@ -17,87 +16,87 @@ public class RangeTests { - private ErrorReporter reporter = new DefaultErrorReporter(); - private static LfFactory factory = LfFactory.eINSTANCE; - - @Test - public void createRange() throws Exception { - Reactor main = factory.createReactor(); - ReactorInstance maini = new ReactorInstance(main, reporter); - - Reactor a = factory.createReactor(); - a.setName("A"); - ReactorInstance ai = new ReactorInstance(a, maini, reporter); - ai.setWidth(2); - - Reactor b = factory.createReactor(); - b.setName("B"); - ReactorInstance bi = new ReactorInstance(b, ai, reporter); - bi.setWidth(2); - - Port p = factory.createPort(); - p.setName("P"); - PortInstance pi = new PortInstance(p, bi, reporter); - pi.setWidth(2); - - Assertions.assertEquals(".A.B.P", pi.getFullName()); - - RuntimeRange range = new RuntimeRange.Port(pi, 3, 4, null); - - Assertions.assertEquals(8, range.maxWidth); - - Assertions.assertEquals(".A.B.P(3,4)", range.toString()); - - // The results expected below are derived from the class comment for RuntimeRange, - // which includes this example. - List instances = range.instances(); - Assertions.assertEquals(List.of(3, 4, 5, 6), instances); - Set parents = range.parentInstances(1); - Assertions.assertEquals(Set.of(1, 2, 3), parents); - - parents = range.parentInstances(2); - Assertions.assertEquals(Set.of(0, 1), parents); - - // Test startMR().getDigits. - Assertions.assertEquals(List.of(1, 1, 0), range.startMR().getDigits()); - - // Create a SendRange sending from and to this range. - SendRange sendRange = new SendRange(pi, 3, 4, null, null); - sendRange.destinations.add(range); - - // Test getNumberOfDestinationReactors. - Assertions.assertEquals(3, sendRange.getNumberOfDestinationReactors()); - - // Make first interleaved version. - range = range.toggleInterleaved(bi); - instances = range.instances(); - Assertions.assertEquals(List.of(3, 4, 6, 5), instances); - - // Test startMR().getDigits. - Assertions.assertEquals(List.of(1, 1, 0), range.startMR().getDigits()); - - // Make second interleaved version. - range = range.toggleInterleaved(ai); - instances = range.instances(); - Assertions.assertEquals(List.of(6, 1, 5, 3), instances); - - // Test startMR().getDigits. - Assertions.assertEquals(List.of(0, 1, 1), range.startMR().getDigits()); - - // Test instances of the parent. - Assertions.assertEquals(Set.of(3, 0, 2, 1), range.parentInstances(1)); - - // Add this range to the sendRange destinations and verify - // that the number of destination reactors becomes 4. - sendRange.addDestination(range); - Assertions.assertEquals(4, sendRange.getNumberOfDestinationReactors()); - - // Make third interleaved version. - range = range.toggleInterleaved(bi); - instances = range.instances(); - Assertions.assertEquals(List.of(5, 2, 6, 3), instances); - - // Test startMR().getDigits. - Assertions.assertEquals(List.of(1, 0, 1), range.startMR().getDigits()); - } + private ErrorReporter reporter = new DefaultErrorReporter(); + private static LfFactory factory = LfFactory.eINSTANCE; + + @Test + public void createRange() throws Exception { + Reactor main = factory.createReactor(); + ReactorInstance maini = new ReactorInstance(main, reporter); + + Reactor a = factory.createReactor(); + a.setName("A"); + ReactorInstance ai = new ReactorInstance(a, maini, reporter); + ai.setWidth(2); + + Reactor b = factory.createReactor(); + b.setName("B"); + ReactorInstance bi = new ReactorInstance(b, ai, reporter); + bi.setWidth(2); + + Port p = factory.createPort(); + p.setName("P"); + PortInstance pi = new PortInstance(p, bi, reporter); + pi.setWidth(2); + + Assertions.assertEquals(".A.B.P", pi.getFullName()); + + RuntimeRange range = new RuntimeRange.Port(pi, 3, 4, null); + + Assertions.assertEquals(8, range.maxWidth); + + Assertions.assertEquals(".A.B.P(3,4)", range.toString()); + + // The results expected below are derived from the class comment for RuntimeRange, + // which includes this example. + List instances = range.instances(); + Assertions.assertEquals(List.of(3, 4, 5, 6), instances); + Set parents = range.parentInstances(1); + Assertions.assertEquals(Set.of(1, 2, 3), parents); + + parents = range.parentInstances(2); + Assertions.assertEquals(Set.of(0, 1), parents); + + // Test startMR().getDigits. + Assertions.assertEquals(List.of(1, 1, 0), range.startMR().getDigits()); + + // Create a SendRange sending from and to this range. + SendRange sendRange = new SendRange(pi, 3, 4, null, null); + sendRange.destinations.add(range); + + // Test getNumberOfDestinationReactors. + Assertions.assertEquals(3, sendRange.getNumberOfDestinationReactors()); + + // Make first interleaved version. + range = range.toggleInterleaved(bi); + instances = range.instances(); + Assertions.assertEquals(List.of(3, 4, 6, 5), instances); + + // Test startMR().getDigits. + Assertions.assertEquals(List.of(1, 1, 0), range.startMR().getDigits()); + + // Make second interleaved version. + range = range.toggleInterleaved(ai); + instances = range.instances(); + Assertions.assertEquals(List.of(6, 1, 5, 3), instances); + + // Test startMR().getDigits. + Assertions.assertEquals(List.of(0, 1, 1), range.startMR().getDigits()); + + // Test instances of the parent. + Assertions.assertEquals(Set.of(3, 0, 2, 1), range.parentInstances(1)); + + // Add this range to the sendRange destinations and verify + // that the number of destination reactors becomes 4. + sendRange.addDestination(range); + Assertions.assertEquals(4, sendRange.getNumberOfDestinationReactors()); + + // Make third interleaved version. + range = range.toggleInterleaved(bi); + instances = range.instances(); + Assertions.assertEquals(List.of(5, 2, 6, 3), instances); + + // Test startMR().getDigits. + Assertions.assertEquals(List.of(1, 0, 1), range.startMR().getDigits()); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java index 801211be23..8087d552a8 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java @@ -7,13 +7,11 @@ import java.nio.file.Files; import java.nio.file.Path; - import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.Target; import org.lflang.ast.FormattingUtils; import org.lflang.ast.IsEqual; @@ -28,46 +26,42 @@ @InjectWith(LFInjectorProvider.class) public class RoundTripTests { - @Test - public void roundTripTest() { - for (Target target : Target.values()) { - for (TestCategory category : TestCategory.values()) { - for (LFTest test : TestRegistry.getRegisteredTests(target, category, false)) { - try { - run(test.getSrcPath()); - } catch (Throwable thrown) { - fail("Test case " + test.getSrcPath() + " failed", thrown); - } - } - } + @Test + public void roundTripTest() { + for (Target target : Target.values()) { + for (TestCategory category : TestCategory.values()) { + for (LFTest test : TestRegistry.getRegisteredTests(target, category, false)) { + try { + run(test.getSrcPath()); + } catch (Throwable thrown) { + fail("Test case " + test.getSrcPath() + " failed", thrown); + } } + } } + } - private void run(Path file) throws Exception { - Model originalModel = LfParsingUtil.parse(file); - System.out.println(file); - assertThat(originalModel.eResource().getErrors(), equalTo(emptyList())); - // TODO: Check that the output is a fixed point - final int smallLineLength = 20; - final String squishedTestCase = FormattingUtils.render(originalModel, smallLineLength); - final Model resultingModel = LfParsingUtil.parseSourceAsIfInDirectory(file.getParent(), squishedTestCase); - - assertThat(resultingModel.eResource().getErrors(), equalTo(emptyList())); - Assertions.assertTrue( - new IsEqual(originalModel).doSwitch(resultingModel), - String.format( - "The reformatted version of %s was not equivalent to the original file.%n" - + "Formatted file:%n%s%n%n", - file, - squishedTestCase - ) - ); - final String normalTestCase = FormattingUtils.render(originalModel); - Assertions.assertEquals( - Files.readString(file).replaceAll("\\r\\n?", "\n"), - normalTestCase, - "File is not formatted properly, or formatter is bugged. Check " + file - ); - } + private void run(Path file) throws Exception { + Model originalModel = LfParsingUtil.parse(file); + System.out.println(file); + assertThat(originalModel.eResource().getErrors(), equalTo(emptyList())); + // TODO: Check that the output is a fixed point + final int smallLineLength = 20; + final String squishedTestCase = FormattingUtils.render(originalModel, smallLineLength); + final Model resultingModel = + LfParsingUtil.parseSourceAsIfInDirectory(file.getParent(), squishedTestCase); + assertThat(resultingModel.eResource().getErrors(), equalTo(emptyList())); + Assertions.assertTrue( + new IsEqual(originalModel).doSwitch(resultingModel), + String.format( + "The reformatted version of %s was not equivalent to the original file.%n" + + "Formatted file:%n%s%n%n", + file, squishedTestCase)); + final String normalTestCase = FormattingUtils.render(originalModel); + Assertions.assertEquals( + Files.readString(file).replaceAll("\\r\\n?", "\n"), + normalTestCase, + "File is not formatted properly, or formatter is bugged. Check " + file); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java index eede6a6831..e949ab6f9f 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import org.lflang.federated.generator.FedFileConfig; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGenerator; @@ -24,79 +23,81 @@ @ExtendWith(InjectionExtension.class) @InjectWith(LFInjectorProvider.class) -/** - * Tests for checking that target properties adequately translate into the target configuration. - */ +/** Tests for checking that target properties adequately translate into the target configuration. */ class TargetConfigTests { - @Inject - ParseHelper parser; - - @Inject - LFGenerator generator; - - @Inject - JavaIoFileSystemAccess fileAccess; - - @Inject - Provider resourceSetProvider; - - private void assertHasTargetProperty(Model model, String name) { - Assertions.assertNotNull(model); - Assertions.assertTrue( - model.getTarget().getConfig().getPairs().stream().anyMatch( - p -> p.getName().equals(name) - ) - ); - } - - /** - * Check that tracing target property affects the target configuration. - * @throws Exception - */ - @Test - public void testParsing() throws Exception { - assertHasTargetProperty(parser.parse(""" + @Inject ParseHelper parser; + + @Inject LFGenerator generator; + + @Inject JavaIoFileSystemAccess fileAccess; + + @Inject Provider resourceSetProvider; + + private void assertHasTargetProperty(Model model, String name) { + Assertions.assertNotNull(model); + Assertions.assertTrue( + model.getTarget().getConfig().getPairs().stream().anyMatch(p -> p.getName().equals(name))); + } + + /** + * Check that tracing target property affects the target configuration. + * + * @throws Exception + */ + @Test + public void testParsing() throws Exception { + assertHasTargetProperty( + parser.parse( + """ target C { tracing: true } - """), "tracing"); - } - - /** - * Check that when a federation has the "tracing" target property set, the generated federates - * will also have it set. - * @throws Exception - */ - @Test - public void testFederation() throws Exception { - fileAccess.setOutputPath("src-gen"); - - Model federation = parser.parse(""" + """), + "tracing"); + } + + /** + * Check that when a federation has the "tracing" target property set, the generated federates + * will also have it set. + * + * @throws Exception + */ + @Test + public void testFederation() throws Exception { + fileAccess.setOutputPath("src-gen"); + + Model federation = + parser.parse( + """ target C { tracing: true } reactor Foo { - + } federated reactor { a = new Foo() b = new Foo() } - """, URI.createFileURI("tmp/src/Federation.lf"), resourceSetProvider.get()); - assertHasTargetProperty(federation, "tracing"); - - var resource = federation.eResource(); - var context = new MainContext(Mode.STANDALONE, resource, fileAccess, () -> false); - - if (GeneratorUtils.isHostWindows()) return; - - generator.doGenerate(resource, fileAccess, context); - - String lfSrc = Files.readAllLines( - ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("federate__a.lf") - ).stream().reduce("\n", String::concat); - Model federate = parser.parse(lfSrc); - assertHasTargetProperty(federate, "tracing"); - } + """, + URI.createFileURI("tmp/src/Federation.lf"), + resourceSetProvider.get()); + assertHasTargetProperty(federation, "tracing"); + + var resource = federation.eResource(); + var context = new MainContext(Mode.STANDALONE, resource, fileAccess, () -> false); + + if (GeneratorUtils.isHostWindows()) return; + + generator.doGenerate(resource, fileAccess, context); + + String lfSrc = + Files.readAllLines( + ((FedFileConfig) context.getFileConfig()).getSrcPath().resolve("federate__a.lf")) + .stream() + .reduce("\n", String::concat); + Model federate = parser.parse(lfSrc); + assertHasTargetProperty(federate, "tracing"); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java index a7b1c9d8ec..a1948821eb 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java @@ -1,5 +1,6 @@ package org.lflang.tests.lsp; +import com.google.common.collect.ImmutableList; import java.io.Closeable; import java.io.IOException; import java.io.PrintWriter; @@ -17,339 +18,364 @@ import java.util.function.Predicate; import java.util.stream.Stream; -import com.google.common.collect.ImmutableList; - /** * Insert problems into integration tests. + * * @author Peter Donovan */ @SuppressWarnings("ClassCanBeRecord") class ErrorInserter { - /** A basic error inserter builder on which more specific error inserters can be built. */ - private static final Builder BASE_ERROR_INSERTER = new Builder() - .insertCondition((s0, s1) -> Stream.of(s0, s1).allMatch(it -> Stream.of(";", "}", "{").anyMatch(it::endsWith))) - .insertCondition((s0, s1) -> !s1.trim().startsWith("else")) - .insertable(" 0 = 1;").insertable("some_undeclared_var1524263 = 9;").insertable(" ++;"); - public static final Builder C = BASE_ERROR_INSERTER - .replacer("lf_set(", "UNDEFINED_NAME2828376(") - .replacer("lf_schedule(", "undefined_name15291838("); - public static final Builder CPP = BASE_ERROR_INSERTER - .replacer(".get", ".undefined_name15291838") - .replacer("std::", "undefined_name3286634::"); - public static final Builder PYTHON_SYNTAX_ONLY = new Builder() - .insertable(" +++++;").insertable(" .."); - public static final Builder PYTHON = PYTHON_SYNTAX_ONLY - .replacer("print(", "undefined_name15291838("); - public static final Builder RUST = BASE_ERROR_INSERTER - .replacer("println!", "undefined_name15291838!") - .replacer("ctx.", "undefined_name3286634."); - public static final Builder TYPESCRIPT = BASE_ERROR_INSERTER - .replacer("requestErrorStop(", "not_an_attribute_of_util9764(") - .replacer("const ", "var "); - - /** An {@code AlteredTest} represents an altered version of what was a valid LF file. */ - static class AlteredTest implements Closeable { - - /** A {@code OnceTrue} is randomly true once, and then never again. */ - private static class OnceTrue { - boolean beenTrue; - Random random; - private OnceTrue(Random random) { - this.beenTrue = false; - this.random = random; - } - private boolean get() { - if (beenTrue) return false; - return beenTrue = random.nextBoolean() && random.nextBoolean(); - } - } - - /** 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; - - /** - * Initialize a possibly altered copy of {@code originalTest}. - * @param originalTest A path to an LF file that serves as a test. - * @param insertCondition Whether the error inserter is permitted to insert a line between two given lines. - * @throws IOException if the content of {@code originalTest} cannot be read. - */ - private AlteredTest(Path originalTest, BiPredicate insertCondition) throws IOException { - this.badLines = new ArrayList<>(); - this.srcFile = originalTest; - this.lines = new LinkedList<>(); // Constant-time insertion during iteration is desired. - this.lines.addAll(Files.readAllLines(srcFile)); - this.insertCondition = it -> { - it.previous(); - String s0 = it.previous(); - it.next(); - String s1 = it.next(); - return insertCondition.test(s0, s1); - }; - } + /** A basic error inserter builder on which more specific error inserters can be built. */ + private static final Builder BASE_ERROR_INSERTER = + new Builder() + .insertCondition( + (s0, s1) -> + Stream.of(s0, s1).allMatch(it -> Stream.of(";", "}", "{").anyMatch(it::endsWith))) + .insertCondition((s0, s1) -> !s1.trim().startsWith("else")) + .insertable(" 0 = 1;") + .insertable("some_undeclared_var1524263 = 9;") + .insertable(" ++;"); + + public static final Builder C = + BASE_ERROR_INSERTER + .replacer("lf_set(", "UNDEFINED_NAME2828376(") + .replacer("lf_schedule(", "undefined_name15291838("); + public static final Builder CPP = + BASE_ERROR_INSERTER + .replacer(".get", ".undefined_name15291838") + .replacer("std::", "undefined_name3286634::"); + public static final Builder PYTHON_SYNTAX_ONLY = + new Builder().insertable(" +++++;").insertable(" .."); + public static final Builder PYTHON = + PYTHON_SYNTAX_ONLY.replacer("print(", "undefined_name15291838("); + public static final Builder RUST = + BASE_ERROR_INSERTER + .replacer("println!", "undefined_name15291838!") + .replacer("ctx.", "undefined_name3286634."); + public static final Builder TYPESCRIPT = + BASE_ERROR_INSERTER + .replacer("requestErrorStop(", "not_an_attribute_of_util9764(") + .replacer("const ", "var "); + + /** An {@code AlteredTest} represents an altered version of what was a valid LF file. */ + static class AlteredTest implements Closeable { + + /** A {@code OnceTrue} is randomly true once, and then never again. */ + private static class OnceTrue { + boolean beenTrue; + Random random; + + private OnceTrue(Random random) { + this.beenTrue = false; + this.random = random; + } - /** Return the location where the content of {@code this} lives. */ - public Path getSrcFile() { - return srcFile; - } + private boolean get() { + if (beenTrue) return false; + return beenTrue = random.nextBoolean() && random.nextBoolean(); + } + } - /** - * Write the altered version of the test to the file system. - * @throws IOException If an I/O error occurred. - */ - public void write() throws IOException { - Path src = srcFile; - if (!src.toFile().renameTo(swapFile(src).toFile())) { - throw new IOException("Failed to create a swap file."); - } - try (PrintWriter writer = new PrintWriter(src.toFile())) { - lines.forEach(writer::println); - } - } + /** 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; - /** - * Restore the file associated with this test to its original state. - */ - @Override - public void close() throws IOException { - Path src = srcFile; - if (!swapFile(src).toFile().exists()) throw new IllegalStateException("Swap file does not exist."); - if (!src.toFile().delete()) { - throw new IOException("Failed to delete the file associated with the original test."); - } - if (!swapFile(src).toFile().renameTo(src.toFile())) { - throw new IOException("Failed to restore the altered LF file to its original state."); - } - } + /** + * Initialize a possibly altered copy of {@code originalTest}. + * + * @param originalTest A path to an LF file that serves as a test. + * @param insertCondition Whether the error inserter is permitted to insert a line between two + * given lines. + * @throws IOException if the content of {@code originalTest} cannot be read. + */ + private AlteredTest(Path originalTest, BiPredicate insertCondition) + throws IOException { + this.badLines = new ArrayList<>(); + this.srcFile = originalTest; + this.lines = new LinkedList<>(); // Constant-time insertion during iteration is desired. + this.lines.addAll(Files.readAllLines(srcFile)); + this.insertCondition = + it -> { + it.previous(); + String s0 = it.previous(); + it.next(); + String s1 = it.next(); + return insertCondition.test(s0, s1); + }; + } - @Override - public String toString() { - int lengthOfPrefix = 6; - StringBuilder ret = new StringBuilder( - lines.stream().mapToInt(String::length).reduce(0, Integer::sum) - + lines.size() * lengthOfPrefix - ); - for (int i = 0; i < lines.size(); i++) { - ret.append(badLines.contains(i) ? "-> " : " ") - .append(String.format("%1$2s ", i)) - .append(lines.get(i)).append("\n"); - } - return ret.toString(); - } + /** Return the location where the content of {@code this} lives. */ + public Path getSrcFile() { + return srcFile; + } - /** Return the lines where this differs from the test from which it was derived. */ - public ImmutableList getBadLines() { - return ImmutableList.copyOf(badLines); - } + /** + * Write the altered version of the test to the file system. + * + * @throws IOException If an I/O error occurred. + */ + public void write() throws IOException { + Path src = srcFile; + if (!src.toFile().renameTo(swapFile(src).toFile())) { + throw new IOException("Failed to create a swap file."); + } + try (PrintWriter writer = new PrintWriter(src.toFile())) { + lines.forEach(writer::println); + } + } - /** - * Attempt to replace a line of this test with a different line of target language code. - * @param replacer A function that replaces lines of code with possibly different lines. - */ - public void replace(Function replacer, Random random) { - OnceTrue onceTrue = new OnceTrue(random); - alter((it, current) -> { - if (!onceTrue.get()) return false; - String newLine = replacer.apply(current); - it.remove(); - it.add(newLine); - return !newLine.equals(current); - }); - } + /** Restore the file associated with this test to its original state. */ + @Override + public void close() throws IOException { + Path src = srcFile; + if (!swapFile(src).toFile().exists()) + throw new IllegalStateException("Swap file does not exist."); + if (!src.toFile().delete()) { + throw new IOException("Failed to delete the file associated with the original test."); + } + if (!swapFile(src).toFile().renameTo(src.toFile())) { + throw new IOException("Failed to restore the altered LF file to its original state."); + } + } - /** - * Attempt to insert a new line of target language code into this test. - * @param line The line to be inserted. - */ - public void insert(String line, Random random) { - OnceTrue onceTrue = new OnceTrue(random); - alter((it, current) -> { - if (insertCondition.test(it) && onceTrue.get()) { - it.previous(); - it.add(line); - it.next(); - return true; - } - return false; - }); - } + @Override + public String toString() { + int lengthOfPrefix = 6; + StringBuilder ret = + new StringBuilder( + lines.stream().mapToInt(String::length).reduce(0, Integer::sum) + + lines.size() * lengthOfPrefix); + for (int i = 0; i < lines.size(); i++) { + ret.append(badLines.contains(i) ? "-> " : " ") + .append(String.format("%1$2s ", i)) + .append(lines.get(i)) + .append("\n"); + } + return ret.toString(); + } - /** - * Alter the content of this test. - * @param alterer A function whose first argument is an iterator over the lines of {@code this}, whose second - * argument is the line most recently returned by that iterator, and whose return value is - * whether an alteration was successfully performed. This function is only applied within - * multiline code blocks. - */ - private void alter(BiFunction, String, Boolean> alterer) { - ListIterator it = lines.listIterator(); - boolean inCodeBlock = false; - int lineNumber = 0; - while (it.hasNext()) { - String current = it.next(); - String uncommented = current.contains("//") ? - current.substring(0, current.indexOf("//")) : current; - uncommented = uncommented.contains("#") ? - uncommented.substring(0, uncommented.indexOf("#")) : current; - if (uncommented.contains("=}")) inCodeBlock = false; - if (inCodeBlock && alterer.apply(it, current)) badLines.add(lineNumber); - if (uncommented.contains("{=")) inCodeBlock = true; - if (uncommented.contains("{=") && uncommented.contains("=}")) { - inCodeBlock = uncommented.lastIndexOf("{=") > uncommented.lastIndexOf("=}"); - } - lineNumber++; - } - } + /** Return the lines where this differs from the test from which it was derived. */ + public ImmutableList getBadLines() { + return ImmutableList.copyOf(badLines); + } - /** Return the swap file associated with {@code f}. */ - private static Path swapFile(Path p) { - return p.getParent().resolve("." + p.getFileName() + ".swp"); - } + /** + * Attempt to replace a line of this test with a different line of target language code. + * + * @param replacer A function that replaces lines of code with possibly different lines. + */ + public void replace(Function replacer, Random random) { + OnceTrue onceTrue = new OnceTrue(random); + alter( + (it, current) -> { + if (!onceTrue.get()) return false; + String newLine = replacer.apply(current); + it.remove(); + it.add(newLine); + return !newLine.equals(current); + }); } - /** A builder for an error inserter. */ - public static class Builder { - private static class Node implements Iterable { - private final Node previous; - private final T item; - private Node(Node previous, T item) { - this.previous = previous; - this.item = item; + /** + * Attempt to insert a new line of target language code into this test. + * + * @param line The line to be inserted. + */ + public void insert(String line, Random random) { + OnceTrue onceTrue = new OnceTrue(random); + alter( + (it, current) -> { + if (insertCondition.test(it) && onceTrue.get()) { + it.previous(); + it.add(line); + it.next(); + return true; } + return false; + }); + } - @Override - public Iterator iterator() { - NodeIterator ret = new NodeIterator<>(); - ret.current = this; - return ret; - } + /** + * Alter the content of this test. + * + * @param alterer A function whose first argument is an iterator over the lines of {@code this}, + * whose second argument is the line most recently returned by that iterator, and whose + * return value is whether an alteration was successfully performed. This function is only + * applied within multiline code blocks. + */ + private void alter(BiFunction, String, Boolean> alterer) { + ListIterator it = lines.listIterator(); + boolean inCodeBlock = false; + int lineNumber = 0; + while (it.hasNext()) { + String current = it.next(); + String uncommented = + current.contains("//") ? current.substring(0, current.indexOf("//")) : current; + uncommented = + uncommented.contains("#") + ? uncommented.substring(0, uncommented.indexOf("#")) + : current; + if (uncommented.contains("=}")) inCodeBlock = false; + if (inCodeBlock && alterer.apply(it, current)) badLines.add(lineNumber); + if (uncommented.contains("{=")) inCodeBlock = true; + if (uncommented.contains("{=") && uncommented.contains("=}")) { + inCodeBlock = uncommented.lastIndexOf("{=") > uncommented.lastIndexOf("=}"); + } + lineNumber++; + } + } - private static class NodeIterator implements Iterator { - private Node current; + /** Return the swap file associated with {@code f}. */ + private static Path swapFile(Path p) { + return p.getParent().resolve("." + p.getFileName() + ".swp"); + } + } - @Override - public boolean hasNext() { - return current != null; - } + /** A builder for an error inserter. */ + public static class Builder { + private static class Node implements Iterable { + private final Node previous; + private final T item; - @Override - public T next() { - T ret = current.item; - current = current.previous; - return ret; - } - } - } - private final Node> replacers; - private final Node insertables; - private final BiPredicate insertCondition; + private Node(Node previous, T item) { + this.previous = previous; + this.item = item; + } - /** Initializes a builder for error inserters. */ - public Builder() { - this(null, null, (s0, s1) -> true); - } + @Override + public Iterator iterator() { + NodeIterator ret = new NodeIterator<>(); + ret.current = this; + return ret; + } - /** Construct a builder with the given replacers and insertables. */ - private Builder( - Node> replacers, - Node insertables, - BiPredicate insertCondition - ) { - this.replacers = replacers; - this.insertables = insertables; - this.insertCondition = insertCondition; - } + private static class NodeIterator implements Iterator { + private Node current; - /** - * Record that the resulting {@code ErrorInserter} may replace {@code phrase} with {@code alternativePhrase}. - * @param phrase A phrase in target language code. - * @param alternativePhrase A phrase that {@code phrase} may be replaced with in order to introduce an error. - * @return A {@code Builder} that knows about all the edits that {@code this} knows about, plus the edit that - * replaces {@code phrase} with {@code alternativePhrase}. - */ - public Builder replacer(String phrase, String alternativePhrase) { - return new Builder( - new Node<>( - replacers, - line -> { - int changeableEnd = line.length(); - for (String bad : new String[]{"#", "//", "\""}) { - if (line.contains(bad)) changeableEnd = Math.min(changeableEnd, line.indexOf(bad)); - } - return line.substring(0, changeableEnd).replace(phrase, alternativePhrase) - + line.substring(changeableEnd); - } - ), - insertables, - insertCondition - ); + @Override + public boolean hasNext() { + return current != null; } - /** Record that {@code} line may be inserted in order to introduce an error. */ - public Builder insertable(String line) { - return new Builder(replacers, new Node<>(insertables, line), insertCondition); + @Override + public T next() { + T ret = current.item; + current = current.previous; + return ret; } + } + } - /** - * Record that for any lines X, Y, insertCondition(X, Y) is a necessary condition that a line may be inserted - * between X and Y. - */ - public Builder insertCondition(BiPredicate insertCondition) { - return new Builder(replacers, insertables, this.insertCondition.and(insertCondition)); - } + private final Node> replacers; + private final Node insertables; + private final BiPredicate insertCondition; - /** Get the error inserter generated by {@code this}. */ - public ErrorInserter get(Random random) { - return new ErrorInserter( - random, - replacers == null ? ImmutableList.of() : ImmutableList.copyOf(replacers), - insertables == null ? ImmutableList.of() : ImmutableList.copyOf(insertables), - insertCondition - ); - } + /** Initializes a builder for error inserters. */ + public Builder() { + this(null, null, (s0, s1) -> true); } - private static final int MAX_ALTERATION_ATTEMPTS = 100; + /** Construct a builder with the given replacers and insertables. */ + private Builder( + Node> replacers, + Node insertables, + BiPredicate insertCondition) { + this.replacers = replacers; + this.insertables = insertables; + this.insertCondition = insertCondition; + } - private final Random random; - private final ImmutableList> replacers; - private final ImmutableList insertables; - private final BiPredicate insertCondition; + /** + * Record that the resulting {@code ErrorInserter} may replace {@code phrase} with {@code + * alternativePhrase}. + * + * @param phrase A phrase in target language code. + * @param alternativePhrase A phrase that {@code phrase} may be replaced with in order to + * introduce an error. + * @return A {@code Builder} that knows about all the edits that {@code this} knows about, plus + * the edit that replaces {@code phrase} with {@code alternativePhrase}. + */ + public Builder replacer(String phrase, String alternativePhrase) { + return new Builder( + new Node<>( + replacers, + line -> { + int changeableEnd = line.length(); + for (String bad : new String[] {"#", "//", "\""}) { + if (line.contains(bad)) + changeableEnd = Math.min(changeableEnd, line.indexOf(bad)); + } + return line.substring(0, changeableEnd).replace(phrase, alternativePhrase) + + line.substring(changeableEnd); + }), + insertables, + insertCondition); + } - private ErrorInserter( - Random random, - ImmutableList> replacers, - ImmutableList insertables, - BiPredicate insertCondition - ) { - this.random = random; - this.replacers = replacers; - this.insertables = insertables; - this.insertCondition = insertCondition; + /** Record that {@code} line may be inserted in order to introduce an error. */ + public Builder insertable(String line) { + return new Builder(replacers, new Node<>(insertables, line), insertCondition); } /** - * Alter the given test and return the altered version. - * @param test The path to the test. - * @return An {@code AlteredTest} that is based on {@code test}. + * Record that for any lines X, Y, insertCondition(X, Y) is a necessary condition that a line + * may be inserted between X and Y. */ - public AlteredTest alterTest(Path test) throws IOException { - AlteredTest alterable = new AlteredTest(test, insertCondition); - int remainingAlterationAttempts = MAX_ALTERATION_ATTEMPTS; - while (alterable.getBadLines().isEmpty() && remainingAlterationAttempts-- > 0) { - if (random.nextBoolean() && !replacers.isEmpty()) { - alterable.replace(replacers.get(random.nextInt(replacers.size())), random); - } else if (!insertables.isEmpty()) { - alterable.insert(insertables.get(random.nextInt(insertables.size())), random); - } - } - alterable.write(); - return alterable; + public Builder insertCondition(BiPredicate insertCondition) { + return new Builder(replacers, insertables, this.insertCondition.and(insertCondition)); + } + + /** Get the error inserter generated by {@code this}. */ + public ErrorInserter get(Random random) { + return new ErrorInserter( + random, + replacers == null ? ImmutableList.of() : ImmutableList.copyOf(replacers), + insertables == null ? ImmutableList.of() : ImmutableList.copyOf(insertables), + insertCondition); + } + } + + private static final int MAX_ALTERATION_ATTEMPTS = 100; + + private final Random random; + private final ImmutableList> replacers; + private final ImmutableList insertables; + private final BiPredicate insertCondition; + + private ErrorInserter( + Random random, + ImmutableList> replacers, + ImmutableList insertables, + BiPredicate insertCondition) { + this.random = random; + this.replacers = replacers; + this.insertables = insertables; + this.insertCondition = insertCondition; + } + + /** + * Alter the given test and return the altered version. + * + * @param test The path to the test. + * @return An {@code AlteredTest} that is based on {@code test}. + */ + public AlteredTest alterTest(Path test) throws IOException { + AlteredTest alterable = new AlteredTest(test, insertCondition); + int remainingAlterationAttempts = MAX_ALTERATION_ATTEMPTS; + while (alterable.getBadLines().isEmpty() && remainingAlterationAttempts-- > 0) { + if (random.nextBoolean() && !replacers.isEmpty()) { + alterable.replace(replacers.get(random.nextInt(replacers.size())), random); + } else if (!insertables.isEmpty()) { + alterable.insert(insertables.get(random.nextInt(insertables.size())), random); + } } + alterable.write(); + return alterable; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java b/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java index 99c1260d44..fe52d6016c 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java @@ -9,12 +9,10 @@ import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; - -import org.eclipse.lsp4j.Diagnostic; import org.eclipse.emf.common.util.URI; +import org.eclipse.lsp4j.Diagnostic; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; - import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; import org.lflang.Target; @@ -33,188 +31,211 @@ */ class LspTests { - /** The test categories that should be excluded from LSP tests. */ - private static final TestCategory[] EXCLUDED_CATEGORIES = { - TestCategory.SERIALIZATION, TestCategory.DOCKER, TestCategory.DOCKER_FEDERATED - }; - private static final Predicate> NOT_SUPPORTED = diagnosticsHaveKeyword("supported"); - private static final Predicate> MISSING_DEPENDENCY = 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. */ - private static final int SAMPLES_PER_CATEGORY_VALIDATION_TESTS = 3; - - /** The {@code IntegratedBuilder} instance whose behavior is to be tested. */ - private static final IntegratedBuilder builder = new LFStandaloneSetup(new LFRuntimeModule()) - .createInjectorAndDoEMFRegistration().getInstance(IntegratedBuilder.class); - - /** Test for false negatives in Python syntax-only validation. */ - @Test - void pythonValidationTestSyntaxOnly() throws IOException { - targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON_SYNTAX_ONLY); - } - - /** Test for false negatives in C++ validation. */ - @Test - void cppValidationTest() throws IOException { - targetLanguageValidationTest(Target.CPP, ErrorInserter.CPP); - } - - /** Test for false negatives in Python validation. */ - @Test - void pythonValidationTest() throws IOException { - targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON); - } - - /** Test for false negatives in Rust validation. */ - @Test - void rustValidationTest() throws IOException { - targetLanguageValidationTest(Target.Rust, ErrorInserter.RUST); - } - - /** Test for false negatives in TypeScript validation. */ - @Test - void typescriptValidationTest() throws IOException { - targetLanguageValidationTest(Target.TS, ErrorInserter.TYPESCRIPT); - } - - /** - * Test for false negatives in the validation of LF files. - * @param target The target language of the LF files to be validated. - * @param builder A builder for the error inserter that will be used. - */ - private void targetLanguageValidationTest(Target target, ErrorInserter.Builder builder) throws IOException { - long seed = new Random().nextLong(); - System.out.printf("Running validation tests for %s with random seed %d.%n", target.getDisplayName(), seed); - Random random = new Random(seed); - int i = SAMPLES_PER_CATEGORY_VALIDATION_TESTS; - while (i-- > 0) checkDiagnostics( - target, - alteredTest -> MISSING_DEPENDENCY.or(diagnostics -> alteredTest.getBadLines().stream().allMatch( - badLine -> { - System.out.print("Expecting an error to be reported at line " + badLine + "..."); - boolean result = NOT_SUPPORTED.test(diagnostics) || diagnostics.stream().anyMatch( - diagnostic -> diagnostic.getRange().getStart().getLine() == badLine - ); - if (result) { - System.out.println(" Success."); - } else { - System.out.println(" but the expected error could not be found."); - System.out.printf( - "%s failed. Content of altered version of %s:%n%s%n", - alteredTest.getSrcFile(), - alteredTest.getSrcFile(), - TestBase.THIN_LINE - ); - System.out.println(alteredTest + "\n" + TestBase.THIN_LINE); - } - return result; - } - )), - builder.get(random), - random - ); - } - - /** - * Verify that the diagnostics that result from fully validating tests associated with {@code target} satisfy - * {@code requirementGetter}. - * @param target Any target language. - * @param requirementGetter A map from altered tests to the requirements that diagnostics regarding those tests - * must meet. - * @param alterer The means of inserting problems into the tests, or {@code null} if problems are not to be - * inserted. - * @param random The {@code Random} instance that determines which tests are selected. - * @throws IOException upon failure to write an altered copy of some test to storage. - */ - private void checkDiagnostics( - Target target, - Function>> requirementGetter, - ErrorInserter alterer, - Random random - ) throws IOException { - MockLanguageClient client = new MockLanguageClient(); - LanguageServerErrorReporter.setClient(client); - for (LFTest test : selectTests(target, random)) { - client.clearDiagnostics(); - if (alterer != null) { - try (AlteredTest altered = alterer.alterTest(test.getSrcPath())) { - runTest(altered.getSrcFile()); - Assertions.assertTrue(requirementGetter.apply(altered).test(client.getReceivedDiagnostics())); - } - } else { - runTest(test.getSrcPath()); - Assertions.assertTrue(requirementGetter.apply(null).test(client.getReceivedDiagnostics())); - } + /** The test categories that should be excluded from LSP tests. */ + private static final TestCategory[] EXCLUDED_CATEGORIES = { + TestCategory.SERIALIZATION, TestCategory.DOCKER, TestCategory.DOCKER_FEDERATED + }; + + private static final Predicate> NOT_SUPPORTED = + diagnosticsHaveKeyword("supported"); + private static final Predicate> MISSING_DEPENDENCY = + 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. + */ + private static final int SAMPLES_PER_CATEGORY_VALIDATION_TESTS = 3; + + /** The {@code IntegratedBuilder} instance whose behavior is to be tested. */ + private static final IntegratedBuilder builder = + new LFStandaloneSetup(new LFRuntimeModule()) + .createInjectorAndDoEMFRegistration() + .getInstance(IntegratedBuilder.class); + + /** Test for false negatives in Python syntax-only validation. */ + @Test + void pythonValidationTestSyntaxOnly() throws IOException { + targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON_SYNTAX_ONLY); + } + + /** Test for false negatives in C++ validation. */ + @Test + void cppValidationTest() throws IOException { + targetLanguageValidationTest(Target.CPP, ErrorInserter.CPP); + } + + /** Test for false negatives in Python validation. */ + @Test + void pythonValidationTest() throws IOException { + targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON); + } + + /** Test for false negatives in Rust validation. */ + @Test + void rustValidationTest() throws IOException { + targetLanguageValidationTest(Target.Rust, ErrorInserter.RUST); + } + + /** Test for false negatives in TypeScript validation. */ + @Test + void typescriptValidationTest() throws IOException { + targetLanguageValidationTest(Target.TS, ErrorInserter.TYPESCRIPT); + } + + /** + * Test for false negatives in the validation of LF files. + * + * @param target The target language of the LF files to be validated. + * @param builder A builder for the error inserter that will be used. + */ + private void targetLanguageValidationTest(Target target, ErrorInserter.Builder builder) + throws IOException { + long seed = new Random().nextLong(); + System.out.printf( + "Running validation tests for %s with random seed %d.%n", target.getDisplayName(), seed); + Random random = new Random(seed); + int i = SAMPLES_PER_CATEGORY_VALIDATION_TESTS; + while (i-- > 0) + checkDiagnostics( + target, + alteredTest -> + MISSING_DEPENDENCY.or( + diagnostics -> + alteredTest.getBadLines().stream() + .allMatch( + badLine -> { + System.out.print( + "Expecting an error to be reported at line " + badLine + "..."); + boolean result = + NOT_SUPPORTED.test(diagnostics) + || diagnostics.stream() + .anyMatch( + diagnostic -> + diagnostic.getRange().getStart().getLine() + == badLine); + if (result) { + System.out.println(" Success."); + } else { + System.out.println(" but the expected error could not be found."); + System.out.printf( + "%s failed. Content of altered version of %s:%n%s%n", + alteredTest.getSrcFile(), + alteredTest.getSrcFile(), + TestBase.THIN_LINE); + System.out.println(alteredTest + "\n" + TestBase.THIN_LINE); + } + return result; + })), + builder.get(random), + random); + } + + /** + * Verify that the diagnostics that result from fully validating tests associated with {@code + * target} satisfy {@code requirementGetter}. + * + * @param target Any target language. + * @param requirementGetter A map from altered tests to the requirements that diagnostics + * regarding those tests must meet. + * @param alterer The means of inserting problems into the tests, or {@code null} if problems are + * not to be inserted. + * @param random The {@code Random} instance that determines which tests are selected. + * @throws IOException upon failure to write an altered copy of some test to storage. + */ + private void checkDiagnostics( + Target target, + Function>> requirementGetter, + ErrorInserter alterer, + Random random) + throws IOException { + MockLanguageClient client = new MockLanguageClient(); + LanguageServerErrorReporter.setClient(client); + for (LFTest test : selectTests(target, random)) { + client.clearDiagnostics(); + if (alterer != null) { + try (AlteredTest altered = alterer.alterTest(test.getSrcPath())) { + runTest(altered.getSrcFile()); + Assertions.assertTrue( + requirementGetter.apply(altered).test(client.getReceivedDiagnostics())); } + } else { + runTest(test.getSrcPath()); + Assertions.assertTrue(requirementGetter.apply(null).test(client.getReceivedDiagnostics())); + } } - - /** - * Select a test from each test category. - * @param target The target language of the desired tests. - * @param random The {@code Random} instance that determines which tests are selected. - * @return A sample of one integration test per target, per category. - */ - private Set selectTests(Target target, Random random) { - Set ret = new HashSet<>(); - for (TestCategory category : selectedCategories()) { - Set registeredTests = TestRegistry.getRegisteredTests(target, category, false); - if (registeredTests.size() == 0) continue; - int relativeIndex = random.nextInt(registeredTests.size()); - for (LFTest t : registeredTests) { - if (relativeIndex-- == 0) { - ret.add(t); - break; - } - } + } + + /** + * Select a test from each test category. + * + * @param target The target language of the desired tests. + * @param random The {@code Random} instance that determines which tests are selected. + * @return A sample of one integration test per target, per category. + */ + private Set selectTests(Target target, Random random) { + Set ret = new HashSet<>(); + for (TestCategory category : selectedCategories()) { + Set registeredTests = TestRegistry.getRegisteredTests(target, category, false); + if (registeredTests.size() == 0) continue; + int relativeIndex = random.nextInt(registeredTests.size()); + for (LFTest t : registeredTests) { + if (relativeIndex-- == 0) { + ret.add(t); + break; } - return ret; - } - - /** Return the non-excluded categories. */ - private Iterable selectedCategories() { - return () -> Arrays.stream(TestCategory.values()).filter( - category -> Arrays.stream(EXCLUDED_CATEGORIES).noneMatch(category::equals) - ).iterator(); + } } - - /** - * Return the predicate that a list of diagnostics contains the given keyword. - * @param keyword A keyword that a list of diagnostics should be searched for. - * @return The predicate, "X mentions {@code keyword}." - */ - private static Predicate> diagnosticsHaveKeyword(String keyword) { - return diagnostics -> diagnostics.stream().anyMatch( - d -> Arrays.asList(d.getMessage().toLowerCase().split("\\b")).contains(keyword) - ); - } - - /** - * Return the predicate that a list of diagnostics contains the given text. - * @param requiredText A keyword that a list of diagnostics should be searched for. - * @return The predicate, "X includes {@code requiredText}." - */ - private static Predicate> diagnosticsIncludeText(@SuppressWarnings("SameParameterValue") String requiredText) { - return diagnostics -> diagnostics.stream().anyMatch( - d -> d.getMessage().toLowerCase().contains(requiredText) - ); - } - - /** - * Run the given test. - * @param test The test b - */ - private void runTest(Path test) { - MockReportProgress reportProgress = new MockReportProgress(); - try { - builder.run( - URI.createFileURI(test.toString()), - false, reportProgress, - () -> false - ); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - Assertions.assertFalse(reportProgress.failed()); + return ret; + } + + /** Return the non-excluded categories. */ + private Iterable selectedCategories() { + return () -> + Arrays.stream(TestCategory.values()) + .filter(category -> Arrays.stream(EXCLUDED_CATEGORIES).noneMatch(category::equals)) + .iterator(); + } + + /** + * Return the predicate that a list of diagnostics contains the given keyword. + * + * @param keyword A keyword that a list of diagnostics should be searched for. + * @return The predicate, "X mentions {@code keyword}." + */ + private static Predicate> diagnosticsHaveKeyword(String keyword) { + return diagnostics -> + diagnostics.stream() + .anyMatch( + d -> Arrays.asList(d.getMessage().toLowerCase().split("\\b")).contains(keyword)); + } + + /** + * Return the predicate that a list of diagnostics contains the given text. + * + * @param requiredText A keyword that a list of diagnostics should be searched for. + * @return The predicate, "X includes {@code requiredText}." + */ + private static Predicate> diagnosticsIncludeText( + @SuppressWarnings("SameParameterValue") String requiredText) { + return diagnostics -> + diagnostics.stream().anyMatch(d -> d.getMessage().toLowerCase().contains(requiredText)); + } + + /** + * Run the given test. + * + * @param test The test b + */ + private void runTest(Path test) { + MockReportProgress reportProgress = new MockReportProgress(); + try { + builder.run(URI.createFileURI(test.toString()), false, reportProgress, () -> false); + } catch (Exception e) { + e.printStackTrace(); + throw e; } + Assertions.assertFalse(reportProgress.failed()); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/MockLanguageClient.java b/org.lflang.tests/src/org/lflang/tests/lsp/MockLanguageClient.java index 8aad48c547..1e3e06ef05 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/MockLanguageClient.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/MockLanguageClient.java @@ -4,7 +4,6 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; - import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.lsp4j.MessageActionItem; @@ -20,49 +19,53 @@ */ public class MockLanguageClient implements LanguageClient { - private List receivedDiagnostics = new ArrayList<>(); + private List receivedDiagnostics = new ArrayList<>(); - @Override - public void telemetryEvent(Object object) { - // Do nothing. - } + @Override + public void telemetryEvent(Object object) { + // Do nothing. + } - @Override - public void publishDiagnostics(PublishDiagnosticsParams diagnostics) { - receivedDiagnostics.addAll(diagnostics.getDiagnostics()); - for (Diagnostic d : diagnostics.getDiagnostics()) { - ( - (d.getSeverity() == DiagnosticSeverity.Error || d.getSeverity() == DiagnosticSeverity.Warning) ? - System.err : System.out - ).println( - "Test client received diagnostic at line " + d.getRange().getStart().getLine() + ": " + d.getMessage() - ); - } + @Override + public void publishDiagnostics(PublishDiagnosticsParams diagnostics) { + receivedDiagnostics.addAll(diagnostics.getDiagnostics()); + for (Diagnostic d : diagnostics.getDiagnostics()) { + ((d.getSeverity() == DiagnosticSeverity.Error + || d.getSeverity() == DiagnosticSeverity.Warning) + ? System.err + : System.out) + .println( + "Test client received diagnostic at line " + + d.getRange().getStart().getLine() + + ": " + + d.getMessage()); } + } - @Override - public void showMessage(MessageParams messageParams) { - System.out.println("Test client received message: " + messageParams.getMessage()); - } + @Override + public void showMessage(MessageParams messageParams) { + System.out.println("Test client received message: " + messageParams.getMessage()); + } - @Override - public CompletableFuture showMessageRequest(ShowMessageRequestParams requestParams) { - showMessage(requestParams); - return null; - } + @Override + public CompletableFuture showMessageRequest( + ShowMessageRequestParams requestParams) { + showMessage(requestParams); + return null; + } - @Override - public void logMessage(MessageParams message) { - showMessage(message); - } + @Override + public void logMessage(MessageParams message) { + showMessage(message); + } - /** Return the diagnostics that {@code this} has received. */ - public List getReceivedDiagnostics() { - return Collections.unmodifiableList(receivedDiagnostics); - } + /** Return the diagnostics that {@code this} has received. */ + public List getReceivedDiagnostics() { + return Collections.unmodifiableList(receivedDiagnostics); + } - /** Clear the diagnostics recorded by {@code this}. */ - public void clearDiagnostics() { - receivedDiagnostics.clear(); - } + /** Clear the diagnostics recorded by {@code this}. */ + public void clearDiagnostics() { + receivedDiagnostics.clear(); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java b/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java index 014fcc7276..f0cfb088c1 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java @@ -8,26 +8,29 @@ * @author Peter Donovan */ public class MockReportProgress implements IntegratedBuilder.ReportProgress { - private int previousPercentProgress; - private boolean failed; - public MockReportProgress() { - previousPercentProgress = 0; - failed = false; - } + private int previousPercentProgress; + private boolean failed; - @Override - public void apply(String message, Integer percentage) { - System.out.printf("MockReportProgress: %s [%d -> %d]%n", message, previousPercentProgress, percentage); - if (percentage == null) return; - if (percentage < previousPercentProgress || percentage < 0 || percentage > 100) failed = true; - previousPercentProgress = percentage; - } + public MockReportProgress() { + previousPercentProgress = 0; + failed = false; + } - /** - * Returns whether an invalid sequence of progress reports was received. - * @return whether an invalid sequence of progress reports was received - */ - public boolean failed() { - return failed; - } + @Override + public void apply(String message, Integer percentage) { + System.out.printf( + "MockReportProgress: %s [%d -> %d]%n", message, previousPercentProgress, percentage); + if (percentage == null) return; + if (percentage < previousPercentProgress || percentage < 0 || percentage > 100) failed = true; + previousPercentProgress = percentage; + } + + /** + * Returns whether an invalid sequence of progress reports was received. + * + * @return whether an invalid sequence of progress reports was received + */ + public boolean failed() { + return failed; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java index e783c335a0..95363fd30b 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java @@ -2,9 +2,7 @@ import java.util.List; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - import org.lflang.Target; import org.lflang.tests.Configurators; import org.lflang.tests.RuntimeTest; @@ -17,17 +15,19 @@ */ public class CArduinoTest extends RuntimeTest { - public CArduinoTest() { - super(Target.C); - } + public CArduinoTest() { + super(Target.C); + } - @Test - public void buildArduinoTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runTestsFor(List.of(Target.C), - Message.DESC_ARDUINO, - TestCategory.ARDUINO::equals, Configurators::noChanges, - TestLevel.BUILD, - false); - } + @Test + public void buildArduinoTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runTestsFor( + List.of(Target.C), + Message.DESC_ARDUINO, + TestCategory.ARDUINO::equals, + Configurators::noChanges, + TestLevel.BUILD, + false); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java index c8c2fc5b93..ba1865e870 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java @@ -2,51 +2,49 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; -import org.lflang.ast.ASTUtils; import org.lflang.Target; +import org.lflang.ast.ASTUtils; import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; /** * Collection of tests for the CCpp target. * - * NOTE: This test does not inherit any tests because it directly extends TestBase. + *

    NOTE: This test does not inherit any tests because it directly extends TestBase. * * @author Marten Lohstroh */ public class CCppTest extends TestBase { - /** - * This target selects the C target it has no tests defined for it. - * Instead, it reconfigures existing C tests to adopt the CCpp target. - */ - public CCppTest() { - super(Target.C); - } + /** + * This target selects the C target it has no tests defined for it. Instead, it reconfigures + * existing C tests to adopt the CCpp target. + */ + public CCppTest() { + super(Target.C); + } - /** - * Run C tests with the target CCpp. - */ - @Test - public void runAsCCpp() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - runTestsForTargets(Message.DESC_AS_CCPP, CCppTest::isExcludedFromCCpp, - it -> ASTUtils.changeTargetName(it.getFileConfig().resource, - Target.CCPP.getDisplayName()), - TestLevel.EXECUTION, - true); - } + /** Run C tests with the target CCpp. */ + @Test + public void runAsCCpp() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + runTestsForTargets( + Message.DESC_AS_CCPP, + CCppTest::isExcludedFromCCpp, + it -> ASTUtils.changeTargetName(it.getFileConfig().resource, Target.CCPP.getDisplayName()), + TestLevel.EXECUTION, + true); + } - /** - * Exclusion function for runAsCCpp test - */ - private static boolean isExcludedFromCCpp(TestCategory category) { - boolean excluded = category == TestCategory.SERIALIZATION; - excluded |= isWindows() && (category == TestCategory.DOCKER_FEDERATED); - excluded |= isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER); - excluded |= category == TestCategory.ZEPHYR; - excluded |= category == TestCategory.ARDUINO; - excluded |= category == TestCategory.NO_INLINING; - return !excluded; - } + /** Exclusion function for runAsCCpp test */ + private static boolean isExcludedFromCCpp(TestCategory category) { + boolean excluded = category == TestCategory.SERIALIZATION; + excluded |= isWindows() && (category == TestCategory.DOCKER_FEDERATED); + excluded |= + isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER); + excluded |= category == TestCategory.ZEPHYR; + excluded |= category == TestCategory.ARDUINO; + excluded |= category == TestCategory.NO_INLINING; + return !excluded; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java index fa387d8a00..fd2345723f 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java @@ -1,74 +1,65 @@ package org.lflang.tests.runtime; import java.util.EnumSet; - import org.junit.jupiter.api.Test; - import org.lflang.Target; import org.lflang.TargetProperty.SchedulerOption; import org.lflang.tests.Configurators; import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; -/** - */ +/** */ public class CSchedulerTest extends TestBase { + public CSchedulerTest() { + super(Target.C); + } - public CSchedulerTest() { - super(Target.C); - } - - /** - * Swap the default runtime scheduler with other supported versions and - * run all the supported tests. Only run tests for a specific non-default - * scheduler if specified using a system property (e.g., -Dscheduler=GEDF_NP). - */ - @Test - public void runWithNonDefaultSchedulers() { - EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, - TestCategory.MULTIPORT); - - // Add federated and docker tests if supported - if (!isWindows()) { - categories.add(TestCategory.FEDERATED); - if (isLinux()) { - categories.add(TestCategory.DOCKER_FEDERATED); - } - } - var name = System.getProperty("scheduler"); + /** + * Swap the default runtime scheduler with other supported versions and run all the supported + * tests. Only run tests for a specific non-default scheduler if specified using a system property + * (e.g., -Dscheduler=GEDF_NP). + */ + @Test + public void runWithNonDefaultSchedulers() { + EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, TestCategory.MULTIPORT); - if (name != null) { - var option = EnumSet.allOf(SchedulerOption.class).stream() - .filter(it -> it.name().equals(name)).findFirst(); - if (option.isPresent()) { - this.runTest(option.get(), categories); - } else { - throw new RuntimeException("Cannot find runtime scheduler called " + name); - } - } else { - for (SchedulerOption scheduler: EnumSet.allOf(SchedulerOption.class)) { - if (scheduler == SchedulerOption.getDefault()) continue; - this.runTest(scheduler, categories); - } - } + // Add federated and docker tests if supported + if (!isWindows()) { + categories.add(TestCategory.FEDERATED); + if (isLinux()) { + categories.add(TestCategory.DOCKER_FEDERATED); + } } + var name = System.getProperty("scheduler"); - private void runTest(SchedulerOption scheduler, EnumSet categories) { - this.runTestsForTargets( - Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", - categories::contains, - test -> { - test.getContext().getArgs() - .setProperty( - "scheduler", - scheduler.toString() - ); - return Configurators.noChanges(test); - }, - TestLevel.EXECUTION, - true - ); + if (name != null) { + var option = + EnumSet.allOf(SchedulerOption.class).stream() + .filter(it -> it.name().equals(name)) + .findFirst(); + if (option.isPresent()) { + this.runTest(option.get(), categories); + } else { + throw new RuntimeException("Cannot find runtime scheduler called " + name); + } + } else { + for (SchedulerOption scheduler : EnumSet.allOf(SchedulerOption.class)) { + if (scheduler == SchedulerOption.getDefault()) continue; + this.runTest(scheduler, categories); + } } -} + } + private void runTest(SchedulerOption scheduler, EnumSet categories) { + this.runTestsForTargets( + Message.DESC_SCHED_SWAPPING + scheduler.toString() + ".", + categories::contains, + test -> { + test.getContext().getArgs().setProperty("scheduler", scheduler.toString()); + return Configurators.noChanges(test); + }, + TestLevel.EXECUTION, + true); + } +} diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index eba4f7bc71..4902550661 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -1,133 +1,131 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - import org.lflang.Target; import org.lflang.tests.RuntimeTest; /** * Collection of tests for the C target. * - * Tests that are implemented in the base class are still overridden so that - * each test can be easily invoked individually from IDEs with JUnit support - * like Eclipse and IntelliJ. - * This is typically done by right-clicking on the name of the test method and - * then clicking "Run".* + *

    Tests that are implemented in the base class are still overridden so that each test can be + * easily invoked individually from IDEs with JUnit support like Eclipse and IntelliJ. This is + * typically done by right-clicking on the name of the test method and then clicking "Run".* + * * @author Marten Lohstroh */ public class CTest extends RuntimeTest { - public CTest() { - super(Target.C); - } - - @Override - protected boolean supportsSingleThreadedExecution() { - return true; - } - - @Override - protected boolean supportsFederatedExecution() { - return true; - } - - @Override - protected boolean supportsDockerOption() { - return true; - } - - @Test - @Override - public void runGenericTests() { - super.runGenericTests(); - } - - @Test - @Override - public void runTargetSpecificTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runTargetSpecificTests(); - } - - @Test - @Override - public void runMultiportTests() { - super.runMultiportTests(); - } - - @Test - @Override - public void runWithThreadingOff() { - super.runWithThreadingOff(); - } - - @Test - @Disabled("TODO only 27/96 tests pass") - @Override - public void runAsFederated() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runAsFederated(); - } - - @Test - @Override - public void runConcurrentTests() { - super.runConcurrentTests(); - } - - @Test - @Override - public void runFederatedTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runFederatedTests(); - } - - @Test - public void runModalTests() { - super.runModalTests(); - } - - @Test - public void runNoInliningTests() { - super.runNoInliningTests(); - } - - @Test - @Override - public void runDockerTests() { - super.runDockerTests(); - } - - @Test - @Override - public void runDockerFederatedTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runDockerFederatedTests(); - } + public CTest() { + super(Target.C); + } + + @Override + protected boolean supportsSingleThreadedExecution() { + return true; + } + + @Override + protected boolean supportsFederatedExecution() { + return true; + } + + @Override + protected boolean supportsDockerOption() { + return true; + } + + @Test + @Override + public void runGenericTests() { + super.runGenericTests(); + } + + @Test + @Override + public void runTargetSpecificTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runTargetSpecificTests(); + } + + @Test + @Override + public void runMultiportTests() { + super.runMultiportTests(); + } + + @Test + @Override + public void runWithThreadingOff() { + super.runWithThreadingOff(); + } + + @Test + @Disabled("TODO only 27/96 tests pass") + @Override + public void runAsFederated() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runAsFederated(); + } + + @Test + @Override + public void runConcurrentTests() { + super.runConcurrentTests(); + } + + @Test + @Override + public void runFederatedTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runFederatedTests(); + } + + @Test + public void runModalTests() { + super.runModalTests(); + } + + @Test + public void runNoInliningTests() { + super.runNoInliningTests(); + } + + @Test + @Override + public void runDockerTests() { + super.runDockerTests(); + } + + @Test + @Override + public void runDockerFederatedTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runDockerFederatedTests(); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index afe1646829..c151c1bb76 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -1,35 +1,32 @@ /************* -Copyright (c) 2023, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2023, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.runtime; import java.util.List; - import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - import org.lflang.Target; import org.lflang.tests.Configurators; import org.lflang.tests.RuntimeTest; @@ -42,29 +39,31 @@ */ public class CZephyrTest extends RuntimeTest { - public CZephyrTest() { - super(Target.C); - } + public CZephyrTest() { + super(Target.C); + } - @Test - public void buildZephyrTests() { - Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - super.runTestsFor(List.of(Target.C), - Message.DESC_ZEPHYR, - TestCategory.ZEPHYR::equals, - Configurators::makeZephyrCompatible, - TestLevel.BUILD, - false); - } - @Test - public void buildGenericTests() { - Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - super.runTestsFor(List.of(Target.C), - Message.DESC_GENERIC, - TestCategory.GENERIC::equals, - Configurators::makeZephyrCompatible, - TestLevel.BUILD, - false); - } -} + @Test + public void buildZephyrTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor( + List.of(Target.C), + Message.DESC_ZEPHYR, + TestCategory.ZEPHYR::equals, + Configurators::makeZephyrCompatible, + TestLevel.BUILD, + false); + } + @Test + public void buildGenericTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor( + List.of(Target.C), + Message.DESC_GENERIC, + TestCategory.GENERIC::equals, + Configurators::makeZephyrCompatible, + TestLevel.BUILD, + false); + } +} diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java b/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java index 2e4f6b78d3..dc2612c14b 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java @@ -2,9 +2,8 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; - -import org.lflang.ast.ASTUtils; import org.lflang.Target; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Element; import org.lflang.lf.LfFactory; import org.lflang.tests.TestBase; @@ -12,25 +11,27 @@ /** * Run C++ tests using the ROS2 platform. * - * NOTE: This test does not inherit any tests because it directly extends TestBase. + *

    NOTE: This test does not inherit any tests because it directly extends TestBase. * * @author Christian Menard */ public class CppRos2Test extends TestBase { - public CppRos2Test() { super(Target.CPP); } + public CppRos2Test() { + super(Target.CPP); + } - /** - * Run C++ tests with the ros2 target property set - */ - @Test - public void runWithRos2() { - Assumptions.assumeTrue(isLinux(), "Only supported on Linux"); - Element trueLiteral = LfFactory.eINSTANCE.createElement(); - trueLiteral.setLiteral("true"); - runTestsForTargets(Message.DESC_ROS2, it -> true, - it -> ASTUtils.addTargetProperty(it.getFileConfig().resource, "ros2", trueLiteral), - TestLevel.EXECUTION, - true); - } + /** Run C++ tests with the ros2 target property set */ + @Test + public void runWithRos2() { + Assumptions.assumeTrue(isLinux(), "Only supported on Linux"); + Element trueLiteral = LfFactory.eINSTANCE.createElement(); + trueLiteral.setLiteral("true"); + runTestsForTargets( + Message.DESC_ROS2, + it -> true, + it -> ASTUtils.addTargetProperty(it.getFileConfig().resource, "ros2", trueLiteral), + TestLevel.EXECUTION, + true); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java index 77bf4e664a..20973189b9 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java @@ -1,86 +1,84 @@ /* Integration tests for the C++ target. */ /************* -Copyright (c) 2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.runtime; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; /** - * Collection of tests for the Cpp target. - * Even though all tests are implemented in the base class, we override them - * here so that each test can be easily invoked individually from IDEs with - * JUnit support like Eclipse and IntelliJ. - * This is typically done by right-clicking on the name of the test method and - * then clicking "Run". + * Collection of tests for the Cpp target. Even though all tests are implemented in the base class, + * we override them here so that each test can be easily invoked individually from IDEs with JUnit + * support like Eclipse and IntelliJ. This is typically done by right-clicking on the name of the + * test method and then clicking "Run". * * @author Marten Lohstroh */ public class CppTest extends RuntimeTest { - public CppTest() { - super(Target.CPP); - } - - @Override - protected boolean supportsEnclaves() { return true; } - - @Test - @Override - public void runGenericTests() { - super.runGenericTests(); - } - - @Test - @Override - public void runTargetSpecificTests() { - super.runTargetSpecificTests(); - } - - @Test - @Override - public void runMultiportTests() { - super.runMultiportTests(); - } - - @Test - @Override - public void runConcurrentTests() { - super.runConcurrentTests(); - } - - @Test - @Override - public void runFederatedTests() { - super.runFederatedTests(); - } - - @Test - public void runRos2Tests() { } - + public CppTest() { + super(Target.CPP); + } + + @Override + protected boolean supportsEnclaves() { + return true; + } + + @Test + @Override + public void runGenericTests() { + super.runGenericTests(); + } + + @Test + @Override + public void runTargetSpecificTests() { + super.runTargetSpecificTests(); + } + + @Test + @Override + public void runMultiportTests() { + super.runMultiportTests(); + } + + @Test + @Override + public void runConcurrentTests() { + super.runConcurrentTests(); + } + + @Test + @Override + public void runFederatedTests() { + super.runFederatedTests(); + } + + @Test + public void runRos2Tests() {} } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java index e028e6ac4d..1c258b7481 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java @@ -1,31 +1,30 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.runtime; import java.util.Properties; - import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -35,94 +34,92 @@ /** * Collection of tests for the Python target. * - * Even though all tests are implemented in the base class, we override them - * here so that each test can be easily invoked individually from IDEs with - * JUnit support like Eclipse and IntelliJ. - * This is typically done by right-clicking on the name of the test method and - * then clicking "Run". + *

    Even though all tests are implemented in the base class, we override them here so that each + * test can be easily invoked individually from IDEs with JUnit support like Eclipse and IntelliJ. + * This is typically done by right-clicking on the name of the test method and then clicking "Run". * * @author Marten Lohstroh */ public class PythonTest extends RuntimeTest { - public PythonTest() { - super(Target.Python); - } - - @Override - protected void addExtraLfcArgs(Properties args) { - super.addExtraLfcArgs(args); - if (System.getProperty("os.name").startsWith("Windows")) { - // Use the RelWithDebInfo build type on Windows as the Debug/Test build type produces linker Errors in CI - args.setProperty("build-type", "RelWithDebInfo"); - } - } - - @Override - protected boolean supportsFederatedExecution() { - return true; - } - - @Override - protected boolean supportsSingleThreadedExecution() { - return true; - } - - @Override - protected boolean supportsDockerOption() { - return false; // FIXME: https://issues.lf-lang.org/1564 - } - - @Test - @Override - public void runGenericTests() { - super.runGenericTests(); - } - - @Test - @Override - public void runTargetSpecificTests() { - super.runTargetSpecificTests(); - } - - @Test - @Override - public void runMultiportTests() { - super.runMultiportTests(); - } - - @Test - @Disabled("TODO") - @Override - public void runAsFederated() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runAsFederated(); - } - - - @Test - @Override - public void runConcurrentTests() { - super.runConcurrentTests(); - } - - @Test - @Override - public void runFederatedTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runFederatedTests(); - } - - @Test - @Override - public void runDockerTests() { - super.runDockerTests(); - } - - @Test - @Override - public void runDockerFederatedTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runDockerFederatedTests(); + public PythonTest() { + super(Target.Python); + } + + @Override + protected void addExtraLfcArgs(Properties args) { + super.addExtraLfcArgs(args); + if (System.getProperty("os.name").startsWith("Windows")) { + // Use the RelWithDebInfo build type on Windows as the Debug/Test build type produces linker + // Errors in CI + args.setProperty("build-type", "RelWithDebInfo"); } + } + + @Override + protected boolean supportsFederatedExecution() { + return true; + } + + @Override + protected boolean supportsSingleThreadedExecution() { + return true; + } + + @Override + protected boolean supportsDockerOption() { + return false; // FIXME: https://issues.lf-lang.org/1564 + } + + @Test + @Override + public void runGenericTests() { + super.runGenericTests(); + } + + @Test + @Override + public void runTargetSpecificTests() { + super.runTargetSpecificTests(); + } + + @Test + @Override + public void runMultiportTests() { + super.runMultiportTests(); + } + + @Test + @Disabled("TODO") + @Override + public void runAsFederated() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runAsFederated(); + } + + @Test + @Override + public void runConcurrentTests() { + super.runConcurrentTests(); + } + + @Test + @Override + public void runFederatedTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runFederatedTests(); + } + + @Test + @Override + public void runDockerTests() { + super.runDockerTests(); + } + + @Test + @Override + public void runDockerFederatedTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runDockerFederatedTests(); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/RustTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/RustTest.java index 2601fe79d0..e41d358ac0 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/RustTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/RustTest.java @@ -24,22 +24,18 @@ package org.lflang.tests.runtime; -import java.util.Properties; - import org.lflang.Target; import org.lflang.tests.RuntimeTest; -/** - * - */ +/** */ public class RustTest extends RuntimeTest { - public RustTest() { - super(Target.Rust); - } + public RustTest() { + super(Target.Rust); + } - @Override - protected boolean supportsGenericTypes() { - return true; - } + @Override + protected boolean supportsGenericTypes() { + return true; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java index 295a1961ed..036211607a 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java @@ -8,74 +8,72 @@ /** * Collection of tests for the TypeScript target. * - * Even though all tests are implemented in the base class, we override them - * here so that each test can be easily invoked individually from IDEs with - * JUnit support like Eclipse and IntelliJ. - * This is typically done by right-clicking on the name of the test method and - * then clicking "Run". + *

    Even though all tests are implemented in the base class, we override them here so that each + * test can be easily invoked individually from IDEs with JUnit support like Eclipse and IntelliJ. + * This is typically done by right-clicking on the name of the test method and then clicking "Run". * * @author Marten Lohstroh */ public class TypeScriptTest extends RuntimeTest { - public TypeScriptTest() { - super(Target.TS); - } + public TypeScriptTest() { + super(Target.TS); + } - @Override - protected boolean supportsDockerOption() { - return true; - } + @Override + protected boolean supportsDockerOption() { + return true; + } - @Override - protected boolean supportsFederatedExecution() { - return true; - } + @Override + protected boolean supportsFederatedExecution() { + return true; + } - @Test - @Override - public void runGenericTests() { - super.runGenericTests(); - } + @Test + @Override + public void runGenericTests() { + super.runGenericTests(); + } - @Test - @Override - public void runTargetSpecificTests() { - super.runTargetSpecificTests(); - } + @Test + @Override + public void runTargetSpecificTests() { + super.runTargetSpecificTests(); + } - @Test - @Override - public void runMultiportTests() { - super.runMultiportTests(); - } + @Test + @Override + public void runMultiportTests() { + super.runMultiportTests(); + } - @Test - @Override - public void runConcurrentTests() { - super.runConcurrentTests(); - } + @Test + @Override + public void runConcurrentTests() { + super.runConcurrentTests(); + } - @Test - @Override - public void runFederatedTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runFederatedTests(); - } + @Test + @Override + public void runFederatedTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runFederatedTests(); + } - @Test - @Override - public void runDockerTests() { - super.runDockerTests(); - } + @Test + @Override + public void runDockerTests() { + super.runDockerTests(); + } - @Test - @Override - public void runDockerFederatedTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - super.runDockerFederatedTests(); - } + @Test + @Override + public void runDockerFederatedTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + super.runDockerFederatedTests(); + } - @Test - @Override - public void runAsFederated() {} + @Test + @Override + public void runAsFederated() {} } diff --git a/org.lflang.tests/src/org/lflang/tests/serialization/SerializationTest.java b/org.lflang.tests/src/org/lflang/tests/serialization/SerializationTest.java index 35dfa9f6de..26f3ec37af 100644 --- a/org.lflang.tests/src/org/lflang/tests/serialization/SerializationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/serialization/SerializationTest.java @@ -1,7 +1,6 @@ package org.lflang.tests.serialization; import java.util.Properties; - import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import org.lflang.Target; @@ -11,32 +10,36 @@ public class SerializationTest extends TestBase { - protected SerializationTest() { - super(Target.ALL); - } + protected SerializationTest() { + super(Target.ALL); + } + + @Override + protected void addExtraLfcArgs(Properties args) { + super.addExtraLfcArgs(args); + // Use the Debug build type as coverage generation does not work for the serialization tests + args.setProperty("build-type", "Debug"); + } + + @Test + public void runSerializationTestsWithThreadingOff() { + Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); + runTestsForTargets( + Message.DESC_SERIALIZATION, + TestCategory.SERIALIZATION::equals, + Configurators::disableThreading, + TestLevel.EXECUTION, + false); + } - @Override - protected void addExtraLfcArgs(Properties args) { - super.addExtraLfcArgs(args); - // Use the Debug build type as coverage generation does not work for the serialization tests - args.setProperty("build-type", "Debug"); - } - - @Test - public void runSerializationTestsWithThreadingOff() { - Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); - runTestsForTargets(Message.DESC_SERIALIZATION, - TestCategory.SERIALIZATION::equals, Configurators::disableThreading, - TestLevel.EXECUTION, - false); - } - - @Test - public void runSerializationTests() { - Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); - runTestsForTargets(Message.DESC_SERIALIZATION, - TestCategory.SERIALIZATION::equals, Configurators::noChanges, - TestLevel.EXECUTION, - false); - } + @Test + public void runSerializationTests() { + Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); + runTestsForTargets( + Message.DESC_SERIALIZATION, + TestCategory.SERIALIZATION::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } } diff --git a/org.lflang.tests/src/org/lflang/tests/util/StringUtilTest.java b/org.lflang.tests/src/org/lflang/tests/util/StringUtilTest.java index fb15cda64c..7c8ca60b83 100644 --- a/org.lflang.tests/src/org/lflang/tests/util/StringUtilTest.java +++ b/org.lflang.tests/src/org/lflang/tests/util/StringUtilTest.java @@ -33,24 +33,24 @@ public class StringUtilTest { - @Test - public void testRemoveQuotes() { - assertEquals("abc", removeQuotes("\"abc\"")); - assertEquals("a", removeQuotes("'a'")); - assertEquals("'a", removeQuotes("'a")); - assertEquals("a\"", removeQuotes("a\"")); - assertEquals("\"", removeQuotes("\"")); - assertEquals("'", removeQuotes("'")); - assertEquals("", removeQuotes("")); - assertNull(removeQuotes(null)); - } + @Test + public void testRemoveQuotes() { + assertEquals("abc", removeQuotes("\"abc\"")); + assertEquals("a", removeQuotes("'a'")); + assertEquals("'a", removeQuotes("'a")); + assertEquals("a\"", removeQuotes("a\"")); + assertEquals("\"", removeQuotes("\"")); + assertEquals("'", removeQuotes("'")); + assertEquals("", removeQuotes("")); + assertNull(removeQuotes(null)); + } - @Test - public void testCamelToSnakeCase() { - assertEquals("some_string", camelToSnakeCase("someString")); - assertEquals("abc_str", camelToSnakeCase("AbcStr")); - assertEquals("ast", camelToSnakeCase("AST")); - assertEquals("ast_builder", camelToSnakeCase("ASTBuilder")); - assertEquals("something_with_a_preamble", camelToSnakeCase("SomethingWithAPreamble")); - } + @Test + public void testCamelToSnakeCase() { + assertEquals("some_string", camelToSnakeCase("someString")); + assertEquals("abc_str", camelToSnakeCase("AbcStr")); + assertEquals("ast", camelToSnakeCase("AST")); + assertEquals("ast_builder", camelToSnakeCase("ASTBuilder")); + assertEquals("something_with_a_preamble", camelToSnakeCase("SomethingWithAPreamble")); + } } diff --git a/org.lflang/src/org/lflang/AttributeUtils.java b/org.lflang/src/org/lflang/AttributeUtils.java index b6fddf0b0e..6703df2d0e 100644 --- a/org.lflang/src/org/lflang/AttributeUtils.java +++ b/org.lflang/src/org/lflang/AttributeUtils.java @@ -27,12 +27,10 @@ import java.util.List; import java.util.Objects; - import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.nodemodel.ICompositeNode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; - import org.lflang.ast.ASTUtils; import org.lflang.lf.Action; import org.lflang.lf.AttrParm; @@ -56,197 +54,194 @@ */ public class AttributeUtils { - /** - * Return the attributes declared on the given node. Throws - * if the node does not support declaring attributes. - * - * @throws IllegalArgumentException If the node cannot have attributes - */ - public static List getAttributes(EObject node) { - if (node instanceof Reactor) { - return ((Reactor) node).getAttributes(); - } else if (node instanceof Reaction) { - return ((Reaction) node).getAttributes(); - } else if (node instanceof Action) { - return ((Action) node).getAttributes(); - } else if (node instanceof Timer) { - return ((Timer) node).getAttributes(); - } else if (node instanceof StateVar) { - return ((StateVar) node).getAttributes(); - } else if (node instanceof Parameter) { - return ((Parameter) node).getAttributes(); - } else if (node instanceof Input) { - return ((Input) node).getAttributes(); - } else if (node instanceof Output) { - return ((Output) node).getAttributes(); - } else if (node instanceof Instantiation) { - return ((Instantiation) node).getAttributes(); - } - throw new IllegalArgumentException("Not annotatable: " + node); - } - - /** - * Return the attribute with the given name - * if present, otherwise return null. - * - * @throws IllegalArgumentException If the node cannot have attributes - */ - public static Attribute findAttributeByName(EObject node, String name) { - List attrs = getAttributes(node); - return attrs.stream() - .filter(it -> it.getAttrName().equalsIgnoreCase(name)) // case-insensitive search (more user-friendly) - .findFirst() - .orElse(null); + /** + * Return the attributes declared on the given node. Throws if the node does not support declaring + * attributes. + * + * @throws IllegalArgumentException If the node cannot have attributes + */ + public static List getAttributes(EObject node) { + if (node instanceof Reactor) { + return ((Reactor) node).getAttributes(); + } else if (node instanceof Reaction) { + return ((Reaction) node).getAttributes(); + } else if (node instanceof Action) { + return ((Action) node).getAttributes(); + } else if (node instanceof Timer) { + return ((Timer) node).getAttributes(); + } else if (node instanceof StateVar) { + return ((StateVar) node).getAttributes(); + } else if (node instanceof Parameter) { + return ((Parameter) node).getAttributes(); + } else if (node instanceof Input) { + return ((Input) node).getAttributes(); + } else if (node instanceof Output) { + return ((Output) node).getAttributes(); + } else if (node instanceof Instantiation) { + return ((Instantiation) node).getAttributes(); } - - /** - * Return the first argument specified for the attribute. - * - * This should be used if the attribute is expected to have a single argument. - * If there is no argument, null is returned. - */ - public static String getFirstArgumentValue(Attribute attr) { - if (attr == null || attr.getAttrParms().isEmpty()) { - return null; - } - return StringUtil.removeQuotes(attr.getAttrParms().get(0).getValue()); - } - - /** - * Search for an attribute with the given name on the given AST node and return its first - * argument as a String. - * - * This should only be used on attributes that are expected to have a single argument. - * - * Returns null if the attribute is not found or if it does not have any arguments. - */ - public static String getAttributeValue(EObject node, String attrName) { - final var attr = findAttributeByName(node, attrName); - String value = getFirstArgumentValue(attr); - // Attribute annotations in comments are deprecated, but we still check for then for backwards - // compatibility - if (value == null) { - return findAnnotationInComments(node, "@" + attrName); - } - return value; + throw new IllegalArgumentException("Not annotatable: " + node); + } + + /** + * Return the attribute with the given name if present, otherwise return null. + * + * @throws IllegalArgumentException If the node cannot have attributes + */ + public static Attribute findAttributeByName(EObject node, String name) { + List attrs = getAttributes(node); + return attrs.stream() + .filter( + it -> + it.getAttrName() + .equalsIgnoreCase(name)) // case-insensitive search (more user-friendly) + .findFirst() + .orElse(null); + } + + /** + * Return the first argument specified for the attribute. + * + *

    This should be used if the attribute is expected to have a single argument. If there is no + * argument, null is returned. + */ + public static String getFirstArgumentValue(Attribute attr) { + if (attr == null || attr.getAttrParms().isEmpty()) { + return null; } - - /** - * Retrieve a specific annotation in a comment associated with the given model element in the AST. - * - * This will look for a comment. If one is found, it searches for the given annotation {@code key}. - * and extracts any string that follows the annotation marker. - * - * @param object the AST model element to search a comment for - * @param key the specific annotation key to be extracted - * @return {@code null} if no JavaDoc style comment was found or if it does not contain the given key. - * The string immediately following the annotation marker otherwise. - */ - public static String findAnnotationInComments(EObject object, String key) { - if (!(object.eResource() instanceof XtextResource)) return null; - ICompositeNode node = NodeModelUtils.findActualNodeFor(object); - return ASTUtils.getPrecedingComments(node, n -> true).flatMap(String::lines) - .filter(line -> line.contains(key)) - .map(String::trim) - .map(it -> it.substring(it.indexOf(key) + key.length())) - .map(it -> it.endsWith("*/") ? it.substring(0, it.length() - "*/".length()) : it) - .findFirst().orElse(null); + return StringUtil.removeQuotes(attr.getAttrParms().get(0).getValue()); + } + + /** + * Search for an attribute with the given name on the given AST node and return its first argument + * as a String. + * + *

    This should only be used on attributes that are expected to have a single argument. + * + *

    Returns null if the attribute is not found or if it does not have any arguments. + */ + public static String getAttributeValue(EObject node, String attrName) { + final var attr = findAttributeByName(node, attrName); + String value = getFirstArgumentValue(attr); + // Attribute annotations in comments are deprecated, but we still check for then for backwards + // compatibility + if (value == null) { + return findAnnotationInComments(node, "@" + attrName); } - - /** - * Return the parameter of the given attribute with the given name. - * - * Returns null if no such parameter is found. - */ - public static String getAttributeParameter(Attribute attribute, String parameterName) { - return (attribute == null) ? null : attribute.getAttrParms().stream() + return value; + } + + /** + * Retrieve a specific annotation in a comment associated with the given model element in the AST. + * + *

    This will look for a comment. If one is found, it searches for the given annotation {@code + * key}. and extracts any string that follows the annotation marker. + * + * @param object the AST model element to search a comment for + * @param key the specific annotation key to be extracted + * @return {@code null} if no JavaDoc style comment was found or if it does not contain the given + * key. The string immediately following the annotation marker otherwise. + */ + public static String findAnnotationInComments(EObject object, String key) { + if (!(object.eResource() instanceof XtextResource)) return null; + ICompositeNode node = NodeModelUtils.findActualNodeFor(object); + return ASTUtils.getPrecedingComments(node, n -> true) + .flatMap(String::lines) + .filter(line -> line.contains(key)) + .map(String::trim) + .map(it -> it.substring(it.indexOf(key) + key.length())) + .map(it -> it.endsWith("*/") ? it.substring(0, it.length() - "*/".length()) : it) + .findFirst() + .orElse(null); + } + + /** + * Return the parameter of the given attribute with the given name. + * + *

    Returns null if no such parameter is found. + */ + public static String getAttributeParameter(Attribute attribute, String parameterName) { + return (attribute == null) + ? null + : attribute.getAttrParms().stream() .filter(param -> Objects.equals(param.getName(), parameterName)) .map(AttrParm::getValue) .map(StringUtil::removeQuotes) .findFirst() .orElse(null); + } + + /** + * Return the parameter of the given attribute with the given name and interpret it as a boolean. + * + *

    Returns null if no such parameter is found. + */ + public static Boolean getBooleanAttributeParameter(Attribute attribute, String parameterName) { + if (attribute == null || parameterName == null) { + return null; } - - /** - * Return the parameter of the given attribute with the given name and interpret it as a boolean. - * - * Returns null if no such parameter is found. - */ - public static Boolean getBooleanAttributeParameter(Attribute attribute, String parameterName) { - if (attribute == null || parameterName == null) { - return null; - } - final var param = getAttributeParameter(attribute, parameterName); - if (param == null) { - return null; - } - return param.equalsIgnoreCase("true"); - } - - /** - * Return true if the specified node is an Input and has an {@code @sparse} - * attribute. - * @param node An AST node. - */ - public static boolean isSparse(EObject node) { - return findAttributeByName(node, "sparse") != null; - } - - /** - * Return true if the reaction is unordered. - * - * Currently, this is only used for synthesized reactions in the context of - * federated execution. - */ - public static boolean isUnordered(Reaction reaction) { - return findAttributeByName(reaction, "_unordered") != null; + final var param = getAttributeParameter(attribute, parameterName); + if (param == null) { + return null; } - - /** - * Return true if the reactor is marked to be a federate. - */ - public static boolean isFederate(Reactor reactor) { - return findAttributeByName(reactor, "_fed_config") != null; - } - - /** - * Return true if the reaction is marked to have a C code body. - * - * Currently, this is only used for synthesized reactions in the context of - * federated execution in Python. - */ - public static boolean hasCBody(Reaction reaction) { - return findAttributeByName(reaction, "_c_body") != null; - } - - /** - * Return the declared label of the node, as given by the @label annotation. - */ - public static String getLabel(EObject node) { - return getAttributeValue(node, "label"); - } - - /** - * Return the declared icon of the node, as given by the @icon annotation. - */ - public static String getIconPath(EObject node) { - return getAttributeValue(node, "icon"); - } - - /** - * Return the {@code @enclave} attribute annotated on the given node. - * - * Returns null if there is no such attribute. - */ - public static Attribute getEnclaveAttribute(Instantiation node) { - return findAttributeByName(node, "enclave"); - } - - /** - * Return true if the specified instance has an {@code @enclave} attribute. - */ - public static boolean isEnclave(Instantiation node) { - return getEnclaveAttribute(node) != null; - } - + return param.equalsIgnoreCase("true"); + } + + /** + * Return true if the specified node is an Input and has an {@code @sparse} attribute. + * + * @param node An AST node. + */ + public static boolean isSparse(EObject node) { + return findAttributeByName(node, "sparse") != null; + } + + /** + * Return true if the reaction is unordered. + * + *

    Currently, this is only used for synthesized reactions in the context of federated + * execution. + */ + public static boolean isUnordered(Reaction reaction) { + return findAttributeByName(reaction, "_unordered") != null; + } + + /** Return true if the reactor is marked to be a federate. */ + public static boolean isFederate(Reactor reactor) { + return findAttributeByName(reactor, "_fed_config") != null; + } + + /** + * Return true if the reaction is marked to have a C code body. + * + *

    Currently, this is only used for synthesized reactions in the context of federated execution + * in Python. + */ + public static boolean hasCBody(Reaction reaction) { + return findAttributeByName(reaction, "_c_body") != null; + } + + /** Return the declared label of the node, as given by the @label annotation. */ + public static String getLabel(EObject node) { + return getAttributeValue(node, "label"); + } + + /** Return the declared icon of the node, as given by the @icon annotation. */ + public static String getIconPath(EObject node) { + return getAttributeValue(node, "icon"); + } + + /** + * Return the {@code @enclave} attribute annotated on the given node. + * + *

    Returns null if there is no such attribute. + */ + public static Attribute getEnclaveAttribute(Instantiation node) { + return findAttributeByName(node, "enclave"); + } + + /** Return true if the specified instance has an {@code @enclave} attribute. */ + public static boolean isEnclave(Instantiation node) { + return getEnclaveAttribute(node) != null; + } } diff --git a/org.lflang/src/org/lflang/DefaultErrorReporter.java b/org.lflang/src/org/lflang/DefaultErrorReporter.java index 704e19951c..2698d2b582 100644 --- a/org.lflang/src/org/lflang/DefaultErrorReporter.java +++ b/org.lflang/src/org/lflang/DefaultErrorReporter.java @@ -1,72 +1,68 @@ package org.lflang; -import org.eclipse.emf.ecore.EObject; - import java.nio.file.Path; +import org.eclipse.emf.ecore.EObject; -/** - * Simple implementation of the ErrorReport interface that simply prints to - * standard out. - */ +/** Simple implementation of the ErrorReport interface that simply prints to standard out. */ public class DefaultErrorReporter implements ErrorReporter { - private boolean errorsOccurred = false; + private boolean errorsOccurred = false; - private String println(String s) { - System.out.println(s); - return s; - } + private String println(String s) { + System.out.println(s); + return s; + } - @Override - public String reportError(String message) { - errorsOccurred = true; - return println("ERROR: " + message); - } + @Override + public String reportError(String message) { + errorsOccurred = true; + return println("ERROR: " + message); + } - @Override - public String reportError(EObject object, String message) { - errorsOccurred = true; - return println("ERROR: " + message); - } + @Override + public String reportError(EObject object, String message) { + errorsOccurred = true; + return println("ERROR: " + message); + } - @Override - public String reportError(Path file, Integer line, String message) { - errorsOccurred = true; - return println("ERROR: " + message); - } + @Override + public String reportError(Path file, Integer line, String message) { + errorsOccurred = true; + return println("ERROR: " + message); + } - @Override - public String reportWarning(String message) { - return println("WARNING: " + message); - } + @Override + public String reportWarning(String message) { + return println("WARNING: " + message); + } - @Override - public String reportInfo(String message) { - return println("INFO: " + message); - } + @Override + public String reportInfo(String message) { + return println("INFO: " + message); + } - @Override - public String reportWarning(EObject object, String message) { - return println("WARNING: " + message); - } + @Override + public String reportWarning(EObject object, String message) { + return println("WARNING: " + message); + } - @Override - public String reportInfo(EObject object, String message) { - return println("INFO: " + message); - } + @Override + public String reportInfo(EObject object, String message) { + return println("INFO: " + message); + } - @Override - public String reportWarning(Path file, Integer line, String message) { - return println("WARNING: " + message); - } + @Override + public String reportWarning(Path file, Integer line, String message) { + return println("WARNING: " + message); + } - @Override - public String reportInfo(Path file, Integer line, String message) { - return println("INFO: " + message); - } + @Override + public String reportInfo(Path file, Integer line, String message) { + return println("INFO: " + message); + } - @Override - public boolean getErrorsOccurred() { - return errorsOccurred; - } + @Override + public boolean getErrorsOccurred() { + return errorsOccurred; + } } diff --git a/org.lflang/src/org/lflang/ErrorReporter.java b/org.lflang/src/org/lflang/ErrorReporter.java index 0a01e252ee..f7fe6dcb31 100644 --- a/org.lflang/src/org/lflang/ErrorReporter.java +++ b/org.lflang/src/org/lflang/ErrorReporter.java @@ -1,10 +1,8 @@ package org.lflang; import java.nio.file.Path; - import org.eclipse.emf.ecore.EObject; import org.eclipse.lsp4j.DiagnosticSeverity; - import org.lflang.generator.Position; /** @@ -16,164 +14,157 @@ */ public interface ErrorReporter { - /** - * Report an error. - * - * @param message The error message. - * @return a string that describes the error. - */ - String reportError(String message); - - - /** - * Report a warning. - * - * @param message The warning message. - * @return a string that describes the warning. - */ - String reportWarning(String message); - - /** - * Report an informational message. - * - * @param message The message to report - * @return a string that describes the error - */ - String reportInfo(String message); - - - /** - * Report an error on the specified parse tree object. - * - * @param object The parse tree object. - * @param message The error message. - * @return a string that describes the error. - */ - String reportError(EObject object, String message); - - - /** - * Report a warning on the specified parse tree object. - * - * @param object The parse tree object. - * @param message The error message. - * @return a string that describes the warning. - */ - String reportWarning(EObject object, String message); - - /** - * Report an informational message on the specified parse tree object. - * - * @param object The parse tree object. - * @param message The informational message - * @return a string that describes the info - */ - String reportInfo(EObject object, String message); - - - /** - * Report an error at the specified line within a file. - * - * @param message The error message. - * @param line The one-based line number to report at. - * @param file The file to report at. - * @return a string that describes the error. - */ - String reportError(Path file, Integer line, String message); - - - /** - * Report a warning at the specified line within a file. - * - * @param message The error message. - * @param line The one-based line number to report at. - * @param file The file to report at. - * @return a string that describes the warning. - */ - String reportWarning(Path file, Integer line, String message); - - - /** - * Report an informational message at the specified line within a file. - * - * @param file The file to report at. - * @param line The one-based line number to report at. - * @param message The error message. - * @return - */ - String reportInfo(Path file, Integer line, String message); - - /** - * Report a message of severity {@code severity}. - * @param file The file to which the message pertains, or {@code null} if the file is unknown. - * @param severity the severity of the message - * @param message the message to send to the IDE - * @return a string that describes the diagnostic - */ - default String report(Path file, DiagnosticSeverity severity, String message) { - switch (severity) { - case Error: - return reportError(message); - case Warning: - case Hint: - case Information: - return reportInfo(message); - default: - return reportWarning(message); - } - } - - /** - * Report a message of severity {@code severity} that - * pertains to line {@code line} of an LF source file. - * @param file The file to which the message pertains, or {@code null} if the file is unknown. - * @param severity the severity of the message - * @param message the message to send to the IDE - * @param line the one-based line number associated - * with the message - * @return a string that describes the diagnostic - */ - default String report(Path file, DiagnosticSeverity severity, String message, int line) { - switch (severity) { - case Error: - return reportError(file, line, message); - case Warning: - case Hint: - case Information: - return reportInfo(file, line, message); - default: - return reportWarning(file, line, message); - } + /** + * Report an error. + * + * @param message The error message. + * @return a string that describes the error. + */ + String reportError(String message); + + /** + * Report a warning. + * + * @param message The warning message. + * @return a string that describes the warning. + */ + String reportWarning(String message); + + /** + * Report an informational message. + * + * @param message The message to report + * @return a string that describes the error + */ + String reportInfo(String message); + + /** + * Report an error on the specified parse tree object. + * + * @param object The parse tree object. + * @param message The error message. + * @return a string that describes the error. + */ + String reportError(EObject object, String message); + + /** + * Report a warning on the specified parse tree object. + * + * @param object The parse tree object. + * @param message The error message. + * @return a string that describes the warning. + */ + String reportWarning(EObject object, String message); + + /** + * Report an informational message on the specified parse tree object. + * + * @param object The parse tree object. + * @param message The informational message + * @return a string that describes the info + */ + String reportInfo(EObject object, String message); + + /** + * Report an error at the specified line within a file. + * + * @param message The error message. + * @param line The one-based line number to report at. + * @param file The file to report at. + * @return a string that describes the error. + */ + String reportError(Path file, Integer line, String message); + + /** + * Report a warning at the specified line within a file. + * + * @param message The error message. + * @param line The one-based line number to report at. + * @param file The file to report at. + * @return a string that describes the warning. + */ + String reportWarning(Path file, Integer line, String message); + + /** + * Report an informational message at the specified line within a file. + * + * @param file The file to report at. + * @param line The one-based line number to report at. + * @param message The error message. + * @return + */ + String reportInfo(Path file, Integer line, String message); + + /** + * Report a message of severity {@code severity}. + * + * @param file The file to which the message pertains, or {@code null} if the file is unknown. + * @param severity the severity of the message + * @param message the message to send to the IDE + * @return a string that describes the diagnostic + */ + default String report(Path file, DiagnosticSeverity severity, String message) { + switch (severity) { + case Error: + return reportError(message); + case Warning: + case Hint: + case Information: + return reportInfo(message); + default: + return reportWarning(message); } - - /** - * Report a message of severity {@code severity} that - * pertains to the range [{@code startPos}, {@code endPos}) - * of an LF source file. - * @param file The file to which the message pertains, or {@code null} if the file is unknown. - * @param severity the severity of the message - * @param message the message to send to the IDE - * @param startPos the position of the first character - * of the range of interest - * @param endPos the position immediately AFTER the - * final character of the range of - * interest - * @return a string that describes the diagnostic - */ - default String report(Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { - return report(file, severity, message, startPos.getOneBasedLine()); + } + + /** + * Report a message of severity {@code severity} that pertains to line {@code line} of an LF + * source file. + * + * @param file The file to which the message pertains, or {@code null} if the file is unknown. + * @param severity the severity of the message + * @param message the message to send to the IDE + * @param line the one-based line number associated with the message + * @return a string that describes the diagnostic + */ + default String report(Path file, DiagnosticSeverity severity, String message, int line) { + switch (severity) { + case Error: + return reportError(file, line, message); + case Warning: + case Hint: + case Information: + return reportInfo(file, line, message); + default: + return reportWarning(file, line, message); } - - /** - * Check if errors where reported. - * - * @return true if errors where reported - */ - boolean getErrorsOccurred(); - - /** - * Clear error history, if exists. - * This is usually only the case for error markers in Epoch (Eclipse). - */ - default void clearHistory() {} + } + + /** + * Report a message of severity {@code severity} that pertains to the range [{@code startPos}, + * {@code endPos}) of an LF source file. + * + * @param file The file to which the message pertains, or {@code null} if the file is unknown. + * @param severity the severity of the message + * @param message the message to send to the IDE + * @param startPos the position of the first character of the range of interest + * @param endPos the position immediately AFTER the final character of the range of interest + * @return a string that describes the diagnostic + */ + default String report( + Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { + return report(file, severity, message, startPos.getOneBasedLine()); + } + + /** + * Check if errors where reported. + * + * @return true if errors where reported + */ + boolean getErrorsOccurred(); + + /** + * Clear error history, if exists. This is usually only the case for error markers in Epoch + * (Eclipse). + */ + default void clearHistory() {} } diff --git a/org.lflang/src/org/lflang/FileConfig.java b/org.lflang/src/org/lflang/FileConfig.java index e2d3313a61..831cb7957f 100644 --- a/org.lflang/src/org/lflang/FileConfig.java +++ b/org.lflang/src/org/lflang/FileConfig.java @@ -5,15 +5,12 @@ import java.nio.file.Paths; import java.util.List; import java.util.function.Consumer; - import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.IFileSystemAccess2; - - import org.lflang.generator.GeneratorUtils; import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; @@ -22,297 +19,267 @@ * Base class that governs the interactions between code generators and the file system. * * @author Marten Lohstroh - * */ public abstract class FileConfig { - // Public static fields. - - public static final String DEFAULT_SRC_DIR = "src"; - - /** - * Default name of the directory to store binaries in. - */ - public static final String DEFAULT_BIN_DIR = "bin"; - - /** - * Default name of the directory to store generated sources in. - */ - public static final String DEFAULT_SRC_GEN_DIR = "src-gen"; - - // Public fields. - - /** - * The directory in which to put binaries, if the code generator produces any. - */ - public final Path binPath; - - /** - * The name of the main reactor, which has to match the file name (without - * the '.lf' extension). - */ - public final String name; - - /** - * The directory that is the root of the package in which the .lf source file resides. This path is determined - * differently depending on whether the compiler is invoked through the IDE or from the command line. In the former - * case, the package is the project root that the source resides in. In the latter case, it is the parent directory - * of the nearest {@code src} directory up the hierarchy, if there is one, or just the {@code outPath} if there is none. It is - * recommended to always keep the sources in a {@code src} directory regardless of the workflow, in which case the - * output behavior will be identical irrespective of the way the compiler is invoked. - */ - public final Path srcPkgPath; - - /** - * The file containing the main source code. - * This is the Eclipse eCore view of the file, which is distinct - * from the XText view of the file and the OS view of the file. - */ - public final Resource resource; - - /** - * If running in an Eclipse IDE, the iResource refers to the - * IFile representing the Lingua Franca program. - * This is the XText view of the file, which is distinct - * from the Eclipse eCore view of the file and the OS view of the file. - *

    - * This is null if running outside an Eclipse IDE. - */ - public final IResource iResource; - - /** - * The full path to the file containing the .lf file including the - * full filename with the .lf extension. - */ - public final Path srcFile; - - /** - * The directory in which the source .lf file was found. - */ - public final Path srcPath; // FIXME: rename this to srcDir? - - /** - * Indicate whether the bin directory should be hierarchical. - */ - public final boolean useHierarchicalBin; - - // Protected fields. - - /** - * Path representation of srcGenRoot, the root directory for generated - * sources. - */ - protected Path srcGenBasePath; - - /** - * The directory in which to put the generated sources. - * This takes into account the location of the source file relative to the - * package root. Specifically, if the source file is x/y/Z.lf relative - * to the package root, then the generated sources will be put in x/y/Z - * relative to srcGenBasePath. - */ - protected Path srcGenPath; - - // private fields - - /** - * The parent of the directory designated for placing generated sources into ({@code ./src-gen} by default). Additional - * directories (such as {@code bin} or {@code build}) should be created as siblings of the directory for generated sources, - * which means that such directories should be created relative to the path assigned to this class variable. - *

    - * The generated source directory is specified in the IDE (Project Properties->LF->Compiler->Output Folder). When - * invoking the standalone compiler, the output path is specified directly using the {@code -o} or {@code --output-path} option. - */ - private final Path outPath; - - /** - * The directory that denotes the root of the package to which the - * generated sources belong. Even if the target language does not have a - * notion of packages, this directory groups all files associated with a - * single main reactor. - * of packages. - */ - private final Path srcGenPkgPath; - - public FileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { - this.resource = resource; - this.useHierarchicalBin = useHierarchicalBin; - - this.srcFile = FileUtil.toPath(this.resource); - - this.srcPath = srcFile.getParent(); - this.srcPkgPath = getPkgPath(resource); - - this.srcGenBasePath = srcGenBasePath; - this.name = FileUtil.nameWithoutExtension(this.srcFile); - this.srcGenPath = srcGenBasePath.resolve(getSubPkgPath(srcPath)).resolve(name); - this.srcGenPkgPath = this.srcGenPath; - this.outPath = srcGenBasePath.getParent(); - - Path binRoot = outPath.resolve(DEFAULT_BIN_DIR); - this.binPath = useHierarchicalBin ? binRoot.resolve(getSubPkgPath(srcPath)) : binRoot; - - this.iResource = FileUtil.getIResource(resource); - } - - /** - * Get the directory a resource is located in relative to the root package - */ - public Path getDirectory(Resource r) throws IOException { - return getSubPkgPath(FileUtil.toPath(r).getParent()); - } - - /** - * The parent of the directory designated for placing generated sources into ({@code ./src-gen} by default). Additional - * directories (such as {@code bin} or {@code build}) should be created as siblings of the directory for generated sources, - * which means that such directories should be created relative to the path assigned to this class variable. - *

    - * The generated source directory is specified in the IDE (Project Properties->LF->Compiler->Output Folder). When - * invoking the standalone compiler, the output path is specified directly using the {@code -o} or {@code --output-path} option. - */ - public Path getOutPath() { - return outPath; + // Public static fields. + + public static final String DEFAULT_SRC_DIR = "src"; + + /** Default name of the directory to store binaries in. */ + public static final String DEFAULT_BIN_DIR = "bin"; + + /** Default name of the directory to store generated sources in. */ + public static final String DEFAULT_SRC_GEN_DIR = "src-gen"; + + // Public fields. + + /** The directory in which to put binaries, if the code generator produces any. */ + public final Path binPath; + + /** + * The name of the main reactor, which has to match the file name (without the '.lf' extension). + */ + public final String name; + + /** + * The directory that is the root of the package in which the .lf source file resides. This path + * is determined differently depending on whether the compiler is invoked through the IDE or from + * the command line. In the former case, the package is the project root that the source resides + * in. In the latter case, it is the parent directory of the nearest {@code src} directory up the + * hierarchy, if there is one, or just the {@code outPath} if there is none. It is recommended to + * always keep the sources in a {@code src} directory regardless of the workflow, in which case + * the output behavior will be identical irrespective of the way the compiler is invoked. + */ + public final Path srcPkgPath; + + /** + * The file containing the main source code. This is the Eclipse eCore view of the file, which is + * distinct from the XText view of the file and the OS view of the file. + */ + public final Resource resource; + + /** + * If running in an Eclipse IDE, the iResource refers to the IFile representing the Lingua Franca + * program. This is the XText view of the file, which is distinct from the Eclipse eCore view of + * the file and the OS view of the file. + * + *

    This is null if running outside an Eclipse IDE. + */ + public final IResource iResource; + + /** + * The full path to the file containing the .lf file including the full filename with the .lf + * extension. + */ + public final Path srcFile; + + /** The directory in which the source .lf file was found. */ + public final Path srcPath; // FIXME: rename this to srcDir? + + /** Indicate whether the bin directory should be hierarchical. */ + public final boolean useHierarchicalBin; + + // Protected fields. + + /** Path representation of srcGenRoot, the root directory for generated sources. */ + protected Path srcGenBasePath; + + /** + * The directory in which to put the generated sources. This takes into account the location of + * the source file relative to the package root. Specifically, if the source file is x/y/Z.lf + * relative to the package root, then the generated sources will be put in x/y/Z relative to + * srcGenBasePath. + */ + protected Path srcGenPath; + + // private fields + + /** + * The parent of the directory designated for placing generated sources into ({@code ./src-gen} by + * default). Additional directories (such as {@code bin} or {@code build}) should be created as + * siblings of the directory for generated sources, which means that such directories should be + * created relative to the path assigned to this class variable. + * + *

    The generated source directory is specified in the IDE (Project + * Properties->LF->Compiler->Output Folder). When invoking the standalone compiler, the output + * path is specified directly using the {@code -o} or {@code --output-path} option. + */ + private final Path outPath; + + /** + * The directory that denotes the root of the package to which the generated sources belong. Even + * if the target language does not have a notion of packages, this directory groups all files + * associated with a single main reactor. of packages. + */ + private final Path srcGenPkgPath; + + public FileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) + throws IOException { + this.resource = resource; + this.useHierarchicalBin = useHierarchicalBin; + + this.srcFile = FileUtil.toPath(this.resource); + + this.srcPath = srcFile.getParent(); + this.srcPkgPath = getPkgPath(resource); + + this.srcGenBasePath = srcGenBasePath; + this.name = FileUtil.nameWithoutExtension(this.srcFile); + this.srcGenPath = srcGenBasePath.resolve(getSubPkgPath(srcPath)).resolve(name); + this.srcGenPkgPath = this.srcGenPath; + this.outPath = srcGenBasePath.getParent(); + + Path binRoot = outPath.resolve(DEFAULT_BIN_DIR); + this.binPath = useHierarchicalBin ? binRoot.resolve(getSubPkgPath(srcPath)) : binRoot; + + this.iResource = FileUtil.getIResource(resource); + } + + /** Get the directory a resource is located in relative to the root package */ + public Path getDirectory(Resource r) throws IOException { + return getSubPkgPath(FileUtil.toPath(r).getParent()); + } + + /** + * The parent of the directory designated for placing generated sources into ({@code ./src-gen} by + * default). Additional directories (such as {@code bin} or {@code build}) should be created as + * siblings of the directory for generated sources, which means that such directories should be + * created relative to the path assigned to this class variable. + * + *

    The generated source directory is specified in the IDE (Project + * Properties->LF->Compiler->Output Folder). When invoking the standalone compiler, the output + * path is specified directly using the {@code -o} or {@code --output-path} option. + */ + public Path getOutPath() { + return outPath; + } + + /** + * The directory in which to put the generated sources. This takes into account the location of + * the source file relative to the package root. Specifically, if the source file is x/y/Z.lf + * relative to the package root, then the generated sources will be put in x/y/Z relative to + * srcGenBasePath. + */ + public Path getSrcGenPath() { + return srcGenPath; + } + + /** + * Path representation of srcGenRoot, the root directory for generated sources. This is the root, + * meaning that if the source file is x/y/Z.lf relative to the package root, then the generated + * sources will be put in x/y/Z relative to this URI. + */ + public Path getSrcGenBasePath() { + return srcGenBasePath; + } + + /** + * The directory that denotes the root of the package to which the generated sources belong. Even + * if the target language does not have a notion of packages, this directory groups all files + * associated with a single main reactor. + */ + public Path getSrcGenPkgPath() { + return srcGenPkgPath; + } + + /** Returns the root directory for generated sources. */ + public static Path getSrcGenRoot(IFileSystemAccess2 fsa) throws IOException { + URI srcGenURI = fsa.getURI(""); + if (srcGenURI.hasTrailingPathSeparator()) { + srcGenURI = srcGenURI.trimSegments(1); } - - /** - * The directory in which to put the generated sources. - * This takes into account the location of the source file relative to the - * package root. Specifically, if the source file is x/y/Z.lf relative - * to the package root, then the generated sources will be put in x/y/Z - * relative to srcGenBasePath. - */ - public Path getSrcGenPath() { - return srcGenPath; - } - - - /** - * Path representation of srcGenRoot, the root directory for generated - * sources. This is the root, meaning that if the source file is x/y/Z.lf - * relative to the package root, then the generated sources will be put in x/y/Z - * relative to this URI. - */ - public Path getSrcGenBasePath() { - return srcGenBasePath; + return FileUtil.toPath(srcGenURI); + } + + /** + * Given a path that denotes the full path to a source file (not including the file itself), + * return the relative path from the root of the 'src' directory, or, if there is no 'src' + * directory, the relative path from the root of the package. + * + * @param srcPath The path to the source. + * @return the relative path from the root of the 'src' directory, or, if there is no 'src' + * directory, the relative path from the root of the package + */ + protected Path getSubPkgPath(Path srcPath) { + Path relSrcPath = srcPkgPath.relativize(srcPath); + if (relSrcPath.startsWith(DEFAULT_SRC_DIR)) { + int segments = relSrcPath.getNameCount(); + if (segments == 1) { + return Paths.get(""); + } else { + relSrcPath = relSrcPath.subpath(1, segments); + } } - - /** - * The directory that denotes the root of the package to which the - * generated sources belong. Even if the target language does not have a - * notion of packages, this directory groups all files associated with a - * single main reactor. - */ - public Path getSrcGenPkgPath() { - return srcGenPkgPath; - } - - /** - * Returns the root directory for generated sources. - */ - public static Path getSrcGenRoot(IFileSystemAccess2 fsa) throws IOException { - URI srcGenURI = fsa.getURI(""); - if (srcGenURI.hasTrailingPathSeparator()) { - srcGenURI = srcGenURI.trimSegments(1); + return relSrcPath; + } + + /** + * Clean any artifacts produced by the code generator and target compilers. + * + *

    The base implementation deletes the bin and src-gen directories. If the target code + * generator creates additional files or directories, the corresponding generator should override + * this method. + * + * @throws IOException If an I/O error occurs. + */ + public void doClean() throws IOException { + FileUtil.deleteDirectory(binPath); + FileUtil.deleteDirectory(srcGenBasePath); + } + + private static Path getPkgPath(Resource resource) throws IOException { + if (resource.getURI().isPlatform()) { + // We are in the RCA. + Path srcFile = FileUtil.toPath(resource); + for (IProject r : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + Path p = Paths.get(r.getLocation().toFile().getAbsolutePath()); + Path f = srcFile.toAbsolutePath(); + if (f.startsWith(p)) { + return p; } - return FileUtil.toPath(srcGenURI); - } - - /** - * Given a path that denotes the full path to a source file (not including the - * file itself), return the relative path from the root of the 'src' - * directory, or, if there is no 'src' directory, the relative path - * from the root of the package. - * @param srcPath The path to the source. - * @return the relative path from the root of the 'src' - * directory, or, if there is no 'src' directory, the relative path - * from the root of the package - */ - protected Path getSubPkgPath(Path srcPath) { - Path relSrcPath = srcPkgPath.relativize(srcPath); - if (relSrcPath.startsWith(DEFAULT_SRC_DIR)) { - int segments = relSrcPath.getNameCount(); - if (segments == 1) { - return Paths.get(""); - } else { - relSrcPath = relSrcPath.subpath(1, segments); - } - } - return relSrcPath; - } - - /** - * Clean any artifacts produced by the code generator and target compilers. - *

    - * The base implementation deletes the bin and src-gen directories. If the - * target code generator creates additional files or directories, the - * corresponding generator should override this method. - * - * @throws IOException If an I/O error occurs. - */ - public void doClean() throws IOException { - FileUtil.deleteDirectory(binPath); - FileUtil.deleteDirectory(srcGenBasePath); - } - - private static Path getPkgPath(Resource resource) throws IOException { - if (resource.getURI().isPlatform()) { - // We are in the RCA. - Path srcFile = FileUtil.toPath(resource); - for (IProject r : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { - Path p = Paths.get(r.getLocation().toFile().getAbsolutePath()); - Path f = srcFile.toAbsolutePath(); - if (f.startsWith(p)) { - return p; - } - } - } - return findPackageRoot(FileUtil.toPath(resource), s -> {}); - } - - /** - * Find the package root by looking for an 'src' - * directory. If none can be found, return the current - * working directory instead. - * - * @param input The *.lf file to find the package root - * for. - * @return The package root, or the current working - * directory if none exists. - */ - public static Path findPackageRoot(final Path input, final Consumer printWarning) { - Path p = input; - do { - p = p.getParent(); - if (p == null) { - printWarning.accept("File '" + input.getFileName() + "' is not located in an 'src' directory."); - printWarning.accept("Adopting the current working directory as the package root."); - return Paths.get(".").toAbsolutePath(); // todo #1478 replace with Io::getWd - } - } while (!p.toFile().getName().equals("src")); - return p.getParent(); - } - - /** - * Return an LFCommand instance that can be used to execute the program under compilation. - */ - public LFCommand getCommand() { - String cmd = GeneratorUtils.isHostWindows() ? - getExecutable().toString() : - srcPkgPath.relativize(getExecutable()).toString(); - return LFCommand.get(cmd, List.of(), true, srcPkgPath); - } - - /** - * Return the extension used for binaries on the platform on which compilation takes place. - */ - protected String getExecutableExtension() { - return GeneratorUtils.isHostWindows() ? ".exe" : ""; - } - - /** - * Return a path to an executable version of the program under compilation. - */ - public Path getExecutable() { - return binPath.resolve(name + getExecutableExtension()); + } } + return findPackageRoot(FileUtil.toPath(resource), s -> {}); + } + + /** + * Find the package root by looking for an 'src' directory. If none can be found, return the + * current working directory instead. + * + * @param input The *.lf file to find the package root for. + * @return The package root, or the current working directory if none exists. + */ + public static Path findPackageRoot(final Path input, final Consumer printWarning) { + Path p = input; + do { + p = p.getParent(); + if (p == null) { + printWarning.accept( + "File '" + input.getFileName() + "' is not located in an 'src' directory."); + printWarning.accept("Adopting the current working directory as the package root."); + return Paths.get(".").toAbsolutePath(); // todo #1478 replace with Io::getWd + } + } while (!p.toFile().getName().equals("src")); + return p.getParent(); + } + + /** Return an LFCommand instance that can be used to execute the program under compilation. */ + public LFCommand getCommand() { + String cmd = + GeneratorUtils.isHostWindows() + ? getExecutable().toString() + : srcPkgPath.relativize(getExecutable()).toString(); + return LFCommand.get(cmd, List.of(), true, srcPkgPath); + } + + /** Return the extension used for binaries on the platform on which compilation takes place. */ + protected String getExecutableExtension() { + return GeneratorUtils.isHostWindows() ? ".exe" : ""; + } + + /** Return a path to an executable version of the program under compilation. */ + public Path getExecutable() { + return binPath.resolve(name + getExecutableExtension()); + } } diff --git a/org.lflang/src/org/lflang/InferredType.java b/org.lflang/src/org/lflang/InferredType.java index 41931e0e32..5e9b4a8aa3 100644 --- a/org.lflang/src/org/lflang/InferredType.java +++ b/org.lflang/src/org/lflang/InferredType.java @@ -1,209 +1,184 @@ /************* -Copyright (c) 2020, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; import java.util.function.Function; - import org.eclipse.emf.ecore.EObject; - import org.lflang.ast.ASTUtils; import org.lflang.lf.Type; /** * A helper class that represents an inferred type. * - *

    This class helps to separate the rules of type inference from code generation - * for types. It is particularly useful in cases when the type is not given directly - * in LF code, but is inferred from the context. In this case it could happen that - * no ASTNode representing the type does not exist. For instance when a - * parameter type is inferred from a time value. All in all, this class provides a - * clean interface between type inference in ASTUtils and code generation. + *

    This class helps to separate the rules of type inference from code generation for types. It is + * particularly useful in cases when the type is not given directly in LF code, but is inferred from + * the context. In this case it could happen that no ASTNode representing the type does not exist. + * For instance when a parameter type is inferred from a time value. All in all, this class provides + * a clean interface between type inference in ASTUtils and code generation. * - *

    ASTUtils provides functionality to create an inferred type from - * Lingua Franca variables (getInferredType). This inferred type can than be - * translated to target code using the code generators or be converted to a general - * textual representation using toText(). + *

    ASTUtils provides functionality to create an inferred type from Lingua Franca variables + * (getInferredType). This inferred type can than be translated to target code using the code + * generators or be converted to a general textual representation using toText(). * * @author Christian Menard */ 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; - /** - * A flag indicating whether the inferred type is a list. - */ - public final boolean isList; - /** - * A flag indicating whether the inferred type is a list of variable size. - */ - public final boolean isVariableSizeList; - /** - * A flag indicating whether the inferred type is a list of fixed size. - */ - public final boolean isFixedSizeList; - /** - * The list size if the inferred type is a fixed size list. - * Otherwise, null. - */ - public final Integer listSize; - - - /** - * Private constructor - */ - private InferredType(Type astType, boolean isTime, boolean isVariableSizeList, - boolean isFixedSizeList, Integer listSize) { - this.astType = astType; - this.isTime = isTime; - this.isList = isVariableSizeList || isFixedSizeList; - this.isVariableSizeList = isVariableSizeList; - this.isFixedSizeList = isFixedSizeList; - this.listSize = listSize; + /** 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; + /** A flag indicating whether the inferred type is a list. */ + public final boolean isList; + /** A flag indicating whether the inferred type is a list of variable size. */ + public final boolean isVariableSizeList; + /** A flag indicating whether the inferred type is a list of fixed size. */ + public final boolean isFixedSizeList; + /** The list size if the inferred type is a fixed size list. Otherwise, null. */ + public final Integer listSize; + + /** Private constructor */ + private InferredType( + Type astType, + boolean isTime, + boolean isVariableSizeList, + boolean isFixedSizeList, + Integer listSize) { + this.astType = astType; + this.isTime = isTime; + this.isList = isVariableSizeList || isFixedSizeList; + this.isVariableSizeList = isVariableSizeList; + this.isFixedSizeList = isFixedSizeList; + this.listSize = listSize; + } + + /** Check if the inferred type is undefined. */ + public boolean isUndefined() { + return astType == null && !isTime; + } + + /** + * Convert the inferred type to its textual representation as it would appear in LF code, with + * CodeMap tags inserted. + */ + public String toText() { + return toTextHelper(ASTUtils::toText); + } + + /** + * Convert the inferred type to its textual representation as it would appear in LF code, without + * CodeMap tags inserted. + */ + public String toOriginalText() { + return toTextHelper(ASTUtils::toOriginalText); + } + + private String toTextHelper(Function toText) { + if (astType != null) { + return toText.apply(astType); + } else if (isTime) { + if (isFixedSizeList) { + return "time[" + listSize + "]"; + } else if (isVariableSizeList) { + return "time[]"; + } else { + return "time"; + } } - - - /** - * Check if the inferred type is undefined. - */ - public boolean isUndefined() { - return astType == null && !isTime; - } - - /** - * Convert the inferred type to its textual representation as it would appear in LF code, - * with CodeMap tags inserted. - */ - public String toText() { return toTextHelper(ASTUtils::toText); } - - /** - * Convert the inferred type to its textual representation as it would appear in LF code, - * without CodeMap tags inserted. - */ - public String toOriginalText() { return toTextHelper(ASTUtils::toOriginalText); } - - private String toTextHelper(Function toText) { - if (astType != null) { - return toText.apply(astType); - } else if (isTime) { - if (isFixedSizeList) { - return "time[" + listSize + "]"; - } else if (isVariableSizeList) { - return "time[]"; - } else { - return "time"; - } - } - return ""; - } - - /** - * Convert the inferred type to its textual representation - * while ignoring any list qualifiers or type arguments. - * - * @return Textual representation of this inferred type without list qualifiers - */ - public String baseType() { - if (astType != null) { - return ASTUtils.baseType(astType); - } else if (isTime) { - return "time"; - } - return ""; + return ""; + } + + /** + * Convert the inferred type to its textual representation while ignoring any list qualifiers or + * type arguments. + * + * @return Textual representation of this inferred type without list qualifiers + */ + public String baseType() { + if (astType != null) { + return ASTUtils.baseType(astType); + } else if (isTime) { + return "time"; } - - /** - * Create an inferred type from an AST node. - * - * @param type an AST node - * @return A new inferred type representing the given AST node - */ - public static InferredType fromAST(Type type) { - if (type == null) { - return undefined(); - } - return new InferredType( - type, - type.isTime(), - type.getArraySpec() != null && type.getArraySpec().isOfVariableLength(), - type.getArraySpec() != null && !type.getArraySpec().isOfVariableLength(), - type.getArraySpec() != null ? type.getArraySpec().getLength() : null - ); - } - - /** - * Create an undefined inferred type. - */ - public static InferredType undefined() { - return new InferredType(null, false, false, false, null); - } - - /** - * Create an inferred type representing time. - */ - public static InferredType time() { - return new InferredType(null, true, false, false, null); - } - - /** - * Create an inferred type representing a list of time values. - * - *

    This creates a fixed size list if size is non-null, - * otherwise a variable size list. - * - * @param size The list size, may be null - */ - public static InferredType timeList(Integer size) { - return new InferredType(null, true, size == null, size != null, size); - } - - /** - * Create an inferred type representing a variable size time list. - */ - public static InferredType timeList() { - return timeList(null); - } - - /** - * Returns the component type, if this is a first-class - * list type. Eg returns {@code time} for the type {@code time[]}. - * If this is not a first-class list type, returns null. - * - *

    Todo this does not return int for int[], we need to - * make the parser production left-recursive. OTOH only - * time and time[] are first class in our framework so - * this doesn't contradict the contract of this method. - */ - public InferredType getComponentType() { - return isTime && isList ? time() : null; + return ""; + } + + /** + * Create an inferred type from an AST node. + * + * @param type an AST node + * @return A new inferred type representing the given AST node + */ + public static InferredType fromAST(Type type) { + if (type == null) { + return undefined(); } + return new InferredType( + type, + type.isTime(), + type.getArraySpec() != null && type.getArraySpec().isOfVariableLength(), + type.getArraySpec() != null && !type.getArraySpec().isOfVariableLength(), + type.getArraySpec() != null ? type.getArraySpec().getLength() : null); + } + + /** Create an undefined inferred type. */ + public static InferredType undefined() { + return new InferredType(null, false, false, false, null); + } + + /** Create an inferred type representing time. */ + public static InferredType time() { + return new InferredType(null, true, false, false, null); + } + + /** + * Create an inferred type representing a list of time values. + * + *

    This creates a fixed size list if size is non-null, otherwise a variable size list. + * + * @param size The list size, may be null + */ + public static InferredType timeList(Integer size) { + return new InferredType(null, true, size == null, size != null, size); + } + + /** Create an inferred type representing a variable size time list. */ + public static InferredType timeList() { + return timeList(null); + } + + /** + * Returns the component type, if this is a first-class list type. Eg returns {@code time} for the + * type {@code time[]}. If this is not a first-class list type, returns null. + * + *

    Todo this does not return int for int[], we need to make the parser production + * left-recursive. OTOH only time and time[] are first class in our framework so this doesn't + * contradict the contract of this method. + */ + public InferredType getComponentType() { + return isTime && isList ? time() : null; + } } diff --git a/org.lflang/src/org/lflang/LFResourceDescriptionStrategy.java b/org.lflang/src/org/lflang/LFResourceDescriptionStrategy.java index 548d5e0ea6..487e63374b 100644 --- a/org.lflang/src/org/lflang/LFResourceDescriptionStrategy.java +++ b/org.lflang/src/org/lflang/LFResourceDescriptionStrategy.java @@ -1,32 +1,32 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; +import com.google.inject.Inject; import java.util.Map; import java.util.stream.Collectors; - import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.naming.QualifiedName; import org.eclipse.xtext.resource.EObjectDescription; @@ -34,56 +34,52 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy; import org.eclipse.xtext.scoping.impl.ImportUriResolver; import org.eclipse.xtext.util.IAcceptor; - import org.lflang.lf.Model; -import com.google.inject.Inject; - /** - * Resource description strategy designed to limit global scope to only those - * files that were explicitly imported. - *

    - * Adapted from example provided by Itemis. + * Resource description strategy designed to limit global scope to only those files that were + * explicitly imported. + * + *

    Adapted from example provided by Itemis. * * @author Marten Lohstroh * @see "https://blogs.itemis.com/en/in-five-minutes-to-transitive-imports-within-a-dsl-with-xtext" */ public class LFResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy { - /** - * Key used in user data attached to description of a Model. - */ - public static final String INCLUDES = "includes"; + /** Key used in user data attached to description of a Model. */ + public static final String INCLUDES = "includes"; - /** - * Delimiter used in the values associated with INCLUDES keys in the - * user-data descriptions of Models. - */ - public static final String DELIMITER = ","; + /** + * Delimiter used in the values associated with INCLUDES keys in the user-data descriptions of + * Models. + */ + public static final String DELIMITER = ","; - @Inject - private ImportUriResolver uriResolver; + @Inject private ImportUriResolver uriResolver; - @Override - public boolean createEObjectDescriptions(EObject eObject, IAcceptor acceptor) { - if (eObject instanceof Model) { - this.createEObjectDescriptionForModel((Model) eObject, acceptor); - return true; - } else { - return super.createEObjectDescriptions(eObject, acceptor); - } + @Override + public boolean createEObjectDescriptions( + EObject eObject, IAcceptor acceptor) { + if (eObject instanceof Model) { + this.createEObjectDescriptionForModel((Model) eObject, acceptor); + return true; + } else { + return super.createEObjectDescriptions(eObject, acceptor); } + } - /** - * Build an index containing the strings of the URIs imported resources. - *

    - * All the URIs are added to comma-separated string and stored under the - * key "includes" in the userData map of the object description. - **/ - private void createEObjectDescriptionForModel(Model model, IAcceptor acceptor) { - var uris = model.getImports().stream().map(uriResolver).collect(Collectors.joining(DELIMITER)); - var userData = Map.of(INCLUDES, uris); - QualifiedName qname = QualifiedName.create(model.eResource().getURI().toString()); - acceptor.accept(EObjectDescription.create(qname, model, userData)); - } + /** + * Build an index containing the strings of the URIs imported resources. + * + *

    All the URIs are added to comma-separated string and stored under the key "includes" in the + * userData map of the object description. + */ + private void createEObjectDescriptionForModel( + Model model, IAcceptor acceptor) { + var uris = model.getImports().stream().map(uriResolver).collect(Collectors.joining(DELIMITER)); + var userData = Map.of(INCLUDES, uris); + QualifiedName qname = QualifiedName.create(model.eResource().getURI().toString()); + acceptor.accept(EObjectDescription.create(qname, model, userData)); + } } diff --git a/org.lflang/src/org/lflang/LFResourceProvider.java b/org.lflang/src/org/lflang/LFResourceProvider.java index 51db96a6d5..03c7b9ea47 100644 --- a/org.lflang/src/org/lflang/LFResourceProvider.java +++ b/org.lflang/src/org/lflang/LFResourceProvider.java @@ -1,28 +1,24 @@ package org.lflang; -import org.eclipse.emf.ecore.resource.ResourceSet; - import com.google.inject.Inject; import com.google.inject.Provider; +import org.eclipse.emf.ecore.resource.ResourceSet; /** * Class that provides access to a resource set. - * - * @author Marten Lohstroh * + * @author Marten Lohstroh */ public class LFResourceProvider { - /** - * Injected resource set provider. - */ - @Inject - private Provider resourceSetProvider; - - /** - * Return a resource set obtained from the injected provider. - * @return - */ - public ResourceSet getResourceSet() { - return this.resourceSetProvider.get(); - } + /** Injected resource set provider. */ + @Inject private Provider resourceSetProvider; + + /** + * Return a resource set obtained from the injected provider. + * + * @return + */ + public ResourceSet getResourceSet() { + return this.resourceSetProvider.get(); + } } diff --git a/org.lflang/src/org/lflang/LFRuntimeModule.java b/org.lflang/src/org/lflang/LFRuntimeModule.java index a7c1e80a19..a01986dfb3 100644 --- a/org.lflang/src/org/lflang/LFRuntimeModule.java +++ b/org.lflang/src/org/lflang/LFRuntimeModule.java @@ -8,50 +8,50 @@ import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy; import org.eclipse.xtext.scoping.IGlobalScopeProvider; import org.eclipse.xtext.validation.INamesAreUniqueValidationHelper; - import org.lflang.formatting2.LFFormatter; import org.lflang.scoping.LFGlobalScopeProvider; import org.lflang.validation.LFNamesAreUniqueValidationHelper; /** - * Binds services that are available both when running LFC - * standalone, and when running within the IDE. + * Binds services that are available both when running LFC standalone, and when running within the + * IDE. + * *

      - *
    • LfIdeModule overrides this module with additional - * bindings when running in the IDE. - *
    • {@code org.lflang.lfc.LFStandaloneModule} overrides this module when - * running LFC standalone. + *
    • LfIdeModule overrides this module with additional bindings when running in the IDE. + *
    • {@code org.lflang.lfc.LFStandaloneModule} overrides this module when running LFC + * standalone. *
    */ public class LFRuntimeModule extends AbstractLFRuntimeModule { - /** Establish a binding to our custom resource description strategy. */ - public Class bindIDefaultResourceDescriptionStrategy() { - return LFResourceDescriptionStrategy.class; - } - - /** Establish a binding to our custom global scope provider. */ - @Override - public Class bindIGlobalScopeProvider() { - return LFGlobalScopeProvider.class; - } - - /** Establish a binding to a helper that checks that names are unique. */ - public Class bindNamesAreUniqueValidationHelper() { - return LFNamesAreUniqueValidationHelper.class; - } - - public Class bindISyntaxErrorMessageProvider() { - return LFSyntaxErrorMessageProvider.class; - } - - /** The error reporter. {@code org.lflang.lfc.LFStandaloneModule} overrides this binding. */ - public Class bindErrorReporter() { - return DefaultErrorReporter.class; - } - - @Override - public Class bindIFormatter2() { - return LFFormatter.class; - } + /** Establish a binding to our custom resource description strategy. */ + public Class + bindIDefaultResourceDescriptionStrategy() { + return LFResourceDescriptionStrategy.class; + } + + /** Establish a binding to our custom global scope provider. */ + @Override + public Class bindIGlobalScopeProvider() { + return LFGlobalScopeProvider.class; + } + + /** Establish a binding to a helper that checks that names are unique. */ + public Class bindNamesAreUniqueValidationHelper() { + return LFNamesAreUniqueValidationHelper.class; + } + + public Class bindISyntaxErrorMessageProvider() { + return LFSyntaxErrorMessageProvider.class; + } + + /** The error reporter. {@code org.lflang.lfc.LFStandaloneModule} overrides this binding. */ + public Class bindErrorReporter() { + return DefaultErrorReporter.class; + } + + @Override + public Class bindIFormatter2() { + return LFFormatter.class; + } } diff --git a/org.lflang/src/org/lflang/LFStandaloneSetup.java b/org.lflang/src/org/lflang/LFStandaloneSetup.java index c1b5e85ecf..13264adabe 100644 --- a/org.lflang/src/org/lflang/LFStandaloneSetup.java +++ b/org.lflang/src/org/lflang/LFStandaloneSetup.java @@ -4,33 +4,30 @@ package org.lflang; - -import org.eclipse.xtext.util.Modules2; - import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; +import org.eclipse.xtext.util.Modules2; /** - * Initialization support for running Xtext languages without - * Equinox extension registry. + * Initialization support for running Xtext languages without Equinox extension registry. * - * See {@link LFRuntimeModule}, the base Guice module for LF services. + *

    See {@link LFRuntimeModule}, the base Guice module for LF services. */ public class LFStandaloneSetup extends LFStandaloneSetupGenerated { - private final Module module; + private final Module module; - public LFStandaloneSetup() { - this.module = new LFRuntimeModule(); - } + public LFStandaloneSetup() { + this.module = new LFRuntimeModule(); + } - public LFStandaloneSetup(Module... modules) { - this.module = Modules2.mixin(modules); - } + public LFStandaloneSetup(Module... modules) { + this.module = Modules2.mixin(modules); + } - @Override - public Injector createInjector() { - return Guice.createInjector(this.module); - } + @Override + public Injector createInjector() { + return Guice.createInjector(this.module); + } } diff --git a/org.lflang/src/org/lflang/LFSyntaxErrorMessageProvider.java b/org.lflang/src/org/lflang/LFSyntaxErrorMessageProvider.java index ac5511980a..d1ddb312e1 100644 --- a/org.lflang/src/org/lflang/LFSyntaxErrorMessageProvider.java +++ b/org.lflang/src/org/lflang/LFSyntaxErrorMessageProvider.java @@ -1,8 +1,8 @@ package org.lflang; +import com.google.inject.Inject; import java.util.Set; import java.util.stream.Collectors; - import org.antlr.runtime.RecognitionException; import org.antlr.runtime.Token; import org.eclipse.xtext.GrammarUtil; @@ -10,78 +10,70 @@ import org.eclipse.xtext.nodemodel.SyntaxErrorMessage; import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider; -import com.google.inject.Inject; - /** * Custom error message provider that intercepts syntax errors. - * + * * @author Marten Lohstroh */ public class LFSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider { - - /** - * Issue code for syntax error due to misused keyword. - */ - public static String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD"; - - /** - * Issue code for syntax error due to misused single quotes. - */ - public static String SINGLY_QUOTED_STRING = "SINGLE_QUOTED_STRING"; - - /** - * Helper that provides access to the grammar. - */ - @Inject IGrammarAccess grammarAccess; - - /** - * Set of keywords that otherwise would be valid identifiers. - * For example, 'reaction' is part of this set, but '{=' is not. - */ - public Set keywords; - - /** - * Customize intercepted error messages. - * - * @Override - */ - public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) { - - if (context != null) { - String message = context.getDefaultMessage(); - - // Describe situation where an unexpected token was encountered where a closing single quote was expected. - if (message.contains("expecting '''")) { - return new SyntaxErrorMessage("Single quotes can only be used around single characters, not strings. " - + "Please use double quotes instead.", SINGLY_QUOTED_STRING); + + /** Issue code for syntax error due to misused keyword. */ + public static String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD"; + + /** Issue code for syntax error due to misused single quotes. */ + public static String SINGLY_QUOTED_STRING = "SINGLE_QUOTED_STRING"; + + /** Helper that provides access to the grammar. */ + @Inject IGrammarAccess grammarAccess; + + /** + * Set of keywords that otherwise would be valid identifiers. For example, 'reaction' is part of + * this set, but '{=' is not. + */ + public Set keywords; + + /** Customize intercepted error messages. @Override */ + public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) { + + if (context != null) { + String message = context.getDefaultMessage(); + + // Describe situation where an unexpected token was encountered where a closing single quote + // was expected. + if (message.contains("expecting '''")) { + return new SyntaxErrorMessage( + "Single quotes can only be used around single characters, not strings. " + + "Please use double quotes instead.", + SINGLY_QUOTED_STRING); + } + + RecognitionException e = context.getRecognitionException(); + if (e != null) { + Token token = e.token; + if (token != null) { + String text = token.getText(); + if (text != null) { + // Update keywords if not yet set. + if (keywords == null) { + // ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* + this.keywords = + GrammarUtil.getAllKeywords(grammarAccess.getGrammar()).stream() + .filter(k -> k.matches("^([a-z]|[A-Z]|_)+(\\w|_)*$")) + .collect(Collectors.toSet()); } - - RecognitionException e = context.getRecognitionException(); - if (e != null) { - Token token = e.token; - if (token != null) { - String text = token.getText(); - if (text != null) { - // Update keywords if not yet set. - if (keywords == null) { - // ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* - this.keywords = GrammarUtil - .getAllKeywords(grammarAccess.getGrammar()) - .stream() - .filter(k -> k - .matches("^([a-z]|[A-Z]|_)+(\\w|_)*$")) - .collect(Collectors.toSet()); - - } - // Describe situation where a keyword is used as an identifier. - if (keywords.contains(text)) { - return new SyntaxErrorMessage("'" + text + "' is a reserved keyword " - + "which cannot be used as an identifier.", USED_RESERVED_KEYWORD); - } - } - } + // Describe situation where a keyword is used as an identifier. + if (keywords.contains(text)) { + return new SyntaxErrorMessage( + "'" + + text + + "' is a reserved keyword " + + "which cannot be used as an identifier.", + USED_RESERVED_KEYWORD); } + } } - return super.getSyntaxErrorMessage(context); + } } + return super.getSyntaxErrorMessage(context); + } } diff --git a/org.lflang/src/org/lflang/LocalStrings.java b/org.lflang/src/org/lflang/LocalStrings.java index 79f338b39d..314839c3f1 100644 --- a/org.lflang/src/org/lflang/LocalStrings.java +++ b/org.lflang/src/org/lflang/LocalStrings.java @@ -2,10 +2,8 @@ import java.util.ResourceBundle; -/** - * Static class for managing strings. - */ +/** Static class for managing strings. */ public class LocalStrings { - public static final ResourceBundle res = ResourceBundle.getBundle("org.lflang.StringsBundle"); - public static final String VERSION = res.getString("VERSION"); + public static final ResourceBundle res = ResourceBundle.getBundle("org.lflang.StringsBundle"); + public static final String VERSION = res.getString("VERSION"); } diff --git a/org.lflang/src/org/lflang/MainConflictChecker.java b/org.lflang/src/org/lflang/MainConflictChecker.java index 6ee3ebf569..1805cda5d7 100644 --- a/org.lflang/src/org/lflang/MainConflictChecker.java +++ b/org.lflang/src/org/lflang/MainConflictChecker.java @@ -2,6 +2,7 @@ import static java.nio.file.FileVisitResult.CONTINUE; +import com.google.common.collect.Iterables; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -11,7 +12,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -20,92 +20,79 @@ import org.lflang.lf.Reactor; import org.lflang.util.FileUtil; -import com.google.common.collect.Iterables; - /** - * Class that (upon instantiation) determines whether there are any conflicting main reactors in the current package. - * Conflicts are reported in the instance's conflicts list. - * - * @author Marten Lohstroh + * Class that (upon instantiation) determines whether there are any conflicting main reactors in the + * current package. Conflicts are reported in the instance's conflicts list. * + * @author Marten Lohstroh */ public class MainConflictChecker { - /** - * List of conflict encountered while traversing the package. - */ - public final List conflicts = new LinkedList(); - - /** - * The current file configuration. - */ - protected FileConfig fileConfig; - - /** - * Resource set used to obtain resources from. - */ - protected static final ResourceSet rs = new LFStandaloneSetup() - .createInjectorAndDoEMFRegistration() - .getInstance(LFResourceProvider.class).getResourceSet(); - - /** - * Create a new instance that walks the file tree of the package to find conflicts. - * - * @param fileConfig The current file configuration. - */ - public MainConflictChecker(FileConfig fileConfig) { - // FIXME: See if there is a faster way to do this check that does not involve parsing all - // files in the current package (which happens when we get the resources) - this.fileConfig = fileConfig; - try { - Files.walkFileTree(fileConfig.srcPkgPath, new PackageVisitor()); - } catch (IOException e) { - System.err.println("Error while checking for name conflicts in package."); - e.printStackTrace(); - } + /** List of conflict encountered while traversing the package. */ + public final List conflicts = new LinkedList(); + + /** The current file configuration. */ + protected FileConfig fileConfig; + + /** Resource set used to obtain resources from. */ + protected static final ResourceSet rs = + new LFStandaloneSetup() + .createInjectorAndDoEMFRegistration() + .getInstance(LFResourceProvider.class) + .getResourceSet(); + + /** + * Create a new instance that walks the file tree of the package to find conflicts. + * + * @param fileConfig The current file configuration. + */ + public MainConflictChecker(FileConfig fileConfig) { + // FIXME: See if there is a faster way to do this check that does not involve parsing all + // files in the current package (which happens when we get the resources) + this.fileConfig = fileConfig; + try { + Files.walkFileTree(fileConfig.srcPkgPath, new PackageVisitor()); + } catch (IOException e) { + System.err.println("Error while checking for name conflicts in package."); + e.printStackTrace(); } - - /** - * Extension of a SimpleFileVisitor that adds entries to the conflicts list in the outer class. - * - * Specifically, each visited file is checked against the name present in the current file configuration. - * If the name matches the current file (but is not the file itself), then parse that file and determine whether - * there is a main reactor declared. If there is one, report a conflict. - * - * @author Marten Lohstroh - * - */ - public class PackageVisitor extends SimpleFileVisitor { + } + + /** + * Extension of a SimpleFileVisitor that adds entries to the conflicts list in the outer class. + * + *

    Specifically, each visited file is checked against the name present in the current file + * configuration. If the name matches the current file (but is not the file itself), then parse + * that file and determine whether there is a main reactor declared. If there is one, report a + * conflict. + * + * @author Marten Lohstroh + */ + public class PackageVisitor extends SimpleFileVisitor { - /** - * Report a conflicting main reactors in visited files. - */ - @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attr) { - path = path.normalize(); - if (attr.isRegularFile() && path.toString().endsWith(".lf")) { - // Parse the file. - Resource r = rs.getResource( - URI.createFileURI(path.toFile().getAbsolutePath()), - true); - if (r.getErrors().isEmpty()) { - // No errors. Find the main reactor. - Iterator reactors = Iterables - .filter(IteratorExtensions - .toIterable(r.getAllContents()), - Reactor.class) - .iterator(); - // If this is not the same file, but it has a main reactor - // and the name matches, then report the conflict. - if (!fileConfig.srcFile.equals(path) - && IteratorExtensions.exists(reactors, it -> it.isMain() || it.isFederated()) - && fileConfig.name.equals(FileUtil.nameWithoutExtension(path))) { - conflicts.add( - fileConfig.srcPath.relativize(path).toString()); - } - } - } - return CONTINUE; + /** Report a conflicting main reactors in visited files. */ + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attr) { + path = path.normalize(); + if (attr.isRegularFile() && path.toString().endsWith(".lf")) { + // Parse the file. + Resource r = rs.getResource(URI.createFileURI(path.toFile().getAbsolutePath()), true); + if (r.getErrors().isEmpty()) { + // No errors. Find the main reactor. + Iterator reactors = + Iterables.filter( + IteratorExtensions.toIterable(r.getAllContents()), Reactor.class) + .iterator(); + // If this is not the same file, but it has a main reactor + // and the name matches, then report the conflict. + if (!fileConfig.srcFile.equals(path) + && IteratorExtensions.exists(reactors, it -> it.isMain() || it.isFederated()) + && fileConfig.name.equals(FileUtil.nameWithoutExtension(path))) { + conflicts.add(fileConfig.srcPath.relativize(path).toString()); + } } + } + return CONTINUE; } + } } diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index 24d5c447c2..17ee7cfb76 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -1,27 +1,27 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; @@ -35,7 +35,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; - import org.lflang.ast.ASTUtils; import org.lflang.generator.NamedInstance; import org.lflang.generator.ReactorInstance; @@ -51,214 +50,209 @@ import org.lflang.lf.STP; import org.lflang.util.FileUtil; - /** * A helper class for analyzing the AST. This class is instantiated once for each compilation. - *

    - * NOTE: the validator used on imported files uses the same instance! Hence, this class should not contain any info - * specific to any particular resource that is involved in the compilation. + * + *

    NOTE: the validator used on imported files uses the same instance! Hence, this class should + * not contain any info specific to any particular resource that is involved in the compilation. * * @author Marten Lohstroh */ public class ModelInfo { - /** - * Data structure for tracking dependencies between reactor classes. An - * instantiation of class A inside of class B implies that B depends on A. - */ - public InstantiationGraph instantiationGraph; - - /** - * The AST that the info gathered in this class pertains to. - */ - public Model model; - - /** - * The set of assignments that assign a too-large constant to a parameter - * that is used to specify a deadline. These assignments are to be reported - * during validation. - */ - public Set overflowingAssignments; - - /** - * The set of deadlines that use a too-large constant to specify their time - * interval. - */ - public Set overflowingDeadlines; - - /** - * The set of STP offsets that use a too-large constant to specify their time - * interval. - */ - public Set overflowingSTP; - - /** - * The set of parameters used to specify a deadline while having been - * assigned a default value the is too large for this purpose. These - * parameters are to be reported during validation. - */ - public Set overflowingParameters; - - /** Cycles found during topology analysis. */ - private Set> topologyCycles = new LinkedHashSet>(); - - /** - * Whether or not the model information has been updated at least once. - */ - public boolean updated; - - /** - * Redo all analysis based on the given model. - * - * @param model the model to analyze. - */ - public void update(Model model, ErrorReporter reporter) { - this.updated = true; - this.model = model; - this.instantiationGraph = new InstantiationGraph(model, true); - - if (this.instantiationGraph.getCycles().size() == 0) { - List topLevelReactorInstances = new LinkedList<>(); - var main = model.getReactors().stream().filter(it -> it.isMain() || it.isFederated()).findFirst(); - if (main.isPresent()) { - var inst = new ReactorInstance(main.get(), reporter); - topLevelReactorInstances.add(inst); - } else { - model.getReactors().forEach( - it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter)) - ); - } - // don't store the graph into a field, only the cycles. - for (ReactorInstance top : topLevelReactorInstances) { - this.topologyCycles.addAll(top.getCycles()); - } - } - - // may be null if the target is invalid - var target = Target.forName(model.getTarget().getName()).orElse(null); + /** + * Data structure for tracking dependencies between reactor classes. An instantiation of class A + * inside of class B implies that B depends on A. + */ + public InstantiationGraph instantiationGraph; + + /** The AST that the info gathered in this class pertains to. */ + public Model model; + + /** + * The set of assignments that assign a too-large constant to a parameter that is used to specify + * a deadline. These assignments are to be reported during validation. + */ + public Set overflowingAssignments; + + /** The set of deadlines that use a too-large constant to specify their time interval. */ + public Set overflowingDeadlines; + + /** The set of STP offsets that use a too-large constant to specify their time interval. */ + public Set overflowingSTP; + + /** + * The set of parameters used to specify a deadline while having been assigned a default value the + * is too large for this purpose. These parameters are to be reported during validation. + */ + public Set overflowingParameters; + + /** Cycles found during topology analysis. */ + private Set> topologyCycles = new LinkedHashSet>(); + + /** Whether or not the model information has been updated at least once. */ + public boolean updated; + + /** + * Redo all analysis based on the given model. + * + * @param model the model to analyze. + */ + public void update(Model model, ErrorReporter reporter) { + this.updated = true; + this.model = model; + this.instantiationGraph = new InstantiationGraph(model, true); + + if (this.instantiationGraph.getCycles().size() == 0) { + List topLevelReactorInstances = new LinkedList<>(); + var main = + model.getReactors().stream().filter(it -> it.isMain() || it.isFederated()).findFirst(); + if (main.isPresent()) { + var inst = new ReactorInstance(main.get(), reporter); + topLevelReactorInstances.add(inst); + } else { + model + .getReactors() + .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter))); + } + // don't store the graph into a field, only the cycles. + for (ReactorInstance top : topLevelReactorInstances) { + this.topologyCycles.addAll(top.getCycles()); + } + } - // Perform C-specific traversals. - if (target == Target.C) { - this.collectOverflowingNodes(); - } + // may be null if the target is invalid + var target = Target.forName(model.getTarget().getName()).orElse(null); - checkCaseInsensitiveNameCollisions(model, reporter); + // Perform C-specific traversals. + if (target == Target.C) { + this.collectOverflowingNodes(); } - public void checkCaseInsensitiveNameCollisions(Model model, ErrorReporter reporter) { - var reactorNames = new HashSet<>(); - var bad = new ArrayList<>(); - for (var reactor : model.getReactors()) { - var lowerName = getName(reactor).toLowerCase(); - if (reactorNames.contains(lowerName)) bad.add(lowerName); - reactorNames.add(lowerName); - } - for (var badName : bad) { - model.getReactors().stream() - .filter(it -> getName(it).toLowerCase().equals(badName)) - .forEach(it -> reporter.reportError(it, "Multiple reactors have the same name up to case differences.")); - } - } + checkCaseInsensitiveNameCollisions(model, reporter); + } - private String getName(Reactor r) { - return r.getName() != null ? r.getName() : FileUtil.nameWithoutExtension(Path.of(model.eResource().getURI().toFileString())); + public void checkCaseInsensitiveNameCollisions(Model model, ErrorReporter reporter) { + var reactorNames = new HashSet<>(); + var bad = new ArrayList<>(); + for (var reactor : model.getReactors()) { + var lowerName = getName(reactor).toLowerCase(); + if (reactorNames.contains(lowerName)) bad.add(lowerName); + reactorNames.add(lowerName); } - - public Set> topologyCycles() { - return this.topologyCycles; + for (var badName : bad) { + model.getReactors().stream() + .filter(it -> getName(it).toLowerCase().equals(badName)) + .forEach( + it -> + reporter.reportError( + it, "Multiple reactors have the same name up to case differences.")); } - - /** - * Collect all assignments, deadlines, and parameters that can cause the - * time interval of a deadline to overflow. In the C target, only 48 bits - * are allotted for deadline intervals, which are specified in nanosecond - * precision. - */ - private void collectOverflowingNodes() { - - this.overflowingAssignments = new HashSet<>(); - this.overflowingDeadlines = new HashSet<>(); - this.overflowingParameters = new HashSet<>(); - this.overflowingSTP = new HashSet<>(); - - // Visit all deadlines in the model; detect possible overflow. - for (var deadline : filter(toIterable(model.eAllContents()), Deadline.class)) { - // If the time value overflows, mark this deadline as overflowing. - if (isTooLarge(ASTUtils.getLiteralTimeValue(deadline.getDelay()))) { - this.overflowingDeadlines.add(deadline); - } - - // If any of the upstream parameters overflow, report this deadline. - final var delay = deadline.getDelay(); - if (delay instanceof ParameterReference - && detectOverflow(new HashSet<>(), ((ParameterReference) deadline.getDelay()).getParameter())) { - this.overflowingDeadlines.add(deadline); - } - } - // Visit all STP offsets in the model; detect possible overflow. - for (var stp : filter(toIterable(model.eAllContents()), STP.class)) { - // If the time value overflows, mark this deadline as overflowing. - if (isTooLarge(ASTUtils.getLiteralTimeValue(stp.getValue()))) { - this.overflowingSTP.add(stp); - } - } + } + + private String getName(Reactor r) { + return r.getName() != null + ? r.getName() + : FileUtil.nameWithoutExtension(Path.of(model.eResource().getURI().toFileString())); + } + + public Set> topologyCycles() { + return this.topologyCycles; + } + + /** + * Collect all assignments, deadlines, and parameters that can cause the time interval of a + * deadline to overflow. In the C target, only 48 bits are allotted for deadline intervals, which + * are specified in nanosecond precision. + */ + private void collectOverflowingNodes() { + + this.overflowingAssignments = new HashSet<>(); + this.overflowingDeadlines = new HashSet<>(); + this.overflowingParameters = new HashSet<>(); + this.overflowingSTP = new HashSet<>(); + + // Visit all deadlines in the model; detect possible overflow. + for (var deadline : filter(toIterable(model.eAllContents()), Deadline.class)) { + // If the time value overflows, mark this deadline as overflowing. + if (isTooLarge(ASTUtils.getLiteralTimeValue(deadline.getDelay()))) { + this.overflowingDeadlines.add(deadline); + } + + // If any of the upstream parameters overflow, report this deadline. + final var delay = deadline.getDelay(); + if (delay instanceof ParameterReference + && detectOverflow( + new HashSet<>(), ((ParameterReference) deadline.getDelay()).getParameter())) { + this.overflowingDeadlines.add(deadline); + } } - - /** - * In the C target, only 48 bits are allotted for deadline intervals, which - * are specified in nanosecond precision. Check whether the given time value - * exceeds the maximum specified value. - * - * @return true if the time value is greater than the specified maximum, - * false otherwise. - */ - private boolean isTooLarge(TimeValue time) { - return time != null && time.toNanoSeconds() > TimeValue.MAX_LONG_DEADLINE; + // Visit all STP offsets in the model; detect possible overflow. + for (var stp : filter(toIterable(model.eAllContents()), STP.class)) { + // If the time value overflows, mark this deadline as overflowing. + if (isTooLarge(ASTUtils.getLiteralTimeValue(stp.getValue()))) { + this.overflowingSTP.add(stp); + } + } + } + + /** + * In the C target, only 48 bits are allotted for deadline intervals, which are specified in + * nanosecond precision. Check whether the given time value exceeds the maximum specified value. + * + * @return true if the time value is greater than the specified maximum, false otherwise. + */ + private boolean isTooLarge(TimeValue time) { + return time != null && time.toNanoSeconds() > TimeValue.MAX_LONG_DEADLINE; + } + + /** + * Given a parameter that is used in a deadline specification, recursively track down its + * definition and check whether it is overflowing. Also detect and report overrides that are + * overflowing. + * + * @return true if there exists a parameter corresponding to a value that does not fit in the + * available bits. + */ + private boolean detectOverflow(Set visited, Parameter current) { + var overflow = false; + + // Determine whether the parameter's default value overflows or not. + if (isTooLarge(ASTUtils.getDefaultAsTimeValue(current))) { + this.overflowingParameters.add(current); + overflow = true; } - /** - * Given a parameter that is used in a deadline specification, recursively - * track down its definition and check whether it is overflowing. Also - * detect and report overrides that are overflowing. - * @return true if there exists a parameter corresponding to a value that - * does not fit in the available bits. - */ - private boolean detectOverflow(Set visited, Parameter current) { - var overflow = false; - - // Determine whether the parameter's default value overflows or not. - if (isTooLarge(ASTUtils.getDefaultAsTimeValue(current))) { - this.overflowingParameters.add(current); - overflow = true; - } - - // Iterate over the instantiations of the reactor in which the - // current parameter was found. - Set instantiations = this.instantiationGraph.getInstantiations((Reactor) current.eContainer()); - for (var instantiation : instantiations) { - // Only visit each instantiation once per deadline to avoid cycles. - if (!visited.contains(instantiation)) { - visited.add(instantiation); - // Find assignments that override the current parameter. - for (var assignment : instantiation.getParameters()) { - if (assignment.getLhs().equals(current)) { - if (assignment.getRhs().getExprs().isEmpty()) continue; // This error should be caught elsewhere. - Expression expr = ASTUtils.asSingleExpr(assignment.getRhs()); - if (expr instanceof ParameterReference) { - // Check for overflow in the referenced parameter. - overflow = detectOverflow(visited, ((ParameterReference)expr).getParameter()) || overflow; - } else { - // The right-hand side of the assignment is a - // constant; check whether it is too large. - if (isTooLarge(ASTUtils.getLiteralTimeValue(expr))) { - this.overflowingAssignments.add(assignment); - overflow = true; - } - } - } - } + // Iterate over the instantiations of the reactor in which the + // current parameter was found. + Set instantiations = + this.instantiationGraph.getInstantiations((Reactor) current.eContainer()); + for (var instantiation : instantiations) { + // Only visit each instantiation once per deadline to avoid cycles. + if (!visited.contains(instantiation)) { + visited.add(instantiation); + // Find assignments that override the current parameter. + for (var assignment : instantiation.getParameters()) { + if (assignment.getLhs().equals(current)) { + if (assignment.getRhs().getExprs().isEmpty()) + continue; // This error should be caught elsewhere. + Expression expr = ASTUtils.asSingleExpr(assignment.getRhs()); + if (expr instanceof ParameterReference) { + // Check for overflow in the referenced parameter. + overflow = + detectOverflow(visited, ((ParameterReference) expr).getParameter()) || overflow; + } else { + // The right-hand side of the assignment is a + // constant; check whether it is too large. + if (isTooLarge(ASTUtils.getLiteralTimeValue(expr))) { + this.overflowingAssignments.add(assignment); + overflow = true; + } } + } } - return overflow; + } } + return overflow; + } } diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/src/org/lflang/Target.java index 2a0e0e8700..8f08e89fcc 100644 --- a/org.lflang/src/org/lflang/Target.java +++ b/org.lflang/src/org/lflang/Target.java @@ -1,22 +1,19 @@ /* Static information about targets. */ /** - * Copyright (c) 2019, The University of California at Berkeley. - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2019, The University of California at Berkeley. Redistribution and use in source + * and binary forms, with or without modification, are permitted provided that the following + * conditions are met: 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in binary form must + * reproduce the above copyright notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY + * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lflang; @@ -27,574 +24,552 @@ import java.util.List; import java.util.Optional; import java.util.Set; - import org.lflang.lf.TargetDecl; -/** - * Enumeration of targets and their associated properties. These classes are - * written in Java, not Xtend, because the enum implementation in Xtend more - * primitive. It is safer to use enums rather than string values since it allows - * faulty references to be caught at compile time. Switch statements that take - * as input an enum but do not have cases for all members of the enum are also +/** + * Enumeration of targets and their associated properties. These classes are written in Java, not + * Xtend, because the enum implementation in Xtend more primitive. It is safer to use enums rather + * than string values since it allows faulty references to be caught at compile time. Switch + * statements that take as input an enum but do not have cases for all members of the enum are also * reported by Xtend with a warning message. - * + * * @author Marten Lohstroh */ public enum Target { - C("C", true, Arrays.asList( - // List via: https://en.cppreference.com/w/c/keyword - "auto", - "break", - "case", - "char", - "const", - "continue", - "default", - "do", - "double", - "else", - "enum", - "extern", - "float", - "for", - "goto", - "if", - "inline", // (since C99) - "int", - "long", - "register", - "restrict", // (since C99) - "return", - "short", - "signed", - "sizeof", - "static", - "struct", - "switch", - "typedef", - "union", - "unsigned", - "void", - "volatile", - "while", - "_Alignas", // (since C11) - "_Alignof", // (since C11) - "_Atomic", // (since C11) - "_Bool", // (since C99) - "_Complex", // (since C99) - "_Generic", // (since C11) - "_Imaginary", // (since C99) - "_Noreturn", // (since C11) - "_Static_assert", // (since C11) - "_Thread_local" // (since C11) - ) - ), - CCPP("CCpp", true, Target.C.keywords), - CPP("Cpp", true, "cpp", "Cpp", Arrays.asList( - // List via: https://en.cppreference.com/w/cpp/keyword - "alignas", // (since C++11) - "alignof", // (since C++11) - "and", - "and_eq", - "asm", - "atomic_cancel", // (TM TS) - "atomic_commit", // (TM TS) - "atomic_noexcept", // (TM TS) - "auto(1)", - "bitand", - "bitor", - "bool", - "break", - "case", - "catch", - "char", - "char8_t", // (since C++20) - "char16_t", // (since C++11) - "char32_t", // (since C++11) - "class(1)", - "compl", - "concept", // (since C++20) - "const", - "consteval", // (since C++20) - "constexpr", // (since C++11) - "constinit", // (since C++20) - "const_cast", - "continue", - "co_await", // (since C++20) - "co_return", // (since C++20) - "co_yield", // (since C++20) - "decltype", // (since C++11) - "default(1)", - "delete(1)", - "do", - "double", - "dynamic_cast", - "else", - "enum", - "explicit", - "export(1)(3)", - "extern(1)", - "false", - "float", - "for", - "friend", - "goto", - "if", - "inline(1)", - "int", - "long", - "mutable(1)", - "namespace", - "new", - "noexcept", // (since C++11) - "not", - "not_eq", - "nullptr", // (since C++11) - "operator", - "or", - "or_eq", - "private", - "protected", - "public", - "reflexpr", // (reflection TS) - "register(2)", - "reinterpret_cast", - "requires", // (since C++20) - "return", - "short", - "signed", - "sizeof(1)", - "static", - "static_assert", // (since C++11) - "static_cast", - "struct(1)", - "switch", - "synchronized", // (TM TS) - "template", - "this", - "thread_local", // (since C++11) - "throw", - "true", - "try", - "typedef", - "typeid", - "typename", - "union", - "unsigned", - "using(1)", - "virtual", - "void", - "volatile", - "wchar_t", - "while", - "xor", - "xor_eq" - ) - ), - TS("TypeScript", false, "ts", "TS", Arrays.asList( - // List via: https://github.com/Microsoft/TypeScript/issues/2536 - // Reserved words - "break", - "case", - "catch", - "class", - "const", - "continue", - "debugger", - "default", - "delete", - "do", - "else", - "enum", - "export", - "extends", - "false", - "finally", - "for", - "function", - "if", - "import", - "in", - "instanceof", - "new", - "null", - "return", - "super", - "switch", - "this", - "throw", - "true", - "try", - "typeof", - "var", - "void", - "while", - "with", - - // Strict Mode Reserved Words - "as", - "implements", - "interface", - "let", - "package", - "private", - "protected", - "public", - "static", - "yield", - - // Contextual Keywords - "any", - "boolean", - "constructor", - "declare", - "get", - "module", - "require", - "number", - "set", - "string", - "symbol", - "type", - "from", - "of", - - // Reactor-TS specific keywords (other classes, which are less user-facing, have double underscores) - "TimeUnit", - "TimeValue", - "Present", - "Sched", - "Read", - "Write", - "ReadWrite" - ) - ), - Python("Python", false, Arrays.asList( - // List via: https://www.w3schools.com/python/python_ref_keywords.asp - // and https://en.cppreference.com/w/c/keyword (due to reliance on the C lib). - "and", - "as", - "assert", - "auto", - "break", - "case", - "char", - "class", - "const", - "continue", - "def", - "default", - "del", - "do", - "double", - "elif", - "else", - "enum", - "except", - "extern", - "False", - "finally", - "float", - "for", - "from", - "global", - "goto", - "if", - "import", - "inline", // (since C99) - "int", - "in", - "is", - "lambda", - "long", - "None", - "nonlocal", - "not", - "or", - "pass", - "raise", - "register", - "restrict", // (since C99) - "return", - "short", - "signed", - "sizeof", - "static", - "struct", - "switch", - "True", - "try", - "typedef", - "union", - "unsigned", - "void", - "volatile", - "while", - "with", - "yield", - "_Alignas", // (since C11) - "_Alignof", // (since C11) - "_Atomic", // (since C11) - "_Bool", // (since C99) - "_Complex", // (since C99) - "_Generic", // (since C11) - "_Imaginary", // (since C99) - "_Noreturn", // (since C11) - "_Static_assert", // (since C11) - "_Thread_local" // (since C11) - ) - ), - Rust("Rust", true, - "rust", "Rust", - // In our Rust implementation, the only reserved keywords - // are those that are a valid expression. Others may be escaped - // with the syntax r#keyword. - Arrays.asList("self", "true", "false") - ); - - /** - * String representation of this target. - */ - private final String displayName; - - /** - * Name of package containing Kotlin classes for the target language. - */ - public final String packageName; - - /** - * Prefix of names of Kotlin classes for the target language. - */ - public final String classNamePrefix; - - /** - * Whether or not this target requires types. - */ - public final boolean requiresTypes; - - /** - * Reserved words in the target language. - */ - public final Set keywords; - - /** - *An unmodifiable list of all known targets. - */ - public static final List ALL = List.of(Target.values()); - - /** - * Private constructor for targets. - * - * @param displayName String representation of this target. - * @param requiresTypes Types Whether this target requires type annotations or not. - * @param packageName Name of package containing Kotlin classes for the target language. - * @param classNamePrefix Prefix of names of Kotlin classes for the target language. - * @param keywords List of reserved strings in the target language. - */ - Target(String displayName, boolean requiresTypes, String packageName, - String classNamePrefix, Collection keywords) { - this.displayName = displayName; - this.requiresTypes = requiresTypes; - this.keywords = Collections.unmodifiableSet(new LinkedHashSet<>(keywords)); - this.packageName = packageName; - this.classNamePrefix = classNamePrefix; - } - - - /** - * Private constructor for targets without packageName and classNamePrefix. - */ - Target(String displayName, boolean requiresTypes, Collection keywords) { - this(displayName, requiresTypes, "N/A", "N/A", keywords); // FIXME: prefix - } - - - /** - * Return the target whose {@linkplain #getDisplayName() display name} - * is the given string (modulo character case), or an empty - * optional if there is no such target. - */ - public static Optional forName(String name) { - return Arrays.stream(Target.values()) - .filter(it -> it.getDisplayName().equalsIgnoreCase(name)) - .findFirst(); - } - - /** - * Return the display name of the target, as it should be - * written in LF code. This is hence a single identifier. - * Eg for {@link #CPP} returns {@code "Cpp"}, for {@link #Python} - * returns {@code "Python"}. Avoid using either {@link #name()} - * or {@link #toString()}, which have unrelated contracts. - */ - public String getDisplayName() { - return displayName; - } - - /** - * Returns the conventional directory name for this target. - * This is used to divide e.g. the {@code test} and {@code example} - * directories by target language. For instance, {@code test/Cpp} - * is the path of {@link #CPP}'s test directory, and this - * method returns {@code "Cpp"}. - */ - public String getDirectoryName() { - return displayName; - } - - /** - * Return the description. Avoid depending on this, toString - * is supposed to be debug information. Prefer {@link #getDisplayName()}. - */ - @Override - public String toString() { - return displayName; - } - - /** - * Returns whether the given identifier is invalid as the - * name of an LF construct. This usually means that the identifier - * is a keyword in the target language. In Rust, many - * keywords may be escaped with the syntax {@code r#keyword}, - * and they are considered valid identifiers. - */ - public boolean isReservedIdent(String ident) { - return this.keywords.contains(ident); - } - - /** - * Return true if the target supports federated execution. - */ - public boolean supportsFederated() { - return switch (this) { - case C, CCPP, Python, TS -> true; - default -> false; - }; - } - - /** - * Return true if the target supports reactor inheritance (extends keyword). - */ - public boolean supportsInheritance() { - return switch (this) { - case C, CCPP, Python -> true; - default -> false; - }; - } - - /** - * Return true if the target supports multiports and banks - * of reactors. - */ - public boolean supportsMultiports() { - switch (this) { - case C: - case CCPP: - case CPP: - case Python: - case Rust: - case TS: - return true; - } - return false; - } - - - /** - * Return true if the target supports widths of banks and - * multiports that depend on reactor parameters (not only - * on constants). - */ - public boolean supportsParameterizedWidths() { + C( + "C", + true, + Arrays.asList( + // List via: https://en.cppreference.com/w/c/keyword + "auto", + "break", + "case", + "char", + "const", + "continue", + "default", + "do", + "double", + "else", + "enum", + "extern", + "float", + "for", + "goto", + "if", + "inline", // (since C99) + "int", + "long", + "register", + "restrict", // (since C99) + "return", + "short", + "signed", + "sizeof", + "static", + "struct", + "switch", + "typedef", + "union", + "unsigned", + "void", + "volatile", + "while", + "_Alignas", // (since C11) + "_Alignof", // (since C11) + "_Atomic", // (since C11) + "_Bool", // (since C99) + "_Complex", // (since C99) + "_Generic", // (since C11) + "_Imaginary", // (since C99) + "_Noreturn", // (since C11) + "_Static_assert", // (since C11) + "_Thread_local" // (since C11) + )), + CCPP("CCpp", true, Target.C.keywords), + CPP( + "Cpp", + true, + "cpp", + "Cpp", + Arrays.asList( + // List via: https://en.cppreference.com/w/cpp/keyword + "alignas", // (since C++11) + "alignof", // (since C++11) + "and", + "and_eq", + "asm", + "atomic_cancel", // (TM TS) + "atomic_commit", // (TM TS) + "atomic_noexcept", // (TM TS) + "auto(1)", + "bitand", + "bitor", + "bool", + "break", + "case", + "catch", + "char", + "char8_t", // (since C++20) + "char16_t", // (since C++11) + "char32_t", // (since C++11) + "class(1)", + "compl", + "concept", // (since C++20) + "const", + "consteval", // (since C++20) + "constexpr", // (since C++11) + "constinit", // (since C++20) + "const_cast", + "continue", + "co_await", // (since C++20) + "co_return", // (since C++20) + "co_yield", // (since C++20) + "decltype", // (since C++11) + "default(1)", + "delete(1)", + "do", + "double", + "dynamic_cast", + "else", + "enum", + "explicit", + "export(1)(3)", + "extern(1)", + "false", + "float", + "for", + "friend", + "goto", + "if", + "inline(1)", + "int", + "long", + "mutable(1)", + "namespace", + "new", + "noexcept", // (since C++11) + "not", + "not_eq", + "nullptr", // (since C++11) + "operator", + "or", + "or_eq", + "private", + "protected", + "public", + "reflexpr", // (reflection TS) + "register(2)", + "reinterpret_cast", + "requires", // (since C++20) + "return", + "short", + "signed", + "sizeof(1)", + "static", + "static_assert", // (since C++11) + "static_cast", + "struct(1)", + "switch", + "synchronized", // (TM TS) + "template", + "this", + "thread_local", // (since C++11) + "throw", + "true", + "try", + "typedef", + "typeid", + "typename", + "union", + "unsigned", + "using(1)", + "virtual", + "void", + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq")), + TS( + "TypeScript", + false, + "ts", + "TS", + Arrays.asList( + // List via: https://github.com/Microsoft/TypeScript/issues/2536 + // Reserved words + "break", + "case", + "catch", + "class", + "const", + "continue", + "debugger", + "default", + "delete", + "do", + "else", + "enum", + "export", + "extends", + "false", + "finally", + "for", + "function", + "if", + "import", + "in", + "instanceof", + "new", + "null", + "return", + "super", + "switch", + "this", + "throw", + "true", + "try", + "typeof", + "var", + "void", + "while", + "with", + + // Strict Mode Reserved Words + "as", + "implements", + "interface", + "let", + "package", + "private", + "protected", + "public", + "static", + "yield", + + // Contextual Keywords + "any", + "boolean", + "constructor", + "declare", + "get", + "module", + "require", + "number", + "set", + "string", + "symbol", + "type", + "from", + "of", + + // Reactor-TS specific keywords (other classes, which are less user-facing, have double + // underscores) + "TimeUnit", + "TimeValue", + "Present", + "Sched", + "Read", + "Write", + "ReadWrite")), + Python( + "Python", + false, + Arrays.asList( + // List via: https://www.w3schools.com/python/python_ref_keywords.asp + // and https://en.cppreference.com/w/c/keyword (due to reliance on the C lib). + "and", + "as", + "assert", + "auto", + "break", + "case", + "char", + "class", + "const", + "continue", + "def", + "default", + "del", + "do", + "double", + "elif", + "else", + "enum", + "except", + "extern", + "False", + "finally", + "float", + "for", + "from", + "global", + "goto", + "if", + "import", + "inline", // (since C99) + "int", + "in", + "is", + "lambda", + "long", + "None", + "nonlocal", + "not", + "or", + "pass", + "raise", + "register", + "restrict", // (since C99) + "return", + "short", + "signed", + "sizeof", + "static", + "struct", + "switch", + "True", + "try", + "typedef", + "union", + "unsigned", + "void", + "volatile", + "while", + "with", + "yield", + "_Alignas", // (since C11) + "_Alignof", // (since C11) + "_Atomic", // (since C11) + "_Bool", // (since C99) + "_Complex", // (since C99) + "_Generic", // (since C11) + "_Imaginary", // (since C99) + "_Noreturn", // (since C11) + "_Static_assert", // (since C11) + "_Thread_local" // (since C11) + )), + Rust( + "Rust", + true, + "rust", + "Rust", + // In our Rust implementation, the only reserved keywords + // are those that are a valid expression. Others may be escaped + // with the syntax r#keyword. + Arrays.asList("self", "true", "false")); + + /** String representation of this target. */ + private final String displayName; + + /** Name of package containing Kotlin classes for the target language. */ + public final String packageName; + + /** Prefix of names of Kotlin classes for the target language. */ + public final String classNamePrefix; + + /** Whether or not this target requires types. */ + public final boolean requiresTypes; + + /** Reserved words in the target language. */ + public final Set keywords; + + /** An unmodifiable list of all known targets. */ + public static final List ALL = List.of(Target.values()); + + /** + * Private constructor for targets. + * + * @param displayName String representation of this target. + * @param requiresTypes Types Whether this target requires type annotations or not. + * @param packageName Name of package containing Kotlin classes for the target language. + * @param classNamePrefix Prefix of names of Kotlin classes for the target language. + * @param keywords List of reserved strings in the target language. + */ + Target( + String displayName, + boolean requiresTypes, + String packageName, + String classNamePrefix, + Collection keywords) { + this.displayName = displayName; + this.requiresTypes = requiresTypes; + this.keywords = Collections.unmodifiableSet(new LinkedHashSet<>(keywords)); + this.packageName = packageName; + this.classNamePrefix = classNamePrefix; + } + + /** Private constructor for targets without packageName and classNamePrefix. */ + Target(String displayName, boolean requiresTypes, Collection keywords) { + this(displayName, requiresTypes, "N/A", "N/A", keywords); // FIXME: prefix + } + + /** + * Return the target whose {@linkplain #getDisplayName() display name} is the given string (modulo + * character case), or an empty optional if there is no such target. + */ + public static Optional forName(String name) { + return Arrays.stream(Target.values()) + .filter(it -> it.getDisplayName().equalsIgnoreCase(name)) + .findFirst(); + } + + /** + * Return the display name of the target, as it should be written in LF code. This is hence a + * single identifier. Eg for {@link #CPP} returns {@code "Cpp"}, for {@link #Python} returns + * {@code "Python"}. Avoid using either {@link #name()} or {@link #toString()}, which have + * unrelated contracts. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Returns the conventional directory name for this target. This is used to divide e.g. the {@code + * test} and {@code example} directories by target language. For instance, {@code test/Cpp} is the + * path of {@link #CPP}'s test directory, and this method returns {@code "Cpp"}. + */ + public String getDirectoryName() { + return displayName; + } + + /** + * Return the description. Avoid depending on this, toString is supposed to be debug information. + * Prefer {@link #getDisplayName()}. + */ + @Override + public String toString() { + return displayName; + } + + /** + * Returns whether the given identifier is invalid as the name of an LF construct. This usually + * means that the identifier is a keyword in the target language. In Rust, many keywords may be + * escaped with the syntax {@code r#keyword}, and they are considered valid identifiers. + */ + public boolean isReservedIdent(String ident) { + return this.keywords.contains(ident); + } + + /** Return true if the target supports federated execution. */ + public boolean supportsFederated() { + return switch (this) { + case C, CCPP, Python, TS -> true; + default -> false; + }; + } + + /** Return true if the target supports reactor inheritance (extends keyword). */ + public boolean supportsInheritance() { + return switch (this) { + case C, CCPP, Python -> true; + default -> false; + }; + } + + /** Return true if the target supports multiports and banks of reactors. */ + public boolean supportsMultiports() { + switch (this) { + case C: + case CCPP: + case CPP: + case Python: + case Rust: + case TS: return true; } - - /** - * Return true if this code for this target should be built using Docker if Docker is used. - * @return - */ - public boolean buildsUsingDocker() { - return switch (this) { - case TS -> false; - case C, CCPP, CPP, Python, Rust -> true; - }; - } - - /** - * Whether the target requires using an equal sign to assign a default value to a parameter, - * or initialize a state variable. All targets mandate an equal sign when passing - * arguments to a reactor constructor call, regardless of this method. - */ - public boolean mandatesEqualsInitializers() { - return this != CPP; + return false; + } + + /** + * Return true if the target supports widths of banks and multiports that depend on reactor + * parameters (not only on constants). + */ + public boolean supportsParameterizedWidths() { + return true; + } + + /** + * Return true if this code for this target should be built using Docker if Docker is used. + * + * @return + */ + public boolean buildsUsingDocker() { + return switch (this) { + case TS -> false; + case C, CCPP, CPP, Python, Rust -> true; + }; + } + + /** + * Whether the target requires using an equal sign to assign a default value to a parameter, or + * initialize a state variable. All targets mandate an equal sign when passing arguments to a + * reactor constructor call, regardless of this method. + */ + public boolean mandatesEqualsInitializers() { + return this != CPP; + } + + /** Allow expressions of the form {@code {a, b, c}}. */ + public boolean allowsBracedListExpressions() { + return this == C || this == CCPP || this == CPP; + } + + /** Return a string that demarcates the beginning of a single-line comment. */ + public String getSingleLineCommentPrefix() { + return this.equals(Target.Python) ? "#" : "//"; + } + + /** + * Return true if the keepalive option is set automatically for this target if physical actions + * are detected in the program (and keepalive was not explicitly unset by the user). + */ + public boolean setsKeepAliveOptionAutomatically() { + return this != Rust && this != CPP; + } + + /** + * Given a string and a list of candidate objects, return the first candidate that matches, or + * null if no candidate matches. + * + *

    todo move to CollectionUtil (introduced in #442) + * + * @param string The string to match against candidates. + * @param candidates The candidates to match the string against. + */ + public static T match(final String string, final Iterable candidates) { + // kotlin: candidates.firstOrNull { it.toString().equalsIgnoreCase(string) } + for (T candidate : candidates) { + if (candidate.toString().equalsIgnoreCase(string)) { + return candidate; + } } - - /** Allow expressions of the form {@code {a, b, c}}. */ - public boolean allowsBracedListExpressions() { - return this == C || this == CCPP || this == CPP; - } - - /** - * Return a string that demarcates the beginning of a single-line comment. - */ - public String getSingleLineCommentPrefix() { - return this.equals(Target.Python) ? "#" : "//"; - } - - /** - * Return true if the keepalive option is set automatically - * for this target if physical actions are detected in the - * program (and keepalive was not explicitly unset by the user). - */ - public boolean setsKeepAliveOptionAutomatically() { - return this != Rust && this != CPP; - } - - /** - * Given a string and a list of candidate objects, return the first - * candidate that matches, or null if no candidate matches. - * - * todo move to CollectionUtil (introduced in #442) - * - * @param string The string to match against candidates. - * @param candidates The candidates to match the string against. - */ - public static T match(final String string, final Iterable candidates) { - // kotlin: candidates.firstOrNull { it.toString().equalsIgnoreCase(string) } - for (T candidate : candidates) { - if (candidate.toString().equalsIgnoreCase(string)) { - return candidate; - } - } - return null; - } - - - /** - * Given a string and a list of candidate objects, return the first - * candidate that matches, or null if no candidate matches. - * - * todo move to CollectionUtil (introduced in #442) - * - * @param string The string to match against candidates. - * @param candidates The candidates to match the string against. - */ - public static T match(final String string, final T[] candidates) { - return match(string, Arrays.asList(candidates)); - } - - - /** - * Return the target constant corresponding to given target - * declaration among. Return a non-null result, will throw - * if invalid. - * - * @throws RuntimeException If no {@link TargetDecl} is present or if it is invalid. - */ - public static Target fromDecl(TargetDecl targetDecl) { - String name = targetDecl.getName(); - return Target.forName(name) - .orElseThrow(() -> new RuntimeException("Invalid target name '" + name + "'")); - } - + return null; + } + + /** + * Given a string and a list of candidate objects, return the first candidate that matches, or + * null if no candidate matches. + * + *

    todo move to CollectionUtil (introduced in #442) + * + * @param string The string to match against candidates. + * @param candidates The candidates to match the string against. + */ + public static T match(final String string, final T[] candidates) { + return match(string, Arrays.asList(candidates)); + } + + /** + * Return the target constant corresponding to given target declaration among. Return a non-null + * result, will throw if invalid. + * + * @throws RuntimeException If no {@link TargetDecl} is present or if it is invalid. + */ + public static Target fromDecl(TargetDecl targetDecl) { + String name = targetDecl.getName(); + return Target.forName(name) + .orElseThrow(() -> new RuntimeException("Invalid target name '" + name + "'")); + } } diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 84770be5d1..c4794b4b1a 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -1,27 +1,27 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; import java.util.ArrayList; @@ -32,7 +32,6 @@ import java.util.Objects; import java.util.Properties; import java.util.Set; - import org.lflang.TargetProperty.BuildType; import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.TargetProperty.CoordinationType; @@ -48,453 +47,376 @@ /** * A class for keeping the current target configuration. * - * Class members of type String are initialized as empty strings, - * unless otherwise stated. + *

    Class members of type String are initialized as empty strings, unless otherwise stated. + * * @author Marten Lohstroh */ public class TargetConfig { - /** - * The target of this configuration (e.g., C, TypeScript, Python). - */ - public final Target target; - - /** - * Create a new target configuration based on the given target declaration AST node only. - * @param target AST node of a target declaration. - */ - public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can - this.target = Target.fromDecl(target); + /** The target of this configuration (e.g., C, TypeScript, Python). */ + public final Target target; + + /** + * Create a new target configuration based on the given target declaration AST node only. + * + * @param target AST node of a target declaration. + */ + public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can + this.target = Target.fromDecl(target); + } + + /** + * Create a new target configuration based on the given commandline arguments and target + * declaration AST node. + * + * @param cliArgs Arguments passed on the commandline. + * @param target AST node of a target declaration. + * @param errorReporter An error reporter to report problems. + */ + public TargetConfig(Properties cliArgs, TargetDecl target, ErrorReporter errorReporter) { + this(target); + if (target.getConfig() != null) { + List pairs = target.getConfig().getPairs(); + TargetProperty.set(this, pairs != null ? pairs : List.of(), errorReporter); } - - /** - * Create a new target configuration based on the given commandline arguments and target - * declaration AST node. - * @param cliArgs Arguments passed on the commandline. - * @param target AST node of a target declaration. - * @param errorReporter An error reporter to report problems. - */ - public TargetConfig( - Properties cliArgs, - TargetDecl target, - ErrorReporter errorReporter - ) { - this(target); - if (target.getConfig() != null) { - List pairs = target.getConfig().getPairs(); - TargetProperty.set(this, pairs != null ? pairs : List.of(), errorReporter); - } - if (cliArgs.containsKey("no-compile")) { - this.noCompile = true; - } - if (cliArgs.containsKey("docker")) { - var arg = cliArgs.getProperty("docker"); - if (Boolean.parseBoolean(arg)) { - this.dockerOptions = new DockerOptions(); - } else { - this.dockerOptions = null; - } - // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. - } - if (cliArgs.containsKey("build-type")) { - this.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); - } - if (cliArgs.containsKey("logging")) { - this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); - } - if (cliArgs.containsKey("workers")) { - this.workers = Integer.parseInt(cliArgs.getProperty("workers")); - } - if (cliArgs.containsKey("threading")) { - this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); - } - if (cliArgs.containsKey("target-compiler")) { - this.compiler = cliArgs.getProperty("target-compiler"); - } - if (cliArgs.containsKey("tracing")) { - this.tracing = new TracingOptions(); - } - if (cliArgs.containsKey("scheduler")) { - this.schedulerType = SchedulerOption.valueOf( - cliArgs.getProperty("scheduler") - ); - this.setByUser.add(TargetProperty.SCHEDULER); - } - if (cliArgs.containsKey("target-flags")) { - this.compilerFlags.clear(); - if (!cliArgs.getProperty("target-flags").isEmpty()) { - this.compilerFlags.addAll(List.of( - cliArgs.getProperty("target-flags").split(" ") - )); - } - } - if (cliArgs.containsKey("runtime-version")) { - this.runtimeVersion = cliArgs.getProperty("runtime-version"); - } - if (cliArgs.containsKey("external-runtime-path")) { - this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); - } - if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { - this.keepalive = Boolean.parseBoolean( - cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); - } - if (cliArgs.containsKey(BuildParm.PRINT_STATISTICS.getKey())) { - this.printStatistics = true; - } + if (cliArgs.containsKey("no-compile")) { + this.noCompile = true; + } + if (cliArgs.containsKey("docker")) { + var arg = cliArgs.getProperty("docker"); + if (Boolean.parseBoolean(arg)) { + this.dockerOptions = new DockerOptions(); + } else { + this.dockerOptions = null; + } + // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. + } + if (cliArgs.containsKey("build-type")) { + this.cmakeBuildType = + (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); + } + if (cliArgs.containsKey("logging")) { + this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); + } + if (cliArgs.containsKey("workers")) { + this.workers = Integer.parseInt(cliArgs.getProperty("workers")); + } + if (cliArgs.containsKey("threading")) { + this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); + } + if (cliArgs.containsKey("target-compiler")) { + this.compiler = cliArgs.getProperty("target-compiler"); + } + if (cliArgs.containsKey("tracing")) { + this.tracing = new TracingOptions(); + } + if (cliArgs.containsKey("scheduler")) { + this.schedulerType = SchedulerOption.valueOf(cliArgs.getProperty("scheduler")); + this.setByUser.add(TargetProperty.SCHEDULER); + } + if (cliArgs.containsKey("target-flags")) { + this.compilerFlags.clear(); + if (!cliArgs.getProperty("target-flags").isEmpty()) { + this.compilerFlags.addAll(List.of(cliArgs.getProperty("target-flags").split(" "))); + } + } + if (cliArgs.containsKey("runtime-version")) { + this.runtimeVersion = cliArgs.getProperty("runtime-version"); + } + if (cliArgs.containsKey("external-runtime-path")) { + this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); + } + if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { + this.keepalive = + Boolean.parseBoolean(cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); } + if (cliArgs.containsKey(BuildParm.PRINT_STATISTICS.getKey())) { + this.printStatistics = true; + } + } - /** - * Keep track of every target property that is explicitly set by the user. - */ - public Set setByUser = new HashSet<>(); + /** Keep track of every target property that is explicitly set by the user. */ + public Set setByUser = new HashSet<>(); - /** - * A list of custom build commands that replace the default build process of - * directly invoking a designated compiler. A common usage of this target - * property is to set the command to build on the basis of a Makefile. - */ - public List buildCommands = new ArrayList<>(); + /** + * A list of custom build commands that replace the default build process of directly invoking a + * designated compiler. A common usage of this target property is to set the command to build on + * the basis of a Makefile. + */ + public List buildCommands = new ArrayList<>(); - /** - * The mode of clock synchronization to be used in federated programs. - * The default is 'initial'. - */ - public ClockSyncMode clockSync = ClockSyncMode.INIT; + /** + * The mode of clock synchronization to be used in federated programs. The default is 'initial'. + */ + public ClockSyncMode clockSync = ClockSyncMode.INIT; - /** - * Clock sync options. - */ - public ClockSyncOptions clockSyncOptions = new ClockSyncOptions(); + /** Clock sync options. */ + public ClockSyncOptions clockSyncOptions = new ClockSyncOptions(); - /** - * Parameter passed to cmake. The default is 'Release'. - */ - public BuildType cmakeBuildType = BuildType.RELEASE; + /** Parameter passed to cmake. The default is 'Release'. */ + public BuildType cmakeBuildType = BuildType.RELEASE; - /** - * Optional additional extensions to include in the generated CMakeLists.txt. - */ - public List cmakeIncludes = new ArrayList<>(); + /** Optional additional extensions to include in the generated CMakeLists.txt. */ + public List cmakeIncludes = new ArrayList<>(); - /** - * The compiler to invoke, unless a build command has been specified. - */ - public String compiler = ""; + /** The compiler to invoke, unless a build command has been specified. */ + public String compiler = ""; - /** - * Additional sources to add to the compile command if appropriate. - */ - public List compileAdditionalSources = new ArrayList<>(); + /** Additional sources to add to the compile command if appropriate. */ + public List compileAdditionalSources = new ArrayList<>(); - /** - * Additional (preprocessor) definitions to add to the compile command if appropriate. - * - * The first string is the definition itself, and the second string is the value to attribute to that definition, if any. - * The second value could be left empty. - */ - public Map compileDefinitions = new HashMap<>(); + /** + * Additional (preprocessor) definitions to add to the compile command if appropriate. + * + *

    The first string is the definition itself, and the second string is the value to attribute + * to that definition, if any. The second value could be left empty. + */ + public Map compileDefinitions = new HashMap<>(); - /** - * Additional libraries to add to the compile command using the "-l" command-line option. - */ - public List compileLibraries = new ArrayList<>(); + /** Additional libraries to add to the compile command using the "-l" command-line option. */ + public List compileLibraries = new ArrayList<>(); - /** - * Flags to pass to the compiler, unless a build command has been specified. - */ - public List compilerFlags = new ArrayList<>(); + /** Flags to pass to the compiler, unless a build command has been specified. */ + public List compilerFlags = new ArrayList<>(); - /** - * The type of coordination used during the execution of a federated program. - * The default is 'centralized'. - */ - public CoordinationType coordination = CoordinationType.CENTRALIZED; + /** + * The type of coordination used during the execution of a federated program. The default is + * 'centralized'. + */ + public CoordinationType coordination = CoordinationType.CENTRALIZED; + + /** Docker options. */ + public DockerOptions dockerOptions = null; - /** - * Docker options. - */ - public DockerOptions dockerOptions = null; + /** Coordination options. */ + public CoordinationOptions coordinationOptions = new CoordinationOptions(); - /** - * Coordination options. - */ - public CoordinationOptions coordinationOptions = new CoordinationOptions(); + /** Link to an external runtime library instead of the default one. */ + public String externalRuntimePath = null; - /** - * Link to an external runtime library instead of the default one. - */ - public String externalRuntimePath = null; + /** + * If true, configure the execution environment such that it does not wait for physical time to + * match logical time. The default is false. + */ + public boolean fastMode = false; - /** - * If true, configure the execution environment such that it does not - * wait for physical time to match logical time. The default is false. - */ - public boolean fastMode = false; + /** List of files to be copied to src-gen. */ + public List files = new ArrayList<>(); - /** - * List of files to be copied to src-gen. - */ - public List files = new ArrayList<>(); + /** + * If true, configure the execution environment to keep executing if there are no more events on + * the event queue. The default is false. + */ + public boolean keepalive = false; - /** - * If true, configure the execution environment to keep executing if there - * are no more events on the event queue. The default is false. - */ - public boolean keepalive = false; + /** The level of logging during execution. The default is INFO. */ + public LogLevel logLevel = LogLevel.INFO; - /** - * The level of logging during execution. The default is INFO. - */ - public LogLevel logLevel = LogLevel.INFO; + /** Flags to pass to the linker, unless a build command has been specified. */ + public String linkerFlags = ""; - /** - * Flags to pass to the linker, unless a build command has been specified. - */ - public String linkerFlags = ""; + /** If true, do not invoke the target compiler or build command. The default is false. */ + public boolean noCompile = false; - /** - * If true, do not invoke the target compiler or build command. - * The default is false. - */ - public boolean noCompile = false; + /** If true, do not perform runtime validation. The default is false. */ + public boolean noRuntimeValidation = false; - /** - * If true, do not perform runtime validation. The default is false. - */ - public boolean noRuntimeValidation = false; + /** + * Set the target platform config. This tells the build system what platform-specific support + * files it needs to incorporate at compile time. + * + *

    This is now a wrapped class to account for overloaded definitions of defining platform + * (either a string or dictionary of values) + */ + public PlatformOptions platformOptions = new PlatformOptions(); - /** - * Set the target platform config. - * This tells the build system what platform-specific support - * files it needs to incorporate at compile time. - * - * This is now a wrapped class to account for overloaded definitions - * of defining platform (either a string or dictionary of values) - */ - public PlatformOptions platformOptions = new PlatformOptions(); + /** If true, instruct the runtime to collect and print execution statistics. */ + public boolean printStatistics = false; - /** - * If true, instruct the runtime to collect and print execution statistics. - */ - public boolean printStatistics = false; + /** List of proto files to be processed by the code generator. */ + public List protoFiles = new ArrayList<>(); - /** - * List of proto files to be processed by the code generator. - */ - public List protoFiles = new ArrayList<>(); + /** If true, generate ROS2 specific code. */ + public boolean ros2 = false; - /** - * If true, generate ROS2 specific code. - */ - public boolean ros2 = false; + /** Additional ROS2 packages that the LF program depends on. */ + public List ros2Dependencies = null; - /** - * Additional ROS2 packages that the LF program depends on. - */ - public List ros2Dependencies = null; + /** The version of the runtime library to be used in the generated target. */ + public String runtimeVersion = null; - /** - * The version of the runtime library to be used in the generated target. - */ - public String runtimeVersion = null; + /** Whether all reactors are to be generated into a single target language file. */ + public boolean singleFileProject = false; + + /** What runtime scheduler to use. */ + public SchedulerOption schedulerType = SchedulerOption.getDefault(); + + /** + * The number of worker threads to deploy. The default is zero, which indicates that the runtime + * is allowed to freely choose the number of workers. + */ + public int workers = 0; + + /** Indicate whether HMAC authentication is used. */ + public boolean auth = false; + + /** Indicate whether the runtime should use multithreaded execution. */ + public boolean threading = true; + + /** The timeout to be observed during execution of the program. */ + public TimeValue timeout; + + /** If non-null, configure the runtime environment to perform tracing. The default is null. */ + public TracingOptions tracing = null; + + /** + * If true, the resulting binary will output a graph visualizing all reaction dependencies. + * + *

    This option is currently only used for C++ and Rust. This export function is a valuable tool + * for debugging LF programs and helps to understand the dependencies inferred by the runtime. + */ + public boolean exportDependencyGraph = false; - /** Whether all reactors are to be generated into a single target language file. */ - public boolean singleFileProject = false; + /** + * If true, the resulting binary will output a yaml file describing the whole reactor structure of + * the program. + * + *

    This option is currently only used for C++. This export function is a valuable tool for + * debugging LF programs and performing external analysis. + */ + public boolean exportToYaml = false; - /** What runtime scheduler to use. */ - public SchedulerOption schedulerType = SchedulerOption.getDefault(); + /** Rust-specific configuration. */ + public final RustTargetConfig rust = + new RustTargetConfig(); // FIXME: https://issue.lf-lang.org/1558 + + /** Path to a C file used by the Python target to setup federated execution. */ + public String fedSetupPreamble = null; // FIXME: https://issue.lf-lang.org/1558 + + /** Settings related to clock synchronization. */ + public static class ClockSyncOptions { /** - * The number of worker threads to deploy. The default is zero, which indicates that - * the runtime is allowed to freely choose the number of workers. + * Dampen the adjustments to the clock synchronization offset by this rate. The default is 10. */ - public int workers = 0; + public int attenuation = 10; /** - * Indicate whether HMAC authentication is used. + * Whether to collect statistics while performing clock synchronization. This setting is only + * considered when clock synchronization has been activated. The default is true. */ - public boolean auth = false; + public boolean collectStats = true; + + /** Enable clock synchronization for federates on the same machine. Default is false. */ + public boolean localFederatesOn = false; /** - * Indicate whether the runtime should use multithreaded execution. + * Interval at which clock synchronization is initiated by the RTI (will be passed to it as an + * argument on the command-line). The default is 5 milliseconds. */ - public boolean threading = true; + public TimeValue period = new TimeValue(5, TimeUnit.MILLI); /** - * The timeout to be observed during execution of the program. + * Indicate the number of exchanges to be had per each clock synchronization round. See + * /lib/core/federated/clock-sync.h for more details. The default is 10. */ - public TimeValue timeout; + public int trials = 10; /** - * If non-null, configure the runtime environment to perform tracing. - * The default is null. + * Used to create an artificial clock synchronization error for the purpose of testing. The + * default is null. */ - public TracingOptions tracing = null; + public TimeValue testOffset; + } + /** Settings related to coordination of federated execution. */ + public static class CoordinationOptions { /** - * If true, the resulting binary will output a graph visualizing all reaction dependencies. - * - * This option is currently only used for C++ and Rust. This export function is a valuable tool - * for debugging LF programs and helps to understand the dependencies inferred by the runtime. + * For centralized coordination, if a federate has a physical action that can trigger an output, + * directly or indirectly, then it will send NET (next event tag) messages to the RTI + * periodically as its physical clock advances. This option sets the amount of time to wait + * between sending such messages. Increasing this value results in downstream federates that lag + * further behind physical time (if the "after" delays are insufficient). The default is null, + * which means it is up the implementation to choose an interval. */ - public boolean exportDependencyGraph = false; - + public TimeValue advance_message_interval = null; + } + /** Settings related to Docker options. */ + public static class DockerOptions { /** - * If true, the resulting binary will output a yaml file describing the whole reactor structure - * of the program. - * - * This option is currently only used for C++. This export function is a valuable tool for debugging - * LF programs and performing external analysis. + * The base image and tag from which to build the Docker image. The default is "alpine:latest". */ - public boolean exportToYaml = false; + public String from = "alpine:latest"; - /** Rust-specific configuration. */ - public final RustTargetConfig rust = new RustTargetConfig(); // FIXME: https://issue.lf-lang.org/1558 + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DockerOptions that = (DockerOptions) o; + return from.equals(that.from); + } + } - /** Path to a C file used by the Python target to setup federated execution. */ - public String fedSetupPreamble = null; // FIXME: https://issue.lf-lang.org/1558 + /** Settings related to Platform Options. */ + public static class PlatformOptions { /** - * Settings related to clock synchronization. + * The base platform we build our LF Files on. Should be set to AUTO by default unless + * developing for specific OS/Embedded Platform */ - public static class ClockSyncOptions { - - /** - * Dampen the adjustments to the clock synchronization offset by this rate. - * The default is 10. - */ - public int attenuation = 10; - - /** - * Whether to collect statistics while performing clock synchronization. - * This setting is only considered when clock synchronization has been activated. - * The default is true. - */ - public boolean collectStats = true; - - /** - * Enable clock synchronization for federates on the same machine. - * Default is false. - */ - public boolean localFederatesOn = false; - - - /** - * Interval at which clock synchronization is initiated by the RTI (will be passed - * to it as an argument on the command-line). - * The default is 5 milliseconds. - */ - public TimeValue period = new TimeValue(5, TimeUnit.MILLI); - - /** - * Indicate the number of exchanges to be had per each clock synchronization round. - * See /lib/core/federated/clock-sync.h for more details. - * The default is 10. - */ - public int trials = 10; - - /** - * Used to create an artificial clock synchronization error for the purpose of testing. - * The default is null. - */ - public TimeValue testOffset; - } + public Platform platform = Platform.AUTO; /** - * Settings related to coordination of federated execution. + * The string value used to determine what type of embedded board we work with and can be used + * to simplify the build process. For example, when we want to flash to an Arduino Nano 33 BLE + * board, we can use the string arduino:mbed_nano:nano33ble */ - public static class CoordinationOptions { - - /** - * For centralized coordination, if a federate has a physical action that can trigger - * an output, directly or indirectly, then it will send NET (next event tag) messages - * to the RTI periodically as its physical clock advances. This option sets the amount - * of time to wait between sending such messages. Increasing this value results in - * downstream federates that lag further behind physical time (if the "after" delays - * are insufficient). - * The default is null, which means it is up the implementation to choose an interval. - */ - public TimeValue advance_message_interval = null; - } + public String board = null; /** - * Settings related to Docker options. + * The string value used to determine the port on which to flash the compiled program (i.e. + * /dev/cu.usbmodem21301) */ - public static class DockerOptions { - /** - * The base image and tag from which to build the Docker image. The default is "alpine:latest". - */ - public String from = "alpine:latest"; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - DockerOptions that = (DockerOptions) o; - return from.equals(that.from); - } - } + public String port = null; + + /** + * The baud rate used as a parameter to certain embedded platforms. 9600 is a standard rate + * amongst systems like Arduino, so it's the default value. + */ + public int baudRate = 9600; /** - * Settings related to Platform Options. + * The boolean statement used to determine whether we should automatically attempt to flash once + * we compile. This may require the use of board and port values depending on the infrastructure + * you use to flash the boards. */ - public static class PlatformOptions { - - /** - * The base platform we build our LF Files on. Should be set to AUTO by default unless developing for specific OS/Embedded Platform - */ - public Platform platform = Platform.AUTO; - - /** - * The string value used to determine what type of embedded board we work with and can be used to simplify the build process. For example, - * when we want to flash to an Arduino Nano 33 BLE board, we can use the string arduino:mbed_nano:nano33ble - */ - public String board = null; - - - /** - * The string value used to determine the port on which to flash the compiled program (i.e. /dev/cu.usbmodem21301) - */ - public String port = null; - - /** - * The baud rate used as a parameter to certain embedded platforms. 9600 is a standard rate amongst systems like Arduino, so it's the default value. - */ - public int baudRate = 9600; - - /** - * The boolean statement used to determine whether we should automatically attempt to flash once we compile. This may require the use of board and - * port values depending on the infrastructure you use to flash the boards. - */ - public boolean flash = false; - } + public boolean flash = false; + } + /** Settings related to tracing options. */ + public static class TracingOptions { /** - * Settings related to tracing options. + * The name to use as the root of the trace file produced. This defaults to the name of the .lf + * file. */ - public static class TracingOptions { - /** - * The name to use as the root of the trace file produced. - * This defaults to the name of the .lf file. - */ - public String traceFileName = null; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TracingOptions that = (TracingOptions) o; - return Objects.equals(traceFileName, that.traceFileName); // traceFileName may be null - } + public String traceFileName = null; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TracingOptions that = (TracingOptions) o; + return Objects.equals(traceFileName, that.traceFileName); // traceFileName may be null } + } } diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index fe5c7dd0b2..b3abf815a3 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1,30 +1,31 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; +import com.google.common.collect.ImmutableList; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; @@ -33,7 +34,6 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; - import org.eclipse.xtext.util.RuntimeIOException; import org.lflang.TargetConfig.DockerOptions; import org.lflang.TargetConfig.PlatformOptions; @@ -52,1819 +52,1761 @@ import org.lflang.util.StringUtil; import org.lflang.validation.LFValidator; -import com.google.common.collect.ImmutableList; - /** - * A target properties along with a type and a list of supporting targets - * that supports it, as well as a function for configuration updates. + * A target properties along with a type and a list of supporting targets that supports it, as well + * as a function for configuration updates. * * @author Marten Lohstroh */ public enum TargetProperty { - /** - * Directive to allow including OpenSSL libraries and process HMAC authentication. - */ - AUTH("auth", PrimitiveType.BOOLEAN, - Arrays.asList(Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.auth), - (config, value, err) -> { - config.auth = ASTUtils.toBoolean(value); - }), - /** - * Directive to let the generator use the custom build command. - */ - BUILD("build", UnionType.STRING_OR_STRING_ARRAY, - Arrays.asList(Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.buildCommands), - (config, value, err) -> { - config.buildCommands = ASTUtils.elementToListOfStrings(value); - }), - - /** - * Directive to specify the target build type such as 'Release' or 'Debug'. - * This is also used in the Rust target to select a Cargo profile. - */ - BUILD_TYPE("build-type", UnionType.BUILD_TYPE_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Rust), - (config) -> ASTUtils.toElement(config.cmakeBuildType.toString()), - (config, value, err) -> { - config.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION - .forName(ASTUtils.elementToSingleString(value)); - // set it there too, because the default is different. - config.rust.setBuildType(config.cmakeBuildType); - }), - - /** - * Directive to let the federate execution handle clock synchronization in software. - */ - CLOCK_SYNC("clock-sync", UnionType.CLOCK_SYNC_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.clockSync.toString()), - (config, value, err) -> { - config.clockSync = (ClockSyncMode) UnionType.CLOCK_SYNC_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - /** - * Key-value pairs giving options for clock synchronization. - */ - CLOCK_SYNC_OPTIONS("clock-sync-options", - DictionaryType.CLOCK_SYNC_OPTION_DICT, Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (ClockSyncOption opt : ClockSyncOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case ATTENUATION: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.attenuation)); - break; - case COLLECT_STATS: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.collectStats)); - break; - case LOCAL_FEDERATES_ON: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.localFederatesOn)); - break; - case PERIOD: - if (config.clockSyncOptions.period == null) continue; // don't set if null - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.period)); - break; - case TEST_OFFSET: - if (config.clockSyncOptions.testOffset == null) continue; // don't set if null - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.testOffset)); - break; - case TRIALS: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.trials)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - // kvp will never be empty - return e; - }, - (config, value, err) -> { - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - ClockSyncOption option = (ClockSyncOption) DictionaryType.CLOCK_SYNC_OPTION_DICT - .forName(entry.getName()); - switch (option) { - case ATTENUATION: - config.clockSyncOptions.attenuation = ASTUtils - .toInteger(entry.getValue()); - break; - case COLLECT_STATS: - config.clockSyncOptions.collectStats = ASTUtils - .toBoolean(entry.getValue()); - break; - case LOCAL_FEDERATES_ON: - config.clockSyncOptions.localFederatesOn = ASTUtils - .toBoolean(entry.getValue()); - break; - case PERIOD: - config.clockSyncOptions.period = ASTUtils - .toTimeValue(entry.getValue()); - break; - case TEST_OFFSET: - config.clockSyncOptions.testOffset = ASTUtils - .toTimeValue(entry.getValue()); - break; - case TRIALS: - config.clockSyncOptions.trials = ASTUtils - .toInteger(entry.getValue()); - break; - default: - break; - } - } - }), - - /** - * Directive to specify a cmake to be included by the generated build - * systems. - * - * This gives full control over the C/C++ build as any cmake parameters - * can be adjusted in the included file. - */ - CMAKE_INCLUDE("cmake-include", UnionType.FILE_OR_FILE_ARRAY, - Arrays.asList(Target.CPP, Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.cmakeIncludes), - (config, value, err) -> { - config.cmakeIncludes = ASTUtils.elementToListOfStrings(value); - }, - // FIXME: This merging of lists is potentially dangerous since - // the incoming list of cmake-includes can belong to a .lf file that is - // located in a different location, and keeping just filename - // strings like this without absolute paths is incorrect. - (config, value, err) -> { - config.cmakeIncludes.addAll(ASTUtils.elementToListOfStrings(value)); - }), - /** - * Directive to specify the target compiler. - */ - COMPILER("compiler", PrimitiveType.STRING, Target.ALL, - (config) -> ASTUtils.toElement(config.compiler), - (config, value, err) -> { - config.compiler = ASTUtils.elementToSingleString(value); - }), - - /** - * Directive to specify compile-time definitions. - */ - COMPILE_DEFINITIONS("compile-definitions", StringDictionaryType.COMPILE_DEFINITION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.compileDefinitions), - (config, value, err) -> { - config.compileDefinitions = ASTUtils.elementToStringMaps(value); - }), - - /** - * Directive to generate a Dockerfile. This is either a boolean, - * true or false, or a dictionary of options. - */ - DOCKER("docker", UnionType.DOCKER_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), - (config) -> { - if (config.dockerOptions == null) { - return null; - } else if(config.dockerOptions.equals(new DockerOptions())) { - // default configuration - return ASTUtils.toElement(true); - } else { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (DockerOption opt : DockerOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case FROM: - if (config.dockerOptions.from == null) continue; - pair.setValue(ASTUtils.toElement(config.dockerOptions.from)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - } - }, - (config, value, err) -> setDockerProperty(config, value), - (config, value, err) -> setDockerProperty(config, value)), - - /** - * Directive for specifying a path to an external runtime to be used for the - * compiled binary. - */ - EXTERNAL_RUNTIME_PATH("external-runtime-path", PrimitiveType.STRING, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.externalRuntimePath), - (config, value, err) -> { - config.externalRuntimePath = ASTUtils.elementToSingleString(value); - }), - - /** - * Directive to let the execution engine allow logical time to elapse - * faster than physical time. - */ - FAST("fast", PrimitiveType.BOOLEAN, Target.ALL, - (config) -> ASTUtils.toElement(config.fastMode), - (config, value, err) -> { - config.fastMode = ASTUtils.toBoolean(value); - }), - - /** - * Directive to stage particular files on the class path to be - * processed by the code generator. - */ - FILES("files", UnionType.FILE_OR_FILE_ARRAY, List.of(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.files), - (config, value, err) -> { - config.files = ASTUtils.elementToListOfStrings(value); - }, - // FIXME: This merging of lists is potentially dangerous since - // the incoming list of files can belong to a .lf file that is - // located in a different location, and keeping just filename - // strings like this without absolute paths is incorrect. - (config, value, err) -> { - config.files.addAll(ASTUtils.elementToListOfStrings(value)); - }), - - /** - * Flags to be passed on to the target compiler. - */ - FLAGS("flags", UnionType.STRING_OR_STRING_ARRAY, - Arrays.asList(Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.compilerFlags), - (config, value, err) -> { - config.compilerFlags = ASTUtils.elementToListOfStrings(value); - }), - - /** - * Directive to specify the coordination mode - */ - COORDINATION("coordination", UnionType.COORDINATION_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.coordination.toString()), - (config, value, err) -> { - config.coordination = (CoordinationType) UnionType.COORDINATION_UNION - .forName(ASTUtils.elementToSingleString(value)); - }, - (config, value, err) -> { - config.coordination = (CoordinationType) UnionType.COORDINATION_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - - /** - * Key-value pairs giving options for clock synchronization. - */ - COORDINATION_OPTIONS("coordination-options", - DictionaryType.COORDINATION_OPTION_DICT, Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), - (config) -> { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (CoordinationOption opt : CoordinationOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case ADVANCE_MESSAGE_INTERVAL: - if (config.coordinationOptions.advance_message_interval == null) continue; - pair.setValue(ASTUtils.toElement(config.coordinationOptions.advance_message_interval)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - }, - (config, value, err) -> { - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - CoordinationOption option = (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT - .forName(entry.getName()); - switch (option) { - case ADVANCE_MESSAGE_INTERVAL: - config.coordinationOptions.advance_message_interval = ASTUtils - .toTimeValue(entry.getValue()); - break; - default: - break; - } - } - }, - (config, value, err) -> { - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - CoordinationOption option = (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT - .forName(entry.getName()); - switch (option) { - case ADVANCE_MESSAGE_INTERVAL: - config.coordinationOptions.advance_message_interval = ASTUtils - .toTimeValue(entry.getValue()); - break; - default: - break; - } - } - }), - - /** - * Directive to let the execution engine remain active also if there - * are no more events in the event queue. - */ - KEEPALIVE("keepalive", PrimitiveType.BOOLEAN, Target.ALL, - (config) -> ASTUtils.toElement(config.keepalive), - (config, value, err) -> { - config.keepalive = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify the grain at which to report log messages during execution. - */ - LOGGING("logging", UnionType.LOGGING_UNION, Target.ALL, - (config) -> ASTUtils.toElement(config.logLevel.toString()), - (config, value, err) -> { - config.logLevel = (LogLevel) UnionType.LOGGING_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - - /** - * Directive to not invoke the target compiler. - */ - NO_COMPILE("no-compile", PrimitiveType.BOOLEAN, - Arrays.asList(Target.C, Target.CPP, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.noCompile), - (config, value, err) -> { - config.noCompile = ASTUtils.toBoolean(value); - }), - - /** - * Directive to disable validation of reactor rules at runtime. - */ - NO_RUNTIME_VALIDATION("no-runtime-validation", PrimitiveType.BOOLEAN, - Arrays.asList(Target.CPP), - (config) -> ASTUtils.toElement(config.noRuntimeValidation), - (config, value, err) -> { - config.noRuntimeValidation = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify the platform for cross code generation. This is either a string of the platform - * or a dictionary of options that includes the string name. - */ - PLATFORM("platform", UnionType.PLATFORM_STRING_OR_DICTIONARY, Target.ALL, - (config) -> { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (PlatformOption opt : PlatformOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case NAME: - pair.setValue(ASTUtils.toElement(config.platformOptions.platform.toString())); - break; - case BAUDRATE: - pair.setValue(ASTUtils.toElement(config.platformOptions.baudRate)); - break; - case BOARD: - pair.setValue(ASTUtils.toElement(config.platformOptions.board)); - break; - case FLASH: - pair.setValue(ASTUtils.toElement(config.platformOptions.flash)); - break; - case PORT: - pair.setValue(ASTUtils.toElement(config.platformOptions.port)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - }, - (config, value, err) -> { - if (value.getLiteral() != null) { - config.platformOptions = new PlatformOptions(); - config.platformOptions.platform = (Platform) UnionType.PLATFORM_UNION - .forName(ASTUtils.elementToSingleString(value)); - } else { - config.platformOptions= new PlatformOptions(); - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - PlatformOption option = (PlatformOption) DictionaryType.PLATFORM_DICT - .forName(entry.getName()); - switch (option) { - case NAME: - Platform p = (Platform) UnionType.PLATFORM_UNION - .forName(ASTUtils.elementToSingleString(entry.getValue())); - if(p == null) { - String s = "Unidentified Platform Type, LF supports the following platform types: " + Arrays.asList(Platform.values()).toString(); - err.reportError(s); - throw new AssertionError(s); - } - config.platformOptions.platform = p; - break; - case BAUDRATE: - config.platformOptions.baudRate = ASTUtils.toInteger(entry.getValue()); - break; - case BOARD: - config.platformOptions.board = ASTUtils.elementToSingleString(entry.getValue()); - break; - case FLASH: - config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()); - break; - case PORT: - config.platformOptions.port = ASTUtils.elementToSingleString(entry.getValue()); - break; - default: - break; - } - } - } - }), - - /** - * Directive to instruct the runtime to collect and print execution statistics. - */ - PRINT_STATISTICS("print-statistics", PrimitiveType.BOOLEAN, - Arrays.asList(Target.CPP), - (config) -> ASTUtils.toElement(config.printStatistics), - (config, value, err) -> { - config.printStatistics = ASTUtils.toBoolean(value); - }), - - /** - * Directive for specifying .proto files that need to be compiled and their - * code included in the sources. - */ - PROTOBUFS("protobufs", UnionType.FILE_OR_FILE_ARRAY, - Arrays.asList(Target.C, Target.CCPP, Target.TS, Target.Python), - (config) -> ASTUtils.toElement(config.protoFiles), - (config, value, err) -> { - config.protoFiles = ASTUtils.elementToListOfStrings(value); - }), - - - /** - * Directive to specify that ROS2 specific code is generated, - */ - ROS2("ros2", PrimitiveType.BOOLEAN, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.ros2), - (config, value, err) -> { - config.ros2 = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify additional ROS2 packages that this LF program depends on. - */ - ROS2_DEPENDENCIES("ros2-dependencies", ArrayType.STRING_ARRAY, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.ros2Dependencies), - (config, value, err) -> { - config.ros2Dependencies = ASTUtils.elementToListOfStrings(value); - }), - - /** - * Directive for specifying a specific version of the reactor runtime library. - */ - RUNTIME_VERSION("runtime-version", PrimitiveType.STRING, - Arrays.asList(Target.CPP), - (config) -> ASTUtils.toElement(config.runtimeVersion), - (config, value, err) -> { - config.runtimeVersion = ASTUtils.elementToSingleString(value); - }), - - - /** - * Directive for specifying a specific runtime scheduler, if supported. - */ - SCHEDULER("scheduler", UnionType.SCHEDULER_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.schedulerType.toString()), - (config, value, err) -> { - config.schedulerType = (SchedulerOption) UnionType.SCHEDULER_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - - /** - * Directive to specify that all code is generated in a single file. - */ - SINGLE_FILE_PROJECT("single-file-project", PrimitiveType.BOOLEAN, - List.of(Target.Rust), - (config) -> ASTUtils.toElement(config.singleFileProject), - (config, value, err) -> { - config.singleFileProject = ASTUtils.toBoolean(value); - }), - - /** - * Directive to indicate whether the runtime should use multi-threading. - */ - THREADING("threading", PrimitiveType.BOOLEAN, - List.of(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.threading), - (config, value, err) -> { - config.threading = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify the number of worker threads used by the runtime. - */ - WORKERS("workers", PrimitiveType.NON_NEGATIVE_INTEGER, - List.of(Target.C, Target.CCPP, Target.Python, Target.CPP, Target.Rust), - (config) -> ASTUtils.toElement(config.workers), - (config, value, err) -> { - config.workers = ASTUtils.toInteger(value); - }), - - /** - * Directive to specify the execution timeout. - */ - TIMEOUT("timeout", PrimitiveType.TIME_VALUE, Target.ALL, - (config) -> ASTUtils.toElement(config.timeout), - (config, value, err) -> { - config.timeout = ASTUtils.toTimeValue(value); - }, - (config, value, err) -> { - config.timeout = ASTUtils.toTimeValue(value); - }), - - /** - * Directive to enable tracing. - */ - TRACING("tracing", UnionType.TRACING_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), - (config) -> { - if (config.tracing == null) { - return null; - } else if (config.tracing.equals(new TracingOptions())) { - // default values - return ASTUtils.toElement(true); - } else { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (TracingOption opt : TracingOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case TRACE_FILE_NAME: - if (config.tracing.traceFileName == null) continue; - pair.setValue(ASTUtils.toElement(config.tracing.traceFileName)); - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - } - }, - (config, value, err) -> { - if (value.getLiteral() != null) { - if (ASTUtils.toBoolean(value)) { - config.tracing = new TracingOptions(); - } else { - config.tracing = null; - } - } else { - config.tracing = new TracingOptions(); - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - TracingOption option = (TracingOption) DictionaryType.TRACING_DICT - .forName(entry.getName()); - switch (option) { - case TRACE_FILE_NAME: - config.tracing.traceFileName = ASTUtils.elementToSingleString(entry.getValue()); - break; - default: - break; - } - } - } - }), - - /** - * Directive to let the runtime export its internal dependency graph. - * - * This is a debugging feature and currently only used for C++ and Rust programs. - */ - EXPORT_DEPENDENCY_GRAPH("export-dependency-graph", PrimitiveType.BOOLEAN, - List.of(Target.CPP, Target.Rust), - (config) -> ASTUtils.toElement(config.exportDependencyGraph), - (config, value, err) -> { - config.exportDependencyGraph = ASTUtils.toBoolean(value); - }), - - /** - * Directive to let the runtime export the program structure to a yaml file. - * - * This is a debugging feature and currently only used for C++ programs. - */ - EXPORT_TO_YAML("export-to-yaml", PrimitiveType.BOOLEAN, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.exportToYaml), - (config, value, err) -> { - config.exportToYaml = ASTUtils.toBoolean(value); - }), - - /** - * List of module files to link into the crate as top-level. - * For instance, a {@code target Rust { rust-modules: [ "foo.rs" ] }} - * will cause the file to be copied into the generated project, - * and the generated {@code main.rs} will include it with a {@code mod foo;}. - * If one of the paths is a directory, it must contain a {@code mod.rs} - * file, and all its contents are copied. - */ - RUST_INCLUDE("rust-include", - UnionType.FILE_OR_FILE_ARRAY, - List.of(Target.Rust), - (config) -> { - // do not check paths here, and simply copy the absolute path over - List paths = config.rust.getRustTopLevelModules(); - if (paths.isEmpty()) return null; - else if (paths.size() == 1) { - return ASTUtils.toElement(paths.get(0).toString()); - } else { - Element e = LfFactory.eINSTANCE.createElement(); - Array arr = LfFactory.eINSTANCE.createArray(); - for (Path p : paths) { - arr.getElements().add(ASTUtils.toElement(p.toString())); - } - e.setArray(arr); - return e; - } - }, - (config, value, err) -> { - Path referencePath; - try { - referencePath = FileUtil.toPath(value.eResource().getURI()).toAbsolutePath(); - } catch (IOException e) { - err.reportError(value, "Invalid path? " + e.getMessage()); - throw new RuntimeIOException(e); - } - - // we'll resolve relative paths to check that the files - // are as expected. - - if (value.getLiteral() != null) { - Path resolved = referencePath.resolveSibling(StringUtil.removeQuotes(value.getLiteral())); - - config.rust.addAndCheckTopLevelModule(resolved, value, err); - } else if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - String literal = StringUtil.removeQuotes(element.getLiteral()); - Path resolved = referencePath.resolveSibling(literal); - config.rust.addAndCheckTopLevelModule(resolved, element, err); - } - } - }), - - /** - * Directive for specifying Cargo features of the generated - * program to enable. - */ - CARGO_FEATURES("cargo-features", ArrayType.STRING_ARRAY, - List.of(Target.Rust), - (config) -> ASTUtils.toElement(config.rust.getCargoFeatures()), - (config, value, err) -> { - config.rust.setCargoFeatures(ASTUtils.elementToListOfStrings(value)); - }), - - /** - * Dependency specifications for Cargo. This property looks like this: - *

    {@code
    -     * cargo-dependencies: {
    -     *    // Name-of-the-crate: "version"
    -     *    rand: "0.8",
    -     *    // Equivalent to using an explicit map:
    -     *    rand: {
    -     *      version: "0.8"
    -     *    },
    -     *    // The map allows specifying more details
    -     *    rand: {
    -     *      // A path to a local unpublished crate.
    -     *      // Note 'path' is mutually exclusive with 'version'.
    -     *      path: "/home/me/Git/local-rand-clone"
    -     *    },
    -     *    rand: {
    -     *      version: "0.8",
    -     *      // you can specify cargo features
    -     *      features: ["some-cargo-feature",]
    -     *    }
    -     * }
    -     * }
    - */ - CARGO_DEPENDENCIES("cargo-dependencies", - CargoDependenciesPropertyType.INSTANCE, - List.of(Target.Rust), - (config) -> { - var deps = config.rust.getCargoDependencies(); - if (deps.size() == 0) return null; - else { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var ent : deps.entrySet()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(ent.getKey()); - pair.setValue(CargoDependencySpec.extractSpec(ent.getValue())); - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - return e; - } - }, - (config, value, err) -> { - config.rust.setCargoDependencies(CargoDependencySpec.parseAll(value)); - }), - - /** - * Directs the C or Python target to include the associated C file used for - * setting up federated execution before processing the first tag. - */ - FED_SETUP("_fed_setup", PrimitiveType.FILE, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.fedSetupPreamble), - (config, value, err) -> - config.fedSetupPreamble = StringUtil.removeQuotes(ASTUtils.elementToSingleString(value)) - ) - ; - - /** - * Update {@code config}.dockerOptions based on value. - */ - private static void setDockerProperty(TargetConfig config, Element value) { - if (value.getLiteral() != null) { - if (ASTUtils.toBoolean(value)) { - config.dockerOptions = new DockerOptions(); - } else { - config.dockerOptions = null; + /** Directive to allow including OpenSSL libraries and process HMAC authentication. */ + AUTH( + "auth", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.auth), + (config, value, err) -> { + config.auth = ASTUtils.toBoolean(value); + }), + /** Directive to let the generator use the custom build command. */ + BUILD( + "build", + UnionType.STRING_OR_STRING_ARRAY, + Arrays.asList(Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.buildCommands), + (config, value, err) -> { + config.buildCommands = ASTUtils.elementToListOfStrings(value); + }), + + /** + * Directive to specify the target build type such as 'Release' or 'Debug'. This is also used in + * the Rust target to select a Cargo profile. + */ + BUILD_TYPE( + "build-type", + UnionType.BUILD_TYPE_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Rust), + (config) -> ASTUtils.toElement(config.cmakeBuildType.toString()), + (config, value, err) -> { + config.cmakeBuildType = + (BuildType) UnionType.BUILD_TYPE_UNION.forName(ASTUtils.elementToSingleString(value)); + // set it there too, because the default is different. + config.rust.setBuildType(config.cmakeBuildType); + }), + + /** Directive to let the federate execution handle clock synchronization in software. */ + CLOCK_SYNC( + "clock-sync", + UnionType.CLOCK_SYNC_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.clockSync.toString()), + (config, value, err) -> { + config.clockSync = + (ClockSyncMode) + UnionType.CLOCK_SYNC_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + /** Key-value pairs giving options for clock synchronization. */ + CLOCK_SYNC_OPTIONS( + "clock-sync-options", + DictionaryType.CLOCK_SYNC_OPTION_DICT, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (ClockSyncOption opt : ClockSyncOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case ATTENUATION: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.attenuation)); + break; + case COLLECT_STATS: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.collectStats)); + break; + case LOCAL_FEDERATES_ON: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.localFederatesOn)); + break; + case PERIOD: + if (config.clockSyncOptions.period == null) continue; // don't set if null + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.period)); + break; + case TEST_OFFSET: + if (config.clockSyncOptions.testOffset == null) continue; // don't set if null + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.testOffset)); + break; + case TRIALS: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.trials)); + break; + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + // kvp will never be empty + return e; + }, + (config, value, err) -> { + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + ClockSyncOption option = + (ClockSyncOption) DictionaryType.CLOCK_SYNC_OPTION_DICT.forName(entry.getName()); + switch (option) { + case ATTENUATION: + config.clockSyncOptions.attenuation = ASTUtils.toInteger(entry.getValue()); + break; + case COLLECT_STATS: + config.clockSyncOptions.collectStats = ASTUtils.toBoolean(entry.getValue()); + break; + case LOCAL_FEDERATES_ON: + config.clockSyncOptions.localFederatesOn = ASTUtils.toBoolean(entry.getValue()); + break; + case PERIOD: + config.clockSyncOptions.period = ASTUtils.toTimeValue(entry.getValue()); + break; + case TEST_OFFSET: + config.clockSyncOptions.testOffset = ASTUtils.toTimeValue(entry.getValue()); + break; + case TRIALS: + config.clockSyncOptions.trials = ASTUtils.toInteger(entry.getValue()); + break; + default: + break; + } + } + }), + + /** + * Directive to specify a cmake to be included by the generated build systems. + * + *

    This gives full control over the C/C++ build as any cmake parameters can be adjusted in the + * included file. + */ + CMAKE_INCLUDE( + "cmake-include", + UnionType.FILE_OR_FILE_ARRAY, + Arrays.asList(Target.CPP, Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.cmakeIncludes), + (config, value, err) -> { + config.cmakeIncludes = ASTUtils.elementToListOfStrings(value); + }, + // FIXME: This merging of lists is potentially dangerous since + // the incoming list of cmake-includes can belong to a .lf file that is + // located in a different location, and keeping just filename + // strings like this without absolute paths is incorrect. + (config, value, err) -> { + config.cmakeIncludes.addAll(ASTUtils.elementToListOfStrings(value)); + }), + /** Directive to specify the target compiler. */ + COMPILER( + "compiler", + PrimitiveType.STRING, + Target.ALL, + (config) -> ASTUtils.toElement(config.compiler), + (config, value, err) -> { + config.compiler = ASTUtils.elementToSingleString(value); + }), + + /** Directive to specify compile-time definitions. */ + COMPILE_DEFINITIONS( + "compile-definitions", + StringDictionaryType.COMPILE_DEFINITION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.compileDefinitions), + (config, value, err) -> { + config.compileDefinitions = ASTUtils.elementToStringMaps(value); + }), + + /** + * Directive to generate a Dockerfile. This is either a boolean, true or false, or a dictionary of + * options. + */ + DOCKER( + "docker", + UnionType.DOCKER_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), + (config) -> { + if (config.dockerOptions == null) { + return null; + } else if (config.dockerOptions.equals(new DockerOptions())) { + // default configuration + return ASTUtils.toElement(true); + } else { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (DockerOption opt : DockerOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case FROM: + if (config.dockerOptions.from == null) continue; + pair.setValue(ASTUtils.toElement(config.dockerOptions.from)); + break; } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + } + }, + (config, value, err) -> setDockerProperty(config, value), + (config, value, err) -> setDockerProperty(config, value)), + + /** Directive for specifying a path to an external runtime to be used for the compiled binary. */ + EXTERNAL_RUNTIME_PATH( + "external-runtime-path", + PrimitiveType.STRING, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.externalRuntimePath), + (config, value, err) -> { + config.externalRuntimePath = ASTUtils.elementToSingleString(value); + }), + + /** + * Directive to let the execution engine allow logical time to elapse faster than physical time. + */ + FAST( + "fast", + PrimitiveType.BOOLEAN, + Target.ALL, + (config) -> ASTUtils.toElement(config.fastMode), + (config, value, err) -> { + config.fastMode = ASTUtils.toBoolean(value); + }), + + /** + * Directive to stage particular files on the class path to be processed by the code generator. + */ + FILES( + "files", + UnionType.FILE_OR_FILE_ARRAY, + List.of(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.files), + (config, value, err) -> { + config.files = ASTUtils.elementToListOfStrings(value); + }, + // FIXME: This merging of lists is potentially dangerous since + // the incoming list of files can belong to a .lf file that is + // located in a different location, and keeping just filename + // strings like this without absolute paths is incorrect. + (config, value, err) -> { + config.files.addAll(ASTUtils.elementToListOfStrings(value)); + }), + + /** Flags to be passed on to the target compiler. */ + FLAGS( + "flags", + UnionType.STRING_OR_STRING_ARRAY, + Arrays.asList(Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.compilerFlags), + (config, value, err) -> { + config.compilerFlags = ASTUtils.elementToListOfStrings(value); + }), + + /** Directive to specify the coordination mode */ + COORDINATION( + "coordination", + UnionType.COORDINATION_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.coordination.toString()), + (config, value, err) -> { + config.coordination = + (CoordinationType) + UnionType.COORDINATION_UNION.forName(ASTUtils.elementToSingleString(value)); + }, + (config, value, err) -> { + config.coordination = + (CoordinationType) + UnionType.COORDINATION_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + + /** Key-value pairs giving options for clock synchronization. */ + COORDINATION_OPTIONS( + "coordination-options", + DictionaryType.COORDINATION_OPTION_DICT, + Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), + (config) -> { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (CoordinationOption opt : CoordinationOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case ADVANCE_MESSAGE_INTERVAL: + if (config.coordinationOptions.advance_message_interval == null) continue; + pair.setValue( + ASTUtils.toElement(config.coordinationOptions.advance_message_interval)); + break; + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + }, + (config, value, err) -> { + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + CoordinationOption option = + (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT.forName(entry.getName()); + switch (option) { + case ADVANCE_MESSAGE_INTERVAL: + config.coordinationOptions.advance_message_interval = + ASTUtils.toTimeValue(entry.getValue()); + break; + default: + break; + } + } + }, + (config, value, err) -> { + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + CoordinationOption option = + (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT.forName(entry.getName()); + switch (option) { + case ADVANCE_MESSAGE_INTERVAL: + config.coordinationOptions.advance_message_interval = + ASTUtils.toTimeValue(entry.getValue()); + break; + default: + break; + } + } + }), + + /** + * Directive to let the execution engine remain active also if there are no more events in the + * event queue. + */ + KEEPALIVE( + "keepalive", + PrimitiveType.BOOLEAN, + Target.ALL, + (config) -> ASTUtils.toElement(config.keepalive), + (config, value, err) -> { + config.keepalive = ASTUtils.toBoolean(value); + }), + + /** Directive to specify the grain at which to report log messages during execution. */ + LOGGING( + "logging", + UnionType.LOGGING_UNION, + Target.ALL, + (config) -> ASTUtils.toElement(config.logLevel.toString()), + (config, value, err) -> { + config.logLevel = + (LogLevel) UnionType.LOGGING_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + + /** Directive to not invoke the target compiler. */ + NO_COMPILE( + "no-compile", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.C, Target.CPP, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.noCompile), + (config, value, err) -> { + config.noCompile = ASTUtils.toBoolean(value); + }), + + /** Directive to disable validation of reactor rules at runtime. */ + NO_RUNTIME_VALIDATION( + "no-runtime-validation", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.noRuntimeValidation), + (config, value, err) -> { + config.noRuntimeValidation = ASTUtils.toBoolean(value); + }), + + /** + * Directive to specify the platform for cross code generation. This is either a string of the + * platform or a dictionary of options that includes the string name. + */ + PLATFORM( + "platform", + UnionType.PLATFORM_STRING_OR_DICTIONARY, + Target.ALL, + (config) -> { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (PlatformOption opt : PlatformOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case NAME: + pair.setValue(ASTUtils.toElement(config.platformOptions.platform.toString())); + break; + case BAUDRATE: + pair.setValue(ASTUtils.toElement(config.platformOptions.baudRate)); + break; + case BOARD: + pair.setValue(ASTUtils.toElement(config.platformOptions.board)); + break; + case FLASH: + pair.setValue(ASTUtils.toElement(config.platformOptions.flash)); + break; + case PORT: + pair.setValue(ASTUtils.toElement(config.platformOptions.port)); + break; + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + }, + (config, value, err) -> { + if (value.getLiteral() != null) { + config.platformOptions = new PlatformOptions(); + config.platformOptions.platform = + (Platform) UnionType.PLATFORM_UNION.forName(ASTUtils.elementToSingleString(value)); } else { - config.dockerOptions = new DockerOptions(); - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - DockerOption option = (DockerOption) DictionaryType.DOCKER_DICT - .forName(entry.getName()); - switch (option) { - case FROM: - config.dockerOptions.from = ASTUtils.elementToSingleString(entry.getValue()); - break; - default: - break; + config.platformOptions = new PlatformOptions(); + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + PlatformOption option = + (PlatformOption) DictionaryType.PLATFORM_DICT.forName(entry.getName()); + switch (option) { + case NAME: + Platform p = + (Platform) + UnionType.PLATFORM_UNION.forName( + ASTUtils.elementToSingleString(entry.getValue())); + if (p == null) { + String s = + "Unidentified Platform Type, LF supports the following platform types: " + + Arrays.asList(Platform.values()).toString(); + err.reportError(s); + throw new AssertionError(s); } + config.platformOptions.platform = p; + break; + case BAUDRATE: + config.platformOptions.baudRate = ASTUtils.toInteger(entry.getValue()); + break; + case BOARD: + config.platformOptions.board = ASTUtils.elementToSingleString(entry.getValue()); + break; + case FLASH: + config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()); + break; + case PORT: + config.platformOptions.port = ASTUtils.elementToSingleString(entry.getValue()); + break; + default: + break; } + } + } + }), + + /** Directive to instruct the runtime to collect and print execution statistics. */ + PRINT_STATISTICS( + "print-statistics", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.printStatistics), + (config, value, err) -> { + config.printStatistics = ASTUtils.toBoolean(value); + }), + + /** + * Directive for specifying .proto files that need to be compiled and their code included in the + * sources. + */ + PROTOBUFS( + "protobufs", + UnionType.FILE_OR_FILE_ARRAY, + Arrays.asList(Target.C, Target.CCPP, Target.TS, Target.Python), + (config) -> ASTUtils.toElement(config.protoFiles), + (config, value, err) -> { + config.protoFiles = ASTUtils.elementToListOfStrings(value); + }), + + /** Directive to specify that ROS2 specific code is generated, */ + ROS2( + "ros2", + PrimitiveType.BOOLEAN, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.ros2), + (config, value, err) -> { + config.ros2 = ASTUtils.toBoolean(value); + }), + + /** Directive to specify additional ROS2 packages that this LF program depends on. */ + ROS2_DEPENDENCIES( + "ros2-dependencies", + ArrayType.STRING_ARRAY, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.ros2Dependencies), + (config, value, err) -> { + config.ros2Dependencies = ASTUtils.elementToListOfStrings(value); + }), + + /** Directive for specifying a specific version of the reactor runtime library. */ + RUNTIME_VERSION( + "runtime-version", + PrimitiveType.STRING, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.runtimeVersion), + (config, value, err) -> { + config.runtimeVersion = ASTUtils.elementToSingleString(value); + }), + + /** Directive for specifying a specific runtime scheduler, if supported. */ + SCHEDULER( + "scheduler", + UnionType.SCHEDULER_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.schedulerType.toString()), + (config, value, err) -> { + config.schedulerType = + (SchedulerOption) + UnionType.SCHEDULER_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + + /** Directive to specify that all code is generated in a single file. */ + SINGLE_FILE_PROJECT( + "single-file-project", + PrimitiveType.BOOLEAN, + List.of(Target.Rust), + (config) -> ASTUtils.toElement(config.singleFileProject), + (config, value, err) -> { + config.singleFileProject = ASTUtils.toBoolean(value); + }), + + /** Directive to indicate whether the runtime should use multi-threading. */ + THREADING( + "threading", + PrimitiveType.BOOLEAN, + List.of(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.threading), + (config, value, err) -> { + config.threading = ASTUtils.toBoolean(value); + }), + + /** Directive to specify the number of worker threads used by the runtime. */ + WORKERS( + "workers", + PrimitiveType.NON_NEGATIVE_INTEGER, + List.of(Target.C, Target.CCPP, Target.Python, Target.CPP, Target.Rust), + (config) -> ASTUtils.toElement(config.workers), + (config, value, err) -> { + config.workers = ASTUtils.toInteger(value); + }), + + /** Directive to specify the execution timeout. */ + TIMEOUT( + "timeout", + PrimitiveType.TIME_VALUE, + Target.ALL, + (config) -> ASTUtils.toElement(config.timeout), + (config, value, err) -> { + config.timeout = ASTUtils.toTimeValue(value); + }, + (config, value, err) -> { + config.timeout = ASTUtils.toTimeValue(value); + }), + + /** Directive to enable tracing. */ + TRACING( + "tracing", + UnionType.TRACING_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), + (config) -> { + if (config.tracing == null) { + return null; + } else if (config.tracing.equals(new TracingOptions())) { + // default values + return ASTUtils.toElement(true); + } else { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (TracingOption opt : TracingOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case TRACE_FILE_NAME: + if (config.tracing.traceFileName == null) continue; + pair.setValue(ASTUtils.toElement(config.tracing.traceFileName)); + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + } + }, + (config, value, err) -> { + if (value.getLiteral() != null) { + if (ASTUtils.toBoolean(value)) { + config.tracing = new TracingOptions(); + } else { + config.tracing = null; + } + } else { + config.tracing = new TracingOptions(); + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + TracingOption option = + (TracingOption) DictionaryType.TRACING_DICT.forName(entry.getName()); + switch (option) { + case TRACE_FILE_NAME: + config.tracing.traceFileName = ASTUtils.elementToSingleString(entry.getValue()); + break; + default: + break; + } + } + } + }), + + /** + * Directive to let the runtime export its internal dependency graph. + * + *

    This is a debugging feature and currently only used for C++ and Rust programs. + */ + EXPORT_DEPENDENCY_GRAPH( + "export-dependency-graph", + PrimitiveType.BOOLEAN, + List.of(Target.CPP, Target.Rust), + (config) -> ASTUtils.toElement(config.exportDependencyGraph), + (config, value, err) -> { + config.exportDependencyGraph = ASTUtils.toBoolean(value); + }), + + /** + * Directive to let the runtime export the program structure to a yaml file. + * + *

    This is a debugging feature and currently only used for C++ programs. + */ + EXPORT_TO_YAML( + "export-to-yaml", + PrimitiveType.BOOLEAN, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.exportToYaml), + (config, value, err) -> { + config.exportToYaml = ASTUtils.toBoolean(value); + }), + + /** + * List of module files to link into the crate as top-level. For instance, a {@code target Rust { + * rust-modules: [ "foo.rs" ] }} will cause the file to be copied into the generated project, and + * the generated {@code main.rs} will include it with a {@code mod foo;}. If one of the paths is a + * directory, it must contain a {@code mod.rs} file, and all its contents are copied. + */ + RUST_INCLUDE( + "rust-include", + UnionType.FILE_OR_FILE_ARRAY, + List.of(Target.Rust), + (config) -> { + // do not check paths here, and simply copy the absolute path over + List paths = config.rust.getRustTopLevelModules(); + if (paths.isEmpty()) return null; + else if (paths.size() == 1) { + return ASTUtils.toElement(paths.get(0).toString()); + } else { + Element e = LfFactory.eINSTANCE.createElement(); + Array arr = LfFactory.eINSTANCE.createArray(); + for (Path p : paths) { + arr.getElements().add(ASTUtils.toElement(p.toString())); + } + e.setArray(arr); + return e; + } + }, + (config, value, err) -> { + Path referencePath; + try { + referencePath = FileUtil.toPath(value.eResource().getURI()).toAbsolutePath(); + } catch (IOException e) { + err.reportError(value, "Invalid path? " + e.getMessage()); + throw new RuntimeIOException(e); } - } - - /** - * String representation of this target property. - */ - public final String description; - - /** - * List of targets that support this property. If a property is used for - * a target that does not support it, a warning reported during - * validation. - */ - public final List supportedBy; - - /** - * The type of values that can be assigned to this property. - */ - public final TargetPropertyType type; - /** - * Function that given a configuration object and an Element AST node - * sets the configuration. It is assumed that validation already - * occurred, so this code should be straightforward. - */ - public final PropertyParser setter; + // we'll resolve relative paths to check that the files + // are as expected. - /** - * Function that given a configuration object and an Element AST node - * sets the configuration. It is assumed that validation already - * occurred, so this code should be straightforward. - */ - public final PropertyParser updater; + if (value.getLiteral() != null) { + Path resolved = referencePath.resolveSibling(StringUtil.removeQuotes(value.getLiteral())); + + config.rust.addAndCheckTopLevelModule(resolved, value, err); + } else if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + String literal = StringUtil.removeQuotes(element.getLiteral()); + Path resolved = referencePath.resolveSibling(literal); + config.rust.addAndCheckTopLevelModule(resolved, element, err); + } + } + }), + + /** Directive for specifying Cargo features of the generated program to enable. */ + CARGO_FEATURES( + "cargo-features", + ArrayType.STRING_ARRAY, + List.of(Target.Rust), + (config) -> ASTUtils.toElement(config.rust.getCargoFeatures()), + (config, value, err) -> { + config.rust.setCargoFeatures(ASTUtils.elementToListOfStrings(value)); + }), + + /** + * Dependency specifications for Cargo. This property looks like this: + * + *

    {@code
    +   * cargo-dependencies: {
    +   *    // Name-of-the-crate: "version"
    +   *    rand: "0.8",
    +   *    // Equivalent to using an explicit map:
    +   *    rand: {
    +   *      version: "0.8"
    +   *    },
    +   *    // The map allows specifying more details
    +   *    rand: {
    +   *      // A path to a local unpublished crate.
    +   *      // Note 'path' is mutually exclusive with 'version'.
    +   *      path: "/home/me/Git/local-rand-clone"
    +   *    },
    +   *    rand: {
    +   *      version: "0.8",
    +   *      // you can specify cargo features
    +   *      features: ["some-cargo-feature",]
    +   *    }
    +   * }
    +   * }
    + */ + CARGO_DEPENDENCIES( + "cargo-dependencies", + CargoDependenciesPropertyType.INSTANCE, + List.of(Target.Rust), + (config) -> { + var deps = config.rust.getCargoDependencies(); + if (deps.size() == 0) return null; + else { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var ent : deps.entrySet()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(ent.getKey()); + pair.setValue(CargoDependencySpec.extractSpec(ent.getValue())); + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + return e; + } + }, + (config, value, err) -> { + config.rust.setCargoDependencies(CargoDependencySpec.parseAll(value)); + }), + + /** + * Directs the C or Python target to include the associated C file used for setting up federated + * execution before processing the first tag. + */ + FED_SETUP( + "_fed_setup", + PrimitiveType.FILE, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.fedSetupPreamble), + (config, value, err) -> + config.fedSetupPreamble = StringUtil.removeQuotes(ASTUtils.elementToSingleString(value))); + + /** Update {@code config}.dockerOptions based on value. */ + private static void setDockerProperty(TargetConfig config, Element value) { + if (value.getLiteral() != null) { + if (ASTUtils.toBoolean(value)) { + config.dockerOptions = new DockerOptions(); + } else { + config.dockerOptions = null; + } + } else { + config.dockerOptions = new DockerOptions(); + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + DockerOption option = (DockerOption) DictionaryType.DOCKER_DICT.forName(entry.getName()); + switch (option) { + case FROM: + config.dockerOptions.from = ASTUtils.elementToSingleString(entry.getValue()); + break; + default: + break; + } + } + } + } + + /** String representation of this target property. */ + public final String description; + + /** + * List of targets that support this property. If a property is used for a target that does not + * support it, a warning reported during validation. + */ + public final List supportedBy; + + /** The type of values that can be assigned to this property. */ + public final TargetPropertyType type; + + /** + * Function that given a configuration object and an Element AST node sets the configuration. It + * is assumed that validation already occurred, so this code should be straightforward. + */ + public final PropertyParser setter; + + /** + * Function that given a configuration object and an Element AST node sets the configuration. It + * is assumed that validation already occurred, so this code should be straightforward. + */ + public final PropertyParser updater; + + @FunctionalInterface + private interface PropertyParser { + + /** + * Parse the given element into the given target config. May use the error reporter to report + * format errors. + */ + void parseIntoTargetConfig(TargetConfig config, Element element, ErrorReporter err); + } + + public final PropertyGetter getter; + + @FunctionalInterface + private interface PropertyGetter { + + /** + * Read this property from the target config and build an element which represents it for the + * AST. May return null if the given value of this property is the same as the default. + */ + Element getPropertyElement(TargetConfig config); + } + + /** + * Private constructor for target properties. + * + * @param description String representation of this property. + * @param type The type that values assigned to this property should conform to. + * @param supportedBy List of targets that support this property. + * @param setter Function for configuration updates. + */ + TargetProperty( + String description, + TargetPropertyType type, + List supportedBy, + PropertyGetter getter, + PropertyParser setter) { + this.description = description; + this.type = type; + this.supportedBy = supportedBy; + this.getter = getter; + this.setter = setter; + this.updater = setter; // (Re)set by default + } + + /** + * Private constructor for target properties. This will take an additional {@code updater}, which + * will be used to merge target properties from imported resources. + * + * @param description String representation of this property. + * @param type The type that values assigned to this property should conform to. + * @param supportedBy List of targets that support this property. + * @param setter Function for setting configuration values. + * @param updater Function for updating configuration values. + */ + TargetProperty( + String description, + TargetPropertyType type, + List supportedBy, + PropertyGetter getter, + PropertyParser setter, + PropertyParser updater) { + this.description = description; + this.type = type; + this.supportedBy = supportedBy; + this.getter = getter; + this.setter = setter; + this.updater = updater; + } + + /** + * Return the name of the property in lingua franca. This is suitable for use as a key in a target + * properties block. It may be an invalid identifier in other languages (may contains dashes + * {@code -}). + */ + public String getDisplayName() { + return description; + } + + /** + * Set the given configuration using the given target properties. + * + * @param config The configuration object to update. + * @param properties AST node that holds all the target properties. + * @param err Error reporter on which property format errors will be reported + */ + public static void set(TargetConfig config, List properties, ErrorReporter err) { + properties.forEach( + property -> { + TargetProperty p = forName(property.getName()); + if (p != null) { + // Mark the specified target property as set by the user + config.setByUser.add(p); + try { + p.setter.parseIntoTargetConfig(config, property.getValue(), err); + } catch (InvalidLfSourceException e) { + err.reportError(e.getNode(), e.getProblem()); + } + } + }); + } + + /** + * Extracts all properties as a list of key-value pairs from a TargetConfig. Only extracts + * properties explicitly set by user. + * + * @param config The TargetConfig to extract from. + * @return The extracted properties. + */ + public static List extractProperties(TargetConfig config) { + var res = new LinkedList(); + for (TargetProperty p : config.setByUser) { + KeyValuePair kv = LfFactory.eINSTANCE.createKeyValuePair(); + kv.setName(p.toString()); + kv.setValue(p.getter.getPropertyElement(config)); + if (kv.getValue() != null) res.add(kv); + } + return res; + } + + /** + * Constructs a TargetDecl by extracting the fields of the given TargetConfig. + * + * @param target The target to generate for. + * @param config The TargetConfig to extract from. + * @return A generated TargetDecl. + */ + public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { + TargetDecl decl = LfFactory.eINSTANCE.createTargetDecl(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (KeyValuePair p : extractProperties(config)) { + kvp.getPairs().add(p); + } + decl.setName(target.toString()); + decl.setConfig(kvp); + return decl; + } + + /** + * Update the given configuration using the given target properties. + * + * @param config The configuration object to update. + * @param properties AST node that holds all the target properties. + */ + public static void update(TargetConfig config, List properties, ErrorReporter err) { + properties.forEach( + property -> { + TargetProperty p = forName(property.getName()); + if (p != null) { + // Mark the specified target property as set by the user + config.setByUser.add(p); + p.updater.parseIntoTargetConfig(config, property.getValue(), err); + } + }); + } + + /** + * Update one of the target properties, given by 'propertyName'. For convenience, a list of target + * properties (e.g., taken from a file or resource) can be passed without any filtering. This + * function will do nothing if the list of target properties doesn't include the property given by + * 'propertyName'. + * + * @param config The target config to apply the update to. + * @param property The target property. + * @param properties AST node that holds all the target properties. + * @param err Error reporter on which property format errors will be reported + */ + public static void updateOne( + TargetConfig config, + TargetProperty property, + List properties, + ErrorReporter err) { + properties.stream() + .filter(p -> p.getName().equals(property.getDisplayName())) + .findFirst() + .map(KeyValuePair::getValue) + .ifPresent(value -> property.updater.parseIntoTargetConfig(config, value, err)); + } + + /** + * Return the entry that matches the given string. + * + * @param name The string to match against. + */ + public static TargetProperty forName(String name) { + return Target.match(name, TargetProperty.values()); + } + + /** + * Return a list with all target properties. + * + * @return All existing target properties. + */ + public static List getOptions() { + return Arrays.asList(TargetProperty.values()); + } + + /** Return the description. */ + @Override + public String toString() { + return this.description; + } + + // Inner classes for the various supported types. + + /** Dictionary type that allows for keys that will be interpreted as strings and string values. */ + public enum StringDictionaryType implements TargetPropertyType { + COMPILE_DEFINITION(); - @FunctionalInterface - private interface PropertyParser { + @Override + public boolean validate(Element e) { + if (e.getKeyvalue() != null) { + return true; + } + return false; + } - /** - * Parse the given element into the given target config. - * May use the error reporter to report format errors. - */ - void parseIntoTargetConfig(TargetConfig config, Element element, ErrorReporter err); + @Override + public void check(Element e, String name, LFValidator v) { + KeyValuePairs kv = e.getKeyvalue(); + if (kv == null) { + TargetPropertyType.produceError(name, this.toString(), v); + } else { + for (KeyValuePair pair : kv.getPairs()) { + String key = pair.getName(); + Element val = pair.getValue(); + + // Make sure the type is string + PrimitiveType.STRING.check(val, name + "." + key, v); + } + } } + } - public final PropertyGetter getter; + /** Interface for dictionary elements. It associates an entry with a type. */ + public interface DictionaryElement { - @FunctionalInterface - private interface PropertyGetter { + TargetPropertyType getType(); + } - /** - * Read this property from the target config and build an element which represents it for the AST. - * May return null if the given value of this property is the same as the default. - */ - Element getPropertyElement(TargetConfig config); - } + /** + * A dictionary type with a predefined set of possible keys and assignable types. + * + * @author Marten Lohstroh + */ + public enum DictionaryType implements TargetPropertyType { + CLOCK_SYNC_OPTION_DICT(Arrays.asList(ClockSyncOption.values())), + DOCKER_DICT(Arrays.asList(DockerOption.values())), + PLATFORM_DICT(Arrays.asList(PlatformOption.values())), + COORDINATION_OPTION_DICT(Arrays.asList(CoordinationOption.values())), + TRACING_DICT(Arrays.asList(TracingOption.values())); - /** - * Private constructor for target properties. - * - * @param description String representation of this property. - * @param type The type that values assigned to this property - * should conform to. - * @param supportedBy List of targets that support this property. - * @param setter Function for configuration updates. - */ - TargetProperty(String description, TargetPropertyType type, - List supportedBy, - PropertyGetter getter, - PropertyParser setter) { - this.description = description; - this.type = type; - this.supportedBy = supportedBy; - this.getter = getter; - this.setter = setter; - this.updater = setter; // (Re)set by default - } + /** The keys and assignable types that are allowed in this dictionary. */ + public List options; /** - * Private constructor for target properties. This will take an additional - * {@code updater}, which will be used to merge target properties from imported resources. + * A dictionary type restricted to sets of predefined keys and types of values. * - * @param description String representation of this property. - * @param type The type that values assigned to this property - * should conform to. - * @param supportedBy List of targets that support this property. - * @param setter Function for setting configuration values. - * @param updater Function for updating configuration values. - */ - TargetProperty(String description, TargetPropertyType type, - List supportedBy, - PropertyGetter getter, - PropertyParser setter, - PropertyParser updater) { - this.description = description; - this.type = type; - this.supportedBy = supportedBy; - this.getter = getter; - this.setter = setter; - this.updater = updater; - } - - /** - * Return the name of the property in lingua franca. This - * is suitable for use as a key in a target properties block. - * It may be an invalid identifier in other languages (may - * contains dashes {@code -}). + * @param options The dictionary elements allowed by this type. */ - public String getDisplayName() { - return description; + private DictionaryType(List options) { + this.options = options; } /** - * Set the given configuration using the given target properties. + * Return the dictionary element of which the key matches the given string. * - * @param config The configuration object to update. - * @param properties AST node that holds all the target properties. - * @param err Error reporter on which property format errors will be reported + * @param name The string to match against. + * @return The matching dictionary element (or null if there is none). */ - public static void set(TargetConfig config, List properties, ErrorReporter err) { - properties.forEach(property -> { - TargetProperty p = forName(property.getName()); - if (p != null) { - // Mark the specified target property as set by the user - config.setByUser.add(p); - try { - p.setter.parseIntoTargetConfig(config, property.getValue(), err); - } catch (InvalidLfSourceException e) { - err.reportError(e.getNode(), e.getProblem()); - } - } - }); + public DictionaryElement forName(String name) { + return Target.match(name, options); } - /** - * Extracts all properties as a list of key-value pairs from a TargetConfig. Only extracts properties explicitly set by user. - * @param config The TargetConfig to extract from. - * @return The extracted properties. - */ - public static List extractProperties(TargetConfig config) { - var res = new LinkedList(); - for (TargetProperty p : config.setByUser) { - KeyValuePair kv = LfFactory.eINSTANCE.createKeyValuePair(); - kv.setName(p.toString()); - kv.setValue(p.getter.getPropertyElement(config)); - if (kv.getValue() != null) - res.add(kv); + /** Recursively check that the passed in element conforms to the rules of this dictionary. */ + @Override + public void check(Element e, String name, LFValidator v) { + KeyValuePairs kv = e.getKeyvalue(); + if (kv == null) { + TargetPropertyType.produceError(name, this.toString(), v); + } else { + for (KeyValuePair pair : kv.getPairs()) { + String key = pair.getName(); + Element val = pair.getValue(); + Optional match = + this.options.stream() + .filter(element -> key.equalsIgnoreCase(element.toString())) + .findAny(); + if (match.isPresent()) { + // Make sure the type is correct, too. + TargetPropertyType type = match.get().getType(); + type.check(val, name + "." + key, v); + } else { + // No match found; report error. + TargetPropertyType.produceError(name, this.toString(), v); + } } - return res; + } } - /** - * Constructs a TargetDecl by extracting the fields of the given TargetConfig. - * @param target The target to generate for. - * @param config The TargetConfig to extract from. - * @return A generated TargetDecl. - */ - public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { - TargetDecl decl = LfFactory.eINSTANCE.createTargetDecl(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (KeyValuePair p : extractProperties(config)) { - kvp.getPairs().add(p); - } - decl.setName(target.toString()); - decl.setConfig(kvp); - return decl; + /** Return true if the given element represents a dictionary, false otherwise. */ + @Override + public boolean validate(Element e) { + if (e.getKeyvalue() != null) { + return true; + } + return false; } - /** - * Update the given configuration using the given target properties. - * - * @param config The configuration object to update. - * @param properties AST node that holds all the target properties. - */ - public static void update(TargetConfig config, List properties, ErrorReporter err) { - properties.forEach(property -> { - TargetProperty p = forName(property.getName()); - if (p != null) { - // Mark the specified target property as set by the user - config.setByUser.add(p); - p.updater.parseIntoTargetConfig(config, property.getValue(), err); - } - }); + /** Return a human-readable description of this type. */ + @Override + public String toString() { + return "a dictionary with one or more of the following keys: " + + options.stream().map(option -> option.toString()).collect(Collectors.joining(", ")); } - - /** - * Update one of the target properties, given by 'propertyName'. - * For convenience, a list of target properties (e.g., taken from - * a file or resource) can be passed without any filtering. This - * function will do nothing if the list of target properties doesn't - * include the property given by 'propertyName'. + } + /** + * A type that can assume one of several types. + * + * @author Marten Lohstroh + */ + public enum UnionType implements TargetPropertyType { + STRING_OR_STRING_ARRAY(Arrays.asList(PrimitiveType.STRING, ArrayType.STRING_ARRAY), null), + PLATFORM_STRING_OR_DICTIONARY( + Arrays.asList(PrimitiveType.STRING, DictionaryType.PLATFORM_DICT), null), + FILE_OR_FILE_ARRAY(Arrays.asList(PrimitiveType.FILE, ArrayType.FILE_ARRAY), null), + BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), + COORDINATION_UNION(Arrays.asList(CoordinationType.values()), CoordinationType.CENTRALIZED), + SCHEDULER_UNION(Arrays.asList(SchedulerOption.values()), SchedulerOption.getDefault()), + LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), + PLATFORM_UNION(Arrays.asList(Platform.values()), Platform.AUTO), + CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), ClockSyncMode.INIT), + DOCKER_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.DOCKER_DICT), null), + TRACING_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.TRACING_DICT), null); + + /** The constituents of this type union. */ + public final List> options; + + /** The default type, if there is one. */ + private final Enum defaultOption; + + /** + * Private constructor for creating unions types. * - * @param config The target config to apply the update to. - * @param property The target property. - * @param properties AST node that holds all the target properties. - * @param err Error reporter on which property format errors will be reported + * @param options The types that that are part of the union. + * @param defaultOption The default type. */ - public static void updateOne(TargetConfig config, TargetProperty property, List properties, ErrorReporter err) { - properties.stream() - .filter(p -> p.getName().equals(property.getDisplayName())) - .findFirst() - .map(KeyValuePair::getValue) - .ifPresent(value -> property.updater.parseIntoTargetConfig( - config, - value, - err - )); + private UnionType(List> options, Enum defaultOption) { + this.options = options; + this.defaultOption = defaultOption; } /** - * Return the entry that matches the given string. - * @param name The string to match against. - */ - public static TargetProperty forName(String name) { - return Target.match(name, TargetProperty.values()); - } - - /** - * Return a list with all target properties. + * Return the type among those in this type union that matches the given name. * - * @return All existing target properties. + * @param name The string to match against. + * @return The matching dictionary element (or null if there is none). */ - public static List getOptions() { - return Arrays.asList(TargetProperty.values()); + public Enum forName(String name) { + return Target.match(name, options); } - /** - * Return the description. - */ + /** Recursively check that the passed in element conforms to the rules of this union. */ @Override - public String toString() { - return this.description; + public void check(Element e, String name, LFValidator v) { + Optional> match = this.match(e); + if (match.isPresent()) { + // Go deeper if the element is an array or dictionary. + Enum type = match.get(); + if (type instanceof DictionaryType) { + ((DictionaryType) type).check(e, name, v); + } else if (type instanceof ArrayType) { + ((ArrayType) type).check(e, name, v); + } else if (type instanceof PrimitiveType) { + ((PrimitiveType) type).check(e, name, v); + } else if (!(type instanceof Enum)) { + throw new RuntimeException("Encountered an unknown type."); + } + } else { + // No match found; report error. + TargetPropertyType.produceError(name, this.toString(), v); + } } - // Inner classes for the various supported types. - /** - * Dictionary type that allows for keys that will be interpreted as strings - * and string values. + * Internal method for matching a given element against the allowable types. + * + * @param e AST node that represents the value of a target property. + * @return The matching type wrapped in an Optional object. */ - public enum StringDictionaryType implements TargetPropertyType { - COMPILE_DEFINITION(); - @Override - public boolean validate(Element e) { - if (e.getKeyvalue() != null) { - return true; - } - return false; - } - - @Override - public void check(Element e, String name, LFValidator v) { - KeyValuePairs kv = e.getKeyvalue(); - if (kv == null) { - TargetPropertyType.produceError(name, this.toString(), v); - } else { - for (KeyValuePair pair : kv.getPairs()) { - String key = pair.getName(); - Element val = pair.getValue(); - - // Make sure the type is string - PrimitiveType.STRING.check(val, name + "." + key, v); + private Optional> match(Element e) { + return this.options.stream() + .filter( + option -> { + if (option instanceof TargetPropertyType) { + return ((TargetPropertyType) option).validate(e); + } else { + return ASTUtils.elementToSingleString(e).equalsIgnoreCase(option.toString()); } - } - - } + }) + .findAny(); } /** - * Interface for dictionary elements. It associates an entry with a type. + * Return true if this union has an option that matches the given element. + * + * @param e The element to match against this type. */ - public interface DictionaryElement { - - TargetPropertyType getType(); + @Override + public boolean validate(Element e) { + if (this.match(e).isPresent()) { + return true; + } + return false; } /** - * A dictionary type with a predefined set of possible keys and assignable - * types. - * - * @author Marten Lohstroh - * + * Return a human-readable description of this type. If three is a default option, then indicate + * it. */ - public enum DictionaryType implements TargetPropertyType { - CLOCK_SYNC_OPTION_DICT(Arrays.asList(ClockSyncOption.values())), - DOCKER_DICT(Arrays.asList(DockerOption.values())), - PLATFORM_DICT(Arrays.asList(PlatformOption.values())), - COORDINATION_OPTION_DICT(Arrays.asList(CoordinationOption.values())), - TRACING_DICT(Arrays.asList(TracingOption.values())); - - /** - * The keys and assignable types that are allowed in this dictionary. - */ - public List options; - - /** - * A dictionary type restricted to sets of predefined keys and types of - * values. - * - * @param options The dictionary elements allowed by this type. - */ - private DictionaryType(List options) { - this.options = options; - } - - /** - * Return the dictionary element of which the key matches the given - * string. - * - * @param name The string to match against. - * @return The matching dictionary element (or null if there is none). - */ - public DictionaryElement forName(String name) { - return Target.match(name, options); - } - - /** - * Recursively check that the passed in element conforms to the rules of - * this dictionary. - */ - @Override - public void check(Element e, String name, LFValidator v) { - KeyValuePairs kv = e.getKeyvalue(); - if (kv == null) { - TargetPropertyType.produceError(name, this.toString(), v); - } else { - for (KeyValuePair pair : kv.getPairs()) { - String key = pair.getName(); - Element val = pair.getValue(); - Optional match = this.options.stream() - .filter(element -> key.equalsIgnoreCase(element.toString())).findAny(); - if (match.isPresent()) { - // Make sure the type is correct, too. - TargetPropertyType type = match.get().getType(); - type.check(val, name + "." + key, v); + @Override + public String toString() { + return "one of the following: " + + options.stream() + .map( + option -> { + if (option == this.defaultOption) { + return option.toString() + " (default)"; } else { - // No match found; report error. - TargetPropertyType.produceError(name, - this.toString(), v); + return option.toString(); } - } - } - } - - /** - * Return true if the given element represents a dictionary, false - * otherwise. - */ - @Override - public boolean validate(Element e) { - if (e.getKeyvalue() != null) { - return true; - } - return false; - } - - /** - * Return a human-readable description of this type. - */ - @Override - public String toString() { - return "a dictionary with one or more of the following keys: " - + options.stream().map(option -> option.toString()) - .collect(Collectors.joining(", ")); - } + }) + .collect(Collectors.joining(", ")); } - /** - * A type that can assume one of several types. - * - * @author Marten Lohstroh - * - */ - public enum UnionType implements TargetPropertyType { - STRING_OR_STRING_ARRAY( - Arrays.asList(PrimitiveType.STRING, ArrayType.STRING_ARRAY), - null), - PLATFORM_STRING_OR_DICTIONARY( - Arrays.asList(PrimitiveType.STRING, DictionaryType.PLATFORM_DICT), - null), - FILE_OR_FILE_ARRAY( - Arrays.asList(PrimitiveType.FILE, ArrayType.FILE_ARRAY), null), - BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), - COORDINATION_UNION(Arrays.asList(CoordinationType.values()), - CoordinationType.CENTRALIZED), - SCHEDULER_UNION(Arrays.asList(SchedulerOption.values()), SchedulerOption.getDefault()), - LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), - PLATFORM_UNION(Arrays.asList(Platform.values()), Platform.AUTO), - CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), - ClockSyncMode.INIT), - DOCKER_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.DOCKER_DICT), - null), - TRACING_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.TRACING_DICT), - null); - - /** - * The constituents of this type union. - */ - public final List> options; - - /** - * The default type, if there is one. - */ - private final Enum defaultOption; - - /** - * Private constructor for creating unions types. - * - * @param options The types that that are part of the union. - * @param defaultOption The default type. - */ - private UnionType(List> options, Enum defaultOption) { - this.options = options; - this.defaultOption = defaultOption; - } - - /** - * Return the type among those in this type union that matches the given - * name. - * - * @param name The string to match against. - * @return The matching dictionary element (or null if there is none). - */ - public Enum forName(String name) { - return Target.match(name, options); - } - - /** - * Recursively check that the passed in element conforms to the rules of - * this union. - */ - @Override - public void check(Element e, String name, LFValidator v) { - Optional> match = this.match(e); - if (match.isPresent()) { - // Go deeper if the element is an array or dictionary. - Enum type = match.get(); - if (type instanceof DictionaryType) { - ((DictionaryType) type).check(e, name, v); - } else if (type instanceof ArrayType) { - ((ArrayType) type).check(e, name, v); - } else if (type instanceof PrimitiveType) { - ((PrimitiveType) type).check(e, name, v); - } else if (!(type instanceof Enum)) { - throw new RuntimeException("Encountered an unknown type."); - } - } else { - // No match found; report error. - TargetPropertyType.produceError(name, this.toString(), v); - } - } - - /** - * Internal method for matching a given element against the allowable - * types. - * - * @param e AST node that represents the value of a target property. - * @return The matching type wrapped in an Optional object. - */ - private Optional> match(Element e) { - return this.options.stream().filter(option -> { - if (option instanceof TargetPropertyType) { - return ((TargetPropertyType) option).validate(e); - } else { - return ASTUtils.elementToSingleString(e) - .equalsIgnoreCase(option.toString()); - } - }).findAny(); - } + } - /** - * Return true if this union has an option that matches the given - * element. - * @param e The element to match against this type. - */ - @Override - public boolean validate(Element e) { - if (this.match(e).isPresent()) { - return true; - } - return false; - } - - /** - * Return a human-readable description of this type. If three is a - * default option, then indicate it. - */ - @Override - public String toString() { - return "one of the following: " + options.stream().map(option -> { - if (option == this.defaultOption) { - return option.toString() + " (default)"; - } else { - return option.toString(); - } - }).collect(Collectors.joining(", ")); - } + /** + * An array type of which the elements confirm to a given type. + * + * @author Marten Lohstroh + */ + public enum ArrayType implements TargetPropertyType { + STRING_ARRAY(PrimitiveType.STRING), + FILE_ARRAY(PrimitiveType.FILE); - } + /** Type parameter of this array type. */ + public TargetPropertyType type; /** - * An array type of which the elements confirm to a given type. - * - * @author Marten Lohstroh + * Private constructor to create a new array type. * + * @param type The type of elements in the array. */ - public enum ArrayType implements TargetPropertyType { - STRING_ARRAY(PrimitiveType.STRING), - FILE_ARRAY(PrimitiveType.FILE); - - /** - * Type parameter of this array type. - */ - public TargetPropertyType type; - - /** - * Private constructor to create a new array type. - * - * @param type The type of elements in the array. - */ - private ArrayType(TargetPropertyType type) { - this.type = type; - } - - /** - * Check that the passed in element represents an array and ensure that - * its elements are all of the correct type. - */ - @Override - public void check(Element e, String name, LFValidator v) { - Array array = e.getArray(); - if (array == null) { - TargetPropertyType.produceError(name, this.toString(), v); - } else { - List elements = array.getElements(); - for (int i = 0; i < elements.size(); i++) { - this.type.check(elements.get(i), name + "[" + i + "]", v); - } - } - } - - /** - * Return true of the given element is an array. - */ - @Override - public boolean validate(Element e) { - if (e.getArray() != null) { - return true; - } - return false; - } - - /** - * Return a human-readable description of this type. - */ - @Override - public String toString() { - return "an array of which each element is " + this.type.toString(); - } + private ArrayType(TargetPropertyType type) { + this.type = type; } /** - * Enumeration of Cmake build types. These are also mapped - * to Cargo profiles for the Rust target (see {@link org.lflang.generator.rust.RustTargetConfig}) - * - * @author Christian Menard + * Check that the passed in element represents an array and ensure that its elements are all of + * the correct type. */ - public enum BuildType { - RELEASE("Release"), - DEBUG("Debug"), - TEST("Test"), - REL_WITH_DEB_INFO("RelWithDebInfo"), - MIN_SIZE_REL("MinSizeRel"); - - /** - * Alias used in toString method. - */ - private final String alias; - - /** - * Private constructor for Cmake build types. - */ - BuildType(String alias) { - this.alias = alias; + @Override + public void check(Element e, String name, LFValidator v) { + Array array = e.getArray(); + if (array == null) { + TargetPropertyType.produceError(name, this.toString(), v); + } else { + List elements = array.getElements(); + for (int i = 0; i < elements.size(); i++) { + this.type.check(elements.get(i), name + "[" + i + "]", v); } + } + } - /** - * Return the alias. - */ - @Override - public String toString() { - return this.alias; - } + /** Return true of the given element is an array. */ + @Override + public boolean validate(Element e) { + if (e.getArray() != null) { + return true; + } + return false; } - /** - * Enumeration of coordination types. - * - * @author Marten Lohstroh - */ - public enum CoordinationType { - CENTRALIZED, DECENTRALIZED; - - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } + /** Return a human-readable description of this type. */ + @Override + public String toString() { + return "an array of which each element is " + this.type.toString(); + } + } + + /** + * Enumeration of Cmake build types. These are also mapped to Cargo profiles for the Rust target + * (see {@link org.lflang.generator.rust.RustTargetConfig}) + * + * @author Christian Menard + */ + public enum BuildType { + RELEASE("Release"), + DEBUG("Debug"), + TEST("Test"), + REL_WITH_DEB_INFO("RelWithDebInfo"), + MIN_SIZE_REL("MinSizeRel"); + + /** Alias used in toString method. */ + private final String alias; + + /** Private constructor for Cmake build types. */ + BuildType(String alias) { + this.alias = alias; + } + + /** Return the alias. */ + @Override + public String toString() { + return this.alias; + } + } + + /** + * Enumeration of coordination types. + * + * @author Marten Lohstroh + */ + public enum CoordinationType { + CENTRALIZED, + DECENTRALIZED; + + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); + } + } + + /** + * Enumeration of clock synchronization modes. + * + *
      + *
    • OFF: The clock synchronization is universally off. + *
    • STARTUP: Clock synchronization occurs at startup only. + *
    • ON: Clock synchronization occurs at startup and at runtime. + *
    + * + * @author Edward A. Lee + */ + public enum ClockSyncMode { + OFF, + INIT, + ON; // TODO Discuss initial in now a mode keyword (same as startup) and cannot be used as target + // property value, thus changed it to init + // FIXME I could not test if this change breaks anything + + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); } + } + /** + * An interface for types associated with target properties. + * + * @author Marten Lohstroh + */ + public interface TargetPropertyType { /** - * Enumeration of clock synchronization modes. + * Return true if the the given Element is a valid instance of this type. * - *
      - *
    • OFF: The clock synchronization is universally off.
    • - *
    • STARTUP: Clock synchronization occurs at startup only.
    • - *
    • ON: Clock synchronization occurs at startup and at runtime.
    • - *
    - * - * @author Edward A. Lee + * @param e The Element to validate. + * @return True if the element conforms to this type, false otherwise. */ - public enum ClockSyncMode { - OFF, INIT, ON; // TODO Discuss initial in now a mode keyword (same as startup) and cannot be used as target property value, thus changed it to init - // FIXME I could not test if this change breaks anything - - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } - } + public boolean validate(Element e); /** - * An interface for types associated with target properties. + * Check (recursively) the given Element against its associated type(s) and add found problems + * to the given list of errors. * - * @author Marten Lohstroh + * @param e The Element to type check. + * @param name The name of the target property. + * @param v A reference to the validator to report errors to. */ - public interface TargetPropertyType { - - /** - * Return true if the the given Element is a valid instance of this - * type. - * - * @param e The Element to validate. - * @return True if the element conforms to this type, false otherwise. - */ - public boolean validate(Element e); - - /** - * Check (recursively) the given Element against its associated type(s) - * and add found problems to the given list of errors. - * - * @param e The Element to type check. - * @param name The name of the target property. - * @param v A reference to the validator to report errors to. - */ - public void check(Element e, String name, LFValidator v); - - /** - * Helper function to produce an error during type checking. - * - * @param name The description of the target property. - * @param description The description of the type. - * @param v A reference to the validator to report errors to. - */ - public static void produceError(String name, String description, - LFValidator v) { - v.getTargetPropertyErrors().add("Target property '" + name - + "' is required to be " + description + "."); - } - } + public void check(Element e, String name, LFValidator v); /** - * Primitive types for target properties, each with a description used in - * error messages and predicate used for validating values. + * Helper function to produce an error during type checking. * - * @author Marten Lohstroh + * @param name The description of the target property. + * @param description The description of the type. + * @param v A reference to the validator to report errors to. */ - public enum PrimitiveType implements TargetPropertyType { - BOOLEAN("'true' or 'false'", - v -> ASTUtils.elementToSingleString(v).equalsIgnoreCase("true") - || ASTUtils.elementToSingleString(v).equalsIgnoreCase("false")), - INTEGER("an integer", v -> { - try { - Integer.parseInt(ASTUtils.elementToSingleString(v)); - } catch (NumberFormatException e) { - return false; - } - return true; + public static void produceError(String name, String description, LFValidator v) { + v.getTargetPropertyErrors() + .add("Target property '" + name + "' is required to be " + description + "."); + } + } + + /** + * Primitive types for target properties, each with a description used in error messages and + * predicate used for validating values. + * + * @author Marten Lohstroh + */ + public enum PrimitiveType implements TargetPropertyType { + BOOLEAN( + "'true' or 'false'", + v -> + ASTUtils.elementToSingleString(v).equalsIgnoreCase("true") + || ASTUtils.elementToSingleString(v).equalsIgnoreCase("false")), + INTEGER( + "an integer", + v -> { + try { + Integer.parseInt(ASTUtils.elementToSingleString(v)); + } catch (NumberFormatException e) { + return false; + } + return true; }), - NON_NEGATIVE_INTEGER("a non-negative integer", v -> { - try { - int result = Integer.parseInt(ASTUtils.elementToSingleString(v)); - if (result < 0) - return false; - } catch (NumberFormatException e) { - return false; - } - return true; + NON_NEGATIVE_INTEGER( + "a non-negative integer", + v -> { + try { + int result = Integer.parseInt(ASTUtils.elementToSingleString(v)); + if (result < 0) return false; + } catch (NumberFormatException e) { + return false; + } + return true; }), - TIME_VALUE("a time value with units", v -> - v.getKeyvalue() == null && v.getArray() == null - && v.getLiteral() == null && v.getId() == null + TIME_VALUE( + "a time value with units", + v -> + v.getKeyvalue() == null + && v.getArray() == null + && v.getLiteral() == null + && v.getId() == null && (v.getTime() == 0 || v.getUnit() != null)), - STRING("a string", v -> v.getLiteral() != null && !isCharLiteral(v.getLiteral()) || v.getId() != null), - FILE("a path to a file", STRING.validator); - - /** - * A description of this type, featured in error messages. - */ - private final String description; - - /** - * A predicate for determining whether a given Element conforms to this - * type. - */ - public final Predicate validator; - - /** - * Private constructor to create a new primitive type. - * @param description A textual description of the type that should - * start with "a/an". - * @param validator A predicate that returns true if a given Element - * conforms to this type. - */ - private PrimitiveType(String description, - Predicate validator) { - this.description = description; - this.validator = validator; - } + STRING( + "a string", + v -> v.getLiteral() != null && !isCharLiteral(v.getLiteral()) || v.getId() != null), + FILE("a path to a file", STRING.validator); - /** - * Return true if the the given Element is a valid instance of this type. - */ - public boolean validate(Element e) { - return this.validator.test(e); - } + /** A description of this type, featured in error messages. */ + private final String description; - /** - * Check (recursively) the given Element against its associated type(s) - * and add found problems to the given list of errors. - * - * @param e The element to type check. - * @param name The name of the target property. - * @param v The LFValidator to append errors to. - */ - public void check(Element e, String name, LFValidator v) { - if (!this.validate(e)) { - TargetPropertyType.produceError(name, this.description, v); - } - // If this is a file, perform an additional check to make sure - // the file actually exists. - // FIXME: premature because we first need a mechanism for looking up files! - // Looking in the same directory is too restrictive. Disabling this check for now. - /* - if (this == FILE) { - String file = ASTUtils.toSingleString(e); - - if (!FileConfig.fileExists(file, FileConfig.toPath(e.eResource().getURI()).toFile().getParent())) { - v.targetPropertyWarnings - .add("Could not find file: '" + file + "'."); - } - } - */ - } - - /** - * Return a textual description of this type. - */ - @Override - public String toString() { - return this.description; - } - - - private static boolean isCharLiteral(String s) { - return s.length() > 2 - && '\'' == s.charAt(0) - && '\'' == s.charAt(s.length() - 1); - } - } + /** A predicate for determining whether a given Element conforms to this type. */ + public final Predicate validator; /** - * Clock synchronization options. - * @author Marten Lohstroh + * Private constructor to create a new primitive type. + * + * @param description A textual description of the type that should start with "a/an". + * @param validator A predicate that returns true if a given Element conforms to this type. */ - public enum ClockSyncOption implements DictionaryElement { - ATTENUATION("attenuation", PrimitiveType.NON_NEGATIVE_INTEGER), - LOCAL_FEDERATES_ON("local-federates-on", PrimitiveType.BOOLEAN), - PERIOD("period", PrimitiveType.TIME_VALUE), - TEST_OFFSET("test-offset", PrimitiveType.TIME_VALUE), - TRIALS("trials", PrimitiveType.NON_NEGATIVE_INTEGER), - COLLECT_STATS("collect-stats", PrimitiveType.BOOLEAN); - - public final PrimitiveType type; - - private final String description; - - private ClockSyncOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } - - - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + private PrimitiveType(String description, Predicate validator) { + this.description = description; + this.validator = validator; + } - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + /** Return true if the the given Element is a valid instance of this type. */ + public boolean validate(Element e) { + return this.validator.test(e); } /** - * Docker options. - * @author Edward A. Lee - */ - public enum DockerOption implements DictionaryElement { - FROM("FROM", PrimitiveType.STRING); - - public final PrimitiveType type; - - private final String description; - - private DockerOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } - - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + * Check (recursively) the given Element against its associated type(s) and add found problems + * to the given list of errors. + * + * @param e The element to type check. + * @param name The name of the target property. + * @param v The LFValidator to append errors to. + */ + public void check(Element e, String name, LFValidator v) { + if (!this.validate(e)) { + TargetPropertyType.produceError(name, this.description, v); + } + // If this is a file, perform an additional check to make sure + // the file actually exists. + // FIXME: premature because we first need a mechanism for looking up files! + // Looking in the same directory is too restrictive. Disabling this check for now. + /* + if (this == FILE) { + String file = ASTUtils.toSingleString(e); + + if (!FileConfig.fileExists(file, FileConfig.toPath(e.eResource().getURI()).toFile().getParent())) { + v.targetPropertyWarnings + .add("Could not find file: '" + file + "'."); + } + } + */ + } - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + /** Return a textual description of this type. */ + @Override + public String toString() { + return this.description; } + private static boolean isCharLiteral(String s) { + return s.length() > 2 && '\'' == s.charAt(0) && '\'' == s.charAt(s.length() - 1); + } + } + + /** + * Clock synchronization options. + * + * @author Marten Lohstroh + */ + public enum ClockSyncOption implements DictionaryElement { + ATTENUATION("attenuation", PrimitiveType.NON_NEGATIVE_INTEGER), + LOCAL_FEDERATES_ON("local-federates-on", PrimitiveType.BOOLEAN), + PERIOD("period", PrimitiveType.TIME_VALUE), + TEST_OFFSET("test-offset", PrimitiveType.TIME_VALUE), + TRIALS("trials", PrimitiveType.NON_NEGATIVE_INTEGER), + COLLECT_STATS("collect-stats", PrimitiveType.BOOLEAN); + + public final PrimitiveType type; + + private final String description; + + private ClockSyncOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; + } - /** - * Platform options. - * @author Anirudh Rengarajan - */ - public enum PlatformOption implements DictionaryElement { - NAME("name", PrimitiveType.STRING), - BAUDRATE("baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), - BOARD("board", PrimitiveType.STRING), - FLASH("flash", PrimitiveType.BOOLEAN), - PORT("port", PrimitiveType.STRING); + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; + } - public final PrimitiveType type; + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } - private final String description; + /** + * Docker options. + * + * @author Edward A. Lee + */ + public enum DockerOption implements DictionaryElement { + FROM("FROM", PrimitiveType.STRING); - private PlatformOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } + public final PrimitiveType type; + private final String description; - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + private DockerOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; + } - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; } - /** - * Coordination options. - * @author Edward A. Lee - */ - public enum CoordinationOption implements DictionaryElement { - ADVANCE_MESSAGE_INTERVAL("advance-message-interval", PrimitiveType.TIME_VALUE); + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } + + /** + * Platform options. + * + * @author Anirudh Rengarajan + */ + public enum PlatformOption implements DictionaryElement { + NAME("name", PrimitiveType.STRING), + BAUDRATE("baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), + BOARD("board", PrimitiveType.STRING), + FLASH("flash", PrimitiveType.BOOLEAN), + PORT("port", PrimitiveType.STRING); + + public final PrimitiveType type; + + private final String description; + + private PlatformOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; + } - public final PrimitiveType type; + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; + } - private final String description; + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } - private CoordinationOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } + /** + * Coordination options. + * + * @author Edward A. Lee + */ + public enum CoordinationOption implements DictionaryElement { + ADVANCE_MESSAGE_INTERVAL("advance-message-interval", PrimitiveType.TIME_VALUE); + public final PrimitiveType type; - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + private final String description; - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + private CoordinationOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; } - /** - * Log levels in descending order of severity. - * @author Marten Lohstroh - */ - public enum LogLevel { - ERROR, WARN, INFO, LOG, DEBUG; - - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; } - /** - * Enumeration of supported platforms - */ - public enum Platform { - AUTO, - ARDUINO, - NRF52("Nrf52"), - LINUX("Linux"), - MAC("Darwin"), - ZEPHYR("Zephyr"), - WINDOWS("Windows"); - - String cMakeName; - Platform() { - this.cMakeName = this.toString(); - } - Platform(String cMakeName) { - this.cMakeName = cMakeName; - } + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } + + /** + * Log levels in descending order of severity. + * + * @author Marten Lohstroh + */ + public enum LogLevel { + ERROR, + WARN, + INFO, + LOG, + DEBUG; + + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); + } + } + + /** Enumeration of supported platforms */ + public enum Platform { + AUTO, + ARDUINO, + NRF52("Nrf52"), + LINUX("Linux"), + MAC("Darwin"), + ZEPHYR("Zephyr"), + WINDOWS("Windows"); + + String cMakeName; + + Platform() { + this.cMakeName = this.toString(); + } - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } + Platform(String cMakeName) { + this.cMakeName = cMakeName; + } - /** - * Get the CMake name for the platform. - */ - public String getcMakeName() { - return this.cMakeName; - } + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); } - /** - * Supported schedulers. - * @author Soroush Bateni - */ - public enum SchedulerOption { - NP(false), // Non-preemptive - ADAPTIVE(false, List.of( + /** Get the CMake name for the platform. */ + public String getcMakeName() { + return this.cMakeName; + } + } + + /** + * Supported schedulers. + * + * @author Soroush Bateni + */ + public enum SchedulerOption { + NP(false), // Non-preemptive + ADAPTIVE( + false, + List.of( Path.of("scheduler_adaptive.c"), Path.of("worker_assignments.h"), Path.of("worker_states.h"), - Path.of("data_collection.h") - )), - GEDF_NP(true), // Global EDF non-preemptive - GEDF_NP_CI(true); // Global EDF non-preemptive with chain ID - // PEDF_NP(true); // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) - - /** - * Indicate whether or not the scheduler prioritizes reactions by deadline. - */ - private final boolean prioritizesDeadline; - - /** Relative paths to files required by this scheduler. */ - private final List relativePaths; - - SchedulerOption(boolean prioritizesDeadline) { - this(prioritizesDeadline, null); - } + Path.of("data_collection.h"))), + GEDF_NP(true), // Global EDF non-preemptive + GEDF_NP_CI(true); // Global EDF non-preemptive with chain ID + // PEDF_NP(true); // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) - SchedulerOption(boolean prioritizesDeadline, List relativePaths) { - this.prioritizesDeadline = prioritizesDeadline; - this.relativePaths = relativePaths; - } + /** Indicate whether or not the scheduler prioritizes reactions by deadline. */ + private final boolean prioritizesDeadline; - /** - * Return true if the scheduler prioritizes reactions by deadline. - */ - public boolean prioritizesDeadline() { - return this.prioritizesDeadline; - } + /** Relative paths to files required by this scheduler. */ + private final List relativePaths; - public List getRelativePaths() { - return relativePaths != null ? ImmutableList.copyOf(relativePaths) : - List.of(Path.of("scheduler_" + this + ".c")); - } + SchedulerOption(boolean prioritizesDeadline) { + this(prioritizesDeadline, null); + } - public static SchedulerOption getDefault() { - return NP; - } + SchedulerOption(boolean prioritizesDeadline, List relativePaths) { + this.prioritizesDeadline = prioritizesDeadline; + this.relativePaths = relativePaths; } - /** - * Tracing options. - * @author Edward A. Lee - */ - public enum TracingOption implements DictionaryElement { - TRACE_FILE_NAME("trace-file-name", PrimitiveType.STRING); + /** Return true if the scheduler prioritizes reactions by deadline. */ + public boolean prioritizesDeadline() { + return this.prioritizesDeadline; + } - public final PrimitiveType type; + public List getRelativePaths() { + return relativePaths != null + ? ImmutableList.copyOf(relativePaths) + : List.of(Path.of("scheduler_" + this + ".c")); + } - private final String description; + public static SchedulerOption getDefault() { + return NP; + } + } - private TracingOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } + /** + * Tracing options. + * + * @author Edward A. Lee + */ + public enum TracingOption implements DictionaryElement { + TRACE_FILE_NAME("trace-file-name", PrimitiveType.STRING); - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + public final PrimitiveType type; - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + private final String description; + + private TracingOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; } + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; + } + + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } } diff --git a/org.lflang/src/org/lflang/TimeUnit.java b/org.lflang/src/org/lflang/TimeUnit.java index 00c6314e51..a39bd505e8 100644 --- a/org.lflang/src/org/lflang/TimeUnit.java +++ b/org.lflang/src/org/lflang/TimeUnit.java @@ -38,82 +38,73 @@ * @author Clément Fournier, TU Dresden, INSA Rennes */ public enum TimeUnit { - /** Nanoseconds. */ - NANO("nsec", "ns", "nsecs"), - /** Microseconds. */ - MICRO("usec", "us", "usecs"), - /** Milliseconds. */ - MILLI("msec", "ms", "msecs"), - /** Seconds. */ - SECOND("sec", "s", "secs", "second", "seconds"), - /** Minute. */ // NOTE: Do not use MIN as the first entry. Common macro for minimum. - MINUTE("minute", "min", "mins", "minutes"), - /** Hour. */ - HOUR("hour", "h", "hours"), - /** Day. */ - DAY("day", "d", "days"), - WEEK("week", "weeks"), - ; + /** Nanoseconds. */ + NANO("nsec", "ns", "nsecs"), + /** Microseconds. */ + MICRO("usec", "us", "usecs"), + /** Milliseconds. */ + MILLI("msec", "ms", "msecs"), + /** Seconds. */ + SECOND("sec", "s", "secs", "second", "seconds"), + /** Minute. */ + // NOTE: Do not use MIN as the first entry. Common macro for minimum. + MINUTE("minute", "min", "mins", "minutes"), + /** Hour. */ + HOUR("hour", "h", "hours"), + /** Day. */ + DAY("day", "d", "days"), + WEEK("week", "weeks"), + ; - private final Set allNames; - private final String canonicalName; + private final Set allNames; + private final String canonicalName; - TimeUnit(String canonicalName, String... aliases) { - this.canonicalName = canonicalName; - this.allNames = immutableSetOf(canonicalName, aliases); - } + TimeUnit(String canonicalName, String... aliases) { + this.canonicalName = canonicalName; + this.allNames = immutableSetOf(canonicalName, aliases); + } + /** Returns the name that is preferred when displaying this unit. */ + public String getCanonicalName() { + return canonicalName; + } - /** - * Returns the name that is preferred when displaying this unit. - */ - public String getCanonicalName() { - return canonicalName; - } + /** Returns true if the given name is one of the aliases of this unit. */ + public boolean hasAlias(String name) { + return allNames.contains(name); + } - /** Returns true if the given name is one of the aliases of this unit. */ - public boolean hasAlias(String name) { - return allNames.contains(name); + /** + * Returns the constant corresponding to the given name. The comparison is case-sensitive. + * + * @return Null if the parameter is null, otherwise a non-null constant + * @throws IllegalArgumentException If the name doesn't correspond to any constant + */ + public static TimeUnit fromName(String name) { + if (name == null) { + return null; } + return Arrays.stream(values()) + .filter(it -> it.hasAlias(name)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("invalid name '" + name + "'")); + } - - /** - * Returns the constant corresponding to the given name. - * The comparison is case-sensitive. - * - * @return Null if the parameter is null, otherwise a non-null constant - * @throws IllegalArgumentException If the name doesn't correspond to any constant - */ - public static TimeUnit fromName(String name) { - if (name == null) { - return null; - } - return Arrays.stream(values()) - .filter(it -> it.hasAlias(name)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("invalid name '" + name + "'")); + /** Returns true if the parameter is null, or it is the alias of a valid time unit. */ + public static boolean isValidUnit(String name) { + if (name == null) { + return false; } + return Arrays.stream(values()).anyMatch(it -> it.hasAlias(name)); + } - /** - * Returns true if the parameter is null, or it is the - * alias of a valid time unit. - */ - public static boolean isValidUnit(String name) { - if (name == null) { - return false; - } - return Arrays.stream(values()).anyMatch(it -> it.hasAlias(name)); - } + /** Returns a list of all possible aliases for time values. */ + public static List list() { + return Arrays.stream(values()).flatMap(it -> it.allNames.stream()).collect(Collectors.toList()); + } - /** - * Returns a list of all possible aliases for time values. - */ - public static List list() { - return Arrays.stream(values()).flatMap(it -> it.allNames.stream()).collect(Collectors.toList()); - } - - @Override - public String toString() { - return this.canonicalName; - } + @Override + public String toString() { + return this.canonicalName; + } } diff --git a/org.lflang/src/org/lflang/TimeValue.java b/org.lflang/src/org/lflang/TimeValue.java index f008a0ae4b..f0bb94820c 100644 --- a/org.lflang/src/org/lflang/TimeValue.java +++ b/org.lflang/src/org/lflang/TimeValue.java @@ -1,27 +1,27 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; @@ -33,172 +33,152 @@ */ 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); - - - /** - * Primitive numerical representation of this time value, - * to be interpreted in terms the associated time unit. - */ - public final long time; - - /** - * Units associated with this time value. May be null. - */ - public final TimeUnit unit; - - /** - * Maximum size of a deadline in primitive representation. - * NOTE: if we were to use an unsigned data type this would be - * 0xFFFFFFFFFFFF - */ - public static final long MAX_LONG_DEADLINE = Long.decode("0x7FFFFFFFFFFF"); - - /** - * Create a new time value. - * - * @throws IllegalArgumentException If time is non-zero and the unit is null - */ - public TimeValue(long time, TimeUnit unit) { - if (unit == null && time != 0) { - throw new IllegalArgumentException("Non-zero time values must have a unit"); - } - this.time = time; - this.unit = unit; - } - - @Override - public boolean equals(Object t1) { - if (t1 instanceof TimeValue) { - return this.compareTo((TimeValue) t1) == 0; - } - return false; - } - - public static int compare(TimeValue t1, TimeValue t2) { - if (t1.isEarlierThan(t2)) { - return -1; - } - if (t2.isEarlierThan(t1)) { - return 1; - } - return 0; - } - - private static long makeNanosecs(long time, TimeUnit unit) { - if (unit == null) { - return time; // == 0, see constructor. - } - switch (unit) { - case NANO: - return time; - case MICRO: - return time * 1000; - case MILLI: - return time * 1_000_000; - case SECOND: - return time * 1_000_000_000; - case MINUTE: - return time * 60_000_000_000L; - case HOUR: - return time * 3_600_000_000_000L; - case DAY: - return time * 86_400_000_000_000L; - case WEEK: - return time * 604_800_016_558_522L; - } - throw new AssertionError("unreachable"); - } - - /** - * Returns whether this time value is earlier than another. - */ - public boolean isEarlierThan(TimeValue other) { - return this.compareTo(other) < 0; + /** 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); + + /** + * Primitive numerical representation of this time value, to be interpreted in terms the + * associated time unit. + */ + public final long time; + + /** Units associated with this time value. May be null. */ + public final TimeUnit unit; + + /** + * Maximum size of a deadline in primitive representation. NOTE: if we were to use an unsigned + * data type this would be 0xFFFFFFFFFFFF + */ + public static final long MAX_LONG_DEADLINE = Long.decode("0x7FFFFFFFFFFF"); + + /** + * Create a new time value. + * + * @throws IllegalArgumentException If time is non-zero and the unit is null + */ + public TimeValue(long time, TimeUnit unit) { + if (unit == null && time != 0) { + throw new IllegalArgumentException("Non-zero time values must have a unit"); } - - @Override - public int compareTo(TimeValue o) { - return Long.compare(this.toNanoSeconds(), o.toNanoSeconds()); + this.time = time; + this.unit = unit; + } + + @Override + public boolean equals(Object t1) { + if (t1 instanceof TimeValue) { + return this.compareTo((TimeValue) t1) == 0; } + return false; + } - /** - * Return the magnitude of this value, as expressed in the - * {@linkplain #getUnit() unit} of this value. - */ - public long getMagnitude() { - return time; + public static int compare(TimeValue t1, TimeValue t2) { + if (t1.isEarlierThan(t2)) { + return -1; } - - /** - * Units associated with this time value. May be null, - * but only if the magnitude is zero. - */ - public TimeUnit getUnit() { - return unit; + if (t2.isEarlierThan(t1)) { + return 1; } + return 0; + } - /** - * Get this time value in number of nanoseconds. - */ - public long toNanoSeconds() { - return makeNanosecs(time, unit); + private static long makeNanosecs(long time, TimeUnit unit) { + if (unit == null) { + return time; // == 0, see constructor. } - - /** - * Return a string representation of this time value. - */ - public String toString() { - return unit != null ? time + " " + unit.getCanonicalName() - : Long.toString(time); + switch (unit) { + case NANO: + return time; + case MICRO: + return time * 1000; + case MILLI: + return time * 1_000_000; + case SECOND: + return time * 1_000_000_000; + case MINUTE: + return time * 60_000_000_000L; + case HOUR: + return time * 3_600_000_000_000L; + case DAY: + return time * 86_400_000_000_000L; + case WEEK: + return time * 604_800_016_558_522L; } - - /** Return the latest of both values. */ - public static TimeValue max(TimeValue t1, TimeValue t2) { - return t1.isEarlierThan(t2) ? t2 : t1; + throw new AssertionError("unreachable"); + } + + /** Returns whether this time value is earlier than another. */ + public boolean isEarlierThan(TimeValue other) { + return this.compareTo(other) < 0; + } + + @Override + public int compareTo(TimeValue o) { + return Long.compare(this.toNanoSeconds(), o.toNanoSeconds()); + } + + /** + * Return the magnitude of this value, as expressed in the {@linkplain #getUnit() unit} of this + * value. + */ + public long getMagnitude() { + return time; + } + + /** Units associated with this time value. May be null, but only if the magnitude is zero. */ + public TimeUnit getUnit() { + return unit; + } + + /** Get this time value in number of nanoseconds. */ + public long toNanoSeconds() { + return makeNanosecs(time, unit); + } + + /** Return a string representation of this time value. */ + public String toString() { + return unit != null ? time + " " + unit.getCanonicalName() : Long.toString(time); + } + + /** Return the latest of both values. */ + public static TimeValue max(TimeValue t1, TimeValue t2) { + return t1.isEarlierThan(t2) ? t2 : t1; + } + + /** Return the earliest of both values. */ + public static TimeValue min(TimeValue t1, TimeValue t2) { + return t1.isEarlierThan(t2) ? t1 : t2; + } + + /** + * Return the sum of this duration and the one represented by b. + * + *

    The unit of the returned TimeValue will be the minimum of the units of both operands except + * if only one of the units is TimeUnit.NONE. In that case, the unit of the other input is used. + * + * @param b The right operand + * @return A new TimeValue (the current value will not be affected) + */ + public TimeValue add(TimeValue b) { + // Figure out the actual sum + final long sumOfNumbers; + try { + sumOfNumbers = Math.addExact(this.toNanoSeconds(), b.toNanoSeconds()); + } catch (ArithmeticException overflow) { + return MAX_VALUE; } - /** Return the earliest of both values. */ - public static TimeValue min(TimeValue t1, TimeValue t2) { - return t1.isEarlierThan(t2) ? t1 : t2; + if (this.unit == null || b.unit == null) { + // A time value with no unit is necessarily zero. So + // if this is null, (this + b) == b, if b is none, (this+b) == this. + return b.unit == null ? this : b; } - - /** - * Return the sum of this duration and the one represented by b. - *

    - * The unit of the returned TimeValue will be the minimum - * of the units of both operands except if only one of the units - * is TimeUnit.NONE. In that case, the unit of the other input is used. - * - * @param b The right operand - * @return A new TimeValue (the current value will not be affected) - */ - public TimeValue add(TimeValue b) { - // Figure out the actual sum - final long sumOfNumbers; - try { - sumOfNumbers = Math.addExact(this.toNanoSeconds(), b.toNanoSeconds()); - } catch (ArithmeticException overflow) { - return MAX_VALUE; - } - - if (this.unit == null || b.unit == null) { - // A time value with no unit is necessarily zero. So - // if this is null, (this + b) == b, if b is none, (this+b) == this. - return b.unit == null ? this : b; - } - boolean isThisUnitSmallerThanBUnit = this.unit.compareTo(b.unit) <= 0; - TimeUnit smallestUnit = isThisUnitSmallerThanBUnit ? this.unit : b.unit; - // Find the appropriate divider to bring sumOfNumbers from nanoseconds to returnUnit - var unitDivider = makeNanosecs(1, smallestUnit); - return new TimeValue(sumOfNumbers / unitDivider, smallestUnit); - } - + boolean isThisUnitSmallerThanBUnit = this.unit.compareTo(b.unit) <= 0; + TimeUnit smallestUnit = isThisUnitSmallerThanBUnit ? this.unit : b.unit; + // Find the appropriate divider to bring sumOfNumbers from nanoseconds to returnUnit + var unitDivider = makeNanosecs(1, smallestUnit); + return new TimeValue(sumOfNumbers / unitDivider, smallestUnit); + } } diff --git a/org.lflang/src/org/lflang/ast/ASTUtils.java b/org.lflang/src/org/lflang/ast/ASTUtils.java index 26d4e0d6b0..91ff7ac69a 100644 --- a/org.lflang/src/org/lflang/ast/ASTUtils.java +++ b/org.lflang/src/org/lflang/ast/ASTUtils.java @@ -25,6 +25,9 @@ package org.lflang.ast; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -39,7 +42,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -54,7 +56,6 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; - import org.lflang.InferredType; import org.lflang.Target; import org.lflang.TimeUnit; @@ -100,1793 +101,1768 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.StringUtil; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; - /** * A helper class for modifying and analyzing the AST. + * * @author Marten Lohstroh * @author Edward A. Lee * @author Christian Menard */ public class ASTUtils { - /** - * The Lingua Franca factory for creating new AST nodes. - */ - public static final LfFactory factory = LfFactory.eINSTANCE; - - /** - * The Lingua Franca feature package. - */ - public static final LfPackage featurePackage = LfPackage.eINSTANCE; - - /* Match an abbreviated form of a float literal. */ - private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); - - /** - * A mapping from Reactor features to corresponding Mode features for collecting contained elements. - */ - private static final Map reactorModeFeatureMap = Map.of( - featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), - featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), - featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), - featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), - featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), - featurePackage.getReactor_Timers(), featurePackage.getMode_Timers() - ); - - - /** - * Get all reactors defined in the given resource. - * @param resource the resource to extract reactors from - * @return An iterable over all reactors found in the resource - */ - public static List getAllReactors(Resource resource) { - return StreamSupport.stream(IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) - .filter(Reactor.class::isInstance) - .map(Reactor.class::cast) - .collect(Collectors.toList()); - } - - /** - * Find connections in the given resource that would be conflicting writes if they were not located in mutually - * exclusive modes. - * - * @param resource The AST. - * @return a list of connections being able to be transformed - */ - public static Collection findConflictingConnectionsInModalReactors(Resource resource) { - var transform = new HashSet(); - - for (Reactor reactor : getAllReactors(resource)) { - if (!reactor.getModes().isEmpty()) { // Only for modal reactors - var allWriters = HashMultimap., EObject>create(); - - // Collect destinations - for (var rea : allReactions(reactor)) { - for (var eff : rea.getEffects()) { - if (eff.getVariable() instanceof Port) { - allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); - } - } - } - for (var con : ASTUtils.collectElements(reactor, featurePackage.getReactor_Connections(), false, true)) { - for (var port : con.getRightPorts()) { - allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); - } - } - - // Handle conflicting writers - for (var key : allWriters.keySet()) { - var writers = allWriters.get(key); - if (writers.size() > 1) { // has multiple sources - var writerModes = HashMultimap.create(); - // find modes - for (var writer : writers) { - if (writer.eContainer() instanceof Mode) { - writerModes.put((Mode) writer.eContainer(), writer); - } else { - writerModes.put(null, writer); - } - } - // Conflicting connection can only be handled if.. - if (!writerModes.containsKey(null) && // no writer is on root level (outside of modes) and... - writerModes.keySet().stream().map(writerModes::get).allMatch(writersInMode -> // all writers in a mode are either... - writersInMode.size() == 1 || // the only writer or... - writersInMode.stream().allMatch(w -> w instanceof Reaction) // all are reactions and hence ordered - )) { - // Add connections to transform list - writers.stream().filter(w -> w instanceof Connection).forEach(c -> transform.add((Connection) c)); - } - } - } - } - } - - return transform; - } - - /** - * Return the enclosing reactor of an LF EObject in a reactor or mode. - * @param obj the LF model element - * @return the reactor or null - */ - public static Reactor getEnclosingReactor(EObject obj) { - if (obj.eContainer() instanceof Reactor) { - return (Reactor) obj.eContainer(); - } else if (obj.eContainer() instanceof Mode) { - return (Reactor) obj.eContainer().eContainer(); - } - return null; - } - - /** - * Return the main reactor in the given resource if there is one, null otherwise. - */ - public static Reactor findMainReactor(Resource resource) { - return IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), - Reactor::isMain - ); - } - - /** - * Find the main reactor and change it to a federated reactor. - * Return true if the transformation was successful (or the given resource - * already had a federated reactor); return false otherwise. - */ - public static boolean makeFederated(Resource resource) { - // Find the main reactor - Reactor r = findMainReactor(resource); - if (r == null) { - return false; - } - r.setMain(false); - r.setFederated(true); - return true; - } - - /** - * Change the target name to 'newTargetName'. - * For example, change C to CCpp. - */ - public static boolean changeTargetName(Resource resource, String newTargetName) { - targetDecl(resource).setName(newTargetName); - return true; - } - - /** - * Return the target of the file in which the given node lives. - */ - public static Target getTarget(EObject object) { - TargetDecl targetDecl = targetDecl(object.eResource()); - return Target.fromDecl(targetDecl); - } - - /** - * Add a new target property to the given resource. - * This also creates a config object if the resource does not yey have one. - * - * @param resource The resource to modify - * @param name Name of the property to add - * @param value Value to be assigned to the property - */ - public static boolean addTargetProperty(final Resource resource, final String name, final Element value) { - var config = targetDecl(resource).getConfig(); - if (config == null) { - config = LfFactory.eINSTANCE.createKeyValuePairs(); - targetDecl(resource).setConfig(config); - } - final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); - newProperty.setName(name); - newProperty.setValue(value); - config.getPairs().add(newProperty); - return true; - } - - /** - * Return true if the connection involves multiple ports on the left or right side of the connection, or - * if the port on the left or right of the connection involves a bank of reactors or a multiport. - * @param connection The connection. - */ - public static boolean hasMultipleConnections(Connection connection) { - if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { - return true; - } - VarRef leftPort = connection.getLeftPorts().get(0); - VarRef rightPort = connection.getRightPorts().get(0); - Instantiation leftContainer = leftPort.getContainer(); - Instantiation rightContainer = rightPort.getContainer(); - Port leftPortAsPort = (Port) leftPort.getVariable(); - Port rightPortAsPort = (Port) rightPort.getVariable(); - return leftPortAsPort.getWidthSpec() != null - || leftContainer != null && leftContainer.getWidthSpec() != null - || rightPortAsPort.getWidthSpec() != null - || rightContainer != null && rightContainer.getWidthSpec() != null; - } - - /** - * Produce a unique identifier within a reactor based on a - * given based name. If the name does not exists, it is returned; - * if does exist, an index is appended that makes the name unique. - * @param reactor The reactor to find a unique identifier within. - * @param name The name to base the returned identifier on. - */ - public static String getUniqueIdentifier(Reactor reactor, String name) { - LinkedHashSet vars = new LinkedHashSet<>(); - allActions(reactor).forEach(it -> vars.add(it.getName())); - allTimers(reactor).forEach(it -> vars.add(it.getName())); - allParameters(reactor).forEach(it -> vars.add(it.getName())); - allInputs(reactor).forEach(it -> vars.add(it.getName())); - allOutputs(reactor).forEach(it -> vars.add(it.getName())); - allStateVars(reactor).forEach(it -> vars.add(it.getName())); - allInstantiations(reactor).forEach(it -> vars.add(it.getName())); - - int index = 0; - String suffix = ""; - boolean exists = true; - while (exists) { - String id = name + suffix; - if (IterableExtensions.exists(vars, it -> it.equals(id))) { - suffix = "_" + index; - index++; - } else { - exists = false; - } - } - return name + suffix; - } - - //////////////////////////////// - //// Utility functions for supporting inheritance and modes - - /** - * Given a reactor class, return a list of all its actions, - * which includes actions of base classes that it extends. - * This also includes actions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allActions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); - } - - /** - * Given a reactor class, return a list of all its connections, - * which includes connections of base classes that it extends. - * This also includes connections in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allConnections(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); - } - - /** - * Given a reactor class, return a list of all its inputs, - * which includes inputs of base classes that it extends. - * If the base classes include a cycle, where X extends Y and Y extends X, - * then return only the input defined in the base class. - * The returned list may be empty. - * @param definition Reactor class definition. - */ - public static List allInputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); - } - - /** A list of all ports of {@code definition}, in an unspecified order. */ - public static List allPorts(Reactor definition) { - return Stream.concat(ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()).toList(); - } - - /** - * Given a reactor class, return a list of all its preambles, - * which includes preambles of base classes that it extends. - * If the base classes include a cycle, where X extends Y and Y extends X, - * then return only the input defined in the base class. - * The returned list may be empty. - * @param definition Reactor class definition. - */ - public static List allPreambles(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Preambles()); - } - - /** - * Given a reactor class, return a list of all its instantiations, - * which includes instantiations of base classes that it extends. - * This also includes instantiations in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allInstantiations(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); - } - - /** - * Given a reactor Class, return a set of include names for - * interacting reactors which includes all instantiations of base class that it extends. - * - * @param r Reactor Class - * */ - public static HashSet allIncludes(Reactor r) { - var set = new HashSet(); - for (var i : allInstantiations(r)) - { - set.add(CUtil.getName(new TypeParameterizedReactor(i))); - } - return set; - } - - /* - * Given a reactor class, return a stream of reactor classes that it instantiates. - * @param definition Reactor class definition. - * @return A stream of reactor classes. - */ - public static Stream allNestedClasses(Reactor definition) { - return new HashSet<>(ASTUtils.allInstantiations(definition)).stream() - .map(Instantiation::getReactorClass) - .map(ASTUtils::toDefinition); - } - - /** - * Given a reactor class, return a list of all its methods, - * which includes methods of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allMethods(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); - } - - /** - * Given a reactor class, return a list of all its outputs, - * which includes outputs of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allOutputs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); - } - - /** - * Given a reactor class, return a list of all its parameters, - * which includes parameters of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allParameters(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); - } - - /** - * Given a reactor class, return a list of all its reactions, - * which includes reactions of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allReactions(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); - } - - /** - * Given a reactor class, return a list of all its watchdogs. - * - * @param definition Reactor class definition - * @return List - */ - public static List allWatchdogs(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); - } - - /** - * Given a reactor class, return a list of all its state variables, - * which includes state variables of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allStateVars(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); - } - - /** - * Given a reactor class, return a list of all its timers, - * which includes timers of base classes that it extends. - * This also includes reactions in modes, returning a flattened - * view over all modes. - * @param definition Reactor class definition. - */ - public static List allTimers(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); - } - - /** - * Given a reactor class, returns a list of all its modes, - * which includes modes of base classes that it extends. - * @param definition Reactor class definition. - */ - public static List allModes(Reactor definition) { - return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); - } - - public static List recursiveChildren(ReactorInstance r) { - List ret = new ArrayList<>(); - ret.add(r); - for (var child: r.children) { - ret.addAll(recursiveChildren(child)); - } - return ret; - } - - /** - * Return all the superclasses of the specified reactor - * in deepest-first order. For example, if A extends B and C, and - * B and C both extend D, this will return the list [D, B, C, A]. - * Duplicates are removed. If the specified reactor does not extend - * any other reactor, then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - */ - public static LinkedHashSet superClasses(Reactor reactor) { - return superClasses(reactor, new LinkedHashSet<>()); - } - - /** - * Return all the file-level preambles in the files that define the - * specified class and its superclasses in deepest-first order. - * Duplicates are removed. If there are no file-level preambles, - * then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - */ - public static LinkedHashSet allFileLevelPreambles(Reactor reactor) { - return allFileLevelPreambles(reactor, new LinkedHashSet<>()); - } - - /** - * Collect elements of type T from the class hierarchy and modes - * defined by a given reactor definition. - * @param definition The reactor definition. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - public static List collectElements(Reactor definition, EStructuralFeature feature) { - return ASTUtils.collectElements(definition, feature, true, true); - } - - /** - * Collect elements of type T contained in given reactor definition, including - * modes and the class hierarchy defined depending on configuration. - * @param definition The reactor definition. - * @param feature The structual model elements to collect. - * @param includeSuperClasses Whether to include elements in super classes. - * @param includeModes Whether to include elements in modes. - * @param The type of elements to collect (e.g., Port, Timer, etc.) - * @return A list of all elements of type T found - */ - @SuppressWarnings("unchecked") - public static List collectElements(Reactor definition, EStructuralFeature feature, boolean includeSuperClasses, boolean includeModes) { - List result = new ArrayList<>(); - - if (includeSuperClasses) { - // Add elements of elements defined in superclasses. - LinkedHashSet s = superClasses(definition); - if (s != null) { - for (Reactor superClass : s) { - result.addAll((EList) superClass.eGet(feature)); - } + /** The Lingua Franca factory for creating new AST nodes. */ + public static final LfFactory factory = LfFactory.eINSTANCE; + + /** The Lingua Franca feature package. */ + public static final LfPackage featurePackage = LfPackage.eINSTANCE; + + /* Match an abbreviated form of a float literal. */ + private static final Pattern ABBREVIATED_FLOAT = Pattern.compile("[+\\-]?\\.\\d+[\\deE+\\-]*"); + + /** + * A mapping from Reactor features to corresponding Mode features for collecting contained + * elements. + */ + private static final Map reactorModeFeatureMap = + Map.of( + featurePackage.getReactor_Actions(), featurePackage.getMode_Actions(), + featurePackage.getReactor_Connections(), featurePackage.getMode_Connections(), + featurePackage.getReactor_Instantiations(), featurePackage.getMode_Instantiations(), + featurePackage.getReactor_Reactions(), featurePackage.getMode_Reactions(), + featurePackage.getReactor_StateVars(), featurePackage.getMode_StateVars(), + featurePackage.getReactor_Timers(), featurePackage.getMode_Timers()); + + /** + * Get all reactors defined in the given resource. + * + * @param resource the resource to extract reactors from + * @return An iterable over all reactors found in the resource + */ + public static List getAllReactors(Resource resource) { + return StreamSupport.stream( + IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false) + .filter(Reactor.class::isInstance) + .map(Reactor.class::cast) + .collect(Collectors.toList()); + } + + /** + * Find connections in the given resource that would be conflicting writes if they were not + * located in mutually exclusive modes. + * + * @param resource The AST. + * @return a list of connections being able to be transformed + */ + public static Collection findConflictingConnectionsInModalReactors( + Resource resource) { + var transform = new HashSet(); + + for (Reactor reactor : getAllReactors(resource)) { + if (!reactor.getModes().isEmpty()) { // Only for modal reactors + var allWriters = HashMultimap., EObject>create(); + + // Collect destinations + for (var rea : allReactions(reactor)) { + for (var eff : rea.getEffects()) { + if (eff.getVariable() instanceof Port) { + allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea); } + } } - - // Add elements of the current reactor. - result.addAll((EList) definition.eGet(feature)); - - if (includeModes && reactorModeFeatureMap.containsKey(feature)) { - var modeFeature = reactorModeFeatureMap.get(feature); - // Add elements of elements defined in modes. - for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { - insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); - } - } - - return result; - } - - /** - * Adds the elements into the given list at a location matching to their textual position. - * - * When creating a flat view onto reactor elements including modes, the final list must be ordered according - * to the textual positions. - * - * Example: - * reactor R { - * reaction // -> is R.reactions[0] - * mode M { - * reaction // -> is R.mode[0].reactions[0] - * reaction // -> is R.mode[0].reactions[1] - * } - * reaction // -> is R.reactions[1] - * } - * In this example, it is important that the reactions in the mode are inserted between the top-level - * reactions to retain the correct global reaction ordering, which will be derived from this flattened view. - * - * @param list The list to add the elements into. - * @param elements The elements to add. - * @param mode The mode containing the elements. - * @param The type of elements to add (e.g., Port, Timer, etc.) - */ - private static void insertModeElementsAtTextualPosition(List list, List elements, Mode mode) { - if (elements.isEmpty()) { - return; // Nothing to add + for (var con : + ASTUtils.collectElements( + reactor, featurePackage.getReactor_Connections(), false, true)) { + for (var port : con.getRightPorts()) { + allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con); + } } - var idx = list.size(); - if (idx > 0) { - // If there are elements in the list, first check if the last element has the same container as the mode. - // I.e. we don't want to compare textual positions of different reactors (super classes) - if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { - var modeAstNode = NodeModelUtils.getNode(mode); - if (modeAstNode != null) { - var modePos = modeAstNode.getOffset(); - // Now move the insertion index from the last element forward as long as this element has a textual - // position after the mode. - do { - var astNode = NodeModelUtils.getNode(list.get(idx - 1)); - if (astNode != null && astNode.getOffset() > modePos) { - idx--; - } else { - break; // Insertion index is ok. - } - } while (idx > 0); - } + // Handle conflicting writers + for (var key : allWriters.keySet()) { + var writers = allWriters.get(key); + if (writers.size() > 1) { // has multiple sources + var writerModes = HashMultimap.create(); + // find modes + for (var writer : writers) { + if (writer.eContainer() instanceof Mode) { + writerModes.put((Mode) writer.eContainer(), writer); + } else { + writerModes.put(null, writer); + } } - } - list.addAll(idx, elements); - } - - public static Iterable allElementsOfClass( - Resource resource, - Class elementClass - ) { - //noinspection StaticPseudoFunctionalStyleMethod - return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); - } - - //////////////////////////////// - //// Utility functions for translating AST nodes into text - - /** - * Translate the given code into its textual representation - * with {@code CodeMap.Correspondence} tags inserted, or - * return the empty string if {@code node} is {@code null}. - * This method should be used to generate code. - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toText(EObject node) { - if (node == null) return ""; - return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); - } - - /** - * Translate the given code into its textual representation - * without {@code CodeMap.Correspondence} tags, or return - * the empty string if {@code node} is {@code null}. - * This method should be used for analyzing AST nodes in - * cases where they are easiest to analyze as strings. - * @param node AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toOriginalText(EObject node) { - if (node == null) return ""; - return ToText.instance.doSwitch(node); - } - - /** - * Return an integer representation of the given element. - * - * Internally, this method uses Integer.decode, so it will - * also understand hexadecimal, binary, etc. - * - * @param e The element to be rendered as an integer. - */ - public static Integer toInteger(Element e) { - return Integer.decode(e.getLiteral()); - } - - /** - * Return a time value based on the given element. - * - * @param e The element to be rendered as a time value. - */ - public static TimeValue toTimeValue(Element e) { - return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); - } - - /** - * Returns the time value represented by the given AST node. - */ - public static TimeValue toTimeValue(Time e) { - if (!isValidTime(e)) { - // invalid unit, will have been reported by validator - throw new IllegalArgumentException(); - } - return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); - } - - /** - * Return a boolean based on the given element. - * - * @param e The element to be rendered as a boolean. - */ - public static boolean toBoolean(Element e) { - return elementToSingleString(e).equalsIgnoreCase("true"); - } - - /** - * Given the right-hand side of a target property, return a string that - * represents the given value/ - * - * If the given value is not a literal or and id (but for instance and array or dict), - * an empty string is returned. If the element is a string, any quotes are removed. - * - * @param e The right-hand side of a target property. - */ - public static String elementToSingleString(Element e) { - if (e.getLiteral() != null) { - return StringUtil.removeQuotes(e.getLiteral()).trim(); - } else if (e.getId() != null) { - return e.getId(); - } - return ""; - } - - /** - * Given the right-hand side of a target property, return a list with all - * the strings that the property lists. - * - * Arrays are traversed, so strings are collected recursively. Empty strings - * are ignored; they are not added to the list. - * @param value The right-hand side of a target property. - */ - public static List elementToListOfStrings(Element value) { - List elements = new ArrayList<>(); - if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - elements.addAll(elementToListOfStrings(element)); - } - return elements; - } else { - String v = elementToSingleString(value); - if (!v.isEmpty()) { - elements.add(v); + // Conflicting connection can only be handled if.. + if (!writerModes.containsKey(null) + && // no writer is on root level (outside of modes) and... + writerModes.keySet().stream() + .map(writerModes::get) + .allMatch( + writersInMode -> // all writers in a mode are either... + writersInMode.size() == 1 + || // the only writer or... + writersInMode.stream() + .allMatch( + w -> + w + instanceof + Reaction) // all are reactions and hence ordered + )) { + // Add connections to transform list + writers.stream() + .filter(w -> w instanceof Connection) + .forEach(c -> transform.add((Connection) c)); } + } } - return elements; - } - - /** - * Convert key-value pairs in an Element to a map, assuming that both the key - * and the value are strings. - */ - public static Map elementToStringMaps(Element value) { - Map elements = new HashMap<>(); - for (var element: value.getKeyvalue().getPairs()) { - elements.put( - element.getName().trim(), - StringUtil.removeQuotes(elementToSingleString(element.getValue())) - ); - } - return elements; - } - - // Various utility methods to convert various data types to Elements - - /** - * Convert a map to key-value pairs in an Element. - */ - public static Element toElement(Map map) { - Element e = LfFactory.eINSTANCE.createElement(); - if (map.size() == 0) return null; - else { - var kv = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var entry : map.entrySet()) { - var pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(entry.getKey()); - var element = LfFactory.eINSTANCE.createElement(); - element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); - pair.setValue(element); - kv.getPairs().add(pair); - } - e.setKeyvalue(kv); - } - - return e; - } - - /** - * Given a single string, convert it into its AST representation. - * {@code addQuotes} controls if the generated representation should be - * accompanied by double quotes ("") or not. - */ - private static Element toElement(String str, boolean addQuotes) { - if (str == null) return null; - var strToReturn = addQuotes? StringUtil.addDoubleQuotes(str):str; - Element e = LfFactory.eINSTANCE.createElement(); - e.setLiteral(strToReturn); - return e; - } - - /** - * Given a single string, convert it into its AST representation. - */ - public static Element toElement(String str) { - return toElement(str, true); - } - - /** - * Given a list of strings, convert it into its AST representation. - * Stores the list in the Array field of the element, unless the list only has one string, - * in which case it is stored in the Literal field. Returns null if the provided list is empty. - */ - public static Element toElement(List list) { - Element e = LfFactory.eINSTANCE.createElement(); - if (list.size() == 0) return null; - else if (list.size() == 1) { - return toElement(list.get(0)); - } else { - var arr = LfFactory.eINSTANCE.createArray(); - for (String s : list) { - arr.getElements().add(ASTUtils.toElement(s)); - } - e.setArray(arr); + } + } + + return transform; + } + + /** + * Return the enclosing reactor of an LF EObject in a reactor or mode. + * + * @param obj the LF model element + * @return the reactor or null + */ + public static Reactor getEnclosingReactor(EObject obj) { + if (obj.eContainer() instanceof Reactor) { + return (Reactor) obj.eContainer(); + } else if (obj.eContainer() instanceof Mode) { + return (Reactor) obj.eContainer().eContainer(); + } + return null; + } + + /** Return the main reactor in the given resource if there is one, null otherwise. */ + public static Reactor findMainReactor(Resource resource) { + return IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), Reactor::isMain); + } + + /** + * Find the main reactor and change it to a federated reactor. Return true if the transformation + * was successful (or the given resource already had a federated reactor); return false otherwise. + */ + public static boolean makeFederated(Resource resource) { + // Find the main reactor + Reactor r = findMainReactor(resource); + if (r == null) { + return false; + } + r.setMain(false); + r.setFederated(true); + return true; + } + + /** Change the target name to 'newTargetName'. For example, change C to CCpp. */ + public static boolean changeTargetName(Resource resource, String newTargetName) { + targetDecl(resource).setName(newTargetName); + return true; + } + + /** Return the target of the file in which the given node lives. */ + public static Target getTarget(EObject object) { + TargetDecl targetDecl = targetDecl(object.eResource()); + return Target.fromDecl(targetDecl); + } + + /** + * Add a new target property to the given resource. This also creates a config object if the + * resource does not yey have one. + * + * @param resource The resource to modify + * @param name Name of the property to add + * @param value Value to be assigned to the property + */ + public static boolean addTargetProperty( + final Resource resource, final String name, final Element value) { + var config = targetDecl(resource).getConfig(); + if (config == null) { + config = LfFactory.eINSTANCE.createKeyValuePairs(); + targetDecl(resource).setConfig(config); + } + final var newProperty = LfFactory.eINSTANCE.createKeyValuePair(); + newProperty.setName(name); + newProperty.setValue(value); + config.getPairs().add(newProperty); + return true; + } + + /** + * Return true if the connection involves multiple ports on the left or right side of the + * connection, or if the port on the left or right of the connection involves a bank of reactors + * or a multiport. + * + * @param connection The connection. + */ + public static boolean hasMultipleConnections(Connection connection) { + if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) { + return true; + } + VarRef leftPort = connection.getLeftPorts().get(0); + VarRef rightPort = connection.getRightPorts().get(0); + Instantiation leftContainer = leftPort.getContainer(); + Instantiation rightContainer = rightPort.getContainer(); + Port leftPortAsPort = (Port) leftPort.getVariable(); + Port rightPortAsPort = (Port) rightPort.getVariable(); + return leftPortAsPort.getWidthSpec() != null + || leftContainer != null && leftContainer.getWidthSpec() != null + || rightPortAsPort.getWidthSpec() != null + || rightContainer != null && rightContainer.getWidthSpec() != null; + } + + /** + * Produce a unique identifier within a reactor based on a given based name. If the name does not + * exists, it is returned; if does exist, an index is appended that makes the name unique. + * + * @param reactor The reactor to find a unique identifier within. + * @param name The name to base the returned identifier on. + */ + public static String getUniqueIdentifier(Reactor reactor, String name) { + LinkedHashSet vars = new LinkedHashSet<>(); + allActions(reactor).forEach(it -> vars.add(it.getName())); + allTimers(reactor).forEach(it -> vars.add(it.getName())); + allParameters(reactor).forEach(it -> vars.add(it.getName())); + allInputs(reactor).forEach(it -> vars.add(it.getName())); + allOutputs(reactor).forEach(it -> vars.add(it.getName())); + allStateVars(reactor).forEach(it -> vars.add(it.getName())); + allInstantiations(reactor).forEach(it -> vars.add(it.getName())); + + int index = 0; + String suffix = ""; + boolean exists = true; + while (exists) { + String id = name + suffix; + if (IterableExtensions.exists(vars, it -> it.equals(id))) { + suffix = "_" + index; + index++; + } else { + exists = false; + } + } + return name + suffix; + } + + //////////////////////////////// + //// Utility functions for supporting inheritance and modes + + /** + * Given a reactor class, return a list of all its actions, which includes actions of base classes + * that it extends. This also includes actions in modes, returning a flattened view over all + * modes. + * + * @param definition Reactor class definition. + */ + public static List allActions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Actions()); + } + + /** + * Given a reactor class, return a list of all its connections, which includes connections of base + * classes that it extends. This also includes connections in modes, returning a flattened view + * over all modes. + * + * @param definition Reactor class definition. + */ + public static List allConnections(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Connections()); + } + + /** + * Given a reactor class, return a list of all its inputs, which includes inputs of base classes + * that it extends. If the base classes include a cycle, where X extends Y and Y extends X, then + * return only the input defined in the base class. The returned list may be empty. + * + * @param definition Reactor class definition. + */ + public static List allInputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Inputs()); + } + + /** A list of all ports of {@code definition}, in an unspecified order. */ + public static List allPorts(Reactor definition) { + return Stream.concat( + ASTUtils.allInputs(definition).stream(), ASTUtils.allOutputs(definition).stream()) + .toList(); + } + + /** + * Given a reactor class, return a list of all its preambles, which includes preambles of base + * classes that it extends. If the base classes include a cycle, where X extends Y and Y extends + * X, then return only the input defined in the base class. The returned list may be empty. + * + * @param definition Reactor class definition. + */ + public static List allPreambles(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Preambles()); + } + + /** + * Given a reactor class, return a list of all its instantiations, which includes instantiations + * of base classes that it extends. This also includes instantiations in modes, returning a + * flattened view over all modes. + * + * @param definition Reactor class definition. + */ + public static List allInstantiations(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); + } + + /** + * Given a reactor Class, return a set of include names for interacting reactors which includes + * all instantiations of base class that it extends. + * + * @param r Reactor Class + */ + public static HashSet allIncludes(Reactor r) { + var set = new HashSet(); + for (var i : allInstantiations(r)) { + set.add(CUtil.getName(new TypeParameterizedReactor(i))); + } + return set; + } + + /* + * Given a reactor class, return a stream of reactor classes that it instantiates. + * @param definition Reactor class definition. + * @return A stream of reactor classes. + */ + public static Stream allNestedClasses(Reactor definition) { + return new HashSet<>(ASTUtils.allInstantiations(definition)) + .stream().map(Instantiation::getReactorClass).map(ASTUtils::toDefinition); + } + + /** + * Given a reactor class, return a list of all its methods, which includes methods of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allMethods(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Methods()); + } + + /** + * Given a reactor class, return a list of all its outputs, which includes outputs of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allOutputs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Outputs()); + } + + /** + * Given a reactor class, return a list of all its parameters, which includes parameters of base + * classes that it extends. + * + * @param definition Reactor class definition. + */ + public static List allParameters(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Parameters()); + } + + /** + * Given a reactor class, return a list of all its reactions, which includes reactions of base + * classes that it extends. This also includes reactions in modes, returning a flattened view over + * all modes. + * + * @param definition Reactor class definition. + */ + public static List allReactions(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions()); + } + + /** + * Given a reactor class, return a list of all its watchdogs. + * + * @param definition Reactor class definition + * @return List + */ + public static List allWatchdogs(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs()); + } + + /** + * Given a reactor class, return a list of all its state variables, which includes state variables + * of base classes that it extends. This also includes reactions in modes, returning a flattened + * view over all modes. + * + * @param definition Reactor class definition. + */ + public static List allStateVars(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_StateVars()); + } + + /** + * Given a reactor class, return a list of all its timers, which includes timers of base classes + * that it extends. This also includes reactions in modes, returning a flattened view over all + * modes. + * + * @param definition Reactor class definition. + */ + public static List allTimers(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Timers()); + } + + /** + * Given a reactor class, returns a list of all its modes, which includes modes of base classes + * that it extends. + * + * @param definition Reactor class definition. + */ + public static List allModes(Reactor definition) { + return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes()); + } + + public static List recursiveChildren(ReactorInstance r) { + List ret = new ArrayList<>(); + ret.add(r); + for (var child : r.children) { + ret.addAll(recursiveChildren(child)); + } + return ret; + } + + /** + * Return all the superclasses of the specified reactor in deepest-first order. For example, if A + * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates + * are removed. If the specified reactor does not extend any other reactor, then return an empty + * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared + * that is not found, then return null. + * + * @param reactor The specified reactor. + */ + public static LinkedHashSet superClasses(Reactor reactor) { + return superClasses(reactor, new LinkedHashSet<>()); + } + + /** + * Return all the file-level preambles in the files that define the specified class and its + * superclasses in deepest-first order. Duplicates are removed. If there are no file-level + * preambles, then return an empty list. If a cycle is found, where X extends Y and Y extends X, + * or if a superclass is declared that is not found, then return null. + * + * @param reactor The specified reactor. + */ + public static LinkedHashSet allFileLevelPreambles(Reactor reactor) { + return allFileLevelPreambles(reactor, new LinkedHashSet<>()); + } + + /** + * Collect elements of type T from the class hierarchy and modes defined by a given reactor + * definition. + * + * @param definition The reactor definition. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + public static List collectElements( + Reactor definition, EStructuralFeature feature) { + return ASTUtils.collectElements(definition, feature, true, true); + } + + /** + * Collect elements of type T contained in given reactor definition, including modes and the class + * hierarchy defined depending on configuration. + * + * @param definition The reactor definition. + * @param feature The structual model elements to collect. + * @param includeSuperClasses Whether to include elements in super classes. + * @param includeModes Whether to include elements in modes. + * @param The type of elements to collect (e.g., Port, Timer, etc.) + * @return A list of all elements of type T found + */ + @SuppressWarnings("unchecked") + public static List collectElements( + Reactor definition, + EStructuralFeature feature, + boolean includeSuperClasses, + boolean includeModes) { + List result = new ArrayList<>(); + + if (includeSuperClasses) { + // Add elements of elements defined in superclasses. + LinkedHashSet s = superClasses(definition); + if (s != null) { + for (Reactor superClass : s) { + result.addAll((EList) superClass.eGet(feature)); } - return e; - } - - /** - * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit inside an Element. - */ - public static Element toElement(TimeValue tv) { - Element e = LfFactory.eINSTANCE.createElement(); - e.setTime((int)tv.time); - if (tv.unit != null) { - e.setUnit(tv.unit.toString()); - } - return e; - } - - public static Element toElement(boolean val) { - return toElement(Boolean.toString(val), false); - } - - public static Element toElement(int val) { - return toElement(Integer.toString(val), false); - } - - /** - * Translate the given type into its textual representation, but - * do not append any array specifications or type arguments. - * @param type AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String baseType(Type type) { - if (type != null) { - if (type.getCode() != null) { - return toText(type.getCode()); + } + } + + // Add elements of the current reactor. + result.addAll((EList) definition.eGet(feature)); + + if (includeModes && reactorModeFeatureMap.containsKey(feature)) { + var modeFeature = reactorModeFeatureMap.get(feature); + // Add elements of elements defined in modes. + for (Mode mode : includeSuperClasses ? allModes(definition) : definition.getModes()) { + insertModeElementsAtTextualPosition(result, (EList) mode.eGet(modeFeature), mode); + } + } + + return result; + } + + /** + * Adds the elements into the given list at a location matching to their textual position. + * + *

    When creating a flat view onto reactor elements including modes, the final list must be + * ordered according to the textual positions. + * + *

    Example: reactor R { reaction // -> is R.reactions[0] mode M { reaction // -> is + * R.mode[0].reactions[0] reaction // -> is R.mode[0].reactions[1] } reaction // -> is + * R.reactions[1] } In this example, it is important that the reactions in the mode are inserted + * between the top-level reactions to retain the correct global reaction ordering, which will be + * derived from this flattened view. + * + * @param list The list to add the elements into. + * @param elements The elements to add. + * @param mode The mode containing the elements. + * @param The type of elements to add (e.g., Port, Timer, etc.) + */ + private static void insertModeElementsAtTextualPosition( + List list, List elements, Mode mode) { + if (elements.isEmpty()) { + return; // Nothing to add + } + + var idx = list.size(); + if (idx > 0) { + // If there are elements in the list, first check if the last element has the same container + // as the mode. + // I.e. we don't want to compare textual positions of different reactors (super classes) + if (mode.eContainer() == list.get(list.size() - 1).eContainer()) { + var modeAstNode = NodeModelUtils.getNode(mode); + if (modeAstNode != null) { + var modePos = modeAstNode.getOffset(); + // Now move the insertion index from the last element forward as long as this element has + // a textual + // position after the mode. + do { + var astNode = NodeModelUtils.getNode(list.get(idx - 1)); + if (astNode != null && astNode.getOffset() > modePos) { + idx--; } else { - if (type.isTime()) { - return "time"; - } else { - StringBuilder result = new StringBuilder(type.getId()); - - for (String s : convertToEmptyListIfNull(type.getStars())) { - result.append(s); - } - return result.toString(); - } - } - } - return ""; - } - - /** - * Report whether the given literal is zero or not. - * @param literal AST node to inspect. - * @return True if the given literal denotes the constant {@code 0}, false - * otherwise. - */ - public static boolean isZero(String literal) { - try { - if (literal != null && - Integer.parseInt(literal) == 0) { - return true; + break; // Insertion index is ok. } - } catch (NumberFormatException e) { - // Not an int. + } while (idx > 0); } - return false; - } - - /** - * Report whether the given expression is zero or not. - * - * @param expr AST node to inspect. - * @return True if the given value denotes the constant {@code 0}, false otherwise. - */ - public static boolean isZero(Expression expr) { - if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); - } - return false; - } - - /** - * Report whether the given string literal is an integer number or not. - * - * @param literal AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Integer.decode(literal); - } catch (NumberFormatException e) { - return false; - } - return true; - } - - /** - * Report whether the given string literal is a boolean value or not. - * @param literal AST node to inspect. - * @return True if the given value is a boolean, false otherwise. - */ - public static boolean isBoolean(String literal) { - return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); - } + } + } + list.addAll(idx, elements); + } + + public static Iterable allElementsOfClass( + Resource resource, Class elementClass) { + //noinspection StaticPseudoFunctionalStyleMethod + return Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), elementClass); + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + + /** + * Translate the given code into its textual representation with {@code CodeMap.Correspondence} + * tags inserted, or return the empty string if {@code node} is {@code null}. This method should + * be used to generate code. + * + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toText(EObject node) { + if (node == null) return ""; + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); + } + + /** + * Translate the given code into its textual representation without {@code CodeMap.Correspondence} + * tags, or return the empty string if {@code node} is {@code null}. This method should be used + * for analyzing AST nodes in cases where they are easiest to analyze as strings. + * + * @param node AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String toOriginalText(EObject node) { + if (node == null) return ""; + return ToText.instance.doSwitch(node); + } + + /** + * Return an integer representation of the given element. + * + *

    Internally, this method uses Integer.decode, so it will also understand hexadecimal, binary, + * etc. + * + * @param e The element to be rendered as an integer. + */ + public static Integer toInteger(Element e) { + return Integer.decode(e.getLiteral()); + } + + /** + * Return a time value based on the given element. + * + * @param e The element to be rendered as a time value. + */ + public static TimeValue toTimeValue(Element e) { + return new TimeValue(e.getTime(), TimeUnit.fromName(e.getUnit())); + } + + /** Returns the time value represented by the given AST node. */ + public static TimeValue toTimeValue(Time e) { + if (!isValidTime(e)) { + // invalid unit, will have been reported by validator + throw new IllegalArgumentException(); + } + return new TimeValue(e.getInterval(), TimeUnit.fromName(e.getUnit())); + } + + /** + * Return a boolean based on the given element. + * + * @param e The element to be rendered as a boolean. + */ + public static boolean toBoolean(Element e) { + return elementToSingleString(e).equalsIgnoreCase("true"); + } + + /** + * Given the right-hand side of a target property, return a string that represents the given + * value/ + * + *

    If the given value is not a literal or and id (but for instance and array or dict), an empty + * string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String elementToSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } + + /** + * Given the right-hand side of a target property, return a list with all the strings that the + * property lists. + * + *

    Arrays are traversed, so strings are collected recursively. Empty strings are ignored; they + * are not added to the list. + * + * @param value The right-hand side of a target property. + */ + public static List elementToListOfStrings(Element value) { + List elements = new ArrayList<>(); + if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + elements.addAll(elementToListOfStrings(element)); + } + return elements; + } else { + String v = elementToSingleString(value); + if (!v.isEmpty()) { + elements.add(v); + } + } + return elements; + } + + /** + * Convert key-value pairs in an Element to a map, assuming that both the key and the value are + * strings. + */ + public static Map elementToStringMaps(Element value) { + Map elements = new HashMap<>(); + for (var element : value.getKeyvalue().getPairs()) { + elements.put( + element.getName().trim(), + StringUtil.removeQuotes(elementToSingleString(element.getValue()))); + } + return elements; + } + + // Various utility methods to convert various data types to Elements + + /** Convert a map to key-value pairs in an Element. */ + public static Element toElement(Map map) { + Element e = LfFactory.eINSTANCE.createElement(); + if (map.size() == 0) return null; + else { + var kv = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var entry : map.entrySet()) { + var pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(entry.getKey()); + var element = LfFactory.eINSTANCE.createElement(); + element.setLiteral(StringUtil.addDoubleQuotes(entry.getValue())); + pair.setValue(element); + kv.getPairs().add(pair); + } + e.setKeyvalue(kv); + } + + return e; + } + + /** + * Given a single string, convert it into its AST representation. {@code addQuotes} controls if + * the generated representation should be accompanied by double quotes ("") or not. + */ + private static Element toElement(String str, boolean addQuotes) { + if (str == null) return null; + var strToReturn = addQuotes ? StringUtil.addDoubleQuotes(str) : str; + Element e = LfFactory.eINSTANCE.createElement(); + e.setLiteral(strToReturn); + return e; + } + + /** Given a single string, convert it into its AST representation. */ + public static Element toElement(String str) { + return toElement(str, true); + } + + /** + * Given a list of strings, convert it into its AST representation. Stores the list in the Array + * field of the element, unless the list only has one string, in which case it is stored in the + * Literal field. Returns null if the provided list is empty. + */ + public static Element toElement(List list) { + Element e = LfFactory.eINSTANCE.createElement(); + if (list.size() == 0) return null; + else if (list.size() == 1) { + return toElement(list.get(0)); + } else { + var arr = LfFactory.eINSTANCE.createArray(); + for (String s : list) { + arr.getElements().add(ASTUtils.toElement(s)); + } + e.setArray(arr); + } + return e; + } + + /** + * Convert a TimeValue to its AST representation. The value is type-cast to int in order to fit + * inside an Element. + */ + public static Element toElement(TimeValue tv) { + Element e = LfFactory.eINSTANCE.createElement(); + e.setTime((int) tv.time); + if (tv.unit != null) { + e.setUnit(tv.unit.toString()); + } + return e; + } + + public static Element toElement(boolean val) { + return toElement(Boolean.toString(val), false); + } + + public static Element toElement(int val) { + return toElement(Integer.toString(val), false); + } + + /** + * Translate the given type into its textual representation, but do not append any array + * specifications or type arguments. + * + * @param type AST node to render as string. + * @return Textual representation of the given argument. + */ + public static String baseType(Type type) { + if (type != null) { + if (type.getCode() != null) { + return toText(type.getCode()); + } else { + if (type.isTime()) { + return "time"; + } else { + StringBuilder result = new StringBuilder(type.getId()); - /** - * Report whether the given string literal is a float value or not. - * @param literal AST node to inspect. - * @return True if the given value is a float, false otherwise. - */ - public static boolean isFloat(String literal) { - try { - //noinspection ResultOfMethodCallIgnored - Float.parseFloat(literal); - } catch (NumberFormatException e) { - return false; + for (String s : convertToEmptyListIfNull(type.getStars())) { + result.append(s); + } + return result.toString(); } + } + } + return ""; + } + + /** + * Report whether the given literal is zero or not. + * + * @param literal AST node to inspect. + * @return True if the given literal denotes the constant {@code 0}, false otherwise. + */ + public static boolean isZero(String literal) { + try { + if (literal != null && Integer.parseInt(literal) == 0) { return true; - } - - /** - * Report whether the given code is an integer number or not. - * @param code AST node to inspect. - * @return True if the given code is an integer, false otherwise. - */ - public static boolean isInteger(Code code) { - return isInteger(toText(code)); - } - - /** - * Report whether the given expression is an integer number or not. - * @param expr AST node to inspect. - * @return True if the given value is an integer, false otherwise. - */ - public static boolean isInteger(Expression expr) { - if (expr instanceof Literal) { - return isInteger(((Literal) expr).getLiteral()); - } else if (expr instanceof Code) { - return isInteger((Code) expr); + } + } catch (NumberFormatException e) { + // Not an int. + } + return false; + } + + /** + * Report whether the given expression is zero or not. + * + * @param expr AST node to inspect. + * @return True if the given value denotes the constant {@code 0}, false otherwise. + */ + public static boolean isZero(Expression expr) { + if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } + + /** + * Report whether the given string literal is an integer number or not. + * + * @param literal AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Integer.decode(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + /** + * Report whether the given string literal is a boolean value or not. + * + * @param literal AST node to inspect. + * @return True if the given value is a boolean, false otherwise. + */ + public static boolean isBoolean(String literal) { + return literal.equalsIgnoreCase("true") || literal.equalsIgnoreCase("false"); + } + + /** + * Report whether the given string literal is a float value or not. + * + * @param literal AST node to inspect. + * @return True if the given value is a float, false otherwise. + */ + public static boolean isFloat(String literal) { + try { + //noinspection ResultOfMethodCallIgnored + Float.parseFloat(literal); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + /** + * Report whether the given code is an integer number or not. + * + * @param code AST node to inspect. + * @return True if the given code is an integer, false otherwise. + */ + public static boolean isInteger(Code code) { + return isInteger(toText(code)); + } + + /** + * Report whether the given expression is an integer number or not. + * + * @param expr AST node to inspect. + * @return True if the given value is an integer, false otherwise. + */ + public static boolean isInteger(Expression expr) { + if (expr instanceof Literal) { + return isInteger(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isInteger((Code) expr); + } + return false; + } + + /** + * Report whether the given expression denotes a valid time or not. + * + * @param expr AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Expression expr) { + if (expr instanceof ParameterReference) { + return isOfTimeType(((ParameterReference) expr).getParameter()); + } else if (expr instanceof Time) { + return isValidTime((Time) expr); + } else if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } + return false; + } + + /** + * Report whether the given time denotes a valid time or not. + * + * @param t AST node to inspect. + * @return True if the argument denotes a valid time, false otherwise. + */ + public static boolean isValidTime(Time t) { + if (t == null) return false; + String unit = t.getUnit(); + return t.getInterval() == 0 || TimeUnit.isValidUnit(unit); + } + + /** If the initializer contains exactly one expression, return it. Otherwise, return null. */ + public static Expression asSingleExpr(Initializer init) { + if (init == null) { + return null; + } + var exprs = init.getExprs(); + return exprs.size() == 1 ? exprs.get(0) : null; + } + + public static boolean isSingleExpr(Initializer init) { + // todo expand that to = initialization + if (init == null) { + return false; + } + var exprs = init.getExprs(); + return exprs.size() == 1; + } + + public static boolean isListInitializer(Initializer init) { + return init != null && !isSingleExpr(init); + } + + /** + * Return the type of a declaration with the given (nullable) explicit type, and the given + * (nullable) initializer. If the explicit type is null, then the type is inferred from the + * initializer. Only two types can be inferred: "time" and "timeList". Return the "undefined" type + * if neither can be inferred. + * + * @param type Explicit type declared on the declaration + * @param init The initializer expression + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Type type, Initializer init) { + if (type != null) { + return InferredType.fromAST(type); + } else if (init == null) { + return InferredType.undefined(); + } + + var single = asSingleExpr(init); + if (single != null) { + // If there is a single element in the list, and it is a proper + // time value with units, we infer the type "time". + if (single instanceof ParameterReference) { + return getInferredType(((ParameterReference) single).getParameter()); + } else if (single instanceof Time) { + return InferredType.time(); + } + } else if (init.getExprs().size() > 1) { + // If there are multiple elements in the list, and there is at + // least one proper time value with units, and all other elements + // are valid times (including zero without units), we infer the + // type "time list". + var allValidTime = true; + var foundNonZero = false; + + for (var e : init.getExprs()) { + if (!ASTUtils.isValidTime(e)) { + allValidTime = false; } - return false; - } - - /** - * Report whether the given expression denotes a valid time or not. - * @param expr AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Expression expr) { - if (expr instanceof ParameterReference) { - return isOfTimeType(((ParameterReference) expr).getParameter()); - } else if (expr instanceof Time) { - return isValidTime((Time) expr); - } else if (expr instanceof Literal) { - return isZero(((Literal) expr).getLiteral()); + if (!ASTUtils.isZero(e)) { + foundNonZero = true; } - return false; - } - - /** - * Report whether the given time denotes a valid time or not. - * @param t AST node to inspect. - * @return True if the argument denotes a valid time, false otherwise. - */ - public static boolean isValidTime(Time t) { - if (t == null) return false; - String unit = t.getUnit(); - return t.getInterval() == 0 || - TimeUnit.isValidUnit(unit); - } - - /** - * If the initializer contains exactly one expression, - * return it. Otherwise, return null. - */ - public static Expression asSingleExpr(Initializer init) { - if (init == null) { - return null; + } + + if (allValidTime && foundNonZero) { + // Conservatively, no bounds are inferred; the returned type + // is a variable-size list. + return InferredType.timeList(); + } + } + return InferredType.undefined(); + } + + /** + * Given a parameter, return an inferred type. Only two types can be inferred: "time" and + * "timeList". Return the "undefined" type if neither can be inferred. + * + * @param p A parameter to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(Parameter p) { + return getInferredType(p.getType(), p.getInit()); + } + + /** + * Given a state variable, return an inferred type. Only two types can be inferred: "time" and + * "timeList". Return the "undefined" type if neither can be inferred. + * + * @param s A state variable to infer the type of. + * @return The inferred type, or "undefined" if none could be inferred. + */ + public static InferredType getInferredType(StateVar s) { + return getInferredType(s.getType(), s.getInit()); + } + + /** + * Construct an inferred type from an "action" AST node based on its declared type. If no type is + * declared, return the "undefined" type. + * + * @param a An action to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Action a) { + return getInferredType(a.getType(), null); + } + + /** + * Construct an inferred type from a "port" AST node based on its declared type. If no type is + * declared, return the "undefined" type. + * + * @param p A port to construct an inferred type object for. + * @return The inferred type, or "undefined" if none was declared. + */ + public static InferredType getInferredType(Port p) { + return getInferredType(p.getType(), null); + } + + /** + * If the given string can be recognized as a floating-point number that has a leading decimal + * point, prepend the string with a zero and return it. Otherwise, return the original string. + * + * @param literal A string might be recognizable as a floating point number with a leading decimal + * point. + * @return an equivalent representation of literal + * + */ + public static String addZeroToLeadingDot(String literal) { + Matcher m = ABBREVIATED_FLOAT.matcher(literal); + if (m.matches()) { + return literal.replace(".", "0."); + } + return literal; + } + + /** + * Return true if the specified port is a multiport. + * + * @param port The port. + * @return True if the port is a multiport. + */ + public static boolean isMultiport(Port port) { + return port.getWidthSpec() != null; + } + + //////////////////////////////// + //// Utility functions for translating AST nodes into text + // This is a continuation of a large section of ASTUtils.xtend + // with the same name. + + /** + * Generate code for referencing a port, action, or timer. + * + * @param reference The reference to the variable. + */ + public static String generateVarRef(VarRef reference) { + var prefix = ""; + if (reference.getContainer() != null) { + prefix = reference.getContainer().getName() + "."; + } + return prefix + reference.getVariable().getName(); + } + + /** Assuming that the given expression denotes a valid time literal, return a time value. */ + public static TimeValue getLiteralTimeValue(Expression expr) { + if (expr instanceof Time) { + return toTimeValue((Time) expr); + } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { + return TimeValue.ZERO; + } else { + return null; + } + } + + /** If the parameter is of time type, return its default value. Otherwise, return null. */ + public static TimeValue getDefaultAsTimeValue(Parameter p) { + if (isOfTimeType(p)) { + var init = asSingleExpr(p.getInit()); + if (init != null) { + return getLiteralTimeValue(init); + } + } + return null; + } + + /** Return whether the given state variable is inferred to a time type. */ + public static boolean isOfTimeType(StateVar state) { + InferredType t = getInferredType(state); + return t.isTime && !t.isList; + } + + /** Return whether the given parameter is inferred to a time type. */ + public static boolean isOfTimeType(Parameter param) { + InferredType t = getInferredType(param); + return t.isTime && !t.isList; + } + + /** + * Given a parameter, return its initial value. The initial value is a list of instances of + * Expressions. + * + *

    If the instantiations argument is null or an empty list, then the value returned is simply + * the default value given when the parameter is defined. + * + *

    If a list of instantiations is given, then the first instantiation is required to be an + * instantiation of the reactor class that is parameterized by the parameter. I.e., + * + *

    +   *      parameter.eContainer == instantiations.get(0).reactorClass
    +   * 
    + * + *

    If a second instantiation is given, then it is required to be an instantiation of a reactor + * class that contains the first instantiation. That is, + * + *

    +   *      instantiations.get(0).eContainer == instantiations.get(1).reactorClass
    +   * 
    + * + *

    More generally, for all 0 <= i < instantiations.size - 1, + * + *

    +   *      instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass
    +   * 
    + * + *

    If any of these conditions is not satisfied, then an IllegalArgumentException will be + * thrown. + * + *

    Note that this chain of reactions cannot be inferred from the parameter because in each of + * the predicates above, there may be more than one instantiation that can appear on the right + * hand side of the predicate. + * + *

    For example, consider the following program: + * + *

         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);
    +   *      }
    +   * 
    + * + *

    Notice that there are a total of four instances of reactor class A. Then + * + *

    +   *      initialValue(x, null) returns 1
    +   *      initialValue(x, [a1]) returns 2
    +   *      initialValue(x, [a2]) returns -1
    +   *      initialValue(x, [a1, b1]) returns 3
    +   *      initialValue(x, [a2, b1]) returns -1
    +   *      initialValue(x, [a1, b2]) returns -2
    +   *      initialValue(x, [a2, b2]) returns -1
    +   * 
    + * + *

    (Actually, in each of the above cases, the returned value is a list with one entry, a + * Literal, e.g. ["1"]). + * + *

    There are two instances of reactor class B. + * + *

    +   *      initialValue(y, null) returns 2
    +   *      initialValue(y, [a1]) throws an IllegalArgumentException
    +   *      initialValue(y, [b1]) returns 3
    +   *      initialValue(y, [b2]) returns -2
    +   * 
    + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * @return The value of the parameter. + * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the + * reactor class that is parameterized by the respective parameter or if the chain of + * instantiations is not nested. + */ + public static List initialValue( + Parameter parameter, List instantiations) { + // If instantiations are given, then check to see whether this parameter gets overridden in + // the first of those instantiations. + if (instantiations != null && instantiations.size() > 0) { + // Check to be sure that the instantiation is in fact an instantiation + // of the reactor class for which this is a parameter. + Instantiation instantiation = instantiations.get(0); + + if (!belongsTo(parameter, instantiation)) { + throw new IllegalArgumentException( + "Parameter " + + parameter.getName() + + " is not a parameter of reactor instance " + + instantiation.getName() + + "."); + } + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = null; + for (Assignment assignment : instantiation.getParameters()) { + if (assignment.getLhs().equals(parameter)) { + lastAssignment = assignment; } - var exprs = init.getExprs(); - return exprs.size() == 1 ? exprs.get(0) : null; - } - - public static boolean isSingleExpr(Initializer init) { - // todo expand that to = initialization - if (init == null) { - return false; - } - var exprs = init.getExprs(); - return exprs.size() == 1; - } - - public static boolean isListInitializer(Initializer init) { - return init != null && !isSingleExpr(init); - } - - /** - * Return the type of a declaration with the given - * (nullable) explicit type, and the given (nullable) - * initializer. If the explicit type is null, then the - * type is inferred from the initializer. Only two types - * can be inferred: "time" and "timeList". Return the - * "undefined" type if neither can be inferred. - * - * @param type Explicit type declared on the declaration - * @param init The initializer expression - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Type type, Initializer init) { - if (type != null) { - return InferredType.fromAST(type); - } else if (init == null) { - return InferredType.undefined(); - } - - var single = asSingleExpr(init); - if (single != null) { - // If there is a single element in the list, and it is a proper - // time value with units, we infer the type "time". - if (single instanceof ParameterReference) { - return getInferredType(((ParameterReference) single).getParameter()); - } else if (single instanceof Time) { - return InferredType.time(); - } - } else if (init.getExprs().size() > 1) { - // If there are multiple elements in the list, and there is at - // least one proper time value with units, and all other elements - // are valid times (including zero without units), we infer the - // type "time list". - var allValidTime = true; - var foundNonZero = false; - - for (var e : init.getExprs()) { - if (!ASTUtils.isValidTime(e)) { - allValidTime = false; - } - if (!ASTUtils.isZero(e)) { - foundNonZero = true; - } - } - - if (allValidTime && foundNonZero) { - // Conservatively, no bounds are inferred; the returned type - // is a variable-size list. - return InferredType.timeList(); - } - } - return InferredType.undefined(); - } - - /** - * Given a parameter, return an inferred type. Only two types can be - * inferred: "time" and "timeList". Return the "undefined" type if - * neither can be inferred. - * - * @param p A parameter to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(Parameter p) { - return getInferredType(p.getType(), p.getInit()); - } - - /** - * Given a state variable, return an inferred type. Only two types can be - * inferred: "time" and "timeList". Return the "undefined" type if - * neither can be inferred. - * - * @param s A state variable to infer the type of. - * @return The inferred type, or "undefined" if none could be inferred. - */ - public static InferredType getInferredType(StateVar s) { - return getInferredType(s.getType(), s.getInit()); - } - - /** - * Construct an inferred type from an "action" AST node based - * on its declared type. If no type is declared, return the "undefined" - * type. - * - * @param a An action to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Action a) { - return getInferredType(a.getType(), null); - } - - /** - * Construct an inferred type from a "port" AST node based on its declared - * type. If no type is declared, return the "undefined" type. - * - * @param p A port to construct an inferred type object for. - * @return The inferred type, or "undefined" if none was declared. - */ - public static InferredType getInferredType(Port p) { - return getInferredType(p.getType(), null); - } - - /** - * If the given string can be recognized as a floating-point number that has a leading decimal point, - * prepend the string with a zero and return it. Otherwise, return the original string. - * - * @param literal A string might be recognizable as a floating point number with a leading decimal point. - * @return an equivalent representation of literal - * - */ - public static String addZeroToLeadingDot(String literal) { - Matcher m = ABBREVIATED_FLOAT.matcher(literal); - if (m.matches()) { - return literal.replace(".", "0."); - } - return literal; - } - - /** - * Return true if the specified port is a multiport. - * @param port The port. - * @return True if the port is a multiport. - */ - public static boolean isMultiport(Port port) { - return port.getWidthSpec() != null; - } - - //////////////////////////////// - //// Utility functions for translating AST nodes into text - // This is a continuation of a large section of ASTUtils.xtend - // with the same name. - - /** - * Generate code for referencing a port, action, or timer. - * @param reference The reference to the variable. - */ - public static String generateVarRef(VarRef reference) { - var prefix = ""; - if (reference.getContainer() != null) { - prefix = reference.getContainer().getName() + "."; - } - return prefix + reference.getVariable().getName(); - } - - /** - * Assuming that the given expression denotes a valid time literal, - * return a time value. - */ - public static TimeValue getLiteralTimeValue(Expression expr) { - if (expr instanceof Time) { - return toTimeValue((Time)expr); - } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { - return TimeValue.ZERO; - } else { - return null; - } - } - - /** - * If the parameter is of time type, return its default value. - * Otherwise, return null. - */ - public static TimeValue getDefaultAsTimeValue(Parameter p) { - if (isOfTimeType(p)) { - var init = asSingleExpr(p.getInit()); - if (init != null) { - return getLiteralTimeValue(init); - } - } - return null; - } - - /** - * Return whether the given state variable is inferred - * to a time type. - */ - public static boolean isOfTimeType(StateVar state) { - InferredType t = getInferredType(state); - return t.isTime && !t.isList; - } - - /** - * Return whether the given parameter is inferred - * to a time type. - */ - public static boolean isOfTimeType(Parameter param) { - InferredType t = getInferredType(param); - return t.isTime && !t.isList; - } - - /** - * Given a parameter, return its initial value. - * The initial value is a list of instances of Expressions. - * - * If the instantiations argument is null or an empty list, then the - * value returned is simply the default value given when the parameter - * is defined. - * - * If a list of instantiations is given, then the first instantiation - * is required to be an instantiation of the reactor class that is - * parameterized by the parameter. I.e., - *
         parameter.eContainer == instantiations.get(0).reactorClass
    -     * 

    If a second instantiation is given, then it is required to be an instantiation of a - * reactor class that contains the first instantiation. That is,

    - *
         instantiations.get(0).eContainer == instantiations.get(1).reactorClass
    -     * 

    More generally, for all 0 <= i < instantiations.size - 1,

    - *
         instantiations.get(i).eContainer == instantiations.get(i + 1).reactorClass
    -     * 

    If any of these conditions is not satisfied, then an IllegalArgumentException - * will be thrown.

    - *

    Note that this chain of reactions cannot be inferred from the parameter because - * in each of the predicates above, there may be more than one instantiation that - * can appear on the right hand side of the predicate.

    - *

    For example, consider the following program:

    - *
         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);
    -     *      }
    -     * 

    Notice that there are a total of four instances of reactor class A. - * Then

    - *
         initialValue(x, null) returns 1
    -     *      initialValue(x, [a1]) returns 2
    -     *      initialValue(x, [a2]) returns -1
    -     *      initialValue(x, [a1, b1]) returns 3
    -     *      initialValue(x, [a2, b1]) returns -1
    -     *      initialValue(x, [a1, b2]) returns -2
    -     *      initialValue(x, [a2, b2]) returns -1
    -     * 

    (Actually, in each of the above cases, the returned value is a list with - * one entry, a Literal, e.g. ["1"]).

    - *

    There are two instances of reactor class B.

    - *
         initialValue(y, null) returns 2
    -     *      initialValue(y, [a1]) throws an IllegalArgumentException
    -     *      initialValue(y, [b1]) returns 3
    -     *      initialValue(y, [b2]) returns -2
    -     * 
    - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * - * @return The value of the parameter. - * - * @throws IllegalArgumentException If an instantiation provided is not an - * instantiation of the reactor class that is parameterized by the - * respective parameter or if the chain of instantiations is not nested. - */ - public static List initialValue(Parameter parameter, List instantiations) { - // If instantiations are given, then check to see whether this parameter gets overridden in - // the first of those instantiations. - if (instantiations != null && instantiations.size() > 0) { - // Check to be sure that the instantiation is in fact an instantiation - // of the reactor class for which this is a parameter. - Instantiation instantiation = instantiations.get(0); - - if (!belongsTo(parameter, instantiation)) { - throw new IllegalArgumentException("Parameter " - + parameter.getName() - + " is not a parameter of reactor instance " - + instantiation.getName() - + "." - ); - } - // In case there is more than one assignment to this parameter, we need to - // find the last one. - Assignment lastAssignment = null; - for (Assignment assignment: instantiation.getParameters()) { - if (assignment.getLhs().equals(parameter)) { - lastAssignment = assignment; - } - } - if (lastAssignment != null) { - // Right hand side can be a list. Collect the entries. - List result = new ArrayList<>(); - for (Expression expr: lastAssignment.getRhs().getExprs()) { - if (expr instanceof ParameterReference) { - if (instantiations.size() > 1 - && instantiation.eContainer() != instantiations.get(1).getReactorClass() - ) { - throw new IllegalArgumentException("Reactor instance " - + instantiation.getName() - + " is not contained by instance " - + instantiations.get(1).getName() - + "." - ); - } - result.addAll(initialValue(((ParameterReference)expr).getParameter(), - instantiations.subList(1, instantiations.size()))); - } else { - result.add(expr); - } - } - return result; - } - } - // If we reach here, then either no instantiation was supplied or - // there was no assignment in the instantiation. So just use the - // parameter's initial value. - return parameter.getInit().getExprs(); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) - * belongs to the specified instantiation, meaning that it is defined in - * the reactor class being instantiated or one of its base classes. - * @param eobject The object. - * @param instantiation The instantiation. - */ - public static boolean belongsTo(EObject eobject, Instantiation instantiation) { - Reactor reactor = toDefinition(instantiation.getReactorClass()); - return belongsTo(eobject, reactor); - } - - /** - * Return true if the specified object (a Parameter, Port, Action, or Timer) - * belongs to the specified reactor, meaning that it is defined in - * reactor class or one of its base classes. - * @param eobject The object. - * @param reactor The reactor. - */ - public static boolean belongsTo(EObject eobject, Reactor reactor) { - if (eobject.eContainer() == reactor) return true; - for (ReactorDecl baseClass : reactor.getSuperClasses()) { - if (belongsTo(eobject, toDefinition(baseClass))) { - return true; - } - } - return false; - } - - /** - * Given a parameter return its integer value or null - * if it does not have an integer value. - * If the value of the parameter is a list of integers, - * return the sum of value in the list. - * The instantiations parameter is as in - * {@link #initialValue(Parameter, List)}. - * - * @param parameter The parameter. - * @param instantiations The (optional) list of instantiations. - * - * @return The integer value of the parameter, or null if it does not have an integer value. - * - * @throws IllegalArgumentException If an instantiation provided is not an - * instantiation of the reactor class that is parameterized by the - * respective parameter or if the chain of instantiations is not nested. - */ - public static Integer initialValueInt(Parameter parameter, List instantiations) { - List expressions = initialValue(parameter, instantiations); - int result = 0; - for (Expression expr: expressions) { - if (!(expr instanceof Literal)) { - return null; - } - try { - result += Integer.decode(((Literal) expr).getLiteral()); - } catch (NumberFormatException ex) { - return null; + } + if (lastAssignment != null) { + // Right hand side can be a list. Collect the entries. + List result = new ArrayList<>(); + for (Expression expr : lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + if (instantiations.size() > 1 + && instantiation.eContainer() != instantiations.get(1).getReactorClass()) { + throw new IllegalArgumentException( + "Reactor instance " + + instantiation.getName() + + " is not contained by instance " + + instantiations.get(1).getName() + + "."); } + result.addAll( + initialValue( + ((ParameterReference) expr).getParameter(), + instantiations.subList(1, instantiations.size()))); + } else { + result.add(expr); + } } return result; - } - - /** - * Given the width specification of port or instantiation - * and an (optional) list of nested instantiations, return - * the width if it can be determined and -1 if not. - * It will not be able to be determined if either the - * width is variable (in which case you should use - * {@link #inferPortWidth(VarRef, Connection, List)} ) - * or the list of instantiations is incomplete or missing. - * If there are parameter references in the width, they are - * evaluated to the extent possible given the instantiations list. - * - * The instantiations list is as in - * {@link #initialValue(Parameter, List)}. - * If the spec belongs to an instantiation (for a bank of reactors), - * then the first element on this list should be the instantiation - * that contains this instantiation. If the spec belongs to a port, - * then the first element on the list should be the instantiation - * of the reactor that contains the port. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * - * @return The width, or -1 if the width could not be determined. - * - * @throws IllegalArgumentException If an instantiation provided is not as - * given above or if the chain of instantiations is not nested. - */ - public static int width(WidthSpec spec, List instantiations) { - if (spec == null) { - return 1; - } - if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { - return inferWidthFromConnections(spec, instantiations); - } - var result = 0; - for (WidthTerm term: spec.getTerms()) { - if (term.getParameter() != null) { - Integer termWidth = initialValueInt(term.getParameter(), instantiations); - if (termWidth != null) { - result += termWidth; - } else { - return -1; - } - } else if (term.getWidth() > 0) { - result += term.getWidth(); - } else { - // If the width cannot be determined because term's width <= 0, which means the term's width - // must be inferred, try to infer the width using connections. - if (spec.eContainer() instanceof Instantiation) { - try { - return inferWidthFromConnections(spec, instantiations); - } catch (InvalidSourceException e) { - // If the inference fails, return -1. - return -1; - } - } - } - } - return result; - } - - /** - * Infer the width of a port reference in a connection. - * The port reference one or two parts, a port and an (optional) container - * which is an Instantiation that may refer to a bank of reactors. - * The width will be the product of the bank width and the port width. - * The returned value will be 1 if the port is not in a bank and is not a multiport. - * - * If the width cannot be determined, this will return -1. - * The width cannot be determined if the list of instantiations is - * missing or incomplete. - * - * The instantiations list is as in - * {@link #initialValue(Parameter, List)}. - * The first element on this list should be the instantiation - * that contains the specified connection. - * - * @param reference A port reference. - * @param connection A connection, or null if not in the context of a connection. - * @param instantiations The (optional) list of instantiations. - * - * @return The width or -1 if it could not be determined. - * - * @throws IllegalArgumentException If an instantiation provided is not as - * given above or if the chain of instantiations is not nested. - */ - public static int inferPortWidth( - VarRef reference, Connection connection, List instantiations - ) { - if (reference.getVariable() instanceof Port) { - // If the port is given as a.b, then we want to prepend a to - // the list of instantiations to determine the width of this port. - List extended = instantiations; - if (reference.getContainer() != null) { - extended = new ArrayList<>(); - extended.add(reference.getContainer()); - if (instantiations != null) { - extended.addAll(instantiations); - } - } - - int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); - if (portWidth < 0) { - // Could not determine port width. - return -1; - } - - // Next determine the bank width. This may be unspecified, in which - // case it has to be inferred using the connection. - int bankWidth = 1; - if (reference.getContainer() != null) { - bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); - if (bankWidth < 0 && connection != null) { - // Try to infer the bank width from the connection. - if (reference.getContainer().getWidthSpec().isOfVariableLength()) { - // This occurs for a bank of delays. - int leftWidth = 0; - int rightWidth = 0; - int leftOrRight = 0; - for (VarRef leftPort : connection.getLeftPorts()) { - if (leftPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the left. - leftOrRight = -1; - } else { - // The left port is not the same as this reference. - int otherWidth = inferPortWidth(leftPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; - } - leftWidth += otherWidth; - } - } - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort == reference) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that this port is on the right. - leftOrRight = 1; - } else { - int otherWidth = inferPortWidth(rightPort, connection, instantiations); - if (otherWidth < 0) { - // Cannot determine width. - return -1; - } - rightWidth += otherWidth; - } - } - int discrepancy = 0; - if (leftOrRight < 0) { - // This port is on the left. - discrepancy = rightWidth - leftWidth; - } else if (leftOrRight > 0) { - // This port is on the right. - discrepancy = leftWidth - rightWidth; - } - // Check that portWidth divides the discrepancy. - if (discrepancy % portWidth != 0) { - // This is an error. - return -1; - } - bankWidth = discrepancy / portWidth; - } else { - // Could not determine the bank width. - return -1; - } - } - } - return portWidth * bankWidth; - } - // Argument is not a port. - return -1; - } - - /** - * Given an instantiation of a reactor or bank of reactors, return - * the width. This will be 1 if this is not a reactor bank. Otherwise, - * this will attempt to determine the width. If the width is declared - * as a literal constant, it will return that constant. If the width - * is specified as a reference to a parameter, this will throw an - * exception. If the width is variable, this will find - * connections in the enclosing reactor and attempt to infer the - * width. If the width cannot be determined, it will throw an exception. - * - * IMPORTANT: This method should not be used you really need to - * determine the width! It will not evaluate parameter values. - * @see #width(WidthSpec, List) - * - * @param instantiation A reactor instantiation. - * - * @return The width, if it can be determined. - * @deprecated - */ - @Deprecated - public static int widthSpecification(Instantiation instantiation) { - int result = width(instantiation.getWidthSpec(), null); - if (result < 0) { - throw new InvalidSourceException("Cannot determine width for the instance " - + instantiation.getName()); - } - return result; - } - - /** - * Report whether a state variable has been initialized or not. - * @param v The state variable to be checked. - * @return True if the variable was initialized, false otherwise. - */ - public static boolean isInitialized(StateVar v) { - return v != null && v.getInit() != null; - } - - /** - * Report whether the given time state variable is initialized using a - * parameter or not. - * @param s A state variable. - * @return True if the argument is initialized using a parameter, false - * otherwise. - */ - public static boolean isParameterized(StateVar s) { - return s.getInit() != null && - IterableExtensions.exists(s.getInit().getExprs(), it -> it instanceof ParameterReference); - } - - /** - * Check if the reactor class uses generics - * @param r the reactor to check - * @return true if the reactor uses generics - */ - public static boolean isGeneric(Reactor r) { - if (r == null) { - return false; - } - return r.getTypeParms().size() != 0; - } - - /** - * If the specified reactor declaration is an import, then - * return the imported reactor class definition. Otherwise, - * just return the argument. - * @param r A Reactor or an ImportedReactor. - * @return The Reactor class definition or null if no definition is found. - */ - public static Reactor toDefinition(ReactorDecl r) { - if (r == null) - return null; - if (r instanceof Reactor) { - return (Reactor) r; - } else if (r instanceof ImportedReactor) { - return ((ImportedReactor) r).getReactorClass(); - } + } + } + // If we reach here, then either no instantiation was supplied or + // there was no assignment in the instantiation. So just use the + // parameter's initial value. + return parameter.getInit().getExprs(); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the + * specified instantiation, meaning that it is defined in the reactor class being instantiated or + * one of its base classes. + * + * @param eobject The object. + * @param instantiation The instantiation. + */ + public static boolean belongsTo(EObject eobject, Instantiation instantiation) { + Reactor reactor = toDefinition(instantiation.getReactorClass()); + return belongsTo(eobject, reactor); + } + + /** + * Return true if the specified object (a Parameter, Port, Action, or Timer) belongs to the + * specified reactor, meaning that it is defined in reactor class or one of its base classes. + * + * @param eobject The object. + * @param reactor The reactor. + */ + public static boolean belongsTo(EObject eobject, Reactor reactor) { + if (eobject.eContainer() == reactor) return true; + for (ReactorDecl baseClass : reactor.getSuperClasses()) { + if (belongsTo(eobject, toDefinition(baseClass))) { + return true; + } + } + return false; + } + + /** + * Given a parameter return its integer value or null if it does not have an integer value. If the + * value of the parameter is a list of integers, return the sum of value in the list. The + * instantiations parameter is as in {@link #initialValue(Parameter, List)}. + * + * @param parameter The parameter. + * @param instantiations The (optional) list of instantiations. + * @return The integer value of the parameter, or null if it does not have an integer value. + * @throws IllegalArgumentException If an instantiation provided is not an instantiation of the + * reactor class that is parameterized by the respective parameter or if the chain of + * instantiations is not nested. + */ + public static Integer initialValueInt(Parameter parameter, List instantiations) { + List expressions = initialValue(parameter, instantiations); + int result = 0; + for (Expression expr : expressions) { + if (!(expr instanceof Literal)) { return null; - } - - /** - * Return all single-line or multi-line comments immediately preceding the - * given EObject. - */ - public static Stream getPrecedingComments( - ICompositeNode compNode, - Predicate filter - ) { - return getPrecedingCommentNodes(compNode, filter).map(INode::getText); - } - - /** - * Return all single-line or multi-line comments immediately preceding the - * given EObject. - */ - public static Stream getPrecedingCommentNodes( - ICompositeNode compNode, - Predicate filter - ) { - if (compNode == null) return Stream.of(); - List ret = new ArrayList<>(); - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode)) { - if (isComment(node)) { - if (filter.test(node)) ret.add(node); - } else if (!node.getText().isBlank()) { - break; - } - } - } - return ret.stream(); - } - - /** Return whether {@code node} is a comment. */ - public static boolean isComment(INode node) { - return node instanceof HiddenLeafNode hlNode - && hlNode.getGrammarElement() instanceof TerminalRule tRule - && tRule.getName().endsWith("_COMMENT"); - } - - /** - * Return true if the given node starts on the same line as the given other - * node. - */ - public static Predicate sameLine(ICompositeNode compNode) { - return other -> { - for (INode node : compNode.getAsTreeIterable()) { - if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { - return node.getStartLine() == other.getStartLine(); - } - } - return false; - }; - } - - /** - * Find the main reactor and set its name if none was defined. - * @param resource The resource to find the main reactor in. - */ - public static void setMainName(Resource resource, String name) { - Reactor main = IteratorExtensions.findFirst(Iterators.filter(resource.getAllContents(), Reactor.class), - it -> it.isMain() || it.isFederated() - ); - if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { - main.setName(name); - } - } - - /** - * Create a new instantiation node with the given reactor as its defining class. - * @param reactor The reactor class to create an instantiation of. - */ - public static Instantiation createInstantiation(Reactor reactor) { - Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); - inst.setReactorClass(reactor); - // If the reactor is federated or at the top level, then it - // may not have a name. In the generator's doGenerate() - // method, the name gets set using setMainName(). - // But this may be called before that, e.g. during - // diagram synthesis. We assign a temporary name here. - if (reactor.getName() == null) { - if (reactor.isFederated() || reactor.isMain()) { - inst.setName("main"); - } else { - inst.setName(""); - } - + } + try { + result += Integer.decode(((Literal) expr).getLiteral()); + } catch (NumberFormatException ex) { + return null; + } + } + return result; + } + + /** + * Given the width specification of port or instantiation and an (optional) list of nested + * instantiations, return the width if it can be determined and -1 if not. It will not be able to + * be determined if either the width is variable (in which case you should use {@link + * #inferPortWidth(VarRef, Connection, List)} ) or the list of instantiations is incomplete or + * missing. If there are parameter references in the width, they are evaluated to the extent + * possible given the instantiations list. + * + *

    The instantiations list is as in {@link #initialValue(Parameter, List)}. If the spec belongs + * to an instantiation (for a bank of reactors), then the first element on this list should be the + * instantiation that contains this instantiation. If the spec belongs to a port, then the first + * element on the list should be the instantiation of the reactor that contains the port. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * @return The width, or -1 if the width could not be determined. + * @throws IllegalArgumentException If an instantiation provided is not as given above or if the + * chain of instantiations is not nested. + */ + public static int width(WidthSpec spec, List instantiations) { + if (spec == null) { + return 1; + } + if (spec.isOfVariableLength() && spec.eContainer() instanceof Instantiation) { + return inferWidthFromConnections(spec, instantiations); + } + var result = 0; + for (WidthTerm term : spec.getTerms()) { + if (term.getParameter() != null) { + Integer termWidth = initialValueInt(term.getParameter(), instantiations); + if (termWidth != null) { + result += termWidth; } else { - inst.setName(reactor.getName()); + return -1; } - return inst; - } - - /** - * Returns the target declaration in the given model. - * Non-null because it would cause a parse error. - */ - public static TargetDecl targetDecl(Model model) { - return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); - } - - /** - * Returns the target declaration in the given resource. - * Non-null because it would cause a parse error. - */ - public static TargetDecl targetDecl(Resource model) { - return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); - } - - ///////////////////////////////////////////////////////// - //// Private methods - - /** - * Returns the list if it is not null. Otherwise, return an empty list. - */ - public static List convertToEmptyListIfNull(List list) { - return list != null ? list : new ArrayList<>(); - } - - /** - * Return all the superclasses of the specified reactor - * in deepest-first order. For example, if A extends B and C, and - * B and C both extend D, this will return the list [D, B, C, A]. - * Duplicates are removed. If the specified reactor does not extend - * any other reactor, then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - * @param extensions A set of reactors extending the specified reactor - * (used to detect circular extensions). - */ - private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { - LinkedHashSet result = new LinkedHashSet<>(); - for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { - Reactor r = toDefinition(superDecl); - if (r == reactor || r == null) return null; - // If r is in the extensions, then we have a circular inheritance structure. - if (extensions.contains(r)) return null; - extensions.add(r); - LinkedHashSet baseExtends = superClasses(r, extensions); - extensions.remove(r); - if (baseExtends == null) return null; - result.addAll(baseExtends); - result.add(r); + } else if (term.getWidth() > 0) { + result += term.getWidth(); + } else { + // If the width cannot be determined because term's width <= 0, which means the term's width + // must be inferred, try to infer the width using connections. + if (spec.eContainer() instanceof Instantiation) { + try { + return inferWidthFromConnections(spec, instantiations); + } catch (InvalidSourceException e) { + // If the inference fails, return -1. + return -1; + } } - return result; - } - - /** - * Return all the file-level preambles in the files that define the - * specified class and its superclasses in deepest-first order. - * Duplicates are removed. If there are no file-level preambles, - * then return an empty list. - * If a cycle is found, where X extends Y and Y extends X, or if - * a superclass is declared that is not found, then return null. - * @param reactor The specified reactor. - * @param extensions A set of reactors extending the specified reactor - * (used to detect circular extensions). - */ - private static LinkedHashSet allFileLevelPreambles(Reactor reactor, Set extensions) { - LinkedHashSet result = new LinkedHashSet<>(); - for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { - Reactor r = toDefinition(superDecl); - if (r == reactor || r == null) return null; - // If r is in the extensions, then we have a circular inheritance structure. - if (extensions.contains(r)) return null; - extensions.add(r); - LinkedHashSet basePreambles = allFileLevelPreambles(r, extensions); - extensions.remove(r); - if (basePreambles == null) return null; - result.addAll(basePreambles); + } + } + return result; + } + + /** + * Infer the width of a port reference in a connection. The port reference one or two parts, a + * port and an (optional) container which is an Instantiation that may refer to a bank of + * reactors. The width will be the product of the bank width and the port width. The returned + * value will be 1 if the port is not in a bank and is not a multiport. + * + *

    If the width cannot be determined, this will return -1. The width cannot be determined if + * the list of instantiations is missing or incomplete. + * + *

    The instantiations list is as in {@link #initialValue(Parameter, List)}. The first element + * on this list should be the instantiation that contains the specified connection. + * + * @param reference A port reference. + * @param connection A connection, or null if not in the context of a connection. + * @param instantiations The (optional) list of instantiations. + * @return The width or -1 if it could not be determined. + * @throws IllegalArgumentException If an instantiation provided is not as given above or if the + * chain of instantiations is not nested. + */ + public static int inferPortWidth( + VarRef reference, Connection connection, List instantiations) { + if (reference.getVariable() instanceof Port) { + // If the port is given as a.b, then we want to prepend a to + // the list of instantiations to determine the width of this port. + List extended = instantiations; + if (reference.getContainer() != null) { + extended = new ArrayList<>(); + extended.add(reference.getContainer()); + if (instantiations != null) { + extended.addAll(instantiations); } - result.addAll(((Model) reactor.eContainer()).getPreambles()); - return result; - } + } - /** - * We may be able to infer the width by examining the connections of - * the enclosing reactor definition. This works, for example, with - * delays between multiports or banks of reactors. - * Attempt to infer the width from connections and return -1 if the width cannot be inferred. - * - * @param spec The width specification or null (to return 1). - * @param instantiations The (optional) list of instantiations. - * - * @return The width, or -1 if the width could not be inferred from connections. - */ - private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { - for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + int portWidth = width(((Port) reference.getVariable()).getWidthSpec(), extended); + if (portWidth < 0) { + // Could not determine port width. + return -1; + } + + // Next determine the bank width. This may be unspecified, in which + // case it has to be inferred using the connection. + int bankWidth = 1; + if (reference.getContainer() != null) { + bankWidth = width(reference.getContainer().getWidthSpec(), instantiations); + if (bankWidth < 0 && connection != null) { + // Try to infer the bank width from the connection. + if (reference.getContainer().getWidthSpec().isOfVariableLength()) { + // This occurs for a bank of delays. int leftWidth = 0; int rightWidth = 0; int leftOrRight = 0; - for (VarRef leftPort : c.getLeftPorts()) { - if (leftPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the left. - leftOrRight = -1; - } else { - leftWidth += inferPortWidth(leftPort, c, instantiations); + for (VarRef leftPort : connection.getLeftPorts()) { + if (leftPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException( + "Multiple ports with variable width on a connection."); + } + // Indicate that this port is on the left. + leftOrRight = -1; + } else { + // The left port is not the same as this reference. + int otherWidth = inferPortWidth(leftPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; } + leftWidth += otherWidth; + } } - for (VarRef rightPort : c.getRightPorts()) { - if (rightPort.getContainer() == spec.eContainer()) { - if (leftOrRight != 0) { - throw new InvalidSourceException("Multiple ports with variable width on a connection."); - } - // Indicate that the port is on the right. - leftOrRight = 1; - } else { - rightWidth += inferPortWidth(rightPort, c, instantiations); + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort == reference) { + if (leftOrRight != 0) { + throw new InvalidSourceException( + "Multiple ports with variable width on a connection."); } + // Indicate that this port is on the right. + leftOrRight = 1; + } else { + int otherWidth = inferPortWidth(rightPort, connection, instantiations); + if (otherWidth < 0) { + // Cannot determine width. + return -1; + } + rightWidth += otherWidth; + } } + int discrepancy = 0; if (leftOrRight < 0) { - return rightWidth - leftWidth; + // This port is on the left. + discrepancy = rightWidth - leftWidth; } else if (leftOrRight > 0) { - return leftWidth - rightWidth; + // This port is on the right. + discrepancy = leftWidth - rightWidth; + } + // Check that portWidth divides the discrepancy. + if (discrepancy % portWidth != 0) { + // This is an error. + return -1; } + bankWidth = discrepancy / portWidth; + } else { + // Could not determine the bank width. + return -1; + } } - // A connection was not found with the instantiation. - return -1; - } - - public static void addReactionAttribute(Reaction reaction, String name) { - var fedAttr = factory.createAttribute(); - fedAttr.setAttrName(name); - reaction.getAttributes().add(fedAttr); - } + } + return portWidth * bankWidth; + } + // Argument is not a port. + return -1; + } + + /** + * Given an instantiation of a reactor or bank of reactors, return the width. This will be 1 if + * this is not a reactor bank. Otherwise, this will attempt to determine the width. If the width + * is declared as a literal constant, it will return that constant. If the width is specified as a + * reference to a parameter, this will throw an exception. If the width is variable, this will + * find connections in the enclosing reactor and attempt to infer the width. If the width cannot + * be determined, it will throw an exception. + * + *

    IMPORTANT: This method should not be used you really need to determine the width! It will + * not evaluate parameter values. + * + * @see #width(WidthSpec, List) + * @param instantiation A reactor instantiation. + * @return The width, if it can be determined. + * @deprecated + */ + @Deprecated + public static int widthSpecification(Instantiation instantiation) { + int result = width(instantiation.getWidthSpec(), null); + if (result < 0) { + throw new InvalidSourceException( + "Cannot determine width for the instance " + instantiation.getName()); + } + return result; + } + + /** + * Report whether a state variable has been initialized or not. + * + * @param v The state variable to be checked. + * @return True if the variable was initialized, false otherwise. + */ + public static boolean isInitialized(StateVar v) { + return v != null && v.getInit() != null; + } + + /** + * Report whether the given time state variable is initialized using a parameter or not. + * + * @param s A state variable. + * @return True if the argument is initialized using a parameter, false otherwise. + */ + public static boolean isParameterized(StateVar s) { + return s.getInit() != null + && IterableExtensions.exists( + s.getInit().getExprs(), it -> it instanceof ParameterReference); + } + + /** + * Check if the reactor class uses generics + * + * @param r the reactor to check + * @return true if the reactor uses generics + */ + public static boolean isGeneric(Reactor r) { + if (r == null) { + return false; + } + return r.getTypeParms().size() != 0; + } + + /** + * If the specified reactor declaration is an import, then return the imported reactor class + * definition. Otherwise, just return the argument. + * + * @param r A Reactor or an ImportedReactor. + * @return The Reactor class definition or null if no definition is found. + */ + public static Reactor toDefinition(ReactorDecl r) { + if (r == null) return null; + if (r instanceof Reactor) { + return (Reactor) r; + } else if (r instanceof ImportedReactor) { + return ((ImportedReactor) r).getReactorClass(); + } + return null; + } + + /** Return all single-line or multi-line comments immediately preceding the given EObject. */ + public static Stream getPrecedingComments( + ICompositeNode compNode, Predicate filter) { + return getPrecedingCommentNodes(compNode, filter).map(INode::getText); + } + + /** Return all single-line or multi-line comments immediately preceding the given EObject. */ + public static Stream getPrecedingCommentNodes( + ICompositeNode compNode, Predicate filter) { + if (compNode == null) return Stream.of(); + List ret = new ArrayList<>(); + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode)) { + if (isComment(node)) { + if (filter.test(node)) ret.add(node); + } else if (!node.getText().isBlank()) { + break; + } + } + } + return ret.stream(); + } + + /** Return whether {@code node} is a comment. */ + public static boolean isComment(INode node) { + return node instanceof HiddenLeafNode hlNode + && hlNode.getGrammarElement() instanceof TerminalRule tRule + && tRule.getName().endsWith("_COMMENT"); + } + + /** Return true if the given node starts on the same line as the given other node. */ + public static Predicate sameLine(ICompositeNode compNode) { + return other -> { + for (INode node : compNode.getAsTreeIterable()) { + if (!(node instanceof ICompositeNode) && !node.getText().isBlank() && !isComment(node)) { + return node.getStartLine() == other.getStartLine(); + } + } + return false; + }; + } + + /** + * Find the main reactor and set its name if none was defined. + * + * @param resource The resource to find the main reactor in. + */ + public static void setMainName(Resource resource, String name) { + Reactor main = + IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), + it -> it.isMain() || it.isFederated()); + if (main != null && StringExtensions.isNullOrEmpty(main.getName())) { + main.setName(name); + } + } + + /** + * Create a new instantiation node with the given reactor as its defining class. + * + * @param reactor The reactor class to create an instantiation of. + */ + public static Instantiation createInstantiation(Reactor reactor) { + Instantiation inst = LfFactory.eINSTANCE.createInstantiation(); + inst.setReactorClass(reactor); + // If the reactor is federated or at the top level, then it + // may not have a name. In the generator's doGenerate() + // method, the name gets set using setMainName(). + // But this may be called before that, e.g. during + // diagram synthesis. We assign a temporary name here. + if (reactor.getName() == null) { + if (reactor.isFederated() || reactor.isMain()) { + inst.setName("main"); + } else { + inst.setName(""); + } + + } else { + inst.setName(reactor.getName()); + } + return inst; + } + + /** + * Returns the target declaration in the given model. Non-null because it would cause a parse + * error. + */ + public static TargetDecl targetDecl(Model model) { + return IteratorExtensions.head(Iterators.filter(model.eAllContents(), TargetDecl.class)); + } + + /** + * Returns the target declaration in the given resource. Non-null because it would cause a parse + * error. + */ + public static TargetDecl targetDecl(Resource model) { + return IteratorExtensions.head(Iterators.filter(model.getAllContents(), TargetDecl.class)); + } + + ///////////////////////////////////////////////////////// + //// Private methods + + /** Returns the list if it is not null. Otherwise, return an empty list. */ + public static List convertToEmptyListIfNull(List list) { + return list != null ? list : new ArrayList<>(); + } + + /** + * Return all the superclasses of the specified reactor in deepest-first order. For example, if A + * extends B and C, and B and C both extend D, this will return the list [D, B, C, A]. Duplicates + * are removed. If the specified reactor does not extend any other reactor, then return an empty + * list. If a cycle is found, where X extends Y and Y extends X, or if a superclass is declared + * that is not found, then return null. + * + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor (used to detect circular + * extensions). + */ + private static LinkedHashSet superClasses(Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet baseExtends = superClasses(r, extensions); + extensions.remove(r); + if (baseExtends == null) return null; + result.addAll(baseExtends); + result.add(r); + } + return result; + } + + /** + * Return all the file-level preambles in the files that define the specified class and its + * superclasses in deepest-first order. Duplicates are removed. If there are no file-level + * preambles, then return an empty list. If a cycle is found, where X extends Y and Y extends X, + * or if a superclass is declared that is not found, then return null. + * + * @param reactor The specified reactor. + * @param extensions A set of reactors extending the specified reactor (used to detect circular + * extensions). + */ + private static LinkedHashSet allFileLevelPreambles( + Reactor reactor, Set extensions) { + LinkedHashSet result = new LinkedHashSet<>(); + for (ReactorDecl superDecl : convertToEmptyListIfNull(reactor.getSuperClasses())) { + Reactor r = toDefinition(superDecl); + if (r == reactor || r == null) return null; + // If r is in the extensions, then we have a circular inheritance structure. + if (extensions.contains(r)) return null; + extensions.add(r); + LinkedHashSet basePreambles = allFileLevelPreambles(r, extensions); + extensions.remove(r); + if (basePreambles == null) return null; + result.addAll(basePreambles); + } + result.addAll(((Model) reactor.eContainer()).getPreambles()); + return result; + } + + /** + * We may be able to infer the width by examining the connections of the enclosing reactor + * definition. This works, for example, with delays between multiports or banks of reactors. + * Attempt to infer the width from connections and return -1 if the width cannot be inferred. + * + * @param spec The width specification or null (to return 1). + * @param instantiations The (optional) list of instantiations. + * @return The width, or -1 if the width could not be inferred from connections. + */ + private static int inferWidthFromConnections(WidthSpec spec, List instantiations) { + for (Connection c : ((Reactor) spec.eContainer().eContainer()).getConnections()) { + int leftWidth = 0; + int rightWidth = 0; + int leftOrRight = 0; + for (VarRef leftPort : c.getLeftPorts()) { + if (leftPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the left. + leftOrRight = -1; + } else { + leftWidth += inferPortWidth(leftPort, c, instantiations); + } + } + for (VarRef rightPort : c.getRightPorts()) { + if (rightPort.getContainer() == spec.eContainer()) { + if (leftOrRight != 0) { + throw new InvalidSourceException("Multiple ports with variable width on a connection."); + } + // Indicate that the port is on the right. + leftOrRight = 1; + } else { + rightWidth += inferPortWidth(rightPort, c, instantiations); + } + } + if (leftOrRight < 0) { + return rightWidth - leftWidth; + } else if (leftOrRight > 0) { + return leftWidth - rightWidth; + } + } + // A connection was not found with the instantiation. + return -1; + } + + public static void addReactionAttribute(Reaction reaction, String name) { + var fedAttr = factory.createAttribute(); + fedAttr.setAttrName(name); + reaction.getAttributes().add(fedAttr); + } } diff --git a/org.lflang/src/org/lflang/ast/AstTransformation.java b/org.lflang/src/org/lflang/ast/AstTransformation.java index 80a93da4b9..cf5c5843ff 100644 --- a/org.lflang/src/org/lflang/ast/AstTransformation.java +++ b/org.lflang/src/org/lflang/ast/AstTransformation.java @@ -1,16 +1,11 @@ package org.lflang.ast; import java.util.List; - import org.lflang.lf.Reactor; -/** - * Interface for AST Transfomations - */ +/** Interface for AST Transfomations */ public interface AstTransformation { - /** - * Apply the AST transformation to all given reactors. - */ - void applyTransformation(List reactors); + /** Apply the AST transformation to all given reactors. */ + void applyTransformation(List reactors); } diff --git a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java index 953b9bdfdb..882019ac44 100644 --- a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java +++ b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java @@ -6,13 +6,11 @@ import java.util.List; import java.util.Map; import java.util.Objects; - import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; - import org.lflang.InferredType; import org.lflang.generator.DelayBodyGenerator; import org.lflang.generator.TargetTypes; @@ -40,365 +38,371 @@ import org.lflang.lf.WidthTerm; /** - This class implements AST transformations for delayed connections. - There are two types of delayed connections: - 1) Connections with {@code after}-delays - 2) Physical connections + * This class implements AST transformations for delayed connections. There are two types of delayed + * connections: 1) Connections with {@code after}-delays 2) Physical connections */ public class DelayedConnectionTransformation implements AstTransformation { - /** - * The Lingua Franca factory for creating new AST nodes. - */ - public static final LfFactory factory = ASTUtils.factory; - - /** - * A code generator used to insert reaction bodies for the generated delay reactors. - */ - private final DelayBodyGenerator generator; - - /** - * A target type instance that is used during the transformation to manage target specific types - */ - private final TargetTypes targetTypes; - - /** - * The Eclipse eCore view of the main LF file. - */ - private final Resource mainResource; - - private boolean transformAfterDelays = false; - private boolean transformPhysicalConnection = false; - /** - * Collection of generated delay classes. - */ - private final LinkedHashSet delayClasses = new LinkedHashSet<>(); - - public DelayedConnectionTransformation(DelayBodyGenerator generator, TargetTypes targetTypes, Resource mainResource, boolean transformAfterDelays, boolean transformPhysicalConnections) { - this.generator = generator; - this.targetTypes = targetTypes; - this.mainResource = mainResource; - this.transformAfterDelays = transformAfterDelays; - this.transformPhysicalConnection = transformPhysicalConnections; - } - - /** - * Transform all after delay connections by inserting generated delay reactors. - */ - @Override - public void applyTransformation(List reactors) { - insertGeneratedDelays(reactors); - } - - /** - * Find connections in the given resource that have a delay associated with them, - * and reroute them via a generated delay reactor. - * @param reactors A list of reactors to apply the transformation to. - */ - private void insertGeneratedDelays(List reactors) { - // The resulting changes to the AST are performed _after_ iterating - // in order to avoid concurrent modification problems. - List oldConnections = new ArrayList<>(); - Map> newConnections = new LinkedHashMap<>(); - Map> delayInstances = new LinkedHashMap<>(); - - // Iterate over the connections in the tree. - for (Reactor container : reactors) { - for (Connection connection : ASTUtils.allConnections(container)) { - if ( transformAfterDelays && connection.getDelay() != null || - transformPhysicalConnection && connection.isPhysical()) { - EObject parent = connection.eContainer(); - // Assume all the types are the same, so just use the first on the right. - Type type = ((Port) connection.getRightPorts().get(0).getVariable()).getType(); - Reactor delayClass = getDelayClass(type, connection.isPhysical()); - String generic = targetTypes.supportsGenerics() - ? targetTypes.getTargetType(type) : null; - - Instantiation delayInstance = getDelayInstance(delayClass, connection, generic, - !generator.generateAfterDelaysWithVariableWidth(), connection.isPhysical()); - - // Stage the new connections for insertion into the tree. - List connections = ASTUtils.convertToEmptyListIfNull(newConnections.get(parent)); - connections.addAll(rerouteViaDelay(connection, delayInstance)); - newConnections.put(parent, connections); - // Stage the original connection for deletion from the tree. - oldConnections.add(connection); - - // Stage the newly created delay reactor instance for insertion - List instances = ASTUtils.convertToEmptyListIfNull(delayInstances.get(parent)); - instances.add(delayInstance); - delayInstances.put(parent, instances); - } - } + /** The Lingua Franca factory for creating new AST nodes. */ + public static final LfFactory factory = ASTUtils.factory; + + /** A code generator used to insert reaction bodies for the generated delay reactors. */ + private final DelayBodyGenerator generator; + + /** + * A target type instance that is used during the transformation to manage target specific types + */ + private final TargetTypes targetTypes; + + /** The Eclipse eCore view of the main LF file. */ + private final Resource mainResource; + + private boolean transformAfterDelays = false; + private boolean transformPhysicalConnection = false; + /** Collection of generated delay classes. */ + private final LinkedHashSet delayClasses = new LinkedHashSet<>(); + + public DelayedConnectionTransformation( + DelayBodyGenerator generator, + TargetTypes targetTypes, + Resource mainResource, + boolean transformAfterDelays, + boolean transformPhysicalConnections) { + this.generator = generator; + this.targetTypes = targetTypes; + this.mainResource = mainResource; + this.transformAfterDelays = transformAfterDelays; + this.transformPhysicalConnection = transformPhysicalConnections; + } + + /** Transform all after delay connections by inserting generated delay reactors. */ + @Override + public void applyTransformation(List reactors) { + insertGeneratedDelays(reactors); + } + + /** + * Find connections in the given resource that have a delay associated with them, and reroute them + * via a generated delay reactor. + * + * @param reactors A list of reactors to apply the transformation to. + */ + private void insertGeneratedDelays(List reactors) { + // The resulting changes to the AST are performed _after_ iterating + // in order to avoid concurrent modification problems. + List oldConnections = new ArrayList<>(); + Map> newConnections = new LinkedHashMap<>(); + Map> delayInstances = new LinkedHashMap<>(); + + // Iterate over the connections in the tree. + for (Reactor container : reactors) { + for (Connection connection : ASTUtils.allConnections(container)) { + if (transformAfterDelays && connection.getDelay() != null + || transformPhysicalConnection && connection.isPhysical()) { + EObject parent = connection.eContainer(); + // Assume all the types are the same, so just use the first on the right. + Type type = ((Port) connection.getRightPorts().get(0).getVariable()).getType(); + Reactor delayClass = getDelayClass(type, connection.isPhysical()); + String generic = targetTypes.supportsGenerics() ? targetTypes.getTargetType(type) : null; + + Instantiation delayInstance = + getDelayInstance( + delayClass, + connection, + generic, + !generator.generateAfterDelaysWithVariableWidth(), + connection.isPhysical()); + + // Stage the new connections for insertion into the tree. + List connections = + ASTUtils.convertToEmptyListIfNull(newConnections.get(parent)); + connections.addAll(rerouteViaDelay(connection, delayInstance)); + newConnections.put(parent, connections); + // Stage the original connection for deletion from the tree. + oldConnections.add(connection); + + // Stage the newly created delay reactor instance for insertion + List instances = + ASTUtils.convertToEmptyListIfNull(delayInstances.get(parent)); + instances.add(delayInstance); + delayInstances.put(parent, instances); } + } + } - // Remove old connections; insert new ones. - oldConnections.forEach(connection -> { - var container = connection.eContainer(); - if (container instanceof Reactor) { - ((Reactor) container).getConnections().remove(connection); - } else if (container instanceof Mode) { - ((Mode) container).getConnections().remove(connection); - } + // Remove old connections; insert new ones. + oldConnections.forEach( + connection -> { + var container = connection.eContainer(); + if (container instanceof Reactor) { + ((Reactor) container).getConnections().remove(connection); + } else if (container instanceof Mode) { + ((Mode) container).getConnections().remove(connection); + } }); - newConnections.forEach((container, connections) -> { - if (container instanceof Reactor) { - ((Reactor) container).getConnections().addAll(connections); - } else if (container instanceof Mode) { - ((Mode) container).getConnections().addAll(connections); - } + newConnections.forEach( + (container, connections) -> { + if (container instanceof Reactor) { + ((Reactor) container).getConnections().addAll(connections); + } else if (container instanceof Mode) { + ((Mode) container).getConnections().addAll(connections); + } }); - // Finally, insert the instances and, before doing so, assign them a unique name. - delayInstances.forEach((container, instantiations) -> - instantiations.forEach(instantiation -> { - if (container instanceof Reactor) { - instantiation.setName(ASTUtils.getUniqueIdentifier((Reactor) container, "delay")); + // Finally, insert the instances and, before doing so, assign them a unique name. + delayInstances.forEach( + (container, instantiations) -> + instantiations.forEach( + instantiation -> { + if (container instanceof Reactor) { + instantiation.setName( + ASTUtils.getUniqueIdentifier((Reactor) container, "delay")); ((Reactor) container).getInstantiations().add(instantiation); - } else if (container instanceof Mode) { - instantiation.setName(ASTUtils.getUniqueIdentifier((Reactor) container.eContainer(), "delay")); + } else if (container instanceof Mode) { + instantiation.setName( + ASTUtils.getUniqueIdentifier((Reactor) container.eContainer(), "delay")); ((Mode) container).getInstantiations().add(instantiation); - } - }) - ); - } - - /** - * Take a connection and reroute it via an instance of a generated delay - * reactor. This method returns a list to new connections to substitute - * the original one. - * @param connection The connection to reroute. - * @param delayInstance The delay instance to route the connection through. - */ - private static List rerouteViaDelay(Connection connection, - Instantiation delayInstance) { - List connections = new ArrayList<>(); - Connection upstream = factory.createConnection(); - Connection downstream = factory.createConnection(); - VarRef input = factory.createVarRef(); - VarRef output = factory.createVarRef(); - - Reactor delayClass = ASTUtils.toDefinition(delayInstance.getReactorClass()); - - // Establish references to the involved ports. - input.setContainer(delayInstance); - input.setVariable(delayClass.getInputs().get(0)); - output.setContainer(delayInstance); - output.setVariable(delayClass.getOutputs().get(0)); - upstream.getLeftPorts().addAll(connection.getLeftPorts()); - upstream.getRightPorts().add(input); - downstream.getLeftPorts().add(output); - downstream.getRightPorts().addAll(connection.getRightPorts()); - downstream.setIterated(connection.isIterated()); - connections.add(upstream); - connections.add(downstream); - return connections; + } + })); + } + + /** + * Take a connection and reroute it via an instance of a generated delay reactor. This method + * returns a list to new connections to substitute the original one. + * + * @param connection The connection to reroute. + * @param delayInstance The delay instance to route the connection through. + */ + private static List rerouteViaDelay( + Connection connection, Instantiation delayInstance) { + List connections = new ArrayList<>(); + Connection upstream = factory.createConnection(); + Connection downstream = factory.createConnection(); + VarRef input = factory.createVarRef(); + VarRef output = factory.createVarRef(); + + Reactor delayClass = ASTUtils.toDefinition(delayInstance.getReactorClass()); + + // Establish references to the involved ports. + input.setContainer(delayInstance); + input.setVariable(delayClass.getInputs().get(0)); + output.setContainer(delayInstance); + output.setVariable(delayClass.getOutputs().get(0)); + upstream.getLeftPorts().addAll(connection.getLeftPorts()); + upstream.getRightPorts().add(input); + downstream.getLeftPorts().add(output); + downstream.getRightPorts().addAll(connection.getRightPorts()); + downstream.setIterated(connection.isIterated()); + connections.add(upstream); + connections.add(downstream); + return connections; + } + + /** + * Create a new instance delay instances using the given reactor class. The supplied time value is + * used to override the default interval (which is zero). If the target supports parametric + * polymorphism, then a single class may be used for each instantiation, in which case a non-empty + * string must be supplied to parameterize the instance. A default name ("delay") is assigned to + * the instantiation, but this name must be overridden at the call site, where checks can be done + * to avoid name collisions in the container in which the instantiation is to be placed. Such + * checks (or modifications of the AST) are not performed in this method in order to avoid causing + * concurrent modification exceptions. + * + * @param delayClass The class to create an instantiation for + * @param connection The connection to create a delay instantiation foe + * @param genericArg A string that denotes the appropriate type parameter, which should be null or + * empty if the target does not support generics. + * @param defineWidthFromConnection If this is true and if the connection is a wide connection, + * then instantiate a bank of delays where the width is given by ports involved in the + * connection. Otherwise, the width will be unspecified indicating a variable length. + * @param isPhysical Is this a delay instance using a physical action. These are used for + * implementing Physical Connections. If true we will accept zero delay on the connection. + */ + private static Instantiation getDelayInstance( + Reactor delayClass, + Connection connection, + String genericArg, + Boolean defineWidthFromConnection, + Boolean isPhysical) { + Instantiation delayInstance = factory.createInstantiation(); + delayInstance.setReactorClass(delayClass); + if (genericArg != null) { + Code code = factory.createCode(); + code.setBody(genericArg); + Type type = factory.createType(); + type.setCode(code); + delayInstance.getTypeArgs().add(type); } - - /** - * Create a new instance delay instances using the given reactor class. - * The supplied time value is used to override the default interval (which - * is zero). - * If the target supports parametric polymorphism, then a single class may - * be used for each instantiation, in which case a non-empty string must - * be supplied to parameterize the instance. - * A default name ("delay") is assigned to the instantiation, but this - * name must be overridden at the call site, where checks can be done to - * avoid name collisions in the container in which the instantiation is - * to be placed. Such checks (or modifications of the AST) are not - * performed in this method in order to avoid causing concurrent - * modification exceptions. - * @param delayClass The class to create an instantiation for - * @param connection The connection to create a delay instantiation foe - * @param genericArg A string that denotes the appropriate type parameter, - * which should be null or empty if the target does not support generics. - * @param defineWidthFromConnection If this is true and if the connection - * is a wide connection, then instantiate a bank of delays where the width - * is given by ports involved in the connection. Otherwise, the width will - * be unspecified indicating a variable length. - * @param isPhysical Is this a delay instance using a physical action. - * These are used for implementing Physical Connections. If true - * we will accept zero delay on the connection. - */ - private static Instantiation getDelayInstance(Reactor delayClass, - Connection connection, String genericArg, Boolean defineWidthFromConnection, Boolean isPhysical) { - Instantiation delayInstance = factory.createInstantiation(); - delayInstance.setReactorClass(delayClass); - if (genericArg != null) { - Code code = factory.createCode(); - code.setBody(genericArg); - Type type = factory.createType(); - type.setCode(code); - delayInstance.getTypeArgs().add(type); - } - if (ASTUtils.hasMultipleConnections(connection)) { - WidthSpec widthSpec = factory.createWidthSpec(); - if (defineWidthFromConnection) { - // Add all left ports of the connection to the WidthSpec of the generated delay instance. - // This allows the code generator to later infer the width from the involved ports. - // We only consider the left ports here, as they could be part of a broadcast. In this case, we want - // to delay the ports first, and then broadcast the output of the delays. - for (VarRef port : connection.getLeftPorts()) { - WidthTerm term = factory.createWidthTerm(); - term.setPort(EcoreUtil.copy(port)); - widthSpec.getTerms().add(term); - } - } else { - widthSpec.setOfVariableLength(true); - } - delayInstance.setWidthSpec(widthSpec); - } - // Allow physical connections with no after delay - // they will use the default min_delay of 0. - if (!isPhysical || connection.getDelay() != null) { - Assignment assignment = factory.createAssignment(); - assignment.setLhs(delayClass.getParameters().get(0)); - Initializer init = factory.createInitializer(); - init.getExprs().add(Objects.requireNonNull(connection.getDelay(), "null delay")); - assignment.setRhs(init); - delayInstance.getParameters().add(assignment); + if (ASTUtils.hasMultipleConnections(connection)) { + WidthSpec widthSpec = factory.createWidthSpec(); + if (defineWidthFromConnection) { + // Add all left ports of the connection to the WidthSpec of the generated delay instance. + // This allows the code generator to later infer the width from the involved ports. + // We only consider the left ports here, as they could be part of a broadcast. In this case, + // we want + // to delay the ports first, and then broadcast the output of the delays. + for (VarRef port : connection.getLeftPorts()) { + WidthTerm term = factory.createWidthTerm(); + term.setPort(EcoreUtil.copy(port)); + widthSpec.getTerms().add(term); } - - delayInstance.setName("delay"); // This has to be overridden. - return delayInstance; + } else { + widthSpec.setOfVariableLength(true); + } + delayInstance.setWidthSpec(widthSpec); + } + // Allow physical connections with no after delay + // they will use the default min_delay of 0. + if (!isPhysical || connection.getDelay() != null) { + Assignment assignment = factory.createAssignment(); + assignment.setLhs(delayClass.getParameters().get(0)); + Initializer init = factory.createInitializer(); + init.getExprs().add(Objects.requireNonNull(connection.getDelay(), "null delay")); + assignment.setRhs(init); + delayInstance.getParameters().add(assignment); } - /** - * Return a synthesized AST node that represents the definition of a delay - * reactor. Depending on whether the target supports generics, either this - * method will synthesize a generic definition and keep returning it upon - * subsequent calls, or otherwise, it will synthesize a new definition for - * each new type it hasn't yet created a compatible delay reactor for. - * @param type The type the delay class must be compatible with. - * @param isPhysical Is this delay reactor using a physical action. - */ - private Reactor getDelayClass(Type type, boolean isPhysical) { - String className; - if (targetTypes.supportsGenerics()) { - className = DelayBodyGenerator.GEN_DELAY_CLASS_NAME; - } else { - String id = Integer.toHexString(InferredType.fromAST(type).toText().hashCode()); - className = String.format("%s_%s", DelayBodyGenerator.GEN_DELAY_CLASS_NAME, id); - } - - // Only add class definition if it is not already there. - Reactor classDef = findDelayClass(className); - if (classDef != null) { - return classDef; - } - - Reactor delayClass = factory.createReactor(); - Parameter delayParameter = factory.createParameter(); - Action action = factory.createAction(); - VarRef triggerRef = factory.createVarRef(); - VarRef effectRef = factory.createVarRef(); - Input input = factory.createInput(); - Output output = factory.createOutput(); - VarRef inRef = factory.createVarRef(); - VarRef outRef = factory.createVarRef(); - - Reaction r1 = factory.createReaction(); - Reaction r2 = factory.createReaction(); - - delayParameter.setName("delay"); - delayParameter.setType(factory.createType()); - delayParameter.getType().setId("time"); - delayParameter.getType().setTime(true); - Time defaultTime = factory.createTime(); - defaultTime.setUnit(null); - defaultTime.setInterval(0); - Initializer init = factory.createInitializer(); - init.setParens(true); - init.setBraces(false); - init.getExprs().add(defaultTime); - delayParameter.setInit(init); - - // Name the newly created action; set its delay and type. - action.setName("act"); - var paramRef = factory.createParameterReference(); - paramRef.setParameter(delayParameter); - action.setMinDelay(paramRef); - if (isPhysical) { - action.setOrigin(ActionOrigin.PHYSICAL); - } else { - action.setOrigin(ActionOrigin.LOGICAL); - } + delayInstance.setName("delay"); // This has to be overridden. + return delayInstance; + } + + /** + * Return a synthesized AST node that represents the definition of a delay reactor. Depending on + * whether the target supports generics, either this method will synthesize a generic definition + * and keep returning it upon subsequent calls, or otherwise, it will synthesize a new definition + * for each new type it hasn't yet created a compatible delay reactor for. + * + * @param type The type the delay class must be compatible with. + * @param isPhysical Is this delay reactor using a physical action. + */ + private Reactor getDelayClass(Type type, boolean isPhysical) { + String className; + if (targetTypes.supportsGenerics()) { + className = DelayBodyGenerator.GEN_DELAY_CLASS_NAME; + } else { + String id = Integer.toHexString(InferredType.fromAST(type).toText().hashCode()); + className = String.format("%s_%s", DelayBodyGenerator.GEN_DELAY_CLASS_NAME, id); + } - if (targetTypes.supportsGenerics()) { - action.setType(factory.createType()); - action.getType().setId("T"); - } else { - action.setType(EcoreUtil.copy(type)); - } + // Only add class definition if it is not already there. + Reactor classDef = findDelayClass(className); + if (classDef != null) { + return classDef; + } - input.setName("inp"); - input.setType(EcoreUtil.copy(action.getType())); - - output.setName("out"); - output.setType(EcoreUtil.copy(action.getType())); - - // Establish references to the involved ports. - inRef.setVariable(input); - outRef.setVariable(output); - - // Establish references to the action. - triggerRef.setVariable(action); - effectRef.setVariable(action); - - // Add the action to the reactor. - delayClass.setName(className); - delayClass.getActions().add(action); - - // Configure the second reaction, which reads the input. - r1.getTriggers().add(inRef); - r1.getEffects().add(effectRef); - r1.setCode(factory.createCode()); - r1.getCode().setBody(generator.generateDelayBody(action, inRef)); - - // Configure the first reaction, which produces the output. - r2.getTriggers().add(triggerRef); - r2.getEffects().add(outRef); - r2.setCode(factory.createCode()); - r2.getCode().setBody(generator.generateForwardBody(action, outRef)); - - generator.finalizeReactions(r1, r2); - - // Add the reactions to the newly created reactor class. - // These need to go in the opposite order in case - // a new input arrives at the same time the delayed - // output is delivered! - delayClass.getReactions().add(r2); - delayClass.getReactions().add(r1); - - // Add a type parameter if the target supports it. - if (targetTypes.supportsGenerics()) { - TypeParm parm = factory.createTypeParm(); - parm.setLiteral(generator.generateDelayGeneric()); - delayClass.getTypeParms().add(parm); - } - delayClass.getInputs().add(input); - delayClass.getOutputs().add(output); - delayClass.getParameters().add(delayParameter); - addDelayClass(delayClass); - return delayClass; + Reactor delayClass = factory.createReactor(); + Parameter delayParameter = factory.createParameter(); + Action action = factory.createAction(); + VarRef triggerRef = factory.createVarRef(); + VarRef effectRef = factory.createVarRef(); + Input input = factory.createInput(); + Output output = factory.createOutput(); + VarRef inRef = factory.createVarRef(); + VarRef outRef = factory.createVarRef(); + + Reaction r1 = factory.createReaction(); + Reaction r2 = factory.createReaction(); + + delayParameter.setName("delay"); + delayParameter.setType(factory.createType()); + delayParameter.getType().setId("time"); + delayParameter.getType().setTime(true); + Time defaultTime = factory.createTime(); + defaultTime.setUnit(null); + defaultTime.setInterval(0); + Initializer init = factory.createInitializer(); + init.setParens(true); + init.setBraces(false); + init.getExprs().add(defaultTime); + delayParameter.setInit(init); + + // Name the newly created action; set its delay and type. + action.setName("act"); + var paramRef = factory.createParameterReference(); + paramRef.setParameter(delayParameter); + action.setMinDelay(paramRef); + if (isPhysical) { + action.setOrigin(ActionOrigin.PHYSICAL); + } else { + action.setOrigin(ActionOrigin.LOGICAL); } - /** - * Store the given reactor in the collection of generated delay classes - * and insert it in the AST under the top-level reactor's node. - */ - private void addDelayClass(Reactor generatedDelay) { - // Record this class, so it can be reused. - delayClasses.add(generatedDelay); - // And hook it into the AST. - EObject node = IteratorExtensions.findFirst(mainResource.getAllContents(), Model.class::isInstance); - ((Model) node).getReactors().add(generatedDelay); + if (targetTypes.supportsGenerics()) { + action.setType(factory.createType()); + action.getType().setId("T"); + } else { + action.setType(EcoreUtil.copy(type)); } - /** - * Return the generated delay reactor that corresponds to the given class - * name if it had been created already, {@code null} otherwise. - */ - private Reactor findDelayClass(String className) { - return IterableExtensions.findFirst(delayClasses, it -> it.getName().equals(className)); + input.setName("inp"); + input.setType(EcoreUtil.copy(action.getType())); + + output.setName("out"); + output.setType(EcoreUtil.copy(action.getType())); + + // Establish references to the involved ports. + inRef.setVariable(input); + outRef.setVariable(output); + + // Establish references to the action. + triggerRef.setVariable(action); + effectRef.setVariable(action); + + // Add the action to the reactor. + delayClass.setName(className); + delayClass.getActions().add(action); + + // Configure the second reaction, which reads the input. + r1.getTriggers().add(inRef); + r1.getEffects().add(effectRef); + r1.setCode(factory.createCode()); + r1.getCode().setBody(generator.generateDelayBody(action, inRef)); + + // Configure the first reaction, which produces the output. + r2.getTriggers().add(triggerRef); + r2.getEffects().add(outRef); + r2.setCode(factory.createCode()); + r2.getCode().setBody(generator.generateForwardBody(action, outRef)); + + generator.finalizeReactions(r1, r2); + + // Add the reactions to the newly created reactor class. + // These need to go in the opposite order in case + // a new input arrives at the same time the delayed + // output is delivered! + delayClass.getReactions().add(r2); + delayClass.getReactions().add(r1); + + // Add a type parameter if the target supports it. + if (targetTypes.supportsGenerics()) { + TypeParm parm = factory.createTypeParm(); + parm.setLiteral(generator.generateDelayGeneric()); + delayClass.getTypeParms().add(parm); } + delayClass.getInputs().add(input); + delayClass.getOutputs().add(output); + delayClass.getParameters().add(delayParameter); + addDelayClass(delayClass); + return delayClass; + } + + /** + * Store the given reactor in the collection of generated delay classes and insert it in the AST + * under the top-level reactor's node. + */ + private void addDelayClass(Reactor generatedDelay) { + // Record this class, so it can be reused. + delayClasses.add(generatedDelay); + // And hook it into the AST. + EObject node = + IteratorExtensions.findFirst(mainResource.getAllContents(), Model.class::isInstance); + ((Model) node).getReactors().add(generatedDelay); + } + + /** + * Return the generated delay reactor that corresponds to the given class name if it had been + * created already, {@code null} otherwise. + */ + private Reactor findDelayClass(String className) { + return IterableExtensions.findFirst(delayClasses, it -> it.getName().equals(className)); + } } diff --git a/org.lflang/src/org/lflang/ast/FormattingUtils.java b/org.lflang/src/org/lflang/ast/FormattingUtils.java index 860e3d6bb2..9b47440391 100644 --- a/org.lflang/src/org/lflang/ast/FormattingUtils.java +++ b/org.lflang/src/org/lflang/ast/FormattingUtils.java @@ -8,264 +8,241 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.EObject; - import org.lflang.Target; import org.lflang.lf.Model; /** * Utility functions that determine the specific behavior of the LF formatter. + * * @author Peter Donovan * @author Billy Bao */ public class FormattingUtils { - /** - * The minimum number of columns that should be allotted to a comment. - * This is relevant in case of high indentation/small wrapLength. - */ - private static final int MINIMUM_COMMENT_WIDTH_IN_COLUMNS = 15; + /** + * The minimum number of columns that should be allotted to a comment. This is relevant in case of + * high indentation/small wrapLength. + */ + private static final int MINIMUM_COMMENT_WIDTH_IN_COLUMNS = 15; - /** Match a multiline comment. */ - private static final Pattern MULTILINE_COMMENT = Pattern.compile( - "\\s*/\\*\\v?(\\V*\\v+)*\\V*" - ); + /** Match a multiline comment. */ + private static final Pattern MULTILINE_COMMENT = Pattern.compile("\\s*/\\*\\v?(\\V*\\v+)*\\V*"); - /** The number of spaces to prepend to a line per indentation level. */ - private static final int INDENTATION = 4; + /** The number of spaces to prepend to a line per indentation level. */ + private static final int INDENTATION = 4; - public static final int DEFAULT_LINE_LENGTH = 80; + public static final int DEFAULT_LINE_LENGTH = 80; - static final int MAX_WHITESPACE_USED_FOR_ALIGNMENT = 20; + static final int MAX_WHITESPACE_USED_FOR_ALIGNMENT = 20; - static final long BADNESS_PER_CHARACTER_VIOLATING_LINE_LENGTH = 20; + static final long BADNESS_PER_CHARACTER_VIOLATING_LINE_LENGTH = 20; - static final long BADNESS_PER_LEVEL_OF_COMMENT_DISPLACEMENT = 1000; + static final long BADNESS_PER_LEVEL_OF_COMMENT_DISPLACEMENT = 1000; - static final long BADNESS_PER_NEWLINE = 1; + static final long BADNESS_PER_NEWLINE = 1; - /** - * Return a String representation of {@code object}, with lines wrapped at - * {@code lineLength}. - */ - public static String render(EObject object, int lineLength) { - return render(object, lineLength, inferTarget(object), false); - } + /** Return a String representation of {@code object}, with lines wrapped at {@code lineLength}. */ + public static String render(EObject object, int lineLength) { + return render(object, lineLength, inferTarget(object), false); + } - /** Return a function that renders AST nodes for the given target. */ - public static Function renderer(Target target) { - return object -> render(object, DEFAULT_LINE_LENGTH, target, true); - } + /** Return a function that renders AST nodes for the given target. */ + public static Function renderer(Target target) { + return object -> render(object, DEFAULT_LINE_LENGTH, target, true); + } - /** - * Return a String representation of {@code object}, with lines wrapped at - * {@code lineLength}, with the assumption that the target language is - * {@code target}. - */ - public static String render(EObject object, int lineLength, Target target, boolean codeMapTags) { - MalleableString ms = ToLf.instance.doSwitch(object); - String singleLineCommentPrefix = target.getSingleLineCommentPrefix(); - ms.findBestRepresentation( - () -> ms.render(INDENTATION, singleLineCommentPrefix, codeMapTags, null), - r -> r.levelsOfCommentDisplacement() * BADNESS_PER_LEVEL_OF_COMMENT_DISPLACEMENT + /** + * Return a String representation of {@code object}, with lines wrapped at {@code lineLength}, + * with the assumption that the target language is {@code target}. + */ + public static String render(EObject object, int lineLength, Target target, boolean codeMapTags) { + MalleableString ms = ToLf.instance.doSwitch(object); + String singleLineCommentPrefix = target.getSingleLineCommentPrefix(); + ms.findBestRepresentation( + () -> ms.render(INDENTATION, singleLineCommentPrefix, codeMapTags, null), + r -> + r.levelsOfCommentDisplacement() * BADNESS_PER_LEVEL_OF_COMMENT_DISPLACEMENT + countCharactersViolatingLineLength(lineLength).applyAsLong(r.rendering()) * BADNESS_PER_CHARACTER_VIOLATING_LINE_LENGTH + countNewlines(r.rendering()) * BADNESS_PER_NEWLINE, - lineLength, - INDENTATION, - singleLineCommentPrefix - ); - var optimizedRendering = ms.render(INDENTATION, singleLineCommentPrefix, codeMapTags, null); - List comments = optimizedRendering.unplacedComments().toList(); - return comments.stream().allMatch(String::isBlank) ? optimizedRendering.rendering() - : lineWrapComments(comments, lineLength, singleLineCommentPrefix) - + "\n" + optimizedRendering.rendering(); + lineLength, + INDENTATION, + singleLineCommentPrefix); + var optimizedRendering = ms.render(INDENTATION, singleLineCommentPrefix, codeMapTags, null); + List comments = optimizedRendering.unplacedComments().toList(); + return comments.stream().allMatch(String::isBlank) + ? optimizedRendering.rendering() + : lineWrapComments(comments, lineLength, singleLineCommentPrefix) + + "\n" + + optimizedRendering.rendering(); + } + + /** Infer the target language of the object. */ + private static Target inferTarget(EObject object) { + if (object instanceof Model model) { + var targetDecl = ASTUtils.targetDecl(model); + if (targetDecl != null) { + return Target.fromDecl(targetDecl); + } } - - /** - * Infer the target language of the object. - */ - private static Target inferTarget(EObject object) { - if (object instanceof Model model) { - var targetDecl = ASTUtils.targetDecl(model); - if (targetDecl != null) { - return Target.fromDecl(targetDecl); - } - } - throw new IllegalArgumentException("Unable to determine target based on given EObject."); - } - - /** - * Return a String representation of {@code object} using a reasonable - * default line length. - */ - public static String render(EObject object) { return render(object, DEFAULT_LINE_LENGTH); } - - /** - * Return the number of characters appearing in columns exceeding {@code lineLength}. - */ - private static ToLongFunction countCharactersViolatingLineLength(int lineLength) { - return s -> s.lines().mapToInt(it -> Math.max(0, it.length() - lineLength)).sum(); - } - - private static long countNewlines(String s) { - return s.lines().count(); - } - - /** - * Break lines at spaces so that each line is no more than {@code width} - * columns long, if possible. Normalize whitespace. Merge consecutive - * single-line comments. - */ - static String lineWrapComments( - List comments, - int width, - String singleLineCommentPrefix - ) { - StringBuilder ret = new StringBuilder(); - StringBuilder current = new StringBuilder(); - for (String comment : comments) { - if (comment.stripLeading().startsWith("/*")) { - if (!ret.isEmpty() && !current.isEmpty()) ret.append("\n"); - ret.append(lineWrapComment(current.toString(), width, singleLineCommentPrefix)); - current.setLength(0); - if (!ret.isEmpty()) ret.append("\n"); - ret.append(lineWrapComment(comment.strip(), width, singleLineCommentPrefix)); - } else { - if (!current.isEmpty()) current.append("\n"); - current.append(comment.strip()); - } - } + throw new IllegalArgumentException("Unable to determine target based on given EObject."); + } + + /** Return a String representation of {@code object} using a reasonable default line length. */ + public static String render(EObject object) { + return render(object, DEFAULT_LINE_LENGTH); + } + + /** Return the number of characters appearing in columns exceeding {@code lineLength}. */ + private static ToLongFunction countCharactersViolatingLineLength(int lineLength) { + return s -> s.lines().mapToInt(it -> Math.max(0, it.length() - lineLength)).sum(); + } + + private static long countNewlines(String s) { + return s.lines().count(); + } + + /** + * Break lines at spaces so that each line is no more than {@code width} columns long, if + * possible. Normalize whitespace. Merge consecutive single-line comments. + */ + static String lineWrapComments(List comments, int width, String singleLineCommentPrefix) { + StringBuilder ret = new StringBuilder(); + StringBuilder current = new StringBuilder(); + for (String comment : comments) { + if (comment.stripLeading().startsWith("/*")) { if (!ret.isEmpty() && !current.isEmpty()) ret.append("\n"); ret.append(lineWrapComment(current.toString(), width, singleLineCommentPrefix)); - return ret.toString(); + current.setLength(0); + if (!ret.isEmpty()) ret.append("\n"); + ret.append(lineWrapComment(comment.strip(), width, singleLineCommentPrefix)); + } else { + if (!current.isEmpty()) current.append("\n"); + current.append(comment.strip()); + } } - /** Wrap lines. Do not merge lines that start with weird characters. */ - private static String lineWrapComment( - String comment, - int width, - String singleLineCommentPrefix - ) { - width = Math.max(width, MINIMUM_COMMENT_WIDTH_IN_COLUMNS); - List> paragraphs = Arrays.stream( - comment.strip() - .replaceAll("^/?((\\*|//|#)\\s*)+", "") - .replaceAll("\\s*\\*/$", "") - .replaceAll("(?<=(\\r\\n|\\r|\\n))\\h*(\\*|//|#)\\h*", "") - .split("(\n\\s*){2,}") - ).map(s -> Arrays.stream(s.split("(\\r\\n|\\r|\\n)\\h*(?=[@#$%^&*\\-+=:;<>/])"))) + if (!ret.isEmpty() && !current.isEmpty()) ret.append("\n"); + 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) { + width = Math.max(width, MINIMUM_COMMENT_WIDTH_IN_COLUMNS); + List> paragraphs = + Arrays.stream( + comment + .strip() + .replaceAll("^/?((\\*|//|#)\\s*)+", "") + .replaceAll("\\s*\\*/$", "") + .replaceAll("(?<=(\\r\\n|\\r|\\n))\\h*(\\*|//|#)\\h*", "") + .split("(\n\\s*){2,}")) + .map(s -> Arrays.stream(s.split("(\\r\\n|\\r|\\n)\\h*(?=[@#$%^&*\\-+=:;<>/])"))) .map(stream -> stream.map(s -> s.replaceAll("\\s+", " "))) .map(Stream::toList) .toList(); - if (MULTILINE_COMMENT.matcher(comment).matches()) { - if (paragraphs.size() == 1 && paragraphs.get(0).size() == 1) { - String singleLineRepresentation = String.format( - "/** %s */", paragraphs.get(0).get(0) - ); - if (singleLineRepresentation.length() <= width) return singleLineRepresentation; - } - return String.format("/**\n%s\n */", lineWrapComment(paragraphs, width, " * ")); - } - return lineWrapComment(paragraphs, width, singleLineCommentPrefix + " "); - } - - /** - * Wrap lines. - * @param paragraphs A list of lists of subparagraphs. - * @param width The preferred maximum number of columns per line. - * @param linePrefix A string to prepend to each line of comment. - */ - private static String lineWrapComment( - List> paragraphs, - int width, - String linePrefix - ) { - int widthAfterPrefix = Math.max( - width - linePrefix.length(), - MINIMUM_COMMENT_WIDTH_IN_COLUMNS - ); - return paragraphs.stream() - .map(paragraph -> wrapLines(paragraph, widthAfterPrefix) - .map(s -> (linePrefix + s.stripLeading()).stripTrailing()) - .collect(Collectors.joining("\n")) - ).collect(Collectors.joining(String.format("\n%s\n", linePrefix.stripTrailing()))); + if (MULTILINE_COMMENT.matcher(comment).matches()) { + if (paragraphs.size() == 1 && paragraphs.get(0).size() == 1) { + String singleLineRepresentation = String.format("/** %s */", paragraphs.get(0).get(0)); + if (singleLineRepresentation.length() <= width) return singleLineRepresentation; + } + return String.format("/**\n%s\n */", lineWrapComment(paragraphs, width, " * ")); } - - /** Wrap a given paragraph. */ - private static Stream wrapLines(List subparagraphs, int width) { - var ret = new ArrayList(); - for (String s : subparagraphs) { - int numCharactersProcessed = 0; - while (numCharactersProcessed + width < s.length()) { - // try to wrap at space - int breakAt = s.lastIndexOf(' ', numCharactersProcessed + width); - // if unable to find space in limit, extend to the first space we find - if (breakAt < numCharactersProcessed) { - breakAt = s.indexOf(' ', numCharactersProcessed + width); - } - if (breakAt < numCharactersProcessed) breakAt = s.length(); - ret.add(s.substring(numCharactersProcessed, breakAt)); - numCharactersProcessed = breakAt + 1; - } - if (numCharactersProcessed < s.length()) ret.add(s.substring(numCharactersProcessed)); + return lineWrapComment(paragraphs, width, singleLineCommentPrefix + " "); + } + + /** + * Wrap lines. + * + * @param paragraphs A list of lists of subparagraphs. + * @param width The preferred maximum number of columns per line. + * @param linePrefix A string to prepend to each line of comment. + */ + private static String lineWrapComment( + List> paragraphs, int width, String linePrefix) { + int widthAfterPrefix = Math.max(width - linePrefix.length(), MINIMUM_COMMENT_WIDTH_IN_COLUMNS); + return paragraphs.stream() + .map( + paragraph -> + wrapLines(paragraph, widthAfterPrefix) + .map(s -> (linePrefix + s.stripLeading()).stripTrailing()) + .collect(Collectors.joining("\n"))) + .collect(Collectors.joining(String.format("\n%s\n", linePrefix.stripTrailing()))); + } + + /** Wrap a given paragraph. */ + private static Stream wrapLines(List subparagraphs, int width) { + var ret = new ArrayList(); + for (String s : subparagraphs) { + int numCharactersProcessed = 0; + while (numCharactersProcessed + width < s.length()) { + // try to wrap at space + int breakAt = s.lastIndexOf(' ', numCharactersProcessed + width); + // if unable to find space in limit, extend to the first space we find + if (breakAt < numCharactersProcessed) { + breakAt = s.indexOf(' ', numCharactersProcessed + width); } - return ret.stream(); + if (breakAt < numCharactersProcessed) breakAt = s.length(); + ret.add(s.substring(numCharactersProcessed, breakAt)); + numCharactersProcessed = breakAt + 1; + } + if (numCharactersProcessed < s.length()) ret.add(s.substring(numCharactersProcessed)); } - - /** - * Merge {@code comment} into the given list of strings without changing the - * length of the list, preferably in a place that indicates that - * {@code comment} is associated with the {@code i}th string. - * @param comment A comment associated with an element of - * {@code components}. - * @param components A list of strings that will be rendered in sequence. - * @param i The position of the component associated with {@code comment}. - * @param width The ideal number of columns available for comments that - * appear on their own line. - * @param keepCommentsOnSameLine Whether to make a best-effort attempt to - * keep the comment on the same line as the associated string. - * @param singleLineCommentPrefix The prefix that marks the start of a - * single-line comment. - * @param startColumn The ideal starting column of a comment - * @return Whether the comment placement succeeded. - */ - static boolean placeComment( - List comment, - List components, - int i, - int width, - boolean keepCommentsOnSameLine, - String singleLineCommentPrefix, - int startColumn - ) { - if (comment.stream().allMatch(String::isBlank)) return true; - String wrapped = FormattingUtils.lineWrapComments(comment, width, singleLineCommentPrefix); - if (keepCommentsOnSameLine && wrapped.lines().count() == 1 && !wrapped.startsWith("/**")) { - int sum = 0; - for (int j = 0; j < components.size(); j++) { - String current = components.get(j); - if (j >= i && current.contains("\n")) { - components.set(j, components.get(j).replaceFirst( - "\n", - " ".repeat(Math.max( - 2, - startColumn - sum - components.get(j).indexOf("\n") - )) + wrapped + "\n" - )); - return true; - } else if (current.contains("\n")) { - sum = current.length() - current.lastIndexOf("\n") - 1; - } else { - sum += current.length(); - } - } + return ret.stream(); + } + + /** + * Merge {@code comment} into the given list of strings without changing the length of the list, + * preferably in a place that indicates that {@code comment} is associated with the {@code i}th + * string. + * + * @param comment A comment associated with an element of {@code components}. + * @param components A list of strings that will be rendered in sequence. + * @param i The position of the component associated with {@code comment}. + * @param width The ideal number of columns available for comments that appear on their own line. + * @param keepCommentsOnSameLine Whether to make a best-effort attempt to keep the comment on the + * same line as the associated string. + * @param singleLineCommentPrefix The prefix that marks the start of a single-line comment. + * @param startColumn The ideal starting column of a comment + * @return Whether the comment placement succeeded. + */ + static boolean placeComment( + List comment, + List components, + int i, + int width, + boolean keepCommentsOnSameLine, + String singleLineCommentPrefix, + int startColumn) { + if (comment.stream().allMatch(String::isBlank)) return true; + String wrapped = FormattingUtils.lineWrapComments(comment, width, singleLineCommentPrefix); + if (keepCommentsOnSameLine && wrapped.lines().count() == 1 && !wrapped.startsWith("/**")) { + int sum = 0; + for (int j = 0; j < components.size(); j++) { + String current = components.get(j); + if (j >= i && current.contains("\n")) { + components.set( + j, + components + .get(j) + .replaceFirst( + "\n", + " ".repeat(Math.max(2, startColumn - sum - components.get(j).indexOf("\n"))) + + wrapped + + "\n")); + return true; + } else if (current.contains("\n")) { + sum = current.length() - current.lastIndexOf("\n") - 1; + } else { + sum += current.length(); } - for (int j = i - 1; j >= 0; j--) { - if (components.get(j).endsWith("\n")) { - components.set(j, String.format("%s%s\n", components.get(j), wrapped)); - return true; - } - } - return false; + } + } + for (int j = i - 1; j >= 0; j--) { + if (components.get(j).endsWith("\n")) { + components.set(j, String.format("%s%s\n", components.get(j), wrapped)); + return true; + } } + return false; + } } diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index af0274ea2a..bc0fc31abf 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -6,9 +6,7 @@ import java.util.function.BiPredicate; import java.util.function.Function; import java.util.stream.Collectors; - import org.eclipse.emf.ecore.EObject; - import org.lflang.TimeUnit; import org.lflang.lf.Action; import org.lflang.lf.Array; @@ -66,620 +64,603 @@ import org.lflang.lf.util.LfSwitch; /** - * Switch class that checks if subtrees of the AST are semantically equivalent - * to each other. Return {@code false} if they are not equivalent; return - * {@code true} or {@code false} (but preferably {@code true}) if they are - * equivalent. + * Switch class that checks if subtrees of the AST are semantically equivalent to each other. Return + * {@code false} if they are not equivalent; return {@code true} or {@code false} (but preferably + * {@code true}) if they are equivalent. */ public class IsEqual extends LfSwitch { - private final EObject otherObject; - - public IsEqual(EObject other) { - this.otherObject = other; - } - - @Override - public Boolean doSwitch(EObject eObject) { - if (otherObject == eObject) return true; - if (eObject == null) return false; - return super.doSwitch(eObject); - } - - @Override - public Boolean caseModel(Model object) { - return new ComparisonMachine<>(object, Model.class) - .equivalent(Model::getTarget) - .listsEquivalent(Model::getImports) - .listsEquivalent(Model::getPreambles) - .listsEquivalent(Model::getReactors).conclusion; - } - - @Override - public Boolean caseImport(Import object) { - return new ComparisonMachine<>(object, Import.class) - .equalAsObjects(Import::getImportURI) - .listsEquivalent(Import::getReactorClasses).conclusion; - } - - @Override - public Boolean caseReactorDecl(ReactorDecl object) { - return new ComparisonMachine<>(object, ReactorDecl.class) - .equalAsObjects(ReactorDecl::getName) - .conclusion; - } - - @Override - public Boolean caseImportedReactor(ImportedReactor object) { - return new ComparisonMachine<>(object, ImportedReactor.class) - .equalAsObjects(ImportedReactor::getName) - .equivalent(ImportedReactor::getReactorClass) - .conclusion; - } - - @Override - public Boolean caseReactor(Reactor object) { - return new ComparisonMachine<>(object, Reactor.class) - .listsEquivalent(Reactor::getAttributes) - .equalAsObjects(Reactor::isFederated) - .equalAsObjects(Reactor::isRealtime) - .equalAsObjects(Reactor::isMain) - .equalAsObjects(Reactor::getName) - .listsEquivalent(Reactor::getTypeParms) - .listsEquivalent(Reactor::getParameters) - .equivalent(Reactor::getHost) - .listsEquivalent(Reactor::getSuperClasses) - .listsEquivalent(Reactor::getPreambles) - .listsEquivalent(Reactor::getInputs) - .listsEquivalent(Reactor::getOutputs) - .listsEquivalent(Reactor::getTimers) - .listsEquivalent(Reactor::getActions) - .listsEquivalent(Reactor::getInstantiations) - .listsEquivalent(Reactor::getConnections) - .listsEquivalent(Reactor::getStateVars) - .listsEquivalent(Reactor::getReactions) - .listsEquivalent(Reactor::getMethods) - .listsEquivalent(Reactor::getModes) - .conclusion; - } - - @Override - public Boolean caseTypeParm(TypeParm object) { - return new ComparisonMachine<>(object, TypeParm.class) - .equalAsObjects(TypeParm::getLiteral) - .equivalent(TypeParm::getCode) - .conclusion; - } - - @Override - public Boolean caseTargetDecl(TargetDecl object) { - return new ComparisonMachine<>(object, TargetDecl.class) - .equalAsObjects(TargetDecl::getName) - .equivalentModulo( - TargetDecl::getConfig, - (KeyValuePairs it) -> it != null && it.getPairs().isEmpty() ? null : it - ) - .conclusion; - } - - @Override - public Boolean caseStateVar(StateVar object) { - return new ComparisonMachine<>(object, StateVar.class) - .listsEquivalent(StateVar::getAttributes) - .equalAsObjects(StateVar::getName) - .equivalent(StateVar::getType) - .equivalent(StateVar::getInit) - .conclusion; - } - - @Override - public Boolean caseInitializer(Initializer object) { - // Empty braces are not equivalent to no init. - return new ComparisonMachine<>(object, Initializer.class) - .equalAsObjects(Initializer::isBraces) - // An initializer with no parens is equivalent to one with parens, - // if the list has a single element. This is probably going to change - // when we introduce equals initializers. - // .equalAsObjects(Initializer::isParens) - .listsEquivalent(Initializer::getExprs) - .conclusion; - } - - @Override - public Boolean caseMethod(Method object) { - return new ComparisonMachine<>(object, Method.class) - .equalAsObjects(Method::isConst) - .equalAsObjects(Method::getName) - .listsEquivalent(Method::getArguments) - .equivalent(Method::getReturn) - .equivalent(Method::getCode) - .conclusion; - } - - @Override - public Boolean caseMethodArgument(MethodArgument object) { - return new ComparisonMachine<>(object, MethodArgument.class) - .equalAsObjects(MethodArgument::getName) - .equivalent(MethodArgument::getType) - .conclusion; - } - - @Override - public Boolean caseInput(Input object) { - return new ComparisonMachine<>(object, Input.class) - .listsEquivalent(Input::getAttributes) - .equalAsObjects(Input::isMutable) - .equivalent(Input::getWidthSpec) - .equivalent(Input::getType) - .conclusion; - } - - @Override - public Boolean caseOutput(Output object) { - return new ComparisonMachine<>(object, Output.class) - .listsEquivalent(Output::getAttributes) - .equivalent(Output::getWidthSpec) - .equalAsObjects(Output::getName) - .equivalent(Output::getType) - .conclusion; - } - - @Override - public Boolean caseTimer(Timer object) { - return new ComparisonMachine<>(object, Timer.class) - .listsEquivalent(Timer::getAttributes) - .equalAsObjects(Timer::getName) - .equivalent(Timer::getOffset) - .equivalent(Timer::getPeriod) - .conclusion; - } - - @Override - public Boolean caseMode(Mode object) { - return new ComparisonMachine<>(object, Mode.class) - .equalAsObjects(Mode::isInitial) - .equalAsObjects(Mode::getName) - .listsEquivalent(Mode::getStateVars) - .listsEquivalent(Mode::getTimers) - .listsEquivalent(Mode::getActions) - .listsEquivalent(Mode::getInstantiations) - .listsEquivalent(Mode::getConnections) - .listsEquivalent(Mode::getReactions) - .conclusion; - } - - @Override - public Boolean caseAction(Action object) { - return new ComparisonMachine<>(object, Action.class) - .listsEquivalent(Action::getAttributes) - .equalAsObjects(Action::getOrigin) // This is an enum - .equalAsObjects(Action::getName) - .equivalent(Action::getMinDelay) - .equivalent(Action::getMinSpacing) - .equalAsObjects(Action::getPolicy) - .equivalent(Action::getType) - .conclusion; - } - - @Override - public Boolean caseAttribute(Attribute object) { - return new ComparisonMachine<>(object, Attribute.class) - .equalAsObjects(Attribute::getAttrName) - .listsEquivalent(Attribute::getAttrParms) - .conclusion; - } - - @Override - public Boolean caseAttrParm(AttrParm object) { - return new ComparisonMachine<>(object, AttrParm.class) - .equalAsObjects(AttrParm::getName) - .equalAsObjects(AttrParm::getValue) - .conclusion; - } - - @Override - public Boolean caseReaction(Reaction object) { - return new ComparisonMachine<>(object, Reaction.class) - .listsEquivalent(Reaction::getAttributes) - .listsEquivalent(Reaction::getTriggers) - .listsEquivalent(Reaction::getSources) - .listsEquivalent(Reaction::getEffects) - .equalAsObjects(Reaction::isMutation) - .equalAsObjects(Reaction::getName) - .equivalent(Reaction::getCode) - .equivalent(Reaction::getStp) - .equivalent(Reaction::getDeadline) - .conclusion; - } - - @Override - public Boolean caseTriggerRef(TriggerRef object) { - throw thereIsAMoreSpecificCase(TriggerRef.class, BuiltinTriggerRef.class, VarRef.class); - } - - @Override - public Boolean caseBuiltinTriggerRef(BuiltinTriggerRef object) { - return new ComparisonMachine<>(object, BuiltinTriggerRef.class) - .equalAsObjects(BuiltinTriggerRef::getType) // This is an enum - .conclusion; - } - - @Override - public Boolean caseDeadline(Deadline object) { - return new ComparisonMachine<>(object, Deadline.class) - .equivalent(Deadline::getDelay) - .equivalent(Deadline::getCode) - .conclusion; - } - - @Override - public Boolean caseSTP(STP object) { - return new ComparisonMachine<>(object, STP.class) - .equivalent(STP::getValue) - .equivalent(STP::getCode) - .conclusion; - } - - @Override - public Boolean casePreamble(Preamble object) { - return new ComparisonMachine<>(object, Preamble.class) - .equalAsObjects(Preamble::getVisibility) // This is an enum - .equivalent(Preamble::getCode) - .conclusion; - } - - @Override - public Boolean caseInstantiation(Instantiation object) { - return new ComparisonMachine<>(object, Instantiation.class) - .equalAsObjects(Instantiation::getName) - .equivalent(Instantiation::getWidthSpec) - .equivalent(Instantiation::getReactorClass) - .listsEquivalent(Instantiation::getTypeArgs) - .listsEquivalent(Instantiation::getParameters) - .equivalent(Instantiation::getHost) - .conclusion; - } - - @Override - public Boolean caseConnection(Connection object) { - return new ComparisonMachine<>(object, Connection.class) - .listsEquivalent(Connection::getLeftPorts) - .equalAsObjects(Connection::isIterated) - .equalAsObjects(Connection::isPhysical) - .listsEquivalent(Connection::getRightPorts) - .equivalent(Connection::getDelay) - .equivalent(Connection::getSerializer) - .conclusion; - } - - @Override - public Boolean caseSerializer(Serializer object) { - return new ComparisonMachine<>(object, Serializer.class) - .equalAsObjects(Serializer::getType) - .conclusion; - } - - @Override - public Boolean caseKeyValuePairs(KeyValuePairs object) { - return new ComparisonMachine<>(object, KeyValuePairs.class) - .listsEquivalent(KeyValuePairs::getPairs) - .conclusion; - } - - @Override - public Boolean caseKeyValuePair(KeyValuePair object) { - return new ComparisonMachine<>(object, KeyValuePair.class) - .equalAsObjects(KeyValuePair::getName) - .equivalent(KeyValuePair::getValue) - .conclusion; - } - - @Override - public Boolean caseArray(Array object) { - return new ComparisonMachine<>(object, Array.class) - .listsEquivalent(Array::getElements) - .conclusion; - } - - @Override - public Boolean caseElement(Element object) { - return new ComparisonMachine<>(object, Element.class) - .equivalent(Element::getKeyvalue) - .equivalent(Element::getArray) - .equalAsObjects(Element::getLiteral) - .equalAsObjects(Element::getId) - .equalAsObjects(Element::getUnit) - .conclusion; - } - - @Override - public Boolean caseTypedVariable(TypedVariable object) { - throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); - } - - @Override - public Boolean caseVariable(Variable object) { - throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class); - } - - @Override - public Boolean caseVarRef(VarRef object) { - return new ComparisonMachine<>(object, VarRef.class) - .equalAsObjects(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable().getName()) - .equivalent(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable()) - .equalAsObjects(varRef -> varRef.getContainer() == null ? null : varRef.getContainer().getName()) - .equalAsObjects(VarRef::isInterleaved) - .equalAsObjects(VarRef::getTransition) - .conclusion; - } - - @Override - public Boolean caseAssignment(Assignment object) { - return new ComparisonMachine<>(object, Assignment.class) - .equivalent(Assignment::getLhs) - .equivalent(Assignment::getRhs) - .conclusion; - } - - @Override - public Boolean caseParameter(Parameter object) { - return new ComparisonMachine<>(object, Parameter.class) - .listsEquivalent(Parameter::getAttributes) - .equalAsObjects(Parameter::getName) - .equivalent(Parameter::getType) - .equivalent(Parameter::getInit) - .conclusion; - } - - @Override - public Boolean caseExpression(Expression object) { - throw thereIsAMoreSpecificCase( - Expression.class, - Literal.class, - Time.class, - ParameterReference.class, - Code.class, - BracedListExpression.class - ); - } - - @Override - public Boolean caseBracedListExpression(BracedListExpression object) { - return new ComparisonMachine<>(object, BracedListExpression.class) - .listsEquivalent(BracedListExpression::getItems) - .conclusion; - } - - @Override - public Boolean caseParameterReference(ParameterReference object) { - return new ComparisonMachine<>(object, ParameterReference.class) - .equivalent(ParameterReference::getParameter) - .conclusion; - } - - @Override - public Boolean caseTime(Time object) { - return new ComparisonMachine<>(object, Time.class) - .equalAsObjects(Time::getInterval) - .equalAsObjectsModulo( - Time::getUnit, - ((Function) TimeUnit::getCanonicalName) - .compose(TimeUnit::fromName) - ) - .conclusion; - } - - @Override - public Boolean casePort(Port object) { - throw thereIsAMoreSpecificCase(Port.class, Input.class, Output.class); - } - - @Override - public Boolean caseType(Type object) { - return new ComparisonMachine<>(object, Type.class) - .equivalent(Type::getCode) - .equalAsObjects(Type::isTime) - .equivalent(Type::getArraySpec) - .equalAsObjects(Type::getId) - .listsEquivalent(Type::getTypeArgs) - .listsEqualAsObjects(Type::getStars) - .equivalent(Type::getArraySpec) - .equivalent(Type::getCode) - .conclusion; - } - - @Override - public Boolean caseArraySpec(ArraySpec object) { - return new ComparisonMachine<>(object, ArraySpec.class) - .equalAsObjects(ArraySpec::isOfVariableLength) - .equalAsObjects(ArraySpec::getLength) - .conclusion; - } - - @Override - public Boolean caseWatchdog(Watchdog object) { - return new ComparisonMachine<>(object, Watchdog.class) - .equalAsObjects(Watchdog::getName) - .equivalent(Watchdog::getTimeout) - .listsEquivalent(Watchdog::getEffects) - .equivalent(Watchdog::getCode) - .conclusion; - } - - @Override - public Boolean caseWidthSpec(WidthSpec object) { - return new ComparisonMachine<>(object, WidthSpec.class) - .equalAsObjects(WidthSpec::isOfVariableLength) - .listsEquivalent(WidthSpec::getTerms) - .conclusion; - } - - @Override - public Boolean caseWidthTerm(WidthTerm object) { - return new ComparisonMachine<>(object, WidthTerm.class) - .equalAsObjects(WidthTerm::getWidth) - .equivalent(WidthTerm::getParameter) - .equivalent(WidthTerm::getPort) - .equivalent(WidthTerm::getCode) - .conclusion; - } - - @Override - public Boolean caseIPV4Host(IPV4Host object) { - return caseHost(object); - } - - @Override - public Boolean caseIPV6Host(IPV6Host object) { - return caseHost(object); - } - - @Override - public Boolean caseNamedHost(NamedHost object) { - return caseHost(object); - } - - @Override - public Boolean caseHost(Host object) { - return new ComparisonMachine<>(object, Host.class) - .equalAsObjects(Host::getUser) - .equalAsObjects(Host::getAddr) - .equalAsObjects(Host::getPort) - .conclusion; - } - - @Override - public Boolean caseCodeExpr(CodeExpr object) { - return new ComparisonMachine<>(object, CodeExpr.class).equivalent(CodeExpr::getCode).conclusion; - } - - @Override - public Boolean caseCode(Code object) { - return new ComparisonMachine<>(object, Code.class) - .equalAsObjectsModulo( - Code::getBody, - s -> s == null ? null : s.strip().stripIndent() - ) - .conclusion; - } - - @Override - public Boolean caseLiteral(Literal object) { - return new ComparisonMachine<>(object, Literal.class) - .equalAsObjects(Literal::getLiteral) - .conclusion; - } - - @Override - public Boolean defaultCase(EObject object) { - return super.defaultCase(object); - } - - @SafeVarargs - private UnsupportedOperationException thereIsAMoreSpecificCase( - Class thisCase, - Class... moreSpecificCases - ) { - return new UnsupportedOperationException(String.format( + private final EObject otherObject; + + public IsEqual(EObject other) { + this.otherObject = other; + } + + @Override + public Boolean doSwitch(EObject eObject) { + if (otherObject == eObject) return true; + if (eObject == null) return false; + return super.doSwitch(eObject); + } + + @Override + public Boolean caseModel(Model object) { + return new ComparisonMachine<>(object, Model.class) + .equivalent(Model::getTarget) + .listsEquivalent(Model::getImports) + .listsEquivalent(Model::getPreambles) + .listsEquivalent(Model::getReactors) + .conclusion; + } + + @Override + public Boolean caseImport(Import object) { + return new ComparisonMachine<>(object, Import.class) + .equalAsObjects(Import::getImportURI) + .listsEquivalent(Import::getReactorClasses) + .conclusion; + } + + @Override + public Boolean caseReactorDecl(ReactorDecl object) { + return new ComparisonMachine<>(object, ReactorDecl.class) + .equalAsObjects(ReactorDecl::getName) + .conclusion; + } + + @Override + public Boolean caseImportedReactor(ImportedReactor object) { + return new ComparisonMachine<>(object, ImportedReactor.class) + .equalAsObjects(ImportedReactor::getName) + .equivalent(ImportedReactor::getReactorClass) + .conclusion; + } + + @Override + public Boolean caseReactor(Reactor object) { + return new ComparisonMachine<>(object, Reactor.class) + .listsEquivalent(Reactor::getAttributes) + .equalAsObjects(Reactor::isFederated) + .equalAsObjects(Reactor::isRealtime) + .equalAsObjects(Reactor::isMain) + .equalAsObjects(Reactor::getName) + .listsEquivalent(Reactor::getTypeParms) + .listsEquivalent(Reactor::getParameters) + .equivalent(Reactor::getHost) + .listsEquivalent(Reactor::getSuperClasses) + .listsEquivalent(Reactor::getPreambles) + .listsEquivalent(Reactor::getInputs) + .listsEquivalent(Reactor::getOutputs) + .listsEquivalent(Reactor::getTimers) + .listsEquivalent(Reactor::getActions) + .listsEquivalent(Reactor::getInstantiations) + .listsEquivalent(Reactor::getConnections) + .listsEquivalent(Reactor::getStateVars) + .listsEquivalent(Reactor::getReactions) + .listsEquivalent(Reactor::getMethods) + .listsEquivalent(Reactor::getModes) + .conclusion; + } + + @Override + public Boolean caseTypeParm(TypeParm object) { + return new ComparisonMachine<>(object, TypeParm.class) + .equalAsObjects(TypeParm::getLiteral) + .equivalent(TypeParm::getCode) + .conclusion; + } + + @Override + public Boolean caseTargetDecl(TargetDecl object) { + return new ComparisonMachine<>(object, TargetDecl.class) + .equalAsObjects(TargetDecl::getName) + .equivalentModulo( + TargetDecl::getConfig, + (KeyValuePairs it) -> it != null && it.getPairs().isEmpty() ? null : it) + .conclusion; + } + + @Override + public Boolean caseStateVar(StateVar object) { + return new ComparisonMachine<>(object, StateVar.class) + .listsEquivalent(StateVar::getAttributes) + .equalAsObjects(StateVar::getName) + .equivalent(StateVar::getType) + .equivalent(StateVar::getInit) + .conclusion; + } + + @Override + public Boolean caseInitializer(Initializer object) { + // Empty braces are not equivalent to no init. + return new ComparisonMachine<>(object, Initializer.class) + .equalAsObjects(Initializer::isBraces) + // An initializer with no parens is equivalent to one with parens, + // if the list has a single element. This is probably going to change + // when we introduce equals initializers. + // .equalAsObjects(Initializer::isParens) + .listsEquivalent(Initializer::getExprs) + .conclusion; + } + + @Override + public Boolean caseMethod(Method object) { + return new ComparisonMachine<>(object, Method.class) + .equalAsObjects(Method::isConst) + .equalAsObjects(Method::getName) + .listsEquivalent(Method::getArguments) + .equivalent(Method::getReturn) + .equivalent(Method::getCode) + .conclusion; + } + + @Override + public Boolean caseMethodArgument(MethodArgument object) { + return new ComparisonMachine<>(object, MethodArgument.class) + .equalAsObjects(MethodArgument::getName) + .equivalent(MethodArgument::getType) + .conclusion; + } + + @Override + public Boolean caseInput(Input object) { + return new ComparisonMachine<>(object, Input.class) + .listsEquivalent(Input::getAttributes) + .equalAsObjects(Input::isMutable) + .equivalent(Input::getWidthSpec) + .equivalent(Input::getType) + .conclusion; + } + + @Override + public Boolean caseOutput(Output object) { + return new ComparisonMachine<>(object, Output.class) + .listsEquivalent(Output::getAttributes) + .equivalent(Output::getWidthSpec) + .equalAsObjects(Output::getName) + .equivalent(Output::getType) + .conclusion; + } + + @Override + public Boolean caseTimer(Timer object) { + return new ComparisonMachine<>(object, Timer.class) + .listsEquivalent(Timer::getAttributes) + .equalAsObjects(Timer::getName) + .equivalent(Timer::getOffset) + .equivalent(Timer::getPeriod) + .conclusion; + } + + @Override + public Boolean caseMode(Mode object) { + return new ComparisonMachine<>(object, Mode.class) + .equalAsObjects(Mode::isInitial) + .equalAsObjects(Mode::getName) + .listsEquivalent(Mode::getStateVars) + .listsEquivalent(Mode::getTimers) + .listsEquivalent(Mode::getActions) + .listsEquivalent(Mode::getInstantiations) + .listsEquivalent(Mode::getConnections) + .listsEquivalent(Mode::getReactions) + .conclusion; + } + + @Override + public Boolean caseAction(Action object) { + return new ComparisonMachine<>(object, Action.class) + .listsEquivalent(Action::getAttributes) + .equalAsObjects(Action::getOrigin) // This is an enum + .equalAsObjects(Action::getName) + .equivalent(Action::getMinDelay) + .equivalent(Action::getMinSpacing) + .equalAsObjects(Action::getPolicy) + .equivalent(Action::getType) + .conclusion; + } + + @Override + public Boolean caseAttribute(Attribute object) { + return new ComparisonMachine<>(object, Attribute.class) + .equalAsObjects(Attribute::getAttrName) + .listsEquivalent(Attribute::getAttrParms) + .conclusion; + } + + @Override + public Boolean caseAttrParm(AttrParm object) { + return new ComparisonMachine<>(object, AttrParm.class) + .equalAsObjects(AttrParm::getName) + .equalAsObjects(AttrParm::getValue) + .conclusion; + } + + @Override + public Boolean caseReaction(Reaction object) { + return new ComparisonMachine<>(object, Reaction.class) + .listsEquivalent(Reaction::getAttributes) + .listsEquivalent(Reaction::getTriggers) + .listsEquivalent(Reaction::getSources) + .listsEquivalent(Reaction::getEffects) + .equalAsObjects(Reaction::isMutation) + .equalAsObjects(Reaction::getName) + .equivalent(Reaction::getCode) + .equivalent(Reaction::getStp) + .equivalent(Reaction::getDeadline) + .conclusion; + } + + @Override + public Boolean caseTriggerRef(TriggerRef object) { + throw thereIsAMoreSpecificCase(TriggerRef.class, BuiltinTriggerRef.class, VarRef.class); + } + + @Override + public Boolean caseBuiltinTriggerRef(BuiltinTriggerRef object) { + return new ComparisonMachine<>(object, BuiltinTriggerRef.class) + .equalAsObjects(BuiltinTriggerRef::getType) // This is an enum + .conclusion; + } + + @Override + public Boolean caseDeadline(Deadline object) { + return new ComparisonMachine<>(object, Deadline.class) + .equivalent(Deadline::getDelay) + .equivalent(Deadline::getCode) + .conclusion; + } + + @Override + public Boolean caseSTP(STP object) { + return new ComparisonMachine<>(object, STP.class) + .equivalent(STP::getValue) + .equivalent(STP::getCode) + .conclusion; + } + + @Override + public Boolean casePreamble(Preamble object) { + return new ComparisonMachine<>(object, Preamble.class) + .equalAsObjects(Preamble::getVisibility) // This is an enum + .equivalent(Preamble::getCode) + .conclusion; + } + + @Override + public Boolean caseInstantiation(Instantiation object) { + return new ComparisonMachine<>(object, Instantiation.class) + .equalAsObjects(Instantiation::getName) + .equivalent(Instantiation::getWidthSpec) + .equivalent(Instantiation::getReactorClass) + .listsEquivalent(Instantiation::getTypeArgs) + .listsEquivalent(Instantiation::getParameters) + .equivalent(Instantiation::getHost) + .conclusion; + } + + @Override + public Boolean caseConnection(Connection object) { + return new ComparisonMachine<>(object, Connection.class) + .listsEquivalent(Connection::getLeftPorts) + .equalAsObjects(Connection::isIterated) + .equalAsObjects(Connection::isPhysical) + .listsEquivalent(Connection::getRightPorts) + .equivalent(Connection::getDelay) + .equivalent(Connection::getSerializer) + .conclusion; + } + + @Override + public Boolean caseSerializer(Serializer object) { + return new ComparisonMachine<>(object, Serializer.class) + .equalAsObjects(Serializer::getType) + .conclusion; + } + + @Override + public Boolean caseKeyValuePairs(KeyValuePairs object) { + return new ComparisonMachine<>(object, KeyValuePairs.class) + .listsEquivalent(KeyValuePairs::getPairs) + .conclusion; + } + + @Override + public Boolean caseKeyValuePair(KeyValuePair object) { + return new ComparisonMachine<>(object, KeyValuePair.class) + .equalAsObjects(KeyValuePair::getName) + .equivalent(KeyValuePair::getValue) + .conclusion; + } + + @Override + public Boolean caseArray(Array object) { + return new ComparisonMachine<>(object, Array.class) + .listsEquivalent(Array::getElements) + .conclusion; + } + + @Override + public Boolean caseElement(Element object) { + return new ComparisonMachine<>(object, Element.class) + .equivalent(Element::getKeyvalue) + .equivalent(Element::getArray) + .equalAsObjects(Element::getLiteral) + .equalAsObjects(Element::getId) + .equalAsObjects(Element::getUnit) + .conclusion; + } + + @Override + public Boolean caseTypedVariable(TypedVariable object) { + throw thereIsAMoreSpecificCase(TypedVariable.class, Port.class, Action.class); + } + + @Override + public Boolean caseVariable(Variable object) { + throw thereIsAMoreSpecificCase(Variable.class, TypedVariable.class, Timer.class, Mode.class); + } + + @Override + public Boolean caseVarRef(VarRef object) { + return new ComparisonMachine<>(object, VarRef.class) + .equalAsObjects( + varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable().getName()) + .equivalent(varRef -> varRef.getVariable() instanceof Mode ? null : varRef.getVariable()) + .equalAsObjects( + varRef -> varRef.getContainer() == null ? null : varRef.getContainer().getName()) + .equalAsObjects(VarRef::isInterleaved) + .equalAsObjects(VarRef::getTransition) + .conclusion; + } + + @Override + public Boolean caseAssignment(Assignment object) { + return new ComparisonMachine<>(object, Assignment.class) + .equivalent(Assignment::getLhs) + .equivalent(Assignment::getRhs) + .conclusion; + } + + @Override + public Boolean caseParameter(Parameter object) { + return new ComparisonMachine<>(object, Parameter.class) + .listsEquivalent(Parameter::getAttributes) + .equalAsObjects(Parameter::getName) + .equivalent(Parameter::getType) + .equivalent(Parameter::getInit) + .conclusion; + } + + @Override + public Boolean caseExpression(Expression object) { + throw thereIsAMoreSpecificCase( + Expression.class, + Literal.class, + Time.class, + ParameterReference.class, + Code.class, + BracedListExpression.class); + } + + @Override + public Boolean caseBracedListExpression(BracedListExpression object) { + return new ComparisonMachine<>(object, BracedListExpression.class) + .listsEquivalent(BracedListExpression::getItems) + .conclusion; + } + + @Override + public Boolean caseParameterReference(ParameterReference object) { + return new ComparisonMachine<>(object, ParameterReference.class) + .equivalent(ParameterReference::getParameter) + .conclusion; + } + + @Override + public Boolean caseTime(Time object) { + return new ComparisonMachine<>(object, Time.class) + .equalAsObjects(Time::getInterval) + .equalAsObjectsModulo( + Time::getUnit, + ((Function) TimeUnit::getCanonicalName).compose(TimeUnit::fromName)) + .conclusion; + } + + @Override + public Boolean casePort(Port object) { + throw thereIsAMoreSpecificCase(Port.class, Input.class, Output.class); + } + + @Override + public Boolean caseType(Type object) { + return new ComparisonMachine<>(object, Type.class) + .equivalent(Type::getCode) + .equalAsObjects(Type::isTime) + .equivalent(Type::getArraySpec) + .equalAsObjects(Type::getId) + .listsEquivalent(Type::getTypeArgs) + .listsEqualAsObjects(Type::getStars) + .equivalent(Type::getArraySpec) + .equivalent(Type::getCode) + .conclusion; + } + + @Override + public Boolean caseArraySpec(ArraySpec object) { + return new ComparisonMachine<>(object, ArraySpec.class) + .equalAsObjects(ArraySpec::isOfVariableLength) + .equalAsObjects(ArraySpec::getLength) + .conclusion; + } + + @Override + public Boolean caseWatchdog(Watchdog object) { + return new ComparisonMachine<>(object, Watchdog.class) + .equalAsObjects(Watchdog::getName) + .equivalent(Watchdog::getTimeout) + .listsEquivalent(Watchdog::getEffects) + .equivalent(Watchdog::getCode) + .conclusion; + } + + @Override + public Boolean caseWidthSpec(WidthSpec object) { + return new ComparisonMachine<>(object, WidthSpec.class) + .equalAsObjects(WidthSpec::isOfVariableLength) + .listsEquivalent(WidthSpec::getTerms) + .conclusion; + } + + @Override + public Boolean caseWidthTerm(WidthTerm object) { + return new ComparisonMachine<>(object, WidthTerm.class) + .equalAsObjects(WidthTerm::getWidth) + .equivalent(WidthTerm::getParameter) + .equivalent(WidthTerm::getPort) + .equivalent(WidthTerm::getCode) + .conclusion; + } + + @Override + public Boolean caseIPV4Host(IPV4Host object) { + return caseHost(object); + } + + @Override + public Boolean caseIPV6Host(IPV6Host object) { + return caseHost(object); + } + + @Override + public Boolean caseNamedHost(NamedHost object) { + return caseHost(object); + } + + @Override + public Boolean caseHost(Host object) { + return new ComparisonMachine<>(object, Host.class) + .equalAsObjects(Host::getUser) + .equalAsObjects(Host::getAddr) + .equalAsObjects(Host::getPort) + .conclusion; + } + + @Override + public Boolean caseCodeExpr(CodeExpr object) { + return new ComparisonMachine<>(object, CodeExpr.class).equivalent(CodeExpr::getCode).conclusion; + } + + @Override + public Boolean caseCode(Code object) { + return new ComparisonMachine<>(object, Code.class) + .equalAsObjectsModulo(Code::getBody, s -> s == null ? null : s.strip().stripIndent()) + .conclusion; + } + + @Override + public Boolean caseLiteral(Literal object) { + return new ComparisonMachine<>(object, Literal.class) + .equalAsObjects(Literal::getLiteral) + .conclusion; + } + + @Override + public Boolean defaultCase(EObject object) { + return super.defaultCase(object); + } + + @SafeVarargs + private UnsupportedOperationException thereIsAMoreSpecificCase( + Class thisCase, Class... moreSpecificCases) { + return new UnsupportedOperationException( + String.format( "%ss are %s, so the methods " + "corresponding to those types should be invoked instead.", thisCase.getName(), Arrays.stream(moreSpecificCases) - .map(Class::getName) - .map(it -> it + (it.endsWith("s") ? "es" : "s")) - .collect(Collectors.joining(" or ")) - )); - } - - /** Fluently compare a pair of parse tree nodes for equivalence. */ - private class ComparisonMachine { - private final E object; - private final E other; - private boolean conclusion; - - ComparisonMachine(E object, Class clz) { - this.object = object; - this.conclusion = clz.isInstance(otherObject); - this.other = conclusion ? clz.cast(otherObject) : null; - } - - /** - * Conclude false if the two given Lists are different as EObject - * sequences. Order matters. - */ - ComparisonMachine listsEquivalent(Function> listGetter) { - if (conclusion) conclusion = listsEqualish(listGetter, (T a, T b) -> new IsEqual(a).doSwitch(b)); - return this; - } - - /** - * Conclude false if the two given Lists are different as object - * sequences. Order matters. - */ - ComparisonMachine listsEqualAsObjects(Function> listGetter) { - if (conclusion) conclusion = listsEqualish(listGetter, Objects::equals); - return this; - } - - boolean listsEqualish(Function> listGetter, BiPredicate equalish) { - if (!conclusion) return false; - List list0 = listGetter.apply(object); - List list1 = listGetter.apply(other); - if (list0 == list1) return true; // e.g., they are both null - if (list0.size() != list1.size()) return false; - for (int i = 0; i < list0.size(); i++) { - if (!equalish.test(list0.get(i), list1.get(i))) { - return false; - } - } - return true; - } - - /** Conclude false if the two properties are not equal as objects. */ - ComparisonMachine equalAsObjects(Function propertyGetter) { - return equalAsObjectsModulo(propertyGetter, Function.identity()); - } - - /** - * Conclude false if the two properties are not equal as objects, - * given that {@code projectionToClassRepresentatives} maps each - * object to some semantically equivalent object. - */ - ComparisonMachine equalAsObjectsModulo( - Function propertyGetter, - Function projectionToClassRepresentatives - ) { - if (propertyGetter.apply(object) instanceof EObject) { - throw new IllegalArgumentException( - "EObjects should be compared for semantic equivalence, not object equality." - ); - } - propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); - if (conclusion) conclusion = Objects.equals(propertyGetter.apply(object), propertyGetter.apply(other)); - return this; - } - - /** - * Conclude false if the two properties are not semantically equivalent - * parse nodes. - */ - ComparisonMachine equivalent(Function propertyGetter) { - return equivalentModulo(propertyGetter, Function.identity()); - } - - /** - * Conclude false if the two properties are not semantically equivalent - * parse nodes, given that {@code projectionToClassRepresentatives} - * maps each parse node to some semantically equivalent node. - */ - ComparisonMachine equivalentModulo( - Function propertyGetter, - Function projectionToClassRepresentatives - ) { - propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); - if (conclusion) conclusion = new IsEqual(propertyGetter.apply(object)) - .doSwitch(propertyGetter.apply(other)); - return this; + .map(Class::getName) + .map(it -> it + (it.endsWith("s") ? "es" : "s")) + .collect(Collectors.joining(" or ")))); + } + + /** Fluently compare a pair of parse tree nodes for equivalence. */ + private class ComparisonMachine { + private final E object; + private final E other; + private boolean conclusion; + + ComparisonMachine(E object, Class clz) { + this.object = object; + this.conclusion = clz.isInstance(otherObject); + this.other = conclusion ? clz.cast(otherObject) : null; + } + + /** Conclude false if the two given Lists are different as EObject sequences. Order matters. */ + ComparisonMachine listsEquivalent(Function> listGetter) { + if (conclusion) + conclusion = listsEqualish(listGetter, (T a, T b) -> new IsEqual(a).doSwitch(b)); + return this; + } + + /** Conclude false if the two given Lists are different as object sequences. Order matters. */ + ComparisonMachine listsEqualAsObjects(Function> listGetter) { + if (conclusion) conclusion = listsEqualish(listGetter, Objects::equals); + return this; + } + + boolean listsEqualish( + Function> listGetter, BiPredicate equalish) { + if (!conclusion) return false; + List list0 = listGetter.apply(object); + List list1 = listGetter.apply(other); + if (list0 == list1) return true; // e.g., they are both null + if (list0.size() != list1.size()) return false; + for (int i = 0; i < list0.size(); i++) { + if (!equalish.test(list0.get(i), list1.get(i))) { + return false; } - } + } + return true; + } + + /** Conclude false if the two properties are not equal as objects. */ + ComparisonMachine equalAsObjects(Function propertyGetter) { + return equalAsObjectsModulo(propertyGetter, Function.identity()); + } + + /** + * Conclude false if the two properties are not equal as objects, given that {@code + * projectionToClassRepresentatives} maps each object to some semantically equivalent object. + */ + ComparisonMachine equalAsObjectsModulo( + Function propertyGetter, Function projectionToClassRepresentatives) { + if (propertyGetter.apply(object) instanceof EObject) { + throw new IllegalArgumentException( + "EObjects should be compared for semantic equivalence, not object equality."); + } + propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); + if (conclusion) + conclusion = Objects.equals(propertyGetter.apply(object), propertyGetter.apply(other)); + return this; + } + + /** Conclude false if the two properties are not semantically equivalent parse nodes. */ + ComparisonMachine equivalent(Function propertyGetter) { + return equivalentModulo(propertyGetter, Function.identity()); + } + + /** + * Conclude false if the two properties are not semantically equivalent parse nodes, given that + * {@code projectionToClassRepresentatives} maps each parse node to some semantically equivalent + * node. + */ + ComparisonMachine equivalentModulo( + Function propertyGetter, Function projectionToClassRepresentatives) { + propertyGetter = projectionToClassRepresentatives.compose(propertyGetter); + if (conclusion) + conclusion = + new IsEqual(propertyGetter.apply(object)).doSwitch(propertyGetter.apply(other)); + return this; + } + } } diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 7ecf04684f..9505c57478 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -20,7 +20,6 @@ import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.xbase.lib.StringExtensions; - import org.lflang.Target; import org.lflang.ast.MalleableString.Builder; import org.lflang.ast.MalleableString.Joiner; @@ -219,11 +218,7 @@ public MalleableString caseCode(Code code) { .map(String::stripTrailing) .collect(Collectors.joining("\n")); MalleableString singleLineRepresentation = - new Builder() - .append("{= ") - .append(content.strip()) - .append(" =}") - .get(); + new Builder().append("{= ").append(content.strip()).append(" =}").get(); MalleableString multilineRepresentation = new Builder() .append(String.format("{=%n")) diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 4d02d4ed08..f1d47b7c69 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -4,7 +4,6 @@ import org.eclipse.xtext.nodemodel.ICompositeNode; import org.eclipse.xtext.nodemodel.ILeafNode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; - import org.lflang.lf.ArraySpec; import org.lflang.lf.BracedListExpression; import org.lflang.lf.Code; @@ -19,112 +18,115 @@ import org.lflang.lf.util.LfSwitch; import org.lflang.util.StringUtil; - /** - * Switch class for converting AST nodes to some textual representation that seems likely - * to be useful for as many code generators as possible. + * Switch class for converting AST nodes to some textual representation that seems likely to be + * useful for as many code generators as possible. */ public class ToText extends LfSwitch { - /// public instance initialized when loading the class - public static final ToText instance = new ToText(); - - // private constructor - private ToText() { super(); } - - @Override - public String caseArraySpec(ArraySpec spec) { - return ToLf.instance.doSwitch(spec).toString(); - } - - @Override - public String caseCodeExpr(CodeExpr object) { - return caseCode(object.getCode()); + /// public instance initialized when loading the class + public static final ToText instance = new ToText(); + + // private constructor + private ToText() { + super(); + } + + @Override + public String caseArraySpec(ArraySpec spec) { + return ToLf.instance.doSwitch(spec).toString(); + } + + @Override + public String caseCodeExpr(CodeExpr object) { + return caseCode(object.getCode()); + } + + @Override + public String caseCode(Code code) { + ICompositeNode node = NodeModelUtils.getNode(code); + if (node != null) { + StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1)); + for (ILeafNode leaf : node.getLeafNodes()) { + builder.append(leaf.getText()); + } + String str = builder.toString().trim(); + // Remove the code delimiters (and any surrounding comments). + // This assumes any comment before {= does not include {=. + int start = str.indexOf("{="); + int end = str.lastIndexOf("=}"); + if (start == -1 || end == -1) { + // Silent failure is needed here because toText is needed to create the intermediate + // representation, + // which the validator uses. + return str; + } + str = str.substring(start + 2, end); + if (str.split("\n").length > 1) { + // multi line code + return StringUtil.trimCodeBlock(str, 1); + } else { + // single line code + return str.trim(); + } + } else if (code.getBody() != null) { + // Code must have been added as a simple string. + return code.getBody(); } - - @Override - public String caseCode(Code code) { - ICompositeNode node = NodeModelUtils.getNode(code); - if (node != null) { - StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1)); - for (ILeafNode leaf : node.getLeafNodes()) { - builder.append(leaf.getText()); - } - String str = builder.toString().trim(); - // Remove the code delimiters (and any surrounding comments). - // This assumes any comment before {= does not include {=. - int start = str.indexOf("{="); - int end = str.lastIndexOf("=}"); - if (start == -1 || end == -1) { - // Silent failure is needed here because toText is needed to create the intermediate representation, - // which the validator uses. - return str; - } - str = str.substring(start + 2, end); - if (str.split("\n").length > 1) { - // multi line code - return StringUtil.trimCodeBlock(str, 1); - } else { - // single line code - return str.trim(); - } - } else if (code.getBody() != null) { - // Code must have been added as a simple string. - return code.getBody(); - } - return ""; - } - - @Override - public String caseBracedListExpression(BracedListExpression object) { - return ToLf.instance.caseBracedListExpression(object).toString(); + return ""; + } + + @Override + public String caseBracedListExpression(BracedListExpression object) { + return ToLf.instance.caseBracedListExpression(object).toString(); + } + + @Override + public String caseHost(Host host) { + return ToLf.instance.caseHost(host).toString(); + } + + @Override + public String caseLiteral(Literal l) { + return ToLf.instance.caseLiteral(l).toString(); + } + + @Override + public String caseParameterReference(ParameterReference p) { + return ToLf.instance.caseParameterReference(p).toString(); + } + + @Override + public String caseTime(Time t) { + return ToLf.instance.caseTime(t).toString(); + } + + @Override + public String caseType(Type type) { + if (type.getCode() != null) { + return caseCode(type.getCode()); } - - @Override - public String caseHost(Host host) { - return ToLf.instance.caseHost(host).toString(); - } - - @Override - public String caseLiteral(Literal l) { - return ToLf.instance.caseLiteral(l).toString(); + return ToLf.instance.caseType(type).toString(); + } + + @Override + public String caseTypeParm(TypeParm t) { + if (t.getCode() != null) return doSwitch(t.getCode()); + return ToLf.instance.caseTypeParm(t).toString(); + } + + @Override + public String caseVarRef(VarRef v) { + if (v.getContainer() != null) { + return String.format("%s.%s", v.getContainer().getName(), v.getVariable().getName()); + } else { + return v.getVariable().getName(); } + } - @Override - public String caseParameterReference(ParameterReference p) { - return ToLf.instance.caseParameterReference(p).toString(); - } - - @Override - public String caseTime(Time t) { - return ToLf.instance.caseTime(t).toString(); - } - - @Override - public String caseType(Type type) { - if (type.getCode() != null) { - return caseCode(type.getCode()); - } - return ToLf.instance.caseType(type).toString(); - } - - @Override - public String caseTypeParm(TypeParm t) { - if (t.getCode() != null) return doSwitch(t.getCode()); - return ToLf.instance.caseTypeParm(t).toString(); - } - - @Override - public String caseVarRef(VarRef v) { - if (v.getContainer() != null) { - return String.format("%s.%s", v.getContainer().getName(), v.getVariable().getName()); - } else { - return v.getVariable().getName(); - } - } - - @Override - public String defaultCase(EObject object) { - throw new UnsupportedOperationException("ToText has no case for " + object.getClass().getName()); - } + @Override + public String defaultCase(EObject object) { + throw new UnsupportedOperationException( + "ToText has no case for " + object.getClass().getName()); + } } diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index 2f4a9d849c..a6c1c805ed 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -1,26 +1,21 @@ package org.lflang.cli; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.google.inject.Provider; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map.Entry; -import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; - -import picocli.CommandLine; -import picocli.CommandLine.ArgGroup; -import picocli.CommandLine.Command; -import picocli.CommandLine.Model.CommandSpec; -import picocli.CommandLine.Option; -import picocli.CommandLine.Parameters; -import picocli.CommandLine.Spec; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -28,18 +23,16 @@ import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.eclipse.xtext.validation.Issue; - import org.lflang.ErrorReporter; import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; import org.lflang.util.FileUtil; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonParseException; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Provider; +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Model.CommandSpec; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; +import picocli.CommandLine.Spec; /** * Base class for standalone CLI applications. @@ -50,318 +43,277 @@ * @author Atharva Patil */ public abstract class CliBase implements Runnable { - /** - * Models a command specification, including the options, positional - * parameters and subcommands supported by the command. - */ - @Spec CommandSpec spec; - - /** - * Options and parameters present in both Lfc and Lff. - */ - static class MutuallyExclusive { - @Parameters( - arity = "1..", - paramLabel = "FILES", - description = "Paths to one or more Lingua Franca programs.") - protected List files; - - @Option( - names="--json", - description="JSON object containing CLI arguments.") - private String jsonString; - - @Option( - names="--json-file", - description="JSON file containing CLI arguments.") - private Path jsonFile; - } - - @ArgGroup(exclusive = true, multiplicity = "1") - MutuallyExclusive topLevelArg; - - @Option( - names = {"-o", "--output-path"}, - defaultValue = "", - fallbackValue = "", - description = "Specify the root output directory.") - private Path outputPath; - - /** - * Used to collect all errors that happen during validation/generation. - */ - @Inject - protected IssueCollector issueCollector; - - /** - * Used to report error messages at the end. - */ - @Inject - protected ReportingBackend reporter; - - /** - * Used to report error messages at the end. - */ - @Inject - protected ErrorReporter errorReporter; - - /** - * IO context of this run. - */ - @Inject - protected Io io; - - /** - * Injected resource provider. - */ - @Inject - private Provider resourceSetProvider; - - /** - * Injected resource validator. - */ - @Inject - private IResourceValidator validator; - - protected static void cliMain( - String toolName, Class toolClass, - Io io, String[] args) { - // Injector used to obtain Main instance. - final Injector injector = getInjector(toolName, io); - // Main instance. - final CliBase main = injector.getInstance(toolClass); - // Parse arguments and execute main logic. - main.doExecute(io, args); - } - - public void doExecute(Io io, String[] args) { - CommandLine cmd = new CommandLine(this) + /** + * Models a command specification, including the options, positional parameters and subcommands + * supported by the command. + */ + @Spec CommandSpec spec; + + /** Options and parameters present in both Lfc and Lff. */ + static class MutuallyExclusive { + @Parameters( + arity = "1..", + paramLabel = "FILES", + description = "Paths to one or more Lingua Franca programs.") + protected List files; + + @Option(names = "--json", description = "JSON object containing CLI arguments.") + private String jsonString; + + @Option(names = "--json-file", description = "JSON file containing CLI arguments.") + private Path jsonFile; + } + + @ArgGroup(exclusive = true, multiplicity = "1") + MutuallyExclusive topLevelArg; + + @Option( + names = {"-o", "--output-path"}, + defaultValue = "", + fallbackValue = "", + description = "Specify the root output directory.") + private Path outputPath; + + /** Used to collect all errors that happen during validation/generation. */ + @Inject protected IssueCollector issueCollector; + + /** Used to report error messages at the end. */ + @Inject protected ReportingBackend reporter; + + /** Used to report error messages at the end. */ + @Inject protected ErrorReporter errorReporter; + + /** IO context of this run. */ + @Inject protected Io io; + + /** Injected resource provider. */ + @Inject private Provider resourceSetProvider; + + /** Injected resource validator. */ + @Inject private IResourceValidator validator; + + protected static void cliMain( + String toolName, Class toolClass, Io io, String[] args) { + // Injector used to obtain Main instance. + final Injector injector = getInjector(toolName, io); + // Main instance. + final CliBase main = injector.getInstance(toolClass); + // Parse arguments and execute main logic. + main.doExecute(io, args); + } + + public void doExecute(Io io, String[] args) { + CommandLine cmd = + new CommandLine(this) .setOut(new PrintWriter(io.getOut())) .setErr(new PrintWriter(io.getErr())); - int exitCode = cmd.execute(args); - io.callSystemExit(exitCode); + int exitCode = cmd.execute(args); + io.callSystemExit(exitCode); + } + + /** + * The entrypoint of Picocli applications - the first method called when CliBase, which implements + * the Runnable interface, is instantiated. + */ + public void run() { + // If args are given in a json file, store its contents in jsonString. + if (topLevelArg.jsonFile != null) { + try { + topLevelArg.jsonString = + new String(Files.readAllBytes(io.getWd().resolve(topLevelArg.jsonFile))); + } catch (IOException e) { + reporter.printFatalErrorAndExit("No such file: " + topLevelArg.jsonFile); + } } - - /** - * The entrypoint of Picocli applications - the first method called when - * CliBase, which implements the Runnable interface, is instantiated. - */ - public void run() { - // If args are given in a json file, store its contents in jsonString. - if (topLevelArg.jsonFile != null) { - try { - topLevelArg.jsonString = new String(Files.readAllBytes( - io.getWd().resolve(topLevelArg.jsonFile))); - } catch (IOException e) { - reporter.printFatalErrorAndExit( - "No such file: " + topLevelArg.jsonFile); - } - } - // If args are given in a json string, unpack them and re-run - // picocli argument validation. - if (topLevelArg.jsonString != null) { - // Unpack args from json string. - String[] args = jsonStringToArgs(topLevelArg.jsonString); - // Execute application on unpacked args. - CommandLine cmd = spec.commandLine(); - cmd.execute(args); - // If args are already unpacked, invoke tool-specific logic. - } else { - doRun(); - } + // If args are given in a json string, unpack them and re-run + // picocli argument validation. + if (topLevelArg.jsonString != null) { + // Unpack args from json string. + String[] args = jsonStringToArgs(topLevelArg.jsonString); + // Execute application on unpacked args. + CommandLine cmd = spec.commandLine(); + cmd.execute(args); + // If args are already unpacked, invoke tool-specific logic. + } else { + doRun(); } - - /* - * The entrypoint of tool-specific logic. - * Lfc and Lff have their own specific implementations for this method. - */ - public abstract void doRun(); - - public static Injector getInjector(String toolName, Io io) { - final ReportingBackend reporter - = new ReportingBackend(io, toolName + ": "); - - // Injector used to obtain Main instance. - return new LFStandaloneSetup( - new LFRuntimeModule(), - new LFStandaloneModule(reporter, io) - ).createInjectorAndDoEMFRegistration(); + } + + /* + * The entrypoint of tool-specific logic. + * Lfc and Lff have their own specific implementations for this method. + */ + public abstract void doRun(); + + public static Injector getInjector(String toolName, Io io) { + final ReportingBackend reporter = new ReportingBackend(io, toolName + ": "); + + // Injector used to obtain Main instance. + return new LFStandaloneSetup(new LFRuntimeModule(), new LFStandaloneModule(reporter, io)) + .createInjectorAndDoEMFRegistration(); + } + + /** Resolve to an absolute path, in the given {@link #io} context. */ + protected Path toAbsolutePath(Path other) { + return io.getWd().resolve(other).toAbsolutePath(); + } + + /** + * Returns the validated input paths. + * + * @return Validated input paths. + */ + protected List getInputPaths() { + List paths = + topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); + + for (Path path : paths) { + if (!Files.exists(path)) { + reporter.printFatalErrorAndExit(path + ": No such file or directory."); + } } - /** - * Resolve to an absolute path, in the given {@link #io} context. - */ - protected Path toAbsolutePath(Path other) { - return io.getWd().resolve(other).toAbsolutePath(); + return paths; + } + + /** + * Returns the validated, normalized output path. + * + * @return Validated, normalized output path. + */ + protected Path getOutputRoot() { + Path root = null; + if (!outputPath.toString().isEmpty()) { + root = io.getWd().resolve(outputPath).normalize(); + if (!Files.exists(root)) { // FIXME: Create it instead? + reporter.printFatalErrorAndExit(root + ": Output location does not exist."); + } + if (!Files.isDirectory(root)) { + reporter.printFatalErrorAndExit(root + ": Output location is not a directory."); + } } - /** - * Returns the validated input paths. - * - * @return Validated input paths. - */ - protected List getInputPaths() { - List paths = topLevelArg.files.stream() - .map(io.getWd()::resolve) - .collect(Collectors.toList()); - - for (Path path : paths) { - if (!Files.exists(path)) { - reporter.printFatalErrorAndExit( - path + ": No such file or directory."); - } - } - - return paths; + return root; + } + + /** If some errors were collected, print them and abort execution. Otherwise, return. */ + protected void exitIfCollectedErrors() { + if (issueCollector.getErrorsOccurred()) { + // if there are errors, don't print warnings. + List errors = printErrorsIfAny(); + String cause = errors.size() + " previous error"; + if (errors.size() > 1) { + cause += 's'; + } + reporter.printFatalErrorAndExit("Aborting due to " + cause + '.'); } - - /** - * Returns the validated, normalized output path. - * - * @return Validated, normalized output path. - */ - protected Path getOutputRoot() { - Path root = null; - if (!outputPath.toString().isEmpty()) { - root = io.getWd().resolve(outputPath).normalize(); - if (!Files.exists(root)) { // FIXME: Create it instead? - reporter.printFatalErrorAndExit( - root + ": Output location does not exist."); - } - if (!Files.isDirectory(root)) { - reporter.printFatalErrorAndExit( - root + ": Output location is not a directory."); - } + } + + /** + * If any errors were collected, print them, then return them. + * + * @return A list of collected errors. + */ + public List printErrorsIfAny() { + List errors = issueCollector.getErrors(); + errors.forEach(reporter::printIssue); + return errors; + } + + /** + * Validates a given resource. If issues arise during validation, these are recorded using the + * issue collector. + * + * @param resource The resource to validate. + */ + public void validateResource(Resource resource) { + assert resource != null; + + List issues = this.validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); + + for (Issue issue : issues) { + // Issues may also relate to imported resources. + URI uri = issue.getUriToProblem(); + Path path = null; + if (uri != null) { + try { + path = FileUtil.toPath(uri); + } catch (IOException e) { + reporter.printError("Unable to convert '" + uri + "' to path." + e); } - - return root; + } + issueCollector.accept( + new LfIssue( + issue.getMessage(), + issue.getSeverity(), + issue.getLineNumber(), + issue.getColumn(), + issue.getLineNumberEnd(), + issue.getColumnEnd(), + issue.getLength(), + path)); } - - /** - * If some errors were collected, print them and abort execution. - * Otherwise, return. - */ - protected void exitIfCollectedErrors() { - if (issueCollector.getErrorsOccurred()) { - // if there are errors, don't print warnings. - List errors = printErrorsIfAny(); - String cause = errors.size() + " previous error"; - if (errors.size() > 1) { - cause += 's'; - } - reporter.printFatalErrorAndExit("Aborting due to " + cause + '.'); - } + } + + /** + * Obtains a resource from a path. Returns null if path is not an LF file. + * + * @param path The path to obtain the resource from. + * @return The obtained resource. Set to null if path is not an LF file. + */ + public Resource getResource(Path path) { + final ResourceSet set = this.resourceSetProvider.get(); + try { + return set.getResource(URI.createFileURI(path.toString()), true); + } catch (RuntimeException e) { + return null; } + } - /** - * If any errors were collected, print them, then return them. - * @return A list of collected errors. - */ - public List printErrorsIfAny() { - List errors = issueCollector.getErrors(); - errors.forEach(reporter::printIssue); - return errors; - } + private String[] jsonStringToArgs(String jsonString) { + ArrayList argsList = new ArrayList<>(); + JsonObject jsonObject = new JsonObject(); - /** - * Validates a given resource. If issues arise during validation, - * these are recorded using the issue collector. - * - * @param resource The resource to validate. - */ - public void validateResource(Resource resource) { - assert resource != null; - - List issues = this.validator.validate( - resource, CheckMode.ALL, CancelIndicator.NullImpl); - - for (Issue issue : issues) { - // Issues may also relate to imported resources. - URI uri = issue.getUriToProblem(); - Path path = null; - if (uri != null) { - try { - path = FileUtil.toPath(uri); - } catch (IOException e) { - reporter.printError("Unable to convert '" + uri + "' to path." + e); - } - } - issueCollector.accept( - new LfIssue( - issue.getMessage(), - issue.getSeverity(), - issue.getLineNumber(), - issue.getColumn(), - issue.getLineNumberEnd(), - issue.getColumnEnd(), - issue.getLength(), - path)); - } + // Parse JSON string and get top-level JSON object. + try { + jsonObject = JsonParser.parseString(jsonString).getAsJsonObject(); + } catch (JsonParseException e) { + reporter.printFatalErrorAndExit(String.format("Invalid JSON string:%n %s", jsonString)); } - - /** - * Obtains a resource from a path. Returns null if path is not an LF file. - * - * @param path The path to obtain the resource from. - * @return The obtained resource. Set to null if path is not an LF file. - */ - public Resource getResource(Path path) { - final ResourceSet set = this.resourceSetProvider.get(); - try { - return set.getResource(URI.createFileURI(path.toString()), true); - } catch (RuntimeException e) { - return null; - } + // Append input paths. + JsonElement src = jsonObject.get("src"); + if (src == null) { + reporter.printFatalErrorAndExit("JSON Parse Exception: field \"src\" not found."); + } + argsList.add(src.getAsString()); + // Append output path if given. + JsonElement out = jsonObject.get("out"); + if (out != null) { + argsList.add("--output-path"); + argsList.add(out.getAsString()); } - private String[] jsonStringToArgs(String jsonString) { - ArrayList argsList = new ArrayList<>(); - JsonObject jsonObject = new JsonObject(); - - // Parse JSON string and get top-level JSON object. - try { - jsonObject = JsonParser.parseString(jsonString).getAsJsonObject(); - } catch (JsonParseException e) { - reporter.printFatalErrorAndExit( - String.format("Invalid JSON string:%n %s", jsonString)); - } - // Append input paths. - JsonElement src = jsonObject.get("src"); - if (src == null) { - reporter.printFatalErrorAndExit( - "JSON Parse Exception: field \"src\" not found."); - } - argsList.add(src.getAsString()); - // Append output path if given. - JsonElement out = jsonObject.get("out"); - if (out != null) { - argsList.add("--output-path"); - argsList.add(out.getAsString()); - } - - // If there are no other properties, return args array. - JsonElement properties = jsonObject.get("properties"); - if (properties != null) { - // Get the remaining properties. - Set> entrySet = properties - .getAsJsonObject() - .entrySet(); - // Append the remaining properties to the args array. - for(Entry entry : entrySet) { - String property = entry.getKey(); - String value = entry.getValue().getAsString(); - - // Append option. - argsList.add("--" + property); - // Append argument for non-boolean options. - if (value != "true" || property == "threading") { - argsList.add(value); - } - } + // If there are no other properties, return args array. + JsonElement properties = jsonObject.get("properties"); + if (properties != null) { + // Get the remaining properties. + Set> entrySet = properties.getAsJsonObject().entrySet(); + // Append the remaining properties to the args array. + for (Entry entry : entrySet) { + String property = entry.getKey(); + String value = entry.getValue().getAsString(); + + // Append option. + argsList.add("--" + property); + // Append argument for non-boolean options. + if (value != "true" || property == "threading") { + argsList.add(value); } - - // Return as String[]. - String[] args = argsList.toArray(new String[argsList.size()]); - return args; + } } + + // Return as String[]. + String[] args = argsList.toArray(new String[argsList.size()]); + return args; + } } diff --git a/org.lflang/src/org/lflang/cli/LFStandaloneModule.java b/org.lflang/src/org/lflang/cli/LFStandaloneModule.java index 8b85e49282..abf01bfcd3 100644 --- a/org.lflang/src/org/lflang/cli/LFStandaloneModule.java +++ b/org.lflang/src/org/lflang/cli/LFStandaloneModule.java @@ -28,49 +28,45 @@ package org.lflang.cli; +import com.google.inject.Binder; +import com.google.inject.Module; import java.util.Objects; - import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.ecore.impl.EValidatorRegistryImpl; import org.eclipse.xtext.validation.ValidationMessageAcceptor; - import org.lflang.ErrorReporter; import org.lflang.LFRuntimeModule; -import com.google.inject.Binder; -import com.google.inject.Module; - /** - * Module that is only available when running LFC as a - * standalone program. + * Module that is only available when running LFC as a standalone program. * * @see LFRuntimeModule */ public class LFStandaloneModule implements Module { - // Note that xtext's base module classes has broken support - // for @Provides, which would allow us to bind this field. - // So we directly implement Module, instead of extending eg LFRuntimeModule. - private final ReportingBackend helper; - private final Io io; + // Note that xtext's base module classes has broken support + // for @Provides, which would allow us to bind this field. + // So we directly implement Module, instead of extending eg LFRuntimeModule. + private final ReportingBackend helper; + private final Io io; - public LFStandaloneModule(ReportingBackend helper, Io io) { - this.helper = Objects.requireNonNull(helper); - this.io = Objects.requireNonNull(io); - } + public LFStandaloneModule(ReportingBackend helper, Io io) { + this.helper = Objects.requireNonNull(helper); + this.io = Objects.requireNonNull(io); + } - @Override - public void configure(Binder binder) { - binder.bind(ErrorReporter.class).to(StandaloneErrorReporter.class); - binder.bind(ReportingBackend.class).toInstance(helper); - binder.bind(Io.class).toInstance(io); - binder.bind(ValidationMessageAcceptor.class).to(StandaloneIssueAcceptor.class); - // This is required to force the ResourceValidator to - // use a new registry instance (which is reused by the injector as a singleton). - // Otherwise, it uses the static EValidator.Registry.INSTANCE which is bad - // as the first validator to be created would persist in that static instance. - // New injectors would reuse the existing instance, but - // its fields would have been injected by an older injector - // and be out of sync with the rest of the application. - binder.bind(EValidator.Registry.class).to(EValidatorRegistryImpl.class).asEagerSingleton(); - } + @Override + public void configure(Binder binder) { + binder.bind(ErrorReporter.class).to(StandaloneErrorReporter.class); + binder.bind(ReportingBackend.class).toInstance(helper); + binder.bind(Io.class).toInstance(io); + binder.bind(ValidationMessageAcceptor.class).to(StandaloneIssueAcceptor.class); + // This is required to force the ResourceValidator to + // use a new registry instance (which is reused by the injector as a singleton). + // Otherwise, it uses the static EValidator.Registry.INSTANCE which is bad + // as the first validator to be created would persist in that static instance. + // New injectors would reuse the existing instance, but + // its fields would have been injected by an older injector + // and be out of sync with the rest of the application. + binder.bind(EValidator.Registry.class).to(EValidatorRegistryImpl.class).asEagerSingleton(); + } } diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index 3ef52e54a0..19869f9394 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -1,27 +1,22 @@ package org.lflang.cli; - +import com.google.inject.Inject; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Properties; - -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.GeneratorDelegate; import org.eclipse.xtext.generator.JavaIoFileSystemAccess; import org.eclipse.xtext.util.CancelIndicator; - -import org.lflang.ast.ASTUtils; import org.lflang.FileConfig; import org.lflang.TargetProperty.UnionType; - +import org.lflang.ast.ASTUtils; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFGeneratorContext.BuildParm; import org.lflang.generator.MainContext; - -import com.google.inject.Inject; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; /** * Standalone version of the Lingua Franca compiler (lfc). @@ -36,287 +31,261 @@ mixinStandardHelpOptions = true, versionProvider = VersionProvider.class) public class Lfc extends CliBase { - /** - * Injected code generator. - */ - @Inject - private GeneratorDelegate generator; - - /** - * Injected file access object. - */ - @Inject - private JavaIoFileSystemAccess fileAccess; - - /* - * Supported CLI options. - */ - - @Option( - names = "--build-type", - description = "The build type to use.") - private String buildType; - - @Option( - names = {"-c", "--clean"}, - arity = "0", - description = "Clean before building.") - private boolean clean; - - @Option( - names = "--target-compiler", - description = "Target compiler to invoke.") - private String targetCompiler; - - @Option( - names = "--external-runtime-path", - description = "Specify an external runtime library to be used by the" - + " compiled binary.") - private Path externalRuntimePath; - - @Option( - names = {"-f", "--federated"}, - arity = "0", - description = "Treat main reactor as federated.") - private boolean federated; - - @Option( - names = "--logging", - description = "The logging level to use by the generated binary") - private String logging; - - @Option( - names = {"-l", "--lint"}, - arity = "0", - description = "Enable linting of generated code.") - private boolean lint; - - @Option( - names = {"-n", "--no-compile"}, - arity = "0", - description = "Do not invoke target compiler.") - private boolean noCompile; - - @Option( - names = {"--print-statistics"}, - arity = "0", - description = "Instruct the runtime to collect and print statistics.") - private boolean printStatistics; - - @Option( - names = {"-q", "--quiet"}, - arity = "0", - description = - "Suppress output of the target compiler and other commands") - private boolean quiet; - - @Option( - names = {"-r", "--rti"}, - description = "Specify the location of the RTI.") - private Path rti; - - @Option( - names = "--runtime-version", - description = "Specify the version of the runtime library used for" - + " compiling LF programs.") - private String runtimeVersion; - - @Option( - names = {"-s", "--scheduler"}, - description = "Specify the runtime scheduler (if supported).") - private String scheduler; - - @Option( - names = {"-t", "--threading"}, - paramLabel = "", - description = "Specify whether the runtime should use multi-threading" - + " (true/false).") - private String threading; - - @Option( - names = {"-w", "--workers"}, - description = "Specify the default number of worker threads.") - private Integer workers; - - /** - * Main function of the stand-alone compiler. - * Caution: this will invoke System.exit. - * - * @param args CLI arguments - */ - public static void main(final String[] args) { - main(Io.SYSTEM, args); + /** Injected code generator. */ + @Inject private GeneratorDelegate generator; + + /** Injected file access object. */ + @Inject private JavaIoFileSystemAccess fileAccess; + + /* + * Supported CLI options. + */ + + @Option(names = "--build-type", description = "The build type to use.") + private String buildType; + + @Option( + names = {"-c", "--clean"}, + arity = "0", + description = "Clean before building.") + private boolean clean; + + @Option(names = "--target-compiler", description = "Target compiler to invoke.") + private String targetCompiler; + + @Option( + names = "--external-runtime-path", + description = "Specify an external runtime library to be used by the" + " compiled binary.") + private Path externalRuntimePath; + + @Option( + names = {"-f", "--federated"}, + arity = "0", + description = "Treat main reactor as federated.") + private boolean federated; + + @Option(names = "--logging", description = "The logging level to use by the generated binary") + private String logging; + + @Option( + names = {"-l", "--lint"}, + arity = "0", + description = "Enable linting of generated code.") + private boolean lint; + + @Option( + names = {"-n", "--no-compile"}, + arity = "0", + description = "Do not invoke target compiler.") + private boolean noCompile; + + @Option( + names = {"--print-statistics"}, + arity = "0", + description = "Instruct the runtime to collect and print statistics.") + private boolean printStatistics; + + @Option( + names = {"-q", "--quiet"}, + arity = "0", + description = "Suppress output of the target compiler and other commands") + private boolean quiet; + + @Option( + names = {"-r", "--rti"}, + description = "Specify the location of the RTI.") + private Path rti; + + @Option( + names = "--runtime-version", + description = + "Specify the version of the runtime library used for" + " compiling LF programs.") + private String runtimeVersion; + + @Option( + names = {"-s", "--scheduler"}, + description = "Specify the runtime scheduler (if supported).") + private String scheduler; + + @Option( + names = {"-t", "--threading"}, + paramLabel = "", + description = "Specify whether the runtime should use multi-threading" + " (true/false).") + private String threading; + + @Option( + names = {"-w", "--workers"}, + description = "Specify the default number of worker threads.") + private Integer workers; + + /** + * Main function of the stand-alone compiler. Caution: this will invoke System.exit. + * + * @param args CLI arguments + */ + public static void main(final String[] args) { + main(Io.SYSTEM, args); + } + + /** + * Main function of the standalone compiler, with a custom IO. + * + * @param io IO streams. + * @param args Command-line arguments. + */ + public static void main(Io io, final String... args) { + cliMain("lfc", Lfc.class, io, args); + } + + /** Load the resource, validate it, and, invoke the code generator. */ + @Override + public void doRun() { + List paths = getInputPaths(); + final Path outputRoot = getOutputRoot(); + // Hard code the props based on the options we want. + Properties properties = this.getGeneratorArgs(); + + try { + // Invoke the generator on all input file paths. + invokeGenerator(paths, outputRoot, properties); + } catch (RuntimeException e) { + reporter.printFatalErrorAndExit("An unexpected error occurred:", e); } - - /** - * Main function of the standalone compiler, with a custom IO. - * - * @param io IO streams. - * @param args Command-line arguments. - */ - public static void main(Io io, final String... args) { - cliMain("lfc", Lfc.class, io, args); - } - - /** - * Load the resource, validate it, and, invoke the code generator. - */ - @Override - public void doRun() { - List paths = getInputPaths(); - final Path outputRoot = getOutputRoot(); - // Hard code the props based on the options we want. - Properties properties = this.getGeneratorArgs(); - - try { - // Invoke the generator on all input file paths. - invokeGenerator(paths, outputRoot, properties); - } catch (RuntimeException e) { - reporter.printFatalErrorAndExit("An unexpected error occurred:", e); + } + + /** Invoke the code generator on the given validated file paths. */ + private void invokeGenerator(List files, Path root, Properties properties) { + for (Path path : files) { + path = toAbsolutePath(path); + String outputPath = getActualOutputPath(root, path).toString(); + this.fileAccess.setOutputPath(outputPath); + + final Resource resource = getResource(path); + if (resource == null) { + reporter.printFatalErrorAndExit( + path + " is not an LF file. Use the .lf file extension to" + " denote LF files."); + } else if (federated) { + if (!ASTUtils.makeFederated(resource)) { + reporter.printError("Unable to change main reactor to federated reactor."); } + } + + validateResource(resource); + exitIfCollectedErrors(); + + LFGeneratorContext context = + new MainContext( + LFGeneratorContext.Mode.STANDALONE, + CancelIndicator.NullImpl, + (m, p) -> {}, + properties, + resource, + this.fileAccess, + fileConfig -> errorReporter); + + try { + this.generator.generate(resource, this.fileAccess, context); + } catch (Exception e) { + reporter.printFatalErrorAndExit("Error running generator", e); + } + + exitIfCollectedErrors(); + // Print all other issues (not errors). + issueCollector.getAllIssues().forEach(reporter::printIssue); + + this.io.getOut().println("Code generation finished."); } - - /** - * Invoke the code generator on the given validated file paths. - */ - private void invokeGenerator( - List files, Path root, Properties properties) { - for (Path path : files) { - path = toAbsolutePath(path); - String outputPath = getActualOutputPath(root, path).toString(); - this.fileAccess.setOutputPath(outputPath); - - final Resource resource = getResource(path); - if (resource == null) { - reporter.printFatalErrorAndExit(path - + " is not an LF file. Use the .lf file extension to" - + " denote LF files."); - } else if (federated) { - if (!ASTUtils.makeFederated(resource)) { - reporter.printError( - "Unable to change main reactor to federated reactor."); - } - } - - validateResource(resource); - exitIfCollectedErrors(); - - LFGeneratorContext context = new MainContext( - LFGeneratorContext.Mode.STANDALONE, CancelIndicator.NullImpl, - (m, p) -> {}, properties, resource, this.fileAccess, - fileConfig -> errorReporter - ); - - try { - this.generator.generate(resource, this.fileAccess, context); - } catch (Exception e) { - reporter.printFatalErrorAndExit("Error running generator", e); - } - - exitIfCollectedErrors(); - // Print all other issues (not errors). - issueCollector.getAllIssues().forEach(reporter::printIssue); - - this.io.getOut().println("Code generation finished."); - } + } + + private Path getActualOutputPath(Path root, Path path) { + if (root != null) { + return root.resolve("src-gen"); + } else { + Path pkgRoot = FileConfig.findPackageRoot(path, reporter::printWarning); + return pkgRoot.resolve("src-gen"); } - - private Path getActualOutputPath(Path root, Path path) { - if (root != null) { - return root.resolve("src-gen"); - } else { - Path pkgRoot = FileConfig.findPackageRoot( - path, reporter::printWarning); - return pkgRoot.resolve("src-gen"); - } + } + + /** + * Filter the command-line arguments needed by the code generator, and return them as properties. + * + * @return Properties for the code generator. + */ + public Properties getGeneratorArgs() { + Properties props = new Properties(); + + if (buildType != null) { + // Validate build type. + if (UnionType.BUILD_TYPE_UNION.forName(buildType) == null) { + reporter.printFatalErrorAndExit(buildType + ": Invalid build type."); + } + props.setProperty(BuildParm.BUILD_TYPE.getKey(), buildType); } - /** - * Filter the command-line arguments needed by the code generator, and - * return them as properties. - * - * @return Properties for the code generator. - */ - public Properties getGeneratorArgs() { - Properties props = new Properties(); - - if (buildType != null) { - // Validate build type. - if (UnionType.BUILD_TYPE_UNION.forName(buildType) == null) { - reporter.printFatalErrorAndExit( - buildType + ": Invalid build type."); - } - props.setProperty(BuildParm.BUILD_TYPE.getKey(), buildType); - } - - if (clean) { - props.setProperty(BuildParm.CLEAN.getKey(), "true"); - } - - if (externalRuntimePath != null) { - props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), - externalRuntimePath.toString()); - } + if (clean) { + props.setProperty(BuildParm.CLEAN.getKey(), "true"); + } - if (lint) { - props.setProperty(BuildParm.LINT.getKey(), "true"); - } + if (externalRuntimePath != null) { + props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), externalRuntimePath.toString()); + } - if (logging != null) { - // Validate log level. - if (UnionType.LOGGING_UNION.forName(logging) == null) { - reporter.printFatalErrorAndExit( - logging + ": Invalid log level."); - } - props.setProperty(BuildParm.LOGGING.getKey(), logging); - } + if (lint) { + props.setProperty(BuildParm.LINT.getKey(), "true"); + } - if(printStatistics) { - props.setProperty(BuildParm.PRINT_STATISTICS.getKey(), "true"); - } + if (logging != null) { + // Validate log level. + if (UnionType.LOGGING_UNION.forName(logging) == null) { + reporter.printFatalErrorAndExit(logging + ": Invalid log level."); + } + props.setProperty(BuildParm.LOGGING.getKey(), logging); + } - if (noCompile) { - props.setProperty(BuildParm.NO_COMPILE.getKey(), "true"); - } + if (printStatistics) { + props.setProperty(BuildParm.PRINT_STATISTICS.getKey(), "true"); + } - if (targetCompiler != null) { - props.setProperty(BuildParm.TARGET_COMPILER.getKey(), targetCompiler); - } + if (noCompile) { + props.setProperty(BuildParm.NO_COMPILE.getKey(), "true"); + } - if (quiet) { - props.setProperty(BuildParm.QUIET.getKey(), "true"); - } + if (targetCompiler != null) { + props.setProperty(BuildParm.TARGET_COMPILER.getKey(), targetCompiler); + } - if (rti != null) { - // Validate RTI path. - if (!Files.exists(io.getWd().resolve(rti))) { - reporter.printFatalErrorAndExit( - rti + ": Invalid RTI path."); - } - props.setProperty(BuildParm.RTI.getKey(), rti.toString()); - } + if (quiet) { + props.setProperty(BuildParm.QUIET.getKey(), "true"); + } - if (runtimeVersion != null) { - props.setProperty(BuildParm.RUNTIME_VERSION.getKey(), runtimeVersion); - } + if (rti != null) { + // Validate RTI path. + if (!Files.exists(io.getWd().resolve(rti))) { + reporter.printFatalErrorAndExit(rti + ": Invalid RTI path."); + } + props.setProperty(BuildParm.RTI.getKey(), rti.toString()); + } - if (scheduler != null) { - // Validate scheduler. - if (UnionType.SCHEDULER_UNION.forName(scheduler) == null) { - reporter.printFatalErrorAndExit( - scheduler + ": Invalid scheduler."); - } - props.setProperty(BuildParm.SCHEDULER.getKey(), scheduler); - } + if (runtimeVersion != null) { + props.setProperty(BuildParm.RUNTIME_VERSION.getKey(), runtimeVersion); + } - if (threading != null) { - props.setProperty(BuildParm.THREADING.getKey(), threading); - } + if (scheduler != null) { + // Validate scheduler. + if (UnionType.SCHEDULER_UNION.forName(scheduler) == null) { + reporter.printFatalErrorAndExit(scheduler + ": Invalid scheduler."); + } + props.setProperty(BuildParm.SCHEDULER.getKey(), scheduler); + } - if (workers != null) { - props.setProperty(BuildParm.WORKERS.getKey(), workers.toString()); - } + if (threading != null) { + props.setProperty(BuildParm.THREADING.getKey(), threading); + } - return props; + if (workers != null) { + props.setProperty(BuildParm.WORKERS.getKey(), workers.toString()); } + + return props; + } } diff --git a/org.lflang/src/org/lflang/cli/Lff.java b/org.lflang/src/org/lflang/cli/Lff.java index 297bc5ad84..f4f7714119 100644 --- a/org.lflang/src/org/lflang/cli/Lff.java +++ b/org.lflang/src/org/lflang/cli/Lff.java @@ -8,13 +8,11 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.List; - -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; import org.eclipse.emf.ecore.resource.Resource; - import org.lflang.ast.FormattingUtils; import org.lflang.util.FileUtil; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; /** * Standalone version of the Lingua Franca formatter (lff). Based on lfc. @@ -31,169 +29,163 @@ versionProvider = VersionProvider.class) public class Lff extends CliBase { - /** - * Supported CLI options for Lff. - */ - @Option( - names = {"-d", "--dry-run"}, - description = "Send the formatted file contents to stdout" - + " without writing to the file system.") - private boolean dryRun = false; - - @Option( - names = {"-w", "--wrap"}, - description = "Causes the formatter to line wrap the files to a" - + " specified length.", - defaultValue = "" + FormattingUtils.DEFAULT_LINE_LENGTH, - fallbackValue = "" + FormattingUtils.DEFAULT_LINE_LENGTH) - private int lineLength; - - @Option( - names = "--no-recurse", - description = "Do not format files in subdirectories of the" - + " specified paths.") - private boolean noRecurse = false; - - @Option( - names = {"-v", "--verbose"}, - description = "Print more details on files affected.") - private boolean verbose = false; - - @Option( - names = {"--ignore-errors"}, - description = "Ignore validation errors in files and format them anyway.") - private boolean ignoreErrors = false; - - /** - * Main function of the formatter. - * Caution: this will invoke System.exit. - * - * @param args CLI arguments - */ - public static void main(String[] args) { - main(Io.SYSTEM, args); + /** Supported CLI options for Lff. */ + @Option( + names = {"-d", "--dry-run"}, + description = + "Send the formatted file contents to stdout" + " without writing to the file system.") + private boolean dryRun = false; + + @Option( + names = {"-w", "--wrap"}, + description = "Causes the formatter to line wrap the files to a" + " specified length.", + defaultValue = "" + FormattingUtils.DEFAULT_LINE_LENGTH, + fallbackValue = "" + FormattingUtils.DEFAULT_LINE_LENGTH) + private int lineLength; + + @Option( + names = "--no-recurse", + description = "Do not format files in subdirectories of the" + " specified paths.") + private boolean noRecurse = false; + + @Option( + names = {"-v", "--verbose"}, + description = "Print more details on files affected.") + private boolean verbose = false; + + @Option( + names = {"--ignore-errors"}, + description = "Ignore validation errors in files and format them anyway.") + private boolean ignoreErrors = false; + + /** + * Main function of the formatter. Caution: this will invoke System.exit. + * + * @param args CLI arguments + */ + public static void main(String[] args) { + main(Io.SYSTEM, args); + } + + /** + * Programmatic entry point, with a custom IO. + * + * @param io IO streams. + * @param args Command-line arguments. + */ + public static void main(Io io, final String... args) { + cliMain("lff", Lff.class, io, args); + } + + /** Validates all paths and invokes the formatter on the input paths. */ + @Override + public void doRun() { + List paths = getInputPaths(); + final Path outputRoot = getOutputRoot(); + + try { + // Format all files defined by the list of paths. + formatAllFiles(paths, outputRoot); + + exitIfCollectedErrors(); + if (!dryRun || verbose) { + reporter.printInfo("Done formatting."); + } + } catch (RuntimeException e) { + reporter.printFatalErrorAndExit("An unexpected error occurred:", e); } - - /** - * Programmatic entry point, with a custom IO. - * - * @param io IO streams. - * @param args Command-line arguments. - */ - public static void main(Io io, final String... args) { - cliMain("lff", Lff.class, io, args); - } - - /** - * Validates all paths and invokes the formatter on the input paths. - */ - @Override - public void doRun() { - List paths = getInputPaths(); - final Path outputRoot = getOutputRoot(); - + } + + /* + * Invokes the formatter on all files defined by the list of paths. + */ + private void formatAllFiles(List paths, Path outputRoot) { + for (Path relativePath : paths) { + if (verbose) { + reporter.printInfo("Formatting " + io.getWd().relativize(relativePath) + ":"); + } + + Path path = toAbsolutePath(relativePath); + if (Files.isDirectory(path) && !noRecurse) { + // Walk the contents of this directory. try { - // Format all files defined by the list of paths. - formatAllFiles(paths, outputRoot); - - exitIfCollectedErrors(); - if (!dryRun || verbose) { - reporter.printInfo("Done formatting."); - } - } catch (RuntimeException e) { - reporter.printFatalErrorAndExit("An unexpected error occurred:", e); - } - } - - /* - * Invokes the formatter on all files defined by the list of paths. - */ - private void formatAllFiles(List paths, Path outputRoot) { - for (Path relativePath : paths) { - if (verbose) { - reporter.printInfo("Formatting " - + io.getWd().relativize(relativePath) + ":"); - } - - Path path = toAbsolutePath(relativePath); - if (Files.isDirectory(path) && !noRecurse) { - // Walk the contents of this directory. - try { - Files.walkFileTree(path, new SimpleFileVisitor<>() { - @Override - public FileVisitResult visitFile( - Path file, BasicFileAttributes attrs) { - formatSingleFile(file, path, outputRoot); - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException e) { - reporter.printError("IO error: " + e); + Files.walkFileTree( + path, + new SimpleFileVisitor<>() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + formatSingleFile(file, path, outputRoot); + return FileVisitResult.CONTINUE; } - } else { - // Simple file. - formatSingleFile(path, path.getParent(), outputRoot); - } + }); + } catch (IOException e) { + reporter.printError("IO error: " + e); } + } else { + // Simple file. + formatSingleFile(path, path.getParent(), outputRoot); + } } - - /* - * Invokes the formatter on a single file defined by the given path. - */ - private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { - path = path.normalize(); - Path outputPath = outputRoot == null + } + + /* + * Invokes the formatter on a single file defined by the given path. + */ + private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { + path = path.normalize(); + Path outputPath = + outputRoot == null ? path // Format in place. : outputRoot.resolve(inputRoot.relativize(path)).normalize(); - final Resource resource = getResource(path); - // Skip file if not an LF file. - if (resource == null) { - if (verbose) { - reporter.printInfo("Skipped " + path + ": not an LF file"); - } - return; - } - validateResource(resource); + final Resource resource = getResource(path); + // Skip file if not an LF file. + if (resource == null) { + if (verbose) { + reporter.printInfo("Skipped " + path + ": not an LF file"); + } + return; + } + validateResource(resource); - if (!ignoreErrors) { - exitIfCollectedErrors(); - } - final String formattedFileContents = - FormattingUtils.render(resource.getContents().get(0), lineLength); - - if (dryRun) { - io.getOut().print(formattedFileContents); - } else { - try { - FileUtil.writeToFile(formattedFileContents, outputPath, true); - } catch (IOException e) { - if (e instanceof FileAlreadyExistsException) { - // Only happens if a subdirectory is named with - // ".lf" at the end. - reporter.printFatalErrorAndExit( - "Error writing to " - + outputPath - + ": file already exists. Make sure that no file or" - + " directory within provided input paths have the" - + " same relative paths."); - } - } + if (!ignoreErrors) { + exitIfCollectedErrors(); + } + final String formattedFileContents = + FormattingUtils.render(resource.getContents().get(0), lineLength); + + if (dryRun) { + io.getOut().print(formattedFileContents); + } else { + try { + FileUtil.writeToFile(formattedFileContents, outputPath, true); + } catch (IOException e) { + if (e instanceof FileAlreadyExistsException) { + // Only happens if a subdirectory is named with + // ".lf" at the end. + reporter.printFatalErrorAndExit( + "Error writing to " + + outputPath + + ": file already exists. Make sure that no file or" + + " directory within provided input paths have the" + + " same relative paths."); } + } + } - if (!ignoreErrors) { - exitIfCollectedErrors(); - } - // Only errors are printed. Warnings are not helpful for LFF - // and since they don't prevent the file from being formatted, - // the position of the issue may be wrong in the formatted file. - // issueCollector.getAllIssues().forEach(reporter::printIssue); - if (verbose) { - String msg = "Formatted " + io.getWd().relativize(path); - if (path != outputPath) { - msg += " -> " + io.getWd().relativize(outputPath); - } - reporter.printInfo(msg); - } + if (!ignoreErrors) { + exitIfCollectedErrors(); + } + // Only errors are printed. Warnings are not helpful for LFF + // and since they don't prevent the file from being formatted, + // the position of the issue may be wrong in the formatted file. + // issueCollector.getAllIssues().forEach(reporter::printIssue); + if (verbose) { + String msg = "Formatted " + io.getWd().relativize(path); + if (path != outputPath) { + msg += " -> " + io.getWd().relativize(outputPath); + } + reporter.printInfo(msg); } + } } diff --git a/org.lflang/src/org/lflang/cli/StandaloneErrorReporter.java b/org.lflang/src/org/lflang/cli/StandaloneErrorReporter.java index 2b4ae6fe46..83e58eb15c 100644 --- a/org.lflang/src/org/lflang/cli/StandaloneErrorReporter.java +++ b/org.lflang/src/org/lflang/cli/StandaloneErrorReporter.java @@ -27,90 +27,79 @@ package org.lflang.cli; +import com.google.inject.Inject; import java.nio.file.Path; - import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.diagnostics.Severity; - import org.lflang.ErrorReporter; -import com.google.inject.Inject; - /** - * An error reporter that forwards all messages to an {@link IssueCollector}. - * They'll be sorted out later. + * An error reporter that forwards all messages to an {@link IssueCollector}. They'll be sorted out + * later. */ public class StandaloneErrorReporter implements ErrorReporter { - @Inject - private StandaloneIssueAcceptor issueAcceptor; - - private String reportWithNode(String message, Severity severity, EObject obj) { - issueAcceptor.accept(severity, message, obj, null, 0, null); - return message; - } - - private String reportSimpleFileCtx(String message, Severity severity, Integer line, Path path) { - LfIssue issue = new LfIssue(message, severity, line, 1, line, 1, 0, path); - issueAcceptor.accept(issue); - // Return a string that can be inserted into the generated code. - return message; - } - - - @Override - public String reportError(String message) { - return reportSimpleFileCtx(message, Severity.ERROR, null, null); - } - - - @Override - public String reportWarning(String message) { - return reportSimpleFileCtx(message, Severity.WARNING, null, null); - } - - @Override - public String reportInfo(String message) { - return reportSimpleFileCtx(message, Severity.INFO, null, null); - } - - - @Override - public String reportError(EObject obj, String message) { - return reportWithNode(message, Severity.ERROR, obj); - } - - - @Override - public String reportWarning(EObject obj, String message) { - return reportWithNode(message, Severity.WARNING, obj); - } - - @Override - public String reportInfo(EObject obj, String message) { - return reportWithNode(message, Severity.INFO, obj); - } - - - @Override - public String reportError(Path file, Integer line, String message) { - return reportSimpleFileCtx(message, Severity.ERROR, line, file); - } - - - @Override - public String reportWarning(Path file, Integer line, String message) { - return reportSimpleFileCtx(message, Severity.WARNING, line, file); - } - - @Override - public String reportInfo(Path file, Integer line, String message) { - return reportSimpleFileCtx(message, Severity.INFO, line, file); - } - - - @Override - public boolean getErrorsOccurred() { - return issueAcceptor.getErrorsOccurred(); - } + @Inject private StandaloneIssueAcceptor issueAcceptor; + + private String reportWithNode(String message, Severity severity, EObject obj) { + issueAcceptor.accept(severity, message, obj, null, 0, null); + return message; + } + + private String reportSimpleFileCtx(String message, Severity severity, Integer line, Path path) { + LfIssue issue = new LfIssue(message, severity, line, 1, line, 1, 0, path); + issueAcceptor.accept(issue); + // Return a string that can be inserted into the generated code. + return message; + } + + @Override + public String reportError(String message) { + return reportSimpleFileCtx(message, Severity.ERROR, null, null); + } + + @Override + public String reportWarning(String message) { + return reportSimpleFileCtx(message, Severity.WARNING, null, null); + } + + @Override + public String reportInfo(String message) { + return reportSimpleFileCtx(message, Severity.INFO, null, null); + } + + @Override + public String reportError(EObject obj, String message) { + return reportWithNode(message, Severity.ERROR, obj); + } + + @Override + public String reportWarning(EObject obj, String message) { + return reportWithNode(message, Severity.WARNING, obj); + } + + @Override + public String reportInfo(EObject obj, String message) { + return reportWithNode(message, Severity.INFO, obj); + } + + @Override + public String reportError(Path file, Integer line, String message) { + return reportSimpleFileCtx(message, Severity.ERROR, line, file); + } + + @Override + public String reportWarning(Path file, Integer line, String message) { + return reportSimpleFileCtx(message, Severity.WARNING, line, file); + } + + @Override + public String reportInfo(Path file, Integer line, String message) { + return reportSimpleFileCtx(message, Severity.INFO, line, file); + } + + @Override + public boolean getErrorsOccurred() { + return issueAcceptor.getErrorsOccurred(); + } } diff --git a/org.lflang/src/org/lflang/cli/StandaloneIssueAcceptor.java b/org.lflang/src/org/lflang/cli/StandaloneIssueAcceptor.java index 73ca4bea9e..cb9712a7cb 100644 --- a/org.lflang/src/org/lflang/cli/StandaloneIssueAcceptor.java +++ b/org.lflang/src/org/lflang/cli/StandaloneIssueAcceptor.java @@ -1,42 +1,41 @@ package org.lflang.cli; +import com.google.inject.Inject; import java.io.IOException; import java.nio.file.Path; - import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.xtext.diagnostics.Severity; import org.eclipse.xtext.validation.EObjectDiagnosticImpl; import org.eclipse.xtext.validation.ValidationMessageAcceptor; - import org.lflang.util.FileUtil; -import com.google.inject.Inject; - -/** - * - */ +/** */ public class StandaloneIssueAcceptor implements ValidationMessageAcceptor { - @Inject - private IssueCollector collector; - - - boolean getErrorsOccurred() { - return collector.getErrorsOccurred(); - } - - - void accept(LfIssue lfIssue) { - collector.accept(lfIssue); - } - - - void accept(Severity severity, String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { - EObjectDiagnosticImpl diagnostic = - new EObjectDiagnosticImpl(severity, code, message, object, feature, index, issueData); - - LfIssue lfIssue = new LfIssue( + @Inject private IssueCollector collector; + + boolean getErrorsOccurred() { + return collector.getErrorsOccurred(); + } + + void accept(LfIssue lfIssue) { + collector.accept(lfIssue); + } + + void accept( + Severity severity, + String message, + EObject object, + EStructuralFeature feature, + int index, + String code, + String... issueData) { + EObjectDiagnosticImpl diagnostic = + new EObjectDiagnosticImpl(severity, code, message, object, feature, index, issueData); + + LfIssue lfIssue = + new LfIssue( message, severity, diagnostic.getLine(), @@ -44,64 +43,81 @@ void accept(Severity severity, String message, EObject object, EStructuralFeatur diagnostic.getLineEnd(), diagnostic.getColumnEnd(), diagnostic.getLength(), - getPath(diagnostic) - ); - - accept(lfIssue); - } - - - /** - * Best effort to get a fileName. May return null. - */ - private Path getPath(EObjectDiagnosticImpl diagnostic) { - Path file = null; - try { - file = FileUtil.toPath(diagnostic.getUriToProblem()); - } catch (IOException e) { - // just continue with null - } - return file; - } - - - private void accept(Severity severity, String message, EObject object, int offset, int length, String code, String... issueData) { - throw new UnsupportedOperationException("not implemented: range based diagnostics"); - } - - - @Override - public void acceptError(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { - accept(Severity.ERROR, message, object, feature, index, code, issueData); - } - - - @Override - public void acceptError(String message, EObject object, int offset, int length, String code, String... issueData) { - accept(Severity.ERROR, message, object, offset, length, code, issueData); - } - - - @Override - public void acceptWarning(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { - accept(Severity.WARNING, message, object, feature, index, code, issueData); - } - - - @Override - public void acceptWarning(String message, EObject object, int offset, int length, String code, String... issueData) { - accept(Severity.WARNING, message, object, offset, length, code, issueData); - } - - - @Override - public void acceptInfo(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { - accept(Severity.INFO, message, object, feature, index, code, issueData); - } - - - @Override - public void acceptInfo(String message, EObject object, int offset, int length, String code, String... issueData) { - accept(Severity.INFO, message, object, offset, length, code, issueData); + getPath(diagnostic)); + + accept(lfIssue); + } + + /** Best effort to get a fileName. May return null. */ + private Path getPath(EObjectDiagnosticImpl diagnostic) { + Path file = null; + try { + file = FileUtil.toPath(diagnostic.getUriToProblem()); + } catch (IOException e) { + // just continue with null } + return file; + } + + private void accept( + Severity severity, + String message, + EObject object, + int offset, + int length, + String code, + String... issueData) { + throw new UnsupportedOperationException("not implemented: range based diagnostics"); + } + + @Override + public void acceptError( + String message, + EObject object, + EStructuralFeature feature, + int index, + String code, + String... issueData) { + accept(Severity.ERROR, message, object, feature, index, code, issueData); + } + + @Override + public void acceptError( + String message, EObject object, int offset, int length, String code, String... issueData) { + accept(Severity.ERROR, message, object, offset, length, code, issueData); + } + + @Override + public void acceptWarning( + String message, + EObject object, + EStructuralFeature feature, + int index, + String code, + String... issueData) { + accept(Severity.WARNING, message, object, feature, index, code, issueData); + } + + @Override + public void acceptWarning( + String message, EObject object, int offset, int length, String code, String... issueData) { + accept(Severity.WARNING, message, object, offset, length, code, issueData); + } + + @Override + public void acceptInfo( + String message, + EObject object, + EStructuralFeature feature, + int index, + String code, + String... issueData) { + accept(Severity.INFO, message, object, feature, index, code, issueData); + } + + @Override + public void acceptInfo( + String message, EObject object, int offset, int length, String code, String... issueData) { + accept(Severity.INFO, message, object, offset, length, code, issueData); + } } diff --git a/org.lflang/src/org/lflang/cli/VersionProvider.java b/org.lflang/src/org/lflang/cli/VersionProvider.java index ce9c8f6252..ca9c3d6bbb 100644 --- a/org.lflang/src/org/lflang/cli/VersionProvider.java +++ b/org.lflang/src/org/lflang/cli/VersionProvider.java @@ -1,11 +1,10 @@ package org.lflang.cli; +import org.lflang.LocalStrings; import picocli.CommandLine.IVersionProvider; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Spec; -import org.lflang.LocalStrings; - /* * Dynamically provides version information to the Lingua Franca CLI. * Picocli will instantiate this class and invoke it to collect version @@ -14,19 +13,18 @@ * @author Atharva Patil */ class VersionProvider implements IVersionProvider { - /* - * Here, picocli will inject the CommandSpec (full command hierarchy) of the - * command that uses this version provider. This allows this version - * provider to be reused among multiple commands. - */ - @Spec CommandSpec spec; + /* + * Here, picocli will inject the CommandSpec (full command hierarchy) of the + * command that uses this version provider. This allows this version + * provider to be reused among multiple commands. + */ + @Spec CommandSpec spec; - // Method invoked by picocli to get the version info. - public String[] getVersion() { - return new String[] { - // "lfc", "lff", etc. - spec.qualifiedName() - + " " + LocalStrings.VERSION - }; - } + // Method invoked by picocli to get the version info. + public String[] getVersion() { + return new String[] { + // "lfc", "lff", etc. + spec.qualifiedName() + " " + LocalStrings.VERSION + }; + } } diff --git a/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServer.java b/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServer.java index 1971fbc081..405e322a88 100644 --- a/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServer.java +++ b/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServer.java @@ -1,10 +1,9 @@ package org.lflang.diagram.lsp; -import org.eclipse.lsp4j.WorkDoneProgressCancelParams; import de.cau.cs.kieler.klighd.lsp.KGraphLanguageServerExtension; - import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.HoverParams; +import org.eclipse.lsp4j.WorkDoneProgressCancelParams; import org.eclipse.xtext.ide.server.hover.IHoverService; import org.eclipse.xtext.util.CancelIndicator; @@ -14,21 +13,24 @@ * @author Peter Donovan */ public class LFLanguageServer extends KGraphLanguageServerExtension { - @Override - public void cancelProgress(WorkDoneProgressCancelParams params) { - Progress.cancel(params.getToken().getRight().intValue()); - } + @Override + public void cancelProgress(WorkDoneProgressCancelParams params) { + Progress.cancel(params.getToken().getRight().intValue()); + } - @Override - protected Hover hover(HoverParams params, CancelIndicator cancelIndicator) { - // This override is just a hacky little patch that is being applied downstream of the original mistake and - // upstream of the ungraceful handling (IndexOutOfBoundsException) of said mistake. This patch is applied here - // simply because it is easy. This would be done differently were it not for the fact that we plan to rebuild - // this infrastructure from scratch anyway. - try { - return super.hover(params, cancelIndicator); - } catch (IndexOutOfBoundsException e) { - return IHoverService.EMPTY_HOVER; // Fail silently - } + @Override + protected Hover hover(HoverParams params, CancelIndicator cancelIndicator) { + // This override is just a hacky little patch that is being applied downstream of the original + // mistake and + // upstream of the ungraceful handling (IndexOutOfBoundsException) of said mistake. This patch + // is applied here + // simply because it is easy. This would be done differently were it not for the fact that we + // plan to rebuild + // this infrastructure from scratch anyway. + try { + return super.hover(params, cancelIndicator); + } catch (IndexOutOfBoundsException e) { + return IHoverService.EMPTY_HOVER; // Fail silently } + } } diff --git a/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServerExtension.java b/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServerExtension.java index fd25b0fc0a..18de51f482 100644 --- a/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServerExtension.java +++ b/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServerExtension.java @@ -1,125 +1,125 @@ package org.lflang.diagram.lsp; -import java.util.concurrent.CompletableFuture; import java.util.ArrayList; - +import java.util.concurrent.CompletableFuture; import org.eclipse.emf.common.util.URI; import org.eclipse.lsp4j.jsonrpc.services.JsonNotification; import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; import org.eclipse.lsp4j.services.LanguageClient; -import org.eclipse.xtext.ide.server.ILanguageServerExtension; import org.eclipse.xtext.ide.server.ILanguageServerAccess; - +import org.eclipse.xtext.ide.server.ILanguageServerExtension; +import org.lflang.LFRuntimeModule; +import org.lflang.LFStandaloneSetup; +import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorResult.Status; import org.lflang.generator.IntegratedBuilder; -import org.lflang.generator.GeneratorResult; -import org.lflang.LFStandaloneSetup; -import org.lflang.LFRuntimeModule; import org.lflang.util.LFCommand; /** - * Provide Lingua-Franca-specific extensions to the - * language server's behavior. + * Provide Lingua-Franca-specific extensions to the language server's behavior. * * @author Peter Donovan */ class LFLanguageServerExtension implements ILanguageServerExtension { - /** The IntegratedBuilder instance that handles all build requests for the current session. */ - private static final IntegratedBuilder builder = new LFStandaloneSetup(new LFRuntimeModule()) - .createInjectorAndDoEMFRegistration().getInstance(IntegratedBuilder.class); + /** The IntegratedBuilder instance that handles all build requests for the current session. */ + private static final IntegratedBuilder builder = + new LFStandaloneSetup(new LFRuntimeModule()) + .createInjectorAndDoEMFRegistration() + .getInstance(IntegratedBuilder.class); - /** The access point for reading documents, communicating with the language client, etc. */ - private LanguageClient client; + /** The access point for reading documents, communicating with the language client, etc. */ + private LanguageClient client; - @Override - public void initialize(ILanguageServerAccess access) { - // This method is never invoked. - } + @Override + public void initialize(ILanguageServerAccess access) { + // This method is never invoked. + } - public void setClient(LanguageClient client) { - this.client = client; - } + public void setClient(LanguageClient client) { + this.client = client; + } - /** - * Handle a request for a complete build of the Lingua - * Franca file specified by {@code uri}. - * @param uri the URI of the LF file of interest - * @return A message describing the outcome of the build - * process. - */ - @JsonRequest("generator/build") - public CompletableFuture build(String uri) { - if (client == null) return CompletableFuture.completedFuture( - "Please wait for the Lingua Franca language server to be fully initialized." - ); - return CompletableFuture.supplyAsync( - () -> { - try { - return buildWithProgress(client, uri, true).getUserMessage(); - } catch (Exception e) { - return "An internal error occurred:\n" + e; - } - } - ); - } + /** + * Handle a request for a complete build of the Lingua Franca file specified by {@code uri}. + * + * @param uri the URI of the LF file of interest + * @return A message describing the outcome of the build process. + */ + @JsonRequest("generator/build") + public CompletableFuture build(String uri) { + if (client == null) + return CompletableFuture.completedFuture( + "Please wait for the Lingua Franca language server to be fully initialized."); + return CompletableFuture.supplyAsync( + () -> { + try { + return buildWithProgress(client, uri, true).getUserMessage(); + } catch (Exception e) { + return "An internal error occurred:\n" + e; + } + }); + } - /** - * Handles a request for the most complete build of the - * specified Lingua Franca file that can be done in a - * limited amount of time. - * @param uri the URI of the LF file of interest - */ - @JsonNotification("generator/partialBuild") - public void partialBuild(String uri) { - if (client == null) return; - buildWithProgress(client, uri, false); - } + /** + * Handles a request for the most complete build of the specified Lingua Franca file that can be + * done in a limited amount of time. + * + * @param uri the URI of the LF file of interest + */ + @JsonNotification("generator/partialBuild") + public void partialBuild(String uri) { + if (client == null) return; + buildWithProgress(client, uri, false); + } - /** - * Completely build the specified LF program and provide information that is sufficient to - * run it. - * @param uri The URI of the LF program to be built. - * @return An array consisting of the directory in which the execute command should be - * executed, the program of the execute command, and the arguments of the execute command. - */ - @JsonNotification("generator/buildAndRun") - public CompletableFuture buildAndRun(String uri) { - return new CompletableFuture().completeAsync(() -> { - var result = buildWithProgress(client, uri, true); - if (!result.getStatus().equals(Status.COMPILED)) return null; - LFCommand cmd = result.getContext().getFileConfig().getCommand(); - ArrayList ret = new ArrayList<>(); - ret.add(cmd.directory().toString()); - ret.addAll(cmd.command()); - return ret.toArray(new String[0]); - }); - } + /** + * Completely build the specified LF program and provide information that is sufficient to run it. + * + * @param uri The URI of the LF program to be built. + * @return An array consisting of the directory in which the execute command should be executed, + * the program of the execute command, and the arguments of the execute command. + */ + @JsonNotification("generator/buildAndRun") + public CompletableFuture buildAndRun(String uri) { + return new CompletableFuture() + .completeAsync( + () -> { + var result = buildWithProgress(client, uri, true); + if (!result.getStatus().equals(Status.COMPILED)) return null; + LFCommand cmd = result.getContext().getFileConfig().getCommand(); + ArrayList ret = new ArrayList<>(); + ret.add(cmd.directory().toString()); + ret.addAll(cmd.command()); + return ret.toArray(new String[0]); + }); + } - /** - * Describes a build process that has a progress. - */ - private GeneratorResult buildWithProgress(LanguageClient client, String uri, boolean mustComplete) { - URI parsedUri; - try { - parsedUri = URI.createFileURI(new java.net.URI(uri).getPath()); - } catch (java.net.URISyntaxException e) { - // This error will appear as a silent failure to most users, but that is acceptable because this error - // should be impossible. The URI is not the result of user input -- the language client provides it -- - // so it should be valid. - System.err.println(e); - return GeneratorResult.NOTHING; - } - Progress progress = new Progress(client, "Build \"" + parsedUri.lastSegment() + "\"", mustComplete); - progress.begin(); - GeneratorResult result = null; - try { - result = builder.run( - parsedUri, mustComplete, progress::report, progress.getCancelIndicator() - ); - } finally { - progress.end(result == null ? "An internal error occurred." : result.getUserMessage()); - } - return result; + /** Describes a build process that has a progress. */ + private GeneratorResult buildWithProgress( + LanguageClient client, String uri, boolean mustComplete) { + URI parsedUri; + try { + parsedUri = URI.createFileURI(new java.net.URI(uri).getPath()); + } catch (java.net.URISyntaxException e) { + // This error will appear as a silent failure to most users, but that is acceptable because + // this error + // should be impossible. The URI is not the result of user input -- the language client + // provides it -- + // so it should be valid. + System.err.println(e); + return GeneratorResult.NOTHING; + } + Progress progress = + new Progress(client, "Build \"" + parsedUri.lastSegment() + "\"", mustComplete); + progress.begin(); + GeneratorResult result = null; + try { + result = + builder.run(parsedUri, mustComplete, progress::report, progress.getCancelIndicator()); + } finally { + progress.end(result == null ? "An internal error occurred." : result.getUserMessage()); } + return result; + } } diff --git a/org.lflang/src/org/lflang/diagram/lsp/LanguageDiagramServer.java b/org.lflang/src/org/lflang/diagram/lsp/LanguageDiagramServer.java index c4d7804453..96e887d242 100644 --- a/org.lflang/src/org/lflang/diagram/lsp/LanguageDiagramServer.java +++ b/org.lflang/src/org/lflang/diagram/lsp/LanguageDiagramServer.java @@ -1,20 +1,8 @@ package org.lflang.diagram.lsp; -import java.util.List; - -import org.eclipse.xtext.Constants; -import org.eclipse.xtext.IGrammarAccess; -import org.eclipse.xtext.ide.server.ILanguageServerExtension; -import org.eclipse.xtext.ide.server.LanguageServerImpl; -import org.eclipse.xtext.service.AbstractGenericModule; -import org.eclipse.xtext.util.Modules2; -import org.lflang.generator.LanguageServerErrorReporter; -import org.lflang.ide.LFIdeSetup; - import com.google.inject.Module; import com.google.inject.name.Names; import com.google.inject.util.Modules; - import de.cau.cs.kieler.kgraph.text.services.KGraphGrammarAccess; import de.cau.cs.kieler.klighd.lsp.KGraphLanguageClient; import de.cau.cs.kieler.klighd.lsp.interactive.layered.LayeredInteractiveLanguageServerExtension; @@ -24,82 +12,102 @@ import de.cau.cs.kieler.klighd.lsp.launch.AbstractRegistrationLanguageServerExtension; import de.cau.cs.kieler.klighd.lsp.launch.ILanguageRegistration; import de.cau.cs.kieler.klighd.lsp.launch.Language; +import java.util.List; +import org.eclipse.xtext.Constants; +import org.eclipse.xtext.IGrammarAccess; +import org.eclipse.xtext.ide.server.ILanguageServerExtension; +import org.eclipse.xtext.ide.server.LanguageServerImpl; +import org.eclipse.xtext.service.AbstractGenericModule; +import org.eclipse.xtext.util.Modules2; +import org.lflang.generator.LanguageServerErrorReporter; +import org.lflang.ide.LFIdeSetup; /** * Language server with extended diagram communication. - * + * * @author Alexander Schulz-Rosengarten */ public class LanguageDiagramServer extends AbstractLanguageServer { - - private static class LFLsCreator extends AbstractLsCreator { - @Override - public Module createLSModules(boolean socket) { - return Modules2.mixin(Modules.override(super.createLSModules(socket)).with(new AbstractGenericModule() { - public Class bindLanguageServerImpl() { - return LFLanguageServer.class; - } - }), it -> { - // Temporary fix for an issue of Klighd with Xtext 2.28 (https://github.com/kieler/KLighD/issues/144) - it.bind(IGrammarAccess.class).to(KGraphGrammarAccess.class); - it.bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("de.cau.cs.kieler.kgraph.text.KGraph"); - }); - } - - LayeredInteractiveLanguageServerExtension constraints; - RectpackingInteractiveLanguageServerExtension rectPack; - LFLanguageServerExtension lfExtension; - - @Override - public List getLanguageServerExtensions() { - constraints = injector.getInstance(LayeredInteractiveLanguageServerExtension.class); - rectPack = injector.getInstance(RectpackingInteractiveLanguageServerExtension.class); - lfExtension = injector.getInstance(LFLanguageServerExtension.class); - return List.of( - injector.getInstance(LFRegistrationLanguageServerExtension.class), constraints, rectPack, lfExtension - ); - } - - @Override - public Class getRemoteInterface() { - return KGraphLanguageClient.class; - } - - @Override - public void onConnect() { - super.onConnect(); - constraints.setClient((KGraphLanguageClient) languageClient); - rectPack.setClient((KGraphLanguageClient) languageClient); - LanguageServerErrorReporter.setClient(languageClient); - lfExtension.setClient(languageClient); - // The following is needed because VS Code treats System.err like System.out and System.out like a shout - // into the void. - System.setOut(System.err); - } + private static class LFLsCreator extends AbstractLsCreator { + + @Override + public Module createLSModules(boolean socket) { + return Modules2.mixin( + Modules.override(super.createLSModules(socket)) + .with( + new AbstractGenericModule() { + public Class bindLanguageServerImpl() { + return LFLanguageServer.class; + } + }), + it -> { + // Temporary fix for an issue of Klighd with Xtext 2.28 + // (https://github.com/kieler/KLighD/issues/144) + it.bind(IGrammarAccess.class).to(KGraphGrammarAccess.class); + it.bind(String.class) + .annotatedWith(Names.named(Constants.LANGUAGE_NAME)) + .toInstance("de.cau.cs.kieler.kgraph.text.KGraph"); + }); + } + + LayeredInteractiveLanguageServerExtension constraints; + RectpackingInteractiveLanguageServerExtension rectPack; + LFLanguageServerExtension lfExtension; + + @Override + public List getLanguageServerExtensions() { + constraints = injector.getInstance(LayeredInteractiveLanguageServerExtension.class); + rectPack = injector.getInstance(RectpackingInteractiveLanguageServerExtension.class); + lfExtension = injector.getInstance(LFLanguageServerExtension.class); + return List.of( + injector.getInstance(LFRegistrationLanguageServerExtension.class), + constraints, + rectPack, + lfExtension); } - - private static class LFLanguageRegistration implements ILanguageRegistration { - - @Override - public void bindAndRegisterLanguages() { - LFIdeSetup.doSetup(); - } + + @Override + public Class getRemoteInterface() { + return KGraphLanguageClient.class; } - private static class LFRegistrationLanguageServerExtension extends AbstractRegistrationLanguageServerExtension { - - @Override - public List getLanguageExtensions() { - return List.of(new Language("lf", "Lingua Franca", List.of())); - } + @Override + public void onConnect() { + super.onConnect(); + constraints.setClient((KGraphLanguageClient) languageClient); + rectPack.setClient((KGraphLanguageClient) languageClient); + LanguageServerErrorReporter.setClient(languageClient); + lfExtension.setClient(languageClient); + // The following is needed because VS Code treats System.err like System.out and System.out + // like a shout + // into the void. + System.setOut(System.err); } - - public static void main(String[] args) { - new LanguageDiagramServer().start(); + } + + private static class LFLanguageRegistration implements ILanguageRegistration { + + @Override + public void bindAndRegisterLanguages() { + LFIdeSetup.doSetup(); } - - public void start() { - configureAndRun(new LFLanguageRegistration(), new LFLsCreator()); + } + + private static class LFRegistrationLanguageServerExtension + extends AbstractRegistrationLanguageServerExtension { + + @Override + public List getLanguageExtensions() { + return List.of(new Language("lf", "Lingua Franca", List.of())); } + } + + public static void main(String[] args) { + new LanguageDiagramServer().start(); + } + + public void start() { + configureAndRun(new LFLanguageRegistration(), new LFLsCreator()); + } } diff --git a/org.lflang/src/org/lflang/diagram/lsp/Progress.java b/org.lflang/src/org/lflang/diagram/lsp/Progress.java index 2c1bb2f7fe..56c6788ea8 100644 --- a/org.lflang/src/org/lflang/diagram/lsp/Progress.java +++ b/org.lflang/src/org/lflang/diagram/lsp/Progress.java @@ -2,15 +2,14 @@ import java.util.HashMap; import java.util.Map; - -import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.ProgressParams; -import org.eclipse.lsp4j.services.LanguageClient; -import org.eclipse.lsp4j.WorkDoneProgressCreateParams; import org.eclipse.lsp4j.WorkDoneProgressBegin; +import org.eclipse.lsp4j.WorkDoneProgressCreateParams; import org.eclipse.lsp4j.WorkDoneProgressEnd; import org.eclipse.lsp4j.WorkDoneProgressNotification; import org.eclipse.lsp4j.WorkDoneProgressReport; +import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.eclipse.lsp4j.services.LanguageClient; import org.eclipse.xtext.util.CancelIndicator; /** @@ -19,88 +18,85 @@ * @author Peter Donovan */ public class Progress { - private static int nextToken = 0; - private static final Map cancellations = new HashMap<>(); + private static int nextToken = 0; + private static final Map cancellations = new HashMap<>(); - private final LanguageClient client; - private final String title; - private final int token; - private final boolean cancellable; + private final LanguageClient client; + private final String title; + private final int token; + private final boolean cancellable; - /** - * Initialize the {@code Progress} of a task titled {@code title} that is - * triggered via {@code client}. - * @param client A language client through which a task was triggered. - * @param title The title of the task. - * @param cancellable Whether the task tracked by {@code this} can be - * cancelled. - */ - public Progress(LanguageClient client, String title, boolean cancellable) { - this.client = client; - this.title = title; - this.token = nextToken++; - this.cancellable = cancellable; - if (cancellable) cancellations.put(token, false); - client.createProgress(new WorkDoneProgressCreateParams(Either.forRight(token))); - } + /** + * Initialize the {@code Progress} of a task titled {@code title} that is triggered via {@code + * client}. + * + * @param client A language client through which a task was triggered. + * @param title The title of the task. + * @param cancellable Whether the task tracked by {@code this} can be cancelled. + */ + public Progress(LanguageClient client, String title, boolean cancellable) { + this.client = client; + this.title = title; + this.token = nextToken++; + this.cancellable = cancellable; + if (cancellable) cancellations.put(token, false); + client.createProgress(new WorkDoneProgressCreateParams(Either.forRight(token))); + } - /** - * Cancel the task tracked by the {@code Progress} that has token - * {@code token}. - */ - public static void cancel(int token) { - if (cancellations.containsKey(token)) cancellations.put(token, true); - } + /** Cancel the task tracked by the {@code Progress} that has token {@code token}. */ + public static void cancel(int token) { + if (cancellations.containsKey(token)) cancellations.put(token, true); + } - /** - * Returns the cancel indicator for the task tracked by this - * {@code Progress}. - * @return the cancel indicator for the task tracked by this - * {@code Progress} - */ - public CancelIndicator getCancelIndicator() { - if (cancellable) return () -> cancellations.get(token); - return () -> false; - } + /** + * Returns the cancel indicator for the task tracked by this {@code Progress}. + * + * @return the cancel indicator for the task tracked by this {@code Progress} + */ + public CancelIndicator getCancelIndicator() { + if (cancellable) return () -> cancellations.get(token); + return () -> false; + } - /** - * Report that the task tracked by {@code this} is done. - */ - public void begin() { - WorkDoneProgressBegin begin = new WorkDoneProgressBegin(); - begin.setTitle(title); - begin.setCancellable(cancellable); - begin.setPercentage(0); - notifyProgress(begin); - } + /** Report that the task tracked by {@code this} is done. */ + public void begin() { + WorkDoneProgressBegin begin = new WorkDoneProgressBegin(); + begin.setTitle(title); + begin.setCancellable(cancellable); + begin.setPercentage(0); + notifyProgress(begin); + } - /** - * Report the progress of the task tracked by {@code this}. - * @param message A message describing the progress of the task. - */ - public void report(String message, Integer percentage) { - WorkDoneProgressReport report = new WorkDoneProgressReport(); - report.setMessage(message); - report.setCancellable(cancellable); - report.setPercentage(percentage); - notifyProgress(report); - } + /** + * Report the progress of the task tracked by {@code this}. + * + * @param message A message describing the progress of the task. + */ + public void report(String message, Integer percentage) { + WorkDoneProgressReport report = new WorkDoneProgressReport(); + report.setMessage(message); + report.setCancellable(cancellable); + report.setPercentage(percentage); + notifyProgress(report); + } - /** - * Marks the task tracked by {@code this} as terminated. - * @param message A message describing the outcome of the task. - */ - public void end(String message) { - WorkDoneProgressEnd end = new WorkDoneProgressEnd(); - end.setMessage(message); - notifyProgress(end); - } + /** + * Marks the task tracked by {@code this} as terminated. + * + * @param message A message describing the outcome of the task. + */ + public void end(String message) { + WorkDoneProgressEnd end = new WorkDoneProgressEnd(); + end.setMessage(message); + notifyProgress(end); + } - /** - * Send the given progress notification to the client. - * @param notification - */ - private void notifyProgress(WorkDoneProgressNotification notification) { - client.notifyProgress(new ProgressParams(Either.forRight(token), Either.forLeft(notification))); - } + /** + * Send the given progress notification to the client. + * + * @param notification + */ + private void notifyProgress(WorkDoneProgressNotification notification) { + client.notifyProgress(new ProgressParams(Either.forRight(token), Either.forLeft(notification))); + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java b/org.lflang/src/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java index 1041af3ce7..4d32af61ef 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis; import de.cau.cs.kieler.klighd.SynthesisOption; @@ -30,33 +30,33 @@ import org.eclipse.emf.ecore.EObject; /** - * Abstract super class for extension classes used in for the diagram synthesis that provides some convince methods. - * + * Abstract super class for extension classes used in for the diagram synthesis that provides some + * convince methods. + * * @author Alexander Schulz-Rosengarten */ public abstract class AbstractSynthesisExtensions { - - @Inject - private AbstractDiagramSynthesis delegate; - - public boolean getBooleanValue(SynthesisOption option) { - return delegate.getBooleanValue(option); - } - - public float getFloatValue(SynthesisOption option) { - return delegate.getFloatValue(option); - } - - public Object getObjectValue(final SynthesisOption option) { - return delegate.getObjectValue(option); - } - - public T associateWith(T derived, Object source) { - return delegate.associateWith(derived, source); - } - - @SuppressWarnings("unchecked") - public > T getRootSynthesis() { - return (T) delegate; - } + + @Inject private AbstractDiagramSynthesis delegate; + + public boolean getBooleanValue(SynthesisOption option) { + return delegate.getBooleanValue(option); + } + + public float getFloatValue(SynthesisOption option) { + return delegate.getFloatValue(option); + } + + public Object getObjectValue(final SynthesisOption option) { + return delegate.getObjectValue(option); + } + + public T associateWith(T derived, Object source) { + return delegate.associateWith(derived, source); + } + + @SuppressWarnings("unchecked") + public > T getRootSynthesis() { + return (T) delegate; + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index 2b1a2a1bf6..45f3342a0a 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -1,29 +1,61 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; +import com.google.common.collect.Table; +import de.cau.cs.kieler.klighd.DisplayedActionData; +import de.cau.cs.kieler.klighd.SynthesisOption; +import de.cau.cs.kieler.klighd.kgraph.KEdge; +import de.cau.cs.kieler.klighd.kgraph.KLabel; +import de.cau.cs.kieler.klighd.kgraph.KNode; +import de.cau.cs.kieler.klighd.kgraph.KPort; +import de.cau.cs.kieler.klighd.krendering.Colors; +import de.cau.cs.kieler.klighd.krendering.HorizontalAlignment; +import de.cau.cs.kieler.klighd.krendering.KContainerRendering; +import de.cau.cs.kieler.klighd.krendering.KPolyline; +import de.cau.cs.kieler.klighd.krendering.KRectangle; +import de.cau.cs.kieler.klighd.krendering.KRendering; +import de.cau.cs.kieler.klighd.krendering.KRoundedRectangle; +import de.cau.cs.kieler.klighd.krendering.KStyle; +import de.cau.cs.kieler.klighd.krendering.KText; +import de.cau.cs.kieler.klighd.krendering.LineCap; +import de.cau.cs.kieler.klighd.krendering.LineStyle; +import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; +import de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KPortExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions; +import de.cau.cs.kieler.klighd.syntheses.AbstractDiagramSynthesis; +import de.cau.cs.kieler.klighd.util.KlighdProperties; import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; @@ -35,9 +67,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - import javax.inject.Inject; - import org.eclipse.elk.alg.layered.options.LayerConstraint; import org.eclipse.elk.alg.layered.options.LayeredOptions; import org.eclipse.elk.alg.layered.options.NodePlacementStrategy; @@ -62,9 +92,9 @@ import org.eclipse.xtext.xbase.lib.ListExtensions; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.InferredType; +import org.lflang.ast.ASTUtils; import org.lflang.ast.FormattingUtils; import org.lflang.diagram.synthesis.action.CollapseAllReactorsAction; import org.lflang.diagram.synthesis.action.ExpandAllReactorsAction; @@ -99,40 +129,6 @@ import org.lflang.lf.StateVar; import org.lflang.util.FileUtil; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; -import com.google.common.collect.Table; - -import de.cau.cs.kieler.klighd.DisplayedActionData; -import de.cau.cs.kieler.klighd.SynthesisOption; -import de.cau.cs.kieler.klighd.kgraph.KEdge; -import de.cau.cs.kieler.klighd.kgraph.KLabel; -import de.cau.cs.kieler.klighd.kgraph.KNode; -import de.cau.cs.kieler.klighd.kgraph.KPort; -import de.cau.cs.kieler.klighd.krendering.Colors; -import de.cau.cs.kieler.klighd.krendering.HorizontalAlignment; -import de.cau.cs.kieler.klighd.krendering.KContainerRendering; -import de.cau.cs.kieler.klighd.krendering.KPolyline; -import de.cau.cs.kieler.klighd.krendering.KRectangle; -import de.cau.cs.kieler.klighd.krendering.KRendering; -import de.cau.cs.kieler.klighd.krendering.KRoundedRectangle; -import de.cau.cs.kieler.klighd.krendering.KStyle; -import de.cau.cs.kieler.klighd.krendering.KText; -import de.cau.cs.kieler.klighd.krendering.LineCap; -import de.cau.cs.kieler.klighd.krendering.LineStyle; -import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; -import de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KPortExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions; -import de.cau.cs.kieler.klighd.syntheses.AbstractDiagramSynthesis; -import de.cau.cs.kieler.klighd.util.KlighdProperties; - /** * Diagram synthesis for Lingua Franca programs. * @@ -140,1270 +136,1537 @@ */ @ViewSynthesisShared public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis { - @Inject @Extension private KNodeExtensions _kNodeExtensions; - @Inject @Extension private KEdgeExtensions _kEdgeExtensions; - @Inject @Extension private KPortExtensions _kPortExtensions; - @Inject @Extension private KLabelExtensions _kLabelExtensions; - @Inject @Extension private KRenderingExtensions _kRenderingExtensions; - @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; - @Inject @Extension private KPolylineExtensions _kPolylineExtensions; - @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; - @Inject @Extension private LinguaFrancaShapeExtensions _linguaFrancaShapeExtensions; - @Inject @Extension private UtilityExtensions _utilityExtensions; - @Inject @Extension private CycleVisualization _cycleVisualization; - @Inject @Extension private InterfaceDependenciesVisualization _interfaceDependenciesVisualization; - @Inject @Extension private FilterCycleAction _filterCycleAction; - @Inject @Extension private ReactorIcons _reactorIcons; - @Inject @Extension private ModeDiagrams _modeDiagrams; - @Inject @Extension private LayoutPostProcessing _layoutPostProcessing; - - // ------------------------------------------------------------------------- - - public static final String ID = "org.lflang.diagram.synthesis.LinguaFrancaSynthesis"; - - // -- INTERNAL -- - public static final Property REACTOR_RECURSIVE_INSTANTIATION = new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.recursive.instantiation", false); - public static final Property REACTOR_HAS_BANK_PORT_OFFSET = new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.bank.offset", false); - public static final Property REACTOR_INPUT = new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.input", false); - public static final Property REACTOR_OUTPUT = new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.output", false); - public static final Property REACTION_SPECIAL_TRIGGER = new Property<>("org.lflang.linguafranca.diagram.synthesis.reaction.special.trigger", false); - - // -- STYLE -- - public static final List ALTERNATIVE_DASH_PATTERN = List.of(3.0f); - - // -- TEXT -- - public static final String TEXT_ERROR_RECURSIVE = "Recursive reactor instantiation!"; - public static final String TEXT_ERROR_CONTAINS_RECURSION = "Reactor contains recursive instantiation!"; - public static final String TEXT_ERROR_CONTAINS_CYCLE = "Reactor contains cyclic dependencies!"; - public static final String TEXT_ERROR_CYCLE_DETECTION = "Dependency cycle detection failed.\nCould not detect dependency cycles due to unexpected graph structure."; - public static final String TEXT_ERROR_CYCLE_BTN_SHOW = "Show Cycle"; - public static final String TEXT_ERROR_CYCLE_BTN_FILTER = "Filter Cycle"; - public static final String TEXT_ERROR_CYCLE_BTN_UNFILTER = "Remove Cycle Filter"; - public static final String TEXT_NO_MAIN_REACTOR = "No Main Reactor"; - public static final String TEXT_REACTOR_NULL = "Reactor is null"; - public static final String TEXT_HIDE_ACTION = "[Hide]"; - public static final String TEXT_SHOW_ACTION = "[Details]"; - - // ------------------------------------------------------------------------- - - /** Synthesis category */ - public static final SynthesisOption APPEARANCE = SynthesisOption.createCategory("Appearance", true); - public static final SynthesisOption EXPERIMENTAL = SynthesisOption.createCategory("Experimental", true); - public static final SynthesisOption LAYOUT = SynthesisOption.createCategory("Layout", false).setCategory(LinguaFrancaSynthesis.APPEARANCE); - - /** Synthesis options */ - public static final SynthesisOption SHOW_ALL_REACTORS = SynthesisOption.createCheckOption("All Reactors", false); - public static final SynthesisOption CYCLE_DETECTION = SynthesisOption.createCheckOption("Dependency Cycle Detection", true); - - public static final SynthesisOption SHOW_USER_LABELS = SynthesisOption.createCheckOption("User Labels (@label in JavaDoc)", true).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_HYPERLINKS = SynthesisOption.createCheckOption("Expand/Collapse Hyperlinks", false).setCategory(APPEARANCE); - public static final SynthesisOption REACTIONS_USE_HYPEREDGES = SynthesisOption.createCheckOption("Bundled Dependencies", false).setCategory(APPEARANCE); - public static final SynthesisOption USE_ALTERNATIVE_DASH_PATTERN = SynthesisOption.createCheckOption("Alternative Dependency Line Style", false).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_PORT_NAMES = SynthesisOption.createCheckOption("Port names", true).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_MULTIPORT_WIDTH = SynthesisOption.createCheckOption("Multiport Widths", false).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_REACTION_CODE = SynthesisOption.createCheckOption("Reaction Code", false).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_REACTION_LEVEL = SynthesisOption.createCheckOption("Reaction Level", false).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_REACTION_ORDER_EDGES = SynthesisOption.createCheckOption("Reaction Order Edges", false).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_REACTOR_HOST = SynthesisOption.createCheckOption("Reactor Host Addresses", true).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_INSTANCE_NAMES = SynthesisOption.createCheckOption("Reactor Instance Names", false).setCategory(APPEARANCE); - public static final SynthesisOption REACTOR_PARAMETER_MODE = SynthesisOption.createChoiceOption("Reactor Parameters", ((List)Conversions.doWrapArray(ReactorParameterDisplayModes.values())), ReactorParameterDisplayModes.NONE).setCategory(APPEARANCE); - public static final SynthesisOption SHOW_STATE_VARIABLES = SynthesisOption.createCheckOption("Reactor State Variables", false).setCategory(APPEARANCE); - public static final SynthesisOption REACTOR_BODY_TABLE_COLS = SynthesisOption.createRangeOption("Reactor Parameter/Variable Columns", 1, 10, 1).setCategory(APPEARANCE); - - public static final SynthesisOption SPACING = SynthesisOption.createRangeOption("Spacing (%)", 0, 150, 5, 75).setCategory(LAYOUT); - - /** Synthesis actions */ - public static final DisplayedActionData COLLAPSE_ALL = DisplayedActionData.create(CollapseAllReactorsAction.ID, "Hide all Details"); - public static final DisplayedActionData EXPAND_ALL = DisplayedActionData.create(ExpandAllReactorsAction.ID, "Show all Details"); - - @Override - public List getDisplayedSynthesisOptions() { - return List.of( - SHOW_ALL_REACTORS, - MemorizingExpandCollapseAction.MEMORIZE_EXPANSION_STATES, - CYCLE_DETECTION, - APPEARANCE, - ModeDiagrams.MODES_CATEGORY, - ModeDiagrams.SHOW_TRANSITION_LABELS, - ModeDiagrams.INITIALLY_COLLAPSE_MODES, - SHOW_USER_LABELS, - SHOW_HYPERLINKS, - //LinguaFrancaSynthesisInterfaceDependencies.SHOW_INTERFACE_DEPENDENCIES, - REACTIONS_USE_HYPEREDGES, - USE_ALTERNATIVE_DASH_PATTERN, - SHOW_PORT_NAMES, - SHOW_MULTIPORT_WIDTH, - SHOW_REACTION_CODE, - SHOW_REACTION_LEVEL, - SHOW_REACTION_ORDER_EDGES, - SHOW_REACTOR_HOST, - SHOW_INSTANCE_NAMES, - REACTOR_PARAMETER_MODE, - SHOW_STATE_VARIABLES, - REACTOR_BODY_TABLE_COLS, - LAYOUT, - LayoutPostProcessing.MODEL_ORDER, - SPACING - ); - } - - @Override - public List getDisplayedActions() { - return List.of(COLLAPSE_ALL, EXPAND_ALL); - } - - // ------------------------------------------------------------------------- - - @Override - public KNode transform(final Model model) { - KNode rootNode = _kNodeExtensions.createNode(); - setLayoutOption(rootNode, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); - setLayoutOption(rootNode, CoreOptions.DIRECTION, Direction.RIGHT); - setLayoutOption(rootNode, CoreOptions.PADDING, new ElkPadding(0)); - - try { - // Find main - Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated); - if (main != null) { - ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter()); - rootNode.getChildren().addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>())); - } else if (!getBooleanValue(SHOW_ALL_REACTORS)) { - KNode messageNode = _kNodeExtensions.createNode(); - _linguaFrancaShapeExtensions.addErrorMessage(messageNode, TEXT_NO_MAIN_REACTOR, null); - rootNode.getChildren().add(messageNode); - } - - // Show all reactors - if (main == null || getBooleanValue(SHOW_ALL_REACTORS)) { - List reactorNodes = new ArrayList<>(); - for (Reactor reactor : model.getReactors()) { - if (reactor == main) continue; - ReactorInstance reactorInstance = new ReactorInstance(reactor, new SynthesisErrorReporter()); - reactorNodes.addAll(createReactorNode(reactorInstance, main == null, - HashBasedTable.create(), - HashBasedTable.create(), - new HashMap<>())); - } - if (!reactorNodes.isEmpty()) { - // To allow ordering, we need box layout but we also need layered layout for ports thus wrap all node - reactorNodes.add(0, IterableExtensions.head(rootNode.getChildren())); - - int index = 0; - for (KNode node : reactorNodes) { - // Element could be null if there is no main reactor and Show All Reactors is checked. - if (node == null) continue; - if (node.getProperty(CoreOptions.COMMENT_BOX)) continue; - KNode child = _kNodeExtensions.createNode(); - child.getChildren().add(node); - // Add comment nodes - for (KEdge edge : node.getIncomingEdges()) { - if (!edge.getSource().getProperty(CoreOptions.COMMENT_BOX)) continue; - child.getChildren().add(edge.getSource()); - } - _kRenderingExtensions.addInvisibleContainerRendering(child); - setLayoutOption(child, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); - setLayoutOption(child, CoreOptions.DIRECTION, Direction.RIGHT); - setLayoutOption(child, CoreOptions.PADDING, new ElkPadding(0)); - // Legacy ordering option. - setLayoutOption(child, CoreOptions.PRIORITY, reactorNodes.size() - index); // Order! - rootNode.getChildren().add(child); - index++; - } - - setLayoutOption(rootNode, CoreOptions.ALGORITHM, BoxLayouterOptions.ALGORITHM_ID); - setLayoutOption(rootNode, CoreOptions.SPACING_NODE_NODE, 25.0); - } + @Inject @Extension private KNodeExtensions _kNodeExtensions; + @Inject @Extension private KEdgeExtensions _kEdgeExtensions; + @Inject @Extension private KPortExtensions _kPortExtensions; + @Inject @Extension private KLabelExtensions _kLabelExtensions; + @Inject @Extension private KRenderingExtensions _kRenderingExtensions; + @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; + @Inject @Extension private KPolylineExtensions _kPolylineExtensions; + @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; + @Inject @Extension private LinguaFrancaShapeExtensions _linguaFrancaShapeExtensions; + @Inject @Extension private UtilityExtensions _utilityExtensions; + @Inject @Extension private CycleVisualization _cycleVisualization; + @Inject @Extension private InterfaceDependenciesVisualization _interfaceDependenciesVisualization; + @Inject @Extension private FilterCycleAction _filterCycleAction; + @Inject @Extension private ReactorIcons _reactorIcons; + @Inject @Extension private ModeDiagrams _modeDiagrams; + @Inject @Extension private LayoutPostProcessing _layoutPostProcessing; + + // ------------------------------------------------------------------------- + + public static final String ID = "org.lflang.diagram.synthesis.LinguaFrancaSynthesis"; + + // -- INTERNAL -- + public static final Property REACTOR_RECURSIVE_INSTANTIATION = + new Property<>( + "org.lflang.linguafranca.diagram.synthesis.reactor.recursive.instantiation", false); + public static final Property REACTOR_HAS_BANK_PORT_OFFSET = + new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.bank.offset", false); + public static final Property REACTOR_INPUT = + new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.input", false); + public static final Property REACTOR_OUTPUT = + new Property<>("org.lflang.linguafranca.diagram.synthesis.reactor.output", false); + public static final Property REACTION_SPECIAL_TRIGGER = + new Property<>("org.lflang.linguafranca.diagram.synthesis.reaction.special.trigger", false); + + // -- STYLE -- + public static final List ALTERNATIVE_DASH_PATTERN = List.of(3.0f); + + // -- TEXT -- + public static final String TEXT_ERROR_RECURSIVE = "Recursive reactor instantiation!"; + public static final String TEXT_ERROR_CONTAINS_RECURSION = + "Reactor contains recursive instantiation!"; + public static final String TEXT_ERROR_CONTAINS_CYCLE = "Reactor contains cyclic dependencies!"; + public static final String TEXT_ERROR_CYCLE_DETECTION = + "Dependency cycle detection failed.\n" + + "Could not detect dependency cycles due to unexpected graph structure."; + public static final String TEXT_ERROR_CYCLE_BTN_SHOW = "Show Cycle"; + public static final String TEXT_ERROR_CYCLE_BTN_FILTER = "Filter Cycle"; + public static final String TEXT_ERROR_CYCLE_BTN_UNFILTER = "Remove Cycle Filter"; + public static final String TEXT_NO_MAIN_REACTOR = "No Main Reactor"; + public static final String TEXT_REACTOR_NULL = "Reactor is null"; + public static final String TEXT_HIDE_ACTION = "[Hide]"; + public static final String TEXT_SHOW_ACTION = "[Details]"; + + // ------------------------------------------------------------------------- + + /** Synthesis category */ + public static final SynthesisOption APPEARANCE = + SynthesisOption.createCategory("Appearance", true); + + public static final SynthesisOption EXPERIMENTAL = + SynthesisOption.createCategory("Experimental", true); + public static final SynthesisOption LAYOUT = + SynthesisOption.createCategory("Layout", false).setCategory(LinguaFrancaSynthesis.APPEARANCE); + + /** Synthesis options */ + public static final SynthesisOption SHOW_ALL_REACTORS = + SynthesisOption.createCheckOption("All Reactors", false); + + public static final SynthesisOption CYCLE_DETECTION = + SynthesisOption.createCheckOption("Dependency Cycle Detection", true); + + public static final SynthesisOption SHOW_USER_LABELS = + SynthesisOption.createCheckOption("User Labels (@label in JavaDoc)", true) + .setCategory(APPEARANCE); + public static final SynthesisOption SHOW_HYPERLINKS = + SynthesisOption.createCheckOption("Expand/Collapse Hyperlinks", false) + .setCategory(APPEARANCE); + public static final SynthesisOption REACTIONS_USE_HYPEREDGES = + SynthesisOption.createCheckOption("Bundled Dependencies", false).setCategory(APPEARANCE); + public static final SynthesisOption USE_ALTERNATIVE_DASH_PATTERN = + SynthesisOption.createCheckOption("Alternative Dependency Line Style", false) + .setCategory(APPEARANCE); + public static final SynthesisOption SHOW_PORT_NAMES = + SynthesisOption.createCheckOption("Port names", true).setCategory(APPEARANCE); + public static final SynthesisOption SHOW_MULTIPORT_WIDTH = + SynthesisOption.createCheckOption("Multiport Widths", false).setCategory(APPEARANCE); + public static final SynthesisOption SHOW_REACTION_CODE = + SynthesisOption.createCheckOption("Reaction Code", false).setCategory(APPEARANCE); + public static final SynthesisOption SHOW_REACTION_LEVEL = + SynthesisOption.createCheckOption("Reaction Level", false).setCategory(APPEARANCE); + public static final SynthesisOption SHOW_REACTION_ORDER_EDGES = + SynthesisOption.createCheckOption("Reaction Order Edges", false).setCategory(APPEARANCE); + public static final SynthesisOption SHOW_REACTOR_HOST = + SynthesisOption.createCheckOption("Reactor Host Addresses", true).setCategory(APPEARANCE); + public static final SynthesisOption SHOW_INSTANCE_NAMES = + SynthesisOption.createCheckOption("Reactor Instance Names", false).setCategory(APPEARANCE); + public static final SynthesisOption REACTOR_PARAMETER_MODE = + SynthesisOption.createChoiceOption( + "Reactor Parameters", + ((List) Conversions.doWrapArray(ReactorParameterDisplayModes.values())), + ReactorParameterDisplayModes.NONE) + .setCategory(APPEARANCE); + public static final SynthesisOption SHOW_STATE_VARIABLES = + SynthesisOption.createCheckOption("Reactor State Variables", false).setCategory(APPEARANCE); + public static final SynthesisOption REACTOR_BODY_TABLE_COLS = + SynthesisOption.createRangeOption("Reactor Parameter/Variable Columns", 1, 10, 1) + .setCategory(APPEARANCE); + + public static final SynthesisOption SPACING = + SynthesisOption.createRangeOption("Spacing (%)", 0, 150, 5, 75).setCategory(LAYOUT); + + /** Synthesis actions */ + public static final DisplayedActionData COLLAPSE_ALL = + DisplayedActionData.create(CollapseAllReactorsAction.ID, "Hide all Details"); + + public static final DisplayedActionData EXPAND_ALL = + DisplayedActionData.create(ExpandAllReactorsAction.ID, "Show all Details"); + + @Override + public List getDisplayedSynthesisOptions() { + return List.of( + SHOW_ALL_REACTORS, + MemorizingExpandCollapseAction.MEMORIZE_EXPANSION_STATES, + CYCLE_DETECTION, + APPEARANCE, + ModeDiagrams.MODES_CATEGORY, + ModeDiagrams.SHOW_TRANSITION_LABELS, + ModeDiagrams.INITIALLY_COLLAPSE_MODES, + SHOW_USER_LABELS, + SHOW_HYPERLINKS, + // LinguaFrancaSynthesisInterfaceDependencies.SHOW_INTERFACE_DEPENDENCIES, + REACTIONS_USE_HYPEREDGES, + USE_ALTERNATIVE_DASH_PATTERN, + SHOW_PORT_NAMES, + SHOW_MULTIPORT_WIDTH, + SHOW_REACTION_CODE, + SHOW_REACTION_LEVEL, + SHOW_REACTION_ORDER_EDGES, + SHOW_REACTOR_HOST, + SHOW_INSTANCE_NAMES, + REACTOR_PARAMETER_MODE, + SHOW_STATE_VARIABLES, + REACTOR_BODY_TABLE_COLS, + LAYOUT, + LayoutPostProcessing.MODEL_ORDER, + SPACING); + } + + @Override + public List getDisplayedActions() { + return List.of(COLLAPSE_ALL, EXPAND_ALL); + } + + // ------------------------------------------------------------------------- + + @Override + public KNode transform(final Model model) { + KNode rootNode = _kNodeExtensions.createNode(); + setLayoutOption(rootNode, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); + setLayoutOption(rootNode, CoreOptions.DIRECTION, Direction.RIGHT); + setLayoutOption(rootNode, CoreOptions.PADDING, new ElkPadding(0)); + + try { + // Find main + Reactor main = + IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated); + if (main != null) { + ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter()); + rootNode + .getChildren() + .addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>())); + } else if (!getBooleanValue(SHOW_ALL_REACTORS)) { + KNode messageNode = _kNodeExtensions.createNode(); + _linguaFrancaShapeExtensions.addErrorMessage(messageNode, TEXT_NO_MAIN_REACTOR, null); + rootNode.getChildren().add(messageNode); + } + + // Show all reactors + if (main == null || getBooleanValue(SHOW_ALL_REACTORS)) { + List reactorNodes = new ArrayList<>(); + for (Reactor reactor : model.getReactors()) { + if (reactor == main) continue; + ReactorInstance reactorInstance = + new ReactorInstance(reactor, new SynthesisErrorReporter()); + reactorNodes.addAll( + createReactorNode( + reactorInstance, + main == null, + HashBasedTable.create(), + HashBasedTable.create(), + new HashMap<>())); + } + if (!reactorNodes.isEmpty()) { + // To allow ordering, we need box layout but we also need layered layout for ports thus + // wrap all node + reactorNodes.add(0, IterableExtensions.head(rootNode.getChildren())); + + int index = 0; + for (KNode node : reactorNodes) { + // Element could be null if there is no main reactor and Show All Reactors is checked. + if (node == null) continue; + if (node.getProperty(CoreOptions.COMMENT_BOX)) continue; + KNode child = _kNodeExtensions.createNode(); + child.getChildren().add(node); + // Add comment nodes + for (KEdge edge : node.getIncomingEdges()) { + if (!edge.getSource().getProperty(CoreOptions.COMMENT_BOX)) continue; + child.getChildren().add(edge.getSource()); } - } catch (Exception e) { - e.printStackTrace(); + _kRenderingExtensions.addInvisibleContainerRendering(child); + setLayoutOption(child, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); + setLayoutOption(child, CoreOptions.DIRECTION, Direction.RIGHT); + setLayoutOption(child, CoreOptions.PADDING, new ElkPadding(0)); + // Legacy ordering option. + setLayoutOption(child, CoreOptions.PRIORITY, reactorNodes.size() - index); // Order! + rootNode.getChildren().add(child); + index++; + } - KNode messageNode = _kNodeExtensions.createNode(); - _linguaFrancaShapeExtensions.addErrorMessage(messageNode, "Error in Diagram Synthesis", - e.getClass().getSimpleName() + " occurred. Could not create diagram."); - rootNode.getChildren().add(messageNode); + setLayoutOption(rootNode, CoreOptions.ALGORITHM, BoxLayouterOptions.ALGORITHM_ID); + setLayoutOption(rootNode, CoreOptions.SPACING_NODE_NODE, 25.0); } + } + } catch (Exception e) { + e.printStackTrace(); + + KNode messageNode = _kNodeExtensions.createNode(); + _linguaFrancaShapeExtensions.addErrorMessage( + messageNode, + "Error in Diagram Synthesis", + e.getClass().getSimpleName() + " occurred. Could not create diagram."); + rootNode.getChildren().add(messageNode); + } - return rootNode; + return rootNode; + } + + private Collection createReactorNode( + ReactorInstance reactorInstance, + boolean expandDefault, + Table inputPortsReg, + Table outputPortsReg, + Map allReactorNodes) { + Reactor reactor = reactorInstance.reactorDefinition; + KNode node = _kNodeExtensions.createNode(); + allReactorNodes.put(reactorInstance, node); + associateWith(node, reactor); + _utilityExtensions.setID(node, reactorInstance.uniqueID()); + // save to distinguish nodes associated with the same reactor + NamedInstanceUtil.linkInstance(node, reactorInstance); + + List nodes = new ArrayList<>(); + nodes.add(node); + String label = createReactorLabel(reactorInstance); + + if (reactorInstance.recursive) { + // Mark this node + node.setProperty(REACTOR_RECURSIVE_INSTANTIATION, true); + // Mark root + allReactorNodes + .get(reactorInstance.root()) + .setProperty(REACTOR_RECURSIVE_INSTANTIATION, true); } - private Collection createReactorNode( - ReactorInstance reactorInstance, - boolean expandDefault, - Table inputPortsReg, - Table outputPortsReg, - Map allReactorNodes - ) { - Reactor reactor = reactorInstance.reactorDefinition; - KNode node = _kNodeExtensions.createNode(); - allReactorNodes.put(reactorInstance, node); - associateWith(node, reactor); - _utilityExtensions.setID(node, reactorInstance.uniqueID()); - // save to distinguish nodes associated with the same reactor - NamedInstanceUtil.linkInstance(node, reactorInstance); - - List nodes = new ArrayList<>(); - nodes.add(node); - String label = createReactorLabel(reactorInstance); - - if (reactorInstance.recursive) { - // Mark this node - node.setProperty(REACTOR_RECURSIVE_INSTANTIATION, true); - // Mark root - allReactorNodes.get(reactorInstance.root()).setProperty(REACTOR_RECURSIVE_INSTANTIATION, true); + if (reactor == null) { + _linguaFrancaShapeExtensions.addErrorMessage(node, TEXT_REACTOR_NULL, null); + } else if (reactorInstance.isMainOrFederated()) { + KRoundedRectangle figure = + _linguaFrancaShapeExtensions.addMainReactorFigure(node, reactorInstance, label); + + if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE + && !reactorInstance.parameters.isEmpty()) { + KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(figure); + _kRenderingExtensions.setInvisible(rectangle, true); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); + _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); + addParameterList(rectangle, reactorInstance.parameters); + } + + if (getBooleanValue(SHOW_STATE_VARIABLES)) { + var variables = + ASTUtils.collectElements( + reactor, LfPackage.eINSTANCE.getReactor_StateVars(), true, false); + if (!variables.isEmpty()) { + KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(figure); + _kRenderingExtensions.setInvisible(rectangle, true); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); + _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); + addStateVariableList(rectangle, variables); } - - if (reactor == null) { - _linguaFrancaShapeExtensions.addErrorMessage(node, TEXT_REACTOR_NULL, null); - } else if (reactorInstance.isMainOrFederated()) { - KRoundedRectangle figure = _linguaFrancaShapeExtensions.addMainReactorFigure(node, reactorInstance, label); - - if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE - && !reactorInstance.parameters.isEmpty() - ) { - KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(figure); - _kRenderingExtensions.setInvisible(rectangle, true); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); - addParameterList(rectangle, reactorInstance.parameters); - } - - if (getBooleanValue(SHOW_STATE_VARIABLES)) { - var variables = ASTUtils.collectElements(reactor, LfPackage.eINSTANCE.getReactor_StateVars(), true, false); - if (!variables.isEmpty()) { - KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(figure); - _kRenderingExtensions.setInvisible(rectangle, true); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); - addStateVariableList(rectangle, variables); - } - } - - if (reactorInstance.recursive) { - nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE)); - _linguaFrancaStyleExtensions.errorStyle(figure); - } else { - _kContainerRenderingExtensions.addChildArea(figure); - node.getChildren().addAll(transformReactorNetwork(reactorInstance, - new HashMap<>(), - new HashMap<>(), - allReactorNodes)); - } - Iterables.addAll(nodes, createUserComments(reactor, node)); - configureReactorNodeLayout(node, true); - _layoutPostProcessing.configureMainReactor(node); + } + + if (reactorInstance.recursive) { + nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE)); + _linguaFrancaStyleExtensions.errorStyle(figure); + } else { + _kContainerRenderingExtensions.addChildArea(figure); + node.getChildren() + .addAll( + transformReactorNetwork( + reactorInstance, new HashMap<>(), new HashMap<>(), allReactorNodes)); + } + Iterables.addAll(nodes, createUserComments(reactor, node)); + configureReactorNodeLayout(node, true); + _layoutPostProcessing.configureMainReactor(node); + } else { + ReactorInstance instance = reactorInstance; + + // Expanded Rectangle + ReactorFigureComponents comps = + _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label); + comps.getOuter().setProperty(KlighdProperties.EXPANDED_RENDERING, true); + for (KRendering figure : comps.getFigures()) { + associateWith(figure, reactor); + _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID); + } + _reactorIcons.handleIcon(comps.getReactor(), reactor, false); + + if (getBooleanValue(SHOW_HYPERLINKS)) { + // Collapse button + KText button = + _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_HIDE_ACTION); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(button), + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); + _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID); + _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID); + } + + if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE + && !instance.parameters.isEmpty()) { + KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(comps.getReactor()); + _kRenderingExtensions.setInvisible(rectangle, true); + if (!getBooleanValue(SHOW_HYPERLINKS)) { + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); } else { - ReactorInstance instance = reactorInstance; - - // Expanded Rectangle - ReactorFigureComponents comps = _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label); - comps.getOuter().setProperty(KlighdProperties.EXPANDED_RENDERING, true); - for (KRendering figure : comps.getFigures()) { - associateWith(figure, reactor); - _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID); - } - _reactorIcons.handleIcon(comps.getReactor(), reactor, false); - - if (getBooleanValue(SHOW_HYPERLINKS)) { - // Collapse button - KText button = _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_HIDE_ACTION); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(button), - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 8, 0, - _kRenderingExtensions.BOTTOM, 0, 0); - _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID); - _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID); - } - - if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE - && !instance.parameters.isEmpty()) { - KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(comps.getReactor()); - _kRenderingExtensions.setInvisible(rectangle, true); - if (!getBooleanValue(SHOW_HYPERLINKS)) { - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - } else { - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 4, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 0, 0); - } - _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); - addParameterList(rectangle, instance.parameters); - } - - if (getBooleanValue(SHOW_STATE_VARIABLES)) { - var variables = ASTUtils.collectElements(reactor, LfPackage.eINSTANCE.getReactor_StateVars(), true, false); - if (!variables.isEmpty()) { - KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(comps.getReactor()); - _kRenderingExtensions.setInvisible(rectangle, true); - if (!getBooleanValue(SHOW_HYPERLINKS)) { - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - } else { - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 4, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 0, 0); - } - _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); - addStateVariableList(rectangle, variables); - } - } - - if (instance.recursive) { - comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle); - } else { - _kContainerRenderingExtensions.addChildArea(comps.getReactor()); - } - - // Collapse Rectangle - comps = _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label); - comps.getOuter().setProperty(KlighdProperties.COLLAPSED_RENDERING, true); - for (KRendering figure : comps.getFigures()) { - associateWith(figure, reactor); - if (_utilityExtensions.hasContent(instance) && !instance.recursive) { - _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID); - } - } - _reactorIcons.handleIcon(comps.getReactor(), reactor, true); - - if (getBooleanValue(SHOW_HYPERLINKS)) { - // Expand button - if (_utilityExtensions.hasContent(instance) && !instance.recursive) { - KText button = _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_SHOW_ACTION); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(button), - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 8, 0, - _kRenderingExtensions.BOTTOM, 8, 0); - _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID); - _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID); - } - } - - if (instance.recursive) { - comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle); - } - - - // Create ports - Map inputPorts = new HashMap<>(); - Map outputPorts = new HashMap<>(); - List inputs = instance.inputs; - if (LayoutPostProcessing.LEGACY.equals((String) getObjectValue(LayoutPostProcessing.MODEL_ORDER))) { - inputs = ListExtensions.reverseView(instance.inputs); - } - for (PortInstance input : inputs) { - inputPorts.put(input, addIOPort(node, input, true, input.isMultiport(), reactorInstance.isBank())); - } - for (PortInstance output : instance.outputs) { - outputPorts.put(output, addIOPort(node, output, false, output.isMultiport(), reactorInstance.isBank())); - } - // Mark ports - inputPorts.values().forEach(it -> it.setProperty(REACTOR_INPUT, true)); - outputPorts.values().forEach(it -> it.setProperty(REACTOR_OUTPUT, true)); - - // Add content - if (_utilityExtensions.hasContent(instance) && !instance.recursive) { - node.getChildren().addAll(transformReactorNetwork(instance, inputPorts, outputPorts, allReactorNodes)); - } - - // Pass port to given tables - if (!_utilityExtensions.isRoot(instance)) { - if (inputPortsReg != null) { - for (Map.Entry entry : inputPorts.entrySet()) { - inputPortsReg.put(instance, entry.getKey(), entry.getValue()); - } - } - if (outputPortsReg != null) { - for (Map.Entry entry : outputPorts.entrySet()) { - outputPortsReg.put(instance, entry.getKey(), entry.getValue()); - } - } - } - - if (instance.recursive) { - setLayoutOption(node, KlighdProperties.EXPAND, false); - nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE)); - } else { - setLayoutOption(node, KlighdProperties.EXPAND, expandDefault); - - // Interface Dependencies - _interfaceDependenciesVisualization.addInterfaceDependencies(node, expandDefault); - } - - if (!_utilityExtensions.isRoot(instance)) { - // If all reactors are being shown, then only put the label on - // the reactor definition, not on its instances. Otherwise, - // add the annotation now. - if (!getBooleanValue(SHOW_ALL_REACTORS)) { - Iterables.addAll(nodes, createUserComments(reactor, node)); - } - } else { - Iterables.addAll(nodes, createUserComments(reactor, node)); - } - configureReactorNodeLayout(node, false); - _layoutPostProcessing.configureReactor(node); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 4, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); } - - // Find and annotate cycles - if (getBooleanValue(CYCLE_DETECTION) && - _utilityExtensions.isRoot(reactorInstance)) { - KNode errNode = detectAndAnnotateCycles(node, reactorInstance, allReactorNodes); - if (errNode != null) { - nodes.add(errNode); - } + _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); + addParameterList(rectangle, instance.parameters); + } + + if (getBooleanValue(SHOW_STATE_VARIABLES)) { + var variables = + ASTUtils.collectElements( + reactor, LfPackage.eINSTANCE.getReactor_StateVars(), true, false); + if (!variables.isEmpty()) { + KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(comps.getReactor()); + _kRenderingExtensions.setInvisible(rectangle, true); + if (!getBooleanValue(SHOW_HYPERLINKS)) { + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); + } else { + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 4, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); + } + _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); + addStateVariableList(rectangle, variables); } - - return nodes; - } - - public KNode configureReactorNodeLayout(KNode node, boolean main) { - // Set layered algorithm - setLayoutOption(node, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); - // Left to right layout - setLayoutOption(node, CoreOptions.DIRECTION, Direction.RIGHT); - // Center free floating children - setLayoutOption(node, CoreOptions.CONTENT_ALIGNMENT, ContentAlignment.centerCenter()); - - // Balanced placement with straight long edges. - setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.NETWORK_SIMPLEX); - // Do not shrink nodes below content - setLayoutOption(node, CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.PORTS)); - - // Allows to freely shuffle ports on each side - setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); - // Adjust port label spacing to be closer to edge but not overlap with port figure - // TODO: Add PortLabelPlacement.NEXT_TO_PORT_IF_POSSIBLE back into the configuration, as soon as ELK provides a fix for LF issue #1273 - setLayoutOption(node, CoreOptions.PORT_LABELS_PLACEMENT, EnumSet.of(PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE)); - setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_HORIZONTAL, 2.0); - setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_VERTICAL, -3.0); - - // Configure spacing - if (!getBooleanValue(SHOW_HYPERLINKS)) { // Hyperlink version is more relaxed in terms of space - var factor = (double) getIntValue(SPACING) / 100; - - setLayoutOption(node, LayeredOptions.SPACING_COMPONENT_COMPONENT, LayeredOptions.SPACING_COMPONENT_COMPONENT.getDefault() * factor); - - setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE, LayeredOptions.SPACING_NODE_NODE.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS.getDefault() * factor); - - setLayoutOption(node, LayeredOptions.SPACING_PORT_PORT, LayeredOptions.SPACING_PORT_PORT.getDefault() * factor); - - setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE, LayeredOptions.SPACING_EDGE_NODE.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE, LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE, LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor); - setLayoutOption(node, LayeredOptions.SPACING_EDGE_LABEL, LayeredOptions.SPACING_EDGE_LABEL.getDefault() * factor); - - // Padding for sub graph - if (main) { // Special handing for main reactors - setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(-1, 6, 6, 6)); - } else { - setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(2, 6, 6, 6)); - } + } + + if (instance.recursive) { + comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle); + } else { + _kContainerRenderingExtensions.addChildArea(comps.getReactor()); + } + + // Collapse Rectangle + comps = _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label); + comps.getOuter().setProperty(KlighdProperties.COLLAPSED_RENDERING, true); + for (KRendering figure : comps.getFigures()) { + associateWith(figure, reactor); + if (_utilityExtensions.hasContent(instance) && !instance.recursive) { + _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID); } - - return node; - } - - private KNode detectAndAnnotateCycles(KNode node, ReactorInstance reactorInstance, Map allReactorNodes) { - if (node.getProperty(REACTOR_RECURSIVE_INSTANTIATION)) { - _filterCycleAction.resetCycleFiltering(node); - return addErrorComment(node, TEXT_ERROR_CONTAINS_RECURSION); - } else { // only detect dependency cycles if not recursive - try { - boolean hasCycle = _cycleVisualization.detectAndHighlightCycles(reactorInstance, - allReactorNodes, it -> { - if (it instanceof KNode) { - List renderings = IterableExtensions.toList( - Iterables.filter(((KNode) it).getData(), KRendering.class)); - if (renderings.size() == 1) { - _linguaFrancaStyleExtensions.errorStyle(IterableExtensions.head(renderings)); - } else { - IterableExtensions.filter(renderings, rendering -> { - return rendering.getProperty(KlighdProperties.COLLAPSED_RENDERING); - }).forEach(_linguaFrancaStyleExtensions::errorStyle); - } - } else if (it instanceof KEdge) { - Iterables.filter(((KEdge) it).getData(), - KRendering.class).forEach(_linguaFrancaStyleExtensions::errorStyle); - // TODO initiallyHide does not work with incremental (https://github.com/kieler/KLighD/issues/37) - // cycleEgde.initiallyShow() // Show hidden order dependencies - _kRenderingExtensions.setInvisible(_kRenderingExtensions.getKRendering(it), false); - } else if (it instanceof KPort) { - Iterables.filter(((KPort) it).getData(), - KRendering.class).forEach(_linguaFrancaStyleExtensions::errorStyle); - //it.reverseTrianglePort() - } - }); - - if (hasCycle) { - KNode err = addErrorComment(node, TEXT_ERROR_CONTAINS_CYCLE); - - // Add to existing figure - KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(_kRenderingExtensions.getKContainerRendering(err)); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 3, 0, - _kRenderingExtensions.TOP, (-1), 0), - _kRenderingExtensions.RIGHT, 3, 0, - _kRenderingExtensions.BOTTOM, 3, 0); - _linguaFrancaStyleExtensions.noSelectionStyle(rectangle); - _kRenderingExtensions.setInvisible(rectangle, true); - _kContainerRenderingExtensions.setGridPlacement(rectangle, 2); - - KRectangle subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(subrectangle), - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 2, 0, - _kRenderingExtensions.BOTTOM, 0, 0); - _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle); - _kRenderingExtensions.addSingleClickAction(subrectangle, ShowCycleAction.ID); - - KText subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, TEXT_ERROR_CYCLE_BTN_SHOW); - // Copy text style - List styles = ListExtensions.map( - IterableExtensions.head( - _kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), - EcoreUtil::copy); - subrectangleText.getStyles().addAll(styles); - _kRenderingExtensions.setFontSize(subrectangleText, 5); - _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0); - _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText); - _kRenderingExtensions.addSingleClickAction(subrectangleText, ShowCycleAction.ID); - - subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle); - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(subrectangle), - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 0, 0, - _kRenderingExtensions.BOTTOM, 0, 0); - _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle); - _kRenderingExtensions.addSingleClickAction(subrectangle, FilterCycleAction.ID); - - subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, - _filterCycleAction.isCycleFiltered(node) ? - TEXT_ERROR_CYCLE_BTN_UNFILTER : TEXT_ERROR_CYCLE_BTN_FILTER); - // Copy text style - styles = ListExtensions.map( - IterableExtensions.head( - _kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), - EcoreUtil::copy); - subrectangleText.getStyles().addAll(styles); - _kRenderingExtensions.setFontSize(subrectangleText, 5); - _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0); - _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText); - _kRenderingExtensions.addSingleClickAction(subrectangleText, FilterCycleAction.ID); - _filterCycleAction.markCycleFilterText(subrectangleText, err); - - // if user interactively requested a filtered diagram keep it filtered during updates - if (_filterCycleAction.isCycleFiltered(node)) { - _filterCycleAction.filterCycle(node); - } - return err; - } - } catch(Exception e) { - _filterCycleAction.resetCycleFiltering(node); - e.printStackTrace(); - return addErrorComment(node, TEXT_ERROR_CYCLE_DETECTION); - } + } + _reactorIcons.handleIcon(comps.getReactor(), reactor, true); + + if (getBooleanValue(SHOW_HYPERLINKS)) { + // Expand button + if (_utilityExtensions.hasContent(instance) && !instance.recursive) { + KText button = + _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_SHOW_ACTION); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(button), + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 8, + 0); + _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID); + _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID); } - return null; - } - - private Collection transformReactorNetwork( - ReactorInstance reactorInstance, - Map parentInputPorts, - Map parentOutputPorts, - Map allReactorNodes - ) { - List nodes = new ArrayList<>(); - Table inputPorts = HashBasedTable.create(); - Table outputPorts = HashBasedTable.create(); - Map reactionNodes = new HashMap<>(); - Map directConnectionDummyNodes = new HashMap<>(); - Multimap actionDestinations = HashMultimap.create(); - Multimap actionSources = HashMultimap.create(); - Map timerNodes = new HashMap<>(); - KNode startupNode = _kNodeExtensions.createNode(); - TriggerInstance startup = null; - KNode shutdownNode = _kNodeExtensions.createNode(); - TriggerInstance shutdown = null; - KNode resetNode = _kNodeExtensions.createNode(); - TriggerInstance reset = null; - - // Transform instances - int index = 0; - for (ReactorInstance child : reactorInstance.children) { - Boolean expansionState = MemorizingExpandCollapseAction.getExpansionState(child); - Collection rNodes = createReactorNode( - child, - expansionState != null ? expansionState : false, - inputPorts, - outputPorts, - allReactorNodes); - nodes.addAll(rNodes); - index++; + } + + if (instance.recursive) { + comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle); + } + + // Create ports + Map inputPorts = new HashMap<>(); + Map outputPorts = new HashMap<>(); + List inputs = instance.inputs; + if (LayoutPostProcessing.LEGACY.equals( + (String) getObjectValue(LayoutPostProcessing.MODEL_ORDER))) { + inputs = ListExtensions.reverseView(instance.inputs); + } + for (PortInstance input : inputs) { + inputPorts.put( + input, addIOPort(node, input, true, input.isMultiport(), reactorInstance.isBank())); + } + for (PortInstance output : instance.outputs) { + outputPorts.put( + output, addIOPort(node, output, false, output.isMultiport(), reactorInstance.isBank())); + } + // Mark ports + inputPorts.values().forEach(it -> it.setProperty(REACTOR_INPUT, true)); + outputPorts.values().forEach(it -> it.setProperty(REACTOR_OUTPUT, true)); + + // Add content + if (_utilityExtensions.hasContent(instance) && !instance.recursive) { + node.getChildren() + .addAll(transformReactorNetwork(instance, inputPorts, outputPorts, allReactorNodes)); + } + + // Pass port to given tables + if (!_utilityExtensions.isRoot(instance)) { + if (inputPortsReg != null) { + for (Map.Entry entry : inputPorts.entrySet()) { + inputPortsReg.put(instance, entry.getKey(), entry.getValue()); + } } - - // Create timers - for (TimerInstance timer : reactorInstance.timers) { - KNode node = associateWith(_kNodeExtensions.createNode(), timer.getDefinition()); - NamedInstanceUtil.linkInstance(node, timer); - _utilityExtensions.setID(node, timer.uniqueID()); - nodes.add(node); - Iterables.addAll(nodes, createUserComments(timer.getDefinition(), node)); - timerNodes.put(timer, node); - _linguaFrancaShapeExtensions.addTimerFigure(node, timer); - _layoutPostProcessing.configureTimer(node); + if (outputPortsReg != null) { + for (Map.Entry entry : outputPorts.entrySet()) { + outputPortsReg.put(instance, entry.getKey(), entry.getValue()); + } } + } + + if (instance.recursive) { + setLayoutOption(node, KlighdProperties.EXPAND, false); + nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE)); + } else { + setLayoutOption(node, KlighdProperties.EXPAND, expandDefault); + + // Interface Dependencies + _interfaceDependenciesVisualization.addInterfaceDependencies(node, expandDefault); + } + + if (!_utilityExtensions.isRoot(instance)) { + // If all reactors are being shown, then only put the label on + // the reactor definition, not on its instances. Otherwise, + // add the annotation now. + if (!getBooleanValue(SHOW_ALL_REACTORS)) { + Iterables.addAll(nodes, createUserComments(reactor, node)); + } + } else { + Iterables.addAll(nodes, createUserComments(reactor, node)); + } + configureReactorNodeLayout(node, false); + _layoutPostProcessing.configureReactor(node); + } - // Create reactions - for (ReactionInstance reaction : reactorInstance.reactions) { - int idx = reactorInstance.reactions.indexOf(reaction); - KNode node = associateWith(_kNodeExtensions.createNode(), reaction.getDefinition()); - NamedInstanceUtil.linkInstance(node, reaction); - _utilityExtensions.setID(node, reaction.uniqueID()); - nodes.add(node); - Iterables.addAll(nodes, createUserComments(reaction.getDefinition(), node)); - reactionNodes.put(reaction, node); - - setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); - _layoutPostProcessing.configureReaction(node); - setLayoutOption(node, LayeredOptions.POSITION, new KVector(0, idx + 1)); // try order reactions vertically if in one layer (+1 to account for startup) - - var figure = _linguaFrancaShapeExtensions.addReactionFigure(node, reaction); - - int inputSize = Stream.concat(reaction.triggers.stream(), reaction.sources.stream()).collect(Collectors.toSet()).size(); - int outputSize = reaction.effects.size(); - if (!getBooleanValue(REACTIONS_USE_HYPEREDGES) && (inputSize > 1 || outputSize > 1)) { - // If this node will have more than one input/output port, the port positions must be adjusted to the - // pointy shape. However, this is only possible after the layout. - ReactionPortAdjustment.apply(node, figure); - } - - // connect input - KPort port = null; - for (TriggerInstance trigger : reaction.triggers) { - // Create new port if there is no previous one or each dependency should have its own one - if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { - port = addInvisiblePort(node); - setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); - - if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || inputSize == 1) { - // manual adjustment disabling automatic one - setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, - (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS); - } - } - - if (trigger.isStartup()) { - connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), - startupNode, - port); - startup = trigger; - } else if (trigger.isShutdown()) { - connect(createDelayEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), - shutdownNode, - port); - shutdown = trigger; - } else if (trigger.isReset()) { - connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), - resetNode, - port); - reset = trigger; - } else if (trigger instanceof ActionInstance) { - actionDestinations.put(((ActionInstance) trigger), port); - } else if (trigger instanceof PortInstance) { - KPort src = null; - PortInstance triggerAsPort = (PortInstance) trigger; - if (triggerAsPort.getParent() == reactorInstance) { - src = parentInputPorts.get(trigger); - } else { - src = outputPorts.get(triggerAsPort.getParent(), trigger); - } - if (src != null) { - connect(createDependencyEdge(triggerAsPort.getDefinition()), src, port); - } - } else if (trigger instanceof TimerInstance) { - KNode src = timerNodes.get(trigger); - if (src != null) { - connect(createDependencyEdge(trigger.getDefinition()), src, port); - } - } - } - - // connect dependencies - for (TriggerInstance dep : reaction.sources) { - if (reaction.triggers.contains(dep)) continue; // skip - - // Create new port if there is no previous one or each dependency should have its own one - if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { - port = addInvisiblePort(node); - setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); + // Find and annotate cycles + if (getBooleanValue(CYCLE_DETECTION) && _utilityExtensions.isRoot(reactorInstance)) { + KNode errNode = detectAndAnnotateCycles(node, reactorInstance, allReactorNodes); + if (errNode != null) { + nodes.add(errNode); + } + } - if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || inputSize == 1) { - // manual adjustment disabling automatic one - setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, - (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS); - } - } + return nodes; + } + + public KNode configureReactorNodeLayout(KNode node, boolean main) { + // Set layered algorithm + setLayoutOption(node, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID); + // Left to right layout + setLayoutOption(node, CoreOptions.DIRECTION, Direction.RIGHT); + // Center free floating children + setLayoutOption(node, CoreOptions.CONTENT_ALIGNMENT, ContentAlignment.centerCenter()); + + // Balanced placement with straight long edges. + setLayoutOption( + node, LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.NETWORK_SIMPLEX); + // Do not shrink nodes below content + setLayoutOption( + node, + CoreOptions.NODE_SIZE_CONSTRAINTS, + EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.PORTS)); + + // Allows to freely shuffle ports on each side + setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); + // Adjust port label spacing to be closer to edge but not overlap with port figure + // TODO: Add PortLabelPlacement.NEXT_TO_PORT_IF_POSSIBLE back into the configuration, as soon as + // ELK provides a fix for LF issue #1273 + setLayoutOption( + node, + CoreOptions.PORT_LABELS_PLACEMENT, + EnumSet.of(PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE)); + setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_HORIZONTAL, 2.0); + setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_VERTICAL, -3.0); + + // Configure spacing + if (!getBooleanValue(SHOW_HYPERLINKS)) { // Hyperlink version is more relaxed in terms of space + var factor = (double) getIntValue(SPACING) / 100; + + setLayoutOption( + node, + LayeredOptions.SPACING_COMPONENT_COMPONENT, + LayeredOptions.SPACING_COMPONENT_COMPONENT.getDefault() * factor); + + setLayoutOption( + node, + LayeredOptions.SPACING_NODE_NODE, + LayeredOptions.SPACING_NODE_NODE.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, + LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS.getDefault() * factor); + + setLayoutOption( + node, + LayeredOptions.SPACING_PORT_PORT, + LayeredOptions.SPACING_PORT_PORT.getDefault() * factor); + + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_NODE, + LayeredOptions.SPACING_EDGE_NODE.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, + LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_EDGE, + LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, + LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_EDGE, + LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, + LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor); + setLayoutOption( + node, + LayeredOptions.SPACING_EDGE_LABEL, + LayeredOptions.SPACING_EDGE_LABEL.getDefault() * factor); + + // Padding for sub graph + if (main) { // Special handing for main reactors + setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(-1, 6, 6, 6)); + } else { + setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(2, 6, 6, 6)); + } + } - if (dep instanceof PortInstance) { - KPort src = null; - PortInstance depAsPort = (PortInstance) dep; - if (dep.getParent() == reactorInstance) { - src = parentInputPorts.get(dep); + return node; + } + + private KNode detectAndAnnotateCycles( + KNode node, ReactorInstance reactorInstance, Map allReactorNodes) { + if (node.getProperty(REACTOR_RECURSIVE_INSTANTIATION)) { + _filterCycleAction.resetCycleFiltering(node); + return addErrorComment(node, TEXT_ERROR_CONTAINS_RECURSION); + } else { // only detect dependency cycles if not recursive + try { + boolean hasCycle = + _cycleVisualization.detectAndHighlightCycles( + reactorInstance, + allReactorNodes, + it -> { + if (it instanceof KNode) { + List renderings = + IterableExtensions.toList( + Iterables.filter(((KNode) it).getData(), KRendering.class)); + if (renderings.size() == 1) { + _linguaFrancaStyleExtensions.errorStyle(IterableExtensions.head(renderings)); } else { - src = outputPorts.get(depAsPort.getParent(), dep); + IterableExtensions.filter( + renderings, + rendering -> { + return rendering.getProperty(KlighdProperties.COLLAPSED_RENDERING); + }) + .forEach(_linguaFrancaStyleExtensions::errorStyle); } - if (src != null) { - connect(createDependencyEdge(dep.getDefinition()), src, port); - } - } - } - - // connect outputs - port = null; // enforce new ports for outputs - Set> iterSet = reaction.effects != null ? reaction.effects : new HashSet<>(); - for (TriggerInstance effect : iterSet) { - // Create new port if there is no previous one or each dependency should have its own one - if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { - port = addInvisiblePort(node); - setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST); - } + } else if (it instanceof KEdge) { + Iterables.filter(((KEdge) it).getData(), KRendering.class) + .forEach(_linguaFrancaStyleExtensions::errorStyle); + // TODO initiallyHide does not work with incremental + // (https://github.com/kieler/KLighD/issues/37) + // cycleEgde.initiallyShow() // Show hidden order dependencies + _kRenderingExtensions.setInvisible( + _kRenderingExtensions.getKRendering(it), false); + } else if (it instanceof KPort) { + Iterables.filter(((KPort) it).getData(), KRendering.class) + .forEach(_linguaFrancaStyleExtensions::errorStyle); + // it.reverseTrianglePort() + } + }); - if (effect instanceof ActionInstance) { - actionSources.put((ActionInstance) effect, port); - } else if (effect instanceof PortInstance) { - KPort dst = null; - PortInstance effectAsPort = (PortInstance) effect; - if (effectAsPort.isOutput()) { - dst = parentOutputPorts.get(effect); - } else { - dst = inputPorts.get(effectAsPort.getParent(), effect); - } - if (dst != null) { - connect(createDependencyEdge(effect), port, dst); - } - } - } + if (hasCycle) { + KNode err = addErrorComment(node, TEXT_ERROR_CONTAINS_CYCLE); + + // Add to existing figure + KRectangle rectangle = + _kContainerRenderingExtensions.addRectangle( + _kRenderingExtensions.getKContainerRendering(err)); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 3, + 0, + _kRenderingExtensions.TOP, + (-1), + 0), + _kRenderingExtensions.RIGHT, + 3, + 0, + _kRenderingExtensions.BOTTOM, + 3, + 0); + _linguaFrancaStyleExtensions.noSelectionStyle(rectangle); + _kRenderingExtensions.setInvisible(rectangle, true); + _kContainerRenderingExtensions.setGridPlacement(rectangle, 2); + + KRectangle subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(subrectangle), + _kRenderingExtensions.LEFT, + 0, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 2, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); + _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle); + _kRenderingExtensions.addSingleClickAction(subrectangle, ShowCycleAction.ID); + + KText subrectangleText = + _kContainerRenderingExtensions.addText(subrectangle, TEXT_ERROR_CYCLE_BTN_SHOW); + // Copy text style + List styles = + ListExtensions.map( + IterableExtensions.head( + _kRenderingExtensions.getKContainerRendering(err).getChildren()) + .getStyles(), + EcoreUtil::copy); + subrectangleText.getStyles().addAll(styles); + _kRenderingExtensions.setFontSize(subrectangleText, 5); + _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0); + _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText); + _kRenderingExtensions.addSingleClickAction(subrectangleText, ShowCycleAction.ID); + + subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(subrectangle), + _kRenderingExtensions.LEFT, + 0, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 0, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); + _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle); + _kRenderingExtensions.addSingleClickAction(subrectangle, FilterCycleAction.ID); + + subrectangleText = + _kContainerRenderingExtensions.addText( + subrectangle, + _filterCycleAction.isCycleFiltered(node) + ? TEXT_ERROR_CYCLE_BTN_UNFILTER + : TEXT_ERROR_CYCLE_BTN_FILTER); + // Copy text style + styles = + ListExtensions.map( + IterableExtensions.head( + _kRenderingExtensions.getKContainerRendering(err).getChildren()) + .getStyles(), + EcoreUtil::copy); + subrectangleText.getStyles().addAll(styles); + _kRenderingExtensions.setFontSize(subrectangleText, 5); + _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0); + _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText); + _kRenderingExtensions.addSingleClickAction(subrectangleText, FilterCycleAction.ID); + _filterCycleAction.markCycleFilterText(subrectangleText, err); + + // if user interactively requested a filtered diagram keep it filtered during updates + if (_filterCycleAction.isCycleFiltered(node)) { + _filterCycleAction.filterCycle(node); + } + return err; } + } catch (Exception e) { + _filterCycleAction.resetCycleFiltering(node); + e.printStackTrace(); + return addErrorComment(node, TEXT_ERROR_CYCLE_DETECTION); + } + } + return null; + } + + private Collection transformReactorNetwork( + ReactorInstance reactorInstance, + Map parentInputPorts, + Map parentOutputPorts, + Map allReactorNodes) { + List nodes = new ArrayList<>(); + Table inputPorts = HashBasedTable.create(); + Table outputPorts = HashBasedTable.create(); + Map reactionNodes = new HashMap<>(); + Map directConnectionDummyNodes = new HashMap<>(); + Multimap actionDestinations = HashMultimap.create(); + Multimap actionSources = HashMultimap.create(); + Map timerNodes = new HashMap<>(); + KNode startupNode = _kNodeExtensions.createNode(); + TriggerInstance startup = null; + KNode shutdownNode = _kNodeExtensions.createNode(); + TriggerInstance shutdown = null; + KNode resetNode = _kNodeExtensions.createNode(); + TriggerInstance reset = null; + + // Transform instances + int index = 0; + for (ReactorInstance child : reactorInstance.children) { + Boolean expansionState = MemorizingExpandCollapseAction.getExpansionState(child); + Collection rNodes = + createReactorNode( + child, + expansionState != null ? expansionState : false, + inputPorts, + outputPorts, + allReactorNodes); + nodes.addAll(rNodes); + index++; + } - // Connect actions - Set actions = new HashSet<>(); - actions.addAll(actionSources.keySet()); - actions.addAll(actionDestinations.keySet()); - - for (ActionInstance action : actions) { - KNode node = associateWith(_kNodeExtensions.createNode(), action.getDefinition()); - NamedInstanceUtil.linkInstance(node, action); - _utilityExtensions.setID(node, action.uniqueID()); - nodes.add(node); - Iterables.addAll(nodes, createUserComments(action.getDefinition(), node)); - setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); - _layoutPostProcessing.configureAction(node); - Pair ports = _linguaFrancaShapeExtensions.addActionFigureAndPorts( - node, - action.isPhysical() ? "P" : "L"); - // TODO handle variables? - if (action.getMinDelay() != null && action.getMinDelay() != ActionInstance.DEFAULT_MIN_DELAY) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel( - node, - String.format("min delay: %s", action.getMinDelay().toString()), - 7); - } - // TODO default value? - if (action.getDefinition().getMinSpacing() != null) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, - String.format("min spacing: %s", action.getMinSpacing().toString()), - 7); - } - if (!StringExtensions.isNullOrEmpty(action.getDefinition().getPolicy())) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, - String.format("policy: %s", action.getPolicy().toString()), - 7); - } - // connect source - for (KPort source : actionSources.get(action)) { - connect(createDelayEdge(action), source, ports.getKey()); - } + // Create timers + for (TimerInstance timer : reactorInstance.timers) { + KNode node = associateWith(_kNodeExtensions.createNode(), timer.getDefinition()); + NamedInstanceUtil.linkInstance(node, timer); + _utilityExtensions.setID(node, timer.uniqueID()); + nodes.add(node); + Iterables.addAll(nodes, createUserComments(timer.getDefinition(), node)); + timerNodes.put(timer, node); + _linguaFrancaShapeExtensions.addTimerFigure(node, timer); + _layoutPostProcessing.configureTimer(node); + } - // connect targets - for (KPort target : actionDestinations.get(action)) { - connect(createDelayEdge(action), ports.getValue(), target); - } + // Create reactions + for (ReactionInstance reaction : reactorInstance.reactions) { + int idx = reactorInstance.reactions.indexOf(reaction); + KNode node = associateWith(_kNodeExtensions.createNode(), reaction.getDefinition()); + NamedInstanceUtil.linkInstance(node, reaction); + _utilityExtensions.setID(node, reaction.uniqueID()); + nodes.add(node); + Iterables.addAll(nodes, createUserComments(reaction.getDefinition(), node)); + reactionNodes.put(reaction, node); + + setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); + _layoutPostProcessing.configureReaction(node); + setLayoutOption( + node, + LayeredOptions.POSITION, + new KVector( + 0, idx + 1)); // try order reactions vertically if in one layer (+1 to account for + // startup) + + var figure = _linguaFrancaShapeExtensions.addReactionFigure(node, reaction); + + int inputSize = + Stream.concat(reaction.triggers.stream(), reaction.sources.stream()) + .collect(Collectors.toSet()) + .size(); + int outputSize = reaction.effects.size(); + if (!getBooleanValue(REACTIONS_USE_HYPEREDGES) && (inputSize > 1 || outputSize > 1)) { + // If this node will have more than one input/output port, the port positions must be + // adjusted to the + // pointy shape. However, this is only possible after the layout. + ReactionPortAdjustment.apply(node, figure); + } + + // connect input + KPort port = null; + for (TriggerInstance trigger : reaction.triggers) { + // Create new port if there is no previous one or each dependency should have its own one + if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { + port = addInvisiblePort(node); + setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); + + if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || inputSize == 1) { + // manual adjustment disabling automatic one + setLayoutOption( + port, + CoreOptions.PORT_BORDER_OFFSET, + (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS); + } } - // Transform connections. - // First, collect all the source ports. - List sourcePorts = new LinkedList<>(reactorInstance.inputs); - for (ReactorInstance child : reactorInstance.children) { - sourcePorts.addAll(child.outputs); + if (trigger.isStartup()) { + connect( + createDependencyEdge( + ((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), + startupNode, + port); + startup = trigger; + } else if (trigger.isShutdown()) { + connect( + createDelayEdge( + ((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), + shutdownNode, + port); + shutdown = trigger; + } else if (trigger.isReset()) { + connect( + createDependencyEdge( + ((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), + resetNode, + port); + reset = trigger; + } else if (trigger instanceof ActionInstance) { + actionDestinations.put(((ActionInstance) trigger), port); + } else if (trigger instanceof PortInstance) { + KPort src = null; + PortInstance triggerAsPort = (PortInstance) trigger; + if (triggerAsPort.getParent() == reactorInstance) { + src = parentInputPorts.get(trigger); + } else { + src = outputPorts.get(triggerAsPort.getParent(), trigger); + } + if (src != null) { + connect(createDependencyEdge(triggerAsPort.getDefinition()), src, port); + } + } else if (trigger instanceof TimerInstance) { + KNode src = timerNodes.get(trigger); + if (src != null) { + connect(createDependencyEdge(trigger.getDefinition()), src, port); + } } - - for (PortInstance leftPort : sourcePorts) { - KPort source = leftPort.getParent() == reactorInstance ? - parentInputPorts.get(leftPort) : - outputPorts.get(leftPort.getParent(), leftPort); - - for (SendRange sendRange : leftPort.getDependentPorts()) { - for (RuntimeRange rightRange : sendRange.destinations) { - PortInstance rightPort = rightRange.instance; - KPort target = rightPort.getParent() == reactorInstance ? - parentOutputPorts.get(rightPort) : - inputPorts.get(rightPort.getParent(), rightPort); - // There should be a connection, but skip if not. - Connection connection = sendRange.connection; - if (connection != null) { - KEdge edge = createIODependencyEdge(connection, (leftPort.isMultiport() || rightPort.isMultiport())); - if (connection.getDelay() != null) { - KLabel delayLabel = _kLabelExtensions.addCenterEdgeLabel(edge, ASTUtils.toOriginalText(connection.getDelay())); - associateWith(delayLabel, connection.getDelay()); - if (connection.isPhysical()) { - _linguaFrancaStyleExtensions.applyOnEdgePysicalDelayStyle(delayLabel, - reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95); - } else { - _linguaFrancaStyleExtensions.applyOnEdgeDelayStyle(delayLabel); - } - } else if (connection.isPhysical()) { - KLabel physicalConnectionLabel = _kLabelExtensions.addCenterEdgeLabel(edge, "---"); - _linguaFrancaStyleExtensions.applyOnEdgePysicalStyle(physicalConnectionLabel, - reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95); - } - if (source != null && target != null) { - // check for inside loop (direct in -> out connection with delay) - if (parentInputPorts.values().contains(source) && - parentOutputPorts.values().contains(target)) { - // edge.setLayoutOption(CoreOptions.INSIDE_SELF_LOOPS_YO, true) // Does not work as expected - // Introduce dummy node to enable direct connection (that is also hidden when collapsed) - KNode dummy = _kNodeExtensions.createNode(); - if (directConnectionDummyNodes.containsKey(target)) { - dummy = directConnectionDummyNodes.get(target); - } else { - nodes.add(dummy); - directConnectionDummyNodes.put(target, dummy); - _kRenderingExtensions.addInvisibleContainerRendering(dummy); - _kNodeExtensions.setNodeSize(dummy, 0, 0); - KEdge extraEdge = createIODependencyEdge(null, - (leftPort.isMultiport() || rightPort.isMultiport())); - connect(extraEdge, dummy, target); - } - connect(edge, source, dummy); - } else { - connect(edge, source, target); - } - } - } - } - } + } + + // connect dependencies + for (TriggerInstance dep : reaction.sources) { + if (reaction.triggers.contains(dep)) continue; // skip + + // Create new port if there is no previous one or each dependency should have its own one + if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { + port = addInvisiblePort(node); + setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); + + if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || inputSize == 1) { + // manual adjustment disabling automatic one + setLayoutOption( + port, + CoreOptions.PORT_BORDER_OFFSET, + (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS); + } } - // Add startup/shutdown - if (startup != null) { - _linguaFrancaShapeExtensions.addStartupFigure(startupNode); - _utilityExtensions.setID(startupNode, reactorInstance.uniqueID() + "_startup"); - NamedInstanceUtil.linkInstance(startupNode, startup); - startupNode.setProperty(REACTION_SPECIAL_TRIGGER, true); - nodes.add(0, startupNode); // add at the start (ordered first) - // try to order with reactions vertically if in one layer - setLayoutOption(startupNode, LayeredOptions.POSITION, new KVector(0, 0)); - setLayoutOption(startupNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); - _layoutPostProcessing.configureAction(startupNode); - - if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { - KPort port = addInvisiblePort(startupNode); - startupNode.getOutgoingEdges().forEach(it -> { - it.setSourcePort(port); - }); - } + if (dep instanceof PortInstance) { + KPort src = null; + PortInstance depAsPort = (PortInstance) dep; + if (dep.getParent() == reactorInstance) { + src = parentInputPorts.get(dep); + } else { + src = outputPorts.get(depAsPort.getParent(), dep); + } + if (src != null) { + connect(createDependencyEdge(dep.getDefinition()), src, port); + } } - if (shutdown != null) { - _linguaFrancaShapeExtensions.addShutdownFigure(shutdownNode); - _utilityExtensions.setID(shutdownNode, reactorInstance.uniqueID() + "_shutdown"); - NamedInstanceUtil.linkInstance(shutdownNode, shutdown); - shutdownNode.setProperty(REACTION_SPECIAL_TRIGGER, true); - nodes.add(shutdownNode); // add at the end (ordered last) - // try to order with reactions vertically if in one layer - _layoutPostProcessing.configureShutDown(shutdownNode); - setLayoutOption(shutdownNode, LayeredOptions.POSITION, new KVector(0, reactorInstance.reactions.size() + 1)); - - if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port - KPort port = addInvisiblePort(shutdownNode); - shutdownNode.getOutgoingEdges().forEach(it -> { - it.setSourcePort(port); - }); - } - } - if (reset != null) { - _linguaFrancaShapeExtensions.addResetFigure(resetNode); - _utilityExtensions.setID(resetNode, reactorInstance.uniqueID() + "_reset"); - NamedInstanceUtil.linkInstance(resetNode, reset); - resetNode.setProperty(REACTION_SPECIAL_TRIGGER, true); - nodes.add(startup != null ? 1 : 0, resetNode); // after startup - // try to order with reactions vertically if in one layer - setLayoutOption(resetNode, LayeredOptions.POSITION, new KVector(0, 0.5)); - setLayoutOption(resetNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); - - if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port - KPort port = addInvisiblePort(resetNode); - resetNode.getOutgoingEdges().forEach(it -> { - it.setSourcePort(port); - }); - } - } - - // Postprocess timer nodes - if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port - for (KNode timerNode : timerNodes.values()) { - KPort port = addInvisiblePort(timerNode); - timerNode.getOutgoingEdges().forEach(it -> { - it.setSourcePort(port); - }); - } + } + + // connect outputs + port = null; // enforce new ports for outputs + Set> iterSet = + reaction.effects != null ? reaction.effects : new HashSet<>(); + for (TriggerInstance effect : iterSet) { + // Create new port if there is no previous one or each dependency should have its own one + if (port == null || !getBooleanValue(REACTIONS_USE_HYPEREDGES)) { + port = addInvisiblePort(node); + setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST); } - // Add reaction order edges (add last to have them on top of other edges) - if (reactorInstance.reactions.size() > 1) { - KNode prevNode = reactionNodes.get(IterableExtensions.head(reactorInstance.reactions)); - Iterable iterList = IterableExtensions.map( - IterableExtensions.drop(reactorInstance.reactions, 1), - reactionNodes::get); - for (KNode node : iterList) { - KEdge edge = createOrderEdge(); - edge.setSource(prevNode); - edge.setTarget(node); - edge.setProperty(CoreOptions.NO_LAYOUT, true); - - // Do not remove them, as they are needed for cycle detection - KRendering edgeRendering = _kRenderingExtensions.getKRendering(edge); - _kRenderingExtensions.setInvisible(edgeRendering, !getBooleanValue(SHOW_REACTION_ORDER_EDGES)); - _kRenderingExtensions.getInvisible(edgeRendering).setPropagateToChildren(true); - // TODO this does not work work with incremental update (https://github.com/kieler/KLighD/issues/37) - // if (!getBooleanValue(SHOW_REACTION_ORDER_EDGES)) edge.initiallyHide() - - prevNode = node; - } + if (effect instanceof ActionInstance) { + actionSources.put((ActionInstance) effect, port); + } else if (effect instanceof PortInstance) { + KPort dst = null; + PortInstance effectAsPort = (PortInstance) effect; + if (effectAsPort.isOutput()) { + dst = parentOutputPorts.get(effect); + } else { + dst = inputPorts.get(effectAsPort.getParent(), effect); + } + if (dst != null) { + connect(createDependencyEdge(effect), port, dst); + } } + } + } - _layoutPostProcessing.orderChildren(nodes); - _modeDiagrams.handleModes(nodes, reactorInstance); + // Connect actions + Set actions = new HashSet<>(); + actions.addAll(actionSources.keySet()); + actions.addAll(actionDestinations.keySet()); + + for (ActionInstance action : actions) { + KNode node = associateWith(_kNodeExtensions.createNode(), action.getDefinition()); + NamedInstanceUtil.linkInstance(node, action); + _utilityExtensions.setID(node, action.uniqueID()); + nodes.add(node); + Iterables.addAll(nodes, createUserComments(action.getDefinition(), node)); + setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE); + _layoutPostProcessing.configureAction(node); + Pair ports = + _linguaFrancaShapeExtensions.addActionFigureAndPorts( + node, action.isPhysical() ? "P" : "L"); + // TODO handle variables? + if (action.getMinDelay() != null + && action.getMinDelay() != ActionInstance.DEFAULT_MIN_DELAY) { + _kLabelExtensions.addOutsideBottomCenteredNodeLabel( + node, String.format("min delay: %s", action.getMinDelay().toString()), 7); + } + // TODO default value? + if (action.getDefinition().getMinSpacing() != null) { + _kLabelExtensions.addOutsideBottomCenteredNodeLabel( + node, String.format("min spacing: %s", action.getMinSpacing().toString()), 7); + } + if (!StringExtensions.isNullOrEmpty(action.getDefinition().getPolicy())) { + _kLabelExtensions.addOutsideBottomCenteredNodeLabel( + node, String.format("policy: %s", action.getPolicy().toString()), 7); + } + // connect source + for (KPort source : actionSources.get(action)) { + connect(createDelayEdge(action), source, ports.getKey()); + } + + // connect targets + for (KPort target : actionDestinations.get(action)) { + connect(createDelayEdge(action), ports.getValue(), target); + } + } - return nodes; + // Transform connections. + // First, collect all the source ports. + List sourcePorts = new LinkedList<>(reactorInstance.inputs); + for (ReactorInstance child : reactorInstance.children) { + sourcePorts.addAll(child.outputs); } - private String createReactorLabel(ReactorInstance reactorInstance) { - StringBuilder b = new StringBuilder(); - if (getBooleanValue(SHOW_INSTANCE_NAMES) && !_utilityExtensions.isRoot(reactorInstance)) { - if (!reactorInstance.isMainOrFederated()) { - b.append(reactorInstance.getName()).append(" : "); - } - } - if (reactorInstance.isMainOrFederated()) { - try { - b.append(FileUtil.nameWithoutExtension(reactorInstance.reactorDeclaration.eResource())); - } catch (Exception e) { - throw Exceptions.sneakyThrow(e); + for (PortInstance leftPort : sourcePorts) { + KPort source = + leftPort.getParent() == reactorInstance + ? parentInputPorts.get(leftPort) + : outputPorts.get(leftPort.getParent(), leftPort); + + for (SendRange sendRange : leftPort.getDependentPorts()) { + for (RuntimeRange rightRange : sendRange.destinations) { + PortInstance rightPort = rightRange.instance; + KPort target = + rightPort.getParent() == reactorInstance + ? parentOutputPorts.get(rightPort) + : inputPorts.get(rightPort.getParent(), rightPort); + // There should be a connection, but skip if not. + Connection connection = sendRange.connection; + if (connection != null) { + KEdge edge = + createIODependencyEdge( + connection, (leftPort.isMultiport() || rightPort.isMultiport())); + if (connection.getDelay() != null) { + KLabel delayLabel = + _kLabelExtensions.addCenterEdgeLabel( + edge, ASTUtils.toOriginalText(connection.getDelay())); + associateWith(delayLabel, connection.getDelay()); + if (connection.isPhysical()) { + _linguaFrancaStyleExtensions.applyOnEdgePysicalDelayStyle( + delayLabel, + reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95); + } else { + _linguaFrancaStyleExtensions.applyOnEdgeDelayStyle(delayLabel); + } + } else if (connection.isPhysical()) { + KLabel physicalConnectionLabel = _kLabelExtensions.addCenterEdgeLabel(edge, "---"); + _linguaFrancaStyleExtensions.applyOnEdgePysicalStyle( + physicalConnectionLabel, + reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95); } - } else if (reactorInstance.reactorDeclaration == null) { - // There is an error in the graph. - b.append(""); - } else { - b.append(reactorInstance.reactorDeclaration.getName()); - } - if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TITLE) { - if (reactorInstance.parameters.isEmpty()) { - b.append("()"); - } else { - b.append(IterableExtensions.join(reactorInstance.parameters, "(", ", ", ")", - it -> { - return createParameterLabel(it); - })); + if (source != null && target != null) { + // check for inside loop (direct in -> out connection with delay) + if (parentInputPorts.values().contains(source) + && parentOutputPorts.values().contains(target)) { + // edge.setLayoutOption(CoreOptions.INSIDE_SELF_LOOPS_YO, true) // Does not work as + // expected + // Introduce dummy node to enable direct connection (that is also hidden when + // collapsed) + KNode dummy = _kNodeExtensions.createNode(); + if (directConnectionDummyNodes.containsKey(target)) { + dummy = directConnectionDummyNodes.get(target); + } else { + nodes.add(dummy); + directConnectionDummyNodes.put(target, dummy); + _kRenderingExtensions.addInvisibleContainerRendering(dummy); + _kNodeExtensions.setNodeSize(dummy, 0, 0); + KEdge extraEdge = + createIODependencyEdge( + null, (leftPort.isMultiport() || rightPort.isMultiport())); + connect(extraEdge, dummy, target); + } + connect(edge, source, dummy); + } else { + connect(edge, source, target); + } } + } } - return b.toString(); + } } - private void addParameterList(KContainerRendering container, List parameters) { - int cols = 1; - try { - cols = getIntValue(REACTOR_BODY_TABLE_COLS); - } catch (Exception e) {} // ignore - if (cols > parameters.size()) { - cols = parameters.size(); - } - _kContainerRenderingExtensions.setGridPlacement(container, cols); - for (ParameterInstance param : parameters) { - var entry = _linguaFrancaShapeExtensions.addParameterEntry( - container, param.getDefinition(), createParameterLabel(param)); - _kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT); - } + // Add startup/shutdown + if (startup != null) { + _linguaFrancaShapeExtensions.addStartupFigure(startupNode); + _utilityExtensions.setID(startupNode, reactorInstance.uniqueID() + "_startup"); + NamedInstanceUtil.linkInstance(startupNode, startup); + startupNode.setProperty(REACTION_SPECIAL_TRIGGER, true); + nodes.add(0, startupNode); // add at the start (ordered first) + // try to order with reactions vertically if in one layer + setLayoutOption(startupNode, LayeredOptions.POSITION, new KVector(0, 0)); + setLayoutOption(startupNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); + _layoutPostProcessing.configureAction(startupNode); + + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { + KPort port = addInvisiblePort(startupNode); + startupNode + .getOutgoingEdges() + .forEach( + it -> { + it.setSourcePort(port); + }); + } } - - private String createParameterLabel(ParameterInstance param) { - StringBuilder b = new StringBuilder(); - b.append(param.getName()); - String t = param.type.toOriginalText(); - if (!StringExtensions.isNullOrEmpty(t)) { - b.append(": ").append(t); - } - if (param.getOverride() != null) { - b.append(" = "); - var init = param.getActualValue(); - b.append(FormattingUtils.render(init)); - } - return b.toString(); + if (shutdown != null) { + _linguaFrancaShapeExtensions.addShutdownFigure(shutdownNode); + _utilityExtensions.setID(shutdownNode, reactorInstance.uniqueID() + "_shutdown"); + NamedInstanceUtil.linkInstance(shutdownNode, shutdown); + shutdownNode.setProperty(REACTION_SPECIAL_TRIGGER, true); + nodes.add(shutdownNode); // add at the end (ordered last) + // try to order with reactions vertically if in one layer + _layoutPostProcessing.configureShutDown(shutdownNode); + setLayoutOption( + shutdownNode, + LayeredOptions.POSITION, + new KVector(0, reactorInstance.reactions.size() + 1)); + + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port + KPort port = addInvisiblePort(shutdownNode); + shutdownNode + .getOutgoingEdges() + .forEach( + it -> { + it.setSourcePort(port); + }); + } } - - public void addStateVariableList(KContainerRendering container, List variables) { - int cols = 1; - try { - cols = getIntValue(REACTOR_BODY_TABLE_COLS); - } catch (Exception e) {} // ignore - if (cols > variables.size()) { - cols = variables.size(); - } - _kContainerRenderingExtensions.setGridPlacement(container, cols); - for (var variable : variables) { - var entry = _linguaFrancaShapeExtensions.addStateEntry( - container, variable, createStateVariableLabel(variable), variable.isReset()); - _kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT); - } + if (reset != null) { + _linguaFrancaShapeExtensions.addResetFigure(resetNode); + _utilityExtensions.setID(resetNode, reactorInstance.uniqueID() + "_reset"); + NamedInstanceUtil.linkInstance(resetNode, reset); + resetNode.setProperty(REACTION_SPECIAL_TRIGGER, true); + nodes.add(startup != null ? 1 : 0, resetNode); // after startup + // try to order with reactions vertically if in one layer + setLayoutOption(resetNode, LayeredOptions.POSITION, new KVector(0, 0.5)); + setLayoutOption(resetNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); + + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port + KPort port = addInvisiblePort(resetNode); + resetNode + .getOutgoingEdges() + .forEach( + it -> { + it.setSourcePort(port); + }); + } } - private String createStateVariableLabel(StateVar variable) { - StringBuilder b = new StringBuilder(); - b.append(variable.getName()); - if (variable.getType() != null) { - var t = InferredType.fromAST(variable.getType()); - b.append(":").append(t.toOriginalText()); - } - if (variable.getInit() != null) { - b.append(FormattingUtils.render(variable.getInit())); - } - return b.toString(); + // Postprocess timer nodes + if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) { // connect all edges to one port + for (KNode timerNode : timerNodes.values()) { + KPort port = addInvisiblePort(timerNode); + timerNode + .getOutgoingEdges() + .forEach( + it -> { + it.setSourcePort(port); + }); + } } - private KEdge createDelayEdge(Object associate) { - KEdge edge = _kEdgeExtensions.createEdge(); - associateWith(edge, associate); - KPolyline line = _kEdgeExtensions.addPolyline(edge); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); - _kPolylineExtensions.addJunctionPointDecorator(line); - if (getBooleanValue(USE_ALTERNATIVE_DASH_PATTERN)) { - _kRenderingExtensions.setLineStyle(line, LineStyle.CUSTOM); - _kRenderingExtensions.getLineStyle(line).getDashPattern().addAll(ALTERNATIVE_DASH_PATTERN); - } else { - _kRenderingExtensions.setLineStyle(line, LineStyle.DASH); - } - return edge; + // Add reaction order edges (add last to have them on top of other edges) + if (reactorInstance.reactions.size() > 1) { + KNode prevNode = reactionNodes.get(IterableExtensions.head(reactorInstance.reactions)); + Iterable iterList = + IterableExtensions.map( + IterableExtensions.drop(reactorInstance.reactions, 1), reactionNodes::get); + for (KNode node : iterList) { + KEdge edge = createOrderEdge(); + edge.setSource(prevNode); + edge.setTarget(node); + edge.setProperty(CoreOptions.NO_LAYOUT, true); + + // Do not remove them, as they are needed for cycle detection + KRendering edgeRendering = _kRenderingExtensions.getKRendering(edge); + _kRenderingExtensions.setInvisible( + edgeRendering, !getBooleanValue(SHOW_REACTION_ORDER_EDGES)); + _kRenderingExtensions.getInvisible(edgeRendering).setPropagateToChildren(true); + // TODO this does not work work with incremental update + // (https://github.com/kieler/KLighD/issues/37) + // if (!getBooleanValue(SHOW_REACTION_ORDER_EDGES)) edge.initiallyHide() + + prevNode = node; + } } - private KEdge createIODependencyEdge(Object associate, boolean multiport) { - KEdge edge = _kEdgeExtensions.createEdge(); - if (associate != null) { - associateWith(edge, associate); - } - KPolyline line = _kEdgeExtensions.addPolyline(edge); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); - _kPolylineExtensions.addJunctionPointDecorator(line); - if (multiport) { - // Render multiport connections and bank connections in bold. - _kRenderingExtensions.setLineWidth(line, 2.2f); - _kRenderingExtensions.setLineCap(line, LineCap.CAP_SQUARE); - // Adjust junction point size - _kPolylineExtensions.setJunctionPointDecorator(line, line.getJunctionPointRendering(), 6, 6); - } - return edge; - } + _layoutPostProcessing.orderChildren(nodes); + _modeDiagrams.handleModes(nodes, reactorInstance); - private KEdge createDependencyEdge(Object associate) { - KEdge edge = _kEdgeExtensions.createEdge(); - if (associate != null) { - associateWith(edge, associate); - } - KPolyline line = _kEdgeExtensions.addPolyline(edge); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); - _kPolylineExtensions.addJunctionPointDecorator(line); - if (getBooleanValue(USE_ALTERNATIVE_DASH_PATTERN)) { - _kRenderingExtensions.setLineStyle(line, LineStyle.CUSTOM); - _kRenderingExtensions.getLineStyle(line).getDashPattern().addAll(ALTERNATIVE_DASH_PATTERN); - } else { - _kRenderingExtensions.setLineStyle(line, LineStyle.DASH); - } - return edge; - } + return nodes; + } - private KEdge createOrderEdge() { - KEdge edge = _kEdgeExtensions.createEdge(); - KPolyline line = _kEdgeExtensions.addPolyline(edge); - _kRenderingExtensions.setLineWidth(line, 1.5f); - _kRenderingExtensions.setLineStyle(line, LineStyle.DOT); - _kRenderingExtensions.setForeground(line, Colors.CHOCOLATE_1); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); - //addFixedTailArrowDecorator() // Fix for bug: https://github.com/kieler/KLighD/issues/38 - _kPolylineExtensions.addHeadArrowDecorator(line); - return edge; + private String createReactorLabel(ReactorInstance reactorInstance) { + StringBuilder b = new StringBuilder(); + if (getBooleanValue(SHOW_INSTANCE_NAMES) && !_utilityExtensions.isRoot(reactorInstance)) { + if (!reactorInstance.isMainOrFederated()) { + b.append(reactorInstance.getName()).append(" : "); + } } - - private KEdge connect(KEdge edge, KNode src, KNode dst) { - edge.setSource(src); - edge.setTarget(dst); - return edge; + if (reactorInstance.isMainOrFederated()) { + try { + b.append(FileUtil.nameWithoutExtension(reactorInstance.reactorDeclaration.eResource())); + } catch (Exception e) { + throw Exceptions.sneakyThrow(e); + } + } else if (reactorInstance.reactorDeclaration == null) { + // There is an error in the graph. + b.append(""); + } else { + b.append(reactorInstance.reactorDeclaration.getName()); } - - private KEdge connect(KEdge edge, KNode src, KPort dst) { - edge.setSource(src); - edge.setTargetPort(dst); - edge.setTarget(dst != null ? dst.getNode() : null); - return edge; + if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TITLE) { + if (reactorInstance.parameters.isEmpty()) { + b.append("()"); + } else { + b.append( + IterableExtensions.join( + reactorInstance.parameters, + "(", + ", ", + ")", + it -> { + return createParameterLabel(it); + })); + } } - - private KEdge connect(KEdge edge, KPort src, KNode dst) { - edge.setSourcePort(src); - edge.setSource(src != null ? src.getNode() : null); - edge.setTarget(dst); - return edge; + return b.toString(); + } + + private void addParameterList(KContainerRendering container, List parameters) { + int cols = 1; + try { + cols = getIntValue(REACTOR_BODY_TABLE_COLS); + } catch (Exception e) { + } // ignore + if (cols > parameters.size()) { + cols = parameters.size(); + } + _kContainerRenderingExtensions.setGridPlacement(container, cols); + for (ParameterInstance param : parameters) { + var entry = + _linguaFrancaShapeExtensions.addParameterEntry( + container, param.getDefinition(), createParameterLabel(param)); + _kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT); + } + } + + private String createParameterLabel(ParameterInstance param) { + StringBuilder b = new StringBuilder(); + b.append(param.getName()); + String t = param.type.toOriginalText(); + if (!StringExtensions.isNullOrEmpty(t)) { + b.append(": ").append(t); + } + if (param.getOverride() != null) { + b.append(" = "); + var init = param.getActualValue(); + b.append(FormattingUtils.render(init)); + } + return b.toString(); + } + + public void addStateVariableList(KContainerRendering container, List variables) { + int cols = 1; + try { + cols = getIntValue(REACTOR_BODY_TABLE_COLS); + } catch (Exception e) { + } // ignore + if (cols > variables.size()) { + cols = variables.size(); + } + _kContainerRenderingExtensions.setGridPlacement(container, cols); + for (var variable : variables) { + var entry = + _linguaFrancaShapeExtensions.addStateEntry( + container, variable, createStateVariableLabel(variable), variable.isReset()); + _kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT); } + } + + private String createStateVariableLabel(StateVar variable) { + StringBuilder b = new StringBuilder(); + b.append(variable.getName()); + if (variable.getType() != null) { + var t = InferredType.fromAST(variable.getType()); + b.append(":").append(t.toOriginalText()); + } + if (variable.getInit() != null) { + b.append(FormattingUtils.render(variable.getInit())); + } + return b.toString(); + } + + private KEdge createDelayEdge(Object associate) { + KEdge edge = _kEdgeExtensions.createEdge(); + associateWith(edge, associate); + KPolyline line = _kEdgeExtensions.addPolyline(edge); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); + _kPolylineExtensions.addJunctionPointDecorator(line); + if (getBooleanValue(USE_ALTERNATIVE_DASH_PATTERN)) { + _kRenderingExtensions.setLineStyle(line, LineStyle.CUSTOM); + _kRenderingExtensions.getLineStyle(line).getDashPattern().addAll(ALTERNATIVE_DASH_PATTERN); + } else { + _kRenderingExtensions.setLineStyle(line, LineStyle.DASH); + } + return edge; + } - private KEdge connect(KEdge edge, KPort src, KPort dst) { - edge.setSourcePort(src); - edge.setSource(src != null ? src.getNode() : null); - edge.setTargetPort(dst); - edge.setTarget(dst != null ? dst.getNode() : null); - return edge; + private KEdge createIODependencyEdge(Object associate, boolean multiport) { + KEdge edge = _kEdgeExtensions.createEdge(); + if (associate != null) { + associateWith(edge, associate); + } + KPolyline line = _kEdgeExtensions.addPolyline(edge); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); + _kPolylineExtensions.addJunctionPointDecorator(line); + if (multiport) { + // Render multiport connections and bank connections in bold. + _kRenderingExtensions.setLineWidth(line, 2.2f); + _kRenderingExtensions.setLineCap(line, LineCap.CAP_SQUARE); + // Adjust junction point size + _kPolylineExtensions.setJunctionPointDecorator(line, line.getJunctionPointRendering(), 6, 6); } + return edge; + } - /** - * Translate an input/output into a port. - */ - private KPort addIOPort(KNode node, PortInstance lfPort, boolean input, boolean multiport, boolean bank) { - KPort port = _kPortExtensions.createPort(); - node.getPorts().add(port); - associateWith(port, lfPort.getDefinition()); - NamedInstanceUtil.linkInstance(port, lfPort); - _kPortExtensions.setPortSize(port, 6, 6); - - if (input) { - // multiports are smaller by an offset at the right, hence compensate in inputs - double offset = multiport ? -3.4 : -3.3; - setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); - setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset); - } else { - double offset = multiport ? -2.6 : -3.3; // multiports are smaller - offset = bank ? offset - LinguaFrancaShapeExtensions.BANK_FIGURE_X_OFFSET_SUM : offset; // compensate bank figure width - setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST); - setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset); - } + private KEdge createDependencyEdge(Object associate) { + KEdge edge = _kEdgeExtensions.createEdge(); + if (associate != null) { + associateWith(edge, associate); + } + KPolyline line = _kEdgeExtensions.addPolyline(edge); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); + _kPolylineExtensions.addJunctionPointDecorator(line); + if (getBooleanValue(USE_ALTERNATIVE_DASH_PATTERN)) { + _kRenderingExtensions.setLineStyle(line, LineStyle.CUSTOM); + _kRenderingExtensions.getLineStyle(line).getDashPattern().addAll(ALTERNATIVE_DASH_PATTERN); + } else { + _kRenderingExtensions.setLineStyle(line, LineStyle.DASH); + } + return edge; + } + + private KEdge createOrderEdge() { + KEdge edge = _kEdgeExtensions.createEdge(); + KPolyline line = _kEdgeExtensions.addPolyline(edge); + _kRenderingExtensions.setLineWidth(line, 1.5f); + _kRenderingExtensions.setLineStyle(line, LineStyle.DOT); + _kRenderingExtensions.setForeground(line, Colors.CHOCOLATE_1); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(line); + // addFixedTailArrowDecorator() // Fix for bug: https://github.com/kieler/KLighD/issues/38 + _kPolylineExtensions.addHeadArrowDecorator(line); + return edge; + } + + private KEdge connect(KEdge edge, KNode src, KNode dst) { + edge.setSource(src); + edge.setTarget(dst); + return edge; + } + + private KEdge connect(KEdge edge, KNode src, KPort dst) { + edge.setSource(src); + edge.setTargetPort(dst); + edge.setTarget(dst != null ? dst.getNode() : null); + return edge; + } + + private KEdge connect(KEdge edge, KPort src, KNode dst) { + edge.setSourcePort(src); + edge.setSource(src != null ? src.getNode() : null); + edge.setTarget(dst); + return edge; + } + + private KEdge connect(KEdge edge, KPort src, KPort dst) { + edge.setSourcePort(src); + edge.setSource(src != null ? src.getNode() : null); + edge.setTargetPort(dst); + edge.setTarget(dst != null ? dst.getNode() : null); + return edge; + } + + /** Translate an input/output into a port. */ + private KPort addIOPort( + KNode node, PortInstance lfPort, boolean input, boolean multiport, boolean bank) { + KPort port = _kPortExtensions.createPort(); + node.getPorts().add(port); + associateWith(port, lfPort.getDefinition()); + NamedInstanceUtil.linkInstance(port, lfPort); + _kPortExtensions.setPortSize(port, 6, 6); + + if (input) { + // multiports are smaller by an offset at the right, hence compensate in inputs + double offset = multiport ? -3.4 : -3.3; + setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST); + setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset); + } else { + double offset = multiport ? -2.6 : -3.3; // multiports are smaller + offset = + bank + ? offset - LinguaFrancaShapeExtensions.BANK_FIGURE_X_OFFSET_SUM + : offset; // compensate bank figure width + setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST); + setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset); + } - if (bank && !node.getProperty(REACTOR_HAS_BANK_PORT_OFFSET)) {// compensate bank figure height - // https://github.com/eclipse/elk/issues/693 - _utilityExtensions.getPortMarginsInitIfAbsent(node).add( - new ElkMargin(0, 0, LinguaFrancaShapeExtensions.BANK_FIGURE_Y_OFFSET_SUM, 0)); - node.setProperty(REACTOR_HAS_BANK_PORT_OFFSET, true); // only once - } + if (bank && !node.getProperty(REACTOR_HAS_BANK_PORT_OFFSET)) { // compensate bank figure height + // https://github.com/eclipse/elk/issues/693 + _utilityExtensions + .getPortMarginsInitIfAbsent(node) + .add(new ElkMargin(0, 0, LinguaFrancaShapeExtensions.BANK_FIGURE_Y_OFFSET_SUM, 0)); + node.setProperty(REACTOR_HAS_BANK_PORT_OFFSET, true); // only once + } - _linguaFrancaShapeExtensions.addTrianglePort(port, multiport); + _linguaFrancaShapeExtensions.addTrianglePort(port, multiport); - String label = lfPort.getName(); - if (!getBooleanValue(SHOW_PORT_NAMES)) { - label = ""; - } - if (getBooleanValue(SHOW_MULTIPORT_WIDTH)) { - if (lfPort.isMultiport()) { - label += (lfPort.getWidth() >= 0) ? - "[" + lfPort.getWidth() + "]" : - "[?]"; - } - } - associateWith(_kLabelExtensions.addOutsidePortLabel(port, label, 8), lfPort.getDefinition()); - return port; + String label = lfPort.getName(); + if (!getBooleanValue(SHOW_PORT_NAMES)) { + label = ""; } - - private KPort addInvisiblePort(KNode node) { - KPort port = _kPortExtensions.createPort(); - node.getPorts().add(port); - port.setSize(0, 0); // invisible - return port; + if (getBooleanValue(SHOW_MULTIPORT_WIDTH)) { + if (lfPort.isMultiport()) { + label += (lfPort.getWidth() >= 0) ? "[" + lfPort.getWidth() + "]" : "[?]"; + } } - - private KNode addErrorComment(KNode node, String message) { + associateWith(_kLabelExtensions.addOutsidePortLabel(port, label, 8), lfPort.getDefinition()); + return port; + } + + private KPort addInvisiblePort(KNode node) { + KPort port = _kPortExtensions.createPort(); + node.getPorts().add(port); + port.setSize(0, 0); // invisible + return port; + } + + private KNode addErrorComment(KNode node, String message) { + KNode comment = _kNodeExtensions.createNode(); + setLayoutOption(comment, CoreOptions.COMMENT_BOX, true); + KRoundedRectangle commentFigure = + _linguaFrancaShapeExtensions.addCommentFigure(comment, message); + _linguaFrancaStyleExtensions.errorStyle(commentFigure); + _kRenderingExtensions.setBackground(commentFigure, Colors.PEACH_PUFF_2); + + // connect + KEdge edge = _kEdgeExtensions.createEdge(); + edge.setSource(comment); + edge.setTarget(node); + _linguaFrancaStyleExtensions.errorStyle(_linguaFrancaShapeExtensions.addCommentPolyline(edge)); + return comment; + } + + private Iterable createUserComments(EObject element, KNode targetNode) { + if (getBooleanValue(SHOW_USER_LABELS)) { + String commentText = AttributeUtils.getLabel(element); + + if (!StringExtensions.isNullOrEmpty(commentText)) { KNode comment = _kNodeExtensions.createNode(); setLayoutOption(comment, CoreOptions.COMMENT_BOX, true); - KRoundedRectangle commentFigure = _linguaFrancaShapeExtensions.addCommentFigure(comment, message); - _linguaFrancaStyleExtensions.errorStyle(commentFigure); - _kRenderingExtensions.setBackground(commentFigure, Colors.PEACH_PUFF_2); + KRoundedRectangle commentFigure = + _linguaFrancaShapeExtensions.addCommentFigure(comment, commentText); + _linguaFrancaStyleExtensions.commentStyle(commentFigure); // connect KEdge edge = _kEdgeExtensions.createEdge(); edge.setSource(comment); - edge.setTarget(node); - _linguaFrancaStyleExtensions.errorStyle(_linguaFrancaShapeExtensions.addCommentPolyline(edge)); - return comment; - } - - private Iterable createUserComments(EObject element, KNode targetNode) { - if (getBooleanValue(SHOW_USER_LABELS)) { - String commentText = AttributeUtils.getLabel(element); - - if (!StringExtensions.isNullOrEmpty(commentText)) { - KNode comment = _kNodeExtensions.createNode(); - setLayoutOption(comment, CoreOptions.COMMENT_BOX, true); - KRoundedRectangle commentFigure = _linguaFrancaShapeExtensions.addCommentFigure(comment, commentText); - _linguaFrancaStyleExtensions.commentStyle(commentFigure); + edge.setTarget(targetNode); + _linguaFrancaStyleExtensions.commentStyle( + _linguaFrancaShapeExtensions.addCommentPolyline(edge)); - // connect - KEdge edge = _kEdgeExtensions.createEdge(); - edge.setSource(comment); - edge.setTarget(targetNode); - _linguaFrancaStyleExtensions.commentStyle(_linguaFrancaShapeExtensions.addCommentPolyline(edge)); - - return List.of(comment); - } - } - return List.of(); + return List.of(comment); + } } - + return List.of(); + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java b/org.lflang/src/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java index 23365eeff9..dba7c94dde 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java @@ -1,47 +1,51 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis; /** * Enumeration of different display options for reactor parameters. - * + * * @author Alexander Schulz-Rosengarten */ public enum ReactorParameterDisplayModes { - NONE, - TITLE, - TABLE; - - @Override - public String toString() { - switch(this) { - case NONE: return "None"; - case TITLE: return "List in Title"; - case TABLE: return "Table in Body"; - default: return ""; - } + NONE, + TITLE, + TABLE; + + @Override + public String toString() { + switch (this) { + case NONE: + return "None"; + case TITLE: + return "List in Title"; + case TABLE: + return "Table in Body"; + default: + return ""; } + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/SynthesisRegistration.java b/org.lflang/src/org/lflang/diagram/synthesis/SynthesisRegistration.java index f1e217b9f1..c48d2e59ee 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/SynthesisRegistration.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/SynthesisRegistration.java @@ -1,5 +1,7 @@ package org.lflang.diagram.synthesis; +import de.cau.cs.kieler.klighd.IKlighdStartupHook; +import de.cau.cs.kieler.klighd.KlighdDataManager; import org.lflang.diagram.synthesis.action.CollapseAllReactorsAction; import org.lflang.diagram.synthesis.action.ExpandAllReactorsAction; import org.lflang.diagram.synthesis.action.FilterCycleAction; @@ -10,43 +12,42 @@ import org.lflang.diagram.synthesis.styles.LinguaFrancaStyleExtensions; import org.lflang.diagram.synthesis.util.NamedInstanceUtil; -import de.cau.cs.kieler.klighd.IKlighdStartupHook; -import de.cau.cs.kieler.klighd.KlighdDataManager; - /** * Registration of all diagram synthesis related classes in Klighd. - * + * * @author Alexander Schulz-Rosengarten */ public class SynthesisRegistration implements IKlighdStartupHook { - - @Override - public void execute() { - KlighdDataManager reg = KlighdDataManager.getInstance(); - - // Synthesis - reg.registerDiagramSynthesisClass(LinguaFrancaSynthesis.ID, LinguaFrancaSynthesis.class); - - // Actions - reg.registerAction(MemorizingExpandCollapseAction.ID, new MemorizingExpandCollapseAction()); - reg.registerAction(ExpandAllReactorsAction.ID, new ExpandAllReactorsAction()); - reg.registerAction(CollapseAllReactorsAction.ID, new CollapseAllReactorsAction()); - reg.registerAction(ShowCycleAction.ID, new ShowCycleAction()); - reg.registerAction(FilterCycleAction.ID, new FilterCycleAction()); - - // Style Mod - reg.registerStyleModifier(ReactionPortAdjustment.ID, new ReactionPortAdjustment()); - - // Blacklist LF-specific properties that should be removed when a diagram is sent from the diagram server to a client. - reg.registerBlacklistedProperty(FilterCycleAction.FILTER_BUTTON); - reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTOR_HAS_BANK_PORT_OFFSET); - reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTOR_INPUT); - reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTOR_OUTPUT); - reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTION_SPECIAL_TRIGGER); - reg.registerBlacklistedProperty(ReactionPortAdjustment.PROCESSED); - reg.registerBlacklistedProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER); - reg.registerBlacklistedProperty(LinguaFrancaStyleExtensions.LABEL_PARENT_BACKGROUND); - reg.registerBlacklistedProperty(NamedInstanceUtil.LINKED_INSTANCE); // Very important since its values can not be synthesized easily! - } - + + @Override + public void execute() { + KlighdDataManager reg = KlighdDataManager.getInstance(); + + // Synthesis + reg.registerDiagramSynthesisClass(LinguaFrancaSynthesis.ID, LinguaFrancaSynthesis.class); + + // Actions + reg.registerAction(MemorizingExpandCollapseAction.ID, new MemorizingExpandCollapseAction()); + reg.registerAction(ExpandAllReactorsAction.ID, new ExpandAllReactorsAction()); + reg.registerAction(CollapseAllReactorsAction.ID, new CollapseAllReactorsAction()); + reg.registerAction(ShowCycleAction.ID, new ShowCycleAction()); + reg.registerAction(FilterCycleAction.ID, new FilterCycleAction()); + + // Style Mod + reg.registerStyleModifier(ReactionPortAdjustment.ID, new ReactionPortAdjustment()); + + // Blacklist LF-specific properties that should be removed when a diagram is sent from the + // diagram server to a client. + reg.registerBlacklistedProperty(FilterCycleAction.FILTER_BUTTON); + reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTOR_HAS_BANK_PORT_OFFSET); + reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTOR_INPUT); + reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTOR_OUTPUT); + reg.registerBlacklistedProperty(LinguaFrancaSynthesis.REACTION_SPECIAL_TRIGGER); + reg.registerBlacklistedProperty(ReactionPortAdjustment.PROCESSED); + reg.registerBlacklistedProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER); + reg.registerBlacklistedProperty(LinguaFrancaStyleExtensions.LABEL_PARENT_BACKGROUND); + reg.registerBlacklistedProperty( + NamedInstanceUtil + .LINKED_INSTANCE); // Very important since its values can not be synthesized easily! + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/AbstractAction.java b/org.lflang/src/org/lflang/diagram/synthesis/action/AbstractAction.java index d665dff433..e840b99077 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/action/AbstractAction.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/action/AbstractAction.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.action; import de.cau.cs.kieler.klighd.IAction; @@ -32,24 +32,23 @@ /** * Abstract super class for diagram actions that provides some convince methods. - * + * * @author Alexander Schulz-Rosengarten */ public abstract class AbstractAction implements IAction { - public Object sourceElement(final KGraphElement elem) { - return elem.getProperty(KlighdInternalProperties.MODEL_ELEMEMT); - } - - public boolean sourceIs(KNode node, Class clazz) { - return clazz.isInstance(sourceElement(node)); - } - - public boolean sourceIsReactor(final KNode node) { - return sourceElement(node) instanceof Reactor; - } - - public Reactor sourceAsReactor(final KNode node) { - return sourceIsReactor(node) ? (Reactor) sourceElement(node) : null; - } + public Object sourceElement(final KGraphElement elem) { + return elem.getProperty(KlighdInternalProperties.MODEL_ELEMEMT); + } + + public boolean sourceIs(KNode node, Class clazz) { + return clazz.isInstance(sourceElement(node)); + } + + public boolean sourceIsReactor(final KNode node) { + return sourceElement(node) instanceof Reactor; + } + + public Reactor sourceAsReactor(final KNode node) { + return sourceIsReactor(node) ? (Reactor) sourceElement(node) : null; + } } - \ No newline at end of file diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java b/org.lflang/src/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java index 0927caeb37..712e9d9e66 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.action; import de.cau.cs.kieler.klighd.IAction; @@ -29,36 +29,32 @@ import de.cau.cs.kieler.klighd.kgraph.KNode; import de.cau.cs.kieler.klighd.util.ModelingUtil; import java.util.Iterator; -import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.lflang.diagram.synthesis.util.NamedInstanceUtil; import org.lflang.lf.Mode; /** * Action that expands (shows details) of all reactor nodes. - * + * * @author Alexander Schulz-Rosengarten */ public class CollapseAllReactorsAction extends AbstractAction { - - public static final String ID = "org.lflang.diagram.synthesis.action.CollapseAllReactorsAction"; - - @Override - public IAction.ActionResult execute(final IAction.ActionContext context) { - ViewContext vc = context.getViewContext(); - Iterator nodes = ModelingUtil.eAllContentsOfType(vc.getViewModel(), KNode.class); - - while(nodes.hasNext()) { - var node = nodes.next(); - if (sourceIs(node, Mode.class) || (sourceIsReactor(node) && - !(sourceAsReactor(node).isMain() || sourceAsReactor(node).isFederated()))) { - MemorizingExpandCollapseAction.setExpansionState( - node, - NamedInstanceUtil.getLinkedInstance(node), - vc.getViewer(), - false - ); - } - } - return IAction.ActionResult.createResult(true); + + public static final String ID = "org.lflang.diagram.synthesis.action.CollapseAllReactorsAction"; + + @Override + public IAction.ActionResult execute(final IAction.ActionContext context) { + ViewContext vc = context.getViewContext(); + Iterator nodes = ModelingUtil.eAllContentsOfType(vc.getViewModel(), KNode.class); + + while (nodes.hasNext()) { + var node = nodes.next(); + if (sourceIs(node, Mode.class) + || (sourceIsReactor(node) + && !(sourceAsReactor(node).isMain() || sourceAsReactor(node).isFederated()))) { + MemorizingExpandCollapseAction.setExpansionState( + node, NamedInstanceUtil.getLinkedInstance(node), vc.getViewer(), false); + } } + return IAction.ActionResult.createResult(true); + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java b/org.lflang/src/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java index 08f8b5a115..bdd7c173d6 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.action; import de.cau.cs.kieler.klighd.IAction; @@ -29,36 +29,30 @@ import de.cau.cs.kieler.klighd.kgraph.KNode; import de.cau.cs.kieler.klighd.util.ModelingUtil; import java.util.Iterator; -import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.lflang.diagram.synthesis.util.NamedInstanceUtil; import org.lflang.lf.Mode; /** * Action that collapses (hides details) of all reactor nodes. - * + * * @author Alexander Schulz-Rosengarten */ public class ExpandAllReactorsAction extends AbstractAction { - public static final String ID = "org.lflang.diagram.synthesis.action.ExpandAllReactorsAction"; - - @Override - public IAction.ActionResult execute(final IAction.ActionContext context) { - ViewContext vc = context.getViewContext(); - Iterator nodes = ModelingUtil.eAllContentsOfType(vc.getViewModel(), KNode.class); - - while(nodes.hasNext()) { - var node = nodes.next(); - if (sourceIs(node, Mode.class) || sourceIsReactor(node)) { - MemorizingExpandCollapseAction.setExpansionState( - node, - NamedInstanceUtil.getLinkedInstance(node), - vc.getViewer(), - true - ); - } - } - return IAction.ActionResult.createResult(true); + public static final String ID = "org.lflang.diagram.synthesis.action.ExpandAllReactorsAction"; + + @Override + public IAction.ActionResult execute(final IAction.ActionContext context) { + ViewContext vc = context.getViewContext(); + Iterator nodes = ModelingUtil.eAllContentsOfType(vc.getViewModel(), KNode.class); + + while (nodes.hasNext()) { + var node = nodes.next(); + if (sourceIs(node, Mode.class) || sourceIsReactor(node)) { + MemorizingExpandCollapseAction.setExpansionState( + node, NamedInstanceUtil.getLinkedInstance(node), vc.getViewer(), true); + } } + return IAction.ActionResult.createResult(true); + } } - \ No newline at end of file diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/FilterCycleAction.java b/org.lflang/src/org/lflang/diagram/synthesis/action/FilterCycleAction.java index 6daf07a1b3..bbe20806a3 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/action/FilterCycleAction.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/action/FilterCycleAction.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.action; import com.google.common.collect.Iterables; @@ -31,7 +31,6 @@ import de.cau.cs.kieler.klighd.kgraph.KEdge; import de.cau.cs.kieler.klighd.kgraph.KNode; import de.cau.cs.kieler.klighd.krendering.KText; - import java.util.Iterator; import java.util.List; import java.util.WeakHashMap; @@ -46,112 +45,115 @@ /** * Action that filters the diagram for only those elements included in a cycle. - * + * * @author Alexander Schulz-Rosengarten */ public class FilterCycleAction extends AbstractAction { - - public static final String ID = "org.lflang.diagram.synthesis.action.FilterCycleAction"; - - /** - * Memory-leak-free cache of filtered states - */ - private static final WeakHashMap FILTERING_STATES = new WeakHashMap<>(); - - /** - * INTERNAL property to mark filter button. - */ - public static final Property FILTER_BUTTON = new Property<>("org.lflang.diagram.synthesis.action.cyclefilter.button", false); - - @Override - public IAction.ActionResult execute(final IAction.ActionContext context) { - ViewContext vc = context.getViewContext(); - Object all = vc.getOptionValue(LinguaFrancaSynthesis.SHOW_ALL_REACTORS); - List nodes = vc.getViewModel().getChildren(); - - if (all instanceof Boolean && (Boolean) all) { - nodes = IterableExtensions.toList( - Iterables.concat( - ListExtensions.map( - nodes, it -> { return it.getChildren(); } - ) - ) - ); - } - if (IterableExtensions.exists(nodes, this::isCycleFiltered)) { - // undo - nodes.forEach(this::resetCycleFiltering); - - // re-synthesize everything - vc.getViewModel().getChildren().clear(); - vc.update(); - } else { - // filter - nodes.forEach(it -> { - this.markCycleFiltered(it); - this.filterCycle(it); - }); - - Function1 knodeFilterButton = it -> { - return it.getProperty(FILTER_BUTTON); - }; - - Function1 ktextFilterButton = it -> { - return it.getProperty(FILTER_BUTTON); - }; - - // switch filter label - for (KNode node : IterableExtensions.filter(nodes, knodeFilterButton)) { - Iterator ktexts = Iterators.filter(node.eAllContents(), KText.class); - KText text = IteratorExtensions.findFirst(ktexts, ktextFilterButton); - if (text != null) { - text.setText(LinguaFrancaSynthesis.TEXT_ERROR_CYCLE_BTN_UNFILTER); - } - } + public static final String ID = "org.lflang.diagram.synthesis.action.FilterCycleAction"; + + /** Memory-leak-free cache of filtered states */ + private static final WeakHashMap FILTERING_STATES = new WeakHashMap<>(); + + /** INTERNAL property to mark filter button. */ + public static final Property FILTER_BUTTON = + new Property<>("org.lflang.diagram.synthesis.action.cyclefilter.button", false); + + @Override + public IAction.ActionResult execute(final IAction.ActionContext context) { + ViewContext vc = context.getViewContext(); + Object all = vc.getOptionValue(LinguaFrancaSynthesis.SHOW_ALL_REACTORS); + List nodes = vc.getViewModel().getChildren(); + + if (all instanceof Boolean && (Boolean) all) { + nodes = + IterableExtensions.toList( + Iterables.concat( + ListExtensions.map( + nodes, + it -> { + return it.getChildren(); + }))); + } + + if (IterableExtensions.exists(nodes, this::isCycleFiltered)) { + // undo + nodes.forEach(this::resetCycleFiltering); + + // re-synthesize everything + vc.getViewModel().getChildren().clear(); + vc.update(); + } else { + // filter + nodes.forEach( + it -> { + this.markCycleFiltered(it); + this.filterCycle(it); + }); + + Function1 knodeFilterButton = + it -> { + return it.getProperty(FILTER_BUTTON); + }; + + Function1 ktextFilterButton = + it -> { + return it.getProperty(FILTER_BUTTON); + }; + + // switch filter label + for (KNode node : IterableExtensions.filter(nodes, knodeFilterButton)) { + Iterator ktexts = Iterators.filter(node.eAllContents(), KText.class); + KText text = IteratorExtensions.findFirst(ktexts, ktextFilterButton); + if (text != null) { + text.setText(LinguaFrancaSynthesis.TEXT_ERROR_CYCLE_BTN_UNFILTER); } - - return IAction.ActionResult.createResult(true); + } } - - public void filterCycle(KNode root) { - Predicate knodeNotInCycle = it -> { - return !it.getProperty(CycleVisualization.DEPENDENCY_CYCLE); + + return IAction.ActionResult.createResult(true); + } + + public void filterCycle(KNode root) { + Predicate knodeNotInCycle = + it -> { + return !it.getProperty(CycleVisualization.DEPENDENCY_CYCLE); }; - - Predicate kedgeNotInCycle = it -> { - return !it.getProperty(CycleVisualization.DEPENDENCY_CYCLE); + + Predicate kedgeNotInCycle = + it -> { + return !it.getProperty(CycleVisualization.DEPENDENCY_CYCLE); }; - - root.getChildren().removeIf(knodeNotInCycle); - for (KNode node : root.getChildren()) { - node.getOutgoingEdges().removeIf(kedgeNotInCycle); - this.filterCycle(node); - } - } - public void markCycleFiltered(KNode node) { - Object source = this.sourceElement(node); - if (source != null) { - FILTERING_STATES.put(source, true); - } - } - - public void resetCycleFiltering(KNode node) { - Object source = this.sourceElement(node); - if (source != null) { - FILTERING_STATES.remove(source); - } + root.getChildren().removeIf(knodeNotInCycle); + for (KNode node : root.getChildren()) { + node.getOutgoingEdges().removeIf(kedgeNotInCycle); + this.filterCycle(node); } + } - public boolean isCycleFiltered(KNode node) { - Object source = this.sourceElement(node); - Boolean result = FILTERING_STATES.get(source); - return result == null ? false : result; + public void markCycleFiltered(KNode node) { + Object source = this.sourceElement(node); + if (source != null) { + FILTERING_STATES.put(source, true); } + } - public void markCycleFilterText(KText text, KNode node) { - text.setProperty(FILTER_BUTTON, true); - node.setProperty(FILTER_BUTTON, true); + public void resetCycleFiltering(KNode node) { + Object source = this.sourceElement(node); + if (source != null) { + FILTERING_STATES.remove(source); } + } + + public boolean isCycleFiltered(KNode node) { + Object source = this.sourceElement(node); + Boolean result = FILTERING_STATES.get(source); + return result == null ? false : result; + } + + public void markCycleFilterText(KText text, KNode node) { + text.setProperty(FILTER_BUTTON, true); + node.setProperty(FILTER_BUTTON, true); + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java b/org.lflang/src/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java index 20347e2c22..b9a91fe08c 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java @@ -1,123 +1,119 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.action; -import java.util.WeakHashMap; - -import org.lflang.diagram.synthesis.util.InterfaceDependenciesVisualization; -import org.lflang.diagram.synthesis.util.NamedInstanceUtil; -import org.lflang.generator.NamedInstance; -import org.lflang.generator.ReactorInstance; - import com.google.common.base.Preconditions; - import de.cau.cs.kieler.klighd.IAction; import de.cau.cs.kieler.klighd.IViewer; import de.cau.cs.kieler.klighd.SynthesisOption; import de.cau.cs.kieler.klighd.ViewContext; import de.cau.cs.kieler.klighd.kgraph.KNode; +import java.util.WeakHashMap; +import org.lflang.diagram.synthesis.util.InterfaceDependenciesVisualization; +import org.lflang.diagram.synthesis.util.NamedInstanceUtil; +import org.lflang.generator.NamedInstance; +import org.lflang.generator.ReactorInstance; /** - * Action for toggling collapse/expand state of reactors that memorizes the state and - * allows correct initialization synthesis runs for the same model. - * Prevents automatic collapsing of manually expanded nodes. - * + * Action for toggling collapse/expand state of reactors that memorizes the state and allows correct + * initialization synthesis runs for the same model. Prevents automatic collapsing of manually + * expanded nodes. + * * @author Alexander Schulz-Rosengarten */ public class MemorizingExpandCollapseAction extends AbstractAction { - - public static final String ID = "org.lflang.diagram.synthesis.action.MemorizingExpandCollapseAction"; - - /** - * The related synthesis option - */ - public static final SynthesisOption MEMORIZE_EXPANSION_STATES = SynthesisOption.createCheckOption("Remember Collapsed/Expanded Reactors", true); - - /** - * Memory-leak-free cache of expansion states - */ - private static final WeakHashMap EXPANSION_STATES = new WeakHashMap<>(); - - /** - * Sets the expansion state of a node and saves it for future synthesis. - */ - public static void setExpansionState(final KNode node, final Object memorizableObj, final IViewer viewer, final boolean expand) { - Preconditions.checkNotNull(node); - - // Store new state if activated - if (((Boolean) viewer.getViewContext().getOptionValue(MEMORIZE_EXPANSION_STATES)) && memorizableObj != null) { - if (memorizableObj instanceof NamedInstance) { - EXPANSION_STATES.put(((NamedInstance) memorizableObj).uniqueID(), expand); - } else { - EXPANSION_STATES.put(memorizableObj, expand); - } - } - - // Apply state - if (expand) { - viewer.expand(node); - } else { - viewer.collapse(node); - } - - // Handle edges that should only appear for one of the renderings - InterfaceDependenciesVisualization.updateInterfaceDependencyVisibility(node, expand); + public static final String ID = + "org.lflang.diagram.synthesis.action.MemorizingExpandCollapseAction"; + + /** The related synthesis option */ + public static final SynthesisOption MEMORIZE_EXPANSION_STATES = + SynthesisOption.createCheckOption("Remember Collapsed/Expanded Reactors", true); + + /** Memory-leak-free cache of expansion states */ + private static final WeakHashMap EXPANSION_STATES = new WeakHashMap<>(); + + /** Sets the expansion state of a node and saves it for future synthesis. */ + public static void setExpansionState( + final KNode node, final Object memorizableObj, final IViewer viewer, final boolean expand) { + + Preconditions.checkNotNull(node); + + // Store new state if activated + if (((Boolean) viewer.getViewContext().getOptionValue(MEMORIZE_EXPANSION_STATES)) + && memorizableObj != null) { + if (memorizableObj instanceof NamedInstance) { + EXPANSION_STATES.put(((NamedInstance) memorizableObj).uniqueID(), expand); + } else { + EXPANSION_STATES.put(memorizableObj, expand); + } } - - /** - * @return the memorized expansion state of the given model element or null if not memorized - */ - public static Boolean getExpansionState(final Object obj) { - if (obj instanceof NamedInstance) { - return EXPANSION_STATES.get(((NamedInstance) obj).uniqueID()); - } - return EXPANSION_STATES.get(obj); + + // Apply state + if (expand) { + viewer.expand(node); + } else { + viewer.collapse(node); } - - //----------------------------------------------------------------------------------------------------------------- - - @Override - public IAction.ActionResult execute(final IAction.ActionContext context) { - ViewContext vc = context.getViewContext(); - IViewer v = vc.getViewer(); - KNode node = context.getKNode(); - NamedInstance linkedInstance = NamedInstanceUtil.getLinkedInstance(node); - - // Find node that is properly linked - while(node != null && linkedInstance == null) { - node = node.getParent(); - linkedInstance = NamedInstanceUtil.getLinkedInstance(node); - } - - if (node == null || (linkedInstance instanceof ReactorInstance && ((ReactorInstance) linkedInstance).isMainOrFederated())) { - return IAction.ActionResult.createResult(false); - } else { - setExpansionState(node, linkedInstance, v, !v.isExpanded(node)); // toggle - return IAction.ActionResult.createResult(true); - } + + // Handle edges that should only appear for one of the renderings + InterfaceDependenciesVisualization.updateInterfaceDependencyVisibility(node, expand); + } + + /** + * @return the memorized expansion state of the given model element or null if not memorized + */ + public static Boolean getExpansionState(final Object obj) { + if (obj instanceof NamedInstance) { + return EXPANSION_STATES.get(((NamedInstance) obj).uniqueID()); + } + return EXPANSION_STATES.get(obj); + } + + // ----------------------------------------------------------------------------------------------------------------- + + @Override + public IAction.ActionResult execute(final IAction.ActionContext context) { + ViewContext vc = context.getViewContext(); + IViewer v = vc.getViewer(); + KNode node = context.getKNode(); + NamedInstance linkedInstance = NamedInstanceUtil.getLinkedInstance(node); + + // Find node that is properly linked + while (node != null && linkedInstance == null) { + node = node.getParent(); + linkedInstance = NamedInstanceUtil.getLinkedInstance(node); + } + + if (node == null + || (linkedInstance instanceof ReactorInstance + && ((ReactorInstance) linkedInstance).isMainOrFederated())) { + return IAction.ActionResult.createResult(false); + } else { + setExpansionState(node, linkedInstance, v, !v.isExpanded(node)); // toggle + return IAction.ActionResult.createResult(true); } - + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/ShowCycleAction.java b/org.lflang/src/org/lflang/diagram/synthesis/action/ShowCycleAction.java index fb947511e4..5640adc424 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/action/ShowCycleAction.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/action/ShowCycleAction.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.action; import de.cau.cs.kieler.klighd.IAction; @@ -31,61 +31,58 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Set; - import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.lflang.diagram.synthesis.util.CycleVisualization; import org.lflang.diagram.synthesis.util.NamedInstanceUtil; /** * Action that expands all reactor nodes that are included in a cycle. - * + * * @author Alexander Schulz-Rosengarten */ public class ShowCycleAction extends AbstractAction { - - public static final String ID = "org.lflang.diagram.synthesis.action.ShowCycleAction"; - private static final CollapseAllReactorsAction collapseAll = new CollapseAllReactorsAction(); - - @Override - public IAction.ActionResult execute(final IAction.ActionContext context) { - ViewContext vc = context.getViewContext(); - - // Collapse all - collapseAll.execute(context); - - // Expand only errors - Iterator knodes = ModelingUtil.eAllContentsOfType(vc.getViewModel(), KNode.class); - - // Filter out nodes that are not in cycle or not a reactor - knodes = IteratorExtensions.filter(knodes, it -> { - return it.getProperty(CycleVisualization.DEPENDENCY_CYCLE) && sourceIsReactor(it); - }); - - // Remove duplicates - Set cycleNodes = IteratorExtensions.toSet(knodes); + public static final String ID = "org.lflang.diagram.synthesis.action.ShowCycleAction"; + + private static final CollapseAllReactorsAction collapseAll = new CollapseAllReactorsAction(); + + @Override + public IAction.ActionResult execute(final IAction.ActionContext context) { + ViewContext vc = context.getViewContext(); + + // Collapse all + collapseAll.execute(context); + + // Expand only errors + Iterator knodes = ModelingUtil.eAllContentsOfType(vc.getViewModel(), KNode.class); - // Include parents - LinkedList check = new LinkedList<>(cycleNodes); + // Filter out nodes that are not in cycle or not a reactor + knodes = + IteratorExtensions.filter( + knodes, + it -> { + return it.getProperty(CycleVisualization.DEPENDENCY_CYCLE) && sourceIsReactor(it); + }); + + // Remove duplicates + Set cycleNodes = IteratorExtensions.toSet(knodes); + + // Include parents + LinkedList check = new LinkedList<>(cycleNodes); + + while (!check.isEmpty()) { + KNode parent = check.pop().getParent(); + if (parent != null && !cycleNodes.contains(parent)) { + cycleNodes.add(parent); + check.add(parent); + } + } - while (!check.isEmpty()) { - KNode parent = check.pop().getParent(); - if (parent != null && !cycleNodes.contains(parent)) { - cycleNodes.add(parent); - check.add(parent); - } - } - - // Expand - for (KNode node : cycleNodes) { - MemorizingExpandCollapseAction.setExpansionState( - node, - NamedInstanceUtil.getLinkedInstance(node), - vc.getViewer(), - true - ); - } - return IAction.ActionResult.createResult(true); + // Expand + for (KNode node : cycleNodes) { + MemorizingExpandCollapseAction.setExpansionState( + node, NamedInstanceUtil.getLinkedInstance(node), vc.getViewer(), true); } - + return IAction.ActionResult.createResult(true); + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java b/org.lflang/src/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java index db3a42fd7a..4507039b28 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java @@ -1,39 +1,29 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.postprocessor; -import java.util.stream.Collectors; - -import org.eclipse.elk.core.options.CoreOptions; -import org.eclipse.elk.core.options.PortSide; -import org.eclipse.elk.graph.properties.Property; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions; - import de.cau.cs.kieler.klighd.IStyleModifier; import de.cau.cs.kieler.klighd.IViewer; import de.cau.cs.kieler.klighd.internal.ILayoutRecorder; @@ -45,142 +35,159 @@ import de.cau.cs.kieler.klighd.kgraph.KPort; import de.cau.cs.kieler.klighd.krendering.KRendering; import de.cau.cs.kieler.klighd.krendering.KRenderingFactory; +import java.util.stream.Collectors; +import org.eclipse.elk.core.options.CoreOptions; +import org.eclipse.elk.core.options.PortSide; +import org.eclipse.elk.graph.properties.Property; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Pair; +import org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions; /** - * Adjusts the port position of reactions node AFTER layout, to allow free port order but also adapt (snuggle) to pointy shape of reaction node. - * + * Adjusts the port position of reactions node AFTER layout, to allow free port order but also adapt + * (snuggle) to pointy shape of reaction node. + * * @author Alexander Schulz-Rosengarten */ public class ReactionPortAdjustment implements IStyleModifier { - public static final String ID = "org.lflang.diagram.synthesis.postprocessor.ReactionPortAdjustment"; - - /** - * INTERNAL property to mark node as processed. - */ - public static final Property PROCESSED = new Property<>("org.lflang.diagram.synthesis.postprocessor.reaction.ports.processed", false); - - @Extension - private KGraphFactory _kGraphFactory = KGraphFactory.eINSTANCE; - private static KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; - - /** - * Register this modifier on a reaction rendering. - */ - public static void apply(KNode node, KRendering rendering) { - // Add modifier that fixes port positions such that edges are properly attached to the shape - var invisible = _kRenderingFactory.createKInvisibility(); - invisible.setInvisible(false); // make it ineffective (just for purpose of holding modifier) - invisible.setModifierId(ReactionPortAdjustment.ID); // Add modifier to receive callback after layout - rendering.getStyles().add(invisible); - node.setProperty(PROCESSED, false); - } + public static final String ID = + "org.lflang.diagram.synthesis.postprocessor.ReactionPortAdjustment"; - @Override - public boolean modify(IStyleModifier.StyleModificationContext context) { - try { - KGraphElement node = context.getGraphElement(); - if (node instanceof KNode) { - KNode knode = (KNode) node; - - // Find root node - KNode parent = knode; - while (parent.eContainer() != null) { - parent = (KNode) parent.eContainer(); - } - - // Get viewer (this is a bit brittle because it fetches the viewer from some internal property) - Object viewer = - parent.getAllProperties().entrySet().stream().filter(entry -> - entry.getKey().getId().equals("de.cau.cs.kieler.klighd.viewer") - || entry.getKey().getId().equals("klighd.layout.viewer")) - .findAny().map(entry -> entry.getValue()).orElse(null); - - ILayoutRecorder recorder = null; - if (viewer instanceof IViewer) { - recorder = ((IViewer) viewer).getViewContext().getLayoutRecorder(); - } - - if (!knode.getPorts().isEmpty()) { - if (IterableExtensions.head(knode.getPorts()).getYpos() != 0 && - // Only adjust if layout is already applied important for incremental update animation - !knode.getProperty(ReactionPortAdjustment.PROCESSED)) { - if (recorder != null) { - recorder.startRecording(); - } - - var in = knode.getPorts().stream().filter(p -> - p.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST).sorted((p1, p2) -> - Float.compare(p1.getYpos(), p2.getYpos())).collect(Collectors.toList()); - - var out = knode.getPorts().stream().filter(p -> - p.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST).sorted((p1, p2) -> - Float.compare(p1.getYpos(), p2.getYpos())).collect(Collectors.toList()); - - // Adjust - if (in.stream().anyMatch(p -> !p.hasProperty(CoreOptions.PORT_BORDER_OFFSET))) { - adjustPositions(IterableExtensions.indexed(in), in.size(), true); - } - if (out.stream().anyMatch(p -> !p.hasProperty(CoreOptions.PORT_BORDER_OFFSET))) { - adjustPositions(IterableExtensions.indexed(out), out.size(), false); - } - knode.setProperty(ReactionPortAdjustment.PROCESSED, true); - - if (recorder!=null) { - recorder.stopRecording(0); - } - - } else if (IterableExtensions.head(knode.getPorts()).getYpos() == 0) { - knode.setProperty(PROCESSED, false); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - // do not disturb rendering process + /** INTERNAL property to mark node as processed. */ + public static final Property PROCESSED = + new Property<>("org.lflang.diagram.synthesis.postprocessor.reaction.ports.processed", false); + + @Extension private KGraphFactory _kGraphFactory = KGraphFactory.eINSTANCE; + private static KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; + + /** Register this modifier on a reaction rendering. */ + public static void apply(KNode node, KRendering rendering) { + // Add modifier that fixes port positions such that edges are properly attached to the shape + var invisible = _kRenderingFactory.createKInvisibility(); + invisible.setInvisible(false); // make it ineffective (just for purpose of holding modifier) + invisible.setModifierId( + ReactionPortAdjustment.ID); // Add modifier to receive callback after layout + rendering.getStyles().add(invisible); + node.setProperty(PROCESSED, false); + } + + @Override + public boolean modify(IStyleModifier.StyleModificationContext context) { + try { + KGraphElement node = context.getGraphElement(); + if (node instanceof KNode) { + KNode knode = (KNode) node; + + // Find root node + KNode parent = knode; + while (parent.eContainer() != null) { + parent = (KNode) parent.eContainer(); } - return false; - } - public void adjustPositions(Iterable> indexedPorts, int count, boolean input) { - float segments = LinguaFrancaShapeExtensions.REACTION_POINTINESS * 2 / (count + 1); - for (Pair indexedPort : indexedPorts) { - KPort port = indexedPort.getValue(); - int idx = indexedPort.getKey(); - float offset = 0; - - if (count % 2 != 0 && idx == count / 2) { - offset += LinguaFrancaShapeExtensions.REACTION_POINTINESS; - } else if (idx < count / 2) { - offset += segments * (idx + 1); - } else { - offset += segments * (count - idx); + // Get viewer (this is a bit brittle because it fetches the viewer from some internal + // property) + Object viewer = + parent.getAllProperties().entrySet().stream() + .filter( + entry -> + entry.getKey().getId().equals("de.cau.cs.kieler.klighd.viewer") + || entry.getKey().getId().equals("klighd.layout.viewer")) + .findAny() + .map(entry -> entry.getValue()) + .orElse(null); + + ILayoutRecorder recorder = null; + if (viewer instanceof IViewer) { + recorder = ((IViewer) viewer).getViewContext().getLayoutRecorder(); + } + + if (!knode.getPorts().isEmpty()) { + if (IterableExtensions.head(knode.getPorts()).getYpos() != 0 + && + // Only adjust if layout is already applied important for incremental update animation + !knode.getProperty(ReactionPortAdjustment.PROCESSED)) { + if (recorder != null) { + recorder.startRecording(); } - - if (!input) { // reverse - offset -= LinguaFrancaShapeExtensions.REACTION_POINTINESS; + + var in = + knode.getPorts().stream() + .filter(p -> p.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST) + .sorted((p1, p2) -> Float.compare(p1.getYpos(), p2.getYpos())) + .collect(Collectors.toList()); + + var out = + knode.getPorts().stream() + .filter(p -> p.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST) + .sorted((p1, p2) -> Float.compare(p1.getYpos(), p2.getYpos())) + .collect(Collectors.toList()); + + // Adjust + if (in.stream().anyMatch(p -> !p.hasProperty(CoreOptions.PORT_BORDER_OFFSET))) { + adjustPositions(IterableExtensions.indexed(in), in.size(), true); + } + if (out.stream().anyMatch(p -> !p.hasProperty(CoreOptions.PORT_BORDER_OFFSET))) { + adjustPositions(IterableExtensions.indexed(out), out.size(), false); } - - // apply - port.setPos(port.getXpos() + offset, port.getYpos()); - for (KEdge edge : port.getEdges()) { - if (input) { - edge.setTargetPoint(adjustedKPoint(edge.getTargetPoint(), offset)); - } else { - edge.setSourcePoint(adjustedKPoint(edge.getSourcePoint(), offset)); - } + knode.setProperty(ReactionPortAdjustment.PROCESSED, true); + + if (recorder != null) { + recorder.stopRecording(0); } - - // Save for future layout - port.setProperty(CoreOptions.PORT_BORDER_OFFSET, (double) (input ? -offset : offset)); + + } else if (IterableExtensions.head(knode.getPorts()).getYpos() == 0) { + knode.setProperty(PROCESSED, false); + } } + } + } catch (Exception e) { + e.printStackTrace(); + // do not disturb rendering process } + return false; + } + + public void adjustPositions( + Iterable> indexedPorts, int count, boolean input) { + float segments = LinguaFrancaShapeExtensions.REACTION_POINTINESS * 2 / (count + 1); + for (Pair indexedPort : indexedPorts) { + KPort port = indexedPort.getValue(); + int idx = indexedPort.getKey(); + float offset = 0; + + if (count % 2 != 0 && idx == count / 2) { + offset += LinguaFrancaShapeExtensions.REACTION_POINTINESS; + } else if (idx < count / 2) { + offset += segments * (idx + 1); + } else { + offset += segments * (count - idx); + } + + if (!input) { // reverse + offset -= LinguaFrancaShapeExtensions.REACTION_POINTINESS; + } + + // apply + port.setPos(port.getXpos() + offset, port.getYpos()); + for (KEdge edge : port.getEdges()) { + if (input) { + edge.setTargetPoint(adjustedKPoint(edge.getTargetPoint(), offset)); + } else { + edge.setSourcePoint(adjustedKPoint(edge.getSourcePoint(), offset)); + } + } - public KPoint adjustedKPoint(KPoint point, float xOffset) { - KPoint kPoint = _kGraphFactory.createKPoint(); - kPoint.setX(point.getX() + xOffset); - kPoint.setY(point.getY()); - return kPoint; + // Save for future layout + port.setProperty(CoreOptions.PORT_BORDER_OFFSET, (double) (input ? -offset : offset)); } + } + public KPoint adjustedKPoint(KPoint point, float xOffset) { + KPoint kPoint = _kGraphFactory.createKPoint(); + kPoint.setX(point.getX() + xOffset); + kPoint.setY(point.getY()); + return kPoint; + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java b/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java index 260e2c98db..efdc2ff4d5 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.styles; import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX.LEFT; @@ -29,29 +29,6 @@ import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.BOTTOM; import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.TOP; -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import org.eclipse.elk.core.options.CoreOptions; -import org.eclipse.elk.core.options.PortSide; -import org.eclipse.elk.graph.properties.Property; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.lflang.ast.ASTUtils; -import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; -import org.lflang.diagram.synthesis.LinguaFrancaSynthesis; -import org.lflang.diagram.synthesis.util.UtilityExtensions; -import org.lflang.generator.ReactionInstance; -import org.lflang.generator.ReactorInstance; -import org.lflang.generator.TimerInstance; -import org.lflang.lf.Parameter; -import org.lflang.lf.StateVar; - import de.cau.cs.kieler.klighd.KlighdConstants; import de.cau.cs.kieler.klighd.kgraph.KEdge; import de.cau.cs.kieler.klighd.kgraph.KNode; @@ -87,6 +64,26 @@ import de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX; import de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY; import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses; +import java.util.ArrayList; +import java.util.List; +import javax.inject.Inject; +import org.eclipse.elk.core.options.CoreOptions; +import org.eclipse.elk.core.options.PortSide; +import org.eclipse.elk.graph.properties.Property; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Pair; +import org.eclipse.xtext.xbase.lib.StringExtensions; +import org.lflang.ast.ASTUtils; +import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; +import org.lflang.diagram.synthesis.LinguaFrancaSynthesis; +import org.lflang.diagram.synthesis.util.UtilityExtensions; +import org.lflang.generator.ReactionInstance; +import org.lflang.generator.ReactorInstance; +import org.lflang.generator.TimerInstance; +import org.lflang.lf.Parameter; +import org.lflang.lf.StateVar; /** * Extension class that provides shapes and figures for the Lingua France diagram synthesis. @@ -96,873 +93,1207 @@ @ViewSynthesisShared public class LinguaFrancaShapeExtensions extends AbstractSynthesisExtensions { - public static final float REACTION_POINTINESS = 6; // arrow point length - // Property for marking the KContainterRendering in Reactor figures that is supposed to hold the content - public static final Property REACTOR_CONTENT_CONTAINER = new Property<>( - "org.lflang.diagram.synthesis.shapes.reactor.content", false); - - @Inject - @Extension - private KNodeExtensions _kNodeExtensions; - @Inject - @Extension - private KEdgeExtensions _kEdgeExtensions; - @Inject - @Extension - private KPortExtensions _kPortExtensions; - @Inject - @Extension - private KLabelExtensions _kLabelExtensions; - @Inject - @Extension - private KRenderingExtensions _kRenderingExtensions; - @Inject - @Extension - private KContainerRenderingExtensions _kContainerRenderingExtensions; - @Inject - @Extension - private KPolylineExtensions _kPolylineExtensions; - @Inject - @Extension - private KColorExtensions _kColorExtensions; - @Inject - @Extension - private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; - @Inject - @Extension - private UtilityExtensions _utilityExtensions; - @Extension - private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; - - public static final float BANK_FIGURE_X_OFFSET_SUM = 6.0f; - public static final float BANK_FIGURE_Y_OFFSET_SUM = 9.0f; - - /** - * Creates the main reactor frame. - */ - public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reactorInstance, String text) { - int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; - KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1); - _kContainerRenderingExtensions.setGridPlacement(figure, 1); - _kRenderingExtensions.setLineWidth(figure, 1); - _kRenderingExtensions.setForeground(figure, Colors.GRAY); - _kRenderingExtensions.setBackground(figure, Colors.WHITE); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - - // Create parent container - KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure); - _kRenderingExtensions.setInvisible(parentContainer, true); - setGridPlacementDataFromPointToPoint(parentContainer, - LEFT, padding, 0, TOP, padding, 0, - RIGHT, padding, 0, BOTTOM, 4, 0 - ); - - // Create child container - KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer); - _kRenderingExtensions.setInvisible(childContainer, true); - _kRenderingExtensions.setPointPlacementData(childContainer, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, - 0, 0, 0); - KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1); - - // Add text to the child container - KText childText = _kContainerRenderingExtensions.addText(childContainer, text); - DiagramSyntheses.suppressSelectability(childText); - _linguaFrancaStyleExtensions.underlineSelectionStyle(childText); - - if (reactorInstance.reactorDefinition.isFederated()) { - KContainerRendering cloudIcon = _linguaFrancaStyleExtensions.addCloudIcon(childContainer); - setGridPlacementDataFromPointToPoint(cloudIcon, - LEFT, 3, 0, TOP, 0, 0, - RIGHT, 0, 0, BOTTOM, 0, 0 - ); - placement.setNumColumns(2); - - if (reactorInstance.reactorDefinition.getHost() != null && - getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { - KText hostNameText = _kContainerRenderingExtensions.addText(childContainer, - ASTUtils.toOriginalText(reactorInstance.reactorDefinition.getHost())); - DiagramSyntheses.suppressSelectability(hostNameText); - _linguaFrancaStyleExtensions.underlineSelectionStyle(hostNameText); - setGridPlacementDataFromPointToPoint(hostNameText, - LEFT, 3, 0, TOP, 0, 0, - RIGHT, 0, 0, BOTTOM, 0, 0 - ); - placement.setNumColumns(3); - } - } - return figure; + public static final float REACTION_POINTINESS = 6; // arrow point length + // Property for marking the KContainterRendering in Reactor figures that is supposed to hold the + // content + public static final Property REACTOR_CONTENT_CONTAINER = + new Property<>("org.lflang.diagram.synthesis.shapes.reactor.content", false); + + @Inject @Extension private KNodeExtensions _kNodeExtensions; + @Inject @Extension private KEdgeExtensions _kEdgeExtensions; + @Inject @Extension private KPortExtensions _kPortExtensions; + @Inject @Extension private KLabelExtensions _kLabelExtensions; + @Inject @Extension private KRenderingExtensions _kRenderingExtensions; + @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; + @Inject @Extension private KPolylineExtensions _kPolylineExtensions; + @Inject @Extension private KColorExtensions _kColorExtensions; + @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; + @Inject @Extension private UtilityExtensions _utilityExtensions; + @Extension private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; + + public static final float BANK_FIGURE_X_OFFSET_SUM = 6.0f; + public static final float BANK_FIGURE_Y_OFFSET_SUM = 9.0f; + + /** Creates the main reactor frame. */ + public KRoundedRectangle addMainReactorFigure( + KNode node, ReactorInstance reactorInstance, String text) { + int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; + KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1); + _kContainerRenderingExtensions.setGridPlacement(figure, 1); + _kRenderingExtensions.setLineWidth(figure, 1); + _kRenderingExtensions.setForeground(figure, Colors.GRAY); + _kRenderingExtensions.setBackground(figure, Colors.WHITE); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + + // Create parent container + KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure); + _kRenderingExtensions.setInvisible(parentContainer, true); + setGridPlacementDataFromPointToPoint( + parentContainer, LEFT, padding, 0, TOP, padding, 0, RIGHT, padding, 0, BOTTOM, 4, 0); + + // Create child container + KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer); + _kRenderingExtensions.setInvisible(childContainer, true); + _kRenderingExtensions.setPointPlacementData( + childContainer, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 0, + 0); + KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1); + + // Add text to the child container + KText childText = _kContainerRenderingExtensions.addText(childContainer, text); + DiagramSyntheses.suppressSelectability(childText); + _linguaFrancaStyleExtensions.underlineSelectionStyle(childText); + + if (reactorInstance.reactorDefinition.isFederated()) { + KContainerRendering cloudIcon = _linguaFrancaStyleExtensions.addCloudIcon(childContainer); + setGridPlacementDataFromPointToPoint( + cloudIcon, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0); + placement.setNumColumns(2); + + if (reactorInstance.reactorDefinition.getHost() != null + && getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { + KText hostNameText = + _kContainerRenderingExtensions.addText( + childContainer, + ASTUtils.toOriginalText(reactorInstance.reactorDefinition.getHost())); + DiagramSyntheses.suppressSelectability(hostNameText); + _linguaFrancaStyleExtensions.underlineSelectionStyle(hostNameText); + setGridPlacementDataFromPointToPoint( + hostNameText, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0); + placement.setNumColumns(3); + } } - - /** - * Creates the visual representation of a reactor node - */ - public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reactorInstance, String text) { - int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; - - Function1 style = r -> { - _kRenderingExtensions.setLineWidth(r, 1); - _kRenderingExtensions.setForeground(r, Colors.GRAY); - _kRenderingExtensions.setBackground(r, Colors.GRAY_95); - return _linguaFrancaStyleExtensions.boldLineSelectionStyle(r); + return figure; + } + + /** Creates the visual representation of a reactor node */ + public ReactorFigureComponents addReactorFigure( + KNode node, ReactorInstance reactorInstance, String text) { + int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; + + Function1 style = + r -> { + _kRenderingExtensions.setLineWidth(r, 1); + _kRenderingExtensions.setForeground(r, Colors.GRAY); + _kRenderingExtensions.setBackground(r, Colors.GRAY_95); + return _linguaFrancaStyleExtensions.boldLineSelectionStyle(r); }; - KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1); - _kContainerRenderingExtensions.setGridPlacement(figure, 1); - style.apply(figure); - figure.setProperty(REACTOR_CONTENT_CONTAINER, true); - - // minimal node size is necessary if no text will be added - List minSize = List.of(2 * figure.getCornerWidth(), 2 * figure.getCornerHeight()); - _kNodeExtensions.setMinimalNodeSize(node, minSize.get(0), minSize.get(1)); - - // Add parent container - KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure); - _kRenderingExtensions.setInvisible(parentContainer, true); - setGridPlacementDataFromPointToPoint(parentContainer, - LEFT, padding, 0, - TOP, padding, 0, - RIGHT, padding, 0, BOTTOM, - _utilityExtensions.hasContent(reactorInstance) ? 4 : padding, 0 - ); - - // Add centered child container - KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer); - _kRenderingExtensions.setInvisible(childContainer, true); - _kRenderingExtensions.setPointPlacementData(childContainer, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, - 0, 0, 0); - KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1); - - KText childText = _kContainerRenderingExtensions.addText(childContainer, text); - DiagramSyntheses.suppressSelectability(childText); - _linguaFrancaStyleExtensions.underlineSelectionStyle(childText); - - if (!_utilityExtensions.isRoot(reactorInstance) && - reactorInstance.getDefinition().getHost() != null) { - KRendering cloudUploadIcon = _linguaFrancaStyleExtensions.addCloudUploadIcon(childContainer); - setGridPlacementDataFromPointToPoint(cloudUploadIcon, - LEFT, 3, 0, TOP, 0, 0, - RIGHT, 0, 0, BOTTOM, 0, 0 - ); - placement.setNumColumns(2); - - if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { - KText reactorHostText = _kContainerRenderingExtensions.addText(childContainer, - ASTUtils.toOriginalText(reactorInstance.getDefinition().getHost())); - DiagramSyntheses.suppressSelectability(reactorHostText); - _linguaFrancaStyleExtensions.underlineSelectionStyle(reactorHostText); - setGridPlacementDataFromPointToPoint(reactorHostText, - LEFT, 3, 0, TOP, 0, 0, - RIGHT, 0, 0, BOTTOM, 0, 0 - ); - placement.setNumColumns(3); - } - } - - if (reactorInstance.isBank()) { - List bank = new ArrayList<>(); - KContainerRendering container = _kRenderingExtensions.addInvisibleContainerRendering(node); - // TODO handle unresolved width - KRoundedRectangle banks; - banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); - style.apply(banks); - setGridPlacementDataFromPointToPoint(banks, - LEFT, BANK_FIGURE_X_OFFSET_SUM, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM, 0, - RIGHT, 0, 0, BOTTOM, 0, 0 - ); - if (reactorInstance.getWidth() == 3) { - banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); - style.apply(banks); - setGridPlacementDataFromPointToPoint(banks, - LEFT, BANK_FIGURE_X_OFFSET_SUM / 2, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM / 2, 0, - RIGHT, BANK_FIGURE_X_OFFSET_SUM / 2, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 2, 0 - ); - } else if (reactorInstance.getWidth() != 2 && reactorInstance.getWidth() != 3) { - banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); - style.apply(banks); - setGridPlacementDataFromPointToPoint(banks, - LEFT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0, - RIGHT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 3, 0 - ); - - banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); - style.apply(banks); - setGridPlacementDataFromPointToPoint(banks, - LEFT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM / 3, 0, - RIGHT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0 - ); - } - - container.getChildren().add(figure); - setGridPlacementDataFromPointToPoint(figure, - LEFT, 0, 0, TOP, 0, 0, - RIGHT, BANK_FIGURE_X_OFFSET_SUM, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM, 0 - ); - bank.addAll(container.getChildren()); - - KRectangle widthLabelContainer = _kContainerRenderingExtensions.addRectangle(container); - _kRenderingExtensions.setInvisible(widthLabelContainer, true); - setGridPlacementDataFromPointToPoint(widthLabelContainer, - LEFT, 12, 0, BOTTOM, 9, 0, - RIGHT, 6, 0, BOTTOM, 0.5f, 0 - ); - // Handle unresolved width. - String widthLabel = reactorInstance.getWidth() >= 0 ? Integer.toString(reactorInstance.getWidth()) : "?"; - KText widthLabelText = _kContainerRenderingExtensions.addText(widthLabelContainer, widthLabel); - _kRenderingExtensions.setHorizontalAlignment(widthLabelText, HorizontalAlignment.LEFT); - _kRenderingExtensions.setVerticalAlignment(widthLabelText, VerticalAlignment.BOTTOM); - _kRenderingExtensions.setFontSize(widthLabelText, 6); - _linguaFrancaStyleExtensions.noSelectionStyle(widthLabelText); - associateWith(widthLabelText, reactorInstance.getDefinition().getWidthSpec()); - return new ReactorFigureComponents(container, figure, bank); - } else { - return new ReactorFigureComponents(figure, figure, List.of(figure)); - } + KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1); + _kContainerRenderingExtensions.setGridPlacement(figure, 1); + style.apply(figure); + figure.setProperty(REACTOR_CONTENT_CONTAINER, true); + + // minimal node size is necessary if no text will be added + List minSize = List.of(2 * figure.getCornerWidth(), 2 * figure.getCornerHeight()); + _kNodeExtensions.setMinimalNodeSize(node, minSize.get(0), minSize.get(1)); + + // Add parent container + KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure); + _kRenderingExtensions.setInvisible(parentContainer, true); + setGridPlacementDataFromPointToPoint( + parentContainer, + LEFT, + padding, + 0, + TOP, + padding, + 0, + RIGHT, + padding, + 0, + BOTTOM, + _utilityExtensions.hasContent(reactorInstance) ? 4 : padding, + 0); + + // Add centered child container + KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer); + _kRenderingExtensions.setInvisible(childContainer, true); + _kRenderingExtensions.setPointPlacementData( + childContainer, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 0, + 0); + KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1); + + KText childText = _kContainerRenderingExtensions.addText(childContainer, text); + DiagramSyntheses.suppressSelectability(childText); + _linguaFrancaStyleExtensions.underlineSelectionStyle(childText); + + if (!_utilityExtensions.isRoot(reactorInstance) + && reactorInstance.getDefinition().getHost() != null) { + KRendering cloudUploadIcon = _linguaFrancaStyleExtensions.addCloudUploadIcon(childContainer); + setGridPlacementDataFromPointToPoint( + cloudUploadIcon, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0); + placement.setNumColumns(2); + + if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { + KText reactorHostText = + _kContainerRenderingExtensions.addText( + childContainer, ASTUtils.toOriginalText(reactorInstance.getDefinition().getHost())); + DiagramSyntheses.suppressSelectability(reactorHostText); + _linguaFrancaStyleExtensions.underlineSelectionStyle(reactorHostText); + setGridPlacementDataFromPointToPoint( + reactorHostText, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0); + placement.setNumColumns(3); + } } - /** - * Creates the visual representation of a reaction node - */ - public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { - int minHeight = 22; - int minWidth = 45; - ReactorInstance reactor = reaction.getParent(); - _kNodeExtensions.setMinimalNodeSize(node, minWidth, minHeight); - - // Create base shape - KPolygon baseShape = _kRenderingExtensions.addPolygon(node); - associateWith(baseShape, reaction); - _kRenderingExtensions.setLineWidth(baseShape, 1); - _kRenderingExtensions.setForeground(baseShape, Colors.GRAY_45); - _kRenderingExtensions.setBackground(baseShape, Colors.GRAY_65); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(baseShape); - baseShape.getPoints().addAll( + if (reactorInstance.isBank()) { + List bank = new ArrayList<>(); + KContainerRendering container = _kRenderingExtensions.addInvisibleContainerRendering(node); + // TODO handle unresolved width + KRoundedRectangle banks; + banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); + style.apply(banks); + setGridPlacementDataFromPointToPoint( + banks, + LEFT, + BANK_FIGURE_X_OFFSET_SUM, + 0, + TOP, + BANK_FIGURE_Y_OFFSET_SUM, + 0, + RIGHT, + 0, + 0, + BOTTOM, + 0, + 0); + if (reactorInstance.getWidth() == 3) { + banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); + style.apply(banks); + setGridPlacementDataFromPointToPoint( + banks, + LEFT, + BANK_FIGURE_X_OFFSET_SUM / 2, + 0, + TOP, + BANK_FIGURE_Y_OFFSET_SUM / 2, + 0, + RIGHT, + BANK_FIGURE_X_OFFSET_SUM / 2, + 0, + BOTTOM, + BANK_FIGURE_Y_OFFSET_SUM / 2, + 0); + } else if (reactorInstance.getWidth() != 2 && reactorInstance.getWidth() != 3) { + banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); + style.apply(banks); + setGridPlacementDataFromPointToPoint( + banks, + LEFT, + 2 * BANK_FIGURE_X_OFFSET_SUM / 3, + 0, + TOP, + 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, + 0, + RIGHT, + BANK_FIGURE_X_OFFSET_SUM / 3, + 0, + BOTTOM, + BANK_FIGURE_Y_OFFSET_SUM / 3, + 0); + + banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1); + style.apply(banks); + setGridPlacementDataFromPointToPoint( + banks, + LEFT, + BANK_FIGURE_X_OFFSET_SUM / 3, + 0, + TOP, + BANK_FIGURE_Y_OFFSET_SUM / 3, + 0, + RIGHT, + 2 * BANK_FIGURE_X_OFFSET_SUM / 3, + 0, + BOTTOM, + 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, + 0); + } + + container.getChildren().add(figure); + setGridPlacementDataFromPointToPoint( + figure, + LEFT, + 0, + 0, + TOP, + 0, + 0, + RIGHT, + BANK_FIGURE_X_OFFSET_SUM, + 0, + BOTTOM, + BANK_FIGURE_Y_OFFSET_SUM, + 0); + bank.addAll(container.getChildren()); + + KRectangle widthLabelContainer = _kContainerRenderingExtensions.addRectangle(container); + _kRenderingExtensions.setInvisible(widthLabelContainer, true); + setGridPlacementDataFromPointToPoint( + widthLabelContainer, LEFT, 12, 0, BOTTOM, 9, 0, RIGHT, 6, 0, BOTTOM, 0.5f, 0); + // Handle unresolved width. + String widthLabel = + reactorInstance.getWidth() >= 0 ? Integer.toString(reactorInstance.getWidth()) : "?"; + KText widthLabelText = + _kContainerRenderingExtensions.addText(widthLabelContainer, widthLabel); + _kRenderingExtensions.setHorizontalAlignment(widthLabelText, HorizontalAlignment.LEFT); + _kRenderingExtensions.setVerticalAlignment(widthLabelText, VerticalAlignment.BOTTOM); + _kRenderingExtensions.setFontSize(widthLabelText, 6); + _linguaFrancaStyleExtensions.noSelectionStyle(widthLabelText); + associateWith(widthLabelText, reactorInstance.getDefinition().getWidthSpec()); + return new ReactorFigureComponents(container, figure, bank); + } else { + return new ReactorFigureComponents(figure, figure, List.of(figure)); + } + } + + /** Creates the visual representation of a reaction node */ + public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) { + int minHeight = 22; + int minWidth = 45; + ReactorInstance reactor = reaction.getParent(); + _kNodeExtensions.setMinimalNodeSize(node, minWidth, minHeight); + + // Create base shape + KPolygon baseShape = _kRenderingExtensions.addPolygon(node); + associateWith(baseShape, reaction); + _kRenderingExtensions.setLineWidth(baseShape, 1); + _kRenderingExtensions.setForeground(baseShape, Colors.GRAY_45); + _kRenderingExtensions.setBackground(baseShape, Colors.GRAY_65); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(baseShape); + baseShape + .getPoints() + .addAll( List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, REACTION_POINTINESS, 0, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(RIGHT, REACTION_POINTINESS, 0, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0), - _kRenderingExtensions.createKPosition(LEFT, REACTION_POINTINESS, 0, BOTTOM, 0, 0.5f) - ) - ); - - KRectangle contentContainer = _kContainerRenderingExtensions.addRectangle(baseShape); - associateWith(contentContainer, reaction); - _kRenderingExtensions.setInvisible(contentContainer, true); - _kRenderingExtensions.setPointPlacementData(contentContainer, - _kRenderingExtensions.LEFT, REACTION_POINTINESS, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, REACTION_POINTINESS, - 0, minWidth - REACTION_POINTINESS * 2, minHeight); - _kContainerRenderingExtensions.setGridPlacement(contentContainer, 1); - - if (reactor.reactions.size() > 1) { - KText textToAdd = _kContainerRenderingExtensions.addText(contentContainer, - Integer.toString(reactor.reactions.indexOf(reaction) + 1)); - _kRenderingExtensions.setFontBold(textToAdd, true); - _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); - DiagramSyntheses.suppressSelectability(textToAdd); - } - - // optional reaction level - if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_LEVEL)) { - // Force calculation of levels for reactions. This calculation - // will only be done once. Note that if this fails due to a causality loop, - // then some reactions will have level -1. - try { - String levels = IterableExtensions.join(reaction.getLevels(), ", "); - KText levelsText = _kContainerRenderingExtensions.addText(contentContainer, ("level: " + levels)); - _kRenderingExtensions.setFontBold(levelsText, false); - _linguaFrancaStyleExtensions.noSelectionStyle(levelsText); - DiagramSyntheses.suppressSelectability(levelsText); - } catch (Exception ex) { - // If the graph has cycles, the above fails. Continue without showing levels. - } - } - - // optional code content - boolean hasCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && - !StringExtensions.isNullOrEmpty(reaction.getDefinition().getCode().getBody()); - if (hasCode) { - KText hasCodeText = _kContainerRenderingExtensions.addText(contentContainer, - _utilityExtensions.trimCode(reaction.getDefinition().getCode())); - associateWith(hasCodeText, reaction); - _kRenderingExtensions.setFontSize(hasCodeText, 6); - _kRenderingExtensions.setFontName(hasCodeText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME); - _linguaFrancaStyleExtensions.noSelectionStyle(hasCodeText); - _kRenderingExtensions.setHorizontalAlignment(hasCodeText, HorizontalAlignment.LEFT); - _kRenderingExtensions.setVerticalAlignment(hasCodeText, VerticalAlignment.TOP); - setGridPlacementDataFromPointToPoint(hasCodeText, - _kRenderingExtensions.LEFT, 5, 0, - _kRenderingExtensions.TOP, 5, 0, - _kRenderingExtensions.RIGHT, 5, 0, - _kRenderingExtensions.BOTTOM, 5, 0 - ); - } - - if (reaction.declaredDeadline != null) { - boolean hasDeadlineCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && - !StringExtensions.isNullOrEmpty(reaction.getDefinition().getDeadline().getCode().getBody()); - if (hasCode || hasDeadlineCode) { - KPolyline line = _kContainerRenderingExtensions.addHorizontalLine(contentContainer, 0); - setGridPlacementDataFromPointToPoint(line, - _kRenderingExtensions.LEFT, 5, 0, - _kRenderingExtensions.TOP, 3, 0, - _kRenderingExtensions.RIGHT, 5, 0, - _kRenderingExtensions.BOTTOM, 6, 0 - ); - } - - // delay with stopwatch - KRectangle labelContainer = _kContainerRenderingExtensions.addRectangle(contentContainer); - _kRenderingExtensions.setInvisible(labelContainer, true); - KRendering placement = setGridPlacementDataFromPointToPoint(labelContainer, - _kRenderingExtensions.LEFT, hasDeadlineCode ? 0 : -REACTION_POINTINESS * 0.5f, 0, - _kRenderingExtensions.TOP, 0, reactor.reactions.size() > 1 || hasCode || hasDeadlineCode ? 0 : 0.5f, - _kRenderingExtensions.RIGHT, 0, 0, - _kRenderingExtensions.BOTTOM, 0, 0 - ); - _kRenderingExtensions.setHorizontalAlignment(placement, HorizontalAlignment.LEFT); - - KRectangle stopWatchFigure = addStopwatchFigure(labelContainer); - _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchFigure, 0, 0, 0, 0); - - KText stopWatchText = _kContainerRenderingExtensions.addText(labelContainer, - reaction.declaredDeadline.maxDelay.toString()); - associateWith(stopWatchText, reaction.getDefinition().getDeadline().getDelay()); - _kRenderingExtensions.setForeground(stopWatchText, Colors.BROWN); - _kRenderingExtensions.setFontBold(stopWatchText, true); - _kRenderingExtensions.setFontSize(stopWatchText, 7); - _linguaFrancaStyleExtensions.underlineSelectionStyle(stopWatchText); - _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchText, 15, 0, 0, 0); - - // optional code content - if (hasDeadlineCode) { - KText contentContainerText = _kContainerRenderingExtensions.addText(contentContainer, - _utilityExtensions.trimCode(reaction.getDefinition().getDeadline().getCode())); - associateWith(contentContainerText, reaction.declaredDeadline); - _kRenderingExtensions.setForeground(contentContainerText, Colors.BROWN); - _kRenderingExtensions.setFontSize(contentContainerText, 6); - _kRenderingExtensions.setFontName(contentContainerText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME); - setGridPlacementDataFromPointToPoint(contentContainerText, - _kRenderingExtensions.LEFT, 5, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.RIGHT, 5, 0, - _kRenderingExtensions.BOTTOM, 5, 0 - ); - _kRenderingExtensions.setHorizontalAlignment(contentContainerText, HorizontalAlignment.LEFT); - _linguaFrancaStyleExtensions.noSelectionStyle(contentContainerText); - } - } - - return baseShape; + _kRenderingExtensions.createKPosition( + LEFT, REACTION_POINTINESS, 0, BOTTOM, 0, 0.5f))); + + KRectangle contentContainer = _kContainerRenderingExtensions.addRectangle(baseShape); + associateWith(contentContainer, reaction); + _kRenderingExtensions.setInvisible(contentContainer, true); + _kRenderingExtensions.setPointPlacementData( + contentContainer, + _kRenderingExtensions.LEFT, + REACTION_POINTINESS, + 0, + _kRenderingExtensions.TOP, + 0, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + REACTION_POINTINESS, + 0, + minWidth - REACTION_POINTINESS * 2, + minHeight); + _kContainerRenderingExtensions.setGridPlacement(contentContainer, 1); + + if (reactor.reactions.size() > 1) { + KText textToAdd = + _kContainerRenderingExtensions.addText( + contentContainer, Integer.toString(reactor.reactions.indexOf(reaction) + 1)); + _kRenderingExtensions.setFontBold(textToAdd, true); + _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); + DiagramSyntheses.suppressSelectability(textToAdd); } - /** - * Stopwatch figure for deadlines. - */ - public KRectangle addStopwatchFigure(KContainerRendering parent) { - final int size = 12; - KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); - _kRenderingExtensions.setInvisible(container, true); - _kRenderingExtensions.setPointPlacementData(container, - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, - 0, size, size); - - KPolyline polyline = _kContainerRenderingExtensions.addPolyline(container, 2, - List.of( - _kRenderingExtensions.createKPosition(LEFT, 3, 0.5f, TOP, (-2), 0), - _kRenderingExtensions.createKPosition(LEFT, (-3), 0.5f, TOP, (-2), 0) - ) - ); - _kRenderingExtensions.setForeground(polyline, Colors.BROWN); + // optional reaction level + if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_LEVEL)) { + // Force calculation of levels for reactions. This calculation + // will only be done once. Note that if this fails due to a causality loop, + // then some reactions will have level -1. + try { + String levels = IterableExtensions.join(reaction.getLevels(), ", "); + KText levelsText = + _kContainerRenderingExtensions.addText(contentContainer, ("level: " + levels)); + _kRenderingExtensions.setFontBold(levelsText, false); + _linguaFrancaStyleExtensions.noSelectionStyle(levelsText); + DiagramSyntheses.suppressSelectability(levelsText); + } catch (Exception ex) { + // If the graph has cycles, the above fails. Continue without showing levels. + } + } - polyline = _kContainerRenderingExtensions.addPolyline(container, 2, - List.of( - _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, (-2), 0), - _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 1, 0) - ) - ); - _kRenderingExtensions.setForeground(polyline, Colors.BROWN); - - KEllipse body = _kContainerRenderingExtensions.addEllipse(container); - _kRenderingExtensions.setLineWidth(body, 1); - _kRenderingExtensions.setForeground(body, Colors.BROWN); - _kRenderingExtensions.setPointPlacementData(body, - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, - 0, size, size); - _linguaFrancaStyleExtensions.noSelectionStyle(body); - - KArc arc = _kContainerRenderingExtensions.addArc(body); - arc.setStartAngle((-20)); - arc.setArcAngle(110); - arc.setArcType(Arc.PIE); - _kRenderingExtensions.setLineWidth(arc, 0); - _kRenderingExtensions.setBackground(arc, Colors.BROWN); - _kRenderingExtensions.setPointPlacementData(arc, - _kRenderingExtensions.LEFT, 2, 0, - _kRenderingExtensions.TOP, 2, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 2, - 2, size - 4, size - 4); - _linguaFrancaStyleExtensions.noSelectionStyle(arc); - - return container; + // optional code content + boolean hasCode = + getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) + && !StringExtensions.isNullOrEmpty(reaction.getDefinition().getCode().getBody()); + if (hasCode) { + KText hasCodeText = + _kContainerRenderingExtensions.addText( + contentContainer, _utilityExtensions.trimCode(reaction.getDefinition().getCode())); + associateWith(hasCodeText, reaction); + _kRenderingExtensions.setFontSize(hasCodeText, 6); + _kRenderingExtensions.setFontName(hasCodeText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME); + _linguaFrancaStyleExtensions.noSelectionStyle(hasCodeText); + _kRenderingExtensions.setHorizontalAlignment(hasCodeText, HorizontalAlignment.LEFT); + _kRenderingExtensions.setVerticalAlignment(hasCodeText, VerticalAlignment.TOP); + setGridPlacementDataFromPointToPoint( + hasCodeText, + _kRenderingExtensions.LEFT, + 5, + 0, + _kRenderingExtensions.TOP, + 5, + 0, + _kRenderingExtensions.RIGHT, + 5, + 0, + _kRenderingExtensions.BOTTOM, + 5, + 0); } - /** - * Creates the visual representation of a timer node - */ - public KEllipse addTimerFigure(KNode node, TimerInstance timer) { - _kNodeExtensions.setMinimalNodeSize(node, 30, 30); + if (reaction.declaredDeadline != null) { + boolean hasDeadlineCode = + getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) + && !StringExtensions.isNullOrEmpty( + reaction.getDefinition().getDeadline().getCode().getBody()); + if (hasCode || hasDeadlineCode) { + KPolyline line = _kContainerRenderingExtensions.addHorizontalLine(contentContainer, 0); + setGridPlacementDataFromPointToPoint( + line, + _kRenderingExtensions.LEFT, + 5, + 0, + _kRenderingExtensions.TOP, + 3, + 0, + _kRenderingExtensions.RIGHT, + 5, + 0, + _kRenderingExtensions.BOTTOM, + 6, + 0); + } + + // delay with stopwatch + KRectangle labelContainer = _kContainerRenderingExtensions.addRectangle(contentContainer); + _kRenderingExtensions.setInvisible(labelContainer, true); + KRendering placement = + setGridPlacementDataFromPointToPoint( + labelContainer, + _kRenderingExtensions.LEFT, + hasDeadlineCode ? 0 : -REACTION_POINTINESS * 0.5f, + 0, + _kRenderingExtensions.TOP, + 0, + reactor.reactions.size() > 1 || hasCode || hasDeadlineCode ? 0 : 0.5f, + _kRenderingExtensions.RIGHT, + 0, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); + _kRenderingExtensions.setHorizontalAlignment(placement, HorizontalAlignment.LEFT); + + KRectangle stopWatchFigure = addStopwatchFigure(labelContainer); + _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchFigure, 0, 0, 0, 0); + + KText stopWatchText = + _kContainerRenderingExtensions.addText( + labelContainer, reaction.declaredDeadline.maxDelay.toString()); + associateWith(stopWatchText, reaction.getDefinition().getDeadline().getDelay()); + _kRenderingExtensions.setForeground(stopWatchText, Colors.BROWN); + _kRenderingExtensions.setFontBold(stopWatchText, true); + _kRenderingExtensions.setFontSize(stopWatchText, 7); + _linguaFrancaStyleExtensions.underlineSelectionStyle(stopWatchText); + _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchText, 15, 0, 0, 0); + + // optional code content + if (hasDeadlineCode) { + KText contentContainerText = + _kContainerRenderingExtensions.addText( + contentContainer, + _utilityExtensions.trimCode(reaction.getDefinition().getDeadline().getCode())); + associateWith(contentContainerText, reaction.declaredDeadline); + _kRenderingExtensions.setForeground(contentContainerText, Colors.BROWN); + _kRenderingExtensions.setFontSize(contentContainerText, 6); + _kRenderingExtensions.setFontName( + contentContainerText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME); + setGridPlacementDataFromPointToPoint( + contentContainerText, + _kRenderingExtensions.LEFT, + 5, + 0, + _kRenderingExtensions.TOP, + 0, + 0, + _kRenderingExtensions.RIGHT, + 5, + 0, + _kRenderingExtensions.BOTTOM, + 5, + 0); + _kRenderingExtensions.setHorizontalAlignment( + contentContainerText, HorizontalAlignment.LEFT); + _linguaFrancaStyleExtensions.noSelectionStyle(contentContainerText); + } + } - KEllipse figure = _kRenderingExtensions.addEllipse(node); - _kRenderingExtensions.setBackground(figure, Colors.GRAY_95); - _linguaFrancaStyleExtensions.noSelectionStyle(figure); - _kRenderingExtensions.setLineWidth(figure, 1); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + return baseShape; + } + + /** Stopwatch figure for deadlines. */ + public KRectangle addStopwatchFigure(KContainerRendering parent) { + final int size = 12; + KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); + _kRenderingExtensions.setInvisible(container, true); + _kRenderingExtensions.setPointPlacementData( + container, + _kRenderingExtensions.LEFT, + 0, + 0, + _kRenderingExtensions.TOP, + 0, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + 0, + 0, + size, + size); + + KPolyline polyline = + _kContainerRenderingExtensions.addPolyline( + container, + 2, + List.of( + _kRenderingExtensions.createKPosition(LEFT, 3, 0.5f, TOP, (-2), 0), + _kRenderingExtensions.createKPosition(LEFT, (-3), 0.5f, TOP, (-2), 0))); + _kRenderingExtensions.setForeground(polyline, Colors.BROWN); - List polylinePoints = List.of( + polyline = + _kContainerRenderingExtensions.addPolyline( + container, + 2, + List.of( + _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, (-2), 0), + _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 1, 0))); + _kRenderingExtensions.setForeground(polyline, Colors.BROWN); + + KEllipse body = _kContainerRenderingExtensions.addEllipse(container); + _kRenderingExtensions.setLineWidth(body, 1); + _kRenderingExtensions.setForeground(body, Colors.BROWN); + _kRenderingExtensions.setPointPlacementData( + body, + _kRenderingExtensions.LEFT, + 0, + 0, + _kRenderingExtensions.TOP, + 0, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + 0, + 0, + size, + size); + _linguaFrancaStyleExtensions.noSelectionStyle(body); + + KArc arc = _kContainerRenderingExtensions.addArc(body); + arc.setStartAngle((-20)); + arc.setArcAngle(110); + arc.setArcType(Arc.PIE); + _kRenderingExtensions.setLineWidth(arc, 0); + _kRenderingExtensions.setBackground(arc, Colors.BROWN); + _kRenderingExtensions.setPointPlacementData( + arc, + _kRenderingExtensions.LEFT, + 2, + 0, + _kRenderingExtensions.TOP, + 2, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + 2, + 2, + size - 4, + size - 4); + _linguaFrancaStyleExtensions.noSelectionStyle(arc); + + return container; + } + + /** Creates the visual representation of a timer node */ + public KEllipse addTimerFigure(KNode node, TimerInstance timer) { + _kNodeExtensions.setMinimalNodeSize(node, 30, 30); + + KEllipse figure = _kRenderingExtensions.addEllipse(node); + _kRenderingExtensions.setBackground(figure, Colors.GRAY_95); + _linguaFrancaStyleExtensions.noSelectionStyle(figure); + _kRenderingExtensions.setLineWidth(figure, 1); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + + List polylinePoints = + List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.1f), _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.5f), - _kRenderingExtensions.createKPosition(LEFT, 0, 0.7f, TOP, 0, 0.7f) - ); - KPolyline polyline = _kContainerRenderingExtensions.addPolyline(figure, 1, polylinePoints); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(polyline); - - List labelParts = new ArrayList<>(); - if (timer.getOffset() != TimerInstance.DEFAULT_OFFSET && timer.getOffset() != null) { - labelParts.add(timer.getOffset().toString()); - } - if (timer.getPeriod() != TimerInstance.DEFAULT_PERIOD && timer.getPeriod() != null) { - if (timer.getOffset() == TimerInstance.DEFAULT_OFFSET) { - labelParts.add(timer.getOffset().toString()); - } - labelParts.add(timer.getPeriod().toString()); - } - if (!labelParts.isEmpty()) { - _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, - "(" + String.join(", ", labelParts) + ")", 8); - } - return figure; - } + _kRenderingExtensions.createKPosition(LEFT, 0, 0.7f, TOP, 0, 0.7f)); + KPolyline polyline = _kContainerRenderingExtensions.addPolyline(figure, 1, polylinePoints); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(polyline); - /** - * Creates the visual representation of a startup trigger. - */ - public KEllipse addStartupFigure(KNode node) { - _kNodeExtensions.setMinimalNodeSize(node, 18, 18); - KEllipse figure = _kRenderingExtensions.addEllipse(node); - _kRenderingExtensions.setLineWidth(figure, 1); - _kRenderingExtensions.setBackground(figure, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(figure); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - return figure; + List labelParts = new ArrayList<>(); + if (timer.getOffset() != TimerInstance.DEFAULT_OFFSET && timer.getOffset() != null) { + labelParts.add(timer.getOffset().toString()); } - - /** - * Creates the visual representation of a shutdown trigger. - */ - public KPolygon addShutdownFigure(KNode node) { - _kNodeExtensions.setMinimalNodeSize(node, 18, 18); - KPolygon figure = _kRenderingExtensions.addPolygon(node); - _kRenderingExtensions.setLineWidth(figure, 1); - _kRenderingExtensions.setBackground(figure, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(figure); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - - List pointsToAdd = List.of( + if (timer.getPeriod() != TimerInstance.DEFAULT_PERIOD && timer.getPeriod() != null) { + if (timer.getOffset() == TimerInstance.DEFAULT_OFFSET) { + labelParts.add(timer.getOffset().toString()); + } + labelParts.add(timer.getPeriod().toString()); + } + if (!labelParts.isEmpty()) { + _kLabelExtensions.addOutsideBottomCenteredNodeLabel( + node, "(" + String.join(", ", labelParts) + ")", 8); + } + return figure; + } + + /** Creates the visual representation of a startup trigger. */ + public KEllipse addStartupFigure(KNode node) { + _kNodeExtensions.setMinimalNodeSize(node, 18, 18); + KEllipse figure = _kRenderingExtensions.addEllipse(node); + _kRenderingExtensions.setLineWidth(figure, 1); + _kRenderingExtensions.setBackground(figure, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(figure); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + return figure; + } + + /** Creates the visual representation of a shutdown trigger. */ + public KPolygon addShutdownFigure(KNode node) { + _kNodeExtensions.setMinimalNodeSize(node, 18, 18); + KPolygon figure = _kRenderingExtensions.addPolygon(node); + _kRenderingExtensions.setLineWidth(figure, 1); + _kRenderingExtensions.setBackground(figure, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(figure); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + + List pointsToAdd = + List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(RIGHT, 0, 0.5f, BOTTOM, 0, 0), - _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0.5f) - ); - - figure.getPoints().addAll(pointsToAdd); - return figure; - } - - /** - * Creates the visual representation of a shutdown trigger. - */ - public KEllipse addResetFigure(KNode node) { - _kNodeExtensions.setMinimalNodeSize(node, 18, 18); - KEllipse figure = _kRenderingExtensions.addEllipse(node); - _kRenderingExtensions.setLineWidth(figure, 1); - _kRenderingExtensions.setBackground(figure, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(figure); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - - KEllipse resetCircle = _kContainerRenderingExtensions.addEllipse(figure); - _kRenderingExtensions.setSurroundingSpace(resetCircle, 3f, 0); - _kRenderingExtensions.setLineWidth(resetCircle, 1.5f); - _kRenderingExtensions.setBackground(resetCircle, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(resetCircle); - - var resetCycleGap = _kContainerRenderingExtensions.addPolygon(resetCircle); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.0f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 1.1f, 0, PositionReferenceY.BOTTOM, 0, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 1.1f, 0, PositionReferenceY.BOTTOM, 0, 0)); - _kRenderingExtensions.setLineWidth(resetCycleGap, 0.3f); - _kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE); - _kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap); - _kRenderingExtensions.setPointPlacementData(resetCycleGap, - _kRenderingExtensions.LEFT, -2, 0.5f, - _kRenderingExtensions.TOP, 1.5f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 4.0f, 3.0f); - - var resetArrow = _kContainerRenderingExtensions.addPolygon(resetCircle); - resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f)); - resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0)); - resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0.0f, 0, PositionReferenceY.TOP, 0.0f, 0.0f)); - _kRenderingExtensions.setLineWidth(resetArrow, 0.3f); - _kRenderingExtensions.setBackground(resetArrow, Colors.BLACK); - _linguaFrancaStyleExtensions.noSelectionStyle(resetArrow); - _kRenderingExtensions.setPointPlacementData(resetArrow, - _kRenderingExtensions.LEFT, 1.0f, 0.5f, - _kRenderingExtensions.TOP, 1.8f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 3.2f, 3.2f); - - return figure; + _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0.5f)); + + figure.getPoints().addAll(pointsToAdd); + return figure; + } + + /** Creates the visual representation of a shutdown trigger. */ + public KEllipse addResetFigure(KNode node) { + _kNodeExtensions.setMinimalNodeSize(node, 18, 18); + KEllipse figure = _kRenderingExtensions.addEllipse(node); + _kRenderingExtensions.setLineWidth(figure, 1); + _kRenderingExtensions.setBackground(figure, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(figure); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + + KEllipse resetCircle = _kContainerRenderingExtensions.addEllipse(figure); + _kRenderingExtensions.setSurroundingSpace(resetCircle, 3f, 0); + _kRenderingExtensions.setLineWidth(resetCircle, 1.5f); + _kRenderingExtensions.setBackground(resetCircle, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(resetCircle); + + var resetCycleGap = _kContainerRenderingExtensions.addPolygon(resetCircle); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.0f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 1.1f, 0, PositionReferenceY.BOTTOM, 0, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 1.1f, 0, PositionReferenceY.BOTTOM, 0, 0)); + _kRenderingExtensions.setLineWidth(resetCycleGap, 0.3f); + _kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE); + _kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap); + _kRenderingExtensions.setPointPlacementData( + resetCycleGap, + _kRenderingExtensions.LEFT, + -2, + 0.5f, + _kRenderingExtensions.TOP, + 1.5f, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 4.0f, + 3.0f); + + var resetArrow = _kContainerRenderingExtensions.addPolygon(resetCircle); + resetArrow + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f)); + resetArrow + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0)); + resetArrow + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 0.0f, 0, PositionReferenceY.TOP, 0.0f, 0.0f)); + _kRenderingExtensions.setLineWidth(resetArrow, 0.3f); + _kRenderingExtensions.setBackground(resetArrow, Colors.BLACK); + _linguaFrancaStyleExtensions.noSelectionStyle(resetArrow); + _kRenderingExtensions.setPointPlacementData( + resetArrow, + _kRenderingExtensions.LEFT, + 1.0f, + 0.5f, + _kRenderingExtensions.TOP, + 1.8f, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 3.2f, + 3.2f); + + return figure; + } + + /** Creates the visual representation of a reactor port. */ + public KPolygon addTrianglePort(KPort port, boolean multiport) { + port.setSize(8, 8); + + // Create triangle port + KPolygon trianglePort = _kRenderingExtensions.addPolygon(port); + + // Set line width and background color according to multiport or not + float lineWidth = multiport ? 2.2f : 1; + _kRenderingExtensions.setLineWidth(trianglePort, lineWidth); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(trianglePort); + Colors background = multiport ? Colors.WHITE : Colors.BLACK; + _kRenderingExtensions.setBackground(trianglePort, background); + + List pointsToAdd; + if (multiport) { + // Compensate for line width by making triangle smaller + // Do not adjust by port size because this will affect port distribution and cause offsets + // between parallel connections + pointsToAdd = + List.of( + _kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0.6f, 0), + _kRenderingExtensions.createKPosition(RIGHT, 1.2f, 0, TOP, 0, 0.5f), + _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0.6f, 0)); + } else { + pointsToAdd = + List.of( + _kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0, 0), + _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), + _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0)); } - - /** - * Creates the visual representation of a reactor port. - */ - public KPolygon addTrianglePort(KPort port, boolean multiport) { - port.setSize(8, 8); - - // Create triangle port - KPolygon trianglePort = _kRenderingExtensions.addPolygon(port); - - // Set line width and background color according to multiport or not - float lineWidth = multiport ? 2.2f : 1; - _kRenderingExtensions.setLineWidth(trianglePort, lineWidth); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(trianglePort); - Colors background = multiport ? Colors.WHITE : Colors.BLACK; - _kRenderingExtensions.setBackground(trianglePort, background); - - List pointsToAdd; - if (multiport) { - // Compensate for line width by making triangle smaller - // Do not adjust by port size because this will affect port distribution and cause offsets between parallel connections - pointsToAdd = List.of( - _kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0.6f, 0), - _kRenderingExtensions.createKPosition(RIGHT, 1.2f, 0, TOP, 0, 0.5f), - _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0.6f, 0) - ); - } else { - pointsToAdd = List.of( - _kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0, 0), - _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), - _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0) - ); - } - trianglePort.getPoints().addAll(pointsToAdd); - return trianglePort; - } - - /** - * Added a text as collapse expand button. - */ - public KText addTextButton(KContainerRendering container, String text) { - KText textToAdd = _kContainerRenderingExtensions.addText(container, text); - _kRenderingExtensions.setForeground(textToAdd, Colors.BLUE); - _kRenderingExtensions.setFontSize(textToAdd, 8); - _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); - return textToAdd; - } - - /** - * Creates the triangular line decorator with text. - */ - public KPolygon addActionDecorator(KPolyline line, String text) { - final float size = 18; - - // Create action decorator - KPolygon actionDecorator = _kContainerRenderingExtensions.addPolygon(line); - _kRenderingExtensions.setBackground(actionDecorator, Colors.WHITE); - List pointsToAdd = List.of( + trianglePort.getPoints().addAll(pointsToAdd); + return trianglePort; + } + + /** Added a text as collapse expand button. */ + public KText addTextButton(KContainerRendering container, String text) { + KText textToAdd = _kContainerRenderingExtensions.addText(container, text); + _kRenderingExtensions.setForeground(textToAdd, Colors.BLUE); + _kRenderingExtensions.setFontSize(textToAdd, 8); + _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); + return textToAdd; + } + + /** Creates the triangular line decorator with text. */ + public KPolygon addActionDecorator(KPolyline line, String text) { + final float size = 18; + + // Create action decorator + KPolygon actionDecorator = _kContainerRenderingExtensions.addPolygon(line); + _kRenderingExtensions.setBackground(actionDecorator, Colors.WHITE); + List pointsToAdd = + List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, BOTTOM, 0, 0), - _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0) - ); - actionDecorator.getPoints().addAll(pointsToAdd); - - // Set placement data of the action decorator - KDecoratorPlacementData placementData = _kRenderingFactory.createKDecoratorPlacementData(); - placementData.setRelative(0.5f); - placementData.setAbsolute(-size / 2); - placementData.setWidth(size); - placementData.setHeight(size); - placementData.setYOffset(-size * 0.66f); - placementData.setRotateWithLine(true); - actionDecorator.setPlacementData(placementData); - - // Add text to the action decorator - KText textToAdd = _kContainerRenderingExtensions.addText(actionDecorator, text); - _kRenderingExtensions.setFontSize(textToAdd, 8); - _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); - DiagramSyntheses.suppressSelectability(textToAdd); - _kRenderingExtensions.setPointPlacementData(textToAdd, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, size * 0.15f, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, - 0, size, size); - - return actionDecorator; - } - - /** - * Creates the triangular action node with text and ports. - */ - public Pair addActionFigureAndPorts(KNode node, String text) { - final float size = 18; - _kNodeExtensions.setMinimalNodeSize(node, size, size); - KPolygon figure = _kRenderingExtensions.addPolygon(node); - _kRenderingExtensions.setBackground(figure, Colors.WHITE); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - - List pointsToAdd = List.of( + _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0)); + actionDecorator.getPoints().addAll(pointsToAdd); + + // Set placement data of the action decorator + KDecoratorPlacementData placementData = _kRenderingFactory.createKDecoratorPlacementData(); + placementData.setRelative(0.5f); + placementData.setAbsolute(-size / 2); + placementData.setWidth(size); + placementData.setHeight(size); + placementData.setYOffset(-size * 0.66f); + placementData.setRotateWithLine(true); + actionDecorator.setPlacementData(placementData); + + // Add text to the action decorator + KText textToAdd = _kContainerRenderingExtensions.addText(actionDecorator, text); + _kRenderingExtensions.setFontSize(textToAdd, 8); + _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); + DiagramSyntheses.suppressSelectability(textToAdd); + _kRenderingExtensions.setPointPlacementData( + textToAdd, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + size * 0.15f, + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + size, + size); + + return actionDecorator; + } + + /** Creates the triangular action node with text and ports. */ + public Pair addActionFigureAndPorts(KNode node, String text) { + final float size = 18; + _kNodeExtensions.setMinimalNodeSize(node, size, size); + KPolygon figure = _kRenderingExtensions.addPolygon(node); + _kRenderingExtensions.setBackground(figure, Colors.WHITE); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + + List pointsToAdd = + List.of( _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, BOTTOM, 0, 0), - _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0) - ); - figure.getPoints().addAll(pointsToAdd); - - // Add text to the action figure - KText textToAdd = _kContainerRenderingExtensions.addText(figure, text); - _kRenderingExtensions.setFontSize(textToAdd, 8); - _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); - DiagramSyntheses.suppressSelectability(textToAdd); - _kRenderingExtensions.setPointPlacementData(textToAdd, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, (size * 0.15f), 0.5f, - _kRenderingExtensions.H_CENTRAL, - _kRenderingExtensions.V_CENTRAL, 0, 0, size, size); - - // Add input port - KPort in = _kPortExtensions.createPort(); - node.getPorts().add(in); - in.setSize(0, 0); - DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_SIDE, PortSide.WEST); - DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4)); - - // Add output port - KPort out = _kPortExtensions.createPort(); - node.getPorts().add(out); - DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_SIDE, PortSide.EAST); - DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4)); - return new Pair(in, out); + _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0)); + figure.getPoints().addAll(pointsToAdd); + + // Add text to the action figure + KText textToAdd = _kContainerRenderingExtensions.addText(figure, text); + _kRenderingExtensions.setFontSize(textToAdd, 8); + _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd); + DiagramSyntheses.suppressSelectability(textToAdd); + _kRenderingExtensions.setPointPlacementData( + textToAdd, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + (size * 0.15f), + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + size, + size); + + // Add input port + KPort in = _kPortExtensions.createPort(); + node.getPorts().add(in); + in.setSize(0, 0); + DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_SIDE, PortSide.WEST); + DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4)); + + // Add output port + KPort out = _kPortExtensions.createPort(); + node.getPorts().add(out); + DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_SIDE, PortSide.EAST); + DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4)); + return new Pair(in, out); + } + + /** Creates and adds an error message figure */ + public KRectangle addErrorMessage(KNode node, String title, String message) { + // Create figure for error message + KRectangle figure = _kRenderingExtensions.addRectangle(node); + _kRenderingExtensions.setInvisible(figure, true); + + // Add error message box + KRoundedRectangle errMsgBox = _kContainerRenderingExtensions.addRoundedRectangle(figure, 7, 7); + _kContainerRenderingExtensions.setGridPlacement(errMsgBox, 1); + _kRenderingExtensions.setLineWidth(errMsgBox, 2); + _linguaFrancaStyleExtensions.noSelectionStyle(errMsgBox); + + if (title != null) { + // Add title to error message box + KText titleText = _kContainerRenderingExtensions.addText(errMsgBox, title); + _kRenderingExtensions.setFontSize(titleText, 12); + _kRenderingExtensions.setFontBold(titleText, true); + _kRenderingExtensions.setForeground(titleText, Colors.RED); + setGridPlacementDataFromPointToPoint( + titleText, + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 8, + 0, + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); + DiagramSyntheses.suppressSelectability(titleText); + _linguaFrancaStyleExtensions.noSelectionStyle(titleText); } - /** - * Creates and adds an error message figure - */ - public KRectangle addErrorMessage(KNode node, String title, String message) { - // Create figure for error message - KRectangle figure = _kRenderingExtensions.addRectangle(node); - _kRenderingExtensions.setInvisible(figure, true); - - // Add error message box - KRoundedRectangle errMsgBox = _kContainerRenderingExtensions.addRoundedRectangle(figure, 7, 7); - _kContainerRenderingExtensions.setGridPlacement(errMsgBox, 1); - _kRenderingExtensions.setLineWidth(errMsgBox, 2); - _linguaFrancaStyleExtensions.noSelectionStyle(errMsgBox); - - if (title != null) { - // Add title to error message box - KText titleText = _kContainerRenderingExtensions.addText(errMsgBox, title); - _kRenderingExtensions.setFontSize(titleText, 12); - _kRenderingExtensions.setFontBold(titleText, true); - _kRenderingExtensions.setForeground(titleText, Colors.RED); - setGridPlacementDataFromPointToPoint(titleText, - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 8, 0, - _kRenderingExtensions.RIGHT, 8, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - DiagramSyntheses.suppressSelectability(titleText); - _linguaFrancaStyleExtensions.noSelectionStyle(titleText); - } - - if (message != null) { - // Add message to error message box - KText msgText = _kContainerRenderingExtensions.addText(errMsgBox, message); - if (title != null) { - setGridPlacementDataFromPointToPoint(msgText, - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.RIGHT, 8, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - } else { - setGridPlacementDataFromPointToPoint(msgText, - _kRenderingExtensions.LEFT, 8, 0, - _kRenderingExtensions.TOP, 8, 0, - _kRenderingExtensions.RIGHT, 8, 0, - _kRenderingExtensions.BOTTOM, 8, 0); - } - _linguaFrancaStyleExtensions.noSelectionStyle(msgText); - } - return figure; + if (message != null) { + // Add message to error message box + KText msgText = _kContainerRenderingExtensions.addText(errMsgBox, message); + if (title != null) { + setGridPlacementDataFromPointToPoint( + msgText, + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 0, + 0, + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); + } else { + setGridPlacementDataFromPointToPoint( + msgText, + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 8, + 0, + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 8, + 0); + } + _linguaFrancaStyleExtensions.noSelectionStyle(msgText); } - - public KRoundedRectangle addCommentFigure(KNode node, String message) { - // Create rectangle for comment figure - KRoundedRectangle commentFigure = _kRenderingExtensions.addRoundedRectangle(node, 1, 1, 1); - _kContainerRenderingExtensions.setGridPlacement(commentFigure, 1); - - // Add message - KText text = _kContainerRenderingExtensions.addText(commentFigure, message); - _kRenderingExtensions.setFontSize(text, 6); - setGridPlacementDataFromPointToPoint(text, - _kRenderingExtensions.LEFT, 3, 0, - _kRenderingExtensions.TOP, 3, 0, - _kRenderingExtensions.RIGHT, 3, 0, - _kRenderingExtensions.BOTTOM, 3, 0); - _linguaFrancaStyleExtensions.noSelectionStyle(text); - return commentFigure; - } - - private KRendering setGridPlacementDataFromPointToPoint(KRendering rendering, - PositionReferenceX fPx, float fAbsoluteLR, float fRelativeLR, - PositionReferenceY fPy, float fAbsoluteTB, float fRelativeTB, - PositionReferenceX tPx, float tAbsoluteLR, float tRelativeLR, - PositionReferenceY tPy, float tAbsoluteTB, float tRelativeTB) { - KAreaPlacementData fromPoint = _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rendering), - fPx, fAbsoluteLR, fRelativeLR, - fPy, fAbsoluteTB, fRelativeTB); - return _kRenderingExtensions.to(fromPoint, - tPx, tAbsoluteLR, tRelativeLR, - tPy, tAbsoluteTB, tRelativeTB); - } - - - public KPolyline addCommentPolyline(KEdge edge) { - KPolyline polyline = _kEdgeExtensions.addPolyline(edge); - _kRenderingExtensions.setLineWidth(polyline, 1); - _kRenderingExtensions.setLineStyle(polyline, LineStyle.DOT); - return polyline; - } - - public KContainerRendering addParameterEntry(KContainerRendering parent, Parameter associate, String text) { - KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); - _kRenderingExtensions.setInvisible(container, true); - - var ktext = _kContainerRenderingExtensions.addText(container, text); - _kRenderingExtensions.setFontSize(ktext, 8); - _kRenderingExtensions.setPointPlacementData(ktext, - _kRenderingExtensions.LEFT, 10, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 0, 0); - associateWith(ktext, associate); - - var dot = _kContainerRenderingExtensions.addEllipse(container); - _kRenderingExtensions.setLineWidth(dot, 1); - _linguaFrancaStyleExtensions.noSelectionStyle(dot); - _kRenderingExtensions.setPointPlacementData(dot, - _kRenderingExtensions.LEFT, 2, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 5, 5); - - return container; - } - - - public KContainerRendering addStateEntry(KContainerRendering parent, StateVar associate, String text, boolean reset) { - KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); - _kRenderingExtensions.setInvisible(container, true); - - var ktext = _kContainerRenderingExtensions.addText(container, text); - _kRenderingExtensions.setFontSize(ktext, 8); - _kRenderingExtensions.setPointPlacementData(ktext, - _kRenderingExtensions.LEFT, 10, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 0, 0); - associateWith(ktext, associate); - - KEllipse outerCircle; - - if (reset) { - outerCircle = _kContainerRenderingExtensions.addEllipse(container); - _kRenderingExtensions.setLineWidth(outerCircle, 0.9f); - _kRenderingExtensions.setBackground(outerCircle, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(outerCircle); - _kRenderingExtensions.setPointPlacementData(outerCircle, - _kRenderingExtensions.LEFT, 1.5f, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 6.3f, 6.3f); - - var resetCycleGap = _kContainerRenderingExtensions.addPolygon(outerCircle); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.26f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0.5f, PositionReferenceY.TOP, 0.0f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.26f, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0.5f, 0, PositionReferenceY.BOTTOM, 0, 0)); - resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.5f, 0, PositionReferenceY.BOTTOM, 0, 0)); - _kRenderingExtensions.setLineWidth(resetCycleGap, 0.3f); - _kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE); - _kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap); - _kRenderingExtensions.setPointPlacementData(resetCycleGap, - _kRenderingExtensions.LEFT, -1.2f, 0.5f, - _kRenderingExtensions.TOP, 0.75f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 2.5f, 1.3f); - - var resetArrow = _kContainerRenderingExtensions.addPolygon(outerCircle); - resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f)); - resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0)); - resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0.0f, 0, PositionReferenceY.TOP, 0.0f, 0.0f)); - _kRenderingExtensions.setLineWidth(resetArrow, 0.3f); - _kRenderingExtensions.setBackground(resetArrow, Colors.BLACK); - _linguaFrancaStyleExtensions.noSelectionStyle(resetArrow); - _kRenderingExtensions.setPointPlacementData(resetArrow, - _kRenderingExtensions.LEFT, 0.8f, 0.5f, - _kRenderingExtensions.TOP, 1.1f, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 1.5f, 1.5f); - } else { - outerCircle = _kContainerRenderingExtensions.addEllipse(container); - _kRenderingExtensions.setLineWidth(outerCircle, 1); - _kRenderingExtensions.setBackground(outerCircle, Colors.WHITE); - _linguaFrancaStyleExtensions.noSelectionStyle(outerCircle); - _kRenderingExtensions.setPointPlacementData(outerCircle, - _kRenderingExtensions.LEFT, 1.5f, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL, - 0, 0, 6, 6); - } - - var innerDot = _kContainerRenderingExtensions.addEllipse(outerCircle); - _kRenderingExtensions.setLineWidth(innerDot, 0.5f); - _kRenderingExtensions.setBackground(innerDot, Colors.BLACK); - _linguaFrancaStyleExtensions.noSelectionStyle(innerDot); - _kRenderingExtensions.setPointPlacementData(innerDot, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, - 0, 0, 2.5f, 2.5f); - - return container; + return figure; + } + + public KRoundedRectangle addCommentFigure(KNode node, String message) { + // Create rectangle for comment figure + KRoundedRectangle commentFigure = _kRenderingExtensions.addRoundedRectangle(node, 1, 1, 1); + _kContainerRenderingExtensions.setGridPlacement(commentFigure, 1); + + // Add message + KText text = _kContainerRenderingExtensions.addText(commentFigure, message); + _kRenderingExtensions.setFontSize(text, 6); + setGridPlacementDataFromPointToPoint( + text, + _kRenderingExtensions.LEFT, + 3, + 0, + _kRenderingExtensions.TOP, + 3, + 0, + _kRenderingExtensions.RIGHT, + 3, + 0, + _kRenderingExtensions.BOTTOM, + 3, + 0); + _linguaFrancaStyleExtensions.noSelectionStyle(text); + return commentFigure; + } + + private KRendering setGridPlacementDataFromPointToPoint( + KRendering rendering, + PositionReferenceX fPx, + float fAbsoluteLR, + float fRelativeLR, + PositionReferenceY fPy, + float fAbsoluteTB, + float fRelativeTB, + PositionReferenceX tPx, + float tAbsoluteLR, + float tRelativeLR, + PositionReferenceY tPy, + float tAbsoluteTB, + float tRelativeTB) { + KAreaPlacementData fromPoint = + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rendering), + fPx, + fAbsoluteLR, + fRelativeLR, + fPy, + fAbsoluteTB, + fRelativeTB); + return _kRenderingExtensions.to( + fromPoint, tPx, tAbsoluteLR, tRelativeLR, tPy, tAbsoluteTB, tRelativeTB); + } + + public KPolyline addCommentPolyline(KEdge edge) { + KPolyline polyline = _kEdgeExtensions.addPolyline(edge); + _kRenderingExtensions.setLineWidth(polyline, 1); + _kRenderingExtensions.setLineStyle(polyline, LineStyle.DOT); + return polyline; + } + + public KContainerRendering addParameterEntry( + KContainerRendering parent, Parameter associate, String text) { + KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); + _kRenderingExtensions.setInvisible(container, true); + + var ktext = _kContainerRenderingExtensions.addText(container, text); + _kRenderingExtensions.setFontSize(ktext, 8); + _kRenderingExtensions.setPointPlacementData( + ktext, + _kRenderingExtensions.LEFT, + 10, + 0, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 0, + 0); + associateWith(ktext, associate); + + var dot = _kContainerRenderingExtensions.addEllipse(container); + _kRenderingExtensions.setLineWidth(dot, 1); + _linguaFrancaStyleExtensions.noSelectionStyle(dot); + _kRenderingExtensions.setPointPlacementData( + dot, + _kRenderingExtensions.LEFT, + 2, + 0, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 5, + 5); + + return container; + } + + public KContainerRendering addStateEntry( + KContainerRendering parent, StateVar associate, String text, boolean reset) { + KRectangle container = _kContainerRenderingExtensions.addRectangle(parent); + _kRenderingExtensions.setInvisible(container, true); + + var ktext = _kContainerRenderingExtensions.addText(container, text); + _kRenderingExtensions.setFontSize(ktext, 8); + _kRenderingExtensions.setPointPlacementData( + ktext, + _kRenderingExtensions.LEFT, + 10, + 0, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 0, + 0); + associateWith(ktext, associate); + + KEllipse outerCircle; + + if (reset) { + outerCircle = _kContainerRenderingExtensions.addEllipse(container); + _kRenderingExtensions.setLineWidth(outerCircle, 0.9f); + _kRenderingExtensions.setBackground(outerCircle, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(outerCircle); + _kRenderingExtensions.setPointPlacementData( + outerCircle, + _kRenderingExtensions.LEFT, + 1.5f, + 0, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 6.3f, + 6.3f); + + var resetCycleGap = _kContainerRenderingExtensions.addPolygon(outerCircle); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.26f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0, 0.5f, PositionReferenceY.TOP, 0.0f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.26f, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 0.5f, 0, PositionReferenceY.BOTTOM, 0, 0)); + resetCycleGap + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0.5f, 0, PositionReferenceY.BOTTOM, 0, 0)); + _kRenderingExtensions.setLineWidth(resetCycleGap, 0.3f); + _kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE); + _kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap); + _kRenderingExtensions.setPointPlacementData( + resetCycleGap, + _kRenderingExtensions.LEFT, + -1.2f, + 0.5f, + _kRenderingExtensions.TOP, + 0.75f, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 2.5f, + 1.3f); + + var resetArrow = _kContainerRenderingExtensions.addPolygon(outerCircle); + resetArrow + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f)); + resetArrow + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0)); + resetArrow + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + PositionReferenceX.RIGHT, 0.0f, 0, PositionReferenceY.TOP, 0.0f, 0.0f)); + _kRenderingExtensions.setLineWidth(resetArrow, 0.3f); + _kRenderingExtensions.setBackground(resetArrow, Colors.BLACK); + _linguaFrancaStyleExtensions.noSelectionStyle(resetArrow); + _kRenderingExtensions.setPointPlacementData( + resetArrow, + _kRenderingExtensions.LEFT, + 0.8f, + 0.5f, + _kRenderingExtensions.TOP, + 1.1f, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 1.5f, + 1.5f); + } else { + outerCircle = _kContainerRenderingExtensions.addEllipse(container); + _kRenderingExtensions.setLineWidth(outerCircle, 1); + _kRenderingExtensions.setBackground(outerCircle, Colors.WHITE); + _linguaFrancaStyleExtensions.noSelectionStyle(outerCircle); + _kRenderingExtensions.setPointPlacementData( + outerCircle, + _kRenderingExtensions.LEFT, + 1.5f, + 0, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 6, + 6); } + var innerDot = _kContainerRenderingExtensions.addEllipse(outerCircle); + _kRenderingExtensions.setLineWidth(innerDot, 0.5f); + _kRenderingExtensions.setBackground(innerDot, Colors.BLACK); + _linguaFrancaStyleExtensions.noSelectionStyle(innerDot); + _kRenderingExtensions.setPointPlacementData( + innerDot, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 2.5f, + 2.5f); + + return container; + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java b/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java index f4c0aefd98..6eb2cfd7f0 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java @@ -1,29 +1,32 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.styles; +import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX.*; +import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.*; + import de.cau.cs.kieler.klighd.internal.util.KlighdInternalProperties; import de.cau.cs.kieler.klighd.kgraph.KEdge; import de.cau.cs.kieler.klighd.kgraph.KLabel; @@ -48,7 +51,6 @@ import de.cau.cs.kieler.klighd.labels.decoration.IDecoratorRenderingProvider; import de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator; import java.util.List; - import javax.inject.Inject; import org.eclipse.elk.core.math.ElkPadding; import org.eclipse.elk.graph.properties.Property; @@ -56,415 +58,469 @@ import org.eclipse.xtext.xbase.lib.Extension; import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; -import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX.*; -import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.*; - /** * Extension class that provides styles and coloring for the Lingua France diagram synthesis. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class LinguaFrancaStyleExtensions extends AbstractSynthesisExtensions { - - /** - * INTERNAL property to communicate a node's background color. - */ - public static final Property LABEL_PARENT_BACKGROUND = new Property<>( - "org.lflang.linguafranca.diagram.synthesis.styles.label.parent.background", Colors.WHITE); - - @Inject - @Extension - private KRenderingExtensions _kRenderingExtensions; - @Inject - @Extension - private KContainerRenderingExtensions _kContainerRenderingExtensions; - @Inject - @Extension - private KPolylineExtensions _kPolylineExtensions; - @Extension - private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; - - public KRendering noSelectionStyle(KRendering r) { - return _kRenderingExtensions.setSelectionTextStrikeout(r, false); - } - - public KRendering underlineSelectionStyle(KRendering r) { - return _kRenderingExtensions.setSelectionTextUnderline(r, Underline.SINGLE); - } - - public KRendering boldLineSelectionStyle(KRendering r) { - float lineWidthValue = _kRenderingExtensions.getLineWidthValue(r); - return _kRenderingExtensions.setSelectionLineWidth(r, lineWidthValue * 2); - } - - public KText boldTextSelectionStyle(KText t) { - return _kRenderingExtensions.setSelectionFontBold(t, true); - } - - public void errorStyle(KRendering r) { - _kRenderingExtensions.setForeground(r, Colors.RED); - _kRenderingExtensions.setLineWidth(r, 2); - _kRenderingExtensions.setSelectionLineWidth(r, 3); - - // Set background color the body if its a port or an line decorator - if (r.eContainer() instanceof KPort || r.eContainer() instanceof KPolyline) { - _kRenderingExtensions.setBackground(r, Colors.RED); - _kRenderingExtensions.getBackground(r).setPropagateToChildren(true); - _kRenderingExtensions.getForeground(r).setPropagateToChildren(true); - _kRenderingExtensions.getLineWidth(r).setPropagateToChildren(true); - } else if (r.eContainer() instanceof KEdge && r instanceof KPolyline) { - // As a workaround for a rendering issue in Klighd VSCode, the style is applied to polyline - // children directly because a propagated background would lead to a filled edge area. - // See https://github.com/kieler/klighd-vscode/issues/67 - // If fixed this commit can be reverted - ((KPolyline) r).getChildren().stream().forEach(c -> errorStyle(c)); - } - } - - public void commentStyle(KRendering r) { - _kRenderingExtensions.setForeground(r, Colors.LIGHT_GOLDENROD); - _kRenderingExtensions.setBackground(r, Colors.PALE_GOLDENROD); - _kRenderingExtensions.setLineWidth(r, 1); - _kRenderingExtensions.setSelectionLineWidth(r, 2); - - if (r.eContainer() instanceof KEdge) { // also color potential arrow heads - _kRenderingExtensions.setBackground(r, Colors.LIGHT_GOLDENROD); - _kRenderingExtensions.getBackground(r).setPropagateToChildren(true); - _kRenderingExtensions.getForeground(r).setPropagateToChildren(true); - _kRenderingExtensions.getLineWidth(r).setPropagateToChildren(true); - } + + /** INTERNAL property to communicate a node's background color. */ + public static final Property LABEL_PARENT_BACKGROUND = + new Property<>( + "org.lflang.linguafranca.diagram.synthesis.styles.label.parent.background", Colors.WHITE); + + @Inject @Extension private KRenderingExtensions _kRenderingExtensions; + @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; + @Inject @Extension private KPolylineExtensions _kPolylineExtensions; + @Extension private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; + + public KRendering noSelectionStyle(KRendering r) { + return _kRenderingExtensions.setSelectionTextStrikeout(r, false); + } + + public KRendering underlineSelectionStyle(KRendering r) { + return _kRenderingExtensions.setSelectionTextUnderline(r, Underline.SINGLE); + } + + public KRendering boldLineSelectionStyle(KRendering r) { + float lineWidthValue = _kRenderingExtensions.getLineWidthValue(r); + return _kRenderingExtensions.setSelectionLineWidth(r, lineWidthValue * 2); + } + + public KText boldTextSelectionStyle(KText t) { + return _kRenderingExtensions.setSelectionFontBold(t, true); + } + + public void errorStyle(KRendering r) { + _kRenderingExtensions.setForeground(r, Colors.RED); + _kRenderingExtensions.setLineWidth(r, 2); + _kRenderingExtensions.setSelectionLineWidth(r, 3); + + // Set background color the body if its a port or an line decorator + if (r.eContainer() instanceof KPort || r.eContainer() instanceof KPolyline) { + _kRenderingExtensions.setBackground(r, Colors.RED); + _kRenderingExtensions.getBackground(r).setPropagateToChildren(true); + _kRenderingExtensions.getForeground(r).setPropagateToChildren(true); + _kRenderingExtensions.getLineWidth(r).setPropagateToChildren(true); + } else if (r.eContainer() instanceof KEdge && r instanceof KPolyline) { + // As a workaround for a rendering issue in Klighd VSCode, the style is applied to polyline + // children directly because a propagated background would lead to a filled edge area. + // See https://github.com/kieler/klighd-vscode/issues/67 + // If fixed this commit can be reverted + ((KPolyline) r).getChildren().stream().forEach(c -> errorStyle(c)); } - - private static final int CLOUD_WIDTH = 20; - public KContainerRendering addCloudIcon(final KContainerRendering parent) { - KRectangle figure = _kContainerRenderingExtensions.addRectangle(parent); - _kRenderingExtensions.setInvisible(figure, true); - - KRoundedRectangle roundRectangle = _kContainerRenderingExtensions.addRoundedRectangle( - figure, - CLOUD_WIDTH / 7, - CLOUD_WIDTH / 7 - ); - _kRenderingExtensions.setBackground(roundRectangle, Colors.GRAY); - _kRenderingExtensions.setForeground(roundRectangle, Colors.GRAY); - _kRenderingExtensions.setPointPlacementData(roundRectangle, - _kRenderingExtensions.LEFT, 2, 0, - _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, - 0, CLOUD_WIDTH, CLOUD_WIDTH / 3); - - KEllipse childEllipse = _kContainerRenderingExtensions.addEllipse(figure); - _kRenderingExtensions.setBackground(childEllipse, Colors.GRAY); - _kRenderingExtensions.setForeground(childEllipse, Colors.GRAY); - _kRenderingExtensions.setPointPlacementData(childEllipse, - _kRenderingExtensions.LEFT, 0, 0f, - _kRenderingExtensions.TOP, 0, 0.38f, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, - 0, CLOUD_WIDTH / 2.5f, CLOUD_WIDTH / 2.5f); - - childEllipse = _kContainerRenderingExtensions.addEllipse(figure); - _kRenderingExtensions.setBackground(childEllipse, Colors.GRAY); - _kRenderingExtensions.setForeground(childEllipse, Colors.GRAY); - _kRenderingExtensions.setPointPlacementData(childEllipse, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0.25f, - _kRenderingExtensions.H_RIGHT, _kRenderingExtensions.V_TOP, 0, - 0, CLOUD_WIDTH / 3f, CLOUD_WIDTH / 3f); - - childEllipse = _kContainerRenderingExtensions.addEllipse(figure); - _kRenderingExtensions.setBackground(childEllipse, Colors.GRAY); - _kRenderingExtensions.setForeground(childEllipse, Colors.GRAY); - _kRenderingExtensions.setPointPlacementData(childEllipse, - _kRenderingExtensions.LEFT, 0, 0.4f, - _kRenderingExtensions.TOP, CLOUD_WIDTH / 10, 0, - _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, - 0, CLOUD_WIDTH / 2, CLOUD_WIDTH / 2); - - return figure; + } + + public void commentStyle(KRendering r) { + _kRenderingExtensions.setForeground(r, Colors.LIGHT_GOLDENROD); + _kRenderingExtensions.setBackground(r, Colors.PALE_GOLDENROD); + _kRenderingExtensions.setLineWidth(r, 1); + _kRenderingExtensions.setSelectionLineWidth(r, 2); + + if (r.eContainer() instanceof KEdge) { // also color potential arrow heads + _kRenderingExtensions.setBackground(r, Colors.LIGHT_GOLDENROD); + _kRenderingExtensions.getBackground(r).setPropagateToChildren(true); + _kRenderingExtensions.getForeground(r).setPropagateToChildren(true); + _kRenderingExtensions.getLineWidth(r).setPropagateToChildren(true); } - - public KRendering addCloudUploadIcon(KContainerRendering parent) { - KContainerRendering cloudIcon = addCloudIcon(parent); - KPolygon cloudPolygon = _kContainerRenderingExtensions.addPolygon(cloudIcon); - _kRenderingExtensions.setBackground(cloudPolygon, Colors.WHITE); - _kRenderingExtensions.setForeground(cloudPolygon, Colors.WHITE); - cloudPolygon.getPoints().addAll( + } + + private static final int CLOUD_WIDTH = 20; + + public KContainerRendering addCloudIcon(final KContainerRendering parent) { + KRectangle figure = _kContainerRenderingExtensions.addRectangle(parent); + _kRenderingExtensions.setInvisible(figure, true); + + KRoundedRectangle roundRectangle = + _kContainerRenderingExtensions.addRoundedRectangle( + figure, CLOUD_WIDTH / 7, CLOUD_WIDTH / 7); + _kRenderingExtensions.setBackground(roundRectangle, Colors.GRAY); + _kRenderingExtensions.setForeground(roundRectangle, Colors.GRAY); + _kRenderingExtensions.setPointPlacementData( + roundRectangle, + _kRenderingExtensions.LEFT, + 2, + 0, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + 0, + 0, + CLOUD_WIDTH, + CLOUD_WIDTH / 3); + + KEllipse childEllipse = _kContainerRenderingExtensions.addEllipse(figure); + _kRenderingExtensions.setBackground(childEllipse, Colors.GRAY); + _kRenderingExtensions.setForeground(childEllipse, Colors.GRAY); + _kRenderingExtensions.setPointPlacementData( + childEllipse, + _kRenderingExtensions.LEFT, + 0, + 0f, + _kRenderingExtensions.TOP, + 0, + 0.38f, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + 0, + 0, + CLOUD_WIDTH / 2.5f, + CLOUD_WIDTH / 2.5f); + + childEllipse = _kContainerRenderingExtensions.addEllipse(figure); + _kRenderingExtensions.setBackground(childEllipse, Colors.GRAY); + _kRenderingExtensions.setForeground(childEllipse, Colors.GRAY); + _kRenderingExtensions.setPointPlacementData( + childEllipse, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + 0, + 0.25f, + _kRenderingExtensions.H_RIGHT, + _kRenderingExtensions.V_TOP, + 0, + 0, + CLOUD_WIDTH / 3f, + CLOUD_WIDTH / 3f); + + childEllipse = _kContainerRenderingExtensions.addEllipse(figure); + _kRenderingExtensions.setBackground(childEllipse, Colors.GRAY); + _kRenderingExtensions.setForeground(childEllipse, Colors.GRAY); + _kRenderingExtensions.setPointPlacementData( + childEllipse, + _kRenderingExtensions.LEFT, + 0, + 0.4f, + _kRenderingExtensions.TOP, + CLOUD_WIDTH / 10, + 0, + _kRenderingExtensions.H_LEFT, + _kRenderingExtensions.V_TOP, + 0, + 0, + CLOUD_WIDTH / 2, + CLOUD_WIDTH / 2); + + return figure; + } + + public KRendering addCloudUploadIcon(KContainerRendering parent) { + KContainerRendering cloudIcon = addCloudIcon(parent); + KPolygon cloudPolygon = _kContainerRenderingExtensions.addPolygon(cloudIcon); + _kRenderingExtensions.setBackground(cloudPolygon, Colors.WHITE); + _kRenderingExtensions.setForeground(cloudPolygon, Colors.WHITE); + cloudPolygon + .getPoints() + .addAll( List.of( - _kRenderingExtensions.createKPosition(LEFT, -1.5f, 0.5f, TOP, CLOUD_WIDTH / 3, 0.5f), + _kRenderingExtensions.createKPosition( + LEFT, -1.5f, 0.5f, TOP, CLOUD_WIDTH / 3, 0.5f), _kRenderingExtensions.createKPosition(LEFT, -1.5f, 0.5f, TOP, 0, 0.58f), _kRenderingExtensions.createKPosition(LEFT, (-4), 0.5f, TOP, 0, 0.58f), _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.35f), _kRenderingExtensions.createKPosition(LEFT, 4, 0.5f, TOP, 0, 0.58f), _kRenderingExtensions.createKPosition(LEFT, 1.5f, 0.5f, TOP, 0, 0.58f), - _kRenderingExtensions.createKPosition(LEFT, 1.5f, 0.5f, TOP, CLOUD_WIDTH / 3, 0.5f) - ) - ); - return cloudIcon; - } - - private static LabelDecorationConfigurator _onEdgeLabelConfigurator; // ONLY for use in applyOnEdgeStyle - public void applyOnEdgeStyle(KLabel label) { - if (_onEdgeLabelConfigurator == null) { - LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true); - _onEdgeLabelConfigurator = configurator.withLabelTextRenderingProvider( - (KContainerRendering container, KLabel klabel) -> { + _kRenderingExtensions.createKPosition( + LEFT, 1.5f, 0.5f, TOP, CLOUD_WIDTH / 3, 0.5f))); + return cloudIcon; + } + + private static LabelDecorationConfigurator + _onEdgeLabelConfigurator; // ONLY for use in applyOnEdgeStyle + + public void applyOnEdgeStyle(KLabel label) { + if (_onEdgeLabelConfigurator == null) { + LabelDecorationConfigurator configurator = + LabelDecorationConfigurator.create().withInlineLabels(true); + _onEdgeLabelConfigurator = + configurator.withLabelTextRenderingProvider( + (KContainerRendering container, KLabel klabel) -> { KText kText = _kRenderingFactory.createKText(); _kRenderingExtensions.setFontSize(kText, 9); container.getChildren().add(kText); return kText; - }); - } - _onEdgeLabelConfigurator.applyTo(label); + }); } - - private static LabelDecorationConfigurator _onEdgeDelayLabelConfigurator; // ONLY for use in applyOnEdgeDelayStyle - public void applyOnEdgeDelayStyle(KLabel label) { - if (_onEdgeDelayLabelConfigurator == null) { - LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true); - configurator = configurator.withLabelTextRenderingProvider( - (KContainerRendering container, KLabel klabel) -> { - KText kText = _kRenderingFactory.createKText(); - _kRenderingExtensions.setFontSize(kText, 8); - boldTextSelectionStyle(kText); - kText.setProperty(KlighdInternalProperties.MODEL_ELEMEMT, - klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT)); - container.getChildren().add(kText); - return kText; - } - ); - configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() { + _onEdgeLabelConfigurator.applyTo(label); + } + + private static LabelDecorationConfigurator + _onEdgeDelayLabelConfigurator; // ONLY for use in applyOnEdgeDelayStyle + + public void applyOnEdgeDelayStyle(KLabel label) { + if (_onEdgeDelayLabelConfigurator == null) { + LabelDecorationConfigurator configurator = + LabelDecorationConfigurator.create().withInlineLabels(true); + configurator = + configurator.withLabelTextRenderingProvider( + (KContainerRendering container, KLabel klabel) -> { + KText kText = _kRenderingFactory.createKText(); + _kRenderingExtensions.setFontSize(kText, 8); + boldTextSelectionStyle(kText); + kText.setProperty( + KlighdInternalProperties.MODEL_ELEMEMT, + klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT)); + container.getChildren().add(kText); + return kText; + }); + configurator = + configurator.addDecoratorRenderingProvider( + new IDecoratorRenderingProvider() { @Override public ElkPadding createDecoratorRendering( - KContainerRendering container, KLabel label, - LabelDecorationConfigurator.LayoutMode layoutMode) { - ElkPadding padding = new ElkPadding(); - padding.top = 1; - padding.bottom = 1; - padding.left = 2; - padding.right = 2; - - KPolygon polygon = _kRenderingFactory.createKPolygon(); - _kRenderingExtensions.from(polygon, LEFT, (-2), 0, BOTTOM, 0, 0); - _kRenderingExtensions.to(polygon, LEFT, 2, 0, TOP, 0, 0); - _kRenderingExtensions.to(polygon, RIGHT, (-2), 0, TOP, 0, 0); - _kRenderingExtensions.to(polygon, RIGHT, 2, 0, BOTTOM, 0, 0); - _kRenderingExtensions.setBackground(polygon, Colors.WHITE); - _kRenderingExtensions.setForeground(polygon, Colors.WHITE); - container.getChildren().add(polygon); - - KPolyline polyline = _kRenderingFactory.createKPolyline(); - _kRenderingExtensions.from(polyline, LEFT, (-2), 0, BOTTOM, 0, 0); - _kRenderingExtensions.to(polyline, LEFT, 2, 0, TOP, 0, 0); - container.getChildren().add(polyline); - - polyline = _kRenderingFactory.createKPolyline(); - _kRenderingExtensions.from(polyline, RIGHT, 2, 0, BOTTOM, 0, 0); - _kRenderingExtensions.to(polyline, RIGHT, (-2), 0, TOP, 0, 0); - container.getChildren().add(polyline); - - return padding; + KContainerRendering container, + KLabel label, + LabelDecorationConfigurator.LayoutMode layoutMode) { + ElkPadding padding = new ElkPadding(); + padding.top = 1; + padding.bottom = 1; + padding.left = 2; + padding.right = 2; + + KPolygon polygon = _kRenderingFactory.createKPolygon(); + _kRenderingExtensions.from(polygon, LEFT, (-2), 0, BOTTOM, 0, 0); + _kRenderingExtensions.to(polygon, LEFT, 2, 0, TOP, 0, 0); + _kRenderingExtensions.to(polygon, RIGHT, (-2), 0, TOP, 0, 0); + _kRenderingExtensions.to(polygon, RIGHT, 2, 0, BOTTOM, 0, 0); + _kRenderingExtensions.setBackground(polygon, Colors.WHITE); + _kRenderingExtensions.setForeground(polygon, Colors.WHITE); + container.getChildren().add(polygon); + + KPolyline polyline = _kRenderingFactory.createKPolyline(); + _kRenderingExtensions.from(polyline, LEFT, (-2), 0, BOTTOM, 0, 0); + _kRenderingExtensions.to(polyline, LEFT, 2, 0, TOP, 0, 0); + container.getChildren().add(polyline); + + polyline = _kRenderingFactory.createKPolyline(); + _kRenderingExtensions.from(polyline, RIGHT, 2, 0, BOTTOM, 0, 0); + _kRenderingExtensions.to(polyline, RIGHT, (-2), 0, TOP, 0, 0); + container.getChildren().add(polyline); + + return padding; } - }); - _onEdgeDelayLabelConfigurator = configurator; - } - _onEdgeDelayLabelConfigurator.applyTo(label); + }); + _onEdgeDelayLabelConfigurator = configurator; } + _onEdgeDelayLabelConfigurator.applyTo(label); + } - private static LabelDecorationConfigurator _onEdgePysicalDelayLabelConfigurator; // ONLY for use in applyOnEdgePysicalDelayStyle - public void applyOnEdgePysicalDelayStyle(KLabel label, Colors parentBackgroundColor) { - if (_onEdgePysicalDelayLabelConfigurator == null) { - LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true); - configurator = configurator.withLabelTextRenderingProvider( - (KContainerRendering container, KLabel klabel) -> { - KText kText = _kRenderingFactory.createKText(); - _kRenderingExtensions.setFontSize(kText, 8); - boldTextSelectionStyle(kText); - kText.setProperty(KlighdInternalProperties.MODEL_ELEMEMT, - klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT)); - container.getChildren().add(kText); - return kText; - } - ); - configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() { + private static LabelDecorationConfigurator + _onEdgePysicalDelayLabelConfigurator; // ONLY for use in applyOnEdgePysicalDelayStyle + + public void applyOnEdgePysicalDelayStyle(KLabel label, Colors parentBackgroundColor) { + if (_onEdgePysicalDelayLabelConfigurator == null) { + LabelDecorationConfigurator configurator = + LabelDecorationConfigurator.create().withInlineLabels(true); + configurator = + configurator.withLabelTextRenderingProvider( + (KContainerRendering container, KLabel klabel) -> { + KText kText = _kRenderingFactory.createKText(); + _kRenderingExtensions.setFontSize(kText, 8); + boldTextSelectionStyle(kText); + kText.setProperty( + KlighdInternalProperties.MODEL_ELEMEMT, + klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT)); + container.getChildren().add(kText); + return kText; + }); + configurator = + configurator.addDecoratorRenderingProvider( + new IDecoratorRenderingProvider() { @Override public ElkPadding createDecoratorRendering( - KContainerRendering container, - KLabel label, - LabelDecorationConfigurator.LayoutMode layoutMode) { - ElkPadding padding = new ElkPadding(); - padding.top = 1; - padding.bottom = 1; - padding.left = 8; - padding.right = 16; - - KPolygon polygon = _kRenderingFactory.createKPolygon(); - _kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f); - _kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f); - _kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); - _kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); - container.getChildren().add(polygon); - - KSpline kSpline = _kRenderingFactory.createKSpline(); - _kRenderingExtensions.from(kSpline, LEFT, -0.66f, 0, BOTTOM, -0.5f, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, -0.5f, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 3, 0, BOTTOM, 8, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 5, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 5.5f, 0, BOTTOM, -1.5f, 0.5f); - container.getChildren().add(kSpline); - - kSpline = _kRenderingFactory.createKSpline(); - _kRenderingExtensions.from(kSpline, RIGHT, 15f, 0, BOTTOM, 3.5f, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 14f, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 11, 0, BOTTOM, -8, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 9, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 7, 0, BOTTOM, 8, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 4f, 0, BOTTOM, 2, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 1.5f, 0, BOTTOM, 0.5f, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, 0.2f, 0, BOTTOM, -0.5f, 0.5f); - _kRenderingExtensions.to(kSpline, RIGHT, -0.7f, 0, BOTTOM, -0.5f, 0.5f); - container.getChildren().add(kSpline); - - polygon = _kRenderingFactory.createKPolygon(); - _kRenderingExtensions.from(polygon, LEFT, 4, 0, BOTTOM, 0, 0); - _kRenderingExtensions.to(polygon, LEFT, 8, 0, TOP, 0, 0); - _kRenderingExtensions.to(polygon, RIGHT, 12, 0, TOP, 0, 0); - _kRenderingExtensions.to(polygon, RIGHT, 16, 0, BOTTOM, 0, 0); - _kRenderingExtensions.setBackground(polygon, Colors.WHITE); - _kRenderingExtensions.setForeground(polygon, Colors.WHITE); - container.getChildren().add(polygon); - - KPolyline polyline = _kRenderingFactory.createKPolyline(); - _kRenderingExtensions.from(polyline, LEFT, 4, 0, BOTTOM, 0, 0); - _kRenderingExtensions.to(polyline, LEFT, 8, 0, TOP, 0, 0); - container.getChildren().add(polyline); - - polyline = _kRenderingFactory.createKPolyline(); - _kRenderingExtensions.from(polyline, RIGHT, 16, 0, BOTTOM, 0, 0); - _kRenderingExtensions.to(polyline, RIGHT, 12, 0, TOP, 0, 0); - container.getChildren().add(polyline); - - return padding; + KContainerRendering container, + KLabel label, + LabelDecorationConfigurator.LayoutMode layoutMode) { + ElkPadding padding = new ElkPadding(); + padding.top = 1; + padding.bottom = 1; + padding.left = 8; + padding.right = 16; + + KPolygon polygon = _kRenderingFactory.createKPolygon(); + _kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f); + _kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f); + _kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.setBackground( + polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); + _kRenderingExtensions.setForeground( + polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); + container.getChildren().add(polygon); + + KSpline kSpline = _kRenderingFactory.createKSpline(); + _kRenderingExtensions.from(kSpline, LEFT, -0.66f, 0, BOTTOM, -0.5f, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, -0.5f, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 3, 0, BOTTOM, 8, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 5, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 5.5f, 0, BOTTOM, -1.5f, 0.5f); + container.getChildren().add(kSpline); + + kSpline = _kRenderingFactory.createKSpline(); + _kRenderingExtensions.from(kSpline, RIGHT, 15f, 0, BOTTOM, 3.5f, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 14f, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 11, 0, BOTTOM, -8, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 9, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 7, 0, BOTTOM, 8, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 4f, 0, BOTTOM, 2, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 1.5f, 0, BOTTOM, 0.5f, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, 0.2f, 0, BOTTOM, -0.5f, 0.5f); + _kRenderingExtensions.to(kSpline, RIGHT, -0.7f, 0, BOTTOM, -0.5f, 0.5f); + container.getChildren().add(kSpline); + + polygon = _kRenderingFactory.createKPolygon(); + _kRenderingExtensions.from(polygon, LEFT, 4, 0, BOTTOM, 0, 0); + _kRenderingExtensions.to(polygon, LEFT, 8, 0, TOP, 0, 0); + _kRenderingExtensions.to(polygon, RIGHT, 12, 0, TOP, 0, 0); + _kRenderingExtensions.to(polygon, RIGHT, 16, 0, BOTTOM, 0, 0); + _kRenderingExtensions.setBackground(polygon, Colors.WHITE); + _kRenderingExtensions.setForeground(polygon, Colors.WHITE); + container.getChildren().add(polygon); + + KPolyline polyline = _kRenderingFactory.createKPolyline(); + _kRenderingExtensions.from(polyline, LEFT, 4, 0, BOTTOM, 0, 0); + _kRenderingExtensions.to(polyline, LEFT, 8, 0, TOP, 0, 0); + container.getChildren().add(polyline); + + polyline = _kRenderingFactory.createKPolyline(); + _kRenderingExtensions.from(polyline, RIGHT, 16, 0, BOTTOM, 0, 0); + _kRenderingExtensions.to(polyline, RIGHT, 12, 0, TOP, 0, 0); + container.getChildren().add(polyline); + + return padding; } - }); - _onEdgePysicalDelayLabelConfigurator = configurator; - } - label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor); - _onEdgePysicalDelayLabelConfigurator.applyTo(label); + }); + _onEdgePysicalDelayLabelConfigurator = configurator; } - - private static LabelDecorationConfigurator _onEdgePysicalLabelConfigurator; // ONLY for use in applyOnEdgePysicalStyle - public void applyOnEdgePysicalStyle(KLabel label, Colors parentBackgroundColor) { - if (_onEdgePysicalLabelConfigurator == null) { - LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true); - configurator = configurator.withLabelTextRenderingProvider( - (KContainerRendering container, KLabel klabel) -> { - KText kText = _kRenderingFactory.createKText(); - _kRenderingExtensions.setInvisible(kText, true); - container.getChildren().add(kText); - return kText; - } - ); - configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() { + label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor); + _onEdgePysicalDelayLabelConfigurator.applyTo(label); + } + + private static LabelDecorationConfigurator + _onEdgePysicalLabelConfigurator; // ONLY for use in applyOnEdgePysicalStyle + + public void applyOnEdgePysicalStyle(KLabel label, Colors parentBackgroundColor) { + if (_onEdgePysicalLabelConfigurator == null) { + LabelDecorationConfigurator configurator = + LabelDecorationConfigurator.create().withInlineLabels(true); + configurator = + configurator.withLabelTextRenderingProvider( + (KContainerRendering container, KLabel klabel) -> { + KText kText = _kRenderingFactory.createKText(); + _kRenderingExtensions.setInvisible(kText, true); + container.getChildren().add(kText); + return kText; + }); + configurator = + configurator.addDecoratorRenderingProvider( + new IDecoratorRenderingProvider() { @Override - public ElkPadding createDecoratorRendering(final KContainerRendering container, final KLabel label, final LabelDecorationConfigurator.LayoutMode layoutMode) { - ElkPadding padding = new ElkPadding(); - padding.top = 1; - padding.bottom = 1; - padding.left = 3; - padding.right = 3; - - KPolygon polygon = _kRenderingFactory.createKPolygon(); - _kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f); - _kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f); - _kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f); - _kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); - _kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); - container.getChildren().add(polygon); - - KSpline kSpline = _kRenderingFactory.createKSpline(); - _kRenderingExtensions.from(kSpline, LEFT, (-0.66f), 0, BOTTOM, (-0.5f), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, (-0.5f), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.1f, BOTTOM, 8, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.2f, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.3f, BOTTOM, (-8), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.4f, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.45f, BOTTOM, 4f, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.5f, BOTTOM, 8, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.55f, BOTTOM, 4f, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.6f, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.65f, BOTTOM, (-4), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.7f, BOTTOM, (-8), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.8f, BOTTOM, (-4), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0, 0.9f, BOTTOM, 0, 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, (-1), 1, BOTTOM, (-0.5f), 0.5f); - _kRenderingExtensions.to(kSpline, LEFT, 0.66f, 1, BOTTOM, (-0.5f), 0.5f); - container.getChildren().add(kSpline); - return padding; + public ElkPadding createDecoratorRendering( + final KContainerRendering container, + final KLabel label, + final LabelDecorationConfigurator.LayoutMode layoutMode) { + ElkPadding padding = new ElkPadding(); + padding.top = 1; + padding.bottom = 1; + padding.left = 3; + padding.right = 3; + + KPolygon polygon = _kRenderingFactory.createKPolygon(); + _kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f); + _kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f); + _kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f); + _kRenderingExtensions.setBackground( + polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); + _kRenderingExtensions.setForeground( + polygon, label.getProperty(LABEL_PARENT_BACKGROUND)); + container.getChildren().add(polygon); + + KSpline kSpline = _kRenderingFactory.createKSpline(); + _kRenderingExtensions.from(kSpline, LEFT, (-0.66f), 0, BOTTOM, (-0.5f), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, (-0.5f), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.1f, BOTTOM, 8, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.2f, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.3f, BOTTOM, (-8), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.4f, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.45f, BOTTOM, 4f, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.5f, BOTTOM, 8, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.55f, BOTTOM, 4f, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.6f, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.65f, BOTTOM, (-4), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.7f, BOTTOM, (-8), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.8f, BOTTOM, (-4), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0, 0.9f, BOTTOM, 0, 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, (-1), 1, BOTTOM, (-0.5f), 0.5f); + _kRenderingExtensions.to(kSpline, LEFT, 0.66f, 1, BOTTOM, (-0.5f), 0.5f); + container.getChildren().add(kSpline); + return padding; } - }); - _onEdgePysicalLabelConfigurator = configurator; - } - label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor); - _onEdgePysicalLabelConfigurator.applyTo(label); + }); + _onEdgePysicalLabelConfigurator = configurator; } + label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor); + _onEdgePysicalLabelConfigurator.applyTo(label); + } - public KRendering addFixedTailArrowDecorator(KPolyline pl) { - KRendering head = _kPolylineExtensions.addTailArrowDecorator(pl); - KDecoratorPlacementData placement = _kRenderingFactory.createKDecoratorPlacementData(); - placement.setRotateWithLine(true); - placement.setRelative(0f); - placement.setAbsolute(2f); - placement.setWidth(8); - placement.setHeight(6); - placement.setXOffset(-3f); - placement.setYOffset(-4f); - head.setPlacementData(placement); - return head; - } - - public void addArrayDecorator(KEdge edge, Integer size) { - final KRendering line = _kRenderingExtensions.getKRendering(edge); - if (line instanceof KPolyline) { - KDecoratorPlacementData placement = _kRenderingFactory.createKDecoratorPlacementData(); - placement.setRotateWithLine(true); - placement.setRelative(0f); - placement.setAbsolute(6f); - - KPolyline slash = _kContainerRenderingExtensions.addChild( - (KContainerRendering) line, - _kRenderingFactory.createKPolyline()); - slash.getPoints().add( - _kRenderingExtensions.createKPosition( - _kRenderingExtensions.RIGHT, 0, 0, - _kRenderingExtensions.TOP, 0, 0) - ); - slash.getPoints().add( - _kRenderingExtensions.createKPosition( - _kRenderingExtensions.LEFT, 0, 0, - _kRenderingExtensions.BOTTOM, 0, 0) - ); - KDecoratorPlacementData slashPlacement = EcoreUtil.copy(placement); - slashPlacement.setWidth(5); - slashPlacement.setHeight(10); - slashPlacement.setYOffset(-5f); - slash.setPlacementData(slashPlacement); - - if (size != null) { - KText num = _kContainerRenderingExtensions.addChild( - (KContainerRendering) line, - _kRenderingFactory.createKText() - ); - num.setText(size.toString()); - _kRenderingExtensions.setFontSize(num, 5); - noSelectionStyle(num); - KDecoratorPlacementData numPlacement = EcoreUtil.copy(placement); - numPlacement.setXOffset(2f); - num.setPlacementData(numPlacement); - } - } + public KRendering addFixedTailArrowDecorator(KPolyline pl) { + KRendering head = _kPolylineExtensions.addTailArrowDecorator(pl); + KDecoratorPlacementData placement = _kRenderingFactory.createKDecoratorPlacementData(); + placement.setRotateWithLine(true); + placement.setRelative(0f); + placement.setAbsolute(2f); + placement.setWidth(8); + placement.setHeight(6); + placement.setXOffset(-3f); + placement.setYOffset(-4f); + head.setPlacementData(placement); + return head; + } + + public void addArrayDecorator(KEdge edge, Integer size) { + final KRendering line = _kRenderingExtensions.getKRendering(edge); + if (line instanceof KPolyline) { + KDecoratorPlacementData placement = _kRenderingFactory.createKDecoratorPlacementData(); + placement.setRotateWithLine(true); + placement.setRelative(0f); + placement.setAbsolute(6f); + + KPolyline slash = + _kContainerRenderingExtensions.addChild( + (KContainerRendering) line, _kRenderingFactory.createKPolyline()); + slash + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.RIGHT, 0, 0, _kRenderingExtensions.TOP, 0, 0)); + slash + .getPoints() + .add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.LEFT, 0, 0, _kRenderingExtensions.BOTTOM, 0, 0)); + KDecoratorPlacementData slashPlacement = EcoreUtil.copy(placement); + slashPlacement.setWidth(5); + slashPlacement.setHeight(10); + slashPlacement.setYOffset(-5f); + slash.setPlacementData(slashPlacement); + + if (size != null) { + KText num = + _kContainerRenderingExtensions.addChild( + (KContainerRendering) line, _kRenderingFactory.createKText()); + num.setText(size.toString()); + _kRenderingExtensions.setFontSize(num, 5); + noSelectionStyle(num); + KDecoratorPlacementData numPlacement = EcoreUtil.copy(placement); + numPlacement.setXOffset(2f); + num.setPlacementData(numPlacement); + } } -} \ No newline at end of file + } +} diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java b/org.lflang/src/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java index a7ca735f29..aab539926b 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java @@ -1,26 +1,24 @@ /** * Copyright (c) 2020, Kiel University. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *

    Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + *

    1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + *

    2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided with + * the distribution. + * + *

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lflang.diagram.synthesis.styles; @@ -31,81 +29,77 @@ import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; public class ReactorFigureComponents { - private final KContainerRendering outer; + private final KContainerRendering outer; - private final KContainerRendering reactor; + private final KContainerRendering reactor; - private final List figures; + private final List figures; - public ReactorFigureComponents(KContainerRendering outer, - KContainerRendering reactor, - List figures) { - super(); - this.outer = outer; - this.reactor = reactor; - this.figures = figures; - } + public ReactorFigureComponents( + KContainerRendering outer, KContainerRendering reactor, List figures) { + super(); + this.outer = outer; + this.reactor = reactor; + this.figures = figures; + } - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.outer== null) ? 0 : this.outer.hashCode()); - result = prime * result + ((this.reactor== null) ? 0 : this.reactor.hashCode()); - return prime * result + ((this.figures== null) ? 0 : this.figures.hashCode()); - } + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.outer == null) ? 0 : this.outer.hashCode()); + result = prime * result + ((this.reactor == null) ? 0 : this.reactor.hashCode()); + return prime * result + ((this.figures == null) ? 0 : this.figures.hashCode()); + } - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ReactorFigureComponents other = (ReactorFigureComponents) obj; - if (this.outer == null && other.outer != null) { - return false; - } else if (!this.outer.equals(other.outer)) { - return false; - } - if (this.reactor == null && other.reactor != null) { - return false; - } else if (!this.reactor.equals(other.reactor)) { - return false; - } - if (this.figures == null && other.figures != null) { - return false; - } else if (!this.figures.equals(other.figures)) { - return false; - } - return true; + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + ReactorFigureComponents other = (ReactorFigureComponents) obj; + if (this.outer == null && other.outer != null) { + return false; + } else if (!this.outer.equals(other.outer)) { + return false; } - - @Override - @Pure - public String toString() { - ToStringBuilder b = new ToStringBuilder(this); - b.add("outer", this.outer); - b.add("reactor", this.reactor); - b.add("figures", this.figures); - return b.toString(); + if (this.reactor == null && other.reactor != null) { + return false; + } else if (!this.reactor.equals(other.reactor)) { + return false; } - - @Pure - public KContainerRendering getOuter() { - return this.outer; + if (this.figures == null && other.figures != null) { + return false; + } else if (!this.figures.equals(other.figures)) { + return false; } + return true; + } - @Pure - public KContainerRendering getReactor() { - return this.reactor; - } + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("outer", this.outer); + b.add("reactor", this.reactor); + b.add("figures", this.figures); + return b.toString(); + } - @Pure - public List getFigures() { - return this.figures; - } + @Pure + public KContainerRendering getOuter() { + return this.outer; + } + + @Pure + public KContainerRendering getReactor() { + return this.reactor; + } + + @Pure + public List getFigures() { + return this.figures; + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/CycleVisualization.java b/org.lflang/src/org/lflang/diagram/synthesis/util/CycleVisualization.java index 0fc52b0665..4fb313fe4b 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/CycleVisualization.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/CycleVisualization.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; import com.google.common.collect.HashMultimap; @@ -43,115 +43,114 @@ /** * Dependency cycle detection for Lingua Franca diagrams. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class CycleVisualization extends AbstractSynthesisExtensions { - - // Properties for marking diagram elements - public static final Property DEPENDENCY_CYCLE = new Property<>("org.lflang.diagram.synthesis.dependency.cycle", false); - @Inject @Extension private UtilityExtensions _utilityExtensions; - - /** - * Performs cycle detection based on the diagram's graph structure and applies given highlighting to the included elements - */ - public boolean detectAndHighlightCycles(ReactorInstance rootReactorInstance, - Map allReactorNodes, - Consumer highlighter) { - - if (rootReactorInstance.hasCycles() && highlighter != null) { - // Highlight cycles - // A cycle consists of reactions and ports. - HashMultimap> cycleElementsByReactor = HashMultimap.create(); - Set> cycles = rootReactorInstance.getCycles(); - for (NamedInstance element : cycles) { - // First find the involved reactor instances - if (element instanceof ReactorInstance) { - cycleElementsByReactor.put((ReactorInstance) element, element); - } else { - cycleElementsByReactor.put(element.getParent(), element); - } - } - - for (ReactorInstance reactor : cycleElementsByReactor.keySet()) { - KNode node = allReactorNodes.get(reactor); - if (node != null) { - node.setProperty(DEPENDENCY_CYCLE, true); - highlighter.accept(node); + // Properties for marking diagram elements + public static final Property DEPENDENCY_CYCLE = + new Property<>("org.lflang.diagram.synthesis.dependency.cycle", false); + + @Inject @Extension private UtilityExtensions _utilityExtensions; - Set> reactorContentInCycle = cycleElementsByReactor.get(reactor); - - // Reactor edges - for (KEdge edge : node.getOutgoingEdges()) { - if (connectsCycleElements(edge, cycles)) { - edge.setProperty(DEPENDENCY_CYCLE, true); - highlighter.accept(edge); - } - } + /** + * Performs cycle detection based on the diagram's graph structure and applies given highlighting + * to the included elements + */ + public boolean detectAndHighlightCycles( + ReactorInstance rootReactorInstance, + Map allReactorNodes, + Consumer highlighter) { - // Reactor ports - for (KPort port : node.getPorts()) { - if (reactorContentInCycle.contains(NamedInstanceUtil.getLinkedInstance(port))) { - port.setProperty(DEPENDENCY_CYCLE, true); - highlighter.accept(port); - } - } + if (rootReactorInstance.hasCycles() && highlighter != null) { + // Highlight cycles + // A cycle consists of reactions and ports. + HashMultimap> cycleElementsByReactor = + HashMultimap.create(); + Set> cycles = rootReactorInstance.getCycles(); + for (NamedInstance element : cycles) { + // First find the involved reactor instances + if (element instanceof ReactorInstance) { + cycleElementsByReactor.put((ReactorInstance) element, element); + } else { + cycleElementsByReactor.put(element.getParent(), element); + } + } - // Child Nodes - for (KNode childNode : node.getChildren()) { - if (reactorContentInCycle.contains(NamedInstanceUtil.getLinkedInstance(childNode)) && - !_utilityExtensions.sourceIsReactor(childNode)) { - childNode.setProperty(DEPENDENCY_CYCLE, true); - highlighter.accept(childNode); + for (ReactorInstance reactor : cycleElementsByReactor.keySet()) { + KNode node = allReactorNodes.get(reactor); + if (node != null) { + node.setProperty(DEPENDENCY_CYCLE, true); + highlighter.accept(node); + + Set> reactorContentInCycle = cycleElementsByReactor.get(reactor); + + // Reactor edges + for (KEdge edge : node.getOutgoingEdges()) { + if (connectsCycleElements(edge, cycles)) { + edge.setProperty(DEPENDENCY_CYCLE, true); + highlighter.accept(edge); + } + } - for (KEdge edge : childNode.getOutgoingEdges()) { - if (connectsCycleElements(edge, cycles)) { - edge.setProperty(DEPENDENCY_CYCLE, true); - highlighter.accept(edge); - } - } - } - } + // Reactor ports + for (KPort port : node.getPorts()) { + if (reactorContentInCycle.contains(NamedInstanceUtil.getLinkedInstance(port))) { + port.setProperty(DEPENDENCY_CYCLE, true); + highlighter.accept(port); + } + } + + // Child Nodes + for (KNode childNode : node.getChildren()) { + if (reactorContentInCycle.contains(NamedInstanceUtil.getLinkedInstance(childNode)) + && !_utilityExtensions.sourceIsReactor(childNode)) { + childNode.setProperty(DEPENDENCY_CYCLE, true); + highlighter.accept(childNode); + + for (KEdge edge : childNode.getOutgoingEdges()) { + if (connectsCycleElements(edge, cycles)) { + edge.setProperty(DEPENDENCY_CYCLE, true); + highlighter.accept(edge); } + } } - return true; - } - return false; - } - - /** - * Checks whether an edge connects two elements that are part of the cycle. - * Assumes that the source node is always part of the cycle! - */ - private boolean connectsCycleElements(KEdge edge, Set> cycle) { - return ( - // if source is not a reactor, there is nothing to check - !_utilityExtensions.sourceIsReactor(edge.getSource()) - || - // otherwise, the source port must be on the cycle - cycle.contains(NamedInstanceUtil.getLinkedInstance(edge.getSourcePort())) - ) && ( - // leads to reactor port in cycle - _utilityExtensions.sourceIsReactor(edge.getTarget()) - && - cycle.contains(NamedInstanceUtil.getLinkedInstance(edge.getTargetPort())) - || - // leads to reaction in cycle - !_utilityExtensions.sourceIsReactor(edge.getTarget()) - && - cycle.contains(NamedInstanceUtil.getLinkedInstance(edge.getTarget())) - ) && ( - // Special case only for connections - !(_utilityExtensions.sourceElement(edge) instanceof Connection) - || ( - // If the edge represents a connections between two ports in the cycle (checked before), - // then it is only included in the actual cycle, if it is neither delayed nor physical. - ((Connection) _utilityExtensions.sourceElement(edge)).getDelay() == null - && - !((Connection) _utilityExtensions.sourceElement(edge)).isPhysical() - ) - ); + } + } + } + return true; } + return false; + } + + /** + * Checks whether an edge connects two elements that are part of the cycle. Assumes that the + * source node is always part of the cycle! + */ + private boolean connectsCycleElements(KEdge edge, Set> cycle) { + return ( + // if source is not a reactor, there is nothing to check + !_utilityExtensions.sourceIsReactor(edge.getSource()) + || + // otherwise, the source port must be on the cycle + cycle.contains(NamedInstanceUtil.getLinkedInstance(edge.getSourcePort()))) + && ( + // leads to reactor port in cycle + _utilityExtensions.sourceIsReactor(edge.getTarget()) + && cycle.contains(NamedInstanceUtil.getLinkedInstance(edge.getTargetPort())) + || + // leads to reaction in cycle + !_utilityExtensions.sourceIsReactor(edge.getTarget()) + && cycle.contains(NamedInstanceUtil.getLinkedInstance(edge.getTarget()))) + && ( + // Special case only for connections + !(_utilityExtensions.sourceElement(edge) instanceof Connection) + || ( + // If the edge represents a connections between two ports in the cycle (checked before), + // then it is only included in the actual cycle, if it is neither delayed nor physical. + ((Connection) _utilityExtensions.sourceElement(edge)).getDelay() == null + && !((Connection) _utilityExtensions.sourceElement(edge)).isPhysical())); + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java b/org.lflang/src/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java index 41635fb7c7..e3de923847 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; import com.google.common.collect.ImmutableList; @@ -64,143 +64,177 @@ /** * Utility class to handle dependency edges for collapsed reactors in Lingua Franca diagrams. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class InterfaceDependenciesVisualization extends AbstractSynthesisExtensions { - - // Related synthesis option - public static final SynthesisOption SHOW_INTERFACE_DEPENDENCIES = SynthesisOption.createCheckOption("Port Dependencies in Collapsed Reactors", false).setCategory(LinguaFrancaSynthesis.APPEARANCE); - - // Properties for marking diagram elements - public static final Property INTERFACE_DEPENDENCY = new Property<>("org.lflang.linguafranca.diagram.synthesis.dependency.interface", false); - - @Inject @Extension private KEdgeExtensions _kEdgeExtensions; - @Inject @Extension private KRenderingExtensions _kRenderingExtensions; - @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; - @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; - @Inject @Extension private UtilityExtensions _utilityExtensions; - - /** - * Updates the visibility of interface dependencies edges based on the expansion state. - */ - public static void updateInterfaceDependencyVisibility(KNode node, boolean expanded) { - Iterable edges = IterableExtensions.filter(node.getOutgoingEdges(), it -> { - return it.getProperty(INTERFACE_DEPENDENCY); - }); - - Iterable> renders = IterableExtensions.map(edges, (KEdge it) -> { - return Iterables.filter(it.getData(), KRendering.class); - }); - - Iterables.concat(renders).forEach( + + // Related synthesis option + public static final SynthesisOption SHOW_INTERFACE_DEPENDENCIES = + SynthesisOption.createCheckOption("Port Dependencies in Collapsed Reactors", false) + .setCategory(LinguaFrancaSynthesis.APPEARANCE); + + // Properties for marking diagram elements + public static final Property INTERFACE_DEPENDENCY = + new Property<>("org.lflang.linguafranca.diagram.synthesis.dependency.interface", false); + + @Inject @Extension private KEdgeExtensions _kEdgeExtensions; + @Inject @Extension private KRenderingExtensions _kRenderingExtensions; + @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; + @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; + @Inject @Extension private UtilityExtensions _utilityExtensions; + + /** Updates the visibility of interface dependencies edges based on the expansion state. */ + public static void updateInterfaceDependencyVisibility(KNode node, boolean expanded) { + Iterable edges = + IterableExtensions.filter( + node.getOutgoingEdges(), it -> { - KInvisibility inv = IterableExtensions.last(Iterables.filter(it.getStyles(), KInvisibility.class)); - if (inv == null) { - inv = KRenderingFactory.eINSTANCE.createKInvisibility(); - it.getStyles().add(inv); - } - inv.setInvisible(expanded); - } - ); - } + return it.getProperty(INTERFACE_DEPENDENCY); + }); + + Iterable> renders = + IterableExtensions.map( + edges, + (KEdge it) -> { + return Iterables.filter(it.getData(), KRendering.class); + }); + + Iterables.concat(renders) + .forEach( + it -> { + KInvisibility inv = + IterableExtensions.last(Iterables.filter(it.getStyles(), KInvisibility.class)); + if (inv == null) { + inv = KRenderingFactory.eINSTANCE.createKInvisibility(); + it.getStyles().add(inv); + } + inv.setInvisible(expanded); + }); + } + + /** + * Adds interface dependencies to the node if this option is active. Visibility will be adjusted + * based on expansion state. + */ + public Spacing addInterfaceDependencies(KNode node, boolean expanded) { + Spacing marginInit = null; + if (getBooleanValue(SHOW_INTERFACE_DEPENDENCIES)) { + List> deps = getPortDependencies(node); + if (!deps.isEmpty()) { + for (Pair pair : deps) { + createDependencyEdge(pair, expanded); + } - /** - * Adds interface dependencies to the node if this option is active. - * Visibility will be adjusted based on expansion state. - */ - public Spacing addInterfaceDependencies(KNode node, boolean expanded) { - Spacing marginInit = null; - if (getBooleanValue(SHOW_INTERFACE_DEPENDENCIES)) { - List> deps = getPortDependencies(node); - if (!deps.isEmpty()) { - for (Pair pair : deps) { - createDependencyEdge(pair, expanded); - } - - // Fix content (label) of collapsed rendering - KContainerRendering contentContainer = IterableExtensions.findFirst( - Iterables.filter(node.getData(), KContainerRendering.class), - it -> { return it.getProperty(KlighdProperties.COLLAPSED_RENDERING); } - ); - if (contentContainer != null) { - if (!contentContainer.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER)) { - contentContainer = IteratorExtensions.findFirst( - Iterators.filter(contentContainer.eAllContents(), KContainerRendering.class), - it -> { return it.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER); } - ); - } - if (contentContainer != null) { - List content = ImmutableList.copyOf(contentContainer.getChildren()); - // Put into two new containers such that they are not centered/maximized - KRectangle firstContainer = _kContainerRenderingExtensions.addRectangle(contentContainer); - _kRenderingExtensions.setInvisible(firstContainer, true); - - KRectangle secondContainer = _kContainerRenderingExtensions.addRectangle(firstContainer); - _kRenderingExtensions.setInvisible(secondContainer, true); - _kContainerRenderingExtensions.setGridPlacement(secondContainer, 1); - Iterables.addAll(secondContainer.getChildren(), content); - _kRenderingExtensions.setPointPlacementData(secondContainer, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.TOP, 0, 0, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_TOP, 0, - 0, 0, 0); - - - // Adjust ports separate dependency edges from label/content - if (content.size() > 0) { - marginInit = _utilityExtensions.getPortMarginsInitIfAbsent(node).add( - new ElkMargin((content.size() * 20) - 8, 0, 0, 0) - ); - } - } - } + // Fix content (label) of collapsed rendering + KContainerRendering contentContainer = + IterableExtensions.findFirst( + Iterables.filter(node.getData(), KContainerRendering.class), + it -> { + return it.getProperty(KlighdProperties.COLLAPSED_RENDERING); + }); + if (contentContainer != null) { + if (!contentContainer.getProperty( + LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER)) { + contentContainer = + IteratorExtensions.findFirst( + Iterators.filter(contentContainer.eAllContents(), KContainerRendering.class), + it -> { + return it.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER); + }); + } + if (contentContainer != null) { + List content = ImmutableList.copyOf(contentContainer.getChildren()); + // Put into two new containers such that they are not centered/maximized + KRectangle firstContainer = + _kContainerRenderingExtensions.addRectangle(contentContainer); + _kRenderingExtensions.setInvisible(firstContainer, true); + + KRectangle secondContainer = + _kContainerRenderingExtensions.addRectangle(firstContainer); + _kRenderingExtensions.setInvisible(secondContainer, true); + _kContainerRenderingExtensions.setGridPlacement(secondContainer, 1); + Iterables.addAll(secondContainer.getChildren(), content); + _kRenderingExtensions.setPointPlacementData( + secondContainer, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + 0, + 0, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_TOP, + 0, + 0, + 0, + 0); + + // Adjust ports separate dependency edges from label/content + if (content.size() > 0) { + marginInit = + _utilityExtensions + .getPortMarginsInitIfAbsent(node) + .add(new ElkMargin((content.size() * 20) - 8, 0, 0, 0)); } + } } - return marginInit; - } - - /** - * Find dependencies between ports. - */ - private List> getPortDependencies(KNode node) { - Set inputPorts = IterableExtensions.toSet(IterableExtensions.filter( - node.getPorts(), - it -> { return it.getProperty(LinguaFrancaSynthesis.REACTOR_INPUT); }) - ); - Set outputPorts = IterableExtensions.toSet(IterableExtensions.filter( - node.getPorts(), - it -> { return it.getProperty(LinguaFrancaSynthesis.REACTOR_OUTPUT); }) - ); - - // FIXME Replace with real logic - Random rand = new Random(); - return IterableExtensions.toList( - IterableExtensions.map(IterableExtensions.filter( - Sets.cartesianProduct(inputPorts, outputPorts), - it -> { return rand.nextBoolean(); }), - it -> { return new Pair(it.get(0), it.get(1)); })); - } - - /** - * Create an edges for interface dependencies and adjust visibility based on the expansion state of the node. - */ - private KEdge createDependencyEdge(final Pair connection, final boolean expanded) { - KEdge depEdge = _kEdgeExtensions.createEdge(); - depEdge.setSource(connection.getKey().getNode()); - depEdge.setSourcePort(connection.getKey()); - depEdge.setTarget(connection.getValue().getNode()); - depEdge.setTargetPort(connection.getValue()); - depEdge.setProperty(InterfaceDependenciesVisualization.INTERFACE_DEPENDENCY, true); - depEdge.setProperty(CoreOptions.NO_LAYOUT, true); // no routing! - DiagramSyntheses.suppressSelectability(depEdge); - - KPolyline polyline = _kEdgeExtensions.addPolyline(depEdge); - _kRenderingExtensions.setLineStyle(polyline, LineStyle.DOT); - _linguaFrancaStyleExtensions.noSelectionStyle(polyline); - _kRenderingExtensions.setInvisible(polyline, expanded); // make sure there is a style to toggle! - - return depEdge; + } } + return marginInit; + } + + /** Find dependencies between ports. */ + private List> getPortDependencies(KNode node) { + Set inputPorts = + IterableExtensions.toSet( + IterableExtensions.filter( + node.getPorts(), + it -> { + return it.getProperty(LinguaFrancaSynthesis.REACTOR_INPUT); + })); + Set outputPorts = + IterableExtensions.toSet( + IterableExtensions.filter( + node.getPorts(), + it -> { + return it.getProperty(LinguaFrancaSynthesis.REACTOR_OUTPUT); + })); + + // FIXME Replace with real logic + Random rand = new Random(); + return IterableExtensions.toList( + IterableExtensions.map( + IterableExtensions.filter( + Sets.cartesianProduct(inputPorts, outputPorts), + it -> { + return rand.nextBoolean(); + }), + it -> { + return new Pair(it.get(0), it.get(1)); + })); + } + + /** + * Create an edges for interface dependencies and adjust visibility based on the expansion state + * of the node. + */ + private KEdge createDependencyEdge(final Pair connection, final boolean expanded) { + KEdge depEdge = _kEdgeExtensions.createEdge(); + depEdge.setSource(connection.getKey().getNode()); + depEdge.setSourcePort(connection.getKey()); + depEdge.setTarget(connection.getValue().getNode()); + depEdge.setTargetPort(connection.getValue()); + depEdge.setProperty(InterfaceDependenciesVisualization.INTERFACE_DEPENDENCY, true); + depEdge.setProperty(CoreOptions.NO_LAYOUT, true); // no routing! + DiagramSyntheses.suppressSelectability(depEdge); + + KPolyline polyline = _kEdgeExtensions.addPolyline(depEdge); + _kRenderingExtensions.setLineStyle(polyline, LineStyle.DOT); + _linguaFrancaStyleExtensions.noSelectionStyle(polyline); + _kRenderingExtensions.setInvisible(polyline, expanded); // make sure there is a style to toggle! + + return depEdge; + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java b/org.lflang/src/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java index e3264c4b75..33a9b02167 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java @@ -1,33 +1,36 @@ /************* -* Copyright (c) 2022, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2022, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; +import de.cau.cs.kieler.klighd.SynthesisOption; +import de.cau.cs.kieler.klighd.kgraph.KNode; +import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; +import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses; import java.util.Arrays; import java.util.Comparator; import java.util.List; - import org.eclipse.elk.alg.layered.components.ComponentOrderingStrategy; import org.eclipse.elk.alg.layered.options.CrossingMinimizationStrategy; import org.eclipse.elk.alg.layered.options.CycleBreakingStrategy; @@ -41,326 +44,392 @@ import org.lflang.diagram.synthesis.LinguaFrancaSynthesis; import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable; -import de.cau.cs.kieler.klighd.SynthesisOption; -import de.cau.cs.kieler.klighd.kgraph.KNode; -import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; -import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses; - /** * Set layout configuration options for the Lingua Franca diagram synthesis. - * + * * @author Sören Domrös */ @ViewSynthesisShared 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. - */ - public static final String FULL_CONTROL = "Full Control"; - - - public static final SynthesisOption MODEL_ORDER = - SynthesisOption.createChoiceOption( - MODEL_ORDER_OPTION, - Arrays.asList(TIE_BREAKER, STRICT_REACTION_ONLY, STRICT, FULL_CONTROL), - STRICT_REACTION_ONLY).setCategory(LinguaFrancaSynthesis.LAYOUT); + /** 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. + */ + public static final String FULL_CONTROL = "Full Control"; - /** - * Comparator to sort KNodes based on the textual order of their linked instances. - * - * Startup, reset and shutdown actions are not in the model and are handled separately: - * Startup actions will always be first. - * Reset actions follow after the startup action. - * Shutdown is always sorted last. However, shutdown actions will not have a model order set and are, therefore, - * implicitly ordered by their connection. - */ - public static final Comparator TEXTUAL_ORDER = new Comparator() { + public static final SynthesisOption MODEL_ORDER = + SynthesisOption.createChoiceOption( + MODEL_ORDER_OPTION, + Arrays.asList(TIE_BREAKER, STRICT_REACTION_ONLY, STRICT, FULL_CONTROL), + STRICT_REACTION_ONLY) + .setCategory(LinguaFrancaSynthesis.LAYOUT); + + /** + * Comparator to sort KNodes based on the textual order of their linked instances. + * + *

    Startup, reset and shutdown actions are not in the model and are handled separately: Startup + * actions will always be first. Reset actions follow after the startup action. Shutdown is always + * sorted last. However, shutdown actions will not have a model order set and are, therefore, + * implicitly ordered by their connection. + */ + public static final Comparator TEXTUAL_ORDER = + new Comparator() { @Override public int compare(KNode node1, KNode node2) { - var pos1 = getTextPosition(node1); - var pos2 = getTextPosition(node2); - if (pos1 >= 0 && pos1 >= 0) { - return Integer.compare(pos1, pos2); // textual order - } else if (pos1 >= 0) { - return -1; // unassociated elements last - } else if (pos2 >= 0) { - return 1; // unassociated elements last - } - return Integer.compare(node1.hashCode(), node2.hashCode()); // any stable order between unassociated elements + var pos1 = getTextPosition(node1); + var pos2 = getTextPosition(node2); + if (pos1 >= 0 && pos1 >= 0) { + return Integer.compare(pos1, pos2); // textual order + } else if (pos1 >= 0) { + return -1; // unassociated elements last + } else if (pos2 >= 0) { + return 1; // unassociated elements last + } + return Integer.compare( + node1.hashCode(), node2.hashCode()); // any stable order between unassociated elements } - + private int getTextPosition(KNode node) { - var instance = NamedInstanceUtil.getLinkedInstance(node); - if (instance != null) { - var definition = instance.getDefinition(); - if (definition instanceof BuiltinTriggerVariable) { - // special handling for built-in triggers - switch(((BuiltinTriggerVariable)definition).type) { - case STARTUP: return 0; // first - case RESET: return 1; // second - case SHUTDOWN: return Integer.MAX_VALUE; // last - } - } else if (definition instanceof EObject) { - var ast = NodeModelUtils.getNode((EObject) definition); - if (ast != null) { - return ast.getOffset(); - } - } + var instance = NamedInstanceUtil.getLinkedInstance(node); + if (instance != null) { + var definition = instance.getDefinition(); + if (definition instanceof BuiltinTriggerVariable) { + // special handling for built-in triggers + switch (((BuiltinTriggerVariable) definition).type) { + case STARTUP: + return 0; // first + case RESET: + return 1; // second + case SHUTDOWN: + return Integer.MAX_VALUE; // last + } + } else if (definition instanceof EObject) { + var ast = NodeModelUtils.getNode((EObject) definition); + if (ast != null) { + return ast.getOffset(); + } } - return -1; + } + return -1; } - }; + }; - /** - * Configures layout options for main reactor. - * - * @param node The KNode of the main reactor. - */ - public void configureMainReactor(KNode node) { - configureReactor(node); - } + /** + * Configures layout options for main reactor. + * + * @param node The KNode of the main reactor. + */ + public void configureMainReactor(KNode node) { + configureReactor(node); + } - /** - * Configures layout options for a reactor. - * - * @param node The KNode of a reactor. - */ - public void configureReactor(KNode node) { - String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - - switch (modelOrderStrategy) { - case LEGACY: - // Otherwise nodes are not sorted if they are not connected - DiagramSyntheses.setLayoutOption(node, CoreOptions.SEPARATE_CONNECTED_COMPONENTS, false); - // Needed to enforce node positions. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_SEMI_INTERACTIVE, true); - // Costs a little more time but layout is quick, therefore, we can do that. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.THOROUGHNESS, 100); - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.TWO_SIDED); - break; - case STRICT_REACTION_ONLY: - // Only set model order for reactions. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); - // Do tie-breaking model order cycle breaking. - // Minimize number of backward edges but make decisions based on the model order if no greedy best alternative exists. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.GREEDY_MODEL_ORDER); - // Before crossing minimization sort all nodes and edges/ports but also consider the node model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); - // Separate connected components should be drawn separately. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); - // Component order is enforced by looking at the minimum element with respect to model order of each component. - // Remember that the startUp action is always the first node. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, ComponentOrderingStrategy.FORCE_MODEL_ORDER); - DiagramSyntheses.setLayoutOption(node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); + /** + * Configures layout options for a reactor. + * + * @param node The KNode of a reactor. + */ + public void configureReactor(KNode node) { + String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - // Node order should not change during crossing minimization. - // Since only reactions will have a model order set in this approach the order of reactions in their respective - // separate connected components always respects the model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_FORCE_NODE_MODEL_ORDER, true); - // Disable greedy switch since this does otherwise change the node order after crossing minimization. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.OFF); - break; - case STRICT: - // Do tie-breaking model order cycle breaking. - // Minimize number of backward edges but make decisions based on the model order if no greedy best alternative exists. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.GREEDY_MODEL_ORDER); - // Before crossing minimization sort all nodes and edges/ports but also consider the node model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); - // Separate connected components should be drawn separately. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); - // Component order is enforced by looking at the minimum element with respect to model order of each component. - // Remember that the startUp action is always the first node. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, ComponentOrderingStrategy.FORCE_MODEL_ORDER); - DiagramSyntheses.setLayoutOption(node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); - - // Node order should not change during crossing minimization. - // Since only reactions and reactors will have a model order set in this approach the order of reactions and reactors in their respective - // separate connected components always respects the model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_FORCE_NODE_MODEL_ORDER, true); - // Disable greedy switch since this does otherwise change the node order after crossing minimization. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.OFF); - break; - case TIE_BREAKER: - // Do tie-breaking model order cycle breaking. - // Minimize number of backward edges but make decisions based on the model order if no greedy best alternative exists. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.GREEDY_MODEL_ORDER); - // Before crossing minimization sort all nodes and edges/ports but also consider the node model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); - // Separate connected components should be drawn separately. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); - // Component order is enforced by looking at the minimum element with respect to model order of each component. - // Remember that the startUp action is always the first node. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, ComponentOrderingStrategy.FORCE_MODEL_ORDER); - DiagramSyntheses.setLayoutOption(node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); - // During crossing minimization 10 node order violations are regarded as important as 1 edge crossing. - // In reality this chooses the best node order from all tries. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_CROSSING_COUNTER_NODE_INFLUENCE, 0.1); - // Increase the number of tries with different starting configurations. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.THOROUGHNESS, 100); + switch (modelOrderStrategy) { + case LEGACY: + // Otherwise nodes are not sorted if they are not connected + DiagramSyntheses.setLayoutOption(node, CoreOptions.SEPARATE_CONNECTED_COMPONENTS, false); + // Needed to enforce node positions. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_SEMI_INTERACTIVE, true); + // Costs a little more time but layout is quick, therefore, we can do that. + DiagramSyntheses.setLayoutOption(node, LayeredOptions.THOROUGHNESS, 100); + DiagramSyntheses.setLayoutOption( + node, + LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, + GreedySwitchType.TWO_SIDED); + break; + case STRICT_REACTION_ONLY: + // Only set model order for reactions. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); + // Do tie-breaking model order cycle breaking. + // Minimize number of backward edges but make decisions based on the model order if no + // greedy best alternative exists. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.GREEDY_MODEL_ORDER); + // Before crossing minimization sort all nodes and edges/ports but also consider the node + // model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); + // Separate connected components should be drawn separately. + DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); + // Component order is enforced by looking at the minimum element with respect to model order + // of each component. + // Remember that the startUp action is always the first node. + DiagramSyntheses.setLayoutOption( + node, + LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, + ComponentOrderingStrategy.FORCE_MODEL_ORDER); + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); - break; - case FULL_CONTROL: - // Do strict model order cycle breaking. This may introduce unnecessary backward edges. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.MODEL_ORDER); - // Before crossing minimization sort all nodes and edges/ports but also consider the node model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); - // Separate connected components should be drawn separately. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); - // Component order is enforced by looking at the minimum element with respect to model order of each component. - // Remember that the startUp action is always the first node. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, ComponentOrderingStrategy.FORCE_MODEL_ORDER); - DiagramSyntheses.setLayoutOption(node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); - // Disable all kinds of crossing minimization entirely. Just take what is in the model and just do it. - // This requires that the list of nodes is not ordered by type, e.g. first all reactions, then all reactors, then all actions, ... - // but by their model order. In other approaches ordering actions between the reactions has no effect. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_STRATEGY, CrossingMinimizationStrategy.NONE); - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.OFF); - - break; - default: - // Do nothing. - } - } + // Node order should not change during crossing minimization. + // Since only reactions will have a model order set in this approach the order of reactions + // in their respective + // separate connected components always respects the model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_FORCE_NODE_MODEL_ORDER, true); + // Disable greedy switch since this does otherwise change the node order after crossing + // minimization. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.OFF); + break; + case STRICT: + // Do tie-breaking model order cycle breaking. + // Minimize number of backward edges but make decisions based on the model order if no + // greedy best alternative exists. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.GREEDY_MODEL_ORDER); + // Before crossing minimization sort all nodes and edges/ports but also consider the node + // model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); + // Separate connected components should be drawn separately. + DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); + // Component order is enforced by looking at the minimum element with respect to model order + // of each component. + // Remember that the startUp action is always the first node. + DiagramSyntheses.setLayoutOption( + node, + LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, + ComponentOrderingStrategy.FORCE_MODEL_ORDER); + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); - /** - * Configures layout options for an action. - * - * @param node The KNode of an action. - */ - public void configureAction(KNode node) { - String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - - switch (modelOrderStrategy) { - case STRICT_REACTION_ONLY: - case STRICT: - case TIE_BREAKER: - // Actions have no model order since their ordering in the model cannot be compared to the order of - // for example reactions since they are generally defined below in inputs/outputs and above the reactions. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); - break; - case FULL_CONTROL: - // Give actions a model order since they should be controllable too. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, false); - break; - default: - // Do nothing. - } - } + // Node order should not change during crossing minimization. + // Since only reactions and reactors will have a model order set in this approach the order + // of reactions and reactors in their respective + // separate connected components always respects the model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_FORCE_NODE_MODEL_ORDER, true); + // Disable greedy switch since this does otherwise change the node order after crossing + // minimization. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.OFF); + break; + case TIE_BREAKER: + // Do tie-breaking model order cycle breaking. + // Minimize number of backward edges but make decisions based on the model order if no + // greedy best alternative exists. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.GREEDY_MODEL_ORDER); + // Before crossing minimization sort all nodes and edges/ports but also consider the node + // model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); + // Separate connected components should be drawn separately. + DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); + // Component order is enforced by looking at the minimum element with respect to model order + // of each component. + // Remember that the startUp action is always the first node. + DiagramSyntheses.setLayoutOption( + node, + LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, + ComponentOrderingStrategy.FORCE_MODEL_ORDER); + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); + // During crossing minimization 10 node order violations are regarded as important as 1 edge + // crossing. + // In reality this chooses the best node order from all tries. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_CROSSING_COUNTER_NODE_INFLUENCE, 0.1); + // Increase the number of tries with different starting configurations. + DiagramSyntheses.setLayoutOption(node, LayeredOptions.THOROUGHNESS, 100); - /** - * Configures layout options for a timer. - * - * @param node The KNode of a timer. - */ - public void configureTimer(KNode node) { - String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - - switch (modelOrderStrategy) { - case STRICT_REACTION_ONLY: - case STRICT: - case TIE_BREAKER: - // Timers have no model order since their ordering in the model cannot be compared to the order of - // for example reactions since they are generally defined below in inputs/outputs and above the reactions. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); - break; - case FULL_CONTROL: - // Give timers a model order since they should be controllable too. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, false); - break; - default: - // Do nothing. - } + break; + case FULL_CONTROL: + // Do strict model order cycle breaking. This may introduce unnecessary backward edges. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.MODEL_ORDER); + // Before crossing minimization sort all nodes and edges/ports but also consider the node + // model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.NODES_AND_EDGES); + // Separate connected components should be drawn separately. + DiagramSyntheses.setLayoutOption(node, LayeredOptions.SEPARATE_CONNECTED_COMPONENTS, true); + // Component order is enforced by looking at the minimum element with respect to model order + // of each component. + // Remember that the startUp action is always the first node. + DiagramSyntheses.setLayoutOption( + node, + LayeredOptions.CONSIDER_MODEL_ORDER_COMPONENTS, + ComponentOrderingStrategy.FORCE_MODEL_ORDER); + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.COMPACTION_CONNECTED_COMPONENTS, true); + // Disable all kinds of crossing minimization entirely. Just take what is in the model and + // just do it. + // This requires that the list of nodes is not ordered by type, e.g. first all reactions, + // then all reactors, then all actions, ... + // but by their model order. In other approaches ordering actions between the reactions has + // no effect. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_STRATEGY, CrossingMinimizationStrategy.NONE); + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CROSSING_MINIMIZATION_GREEDY_SWITCH_TYPE, GreedySwitchType.OFF); + + break; + default: + // Do nothing. } + } + + /** + * Configures layout options for an action. + * + * @param node The KNode of an action. + */ + public void configureAction(KNode node) { + String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - /** - * Configures layout options for a startup action. - * - * @param node The KNode of a startup action. - */ - public void configureStartUp(KNode node) { - // Nothing should be done. Model order is considered per default value. - // The actual ordering of this node has to be done in the synthesis. + switch (modelOrderStrategy) { + case STRICT_REACTION_ONLY: + case STRICT: + case TIE_BREAKER: + // Actions have no model order since their ordering in the model cannot be compared to the + // order of + // for example reactions since they are generally defined below in inputs/outputs and above + // the reactions. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); + break; + case FULL_CONTROL: + // Give actions a model order since they should be controllable too. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, false); + break; + default: + // Do nothing. } + } - /** - * Configures layout options for a shutdown action. - * - * @param node The KNode of a shutdown action. - */ - public void configureShutDown(KNode node) { - String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - - switch (modelOrderStrategy) { - case STRICT_REACTION_ONLY: - case STRICT: - case TIE_BREAKER: - case FULL_CONTROL: - // The shutdown node cannot have a high model order, since this would confuse cycle breaking. - // It also cannot have a low model order. - // It should have none at all and the other nodes should define its position. - // This is no problem since the shutdown node has only outgoing edges. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); - break; - default: - // Do nothing. - } + /** + * Configures layout options for a timer. + * + * @param node The KNode of a timer. + */ + public void configureTimer(KNode node) { + String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); + + switch (modelOrderStrategy) { + case STRICT_REACTION_ONLY: + case STRICT: + case TIE_BREAKER: + // Timers have no model order since their ordering in the model cannot be compared to the + // order of + // for example reactions since they are generally defined below in inputs/outputs and above + // the reactions. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); + break; + case FULL_CONTROL: + // Give timers a model order since they should be controllable too. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, false); + break; + default: + // Do nothing. } + } + + /** + * Configures layout options for a startup action. + * + * @param node The KNode of a startup action. + */ + public void configureStartUp(KNode node) { + // Nothing should be done. Model order is considered per default value. + // The actual ordering of this node has to be done in the synthesis. + } - /** - * Configures layout options for a reaction. - * Currently a reaction does not have internal behavior that is visualized and its order is always considered, - * therefore, nothing needs to be done. - * - * @param node The KNode of a reaction. - */ - public void configureReaction(KNode node) { - // Has no internal behavior and model order is set by default. + /** + * Configures layout options for a shutdown action. + * + * @param node The KNode of a shutdown action. + */ + public void configureShutDown(KNode node) { + String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); + + switch (modelOrderStrategy) { + case STRICT_REACTION_ONLY: + case STRICT: + case TIE_BREAKER: + case FULL_CONTROL: + // The shutdown node cannot have a high model order, since this would confuse cycle + // breaking. + // It also cannot have a low model order. + // It should have none at all and the other nodes should define its position. + // This is no problem since the shutdown node has only outgoing edges. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); + break; + default: + // Do nothing. } + } - /** - * Configures layout options for a dummy node. - * - * @param node The KNode of a dummy node. - */ - public void configureDummy(KNode node) { - String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - - switch (modelOrderStrategy) { - case STRICT_REACTION_ONLY: - case STRICT: - case TIE_BREAKER: - case FULL_CONTROL: - // A dummy node has no model order. - DiagramSyntheses.setLayoutOption(node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); - break; - default: - // Do nothing. - } + /** + * Configures layout options for a reaction. Currently a reaction does not have internal behavior + * that is visualized and its order is always considered, therefore, nothing needs to be done. + * + * @param node The KNode of a reaction. + */ + public void configureReaction(KNode node) { + // Has no internal behavior and model order is set by default. + } + + /** + * Configures layout options for a dummy node. + * + * @param node The KNode of a dummy node. + */ + public void configureDummy(KNode node) { + String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); + + switch (modelOrderStrategy) { + case STRICT_REACTION_ONLY: + case STRICT: + case TIE_BREAKER: + case FULL_CONTROL: + // A dummy node has no model order. + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); + break; + default: + // Do nothing. } + } - /** - * Orders a list of nodes by their corresponding linked instance if synthesis option for full control is enabled. - * Ordering is done by the {@link #TEXTUAL_ORDER} comparator. - * - * @param nodes List of KNodes to be ordered. - */ - public void orderChildren(List nodes) { - String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); - if (FULL_CONTROL.equals(modelOrderStrategy)) { - nodes.sort(TEXTUAL_ORDER); - } + /** + * Orders a list of nodes by their corresponding linked instance if synthesis option for full + * control is enabled. Ordering is done by the {@link #TEXTUAL_ORDER} comparator. + * + * @param nodes List of KNodes to be ordered. + */ + public void orderChildren(List nodes) { + String modelOrderStrategy = (String) getObjectValue(MODEL_ORDER); + if (FULL_CONTROL.equals(modelOrderStrategy)) { + nodes.sort(TEXTUAL_ORDER); } + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/ModeDiagrams.java b/org.lflang/src/org/lflang/diagram/synthesis/util/ModeDiagrams.java index 7222df3cf1..18c13e2b1f 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/ModeDiagrams.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/ModeDiagrams.java @@ -1,30 +1,62 @@ /************* -* Copyright (c) 2021, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2021, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; - +import com.google.common.collect.LinkedHashMultimap; +import com.google.inject.Inject; +import de.cau.cs.kieler.klighd.SynthesisOption; +import de.cau.cs.kieler.klighd.kgraph.KEdge; +import de.cau.cs.kieler.klighd.kgraph.KIdentifier; +import de.cau.cs.kieler.klighd.kgraph.KLabel; +import de.cau.cs.kieler.klighd.kgraph.KNode; +import de.cau.cs.kieler.klighd.kgraph.KPort; +import de.cau.cs.kieler.klighd.krendering.Colors; +import de.cau.cs.kieler.klighd.krendering.HorizontalAlignment; +import de.cau.cs.kieler.klighd.krendering.KContainerRendering; +import de.cau.cs.kieler.klighd.krendering.KDecoratorPlacementData; +import de.cau.cs.kieler.klighd.krendering.KEllipse; +import de.cau.cs.kieler.klighd.krendering.KPolyline; +import de.cau.cs.kieler.klighd.krendering.KRectangle; +import de.cau.cs.kieler.klighd.krendering.KRendering; +import de.cau.cs.kieler.klighd.krendering.KRenderingFactory; +import de.cau.cs.kieler.klighd.krendering.KText; +import de.cau.cs.kieler.klighd.krendering.LineStyle; +import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; +import de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KPortExtensions; +import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions; +import de.cau.cs.kieler.klighd.labels.decoration.ITextRenderingProvider; +import de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator; +import de.cau.cs.kieler.klighd.labels.decoration.LinesDecorator; +import de.cau.cs.kieler.klighd.labels.decoration.RectangleDecorator; +import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses; +import de.cau.cs.kieler.klighd.util.KlighdProperties; import java.awt.Color; import java.util.EnumSet; import java.util.HashMap; @@ -33,7 +65,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.stream.Collectors; - import org.eclipse.elk.alg.layered.options.CenterEdgeLabelPlacementStrategy; import org.eclipse.elk.alg.layered.options.EdgeStraighteningStrategy; import org.eclipse.elk.alg.layered.options.FixedAlignment; @@ -57,8 +88,8 @@ import org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions; import org.lflang.diagram.synthesis.styles.LinguaFrancaStyleExtensions; import org.lflang.generator.ModeInstance; -import org.lflang.generator.NamedInstance; import org.lflang.generator.ModeInstance.Transition; +import org.lflang.generator.NamedInstance; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Mode; @@ -66,531 +97,648 @@ import org.lflang.lf.Reactor; import org.lflang.lf.Timer; -import com.google.common.collect.LinkedHashMultimap; -import com.google.inject.Inject; - -import de.cau.cs.kieler.klighd.SynthesisOption; -import de.cau.cs.kieler.klighd.kgraph.KEdge; -import de.cau.cs.kieler.klighd.kgraph.KIdentifier; -import de.cau.cs.kieler.klighd.kgraph.KLabel; -import de.cau.cs.kieler.klighd.kgraph.KNode; -import de.cau.cs.kieler.klighd.kgraph.KPort; -import de.cau.cs.kieler.klighd.krendering.Colors; -import de.cau.cs.kieler.klighd.krendering.HorizontalAlignment; -import de.cau.cs.kieler.klighd.krendering.KContainerRendering; -import de.cau.cs.kieler.klighd.krendering.KDecoratorPlacementData; -import de.cau.cs.kieler.klighd.krendering.KEllipse; -import de.cau.cs.kieler.klighd.krendering.KPolyline; -import de.cau.cs.kieler.klighd.krendering.KRectangle; -import de.cau.cs.kieler.klighd.krendering.KRendering; -import de.cau.cs.kieler.klighd.krendering.KRenderingFactory; -import de.cau.cs.kieler.klighd.krendering.KText; -import de.cau.cs.kieler.klighd.krendering.LineStyle; -import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; -import de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KPortExtensions; -import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions; -import de.cau.cs.kieler.klighd.labels.decoration.ITextRenderingProvider; -import de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator; -import de.cau.cs.kieler.klighd.labels.decoration.LinesDecorator; -import de.cau.cs.kieler.klighd.labels.decoration.RectangleDecorator; -import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses; -import de.cau.cs.kieler.klighd.util.KlighdProperties; - /** * Transformations to support modes in the Lingua Franca diagram synthesis. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class ModeDiagrams extends AbstractSynthesisExtensions { - - // Related synthesis option - public static final SynthesisOption MODES_CATEGORY = - SynthesisOption.createCategory("Modes", false).setCategory(LinguaFrancaSynthesis.APPEARANCE); - public static final SynthesisOption SHOW_TRANSITION_LABELS = - SynthesisOption.createCheckOption("Transition Labels", true).setCategory(MODES_CATEGORY); - public static final SynthesisOption INITIALLY_COLLAPSE_MODES = - SynthesisOption.createCheckOption("Initially Collapse Modes", true).setCategory(MODES_CATEGORY); - - private static final Colors MODE_FG = Colors.SLATE_GRAY; - private static final Colors MODE_BG = Colors.SLATE_GRAY_3; - private static final int MODE_BG_ALPHA = 50; - - @Inject @Extension private KNodeExtensions _kNodeExtensions; - @Inject @Extension private KEdgeExtensions _kEdgeExtensions; - @Inject @Extension private KPortExtensions _kPortExtensions; - @Inject @Extension private KLabelExtensions _kLabelExtensions; - @Inject @Extension private KPolylineExtensions _kPolylineExtensions; - @Inject @Extension private KRenderingExtensions _kRenderingExtensions; - @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; - @Inject @Extension private LinguaFrancaShapeExtensions _linguaFrancaShapeExtensions; - @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; - @Inject @Extension private UtilityExtensions _utilityExtensions; - @Inject @Extension private LayoutPostProcessing _layoutPostProcessing; - - @Extension private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; - - public void handleModes(List nodes, ReactorInstance reactor) { - if (!reactor.modes.isEmpty()) { - var modeNodes = new LinkedHashMap(); - var modeDefinitionMap = new LinkedHashMap(); - for (ModeInstance mode : reactor.modes) { - var node = _kNodeExtensions.createNode(); - associateWith(node, mode.getDefinition()); - NamedInstanceUtil.linkInstance(node, mode); - _utilityExtensions.setID(node, mode.uniqueID()); - - modeNodes.put(mode, node); - modeDefinitionMap.put(mode.getDefinition(), mode); - - // Layout - if (mode.isInitial()) { - DiagramSyntheses.setLayoutOption(node, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); - } - // Use general layout configuration of reactors - this.getRootSynthesis().configureReactorNodeLayout(node, false); - _layoutPostProcessing.configureReactor(node); - // Adjust for modes - DiagramSyntheses.setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FREE); - - var expansionState = MemorizingExpandCollapseAction.getExpansionState(mode); - DiagramSyntheses.setLayoutOption(node, KlighdProperties.EXPAND, - expansionState != null ? expansionState : !this.getBooleanValue(INITIALLY_COLLAPSE_MODES)); - - // Expanded Rectangle - var expandFigure = addModeFigure(node, mode, true); - expandFigure.setProperty(KlighdProperties.EXPANDED_RENDERING, true); - _kRenderingExtensions.addDoubleClickAction(expandFigure, MemorizingExpandCollapseAction.ID); - - if (getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS)) { - // Collapse button - KText textButton = _linguaFrancaShapeExtensions.addTextButton(expandFigure, LinguaFrancaSynthesis.TEXT_HIDE_ACTION); - _kRenderingExtensions.to( - _kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(textButton), - _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 0, 0); - _kRenderingExtensions.addSingleClickAction(textButton, MemorizingExpandCollapseAction.ID); - _kRenderingExtensions.addDoubleClickAction(textButton, MemorizingExpandCollapseAction.ID); - } - - if (getBooleanValue(LinguaFrancaSynthesis.SHOW_STATE_VARIABLES)) { - // Add mode-local state variables - var variables = mode.getDefinition().getStateVars(); - if (!variables.isEmpty()) { - KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(expandFigure); - _kRenderingExtensions.setInvisible(rectangle, true); - if (!getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS)) { - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 4, 0); - } else { - _kRenderingExtensions.to( - _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(rectangle), - _kRenderingExtensions.LEFT, 6, 0, - _kRenderingExtensions.TOP, 4, 0), - _kRenderingExtensions.RIGHT, 6, 0, - _kRenderingExtensions.BOTTOM, 0, 0); - } - _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); - this.getRootSynthesis().addStateVariableList(rectangle, variables); - } - } - - _kContainerRenderingExtensions.addChildArea(expandFigure); - - // Collapse Rectangle - var collapseFigure = addModeFigure(node, mode, false); - collapseFigure.setProperty(KlighdProperties.COLLAPSED_RENDERING, true); - if (this.hasContent(mode)) { - _kRenderingExtensions.addDoubleClickAction(collapseFigure, MemorizingExpandCollapseAction.ID); - - if (getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS)) { - // Expand button - KText textButton = _linguaFrancaShapeExtensions.addTextButton(collapseFigure, LinguaFrancaSynthesis.TEXT_SHOW_ACTION); - _kRenderingExtensions.to(_kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(textButton), - _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0), - _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 8, 0); - _kRenderingExtensions.addSingleClickAction(textButton, MemorizingExpandCollapseAction.ID); - _kRenderingExtensions.addDoubleClickAction(textButton, MemorizingExpandCollapseAction.ID); - } - } + + // Related synthesis option + public static final SynthesisOption MODES_CATEGORY = + SynthesisOption.createCategory("Modes", false).setCategory(LinguaFrancaSynthesis.APPEARANCE); + public static final SynthesisOption SHOW_TRANSITION_LABELS = + SynthesisOption.createCheckOption("Transition Labels", true).setCategory(MODES_CATEGORY); + public static final SynthesisOption INITIALLY_COLLAPSE_MODES = + SynthesisOption.createCheckOption("Initially Collapse Modes", true) + .setCategory(MODES_CATEGORY); + + private static final Colors MODE_FG = Colors.SLATE_GRAY; + private static final Colors MODE_BG = Colors.SLATE_GRAY_3; + private static final int MODE_BG_ALPHA = 50; + + @Inject @Extension private KNodeExtensions _kNodeExtensions; + @Inject @Extension private KEdgeExtensions _kEdgeExtensions; + @Inject @Extension private KPortExtensions _kPortExtensions; + @Inject @Extension private KLabelExtensions _kLabelExtensions; + @Inject @Extension private KPolylineExtensions _kPolylineExtensions; + @Inject @Extension private KRenderingExtensions _kRenderingExtensions; + @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; + @Inject @Extension private LinguaFrancaShapeExtensions _linguaFrancaShapeExtensions; + @Inject @Extension private LinguaFrancaStyleExtensions _linguaFrancaStyleExtensions; + @Inject @Extension private UtilityExtensions _utilityExtensions; + @Inject @Extension private LayoutPostProcessing _layoutPostProcessing; + + @Extension private KRenderingFactory _kRenderingFactory = KRenderingFactory.eINSTANCE; + + public void handleModes(List nodes, ReactorInstance reactor) { + if (!reactor.modes.isEmpty()) { + var modeNodes = new LinkedHashMap(); + var modeDefinitionMap = new LinkedHashMap(); + for (ModeInstance mode : reactor.modes) { + var node = _kNodeExtensions.createNode(); + associateWith(node, mode.getDefinition()); + NamedInstanceUtil.linkInstance(node, mode); + _utilityExtensions.setID(node, mode.uniqueID()); + + modeNodes.put(mode, node); + modeDefinitionMap.put(mode.getDefinition(), mode); + + // Layout + if (mode.isInitial()) { + DiagramSyntheses.setLayoutOption( + node, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST); + } + // Use general layout configuration of reactors + this.getRootSynthesis().configureReactorNodeLayout(node, false); + _layoutPostProcessing.configureReactor(node); + // Adjust for modes + DiagramSyntheses.setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FREE); + + var expansionState = MemorizingExpandCollapseAction.getExpansionState(mode); + DiagramSyntheses.setLayoutOption( + node, + KlighdProperties.EXPAND, + expansionState != null + ? expansionState + : !this.getBooleanValue(INITIALLY_COLLAPSE_MODES)); + + // Expanded Rectangle + var expandFigure = addModeFigure(node, mode, true); + expandFigure.setProperty(KlighdProperties.EXPANDED_RENDERING, true); + _kRenderingExtensions.addDoubleClickAction(expandFigure, MemorizingExpandCollapseAction.ID); + + if (getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS)) { + // Collapse button + KText textButton = + _linguaFrancaShapeExtensions.addTextButton( + expandFigure, LinguaFrancaSynthesis.TEXT_HIDE_ACTION); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(textButton), + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); + _kRenderingExtensions.addSingleClickAction(textButton, MemorizingExpandCollapseAction.ID); + _kRenderingExtensions.addDoubleClickAction(textButton, MemorizingExpandCollapseAction.ID); + } + + if (getBooleanValue(LinguaFrancaSynthesis.SHOW_STATE_VARIABLES)) { + // Add mode-local state variables + var variables = mode.getDefinition().getStateVars(); + if (!variables.isEmpty()) { + KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(expandFigure); + _kRenderingExtensions.setInvisible(rectangle, true); + if (!getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS)) { + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 4, + 0); + } else { + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(rectangle), + _kRenderingExtensions.LEFT, + 6, + 0, + _kRenderingExtensions.TOP, + 4, + 0), + _kRenderingExtensions.RIGHT, + 6, + 0, + _kRenderingExtensions.BOTTOM, + 0, + 0); } - - var modeChildren = LinkedHashMultimap.create(); - var nodeModes = new HashMap(); - for (var node : nodes) { - var instance = NamedInstanceUtil.getLinkedInstance(node); - if (instance == null && node.getProperty(CoreOptions.COMMENT_BOX)) { - var firstEdge = IterableExtensions.head(node.getOutgoingEdges()); - if (firstEdge != null && firstEdge.getTarget() != null) { - instance = NamedInstanceUtil.getLinkedInstance(firstEdge.getTarget()); - } - } - if (instance != null) { - var mode = instance.getMode(true); - modeChildren.put(mode, node); - nodeModes.put(node, mode); - } else { - modeChildren.put(null, node); - } + _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT); + this.getRootSynthesis() + .addStateVariableList(rectangle, variables); + } + } + + _kContainerRenderingExtensions.addChildArea(expandFigure); + + // Collapse Rectangle + var collapseFigure = addModeFigure(node, mode, false); + collapseFigure.setProperty(KlighdProperties.COLLAPSED_RENDERING, true); + if (this.hasContent(mode)) { + _kRenderingExtensions.addDoubleClickAction( + collapseFigure, MemorizingExpandCollapseAction.ID); + + if (getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS)) { + // Expand button + KText textButton = + _linguaFrancaShapeExtensions.addTextButton( + collapseFigure, LinguaFrancaSynthesis.TEXT_SHOW_ACTION); + _kRenderingExtensions.to( + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(textButton), + _kRenderingExtensions.LEFT, + 8, + 0, + _kRenderingExtensions.TOP, + 0, + 0), + _kRenderingExtensions.RIGHT, + 8, + 0, + _kRenderingExtensions.BOTTOM, + 8, + 0); + _kRenderingExtensions.addSingleClickAction( + textButton, MemorizingExpandCollapseAction.ID); + _kRenderingExtensions.addDoubleClickAction( + textButton, MemorizingExpandCollapseAction.ID); + } + } + } + + var modeChildren = LinkedHashMultimap.create(); + var nodeModes = new HashMap(); + for (var node : nodes) { + var instance = NamedInstanceUtil.getLinkedInstance(node); + if (instance == null && node.getProperty(CoreOptions.COMMENT_BOX)) { + var firstEdge = IterableExtensions.head(node.getOutgoingEdges()); + if (firstEdge != null && firstEdge.getTarget() != null) { + instance = NamedInstanceUtil.getLinkedInstance(firstEdge.getTarget()); + } + } + if (instance != null) { + var mode = instance.getMode(true); + modeChildren.put(mode, node); + nodeModes.put(node, mode); + } else { + modeChildren.put(null, node); + } + } + + var modeContainer = _kNodeExtensions.createNode(); + modeContainer.getChildren().addAll(modeNodes.values()); + var modeContainerFigure = addModeContainerFigure(modeContainer); + _kRenderingExtensions.addDoubleClickAction( + modeContainerFigure, MemorizingExpandCollapseAction.ID); + + // Use general layout configuration of reactors + this.getRootSynthesis() + .configureReactorNodeLayout(modeContainer, false); + _layoutPostProcessing.configureReactor(modeContainer); + // Adjust for state machine style + // Create alternating directions to make the model more compact + DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.DIRECTION, Direction.DOWN); + // More state machine like node placement + DiagramSyntheses.setLayoutOption( + modeContainer, + LayeredOptions.NODE_PLACEMENT_STRATEGY, + NodePlacementStrategy.BRANDES_KOEPF); + DiagramSyntheses.setLayoutOption( + modeContainer, LayeredOptions.NODE_PLACEMENT_BK_FIXED_ALIGNMENT, FixedAlignment.BALANCED); + DiagramSyntheses.setLayoutOption( + modeContainer, + LayeredOptions.NODE_PLACEMENT_BK_EDGE_STRAIGHTENING, + EdgeStraighteningStrategy.IMPROVE_STRAIGHTNESS); + // Splines + DiagramSyntheses.setLayoutOption( + modeContainer, CoreOptions.EDGE_ROUTING, EdgeRouting.SPLINES); + DiagramSyntheses.setLayoutOption( + modeContainer, + LayeredOptions.EDGE_LABELS_CENTER_LABEL_PLACEMENT_STRATEGY, + CenterEdgeLabelPlacementStrategy.TAIL_LAYER); + DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.SPACING_NODE_SELF_LOOP, 18.0); + // Unreachable states are unlikely + DiagramSyntheses.setLayoutOption( + modeContainer, CoreOptions.SEPARATE_CONNECTED_COMPONENTS, false); + // Equal padding + DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.PADDING, new ElkPadding(6)); + if (reactor.modes.stream() + .anyMatch(m -> m.transitions.stream().anyMatch(t -> t.type == ModeTransition.HISTORY))) { + // Make additional space for history indicator + DiagramSyntheses.setLayoutOption( + modeContainer, + LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, + modeContainer.getProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS) + + (getBooleanValue(SHOW_TRANSITION_LABELS) ? 6.0 : 10.0)); + } + + var modeContainerPorts = new HashMap(); + for (var mode : reactor.modes) { + var modeNode = modeNodes.get(mode); + var edges = new LinkedHashSet(); + // add children + for (var child : modeChildren.get(mode)) { + nodes.remove(child); + modeNode.getChildren().add(child); + + edges.addAll(child.getIncomingEdges()); + edges.addAll(child.getOutgoingEdges()); + } + + // add transitions + var representedTargets = new HashSet>(); + for (var transition : mode.transitions) { + if (!representedTargets.contains( + new Pair(transition.target, transition.type))) { + var edge = _kEdgeExtensions.createEdge(); + edge.setSource(modeNode); + edge.setTarget(modeNodes.get(transition.target)); + addTransitionFigure(edge, transition); + + if (getBooleanValue(SHOW_TRANSITION_LABELS)) { + associateWith(edge, transition.getDefinition()); + } else { + // Bundle similar transitions + representedTargets.add( + new Pair(transition.target, transition.type)); + } + } + } + + // handle cross hierarchy edges + var portCopies = new HashMap(); + var triggerCopies = new HashMap(); + for (var edge : edges) { + if (!edge.getProperty(CoreOptions.NO_LAYOUT)) { + var sourceNodeMode = nodeModes.get(edge.getSource()); + if (sourceNodeMode == null) { + sourceNodeMode = nodeModes.get(edge.getSource().getParent()); } - - var modeContainer = _kNodeExtensions.createNode(); - modeContainer.getChildren().addAll(modeNodes.values()); - var modeContainerFigure = addModeContainerFigure(modeContainer); - _kRenderingExtensions.addDoubleClickAction(modeContainerFigure, MemorizingExpandCollapseAction.ID); - - // Use general layout configuration of reactors - this.getRootSynthesis().configureReactorNodeLayout(modeContainer, false); - _layoutPostProcessing.configureReactor(modeContainer); - // Adjust for state machine style - // Create alternating directions to make the model more compact - DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.DIRECTION, Direction.DOWN); - // More state machine like node placement - DiagramSyntheses.setLayoutOption(modeContainer, LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.BRANDES_KOEPF); - DiagramSyntheses.setLayoutOption(modeContainer, LayeredOptions.NODE_PLACEMENT_BK_FIXED_ALIGNMENT, FixedAlignment.BALANCED); - DiagramSyntheses.setLayoutOption(modeContainer, LayeredOptions.NODE_PLACEMENT_BK_EDGE_STRAIGHTENING, EdgeStraighteningStrategy.IMPROVE_STRAIGHTNESS); - // Splines - DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.EDGE_ROUTING, EdgeRouting.SPLINES); - DiagramSyntheses.setLayoutOption(modeContainer, LayeredOptions.EDGE_LABELS_CENTER_LABEL_PLACEMENT_STRATEGY, CenterEdgeLabelPlacementStrategy.TAIL_LAYER); - DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.SPACING_NODE_SELF_LOOP, 18.0); - // Unreachable states are unlikely - DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.SEPARATE_CONNECTED_COMPONENTS, false); - // Equal padding - DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.PADDING, new ElkPadding(6)); - if (reactor.modes.stream().anyMatch(m -> m.transitions.stream().anyMatch(t -> t.type == ModeTransition.HISTORY))) { - // Make additional space for history indicator - DiagramSyntheses.setLayoutOption(modeContainer, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, - modeContainer.getProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS) - + (getBooleanValue(SHOW_TRANSITION_LABELS) ? 6.0 : 10.0)); + var sourceIsInMode = sourceNodeMode != null; + var targetNodeMode = nodeModes.get(edge.getTarget()); + if (targetNodeMode == null) { + targetNodeMode = nodeModes.get(edge.getTarget().getParent()); } + var targetIsInMode = targetNodeMode != null; + + if (!sourceIsInMode || !targetIsInMode) { + var node = sourceIsInMode ? edge.getTarget() : edge.getSource(); + + if (node.getProperty(LinguaFrancaSynthesis.REACTION_SPECIAL_TRIGGER)) { + // Duplicate trigger node + if (!triggerCopies.containsKey(node)) { + var copy = EcoreUtil.copy(node); + modeNode + .getChildren() + .add(modeNode.getChildren().indexOf(edge.getTarget()), copy); + triggerCopies.put(node, copy); - var modeContainerPorts = new HashMap(); - for (var mode : reactor.modes) { - var modeNode = modeNodes.get(mode); - var edges = new LinkedHashSet(); - // add children - for (var child : modeChildren.get(mode)) { - nodes.remove(child); - modeNode.getChildren().add(child); - - edges.addAll(child.getIncomingEdges()); - edges.addAll(child.getOutgoingEdges()); + // Adjust copy + copy.getOutgoingEdges() + .forEach( + e -> { + e.setTarget(null); + e.setTargetPort(null); + }); + copy.getOutgoingEdges().clear(); + copy.getData().stream() + .filter(d -> d instanceof KIdentifier) + .forEach( + d -> { + var kid = (KIdentifier) d; + kid.setId(kid.getId() + "_" + mode.getName()); + }); } - - // add transitions - var representedTargets = new HashSet>(); - for (var transition : mode.transitions) { - if (!representedTargets.contains(new Pair(transition.target, transition.type))) { - var edge = _kEdgeExtensions.createEdge(); - edge.setSource(modeNode); - edge.setTarget(modeNodes.get(transition.target)); - addTransitionFigure(edge, transition); - - if (getBooleanValue(SHOW_TRANSITION_LABELS)) { - associateWith(edge, transition.getDefinition()); - } else { - // Bundle similar transitions - representedTargets.add(new Pair(transition.target, transition.type)); - } - } + + var newNode = triggerCopies.get(node); + edge.setSource(newNode); + + // Remove trigger on top level if only used in modes + if (node.getOutgoingEdges().isEmpty()) { + nodes.remove(node); } - - // handle cross hierarchy edges - var portCopies = new HashMap(); - var triggerCopies = new HashMap(); - for (var edge : edges) { - if (!edge.getProperty(CoreOptions.NO_LAYOUT)) { - var sourceNodeMode = nodeModes.get(edge.getSource()); - if (sourceNodeMode == null) { - sourceNodeMode = nodeModes.get(edge.getSource().getParent()); - } - var sourceIsInMode = sourceNodeMode != null; - var targetNodeMode = nodeModes.get(edge.getTarget()); - if (targetNodeMode == null) { - targetNodeMode = nodeModes.get(edge.getTarget().getParent()); - } - var targetIsInMode = targetNodeMode != null; - - if (!sourceIsInMode || !targetIsInMode) { - var node = sourceIsInMode ? edge.getTarget() : edge.getSource(); - - if (node.getProperty(LinguaFrancaSynthesis.REACTION_SPECIAL_TRIGGER)) { - // Duplicate trigger node - if (!triggerCopies.containsKey(node)) { - var copy = EcoreUtil.copy(node); - modeNode.getChildren().add(modeNode.getChildren().indexOf(edge.getTarget()), copy); - triggerCopies.put(node, copy); - - // Adjust copy - copy.getOutgoingEdges().forEach(e -> {e.setTarget(null);e.setTargetPort(null);}); - copy.getOutgoingEdges().clear(); - copy.getData().stream().filter(d -> d instanceof KIdentifier).forEach(d -> { - var kid = (KIdentifier) d; - kid.setId(kid.getId() + "_" + mode.getName()); - }); - } - - var newNode = triggerCopies.get(node); - edge.setSource(newNode); - - // Remove trigger on top level if only used in modes - if (node.getOutgoingEdges().isEmpty()) { - nodes.remove(node); - } - } else { - var port = sourceIsInMode ? edge.getTargetPort() : edge.getSourcePort(); - var isLocal = modeChildren.get(null).contains(node); - if (isLocal) { - // Add port to mode container - if (modeContainerPorts.containsKey(port)) { - node = modeContainer; - port = modeContainerPorts.get(port); - } else { - var containerPort = _kPortExtensions.createPort(); - modeContainerPorts.put(port, containerPort); - modeContainer.getPorts().add(containerPort); - - _kPortExtensions.setPortSize(containerPort, 8, 8); - KRectangle rect = _kRenderingExtensions.addRectangle(containerPort); - _kRenderingExtensions.setPointPlacementData(rect, - _kRenderingExtensions.LEFT, 0, 0.5f, - _kRenderingExtensions.BOTTOM, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, - 0, 0, 8, 4); - _kRenderingExtensions.setBackground(rect, Colors.BLACK); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(rect); - - DiagramSyntheses.setLayoutOption(containerPort, CoreOptions.PORT_BORDER_OFFSET, -4.0); - DiagramSyntheses.setLayoutOption(containerPort, CoreOptions.PORT_SIDE, sourceIsInMode ? PortSide.EAST : PortSide.WEST); - - var source = _utilityExtensions.sourceElement(node); - var label = ""; - if (source instanceof Action) { - label = ((Action) source).getName(); - } else if (source instanceof Timer) { - label = ((Timer) source).getName(); - } else if (!port.getLabels().isEmpty()) { - label = port.getLabels().get(0).getText(); - if (source instanceof Reactor && getBooleanValue(LinguaFrancaSynthesis.SHOW_INSTANCE_NAMES)) { - NamedInstance linkedInstance = NamedInstanceUtil.getLinkedInstance(node); - if (linkedInstance instanceof ReactorInstance) { - label = ((ReactorInstance) linkedInstance).getName() + "." + label; - } - } - } - var portLabel = _kLabelExtensions.createLabel(containerPort); - portLabel.setText(label); - var portLabelKText = _kRenderingFactory.createKText(); - _kRenderingExtensions.setFontSize(portLabelKText, 8); - portLabel.getData().add(portLabelKText); - - // new connection - var copy = EcoreUtil.copy(edge); - if (sourceIsInMode) { - copy.setSource(modeContainer); - copy.setSourcePort(containerPort); - copy.setTarget(edge.getTarget()); - } else { - copy.setTarget(modeContainer); - copy.setTargetPort(containerPort); - copy.setSource(edge.getSource()); - } - - node = modeContainer; - port = containerPort; - } - } - - // Duplicate port - if (!portCopies.containsKey(port)) { - var copy = EcoreUtil.copy(port); - portCopies.put(port, copy); - - var dummyNode = _kNodeExtensions.createNode(); - var newID = mode.uniqueID() + "_"; - if (!port.getLabels().isEmpty()) { - newID += IterableExtensions.head(port.getLabels()).getText(); - } - _utilityExtensions.setID(dummyNode, newID); - _kRenderingExtensions.addInvisibleContainerRendering(dummyNode); - dummyNode.getPorts().add(copy); - // Assign layer - DiagramSyntheses.setLayoutOption(dummyNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, - port.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST ? LayerConstraint.FIRST : LayerConstraint.LAST); - // Configure port spacing - DiagramSyntheses.setLayoutOption(dummyNode, CoreOptions.PORT_LABELS_PLACEMENT, EnumSet.of(PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE)); - // Place freely - DiagramSyntheses.setLayoutOption(dummyNode, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); - // Switch port side - DiagramSyntheses.setLayoutOption(copy, CoreOptions.PORT_SIDE, - port.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST ? PortSide.EAST : PortSide.WEST); - - modeNode.getChildren().add(dummyNode); - } - var newPort = portCopies.get(port); - if (sourceIsInMode) { - edge.setTarget(newPort.getNode()); - edge.setTargetPort(newPort); - } else { - edge.setSource(newPort.getNode()); - edge.setSourcePort(newPort); - } - } + } else { + var port = sourceIsInMode ? edge.getTargetPort() : edge.getSourcePort(); + var isLocal = modeChildren.get(null).contains(node); + if (isLocal) { + // Add port to mode container + if (modeContainerPorts.containsKey(port)) { + node = modeContainer; + port = modeContainerPorts.get(port); + } else { + var containerPort = _kPortExtensions.createPort(); + modeContainerPorts.put(port, containerPort); + modeContainer.getPorts().add(containerPort); + + _kPortExtensions.setPortSize(containerPort, 8, 8); + KRectangle rect = _kRenderingExtensions.addRectangle(containerPort); + _kRenderingExtensions.setPointPlacementData( + rect, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.BOTTOM, + 0, + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 8, + 4); + _kRenderingExtensions.setBackground(rect, Colors.BLACK); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(rect); + + DiagramSyntheses.setLayoutOption( + containerPort, CoreOptions.PORT_BORDER_OFFSET, -4.0); + DiagramSyntheses.setLayoutOption( + containerPort, + CoreOptions.PORT_SIDE, + sourceIsInMode ? PortSide.EAST : PortSide.WEST); + + var source = _utilityExtensions.sourceElement(node); + var label = ""; + if (source instanceof Action) { + label = ((Action) source).getName(); + } else if (source instanceof Timer) { + label = ((Timer) source).getName(); + } else if (!port.getLabels().isEmpty()) { + label = port.getLabels().get(0).getText(); + if (source instanceof Reactor + && getBooleanValue(LinguaFrancaSynthesis.SHOW_INSTANCE_NAMES)) { + NamedInstance linkedInstance = NamedInstanceUtil.getLinkedInstance(node); + if (linkedInstance instanceof ReactorInstance) { + label = ((ReactorInstance) linkedInstance).getName() + "." + label; } + } + } + var portLabel = _kLabelExtensions.createLabel(containerPort); + portLabel.setText(label); + var portLabelKText = _kRenderingFactory.createKText(); + _kRenderingExtensions.setFontSize(portLabelKText, 8); + portLabel.getData().add(portLabelKText); + + // new connection + var copy = EcoreUtil.copy(edge); + if (sourceIsInMode) { + copy.setSource(modeContainer); + copy.setSourcePort(containerPort); + copy.setTarget(edge.getTarget()); + } else { + copy.setTarget(modeContainer); + copy.setTargetPort(containerPort); + copy.setSource(edge.getSource()); } + + node = modeContainer; + port = containerPort; + } } - } - - // If mode container is unused (no ports for local connections) -> hide it - if (modeContainer.getPorts().isEmpty()) { - _kRenderingExtensions.setInvisible(modeContainerFigure, true); - DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.PADDING, new ElkPadding(2)); - } else if (getBooleanValue(LinguaFrancaSynthesis.SHOW_INSTANCE_NAMES)) { - // Remove mode container port labels of ports representing internal connections - // because their association to reactor instances is unambiguous due to instance names - for (var p : modeContainer.getPorts()) { - p.getLabels().removeIf(l -> l.getText().contains(".")); + + // Duplicate port + if (!portCopies.containsKey(port)) { + var copy = EcoreUtil.copy(port); + portCopies.put(port, copy); + + var dummyNode = _kNodeExtensions.createNode(); + var newID = mode.uniqueID() + "_"; + if (!port.getLabels().isEmpty()) { + newID += IterableExtensions.head(port.getLabels()).getText(); + } + _utilityExtensions.setID(dummyNode, newID); + _kRenderingExtensions.addInvisibleContainerRendering(dummyNode); + dummyNode.getPorts().add(copy); + // Assign layer + DiagramSyntheses.setLayoutOption( + dummyNode, + LayeredOptions.LAYERING_LAYER_CONSTRAINT, + port.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST + ? LayerConstraint.FIRST + : LayerConstraint.LAST); + // Configure port spacing + DiagramSyntheses.setLayoutOption( + dummyNode, + CoreOptions.PORT_LABELS_PLACEMENT, + EnumSet.of( + PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE)); + // Place freely + DiagramSyntheses.setLayoutOption( + dummyNode, LayeredOptions.CONSIDER_MODEL_ORDER_NO_MODEL_ORDER, true); + // Switch port side + DiagramSyntheses.setLayoutOption( + copy, + CoreOptions.PORT_SIDE, + port.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST + ? PortSide.EAST + : PortSide.WEST); + + modeNode.getChildren().add(dummyNode); + } + var newPort = portCopies.get(port); + if (sourceIsInMode) { + edge.setTarget(newPort.getNode()); + edge.setTargetPort(newPort); + } else { + edge.setSource(newPort.getNode()); + edge.setSourcePort(newPort); } + } } - - nodes.add(modeContainer); + } } - } - - private boolean hasContent(ModeInstance mode) { - return !mode.reactions.isEmpty() || !mode.instantiations.isEmpty(); - } - - private KContainerRendering addModeFigure(KNode node, ModeInstance mode, boolean expanded) { - int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; - - var figure = _kRenderingExtensions.addRoundedRectangle(node, 13, 13, 1); - _kContainerRenderingExtensions.setGridPlacement(figure, 1); - _kRenderingExtensions.setLineWidth(figure, mode.isInitial() ? 3f : 1.5f); - _kRenderingExtensions.setForeground(figure, MODE_FG); - _kRenderingExtensions.setBackground(figure, MODE_BG); - var background = _kRenderingExtensions.getBackground(figure); - background.setAlpha(MODE_BG_ALPHA); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); - - // Invisible container - KRectangle container = _kContainerRenderingExtensions.addRectangle(figure); - _kRenderingExtensions.setInvisible(container, true); - int bottomPadding = this.hasContent(mode) && expanded ? 4 : padding; - var from = _kRenderingExtensions.from( - _kRenderingExtensions.setGridPlacementData(container), - _kRenderingExtensions.LEFT, padding, 0, _kRenderingExtensions.TOP, padding, 0); - _kRenderingExtensions.to(from, _kRenderingExtensions.RIGHT, padding, 0, _kRenderingExtensions.BOTTOM, bottomPadding, 0); - - // Centered child container - KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(container); - this._kRenderingExtensions.setInvisible(childContainer, true); - this._kRenderingExtensions.setPointPlacementData(childContainer, - _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0.5f, - _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0); - this._kContainerRenderingExtensions.setGridPlacement(childContainer, 1); - - KText text = _kContainerRenderingExtensions.addText(childContainer, mode.getName()); - DiagramSyntheses.suppressSelectability(text); - _linguaFrancaStyleExtensions.underlineSelectionStyle(text); - - return figure; - } - - private KContainerRendering addModeContainerFigure(KNode node) { - var rect = _kRenderingExtensions.addRectangle(node); - _kRenderingExtensions.setLineWidth(rect, 1); - _kRenderingExtensions.setLineStyle(rect, LineStyle.DOT); - _kRenderingExtensions.setForeground(rect, MODE_FG); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(rect); - return rect; - } - - private void addTransitionFigure(KEdge edge, Transition transition) { - var spline = _kEdgeExtensions.addSpline(edge); - _kRenderingExtensions.setLineWidth(spline, 1.5f); - _kRenderingExtensions.setForeground(spline, MODE_FG); - _linguaFrancaStyleExtensions.boldLineSelectionStyle(spline); - - if (transition.type == ModeTransition.HISTORY) { - addHistoryDecorator(spline); - } else { - KRendering arrowDecorator = _kPolylineExtensions.addHeadArrowDecorator(spline); - this._kRenderingExtensions.setForeground(arrowDecorator, MODE_FG); - this._kRenderingExtensions.setBackground(arrowDecorator, MODE_FG); - } - - if (getBooleanValue(SHOW_TRANSITION_LABELS)) { - associateWith(spline, transition.getDefinition()); - - KLabel centerEdgeLabel = _kLabelExtensions.addCenterEdgeLabel(edge, this.toTransitionLabel(transition)); - associateWith(centerEdgeLabel, transition.getDefinition()); - applyTransitionOnEdgeStyle(centerEdgeLabel); + } + + // If mode container is unused (no ports for local connections) -> hide it + if (modeContainer.getPorts().isEmpty()) { + _kRenderingExtensions.setInvisible(modeContainerFigure, true); + DiagramSyntheses.setLayoutOption(modeContainer, CoreOptions.PADDING, new ElkPadding(2)); + } else if (getBooleanValue(LinguaFrancaSynthesis.SHOW_INSTANCE_NAMES)) { + // Remove mode container port labels of ports representing internal connections + // because their association to reactor instances is unambiguous due to instance names + for (var p : modeContainer.getPorts()) { + p.getLabels().removeIf(l -> l.getText().contains(".")); } + } + + nodes.add(modeContainer); } - - private String toTransitionLabel(Transition transition) { - var text = new StringBuilder(); - - text.append(transition.reaction.triggers.stream().map(t -> t.getDefinition().getName()).collect(Collectors.joining(", "))); - return text.toString(); + } + + private boolean hasContent(ModeInstance mode) { + return !mode.reactions.isEmpty() || !mode.instantiations.isEmpty(); + } + + private KContainerRendering addModeFigure(KNode node, ModeInstance mode, boolean expanded) { + int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6; + + var figure = _kRenderingExtensions.addRoundedRectangle(node, 13, 13, 1); + _kContainerRenderingExtensions.setGridPlacement(figure, 1); + _kRenderingExtensions.setLineWidth(figure, mode.isInitial() ? 3f : 1.5f); + _kRenderingExtensions.setForeground(figure, MODE_FG); + _kRenderingExtensions.setBackground(figure, MODE_BG); + var background = _kRenderingExtensions.getBackground(figure); + background.setAlpha(MODE_BG_ALPHA); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure); + + // Invisible container + KRectangle container = _kContainerRenderingExtensions.addRectangle(figure); + _kRenderingExtensions.setInvisible(container, true); + int bottomPadding = this.hasContent(mode) && expanded ? 4 : padding; + var from = + _kRenderingExtensions.from( + _kRenderingExtensions.setGridPlacementData(container), + _kRenderingExtensions.LEFT, + padding, + 0, + _kRenderingExtensions.TOP, + padding, + 0); + _kRenderingExtensions.to( + from, + _kRenderingExtensions.RIGHT, + padding, + 0, + _kRenderingExtensions.BOTTOM, + bottomPadding, + 0); + + // Centered child container + KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(container); + this._kRenderingExtensions.setInvisible(childContainer, true); + this._kRenderingExtensions.setPointPlacementData( + childContainer, + _kRenderingExtensions.LEFT, + 0, + 0.5f, + _kRenderingExtensions.TOP, + 0, + 0.5f, + _kRenderingExtensions.H_CENTRAL, + _kRenderingExtensions.V_CENTRAL, + 0, + 0, + 0, + 0); + this._kContainerRenderingExtensions.setGridPlacement(childContainer, 1); + + KText text = _kContainerRenderingExtensions.addText(childContainer, mode.getName()); + DiagramSyntheses.suppressSelectability(text); + _linguaFrancaStyleExtensions.underlineSelectionStyle(text); + + return figure; + } + + private KContainerRendering addModeContainerFigure(KNode node) { + var rect = _kRenderingExtensions.addRectangle(node); + _kRenderingExtensions.setLineWidth(rect, 1); + _kRenderingExtensions.setLineStyle(rect, LineStyle.DOT); + _kRenderingExtensions.setForeground(rect, MODE_FG); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(rect); + return rect; + } + + private void addTransitionFigure(KEdge edge, Transition transition) { + var spline = _kEdgeExtensions.addSpline(edge); + _kRenderingExtensions.setLineWidth(spline, 1.5f); + _kRenderingExtensions.setForeground(spline, MODE_FG); + _linguaFrancaStyleExtensions.boldLineSelectionStyle(spline); + + if (transition.type == ModeTransition.HISTORY) { + addHistoryDecorator(spline); + } else { + KRendering arrowDecorator = _kPolylineExtensions.addHeadArrowDecorator(spline); + this._kRenderingExtensions.setForeground(arrowDecorator, MODE_FG); + this._kRenderingExtensions.setBackground(arrowDecorator, MODE_FG); + } + + if (getBooleanValue(SHOW_TRANSITION_LABELS)) { + associateWith(spline, transition.getDefinition()); + + KLabel centerEdgeLabel = + _kLabelExtensions.addCenterEdgeLabel(edge, this.toTransitionLabel(transition)); + associateWith(centerEdgeLabel, transition.getDefinition()); + applyTransitionOnEdgeStyle(centerEdgeLabel); } - - private static LabelDecorationConfigurator _onEdgeTransitionLabelConfigurator; // ONLY for use in applyTransitionOnEdgeStyle - private void applyTransitionOnEdgeStyle(KLabel label) { - if (_onEdgeTransitionLabelConfigurator == null) { - var foreground = new Color(MODE_FG.getRed(), MODE_FG.getGreen(), MODE_FG.getBlue()); - var background = new Color(Colors.GRAY_95.getRed(), Colors.GRAY_95.getGreen(), Colors.GRAY_95.getBlue()); - _onEdgeTransitionLabelConfigurator = LabelDecorationConfigurator.create() - .withInlineLabels(true) - .withLabelTextRenderingProvider(new ITextRenderingProvider() { + } + + private String toTransitionLabel(Transition transition) { + var text = new StringBuilder(); + + text.append( + transition.reaction.triggers.stream() + .map(t -> t.getDefinition().getName()) + .collect(Collectors.joining(", "))); + return text.toString(); + } + + private static LabelDecorationConfigurator + _onEdgeTransitionLabelConfigurator; // ONLY for use in applyTransitionOnEdgeStyle + + private void applyTransitionOnEdgeStyle(KLabel label) { + if (_onEdgeTransitionLabelConfigurator == null) { + var foreground = new Color(MODE_FG.getRed(), MODE_FG.getGreen(), MODE_FG.getBlue()); + var background = + new Color(Colors.GRAY_95.getRed(), Colors.GRAY_95.getGreen(), Colors.GRAY_95.getBlue()); + _onEdgeTransitionLabelConfigurator = + LabelDecorationConfigurator.create() + .withInlineLabels(true) + .withLabelTextRenderingProvider( + new ITextRenderingProvider() { @Override public KRendering createTextRendering( - KContainerRendering container, KLabel llabel) { - var kText = _kRenderingFactory.createKText(); - _kRenderingExtensions.setFontSize(kText, 8); - container.getChildren().add(kText); - return kText; + KContainerRendering container, KLabel llabel) { + var kText = _kRenderingFactory.createKText(); + _kRenderingExtensions.setFontSize(kText, 8); + container.getChildren().add(kText); + return kText; } - }) - .addDecoratorRenderingProvider(RectangleDecorator.create().withBackground(background)) - .addDecoratorRenderingProvider(LinesDecorator.create().withColor(foreground)); - } - _onEdgeTransitionLabelConfigurator.applyTo(label); - } - - private void addHistoryDecorator(KPolyline line) { - var decorator = _kPolylineExtensions.addHeadArrowDecorator(line); - ((KDecoratorPlacementData) decorator.getPlacementData()).setAbsolute((-15.0f)); - - var ellipse = _kContainerRenderingExtensions.addEllipse(line); - _kRenderingExtensions.setDecoratorPlacementData(ellipse, 16, 16, (-6), 1, false); - _kRenderingExtensions.setLineWidth(ellipse, 0.8f); - _kRenderingExtensions.setForeground(ellipse, MODE_FG); - _kRenderingExtensions.setBackground(ellipse, Colors.WHITE); - - var innerLine = _kContainerRenderingExtensions.addPolyline(ellipse); - _kRenderingExtensions.setLineWidth(innerLine, 2); - var points = innerLine.getPoints(); - points.add(_kRenderingExtensions.createKPosition(_kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 4, 0)); - points.add(_kRenderingExtensions.createKPosition(_kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.BOTTOM, 4, 0)); - points.add(_kRenderingExtensions.createKPosition(_kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 0, 0.5f)); - points.add(_kRenderingExtensions.createKPosition(_kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.TOP, 0, 0.5f)); - points.add(_kRenderingExtensions.createKPosition(_kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 4, 0)); - points.add(_kRenderingExtensions.createKPosition(_kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.TOP, 4, 0)); - _kRenderingExtensions.setForeground(innerLine, MODE_FG); + }) + .addDecoratorRenderingProvider(RectangleDecorator.create().withBackground(background)) + .addDecoratorRenderingProvider(LinesDecorator.create().withColor(foreground)); } - -} \ No newline at end of file + _onEdgeTransitionLabelConfigurator.applyTo(label); + } + + private void addHistoryDecorator(KPolyline line) { + var decorator = _kPolylineExtensions.addHeadArrowDecorator(line); + ((KDecoratorPlacementData) decorator.getPlacementData()).setAbsolute((-15.0f)); + + var ellipse = _kContainerRenderingExtensions.addEllipse(line); + _kRenderingExtensions.setDecoratorPlacementData(ellipse, 16, 16, (-6), 1, false); + _kRenderingExtensions.setLineWidth(ellipse, 0.8f); + _kRenderingExtensions.setForeground(ellipse, MODE_FG); + _kRenderingExtensions.setBackground(ellipse, Colors.WHITE); + + var innerLine = _kContainerRenderingExtensions.addPolyline(ellipse); + _kRenderingExtensions.setLineWidth(innerLine, 2); + var points = innerLine.getPoints(); + points.add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 4, 0)); + points.add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.BOTTOM, 4, 0)); + points.add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 0, 0.5f)); + points.add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.TOP, 0, 0.5f)); + points.add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 4, 0)); + points.add( + _kRenderingExtensions.createKPosition( + _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.TOP, 4, 0)); + _kRenderingExtensions.setForeground(innerLine, MODE_FG); + } +} diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java b/org.lflang/src/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java index e7143b44fc..ab2edc658a 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; import de.cau.cs.kieler.klighd.kgraph.KGraphElement; @@ -31,28 +31,24 @@ /** * Utility class to link KGraphElements to NamedInstances. - * + * * @author Alexander Schulz-Rosengarten */ public class NamedInstanceUtil { - public static final Property> LINKED_INSTANCE = new Property<>( - "org.lflang.linguafranca.diagram.synthesis.graph.instance"); + public static final Property> LINKED_INSTANCE = + new Property<>("org.lflang.linguafranca.diagram.synthesis.graph.instance"); - /** - * Establishes a link between KGraphElement and NamedInstance. - */ - public static IPropertyHolder linkInstance(KGraphElement elem, NamedInstance instance) { - return elem.setProperty(LINKED_INSTANCE, instance); - } + /** Establishes a link between KGraphElement and NamedInstance. */ + public static IPropertyHolder linkInstance(KGraphElement elem, NamedInstance instance) { + return elem.setProperty(LINKED_INSTANCE, instance); + } - /** - * Returns the linked NamedInstance for the given KGraphElement. - */ - public static NamedInstance getLinkedInstance(KGraphElement elem) { - var instance = elem.getProperty(LINKED_INSTANCE); - if (instance != null) { - return instance; - } - return null; + /** Returns the linked NamedInstance for the given KGraphElement. */ + public static NamedInstance getLinkedInstance(KGraphElement elem) { + var instance = elem.getProperty(LINKED_INSTANCE); + if (instance != null) { + return instance; } + return null; + } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/ReactorIcons.java b/org.lflang/src/org/lflang/diagram/synthesis/util/ReactorIcons.java index e740ebf653..a69b7d3e4f 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/ReactorIcons.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/ReactorIcons.java @@ -1,146 +1,148 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; -//import org.eclipse.swt.graphics.ImageData; -//import org.eclipse.swt.graphics.ImageLoader; -import org.eclipse.xtext.xbase.lib.Extension; -import org.lflang.AttributeUtils; -import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; -import org.lflang.lf.ReactorDecl; -import org.lflang.util.FileUtil; - +// import org.eclipse.swt.graphics.ImageData; +// import org.eclipse.swt.graphics.ImageLoader; import com.google.inject.Inject; - import de.cau.cs.kieler.klighd.krendering.KContainerRendering; import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; import de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions; import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions; +import org.eclipse.xtext.xbase.lib.Extension; +import org.lflang.AttributeUtils; +import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; +import org.lflang.lf.ReactorDecl; +import org.lflang.util.FileUtil; /** * Utility class to handle icons for reactors in Lingua Franca diagrams. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class ReactorIcons extends AbstractSynthesisExtensions { - @Inject @Extension private KRenderingExtensions _kRenderingExtensions; - @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; - -// private static final ImageLoader LOADER = new ImageLoader(); - - // Image cache during synthesis -// private final HashMap cache = new HashMap<>(); - - // Error message - private String error = null; + @Inject @Extension private KRenderingExtensions _kRenderingExtensions; + @Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions; + + // private static final ImageLoader LOADER = new ImageLoader(); + + // Image cache during synthesis + // private final HashMap cache = new HashMap<>(); + + // Error message + private String error = null; - public void handleIcon(KContainerRendering rendering, ReactorDecl reactor, boolean collapsed) { - if (!collapsed) { - return; - } - - // Reset error - error = null; - - // Get annotation - var iconPath = AttributeUtils.getIconPath(reactor); - if (iconPath != null && !iconPath.isEmpty()) { - var iconLocation = FileUtil.locateFile(iconPath, reactor.eResource()); - if (iconLocation == null) { - error = "Cannot find given icon file."; - } else { - /* - * This code was disabled because it cannot be compiled for the language server with Gradle. - * As soon as the Klighd API is extended to support URI-based images in both Eclipse and VSCode, - * this code should be reactivated and adapted. - * See: https://github.com/kieler/KLighD/issues/146 - */ -// ImageData data = loadImage(iconLocation); -// if (data != null) { -// KRectangle figure = _kContainerRenderingExtensions.addRectangle(rendering); -// _kRenderingExtensions.setInvisible(figure, true); -// KGridPlacementData figurePlacement = _kRenderingExtensions.setGridPlacementData(figure, data.width, data.height); -// _kRenderingExtensions.to( -// _kRenderingExtensions.from( -// figurePlacement, -// _kRenderingExtensions.LEFT, 3, 0, -// _kRenderingExtensions.TOP, 0, 0), -// _kRenderingExtensions.RIGHT, 3, 0, -// _kRenderingExtensions.BOTTOM, 3, 0); -// -// KRectangle icon = _kContainerRenderingExtensions.addRectangle(figure); -// _kRenderingExtensions.setInvisible(icon, true); -// _kContainerRenderingExtensions.addImage(icon, data); -// _kRenderingExtensions.setPointPlacementData(icon, -// _kRenderingExtensions.createKPosition( -// _kRenderingExtensions.LEFT, 0, 0.5f, -// _kRenderingExtensions.TOP, 0, 0.5f), -// _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, -// 0, data.width, data.height); -// } -// if (error != null) { -// var errorText = _kContainerRenderingExtensions.addText(rendering, "Icon not found!\n"+error); -// _kRenderingExtensions.setForeground(errorText, Colors.RED); -// _kRenderingExtensions.setFontBold(errorText, true); -// _kRenderingExtensions.setSurroundingSpaceGrid(errorText, 8, 0); -// } - } - } + public void handleIcon(KContainerRendering rendering, ReactorDecl reactor, boolean collapsed) { + if (!collapsed) { + return; } -// private ImageData loadImage(final java.net.URI uri) { -// try { -// if (cache.containsKey(uri)) { -// return cache.get(uri); -// } -// synchronized (LOADER) { -// InputStream inStream = null; -// try { -// inStream = uri.toURL().openStream(); -// ImageData[] data = LOADER.load(inStream); -// if (data != null && data.length > 0) { -// ImageData img = data[0]; -// cache.put(uri, img); -// return img; -// } else { -// error = "Could not load icon image."; -// return null; -// } -// } finally { -// if (inStream != null) { -// inStream.close(); -// } -// } -// } -// } catch (Exception ex) { -// ex.printStackTrace(); -// error = "Could not load icon image."; -// return null; -// } -// } - + // Reset error + error = null; + + // Get annotation + var iconPath = AttributeUtils.getIconPath(reactor); + if (iconPath != null && !iconPath.isEmpty()) { + var iconLocation = FileUtil.locateFile(iconPath, reactor.eResource()); + if (iconLocation == null) { + error = "Cannot find given icon file."; + } else { + /* + * This code was disabled because it cannot be compiled for the language server with Gradle. + * As soon as the Klighd API is extended to support URI-based images in both Eclipse and VSCode, + * this code should be reactivated and adapted. + * See: https://github.com/kieler/KLighD/issues/146 + */ + // ImageData data = loadImage(iconLocation); + // if (data != null) { + // KRectangle figure = + // _kContainerRenderingExtensions.addRectangle(rendering); + // _kRenderingExtensions.setInvisible(figure, true); + // KGridPlacementData figurePlacement = + // _kRenderingExtensions.setGridPlacementData(figure, data.width, data.height); + // _kRenderingExtensions.to( + // _kRenderingExtensions.from( + // figurePlacement, + // _kRenderingExtensions.LEFT, 3, 0, + // _kRenderingExtensions.TOP, 0, 0), + // _kRenderingExtensions.RIGHT, 3, 0, + // _kRenderingExtensions.BOTTOM, 3, 0); + // + // KRectangle icon = _kContainerRenderingExtensions.addRectangle(figure); + // _kRenderingExtensions.setInvisible(icon, true); + // _kContainerRenderingExtensions.addImage(icon, data); + // _kRenderingExtensions.setPointPlacementData(icon, + // _kRenderingExtensions.createKPosition( + // _kRenderingExtensions.LEFT, 0, 0.5f, + // _kRenderingExtensions.TOP, 0, 0.5f), + // _kRenderingExtensions.H_CENTRAL, + // _kRenderingExtensions.V_CENTRAL, 0, + // 0, data.width, data.height); + // } + // if (error != null) { + // var errorText = _kContainerRenderingExtensions.addText(rendering, + // "Icon not found!\n"+error); + // _kRenderingExtensions.setForeground(errorText, Colors.RED); + // _kRenderingExtensions.setFontBold(errorText, true); + // _kRenderingExtensions.setSurroundingSpaceGrid(errorText, 8, 0); + // } + } + } + } + + // private ImageData loadImage(final java.net.URI uri) { + // try { + // if (cache.containsKey(uri)) { + // return cache.get(uri); + // } + // synchronized (LOADER) { + // InputStream inStream = null; + // try { + // inStream = uri.toURL().openStream(); + // ImageData[] data = LOADER.load(inStream); + // if (data != null && data.length > 0) { + // ImageData img = data[0]; + // cache.put(uri, img); + // return img; + // } else { + // error = "Could not load icon image."; + // return null; + // } + // } finally { + // if (inStream != null) { + // inStream.close(); + // } + // } + // } + // } catch (Exception ex) { + // ex.printStackTrace(); + // error = "Could not load icon image."; + // return null; + // } + // } + } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java b/org.lflang/src/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java index fdf5070713..a249c009fd 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java @@ -1,27 +1,27 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; import java.nio.file.Path; @@ -32,53 +32,53 @@ * @author Alexander Schulz-Rosengarten */ public class SynthesisErrorReporter implements ErrorReporter { - @Override - public String reportError(String message) { - return null; - } - - @Override - public String reportError(EObject object, String message) { - return null; - } - - @Override - public String reportError(Path file, Integer line, String message) { - return null; - } - - @Override - public String reportWarning(String message) { - return null; - } - - @Override - public String reportWarning(EObject object, String message) { - return null; - } - - @Override - public String reportWarning(Path file, Integer line, String message) { - return null; - } + @Override + public String reportError(String message) { + return null; + } - @Override - public String reportInfo(String message) { - return null; - } + @Override + public String reportError(EObject object, String message) { + return null; + } - @Override - public String reportInfo(EObject object, String message) { - return null; - } + @Override + public String reportError(Path file, Integer line, String message) { + return null; + } - @Override - public String reportInfo(Path file, Integer line, String message) { - return null; - } + @Override + public String reportWarning(String message) { + return null; + } - @Override - public boolean getErrorsOccurred() { - return false; - } -} \ No newline at end of file + @Override + public String reportWarning(EObject object, String message) { + return null; + } + + @Override + public String reportWarning(Path file, Integer line, String message) { + return null; + } + + @Override + public String reportInfo(String message) { + return null; + } + + @Override + public String reportInfo(EObject object, String message) { + return null; + } + + @Override + public String reportInfo(Path file, Integer line, String message) { + return null; + } + + @Override + public boolean getErrorsOccurred() { + return false; + } +} diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java b/org.lflang/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java index fb97bd1449..ca83da41a8 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java @@ -1,33 +1,38 @@ /************* -* Copyright (c) 2020, Kiel University. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.diagram.synthesis.util; +import de.cau.cs.kieler.klighd.internal.util.KlighdInternalProperties; +import de.cau.cs.kieler.klighd.kgraph.KGraphElement; +import de.cau.cs.kieler.klighd.kgraph.KGraphFactory; +import de.cau.cs.kieler.klighd.kgraph.KIdentifier; +import de.cau.cs.kieler.klighd.kgraph.KNode; +import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.eclipse.elk.core.math.ElkMargin; import org.eclipse.elk.core.options.CoreOptions; import org.eclipse.elk.core.util.IndividualSpacings; @@ -39,163 +44,133 @@ import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Code; -import org.lflang.lf.Expression; -import org.lflang.lf.Host; -import org.lflang.lf.Literal; -import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; -import org.lflang.lf.Time; -import org.lflang.util.StringUtil; - -import de.cau.cs.kieler.klighd.internal.util.KlighdInternalProperties; -import de.cau.cs.kieler.klighd.kgraph.KGraphElement; -import de.cau.cs.kieler.klighd.kgraph.KGraphFactory; -import de.cau.cs.kieler.klighd.kgraph.KIdentifier; -import de.cau.cs.kieler.klighd.kgraph.KNode; -import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared; /** * Extension class that provides various utility methods for the synthesis. - * + * * @author Alexander Schulz-Rosengarten */ @ViewSynthesisShared public class UtilityExtensions extends AbstractSynthesisExtensions { - - @Extension - private KGraphFactory _kGraphFactory = KGraphFactory.eINSTANCE; - - - /** - * Returns true if the reactor is the primary reactor - */ - public boolean isMainOrFederated(Reactor reactor) { - return reactor.isMain() || reactor.isFederated(); - } - - /** - * Returns true if the instance is a bank of reactors - */ -// def boolean isBank(Instantiation ins) { -// return ins?.widthSpec !== null ? ins.widthSpec.width !== 1 : false -// } - - /** - * Returns true if the reactor as has inner reactions or instances - */ - public boolean hasContent(final ReactorInstance reactor) { - return !reactor.reactions.isEmpty() || !reactor.instantiations().isEmpty(); - } - - /** - * - */ - public boolean isRoot(final ReactorInstance ri) { - return ri.getParent() == null; + + @Extension private KGraphFactory _kGraphFactory = KGraphFactory.eINSTANCE; + + /** Returns true if the reactor is the primary reactor */ + public boolean isMainOrFederated(Reactor reactor) { + return reactor.isMain() || reactor.isFederated(); + } + + /** Returns true if the instance is a bank of reactors */ + // def boolean isBank(Instantiation ins) { + // return ins?.widthSpec !== null ? ins.widthSpec.width !== 1 : false + // } + + /** Returns true if the reactor as has inner reactions or instances */ + public boolean hasContent(final ReactorInstance reactor) { + return !reactor.reactions.isEmpty() || !reactor.instantiations().isEmpty(); + } + + /** */ + public boolean isRoot(final ReactorInstance ri) { + return ri.getParent() == null; + } + + /** Trims the hostcode of reactions. */ + public String trimCode(final Code tokenizedCode) { + if (tokenizedCode == null || StringExtensions.isNullOrEmpty(tokenizedCode.getBody())) { + return ""; } - - /** - * Trims the hostcode of reactions. - */ - public String trimCode(final Code tokenizedCode) { - if (tokenizedCode == null || StringExtensions.isNullOrEmpty(tokenizedCode.getBody())) { - return ""; + try { + ICompositeNode node = NodeModelUtils.findActualNodeFor(tokenizedCode); + String code = node != null ? node.getText() : null; + int contentStart = 0; + List lines = new ArrayList<>(); + Arrays.stream(code.split("\n")) + .dropWhile(line -> !line.contains("{=")) + .forEachOrdered(lines::add); + + // Remove start pattern + if (!lines.isEmpty()) { + if (IterableExtensions.head(lines).trim().equals("{=")) { + lines.remove(0); // skip + } else { + lines.set(0, IterableExtensions.head(lines).replace("{=", "").trim()); + contentStart = 1; } - try { - ICompositeNode node = NodeModelUtils.findActualNodeFor(tokenizedCode); - String code = node != null ? node.getText() : null; - int contentStart = 0; - List lines = new ArrayList<>(); - Arrays.stream(code.split("\n")).dropWhile(line -> !line.contains("{=")).forEachOrdered(lines::add); - - // Remove start pattern - if (!lines.isEmpty()) { - if (IterableExtensions.head(lines).trim().equals("{=")) { - lines.remove(0); // skip - } else { - lines.set(0, IterableExtensions.head(lines).replace("{=", "").trim()); - contentStart = 1; - } - } - - // Remove end pattern - if (!lines.isEmpty()) { - if (IterableExtensions.last(lines).trim().equals("=}")) { - lines.remove(lines.size() - 1); // skip - } else { - lines.set(lines.size() - 1, IterableExtensions.last(lines).replace("=}", "")); - } - } - - // Find indentation - String indentation = null; - while (indentation == null && lines.size() > contentStart) { - String firstLine = lines.get(contentStart); - String trimmed = firstLine.trim(); - if (trimmed.isEmpty()) { - lines.set(contentStart, ""); - contentStart++; - } else { - int firstCharIdx = firstLine.indexOf(trimmed.charAt(0)); - indentation = firstLine.substring(0, firstCharIdx); - } - } - - // Remove root indentation - if (!lines.isEmpty()) { - for (int i = 0; i < lines.size(); i++) { - if (lines.get(i).startsWith(indentation)) { - lines.set(i, lines.get(i).substring(indentation.length())); - } - } - } - - return String.join("\n", lines); - } catch(Exception e) { - e.printStackTrace(); - return tokenizedCode.getBody(); + } + + // Remove end pattern + if (!lines.isEmpty()) { + if (IterableExtensions.last(lines).trim().equals("=}")) { + lines.remove(lines.size() - 1); // skip + } else { + lines.set(lines.size() - 1, IterableExtensions.last(lines).replace("=}", "")); } - } - - /** - * Sets KGE ID. - */ - public boolean setID(KGraphElement kge, String id) { - KIdentifier identifier = _kGraphFactory.createKIdentifier(); - identifier.setId(id); - return kge.getData().add(identifier); - } - - /** - * Retrieves the source element of the given diagram element - */ - public Object sourceElement(KGraphElement elem) { - return elem.getProperty(KlighdInternalProperties.MODEL_ELEMEMT); - } - - /** - * Checks if the source element of the given diagram element is a reactor - */ - public boolean sourceIsReactor(KNode node) { - return sourceElement(node) instanceof Reactor; - } + } - /** - * Returns the port placement margins for the node. - * If this spacing does not yet exist, the properties are initialized. - */ - public ElkMargin getPortMarginsInitIfAbsent(KNode node) { - IndividualSpacings spacing = node.getProperty(CoreOptions.SPACING_INDIVIDUAL); - if (spacing == null) { - spacing = new IndividualSpacings(); - node.setProperty(CoreOptions.SPACING_INDIVIDUAL, spacing); + // Find indentation + String indentation = null; + while (indentation == null && lines.size() > contentStart) { + String firstLine = lines.get(contentStart); + String trimmed = firstLine.trim(); + if (trimmed.isEmpty()) { + lines.set(contentStart, ""); + contentStart++; + } else { + int firstCharIdx = firstLine.indexOf(trimmed.charAt(0)); + indentation = firstLine.substring(0, firstCharIdx); } - ElkMargin margin = spacing.getProperty(CoreOptions.SPACING_PORTS_SURROUNDING); - if (margin == null) { - margin = new ElkMargin(); - node.setProperty(CoreOptions.SPACING_PORTS_SURROUNDING, margin); + } + + // Remove root indentation + if (!lines.isEmpty()) { + for (int i = 0; i < lines.size(); i++) { + if (lines.get(i).startsWith(indentation)) { + lines.set(i, lines.get(i).substring(indentation.length())); + } } - return margin; - } + } + + return String.join("\n", lines); + } catch (Exception e) { + e.printStackTrace(); + return tokenizedCode.getBody(); + } + } + + /** Sets KGE ID. */ + public boolean setID(KGraphElement kge, String id) { + KIdentifier identifier = _kGraphFactory.createKIdentifier(); + identifier.setId(id); + return kge.getData().add(identifier); + } + /** Retrieves the source element of the given diagram element */ + public Object sourceElement(KGraphElement elem) { + return elem.getProperty(KlighdInternalProperties.MODEL_ELEMEMT); + } + + /** Checks if the source element of the given diagram element is a reactor */ + public boolean sourceIsReactor(KNode node) { + return sourceElement(node) instanceof Reactor; + } + + /** + * Returns the port placement margins for the node. If this spacing does not yet exist, the + * properties are initialized. + */ + public ElkMargin getPortMarginsInitIfAbsent(KNode node) { + IndividualSpacings spacing = node.getProperty(CoreOptions.SPACING_INDIVIDUAL); + if (spacing == null) { + spacing = new IndividualSpacings(); + node.setProperty(CoreOptions.SPACING_INDIVIDUAL, spacing); + } + ElkMargin margin = spacing.getProperty(CoreOptions.SPACING_PORTS_SURROUNDING); + if (margin == null) { + margin = new ElkMargin(); + node.setProperty(CoreOptions.SPACING_PORTS_SURROUNDING, margin); + } + return margin; + } } diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index 18b5d9615a..121cf5d817 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -33,14 +33,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.federated.generator.FedASTUtils; import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; @@ -59,708 +58,763 @@ import org.lflang.lf.VarRef; /** - * An extension class to the CGenerator that enables certain federated - * functionalities. Currently, this class offers the following features: + * An extension class to the CGenerator that enables certain federated functionalities. Currently, + * this class offers the following features: * *

      - *
    • Allocating and initializing C structures for federated communication
    • - *
    • Creating status field for network input ports that help the receiver logic in - * federate.c communicate the status of a network input port with network input - * control reactions.
    • + *
    • Allocating and initializing C structures for federated communication + *
    • Creating status field for network input ports that help the receiver logic in federate.c + * communicate the status of a network input port with network input control reactions. *
    * * @author {Soroush Bateni } * @author {Hou Seng Wong } * @author {Billy Bao } - * */ public class CExtension implements FedTargetExtension { - @Override - public void initializeTargetConfig( - LFGeneratorContext context, - int numOfFederates, FederateInstance federate, - FedFileConfig fileConfig, - ErrorReporter errorReporter, - RtiConfig rtiConfig - ) throws IOException { - - CExtensionUtils.handleCompileDefinitions(federate, numOfFederates, rtiConfig); - - generateCMakeInclude(federate, fileConfig); - - federate.targetConfig.keepalive = true; - federate.targetConfig.setByUser.add(TargetProperty.KEEPALIVE); - - // If there are federates, copy the required files for that. - // Also, create the RTI C file and the launcher script. - // Handle target parameters. - // If the program is federated, then ensure that threading is enabled. - federate.targetConfig.threading = true; - federate.targetConfig.setByUser.add(TargetProperty.THREADING); - - // Include the fed setup file for this federate in the target property - String relPath = getPreamblePath(federate); - federate.targetConfig.fedSetupPreamble = relPath; - federate.targetConfig.setByUser.add(TargetProperty.FED_SETUP); + @Override + public void initializeTargetConfig( + LFGeneratorContext context, + int numOfFederates, + FederateInstance federate, + FedFileConfig fileConfig, + ErrorReporter errorReporter, + RtiConfig rtiConfig) + throws IOException { + + CExtensionUtils.handleCompileDefinitions(federate, numOfFederates, rtiConfig); + + generateCMakeInclude(federate, fileConfig); + + federate.targetConfig.keepalive = true; + federate.targetConfig.setByUser.add(TargetProperty.KEEPALIVE); + + // If there are federates, copy the required files for that. + // Also, create the RTI C file and the launcher script. + // Handle target parameters. + // If the program is federated, then ensure that threading is enabled. + federate.targetConfig.threading = true; + federate.targetConfig.setByUser.add(TargetProperty.THREADING); + + // Include the fed setup file for this federate in the target property + String relPath = getPreamblePath(federate); + federate.targetConfig.fedSetupPreamble = relPath; + federate.targetConfig.setByUser.add(TargetProperty.FED_SETUP); + } + + /** Generate a cmake-include file for {@code federate} if needed. */ + protected void generateCMakeInclude(FederateInstance federate, FedFileConfig fileConfig) + throws IOException { + CExtensionUtils.generateCMakeInclude(federate, fileConfig); + } + + /** + * Generate code for the body of a reaction that handles the action that is triggered by receiving + * a message from a remote federate. + * + * @param action The action. + * @param sendingPort The output port providing the data to send. + * @param receivingPort The ID of the destination port. + * @param connection FIXME + * @param type FIXME + * @param coordinationType The coordination type + * @param errorReporter + */ + public String generateNetworkReceiverBody( + Action action, + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter) { + var receiveRef = + CUtil.portRefInReaction(receivingPort, connection.getDstBank(), connection.getDstChannel()); + var result = new CodeBuilder(); + // We currently have no way to mark a reaction "unordered" + // in the AST, so we use a magic string at the start of the body. + result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER); + // Transfer the physical time of arrival from the action to the port + result.pr( + receiveRef + + "->physical_time_of_arrival = self->_lf__" + + action.getName() + + ".physical_time_of_arrival;"); + if (coordinationType == CoordinationType.DECENTRALIZED + && !connection.getDefinition().isPhysical()) { + // Transfer the intended tag. + result.pr( + receiveRef + "->intended_tag = self->_lf__" + action.getName() + ".intended_tag;\n"); } - /** - * Generate a cmake-include file for {@code federate} if needed. - */ - protected void generateCMakeInclude(FederateInstance federate, FedFileConfig fileConfig) throws IOException { - CExtensionUtils.generateCMakeInclude(federate, fileConfig); + deserialize(action, receivingPort, connection, type, receiveRef, result, errorReporter); + return result.toString(); + } + + /** + * Generate code to deserialize a message received over the network. + * + * @param action The network action that is mapped to the {@code receivingPort} + * @param receivingPort The receiving port + * @param connection The connection used to receive the message + * @param type Type for the port + * @param receiveRef A target language reference to the receiving port + * @param result Used to put generated code in + * @param errorReporter Used to report errors, if any + */ + protected void deserialize( + Action action, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + String receiveRef, + CodeBuilder result, + ErrorReporter errorReporter) { + CTypes types = new CTypes(); + // Adjust the type of the action and the receivingPort. + // If it is "string", then change it to "char*". + // This string is dynamically allocated, and type 'string' is to be + // used only for statically allocated strings. This would force the + // CGenerator to treat the port and action as token types. + if (types.getTargetType(action).equals("string")) { + action.getType().setCode(null); + action.getType().setId("char*"); } - - /** - * Generate code for the body of a reaction that handles the - * action that is triggered by receiving a message from a remote - * federate. - * @param action The action. - * @param sendingPort The output port providing the data to send. - * @param receivingPort The ID of the destination port. - * @param connection FIXME - * @param type FIXME - * @param coordinationType The coordination type - * @param errorReporter - */ - public String generateNetworkReceiverBody( - Action action, - VarRef sendingPort, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - CoordinationType coordinationType, - ErrorReporter errorReporter - ) { - var receiveRef = CUtil.portRefInReaction(receivingPort, connection.getDstBank(), connection.getDstChannel()); - var result = new CodeBuilder(); - // We currently have no way to mark a reaction "unordered" - // in the AST, so we use a magic string at the start of the body. - result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER); - // Transfer the physical time of arrival from the action to the port - result.pr(receiveRef+"->physical_time_of_arrival = self->_lf__"+action.getName()+".physical_time_of_arrival;"); - if (coordinationType == CoordinationType.DECENTRALIZED && !connection.getDefinition().isPhysical()) { - // Transfer the intended tag. - result.pr(receiveRef+"->intended_tag = self->_lf__"+action.getName()+".intended_tag;\n"); - } - - deserialize(action, receivingPort, connection, type, receiveRef, result, errorReporter); - return result.toString(); + if (types.getTargetType((Port) receivingPort.getVariable()).equals("string")) { + ((Port) receivingPort.getVariable()).getType().setCode(null); + ((Port) receivingPort.getVariable()).getType().setId("char*"); } - - /** - * Generate code to deserialize a message received over the network. - * @param action The network action that is mapped to the {@code receivingPort} - * @param receivingPort The receiving port - * @param connection The connection used to receive the message - * @param type Type for the port - * @param receiveRef A target language reference to the receiving port - * @param result Used to put generated code in - * @param errorReporter Used to report errors, if any - */ - protected void deserialize( - Action action, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - String receiveRef, - CodeBuilder result, - ErrorReporter errorReporter - ) { - CTypes types = new CTypes(); - // Adjust the type of the action and the receivingPort. - // If it is "string", then change it to "char*". - // This string is dynamically allocated, and type 'string' is to be - // used only for statically allocated strings. This would force the - // CGenerator to treat the port and action as token types. - if (types.getTargetType(action).equals("string")) { - action.getType().setCode(null); - action.getType().setId("char*"); + var value = ""; + switch (connection.getSerializer()) { + case NATIVE: + { + // NOTE: Docs say that malloc'd char* is freed on conclusion of the time step. + // So passing it downstream should be OK. + value = action.getName() + "->value"; + if (CUtil.isTokenType(type, types)) { + result.pr("lf_set_token(" + receiveRef + ", " + action.getName() + "->token);"); + } else { + result.pr("lf_set(" + receiveRef + ", " + value + ");"); + } + break; } - if (types.getTargetType((Port) receivingPort.getVariable()).equals("string")) { - ((Port) receivingPort.getVariable()).getType().setCode(null); - ((Port) receivingPort.getVariable()).getType().setId("char*"); + case PROTO: + { + throw new UnsupportedOperationException("Protobuf serialization is not supported yet."); } - var value = ""; - switch (connection.getSerializer()) { - case NATIVE: { - // NOTE: Docs say that malloc'd char* is freed on conclusion of the time step. - // So passing it downstream should be OK. - value = action.getName()+"->value"; - if (CUtil.isTokenType(type, types)) { - result.pr("lf_set_token("+ receiveRef +", "+ action.getName()+"->token);"); - } else { - result.pr("lf_set("+ receiveRef +", "+value+");"); + case ROS2: + { + var portType = ASTUtils.getInferredType(((Port) receivingPort.getVariable())); + var portTypeStr = types.getTargetType(portType); + if (CUtil.isTokenType(portType, types)) { + throw new UnsupportedOperationException( + "Cannot handle ROS serialization when ports are pointers."); + } else if (CExtensionUtils.isSharedPtrType(portType, types)) { + var matcher = CExtensionUtils.sharedPointerVariable.matcher(portTypeStr); + if (matcher.find()) { + portTypeStr = matcher.group("type"); } - break; - } - 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); - if (CUtil.isTokenType(portType, types)) { - throw new UnsupportedOperationException("Cannot handle ROS serialization when ports are pointers."); - } else if (CExtensionUtils.isSharedPtrType(portType, types)) { - var matcher = CExtensionUtils.sharedPointerVariable.matcher(portTypeStr); - if (matcher.find()) { - portTypeStr = matcher.group("type"); - } - } - var ROSDeserializer = new FedROS2CPPSerialization(); - value = FedROS2CPPSerialization.deserializedVarName; + } + var ROSDeserializer = new FedROS2CPPSerialization(); + value = FedROS2CPPSerialization.deserializedVarName; + result.pr( + ROSDeserializer.generateNetworkDeserializerCode( + "self->_lf__" + action.getName(), portTypeStr)); + if (CExtensionUtils.isSharedPtrType(portType, types)) { result.pr( - ROSDeserializer.generateNetworkDeserializerCode( - "self->_lf__"+ action.getName(), - portTypeStr - ) - ); - if (CExtensionUtils.isSharedPtrType(portType, types)) { - result.pr("auto msg_shared_ptr = std::make_shared<"+portTypeStr+">("+value+");"); - result.pr("lf_set("+ receiveRef +", msg_shared_ptr);"); - } else { - result.pr("lf_set("+ receiveRef +", std::move("+value+"));"); - } - break; - } + "auto msg_shared_ptr = std::make_shared<" + portTypeStr + ">(" + value + ");"); + result.pr("lf_set(" + receiveRef + ", msg_shared_ptr);"); + } else { + result.pr("lf_set(" + receiveRef + ", std::move(" + value + "));"); + } + break; } } + } + + /** + * Generate code for the body of a reaction that handles an output that is to be sent over the + * network. + * + * @param sendingPort The output port providing the data to send. + * @param receivingPort The variable reference to the destination port. + * @param connection + * @param type + * @param coordinationType + * @param errorReporter FIXME + */ + public String generateNetworkSenderBody( + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter) { + var sendRef = + CUtil.portRefInReaction(sendingPort, connection.getSrcBank(), connection.getSrcChannel()); + var receiveRef = + ASTUtils.generateVarRef( + receivingPort); // Used for comments only, so no need for bank/multiport index. + var result = new CodeBuilder(); + // The ID of the receiving port (rightPort) is the position + // of the action in this list. + int receivingPortID = connection.getDstFederate().networkMessageActions.size(); + + // We currently have no way to mark a reaction "unordered" + // in the AST, so we use a magic string at the start of the body. + result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); + + result.pr( + "// Sending from " + + sendRef + + " in federate " + + connection.getSrcFederate().name + + " to " + + receiveRef + + " in federate " + + connection.getDstFederate().name); + + // In case sendRef is a multiport or is in a bank, this reaction will be triggered when any + // channel or bank index of sendRef is present + // ex. if a.out[i] is present, the entire output a.out is triggered. + if (connection.getSrcBank() != -1 || connection.getSrcChannel() != -1) { + result.pr("if (!" + sendRef + "->is_present) return;"); + } - /** - * Generate code for the body of a reaction that handles an output - * that is to be sent over the network. - * @param sendingPort The output port providing the data to send. - * @param receivingPort The variable reference to the destination port. - * @param connection - * @param type - * @param coordinationType - * @param errorReporter FIXME - */ - public String generateNetworkSenderBody( - VarRef sendingPort, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - CoordinationType coordinationType, - ErrorReporter errorReporter - ) { - var sendRef = CUtil.portRefInReaction(sendingPort, connection.getSrcBank(), connection.getSrcChannel()); - var receiveRef = ASTUtils.generateVarRef(receivingPort); // Used for comments only, so no need for bank/multiport index. - var result = new CodeBuilder(); - // The ID of the receiving port (rightPort) is the position - // of the action in this list. - int receivingPortID = connection.getDstFederate().networkMessageActions.size(); - - // We currently have no way to mark a reaction "unordered" - // in the AST, so we use a magic string at the start of the body. - result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); - - result.pr("// Sending from " + sendRef + " in federate " - + connection.getSrcFederate().name + " to " + receiveRef - + " in federate " + connection.getDstFederate().name); - - // In case sendRef is a multiport or is in a bank, this reaction will be triggered when any channel or bank index of sendRef is present - // ex. if a.out[i] is present, the entire output a.out is triggered. - if (connection.getSrcBank() != -1 || connection.getSrcChannel() != -1) { - result.pr("if (!"+sendRef+"->is_present) return;"); - } - - // If the connection is physical and the receiving federate is remote, send it directly on a socket. - // If the connection is logical and the coordination mode is centralized, send via RTI. - // If the connection is logical and the coordination mode is decentralized, send directly - String messageType; - // Name of the next immediate destination of this message - var next_destination_name = "\"federate "+connection.getDstFederate().id+"\""; - - // Get the delay literal - String additionalDelayString = CExtensionUtils.getNetworkDelayLiteral(connection.getDefinition().getDelay()); - - if (connection.getDefinition().isPhysical()) { - messageType = "MSG_TYPE_P2P_MESSAGE"; - } else if (coordinationType == CoordinationType.DECENTRALIZED) { - messageType = "MSG_TYPE_P2P_TAGGED_MESSAGE"; - } else { - // Logical connection - // Send the message via rti - messageType = "MSG_TYPE_TAGGED_MESSAGE"; - next_destination_name = "\"federate "+connection.getDstFederate().id+" via the RTI\""; - } - - - String sendingFunction = "send_timed_message"; - String commonArgs = String.join(", ", - additionalDelayString, - messageType, - receivingPortID + "", - connection.getDstFederate().id + "", - next_destination_name, - "message_length" - ); - if (connection.getDefinition().isPhysical()) { - // Messages going on a physical connection do not - // carry a timestamp or require the delay; - sendingFunction = "send_message"; - commonArgs = messageType+", "+receivingPortID+", "+connection.getDstFederate().id+", "+next_destination_name+", message_length"; - } + // If the connection is physical and the receiving federate is remote, send it directly on a + // socket. + // If the connection is logical and the coordination mode is centralized, send via RTI. + // If the connection is logical and the coordination mode is decentralized, send directly + String messageType; + // Name of the next immediate destination of this message + var next_destination_name = "\"federate " + connection.getDstFederate().id + "\""; + + // Get the delay literal + String additionalDelayString = + CExtensionUtils.getNetworkDelayLiteral(connection.getDefinition().getDelay()); + + if (connection.getDefinition().isPhysical()) { + messageType = "MSG_TYPE_P2P_MESSAGE"; + } else if (coordinationType == CoordinationType.DECENTRALIZED) { + messageType = "MSG_TYPE_P2P_TAGGED_MESSAGE"; + } else { + // Logical connection + // Send the message via rti + messageType = "MSG_TYPE_TAGGED_MESSAGE"; + next_destination_name = "\"federate " + connection.getDstFederate().id + " via the RTI\""; + } - serializeAndSend( - connection, - type, - sendRef, - result, - sendingFunction, - commonArgs, - errorReporter - ); - return result.toString(); + String sendingFunction = "send_timed_message"; + String commonArgs = + String.join( + ", ", + additionalDelayString, + messageType, + receivingPortID + "", + connection.getDstFederate().id + "", + next_destination_name, + "message_length"); + if (connection.getDefinition().isPhysical()) { + // Messages going on a physical connection do not + // carry a timestamp or require the delay; + sendingFunction = "send_message"; + commonArgs = + messageType + + ", " + + receivingPortID + + ", " + + connection.getDstFederate().id + + ", " + + next_destination_name + + ", message_length"; } - /** - * FIXME - * @param connection - * @param type - * @param sendRef - * @param result - * @param sendingFunction - * @param commonArgs - * @param errorReporter - */ - protected void serializeAndSend( - FedConnectionInstance connection, - InferredType type, - String sendRef, - CodeBuilder result, - String sendingFunction, - String commonArgs, - ErrorReporter errorReporter - ) { - CTypes types = new CTypes(); - var lengthExpression = ""; - var pointerExpression = ""; - switch (connection.getSerializer()) { - case NATIVE: { - // Handle native types. - if (CUtil.isTokenType(type, types)) { - // NOTE: Transporting token types this way is likely to only work if the sender and receiver - // both have the same endianness. Otherwise, you have to use protobufs or some other serialization scheme. - result.pr("size_t message_length = "+ sendRef +"->token->length * "+ sendRef - +"->token->type->element_size;"); - result.pr(sendingFunction +"("+ commonArgs +", (unsigned char*) "+ sendRef - +"->value);"); - } else { - // string types need to be dealt with specially because they are hidden pointers. - // void type is odd, but it avoids generating non-standard expression sizeof(void), - // which some compilers reject. - lengthExpression = "sizeof("+ types.getTargetType(type)+")"; - pointerExpression = "(unsigned char*)&"+ sendRef +"->value"; - var targetType = types.getTargetType(type); - if (targetType.equals("string")) { - lengthExpression = "strlen("+ sendRef +"->value) + 1"; - pointerExpression = "(unsigned char*) "+ sendRef +"->value"; - } else if (targetType.equals("void")) { - lengthExpression = "0"; - } - result.pr("size_t message_length = "+lengthExpression+";"); - result.pr( - sendingFunction +"("+ commonArgs +", "+pointerExpression+");"); + serializeAndSend(connection, type, sendRef, result, sendingFunction, commonArgs, errorReporter); + return result.toString(); + } + + /** + * FIXME + * + * @param connection + * @param type + * @param sendRef + * @param result + * @param sendingFunction + * @param commonArgs + * @param errorReporter + */ + protected void serializeAndSend( + FedConnectionInstance connection, + InferredType type, + String sendRef, + CodeBuilder result, + String sendingFunction, + String commonArgs, + ErrorReporter errorReporter) { + CTypes types = new CTypes(); + var lengthExpression = ""; + var pointerExpression = ""; + switch (connection.getSerializer()) { + case NATIVE: + { + // Handle native types. + if (CUtil.isTokenType(type, types)) { + // NOTE: Transporting token types this way is likely to only work if the sender and + // receiver + // both have the same endianness. Otherwise, you have to use protobufs or some other + // serialization scheme. + result.pr( + "size_t message_length = " + + sendRef + + "->token->length * " + + sendRef + + "->token->type->element_size;"); + result.pr( + sendingFunction + "(" + commonArgs + ", (unsigned char*) " + sendRef + "->value);"); + } else { + // string types need to be dealt with specially because they are hidden pointers. + // void type is odd, but it avoids generating non-standard expression sizeof(void), + // which some compilers reject. + lengthExpression = "sizeof(" + types.getTargetType(type) + ")"; + pointerExpression = "(unsigned char*)&" + sendRef + "->value"; + var targetType = types.getTargetType(type); + if (targetType.equals("string")) { + lengthExpression = "strlen(" + sendRef + "->value) + 1"; + pointerExpression = "(unsigned char*) " + sendRef + "->value"; + } else if (targetType.equals("void")) { + lengthExpression = "0"; } - break; + result.pr("size_t message_length = " + lengthExpression + ";"); + result.pr(sendingFunction + "(" + commonArgs + ", " + pointerExpression + ");"); + } + break; } - 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 variableToSerialize = sendRef; - var typeStr = types.getTargetType(type); - if (CUtil.isTokenType(type, types)) { - throw new UnsupportedOperationException("Cannot handle ROS serialization when ports are pointers."); - } else if (CExtensionUtils.isSharedPtrType(type, types)) { - var matcher = CExtensionUtils.sharedPointerVariable.matcher(typeStr); - if (matcher.find()) { - typeStr = matcher.group("type"); - } + case ROS2: + { + var variableToSerialize = sendRef; + var typeStr = types.getTargetType(type); + if (CUtil.isTokenType(type, types)) { + throw new UnsupportedOperationException( + "Cannot handle ROS serialization when ports are pointers."); + } else if (CExtensionUtils.isSharedPtrType(type, types)) { + var matcher = CExtensionUtils.sharedPointerVariable.matcher(typeStr); + if (matcher.find()) { + typeStr = matcher.group("type"); } - var ROSSerializer = new FedROS2CPPSerialization(); - lengthExpression = ROSSerializer.serializedBufferLength(); - pointerExpression = ROSSerializer.seializedBufferVar(); - result.pr( - ROSSerializer.generateNetworkSerializerCode(variableToSerialize, typeStr, CExtensionUtils.isSharedPtrType(type, types)) - ); - result.pr("size_t message_length = "+lengthExpression+";"); - result.pr(sendingFunction +"("+ commonArgs +", "+pointerExpression+");"); - break; - } - + } + var ROSSerializer = new FedROS2CPPSerialization(); + lengthExpression = ROSSerializer.serializedBufferLength(); + pointerExpression = ROSSerializer.seializedBufferVar(); + result.pr( + ROSSerializer.generateNetworkSerializerCode( + variableToSerialize, typeStr, CExtensionUtils.isSharedPtrType(type, types))); + result.pr("size_t message_length = " + lengthExpression + ";"); + result.pr(sendingFunction + "(" + commonArgs + ", " + pointerExpression + ");"); + break; } } - - /** - * Generate code for the body of a reaction that decides whether the trigger for the given - * port is going to be present or absent for the current logical time. - * This reaction is put just before the first reaction that is triggered by the network - * input port "port" or has it in its sources. If there are only connections to contained - * reactors, in the top-level reactor. - * - * @param receivingPortID The port to generate the control reaction for - * @param maxSTP The maximum value of STP is assigned to reactions (if any) - * that have port as their trigger or source - */ - public String generateNetworkInputControlReactionBody( - int receivingPortID, - TimeValue maxSTP, - CoordinationType coordination - ) { - // Store the code - var result = new CodeBuilder(); - - // We currently have no way to mark a reaction "unordered" - // in the AST, so we use a magic string at the start of the body. - result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); - result.pr("interval_t max_STP = 0LL;"); - - // Find the maximum STP for decentralized coordination - if(coordination == CoordinationType.DECENTRALIZED) { - result.pr("max_STP = "+ CTypes.getInstance().getTargetTimeExpr(maxSTP) +";"); - } - result.pr("// Wait until the port status is known"); - result.pr("wait_until_port_status_known("+receivingPortID+", max_STP);"); - return result.toString(); - } - - /** - * Generate code for the body of a reaction that sends a port status message for the given - * port if it is absent. - * - * @oaram srcOutputPort FIXME - * @param connection FIXME - */ - public String generateNetworkOutputControlReactionBody( - VarRef srcOutputPort, - FedConnectionInstance connection - ) { - // Store the code - var result = new CodeBuilder(); - // The ID of the receiving port (rightPort) is the position - // of the networkAction (see below) in this list. - int receivingPortID = connection.getDstFederate().networkMessageActions.size(); - - // We currently have no way to mark a reaction "unordered" - // in the AST, so we use a magic string at the start of the body. - result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); - var sendRef = CUtil.portRefInReaction(srcOutputPort, connection.getSrcBank(), connection.getSrcChannel()); - // Get the delay literal - var additionalDelayString = CExtensionUtils.getNetworkDelayLiteral(connection.getDefinition().getDelay()); - result.pr(String.join("\n", - "// If the output port has not been lf_set for the current logical time,", - "// send an ABSENT message to the receiving federate ", - "LF_PRINT_LOG(\"Contemplating whether to send port \"", - " \"absent for port %d to federate %d.\", ", - " "+receivingPortID+", "+connection.getDstFederate().id+");", - "if ("+sendRef+" == NULL || !"+sendRef+"->is_present) {", - " // The output port is NULL or it is not present.", - " send_port_absent_to_federate("+additionalDelayString+", "+receivingPortID+", "+connection.getDstFederate().id+");", - "}" - )); - return result.toString(); + } + + /** + * Generate code for the body of a reaction that decides whether the trigger for the given port is + * going to be present or absent for the current logical time. This reaction is put just before + * the first reaction that is triggered by the network input port "port" or has it in its sources. + * If there are only connections to contained reactors, in the top-level reactor. + * + * @param receivingPortID The port to generate the control reaction for + * @param maxSTP The maximum value of STP is assigned to reactions (if any) that have port as + * their trigger or source + */ + public String generateNetworkInputControlReactionBody( + int receivingPortID, TimeValue maxSTP, CoordinationType coordination) { + // Store the code + var result = new CodeBuilder(); + + // We currently have no way to mark a reaction "unordered" + // in the AST, so we use a magic string at the start of the body. + result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); + result.pr("interval_t max_STP = 0LL;"); + + // Find the maximum STP for decentralized coordination + if (coordination == CoordinationType.DECENTRALIZED) { + result.pr("max_STP = " + CTypes.getInstance().getTargetTimeExpr(maxSTP) + ";"); } - - - public String getNetworkBufferType() { - return "uint8_t*"; + result.pr("// Wait until the port status is known"); + result.pr("wait_until_port_status_known(" + receivingPortID + ", max_STP);"); + return result.toString(); + } + + /** + * Generate code for the body of a reaction that sends a port status message for the given port if + * it is absent. + * + * @oaram srcOutputPort FIXME + * @param connection FIXME + */ + public String generateNetworkOutputControlReactionBody( + VarRef srcOutputPort, FedConnectionInstance connection) { + // Store the code + var result = new CodeBuilder(); + // The ID of the receiving port (rightPort) is the position + // of the networkAction (see below) in this list. + int receivingPortID = connection.getDstFederate().networkMessageActions.size(); + + // We currently have no way to mark a reaction "unordered" + // in the AST, so we use a magic string at the start of the body. + result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); + var sendRef = + CUtil.portRefInReaction(srcOutputPort, connection.getSrcBank(), connection.getSrcChannel()); + // Get the delay literal + var additionalDelayString = + CExtensionUtils.getNetworkDelayLiteral(connection.getDefinition().getDelay()); + result.pr( + String.join( + "\n", + "// If the output port has not been lf_set for the current logical time,", + "// send an ABSENT message to the receiving federate ", + "LF_PRINT_LOG(\"Contemplating whether to send port \"", + " \"absent for port %d to federate %d.\", ", + " " + receivingPortID + ", " + connection.getDstFederate().id + ");", + "if (" + sendRef + " == NULL || !" + sendRef + "->is_present) {", + " // The output port is NULL or it is not present.", + " send_port_absent_to_federate(" + + additionalDelayString + + ", " + + receivingPortID + + ", " + + connection.getDstFederate().id + + ");", + "}")); + return result.toString(); + } + + public String getNetworkBufferType() { + return "uint8_t*"; + } + + /** + * Add preamble to a separate file to set up federated execution. Return an empty string since no + * code generated needs to go in the source. + */ + @Override + public String generatePreamble( + FederateInstance federate, + FedFileConfig fileConfig, + RtiConfig rtiConfig, + ErrorReporter errorReporter) + throws IOException { + // Put the C preamble in a {@code include/_federate.name + _preamble.h} file + String cPreamble = makePreamble(federate, fileConfig, rtiConfig, errorReporter); + String relPath = getPreamblePath(federate); + Path fedPreamblePath = fileConfig.getSrcPath().resolve(relPath); + Files.createDirectories(fedPreamblePath.getParent()); + try (var writer = Files.newBufferedWriter(fedPreamblePath)) { + writer.write(cPreamble); } - - /** - * Add preamble to a separate file to set up federated execution. - * Return an empty string since no code generated needs to go in the source. - */ - @Override - public String generatePreamble( - FederateInstance federate, - FedFileConfig fileConfig, - RtiConfig rtiConfig, - ErrorReporter errorReporter - ) throws IOException { - // Put the C preamble in a {@code include/_federate.name + _preamble.h} file - String cPreamble = makePreamble(federate, fileConfig, rtiConfig, errorReporter); - String relPath = getPreamblePath(federate); - Path fedPreamblePath = fileConfig.getSrcPath().resolve(relPath); - Files.createDirectories(fedPreamblePath.getParent()); - try (var writer = Files.newBufferedWriter(fedPreamblePath)) { - writer.write(cPreamble); - } - var includes = new CodeBuilder(); - if (federate.targetConfig.target != Target.Python) { - includes.pr("#ifdef __cplusplus\n" - + "extern \"C\" {\n" - + "#endif"); - includes.pr("#include \"core/federated/federate.h\""); - includes.pr("#include \"core/federated/net_common.h\""); - includes.pr("#include \"core/federated/net_util.h\""); - includes.pr("#include \"core/federated/clock-sync.h\""); - 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\n" - + "}\n" - + "#endif"); - includes.pr(generateSerializationIncludes(federate, fileConfig)); - } - - return includes.toString(); + var includes = new CodeBuilder(); + if (federate.targetConfig.target != Target.Python) { + includes.pr("#ifdef __cplusplus\n" + "extern \"C\" {\n" + "#endif"); + includes.pr("#include \"core/federated/federate.h\""); + includes.pr("#include \"core/federated/net_common.h\""); + includes.pr("#include \"core/federated/net_util.h\""); + includes.pr("#include \"core/federated/clock-sync.h\""); + 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\n" + "}\n" + "#endif"); + includes.pr(generateSerializationIncludes(federate, fileConfig)); } - /** - * Generate the preamble to setup federated execution in C. - */ - protected String makePreamble( - FederateInstance federate, - FedFileConfig fileConfig, - RtiConfig rtiConfig, - ErrorReporter errorReporter) { - - var code = new CodeBuilder(); - - code.pr("#include \"core/federated/federate.h\""); - code.pr("#include \"core/federated/net_common.h\""); - code.pr("#include \"core/federated/net_util.h\""); - code.pr("#include \"core/threaded/reactor_threaded.h\""); - code.pr("#include \"core/utils/util.h\""); - code.pr("extern federate_instance_t _fed;"); - - // Generate function to return a pointer to the action trigger_t - // that handles incoming network messages destined to the specified - // port. This will only be used if there are federates. - int numOfNetworkActions = federate.networkMessageActions.size(); - code.pr(""" + return includes.toString(); + } + + /** Generate the preamble to setup federated execution in C. */ + protected String makePreamble( + FederateInstance federate, + FedFileConfig fileConfig, + RtiConfig rtiConfig, + ErrorReporter errorReporter) { + + var code = new CodeBuilder(); + + code.pr("#include \"core/federated/federate.h\""); + code.pr("#include \"core/federated/net_common.h\""); + code.pr("#include \"core/federated/net_util.h\""); + code.pr("#include \"core/threaded/reactor_threaded.h\""); + code.pr("#include \"core/utils/util.h\""); + code.pr("extern federate_instance_t _fed;"); + + // Generate function to return a pointer to the action trigger_t + // that handles incoming network messages destined to the specified + // port. This will only be used if there are federates. + int numOfNetworkActions = federate.networkMessageActions.size(); + code.pr( + """ lf_action_base_t* _lf_action_table[%1$s]; size_t _lf_action_table_size = %1$s; - """.formatted(numOfNetworkActions)); - - code.pr(generateExecutablePreamble(federate, rtiConfig, errorReporter)); - - code.pr(generateInitializeTriggers(federate, errorReporter)); - - code.pr(CExtensionUtils.generateFederateNeighborStructure(federate)); - - return code.getCode(); - } - - /** - * Generate preamble code needed for enabled serializers of the federate. - */ - protected String generateSerializationIncludes(FederateInstance federate, FedFileConfig fileConfig) { - return CExtensionUtils.generateSerializationIncludes(federate, fileConfig); - } - - /** - * Create a function that initializes necessary triggers for federated execution, - * which are the triggers for control reactions and references to all network - * actions (which are triggered upon receiving network messages). - * - * @param federate The federate to initialize triggers for. - * @param errorReporter Used to report errors. - * @return The generated code for the macro. - */ - private String generateInitializeTriggers(FederateInstance federate, ErrorReporter errorReporter) { - CodeBuilder code = new CodeBuilder(); - // Temporarily change the original federate reactor's name in the AST to - // the federate's name so that trigger references are accurate. - var federatedReactor = FedASTUtils.findFederatedReactor(federate.instantiation.eResource()); - var oldFederatedReactorName = federatedReactor.getName(); - federatedReactor.setName(federate.name); - var main = new ReactorInstance(federatedReactor, errorReporter, 1); - code.pr(CExtensionUtils.initializeTriggersForNetworkActions(federate, main)); - code.pr(CExtensionUtils.initializeTriggerForControlReactions(main, main, federate)); - federatedReactor.setName(oldFederatedReactorName); - - return """ + """ + .formatted(numOfNetworkActions)); + + code.pr(generateExecutablePreamble(federate, rtiConfig, errorReporter)); + + code.pr(generateInitializeTriggers(federate, errorReporter)); + + code.pr(CExtensionUtils.generateFederateNeighborStructure(federate)); + + return code.getCode(); + } + + /** Generate preamble code needed for enabled serializers of the federate. */ + protected String generateSerializationIncludes( + FederateInstance federate, FedFileConfig fileConfig) { + return CExtensionUtils.generateSerializationIncludes(federate, fileConfig); + } + + /** + * Create a function that initializes necessary triggers for federated execution, which are the + * triggers for control reactions and references to all network actions (which are triggered upon + * receiving network messages). + * + * @param federate The federate to initialize triggers for. + * @param errorReporter Used to report errors. + * @return The generated code for the macro. + */ + private String generateInitializeTriggers( + FederateInstance federate, ErrorReporter errorReporter) { + CodeBuilder code = new CodeBuilder(); + // Temporarily change the original federate reactor's name in the AST to + // the federate's name so that trigger references are accurate. + var federatedReactor = FedASTUtils.findFederatedReactor(federate.instantiation.eResource()); + var oldFederatedReactorName = federatedReactor.getName(); + federatedReactor.setName(federate.name); + var main = new ReactorInstance(federatedReactor, errorReporter, 1); + code.pr(CExtensionUtils.initializeTriggersForNetworkActions(federate, main)); + code.pr(CExtensionUtils.initializeTriggerForControlReactions(main, main, federate)); + federatedReactor.setName(oldFederatedReactorName); + + return """ #define initialize_triggers_for_federate() \\ do { \\ %s } \\ while (0) - """.formatted((code.getCode().isBlank() ? "\\" : code.getCode()).indent(4).stripTrailing()); - } + """ + .formatted((code.getCode().isBlank() ? "\\" : code.getCode()).indent(4).stripTrailing()); + } - /** - * Generate code for an executed preamble. - * - */ - private String generateExecutablePreamble(FederateInstance federate, RtiConfig rtiConfig, ErrorReporter errorReporter) { - CodeBuilder code = new CodeBuilder(); + /** Generate code for an executed preamble. */ + private String generateExecutablePreamble( + FederateInstance federate, RtiConfig rtiConfig, ErrorReporter errorReporter) { + CodeBuilder code = new CodeBuilder(); - code.pr(generateCodeForPhysicalActions(federate, errorReporter)); + code.pr(generateCodeForPhysicalActions(federate, errorReporter)); - code.pr(generateCodeToInitializeFederate(federate, rtiConfig)); + code.pr(generateCodeToInitializeFederate(federate, rtiConfig)); - code.pr(CExtensionUtils.allocateTriggersForFederate(federate)); + code.pr(CExtensionUtils.allocateTriggersForFederate(federate)); - return """ + return """ void _lf_executable_preamble() { %s } - """.formatted(code.toString().indent(4).stripTrailing()); + """ + .formatted(code.toString().indent(4).stripTrailing()); + } + + /** + * Generate code to initialize the {@code federate}. + * + * @param rtiConfig + * @return The generated code + */ + private String generateCodeToInitializeFederate(FederateInstance federate, RtiConfig rtiConfig) { + CodeBuilder code = new CodeBuilder(); + code.pr("// ***** Start initializing the federated execution. */"); + code.pr( + String.join( + "\n", + "// Initialize the socket mutex", + "lf_mutex_init(&outbound_socket_mutex);", + "lf_cond_init(&port_status_changed, &mutex);")); + + // Find the STA (A.K.A. the global STP offset) for this federate. + if (federate.targetConfig.coordination == CoordinationType.DECENTRALIZED) { + var reactor = ASTUtils.toDefinition(federate.instantiation.getReactorClass()); + var stpParam = + reactor.getParameters().stream() + .filter( + param -> + param.getName().equalsIgnoreCase("STP_offset") + && (param.getType() == null || param.getType().isTime())) + .findFirst(); + + if (stpParam.isPresent()) { + var globalSTP = + ASTUtils.initialValue(stpParam.get(), List.of(federate.instantiation)).get(0); + var globalSTPTV = ASTUtils.getLiteralTimeValue(globalSTP); + code.pr("lf_set_stp_offset(" + CTypes.getInstance().getTargetTimeExpr(globalSTPTV) + ");"); + } } - /** - * Generate code to initialize the {@code federate}. - * @param rtiConfig - * @return The generated code - */ - private String generateCodeToInitializeFederate(FederateInstance federate, RtiConfig rtiConfig) { - CodeBuilder code = new CodeBuilder(); - code.pr("// ***** Start initializing the federated execution. */"); - code.pr(String.join("\n", - "// Initialize the socket mutex", - "lf_mutex_init(&outbound_socket_mutex);", - "lf_cond_init(&port_status_changed, &mutex);" - )); - - // Find the STA (A.K.A. the global STP offset) for this federate. - if (federate.targetConfig.coordination == CoordinationType.DECENTRALIZED) { - var reactor = ASTUtils.toDefinition(federate.instantiation.getReactorClass()); - var stpParam = reactor.getParameters().stream().filter( - param -> - param.getName().equalsIgnoreCase("STP_offset") - && (param.getType() == null || param.getType().isTime()) - ).findFirst(); - - if (stpParam.isPresent()) { - var globalSTP = ASTUtils.initialValue(stpParam.get(), List.of(federate.instantiation)).get(0); - var globalSTPTV = ASTUtils.getLiteralTimeValue(globalSTP); - code.pr("lf_set_stp_offset("+ CTypes.getInstance().getTargetTimeExpr(globalSTPTV) +");"); - } - } - - // Set indicator variables that specify whether the federate has - // upstream logical connections. - if (federate.dependsOn.size() > 0) { - code.pr("_fed.has_upstream = true;"); - } - if (federate.sendsTo.size() > 0) { - code.pr("_fed.has_downstream = true;"); - } - // Set global variable identifying the federate. - code.pr("_lf_my_fed_id = "+ federate.id+";"); - - // We keep separate record for incoming and outgoing p2p connections to allow incoming traffic to be processed in a separate - // thread without requiring a mutex lock. - var numberOfInboundConnections = federate.inboundP2PConnections.size(); - var numberOfOutboundConnections = federate.outboundP2PConnections.size(); - - code.pr(String.join("\n", - "_fed.number_of_inbound_p2p_connections = "+numberOfInboundConnections+";", - "_fed.number_of_outbound_p2p_connections = "+numberOfOutboundConnections+";" - )); - if (numberOfInboundConnections > 0) { - code.pr(String.join("\n", - "// Initialize the array of socket for incoming connections to -1.", - "for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {", - " _fed.sockets_for_inbound_p2p_connections[i] = -1;", - "}" - )); - } - if (numberOfOutboundConnections > 0) { - code.pr(String.join("\n", - "// Initialize the array of socket for outgoing connections to -1.", - "for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {", - " _fed.sockets_for_outbound_p2p_connections[i] = -1;", - "}" - )); - } + // Set indicator variables that specify whether the federate has + // upstream logical connections. + if (federate.dependsOn.size() > 0) { + code.pr("_fed.has_upstream = true;"); + } + if (federate.sendsTo.size() > 0) { + code.pr("_fed.has_downstream = true;"); + } + // Set global variable identifying the federate. + code.pr("_lf_my_fed_id = " + federate.id + ";"); + + // We keep separate record for incoming and outgoing p2p connections to allow incoming traffic + // to be processed in a separate + // thread without requiring a mutex lock. + var numberOfInboundConnections = federate.inboundP2PConnections.size(); + var numberOfOutboundConnections = federate.outboundP2PConnections.size(); + + code.pr( + String.join( + "\n", + "_fed.number_of_inbound_p2p_connections = " + numberOfInboundConnections + ";", + "_fed.number_of_outbound_p2p_connections = " + numberOfOutboundConnections + ";")); + if (numberOfInboundConnections > 0) { + code.pr( + String.join( + "\n", + "// Initialize the array of socket for incoming connections to -1.", + "for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {", + " _fed.sockets_for_inbound_p2p_connections[i] = -1;", + "}")); + } + if (numberOfOutboundConnections > 0) { + code.pr( + String.join( + "\n", + "// Initialize the array of socket for outgoing connections to -1.", + "for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {", + " _fed.sockets_for_outbound_p2p_connections[i] = -1;", + "}")); + } - // If a test clock offset has been specified, insert code to set it here. - if (federate.targetConfig.clockSyncOptions.testOffset != null) { - code.pr("lf_set_physical_clock_offset((1 + "+ federate.id+") * "+ federate.targetConfig.clockSyncOptions.testOffset.toNanoSeconds()+"LL);"); - } + // If a test clock offset has been specified, insert code to set it here. + if (federate.targetConfig.clockSyncOptions.testOffset != null) { + code.pr( + "lf_set_physical_clock_offset((1 + " + + federate.id + + ") * " + + federate.targetConfig.clockSyncOptions.testOffset.toNanoSeconds() + + "LL);"); + } - code.pr(String.join("\n", - "// Connect to the RTI. This sets _fed.socket_TCP_RTI and _lf_rti_socket_UDP.", - "connect_to_rti("+addDoubleQuotes(rtiConfig.getHost())+", "+ rtiConfig.getPort()+");" - )); + code.pr( + String.join( + "\n", + "// Connect to the RTI. This sets _fed.socket_TCP_RTI and _lf_rti_socket_UDP.", + "connect_to_rti(" + + addDoubleQuotes(rtiConfig.getHost()) + + ", " + + rtiConfig.getPort() + + ");")); + + // Disable clock synchronization for the federate if it resides on the same host as the RTI, + // unless that is overridden with the clock-sync-options target property. + if (CExtensionUtils.clockSyncIsOn(federate, rtiConfig)) { + code.pr("synchronize_initial_physical_clock_with_rti(_fed.socket_TCP_RTI);"); + } - // Disable clock synchronization for the federate if it resides on the same host as the RTI, - // unless that is overridden with the clock-sync-options target property. - if (CExtensionUtils.clockSyncIsOn(federate, rtiConfig)) { - code.pr("synchronize_initial_physical_clock_with_rti(_fed.socket_TCP_RTI);"); - } + if (numberOfInboundConnections > 0) { + code.pr( + String.join( + "\n", + "// Create a socket server to listen to other federates.", + "// If a port is specified by the user, that will be used", + "// as the only possibility for the server. If not, the port", + "// will start from STARTING_PORT. The function will", + "// keep incrementing the port until the number of tries reaches PORT_RANGE_LIMIT.", + "create_server(" + federate.port + ");", + "// Connect to remote federates for each physical connection.", + "// This is done in a separate thread because this thread will call", + "// connect_to_federate for each outbound physical connection at the same", + "// time that the new thread is listening for such connections for inbound", + "// physical connections. The thread will live until all connections", + "// have been established.", + "lf_thread_create(&_fed.inbound_p2p_handling_thread_id," + + " handle_p2p_connections_from_federates, NULL);")); + } - if (numberOfInboundConnections > 0) { - code.pr(String.join("\n", - "// Create a socket server to listen to other federates.", - "// If a port is specified by the user, that will be used", - "// as the only possibility for the server. If not, the port", - "// will start from STARTING_PORT. The function will", - "// keep incrementing the port until the number of tries reaches PORT_RANGE_LIMIT.", - "create_server("+ federate.port+");", - "// Connect to remote federates for each physical connection.", - "// This is done in a separate thread because this thread will call", - "// connect_to_federate for each outbound physical connection at the same", - "// time that the new thread is listening for such connections for inbound", - "// physical connections. The thread will live until all connections", - "// have been established.", - "lf_thread_create(&_fed.inbound_p2p_handling_thread_id, handle_p2p_connections_from_federates, NULL);" - )); + for (FederateInstance remoteFederate : federate.outboundP2PConnections) { + code.pr("connect_to_federate(" + remoteFederate.id + ");"); + } + return code.getCode(); + } + + /** + * Generate code to handle physical actions in the {@code federate}. + * + * @param errorReporter Used to report errors. + * @return Generated code. + */ + private String generateCodeForPhysicalActions( + FederateInstance federate, ErrorReporter errorReporter) { + CodeBuilder code = new CodeBuilder(); + if (federate.targetConfig.coordination.equals(CoordinationType.CENTRALIZED)) { + // If this program uses centralized coordination then check + // for outputs that depend on physical actions so that null messages can be + // sent to the RTI. + var federateClass = ASTUtils.toDefinition(federate.instantiation.getReactorClass()); + var main = + new ReactorInstance( + FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), + errorReporter, + 1); + var instance = new ReactorInstance(federateClass, main, errorReporter); + var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); + var minDelay = TimeValue.MAX_VALUE; + Output outputFound = null; + for (Output output : outputDelayMap.keySet()) { + var outputDelay = outputDelayMap.get(output); + if (outputDelay.isEarlierThan(minDelay)) { + minDelay = outputDelay; + outputFound = output; } - - for (FederateInstance remoteFederate : federate.outboundP2PConnections) { - code.pr("connect_to_federate("+remoteFederate.id+");"); + } + if (minDelay != TimeValue.MAX_VALUE) { + // Unless silenced, issue a warning. + if (federate.targetConfig.coordinationOptions.advance_message_interval == null) { + errorReporter.reportWarning( + outputFound, + String.join( + "\n", + "Found a path from a physical action to output for reactor " + + addDoubleQuotes(instance.getName()) + + ". ", + "The amount of delay is " + minDelay + ".", + "With centralized coordination, this can result in a large number of messages to" + + " the RTI.", + "Consider refactoring the code so that the output does not depend on the physical" + + " action,", + "or consider using decentralized coordination. To silence this warning, set the" + + " target", + "parameter coordination-options with a value like {advance-message-interval: 10" + + " msec}")); } - return code.getCode(); + code.pr( + "_fed.min_delay_from_physical_action_to_federate_output = " + + CTypes.getInstance().getTargetTimeExpr(minDelay) + + ";"); + } } + return code.getCode(); + } - /** - * Generate code to handle physical actions in the {@code federate}. - * @param errorReporter Used to report errors. - * @return Generated code. - */ - private String generateCodeForPhysicalActions(FederateInstance federate, ErrorReporter errorReporter) { - CodeBuilder code = new CodeBuilder(); - if (federate.targetConfig.coordination.equals(CoordinationType.CENTRALIZED)) { - // If this program uses centralized coordination then check - // for outputs that depend on physical actions so that null messages can be - // sent to the RTI. - var federateClass = ASTUtils.toDefinition(federate.instantiation.getReactorClass()); - var main = new ReactorInstance(FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, 1); - var instance = new ReactorInstance(federateClass, main, errorReporter); - var outputDelayMap = federate - .findOutputsConnectedToPhysicalActions(instance); - var minDelay = TimeValue.MAX_VALUE; - Output outputFound = null; - for (Output output : outputDelayMap.keySet()) { - var outputDelay = outputDelayMap.get(output); - if (outputDelay.isEarlierThan(minDelay)) { - minDelay = outputDelay; - outputFound = output; - } - } - if (minDelay != TimeValue.MAX_VALUE) { - // Unless silenced, issue a warning. - if (federate.targetConfig.coordinationOptions.advance_message_interval - == null) { - errorReporter.reportWarning(outputFound, String.join("\n", - "Found a path from a physical action to output for reactor " - + addDoubleQuotes(instance.getName()) - + ". ", - "The amount of delay is " - + minDelay - + ".", - "With centralized coordination, this can result in a large number of messages to the RTI.", - "Consider refactoring the code so that the output does not depend on the physical action,", - "or consider using decentralized coordination. To silence this warning, set the target", - "parameter coordination-options with a value like {advance-message-interval: 10 msec}" - )); - } - code.pr( - "_fed.min_delay_from_physical_action_to_federate_output = " - + CTypes.getInstance().getTargetTimeExpr(minDelay) + ";"); - } - } - return code.getCode(); - } - private String getPreamblePath(FederateInstance f) { - return "include" + File.separator + "_" + f.name + "_preamble.h"; - } + private String getPreamblePath(FederateInstance f) { + return "include" + File.separator + "_" + f.name + "_preamble.h"; + } } diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 3eeee4b5cb..391204fdb5 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -7,13 +7,12 @@ import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; - -import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.TargetConfig.ClockSyncOptions; import org.lflang.TargetProperty; import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; import org.lflang.federated.launcher.RtiConfig; @@ -33,563 +32,573 @@ public class CExtensionUtils { - // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); - - /** - * Generate C code that allocates sufficient memory for the following two - * critical data structures that support network control reactions: - *
      - *
    • {@code triggers_for_network_input_control_reactions}: These are triggers that - * are used at runtime to insert network input control reactions into the - * reaction queue.
    • - *
    • {@code trigger_for_network_output_control_reactions}: Triggers for - * network output control reactions, which are unique per each output port. - * There could be multiple network output control reactions for each - * network - * output port if it is connected to multiple downstream federates.
    • - *
    - * - * @param federate The top-level federate instance - * @return A string that allocates memory for the aforementioned three - * structures. - */ - public static String allocateTriggersForFederate( - FederateInstance federate - ) { - - CodeBuilder builder = new CodeBuilder(); - if (federate.networkInputControlReactionsTriggers.size() > 0) { - // Proliferate the network input control reaction trigger array - builder.pr( - """ + // Regular expression pattern for shared_ptr types. + static final Pattern sharedPointerVariable = + Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); + + /** + * Generate C code that allocates sufficient memory for the following two critical data structures + * that support network control reactions: + * + *
      + *
    • {@code triggers_for_network_input_control_reactions}: These are triggers that are used at + * runtime to insert network input control reactions into the reaction queue. + *
    • {@code trigger_for_network_output_control_reactions}: Triggers for network output control + * reactions, which are unique per each output port. There could be multiple network output + * control reactions for each network output port if it is connected to multiple downstream + * federates. + *
    + * + * @param federate The top-level federate instance + * @return A string that allocates memory for the aforementioned three structures. + */ + public static String allocateTriggersForFederate(FederateInstance federate) { + + CodeBuilder builder = new CodeBuilder(); + if (federate.networkInputControlReactionsTriggers.size() > 0) { + // Proliferate the network input control reaction trigger array + builder.pr( + """ // Initialize the array of pointers to network input port triggers _fed.triggers_for_network_input_control_reactions_size = %s; _fed.triggers_for_network_input_control_reactions = (trigger_t**)malloc( _fed.triggers_for_network_input_control_reactions_size * sizeof(trigger_t*)); - """.formatted(federate.networkInputControlReactionsTriggers.size())); - - } - return builder.getCode(); + """ + .formatted(federate.networkInputControlReactionsTriggers.size())); } - - /** - * Generate C code that initializes network actions. - * - * These network actions will be triggered by federate.c whenever a message - * is received from the network. - * @param federate The federate. - * @param main The main reactor that contains the federate (used to lookup references). - * @return - */ - public static String initializeTriggersForNetworkActions(FederateInstance federate, ReactorInstance main) { - CodeBuilder code = new CodeBuilder(); - if (federate.networkMessageActions.size() > 0) { - // Create a static array of trigger_t pointers. - // networkMessageActions is a list of Actions, but we - // need a list of trigger struct names for ActionInstances. - // There should be exactly one ActionInstance in the - // main reactor for each Action. - var triggers = new LinkedList(); - for (Action action : federate.networkMessageActions) { - // Find the corresponding ActionInstance. - var actionInstance = main.lookupActionInstance(action); - triggers.add(CUtil.actionRef(actionInstance, null)); - } - var actionTableCount = 0; - for (String trigger : triggers) { - code.pr("_lf_action_table[" + (actionTableCount++) + "] = (lf_action_base_t*)&" - + trigger + "; \\"); - } - } - return code.getCode(); + return builder.getCode(); + } + + /** + * Generate C code that initializes network actions. + * + *

    These network actions will be triggered by federate.c whenever a message is received from + * the network. + * + * @param federate The federate. + * @param main The main reactor that contains the federate (used to lookup references). + * @return + */ + public static String initializeTriggersForNetworkActions( + FederateInstance federate, ReactorInstance main) { + CodeBuilder code = new CodeBuilder(); + if (federate.networkMessageActions.size() > 0) { + // Create a static array of trigger_t pointers. + // networkMessageActions is a list of Actions, but we + // need a list of trigger struct names for ActionInstances. + // There should be exactly one ActionInstance in the + // main reactor for each Action. + var triggers = new LinkedList(); + for (Action action : federate.networkMessageActions) { + // Find the corresponding ActionInstance. + var actionInstance = main.lookupActionInstance(action); + triggers.add(CUtil.actionRef(actionInstance, null)); + } + var actionTableCount = 0; + for (String trigger : triggers) { + code.pr( + "_lf_action_table[" + + (actionTableCount++) + + "] = (lf_action_base_t*)&" + + trigger + + "; \\"); + } + } + return code.getCode(); + } + + /** + * Generate C code that initializes three critical structures that support network control + * reactions: - triggers_for_network_input_control_reactions: These are triggers that are used at + * runtime to insert network input control reactions into the reaction queue. There could be + * multiple network input control reactions for one network input at multiple levels in the + * hierarchy. - trigger_for_network_output_control_reactions: Triggers for network output control + * reactions, which are unique per each output port. There could be multiple network output + * control reactions for each network output port if it is connected to multiple downstream + * federates. + * + * @param instance The reactor instance that is at any level of the hierarchy within the federate. + * @param federate The top-level federate + * @return A string that initializes the aforementioned three structures. + */ + public static String initializeTriggerForControlReactions( + ReactorInstance instance, ReactorInstance main, FederateInstance federate) { + CodeBuilder builder = new CodeBuilder(); + // The network control reactions are always in the main federated + // reactor + if (instance != main) { + return ""; } - /** - * Generate C code that initializes three critical structures that support - * network control reactions: - * - triggers_for_network_input_control_reactions: These are triggers that are - * used at runtime to insert network input control reactions into the - * reaction queue. There could be multiple network input control reactions - * for one network input at multiple levels in the hierarchy. - * - trigger_for_network_output_control_reactions: Triggers for - * network output control reactions, which are unique per each output port. - * There could be multiple network output control reactions for each network - * output port if it is connected to multiple downstream federates. - * - * @param instance The reactor instance that is at any level of the - * hierarchy within the federate. - * @param federate The top-level federate - * @return A string that initializes the aforementioned three structures. - */ - public static String initializeTriggerForControlReactions( - ReactorInstance instance, - ReactorInstance main, - FederateInstance federate - ) { - CodeBuilder builder = new CodeBuilder(); - // The network control reactions are always in the main federated - // reactor - if (instance != main) { - return ""; - } - - ReactorDecl reactorClass = instance.getDefinition().getReactorClass(); - Reactor reactor = ASTUtils.toDefinition(reactorClass); - String nameOfSelfStruct = CUtil.reactorRef(instance); - - // Initialize triggers for network input control reactions - for (Action trigger : federate.networkInputControlReactionsTriggers) { - // Check if the trigger belongs to this reactor instance - if (ASTUtils.allReactions(reactor).stream().anyMatch(r -> { - return r.getTriggers().stream().anyMatch(t -> { - if (t instanceof VarRef) { - return ((VarRef) t).getVariable().equals(trigger); - } else { - return false; - } - }); - })) { - // Initialize the triggers_for_network_input_control_reactions for the input - builder.pr( - String.join("\n", - "/* Add trigger " + nameOfSelfStruct + "->_lf__"+trigger.getName()+" to the global list of network input ports. */ \\", - "_fed.triggers_for_network_input_control_reactions["+federate.networkInputControlReactionsTriggers.indexOf(trigger)+"]= \\", - " &"+nameOfSelfStruct+"->_lf__"+trigger.getName()+"; \\" - ) - ); - } - } - - nameOfSelfStruct = CUtil.reactorRef(instance); - - // Initialize the trigger for network output control reactions if it doesn't exist. - if (federate.networkOutputControlReactionsTrigger != null) { - builder.pr("_fed.trigger_for_network_output_control_reactions=&" + ReactorDecl reactorClass = instance.getDefinition().getReactorClass(); + Reactor reactor = ASTUtils.toDefinition(reactorClass); + String nameOfSelfStruct = CUtil.reactorRef(instance); + + // Initialize triggers for network input control reactions + for (Action trigger : federate.networkInputControlReactionsTriggers) { + // Check if the trigger belongs to this reactor instance + if (ASTUtils.allReactions(reactor).stream() + .anyMatch( + r -> { + return r.getTriggers().stream() + .anyMatch( + t -> { + if (t instanceof VarRef) { + return ((VarRef) t).getVariable().equals(trigger); + } else { + return false; + } + }); + })) { + // Initialize the triggers_for_network_input_control_reactions for the input + builder.pr( + String.join( + "\n", + "/* Add trigger " + nameOfSelfStruct - + "->_lf__outputControlReactionTrigger; \\"); - } - - return builder.getCode(); + + "->_lf__" + + trigger.getName() + + " to the global list of network input ports. */ \\", + "_fed.triggers_for_network_input_control_reactions[" + + federate.networkInputControlReactionsTriggers.indexOf(trigger) + + "]= \\", + " &" + nameOfSelfStruct + "->_lf__" + trigger.getName() + "; \\")); + } } - /** - * Create a port status field variable for a network input port "input" in - * the self struct of a reactor. - * - * @param input The network input port - * @return A string containing the appropriate variable - */ - public static String createPortStatusFieldForInput(Input input) { - StringBuilder builder = new StringBuilder(); - // Check if the port is a multiport - if (ASTUtils.isMultiport(input)) { - // If it is a multiport, then create an auxiliary list of port - // triggers for each channel of - // the multiport to keep track of the status of each channel - // individually - builder.append("trigger_t* _lf__" + input.getName() - + "_network_port_status;\n"); - } else { - // If it is not a multiport, then we could re-use the port trigger, - // and nothing needs to be - // done - } - return builder.toString(); - } + nameOfSelfStruct = CUtil.reactorRef(instance); - /** - * Given a connection 'delay' predicate, return a string that represents the - * interval_t value of the additional delay that needs to be applied to the - * outgoing message. - * - * The returned additional delay in absence of after on network connection - * (i.e., if delay is passed as a null) is NEVER. This has a special - * meaning in C library functions that send network messages that carry - * timestamps (@see send_timed_message and send_port_absent_to_federate - * in lib/core/federate.c). In this case, the sender will send its current - * tag as the timestamp of the outgoing message without adding a microstep delay. - * If the user has assigned an after delay to the network connection (that - * can be zero) either as a time value (e.g., 200 msec) or as a literal - * (e.g., a parameter), that delay in nsec will be returned. - * - * @param delay - * @return - */ - public static String getNetworkDelayLiteral(Expression delay) { - String additionalDelayString = "NEVER"; - if (delay != null) { - TimeValue tv; - if (delay instanceof ParameterReference) { - // The parameter has to be parameter of the main reactor. - // And that value has to be a Time. - tv = ASTUtils.getDefaultAsTimeValue(((ParameterReference)delay).getParameter()); - } else { - tv = ASTUtils.getLiteralTimeValue(delay); - } - additionalDelayString = Long.toString(tv.toNanoSeconds()); - } - return additionalDelayString; + // Initialize the trigger for network output control reactions if it doesn't exist. + if (federate.networkOutputControlReactionsTrigger != null) { + builder.pr( + "_fed.trigger_for_network_output_control_reactions=&" + + nameOfSelfStruct + + "->_lf__outputControlReactionTrigger; \\"); } - static boolean isSharedPtrType(InferredType type, CTypes types) { - return !type.isUndefined() && sharedPointerVariable.matcher(types.getTargetType(type)).find(); + return builder.getCode(); + } + + /** + * Create a port status field variable for a network input port "input" in the self struct of a + * reactor. + * + * @param input The network input port + * @return A string containing the appropriate variable + */ + public static String createPortStatusFieldForInput(Input input) { + StringBuilder builder = new StringBuilder(); + // Check if the port is a multiport + if (ASTUtils.isMultiport(input)) { + // If it is a multiport, then create an auxiliary list of port + // triggers for each channel of + // the multiport to keep track of the status of each channel + // individually + builder.append("trigger_t* _lf__" + input.getName() + "_network_port_status;\n"); + } else { + // If it is not a multiport, then we could re-use the port trigger, + // and nothing needs to be + // done } - - public static void handleCompileDefinitions( - FederateInstance federate, - int numOfFederates, - RtiConfig rtiConfig - ) { - federate.targetConfig.setByUser.add(TargetProperty.COMPILE_DEFINITIONS); - federate.targetConfig.compileDefinitions.put("FEDERATED", ""); - federate.targetConfig.compileDefinitions.put("FEDERATED_"+federate.targetConfig.coordination.toString().toUpperCase(), ""); - if (federate.targetConfig.auth) { - federate.targetConfig.compileDefinitions.put("FEDERATED_AUTHENTICATED", ""); - } - federate.targetConfig.compileDefinitions.put("NUMBER_OF_FEDERATES", String.valueOf(numOfFederates)); - federate.targetConfig.compileDefinitions.put("EXECUTABLE_PREAMBLE", ""); - federate.targetConfig.compileDefinitions.put("WORKERS_NEEDED_FOR_FEDERATE", String.valueOf(minThreadsToHandleInputPorts(federate))); - - handleAdvanceMessageInterval(federate); - - initializeClockSynchronization(federate, rtiConfig); + return builder.toString(); + } + + /** + * Given a connection 'delay' predicate, return a string that represents the interval_t value of + * the additional delay that needs to be applied to the outgoing message. + * + *

    The returned additional delay in absence of after on network connection (i.e., if delay is + * passed as a null) is NEVER. This has a special meaning in C library functions that send network + * messages that carry timestamps (@see send_timed_message and send_port_absent_to_federate in + * lib/core/federate.c). In this case, the sender will send its current tag as the timestamp of + * the outgoing message without adding a microstep delay. If the user has assigned an after delay + * to the network connection (that can be zero) either as a time value (e.g., 200 msec) or as a + * literal (e.g., a parameter), that delay in nsec will be returned. + * + * @param delay + * @return + */ + public static String getNetworkDelayLiteral(Expression delay) { + String additionalDelayString = "NEVER"; + if (delay != null) { + TimeValue tv; + if (delay instanceof ParameterReference) { + // The parameter has to be parameter of the main reactor. + // And that value has to be a Time. + tv = ASTUtils.getDefaultAsTimeValue(((ParameterReference) delay).getParameter()); + } else { + tv = ASTUtils.getLiteralTimeValue(delay); + } + additionalDelayString = Long.toString(tv.toNanoSeconds()); } - - /** - * The number of threads needs to be at least one larger than the input ports - * to allow the federate to wait on all input ports while allowing an additional - * worker thread to process incoming messages. - * @return The minimum number of threads needed. - */ - public static int minThreadsToHandleInputPorts(FederateInstance federate) { - int nthreads = 1; - nthreads = Math.max(nthreads, federate.networkMessageActions.size() + 1); - return nthreads; + return additionalDelayString; + } + + static boolean isSharedPtrType(InferredType type, CTypes types) { + return !type.isUndefined() && sharedPointerVariable.matcher(types.getTargetType(type)).find(); + } + + public static void handleCompileDefinitions( + FederateInstance federate, int numOfFederates, RtiConfig rtiConfig) { + federate.targetConfig.setByUser.add(TargetProperty.COMPILE_DEFINITIONS); + federate.targetConfig.compileDefinitions.put("FEDERATED", ""); + federate.targetConfig.compileDefinitions.put( + "FEDERATED_" + federate.targetConfig.coordination.toString().toUpperCase(), ""); + if (federate.targetConfig.auth) { + federate.targetConfig.compileDefinitions.put("FEDERATED_AUTHENTICATED", ""); } - - private static void handleAdvanceMessageInterval(FederateInstance federate) { - var advanceMessageInterval = federate.targetConfig.coordinationOptions.advance_message_interval; - federate.targetConfig.setByUser.remove(TargetProperty.COORDINATION_OPTIONS); - if (advanceMessageInterval != null) { - federate.targetConfig.compileDefinitions.put( - "ADVANCE_MESSAGE_INTERVAL", - String.valueOf(advanceMessageInterval.toNanoSeconds()) - ); - } + federate.targetConfig.compileDefinitions.put( + "NUMBER_OF_FEDERATES", String.valueOf(numOfFederates)); + federate.targetConfig.compileDefinitions.put("EXECUTABLE_PREAMBLE", ""); + federate.targetConfig.compileDefinitions.put( + "WORKERS_NEEDED_FOR_FEDERATE", String.valueOf(minThreadsToHandleInputPorts(federate))); + + handleAdvanceMessageInterval(federate); + + initializeClockSynchronization(federate, rtiConfig); + } + + /** + * The number of threads needs to be at least one larger than the input ports to allow the + * federate to wait on all input ports while allowing an additional worker thread to process + * incoming messages. + * + * @return The minimum number of threads needed. + */ + public static int minThreadsToHandleInputPorts(FederateInstance federate) { + int nthreads = 1; + nthreads = Math.max(nthreads, federate.networkMessageActions.size() + 1); + return nthreads; + } + + private static void handleAdvanceMessageInterval(FederateInstance federate) { + var advanceMessageInterval = federate.targetConfig.coordinationOptions.advance_message_interval; + federate.targetConfig.setByUser.remove(TargetProperty.COORDINATION_OPTIONS); + if (advanceMessageInterval != null) { + federate.targetConfig.compileDefinitions.put( + "ADVANCE_MESSAGE_INTERVAL", String.valueOf(advanceMessageInterval.toNanoSeconds())); } + } - static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { - return federate.targetConfig.clockSync != ClockSyncMode.OFF - && (!rtiConfig.getHost().equals(federate.host) + static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { + return federate.targetConfig.clockSync != ClockSyncMode.OFF + && (!rtiConfig.getHost().equals(federate.host) || federate.targetConfig.clockSyncOptions.localFederatesOn); - } - - /** - * Initialize clock synchronization (if enabled) and its related options for a given federate. - * - * Clock synchronization can be enabled using the clock-sync target property. - * @see Documentation - */ - public static void initializeClockSynchronization( - FederateInstance federate, - RtiConfig rtiConfig - ) { - // Check if clock synchronization should be enabled for this federate in the first place - if (clockSyncIsOn(federate, rtiConfig)) { - System.out.println("Initial clock synchronization is enabled for federate " - + federate.id - ); - if (federate.targetConfig.clockSync == ClockSyncMode.ON) { - if (federate.targetConfig.clockSyncOptions.collectStats) { - System.out.println("Will collect clock sync statistics for federate " + federate.id); - // Add libm to the compiler flags - // FIXME: This is a linker flag not compile flag but we don't have a way to add linker flags - // FIXME: This is probably going to fail on MacOS (especially using clang) - // because libm functions are builtin - federate.targetConfig.compilerFlags.add("-lm"); - federate.targetConfig.setByUser.add(TargetProperty.FLAGS); - } - System.out.println("Runtime clock synchronization is enabled for federate " - + federate.id - ); - } - - addClockSyncCompileDefinitions(federate); + } + + /** + * Initialize clock synchronization (if enabled) and its related options for a given federate. + * + *

    Clock synchronization can be enabled using the clock-sync target property. + * + * @see Documentation + */ + public static void initializeClockSynchronization( + FederateInstance federate, RtiConfig rtiConfig) { + // Check if clock synchronization should be enabled for this federate in the first place + if (clockSyncIsOn(federate, rtiConfig)) { + System.out.println("Initial clock synchronization is enabled for federate " + federate.id); + if (federate.targetConfig.clockSync == ClockSyncMode.ON) { + if (federate.targetConfig.clockSyncOptions.collectStats) { + System.out.println("Will collect clock sync statistics for federate " + federate.id); + // Add libm to the compiler flags + // FIXME: This is a linker flag not compile flag but we don't have a way to add linker + // flags + // FIXME: This is probably going to fail on MacOS (especially using clang) + // because libm functions are builtin + federate.targetConfig.compilerFlags.add("-lm"); + federate.targetConfig.setByUser.add(TargetProperty.FLAGS); } - } - - - /** - * Initialize clock synchronization (if enabled) and its related options for a given federate. - * - * Clock synchronization can be enabled using the clock-sync target property. - * @see Documentation - */ - public static void addClockSyncCompileDefinitions(FederateInstance federate) { + System.out.println("Runtime clock synchronization is enabled for federate " + federate.id); + } - ClockSyncMode mode = federate.targetConfig.clockSync; - ClockSyncOptions options = federate.targetConfig.clockSyncOptions; - - - federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_INITIAL", ""); - federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_PERIOD_NS", String.valueOf(options.period.toNanoSeconds())); - federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL", String.valueOf(options.trials)); - federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_ATTENUATION", String.valueOf(options.attenuation)); - - if (mode == ClockSyncMode.ON) { - federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_ON", ""); - if (options.collectStats) { - federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_COLLECT_STATS", ""); - } - } + addClockSyncCompileDefinitions(federate); + } + } + + /** + * Initialize clock synchronization (if enabled) and its related options for a given federate. + * + *

    Clock synchronization can be enabled using the clock-sync target property. + * + * @see Documentation + */ + public static void addClockSyncCompileDefinitions(FederateInstance federate) { + + ClockSyncMode mode = federate.targetConfig.clockSync; + ClockSyncOptions options = federate.targetConfig.clockSyncOptions; + + federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_INITIAL", ""); + federate.targetConfig.compileDefinitions.put( + "_LF_CLOCK_SYNC_PERIOD_NS", String.valueOf(options.period.toNanoSeconds())); + federate.targetConfig.compileDefinitions.put( + "_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL", String.valueOf(options.trials)); + federate.targetConfig.compileDefinitions.put( + "_LF_CLOCK_SYNC_ATTENUATION", String.valueOf(options.attenuation)); + + if (mode == ClockSyncMode.ON) { + federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_ON", ""); + if (options.collectStats) { + federate.targetConfig.compileDefinitions.put("_LF_CLOCK_SYNC_COLLECT_STATS", ""); + } } + } + /** Generate a file to be included by CMake. */ + public static void generateCMakeInclude(FederateInstance federate, FedFileConfig fileConfig) + throws IOException { + Files.createDirectories(fileConfig.getSrcPath().resolve("include")); - /** - * Generate a file to be included by CMake. - */ - public static void generateCMakeInclude( - FederateInstance federate, - FedFileConfig fileConfig - ) throws IOException { - Files.createDirectories(fileConfig.getSrcPath().resolve("include")); - - Path cmakeIncludePath = fileConfig.getSrcPath() - .resolve("include" + File.separator + federate.name + "_extension.cmake"); - - CodeBuilder cmakeIncludeCode = new CodeBuilder(); - - cmakeIncludeCode.pr(generateSerializationCMakeExtension(federate)); - cmakeIncludeCode.pr( - "add_compile_definitions(LF_SOURCE_DIRECTORY=\"" - + fileConfig.srcPath - + "\")" - ); - cmakeIncludeCode.pr( - "add_compile_definitions(LF_PACKAGE_DIRECTORY=\"" - + fileConfig.srcPkgPath - + "\")" - ); - - try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) { - srcWriter.write(cmakeIncludeCode.getCode()); - } + Path cmakeIncludePath = + fileConfig + .getSrcPath() + .resolve("include" + File.separator + federate.name + "_extension.cmake"); - federate.targetConfig.cmakeIncludes.add(fileConfig.getSrcPath().relativize(cmakeIncludePath).toString()); - federate.targetConfig.setByUser.add(TargetProperty.CMAKE_INCLUDE); - } + CodeBuilder cmakeIncludeCode = new CodeBuilder(); + cmakeIncludeCode.pr(generateSerializationCMakeExtension(federate)); + cmakeIncludeCode.pr( + "add_compile_definitions(LF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\")"); + cmakeIncludeCode.pr( + "add_compile_definitions(LF_PACKAGE_DIRECTORY=\"" + fileConfig.srcPkgPath + "\")"); - /** - * Generate code that sends the neighbor structure message to the RTI. - * See {@code MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}. - * - * @param federate The federate that is sending its neighbor structure - */ - public static String generateFederateNeighborStructure(FederateInstance federate) { - var code = new CodeBuilder(); - code.pr(String.join("\n", - "/**", - "* Generated function that sends information about connections between this federate and", - "* other federates where messages are routed through the RTI. Currently, this", - "* only includes logical connections when the coordination is centralized. This", - "* information is needed for the RTI to perform the centralized coordination.", - "* @see MSG_TYPE_NEIGHBOR_STRUCTURE in net_common.h", - "*/", - "void send_neighbor_structure_to_RTI(int rti_socket) {" - )); - code.indent(); - // Initialize the array of information about the federate's immediate upstream - // and downstream relayed (through the RTI) logical connections, to send to the - // RTI. - code.pr(String.join("\n", - "interval_t candidate_tmp;", - "size_t buffer_size = 1 + 8 + ", - " "+federate.dependsOn.keySet().size()+" * ( sizeof(uint16_t) + sizeof(int64_t) ) +", - " "+federate.sendsTo.keySet().size()+" * sizeof(uint16_t);", - "unsigned char buffer_to_send[buffer_size];", - "", - "size_t message_head = 0;", - "buffer_to_send[message_head] = MSG_TYPE_NEIGHBOR_STRUCTURE;", - "message_head++;", - "encode_int32((int32_t)"+federate.dependsOn.keySet().size()+", &(buffer_to_send[message_head]));", - "message_head+=sizeof(int32_t);", - "encode_int32((int32_t)"+federate.sendsTo.keySet().size()+", &(buffer_to_send[message_head]));", - "message_head+=sizeof(int32_t);" - )); - - if (!federate.dependsOn.keySet().isEmpty()) { - // Next, populate these arrays. - // Find the minimum delay in the process. - // FIXME: Zero delay is not really the same as a microstep delay. - for (FederateInstance upstreamFederate : federate.dependsOn.keySet()) { - code.pr(String.join("\n", - "encode_uint16((uint16_t)"+upstreamFederate.id+", &(buffer_to_send[message_head]));", - "message_head += sizeof(uint16_t);" - )); - // The minimum delay calculation needs to be made in the C code because it - // may depend on parameter values. - // FIXME: These would have to be top-level parameters, which don't really - // have any support yet. Ideally, they could be overridden on the command line. - // When that is done, they will need to be in scope here. - var delays = federate.dependsOn.get(upstreamFederate); - if (delays != null) { - // There is at least one delay, so find the minimum. - // If there is no delay at all, this is encoded as NEVER. - code.pr("candidate_tmp = FOREVER;"); - for (Expression delay : delays) { - if (delay == null) { - // Use NEVER to encode no delay at all. - code.pr("candidate_tmp = NEVER;"); - } else { - var delayTime = - delay instanceof ParameterReference - // In that case use the default value. - ? CTypes.getInstance().getTargetTimeExpr(ASTUtils.getDefaultAsTimeValue(((ParameterReference) delay).getParameter())) - : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); - - code.pr(String.join("\n", - "if (" + delayTime + " < candidate_tmp) {", - " candidate_tmp = " + delayTime + ";", - "}" - )); - } - } - code.pr(String.join("\n", - "encode_int64((int64_t)candidate_tmp, &(buffer_to_send[message_head]));", - "message_head += sizeof(int64_t);" - )); - } else { - // Use NEVER to encode no delay at all. - code.pr(String.join("\n", - "encode_int64(NEVER, &(buffer_to_send[message_head]));", - "message_head += sizeof(int64_t);" - )); - } - } - } + try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) { + srcWriter.write(cmakeIncludeCode.getCode()); + } - // Next, set up the downstream array. - if (!federate.sendsTo.keySet().isEmpty()) { - // Next, populate the array. - // Find the minimum delay in the process. - // FIXME: Zero delay is not really the same as a microstep delay. - for (FederateInstance downstreamFederate : federate.sendsTo.keySet()) { - code.pr(String.join("\n", - "encode_uint16("+downstreamFederate.id+", &(buffer_to_send[message_head]));", - "message_head += sizeof(uint16_t);" - )); + federate.targetConfig.cmakeIncludes.add( + fileConfig.getSrcPath().relativize(cmakeIncludePath).toString()); + federate.targetConfig.setByUser.add(TargetProperty.CMAKE_INCLUDE); + } + + /** + * Generate code that sends the neighbor structure message to the RTI. See {@code + * MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}. + * + * @param federate The federate that is sending its neighbor structure + */ + public static String generateFederateNeighborStructure(FederateInstance federate) { + var code = new CodeBuilder(); + code.pr( + String.join( + "\n", + "/**", + "* Generated function that sends information about connections between this federate" + + " and", + "* other federates where messages are routed through the RTI. Currently, this", + "* only includes logical connections when the coordination is centralized. This", + "* information is needed for the RTI to perform the centralized coordination.", + "* @see MSG_TYPE_NEIGHBOR_STRUCTURE in net_common.h", + "*/", + "void send_neighbor_structure_to_RTI(int rti_socket) {")); + code.indent(); + // Initialize the array of information about the federate's immediate upstream + // and downstream relayed (through the RTI) logical connections, to send to the + // RTI. + code.pr( + String.join( + "\n", + "interval_t candidate_tmp;", + "size_t buffer_size = 1 + 8 + ", + " " + + federate.dependsOn.keySet().size() + + " * ( sizeof(uint16_t) + sizeof(int64_t) ) +", + " " + federate.sendsTo.keySet().size() + " * sizeof(uint16_t);", + "unsigned char buffer_to_send[buffer_size];", + "", + "size_t message_head = 0;", + "buffer_to_send[message_head] = MSG_TYPE_NEIGHBOR_STRUCTURE;", + "message_head++;", + "encode_int32((int32_t)" + + federate.dependsOn.keySet().size() + + ", &(buffer_to_send[message_head]));", + "message_head+=sizeof(int32_t);", + "encode_int32((int32_t)" + + federate.sendsTo.keySet().size() + + ", &(buffer_to_send[message_head]));", + "message_head+=sizeof(int32_t);")); + + if (!federate.dependsOn.keySet().isEmpty()) { + // Next, populate these arrays. + // Find the minimum delay in the process. + // FIXME: Zero delay is not really the same as a microstep delay. + for (FederateInstance upstreamFederate : federate.dependsOn.keySet()) { + code.pr( + String.join( + "\n", + "encode_uint16((uint16_t)" + + upstreamFederate.id + + ", &(buffer_to_send[message_head]));", + "message_head += sizeof(uint16_t);")); + // The minimum delay calculation needs to be made in the C code because it + // may depend on parameter values. + // FIXME: These would have to be top-level parameters, which don't really + // have any support yet. Ideally, they could be overridden on the command line. + // When that is done, they will need to be in scope here. + var delays = federate.dependsOn.get(upstreamFederate); + if (delays != null) { + // There is at least one delay, so find the minimum. + // If there is no delay at all, this is encoded as NEVER. + code.pr("candidate_tmp = FOREVER;"); + for (Expression delay : delays) { + if (delay == null) { + // Use NEVER to encode no delay at all. + code.pr("candidate_tmp = NEVER;"); + } else { + var delayTime = + delay instanceof ParameterReference + // In that case use the default value. + ? CTypes.getInstance() + .getTargetTimeExpr( + ASTUtils.getDefaultAsTimeValue( + ((ParameterReference) delay).getParameter())) + : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); + + code.pr( + String.join( + "\n", + "if (" + delayTime + " < candidate_tmp) {", + " candidate_tmp = " + delayTime + ";", + "}")); } + } + code.pr( + String.join( + "\n", + "encode_int64((int64_t)candidate_tmp, &(buffer_to_send[message_head]));", + "message_head += sizeof(int64_t);")); + } else { + // Use NEVER to encode no delay at all. + code.pr( + String.join( + "\n", + "encode_int64(NEVER, &(buffer_to_send[message_head]));", + "message_head += sizeof(int64_t);")); } - code.pr(String.join("\n", - "write_to_socket_errexit(", - " rti_socket, ", - " buffer_size,", - " buffer_to_send,", - " \"Failed to send the neighbor structure message to the RTI.\"", - ");" - )); - code.unindent(); - code.pr("}"); - return code.toString(); + } } - - public static List getFederatedFiles() { - return List.of( - "federated/net_util.c", - "federated/net_util.h", - "federated/net_common.h", - "federated/federate.c", - "federated/federate.h", - "federated/clock-sync.h", - "federated/clock-sync.c" - ); + // Next, set up the downstream array. + if (!federate.sendsTo.keySet().isEmpty()) { + // Next, populate the array. + // Find the minimum delay in the process. + // FIXME: Zero delay is not really the same as a microstep delay. + for (FederateInstance downstreamFederate : federate.sendsTo.keySet()) { + code.pr( + String.join( + "\n", + "encode_uint16(" + downstreamFederate.id + ", &(buffer_to_send[message_head]));", + "message_head += sizeof(uint16_t);")); + } } - - /** - * Surround {@code code} with blocks to ensure that code only executes - * if the program is federated. - */ - public static String surroundWithIfFederated(String code) { - return """ + code.pr( + String.join( + "\n", + "write_to_socket_errexit(", + " rti_socket, ", + " buffer_size,", + " buffer_to_send,", + " \"Failed to send the neighbor structure message to the RTI.\"", + ");")); + code.unindent(); + code.pr("}"); + return code.toString(); + } + + public static List getFederatedFiles() { + return List.of( + "federated/net_util.c", + "federated/net_util.h", + "federated/net_common.h", + "federated/federate.c", + "federated/federate.h", + "federated/clock-sync.h", + "federated/clock-sync.c"); + } + + /** + * Surround {@code code} with blocks to ensure that code only executes if the program is + * federated. + */ + public static String surroundWithIfFederated(String code) { + return """ #ifdef FEDERATED %s #endif // FEDERATED - """.formatted(code); - } - - /** - * Surround {@code code} with blocks to ensure that code only executes - * if the program is federated and has a centralized coordination. - */ - public static String surroundWithIfFederatedCentralized(String code) { - return """ + """ + .formatted(code); + } + + /** + * Surround {@code code} with blocks to ensure that code only executes if the program is federated + * and has a centralized coordination. + */ + public static String surroundWithIfFederatedCentralized(String code) { + return """ #ifdef FEDERATED_CENTRALIZED %s #endif // FEDERATED_CENTRALIZED - """.formatted(code); - } - - /** - * Surround {@code code} with blocks to ensure that code only executes - * if the program is federated and has a decentralized coordination. - */ - public static String surroundWithIfFederatedDecentralized(String code) { - return """ + """ + .formatted(code); + } + + /** + * Surround {@code code} with blocks to ensure that code only executes if the program is federated + * and has a decentralized coordination. + */ + public static String surroundWithIfFederatedDecentralized(String code) { + return """ #ifdef FEDERATED_DECENTRALIZED %s #endif // FEDERATED_DECENTRALIZED - """.formatted(code); + """ + .formatted(code); + } + + /** Generate preamble code needed for enabled serializers of the federate. */ + public static String generateSerializationIncludes( + FederateInstance federate, FedFileConfig fileConfig) { + CodeBuilder code = new CodeBuilder(); + for (SupportedSerializers serializer : federate.enabledSerializers) { + switch (serializer) { + case NATIVE: + case PROTO: + { + // No need to do anything at this point. + break; + } + case ROS2: + { + var ROSSerializer = new FedROS2CPPSerialization(); + code.pr(ROSSerializer.generatePreambleForSupport().toString()); + break; + } + } } - - /** - * Generate preamble code needed for enabled serializers of the federate. - */ - public static String generateSerializationIncludes( - FederateInstance federate, - FedFileConfig fileConfig - ) { - CodeBuilder code = new CodeBuilder(); - for (SupportedSerializers serializer : federate.enabledSerializers) { - switch (serializer) { - case NATIVE: - case PROTO: { - // No need to do anything at this point. - break; - } - case ROS2: { - var ROSSerializer = new FedROS2CPPSerialization(); - code.pr(ROSSerializer.generatePreambleForSupport().toString()); - break; - } - } - } - return code.getCode(); - } - - /** - * Generate cmake-include code needed for enabled serializers of the federate. - */ - public static String generateSerializationCMakeExtension( - FederateInstance federate - ) { - CodeBuilder code = new CodeBuilder(); - for (SupportedSerializers serializer : federate.enabledSerializers) { - switch (serializer) { - case NATIVE: - case PROTO: { - // No CMake code is needed for now - break; - } - case ROS2: { - var ROSSerializer = new FedROS2CPPSerialization(); - code.pr(ROSSerializer.generateCompilerExtensionForSupport()); - break; - } - } - } - return code.getCode(); + return code.getCode(); + } + + /** Generate cmake-include code needed for enabled serializers of the federate. */ + public static String generateSerializationCMakeExtension(FederateInstance federate) { + CodeBuilder code = new CodeBuilder(); + for (SupportedSerializers serializer : federate.enabledSerializers) { + switch (serializer) { + case NATIVE: + case PROTO: + { + // No CMake code is needed for now + break; + } + case ROS2: + { + var ROSSerializer = new FedROS2CPPSerialization(); + code.pr(ROSSerializer.generateCompilerExtensionForSupport()); + break; + } + } } + return code.getCode(); + } } diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java index d50a801617..17ac198781 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java @@ -1,7 +1,6 @@ package org.lflang.federated.extensions; import java.io.IOException; - import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetProperty.CoordinationType; @@ -17,110 +16,110 @@ public interface FedTargetExtension { - /** - * Perform necessary actions to initialize the target config. - * - * @param context - * @param numOfFederates - * @param federate The federate instance. - * @param fileConfig An instance of {@code FedFileConfig}. - * @param errorReporter Used to report errors. - */ - void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, - ErrorReporter errorReporter, RtiConfig rtiConfig) throws IOException; + /** + * Perform necessary actions to initialize the target config. + * + * @param context + * @param numOfFederates + * @param federate The federate instance. + * @param fileConfig An instance of {@code FedFileConfig}. + * @param errorReporter Used to report errors. + */ + void initializeTargetConfig( + LFGeneratorContext context, + int numOfFederates, + FederateInstance federate, + FedFileConfig fileConfig, + ErrorReporter errorReporter, + RtiConfig rtiConfig) + throws IOException; - /** - * Generate code for the body of a reaction that handles the - * action that is triggered by receiving a message from a remote - * federate. - * @param action The action. - * @param sendingPort The output port providing the data to send. - * @param receivingPort The ID of the destination port. - * @param connection FIXME - * @param type FIXME - * @param coordinationType The coordination type - * @param errorReporter - */ - String generateNetworkReceiverBody( - Action action, - VarRef sendingPort, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - CoordinationType coordinationType, - ErrorReporter errorReporter - ); + /** + * Generate code for the body of a reaction that handles the action that is triggered by receiving + * a message from a remote federate. + * + * @param action The action. + * @param sendingPort The output port providing the data to send. + * @param receivingPort The ID of the destination port. + * @param connection FIXME + * @param type FIXME + * @param coordinationType The coordination type + * @param errorReporter + */ + String generateNetworkReceiverBody( + Action action, + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter); - /** - * Generate code for the body of a reaction that handles an output - * that is to be sent over the network. - * @param sendingPort The output port providing the data to send. - * @param receivingPort The variable reference to the destination port. - * @param connection - * @param type - * @param coordinationType - * @param errorReporter FIXME - */ - String generateNetworkSenderBody( - VarRef sendingPort, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - CoordinationType coordinationType, - ErrorReporter errorReporter - ); + /** + * Generate code for the body of a reaction that handles an output that is to be sent over the + * network. + * + * @param sendingPort The output port providing the data to send. + * @param receivingPort The variable reference to the destination port. + * @param connection + * @param type + * @param coordinationType + * @param errorReporter FIXME + */ + String generateNetworkSenderBody( + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter); - /** - * Generate code for the body of a reaction that decides whether the trigger for the given - * port is going to be present or absent for the current logical time. - * This reaction is put just before the first reaction that is triggered by the network - * input port "port" or has it in its sources. If there are only connections to contained - * reactors, in the top-level reactor. - * - * @param receivingPortID The port to generate the control reaction for - * @param maxSTP The maximum value of STP is assigned to reactions (if any) - * that have port as their trigger or source - * @param coordination FIXME - */ - String generateNetworkInputControlReactionBody( - int receivingPortID, - TimeValue maxSTP, - CoordinationType coordination - ); + /** + * Generate code for the body of a reaction that decides whether the trigger for the given port is + * going to be present or absent for the current logical time. This reaction is put just before + * the first reaction that is triggered by the network input port "port" or has it in its sources. + * If there are only connections to contained reactors, in the top-level reactor. + * + * @param receivingPortID The port to generate the control reaction for + * @param maxSTP The maximum value of STP is assigned to reactions (if any) that have port as + * their trigger or source + * @param coordination FIXME + */ + String generateNetworkInputControlReactionBody( + int receivingPortID, TimeValue maxSTP, CoordinationType coordination); - /** - * Generate code for the body of a reaction that sends a port status message for the given - * port if it is absent. - * - * @oaram srcOutputPort FIXME - * @param connection FIXME - */ - String generateNetworkOutputControlReactionBody( - VarRef srcOutputPort, - FedConnectionInstance connection - ); + /** + * Generate code for the body of a reaction that sends a port status message for the given port if + * it is absent. + * + * @oaram srcOutputPort FIXME + * @param connection FIXME + */ + String generateNetworkOutputControlReactionBody( + VarRef srcOutputPort, FedConnectionInstance connection); - /** Optionally apply additional annotations to the reaction. */ - default void annotateReaction(Reaction reaction) {} + /** Optionally apply additional annotations to the reaction. */ + default void annotateReaction(Reaction reaction) {} - /** - * Return the type for the raw network buffer in the target language (e.g., {@code uint_8} in C). This would be the type of the - * network messages after serialization and before deserialization. It is primarily used to determine the type for the - * network action at the receiver. - */ - String getNetworkBufferType(); + /** + * Return the type for the raw network buffer in the target language (e.g., {@code uint_8} in C). + * This would be the type of the network messages after serialization and before deserialization. + * It is primarily used to determine the type for the network action at the receiver. + */ + String getNetworkBufferType(); - /** - * Add necessary preamble to the source to set up federated execution. - * - * @param federate - * @param rtiConfig - * @param errorReporter - * @return - */ - String generatePreamble(FederateInstance federate, - FedFileConfig fileConfig, - RtiConfig rtiConfig, - ErrorReporter errorReporter) - throws IOException; + /** + * Add necessary preamble to the source to set up federated execution. + * + * @param federate + * @param rtiConfig + * @param errorReporter + * @return + */ + String generatePreamble( + FederateInstance federate, + FedFileConfig fileConfig, + RtiConfig rtiConfig, + ErrorReporter errorReporter) + throws IOException; } diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java index 5caafc1c0c..ca16d1d445 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java @@ -1,24 +1,26 @@ package org.lflang.federated.extensions; import org.lflang.Target; -import org.lflang.lf.TargetDecl; /** * Class for instantiating target extensions. + * * @author Soroush Bateni */ public class FedTargetExtensionFactory { - /** - * Given a target, return the appropriate extension. - */ - public static FedTargetExtension getExtension(Target target) { - switch (target) { - case CCPP: - case C: return new CExtension(); - case Python: return new PythonExtension(); - case TS: return new TSExtension(); - default: throw new RuntimeException("Target not supported"); - } + /** Given a target, return the appropriate extension. */ + public static FedTargetExtension getExtension(Target target) { + switch (target) { + case CCPP: + case C: + return new CExtension(); + case Python: + return new PythonExtension(); + case TS: + return new TSExtension(); + default: + throw new RuntimeException("Target not supported"); } + } } diff --git a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java b/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java index 15606c6fa0..6fd1cb3dc9 100644 --- a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java @@ -27,11 +27,10 @@ package org.lflang.federated.extensions; import java.io.IOException; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetProperty.CoordinationType; +import org.lflang.ast.ASTUtils; import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; @@ -46,165 +45,149 @@ import org.lflang.lf.VarRef; /** - * An extension class to the PythonGenerator that enables certain federated - * functionalities. + * An extension class to the PythonGenerator that enables certain federated functionalities. * * @author Soroush Bateni */ public class PythonExtension extends CExtension { - @Override - protected void generateCMakeInclude(FederateInstance federate, FedFileConfig fileConfig) throws IOException {} - - @Override - protected String generateSerializationIncludes(FederateInstance federate, FedFileConfig fileConfig) { - CodeBuilder code = new CodeBuilder(); - for (SupportedSerializers serialization : federate.enabledSerializers) { - switch (serialization) { - case NATIVE: { - FedNativePythonSerialization pickler = new FedNativePythonSerialization(); - code.pr(pickler.generatePreambleForSupport().toString()); - } - case PROTO: { - // Nothing needs to be done - } - case ROS2: { - // FIXME: Not supported yet - } - } - } - return code.getCode(); - } - - @Override - public String generateNetworkSenderBody( - VarRef sendingPort, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - CoordinationType coordinationType, - ErrorReporter errorReporter - ) { - var result = new CodeBuilder(); - - // We currently have no way to mark a reaction "unordered" - // in the AST, so we use a magic string at the start of the body. - result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); - result.pr(PyUtil.generateGILAcquireCode() + "\n"); - result.pr( - super.generateNetworkSenderBody( - sendingPort, - receivingPort, - connection, - type, - coordinationType, - errorReporter - ) - ); - result.pr(PyUtil.generateGILReleaseCode() + "\n"); - return result.getCode(); - } - - @Override - public String generateNetworkReceiverBody( - Action action, - VarRef sendingPort, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - CoordinationType coordinationType, - ErrorReporter errorReporter - ) { - var result = new CodeBuilder(); - - // We currently have no way to mark a reaction "unordered" - // in the AST, so we use a magic string at the start of the body. - result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); - result.pr(PyUtil.generateGILAcquireCode() + "\n"); - result.pr( - super.generateNetworkReceiverBody( - action, - sendingPort, - receivingPort, - connection, - type, - coordinationType, - errorReporter - ) - ); - result.pr(PyUtil.generateGILReleaseCode() + "\n"); - return result.getCode(); - - } - - @Override - protected void deserialize( - Action action, - VarRef receivingPort, - FedConnectionInstance connection, - InferredType type, - String receiveRef, - CodeBuilder result, - ErrorReporter errorReporter - ) { - String value = ""; - switch (connection.getSerializer()) { - case NATIVE: { - value = action.getName(); + @Override + protected void generateCMakeInclude(FederateInstance federate, FedFileConfig fileConfig) + throws IOException {} + + @Override + protected String generateSerializationIncludes( + FederateInstance federate, FedFileConfig fileConfig) { + CodeBuilder code = new CodeBuilder(); + for (SupportedSerializers serialization : federate.enabledSerializers) { + switch (serialization) { + case NATIVE: + { FedNativePythonSerialization pickler = new FedNativePythonSerialization(); - result.pr(pickler.generateNetworkDeserializerCode(value, null)); - result.pr("lf_set(" + receiveRef + ", " - + FedSerialization.deserializedVarName + ");\n"); - break; - } - case PROTO: { - throw new UnsupportedOperationException("Protobuf serialization is not supported yet."); + code.pr(pickler.generatePreambleForSupport().toString()); + } + case PROTO: + { + // Nothing needs to be done + } + case ROS2: + { + // FIXME: Not supported yet + } + } + } + return code.getCode(); + } + + @Override + public String generateNetworkSenderBody( + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter) { + var result = new CodeBuilder(); + + // We currently have no way to mark a reaction "unordered" + // in the AST, so we use a magic string at the start of the body. + result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); + result.pr(PyUtil.generateGILAcquireCode() + "\n"); + result.pr( + super.generateNetworkSenderBody( + sendingPort, receivingPort, connection, type, coordinationType, errorReporter)); + result.pr(PyUtil.generateGILReleaseCode() + "\n"); + return result.getCode(); + } + + @Override + public String generateNetworkReceiverBody( + Action action, + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter) { + var result = new CodeBuilder(); + + // We currently have no way to mark a reaction "unordered" + // in the AST, so we use a magic string at the start of the body. + result.pr("// " + ReactionInstance.UNORDERED_REACTION_MARKER + "\n"); + result.pr(PyUtil.generateGILAcquireCode() + "\n"); + result.pr( + super.generateNetworkReceiverBody( + action, sendingPort, receivingPort, connection, type, coordinationType, errorReporter)); + result.pr(PyUtil.generateGILReleaseCode() + "\n"); + return result.getCode(); + } + + @Override + protected void deserialize( + Action action, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + String receiveRef, + CodeBuilder result, + ErrorReporter errorReporter) { + String value = ""; + switch (connection.getSerializer()) { + case NATIVE: + { + value = action.getName(); + FedNativePythonSerialization pickler = new FedNativePythonSerialization(); + result.pr(pickler.generateNetworkDeserializerCode(value, null)); + result.pr("lf_set(" + receiveRef + ", " + FedSerialization.deserializedVarName + ");\n"); + break; } - 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."); } } - - @Override - protected void serializeAndSend( - FedConnectionInstance connection, - InferredType type, - String sendRef, - CodeBuilder result, - String sendingFunction, - String commonArgs, - ErrorReporter errorReporter - ) { - String lengthExpression = ""; - String pointerExpression = ""; - switch (connection.getSerializer()) { - case NATIVE: { - var variableToSerialize = sendRef + "->value"; - FedNativePythonSerialization pickler = new FedNativePythonSerialization(); - lengthExpression = pickler.serializedBufferLength(); - pointerExpression = pickler.seializedBufferVar(); - result.pr(pickler.generateNetworkSerializerCode(variableToSerialize, null)); - result.pr( - "size_t message_length = " + lengthExpression + ";"); - result.pr( - sendingFunction + "(" + commonArgs + ", " + pointerExpression - + ");\n"); - break; + } + + @Override + protected void serializeAndSend( + FedConnectionInstance connection, + InferredType type, + String sendRef, + CodeBuilder result, + String sendingFunction, + String commonArgs, + ErrorReporter errorReporter) { + String lengthExpression = ""; + String pointerExpression = ""; + switch (connection.getSerializer()) { + case NATIVE: + { + var variableToSerialize = sendRef + "->value"; + FedNativePythonSerialization pickler = new FedNativePythonSerialization(); + lengthExpression = pickler.serializedBufferLength(); + pointerExpression = pickler.seializedBufferVar(); + result.pr(pickler.generateNetworkSerializerCode(variableToSerialize, null)); + result.pr("size_t message_length = " + lengthExpression + ";"); + result.pr(sendingFunction + "(" + commonArgs + ", " + pointerExpression + ");\n"); + break; } - case PROTO: { - throw new UnsupportedOperationException("Protbuf serialization is not supported yet."); + case PROTO: + { + throw new UnsupportedOperationException("Protbuf serialization is not supported yet."); } - case ROS2: { - throw new UnsupportedOperationException("ROS2 serialization is not supported yet."); - } - + case ROS2: + { + throw new UnsupportedOperationException("ROS2 serialization is not supported yet."); } } + } - @Override - public void annotateReaction(Reaction reaction) { - ASTUtils.addReactionAttribute(reaction, "_c_body"); - } + @Override + public void annotateReaction(Reaction reaction) { + ASTUtils.addReactionAttribute(reaction, "_c_body"); + } } diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index 4a70f4cc6b..b52b739803 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -6,12 +6,11 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.federated.generator.FedASTUtils; import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; @@ -27,73 +26,94 @@ import org.lflang.lf.Variable; public class TSExtension implements FedTargetExtension { - @Override - public void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, RtiConfig rtiConfig) throws IOException { - - } + @Override + public void initializeTargetConfig( + LFGeneratorContext context, + int numOfFederates, + FederateInstance federate, + FedFileConfig fileConfig, + ErrorReporter errorReporter, + RtiConfig rtiConfig) + throws IOException {} - @Override - public String generateNetworkReceiverBody(Action action, VarRef sendingPort, VarRef receivingPort, FedConnectionInstance connection, InferredType type, CoordinationType coordinationType, ErrorReporter errorReporter) { - return """ + @Override + public String generateNetworkReceiverBody( + Action action, + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter) { + return """ // generateNetworkReceiverBody if (%1$s !== undefined) { %2$s.%3$s = %1$s; } - """.formatted( + """ + .formatted( action.getName(), receivingPort.getContainer().getName(), - receivingPort.getVariable().getName() - ); - } + receivingPort.getVariable().getName()); + } - @Override - public String generateNetworkSenderBody(VarRef sendingPort, VarRef receivingPort, FedConnectionInstance connection, InferredType type, CoordinationType coordinationType, ErrorReporter errorReporter) { - return""" + @Override + public String generateNetworkSenderBody( + VarRef sendingPort, + VarRef receivingPort, + FedConnectionInstance connection, + InferredType type, + CoordinationType coordinationType, + ErrorReporter errorReporter) { + return """ if (%1$s.%2$s !== undefined) { this.util.sendRTITimedMessage(%1$s.%2$s, %3$s, %4$s, %5$s); } - """.formatted( + """ + .formatted( sendingPort.getContainer().getName(), sendingPort.getVariable().getName(), connection.getDstFederate().id, connection.getDstFederate().networkMessageActions.size(), - getNetworkDelayLiteral(connection.getDefinition().getDelay()) - ); - } + getNetworkDelayLiteral(connection.getDefinition().getDelay())); + } - private String getNetworkDelayLiteral(Expression e) { - var cLiteral = CExtensionUtils.getNetworkDelayLiteral(e); - return cLiteral.equals("NEVER") ? "0" : cLiteral; - } + private String getNetworkDelayLiteral(Expression e) { + var cLiteral = CExtensionUtils.getNetworkDelayLiteral(e); + return cLiteral.equals("NEVER") ? "0" : cLiteral; + } - @Override - public String generateNetworkInputControlReactionBody(int receivingPortID, TimeValue maxSTP, CoordinationType coordination) { - return "// TODO(hokeun): Figure out what to do for generateNetworkInputControlReactionBody"; - } + @Override + public String generateNetworkInputControlReactionBody( + int receivingPortID, TimeValue maxSTP, CoordinationType coordination) { + return "// TODO(hokeun): Figure out what to do for generateNetworkInputControlReactionBody"; + } - @Override - public String generateNetworkOutputControlReactionBody(VarRef srcOutputPort, FedConnectionInstance connection) { - return "// TODO(hokeun): Figure out what to do for generateNetworkOutputControlReactionBody"; - } + @Override + public String generateNetworkOutputControlReactionBody( + VarRef srcOutputPort, FedConnectionInstance connection) { + return "// TODO(hokeun): Figure out what to do for generateNetworkOutputControlReactionBody"; + } - @Override - public String getNetworkBufferType() { - return ""; - } + @Override + public String getNetworkBufferType() { + return ""; + } - /** - * Add necessary preamble to the source to set up federated execution. - * - * @return - */ - @Override - public String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, - RtiConfig rtiConfig, - ErrorReporter errorReporter) { - var minOutputDelay = getMinOutputDelay(federate, fileConfig, errorReporter); - var upstreamConnectionDelays = getUpstreamConnectionDelays(federate); - return - """ + /** + * Add necessary preamble to the source to set up federated execution. + * + * @return + */ + @Override + public String generatePreamble( + FederateInstance federate, + FedFileConfig fileConfig, + RtiConfig rtiConfig, + ErrorReporter errorReporter) { + var minOutputDelay = getMinOutputDelay(federate, fileConfig, errorReporter); + var upstreamConnectionDelays = getUpstreamConnectionDelays(federate); + return """ const defaultFederateConfig: __FederateConfig = { dependsOn: [%s], executionTimeout: undefined, @@ -108,94 +128,101 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf sendsTo: [%s], upstreamConnectionDelays: [%s] } - """.formatted( + """ + .formatted( federate.dependsOn.keySet().stream() - .map(e->String.valueOf(e.id)) - .collect(Collectors.joining(",")), + .map(e -> String.valueOf(e.id)) + .collect(Collectors.joining(",")), federate.id, - minOutputDelay == null ? "undefined" - : "%s".formatted(TSTypes.getInstance().getTargetTimeExpr(minOutputDelay)), - federate.networkMessageActions - .stream() + minOutputDelay == null + ? "undefined" + : "%s".formatted(TSTypes.getInstance().getTargetTimeExpr(minOutputDelay)), + federate.networkMessageActions.stream() .map(Variable::getName) .collect(Collectors.joining(",", "\"", "\"")), rtiConfig.getHost(), rtiConfig.getPort(), federate.sendsTo.keySet().stream() - .map(e->String.valueOf(e.id)) - .collect(Collectors.joining(",")), - upstreamConnectionDelays.stream().collect(Collectors.joining(",")) - ); - } + .map(e -> String.valueOf(e.id)) + .collect(Collectors.joining(",")), + upstreamConnectionDelays.stream().collect(Collectors.joining(","))); + } - private TimeValue getMinOutputDelay(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - if (federate.targetConfig.coordination.equals(CoordinationType.CENTRALIZED)) { - // If this program uses centralized coordination then check - // for outputs that depend on physical actions so that null messages can be - // sent to the RTI. - var federateClass = ASTUtils.toDefinition(federate.instantiation.getReactorClass()); - var main = new ReactorInstance(FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, 1); - var instance = new ReactorInstance(federateClass, main, errorReporter); - var outputDelayMap = federate - .findOutputsConnectedToPhysicalActions(instance); - var minOutputDelay = TimeValue.MAX_VALUE; - Output outputFound = null; - for (Output output : outputDelayMap.keySet()) { - var outputDelay = outputDelayMap.get(output); - if (outputDelay.isEarlierThan(minOutputDelay)) { - minOutputDelay = outputDelay; - outputFound = output; - } - } - if (minOutputDelay != TimeValue.MAX_VALUE) { - // Unless silenced, issue a warning. - if (federate.targetConfig.coordinationOptions.advance_message_interval - == null) { - errorReporter.reportWarning(outputFound, String.join("\n", - "Found a path from a physical action to output for reactor " - + addDoubleQuotes(instance.getName()) - + ". ", - "The amount of delay is " - + minOutputDelay - + ".", - "With centralized coordination, this can result in a large number of messages to the RTI.", - "Consider refactoring the code so that the output does not depend on the physical action,", - "or consider using decentralized coordination. To silence this warning, set the target", - "parameter coordination-options with a value like {advance-message-interval: 10 msec}" - )); - } - return minOutputDelay; - } + private TimeValue getMinOutputDelay( + FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + if (federate.targetConfig.coordination.equals(CoordinationType.CENTRALIZED)) { + // If this program uses centralized coordination then check + // for outputs that depend on physical actions so that null messages can be + // sent to the RTI. + var federateClass = ASTUtils.toDefinition(federate.instantiation.getReactorClass()); + var main = + new ReactorInstance( + FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), + errorReporter, + 1); + var instance = new ReactorInstance(federateClass, main, errorReporter); + var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); + var minOutputDelay = TimeValue.MAX_VALUE; + Output outputFound = null; + for (Output output : outputDelayMap.keySet()) { + var outputDelay = outputDelayMap.get(output); + if (outputDelay.isEarlierThan(minOutputDelay)) { + minOutputDelay = outputDelay; + outputFound = output; } - return null; + } + if (minOutputDelay != TimeValue.MAX_VALUE) { + // Unless silenced, issue a warning. + if (federate.targetConfig.coordinationOptions.advance_message_interval == null) { + errorReporter.reportWarning( + outputFound, + String.join( + "\n", + "Found a path from a physical action to output for reactor " + + addDoubleQuotes(instance.getName()) + + ". ", + "The amount of delay is " + minOutputDelay + ".", + "With centralized coordination, this can result in a large number of messages to" + + " the RTI.", + "Consider refactoring the code so that the output does not depend on the physical" + + " action,", + "or consider using decentralized coordination. To silence this warning, set the" + + " target", + "parameter coordination-options with a value like {advance-message-interval: 10" + + " msec}")); + } + return minOutputDelay; + } } + return null; + } - private List getUpstreamConnectionDelays(FederateInstance federate) { - List candidates = new ArrayList<>(); - if (!federate.dependsOn.keySet().isEmpty()) { - for (FederateInstance upstreamFederate: federate.dependsOn.keySet()) { - String element = "["; - var delays = federate.dependsOn.get(upstreamFederate); - int cnt = 0; - if (delays != null) { - for (Expression delay : delays) { - if (delay == null) { - element += "TimeValue.NEVER()"; - } else { - element += "TimeValue.nsec(" + getNetworkDelayLiteral(delay) + ")"; - } - cnt++; - if (cnt != delays.size()) { - element += ", "; - } - } - } else { - element += "TimeValue.NEVER()"; - } - element += "]"; - candidates.add(element); + private List getUpstreamConnectionDelays(FederateInstance federate) { + List candidates = new ArrayList<>(); + if (!federate.dependsOn.keySet().isEmpty()) { + for (FederateInstance upstreamFederate : federate.dependsOn.keySet()) { + String element = "["; + var delays = federate.dependsOn.get(upstreamFederate); + int cnt = 0; + if (delays != null) { + for (Expression delay : delays) { + if (delay == null) { + element += "TimeValue.NEVER()"; + } else { + element += "TimeValue.nsec(" + getNetworkDelayLiteral(delay) + ")"; + } + cnt++; + if (cnt != delays.size()) { + element += ", "; } + } + } else { + element += "TimeValue.NEVER()"; } - return candidates; + element += "]"; + candidates.add(element); + } } + return candidates; + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java index cedb9da017..338fbff242 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java +++ b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java @@ -27,6 +27,7 @@ package org.lflang.federated.generator; +import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -38,17 +39,15 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IteratorExtensions; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.ModelInfo; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.federated.extensions.FedTargetExtensionFactory; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.PortInstance; @@ -68,795 +67,740 @@ import org.lflang.lf.VarRef; import org.lflang.lf.Variable; -import com.google.common.collect.Iterators; - /** - * A helper class for AST transformations needed for federated - * execution. + * A helper class for AST transformations needed for federated execution. * * @author Soroush Bateni * @author Edward A. Lee */ public class FedASTUtils { - /** - * Map from reactions to bank indices - */ - private static Map reactionBankIndices = null; - - /** - * Mark the specified reaction to belong to only the specified - * bank index. This is needed because reactions cannot declare - * a specific bank index as an effect or trigger. Reactions that - * send messages between federates, including absent messages, - * need to be specific to a bank member. - * @param reaction The reaction. - * @param bankIndex The bank index, or -1 if there is no bank. - */ - public static void setReactionBankIndex(Reaction reaction, int bankIndex) { - if (bankIndex < 0) { - return; - } - if (reactionBankIndices == null) { - reactionBankIndices = new LinkedHashMap<>(); - } - reactionBankIndices.put(reaction, bankIndex); + /** Map from reactions to bank indices */ + private static Map reactionBankIndices = null; + + /** + * Mark the specified reaction to belong to only the specified bank index. This is needed because + * reactions cannot declare a specific bank index as an effect or trigger. Reactions that send + * messages between federates, including absent messages, need to be specific to a bank member. + * + * @param reaction The reaction. + * @param bankIndex The bank index, or -1 if there is no bank. + */ + public static void setReactionBankIndex(Reaction reaction, int bankIndex) { + if (bankIndex < 0) { + return; } - - /** - * Return the reaction bank index. - * @see #setReactionBankIndex(Reaction reaction, int bankIndex) - * @param reaction The reaction. - * @return The reaction bank index, if one has been set, and -1 otherwise. - */ - public static int getReactionBankIndex(Reaction reaction) { - if (reactionBankIndices == null) return -1; - if (reactionBankIndices.get(reaction) == null) return -1; - return reactionBankIndices.get(reaction); - } - - /** - * Find the federated reactor in a .lf file. - * - * @param resource Resource representing a .lf file. - * @return The federated reactor if found. - */ - public static Reactor findFederatedReactor(Resource resource) { - return IteratorExtensions.findFirst( - Iterators.filter(resource.getAllContents(), Reactor.class), - Reactor::isFederated - ); + if (reactionBankIndices == null) { + reactionBankIndices = new LinkedHashMap<>(); } - - /** - * Replace the specified connection with communication between federates. - * - * @param connection Network connection between two federates. - * @param coordination One of CoordinationType.DECENTRALIZED or - * CoordinationType.CENTRALIZED. - * @param errorReporter Used to report errors encountered. - */ - public static void makeCommunication( - FedConnectionInstance connection, - CoordinationType coordination, - ErrorReporter errorReporter + reactionBankIndices.put(reaction, bankIndex); + } + + /** + * Return the reaction bank index. + * + * @see #setReactionBankIndex(Reaction reaction, int bankIndex) + * @param reaction The reaction. + * @return The reaction bank index, if one has been set, and -1 otherwise. + */ + public static int getReactionBankIndex(Reaction reaction) { + if (reactionBankIndices == null) return -1; + if (reactionBankIndices.get(reaction) == null) return -1; + return reactionBankIndices.get(reaction); + } + + /** + * Find the federated reactor in a .lf file. + * + * @param resource Resource representing a .lf file. + * @return The federated reactor if found. + */ + public static Reactor findFederatedReactor(Resource resource) { + return IteratorExtensions.findFirst( + Iterators.filter(resource.getAllContents(), Reactor.class), Reactor::isFederated); + } + + /** + * Replace the specified connection with communication between federates. + * + * @param connection Network connection between two federates. + * @param coordination One of CoordinationType.DECENTRALIZED or CoordinationType.CENTRALIZED. + * @param errorReporter Used to report errors encountered. + */ + public static void makeCommunication( + FedConnectionInstance connection, + CoordinationType coordination, + ErrorReporter errorReporter) { + + // Add the sender reaction. + addNetworkSenderReaction(connection, coordination, errorReporter); + + // Next, generate control reactions + if (!connection.getDefinition().isPhysical() + && + // Connections that are physical don't need control reactions + connection.getDefinition().getDelay() + == null // Connections that have delays don't need control reactions ) { + // Add the network output control reaction to the parent + FedASTUtils.addNetworkOutputControlReaction(connection); - // Add the sender reaction. - addNetworkSenderReaction( - connection, - coordination, - errorReporter - ); - - // Next, generate control reactions - if ( - !connection.getDefinition().isPhysical() && - // Connections that are physical don't need control reactions - connection.getDefinition().getDelay() - == null // Connections that have delays don't need control reactions - ) { - // Add the network output control reaction to the parent - FedASTUtils.addNetworkOutputControlReaction(connection); - - // Add the network input control reaction to the parent - FedASTUtils.addNetworkInputControlReaction(connection, coordination, errorReporter); - } - - // Create the network action (@see createNetworkAction) - Action networkAction = createNetworkAction(connection); - - // Keep track of this action in the destination federate. - connection.dstFederate.networkMessageActions.add(networkAction); - - // Add the action definition to the parent reactor. - ((Reactor) connection.getDefinition().eContainer()).getActions().add(networkAction); - - // Add the network receiver reaction in the destinationFederate - addNetworkReceiverReaction( - networkAction, - connection, - coordination, - errorReporter - ); + // Add the network input control reaction to the parent + FedASTUtils.addNetworkInputControlReaction(connection, coordination, errorReporter); } - /** - * Create a "network action" in the reactor that contains the given - * connection and return it. - * - * The purpose of this action is to serve as a trigger for a "network - * input reaction" that is responsible for relaying messages to the - * port that is on the receiving side of the given connection. The - * connection is assumed to be between two reactors that reside in - * distinct federates. Hence, the container of the connection is - * assumed to be top-level. - * - * @param connection A connection between two federates - * @return The newly created action. - */ - private static Action createNetworkAction(FedConnectionInstance connection) { - Reactor top = (Reactor) connection.getDefinition().eContainer(); - LfFactory factory = LfFactory.eINSTANCE; - - Action action = factory.createAction(); - // Name the newly created action; set its delay and type. - action.setName(ASTUtils.getUniqueIdentifier(top, "networkMessage")); - if (connection.serializer == SupportedSerializers.NATIVE) { - action.setType(EcoreUtil.copy(connection.getSourcePortInstance().getDefinition().getType())); - } else { - Type action_type = factory.createType(); - action_type.setId( - FedTargetExtensionFactory.getExtension( - connection.srcFederate.targetConfig.target - ).getNetworkBufferType() - ); - action.setType(action_type); - } - - // The connection is 'physical' if it uses the ~> notation. - if (connection.getDefinition().isPhysical()) { - action.setOrigin(ActionOrigin.PHYSICAL); - // Messages sent on physical connections do not - // carry a timestamp, or a delay. The delay - // provided using after is enforced by setting - // the minDelay. - if (connection.getDefinition().getDelay() != null) { - action.setMinDelay(connection.getDefinition().getDelay()); - } - } else { - action.setOrigin(ActionOrigin.LOGICAL); - } + // Create the network action (@see createNetworkAction) + Action networkAction = createNetworkAction(connection); + + // Keep track of this action in the destination federate. + connection.dstFederate.networkMessageActions.add(networkAction); + + // Add the action definition to the parent reactor. + ((Reactor) connection.getDefinition().eContainer()).getActions().add(networkAction); + + // Add the network receiver reaction in the destinationFederate + addNetworkReceiverReaction(networkAction, connection, coordination, errorReporter); + } + + /** + * Create a "network action" in the reactor that contains the given connection and return it. + * + *

    The purpose of this action is to serve as a trigger for a "network input reaction" that is + * responsible for relaying messages to the port that is on the receiving side of the given + * connection. The connection is assumed to be between two reactors that reside in distinct + * federates. Hence, the container of the connection is assumed to be top-level. + * + * @param connection A connection between two federates + * @return The newly created action. + */ + private static Action createNetworkAction(FedConnectionInstance connection) { + Reactor top = (Reactor) connection.getDefinition().eContainer(); + LfFactory factory = LfFactory.eINSTANCE; + + Action action = factory.createAction(); + // Name the newly created action; set its delay and type. + action.setName(ASTUtils.getUniqueIdentifier(top, "networkMessage")); + if (connection.serializer == SupportedSerializers.NATIVE) { + action.setType(EcoreUtil.copy(connection.getSourcePortInstance().getDefinition().getType())); + } else { + Type action_type = factory.createType(); + action_type.setId( + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + .getNetworkBufferType()); + action.setType(action_type); + } - return action; + // The connection is 'physical' if it uses the ~> notation. + if (connection.getDefinition().isPhysical()) { + action.setOrigin(ActionOrigin.PHYSICAL); + // Messages sent on physical connections do not + // carry a timestamp, or a delay. The delay + // provided using after is enforced by setting + // the minDelay. + if (connection.getDefinition().getDelay() != null) { + action.setMinDelay(connection.getDefinition().getDelay()); + } + } else { + action.setOrigin(ActionOrigin.LOGICAL); } - /** - * Add a network receiver reaction for a given input port 'destination' to - * destination's parent reactor. This reaction will react to a generated - * 'networkAction' (triggered asynchronously, e.g., by federate.c). This - * 'networkAction' will contain the actual message that is sent by the - * sender - * in 'action->value'. This value is forwarded to 'destination' in the - * network - * receiver reaction. - * - * @param networkAction The network action (also, @see createNetworkAction) - * @param connection FIXME - * @param coordination One of CoordinationType.DECENTRALIZED or - * CoordinationType.CENTRALIZED. - * @note: Used in federated execution - */ - private static void addNetworkReceiverReaction( - Action networkAction, - FedConnectionInstance connection, - CoordinationType coordination, - ErrorReporter errorReporter - ) { - LfFactory factory = LfFactory.eINSTANCE; - VarRef sourceRef = factory.createVarRef(); - VarRef destRef = factory.createVarRef(); - Reactor parent = (Reactor) connection.getDefinition().eContainer(); - Reaction networkReceiverReaction = factory.createReaction(); - - // If the sender or receiver is in a bank of reactors, then we want - // these reactions to appear only in the federate whose bank ID matches. - setReactionBankIndex(networkReceiverReaction, connection.getDstBank()); - - // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) - .annotateReaction(networkReceiverReaction); - - // The connection is 'physical' if it uses the ~> notation. - if (connection.getDefinition().isPhysical()) { - connection.dstFederate.inboundP2PConnections.add(connection.srcFederate); - } else { - // If the connection is logical but coordination - // is decentralized, we would need - // to make P2P connections - if (coordination == CoordinationType.DECENTRALIZED) { - connection.dstFederate.inboundP2PConnections.add(connection.srcFederate); - } - } + return action; + } + + /** + * Add a network receiver reaction for a given input port 'destination' to destination's parent + * reactor. This reaction will react to a generated 'networkAction' (triggered asynchronously, + * e.g., by federate.c). This 'networkAction' will contain the actual message that is sent by the + * sender in 'action->value'. This value is forwarded to 'destination' in the network receiver + * reaction. + * + * @param networkAction The network action (also, @see createNetworkAction) + * @param connection FIXME + * @param coordination One of CoordinationType.DECENTRALIZED or CoordinationType.CENTRALIZED. + * @note: Used in federated execution + */ + private static void addNetworkReceiverReaction( + Action networkAction, + FedConnectionInstance connection, + CoordinationType coordination, + ErrorReporter errorReporter) { + LfFactory factory = LfFactory.eINSTANCE; + VarRef sourceRef = factory.createVarRef(); + VarRef destRef = factory.createVarRef(); + Reactor parent = (Reactor) connection.getDefinition().eContainer(); + Reaction networkReceiverReaction = factory.createReaction(); + + // If the sender or receiver is in a bank of reactors, then we want + // these reactions to appear only in the federate whose bank ID matches. + setReactionBankIndex(networkReceiverReaction, connection.getDstBank()); + + // FIXME: do not create a new extension every time it is used + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + .annotateReaction(networkReceiverReaction); + + // The connection is 'physical' if it uses the ~> notation. + if (connection.getDefinition().isPhysical()) { + connection.dstFederate.inboundP2PConnections.add(connection.srcFederate); + } else { + // If the connection is logical but coordination + // is decentralized, we would need + // to make P2P connections + if (coordination == CoordinationType.DECENTRALIZED) { + connection.dstFederate.inboundP2PConnections.add(connection.srcFederate); + } + } - // Establish references to the involved ports. - sourceRef.setContainer(connection.getSourcePortInstance().getParent().getDefinition()); - sourceRef.setVariable(connection.getSourcePortInstance().getDefinition()); - destRef.setContainer(connection.getDestinationPortInstance().getParent().getDefinition()); - destRef.setVariable(connection.getDestinationPortInstance().getDefinition()); - - // Add the input port at the receiver federate reactor as an effect - networkReceiverReaction.getEffects().add(destRef); - - VarRef triggerRef = factory.createVarRef(); - // Establish references to the action. - triggerRef.setVariable(networkAction); - // Add the action as a trigger to the receiver reaction - networkReceiverReaction.getTriggers().add(triggerRef); - - // Generate code for the network receiver reaction - networkReceiverReaction.setCode(factory.createCode()); - networkReceiverReaction.getCode().setBody( - FedTargetExtensionFactory.getExtension( - connection.dstFederate.targetConfig.target).generateNetworkReceiverBody( + // Establish references to the involved ports. + sourceRef.setContainer(connection.getSourcePortInstance().getParent().getDefinition()); + sourceRef.setVariable(connection.getSourcePortInstance().getDefinition()); + destRef.setContainer(connection.getDestinationPortInstance().getParent().getDefinition()); + destRef.setVariable(connection.getDestinationPortInstance().getDefinition()); + + // Add the input port at the receiver federate reactor as an effect + networkReceiverReaction.getEffects().add(destRef); + + VarRef triggerRef = factory.createVarRef(); + // Establish references to the action. + triggerRef.setVariable(networkAction); + // Add the action as a trigger to the receiver reaction + networkReceiverReaction.getTriggers().add(triggerRef); + + // Generate code for the network receiver reaction + networkReceiverReaction.setCode(factory.createCode()); + networkReceiverReaction + .getCode() + .setBody( + FedTargetExtensionFactory.getExtension(connection.dstFederate.targetConfig.target) + .generateNetworkReceiverBody( networkAction, sourceRef, destRef, connection, ASTUtils.getInferredType(networkAction), coordination, - errorReporter - )); - - - ASTUtils.addReactionAttribute(networkReceiverReaction, "_unordered"); - - // Add the receiver reaction to the parent - parent.getReactions().add(networkReceiverReaction); - - // Add the network receiver reaction to the federate instance's list - // of network reactions - connection.dstFederate.networkReactions.add(networkReceiverReaction); - - - if ( - !connection.getDefinition().isPhysical() && - // Connections that are physical don't need control reactions - connection.getDefinition().getDelay() - == null // Connections that have delays don't need control reactions - ) { - // Add necessary dependencies to reaction to ensure that it executes correctly - // relative to other network input control reactions in the federate. - addRelativeDependency(connection, networkReceiverReaction, errorReporter); - } - } + errorReporter)); - /** - * Add a network control reaction for a given input port 'destination' to - * destination's parent reactor. This reaction will block for - * any valid logical time until it is known whether the trigger for the - * action corresponding to the given port is present or absent. - * - * @param connection FIXME - * @param coordination FIXME - * @param errorReporter - * @note Used in federated execution - */ - private static void addNetworkInputControlReaction( - FedConnectionInstance connection, - CoordinationType coordination, - ErrorReporter errorReporter) { - - LfFactory factory = LfFactory.eINSTANCE; - Reaction reaction = factory.createReaction(); - VarRef destRef = factory.createVarRef(); - int receivingPortID = connection.dstFederate.networkMessageActions.size(); - - // If the sender or receiver is in a bank of reactors, then we want - // these reactions to appear only in the federate whose bank ID matches. - setReactionBankIndex(reaction, connection.getDstBank()); - - // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) - .annotateReaction(reaction); - - // Create a new action that will be used to trigger the - // input control reactions. - Action newTriggerForControlReactionInput = factory.createAction(); - newTriggerForControlReactionInput.setOrigin(ActionOrigin.LOGICAL); - - // Set the container and variable according to the network port - destRef.setContainer(connection.getDestinationPortInstance().getParent().getDefinition()); - destRef.setVariable(connection.getDestinationPortInstance().getDefinition()); - - Reactor top = connection.getDestinationPortInstance() - .getParent() - .getParent().reactorDefinition; - - newTriggerForControlReactionInput.setName( - ASTUtils.getUniqueIdentifier(top, "inputControlReactionTrigger")); - - // Add the newly created Action to the action list of the federated reactor. - top.getActions().add(newTriggerForControlReactionInput); - - // Create the trigger for the reaction - VarRef newTriggerForControlReaction = factory.createVarRef(); - newTriggerForControlReaction.setVariable(newTriggerForControlReactionInput); - - // Add the appropriate triggers to the list of triggers of the reaction - reaction.getTriggers().add(newTriggerForControlReaction); - - // Add the destination port as an effect of the reaction - reaction.getEffects().add(destRef); - - // Generate code for the network input control reaction - reaction.setCode(factory.createCode()); - - TimeValue maxSTP = findMaxSTP(connection, coordination); - - reaction.getCode() - .setBody( - FedTargetExtensionFactory - .getExtension(connection.dstFederate.targetConfig.target) - .generateNetworkInputControlReactionBody( - receivingPortID, - maxSTP, - coordination - ) - ); - - ASTUtils.addReactionAttribute(reaction, "_unordered"); - - // Insert the reaction - top.getReactions().add(reaction); - - // Add the trigger for this reaction to the list of triggers, used to actually - // trigger the reaction at the beginning of each logical time. - connection.dstFederate.networkInputControlReactionsTriggers.add(newTriggerForControlReactionInput); - - // Add the network input control reaction to the federate instance's list - // of network reactions - connection.dstFederate.networkReactions.add(reaction); - - // Add necessary dependencies to reaction to ensure that it executes correctly - // relative to other network input control reactions in the federate. - addRelativeDependency(connection, reaction, errorReporter); - } + ASTUtils.addReactionAttribute(networkReceiverReaction, "_unordered"); - /** - * Add necessary dependency information to the signature of {@code networkInputReaction} so that - * it can execute in the correct order relative to other network reactions in the federate. - * - * In particular, we want to avoid a deadlock if multiple network input control reactions in federate - * are in a zero-delay cycle through other federates in the federation. To avoid the deadlock, we encode the - * zero-delay cycle inside the federate by adding an artificial dependency from the output port of this federate - * that is involved in the cycle to the signature of {@code networkInputReaction} as a source. - */ - private static void addRelativeDependency( - FedConnectionInstance connection, - Reaction networkInputReaction, - ErrorReporter errorReporter) { - var upstreamOutputPortsInFederate = - findUpstreamPortsInFederate( - connection.dstFederate, - connection.getSourcePortInstance(), - new HashSet<>(), - new HashSet<>() - ); - - ModelInfo info = new ModelInfo(); - for (var port: upstreamOutputPortsInFederate) { - VarRef sourceRef = ASTUtils.factory.createVarRef(); - - sourceRef.setContainer(port.getParent().getDefinition()); - sourceRef.setVariable(port.getDefinition()); - networkInputReaction.getSources().add(sourceRef); - - // Remove the port if it introduces cycles - info.update( - (Model)networkInputReaction.eContainer().eContainer(), - errorReporter - ); - if (!info.topologyCycles().isEmpty()) { - networkInputReaction.getSources().remove(sourceRef); - } - } + // Add the receiver reaction to the parent + parent.getReactions().add(networkReceiverReaction); - } + // Add the network receiver reaction to the federate instance's list + // of network reactions + connection.dstFederate.networkReactions.add(networkReceiverReaction); - /** - * Go upstream from input port {@code port} until we reach one or more output - * ports that belong to the same federate. - * - * Along the path, we follow direct connections, as well as reactions, as long - * as there is no logical delay. When following reactions, we also follow - * dependant reactions (because we are traversing a potential cycle backwards). - * - * @return A set of {@link PortInstance}. If no port exist that match the - * criteria, return an empty set. - */ - private static Set findUpstreamPortsInFederate( - FederateInstance federate, - PortInstance port, - Set visitedPorts, - Set reactionVisited + if (!connection.getDefinition().isPhysical() + && + // Connections that are physical don't need control reactions + connection.getDefinition().getDelay() + == null // Connections that have delays don't need control reactions ) { - Set toReturn = new HashSet<>(); - if (port == null) return toReturn; - else if (federate.contains(port.getParent())) { - // Reached the requested federate - toReturn.add(port); - visitedPorts.add(port); - } else if (visitedPorts.contains(port)) { - return toReturn; - } else { - visitedPorts.add(port); - // Follow depends on reactions - port.getDependsOnReactions().forEach( - reaction -> { - followReactionUpstream(federate, visitedPorts, toReturn, reaction, reactionVisited); - } - ); - // Follow depends on ports - port.getDependsOnPorts().forEach( - it -> toReturn.addAll( - findUpstreamPortsInFederate(federate, it.instance, visitedPorts, reactionVisited) - ) - ); - } - return toReturn; + // Add necessary dependencies to reaction to ensure that it executes correctly + // relative to other network input control reactions in the federate. + addRelativeDependency(connection, networkReceiverReaction, errorReporter); } - - /** - * Follow reactions upstream. This is part of the algorithm of - * {@link #findUpstreamPortsInFederate(FederateInstance, PortInstance, Set)}. - */ - private static void followReactionUpstream( - FederateInstance federate, - Set visitedPorts, - Set toReturn, - ReactionInstance reaction, - Set reactionVisited - ) { - if (reactionVisited.contains(reaction)) return; - reactionVisited.add(reaction); - // Add triggers - Set varRefsToFollow = new HashSet<>(); - varRefsToFollow.addAll( - reaction.getDefinition() - .getTriggers() - .stream() - .filter( - trigger -> !(trigger instanceof BuiltinTriggerRef) - ) - .map(VarRef.class::cast).toList()); - // Add sources - varRefsToFollow.addAll(reaction.getDefinition().getSources()); - - // Follow everything upstream - varRefsToFollow.forEach( - varRef -> - toReturn.addAll( - findUpstreamPortsInFederate( - federate, - reaction.getParent() - .lookupPortInstance(varRef), - visitedPorts, - reactionVisited - ) - ) - ); - - reaction.dependsOnReactions() - .stream() - .filter( - // Stay within the reactor - it -> it.getParent().equals(reaction.getParent()) - ) - .forEach( - it -> followReactionUpstream(federate, visitedPorts, toReturn, it, reactionVisited) - ); - - // FIXME: This is most certainly wrong. Please fix it. - reaction.dependentReactions() - .stream() - .filter( - // Stay within the reactor - it -> it.getParent().equals(reaction.getParent()) - ) - .forEach( - it -> followReactionUpstream(federate, visitedPorts, toReturn, it, reactionVisited) - ); + } + + /** + * Add a network control reaction for a given input port 'destination' to destination's parent + * reactor. This reaction will block for any valid logical time until it is known whether the + * trigger for the action corresponding to the given port is present or absent. + * + * @param connection FIXME + * @param coordination FIXME + * @param errorReporter + * @note Used in federated execution + */ + private static void addNetworkInputControlReaction( + FedConnectionInstance connection, + CoordinationType coordination, + ErrorReporter errorReporter) { + + LfFactory factory = LfFactory.eINSTANCE; + Reaction reaction = factory.createReaction(); + VarRef destRef = factory.createVarRef(); + int receivingPortID = connection.dstFederate.networkMessageActions.size(); + + // If the sender or receiver is in a bank of reactors, then we want + // these reactions to appear only in the federate whose bank ID matches. + setReactionBankIndex(reaction, connection.getDstBank()); + + // FIXME: do not create a new extension every time it is used + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + .annotateReaction(reaction); + + // Create a new action that will be used to trigger the + // input control reactions. + Action newTriggerForControlReactionInput = factory.createAction(); + newTriggerForControlReactionInput.setOrigin(ActionOrigin.LOGICAL); + + // Set the container and variable according to the network port + destRef.setContainer(connection.getDestinationPortInstance().getParent().getDefinition()); + destRef.setVariable(connection.getDestinationPortInstance().getDefinition()); + + Reactor top = connection.getDestinationPortInstance().getParent().getParent().reactorDefinition; + + newTriggerForControlReactionInput.setName( + ASTUtils.getUniqueIdentifier(top, "inputControlReactionTrigger")); + + // Add the newly created Action to the action list of the federated reactor. + top.getActions().add(newTriggerForControlReactionInput); + + // Create the trigger for the reaction + VarRef newTriggerForControlReaction = factory.createVarRef(); + newTriggerForControlReaction.setVariable(newTriggerForControlReactionInput); + + // Add the appropriate triggers to the list of triggers of the reaction + reaction.getTriggers().add(newTriggerForControlReaction); + + // Add the destination port as an effect of the reaction + reaction.getEffects().add(destRef); + + // Generate code for the network input control reaction + reaction.setCode(factory.createCode()); + + TimeValue maxSTP = findMaxSTP(connection, coordination); + + reaction + .getCode() + .setBody( + FedTargetExtensionFactory.getExtension(connection.dstFederate.targetConfig.target) + .generateNetworkInputControlReactionBody(receivingPortID, maxSTP, coordination)); + + ASTUtils.addReactionAttribute(reaction, "_unordered"); + + // Insert the reaction + top.getReactions().add(reaction); + + // Add the trigger for this reaction to the list of triggers, used to actually + // trigger the reaction at the beginning of each logical time. + connection.dstFederate.networkInputControlReactionsTriggers.add( + newTriggerForControlReactionInput); + + // Add the network input control reaction to the federate instance's list + // of network reactions + connection.dstFederate.networkReactions.add(reaction); + + // Add necessary dependencies to reaction to ensure that it executes correctly + // relative to other network input control reactions in the federate. + addRelativeDependency(connection, reaction, errorReporter); + } + + /** + * Add necessary dependency information to the signature of {@code networkInputReaction} so that + * it can execute in the correct order relative to other network reactions in the federate. + * + *

    In particular, we want to avoid a deadlock if multiple network input control reactions in + * federate are in a zero-delay cycle through other federates in the federation. To avoid the + * deadlock, we encode the zero-delay cycle inside the federate by adding an artificial dependency + * from the output port of this federate that is involved in the cycle to the signature of {@code + * networkInputReaction} as a source. + */ + private static void addRelativeDependency( + FedConnectionInstance connection, + Reaction networkInputReaction, + ErrorReporter errorReporter) { + var upstreamOutputPortsInFederate = + findUpstreamPortsInFederate( + connection.dstFederate, + connection.getSourcePortInstance(), + new HashSet<>(), + new HashSet<>()); + + ModelInfo info = new ModelInfo(); + for (var port : upstreamOutputPortsInFederate) { + VarRef sourceRef = ASTUtils.factory.createVarRef(); + + sourceRef.setContainer(port.getParent().getDefinition()); + sourceRef.setVariable(port.getDefinition()); + networkInputReaction.getSources().add(sourceRef); + + // Remove the port if it introduces cycles + info.update((Model) networkInputReaction.eContainer().eContainer(), errorReporter); + if (!info.topologyCycles().isEmpty()) { + networkInputReaction.getSources().remove(sourceRef); + } } - - /** - * Find the maximum STP offset for the given 'port'. - * - * An STP offset predicate can be nested in contained reactors in - * the federate. - * - * @param connection The connection to find the max STP offset for. - * @param coordination The coordination scheme. - * @return The maximum STP as a TimeValue - */ - private static TimeValue findMaxSTP(FedConnectionInstance connection, - CoordinationType coordination) { - Variable port = connection.getDestinationPortInstance().getDefinition(); - FederateInstance instance = connection.dstFederate; - Reactor reactor = connection.getDestinationPortInstance().getParent().reactorDefinition; - - // Find a list of STP offsets (if any exists) - List STPList = new LinkedList<>(); - - // First, check if there are any connections to contained reactors that - // need to be handled - List connectionsWithPort = ASTUtils - .allConnections(reactor).stream().filter(c -> c.getLeftPorts() - .stream() - .anyMatch((VarRef v) -> v - .getVariable().equals(port))) + } + + /** + * Go upstream from input port {@code port} until we reach one or more output ports that belong to + * the same federate. + * + *

    Along the path, we follow direct connections, as well as reactions, as long as there is no + * logical delay. When following reactions, we also follow dependant reactions (because we are + * traversing a potential cycle backwards). + * + * @return A set of {@link PortInstance}. If no port exist that match the criteria, return an + * empty set. + */ + private static Set findUpstreamPortsInFederate( + FederateInstance federate, + PortInstance port, + Set visitedPorts, + Set reactionVisited) { + Set toReturn = new HashSet<>(); + if (port == null) return toReturn; + else if (federate.contains(port.getParent())) { + // Reached the requested federate + toReturn.add(port); + visitedPorts.add(port); + } else if (visitedPorts.contains(port)) { + return toReturn; + } else { + visitedPorts.add(port); + // Follow depends on reactions + port.getDependsOnReactions() + .forEach( + reaction -> { + followReactionUpstream(federate, visitedPorts, toReturn, reaction, reactionVisited); + }); + // Follow depends on ports + port.getDependsOnPorts() + .forEach( + it -> + toReturn.addAll( + findUpstreamPortsInFederate( + federate, it.instance, visitedPorts, reactionVisited))); + } + return toReturn; + } + + /** + * Follow reactions upstream. This is part of the algorithm of {@link + * #findUpstreamPortsInFederate(FederateInstance, PortInstance, Set)}. + */ + private static void followReactionUpstream( + FederateInstance federate, + Set visitedPorts, + Set toReturn, + ReactionInstance reaction, + Set reactionVisited) { + if (reactionVisited.contains(reaction)) return; + reactionVisited.add(reaction); + // Add triggers + Set varRefsToFollow = new HashSet<>(); + varRefsToFollow.addAll( + reaction.getDefinition().getTriggers().stream() + .filter(trigger -> !(trigger instanceof BuiltinTriggerRef)) + .map(VarRef.class::cast) + .toList()); + // Add sources + varRefsToFollow.addAll(reaction.getDefinition().getSources()); + + // Follow everything upstream + varRefsToFollow.forEach( + varRef -> + toReturn.addAll( + findUpstreamPortsInFederate( + federate, + reaction.getParent().lookupPortInstance(varRef), + visitedPorts, + reactionVisited))); + + reaction.dependsOnReactions().stream() + .filter( + // Stay within the reactor + it -> it.getParent().equals(reaction.getParent())) + .forEach( + it -> followReactionUpstream(federate, visitedPorts, toReturn, it, reactionVisited)); + + // FIXME: This is most certainly wrong. Please fix it. + reaction.dependentReactions().stream() + .filter( + // Stay within the reactor + it -> it.getParent().equals(reaction.getParent())) + .forEach( + it -> followReactionUpstream(federate, visitedPorts, toReturn, it, reactionVisited)); + } + + /** + * Find the maximum STP offset for the given 'port'. + * + *

    An STP offset predicate can be nested in contained reactors in the federate. + * + * @param connection The connection to find the max STP offset for. + * @param coordination The coordination scheme. + * @return The maximum STP as a TimeValue + */ + private static TimeValue findMaxSTP( + FedConnectionInstance connection, CoordinationType coordination) { + Variable port = connection.getDestinationPortInstance().getDefinition(); + FederateInstance instance = connection.dstFederate; + Reactor reactor = connection.getDestinationPortInstance().getParent().reactorDefinition; + + // Find a list of STP offsets (if any exists) + List STPList = new LinkedList<>(); + + // First, check if there are any connections to contained reactors that + // need to be handled + List connectionsWithPort = + ASTUtils.allConnections(reactor).stream() + .filter( + c -> c.getLeftPorts().stream().anyMatch((VarRef v) -> v.getVariable().equals(port))) .collect(Collectors.toList()); + // Find the list of reactions that have the port as trigger or source + // (could be a variable name) + List reactionsWithPort = + ASTUtils.allReactions(reactor).stream() + .filter( + r -> { + // Check the triggers of reaction r first + return r.getTriggers().stream() + .anyMatch( + t -> { + if (t instanceof VarRef) { + // Check if the variables match + return ((VarRef) t).getVariable() == port; + } else { + // Not a network port (startup or shutdown) + return false; + } + }) + || // Then check the sources of reaction r + r.getSources().stream().anyMatch(s -> s.getVariable() == port); + }) + .collect(Collectors.toList()); - // Find the list of reactions that have the port as trigger or source - // (could be a variable name) - List reactionsWithPort = ASTUtils - .allReactions(reactor).stream().filter(r -> { - // Check the triggers of reaction r first - return r.getTriggers().stream().anyMatch(t -> { - if (t instanceof VarRef) { - // Check if the variables match - return ((VarRef) t).getVariable() == port; - } else { - // Not a network port (startup or shutdown) - return false; - } - }) || // Then check the sources of reaction r - r.getSources().stream().anyMatch(s -> s.getVariable() - == port); - }).collect(Collectors.toList()); - - // Find a list of STP offsets (if any exists) - if (coordination == CoordinationType.DECENTRALIZED) { - for (Reaction r : safe(reactionsWithPort)) { - // If STP offset is determined, add it - // If not, assume it is zero - if (r.getStp() != null) { - if (r.getStp().getValue() instanceof ParameterReference) { - List instantList = new ArrayList<>(); - instantList.add(instance.instantiation); - final var param = ((ParameterReference) r.getStp().getValue()).getParameter(); - STPList.addAll(ASTUtils.initialValue(param, instantList)); - } else { - STPList.add(r.getStp().getValue()); - } - } - } - // Check the children for STPs as well - for (Connection c : safe(connectionsWithPort)) { - VarRef childPort = c.getRightPorts().get(0); - Reactor childReactor = (Reactor) childPort.getVariable() - .eContainer(); - // Find the list of reactions that have the port as trigger or - // source (could be a variable name) - List childReactionsWithPort = - ASTUtils.allReactions(childReactor) - .stream() - .filter(r -> - r.getTriggers().stream().anyMatch(t -> { - if (t instanceof VarRef) { - // Check if the variables match - return - ((VarRef) t).getVariable() - == childPort.getVariable(); - } else { - // Not a network port (startup or shutdown) - return false; - } - }) || - r.getSources() - .stream() - .anyMatch(s -> - s.getVariable() - == childPort.getVariable()) - ).collect(Collectors.toList()); - - for (Reaction r : safe(childReactionsWithPort)) { - // If STP offset is determined, add it - // If not, assume it is zero - if (r.getStp() != null) { - if (r.getStp().getValue() instanceof ParameterReference) { - List instantList = new ArrayList<>(); - instantList.add(childPort.getContainer()); - final var param = ((ParameterReference) r.getStp().getValue()).getParameter(); - STPList.addAll(ASTUtils.initialValue(param, instantList)); - } else { - STPList.add(r.getStp().getValue()); - } - } - } + // Find a list of STP offsets (if any exists) + if (coordination == CoordinationType.DECENTRALIZED) { + for (Reaction r : safe(reactionsWithPort)) { + // If STP offset is determined, add it + // If not, assume it is zero + if (r.getStp() != null) { + if (r.getStp().getValue() instanceof ParameterReference) { + List instantList = new ArrayList<>(); + instantList.add(instance.instantiation); + final var param = ((ParameterReference) r.getStp().getValue()).getParameter(); + STPList.addAll(ASTUtils.initialValue(param, instantList)); + } else { + STPList.add(r.getStp().getValue()); + } + } + } + // Check the children for STPs as well + for (Connection c : safe(connectionsWithPort)) { + VarRef childPort = c.getRightPorts().get(0); + Reactor childReactor = (Reactor) childPort.getVariable().eContainer(); + // Find the list of reactions that have the port as trigger or + // source (could be a variable name) + List childReactionsWithPort = + ASTUtils.allReactions(childReactor).stream() + .filter( + r -> + r.getTriggers().stream() + .anyMatch( + t -> { + if (t instanceof VarRef) { + // Check if the variables match + return ((VarRef) t).getVariable() + == childPort.getVariable(); + } else { + // Not a network port (startup or shutdown) + return false; + } + }) + || r.getSources().stream() + .anyMatch(s -> s.getVariable() == childPort.getVariable())) + .collect(Collectors.toList()); + + for (Reaction r : safe(childReactionsWithPort)) { + // If STP offset is determined, add it + // If not, assume it is zero + if (r.getStp() != null) { + if (r.getStp().getValue() instanceof ParameterReference) { + List instantList = new ArrayList<>(); + instantList.add(childPort.getContainer()); + final var param = ((ParameterReference) r.getStp().getValue()).getParameter(); + STPList.addAll(ASTUtils.initialValue(param, instantList)); + } else { + STPList.add(r.getStp().getValue()); } + } } - - return STPList.stream() - .map(ASTUtils::getLiteralTimeValue) - .filter(Objects::nonNull) - .reduce(TimeValue.ZERO, TimeValue::max); + } } - /** - * Return a null-safe List - * - * @param The type of the list - * @param list The potentially null List - * @return Empty list or the original list - */ - public static List safe(List list) { - return list == null ? Collections.emptyList() : list; + return STPList.stream() + .map(ASTUtils::getLiteralTimeValue) + .filter(Objects::nonNull) + .reduce(TimeValue.ZERO, TimeValue::max); + } + + /** + * Return a null-safe List + * + * @param The type of the list + * @param list The potentially null List + * @return Empty list or the original list + */ + public static List safe(List list) { + return list == null ? Collections.emptyList() : list; + } + + /** + * Add a network sender reaction for a given input port 'source' to source's parent reactor. This + * reaction will react to the 'source' and then send a message on the network destined for the + * destinationFederate. + * + * @param connection Network connection between two federates. + * @param coordination One of CoordinationType.DECENTRALIZED or CoordinationType.CENTRALIZED. + * @param errorReporter FIXME + * @note Used in federated execution + */ + private static void addNetworkSenderReaction( + FedConnectionInstance connection, + CoordinationType coordination, + ErrorReporter errorReporter) { + LfFactory factory = LfFactory.eINSTANCE; + // Assume all the types are the same, so just use the first on the right. + Type type = EcoreUtil.copy(connection.getSourcePortInstance().getDefinition().getType()); + VarRef sourceRef = factory.createVarRef(); + VarRef destRef = factory.createVarRef(); + Reactor parent = (Reactor) connection.getDefinition().eContainer(); + Reaction networkSenderReaction = factory.createReaction(); + + // FIXME: do not create a new extension every time it is used + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + .annotateReaction(networkSenderReaction); + + // If the sender or receiver is in a bank of reactors, then we want + // these reactions to appear only in the federate whose bank ID matches. + setReactionBankIndex(networkSenderReaction, connection.getSrcBank()); + + // The connection is 'physical' if it uses the ~> notation. + if (connection.getDefinition().isPhysical()) { + connection.srcFederate.outboundP2PConnections.add(connection.dstFederate); + } else { + // If the connection is logical but coordination + // is decentralized, we would need + // to make P2P connections + if (coordination == CoordinationType.DECENTRALIZED) { + connection.srcFederate.outboundP2PConnections.add(connection.dstFederate); + } } - /** - * Add a network sender reaction for a given input port 'source' to - * source's parent reactor. This reaction will react to the 'source' - * and then send a message on the network destined for the - * destinationFederate. - * - * @param connection Network connection between two federates. - * @param coordination One of CoordinationType.DECENTRALIZED or - * CoordinationType.CENTRALIZED. - * @param errorReporter FIXME - * @note Used in federated execution - */ - private static void addNetworkSenderReaction( - FedConnectionInstance connection, - CoordinationType coordination, - ErrorReporter errorReporter - ) { - LfFactory factory = LfFactory.eINSTANCE; - // Assume all the types are the same, so just use the first on the right. - Type type = EcoreUtil.copy(connection.getSourcePortInstance().getDefinition().getType()); - VarRef sourceRef = factory.createVarRef(); - VarRef destRef = factory.createVarRef(); - Reactor parent = (Reactor) connection.getDefinition().eContainer(); - Reaction networkSenderReaction = factory.createReaction(); - - // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) - .annotateReaction(networkSenderReaction); - - // If the sender or receiver is in a bank of reactors, then we want - // these reactions to appear only in the federate whose bank ID matches. - setReactionBankIndex(networkSenderReaction, connection.getSrcBank()); - - // The connection is 'physical' if it uses the ~> notation. - if (connection.getDefinition().isPhysical()) { - connection.srcFederate.outboundP2PConnections.add(connection.dstFederate); - } else { - // If the connection is logical but coordination - // is decentralized, we would need - // to make P2P connections - if (coordination == CoordinationType.DECENTRALIZED) { - connection.srcFederate.outboundP2PConnections.add(connection.dstFederate); - } - } - - // Establish references to the involved ports. - sourceRef.setContainer(connection.getSourcePortInstance().getParent().getDefinition()); - sourceRef.setVariable(connection.getSourcePortInstance().getDefinition()); - destRef.setContainer(connection.getDestinationPortInstance().getParent().getDefinition()); - destRef.setVariable(connection.getDestinationPortInstance().getDefinition()); - - // Configure the sending reaction. - networkSenderReaction.getTriggers().add(sourceRef); - networkSenderReaction.setCode(factory.createCode()); - networkSenderReaction.getCode().setBody( + // Establish references to the involved ports. + sourceRef.setContainer(connection.getSourcePortInstance().getParent().getDefinition()); + sourceRef.setVariable(connection.getSourcePortInstance().getDefinition()); + destRef.setContainer(connection.getDestinationPortInstance().getParent().getDefinition()); + destRef.setVariable(connection.getDestinationPortInstance().getDefinition()); + + // Configure the sending reaction. + networkSenderReaction.getTriggers().add(sourceRef); + networkSenderReaction.setCode(factory.createCode()); + networkSenderReaction + .getCode() + .setBody( FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) - .generateNetworkSenderBody( - sourceRef, - destRef, - connection, - InferredType.fromAST(type), - coordination, - errorReporter - )); - - ASTUtils.addReactionAttribute(networkSenderReaction, "_unordered"); - - // Add the sending reaction to the parent. - parent.getReactions().add(networkSenderReaction); - - // Add the network sender reaction to the federate instance's list - // of network reactions - connection.srcFederate.networkReactions.add(networkSenderReaction); + .generateNetworkSenderBody( + sourceRef, + destRef, + connection, + InferredType.fromAST(type), + coordination, + errorReporter)); + + ASTUtils.addReactionAttribute(networkSenderReaction, "_unordered"); + + // Add the sending reaction to the parent. + parent.getReactions().add(networkSenderReaction); + + // Add the network sender reaction to the federate instance's list + // of network reactions + connection.srcFederate.networkReactions.add(networkSenderReaction); + } + + /** + * Add a network control reaction for a given output port 'source' to source's parent reactor. + * This reaction will send a port absent message if the status of the output port is absent. + * + * @param connection FIXME + * @note Used in federated execution + */ + private static void addNetworkOutputControlReaction(FedConnectionInstance connection) { + LfFactory factory = LfFactory.eINSTANCE; + Reaction reaction = factory.createReaction(); + Reactor top = + connection + .getSourcePortInstance() + .getParent() + .getParent() + .reactorDefinition; // Top-level reactor. + + // Add the output from the contained reactor as a source to + // the reaction to preserve precedence order. + VarRef newPortRef = factory.createVarRef(); + newPortRef.setContainer(connection.getSourcePortInstance().getParent().getDefinition()); + newPortRef.setVariable(connection.getSourcePortInstance().getDefinition()); + reaction.getSources().add(newPortRef); + + // If the sender or receiver is in a bank of reactors, then we want + // these reactions to appear only in the federate whose bank ID matches. + setReactionBankIndex(reaction, connection.getSrcBank()); + + // FIXME: do not create a new extension every time it is used + FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + .annotateReaction(reaction); + + // We use an action at the top-level to manually + // trigger output control reactions. That action is created once + // and recorded in the federate instance. + // Check whether the action already has been created. + if (connection.srcFederate.networkOutputControlReactionsTrigger == null) { + // The port has not been created. + String triggerName = "outputControlReactionTrigger"; + + // Find the trigger definition in the reactor definition, which could have been + // generated for another federate instance if there are multiple instances + // of the same reactor that are each distinct federates. + Optional optTriggerInput = + top.getActions().stream().filter(I -> I.getName().equals(triggerName)).findFirst(); + + if (optTriggerInput.isEmpty()) { + // If no trigger with the name "outputControlReactionTrigger" is + // already added to the reactor definition, we need to create it + // for the first time. The trigger is a logical action. + Action newTriggerForControlReactionVariable = factory.createAction(); + newTriggerForControlReactionVariable.setName(triggerName); + newTriggerForControlReactionVariable.setOrigin(ActionOrigin.LOGICAL); + top.getActions().add(newTriggerForControlReactionVariable); + + // Now that the variable is created, store it in the federate instance + connection.srcFederate.networkOutputControlReactionsTrigger = + newTriggerForControlReactionVariable; + } else { + // If the "outputControlReactionTrigger" trigger is already + // there, we can re-use it for this new reaction since a single trigger + // will trigger + // all network output control reactions. + connection.srcFederate.networkOutputControlReactionsTrigger = optTriggerInput.get(); + } } - /** - * Add a network control reaction for a given output port 'source' to - * source's parent reactor. This reaction will send a port absent - * message if the status of the output port is absent. - * - * @param connection FIXME - * @note Used in federated execution - */ - private static void addNetworkOutputControlReaction(FedConnectionInstance connection) { - LfFactory factory = LfFactory.eINSTANCE; - Reaction reaction = factory.createReaction(); - Reactor top = connection.getSourcePortInstance() - .getParent() - .getParent().reactorDefinition; // Top-level reactor. - - // Add the output from the contained reactor as a source to - // the reaction to preserve precedence order. - VarRef newPortRef = factory.createVarRef(); - newPortRef.setContainer(connection.getSourcePortInstance().getParent().getDefinition()); - newPortRef.setVariable(connection.getSourcePortInstance().getDefinition()); - reaction.getSources().add(newPortRef); - - // If the sender or receiver is in a bank of reactors, then we want - // these reactions to appear only in the federate whose bank ID matches. - setReactionBankIndex(reaction, connection.getSrcBank()); - - // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) - .annotateReaction(reaction); - - // We use an action at the top-level to manually - // trigger output control reactions. That action is created once - // and recorded in the federate instance. - // Check whether the action already has been created. - if (connection.srcFederate.networkOutputControlReactionsTrigger == null) { - // The port has not been created. - String triggerName = "outputControlReactionTrigger"; - - // Find the trigger definition in the reactor definition, which could have been - // generated for another federate instance if there are multiple instances - // of the same reactor that are each distinct federates. - Optional optTriggerInput - = top.getActions().stream().filter( - I -> I.getName().equals(triggerName)).findFirst(); - - if (optTriggerInput.isEmpty()) { - // If no trigger with the name "outputControlReactionTrigger" is - // already added to the reactor definition, we need to create it - // for the first time. The trigger is a logical action. - Action newTriggerForControlReactionVariable = factory.createAction(); - newTriggerForControlReactionVariable.setName(triggerName); - newTriggerForControlReactionVariable.setOrigin(ActionOrigin.LOGICAL); - top.getActions().add(newTriggerForControlReactionVariable); - - // Now that the variable is created, store it in the federate instance - connection.srcFederate.networkOutputControlReactionsTrigger - = newTriggerForControlReactionVariable; - } else { - // If the "outputControlReactionTrigger" trigger is already - // there, we can re-use it for this new reaction since a single trigger - // will trigger - // all network output control reactions. - connection.srcFederate.networkOutputControlReactionsTrigger = optTriggerInput.get(); - } - } - - // Add the trigger for all output control reactions to the list of triggers - VarRef triggerRef = factory.createVarRef(); - triggerRef.setVariable(connection.srcFederate.networkOutputControlReactionsTrigger); - reaction.getTriggers().add(triggerRef); + // Add the trigger for all output control reactions to the list of triggers + VarRef triggerRef = factory.createVarRef(); + triggerRef.setVariable(connection.srcFederate.networkOutputControlReactionsTrigger); + reaction.getTriggers().add(triggerRef); - // Generate the code - reaction.setCode(factory.createCode()); + // Generate the code + reaction.setCode(factory.createCode()); - reaction.getCode().setBody( + reaction + .getCode() + .setBody( FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) - .generateNetworkOutputControlReactionBody(newPortRef, connection)); + .generateNetworkOutputControlReactionBody(newPortRef, connection)); - ASTUtils.addReactionAttribute(reaction, "_unordered"); + ASTUtils.addReactionAttribute(reaction, "_unordered"); + // Insert the newly generated reaction after the generated sender and + // receiver top-level reactions. + top.getReactions().add(reaction); - // Insert the newly generated reaction after the generated sender and - // receiver top-level reactions. - top.getReactions().add(reaction); - - // Add the network output control reaction to the federate instance's list - // of network reactions - connection.srcFederate.networkReactions.add(reaction); - } + // Add the network output control reaction to the federate instance's list + // of network reactions + connection.srcFederate.networkReactions.add(reaction); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedConnectionInstance.java b/org.lflang/src/org/lflang/federated/generator/FedConnectionInstance.java index a82e1d2dfa..d08aa5f850 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedConnectionInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FedConnectionInstance.java @@ -9,102 +9,100 @@ /** * Class representing a federated connection. * - * This is an undocumented class written by a previous contributor who is no longer active. - * It merely serves as a record, presumably to make it easier to pass around information - * around. + *

    This is an undocumented class written by a previous contributor who is no longer active. It + * merely serves as a record, presumably to make it easier to pass around information around. * * @author Soroush Bateni */ public class FedConnectionInstance { - SendRange srcRange; + SendRange srcRange; - RuntimeRange dstRange; + RuntimeRange dstRange; - int srcChannel; + int srcChannel; - int srcBank; + int srcBank; - int dstChannel; + int dstChannel; - int dstBank; + int dstBank; - FederateInstance srcFederate; + FederateInstance srcFederate; - FederateInstance dstFederate; + FederateInstance dstFederate; - SupportedSerializers serializer; + SupportedSerializers serializer; - public FedConnectionInstance( - SendRange srcRange, - RuntimeRange dstRange, - int srcChannel, - int srcBank, - int dstChannel, - int dstBank, - FederateInstance srcFederate, - FederateInstance dstFederate, - SupportedSerializers serializer - ) { - this.srcRange = srcRange; - this.srcChannel = srcChannel; - this.srcBank = srcBank; - this.dstChannel = dstChannel; - this.dstBank = dstBank; - this.srcFederate = srcFederate; - this.dstFederate = dstFederate; - this.dstRange = dstRange; - this.serializer = serializer; + public FedConnectionInstance( + SendRange srcRange, + RuntimeRange dstRange, + int srcChannel, + int srcBank, + int dstChannel, + int dstBank, + FederateInstance srcFederate, + FederateInstance dstFederate, + SupportedSerializers serializer) { + this.srcRange = srcRange; + this.srcChannel = srcChannel; + this.srcBank = srcBank; + this.dstChannel = dstChannel; + this.dstBank = dstBank; + this.srcFederate = srcFederate; + this.dstFederate = dstFederate; + this.dstRange = dstRange; + this.serializer = serializer; - this.srcFederate.connections.add(this); - this.dstFederate.connections.add(this); - } + this.srcFederate.connections.add(this); + this.dstFederate.connections.add(this); + } - public SendRange getSrcRange() { - return srcRange; - } + public SendRange getSrcRange() { + return srcRange; + } - public RuntimeRange getDstRange() { - return dstRange; - } + public RuntimeRange getDstRange() { + return dstRange; + } - public int getSrcChannel() { - return srcChannel; - } + public int getSrcChannel() { + return srcChannel; + } - public int getSrcBank() { - return srcBank; - } + public int getSrcBank() { + return srcBank; + } - public int getDstChannel() { - return dstChannel; - } + public int getDstChannel() { + return dstChannel; + } - public int getDstBank() { - return dstBank; - } + public int getDstBank() { + return dstBank; + } - public FederateInstance getSrcFederate() { - return srcFederate; - } + public FederateInstance getSrcFederate() { + return srcFederate; + } - public FederateInstance getDstFederate() { - return dstFederate; - } + public FederateInstance getDstFederate() { + return dstFederate; + } - public SupportedSerializers getSerializer() { - return serializer; - } + public SupportedSerializers getSerializer() { + return serializer; + } - public Connection getDefinition() { - return srcRange.connection; - } + public Connection getDefinition() { + return srcRange.connection; + } - public PortInstance getSourcePortInstance() { - return srcRange.instance; - } + public PortInstance getSourcePortInstance() { + return srcRange.instance; + } - public PortInstance getDestinationPortInstance() { - return dstRange.instance; - } + public PortInstance getDestinationPortInstance() { + return dstRange.instance; + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java index 2c9f32aad8..bdf912d0c8 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java @@ -4,76 +4,70 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; - import org.lflang.ErrorReporter; import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeMap; import org.lflang.generator.LFGeneratorContext; import org.lflang.lf.Reactor; -/** - * Helper class to generate code for federates. - */ +/** Helper class to generate code for federates. */ public class FedEmitter { - private final FedFileConfig fileConfig; - private final Reactor originalMainReactor; - private final ErrorReporter errorReporter; - private final RtiConfig rtiConfig; + private final FedFileConfig fileConfig; + private final Reactor originalMainReactor; + private final ErrorReporter errorReporter; + private final RtiConfig rtiConfig; - public FedEmitter( - FedFileConfig fileConfig, - Reactor originalMainReactor, - ErrorReporter errorReporter, - RtiConfig rtiConfig - ) { - this.fileConfig = fileConfig; - this.originalMainReactor = originalMainReactor; - this.errorReporter = errorReporter; - this.rtiConfig = rtiConfig; - } + public FedEmitter( + FedFileConfig fileConfig, + Reactor originalMainReactor, + ErrorReporter errorReporter, + RtiConfig rtiConfig) { + this.fileConfig = fileConfig; + this.originalMainReactor = originalMainReactor; + this.errorReporter = errorReporter; + this.rtiConfig = rtiConfig; + } - /** - * Generate a .lf file for federate {@code federate}. - * - * @throws IOException - */ - Map generateFederate( - LFGeneratorContext context, - FederateInstance federate, - int numOfFederates - ) throws IOException { - String fedName = federate.name; - Files.createDirectories(fileConfig.getSrcPath()); - System.out.println("##### Generating code for federate " + fedName - + " in directory " - + fileConfig.getSrcPath()); + /** + * Generate a .lf file for federate {@code federate}. + * + * @throws IOException + */ + Map generateFederate( + LFGeneratorContext context, FederateInstance federate, int numOfFederates) + throws IOException { + String fedName = federate.name; + Files.createDirectories(fileConfig.getSrcPath()); + System.out.println( + "##### Generating code for federate " + + fedName + + " in directory " + + fileConfig.getSrcPath()); - String federateCode = String.join( + String federateCode = + String.join( "\n", - new FedTargetEmitter().generateTarget(context, numOfFederates, federate, fileConfig, errorReporter, rtiConfig), + new FedTargetEmitter() + .generateTarget( + context, numOfFederates, federate, fileConfig, errorReporter, rtiConfig), new FedImportEmitter().generateImports(federate, fileConfig), - new FedPreambleEmitter().generatePreamble(federate, fileConfig, rtiConfig, errorReporter), + new FedPreambleEmitter() + .generatePreamble(federate, fileConfig, rtiConfig, errorReporter), new FedReactorEmitter().generateReactorDefinitions(federate), - new FedMainEmitter().generateMainReactor( - federate, - originalMainReactor, - errorReporter - ) - ); - Map codeMapMap = new HashMap<>(); - var lfFilePath = lfFilePath(fileConfig, federate); - try (var srcWriter = Files.newBufferedWriter(lfFilePath)) { - var codeMap = CodeMap.fromGeneratedCode(federateCode); - codeMapMap.put(lfFilePath, codeMap); - srcWriter.write(codeMap.getGeneratedCode()); - } - return codeMapMap; + new FedMainEmitter().generateMainReactor(federate, originalMainReactor, errorReporter)); + Map codeMapMap = new HashMap<>(); + var lfFilePath = lfFilePath(fileConfig, federate); + try (var srcWriter = Files.newBufferedWriter(lfFilePath)) { + var codeMap = CodeMap.fromGeneratedCode(federateCode); + codeMapMap.put(lfFilePath, codeMap); + srcWriter.write(codeMap.getGeneratedCode()); } + return codeMapMap; + } - public static Path lfFilePath(FedFileConfig fileConfig, FederateInstance federate) { - return fileConfig.getSrcPath().resolve(federate.name + ".lf"); - } + public static Path lfFilePath(FedFileConfig fileConfig, FederateInstance federate) { + return fileConfig.getSrcPath().resolve(federate.name + ".lf"); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index e434501825..cb12c90a7d 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2019-2021, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -30,113 +30,105 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; - import org.eclipse.emf.ecore.resource.Resource; - import org.lflang.FileConfig; import org.lflang.util.FileUtil; /** - * A subclass of @see FileConfig that extends the base functionality to add support - * for compiling federated LF programs. The code generator should create one instance - * of this class for each federate. + * A subclass of @see FileConfig that extends the base functionality to add support for compiling + * federated LF programs. The code generator should create one instance of this class for each + * federate. * * @author Soroush Bateni - * */ public class FedFileConfig extends FileConfig { - public FedFileConfig( - Resource resource, - Path srcGenBasePath, - boolean useHierarchicalBin - ) throws IOException { - super(resource, srcGenBasePath, useHierarchicalBin); - } - - public FedFileConfig(FileConfig fileConfig) throws IOException { - super(fileConfig.resource, fileConfig.getSrcGenBasePath(), fileConfig.useHierarchicalBin); - } - - /** - * Return the path to the root of a LF project generated on the basis of a - * federated LF program currently under compilation. - */ - public Path getGenPath() { - return srcPkgPath.resolve("fed-gen").resolve(name); - } - - /** - * Return the path for storing generated LF sources that jointly constitute a - * federation. - */ - public Path getSrcPath() { - return getGenPath().resolve("src"); - } - - /** - * The directory in which to put the generated sources. - * This takes into account the location of the source file relative to the - * package root. Specifically, if the source file is x/y/Z.lf relative - * to the package root, then the generated sources will be put in x/y/Z - * relative to srcGenBasePath. - */ - @Override - public Path getSrcGenPath() { - return getGenPath().resolve("src-gen"); - } - - /** - * Return the path to the root of a LF project generated on the basis of a - * federated LF program currently under compilation. - */ - public Path getFedGenPath() { - return srcPkgPath.resolve("fed-gen").resolve(this.name); - } - - /** - * Return the path to the directory in which the executables of compiled federates are stored. - */ - public Path getFedBinPath() { return getFedGenPath().resolve("bin"); } - - @Override - public void doClean() throws IOException { - super.doClean(); - FileUtil.deleteDirectory(this.getFedGenPath()); - } - - /** - * Relativize target properties that involve paths like files and cmake-include to be - * relative to the generated .lf file for the federate. - */ - public void relativizePaths(FedTargetConfig targetConfig) { - relativizePathList(targetConfig.protoFiles); - relativizePathList(targetConfig.files); - relativizePathList(targetConfig.cmakeIncludes); - } - - /** - * Relativize each path in the given list. - * @param paths The paths to relativize. - */ - private void relativizePathList(List paths) { - List tempList = new ArrayList<>(); - paths.forEach(f -> tempList.add(relativizePath(Paths.get(f)))); - paths.clear(); - paths.addAll(tempList); - } - - /** - * Relativize a single path, but only if it points to a local resource in the project (i.e., not - * on the class path). - * @param path The path to relativize. - */ - private String relativizePath(Path path) { - if (FileUtil.findInPackage(path, this) == null) { - return String.valueOf(path); - } else { - Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); - return this.getSrcPath().relativize(resolvedPath).toString(); - } + public FedFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) + throws IOException { + super(resource, srcGenBasePath, useHierarchicalBin); + } + + public FedFileConfig(FileConfig fileConfig) throws IOException { + super(fileConfig.resource, fileConfig.getSrcGenBasePath(), fileConfig.useHierarchicalBin); + } + + /** + * Return the path to the root of a LF project generated on the basis of a federated LF program + * currently under compilation. + */ + public Path getGenPath() { + return srcPkgPath.resolve("fed-gen").resolve(name); + } + + /** Return the path for storing generated LF sources that jointly constitute a federation. */ + public Path getSrcPath() { + return getGenPath().resolve("src"); + } + + /** + * The directory in which to put the generated sources. This takes into account the location of + * the source file relative to the package root. Specifically, if the source file is x/y/Z.lf + * relative to the package root, then the generated sources will be put in x/y/Z relative to + * srcGenBasePath. + */ + @Override + public Path getSrcGenPath() { + return getGenPath().resolve("src-gen"); + } + + /** + * Return the path to the root of a LF project generated on the basis of a federated LF program + * currently under compilation. + */ + public Path getFedGenPath() { + return srcPkgPath.resolve("fed-gen").resolve(this.name); + } + + /** Return the path to the directory in which the executables of compiled federates are stored. */ + public Path getFedBinPath() { + return getFedGenPath().resolve("bin"); + } + + @Override + public void doClean() throws IOException { + super.doClean(); + FileUtil.deleteDirectory(this.getFedGenPath()); + } + + /** + * Relativize target properties that involve paths like files and cmake-include to be relative to + * the generated .lf file for the federate. + */ + public void relativizePaths(FedTargetConfig targetConfig) { + relativizePathList(targetConfig.protoFiles); + relativizePathList(targetConfig.files); + relativizePathList(targetConfig.cmakeIncludes); + } + + /** + * Relativize each path in the given list. + * + * @param paths The paths to relativize. + */ + private void relativizePathList(List paths) { + List tempList = new ArrayList<>(); + paths.forEach(f -> tempList.add(relativizePath(Paths.get(f)))); + paths.clear(); + paths.addAll(tempList); + } + + /** + * Relativize a single path, but only if it points to a local resource in the project (i.e., not + * on the class path). + * + * @param path The path to relativize. + */ + private String relativizePath(Path path) { + if (FileUtil.findInPackage(path, this) == null) { + return String.valueOf(path); + } else { + Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); + return this.getSrcPath().relativize(resolvedPath).toString(); } + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index 595a721c93..08a1fcf6e8 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -2,6 +2,7 @@ import static org.lflang.generator.DockerGenerator.dockerGeneratorFactory; +import com.google.inject.Injector; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; @@ -19,7 +20,6 @@ import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.JavaIoFileSystemAccess; @@ -27,14 +27,13 @@ import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.util.RuntimeIOException; import org.eclipse.xtext.xbase.lib.Exceptions; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.LFStandaloneSetup; import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty.CoordinationType; +import org.lflang.ast.ASTUtils; import org.lflang.federated.launcher.FedLauncherGenerator; import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeMap; @@ -58,569 +57,539 @@ import org.lflang.lf.Reactor; import org.lflang.util.Averager; -import com.google.inject.Injector; - public class FedGenerator { - - /** - * - */ - private final ErrorReporter errorReporter; - - /** - * A list of federate instances. - */ - private final List federates = new ArrayList<>(); - - /** - * File configuration to be used during the LF code generation stage (not the target code - * generation stage of individual federates). - */ - private final FedFileConfig fileConfig; - - /** - * Configuration of the RTI. - */ - final RtiConfig rtiConfig = new RtiConfig(); - - /** - * Target configuration of the federation; drawn from the file - * in which the federated reactor is defined. - */ - private final TargetConfig targetConfig; - - /** - * A map from instantiations to the federate instances for that - * instantiation. - * If the instantiation has a width, there may be more than one federate - * instance. - */ - private Map> federatesByInstantiation; - - /** - * Definition of the main (top-level) reactor. - * This is an automatically generated AST node for the top-level - * reactor. - */ - private Instantiation mainDef; - - /** - * Create a new generator and initialize a file configuration, target configuration, and error - * reporter. - * @param context - */ - public FedGenerator(LFGeneratorContext context) { - this.fileConfig = (FedFileConfig) context.getFileConfig(); - this.targetConfig = context.getTargetConfig(); - this.errorReporter = context.getErrorReporter(); + /** */ + private final ErrorReporter errorReporter; + + /** A list of federate instances. */ + private final List federates = new ArrayList<>(); + + /** + * File configuration to be used during the LF code generation stage (not the target code + * generation stage of individual federates). + */ + private final FedFileConfig fileConfig; + + /** Configuration of the RTI. */ + final RtiConfig rtiConfig = new RtiConfig(); + + /** + * Target configuration of the federation; drawn from the file in which the federated reactor is + * defined. + */ + private final TargetConfig targetConfig; + + /** + * A map from instantiations to the federate instances for that instantiation. If the + * instantiation has a width, there may be more than one federate instance. + */ + private Map> federatesByInstantiation; + + /** + * Definition of the main (top-level) reactor. This is an automatically generated AST node for the + * top-level reactor. + */ + private Instantiation mainDef; + + /** + * Create a new generator and initialize a file configuration, target configuration, and error + * reporter. + * + * @param context + */ + public FedGenerator(LFGeneratorContext context) { + this.fileConfig = (FedFileConfig) context.getFileConfig(); + this.targetConfig = context.getTargetConfig(); + this.errorReporter = context.getErrorReporter(); + } + + /** + * Produce LF code for each federate in a separate file, then invoke a target-specific code + * generator for each of those files. + * + * @param resource The resource that has the federated main reactor in it + * @param context The context in which to carry out the code generation. + * @return False if no errors have occurred, true otherwise. + * @throws IOException + */ + public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException { + if (!federatedExecutionIsSupported(resource)) return true; + cleanIfNeeded(context); + + // In a federated execution, we need keepalive to be true, + // otherwise a federate could exit simply because it hasn't received + // any messages. + targetConfig.keepalive = true; + + // Process command-line arguments + processCLIArguments(context); + + // Find the federated reactor + Reactor federation = FedASTUtils.findFederatedReactor(resource); + + // Extract some useful information about the federation + analyzeFederates(federation, context); + + // Find all the connections between federates. + // For each connection between federates, replace it in the + // AST with an action (which inherits the delay) and four reactions. + // The action will be physical for physical connections and logical + // for logical connections. + replaceFederateConnectionsWithProxies(federation); + + FedEmitter fedEmitter = + new FedEmitter( + fileConfig, ASTUtils.toDefinition(mainDef.getReactorClass()), errorReporter, rtiConfig); + + // Generate LF code for each federate. + Map lf2lfCodeMapMap = new HashMap<>(); + for (FederateInstance federate : federates) { + lf2lfCodeMapMap.putAll(fedEmitter.generateFederate(context, federate, federates.size())); } - /** - * Produce LF code for each federate in a separate file, then invoke a target-specific code - * generator for each of those files. - * - * @param resource The resource that has the federated main reactor in it - * @param context The context in which to carry out the code generation. - * @return False if no errors have occurred, true otherwise. - * @throws IOException - */ - public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException { - if (!federatedExecutionIsSupported(resource)) return true; - cleanIfNeeded(context); - - // In a federated execution, we need keepalive to be true, - // otherwise a federate could exit simply because it hasn't received - // any messages. - targetConfig.keepalive = true; - - // Process command-line arguments - processCLIArguments(context); - - // Find the federated reactor - Reactor federation = FedASTUtils.findFederatedReactor(resource); - - // Extract some useful information about the federation - analyzeFederates(federation, context); - - // Find all the connections between federates. - // For each connection between federates, replace it in the - // AST with an action (which inherits the delay) and four reactions. - // The action will be physical for physical connections and logical - // for logical connections. - replaceFederateConnectionsWithProxies(federation); - - FedEmitter fedEmitter = new FedEmitter( - fileConfig, - ASTUtils.toDefinition(mainDef.getReactorClass()), - errorReporter, - rtiConfig - ); - - // Generate LF code for each federate. - Map lf2lfCodeMapMap = new HashMap<>(); - for (FederateInstance federate : federates) { - lf2lfCodeMapMap.putAll(fedEmitter.generateFederate( - context, federate, federates.size() - )); - } - - // Do not invoke target code generators if --no-compile flag is used. - if (context.getTargetConfig().noCompile) { - context.finish(Status.GENERATED, lf2lfCodeMapMap); - return false; - } + // Do not invoke target code generators if --no-compile flag is used. + if (context.getTargetConfig().noCompile) { + context.finish(Status.GENERATED, lf2lfCodeMapMap); + return false; + } - Map codeMapMap = compileFederates(context, lf2lfCodeMapMap, subContexts -> { - createDockerFiles(context, subContexts); - generateLaunchScript(); - }); + Map codeMapMap = + compileFederates( + context, + lf2lfCodeMapMap, + subContexts -> { + createDockerFiles(context, subContexts); + generateLaunchScript(); + }); - context.finish(Status.COMPILED, codeMapMap); - return false; + context.finish(Status.COMPILED, codeMapMap); + return false; + } + + private void generateLaunchScript() { + new FedLauncherGenerator(this.targetConfig, this.fileConfig, this.errorReporter) + .doGenerate(federates, rtiConfig); + } + + /** + * Generate a Dockerfile for each federate and a docker-compose.yml for the federation. + * + * @param context The main context in which the federation has been compiled. + * @param subContexts The subcontexts in which the federates have been compiled. + */ + private void createDockerFiles(LFGeneratorContext context, List subContexts) { + if (context.getTargetConfig().dockerOptions == null) return; + final List services = new ArrayList<>(); + // 1. create a Dockerfile for each federate + for (SubContext subContext : subContexts) { // Inherit Docker options from main context + subContext.getTargetConfig().dockerOptions = context.getTargetConfig().dockerOptions; + var dockerGenerator = dockerGeneratorFactory(subContext); + var dockerData = dockerGenerator.generateDockerData(); + try { + dockerData.writeDockerFile(); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + services.add(dockerData); } - - private void generateLaunchScript() { - new FedLauncherGenerator( - this.targetConfig, - this.fileConfig, - this.errorReporter - ).doGenerate(federates, rtiConfig); + // 2. create a docker-compose.yml for the federation + try { + new FedDockerComposeGenerator(context, rtiConfig.getHost()).writeDockerComposeFile(services); + } catch (IOException e) { + throw new RuntimeIOException(e); } - - /** - * Generate a Dockerfile for each federate and a docker-compose.yml for the federation. - * @param context The main context in which the federation has been compiled. - * @param subContexts The subcontexts in which the federates have been compiled. - */ - private void createDockerFiles(LFGeneratorContext context, List subContexts) { - if (context.getTargetConfig().dockerOptions == null) return; - final List services = new ArrayList<>(); - // 1. create a Dockerfile for each federate - for (SubContext subContext : subContexts) {// Inherit Docker options from main context - subContext.getTargetConfig().dockerOptions = context.getTargetConfig().dockerOptions; - var dockerGenerator = dockerGeneratorFactory(subContext); - var dockerData = dockerGenerator.generateDockerData(); - try { - dockerData.writeDockerFile(); - } catch (IOException e) { - throw new RuntimeIOException(e); - } - services.add(dockerData); - } - // 2. create a docker-compose.yml for the federation - try { - new FedDockerComposeGenerator( - context, - rtiConfig.getHost() - ).writeDockerComposeFile(services); - } catch (IOException e) { - throw new RuntimeIOException(e); - } + } + + /** + * Check if a clean was requested from the standalone compiler and perform the clean step. + * + * @param context Context in which the generator operates + */ + private void cleanIfNeeded(LFGeneratorContext context) { + if (context.getArgs().containsKey(BuildParm.CLEAN.getKey())) { + try { + fileConfig.doClean(); + } catch (IOException e) { + System.err.println("WARNING: IO Error during clean"); + } } - - /** - * Check if a clean was requested from the standalone compiler and perform - * the clean step. - * @param context Context in which the generator operates - */ - private void cleanIfNeeded(LFGeneratorContext context) { - if (context.getArgs().containsKey(BuildParm.CLEAN.getKey())) { - try { - fileConfig.doClean(); - } catch (IOException e) { - System.err.println("WARNING: IO Error during clean"); - } - } + } + + /** Return whether federated execution is supported for {@code resource}. */ + private boolean federatedExecutionIsSupported(Resource resource) { + var target = Target.fromDecl(GeneratorUtils.findTargetDecl(resource)); + var targetOK = + List.of(Target.C, Target.Python, Target.TS, Target.CPP, Target.CCPP).contains(target); + if (!targetOK) { + errorReporter.reportError("Federated execution is not supported with target " + target + "."); } - - /** Return whether federated execution is supported for {@code resource}. */ - private boolean federatedExecutionIsSupported(Resource resource) { - var target = Target.fromDecl(GeneratorUtils.findTargetDecl(resource)); - var targetOK = List.of( - Target.C, Target.Python, Target.TS, Target.CPP, Target.CCPP - ).contains(target); - if (!targetOK) { - errorReporter.reportError( - "Federated execution is not supported with target " + target + "." - ); - } - if(target.equals(Target.C) && GeneratorUtils.isHostWindows()) { - errorReporter.reportError( - "Federated LF programs with a C target are currently not supported on Windows." - ); - targetOK = false; - } - - return targetOK; + if (target.equals(Target.C) && GeneratorUtils.isHostWindows()) { + errorReporter.reportError( + "Federated LF programs with a C target are currently not supported on Windows."); + targetOK = false; } - private Map compileFederates( - LFGeneratorContext context, - Map lf2lfCodeMapMap, - Consumer> finalizer) { - - // FIXME: Use the appropriate resource set instead of always using standalone - Injector inj = new LFStandaloneSetup() - .createInjectorAndDoEMFRegistration(); - XtextResourceSet rs = inj.getInstance(XtextResourceSet.class); - rs.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); - // define output path here - JavaIoFileSystemAccess fsa = inj.getInstance(JavaIoFileSystemAccess.class); - fsa.setOutputPath("DEFAULT_OUTPUT", fileConfig.getSrcGenPath().toString()); - - var numOfCompileThreads = Math.min(6, - Math.min( - Math.max(federates.size(), 1), - Runtime.getRuntime().availableProcessors() - ) - ); - var compileThreadPool = Executors.newFixedThreadPool(numOfCompileThreads); - System.out.println("******** Using "+numOfCompileThreads+" threads to compile the program."); - Map codeMapMap = new ConcurrentHashMap<>(); - List subContexts = Collections.synchronizedList(new ArrayList<>()); - Averager averager = new Averager(federates.size()); - final var threadSafeErrorReporter = new SynchronizedErrorReporter(errorReporter); - for (int i = 0; i < federates.size(); i++) { - FederateInstance fed = federates.get(i); - final int id = i; - compileThreadPool.execute(() -> { - Resource res = rs.getResource(URI.createFileURI( - FedEmitter.lfFilePath(fileConfig, fed).toAbsolutePath().toString() - ), true); - FileConfig subFileConfig = LFGenerator.createFileConfig(res, fileConfig.getSrcGenPath(), true); - ErrorReporter subContextErrorReporter = new LineAdjustingErrorReporter(threadSafeErrorReporter, lf2lfCodeMapMap); - - var props = new Properties(); - if (targetConfig.dockerOptions != null && targetConfig.target.buildsUsingDocker()) { - props.put("no-compile", "true"); - } - props.put("docker", "false"); - - TargetConfig subConfig = new TargetConfig( - props, GeneratorUtils.findTargetDecl(subFileConfig.resource), subContextErrorReporter - ); - SubContext subContext = new SubContext(context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, 100) { - @Override - public ErrorReporter getErrorReporter() { - return subContextErrorReporter; - } - - @Override - public void reportProgress(String message, int percentage) { - averager.report(id, percentage, meanPercentage -> super.reportProgress(message, meanPercentage)); - } - - @Override - public FileConfig getFileConfig() { - return subFileConfig; - } - - @Override - public TargetConfig getTargetConfig() { - return subConfig; - } + return targetOK; + } + + private Map compileFederates( + LFGeneratorContext context, + Map lf2lfCodeMapMap, + Consumer> finalizer) { + + // FIXME: Use the appropriate resource set instead of always using standalone + Injector inj = new LFStandaloneSetup().createInjectorAndDoEMFRegistration(); + XtextResourceSet rs = inj.getInstance(XtextResourceSet.class); + rs.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); + // define output path here + JavaIoFileSystemAccess fsa = inj.getInstance(JavaIoFileSystemAccess.class); + fsa.setOutputPath("DEFAULT_OUTPUT", fileConfig.getSrcGenPath().toString()); + + var numOfCompileThreads = + Math.min( + 6, Math.min(Math.max(federates.size(), 1), Runtime.getRuntime().availableProcessors())); + var compileThreadPool = Executors.newFixedThreadPool(numOfCompileThreads); + System.out.println( + "******** Using " + numOfCompileThreads + " threads to compile the program."); + Map codeMapMap = new ConcurrentHashMap<>(); + List subContexts = Collections.synchronizedList(new ArrayList<>()); + Averager averager = new Averager(federates.size()); + final var threadSafeErrorReporter = new SynchronizedErrorReporter(errorReporter); + for (int i = 0; i < federates.size(); i++) { + FederateInstance fed = federates.get(i); + final int id = i; + compileThreadPool.execute( + () -> { + Resource res = + rs.getResource( + URI.createFileURI( + FedEmitter.lfFilePath(fileConfig, fed).toAbsolutePath().toString()), + true); + FileConfig subFileConfig = + LFGenerator.createFileConfig(res, fileConfig.getSrcGenPath(), true); + ErrorReporter subContextErrorReporter = + new LineAdjustingErrorReporter(threadSafeErrorReporter, lf2lfCodeMapMap); + + var props = new Properties(); + if (targetConfig.dockerOptions != null && targetConfig.target.buildsUsingDocker()) { + props.put("no-compile", "true"); + } + props.put("docker", "false"); + + TargetConfig subConfig = + new TargetConfig( + props, + GeneratorUtils.findTargetDecl(subFileConfig.resource), + subContextErrorReporter); + SubContext subContext = + new SubContext(context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, 100) { + @Override + public ErrorReporter getErrorReporter() { + return subContextErrorReporter; + } + + @Override + public void reportProgress(String message, int percentage) { + averager.report( + id, + percentage, + meanPercentage -> super.reportProgress(message, meanPercentage)); + } + + @Override + public FileConfig getFileConfig() { + return subFileConfig; + } + + @Override + public TargetConfig getTargetConfig() { + return subConfig; + } }; - inj.getInstance(LFGenerator.class).doGenerate(res, fsa, subContext); - codeMapMap.putAll(subContext.getResult().getCodeMaps()); - subContexts.add(subContext); - }); - } - // Initiate an orderly shutdown in which previously submitted tasks are - // executed, but no new tasks will be accepted. - compileThreadPool.shutdown(); - - // Wait for all compile threads to finish (NOTE: Can block forever) - try { - compileThreadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - } catch (Exception e) { - Exceptions.sneakyThrow(e); - } finally { - finalizer.accept(subContexts); - } - return codeMapMap; + inj.getInstance(LFGenerator.class).doGenerate(res, fsa, subContext); + codeMapMap.putAll(subContext.getResult().getCodeMaps()); + subContexts.add(subContext); + }); } - - /** - * Process command-line arguments passed on to the generator. - * - * @param context Context of the build process. - */ - private void processCLIArguments(LFGeneratorContext context) { - if (context.getArgs().containsKey("rti")) { - setFederationRTIProperties(context); - } + // Initiate an orderly shutdown in which previously submitted tasks are + // executed, but no new tasks will be accepted. + compileThreadPool.shutdown(); + + // Wait for all compile threads to finish (NOTE: Can block forever) + try { + compileThreadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + } catch (Exception e) { + Exceptions.sneakyThrow(e); + } finally { + finalizer.accept(subContexts); } - - /** - * Set the RTI hostname, port and username if given as compiler arguments - * - * @param context Context of the build process. - */ - private void setFederationRTIProperties(LFGeneratorContext context) { - String rtiAddr = context.getArgs().getProperty("rti"); - Pattern pattern = Pattern.compile("([a-zA-Z0-9]+@)?([a-zA-Z0-9]+\\.?[a-z]{2,}|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+):?([0-9]+)?"); - Matcher matcher = pattern.matcher(rtiAddr); - - if (!matcher.find()) { - return; - } - - // the user match group contains a trailing "@" which needs to be removed. - String userWithAt = matcher.group(1); - String user = (userWithAt == null) ? null : userWithAt.substring(0, - userWithAt.length() - - 1); - String host = matcher.group(2); - String port = matcher.group(3); - - if (host != null) { - rtiConfig.setHost(host); - } - if (port != null) { - rtiConfig.setPort(Integer.parseInt(port)); - } - if (user != null) { - rtiConfig.setUser(user); - } + return codeMapMap; + } + + /** + * Process command-line arguments passed on to the generator. + * + * @param context Context of the build process. + */ + private void processCLIArguments(LFGeneratorContext context) { + if (context.getArgs().containsKey("rti")) { + setFederationRTIProperties(context); + } + } + + /** + * Set the RTI hostname, port and username if given as compiler arguments + * + * @param context Context of the build process. + */ + private void setFederationRTIProperties(LFGeneratorContext context) { + String rtiAddr = context.getArgs().getProperty("rti"); + Pattern pattern = + Pattern.compile( + "([a-zA-Z0-9]+@)?([a-zA-Z0-9]+\\.?[a-z]{2,}|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+):?([0-9]+)?"); + Matcher matcher = pattern.matcher(rtiAddr); + + if (!matcher.find()) { + return; } - /** - * Analyze the federation and record various properties of it. - * - * @param federation The federated reactor that contains all federates' instances. - */ - private void analyzeFederates(Reactor federation, LFGeneratorContext context) { - // Create an instantiation for the fed reactor because there isn't one. - // Creating a definition for the main reactor because there isn't one. - mainDef = LfFactory.eINSTANCE.createInstantiation(); - mainDef.setName(federation.getName()); - mainDef.setReactorClass(federation); - - // Make sure that if no federation RTI properties were given in the - // cmdline, then those specified in the lf file are not lost - if (rtiConfig.getHost().equals("localhost") && - federation.getHost() != null && - !federation.getHost().getAddr().equals("localhost")) { - rtiConfig.setHost(federation.getHost().getAddr()); - } + // the user match group contains a trailing "@" which needs to be removed. + String userWithAt = matcher.group(1); + String user = (userWithAt == null) ? null : userWithAt.substring(0, userWithAt.length() - 1); + String host = matcher.group(2); + String port = matcher.group(3); - // Since federates are always within the main (federated) reactor, - // create a list containing just that one containing instantiation. - // This will be used to look up parameter values. - List mainReactorContext = new ArrayList<>(); - mainReactorContext.add(mainDef); - - // Create a FederateInstance for each instance in the top-level reactor. - for (Instantiation instantiation : ASTUtils.allInstantiations(federation)) { - int bankWidth = ASTUtils.width(instantiation.getWidthSpec(), mainReactorContext); - if (bankWidth < 0) { - errorReporter.reportError(instantiation, "Cannot determine bank width! Assuming width of 1."); - // Continue with a bank width of 1. - bankWidth = 1; - } - List federateInstances = getFederateInstances(instantiation, bankWidth, context); - if (federatesByInstantiation == null) { - federatesByInstantiation = new LinkedHashMap<>(); - } - federatesByInstantiation.put(instantiation, federateInstances); - } + if (host != null) { + rtiConfig.setHost(host); } - - /** - * Get federate instances for a given {@code instantiation}. A bank will - * result in the creation of multiple federate instances (one for each - * member of the bank). - * - * @param instantiation An instantiation that corresponds to a federate. - * @param bankWidth The width specified for the instantiation. - * @return A list of federate instance (of type @see FederateInstance). - */ - private List getFederateInstances(Instantiation instantiation, int bankWidth, LFGeneratorContext context) { - // Create one federate instance for each instance in a bank of reactors. - List federateInstances = new ArrayList<>(bankWidth); - - for (int i = 0; i < bankWidth; i++) { - // Assign an integer ID to the federate. - int federateID = federates.size(); - var resource = instantiation.getReactorClass().eResource(); - var federateTargetConfig = new FedTargetConfig(context, resource); - FederateInstance federateInstance = new FederateInstance( - instantiation, - federateID, - i, - federateTargetConfig, - errorReporter); - federates.add(federateInstance); - federateInstances.add(federateInstance); - - if (instantiation.getHost() != null) { - federateInstance.host = instantiation.getHost().getAddr(); - // The following could be 0. - federateInstance.port = instantiation.getHost().getPort(); - // The following could be null. - federateInstance.user = instantiation.getHost().getUser(); - /* FIXME: The at keyword should support a directory component. - * federateInstance.dir = instantiation.getHost().dir - */ - if (federateInstance.host != null - && !federateInstance.host.equals("localhost") - && !federateInstance.host.equals("0.0.0.0")) { - federateInstance.isRemote = true; - } - } - } - return federateInstances; + if (port != null) { + rtiConfig.setPort(Integer.parseInt(port)); } - - /** - * Replace connections between federates in the AST with proxies that - * handle sending and receiving data. - * - * @param federation Reactor class of the federation. - */ - private void replaceFederateConnectionsWithProxies(Reactor federation) { - // Each connection in the AST may represent more than one connection between - // federation instances because of banks and multiports. We need to generate communication - // for each of these. To do this, we create a ReactorInstance so that we don't have - // to duplicate the rather complicated logic in that class. We specify a depth of 1, - // so it only creates the reactors immediately within the top level, not reactors - // that those contain. - ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter); - - for (ReactorInstance child : mainInstance.children) { - for (PortInstance output : child.outputs) { - replaceConnectionFromOutputPort(output); - } - } - - // Remove the connections at the top level - federation.getConnections().clear(); - - // There will be AST transformations that invalidate some info - // cached in ReactorInstance. FIXME: most likely not needed anymore - mainInstance.clearCaches(false); + if (user != null) { + rtiConfig.setUser(user); } - - /** - * Replace the connections from the specified output port. - * - * @param output The output port instance. - */ - private void replaceConnectionFromOutputPort(PortInstance output) { - // Iterate through ranges of the output port - for (SendRange srcRange : output.getDependentPorts()) { - if (srcRange.connection == null) { - // This should not happen. - errorReporter.reportError( - output.getDefinition(), - "Unexpected error. Cannot find output connection for port" - ); - continue; - } - // Iterate through destinations - for (RuntimeRange dstRange : srcRange.destinations) { - replaceOneToManyConnection( - srcRange, - dstRange - ); - } - } + } + + /** + * Analyze the federation and record various properties of it. + * + * @param federation The federated reactor that contains all federates' instances. + */ + private void analyzeFederates(Reactor federation, LFGeneratorContext context) { + // Create an instantiation for the fed reactor because there isn't one. + // Creating a definition for the main reactor because there isn't one. + mainDef = LfFactory.eINSTANCE.createInstantiation(); + mainDef.setName(federation.getName()); + mainDef.setReactorClass(federation); + + // Make sure that if no federation RTI properties were given in the + // cmdline, then those specified in the lf file are not lost + if (rtiConfig.getHost().equals("localhost") + && federation.getHost() != null + && !federation.getHost().getAddr().equals("localhost")) { + rtiConfig.setHost(federation.getHost().getAddr()); } - /** - * Replace (potentially multiple) connection(s) that originate from an - * output port to multiple destinations. - * - * @param srcRange A range of an output port that sources data for this - * connection. - * @param dstRange A range of input ports that receive the data. - */ - private void replaceOneToManyConnection( - SendRange srcRange, - RuntimeRange dstRange - ) { - MixedRadixInt srcID = srcRange.startMR(); - MixedRadixInt dstID = dstRange.startMR(); - int dstCount = 0; - int srcCount = 0; - - while (dstCount++ < dstRange.width) { - int srcChannel = srcID.getDigits().get(0); - int srcBank = srcID.get(1); - int dstChannel = dstID.getDigits().get(0); - int dstBank = dstID.get(1); - - FederateInstance srcFederate = federatesByInstantiation.get( - srcRange.instance.getParent().getDefinition() - ).get(srcBank); - FederateInstance dstFederate = federatesByInstantiation.get( - dstRange.instance.getParent().getDefinition() - ).get(dstBank); - - // Clear banks - srcFederate.instantiation.setWidthSpec(null); - dstFederate.instantiation.setWidthSpec(null); - - FedConnectionInstance fedConnection = new FedConnectionInstance( - srcRange, - dstRange, - srcChannel, - srcBank, - dstChannel, - dstBank, - srcFederate, - dstFederate, - FedUtils.getSerializer(srcRange.connection, srcFederate, dstFederate) - ); - - replaceFedConnection(fedConnection); - - dstID.increment(); - srcID.increment(); - srcCount++; - if (srcCount == srcRange.width) { - srcID = srcRange.startMR(); // Multicast. Start over. - } - } + // Since federates are always within the main (federated) reactor, + // create a list containing just that one containing instantiation. + // This will be used to look up parameter values. + List mainReactorContext = new ArrayList<>(); + mainReactorContext.add(mainDef); + + // Create a FederateInstance for each instance in the top-level reactor. + for (Instantiation instantiation : ASTUtils.allInstantiations(federation)) { + int bankWidth = ASTUtils.width(instantiation.getWidthSpec(), mainReactorContext); + if (bankWidth < 0) { + errorReporter.reportError( + instantiation, "Cannot determine bank width! Assuming width of 1."); + // Continue with a bank width of 1. + bankWidth = 1; + } + List federateInstances = + getFederateInstances(instantiation, bankWidth, context); + if (federatesByInstantiation == null) { + federatesByInstantiation = new LinkedHashMap<>(); + } + federatesByInstantiation.put(instantiation, federateInstances); } - - /** - * Replace a one-to-one federated connection with proxies. - * - * @param connection A connection between two federates. - */ - private void replaceFedConnection(FedConnectionInstance connection) { - if (!connection.getDefinition().isPhysical() - && targetConfig.coordination != CoordinationType.DECENTRALIZED) { - // Map the delays on connections between federates. - Set dependsOnDelays = - connection.dstFederate.dependsOn.computeIfAbsent( - connection.srcFederate, - k -> new LinkedHashSet<>() - ); - // Put the delay on the cache. - if (connection.getDefinition().getDelay() != null) { - dependsOnDelays.add(connection.getDefinition().getDelay()); - } else { - // To indicate that at least one connection has no delay, add a null entry. - dependsOnDelays.add(null); - } - // Map the connections between federates. - Set sendsToDelays = - connection.srcFederate.sendsTo.computeIfAbsent( - connection.dstFederate, - k -> new LinkedHashSet<>() - ); - if (connection.getDefinition().getDelay() != null) { - sendsToDelays.add(connection.getDefinition().getDelay()); - } else { - // To indicate that at least one connection has no delay, add a null entry. - sendsToDelays.add(null); - } + } + + /** + * Get federate instances for a given {@code instantiation}. A bank will result in the creation of + * multiple federate instances (one for each member of the bank). + * + * @param instantiation An instantiation that corresponds to a federate. + * @param bankWidth The width specified for the instantiation. + * @return A list of federate instance (of type @see FederateInstance). + */ + private List getFederateInstances( + Instantiation instantiation, int bankWidth, LFGeneratorContext context) { + // Create one federate instance for each instance in a bank of reactors. + List federateInstances = new ArrayList<>(bankWidth); + + for (int i = 0; i < bankWidth; i++) { + // Assign an integer ID to the federate. + int federateID = federates.size(); + var resource = instantiation.getReactorClass().eResource(); + var federateTargetConfig = new FedTargetConfig(context, resource); + FederateInstance federateInstance = + new FederateInstance(instantiation, federateID, i, federateTargetConfig, errorReporter); + federates.add(federateInstance); + federateInstances.add(federateInstance); + + if (instantiation.getHost() != null) { + federateInstance.host = instantiation.getHost().getAddr(); + // The following could be 0. + federateInstance.port = instantiation.getHost().getPort(); + // The following could be null. + federateInstance.user = instantiation.getHost().getUser(); + /* FIXME: The at keyword should support a directory component. + * federateInstance.dir = instantiation.getHost().dir + */ + if (federateInstance.host != null + && !federateInstance.host.equals("localhost") + && !federateInstance.host.equals("0.0.0.0")) { + federateInstance.isRemote = true; } + } + } + return federateInstances; + } + + /** + * Replace connections between federates in the AST with proxies that handle sending and receiving + * data. + * + * @param federation Reactor class of the federation. + */ + private void replaceFederateConnectionsWithProxies(Reactor federation) { + // Each connection in the AST may represent more than one connection between + // federation instances because of banks and multiports. We need to generate communication + // for each of these. To do this, we create a ReactorInstance so that we don't have + // to duplicate the rather complicated logic in that class. We specify a depth of 1, + // so it only creates the reactors immediately within the top level, not reactors + // that those contain. + ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter); + + for (ReactorInstance child : mainInstance.children) { + for (PortInstance output : child.outputs) { + replaceConnectionFromOutputPort(output); + } + } - FedASTUtils.makeCommunication(connection, targetConfig.coordination, errorReporter); + // Remove the connections at the top level + federation.getConnections().clear(); + + // There will be AST transformations that invalidate some info + // cached in ReactorInstance. FIXME: most likely not needed anymore + mainInstance.clearCaches(false); + } + + /** + * Replace the connections from the specified output port. + * + * @param output The output port instance. + */ + private void replaceConnectionFromOutputPort(PortInstance output) { + // Iterate through ranges of the output port + for (SendRange srcRange : output.getDependentPorts()) { + if (srcRange.connection == null) { + // This should not happen. + errorReporter.reportError( + output.getDefinition(), "Unexpected error. Cannot find output connection for port"); + continue; + } + // Iterate through destinations + for (RuntimeRange dstRange : srcRange.destinations) { + replaceOneToManyConnection(srcRange, dstRange); + } + } + } + + /** + * Replace (potentially multiple) connection(s) that originate from an output port to multiple + * destinations. + * + * @param srcRange A range of an output port that sources data for this connection. + * @param dstRange A range of input ports that receive the data. + */ + private void replaceOneToManyConnection(SendRange srcRange, RuntimeRange dstRange) { + MixedRadixInt srcID = srcRange.startMR(); + MixedRadixInt dstID = dstRange.startMR(); + int dstCount = 0; + int srcCount = 0; + + while (dstCount++ < dstRange.width) { + int srcChannel = srcID.getDigits().get(0); + int srcBank = srcID.get(1); + int dstChannel = dstID.getDigits().get(0); + int dstBank = dstID.get(1); + + FederateInstance srcFederate = + federatesByInstantiation.get(srcRange.instance.getParent().getDefinition()).get(srcBank); + FederateInstance dstFederate = + federatesByInstantiation.get(dstRange.instance.getParent().getDefinition()).get(dstBank); + + // Clear banks + srcFederate.instantiation.setWidthSpec(null); + dstFederate.instantiation.setWidthSpec(null); + + FedConnectionInstance fedConnection = + new FedConnectionInstance( + srcRange, + dstRange, + srcChannel, + srcBank, + dstChannel, + dstBank, + srcFederate, + dstFederate, + FedUtils.getSerializer(srcRange.connection, srcFederate, dstFederate)); + + replaceFedConnection(fedConnection); + + dstID.increment(); + srcID.increment(); + srcCount++; + if (srcCount == srcRange.width) { + srcID = srcRange.startMR(); // Multicast. Start over. + } } + } + + /** + * Replace a one-to-one federated connection with proxies. + * + * @param connection A connection between two federates. + */ + private void replaceFedConnection(FedConnectionInstance connection) { + if (!connection.getDefinition().isPhysical() + && targetConfig.coordination != CoordinationType.DECENTRALIZED) { + // Map the delays on connections between federates. + Set dependsOnDelays = + connection.dstFederate.dependsOn.computeIfAbsent( + connection.srcFederate, k -> new LinkedHashSet<>()); + // Put the delay on the cache. + if (connection.getDefinition().getDelay() != null) { + dependsOnDelays.add(connection.getDefinition().getDelay()); + } else { + // To indicate that at least one connection has no delay, add a null entry. + dependsOnDelays.add(null); + } + // Map the connections between federates. + Set sendsToDelays = + connection.srcFederate.sendsTo.computeIfAbsent( + connection.dstFederate, k -> new LinkedHashSet<>()); + if (connection.getDefinition().getDelay() != null) { + sendsToDelays.add(connection.getDefinition().getDelay()); + } else { + // To indicate that at least one connection has no delay, add a null entry. + sendsToDelays.add(null); + } + } + + FedASTUtils.makeCommunication(connection, targetConfig.coordination, errorReporter); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java index 95351237a7..baf13d6a0a 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java @@ -4,9 +4,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; - import org.eclipse.emf.ecore.util.EcoreUtil; - import org.lflang.ast.FormattingUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Import; @@ -19,44 +17,41 @@ */ public class FedImportEmitter { - private static Set visitedImports = new HashSet<>(); - - /** - * Generate import statements for {@code federate}. - */ - String generateImports(FederateInstance federate, FedFileConfig fileConfig) { - var imports = ((Model) federate.instantiation.eContainer().eContainer()) - .getImports() - .stream() - .filter(federate::contains).toList(); - - // Transform the URIs + private static Set visitedImports = new HashSet<>(); + + /** Generate import statements for {@code federate}. */ + String generateImports(FederateInstance federate, FedFileConfig fileConfig) { + var imports = + ((Model) federate.instantiation.eContainer().eContainer()) + .getImports().stream().filter(federate::contains).toList(); + + // Transform the URIs + imports.stream() + .filter(i -> !visitedImports.contains(i)) + .forEach( + i -> { + visitedImports.add(i); + Path importPath = fileConfig.srcPath.resolve(i.getImportURI()).toAbsolutePath(); + i.setImportURI( + fileConfig.getSrcPath().relativize(importPath).toString().replace('\\', '/')); + }); + + var importStatements = new CodeBuilder(); + + // Add import statements needed for the ordinary functionality of the federate + importStatements.pr( imports.stream() - .filter(i -> !visitedImports.contains(i)) - .forEach(i -> { - visitedImports.add(i); - Path importPath = - fileConfig.srcPath - .resolve(i.getImportURI()).toAbsolutePath(); - i.setImportURI(fileConfig.getSrcPath().relativize(importPath) - .toString().replace('\\', '/') - ); - }); - - var importStatements = new CodeBuilder(); - - // Add import statements needed for the ordinary functionality of the federate - importStatements.pr(imports.stream() - .map(i -> { - var new_import = EcoreUtil.copy(i); - new_import.getReactorClasses().removeIf( - importedReactor -> !federate.contains(importedReactor) - ); - return new_import; - }) - .map(FormattingUtils.renderer(federate.targetConfig.target)) - .collect(Collectors.joining("\n"))); - - return importStatements.getCode(); - } + .map( + i -> { + var new_import = EcoreUtil.copy(i); + new_import + .getReactorClasses() + .removeIf(importedReactor -> !federate.contains(importedReactor)); + return new_import; + }) + .map(FormattingUtils.renderer(federate.targetConfig.target)) + .collect(Collectors.joining("\n"))); + + return importStatements.getCode(); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java index 65b9d4cd15..86ce4f02b9 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java @@ -2,83 +2,90 @@ import java.util.function.Function; import java.util.stream.Collectors; - import org.eclipse.emf.ecore.EObject; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; +import org.lflang.ast.ASTUtils; import org.lflang.ast.FormattingUtils; import org.lflang.lf.Reactor; import org.lflang.lf.Variable; -/** - * Helper class to generate a main reactor - */ +/** Helper class to generate a main reactor */ public class FedMainEmitter { - /** - * Generate a main reactor for {@code federate}. - * - * @param federate - * @param originalMainReactor The original main reactor. - * @param errorReporter Used to report errors. - * @return The main reactor. - */ - String generateMainReactor(FederateInstance federate, Reactor originalMainReactor, ErrorReporter errorReporter) { - // FIXME: Handle modes at the top-level - if (!ASTUtils.allModes(originalMainReactor).isEmpty()) { - errorReporter.reportError( - ASTUtils.allModes(originalMainReactor).stream().findFirst().get(), - "Modes at the top level are not supported under federated execution." - ); - } - var renderer = FormattingUtils.renderer(federate.targetConfig.target); + /** + * Generate a main reactor for {@code federate}. + * + * @param federate + * @param originalMainReactor The original main reactor. + * @param errorReporter Used to report errors. + * @return The main reactor. + */ + String generateMainReactor( + FederateInstance federate, Reactor originalMainReactor, ErrorReporter errorReporter) { + // FIXME: Handle modes at the top-level + if (!ASTUtils.allModes(originalMainReactor).isEmpty()) { + errorReporter.reportError( + ASTUtils.allModes(originalMainReactor).stream().findFirst().get(), + "Modes at the top level are not supported under federated execution."); + } + var renderer = FormattingUtils.renderer(federate.targetConfig.target); - return String - .join( + return String.join( + "\n", + generateMainSignature(federate, originalMainReactor, renderer), + String.join( "\n", - generateMainSignature(federate, originalMainReactor, renderer), - String.join( - "\n", - renderer.apply(federate.instantiation), - ASTUtils.allStateVars(originalMainReactor).stream().filter(federate::contains).map(renderer).collect(Collectors.joining("\n")), - ASTUtils.allActions(originalMainReactor).stream().filter(federate::contains).map(renderer).collect(Collectors.joining("\n")), - ASTUtils.allTimers(originalMainReactor).stream().filter(federate::contains).map(renderer).collect(Collectors.joining("\n")), - ASTUtils.allMethods(originalMainReactor).stream().filter(federate::contains).map(renderer).collect(Collectors.joining("\n")), - ASTUtils.allReactions(originalMainReactor).stream().filter(federate::contains).map(renderer).collect(Collectors.joining("\n")) - ).indent(4).stripTrailing(), - "}" - ); - } + renderer.apply(federate.instantiation), + ASTUtils.allStateVars(originalMainReactor).stream() + .filter(federate::contains) + .map(renderer) + .collect(Collectors.joining("\n")), + ASTUtils.allActions(originalMainReactor).stream() + .filter(federate::contains) + .map(renderer) + .collect(Collectors.joining("\n")), + ASTUtils.allTimers(originalMainReactor).stream() + .filter(federate::contains) + .map(renderer) + .collect(Collectors.joining("\n")), + ASTUtils.allMethods(originalMainReactor).stream() + .filter(federate::contains) + .map(renderer) + .collect(Collectors.joining("\n")), + ASTUtils.allReactions(originalMainReactor).stream() + .filter(federate::contains) + .map(renderer) + .collect(Collectors.joining("\n"))) + .indent(4) + .stripTrailing(), + "}"); + } - /** - * Generate the signature of the main reactor. - * @param federate The federate. - * @param originalMainReactor The original main reactor of the original .lf file. - * @param renderer Used to render EObjects (in String representation). - */ - private CharSequence generateMainSignature(FederateInstance federate, Reactor originalMainReactor, Function renderer) { - var paramList = ASTUtils.allParameters(originalMainReactor) - .stream() - .filter(federate::contains) - .map(renderer) - .collect( - Collectors.joining( - ",", "(", ")" - ) - ); - // Empty "()" is currently not allowed by the syntax + /** + * Generate the signature of the main reactor. + * + * @param federate The federate. + * @param originalMainReactor The original main reactor of the original .lf file. + * @param renderer Used to render EObjects (in String representation). + */ + private CharSequence generateMainSignature( + FederateInstance federate, Reactor originalMainReactor, Function renderer) { + var paramList = + ASTUtils.allParameters(originalMainReactor).stream() + .filter(federate::contains) + .map(renderer) + .collect(Collectors.joining(",", "(", ")")); + // Empty "()" is currently not allowed by the syntax - var networkMessageActionsListString = federate.networkMessageActions - .stream() + var networkMessageActionsListString = + federate.networkMessageActions.stream() .map(Variable::getName) .collect(Collectors.joining(",")); - return - """ + return """ @_fed_config(network_message_actions="%s") main reactor %s { - """.formatted(networkMessageActionsListString, - paramList.equals("()") ? "" : paramList); - } + """ + .formatted(networkMessageActionsListString, paramList.equals("()") ? "" : paramList); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java index 154919c816..9cb35b2949 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java @@ -3,9 +3,8 @@ import static org.lflang.ast.ASTUtils.toText; import java.io.IOException; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; +import org.lflang.ast.ASTUtils; import org.lflang.federated.extensions.FedTargetExtensionFactory; import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeBuilder; @@ -14,38 +13,43 @@ public class FedPreambleEmitter { - public FedPreambleEmitter() {} - - /** - * Add necessary code to the source and necessary build support to - * enable the requested serializations in 'enabledSerializations' - */ - String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, RtiConfig rtiConfig, ErrorReporter errorReporter) - throws IOException { - CodeBuilder preambleCode = new CodeBuilder(); - - // Transfer top-level preambles - var mainModel = (Model) ASTUtils.toDefinition(federate.instantiation.getReactorClass()).eContainer(); - for (Preamble p : mainModel.getPreambles()) { - preambleCode.pr( - """ + public FedPreambleEmitter() {} + + /** + * Add necessary code to the source and necessary build support to enable the requested + * serializations in 'enabledSerializations' + */ + String generatePreamble( + FederateInstance federate, + FedFileConfig fileConfig, + RtiConfig rtiConfig, + ErrorReporter errorReporter) + throws IOException { + CodeBuilder preambleCode = new CodeBuilder(); + + // Transfer top-level preambles + var mainModel = + (Model) ASTUtils.toDefinition(federate.instantiation.getReactorClass()).eContainer(); + for (Preamble p : mainModel.getPreambles()) { + preambleCode.pr( + """ %spreamble {= %s =} - """.formatted( - p.getVisibility() == null ? "" : p.getVisibility() + " ", - toText(p.getCode()) - )); - } + """ + .formatted( + p.getVisibility() == null ? "" : p.getVisibility() + " ", toText(p.getCode()))); + } - preambleCode.pr(""" + preambleCode.pr( + """ preamble {= %s - =}""".formatted(FedTargetExtensionFactory.getExtension(federate.targetConfig.target).generatePreamble( - federate, fileConfig, rtiConfig, errorReporter - )) - ); + =}""" + .formatted( + FedTargetExtensionFactory.getExtension(federate.targetConfig.target) + .generatePreamble(federate, fileConfig, rtiConfig, errorReporter))); - return preambleCode.getCode(); - } + return preambleCode.getCode(); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java index 976049601c..69a6342486 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java @@ -1,24 +1,22 @@ package org.lflang.federated.generator; import java.util.stream.Collectors; - import org.lflang.ast.FormattingUtils; import org.lflang.lf.Model; public class FedReactorEmitter { - public FedReactorEmitter() {} + public FedReactorEmitter() {} - /** - * @param federate - * @return - */ - String generateReactorDefinitions(FederateInstance federate) { - return ((Model) federate.instantiation.eContainer().eContainer()) - .getReactors() - .stream() + /** + * @param federate + * @return + */ + String generateReactorDefinitions(FederateInstance federate) { + return ((Model) federate.instantiation.eContainer().eContainer()) + .getReactors().stream() .filter(federate::contains) .map(FormattingUtils.renderer(federate.targetConfig.target)) .collect(Collectors.joining("\n")); - } + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java index af83d1f919..3252f31a39 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java @@ -2,77 +2,69 @@ import static org.lflang.ast.ASTUtils.convertToEmptyListIfNull; +import org.eclipse.emf.ecore.resource.Resource; import org.lflang.ErrorReporter; import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGeneratorContext; -import org.eclipse.emf.ecore.resource.Resource; /** - * Subclass of TargetConfig with a specialized constructor for creating configurations for federates. + * Subclass of TargetConfig with a specialized constructor for creating configurations for + * federates. + * * @author Marten Lohstroh */ public class FedTargetConfig extends TargetConfig { - /** - * Create a configuration for a federate given a main context and the resource in which the class - * of the federate is specified. - * @param context The generator context. - * @param federateResource The resource in which to find the reactor class of the federate. - */ - public FedTargetConfig(LFGeneratorContext context, Resource federateResource) { - // Create target config based on the main .lf file - super( - context.getArgs(), - GeneratorUtils.findTargetDecl(context.getFileConfig().resource), - context.getErrorReporter() - ); + /** + * Create a configuration for a federate given a main context and the resource in which the class + * of the federate is specified. + * + * @param context The generator context. + * @param federateResource The resource in which to find the reactor class of the federate. + */ + public FedTargetConfig(LFGeneratorContext context, Resource federateResource) { + // Create target config based on the main .lf file + super( + context.getArgs(), + GeneratorUtils.findTargetDecl(context.getFileConfig().resource), + context.getErrorReporter()); - mergeImportedConfig( - federateResource, - context.getFileConfig().resource, - context.getErrorReporter() - ); + mergeImportedConfig( + federateResource, context.getFileConfig().resource, context.getErrorReporter()); - clearPropertiesToIgnore(); + clearPropertiesToIgnore(); - ((FedFileConfig)context.getFileConfig()).relativizePaths(this); + ((FedFileConfig) context.getFileConfig()).relativizePaths(this); + } + /** + * If the federate that target configuration applies to is imported, merge target properties + * declared in the file that it was imported from. + * + * @param federateResource The resource where the class of the federate is specified. + * @param mainResource The resource in which the federation (i.e., main reactor) is specified. + * @param errorReporter An error reporter to use when problems are encountered. + */ + private void mergeImportedConfig( + Resource federateResource, Resource mainResource, ErrorReporter errorReporter) { + // If the federate is imported, then update the configuration based on target properties + // in the imported file. + if (!federateResource.equals(mainResource)) { + var importedTargetDecl = GeneratorUtils.findTargetDecl(federateResource); + var targetProperties = importedTargetDecl.getConfig(); + if (targetProperties != null) { + // Merge properties + TargetProperty.update( + this, convertToEmptyListIfNull(targetProperties.getPairs()), errorReporter); + } } + } - /** - * If the federate that target configuration applies to is imported, merge target properties - * declared in the file that it was imported from. - * @param federateResource The resource where the class of the federate is specified. - * @param mainResource The resource in which the federation (i.e., main reactor) is specified. - * @param errorReporter An error reporter to use when problems are encountered. - */ - private void mergeImportedConfig( - Resource federateResource, - Resource mainResource, - ErrorReporter errorReporter) { - // If the federate is imported, then update the configuration based on target properties - // in the imported file. - if (!federateResource.equals(mainResource)) { - var importedTargetDecl = GeneratorUtils.findTargetDecl(federateResource); - var targetProperties = importedTargetDecl.getConfig(); - if (targetProperties != null) { - // Merge properties - TargetProperty.update( - this, - convertToEmptyListIfNull(targetProperties.getPairs()), - errorReporter - ); - } - } - } - - /** - * Method for the removal of things that should not appear in the target config of a federate. - */ - private void clearPropertiesToIgnore() { - this.setByUser.remove(TargetProperty.CLOCK_SYNC); - this.setByUser.remove(TargetProperty.CLOCK_SYNC_OPTIONS); - } + /** Method for the removal of things that should not appear in the target config of a federate. */ + private void clearPropertiesToIgnore() { + this.setByUser.remove(TargetProperty.CLOCK_SYNC); + this.setByUser.remove(TargetProperty.CLOCK_SYNC_OPTIONS); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java index 1616286048..402138f283 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java @@ -1,7 +1,6 @@ package org.lflang.federated.generator; import java.io.IOException; - import org.lflang.ErrorReporter; import org.lflang.TargetProperty; import org.lflang.ast.FormattingUtils; @@ -11,34 +10,25 @@ public class FedTargetEmitter { - String generateTarget( - LFGeneratorContext context, - int numOfFederates, - FederateInstance federate, - FedFileConfig fileConfig, - ErrorReporter errorReporter, - RtiConfig rtiConfig - ) throws IOException { + String generateTarget( + LFGeneratorContext context, + int numOfFederates, + FederateInstance federate, + FedFileConfig fileConfig, + ErrorReporter errorReporter, + RtiConfig rtiConfig) + throws IOException { - // FIXME: First of all, this is not an initialization; there is all sorts of stuff happening - // in the C implementation of this method. Second, true initialization stuff should happen - // when the target config is constructed, not when we're doing code generation. - // See https://issues.lf-lang.org/1667 - FedTargetExtensionFactory.getExtension(federate.targetConfig.target) - .initializeTargetConfig( - context, - numOfFederates, - federate, - fileConfig, - errorReporter, - rtiConfig - ); + // FIXME: First of all, this is not an initialization; there is all sorts of stuff happening + // in the C implementation of this method. Second, true initialization stuff should happen + // when the target config is constructed, not when we're doing code generation. + // See https://issues.lf-lang.org/1667 + FedTargetExtensionFactory.getExtension(federate.targetConfig.target) + .initializeTargetConfig( + context, numOfFederates, federate, fileConfig, errorReporter, rtiConfig); - return FormattingUtils.renderer(federate.targetConfig.target).apply( - TargetProperty.extractTargetDecl( - federate.targetConfig.target, - federate.targetConfig - ) - ); - } + return FormattingUtils.renderer(federate.targetConfig.target) + .apply( + TargetProperty.extractTargetDecl(federate.targetConfig.target, federate.targetConfig)); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedUtils.java b/org.lflang/src/org/lflang/federated/generator/FedUtils.java index dd5ee6a9b3..2970be7c2a 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedUtils.java +++ b/org.lflang/src/org/lflang/federated/generator/FedUtils.java @@ -1,38 +1,24 @@ package org.lflang.federated.generator; -import java.util.List; - import org.lflang.federated.serialization.SupportedSerializers; -import org.lflang.generator.PortInstance; -import org.lflang.generator.ReactionInstance; -import org.lflang.generator.ReactorInstance; import org.lflang.lf.Connection; -import org.lflang.lf.Reaction; -import org.lflang.lf.VarRef; -/** - * A collection of utility methods for the federated generator. - */ +/** A collection of utility methods for the federated generator. */ public class FedUtils { - /** - * Get the serializer for the {@code connection} between {@code srcFederate} and {@code dstFederate}. - */ - public static SupportedSerializers getSerializer( - Connection connection, - FederateInstance srcFederate, - FederateInstance dstFederate - ) { - // Get the serializer - SupportedSerializers serializer = SupportedSerializers.NATIVE; - if (connection.getSerializer() != null) { - serializer = SupportedSerializers.valueOf( - connection.getSerializer().getType().toUpperCase() - ); - } - // Add it to the list of enabled serializers for the source and destination federates - srcFederate.enabledSerializers.add(serializer); - dstFederate.enabledSerializers.add(serializer); - return serializer; + /** + * Get the serializer for the {@code connection} between {@code srcFederate} and {@code + * dstFederate}. + */ + public static SupportedSerializers getSerializer( + Connection connection, FederateInstance srcFederate, FederateInstance dstFederate) { + // Get the serializer + SupportedSerializers serializer = SupportedSerializers.NATIVE; + if (connection.getSerializer() != null) { + serializer = SupportedSerializers.valueOf(connection.getSerializer().getType().toUpperCase()); } - + // Add it to the list of enabled serializers for the source and destination federates + srcFederate.enabledSerializers.add(serializer); + dstFederate.enabledSerializers.add(serializer); + return serializer; + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 0669b4f9dc..ee3c0a46f0 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -1,30 +1,31 @@ -/** Instance of a federate specification. +/** + * Instance of a federate specification. * -Copyright (c) 2020, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ - + *

    Copyright (c) 2020, The University of California at Berkeley. + * + *

    Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + *

    1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + *

    2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided with + * the distribution. + * + *

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ************* + */ package org.lflang.federated.generator; +import com.google.common.base.Objects; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -34,13 +35,11 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.EObject; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.TargetConfig; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.ActionInstance; import org.lflang.generator.PortInstance; @@ -66,599 +65,559 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.VarRef; import org.lflang.lf.Variable; -import com.google.common.base.Objects; - - /** - * Instance of a federate, or marker that no federation has been defined - * (if isSingleton() returns true) FIXME: this comment makes no sense. - * Every top-level reactor (contained - * directly by the main reactor) is a federate, so there will be one - * instance of this class for each top-level reactor. + * Instance of a federate, or marker that no federation has been defined (if isSingleton() returns + * true) FIXME: this comment makes no sense. Every top-level reactor (contained directly by the main + * reactor) is a federate, so there will be one instance of this class for each top-level reactor. * * @author Edward A. Lee * @author Soroush Bateni */ public class FederateInstance { // why does this not extend ReactorInstance? - /** - * Construct a new instance with the specified instantiation of - * of a top-level reactor. The federate will be given the specified - * integer ID. - * @param instantiation The instantiation of a top-level reactor, - * or null if no federation has been defined. - * @param id The federate ID. - * @param bankIndex If instantiation.widthSpec !== null, this gives the bank position. - * @param errorReporter The error reporter - */ - public FederateInstance( - Instantiation instantiation, - int id, - int bankIndex, - TargetConfig targetConfig, - ErrorReporter errorReporter) { - this.instantiation = instantiation; - this.id = id; - this.bankIndex = bankIndex; - this.errorReporter = errorReporter; - this.targetConfig = targetConfig; - - if (instantiation != null) { - // If the instantiation is in a bank, then we have to append - // the bank index to the name. - if (instantiation.getWidthSpec() != null) { - this.name = "federate__" + instantiation.getName() + "__" + bankIndex; - } else { - this.name = "federate__" + instantiation.getName(); - } - } + /** + * Construct a new instance with the specified instantiation of of a top-level reactor. The + * federate will be given the specified integer ID. + * + * @param instantiation The instantiation of a top-level reactor, or null if no federation has + * been defined. + * @param id The federate ID. + * @param bankIndex If instantiation.widthSpec !== null, this gives the bank position. + * @param errorReporter The error reporter + */ + public FederateInstance( + Instantiation instantiation, + int id, + int bankIndex, + TargetConfig targetConfig, + ErrorReporter errorReporter) { + this.instantiation = instantiation; + this.id = id; + this.bankIndex = bankIndex; + this.errorReporter = errorReporter; + this.targetConfig = targetConfig; + + if (instantiation != null) { + // If the instantiation is in a bank, then we have to append + // the bank index to the name. + if (instantiation.getWidthSpec() != null) { + this.name = "federate__" + instantiation.getName() + "__" + bankIndex; + } else { + this.name = "federate__" + instantiation.getName(); + } } - - ///////////////////////////////////////////// - //// Public Fields - - /** - * The position within a bank of reactors for this federate. - * This is 0 if the instantiation is not a bank of reactors. - */ - public int bankIndex = 0; - - /** - * A list of outputs that can be triggered directly or indirectly by physical actions. - */ - public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); - - /** - * The host, if specified using the 'at' keyword. - */ - public String host = "localhost"; - - - /** - * The instantiation of the top-level reactor, or null if there is no federation. - */ - public Instantiation instantiation; - public Instantiation getInstantiation() { - return instantiation; + } + + ///////////////////////////////////////////// + //// Public Fields + + /** + * The position within a bank of reactors for this federate. This is 0 if the instantiation is not + * a bank of reactors. + */ + public int bankIndex = 0; + + /** A list of outputs that can be triggered directly or indirectly by physical actions. */ + public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); + + /** The host, if specified using the 'at' keyword. */ + public String host = "localhost"; + + /** The instantiation of the top-level reactor, or null if there is no federation. */ + public Instantiation instantiation; + + public Instantiation getInstantiation() { + return instantiation; + } + + /** A list of individual connections between federates */ + public Set connections = new HashSet<>(); + + /** + * Map from the federates that this federate receives messages from to the delays on connections + * from that federate. The delay set may include null, meaning that there is a connection from the + * federate instance that has no delay. + */ + public Map> dependsOn = new LinkedHashMap<>(); + + /** The directory, if specified using the 'at' keyword. */ + public String dir = null; + + /** The port, if specified using the 'at' keyword. */ + public int port = 0; + + /** + * Map from the federates that this federate sends messages to to the delays on connections to + * that federate. The delay set may may include null, meaning that there is a connection from the + * federate instance that has no delay. + */ + public Map> sendsTo = new LinkedHashMap<>(); + + /** The user, if specified using the 'at' keyword. */ + public String user = null; + + /** The integer ID of this federate. */ + public int id = 0; + + /** + * The name of this federate instance. This will be the instantiation name, possibly appended with + * "__n", where n is the bank position of this instance if the instantiation is of a bank of + * reactors. + */ + public String name = "Unnamed"; + + /** + * List of networkMessage actions. Each of these handles a message received from another federate + * over the network. The ID of receiving port is simply the position of the action in the list. + * The sending federate needs to specify this ID. + */ + public List networkMessageActions = new ArrayList<>(); + + /** + * A set of federates with which this federate has an inbound connection There will only be one + * physical connection even if federate A has defined multiple physical connections to federate B. + * The message handler on federate A will be responsible for including the appropriate information + * in the message header (such as port ID) to help the receiver distinguish different events. + */ + public Set inboundP2PConnections = new LinkedHashSet<>(); + + /** + * A list of federate with which this federate has an outbound physical connection. There will + * only be one physical connection even if federate A has defined multiple physical connections to + * federate B. The message handler on federate B will be responsible for distinguishing the + * incoming messages by parsing their header and scheduling the appropriate action. + */ + public Set outboundP2PConnections = new LinkedHashSet<>(); + + /** + * A list of triggers for network input control reactions. This is used to trigger all the input + * network control reactions that might be nested in a hierarchy. + */ + public List networkInputControlReactionsTriggers = new ArrayList<>(); + + /** + * The trigger that triggers the output control reaction of this federate. + * + *

    The network output control reactions send a PORT_ABSENT message for a network output port, + * if it is absent at the current tag, to notify all downstream federates that no value will be + * present on the given network port, allowing input control reactions on those federates to stop + * blocking. + */ + public Variable networkOutputControlReactionsTrigger = null; + + /** Indicates whether the federate is remote or local */ + public boolean isRemote = false; + + /** + * List of generated network reactions (network receivers, network input control reactions, + * network senders, and network output control reactions) that belong to this federate instance. + */ + public List networkReactions = new ArrayList<>(); + + /** Parsed target config of the federate. */ + public TargetConfig targetConfig; + + /** Keep a unique list of enabled serializers */ + public HashSet enabledSerializers = new HashSet<>(); + + /** + * Return true if the specified EObject should be included in the code generated for this + * federate. + * + * @param object An {@code EObject} + * @return True if this federate contains the EObject. + */ + public boolean contains(EObject object) { + if (object instanceof Action) { + return contains((Action) object); + } else if (object instanceof Reaction) { + return contains((Reaction) object); + } else if (object instanceof Timer) { + return contains((Timer) object); + } else if (object instanceof ReactorDecl) { + return contains(this.instantiation, (ReactorDecl) object); + } else if (object instanceof Import) { + return contains((Import) object); + } else if (object instanceof Parameter) { + return contains((Parameter) object); + } else if (object instanceof StateVar) { + return true; // FIXME: Should we disallow state vars at the top level? } - - /** - * A list of individual connections between federates - */ - public Set connections = new HashSet<>(); - - /** - * Map from the federates that this federate receives messages from - * to the delays on connections from that federate. The delay set - * may include null, meaning that there is a connection - * from the federate instance that has no delay. - */ - public Map> dependsOn = new LinkedHashMap<>(); - - /** - * The directory, if specified using the 'at' keyword. - */ - public String dir = null; - - /** - * The port, if specified using the 'at' keyword. - */ - public int port = 0; - - /** - * Map from the federates that this federate sends messages to - * to the delays on connections to that federate. The delay set - * may may include null, meaning that there is a connection - * from the federate instance that has no delay. - */ - public Map> sendsTo = new LinkedHashMap<>(); - - /** - * The user, if specified using the 'at' keyword. - */ - public String user = null; - - /** - * The integer ID of this federate. - */ - public int id = 0; - - - /** - * The name of this federate instance. This will be the instantiation - * name, possibly appended with "__n", where n is the bank position of - * this instance if the instantiation is of a bank of reactors. - */ - public String name = "Unnamed"; - - /** - * List of networkMessage actions. Each of these handles a message - * received from another federate over the network. The ID of - * receiving port is simply the position of the action in the list. - * The sending federate needs to specify this ID. - */ - public List networkMessageActions = new ArrayList<>(); - - /** - * A set of federates with which this federate has an inbound connection - * There will only be one physical connection even if federate A has defined multiple - * physical connections to federate B. The message handler on federate A will be - * responsible for including the appropriate information in the message header (such as port ID) - * to help the receiver distinguish different events. - */ - public Set inboundP2PConnections = new LinkedHashSet<>(); - - /** - * A list of federate with which this federate has an outbound physical connection. - * There will only be one physical connection even if federate A has defined multiple - * physical connections to federate B. The message handler on federate B will be - * responsible for distinguishing the incoming messages by parsing their header and - * scheduling the appropriate action. - */ - public Set outboundP2PConnections = new LinkedHashSet<>(); - - /** - * A list of triggers for network input control reactions. This is used to trigger - * all the input network control reactions that might be nested in a hierarchy. - */ - public List networkInputControlReactionsTriggers = new ArrayList<>(); - - /** - * The trigger that triggers the output control reaction of this - * federate. - * - * The network output control reactions send a PORT_ABSENT message for a network output port, - * if it is absent at the current tag, to notify all downstream federates that no value will - * be present on the given network port, allowing input control reactions on those federates - * to stop blocking. - */ - public Variable networkOutputControlReactionsTrigger = null; - - /** - * Indicates whether the federate is remote or local - */ - public boolean isRemote = false; - - /** - * List of generated network reactions (network receivers, - * network input control reactions, network senders, and network output control - * reactions) that belong to this federate instance. - */ - public List networkReactions = new ArrayList<>(); - - /** - * Parsed target config of the federate. - */ - public TargetConfig targetConfig; - - /** - * Keep a unique list of enabled serializers - */ - public HashSet enabledSerializers = new HashSet<>(); - - /** - * Return true if the specified EObject should be included in the code - * generated for this federate. - * - * @param object An {@code EObject} - * @return True if this federate contains the EObject. - */ - public boolean contains(EObject object) { - if (object instanceof Action) { - return contains((Action)object); - } else if (object instanceof Reaction) { - return contains((Reaction)object); - } else if (object instanceof Timer) { - return contains((Timer)object); - } else if (object instanceof ReactorDecl) { - return contains(this.instantiation, (ReactorDecl)object); - } else if (object instanceof Import) { - return contains((Import)object); - } else if (object instanceof Parameter) { - return contains((Parameter)object); - } else if (object instanceof StateVar) { - return true; // FIXME: Should we disallow state vars at the top level? - } - throw new UnsupportedOperationException("EObject class "+object.eClass().getName()+" not supported."); + throw new UnsupportedOperationException( + "EObject class " + object.eClass().getName() + " not supported."); + } + + /** + * Return true if the specified reactor belongs to this federate. + * + * @param instantiation The instantiation to look inside + * @param reactor The reactor declaration to find + */ + private boolean contains(Instantiation instantiation, ReactorDecl reactor) { + if (instantiation.getReactorClass().equals(ASTUtils.toDefinition(reactor))) { + return true; } - /** - * Return true if the specified reactor belongs to this federate. - * @param instantiation The instantiation to look inside - * @param reactor The reactor declaration to find - */ - private boolean contains( - Instantiation instantiation, - ReactorDecl reactor - ) { - if (instantiation.getReactorClass().equals(ASTUtils.toDefinition(reactor))) { - return true; - } - - boolean instantiationsCheck = false; - // For a federate, we don't need to look inside imported reactors. - if (instantiation.getReactorClass() instanceof Reactor reactorDef) { - for (Instantiation child : reactorDef.getInstantiations()) { - instantiationsCheck |= contains(child, reactor); - } - } - - return instantiationsCheck; + boolean instantiationsCheck = false; + // For a federate, we don't need to look inside imported reactors. + if (instantiation.getReactorClass() instanceof Reactor reactorDef) { + for (Instantiation child : reactorDef.getInstantiations()) { + instantiationsCheck |= contains(child, reactor); + } } - /** - * Return true if the specified import should be included in the code generated for this federate. - * @param imp The import - */ - private boolean contains(Import imp) { - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (contains(reactor)) { - return true; - } - } - return false; + return instantiationsCheck; + } + + /** + * Return true if the specified import should be included in the code generated for this federate. + * + * @param imp The import + */ + private boolean contains(Import imp) { + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (contains(reactor)) { + return true; + } } - - /** - * Return true if the specified parameter should be included in the code generated for this federate. - * @param param The parameter - */ - private boolean contains(Parameter param) { - boolean returnValue = false; - // Check if param is referenced in this federate's instantiation - returnValue = instantiation.getParameters().stream().anyMatch( - assignment -> assignment.getRhs() - .getExprs() - .stream() - .filter( - it -> it instanceof ParameterReference - ) - .map(it -> ((ParameterReference) it).getParameter()) - .toList() - .contains(param) - ); - // If there are any user-defined top-level reactions, they could access - // the parameters, so we need to include the parameter. - var topLevelUserDefinedReactions = ((Reactor) instantiation.eContainer()) - .getReactions().stream().filter( - r -> !networkReactions.contains(r) && contains(r) - ).collect(Collectors.toCollection(ArrayList::new)); - returnValue |= !topLevelUserDefinedReactions.isEmpty(); - return returnValue; - } - - /** - * Return true if the specified action should be included in the code generated - * for this federate. This means that either the action is used as a trigger, - * a source, or an effect in a top-level reaction that belongs to this federate. - * This returns true if the program is not federated. - * - * @param action The action - * @return True if this federate contains the action. - */ - private boolean contains(Action action) { - Reactor reactor = ASTUtils.getEnclosingReactor(action); - - // If the action is used as a trigger, a source, or an effect for a top-level reaction - // that belongs to this federate, then generate it. - for (Reaction react : ASTUtils.allReactions(reactor)) { - if (contains(react)) { - // Look in triggers - for (TriggerRef trigger : convertToEmptyListIfNull(react.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (Objects.equal(triggerAsVarRef.getVariable(), action)) { - return true; - } - } - } - // Look in sources - for (VarRef source : convertToEmptyListIfNull(react.getSources())) { - if (Objects.equal(source.getVariable(), action)) { - return true; - } - } - // Look in effects - for (VarRef effect : convertToEmptyListIfNull(react.getEffects())) { - if (Objects.equal(effect.getVariable(), action)) { - return true; - } - } + return false; + } + + /** + * Return true if the specified parameter should be included in the code generated for this + * federate. + * + * @param param The parameter + */ + private boolean contains(Parameter param) { + boolean returnValue = false; + // Check if param is referenced in this federate's instantiation + returnValue = + instantiation.getParameters().stream() + .anyMatch( + assignment -> + assignment.getRhs().getExprs().stream() + .filter(it -> it instanceof ParameterReference) + .map(it -> ((ParameterReference) it).getParameter()) + .toList() + .contains(param)); + // If there are any user-defined top-level reactions, they could access + // the parameters, so we need to include the parameter. + var topLevelUserDefinedReactions = + ((Reactor) instantiation.eContainer()) + .getReactions().stream() + .filter(r -> !networkReactions.contains(r) && contains(r)) + .collect(Collectors.toCollection(ArrayList::new)); + returnValue |= !topLevelUserDefinedReactions.isEmpty(); + return returnValue; + } + + /** + * Return true if the specified action should be included in the code generated for this federate. + * This means that either the action is used as a trigger, a source, or an effect in a top-level + * reaction that belongs to this federate. This returns true if the program is not federated. + * + * @param action The action + * @return True if this federate contains the action. + */ + private boolean contains(Action action) { + Reactor reactor = ASTUtils.getEnclosingReactor(action); + + // If the action is used as a trigger, a source, or an effect for a top-level reaction + // that belongs to this federate, then generate it. + for (Reaction react : ASTUtils.allReactions(reactor)) { + if (contains(react)) { + // Look in triggers + for (TriggerRef trigger : convertToEmptyListIfNull(react.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (Objects.equal(triggerAsVarRef.getVariable(), action)) { + return true; } + } } - - return false; - } - - /** - * Return true if the specified reaction should be included in the code generated for this - * federate at the top-level. This means that if the reaction is triggered by or - * sends data to a port of a contained reactor, then that reaction - * is in the federate. Otherwise, return false. - * - * NOTE: This method assumes that it will not be called with reaction arguments - * that are within other federates. It should only be called on reactions that are - * either at the top level or within this federate. For this reason, for any reaction - * not at the top level, it returns true. - * - * @param reaction The reaction. - */ - private boolean contains(Reaction reaction) { - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - - assert reactor != null; - if (!reactor.getReactions().contains(reaction)) return false; - - if (networkReactions.contains(reaction)) { - // Reaction is a network reaction that belongs to this federate + // Look in sources + for (VarRef source : convertToEmptyListIfNull(react.getSources())) { + if (Objects.equal(source.getVariable(), action)) { return true; + } } - - int reactionBankIndex = FedASTUtils.getReactionBankIndex(reaction); - if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { - return false; - } - - // If this has been called before, then the result of the - // following check is cached. - if (excludeReactions != null) { - return !excludeReactions.contains(reaction); + // Look in effects + for (VarRef effect : convertToEmptyListIfNull(react.getEffects())) { + if (Objects.equal(effect.getVariable(), action)) { + return true; + } } + } + } - indexExcludedTopLevelReactions(reactor); - - return !excludeReactions.contains(reaction); + return false; + } + + /** + * Return true if the specified reaction should be included in the code generated for this + * federate at the top-level. This means that if the reaction is triggered by or sends data to a + * port of a contained reactor, then that reaction is in the federate. Otherwise, return false. + * + *

    NOTE: This method assumes that it will not be called with reaction arguments that are within + * other federates. It should only be called on reactions that are either at the top level or + * within this federate. For this reason, for any reaction not at the top level, it returns true. + * + * @param reaction The reaction. + */ + private boolean contains(Reaction reaction) { + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + + assert reactor != null; + if (!reactor.getReactions().contains(reaction)) return false; + + if (networkReactions.contains(reaction)) { + // Reaction is a network reaction that belongs to this federate + return true; } - /** - * Return true if the specified timer should be included in the code generated - * for the federate. This means that the timer is used as a trigger - * in a top-level reaction that belongs to this federate. - * This also returns true if the program is not federated. - * - * @return True if this federate contains the action in the specified reactor - */ - private boolean contains(Timer timer) { - Reactor reactor = ASTUtils.getEnclosingReactor(timer); - - // If the action is used as a trigger, a source, or an effect for a top-level reaction - // that belongs to this federate, then generate it. - for (Reaction r : ASTUtils.allReactions(reactor)) { - if (contains(r)) { - // Look in triggers - for (TriggerRef trigger : convertToEmptyListIfNull(r.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (Objects.equal(triggerAsVarRef.getVariable(), timer)) { - return true; - } - } - } - } - } + int reactionBankIndex = FedASTUtils.getReactionBankIndex(reaction); + if (reactionBankIndex >= 0 && this.bankIndex >= 0 && reactionBankIndex != this.bankIndex) { + return false; + } - return false; + // If this has been called before, then the result of the + // following check is cached. + if (excludeReactions != null) { + return !excludeReactions.contains(reaction); } - /** - * Return true if the specified reactor instance or any parent - * reactor instance is contained by this federate. - * If the specified instance is the top-level reactor, return true - * (the top-level reactor belongs to all federates). - * If this federate instance is a singleton, then return true if the - * instance is non null. - * - * NOTE: If the instance is bank within the top level, then this - * returns true even though only one of the bank members is in the federate. - * - * @param instance The reactor instance. - * @return True if this federate contains the reactor instance - */ - public boolean contains(ReactorInstance instance) { - if (instance.getParent() == null) { - return true; // Top-level reactor - } - // Start with this instance, then check its parents. - ReactorInstance i = instance; - while (i != null) { - if (i.getDefinition() == instantiation) { - return true; + indexExcludedTopLevelReactions(reactor); + + return !excludeReactions.contains(reaction); + } + + /** + * Return true if the specified timer should be included in the code generated for the federate. + * This means that the timer is used as a trigger in a top-level reaction that belongs to this + * federate. This also returns true if the program is not federated. + * + * @return True if this federate contains the action in the specified reactor + */ + private boolean contains(Timer timer) { + Reactor reactor = ASTUtils.getEnclosingReactor(timer); + + // If the action is used as a trigger, a source, or an effect for a top-level reaction + // that belongs to this federate, then generate it. + for (Reaction r : ASTUtils.allReactions(reactor)) { + if (contains(r)) { + // Look in triggers + for (TriggerRef trigger : convertToEmptyListIfNull(r.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (Objects.equal(triggerAsVarRef.getVariable(), timer)) { + return true; } - i = i.getParent(); + } } - return false; + } } - /** - * Build an index of reactions at the top-level (in the - * federatedReactor) that don't belong to this federate - * instance. This index is put in the excludeReactions - * class variable. - * - * @param federatedReactor The top-level federated reactor - */ - private void indexExcludedTopLevelReactions(Reactor federatedReactor) { - boolean inFederate = false; - if (excludeReactions != null) { - throw new IllegalStateException("The index for excluded reactions at the top level is already built."); - } + return false; + } + + /** + * Return true if the specified reactor instance or any parent reactor instance is contained by + * this federate. If the specified instance is the top-level reactor, return true (the top-level + * reactor belongs to all federates). If this federate instance is a singleton, then return true + * if the instance is non null. + * + *

    NOTE: If the instance is bank within the top level, then this returns true even though only + * one of the bank members is in the federate. + * + * @param instance The reactor instance. + * @return True if this federate contains the reactor instance + */ + public boolean contains(ReactorInstance instance) { + if (instance.getParent() == null) { + return true; // Top-level reactor + } + // Start with this instance, then check its parents. + ReactorInstance i = instance; + while (i != null) { + if (i.getDefinition() == instantiation) { + return true; + } + i = i.getParent(); + } + return false; + } + + /** + * Build an index of reactions at the top-level (in the federatedReactor) that don't belong to + * this federate instance. This index is put in the excludeReactions class variable. + * + * @param federatedReactor The top-level federated reactor + */ + private void indexExcludedTopLevelReactions(Reactor federatedReactor) { + boolean inFederate = false; + if (excludeReactions != null) { + throw new IllegalStateException( + "The index for excluded reactions at the top level is already built."); + } - excludeReactions = new LinkedHashSet<>(); - - // Construct the set of excluded reactions for this federate. - // If a reaction is a network reaction that belongs to this federate, we - // don't need to perform this analysis. - Iterable reactions = ASTUtils.allReactions(federatedReactor).stream().filter(it -> !networkReactions.contains(it)).collect(Collectors.toList()); - for (Reaction react : reactions) { - // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react - // signature that are ports that reference federates. - // We then later check that all these VarRefs reference this federate. If not, we will add this - // react to the list of reactions that have to be excluded (note that mixing VarRefs from - // different federates is not allowed). - List allVarRefsReferencingFederates = new ArrayList<>(); - // Add all the triggers that are outputs - Stream triggersAsVarRef = react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); - allVarRefsReferencingFederates.addAll( - triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList() - ); - // Add all the sources that are outputs - allVarRefsReferencingFederates.addAll( - react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList() - ); - // Add all the effects that are inputs - allVarRefsReferencingFederates.addAll( - react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList() - ); - inFederate = containsAllVarRefs(allVarRefsReferencingFederates); - if (!inFederate) { - excludeReactions.add(react); - } + excludeReactions = new LinkedHashSet<>(); + + // Construct the set of excluded reactions for this federate. + // If a reaction is a network reaction that belongs to this federate, we + // don't need to perform this analysis. + Iterable reactions = + ASTUtils.allReactions(federatedReactor).stream() + .filter(it -> !networkReactions.contains(it)) + .collect(Collectors.toList()); + for (Reaction react : reactions) { + // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react + // signature that are ports that reference federates. + // We then later check that all these VarRefs reference this federate. If not, we will add + // this + // react to the list of reactions that have to be excluded (note that mixing VarRefs from + // different federates is not allowed). + List allVarRefsReferencingFederates = new ArrayList<>(); + // Add all the triggers that are outputs + Stream triggersAsVarRef = + react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); + allVarRefsReferencingFederates.addAll( + triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList()); + // Add all the sources that are outputs + allVarRefsReferencingFederates.addAll( + react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList()); + // Add all the effects that are inputs + allVarRefsReferencingFederates.addAll( + react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList()); + inFederate = containsAllVarRefs(allVarRefsReferencingFederates); + if (!inFederate) { + excludeReactions.add(react); + } + } + } + + /** + * Return true if all members of 'varRefs' belong to this federate. + * + *

    As a convenience measure, if some members of 'varRefs' are from different federates, also + * report an error. + * + * @param varRefs A collection of VarRefs + */ + private boolean containsAllVarRefs(Iterable varRefs) { + var referencesFederate = false; + var inFederate = true; + for (VarRef varRef : varRefs) { + if (varRef.getContainer() == this.instantiation) { + referencesFederate = true; + } else { + if (referencesFederate) { + errorReporter.reportError( + varRef, + "Mixed triggers and effects from" + " different federates. This is not permitted"); } + inFederate = false; + } } - - /** - * Return true if all members of 'varRefs' belong to this federate. - * - * As a convenience measure, if some members of 'varRefs' are from - * different federates, also report an error. - * - * @param varRefs A collection of VarRefs - */ - private boolean containsAllVarRefs(Iterable varRefs) { - var referencesFederate = false; - var inFederate = true; - for (VarRef varRef : varRefs) { - if (varRef.getContainer() == this.instantiation) { - referencesFederate = true; - } else { - if (referencesFederate) { - errorReporter.reportError(varRef, - "Mixed triggers and effects from" - + - " different federates. This is not permitted"); - } - inFederate = false; - } + return inFederate; + } + + /** + * Find output ports that are connected to a physical action trigger upstream in the same reactor. + * Return a list of such outputs paired with the minimum delay from the nearest physical action. + * + * @param instance The reactor instance containing the output ports + * @return A LinkedHashMap + */ + public LinkedHashMap findOutputsConnectedToPhysicalActions( + ReactorInstance instance) { + LinkedHashMap physicalActionToOutputMinDelay = new LinkedHashMap<>(); + // Find reactions that write to the output port of the reactor + for (PortInstance output : instance.outputs) { + for (ReactionInstance reaction : output.getDependsOnReactions()) { + TimeValue minDelay = findNearestPhysicalActionTrigger(reaction); + if (!Objects.equal(minDelay, TimeValue.MAX_VALUE)) { + physicalActionToOutputMinDelay.put((Output) output.getDefinition(), minDelay); } - return inFederate; + } } - - /** - * Find output ports that are connected to a physical action trigger upstream - * in the same reactor. Return a list of such outputs paired with the minimum delay - * from the nearest physical action. - * @param instance The reactor instance containing the output ports - * @return A LinkedHashMap - */ - public LinkedHashMap findOutputsConnectedToPhysicalActions(ReactorInstance instance) { - LinkedHashMap physicalActionToOutputMinDelay = new LinkedHashMap<>(); - // Find reactions that write to the output port of the reactor - for (PortInstance output : instance.outputs) { - for (ReactionInstance reaction : output.getDependsOnReactions()) { - TimeValue minDelay = findNearestPhysicalActionTrigger(reaction); - if (!Objects.equal(minDelay, TimeValue.MAX_VALUE)) { - physicalActionToOutputMinDelay.put((Output) output.getDefinition(), minDelay); - } + return physicalActionToOutputMinDelay; + } + + /** + * Return a list of federates that are upstream of this federate and have a zero-delay (direct) + * connection to this federate. + */ + public List getZeroDelayImmediateUpstreamFederates() { + return this.dependsOn.entrySet().stream() + .filter(e -> e.getValue().contains(null)) + .map(Map.Entry::getKey) + .toList(); + } + + @Override + public String toString() { + return "Federate " + + id + + ": " + + ((instantiation != null) ? instantiation.getName() : "no name"); + } + + ///////////////////////////////////////////// + //// Private Fields + + /** Cached result of analysis of which reactions to exclude from main. */ + private Set excludeReactions = null; + + /** An error reporter */ + private final ErrorReporter errorReporter; + + /** + * Find the nearest (shortest) path to a physical action trigger from this 'reaction' in terms of + * minimum delay. + * + * @param reaction The reaction to start with + * @return The minimum delay found to the nearest physical action and TimeValue.MAX_VALUE + * otherwise + */ + public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { + TimeValue minDelay = TimeValue.MAX_VALUE; + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.getDefinition() instanceof Action action) { + ActionInstance actionInstance = (ActionInstance) trigger; + if (action.getOrigin() == ActionOrigin.PHYSICAL) { + if (actionInstance.getMinDelay().isEarlierThan(minDelay)) { + minDelay = actionInstance.getMinDelay(); + } + } else if (action.getOrigin() == ActionOrigin.LOGICAL) { + // Logical action + // Follow it upstream inside the reactor + for (ReactionInstance uReaction : actionInstance.getDependsOnReactions()) { + // Avoid a loop + if (!Objects.equal(uReaction, reaction)) { + TimeValue uMinDelay = + actionInstance.getMinDelay().add(findNearestPhysicalActionTrigger(uReaction)); + if (uMinDelay.isEarlierThan(minDelay)) { + minDelay = uMinDelay; + } } + } } - return physicalActionToOutputMinDelay; - } - - /** - * Return a list of federates that are upstream of this federate and have a - * zero-delay (direct) connection to this federate. - */ - public List getZeroDelayImmediateUpstreamFederates() { - return this.dependsOn.entrySet() - .stream() - .filter(e -> e.getValue().contains(null)) - .map(Map.Entry::getKey).toList(); - } - @Override - public String toString() { - return "Federate " + id + ": " - + ((instantiation != null) ? instantiation.getName() : "no name"); - } - - ///////////////////////////////////////////// - //// Private Fields - - /** - * Cached result of analysis of which reactions to exclude from main. - */ - private Set excludeReactions = null; - - /** - * An error reporter - */ - private final ErrorReporter errorReporter; - - /** - * Find the nearest (shortest) path to a physical action trigger from this - * 'reaction' in terms of minimum delay. - * - * @param reaction The reaction to start with - * @return The minimum delay found to the nearest physical action and - * TimeValue.MAX_VALUE otherwise - */ - public TimeValue findNearestPhysicalActionTrigger(ReactionInstance reaction) { - TimeValue minDelay = TimeValue.MAX_VALUE; - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.getDefinition() instanceof Action action) { - ActionInstance actionInstance = (ActionInstance) trigger; - if (action.getOrigin() == ActionOrigin.PHYSICAL) { - if (actionInstance.getMinDelay().isEarlierThan(minDelay)) { - minDelay = actionInstance.getMinDelay(); - } - } else if (action.getOrigin() == ActionOrigin.LOGICAL) { - // Logical action - // Follow it upstream inside the reactor - for (ReactionInstance uReaction: actionInstance.getDependsOnReactions()) { - // Avoid a loop - if (!Objects.equal(uReaction, reaction)) { - TimeValue uMinDelay = actionInstance.getMinDelay().add(findNearestPhysicalActionTrigger(uReaction)); - if (uMinDelay.isEarlierThan(minDelay)) { - minDelay = uMinDelay; - } - } - } - } - - } else if (trigger.getDefinition() instanceof Output) { - // Outputs of contained reactions - PortInstance outputInstance = (PortInstance) trigger; - for (ReactionInstance uReaction: outputInstance.getDependsOnReactions()) { - TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); - if (uMinDelay.isEarlierThan(minDelay)) { - minDelay = uMinDelay; - } - } - } + } else if (trigger.getDefinition() instanceof Output) { + // Outputs of contained reactions + PortInstance outputInstance = (PortInstance) trigger; + for (ReactionInstance uReaction : outputInstance.getDependsOnReactions()) { + TimeValue uMinDelay = findNearestPhysicalActionTrigger(uReaction); + if (uMinDelay.isEarlierThan(minDelay)) { + minDelay = uMinDelay; + } } - return minDelay; + } } + return minDelay; + } - // TODO: Put this function into a utils file instead - private List convertToEmptyListIfNull(List list) { - return list == null ? new ArrayList<>() : list; - } + // TODO: Put this function into a utils file instead + private List convertToEmptyListIfNull(List list) { + return list == null ? new ArrayList<>() : list; + } } diff --git a/org.lflang/src/org/lflang/federated/generator/LineAdjustingErrorReporter.java b/org.lflang/src/org/lflang/federated/generator/LineAdjustingErrorReporter.java index f483c228db..aa2f49b6da 100644 --- a/org.lflang/src/org/lflang/federated/generator/LineAdjustingErrorReporter.java +++ b/org.lflang/src/org/lflang/federated/generator/LineAdjustingErrorReporter.java @@ -2,10 +2,8 @@ import java.nio.file.Path; import java.util.Map; - import org.eclipse.emf.ecore.EObject; import org.eclipse.lsp4j.DiagnosticSeverity; - import org.lflang.ErrorReporter; import org.lflang.generator.CodeMap; import org.lflang.generator.Position; @@ -13,116 +11,102 @@ public class LineAdjustingErrorReporter implements ErrorReporter { - private final ErrorReporter parent; - private final Map codeMapMap; - - public LineAdjustingErrorReporter(ErrorReporter parent, Map codeMapMap) { - this.parent = parent; - this.codeMapMap = codeMapMap; - } - - @Override - public String reportError(String message) { - return parent.reportError(message); - } - - @Override - public String reportWarning(String message) { - return parent.reportWarning(message); - } - - @Override - public String reportInfo(String message) { - return parent.reportInfo(message); - } - - @Override - public String reportError(EObject object, String message) { - return parent.reportError(object, message); - } - - @Override - public String reportWarning(EObject object, String message) { - return parent.reportWarning(object, message); - } - - @Override - public String reportInfo(EObject object, String message) { - return parent.reportInfo(object, message); - } - - @Override - public String reportError(Path file, Integer line, String message) { - return report(file, line, message, DiagnosticSeverity.Error); - } - - @Override - public String reportWarning(Path file, Integer line, String message) { - return report(file, line, message, DiagnosticSeverity.Warning); - } - - @Override - public String reportInfo(Path file, Integer line, String message) { - return report(file, line, message, DiagnosticSeverity.Information); - } - - private String report(Path file, Integer line, String message, DiagnosticSeverity severity) { - if (line == null) return report(file, severity, message); - var position = Position.fromOneBased(line, Integer.MAX_VALUE); - return report( - file, - severity, - message, - Position.fromZeroBased(position.getZeroBasedLine(), 0), - position - ); - } - - @Override - public String report(Path file, DiagnosticSeverity severity, String message) { - return ErrorReporter.super.report(file, severity, message); - } - - @Override - public String report(Path file, DiagnosticSeverity severity, String message, int line) { - return ErrorReporter.super.report(file, severity, message, line); - } - - @Override - public String report( - Path file, - DiagnosticSeverity severity, - String message, - Position startPos, - Position endPos - ) { - String ret = null; - if (codeMapMap.containsKey(file)) { - var relevantMap = codeMapMap.get(file); - for (Path lfSource : relevantMap.lfSourcePaths()) { - var adjustedRange = relevantMap.adjusted( - lfSource, - new Range(startPos, endPos) - ); - ret = parent.report( - lfSource, - severity, - message, - adjustedRange.getStartInclusive().equals(Position.ORIGIN) ? - Position.fromZeroBased( - adjustedRange.getEndExclusive().getZeroBasedLine(), - 0 - ) : adjustedRange.getStartInclusive(), - adjustedRange.getEndExclusive() - ); - } - } - if (ret == null) return severity == DiagnosticSeverity.Error ? reportError(message) : reportWarning(message); - return ret; - } - - @Override - public boolean getErrorsOccurred() { - return parent.getErrorsOccurred(); + private final ErrorReporter parent; + private final Map codeMapMap; + + public LineAdjustingErrorReporter(ErrorReporter parent, Map codeMapMap) { + this.parent = parent; + this.codeMapMap = codeMapMap; + } + + @Override + public String reportError(String message) { + return parent.reportError(message); + } + + @Override + public String reportWarning(String message) { + return parent.reportWarning(message); + } + + @Override + public String reportInfo(String message) { + return parent.reportInfo(message); + } + + @Override + public String reportError(EObject object, String message) { + return parent.reportError(object, message); + } + + @Override + public String reportWarning(EObject object, String message) { + return parent.reportWarning(object, message); + } + + @Override + public String reportInfo(EObject object, String message) { + return parent.reportInfo(object, message); + } + + @Override + public String reportError(Path file, Integer line, String message) { + return report(file, line, message, DiagnosticSeverity.Error); + } + + @Override + public String reportWarning(Path file, Integer line, String message) { + return report(file, line, message, DiagnosticSeverity.Warning); + } + + @Override + public String reportInfo(Path file, Integer line, String message) { + return report(file, line, message, DiagnosticSeverity.Information); + } + + private String report(Path file, Integer line, String message, DiagnosticSeverity severity) { + if (line == null) return report(file, severity, message); + var position = Position.fromOneBased(line, Integer.MAX_VALUE); + return report( + file, severity, message, Position.fromZeroBased(position.getZeroBasedLine(), 0), position); + } + + @Override + public String report(Path file, DiagnosticSeverity severity, String message) { + return ErrorReporter.super.report(file, severity, message); + } + + @Override + public String report(Path file, DiagnosticSeverity severity, String message, int line) { + return ErrorReporter.super.report(file, severity, message, line); + } + + @Override + public String report( + Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { + String ret = null; + if (codeMapMap.containsKey(file)) { + var relevantMap = codeMapMap.get(file); + for (Path lfSource : relevantMap.lfSourcePaths()) { + var adjustedRange = relevantMap.adjusted(lfSource, new Range(startPos, endPos)); + ret = + parent.report( + lfSource, + severity, + message, + adjustedRange.getStartInclusive().equals(Position.ORIGIN) + ? Position.fromZeroBased(adjustedRange.getEndExclusive().getZeroBasedLine(), 0) + : adjustedRange.getStartInclusive(), + adjustedRange.getEndExclusive()); + } } + if (ret == null) + return severity == DiagnosticSeverity.Error ? reportError(message) : reportWarning(message); + return ret; + } + + @Override + public boolean getErrorsOccurred() { + return parent.getErrorsOccurred(); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/SynchronizedErrorReporter.java b/org.lflang/src/org/lflang/federated/generator/SynchronizedErrorReporter.java index 571d2de5c7..08c47c4cd3 100644 --- a/org.lflang/src/org/lflang/federated/generator/SynchronizedErrorReporter.java +++ b/org.lflang/src/org/lflang/federated/generator/SynchronizedErrorReporter.java @@ -1,83 +1,83 @@ package org.lflang.federated.generator; import java.nio.file.Path; - import org.eclipse.emf.ecore.EObject; import org.eclipse.lsp4j.DiagnosticSeverity; - import org.lflang.ErrorReporter; import org.lflang.generator.Position; public class SynchronizedErrorReporter implements ErrorReporter { - private final ErrorReporter parent; - - public SynchronizedErrorReporter(ErrorReporter parent) { - this.parent = parent; - } - - @Override - public synchronized String reportError(String message) { - return parent.reportError(message); - } - - @Override - public synchronized String reportWarning(String message) { - return parent.reportWarning(message); - } - - @Override - public synchronized String reportInfo(String message) { - return parent.reportInfo(message); - } - - @Override - public synchronized String reportError(EObject object, String message) { - return parent.reportError(object, message); - } - - @Override - public synchronized String reportWarning(EObject object, String message) { - return parent.reportWarning(object, message); - } - - @Override - public synchronized String reportInfo(EObject object, String message) { - return parent.reportInfo(object, message); - } - - @Override - public synchronized String reportError(Path file, Integer line, String message) { - return parent.reportError(file, line, message); - } - - @Override - public synchronized String reportWarning(Path file, Integer line, String message) { - return parent.reportWarning(file, line, message); - } - - @Override - public synchronized String reportInfo(Path file, Integer line, String message) { - return parent.reportInfo(file, line, message); - } - - @Override - public synchronized String report(Path file, DiagnosticSeverity severity, String message) { - return parent.report(file, severity, message); - } - - @Override - public synchronized String report(Path file, DiagnosticSeverity severity, String message, int line) { - return parent.report(file, severity, message, line); - } - - @Override - public synchronized String report(Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { - return parent.report(file, severity, message, startPos, endPos); - } - - @Override - public synchronized boolean getErrorsOccurred() { - return parent.getErrorsOccurred(); - } + private final ErrorReporter parent; + + public SynchronizedErrorReporter(ErrorReporter parent) { + this.parent = parent; + } + + @Override + public synchronized String reportError(String message) { + return parent.reportError(message); + } + + @Override + public synchronized String reportWarning(String message) { + return parent.reportWarning(message); + } + + @Override + public synchronized String reportInfo(String message) { + return parent.reportInfo(message); + } + + @Override + public synchronized String reportError(EObject object, String message) { + return parent.reportError(object, message); + } + + @Override + public synchronized String reportWarning(EObject object, String message) { + return parent.reportWarning(object, message); + } + + @Override + public synchronized String reportInfo(EObject object, String message) { + return parent.reportInfo(object, message); + } + + @Override + public synchronized String reportError(Path file, Integer line, String message) { + return parent.reportError(file, line, message); + } + + @Override + public synchronized String reportWarning(Path file, Integer line, String message) { + return parent.reportWarning(file, line, message); + } + + @Override + public synchronized String reportInfo(Path file, Integer line, String message) { + return parent.reportInfo(file, line, message); + } + + @Override + public synchronized String report(Path file, DiagnosticSeverity severity, String message) { + return parent.report(file, severity, message); + } + + @Override + public synchronized String report( + Path file, DiagnosticSeverity severity, String message, int line) { + return parent.report(file, severity, message, line); + } + + @Override + public synchronized String report( + Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { + return parent.report(file, severity, message, startPos, endPos); + } + + @Override + public synchronized boolean getErrorsOccurred() { + return parent.getErrorsOccurred(); + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java index c1a01bfa47..47345af147 100644 --- a/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java @@ -4,57 +4,48 @@ import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; -/** - * A collection of methods used for building target code for federates. - */ +/** A collection of methods used for building target code for federates. */ public abstract class BuildConfig { - /** - * The federate that this configuration applies to. - */ - protected final FederateInstance federate; - - /** - * An error reporter to report problems. - */ - protected final ErrorReporter errorReporter; - - /** - * The file configuration of the federation that the federate belongs to. - */ - protected final FedFileConfig fileConfig; - - /** - * Create a new build configuration. - * - * @param federate The federate that this configuration applies to. - * @param fileConfig The file configuration of the federation that the federate belongs to. - * @param errorReporter An error reporter to report problems. - */ - public BuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - this.errorReporter = errorReporter; - this.federate = federate; - this.fileConfig = fileConfig; - } - - /** - * Return the compile command for the federate that this build configuration belongs to. - */ - public String compileCommand() { - throw new UnsupportedOperationException(); - } - - /** - * Return the command that will execute the federate that this build configuration belongs to - * locally, assuming that the current directory is the top-level project folder. - */ - public abstract String localExecuteCommand(); - - /** - * Return the command that will execute the federate that this build configuration belongs to - * remotely, assuming that the current directory is the top-level project folder. - */ - public String remoteExecuteCommand() { - throw new UnsupportedOperationException(); - } + /** The federate that this configuration applies to. */ + protected final FederateInstance federate; + + /** An error reporter to report problems. */ + protected final ErrorReporter errorReporter; + + /** The file configuration of the federation that the federate belongs to. */ + protected final FedFileConfig fileConfig; + + /** + * Create a new build configuration. + * + * @param federate The federate that this configuration applies to. + * @param fileConfig The file configuration of the federation that the federate belongs to. + * @param errorReporter An error reporter to report problems. + */ + public BuildConfig( + FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + this.errorReporter = errorReporter; + this.federate = federate; + this.fileConfig = fileConfig; + } + + /** Return the compile command for the federate that this build configuration belongs to. */ + public String compileCommand() { + throw new UnsupportedOperationException(); + } + + /** + * Return the command that will execute the federate that this build configuration belongs to + * locally, assuming that the current directory is the top-level project folder. + */ + public abstract String localExecuteCommand(); + + /** + * Return the command that will execute the federate that this build configuration belongs to + * remotely, assuming that the current directory is the top-level project folder. + */ + public String remoteExecuteCommand() { + throw new UnsupportedOperationException(); + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java index bd88a719b4..d77ea3988c 100644 --- a/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2019-2021, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -26,51 +26,51 @@ package org.lflang.federated.launcher; import java.io.File; - import org.lflang.ErrorReporter; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.c.CCompiler; /** - * Utility class that can be used to create a launcher for federated LF programs - * that are written in C. + * Utility class that can be used to create a launcher for federated LF programs that are written in + * C. * * @author Soroush Bateni * @author Marten Lohstroh */ public class CBuildConfig extends BuildConfig { - public CBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - super(federate, fileConfig, errorReporter); - } + public CBuildConfig( + FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + super(federate, fileConfig, errorReporter); + } - @Override - public String compileCommand() { + @Override + public String compileCommand() { - String commandToReturn = ""; - // FIXME: Hack to add platform support only for linux systems. - // We need to fix the CMake build command for remote federates. - String linuxPlatformSupport = "core" + File.separator + "platform" + File.separator + "lf_linux_support.c"; - if (!federate.targetConfig.compileAdditionalSources.contains(linuxPlatformSupport)) { - federate.targetConfig.compileAdditionalSources.add(linuxPlatformSupport); - } - CCompiler cCompiler= new CCompiler(federate.targetConfig, fileConfig, errorReporter, false); - commandToReturn = String.join(" ", - cCompiler.compileCCommand( - fileConfig.name+"_"+federate.name, - false - ).toString()); - return commandToReturn; + String commandToReturn = ""; + // FIXME: Hack to add platform support only for linux systems. + // We need to fix the CMake build command for remote federates. + String linuxPlatformSupport = + "core" + File.separator + "platform" + File.separator + "lf_linux_support.c"; + if (!federate.targetConfig.compileAdditionalSources.contains(linuxPlatformSupport)) { + federate.targetConfig.compileAdditionalSources.add(linuxPlatformSupport); } + CCompiler cCompiler = new CCompiler(federate.targetConfig, fileConfig, errorReporter, false); + commandToReturn = + String.join( + " ", + cCompiler.compileCCommand(fileConfig.name + "_" + federate.name, false).toString()); + return commandToReturn; + } - @Override - public String remoteExecuteCommand() { - return "bin/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; - } + @Override + public String remoteExecuteCommand() { + return "bin/" + fileConfig.name + "_" + federate.name + " -i '$FEDERATION_ID'"; + } - @Override - public String localExecuteCommand() { - return fileConfig.getFedBinPath().resolve(federate.name)+" -i $FEDERATION_ID"; - } + @Override + public String localExecuteCommand() { + return fileConfig.getFedBinPath().resolve(federate.name) + " -i $FEDERATION_ID"; + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 3ad08e2450..23547ca1d0 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -1,25 +1,25 @@ /************* * Copyright (c) 2019-2021, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ @@ -33,9 +33,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; - import org.lflang.ErrorReporter; -import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.federated.generator.FedFileConfig; @@ -43,453 +41,477 @@ /** * Utility class that can be used to create a launcher for federated LF programs. - * + * * @author Edward A. Lee * @author Soroush Bateni */ public class FedLauncherGenerator { - protected TargetConfig targetConfig; - protected FedFileConfig fileConfig; - protected ErrorReporter errorReporter; - - /** - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. - * @param errorReporter A error reporter for reporting any errors or warnings during the code generation - */ - public FedLauncherGenerator(TargetConfig targetConfig, FedFileConfig fileConfig, ErrorReporter errorReporter) { - this.targetConfig = targetConfig; - this.fileConfig = fileConfig; - this.errorReporter = errorReporter; + protected TargetConfig targetConfig; + protected FedFileConfig fileConfig; + protected ErrorReporter errorReporter; + + /** + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. + * @param errorReporter A error reporter for reporting any errors or warnings during the code + * generation + */ + public FedLauncherGenerator( + TargetConfig targetConfig, FedFileConfig fileConfig, ErrorReporter errorReporter) { + this.targetConfig = targetConfig; + this.fileConfig = fileConfig; + this.errorReporter = errorReporter; + } + + /** + * Create the launcher shell scripts. This will create one or two files in the output path (bin + * directory). The first has name equal to the filename of the source file without the ".lf" + * extension. This will be a shell script that launches the RTI and the federates. If, in + * addition, either the RTI or any federate is mapped to a particular machine (anything other than + * the default "localhost" or "0.0.0.0"), then this will generate a shell script in the bin + * directory with name filename_distribute.sh that copies the relevant source files to the remote + * host and compiles them so that they are ready to execute using the launcher. + * + *

    A precondition for this to work is that the user invoking this code generator can log into + * the remote host without supplying a password. Specifically, you have to have installed your + * public key (typically found in ~/.ssh/id_rsa.pub) in ~/.ssh/authorized_keys on the remote host. + * In addition, the remote host must be running an ssh service. On an Arch Linux system using + * systemd, for example, this means running: + * + *

    sudo systemctl ssh.service + * + *

    Enable means to always start the service at startup, whereas start means to just start it + * this once. + * + *

    On macOS, open System Preferences from the Apple menu and click on the "Sharing" preference + * panel. Select the checkbox next to "Remote Login" to enable it. + * + *

    In addition, every host must have OpenSSL installed, with at least version 1.1.1a. You can + * check the version with + * + *

    openssl version + * + * @param federates A list of federate instances in the federation + * @param rtiConfig Can have values for 'host', 'dir', and 'user' + */ + public void doGenerate(List federates, RtiConfig rtiConfig) { + // NOTE: It might be good to use screen when invoking the RTI + // or federates remotely, so you can detach and the process keeps running. + // However, I was unable to get it working properly. + // What this means is that the shell that invokes the launcher + // needs to remain live for the duration of the federation. + // If that shell is killed, the federation will die. + // Hence, it is reasonable to launch the federation on a + // machine that participates in the federation, for example, + // on the machine that runs the RTI. The command I tried + // to get screen to work looks like this: + // ssh -t «target» cd «path»; screen -S «filename»_«federate.name» -L + // bin/«filename»_«federate.name» 2>&1 + // var outPath = binGenPath + StringBuilder shCode = new StringBuilder(); + StringBuilder distCode = new StringBuilder(); + shCode.append(getSetupCode() + "\n"); + String distHeader = getDistHeader(); + String host = rtiConfig.getHost(); + String target = host; + + String user = rtiConfig.getUser(); + if (user != null) { + target = user + "@" + host; } - /** - * Create the launcher shell scripts. This will create one or two files - * in the output path (bin directory). The first has name equal to - * the filename of the source file without the ".lf" extension. - * This will be a shell script that launches the - * RTI and the federates. If, in addition, either the RTI or any - * federate is mapped to a particular machine (anything other than - * the default "localhost" or "0.0.0.0"), then this will generate - * a shell script in the bin directory with name filename_distribute.sh - * that copies the relevant source files to the remote host and compiles - * them so that they are ready to execute using the launcher. - * - * A precondition for this to work is that the user invoking this - * code generator can log into the remote host without supplying - * a password. Specifically, you have to have installed your - * public key (typically found in ~/.ssh/id_rsa.pub) in - * ~/.ssh/authorized_keys on the remote host. In addition, the - * remote host must be running an ssh service. - * On an Arch Linux system using systemd, for example, this means - * running: - * - * sudo systemctl ssh.service - * - * Enable means to always start the service at startup, whereas - * start means to just start it this once. - * - * On macOS, open System Preferences from the Apple menu and - * click on the "Sharing" preference panel. Select the checkbox - * next to "Remote Login" to enable it. - * - * In addition, every host must have OpenSSL installed, with at least - * version 1.1.1a. You can check the version with - * - * openssl version - * - * @param federates A list of federate instances in the federation - * @param rtiConfig - * Can have values for 'host', 'dir', and 'user' - */ - public void doGenerate( - List federates, - RtiConfig rtiConfig - ) { - // NOTE: It might be good to use screen when invoking the RTI - // or federates remotely, so you can detach and the process keeps running. - // However, I was unable to get it working properly. - // What this means is that the shell that invokes the launcher - // needs to remain live for the duration of the federation. - // If that shell is killed, the federation will die. - // Hence, it is reasonable to launch the federation on a - // machine that participates in the federation, for example, - // on the machine that runs the RTI. The command I tried - // to get screen to work looks like this: - // ssh -t «target» cd «path»; screen -S «filename»_«federate.name» -L bin/«filename»_«federate.name» 2>&1 - // var outPath = binGenPath - StringBuilder shCode = new StringBuilder(); - StringBuilder distCode = new StringBuilder(); - shCode.append(getSetupCode() + "\n"); - String distHeader = getDistHeader(); - String host = rtiConfig.getHost(); - String target = host; - - String user = rtiConfig.getUser(); - if (user != null) { - target = user + "@" + host; - } - - shCode.append("#### Host is " + host); - - // Launch the RTI in the foreground. - if (host.equals("localhost") || host.equals("0.0.0.0")) { - // FIXME: the paths below will not work on Windows - shCode.append(getLaunchCode(getRtiCommand(federates, false)) + "\n"); - } else { - // Start the RTI on the remote machine. - // FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the remote host? - // Copy the source code onto the remote machine and compile it there. - if(distCode.length() == 0) distCode.append(distHeader + "\n"); - - String logFileName = String.format("log/%s_RTI.log", fileConfig.name); - - // Launch the RTI on the remote machine using ssh and screen. - // The -t argument to ssh creates a virtual terminal, which is needed by screen. - // The -S gives the session a name. - // The -L option turns on logging. Unfortunately, the -Logfile giving the log file name - // is not standardized in screen. Logs go to screenlog.0 (or screenlog.n). - // FIXME: Remote errors are not reported back via ssh from screen. - // How to get them back to the local machine? - // Perhaps use -c and generate a screen command file to control the logfile name, - // but screen apparently doesn't write anything to the log file! - // - // The cryptic 2>&1 reroutes stderr to stdout so that both are returned. - // The sleep at the end prevents screen from exiting before outgoing messages from - // the federate have had time to go out to the RTI through the socket. - - shCode.append(getRemoteLaunchCode(host, target, logFileName, - getRtiCommand(federates, true)) + "\n"); - } - - // Index used for storing pids of federates - int federateIndex = 0; - for (FederateInstance federate : federates) { - var buildConfig = getBuildConfig(federate, fileConfig, errorReporter); - if (federate.isRemote) { - Path fedRelSrcGenPath = fileConfig.getOutPath().relativize(fileConfig.getSrcGenPath()).resolve(federate.name); - if(distCode.length() == 0) distCode.append(distHeader + "\n"); - String logFileName = String.format("log/%s_%s.log", fileConfig.name, federate.name); - String compileCommand = buildConfig.compileCommand(); - // FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the remote host? - distCode.append(getDistCode(rtiConfig.getDirectory(), federate, fedRelSrcGenPath, logFileName, fileConfig.getSrcGenPath(), compileCommand) + "\n"); - String executeCommand = buildConfig.remoteExecuteCommand(); - shCode.append(getFedRemoteLaunchCode(federate, rtiConfig.getDirectory(), logFileName, executeCommand, federateIndex++) + "\n"); - } else { - String executeCommand = buildConfig.localExecuteCommand(); - shCode.append(getFedLocalLaunchCode(federate, executeCommand, federateIndex++) + "\n"); - } - } - if (host.equals("localhost") || host.equals("0.0.0.0")) { - // Local PID managements - shCode.append("echo \"#### Bringing the RTI back to foreground so it can receive Control-C.\"" + "\n"); - shCode.append("fg %1" + "\n"); - } - // Wait for launched processes to finish - shCode.append(String.join("\n", - "echo \"RTI has exited. Wait for federates to exit.\"", - "# Wait for launched processes to finish.", - "# The errors are handled separately via trap.", - "for pid in \"${pids[@]}\"", - "do", - " wait $pid", - "done", - "echo \"All done.\"" - ) + "\n"); - - // Create bin directory for the script. - if (!Files.exists(fileConfig.binPath)) { - try { - Files.createDirectories(fileConfig.binPath); - } catch (IOException e) { - errorReporter.reportError("Unable to create directory: " + fileConfig.binPath); - } - } - - System.out.println("##### Generating launcher for federation " - + " in directory " - + fileConfig.binPath); - - // Write the launcher file. - // Delete file previously produced, if any. - File file = fileConfig.binPath.resolve(fileConfig.name).toFile(); - if (file.exists()) { - file.delete(); - } + shCode.append("#### Host is " + host); + + // Launch the RTI in the foreground. + if (host.equals("localhost") || host.equals("0.0.0.0")) { + // FIXME: the paths below will not work on Windows + shCode.append(getLaunchCode(getRtiCommand(federates, false)) + "\n"); + } else { + // Start the RTI on the remote machine. + // FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the + // remote host? + // Copy the source code onto the remote machine and compile it there. + if (distCode.length() == 0) distCode.append(distHeader + "\n"); + + String logFileName = String.format("log/%s_RTI.log", fileConfig.name); + + // Launch the RTI on the remote machine using ssh and screen. + // The -t argument to ssh creates a virtual terminal, which is needed by screen. + // The -S gives the session a name. + // The -L option turns on logging. Unfortunately, the -Logfile giving the log file name + // is not standardized in screen. Logs go to screenlog.0 (or screenlog.n). + // FIXME: Remote errors are not reported back via ssh from screen. + // How to get them back to the local machine? + // Perhaps use -c and generate a screen command file to control the logfile name, + // but screen apparently doesn't write anything to the log file! + // + // The cryptic 2>&1 reroutes stderr to stdout so that both are returned. + // The sleep at the end prevents screen from exiting before outgoing messages from + // the federate have had time to go out to the RTI through the socket. + + shCode.append( + getRemoteLaunchCode(host, target, logFileName, getRtiCommand(federates, true)) + "\n"); + } - FileOutputStream fOut = null; - try { - fOut = new FileOutputStream(file); - } catch (FileNotFoundException e) { - errorReporter.reportError("Unable to find file: " + file); - } - try { - fOut.write(shCode.toString().getBytes()); - fOut.close(); - } catch (IOException e) { - errorReporter.reportError("Unable to write to file: " + file); - } + // Index used for storing pids of federates + int federateIndex = 0; + for (FederateInstance federate : federates) { + var buildConfig = getBuildConfig(federate, fileConfig, errorReporter); + if (federate.isRemote) { + Path fedRelSrcGenPath = + fileConfig.getOutPath().relativize(fileConfig.getSrcGenPath()).resolve(federate.name); + if (distCode.length() == 0) distCode.append(distHeader + "\n"); + String logFileName = String.format("log/%s_%s.log", fileConfig.name, federate.name); + String compileCommand = buildConfig.compileCommand(); + // FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the + // remote host? + distCode.append( + getDistCode( + rtiConfig.getDirectory(), + federate, + fedRelSrcGenPath, + logFileName, + fileConfig.getSrcGenPath(), + compileCommand) + + "\n"); + String executeCommand = buildConfig.remoteExecuteCommand(); + shCode.append( + getFedRemoteLaunchCode( + federate, + rtiConfig.getDirectory(), + logFileName, + executeCommand, + federateIndex++) + + "\n"); + } else { + String executeCommand = buildConfig.localExecuteCommand(); + shCode.append(getFedLocalLaunchCode(federate, executeCommand, federateIndex++) + "\n"); + } + } + if (host.equals("localhost") || host.equals("0.0.0.0")) { + // Local PID managements + shCode.append( + "echo \"#### Bringing the RTI back to foreground so it can receive Control-C.\"" + "\n"); + shCode.append("fg %1" + "\n"); + } + // Wait for launched processes to finish + shCode.append( + String.join( + "\n", + "echo \"RTI has exited. Wait for federates to exit.\"", + "# Wait for launched processes to finish.", + "# The errors are handled separately via trap.", + "for pid in \"${pids[@]}\"", + "do", + " wait $pid", + "done", + "echo \"All done.\"") + + "\n"); + + // Create bin directory for the script. + if (!Files.exists(fileConfig.binPath)) { + try { + Files.createDirectories(fileConfig.binPath); + } catch (IOException e) { + errorReporter.reportError("Unable to create directory: " + fileConfig.binPath); + } + } - if (!file.setExecutable(true, false)) { - errorReporter.reportWarning("Unable to make launcher script executable."); - } + System.out.println( + "##### Generating launcher for federation " + " in directory " + fileConfig.binPath); - // Write the distributor file. - // Delete the file even if it does not get generated. - file = fileConfig.binPath.resolve(fileConfig.name + "_distribute.sh").toFile(); - if (file.exists()) { - file.delete(); - } - if (distCode.length() > 0) { - try { - fOut = new FileOutputStream(file); - fOut.write(distCode.toString().getBytes()); - fOut.close(); - if (!file.setExecutable(true, false)) { - errorReporter.reportWarning("Unable to make file executable: " + file); - } - } catch (FileNotFoundException e) { - errorReporter.reportError("Unable to find file: " + file); - } catch (IOException e) { - errorReporter.reportError("Unable to write to file " + file); - } - } + // Write the launcher file. + // Delete file previously produced, if any. + File file = fileConfig.binPath.resolve(fileConfig.name).toFile(); + if (file.exists()) { + file.delete(); } - private String getSetupCode() { - return String.join("\n", - "#!/bin/bash", - "# Launcher for federated " + fileConfig.name + ".lf Lingua Franca program.", - "# Uncomment to specify to behave as close as possible to the POSIX standard.", - "# set -o posix", - "", - "# Enable job control", - "set -m", - "shopt -s huponexit", - "", - "# Set a trap to kill all background jobs on error or control-C", - "# Use two distinct traps so we can see which signal causes this.", - "cleanup() {", - " printf \"Killing federate %s.\\n\" ${pids[*]}", - " # The || true clause means this is not an error if kill fails.", - " kill ${pids[@]} || true", - " printf \"#### Killing RTI %s.\\n\" ${RTI}", - " kill ${RTI} || true", - " exit 1", - "}", - "cleanup_err() {", - " echo \"#### Received ERR signal on line $1. Invoking cleanup().\"", - " cleanup", - "}", - "cleanup_sigint() {", - " echo \"#### Received SIGINT signal on line $1. Invoking cleanup().\"", - " cleanup", - "}", - "", - "trap 'cleanup_err $LINENO' ERR", - "trap 'cleanup_sigint $LINENO' SIGINT", - "", - "# Create a random 48-byte text ID for this federation.", - "# The likelihood of two federations having the same ID is 1/16,777,216 (1/2^24).", - "FEDERATION_ID=`openssl rand -hex 24`", - "echo \"Federate " + fileConfig.name + " in Federation ID '$FEDERATION_ID'\"", - "# Launch the federates:" - ); + FileOutputStream fOut = null; + try { + fOut = new FileOutputStream(file); + } catch (FileNotFoundException e) { + errorReporter.reportError("Unable to find file: " + file); + } + try { + fOut.write(shCode.toString().getBytes()); + fOut.close(); + } catch (IOException e) { + errorReporter.reportError("Unable to write to file: " + file); } - private String getDistHeader() { - return String.join("\n", - "#!/bin/bash", - "# Distributor for federated "+ fileConfig.name + ".lf Lingua Franca program.", - "# Uncomment to specify to behave as close as possible to the POSIX standard.", - "# set -o posix" - ); + if (!file.setExecutable(true, false)) { + errorReporter.reportWarning("Unable to make launcher script executable."); } - private String getRtiCommand(List federates, boolean isRemote) { - List commands = new ArrayList<>(); - if (isRemote) { - commands.add("RTI -i '${FEDERATION_ID}' \\"); - } else { - commands.add("RTI -i ${FEDERATION_ID} \\"); - } - if (targetConfig.auth) { - commands.add(" -a \\"); - } - if (targetConfig.tracing != null) { - commands.add(" -t \\"); - } - commands.addAll(List.of( - " -n "+federates.size()+" \\", - " -c "+targetConfig.clockSync.toString()+" \\" - )); - if (targetConfig.clockSync.equals(ClockSyncMode.ON)) { - commands.add("period " + targetConfig.clockSyncOptions.period.toNanoSeconds()+" \\"); - } - if (targetConfig.clockSync.equals(ClockSyncMode.ON) || - targetConfig.clockSync.equals(ClockSyncMode.INIT)) { - commands.add("exchanges-per-interval "+targetConfig.clockSyncOptions.trials+" \\"); + // Write the distributor file. + // Delete the file even if it does not get generated. + file = fileConfig.binPath.resolve(fileConfig.name + "_distribute.sh").toFile(); + if (file.exists()) { + file.delete(); + } + if (distCode.length() > 0) { + try { + fOut = new FileOutputStream(file); + fOut.write(distCode.toString().getBytes()); + fOut.close(); + if (!file.setExecutable(true, false)) { + errorReporter.reportWarning("Unable to make file executable: " + file); } - commands.add("&"); - return String.join("\n", commands); + } catch (FileNotFoundException e) { + errorReporter.reportError("Unable to find file: " + file); + } catch (IOException e) { + errorReporter.reportError("Unable to write to file " + file); + } } - - private String getLaunchCode(String rtiLaunchCode) { - return String.join("\n", - "echo \"#### Launching the runtime infrastructure (RTI).\"", - "# First, check if the RTI is on the PATH", - "if ! command -v RTI &> /dev/null", - "then", - " echo \"RTI could not be found.\"", - " echo \"The source code can be obtained from https://github.com/lf-lang/reactor-c/tree/main/core/federated/RTI\"", - " exit", - "fi ", - "# The RTI is started first to allow proper boot-up", - "# before federates will try to connect.", - "# The RTI will be brought back to foreground", - "# to be responsive to user inputs after all federates", - "# are launched.", - rtiLaunchCode, - "# Store the PID of the RTI", - "RTI=$!", - "# Wait for the RTI to boot up before", - "# starting federates (this could be done by waiting for a specific output", - "# from the RTI, but here we use sleep)", - "sleep 1" - ); + } + + private String getSetupCode() { + return String.join( + "\n", + "#!/bin/bash", + "# Launcher for federated " + fileConfig.name + ".lf Lingua Franca program.", + "# Uncomment to specify to behave as close as possible to the POSIX standard.", + "# set -o posix", + "", + "# Enable job control", + "set -m", + "shopt -s huponexit", + "", + "# Set a trap to kill all background jobs on error or control-C", + "# Use two distinct traps so we can see which signal causes this.", + "cleanup() {", + " printf \"Killing federate %s.\\n\" ${pids[*]}", + " # The || true clause means this is not an error if kill fails.", + " kill ${pids[@]} || true", + " printf \"#### Killing RTI %s.\\n\" ${RTI}", + " kill ${RTI} || true", + " exit 1", + "}", + "cleanup_err() {", + " echo \"#### Received ERR signal on line $1. Invoking cleanup().\"", + " cleanup", + "}", + "cleanup_sigint() {", + " echo \"#### Received SIGINT signal on line $1. Invoking cleanup().\"", + " cleanup", + "}", + "", + "trap 'cleanup_err $LINENO' ERR", + "trap 'cleanup_sigint $LINENO' SIGINT", + "", + "# Create a random 48-byte text ID for this federation.", + "# The likelihood of two federations having the same ID is 1/16,777,216 (1/2^24).", + "FEDERATION_ID=`openssl rand -hex 24`", + "echo \"Federate " + fileConfig.name + " in Federation ID '$FEDERATION_ID'\"", + "# Launch the federates:"); + } + + private String getDistHeader() { + return String.join( + "\n", + "#!/bin/bash", + "# Distributor for federated " + fileConfig.name + ".lf Lingua Franca program.", + "# Uncomment to specify to behave as close as possible to the POSIX standard.", + "# set -o posix"); + } + + private String getRtiCommand(List federates, boolean isRemote) { + List commands = new ArrayList<>(); + if (isRemote) { + commands.add("RTI -i '${FEDERATION_ID}' \\"); + } else { + commands.add("RTI -i ${FEDERATION_ID} \\"); } - - private String getRemoteLaunchCode(Object host, Object target, String logFileName, String rtiLaunchString) { - return String.join("\n", - "echo \"#### Launching the runtime infrastructure (RTI) on remote host " + host + ".\"", - "# FIXME: Killing this ssh does not kill the remote process.", - "# A double -t -t option to ssh forces creation of a virtual terminal, which", - "# fixes the problem, but then the ssh command does not execute. The remote", - "# federate does not start!", - "ssh " + target + " 'mkdir -p log; \\", - " echo \"-------------- Federation ID: \"'$FEDERATION_ID' >> " + logFileName + "; \\", - " date >> " + logFileName + "; \\", - " echo \"Executing RTI: " + rtiLaunchString + "\" 2>&1 | tee -a " + logFileName + "; \\", - " # First, check if the RTI is on the PATH", - " if ! command -v RTI &> /dev/null", - " then", - " echo \"RTI could not be found.\"", - " echo \"The source code can be found in org.lflang/src/lib/core/federated/RTI\"", - " exit", - " fi", - " " + rtiLaunchString + " 2>&1 | tee -a " + logFileName + "' &", - "# Store the PID of the channel to RTI", - "RTI=$!", - "# Wait for the RTI to boot up before", - "# starting federates (this could be done by waiting for a specific output", - "# from the RTI, but here we use sleep)", - "sleep 5" - ); + if (targetConfig.auth) { + commands.add(" -a \\"); } - - private String getDistCode( - Path remoteBase, - FederateInstance federate, - Path remoteRelSrcGenPath, - String logFileName, - Path localAbsSrcGenPath, - String compileCommand) { - return String.join("\n", - "echo \"Making directory " + remoteBase - + " and subdirectories src-gen, bin, and log on host " - + getUserHost(federate.user, federate.host) - + "\"", - "# The >> syntax appends stdout to a file. The 2>&1 appends stderr to the same file.", - "ssh " + getUserHost(federate.user, federate.host) - + " '\\", - " mkdir -p " + remoteBase.resolve(remoteRelSrcGenPath).resolve("core") - + " " + remoteBase.resolve("bin") + " " - + remoteBase + "/log; \\", - " echo \"--------------\" >> " + remoteBase + "/" - + logFileName + "; \\", - " date >> " + remoteBase + "/" + logFileName + ";", - "'", - "pushd " + localAbsSrcGenPath - + " > /dev/null", - "echo \"Copying source files to host " - + getUserHost(federate.user, federate.host) - + "\"", - "scp -r * " - + getUserHost(federate.user, federate.host) + ":" - + remoteBase.resolve(remoteRelSrcGenPath), - "popd > /dev/null", - "echo \"Compiling on host " - + getUserHost(federate.user, federate.host) - + " using: " + compileCommand + "\"", - "ssh " + getUserHost(federate.user, federate.host) - + " 'cd " + remoteBase + "; \\", - " echo \"In " + remoteBase + " compiling with: " - + compileCommand + "\" >> " + logFileName - + " 2>&1; \\", - " # Capture the output in the log file and stdout. \\", - " " + compileCommand + " 2>&1 | tee -a " - + logFileName + ";' " - ); + if (targetConfig.tracing != null) { + commands.add(" -t \\"); } - - private String getUserHost(Object user, Object host) { - if (user == null) { - return host.toString(); - } - return user + "@" + host; + commands.addAll( + List.of( + " -n " + federates.size() + " \\", + " -c " + targetConfig.clockSync.toString() + " \\")); + if (targetConfig.clockSync.equals(ClockSyncMode.ON)) { + commands.add("period " + targetConfig.clockSyncOptions.period.toNanoSeconds() + " \\"); } - - private String getFedRemoteLaunchCode( - FederateInstance federate, - Path path, - String logFileName, - String executeCommand, - int federateIndex - ) { - return String.join("\n", - "echo \"#### Launching the federate "+federate.name+" on host "+getUserHost(federate.user, federate.host)+"\"", - "# FIXME: Killing this ssh does not kill the remote process.", - "# A double -t -t option to ssh forces creation of a virtual terminal, which", - "# fixes the problem, but then the ssh command does not execute. The remote", - "# federate does not start!", - "ssh "+getUserHost(federate.user, federate.host)+" '\\", - " cd "+path+"; \\", - " echo \"-------------- Federation ID: \"'$FEDERATION_ID' >> "+logFileName+"; \\", - " date >> "+logFileName+"; \\", - " echo \"In "+path+", executing: "+executeCommand+"\" 2>&1 | tee -a "+logFileName+"; \\", - " "+executeCommand+" 2>&1 | tee -a "+logFileName+"' &", - "pids["+federateIndex+"]=$!" - ); + if (targetConfig.clockSync.equals(ClockSyncMode.ON) + || targetConfig.clockSync.equals(ClockSyncMode.INIT)) { + commands.add("exchanges-per-interval " + targetConfig.clockSyncOptions.trials + " \\"); } - - private String getFedLocalLaunchCode(FederateInstance federate, String executeCommand, int federateIndex) { - return String.format(String.join("\n", - "echo \"#### Launching the federate %s.\"", - "%s &", - "pids[%s]=$!" - ), + commands.add("&"); + return String.join("\n", commands); + } + + private String getLaunchCode(String rtiLaunchCode) { + return String.join( + "\n", + "echo \"#### Launching the runtime infrastructure (RTI).\"", + "# First, check if the RTI is on the PATH", + "if ! command -v RTI &> /dev/null", + "then", + " echo \"RTI could not be found.\"", + " echo \"The source code can be obtained from" + + " https://github.com/lf-lang/reactor-c/tree/main/core/federated/RTI\"", + " exit", + "fi ", + "# The RTI is started first to allow proper boot-up", + "# before federates will try to connect.", + "# The RTI will be brought back to foreground", + "# to be responsive to user inputs after all federates", + "# are launched.", + rtiLaunchCode, + "# Store the PID of the RTI", + "RTI=$!", + "# Wait for the RTI to boot up before", + "# starting federates (this could be done by waiting for a specific output", + "# from the RTI, but here we use sleep)", + "sleep 1"); + } + + private String getRemoteLaunchCode( + Object host, Object target, String logFileName, String rtiLaunchString) { + return String.join( + "\n", + "echo \"#### Launching the runtime infrastructure (RTI) on remote host " + host + ".\"", + "# FIXME: Killing this ssh does not kill the remote process.", + "# A double -t -t option to ssh forces creation of a virtual terminal, which", + "# fixes the problem, but then the ssh command does not execute. The remote", + "# federate does not start!", + "ssh " + target + " 'mkdir -p log; \\", + " echo \"-------------- Federation ID: \"'$FEDERATION_ID' >> " + logFileName + "; \\", + " date >> " + logFileName + "; \\", + " echo \"Executing RTI: " + rtiLaunchString + "\" 2>&1 | tee -a " + logFileName + "; \\", + " # First, check if the RTI is on the PATH", + " if ! command -v RTI &> /dev/null", + " then", + " echo \"RTI could not be found.\"", + " echo \"The source code can be found in org.lflang/src/lib/core/federated/RTI\"", + " exit", + " fi", + " " + rtiLaunchString + " 2>&1 | tee -a " + logFileName + "' &", + "# Store the PID of the channel to RTI", + "RTI=$!", + "# Wait for the RTI to boot up before", + "# starting federates (this could be done by waiting for a specific output", + "# from the RTI, but here we use sleep)", + "sleep 5"); + } + + private String getDistCode( + Path remoteBase, + FederateInstance federate, + Path remoteRelSrcGenPath, + String logFileName, + Path localAbsSrcGenPath, + String compileCommand) { + return String.join( + "\n", + "echo \"Making directory " + + remoteBase + + " and subdirectories src-gen, bin, and log on host " + + getUserHost(federate.user, federate.host) + + "\"", + "# The >> syntax appends stdout to a file. The 2>&1 appends stderr to the same file.", + "ssh " + getUserHost(federate.user, federate.host) + " '\\", + " mkdir -p " + + remoteBase.resolve(remoteRelSrcGenPath).resolve("core") + + " " + + remoteBase.resolve("bin") + + " " + + remoteBase + + "/log; \\", + " echo \"--------------\" >> " + remoteBase + "/" + logFileName + "; \\", + " date >> " + remoteBase + "/" + logFileName + ";", + "'", + "pushd " + localAbsSrcGenPath + " > /dev/null", + "echo \"Copying source files to host " + getUserHost(federate.user, federate.host) + "\"", + "scp -r * " + + getUserHost(federate.user, federate.host) + + ":" + + remoteBase.resolve(remoteRelSrcGenPath), + "popd > /dev/null", + "echo \"Compiling on host " + + getUserHost(federate.user, federate.host) + + " using: " + + compileCommand + + "\"", + "ssh " + getUserHost(federate.user, federate.host) + " 'cd " + remoteBase + "; \\", + " echo \"In " + + remoteBase + + " compiling with: " + + compileCommand + + "\" >> " + + logFileName + + " 2>&1; \\", + " # Capture the output in the log file and stdout. \\", + " " + compileCommand + " 2>&1 | tee -a " + logFileName + ";' "); + } + + private String getUserHost(Object user, Object host) { + if (user == null) { + return host.toString(); + } + return user + "@" + host; + } + + private String getFedRemoteLaunchCode( + FederateInstance federate, + Path path, + String logFileName, + String executeCommand, + int federateIndex) { + return String.join( + "\n", + "echo \"#### Launching the federate " + + federate.name + + " on host " + + getUserHost(federate.user, federate.host) + + "\"", + "# FIXME: Killing this ssh does not kill the remote process.", + "# A double -t -t option to ssh forces creation of a virtual terminal, which", + "# fixes the problem, but then the ssh command does not execute. The remote", + "# federate does not start!", + "ssh " + getUserHost(federate.user, federate.host) + " '\\", + " cd " + path + "; \\", + " echo \"-------------- Federation ID: \"'$FEDERATION_ID' >> " + logFileName + "; \\", + " date >> " + logFileName + "; \\", + " echo \"In " + + path + + ", executing: " + + executeCommand + + "\" 2>&1 | tee -a " + + logFileName + + "; \\", + " " + executeCommand + " 2>&1 | tee -a " + logFileName + "' &", + "pids[" + federateIndex + "]=$!"); + } + + private String getFedLocalLaunchCode( + FederateInstance federate, String executeCommand, int federateIndex) { + return String.format( + String.join("\n", "echo \"#### Launching the federate %s.\"", "%s &", "pids[%s]=$!"), federate.name, executeCommand, federateIndex); - } - - /** - * Create a build configuration of the appropriate target. - * - * @param federate The federate to which the build configuration applies. - * @param fileConfig The file configuration of the federation to which the federate belongs. - * @param errorReporter An error reporter to report problems. - * @return - */ - private BuildConfig getBuildConfig( - FederateInstance federate, - FedFileConfig fileConfig, - ErrorReporter errorReporter) { - return switch(federate.targetConfig.target) { - case C, CCPP -> new CBuildConfig(federate, fileConfig, errorReporter); - case Python -> new PyBuildConfig(federate, fileConfig, errorReporter); - case TS -> new TsBuildConfig(federate, fileConfig, errorReporter); - case CPP, Rust -> throw new UnsupportedOperationException(); - }; - } + } + + /** + * Create a build configuration of the appropriate target. + * + * @param federate The federate to which the build configuration applies. + * @param fileConfig The file configuration of the federation to which the federate belongs. + * @param errorReporter An error reporter to report problems. + * @return + */ + private BuildConfig getBuildConfig( + FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + return switch (federate.targetConfig.target) { + case C, CCPP -> new CBuildConfig(federate, fileConfig, errorReporter); + case Python -> new PyBuildConfig(federate, fileConfig, errorReporter); + case TS -> new TsBuildConfig(federate, fileConfig, errorReporter); + case CPP, Rust -> throw new UnsupportedOperationException(); + }; + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java index 85d6dc4a0f..1a8a996349 100644 --- a/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java @@ -6,17 +6,32 @@ public class PyBuildConfig extends BuildConfig { - public PyBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - super(federate, fileConfig, errorReporter); - } + public PyBuildConfig( + FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + super(federate, fileConfig, errorReporter); + } - @Override - public String localExecuteCommand() { - return "python3 " + fileConfig.getSrcGenPath() + "/" + federate.name + "/" + federate.name+".py -i $FEDERATION_ID"; - } + @Override + public String localExecuteCommand() { + return "python3 " + + fileConfig.getSrcGenPath() + + "/" + + federate.name + + "/" + + federate.name + + ".py -i $FEDERATION_ID"; + } - @Override - public String remoteExecuteCommand() { - return "python3 src-gen/"+fileConfig.name+"/"+federate.name+"/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; - } + @Override + public String remoteExecuteCommand() { + return "python3 src-gen/" + + fileConfig.name + + "/" + + federate.name + + "/" + + fileConfig.name + + "_" + + federate.name + + " -i '$FEDERATION_ID'"; + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java b/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java index 81c608d5b3..60e07c9f53 100644 --- a/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java @@ -4,89 +4,66 @@ /** * Class for storing configuration settings pertaining to the RTI. + * * @author Marten Lohstroh */ public class RtiConfig { - private Path directory; + private Path directory; - /** - * The host on which the RTI process is to be spawned. - */ - private String host; + /** The host on which the RTI process is to be spawned. */ + private String host; - /** - * The port on which to connect to the RTI process. - */ - private int port; + /** The port on which to connect to the RTI process. */ + private int port; - /** - * The username used to gain access to the host where the RTI is to be spawned. - */ - private String user; + /** The username used to gain access to the host where the RTI is to be spawned. */ + private String user; - /** - * Construct a new RTI configuration with all options set to their defaults. - */ - public RtiConfig() { - this.directory = Path.of("LinguaFrancaRemote"); - this.host = "localhost"; - this.port = 0; - } + /** Construct a new RTI configuration with all options set to their defaults. */ + public RtiConfig() { + this.directory = Path.of("LinguaFrancaRemote"); + this.host = "localhost"; + this.port = 0; + } - /** - * Return the directory to create on the remote host. - */ - public Path getDirectory() { - return directory; - } + /** Return the directory to create on the remote host. */ + public Path getDirectory() { + return directory; + } - /** - * Return the host on which the RTI process is to be spawned. - */ - public String getHost() { - return host; - } + /** Return the host on which the RTI process is to be spawned. */ + public String getHost() { + return host; + } - /** - * Return the port on which to connect to the RTI process. - */ - public int getPort() { - return port; - } + /** Return the port on which to connect to the RTI process. */ + public int getPort() { + return port; + } - /** - * Return the username used to gain access to the host where the RTI is to be spawned. - */ - public String getUser() { - return user; - } + /** Return the username used to gain access to the host where the RTI is to be spawned. */ + public String getUser() { + return user; + } - /** - * Set the directory to create on the remote host. - */ - public void setDirectory(Path directory) { - this.directory = directory; - } + /** Set the directory to create on the remote host. */ + public void setDirectory(Path directory) { + this.directory = directory; + } - /** - * Set the host on which the RTI process is to be spawned. - */ - public void setHost(String host) { - this.host = host; - } + /** Set the host on which the RTI process is to be spawned. */ + public void setHost(String host) { + this.host = host; + } - /** - * Set the port on which to connect to the RTI process. - */ - public void setPort(int port) { - this.port = port; - } + /** Set the port on which to connect to the RTI process. */ + public void setPort(int port) { + this.port = port; + } - /** - * Set the username used to gain access to the host where the RTI is to be spawned. - */ - public void setUser(String user) { - this.user = user; - } + /** Set the username used to gain access to the host where the RTI is to be spawned. */ + public void setUser(String user) { + this.user = user; + } } diff --git a/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java index 87b7ffaeb1..97f40c767a 100644 --- a/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java @@ -1,59 +1,59 @@ /************* * Copyright (c) 2019-2021, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.federated.launcher; import org.lflang.ErrorReporter; -import org.lflang.TargetConfig; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; /** - * Utility class that can be used to create a launcher for federated LF programs - * that are written in TypeScript. - * + * Utility class that can be used to create a launcher for federated LF programs that are written in + * TypeScript. + * * @author Soroush Bateni * @author Hokeun Kim * @author Marten Lohstroh */ public class TsBuildConfig extends BuildConfig { - - public TsBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - super(federate, fileConfig, errorReporter); - } - - @Override - public String compileCommand() { - return null; - } - - @Override - public String localExecuteCommand() { - String jsFilename = federate.name + ".js"; - return "node "+fileConfig.getSrcGenPath().resolve(federate.name).resolve("dist").resolve(jsFilename)+" -i $FEDERATION_ID"; - } - + public TsBuildConfig( + FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { + super(federate, fileConfig, errorReporter); + } + + @Override + public String compileCommand() { + return null; + } + + @Override + public String localExecuteCommand() { + String jsFilename = federate.name + ".js"; + return "node " + + fileConfig.getSrcGenPath().resolve(federate.name).resolve("dist").resolve(jsFilename) + + " -i $FEDERATION_ID"; + } } diff --git a/org.lflang/src/org/lflang/federated/serialization/FedNativePythonSerialization.java b/org.lflang/src/org/lflang/federated/serialization/FedNativePythonSerialization.java index e20588d62d..3947b1bd92 100644 --- a/org.lflang/src/org/lflang/federated/serialization/FedNativePythonSerialization.java +++ b/org.lflang/src/org/lflang/federated/serialization/FedNativePythonSerialization.java @@ -1,17 +1,17 @@ /************* * Copyright (c) 2021, The University of California at Berkeley. * Copyright (c) 2021, The University of Texas at Dallas. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -32,91 +32,105 @@ /** * Enables support for Python pickle serialization. - * - * @author Soroush Bateni * + * @author Soroush Bateni */ public class FedNativePythonSerialization implements FedSerialization { - @Override - public boolean isCompatible(GeneratorBase generator) { - if (generator.getTarget() != Target.Python ) { - throw new UnsupportedOperationException("This class only support Python serialization."); - } - return true; + @Override + public boolean isCompatible(GeneratorBase generator) { + if (generator.getTarget() != Target.Python) { + throw new UnsupportedOperationException("This class only support Python serialization."); } + return true; + } - @Override - public String serializedBufferLength() { - return serializedVarName+".len"; - } + @Override + public String serializedBufferLength() { + return serializedVarName + ".len"; + } - @Override - public String seializedBufferVar() { - return serializedVarName+".buf"; - } + @Override + public String seializedBufferVar() { + return serializedVarName + ".buf"; + } - @Override - public StringBuilder generateNetworkSerializerCode(String varName, - String originalType) { - StringBuilder serializerCode = new StringBuilder(); - - // Check that global_pickler is not null - serializerCode.append("if (global_pickler == NULL) lf_print_error_and_exit(\"The pickle module is not loaded.\");\n"); - // Define the serialized PyObject - serializerCode.append("PyObject* serialized_pyobject = PyObject_CallMethod(global_pickler, \"dumps\", \"O\", "+varName+");\n"); - - // Error check - serializerCode.append("if (serialized_pyobject == NULL) {\n"); - serializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n"); - serializerCode.append(" lf_print_error_and_exit(\"Could not serialize serialized_pyobject.\");\n"); - serializerCode.append("}\n"); - - serializerCode.append("Py_buffer "+serializedVarName+";\n"); - serializerCode.append("int returnValue = PyBytes_AsStringAndSize(serialized_pyobject, &"+serializedVarName+".buf, &"+serializedVarName+".len);\n"); - // Error check - serializerCode.append("if (returnValue == -1) {\n"); - serializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n"); - serializerCode.append(" lf_print_error_and_exit(\"Could not serialize "+serializedVarName+".\");\n"); - serializerCode.append("}\n"); - - - - return serializerCode; - } + @Override + public StringBuilder generateNetworkSerializerCode(String varName, String originalType) { + StringBuilder serializerCode = new StringBuilder(); - @Override - public StringBuilder generateNetworkDeserializerCode(String varName, - String targetType) { - StringBuilder deserializerCode = new StringBuilder(); - - // Convert the network message to a Python ByteArray - deserializerCode.append("PyObject* message_byte_array = "+ - "PyBytes_FromStringAndSize((char*)"+varName+"->token->value, "+varName+"->token->length);\n"); - // Deserialize using Pickle - deserializerCode.append("Py_XINCREF(message_byte_array);\n"); - deserializerCode.append("PyObject* "+deserializedVarName+ - " = PyObject_CallMethod(global_pickler, \"loads\", \"O\", message_byte_array);\n"); - // Error check - deserializerCode.append("if ("+deserializedVarName+" == NULL) {\n"); - deserializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n"); - deserializerCode.append(" lf_print_error_and_exit(\"Could not deserialize "+deserializedVarName+".\");\n"); - deserializerCode.append("}\n"); - - // Decrment the reference count - deserializerCode.append("Py_XDECREF(message_byte_array);\n"); - - return deserializerCode; - } + // Check that global_pickler is not null + serializerCode.append( + "if (global_pickler == NULL) lf_print_error_and_exit(\"The pickle module is not" + + " loaded.\");\n"); + // Define the serialized PyObject + serializerCode.append( + "PyObject* serialized_pyobject = PyObject_CallMethod(global_pickler, \"dumps\", \"O\", " + + varName + + ");\n"); - @Override - public StringBuilder generatePreambleForSupport() { - return new StringBuilder(""); - } + // Error check + serializerCode.append("if (serialized_pyobject == NULL) {\n"); + serializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n"); + serializerCode.append( + " lf_print_error_and_exit(\"Could not serialize serialized_pyobject.\");\n"); + serializerCode.append("}\n"); - @Override - public StringBuilder generateCompilerExtensionForSupport() { - return new StringBuilder(""); - } + serializerCode.append("Py_buffer " + serializedVarName + ";\n"); + serializerCode.append( + "int returnValue = PyBytes_AsStringAndSize(serialized_pyobject, &" + + serializedVarName + + ".buf, &" + + serializedVarName + + ".len);\n"); + // Error check + serializerCode.append("if (returnValue == -1) {\n"); + serializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n"); + serializerCode.append( + " lf_print_error_and_exit(\"Could not serialize " + serializedVarName + ".\");\n"); + serializerCode.append("}\n"); + + return serializerCode; + } + + @Override + public StringBuilder generateNetworkDeserializerCode(String varName, String targetType) { + StringBuilder deserializerCode = new StringBuilder(); + + // Convert the network message to a Python ByteArray + deserializerCode.append( + "PyObject* message_byte_array = " + + "PyBytes_FromStringAndSize((char*)" + + varName + + "->token->value, " + + varName + + "->token->length);\n"); + // Deserialize using Pickle + deserializerCode.append("Py_XINCREF(message_byte_array);\n"); + deserializerCode.append( + "PyObject* " + + deserializedVarName + + " = PyObject_CallMethod(global_pickler, \"loads\", \"O\", message_byte_array);\n"); + // Error check + deserializerCode.append("if (" + deserializedVarName + " == NULL) {\n"); + deserializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n"); + deserializerCode.append( + " lf_print_error_and_exit(\"Could not deserialize " + deserializedVarName + ".\");\n"); + deserializerCode.append("}\n"); + + // Decrment the reference count + deserializerCode.append("Py_XDECREF(message_byte_array);\n"); + + return deserializerCode; + } + + @Override + public StringBuilder generatePreambleForSupport() { + return new StringBuilder(""); + } + @Override + public StringBuilder generateCompilerExtensionForSupport() { + return new StringBuilder(""); + } } diff --git a/org.lflang/src/org/lflang/federated/serialization/FedROS2CPPSerialization.java b/org.lflang/src/org/lflang/federated/serialization/FedROS2CPPSerialization.java index d116489dca..1384d11517 100644 --- a/org.lflang/src/org/lflang/federated/serialization/FedROS2CPPSerialization.java +++ b/org.lflang/src/org/lflang/federated/serialization/FedROS2CPPSerialization.java @@ -1,17 +1,17 @@ /************* * Copyright (c) 2021, The University of California at Berkeley. * Copyright (c) 2021, The University of Texas at Dallas. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -32,179 +32,191 @@ /** * Enables support for ROS 2 serialization in C/C++ code. - * - * @author Soroush Bateni * + * @author Soroush Bateni */ public class FedROS2CPPSerialization implements FedSerialization { - /** - * Check whether the current generator is compatible with the given - * serialization technique or not. - * - * @param generator The current generator. - * @return true if compatible, false if not. - */ - @Override - public boolean isCompatible(GeneratorBase generator) { - if (generator.getTarget() != Target.C) { - generator.errorReporter.reportError("ROS serialization is currently only supported for the C target."); - return false; - } else if (!generator.getTargetConfig().compiler.equalsIgnoreCase("g++")) { - generator.errorReporter.reportError( - "Please use the 'compiler: \"g++\"' target property \n"+ - "for ROS serialization" - ); - return false; - } - return true; - } - - /** - * @return Expression in target language that corresponds to the length - * of the serialized buffer. - */ - @Override - public String serializedBufferLength() { - return serializedVarName+".size()"; + /** + * Check whether the current generator is compatible with the given serialization technique or + * not. + * + * @param generator The current generator. + * @return true if compatible, false if not. + */ + @Override + public boolean isCompatible(GeneratorBase generator) { + if (generator.getTarget() != Target.C) { + generator.errorReporter.reportError( + "ROS serialization is currently only supported for the C target."); + return false; + } else if (!generator.getTargetConfig().compiler.equalsIgnoreCase("g++")) { + generator.errorReporter.reportError( + "Please use the 'compiler: \"g++\"' target property \n" + "for ROS serialization"); + return false; } + return true; + } - /** - * @return Expression in target language that is the buffer variable - * itself. - */ - @Override - public String seializedBufferVar() { - return serializedVarName+".get_rcl_serialized_message().buffer"; - } - - /** - * Generate code in C++ that serializes 'varName'. This code - * will convert the data in 'varName' from its 'originalType' into an - * uint8_t. The serialized data will be put in a variable called - * 'serialized_message', defined by @see serializedVarName. - * - * @param varName The variable to be serialized. - * @param originalType The original type of the variable. - * @return Target code that serializes the 'varName' from 'type' - * to an unsigned byte array. - */ - @Override - public StringBuilder generateNetworkSerializerCode(String varName, String originalType) { - StringBuilder serializerCode = new StringBuilder(); - - serializerCode.append("rclcpp::SerializedMessage "+serializedVarName+"(0u);\n"); - // Use the port type verbatim here, which can result - // in compile error if it is not a valid ROS type - serializerCode.append("using MessageT = "+originalType+";\n"); - serializerCode.append("static rclcpp::Serialization _lf_serializer;\n"); - serializerCode.append("_lf_serializer.serialize_message(&"+varName+"->value , &"+serializedVarName+");\n"); - - return serializerCode; - } - - /** - * Variant of @see generateNetworkSerializerCode(String varName, String originalType) - * that also supports shared pointer (i.e., std::shared_ptr<>) definitions of ROS port - * types. - * @param isSharedPtrType Indicates whether the port type is a shared pointer or not. - */ - public StringBuilder generateNetworkSerializerCode(String varName, String originalType, boolean isSharedPtrType) { - StringBuilder serializerCode = new StringBuilder(); - - serializerCode.append("rclcpp::SerializedMessage "+serializedVarName+"(0u);\n"); - // Use the port type verbatim here, which can result - // in compile error if it is not a valid ROS type - serializerCode.append("using MessageT = "+originalType+";\n"); - serializerCode.append("static rclcpp::Serialization _lf_serializer;\n"); - if (isSharedPtrType) { - serializerCode.append("_lf_serializer.serialize_message("+varName+"->value.get() , &"+serializedVarName+");\n"); - } else { - serializerCode.append("_lf_serializer.serialize_message(&"+varName+"->value , &"+serializedVarName+");\n"); - } - - return serializerCode; - } + /** + * @return Expression in target language that corresponds to the length of the serialized buffer. + */ + @Override + public String serializedBufferLength() { + return serializedVarName + ".size()"; + } + /** + * @return Expression in target language that is the buffer variable itself. + */ + @Override + public String seializedBufferVar() { + return serializedVarName + ".get_rcl_serialized_message().buffer"; + } - - /** - * Generate code in C++ that deserializes 'varName'. This code will - * convert the data in 'varName' from a uint8_t into the 'targetType'. - * The deserialized data will be put in a variable called deserialized_message - * defined by @see deserializedVarName. - * - * @param varName The variable to deserialize. - * @param targetType The type to deserialize into. - * @return Target code that deserializes 'varName' from an unsigned byte array - * to 'type'. - */ - @Override - public StringBuilder generateNetworkDeserializerCode(String varName, String targetType) { - StringBuilder deserializerCode = new StringBuilder(); - - deserializerCode.append( - "auto message = std::make_unique( rcl_serialized_message_t{\n" - + " .buffer = (uint8_t*)"+varName+".tmplt.token->value,\n" - + " .buffer_length = "+varName+".tmplt.token->length,\n" - + " .buffer_capacity = "+varName+".tmplt.token->length,\n" - + " .allocator = rcl_get_default_allocator()\n" - + "});\n" - ); - deserializerCode.append("auto msg = std::make_unique(std::move(*message.get()));\n"); - deserializerCode.append(varName+".tmplt.token->value = NULL; // Manually move the data\n"); - // Use the port type verbatim here, which can result - // in compile error if it is not a valid ROS type - deserializerCode.append("using MessageT = "+targetType+";\n"); - deserializerCode.append( - "MessageT "+deserializedVarName+" = MessageT();\n" - + "auto _lf_serializer = rclcpp::Serialization();\n" - + "_lf_serializer.deserialize_message(msg.get(), &"+deserializedVarName+");\n" - ); - - return deserializerCode; - } + /** + * Generate code in C++ that serializes 'varName'. This code will convert the data in 'varName' + * from its 'originalType' into an uint8_t. The serialized data will be put in a variable called + * 'serialized_message', defined by @see serializedVarName. + * + * @param varName The variable to be serialized. + * @param originalType The original type of the variable. + * @return Target code that serializes the 'varName' from 'type' to an unsigned byte array. + */ + @Override + public StringBuilder generateNetworkSerializerCode(String varName, String originalType) { + StringBuilder serializerCode = new StringBuilder(); - /** - * @return Code in C that includes all the necessary preamble to enable - * support for ROS 2 serialization. - */ - @Override - public StringBuilder generatePreambleForSupport() { - StringBuilder preamble = new StringBuilder(); - - preamble.append( - "#include \"rcutils/allocator.h\"\n" - + "#include \"rclcpp/rclcpp.hpp\"\n" - + "#include \"rclcpp/serialization.hpp\"\n" - + "#include \"rclcpp/serialized_message.hpp\"\n" - ); - - return preamble; - } - - /** - * @return Code that should be appended to the CMakeLists.txt to enable - * support for ROS 2 serialization. - */ - @Override - public StringBuilder generateCompilerExtensionForSupport() { - StringBuilder cMakeExtension = new StringBuilder(); - - cMakeExtension.append( - "enable_language(CXX)\n" - + "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wno-write-strings -O2\")\n" - + "\n" - + "find_package(ament_cmake REQUIRED)\n" - + "find_package(rclcpp REQUIRED)\n" - + "find_package(rclcpp_components REQUIRED)\n" - + "find_package(rcutils)\n" - + "find_package(rmw REQUIRED)\n" - + "\n" - + "ament_target_dependencies( ${LF_MAIN_TARGET} rclcpp rmw)" - ); - - return cMakeExtension; + serializerCode.append("rclcpp::SerializedMessage " + serializedVarName + "(0u);\n"); + // Use the port type verbatim here, which can result + // in compile error if it is not a valid ROS type + serializerCode.append("using MessageT = " + originalType + ";\n"); + serializerCode.append("static rclcpp::Serialization _lf_serializer;\n"); + serializerCode.append( + "_lf_serializer.serialize_message(&" + + varName + + "->value , &" + + serializedVarName + + ");\n"); + + return serializerCode; + } + + /** + * Variant of @see generateNetworkSerializerCode(String varName, String originalType) that also + * supports shared pointer (i.e., std::shared_ptr<>) definitions of ROS port types. + * + * @param isSharedPtrType Indicates whether the port type is a shared pointer or not. + */ + public StringBuilder generateNetworkSerializerCode( + String varName, String originalType, boolean isSharedPtrType) { + StringBuilder serializerCode = new StringBuilder(); + + serializerCode.append("rclcpp::SerializedMessage " + serializedVarName + "(0u);\n"); + // Use the port type verbatim here, which can result + // in compile error if it is not a valid ROS type + serializerCode.append("using MessageT = " + originalType + ";\n"); + serializerCode.append("static rclcpp::Serialization _lf_serializer;\n"); + if (isSharedPtrType) { + serializerCode.append( + "_lf_serializer.serialize_message(" + + varName + + "->value.get() , &" + + serializedVarName + + ");\n"); + } else { + serializerCode.append( + "_lf_serializer.serialize_message(&" + + varName + + "->value , &" + + serializedVarName + + ");\n"); } + return serializerCode; + } + + /** + * Generate code in C++ that deserializes 'varName'. This code will convert the data in 'varName' + * from a uint8_t into the 'targetType'. The deserialized data will be put in a variable called + * deserialized_message defined by @see deserializedVarName. + * + * @param varName The variable to deserialize. + * @param targetType The type to deserialize into. + * @return Target code that deserializes 'varName' from an unsigned byte array to 'type'. + */ + @Override + public StringBuilder generateNetworkDeserializerCode(String varName, String targetType) { + StringBuilder deserializerCode = new StringBuilder(); + + deserializerCode.append( + "auto message = std::make_unique( rcl_serialized_message_t{\n" + + " .buffer = (uint8_t*)" + + varName + + ".tmplt.token->value,\n" + + " .buffer_length = " + + varName + + ".tmplt.token->length,\n" + + " .buffer_capacity = " + + varName + + ".tmplt.token->length,\n" + + " .allocator = rcl_get_default_allocator()\n" + + "});\n"); + deserializerCode.append( + "auto msg = std::make_unique(std::move(*message.get()));\n"); + deserializerCode.append(varName + ".tmplt.token->value = NULL; // Manually move the data\n"); + // Use the port type verbatim here, which can result + // in compile error if it is not a valid ROS type + deserializerCode.append("using MessageT = " + targetType + ";\n"); + deserializerCode.append( + "MessageT " + + deserializedVarName + + " = MessageT();\n" + + "auto _lf_serializer = rclcpp::Serialization();\n" + + "_lf_serializer.deserialize_message(msg.get(), &" + + deserializedVarName + + ");\n"); + + return deserializerCode; + } + + /** + * @return Code in C that includes all the necessary preamble to enable support for ROS 2 + * serialization. + */ + @Override + public StringBuilder generatePreambleForSupport() { + StringBuilder preamble = new StringBuilder(); + + preamble.append( + "#include \"rcutils/allocator.h\"\n" + + "#include \"rclcpp/rclcpp.hpp\"\n" + + "#include \"rclcpp/serialization.hpp\"\n" + + "#include \"rclcpp/serialized_message.hpp\"\n"); + + return preamble; + } + + /** + * @return Code that should be appended to the CMakeLists.txt to enable support for ROS 2 + * serialization. + */ + @Override + public StringBuilder generateCompilerExtensionForSupport() { + StringBuilder cMakeExtension = new StringBuilder(); + + cMakeExtension.append( + "enable_language(CXX)\n" + + "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wno-write-strings -O2\")\n" + + "\n" + + "find_package(ament_cmake REQUIRED)\n" + + "find_package(rclcpp REQUIRED)\n" + + "find_package(rclcpp_components REQUIRED)\n" + + "find_package(rcutils)\n" + + "find_package(rmw REQUIRED)\n" + + "\n" + + "ament_target_dependencies( ${LF_MAIN_TARGET} rclcpp rmw)"); + + return cMakeExtension; + } } diff --git a/org.lflang/src/org/lflang/federated/serialization/FedSerialization.java b/org.lflang/src/org/lflang/federated/serialization/FedSerialization.java index 9b7ba0b2eb..fab7201c21 100644 --- a/org.lflang/src/org/lflang/federated/serialization/FedSerialization.java +++ b/org.lflang/src/org/lflang/federated/serialization/FedSerialization.java @@ -3,80 +3,69 @@ import org.lflang.generator.GeneratorBase; /** - * Interface to enable support for automatic data serialization - * in target code. - * - * @author Soroush Bateni + * Interface to enable support for automatic data serialization in target code. * + * @author Soroush Bateni */ public interface FedSerialization { - - /** - * Variable name in the target language for the serialized data. - */ - final static String serializedVarName = "serialized_message"; - - /** - * Variable name in the target language for the deserialized data. - */ - final static String deserializedVarName = "deserialized_message"; - - /** - * Check whether the current generator is compatible with the given - * serialization technique or not. - * - * @param generator The current generator. - * @return true if compatible, false if not. - */ - public boolean isCompatible(GeneratorBase generator); - /** - * @return Expression in target language that corresponds to the length - * of the serialized buffer. - */ - public String serializedBufferLength(); - - /** - * @return Expression in target language that is the buffer variable - * itself. - */ - public String seializedBufferVar(); - - /** - * Generate code in target language that serializes 'varName'. This code - * will convert the data in 'varName' from its 'originalType' into an - * unsigned byte array. The serialized data will be put in a variable - * with the name defined by @see serializedVarName. - * - * @param varName The variable to be serialized. - * @param originalType The original type of the variable. - * @return Target code that serializes the 'varName' from 'type' - * to an unsigned byte array. - */ - public StringBuilder generateNetworkSerializerCode(String varName, String originalType); - - /** - * Generate code in target language that deserializes 'varName'. This code will - * convert the data in 'varName' from an unsigned byte array into the 'targetType'. - * The deserialized data will be put in a variable with the name defined by - * @see deserializedVarName. - * - * @param varName The variable to deserialize. - * @param targetType The type to deserialize into. - * @return Target code that deserializes 'varName' from an unsigned byte array - * to 'type'. - */ - public StringBuilder generateNetworkDeserializerCode(String varName, String targetType); - - /** - * @return Code in target language that includes all the necessary preamble to enable - * support for the current serializer. - */ - public StringBuilder generatePreambleForSupport(); - - /** - * @return Code that should be appended to the compiler instructions (e.g., flags to gcc or - * additional lines to a CMakeLists.txt) to enable support for the current serializer. - */ - public StringBuilder generateCompilerExtensionForSupport(); + /** Variable name in the target language for the serialized data. */ + static final String serializedVarName = "serialized_message"; + + /** Variable name in the target language for the deserialized data. */ + static final String deserializedVarName = "deserialized_message"; + + /** + * Check whether the current generator is compatible with the given serialization technique or + * not. + * + * @param generator The current generator. + * @return true if compatible, false if not. + */ + public boolean isCompatible(GeneratorBase generator); + + /** + * @return Expression in target language that corresponds to the length of the serialized buffer. + */ + public String serializedBufferLength(); + + /** + * @return Expression in target language that is the buffer variable itself. + */ + public String seializedBufferVar(); + + /** + * Generate code in target language that serializes 'varName'. This code will convert the data in + * 'varName' from its 'originalType' into an unsigned byte array. The serialized data will be put + * in a variable with the name defined by @see serializedVarName. + * + * @param varName The variable to be serialized. + * @param originalType The original type of the variable. + * @return Target code that serializes the 'varName' from 'type' to an unsigned byte array. + */ + public StringBuilder generateNetworkSerializerCode(String varName, String originalType); + + /** + * Generate code in target language that deserializes 'varName'. This code will convert the data + * in 'varName' from an unsigned byte array into the 'targetType'. The deserialized data will be + * put in a variable with the name defined by + * + * @see deserializedVarName. + * @param varName The variable to deserialize. + * @param targetType The type to deserialize into. + * @return Target code that deserializes 'varName' from an unsigned byte array to 'type'. + */ + public StringBuilder generateNetworkDeserializerCode(String varName, String targetType); + + /** + * @return Code in target language that includes all the necessary preamble to enable support for + * the current serializer. + */ + public StringBuilder generatePreambleForSupport(); + + /** + * @return Code that should be appended to the compiler instructions (e.g., flags to gcc or + * additional lines to a CMakeLists.txt) to enable support for the current serializer. + */ + public StringBuilder generateCompilerExtensionForSupport(); } diff --git a/org.lflang/src/org/lflang/federated/serialization/SupportedSerializers.java b/org.lflang/src/org/lflang/federated/serialization/SupportedSerializers.java index 332ab6152c..4767f3f4d7 100644 --- a/org.lflang/src/org/lflang/federated/serialization/SupportedSerializers.java +++ b/org.lflang/src/org/lflang/federated/serialization/SupportedSerializers.java @@ -2,23 +2,25 @@ /** * The supported serializers. + * * @author Soroush Bateni */ public enum SupportedSerializers { - NATIVE("native"), // Dangerous: just copies the memory layout of the sender - ROS2("ros2"), - PROTO("proto"); + NATIVE("native"), // Dangerous: just copies the memory layout of the sender + ROS2("ros2"), + PROTO("proto"); - private String serializer; - SupportedSerializers(String serializer) { - this.serializer = serializer; - } - - public String getSerializer() { - return serializer; - } - - public void setSerializer(String serializer) { - this.serializer = serializer; - } + private String serializer; + + SupportedSerializers(String serializer) { + this.serializer = serializer; + } + + public String getSerializer() { + return serializer; + } + + public void setSerializer(String serializer) { + this.serializer = serializer; + } } diff --git a/org.lflang/src/org/lflang/federated/validation/FedValidator.java b/org.lflang/src/org/lflang/federated/validation/FedValidator.java index 49add78557..9aeb535d2f 100644 --- a/org.lflang/src/org/lflang/federated/validation/FedValidator.java +++ b/org.lflang/src/org/lflang/federated/validation/FedValidator.java @@ -3,9 +3,8 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; @@ -13,57 +12,55 @@ import org.lflang.lf.Reactor; import org.lflang.lf.VarRef; -/** - * Helper class that is used to validate a federated reactor. - */ +/** Helper class that is used to validate a federated reactor. */ public class FedValidator { - public static void validateFederatedReactor(Reactor reactor, ErrorReporter errorReporter) { - if (!reactor.isFederated()) return; + public static void validateFederatedReactor(Reactor reactor, ErrorReporter errorReporter) { + if (!reactor.isFederated()) return; - // Construct the set of excluded reactions for this federate. - // If a reaction is a network reaction that belongs to this federate, we - // don't need to perform this analysis. - Iterable reactions = ASTUtils.allReactions(reactor); - for (Reaction react : reactions) { - // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react - // signature that are ports that reference federates. - // We then later check that all these VarRefs reference this federate. If not, we will add this - // react to the list of reactions that have to be excluded (note that mixing VarRefs from - // different federates is not allowed). - List allVarRefsReferencingFederates = new ArrayList<>(); - // Add all the triggers that are outputs - Stream triggersAsVarRef = react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); - allVarRefsReferencingFederates.addAll( - triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList() - ); - // Add all the sources that are outputs - allVarRefsReferencingFederates.addAll( - react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList() - ); - // Add all the effects that are inputs - allVarRefsReferencingFederates.addAll( - react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList() - ); - containsAllVarRefs(allVarRefsReferencingFederates, errorReporter); - } + // Construct the set of excluded reactions for this federate. + // If a reaction is a network reaction that belongs to this federate, we + // don't need to perform this analysis. + Iterable reactions = ASTUtils.allReactions(reactor); + for (Reaction react : reactions) { + // Create a collection of all the VarRefs (i.e., triggers, sources, and effects) in the react + // signature that are ports that reference federates. + // We then later check that all these VarRefs reference this federate. If not, we will add + // this + // react to the list of reactions that have to be excluded (note that mixing VarRefs from + // different federates is not allowed). + List allVarRefsReferencingFederates = new ArrayList<>(); + // Add all the triggers that are outputs + Stream triggersAsVarRef = + react.getTriggers().stream().filter(it -> it instanceof VarRef).map(it -> (VarRef) it); + allVarRefsReferencingFederates.addAll( + triggersAsVarRef.filter(it -> it.getVariable() instanceof Output).toList()); + // Add all the sources that are outputs + allVarRefsReferencingFederates.addAll( + react.getSources().stream().filter(it -> it.getVariable() instanceof Output).toList()); + // Add all the effects that are inputs + allVarRefsReferencingFederates.addAll( + react.getEffects().stream().filter(it -> it.getVariable() instanceof Input).toList()); + containsAllVarRefs(allVarRefsReferencingFederates, errorReporter); } + } - /** - * Check if this federate contains all the {@code varRefs}. If not, report an error using {@code errorReporter}. - */ - private static void containsAllVarRefs(List varRefs, ErrorReporter errorReporter) { - var referencesFederate = false; - Instantiation instantiation = null; - for (VarRef varRef : varRefs) { - if (instantiation == null) { - instantiation = varRef.getContainer(); - referencesFederate = true; - } else if (!varRef.getContainer().equals(instantiation)) { - errorReporter.reportError(varRef, "Mixed triggers and effects from" + - " different federates. This is not permitted"); - } - } - + /** + * Check if this federate contains all the {@code varRefs}. If not, report an error using {@code + * errorReporter}. + */ + private static void containsAllVarRefs(List varRefs, ErrorReporter errorReporter) { + var referencesFederate = false; + Instantiation instantiation = null; + for (VarRef varRef : varRefs) { + if (instantiation == null) { + instantiation = varRef.getContainer(); + referencesFederate = true; + } else if (!varRef.getContainer().equals(instantiation)) { + errorReporter.reportError( + varRef, + "Mixed triggers and effects from" + " different federates. This is not permitted"); + } } + } } diff --git a/org.lflang/src/org/lflang/formatting2/LFFormatter.java b/org.lflang/src/org/lflang/formatting2/LFFormatter.java index 2a5e60cdc8..7df4053eef 100644 --- a/org.lflang/src/org/lflang/formatting2/LFFormatter.java +++ b/org.lflang/src/org/lflang/formatting2/LFFormatter.java @@ -4,8 +4,8 @@ package org.lflang.formatting2; +import com.google.inject.Inject; import java.util.List; - import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.formatting2.FormatterRequest; import org.eclipse.xtext.formatting2.IFormatter2; @@ -15,38 +15,32 @@ import org.eclipse.xtext.util.CancelIndicator; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; - import org.lflang.ast.FormattingUtils; -import com.google.inject.Inject; - public class LFFormatter implements IFormatter2 { - @Inject - private IResourceValidator validator; + @Inject private IResourceValidator validator; - @Override - public List format(FormatterRequest request) { - // TODO: Use a CancelIndicator that actually cancels? - if (!request.getTextRegionAccess().getResource().getErrors().isEmpty() - || !validator.validate( + @Override + public List format(FormatterRequest request) { + // TODO: Use a CancelIndicator that actually cancels? + if (!request.getTextRegionAccess().getResource().getErrors().isEmpty() + || !validator + .validate( request.getTextRegionAccess().getResource(), CheckMode.ALL, - CancelIndicator.NullImpl - ).isEmpty() - ) { - return List.of(); - } - ITextSegment documentRegion = request.getTextRegionAccess().regionForDocument(); - List documentContents = request.getTextRegionAccess().getResource().getContents(); - if (documentContents.isEmpty()) return List.of(); - return List.of( - new TextReplacement( - request.getTextRegionAccess(), - documentRegion.getOffset(), - documentRegion.getLength(), - FormattingUtils.render(documentContents.get(0)) - ) - ); + CancelIndicator.NullImpl) + .isEmpty()) { + return List.of(); } + ITextSegment documentRegion = request.getTextRegionAccess().regionForDocument(); + List documentContents = request.getTextRegionAccess().getResource().getContents(); + if (documentContents.isEmpty()) return List.of(); + return List.of( + new TextReplacement( + request.getTextRegionAccess(), + documentRegion.getOffset(), + documentRegion.getLength(), + FormattingUtils.render(documentContents.get(0)))); + } } diff --git a/org.lflang/src/org/lflang/generator/ActionInstance.java b/org.lflang/src/org/lflang/generator/ActionInstance.java index bdc8793383..b749a26426 100644 --- a/org.lflang/src/org/lflang/generator/ActionInstance.java +++ b/org.lflang/src/org/lflang/generator/ActionInstance.java @@ -1,28 +1,28 @@ /* Instance of an action. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; @@ -32,69 +32,69 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY /** * Instance of an action. + * * @author Edward A. Lee * @author Marten Lohstroh */ public class ActionInstance extends TriggerInstance { - /** The constant default for a minimum delay. */ - public static final TimeValue DEFAULT_MIN_DELAY = TimeValue.ZERO; + /** The constant default for a minimum delay. */ + public static final TimeValue DEFAULT_MIN_DELAY = TimeValue.ZERO; - /** The minimum delay for this action. */ - private TimeValue minDelay = DEFAULT_MIN_DELAY; + /** The minimum delay for this action. */ + private TimeValue minDelay = DEFAULT_MIN_DELAY; - /** The minimum spacing between action events. */ - private TimeValue minSpacing = null; + /** The minimum spacing between action events. */ + private TimeValue minSpacing = null; - /** The replacement policy for when minimum spacing is violated. */ - private String policy = null; + /** The replacement policy for when minimum spacing is violated. */ + private String policy = null; - /** Indicator of whether the action is physical. */ - private boolean physical; + /** Indicator of whether the action is physical. */ + private boolean physical; - /** - * Create a new action instance. - * If the definition is null, then this is a shutdown action. - * @param definition The AST definition, or null for startup. - * @param parent The parent reactor. - */ - public ActionInstance(Action definition, ReactorInstance parent) { - super(definition, parent); - if (parent == null) { - throw new InvalidSourceException("Cannot create an ActionInstance with no parent."); - } - if (definition != null) { - if (definition.getMinDelay() != null) { - this.minDelay = parent.getTimeValue(definition.getMinDelay()); - } - if (definition.getMinSpacing() != null) { - this.minSpacing = parent.getTimeValue(definition.getMinSpacing()); - } - if (definition.getOrigin() == ActionOrigin.PHYSICAL) { - physical = true; - } - policy = definition.getPolicy(); - } + /** + * Create a new action instance. If the definition is null, then this is a shutdown action. + * + * @param definition The AST definition, or null for startup. + * @param parent The parent reactor. + */ + public ActionInstance(Action definition, ReactorInstance parent) { + super(definition, parent); + if (parent == null) { + throw new InvalidSourceException("Cannot create an ActionInstance with no parent."); } - - /** Return the minimum delay for this action. */ - public TimeValue getMinDelay() { - return minDelay; + if (definition != null) { + if (definition.getMinDelay() != null) { + this.minDelay = parent.getTimeValue(definition.getMinDelay()); + } + if (definition.getMinSpacing() != null) { + this.minSpacing = parent.getTimeValue(definition.getMinSpacing()); + } + if (definition.getOrigin() == ActionOrigin.PHYSICAL) { + physical = true; + } + policy = definition.getPolicy(); } - - /** Return the minimum spacing between action events. */ - public TimeValue getMinSpacing() { - return minSpacing; - } - - /** Return the replacement policy for when minimum spacing is violated. */ - public String getPolicy() { - return policy; - } - - /** Return the indicator of whether the action is physical. */ - public boolean isPhysical() { - return physical; - } - + } + + /** Return the minimum delay for this action. */ + public TimeValue getMinDelay() { + return minDelay; + } + + /** Return the minimum spacing between action events. */ + public TimeValue getMinSpacing() { + return minSpacing; + } + + /** Return the replacement policy for when minimum spacing is violated. */ + public String getPolicy() { + return policy; + } + + /** Return the indicator of whether the action is physical. */ + public boolean isPhysical() { + return physical; + } } diff --git a/org.lflang/src/org/lflang/generator/CodeBuilder.java b/org.lflang/src/org/lflang/generator/CodeBuilder.java index 2b77239680..e4e92294fb 100644 --- a/org.lflang/src/org/lflang/generator/CodeBuilder.java +++ b/org.lflang/src/org/lflang/generator/CodeBuilder.java @@ -1,533 +1,555 @@ package org.lflang.generator; -import java.nio.file.Path; -import java.io.IOException; +import static org.lflang.generator.c.CMixedRadixGenerator.*; +import static org.lflang.util.StringUtil.joinObjects; +import java.io.IOException; +import java.nio.file.Path; import org.eclipse.emf.common.CommonPlugin; import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.c.CUtil; import org.lflang.lf.Code; import org.lflang.util.FileUtil; -import static org.lflang.generator.c.CMixedRadixGenerator.*; -import static org.lflang.util.StringUtil.joinObjects; /** - * Helper class for printing code with indentation. - * This class is backed by a StringBuilder and is used to accumulate - * code to be printed to a file. Its main function is to handle indentation. + * Helper class for printing code with indentation. This class is backed by a StringBuilder and is + * used to accumulate code to be printed to a file. Its main function is to handle indentation. * * @author Edward A. Lee * @author Peter Donovan */ public class CodeBuilder { - /** - * Construct a new empty code emitter. - */ - public CodeBuilder() {} - - /** - * Construct a new code emitter with the text and indentation - * of the specified code emitter. - * @param model The model code emitter. - */ - public CodeBuilder(CodeBuilder model) { - indentation = model.indentation; - code.append(model); - } - - ///////////////////////////////////////////// - ///// Public methods. - - /** - * Get the code produced so far. - * @return The code produced so far as a String. - */ - public String getCode() { - return code.toString(); - } - - /** - * Increase the indentation of the output code produced. - */ - public void indent() { - indentation += " "; - } - - /** - * Insert the specified text at the specified position. - * @param position The position. - * @param text The text. - */ - public void insert(int position, String text) { - code.insert(position, text); - } - - /** - * Return the length of the code in characters. - */ - public int length() { - return code.length(); - } - - /** - * Add a new line. - */ - public void newLine() { - this.pr(""); - } - - /** - * Append the specified text plus a final newline. - * @param format A format string to be used by {@code String.format} or - * the text to append if no further arguments are given. - * @param args Additional arguments to pass to the formatter. - */ - public void pr(String format, Object... args) { - pr( - (args != null && args.length > 0) ? String.format(format, args) : format - ); - } - - /** - * Append the given text to the code buffer at the current indentation level. - */ - public void pr(CharSequence text) { - for (String line : (Iterable) () -> text.toString().lines().iterator()) { - code.append(indentation).append(line).append("\n"); - } + /** Construct a new empty code emitter. */ + public CodeBuilder() {} + + /** + * Construct a new code emitter with the text and indentation of the specified code emitter. + * + * @param model The model code emitter. + */ + public CodeBuilder(CodeBuilder model) { + indentation = model.indentation; + code.append(model); + } + + ///////////////////////////////////////////// + ///// Public methods. + + /** + * Get the code produced so far. + * + * @return The code produced so far as a String. + */ + public String getCode() { + return code.toString(); + } + + /** Increase the indentation of the output code produced. */ + public void indent() { + indentation += " "; + } + + /** + * Insert the specified text at the specified position. + * + * @param position The position. + * @param text The text. + */ + public void insert(int position, String text) { + code.insert(position, text); + } + + /** Return the length of the code in characters. */ + public int length() { + return code.length(); + } + + /** Add a new line. */ + public void newLine() { + this.pr(""); + } + + /** + * Append the specified text plus a final newline. + * + * @param format A format string to be used by {@code String.format} or the text to append if no + * further arguments are given. + * @param args Additional arguments to pass to the formatter. + */ + public void pr(String format, Object... args) { + pr((args != null && args.length > 0) ? String.format(format, args) : format); + } + + /** Append the given text to the code buffer at the current indentation level. */ + public void pr(CharSequence text) { + for (String line : (Iterable) () -> text.toString().lines().iterator()) { + code.append(indentation).append(line).append("\n"); } - - /** - * Version of pr() that prints a source line number using a #line - * prior to each line of the output. Use this when multiple lines of - * output code are all due to the same source line in the .lf file. - * @param eObject The AST node that this source line is based on. - * @param text The text to append. - */ - public void pr(EObject eObject, Object text) { - var split = text.toString().split("\n"); - for (String line : split) { - prSourceLineNumber(eObject); - pr(line); - } + } + + /** + * Version of pr() that prints a source line number using a #line prior to each line of the + * output. Use this when multiple lines of output code are all due to the same source line in the + * .lf file. + * + * @param eObject The AST node that this source line is based on. + * @param text The text to append. + */ + public void pr(EObject eObject, Object text) { + var split = text.toString().split("\n"); + for (String line : split) { + prSourceLineNumber(eObject); + pr(line); } - - /** Print the #line compiler directive with the line number of - * the specified object. - * @param eObject The node. - */ - public void prSourceLineNumber(EObject eObject) { - var node = NodeModelUtils.getNode(eObject); - if (node != null) { - // For code blocks (delimited by {= ... =}, unfortunately, - // we have to adjust the offset by the number of newlines before {=. - // Unfortunately, this is complicated because the code has been - // tokenized. - var offset = 0; - if (eObject instanceof Code) { - offset += 1; - } - // Extract the filename from eResource, an astonishingly difficult thing to do. - String filePath = CommonPlugin.resolve(eObject.eResource().getURI()).path(); - pr("#line " + (node.getStartLine() + offset) + " \"" + filePath + "\""); - } + } + + /** + * Print the #line compiler directive with the line number of the specified object. + * + * @param eObject The node. + */ + public void prSourceLineNumber(EObject eObject) { + var node = NodeModelUtils.getNode(eObject); + if (node != null) { + // For code blocks (delimited by {= ... =}, unfortunately, + // we have to adjust the offset by the number of newlines before {=. + // Unfortunately, this is complicated because the code has been + // tokenized. + var offset = 0; + if (eObject instanceof Code) { + offset += 1; + } + // Extract the filename from eResource, an astonishingly difficult thing to do. + String filePath = CommonPlugin.resolve(eObject.eResource().getURI()).path(); + pr("#line " + (node.getStartLine() + offset) + " \"" + filePath + "\""); } - - /** - * Append a single-line, C-style comment to the code. - * @param comment The comment. - */ - public void prComment(String comment) { - pr("// " + comment); + } + + /** + * Append a single-line, C-style comment to the code. + * + * @param comment The comment. + */ + public void prComment(String comment) { + pr("// " + comment); + } + + /** + * Remove all lines that start with the specified prefix and return a new CodeBuilder with the + * result. + * + * @param prefix The prefix. + */ + public CodeBuilder removeLines(String prefix) { + String separator = "\n"; + String[] lines = toString().split(separator); + + CodeBuilder builder = new CodeBuilder(); + + for (String line : lines) { + String trimmedLine = line.trim(); + if (!trimmedLine.startsWith(prefix)) { + builder.pr(line); + } } - - /** - * Remove all lines that start with the specified prefix - * and return a new CodeBuilder with the result. - * @param prefix The prefix. - */ - public CodeBuilder removeLines(String prefix) { - String separator = "\n"; - String[] lines = toString().split(separator); - - CodeBuilder builder = new CodeBuilder(); - - for(String line : lines) { - String trimmedLine = line.trim(); - if(!trimmedLine.startsWith(prefix)) { - builder.pr(line); - } - } - return builder; + return builder; + } + + /** + * Start a scoped block, which is a section of code surrounded by curley braces and indented. This + * must be followed by an {@link #endScopedBlock()}. + */ + public void startScopedBlock() { + pr("{"); + indent(); + } + + /** + * Start a scoped block for the specified reactor. If the reactor is a bank, then this starts a + * for loop that iterates over the bank members using a standard index variable whose name is that + * returned by {@link CUtil#bankIndex(ReactorInstance)}. If the reactor is null or is not a bank, + * then this simply starts a scoped block by printing an opening curly brace. This also adds a + * declaration of a pointer to the self struct of the reactor or bank member. + * + *

    This block is intended to be nested, where each block is put within a similar block for the + * reactor's parent. This ensures that all (possibly nested) bank index variables are defined + * within the block. + * + *

    This must be followed by an {@link #endScopedBlock()}. + * + * @param reactor The reactor instance. + */ + public void startScopedBlock(ReactorInstance reactor) { + if (reactor != null && reactor.isBank()) { + var index = CUtil.bankIndexName(reactor); + pr("// Reactor is a bank. Iterate over bank members."); + pr("for (int " + index + " = 0; " + index + " < " + reactor.width + "; " + index + "++) {"); + indent(); + } else { + startScopedBlock(); } - - /** - * Start a scoped block, which is a section of code - * surrounded by curley braces and indented. - * This must be followed by an {@link #endScopedBlock()}. - */ - public void startScopedBlock() { - pr("{"); - indent(); + } + + /** + * If the specified port is a multiport, then start a specified iteration over the channels of the + * multiport using as the channel index the variable name returned by {@link + * CUtil#channelIndex(PortInstance)}. If the port is not a multiport, do nothing. This is required + * to be followed by {@link #endChannelIteration(PortInstance)}. + * + * @param port The port. + */ + public void startChannelIteration(PortInstance port) { + if (port.isMultiport) { + var channel = CUtil.channelIndexName(port); + pr("// Port " + port.getFullName() + " is a multiport. Iterate over its channels."); + pr( + "for (int " + + channel + + " = 0; " + + channel + + " < " + + port.width + + "; " + + channel + + "++) {"); + indent(); } - - /** - * Start a scoped block for the specified reactor. - * If the reactor is a bank, then this starts a for loop - * that iterates over the bank members using a standard index - * variable whose name is that returned by {@link CUtil#bankIndex(ReactorInstance)}. - * If the reactor is null or is not a bank, then this simply - * starts a scoped block by printing an opening curly brace. - * This also adds a declaration of a pointer to the self - * struct of the reactor or bank member. - * - * This block is intended to be nested, where each block is - * put within a similar block for the reactor's parent. - * This ensures that all (possibly nested) bank index variables - * are defined within the block. - * - * This must be followed by an {@link #endScopedBlock()}. - * - * @param reactor The reactor instance. - */ - public void startScopedBlock( - ReactorInstance reactor - ) { - if (reactor != null && reactor.isBank()) { - var index = CUtil.bankIndexName(reactor); - pr("// Reactor is a bank. Iterate over bank members."); - pr("for (int "+index+" = 0; "+index+" < "+reactor.width+"; "+index+"++) {"); - indent(); - } else { - startScopedBlock(); - } + } + + /** + * Start a scoped block to iterate over bank members and channels for the specified port with a + * variable with the name given by count counting the iterations. If this port is a multiport, + * then the channel index variable name is that returned by {@link + * CUtil#channelIndex(PortInstance)}. + * + *

    This block is intended to be nested, where each block is put within a similar block for the + * reactor's parent. + * + *

    This is required to be followed by a call to {@link + * #endScopedBankChannelIteration(PortInstance, String)}. + * + * @param port The port. + * @param count The variable name to use for the counter, or null to not provide a counter. + */ + public void startScopedBankChannelIteration(PortInstance port, String count) { + if (count != null) { + startScopedBlock(); + pr("int " + count + " = 0;"); } - - /** - * If the specified port is a multiport, then start a specified iteration - * over the channels of the multiport using as the channel index the - * variable name returned by {@link CUtil#channelIndex(PortInstance)}. - * If the port is not a multiport, do nothing. - * This is required to be followed by {@link #endChannelIteration(PortInstance)}. - * @param port The port. - */ - public void startChannelIteration(PortInstance port) { - if (port.isMultiport) { - var channel = CUtil.channelIndexName(port); - pr("// Port "+port.getFullName()+" is a multiport. Iterate over its channels."); - pr("for (int "+channel+" = 0; "+channel+" < "+port.width+"; "+channel+"++) {"); - indent(); - } + startScopedBlock(port.parent); + startChannelIteration(port); + } + + /** + * Start a scoped block that iterates over the specified range of port channels. + * + *

    This must be followed by a call to {@link #endScopedRangeBlock(RuntimeRange)}. + * + *

    This block should NOT be nested, where each block is put within a similar block for the + * reactor's parent. Within the created block, every use of {@link + * CUtil#reactorRef(ReactorInstance, String)} must provide the second argument, a runtime index + * variable name, that must match the runtimeIndex parameter given here. + * + * @param range The range of port channels. + * @param runtimeIndex A variable name to use to index the runtime instance of either port's + * parent or the port's parent's parent (if nested is true), or null to use the default, + * "runtime_index". + * @param bankIndex A variable name to use to index the bank of the port's parent or null to use + * the default, the string returned by {@link CUtil#bankIndexName(ReactorInstance)}. + * @param channelIndex A variable name to use to index the channel or null to use the default, the + * string returned by {@link CUtil#channelIndexName(PortInstance)}. + * @param nested If true, then the runtimeIndex variable will be set to the bank index of the + * port's parent's parent rather than the port's parent. + */ + public void startScopedRangeBlock( + RuntimeRange range, + String runtimeIndex, + String bankIndex, + String channelIndex, + boolean nested) { + + pr("// Iterate over range " + range.toString() + "."); + var ri = (runtimeIndex == null) ? "runtime_index" : runtimeIndex; + var ci = (channelIndex == null) ? CUtil.channelIndexName(range.instance) : channelIndex; + var bi = (bankIndex == null) ? CUtil.bankIndexName(range.instance.parent) : bankIndex; + var rangeMR = range.startMR(); + var sizeMR = rangeMR.getDigits().size(); + var nestedLevel = (nested) ? 2 : 1; + + startScopedBlock(); + if (range.width > 1) { + pr( + String.join( + "\n", + "int range_start[] = { " + joinObjects(rangeMR.getDigits(), ", ") + " };", + "int range_radixes[] = { " + joinObjects(rangeMR.getRadixes(), ", ") + " };", + "int permutation[] = { " + joinObjects(range.permutation(), ", ") + " };", + "mixed_radix_int_t range_mr = {", + " " + sizeMR + ",", + " range_start,", + " range_radixes,", + " permutation", + "};", + "for (int range_count = " + + range.start + + "; range_count < " + + range.start + + " + " + + range.width + + "; range_count++) {")); + indent(); + pr( + String.join( + "\n", + "int " + + ri + + " = mixed_radix_parent(&range_mr, " + + nestedLevel + + "); // Runtime index.", + "SUPPRESS_UNUSED_WARNING(" + ri + ");", + "int " + ci + " = range_mr.digits[0]; // Channel index.", + "SUPPRESS_UNUSED_WARNING(" + ci + ");", + "int " + bi + " = " + (sizeMR <= 1 ? "0" : "range_mr.digits[1]") + "; // Bank index.", + "SUPPRESS_UNUSED_WARNING(" + bi + ");")); + + } else { + var ciValue = rangeMR.getDigits().get(0); + var riValue = rangeMR.get(nestedLevel); + var biValue = (sizeMR > 1) ? rangeMR.getDigits().get(1) : 0; + pr( + String.join( + "\n", + "int " + + ri + + " = " + + riValue + + "; SUPPRESS_UNUSED_WARNING(" + + ri + + "); // Runtime index.", + "int " + + ci + + " = " + + ciValue + + "; SUPPRESS_UNUSED_WARNING(" + + ci + + "); // Channel index.", + "int " + + bi + + " = " + + biValue + + "; SUPPRESS_UNUSED_WARNING(" + + bi + + "); // Bank index.", + "int range_count = 0; SUPPRESS_UNUSED_WARNING(range_count);")); } - - /** - * Start a scoped block to iterate over bank members and - * channels for the specified port with a variable with - * the name given by count counting the iterations. - * If this port is a multiport, then the channel index - * variable name is that returned by {@link CUtil#channelIndex(PortInstance)}. - * - * This block is intended to be nested, where each block is - * put within a similar block for the reactor's parent. - * - * This is required to be followed by a call to - * {@link #endScopedBankChannelIteration(PortInstance, String)}. - * @param port The port. - * @param count The variable name to use for the counter, or - * null to not provide a counter. - */ - public void startScopedBankChannelIteration(PortInstance port, - String count) { - if (count != null) { - startScopedBlock(); - pr("int "+count+" = 0;"); - } - startScopedBlock(port.parent); - startChannelIteration(port); + } + + /** + * Start a scoped block that iterates over the specified pair of ranges. The destination range can + * be wider than the source range, in which case the source range is reused until the destination + * range is filled. The following integer variables will be defined within the scoped block: + * + *

      + *
    • src_channel: The channel index for the source. + *
    • src_bank: The bank index of the source port's parent. + *
    • src_runtime: The runtime index of the source port's parent or the parent's parent + * (if the source is an input). + *
    + * + *
      + *
    • dst_channel: The channel index for the destination. + *
    • dst_bank: The bank index of the destination port's parent. + *
    • dst_runtime: The runtime index of the destination port's parent or the parent's + * parent (if destination is an output). + *
    + * + *

    For convenience, the above variable names are defined in the private class variables sc, sb, + * sr, and dc, db, dr. + * + *

    This block should NOT be nested, where each block is put within a similar block for the + * reactor's parent. Within the created block, every use of {@link + * CUtil#reactorRef(ReactorInstance, String)} and related functions must provide the above + * variable names. + * + *

    This must be followed by a call to {@link #endScopedRangeBlock(SendRange, RuntimeRange)}.x + * + * @param srcRange The send range. + * @param dstRange The destination range. + */ + public void startScopedRangeBlock(SendRange srcRange, RuntimeRange dstRange) { + var srcRangeMR = srcRange.startMR(); + var srcSizeMR = srcRangeMR.getRadixes().size(); + var srcNestedLevel = (srcRange.instance.isInput()) ? 2 : 1; + var dstNested = dstRange.instance.isOutput(); + + pr("// Iterate over ranges " + srcRange + " and " + dstRange + "."); + startScopedBlock(); + if (srcRange.width > 1) { + pr( + String.join( + "\n", + "int src_start[] = { " + joinObjects(srcRangeMR.getDigits(), ", ") + " };", + "int src_value[] = { " + + joinObjects(srcRangeMR.getDigits(), ", ") + + " }; // Will be incremented.", + "int src_radixes[] = { " + joinObjects(srcRangeMR.getRadixes(), ", ") + " };", + "int src_permutation[] = { " + joinObjects(srcRange.permutation(), ", ") + " };", + "mixed_radix_int_t src_range_mr = {", + " " + srcSizeMR + ",", + " src_value,", + " src_radixes,", + " src_permutation", + "};")); + } else { + var ciValue = srcRangeMR.getDigits().get(0); + var biValue = (srcSizeMR > 1) ? srcRangeMR.getDigits().get(1) : 0; + var riValue = srcRangeMR.get(srcNestedLevel); + pr( + String.join( + "\n", + "int " + sr + " = " + riValue + "; // Runtime index.", + "SUPPRESS_UNUSED_WARNING(" + sr + ");", + "int " + sc + " = " + ciValue + "; // Channel index.", + "SUPPRESS_UNUSED_WARNING(" + sc + ");", + "int " + sb + " = " + biValue + "; // Bank index.", + "SUPPRESS_UNUSED_WARNING(" + sb + ");")); } - /** - * Start a scoped block that iterates over the specified range of port channels. - * - * This must be followed by a call to - * {@link #endScopedRangeBlock(RuntimeRange)}. - * - * This block should NOT be nested, where each block is - * put within a similar block for the reactor's parent. - * Within the created block, every use of - * {@link CUtil#reactorRef(ReactorInstance, String)} - * must provide the second argument, a runtime index variable name, - * that must match the runtimeIndex parameter given here. - * - * @param range The range of port channels. - * @param runtimeIndex A variable name to use to index the runtime instance of - * either port's parent or the port's parent's parent (if nested is true), or - * null to use the default, "runtime_index". - * @param bankIndex A variable name to use to index the bank of the port's parent or null to use the - * default, the string returned by {@link CUtil#bankIndexName(ReactorInstance)}. - * @param channelIndex A variable name to use to index the channel or null to - * use the default, the string returned by {@link CUtil#channelIndexName(PortInstance)}. - * @param nested If true, then the runtimeIndex variable will be set - * to the bank index of the port's parent's parent rather than the - * port's parent. - */ - public void startScopedRangeBlock( - RuntimeRange range, - String runtimeIndex, - String bankIndex, - String channelIndex, - boolean nested - ) { - - pr("// Iterate over range "+range.toString()+"."); - var ri = (runtimeIndex == null)? "runtime_index" : runtimeIndex; - var ci = (channelIndex == null)? CUtil.channelIndexName(range.instance) : channelIndex; - var bi = (bankIndex == null)? CUtil.bankIndexName(range.instance.parent) : bankIndex; - var rangeMR = range.startMR(); - var sizeMR = rangeMR.getDigits().size(); - var nestedLevel = (nested) ? 2 : 1; - - startScopedBlock(); - if (range.width > 1) { - pr(String.join("\n", - "int range_start[] = { "+joinObjects(rangeMR.getDigits(), ", ")+" };", - "int range_radixes[] = { "+joinObjects(rangeMR.getRadixes(), ", ")+" };", - "int permutation[] = { "+joinObjects(range.permutation(), ", ")+" };", - "mixed_radix_int_t range_mr = {", - " "+sizeMR+",", - " range_start,", - " range_radixes,", - " permutation", - "};", - "for (int range_count = "+range.start+"; range_count < "+range.start+" + "+range.width+"; range_count++) {" - )); - indent(); - pr(String.join("\n", - "int "+ri+" = mixed_radix_parent(&range_mr, "+nestedLevel+"); // Runtime index.", - "SUPPRESS_UNUSED_WARNING("+ri+");", - "int "+ci+" = range_mr.digits[0]; // Channel index.", - "SUPPRESS_UNUSED_WARNING("+ci+");", - "int "+bi+" = "+(sizeMR <= 1 ? "0" : "range_mr.digits[1]")+"; // Bank index.", - "SUPPRESS_UNUSED_WARNING("+bi+");" - )); - - } else { - var ciValue = rangeMR.getDigits().get(0); - var riValue = rangeMR.get(nestedLevel); - var biValue = (sizeMR > 1)? rangeMR.getDigits().get(1) : 0; - pr(String.join("\n", - "int "+ri+" = "+riValue+"; SUPPRESS_UNUSED_WARNING("+ri+"); // Runtime index.", - "int "+ci+" = "+ciValue+"; SUPPRESS_UNUSED_WARNING("+ci+"); // Channel index.", - "int "+bi+" = "+biValue+"; SUPPRESS_UNUSED_WARNING("+bi+"); // Bank index.", - "int range_count = 0; SUPPRESS_UNUSED_WARNING(range_count);" - )); - } + startScopedRangeBlock(dstRange, dr, db, dc, dstNested); + + if (srcRange.width > 1) { + pr( + String.join( + "\n", + "int " + + sr + + " = mixed_radix_parent(&src_range_mr, " + + srcNestedLevel + + "); // Runtime index.", + "SUPPRESS_UNUSED_WARNING(" + sr + ");", + "int " + sc + " = src_range_mr.digits[0]; // Channel index.", + "SUPPRESS_UNUSED_WARNING(" + sc + ");", + "int " + + sb + + " = " + + (srcSizeMR <= 1 ? "0" : "src_range_mr.digits[1]") + + "; // Bank index.", + "SUPPRESS_UNUSED_WARNING(" + sb + ");")); } - - /** - * Start a scoped block that iterates over the specified pair of ranges. - * The destination range can be wider than the source range, in which case the - * source range is reused until the destination range is filled. - * The following integer variables will be defined within the scoped block: - * - *

      - *
    • src_channel: The channel index for the source.
    • - *
    • src_bank: The bank index of the source port's parent.
    • - *
    • src_runtime: The runtime index of the source port's parent or - * the parent's parent (if the source is an input).
    • - *
    - *
      - *
    • dst_channel: The channel index for the destination.
    • - *
    • dst_bank: The bank index of the destination port's parent.
    • - *
    • dst_runtime: The runtime index of the destination port's parent or - * the parent's parent (if destination is an output).
    • - *
    - * - *

    For convenience, the above variable names are defined in the private - * class variables sc, sb, sr, and dc, db, dr.

    - * - *

    This block should NOT be nested, where each block is - * put within a similar block for the reactor's parent. - * Within the created block, every use of - * {@link CUtil#reactorRef(ReactorInstance, String)} - * and related functions must provide the above variable names.

    - * - *

    This must be followed by a call to - * {@link #endScopedRangeBlock(SendRange, RuntimeRange)}.

    x - * - * @param srcRange The send range. - * @param dstRange The destination range. - */ - public void startScopedRangeBlock( - SendRange srcRange, - RuntimeRange dstRange - ) { - var srcRangeMR = srcRange.startMR(); - var srcSizeMR = srcRangeMR.getRadixes().size(); - var srcNestedLevel = (srcRange.instance.isInput()) ? 2 : 1; - var dstNested = dstRange.instance.isOutput(); - - pr("// Iterate over ranges "+srcRange+" and "+dstRange+"."); - startScopedBlock(); - if (srcRange.width > 1) { - pr(String.join("\n", - "int src_start[] = { "+joinObjects(srcRangeMR.getDigits(), ", ")+" };", - "int src_value[] = { "+joinObjects(srcRangeMR.getDigits(), ", ")+" }; // Will be incremented.", - "int src_radixes[] = { "+joinObjects(srcRangeMR.getRadixes(), ", ")+" };", - "int src_permutation[] = { "+joinObjects(srcRange.permutation(), ", ")+" };", - "mixed_radix_int_t src_range_mr = {", - " "+srcSizeMR+",", - " src_value,", - " src_radixes,", - " src_permutation", - "};" - )); - } else { - var ciValue = srcRangeMR.getDigits().get(0); - var biValue = (srcSizeMR > 1)? srcRangeMR.getDigits().get(1) : 0; - var riValue = srcRangeMR.get(srcNestedLevel); - pr(String.join("\n", - "int "+sr+" = "+riValue+"; // Runtime index.", - "SUPPRESS_UNUSED_WARNING("+sr+");", - "int "+sc+" = "+ciValue+"; // Channel index.", - "SUPPRESS_UNUSED_WARNING("+sc+");", - "int "+sb+" = "+biValue+"; // Bank index.", - "SUPPRESS_UNUSED_WARNING("+sb+");" - )); - } - - startScopedRangeBlock(dstRange, dr, db, dc, dstNested); - - if (srcRange.width > 1) { - pr(String.join("\n", - "int "+sr+" = mixed_radix_parent(&src_range_mr, "+srcNestedLevel+"); // Runtime index.", - "SUPPRESS_UNUSED_WARNING("+sr+");", - "int "+sc+" = src_range_mr.digits[0]; // Channel index.", - "SUPPRESS_UNUSED_WARNING("+sc+");", - "int "+sb+" = "+(srcSizeMR <= 1 ? "0" : "src_range_mr.digits[1]")+"; // Bank index.", - "SUPPRESS_UNUSED_WARNING("+sb+");" - )); - } + } + + public void endScopedBlock() { + unindent(); + pr("}"); + } + + /** + * If the specified port is a multiport, then start a specified iteration over the channels of the + * multiport using as the channel index the variable name returned by {@link + * CUtil#channelIndex(PortInstance)}. If the port is not a multiport, do nothing. + * + * @param port The port. + */ + public void endChannelIteration(PortInstance port) { + if (port.isMultiport) { + unindent(); + pr("}"); } - - public void endScopedBlock() { - unindent(); - pr("}"); + } + + /** + * End a scoped block to iterate over bank members and channels for the specified port with a + * variable with the name given by count counting the iterations. + * + * @param port The port. + * @param count The variable name to use for the counter, or null to not provide a counter. + */ + public void endScopedBankChannelIteration(PortInstance port, String count) { + if (count != null) { + pr(count + "++;"); } - - /** - * If the specified port is a multiport, then start a specified iteration - * over the channels of the multiport using as the channel index the - * variable name returned by {@link CUtil#channelIndex(PortInstance)}. - * If the port is not a multiport, do nothing. - * @param port The port. - */ - public void endChannelIteration(PortInstance port) { - if (port.isMultiport) { - unindent(); - pr("}"); - } + endChannelIteration(port); + endScopedBlock(); + if (count != null) { + endScopedBlock(); } - - /** - * End a scoped block to iterate over bank members and - * channels for the specified port with a variable with - * the name given by count counting the iterations. - * @param port The port. - * @param count The variable name to use for the counter, or - * null to not provide a counter. - */ - public void endScopedBankChannelIteration( - PortInstance port, String count - ) { - if (count != null) { - pr(count + "++;"); - } - endChannelIteration(port); - endScopedBlock(); - if (count != null) { - endScopedBlock(); - } + } + + /** + * End a scoped block for the specified range. + * + * @param range The send range. + */ + public void endScopedRangeBlock(RuntimeRange range) { + if (range.width > 1) { + pr("mixed_radix_incr(&range_mr);"); + endScopedBlock(); // Terminate for loop. } - - /** - * End a scoped block for the specified range. - * @param range The send range. - */ - public void endScopedRangeBlock( - RuntimeRange range - ) { - if (range.width > 1) { - pr("mixed_radix_incr(&range_mr);"); - endScopedBlock(); // Terminate for loop. - } - endScopedBlock(); - } - - /** - * End a scoped block that iterates over the specified pair of ranges. - * - * @param srcRange The send range. - * @param dstRange The destination range. - */ - public void endScopedRangeBlock( - SendRange srcRange, - RuntimeRange dstRange - ) { - if (srcRange.width > 1) { - pr(String.join("\n", - "mixed_radix_incr(&src_range_mr);", - "if (mixed_radix_to_int(&src_range_mr) >= "+srcRange.start+" + "+srcRange.width+") {", - " // Start over with the source.", - " for (int i = 0; i < src_range_mr.size; i++) {", - " src_range_mr.digits[i] = src_start[i];", - " }", - "}" - )); - } - if (dstRange.width > 1) { - pr("mixed_radix_incr(&range_mr);"); - endScopedBlock(); // Terminate for loop. - } - // Terminate unconditional scope block in startScopedRangeBlock calls. - endScopedBlock(); - endScopedBlock(); + endScopedBlock(); + } + + /** + * End a scoped block that iterates over the specified pair of ranges. + * + * @param srcRange The send range. + * @param dstRange The destination range. + */ + public void endScopedRangeBlock(SendRange srcRange, RuntimeRange dstRange) { + if (srcRange.width > 1) { + pr( + String.join( + "\n", + "mixed_radix_incr(&src_range_mr);", + "if (mixed_radix_to_int(&src_range_mr) >= " + + srcRange.start + + " + " + + srcRange.width + + ") {", + " // Start over with the source.", + " for (int i = 0; i < src_range_mr.size; i++) {", + " src_range_mr.digits[i] = src_start[i];", + " }", + "}")); } - - /** - * Return the code as a string. - */ - @Override - public String toString() { - return code.toString(); - } - - /** - * Reduce the indentation by one level for generated code/ - */ - public void unindent() { - indentation = indentation.substring(0, Math.max(0, indentation.length() - 4)); + if (dstRange.width > 1) { + pr("mixed_radix_incr(&range_mr);"); + endScopedBlock(); // Terminate for loop. } - - /** - * Write the text to a file. - * @param path The file to write the code to. - */ - public CodeMap writeToFile(String path) throws IOException { - CodeMap ret = CodeMap.fromGeneratedCode(code.toString()); - FileUtil.writeToFile(ret.getGeneratedCode(), Path.of(path), true); - return ret; - } - - //////////////////////////////////////////// - //// Private fields. - - /** Place to store the code. */ - private final StringBuilder code = new StringBuilder(); - - /** Current indentation. */ - private String indentation = ""; + // Terminate unconditional scope block in startScopedRangeBlock calls. + endScopedBlock(); + endScopedBlock(); + } + + /** Return the code as a string. */ + @Override + public String toString() { + return code.toString(); + } + + /** Reduce the indentation by one level for generated code/ */ + public void unindent() { + indentation = indentation.substring(0, Math.max(0, indentation.length() - 4)); + } + + /** + * Write the text to a file. + * + * @param path The file to write the code to. + */ + public CodeMap writeToFile(String path) throws IOException { + CodeMap ret = CodeMap.fromGeneratedCode(code.toString()); + FileUtil.writeToFile(ret.getGeneratedCode(), Path.of(path), true); + return ret; + } + + //////////////////////////////////////////// + //// Private fields. + + /** Place to store the code. */ + private final StringBuilder code = new StringBuilder(); + + /** Current indentation. */ + private String indentation = ""; } diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/src/org/lflang/generator/CodeMap.java index d00fe9bc9a..9d196c7daa 100644 --- a/org.lflang/src/org/lflang/generator/CodeMap.java +++ b/org.lflang/src/org/lflang/generator/CodeMap.java @@ -1,348 +1,320 @@ package org.lflang.generator; import java.nio.file.Path; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; -import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.util.LineAndColumn; - import org.lflang.lf.ParameterReference; -import org.lflang.lf.impl.ParameterReferenceImpl; /** - * Encapsulates data about the correspondence between - * ranges of generated code and ranges of a Lingua Franca - * file. + * Encapsulates data about the correspondence between ranges of generated code and ranges of a + * Lingua Franca file. */ public class CodeMap { - public static class Correspondence { - // This pattern has the markers "/* */", which some languages use as line comments. This does not - // represent any serious effort to embed the string representation of this object in generated code - // without introducing a syntax error. Instead, it is done simply because it is easy. - private static final Pattern PATTERN = Pattern.compile(String.format( - "/\\*Correspondence: (?%s) \\-> (?%s) \\(verbatim=(?true|false); src=(?%s)\\)\\*/", - Position.removeNamedCapturingGroups(Range.PATTERN), - Position.removeNamedCapturingGroups(Range.PATTERN), - ".*?" - )); - - private final Path path; - private final Range lfRange; - private final Range generatedRange; - private final boolean verbatim; - - /** - * Instantiates a Correspondence between - * {@code lfRange} at {@code path} and - * {@code generatedRange} in the generated file - * associated with this Correspondence. - * @param path a path to an LF source file - * @param lfRange a range in the given LF file - * @param generatedRange the range of generated code - * associated with - * {@code lfRange} - */ - private Correspondence(Path path, Range lfRange, Range generatedRange, boolean verbatim) { - this.path = path; - this.lfRange = lfRange; - this.generatedRange = generatedRange; - this.verbatim = verbatim; - } - - /** - * Returns a path to the LF source file described by - * this Correspondence. - * @return a path to the LF source file described by - * this Correspondence - */ - public Path getPath() { - return path; - } - - /** - * Returns a range in an LF source file. - * @return a range in an LF source file - */ - public Range getLfRange() { - return lfRange; - } + public static class Correspondence { + // This pattern has the markers "/* */", which some languages use as line comments. This does + // not + // represent any serious effort to embed the string representation of this object in generated + // code + // without introducing a syntax error. Instead, it is done simply because it is easy. + private static final Pattern PATTERN = + Pattern.compile( + String.format( + "/\\*Correspondence: (?%s) \\-> (?%s)" + + " \\(verbatim=(?true|false); src=(?%s)\\)\\*/", + Position.removeNamedCapturingGroups(Range.PATTERN), + Position.removeNamedCapturingGroups(Range.PATTERN), + ".*?")); - /** - * Returns a range in a generated file that - * corresponds to a range in an LF file. - * @return a range in a generated file that - * corresponds to a range in an LF file - */ - public Range getGeneratedRange() { - return generatedRange; - } + private final Path path; + private final Range lfRange; + private final Range generatedRange; + private final boolean verbatim; - @Override - public String toString() { - return String.format( - "/*Correspondence: %s -> %s (verbatim=%b; src=%s)*/", - lfRange.toString(), generatedRange.toString(), verbatim, path.toString() - ); - } - - /** - * Returns the Correspondence represented by - * {@code s}. - * @param s a String that represents a - * Correspondence, formatted like the - * output of Correspondence::toString - * @param relativeTo the offset relative to which - * the offsets given are given - * @return the Correspondence represented by - * {@code s} - */ - public static Correspondence fromString(String s, Position relativeTo) { - Matcher matcher = PATTERN.matcher(s); - if (matcher.matches()) { - Range lfRange = Range.fromString(matcher.group("lfRange")); - Range generatedRange = Range.fromString(matcher.group("generatedRange"), relativeTo); - return new Correspondence( - Path.of(matcher.group("path")), - lfRange, - generatedRange, - Boolean.parseBoolean(matcher.group("verbatim")) - ); - } - throw new IllegalArgumentException(String.format("Could not parse %s as a Correspondence.", s)); - } - - /** - * Returns {@code representation}, tagged with - * a Correspondence to the source code associated - * with {@code astNode}. - * @param astNode an arbitrary AST node - * @param representation the code generated from - * that AST node - * @param verbatim whether {@code representation} - * is copied verbatim from the - * part of the source code - * associated with {@code astNode} - * @return {@code representation}, tagged with - * a Correspondence to the source code associated - * with {@code astNode} - */ - public static String tag(EObject astNode, String representation, boolean verbatim) { - final INode node = NodeModelUtils.getNode(astNode); - // If the EObject originates from an AST transformation, then it does not correspond directly - // to any LF code, and it need not be tagged at all. - if (node == null) return representation; - final LineAndColumn oneBasedLfLineAndColumn = NodeModelUtils.getLineAndColumn(node, node.getTotalOffset()); - Position lfStart = Position.fromOneBased( - oneBasedLfLineAndColumn.getLine(), oneBasedLfLineAndColumn.getColumn() - ); - final URI uri = bestEffortGetEResource(astNode).getURI(); - if (uri == null) { - // no EResource, no correspondence can be found - return representation; - } - final Path lfPath = Path.of(uri.isFile() ? uri.toFileString() : uri.path()); - if (verbatim) lfStart = lfStart.plus(node.getText().substring(0, indexOf(node.getText(), representation))); - return new Correspondence( - lfPath, - new Range(lfStart, lfStart.plus(verbatim ? representation : node.getText())), - new Range(Position.ORIGIN, Position.displacementOf(representation)), - verbatim - ) + representation; - } - - /** - * Return the {@code eResource} associated with the given AST node. - * This is a dangerous operation which can cause an unrecoverable error. - */ - private static Resource bestEffortGetEResource(EObject astNode) { - if (astNode instanceof ParameterReference pri) { - return pri.getParameter().eResource(); - } - return astNode.eResource(); - } - - /** - * Make a best-effort attempt to find the index of - * a near substring whose first line is expected to - * be an exact substring of {@code s}. Return 0 - * upon failure. - * @param s an arbitrary string - * @param imperfectSubstring an approximate - * substring of {@code s} - * @return the index of {@code imperfectSubstring} - * within {@code s} - */ - private static int indexOf(String s, String imperfectSubstring) { - String firstLine = imperfectSubstring.lines().findFirst().orElse(""); - return Math.max(0, s.indexOf(firstLine)); - } + /** + * Instantiates a Correspondence between {@code lfRange} at {@code path} and {@code + * generatedRange} in the generated file associated with this Correspondence. + * + * @param path a path to an LF source file + * @param lfRange a range in the given LF file + * @param generatedRange the range of generated code associated with {@code lfRange} + */ + private Correspondence(Path path, Range lfRange, Range generatedRange, boolean verbatim) { + this.path = path; + this.lfRange = lfRange; + this.generatedRange = generatedRange; + this.verbatim = verbatim; } /** - * The content of the generated file represented by - * this. + * Returns a path to the LF source file described by this Correspondence. + * + * @return a path to the LF source file described by this Correspondence */ - private final String generatedCode; + public Path getPath() { + return path; + } + /** - * A mapping from Lingua Franca source paths to mappings - * from ranges in the generated file represented by this - * to ranges in Lingua Franca files. + * Returns a range in an LF source file. + * + * @return a range in an LF source file */ - private final Map> map; + public Range getLfRange() { + return lfRange; + } + /** - * 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. + * Returns a range in a generated file that corresponds to a range in an LF file. + * + * @return a range in a generated file that corresponds to a range in an LF file */ - private final Map> isVerbatimByLfSourceByRange; + public Range getGeneratedRange() { + return generatedRange; + } - /* ------------------------- PUBLIC METHODS -------------------------- */ + @Override + public String toString() { + return String.format( + "/*Correspondence: %s -> %s (verbatim=%b; src=%s)*/", + lfRange.toString(), generatedRange.toString(), verbatim, path.toString()); + } /** - * Instantiates a {@code CodeMap} from - * {@code internalGeneratedCode}. - * {@code internalGeneratedCode} may be invalid - * code that is different from the final generated code - * because it should contain deserializable - * representations of {@code Correspondences}. - * @param internalGeneratedCode code from a code - * generator that contains - * serialized - * Correspondences - * @return a CodeMap documenting the provided code + * Returns the Correspondence represented by {@code s}. + * + * @param s a String that represents a Correspondence, formatted like the output of + * Correspondence::toString + * @param relativeTo the offset relative to which the offsets given are given + * @return the Correspondence represented by {@code s} */ - public static CodeMap fromGeneratedCode(String internalGeneratedCode) { - Map> map = new HashMap<>(); - Map> isVerbatimByLfSourceByRange = new HashMap<>(); - StringBuilder generatedCode = new StringBuilder(); - Iterator it = internalGeneratedCode.lines().iterator(); - int zeroBasedLine = 0; - while (it.hasNext()) { - generatedCode.append(processGeneratedLine(it.next(), zeroBasedLine++, map, isVerbatimByLfSourceByRange)).append('\n'); - } - return new CodeMap(generatedCode.toString(), map, isVerbatimByLfSourceByRange); + public static Correspondence fromString(String s, Position relativeTo) { + Matcher matcher = PATTERN.matcher(s); + if (matcher.matches()) { + Range lfRange = Range.fromString(matcher.group("lfRange")); + Range generatedRange = Range.fromString(matcher.group("generatedRange"), relativeTo); + return new Correspondence( + Path.of(matcher.group("path")), + lfRange, + generatedRange, + Boolean.parseBoolean(matcher.group("verbatim"))); + } + throw new IllegalArgumentException( + String.format("Could not parse %s as a Correspondence.", s)); } /** - * Returns the generated code (without Correspondences). - * @return the generated code (without Correspondences) + * Returns {@code representation}, tagged with a Correspondence to the source code associated + * with {@code astNode}. + * + * @param astNode an arbitrary AST node + * @param representation the code generated from that AST node + * @param verbatim whether {@code representation} is copied verbatim from the part of the source + * code associated with {@code astNode} + * @return {@code representation}, tagged with a Correspondence to the source code associated + * with {@code astNode} */ - public String getGeneratedCode() { - return generatedCode; + public static String tag(EObject astNode, String representation, boolean verbatim) { + final INode node = NodeModelUtils.getNode(astNode); + // If the EObject originates from an AST transformation, then it does not correspond directly + // to any LF code, and it need not be tagged at all. + if (node == null) return representation; + final LineAndColumn oneBasedLfLineAndColumn = + NodeModelUtils.getLineAndColumn(node, node.getTotalOffset()); + Position lfStart = + Position.fromOneBased( + oneBasedLfLineAndColumn.getLine(), oneBasedLfLineAndColumn.getColumn()); + final URI uri = bestEffortGetEResource(astNode).getURI(); + if (uri == null) { + // no EResource, no correspondence can be found + return representation; + } + final Path lfPath = Path.of(uri.isFile() ? uri.toFileString() : uri.path()); + if (verbatim) + lfStart = + lfStart.plus(node.getText().substring(0, indexOf(node.getText(), representation))); + return new Correspondence( + lfPath, + new Range(lfStart, lfStart.plus(verbatim ? representation : node.getText())), + new Range(Position.ORIGIN, Position.displacementOf(representation)), + verbatim) + + representation; } /** - * Returns the set of all paths to Lingua Franca files - * that are known to contain code that corresponds to - * code in the generated file represented by this. + * Return the {@code eResource} associated with the given AST node. This is a dangerous + * operation which can cause an unrecoverable error. */ - public Set lfSourcePaths() { - return map.keySet(); + private static Resource bestEffortGetEResource(EObject astNode) { + if (astNode instanceof ParameterReference pri) { + return pri.getParameter().eResource(); + } + return astNode.eResource(); } /** - * Returns the position in {@code lfFile} - * corresponding to {@code generatedFilePosition} - * if such a position is known, or the zero Position - * otherwise. - * @param lfFile the path to an arbitrary Lingua Franca - * source file - * @param generatedFilePosition a position in a - * generated file - * @return the position in {@code lfFile} - * corresponding to {@code generatedFilePosition} + * Make a best-effort attempt to find the index of a near substring whose first line is expected + * to be an exact substring of {@code s}. Return 0 upon failure. + * + * @param s an arbitrary string + * @param imperfectSubstring an approximate substring of {@code s} + * @return the index of {@code imperfectSubstring} within {@code s} */ - public Position adjusted(Path lfFile, Position generatedFilePosition) { - NavigableMap mapOfInterest = map.get(lfFile); - Map isVerbatimByRange = isVerbatimByLfSourceByRange.get(lfFile); - Map.Entry nearestEntry = mapOfInterest.floorEntry(Range.degenerateRange(generatedFilePosition)); - if (nearestEntry == null) return Position.ORIGIN; - if (!isVerbatimByRange.get(nearestEntry.getKey())) { - return nearestEntry.getValue().getStartInclusive(); - } - if (nearestEntry.getKey().contains(generatedFilePosition)) { - return nearestEntry.getValue().getStartInclusive().plus( - generatedFilePosition.minus(nearestEntry.getKey().getStartInclusive()) - ); - } - return Position.ORIGIN; + private static int indexOf(String s, String imperfectSubstring) { + String firstLine = imperfectSubstring.lines().findFirst().orElse(""); + return Math.max(0, s.indexOf(firstLine)); } + } - /** - * Returns the range in {@code lfFile} - * corresponding to {@code generatedFileRange} - * if such a range is known, or a degenerate Range - * otherwise. - * @param lfFile the path to an arbitrary Lingua Franca - * source file - * @param generatedFileRange a position in a - * generated file - * @return the range in {@code lfFile} - * corresponding to {@code generatedFileRange} - */ - public Range adjusted(Path lfFile, Range generatedFileRange) { - final Position start = adjusted(lfFile, generatedFileRange.getStartInclusive()); - final Position end = adjusted(lfFile, generatedFileRange.getEndExclusive()); - return start.compareTo(end) <= 0 ? new Range(start, end) : new Range(start, start); + /** 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. + */ + private final Map> isVerbatimByLfSourceByRange; + + /* ------------------------- PUBLIC METHODS -------------------------- */ + + /** + * Instantiates a {@code CodeMap} from {@code internalGeneratedCode}. {@code + * internalGeneratedCode} may be invalid code that is different from the final generated code + * because it should contain deserializable representations of {@code Correspondences}. + * + * @param internalGeneratedCode code from a code generator that contains serialized + * Correspondences + * @return a CodeMap documenting the provided code + */ + public static CodeMap fromGeneratedCode(String internalGeneratedCode) { + Map> map = new HashMap<>(); + Map> isVerbatimByLfSourceByRange = new HashMap<>(); + StringBuilder generatedCode = new StringBuilder(); + Iterator it = internalGeneratedCode.lines().iterator(); + int zeroBasedLine = 0; + while (it.hasNext()) { + generatedCode + .append( + processGeneratedLine(it.next(), zeroBasedLine++, map, isVerbatimByLfSourceByRange)) + .append('\n'); } + return new CodeMap(generatedCode.toString(), map, isVerbatimByLfSourceByRange); + } - /* ------------------------- PRIVATE METHODS ------------------------- */ + /** + * Returns the generated code (without Correspondences). + * + * @return the generated code (without Correspondences) + */ + public String getGeneratedCode() { + return generatedCode; + } - private CodeMap( - String generatedCode, Map> map, - Map> isVerbatimByLfSourceByRange - ) { - this.generatedCode = generatedCode; - this.map = map; - this.isVerbatimByLfSourceByRange = isVerbatimByLfSourceByRange; + /** + * Returns the set of all paths to Lingua Franca files that are known to contain code that + * corresponds to code in the generated file represented by this. + */ + public Set lfSourcePaths() { + return map.keySet(); + } + + /** + * Returns the position in {@code lfFile} corresponding to {@code generatedFilePosition} if such a + * position is known, or the zero Position otherwise. + * + * @param lfFile the path to an arbitrary Lingua Franca source file + * @param generatedFilePosition a position in a generated file + * @return the position in {@code lfFile} corresponding to {@code generatedFilePosition} + */ + public Position adjusted(Path lfFile, Position generatedFilePosition) { + NavigableMap mapOfInterest = map.get(lfFile); + Map isVerbatimByRange = isVerbatimByLfSourceByRange.get(lfFile); + Map.Entry nearestEntry = + mapOfInterest.floorEntry(Range.degenerateRange(generatedFilePosition)); + if (nearestEntry == null) return Position.ORIGIN; + if (!isVerbatimByRange.get(nearestEntry.getKey())) { + return nearestEntry.getValue().getStartInclusive(); + } + if (nearestEntry.getKey().contains(generatedFilePosition)) { + return nearestEntry + .getValue() + .getStartInclusive() + .plus(generatedFilePosition.minus(nearestEntry.getKey().getStartInclusive())); } + return Position.ORIGIN; + } - /** - * Removes serialized Correspondences from {@code line} - * and updates {@code map} according to those - * Correspondences. - * @param line a line of generated code - * @param zeroBasedLineIndex the index of the given line - * @param map a map that stores Correspondences - * @return the line of generated code with all - * Correspondences removed - */ - private static String processGeneratedLine( - String line, - int zeroBasedLineIndex, - Map> map, - Map> isVerbatimByLfSourceByRange - ) { - Matcher matcher = Correspondence.PATTERN.matcher(line); - StringBuilder cleanedLine = new StringBuilder(); - int lastEnd = 0; - while (matcher.find()) { - cleanedLine.append(line, lastEnd, matcher.start()); - Correspondence c = Correspondence.fromString( - matcher.group(), - Position.fromZeroBased(zeroBasedLineIndex, cleanedLine.length()) - ); - if (!map.containsKey(c.path)) map.put(c.path, new TreeMap<>()); - map.get(c.path).put(c.generatedRange, c.lfRange); - if (!isVerbatimByLfSourceByRange.containsKey(c.path)) isVerbatimByLfSourceByRange.put(c.path, new HashMap<>()); - isVerbatimByLfSourceByRange.get(c.path).put(c.generatedRange, c.verbatim); - lastEnd = matcher.end(); - } - cleanedLine.append(line.substring(lastEnd)); - return cleanedLine.toString(); + /** + * Returns the range in {@code lfFile} corresponding to {@code generatedFileRange} if such a range + * is known, or a degenerate Range otherwise. + * + * @param lfFile the path to an arbitrary Lingua Franca source file + * @param generatedFileRange a position in a generated file + * @return the range in {@code lfFile} corresponding to {@code generatedFileRange} + */ + public Range adjusted(Path lfFile, Range generatedFileRange) { + final Position start = adjusted(lfFile, generatedFileRange.getStartInclusive()); + final Position end = adjusted(lfFile, generatedFileRange.getEndExclusive()); + return start.compareTo(end) <= 0 ? new Range(start, end) : new Range(start, start); + } + + /* ------------------------- PRIVATE METHODS ------------------------- */ + + private CodeMap( + String generatedCode, + Map> map, + Map> isVerbatimByLfSourceByRange) { + this.generatedCode = generatedCode; + this.map = map; + this.isVerbatimByLfSourceByRange = isVerbatimByLfSourceByRange; + } + + /** + * Removes serialized Correspondences from {@code line} and updates {@code map} according to those + * Correspondences. + * + * @param line a line of generated code + * @param zeroBasedLineIndex the index of the given line + * @param map a map that stores Correspondences + * @return the line of generated code with all Correspondences removed + */ + private static String processGeneratedLine( + String line, + int zeroBasedLineIndex, + Map> map, + Map> isVerbatimByLfSourceByRange) { + Matcher matcher = Correspondence.PATTERN.matcher(line); + StringBuilder cleanedLine = new StringBuilder(); + int lastEnd = 0; + while (matcher.find()) { + cleanedLine.append(line, lastEnd, matcher.start()); + Correspondence c = + Correspondence.fromString( + matcher.group(), Position.fromZeroBased(zeroBasedLineIndex, cleanedLine.length())); + if (!map.containsKey(c.path)) map.put(c.path, new TreeMap<>()); + map.get(c.path).put(c.generatedRange, c.lfRange); + if (!isVerbatimByLfSourceByRange.containsKey(c.path)) + isVerbatimByLfSourceByRange.put(c.path, new HashMap<>()); + isVerbatimByLfSourceByRange.get(c.path).put(c.generatedRange, c.verbatim); + lastEnd = matcher.end(); } + cleanedLine.append(line.substring(lastEnd)); + return cleanedLine.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/DeadlineInstance.java b/org.lflang/src/org/lflang/generator/DeadlineInstance.java index 208c116791..e73f6b8f9b 100644 --- a/org.lflang/src/org/lflang/generator/DeadlineInstance.java +++ b/org.lflang/src/org/lflang/generator/DeadlineInstance.java @@ -1,29 +1,29 @@ /** A data structure for a deadline instance. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; @@ -31,41 +31,37 @@ import org.lflang.lf.Deadline; /** - * Instance of a deadline. Upon creation the actual delay is converted into - * a proper time value. If a parameter is referenced, it is looked up in the - * given (grand)parent reactor instance. - * + * Instance of a deadline. Upon creation the actual delay is converted into a proper time value. If + * a parameter is referenced, it is looked up in the given (grand)parent reactor instance. + * * @author Marten Lohstroh * @author Edward A. Lee */ public class DeadlineInstance { - - /** - * Create a new deadline instance associated with the given reaction - * instance. - */ - public DeadlineInstance(Deadline definition, ReactionInstance reaction) { - if (definition.getDelay() != null) { - this.maxDelay = reaction.parent.getTimeValue(definition.getDelay()); - } else { - this.maxDelay = TimeValue.ZERO; - } + + /** Create a new deadline instance associated with the given reaction instance. */ + public DeadlineInstance(Deadline definition, ReactionInstance reaction) { + if (definition.getDelay() != null) { + this.maxDelay = reaction.parent.getTimeValue(definition.getDelay()); + } else { + this.maxDelay = TimeValue.ZERO; } + } - ////////////////////////////////////////////////////// - //// Public fields. + ////////////////////////////////////////////////////// + //// Public fields. - /** - * The delay D associated with this deadline. If physical time T < logical - * time t + D, the deadline is met, otherwise, it is violated. - */ - public final TimeValue maxDelay; + /** + * The delay D associated with this deadline. If physical time T < logical time t + D, the + * deadline is met, otherwise, it is violated. + */ + public final TimeValue maxDelay; - ////////////////////////////////////////////////////// - //// Public methods. - - @Override - public String toString() { - return "DeadlineInstance " + maxDelay.toString(); - } + ////////////////////////////////////////////////////// + //// Public methods. + + @Override + public String toString() { + return "DeadlineInstance " + maxDelay.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/DelayBodyGenerator.java b/org.lflang/src/org/lflang/generator/DelayBodyGenerator.java index 39742a3488..240eba7bc1 100644 --- a/org.lflang/src/org/lflang/generator/DelayBodyGenerator.java +++ b/org.lflang/src/org/lflang/generator/DelayBodyGenerator.java @@ -6,54 +6,47 @@ public interface DelayBodyGenerator { - /** - * Constant that specifies how to name generated delay reactors. - */ - String GEN_DELAY_CLASS_NAME = "_lf_GenDelay"; - - /** - * Generate code for the body of a reaction that takes an input and - * schedules an action with the value of that input. - * - * @param action the action to schedule - * @param port the port to read from - */ - String generateDelayBody(Action action, VarRef port); - - /** - * Generate code for the body of a reaction that is triggered by the - * given action and writes its value to the given port. - * - * @param action the action that triggers the reaction - * @param port the port to write to - */ - String generateForwardBody(Action action, VarRef port); - - /** - * Generate code for the generic type to be used in the class definition - * of a generated delay reactor. - */ - String generateDelayGeneric(); - - /** - * Indicates whether delay banks generated from after delays should have a variable length - * width. - *

    - * If this is true, any delay reactors that are inserted for after delays on multiport - * connections - * will have an unspecified variable length width. The code generator is then responsible for - * inferring the - * correct width of the delay bank, which is only possible if the precise connection width is - * known at compile time. - *

    - * If this is false, the width specification of the generated bank will list all the ports - * listed on the right - * side of the connection. This gives the code generator the information needed to infer the - * correct width at - * runtime. - */ - boolean generateAfterDelaysWithVariableWidth(); - - /** Used to optionally apply additional transformations to the generated reactions */ - default void finalizeReactions(Reaction delayReaction, Reaction forwardReaction) { } + /** Constant that specifies how to name generated delay reactors. */ + String GEN_DELAY_CLASS_NAME = "_lf_GenDelay"; + + /** + * Generate code for the body of a reaction that takes an input and schedules an action with the + * value of that input. + * + * @param action the action to schedule + * @param port the port to read from + */ + String generateDelayBody(Action action, VarRef port); + + /** + * Generate code for the body of a reaction that is triggered by the given action and writes its + * value to the given port. + * + * @param action the action that triggers the reaction + * @param port the port to write to + */ + String generateForwardBody(Action action, VarRef port); + + /** + * Generate code for the generic type to be used in the class definition of a generated delay + * reactor. + */ + String generateDelayGeneric(); + + /** + * Indicates whether delay banks generated from after delays should have a variable length width. + * + *

    If this is true, any delay reactors that are inserted for after delays on multiport + * connections will have an unspecified variable length width. The code generator is then + * responsible for inferring the correct width of the delay bank, which is only possible if the + * precise connection width is known at compile time. + * + *

    If this is false, the width specification of the generated bank will list all the ports + * listed on the right side of the connection. This gives the code generator the information + * needed to infer the correct width at runtime. + */ + boolean generateAfterDelaysWithVariableWidth(); + + /** Used to optionally apply additional transformations to the generated reactions */ + default void finalizeReactions(Reaction delayReaction, Reaction forwardReaction) {} } diff --git a/org.lflang/src/org/lflang/generator/DiagnosticReporting.java b/org.lflang/src/org/lflang/generator/DiagnosticReporting.java index 82d3535444..871f417a0d 100644 --- a/org.lflang/src/org/lflang/generator/DiagnosticReporting.java +++ b/org.lflang/src/org/lflang/generator/DiagnosticReporting.java @@ -2,59 +2,62 @@ import java.nio.file.Path; import java.util.Map; - import org.eclipse.lsp4j.DiagnosticSeverity; - import org.lflang.ErrorReporter; /** - * {@code DiagnosticReporting} provides utilities for - * reporting validation output. + * {@code DiagnosticReporting} provides utilities for reporting validation output. * * @author Peter Donovan */ public class DiagnosticReporting { - private DiagnosticReporting() { - // utility class - } - - /** - * A means of parsing the output of a validator. - */ - @FunctionalInterface public interface Strategy { - /** - * Parse the validation output and report any errors - * that it contains. - * @param validationOutput any validation output - * @param errorReporter any error reporter - * @param map the map from generated files to CodeMaps - */ - void report(String validationOutput, ErrorReporter errorReporter, Map map); - } - - /** - * Format the given data as a human-readable message. - * @param message An error message. - * @param path The path of the source of the message. - * @param position The position where the message originates. - * @return The given data as a human-readable message. - */ - public static String messageOf(String message, Path path, Position position) { - return String.format("%s [%s:%s:%s]", message, path.getFileName().toString(), position.getOneBasedLine(), position.getOneBasedColumn()); - } + private DiagnosticReporting() { + // utility class + } + /** A means of parsing the output of a validator. */ + @FunctionalInterface + public interface Strategy { /** - * Convert {@code severity} into a {@code DiagnosticSeverity} using a heuristic that should be - * compatible with many tools. - * @param severity The string representation of a diagnostic severity. - * @return The {@code DiagnosticSeverity} representation of {@code severity}. + * Parse the validation output and report any errors that it contains. + * + * @param validationOutput any validation output + * @param errorReporter any error reporter + * @param map the map from generated files to CodeMaps */ - public static DiagnosticSeverity severityOf(String severity) { - severity = severity.toLowerCase(); - if (severity.contains("error")) return DiagnosticSeverity.Error; - else if (severity.contains("warning")) return DiagnosticSeverity.Warning; - else if (severity.contains("hint") || severity.contains("help")) return DiagnosticSeverity.Hint; - else return DiagnosticSeverity.Information; - } + void report(String validationOutput, ErrorReporter errorReporter, Map map); + } + + /** + * Format the given data as a human-readable message. + * + * @param message An error message. + * @param path The path of the source of the message. + * @param position The position where the message originates. + * @return The given data as a human-readable message. + */ + public static String messageOf(String message, Path path, Position position) { + return String.format( + "%s [%s:%s:%s]", + message, + path.getFileName().toString(), + position.getOneBasedLine(), + position.getOneBasedColumn()); + } + + /** + * Convert {@code severity} into a {@code DiagnosticSeverity} using a heuristic that should be + * compatible with many tools. + * + * @param severity The string representation of a diagnostic severity. + * @return The {@code DiagnosticSeverity} representation of {@code severity}. + */ + public static DiagnosticSeverity severityOf(String severity) { + severity = severity.toLowerCase(); + if (severity.contains("error")) return DiagnosticSeverity.Error; + else if (severity.contains("warning")) return DiagnosticSeverity.Warning; + else if (severity.contains("hint") || severity.contains("help")) return DiagnosticSeverity.Hint; + else return DiagnosticSeverity.Information; + } } diff --git a/org.lflang/src/org/lflang/generator/DockerComposeGenerator.java b/org.lflang/src/org/lflang/generator/DockerComposeGenerator.java index 040d925614..a3e5028317 100644 --- a/org.lflang/src/org/lflang/generator/DockerComposeGenerator.java +++ b/org.lflang/src/org/lflang/generator/DockerComposeGenerator.java @@ -4,7 +4,6 @@ import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; - import org.lflang.util.FileUtil; /** @@ -15,109 +14,104 @@ */ public class DockerComposeGenerator { - /** - * Path to the docker-compose.yml file. - */ - protected final Path path; + /** Path to the docker-compose.yml file. */ + protected final Path path; - public DockerComposeGenerator(LFGeneratorContext context) { - this.path = context.getFileConfig().getSrcGenPath().resolve("docker-compose.yml"); - } + public DockerComposeGenerator(LFGeneratorContext context) { + this.path = context.getFileConfig().getSrcGenPath().resolve("docker-compose.yml"); + } - /** - * Return a string that represents the network portion of the docker-compose configuration. - * @param networkName Name of the default network - */ - protected String generateDockerNetwork(String networkName) { - return """ + /** + * Return a string that represents the network portion of the docker-compose configuration. + * + * @param networkName Name of the default network + */ + protected String generateDockerNetwork(String networkName) { + return """ networks: default: name: "%s" - """.formatted(networkName); - } + """ + .formatted(networkName); + } - /** - * Return a string that represents the services portion of the docker-compose configuration. - * @param services A list of docker data representing the services to render - */ - protected String generateDockerServices(List services) { - return """ - version: "3.9" + /** + * Return a string that represents the services portion of the docker-compose configuration. + * + * @param services A list of docker data representing the services to render + */ + protected String generateDockerServices(List services) { + return """ + version: "3.9" services: %s - """.formatted(services.stream().map( - data -> getServiceDescription(data) - ).collect(Collectors.joining("\n"))); - } + """ + .formatted( + services.stream() + .map(data -> getServiceDescription(data)) + .collect(Collectors.joining("\n"))); + } - /** - * Return the command to build and run using the docker-compose configuration. - */ - public String getUsageInstructions() { - return """ + /** Return the command to build and run using the docker-compose configuration. */ + public String getUsageInstructions() { + return """ ##################################### To build and run: pushd %s && docker compose up --build To return to the current working directory afterwards: popd ##################################### - """.formatted(path.getParent()); - } + """ + .formatted(path.getParent()); + } - /** - * Turn given docker data into a string. - */ - protected String getServiceDescription(DockerData data) { - return """ + /** Turn given docker data into a string. */ + protected String getServiceDescription(DockerData data) { + return """ %s: build: context: "%s" container_name: "%s" - """.formatted(getServiceName(data), getBuildContext(data), getContainerName(data)); - } + """ + .formatted(getServiceName(data), getBuildContext(data), getContainerName(data)); + } - /** - * Return the name of the service represented by the given data. - */ - protected String getServiceName(DockerData data) { - return "main"; - } + /** Return the name of the service represented by the given data. */ + protected String getServiceName(DockerData data) { + return "main"; + } - /** - * Return the name of the service represented by the given data. - */ - protected String getBuildContext(DockerData data) { - return "."; - } + /** Return the name of the service represented by the given data. */ + protected String getBuildContext(DockerData data) { + return "."; + } - /** - * Return the name of the container for the given data. - */ - protected String getContainerName(DockerData data) { - return data.serviceName; - } + /** Return the name of the container for the given data. */ + protected String getContainerName(DockerData data) { + return data.serviceName; + } - /** - * Write the docker-compose.yml file with a default network called "lf". - * @param services A list of all the services. - */ - public void writeDockerComposeFile(List services) throws IOException { - writeDockerComposeFile(services, "lf"); - } + /** + * Write the docker-compose.yml file with a default network called "lf". + * + * @param services A list of all the services. + */ + public void writeDockerComposeFile(List services) throws IOException { + writeDockerComposeFile(services, "lf"); + } - /** - * Write the docker-compose.yml file. - * @param services A list of all the services to include. - * @param networkName The name of the network to which docker will connect the services. - */ - public void writeDockerComposeFile( - List services, - String networkName - ) throws IOException { - var contents = String.join("\n", - this.generateDockerServices(services), - this.generateDockerNetwork(networkName)); - FileUtil.writeToFile(contents, path); - System.out.println(getUsageInstructions()); - } + /** + * Write the docker-compose.yml file. + * + * @param services A list of all the services to include. + * @param networkName The name of the network to which docker will connect the services. + */ + public void writeDockerComposeFile(List services, String networkName) + throws IOException { + var contents = + String.join( + "\n", this.generateDockerServices(services), this.generateDockerNetwork(networkName)); + FileUtil.writeToFile(contents, path); + System.out.println(getUsageInstructions()); + } } diff --git a/org.lflang/src/org/lflang/generator/DockerData.java b/org.lflang/src/org/lflang/generator/DockerData.java index a2b1927125..af29e9e1d5 100644 --- a/org.lflang/src/org/lflang/generator/DockerData.java +++ b/org.lflang/src/org/lflang/generator/DockerData.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.nio.file.Path; - import org.lflang.util.FileUtil; /** @@ -11,43 +10,31 @@ * @author Marten Lohstroh */ public class DockerData { - /** - * The absolute path to the docker file. - */ - private final Path dockerFilePath; + /** The absolute path to the docker file. */ + private final Path dockerFilePath; - /** - * The content of the docker file to be generated. - */ - private final String dockerFileContent; + /** The content of the docker file to be generated. */ + private final String dockerFileContent; - /** - * The name of the service. - */ - public final String serviceName; + /** The name of the service. */ + public final String serviceName; - public DockerData( - String serviceName, - Path dockerFilePath, - String dockerFileContent - ) { + public DockerData(String serviceName, Path dockerFilePath, String dockerFileContent) { - if (!dockerFilePath.toFile().isAbsolute()) { - throw new RuntimeException("Cannot use relative docker file path in DockerData instance"); - } - this.serviceName = serviceName; - this.dockerFilePath = dockerFilePath; - this.dockerFileContent = dockerFileContent; + if (!dockerFilePath.toFile().isAbsolute()) { + throw new RuntimeException("Cannot use relative docker file path in DockerData instance"); } - - /** - * Write a docker file based on this data. - */ - public void writeDockerFile() throws IOException { - if (dockerFilePath.toFile().exists()) { - dockerFilePath.toFile().delete(); - } - FileUtil.writeToFile(dockerFileContent, dockerFilePath); - System.out.println("Dockerfile written to " + dockerFilePath); + this.serviceName = serviceName; + this.dockerFilePath = dockerFilePath; + this.dockerFileContent = dockerFileContent; + } + + /** Write a docker file based on this data. */ + public void writeDockerFile() throws IOException { + if (dockerFilePath.toFile().exists()) { + dockerFilePath.toFile().delete(); } + FileUtil.writeToFile(dockerFileContent, dockerFilePath); + System.out.println("Dockerfile written to " + dockerFilePath); + } } diff --git a/org.lflang/src/org/lflang/generator/DockerGenerator.java b/org.lflang/src/org/lflang/generator/DockerGenerator.java index 851ee6c0be..cf6044f14f 100644 --- a/org.lflang/src/org/lflang/generator/DockerGenerator.java +++ b/org.lflang/src/org/lflang/generator/DockerGenerator.java @@ -4,7 +4,6 @@ import org.lflang.generator.python.PythonDockerGenerator; import org.lflang.generator.ts.TSDockerGenerator; - /** * A class for generating docker files. * @@ -13,46 +12,43 @@ */ public abstract class DockerGenerator { - /** - * Configuration for interactions with the filesystem. - */ - protected final LFGeneratorContext context; - - /** - * The constructor for the base docker file generation class. - * @param context The context of the code generator. - */ - public DockerGenerator(LFGeneratorContext context) { - this.context = context; - - } - - /** - * Generate the contents of a Dockerfile. - */ - protected abstract String generateDockerFileContent(); - - /** - * Produce a DockerData object. - * If the returned object is to be used in a federated context, - * pass in the file configuration of the federated generator, null otherwise. - * @return docker data created based on the context in this instance - */ - public DockerData generateDockerData() { - var name = context.getFileConfig().name; - var dockerFilePath = context.getFileConfig().getSrcGenPath().resolve("Dockerfile"); - var dockerFileContent = generateDockerFileContent(); - - return new DockerData(name.replace("_", ""), dockerFilePath, dockerFileContent); - } - - public static DockerGenerator dockerGeneratorFactory(LFGeneratorContext context) { - var target = context.getTargetConfig().target; - return switch (target) { - 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."); - }; - } + /** Configuration for interactions with the filesystem. */ + protected final LFGeneratorContext context; + + /** + * The constructor for the base docker file generation class. + * + * @param context The context of the code generator. + */ + public DockerGenerator(LFGeneratorContext context) { + this.context = context; + } + + /** Generate the contents of a Dockerfile. */ + protected abstract String generateDockerFileContent(); + + /** + * Produce a DockerData object. If the returned object is to be used in a federated context, pass + * in the file configuration of the federated generator, null otherwise. + * + * @return docker data created based on the context in this instance + */ + public DockerData generateDockerData() { + var name = context.getFileConfig().name; + var dockerFilePath = context.getFileConfig().getSrcGenPath().resolve("Dockerfile"); + var dockerFileContent = generateDockerFileContent(); + + return new DockerData(name.replace("_", ""), dockerFilePath, dockerFileContent); + } + + public static DockerGenerator dockerGeneratorFactory(LFGeneratorContext context) { + var target = context.getTargetConfig().target; + return switch (target) { + 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."); + }; + } } diff --git a/org.lflang/src/org/lflang/generator/FedDockerComposeGenerator.java b/org.lflang/src/org/lflang/generator/FedDockerComposeGenerator.java index d666abba2d..18896f03a0 100644 --- a/org.lflang/src/org/lflang/generator/FedDockerComposeGenerator.java +++ b/org.lflang/src/org/lflang/generator/FedDockerComposeGenerator.java @@ -1,6 +1,5 @@ package org.lflang.generator; - import java.util.List; /** @@ -10,57 +9,55 @@ */ public class FedDockerComposeGenerator extends DockerComposeGenerator { - /** - * The host on which to run the rti. - */ - private String rtiHost; + /** The host on which to run the rti. */ + private String rtiHost; - /** - * The name of this federation. - */ - private String containerName; + /** The name of this federation. */ + private String containerName; - public FedDockerComposeGenerator(LFGeneratorContext context, String rtiHost) { - super(context); - this.rtiHost = rtiHost; - this.containerName = context.getFileConfig().name; - } + public FedDockerComposeGenerator(LFGeneratorContext context, String rtiHost) { + super(context); + this.rtiHost = rtiHost; + this.containerName = context.getFileConfig().name; + } - @Override - protected String generateDockerServices(List services) { - return """ + @Override + protected String generateDockerServices(List services) { + return """ %s\ rti: image: "lflang/rti:rti" hostname: "%s" command: "-i 1 -n %s" container_name: "%s-rti" - """.formatted(super.generateDockerServices(services), - this.rtiHost, services.size(), containerName); - } - - @Override - protected String getServiceDescription(DockerData data) { - return """ + """ + .formatted( + super.generateDockerServices(services), this.rtiHost, services.size(), containerName); + } + + @Override + protected String getServiceDescription(DockerData data) { + return """ %s\ command: "-i 1" depends_on: - rti - """.formatted(super.getServiceDescription(data)); - } - - @Override - protected String getServiceName(DockerData data) { - return data.serviceName; - } - - @Override - protected String getBuildContext(DockerData data) { - return data.serviceName; - } - - @Override - protected String getContainerName(DockerData data) { - return this.containerName + "-" + data.serviceName; - } + """ + .formatted(super.getServiceDescription(data)); + } + + @Override + protected String getServiceName(DockerData data) { + return data.serviceName; + } + + @Override + protected String getBuildContext(DockerData data) { + return data.serviceName; + } + + @Override + protected String getContainerName(DockerData data) { + return this.containerName + "-" + data.serviceName; + } } diff --git a/org.lflang/src/org/lflang/generator/GenerationException.java b/org.lflang/src/org/lflang/generator/GenerationException.java index 1920e9aca8..1bc7985ee7 100644 --- a/org.lflang/src/org/lflang/generator/GenerationException.java +++ b/org.lflang/src/org/lflang/generator/GenerationException.java @@ -27,40 +27,36 @@ import org.eclipse.emf.ecore.EObject; // import org.jetbrains.annotations.Nullable; -/** - * An exception that occurred during code generation. May also - * wrap another exception. - */ -public class GenerationException extends RuntimeException { // note that this is an unchecked exception. - - /* @Nullable */ - private final EObject location; - - public GenerationException(String message) { - this(null, message, null); - } - - public GenerationException(/* @Nullable */ EObject location, String message) { - this(location, message, null); - } - - public GenerationException(String message, Throwable cause) { - this(null, message, cause); - - } - - public GenerationException(/* @Nullable */ EObject location, String message, Throwable cause) { - super(message, cause); - this.location = location; - } - - public GenerationException(Throwable cause) { - this(null, null, cause); - } - - /* @Nullable */ - public EObject getLocation() { - return location; - } +/** An exception that occurred during code generation. May also wrap another exception. */ +public class GenerationException + extends RuntimeException { // note that this is an unchecked exception. + + /* @Nullable */ + private final EObject location; + + public GenerationException(String message) { + this(null, message, null); + } + + public GenerationException(/* @Nullable */ EObject location, String message) { + this(location, message, null); + } + + public GenerationException(String message, Throwable cause) { + this(null, message, cause); + } + + public GenerationException(/* @Nullable */ EObject location, String message, Throwable cause) { + super(message, cause); + this.location = location; + } + + public GenerationException(Throwable cause) { + this(null, null, cause); + } + + /* @Nullable */ + public EObject getLocation() { + return location; + } } - diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 8d57e4c522..c8ebbc38a2 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -24,47 +24,42 @@ ***************/ package org.lflang.generator; +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; - import org.eclipse.core.resources.IMarker; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IteratorExtensions; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.MainConflictChecker; import org.lflang.Target; import org.lflang.TargetConfig; +import org.lflang.ast.ASTUtils; import org.lflang.ast.AstTransformation; import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Connection; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; - import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.util.FileUtil; import org.lflang.validation.AbstractLFValidator; -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; - /** - * Generator base class for specifying core functionality - * that all code generators should have. + * Generator base class for specifying core functionality that all code generators should have. * * @author Edward A. Lee * @author Marten Lohstroh @@ -74,598 +69,599 @@ */ public abstract class GeneratorBase extends AbstractLFValidator { - //////////////////////////////////////////// - //// Public fields. - - /** - * The main (top-level) reactor instance. - */ - public ReactorInstance main; - - /** An error reporter for reporting any errors or warnings during the code generation */ - public ErrorReporter errorReporter; - - //////////////////////////////////////////// - //// Protected fields. - - /** - * The current target configuration. - */ - protected final TargetConfig targetConfig; - - public TargetConfig getTargetConfig() { return this.targetConfig;} - - public final LFGeneratorContext context; - - /** - * A factory for compiler commands. - */ - protected GeneratorCommandFactory commandFactory; - - public GeneratorCommandFactory getCommandFactory() { return commandFactory; } - - /** - * Definition of the main (top-level) reactor. - * This is an automatically generated AST node for the top-level - * reactor. - */ - protected Instantiation mainDef; - public Instantiation getMainDef() { return mainDef; } - - /** - * A list of Reactor definitions in the main resource, including non-main - * reactors defined in imported resources. These are ordered in the list in - * such a way that each reactor is preceded by any reactor that it instantiates - * using a command like {@code foo = new Foo();} - */ - protected List reactors = new ArrayList<>(); - - /** - * The set of resources referenced reactor classes reside in. - */ - protected Set resources = new LinkedHashSet<>(); // FIXME: Why do we need this? - - /** - * Graph that tracks dependencies between instantiations. - * This is a graph where each node is a Reactor (not a ReactorInstance) - * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement - * like {@code a = new A();} After creating the graph, - * sort the reactors in topological order and assign them to the reactors class variable. - * Hence, after this method returns, {@code this.reactors} will be a list of Reactors such that any - * reactor is preceded in the list by reactors that it instantiates. - */ - protected InstantiationGraph instantiationGraph; - - /** - * The set of unordered reactions. An unordered reaction is one that does - * not have any dependency on other reactions in the containing reactor, - * and where no other reaction in the containing reactor depends on it. - * There is currently no way in the syntax of LF to make a reaction - * unordered, deliberately, because it can introduce unexpected - * nondeterminacy. However, certain automatically generated reactions are - * known to be safe to be unordered because they do not interact with the - * state of the containing reactor. To make a reaction unordered, when - * the Reaction instance is created, add that instance to this set. - */ - protected Set unorderedReactions = null; - - /** - * Map from reactions to bank indices - */ - protected Map reactionBankIndices = null; - - /** - * Indicates whether the current Lingua Franca program - * contains model reactors. - */ - public boolean hasModalReactors = false; - - /** - * Indicates whether the program has any deadlines and thus - * needs to propagate deadlines through the reaction instance graph - */ - public boolean hasDeadlines = false; - - /** Indicates whether the program has any watchdogs. This is used to check for support. */ - public boolean hasWatchdogs = false; - - // ////////////////////////////////////////// - // // Private fields. - - /** - * A list ot AST transformations to apply before code generation - */ - private final List astTransformations = new ArrayList<>(); - - /** - * Create a new GeneratorBase object. - */ - public GeneratorBase(LFGeneratorContext context) { - this.context = context; - this.targetConfig = context.getTargetConfig(); - this.errorReporter = context.getErrorReporter(); - this.commandFactory = new GeneratorCommandFactory(errorReporter, context.getFileConfig()); + //////////////////////////////////////////// + //// Public fields. + + /** The main (top-level) reactor instance. */ + public ReactorInstance main; + + /** An error reporter for reporting any errors or warnings during the code generation */ + public ErrorReporter errorReporter; + + //////////////////////////////////////////// + //// Protected fields. + + /** The current target configuration. */ + protected final TargetConfig targetConfig; + + public TargetConfig getTargetConfig() { + return this.targetConfig; + } + + public final LFGeneratorContext context; + + /** A factory for compiler commands. */ + protected GeneratorCommandFactory commandFactory; + + public GeneratorCommandFactory getCommandFactory() { + return commandFactory; + } + + /** + * Definition of the main (top-level) reactor. This is an automatically generated AST node for the + * top-level reactor. + */ + protected Instantiation mainDef; + + public Instantiation getMainDef() { + return mainDef; + } + + /** + * A list of Reactor definitions in the main resource, including non-main reactors defined in + * imported resources. These are ordered in the list in such a way that each reactor is preceded + * by any reactor that it instantiates using a command like {@code foo = new Foo();} + */ + protected List reactors = new ArrayList<>(); + + /** The set of resources referenced reactor classes reside in. */ + protected Set resources = new LinkedHashSet<>(); // FIXME: Why do we need this? + + /** + * Graph that tracks dependencies between instantiations. This is a graph where each node is a + * Reactor (not a ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an + * instance of A, constructed with a statement like {@code a = new A();} After creating the graph, + * sort the reactors in topological order and assign them to the reactors class variable. Hence, + * after this method returns, {@code this.reactors} will be a list of Reactors such that any + * reactor is preceded in the list by reactors that it instantiates. + */ + protected InstantiationGraph instantiationGraph; + + /** + * The set of unordered reactions. An unordered reaction is one that does not have any dependency + * on other reactions in the containing reactor, and where no other reaction in the containing + * reactor depends on it. There is currently no way in the syntax of LF to make a reaction + * unordered, deliberately, because it can introduce unexpected nondeterminacy. However, certain + * automatically generated reactions are known to be safe to be unordered because they do not + * interact with the state of the containing reactor. To make a reaction unordered, when the + * Reaction instance is created, add that instance to this set. + */ + protected Set unorderedReactions = null; + + /** Map from reactions to bank indices */ + protected Map reactionBankIndices = null; + + /** Indicates whether the current Lingua Franca program contains model reactors. */ + public boolean hasModalReactors = false; + + /** + * Indicates whether the program has any deadlines and thus needs to propagate deadlines through + * the reaction instance graph + */ + public boolean hasDeadlines = false; + + /** Indicates whether the program has any watchdogs. This is used to check for support. */ + public boolean hasWatchdogs = false; + + // ////////////////////////////////////////// + // // Private fields. + + /** A list ot AST transformations to apply before code generation */ + private final List astTransformations = new ArrayList<>(); + + /** Create a new GeneratorBase object. */ + public GeneratorBase(LFGeneratorContext context) { + this.context = context; + this.targetConfig = context.getTargetConfig(); + this.errorReporter = context.getErrorReporter(); + this.commandFactory = new GeneratorCommandFactory(errorReporter, context.getFileConfig()); + } + + /** + * Register an AST transformation to be applied to the AST. + * + *

    The transformations will be applied in the order that they are registered in. + */ + protected void registerTransformation(AstTransformation transformation) { + astTransformations.add(transformation); + } + + // ////////////////////////////////////////// + // // Code generation functions to override for a concrete code generator. + + /** + * If there is a main or federated reactor, then create a synthetic Instantiation for that + * top-level reactor and set the field mainDef to refer to it. + */ + private void createMainInstantiation() { + // Find the main reactor and create an AST node for its instantiation. + Iterable nodes = + IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); + for (Reactor reactor : Iterables.filter(nodes, Reactor.class)) { + if (reactor.isMain()) { + // Creating a definition for the main reactor because there isn't one. + this.mainDef = LfFactory.eINSTANCE.createInstantiation(); + this.mainDef.setName(reactor.getName()); + this.mainDef.setReactorClass(reactor); + } } - - /** - * Register an AST transformation to be applied to the AST. - * - * The transformations will be applied in the order that they are registered in. - */ - protected void registerTransformation(AstTransformation transformation) { - astTransformations.add(transformation); + } + + /** + * Generate code from the Lingua Franca model contained by the specified resource. + * + *

    This is the main entry point for code generation. This base class finds all reactor class + * definitions, including any reactors defined in imported .lf files (except any main reactors in + * those imported files), and adds them to the {@link GeneratorBase#reactors reactors} list. If + * errors occur during generation, then a subsequent call to errorsOccurred() will return true. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. In standalone mode, this + * object is also used to relay CLI arguments. + */ + public void doGenerate(Resource resource, LFGeneratorContext context) { + + // FIXME: the signature can be reduced to only take context. + // The constructor also need not take a file config because this is tied to the context as well. + cleanIfNeeded(context); + + printInfo(context.getMode()); + + // Clear any IDE markers that may have been created by a previous build. + // Markers mark problems in the Eclipse IDE when running in integrated mode. + errorReporter.clearHistory(); + + ASTUtils.setMainName(context.getFileConfig().resource, context.getFileConfig().name); + + createMainInstantiation(); + + // Check if there are any conflicting main reactors elsewhere in the package. + if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && mainDef != null) { + for (String conflict : new MainConflictChecker(context.getFileConfig()).conflicts) { + errorReporter.reportError( + this.mainDef.getReactorClass(), "Conflicting main reactor in " + conflict); + } } - // ////////////////////////////////////////// - // // Code generation functions to override for a concrete code generator. - - /** - * If there is a main or federated reactor, then create a synthetic Instantiation - * for that top-level reactor and set the field mainDef to refer to it. - */ - private void createMainInstantiation() { - // Find the main reactor and create an AST node for its instantiation. - Iterable nodes = IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); - for (Reactor reactor : Iterables.filter(nodes, Reactor.class)) { - if (reactor.isMain()) { - // Creating a definition for the main reactor because there isn't one. - this.mainDef = LfFactory.eINSTANCE.createInstantiation(); - this.mainDef.setName(reactor.getName()); - this.mainDef.setReactorClass(reactor); - } - } + // Configure the command factory + commandFactory.setVerbose(); + if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) + && context.getArgs().containsKey("quiet")) { + commandFactory.setQuiet(); } - /** - * Generate code from the Lingua Franca model contained by the specified resource. - * - * This is the main entry point for code generation. This base class finds all - * reactor class definitions, including any reactors defined in imported .lf files - * (except any main reactors in those imported files), and adds them to the - * {@link GeneratorBase#reactors reactors} list. If errors occur during - * generation, then a subsequent call to errorsOccurred() will return true. - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. - * In standalone mode, this object is also used to relay CLI arguments. - */ - public void doGenerate(Resource resource, LFGeneratorContext context) { - - // FIXME: the signature can be reduced to only take context. - // The constructor also need not take a file config because this is tied to the context as well. - cleanIfNeeded(context); - - printInfo(context.getMode()); - - // Clear any IDE markers that may have been created by a previous build. - // Markers mark problems in the Eclipse IDE when running in integrated mode. - errorReporter.clearHistory(); - - ASTUtils.setMainName(context.getFileConfig().resource, context.getFileConfig().name); - - createMainInstantiation(); - - // Check if there are any conflicting main reactors elsewhere in the package. - if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && mainDef != null) { - for (String conflict : new MainConflictChecker(context.getFileConfig()).conflicts) { - errorReporter.reportError(this.mainDef.getReactorClass(), "Conflicting main reactor in " + conflict); - } - } - - // Configure the command factory - commandFactory.setVerbose(); - if (Objects.equal(context.getMode(), LFGeneratorContext.Mode.STANDALONE) && context.getArgs().containsKey("quiet")) { - commandFactory.setQuiet(); - } - - // Process target files. Copy each of them into the src-gen dir. - // FIXME: Should we do this here? This doesn't make sense for federates the way it is - // done here. - copyUserFiles(this.targetConfig, context.getFileConfig()); - - // Collect reactors and create an instantiation graph. - // These are needed to figure out which resources we need - // to validate, which happens in setResources(). - setReactorsAndInstantiationGraph(context.getMode()); - - List allResources = GeneratorUtils.getResources(reactors); - resources.addAll(allResources.stream() // FIXME: This filter reproduces the behavior of the method it replaces. But why must it be so complicated? Why are we worried about weird corner cases like this? - .filter(it -> !Objects.equal(it, context.getFileConfig().resource) || mainDef != null && it == mainDef.getReactorClass().eResource()) - .map(it -> GeneratorUtils.getLFResource(it, context.getFileConfig().getSrcGenBasePath(), context, errorReporter)) - .toList() - ); - GeneratorUtils.accommodatePhysicalActionsIfPresent( - allResources, - getTarget().setsKeepAliveOptionAutomatically(), - targetConfig, - errorReporter - ); - // FIXME: Should the GeneratorBase pull in {@code files} from imported - // resources? - - for (AstTransformation transformation : astTransformations) { - transformation.applyTransformation(reactors); - } - - // Transform connections that reside in mutually exclusive modes and are otherwise conflicting - // This should be done before creating the instantiation graph - transformConflictingConnectionsInModalReactors(); - - // Invoke these functions a second time because transformations - // may have introduced new reactors! - setReactorsAndInstantiationGraph(context.getMode()); - - // Check for existence and support of modes - hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); - checkModalReactorSupport(false); - - // Check for the existence and support of watchdogs - hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); - checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); - additionalPostProcessingForModes(); + // Process target files. Copy each of them into the src-gen dir. + // FIXME: Should we do this here? This doesn't make sense for federates the way it is + // done here. + copyUserFiles(this.targetConfig, context.getFileConfig()); + + // Collect reactors and create an instantiation graph. + // These are needed to figure out which resources we need + // to validate, which happens in setResources(). + setReactorsAndInstantiationGraph(context.getMode()); + + List allResources = GeneratorUtils.getResources(reactors); + resources.addAll( + allResources + .stream() // FIXME: This filter reproduces the behavior of the method it replaces. But + // why must it be so complicated? Why are we worried about weird corner cases + // like this? + .filter( + it -> + !Objects.equal(it, context.getFileConfig().resource) + || mainDef != null && it == mainDef.getReactorClass().eResource()) + .map( + it -> + GeneratorUtils.getLFResource( + it, context.getFileConfig().getSrcGenBasePath(), context, errorReporter)) + .toList()); + GeneratorUtils.accommodatePhysicalActionsIfPresent( + allResources, getTarget().setsKeepAliveOptionAutomatically(), targetConfig, errorReporter); + // FIXME: Should the GeneratorBase pull in {@code files} from imported + // resources? + + for (AstTransformation transformation : astTransformations) { + transformation.applyTransformation(reactors); } - /** - * Check if a clean was requested from the standalone compiler and perform - * the clean step. - */ - protected void cleanIfNeeded(LFGeneratorContext context) { - if (context.getArgs().containsKey("clean")) { - try { - context.getFileConfig().doClean(); - } catch (IOException e) { - System.err.println("WARNING: IO Error during clean"); - } - } + // Transform connections that reside in mutually exclusive modes and are otherwise conflicting + // This should be done before creating the instantiation graph + transformConflictingConnectionsInModalReactors(); + + // Invoke these functions a second time because transformations + // may have introduced new reactors! + setReactorsAndInstantiationGraph(context.getMode()); + + // Check for existence and support of modes + hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty()); + checkModalReactorSupport(false); + + // Check for the existence and support of watchdogs + hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty()); + checkWatchdogSupport(targetConfig.threading && getTarget() == Target.C); + additionalPostProcessingForModes(); + } + + /** Check if a clean was requested from the standalone compiler and perform the clean step. */ + protected void cleanIfNeeded(LFGeneratorContext context) { + if (context.getArgs().containsKey("clean")) { + try { + context.getFileConfig().doClean(); + } catch (IOException e) { + System.err.println("WARNING: IO Error during clean"); + } } - - /** - * Create a new instantiation graph. This is a graph where each node is a Reactor (not a ReactorInstance) - * and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement - * like {@code a = new A();} After creating the graph, - * sort the reactors in topological order and assign them to the reactors class variable. - * Hence, after this method returns, {@code this.reactors} will be a list of Reactors such that any - * reactor is preceded in the list by reactors that it instantiates. - */ - protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { - // Build the instantiation graph . - instantiationGraph = new InstantiationGraph(context.getFileConfig().resource, false); - - // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur earlier in - // the sorted list of reactors. This helps the code generator output code in the correct order. - // For example if {@code reactor Foo {bar = new Bar()}} then the definition of {@code Bar} has to be generated before - // the definition of {@code Foo}. - reactors = instantiationGraph.nodesInTopologicalOrder(); - - // If there is no main reactor or if all reactors in the file need to be validated, then make sure the reactors - // list includes even reactors that are not instantiated anywhere. - if (mainDef == null || Objects.equal(mode, LFGeneratorContext.Mode.LSP_MEDIUM)) { - Iterable nodes = IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); - for (Reactor r : IterableExtensions.filter(nodes, Reactor.class)) { - if (!reactors.contains(r)) { - reactors.add(r); - } - } + } + + /** + * Create a new instantiation graph. This is a graph where each node is a Reactor (not a + * ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an instance of A, + * constructed with a statement like {@code a = new A();} After creating the graph, sort the + * reactors in topological order and assign them to the reactors class variable. Hence, after this + * method returns, {@code this.reactors} will be a list of Reactors such that any reactor is + * preceded in the list by reactors that it instantiates. + */ + protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) { + // Build the instantiation graph . + instantiationGraph = new InstantiationGraph(context.getFileConfig().resource, false); + + // Topologically sort the reactors such that all of a reactor's instantiation dependencies occur + // earlier in + // the sorted list of reactors. This helps the code generator output code in the correct order. + // For example if {@code reactor Foo {bar = new Bar()}} then the definition of {@code Bar} has + // to be generated before + // the definition of {@code Foo}. + reactors = instantiationGraph.nodesInTopologicalOrder(); + + // If there is no main reactor or if all reactors in the file need to be validated, then make + // sure the reactors + // list includes even reactors that are not instantiated anywhere. + if (mainDef == null || Objects.equal(mode, LFGeneratorContext.Mode.LSP_MEDIUM)) { + Iterable nodes = + IteratorExtensions.toIterable(context.getFileConfig().resource.getAllContents()); + for (Reactor r : IterableExtensions.filter(nodes, Reactor.class)) { + if (!reactors.contains(r)) { + reactors.add(r); } + } } - - /** - * Copy user specific files to the src-gen folder. - * - * This should be overridden by the target generators. - * - * @param targetConfig The targetConfig to read the {@code files} from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - var dst = this.context.getFileConfig().getSrcGenPath(); - FileUtil.copyFilesOrDirectories(targetConfig.files, dst, fileConfig, errorReporter, false); - } - - /** - * Return true if errors occurred in the last call to doGenerate(). - * This will return true if any of the reportError methods was called. - * @return True if errors occurred. - */ - public boolean errorsOccurred() { - return errorReporter.getErrorsOccurred(); + } + + /** + * Copy user specific files to the src-gen folder. + * + *

    This should be overridden by the target generators. + * + * @param targetConfig The targetConfig to read the {@code files} from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + var dst = this.context.getFileConfig().getSrcGenPath(); + FileUtil.copyFilesOrDirectories(targetConfig.files, dst, fileConfig, errorReporter, false); + } + + /** + * Return true if errors occurred in the last call to doGenerate(). This will return true if any + * of the reportError methods was called. + * + * @return True if errors occurred. + */ + public boolean errorsOccurred() { + return errorReporter.getErrorsOccurred(); + } + + /* + * Return the TargetTypes instance associated with this. + */ + public abstract TargetTypes getTargetTypes(); + + /** + * Mark the reaction unordered. An unordered reaction is one that does not have any dependency on + * other reactions in the containing reactor, and where no other reaction in the containing + * reactor depends on it. There is currently no way in the syntax of LF to make a reaction + * unordered, deliberately, because it can introduce unexpected nondeterminacy. However, certain + * automatically generated reactions are known to be safe to be unordered because they do not + * interact with the state of the containing reactor. To make a reaction unordered, when the + * Reaction instance is created, add that instance to this set. + * + * @param reaction The reaction to make unordered. + */ + public void makeUnordered(Reaction reaction) { + if (unorderedReactions == null) { + unorderedReactions = new LinkedHashSet<>(); } - - /* - * Return the TargetTypes instance associated with this. - */ - public abstract TargetTypes getTargetTypes(); - - /** - * Mark the reaction unordered. An unordered reaction is one that does not - * have any dependency on other reactions in the containing reactor, and - * where no other reaction in the containing reactor depends on it. There - * is currently no way in the syntax of LF to make a reaction unordered, - * deliberately, because it can introduce unexpected nondeterminacy. - * However, certain automatically generated reactions are known to be safe - * to be unordered because they do not interact with the state of the - * containing reactor. To make a reaction unordered, when the Reaction - * instance is created, add that instance to this set. - * @param reaction The reaction to make unordered. - */ - public void makeUnordered(Reaction reaction) { - if (unorderedReactions == null) { - unorderedReactions = new LinkedHashSet<>(); - } - unorderedReactions.add(reaction); + unorderedReactions.add(reaction); + } + + /** + * Mark the specified reaction to belong to only the specified bank index. This is needed because + * reactions cannot declare a specific bank index as an effect or trigger. Reactions that send + * messages between federates, including absent messages, need to be specific to a bank member. + * + * @param reaction The reaction. + * @param bankIndex The bank index, or -1 if there is no bank. + */ + public void setReactionBankIndex(Reaction reaction, int bankIndex) { + if (bankIndex < 0) { + return; } - - /** - * Mark the specified reaction to belong to only the specified - * bank index. This is needed because reactions cannot declare - * a specific bank index as an effect or trigger. Reactions that - * send messages between federates, including absent messages, - * need to be specific to a bank member. - * @param reaction The reaction. - * @param bankIndex The bank index, or -1 if there is no bank. - */ - public void setReactionBankIndex(Reaction reaction, int bankIndex) { - if (bankIndex < 0) { - return; - } - if (reactionBankIndices == null) { - reactionBankIndices = new LinkedHashMap<>(); - } - reactionBankIndices.put(reaction, bankIndex); + if (reactionBankIndices == null) { + reactionBankIndices = new LinkedHashMap<>(); } - - /** - * Return the reaction bank index. - * @see #setReactionBankIndex(Reaction reaction, int bankIndex) - * @param reaction The reaction. - * @return The reaction bank index, if one has been set, and -1 otherwise. - */ - public int getReactionBankIndex(Reaction reaction) { - if (reactionBankIndices == null) return -1; - if (reactionBankIndices.get(reaction) == null) return -1; - return reactionBankIndices.get(reaction); + reactionBankIndices.put(reaction, bankIndex); + } + + /** + * Return the reaction bank index. + * + * @see #setReactionBankIndex(Reaction reaction, int bankIndex) + * @param reaction The reaction. + * @return The reaction bank index, if one has been set, and -1 otherwise. + */ + public int getReactionBankIndex(Reaction reaction) { + if (reactionBankIndices == null) return -1; + if (reactionBankIndices.get(reaction) == null) return -1; + return reactionBankIndices.get(reaction); + } + + // ////////////////////////////////////////// + // // Protected methods. + + /** + * Checks whether modal reactors are present and require appropriate code generation. This will + * set the hasModalReactors variable. + * + * @param isSupported indicates if modes are supported by this code generation. + */ + protected void checkModalReactorSupport(boolean isSupported) { + if (hasModalReactors && !isSupported) { + errorReporter.reportError( + "The currently selected code generation or " + + "target configuration does not support modal reactors!"); } - - // ////////////////////////////////////////// - // // Protected methods. - - /** - * Checks whether modal reactors are present and require appropriate code generation. - * This will set the hasModalReactors variable. - * @param isSupported indicates if modes are supported by this code generation. - */ - protected void checkModalReactorSupport(boolean isSupported) { - if (hasModalReactors && !isSupported) { - errorReporter.reportError("The currently selected code generation or " + - "target configuration does not support modal reactors!"); - } + } + + /** + * Check whether watchdogs are present and are supported. + * + * @param isSupported indicates whether or not this is a supported target and whether or not it is + * a threaded runtime. + */ + protected void checkWatchdogSupport(boolean isSupported) { + if (hasWatchdogs && !isSupported) { + errorReporter.reportError( + "Watchdogs are currently only supported for threaded programs in the C target."); } - - /** - * Check whether watchdogs are present and are supported. - * - * @param isSupported indicates whether or not this is a supported target and whether or not it - * is - * a threaded runtime. - */ - protected void checkWatchdogSupport(boolean isSupported) { - if (hasWatchdogs && !isSupported) { + } + + /** + * Finds and transforms connections into forwarding reactions iff the connections have the same + * destination as other connections or reaction in mutually exclusive modes. + */ + private void transformConflictingConnectionsInModalReactors() { + for (LFResource r : resources) { + var transform = ASTUtils.findConflictingConnectionsInModalReactors(r.eResource); + if (!transform.isEmpty()) { + var factory = LfFactory.eINSTANCE; + for (Connection connection : transform) { + // Currently only simple transformations are supported + if (connection.isPhysical() + || connection.getDelay() != null + || connection.isIterated() + || connection.getLeftPorts().size() > 1 + || connection.getRightPorts().size() > 1) { errorReporter.reportError( - "Watchdogs are currently only supported for threaded programs in the C target."); + connection, + "Cannot transform connection in modal reactor. Connection uses currently not" + + " supported features."); + } else { + var reaction = factory.createReaction(); + ((Mode) connection.eContainer()).getReactions().add(reaction); + + var sourceRef = connection.getLeftPorts().get(0); + var destRef = connection.getRightPorts().get(0); + reaction.getTriggers().add(sourceRef); + reaction.getEffects().add(destRef); + + var code = factory.createCode(); + var source = + (sourceRef.getContainer() != null ? sourceRef.getContainer().getName() + "." : "") + + sourceRef.getVariable().getName(); + var dest = + (destRef.getContainer() != null ? destRef.getContainer().getName() + "." : "") + + destRef.getVariable().getName(); + code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest)); + reaction.setCode(code); + + EcoreUtil.remove(connection); + } } + } } - - /** - * Finds and transforms connections into forwarding reactions iff the connections have the same - * destination as other connections or reaction in mutually exclusive modes. - */ - private void transformConflictingConnectionsInModalReactors() { - for (LFResource r : resources) { - var transform = ASTUtils.findConflictingConnectionsInModalReactors(r.eResource); - if (!transform.isEmpty()) { - var factory = LfFactory.eINSTANCE; - for (Connection connection : transform) { - // Currently only simple transformations are supported - if (connection.isPhysical() || connection.getDelay() != null || connection.isIterated() || - connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1 - ) { - errorReporter.reportError(connection, "Cannot transform connection in modal reactor. Connection uses currently not supported features."); - } else { - var reaction = factory.createReaction(); - ((Mode)connection.eContainer()).getReactions().add(reaction); - - var sourceRef = connection.getLeftPorts().get(0); - var destRef = connection.getRightPorts().get(0); - reaction.getTriggers().add(sourceRef); - reaction.getEffects().add(destRef); - - var code = factory.createCode(); - var source = (sourceRef.getContainer() != null ? - sourceRef.getContainer().getName() + "." : "") + sourceRef.getVariable().getName(); - var dest = (destRef.getContainer() != null ? - destRef.getContainer().getName() + "." : "") + destRef.getVariable().getName(); - code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest)); - reaction.setCode(code); - - EcoreUtil.remove(connection); - } - } - } - } - } - - /** - * Return target code for forwarding reactions iff the connections have the - * same destination as other connections or reaction in mutually exclusive modes. - * - * This method needs to be overridden in target specific code generators that - * support modal reactors. - */ - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - errorReporter.reportError("The currently selected code generation " + - "is missing an implementation for conflicting " + - "transforming connections in modal reactors."); - return "MODAL MODELS NOT SUPPORTED"; + } + + /** + * Return target code for forwarding reactions iff the connections have the same destination as + * other connections or reaction in mutually exclusive modes. + * + *

    This method needs to be overridden in target specific code generators that support modal + * reactors. + */ + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + errorReporter.reportError( + "The currently selected code generation " + + "is missing an implementation for conflicting " + + "transforming connections in modal reactors."); + return "MODAL MODELS NOT SUPPORTED"; + } + + /** Hook for additional post-processing of the model. */ + protected void additionalPostProcessingForModes() { + // Do nothing + } + + /** Parsed error message from a compiler is returned here. */ + public static class ErrorFileAndLine { + public String filepath = null; + public String line = "1"; + public String character = "0"; + public String message = ""; + public boolean isError = true; // false for a warning. + + @Override + public String toString() { + return (isError ? "Error" : "Non-error") + + " at " + + line + + ":" + + character + + " of file " + + filepath + + ": " + + message; } - - /** - * Hook for additional post-processing of the model. - */ - protected void additionalPostProcessingForModes() { - // Do nothing - } - - /** - * Parsed error message from a compiler is returned here. - */ - public static class ErrorFileAndLine { - public String filepath = null; - public String line = "1"; - public String character = "0"; - public String message = ""; - public boolean isError = true; // false for a warning. - - @Override - public String toString() { - return (isError ? "Error" : "Non-error") + " at " + line + ":" + character + " of file " + filepath + ": " + message; - } - } - - /** - * Given a line of text from the output of a compiler, return - * an instance of ErrorFileAndLine if the line is recognized as - * the first line of an error message. Otherwise, return null. - * This base class simply returns null. - * @param line A line of output from a compiler or other external - * tool that might generate errors. - * @return If the line is recognized as the start of an error message, - * then return a class containing the path to the file on which the - * error occurred (or null if there is none), the line number (or the - * string "1" if there is none), the character position (or the string - * "0" if there is none), and the message (or an empty string if there - * is none). - */ - protected ErrorFileAndLine parseCommandOutput(String line) { - return null; - } - - /** - * Parse the specified string for command errors that can be reported - * using marks in the Eclipse IDE. In this class, we attempt to parse - * the messages to look for file and line information, thereby generating - * marks on the appropriate lines. This should not be called in standalone - * mode. - * - * @param stderr The output on standard error of executing a command. - */ - public void reportCommandErrors(String stderr) { - // NOTE: If the VS Code branch passes code review, then this function, - // parseCommandOutput, and ErrorFileAndLine will be deleted soon after. - // First, split the message into lines. - String[] lines = stderr.split("\\r?\\n"); - StringBuilder message = new StringBuilder(); - Integer lineNumber = null; - Path path = context.getFileConfig().srcFile; - // In case errors occur within an imported file, record the original path. - Path originalPath = path; - - int severity = IMarker.SEVERITY_ERROR; - for (String line : lines) { - ErrorFileAndLine parsed = parseCommandOutput(line); - if (parsed != null) { - // Found a new line number designator. - // If there is a previously accumulated message, report it. - if (message.length() > 0) { - if (severity == IMarker.SEVERITY_ERROR) - errorReporter.reportError(path, lineNumber, message.toString()); - else - errorReporter.reportWarning(path, lineNumber, message.toString()); - - if (!Objects.equal(originalPath.toFile(), path.toFile())) { - // Report an error also in the top-level resource. - // FIXME: It should be possible to descend through the import - // statements to find which one matches and mark all the - // import statements down the chain. But what a pain! - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); - } else { - errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); - } - } - } - if (parsed.isError) { - severity = IMarker.SEVERITY_ERROR; - } else { - severity = IMarker.SEVERITY_WARNING; - } - - // Start accumulating a new message. - message = new StringBuilder(); - // Append the message on the line number designator line. - message.append(parsed.message); - - // Set the new line number. - try { - lineNumber = Integer.decode(parsed.line); - } catch (Exception ex) { - // Set the line number unknown. - lineNumber = null; - } - // FIXME: Ignoring the position within the line. - // Determine the path within which the error occurred. - path = Paths.get(parsed.filepath); - } else { - // No line designator. - if (message.length() > 0) { - message.append("\n"); - } else { - if (!line.toLowerCase().contains("error:")) { - severity = IMarker.SEVERITY_WARNING; - } - } - message.append(line); - } - } + } + + /** + * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if + * the line is recognized as the first line of an error message. Otherwise, return null. This base + * class simply returns null. + * + * @param line A line of output from a compiler or other external tool that might generate errors. + * @return If the line is recognized as the start of an error message, then return a class + * containing the path to the file on which the error occurred (or null if there is none), the + * line number (or the string "1" if there is none), the character position (or the string "0" + * if there is none), and the message (or an empty string if there is none). + */ + protected ErrorFileAndLine parseCommandOutput(String line) { + return null; + } + + /** + * Parse the specified string for command errors that can be reported using marks in the Eclipse + * IDE. In this class, we attempt to parse the messages to look for file and line information, + * thereby generating marks on the appropriate lines. This should not be called in standalone + * mode. + * + * @param stderr The output on standard error of executing a command. + */ + public void reportCommandErrors(String stderr) { + // NOTE: If the VS Code branch passes code review, then this function, + // parseCommandOutput, and ErrorFileAndLine will be deleted soon after. + // First, split the message into lines. + String[] lines = stderr.split("\\r?\\n"); + StringBuilder message = new StringBuilder(); + Integer lineNumber = null; + Path path = context.getFileConfig().srcFile; + // In case errors occur within an imported file, record the original path. + Path originalPath = path; + + int severity = IMarker.SEVERITY_ERROR; + for (String line : lines) { + ErrorFileAndLine parsed = parseCommandOutput(line); + if (parsed != null) { + // Found a new line number designator. + // If there is a previously accumulated message, report it. if (message.length() > 0) { + if (severity == IMarker.SEVERITY_ERROR) + errorReporter.reportError(path, lineNumber, message.toString()); + else errorReporter.reportWarning(path, lineNumber, message.toString()); + + if (!Objects.equal(originalPath.toFile(), path.toFile())) { + // Report an error also in the top-level resource. + // FIXME: It should be possible to descend through the import + // statements to find which one matches and mark all the + // import statements down the chain. But what a pain! if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(path, lineNumber, message.toString()); + errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); } else { - errorReporter.reportWarning(path, lineNumber, message.toString()); + errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); } + } + } + if (parsed.isError) { + severity = IMarker.SEVERITY_ERROR; + } else { + severity = IMarker.SEVERITY_WARNING; + } - if (originalPath.toFile() != path.toFile()) { - // Report an error also in the top-level resource. - // FIXME: It should be possible to descend through the import - // statements to find which one matches and mark all the - // import statements down the chain. But what a pain! - if (severity == IMarker.SEVERITY_ERROR) { - errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); - } else { - errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); - } - } + // Start accumulating a new message. + message = new StringBuilder(); + // Append the message on the line number designator line. + message.append(parsed.message); + + // Set the new line number. + try { + lineNumber = Integer.decode(parsed.line); + } catch (Exception ex) { + // Set the line number unknown. + lineNumber = null; + } + // FIXME: Ignoring the position within the line. + // Determine the path within which the error occurred. + path = Paths.get(parsed.filepath); + } else { + // No line designator. + if (message.length() > 0) { + message.append("\n"); + } else { + if (!line.toLowerCase().contains("error:")) { + severity = IMarker.SEVERITY_WARNING; + } } + message.append(line); + } } - - // ////////////////////////////////////////////////// - // // Private functions - - /** - * Print to stdout information about what source file is being generated, - * what mode the generator is in, and where the generated sources are to be put. - */ - public void printInfo(LFGeneratorContext.Mode mode) { - System.out.println("Generating code for: " + context.getFileConfig().resource.getURI().toString()); - System.out.println("******** mode: " + mode); - System.out.println("******** generated sources: " + context.getFileConfig().getSrcGenPath()); + if (message.length() > 0) { + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(path, lineNumber, message.toString()); + } else { + errorReporter.reportWarning(path, lineNumber, message.toString()); + } + + if (originalPath.toFile() != path.toFile()) { + // Report an error also in the top-level resource. + // FIXME: It should be possible to descend through the import + // statements to find which one matches and mark all the + // import statements down the chain. But what a pain! + if (severity == IMarker.SEVERITY_ERROR) { + errorReporter.reportError(originalPath, 1, "Error in imported file: " + path); + } else { + errorReporter.reportWarning(originalPath, 1, "Warning in imported file: " + path); + } + } } - - /** - * Get the buffer type used for network messages - */ - public String getNetworkBufferType() { return ""; } - - /** - * Return the Targets enum for the current target - */ - public abstract Target getTarget(); + } + + // ////////////////////////////////////////////////// + // // Private functions + + /** + * Print to stdout information about what source file is being generated, what mode the generator + * is in, and where the generated sources are to be put. + */ + public void printInfo(LFGeneratorContext.Mode mode) { + System.out.println( + "Generating code for: " + context.getFileConfig().resource.getURI().toString()); + System.out.println("******** mode: " + mode); + System.out.println("******** generated sources: " + context.getFileConfig().getSrcGenPath()); + } + + /** Get the buffer type used for network messages */ + public String getNetworkBufferType() { + return ""; + } + + /** Return the Targets enum for the current target */ + public abstract Target getTarget(); } diff --git a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java b/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java index 081f07320b..b1dc44e094 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java +++ b/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java @@ -1,26 +1,26 @@ /************* - Copyright (c) 2019-2021 TU Dresden - Copyright (c) 2019-2021 UC Berkeley - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2019-2021 TU Dresden + * Copyright (c) 2019-2021 UC Berkeley + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.generator; @@ -29,120 +29,128 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.nio.file.Paths; import java.util.List; import java.util.Objects; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.util.LFCommand; /** * A factory class responsible for creating commands for use by the LF code generators. - *

    - * In addition to the basic functionality of LFCommand, this class additionally ensures that error messages (or - * optionally warnings) are shown when a command is not found and that certain environment variables are set (see - * {@link #createCommand(String, List, Path, boolean) createCommand}). + * + *

    In addition to the basic functionality of LFCommand, this class additionally ensures that + * error messages (or optionally warnings) are shown when a command is not found and that certain + * environment variables are set (see {@link #createCommand(String, List, Path, boolean) + * createCommand}). */ public class GeneratorCommandFactory { - protected final ErrorReporter errorReporter; - protected final FileConfig fileConfig; - protected boolean quiet = false; - - public GeneratorCommandFactory(ErrorReporter errorReporter, FileConfig fileConfig) { - this.errorReporter = Objects.requireNonNull(errorReporter); - this.fileConfig = Objects.requireNonNull(fileConfig); - } - - /// enable quiet mode (command output is not printed) - public void setQuiet() { quiet = true; } - - /// enable verbose mode (command output is printed) - public void setVerbose() { quiet = false; } - - /** - * Create a LFCommand instance from a given command and an argument list. - *

    - * The command will be executed in the CWD and if the command cannot be found an error message is shown. - * - * @param cmd the command to look up - * @param args a list of arguments - * @return an LFCommand object or null if the command could not be found - * @see #createCommand(String, List, Path, boolean) - */ - public LFCommand createCommand(String cmd, List args) { - return createCommand(cmd, args, null, true); + protected final ErrorReporter errorReporter; + protected final FileConfig fileConfig; + protected boolean quiet = false; + + public GeneratorCommandFactory(ErrorReporter errorReporter, FileConfig fileConfig) { + this.errorReporter = Objects.requireNonNull(errorReporter); + this.fileConfig = Objects.requireNonNull(fileConfig); + } + + /// enable quiet mode (command output is not printed) + public void setQuiet() { + quiet = true; + } + + /// enable verbose mode (command output is printed) + public void setVerbose() { + quiet = false; + } + + /** + * Create a LFCommand instance from a given command and an argument list. + * + *

    The command will be executed in the CWD and if the command cannot be found an error message + * is shown. + * + * @param cmd the command to look up + * @param args a list of arguments + * @return an LFCommand object or null if the command could not be found + * @see #createCommand(String, List, Path, boolean) + */ + public LFCommand createCommand(String cmd, List args) { + return createCommand(cmd, args, null, true); + } + + /** + * Create a LFCommand instance from a given command, an argument list and a directory. + * + * @param cmd the command to look up + * @param args a list of arguments + * @param failOnError If true, an error is shown if the command cannot be found. Otherwise, only a + * warning is displayed. + * @return an LFCommand object or null if the command could not be found + * @see #createCommand(String, List, Path, boolean) + */ + public LFCommand createCommand(String cmd, List args, boolean failOnError) { + return createCommand(cmd, args, null, failOnError); + } + + /** + * Create a LFCommand instance from a given command, an argument list and a directory. + * + *

    The command will be executed in the CWD and if the command cannot be found an error message + * is shown. + * + * @param cmd the command to look up + * @param args a list of arguments + * @param dir the directory to execute the command in. If null, this will default to the CWD + * @return an LFCommand object or null if the command could not be found + * @see #createCommand(String, List, Path, boolean) + */ + public LFCommand createCommand(String cmd, List args, Path dir) { + return createCommand(cmd, args, dir, true); + } + + /** + * Create a LFCommand instance from a given command, an argument list and a directory. + * + *

    This will check first if the command can actually be found and executed. If the command is + * not found, null is returned. In addition, an error message will be shown if failOnError is + * true. Otherwise, a warning will be displayed. + * + * @param cmd the command to look up + * @param args a list of arguments + * @param dir the directory to execute the command in. If null, this will default to the CWD + * @param failOnError If true, an error is shown if the command cannot be found. Otherwise, only a + * warning is displayed. + * @return an LFCommand object or null if the command could not be found + * @see LFCommand#get(String, List, boolean, Path) + */ + public LFCommand createCommand(String cmd, List args, Path dir, boolean failOnError) { + assert cmd != null && args != null; + if (dir == null) { + dir = Paths.get(""); } - - - /** - * Create a LFCommand instance from a given command, an argument list and a directory. - * - * @param cmd the command to look up - * @param args a list of arguments - * @param failOnError If true, an error is shown if the command cannot be found. Otherwise, only a warning is - * displayed. - * @return an LFCommand object or null if the command could not be found - * @see #createCommand(String, List, Path, boolean) - */ - public LFCommand createCommand(String cmd, List args, boolean failOnError) { - return createCommand(cmd, args, null, failOnError); + LFCommand command = LFCommand.get(cmd, args, quiet, dir); + if (command != null) { + command.setEnvironmentVariable("LF_CURRENT_WORKING_DIRECTORY", dir.toString()); + command.setEnvironmentVariable("LF_SOURCE_DIRECTORY", fileConfig.srcPath.toString()); + command.setEnvironmentVariable("LF_PACKAGE_DIRECTORY", fileConfig.srcPkgPath.toString()); + command.setEnvironmentVariable( + "LF_SOURCE_GEN_DIRECTORY", fileConfig.getSrcGenPath().toString()); + command.setEnvironmentVariable("LF_BIN_DIRECTORY", fileConfig.binPath.toString()); + } else { + final String message = + "The command " + + cmd + + " could not be found in the current working directory or in your PATH. " + + "Make sure that your PATH variable includes the directory where " + + cmd + + " is installed. " + + "You can set PATH in ~/.bash_profile on Linux or Mac."; + if (failOnError) { + errorReporter.reportError(message); + } else { + errorReporter.reportWarning(message); + } } - - /** - * Create a LFCommand instance from a given command, an argument list and a directory. - *

    - * The command will be executed in the CWD and if the command cannot be found an error message is shown. - * - * @param cmd the command to look up - * @param args a list of arguments - * @param dir the directory to execute the command in. If null, this will default to the CWD - * @return an LFCommand object or null if the command could not be found - * @see #createCommand(String, List, Path, boolean) - */ - public LFCommand createCommand(String cmd, List args, Path dir) { - return createCommand(cmd, args, dir, true); - } - - - /** - * Create a LFCommand instance from a given command, an argument list and a directory. - *

    - * This will check first if the command can actually be found and executed. If the command is not found, null is - * returned. In addition, an error message will be shown if failOnError is true. Otherwise, a warning will be - * displayed. - * - * @param cmd the command to look up - * @param args a list of arguments - * @param dir the directory to execute the command in. If null, this will default to the CWD - * @param failOnError If true, an error is shown if the command cannot be found. Otherwise, only a warning is - * displayed. - * @return an LFCommand object or null if the command could not be found - * @see LFCommand#get(String, List, boolean, Path) - */ - public LFCommand createCommand(String cmd, List args, Path dir, boolean failOnError) { - assert cmd != null && args != null; - if (dir == null) { - dir = Paths.get(""); - } - LFCommand command = LFCommand.get(cmd, args, quiet, dir); - if (command != null) { - command.setEnvironmentVariable("LF_CURRENT_WORKING_DIRECTORY", dir.toString()); - command.setEnvironmentVariable("LF_SOURCE_DIRECTORY", fileConfig.srcPath.toString()); - command.setEnvironmentVariable("LF_PACKAGE_DIRECTORY", fileConfig.srcPkgPath.toString()); - command.setEnvironmentVariable("LF_SOURCE_GEN_DIRECTORY", fileConfig.getSrcGenPath().toString()); - command.setEnvironmentVariable("LF_BIN_DIRECTORY", fileConfig.binPath.toString()); - } else { - final String message = - "The command " + cmd + " could not be found in the current working directory or in your PATH. " + - "Make sure that your PATH variable includes the directory where " + cmd + " is installed. " + - "You can set PATH in ~/.bash_profile on Linux or Mac."; - if (failOnError) { - errorReporter.reportError(message); - } else { - errorReporter.reportWarning(message); - } - } - - return command; - } + return command; + } } diff --git a/org.lflang/src/org/lflang/generator/GeneratorResult.java b/org.lflang/src/org/lflang/generator/GeneratorResult.java index 2b42e17f34..b882510d50 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorResult.java +++ b/org.lflang/src/org/lflang/generator/GeneratorResult.java @@ -1,19 +1,9 @@ package org.lflang.generator; -import java.io.File; import java.nio.file.Path; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.function.BiFunction; -import java.util.function.Function; - -import org.eclipse.xtext.generator.GeneratorContext; - -import org.lflang.FileConfig; -import org.lflang.Target; -import org.lflang.TargetConfig; -import org.lflang.util.LFCommand; /** * A {@code GeneratorResult} is the outcome of a code generation task. @@ -21,101 +11,99 @@ * @author Peter Donovan */ public class GeneratorResult { - public static GeneratorResult NOTHING = incompleteGeneratorResult(Status.NOTHING); - public static GeneratorResult CANCELLED = incompleteGeneratorResult(Status.CANCELLED); - public static GeneratorResult FAILED = incompleteGeneratorResult(Status.FAILED); - public static BiFunction, GeneratorResult> GENERATED_NO_EXECUTABLE - = (context, codeMaps) -> new GeneratorResult(Status.GENERATED, context, codeMaps); - - /** - * A {@code Status} is a level of completion of a code generation task. - */ - public enum Status { - NOTHING(result -> ""), // Code generation was not performed. - CANCELLED(result -> "Code generation was cancelled."), - FAILED(result -> ""), // This may be due to a failed validation check, in which case the error should have been - // sent to the error reporter and handled there. This makes a message unnecessary. - GENERATED(GetUserMessage.COMPLETED), - COMPILED(GetUserMessage.COMPLETED); - - /** - * A {@code GetUserMessage} is a function that translates a - * {@code GeneratorResult} into a human-readable report for the end user. - */ - public interface GetUserMessage { - GetUserMessage COMPLETED = result -> { - return String.format( - "Code generation complete. The executable is at \"%s\".", - result.getContext().getFileConfig().getExecutable() - ); - }; - String apply(GeneratorResult result); - } - - /** The {@code GetUserMessage} associated with this {@code Status}. */ - private final GetUserMessage gum; - - /** Initializes a {@code Status} whose {@code GetUserMessage} is {@code gum}. */ - Status(GetUserMessage gum) { - this.gum = gum; - } - } - - private final Status status; - - private final LFGeneratorContext context; - - private final Map codeMaps; + public static GeneratorResult NOTHING = incompleteGeneratorResult(Status.NOTHING); + public static GeneratorResult CANCELLED = incompleteGeneratorResult(Status.CANCELLED); + public static GeneratorResult FAILED = incompleteGeneratorResult(Status.FAILED); + public static BiFunction, GeneratorResult> + GENERATED_NO_EXECUTABLE = + (context, codeMaps) -> new GeneratorResult(Status.GENERATED, context, codeMaps); + + /** A {@code Status} is a level of completion of a code generation task. */ + public enum Status { + NOTHING(result -> ""), // Code generation was not performed. + CANCELLED(result -> "Code generation was cancelled."), + FAILED( + result -> + ""), // This may be due to a failed validation check, in which case the error should + // have been + // sent to the error reporter and handled there. This makes a message unnecessary. + GENERATED(GetUserMessage.COMPLETED), + COMPILED(GetUserMessage.COMPLETED); /** - * Initialize a GeneratorResult. - * @param status The level of completion of a code generation task. - * @param context The context within which the result was produced. - * @param codeMaps A mapping from generated files to their CodeMaps. + * A {@code GetUserMessage} is a function that translates a {@code GeneratorResult} into a + * human-readable report for the end user. */ - public GeneratorResult(Status status, LFGeneratorContext context, Map codeMaps) { - this.status = status != null ? status : Status.NOTHING; - this.context = context; - this.codeMaps = codeMaps != null ? codeMaps : Collections.emptyMap(); + public interface GetUserMessage { + GetUserMessage COMPLETED = + result -> { + return String.format( + "Code generation complete. The executable is at \"%s\".", + result.getContext().getFileConfig().getExecutable()); + }; + + String apply(GeneratorResult result); } - /** - * Return the result of an incomplete generation task that terminated - * with status {@code status}. - * @return the result of an incomplete generation task that terminated - * with status {@code status} - */ - private static GeneratorResult incompleteGeneratorResult(Status status) { - return new GeneratorResult(status, null, Collections.emptyMap()); - } + /** The {@code GetUserMessage} associated with this {@code Status}. */ + private final GetUserMessage gum; - /** Return the status of {@code this}. */ - public Status getStatus() { - return status; + /** Initializes a {@code Status} whose {@code GetUserMessage} is {@code gum}. */ + Status(GetUserMessage gum) { + this.gum = gum; } - - /** - * Return a message that can be relayed to the end user about this - * {@code GeneratorResult}. - */ - public String getUserMessage() { - return status.gum.apply(this); - } - - /** - * Return a map from generated sources to their code maps. The - * completeness of this resulting map is given on a best-effort - * basis, but those mappings that it does contain are guaranteed - * to be correct. - * @return An unmodifiable map from generated sources to their - * code maps. - */ - public Map getCodeMaps() { - return Collections.unmodifiableMap(codeMaps); - } - - public LFGeneratorContext getContext() { - return context; - } - + } + + private final Status status; + + private final LFGeneratorContext context; + + private final Map codeMaps; + + /** + * Initialize a GeneratorResult. + * + * @param status The level of completion of a code generation task. + * @param context The context within which the result was produced. + * @param codeMaps A mapping from generated files to their CodeMaps. + */ + public GeneratorResult(Status status, LFGeneratorContext context, Map codeMaps) { + this.status = status != null ? status : Status.NOTHING; + this.context = context; + this.codeMaps = codeMaps != null ? codeMaps : Collections.emptyMap(); + } + + /** + * Return the result of an incomplete generation task that terminated with status {@code status}. + * + * @return the result of an incomplete generation task that terminated with status {@code status} + */ + private static GeneratorResult incompleteGeneratorResult(Status status) { + return new GeneratorResult(status, null, Collections.emptyMap()); + } + + /** Return the status of {@code this}. */ + public Status getStatus() { + return status; + } + + /** Return a message that can be relayed to the end user about this {@code GeneratorResult}. */ + public String getUserMessage() { + return status.gum.apply(this); + } + + /** + * Return a map from generated sources to their code maps. The completeness of this resulting map + * is given on a best-effort basis, but those mappings that it does contain are guaranteed to be + * correct. + * + * @return An unmodifiable map from generated sources to their code maps. + */ + public Map getCodeMaps() { + return Collections.unmodifiableMap(codeMaps); + } + + public LFGeneratorContext getContext() { + return context; + } } diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/src/org/lflang/generator/GeneratorUtils.java index b4563a6165..04ae33ba0c 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/GeneratorUtils.java @@ -4,19 +4,17 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; - import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.IteratorExtensions; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; import org.lflang.TargetProperty; +import org.lflang.ast.ASTUtils; import org.lflang.generator.LFGeneratorContext.Mode; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -27,177 +25,162 @@ import org.lflang.lf.TargetDecl; /** - * A helper class with functions that may be useful for code - * generators. - * This is created to ease our transition from Xtend and - * possibly Eclipse. All functions in this class should - * instead be in GeneratorUtils.kt, but Eclipse cannot - * handle Kotlin files. + * A helper class with functions that may be useful for code generators. This is created to ease our + * transition from Xtend and possibly Eclipse. All functions in this class should instead be in + * GeneratorUtils.kt, but Eclipse cannot handle Kotlin files. */ public class GeneratorUtils { - private GeneratorUtils() { - // utility class - } + private GeneratorUtils() { + // utility class + } - /** - * Return the target declaration found in the given resource. - */ - public static TargetDecl findTargetDecl(Resource resource) { - return findAll(resource, TargetDecl.class).iterator().next(); - } + /** Return the target declaration found in the given resource. */ + public static TargetDecl findTargetDecl(Resource resource) { + return findAll(resource, TargetDecl.class).iterator().next(); + } - /** - * Look for physical actions in 'resource'. - * If appropriate, set keepalive to true in - * {@code targetConfig}. - * This is a helper function for setTargetConfig. It - * should not be used elsewhere. - */ - public static void accommodatePhysicalActionsIfPresent( - List resources, - boolean setsKeepAliveOptionAutomatically, - TargetConfig targetConfig, - ErrorReporter errorReporter - ) { - if (!setsKeepAliveOptionAutomatically) { - return; - } - for (Resource resource : resources) { - for (Action action : findAll(resource, Action.class)) { - if (action.getOrigin() == ActionOrigin.PHYSICAL && - // Check if the user has explicitly set keepalive to false - !targetConfig.setByUser.contains(TargetProperty.KEEPALIVE) && - !targetConfig.keepalive - ) { - // If not, set it to true - targetConfig.keepalive = true; - errorReporter.reportWarning( - action, - String.format( - "Setting %s to true because of the physical action %s.", - TargetProperty.KEEPALIVE.getDisplayName(), - action.getName() - ) - ); - return; - } - } + /** + * Look for physical actions in 'resource'. If appropriate, set keepalive to true in {@code + * targetConfig}. This is a helper function for setTargetConfig. It should not be used elsewhere. + */ + public static void accommodatePhysicalActionsIfPresent( + List resources, + boolean setsKeepAliveOptionAutomatically, + TargetConfig targetConfig, + ErrorReporter errorReporter) { + if (!setsKeepAliveOptionAutomatically) { + return; + } + for (Resource resource : resources) { + for (Action action : findAll(resource, Action.class)) { + if (action.getOrigin() == ActionOrigin.PHYSICAL + && + // Check if the user has explicitly set keepalive to false + !targetConfig.setByUser.contains(TargetProperty.KEEPALIVE) + && !targetConfig.keepalive) { + // If not, set it to true + targetConfig.keepalive = true; + errorReporter.reportWarning( + action, + String.format( + "Setting %s to true because of the physical action %s.", + TargetProperty.KEEPALIVE.getDisplayName(), action.getName())); + return; } + } } + } - /** - * Return all instances of {@code eObjectType} in - * {@code resource}. - * @param resource A resource to be searched. - * @param nodeType The type of the desired parse tree - * nodes. - * @param The type of the desired parse tree nodes. - * @return all instances of {@code eObjectType} in - * {@code resource} - */ - public static Iterable findAll(Resource resource, Class nodeType) { - return () -> IteratorExtensions.filter(resource.getAllContents(), nodeType); - } + /** + * Return all instances of {@code eObjectType} in {@code resource}. + * + * @param resource A resource to be searched. + * @param nodeType The type of the desired parse tree nodes. + * @param The type of the desired parse tree nodes. + * @return all instances of {@code eObjectType} in {@code resource} + */ + public static Iterable findAll(Resource resource, Class nodeType) { + return () -> IteratorExtensions.filter(resource.getAllContents(), nodeType); + } - /** - * Return the resources that provide the given - * reactors. - * @param reactors The reactors for which to find - * containing resources. - * @return the resources that provide the given - * reactors. - */ - public static List getResources(Iterable reactors) { - HashSet visited = new HashSet<>(); - List resources = new ArrayList<>(); - for (Reactor r : reactors) { - Resource resource = r.eResource(); - if (!visited.contains(resource)) { - visited.add(resource); - resources.add(resource); - } - } - return resources; + /** + * Return the resources that provide the given reactors. + * + * @param reactors The reactors for which to find containing resources. + * @return the resources that provide the given reactors. + */ + public static List getResources(Iterable reactors) { + HashSet visited = new HashSet<>(); + List resources = new ArrayList<>(); + for (Reactor r : reactors) { + Resource resource = r.eResource(); + if (!visited.contains(resource)) { + visited.add(resource); + resources.add(resource); + } } + return resources; + } - /** - * Return the {@code LFResource} representation of the - * given resource. - * @param resource The {@code Resource} to be - * represented as an {@code LFResource} - * @param srcGenBasePath The root directory for any - * generated sources associated with the resource. - * @param context The generator invocation context. - * @param errorReporter An error message acceptor. - * @return the {@code LFResource} representation of the - * given resource. - */ - public static LFResource getLFResource( - Resource resource, - Path srcGenBasePath, - LFGeneratorContext context, - ErrorReporter errorReporter - ) { - var target = ASTUtils.targetDecl(resource); - KeyValuePairs config = target.getConfig(); - var targetConfig = new TargetConfig(target); - if (config != null) { - List pairs = config.getPairs(); - TargetProperty.set(targetConfig, pairs != null ? pairs : List.of(), errorReporter); - } - FileConfig fc = LFGenerator.createFileConfig(resource, srcGenBasePath, context.getFileConfig().useHierarchicalBin); - return new LFResource(resource, fc, targetConfig); + /** + * Return the {@code LFResource} representation of the given resource. + * + * @param resource The {@code Resource} to be represented as an {@code LFResource} + * @param srcGenBasePath The root directory for any generated sources associated with the + * resource. + * @param context The generator invocation context. + * @param errorReporter An error message acceptor. + * @return the {@code LFResource} representation of the given resource. + */ + public static LFResource getLFResource( + Resource resource, + Path srcGenBasePath, + LFGeneratorContext context, + ErrorReporter errorReporter) { + var target = ASTUtils.targetDecl(resource); + KeyValuePairs config = target.getConfig(); + var targetConfig = new TargetConfig(target); + if (config != null) { + List pairs = config.getPairs(); + TargetProperty.set(targetConfig, pairs != null ? pairs : List.of(), errorReporter); } + FileConfig fc = + LFGenerator.createFileConfig( + resource, srcGenBasePath, context.getFileConfig().useHierarchicalBin); + return new LFResource(resource, fc, targetConfig); + } - /** - * If the mode is Mode.EPOCH (the code generator is running in an - * Eclipse IDE), then refresh the project. This will ensure that - * any generated files become visible in the project. - * @param resource The resource. - * @param compilerMode An indicator of whether Epoch is running. - */ - public static void refreshProject(Resource resource, Mode compilerMode) { - if (compilerMode == LFGeneratorContext.Mode.EPOCH) { - URI uri = resource.getURI(); - if (uri.isPlatformResource()) { // This condition should normally be met when running Epoch - IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(uri.toPlatformString(true)); - try { - member.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); - } catch (CoreException e) { - System.err.println("Unable to refresh workspace: " + e); - } - } + /** + * If the mode is Mode.EPOCH (the code generator is running in an Eclipse IDE), then refresh the + * project. This will ensure that any generated files become visible in the project. + * + * @param resource The resource. + * @param compilerMode An indicator of whether Epoch is running. + */ + public static void refreshProject(Resource resource, Mode compilerMode) { + if (compilerMode == LFGeneratorContext.Mode.EPOCH) { + URI uri = resource.getURI(); + if (uri.isPlatformResource()) { // This condition should normally be met when running Epoch + IResource member = + ResourcesPlugin.getWorkspace().getRoot().findMember(uri.toPlatformString(true)); + try { + member.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + System.err.println("Unable to refresh workspace: " + e); } + } } + } - /** Return whether the operating system is Windows. */ - public static boolean isHostWindows() { - return System.getProperty("os.name").toLowerCase().contains("win"); - } + /** Return whether the operating system is Windows. */ + public static boolean isHostWindows() { + return System.getProperty("os.name").toLowerCase().contains("win"); + } - /** - * Check whether code can be generated; report any problems - * and inform the context accordingly. - * @return Whether it is possible to generate code. - */ - public static boolean canGenerate( - Boolean errorsOccurred, - Instantiation mainDef, - ErrorReporter errorReporter, - LFGeneratorContext context - ) { - // stop if there are any errors found in the program by doGenerate() in GeneratorBase - if (errorsOccurred) { - context.finish(GeneratorResult.FAILED); - return false; - } - // abort if there is no main reactor - if (mainDef == null) { - errorReporter.reportInfo("INFO: The given Lingua Franca program does not define a main reactor. Therefore, no code was generated."); - context.finish(GeneratorResult.NOTHING); - return false; - } - return true; + /** + * Check whether code can be generated; report any problems and inform the context accordingly. + * + * @return Whether it is possible to generate code. + */ + public static boolean canGenerate( + Boolean errorsOccurred, + Instantiation mainDef, + ErrorReporter errorReporter, + LFGeneratorContext context) { + // stop if there are any errors found in the program by doGenerate() in GeneratorBase + if (errorsOccurred) { + context.finish(GeneratorResult.FAILED); + return false; + } + // abort if there is no main reactor + if (mainDef == null) { + errorReporter.reportInfo( + "INFO: The given Lingua Franca program does not define a main reactor. Therefore, no code" + + " was generated."); + context.finish(GeneratorResult.NOTHING); + return false; } + return true; + } } diff --git a/org.lflang/src/org/lflang/generator/HumanReadableReportingStrategy.java b/org.lflang/src/org/lflang/generator/HumanReadableReportingStrategy.java index f6ecd0a991..8c1dd1e547 100644 --- a/org.lflang/src/org/lflang/generator/HumanReadableReportingStrategy.java +++ b/org.lflang/src/org/lflang/generator/HumanReadableReportingStrategy.java @@ -6,171 +6,163 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; - import org.lflang.ErrorReporter; /** - * An error reporting strategy that parses human-readable - * output. + * An error reporting strategy that parses human-readable output. * * @author Peter Donovan */ public class HumanReadableReportingStrategy implements DiagnosticReporting.Strategy { - /** 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; + /** 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; - /** - * Instantiate a reporting strategy for lines of - * validator output that match {@code diagnosticMessagePattern}. - * @param diagnosticMessagePattern A pattern that matches lines that should be - * reported via this strategy. This pattern - * must contain named capturing groups called - * "path", "line", "column", "message", and - * "severity". - * @param labelPattern A pattern that matches lines that act as labels, showing - * the location of the relevant piece of text. This pattern - * must contain two groups, the first of which must match - * characters that precede the location given by the "line" - * and "column" groups. - */ - public HumanReadableReportingStrategy(Pattern diagnosticMessagePattern, Pattern labelPattern) { - this(diagnosticMessagePattern, labelPattern, null); - } + /** + * Instantiate a reporting strategy for lines of validator output that match {@code + * diagnosticMessagePattern}. + * + * @param diagnosticMessagePattern A pattern that matches lines that should be reported via this + * strategy. This pattern must contain named capturing groups called "path", "line", "column", + * "message", and "severity". + * @param labelPattern A pattern that matches lines that act as labels, showing the location of + * the relevant piece of text. This pattern must contain two groups, the first of which must + * match characters that precede the location given by the "line" and "column" groups. + */ + public HumanReadableReportingStrategy(Pattern diagnosticMessagePattern, Pattern labelPattern) { + this(diagnosticMessagePattern, labelPattern, null); + } - /** - * Instantiate a reporting strategy for lines of - * validator output that match {@code diagnosticMessagePattern}. - * @param diagnosticMessagePattern a pattern that matches lines that should be - * reported via this strategy. This pattern - * must contain named capturing groups called - * "path", "line", "column", "message", and - * "severity". - * @param labelPattern A pattern that matches lines that act as labels, showing - * the location of the relevant piece of text. This pattern - * must contain two groups, the first of which must match - * characters that precede the location given by the "line" - * and "column" groups. - * @param relativeTo The path against which any paths should be resolved. - */ - public HumanReadableReportingStrategy(Pattern diagnosticMessagePattern, Pattern labelPattern, Path relativeTo) { - for (String groupName : new String[]{"path", "line", "column", "message", "severity"}) { - assert diagnosticMessagePattern.pattern().contains(groupName) : String.format( - "Error line patterns must have a named capturing group called %s", groupName - ); - } - this.diagnosticMessagePattern = diagnosticMessagePattern; - this.labelPattern = labelPattern; - this.relativeTo = relativeTo; - this.bufferedLine = null; + /** + * Instantiate a reporting strategy for lines of validator output that match {@code + * diagnosticMessagePattern}. + * + * @param diagnosticMessagePattern a pattern that matches lines that should be reported via this + * strategy. This pattern must contain named capturing groups called "path", "line", "column", + * "message", and "severity". + * @param labelPattern A pattern that matches lines that act as labels, showing the location of + * the relevant piece of text. This pattern must contain two groups, the first of which must + * match characters that precede the location given by the "line" and "column" groups. + * @param relativeTo The path against which any paths should be resolved. + */ + public HumanReadableReportingStrategy( + Pattern diagnosticMessagePattern, Pattern labelPattern, Path relativeTo) { + for (String groupName : new String[] {"path", "line", "column", "message", "severity"}) { + assert diagnosticMessagePattern.pattern().contains(groupName) + : String.format( + "Error line patterns must have a named capturing group called %s", groupName); } + this.diagnosticMessagePattern = diagnosticMessagePattern; + this.labelPattern = labelPattern; + this.relativeTo = relativeTo; + this.bufferedLine = null; + } - @Override - public void report(String validationOutput, ErrorReporter errorReporter, Map map) { - Iterator it = validationOutput.lines().iterator(); - while (it.hasNext() || bufferedLine != null) { - if (bufferedLine != null) { - reportErrorLine(bufferedLine, it, errorReporter, map); - bufferedLine = null; - } else { - reportErrorLine(it.next(), it, errorReporter, map); - } - } + @Override + public void report(String validationOutput, ErrorReporter errorReporter, Map map) { + Iterator it = validationOutput.lines().iterator(); + while (it.hasNext() || bufferedLine != null) { + if (bufferedLine != null) { + reportErrorLine(bufferedLine, it, errorReporter, map); + bufferedLine = null; + } else { + reportErrorLine(it.next(), it, errorReporter, map); + } } + } - /** - * Report the validation message contained in the given line of text. - * @param line The current line. - * @param it An iterator over the lines that follow the current line. - * @param errorReporter An arbitrary ErrorReporter. - * @param maps A mapping from generated file paths to - * CodeMaps. - */ - private void reportErrorLine(String line, Iterator it, ErrorReporter errorReporter, Map maps) { - Matcher matcher = diagnosticMessagePattern.matcher(stripEscaped(line)); - if (matcher.matches()) { - final Path path = Paths.get(matcher.group("path")); - final Position generatedFilePosition = Position.fromOneBased( - Integer.parseInt(matcher.group("line")), - Integer.parseInt(matcher.group("column") != null ? matcher.group("column") : "0") // FIXME: Unreliable heuristic - ); - final String message = DiagnosticReporting.messageOf( - matcher.group("message"), path, generatedFilePosition - ); - final CodeMap map = maps.get(relativeTo != null ? relativeTo.resolve(path) : path); - final DiagnosticSeverity severity = DiagnosticReporting.severityOf(matcher.group("severity")); - if (map == null) { - errorReporter.report(null, severity, message); - return; - } - for (Path srcFile : map.lfSourcePaths()) { - Position lfFilePosition = map.adjusted(srcFile, generatedFilePosition); - if (matcher.group("column") != null) { - reportAppropriateRange( - (p0, p1) -> errorReporter.report(srcFile, severity, message, p0, p1), lfFilePosition, it - ); - } else { - errorReporter.report(srcFile, severity, message, lfFilePosition.getOneBasedLine()); - } - } + /** + * Report the validation message contained in the given line of text. + * + * @param line The current line. + * @param it An iterator over the lines that follow the current line. + * @param errorReporter An arbitrary ErrorReporter. + * @param maps A mapping from generated file paths to CodeMaps. + */ + private void reportErrorLine( + String line, Iterator it, ErrorReporter errorReporter, Map maps) { + Matcher matcher = diagnosticMessagePattern.matcher(stripEscaped(line)); + if (matcher.matches()) { + final Path path = Paths.get(matcher.group("path")); + final Position generatedFilePosition = + Position.fromOneBased( + Integer.parseInt(matcher.group("line")), + Integer.parseInt( + matcher.group("column") != null + ? matcher.group("column") + : "0") // FIXME: Unreliable heuristic + ); + final String message = + DiagnosticReporting.messageOf(matcher.group("message"), path, generatedFilePosition); + final CodeMap map = maps.get(relativeTo != null ? relativeTo.resolve(path) : path); + final DiagnosticSeverity severity = DiagnosticReporting.severityOf(matcher.group("severity")); + if (map == null) { + errorReporter.report(null, severity, message); + return; + } + for (Path srcFile : map.lfSourcePaths()) { + Position lfFilePosition = map.adjusted(srcFile, generatedFilePosition); + if (matcher.group("column") != null) { + reportAppropriateRange( + (p0, p1) -> errorReporter.report(srcFile, severity, message, p0, p1), + lfFilePosition, + it); + } else { + errorReporter.report(srcFile, severity, message, lfFilePosition.getOneBasedLine()); } + } } + } - /** - * Report the appropriate range to {@code report}. - * @param report A reporting method whose first and - * second parameters are the (included) - * start and (excluded) end of the - * relevant range. - * @param lfFilePosition The point about which the - * relevant range is anchored. - * @param it An iterator over the lines immediately - * following a diagnostic message. - */ - private void reportAppropriateRange( - Procedure2 report, Position lfFilePosition, Iterator it - ) { - Procedure0 failGracefully = () -> report.apply(lfFilePosition, lfFilePosition.plus(" ")); - if (!it.hasNext()) { - failGracefully.apply(); - return; - } - String line = it.next(); - Matcher labelMatcher = labelPattern.matcher(line); - if (labelMatcher.find()) { - report.apply( - Position.fromZeroBased( - lfFilePosition.getZeroBasedLine(), - lfFilePosition.getZeroBasedColumn() - labelMatcher.group(1).length() - ), - lfFilePosition.plus(labelMatcher.group(2)) - ); - return; - } - if (diagnosticMessagePattern.matcher(line).find()) { - failGracefully.apply(); - bufferedLine = line; - return; - } - reportAppropriateRange(report, lfFilePosition, it); + /** + * Report the appropriate range to {@code report}. + * + * @param report A reporting method whose first and second parameters are the (included) start and + * (excluded) end of the relevant range. + * @param lfFilePosition The point about which the relevant range is anchored. + * @param it An iterator over the lines immediately following a diagnostic message. + */ + private void reportAppropriateRange( + Procedure2 report, Position lfFilePosition, Iterator it) { + Procedure0 failGracefully = () -> report.apply(lfFilePosition, lfFilePosition.plus(" ")); + if (!it.hasNext()) { + failGracefully.apply(); + return; } - - /** - * Strip the ANSI escape sequences from {@code s}. - * @param s Any string. - * @return {@code s}, with any escape sequences removed. - */ - private static String stripEscaped(String s) { - return s.replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", ""); + String line = it.next(); + Matcher labelMatcher = labelPattern.matcher(line); + if (labelMatcher.find()) { + report.apply( + Position.fromZeroBased( + lfFilePosition.getZeroBasedLine(), + lfFilePosition.getZeroBasedColumn() - labelMatcher.group(1).length()), + lfFilePosition.plus(labelMatcher.group(2))); + return; } + if (diagnosticMessagePattern.matcher(line).find()) { + failGracefully.apply(); + bufferedLine = line; + return; + } + reportAppropriateRange(report, lfFilePosition, it); + } + + /** + * Strip the ANSI escape sequences from {@code s}. + * + * @param s Any string. + * @return {@code s}, with any escape sequences removed. + */ + private static String stripEscaped(String s) { + return s.replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", ""); + } } diff --git a/org.lflang/src/org/lflang/generator/IntegratedBuilder.java b/org.lflang/src/org/lflang/generator/IntegratedBuilder.java index d6a2d3d681..f87c81728d 100644 --- a/org.lflang/src/org/lflang/generator/IntegratedBuilder.java +++ b/org.lflang/src/org/lflang/generator/IntegratedBuilder.java @@ -1,9 +1,10 @@ package org.lflang.generator; +import com.google.inject.Inject; +import com.google.inject.Provider; import java.nio.file.Path; import java.util.List; import java.util.Properties; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -15,142 +16,133 @@ import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.eclipse.xtext.validation.Issue; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.generator.LFGeneratorContext.Mode; -import com.google.inject.Inject; -import com.google.inject.Provider; - /** - * Manages Lingua Franca build processes that are requested - * from the language server. + * Manages Lingua Franca build processes that are requested from the language server. * * @author Peter Donovan */ public class IntegratedBuilder { - public static final int START_PERCENT_PROGRESS = 0; - public static final int VALIDATED_PERCENT_PROGRESS = 33; - public static final int GENERATED_PERCENT_PROGRESS = 67; - public static final int COMPILED_PERCENT_PROGRESS = 100; - - /** - * A {@code ProgressReporter} reports the progress of a build. - */ - public interface ReportProgress { - void apply(String message, Integer percentage); - } - - // Note: This class is not currently used in response to - // document edits, even though the validator and code - // generator are invoked by Xtext in response to - // document edits. - /** - * A {@code ReportMethod} is a way of reporting issues. - */ - private interface ReportMethod { - void apply(Path file, Integer line, String message); - } - - /* ---------------------- INJECTED DEPENDENCIES ---------------------- */ - - @Inject - private IResourceValidator validator; - @Inject - private GeneratorDelegate generator; - @Inject - private JavaIoFileSystemAccess fileAccess; - @Inject - private Provider resourceSetProvider; - - /* ------------------------- PUBLIC METHODS -------------------------- */ - - /** - * Generates code from the Lingua Franca file {@code f}. - * @param uri The URI of a Lingua Franca file. - * @param mustComplete Whether the build must be taken to completion. - * @return The result of the build. - */ - public GeneratorResult run( - URI uri, - boolean mustComplete, - ReportProgress reportProgress, - CancelIndicator cancelIndicator - ) { - fileAccess.setOutputPath( - FileConfig.findPackageRoot(Path.of(uri.path()), s -> {}).resolve(FileConfig.DEFAULT_SRC_GEN_DIR).toString() - ); - List parseRoots = getResource(uri).getContents(); - if (parseRoots.isEmpty()) return GeneratorResult.NOTHING; - ErrorReporter errorReporter = new LanguageServerErrorReporter(parseRoots.get(0)); - reportProgress.apply("Validating...", START_PERCENT_PROGRESS); - validate(uri, errorReporter); - reportProgress.apply("Code validation complete.", VALIDATED_PERCENT_PROGRESS); - if (cancelIndicator.isCanceled()) return GeneratorResult.CANCELLED; - if (errorReporter.getErrorsOccurred()) return GeneratorResult.FAILED; - reportProgress.apply("Generating code...", VALIDATED_PERCENT_PROGRESS); - return doGenerate(uri, mustComplete, reportProgress, cancelIndicator); - } - - /* ------------------------- PRIVATE METHODS ------------------------- */ - - /** - * Validates the Lingua Franca file {@code f}. - * @param uri The URI of a Lingua Franca file. - * @param errorReporter The error reporter. - */ - private void validate(URI uri, ErrorReporter errorReporter) { - for (Issue issue : validator.validate(getResource(uri), CheckMode.ALL, CancelIndicator.NullImpl)) { - getReportMethod(errorReporter, issue.getSeverity()).apply( - Path.of(uri.path()), issue.getLineNumber(), issue.getMessage() - ); - } + public static final int START_PERCENT_PROGRESS = 0; + public static final int VALIDATED_PERCENT_PROGRESS = 33; + public static final int GENERATED_PERCENT_PROGRESS = 67; + public static final int COMPILED_PERCENT_PROGRESS = 100; + + /** A {@code ProgressReporter} reports the progress of a build. */ + public interface ReportProgress { + void apply(String message, Integer percentage); + } + + // Note: This class is not currently used in response to + // document edits, even though the validator and code + // generator are invoked by Xtext in response to + // document edits. + /** A {@code ReportMethod} is a way of reporting issues. */ + private interface ReportMethod { + void apply(Path file, Integer line, String message); + } + + /* ---------------------- INJECTED DEPENDENCIES ---------------------- */ + + @Inject private IResourceValidator validator; + @Inject private GeneratorDelegate generator; + @Inject private JavaIoFileSystemAccess fileAccess; + @Inject private Provider resourceSetProvider; + + /* ------------------------- PUBLIC METHODS -------------------------- */ + + /** + * Generates code from the Lingua Franca file {@code f}. + * + * @param uri The URI of a Lingua Franca file. + * @param mustComplete Whether the build must be taken to completion. + * @return The result of the build. + */ + public GeneratorResult run( + URI uri, + boolean mustComplete, + ReportProgress reportProgress, + CancelIndicator cancelIndicator) { + fileAccess.setOutputPath( + FileConfig.findPackageRoot(Path.of(uri.path()), s -> {}) + .resolve(FileConfig.DEFAULT_SRC_GEN_DIR) + .toString()); + List parseRoots = getResource(uri).getContents(); + if (parseRoots.isEmpty()) return GeneratorResult.NOTHING; + ErrorReporter errorReporter = new LanguageServerErrorReporter(parseRoots.get(0)); + reportProgress.apply("Validating...", START_PERCENT_PROGRESS); + validate(uri, errorReporter); + reportProgress.apply("Code validation complete.", VALIDATED_PERCENT_PROGRESS); + if (cancelIndicator.isCanceled()) return GeneratorResult.CANCELLED; + if (errorReporter.getErrorsOccurred()) return GeneratorResult.FAILED; + reportProgress.apply("Generating code...", VALIDATED_PERCENT_PROGRESS); + return doGenerate(uri, mustComplete, reportProgress, cancelIndicator); + } + + /* ------------------------- PRIVATE METHODS ------------------------- */ + + /** + * Validates the Lingua Franca file {@code f}. + * + * @param uri The URI of a Lingua Franca file. + * @param errorReporter The error reporter. + */ + private void validate(URI uri, ErrorReporter errorReporter) { + for (Issue issue : + validator.validate(getResource(uri), CheckMode.ALL, CancelIndicator.NullImpl)) { + getReportMethod(errorReporter, issue.getSeverity()) + .apply(Path.of(uri.path()), issue.getLineNumber(), issue.getMessage()); } - - /** - * Generates code from the contents of {@code f}. - * @param uri The URI of a Lingua Franca file. - * @param mustComplete Whether the build must be taken to completion. - * @param cancelIndicator An indicator that returns true when the build is - * cancelled. - * @return The result of the build. - */ - private GeneratorResult doGenerate( - URI uri, - boolean mustComplete, - ReportProgress reportProgress, - CancelIndicator cancelIndicator - ) { - var resource = getResource(uri); - LFGeneratorContext context = new MainContext( + } + + /** + * Generates code from the contents of {@code f}. + * + * @param uri The URI of a Lingua Franca file. + * @param mustComplete Whether the build must be taken to completion. + * @param cancelIndicator An indicator that returns true when the build is cancelled. + * @return The result of the build. + */ + private GeneratorResult doGenerate( + URI uri, + boolean mustComplete, + ReportProgress reportProgress, + CancelIndicator cancelIndicator) { + var resource = getResource(uri); + LFGeneratorContext context = + new MainContext( mustComplete ? Mode.LSP_SLOW : LFGeneratorContext.Mode.LSP_MEDIUM, - cancelIndicator, reportProgress, new Properties(), - resource, fileAccess, - fileConfig -> new LanguageServerErrorReporter(resource.getContents().get(0)) - ); - generator.generate(getResource(uri), fileAccess, context); - return context.getResult(); - } - - /** - * Returns the resource corresponding to {@code uri}. - * @param uri The URI of a Lingua Franca file. - * @return The resource corresponding to {@code uri}. - */ - private Resource getResource(URI uri) { - return resourceSetProvider.get().getResource(uri, true); - } - - /** - * Returns the appropriate reporting method for the - * given {@code Severity}. - * @param severity An arbitrary {@code Severity}. - * @return The appropriate reporting method for - * {@code severity}. - */ - private ReportMethod getReportMethod(ErrorReporter errorReporter, Severity severity) { - if (severity == Severity.ERROR) return errorReporter::reportError; - return errorReporter::reportWarning; - } + cancelIndicator, + reportProgress, + new Properties(), + resource, + fileAccess, + fileConfig -> new LanguageServerErrorReporter(resource.getContents().get(0))); + generator.generate(getResource(uri), fileAccess, context); + return context.getResult(); + } + + /** + * Returns the resource corresponding to {@code uri}. + * + * @param uri The URI of a Lingua Franca file. + * @return The resource corresponding to {@code uri}. + */ + private Resource getResource(URI uri) { + return resourceSetProvider.get().getResource(uri, true); + } + + /** + * Returns the appropriate reporting method for the given {@code Severity}. + * + * @param severity An arbitrary {@code Severity}. + * @return The appropriate reporting method for {@code severity}. + */ + private ReportMethod getReportMethod(ErrorReporter errorReporter, Severity severity) { + if (severity == Severity.ERROR) return errorReporter::reportError; + return errorReporter::reportWarning; + } } diff --git a/org.lflang/src/org/lflang/generator/InvalidLfSourceException.java b/org.lflang/src/org/lflang/generator/InvalidLfSourceException.java index 515bdbb8a0..61cf9632f2 100644 --- a/org.lflang/src/org/lflang/generator/InvalidLfSourceException.java +++ b/org.lflang/src/org/lflang/generator/InvalidLfSourceException.java @@ -27,32 +27,31 @@ import org.eclipse.emf.ecore.EObject; /** - * An exception that indicates invalid source, which should - * be reported to the user. This is an error, it should not - * be used for warnings. + * An exception that indicates invalid source, which should be reported to the user. This is an + * error, it should not be used for warnings. * * @author Clément Fournier */ public class InvalidLfSourceException extends RuntimeException { - private final EObject node; - private final String problem; + private final EObject node; + private final String problem; - public InvalidLfSourceException(EObject node, String problem) { - super(problem); - this.node = node; - this.problem = problem; - } + public InvalidLfSourceException(EObject node, String problem) { + super(problem); + this.node = node; + this.problem = problem; + } - public InvalidLfSourceException(String problem, EObject node) { - this(node, problem); - } + public InvalidLfSourceException(String problem, EObject node) { + this(node, problem); + } - public EObject getNode() { - return node; - } + public EObject getNode() { + return node; + } - public String getProblem() { - return problem; - } + public String getProblem() { + return problem; + } } diff --git a/org.lflang/src/org/lflang/generator/InvalidSourceException.java b/org.lflang/src/org/lflang/generator/InvalidSourceException.java index 11bedabce2..88b65d0c24 100644 --- a/org.lflang/src/org/lflang/generator/InvalidSourceException.java +++ b/org.lflang/src/org/lflang/generator/InvalidSourceException.java @@ -25,19 +25,17 @@ package org.lflang.generator; /** - * - * This exception is thrown when a program fails a validity check - * performed by a code generator (and not the validator). This should - * be thrown only when local control flow cannot recover, otherwise - * using {@link GeneratorBase#errorReporter} should be preferred, - * in order to collect more errors before failing. + * This exception is thrown when a program fails a validity check performed by a code generator (and + * not the validator). This should be thrown only when local control flow cannot recover, otherwise + * using {@link GeneratorBase#errorReporter} should be preferred, in order to collect more errors + * before failing. * * @author Clément Fournier */ public class InvalidSourceException extends RuntimeException { - /** Create a new instance of the exception with the given message. */ - public InvalidSourceException(String message) { - super(message); - } + /** Create a new instance of the exception with the given message. */ + public InvalidSourceException(String message) { + super(message); + } } diff --git a/org.lflang/src/org/lflang/generator/LFGenerator.java b/org.lflang/src/org/lflang/generator/LFGenerator.java index c8d985e80c..f2881c9fb8 100644 --- a/org.lflang/src/org/lflang/generator/LFGenerator.java +++ b/org.lflang/src/org/lflang/generator/LFGenerator.java @@ -1,19 +1,18 @@ package org.lflang.generator; +import com.google.inject.Inject; import java.io.IOException; import java.lang.reflect.Constructor; import java.nio.file.Path; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.AbstractGenerator; import org.eclipse.xtext.generator.IFileSystemAccess2; import org.eclipse.xtext.generator.IGeneratorContext; import org.eclipse.xtext.util.RuntimeIOException; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.Target; +import org.lflang.ast.ASTUtils; import org.lflang.federated.generator.FedASTUtils; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FedGenerator; @@ -23,170 +22,179 @@ import org.lflang.generator.python.PythonGenerator; import org.lflang.scoping.LFGlobalScopeProvider; -import com.google.inject.Inject; - /** * Generates code from your model files on save. * - * See - * https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation + *

    See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation */ public class LFGenerator extends AbstractGenerator { - @Inject - private LFGlobalScopeProvider scopeProvider; - - // Indicator of whether generator errors occurred. - protected boolean generatorErrorsOccurred = false; - - /** - * Create a target-specific FileConfig object in Kotlin - *

    - * Since the CppFileConfig and TSFileConfig class are implemented in Kotlin, the classes are - * not visible from all contexts. If the RCA is run from within Eclipse via - * "Run as Eclipse Application", the Kotlin classes are unfortunately not - * available at runtime due to bugs in the Eclipse Kotlin plugin. (See - * https://stackoverflow.com/questions/68095816/is-ist-possible-to-build-mixed-kotlin-and-java-applications-with-a-recent-eclips) - *

    - * If the FileConfig class is found, this method returns an instance. - * Otherwise, it returns an Instance of FileConfig. - * - * @return A FileConfig object in Kotlin if the class can be found. - * @throws IOException If the file config could not be created properly - */ - public static FileConfig createFileConfig(Resource resource, Path srcGenBasePath, - boolean useHierarchicalBin) { - - final Target target = Target.fromDecl(ASTUtils.targetDecl(resource)); - assert target != null; - - // Since our Eclipse Plugin uses code injection via guice, we need to - // play a few tricks here so that FileConfig does not appear as an - // import. Instead, we look the class up at runtime and instantiate it if - // found. - try { - if (FedASTUtils.findFederatedReactor(resource) != null) { - return new FedFileConfig(resource, srcGenBasePath, useHierarchicalBin); - } - switch (target) { - case CCPP: - case C: return new CFileConfig(resource, srcGenBasePath, useHierarchicalBin); - case Python: return new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); - case CPP: - case Rust: - case TS: - String className = "org.lflang.generator." + target.packageName + "." + target.classNamePrefix + "FileConfig"; - try { - return (FileConfig) Class.forName(className) - .getDeclaredConstructor(Resource.class, Path.class, boolean.class) - .newInstance(resource, srcGenBasePath, useHierarchicalBin); - } catch (ReflectiveOperationException e) { - throw new RuntimeException( - "Exception instantiating " + className, e.getCause()); - } - default: - throw new RuntimeException("Could not find FileConfig implementation for target " + target); - } - } catch (IOException e) { - throw new RuntimeException("Unable to create FileConfig object for target " + target + ": " + e.getStackTrace()); - } + @Inject private LFGlobalScopeProvider scopeProvider; + + // Indicator of whether generator errors occurred. + protected boolean generatorErrorsOccurred = false; + + /** + * Create a target-specific FileConfig object in Kotlin + * + *

    Since the CppFileConfig and TSFileConfig class are implemented in Kotlin, the classes are + * not visible from all contexts. If the RCA is run from within Eclipse via "Run as Eclipse + * Application", the Kotlin classes are unfortunately not available at runtime due to bugs in the + * Eclipse Kotlin plugin. (See + * https://stackoverflow.com/questions/68095816/is-ist-possible-to-build-mixed-kotlin-and-java-applications-with-a-recent-eclips) + * + *

    If the FileConfig class is found, this method returns an instance. Otherwise, it returns an + * Instance of FileConfig. + * + * @return A FileConfig object in Kotlin if the class can be found. + * @throws IOException If the file config could not be created properly + */ + public static FileConfig createFileConfig( + Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) { + + final Target target = Target.fromDecl(ASTUtils.targetDecl(resource)); + assert target != null; + + // Since our Eclipse Plugin uses code injection via guice, we need to + // play a few tricks here so that FileConfig does not appear as an + // import. Instead, we look the class up at runtime and instantiate it if + // found. + try { + if (FedASTUtils.findFederatedReactor(resource) != null) { + return new FedFileConfig(resource, srcGenBasePath, useHierarchicalBin); + } + switch (target) { + case CCPP: + case C: + return new CFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case Python: + return new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case CPP: + case Rust: + case TS: + String className = + "org.lflang.generator." + + target.packageName + + "." + + target.classNamePrefix + + "FileConfig"; + try { + return (FileConfig) + Class.forName(className) + .getDeclaredConstructor(Resource.class, Path.class, boolean.class) + .newInstance(resource, srcGenBasePath, useHierarchicalBin); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Exception instantiating " + className, e.getCause()); + } + default: + throw new RuntimeException( + "Could not find FileConfig implementation for target " + target); + } + } catch (IOException e) { + throw new RuntimeException( + "Unable to create FileConfig object for target " + target + ": " + e.getStackTrace()); } - - /** - * Create a generator object for the given target. - * Returns null if the generator could not be created. - */ - private GeneratorBase createGenerator(LFGeneratorContext context) { - final Target target = Target.fromDecl(ASTUtils.targetDecl(context.getFileConfig().resource)); - assert target != null; - return switch (target) { - case C -> new CGenerator(context, false); - case CCPP -> new CGenerator(context, true); - case Python -> new PythonGenerator(context); - case CPP, TS, Rust -> - createKotlinBaseGenerator(target, context); - // If no case matched, then throw a runtime exception. - default -> throw new RuntimeException("Unexpected target!"); - }; + } + + /** + * Create a generator object for the given target. Returns null if the generator could not be + * created. + */ + private GeneratorBase createGenerator(LFGeneratorContext context) { + final Target target = Target.fromDecl(ASTUtils.targetDecl(context.getFileConfig().resource)); + assert target != null; + return switch (target) { + case C -> new CGenerator(context, false); + case CCPP -> new CGenerator(context, true); + case Python -> new PythonGenerator(context); + case CPP, TS, Rust -> createKotlinBaseGenerator(target, context); + // If no case matched, then throw a runtime exception. + default -> throw new RuntimeException("Unexpected target!"); + }; + } + + /** + * Create a code generator in Kotlin. + * + *

    Since the CppGenerator and TSGenerator class are implemented in Kotlin, the classes are not + * visible from all contexts. If the RCA is run from within Eclipse via "Run as Eclipse + * Application", the Kotlin classes are unfortunately not available at runtime due to bugs in the + * Eclipse Kotlin plugin. (See + * https://stackoverflow.com/questions/68095816/is-ist-possible-to-build-mixed-kotlin-and-java-applications-with-a-recent-eclips) + * In this case, the method returns null + * + * @return A Kotlin Generator object if the class can be found + */ + private GeneratorBase createKotlinBaseGenerator(Target target, LFGeneratorContext context) { + // Since our Eclipse Plugin uses code injection via guice, we need to + // play a few tricks here so that Kotlin FileConfig and + // Kotlin Generator do not appear as an import. Instead, we look the + // class up at runtime and instantiate it if found. + String classPrefix = + "org.lflang.generator." + target.packageName + "." + target.classNamePrefix; + try { + Class generatorClass = Class.forName(classPrefix + "Generator"); + Constructor ctor = + generatorClass.getDeclaredConstructor( + LFGeneratorContext.class, LFGlobalScopeProvider.class); + + return (GeneratorBase) ctor.newInstance(context, scopeProvider); + } catch (ReflectiveOperationException e) { + generatorErrorsOccurred = true; + context + .getErrorReporter() + .reportError( + "The code generator for the " + + target + + " target could not be found. " + + "This is likely because you built Epoch using " + + "Eclipse. The " + + target + + " code generator is written in Kotlin and, unfortunately, the plugin that" + + " Eclipse uses for compiling Kotlin code is broken. Please consider building" + + " Epoch using Maven.\n" + + "For step-by-step instructions, see: " + + "https://github.com/icyphy/lingua-franca/wiki/Running-Lingua-Franca-IDE-%28Epoch%29-with-Kotlin-based-Code-Generators-Enabled-%28without-Eclipse-Environment%29"); + return null; + } + } + + @Override + public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { + final LFGeneratorContext lfContext; + if (context instanceof LFGeneratorContext) { + lfContext = (LFGeneratorContext) context; + } else { + lfContext = LFGeneratorContext.lfGeneratorContextOf(resource, fsa, context); } + // The fastest way to generate code is to not generate any code. + if (lfContext.getMode() == LFGeneratorContext.Mode.LSP_FAST) return; - /** - * Create a code generator in Kotlin. - *

    - * Since the CppGenerator and TSGenerator class are implemented in Kotlin, the classes are - * not visible from all contexts. If the RCA is run from within Eclipse via - * "Run as Eclipse Application", the Kotlin classes are unfortunately not - * available at runtime due to bugs in the Eclipse Kotlin plugin. (See - * https://stackoverflow.com/questions/68095816/is-ist-possible-to-build-mixed-kotlin-and-java-applications-with-a-recent-eclips) - * In this case, the method returns null - * - * @return A Kotlin Generator object if the class can be found - */ - private GeneratorBase createKotlinBaseGenerator(Target target, LFGeneratorContext context) { - // Since our Eclipse Plugin uses code injection via guice, we need to - // play a few tricks here so that Kotlin FileConfig and - // Kotlin Generator do not appear as an import. Instead, we look the - // class up at runtime and instantiate it if found. - String classPrefix = "org.lflang.generator." + target.packageName + "." + target.classNamePrefix; - try { - Class generatorClass = Class.forName(classPrefix + "Generator"); - Constructor ctor = generatorClass - .getDeclaredConstructor(LFGeneratorContext.class, LFGlobalScopeProvider.class); - - return (GeneratorBase) ctor.newInstance(context, scopeProvider); - } catch (ReflectiveOperationException e) { - generatorErrorsOccurred = true; - context.getErrorReporter().reportError( - "The code generator for the " + target + " target could not be found. " - + "This is likely because you built Epoch using " - + "Eclipse. The " + target + " code generator is written in Kotlin " - + "and, unfortunately, the plugin that Eclipse uses " - + "for compiling Kotlin code is broken. " - + "Please consider building Epoch using Maven.\n" - + "For step-by-step instructions, see: " - + "https://github.com/icyphy/lingua-franca/wiki/Running-Lingua-Franca-IDE-%28Epoch%29-with-Kotlin-based-Code-Generators-Enabled-%28without-Eclipse-Environment%29"); - return null; - } - } + if (FedASTUtils.findFederatedReactor(resource) != null) { + try { + generatorErrorsOccurred = (new FedGenerator(lfContext)).doGenerate(resource, lfContext); + } catch (IOException e) { + throw new RuntimeIOException("Error during federated code generation", e); + } - @Override - public void doGenerate(Resource resource, IFileSystemAccess2 fsa, - IGeneratorContext context) { - final LFGeneratorContext lfContext; - if (context instanceof LFGeneratorContext) { - lfContext = (LFGeneratorContext)context; - } else { - lfContext = LFGeneratorContext.lfGeneratorContextOf(resource, fsa, context); - } - - // The fastest way to generate code is to not generate any code. - if (lfContext.getMode() == LFGeneratorContext.Mode.LSP_FAST) return; - - if (FedASTUtils.findFederatedReactor(resource) != null) { - try { - generatorErrorsOccurred = (new FedGenerator(lfContext)).doGenerate(resource, lfContext); - } catch (IOException e) { - throw new RuntimeIOException("Error during federated code generation", e); - } - - } else { - - final GeneratorBase generator = createGenerator(lfContext); - - if (generator != null) { - generator.doGenerate(resource, lfContext); - generatorErrorsOccurred = generator.errorsOccurred(); - } - } - final ErrorReporter errorReporter = lfContext.getErrorReporter(); - if (errorReporter instanceof LanguageServerErrorReporter) { - ((LanguageServerErrorReporter) errorReporter).publishDiagnostics(); - } - } + } else { - /** Return true if errors occurred in the last call to doGenerate(). */ - public boolean errorsOccurred() { - return generatorErrorsOccurred; + final GeneratorBase generator = createGenerator(lfContext); + + if (generator != null) { + generator.doGenerate(resource, lfContext); + generatorErrorsOccurred = generator.errorsOccurred(); + } + } + final ErrorReporter errorReporter = lfContext.getErrorReporter(); + if (errorReporter instanceof LanguageServerErrorReporter) { + ((LanguageServerErrorReporter) errorReporter).publishDiagnostics(); } + } + + /** Return true if errors occurred in the last call to doGenerate(). */ + public boolean errorsOccurred() { + return generatorErrorsOccurred; + } } diff --git a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java b/org.lflang/src/org/lflang/generator/LFGeneratorContext.java index 84032ecdc6..727ce229b9 100644 --- a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java +++ b/org.lflang/src/org/lflang/generator/LFGeneratorContext.java @@ -3,160 +3,146 @@ import java.nio.file.Path; import java.util.Map; import java.util.Properties; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.IFileSystemAccess2; import org.eclipse.xtext.generator.IGeneratorContext; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; /** - * An {@code LFGeneratorContext} is the context of a Lingua Franca build process. - * It is the point of communication between a build process and the environment - * in which it is executed. + * An {@code LFGeneratorContext} is the context of a Lingua Franca build process. It is the point of + * communication between a build process and the environment in which it is executed. * * @author Peter Donovan */ public interface LFGeneratorContext extends IGeneratorContext { - /** - * Enumeration of keys used to parameterize the build process. - */ - enum BuildParm { - BUILD_TYPE("The build type to use"), - CLEAN("Clean before building."), - EXTERNAL_RUNTIME_PATH("Specify an external runtime library to be used by the compiled binary."), - FEDERATED("Treat main reactor as federated."), - HELP("Display this information."), - LOGGING("The logging level to use by the generated binary"), - LINT("Enable or disable linting of generated code."), - NO_COMPILE("Do not invoke target compiler."), - OUTPUT_PATH("Specify the root output directory."), - PRINT_STATISTICS("Instruct the runtime to collect and print statistics."), - QUIET("Suppress output of the target compiler and other commands"), - RTI("Specify the location of the RTI."), - RUNTIME_VERSION("Specify the version of the runtime library used for compiling LF programs."), - SCHEDULER("Specify the runtime scheduler (if supported)."), - TARGET_COMPILER("Target compiler to invoke."), - THREADING("Specify whether the runtime should use multi-threading (true/false)."), - VERSION("Print version information."), - WORKERS("Specify the default number of worker threads."); - - public final String description; - - BuildParm(String description) { - this.description = description; - } - - /** - * Return the string to use as the key to store a value relating to this parameter. - */ - public String getKey() { - return this.name().toLowerCase().replace('_', '-'); - } - - /** - * Return the value corresponding to this parameter or {@code null} if there is none. - * @param context The context passed to the code generator. - */ - public String getValue(LFGeneratorContext context) { - return context.getArgs().getProperty(this.getKey()); - } + /** Enumeration of keys used to parameterize the build process. */ + enum BuildParm { + BUILD_TYPE("The build type to use"), + CLEAN("Clean before building."), + EXTERNAL_RUNTIME_PATH("Specify an external runtime library to be used by the compiled binary."), + FEDERATED("Treat main reactor as federated."), + HELP("Display this information."), + LOGGING("The logging level to use by the generated binary"), + LINT("Enable or disable linting of generated code."), + NO_COMPILE("Do not invoke target compiler."), + OUTPUT_PATH("Specify the root output directory."), + PRINT_STATISTICS("Instruct the runtime to collect and print statistics."), + QUIET("Suppress output of the target compiler and other commands"), + RTI("Specify the location of the RTI."), + RUNTIME_VERSION("Specify the version of the runtime library used for compiling LF programs."), + SCHEDULER("Specify the runtime scheduler (if supported)."), + TARGET_COMPILER("Target compiler to invoke."), + THREADING("Specify whether the runtime should use multi-threading (true/false)."), + VERSION("Print version information."), + WORKERS("Specify the default number of worker threads."); + + public final String description; + + BuildParm(String description) { + this.description = description; } - - enum Mode { - STANDALONE, - EPOCH, - LSP_FAST, - LSP_MEDIUM, - LSP_SLOW, - UNDEFINED + /** Return the string to use as the key to store a value relating to this parameter. */ + public String getKey() { + return this.name().toLowerCase().replace('_', '-'); } /** - * Return the mode of operation, which indicates how the compiler has been invoked - * (e.g., from within Epoch, from the command line, or via a Language Server). - */ - Mode getMode(); - - /** - * Return any arguments that will override target properties. - */ - Properties getArgs(); - - /** - * Get the error reporter for this context; construct one if it hasn't been - * constructed yet. - */ - ErrorReporter getErrorReporter(); - - /** - * Mark the code generation process performed in this - * context as finished with the result {@code result}. - * @param result The result of the code generation - * process that was performed in this - * context. + * Return the value corresponding to this parameter or {@code null} if there is none. + * + * @param context The context passed to the code generator. */ - void finish(GeneratorResult result); - - /** - * Return the result of the code generation process that was performed in - * this context. - * @return the result of the code generation process that was performed in - * this context - */ - GeneratorResult getResult(); - - FileConfig getFileConfig(); - - TargetConfig getTargetConfig(); - - /** - * Report the progress of a build. - * @param message A message for the LF programmer to read. - * @param percentage The approximate percent completion of the build. - */ - void reportProgress(String message, int percentage); - - /** - * Conclude this build and record the result if necessary. - * @param status The status of the result. - * @param codeMaps The generated files and their corresponding code maps. - */ - default void finish( - GeneratorResult.Status status, - Map codeMaps - ) { - finish(new GeneratorResult(status, this, codeMaps)); - } - - /** - * Conclude this build and record that it was unsuccessful. - */ - default void unsuccessfulFinish() { - finish( - getCancelIndicator() != null && getCancelIndicator().isCanceled() ? - GeneratorResult.CANCELLED : GeneratorResult.FAILED - ); - } - - /** - * Return the {@code LFGeneratorContext} that best describes the given {@code context} when - * building {@code Resource}. - * @param resource - * @param fsa - * @param context The context of a Lingua Franca build process. - * @return The {@code LFGeneratorContext} that best describes the given {@code context} when - * building {@code Resource}. - */ - static LFGeneratorContext lfGeneratorContextOf(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { - if (context instanceof LFGeneratorContext) return (LFGeneratorContext) context; - - if (resource.getURI().isPlatform()) return new MainContext(Mode.EPOCH, resource, fsa, context.getCancelIndicator()); - - return new MainContext(Mode.LSP_FAST, resource, fsa, context.getCancelIndicator()); + public String getValue(LFGeneratorContext context) { + return context.getArgs().getProperty(this.getKey()); } + } + + enum Mode { + STANDALONE, + EPOCH, + LSP_FAST, + LSP_MEDIUM, + LSP_SLOW, + UNDEFINED + } + + /** + * Return the mode of operation, which indicates how the compiler has been invoked (e.g., from + * within Epoch, from the command line, or via a Language Server). + */ + Mode getMode(); + + /** Return any arguments that will override target properties. */ + Properties getArgs(); + + /** Get the error reporter for this context; construct one if it hasn't been constructed yet. */ + ErrorReporter getErrorReporter(); + + /** + * Mark the code generation process performed in this context as finished with the result {@code + * result}. + * + * @param result The result of the code generation process that was performed in this context. + */ + void finish(GeneratorResult result); + + /** + * Return the result of the code generation process that was performed in this context. + * + * @return the result of the code generation process that was performed in this context + */ + GeneratorResult getResult(); + + FileConfig getFileConfig(); + + TargetConfig getTargetConfig(); + + /** + * Report the progress of a build. + * + * @param message A message for the LF programmer to read. + * @param percentage The approximate percent completion of the build. + */ + void reportProgress(String message, int percentage); + + /** + * Conclude this build and record the result if necessary. + * + * @param status The status of the result. + * @param codeMaps The generated files and their corresponding code maps. + */ + default void finish(GeneratorResult.Status status, Map codeMaps) { + finish(new GeneratorResult(status, this, codeMaps)); + } + + /** Conclude this build and record that it was unsuccessful. */ + default void unsuccessfulFinish() { + finish( + getCancelIndicator() != null && getCancelIndicator().isCanceled() + ? GeneratorResult.CANCELLED + : GeneratorResult.FAILED); + } + + /** + * Return the {@code LFGeneratorContext} that best describes the given {@code context} when + * building {@code Resource}. + * + * @param resource + * @param fsa + * @param context The context of a Lingua Franca build process. + * @return The {@code LFGeneratorContext} that best describes the given {@code context} when + * building {@code Resource}. + */ + static LFGeneratorContext lfGeneratorContextOf( + Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { + if (context instanceof LFGeneratorContext) return (LFGeneratorContext) context; + + if (resource.getURI().isPlatform()) + return new MainContext(Mode.EPOCH, resource, fsa, context.getCancelIndicator()); + + return new MainContext(Mode.LSP_FAST, resource, fsa, context.getCancelIndicator()); + } } diff --git a/org.lflang/src/org/lflang/generator/LFResource.java b/org.lflang/src/org/lflang/generator/LFResource.java index bc59c418ee..42367dd24f 100644 --- a/org.lflang/src/org/lflang/generator/LFResource.java +++ b/org.lflang/src/org/lflang/generator/LFResource.java @@ -5,36 +5,43 @@ import org.lflang.TargetConfig; /** - * A class that keeps metadata for discovered resources - * during code generation and the supporting structures - * associated with that resource. - * + * A class that keeps metadata for discovered resources during code generation and the supporting + * structures associated with that resource. + * * @author Soroush Bateni */ public class LFResource { - LFResource(Resource resource, FileConfig fileConfig, TargetConfig targetConfig) { - this.eResource = resource; // FIXME: this is redundant because fileConfig already has the resource. - this.fileConfig = fileConfig; - this.targetConfig = targetConfig; - } - - /** - * Resource associated with a file either from the main .lf - * file or one of the imported ones. - */ - Resource eResource; - public Resource getEResource() { return this.eResource; }; - - /** - * The file config associated with 'resource' that can be - * used to discover files relative to that resource. - */ - FileConfig fileConfig; - public FileConfig getFileConfig() { return this.fileConfig; }; - - /** - * The target config read from the resource. - */ - TargetConfig targetConfig; - public TargetConfig getTargetConfig() { return this.targetConfig; }; + LFResource(Resource resource, FileConfig fileConfig, TargetConfig targetConfig) { + this.eResource = + resource; // FIXME: this is redundant because fileConfig already has the resource. + this.fileConfig = fileConfig; + this.targetConfig = targetConfig; + } + + /** Resource associated with a file either from the main .lf file or one of the imported ones. */ + Resource eResource; + + public Resource getEResource() { + return this.eResource; + } + ; + + /** + * The file config associated with 'resource' that can be used to discover files relative to that + * resource. + */ + FileConfig fileConfig; + + public FileConfig getFileConfig() { + return this.fileConfig; + } + ; + + /** The target config read from the resource. */ + TargetConfig targetConfig; + + public TargetConfig getTargetConfig() { + return this.targetConfig; + } + ; } diff --git a/org.lflang/src/org/lflang/generator/LanguageServerErrorReporter.java b/org.lflang/src/org/lflang/generator/LanguageServerErrorReporter.java index 5ce5da28dc..31304f43c9 100644 --- a/org.lflang/src/org/lflang/generator/LanguageServerErrorReporter.java +++ b/org.lflang/src/org/lflang/generator/LanguageServerErrorReporter.java @@ -6,16 +6,14 @@ import java.util.List; import java.util.Map; import java.util.Optional; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.lsp4j.PublishDiagnosticsParams; import org.eclipse.lsp4j.Range; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.lsp4j.services.LanguageClient; - +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.lflang.ErrorReporter; /** @@ -25,179 +23,174 @@ */ public class LanguageServerErrorReporter implements ErrorReporter { - /** - * The language client to which errors should be - * reported, if such a client is available. - * FIXME: This is a de facto global, and it is a hack. - */ - private static LanguageClient client; - - /** 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; - - /* ------------------------ CONSTRUCTORS -------------------------- */ - - /** - * Initialize a {@code DiagnosticAcceptor} for the - * document whose parse tree root node is - * {@code parseRoot}. - * @param parseRoot the root of the AST of the document - * for which this is an error reporter - */ - public LanguageServerErrorReporter(EObject parseRoot) { - this.parseRoot = parseRoot; - this.diagnostics = new HashMap<>(); - } - - /* ----------------------- PUBLIC METHODS ------------------------- */ - - @Override - public String reportError(String message) { - return report(getMainFile(), DiagnosticSeverity.Error, message); - } - - @Override - public String reportWarning(String message) { - return report(getMainFile(), DiagnosticSeverity.Warning, message); - } - - @Override - public String reportInfo(String message) { - return report(getMainFile(), DiagnosticSeverity.Information, message); - } - - @Override - public String reportError(EObject object, String message) { - return reportError(message); - } - - @Override - public String reportWarning(EObject object, String message) { - return reportWarning(message); - } - - @Override - public String reportInfo(EObject object, String message) { - return reportInfo(message); - } - - @Override - public String reportError(Path file, Integer line, String message) { - return report(file, DiagnosticSeverity.Error, message, line != null ? line : 1); - } - - @Override - public String reportWarning(Path file, Integer line, String message) { - return report(file, DiagnosticSeverity.Warning, message, line != null ? line : 1); - } - - @Override - public String reportInfo(Path file, Integer line, String message) { - return report(file, DiagnosticSeverity.Information, message, line != null ? line : 1); - } - - @Override - public boolean getErrorsOccurred() { - return diagnostics.values().stream().anyMatch( - it -> it.stream().anyMatch(diagnostic -> diagnostic.getSeverity() == DiagnosticSeverity.Error) - ); - } - - @Override - public String report(Path file, DiagnosticSeverity severity, String message) { - return report(file, severity, message, 1); - } - - @Override - public String report(Path file, DiagnosticSeverity severity, String message, int line) { - Optional text = getLine(line - 1); - return report( - file, - severity, - message, - Position.fromOneBased(line, 1), - Position.fromOneBased(line, 1 + (text.isEmpty() ? 0 : text.get().length())) - ); - } - - @Override - public String report(Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { - if (file == null) file = getMainFile(); - diagnostics.putIfAbsent(file, new ArrayList<>()); - diagnostics.get(file).add(new Diagnostic( - toRange(startPos, endPos), message, severity, "LF Language Server" - )); - return "" + severity + ": " + message; - } - - /** - * Save a reference to the language client. - * @param client the language client - */ - public static void setClient(LanguageClient client) { - LanguageServerErrorReporter.client = client; - } - - /** - * Publish diagnostics by forwarding them to the - * language client. - */ - public void publishDiagnostics() { - if (client == null) { - System.err.println( - "WARNING: Cannot publish diagnostics because the language client has not yet been found." - ); - return; - } - for (Path file : diagnostics.keySet()) { - PublishDiagnosticsParams publishDiagnosticsParams = new PublishDiagnosticsParams(); - publishDiagnosticsParams.setUri(URI.createFileURI(file.toString()).toString()); - publishDiagnosticsParams.setDiagnostics(diagnostics.get(file)); - client.publishDiagnostics(publishDiagnosticsParams); - } - } - - /* ----------------------- PRIVATE METHODS ------------------------ */ - - /** Return the file on which the current validation process was triggered. */ - private Path getMainFile() { - return Path.of(parseRoot.eResource().getURI().toFileString()); - } - - /** - * Return the text of the document for which this is an - * error reporter. - * @return the text of the document for which this is an - * error reporter - */ - private String getText() { - return NodeModelUtils.getNode(parseRoot).getText(); - } - - /** - * Return the line at index {@code line} in the - * document for which this is an error reporter. - * @param line the zero-based line index - * @return the line located at the given index - */ - private Optional getLine(int line) { - return getText().lines().skip(line).findFirst(); - } - - /** - * Return the Range that starts at {@code p0} and ends - * at {@code p1}. - * @param p0 an arbitrary Position - * @param p1 a Position that is greater than {@code p0} - * @return the Range that starts at {@code p0} and ends - * at {@code p1} - */ - private Range toRange(Position p0, Position p1) { - return new Range( - new org.eclipse.lsp4j.Position(p0.getZeroBasedLine(), p0.getZeroBasedColumn()), - new org.eclipse.lsp4j.Position(p1.getZeroBasedLine(), p1.getZeroBasedColumn()) - ); - } + /** + * The language client to which errors should be reported, if such a client is available. FIXME: + * This is a de facto global, and it is a hack. + */ + private static LanguageClient client; + + /** 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; + + /* ------------------------ CONSTRUCTORS -------------------------- */ + + /** + * Initialize a {@code DiagnosticAcceptor} for the document whose parse tree root node is {@code + * parseRoot}. + * + * @param parseRoot the root of the AST of the document for which this is an error reporter + */ + public LanguageServerErrorReporter(EObject parseRoot) { + this.parseRoot = parseRoot; + this.diagnostics = new HashMap<>(); + } + + /* ----------------------- PUBLIC METHODS ------------------------- */ + + @Override + public String reportError(String message) { + return report(getMainFile(), DiagnosticSeverity.Error, message); + } + + @Override + public String reportWarning(String message) { + return report(getMainFile(), DiagnosticSeverity.Warning, message); + } + + @Override + public String reportInfo(String message) { + return report(getMainFile(), DiagnosticSeverity.Information, message); + } + + @Override + public String reportError(EObject object, String message) { + return reportError(message); + } + + @Override + public String reportWarning(EObject object, String message) { + return reportWarning(message); + } + + @Override + public String reportInfo(EObject object, String message) { + return reportInfo(message); + } + + @Override + public String reportError(Path file, Integer line, String message) { + return report(file, DiagnosticSeverity.Error, message, line != null ? line : 1); + } + + @Override + public String reportWarning(Path file, Integer line, String message) { + return report(file, DiagnosticSeverity.Warning, message, line != null ? line : 1); + } + + @Override + public String reportInfo(Path file, Integer line, String message) { + return report(file, DiagnosticSeverity.Information, message, line != null ? line : 1); + } + + @Override + public boolean getErrorsOccurred() { + return diagnostics.values().stream() + .anyMatch( + it -> + it.stream() + .anyMatch(diagnostic -> diagnostic.getSeverity() == DiagnosticSeverity.Error)); + } + + @Override + public String report(Path file, DiagnosticSeverity severity, String message) { + return report(file, severity, message, 1); + } + + @Override + public String report(Path file, DiagnosticSeverity severity, String message, int line) { + Optional text = getLine(line - 1); + return report( + file, + severity, + message, + Position.fromOneBased(line, 1), + Position.fromOneBased(line, 1 + (text.isEmpty() ? 0 : text.get().length()))); + } + + @Override + public String report( + Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) { + if (file == null) file = getMainFile(); + diagnostics.putIfAbsent(file, new ArrayList<>()); + diagnostics + .get(file) + .add(new Diagnostic(toRange(startPos, endPos), message, severity, "LF Language Server")); + return "" + severity + ": " + message; + } + + /** + * Save a reference to the language client. + * + * @param client the language client + */ + public static void setClient(LanguageClient client) { + LanguageServerErrorReporter.client = client; + } + + /** Publish diagnostics by forwarding them to the language client. */ + public void publishDiagnostics() { + if (client == null) { + System.err.println( + "WARNING: Cannot publish diagnostics because the language client has not yet been" + + " found."); + return; + } + for (Path file : diagnostics.keySet()) { + PublishDiagnosticsParams publishDiagnosticsParams = new PublishDiagnosticsParams(); + publishDiagnosticsParams.setUri(URI.createFileURI(file.toString()).toString()); + publishDiagnosticsParams.setDiagnostics(diagnostics.get(file)); + client.publishDiagnostics(publishDiagnosticsParams); + } + } + + /* ----------------------- PRIVATE METHODS ------------------------ */ + + /** Return the file on which the current validation process was triggered. */ + private Path getMainFile() { + return Path.of(parseRoot.eResource().getURI().toFileString()); + } + + /** + * Return the text of the document for which this is an error reporter. + * + * @return the text of the document for which this is an error reporter + */ + private String getText() { + return NodeModelUtils.getNode(parseRoot).getText(); + } + + /** + * Return the line at index {@code line} in the document for which this is an error reporter. + * + * @param line the zero-based line index + * @return the line located at the given index + */ + private Optional getLine(int line) { + return getText().lines().skip(line).findFirst(); + } + + /** + * Return the Range that starts at {@code p0} and ends at {@code p1}. + * + * @param p0 an arbitrary Position + * @param p1 a Position that is greater than {@code p0} + * @return the Range that starts at {@code p0} and ends at {@code p1} + */ + private Range toRange(Position p0, Position p1) { + return new Range( + new org.eclipse.lsp4j.Position(p0.getZeroBasedLine(), p0.getZeroBasedColumn()), + new org.eclipse.lsp4j.Position(p1.getZeroBasedLine(), p1.getZeroBasedColumn())); + } } diff --git a/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java b/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java index 2bb72789ff..15f0e8ddad 100644 --- a/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java +++ b/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java @@ -40,121 +40,120 @@ */ public interface LfExpressionVisitor { - - R visitLiteral(Literal expr, P param); - - R visitBracedListExpr(BracedListExpression expr, P param); - - R visitTimeLiteral(Time expr, P param); - - R visitCodeExpr(CodeExpr expr, P param); - - R visitParameterRef(ParameterReference expr, P param); - - /** - * Dispatch the visitor on the given expression type. - * - * @param e An expression that will be visited - * @param arg Argument for the visitor - * @param visitor Visitor - * @param

    Type of parameter expected by the visitor - * @param Return type of the visitor - * @return The return value of the visitor - */ - static R dispatch(Expression e, P arg, LfExpressionVisitor visitor) { - if (e instanceof Literal) { - return visitor.visitLiteral((Literal) e, arg); - } else if (e instanceof BracedListExpression) { - return visitor.visitBracedListExpr((BracedListExpression) e, arg); - } else if (e instanceof Time) { - return visitor.visitTimeLiteral((Time) e, arg); - } else if (e instanceof CodeExpr) { - return visitor.visitCodeExpr((CodeExpr) e, arg); - } else if (e instanceof ParameterReference) { - return visitor.visitParameterRef((ParameterReference) e, arg); - } - - throw new IllegalArgumentException("Expression of type " + e.getClass() + " not handled"); + R visitLiteral(Literal expr, P param); + + R visitBracedListExpr(BracedListExpression expr, P param); + + R visitTimeLiteral(Time expr, P param); + + R visitCodeExpr(CodeExpr expr, P param); + + R visitParameterRef(ParameterReference expr, P param); + + /** + * Dispatch the visitor on the given expression type. + * + * @param e An expression that will be visited + * @param arg Argument for the visitor + * @param visitor Visitor + * @param

    Type of parameter expected by the visitor + * @param Return type of the visitor + * @return The return value of the visitor + */ + static R dispatch( + Expression e, P arg, LfExpressionVisitor visitor) { + if (e instanceof Literal) { + return visitor.visitLiteral((Literal) e, arg); + } else if (e instanceof BracedListExpression) { + return visitor.visitBracedListExpr((BracedListExpression) e, arg); + } else if (e instanceof Time) { + return visitor.visitTimeLiteral((Time) e, arg); + } else if (e instanceof CodeExpr) { + return visitor.visitCodeExpr((CodeExpr) e, arg); + } else if (e instanceof ParameterReference) { + return visitor.visitParameterRef((ParameterReference) e, arg); } - /** Base visitor class where methods are defaulted to a common one. */ - abstract class DefaultLfVisitor implements LfExpressionVisitor { + throw new IllegalArgumentException("Expression of type " + e.getClass() + " not handled"); + } + + /** Base visitor class where methods are defaulted to a common one. */ + abstract class DefaultLfVisitor implements LfExpressionVisitor { + + abstract R visitExpression(Expression expr, P param); - abstract R visitExpression(Expression expr, P param); + @Override + public R visitLiteral(Literal expr, P param) { + return visitExpression(expr, param); + } + + @Override + public R visitBracedListExpr(BracedListExpression expr, P param) { + return visitExpression(expr, param); + } - @Override - public R visitLiteral(Literal expr, P param) { - return visitExpression(expr, param); - } + @Override + public R visitTimeLiteral(Time expr, P param) { + return visitExpression(expr, param); + } - @Override - public R visitBracedListExpr(BracedListExpression expr, P param) { - return visitExpression(expr, param); - } + @Override + public R visitCodeExpr(CodeExpr expr, P param) { + return visitExpression(expr, param); + } - @Override - public R visitTimeLiteral(Time expr, P param) { - return visitExpression(expr, param); - } + @Override + public R visitParameterRef(ParameterReference expr, P param) { + return visitExpression(expr, param); + } + } + + /** + * A visitor that deep copies the expression. Can be extended to replace certain expressions + * during the copy. + * + * @param

    Parameter type + */ + class LfExpressionDeepCopyVisitor

    implements LfExpressionVisitor { + + @Override + public Expression visitLiteral(Literal expr, P param) { + Literal clone = LfFactory.eINSTANCE.createLiteral(); + clone.setLiteral(expr.getLiteral()); + return clone; + } - @Override - public R visitCodeExpr(CodeExpr expr, P param) { - return visitExpression(expr, param); - } + @Override + public Expression visitBracedListExpr(BracedListExpression expr, P param) { + BracedListExpression clone = LfFactory.eINSTANCE.createBracedListExpression(); + for (Expression item : expr.getItems()) { + clone.getItems().add(dispatch(item, param, this)); + } + return clone; + } - @Override - public R visitParameterRef(ParameterReference expr, P param) { - return visitExpression(expr, param); - } + @Override + public Expression visitTimeLiteral(Time expr, P param) { + Time clone = LfFactory.eINSTANCE.createTime(); + clone.setUnit(expr.getUnit()); + clone.setInterval(expr.getInterval()); + return clone; } - /** - * A visitor that deep copies the expression. Can be extended - * to replace certain expressions during the copy. - * - * @param

    Parameter type - */ - class LfExpressionDeepCopyVisitor

    implements LfExpressionVisitor { - - @Override - public Expression visitLiteral(Literal expr, P param) { - Literal clone = LfFactory.eINSTANCE.createLiteral(); - clone.setLiteral(expr.getLiteral()); - return clone; - } - - @Override - public Expression visitBracedListExpr(BracedListExpression expr, P param) { - BracedListExpression clone = LfFactory.eINSTANCE.createBracedListExpression(); - for (Expression item : expr.getItems()) { - clone.getItems().add(dispatch(item, param, this)); - } - return clone; - } - - @Override - public Expression visitTimeLiteral(Time expr, P param) { - Time clone = LfFactory.eINSTANCE.createTime(); - clone.setUnit(expr.getUnit()); - clone.setInterval(expr.getInterval()); - return clone; - } - - @Override - public Expression visitParameterRef(ParameterReference expr, P param) { - ParameterReference clone = LfFactory.eINSTANCE.createParameterReference(); - clone.setParameter(expr.getParameter()); - return clone; - } - - @Override - public Expression visitCodeExpr(CodeExpr expr, P param) { - CodeExpr codeExpr = LfFactory.eINSTANCE.createCodeExpr(); - Code code = LfFactory.eINSTANCE.createCode(); - code.setBody(expr.getCode().getBody()); - codeExpr.setCode(code); - return codeExpr; - } + @Override + public Expression visitParameterRef(ParameterReference expr, P param) { + ParameterReference clone = LfFactory.eINSTANCE.createParameterReference(); + clone.setParameter(expr.getParameter()); + return clone; } + @Override + public Expression visitCodeExpr(CodeExpr expr, P param) { + CodeExpr codeExpr = LfFactory.eINSTANCE.createCodeExpr(); + Code code = LfFactory.eINSTANCE.createCode(); + code.setBody(expr.getCode().getBody()); + codeExpr.setCode(code); + return codeExpr; + } + } } diff --git a/org.lflang/src/org/lflang/generator/MainContext.java b/org.lflang/src/org/lflang/generator/MainContext.java index 5ee53e5f83..4a60c4d6a8 100644 --- a/org.lflang/src/org/lflang/generator/MainContext.java +++ b/org.lflang/src/org/lflang/generator/MainContext.java @@ -4,12 +4,10 @@ import java.util.Objects; import java.util.Properties; import java.util.function.Function; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.IFileSystemAccess2; import org.eclipse.xtext.util.CancelIndicator; import org.eclipse.xtext.util.RuntimeIOException; - import org.lflang.DefaultErrorReporter; import org.lflang.ErrorReporter; import org.lflang.FileConfig; @@ -17,154 +15,156 @@ import org.lflang.generator.IntegratedBuilder.ReportProgress; /** - * A {@code MainContext} is an {@code LFGeneratorContext} that is - * not nested in any other generator context. There is one - * {@code MainContext} for every build process. + * A {@code MainContext} is an {@code LFGeneratorContext} that is not nested in any other generator + * context. There is one {@code MainContext} for every build process. * * @author Peter Donovan */ public class MainContext implements LFGeneratorContext { - - /** - * This constructor will be set by the LF plugin, if the generator is running in Epoch. - */ - public static Function EPOCH_ERROR_REPORTER_CONSTRUCTOR = null; - - /** - * 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; - - private final FileConfig fileConfig; - - /** Whether the requested build is required to be complete. */ - private final Mode mode; - - private TargetConfig targetConfig; - - /** The result of the code generation process. */ - private GeneratorResult result = null; - private final Properties args; - private final ErrorReporter errorReporter; - - /** - * Initialize the context of a build process whose cancellation is - * indicated by {@code cancelIndicator} - * @param mode The mode of this build process. - * @param cancelIndicator The cancel indicator of the code generation - * process to which this corresponds. - */ - public MainContext(Mode mode, Resource resource, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) { - this( - mode, cancelIndicator, (message, completion) -> {}, new Properties(), resource, fsa, - (mode == Mode.EPOCH && EPOCH_ERROR_REPORTER_CONSTRUCTOR != null) ? - EPOCH_ERROR_REPORTER_CONSTRUCTOR : - fileConfig -> new DefaultErrorReporter() - ); - } - - /** - * Initialize the context of a build process whose cancellation is - * indicated by {@code cancelIndicator} - * @param mode The mode of this build process. - * @param cancelIndicator The cancel indicator of the code generation - * process to which this corresponds. - * @param reportProgress The {@code ReportProgress} function of - * {@code this}. - * @param args Any arguments that may be used to affect the product of the - * build. - * @param resource ... - * @param fsa ... - * @param constructErrorReporter A function that constructs the appropriate - * error reporter for the given FileConfig. - */ - public MainContext( - Mode mode, - CancelIndicator cancelIndicator, - ReportProgress reportProgress, - Properties args, - Resource resource, - IFileSystemAccess2 fsa, - Function constructErrorReporter - ) { - this.mode = mode; - this.cancelIndicator = cancelIndicator == null ? () -> false : cancelIndicator; - this.reportProgress = reportProgress; - this.args = args; - - try { - var useHierarchicalBin = args.containsKey("hierarchical-bin") && Boolean.parseBoolean(args.getProperty("hierarchical-bin")); - fileConfig = Objects.requireNonNull(LFGenerator.createFileConfig(resource, FileConfig.getSrcGenRoot(fsa), useHierarchicalBin)); - } catch (IOException e) { - throw new RuntimeIOException("Error during FileConfig instantiation", e); - } - - this.errorReporter = constructErrorReporter.apply(this.fileConfig); - - loadTargetConfig(); - } - - @Override - public CancelIndicator getCancelIndicator() { - return cancelIndicator; - } - - @Override - public Mode getMode() { - return mode; - } - - @Override - public Properties getArgs() { - return args; - } - - @Override - public ErrorReporter getErrorReporter() { - return errorReporter; + /** This constructor will be set by the LF plugin, if the generator is running in Epoch. */ + public static Function EPOCH_ERROR_REPORTER_CONSTRUCTOR = null; + + /** 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; + + private final FileConfig fileConfig; + + /** Whether the requested build is required to be complete. */ + private final Mode mode; + + private TargetConfig targetConfig; + + /** The result of the code generation process. */ + private GeneratorResult result = null; + + private final Properties args; + private final ErrorReporter errorReporter; + + /** + * Initialize the context of a build process whose cancellation is indicated by {@code + * cancelIndicator} + * + * @param mode The mode of this build process. + * @param cancelIndicator The cancel indicator of the code generation process to which this + * corresponds. + */ + public MainContext( + Mode mode, Resource resource, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) { + this( + mode, + cancelIndicator, + (message, completion) -> {}, + new Properties(), + resource, + fsa, + (mode == Mode.EPOCH && EPOCH_ERROR_REPORTER_CONSTRUCTOR != null) + ? EPOCH_ERROR_REPORTER_CONSTRUCTOR + : fileConfig -> new DefaultErrorReporter()); + } + + /** + * Initialize the context of a build process whose cancellation is indicated by {@code + * cancelIndicator} + * + * @param mode The mode of this build process. + * @param cancelIndicator The cancel indicator of the code generation process to which this + * corresponds. + * @param reportProgress The {@code ReportProgress} function of {@code this}. + * @param args Any arguments that may be used to affect the product of the build. + * @param resource ... + * @param fsa ... + * @param constructErrorReporter A function that constructs the appropriate error reporter for the + * given FileConfig. + */ + public MainContext( + Mode mode, + CancelIndicator cancelIndicator, + ReportProgress reportProgress, + Properties args, + Resource resource, + IFileSystemAccess2 fsa, + Function constructErrorReporter) { + this.mode = mode; + this.cancelIndicator = cancelIndicator == null ? () -> false : cancelIndicator; + this.reportProgress = reportProgress; + this.args = args; + + try { + var useHierarchicalBin = + args.containsKey("hierarchical-bin") + && Boolean.parseBoolean(args.getProperty("hierarchical-bin")); + fileConfig = + Objects.requireNonNull( + LFGenerator.createFileConfig( + resource, FileConfig.getSrcGenRoot(fsa), useHierarchicalBin)); + } catch (IOException e) { + throw new RuntimeIOException("Error during FileConfig instantiation", e); } - @Override - public void finish(GeneratorResult result) { - if (this.result != null) throw new IllegalStateException("A code generation process can only have one result."); - this.result = result; - reportProgress(result.getUserMessage(), 100); - } - - @Override - public GeneratorResult getResult() { - return result != null ? result : GeneratorResult.NOTHING; - } - - @Override - public FileConfig getFileConfig() { - return this.fileConfig; - } - - @Override - public TargetConfig getTargetConfig() { - return this.targetConfig; - } - - @Override - public void reportProgress(String message, int percentage) { - reportProgress.apply(message, percentage); - } - - /** - * Load the target configuration based on the contents of the resource. - * This is done automatically upon instantiation of the context, but - * in case the resource changes (e.g., due to an AST transformation), - * this method can be called to reload to ensure that the changes are - * reflected in the target configuration. - */ - public void loadTargetConfig() { - this.targetConfig = new TargetConfig( - args, GeneratorUtils.findTargetDecl(fileConfig.resource), errorReporter - ); - } + this.errorReporter = constructErrorReporter.apply(this.fileConfig); + + loadTargetConfig(); + } + + @Override + public CancelIndicator getCancelIndicator() { + return cancelIndicator; + } + + @Override + public Mode getMode() { + return mode; + } + + @Override + public Properties getArgs() { + return args; + } + + @Override + public ErrorReporter getErrorReporter() { + return errorReporter; + } + + @Override + public void finish(GeneratorResult result) { + if (this.result != null) + throw new IllegalStateException("A code generation process can only have one result."); + this.result = result; + reportProgress(result.getUserMessage(), 100); + } + + @Override + public GeneratorResult getResult() { + return result != null ? result : GeneratorResult.NOTHING; + } + + @Override + public FileConfig getFileConfig() { + return this.fileConfig; + } + + @Override + public TargetConfig getTargetConfig() { + return this.targetConfig; + } + + @Override + public void reportProgress(String message, int percentage) { + reportProgress.apply(message, percentage); + } + + /** + * Load the target configuration based on the contents of the resource. This is done automatically + * upon instantiation of the context, but in case the resource changes (e.g., due to an AST + * transformation), this method can be called to reload to ensure that the changes are reflected + * in the target configuration. + */ + public void loadTargetConfig() { + this.targetConfig = + new TargetConfig(args, GeneratorUtils.findTargetDecl(fileConfig.resource), errorReporter); + } } diff --git a/org.lflang/src/org/lflang/generator/MixedRadixInt.java b/org.lflang/src/org/lflang/generator/MixedRadixInt.java index 700012385c..c75ebd5864 100644 --- a/org.lflang/src/org/lflang/generator/MixedRadixInt.java +++ b/org.lflang/src/org/lflang/generator/MixedRadixInt.java @@ -34,241 +34,223 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Set; /** - * Representation of a permuted mixed radix (PMR) integer. - * A mixed radix number is a number representation where each digit can have - * a distinct radix. The radixes are given by a list of numbers, r0, r1, ... , rn, - * where r0 is the radix of the lowest-order digit and rn is the radix of the - * highest order digit that has a specified radix. + * Representation of a permuted mixed radix (PMR) integer. A mixed radix number is a number + * representation where each digit can have a distinct radix. The radixes are given by a list of + * numbers, r0, r1, ... , rn, where r0 is the radix of the lowest-order digit and rn is the radix of + * the highest order digit that has a specified radix. + * + *

    A PMR is a mixed radix number that, when incremented, increments the digits in the order given + * by the permutation matrix. For an ordinary mixed radix number, the permutation matrix is [0, 1, + * ..., n-1]. The permutation matrix may be any permutation of these digits, [d0, d1, ..., dn-1], in + * which case, when incremented, the d0 digit will be incremented first. If it overflows, it will be + * set to 0 and the d1 digit will be incremented. If it overflows, the next digit is incremented. If + * the last digit overflows, then the number wraps around so that all digits become zero. + * + *

    This implementation realizes a finite set of numbers, where incrementing past the end of the + * range wraps around to the beginning. As a consequence, the increment() function from any starting + * point is guaranteed to eventually cover all possible values. + * + *

    The {@link #toString()} method gives a string representation of the number where each digit is + * represented by the string "d%r", where d is the digit and r is the radix. For example, the number + * "1%2, 2%3, 1%4" has value 11, 1 + (2*2) + (1*2*3). * - * A PMR is a mixed radix number that, when incremented, - * increments the digits in the order given by the permutation matrix. - * For an ordinary mixed radix number, the permutation matrix is - * [0, 1, ..., n-1]. The permutation matrix may be any permutation of - * these digits, [d0, d1, ..., dn-1], in which case, when incremented, - * the d0 digit will be incremented first. If it overflows, it will be - * set to 0 and the d1 digit will be incremented. If it overflows, the - * next digit is incremented. If the last digit overflows, then the - * number wraps around so that all digits become zero. - * - * This implementation realizes a finite set of numbers, where incrementing - * past the end of the range wraps around to the beginning. As a consequence, - * the increment() function from any starting point is guaranteed to eventually - * cover all possible values. - * - * The {@link #toString()} method gives a string representation of the number - * where each digit is represented by the string "d%r", where d is the digit - * and r is the radix. For example, the number "1%2, 2%3, 1%4" has value 11, - * 1 + (2*2) + (1*2*3). - * * @author Edward A. Lee */ public class MixedRadixInt { - - /** - * Create a mixed radix number with the specified digits and radixes, - * which are given low-order digits first. - * If there is one more digit than radixes, throw an exception. - * @param digits The digits, or null to get a zero-valued number. - * @param radixes The radixes. - * @param permutation The permutation matrix, or null for the default permutation. - */ - public MixedRadixInt( - List digits, List radixes, List permutation - ) { - if (radixes == null - || (digits != null && digits.size() > radixes.size()) - || (permutation != null && permutation.size() != radixes.size()) - || radixes.contains(0)) { - throw new IllegalArgumentException("Invalid constructor arguments."); - } - this.radixes = radixes; - if (digits != null) { - this.digits = digits; - } else { - this.digits = new ArrayList(1); - this.digits.add(0); - } - if (permutation != null) { - // Check the permutation matrix. - Set indices = new HashSet(); - for (int p : permutation) { - if (p < 0 || p >= radixes.size() || indices.contains(p)) { - throw new IllegalArgumentException( - "Permutation list is required to be a permutation of [0, 1, ... , n-1]."); - } - indices.add(p); - } - this.permutation = permutation; - } - } - - /** - * A zero-valued mixed radix number with just one digit will radix 1. - */ - public final static MixedRadixInt ZERO = new MixedRadixInt(null, List.of(1), null); - - ////////////////////////////////////////////////////////// - //// Public methods - /** - * Get the value as an integer. - */ - public int get() { - return get(0); + /** + * Create a mixed radix number with the specified digits and radixes, which are given low-order + * digits first. If there is one more digit than radixes, throw an exception. + * + * @param digits The digits, or null to get a zero-valued number. + * @param radixes The radixes. + * @param permutation The permutation matrix, or null for the default permutation. + */ + public MixedRadixInt(List digits, List radixes, List permutation) { + if (radixes == null + || (digits != null && digits.size() > radixes.size()) + || (permutation != null && permutation.size() != radixes.size()) + || radixes.contains(0)) { + throw new IllegalArgumentException("Invalid constructor arguments."); } - - /** - * Get the value as an integer after dropping the first n digits. - * @param n The number of digits to drop. - */ - public int get(int n) { - int result = 0; - int scale = 1; - if (n < 0) n = 0; - for (int i = n; i < radixes.size(); i++) { - if (i >= digits.size()) return result; - result += digits.get(i) * scale; - scale *= radixes.get(i); - } - return result; + this.radixes = radixes; + if (digits != null) { + this.digits = digits; + } else { + this.digits = new ArrayList(1); + this.digits.add(0); } - - /** - * Return the digits. This is assured of returning as many - * digits as there are radixes. - */ - public List getDigits() { - while (digits.size() < radixes.size()) { - digits.add(0); + if (permutation != null) { + // Check the permutation matrix. + Set indices = new HashSet(); + for (int p : permutation) { + if (p < 0 || p >= radixes.size() || indices.contains(p)) { + throw new IllegalArgumentException( + "Permutation list is required to be a permutation of [0, 1, ... , n-1]."); } - return digits; + indices.add(p); + } + this.permutation = permutation; } - - /** - * Return the permutation list. - */ - public List getPermutation() { - if (permutation == null) { - // Construct a default permutation. - permutation = new ArrayList(radixes.size()); - for (int i = 0; i < radixes.size(); i++) { - permutation.add(i); - } - } - return permutation; + } + + /** A zero-valued mixed radix number with just one digit will radix 1. */ + public static final MixedRadixInt ZERO = new MixedRadixInt(null, List.of(1), null); + + ////////////////////////////////////////////////////////// + //// Public methods + + /** Get the value as an integer. */ + public int get() { + return get(0); + } + + /** + * Get the value as an integer after dropping the first n digits. + * + * @param n The number of digits to drop. + */ + public int get(int n) { + int result = 0; + int scale = 1; + if (n < 0) n = 0; + for (int i = n; i < radixes.size(); i++) { + if (i >= digits.size()) return result; + result += digits.get(i) * scale; + scale *= radixes.get(i); } - - /** - * Return the radixes. - */ - public List getRadixes() { - return radixes; + return result; + } + + /** Return the digits. This is assured of returning as many digits as there are radixes. */ + public List getDigits() { + while (digits.size() < radixes.size()) { + digits.add(0); } - - /** - * Increment the number by one, using the permutation vector to - * determine the order in which the digits are incremented. - * If an overflow occurs, then a radix-infinity digit will be added - * to the digits array if there isn't one there already. - */ - public void increment() { - int i = 0; - while (i < radixes.size()) { - int digit_to_increment = getPermutation().get(i); - while (digit_to_increment >= digits.size()) { - digits.add(0); - } - digits.set(digit_to_increment, digits.get(digit_to_increment) + 1); - if (digits.get(digit_to_increment) >= radixes.get(digit_to_increment)) { - digits.set(digit_to_increment, 0); - i++; - } else { - return; // All done. - } - } + return digits; + } + + /** Return the permutation list. */ + public List getPermutation() { + if (permutation == null) { + // Construct a default permutation. + permutation = new ArrayList(radixes.size()); + for (int i = 0; i < radixes.size(); i++) { + permutation.add(i); + } } - - /** - * Return the magnitude of this PMR, which is defined to be the number - * of times that increment() would need to invoked starting with zero - * before the value returned by {@link #get()} would be reached. - */ - public int magnitude() { - int factor = 1; - int result = 0; - List p = getPermutation(); - for (int i = 0; i < radixes.size(); i++) { - if (digits.size() <= i) return result; - result += factor * digits.get(p.get(i)); - factor *= radixes.get(p.get(i)); - } - return result; + return permutation; + } + + /** Return the radixes. */ + public List getRadixes() { + return radixes; + } + + /** + * Increment the number by one, using the permutation vector to determine the order in which the + * digits are incremented. If an overflow occurs, then a radix-infinity digit will be added to the + * digits array if there isn't one there already. + */ + public void increment() { + int i = 0; + while (i < radixes.size()) { + int digit_to_increment = getPermutation().get(i); + while (digit_to_increment >= digits.size()) { + digits.add(0); + } + digits.set(digit_to_increment, digits.get(digit_to_increment) + 1); + if (digits.get(digit_to_increment) >= radixes.get(digit_to_increment)) { + digits.set(digit_to_increment, 0); + i++; + } else { + return; // All done. + } } - - /** - * Return the number of digits in this mixed radix number. - * This is the size of the radixes list. - */ - public int numDigits() { - return radixes.size(); + } + + /** + * Return the magnitude of this PMR, which is defined to be the number of times that increment() + * would need to invoked starting with zero before the value returned by {@link #get()} would be + * reached. + */ + public int magnitude() { + int factor = 1; + int result = 0; + List p = getPermutation(); + for (int i = 0; i < radixes.size(); i++) { + if (digits.size() <= i) return result; + result += factor * digits.get(p.get(i)); + factor *= radixes.get(p.get(i)); } - - /** - * Set the value of this number to equal that of the specified integer. - * @param v The ordinary integer value of this number. - */ - public void set(int v) { - int temp = v; - int count = 0; - for (int radix : radixes) { - if (count >= digits.size()) { - digits.add(temp % radix); - } else { - digits.set(count, temp % radix); - } - count++; - temp = temp / radix; - } + return result; + } + + /** + * Return the number of digits in this mixed radix number. This is the size of the radixes list. + */ + public int numDigits() { + return radixes.size(); + } + + /** + * Set the value of this number to equal that of the specified integer. + * + * @param v The ordinary integer value of this number. + */ + public void set(int v) { + int temp = v; + int count = 0; + for (int radix : radixes) { + if (count >= digits.size()) { + digits.add(temp % radix); + } else { + digits.set(count, temp % radix); + } + count++; + temp = temp / radix; } - - /** - * Set the magnitude of this number to equal that of the specified integer, - * which is the number of times that increment must be invoked from zero - * for the value returned by {@link #get()} to equal v. - * @param v The new magnitude of this number. - */ - public void setMagnitude(int v) { - int temp = v; - for (int i = 0; i < radixes.size(); i++) { - int p = getPermutation().get(i); - while (digits.size() < p + 1) digits.add(0); - digits.set(p, temp % radixes.get(p)); - temp = temp / radixes.get(p); - } + } + + /** + * Set the magnitude of this number to equal that of the specified integer, which is the number of + * times that increment must be invoked from zero for the value returned by {@link #get()} to + * equal v. + * + * @param v The new magnitude of this number. + */ + public void setMagnitude(int v) { + int temp = v; + for (int i = 0; i < radixes.size(); i++) { + int p = getPermutation().get(i); + while (digits.size() < p + 1) digits.add(0); + digits.set(p, temp % radixes.get(p)); + temp = temp / radixes.get(p); } - - /** - * Give a string representation of the number, where each digit is - * represented as n%r, where r is the radix. - */ - @Override - public String toString() { - List pieces = new LinkedList(); - Iterator radixIterator = radixes.iterator(); - for (int digit : digits) { - if (! radixIterator.hasNext()) { - pieces.add(digit + "%infinity"); - } else { - pieces.add(digit + "%" + radixIterator.next()); - } - } - return String.join(", ", pieces); + } + + /** + * Give a string representation of the number, where each digit is represented as n%r, where r is + * the radix. + */ + @Override + public String toString() { + List pieces = new LinkedList(); + Iterator radixIterator = radixes.iterator(); + for (int digit : digits) { + if (!radixIterator.hasNext()) { + pieces.add(digit + "%infinity"); + } else { + pieces.add(digit + "%" + radixIterator.next()); + } } + return String.join(", ", pieces); + } - ////////////////////////////////////////////////////////// - //// Private variables + ////////////////////////////////////////////////////////// + //// Private variables - private List radixes; - private List digits; - private List permutation; + private List radixes; + private List digits; + private List permutation; } diff --git a/org.lflang/src/org/lflang/generator/ModeInstance.java b/org.lflang/src/org/lflang/generator/ModeInstance.java index 1f30f25802..932683f0ed 100644 --- a/org.lflang/src/org/lflang/generator/ModeInstance.java +++ b/org.lflang/src/org/lflang/generator/ModeInstance.java @@ -1,215 +1,206 @@ /************* -Copyright (c) 2021, Kiel University. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2021, Kiel University. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; import java.util.LinkedList; import java.util.List; - import org.lflang.lf.Mode; import org.lflang.lf.ModeTransition; import org.lflang.lf.VarRef; /** * Representation of a runtime instance of a mode. - * + * * @author Alexander Schulz-Rosengarten */ public class ModeInstance extends NamedInstance { - /** - * Create a new reaction instance from the specified definition - * within the specified parent. This constructor should be called - * only by the ReactorInstance class after all other contents - * (reactions, etc.) are registered because this constructor call - * will look them up. - * @param definition A mode definition. - * @param parent The parent reactor instance, which cannot be null. - */ - protected ModeInstance(Mode definition, ReactorInstance parent) { - super(definition, parent); - - collectMembers(); + /** + * Create a new reaction instance from the specified definition within the specified parent. This + * constructor should be called only by the ReactorInstance class after all other contents + * (reactions, etc.) are registered because this constructor call will look them up. + * + * @param definition A mode definition. + * @param parent The parent reactor instance, which cannot be null. + */ + protected ModeInstance(Mode definition, ReactorInstance parent) { + super(definition, parent); + + collectMembers(); + } + + //////////////////////////////////////////////////// + // Member fields. + + /** The action instances belonging to this mode instance. */ + public List actions = new LinkedList(); + + /** The reactor instances belonging to this mode instance, in order of declaration. */ + public List instantiations = new LinkedList(); + + /** List of reaction instances for this reactor instance. */ + public List reactions = new LinkedList(); + + /** The timer instances belonging to this reactor instance. */ + public List timers = new LinkedList(); + + /** The outgoing transitions of this mode. */ + public List transitions = new LinkedList(); + + //////////////////////////////////////////////////// + // Public methods. + + /** + * Return the name of this mode. + * + * @return The name of this mode. + */ + @Override + public String getName() { + return this.definition.getName(); + } + + /** {@inheritDoc} */ + @Override + public ReactorInstance root() { + return parent.root(); + } + + /** Return a descriptive string. */ + @Override + public String toString() { + return getName() + " of " + parent.getFullName(); + } + + /** Returns true iff this mode is the initial mode of this reactor instance. */ + public boolean isInitial() { + return definition.isInitial(); + } + + /** + * Sets up all transitions that leave this mode. Requires that all mode instances and other + * contents (reactions, etc.) of the parent reactor are created. + */ + public void setupTranstions() { + transitions.clear(); + for (var reaction : reactions) { + for (var effect : reaction.definition.getEffects()) { + if (effect instanceof VarRef) { + var target = effect.getVariable(); + if (target instanceof Mode) { + transitions.add( + new Transition(this, parent.lookupModeInstance((Mode) target), reaction, effect)); + } + } + } } - - //////////////////////////////////////////////////// - // Member fields. - - /** The action instances belonging to this mode instance. */ - public List actions = new LinkedList(); - - /** The reactor instances belonging to this mode instance, in order of declaration. */ - public List instantiations = new LinkedList(); - - /** List of reaction instances for this reactor instance. */ - public List reactions = new LinkedList(); - - /** The timer instances belonging to this reactor instance. */ - public List timers = new LinkedList(); - - /** The outgoing transitions of this mode. */ - public List transitions = new LinkedList(); - - //////////////////////////////////////////////////// - // Public methods. - - /** - * Return the name of this mode. - * @return The name of this mode. - */ - @Override - public String getName() { - return this.definition.getName(); + } + + /** Returns true iff this mode contains the given instance. */ + public boolean contains(NamedInstance instance) { + if (instance instanceof TimerInstance) { + return timers.contains(instance); + } else if (instance instanceof ActionInstance) { + return actions.contains(instance); + } else if (instance instanceof ReactorInstance) { + return instantiations.contains(instance); + } else if (instance instanceof ReactionInstance) { + return reactions.contains(instance); + } else { + return false; } - - /** - * {@inheritDoc} - */ - @Override - public ReactorInstance root() { - return parent.root(); + } + + //////////////////////////////////////////////////// + // Private methods. + + private void collectMembers() { + // Collect timers + for (var decl : definition.getTimers()) { + var instance = parent.lookupTimerInstance(decl); + if (instance != null) { + this.timers.add(instance); + } } - /** - * Return a descriptive string. - */ - @Override - public String toString() { - return getName() + " of " + parent.getFullName(); + // Collect actions + for (var decl : definition.getActions()) { + var instance = parent.lookupActionInstance(decl); + if (instance != null) { + this.actions.add(instance); + } } - - /** - * Returns true iff this mode is the initial mode of this reactor instance. - */ - public boolean isInitial() { - return definition.isInitial(); + + // Collect reactor instantiation + for (var decl : definition.getInstantiations()) { + var instance = parent.lookupReactorInstance(decl); + if (instance != null) { + this.instantiations.add(instance); + } } - - /** - * Sets up all transitions that leave this mode. - * Requires that all mode instances and other contents - * (reactions, etc.) of the parent reactor are created. - */ - public void setupTranstions() { - transitions.clear(); - for (var reaction : reactions) { - for (var effect : reaction.definition.getEffects()) { - if (effect instanceof VarRef) { - var target = effect.getVariable(); - if (target instanceof Mode) { - transitions.add(new Transition(this, parent.lookupModeInstance((Mode) target), reaction, effect)); - } - } - } - } + + // Collect reactions + for (var decl : definition.getReactions()) { + var instance = parent.lookupReactionInstance(decl); + if (instance != null) { + this.reactions.add(instance); + } } - - /** - * Returns true iff this mode contains the given instance. - */ - public boolean contains(NamedInstance instance) { - if (instance instanceof TimerInstance) { - return timers.contains(instance); - } else if (instance instanceof ActionInstance) { - return actions.contains(instance); - } else if (instance instanceof ReactorInstance) { - return instantiations.contains(instance); - } else if (instance instanceof ReactionInstance) { - return reactions.contains(instance); - } else { - return false; - } + } + + //////////////////////////////////////////////////// + // Data class. + + public static class Transition extends NamedInstance { + public final ModeInstance source; + public final ModeInstance target; + public final ReactionInstance reaction; + public final ModeTransition type; + + Transition( + ModeInstance source, ModeInstance target, ReactionInstance reaction, VarRef definition) { + super(definition, source.parent); + this.source = source; + this.target = target; + this.reaction = reaction; + this.type = + definition.getTransition() == null ? ModeTransition.RESET : definition.getTransition(); } - //////////////////////////////////////////////////// - // Private methods. - - private void collectMembers() { - // Collect timers - for (var decl : definition.getTimers()) { - var instance = parent.lookupTimerInstance(decl); - if (instance != null) { - this.timers.add(instance); - } - } - - // Collect actions - for (var decl : definition.getActions()) { - var instance = parent.lookupActionInstance(decl); - if (instance != null) { - this.actions.add(instance); - } - } - - // Collect reactor instantiation - for (var decl : definition.getInstantiations()) { - var instance = parent.lookupReactorInstance(decl); - if (instance != null) { - this.instantiations.add(instance); - } - } - - // Collect reactions - for (var decl : definition.getReactions()) { - var instance = parent.lookupReactionInstance(decl); - if (instance != null) { - this.reactions.add(instance); - } - } + @Override + public String getName() { + return this.source.getName() + " -> " + this.target + " by " + this.reaction.getName(); } - - //////////////////////////////////////////////////// - // Data class. - - public static class Transition extends NamedInstance { - public final ModeInstance source; - public final ModeInstance target; - public final ReactionInstance reaction; - public final ModeTransition type; - - Transition(ModeInstance source, ModeInstance target, ReactionInstance reaction, VarRef definition) { - super(definition, source.parent); - this.source = source; - this.target = target; - this.reaction = reaction; - this.type = definition.getTransition() == null ? ModeTransition.RESET : definition.getTransition(); - } - - @Override - public String getName() { - return this.source.getName() + " -> " + this.target + " by " + this.reaction.getName(); - } - - @Override - public ReactorInstance root() { - return this.parent.root(); - } - - public ModeTransition getType() { - return type; - } - + + @Override + public ReactorInstance root() { + return this.parent.root(); + } + + public ModeTransition getType() { + return type; } - + } } diff --git a/org.lflang/src/org/lflang/generator/NamedInstance.java b/org.lflang/src/org/lflang/generator/NamedInstance.java index 1d8c37321f..3455bcdf40 100644 --- a/org.lflang/src/org/lflang/generator/NamedInstance.java +++ b/org.lflang/src/org/lflang/generator/NamedInstance.java @@ -1,337 +1,319 @@ /* Base class for instances with names in Lingua Franca. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; import java.util.ArrayList; import java.util.HashMap; import java.util.List; - import org.eclipse.emf.ecore.EObject; -/** - * Base class for compile-time instances with names in Lingua Franca. - * An instance of concrete subclasses of this class represents one or - * more runtime instances of a reactor, port, reaction, etc. There - * will be more than one runtime instance if the object or any of its - * parents is a bank of reactors. - * +/** + * Base class for compile-time instances with names in Lingua Franca. An instance of concrete + * subclasses of this class represents one or more runtime instances of a reactor, port, reaction, + * etc. There will be more than one runtime instance if the object or any of its parents is a bank + * of reactors. + * * @author Marten Lohstroh * @author Edward A. Lee */ public abstract class NamedInstance { - - /** - * Construct a new instance with the specified definition - * and parent. E.g., for a reactor instance, the definition - * is Instantiation, and for a port instance, it is Port. These are - * nodes in the AST. This is protected because only subclasses - * should be constructed. - * @param definition The definition in the AST for this instance. - * @param parent The reactor instance that creates this instance. - */ - protected NamedInstance(T definition, ReactorInstance parent) { - this.definition = definition; - this.parent = parent; - - // Calculate the depth. - this.depth = 0; - ReactorInstance p = parent; - while (p != null) { - p = p.parent; - this.depth++; - } - } - - ////////////////////////////////////////////////////// - //// Public fields. - - /** A limit on the number of characters returned by uniqueID. */ - public static int identifierLengthLimit = 40; - - ////////////////////////////////////////////////////// - //// Public methods. - - /** - * Return the definition, which is the AST node for this object. - */ - public T getDefinition() { - return definition; - } - - /** - * Get the depth of the reactor instance. This is 0 for the main reactor, - * 1 for reactors immediately contained therein, etc. - */ - public int getDepth() { - return depth; - } - - /** - * Return the full name of this instance, which has the form - * "a.b.c", where "c" is the name of this instance, "b" is the name - * of its container, and "a" is the name of its container, stopping - * at the container in main. If any reactor in the hierarchy is - * in a bank of reactors then, it will appear as a[index]. - * Similarly, if c is a port in a multiport, it will appear as - * c[index]. - * @return The full name of this instance. - */ - public String getFullName() { - return getFullNameWithJoiner("."); - } - - /** - * Return the name of this instance as given in its definition. - * Note that this is unique only relative to other instances with - * the same parent. - * @return The name of this instance within its parent. - */ - public abstract String getName(); - - /** - * Return the parent or null if this is a top-level reactor. - */ - public ReactorInstance getParent() { - return parent; - } - - /** - * Return the parent at the given depth or null if there is - * no parent at the given depth. - * @param d The depth. - */ - public ReactorInstance getParent(int d) { - if (d >= depth || d < 0) return null; - ReactorInstance p = parent; - while (p != null) { - if (p.depth == d) return p; - p = p.parent; - } - return null; + + /** + * Construct a new instance with the specified definition and parent. E.g., for a reactor + * instance, the definition is Instantiation, and for a port instance, it is Port. These are nodes + * in the AST. This is protected because only subclasses should be constructed. + * + * @param definition The definition in the AST for this instance. + * @param parent The reactor instance that creates this instance. + */ + protected NamedInstance(T definition, ReactorInstance parent) { + this.definition = definition; + this.parent = parent; + + // Calculate the depth. + this.depth = 0; + ReactorInstance p = parent; + while (p != null) { + p = p.parent; + this.depth++; } + } + + ////////////////////////////////////////////////////// + //// Public fields. + + /** A limit on the number of characters returned by uniqueID. */ + public static int identifierLengthLimit = 40; + + ////////////////////////////////////////////////////// + //// Public methods. + + /** Return the definition, which is the AST node for this object. */ + public T getDefinition() { + return definition; + } - /** - * Return the width of this instance, which in this base class is 1. - * Subclasses PortInstance and ReactorInstance change this to the - * multiport and bank widths respectively. - */ - public int getWidth() { - return width; + /** + * Get the depth of the reactor instance. This is 0 for the main reactor, 1 for reactors + * immediately contained therein, etc. + */ + public int getDepth() { + return depth; + } + + /** + * Return the full name of this instance, which has the form "a.b.c", where "c" is the name of + * this instance, "b" is the name of its container, and "a" is the name of its container, stopping + * at the container in main. If any reactor in the hierarchy is in a bank of reactors then, it + * will appear as a[index]. Similarly, if c is a port in a multiport, it will appear as c[index]. + * + * @return The full name of this instance. + */ + public String getFullName() { + return getFullNameWithJoiner("."); + } + + /** + * Return the name of this instance as given in its definition. Note that this is unique only + * relative to other instances with the same parent. + * + * @return The name of this instance within its parent. + */ + public abstract String getName(); + + /** Return the parent or null if this is a top-level reactor. */ + public ReactorInstance getParent() { + return parent; + } + + /** + * Return the parent at the given depth or null if there is no parent at the given depth. + * + * @param d The depth. + */ + public ReactorInstance getParent(int d) { + if (d >= depth || d < 0) return null; + ReactorInstance p = parent; + while (p != null) { + if (p.depth == d) return p; + p = p.parent; } - - /** - * Return true if this instance has the specified parent - * (possibly indirectly, anywhere up the hierarchy). - */ - public boolean hasParent(ReactorInstance container) { - - ReactorInstance p = parent; - - while (p != null) { - if (p == container) return true; - p = p.parent; - } - return false; + return null; + } + + /** + * Return the width of this instance, which in this base class is 1. Subclasses PortInstance and + * ReactorInstance change this to the multiport and bank widths respectively. + */ + public int getWidth() { + return width; + } + + /** + * Return true if this instance has the specified parent (possibly indirectly, anywhere up the + * hierarchy). + */ + public boolean hasParent(ReactorInstance container) { + + ReactorInstance p = parent; + + while (p != null) { + if (p == container) return true; + p = p.parent; } - - /** - * Return a list of all the parents starting with the root(). - */ - public List parents() { - List result = new ArrayList(depth + 1); - if (this instanceof ReactorInstance && parent == null) { - // This is the top level, so it must be a reactor. - result.add((ReactorInstance) this); - } - ReactorInstance container = parent; - while (container != null) { - result.add(container); - container = container.parent; - } - return result; + return false; + } + + /** Return a list of all the parents starting with the root(). */ + public List parents() { + List result = new ArrayList(depth + 1); + if (this instanceof ReactorInstance && parent == null) { + // This is the top level, so it must be a reactor. + result.add((ReactorInstance) this); } - - /** - * Return the root reactor, which is the top-level parent. - * @return The top-level parent. - */ - public ReactorInstance root() { - if (parent != null) { - return parent.root(); - } else { - return (ReactorInstance)this; - } + ReactorInstance container = parent; + while (container != null) { + result.add(container); + container = container.parent; } - - /** - * Set the width. This method is here for testing only and should - * not be used for any other purpose. - * @param width The new width. - */ - public void setWidth(int width) { - this.width = width; + return result; + } + + /** + * Return the root reactor, which is the top-level parent. + * + * @return The top-level parent. + */ + public ReactorInstance root() { + if (parent != null) { + return parent.root(); + } else { + return (ReactorInstance) this; } + } - /** - * Return an identifier for this instance, which has the form "a_b_c" - * or "a_b_c_n", where "c" is the name of this instance, "b" is the name - * of its container, and "a" is the name of its container, stopping - * at the container in main. All names are converted to lower case. - * The suffix _n is usually omitted, but it is possible to get name - * collisions using the above scheme, in which case _n will be an - * increasing integer until there is no collision. - * If the length of the root of the name as calculated above (the root - * is without the _n suffix) is longer than - * the static variable identifierLengthLimit, then the name will be - * truncated. The returned name will be the tail of the name calculated - * above with the prefix '_'. - * @return An identifier for this instance that is guaranteed to be - * unique within the top-level parent. - */ - public String uniqueID() { - if (_uniqueID == null) { - // Construct the unique ID only if it has not been - // previously constructed. - String prefix = getFullNameWithJoiner("_").toLowerCase(); - - // Replace all non-alphanumeric (Latin) characters with underscore. - prefix = prefix.replaceAll("[^A-Za-z0-9]", "_"); - - // Truncate, if necessary. - if (prefix.length() > identifierLengthLimit) { - prefix = '_' - + prefix.substring(prefix.length() - identifierLengthLimit + 1); - } - - // Ensure uniqueness. - ReactorInstance toplevel = root(); - if (toplevel.uniqueIDCount == null) { - toplevel.uniqueIDCount = new HashMap(); - } - var count = toplevel.uniqueIDCount.get(prefix); - if (count == null) { - toplevel.uniqueIDCount.put(prefix, 1); - _uniqueID = prefix; - } else { - toplevel.uniqueIDCount.put(prefix, count + 1); - // NOTE: The length of this name could exceed - // identifierLengthLimit. Is this OK? - _uniqueID = prefix + '_' + (count + 1); - } - } - return _uniqueID; + /** + * Set the width. This method is here for testing only and should not be used for any other + * purpose. + * + * @param width The new width. + */ + public void setWidth(int width) { + this.width = width; + } + + /** + * Return an identifier for this instance, which has the form "a_b_c" or "a_b_c_n", where "c" is + * the name of this instance, "b" is the name of its container, and "a" is the name of its + * container, stopping at the container in main. All names are converted to lower case. The suffix + * _n is usually omitted, but it is possible to get name collisions using the above scheme, in + * which case _n will be an increasing integer until there is no collision. If the length of the + * root of the name as calculated above (the root is without the _n suffix) is longer than the + * static variable identifierLengthLimit, then the name will be truncated. The returned name will + * be the tail of the name calculated above with the prefix '_'. + * + * @return An identifier for this instance that is guaranteed to be unique within the top-level + * parent. + */ + public String uniqueID() { + if (_uniqueID == null) { + // Construct the unique ID only if it has not been + // previously constructed. + String prefix = getFullNameWithJoiner("_").toLowerCase(); + + // Replace all non-alphanumeric (Latin) characters with underscore. + prefix = prefix.replaceAll("[^A-Za-z0-9]", "_"); + + // Truncate, if necessary. + if (prefix.length() > identifierLengthLimit) { + prefix = '_' + prefix.substring(prefix.length() - identifierLengthLimit + 1); + } + + // Ensure uniqueness. + ReactorInstance toplevel = root(); + if (toplevel.uniqueIDCount == null) { + toplevel.uniqueIDCount = new HashMap(); + } + var count = toplevel.uniqueIDCount.get(prefix); + if (count == null) { + toplevel.uniqueIDCount.put(prefix, 1); + _uniqueID = prefix; + } else { + toplevel.uniqueIDCount.put(prefix, count + 1); + // NOTE: The length of this name could exceed + // identifierLengthLimit. Is this OK? + _uniqueID = prefix + '_' + (count + 1); + } } - - /** - * Returns the directly/indirectly enclosing mode. - * @param direct flag whether to check only for direct enclosing mode - * or also consider modes of parent reactor instances. - * @return The mode, if any, null otherwise. - */ - public ModeInstance getMode(boolean direct) { - ModeInstance mode = null; - if (parent != null) { - if (!parent.modes.isEmpty()) { - mode = parent.modes.stream().filter(it -> it.contains(this)).findFirst().orElse(null); - } - if (mode == null && !direct) { - mode = parent.getMode(false); - } - } - return mode; + return _uniqueID; + } + + /** + * Returns the directly/indirectly enclosing mode. + * + * @param direct flag whether to check only for direct enclosing mode or also consider modes of + * parent reactor instances. + * @return The mode, if any, null otherwise. + */ + public ModeInstance getMode(boolean direct) { + ModeInstance mode = null; + if (parent != null) { + if (!parent.modes.isEmpty()) { + mode = parent.modes.stream().filter(it -> it.contains(this)).findFirst().orElse(null); + } + if (mode == null && !direct) { + mode = parent.getMode(false); + } } + return mode; + } - ////////////////////////////////////////////////////// - //// Protected fields. - - /** The Instantiation AST object from which this was created. */ - T definition; - - /** The reactor instance that creates this instance. */ - ReactorInstance parent; - - /** - * Map from a name of the form a_b_c to the number of - * unique IDs with that prefix that have been already - * assigned. If none have been assigned, then there is - * no entry in this map. This map should be non-null only - * for the main reactor (the top level). - */ - HashMap uniqueIDCount; - - /** - * The width of this instance. This is 1 for everything - * except a PortInstance representing a multiport and a - * ReactorInstance representing a bank. - */ - int width = 1; - - ////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Return a string of the form - * "a.b.c", where "." is replaced by the specified joiner, - * "c" is the name of this instance, "b" is the name - * of its container, and "a" is the name of its container, stopping - * at the container in main. - * @return A string representing this instance. - */ - protected String getFullNameWithJoiner(String joiner) { - // This is not cached because _uniqueID is cached. - if (parent == null) { - return this.getName(); - } else if (getMode(true) != null) { - return parent.getFullNameWithJoiner(joiner) + joiner + getMode(true).getName() + joiner + this.getName(); - } else { - return parent.getFullNameWithJoiner(joiner) + joiner + this.getName(); - } + ////////////////////////////////////////////////////// + //// Protected fields. + + /** The Instantiation AST object from which this was created. */ + T definition; + + /** The reactor instance that creates this instance. */ + ReactorInstance parent; + + /** + * Map from a name of the form a_b_c to the number of unique IDs with that prefix that have been + * already assigned. If none have been assigned, then there is no entry in this map. This map + * should be non-null only for the main reactor (the top level). + */ + HashMap uniqueIDCount; + + /** + * The width of this instance. This is 1 for everything except a PortInstance representing a + * multiport and a ReactorInstance representing a bank. + */ + int width = 1; + + ////////////////////////////////////////////////////// + //// Protected methods. + + /** + * Return a string of the form "a.b.c", where "." is replaced by the specified joiner, "c" is the + * name of this instance, "b" is the name of its container, and "a" is the name of its container, + * stopping at the container in main. + * + * @return A string representing this instance. + */ + protected String getFullNameWithJoiner(String joiner) { + // This is not cached because _uniqueID is cached. + if (parent == null) { + return this.getName(); + } else if (getMode(true) != null) { + return parent.getFullNameWithJoiner(joiner) + + joiner + + getMode(true).getName() + + joiner + + this.getName(); + } else { + return parent.getFullNameWithJoiner(joiner) + joiner + this.getName(); } + } + + ////////////////////////////////////////////////////// + //// Protected fields. + + /** + * The depth in the hierarchy of this instance. This is 0 for main or federated, 1 for the + * reactors immediately contained, etc. + */ + protected int depth = 0; + + ////////////////////////////////////////////////////// + //// Private fields. + + /** The full name of this instance. */ + private String _fullName = null; - ////////////////////////////////////////////////////// - //// Protected fields. - - /** - * The depth in the hierarchy of this instance. - * This is 0 for main or federated, 1 for the reactors immediately contained, etc. - */ - protected int depth = 0; - - ////////////////////////////////////////////////////// - //// Private fields. - - /** - * The full name of this instance. - */ - private String _fullName = null; - - /** - * Unique ID for this instance. This is null until - * uniqueID() is called. - */ - private String _uniqueID = null; -} \ No newline at end of file + /** Unique ID for this instance. This is null until uniqueID() is called. */ + private String _uniqueID = null; +} diff --git a/org.lflang/src/org/lflang/generator/ParameterInstance.java b/org.lflang/src/org/lflang/generator/ParameterInstance.java index 851fcb627e..92a1b03ed4 100644 --- a/org.lflang/src/org/lflang/generator/ParameterInstance.java +++ b/org.lflang/src/org/lflang/generator/ParameterInstance.java @@ -1,121 +1,118 @@ /** A data structure for a parameter instance. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; import java.util.List; import java.util.Optional; - -import org.lflang.ast.ASTUtils; import org.lflang.InferredType; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Assignment; import org.lflang.lf.Initializer; import org.lflang.lf.Parameter; /** - * Representation of a compile-time instance of a parameter. - * Upon creation, it is checked whether this parameter is overridden by an - * assignment in the instantiation that this parameter instance is a result of. - * If it is overridden, the parameter gets initialized using the value looked up - * in the instantiation hierarchy. + * Representation of a compile-time instance of a parameter. Upon creation, it is checked whether + * this parameter is overridden by an assignment in the instantiation that this parameter instance + * is a result of. If it is overridden, the parameter gets initialized using the value looked up in + * the instantiation hierarchy. + * * @author Marten Lohstroh * @author Edward A. Lee */ public class ParameterInstance extends NamedInstance { - /** - * Create a runtime instance from the specified definition - * and with the specified parent that instantiated it. - * @param definition The declaration in the AST. - * @param parent The reactor instance this parameter is a part of. - */ - public ParameterInstance(Parameter definition, ReactorInstance parent) { - super(definition, parent); - if (parent == null) { - throw new InvalidSourceException("Cannot create a ParameterInstance with no parent."); - } - - this.type = ASTUtils.getInferredType(definition); - } - - ///////////////////////////////////////////// - //// Public Fields - - public InferredType type; - - ///////////////////////////////////////////// - //// Public Methods - - /** - * Get the initial value of this parameter. - */ - private Initializer getInitialValue() { - return definition.getInit(); - } - - /** - * Return the (possibly overridden) value of this parameter - * in the containing instance. Parameter references are resolved - * to actual expressions. - */ - public Initializer getActualValue() { - Assignment override = getOverride(); - Initializer init; - if (override != null) { - init = override.getRhs(); - } else { - init = getInitialValue(); - } - return init; - } - - /** - * Return the name of this parameter. - * @return The name of this parameter. - */ - public String getName() { - return this.definition.getName(); - } - - /** - * Return the assignment that overrides this parameter in - * the parent's instantiation or null if there is no override. - */ - public Assignment getOverride() { - List assignments = parent.definition.getParameters(); - Optional assignment = assignments.stream().filter( - it -> it.getLhs() == definition - ).findFirst(); - return assignment.orElse(null); + /** + * Create a runtime instance from the specified definition and with the specified parent that + * instantiated it. + * + * @param definition The declaration in the AST. + * @param parent The reactor instance this parameter is a part of. + */ + public ParameterInstance(Parameter definition, ReactorInstance parent) { + super(definition, parent); + if (parent == null) { + throw new InvalidSourceException("Cannot create a ParameterInstance with no parent."); } - /** Return a descriptive string. */ - @Override - public String toString() { - return "ParameterInstance " + getFullName(); + this.type = ASTUtils.getInferredType(definition); + } + + ///////////////////////////////////////////// + //// Public Fields + + public InferredType type; + + ///////////////////////////////////////////// + //// Public Methods + + /** Get the initial value of this parameter. */ + private Initializer getInitialValue() { + return definition.getInit(); + } + + /** + * Return the (possibly overridden) value of this parameter in the containing instance. Parameter + * references are resolved to actual expressions. + */ + public Initializer getActualValue() { + Assignment override = getOverride(); + Initializer init; + if (override != null) { + init = override.getRhs(); + } else { + init = getInitialValue(); } + return init; + } + + /** + * Return the name of this parameter. + * + * @return The name of this parameter. + */ + public String getName() { + return this.definition.getName(); + } + + /** + * Return the assignment that overrides this parameter in the parent's instantiation or null if + * there is no override. + */ + public Assignment getOverride() { + List assignments = parent.definition.getParameters(); + Optional assignment = + assignments.stream().filter(it -> it.getLhs() == definition).findFirst(); + return assignment.orElse(null); + } + + /** Return a descriptive string. */ + @Override + public String toString() { + return "ParameterInstance " + getFullName(); + } } diff --git a/org.lflang/src/org/lflang/generator/PortInstance.java b/org.lflang/src/org/lflang/generator/PortInstance.java index 57dbdcf73d..60a904ef5b 100644 --- a/org.lflang/src/org/lflang/generator/PortInstance.java +++ b/org.lflang/src/org/lflang/generator/PortInstance.java @@ -1,35 +1,34 @@ /** A data structure for a port instance. */ /************* -Copyright (c) 2019-2022, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2022, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.PriorityQueue; - import org.lflang.ErrorReporter; import org.lflang.lf.Input; import org.lflang.lf.Output; @@ -38,422 +37,404 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; -/** - * Representation of a compile-time instance of a port. - * Like {@link ReactorInstance}, if one or more parents of this port - * is a bank of reactors, then there will be more than one runtime instance +/** + * Representation of a compile-time instance of a port. Like {@link ReactorInstance}, if one or more + * parents of this port is a bank of reactors, then there will be more than one runtime instance * corresponding to this compile-time instance. - * - * This may be a single port or a multiport. If it is a multiport, then - * one instance of this PortInstance class represents all channels. - * If in addition any parent is a bank, then it represents all channels of all - * bank members. The {@link #eventualDestinations()} and {@link #eventualSources()} - * functions report the connectivity of all such channels as lists of - * {@link SendRange} and {@link RuntimeRange} objects. - * + * + *

    This may be a single port or a multiport. If it is a multiport, then one instance of this + * PortInstance class represents all channels. If in addition any parent is a bank, then it + * represents all channels of all bank members. The {@link #eventualDestinations()} and {@link + * #eventualSources()} functions report the connectivity of all such channels as lists of {@link + * SendRange} and {@link RuntimeRange} objects. + * * @author Marten Lohstroh * @author Edward A. Lee */ public class PortInstance extends TriggerInstance { - /** - * Create a runtime instance from the specified definition - * and with the specified parent that instantiated it. - * @param definition The declaration in the AST. - * @param parent The parent. - */ - public PortInstance(Port definition, ReactorInstance parent) { - this(definition, parent, null); - } + /** + * Create a runtime instance from the specified definition and with the specified parent that + * instantiated it. + * + * @param definition The declaration in the AST. + * @param parent The parent. + */ + public PortInstance(Port definition, ReactorInstance parent) { + this(definition, parent, null); + } - /** - * Create a port instance from the specified definition - * and with the specified parent that instantiated it. - * @param definition The declaration in the AST. - * @param parent The parent. - * @param errorReporter An error reporter, or null to throw exceptions. - */ - public PortInstance(Port definition, ReactorInstance parent, ErrorReporter errorReporter) { - super(definition, parent); - - if (parent == null) { - throw new NullPointerException("Cannot create a PortInstance with no parent."); - } - - setInitialWidth(errorReporter); - } + /** + * Create a port instance from the specified definition and with the specified parent that + * instantiated it. + * + * @param definition The declaration in the AST. + * @param parent The parent. + * @param errorReporter An error reporter, or null to throw exceptions. + */ + public PortInstance(Port definition, ReactorInstance parent, ErrorReporter errorReporter) { + super(definition, parent); - ////////////////////////////////////////////////////// - //// Public methods - - /** - * Clear cached information about the connectivity of this port. - * In particular, {@link #eventualDestinations()} and {@link #eventualSources()} - * cache the lists they return. To force those methods to recompute - * their lists, call this method. This method also clears the caches - * of any ports that are listed as eventual destinations and sources. - */ - public void clearCaches() { - if (clearingCaches) return; // Prevent stack overflow. - clearingCaches = true; - try { - if (eventualSourceRanges != null) { - for (RuntimeRange sourceRange : eventualSourceRanges) { - sourceRange.instance.clearCaches(); - } - } - if (eventualDestinationRanges != null) { - for (SendRange sendRange : eventualDestinationRanges) { - for (RuntimeRange destinationRange : sendRange.destinations) { - destinationRange.instance.clearCaches(); - } - } - } - eventualDestinationRanges = null; - eventualSourceRanges = null; - } finally { - clearingCaches = false; - } + if (parent == null) { + throw new NullPointerException("Cannot create a PortInstance with no parent."); } - /** - * Return a list of ranges of this port, where each range sends - * to a list of destination ports that receive data from the range of - * this port. Each destination port is annotated with the channel - * range on which it receives data. - * The ports listed are only ports that are sources for reactions, - * not relay ports that the data may go through on the way. - * Also, if there is an "after" delay anywhere along the path, - * then the destination is not in the resulting list. - * - * If this port itself has dependent reactions, - * then this port will be included as a destination in all items - * on the returned list. - * - * Each item in the returned list has the following fields: - *

      - *
    • {@code startRange}: The starting channel index of this port.
    • - *
    • {@code rangeWidth}: The number of channels sent to the destinations.
    • - *
    • {@code destinations}: A list of port ranges for destination ports, each - * of which has the same width as {@code rangeWidth}.
    • - *
    - * - * Each item also has a method, {@link SendRange#getNumberOfDestinationReactors()}, - * that returns the total number of unique destination reactors for - * its range. This is not necessarily the same as the number - * of ports in its destinations field because some of the ports may - * share the same container reactor. - */ - public List eventualDestinations() { - if (eventualDestinationRanges != null) { - return eventualDestinationRanges; + setInitialWidth(errorReporter); + } + + ////////////////////////////////////////////////////// + //// Public methods + + /** + * Clear cached information about the connectivity of this port. In particular, {@link + * #eventualDestinations()} and {@link #eventualSources()} cache the lists they return. To force + * those methods to recompute their lists, call this method. This method also clears the caches of + * any ports that are listed as eventual destinations and sources. + */ + public void clearCaches() { + if (clearingCaches) return; // Prevent stack overflow. + clearingCaches = true; + try { + if (eventualSourceRanges != null) { + for (RuntimeRange sourceRange : eventualSourceRanges) { + sourceRange.instance.clearCaches(); } - - // Construct the full range for this port. - RuntimeRange range = new RuntimeRange.Port(this); - eventualDestinationRanges = eventualDestinations(range); - return eventualDestinationRanges; - } - - /** - * Return a list of ranges of ports that send data to this port. - * If this port is directly written to by one more more reactions, - * then it is its own eventual source and only this port - * will be represented in the result. - * - * If this is not a multiport and is not within a bank, then the list will have - * only one item and the range will have a total width of one. Otherwise, it will - * have enough items so that the range widths add up to the width of this - * multiport multiplied by the total number of instances within containing banks. - * - * The ports listed are only ports that are written to by reactions, - * not relay ports that the data may go through on the way. - */ - public List> eventualSources() { - return eventualSources(new RuntimeRange.Port(this)); + } + if (eventualDestinationRanges != null) { + for (SendRange sendRange : eventualDestinationRanges) { + for (RuntimeRange destinationRange : sendRange.destinations) { + destinationRange.instance.clearCaches(); + } + } + } + eventualDestinationRanges = null; + eventualSourceRanges = null; + } finally { + clearingCaches = false; } + } - /** - * Return the list of ranges of this port together with the - * downstream ports that are connected to this port. - * The total with of the ranges in the returned list is a - * multiple N >= 0 of the total width of this port. - */ - public List getDependentPorts() { - return dependentPorts; + /** + * Return a list of ranges of this port, where each range sends to a list of destination ports + * that receive data from the range of this port. Each destination port is annotated with the + * channel range on which it receives data. The ports listed are only ports that are sources for + * reactions, not relay ports that the data may go through on the way. Also, if there is an + * "after" delay anywhere along the path, then the destination is not in the resulting list. + * + *

    If this port itself has dependent reactions, then this port will be included as a + * destination in all items on the returned list. + * + *

    Each item in the returned list has the following fields: + * + *

      + *
    • {@code startRange}: The starting channel index of this port. + *
    • {@code rangeWidth}: The number of channels sent to the destinations. + *
    • {@code destinations}: A list of port ranges for destination ports, each of which has the + * same width as {@code rangeWidth}. + *
    + * + * Each item also has a method, {@link SendRange#getNumberOfDestinationReactors()}, that returns + * the total number of unique destination reactors for its range. This is not necessarily the same + * as the number of ports in its destinations field because some of the ports may share the same + * container reactor. + */ + public List eventualDestinations() { + if (eventualDestinationRanges != null) { + return eventualDestinationRanges; } - /** - * Return the list of upstream ports that are connected to this port, - * or an empty set if there are none. - * For an ordinary port, this list will have length 0 or 1. - * For a multiport, it can have a larger size. - */ - public List> getDependsOnPorts() { - return dependsOnPorts; - } - - /** - * Return true if the port is an input. - */ - public boolean isInput() { - return (definition instanceof Input); - } - - /** - * Return true if this is a multiport. - */ - public boolean isMultiport() { - return isMultiport; - } + // Construct the full range for this port. + RuntimeRange range = new RuntimeRange.Port(this); + eventualDestinationRanges = eventualDestinations(range); + return eventualDestinationRanges; + } + + /** + * Return a list of ranges of ports that send data to this port. If this port is directly written + * to by one more more reactions, then it is its own eventual source and only this port will be + * represented in the result. + * + *

    If this is not a multiport and is not within a bank, then the list will have only one item + * and the range will have a total width of one. Otherwise, it will have enough items so that the + * range widths add up to the width of this multiport multiplied by the total number of instances + * within containing banks. + * + *

    The ports listed are only ports that are written to by reactions, not relay ports that the + * data may go through on the way. + */ + public List> eventualSources() { + return eventualSources(new RuntimeRange.Port(this)); + } + + /** + * Return the list of ranges of this port together with the downstream ports that are connected to + * this port. The total with of the ranges in the returned list is a multiple N >= 0 of the total + * width of this port. + */ + public List getDependentPorts() { + return dependentPorts; + } + + /** + * Return the list of upstream ports that are connected to this port, or an empty set if there are + * none. For an ordinary port, this list will have length 0 or 1. For a multiport, it can have a + * larger size. + */ + public List> getDependsOnPorts() { + return dependsOnPorts; + } + + /** Return true if the port is an input. */ + public boolean isInput() { + return (definition instanceof Input); + } + + /** Return true if this is a multiport. */ + public boolean isMultiport() { + return isMultiport; + } + + /** Return true if the port is an output. */ + public boolean isOutput() { + return (definition instanceof Output); + } + + @Override + public String toString() { + return "PortInstance " + getFullName(); + } + + ////////////////////////////////////////////////////// + //// Protected fields. + + /** + * Ranges of this port together with downstream ports that are connected directly to this port. + * When there are multiple destinations, the destinations are listed in the order they appear in + * connections in the parent reactor instance of this port (inside connections), followed by the + * order in which they appear in the parent's parent (outside connections). The total of the + * widths of these SendRanges is an integer multiple N >= 0 of the width of this port (this is + * checked by the validator). Each channel of this port will be broadcast to N recipients (or, if + * there are no connections to zero recipients). + */ + List dependentPorts = new ArrayList(); + + /** + * Upstream ports that are connected directly to this port, if there are any. For an ordinary + * port, this set will have size 0 or 1. For a multiport, it can have a larger size. This + * initially has capacity 1 because that is by far the most common case. + */ + List> dependsOnPorts = new ArrayList>(1); + + /** Indicator of whether this is a multiport. */ + boolean isMultiport = false; - /** - * Return true if the port is an output. - */ - public boolean isOutput() { - return (definition instanceof Output); + ////////////////////////////////////////////////////// + //// Private methods. + + /** + * Given a RuntimeRange, return a list of SendRange that describes the eventual destinations of + * the given range. The sum of the total widths of the send ranges on the returned list will be an + * integer multiple N of the total width of the specified range. Each returned SendRange has a + * list of destination RuntimeRanges, each of which represents a port that has dependent + * reactions. Intermediate ports with no dependent reactions are not listed. + * + * @param srcRange The source range. + */ + private static List eventualDestinations(RuntimeRange srcRange) { + + // Getting the destinations is more complex than getting the sources + // because of multicast, where there is more than one connection statement + // for a source of data. The strategy we follow here is to first get all + // the ports that this port eventually sends to. Then, if needed, split + // the resulting ranges so that the resulting list covers exactly + // srcRange, possibly in pieces. We make two passes. First, we build + // a queue of ranges that may overlap, then we split those ranges + // and consolidate their destinations. + + List result = new ArrayList(); + PriorityQueue queue = new PriorityQueue(); + PortInstance srcPort = srcRange.instance; + + // Start with, if this port has dependent reactions, then add it to + // every range of the result. + if (!srcRange.instance.dependentReactions.isEmpty()) { + // This will be the final result if there are no connections. + SendRange candidate = + new SendRange( + srcRange.instance, + srcRange.start, + srcRange.width, + null, // No interleaving for this range. + null // No connection for this range. + ); + candidate.destinations.add(srcRange); + queue.add(candidate); } - - @Override - public String toString() { - return "PortInstance " + getFullName(); - } - - ////////////////////////////////////////////////////// - //// Protected fields. - - /** - * Ranges of this port together with downstream ports that - * are connected directly to this port. When there are multiple destinations, - * the destinations are listed in the order they appear in connections - * in the parent reactor instance of this port (inside connections), - * followed by the order in which they appear in the parent's parent (outside - * connections). The total of the widths of these SendRanges is an integer - * multiple N >= 0 of the width of this port (this is checked - * by the validator). Each channel of this port will be broadcast - * to N recipients (or, if there are no connections to zero recipients). - */ - List dependentPorts = new ArrayList(); - - /** - * Upstream ports that are connected directly to this port, if there are any. - * For an ordinary port, this set will have size 0 or 1. - * For a multiport, it can have a larger size. - * This initially has capacity 1 because that is by far the most common case. - */ - List> dependsOnPorts = new ArrayList>(1); - - /** Indicator of whether this is a multiport. */ - boolean isMultiport = false; - - ////////////////////////////////////////////////////// - //// Private methods. - - /** - * Given a RuntimeRange, return a list of SendRange that describes - * the eventual destinations of the given range. - * The sum of the total widths of the send ranges on the returned list - * will be an integer multiple N of the total width of the specified range. - * Each returned SendRange has a list - * of destination RuntimeRanges, each of which represents a port that - * has dependent reactions. Intermediate ports with no dependent - * reactions are not listed. - * @param srcRange The source range. - */ - private static List eventualDestinations(RuntimeRange srcRange) { - - // Getting the destinations is more complex than getting the sources - // because of multicast, where there is more than one connection statement - // for a source of data. The strategy we follow here is to first get all - // the ports that this port eventually sends to. Then, if needed, split - // the resulting ranges so that the resulting list covers exactly - // srcRange, possibly in pieces. We make two passes. First, we build - // a queue of ranges that may overlap, then we split those ranges - // and consolidate their destinations. - - List result = new ArrayList(); - PriorityQueue queue = new PriorityQueue(); - PortInstance srcPort = srcRange.instance; - - // Start with, if this port has dependent reactions, then add it to - // every range of the result. - if (!srcRange.instance.dependentReactions.isEmpty()) { - // This will be the final result if there are no connections. - SendRange candidate = new SendRange( - srcRange.instance, - srcRange.start, - srcRange.width, - null, // No interleaving for this range. - null // No connection for this range. - ); - candidate.destinations.add(srcRange); - queue.add(candidate); - } - // Need to find send ranges that overlap with this srcRange. - Iterator sendRanges = srcPort.dependentPorts.iterator(); - while (sendRanges.hasNext()) { - - SendRange wSendRange = sendRanges.next(); - - if (wSendRange.connection != null && wSendRange.connection.getDelay() != null) { - continue; - } - - wSendRange = wSendRange.overlap(srcRange); - if (wSendRange == null) { - // This send range does not overlap with the desired range. Try the next one. - continue; - } - for (RuntimeRange dstRange : wSendRange.destinations) { - // Recursively get the send ranges of that destination port. - List dstSendRanges = eventualDestinations(dstRange); - int sendRangeStart = 0; - for (SendRange dstSend : dstSendRanges) { - queue.add(dstSend.newSendRange(wSendRange, sendRangeStart)); - sendRangeStart += dstSend.width; - } - } + // Need to find send ranges that overlap with this srcRange. + Iterator sendRanges = srcPort.dependentPorts.iterator(); + while (sendRanges.hasNext()) { + + SendRange wSendRange = sendRanges.next(); + + if (wSendRange.connection != null && wSendRange.connection.getDelay() != null) { + continue; + } + + wSendRange = wSendRange.overlap(srcRange); + if (wSendRange == null) { + // This send range does not overlap with the desired range. Try the next one. + continue; + } + for (RuntimeRange dstRange : wSendRange.destinations) { + // Recursively get the send ranges of that destination port. + List dstSendRanges = eventualDestinations(dstRange); + int sendRangeStart = 0; + for (SendRange dstSend : dstSendRanges) { + queue.add(dstSend.newSendRange(wSendRange, sendRangeStart)); + sendRangeStart += dstSend.width; } + } + } - // Now check for overlapping ranges, constructing a new result. - SendRange candidate = queue.poll(); - SendRange next = queue.poll(); - while (candidate != null) { - if (next == null) { - // No more candidates. We are done. - result.add(candidate); - break; - } - if (candidate.start == next.start) { - // Ranges have the same starting point. Need to merge them. - if (candidate.width <= next.width) { - // Can use all of the channels of candidate. - // Import the destinations of next and split it. - for (RuntimeRange destination : next.destinations) { - candidate.destinations.add(destination.head(candidate.width)); - } - if (candidate.width < next.width) { - // The next range has more channels connected to this sender. - // Put it back on the queue an poll for a new next. - queue.add(next.tail(candidate.width)); - next = queue.poll(); - } else { - // We are done with next and can discard it. - next = queue.poll(); - } - } else { - // candidate is wider than next. Switch them and continue. - SendRange temp = candidate; - candidate = next; - next = temp; - } - } else { - // Because the result list is sorted, next starts at - // a higher channel than candidate. - if (candidate.start + candidate.width <= next.start) { - // Can use candidate as is and make next the new candidate. - result.add(candidate); - candidate = next; - next = queue.poll(); - } else { - // Ranges overlap. Can use a truncated candidate and make its - // truncated version the new candidate. - result.add(candidate.head(next.start)); - candidate = (SendRange)candidate.tail(next.start); - } - } + // Now check for overlapping ranges, constructing a new result. + SendRange candidate = queue.poll(); + SendRange next = queue.poll(); + while (candidate != null) { + if (next == null) { + // No more candidates. We are done. + result.add(candidate); + break; + } + if (candidate.start == next.start) { + // Ranges have the same starting point. Need to merge them. + if (candidate.width <= next.width) { + // Can use all of the channels of candidate. + // Import the destinations of next and split it. + for (RuntimeRange destination : next.destinations) { + candidate.destinations.add(destination.head(candidate.width)); + } + if (candidate.width < next.width) { + // The next range has more channels connected to this sender. + // Put it back on the queue an poll for a new next. + queue.add(next.tail(candidate.width)); + next = queue.poll(); + } else { + // We are done with next and can discard it. + next = queue.poll(); + } + } else { + // candidate is wider than next. Switch them and continue. + SendRange temp = candidate; + candidate = next; + next = temp; + } + } else { + // Because the result list is sorted, next starts at + // a higher channel than candidate. + if (candidate.start + candidate.width <= next.start) { + // Can use candidate as is and make next the new candidate. + result.add(candidate); + candidate = next; + next = queue.poll(); + } else { + // Ranges overlap. Can use a truncated candidate and make its + // truncated version the new candidate. + result.add(candidate.head(next.start)); + candidate = (SendRange) candidate.tail(next.start); } - - return result; + } } - /** - * Return a list of ranges of ports that send data to this port within the - * specified range. If this port is directly written to by one more more reactions, - * then it is its own eventual source and only this port - * will be represented in the result. - * - * If this is not a multiport and is not within a bank, then the list will have - * only one item and the range will have a total width of one. Otherwise, it will - * have enough items so that the range widths add up to the width of this - * multiport multiplied by the total number of instances within containing banks. - * - * The ports listed are only ports that are written to by reactions, - * not relay ports that the data may go through on the way. - */ - private List> eventualSources(RuntimeRange range) { - if (eventualSourceRanges == null) { - // Cached result has not been created. - eventualSourceRanges = new ArrayList>(); - - if (!dependsOnReactions.isEmpty()) { - eventualSourceRanges.add(new RuntimeRange.Port(this)); - } else { - var channelsCovered = 0; - for (RuntimeRange sourceRange : dependsOnPorts) { - // Check whether the sourceRange overlaps with the range. - if (channelsCovered + sourceRange.width >= range.start - && channelsCovered < range.start + range.width) { - eventualSourceRanges.addAll(sourceRange.instance.eventualSources(sourceRange)); - } - channelsCovered += sourceRange.width; - } - } + return result; + } + + /** + * Return a list of ranges of ports that send data to this port within the specified range. If + * this port is directly written to by one more more reactions, then it is its own eventual source + * and only this port will be represented in the result. + * + *

    If this is not a multiport and is not within a bank, then the list will have only one item + * and the range will have a total width of one. Otherwise, it will have enough items so that the + * range widths add up to the width of this multiport multiplied by the total number of instances + * within containing banks. + * + *

    The ports listed are only ports that are written to by reactions, not relay ports that the + * data may go through on the way. + */ + private List> eventualSources(RuntimeRange range) { + if (eventualSourceRanges == null) { + // Cached result has not been created. + eventualSourceRanges = new ArrayList>(); + + if (!dependsOnReactions.isEmpty()) { + eventualSourceRanges.add(new RuntimeRange.Port(this)); + } else { + var channelsCovered = 0; + for (RuntimeRange sourceRange : dependsOnPorts) { + // Check whether the sourceRange overlaps with the range. + if (channelsCovered + sourceRange.width >= range.start + && channelsCovered < range.start + range.width) { + eventualSourceRanges.addAll(sourceRange.instance.eventualSources(sourceRange)); + } + channelsCovered += sourceRange.width; } - return eventualSourceRanges; + } } + return eventualSourceRanges; + } + + /** + * Set the initial multiport width, if this is a multiport, from the widthSpec in the definition. + * This will be set to -1 if the width cannot be determined. + * + * @param errorReporter For reporting errors. + */ + private void setInitialWidth(ErrorReporter errorReporter) { + // If this is a multiport, determine the width. + WidthSpec widthSpec = definition.getWidthSpec(); + + if (widthSpec != null) { + if (widthSpec.isOfVariableLength()) { + errorReporter.reportError( + definition, "Variable-width multiports not supported (yet): " + definition.getName()); + } else { + isMultiport = true; - /** - * Set the initial multiport width, if this is a multiport, from the widthSpec - * in the definition. This will be set to -1 if the width cannot be determined. - * @param errorReporter For reporting errors. - */ - private void setInitialWidth(ErrorReporter errorReporter) { - // If this is a multiport, determine the width. - WidthSpec widthSpec = definition.getWidthSpec(); - - if (widthSpec != null) { - if (widthSpec.isOfVariableLength()) { - errorReporter.reportError(definition, - "Variable-width multiports not supported (yet): " + definition.getName()); + // Determine the initial width, if possible. + // The width may be given by a parameter or even sum of parameters. + width = 0; + for (WidthTerm term : widthSpec.getTerms()) { + Parameter parameter = term.getParameter(); + if (parameter != null) { + Integer parameterValue = parent.initialIntParameterValue(parameter); + // Only a Literal is supported. + if (parameterValue != null) { + width += parameterValue; } else { - isMultiport = true; - - // Determine the initial width, if possible. - // The width may be given by a parameter or even sum of parameters. - width = 0; - for (WidthTerm term : widthSpec.getTerms()) { - Parameter parameter = term.getParameter(); - if (parameter != null) { - Integer parameterValue = parent.initialIntParameterValue(parameter); - // Only a Literal is supported. - if (parameterValue != null) { - width += parameterValue; - } else { - width = -1; - return; - } - } else if (term.getWidth() != 0){ - width += term.getWidth(); - } else { - width = -1; - return; - } - } + width = -1; + return; } + } else if (term.getWidth() != 0) { + width += term.getWidth(); + } else { + width = -1; + return; + } } + } } + } + + ////////////////////////////////////////////////////// + //// Private fields. + + /** Cached list of destination ports with channel ranges. */ + private List eventualDestinationRanges; + + /** Cached list of source ports with channel ranges. */ + private List> eventualSourceRanges; - ////////////////////////////////////////////////////// - //// Private fields. - - /** Cached list of destination ports with channel ranges. */ - private List eventualDestinationRanges; - - /** Cached list of source ports with channel ranges. */ - private List> eventualSourceRanges; - - /** Indicator that we are clearing the caches. */ - private boolean clearingCaches = false; + /** Indicator that we are clearing the caches. */ + private boolean clearingCaches = false; } diff --git a/org.lflang/src/org/lflang/generator/Position.java b/org.lflang/src/org/lflang/generator/Position.java index 872b09a24e..80e3976365 100644 --- a/org.lflang/src/org/lflang/generator/Position.java +++ b/org.lflang/src/org/lflang/generator/Position.java @@ -4,234 +4,219 @@ import java.util.regex.Pattern; /** - * A position in a document, including line and - * column. This position may be relative to some + * A position in a document, including line and column. This position may be relative to some * position other than the origin. * * @author Peter Donovan */ public class Position implements Comparable { - public static final Pattern PATTERN = Pattern.compile("\\((?[0-9]+), (?[0-9]+)\\)"); - - public static final Position ORIGIN = Position.fromZeroBased(0, 0); - - private static final Pattern LINE_SEPARATOR = Pattern.compile("(\n)|(\r)|(\r\n)"); - - private final int line; - private final int column; - - /* ------------------------ CONSTRUCTORS -------------------------- */ - - /** - * Return the Position that describes the given - * zero-based line and column numbers. - * @param line the zero-based line number - * @param column the zero-based column number - * @return a Position describing the position described - * by {@code line} and {@code column}. - */ - public static Position fromZeroBased(int line, int column) { - return new Position(line, column); - } - - /** - * Return the Position that describes the given - * one-based line and column numbers. - * @param line the one-based line number - * @param column the one-based column number - * @return a Position describing the position described - * by {@code line} and {@code column}. - */ - public static Position fromOneBased(int line, int column) { - return new Position(line - 1, column - 1); - } - - /** - * Return the Position that equals the displacement - * caused by {@code text}, assuming that {@code text} - * starts in column 0. - * @param text an arbitrary string - * @return the Position that equals the displacement - * caused by {@code text} - */ - public static Position displacementOf(String text) { - String[] lines = text.lines().toArray(String[]::new); - if (lines.length == 0) return ORIGIN; - return Position.fromZeroBased(lines.length - 1, lines[lines.length - 1].length()); - } - - /** - * Return the Position that describes the same location - * in {@code content} as {@code offset}. - * @param offset a location, expressed as an offset from - * the beginning of {@code content} - * @param content the content of a document - * @return the Position that describes the same location - * in {@code content} as {@code offset} - */ - public static Position fromOffset(int offset, String content) { - int lineNumber = 0; - Matcher matcher = LINE_SEPARATOR.matcher(content); - int start = 0; - while (matcher.find(start)) { - if (matcher.start() > offset) return Position.fromZeroBased(lineNumber, offset - start); - start = matcher.end(); - lineNumber++; - } - return Position.fromZeroBased(lineNumber, offset); - } - - /** - * Create a new Position with the given line and column - * numbers. - * @param line the zero-based line number - * @param column the zero-based column number - */ - private Position(int line, int column) { - // Assertions about whether line and column are - // non-negative are deliberately omitted. Positions - // can be relative. - this.line = line; - this.column = column; - } - - /* ----------------------- PUBLIC METHODS ------------------------- */ - - /** - * Return the one-based line number described by this - * {@code Position}. - * @return the one-based line number described by this - * {@code Position} - */ - public int getOneBasedLine() { - return line + 1; - } - - /** - * Return the one-based column number described by this - * {@code Position}. - * @return the one-based column number described by this - * {@code Position} - */ - public int getOneBasedColumn() { - return column + 1; - } - - /** - * Return the zero-based line number described by this - * {@code Position}. - * @return the zero-based line number described by this - * {@code Position} - */ - public int getZeroBasedLine() { - return line; - } - - /** - * Return the zero-based column number described by this - * {@code Position}. - * @return the zero-based column number described by this - * {@code Position} - */ - public int getZeroBasedColumn() { - return column; - } - - /** - * Return the Position that equals the displacement of - * ((text whose displacement equals {@code this}) - * concatenated with {@code text}). Note that this is - * not necessarily equal to - * ({@code this} + displacementOf(text)). - * @param text an arbitrary string - * @return the Position that equals the displacement - * caused by {@code text} - */ - public Position plus(String text) { - text += "\n"; // Turn line separators into line terminators. - String[] lines = text.lines().toArray(String[]::new); - if (lines.length == 0) return this; // OK not to copy because Positions are immutable - int lastLineLength = lines[lines.length - 1].length(); - return new Position(line + lines.length - 1, lines.length > 1 ? lastLineLength : column + lastLineLength); - } - - /** - * Return the sum of this and another {@code Position}. - * The result has meaning because Positions are - * relative. - * @param other another {@code Position} - * @return the sum of this and {@code other} - */ - public Position plus(Position other) { - return new Position(line + other.line, column + other.column); - } - - /** - * Return the difference of this and another {@code - * Position}. The result has meaning because - * Positions are relative. - * @param other another {@code Position} - * @return the difference of this and {@code other} - */ - public Position minus(Position other) { - return new Position(line - other.line, column - other.column); - } - - /** - * Compare two positions according to their order of - * appearance in a document (first according to line, - * then according to column). - */ - @Override - public int compareTo(Position o) { - if (line != o.line) { - return line - o.line; - } - return column - o.column; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof Position && ((Position) obj).compareTo(this) == 0; - } - - @Override - public String toString() { - return String.format("(%d, %d)", getZeroBasedLine(), getZeroBasedColumn()); - } - - /** - * Return the Position represented by {@code s}. - * @param s a String that represents a Position, - * formatted like the output of - * {@code Position::toString}. - * @return the Position represented by {@code s} - */ - public static Position fromString(String s) { - Matcher matcher = PATTERN.matcher(s); - if (matcher.matches()) { - return Position.fromZeroBased( - Integer.parseInt(matcher.group("line")), - Integer.parseInt(matcher.group("column")) - ); - } - throw new IllegalArgumentException(String.format("Could not parse %s as a Position.", s)); - } - - @Override - public int hashCode() { - return line * 31 + column; - } - - /** - * Remove the names from the named capturing groups - * that appear in {@code regex}. - * @param regex an arbitrary regular expression - * @return a string representation of {@code regex} - * with the names removed from the named capturing - * groups - */ - public static String removeNamedCapturingGroups(Pattern regex) { // FIXME: Does this belong here? - return regex.toString().replaceAll("\\(\\?<\\w+>", "("); - } + public static final Pattern PATTERN = Pattern.compile("\\((?[0-9]+), (?[0-9]+)\\)"); + + public static final Position ORIGIN = Position.fromZeroBased(0, 0); + + private static final Pattern LINE_SEPARATOR = Pattern.compile("(\n)|(\r)|(\r\n)"); + + private final int line; + private final int column; + + /* ------------------------ CONSTRUCTORS -------------------------- */ + + /** + * Return the Position that describes the given zero-based line and column numbers. + * + * @param line the zero-based line number + * @param column the zero-based column number + * @return a Position describing the position described by {@code line} and {@code column}. + */ + public static Position fromZeroBased(int line, int column) { + return new Position(line, column); + } + + /** + * Return the Position that describes the given one-based line and column numbers. + * + * @param line the one-based line number + * @param column the one-based column number + * @return a Position describing the position described by {@code line} and {@code column}. + */ + public static Position fromOneBased(int line, int column) { + return new Position(line - 1, column - 1); + } + + /** + * Return the Position that equals the displacement caused by {@code text}, assuming that {@code + * text} starts in column 0. + * + * @param text an arbitrary string + * @return the Position that equals the displacement caused by {@code text} + */ + public static Position displacementOf(String text) { + String[] lines = text.lines().toArray(String[]::new); + if (lines.length == 0) return ORIGIN; + return Position.fromZeroBased(lines.length - 1, lines[lines.length - 1].length()); + } + + /** + * Return the Position that describes the same location in {@code content} as {@code offset}. + * + * @param offset a location, expressed as an offset from the beginning of {@code content} + * @param content the content of a document + * @return the Position that describes the same location in {@code content} as {@code offset} + */ + public static Position fromOffset(int offset, String content) { + int lineNumber = 0; + Matcher matcher = LINE_SEPARATOR.matcher(content); + int start = 0; + while (matcher.find(start)) { + if (matcher.start() > offset) return Position.fromZeroBased(lineNumber, offset - start); + start = matcher.end(); + lineNumber++; + } + return Position.fromZeroBased(lineNumber, offset); + } + + /** + * Create a new Position with the given line and column numbers. + * + * @param line the zero-based line number + * @param column the zero-based column number + */ + private Position(int line, int column) { + // Assertions about whether line and column are + // non-negative are deliberately omitted. Positions + // can be relative. + this.line = line; + this.column = column; + } + + /* ----------------------- PUBLIC METHODS ------------------------- */ + + /** + * Return the one-based line number described by this {@code Position}. + * + * @return the one-based line number described by this {@code Position} + */ + public int getOneBasedLine() { + return line + 1; + } + + /** + * Return the one-based column number described by this {@code Position}. + * + * @return the one-based column number described by this {@code Position} + */ + public int getOneBasedColumn() { + return column + 1; + } + + /** + * Return the zero-based line number described by this {@code Position}. + * + * @return the zero-based line number described by this {@code Position} + */ + public int getZeroBasedLine() { + return line; + } + + /** + * Return the zero-based column number described by this {@code Position}. + * + * @return the zero-based column number described by this {@code Position} + */ + public int getZeroBasedColumn() { + return column; + } + + /** + * Return the Position that equals the displacement of ((text whose displacement equals {@code + * this}) concatenated with {@code text}). Note that this is not necessarily equal to ({@code + * this} + displacementOf(text)). + * + * @param text an arbitrary string + * @return the Position that equals the displacement caused by {@code text} + */ + public Position plus(String text) { + text += "\n"; // Turn line separators into line terminators. + String[] lines = text.lines().toArray(String[]::new); + if (lines.length == 0) return this; // OK not to copy because Positions are immutable + int lastLineLength = lines[lines.length - 1].length(); + return new Position( + line + lines.length - 1, lines.length > 1 ? lastLineLength : column + lastLineLength); + } + + /** + * Return the sum of this and another {@code Position}. The result has meaning because Positions + * are relative. + * + * @param other another {@code Position} + * @return the sum of this and {@code other} + */ + public Position plus(Position other) { + return new Position(line + other.line, column + other.column); + } + + /** + * Return the difference of this and another {@code Position}. The result has meaning because + * Positions are relative. + * + * @param other another {@code Position} + * @return the difference of this and {@code other} + */ + public Position minus(Position other) { + return new Position(line - other.line, column - other.column); + } + + /** + * Compare two positions according to their order of appearance in a document (first according to + * line, then according to column). + */ + @Override + public int compareTo(Position o) { + if (line != o.line) { + return line - o.line; + } + return column - o.column; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof Position && ((Position) obj).compareTo(this) == 0; + } + + @Override + public String toString() { + return String.format("(%d, %d)", getZeroBasedLine(), getZeroBasedColumn()); + } + + /** + * Return the Position represented by {@code s}. + * + * @param s a String that represents a Position, formatted like the output of {@code + * Position::toString}. + * @return the Position represented by {@code s} + */ + public static Position fromString(String s) { + Matcher matcher = PATTERN.matcher(s); + if (matcher.matches()) { + return Position.fromZeroBased( + Integer.parseInt(matcher.group("line")), Integer.parseInt(matcher.group("column"))); + } + throw new IllegalArgumentException(String.format("Could not parse %s as a Position.", s)); + } + + @Override + public int hashCode() { + return line * 31 + column; + } + + /** + * Remove the names from the named capturing groups that appear in {@code regex}. + * + * @param regex an arbitrary regular expression + * @return a string representation of {@code regex} with the names removed from the named + * capturing groups + */ + public static String removeNamedCapturingGroups(Pattern regex) { // FIXME: Does this belong here? + return regex.toString().replaceAll("\\(\\?<\\w+>", "("); + } } diff --git a/org.lflang/src/org/lflang/generator/Range.java b/org.lflang/src/org/lflang/generator/Range.java index ffca1104d9..9300127d36 100644 --- a/org.lflang/src/org/lflang/generator/Range.java +++ b/org.lflang/src/org/lflang/generator/Range.java @@ -4,136 +4,129 @@ import java.util.regex.Pattern; /** - * Represents a range in a document. Ranges have a - * natural ordering that respects their start + * Represents a range in a document. Ranges have a natural ordering that respects their start * position(s) only. */ public class Range implements Comparable { - public static final Pattern PATTERN = Pattern.compile(String.format( - "Range: \\[(?%s), (?%s)\\)", - Position.removeNamedCapturingGroups(Position.PATTERN), - Position.removeNamedCapturingGroups(Position.PATTERN) - )); + public static final Pattern PATTERN = + Pattern.compile( + String.format( + "Range: \\[(?%s), (?%s)\\)", + Position.removeNamedCapturingGroups(Position.PATTERN), + Position.removeNamedCapturingGroups(Position.PATTERN))); - /** The start of the Range (INCLUSIVE). */ - private final Position start; - /** The end of the Range (EXCLUSIVE). */ - private final Position end; + /** The start of the Range (INCLUSIVE). */ + private final Position start; + /** The end of the Range (EXCLUSIVE). */ + private final Position end; - /* ------------------------- PUBLIC METHODS -------------------------- */ + /* ------------------------- PUBLIC METHODS -------------------------- */ - /** - * Initializes a Range that starts at - * {@code startInclusive} and ends at, but does not - * include, {@code endExclusive}. - * @param startInclusive the start of the range - * (inclusive) - * @param endExclusive the end of the range (exclusive) - */ - public Range(Position startInclusive, Position endExclusive) { - assert startInclusive.compareTo(endExclusive) <= 0: "endExclusive cannot precede startInclusive"; - start = startInclusive; - end = endExclusive; - } + /** + * Initializes a Range that starts at {@code startInclusive} and ends at, but does not include, + * {@code endExclusive}. + * + * @param startInclusive the start of the range (inclusive) + * @param endExclusive the end of the range (exclusive) + */ + public Range(Position startInclusive, Position endExclusive) { + assert startInclusive.compareTo(endExclusive) <= 0 + : "endExclusive cannot precede startInclusive"; + start = startInclusive; + end = endExclusive; + } - /** - * Returns the first Position that is included in this - * Range. - * @return the first Position that is included in this - * Range - */ - public Position getStartInclusive() { - return start; - } + /** + * Returns the first Position that is included in this Range. + * + * @return the first Position that is included in this Range + */ + public Position getStartInclusive() { + return start; + } - /** - * Returns the Position that immediately follows the - * last Position in this Range. - * @return the Position that immediately follows the - * last Position in this Range - */ - public Position getEndExclusive() { - return end; - } + /** + * Returns the Position that immediately follows the last Position in this Range. + * + * @return the Position that immediately follows the last Position in this Range + */ + public Position getEndExclusive() { + return end; + } - @Override - public boolean equals(Object o) { - if (!(o instanceof Range r)) return false; - return start.equals(r.start); - } + @Override + public boolean equals(Object o) { + if (!(o instanceof Range r)) return false; + return start.equals(r.start); + } - @Override - public int hashCode() { - return start.hashCode(); - } + @Override + public int hashCode() { + return start.hashCode(); + } - /** - * Compares this to {@code o}. - * @param o another Range - * @return an integer indicating how this compares to - * {@code o} - */ - @Override - public int compareTo(Range o) { - return this.start.compareTo(o.start); - } + /** + * Compares this to {@code o}. + * + * @param o another Range + * @return an integer indicating how this compares to {@code o} + */ + @Override + public int compareTo(Range o) { + return this.start.compareTo(o.start); + } - /** - * Returns whether this contains {@code p}. - * @param p an arbitrary Position - * @return whether this contains {@code p} - */ - public boolean contains(Position p) { - return start.compareTo(p) <= 0 && p.compareTo(end) < 0; - } + /** + * Returns whether this contains {@code p}. + * + * @param p an arbitrary Position + * @return whether this contains {@code p} + */ + public boolean contains(Position p) { + return start.compareTo(p) <= 0 && p.compareTo(end) < 0; + } - @Override - public String toString() { - return String.format("Range: [%s, %s)", start, end); - } + @Override + public String toString() { + return String.format("Range: [%s, %s)", start, end); + } - /** - * Converts {@code s} to a Range. - * @param s a String that represents a Range, formatted - * like the output of {@code Range::toString} - * @return the Range r such that {@code r.toString()} - * equals {@code s} - */ - public static Range fromString(String s) { - return fromString(s, Position.fromZeroBased(0, 0)); - } + /** + * Converts {@code s} to a Range. + * + * @param s a String that represents a Range, formatted like the output of {@code Range::toString} + * @return the Range r such that {@code r.toString()} equals {@code s} + */ + public static Range fromString(String s) { + return fromString(s, Position.fromZeroBased(0, 0)); + } - /** - * Converts {@code s} to a Range, with the - * assumption that the positions expressed in {@code s} - * are given relative to {@code relativeTo}. - * @param s a String that represents a Range, formatted - * like the output of {@code Range::toString} - * @param relativeTo the position relative to which the - * positions in {@code s} are - * represented - * @return the Range represented by {@code s}, - * expressed relative to the Position relative to which - * the Position {@code relativeTo} is expressed - */ - public static Range fromString(String s, Position relativeTo) { - Matcher matcher = PATTERN.matcher(s); - if (matcher.matches()) { - Position start = Position.fromString(matcher.group("start")); - Position end = Position.fromString(matcher.group("end")); - return new Range(start.plus(relativeTo), end.plus(relativeTo)); - } - throw new IllegalArgumentException(String.format("Could not parse %s as a Range.", s)); + /** + * Converts {@code s} to a Range, with the assumption that the positions expressed in {@code s} + * are given relative to {@code relativeTo}. + * + * @param s a String that represents a Range, formatted like the output of {@code Range::toString} + * @param relativeTo the position relative to which the positions in {@code s} are represented + * @return the Range represented by {@code s}, expressed relative to the Position relative to + * which the Position {@code relativeTo} is expressed + */ + public static Range fromString(String s, Position relativeTo) { + Matcher matcher = PATTERN.matcher(s); + if (matcher.matches()) { + Position start = Position.fromString(matcher.group("start")); + Position end = Position.fromString(matcher.group("end")); + return new Range(start.plus(relativeTo), end.plus(relativeTo)); } + throw new IllegalArgumentException(String.format("Could not parse %s as a Range.", s)); + } - /** - * Returns the degenerate range that simply - * describes the exact location specified by {@code p}. - * @param p an arbitrary Position - * @return a Range that starts and ends immediately - * before {@code p} - */ - public static Range degenerateRange(Position p) { - return new Range(p, p); - } + /** + * Returns the degenerate range that simply describes the exact location specified by {@code p}. + * + * @param p an arbitrary Position + * @return a Range that starts and ends immediately before {@code p} + */ + public static Range degenerateRange(Position p) { + return new Range(p, p); + } } diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index 1d7cbab52a..a1e35ffb19 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -1,28 +1,28 @@ /** Representation of a runtime instance of a reaction. */ /************* -Copyright (c) 2019-2022, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2022, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; @@ -31,9 +31,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.LinkedList; import java.util.List; import java.util.Set; - -import org.lflang.ast.ASTUtils; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Action; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Port; @@ -44,551 +43,519 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Variable; /** - * Representation of a compile-time instance of a reaction. - * Like {@link ReactorInstance}, if one or more parents of this reaction - * is a bank of reactors, then there will be more than one runtime instance - * corresponding to this compile-time instance. The {@link #getRuntimeInstances()} - * method returns a list of these runtime instances, each an instance of the - * inner class {@link ReactionInstance.Runtime}. Each runtime instance has a "level", which is - * its depth an acyclic precedence graph representing the dependencies between - * reactions at a tag. + * Representation of a compile-time instance of a reaction. Like {@link ReactorInstance}, if one or + * more parents of this reaction is a bank of reactors, then there will be more than one runtime + * instance corresponding to this compile-time instance. The {@link #getRuntimeInstances()} method + * returns a list of these runtime instances, each an instance of the inner class {@link + * ReactionInstance.Runtime}. Each runtime instance has a "level", which is its depth an acyclic + * precedence graph representing the dependencies between reactions at a tag. * * @author Edward A. Lee * @author Marten Lohstroh */ public class ReactionInstance extends NamedInstance { - /** - * Create a new reaction instance from the specified definition - * within the specified parent. This constructor should be called - * only by the ReactorInstance class, but it is public to enable unit tests. - * @param definition A reaction definition. - * @param parent The parent reactor instance, which cannot be null. - * @param isUnordered Indicator that this reaction is unordered w.r.t. other reactions. - * @param index The index of the reaction within the reactor (0 for the - * first reaction, 1 for the second, etc.). - */ - public ReactionInstance( - Reaction definition, - ReactorInstance parent, - boolean isUnordered, - int index - ) { - super(definition, parent); - this.index = index; - this.isUnordered = isUnordered; - - // If the reaction body starts with the magic string - // UNORDERED_REACTION_MARKER, then mark it unordered, - // overriding the argument. - String body = ASTUtils.toText(definition.getCode()); - if (body.contains(UNORDERED_REACTION_MARKER)) { - this.isUnordered = true; - } + /** + * Create a new reaction instance from the specified definition within the specified parent. This + * constructor should be called only by the ReactorInstance class, but it is public to enable unit + * tests. + * + * @param definition A reaction definition. + * @param parent The parent reactor instance, which cannot be null. + * @param isUnordered Indicator that this reaction is unordered w.r.t. other reactions. + * @param index The index of the reaction within the reactor (0 for the first reaction, 1 for the + * second, etc.). + */ + public ReactionInstance( + Reaction definition, ReactorInstance parent, boolean isUnordered, int index) { + super(definition, parent); + this.index = index; + this.isUnordered = isUnordered; + + // If the reaction body starts with the magic string + // UNORDERED_REACTION_MARKER, then mark it unordered, + // overriding the argument. + String body = ASTUtils.toText(definition.getCode()); + if (body.contains(UNORDERED_REACTION_MARKER)) { + this.isUnordered = true; + } - // Identify the dependencies for this reaction. - // First handle the triggers. - for (TriggerRef trigger : definition.getTriggers()) { - if (trigger instanceof VarRef) { - Variable variable = ((VarRef)trigger).getVariable(); - if (variable instanceof Port) { - PortInstance portInstance = parent.lookupPortInstance((Port)variable); - // If the trigger is the port of a contained bank, then the - // portInstance will be null and we have to instead search for - // each port instance in the bank. - if (portInstance != null) { - this.sources.add(portInstance); - portInstance.dependentReactions.add(this); - this.triggers.add(portInstance); - } else if (((VarRef)trigger).getContainer() != null) { - // Port belongs to a contained reactor or bank. - ReactorInstance containedReactor - = parent.lookupReactorInstance(((VarRef)trigger).getContainer()); - if (containedReactor != null) { - portInstance = containedReactor.lookupPortInstance((Port)variable); - if (portInstance != null) { - this.sources.add(portInstance); - portInstance.dependentReactions.add(this); - this.triggers.add(portInstance); - } - } - } - } else if (variable instanceof Action) { - var actionInstance = parent.lookupActionInstance( - (Action)((VarRef)trigger).getVariable()); - this.triggers.add(actionInstance); - actionInstance.dependentReactions.add(this); - this.sources.add(actionInstance); - } else if (variable instanceof Timer) { - var timerInstance = parent.lookupTimerInstance( - (Timer)((VarRef)trigger).getVariable()); - this.triggers.add(timerInstance); - timerInstance.dependentReactions.add(this); - this.sources.add(timerInstance); - } - } else if (trigger instanceof BuiltinTriggerRef) { - this.triggers.add(parent.getOrCreateBuiltinTrigger((BuiltinTriggerRef) trigger)); + // Identify the dependencies for this reaction. + // First handle the triggers. + for (TriggerRef trigger : definition.getTriggers()) { + if (trigger instanceof VarRef) { + Variable variable = ((VarRef) trigger).getVariable(); + if (variable instanceof Port) { + PortInstance portInstance = parent.lookupPortInstance((Port) variable); + // If the trigger is the port of a contained bank, then the + // portInstance will be null and we have to instead search for + // each port instance in the bank. + if (portInstance != null) { + this.sources.add(portInstance); + portInstance.dependentReactions.add(this); + this.triggers.add(portInstance); + } else if (((VarRef) trigger).getContainer() != null) { + // Port belongs to a contained reactor or bank. + ReactorInstance containedReactor = + parent.lookupReactorInstance(((VarRef) trigger).getContainer()); + if (containedReactor != null) { + portInstance = containedReactor.lookupPortInstance((Port) variable); + if (portInstance != null) { + this.sources.add(portInstance); + portInstance.dependentReactions.add(this); + this.triggers.add(portInstance); + } } + } + } else if (variable instanceof Action) { + var actionInstance = + parent.lookupActionInstance((Action) ((VarRef) trigger).getVariable()); + this.triggers.add(actionInstance); + actionInstance.dependentReactions.add(this); + this.sources.add(actionInstance); + } else if (variable instanceof Timer) { + var timerInstance = parent.lookupTimerInstance((Timer) ((VarRef) trigger).getVariable()); + this.triggers.add(timerInstance); + timerInstance.dependentReactions.add(this); + this.sources.add(timerInstance); } - // Next handle the ports that this reaction reads. - for (VarRef source : definition.getSources()) { - Variable variable = source.getVariable(); - if (variable instanceof Port) { - var portInstance = parent.lookupPortInstance((Port)variable); - - // If the trigger is the port of a contained bank, then the - // portInstance will be null and we have to instead search for - // each port instance in the bank. - if (portInstance != null) { - this.sources.add(portInstance); - this.reads.add(portInstance); - portInstance.dependentReactions.add(this); - } else if (source.getContainer() != null) { - ReactorInstance containedReactor - = parent.lookupReactorInstance(source.getContainer()); - if (containedReactor != null) { - portInstance = containedReactor.lookupPortInstance((Port)variable); - if (portInstance != null) { - this.sources.add(portInstance); - portInstance.dependentReactions.add(this); - this.triggers.add(portInstance); - } - } - } + } else if (trigger instanceof BuiltinTriggerRef) { + this.triggers.add(parent.getOrCreateBuiltinTrigger((BuiltinTriggerRef) trigger)); + } + } + // Next handle the ports that this reaction reads. + for (VarRef source : definition.getSources()) { + Variable variable = source.getVariable(); + if (variable instanceof Port) { + var portInstance = parent.lookupPortInstance((Port) variable); + + // If the trigger is the port of a contained bank, then the + // portInstance will be null and we have to instead search for + // each port instance in the bank. + if (portInstance != null) { + this.sources.add(portInstance); + this.reads.add(portInstance); + portInstance.dependentReactions.add(this); + } else if (source.getContainer() != null) { + ReactorInstance containedReactor = parent.lookupReactorInstance(source.getContainer()); + if (containedReactor != null) { + portInstance = containedReactor.lookupPortInstance((Port) variable); + if (portInstance != null) { + this.sources.add(portInstance); + portInstance.dependentReactions.add(this); + this.triggers.add(portInstance); } + } } + } + } - // Finally, handle the effects. - for (VarRef effect : definition.getEffects()) { - Variable variable = effect.getVariable(); - if (variable instanceof Port) { - var portInstance = parent.lookupPortInstance(effect); - if (portInstance != null) { - this.effects.add(portInstance); - portInstance.dependsOnReactions.add(this); - } else { - throw new InvalidSourceException( - "Unexpected effect. Cannot find port " + variable.getName()); - } - } else if (variable instanceof Action) { - // Effect is an Action. - var actionInstance = parent.lookupActionInstance( - (Action)variable); - this.effects.add(actionInstance); - actionInstance.dependsOnReactions.add(this); - } else { - // Effect is either a mode or an unresolved reference. - // Do nothing, transitions will be set up by the ModeInstance. - } - } - // Create a deadline instance if one has been defined. - if (this.definition.getDeadline() != null) { - this.declaredDeadline = new DeadlineInstance( - this.definition.getDeadline(), this); + // Finally, handle the effects. + for (VarRef effect : definition.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Port) { + var portInstance = parent.lookupPortInstance(effect); + if (portInstance != null) { + this.effects.add(portInstance); + portInstance.dependsOnReactions.add(this); + } else { + throw new InvalidSourceException( + "Unexpected effect. Cannot find port " + variable.getName()); } + } else if (variable instanceof Action) { + // Effect is an Action. + var actionInstance = parent.lookupActionInstance((Action) variable); + this.effects.add(actionInstance); + actionInstance.dependsOnReactions.add(this); + } else { + // Effect is either a mode or an unresolved reference. + // Do nothing, transitions will be set up by the ModeInstance. + } } - - ////////////////////////////////////////////////////// - //// Public fields. - - /** - * Indicates the chain this reaction is a part of. It is constructed - * through a bit-wise or among all upstream chains. Each fork in the - * dependency graph setting a new, unused bit to true in order to - * disambiguate it from parallel chains. Note that zero results in - * no overlap with any other reaction, which means the reaction can - * execute in parallel with any other reaction. The default is 1L. - * If left at the default, parallel execution will be based purely - * on levels. - */ - public long chainID = 1L; - - /** - * The ports or actions that this reaction may write to. - */ - public Set> effects = new LinkedHashSet<>(); - - /** - * 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 - // choice in the grammar. - - /** - * Deadline for this reaction instance, if declared. - */ - public DeadlineInstance declaredDeadline; - - /** - * Sadly, we have no way to mark reaction "unordered" in the AST, - * so instead, we use a magic comment at the start of the reaction body. - * This is that magic comment. - */ - public static String UNORDERED_REACTION_MARKER - = "**** This reaction is unordered."; - - /** - * Index of order of occurrence within the reactor definition. - * The first reaction has index 0, the second index 1, etc. - */ - public int index; - - /** - * Whether or not this reaction is ordered with respect to other - * reactions in the same reactor. - */ - public boolean isUnordered; - - /** - * The ports that this reaction reads but that do not trigger it. - */ - public Set> reads = new LinkedHashSet<>(); - - /** - * The trigger instances (input ports, timers, and actions - * that trigger reactions) that trigger this reaction. - */ - public Set> triggers = new LinkedHashSet<>(); - - ////////////////////////////////////////////////////// - //// Public methods. - - /** - * Clear caches used in reporting dependentReactions() and dependsOnReactions(). - * This method should be called if any changes are made to triggers, sources, - * or effects. - * @param includingRuntimes If false, leave the runtime instances intact. - * This is useful for federated execution where levels are computed using - * the top-level connections, but then those connections are discarded. - */ - public void clearCaches(boolean includingRuntimes) { - dependentReactionsCache = null; - dependsOnReactionsCache = null; - if (includingRuntimes) runtimeInstances = null; + // Create a deadline instance if one has been defined. + if (this.definition.getDeadline() != null) { + this.declaredDeadline = new DeadlineInstance(this.definition.getDeadline(), this); } - - /** - * Return the set of immediate downstream reactions, which are reactions - * that receive data produced by this reaction plus - * at most one reaction in the same reactor whose definition - * lexically follows this one (unless this reaction is unordered). - */ - public Set dependentReactions() { - // Cache the result. - if (dependentReactionsCache != null) return dependentReactionsCache; - dependentReactionsCache = new LinkedHashSet<>(); - - // First, add the next lexical reaction, if appropriate. - if (!isUnordered && parent.reactions.size() > index + 1) { - // Find the next reaction in the parent's reaction list. - dependentReactionsCache.add(parent.reactions.get(index + 1)); - } - - // Next, add reactions that get data from this one via a port. - for (TriggerInstance effect : effects) { - if (effect instanceof PortInstance) { - for (SendRange senderRange - : ((PortInstance)effect).eventualDestinations()) { - for (RuntimeRange destinationRange - : senderRange.destinations) { - dependentReactionsCache.addAll( - destinationRange.instance.dependentReactions); - } - } - } - } - return dependentReactionsCache; + } + + ////////////////////////////////////////////////////// + //// Public fields. + + /** + * Indicates the chain this reaction is a part of. It is constructed through a bit-wise or among + * all upstream chains. Each fork in the dependency graph setting a new, unused bit to true in + * order to disambiguate it from parallel chains. Note that zero results in no overlap with any + * other reaction, which means the reaction can execute in parallel with any other reaction. The + * default is 1L. If left at the default, parallel execution will be based purely on levels. + */ + public long chainID = 1L; + + /** The ports or actions that this reaction may write to. */ + public Set> effects = new LinkedHashSet<>(); + + /** 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 + // choice in the grammar. + + /** Deadline for this reaction instance, if declared. */ + public DeadlineInstance declaredDeadline; + + /** + * Sadly, we have no way to mark reaction "unordered" in the AST, so instead, we use a magic + * comment at the start of the reaction body. This is that magic comment. + */ + public static String UNORDERED_REACTION_MARKER = "**** This reaction is unordered."; + + /** + * Index of order of occurrence within the reactor definition. The first reaction has index 0, the + * second index 1, etc. + */ + public int index; + + /** + * Whether or not this reaction is ordered with respect to other reactions in the same reactor. + */ + public boolean isUnordered; + + /** The ports that this reaction reads but that do not trigger it. */ + public Set> reads = new LinkedHashSet<>(); + + /** + * The trigger instances (input ports, timers, and actions that trigger reactions) that trigger + * this reaction. + */ + public Set> triggers = new LinkedHashSet<>(); + + ////////////////////////////////////////////////////// + //// Public methods. + + /** + * Clear caches used in reporting dependentReactions() and dependsOnReactions(). This method + * should be called if any changes are made to triggers, sources, or effects. + * + * @param includingRuntimes If false, leave the runtime instances intact. This is useful for + * federated execution where levels are computed using the top-level connections, but then + * those connections are discarded. + */ + public void clearCaches(boolean includingRuntimes) { + dependentReactionsCache = null; + dependsOnReactionsCache = null; + if (includingRuntimes) runtimeInstances = null; + } + + /** + * Return the set of immediate downstream reactions, which are reactions that receive data + * produced by this reaction plus at most one reaction in the same reactor whose definition + * lexically follows this one (unless this reaction is unordered). + */ + public Set dependentReactions() { + // Cache the result. + if (dependentReactionsCache != null) return dependentReactionsCache; + dependentReactionsCache = new LinkedHashSet<>(); + + // First, add the next lexical reaction, if appropriate. + if (!isUnordered && parent.reactions.size() > index + 1) { + // Find the next reaction in the parent's reaction list. + dependentReactionsCache.add(parent.reactions.get(index + 1)); } - /** - * Return the set of immediate upstream reactions, which are reactions - * that send data to this one plus at most one reaction in the same - * reactor whose definition immediately precedes the definition of this one - * (unless this reaction is unordered). - */ - public Set dependsOnReactions() { - // Cache the result. - if (dependsOnReactionsCache != null) return dependsOnReactionsCache; - dependsOnReactionsCache = new LinkedHashSet<>(); - - // First, add the previous lexical reaction, if appropriate. - if (!isUnordered && index > 0) { - // Find the previous ordered reaction in the parent's reaction list. - int earlierIndex = index - 1; - ReactionInstance earlierOrderedReaction = parent.reactions.get(earlierIndex); - while (earlierOrderedReaction.isUnordered && --earlierIndex >= 0) { - earlierOrderedReaction = parent.reactions.get(earlierIndex); - } - if (earlierIndex >= 0) { - dependsOnReactionsCache.add(parent.reactions.get(index - 1)); - } - } - - // Next, add reactions that send data to this one. - for (TriggerInstance source : sources) { - if (source instanceof PortInstance) { - // First, add reactions that send data through an intermediate port. - for (RuntimeRange senderRange - : ((PortInstance)source).eventualSources()) { - dependsOnReactionsCache.addAll(senderRange.instance.dependsOnReactions); - } - // Then, add reactions that send directly to this port. - dependsOnReactionsCache.addAll(source.dependsOnReactions); - } + // Next, add reactions that get data from this one via a port. + for (TriggerInstance effect : effects) { + if (effect instanceof PortInstance) { + for (SendRange senderRange : ((PortInstance) effect).eventualDestinations()) { + for (RuntimeRange destinationRange : senderRange.destinations) { + dependentReactionsCache.addAll(destinationRange.instance.dependentReactions); + } } - return dependsOnReactionsCache; + } } - - /** - * Return a set of levels that runtime instances of this reaction have. - * A ReactionInstance may have more than one level if it lies within - * a bank and its dependencies on other reactions pass through multiports. - */ - public Set getLevels() { - Set result = new LinkedHashSet<>(); - // Force calculation of levels if it has not been done. - // FIXME: Comment out this as I think it is redundant. - // If it is NOT redundant then deadline propagation is not correct - // parent.assignLevels(); - for (Runtime runtime : runtimeInstances) { - result.add(runtime.level); - } - return result; + return dependentReactionsCache; + } + + /** + * Return the set of immediate upstream reactions, which are reactions that send data to this one + * plus at most one reaction in the same reactor whose definition immediately precedes the + * definition of this one (unless this reaction is unordered). + */ + public Set dependsOnReactions() { + // Cache the result. + if (dependsOnReactionsCache != null) return dependsOnReactionsCache; + dependsOnReactionsCache = new LinkedHashSet<>(); + + // First, add the previous lexical reaction, if appropriate. + if (!isUnordered && index > 0) { + // Find the previous ordered reaction in the parent's reaction list. + int earlierIndex = index - 1; + ReactionInstance earlierOrderedReaction = parent.reactions.get(earlierIndex); + while (earlierOrderedReaction.isUnordered && --earlierIndex >= 0) { + earlierOrderedReaction = parent.reactions.get(earlierIndex); + } + if (earlierIndex >= 0) { + dependsOnReactionsCache.add(parent.reactions.get(index - 1)); + } } - /** - * Return a set of deadlines that runtime instances of this reaction have. - * A ReactionInstance may have more than one deadline if it lies within. - */ - public Set getInferredDeadlines() { - Set result = new LinkedHashSet<>(); - for (Runtime runtime : runtimeInstances) { - result.add(runtime.deadline); + // Next, add reactions that send data to this one. + for (TriggerInstance source : sources) { + if (source instanceof PortInstance) { + // First, add reactions that send data through an intermediate port. + for (RuntimeRange senderRange : ((PortInstance) source).eventualSources()) { + dependsOnReactionsCache.addAll(senderRange.instance.dependsOnReactions); } - return result; + // Then, add reactions that send directly to this port. + dependsOnReactionsCache.addAll(source.dependsOnReactions); + } } - - - /** - * Return a list of levels that runtime instances of this reaction have. - * The size of this list is the total number of runtime instances. - * A ReactionInstance may have more than one level if it lies within - * a bank and its dependencies on other reactions pass through multiports. - */ - public List getLevelsList() { - List result = new LinkedList<>(); - // Force calculation of levels if it has not been done. - // FIXME: Comment out this as I think it is redundant. - // If it is NOT redundant then deadline propagation is not correct - // parent.assignLevels(); - for (Runtime runtime : runtimeInstances) { - result.add(runtime.level); - } - return result; + return dependsOnReactionsCache; + } + + /** + * Return a set of levels that runtime instances of this reaction have. A ReactionInstance may + * have more than one level if it lies within a bank and its dependencies on other reactions pass + * through multiports. + */ + public Set getLevels() { + Set result = new LinkedHashSet<>(); + // Force calculation of levels if it has not been done. + // FIXME: Comment out this as I think it is redundant. + // If it is NOT redundant then deadline propagation is not correct + // parent.assignLevels(); + for (Runtime runtime : runtimeInstances) { + result.add(runtime.level); } - - /** - * Return a list of the deadlines that runtime instances of this reaction have. - * The size of this list is the total number of runtime instances. - * A ReactionInstance may have more than one deadline if it lies within - */ - public List getInferredDeadlinesList() { - List result = new LinkedList<>(); - for (Runtime runtime : runtimeInstances) { - result.add(runtime.deadline); - } - return result; + return result; + } + + /** + * Return a set of deadlines that runtime instances of this reaction have. A ReactionInstance may + * have more than one deadline if it lies within. + */ + public Set getInferredDeadlines() { + Set result = new LinkedHashSet<>(); + for (Runtime runtime : runtimeInstances) { + result.add(runtime.deadline); } - - - /** - * Return the name of this reaction, which is 'reaction_n', - * where n is replaced by the reaction index. - * @return The name of this reaction. - */ - @Override - public String getName() { - return "reaction_" + this.index; + return result; + } + + /** + * Return a list of levels that runtime instances of this reaction have. The size of this list is + * the total number of runtime instances. A ReactionInstance may have more than one level if it + * lies within a bank and its dependencies on other reactions pass through multiports. + */ + public List getLevelsList() { + List result = new LinkedList<>(); + // Force calculation of levels if it has not been done. + // FIXME: Comment out this as I think it is redundant. + // If it is NOT redundant then deadline propagation is not correct + // parent.assignLevels(); + for (Runtime runtime : runtimeInstances) { + result.add(runtime.level); } - - /** - * Return an array of runtime instances of this reaction in a - * natural order, defined as follows. The position within the - * returned list of the runtime instance is given by a mixed-radix - * number where the low-order digit is the bank index within the - * container reactor (or {@code 0} if it is not a bank), the second low order - * digit is the bank index of the container's container (or {@code 0} if - * it is not a bank), etc., until the container that is directly - * contained by the top level (the top-level reactor need not be - * included because its index is always {@code 0}). - * - * The size of the returned array is the product of the widths of all of the - * container {@link ReactorInstance} objects. If none of these is a bank, - * then the size will be {@code 1}. - * - * This method creates this array the first time it is called, but then - * holds on to it. The array is used by {@link ReactionInstanceGraph} - * to determine and record levels and deadline for runtime instances - * of reactors. - */ - public List getRuntimeInstances() { - if (runtimeInstances != null) return runtimeInstances; - int size = parent.getTotalWidth(); - // If the width cannot be determined, assume there is only one instance. - if (size < 0) size = 1; - runtimeInstances = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - Runtime r = new Runtime(); - r.id = i; - if (declaredDeadline != null) { - r.deadline = declaredDeadline.maxDelay; - } - runtimeInstances.add(r); - } - return runtimeInstances; + return result; + } + + /** + * Return a list of the deadlines that runtime instances of this reaction have. The size of this + * list is the total number of runtime instances. A ReactionInstance may have more than one + * deadline if it lies within + */ + public List getInferredDeadlinesList() { + List result = new LinkedList<>(); + for (Runtime runtime : runtimeInstances) { + result.add(runtime.deadline); } - - /** - * Purge 'portInstance' from this reaction, removing it from the list - * of triggers, sources, effects, and reads. Note that this leaves - * the runtime instances intact, including their level information. - */ - public void removePortInstance(PortInstance portInstance) { - this.triggers.remove(portInstance); - this.sources.remove(portInstance); - this.effects.remove(portInstance); - this.reads.remove(portInstance); - clearCaches(false); - portInstance.clearCaches(); + return result; + } + + /** + * Return the name of this reaction, which is 'reaction_n', where n is replaced by the reaction + * index. + * + * @return The name of this reaction. + */ + @Override + public String getName() { + return "reaction_" + this.index; + } + + /** + * Return an array of runtime instances of this reaction in a natural order, defined as + * follows. The position within the returned list of the runtime instance is given by a + * mixed-radix number where the low-order digit is the bank index within the container reactor (or + * {@code 0} if it is not a bank), the second low order digit is the bank index of the container's + * container (or {@code 0} if it is not a bank), etc., until the container that is directly + * contained by the top level (the top-level reactor need not be included because its index is + * always {@code 0}). + * + *

    The size of the returned array is the product of the widths of all of the container {@link + * ReactorInstance} objects. If none of these is a bank, then the size will be {@code 1}. + * + *

    This method creates this array the first time it is called, but then holds on to it. The + * array is used by {@link ReactionInstanceGraph} to determine and record levels and deadline for + * runtime instances of reactors. + */ + public List getRuntimeInstances() { + if (runtimeInstances != null) return runtimeInstances; + int size = parent.getTotalWidth(); + // If the width cannot be determined, assume there is only one instance. + if (size < 0) size = 1; + runtimeInstances = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + Runtime r = new Runtime(); + r.id = i; + if (declaredDeadline != null) { + r.deadline = declaredDeadline.maxDelay; + } + runtimeInstances.add(r); } - - /** - * Return a descriptive string. - */ - @Override - public String toString() { - return getName() + " of " + parent.getFullName(); + return runtimeInstances; + } + + /** + * Purge 'portInstance' from this reaction, removing it from the list of triggers, sources, + * effects, and reads. Note that this leaves the runtime instances intact, including their level + * information. + */ + public void removePortInstance(PortInstance portInstance) { + this.triggers.remove(portInstance); + this.sources.remove(portInstance); + this.effects.remove(portInstance); + this.reads.remove(portInstance); + clearCaches(false); + portInstance.clearCaches(); + } + + /** Return a descriptive string. */ + @Override + public String toString() { + return getName() + " of " + parent.getFullName(); + } + + /** + * Determine logical execution time for each reaction during compile time based on immediate + * downstream logical delays (after delays and actions) and label each reaction with the minimum + * of all such delays. + */ + public TimeValue assignLogicalExecutionTime() { + if (this.let != null) { + return this.let; } - /** - * Determine logical execution time for each reaction during compile - * time based on immediate downstream logical delays (after delays and actions) - * and label each reaction with the minimum of all such delays. - */ - public TimeValue assignLogicalExecutionTime() { - if (this.let != null) { - return this.let; - } - - if (this.parent.isGeneratedDelay()) { - return this.let = TimeValue.ZERO; - } + if (this.parent.isGeneratedDelay()) { + return this.let = TimeValue.ZERO; + } - TimeValue let = null; - - // Iterate over effect and find minimum delay. - for (TriggerInstance effect : effects) { - if (effect instanceof PortInstance) { - var afters = this.parent.getParent().children.stream().filter(c -> { - if (c.isGeneratedDelay()) { - return c.inputs.get(0).getDependsOnPorts().get(0).instance - .equals((PortInstance) effect); - } - return false; - }).map(c -> c.actions.get(0).getMinDelay()) - .min(TimeValue::compare); - - if (afters.isPresent()) { - if (let == null) { - let = afters.get(); - } else { - let = TimeValue.min(afters.get(), let); - } - } - } else if (effect instanceof ActionInstance) { - var action = ((ActionInstance) effect).getMinDelay(); - if (let == null) { - let = action; - } else { - let = TimeValue.min(action, let); - } - } + TimeValue let = null; + + // Iterate over effect and find minimum delay. + for (TriggerInstance effect : effects) { + if (effect instanceof PortInstance) { + var afters = + this.parent.getParent().children.stream() + .filter( + c -> { + if (c.isGeneratedDelay()) { + return c.inputs + .get(0) + .getDependsOnPorts() + .get(0) + .instance + .equals((PortInstance) effect); + } + return false; + }) + .map(c -> c.actions.get(0).getMinDelay()) + .min(TimeValue::compare); + + if (afters.isPresent()) { + if (let == null) { + let = afters.get(); + } else { + let = TimeValue.min(afters.get(), let); + } } - + } else if (effect instanceof ActionInstance) { + var action = ((ActionInstance) effect).getMinDelay(); if (let == null) { - let = TimeValue.ZERO; + let = action; + } else { + let = TimeValue.min(action, let); } - return this.let = let; + } } - ////////////////////////////////////////////////////// - //// Private variables. - - /** Cache of the set of downstream reactions. */ - private Set dependentReactionsCache; - - /** Cache of the set of upstream reactions. */ - private Set dependsOnReactionsCache; - - /** - * Array of runtime instances of this reaction. - * This has length 1 unless the reaction is contained - * by one or more banks. Suppose that this reaction - * has depth 3, with full name r0.r1.r2.r. The top-level - * reactor is r0, which contains r1, which contains r2, - * which contains this reaction r. Suppose the widths - * of the containing reactors are w0, w1, and w2, and - * we are interested in the instance at bank indexes - * b0, b1, and b2. That instance is in this array at - * location given by the natural ordering, which - * is the mixed radix number b2%w2; b1%w1. - */ - private List runtimeInstances; - - private TimeValue let = null; - - /////////////////////////////////////////////////////////// - //// Inner classes - - /** Inner class representing a runtime instance of a reaction. */ - public class Runtime { - public TimeValue deadline; - // If this reaction instance depends on exactly one upstream - // 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 int id; - public int level; - - public ReactionInstance getReaction() { - return ReactionInstance.this; - } - @Override - public String toString() { - String result = ReactionInstance.this + "(level: " + level; - if (deadline != null && deadline != TimeValue.MAX_VALUE) { - result += ", deadline: " + deadline; - } - if (dominating != null) { - result += ", dominating: " + dominating.getReaction(); - } - result += ")"; - return result; - } + if (let == null) { + let = TimeValue.ZERO; + } + return this.let = let; + } + + ////////////////////////////////////////////////////// + //// Private variables. + + /** Cache of the set of downstream reactions. */ + private Set dependentReactionsCache; + + /** Cache of the set of upstream reactions. */ + private Set dependsOnReactionsCache; + + /** + * Array of runtime instances of this reaction. This has length 1 unless the reaction is contained + * by one or more banks. Suppose that this reaction has depth 3, with full name r0.r1.r2.r. The + * top-level reactor is r0, which contains r1, which contains r2, which contains this reaction r. + * Suppose the widths of the containing reactors are w0, w1, and w2, and we are interested in the + * instance at bank indexes b0, b1, and b2. That instance is in this array at location given by + * the natural ordering, which is the mixed radix number b2%w2; b1%w1. + */ + private List runtimeInstances; + + private TimeValue let = null; + + /////////////////////////////////////////////////////////// + //// Inner classes + + /** Inner class representing a runtime instance of a reaction. */ + public class Runtime { + public TimeValue deadline; + // If this reaction instance depends on exactly one upstream + // 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 int id; + + public int level; + + public ReactionInstance getReaction() { + return ReactionInstance.this; + } - public Runtime() { - this.dominating = null; - this.id = 0; - this.level = 0; - if (ReactionInstance.this.declaredDeadline != null) { - this.deadline = ReactionInstance.this.declaredDeadline.maxDelay; - } else { - this.deadline = TimeValue.MAX_VALUE; - } - } + @Override + public String toString() { + String result = ReactionInstance.this + "(level: " + level; + if (deadline != null && deadline != TimeValue.MAX_VALUE) { + result += ", deadline: " + deadline; + } + if (dominating != null) { + result += ", dominating: " + dominating.getReaction(); + } + result += ")"; + return result; + } + + public Runtime() { + this.dominating = null; + this.id = 0; + this.level = 0; + if (ReactionInstance.this.declaredDeadline != null) { + this.deadline = ReactionInstance.this.declaredDeadline.maxDelay; + } else { + this.deadline = TimeValue.MAX_VALUE; + } } + } } diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index 4c5f3ec292..57d171e327 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -1,28 +1,28 @@ /** A graph that represents causality cycles formed by reaction instances. */ /************* -Copyright (c) 2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; @@ -31,359 +31,347 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.List; import java.util.Set; import java.util.stream.Collectors; - import org.lflang.generator.ReactionInstance.Runtime; import org.lflang.generator.c.CUtil; import org.lflang.graph.PrecedenceGraph; import org.lflang.lf.Variable; /** - * This class analyzes the dependencies between reaction runtime instances. - * For each ReactionInstance, there may be more than one runtime instance because - * the ReactionInstance may be nested within one or more banks. - * In the worst case, of these runtime instances may have distinct dependencies, - * and hence distinct levels in the graph. Moreover, some of these instances - * may be involved in cycles while others are not. + * This class analyzes the dependencies between reaction runtime instances. For each + * ReactionInstance, there may be more than one runtime instance because the ReactionInstance may be + * nested within one or more banks. In the worst case, of these runtime instances may have distinct + * dependencies, and hence distinct levels in the graph. Moreover, some of these instances may be + * involved in cycles while others are not. * - * Upon construction of this class, the runtime instances are created if necessary, - * stored each ReactionInstance, and assigned levels (maximum number of - * upstream reaction instances), deadlines, and single dominating reactions. + *

    Upon construction of this class, the runtime instances are created if necessary, stored each + * ReactionInstance, and assigned levels (maximum number of upstream reaction instances), deadlines, + * and single dominating reactions. * - * After creation, the resulting graph will be empty unless there are causality - * cycles, in which case, the resulting graph is a graph of runtime reaction - * instances that form cycles. + *

    After creation, the resulting graph will be empty unless there are causality cycles, in which + * case, the resulting graph is a graph of runtime reaction instances that form cycles. * * @author Marten Lohstroh * @author Edward A. Lee */ public class ReactionInstanceGraph extends PrecedenceGraph { - /** - * Create a new graph by traversing the maps in the named instances - * embedded in the hierarchy of the program. - */ - public ReactionInstanceGraph(ReactorInstance main) { - this.main = main; - rebuild(); - } - - /////////////////////////////////////////////////////////// - //// Public fields - - /** - * The main reactor instance that this graph is associated with. - */ - public final ReactorInstance main; - - /////////////////////////////////////////////////////////// - //// Public methods - - /** - * Rebuild this graph by clearing and repeating the traversal that - * adds all the nodes and edges. - */ - public void rebuild() { - this.clear(); - addNodesAndEdges(main); - - // FIXME: Use {@link TargetProperty#EXPORT_DEPENDENCY_GRAPH}. - // System.out.println(toDOT()); - - // Assign a level to each reaction. - // If there are cycles present in the graph, it will be detected here. - assignLevels(); - if (nodeCount() != 0) { - // The graph has cycles. - // main.reporter.reportError("Reactions form a cycle! " + toString()); - // Do not throw an exception so that cycle visualization can proceed. - // throw new InvalidSourceException("Reactions form a cycle!"); - } + /** + * Create a new graph by traversing the maps in the named instances embedded in the hierarchy of + * the program. + */ + public ReactionInstanceGraph(ReactorInstance main) { + this.main = main; + rebuild(); + } + + /////////////////////////////////////////////////////////// + //// Public fields + + /** The main reactor instance that this graph is associated with. */ + public final ReactorInstance main; + + /////////////////////////////////////////////////////////// + //// Public methods + + /** + * Rebuild this graph by clearing and repeating the traversal that adds all the nodes and edges. + */ + public void rebuild() { + this.clear(); + addNodesAndEdges(main); + + // FIXME: Use {@link TargetProperty#EXPORT_DEPENDENCY_GRAPH}. + // System.out.println(toDOT()); + + // Assign a level to each reaction. + // If there are cycles present in the graph, it will be detected here. + assignLevels(); + if (nodeCount() != 0) { + // The graph has cycles. + // main.reporter.reportError("Reactions form a cycle! " + toString()); + // Do not throw an exception so that cycle visualization can proceed. + // throw new InvalidSourceException("Reactions form a cycle!"); } - /** - * This function rebuilds the graph and propagates and assigns deadlines - * to all reactions. - */ - public void rebuildAndAssignDeadlines() { - this.clear(); - addNodesAndEdges(main); - assignInferredDeadlines(); - this.clear(); - } - - /* - * Get an array of non-negative integers representing the number of reactions - * per each level, where levels are indices of the array. - */ - public Integer[] getNumReactionsPerLevel() { - return numReactionsPerLevel.toArray(new Integer[0]); + } + /** This function rebuilds the graph and propagates and assigns deadlines to all reactions. */ + public void rebuildAndAssignDeadlines() { + this.clear(); + addNodesAndEdges(main); + assignInferredDeadlines(); + this.clear(); + } + + /* + * Get an array of non-negative integers representing the number of reactions + * per each level, where levels are indices of the array. + */ + public Integer[] getNumReactionsPerLevel() { + return numReactionsPerLevel.toArray(new Integer[0]); + } + + /** Return the max breadth of the reaction dependency graph */ + public int getBreadth() { + var maxBreadth = 0; + for (Integer breadth : numReactionsPerLevel) { + if (breadth > maxBreadth) { + maxBreadth = breadth; + } } + return maxBreadth; + } + + /////////////////////////////////////////////////////////// + //// Protected methods + + /** + * Add to the graph edges between the given reaction and all the reactions that depend on the + * specified port. + * + * @param port The port that the given reaction has as an effect. + * @param reaction The reaction to relate downstream reactions to. + */ + protected void addDownstreamReactions(PortInstance port, ReactionInstance reaction) { + // Use mixed-radix numbers to increment over the ranges. + List srcRuntimes = reaction.getRuntimeInstances(); + List eventualDestinations = port.eventualDestinations(); + + int srcDepth = (port.isInput()) ? 2 : 1; + + for (SendRange sendRange : eventualDestinations) { + for (RuntimeRange dstRange : sendRange.destinations) { + + int dstDepth = (dstRange.instance.isOutput()) ? 2 : 1; + MixedRadixInt dstRangePosition = dstRange.startMR(); + int dstRangeCount = 0; + + MixedRadixInt sendRangePosition = sendRange.startMR(); + int sendRangeCount = 0; + + while (dstRangeCount++ < dstRange.width) { + int srcIndex = sendRangePosition.get(srcDepth); + int dstIndex = dstRangePosition.get(dstDepth); + for (ReactionInstance dstReaction : dstRange.instance.dependentReactions) { + List dstRuntimes = dstReaction.getRuntimeInstances(); + Runtime srcRuntime = srcRuntimes.get(srcIndex); + Runtime dstRuntime = dstRuntimes.get(dstIndex); + // Only add this dependency if the reactions are not in modes at all or in the same mode + // or in modes of separate reactors + // This allows modes to break cycles since modes are always mutually exclusive. + if (srcRuntime.getReaction().getMode(true) == null + || dstRuntime.getReaction().getMode(true) == null + || srcRuntime.getReaction().getMode(true) == dstRuntime.getReaction().getMode(true) + || srcRuntime.getReaction().getParent() != dstRuntime.getReaction().getParent()) { + addEdge(dstRuntime, srcRuntime); + } - /** - * Return the max breadth of the reaction dependency graph - */ - public int getBreadth() { - var maxBreadth = 0; - for (Integer breadth: numReactionsPerLevel ) { - if (breadth > maxBreadth) { - maxBreadth = breadth; + // Propagate the deadlines, if any. + if (srcRuntime.deadline.compareTo(dstRuntime.deadline) > 0) { + srcRuntime.deadline = dstRuntime.deadline; } - } - return maxBreadth; - } - /////////////////////////////////////////////////////////// - //// Protected methods - - /** - * Add to the graph edges between the given reaction and all the reactions - * that depend on the specified port. - * @param port The port that the given reaction has as an effect. - * @param reaction The reaction to relate downstream reactions to. - */ - protected void addDownstreamReactions(PortInstance port, ReactionInstance reaction) { - // Use mixed-radix numbers to increment over the ranges. - List srcRuntimes = reaction.getRuntimeInstances(); - List eventualDestinations = port.eventualDestinations(); - - int srcDepth = (port.isInput())? 2 : 1; - - for (SendRange sendRange : eventualDestinations) { - for (RuntimeRange dstRange : sendRange.destinations) { - - int dstDepth = (dstRange.instance.isOutput())? 2 : 1; - MixedRadixInt dstRangePosition = dstRange.startMR(); - int dstRangeCount = 0; - - MixedRadixInt sendRangePosition = sendRange.startMR(); - int sendRangeCount = 0; - - while (dstRangeCount++ < dstRange.width) { - int srcIndex = sendRangePosition.get(srcDepth); - int dstIndex = dstRangePosition.get(dstDepth); - for (ReactionInstance dstReaction : dstRange.instance.dependentReactions) { - List dstRuntimes = dstReaction.getRuntimeInstances(); - Runtime srcRuntime = srcRuntimes.get(srcIndex); - Runtime dstRuntime = dstRuntimes.get(dstIndex); - // Only add this dependency if the reactions are not in modes at all or in the same mode or in modes of separate reactors - // This allows modes to break cycles since modes are always mutually exclusive. - if (srcRuntime.getReaction().getMode(true) == null || - dstRuntime.getReaction().getMode(true) == null || - srcRuntime.getReaction().getMode(true) == dstRuntime.getReaction().getMode(true) || - srcRuntime.getReaction().getParent() != dstRuntime.getReaction().getParent()) { - addEdge(dstRuntime, srcRuntime); - } - - // Propagate the deadlines, if any. - if (srcRuntime.deadline.compareTo(dstRuntime.deadline) > 0) { - srcRuntime.deadline = dstRuntime.deadline; - } - - // If this seems to be a single dominating reaction, set it. - // If another upstream reaction shows up, then this will be - // reset to null. - if (this.getUpstreamAdjacentNodes(dstRuntime).size() == 1 - && (dstRuntime.getReaction().isUnordered - || dstRuntime.getReaction().index == 0)) { - dstRuntime.dominating = srcRuntime; - } else { - dstRuntime.dominating = null; - } - } - dstRangePosition.increment(); - sendRangePosition.increment(); - sendRangeCount++; - if (sendRangeCount >= sendRange.width) { - // Reset to multicast. - sendRangeCount = 0; - sendRangePosition = sendRange.startMR(); - } - } + // If this seems to be a single dominating reaction, set it. + // If another upstream reaction shows up, then this will be + // reset to null. + if (this.getUpstreamAdjacentNodes(dstRuntime).size() == 1 + && (dstRuntime.getReaction().isUnordered || dstRuntime.getReaction().index == 0)) { + dstRuntime.dominating = srcRuntime; + } else { + dstRuntime.dominating = null; } + } + dstRangePosition.increment(); + sendRangePosition.increment(); + sendRangeCount++; + if (sendRangeCount >= sendRange.width) { + // Reset to multicast. + sendRangeCount = 0; + sendRangePosition = sendRange.startMR(); + } } + } } - - /** - * Build the graph by adding nodes and edges based on the given reactor - * instance. - * @param reactor The reactor on the basis of which to add nodes and edges. - */ - protected void addNodesAndEdges(ReactorInstance reactor) { - ReactionInstance previousReaction = null; - for (ReactionInstance reaction : reactor.reactions) { - List runtimes = reaction.getRuntimeInstances(); - - // Add reactions of this reactor. - for (Runtime runtime : runtimes) { - this.addNode(runtime); - } - - // If this is not an unordered reaction, then create a dependency - // on any previously defined reaction. - if (!reaction.isUnordered) { - // If there is an earlier reaction in this same reactor, then - // create a link in the reaction graph for all runtime instances. - if (previousReaction != null) { - List previousRuntimes = previousReaction.getRuntimeInstances(); - int count = 0; - for (Runtime runtime : runtimes) { - // Only add the reaction order edge if previous reaction is outside of a mode or both are in the same mode - // This allows modes to break cycles since modes are always mutually exclusive. - if (runtime.getReaction().getMode(true) == null || runtime.getReaction().getMode(true) == reaction.getMode(true)) { - this.addEdge(runtime, previousRuntimes.get(count)); - count++; - } - } - } - previousReaction = reaction; - } - - // Add downstream reactions. Note that this is sufficient. - // We don't need to also add upstream reactions because this reaction - // will be downstream of those upstream reactions. - for (TriggerInstance effect : reaction.effects) { - if (effect instanceof PortInstance) { - addDownstreamReactions((PortInstance)effect, reaction); - } + } + + /** + * Build the graph by adding nodes and edges based on the given reactor instance. + * + * @param reactor The reactor on the basis of which to add nodes and edges. + */ + protected void addNodesAndEdges(ReactorInstance reactor) { + ReactionInstance previousReaction = null; + for (ReactionInstance reaction : reactor.reactions) { + List runtimes = reaction.getRuntimeInstances(); + + // Add reactions of this reactor. + for (Runtime runtime : runtimes) { + this.addNode(runtime); + } + + // If this is not an unordered reaction, then create a dependency + // on any previously defined reaction. + if (!reaction.isUnordered) { + // If there is an earlier reaction in this same reactor, then + // create a link in the reaction graph for all runtime instances. + if (previousReaction != null) { + List previousRuntimes = previousReaction.getRuntimeInstances(); + int count = 0; + for (Runtime runtime : runtimes) { + // Only add the reaction order edge if previous reaction is outside of a mode or both + // are in the same mode + // This allows modes to break cycles since modes are always mutually exclusive. + if (runtime.getReaction().getMode(true) == null + || runtime.getReaction().getMode(true) == reaction.getMode(true)) { + this.addEdge(runtime, previousRuntimes.get(count)); + count++; } + } } - // Recursively add nodes and edges from contained reactors. - for (ReactorInstance child : reactor.children) { - addNodesAndEdges(child); + previousReaction = reaction; + } + + // Add downstream reactions. Note that this is sufficient. + // We don't need to also add upstream reactions because this reaction + // will be downstream of those upstream reactions. + for (TriggerInstance effect : reaction.effects) { + if (effect instanceof PortInstance) { + addDownstreamReactions((PortInstance) effect, reaction); } + } + } + // Recursively add nodes and edges from contained reactors. + for (ReactorInstance child : reactor.children) { + addNodesAndEdges(child); + } + } + + /////////////////////////////////////////////////////////// + //// Private fields + + /** + * Number of reactions per level, represented as a list of integers where the indices are the + * levels. + */ + private List numReactionsPerLevel = new ArrayList<>(List.of(0)); + + /////////////////////////////////////////////////////////// + //// Private methods + + /** + * Analyze the dependencies between reactions and assign each reaction instance a level. This + * method removes nodes from this graph as it assigns levels. Any remaining nodes are part of + * causality cycles. + * + *

    This procedure is based on Kahn's algorithm for topological sorting. Rather than + * establishing a total order, we establish a partial order. In this order, the level of each + * reaction is the least upper bound of the levels of the reactions it depends on. + */ + private void assignLevels() { + List start = new ArrayList<>(rootNodes()); + + // All root nodes start with level 0. + for (Runtime origin : start) { + origin.level = 0; } - /////////////////////////////////////////////////////////// - //// Private fields - - /** - * Number of reactions per level, represented as a list of - * integers where the indices are the levels. - */ - private List numReactionsPerLevel = new ArrayList<>(List.of(0)); - - /////////////////////////////////////////////////////////// - //// Private methods - - /** - * Analyze the dependencies between reactions and assign each reaction - * instance a level. This method removes nodes from this graph as it - * assigns levels. Any remaining nodes are part of causality cycles. - * - * This procedure is based on Kahn's algorithm for topological sorting. - * Rather than establishing a total order, we establish a partial order. - * In this order, the level of each reaction is the least upper bound of - * the levels of the reactions it depends on. - */ - private void assignLevels() { - List start = new ArrayList<>(rootNodes()); - - // All root nodes start with level 0. - for (Runtime origin : start) { - origin.level = 0; + // No need to do any of this if there are no root nodes; + // the graph must be cyclic. + while (!start.isEmpty()) { + Runtime origin = start.remove(0); + Set toRemove = new LinkedHashSet<>(); + Set downstreamAdjacentNodes = getDownstreamAdjacentNodes(origin); + + // Visit effect nodes. + for (Runtime effect : downstreamAdjacentNodes) { + // Stage edge between origin and effect for removal. + toRemove.add(effect); + + // Update level of downstream node. + effect.level = origin.level + 1; + } + // Remove visited edges. + for (Runtime effect : toRemove) { + removeEdge(effect, origin); + // If the effect node has no more incoming edges, + // then move it in the start set. + if (getUpstreamAdjacentNodes(effect).size() == 0) { + start.add(effect); } + } - // No need to do any of this if there are no root nodes; - // the graph must be cyclic. - while (!start.isEmpty()) { - Runtime origin = start.remove(0); - Set toRemove = new LinkedHashSet<>(); - Set downstreamAdjacentNodes = getDownstreamAdjacentNodes(origin); - - // Visit effect nodes. - for (Runtime effect : downstreamAdjacentNodes) { - // Stage edge between origin and effect for removal. - toRemove.add(effect); + // Remove visited origin. + removeNode(origin); - // Update level of downstream node. - effect.level = origin.level + 1; - } - // Remove visited edges. - for (Runtime effect : toRemove) { - removeEdge(effect, origin); - // If the effect node has no more incoming edges, - // then move it in the start set. - if (getUpstreamAdjacentNodes(effect).size() == 0) { - start.add(effect); - } - } - - // Remove visited origin. - removeNode(origin); - - // Update numReactionsPerLevel info - adjustNumReactionsPerLevel(origin.level, 1); - } + // Update numReactionsPerLevel info + adjustNumReactionsPerLevel(origin.level, 1); } - - /** - * This function assigns inferred deadlines to all the reactions in the graph. - * It is modeled after {@code assignLevels} but it starts at the leaf nodes and uses - * Kahns algorithm to build a reverse topologically sorted graph - * - */ - private void assignInferredDeadlines() { - List start = new ArrayList<>(leafNodes()); - - // All leaf nodes have deadline initialized to their declared deadline or MAX_VALUE - while (!start.isEmpty()) { - Runtime origin = start.remove(0); - Set toRemove = new LinkedHashSet<>(); - Set upstreamAdjacentNodes = getUpstreamAdjacentNodes(origin); - - // Visit effect nodes. - for (Runtime upstream : upstreamAdjacentNodes) { - // Stage edge between origin and upstream for removal. - toRemove.add(upstream); - - // Update deadline of upstream node if origins deadline is earlier. - if (origin.deadline.isEarlierThan(upstream.deadline)) { - upstream.deadline = origin.deadline; - } - } - // Remove visited edges. - for (Runtime upstream : toRemove) { - removeEdge(origin, upstream); - // If the upstream node has no more outgoing edges, - // then move it in the start set. - if (getDownstreamAdjacentNodes(upstream).size() == 0) { - start.add(upstream); - } - } - - // Remove visited origin. - removeNode(origin); + } + + /** + * This function assigns inferred deadlines to all the reactions in the graph. It is modeled after + * {@code assignLevels} but it starts at the leaf nodes and uses Kahns algorithm to build a + * reverse topologically sorted graph + */ + private void assignInferredDeadlines() { + List start = new ArrayList<>(leafNodes()); + + // All leaf nodes have deadline initialized to their declared deadline or MAX_VALUE + while (!start.isEmpty()) { + Runtime origin = start.remove(0); + Set toRemove = new LinkedHashSet<>(); + Set upstreamAdjacentNodes = getUpstreamAdjacentNodes(origin); + + // Visit effect nodes. + for (Runtime upstream : upstreamAdjacentNodes) { + // Stage edge between origin and upstream for removal. + toRemove.add(upstream); + + // Update deadline of upstream node if origins deadline is earlier. + if (origin.deadline.isEarlierThan(upstream.deadline)) { + upstream.deadline = origin.deadline; } - } - - /** - * Adjust {@link #numReactionsPerLevel} at index level by - * adding to the previously recorded number valueToAdd. - * If there is no previously recorded number for this level, then - * create one with index level and value valueToAdd. - * @param level The level. - * @param valueToAdd The value to add to the number of levels. - */ - private void adjustNumReactionsPerLevel(int level, int valueToAdd) { - if (numReactionsPerLevel.size() > level) { - numReactionsPerLevel.set(level, numReactionsPerLevel.get(level) + valueToAdd); - } else { - while (numReactionsPerLevel.size() < level) { - numReactionsPerLevel.add(0); - } - numReactionsPerLevel.add(valueToAdd); + } + // Remove visited edges. + for (Runtime upstream : toRemove) { + removeEdge(origin, upstream); + // If the upstream node has no more outgoing edges, + // then move it in the start set. + if (getDownstreamAdjacentNodes(upstream).size() == 0) { + start.add(upstream); } + } + + // Remove visited origin. + removeNode(origin); } + } + + /** + * Adjust {@link #numReactionsPerLevel} at index level by + * adding to the previously recorded number valueToAdd. + * If there is no previously recorded number for this level, then + * create one with index level and value valueToAdd. + * @param level The level. + * @param valueToAdd The value to add to the number of levels. + */ + private void adjustNumReactionsPerLevel(int level, int valueToAdd) { + if (numReactionsPerLevel.size() > level) { + numReactionsPerLevel.set(level, numReactionsPerLevel.get(level) + valueToAdd); + } else { + while (numReactionsPerLevel.size() < level) { + numReactionsPerLevel.add(0); + } + numReactionsPerLevel.add(valueToAdd); + } + } - /** - * Return the DOT (GraphViz) representation of the graph. - */ - @Override - public String toDOT() { - var dotRepresentation = new CodeBuilder(); - var edges = new StringBuilder(); + /** Return the DOT (GraphViz) representation of the graph. */ + @Override + public String toDOT() { + var dotRepresentation = new CodeBuilder(); + var edges = new StringBuilder(); - // Start the digraph with a left-write rank - dotRepresentation.pr( + // Start the digraph with a left-write rank + dotRepresentation.pr( """ digraph { rankdir=LF; @@ -392,49 +380,52 @@ public String toDOT() { edge [fontname=Times]; """); - var nodes = nodes(); - // Group nodes by levels - var groupedNodes = - nodes.stream() - .collect( - Collectors.groupingBy(it -> it.level) - ); - - dotRepresentation.indent(); - // For each level - for (var level : groupedNodes.keySet()) { - // Create a subgraph - dotRepresentation.pr("subgraph cluster_level_" + level + " {"); - dotRepresentation.pr(" graph [compound=True, label = \"level " + level + "\"];"); - - // Get the nodes at the current level - var currentLevelNodes = groupedNodes.get(level); - for (var node: currentLevelNodes) { - // Draw the node - var label = CUtil.getName(node.getReaction().getParent().tpr) + "." + node.getReaction().getName(); - // Need a positive number to name the nodes in GraphViz - var labelHashCode = label.hashCode() & 0xfffffff; - dotRepresentation.pr(" node_" + labelHashCode + " [label=\""+ label +"\"];"); - - // Draw the edges - var downstreamNodes = getDownstreamAdjacentNodes(node); - for (var downstreamNode: downstreamNodes) { - var downstreamLabel = CUtil.getName(downstreamNode.getReaction().getParent().tpr) + "." + downstreamNode.getReaction().getName(); - edges.append(" node_" + labelHashCode + " -> node_" + - (downstreamLabel.hashCode() & 0xfffffff) + ";\n" - ); - } - } - // Close the subgraph - dotRepresentation.pr("}"); + var nodes = nodes(); + // Group nodes by levels + var groupedNodes = nodes.stream().collect(Collectors.groupingBy(it -> it.level)); + + dotRepresentation.indent(); + // For each level + for (var level : groupedNodes.keySet()) { + // Create a subgraph + dotRepresentation.pr("subgraph cluster_level_" + level + " {"); + dotRepresentation.pr(" graph [compound=True, label = \"level " + level + "\"];"); + + // Get the nodes at the current level + var currentLevelNodes = groupedNodes.get(level); + for (var node : currentLevelNodes) { + // Draw the node + var label = + CUtil.getName(node.getReaction().getParent().tpr) + "." + node.getReaction().getName(); + // Need a positive number to name the nodes in GraphViz + var labelHashCode = label.hashCode() & 0xfffffff; + dotRepresentation.pr(" node_" + labelHashCode + " [label=\"" + label + "\"];"); + + // Draw the edges + var downstreamNodes = getDownstreamAdjacentNodes(node); + for (var downstreamNode : downstreamNodes) { + var downstreamLabel = + CUtil.getName(downstreamNode.getReaction().getParent().tpr) + + "." + + downstreamNode.getReaction().getName(); + edges.append( + " node_" + + labelHashCode + + " -> node_" + + (downstreamLabel.hashCode() & 0xfffffff) + + ";\n"); } - dotRepresentation.unindent(); - // Add the edges to the definition of the graph at the bottom - dotRepresentation.pr(edges); - // Close the digraph - dotRepresentation.pr("}"); - - // Return the DOT representation - return dotRepresentation.toString(); + } + // Close the subgraph + dotRepresentation.pr("}"); } + dotRepresentation.unindent(); + // Add the edges to the definition of the graph at the bottom + dotRepresentation.pr(edges); + // Close the digraph + dotRepresentation.pr("}"); + + // Return the DOT representation + return dotRepresentation.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index e40c3f988a..3bb132ce01 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -1,28 +1,28 @@ /** A data structure for a reactor instance. */ /************* -Copyright (c) 2019-2022, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2022, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; @@ -37,11 +37,10 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Map; import java.util.Optional; import java.util.Set; - -import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable; import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; @@ -68,1122 +67,1092 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.WidthSpec; /** - * Representation of a compile-time instance of a reactor. - * If the reactor is instantiated as a bank of reactors, or if any - * of its parents is instantiated as a bank of reactors, then one instance - * of this ReactorInstance class represents all the runtime instances within - * these banks. The {@link #getTotalWidth()} method returns the number of such - * runtime instances, which is the product of the bank width of this reactor - * instance and the bank widths of all of its parents. - * There is exactly one instance of this ReactorInstance class for each - * graphical rendition of a reactor in the diagram view. + * Representation of a compile-time instance of a reactor. If the reactor is instantiated as a bank + * of reactors, or if any of its parents is instantiated as a bank of reactors, then one instance of + * this ReactorInstance class represents all the runtime instances within these banks. The {@link + * #getTotalWidth()} method returns the number of such runtime instances, which is the product of + * the bank width of this reactor instance and the bank widths of all of its parents. There is + * exactly one instance of this ReactorInstance class for each graphical rendition of a reactor in + * the diagram view. * - * For the main reactor, which has no parent, once constructed, - * this object represents the entire Lingua Franca program. - * If the program has causality loops (a programming error), then - * {@link #hasCycles()} will return true and {@link #getCycles()} will - * return the ports and reaction instances involved in the cycles. + *

    For the main reactor, which has no parent, once constructed, this object represents the entire + * Lingua Franca program. If the program has causality loops (a programming error), then {@link + * #hasCycles()} will return true and {@link #getCycles()} will return the ports and reaction + * instances involved in the cycles. * * @author Marten Lohstroh * @author Edward A. Lee */ public class ReactorInstance extends NamedInstance { - /** - * Create a new instantiation hierarchy that starts with the given top-level reactor. - * @param reactor The top-level reactor. - * @param reporter The error reporter. - */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), null, reporter, -1); + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor. + * + * @param reactor The top-level reactor. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), null, reporter, -1); + } + + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor but only + * creates contained reactors up to the specified depth. + * + * @param reactor The top-level reactor. + * @param reporter The error reporter. + * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { + this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); + } + + /** + * Create a new instantiation with the specified parent. This constructor is here to allow for + * unit tests. It should not be used for any other purpose. + * + * @param reactor The top-level reactor. + * @param parent The parent reactor instance. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); + } + + ////////////////////////////////////////////////////// + //// Public fields. + + /** The action instances belonging to this reactor instance. */ + public List actions = new ArrayList<>(); + + /** + * The contained reactor instances, in order of declaration. For banks of reactors, this includes + * both the bank definition Reactor (which has bankIndex == -2) followed by each of the bank + * members (which have bankIndex >= 0). + */ + public final List children = new ArrayList<>(); + + /** The input port instances belonging to this reactor instance. */ + public final List inputs = new ArrayList<>(); + + /** The output port instances belonging to this reactor instance. */ + public final List outputs = new ArrayList<>(); + + /** The parameters of this instance. */ + public final List parameters = new ArrayList<>(); + + /** List of reaction instances for this reactor instance. */ + public final List reactions = new ArrayList<>(); + + /** List of watchdog instances for this reactor instance. */ + public final List watchdogs = new ArrayList<>(); + + /** The timer instances belonging to this reactor instance. */ + public final List timers = new ArrayList<>(); + + /** The mode instances belonging to this reactor instance. */ + public final List modes = new ArrayList<>(); + + /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ + public final ReactorDecl reactorDeclaration; + + /** The reactor after imports are resolve. */ + public final Reactor reactorDefinition; + + /** Indicator that this reactor has itself as a parent, an error condition. */ + public final boolean recursive; + + public TypeParameterizedReactor tpr; + + ////////////////////////////////////////////////////// + //// Public methods. + + /** + * Assign levels to all reactions within the same root as this reactor. The level of a reaction r + * is equal to the length of the longest chain of reactions that must have the opportunity to + * execute before r at each logical tag. This fails and returns false if a causality cycle exists. + * + *

    This method uses a variant of Kahn's algorithm, which is linear in V + E, where V is the + * number of vertices (reactions) and E is the number of edges (dependencies between reactions). + * + * @return An empty graph if successful and otherwise a graph with runtime reaction instances that + * form cycles. + */ + public ReactionInstanceGraph assignLevels() { + if (depth != 0) return root().assignLevels(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); } - - /** - * Create a new instantiation hierarchy that starts with the given top-level reactor - * but only creates contained reactors up to the specified depth. - * @param reactor The top-level reactor. - * @param reporter The error reporter. - * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. - */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { - this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); + return cachedReactionLoopGraph; + } + + /** + * This function assigns/propagates deadlines through the Reaction Instance Graph. It performs + * Kahn's algorithm in reverse, starting from the leaf nodes and propagates deadlines upstream. To + * reduce cost, it should only be invoked when there are user-specified deadlines in the program. + * + * @return + */ + public ReactionInstanceGraph assignDeadlines() { + if (depth != 0) return root().assignDeadlines(); + if (cachedReactionLoopGraph == null) { + cachedReactionLoopGraph = new ReactionInstanceGraph(this); } - - /** - * Create a new instantiation with the specified parent. - * This constructor is here to allow for unit tests. - * It should not be used for any other purpose. - * @param reactor The top-level reactor. - * @param parent The parent reactor instance. - * @param reporter The error reporter. - */ - public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); + cachedReactionLoopGraph.rebuildAndAssignDeadlines(); + return cachedReactionLoopGraph; + } + + /** + * Return the instance of a child rector created by the specified definition or null if there is + * none. + * + * @param definition The definition of the child reactor ("new" statement). + */ + public ReactorInstance getChildReactorInstance(Instantiation definition) { + for (ReactorInstance child : this.children) { + if (child.definition == definition) { + return child; + } } - - ////////////////////////////////////////////////////// - //// Public fields. - - /** The action instances belonging to this reactor instance. */ - public List actions = new ArrayList<>(); - - /** - * The contained reactor instances, in order of declaration. - * For banks of reactors, this includes both the bank definition - * Reactor (which has bankIndex == -2) followed by each of the - * bank members (which have bankIndex >= 0). - */ - public final List children = new ArrayList<>(); - - /** The input port instances belonging to this reactor instance. */ - public final List inputs = new ArrayList<>(); - - /** The output port instances belonging to this reactor instance. */ - public final List outputs = new ArrayList<>(); - - /** The parameters of this instance. */ - public final List parameters = new ArrayList<>(); - - /** List of reaction instances for this reactor instance. */ - public final List reactions = new ArrayList<>(); - - /** List of watchdog instances for this reactor instance. */ - public final List watchdogs = new ArrayList<>(); - - /** The timer instances belonging to this reactor instance. */ - public final List timers = new ArrayList<>(); - - /** The mode instances belonging to this reactor instance. */ - public final List modes = new ArrayList<>(); - - /** The reactor declaration in the AST. This is either an import or Reactor declaration. */ - public final ReactorDecl reactorDeclaration; - - /** The reactor after imports are resolve. */ - public final Reactor reactorDefinition; - - /** Indicator that this reactor has itself as a parent, an error condition. */ - public final boolean recursive; - - public TypeParameterizedReactor tpr; - - ////////////////////////////////////////////////////// - //// Public methods. - - /** - * Assign levels to all reactions within the same root as this - * reactor. The level of a reaction r is equal to the length of the - * longest chain of reactions that must have the opportunity to - * execute before r at each logical tag. This fails and returns - * false if a causality cycle exists. - * - * This method uses a variant of Kahn's algorithm, which is linear - * in V + E, where V is the number of vertices (reactions) and E - * is the number of edges (dependencies between reactions). - * - * @return An empty graph if successful and otherwise a graph - * with runtime reaction instances that form cycles. - */ - public ReactionInstanceGraph assignLevels() { - if (depth != 0) return root().assignLevels(); - if (cachedReactionLoopGraph == null) { - cachedReactionLoopGraph = new ReactionInstanceGraph(this); - } - return cachedReactionLoopGraph; - } - - /** - * This function assigns/propagates deadlines through the Reaction Instance Graph. - * It performs Kahn's algorithm in reverse, starting from the leaf nodes and - * propagates deadlines upstream. To reduce cost, it should only be invoked when - * there are user-specified deadlines in the program. - * @return - */ - public ReactionInstanceGraph assignDeadlines() { - if (depth != 0) return root().assignDeadlines(); - if (cachedReactionLoopGraph == null) { - cachedReactionLoopGraph = new ReactionInstanceGraph(this); - } - cachedReactionLoopGraph.rebuildAndAssignDeadlines(); - return cachedReactionLoopGraph; + return null; + } + + /** + * Clear any cached data in this reactor and its children. This is useful if a mutation has been + * realized. + */ + public void clearCaches() { + clearCaches(true); + } + + /** + * Clear any cached data in this reactor and its children. This is useful if a mutation has been + * realized. + * + * @param includingRuntimes If false, leave the runtime instances of reactions intact. This is + * useful for federated execution where levels are computed using the top-level connections, + * but then those connections are discarded. + */ + public void clearCaches(boolean includingRuntimes) { + if (includingRuntimes) cachedReactionLoopGraph = null; + for (ReactorInstance child : children) { + child.clearCaches(includingRuntimes); } - - /** - * Return the instance of a child rector created by the specified - * definition or null if there is none. - * @param definition The definition of the child reactor ("new" statement). - */ - public ReactorInstance getChildReactorInstance(Instantiation definition) { - for (ReactorInstance child : this.children) { - if (child.definition == definition) { - return child; - } - } - return null; + for (PortInstance port : inputs) { + port.clearCaches(); } - - /** - * Clear any cached data in this reactor and its children. - * This is useful if a mutation has been realized. - */ - public void clearCaches() { - clearCaches(true); + for (PortInstance port : outputs) { + port.clearCaches(); } - - /** - * Clear any cached data in this reactor and its children. - * This is useful if a mutation has been realized. - * @param includingRuntimes If false, leave the runtime instances of reactions intact. - * This is useful for federated execution where levels are computed using - * the top-level connections, but then those connections are discarded. - */ - public void clearCaches(boolean includingRuntimes) { - if (includingRuntimes) cachedReactionLoopGraph = null; - for (ReactorInstance child : children) { - child.clearCaches(includingRuntimes); - } - for (PortInstance port : inputs) { - port.clearCaches(); - } - for (PortInstance port : outputs) { - port.clearCaches(); - } - for (ReactionInstance reaction : reactions) { - reaction.clearCaches(includingRuntimes); - } - cachedCycles = null; + for (ReactionInstance reaction : reactions) { + reaction.clearCaches(includingRuntimes); } - - /** - * Return the set of ReactionInstance and PortInstance that form causality - * loops in the topmost parent reactor in the instantiation hierarchy. This will return an - * empty set if there are no causality loops. - */ - public Set> getCycles() { - if (depth != 0) return root().getCycles(); - if (cachedCycles != null) return cachedCycles; - cachedCycles = new LinkedHashSet<>(); - - ReactionInstanceGraph reactionRuntimes = assignLevels(); - if (reactionRuntimes.nodes().size() > 0) { - Set reactions = new LinkedHashSet<>(); - Set ports = new LinkedHashSet<>(); - // There are cycles. But the nodes set includes not - // just the cycles, but also nodes that are downstream of the - // cycles. Use Tarjan's algorithm to get just the cycles. - var cycleNodes = reactionRuntimes.getCycles(); - for (var cycle : cycleNodes) { - for (ReactionInstance.Runtime runtime : cycle) { - reactions.add(runtime.getReaction()); - } - } - // Need to figure out which ports are involved in the cycles. - // It may not be all ports that depend on this reaction. - for (ReactionInstance r : reactions) { - for (TriggerInstance p : r.effects) { - if (p instanceof PortInstance) { - findPaths((PortInstance)p, reactions, ports); - } - } - } - cachedCycles.addAll(reactions); - cachedCycles.addAll(ports); + cachedCycles = null; + } + + /** + * Return the set of ReactionInstance and PortInstance that form causality loops in the topmost + * parent reactor in the instantiation hierarchy. This will return an empty set if there are no + * causality loops. + */ + public Set> getCycles() { + if (depth != 0) return root().getCycles(); + if (cachedCycles != null) return cachedCycles; + cachedCycles = new LinkedHashSet<>(); + + ReactionInstanceGraph reactionRuntimes = assignLevels(); + if (reactionRuntimes.nodes().size() > 0) { + Set reactions = new LinkedHashSet<>(); + Set ports = new LinkedHashSet<>(); + // There are cycles. But the nodes set includes not + // just the cycles, but also nodes that are downstream of the + // cycles. Use Tarjan's algorithm to get just the cycles. + var cycleNodes = reactionRuntimes.getCycles(); + for (var cycle : cycleNodes) { + for (ReactionInstance.Runtime runtime : cycle) { + reactions.add(runtime.getReaction()); } - - return cachedCycles; - } - - /** - * Return the specified input by name or null if there is no such input. - * @param name The input name. - */ - public PortInstance getInput(String name) { - for (PortInstance port: inputs) { - if (port.getName().equals(name)) { - return port; - } + } + // Need to figure out which ports are involved in the cycles. + // It may not be all ports that depend on this reaction. + for (ReactionInstance r : reactions) { + for (TriggerInstance p : r.effects) { + if (p instanceof PortInstance) { + findPaths((PortInstance) p, reactions, ports); + } } - return null; + } + cachedCycles.addAll(reactions); + cachedCycles.addAll(ports); } - /** - * Override the base class to append [i_d], where d is the depth, - * if this reactor is in a bank of reactors. - * @return The name of this instance. - */ - @Override - public String getName() { - return this.definition.getName(); + return cachedCycles; + } + + /** + * Return the specified input by name or null if there is no such input. + * + * @param name The input name. + */ + public PortInstance getInput(String name) { + for (PortInstance port : inputs) { + if (port.getName().equals(name)) { + return port; + } } - - /** - * @see NamedInstance#uniqueID() - * - * Append {@code _main} to the name of the main reactor to allow instantiations - * within that reactor to have the same name. - */ - @Override - public String uniqueID() { - if (this.isMainOrFederated()) { - if (reactorDefinition.isFederated() && !super.uniqueID().startsWith("federate__")) return "federate__" + super.uniqueID() + "_main"; - return super.uniqueID() + "_main"; - } - return super.uniqueID(); + return null; + } + + /** + * Override the base class to append [i_d], where d is the depth, if this reactor is in a bank of + * reactors. + * + * @return The name of this instance. + */ + @Override + public String getName() { + return this.definition.getName(); + } + + /** + * @see NamedInstance#uniqueID() + *

    Append {@code _main} to the name of the main reactor to allow instantiations within that + * reactor to have the same name. + */ + @Override + public String uniqueID() { + if (this.isMainOrFederated()) { + if (reactorDefinition.isFederated() && !super.uniqueID().startsWith("federate__")) + return "federate__" + super.uniqueID() + "_main"; + return super.uniqueID() + "_main"; } - - /** - * Return the specified output by name or null if there is no such output. - * @param name The output name. - */ - public PortInstance getOutput(String name) { - for (PortInstance port: outputs) { - if (port.getName().equals(name)) { - return port; - } - } - return null; + return super.uniqueID(); + } + + /** + * Return the specified output by name or null if there is no such output. + * + * @param name The output name. + */ + public PortInstance getOutput(String name) { + for (PortInstance port : outputs) { + if (port.getName().equals(name)) { + return port; + } } - - /** - * Return a parameter matching the specified name if the reactor has one - * and otherwise return null. - * @param name The parameter name. - */ - public ParameterInstance getParameter(String name) { - for (ParameterInstance parameter: parameters) { - if (parameter.getName().equals(name)) { - return parameter; - } - } - return null; + return null; + } + + /** + * Return a parameter matching the specified name if the reactor has one and otherwise return + * null. + * + * @param name The parameter name. + */ + public ParameterInstance getParameter(String name) { + for (ParameterInstance parameter : parameters) { + if (parameter.getName().equals(name)) { + return parameter; + } } - - /** - * Return the startup trigger or null if not used in any reaction. - */ - public TriggerInstance getStartupTrigger() { - return builtinTriggers.get(BuiltinTrigger.STARTUP); + return null; + } + + /** Return the startup trigger or null if not used in any reaction. */ + public TriggerInstance getStartupTrigger() { + return builtinTriggers.get(BuiltinTrigger.STARTUP); + } + + /** Return the shutdown trigger or null if not used in any reaction. */ + public TriggerInstance getShutdownTrigger() { + return builtinTriggers.get(BuiltinTrigger.SHUTDOWN); + } + + /** + * If this reactor is a bank or any of its parents is a bank, return the total number of runtime + * instances, which is the product of the widths of all the parents. Return -1 if the width cannot + * be determined. + */ + public int getTotalWidth() { + return getTotalWidth(0); + } + + /** + * If this reactor is a bank or any of its parents is a bank, return the total number of runtime + * instances, which is the product of the widths of all the parents. Return -1 if the width cannot + * be determined. + * + * @param atDepth The depth at which to determine the width. Use 0 to get the total number of + * instances. Use 1 to get the number of instances within a single top-level bank member (this + * is useful for federates). + */ + public int getTotalWidth(int atDepth) { + if (width <= 0) return -1; + if (depth <= atDepth) return 1; + int result = width; + ReactorInstance p = parent; + while (p != null && p.depth > atDepth) { + if (p.width <= 0) return -1; + result *= p.width; + p = p.parent; } - - /** - * Return the shutdown trigger or null if not used in any reaction. - */ - public TriggerInstance getShutdownTrigger() { - return builtinTriggers.get(BuiltinTrigger.SHUTDOWN); + return result; + } + + /** + * Return the trigger instances (input ports, timers, and actions that trigger reactions) + * belonging to this reactor instance. + */ + public Set> getTriggers() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); } - - /** - * If this reactor is a bank or any of its parents is a bank, - * return the total number of runtime instances, which is the product - * of the widths of all the parents. - * Return -1 if the width cannot be determined. - */ - public int getTotalWidth() { - return getTotalWidth(0); + return triggers; + } + + /** + * Return the trigger instances (input ports, timers, and actions that trigger reactions) together + * the ports that the reaction reads but that don't trigger it. + * + * @return The trigger instances belonging to this reactor instance. + */ + public Set> getTriggersAndReads() { + // FIXME: Cache this. + var triggers = new LinkedHashSet>(); + for (ReactionInstance reaction : this.reactions) { + triggers.addAll(reaction.triggers); + triggers.addAll(reaction.reads); } + return triggers; + } + + /** Return true if the top-level parent of this reactor has causality cycles. */ + public boolean hasCycles() { + return assignLevels().nodeCount() != 0; + } + + /** + * Given a parameter definition for this reactor, return the initial integer value of the + * parameter. If the parameter is overridden when instantiating this reactor or any of its + * containing reactors, use that value. Otherwise, use the default value in the reactor + * definition. If the parameter cannot be found or its value is not an integer, return null. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * @return An integer value or null. + */ + public Integer initialIntParameterValue(Parameter parameter) { + return ASTUtils.initialValueInt(parameter, instantiations()); + } + + public Expression resolveParameters(Expression e) { + return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); + } + + private static final class ParameterInliner + extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { + static final ParameterInliner INSTANCE = new ParameterInliner(); - /** - * If this reactor is a bank or any of its parents is a bank, - * return the total number of runtime instances, which is the product - * of the widths of all the parents. - * Return -1 if the width cannot be determined. - * @param atDepth The depth at which to determine the width. - * Use 0 to get the total number of instances. - * Use 1 to get the number of instances within a single top-level - * bank member (this is useful for federates). - */ - public int getTotalWidth(int atDepth) { - if (width <= 0) return -1; - if (depth <= atDepth) return 1; - int result = width; - ReactorInstance p = parent; - while (p != null && p.depth > atDepth) { - if (p.width <= 0) return -1; - result *= p.width; - p = p.parent; + @Override + public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { + if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { + throw new IllegalArgumentException( + "Parameter " + + expr.getParameter().getName() + + " is not a parameter of reactor instance " + + instance.getName() + + "."); + } + + Optional assignment = + instance.definition.getParameters().stream() + .filter(it -> it.getLhs().equals(expr.getParameter())) + .findAny(); // There is at most one + + if (assignment.isPresent()) { + // replace the parameter with its value. + Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); + // recursively resolve parameters + return instance.getParent().resolveParameters(value); + } else { + // In that case use the default value. Default values + // cannot use parameter values, so they don't need to + // be recursively resolved. + Initializer init = expr.getParameter().getInit(); + Expression defaultValue = ASTUtils.asSingleExpr(init); + if (defaultValue == null) { + // this is a problem + return super.visitParameterRef(expr, instance); } - return result; + return defaultValue; + } } - - /** - * Return the trigger instances (input ports, timers, and actions - * that trigger reactions) belonging to this reactor instance. - */ - public Set> getTriggers() { - // FIXME: Cache this. - var triggers = new LinkedHashSet>(); - for (ReactionInstance reaction : this.reactions) { - triggers.addAll(reaction.triggers); + } + + /** + * Return a list of Instantiation objects for evaluating parameter values. The first object in the + * list is the AST Instantiation that created this reactor instance, the second is the AST + * instantiation that created the containing reactor instance, and so on until there are no more + * containing reactor instances. This will return an empty list if this reactor instance is at the + * top level (is main). + */ + public List instantiations() { + if (_instantiations == null) { + _instantiations = new ArrayList<>(); + if (definition != null) { + _instantiations.add(definition); + if (parent != null) { + _instantiations.addAll(parent.instantiations()); } - return triggers; + } } - - /** - * Return the trigger instances (input ports, timers, and actions - * that trigger reactions) together the ports that the reaction reads - * but that don't trigger it. - * - * @return The trigger instances belonging to this reactor instance. - */ - public Set> getTriggersAndReads() { - // FIXME: Cache this. - var triggers = new LinkedHashSet>(); - for (ReactionInstance reaction : this.reactions) { - triggers.addAll(reaction.triggers); - triggers.addAll(reaction.reads); - } - return triggers; + return _instantiations; + } + + /** + * Returns true if this is a bank of reactors. + * + * @return true if a reactor is a bank, false otherwise + */ + public boolean isBank() { + return definition.getWidthSpec() != null; + } + + /** + * Returns whether this is a main or federated reactor. + * + * @return true if reactor definition is marked as main or federated, false otherwise. + */ + public boolean isMainOrFederated() { + return reactorDefinition != null + && (reactorDefinition.isMain() || reactorDefinition.isFederated()); + } + + /** + * Return true if the specified reactor instance is either equal to this reactor instance or a + * parent of it. + * + * @param r The reactor instance. + */ + public boolean isParent(ReactorInstance r) { + ReactorInstance p = this; + while (p != null) { + if (p == r) return true; + p = p.getParent(); } - - /** - * Return true if the top-level parent of this reactor has causality cycles. - */ - public boolean hasCycles() { - return assignLevels().nodeCount() != 0; + return false; + } + + /////////////////////////////////////////////////// + //// Methods for finding instances in this reactor given an AST node. + + /** + * Return the action instance within this reactor instance corresponding to the specified action + * reference. + * + * @param action The action as an AST node. + * @return The corresponding action instance or null if the action does not belong to this + * reactor. + */ + public ActionInstance lookupActionInstance(Action action) { + for (ActionInstance actionInstance : actions) { + if (actionInstance.definition == action) { + return actionInstance; + } } - - /** - * Given a parameter definition for this reactor, return the initial integer - * value of the parameter. If the parameter is overridden when instantiating - * this reactor or any of its containing reactors, use that value. - * Otherwise, use the default value in the reactor definition. - * If the parameter cannot be found or its value is not an integer, return null. - * - * @param parameter The parameter definition (a syntactic object in the AST). - * - * @return An integer value or null. - */ - public Integer initialIntParameterValue(Parameter parameter) { - return ASTUtils.initialValueInt(parameter, instantiations()); + return null; + } + + /** + * Given a parameter definition, return the parameter instance corresponding to that definition, + * or null if there is no such instance. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * @return A parameter instance, or null if there is none. + */ + public ParameterInstance lookupParameterInstance(Parameter parameter) { + for (ParameterInstance param : parameters) { + if (param.definition == parameter) { + return param; + } } - - public Expression resolveParameters(Expression e) { - return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); + return null; + } + + /** + * Given a port definition, return the port instance corresponding to that definition, or null if + * there is no such instance. + * + * @param port The port definition (a syntactic object in the AST). + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(Port port) { + // Search one of the inputs and outputs sets. + List ports = null; + if (port instanceof Input) { + ports = this.inputs; + } else if (port instanceof Output) { + ports = this.outputs; } - - - private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { - static final ParameterInliner INSTANCE = new ParameterInliner(); - - @Override - public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { - if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { - throw new IllegalArgumentException("Parameter " - + expr.getParameter().getName() - + " is not a parameter of reactor instance " - + instance.getName() - + "." - ); - } - - Optional assignment = - instance.definition.getParameters().stream() - .filter(it -> it.getLhs().equals(expr.getParameter())) - .findAny(); // There is at most one - - if (assignment.isPresent()) { - // replace the parameter with its value. - Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); - // recursively resolve parameters - return instance.getParent().resolveParameters(value); - } else { - // In that case use the default value. Default values - // cannot use parameter values, so they don't need to - // be recursively resolved. - Initializer init = expr.getParameter().getInit(); - Expression defaultValue = ASTUtils.asSingleExpr(init); - if (defaultValue == null) { - // this is a problem - return super.visitParameterRef(expr, instance); - } - return defaultValue; - } - } + for (PortInstance portInstance : ports) { + if (portInstance.definition == port) { + return portInstance; + } } - - /** - * Return a list of Instantiation objects for evaluating parameter - * values. The first object in the list is the AST Instantiation - * that created this reactor instance, the second is the AST instantiation - * that created the containing reactor instance, and so on until there - * are no more containing reactor instances. This will return an empty - * list if this reactor instance is at the top level (is main). - */ - public List instantiations() { - if (_instantiations == null) { - _instantiations = new ArrayList<>(); - if (definition != null) { - _instantiations.add(definition); - if (parent != null) { - _instantiations.addAll(parent.instantiations()); - } - } - } - return _instantiations; + return null; + } + + /** + * Given a reference to a port belonging to this reactor instance, return the port instance. + * Return null if there is no such instance. + * + * @param reference The port reference. + * @return A port instance, or null if there is none. + */ + public PortInstance lookupPortInstance(VarRef reference) { + if (!(reference.getVariable() instanceof Port)) { + // Trying to resolve something that is not a port + return null; } - - /** - * Returns true if this is a bank of reactors. - * @return true if a reactor is a bank, false otherwise - */ - public boolean isBank() { - return definition.getWidthSpec() != null; + if (reference.getContainer() == null) { + // Handle local reference + return lookupPortInstance((Port) reference.getVariable()); + } else { + // Handle hierarchical reference + var containerInstance = getChildReactorInstance(reference.getContainer()); + if (containerInstance == null) return null; + return containerInstance.lookupPortInstance((Port) reference.getVariable()); } - - /** - * Returns whether this is a main or federated reactor. - * @return true if reactor definition is marked as main or federated, false otherwise. - */ - public boolean isMainOrFederated() { - return reactorDefinition != null - && (reactorDefinition.isMain() || reactorDefinition.isFederated()); + } + + /** + * Return the reaction instance within this reactor instance corresponding to the specified + * reaction. + * + * @param reaction The reaction as an AST node. + * @return The corresponding reaction instance or null if the reaction does not belong to this + * reactor. + */ + public ReactionInstance lookupReactionInstance(Reaction reaction) { + for (ReactionInstance reactionInstance : reactions) { + if (reactionInstance.definition == reaction) { + return reactionInstance; + } } - - /** - * Return true if the specified reactor instance is either equal to this - * reactor instance or a parent of it. - * @param r The reactor instance. - */ - public boolean isParent(ReactorInstance r) { - ReactorInstance p = this; - while (p != null) { - if (p == r) return true; - p = p.getParent(); - } - return false; + return null; + } + + /** + * Return the reactor instance within this reactor that has the specified instantiation. Note that + * this may be a bank of reactors. Return null if there is no such reactor instance. + */ + public ReactorInstance lookupReactorInstance(Instantiation instantiation) { + for (ReactorInstance reactorInstance : children) { + if (reactorInstance.definition == instantiation) { + return reactorInstance; + } } - - /////////////////////////////////////////////////// - //// Methods for finding instances in this reactor given an AST node. - - /** - * Return the action instance within this reactor - * instance corresponding to the specified action reference. - * @param action The action as an AST node. - * @return The corresponding action instance or null if the - * action does not belong to this reactor. - */ - public ActionInstance lookupActionInstance(Action action) { - for (ActionInstance actionInstance : actions) { - if (actionInstance.definition == action) { - return actionInstance; - } - } - return null; + return null; + } + + /** + * Return the timer instance within this reactor instance corresponding to the specified timer + * reference. + * + * @param timer The timer as an AST node. + * @return The corresponding timer instance or null if the timer does not belong to this reactor. + */ + public TimerInstance lookupTimerInstance(Timer timer) { + for (TimerInstance timerInstance : timers) { + if (timerInstance.definition == timer) { + return timerInstance; + } } - - /** - * Given a parameter definition, return the parameter instance - * corresponding to that definition, or null if there is - * no such instance. - * @param parameter The parameter definition (a syntactic object in the AST). - * @return A parameter instance, or null if there is none. - */ - public ParameterInstance lookupParameterInstance(Parameter parameter) { - for (ParameterInstance param : parameters) { - if (param.definition == parameter) { - return param; - } - } - return null; + return null; + } + + /** + * Returns the mode instance within this reactor instance corresponding to the specified mode + * reference. + * + * @param mode The mode as an AST node. + * @return The corresponding mode instance or null if the mode does not belong to this reactor. + */ + public ModeInstance lookupModeInstance(Mode mode) { + for (ModeInstance modeInstance : modes) { + if (modeInstance.definition == mode) { + return modeInstance; + } } - - /** - * Given a port definition, return the port instance - * corresponding to that definition, or null if there is - * no such instance. - * @param port The port definition (a syntactic object in the AST). - * @return A port instance, or null if there is none. - */ - public PortInstance lookupPortInstance(Port port) { - // Search one of the inputs and outputs sets. - List ports = null; - if (port instanceof Input) { - ports = this.inputs; - } else if (port instanceof Output) { - ports = this.outputs; + return null; + } + + /** Return a descriptive string. */ + @Override + public String toString() { + return "ReactorInstance " + getFullName(); + } + + /** + * Assuming that the given expression denotes a valid time, return a time value. + * + *

    If the value is given as a parameter reference, this will look up the precise time value + * assigned to this reactor instance. + */ + public TimeValue getTimeValue(Expression expr) { + Expression resolved = resolveParameters(expr); + return getLiteralTimeValue(resolved); + } + + ////////////////////////////////////////////////////// + //// Protected fields. + + /** The generator that created this reactor instance. */ + protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references + + /** The map of used built-in triggers. */ + protected Map> builtinTriggers = + new HashMap<>(); + + /** + * The LF syntax does not currently support declaring reactions unordered, but unordered reactions + * are created in the AST transformations handling federated communication and after delays. + * Unordered reactions can execute in any order and concurrently even though they are in the same + * reactor. FIXME: Remove this when the language provides syntax. + */ + protected Set unorderedReactions = new LinkedHashSet<>(); + + /** The nested list of instantiations that created this reactor instance. */ + protected List _instantiations; + + ////////////////////////////////////////////////////// + //// Protected methods. + + /** + * Create all the reaction instances of this reactor instance and record the dependencies and + * antidependencies between ports, actions, and timers and reactions. This also records the + * dependencies between reactions that follows from the order in which they are defined. + */ + protected void createReactionInstances() { + List reactions = ASTUtils.allReactions(reactorDefinition); + if (reactions != null) { + int count = 0; + + // Check for startup and shutdown triggers. + for (Reaction reaction : reactions) { + if (AttributeUtils.isUnordered(reaction)) { + unorderedReactions.add(reaction); } - for (PortInstance portInstance : ports) { - if (portInstance.definition == port) { - return portInstance; - } - } - return null; + // Create the reaction instance. + var reactionInstance = + new ReactionInstance(reaction, this, unorderedReactions.contains(reaction), count++); + + // Add the reaction instance to the map of reactions for this + // reactor. + this.reactions.add(reactionInstance); + } } - - /** - * Given a reference to a port belonging to this reactor - * instance, return the port instance. - * Return null if there is no such instance. - * @param reference The port reference. - * @return A port instance, or null if there is none. - */ - public PortInstance lookupPortInstance(VarRef reference) { - if (!(reference.getVariable() instanceof Port)) { - // Trying to resolve something that is not a port - return null; - } - if (reference.getContainer() == null) { - // Handle local reference - return lookupPortInstance((Port) reference.getVariable()); + } + + /** Returns the built-in trigger or create a new one if none exists. */ + protected TriggerInstance getOrCreateBuiltinTrigger( + BuiltinTriggerRef trigger) { + return builtinTriggers.computeIfAbsent( + trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + } + + /** Create all the watchdog instances of this reactor instance. */ + protected void createWatchdogInstances() { + List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); + if (watchdogs != null) { + for (Watchdog watchdog : watchdogs) { + // Create the watchdog instance. + var watchdogInstance = new WatchdogInstance(watchdog, this); + + // Add the watchdog instance to the list of watchdogs for this + // reactor. + this.watchdogs.add(watchdogInstance); + } + } + } + + //////////////////////////////////////// + //// Private constructors + + /** + * Create a runtime instance from the specified definition and with the specified parent that + * instantiated it. + * + * @param definition The instantiation statement in the AST. + * @param parent The parent, or null for the main rector. + * @param reporter An error reporter. + * @param desiredDepth The depth to which to expand the hierarchy. + */ + public ReactorInstance( + Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth) { + super(definition, parent); + this.reporter = reporter; + this.reactorDeclaration = definition.getReactorClass(); + this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); + this.tpr = new TypeParameterizedReactor(definition); + + // check for recursive instantiation + var currentParent = parent; + var foundSelfAsParent = false; + do { + if (currentParent != null) { + if (currentParent.reactorDefinition == this.reactorDefinition) { + foundSelfAsParent = true; + currentParent = null; // break } else { - // Handle hierarchical reference - var containerInstance = getChildReactorInstance(reference.getContainer()); - if (containerInstance == null) return null; - return containerInstance.lookupPortInstance((Port) reference.getVariable()); + currentParent = currentParent.parent; } - } + } + } while (currentParent != null); - /** - * Return the reaction instance within this reactor - * instance corresponding to the specified reaction. - * @param reaction The reaction as an AST node. - * @return The corresponding reaction instance or null if the - * reaction does not belong to this reactor. - */ - public ReactionInstance lookupReactionInstance(Reaction reaction) { - for (ReactionInstance reactionInstance : reactions) { - if (reactionInstance.definition == reaction) { - return reactionInstance; - } - } - return null; + this.recursive = foundSelfAsParent; + if (recursive) { + reporter.reportError(definition, "Recursive reactor instantiation."); } - /** - * Return the reactor instance within this reactor - * that has the specified instantiation. Note that this - * may be a bank of reactors. Return null if there - * is no such reactor instance. - */ - public ReactorInstance lookupReactorInstance(Instantiation instantiation) { - for (ReactorInstance reactorInstance : children) { - if (reactorInstance.definition == instantiation) { - return reactorInstance; - } - } - return null; - } - - /** - * Return the timer instance within this reactor - * instance corresponding to the specified timer reference. - * @param timer The timer as an AST node. - * @return The corresponding timer instance or null if the - * timer does not belong to this reactor. - */ - public TimerInstance lookupTimerInstance(Timer timer) { - for (TimerInstance timerInstance : timers) { - if (timerInstance.definition == timer) { - return timerInstance; - } - } - return null; + // If the reactor definition is null, give up here. Otherwise, diagram generation + // will fail an NPE. + if (reactorDefinition == null) { + reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); + return; } - /** Returns the mode instance within this reactor - * instance corresponding to the specified mode reference. - * @param mode The mode as an AST node. - * @return The corresponding mode instance or null if the - * mode does not belong to this reactor. - */ - public ModeInstance lookupModeInstance(Mode mode) { - for (ModeInstance modeInstance : modes) { - if (modeInstance.definition == mode) { - return modeInstance; - } - } - return null; - } + setInitialWidth(); - /** - * Return a descriptive string. - */ - @Override - public String toString() { - return "ReactorInstance " + getFullName(); + // Apply overrides and instantiate parameters for this reactor instance. + for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { + this.parameters.add(new ParameterInstance(parameter, this)); } - /** - * Assuming that the given expression denotes a valid time, return a time value. - * - * If the value is given as a parameter reference, this will look up the - * precise time value assigned to this reactor instance. - */ - public TimeValue getTimeValue(Expression expr) { - Expression resolved = resolveParameters(expr); - return getLiteralTimeValue(resolved); + // Instantiate inputs for this reactor instance + for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { + this.inputs.add(new PortInstance(inputDecl, this, reporter)); } - ////////////////////////////////////////////////////// - //// Protected fields. - - /** The generator that created this reactor instance. */ - protected ErrorReporter reporter; // FIXME: This accumulates a lot of redundant references - - /** The map of used built-in triggers. */ - protected Map> builtinTriggers = new HashMap<>(); - - /** - * The LF syntax does not currently support declaring reactions unordered, - * but unordered reactions are created in the AST transformations handling - * federated communication and after delays. Unordered reactions can execute - * in any order and concurrently even though they are in the same reactor. - * FIXME: Remove this when the language provides syntax. - */ - protected Set unorderedReactions = new LinkedHashSet<>(); - - /** The nested list of instantiations that created this reactor instance. */ - protected List _instantiations; - - ////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Create all the reaction instances of this reactor instance - * and record the dependencies and antidependencies - * between ports, actions, and timers and reactions. - * This also records the dependencies between reactions - * that follows from the order in which they are defined. - */ - protected void createReactionInstances() { - List reactions = ASTUtils.allReactions(reactorDefinition); - if (reactions != null) { - int count = 0; - - // Check for startup and shutdown triggers. - for (Reaction reaction : reactions) { - if (AttributeUtils.isUnordered(reaction)) { - unorderedReactions.add(reaction); - } - // Create the reaction instance. - var reactionInstance = new ReactionInstance(reaction, this, - unorderedReactions.contains(reaction), count++); - - // Add the reaction instance to the map of reactions for this - // reactor. - this.reactions.add(reactionInstance); - } - } + // Instantiate outputs for this reactor instance + for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { + this.outputs.add(new PortInstance(outputDecl, this, reporter)); } - /** - * Returns the built-in trigger or create a new one if none exists. - */ - protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { - return builtinTriggers.computeIfAbsent(trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + // Do not process content (except interface above) if recursive + if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { + // Instantiate children for this reactor instance. + // While doing this, assign an index offset to each. + for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { + var childInstance = new ReactorInstance(child, this, reporter, desiredDepth); + this.children.add(childInstance); + } + + // Instantiate timers for this reactor instance + for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { + this.timers.add(new TimerInstance(timerDecl, this)); + } + + // Instantiate actions for this reactor instance + for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { + this.actions.add(new ActionInstance(actionDecl, this)); + } + + establishPortConnections(); + + // Create the reaction instances in this reactor instance. + // This also establishes all the implied dependencies. + // Note that this can only happen _after_ the children, + // port, action, and timer instances have been created. + createReactionInstances(); + + // Instantiate modes for this reactor instance + // This must come after the child elements (reactions, etc) of this reactor + // are created in order to allow their association with modes + for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { + this.modes.add(new ModeInstance(modeDecl, this)); + } + for (ModeInstance mode : this.modes) { + mode.setupTranstions(); + } } - - /** Create all the watchdog instances of this reactor instance. */ - protected void createWatchdogInstances() { - List watchdogs = ASTUtils.allWatchdogs(reactorDefinition); - if (watchdogs != null) { - for (Watchdog watchdog : watchdogs) { - // Create the watchdog instance. - var watchdogInstance = new WatchdogInstance(watchdog, this); - - // Add the watchdog instance to the list of watchdogs for this - // reactor. - this.watchdogs.add(watchdogInstance); - } + } + + public TypeParameterizedReactor getTypeParameterizedReactor() { + return this.tpr; + } + + ////////////////////////////////////////////////////// + //// Private methods. + + /** + * Connect the given left port range to the given right port range. + * + *

    NOTE: This method is public to enable its use in unit tests. Otherwise, it should be + * private. This is why it is defined here, in the section labeled "Private methods." + * + * @param src The source range. + * @param dst The destination range. + * @param connection The connection establishing this relationship. + */ + public static void connectPortInstances( + RuntimeRange src, RuntimeRange dst, Connection connection) { + SendRange range = new SendRange(src, dst, src._interleaved, connection); + src.instance.dependentPorts.add(range); + dst.instance.dependsOnPorts.add(src); + } + + /** + * Populate connectivity information in the port instances. Note that this can only happen _after_ + * the children and port instances have been created. Unfortunately, we have to do some + * complicated things here to support multiport-to-multiport, multiport-to-bank, and + * bank-to-multiport communication. The principle being followed is: in each connection statement, + * for each port instance on the left, connect to the next available port on the right. + */ + private void establishPortConnections() { + for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { + List> leftPorts = + listPortInstances(connection.getLeftPorts(), connection); + Iterator> srcRanges = leftPorts.iterator(); + List> rightPorts = + listPortInstances(connection.getRightPorts(), connection); + Iterator> dstRanges = rightPorts.iterator(); + + // Check for empty lists. + if (!srcRanges.hasNext()) { + if (dstRanges.hasNext()) { + reporter.reportWarning(connection, "No sources to provide inputs."); } - } - - //////////////////////////////////////// - //// Private constructors - - /** - * Create a runtime instance from the specified definition - * and with the specified parent that instantiated it. - * @param definition The instantiation statement in the AST. - * @param parent The parent, or null for the main rector. - * @param reporter An error reporter. - * @param desiredDepth The depth to which to expand the hierarchy. - */ - public ReactorInstance( - Instantiation definition, - ReactorInstance parent, - ErrorReporter reporter, - int desiredDepth) { - super(definition, parent); - this.reporter = reporter; - this.reactorDeclaration = definition.getReactorClass(); - this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - this.tpr = new TypeParameterizedReactor(definition); - - // check for recursive instantiation - var currentParent = parent; - var foundSelfAsParent = false; - do { - if (currentParent != null) { - if (currentParent.reactorDefinition == this.reactorDefinition) { - foundSelfAsParent = true; - currentParent = null; // break - } else { - currentParent = currentParent.parent; - } + return; + } else if (!dstRanges.hasNext()) { + reporter.reportWarning(connection, "No destination. Outputs will be lost."); + return; + } + + RuntimeRange src = srcRanges.next(); + RuntimeRange dst = dstRanges.next(); + + while (true) { + if (dst.width == src.width) { + connectPortInstances(src, dst, connection); + if (!dstRanges.hasNext()) { + if (srcRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Source is wider than the destination. Outputs will be lost."); } - } while(currentParent != null); - - this.recursive = foundSelfAsParent; - if (recursive) { - reporter.reportError(definition, "Recursive reactor instantiation."); - } - - // If the reactor definition is null, give up here. Otherwise, diagram generation - // will fail an NPE. - if (reactorDefinition == null) { - reporter.reportError(definition, "Reactor instantiation has no matching reactor definition."); - return; - } - - setInitialWidth(); - - // Apply overrides and instantiate parameters for this reactor instance. - for (Parameter parameter : ASTUtils.allParameters(reactorDefinition)) { - this.parameters.add(new ParameterInstance(parameter, this)); - } - - // Instantiate inputs for this reactor instance - for (Input inputDecl : ASTUtils.allInputs(reactorDefinition)) { - this.inputs.add(new PortInstance(inputDecl, this, reporter)); - } - - // Instantiate outputs for this reactor instance - for (Output outputDecl : ASTUtils.allOutputs(reactorDefinition)) { - this.outputs.add(new PortInstance(outputDecl, this, reporter)); - } - - // Do not process content (except interface above) if recursive - if (!recursive && (desiredDepth < 0 || this.depth < desiredDepth)) { - // Instantiate children for this reactor instance. - // While doing this, assign an index offset to each. - for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { - var childInstance = new ReactorInstance( - child, - this, - reporter, - desiredDepth - ); - this.children.add(childInstance); - } - - // Instantiate timers for this reactor instance - for (Timer timerDecl : ASTUtils.allTimers(reactorDefinition)) { - this.timers.add(new TimerInstance(timerDecl, this)); - } - - // Instantiate actions for this reactor instance - for (Action actionDecl : ASTUtils.allActions(reactorDefinition)) { - this.actions.add(new ActionInstance(actionDecl, this)); - } - - establishPortConnections(); - - // Create the reaction instances in this reactor instance. - // This also establishes all the implied dependencies. - // Note that this can only happen _after_ the children, - // port, action, and timer instances have been created. - createReactionInstances(); - - // Instantiate modes for this reactor instance - // This must come after the child elements (reactions, etc) of this reactor - // are created in order to allow their association with modes - for (Mode modeDecl : ASTUtils.allModes(reactorDefinition)) { - this.modes.add(new ModeInstance(modeDecl, this)); + break; + } + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + if (dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Destination is wider than the source. Inputs will be missing."); + } + break; } - for (ModeInstance mode : this.modes) { - mode.setupTranstions(); + } + dst = dstRanges.next(); + src = srcRanges.next(); + } else if (dst.width < src.width) { + // Split the left (src) range in two. + connectPortInstances(src.head(dst.width), dst, connection); + src = src.tail(dst.width); + if (!dstRanges.hasNext()) { + // Should not happen (checked by the validator). + reporter.reportWarning( + connection, "Source is wider than the destination. Outputs will be lost."); + break; + } + dst = dstRanges.next(); + } else if (src.width < dst.width) { + // Split the right (dst) range in two. + connectPortInstances(src, dst.head(src.width), connection); + dst = dst.tail(src.width); + if (!srcRanges.hasNext()) { + if (connection.isIterated()) { + srcRanges = leftPorts.iterator(); + } else { + reporter.reportWarning( + connection, "Destination is wider than the source. Inputs will be missing."); + break; } + } + src = srcRanges.next(); } + } } - - public TypeParameterizedReactor getTypeParameterizedReactor() { - return this.tpr; - } - - ////////////////////////////////////////////////////// - //// Private methods. - - /** - * Connect the given left port range to the given right port range. - * - * NOTE: This method is public to enable its use in unit tests. - * Otherwise, it should be private. This is why it is defined here, - * in the section labeled "Private methods." - * - * @param src The source range. - * @param dst The destination range. - * @param connection The connection establishing this relationship. - */ - public static void connectPortInstances( - RuntimeRange src, - RuntimeRange dst, - Connection connection - ) { - SendRange range = new SendRange(src, dst, src._interleaved, connection); - src.instance.dependentPorts.add(range); - dst.instance.dependsOnPorts.add(src); + } + + /** + * If path exists from the specified port to any reaction in the specified set of reactions, then + * add the specified port and all ports along the path to the specified set of ports. + * + * @return True if the specified port was added. + */ + private boolean findPaths( + PortInstance port, Set reactions, Set ports) { + if (ports.contains(port)) return false; + boolean result = false; + for (ReactionInstance d : port.getDependentReactions()) { + if (reactions.contains(d)) ports.add(port); + result = true; } - - /** - * Populate connectivity information in the port instances. - * Note that this can only happen _after_ the children and port instances have been created. - * Unfortunately, we have to do some complicated things here - * to support multiport-to-multiport, multiport-to-bank, - * and bank-to-multiport communication. The principle being followed is: - * in each connection statement, for each port instance on the left, - * connect to the next available port on the right. - */ - private void establishPortConnections() { - for (Connection connection : ASTUtils.allConnections(reactorDefinition)) { - List> leftPorts = listPortInstances(connection.getLeftPorts(), connection); - Iterator> srcRanges = leftPorts.iterator(); - List> rightPorts = listPortInstances(connection.getRightPorts(), connection); - Iterator> dstRanges = rightPorts.iterator(); - - // Check for empty lists. - if (!srcRanges.hasNext()) { - if (dstRanges.hasNext()) { - reporter.reportWarning(connection, "No sources to provide inputs."); - } - return; - } else if (!dstRanges.hasNext()) { - reporter.reportWarning(connection, "No destination. Outputs will be lost."); - return; - } - - RuntimeRange src = srcRanges.next(); - RuntimeRange dst = dstRanges.next(); - - while(true) { - if (dst.width == src.width) { - connectPortInstances(src, dst, connection); - if (!dstRanges.hasNext()) { - if (srcRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Source is wider than the destination. Outputs will be lost."); - } - break; - } - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - if (dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Destination is wider than the source. Inputs will be missing."); - } - break; - } - } - dst = dstRanges.next(); - src = srcRanges.next(); - } else if (dst.width < src.width) { - // Split the left (src) range in two. - connectPortInstances(src.head(dst.width), dst, connection); - src = src.tail(dst.width); - if (!dstRanges.hasNext()) { - // Should not happen (checked by the validator). - reporter.reportWarning(connection, - "Source is wider than the destination. Outputs will be lost."); - break; - } - dst = dstRanges.next(); - } else if (src.width < dst.width) { - // Split the right (dst) range in two. - connectPortInstances(src, dst.head(src.width), connection); - dst = dst.tail(src.width); - if (!srcRanges.hasNext()) { - if (connection.isIterated()) { - srcRanges = leftPorts.iterator(); - } else { - reporter.reportWarning(connection, - "Destination is wider than the source. Inputs will be missing."); - break; - } - } - src = srcRanges.next(); - } - } + // Perform a depth-first search. + for (SendRange r : port.dependentPorts) { + for (RuntimeRange p : r.destinations) { + boolean added = findPaths(p.instance, reactions, ports); + if (added) { + result = true; + ports.add(port); } + } } - - /** - * If path exists from the specified port to any reaction in the specified - * set of reactions, then add the specified port and all ports along the path - * to the specified set of ports. - * @return True if the specified port was added. - */ - private boolean findPaths( - PortInstance port, - Set reactions, - Set ports - ) { - if (ports.contains(port)) return false; - boolean result = false; - for (ReactionInstance d : port.getDependentReactions()) { - if (reactions.contains(d)) ports.add(port); - result = true; - } - // Perform a depth-first search. - for (SendRange r : port.dependentPorts) { - for (RuntimeRange p : r.destinations) { - boolean added = findPaths(p.instance, reactions, ports); - if (added) { - result = true; - ports.add(port); - } - } - } + return result; + } + + /** + * Given a list of port references, as found on either side of a connection, return a list of the + * port instance ranges referenced. These may be multiports, and may be ports of a contained bank + * (a port representing ports of the bank members) so the returned list includes ranges of banks + * and channels. + * + *

    If a given port reference has the form {@code interleaved(b.m)}, where {@code b} is a bank + * and {@code m} is a multiport, then the corresponding range in the returned list is marked + * interleaved. + * + *

    For example, if {@code b} and {@code m} have width 2, without the interleaved keyword, the + * returned range represents the sequence {@code [b0.m0, b0.m1, b1.m0, b1.m1]}. With the + * interleaved marking, the returned range represents the sequence {@code [b0.m0, b1.m0, b0.m1, + * b1.m1]}. Both ranges will have width 4. + * + * @param references The variable references on one side of the connection. + * @param connection The connection. + */ + private List> listPortInstances( + List references, Connection connection) { + List> result = new ArrayList<>(); + List> tails = new LinkedList<>(); + int count = 0; + for (VarRef portRef : references) { + // Simple error checking first. + if (!(portRef.getVariable() instanceof Port)) { + reporter.reportError(portRef, "Not a port."); return result; - } - - /** - * Given a list of port references, as found on either side of a connection, - * return a list of the port instance ranges referenced. These may be multiports, - * and may be ports of a contained bank (a port representing ports of the bank - * members) so the returned list includes ranges of banks and channels. - * - * If a given port reference has the form {@code interleaved(b.m)}, where {@code b} is - * a bank and {@code m} is a multiport, then the corresponding range in the returned - * list is marked interleaved. - * - * For example, if {@code b} and {@code m} have width 2, without the interleaved keyword, - * the returned range represents the sequence {@code [b0.m0, b0.m1, b1.m0, b1.m1]}. - * With the interleaved marking, the returned range represents the sequence - * {@code [b0.m0, b1.m0, b0.m1, b1.m1]}. Both ranges will have width 4. - * - * @param references The variable references on one side of the connection. - * @param connection The connection. - */ - private List> listPortInstances( - List references, Connection connection - ) { - List> result = new ArrayList<>(); - List> tails = new LinkedList<>(); - int count = 0; - for (VarRef portRef : references) { - // Simple error checking first. - if (!(portRef.getVariable() instanceof Port)) { - reporter.reportError(portRef, "Not a port."); - return result; - } - // First, figure out which reactor we are dealing with. - // The reactor we want is the container of the port. - // If the port reference has no container, then the reactor is this one. - var reactor = this; - if (portRef.getContainer() != null) { - reactor = getChildReactorInstance(portRef.getContainer()); - } - // The reactor can be null only if there is an error in the code. - // Skip this portRef so that diagram synthesis can complete. - if (reactor != null) { - PortInstance portInstance = reactor.lookupPortInstance( - (Port) portRef.getVariable()); - - Set interleaved = new LinkedHashSet<>(); - if (portRef.isInterleaved()) { - // NOTE: Here, we are assuming that the interleaved() - // keyword is only allowed on the multiports contained by - // contained reactors. - interleaved.add(portInstance.parent); - } - RuntimeRange range = new RuntimeRange.Port( - portInstance, interleaved); - // If this portRef is not the last one in the references list - // then we have to check whether the range can be incremented at - // the lowest two levels (port and container). If not, - // split the range and add the tail to list to iterate over again. - // The reason for this is that the connection has only local visibility, - // but the range width may be reflective of bank structure higher - // in the hierarchy. - if (count < references.size() - 1) { - int portWidth = portInstance.width; - int portParentWidth = portInstance.parent.width; - // If the port is being connected on the inside and there is - // more than one port in the list, then we can only connect one - // bank member at a time. - if (reactor == this && references.size() > 1) { - portParentWidth = 1; - } - int widthBound = portWidth * portParentWidth; - - // If either of these widths cannot be determined, assume infinite. - if (portWidth < 0) widthBound = Integer.MAX_VALUE; - if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < range.width) { - // Need to split the range. - tails.add(range.tail(widthBound)); - range = range.head(widthBound); - } - } - result.add(range); - } + } + // First, figure out which reactor we are dealing with. + // The reactor we want is the container of the port. + // If the port reference has no container, then the reactor is this one. + var reactor = this; + if (portRef.getContainer() != null) { + reactor = getChildReactorInstance(portRef.getContainer()); + } + // The reactor can be null only if there is an error in the code. + // Skip this portRef so that diagram synthesis can complete. + if (reactor != null) { + PortInstance portInstance = reactor.lookupPortInstance((Port) portRef.getVariable()); + + Set interleaved = new LinkedHashSet<>(); + if (portRef.isInterleaved()) { + // NOTE: Here, we are assuming that the interleaved() + // keyword is only allowed on the multiports contained by + // contained reactors. + interleaved.add(portInstance.parent); } - // Iterate over the tails. - while(tails.size() > 0) { - List> moreTails = new LinkedList<>(); - count = 0; - for (RuntimeRange tail : tails) { - if (count < tails.size() - 1) { - int widthBound = tail.instance.width; - if (tail._interleaved.contains(tail.instance.parent)) { - widthBound = tail.instance.parent.width; - } - // If the width cannot be determined, assume infinite. - if (widthBound < 0) widthBound = Integer.MAX_VALUE; - - if (widthBound < tail.width) { - // Need to split the range again - moreTails.add(tail.tail(widthBound)); - tail = tail.head(widthBound); - } - } - result.add(tail); - } - tails = moreTails; + RuntimeRange range = new RuntimeRange.Port(portInstance, interleaved); + // If this portRef is not the last one in the references list + // then we have to check whether the range can be incremented at + // the lowest two levels (port and container). If not, + // split the range and add the tail to list to iterate over again. + // The reason for this is that the connection has only local visibility, + // but the range width may be reflective of bank structure higher + // in the hierarchy. + if (count < references.size() - 1) { + int portWidth = portInstance.width; + int portParentWidth = portInstance.parent.width; + // If the port is being connected on the inside and there is + // more than one port in the list, then we can only connect one + // bank member at a time. + if (reactor == this && references.size() > 1) { + portParentWidth = 1; + } + int widthBound = portWidth * portParentWidth; + + // If either of these widths cannot be determined, assume infinite. + if (portWidth < 0) widthBound = Integer.MAX_VALUE; + if (portParentWidth < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < range.width) { + // Need to split the range. + tails.add(range.tail(widthBound)); + range = range.head(widthBound); + } } - return result; + result.add(range); + } } - - /** - * If this is a bank of reactors, set the width. - * It will be set to -1 if it cannot be determined. - */ - private void setInitialWidth() { - WidthSpec widthSpec = definition.getWidthSpec(); - if (widthSpec != null) { - // We need the instantiations list of the containing reactor, - // not this one. - width = ASTUtils.width(widthSpec, parent.instantiations()); + // Iterate over the tails. + while (tails.size() > 0) { + List> moreTails = new LinkedList<>(); + count = 0; + for (RuntimeRange tail : tails) { + if (count < tails.size() - 1) { + int widthBound = tail.instance.width; + if (tail._interleaved.contains(tail.instance.parent)) { + widthBound = tail.instance.parent.width; + } + // If the width cannot be determined, assume infinite. + if (widthBound < 0) widthBound = Integer.MAX_VALUE; + + if (widthBound < tail.width) { + // Need to split the range again + moreTails.add(tail.tail(widthBound)); + tail = tail.head(widthBound); + } } + result.add(tail); + } + tails = moreTails; } - - ////////////////////////////////////////////////////// - //// Private fields. - - /** - * Cached set of reactions and ports that form a causality loop. - */ - private Set> cachedCycles; - - /** - * Cached reaction graph containing reactions that form a causality loop. - */ - private ReactionInstanceGraph cachedReactionLoopGraph = null; - - /** - * Return true if this is a generated delay reactor that originates from - * an "after" delay on a connection. - * - * @return True if this is a generated delay, false otherwise. - */ - public boolean isGeneratedDelay() { - // FIXME: hacky string matching again... - return this.definition.getReactorClass().getName().contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME); + return result; + } + + /** + * If this is a bank of reactors, set the width. It will be set to -1 if it cannot be determined. + */ + private void setInitialWidth() { + WidthSpec widthSpec = definition.getWidthSpec(); + if (widthSpec != null) { + // We need the instantiations list of the containing reactor, + // not this one. + width = ASTUtils.width(widthSpec, parent.instantiations()); } + } + + ////////////////////////////////////////////////////// + //// Private fields. + + /** Cached set of reactions and ports that form a causality loop. */ + private Set> cachedCycles; + + /** Cached reaction graph containing reactions that form a causality loop. */ + private ReactionInstanceGraph cachedReactionLoopGraph = null; + + /** + * Return true if this is a generated delay reactor that originates from an "after" delay on a + * connection. + * + * @return True if this is a generated delay, false otherwise. + */ + public boolean isGeneratedDelay() { + // FIXME: hacky string matching again... + return this.definition + .getReactorClass() + .getName() + .contains(DelayBodyGenerator.GEN_DELAY_CLASS_NAME); + } } diff --git a/org.lflang/src/org/lflang/generator/RuntimeRange.java b/org.lflang/src/org/lflang/generator/RuntimeRange.java index 36f132b27e..d684a41bd9 100644 --- a/org.lflang/src/org/lflang/generator/RuntimeRange.java +++ b/org.lflang/src/org/lflang/generator/RuntimeRange.java @@ -32,478 +32,419 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Set; /** - * Class representing a range of runtime instance objects - * (port channels, reactors, reactions, etc.). This class and its derived classes - * have the most detailed information about the structure of a Lingua Franca - * program. There are three levels of detail: + * Class representing a range of runtime instance objects (port channels, reactors, reactions, + * etc.). This class and its derived classes have the most detailed information about the structure + * of a Lingua Franca program. There are three levels of detail: + * *

      - *
    • The abstract syntax tree (AST).
    • - *
    • The compile-time instance graph (CIG).
    • - *
    • The runtime instance graph (RIG).
    • + *
    • The abstract syntax tree (AST). + *
    • The compile-time instance graph (CIG). + *
    • The runtime instance graph (RIG). *
    - * - * In the AST, each reactor class is represented once. - * In the CIG, each reactor class is represented as many times as it is - * instantiated, except that a bank has only one representation (as - * in the graphical rendition). Equivalently, each CIG node has a unique - * full name, even though it may represent many runtime instances. - * The CIG is represented by - * {@link NamedInstance} and its derived classes. - * In the RIG, each bank is expanded so each bank member and - * each port channel is represented. - * - * In general, determining dependencies between reactions requires analysis - * at the level of the RIG. But a brute-force representation of the RIG - * can get very large, and for most programs it has a great deal of - * redundancy. In a fully detailed representation of the RIG, for example, - * a bank of width N that contains a bank of width M within which there - * is a reactor R with port P will have N*M runtime instances of the port. - * If the port is a multiport with width L, then there are N*M*L - * edges connected to instances of that port, each of which may go - * to a distinct set of other remote runtime port instances. - * - * This class and its subclasses give a more compact representation of the - * RIG in most common cases where collections of runtime instances all have - * the same dependencies or dependencies form a range that can be represented - * compactly. - * - * A RuntimeRange represents an adjacent set of RIG objects (port channels, reactions - * reactors). For example, it can represent port channels 2 through 5 in a multiport - * of width 10. The width in this case is 4. If such a port is - * contained by one or more banks of reactors, then channels 2 through 5 - * of one bank member form a contiguous range. If you want channels 2 through 5 - * of all bank members, then this needs to be represented with multiple ranges. - * - * The maxWidth is the width of the instance multiplied by the widths of - * each of its containers. For example, if a port of width 4 is contained by - * a bank of width 2 that is then contained by a bank of width 3, then - * the maxWidth will be 2*3*4 = 24. - * - * The function iterationOrder returns a list that includes the instance - * of this range and all its containers, except the top-level reactor (main - * or federated). The order of this list is the order in which an - * iteration over the RIG objects represented by this range should be - * iterated. If the instance is a PortInstance, then this order will - * depend on whether connections at any level of the hierarchy are - * interleaved. - * - * The simplest Ranges are those where the corresponding CIG node represents - * only one runtime instance (its instance is not (deeply) within a bank - * and is not a multiport). In this case, the RuntimeRange and all the objects - * returned by iterationOrder will have width 1. - * - * In a more complex instance, consider a bank A of width 2 that contains a - * bank B of width 2 that contains a port instance P with width 2. . - * There are a total of 8 instances of P, which we can name: - * - * A0.B0.P0 - * A0.B0.P1 - * A0.B1.P0 - * A0.B1.P1 - * A1.B0.P0 - * A1.B0.P1 - * A1.B1.P0 - * A1.B1.P1 - * - * If there is no interleaving, iterationOrder() returns [P, B, A], - * indicating that they should be iterated by incrementing the index of P - * first, then the index of B, then the index of A, as done above. - * - * If the connection within B to port P is interleaved, then the order - * of iteration order will be [B, P, A], resulting in the list: - * - * A0.B0.P0 - * A0.B1.P0 - * A0.B0.P1 - * A0.B1.P1 - * A1.B0.P0 - * A1.B1.P0 - * A1.B0.P1 - * A1.B1.P1 - * - * If the connection within A to B is also interleaved, then the order - * will be [A, B, P], resulting in the list: - * - * A0.B0.P0 - * A1.B0.P0 - * A0.B1.P0 - * A1.B1.P0 - * A0.B0.P1 - * A1.B0.P1 - * A0.B1.P1 - * A1.B1.P1 - * - * Finally, if the connection within A to B is interleaved, but not the - * connection within B to P, then the order will be [A, P, B], resulting in - * the list: - * - * A0.B0.P0 - * A1.B0.P0 - * A0.B0.P1 - * A1.B0.P1 - * A0.B1.P0 - * A1.B1.P0 - * A0.B1.P1 - * A1.B1.P1 - * - * A RuntimeRange is a contiguous subset of one of the above lists, given by - * a start offset and a width that is less than or equal to maxWidth. - * - * Each element of the above lists can be represented as a permuted mixed-radix (PMR) number, - * where the low-order digit has radix equal to the width of P, the second digit - * has radix equal to the width of B, and the final digit has radix equal to the - * width of A. Each PMR has a permutation vector that defines how to increment - * PMR number. This permutation vector is derived from the iteration order as - * follows. When there is no interleaving, the iteration order is [P, B, A], - * and the permutation vector is [0, 1, 2]. When there is interleaving, the permutation - * vector simply specifies the iteration order. For example, if the iteration order - * is [A, P, B], then the permutation vector is [2, 0, 1], indicating that digit 2 - * of the PMR (corresponding to A) should be incremented first, then digit 0 (for P), - * then digit 1 (for B). - * - * For a RuntimeRange with width greater than 1, - * the head() and tail() functions split the range. - * - * This class and subclasses are designed to be immutable. - * Modifications always return a new RuntimeRange. + * + * In the AST, each reactor class is represented once. In the CIG, each reactor class is represented + * as many times as it is instantiated, except that a bank has only one representation (as in the + * graphical rendition). Equivalently, each CIG node has a unique full name, even though it may + * represent many runtime instances. The CIG is represented by {@link NamedInstance} and its derived + * classes. In the RIG, each bank is expanded so each bank member and each port channel is + * represented. + * + *

    In general, determining dependencies between reactions requires analysis at the level of the + * RIG. But a brute-force representation of the RIG can get very large, and for most programs it has + * a great deal of redundancy. In a fully detailed representation of the RIG, for example, a bank of + * width N that contains a bank of width M within which there is a reactor R with port P will have + * N*M runtime instances of the port. If the port is a multiport with width L, then there are N*M*L + * edges connected to instances of that port, each of which may go to a distinct set of other remote + * runtime port instances. + * + *

    This class and its subclasses give a more compact representation of the RIG in most common + * cases where collections of runtime instances all have the same dependencies or dependencies form + * a range that can be represented compactly. + * + *

    A RuntimeRange represents an adjacent set of RIG objects (port channels, reactions reactors). + * For example, it can represent port channels 2 through 5 in a multiport of width 10. The width in + * this case is 4. If such a port is contained by one or more banks of reactors, then channels 2 + * through 5 of one bank member form a contiguous range. If you want channels 2 through 5 of all + * bank members, then this needs to be represented with multiple ranges. + * + *

    The maxWidth is the width of the instance multiplied by the widths of each of its containers. + * For example, if a port of width 4 is contained by a bank of width 2 that is then contained by a + * bank of width 3, then the maxWidth will be 2*3*4 = 24. + * + *

    The function iterationOrder returns a list that includes the instance of this range and all + * its containers, except the top-level reactor (main or federated). The order of this list is the + * order in which an iteration over the RIG objects represented by this range should be iterated. If + * the instance is a PortInstance, then this order will depend on whether connections at any level + * of the hierarchy are interleaved. + * + *

    The simplest Ranges are those where the corresponding CIG node represents only one runtime + * instance (its instance is not (deeply) within a bank and is not a multiport). In this case, the + * RuntimeRange and all the objects returned by iterationOrder will have width 1. + * + *

    In a more complex instance, consider a bank A of width 2 that contains a bank B of width 2 + * that contains a port instance P with width 2. . There are a total of 8 instances of P, which we + * can name: + * + *

    A0.B0.P0 A0.B0.P1 A0.B1.P0 A0.B1.P1 A1.B0.P0 A1.B0.P1 A1.B1.P0 A1.B1.P1 + * + *

    If there is no interleaving, iterationOrder() returns [P, B, A], indicating that they should + * be iterated by incrementing the index of P first, then the index of B, then the index of A, as + * done above. + * + *

    If the connection within B to port P is interleaved, then the order of iteration order will be + * [B, P, A], resulting in the list: + * + *

    A0.B0.P0 A0.B1.P0 A0.B0.P1 A0.B1.P1 A1.B0.P0 A1.B1.P0 A1.B0.P1 A1.B1.P1 + * + *

    If the connection within A to B is also interleaved, then the order will be [A, B, P], + * resulting in the list: + * + *

    A0.B0.P0 A1.B0.P0 A0.B1.P0 A1.B1.P0 A0.B0.P1 A1.B0.P1 A0.B1.P1 A1.B1.P1 + * + *

    Finally, if the connection within A to B is interleaved, but not the connection within B to P, + * then the order will be [A, P, B], resulting in the list: + * + *

    A0.B0.P0 A1.B0.P0 A0.B0.P1 A1.B0.P1 A0.B1.P0 A1.B1.P0 A0.B1.P1 A1.B1.P1 + * + *

    A RuntimeRange is a contiguous subset of one of the above lists, given by a start offset and a + * width that is less than or equal to maxWidth. + * + *

    Each element of the above lists can be represented as a permuted mixed-radix (PMR) number, + * where the low-order digit has radix equal to the width of P, the second digit has radix equal to + * the width of B, and the final digit has radix equal to the width of A. Each PMR has a permutation + * vector that defines how to increment PMR number. This permutation vector is derived from the + * iteration order as follows. When there is no interleaving, the iteration order is [P, B, A], and + * the permutation vector is [0, 1, 2]. When there is interleaving, the permutation vector simply + * specifies the iteration order. For example, if the iteration order is [A, P, B], then the + * permutation vector is [2, 0, 1], indicating that digit 2 of the PMR (corresponding to A) should + * be incremented first, then digit 0 (for P), then digit 1 (for B). + * + *

    For a RuntimeRange with width greater than 1, the head() and tail() functions split the range. + * + *

    This class and subclasses are designed to be immutable. Modifications always return a new + * RuntimeRange. * * @author Edward A. Lee */ public class RuntimeRange> implements Comparable> { - - /** - * Create a new range representing the full width of the specified instance - * with no interleaving. The instances will be a list with the specified instance - * first, its parent next, and on up the hierarchy until the depth 1 parent (the - * top-level reactor is not included because it can never be a bank). - * @param instance The instance. - * @param interleaved A list of parents that are interleaved or null if none. - */ - public RuntimeRange( - T instance, - Set interleaved - ) { - this(instance, 0, 0, interleaved); - } - /** - * Create a new range representing a range of the specified instance - * with no interleaving. The instances will be a list with the specified instance - * first, its parent next, and on up the hierarchy until the depth 1 parent (the - * top-level reactor is not included because it can never be a bank). - * @param instance The instance over which this is a range (port, reaction, etc.) - * @param start The starting index for the range. - * @param width The width of the range or 0 to specify the maximum possible width. - * @param interleaved A list of parents that are interleaved or null if none. - */ - public RuntimeRange( - T instance, - int start, - int width, - Set interleaved - ) { - this.instance = instance; - this.start = start; - if (interleaved != null) { - this._interleaved.addAll(interleaved); - } - - int maxWidth = instance.width; // Initial value. - NamedInstance parent = instance.parent; - while (parent.depth > 0) { - maxWidth *= parent.width; - parent = parent.parent; - } - this.maxWidth = maxWidth; - - if (width > 0 && width + start < maxWidth) { - this.width = width; - } else { - this.width = maxWidth - start; - } - } - - ////////////////////////////////////////////////////////// - //// Public variables - - /** The instance that this is a range of. */ - public final T instance; - - /** The start offset of this range. */ - public final int start; - - /** The maximum width of any range with this instance. */ - public final int maxWidth; - - /** The width of this range. */ - public final int width; - - ////////////////////////////////////////////////////////// - //// Public methods - - /** - * Compare ranges by first comparing their start offset, and then, - * if these are equal, comparing their widths. This comparison is - * meaningful only for ranges that have the same instances. - * Note that this can return 0 even if equals() does not return true. - */ - @Override - public int compareTo(RuntimeRange o) { - if (start < o.start) { - return -1; - } else if (start == o.start) { - return Integer.compare(width, o.width); - } else { - return 1; - } + /** + * Create a new range representing the full width of the specified instance with no interleaving. + * The instances will be a list with the specified instance first, its parent next, and on up the + * hierarchy until the depth 1 parent (the top-level reactor is not included because it can never + * be a bank). + * + * @param instance The instance. + * @param interleaved A list of parents that are interleaved or null if none. + */ + public RuntimeRange(T instance, Set interleaved) { + this(instance, 0, 0, interleaved); + } + + /** + * Create a new range representing a range of the specified instance with no interleaving. The + * instances will be a list with the specified instance first, its parent next, and on up the + * hierarchy until the depth 1 parent (the top-level reactor is not included because it can never + * be a bank). + * + * @param instance The instance over which this is a range (port, reaction, etc.) + * @param start The starting index for the range. + * @param width The width of the range or 0 to specify the maximum possible width. + * @param interleaved A list of parents that are interleaved or null if none. + */ + public RuntimeRange(T instance, int start, int width, Set interleaved) { + this.instance = instance; + this.start = start; + if (interleaved != null) { + this._interleaved.addAll(interleaved); } - - /** - * Return a new RuntimeRange that is identical to this range but - * with width reduced to the specified width. - * If the new width is greater than or equal to the width - * of this range, then return this range. - * If the newWidth is 0 or negative, return null. - * @param newWidth The new width. - */ - public RuntimeRange head(int newWidth) { - if (newWidth >= width) return this; - if (newWidth <= 0) return null; - return new RuntimeRange<>(instance, start, newWidth, _interleaved); + + int maxWidth = instance.width; // Initial value. + NamedInstance parent = instance.parent; + while (parent.depth > 0) { + maxWidth *= parent.width; + parent = parent.parent; } - - /** - * Return the list of natural identifiers for the runtime instances - * in this range. Each returned identifier is an integer representation - * of the mixed-radix number [d0, ... , dn] with radices [w0, ... , wn], - * where d0 is the bank or channel index of this RuntimeRange's instance, which - * has width w0, and dn is the bank index of its topmost parent below the - * top-level (main) reactor, which has width wn. The depth of this RuntimeRange's - * instance, therefore, is n - 1. The order of the returned list is the order - * in which the runtime instances should be iterated. - */ - public List instances() { - List result = new ArrayList<>(width); - MixedRadixInt mr = startMR(); - int count = 0; - while (count++ < width) { - result.add(mr.get()); - mr.increment(); - } - return result; + this.maxWidth = maxWidth; + + if (width > 0 && width + start < maxWidth) { + this.width = width; + } else { + this.width = maxWidth - start; } - - /** - * Return a list containing the instance for this range and all of its - * parents, not including the top level reactor, in the order in which - * their banks and multiport channels should be iterated. - * For each depth at which the connection is interleaved, that parent - * will appear before this instance in depth order (shallower to deeper). - * For each depth at which the connection is not interleaved, that parent - * will appear after this instance in reverse depth order (deeper to - * shallower). - */ - public List> iterationOrder() { - ArrayList> result = new ArrayList<>(); - result.add(instance); - ReactorInstance parent = instance.parent; - while (parent.depth > 0) { - if (_interleaved.contains(parent)) { - // Put the parent at the head of the list. - result.add(0, parent); - } else { - result.add(parent); - } - parent = parent.parent; - } - return result; + } + + ////////////////////////////////////////////////////////// + //// Public variables + + /** The instance that this is a range of. */ + public final T instance; + + /** The start offset of this range. */ + public final int start; + + /** The maximum width of any range with this instance. */ + public final int maxWidth; + + /** The width of this range. */ + public final int width; + + ////////////////////////////////////////////////////////// + //// Public methods + + /** + * Compare ranges by first comparing their start offset, and then, if these are equal, comparing + * their widths. This comparison is meaningful only for ranges that have the same instances. Note + * that this can return 0 even if equals() does not return true. + */ + @Override + public int compareTo(RuntimeRange o) { + if (start < o.start) { + return -1; + } else if (start == o.start) { + return Integer.compare(width, o.width); + } else { + return 1; } - - /** - * Return a range that is the subset of this range that overlaps with the - * specified range or null if there is no overlap. - */ - public RuntimeRange overlap(RuntimeRange range) { - if (!overlaps(range)) return null; - int newStart = Math.max(start, range.start); - int newEnd = Math.min(start + width, range.start + range.width); - return tail(newStart - start).head(newEnd - newStart); + } + + /** + * Return a new RuntimeRange that is identical to this range but with width reduced to the + * specified width. If the new width is greater than or equal to the width of this range, then + * return this range. If the newWidth is 0 or negative, return null. + * + * @param newWidth The new width. + */ + public RuntimeRange head(int newWidth) { + if (newWidth >= width) return this; + if (newWidth <= 0) return null; + return new RuntimeRange<>(instance, start, newWidth, _interleaved); + } + + /** + * Return the list of natural identifiers for the runtime instances in this + * range. Each returned identifier is an integer representation of the mixed-radix number [d0, ... + * , dn] with radices [w0, ... , wn], where d0 is the bank or channel index of this RuntimeRange's + * instance, which has width w0, and dn is the bank index of its topmost parent below the + * top-level (main) reactor, which has width wn. The depth of this RuntimeRange's instance, + * therefore, is n - 1. The order of the returned list is the order in which the runtime instances + * should be iterated. + */ + public List instances() { + List result = new ArrayList<>(width); + MixedRadixInt mr = startMR(); + int count = 0; + while (count++ < width) { + result.add(mr.get()); + mr.increment(); } - - /** - * Return true if the specified range has the same instance as this range - * and the ranges overlap. - */ - public boolean overlaps(RuntimeRange range) { - if (!instance.equals(range.instance)) return false; - return start < range.start + range.width && start + width > range.start; + return result; + } + + /** + * Return a list containing the instance for this range and all of its parents, not including the + * top level reactor, in the order in which their banks and multiport channels should be iterated. + * For each depth at which the connection is interleaved, that parent will appear before this + * instance in depth order (shallower to deeper). For each depth at which the connection is not + * interleaved, that parent will appear after this instance in reverse depth order (deeper to + * shallower). + */ + public List> iterationOrder() { + ArrayList> result = new ArrayList<>(); + result.add(instance); + ReactorInstance parent = instance.parent; + while (parent.depth > 0) { + if (_interleaved.contains(parent)) { + // Put the parent at the head of the list. + result.add(0, parent); + } else { + result.add(parent); + } + parent = parent.parent; } - - /** - * Return a set of identifiers for runtime instances of a parent of this - * {@link RuntimeRange}'s instance {@code n} levels above this {@link RuntimeRange}'s instance. If {@code n == 1}, for - * example, then this return the identifiers for the parent ReactorInstance. - * - * This returns a list of natural identifiers, - * as defined below, for the instances within the range. - * - * The resulting list can be used to count the number of distinct - * runtime instances of this RuntimeRange's instance (using {@code n == 0}) or any of its parents that - * lie within the range and to provide an index into an array of runtime - * instances. - * - * Each natural identifier is the integer value of a mixed-radix number - * defined as follows: - *

      - *
    • The low-order digit is the index of the runtime instance of {@code i} within its container. - * If the {@link NamedInstance} is a {@code PortInstance}, this will be the multiport channel or {@code 0} if it is not a - * multiport. If the NamedInstance is a ReactorInstance, then it will be the bank - * index or {@code 0} if the reactor is not a bank. The radix for this digit will be - * the multiport width or bank width or 1 if the NamedInstance is neither a - * multiport nor a bank.
    • - *
    • The next digit will be the bank index of the container of the specified - * {@link NamedInstance} or {@code 0} if it is not a bank.
    • - *
    • The remaining digits will be bank indices of containers up to but not - * including the top-level reactor (there is no point in including the top-level - * reactor because it is never a bank).
    • - *
    • Each index that is returned can be used as an index into an array of - * runtime instances that is assumed to be in a natural order.
    • - *
    - * - * @param n The number of levels up of the parent. This is required to be - * less than the depth of this RuntimeRange's instance or an exception will be thrown. - */ - public Set parentInstances(int n) { - Set result = new LinkedHashSet<>(width); - MixedRadixInt mr = startMR(); - int count = 0; - while (count++ < width) { - result.add(mr.get(n)); - mr.increment(); - } - return result; + return result; + } + + /** + * Return a range that is the subset of this range that overlaps with the specified range or null + * if there is no overlap. + */ + public RuntimeRange overlap(RuntimeRange range) { + if (!overlaps(range)) return null; + int newStart = Math.max(start, range.start); + int newEnd = Math.min(start + width, range.start + range.width); + return tail(newStart - start).head(newEnd - newStart); + } + + /** + * Return true if the specified range has the same instance as this range and the ranges overlap. + */ + public boolean overlaps(RuntimeRange range) { + if (!instance.equals(range.instance)) return false; + return start < range.start + range.width && start + width > range.start; + } + + /** + * Return a set of identifiers for runtime instances of a parent of this {@link RuntimeRange}'s + * instance {@code n} levels above this {@link RuntimeRange}'s instance. If {@code n == 1}, for + * example, then this return the identifiers for the parent ReactorInstance. + * + *

    This returns a list of natural identifiers, as defined below, for the instances + * within the range. + * + *

    The resulting list can be used to count the number of distinct runtime instances of this + * RuntimeRange's instance (using {@code n == 0}) or any of its parents that lie within the range + * and to provide an index into an array of runtime instances. + * + *

    Each natural identifier is the integer value of a mixed-radix number defined as + * follows: + * + *

      + *
    • The low-order digit is the index of the runtime instance of {@code i} within its + * container. If the {@link NamedInstance} is a {@code PortInstance}, this will be the + * multiport channel or {@code 0} if it is not a multiport. If the NamedInstance is a + * ReactorInstance, then it will be the bank index or {@code 0} if the reactor is not a + * bank. The radix for this digit will be the multiport width or bank width or 1 if the + * NamedInstance is neither a multiport nor a bank. + *
    • The next digit will be the bank index of the container of the specified {@link + * NamedInstance} or {@code 0} if it is not a bank. + *
    • The remaining digits will be bank indices of containers up to but not including the + * top-level reactor (there is no point in including the top-level reactor because it is + * never a bank). + *
    • Each index that is returned can be used as an index into an array of runtime instances + * that is assumed to be in a natural order. + *
    + * + * @param n The number of levels up of the parent. This is required to be less than the depth of + * this RuntimeRange's instance or an exception will be thrown. + */ + public Set parentInstances(int n) { + Set result = new LinkedHashSet<>(width); + MixedRadixInt mr = startMR(); + int count = 0; + while (count++ < width) { + result.add(mr.get(n)); + mr.increment(); } + return result; + } - /** - * Return the nearest containing ReactorInstance for this instance. - * If this instance is a ReactorInstance, then return it. - * Otherwise, return its parent. - */ - public ReactorInstance parentReactor() { - if (instance instanceof ReactorInstance) { - return (ReactorInstance)instance; - } else { - return instance.getParent(); - } + /** + * Return the nearest containing ReactorInstance for this instance. If this instance is a + * ReactorInstance, then return it. Otherwise, return its parent. + */ + public ReactorInstance parentReactor() { + if (instance instanceof ReactorInstance) { + return (ReactorInstance) instance; + } else { + return instance.getParent(); } - - /** - * Return the permutation vector that indicates the order in which the digits - * of the permuted mixed-radix representations of indices in this range should - * be incremented. - */ - public List permutation() { - List result = new ArrayList<>(instance.depth); - // Populate the result with default zeros. - for (int i = 0; i < instance.depth; i++) { - result.add(0); - } - int count = 0; - for (NamedInstance i : iterationOrder()) { - result.set(count++, instance.depth - i.depth); - } - return result; + } + + /** + * Return the permutation vector that indicates the order in which the digits of the permuted + * mixed-radix representations of indices in this range should be incremented. + */ + public List permutation() { + List result = new ArrayList<>(instance.depth); + // Populate the result with default zeros. + for (int i = 0; i < instance.depth; i++) { + result.add(0); } - - /** - * Return the radixes vector containing the width of this instance followed - * by the widths of its containers, not including the top level, which always - * has radix 1 and value 0. - */ - public List radixes() { - List result = new ArrayList<>(instance.depth); - int width = instance.width; - // If the width cannot be determined, assume 1. - if (width < 0) width = 1; - result.add(width); - ReactorInstance p = instance.getParent(); - while (p != null && p.getDepth() > 0) { - width = p.getWidth(); - // If the width cannot be determined, assume 1. - if (width < 0) width = 1; - result.add(width); - p = p.getParent(); - } - return result; + int count = 0; + for (NamedInstance i : iterationOrder()) { + result.set(count++, instance.depth - i.depth); } + return result; + } - /** - * Return the start as a new permuted mixed-radix number. - * For any instance that is neither a multiport nor a bank, the - * corresponding digit will be 0. - */ - public MixedRadixInt startMR() { - MixedRadixInt result = new MixedRadixInt(null, radixes(), permutation()); - result.setMagnitude(start); - return result; + /** + * Return the radixes vector containing the width of this instance followed by the widths of its + * containers, not including the top level, which always has radix 1 and value 0. + */ + public List radixes() { + List result = new ArrayList<>(instance.depth); + int width = instance.width; + // If the width cannot be determined, assume 1. + if (width < 0) width = 1; + result.add(width); + ReactorInstance p = instance.getParent(); + while (p != null && p.getDepth() > 0) { + width = p.getWidth(); + // If the width cannot be determined, assume 1. + if (width < 0) width = 1; + result.add(width); + p = p.getParent(); } + return result; + } - /** - * Return a new range that represents the leftover elements - * starting at the specified offset relative to start. - * If start + offset is greater than or equal to the width, then this returns null. - * If this offset is 0 then this returns this range unmodified. - * @param offset The number of elements to consume. - */ - public RuntimeRange tail(int offset) { - if (offset == 0) return this; - if (offset >= width) return null; - return new RuntimeRange<>(instance, start + offset, width - offset, _interleaved); + /** + * Return the start as a new permuted mixed-radix number. For any instance that is neither a + * multiport nor a bank, the corresponding digit will be 0. + */ + public MixedRadixInt startMR() { + MixedRadixInt result = new MixedRadixInt(null, radixes(), permutation()); + result.setMagnitude(start); + return result; + } + + /** + * Return a new range that represents the leftover elements starting at the specified offset + * relative to start. If start + offset is greater than or equal to the width, then this returns + * null. If this offset is 0 then this returns this range unmodified. + * + * @param offset The number of elements to consume. + */ + public RuntimeRange tail(int offset) { + if (offset == 0) return this; + if (offset >= width) return null; + return new RuntimeRange<>(instance, start + offset, width - offset, _interleaved); + } + + /** + * Toggle the interleaved status of the specified reactor, which is assumed to be a parent of the + * instance of this range. If it was previously interleaved, make it not interleaved and vice + * versa. This returns a new RuntimeRange. + * + * @param reactor The parent reactor at which to toggle interleaving. + */ + public RuntimeRange toggleInterleaved(ReactorInstance reactor) { + Set newInterleaved = new HashSet<>(_interleaved); + if (_interleaved.contains(reactor)) { + newInterleaved.remove(reactor); + } else { + newInterleaved.add(reactor); } - - /** - * Toggle the interleaved status of the specified reactor, which is assumed - * to be a parent of the instance of this range. - * If it was previously interleaved, make it not interleaved - * and vice versa. This returns a new RuntimeRange. - * @param reactor The parent reactor at which to toggle interleaving. - */ - public RuntimeRange toggleInterleaved(ReactorInstance reactor) { - Set newInterleaved = new HashSet<>(_interleaved); - if (_interleaved.contains(reactor)) { - newInterleaved.remove(reactor); - } else { - newInterleaved.add(reactor); - } - return new RuntimeRange<>(instance, start, width, newInterleaved); + return new RuntimeRange<>(instance, start, width, newInterleaved); + } + + @Override + public String toString() { + return instance.getFullName() + "(" + start + "," + width + ")"; + } + + ////////////////////////////////////////////////////////// + //// Protected variables + + /** Record of which levels are interleaved. */ + Set _interleaved = new HashSet<>(); + + ////////////////////////////////////////////////////////// + //// Public inner classes + + /** Special case of RuntimeRange for PortInstance. */ + public static class Port extends RuntimeRange { + public Port(PortInstance instance) { + super(instance, null); } - - @Override - public String toString() { - return instance.getFullName() + "(" + start + "," + width + ")"; + + public Port(PortInstance instance, Set interleaved) { + super(instance, interleaved); } - - ////////////////////////////////////////////////////////// - //// Protected variables - - /** Record of which levels are interleaved. */ - Set _interleaved = new HashSet<>(); - - ////////////////////////////////////////////////////////// - //// Public inner classes - - /** - * Special case of RuntimeRange for PortInstance. - */ - public static class Port extends RuntimeRange { - public Port(PortInstance instance) { - super(instance, null); - } - public Port(PortInstance instance, Set interleaved) { - super(instance, interleaved); - } - public Port(PortInstance instance, int start, int width, Set interleaved) { - super(instance, start, width, interleaved); - } + + public Port(PortInstance instance, int start, int width, Set interleaved) { + super(instance, start, width, interleaved); } + } } diff --git a/org.lflang/src/org/lflang/generator/SendRange.java b/org.lflang/src/org/lflang/generator/SendRange.java index c6f6221b5f..5e7f406f1e 100644 --- a/org.lflang/src/org/lflang/generator/SendRange.java +++ b/org.lflang/src/org/lflang/generator/SendRange.java @@ -32,286 +32,277 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.List; import java.util.Map; import java.util.Set; - import org.lflang.lf.Connection; /** - * Class representing a range of a port that sources data - * together with a list of destination ranges of other ports that should all - * receive the same data sent in this range. - * All ranges in the destinations list have widths that are an integer - * multiple N of this range but not necessarily the same start offsets. - * - * This class and subclasses are designed to be immutable. - * Modifications always return a new RuntimeRange. + * Class representing a range of a port that sources data together with a list of destination ranges + * of other ports that should all receive the same data sent in this range. All ranges in the + * destinations list have widths that are an integer multiple N of this range but not necessarily + * the same start offsets. + * + *

    This class and subclasses are designed to be immutable. Modifications always return a new + * RuntimeRange. * * @author Edward A. Lee -*/ + */ public class SendRange extends RuntimeRange.Port { - - /** - * Create a new send range. - * @param instance The instance over which this is a range of. - * @param start The starting index. - * @param width The width. - * @param interleaved A list of parents that are interleaved or null if none. - * @param connection The connection that establishes this send or null if not unique or none. - */ - public SendRange( - PortInstance instance, - int start, - int width, - Set interleaved, - Connection connection - ) { - super(instance, start, width, interleaved); - this.connection = connection; - } - /** - * Create a new send range representing sending from the specified - * src to the specified dst. This preserves the interleaved status - * of both the src and dst. - * @param src The source range. - * @param dst The destination range. - * @param interleaved A list of parents that are interleaved or null if none. - * @param connection The connection that establishes this send or null if not unique or none. - */ - public SendRange( - RuntimeRange src, - RuntimeRange dst, - Set interleaved, - Connection connection - ) { - super(src.instance, src.start, src.width, interleaved); - destinations.add(dst); - _interleaved.addAll(src._interleaved); - this.connection = connection; - } + /** + * Create a new send range. + * + * @param instance The instance over which this is a range of. + * @param start The starting index. + * @param width The width. + * @param interleaved A list of parents that are interleaved or null if none. + * @param connection The connection that establishes this send or null if not unique or none. + */ + public SendRange( + PortInstance instance, + int start, + int width, + Set interleaved, + Connection connection) { + super(instance, start, width, interleaved); + this.connection = connection; + } - ////////////////////////////////////////////////////////// - //// Public variables + /** + * Create a new send range representing sending from the specified src to the specified dst. This + * preserves the interleaved status of both the src and dst. + * + * @param src The source range. + * @param dst The destination range. + * @param interleaved A list of parents that are interleaved or null if none. + * @param connection The connection that establishes this send or null if not unique or none. + */ + public SendRange( + RuntimeRange src, + RuntimeRange dst, + Set interleaved, + Connection connection) { + super(src.instance, src.start, src.width, interleaved); + destinations.add(dst); + _interleaved.addAll(src._interleaved); + this.connection = connection; + } - /** The connection that establishes this relationship or null if not unique or none. */ - public final Connection connection; - - /** The list of destination ranges to which this broadcasts. */ - public final List> destinations = new ArrayList<>(); + ////////////////////////////////////////////////////////// + //// Public variables - ////////////////////////////////////////////////////////// - //// Public methods + /** The connection that establishes this relationship or null if not unique or none. */ + public final Connection connection; - /** - * Add a destination to the list of destinations of this range. - * If the width of the destination is not a multiple of the width - * of this range, throw an exception. - * @throws IllegalArgumentException If the width doesn't match. - */ - public void addDestination(RuntimeRange dst) { - if (dst.width % width != 0) { - throw new IllegalArgumentException( - "Destination range width is not a multiple of sender's width"); - } - destinations.add(dst); - // Void any precomputed number of destinations. - _numberOfDestinationReactors = -1; + /** The list of destination ranges to which this broadcasts. */ + public final List> destinations = new ArrayList<>(); + + ////////////////////////////////////////////////////////// + //// Public methods + + /** + * Add a destination to the list of destinations of this range. If the width of the destination is + * not a multiple of the width of this range, throw an exception. + * + * @throws IllegalArgumentException If the width doesn't match. + */ + public void addDestination(RuntimeRange dst) { + if (dst.width % width != 0) { + throw new IllegalArgumentException( + "Destination range width is not a multiple of sender's width"); } - - /** - * Override the base class to add additional comparisons so that - * ordering is never ambiguous. This means that sorting will be deterministic. - * Note that this can return 0 even if equals() does not return true. - */ - @Override - public int compareTo(RuntimeRange o) { - int result = super.compareTo(o); - if (result == 0) { - // Longer destination lists come first. - if (destinations.size() > ((SendRange)o).destinations.size()) { - return -1; - } else if (destinations.size() == ((SendRange)o).destinations.size()) { - return instance.getFullName().compareTo(o.instance.getFullName()); - } else { - return 1; - } - } - return result; + destinations.add(dst); + // Void any precomputed number of destinations. + _numberOfDestinationReactors = -1; + } + + /** + * Override the base class to add additional comparisons so that ordering is never ambiguous. This + * means that sorting will be deterministic. Note that this can return 0 even if equals() does not + * return true. + */ + @Override + public int compareTo(RuntimeRange o) { + int result = super.compareTo(o); + if (result == 0) { + // Longer destination lists come first. + if (destinations.size() > ((SendRange) o).destinations.size()) { + return -1; + } else if (destinations.size() == ((SendRange) o).destinations.size()) { + return instance.getFullName().compareTo(o.instance.getFullName()); + } else { + return 1; + } } + return result; + } - /** - * Return the total number of destination reactors for this range. - * Specifically, this is the number of distinct runtime reactor instances - * that react to messages from this send range. - */ - public int getNumberOfDestinationReactors() { - if (_numberOfDestinationReactors < 0) { - // Has not been calculated before. Calculate now. - _numberOfDestinationReactors = 0; - Map> result = new HashMap<>(); - for (RuntimeRange destination : this.destinations) { - // The following set contains unique identifiers the parent reactors - // of destination ports. - Set parentIDs = destination.parentInstances(1); - Set previousParentIDs = result.get(destination.instance.parent); - if (previousParentIDs == null) { - result.put(destination.instance.parent, parentIDs); - } else { - previousParentIDs.addAll(parentIDs); - } - } - for (ReactorInstance parent : result.keySet()) { - _numberOfDestinationReactors += result.get(parent).size(); - } + /** + * Return the total number of destination reactors for this range. Specifically, this is the + * number of distinct runtime reactor instances that react to messages from this send range. + */ + public int getNumberOfDestinationReactors() { + if (_numberOfDestinationReactors < 0) { + // Has not been calculated before. Calculate now. + _numberOfDestinationReactors = 0; + Map> result = new HashMap<>(); + for (RuntimeRange destination : this.destinations) { + // The following set contains unique identifiers the parent reactors + // of destination ports. + Set parentIDs = destination.parentInstances(1); + Set previousParentIDs = result.get(destination.instance.parent); + if (previousParentIDs == null) { + result.put(destination.instance.parent, parentIDs); + } else { + previousParentIDs.addAll(parentIDs); } - return _numberOfDestinationReactors; + } + for (ReactorInstance parent : result.keySet()) { + _numberOfDestinationReactors += result.get(parent).size(); + } } + return _numberOfDestinationReactors; + } - /** - * Return a new SendRange that is identical to this range but - * with width reduced to the specified width. - * If the new width is greater than or equal to the width - * of this range, then return this range. - * If the newWidth is 0 or negative, return null. - * This overrides the base class to also apply head() - * to the destination list. - * @param newWidth The new width. - */ - @Override - public SendRange head(int newWidth) { - // NOTE: Cannot use the superclass because it returns a RuntimeRange, not a SendRange. - // Also, cannot return this without applying head() to the destinations. - if (newWidth <= 0) return null; + /** + * Return a new SendRange that is identical to this range but with width reduced to the specified + * width. If the new width is greater than or equal to the width of this range, then return this + * range. If the newWidth is 0 or negative, return null. This overrides the base class to also + * apply head() to the destination list. + * + * @param newWidth The new width. + */ + @Override + public SendRange head(int newWidth) { + // NOTE: Cannot use the superclass because it returns a RuntimeRange, not a SendRange. + // Also, cannot return this without applying head() to the destinations. + if (newWidth <= 0) return null; - SendRange result = new SendRange(instance, start, newWidth, _interleaved, connection); - - for (RuntimeRange destination : destinations) { - result.destinations.add(destination.head(newWidth)); - } - return result; + SendRange result = new SendRange(instance, start, newWidth, _interleaved, connection); + + for (RuntimeRange destination : destinations) { + result.destinations.add(destination.head(newWidth)); } + return result; + } - /** - * Return a range that is the subset of this range that overlaps with the - * specified range or null if there is no overlap. - */ - @Override - public SendRange overlap(RuntimeRange range) { - if (!overlaps(range)) return null; - if (range.start == start && range.width == width) return this; - int newStart = Math.max(start, range.start); - int newEnd = Math.min(start + width, range.start + range.width); - int newWidth = newEnd - newStart; - SendRange result = new SendRange(instance, newStart, newWidth, _interleaved, connection); - result._interleaved.addAll(_interleaved); - for (RuntimeRange destination : destinations) { - // The destination width is a multiple of this range's width. - // If the multiple is greater than 1, then the destination needs to - // split into multiple destinations. - while (destination != null) { - int dstStart = destination.start + (newStart - start); - RuntimeRange.Port dst = new RuntimeRange.Port( - destination.instance, - dstStart, - newWidth, - destination._interleaved - ); - result.addDestination(dst); - destination = destination.tail(width); - } - } - return result; + /** + * Return a range that is the subset of this range that overlaps with the specified range or null + * if there is no overlap. + */ + @Override + public SendRange overlap(RuntimeRange range) { + if (!overlaps(range)) return null; + if (range.start == start && range.width == width) return this; + int newStart = Math.max(start, range.start); + int newEnd = Math.min(start + width, range.start + range.width); + int newWidth = newEnd - newStart; + SendRange result = new SendRange(instance, newStart, newWidth, _interleaved, connection); + result._interleaved.addAll(_interleaved); + for (RuntimeRange destination : destinations) { + // The destination width is a multiple of this range's width. + // If the multiple is greater than 1, then the destination needs to + // split into multiple destinations. + while (destination != null) { + int dstStart = destination.start + (newStart - start); + RuntimeRange.Port dst = + new RuntimeRange.Port( + destination.instance, dstStart, newWidth, destination._interleaved); + result.addDestination(dst); + destination = destination.tail(width); + } } + return result; + } - /** - * Return a new SendRange that represents the leftover elements - * starting at the specified offset. If the offset is greater - * than or equal to the width, then this returns null. - * If this offset is 0 then this returns this range unmodified. - * This overrides the base class to also apply tail() - * to the destination list. - * @param offset The number of elements to consume. - */ - @Override - public SendRange tail(int offset) { - // NOTE: Cannot use the superclass because it returns a RuntimeRange, not a SendRange. - // Also, cannot return this without applying tail() to the destinations. - if (offset >= width) return null; - SendRange result = new SendRange( - instance, start + offset, width - offset, _interleaved, connection); + /** + * Return a new SendRange that represents the leftover elements starting at the specified offset. + * If the offset is greater than or equal to the width, then this returns null. If this offset is + * 0 then this returns this range unmodified. This overrides the base class to also apply tail() + * to the destination list. + * + * @param offset The number of elements to consume. + */ + @Override + public SendRange tail(int offset) { + // NOTE: Cannot use the superclass because it returns a RuntimeRange, not a SendRange. + // Also, cannot return this without applying tail() to the destinations. + if (offset >= width) return null; + SendRange result = + new SendRange(instance, start + offset, width - offset, _interleaved, connection); - for (RuntimeRange destination : destinations) { - result.destinations.add(destination.tail(offset)); - } - return result; + for (RuntimeRange destination : destinations) { + result.destinations.add(destination.tail(offset)); } + return result; + } - @Override - public String toString() { - StringBuilder result = new StringBuilder(); - result.append(super.toString()); - result.append("->["); - List dsts = new LinkedList<>(); - for (RuntimeRange dst : destinations) { - dsts.add(dst.toString()); - } - result.append(String.join(", ", dsts)); - result.append("]"); - return result.toString(); + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(super.toString()); + result.append("->["); + List dsts = new LinkedList<>(); + for (RuntimeRange dst : destinations) { + dsts.add(dst.toString()); } + result.append(String.join(", ", dsts)); + result.append("]"); + return result.toString(); + } + + ////////////////////////////////////////////////////////// + //// Protected methods - ////////////////////////////////////////////////////////// - //// Protected methods + /** + * Assuming that this SendRange is completely contained by one of the destinations of the + * specified srcRange, return a new SendRange where the send range is the subrange of the + * specified srcRange that overlaps with this SendRange and the destinations include all the + * destinations of this SendRange. If the assumption is not satisfied, throw an + * IllegalArgumentException. + * + *

    If any parent of this range is marked interleaved and is also a parent of the specified + * srcRange, then that parent will be marked interleaved in the result. + * + * @param srcRange A new source range. + * @param srcRangeOffset An offset into the source range. + */ + protected SendRange newSendRange(SendRange srcRange, int srcRangeOffset) { + // Every destination of srcRange receives all channels of srcRange (multicast). + // Find which multicast destination overlaps with this srcRange. + for (RuntimeRange srcDestination : srcRange.destinations) { + RuntimeRange overlap = srcDestination.overlap(this); + if (overlap == null) continue; // Not this one. - /** - * Assuming that this SendRange is completely contained by one - * of the destinations of the specified srcRange, return a new SendRange - * where the send range is the subrange of the specified srcRange that - * overlaps with this SendRange and the destinations include all the - * destinations of this SendRange. If the assumption is not satisfied, - * throw an IllegalArgumentException. - * - * If any parent of this range is marked interleaved and is also a parent of the - * specified srcRange, then that parent will be marked interleaved - * in the result. - * - * @param srcRange A new source range. - * @param srcRangeOffset An offset into the source range. - */ - protected SendRange newSendRange(SendRange srcRange, int srcRangeOffset) { - // Every destination of srcRange receives all channels of srcRange (multicast). - // Find which multicast destination overlaps with this srcRange. - for (RuntimeRange srcDestination : srcRange.destinations) { - RuntimeRange overlap = srcDestination.overlap(this); - if (overlap == null) continue; // Not this one. - - if (overlap.width == width) { - // Found an overlap that is completely contained. - // If this width is greater than the srcRange width, - // then assume srcRange is multicasting via this. - int newWidth = Math.min(width, srcRange.width); - // The interleaving of the result is the union of the two interleavings. - Set interleaving = new LinkedHashSet<>(); - interleaving.addAll(_interleaved); - interleaving.addAll(srcRange._interleaved); - SendRange result = new SendRange( - srcRange.instance, - srcRange.start + srcRangeOffset, - newWidth, - interleaving, - connection); - for (RuntimeRange dst : destinations) { - result.addDestination(dst); - } - return result; - } + if (overlap.width == width) { + // Found an overlap that is completely contained. + // If this width is greater than the srcRange width, + // then assume srcRange is multicasting via this. + int newWidth = Math.min(width, srcRange.width); + // The interleaving of the result is the union of the two interleavings. + Set interleaving = new LinkedHashSet<>(); + interleaving.addAll(_interleaved); + interleaving.addAll(srcRange._interleaved); + SendRange result = + new SendRange( + srcRange.instance, + srcRange.start + srcRangeOffset, + newWidth, + interleaving, + connection); + for (RuntimeRange dst : destinations) { + result.addDestination(dst); } - throw new IllegalArgumentException( - "Expected this SendRange " + this - + " to be completely contained by a destination of " + srcRange); + return result; + } } + throw new IllegalArgumentException( + "Expected this SendRange " + + this + + " to be completely contained by a destination of " + + srcRange); + } - ////////////////////////////////////////////////////////// - //// Private variables + ////////////////////////////////////////////////////////// + //// Private variables - private int _numberOfDestinationReactors = -1; // Never access this directly. + private int _numberOfDestinationReactors = -1; // Never access this directly. } diff --git a/org.lflang/src/org/lflang/generator/SubContext.java b/org.lflang/src/org/lflang/generator/SubContext.java index 5e7a981ab8..cf90cb1fda 100644 --- a/org.lflang/src/org/lflang/generator/SubContext.java +++ b/org.lflang/src/org/lflang/generator/SubContext.java @@ -1,90 +1,88 @@ package org.lflang.generator; -import java.io.File; import java.util.Properties; - import org.eclipse.xtext.util.CancelIndicator; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; /** - * A {@code SubContext} is the context of a process within a build process. For example, - * compilation of generated code may optionally be given a {@code SubContext} because - * compilation is part of a complete build. + * A {@code SubContext} is the context of a process within a build process. For example, compilation + * of generated code may optionally be given a {@code SubContext} because compilation is part of a + * complete build. * * @author Peter Donovan */ public class SubContext implements LFGeneratorContext { - private final LFGeneratorContext containingContext; - private final int startPercentProgress; - private final int endPercentProgress; - private GeneratorResult result = null; - - protected ErrorReporter errorReporter; - - /** - * Initializes the context within {@code containingContext} of the process that extends from - * {@code startPercentProgress} to {@code endPercentProgress}. - * @param containingContext The context of the containing build process. - * @param startPercentProgress The percent progress of the containing build process when this - * nested process starts. - * @param endPercentProgress The percent progress of the containing build process when this - * nested process ends. - */ - public SubContext(LFGeneratorContext containingContext, int startPercentProgress, int endPercentProgress) { - this.containingContext = containingContext; - this.startPercentProgress = startPercentProgress; - this.endPercentProgress = endPercentProgress; - } - - @Override - public CancelIndicator getCancelIndicator() { - return containingContext.getCancelIndicator(); - } - - @Override - public Mode getMode() { - return containingContext.getMode(); - } - - @Override - public Properties getArgs() { - return containingContext.getArgs(); - } - - @Override - public ErrorReporter getErrorReporter() { - return containingContext.getErrorReporter(); - } - - @Override - public void finish(GeneratorResult result) { - this.result = result; - } - - @Override - public GeneratorResult getResult() { - return result; - } - - @Override - public FileConfig getFileConfig() { - return containingContext.getFileConfig(); - } - - @Override - public TargetConfig getTargetConfig() { - return containingContext.getTargetConfig(); - } - - @Override - public void reportProgress(String message, int percentage) { - containingContext.reportProgress( - message, - startPercentProgress * (100 - percentage) / 100 + endPercentProgress * percentage / 100 - ); - } + private final LFGeneratorContext containingContext; + private final int startPercentProgress; + private final int endPercentProgress; + private GeneratorResult result = null; + + protected ErrorReporter errorReporter; + + /** + * Initializes the context within {@code containingContext} of the process that extends from + * {@code startPercentProgress} to {@code endPercentProgress}. + * + * @param containingContext The context of the containing build process. + * @param startPercentProgress The percent progress of the containing build process when this + * nested process starts. + * @param endPercentProgress The percent progress of the containing build process when this nested + * process ends. + */ + public SubContext( + LFGeneratorContext containingContext, int startPercentProgress, int endPercentProgress) { + this.containingContext = containingContext; + this.startPercentProgress = startPercentProgress; + this.endPercentProgress = endPercentProgress; + } + + @Override + public CancelIndicator getCancelIndicator() { + return containingContext.getCancelIndicator(); + } + + @Override + public Mode getMode() { + return containingContext.getMode(); + } + + @Override + public Properties getArgs() { + return containingContext.getArgs(); + } + + @Override + public ErrorReporter getErrorReporter() { + return containingContext.getErrorReporter(); + } + + @Override + public void finish(GeneratorResult result) { + this.result = result; + } + + @Override + public GeneratorResult getResult() { + return result; + } + + @Override + public FileConfig getFileConfig() { + return containingContext.getFileConfig(); + } + + @Override + public TargetConfig getTargetConfig() { + return containingContext.getTargetConfig(); + } + + @Override + public void reportProgress(String message, int percentage) { + containingContext.reportProgress( + message, + startPercentProgress * (100 - percentage) / 100 + endPercentProgress * percentage / 100); + } } diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index 585d65c96a..eda5cffd11 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -3,10 +3,9 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; - -import org.lflang.ast.ASTUtils; import org.lflang.InferredType; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.lf.Action; import org.lflang.lf.BracedListExpression; import org.lflang.lf.CodeExpr; @@ -21,257 +20,217 @@ import org.lflang.lf.Type; /** - * Information about the types of a target language. Contains - * utilities to convert LF expressions and types to the target - * language. Each code generator is expected to use at least one + * Information about the types of a target language. Contains utilities to convert LF expressions + * and types to the target language. Each code generator is expected to use at least one * language-specific instance of this interface. - *

    - * TODO currently, {@link GeneratorBase} implements this interface, - * it should instead contain an instance. + * + *

    TODO currently, {@link GeneratorBase} implements this interface, it should instead contain an + * instance. * * @author Clément Fournier - TU Dresden, INSA Rennes */ public interface TargetTypes { - - /** - * Return true if the target supports generics (i.e., parametric - * polymorphism), false otherwise. - */ - boolean supportsGenerics(); - - - /** - * Return the type of time durations. - */ - String getTargetTimeType(); - - - /** - * Return the type of tags. - */ - String getTargetTagType(); - - - /** - * Return the type of fixed sized lists (or arrays). - */ - String getTargetFixedSizeListType(String baseType, int size); - - - /** - * Return the type of variable sized lists (eg {@code std::vector}). - */ - String getTargetVariableSizeListType(String baseType); - - - default String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return escapeIdentifier(expr.getParameter().getName()); - } - - /** Translate the braced list expression into target language syntax. */ - default String getTargetBracedListExpr(BracedListExpression expr, InferredType typeOrNull) { - InferredType t = typeOrNull == null ? InferredType.undefined() : typeOrNull; - return expr.getItems().stream().map(e -> getTargetExpr(e, t)) - .collect(Collectors.joining(",", "{", "}")); - } - - /** - * Return an "undefined" type which is used as a default - * when a type cannot be inferred. - */ - String getTargetUndefinedType(); - - /** - * Returns a version of the given LF identifier that is - * escaped properly for insertion into a piece of target - * code. - */ - default String escapeIdentifier(String ident) { - return ident; - } - - /** - * Returns an expression in the target language that corresponds - * to the given time value ({@link #getTargetTimeType()}). - */ - default String getTargetTimeExpr(TimeValue timeValue) { - // todo make non-default when we reuse this for all generators, - // all targets should support this. - Objects.requireNonNull(timeValue); - throw new UnsupportedGeneratorFeatureException("Time expressions"); - } - - /** - * Returns an expression in the target language that corresponds - * to a variable-size list expression. - * - * @throws UnsupportedGeneratorFeatureException If the target does not support this - */ - default String getVariableSizeListInitExpression(List contents, boolean withBraces) { - throw new UnsupportedGeneratorFeatureException("Variable size lists"); - } - - /** - * Returns an expression in the target language that corresponds - * to a fixed-size list expression. - * - * @throws UnsupportedGeneratorFeatureException If the target does not support this - */ - default String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { - throw new UnsupportedGeneratorFeatureException("Fixed size lists"); - } - - - /** - * Returns the expression that is used to replace a - * missing expression in the source language. The expression - * may for instance be a type-agnostic default value - * (e.g. Rust's {@code Default::default()}), or produce - * a compiler error (e.g. Rust's {@code compiler_error!("missing initializer")}). - * - * @throws UnsupportedGeneratorFeatureException If the target does not support this - */ - default String getMissingExpr(InferredType type) { - throw new UnsupportedGeneratorFeatureException("Missing initializers"); - } - - - /** - * Returns a target type inferred from the type node, or the - * initializer list. If both are absent, then the undefined - * type is returned. - */ - default String getTargetType(Type type, Initializer init) { - return getTargetType(ASTUtils.getInferredType(type, init)); - } - - /** - * Returns the target type of the type node. This just provides - * a default parameter for {@link #getTargetType(Type, Initializer)}. - * If the parameter is null, then the undefined type is returned. - */ - default String getTargetType(Type type) { - return getTargetType(type, null); - } - - /** - * Return a string representing the specified type in the - * target language. - */ - default String getTargetType(InferredType type) { - if (type.isUndefined()) { - return getTargetUndefinedType(); - } else if (type.isTime) { - if (type.isFixedSizeList) { - return getTargetFixedSizeListType(getTargetTimeType(), type.listSize); - } else if (type.isVariableSizeList) { - return getTargetVariableSizeListType(getTargetTimeType()); - } else { - return getTargetTimeType(); - } - } else if (type.isFixedSizeList) { - return getTargetFixedSizeListType(type.baseType(), type.listSize); - } else if (type.isVariableSizeList) { - return getTargetVariableSizeListType(type.baseType()); - } else if (!type.astType.getTypeArgs().isEmpty()) { - List args = type.astType.getTypeArgs().stream().map(this::getTargetType).toList(); - return getGenericType(type.baseType(), args); - } - return type.toOriginalText(); - } - - /** Build a generic type. The type args list must not be empty. */ - default String getGenericType(String base, List args) { - assert !args.isEmpty() : "Empty type arguments for " + base; - return base + "<" + String.join(", ", args) + ">"; - } - - /** - * Return a string representing the type of the given - * parameter. - */ - default String getTargetType(Parameter p) { - return getTargetType(ASTUtils.getInferredType(p)); - } - - /** - * Return a string representing the type of the given - * state variable. - */ - default String getTargetType(StateVar s) { - return getTargetType(ASTUtils.getInferredType(s)); - } - - /** - * Return a string representing the type of the given - * action. - */ - default String getTargetType(Action a) { - return getTargetType(ASTUtils.getInferredType(a)); - } - - /** - * Return a string representing the type of the given - * port. - */ - default String getTargetType(Port p) { - return getTargetType(ASTUtils.getInferredType(p)); - } - - /** - * Returns the representation of the given initializer - * expression in target code. The given type, if non-null, - * may inform the code generation. - * - * @param init Initializer node (nullable) - * @param type Declared type of the expression (nullable) - */ - default String getTargetInitializer(Initializer init, Type type) { - var inferredType = ASTUtils.getInferredType(type, init); - if (init == null) { - return getMissingExpr(inferredType); - } - var single = ASTUtils.asSingleExpr(init); - if (single != null) { - return getTargetExpr(single, inferredType); - } - var targetValues = init.getExprs().stream().map(it -> getTargetExpr(it, inferredType)).collect(Collectors.toList()); - if (inferredType.isFixedSizeList) { - return getFixedSizeListInitExpression(targetValues, inferredType.listSize, init.isBraces()); - } else { - return getVariableSizeListInitExpression(targetValues, init.isBraces()); - } - } - - - /** - * Returns the representation of the given expression in target code. - * The given type, if non-null, may inform the code generation. - */ - default String getTargetExpr(Expression expr, InferredType type) { - if (ASTUtils.isZero(expr) && type != null && type.isTime) { - return getTargetTimeExpr(TimeValue.ZERO); - } else if (expr instanceof ParameterReference) { - return getTargetParamRef((ParameterReference) expr, type); - } else if (expr instanceof Time) { - return getTargetTimeExpr((Time) expr); - } else if (expr instanceof Literal) { - return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape - } else if (expr instanceof CodeExpr) { - return ASTUtils.toText(((CodeExpr) expr).getCode()); - } else if (expr instanceof BracedListExpression) { - return getTargetBracedListExpr((BracedListExpression) expr, type); - } else { - throw new IllegalStateException("Invalid value " + expr); - } - } - - /** - * Returns the representation of the given time value in - * target code. - */ - default String getTargetTimeExpr(Time t) { - return getTargetTimeExpr(ASTUtils.toTimeValue(t)); - } + /** + * Return true if the target supports generics (i.e., parametric polymorphism), false otherwise. + */ + boolean supportsGenerics(); + + /** Return the type of time durations. */ + String getTargetTimeType(); + + /** Return the type of tags. */ + String getTargetTagType(); + + /** Return the type of fixed sized lists (or arrays). */ + String getTargetFixedSizeListType(String baseType, int size); + + /** Return the type of variable sized lists (eg {@code std::vector}). */ + String getTargetVariableSizeListType(String baseType); + + default String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return escapeIdentifier(expr.getParameter().getName()); + } + + /** Translate the braced list expression into target language syntax. */ + default String getTargetBracedListExpr(BracedListExpression expr, InferredType typeOrNull) { + InferredType t = typeOrNull == null ? InferredType.undefined() : typeOrNull; + return expr.getItems().stream() + .map(e -> getTargetExpr(e, t)) + .collect(Collectors.joining(",", "{", "}")); + } + + /** Return an "undefined" type which is used as a default when a type cannot be inferred. */ + String getTargetUndefinedType(); + + /** + * Returns a version of the given LF identifier that is escaped properly for insertion into a + * piece of target code. + */ + default String escapeIdentifier(String ident) { + return ident; + } + + /** + * Returns an expression in the target language that corresponds to the given time value ({@link + * #getTargetTimeType()}). + */ + default String getTargetTimeExpr(TimeValue timeValue) { + // todo make non-default when we reuse this for all generators, + // all targets should support this. + Objects.requireNonNull(timeValue); + throw new UnsupportedGeneratorFeatureException("Time expressions"); + } + + /** + * Returns an expression in the target language that corresponds to a variable-size list + * expression. + * + * @throws UnsupportedGeneratorFeatureException If the target does not support this + */ + default String getVariableSizeListInitExpression(List contents, boolean withBraces) { + throw new UnsupportedGeneratorFeatureException("Variable size lists"); + } + + /** + * Returns an expression in the target language that corresponds to a fixed-size list expression. + * + * @throws UnsupportedGeneratorFeatureException If the target does not support this + */ + default String getFixedSizeListInitExpression( + List contents, int listSize, boolean withBraces) { + throw new UnsupportedGeneratorFeatureException("Fixed size lists"); + } + + /** + * Returns the expression that is used to replace a missing expression in the source language. The + * expression may for instance be a type-agnostic default value (e.g. Rust's {@code + * Default::default()}), or produce a compiler error (e.g. Rust's {@code compiler_error!("missing + * initializer")}). + * + * @throws UnsupportedGeneratorFeatureException If the target does not support this + */ + default String getMissingExpr(InferredType type) { + throw new UnsupportedGeneratorFeatureException("Missing initializers"); + } + + /** + * Returns a target type inferred from the type node, or the initializer list. If both are absent, + * then the undefined type is returned. + */ + default String getTargetType(Type type, Initializer init) { + return getTargetType(ASTUtils.getInferredType(type, init)); + } + + /** + * Returns the target type of the type node. This just provides a default parameter for {@link + * #getTargetType(Type, Initializer)}. If the parameter is null, then the undefined type is + * returned. + */ + default String getTargetType(Type type) { + return getTargetType(type, null); + } + + /** Return a string representing the specified type in the target language. */ + default String getTargetType(InferredType type) { + if (type.isUndefined()) { + return getTargetUndefinedType(); + } else if (type.isTime) { + if (type.isFixedSizeList) { + return getTargetFixedSizeListType(getTargetTimeType(), type.listSize); + } else if (type.isVariableSizeList) { + return getTargetVariableSizeListType(getTargetTimeType()); + } else { + return getTargetTimeType(); + } + } else if (type.isFixedSizeList) { + return getTargetFixedSizeListType(type.baseType(), type.listSize); + } else if (type.isVariableSizeList) { + return getTargetVariableSizeListType(type.baseType()); + } else if (!type.astType.getTypeArgs().isEmpty()) { + List args = type.astType.getTypeArgs().stream().map(this::getTargetType).toList(); + return getGenericType(type.baseType(), args); + } + return type.toOriginalText(); + } + + /** Build a generic type. The type args list must not be empty. */ + default String getGenericType(String base, List args) { + assert !args.isEmpty() : "Empty type arguments for " + base; + return base + "<" + String.join(", ", args) + ">"; + } + + /** Return a string representing the type of the given parameter. */ + default String getTargetType(Parameter p) { + return getTargetType(ASTUtils.getInferredType(p)); + } + + /** Return a string representing the type of the given state variable. */ + default String getTargetType(StateVar s) { + return getTargetType(ASTUtils.getInferredType(s)); + } + + /** Return a string representing the type of the given action. */ + default String getTargetType(Action a) { + return getTargetType(ASTUtils.getInferredType(a)); + } + + /** Return a string representing the type of the given port. */ + default String getTargetType(Port p) { + return getTargetType(ASTUtils.getInferredType(p)); + } + + /** + * Returns the representation of the given initializer expression in target code. The given type, + * if non-null, may inform the code generation. + * + * @param init Initializer node (nullable) + * @param type Declared type of the expression (nullable) + */ + default String getTargetInitializer(Initializer init, Type type) { + var inferredType = ASTUtils.getInferredType(type, init); + if (init == null) { + return getMissingExpr(inferredType); + } + var single = ASTUtils.asSingleExpr(init); + if (single != null) { + return getTargetExpr(single, inferredType); + } + var targetValues = + init.getExprs().stream() + .map(it -> getTargetExpr(it, inferredType)) + .collect(Collectors.toList()); + if (inferredType.isFixedSizeList) { + return getFixedSizeListInitExpression(targetValues, inferredType.listSize, init.isBraces()); + } else { + return getVariableSizeListInitExpression(targetValues, init.isBraces()); + } + } + + /** + * Returns the representation of the given expression in target code. The given type, if non-null, + * may inform the code generation. + */ + default String getTargetExpr(Expression expr, InferredType type) { + if (ASTUtils.isZero(expr) && type != null && type.isTime) { + return getTargetTimeExpr(TimeValue.ZERO); + } else if (expr instanceof ParameterReference) { + return getTargetParamRef((ParameterReference) expr, type); + } else if (expr instanceof Time) { + return getTargetTimeExpr((Time) expr); + } else if (expr instanceof Literal) { + return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape + } else if (expr instanceof CodeExpr) { + return ASTUtils.toText(((CodeExpr) expr).getCode()); + } else if (expr instanceof BracedListExpression) { + return getTargetBracedListExpr((BracedListExpression) expr, type); + } else { + throw new IllegalStateException("Invalid value " + expr); + } + } + + /** Returns the representation of the given time value in target code. */ + default String getTargetTimeExpr(Time t) { + return getTargetTimeExpr(ASTUtils.toTimeValue(t)); + } } diff --git a/org.lflang/src/org/lflang/generator/TimerInstance.java b/org.lflang/src/org/lflang/generator/TimerInstance.java index 492398998c..b25552bb6c 100644 --- a/org.lflang/src/org/lflang/generator/TimerInstance.java +++ b/org.lflang/src/org/lflang/generator/TimerInstance.java @@ -1,28 +1,28 @@ /** Instance of a timer. */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; @@ -31,63 +31,58 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY /** * Instance of a timer. - * + * * @author Marten Lohstroh * @author Edward A. Lee */ public class TimerInstance extends TriggerInstance { - /** The global default for offset. */ - public static final TimeValue DEFAULT_OFFSET = TimeValue.ZERO; + /** The global default for offset. */ + public static final TimeValue DEFAULT_OFFSET = TimeValue.ZERO; - /** The global default for period. */ - public static final TimeValue DEFAULT_PERIOD = TimeValue.ZERO; + /** The global default for period. */ + public static final TimeValue DEFAULT_PERIOD = TimeValue.ZERO; - private TimeValue offset = DEFAULT_OFFSET; + private TimeValue offset = DEFAULT_OFFSET; - private TimeValue period = DEFAULT_PERIOD; + private TimeValue period = DEFAULT_PERIOD; - /** - * Create a new timer instance. - * If the definition is null, then this is a startup timer. - * @param definition The AST definition, or null for startup. - * @param parent The parent reactor. - */ - public TimerInstance(Timer definition, ReactorInstance parent) { - super(definition, parent); - if (parent == null) { - throw new InvalidSourceException("Cannot create an TimerInstance with no parent."); + /** + * Create a new timer instance. If the definition is null, then this is a startup timer. + * + * @param definition The AST definition, or null for startup. + * @param parent The parent reactor. + */ + public TimerInstance(Timer definition, ReactorInstance parent) { + super(definition, parent); + if (parent == null) { + throw new InvalidSourceException("Cannot create an TimerInstance with no parent."); + } + if (definition != null) { + if (definition.getOffset() != null) { + try { + this.offset = parent.getTimeValue(definition.getOffset()); + } catch (IllegalArgumentException ex) { + parent.reporter.reportError(definition.getOffset(), "Invalid time."); } - if (definition != null) { - if (definition.getOffset() != null) { - try { - this.offset = parent.getTimeValue(definition.getOffset()); - } catch (IllegalArgumentException ex) { - parent.reporter.reportError(definition.getOffset(), "Invalid time."); - } - } - if (definition.getPeriod() != null) { - try { - this.period = parent.getTimeValue(definition.getPeriod()); - } catch (IllegalArgumentException ex) { - parent.reporter.reportError(definition.getPeriod(), "Invalid time."); - } - } + } + if (definition.getPeriod() != null) { + try { + this.period = parent.getTimeValue(definition.getPeriod()); + } catch (IllegalArgumentException ex) { + parent.reporter.reportError(definition.getPeriod(), "Invalid time."); } + } } + } - /** - * Get the value of the offset parameter. - */ - public TimeValue getOffset() { - return offset; - } - - /** - * Get the value of the offset parameter. - */ - public TimeValue getPeriod() { - return period; - } + /** Get the value of the offset parameter. */ + public TimeValue getOffset() { + return offset; + } + /** Get the value of the offset parameter. */ + public TimeValue getPeriod() { + return period; + } } diff --git a/org.lflang/src/org/lflang/generator/TriggerInstance.java b/org.lflang/src/org/lflang/generator/TriggerInstance.java index 47212ff0e8..b4ddc35a15 100644 --- a/org.lflang/src/org/lflang/generator/TriggerInstance.java +++ b/org.lflang/src/org/lflang/generator/TriggerInstance.java @@ -1,181 +1,170 @@ /** Instance of a trigger (port, action, or timer). */ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator; import java.util.LinkedHashSet; import java.util.Set; - import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.TriggerRef; import org.lflang.lf.Variable; import org.lflang.lf.impl.VariableImpl; -/** Instance of a trigger (port, action, or timer). +/** + * Instance of a trigger (port, action, or timer). * - * @author Marten Lohstroh - * @author Edward A. Lee - * @author Alexander Schulz-Rosengarten + * @author Marten Lohstroh + * @author Edward A. Lee + * @author Alexander Schulz-Rosengarten */ public class TriggerInstance extends NamedInstance { - /** Construct a new instance with the specified definition - * and parent. E.g., for a action instance, the definition - * is Action, and for a port instance, it is Port. These are - * nodes in the AST. This is protected because only subclasses - * should be constructed. - * @param definition The definition in the AST for this instance. - * @param parent The reactor instance that creates this instance. - */ - protected TriggerInstance(T definition, ReactorInstance parent) { - super(definition, parent); - } - - /** - * Construct a new instance for a special builtin trigger. - * - * @param trigger The actual trigger definition. - * @param parent The reactor instance that creates this instance. - */ - static TriggerInstance builtinTrigger(BuiltinTriggerRef trigger, ReactorInstance parent) { - return new TriggerInstance<>(new BuiltinTriggerVariable(trigger), parent); - } - - ///////////////////////////////////////////// - //// Public Methods - - /** - * Return the reaction instances that are triggered or read by this trigger. - * If this port is an output, then the reaction instances - * belong to the parent of the port's parent. If the port - * is an input, then the reaction instances belong to the - * port's parent. - */ - public Set getDependentReactions() { - return dependentReactions; + /** + * Construct a new instance with the specified definition and parent. E.g., for a action instance, + * the definition is Action, and for a port instance, it is Port. These are nodes in the AST. This + * is protected because only subclasses should be constructed. + * + * @param definition The definition in the AST for this instance. + * @param parent The reactor instance that creates this instance. + */ + protected TriggerInstance(T definition, ReactorInstance parent) { + super(definition, parent); + } + + /** + * Construct a new instance for a special builtin trigger. + * + * @param trigger The actual trigger definition. + * @param parent The reactor instance that creates this instance. + */ + static TriggerInstance builtinTrigger( + BuiltinTriggerRef trigger, ReactorInstance parent) { + return new TriggerInstance<>(new BuiltinTriggerVariable(trigger), parent); + } + + ///////////////////////////////////////////// + //// Public Methods + + /** + * Return the reaction instances that are triggered or read by this trigger. If this port is an + * output, then the reaction instances belong to the parent of the port's parent. If the port is + * an input, then the reaction instances belong to the port's parent. + */ + public Set getDependentReactions() { + return dependentReactions; + } + + /** + * Return the reaction instances that may send data via this port. If this port is an input, then + * the reaction instance belongs to parent of the port's parent. If it is an output, the reaction + * instance belongs to the port's parent. + */ + public Set getDependsOnReactions() { + return dependsOnReactions; + } + + /** + * Return the name of this trigger. + * + * @return The name of this trigger. + */ + @Override + public String getName() { + return definition.getName(); + } + + /** Return true if this trigger is "shutdown". */ + public boolean isShutdown() { + return isBuiltInType(BuiltinTrigger.SHUTDOWN); + } + + /** Return true if this trigger is "startup"./ */ + public boolean isStartup() { + return isBuiltInType(BuiltinTrigger.STARTUP); + } + + /** Return true if this trigger is "startup"./ */ + public boolean isReset() { + return isBuiltInType(BuiltinTrigger.RESET); + } + + ///////////////////////////////////////////// + //// Private Methods + + private boolean isBuiltInType(BuiltinTrigger type) { + return this.definition instanceof BuiltinTriggerVariable + && ((BuiltinTriggerRef) ((BuiltinTriggerVariable) this.definition).definition) + .getType() + .equals(type); + } + + ///////////////////////////////////////////// + //// Protected Fields + + /** + * Reaction instances that are triggered or read by this trigger. If this port is an output, then + * the reaction instances belong to the parent of the port's parent. If the port is an input, then + * the reaction instances belong to the port's parent. + */ + Set dependentReactions = new LinkedHashSet<>(); + + /** + * Reaction instances that may send data via this port. If this port is an input, then the + * reaction instance belongs to parent of the port's parent. If it is an output, the reaction + * instance belongs to the port's parent. + */ + Set dependsOnReactions = new LinkedHashSet<>(); + + ///////////////////////////////////////////// + //// Special class for builtin triggers + + /** This class allows to have BuiltinTriggers represented by a Variable type. */ + public static class BuiltinTriggerVariable extends VariableImpl { + + /** The builtin trigger type represented by this variable. */ + public final BuiltinTrigger type; + + /** The actual TriggerRef definition in the AST. */ + public final TriggerRef definition; + + public BuiltinTriggerVariable(BuiltinTriggerRef trigger) { + this.type = trigger.getType(); + this.definition = trigger; } - /** - * Return the reaction instances that may send data via this port. - * If this port is an input, then the reaction instance - * belongs to parent of the port's parent. If it is an output, - * the reaction instance belongs to the port's parent. - */ - public Set getDependsOnReactions() { - return dependsOnReactions; - } - - /** - * Return the name of this trigger. - * @return The name of this trigger. - */ @Override public String getName() { - return definition.getName(); - } - - /** - * Return true if this trigger is "shutdown". - */ - public boolean isShutdown() { - return isBuiltInType(BuiltinTrigger.SHUTDOWN); - } - - /** - * Return true if this trigger is "startup"./ - */ - public boolean isStartup() { - return isBuiltInType(BuiltinTrigger.STARTUP); + return this.type.name().toLowerCase(); } - /** - * Return true if this trigger is "startup"./ - */ - public boolean isReset() { - return isBuiltInType(BuiltinTrigger.RESET); - } - - ///////////////////////////////////////////// - //// Private Methods - - private boolean isBuiltInType(BuiltinTrigger type) { - return this.definition instanceof BuiltinTriggerVariable - && ((BuiltinTriggerRef) ((BuiltinTriggerVariable) this.definition).definition).getType().equals(type); - } - - ///////////////////////////////////////////// - //// Protected Fields - - - /** - * Reaction instances that are triggered or read by this trigger. - * If this port is an output, then the reaction instances - * belong to the parent of the port's parent. If the port - * is an input, then the reaction instances belong to the - * port's parent. - */ - Set dependentReactions = new LinkedHashSet<>(); - - /** - * Reaction instances that may send data via this port. - * If this port is an input, then the reaction instance - * belongs to parent of the port's parent. If it is an output, - * the reaction instance belongs to the port's parent. - */ - Set dependsOnReactions = new LinkedHashSet<>(); - - ///////////////////////////////////////////// - //// Special class for builtin triggers - - /** - * This class allows to have BuiltinTriggers represented by a Variable type. - */ - static public class BuiltinTriggerVariable extends VariableImpl { - - /** The builtin trigger type represented by this variable. */ - public final BuiltinTrigger type; - - /** The actual TriggerRef definition in the AST. */ - public final TriggerRef definition; - - public BuiltinTriggerVariable(BuiltinTriggerRef trigger) { - this.type = trigger.getType(); - this.definition = trigger; - } - - @Override - public String getName() { - return this.type.name().toLowerCase(); - } - - @Override - public void setName(String newName) { - throw new UnsupportedOperationException( - this.getClass().getName() + " has an immutable name."); - } + @Override + public void setName(String newName) { + throw new UnsupportedOperationException( + this.getClass().getName() + " has an immutable name."); } + } } diff --git a/org.lflang/src/org/lflang/generator/UnsupportedGeneratorFeatureException.java b/org.lflang/src/org/lflang/generator/UnsupportedGeneratorFeatureException.java index 59fe20386c..c1519a161a 100644 --- a/org.lflang/src/org/lflang/generator/UnsupportedGeneratorFeatureException.java +++ b/org.lflang/src/org/lflang/generator/UnsupportedGeneratorFeatureException.java @@ -26,17 +26,14 @@ import org.eclipse.emf.ecore.EObject; -/** - * Signals that the code generator does not support a particular - * feature of the source language. - */ +/** Signals that the code generator does not support a particular feature of the source language. */ public class UnsupportedGeneratorFeatureException extends GenerationException { - public UnsupportedGeneratorFeatureException(String feature) { - super("Unsupported generator feature: " + feature); - } + public UnsupportedGeneratorFeatureException(String feature) { + super("Unsupported generator feature: " + feature); + } - public UnsupportedGeneratorFeatureException(EObject location, String feature) { - super(location, "Unsupported generator feature: " + feature); - } + public UnsupportedGeneratorFeatureException(EObject location, String feature) { + super(location, "Unsupported generator feature: " + feature); + } } diff --git a/org.lflang/src/org/lflang/generator/ValidationStrategy.java b/org.lflang/src/org/lflang/generator/ValidationStrategy.java index 7adff29527..674634ef7f 100644 --- a/org.lflang/src/org/lflang/generator/ValidationStrategy.java +++ b/org.lflang/src/org/lflang/generator/ValidationStrategy.java @@ -1,7 +1,6 @@ package org.lflang.generator; import java.nio.file.Path; - import org.lflang.util.LFCommand; /** @@ -11,36 +10,38 @@ */ public interface ValidationStrategy { - /** - * Return the command that produces validation output in association - * with {@code generatedFile}, or {@code null} if this strategy has no - * command that will successfully produce validation output. - */ - LFCommand getCommand(Path generatedFile); - - /** - * Return a strategy for parsing the stderr of the validation command. - * @return A strategy for parsing the stderr of the validation command. - */ - DiagnosticReporting.Strategy getErrorReportingStrategy(); - - /** - * Return a strategy for parsing the stdout of the validation command. - * @return A strategy for parsing the stdout of the validation command. - */ - DiagnosticReporting.Strategy getOutputReportingStrategy(); - - /** - * Return whether this strategy validates all generated files, as - * opposed to just the given one. - * @return whether this strategy validates all generated files - */ - boolean isFullBatch(); - - /** - * Return the priority of this. Strategies with higher - * priorities are more likely to be used. - * @return The priority of this. - */ - int getPriority(); + /** + * Return the command that produces validation output in association with {@code generatedFile}, + * or {@code null} if this strategy has no command that will successfully produce validation + * output. + */ + LFCommand getCommand(Path generatedFile); + + /** + * Return a strategy for parsing the stderr of the validation command. + * + * @return A strategy for parsing the stderr of the validation command. + */ + DiagnosticReporting.Strategy getErrorReportingStrategy(); + + /** + * Return a strategy for parsing the stdout of the validation command. + * + * @return A strategy for parsing the stdout of the validation command. + */ + DiagnosticReporting.Strategy getOutputReportingStrategy(); + + /** + * Return whether this strategy validates all generated files, as opposed to just the given one. + * + * @return whether this strategy validates all generated files + */ + boolean isFullBatch(); + + /** + * Return the priority of this. Strategies with higher priorities are more likely to be used. + * + * @return The priority of this. + */ + int getPriority(); } diff --git a/org.lflang/src/org/lflang/generator/Validator.java b/org.lflang/src/org/lflang/generator/Validator.java index 7a9b85c453..f9ae61f854 100644 --- a/org.lflang/src/org/lflang/generator/Validator.java +++ b/org.lflang/src/org/lflang/generator/Validator.java @@ -1,9 +1,6 @@ package org.lflang.generator; -import org.eclipse.xtext.util.CancelIndicator; - -import org.lflang.ErrorReporter; -import org.lflang.util.LFCommand; +import com.google.common.collect.ImmutableMap; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -17,8 +14,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableMap; +import org.eclipse.xtext.util.CancelIndicator; +import org.lflang.ErrorReporter; +import org.lflang.util.LFCommand; /** * Validate generated code. @@ -27,159 +25,180 @@ */ public abstract class Validator { - /** - * Files older than {@code FILE_AGE_THRESHOLD_MILLIS} may be skipped in validation on the - * grounds that they probably have not been updated since the last validator pass. - */ - // This will cause silent validation failures if it takes too long to write all generated code to the file system. - private static final long FILE_AGE_THRESHOLD_MILLIS = 10000; - - protected static class Pair { - public final S first; - public final T second; - public Pair(S first, T second) { - this.first = first; - this.second = second; - } - } - - protected final ErrorReporter errorReporter; - protected final ImmutableMap codeMaps; - - /** - * Initialize a {@code Validator} that reports errors to {@code errorReporter} and adjusts - * document positions using {@code codeMaps}. - */ - protected Validator(ErrorReporter errorReporter, Map codeMaps) { - this.errorReporter = errorReporter; - this.codeMaps = ImmutableMap.copyOf(codeMaps); + /** + * Files older than {@code FILE_AGE_THRESHOLD_MILLIS} may be skipped in validation on the grounds + * that they probably have not been updated since the last validator pass. + */ + // This will cause silent validation failures if it takes too long to write all generated code to + // the file system. + private static final long FILE_AGE_THRESHOLD_MILLIS = 10000; + + protected static class Pair { + public final S first; + public final T second; + + public Pair(S first, T second) { + this.first = first; + this.second = second; } - - /** - * Validate this Validator's group of generated files. - * @param context The context of the current build. - */ - public final void doValidate(LFGeneratorContext context) throws ExecutionException, InterruptedException { - if (!validationEnabled(context)) return; - final List>> tasks = getValidationStrategies().stream().map( - it -> (Callable>) () -> { - it.second.run(context.getCancelIndicator()); - return it; - } - ).collect(Collectors.toList()); - for (Future> f : getFutures(tasks)) { - f.get().first.getErrorReportingStrategy().report(f.get().second.getErrors().toString(), errorReporter, codeMaps); - f.get().first.getOutputReportingStrategy().report(f.get().second.getOutput().toString(), errorReporter, codeMaps); - } - } - - /** - * Return whether generated code validation is enabled for this build. - * @param context The context of the current build. - */ - private boolean validationEnabled(LFGeneratorContext context) { - return context.getArgs().containsKey("lint") || validationEnabledByDefault(context); + } + + protected final ErrorReporter errorReporter; + protected final ImmutableMap codeMaps; + + /** + * Initialize a {@code Validator} that reports errors to {@code errorReporter} and adjusts + * document positions using {@code codeMaps}. + */ + protected Validator(ErrorReporter errorReporter, Map codeMaps) { + this.errorReporter = errorReporter; + this.codeMaps = ImmutableMap.copyOf(codeMaps); + } + + /** + * Validate this Validator's group of generated files. + * + * @param context The context of the current build. + */ + public final void doValidate(LFGeneratorContext context) + throws ExecutionException, InterruptedException { + if (!validationEnabled(context)) return; + final List>> tasks = + getValidationStrategies().stream() + .map( + it -> + (Callable>) + () -> { + it.second.run(context.getCancelIndicator()); + return it; + }) + .collect(Collectors.toList()); + for (Future> f : getFutures(tasks)) { + f.get() + .first + .getErrorReportingStrategy() + .report(f.get().second.getErrors().toString(), errorReporter, codeMaps); + f.get() + .first + .getOutputReportingStrategy() + .report(f.get().second.getOutput().toString(), errorReporter, codeMaps); } - - /** - * Return whether validation of generated code is enabled by default. - * @param context The context of the current build. - * @return Whether validation of generated code is enabled by default. - */ - protected boolean validationEnabledByDefault(LFGeneratorContext context) { - return context.getMode() != LFGeneratorContext.Mode.STANDALONE; - } - - /** - * Invoke all the given tasks. - * @param tasks Any set of tasks. - * @param The return type of the tasks. - * @return Futures corresponding to each task, or an empty list upon failure. - * @throws InterruptedException If interrupted while waiting. - */ - private static List> getFutures(List> tasks) throws InterruptedException { - List> futures = List.of(); - switch (tasks.size()) { - case 0: - break; - case 1: - try { - futures = List.of(CompletableFuture.completedFuture(tasks.get(0).call())); - } catch (Exception e) { - System.err.println(e.getMessage()); // This should never happen - } - break; - default: - ExecutorService service = Executors.newFixedThreadPool( - Math.min(Runtime.getRuntime().availableProcessors(), tasks.size()) - ); - futures = service.invokeAll(tasks); - service.shutdown(); + } + + /** + * Return whether generated code validation is enabled for this build. + * + * @param context The context of the current build. + */ + private boolean validationEnabled(LFGeneratorContext context) { + return context.getArgs().containsKey("lint") || validationEnabledByDefault(context); + } + + /** + * Return whether validation of generated code is enabled by default. + * + * @param context The context of the current build. + * @return Whether validation of generated code is enabled by default. + */ + protected boolean validationEnabledByDefault(LFGeneratorContext context) { + return context.getMode() != LFGeneratorContext.Mode.STANDALONE; + } + + /** + * Invoke all the given tasks. + * + * @param tasks Any set of tasks. + * @param The return type of the tasks. + * @return Futures corresponding to each task, or an empty list upon failure. + * @throws InterruptedException If interrupted while waiting. + */ + private static List> getFutures(List> tasks) + throws InterruptedException { + List> futures = List.of(); + switch (tasks.size()) { + case 0: + break; + case 1: + try { + futures = List.of(CompletableFuture.completedFuture(tasks.get(0).call())); + } catch (Exception e) { + System.err.println(e.getMessage()); // This should never happen } - return futures; + break; + default: + ExecutorService service = + Executors.newFixedThreadPool( + Math.min(Runtime.getRuntime().availableProcessors(), tasks.size())); + futures = service.invokeAll(tasks); + service.shutdown(); } - - /** - * Run the given command, report any messages produced using the reporting strategies - * given by {@code getBuildReportingStrategies}, and return its return code. - */ - public final int run(LFCommand command, CancelIndicator cancelIndicator) { - final int returnCode = command.run(cancelIndicator); - getBuildReportingStrategies().first.report(command.getErrors().toString(), errorReporter, codeMaps); - getBuildReportingStrategies().second.report(command.getOutput().toString(), errorReporter, codeMaps); - return returnCode; + return futures; + } + + /** + * Run the given command, report any messages produced using the reporting strategies given by + * {@code getBuildReportingStrategies}, and return its return code. + */ + public final int run(LFCommand command, CancelIndicator cancelIndicator) { + final int returnCode = command.run(cancelIndicator); + getBuildReportingStrategies() + .first + .report(command.getErrors().toString(), errorReporter, codeMaps); + getBuildReportingStrategies() + .second + .report(command.getOutput().toString(), errorReporter, codeMaps); + return returnCode; + } + + /** + * Return the validation strategies and validation commands corresponding to each generated file. + * + * @return the validation strategies and validation commands corresponding to each generated file + */ + private List> getValidationStrategies() { + final List> commands = new ArrayList<>(); + long mostRecentDateModified = + codeMaps.keySet().stream().map(it -> it.toFile().lastModified()).reduce(0L, Math::max); + for (Path generatedFile : codeMaps.keySet()) { + if (generatedFile.toFile().lastModified() + > mostRecentDateModified - FILE_AGE_THRESHOLD_MILLIS) { + final Pair p = getValidationStrategy(generatedFile); + if (p.first == null || p.second == null) continue; + commands.add(p); + if (p.first.isFullBatch()) break; + } } - - /** - * Return the validation strategies and validation - * commands corresponding to each generated file. - * @return the validation strategies and validation - * commands corresponding to each generated file - */ - private List> getValidationStrategies() { - final List> commands = new ArrayList<>(); - long mostRecentDateModified = codeMaps.keySet().stream() - .map(it -> it.toFile().lastModified()).reduce(0L, Math::max); - for (Path generatedFile : codeMaps.keySet()) { - if (generatedFile.toFile().lastModified() > mostRecentDateModified - FILE_AGE_THRESHOLD_MILLIS) { - final Pair p = getValidationStrategy(generatedFile); - if (p.first == null || p.second == null) continue; - commands.add(p); - if (p.first.isFullBatch()) break; - } - } - return commands; + return commands; + } + + /** + * Return the validation strategy and command corresponding to the given file if such a strategy + * and command are available. + * + * @return the validation strategy and command corresponding to the given file if such a strategy + * and command are available + */ + private Pair getValidationStrategy(Path generatedFile) { + List sorted = + getPossibleStrategies().stream() + .sorted(Comparator.comparingInt(vs -> -vs.getPriority())) + .toList(); + for (ValidationStrategy strategy : sorted) { + LFCommand validateCommand = strategy.getCommand(generatedFile); + if (validateCommand != null) { + return new Pair<>(strategy, validateCommand); + } } - - /** - * Return the validation strategy and command - * corresponding to the given file if such a strategy - * and command are available. - * @return the validation strategy and command - * corresponding to the given file if such a strategy - * and command are available - */ - private Pair getValidationStrategy(Path generatedFile) { - List sorted = getPossibleStrategies().stream() - .sorted(Comparator.comparingInt(vs -> -vs.getPriority())).toList(); - for (ValidationStrategy strategy : sorted) { - LFCommand validateCommand = strategy.getCommand(generatedFile); - if (validateCommand != null) { - return new Pair<>(strategy, validateCommand); - } - } - return new Pair<>(null, null); - } - - /** - * List all validation strategies that exist for the implementor - * without filtering by platform or availability. - */ - protected abstract Collection getPossibleStrategies(); - - /** - * Return the appropriate output and error reporting - * strategies for the main build process. - */ - protected abstract Pair getBuildReportingStrategies(); + return new Pair<>(null, null); + } + + /** + * List all validation strategies that exist for the implementor without filtering by platform or + * availability. + */ + protected abstract Collection getPossibleStrategies(); + + /** Return the appropriate output and error reporting strategies for the main build process. */ + protected abstract Pair + getBuildReportingStrategies(); } diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/src/org/lflang/generator/WatchdogInstance.java index 90823102d6..ac51f389cb 100644 --- a/org.lflang/src/org/lflang/generator/WatchdogInstance.java +++ b/org.lflang/src/org/lflang/generator/WatchdogInstance.java @@ -2,8 +2,8 @@ * @file * @author Benjamin Asch * @author Edward A. Lee - * @copyright (c) 2023, The University of California at Berkeley - * License in BSD 2-clause + * @copyright (c) 2023, The University of California at Berkeley License in BSD 2-clause * @brief Instance of a watchdog */ package org.lflang.generator; diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 5f81de89aa..1a99c1b3e2 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -1,15 +1,16 @@ package org.lflang.generator.c; -import java.util.List; +import static org.lflang.generator.c.CGenerator.variableStructType; + import java.util.ArrayList; -import org.lflang.ast.ASTUtils; +import java.util.List; import org.lflang.Target; +import org.lflang.ast.ASTUtils; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; -import static org.lflang.generator.c.CGenerator.variableStructType; /** * Generates code for actions (logical or physical) for the C and CCpp target. * @@ -23,153 +24,156 @@ * @author Hou Seng Wong */ public class CActionGenerator { - /** - * For each action of the specified reactor instance, generate initialization code - * for the offset and period fields. - * @param instance The reactor. - */ - public static String generateInitializers( - ReactorInstance instance - ) { - List code = new ArrayList<>(); - for (ActionInstance action : instance.actions) { - if (!action.isShutdown()) { - var triggerStructName = CUtil.reactorRef(action.getParent()) + "->_lf__" + action.getName(); - var minDelay = action.getMinDelay(); - var minSpacing = action.getMinSpacing(); - var offsetInitializer = triggerStructName+".offset = " + CTypes.getInstance().getTargetTimeExpr(minDelay) - + ";"; - var periodInitializer = triggerStructName+".period = " + (minSpacing != null ? - CTypes.getInstance().getTargetTimeExpr(minSpacing) : - CGenerator.UNDEFINED_MIN_SPACING) + ";"; - code.addAll(List.of( - "// Initializing action "+action.getFullName(), - offsetInitializer, - periodInitializer - )); + /** + * For each action of the specified reactor instance, generate initialization code for the offset + * and period fields. + * + * @param instance The reactor. + */ + public static String generateInitializers(ReactorInstance instance) { + List code = new ArrayList<>(); + for (ActionInstance action : instance.actions) { + if (!action.isShutdown()) { + var triggerStructName = CUtil.reactorRef(action.getParent()) + "->_lf__" + action.getName(); + var minDelay = action.getMinDelay(); + var minSpacing = action.getMinSpacing(); + var offsetInitializer = + triggerStructName + + ".offset = " + + CTypes.getInstance().getTargetTimeExpr(minDelay) + + ";"; + var periodInitializer = + triggerStructName + + ".period = " + + (minSpacing != null + ? CTypes.getInstance().getTargetTimeExpr(minSpacing) + : CGenerator.UNDEFINED_MIN_SPACING) + + ";"; + code.addAll( + List.of( + "// Initializing action " + action.getFullName(), + offsetInitializer, + periodInitializer)); - var mode = action.getMode(false); - if (mode != null) { - var modeParent = mode.getParent(); - var modeRef = "&"+CUtil.reactorRef(modeParent)+"->_lf__modes["+modeParent.modes.indexOf(mode)+"];"; - code.add(triggerStructName+".mode = "+modeRef+";"); - } else { - code.add(triggerStructName+".mode = NULL;"); - } - } + var mode = action.getMode(false); + if (mode != null) { + var modeParent = mode.getParent(); + var modeRef = + "&" + + CUtil.reactorRef(modeParent) + + "->_lf__modes[" + + modeParent.modes.indexOf(mode) + + "];"; + code.add(triggerStructName + ".mode = " + modeRef + ";"); + } else { + code.add(triggerStructName + ".mode = NULL;"); } - return String.join("\n", code); + } } + return String.join("\n", code); + } - /** - * Create a template token initialized to the payload size. - * This token is marked to not be freed so that the trigger_t struct - * always has a template token. - * At the start of each time step, we need to initialize the is_present field - * of each action's trigger object to false and free a previously - * allocated token if appropriate. This code sets up the table that does that. - * - * @param selfStruct The variable name of the self struct - * @param actionName The action name - * @param payloadSize The code that returns the size of the action's payload in C. - */ - public static String generateTokenInitializer( - String selfStruct, - String actionName, - String payloadSize - ) { - return String.join("\n", - "_lf_initialize_template((token_template_t*)", - " &("+selfStruct+"->_lf__"+actionName+"),", - payloadSize+");", - selfStruct+"->_lf__"+actionName+".status = absent;" - ); - } + /** + * Create a template token initialized to the payload size. This token is marked to not be freed + * so that the trigger_t struct always has a template token. At the start of each time step, we + * need to initialize the is_present field of each action's trigger object to false and free a + * previously allocated token if appropriate. This code sets up the table that does that. + * + * @param selfStruct The variable name of the self struct + * @param actionName The action name + * @param payloadSize The code that returns the size of the action's payload in C. + */ + public static String generateTokenInitializer( + String selfStruct, String actionName, String payloadSize) { + return String.join( + "\n", + "_lf_initialize_template((token_template_t*)", + " &(" + selfStruct + "->_lf__" + actionName + "),", + payloadSize + ");", + selfStruct + "->_lf__" + actionName + ".status = absent;"); + } - /** - * Generate the declarations of actions in the self struct - * - * @param body The content of the self struct - * @param constructorCode The constructor code of the reactor - */ - public static void generateDeclarations( - TypeParameterizedReactor tpr, - CodeBuilder body, - CodeBuilder constructorCode - ) { - for (Action action : ASTUtils.allActions(tpr.reactor())) { - var actionName = action.getName(); - body.pr(action, CGenerator.variableStructType(action, tpr, false)+" _lf_"+actionName+";"); - // Initialize the trigger pointer in the action. - constructorCode.pr(action, "self->_lf_"+actionName+".trigger = &self->_lf__"+actionName+";"); - } + /** + * Generate the declarations of actions in the self struct + * + * @param body The content of the self struct + * @param constructorCode The constructor code of the reactor + */ + public static void generateDeclarations( + TypeParameterizedReactor tpr, CodeBuilder body, CodeBuilder constructorCode) { + for (Action action : ASTUtils.allActions(tpr.reactor())) { + var actionName = action.getName(); + body.pr( + action, CGenerator.variableStructType(action, tpr, false) + " _lf_" + actionName + ";"); + // Initialize the trigger pointer in the action. + constructorCode.pr( + action, "self->_lf_" + actionName + ".trigger = &self->_lf__" + actionName + ";"); } + } - /** - * Generate the struct type definitions for the action of the - * reactor - * - * @param action The action to generate the struct for - * @param target The target of the code generation (C, CCpp or Python) - * @param types The helper object for types related stuff - * @param federatedExtension The code needed to support federated execution - * @return The auxiliary struct for the port as a string - */ - public static String generateAuxiliaryStruct( - TypeParameterizedReactor tpr, - Action action, - Target target, - CTypes types, - CodeBuilder federatedExtension, - boolean userFacing - ) { - var code = new CodeBuilder(); - code.pr("typedef struct {"); - code.indent(); - // NOTE: The following fields are required to be the first ones so that - // pointer to this struct can be cast to a (lf_action_base_t*) or to - // (token_template_t*) to access these fields for any port. - // IMPORTANT: These must match exactly the fields defined in port.h!! - code.pr(String.join("\n", - "token_type_t type;", // From token_template_t - "lf_token_t* token;", // From token_template_t - "size_t length;", // From token_template_t - "bool is_present;", // From lf_action_base_t - "bool has_value;", // From lf_action_base_t - "trigger_t* trigger;" // From lf_action_base_t - )); - code.pr(valueDeclaration(tpr, action, target, types)); - code.pr(federatedExtension.toString()); - code.unindent(); - code.pr("} " + variableStructType(action, tpr, userFacing) + ";"); - return code.toString(); - } + /** + * Generate the struct type definitions for the action of the reactor + * + * @param action The action to generate the struct for + * @param target The target of the code generation (C, CCpp or Python) + * @param types The helper object for types related stuff + * @param federatedExtension The code needed to support federated execution + * @return The auxiliary struct for the port as a string + */ + public static String generateAuxiliaryStruct( + TypeParameterizedReactor tpr, + Action action, + Target target, + CTypes types, + CodeBuilder federatedExtension, + boolean userFacing) { + var code = new CodeBuilder(); + code.pr("typedef struct {"); + code.indent(); + // NOTE: The following fields are required to be the first ones so that + // pointer to this struct can be cast to a (lf_action_base_t*) or to + // (token_template_t*) to access these fields for any port. + // IMPORTANT: These must match exactly the fields defined in port.h!! + code.pr( + String.join( + "\n", + "token_type_t type;", // From token_template_t + "lf_token_t* token;", // From token_template_t + "size_t length;", // From token_template_t + "bool is_present;", // From lf_action_base_t + "bool has_value;", // From lf_action_base_t + "trigger_t* trigger;" // From lf_action_base_t + )); + code.pr(valueDeclaration(tpr, action, target, types)); + code.pr(federatedExtension.toString()); + code.unindent(); + code.pr("} " + variableStructType(action, tpr, userFacing) + ";"); + return code.toString(); + } - /** - * For the specified action, return a declaration for action struct to - * contain the value of the action. An action of - * type int[10], for example, will result in this: - *

    
    -     *     int* value;
    -     * 
    - * This will return an empty string for an action with no type. - * @param tpr {@link TypeParameterizedReactor} - * @param action The action. - * @return A string providing the value field of the action struct. - */ - private static String valueDeclaration( - TypeParameterizedReactor tpr, - Action action, - Target target, - CTypes types - ) { - if (target == Target.Python) { - return "PyObject* value;"; - } - // Do not convert to lf_token_t* using lfTypeToTokenType because there - // will be a separate field pointing to the token. - return action.getType() == null && target.requiresTypes ? - "" : - types.getTargetType(tpr.resolveType(action.getType())) + " value;"; + /** + * For the specified action, return a declaration for action struct to contain the value of the + * action. An action of type int[10], for example, will result in this: + * + *
    
    +   *     int* value;
    +   * 
    + * + * This will return an empty string for an action with no type. + * + * @param tpr {@link TypeParameterizedReactor} + * @param action The action. + * @return A string providing the value field of the action struct. + */ + private static String valueDeclaration( + TypeParameterizedReactor tpr, Action action, Target target, CTypes types) { + if (target == Target.Python) { + return "PyObject* value;"; } + // Do not convert to lf_token_t* using lfTypeToTokenType because there + // will be a separate field pointing to the token. + return action.getType() == null && target.requiresTypes + ? "" + : types.getTargetType(tpr.resolveType(action.getType())) + " value;"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index d158f7491b..860c85a75d 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2019-2021, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -31,7 +31,6 @@ import java.util.List; import java.util.Objects; import java.util.stream.Stream; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; @@ -42,357 +41,364 @@ /** * A helper class that generates a CMakefile that can be used to compile the generated C code. * - * Adapted from @see org.lflang.generator.CppCmakeGenerator.kt + *

    Adapted from @see org.lflang.generator.CppCmakeGenerator.kt * * @author Soroush Bateni * @author Peter Donovan */ public class CCmakeGenerator { - private static final String DEFAULT_INSTALL_CODE = """ + private static final String DEFAULT_INSTALL_CODE = + """ install( TARGETS ${LF_MAIN_TARGET} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) """; - public static final String MIN_CMAKE_VERSION = "3.19"; - - private final FileConfig fileConfig; - private final List additionalSources; - private final SetUpMainTarget setUpMainTarget; - private final String installCode; - - public CCmakeGenerator( - FileConfig fileConfig, - List additionalSources - ) { - this.fileConfig = fileConfig; - this.additionalSources = additionalSources; - this.setUpMainTarget = CCmakeGenerator::setUpMainTarget; - this.installCode = DEFAULT_INSTALL_CODE; + public static final String MIN_CMAKE_VERSION = "3.19"; + + private final FileConfig fileConfig; + private final List additionalSources; + private final SetUpMainTarget setUpMainTarget; + private final String installCode; + + public CCmakeGenerator(FileConfig fileConfig, List additionalSources) { + this.fileConfig = fileConfig; + this.additionalSources = additionalSources; + this.setUpMainTarget = CCmakeGenerator::setUpMainTarget; + this.installCode = DEFAULT_INSTALL_CODE; + } + + public CCmakeGenerator( + FileConfig fileConfig, + List additionalSources, + SetUpMainTarget setUpMainTarget, + String installCode) { + this.fileConfig = fileConfig; + this.additionalSources = additionalSources; + this.setUpMainTarget = setUpMainTarget; + this.installCode = installCode; + } + + /** + * Generate the contents of a CMakeLists.txt that builds the provided LF C 'sources'. Any error + * will be reported in the 'errorReporter'. + * + * @param sources A list of .c files to build. + * @param executableName The name of the output executable. + * @param errorReporter Used to report errors. + * @param CppMode Indicate if the compilation should happen in C++ mode + * @param hasMain Indicate if the .lf file has a main reactor or not. If not, a library target + * will be created instead of an executable. + * @param cMakeExtras CMake-specific code that should be appended to the CMakeLists.txt. + * @param targetConfig The TargetConfig instance to use. + * @return The content of the CMakeLists.txt. + */ + CodeBuilder generateCMakeCode( + List sources, + String executableName, + ErrorReporter errorReporter, + boolean CppMode, + boolean hasMain, + String cMakeExtras, + TargetConfig targetConfig) { + CodeBuilder cMakeCode = new CodeBuilder(); + + List additionalSources = new ArrayList<>(); + for (String file : targetConfig.compileAdditionalSources) { + var relativePath = + fileConfig + .getSrcGenPath() + .relativize(fileConfig.getSrcGenPath().resolve(Paths.get(file))); + additionalSources.add(FileUtil.toUnixString(relativePath)); } - - public CCmakeGenerator( - FileConfig fileConfig, - List additionalSources, - SetUpMainTarget setUpMainTarget, - String installCode - ) { - this.fileConfig = fileConfig; - this.additionalSources = additionalSources; - this.setUpMainTarget = setUpMainTarget; - this.installCode = installCode; + additionalSources.addAll(this.additionalSources); + cMakeCode.newLine(); + + cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); + + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + cMakeCode.pr("# Set default configuration file. To add custom configurations,"); + cMakeCode.pr("# pass -- -DOVERLAY_CONFIG=my_config.prj to either cmake or west"); + cMakeCode.pr("set(CONF_FILE prj_lf.conf)"); + if (targetConfig.platformOptions.board != null) { + cMakeCode.pr("# Selecting board specified in target property"); + cMakeCode.pr("set(BOARD " + targetConfig.platformOptions.board + ")"); + } else { + cMakeCode.pr("# Selecting default board"); + cMakeCode.pr("set(BOARD qemu_cortex_m3)"); + } + cMakeCode.pr("# We require Zephyr version 3.2.0"); + cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.2.0)"); + cMakeCode.newLine(); } - /** - * Generate the contents of a CMakeLists.txt that builds the provided LF C 'sources'. Any error will be - * reported in the 'errorReporter'. - * - * @param sources A list of .c files to build. - * @param executableName The name of the output executable. - * @param errorReporter Used to report errors. - * @param CppMode Indicate if the compilation should happen in C++ mode - * @param hasMain Indicate if the .lf file has a main reactor or not. If not, - * a library target will be created instead of an executable. - * @param cMakeExtras CMake-specific code that should be appended to the CMakeLists.txt. - * @param targetConfig The TargetConfig instance to use. - * @return The content of the CMakeLists.txt. - */ - CodeBuilder generateCMakeCode( - List sources, - String executableName, - ErrorReporter errorReporter, - boolean CppMode, - boolean hasMain, - String cMakeExtras, - TargetConfig targetConfig - ) { - CodeBuilder cMakeCode = new CodeBuilder(); - - List additionalSources = new ArrayList<>(); - for (String file: targetConfig.compileAdditionalSources) { - var relativePath = fileConfig.getSrcGenPath().relativize( - fileConfig.getSrcGenPath().resolve(Paths.get(file))); - additionalSources.add(FileUtil.toUnixString(relativePath)); - } - additionalSources.addAll(this.additionalSources); - cMakeCode.newLine(); - - cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); - - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - cMakeCode.pr("# Set default configuration file. To add custom configurations,"); - cMakeCode.pr("# pass -- -DOVERLAY_CONFIG=my_config.prj to either cmake or west"); - cMakeCode.pr("set(CONF_FILE prj_lf.conf)"); - if (targetConfig.platformOptions.board != null) { - cMakeCode.pr("# Selecting board specified in target property"); - cMakeCode.pr("set(BOARD "+targetConfig.platformOptions.board+")"); - } else { - cMakeCode.pr("# Selecting default board"); - cMakeCode.pr("set(BOARD qemu_cortex_m3)"); - } - cMakeCode.pr("# We require Zephyr version 3.2.0"); - cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.2.0)"); - cMakeCode.newLine(); - } - - cMakeCode.pr("project("+executableName+" LANGUAGES C)"); - cMakeCode.newLine(); - - // The Test build type is the Debug type plus coverage generation - cMakeCode.pr("if(CMAKE_BUILD_TYPE STREQUAL \"Test\")"); - cMakeCode.pr(" set(CMAKE_BUILD_TYPE \"Debug\")"); - cMakeCode.pr(" if(CMAKE_C_COMPILER_ID STREQUAL \"GNU\")"); - cMakeCode.pr(" find_program(LCOV_BIN lcov)"); - cMakeCode.pr(" if(LCOV_BIN MATCHES \"lcov$\")"); - cMakeCode.pr(" set(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage\")"); - cMakeCode.pr(" else()"); - cMakeCode.pr(" message(\"Not producing code coverage information since lcov was not found\")"); - cMakeCode.pr(" endif()"); - cMakeCode.pr(" else()"); - cMakeCode.pr(" message(\"Not producing code coverage information since the selected compiler is no gcc\")"); - cMakeCode.pr(" endif()"); - cMakeCode.pr("endif()"); - - cMakeCode.pr("# Require C11"); - cMakeCode.pr("set(CMAKE_C_STANDARD 11)"); - cMakeCode.pr("set(CMAKE_C_STANDARD_REQUIRED ON)"); - cMakeCode.newLine(); - - cMakeCode.pr("# Require C++17"); - cMakeCode.pr("set(CMAKE_CXX_STANDARD 17)"); - cMakeCode.pr("set(CMAKE_CXX_STANDARD_REQUIRED ON)"); - cMakeCode.newLine(); - if (!targetConfig.cmakeIncludes.isEmpty()) { - // The user might be using the non-keyword form of - // target_link_libraries. Ideally we would detect whether they are - // doing that, but it is easier to just always have a deprecation - // warning. - cMakeCode.pr(""" + cMakeCode.pr("project(" + executableName + " LANGUAGES C)"); + cMakeCode.newLine(); + + // The Test build type is the Debug type plus coverage generation + cMakeCode.pr("if(CMAKE_BUILD_TYPE STREQUAL \"Test\")"); + cMakeCode.pr(" set(CMAKE_BUILD_TYPE \"Debug\")"); + cMakeCode.pr(" if(CMAKE_C_COMPILER_ID STREQUAL \"GNU\")"); + cMakeCode.pr(" find_program(LCOV_BIN lcov)"); + cMakeCode.pr(" if(LCOV_BIN MATCHES \"lcov$\")"); + cMakeCode.pr( + " set(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage\")"); + cMakeCode.pr(" else()"); + cMakeCode.pr( + " message(\"Not producing code coverage information since lcov was not found\")"); + cMakeCode.pr(" endif()"); + cMakeCode.pr(" else()"); + cMakeCode.pr( + " message(\"Not producing code coverage information since the selected compiler is no" + + " gcc\")"); + cMakeCode.pr(" endif()"); + cMakeCode.pr("endif()"); + + cMakeCode.pr("# Require C11"); + cMakeCode.pr("set(CMAKE_C_STANDARD 11)"); + cMakeCode.pr("set(CMAKE_C_STANDARD_REQUIRED ON)"); + cMakeCode.newLine(); + + cMakeCode.pr("# Require C++17"); + cMakeCode.pr("set(CMAKE_CXX_STANDARD 17)"); + cMakeCode.pr("set(CMAKE_CXX_STANDARD_REQUIRED ON)"); + cMakeCode.newLine(); + if (!targetConfig.cmakeIncludes.isEmpty()) { + // The user might be using the non-keyword form of + // target_link_libraries. Ideally we would detect whether they are + // doing that, but it is easier to just always have a deprecation + // warning. + cMakeCode.pr( + """ cmake_policy(SET CMP0023 OLD) # This causes deprecation warnings - """ - ); - } - - // Set the build type - cMakeCode.pr("set(DEFAULT_BUILD_TYPE " + targetConfig.cmakeBuildType + ")\n"); - cMakeCode.pr("if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)\n"); - cMakeCode.pr(" set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING \"Choose the type of build.\" FORCE)\n"); - cMakeCode.pr("endif()\n"); - cMakeCode.newLine(); - - cMakeCode.pr("# do not print install messages\n"); - cMakeCode.pr("set(CMAKE_INSTALL_MESSAGE NEVER)\n"); - cMakeCode.newLine(); - - if (CppMode) { - // Suppress warnings about const char*. - cMakeCode.pr("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wno-write-strings\")"); - cMakeCode.newLine(); - } - - if (targetConfig.platformOptions.platform != Platform.AUTO) { - cMakeCode.pr("set(CMAKE_SYSTEM_NAME "+targetConfig.platformOptions.platform.getcMakeName()+")"); - } - cMakeCode.newLine(); - - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - cMakeCode.pr(setUpMainTargetZephyr( - hasMain, - executableName, - Stream.concat(additionalSources.stream(), sources.stream()) - )); - } else { - cMakeCode.pr(setUpMainTarget.getCmakeCode( - hasMain, - executableName, - Stream.concat(additionalSources.stream(), sources.stream()) - )); - } - - cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE core)"); - - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC .)"); - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/)"); - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/api)"); - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core)"); - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core/platform)"); - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core/modal_models)"); - cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core/utils)"); - - if(targetConfig.auth) { - // If security is requested, add the auth option. - var osName = System.getProperty("os.name").toLowerCase(); - // if platform target was set, use given platform instead - if (targetConfig.platformOptions.platform != Platform.AUTO) { - osName = targetConfig.platformOptions.platform.toString(); - } - if (osName.contains("mac")) { - cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); - } - cMakeCode.pr("# Find OpenSSL and link to it"); - cMakeCode.pr("find_package(OpenSSL REQUIRED)"); - cMakeCode.pr("target_link_libraries( ${LF_MAIN_TARGET} PRIVATE OpenSSL::SSL)"); - cMakeCode.newLine(); - } - - if (targetConfig.threading || targetConfig.tracing != null) { - // If threaded computation is requested, add the threads option. - cMakeCode.pr("# Find threads and link to it"); - cMakeCode.pr("find_package(Threads REQUIRED)"); - cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE Threads::Threads)"); - cMakeCode.newLine(); - - // If the LF program itself is threaded or if tracing is enabled, we need to define - // NUMBER_OF_WORKERS so that platform-specific C files will contain the appropriate functions - cMakeCode.pr("# Set the number of workers to enable threading/tracing"); - cMakeCode.pr("target_compile_definitions(${LF_MAIN_TARGET} PUBLIC NUMBER_OF_WORKERS="+targetConfig.workers+")"); - cMakeCode.newLine(); - } - - // Add additional flags so runtime can distinguish between multi-threaded and single-threaded mode - if (targetConfig.threading) { - cMakeCode.pr("# Set flag to indicate a multi-threaded runtime"); - cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC LF_THREADED=1)"); - } else { - cMakeCode.pr("# Set flag to indicate a single-threaded runtime"); - cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC LF_UNTHREADED=1)"); - } - cMakeCode.newLine(); - - - if (CppMode) cMakeCode.pr("enable_language(CXX)"); - - if (targetConfig.compiler != null && !targetConfig.compiler.isBlank()) { - if (CppMode) { - // Set the CXX compiler to what the user has requested. - cMakeCode.pr("set(CMAKE_CXX_COMPILER "+targetConfig.compiler+")"); - } else { - cMakeCode.pr("set(CMAKE_C_COMPILER "+targetConfig.compiler+")"); - } - cMakeCode.newLine(); - } - - // Set the compiler flags - // We can detect a few common libraries and use the proper target_link_libraries to find them - for (String compilerFlag : targetConfig.compilerFlags) { - switch(compilerFlag.trim()) { - case "-lm": - cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE m)"); - break; - case "-lprotobuf-c": - cMakeCode.pr("include(FindPackageHandleStandardArgs)"); - cMakeCode.pr("FIND_PATH( PROTOBUF_INCLUDE_DIR protobuf-c/protobuf-c.h)"); - cMakeCode.pr(""" + """); + } + + // Set the build type + cMakeCode.pr("set(DEFAULT_BUILD_TYPE " + targetConfig.cmakeBuildType + ")\n"); + cMakeCode.pr("if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)\n"); + cMakeCode.pr( + " set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING \"Choose the type of build.\"" + + " FORCE)\n"); + cMakeCode.pr("endif()\n"); + cMakeCode.newLine(); + + cMakeCode.pr("# do not print install messages\n"); + cMakeCode.pr("set(CMAKE_INSTALL_MESSAGE NEVER)\n"); + cMakeCode.newLine(); + + if (CppMode) { + // Suppress warnings about const char*. + cMakeCode.pr("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wno-write-strings\")"); + cMakeCode.newLine(); + } + + if (targetConfig.platformOptions.platform != Platform.AUTO) { + cMakeCode.pr( + "set(CMAKE_SYSTEM_NAME " + targetConfig.platformOptions.platform.getcMakeName() + ")"); + } + cMakeCode.newLine(); + + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + cMakeCode.pr( + setUpMainTargetZephyr( + hasMain, + executableName, + Stream.concat(additionalSources.stream(), sources.stream()))); + } else { + cMakeCode.pr( + setUpMainTarget.getCmakeCode( + hasMain, + executableName, + Stream.concat(additionalSources.stream(), sources.stream()))); + } + + cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE core)"); + + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC .)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/api)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core/platform)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core/modal_models)"); + cMakeCode.pr("target_include_directories(${LF_MAIN_TARGET} PUBLIC include/core/utils)"); + + if (targetConfig.auth) { + // If security is requested, add the auth option. + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } + if (osName.contains("mac")) { + cMakeCode.pr("set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)"); + } + cMakeCode.pr("# Find OpenSSL and link to it"); + cMakeCode.pr("find_package(OpenSSL REQUIRED)"); + cMakeCode.pr("target_link_libraries( ${LF_MAIN_TARGET} PRIVATE OpenSSL::SSL)"); + cMakeCode.newLine(); + } + + if (targetConfig.threading || targetConfig.tracing != null) { + // If threaded computation is requested, add the threads option. + cMakeCode.pr("# Find threads and link to it"); + cMakeCode.pr("find_package(Threads REQUIRED)"); + cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE Threads::Threads)"); + cMakeCode.newLine(); + + // If the LF program itself is threaded or if tracing is enabled, we need to define + // NUMBER_OF_WORKERS so that platform-specific C files will contain the appropriate functions + cMakeCode.pr("# Set the number of workers to enable threading/tracing"); + cMakeCode.pr( + "target_compile_definitions(${LF_MAIN_TARGET} PUBLIC NUMBER_OF_WORKERS=" + + targetConfig.workers + + ")"); + cMakeCode.newLine(); + } + + // Add additional flags so runtime can distinguish between multi-threaded and single-threaded + // mode + if (targetConfig.threading) { + cMakeCode.pr("# Set flag to indicate a multi-threaded runtime"); + cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC LF_THREADED=1)"); + } else { + cMakeCode.pr("# Set flag to indicate a single-threaded runtime"); + cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC LF_UNTHREADED=1)"); + } + cMakeCode.newLine(); + + if (CppMode) cMakeCode.pr("enable_language(CXX)"); + + if (targetConfig.compiler != null && !targetConfig.compiler.isBlank()) { + if (CppMode) { + // Set the CXX compiler to what the user has requested. + cMakeCode.pr("set(CMAKE_CXX_COMPILER " + targetConfig.compiler + ")"); + } else { + cMakeCode.pr("set(CMAKE_C_COMPILER " + targetConfig.compiler + ")"); + } + cMakeCode.newLine(); + } + + // Set the compiler flags + // We can detect a few common libraries and use the proper target_link_libraries to find them + for (String compilerFlag : targetConfig.compilerFlags) { + switch (compilerFlag.trim()) { + case "-lm": + cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE m)"); + break; + case "-lprotobuf-c": + cMakeCode.pr("include(FindPackageHandleStandardArgs)"); + 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 )"""); - cMakeCode.pr("find_package_handle_standard_args(libprotobuf-c DEFAULT_MSG PROTOBUF_INCLUDE_DIR PROTOBUF_LIBRARY)"); - cMakeCode.pr("target_include_directories( ${LF_MAIN_TARGET} PUBLIC ${PROTOBUF_INCLUDE_DIR} )"); - cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE ${PROTOBUF_LIBRARY})"); - break; - case "-O2": - if (Objects.equals(targetConfig.compiler, "gcc") || CppMode) { - // Workaround for the pre-added -O2 option in the CGenerator. - // This flag is specific to gcc/g++ and the clang compiler - cMakeCode.pr("add_compile_options(-O2)"); - cMakeCode.pr("add_link_options(-O2)"); - break; - } - default: - errorReporter.reportWarning("Using the flags target property with cmake is dangerous.\n"+ - " Use cmake-include instead."); - cMakeCode.pr("add_compile_options( "+compilerFlag+" )"); - cMakeCode.pr("add_link_options( "+compilerFlag+")"); - } - } - cMakeCode.newLine(); - - // Add the install option - cMakeCode.pr(installCode); - cMakeCode.newLine(); - - // Add the include file - for (String includeFile : targetConfig.cmakeIncludes) { - cMakeCode.pr("include(\""+ Path.of(includeFile).getFileName()+"\")"); - } - cMakeCode.newLine(); - - cMakeCode.pr(cMakeExtras); - cMakeCode.newLine(); - - return cMakeCode; + cMakeCode.pr( + "find_package_handle_standard_args(libprotobuf-c DEFAULT_MSG PROTOBUF_INCLUDE_DIR" + + " PROTOBUF_LIBRARY)"); + cMakeCode.pr( + "target_include_directories( ${LF_MAIN_TARGET} PUBLIC ${PROTOBUF_INCLUDE_DIR} )"); + cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE ${PROTOBUF_LIBRARY})"); + break; + case "-O2": + if (Objects.equals(targetConfig.compiler, "gcc") || CppMode) { + // Workaround for the pre-added -O2 option in the CGenerator. + // This flag is specific to gcc/g++ and the clang compiler + cMakeCode.pr("add_compile_options(-O2)"); + cMakeCode.pr("add_link_options(-O2)"); + break; + } + default: + errorReporter.reportWarning( + "Using the flags target property with cmake is dangerous.\n" + + " Use cmake-include instead."); + cMakeCode.pr("add_compile_options( " + compilerFlag + " )"); + cMakeCode.pr("add_link_options( " + compilerFlag + ")"); + } } + cMakeCode.newLine(); - /** Provide a strategy for configuring the main target of the CMake build. */ - public interface SetUpMainTarget { - // Implementation note: This indirection is necessary because the Python - // target produces a shared object file, not an executable. - String getCmakeCode(boolean hasMain, String executableName, Stream cSources); - } + // Add the install option + cMakeCode.pr(installCode); + cMakeCode.newLine(); - /** Generate the C-target-specific code for configuring the executable produced by the build. */ - private static String setUpMainTarget( - boolean hasMain, - String executableName, - Stream cSources - ) { - var code = new CodeBuilder(); - code.pr("add_subdirectory(core)"); - code.newLine(); - code.pr("set(LF_MAIN_TARGET "+executableName+")"); - code.newLine(); - - if (hasMain) { - code.pr("# Declare a new executable target and list all its sources"); - code.pr("add_executable("); - } else { - code.pr("# Declare a new library target and list all its sources"); - code.pr("add_library("); - } - code.indent(); - code.pr("${LF_MAIN_TARGET}"); - cSources.forEach(code::pr); - code.unindent(); - code.pr(")"); - code.newLine(); - return code.toString(); + // Add the include file + for (String includeFile : targetConfig.cmakeIncludes) { + cMakeCode.pr("include(\"" + Path.of(includeFile).getFileName() + "\")"); } + cMakeCode.newLine(); + + cMakeCode.pr(cMakeExtras); + cMakeCode.newLine(); + + return cMakeCode; + } + + /** Provide a strategy for configuring the main target of the CMake build. */ + public interface SetUpMainTarget { + // Implementation note: This indirection is necessary because the Python + // target produces a shared object file, not an executable. + String getCmakeCode(boolean hasMain, String executableName, Stream cSources); + } + + /** Generate the C-target-specific code for configuring the executable produced by the build. */ + private static String setUpMainTarget( + boolean hasMain, String executableName, Stream cSources) { + var code = new CodeBuilder(); + code.pr("add_subdirectory(core)"); + code.newLine(); + code.pr("set(LF_MAIN_TARGET " + executableName + ")"); + code.newLine(); + + if (hasMain) { + code.pr("# Declare a new executable target and list all its sources"); + code.pr("add_executable("); + } else { + code.pr("# Declare a new library target and list all its sources"); + code.pr("add_library("); + } + code.indent(); + code.pr("${LF_MAIN_TARGET}"); + cSources.forEach(code::pr); + code.unindent(); + code.pr(")"); + code.newLine(); + return code.toString(); + } + + private static String setUpMainTargetZephyr( + boolean hasMain, String executableName, Stream cSources) { + var code = new CodeBuilder(); + code.pr("add_subdirectory(core)"); + code.pr("target_link_libraries(core PUBLIC zephyr_interface)"); + // FIXME: Linking the reactor-c corelib with the zephyr kernel lib + // resolves linker issues but I am not yet sure if it is safe + code.pr("target_link_libraries(core PRIVATE kernel)"); + code.newLine(); + + if (hasMain) { + code.pr("# Declare a new executable target and list all its sources"); + code.pr("set(LF_MAIN_TARGET app)"); + code.pr("target_sources("); + } else { + code.pr("# Declare a new library target and list all its sources"); + code.pr("set(LF_MAIN_TARGET" + executableName + ")"); + code.pr("add_library("); + } + code.indent(); + code.pr("${LF_MAIN_TARGET}"); - private static String setUpMainTargetZephyr( - boolean hasMain, - String executableName, - Stream cSources - ) { - var code = new CodeBuilder(); - code.pr("add_subdirectory(core)"); - code.pr("target_link_libraries(core PUBLIC zephyr_interface)"); - // FIXME: Linking the reactor-c corelib with the zephyr kernel lib - // resolves linker issues but I am not yet sure if it is safe - code.pr("target_link_libraries(core PRIVATE kernel)"); - code.newLine(); - - if (hasMain) { - code.pr("# Declare a new executable target and list all its sources"); - code.pr("set(LF_MAIN_TARGET app)"); - code.pr("target_sources("); - } else { - code.pr("# Declare a new library target and list all its sources"); - code.pr("set(LF_MAIN_TARGET"+executableName+")"); - code.pr("add_library("); - } - code.indent(); - code.pr("${LF_MAIN_TARGET}"); - - if (hasMain) { - code.pr("PRIVATE"); - } - - cSources.forEach(code::pr); - code.unindent(); - code.pr(")"); - code.newLine(); - return code.toString(); + if (hasMain) { + code.pr("PRIVATE"); } + + cSources.forEach(code::pr); + code.unindent(); + code.pr(")"); + code.newLine(); + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 9fcb72b4a6..f919977ba5 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2019-2021, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -33,7 +33,6 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; @@ -47,8 +46,8 @@ import org.lflang.util.LFCommand; /** - * Responsible for creating and executing the necessary CMake command to compile - * code that is generated by the CGenerator. This class uses CMake to compile. + * Responsible for creating and executing the necessary CMake command to compile code that is + * generated by the CGenerator. This class uses CMake to compile. * * @author Soroush Bateni * @author Edward A. Lee @@ -59,392 +58,386 @@ */ public class CCompiler { - FileConfig fileConfig; - TargetConfig targetConfig; - ErrorReporter errorReporter; - - /** - * Indicate whether the compiler is in C++ mode. - * In C++ mode, the compiler produces .cpp files instead - * of .c files and uses a C++ compiler to compiler the code. - */ - private final boolean cppMode; - - /** - * A factory for compiler commands. - */ - GeneratorCommandFactory commandFactory; - - /** - * Create an instance of CCompiler. - * - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. - * @param errorReporter Used to report errors. - * @param cppMode Whether the generated code should be compiled as if it - * were C++. - */ - public CCompiler( - TargetConfig targetConfig, - FileConfig fileConfig, - ErrorReporter errorReporter, - boolean cppMode - ) { - this.fileConfig = fileConfig; - this.targetConfig = targetConfig; - this.errorReporter = errorReporter; - this.commandFactory = new GeneratorCommandFactory(errorReporter, fileConfig); - this.cppMode = cppMode; + FileConfig fileConfig; + TargetConfig targetConfig; + ErrorReporter errorReporter; + + /** + * Indicate whether the compiler is in C++ mode. In C++ mode, the compiler produces .cpp files + * instead of .c files and uses a C++ compiler to compiler the code. + */ + private final boolean cppMode; + + /** A factory for compiler commands. */ + GeneratorCommandFactory commandFactory; + + /** + * Create an instance of CCompiler. + * + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. + * @param errorReporter Used to report errors. + * @param cppMode Whether the generated code should be compiled as if it were C++. + */ + public CCompiler( + TargetConfig targetConfig, + FileConfig fileConfig, + ErrorReporter errorReporter, + boolean cppMode) { + this.fileConfig = fileConfig; + this.targetConfig = targetConfig; + this.errorReporter = errorReporter; + this.commandFactory = new GeneratorCommandFactory(errorReporter, fileConfig); + this.cppMode = cppMode; + } + + /** + * Run the C compiler by invoking cmake and make. + * + * @param generator An instance of GeneratorBase, only used to report error line numbers in the + * Eclipse IDE. + * @return true if compilation succeeds, false otherwise. + */ + public boolean runCCompiler(GeneratorBase generator, LFGeneratorContext context) + throws IOException { + // Set the build directory to be "build" + Path buildPath = fileConfig.getSrcGenPath().resolve("build"); + // Remove the previous build directory if it exists to + // avoid any error residue that can occur in CMake from + // a previous build. + // FIXME: This is slow and only needed if an error + // has previously occurred. Deleting the build directory + // if no prior errors have occurred can prolong the compilation + // substantially. See #1416 for discussion. + FileUtil.deleteDirectory(buildPath); + // Make sure the build directory exists + Files.createDirectories(buildPath); + + LFCommand compile = compileCmakeCommand(); + if (compile == null) { + return false; } - /** - * Run the C compiler by invoking cmake and make. - * @param generator An instance of GeneratorBase, only used to report error line numbers - * in the Eclipse IDE. - * - * @return true if compilation succeeds, false otherwise. - */ - public boolean runCCompiler( - GeneratorBase generator, - LFGeneratorContext context - ) throws IOException { - // Set the build directory to be "build" - Path buildPath = fileConfig.getSrcGenPath().resolve("build"); - // Remove the previous build directory if it exists to - // avoid any error residue that can occur in CMake from - // a previous build. - // FIXME: This is slow and only needed if an error - // has previously occurred. Deleting the build directory - // if no prior errors have occurred can prolong the compilation - // substantially. See #1416 for discussion. - FileUtil.deleteDirectory(buildPath); - // Make sure the build directory exists - Files.createDirectories(buildPath); - - LFCommand compile = compileCmakeCommand(); - if (compile == null) { - return false; - } - - // Use the user-specified compiler if any - if (targetConfig.compiler != null) { - if (cppMode) { - // Set the CXX environment variable to change the C++ compiler. - compile.replaceEnvironmentVariable("CXX", targetConfig.compiler); - } else { - // Set the CC environment variable to change the C compiler. - compile.replaceEnvironmentVariable("CC", targetConfig.compiler); - } - } - - int cMakeReturnCode = compile.run(context.getCancelIndicator()); - - if (cMakeReturnCode != 0 && - context.getMode() == LFGeneratorContext.Mode.STANDALONE && - !outputContainsKnownCMakeErrors(compile.getErrors().toString())) { - errorReporter.reportError(targetConfig.compiler + " failed with error code " + cMakeReturnCode); - } - - // For warnings (vs. errors), the return code is 0. - // But we still want to mark the IDE. - if (compile.getErrors().toString().length() > 0 && - context.getMode() != LFGeneratorContext.Mode.STANDALONE && - !outputContainsKnownCMakeErrors(compile.getErrors().toString())) { - generator.reportCommandErrors(compile.getErrors().toString()); - } - - int makeReturnCode = 0; - - if (cMakeReturnCode == 0) { - LFCommand build = buildCmakeCommand(); - - makeReturnCode = build.run(context.getCancelIndicator()); - - if (makeReturnCode != 0 && - context.getMode() == LFGeneratorContext.Mode.STANDALONE && - !outputContainsKnownCMakeErrors(build.getErrors().toString())) { - errorReporter.reportError(targetConfig.compiler + " failed with error code " + makeReturnCode); - } - - // For warnings (vs. errors), the return code is 0. - // But we still want to mark the IDE. - if (build.getErrors().toString().length() > 0 && - context.getMode() != LFGeneratorContext.Mode.STANDALONE && - !outputContainsKnownCMakeErrors(build.getErrors().toString())) { - generator.reportCommandErrors(build.getErrors().toString()); - } - - - if (makeReturnCode == 0 && build.getErrors().toString().length() == 0) { - System.out.println("SUCCESS: Compiling generated code for " + fileConfig.name + " finished with no errors."); - } - - if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.platformOptions.flash) { - System.out.println("Invoking flash command for Zephyr"); - LFCommand flash = buildWestFlashCommand(); - int flashRet = flash.run(); - if (flashRet != 0) { - errorReporter.reportError("West flash command failed with error code " + flashRet); - } else { - System.out.println("SUCCESS: Flashed application with west"); - } - } - - } - return cMakeReturnCode == 0 && makeReturnCode == 0; + // Use the user-specified compiler if any + if (targetConfig.compiler != null) { + if (cppMode) { + // Set the CXX environment variable to change the C++ compiler. + compile.replaceEnvironmentVariable("CXX", targetConfig.compiler); + } else { + // Set the CC environment variable to change the C compiler. + compile.replaceEnvironmentVariable("CC", targetConfig.compiler); + } } + int cMakeReturnCode = compile.run(context.getCancelIndicator()); - /** - * Return a command to compile the specified C file using CMake. - * This produces a C-specific compile command. - */ - public LFCommand compileCmakeCommand() { - // Set the build directory to be "build" - Path buildPath = fileConfig.getSrcGenPath().resolve("build"); - - LFCommand command = commandFactory.createCommand( - "cmake", cmakeOptions(targetConfig, fileConfig), - buildPath); - if (command == null) { - errorReporter.reportError( - "The C/CCpp target requires CMAKE >= " + CCmakeGenerator.MIN_CMAKE_VERSION - + " to compile the generated code. " + - "Auto-compiling can be disabled using the \"no-compile: true\" target property."); - } - return command; + if (cMakeReturnCode != 0 + && context.getMode() == LFGeneratorContext.Mode.STANDALONE + && !outputContainsKnownCMakeErrors(compile.getErrors().toString())) { + errorReporter.reportError( + targetConfig.compiler + " failed with error code " + cMakeReturnCode); } - static Stream cmakeCompileDefinitions(TargetConfig targetConfig) { - return targetConfig.compileDefinitions.entrySet().stream() - .map(entry -> "-D" + entry.getKey() + "=" + entry.getValue()); + // For warnings (vs. errors), the return code is 0. + // But we still want to mark the IDE. + if (compile.getErrors().toString().length() > 0 + && context.getMode() != LFGeneratorContext.Mode.STANDALONE + && !outputContainsKnownCMakeErrors(compile.getErrors().toString())) { + generator.reportCommandErrors(compile.getErrors().toString()); } - private static List cmakeOptions(TargetConfig targetConfig, FileConfig fileConfig) { - List arguments = new ArrayList<>(); - cmakeCompileDefinitions(targetConfig).forEachOrdered(arguments::add); - String separator = File.separator; - String maybeQuote = ""; // Windows seems to require extra level of quoting. - String srcPath = fileConfig.srcPath.toString(); // Windows requires escaping the backslashes. - String rootPath = fileConfig.srcPkgPath.toString(); - if (separator.equals("\\")) { - separator = "\\\\\\\\"; - maybeQuote = "\\\""; - srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\"); - rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\"); + int makeReturnCode = 0; + + if (cMakeReturnCode == 0) { + LFCommand build = buildCmakeCommand(); + + makeReturnCode = build.run(context.getCancelIndicator()); + + if (makeReturnCode != 0 + && context.getMode() == LFGeneratorContext.Mode.STANDALONE + && !outputContainsKnownCMakeErrors(build.getErrors().toString())) { + errorReporter.reportError( + targetConfig.compiler + " failed with error code " + makeReturnCode); + } + + // For warnings (vs. errors), the return code is 0. + // But we still want to mark the IDE. + if (build.getErrors().toString().length() > 0 + && context.getMode() != LFGeneratorContext.Mode.STANDALONE + && !outputContainsKnownCMakeErrors(build.getErrors().toString())) { + generator.reportCommandErrors(build.getErrors().toString()); + } + + if (makeReturnCode == 0 && build.getErrors().toString().length() == 0) { + System.out.println( + "SUCCESS: Compiling generated code for " + + fileConfig.name + + " finished with no errors."); + } + + if (targetConfig.platformOptions.platform == Platform.ZEPHYR + && targetConfig.platformOptions.flash) { + System.out.println("Invoking flash command for Zephyr"); + LFCommand flash = buildWestFlashCommand(); + int flashRet = flash.run(); + if (flashRet != 0) { + errorReporter.reportError("West flash command failed with error code " + flashRet); + } else { + System.out.println("SUCCESS: Flashed application with west"); } - arguments.addAll(List.of( - "-DCMAKE_BUILD_TYPE=" + ((targetConfig.cmakeBuildType!=null) ? targetConfig.cmakeBuildType.toString() : "Release"), + } + } + return cMakeReturnCode == 0 && makeReturnCode == 0; + } + + /** + * Return a command to compile the specified C file using CMake. This produces a C-specific + * compile command. + */ + public LFCommand compileCmakeCommand() { + // Set the build directory to be "build" + Path buildPath = fileConfig.getSrcGenPath().resolve("build"); + + LFCommand command = + commandFactory.createCommand("cmake", cmakeOptions(targetConfig, fileConfig), buildPath); + if (command == null) { + errorReporter.reportError( + "The C/CCpp target requires CMAKE >= " + + CCmakeGenerator.MIN_CMAKE_VERSION + + " to compile the generated code. " + + "Auto-compiling can be disabled using the \"no-compile: true\" target property."); + } + return command; + } + + static Stream cmakeCompileDefinitions(TargetConfig targetConfig) { + return targetConfig.compileDefinitions.entrySet().stream() + .map(entry -> "-D" + entry.getKey() + "=" + entry.getValue()); + } + + private static List cmakeOptions(TargetConfig targetConfig, FileConfig fileConfig) { + List arguments = new ArrayList<>(); + cmakeCompileDefinitions(targetConfig).forEachOrdered(arguments::add); + String separator = File.separator; + String maybeQuote = ""; // Windows seems to require extra level of quoting. + String srcPath = fileConfig.srcPath.toString(); // Windows requires escaping the backslashes. + String rootPath = fileConfig.srcPkgPath.toString(); + if (separator.equals("\\")) { + separator = "\\\\\\\\"; + maybeQuote = "\\\""; + srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\"); + rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\"); + } + arguments.addAll( + List.of( + "-DCMAKE_BUILD_TYPE=" + + ((targetConfig.cmakeBuildType != null) + ? targetConfig.cmakeBuildType.toString() + : "Release"), "-DCMAKE_INSTALL_PREFIX=" + FileUtil.toUnixString(fileConfig.getOutPath()), - "-DCMAKE_INSTALL_BINDIR=" + FileUtil.toUnixString( - fileConfig.getOutPath().relativize( - fileConfig.binPath - ) - ), - "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"" - )); - // Add #define for source file directory. - // Do not do this for federated programs because for those, the definition is put - // into the cmake file (and fileConfig.srcPath is the wrong directory anyway). - if (!fileConfig.srcPath.toString().contains("fed-gen")) { - // Do not convert to Unix path - arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\""); - arguments.add("-DLF_PACKAGE_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\""); - } - arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); - - if (GeneratorUtils.isHostWindows()) { - arguments.add("-DCMAKE_SYSTEM_VERSION=\"10.0\""); - } - return arguments; + "-DCMAKE_INSTALL_BINDIR=" + + FileUtil.toUnixString(fileConfig.getOutPath().relativize(fileConfig.binPath)), + "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"")); + // Add #define for source file directory. + // Do not do this for federated programs because for those, the definition is put + // into the cmake file (and fileConfig.srcPath is the wrong directory anyway). + if (!fileConfig.srcPath.toString().contains("fed-gen")) { + // Do not convert to Unix path + arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\""); + arguments.add("-DLF_PACKAGE_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\""); } + arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); - /** - * Return the cmake config name correspnding to a given build type. - */ - private String buildTypeToCmakeConfig(TargetProperty.BuildType type) { - if (type == null) { - return "Release"; - } - switch (type) { - case TEST: - return "Debug"; - default: - return type.toString(); - } + if (GeneratorUtils.isHostWindows()) { + arguments.add("-DCMAKE_SYSTEM_VERSION=\"10.0\""); } + return arguments; + } - /** - * Return a command to build the specified C file using CMake. - * This produces a C-specific build command. - * - *

    Note: It appears that configuration and build cannot happen in one command. - * Therefore, this is separated into a compile command and a build command.

    - */ - public LFCommand buildCmakeCommand() { - // Set the build directory to be "build" - Path buildPath = fileConfig.getSrcGenPath().resolve("build"); - String cores = String.valueOf(Runtime.getRuntime().availableProcessors()); - LFCommand command = commandFactory.createCommand( - "cmake", List.of( - "--build", ".", "--target", "install", "--parallel", cores, "--config", - buildTypeToCmakeConfig(targetConfig.cmakeBuildType) - ), - buildPath); - if (command == null) { - errorReporter.reportError( - "The C/CCpp target requires CMAKE >= 3.5 to compile the generated code. " - + "Auto-compiling can be disabled using the \"no-compile: true\" target property." - ); - } - return command; + /** Return the cmake config name correspnding to a given build type. */ + private String buildTypeToCmakeConfig(TargetProperty.BuildType type) { + if (type == null) { + return "Release"; } - - /** - * Return a flash/emulate command using west. - * If board is null (defaults to qemu_cortex_m3) or qemu_* - * Return a flash command which runs the target as an emulation - * If ordinary target, return {@code west flash} - */ - public LFCommand buildWestFlashCommand() { - // Set the build directory to be "build" - Path buildPath = fileConfig.getSrcGenPath().resolve("build"); - String board = targetConfig.platformOptions.board; - LFCommand cmd; - if (board == null || board.startsWith("qemu")) { - cmd = commandFactory.createCommand( - "west", List.of("build", "-t", "run"), buildPath); - } else { - cmd = commandFactory.createCommand( - "west", List.of("flash"), buildPath); - } - if (cmd == null) { - errorReporter.reportError( - "Could not create west flash command." - ); - } - - return cmd; + switch (type) { + case TEST: + return "Debug"; + default: + return type.toString(); } - - /** - * Check if the output produced by CMake has any known and common errors. - * If a known error is detected, a specialized, more informative message - * is shown. - * - * Errors currently detected: - *
      - *
    • C++ compiler used to compile C files: This error shows up as - * '#error "The CMAKE_C_COMPILER is set to a C++ compiler"' in - * the 'CMakeOutput' string.
    • - *
    - * - * @param CMakeOutput The captured output from CMake. - * @return true if the provided 'CMakeOutput' contains a known error. - * false otherwise. - */ - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - private boolean outputContainsKnownCMakeErrors(String CMakeOutput) { - // Check if the error thrown is due to the wrong compiler - if (CMakeOutput.contains("The CMAKE_C_COMPILER is set to a C++ compiler")) { - // If so, print an appropriate error message - if (targetConfig.compiler != null) { - errorReporter.reportError( - "A C++ compiler was requested in the compiler target property." - + " Use the CCpp or the Cpp target instead."); - } else { - errorReporter.reportError("\"A C++ compiler was detected." - + " The C target works best with a C compiler." - + " Use the CCpp or the Cpp target instead.\""); - } - return true; - } - return false; + } + + /** + * Return a command to build the specified C file using CMake. This produces a C-specific build + * command. + * + *

    Note: It appears that configuration and build cannot happen in one command. Therefore, this + * is separated into a compile command and a build command. + */ + public LFCommand buildCmakeCommand() { + // Set the build directory to be "build" + Path buildPath = fileConfig.getSrcGenPath().resolve("build"); + String cores = String.valueOf(Runtime.getRuntime().availableProcessors()); + LFCommand command = + commandFactory.createCommand( + "cmake", + List.of( + "--build", + ".", + "--target", + "install", + "--parallel", + cores, + "--config", + buildTypeToCmakeConfig(targetConfig.cmakeBuildType)), + buildPath); + if (command == null) { + errorReporter.reportError( + "The C/CCpp target requires CMAKE >= 3.5 to compile the generated code. " + + "Auto-compiling can be disabled using the \"no-compile: true\" target property."); + } + return command; + } + + /** + * Return a flash/emulate command using west. If board is null (defaults to qemu_cortex_m3) or + * qemu_* Return a flash command which runs the target as an emulation If ordinary target, return + * {@code west flash} + */ + public LFCommand buildWestFlashCommand() { + // Set the build directory to be "build" + Path buildPath = fileConfig.getSrcGenPath().resolve("build"); + String board = targetConfig.platformOptions.board; + LFCommand cmd; + if (board == null || board.startsWith("qemu")) { + cmd = commandFactory.createCommand("west", List.of("build", "-t", "run"), buildPath); + } else { + cmd = commandFactory.createCommand("west", List.of("flash"), buildPath); + } + if (cmd == null) { + errorReporter.reportError("Could not create west flash command."); } - /** - * Return a command to compile the specified C file using a native compiler - * (generally gcc unless overridden by the user). - * This produces a C specific compile command. - * - * @param fileToCompile The C filename without the .c extension. - * @param noBinary If true, the compiler will create a .o output instead of a binary. - * If false, the compile command will produce a binary. - */ - public LFCommand compileCCommand( - String fileToCompile, - boolean noBinary - ) { - String cFilename = getTargetFileName(fileToCompile, cppMode, targetConfig); - - Path relativeSrcPath = fileConfig.getOutPath().relativize( - fileConfig.getSrcGenPath().resolve(Paths.get(cFilename))); - Path relativeBinPath = fileConfig.getOutPath().relativize( - fileConfig.binPath.resolve(Paths.get(fileToCompile))); - - // NOTE: we assume that any C compiler takes Unix paths as arguments. - String relSrcPathString = FileUtil.toUnixString(relativeSrcPath); - String relBinPathString = FileUtil.toUnixString(relativeBinPath); - - // If there is no main reactor, then generate a .o file not an executable. - if (noBinary) { - relBinPathString += ".o"; - } - - ArrayList compileArgs = new ArrayList<>(); - compileArgs.add(relSrcPathString); - for (String file: targetConfig.compileAdditionalSources) { - var relativePath = fileConfig.getOutPath().relativize( - fileConfig.getSrcGenPath().resolve(Paths.get(file))); - compileArgs.add(FileUtil.toUnixString(relativePath)); - } - compileArgs.addAll(targetConfig.compileLibraries); + return cmd; + } + + /** + * Check if the output produced by CMake has any known and common errors. If a known error is + * detected, a specialized, more informative message is shown. + * + *

    Errors currently detected: + * + *

      + *
    • C++ compiler used to compile C files: This error shows up as '#error "The + * CMAKE_C_COMPILER is set to a C++ compiler"' in the 'CMakeOutput' string. + *
    + * + * @param CMakeOutput The captured output from CMake. + * @return true if the provided 'CMakeOutput' contains a known error. false otherwise. + */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + private boolean outputContainsKnownCMakeErrors(String CMakeOutput) { + // Check if the error thrown is due to the wrong compiler + if (CMakeOutput.contains("The CMAKE_C_COMPILER is set to a C++ compiler")) { + // If so, print an appropriate error message + if (targetConfig.compiler != null) { + errorReporter.reportError( + "A C++ compiler was requested in the compiler target property." + + " Use the CCpp or the Cpp target instead."); + } else { + errorReporter.reportError( + "\"A C++ compiler was detected." + + " The C target works best with a C compiler." + + " Use the CCpp or the Cpp target instead.\""); + } + return true; + } + return false; + } + + /** + * Return a command to compile the specified C file using a native compiler (generally gcc unless + * overridden by the user). This produces a C specific compile command. + * + * @param fileToCompile The C filename without the .c extension. + * @param noBinary If true, the compiler will create a .o output instead of a binary. If false, + * the compile command will produce a binary. + */ + public LFCommand compileCCommand(String fileToCompile, boolean noBinary) { + String cFilename = getTargetFileName(fileToCompile, cppMode, targetConfig); + + Path relativeSrcPath = + fileConfig + .getOutPath() + .relativize(fileConfig.getSrcGenPath().resolve(Paths.get(cFilename))); + Path relativeBinPath = + fileConfig.getOutPath().relativize(fileConfig.binPath.resolve(Paths.get(fileToCompile))); + + // NOTE: we assume that any C compiler takes Unix paths as arguments. + String relSrcPathString = FileUtil.toUnixString(relativeSrcPath); + String relBinPathString = FileUtil.toUnixString(relativeBinPath); + + // If there is no main reactor, then generate a .o file not an executable. + if (noBinary) { + relBinPathString += ".o"; + } - // Add compile definitions - targetConfig.compileDefinitions.forEach((key,value) -> compileArgs.add("-D"+key+"="+value)); + ArrayList compileArgs = new ArrayList<>(); + compileArgs.add(relSrcPathString); + for (String file : targetConfig.compileAdditionalSources) { + var relativePath = + fileConfig.getOutPath().relativize(fileConfig.getSrcGenPath().resolve(Paths.get(file))); + compileArgs.add(FileUtil.toUnixString(relativePath)); + } + compileArgs.addAll(targetConfig.compileLibraries); - // Finally, add the compiler flags in target parameters (if any) - compileArgs.addAll(targetConfig.compilerFlags); + // Add compile definitions + targetConfig.compileDefinitions.forEach( + (key, value) -> compileArgs.add("-D" + key + "=" + value)); - // Only set the output file name if it hasn't already been set - // using a target property or Args line flag. - if (!compileArgs.contains("-o")) { - compileArgs.add("-o"); - compileArgs.add(relBinPathString); - } + // Finally, add the compiler flags in target parameters (if any) + compileArgs.addAll(targetConfig.compilerFlags); - // If there is no main reactor, then use the -c flag to prevent linking from occurring. - // FIXME: we could add a {@code -c} flag to {@code lfc} to make this explicit in stand-alone mode. - // Then again, I think this only makes sense when we can do linking. - if (noBinary) { - compileArgs.add("-c"); // FIXME: revisit - } + // Only set the output file name if it hasn't already been set + // using a target property or Args line flag. + if (!compileArgs.contains("-o")) { + compileArgs.add("-o"); + compileArgs.add(relBinPathString); + } - LFCommand command = commandFactory.createCommand(targetConfig.compiler, compileArgs, fileConfig.getOutPath()); - if (command == null) { - errorReporter.reportError( - "The C/CCpp target requires GCC >= 7 to compile the generated code. " + - "Auto-compiling can be disabled using the \"no-compile: true\" target property."); - } - return command; + // If there is no main reactor, then use the -c flag to prevent linking from occurring. + // FIXME: we could add a {@code -c} flag to {@code lfc} to make this explicit in stand-alone + // mode. + // Then again, I think this only makes sense when we can do linking. + if (noBinary) { + compileArgs.add("-c"); // FIXME: revisit } - /** - * Produces the filename including the target-specific extension - * - * @param fileName The base name of the file without any extensions - * @param cppMode Indicate whether the compiler is in C++ mode - * In C++ mode, the compiler produces .cpp files instead - * of .c files and uses a C++ compiler to compiler the code. - */ - static String getTargetFileName(String fileName, boolean cppMode, TargetConfig targetConfig) { - if (targetConfig.platformOptions.platform == Platform.ARDUINO) { - return fileName + ".ino"; - } - if (cppMode) { - // If the C++ mode is enabled, use a .cpp extension - return fileName + ".cpp"; - } - return fileName + ".c"; + LFCommand command = + commandFactory.createCommand(targetConfig.compiler, compileArgs, fileConfig.getOutPath()); + if (command == null) { + errorReporter.reportError( + "The C/CCpp target requires GCC >= 7 to compile the generated code. " + + "Auto-compiling can be disabled using the \"no-compile: true\" target property."); + } + return command; + } + + /** + * Produces the filename including the target-specific extension + * + * @param fileName The base name of the file without any extensions + * @param cppMode Indicate whether the compiler is in C++ mode In C++ mode, the compiler produces + * .cpp files instead of .c files and uses a C++ compiler to compiler the code. + */ + static String getTargetFileName(String fileName, boolean cppMode, TargetConfig targetConfig) { + if (targetConfig.platformOptions.platform == Platform.ARDUINO) { + return fileName + ".ino"; + } + if (cppMode) { + // If the C++ mode is enabled, use a .cpp extension + return fileName + ".cpp"; } + return fileName + ".c"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java b/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java index 41731106c3..529e37a975 100644 --- a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java @@ -1,36 +1,30 @@ package org.lflang.generator.c; import org.lflang.generator.CodeBuilder; -import org.lflang.lf.Reactor; -/** - * Generates C constructor code for a reactor. - * - */ +/** Generates C constructor code for a reactor. */ public class CConstructorGenerator { - /** - * Generate a constructor for the specified reactor in the specified federate. - * @param reactor The parsed reactor data structure. - * @param constructorCode Lines of code previously generated that need to - * go into the constructor. - */ - public static String generateConstructor( - TypeParameterizedReactor tpr, - String constructorCode - ) { - var structType = CUtil.selfType(tpr); - var code = new CodeBuilder(); - code.pr(structType+"* new_"+CUtil.getName(tpr)+"() {"); - code.indent(); - code.pr(structType+"* self = ("+structType+"*)_lf_new_reactor(sizeof("+structType+"));"); - code.pr(constructorCode); - code.pr("return self;"); - code.unindent(); - code.pr("}"); - return code.toString(); - } + /** + * Generate a constructor for the specified reactor in the specified federate. + * + * @param reactor The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to go into the constructor. + */ + public static String generateConstructor(TypeParameterizedReactor tpr, String constructorCode) { + var structType = CUtil.selfType(tpr); + var code = new CodeBuilder(); + code.pr(structType + "* new_" + CUtil.getName(tpr) + "() {"); + code.indent(); + code.pr( + structType + "* self = (" + structType + "*)_lf_new_reactor(sizeof(" + structType + "));"); + code.pr(constructorCode); + code.pr("return self;"); + code.unindent(); + code.pr("}"); + return code.toString(); + } - public static String generateConstructorPrototype(TypeParameterizedReactor tpr) { - return CUtil.selfType(tpr)+"* new_"+CUtil.getName(tpr)+"();"; - } + public static String generateConstructorPrototype(TypeParameterizedReactor tpr) { + return CUtil.selfType(tpr) + "* new_" + CUtil.getName(tpr) + "();"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java index 46503d87cc..2d83a105da 100644 --- a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java +++ b/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java @@ -1,32 +1,28 @@ package org.lflang.generator.c; + import java.util.List; /** - * Generates the list of files to be included in the - * core library for each reactor given conditions listed - * as arguments of each function. + * Generates the list of files to be included in the core library for each reactor given conditions + * listed as arguments of each function. * * @author Hou Seng Wong */ public class CCoreFilesUtils { - public static List getCTargetSrc() { - return List.of( - "lib/schedule.c" - ); - } + public static List getCTargetSrc() { + return List.of("lib/schedule.c"); + } - public static List getCTargetHeader() { - return List.of( - "include/api/api.h" - ); - } + public static List getCTargetHeader() { + return List.of("include/api/api.h"); + } - public static String getCTargetSetHeader() { - return "include/api/set.h"; - } + public static String getCTargetSetHeader() { + return "include/api/set.h"; + } - public static String getCTargetSetUndefHeader() { - return "include/api/set_undef.h"; - } + public static String getCTargetSetUndefHeader() { + return "include/api/set_undef.h"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java b/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java index f5aa244e60..ec75412b42 100644 --- a/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java @@ -9,54 +9,51 @@ public class CDelayBodyGenerator implements DelayBodyGenerator { - protected CTypes types; - - public CDelayBodyGenerator(CTypes types) { - this.types = types; - } - - /** - * Generate code for the body of a reaction that takes an input and - * schedules an action with the value of that input. - * @param action The action to schedule - * @param port The port to read from - */ - @Override - public String generateDelayBody(Action action, VarRef port) { - var ref = ASTUtils.generateVarRef(port); - return CReactionGenerator.generateDelayBody( - ref, - action.getName(), - CUtil.isTokenType(getInferredType(action), types) - ); - } - - /** - * Generate code for the body of a reaction that is triggered by the - * given action and writes its value to the given port. This realizes - * the receiving end of a logical delay specified with the 'after' - * keyword. - * @param action The action that triggers the reaction - * @param port The port to write to. - */ - @Override - public String generateForwardBody(Action action, VarRef port) { - var outputName = ASTUtils.generateVarRef(port); - return CReactionGenerator.generateForwardBody( - outputName, - types.getTargetType(action), - action.getName(), - CUtil.isTokenType(getInferredType(action), types) - ); - } - - @Override - public String generateDelayGeneric() { - throw new UnsupportedOperationException("TODO: auto-generated method stub"); - } - - @Override - public boolean generateAfterDelaysWithVariableWidth() { - return true; - } + protected CTypes types; + + public CDelayBodyGenerator(CTypes types) { + this.types = types; + } + + /** + * Generate code for the body of a reaction that takes an input and schedules an action with the + * value of that input. + * + * @param action The action to schedule + * @param port The port to read from + */ + @Override + public String generateDelayBody(Action action, VarRef port) { + var ref = ASTUtils.generateVarRef(port); + return CReactionGenerator.generateDelayBody( + ref, action.getName(), CUtil.isTokenType(getInferredType(action), types)); + } + + /** + * Generate code for the body of a reaction that is triggered by the given action and writes its + * value to the given port. This realizes the receiving end of a logical delay specified with the + * 'after' keyword. + * + * @param action The action that triggers the reaction + * @param port The port to write to. + */ + @Override + public String generateForwardBody(Action action, VarRef port) { + var outputName = ASTUtils.generateVarRef(port); + return CReactionGenerator.generateForwardBody( + outputName, + types.getTargetType(action), + action.getName(), + CUtil.isTokenType(getInferredType(action), types)); + } + + @Override + public String generateDelayGeneric() { + throw new UnsupportedOperationException("TODO: auto-generated method stub"); + } + + @Override + public boolean generateAfterDelaysWithVariableWidth() { + return true; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CDockerGenerator.java b/org.lflang/src/org/lflang/generator/c/CDockerGenerator.java index ae9058dcbb..f52e23a949 100644 --- a/org.lflang/src/org/lflang/generator/c/CDockerGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CDockerGenerator.java @@ -1,9 +1,7 @@ package org.lflang.generator.c; import java.util.stream.Collectors; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - import org.lflang.Target; import org.lflang.generator.DockerGenerator; import org.lflang.generator.LFGeneratorContext; @@ -15,62 +13,66 @@ * @author Hou Seng Wong */ public class CDockerGenerator extends DockerGenerator { - private static final String DEFAULT_BASE_IMAGE = "alpine:latest"; + private static final String DEFAULT_BASE_IMAGE = "alpine:latest"; - /** - * The constructor for the base docker file generation class. - * - * @param context The context of the code generator. - */ - public CDockerGenerator(LFGeneratorContext context) { - super(context); - } + /** + * The constructor for the base docker file generation class. + * + * @param context The context of the code generator. + */ + public CDockerGenerator(LFGeneratorContext context) { + super(context); + } - - /** - * Generate the contents of the docker file. - */ - @Override - protected String generateDockerFileContent() { - var lfModuleName = context.getFileConfig().name; - var config = context.getTargetConfig(); - var compileCommand = IterableExtensions.isNullOrEmpty(config.buildCommands) ? - generateDefaultCompileCommand() : - StringUtil.joinObjects(config.buildCommands, " "); - var compiler = config.target == Target.CCPP ? "g++" : "gcc"; - var baseImage = DEFAULT_BASE_IMAGE; - if (config.dockerOptions != null && config.dockerOptions.from != null) { - baseImage = config.dockerOptions.from; - } - return String.join("\n", - "# For instructions, see: https://www.lf-lang.org/docs/handbook/containerized-execution", - "FROM "+baseImage+" AS builder", - "WORKDIR /lingua-franca/"+lfModuleName, - "RUN set -ex && apk add --no-cache "+compiler+" musl-dev cmake make", - "COPY . src-gen", - compileCommand, - "", - "FROM "+baseImage, - "WORKDIR /lingua-franca", - "RUN mkdir bin", - "COPY --from=builder /lingua-franca/"+lfModuleName+"/bin/"+lfModuleName+" ./bin/"+lfModuleName, - "", - "# Use ENTRYPOINT not CMD so that command-line arguments go through", - "ENTRYPOINT [\"./bin/"+lfModuleName+"\"]", - "" - ); + /** Generate the contents of the docker file. */ + @Override + protected String generateDockerFileContent() { + var lfModuleName = context.getFileConfig().name; + var config = context.getTargetConfig(); + var compileCommand = + IterableExtensions.isNullOrEmpty(config.buildCommands) + ? generateDefaultCompileCommand() + : StringUtil.joinObjects(config.buildCommands, " "); + var compiler = config.target == Target.CCPP ? "g++" : "gcc"; + var baseImage = DEFAULT_BASE_IMAGE; + if (config.dockerOptions != null && config.dockerOptions.from != null) { + baseImage = config.dockerOptions.from; } + return String.join( + "\n", + "# For instructions, see: https://www.lf-lang.org/docs/handbook/containerized-execution", + "FROM " + baseImage + " AS builder", + "WORKDIR /lingua-franca/" + lfModuleName, + "RUN set -ex && apk add --no-cache " + compiler + " musl-dev cmake make", + "COPY . src-gen", + compileCommand, + "", + "FROM " + baseImage, + "WORKDIR /lingua-franca", + "RUN mkdir bin", + "COPY --from=builder /lingua-franca/" + + lfModuleName + + "/bin/" + + lfModuleName + + " ./bin/" + + lfModuleName, + "", + "# Use ENTRYPOINT not CMD so that command-line arguments go through", + "ENTRYPOINT [\"./bin/" + lfModuleName + "\"]", + ""); + } - /** Return the default compile command for the C docker container. */ - protected String generateDefaultCompileCommand() { - return String.join("\n", - "RUN set -ex && \\", - "mkdir bin && \\", - "cmake " + CCompiler.cmakeCompileDefinitions(context.getTargetConfig()) + /** Return the default compile command for the C docker container. */ + protected String generateDefaultCompileCommand() { + return String.join( + "\n", + "RUN set -ex && \\", + "mkdir bin && \\", + "cmake " + + CCompiler.cmakeCompileDefinitions(context.getTargetConfig()) .collect(Collectors.joining(" ")) - + " -S src-gen -B bin && \\", - "cd bin && \\", - "make all" - ); - } + + " -S src-gen -B bin && \\", + "cd bin && \\", + "make all"); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CFileConfig.java b/org.lflang/src/org/lflang/generator/c/CFileConfig.java index 362b8645b5..db9447a833 100644 --- a/org.lflang/src/org/lflang/generator/c/CFileConfig.java +++ b/org.lflang/src/org/lflang/generator/c/CFileConfig.java @@ -2,24 +2,29 @@ import java.io.IOException; import java.nio.file.Path; - import org.eclipse.emf.ecore.resource.Resource; - import org.lflang.FileConfig; public class CFileConfig extends FileConfig { - private final Path includePath; - public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { - super(resource, srcGenBasePath, useHierarchicalBin); - var includeDir = getOutPath().resolve("include"); - includePath = !useHierarchicalBin ? includeDir : includeDir.resolve(getOutPath().relativize(srcPath)).resolve(srcFile.getFileName().toString().split("\\.")[0]); - } + private final Path includePath; + + public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) + throws IOException { + super(resource, srcGenBasePath, useHierarchicalBin); + var includeDir = getOutPath().resolve("include"); + includePath = + !useHierarchicalBin + ? includeDir + : includeDir + .resolve(getOutPath().relativize(srcPath)) + .resolve(srcFile.getFileName().toString().split("\\.")[0]); + } - public Path getIncludePath() { - return includePath; - } + public Path getIncludePath() { + return includePath; + } - public String getRuntimeIncludePath() { - return "/lib/c/reactor-c/include"; - } + public String getRuntimeIncludePath() { + return "/lib/c/reactor-c/include"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index fce667067c..e8606eee9a 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1,26 +1,26 @@ /************* -Copyright (c) 2019-2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator.c; @@ -34,6 +34,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import static org.lflang.ast.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; +import com.google.common.collect.Iterables; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -46,34 +47,27 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; - -import org.lflang.ast.ASTUtils; -import org.lflang.generator.CodeMap; -import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; - -import org.lflang.federated.extensions.CExtensionUtils; - +import org.lflang.ast.ASTUtils; import org.lflang.ast.DelayedConnectionTransformation; - +import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.CodeMap; +import org.lflang.generator.DelayBodyGenerator; +import org.lflang.generator.DockerComposeGenerator; import org.lflang.generator.DockerGenerator; import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorUtils; - -import org.lflang.generator.DelayBodyGenerator; - import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFResource; import org.lflang.generator.ParameterInstance; @@ -99,165 +93,156 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; -import com.google.common.collect.Iterables; - /** - * Generator for C target. This class generates C code defining each reactor - * class given in the input .lf file and imported .lf files. The generated code - * has the following components: + * Generator for C target. This class generates C code defining each reactor class given in the + * input .lf file and imported .lf files. The generated code has the following components: + * *
      - *
    • A typedef for inputs, outputs, and actions of each reactor class. These - * define the types of the variables that reactions use to access inputs and - * action values and to set output values.
    • - *
    • A typedef for a "self" struct for each reactor class. One instance of this - * struct will be created for each reactor instance. See below for details.
    • - *
    • A function definition for each reaction in each reactor class. These - * functions take an instance of the self struct as an argument.
    • - *
    • A constructor function for each reactor class. This is used to create - * a new instance of the reactor. - * After these, the main generated function is _lf_initialize_trigger_objects(). - * This function creates the instances of reactors (using their constructors) - * and makes connections between them. - * A few other smaller functions are also generated.

      Self Struct

      - * The "self" struct has fields for each of the following:
    • - *
    • parameter: the field name and type match the parameter.
    • - *
    • state: the field name and type match the state.
    • - *
    • action: the field name prepends the action name with "lf". - * A second field for the action is also created to house the trigger_t object. - * That second field prepends the action name with "_lf__".
    • - *
    • output: the field name prepends the output name with "lf".
    • - *
    • input: the field name prepends the output name with "lf". - * A second field for the input is also created to house the trigger_t object. - * That second field prepends the input name with "_lf__". - * If, in addition, the reactor contains other reactors and reacts to their outputs, - * then there will be a struct within the self struct for each such contained reactor. - * The name of that self struct will be the name of the contained reactor prepended with "lf". - * That inside struct will contain pointers the outputs of the contained reactors - * that are read together with pointers to booleans indicating whether those outputs are present. - * If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to - * trigger_t object (see reactor.h) for the shutdown event and an action struct named - * _lf_shutdown on the self struct.

      Reaction Functions

      - * For each reaction in a reactor class, this generator will produce a C function - * that expects a pointer to an instance of the "self" struct as an argument. - * This function will contain verbatim the C code specified in the reaction, but - * before that C code, the generator inserts a few lines of code that extract from the - * self struct the variables that that code has declared it will use. For example, if - * the reaction declares that it is triggered by or uses an input named "x" of type - * int, the function will contain a line like this:
        r_x_t* x = self->_lf_x;
      - * 
      where r is the full name of the reactor class and the struct type r_x_t - * has fields is_present and value, where the type of value matches the port type. - * If the programmer fails to declare that it uses x, then the absence of the - * above code will trigger a compile error when the verbatim code attempts to read x.

      Constructor

      - * For each reactor class, this generator will create a constructor function named - * new_r, where r is the reactor class name. This function will malloc and return - * a pointer to an instance of the "self" struct. This struct initially represents - * an unconnected reactor. To establish connections between reactors, additional - * information needs to be inserted (see below). The self struct is made visible - * to the body of a reaction as a variable named "self". The self struct contains the - * following:
    • - *
    • Parameters: For each parameter p of the reactor, there will be a field p - * with the type and value of the parameter. So C code in the body of a reaction - * can access parameter values as self->p.
    • - *
    • State variables: For each state variable s of the reactor, there will be a field s - * with the type and value of the state variable. So C code in the body of a reaction - * can access state variables as self->s. - * The self struct also contains various fields that the user is not intended to - * use. The names of these fields begin with at least two underscores. They are:
    • - *
    • Outputs: For each output named out, there will be a field _lf_out that is - * a struct containing a value field whose type matches that of the output. - * The output value is stored here. That struct also has a field is_present - * that is a boolean indicating whether the output has been set. - * This field is reset to false at the start of every time - * step. There is also a field num_destinations whose value matches the - * number of downstream reactors that use this variable. This field must be - * set when connections are made or changed. It is used to determine for - * a mutable input destination whether a copy needs to be made.
    • - *
    • Inputs: For each input named in of type T, there is a field named _lf_in - * that is a pointer struct with a value field of type T. The struct pointed - * to also has an is_present field of type bool that indicates whether the - * input is present.
    • - *
    • Outputs of contained reactors: If a reactor reacts to outputs of a - * contained reactor r, then the self struct will contain a nested struct - * named _lf_r that has fields pointing to those outputs. For example, - * if r has an output out of type T, then there will be field in _lf_r - * named out that points to a struct containing a value field - * of type T and a field named is_present of type bool.
    • - *
    • Inputs of contained reactors: If a reactor sends to inputs of a - * contained reactor r, then the self struct will contain a nested struct - * named _lf_r that has fields for storing the values provided to those - * inputs. For example, if R has an input in of type T, then there will - * be field in _lf_R named in that is a struct with a value field - * of type T and a field named is_present of type bool.
    • - *
    • Actions: If the reactor has an action a (logical or physical), then there - * will be a field in the self struct named _lf_a and another named _lf__a. - * The type of the first is specific to the action and contains a value - * field with the type and value of the action (if it has a value). That - * struct also has a has_value field, an is_present field, and a - * token field (which is NULL if the action carries no value). - * The _lf__a field is of type trigger_t. - * That struct contains various things, including an array of reactions - * sensitive to this trigger and a lf_token_t struct containing the value of - * the action, if it has a value. See reactor.h in the C library for - * details.
    • - *
    • Reactions: Each reaction will have several fields in the self struct. - * Each of these has a name that begins with _lf__reaction_i, where i is - * the number of the reaction, starting with 0. The fields are:
        - *
      • _lf__reaction_i: The struct that is put onto the reaction queue to - * execute the reaction (see reactor.h in the C library).
      • - *
      • Timers: For each timer t, there is are two fields in the self struct:
          - *
        • _lf__t: The trigger_t struct for this timer (see reactor.h).
        • - *
        • _lf__t_reactions: An array of reactions (pointers to the - * reaction_t structs on this self struct) sensitive to this timer.
        • - *
        - *
      • - *
      - *
    • - *
    • Triggers: For each Timer, Action, Input, and Output of a contained - * reactor that triggers reactions, there will be a trigger_t struct - * on the self struct with name _lf__t, where t is the name of the trigger.

      Connections Between Reactors

      - * Establishing connections between reactors involves two steps. - * First, each destination (e.g. an input port) must have pointers to - * the source (the output port). As explained above, for an input named - * in, the field _lf_in->value is a pointer to the output data being read. - * In addition, _lf_in->is_present is a pointer to the corresponding - * out->is_present field of the output reactor's self struct. - * In addition, the reaction_i struct on the self struct has a triggers - * field that records all the trigger_t structs for ports and actions - * that are triggered by the i-th reaction. The triggers field is - * an array of arrays of pointers to trigger_t structs. - * The length of the outer array is the number of output channels - * (single ports plus multiport widths) that the reaction effects - * plus the number of input port channels of contained - * reactors that it effects. Each inner array has a length equal to the - * number of final destinations of that output channel or input channel. - * The reaction_i struct has an array triggered_sizes that indicates - * the sizes of these inner arrays. The num_outputs field of the - * reaction_i struct gives the length of the triggered_sizes and - * (outer) triggers arrays. The num_outputs field is equal to the - * total number of single ports and multiport channels that the reaction - * writes to.

      Runtime Tables

      - * This generator creates an populates the following tables used at run time. - * These tables may have to be resized and adjusted when mutations occur.
    • - *
    • _lf_is_present_fields: An array of pointers to booleans indicating whether an - * event is present. The _lf_start_time_step() function in reactor_common.c uses - * this to mark every event absent at the start of a time step. The size of this - * table is contained in the variable _lf_is_present_fields_size.
        - *
      • This table is accompanied by another list, _lf_is_present_fields_abbreviated, - * which only contains the is_present fields that have been set to true in the - * current tag. This list can allow a performance improvement if most ports are - * seldom present because only fields that have been set to true need to be - * reset to false.
      • - *
      - *
    • - *
    • _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown - * reactions. The length of this table is in the _lf_shutdown_triggers_size - * variable.
    • - *
    • _lf_timer_triggers: An array of pointers to trigger_t structs for timers that - * need to be started when the program runs. The length of this table is in the - * _lf_timer_triggers_size variable.
    • - *
    • _lf_action_table: For a federated execution, each federate will have this table - * that maps port IDs to the corresponding action struct, which can be cast to - * action_base_t.
    • + *
    • A typedef for inputs, outputs, and actions of each reactor class. These define the types of + * the variables that reactions use to access inputs and action values and to set output + * values. + *
    • A typedef for a "self" struct for each reactor class. One instance of this struct + * will be created for each reactor instance. See below for details. + *
    • A function definition for each reaction in each reactor class. These functions take an + * instance of the self struct as an argument. + *
    • A constructor function for each reactor class. This is used to create a new instance of the + * reactor. After these, the main generated function is _lf_initialize_trigger_objects() + * . This function creates the instances of reactors (using their constructors) and + * makes connections between them. A few other smaller functions are also generated. + *

      Self Struct

      + * The "self" struct has fields for each of the following: + *
    • parameter: the field name and type match the parameter. + *
    • state: the field name and type match the state. + *
    • action: the field name prepends the action name with "lf". A second + * field for the action is also created to house the trigger_t object. That second field + * prepends the action name with "_lf__". + *
    • output: the field name prepends the output name with "lf". + *
    • input: the field name prepends the output name with "lf". A second field + * for the input is also created to house the trigger_t object. That second field prepends the + * input name with "_lf__". If, in addition, the reactor contains other reactors and + * reacts to their outputs, then there will be a struct within the self struct for each such + * contained reactor. The name of that self struct will be the name of the contained reactor + * prepended with "lf". That inside struct will contain pointers the + * outputs of the contained reactors that are read together with pointers to booleans + * indicating whether those outputs are present. If, in addition, the reactor has a reaction + * to shutdown, then there will be a pointer to trigger_t object (see reactor.h) for the + * shutdown event and an action struct named _lf_shutdown on the self struct. + *

      Reaction Functions

      + * For each reaction in a reactor class, this generator will produce a C function that expects + * a pointer to an instance of the "self" struct as an argument. This function will + * contain verbatim the C code specified in the reaction, but before that C code, the + * generator inserts a few lines of code that extract from the self struct the variables that + * that code has declared it will use. For example, if the reaction declares that it is + * triggered by or uses an input named "x" of type int, the function will contain a + * line like this: + *
        r_x_t* x = self->_lf_x;
      + * 
      + * where r is the full name of the reactor class and the struct type r_x_t + * has fields is_present and value, where the type of + * value matches the port type. If the programmer fails to declare that it uses x, then + * the absence of the above code will trigger a compile error when the verbatim code attempts + * to read x. + *

      Constructor

      + * For each reactor class, this generator will create a constructor function named new_r + * , where r is the reactor class name. This function will malloc and + * return a pointer to an instance of the "self" struct. This struct initially + * represents an unconnected reactor. To establish connections between reactors, additional + * information needs to be inserted (see below). The self struct is made visible to the body + * of a reaction as a variable named "self". The self struct contains the following: + *
    • Parameters: For each parameter p of the reactor, there will be a field p + * with the type and value of the parameter. So C code in the body of a reaction can + * access parameter values as self->p. + *
    • State variables: For each state variable s of the reactor, there will be a + * field s with the type and value of the state variable. So C code in the body + * of a reaction can access state variables as self->s. The self struct also + * contains various fields that the user is not intended to use. The names of these fields + * begin with at least two underscores. They are: + *
    • Outputs: For each output named out, there will be a field _lf_out + * that is a struct containing a value field whose type matches that of the output. The output + * value is stored here. That struct also has a field is_present that is a + * boolean indicating whether the output has been set. This field is reset to false at the + * start of every time step. There is also a field num_destinations whose value + * matches the number of downstream reactors that use this variable. This field must be set + * when connections are made or changed. It is used to determine for a mutable input + * destination whether a copy needs to be made. + *
    • Inputs: For each input named in of type T, there is a field named _lf_in + * that is a pointer struct with a value field of type T. The struct pointed to also + * has an is_present field of type bool that indicates whether the input is + * present. + *
    • Outputs of contained reactors: If a reactor reacts to outputs of a contained reactor + * r, then the self struct will contain a nested struct named _lf_r that + * has fields pointing to those outputs. For example, if r has an output + * out of type T, then there will be field in _lf_r named out + * that points to a struct containing a value field of type T and a field named + * is_present of type bool. + *
    • Inputs of contained reactors: If a reactor sends to inputs of a contained reactor r + * , then the self struct will contain a nested struct named _lf_r that + * has fields for storing the values provided to those inputs. For example, if R has an input + * in of type T, then there will be field in _lf_R named in that is + * a struct with a value field of type T and a field named is_present of type + * bool. + *
    • Actions: If the reactor has an action a (logical or physical), then there will be a field + * in the self struct named _lf_a and another named _lf__a. The type + * of the first is specific to the action and contains a value field with the + * type and value of the action (if it has a value). That struct also has a has_value + * field, an is_present field, and a token field (which is + * NULL if the action carries no value). The _lf__a field is of type trigger_t. + * That struct contains various things, including an array of reactions sensitive to this + * trigger and a lf_token_t struct containing the value of the action, if it has a value. See + * reactor.h in the C library for details. + *
    • Reactions: Each reaction will have several fields in the self struct. Each of these has a + * name that begins with _lf__reaction_i, where i is the number of the reaction, + * starting with 0. The fields are: + *
        + *
      • _lf__reaction_i: The struct that is put onto the reaction queue to execute the + * reaction (see reactor.h in the C library). + *
      • Timers: For each timer t, there is are two fields in the self struct: + *
          + *
        • _lf__t: The trigger_t struct for this timer (see reactor.h). + *
        • _lf__t_reactions: An array of reactions (pointers to the reaction_t structs on + * this self struct) sensitive to this timer. + *
        + *
      + *
    • Triggers: For each Timer, Action, Input, and Output of a contained reactor that triggers + * reactions, there will be a trigger_t struct on the self struct with name _lf__t + * , where t is the name of the trigger. + *

      Connections Between Reactors

      + * Establishing connections between reactors involves two steps. First, each destination (e.g. + * an input port) must have pointers to the source (the output port). As explained above, for + * an input named in, the field _lf_in->value is a pointer to the + * output data being read. In addition, _lf_in->is_present is a pointer to the + * corresponding out->is_present field of the output reactor's self + * struct. In addition, the reaction_i struct on the self struct has a + * triggers field that records all the trigger_t structs for ports and actions that are + * triggered by the i-th reaction. The triggers field is an array of arrays of pointers to + * trigger_t structs. The length of the outer array is the number of output channels (single + * ports plus multiport widths) that the reaction effects plus the number of input port + * channels of contained reactors that it effects. Each inner array has a length equal to the + * number of final destinations of that output channel or input channel. The reaction_i struct + * has an array triggered_sizes that indicates the sizes of these inner arrays. The + * num_outputs field of the reaction_i struct gives the length of the triggered_sizes and + * (outer) triggers arrays. The num_outputs field is equal to the total number of single ports + * and multiport channels that the reaction writes to. + *

      Runtime Tables

      + * This generator creates an populates the following tables used at run time. These tables may + * have to be resized and adjusted when mutations occur. + *
    • _lf_is_present_fields: An array of pointers to booleans indicating whether an event is + * present. The _lf_start_time_step() function in reactor_common.c uses this to mark every + * event absent at the start of a time step. The size of this table is contained in the + * variable _lf_is_present_fields_size. + *
        + *
      • This table is accompanied by another list, _lf_is_present_fields_abbreviated, which + * only contains the is_present fields that have been set to true in the current tag. + * This list can allow a performance improvement if most ports are seldom present + * because only fields that have been set to true need to be reset to false. + *
      + *
    • _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown reactions. + * The length of this table is in the _lf_shutdown_triggers_size variable. + *
    • _lf_timer_triggers: An array of pointers to trigger_t structs for timers that need to be + * started when the program runs. The length of this table is in the _lf_timer_triggers_size + * variable. + *
    • _lf_action_table: For a federated execution, each federate will have this table that maps + * port IDs to the corresponding action struct, which can be cast to action_base_t. *
    * * @author Edward A. Lee @@ -273,1153 +258,1164 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY @SuppressWarnings("StaticPseudoFunctionalStyleMethod") public class CGenerator extends GeneratorBase { - // Regular expression pattern for compiler error messages with resource - // and line number information. The first match will a resource URI in the - // form of "file:/path/file.lf". The second match will be a line number. - // The third match is a character position within the line. - // The fourth match will be the error message. - static final Pattern compileErrorPattern = Pattern.compile( - "^(?.*):(?\\d+):(?\\d+):(?.*)$" - ); - - public static int UNDEFINED_MIN_SPACING = -1; - - //////////////////////////////////////////// - //// Protected fields - - /** The main place to put generated code. */ - protected CodeBuilder code = new CodeBuilder(); - - /** Place to collect code to initialize the trigger objects for all reactor instances. */ - protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); - - protected final CFileConfig fileConfig; - - /** - * Count of the number of is_present fields of the self struct that - * need to be reinitialized in _lf_start_time_step(). - */ - protected int startTimeStepIsPresentCount = 0; - - //////////////////////////////////////////// - //// Private fields - /** - * Extra lines that need to go into the generated CMakeLists.txt. - */ - private final String cMakeExtras = ""; - - /** Place to collect code to execute at the start of a time step. */ - private final CodeBuilder startTimeStep = new CodeBuilder(); - - /** Count of the number of token pointers that need to have their - * reference count decremented in _lf_start_time_step(). - */ - private int timerCount = 0; - private int startupReactionCount = 0; - private int shutdownReactionCount = 0; - private int resetReactionCount = 0; - private int modalReactorCount = 0; - private int modalStateResetCount = 0; - private int watchdogCount = 0; - - // Indicate whether the generator is in Cpp mode or not - private final boolean CCppMode; - - private final CTypes types; - - private final CCmakeGenerator cmakeGenerator; - - protected CGenerator( - LFGeneratorContext context, - boolean CCppMode, - CTypes types, - CCmakeGenerator cmakeGenerator, - DelayBodyGenerator delayBodyGenerator - ) { - super(context); - this.fileConfig = (CFileConfig) context.getFileConfig(); - this.CCppMode = CCppMode; - this.types = types; - this.cmakeGenerator = cmakeGenerator; - - // Register the delayed connection transformation to be applied by GeneratorBase. - // transform both after delays and physical connections - registerTransformation(new DelayedConnectionTransformation(delayBodyGenerator, types, fileConfig.resource, true, true)); + // Regular expression pattern for compiler error messages with resource + // and line number information. The first match will a resource URI in the + // form of "file:/path/file.lf". The second match will be a line number. + // The third match is a character position within the line. + // The fourth match will be the error message. + static final Pattern compileErrorPattern = + Pattern.compile("^(?.*):(?\\d+):(?\\d+):(?.*)$"); + + public static int UNDEFINED_MIN_SPACING = -1; + + //////////////////////////////////////////// + //// Protected fields + + /** The main place to put generated code. */ + protected CodeBuilder code = new CodeBuilder(); + + /** Place to collect code to initialize the trigger objects for all reactor instances. */ + protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); + + protected final CFileConfig fileConfig; + + /** + * Count of the number of is_present fields of the self struct that need to be reinitialized in + * _lf_start_time_step(). + */ + protected int startTimeStepIsPresentCount = 0; + + //////////////////////////////////////////// + //// Private fields + /** Extra lines that need to go into the generated CMakeLists.txt. */ + private final String cMakeExtras = ""; + + /** Place to collect code to execute at the start of a time step. */ + private final CodeBuilder startTimeStep = new CodeBuilder(); + + /** + * Count of the number of token pointers that need to have their reference count decremented in + * _lf_start_time_step(). + */ + private int timerCount = 0; + + private int startupReactionCount = 0; + private int shutdownReactionCount = 0; + private int resetReactionCount = 0; + private int modalReactorCount = 0; + private int modalStateResetCount = 0; + private int watchdogCount = 0; + + // Indicate whether the generator is in Cpp mode or not + private final boolean CCppMode; + + private final CTypes types; + + private final CCmakeGenerator cmakeGenerator; + + protected CGenerator( + LFGeneratorContext context, + boolean CCppMode, + CTypes types, + CCmakeGenerator cmakeGenerator, + DelayBodyGenerator delayBodyGenerator) { + super(context); + this.fileConfig = (CFileConfig) context.getFileConfig(); + this.CCppMode = CCppMode; + this.types = types; + this.cmakeGenerator = cmakeGenerator; + + // Register the delayed connection transformation to be applied by GeneratorBase. + // transform both after delays and physical connections + registerTransformation( + new DelayedConnectionTransformation( + delayBodyGenerator, types, fileConfig.resource, true, true)); + } + + public CGenerator(LFGeneratorContext context, boolean ccppMode) { + this( + context, + ccppMode, + new CTypes(), + new CCmakeGenerator(context.getFileConfig(), List.of()), + new CDelayBodyGenerator(new CTypes())); + } + + /** + * Look for physical actions in all resources. If found, set threads to be at least one to allow + * asynchronous schedule calls. + */ + public void accommodatePhysicalActionsIfPresent() { + // If there are any physical actions, ensure the threaded engine is used and that + // keepalive is set to true, unless the user has explicitly set it to false. + for (Resource resource : GeneratorUtils.getResources(reactors)) { + for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { + if (ActionOrigin.PHYSICAL.equals(action.getOrigin())) { + // If the unthreaded runtime is not requested by the user, use the threaded runtime + // instead + // because it is the only one currently capable of handling asynchronous events. + if (!targetConfig.threading + && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = true; + errorReporter.reportWarning( + action, + "Using the threaded C runtime to allow for asynchronous handling of physical action" + + " " + + action.getName()); + return; + } + } + } } - - public CGenerator(LFGeneratorContext context, boolean ccppMode) { - this( - context, - ccppMode, - new CTypes(), - new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes()) - ); + } + + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + protected boolean isOSCompatible() { + if (GeneratorUtils.isHostWindows()) { + if (CCppMode) { + errorReporter.reportError( + "LF programs with a CCpp target are currently not supported on Windows. " + + "Exiting code generation."); + return false; + } } + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context The context in which the generator is invoked, including whether it is cancelled + * and whether it is a standalone context + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + super.doGenerate(resource, context); + if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; + if (!isOSCompatible()) return; // Incompatible OS and configuration - /** - * Look for physical actions in all resources. - * If found, set threads to be at least one to allow asynchronous schedule calls. - */ - public void accommodatePhysicalActionsIfPresent() { - // If there are any physical actions, ensure the threaded engine is used and that - // keepalive is set to true, unless the user has explicitly set it to false. - for (Resource resource : GeneratorUtils.getResources(reactors)) { - for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { - if (ActionOrigin.PHYSICAL.equals(action.getOrigin())) { - // If the unthreaded runtime is not requested by the user, use the threaded runtime instead - // because it is the only one currently capable of handling asynchronous events. - if (!targetConfig.threading && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = true; - errorReporter.reportWarning( - action, - "Using the threaded C runtime to allow for asynchronous handling of physical action " + - action.getName() - ); - return; - } - } - } - } + // Perform set up that does not generate code + setUpGeneralParameters(); + + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); + handleProtoFiles(); + + // Derive target filename from the .lf filename. + var lfModuleName = fileConfig.name; + var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); + var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; + try { + generateCodeFor(lfModuleName); + copyTargetFiles(); + generateHeaders(); + code.writeToFile(targetFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); } - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - protected boolean isOSCompatible() { - if (GeneratorUtils.isHostWindows()) { - if (CCppMode) { - errorReporter.reportError( - "LF programs with a CCpp target are currently not supported on Windows. " + - "Exiting code generation." - ); - return false; - } - } - return true; + // Create docker file. + if (targetConfig.dockerOptions != null && mainDef != null) { + try { + var dockerData = getDockerGenerator(context).generateDockerData(); + dockerData.writeDockerFile(); + (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + } catch (IOException e) { + throw new RuntimeException("Error while writing Docker files", e); + } } - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * @param resource The resource containing the source code. - * @param context The context in which the generator is - * invoked, including whether it is cancelled and - * whether it is a standalone context - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - super.doGenerate(resource, context); - if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; - if (!isOSCompatible()) return; // Incompatible OS and configuration - - // Perform set up that does not generate code - setUpGeneralParameters(); - - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); - handleProtoFiles(); - - // Derive target filename from the .lf filename. - var lfModuleName = fileConfig.name; - var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); - var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; - try { - generateCodeFor(lfModuleName); - copyTargetFiles(); - generateHeaders(); - code.writeToFile(targetFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - - // Create docker file. - if (targetConfig.dockerOptions != null && mainDef != null) { - try { - var dockerData = getDockerGenerator(context).generateDockerData(); - dockerData.writeDockerFile(); - (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); - } catch (IOException e) { - throw new RuntimeException("Error while writing Docker files", e); - } - } - - // If cmake is requested, generate the CMakeLists.txt - if (targetConfig.platformOptions.platform != Platform.ARDUINO) { - var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; - var sources = allTypeParameterizedReactors() - .map(CUtil::getName) - .map(it -> it + (CCppMode ? ".cpp" : ".c")) - .collect(Collectors.toCollection(ArrayList::new)); - sources.add(cFilename); - var cmakeCode = cmakeGenerator.generateCMakeCode( - sources, - lfModuleName, - errorReporter, - CCppMode, - mainDef != null, - cMakeExtras, - targetConfig - ); - try { - cmakeCode.writeToFile(cmakeFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - } else { - try { - Path include = fileConfig.getSrcGenPath().resolve("include/"); - Path src = fileConfig.getSrcGenPath().resolve("src/"); - FileUtil.arduinoDeleteHelper(src, targetConfig.threading); - FileUtil.relativeIncludeHelper(src, include); - FileUtil.relativeIncludeHelper(include, include); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - if (!targetConfig.noCompile) { - ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); - arduinoUtil.buildArduino(fileConfig, targetConfig); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } else { - System.out.println("********"); - System.out.println("To compile your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli compile -b --build-property compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\nTo flash/upload your generated sketch to the board, run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); - // System.out.println("For a list of all boards installed on your computer, you can use the following command:\n\n\tarduino-cli board listall\n"); - context.finish( - GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null) - ); - } - GeneratorUtils.refreshProject(resource, context.getMode()); - return; - } - - // Dump the additional compile definitions to a file to keep the generated project - // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can - // take over and do the rest of compilation. - try { - String compileDefs = targetConfig.compileDefinitions.keySet().stream() - .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) - .collect(Collectors.joining("\n")) + "\n"; - FileUtil.writeToFile( - compileDefs, - Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") - ); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + // If cmake is requested, generate the CMakeLists.txt + if (targetConfig.platformOptions.platform != Platform.ARDUINO) { + var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; + var sources = + allTypeParameterizedReactors() + .map(CUtil::getName) + .map(it -> it + (CCppMode ? ".cpp" : ".c")) + .collect(Collectors.toCollection(ArrayList::new)); + sources.add(cFilename); + var cmakeCode = + cmakeGenerator.generateCMakeCode( + sources, + lfModuleName, + errorReporter, + CCppMode, + mainDef != null, + cMakeExtras, + targetConfig); + try { + cmakeCode.writeToFile(cmakeFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + } else { + try { + Path include = fileConfig.getSrcGenPath().resolve("include/"); + Path src = fileConfig.getSrcGenPath().resolve("src/"); + FileUtil.arduinoDeleteHelper(src, targetConfig.threading); + FileUtil.relativeIncludeHelper(src, include); + FileUtil.relativeIncludeHelper(include, include); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + if (!targetConfig.noCompile) { + ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); + arduinoUtil.buildArduino(fileConfig, targetConfig); + context.finish(GeneratorResult.Status.COMPILED, null); + } else { + System.out.println("********"); + System.out.println( + "To compile your program, run the following command to see information about the board" + + " you plugged in:\n\n" + + "\tarduino-cli board list\n\n" + + "Grab the FQBN and PORT from the command and run the following command in the" + + " generated sources directory:\n\n" + + "\tarduino-cli compile -b --build-property" + + " compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property" + + " compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\n" + + "To flash/upload your generated sketch to the board, run the following command in" + + " the generated sources directory:\n\n" + + "\tarduino-cli upload -b -p \n"); + // System.out.println("For a list of all boards installed on your computer, you can use the + // following command:\n\n\tarduino-cli board listall\n"); + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + } + GeneratorUtils.refreshProject(resource, context.getMode()); + return; + } - // Create a .vscode/settings.json file in the target directory so that VSCode can - // immediately compile the generated code. - try { - String compileDefs = targetConfig.compileDefinitions.keySet().stream() - .map(key -> "\"-D" + key + "=" + targetConfig.compileDefinitions.get(key) + "\"") - .collect(Collectors.joining(",\n")); - String settings = "{\n" - + "\"cmake.configureArgs\": [\n" - + compileDefs - + "\n]\n}\n"; - Path vscodePath = Path.of(fileConfig.getSrcGenPath() + File.separator + ".vscode"); - if (!Files.exists(vscodePath)) - Files.createDirectory(vscodePath); - FileUtil.writeToFile( - settings, - Path.of(fileConfig.getSrcGenPath() - + File.separator + ".vscode" - + File.separator + "settings.json") - ); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + // Dump the additional compile definitions to a file to keep the generated project + // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can + // take over and do the rest of compilation. + try { + String compileDefs = + targetConfig.compileDefinitions.keySet().stream() + .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) + .collect(Collectors.joining("\n")) + + "\n"; + FileUtil.writeToFile( + compileDefs, + Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt")); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } - // If this code generator is directly compiling the code, compile it now so that we - // clean it up after, removing the #line directives after errors have been reported. - if ( - !targetConfig.noCompile && targetConfig.dockerOptions == null - && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) - // This code is unreachable in LSP_FAST mode, so that check is omitted. - && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM - ) { - // FIXME: Currently, a lack of main is treated as a request to not produce - // a binary and produce a .o file instead. There should be a way to control - // this. - // Create an anonymous Runnable class and add it to the compileThreadPool - // so that compilation can happen in parallel. - var cleanCode = code.removeLines("#line"); - - var execName = lfModuleName; - var threadFileConfig = fileConfig; - var generator = this; // FIXME: currently only passed to report errors with line numbers in the Eclipse IDE - var CppMode = CCppMode; - // generatingContext.reportProgress( - // String.format("Generated code for %d/%d executables. Compiling...", federateCount, federates.size()), - // 100 * federateCount / federates.size() - // ); // FIXME: Move to FedGenerator - // Create the compiler to be used later - - var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); - try { - if (!cCompiler.runCCompiler(generator, context)) { - // If compilation failed, remove any bin files that may have been created. - CUtil.deleteBinFiles(threadFileConfig); - // If finish has already been called, it is illegal and makes no sense. However, - // if finish has already been called, then this must be a federated execution. - context.unsuccessfulFinish(); - } else { - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - cleanCode.writeToFile(targetFile); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } - } + // Create a .vscode/settings.json file in the target directory so that VSCode can + // immediately compile the generated code. + try { + String compileDefs = + targetConfig.compileDefinitions.keySet().stream() + .map(key -> "\"-D" + key + "=" + targetConfig.compileDefinitions.get(key) + "\"") + .collect(Collectors.joining(",\n")); + String settings = "{\n" + "\"cmake.configureArgs\": [\n" + compileDefs + "\n]\n}\n"; + Path vscodePath = Path.of(fileConfig.getSrcGenPath() + File.separator + ".vscode"); + if (!Files.exists(vscodePath)) Files.createDirectory(vscodePath); + FileUtil.writeToFile( + settings, + Path.of( + fileConfig.getSrcGenPath() + + File.separator + + ".vscode" + + File.separator + + "settings.json")); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } - // If a build directive has been given, invoke it now. - // Note that the code does not get cleaned in this case. - if (!targetConfig.noCompile) { - if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { - CUtil.runBuildCommand( - fileConfig, - targetConfig, - commandFactory, - errorReporter, - this::reportCommandErrors, - context.getMode() - ); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - if (!errorsOccurred()){ - System.out.println("Compiled binary is in " + fileConfig.binPath); - } + // If this code generator is directly compiling the code, compile it now so that we + // clean it up after, removing the #line directives after errors have been reported. + if (!targetConfig.noCompile + && targetConfig.dockerOptions == null + && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) + // This code is unreachable in LSP_FAST mode, so that check is omitted. + && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM) { + // FIXME: Currently, a lack of main is treated as a request to not produce + // a binary and produce a .o file instead. There should be a way to control + // this. + // Create an anonymous Runnable class and add it to the compileThreadPool + // so that compilation can happen in parallel. + var cleanCode = code.removeLines("#line"); + + var execName = lfModuleName; + var threadFileConfig = fileConfig; + var generator = + this; // FIXME: currently only passed to report errors with line numbers in the Eclipse + // IDE + var CppMode = CCppMode; + // generatingContext.reportProgress( + // String.format("Generated code for %d/%d executables. Compiling...", federateCount, + // federates.size()), + // 100 * federateCount / federates.size() + // ); // FIXME: Move to FedGenerator + // Create the compiler to be used later + + var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); + try { + if (!cCompiler.runCCompiler(generator, context)) { + // If compilation failed, remove any bin files that may have been created. + CUtil.deleteBinFiles(threadFileConfig); + // If finish has already been called, it is illegal and makes no sense. However, + // if finish has already been called, then this must be a federated execution. + context.unsuccessfulFinish(); } else { - context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + context.finish(GeneratorResult.Status.COMPILED, null); } + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + } - // In case we are in Eclipse, make sure the generated code is visible. - GeneratorUtils.refreshProject(resource, context.getMode()); + // If a build directive has been given, invoke it now. + // Note that the code does not get cleaned in this case. + if (!targetConfig.noCompile) { + if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { + CUtil.runBuildCommand( + fileConfig, + targetConfig, + commandFactory, + errorReporter, + this::reportCommandErrors, + context.getMode()); + context.finish(GeneratorResult.Status.COMPILED, null); + } + if (!errorsOccurred()) { + System.out.println("Compiled binary is in " + fileConfig.binPath); + } + } else { + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); } - private void generateCodeFor( - String lfModuleName - ) throws IOException { - startTimeStepIsPresentCount = 0; - code.pr(generateDirectives()); - code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); - // Generate code for each reactor. - generateReactorDefinitions(); - - // Generate main instance, if there is one. - // Note that any main reactors in imported files are ignored. - // Skip generation if there are cycles. - if (main != null) { - initializeTriggerObjects.pr(String.join("\n", - "int _lf_startup_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", - "int _lf_shutdown_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", - "int _lf_reset_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", - "int _lf_timer_triggers_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", - "int bank_index;", - "SUPPRESS_UNUSED_WARNING(bank_index);", - "int watchdog_number = 0;", - "SUPPRESS_UNUSED_WARNING(watchdog_number);")); - // Add counters for modal initialization - initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); - - // Create an array of arrays to store all self structs. - // This is needed because connections cannot be established until - // all reactor instances have self structs because ports that - // receive data reference the self structs of the originating - // reactors, which are arbitarily far away in the program graph. - generateSelfStructs(main); - generateReactorInstance(main); - - if (targetConfig.fedSetupPreamble != null) { - if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); - code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); - if (targetLanguageIsCpp()) code.pr("}"); - } + // In case we are in Eclipse, make sure the generated code is visible. + GeneratorUtils.refreshProject(resource, context.getMode()); + } + + private void generateCodeFor(String lfModuleName) throws IOException { + startTimeStepIsPresentCount = 0; + code.pr(generateDirectives()); + code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); + // Generate code for each reactor. + generateReactorDefinitions(); + + // Generate main instance, if there is one. + // Note that any main reactors in imported files are ignored. + // Skip generation if there are cycles. + if (main != null) { + initializeTriggerObjects.pr( + String.join( + "\n", + "int _lf_startup_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", + "int _lf_shutdown_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", + "int _lf_reset_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", + "int _lf_timer_triggers_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", + "int bank_index;", + "SUPPRESS_UNUSED_WARNING(bank_index);", + "int watchdog_number = 0;", + "SUPPRESS_UNUSED_WARNING(watchdog_number);")); + // Add counters for modal initialization + initializeTriggerObjects.pr( + CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); + + // Create an array of arrays to store all self structs. + // This is needed because connections cannot be established until + // all reactor instances have self structs because ports that + // receive data reference the self structs of the originating + // reactors, which are arbitarily far away in the program graph. + generateSelfStructs(main); + generateReactorInstance(main); + + if (targetConfig.fedSetupPreamble != null) { + if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); + code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); + if (targetLanguageIsCpp()) code.pr("}"); + } - // If there are timers, create a table of timers to be initialized. - code.pr(CTimerGenerator.generateDeclarations(timerCount)); - - // If there are startup reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); - - // If there are shutdown reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); - - // If there are reset reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); - - // If there are watchdogs, create a table of triggers. - code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); - - // If there are modes, create a table of mode state to be checked for transitions. - code.pr(CModesGenerator.generateModeStatesTable( - hasModalReactors, - modalReactorCount, - modalStateResetCount - )); - - // Generate function to initialize the trigger objects for all reactors. - code.pr(CTriggerObjectsGenerator.generateInitializeTriggerObjects( - main, - targetConfig, - initializeTriggerObjects, - startTimeStep, - types, - lfModuleName, - startTimeStepIsPresentCount - )); - - // Generate function to trigger startup reactions for all reactors. - code.pr(CReactionGenerator.generateLfTriggerStartupReactions(startupReactionCount, hasModalReactors)); - - // Generate function to schedule timers for all reactors. - code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - - // Generate a function that will either do nothing - // (if there is only one federate or the coordination - // is set to decentralized) or, if there are - // downstream federates, will notify the RTI - // that the specified logical time is complete. - if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) code.pr("extern \"C\""); - code.pr(String.join("\n", - "void logical_tag_complete(tag_t tag_to_send) {", - CExtensionUtils.surroundWithIfFederatedCentralized( - " _lf_logical_tag_complete(tag_to_send);" - ), - "}" - )); - - // Generate function to schedule shutdown reactions if any - // reactors have reactions to shutdown. - code.pr(CReactionGenerator.generateLfTriggerShutdownReactions(shutdownReactionCount, hasModalReactors)); - - // Generate an empty termination function for non-federated - // execution. For federated execution, an implementation is - // provided in federate.c. That implementation will resign - // from the federation and close any open sockets. - code.pr(""" + // If there are timers, create a table of timers to be initialized. + code.pr(CTimerGenerator.generateDeclarations(timerCount)); + + // If there are startup reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); + + // If there are shutdown reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); + + // If there are reset reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); + + // If there are watchdogs, create a table of triggers. + code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); + + // If there are modes, create a table of mode state to be checked for transitions. + code.pr( + CModesGenerator.generateModeStatesTable( + hasModalReactors, modalReactorCount, modalStateResetCount)); + + // Generate function to initialize the trigger objects for all reactors. + code.pr( + CTriggerObjectsGenerator.generateInitializeTriggerObjects( + main, + targetConfig, + initializeTriggerObjects, + startTimeStep, + types, + lfModuleName, + startTimeStepIsPresentCount)); + + // Generate function to trigger startup reactions for all reactors. + code.pr( + CReactionGenerator.generateLfTriggerStartupReactions( + startupReactionCount, hasModalReactors)); + + // Generate function to schedule timers for all reactors. + code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); + + // Generate a function that will either do nothing + // (if there is only one federate or the coordination + // is set to decentralized) or, if there are + // downstream federates, will notify the RTI + // that the specified logical time is complete. + if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) + code.pr("extern \"C\""); + code.pr( + String.join( + "\n", + "void logical_tag_complete(tag_t tag_to_send) {", + CExtensionUtils.surroundWithIfFederatedCentralized( + " _lf_logical_tag_complete(tag_to_send);"), + "}")); + + // Generate function to schedule shutdown reactions if any + // reactors have reactions to shutdown. + code.pr( + CReactionGenerator.generateLfTriggerShutdownReactions( + shutdownReactionCount, hasModalReactors)); + + // Generate an empty termination function for non-federated + // execution. For federated execution, an implementation is + // provided in federate.c. That implementation will resign + // from the federation and close any open sockets. + code.pr( + """ #ifndef FEDERATED void terminate_execution() {} - #endif""" - ); - - - // Generate functions for modes - code.pr(CModesGenerator.generateLfInitializeModes( - hasModalReactors - )); - code.pr(CModesGenerator.generateLfHandleModeChanges( - hasModalReactors, - modalStateResetCount - )); - code.pr(CReactionGenerator.generateLfModeTriggeredReactions( - startupReactionCount, - resetReactionCount, - hasModalReactors - )); - } - } - - @Override - public void checkModalReactorSupport(boolean __) { - // Modal reactors are currently only supported for non federated applications - super.checkModalReactorSupport(true); + #endif"""); + + // Generate functions for modes + code.pr(CModesGenerator.generateLfInitializeModes(hasModalReactors)); + code.pr(CModesGenerator.generateLfHandleModeChanges(hasModalReactors, modalStateResetCount)); + code.pr( + CReactionGenerator.generateLfModeTriggeredReactions( + startupReactionCount, resetReactionCount, hasModalReactors)); } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - return String.join("\n", - "// Generated forwarding reaction for connections with the same destination", - "// but located in mutually exclusive modes.", - "lf_set("+dest+", "+source+"->value);" - ); - } - - /** Set the scheduler type in the target config as needed. */ - private void pickScheduler() { - // Don't use a scheduler that does not prioritize reactions based on deadlines - // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. - if (!targetConfig.schedulerType.prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - if (hasDeadlines(reactors)) { - if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { - targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; - } - } + } + + @Override + public void checkModalReactorSupport(boolean __) { + // Modal reactors are currently only supported for non federated applications + super.checkModalReactorSupport(true); + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + return String.join( + "\n", + "// Generated forwarding reaction for connections with the same destination", + "// but located in mutually exclusive modes.", + "lf_set(" + dest + ", " + source + "->value);"); + } + + /** Set the scheduler type in the target config as needed. */ + private void pickScheduler() { + // Don't use a scheduler that does not prioritize reactions based on deadlines + // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. + if (!targetConfig.schedulerType.prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (hasDeadlines(reactors)) { + if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { + targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; } + } } + } - private boolean hasDeadlines(List reactors) { - for (Reactor reactor : reactors) { - for (Reaction reaction : allReactions(reactor)) { - if (reaction.getDeadline() != null) { - return true; - } - } + private boolean hasDeadlines(List reactors) { + for (Reactor reactor : reactors) { + for (Reaction reaction : allReactions(reactor)) { + if (reaction.getDeadline() != null) { + return true; } - return false; + } } - - /** - * Look at the 'reactor' eResource. - * If it is an imported .lf file, incorporate it into the current - * program in the following manner: - *
      - *
    • Merge its target property with {@code targetConfig}
    • - *
    • If there are any preambles, add them to the preambles of the reactor.
    • - *
    - * - */ - private void inspectReactorEResource(ReactorDecl reactor) { - // If the reactor is imported, look at the - // target definition of the .lf file in which the reactor is imported from and - // append any cmake-include. - // Check if the reactor definition is imported - if (reactor.eResource() != mainDef.getReactorClass().eResource()) { - // Find the LFResource corresponding to this eResource - LFResource lfResource = null; - for (var resource : resources) { - if (resource.getEResource() == reactor.eResource()) { - lfResource = resource; - break; - } - } - if (lfResource != null) { - // Copy the user files and cmake-includes to the src-gen path of the main .lf file - copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); - // Merge the CMake includes from the imported file into the target config - lfResource.getTargetConfig().cmakeIncludes.forEach(incl -> { - if (!this.targetConfig.cmakeIncludes.contains(incl)) { - this.targetConfig.cmakeIncludes.add(incl); - } - }); - } + return false; + } + + /** + * Look at the 'reactor' eResource. If it is an imported .lf file, incorporate it into the current + * program in the following manner: + * + *
      + *
    • Merge its target property with {@code targetConfig} + *
    • If there are any preambles, add them to the preambles of the reactor. + *
    + */ + private void inspectReactorEResource(ReactorDecl reactor) { + // If the reactor is imported, look at the + // target definition of the .lf file in which the reactor is imported from and + // append any cmake-include. + // Check if the reactor definition is imported + if (reactor.eResource() != mainDef.getReactorClass().eResource()) { + // Find the LFResource corresponding to this eResource + LFResource lfResource = null; + for (var resource : resources) { + if (resource.getEResource() == reactor.eResource()) { + lfResource = resource; + break; } + } + if (lfResource != null) { + // Copy the user files and cmake-includes to the src-gen path of the main .lf file + copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + // Merge the CMake includes from the imported file into the target config + lfResource + .getTargetConfig() + .cmakeIncludes + .forEach( + incl -> { + if (!this.targetConfig.cmakeIncludes.contains(incl)) { + this.targetConfig.cmakeIncludes.add(incl); + } + }); + } } - - /** - * Copy all files or directories listed in the target property {@code files}, {@code cmake-include}, - * and {@code _fed_setup} into the src-gen folder of the main .lf file - * - * @param targetConfig The targetConfig to read the target properties from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - @Override - protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - super.copyUserFiles(targetConfig, fileConfig); - // Must use class variable to determine destination! - var destination = this.fileConfig.getSrcGenPath(); - - FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true); - - // FIXME: Unclear what the following does, but it does not appear to belong here. - if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { - try { - FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), - destination.resolve(targetConfig.fedSetupPreamble)); - } catch (IOException e) { - errorReporter.reportError("Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); - } - } + } + + /** + * Copy all files or directories listed in the target property {@code files}, {@code + * cmake-include}, and {@code _fed_setup} into the src-gen folder of the main .lf file + * + * @param targetConfig The targetConfig to read the target properties from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + @Override + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + super.copyUserFiles(targetConfig, fileConfig); + // Must use class variable to determine destination! + var destination = this.fileConfig.getSrcGenPath(); + + FileUtil.copyFilesOrDirectories( + targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true); + + // FIXME: Unclear what the following does, but it does not appear to belong here. + if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { + try { + FileUtil.copyFile( + fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), + destination.resolve(targetConfig.fedSetupPreamble)); + } catch (IOException e) { + errorReporter.reportError( + "Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); + } } - - /** - * Generate code for defining all instantiated reactors. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - *
      - *
    • If there are any cmake-include files, add them to the current list - * of cmake-include files.
    • - *
    • If there are any preambles, add them to the preambles of the reactor.
    • - *
    - */ - private void generateReactorDefinitions() throws IOException { - var generatedReactors = new LinkedHashSet(); - if (this.main != null) { - resolveTemplatedTypes(this.main, this.main.tpr); - generateReactorChildren(this.main, generatedReactors); - generateReactorClass(this.main.getTypeParameterizedReactor()); - } - // do not generate code for reactors that are not instantiated + } + + /** + * Generate code for defining all instantiated reactors. + * + *

    Imported reactors' original .lf file is incorporated in the following manner: + * + *

      + *
    • If there are any cmake-include files, add them to the current list of cmake-include + * files. + *
    • If there are any preambles, add them to the preambles of the reactor. + *
    + */ + private void generateReactorDefinitions() throws IOException { + var generatedReactors = new LinkedHashSet(); + if (this.main != null) { + resolveTemplatedTypes(this.main, this.main.tpr); + generateReactorChildren(this.main, generatedReactors); + generateReactorClass(this.main.getTypeParameterizedReactor()); } - - /** - * Recursively Resolve all Templated Types of child Reactors to their respective - * concrete types - * - * @param reactorInstance The Reactor Class - * @param parentTpr {@link TypeParameterizedReactor} of Parent - */ - private void resolveTemplatedTypes(ReactorInstance reactorInstance, TypeParameterizedReactor parentTpr) { - for (var child : reactorInstance.children) { - if (parentTpr.typeArgs() != null) { - Map copy = new HashMap<>(); - child.tpr.typeArgs().forEach((literal, typename) -> { - var type = typename.getId(); - if (parentTpr.typeArgs().containsKey(type)) { - var basicType = parentTpr.typeArgs().get(type); - copy.put(literal, basicType); - } else { - // Typename is not inherited from Parent Reactor. Keep As Is! - copy.put(literal, typename); - } + // do not generate code for reactors that are not instantiated + } + + /** + * Recursively Resolve all Templated Types of child Reactors to their respective concrete types + * + * @param reactorInstance The Reactor Class + * @param parentTpr {@link TypeParameterizedReactor} of Parent + */ + private void resolveTemplatedTypes( + ReactorInstance reactorInstance, TypeParameterizedReactor parentTpr) { + for (var child : reactorInstance.children) { + if (parentTpr.typeArgs() != null) { + Map copy = new HashMap<>(); + child + .tpr + .typeArgs() + .forEach( + (literal, typename) -> { + var type = typename.getId(); + if (parentTpr.typeArgs().containsKey(type)) { + var basicType = parentTpr.typeArgs().get(type); + copy.put(literal, basicType); + } else { + // Typename is not inherited from Parent Reactor. Keep As Is! + copy.put(literal, typename); + } }); - if (!copy.isEmpty()) { // If we found some templated-types update the tpr with new map - child.tpr = new TypeParameterizedReactor(child.tpr.reactor(), copy); - } - resolveTemplatedTypes(child, child.tpr); - } - } - } - - private record TypeParameterizedReactorWithDecl(TypeParameterizedReactor tpr, ReactorDecl decl) {} - - /** Generate user-visible header files for all reactors instantiated. */ - private void generateHeaders() throws IOException { - FileUtil.deleteDirectory(fileConfig.getIncludePath()); - FileUtil.copyFromClassPath( - fileConfig.getRuntimeIncludePath(), - fileConfig.getIncludePath(), - false, - true - ); - for (TypeParameterizedReactor tpr : - (Iterable) () -> allTypeParameterizedReactors().iterator() - ) { - CReactorHeaderFileGenerator.doGenerate( - types, tpr, fileConfig, - (builder, rr, userFacing) -> { - generateAuxiliaryStructs(builder, rr, userFacing); - if (userFacing) { - rr.reactor().getInstantiations().stream() - .map(it -> new TypeParameterizedReactorWithDecl(new TypeParameterizedReactor(it), it.getReactorClass())).collect(Collectors.toSet()).forEach(it -> { - ASTUtils.allPorts(it.tpr.reactor()) - .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( - it.tpr, p, getTarget(), errorReporter, types, new CodeBuilder(), true, it.decl() - ))); - }); - } - }, - this::generateTopLevelPreambles); + if (!copy.isEmpty()) { // If we found some templated-types update the tpr with new map + child.tpr = new TypeParameterizedReactor(child.tpr.reactor(), copy); } - FileUtil.copyDirectoryContents(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + resolveTemplatedTypes(child, child.tpr); + } } - - /** - * Generate code for the children of 'reactor' that belong to 'federate'. - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - *
      - *
    • If there are any cmake-include files, add them to the current list - * of cmake-include files.
    • - *
    • If there are any preambles, add them to the preambles of the reactor.
    • - *
    - * - * @param reactor Used to extract children from - */ - private void generateReactorChildren( - ReactorInstance reactor, - LinkedHashSet generatedReactors - ) throws IOException { - for (ReactorInstance r : reactor.children) { - var newTpr = r.tpr; - if (r.reactorDeclaration != null && - !generatedReactors.contains(newTpr)) { - generatedReactors.add(newTpr); - generateReactorChildren(r, generatedReactors); - inspectReactorEResource(r.reactorDeclaration); - generateReactorClass(newTpr); + } + + private record TypeParameterizedReactorWithDecl(TypeParameterizedReactor tpr, ReactorDecl decl) {} + + /** Generate user-visible header files for all reactors instantiated. */ + private void generateHeaders() throws IOException { + FileUtil.deleteDirectory(fileConfig.getIncludePath()); + FileUtil.copyFromClassPath( + fileConfig.getRuntimeIncludePath(), fileConfig.getIncludePath(), false, true); + for (TypeParameterizedReactor tpr : + (Iterable) () -> allTypeParameterizedReactors().iterator()) { + CReactorHeaderFileGenerator.doGenerate( + types, + tpr, + fileConfig, + (builder, rr, userFacing) -> { + generateAuxiliaryStructs(builder, rr, userFacing); + if (userFacing) { + rr.reactor().getInstantiations().stream() + .map( + it -> + new TypeParameterizedReactorWithDecl( + new TypeParameterizedReactor(it), it.getReactorClass())) + .collect(Collectors.toSet()) + .forEach( + it -> { + ASTUtils.allPorts(it.tpr.reactor()) + .forEach( + p -> + builder.pr( + CPortGenerator.generateAuxiliaryStruct( + it.tpr, + p, + getTarget(), + errorReporter, + types, + new CodeBuilder(), + true, + it.decl()))); + }); } - } - } - - /** - * Choose which platform files to compile with according to the OS. - * If there is no main reactor, then compilation will produce a .o file requiring further linking. - * Also, if useCmake is set to true, we don't need to add platform files. The CMakeLists.txt file - * will detect and use the appropriate platform file based on the platform that cmake is invoked on. - */ - private void pickCompilePlatform() { - var osName = System.getProperty("os.name").toLowerCase(); - // if platform target was set, use given platform instead - if (targetConfig.platformOptions.platform != Platform.AUTO) { - osName = targetConfig.platformOptions.platform.toString(); - } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { - errorReporter.reportError("Platform " + osName + " is not supported"); - } + }, + this::generateTopLevelPreambles); } - - /** - * Copy target-specific header file to the src-gen directory. - */ - protected void copyTargetFiles() throws IOException { - // Copy the core lib - String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); - Path dest = fileConfig.getSrcGenPath(); - if (targetConfig.platformOptions.platform == Platform.ARDUINO) { - dest = dest.resolve("src"); + FileUtil.copyDirectoryContents( + fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + } + + /** + * Generate code for the children of 'reactor' that belong to 'federate'. Duplicates are avoided. + * + *

    Imported reactors' original .lf file is incorporated in the following manner: + * + *

      + *
    • If there are any cmake-include files, add them to the current list of cmake-include + * files. + *
    • If there are any preambles, add them to the preambles of the reactor. + *
    + * + * @param reactor Used to extract children from + */ + private void generateReactorChildren( + ReactorInstance reactor, LinkedHashSet generatedReactors) + throws IOException { + for (ReactorInstance r : reactor.children) { + var newTpr = r.tpr; + if (r.reactorDeclaration != null && !generatedReactors.contains(newTpr)) { + generatedReactors.add(newTpr); + generateReactorChildren(r, generatedReactors); + inspectReactorEResource(r.reactorDeclaration); + generateReactorClass(newTpr); } - if (coreLib != null) { - FileUtil.copyDirectoryContents(Path.of(coreLib), dest, true); - } else { - FileUtil.copyFromClassPath( - "/lib/c/reactor-c/core", - dest, - true, - false - ); - FileUtil.copyFromClassPath( - "/lib/c/reactor-c/lib", - dest, - true, - false - ); - } - - // For the Zephyr target, copy default config and board files. - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - FileUtil.copyFromClassPath( - "/lib/platform/zephyr/boards", - fileConfig.getSrcGenPath(), - false, - false - ); - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/prj_lf.conf", - fileConfig.getSrcGenPath(), - true - ); - - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/Kconfig", - fileConfig.getSrcGenPath(), - true - ); - } } - - //////////////////////////////////////////// - //// Code generators. - - /** - * Generate a reactor class definition for the specified federate. - * A class definition has four parts: - * - *
      - *
    • Preamble code, if any, specified in the Lingua Franca file.
    • - *
    • A "self" struct type definition (see the class documentation above).
    • - *
    • A function for each reaction.
    • - *
    • A constructor for creating an instance. - * for deleting an instance.
    • - *
    - * - *

    If the reactor is the main reactor, then - * the generated code may be customized. Specifically, - * if the main reactor has reactions, these reactions - * will not be generated if they are triggered by or send - * data to contained reactors that are not in the federate.

    - */ - private void generateReactorClass(TypeParameterizedReactor tpr) throws IOException { - // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. - CodeBuilder header = new CodeBuilder(); - CodeBuilder src = new CodeBuilder(); - final String headerName = CUtil.getName(tpr) + ".h"; - var guardMacro = headerName.toUpperCase().replace(".", "_"); - header.pr("#ifndef " + guardMacro); - header.pr("#define " + guardMacro); - generateReactorClassHeaders(tpr, headerName, header, src); - header.pr(generateTopLevelPreambles(tpr.reactor())); - generateUserPreamblesForReactor(tpr.reactor(), src); - generateReactorClassBody(tpr, header, src); - header.pr("#endif // " + guardMacro); - FileUtil.writeToFile(CodeMap.fromGeneratedCode(header.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(headerName), true); - var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : - CCppMode ? ".cpp" : ".c"; - FileUtil.writeToFile(CodeMap.fromGeneratedCode(src.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(CUtil.getName(tpr) + extension), true); + } + + /** + * Choose which platform files to compile with according to the OS. If there is no main reactor, + * then compilation will produce a .o file requiring further linking. Also, if useCmake is set to + * true, we don't need to add platform files. The CMakeLists.txt file will detect and use the + * appropriate platform file based on the platform that cmake is invoked on. + */ + private void pickCompilePlatform() { + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { + errorReporter.reportError("Platform " + osName + " is not supported"); } - - protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { - if (CCppMode) { - src.pr("extern \"C\" {"); - header.pr("extern \"C\" {"); - } - header.pr("#include \"include/core/reactor.h\""); - src.pr("#include \"include/api/api.h\""); - src.pr("#include \"include/api/set.h\""); - generateIncludes(tpr); - if (CCppMode) { - src.pr("}"); - header.pr("}"); - } - src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); - src.pr("#include \"" + headerName + "\""); - tpr.doDefines(src); - ASTUtils.allIncludes(tpr.reactor()).stream().map(name -> "#include \"" - + name + ".h\"").forEach(header::pr); + } + + /** Copy target-specific header file to the src-gen directory. */ + protected void copyTargetFiles() throws IOException { + // Copy the core lib + String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); + Path dest = fileConfig.getSrcGenPath(); + if (targetConfig.platformOptions.platform == Platform.ARDUINO) { + dest = dest.resolve("src"); } - - private void generateReactorClassBody(TypeParameterizedReactor tpr, CodeBuilder header, CodeBuilder src) { - // Some of the following methods create lines of code that need to - // go into the constructor. Collect those lines of code here: - var constructorCode = new CodeBuilder(); - generateAuxiliaryStructs(header, tpr, false); - // The following must go before the self struct so the #include watchdog.h ends up in the header. - CWatchdogGenerator.generateWatchdogs(src, header, tpr, errorReporter); - generateSelfStruct(header, tpr, constructorCode); - generateMethods(src, tpr); - generateReactions(src, tpr); - generateConstructor(src, header, tpr, constructorCode); + if (coreLib != null) { + FileUtil.copyDirectoryContents(Path.of(coreLib), dest, true); + } else { + FileUtil.copyFromClassPath("/lib/c/reactor-c/core", dest, true, false); + FileUtil.copyFromClassPath("/lib/c/reactor-c/lib", dest, true, false); } - /** - * Generate methods for {@code reactor}. - */ - protected void generateMethods(CodeBuilder src, TypeParameterizedReactor tpr) { - CMethodGenerator.generateMethods(tpr, src, types); - } + // For the Zephyr target, copy default config and board files. + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyFromClassPath( + "/lib/platform/zephyr/boards", fileConfig.getSrcGenPath(), false, false); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", fileConfig.getSrcGenPath(), true); - /** - * Generates preambles defined by user for a given reactor - * @param reactor The given reactor - */ - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - for (Preamble p : ASTUtils.allPreambles(reactor)) { - src.pr("// *********** From the preamble, verbatim:"); - src.prSourceLineNumber(p.getCode()); - src.pr(toText(p.getCode())); - src.pr("\n// *********** End of preamble."); - } + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath(), true); } - - /** - * Generate a constructor for the specified reactor in the specified federate. - * @param tpr The parsed reactor data structure. - * @param constructorCode Lines of code previously generated that need to - * go into the constructor. - */ - protected void generateConstructor( - CodeBuilder src, CodeBuilder header, TypeParameterizedReactor tpr, CodeBuilder constructorCode - ) { - header.pr(CConstructorGenerator.generateConstructorPrototype(tpr)); - src.pr(CConstructorGenerator.generateConstructor( - tpr, - constructorCode.toString() - )); + } + + //////////////////////////////////////////// + //// Code generators. + + /** + * Generate a reactor class definition for the specified federate. A class definition has four + * parts: + * + *
      + *
    • Preamble code, if any, specified in the Lingua Franca file. + *
    • A "self" struct type definition (see the class documentation above). + *
    • A function for each reaction. + *
    • A constructor for creating an instance. for deleting an instance. + *
    + * + *

    If the reactor is the main reactor, then the generated code may be customized. Specifically, + * if the main reactor has reactions, these reactions will not be generated if they are triggered + * by or send data to contained reactors that are not in the federate. + */ + private void generateReactorClass(TypeParameterizedReactor tpr) throws IOException { + // FIXME: Currently we're not reusing definitions for declarations that point to the same + // definition. + CodeBuilder header = new CodeBuilder(); + CodeBuilder src = new CodeBuilder(); + final String headerName = CUtil.getName(tpr) + ".h"; + var guardMacro = headerName.toUpperCase().replace(".", "_"); + header.pr("#ifndef " + guardMacro); + header.pr("#define " + guardMacro); + generateReactorClassHeaders(tpr, headerName, header, src); + header.pr(generateTopLevelPreambles(tpr.reactor())); + generateUserPreamblesForReactor(tpr.reactor(), src); + generateReactorClassBody(tpr, header, src); + header.pr("#endif // " + guardMacro); + FileUtil.writeToFile( + CodeMap.fromGeneratedCode(header.toString()).getGeneratedCode(), + fileConfig.getSrcGenPath().resolve(headerName), + true); + var extension = + targetConfig.platformOptions.platform == Platform.ARDUINO + ? ".ino" + : CCppMode ? ".cpp" : ".c"; + FileUtil.writeToFile( + CodeMap.fromGeneratedCode(src.toString()).getGeneratedCode(), + fileConfig.getSrcGenPath().resolve(CUtil.getName(tpr) + extension), + true); + } + + protected void generateReactorClassHeaders( + TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { + if (CCppMode) { + src.pr("extern \"C\" {"); + header.pr("extern \"C\" {"); } - - protected void generateIncludes(TypeParameterizedReactor tpr) { - code.pr("#include \"" + CUtil.getName(tpr) + ".h\""); + header.pr("#include \"include/core/reactor.h\""); + src.pr("#include \"include/api/api.h\""); + src.pr("#include \"include/api/set.h\""); + generateIncludes(tpr); + if (CCppMode) { + src.pr("}"); + header.pr("}"); } - - /** - * Generate the struct type definitions for inputs, outputs, and - * actions of the specified reactor. - */ - protected void generateAuxiliaryStructs(CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing) { - // In the case where there are incoming - // p2p logical connections in decentralized - // federated execution, there will be an - // intended_tag field added to accommodate - // the case where a reaction triggered by a - // port or action is late due to network - // latency, etc.. - var federatedExtension = new CodeBuilder(); - federatedExtension.pr(String.format(""" + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); + src.pr("#include \"" + headerName + "\""); + tpr.doDefines(src); + ASTUtils.allIncludes(tpr.reactor()).stream() + .map(name -> "#include \"" + name + ".h\"") + .forEach(header::pr); + } + + private void generateReactorClassBody( + TypeParameterizedReactor tpr, CodeBuilder header, CodeBuilder src) { + // Some of the following methods create lines of code that need to + // go into the constructor. Collect those lines of code here: + var constructorCode = new CodeBuilder(); + generateAuxiliaryStructs(header, tpr, false); + // The following must go before the self struct so the #include watchdog.h ends up in the + // header. + CWatchdogGenerator.generateWatchdogs(src, header, tpr, errorReporter); + generateSelfStruct(header, tpr, constructorCode); + generateMethods(src, tpr); + generateReactions(src, tpr); + generateConstructor(src, header, tpr, constructorCode); + } + + /** Generate methods for {@code reactor}. */ + protected void generateMethods(CodeBuilder src, TypeParameterizedReactor tpr) { + CMethodGenerator.generateMethods(tpr, src, types); + } + + /** + * Generates preambles defined by user for a given reactor + * + * @param reactor The given reactor + */ + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + for (Preamble p : ASTUtils.allPreambles(reactor)) { + src.pr("// *********** From the preamble, verbatim:"); + src.prSourceLineNumber(p.getCode()); + src.pr(toText(p.getCode())); + src.pr("\n// *********** End of preamble."); + } + } + + /** + * Generate a constructor for the specified reactor in the specified federate. + * + * @param tpr The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to go into the constructor. + */ + protected void generateConstructor( + CodeBuilder src, + CodeBuilder header, + TypeParameterizedReactor tpr, + CodeBuilder constructorCode) { + header.pr(CConstructorGenerator.generateConstructorPrototype(tpr)); + src.pr(CConstructorGenerator.generateConstructor(tpr, constructorCode.toString())); + } + + protected void generateIncludes(TypeParameterizedReactor tpr) { + code.pr("#include \"" + CUtil.getName(tpr) + ".h\""); + } + + /** + * Generate the struct type definitions for inputs, outputs, and actions of the specified reactor. + */ + protected void generateAuxiliaryStructs( + CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing) { + // In the case where there are incoming + // p2p logical connections in decentralized + // federated execution, there will be an + // intended_tag field added to accommodate + // the case where a reaction triggered by a + // port or action is late due to network + // latency, etc.. + var federatedExtension = new CodeBuilder(); + federatedExtension.pr( + String.format( + """ #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(CPortGenerator.generateAuxiliaryStruct( - tpr, - p, - getTarget(), - errorReporter, - types, - federatedExtension, - userFacing, - null - )); - } - // The very first item on this struct needs to be - // a trigger_t* because the struct will be cast to (trigger_t*) - // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(tpr.reactor())) { - builder.pr(CActionGenerator.generateAuxiliaryStruct( - tpr, - action, - getTarget(), - types, - federatedExtension, - userFacing - )); - } + """, + types.getTargetTagType(), types.getTargetTimeType())); + for (Port p : allPorts(tpr.reactor())) { + builder.pr( + CPortGenerator.generateAuxiliaryStruct( + tpr, p, getTarget(), errorReporter, types, federatedExtension, userFacing, null)); } - - /** - * Generate the self struct type definition for the specified reactor - * in the specified federate. - * @param constructorCode Place to put lines of code that need to - * go into the constructor. - */ - private void generateSelfStruct(CodeBuilder builder, TypeParameterizedReactor tpr, CodeBuilder constructorCode) { - var reactor = toDefinition(tpr.reactor()); - var selfType = CUtil.selfType(tpr); - - // Construct the typedef for the "self" struct. - // Create a type name for the self struct. - var body = new CodeBuilder(); - - // Extensions can add functionality to the CGenerator - generateSelfStructExtension(body, reactor, constructorCode); - - // Next handle parameters. - body.pr(CParameterGenerator.generateDeclarations(tpr, types)); - - // Next handle states. - body.pr(CStateGenerator.generateDeclarations(tpr, types)); - - // Next handle actions. - CActionGenerator.generateDeclarations(tpr, body, constructorCode); - - // Next handle inputs and outputs. - CPortGenerator.generateDeclarations(tpr, reactor, body, constructorCode); - - // If there are contained reactors that either receive inputs - // from reactions of this reactor or produce outputs that trigger - // reactions of this reactor, then we need to create a struct - // inside the self struct for each contained reactor. That - // struct has a place to hold the data produced by this reactor's - // reactions and a place to put pointers to data produced by - // the contained reactors. - generateInteractingContainedReactors(tpr, body, constructorCode); - - // Next, generate the fields needed for each reaction. - CReactionGenerator.generateReactionAndTriggerStructs( - body, - tpr, - constructorCode, - types - ); - - // Generate the fields needed for each watchdog. - CWatchdogGenerator.generateWatchdogStruct(body, tpr, constructorCode); - - // Next, generate fields for modes - CModesGenerator.generateDeclarations(reactor, body, constructorCode); - - // The first field has to always be a pointer to the list of - // of allocated memory that must be freed when the reactor is freed. - // This means that the struct can be safely cast to self_base_t. - builder.pr("typedef struct {"); - builder.indent(); - builder.pr("struct self_base_t base;"); - builder.pr(body.toString()); - builder.unindent(); - builder.pr("} " + selfType + ";"); + // The very first item on this struct needs to be + // a trigger_t* because the struct will be cast to (trigger_t*) + // by the lf_schedule() functions to get to the trigger. + for (Action action : allActions(tpr.reactor())) { + builder.pr( + CActionGenerator.generateAuxiliaryStruct( + tpr, action, getTarget(), types, federatedExtension, userFacing)); } - - /** - * Generate structs and associated code for contained reactors that - * send or receive data to or from the container's reactions. - * - * If there are contained reactors that either receive inputs - * from reactions of this reactor or produce outputs that trigger - * reactions of this reactor, then we need to create a struct - * inside the self struct of the container for each contained reactor. - * That struct has a place to hold the data produced by the container reactor's - * reactions and a place to put pointers to data produced by - * the contained reactors. - * - * @param tpr {@link TypeParameterizedReactor} - * @param body The place to put the struct definition for the contained reactors. - * @param constructorCode The place to put matching code that goes in the container's constructor. - */ - private void generateInteractingContainedReactors( - TypeParameterizedReactor tpr, - CodeBuilder body, - CodeBuilder constructorCode - ) { - // The contents of the struct will be collected first so that - // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(tpr.reactor()); - // Next generate the relevant code. - for (Instantiation containedReactor : contained.containedReactors()) { - var containedTpr = new TypeParameterizedReactor(containedReactor); - // First define an _width variable in case it is a bank. - var array = ""; - var width = -2; - // If the instantiation is a bank, find the maximum bank width - // to define an array. - if (containedReactor.getWidthSpec() != null) { - width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); - array = "[" + width + "]"; - } - // NOTE: The following needs to be done for each instance - // so that the width can be parameter, not in the constructor. - // Here, we conservatively use a width that is the largest of all instances. - constructorCode.pr(String.join("\n", - "// Set the _width variable for all cases. This will be -2", - "// if the reactor is not a bank of reactors.", - "self->_lf_"+containedReactor.getName()+"_width = "+width+";" - )); - - // Generate one struct for each contained reactor that interacts. - body.pr("struct {"); - body.indent(); - for (Port port : contained.portsOfInstance(containedReactor)) { - if (port instanceof Input) { - // If the variable is a multiport, then the place to store the data has - // to be malloc'd at initialization. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedTpr, false)+" "+port.getName()+";"); - } else { - // Is a multiport. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedTpr, false)+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - } else { - // Must be an output port. - // Outputs of contained reactors are pointers to the source of data on the - // self struct of the container. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedTpr, false)+"* "+port.getName()+";"); - } else { - // Is a multiport. - // Here, we will use an array of pointers. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedTpr, false)+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - body.pr(port, "trigger_t "+port.getName()+"_trigger;"); - var reactorIndex = ""; - if (containedReactor.getWidthSpec() != null) { - reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); - constructorCode.indent(); - } - var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); - - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederatedDecentralized( - portOnSelf+"_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};" - ) - ); - - var triggered = contained.reactionsTriggered(containedReactor, port); - //noinspection StatementWithEmptyBody - if (triggered.size() > 0) { - body.pr(port, "reaction_t* "+port.getName()+"_reactions["+triggered.size()+"];"); - var triggeredCount = 0; - for (Integer index : triggered) { - constructorCode.pr(port, portOnSelf+"_reactions["+triggeredCount+++"] = &self->_lf__reaction_"+index+";"); - } - constructorCode.pr(port, portOnSelf+"_trigger.reactions = "+portOnSelf+"_reactions;"); - } else { - // Since the self struct is created using calloc, there is no need to set - // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL - } - // Since the self struct is created using calloc, there is no need to set falsy fields. - constructorCode.pr(port, String.join("\n", - portOnSelf+"_trigger.last = NULL;", - portOnSelf+"_trigger.number_of_reactions = "+triggered.size()+";" - )); - - - // Set the physical_time_of_arrival - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederated( - portOnSelf+"_trigger.physical_time_of_arrival = NEVER;" - ) - ); - - if (containedReactor.getWidthSpec() != null) { - constructorCode.unindent(); - constructorCode.pr("}"); - } - } + } + + /** + * Generate the self struct type definition for the specified reactor in the specified federate. + * + * @param constructorCode Place to put lines of code that need to go into the constructor. + */ + private void generateSelfStruct( + CodeBuilder builder, TypeParameterizedReactor tpr, CodeBuilder constructorCode) { + var reactor = toDefinition(tpr.reactor()); + var selfType = CUtil.selfType(tpr); + + // Construct the typedef for the "self" struct. + // Create a type name for the self struct. + var body = new CodeBuilder(); + + // Extensions can add functionality to the CGenerator + generateSelfStructExtension(body, reactor, constructorCode); + + // Next handle parameters. + body.pr(CParameterGenerator.generateDeclarations(tpr, types)); + + // Next handle states. + body.pr(CStateGenerator.generateDeclarations(tpr, types)); + + // Next handle actions. + CActionGenerator.generateDeclarations(tpr, body, constructorCode); + + // Next handle inputs and outputs. + CPortGenerator.generateDeclarations(tpr, reactor, body, constructorCode); + + // If there are contained reactors that either receive inputs + // from reactions of this reactor or produce outputs that trigger + // reactions of this reactor, then we need to create a struct + // inside the self struct for each contained reactor. That + // struct has a place to hold the data produced by this reactor's + // reactions and a place to put pointers to data produced by + // the contained reactors. + generateInteractingContainedReactors(tpr, body, constructorCode); + + // Next, generate the fields needed for each reaction. + CReactionGenerator.generateReactionAndTriggerStructs(body, tpr, constructorCode, types); + + // Generate the fields needed for each watchdog. + CWatchdogGenerator.generateWatchdogStruct(body, tpr, constructorCode); + + // Next, generate fields for modes + CModesGenerator.generateDeclarations(reactor, body, constructorCode); + + // The first field has to always be a pointer to the list of + // of allocated memory that must be freed when the reactor is freed. + // This means that the struct can be safely cast to self_base_t. + builder.pr("typedef struct {"); + builder.indent(); + builder.pr("struct self_base_t base;"); + builder.pr(body.toString()); + builder.unindent(); + builder.pr("} " + selfType + ";"); + } + + /** + * Generate structs and associated code for contained reactors that send or receive data to or + * from the container's reactions. + * + *

    If there are contained reactors that either receive inputs from reactions of this reactor or + * produce outputs that trigger reactions of this reactor, then we need to create a struct inside + * the self struct of the container for each contained reactor. That struct has a place to hold + * the data produced by the container reactor's reactions and a place to put pointers to data + * produced by the contained reactors. + * + * @param tpr {@link TypeParameterizedReactor} + * @param body The place to put the struct definition for the contained reactors. + * @param constructorCode The place to put matching code that goes in the container's constructor. + */ + private void generateInteractingContainedReactors( + TypeParameterizedReactor tpr, CodeBuilder body, CodeBuilder constructorCode) { + // The contents of the struct will be collected first so that + // we avoid duplicate entries and then the struct will be constructed. + var contained = new InteractingContainedReactors(tpr.reactor()); + // Next generate the relevant code. + for (Instantiation containedReactor : contained.containedReactors()) { + var containedTpr = new TypeParameterizedReactor(containedReactor); + // First define an _width variable in case it is a bank. + var array = ""; + var width = -2; + // If the instantiation is a bank, find the maximum bank width + // to define an array. + if (containedReactor.getWidthSpec() != null) { + width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); + array = "[" + width + "]"; + } + // NOTE: The following needs to be done for each instance + // so that the width can be parameter, not in the constructor. + // Here, we conservatively use a width that is the largest of all instances. + constructorCode.pr( + String.join( + "\n", + "// Set the _width variable for all cases. This will be -2", + "// if the reactor is not a bank of reactors.", + "self->_lf_" + containedReactor.getName() + "_width = " + width + ";")); + + // Generate one struct for each contained reactor that interacts. + body.pr("struct {"); + body.indent(); + for (Port port : contained.portsOfInstance(containedReactor)) { + if (port instanceof Input) { + // If the variable is a multiport, then the place to store the data has + // to be malloc'd at initialization. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, variableStructType(port, containedTpr, false) + " " + port.getName() + ";"); + } else { + // Is a multiport. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedTpr, false) + "** " + port.getName() + ";", + "int " + port.getName() + "_width;")); + } + } else { + // Must be an output port. + // Outputs of contained reactors are pointers to the source of data on the + // self struct of the container. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, variableStructType(port, containedTpr, false) + "* " + port.getName() + ";"); + } else { + // Is a multiport. + // Here, we will use an array of pointers. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedTpr, false) + "** " + port.getName() + ";", + "int " + port.getName() + "_width;")); + } + body.pr(port, "trigger_t " + port.getName() + "_trigger;"); + var reactorIndex = ""; + if (containedReactor.getWidthSpec() != null) { + reactorIndex = "[reactor_index]"; + constructorCode.pr( + "for (int reactor_index = 0; reactor_index < self->_lf_" + + containedReactor.getName() + + "_width; reactor_index++) {"); + constructorCode.indent(); + } + var portOnSelf = + "self->_lf_" + containedReactor.getName() + reactorIndex + "." + port.getName(); + + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederatedDecentralized( + portOnSelf + + "_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + + var triggered = contained.reactionsTriggered(containedReactor, port); + //noinspection StatementWithEmptyBody + if (triggered.size() > 0) { + body.pr( + port, "reaction_t* " + port.getName() + "_reactions[" + triggered.size() + "];"); + var triggeredCount = 0; + for (Integer index : triggered) { + constructorCode.pr( + port, + portOnSelf + + "_reactions[" + + triggeredCount++ + + "] = &self->_lf__reaction_" + + index + + ";"); } - body.unindent(); - body.pr(String.join("\n", - "} _lf_"+containedReactor.getName()+array+";", - "int _lf_"+containedReactor.getName()+"_width;" - )); + constructorCode.pr( + port, portOnSelf + "_trigger.reactions = " + portOnSelf + "_reactions;"); + } else { + // Since the self struct is created using calloc, there is no need to set + // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL + } + // Since the self struct is created using calloc, there is no need to set falsy fields. + constructorCode.pr( + port, + String.join( + "\n", + portOnSelf + "_trigger.last = NULL;", + portOnSelf + "_trigger.number_of_reactions = " + triggered.size() + ";")); + + // Set the physical_time_of_arrival + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederated( + portOnSelf + "_trigger.physical_time_of_arrival = NEVER;")); + + if (containedReactor.getWidthSpec() != null) { + constructorCode.unindent(); + constructorCode.pr("}"); + } } + } + body.unindent(); + body.pr( + String.join( + "\n", + "} _lf_" + containedReactor.getName() + array + ";", + "int _lf_" + containedReactor.getName() + "_width;")); } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param body The body of the self struct - * @param reactor The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - protected void generateSelfStructExtension( - CodeBuilder body, - Reactor reactor, - CodeBuilder constructorCode - ) { - // Do nothing - } - - /** Generate reaction functions definition for a reactor. - * These functions have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param tpr The reactor. - */ - public void generateReactions(CodeBuilder src, TypeParameterizedReactor tpr) { - var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(tpr.reactor()); - for (Reaction reaction : allReactions(reactor)) { - generateReaction(src, reaction, tpr, reactionIndex); - // Increment reaction index even if the reaction is not in the federate - // so that across federates, the reaction indices are consistent. - reactionIndex++; - } + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param body The body of the self struct + * @param reactor The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + protected void generateSelfStructExtension( + CodeBuilder body, Reactor reactor, CodeBuilder constructorCode) { + // Do nothing + } + + /** + * Generate reaction functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param tpr The reactor. + */ + public void generateReactions(CodeBuilder src, TypeParameterizedReactor tpr) { + var reactionIndex = 0; + var reactor = ASTUtils.toDefinition(tpr.reactor()); + for (Reaction reaction : allReactions(reactor)) { + generateReaction(src, reaction, tpr, reactionIndex); + // Increment reaction index even if the reaction is not in the federate + // so that across federates, the reaction indices are consistent. + reactionIndex++; } - - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param tpr The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { - src.pr(CReactionGenerator.generateReaction( + } + + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param tpr The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + protected void generateReaction( + CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { + src.pr( + CReactionGenerator.generateReaction( reaction, tpr, reactionIndex, @@ -1427,702 +1423,737 @@ protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParamete errorReporter, types, targetConfig, - getTarget().requiresTypes - )); - } - - /** - * Record startup, shutdown, and reset reactions. - * @param instance A reactor instance. - */ - private void recordBuiltinTriggers(ReactorInstance instance) { - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : instance.reactions) { - var reactor = reaction.getParent(); - var temp = new CodeBuilder(); - var foundOne = false; - - var reactionRef = CUtil.reactionRef(reaction); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.isStartup()) { - temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &"+reactionRef+";"); - startupReactionCount += reactor.getTotalWidth(); - foundOne = true; - } else if (trigger.isShutdown()) { - temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &"+reactionRef+";"); - foundOne = true; - shutdownReactionCount += reactor.getTotalWidth(); - - if (targetConfig.tracing != null) { - var description = CUtil.getShortenedName(reactor); - var reactorRef = CUtil.reactorRef(reactor); - temp.pr(String.join("\n", - "_lf_register_trace_event("+reactorRef+", &("+reactorRef+"->_lf__shutdown),", - "trace_trigger, "+addDoubleQuotes(description+".shutdown")+");" - )); - } - } else if (trigger.isReset()) { - temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &"+reactionRef+";"); - resetReactionCount += reactor.getTotalWidth(); - foundOne = true; - } - } - if (foundOne) initializeTriggerObjects.pr(temp.toString()); + getTarget().requiresTypes)); + } + + /** + * Record startup, shutdown, and reset reactions. + * + * @param instance A reactor instance. + */ + private void recordBuiltinTriggers(ReactorInstance instance) { + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : instance.reactions) { + var reactor = reaction.getParent(); + var temp = new CodeBuilder(); + var foundOne = false; + + var reactionRef = CUtil.reactionRef(reaction); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.isStartup()) { + temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &" + reactionRef + ";"); + startupReactionCount += reactor.getTotalWidth(); + foundOne = true; + } else if (trigger.isShutdown()) { + temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &" + reactionRef + ";"); + foundOne = true; + shutdownReactionCount += reactor.getTotalWidth(); + + if (targetConfig.tracing != null) { + var description = CUtil.getShortenedName(reactor); + var reactorRef = CUtil.reactorRef(reactor); + temp.pr( + String.join( + "\n", + "_lf_register_trace_event(" + + reactorRef + + ", &(" + + reactorRef + + "->_lf__shutdown),", + "trace_trigger, " + addDoubleQuotes(description + ".shutdown") + ");")); + } + } else if (trigger.isReset()) { + temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &" + reactionRef + ";"); + resetReactionCount += reactor.getTotalWidth(); + foundOne = true; } + } + if (foundOne) initializeTriggerObjects.pr(temp.toString()); } - - /** - * Generate code to set up the tables used in _lf_start_time_step to decrement reference - * counts and mark outputs absent between time steps. This function puts the code - * into startTimeStep. - */ - private void generateStartTimeStep(ReactorInstance instance) { - // Avoid generating dead code if nothing is relevant. - var foundOne = false; - var temp = new CodeBuilder(); - var containerSelfStructName = CUtil.reactorRef(instance); - - // Handle inputs that get sent data from a reaction rather than from - // another contained reactor and reactions that are triggered by an - // output of a contained reactor. - // Note that there may be more than one reaction reacting to the same - // port so we have to avoid listing the port more than once. - var portsSeen = new LinkedHashSet(); - for (ReactionInstance reaction : instance.reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - portsSeen.add(port); - // This reaction is sending to an input. Must be - // the input of a contained reactor in the federate. - // NOTE: If instance == main and the federate is within a bank, - // this assumes that the reaction writes only to the bank member in the federate. - foundOne = true; - - temp.pr("// Add port "+port.getFullName()+" to array of is_present fields."); - - if (!instance.equals(port.getParent())) { - // The port belongs to contained reactor, so we also have - // iterate over the instance bank members. - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); - temp.startScopedBankChannelIteration(port, null); - } else { - temp.startScopedBankChannelIteration(port, "count"); - } - var portRef = CUtil.portRefNested(port); - var con = (port.isMultiport()) ? "->" : "."; - - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"is_present;"); - // Intended_tag is only applicable to ports in federated execution. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"intended_tag;" - ) - ); - - startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); - - if (!instance.equals(port.getParent())) { - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); - temp.endScopedBankChannelIteration(port, null); - } else { - temp.endScopedBankChannelIteration(port, "count"); - } - } - } + } + + /** + * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts + * and mark outputs absent between time steps. This function puts the code into startTimeStep. + */ + private void generateStartTimeStep(ReactorInstance instance) { + // Avoid generating dead code if nothing is relevant. + var foundOne = false; + var temp = new CodeBuilder(); + var containerSelfStructName = CUtil.reactorRef(instance); + + // Handle inputs that get sent data from a reaction rather than from + // another contained reactor and reactions that are triggered by an + // output of a contained reactor. + // Note that there may be more than one reaction reacting to the same + // port so we have to avoid listing the port more than once. + var portsSeen = new LinkedHashSet(); + for (ReactionInstance reaction : instance.reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + portsSeen.add(port); + // This reaction is sending to an input. Must be + // the input of a contained reactor in the federate. + // NOTE: If instance == main and the federate is within a bank, + // this assumes that the reaction writes only to the bank member in the federate. + foundOne = true; + + temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); + + if (!instance.equals(port.getParent())) { + // The port belongs to contained reactor, so we also have + // iterate over the instance bank members. + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(instance); + temp.startScopedBankChannelIteration(port, null); + } else { + temp.startScopedBankChannelIteration(port, "count"); + } + var portRef = CUtil.portRefNested(port); + var con = (port.isMultiport()) ? "->" : "."; + + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "is_present;"); + // Intended_tag is only applicable to ports in federated execution. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "intended_tag;")); + + startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); + + if (!instance.equals(port.getParent())) { + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + temp.endScopedBankChannelIteration(port, null); + } else { + temp.endScopedBankChannelIteration(port, "count"); + } } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; + } + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + + for (ActionInstance action : instance.actions) { + foundOne = true; + temp.startScopedBlock(instance); + + temp.pr( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of is_present fields.", + "_lf_is_present_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".is_present;")); + + // Intended_tag is only applicable to actions in federated execution with decentralized + // coordination. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".intended_tag;"))); + + startTimeStepIsPresentCount += action.getParent().getTotalWidth(); + temp.endScopedBlock(); + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; - for (ActionInstance action : instance.actions) { - foundOne = true; - temp.startScopedBlock(instance); + // Next, set up the table to mark each output of each contained reactor absent. + for (ReactorInstance child : instance.children) { + if (child.outputs.size() > 0) { - temp.pr(String.join("\n", - "// Add action "+action.getFullName()+" to array of is_present fields.", - "_lf_is_present_fields["+startTimeStepIsPresentCount+"] ", - " = &"+containerSelfStructName+"->_lf_"+action.getName()+".is_present;" - )); + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(child); - // Intended_tag is only applicable to actions in federated execution with decentralized coordination. + var channelCount = 0; + for (PortInstance output : child.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { + foundOne = true; + temp.pr("// Add port " + output.getFullName() + " to array of is_present fields."); + temp.startChannelIteration(output); + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".is_present;"); + + // Intended_tag is only applicable to ports in federated execution with decentralized + // coordination. temp.pr( CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add action " + action.getFullName() - + " to array of intended_tag fields.", - "_lf_intended_tag_fields[" - + startTimeStepIsPresentCount + "] ", - " = &" + containerSelfStructName - + "->_lf_" + action.getName() - + ".intended_tag;" - ))); - - startTimeStepIsPresentCount += action.getParent().getTotalWidth(); - temp.endScopedBlock(); + String.join( + "\n", + "// Add port " + output.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".intended_tag;"))); + + temp.pr("count++;"); + channelCount += output.getWidth(); + temp.endChannelIteration(output); + } } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; - - // Next, set up the table to mark each output of each contained reactor absent. - for (ReactorInstance child : instance.children) { - if (child.outputs.size() > 0) { - - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(child); - - var channelCount = 0; - for (PortInstance output : child.outputs) { - if (!output.getDependsOnReactions().isEmpty()){ - foundOne = true; - temp.pr("// Add port "+output.getFullName()+" to array of is_present fields."); - temp.startChannelIteration(output); - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".is_present;"); - - // Intended_tag is only applicable to ports in federated execution with decentralized coordination. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add port "+output.getFullName()+" to array of intended_tag fields.", - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".intended_tag;" - ))); - - temp.pr("count++;"); - channelCount += output.getWidth(); - temp.endChannelIteration(output); - } - } - startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); - temp.endScopedBlock(); - temp.endScopedBlock(); - } - } - if (foundOne) startTimeStep.pr(temp.toString()); + startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); + temp.endScopedBlock(); + temp.endScopedBlock(); + } } - - /** - * For each timer in the given reactor, generate initialization code for the offset - * and period fields. - * - * This method will also populate the global _lf_timer_triggers array, which is - * used to start all timers at the start of execution. - * - * @param instance A reactor instance. - */ - private void generateTimerInitializations(ReactorInstance instance) { - for (TimerInstance timer : instance.timers) { - if (!timer.isStartup()) { - initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); - timerCount += timer.getParent().getTotalWidth(); - } - } + if (foundOne) startTimeStep.pr(temp.toString()); + } + + /** + * For each timer in the given reactor, generate initialization code for the offset and period + * fields. + * + *

    This method will also populate the global _lf_timer_triggers array, which is used to start + * all timers at the start of execution. + * + * @param instance A reactor instance. + */ + private void generateTimerInitializations(ReactorInstance instance) { + for (TimerInstance timer : instance.timers) { + if (!timer.isStartup()) { + initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); + timerCount += timer.getParent().getTotalWidth(); + } } - - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * @param filename Name of the file to process. - */ - public void processProtoFile(String filename) { - var protoc = commandFactory.createCommand( + } + + /** + * Process a given .proto file. + * + *

    Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + public void processProtoFile(String filename) { + var protoc = + commandFactory.createCommand( "protoc-c", - List.of("--c_out="+this.fileConfig.getSrcGenPath(), filename), + List.of("--c_out=" + this.fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); - return; - } - var returnCode = protoc.run(); - if (returnCode == 0) { - var nameSansProto = filename.substring(0, filename.length() - 6); - targetConfig.compileAdditionalSources.add( - fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString() - ); - - targetConfig.compileLibraries.add("-l"); - targetConfig.compileLibraries.add("protobuf-c"); - targetConfig.compilerFlags.add("-lprotobuf-c"); - } else { - errorReporter.reportError("protoc-c returns error code " + returnCode); - } + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); + return; } - - /** - * Construct a unique type for the struct of the specified - * typed variable (port or action) of the specified reactor class. - * This is required to be the same as the type name returned by - * {@link #variableStructType(TriggerInstance)}. - */ - public static String variableStructType(Variable variable, TypeParameterizedReactor tpr, boolean userFacing) { - return (userFacing ? tpr.getName().toLowerCase() : CUtil.getName(tpr)) +"_"+variable.getName()+"_t"; + var returnCode = protoc.run(); + if (returnCode == 0) { + var nameSansProto = filename.substring(0, filename.length() - 6); + targetConfig.compileAdditionalSources.add( + fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString()); + + targetConfig.compileLibraries.add("-l"); + targetConfig.compileLibraries.add("protobuf-c"); + targetConfig.compilerFlags.add("-lprotobuf-c"); + } else { + errorReporter.reportError("protoc-c returns error code " + returnCode); } - - /** - * Construct a unique type for the struct of the specified - * instance (port or action). - * This is required to be the same as the type name returned by - * {@link #variableStructType(Variable, TypeParameterizedReactor, boolean)}. - * @param portOrAction The port or action instance. - * @return The name of the self struct. - */ - public static String variableStructType(TriggerInstance portOrAction) { - return CUtil.getName(portOrAction.getParent().tpr)+"_"+portOrAction.getName()+"_t"; + } + + /** + * Construct a unique type for the struct of the specified typed variable (port or action) of the + * specified reactor class. This is required to be the same as the type name returned by {@link + * #variableStructType(TriggerInstance)}. + */ + public static String variableStructType( + Variable variable, TypeParameterizedReactor tpr, boolean userFacing) { + return (userFacing ? tpr.getName().toLowerCase() : CUtil.getName(tpr)) + + "_" + + variable.getName() + + "_t"; + } + + /** + * Construct a unique type for the struct of the specified instance (port or action). This is + * required to be the same as the type name returned by {@link #variableStructType(Variable, + * TypeParameterizedReactor, boolean)}. + * + * @param portOrAction The port or action instance. + * @return The name of the self struct. + */ + public static String variableStructType(TriggerInstance portOrAction) { + return CUtil.getName(portOrAction.getParent().tpr) + "_" + portOrAction.getName() + "_t"; + } + + /** + * If tracing is turned on, then generate code that records the full name of the specified reactor + * instance in the trace table. If tracing is not turned on, do nothing. + * + * @param instance The reactor instance. + */ + private void generateTraceTableEntries(ReactorInstance instance) { + if (targetConfig.tracing != null) { + initializeTriggerObjects.pr(CTracingGenerator.generateTraceTableEntries(instance)); } - - /** - * If tracing is turned on, then generate code that records - * the full name of the specified reactor instance in the - * trace table. If tracing is not turned on, do nothing. - * @param instance The reactor instance. - */ - private void generateTraceTableEntries(ReactorInstance instance) { - if (targetConfig.tracing != null) { - initializeTriggerObjects.pr( - CTracingGenerator.generateTraceTableEntries(instance) - ); - } + } + + /** + * Generate code to instantiate the specified reactor instance and initialize it. + * + * @param instance A reactor instance. + */ + public void generateReactorInstance(ReactorInstance instance) { + var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); + var fullName = instance.getFullName(); + initializeTriggerObjects.pr( + "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); + // Generate the instance self struct containing parameters, state variables, + // and outputs (the "self" struct). + initializeTriggerObjects.pr( + CUtil.reactorRefName(instance) + + "[" + + CUtil.runtimeIndex(instance) + + "] = new_" + + CUtil.getName(instance.tpr) + + "();"); + // Generate code to initialize the "self" struct in the + // _lf_initialize_trigger_objects function. + generateTraceTableEntries(instance); + generateReactorInstanceExtension(instance); + generateParameterInitialization(instance); + initializeOutputMultiports(instance); + initializeInputMultiports(instance); + recordBuiltinTriggers(instance); + watchdogCount += + CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); + + // Next, initialize the "self" struct with state variables. + // These values may be expressions that refer to the parameter values defined above. + generateStateVariableInitializations(instance); + + // Generate trigger objects for the instance. + generateTimerInitializations(instance); + generateActionInitializations(instance); + generateInitializeActionToken(instance); + generateSetDeadline(instance); + generateModeStructure(instance); + + // Recursively generate code for the children. + for (ReactorInstance child : instance.children) { + // If this reactor is a placeholder for a bank of reactors, then generate + // an array of instances of reactors and create an enclosing for loop. + // Need to do this for each of the builders into which the code writes. + startTimeStep.startScopedBlock(child); + initializeTriggerObjects.startScopedBlock(child); + generateReactorInstance(child); + initializeTriggerObjects.endScopedBlock(); + startTimeStep.endScopedBlock(); } - /** - * Generate code to instantiate the specified reactor instance and - * initialize it. - * @param instance A reactor instance. - */ - public void generateReactorInstance(ReactorInstance instance) { - var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); - var fullName = instance.getFullName(); - initializeTriggerObjects.pr( - "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); - // Generate the instance self struct containing parameters, state variables, - // and outputs (the "self" struct). - initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(instance.tpr)+"();"); - // Generate code to initialize the "self" struct in the - // _lf_initialize_trigger_objects function. - generateTraceTableEntries(instance); - generateReactorInstanceExtension(instance); - generateParameterInitialization(instance); - initializeOutputMultiports(instance); - initializeInputMultiports(instance); - recordBuiltinTriggers(instance); - watchdogCount += CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); - - // Next, initialize the "self" struct with state variables. - // These values may be expressions that refer to the parameter values defined above. - generateStateVariableInitializations(instance); - - // Generate trigger objects for the instance. - generateTimerInitializations(instance); - generateActionInitializations(instance); - generateInitializeActionToken(instance); - generateSetDeadline(instance); - generateModeStructure(instance); - - // Recursively generate code for the children. - for (ReactorInstance child : instance.children) { - // If this reactor is a placeholder for a bank of reactors, then generate - // an array of instances of reactors and create an enclosing for loop. - // Need to do this for each of the builders into which the code writes. - startTimeStep.startScopedBlock(child); - initializeTriggerObjects.startScopedBlock(child); - generateReactorInstance(child); - initializeTriggerObjects.endScopedBlock(); - startTimeStep.endScopedBlock(); + // For this instance, define what must be done at the start of + // each time step. This sets up the tables that are used by the + // _lf_start_time_step() function in reactor_common.c. + // Note that this function is also run once at the end + // so that it can deallocate any memory. + generateStartTimeStep(instance); + initializeTriggerObjects.pr("//***** End initializing " + fullName); + } + + /** + * For each action of the specified reactor instance, generate initialization code for the offset + * and period fields. + * + * @param instance The reactor. + */ + private void generateActionInitializations(ReactorInstance instance) { + initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + } + + /** + * Initialize actions by creating a lf_token_t in the self struct. This has the information + * required to allocate memory for the action payload. Skip any action that is not actually used + * as a trigger. + * + * @param reactor The reactor containing the actions. + */ + private void generateInitializeActionToken(ReactorInstance reactor) { + for (ActionInstance action : reactor.actions) { + // Skip this step if the action is not in use. + if (action.getParent().getTriggers().contains(action)) { + var type = reactor.tpr.resolveType(getInferredType(action.getDefinition())); + var payloadSize = "0"; + if (!type.isUndefined()) { + var typeStr = types.getTargetType(type); + if (CUtil.isTokenType(type, types)) { + typeStr = CUtil.rootType(typeStr); + } + if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { + payloadSize = "sizeof(" + typeStr + ")"; + } } - // For this instance, define what must be done at the start of - // each time step. This sets up the tables that are used by the - // _lf_start_time_step() function in reactor_common.c. - // Note that this function is also run once at the end - // so that it can deallocate any memory. - generateStartTimeStep(instance); - initializeTriggerObjects.pr("//***** End initializing " + fullName); - } - - /** - * For each action of the specified reactor instance, generate initialization code - * for the offset and period fields. - * @param instance The reactor. - */ - private void generateActionInitializations(ReactorInstance instance) { - initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + var selfStruct = CUtil.reactorRef(action.getParent()); + initializeTriggerObjects.pr( + CActionGenerator.generateTokenInitializer(selfStruct, action.getName(), payloadSize)); + } } - - /** - * Initialize actions by creating a lf_token_t in the self struct. - * This has the information required to allocate memory for the action payload. - * Skip any action that is not actually used as a trigger. - * @param reactor The reactor containing the actions. - */ - private void generateInitializeActionToken(ReactorInstance reactor) { - for (ActionInstance action : reactor.actions) { - // Skip this step if the action is not in use. - if (action.getParent().getTriggers().contains(action) - ) { - var type = reactor.tpr.resolveType(getInferredType(action.getDefinition())); - var payloadSize = "0"; - if (!type.isUndefined()) { - var typeStr = types.getTargetType(type); - if (CUtil.isTokenType(type, types)) { - typeStr = CUtil.rootType(typeStr); - } - if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { - payloadSize = "sizeof("+typeStr+")"; - } - } - - var selfStruct = CUtil.reactorRef(action.getParent()); - initializeTriggerObjects.pr( - CActionGenerator.generateTokenInitializer( - selfStruct, action.getName(), payloadSize - ) - ); - } + } + + /** + * Generate code that is executed while the reactor instance is being initialized. This is + * provided as an extension point for subclasses. Normally, the reactions argument is the full + * list of reactions, but for the top-level of a federate, will be a subset of reactions that is + * relevant to the federate. + * + * @param instance The reactor instance. + */ + protected void generateReactorInstanceExtension(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. + * + * @param instance The reactor class instance + */ + protected void generateStateVariableInitializations(ReactorInstance instance) { + var reactorClass = instance.getDefinition().getReactorClass(); + var selfRef = CUtil.reactorRef(instance); + for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { + if (isInitialized(stateVar)) { + var mode = + stateVar.eContainer() instanceof Mode + ? instance.lookupModeInstance((Mode) stateVar.eContainer()) + : instance.getMode(false); + initializeTriggerObjects.pr( + CStateGenerator.generateInitializer(instance, selfRef, stateVar, mode, types)); + if (mode != null && stateVar.isReset()) { + modalStateResetCount += instance.getTotalWidth(); } + } } - - /** - * Generate code that is executed while the reactor instance is being initialized. - * This is provided as an extension point for subclasses. - * Normally, the reactions argument is the full list of reactions, - * but for the top-level of a federate, will be a subset of reactions that - * is relevant to the federate. - * @param instance The reactor instance. - */ - protected void generateReactorInstanceExtension(ReactorInstance instance) { - // Do nothing + } + + /** + * Generate code to set the deadline field of the reactions in the specified reactor instance. + * + * @param instance The reactor instance. + */ + private void generateSetDeadline(ReactorInstance instance) { + for (ReactionInstance reaction : instance.reactions) { + var selfRef = CUtil.reactorRef(reaction.getParent()) + "->_lf__reaction_" + reaction.index; + if (reaction.declaredDeadline != null) { + var deadline = reaction.declaredDeadline.maxDelay; + initializeTriggerObjects.pr( + selfRef + ".deadline = " + types.getTargetTimeExpr(deadline) + ";"); + } else { // No deadline. + initializeTriggerObjects.pr(selfRef + ".deadline = NEVER;"); + } } - - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all instances - * of the same reactor. - * @param instance The reactor class instance - */ - protected void generateStateVariableInitializations(ReactorInstance instance) { - var reactorClass = instance.getDefinition().getReactorClass(); - var selfRef = CUtil.reactorRef(instance); - for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { - if (isInitialized(stateVar)) { - var mode = stateVar.eContainer() instanceof Mode ? - instance.lookupModeInstance((Mode) stateVar.eContainer()) : - instance.getMode(false); - initializeTriggerObjects.pr(CStateGenerator.generateInitializer( - instance, - selfRef, - stateVar, - mode, - types - )); - if (mode != null && stateVar.isReset()) { - modalStateResetCount += instance.getTotalWidth(); - } - } - } + } + + /** + * Generate code to initialize modes. + * + * @param instance The reactor instance. + */ + private void generateModeStructure(ReactorInstance instance) { + CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); + if (!instance.modes.isEmpty()) { + modalReactorCount += instance.getTotalWidth(); } - - /** - * Generate code to set the deadline field of the reactions in the - * specified reactor instance. - * @param instance The reactor instance. - */ - private void generateSetDeadline(ReactorInstance instance) { - for (ReactionInstance reaction : instance.reactions) { - var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; - if (reaction.declaredDeadline != null) { - var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); - } else { // No deadline. - initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); - } - } + } + + /** + * Generate runtime initialization code for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + protected void generateParameterInitialization(ReactorInstance instance) { + var selfRef = CUtil.reactorRef(instance); + // Set the local bank_index variable so that initializers can use it. + initializeTriggerObjects.pr( + "bank_index = " + + CUtil.bankIndex(instance) + + ";" + + " SUPPRESS_UNUSED_WARNING(bank_index);"); + for (ParameterInstance parameter : instance.parameters) { + // NOTE: we now use the resolved literal value. For better efficiency, we could + // store constants in a global array and refer to its elements to avoid duplicate + // memory allocations. + // NOTE: If the parameter is initialized with a static initializer for an array + // or struct (the initialization expression is surrounded by { ... }), then we + // have to declare a static variable to ensure that the memory is put in data space + // and not on the stack. + // FIXME: Is there a better way to determine this than the string comparison? + var initializer = CParameterGenerator.getInitializer(parameter); + if (initializer.startsWith("{")) { + var temporaryVariableName = parameter.uniqueID(); + initializeTriggerObjects.pr( + String.join( + "\n", + "static " + + types.getVariableDeclaration( + instance.tpr, parameter.type, temporaryVariableName, true) + + " = " + + initializer + + ";", + selfRef + "->" + parameter.getName() + " = " + temporaryVariableName + ";")); + } else { + initializeTriggerObjects.pr( + selfRef + "->" + parameter.getName() + " = " + initializer + ";"); + } } - - /** - * Generate code to initialize modes. - * @param instance The reactor instance. - */ - private void generateModeStructure(ReactorInstance instance) { - CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); - if (!instance.modes.isEmpty()) { - modalReactorCount += instance.getTotalWidth(); - } + } + + /** + * Generate code that mallocs memory for any output multiports. + * + * @param reactor The reactor instance. + */ + private void initializeOutputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance output : reactor.outputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeOutputMultiport(output, reactorSelfStruct)); } - - /** - * Generate runtime initialization code for parameters of a given reactor instance - * @param instance The reactor instance. - */ - protected void generateParameterInitialization(ReactorInstance instance) { - var selfRef = CUtil.reactorRef(instance); - // Set the local bank_index variable so that initializers can use it. - initializeTriggerObjects.pr("bank_index = "+CUtil.bankIndex(instance)+";" - + " SUPPRESS_UNUSED_WARNING(bank_index);"); - for (ParameterInstance parameter : instance.parameters) { - // NOTE: we now use the resolved literal value. For better efficiency, we could - // store constants in a global array and refer to its elements to avoid duplicate - // memory allocations. - // NOTE: If the parameter is initialized with a static initializer for an array - // or struct (the initialization expression is surrounded by { ... }), then we - // have to declare a static variable to ensure that the memory is put in data space - // and not on the stack. - // FIXME: Is there a better way to determine this than the string comparison? - var initializer = CParameterGenerator.getInitializer(parameter); - if (initializer.startsWith("{")) { - var temporaryVariableName = parameter.uniqueID(); - initializeTriggerObjects.pr(String.join("\n", - "static "+types.getVariableDeclaration(instance.tpr, parameter.type, temporaryVariableName, true)+" = "+initializer+";", - selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" - )); - } else { - initializeTriggerObjects.pr(selfRef+"->"+parameter.getName()+" = "+initializer+";"); - } - } + } + + /** + * Allocate memory for inputs. + * + * @param reactor The reactor. + */ + private void initializeInputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance input : reactor.inputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeInputMultiport(input, reactorSelfStruct)); } - - /** - * Generate code that mallocs memory for any output multiports. - * @param reactor The reactor instance. - */ - private void initializeOutputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance output : reactor.outputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeOutputMultiport( - output, - reactorSelfStruct - )); - } + } + + @Override + public TargetTypes getTargetTypes() { + return types; + } + + /** + * Get the Docker generator. + * + * @param context + * @return + */ + protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new CDockerGenerator(context); + } + + // ////////////////////////////////////////// + // // Protected methods. + + // Perform set up that does not generate code + protected void setUpGeneralParameters() { + accommodatePhysicalActionsIfPresent(); + targetConfig.compileDefinitions.put( + "LOG_LEVEL", String.valueOf(targetConfig.logLevel.ordinal())); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); + // Create the main reactor instance if there is a main reactor. + createMainReactorInstance(); + if (hasModalReactors) { + // So that each separate compile knows about modal reactors, do this: + targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); } - - /** - * Allocate memory for inputs. - * @param reactor The reactor. - */ - private void initializeInputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance input : reactor.inputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeInputMultiport( - input, - reactorSelfStruct - )); - } + if (targetConfig.threading + && targetConfig.platformOptions.platform == Platform.ARDUINO + && (targetConfig.platformOptions.board == null + || !targetConfig.platformOptions.board.contains("mbed"))) { + // non-MBED boards should not use threading + System.out.println( + "Threading is incompatible on your current Arduino flavor. Setting threading to false."); + targetConfig.threading = false; } - @Override - public TargetTypes getTargetTypes() { - return types; + if (targetConfig.platformOptions.platform == Platform.ARDUINO + && !targetConfig.noCompile + && targetConfig.platformOptions.board == null) { + System.out.println( + "To enable compilation for the Arduino platform, you must specify the fully-qualified" + + " board name (FQBN) in the target property. For example, platform: {name: arduino," + + " board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target" + + " code only."); + targetConfig.noCompile = true; } - - /** - * Get the Docker generator. - * @param context - * @return - */ - protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new CDockerGenerator(context); + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake + pickScheduler(); + // FIXME: this and pickScheduler should be combined. + targetConfig.compileDefinitions.put("SCHEDULER", targetConfig.schedulerType.name()); + targetConfig.compileDefinitions.put( + "NUMBER_OF_WORKERS", String.valueOf(targetConfig.workers)); } + pickCompilePlatform(); + } - // ////////////////////////////////////////// - // // Protected methods. - - // Perform set up that does not generate code - protected void setUpGeneralParameters() { - accommodatePhysicalActionsIfPresent(); - targetConfig.compileDefinitions.put("LOG_LEVEL", String.valueOf(targetConfig.logLevel.ordinal())); - targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); - // Create the main reactor instance if there is a main reactor. - createMainReactorInstance(); - if (hasModalReactors) { - // So that each separate compile knows about modal reactors, do this: - targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); - } - if (targetConfig.threading && targetConfig.platformOptions.platform == Platform.ARDUINO - && (targetConfig.platformOptions.board == null || !targetConfig.platformOptions.board.contains("mbed"))) { - //non-MBED boards should not use threading - System.out.println("Threading is incompatible on your current Arduino flavor. Setting threading to false."); - targetConfig.threading = false; - } - - if (targetConfig.platformOptions.platform == Platform.ARDUINO && !targetConfig.noCompile - && targetConfig.platformOptions.board == null) { - System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); - targetConfig.noCompile = true; - } - if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake - pickScheduler(); - // FIXME: this and pickScheduler should be combined. - targetConfig.compileDefinitions.put( - "SCHEDULER", - targetConfig.schedulerType.name() - ); - targetConfig.compileDefinitions.put( - "NUMBER_OF_WORKERS", - String.valueOf(targetConfig.workers) - ); - } - pickCompilePlatform(); + protected void handleProtoFiles() { + // Handle .proto files. + for (String file : targetConfig.protoFiles) { + this.processProtoFile(file); } - - protected void handleProtoFiles() { - // Handle .proto files. - for (String file : targetConfig.protoFiles) { - this.processProtoFile(file); - } + } + + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + CPreambleGenerator.generateDefineDirectives( + targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); + code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); + return code.toString(); + } + + /** Generate top-level preamble code. */ + protected String generateTopLevelPreambles(Reactor reactor) { + CodeBuilder builder = new CodeBuilder(); + var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; + builder.pr("#ifndef " + guard); + builder.pr("#define " + guard); + // Reactors that are instantiated by the specified reactor need to have + // their file-level preambles included. This needs to also include file-level + // preambles of base classes of those reactors. + Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) + .flatMap(it -> ASTUtils.allFileLevelPreambles(it).stream()) + .collect(Collectors.toSet()) + .forEach(it -> builder.pr(toText(it.getCode()))); + for (String file : targetConfig.protoFiles) { + var dotIndex = file.lastIndexOf("."); + var rootFilename = file; + if (dotIndex > 0) { + rootFilename = file.substring(0, dotIndex); + } + code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); } - - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(CPreambleGenerator.generateDefineDirectives( - targetConfig, - fileConfig.getSrcGenPath(), - hasModalReactors - )); - code.pr(CPreambleGenerator.generateIncludeStatements( - targetConfig, - CCppMode - )); - return code.toString(); + builder.pr("#endif"); + return builder.toString(); + } + + protected boolean targetLanguageIsCpp() { + return CCppMode; + } + + /** + * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if + * the line is recognized as the first line of an error message. Otherwise, return null. + * + * @param line A line of output from a compiler or other external tool that might generate errors. + * @return If the line is recognized as the start of an error message, then return a class + * containing the path to the file on which the error occurred (or null if there is none), the + * line number (or the string "1" if there is none), the character position (or the string "0" + * if there is none), and the message (or an empty string if there is none). + */ + @Override + public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + var matcher = compileErrorPattern.matcher(line); + if (matcher.find()) { + var result = new ErrorFileAndLine(); + result.filepath = matcher.group("path"); + result.line = matcher.group("line"); + result.character = matcher.group("column"); + result.message = matcher.group("message"); + + if (!result.message.toLowerCase().contains("error:")) { + result.isError = false; + } + return result; } - - /** - * Generate top-level preamble code. - */ - protected String generateTopLevelPreambles(Reactor reactor) { - CodeBuilder builder = new CodeBuilder(); - var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; - builder.pr("#ifndef " + guard); - builder.pr("#define " + guard); - // Reactors that are instantiated by the specified reactor need to have - // their file-level preambles included. This needs to also include file-level - // preambles of base classes of those reactors. - Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) - .flatMap(it -> ASTUtils.allFileLevelPreambles(it).stream()) - .collect(Collectors.toSet()) - .forEach(it -> builder.pr(toText(it.getCode()))); - for (String file : targetConfig.protoFiles) { - var dotIndex = file.lastIndexOf("."); - var rootFilename = file; - if (dotIndex > 0) { - rootFilename = file.substring(0, dotIndex); - } - code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + return null; + } + + //////////////////////////////////////////// + //// Private methods. + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.C; + } + + //////////////////////////////////////////////////////////// + //// Private methods + + /** + * If a main or federated reactor has been declared, create a ReactorInstance for this top level. + * This will also assign levels to reactions, then, if the program is federated, perform an AST + * transformation to disconnect connections between federates. + */ + private void createMainReactorInstance() { + if (this.mainDef != null) { + if (this.main == null) { + // Recursively build instances. + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + var reactionInstanceGraph = this.main.assignLevels(); + if (reactionInstanceGraph.nodeCount() > 0) { + errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); + return; } - builder.pr("#endif"); - return builder.toString(); - } - - protected boolean targetLanguageIsCpp() { - return CCppMode; - } - - /** Given a line of text from the output of a compiler, return - * an instance of ErrorFileAndLine if the line is recognized as - * the first line of an error message. Otherwise, return null. - * @param line A line of output from a compiler or other external - * tool that might generate errors. - * @return If the line is recognized as the start of an error message, - * then return a class containing the path to the file on which the - * error occurred (or null if there is none), the line number (or the - * string "1" if there is none), the character position (or the string - * "0" if there is none), and the message (or an empty string if there - * is none). - */ - @Override - public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { - var matcher = compileErrorPattern.matcher(line); - if (matcher.find()) { - var result = new ErrorFileAndLine(); - result.filepath = matcher.group("path"); - result.line = matcher.group("line"); - result.character = matcher.group("column"); - result.message = matcher.group("message"); - - if (!result.message.toLowerCase().contains("error:")) { - result.isError = false; - } - return result; + if (hasDeadlines) { + this.main.assignDeadlines(); } - return null; - } - - //////////////////////////////////////////// - //// Private methods. - - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.C; - } - - //////////////////////////////////////////////////////////// - //// Private methods - - /** - * If a main or federated reactor has been declared, create a ReactorInstance - * for this top level. This will also assign levels to reactions, then, - * if the program is federated, perform an AST transformation to disconnect - * connections between federates. - */ - private void createMainReactorInstance() { - if (this.mainDef != null) { - if (this.main == null) { - // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); - var reactionInstanceGraph = this.main.assignLevels(); - if (reactionInstanceGraph.nodeCount() > 0) { - errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); - return; - } - if (hasDeadlines) { - this.main.assignDeadlines(); - } - // Inform the run-time of the breadth/parallelism of the reaction graph - var breadth = reactionInstanceGraph.getBreadth(); - if (breadth == 0) { - errorReporter.reportWarning("The program has no reactions"); - } else { - targetConfig.compileDefinitions.put( - "LF_REACTION_GRAPH_BREADTH", - String.valueOf(reactionInstanceGraph.getBreadth()) - ); - } - } + // Inform the run-time of the breadth/parallelism of the reaction graph + var breadth = reactionInstanceGraph.getBreadth(); + if (breadth == 0) { + errorReporter.reportWarning("The program has no reactions"); + } else { + targetConfig.compileDefinitions.put( + "LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())); } + } } - - /** - * Generate an array of self structs for the reactor - * and one for each of its children. - * @param r The reactor instance. - */ - private void generateSelfStructs(ReactorInstance r) { - initializeTriggerObjects.pr(CUtil.selfType(r)+"* "+CUtil.reactorRefName(r)+"["+r.getTotalWidth()+"];"); - initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING("+CUtil.reactorRefName(r)+");"); - for (ReactorInstance child : r.children) { - generateSelfStructs(child); - } + } + + /** + * Generate an array of self structs for the reactor and one for each of its children. + * + * @param r The reactor instance. + */ + private void generateSelfStructs(ReactorInstance r) { + initializeTriggerObjects.pr( + CUtil.selfType(r) + "* " + CUtil.reactorRefName(r) + "[" + r.getTotalWidth() + "];"); + initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING(" + CUtil.reactorRefName(r) + ");"); + for (ReactorInstance child : r.children) { + generateSelfStructs(child); } + } - private Stream allTypeParameterizedReactors() { - return ASTUtils.recursiveChildren(main).stream() - .map(it -> it.tpr) - .distinct(); - } + private Stream allTypeParameterizedReactors() { + return ASTUtils.recursiveChildren(main).stream().map(it -> it.tpr).distinct(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java index 533611368a..044874029f 100644 --- a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java @@ -3,120 +3,113 @@ import java.util.ArrayList; import java.util.List; import org.lflang.TargetConfig; +import org.lflang.TargetProperty.Platform; import org.lflang.generator.CodeBuilder; import org.lflang.util.StringUtil; -import org.lflang.TargetProperty.Platform; public class CMainFunctionGenerator { - private TargetConfig targetConfig; - /** The command to run the generated code if specified in the target directive. */ - private List runCommand; + private TargetConfig targetConfig; + /** The command to run the generated code if specified in the target directive. */ + private List runCommand; - public CMainFunctionGenerator(TargetConfig targetConfig) { - this.targetConfig = targetConfig; - runCommand = new ArrayList<>(); - parseTargetParameters(); - } + public CMainFunctionGenerator(TargetConfig targetConfig) { + this.targetConfig = targetConfig; + runCommand = new ArrayList<>(); + parseTargetParameters(); + } - /** - * Generate the code that is the entry point - * of the program. - * - * Ideally, this code would belong to its own {@code main.c} - * file, but it currently lives in the same file - * as all the code generated for reactors. - */ - public String generateCode() { - CodeBuilder code = new CodeBuilder(); - code.pr(generateMainFunction()); - code.pr(generateSetDefaultCliOption()); - return code.toString(); - } + /** + * Generate the code that is the entry point of the program. + * + *

    Ideally, this code would belong to its own {@code main.c} file, but it currently lives in + * the same file as all the code generated for reactors. + */ + public String generateCode() { + CodeBuilder code = new CodeBuilder(); + code.pr(generateMainFunction()); + code.pr(generateSetDefaultCliOption()); + return code.toString(); + } - /** - * Generate the {@code main} function. - */ - private String generateMainFunction() { - if (targetConfig.platformOptions.platform == Platform.ARDUINO) { - /** - By default, we must have a serial begin line prior to calling lf_reactor_c_main due to internal debugging messages requiring a print buffer. - For the future, we can check whether internal LF logging is enabled or not before removing this line. - - Logging - */ - return String.join("\n", - "\nvoid _lf_arduino_print_message_function(const char* format, va_list args) {", - "\tchar buf[128];", - "\tvsnprintf(buf, 128, format, args);", - "\tSerial.print(buf);", - "}\n", - "// Arduino setup() and loop() functions", - "void setup() {", - "\tSerial.begin(" + targetConfig.platformOptions.baudRate + ");", - "\tlf_register_print_function(&_lf_arduino_print_message_function, LOG_LEVEL);", - "\tlf_reactor_c_main(0, NULL);", - "}\n", - "void loop() {}" - ); - } else if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - // The Zephyr "runtime" does not terminate when main returns. - // Rather, {@code exit} should be called explicitly. - return String.join("\n", - "void main(void) {", - " int res = lf_reactor_c_main(0, NULL);", - " exit(res);", - "}" - ); - } else { - return String.join("\n", - "int main(int argc, const char* argv[]) {", - " return lf_reactor_c_main(argc, argv);", - "}" - ); - } + /** Generate the {@code main} function. */ + private String generateMainFunction() { + if (targetConfig.platformOptions.platform == Platform.ARDUINO) { + /** + * By default, we must have a serial begin line prior to calling lf_reactor_c_main due to + * internal debugging messages requiring a print buffer. For the future, we can check whether + * internal LF logging is enabled or not before removing this line. - Logging + */ + return String.join( + "\n", + "\nvoid _lf_arduino_print_message_function(const char* format, va_list args) {", + "\tchar buf[128];", + "\tvsnprintf(buf, 128, format, args);", + "\tSerial.print(buf);", + "}\n", + "// Arduino setup() and loop() functions", + "void setup() {", + "\tSerial.begin(" + targetConfig.platformOptions.baudRate + ");", + "\tlf_register_print_function(&_lf_arduino_print_message_function, LOG_LEVEL);", + "\tlf_reactor_c_main(0, NULL);", + "}\n", + "void loop() {}"); + } else if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + // The Zephyr "runtime" does not terminate when main returns. + // Rather, {@code exit} should be called explicitly. + return String.join( + "\n", + "void main(void) {", + " int res = lf_reactor_c_main(0, NULL);", + " exit(res);", + "}"); + } else { + return String.join( + "\n", + "int main(int argc, const char* argv[]) {", + " return lf_reactor_c_main(argc, argv);", + "}"); } + } - /** - * Generate code that is used to override the - * command line options to the {@code main} function - */ - private String generateSetDefaultCliOption() { - // Generate function to set default command-line options. - // A literal array needs to be given outside any function definition, - // so start with that. - return runCommand.size() > 0 ? - String.join("\n", - "const char* _lf_default_argv[] = { " + - StringUtil.addDoubleQuotes( - StringUtil.joinObjects(runCommand, - StringUtil.addDoubleQuotes(", ")))+" };", - "void _lf_set_default_command_line_options() {", - " default_argc = "+runCommand.size()+";", - " default_argv = _lf_default_argv;", - "}") - : "void _lf_set_default_command_line_options() {}"; - } + /** + * Generate code that is used to override the command line options to the {@code main} function + */ + private String generateSetDefaultCliOption() { + // Generate function to set default command-line options. + // A literal array needs to be given outside any function definition, + // so start with that. + return runCommand.size() > 0 + ? String.join( + "\n", + "const char* _lf_default_argv[] = { " + + StringUtil.addDoubleQuotes( + StringUtil.joinObjects(runCommand, StringUtil.addDoubleQuotes(", "))) + + " };", + "void _lf_set_default_command_line_options() {", + " default_argc = " + runCommand.size() + ";", + " default_argv = _lf_default_argv;", + "}") + : "void _lf_set_default_command_line_options() {}"; + } - /** - * Parse the target parameters and set flags to the runCommand - * accordingly. - */ - private void parseTargetParameters() { - if (targetConfig.fastMode) { - runCommand.add("-f"); - runCommand.add("true"); - } - if (targetConfig.keepalive) { - runCommand.add("-k"); - runCommand.add("true"); - } - if (targetConfig.timeout != null) { - runCommand.add("-o"); - runCommand.add(targetConfig.timeout.getMagnitude() + ""); - runCommand.add(targetConfig.timeout.unit.getCanonicalName()); - } - // The runCommand has a first entry that is ignored but needed. - if (runCommand.size() > 0) { - runCommand.add(0, "dummy"); - } + /** Parse the target parameters and set flags to the runCommand accordingly. */ + private void parseTargetParameters() { + if (targetConfig.fastMode) { + runCommand.add("-f"); + runCommand.add("true"); + } + if (targetConfig.keepalive) { + runCommand.add("-k"); + runCommand.add("true"); + } + if (targetConfig.timeout != null) { + runCommand.add("-o"); + runCommand.add(targetConfig.timeout.getMagnitude() + ""); + runCommand.add(targetConfig.timeout.unit.getCanonicalName()); + } + // The runCommand has a first entry that is ignored but needed. + if (runCommand.size() > 0) { + runCommand.add(0, "dummy"); } + } } diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java index 5da00ac70e..1950e8df82 100644 --- a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java @@ -2,8 +2,8 @@ import static org.lflang.ast.ASTUtils.allMethods; -import org.lflang.ast.ASTUtils; import org.lflang.InferredType; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Method; import org.lflang.lf.Reactor; @@ -15,165 +15,151 @@ */ public class CMethodGenerator { - /** - * Generate macro definitions for methods. - * @param tpr The reactor. - * @param body The place to put the macro definitions. - */ - public static void generateMacrosForMethods( - TypeParameterizedReactor tpr, - CodeBuilder body - ) { - for (Method method : allMethods(tpr.reactor())) { - var functionName = methodFunctionName(tpr, method); - // If the method has no arguments. Do not pass it any variadic arguments. - if (method.getArguments().size() > 0) { - body.pr("#define "+method.getName()+"(...) "+functionName+"(self, ##__VA_ARGS__)"); - } else { - body.pr("#define "+method.getName()+"() "+functionName+"(self)"); - } - } + /** + * Generate macro definitions for methods. + * + * @param tpr The reactor. + * @param body The place to put the macro definitions. + */ + public static void generateMacrosForMethods(TypeParameterizedReactor tpr, CodeBuilder body) { + for (Method method : allMethods(tpr.reactor())) { + var functionName = methodFunctionName(tpr, method); + // If the method has no arguments. Do not pass it any variadic arguments. + if (method.getArguments().size() > 0) { + body.pr("#define " + method.getName() + "(...) " + functionName + "(self, ##__VA_ARGS__)"); + } else { + body.pr("#define " + method.getName() + "() " + functionName + "(self)"); + } } + } - /** - * Generate macro undefinitions for methods. - * @param reactor The reactor. - * @param body The place to put the macro definitions. - */ - public static void generateMacroUndefsForMethods( - Reactor reactor, - CodeBuilder body - ) { - for (Method method : allMethods(reactor)) { - body.pr("#undef "+method.getName()); - } + /** + * Generate macro undefinitions for methods. + * + * @param reactor The reactor. + * @param body The place to put the macro definitions. + */ + public static void generateMacroUndefsForMethods(Reactor reactor, CodeBuilder body) { + for (Method method : allMethods(reactor)) { + body.pr("#undef " + method.getName()); } + } - /** - * Generate a method function definition for a reactor. - * This function will have a first argument that is a void* pointing to - * the self struct, followed by any arguments given in its definition. - * @param method The method. - * @param tpr The concrete reactor class. - * @param types The C-specific type conversion functions. - */ - public static String generateMethod( - Method method, - TypeParameterizedReactor tpr, - CTypes types - ) { - var code = new CodeBuilder(); - var body = ASTUtils.toText(method.getCode()); - - code.prSourceLineNumber(method); - code.prComment("Implementation of method "+method.getName()+"()"); - code.pr(generateMethodSignature(method, tpr, types) + " {"); - code.indent(); + /** + * Generate a method function definition for a reactor. This function will have a first argument + * that is a void* pointing to the self struct, followed by any arguments given in its definition. + * + * @param method The method. + * @param tpr The concrete reactor class. + * @param types The C-specific type conversion functions. + */ + public static String generateMethod(Method method, TypeParameterizedReactor tpr, CTypes types) { + var code = new CodeBuilder(); + var body = ASTUtils.toText(method.getCode()); - // Define the "self" struct. - String structType = CUtil.selfType(tpr); - // A null structType means there are no inputs, state, - // or anything else. No need to declare it. - if (structType != null) { - code.pr(String.join("\n", - structType+"* self = ("+structType+"*)instance_args;" - + " SUPPRESS_UNUSED_WARNING(self);" - )); - } + code.prSourceLineNumber(method); + code.prComment("Implementation of method " + method.getName() + "()"); + code.pr(generateMethodSignature(method, tpr, types) + " {"); + code.indent(); - code.prSourceLineNumber(method.getCode()); - code.pr(body); - code.unindent(); - code.pr("}"); - return code.toString(); + // Define the "self" struct. + String structType = CUtil.selfType(tpr); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr( + String.join( + "\n", + structType + + "* self = (" + + structType + + "*)instance_args;" + + " SUPPRESS_UNUSED_WARNING(self);")); } - /** - * Generate method functions definition for a reactor. - * These functions have a first argument that is a void* pointing to - * the self struct. - * @param tpr The reactor. - * @param code The place to put the code. - * @param types The C-specific type conversion functions. - */ - public static void generateMethods( - TypeParameterizedReactor tpr, - CodeBuilder code, - CTypes types - ) { - var reactor = tpr.reactor(); - code.prComment("***** Start of method declarations."); - signatures(tpr, code, types); - generateMacrosForMethods(tpr, code); - for (Method method : allMethods(reactor)) { - code.pr(CMethodGenerator.generateMethod(method, tpr, types)); - } - generateMacroUndefsForMethods(reactor, code); - code.prComment("***** End of method declarations."); - } + code.prSourceLineNumber(method.getCode()); + code.pr(body); + code.unindent(); + code.pr("}"); + return code.toString(); + } - /** - * Generate function signatures for methods. - * This can be used to declare all the methods with signatures only - * before giving the full definition so that methods may call each other - * (and themselves) regardless of the order of definition. - * @param tpr The reactor declaration. - * @param types The C-specific type conversion functions. - */ - public static void signatures( - TypeParameterizedReactor tpr, - CodeBuilder body, - CTypes types - ) { - Reactor reactor = tpr.reactor(); - for (Method method : allMethods(reactor)) { - body.pr(generateMethodSignature(method, tpr, types) + ";"); - } + /** + * Generate method functions definition for a reactor. These functions have a first argument that + * is a void* pointing to the self struct. + * + * @param tpr The reactor. + * @param code The place to put the code. + * @param types The C-specific type conversion functions. + */ + public static void generateMethods(TypeParameterizedReactor tpr, CodeBuilder code, CTypes types) { + var reactor = tpr.reactor(); + code.prComment("***** Start of method declarations."); + signatures(tpr, code, types); + generateMacrosForMethods(tpr, code); + for (Method method : allMethods(reactor)) { + code.pr(CMethodGenerator.generateMethod(method, tpr, types)); } + generateMacroUndefsForMethods(reactor, code); + code.prComment("***** End of method declarations."); + } - /** - * Return the function name for specified method of the specified reactor. - * @param tpr The reactor - * @param method The method. - * @return The function name for the method. - */ - private static String methodFunctionName(TypeParameterizedReactor tpr, Method method) { - return CUtil.getName(tpr) + "_method_" + method.getName(); + /** + * Generate function signatures for methods. This can be used to declare all the methods with + * signatures only before giving the full definition so that methods may call each other (and + * themselves) regardless of the order of definition. + * + * @param tpr The reactor declaration. + * @param types The C-specific type conversion functions. + */ + public static void signatures(TypeParameterizedReactor tpr, CodeBuilder body, CTypes types) { + Reactor reactor = tpr.reactor(); + for (Method method : allMethods(reactor)) { + body.pr(generateMethodSignature(method, tpr, types) + ";"); } + } + + /** + * Return the function name for specified method of the specified reactor. + * + * @param tpr The reactor + * @param method The method. + * @return The function name for the method. + */ + private static String methodFunctionName(TypeParameterizedReactor tpr, Method method) { + return CUtil.getName(tpr) + "_method_" + method.getName(); + } - /** - * Generate a method function signature for a reactor. - * This function will have a first argument that is a void* pointing to - * the self struct, followed by any arguments given in its definition. - * @param method The method. - * @param tpr The reactor declaration. - * @param types The C-specific type conversion functions. - */ - public static String generateMethodSignature( - Method method, - TypeParameterizedReactor tpr, - CTypes types - ) { - var functionName = methodFunctionName(tpr, method); + /** + * Generate a method function signature for a reactor. This function will have a first argument + * that is a void* pointing to the self struct, followed by any arguments given in its definition. + * + * @param method The method. + * @param tpr The reactor declaration. + * @param types The C-specific type conversion functions. + */ + public static String generateMethodSignature( + Method method, TypeParameterizedReactor tpr, CTypes types) { + var functionName = methodFunctionName(tpr, method); - StringBuilder result = new StringBuilder(); - if (method.getReturn() != null) { - result.append(types.getTargetType(InferredType.fromAST(method.getReturn()))); - result.append(" "); - } else { - result.append("void "); - } - result.append(functionName); - result.append("(void* instance_args"); - if (method.getArguments() != null) { - for (var arg : method.getArguments()) { - result.append(", "); - result.append(types.getTargetType(InferredType.fromAST(arg.getType()))); - result.append(" "); - result.append(arg.getName()); - } - } - result.append(")"); - return result.toString(); + StringBuilder result = new StringBuilder(); + if (method.getReturn() != null) { + result.append(types.getTargetType(InferredType.fromAST(method.getReturn()))); + result.append(" "); + } else { + result.append("void "); + } + result.append(functionName); + result.append("(void* instance_args"); + if (method.getArguments() != null) { + for (var arg : method.getArguments()) { + result.append(", "); + result.append(types.getTargetType(InferredType.fromAST(arg.getType()))); + result.append(" "); + result.append(arg.getName()); + } } + result.append(")"); + return result.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CMixedRadixGenerator.java b/org.lflang/src/org/lflang/generator/c/CMixedRadixGenerator.java index 40717f3c4d..f2bf71ef66 100644 --- a/org.lflang/src/org/lflang/generator/c/CMixedRadixGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMixedRadixGenerator.java @@ -1,16 +1,16 @@ package org.lflang.generator.c; 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"; + /** 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/org.lflang/src/org/lflang/generator/c/CModesGenerator.java b/org.lflang/src/org/lflang/generator/c/CModesGenerator.java index 2a6217de64..7d72890639 100644 --- a/org.lflang/src/org/lflang/generator/c/CModesGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CModesGenerator.java @@ -1,7 +1,6 @@ package org.lflang.generator.c; import java.util.List; - import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactionInstance; @@ -17,203 +16,228 @@ * @author Hou Seng Wong */ public class CModesGenerator { - /** - * Generate fields in the self struct for mode instances - * - * @param reactor - * @param body - * @param constructorCode - */ - public static void generateDeclarations( - Reactor reactor, - CodeBuilder body, - CodeBuilder constructorCode - ) { - List allModes = ASTUtils.allModes(reactor); - if (!allModes.isEmpty()) { - // Reactor's mode instances and its state. - body.pr(String.join("\n", - "reactor_mode_t _lf__modes["+reactor.getModes().size()+"];" - )); + /** + * Generate fields in the self struct for mode instances + * + * @param reactor + * @param body + * @param constructorCode + */ + public static void generateDeclarations( + Reactor reactor, CodeBuilder body, CodeBuilder constructorCode) { + List allModes = ASTUtils.allModes(reactor); + if (!allModes.isEmpty()) { + // Reactor's mode instances and its state. + body.pr(String.join("\n", "reactor_mode_t _lf__modes[" + reactor.getModes().size() + "];")); - // Initialize the mode instances - constructorCode.pr("// Initialize modes"); - constructorCode.pr("self_base_t* _lf_self_base = (self_base_t*)self;"); - int initialMode = -1; + // Initialize the mode instances + constructorCode.pr("// Initialize modes"); + constructorCode.pr("self_base_t* _lf_self_base = (self_base_t*)self;"); + int initialMode = -1; - for (int i = 0; i < allModes.size(); i++){ - var mode = allModes.get(i); - constructorCode.pr(mode, String.join("\n", - "self->_lf__modes["+i+"].state = &_lf_self_base->_lf__mode_state;", - "self->_lf__modes["+i+"].name = \""+mode.getName()+"\";", - "self->_lf__modes["+i+"].deactivation_time = 0;", - "self->_lf__modes["+i+"].flags = 0;" - )); - if (initialMode < 0 && mode.isInitial()) { - initialMode = i; - } - } + for (int i = 0; i < allModes.size(); i++) { + var mode = allModes.get(i); + constructorCode.pr( + mode, + String.join( + "\n", + "self->_lf__modes[" + i + "].state = &_lf_self_base->_lf__mode_state;", + "self->_lf__modes[" + i + "].name = \"" + mode.getName() + "\";", + "self->_lf__modes[" + i + "].deactivation_time = 0;", + "self->_lf__modes[" + i + "].flags = 0;")); + if (initialMode < 0 && mode.isInitial()) { + initialMode = i; + } + } - assert initialMode >= 0 : "initial mode must be non-negative!!"; + assert initialMode >= 0 : "initial mode must be non-negative!!"; - // Initialize mode state with initial mode active upon start - constructorCode.pr(String.join("\n", - "// Initialize mode state", - "_lf_self_base->_lf__mode_state.parent_mode = NULL;", - "_lf_self_base->_lf__mode_state.initial_mode = &self->_lf__modes["+initialMode+"];", - "_lf_self_base->_lf__mode_state.current_mode = _lf_self_base->_lf__mode_state.initial_mode;", - "_lf_self_base->_lf__mode_state.next_mode = NULL;", - "_lf_self_base->_lf__mode_state.mode_change = no_transition;" - )); - } + // Initialize mode state with initial mode active upon start + constructorCode.pr( + String.join( + "\n", + "// Initialize mode state", + "_lf_self_base->_lf__mode_state.parent_mode = NULL;", + "_lf_self_base->_lf__mode_state.initial_mode = &self->_lf__modes[" + + initialMode + + "];", + "_lf_self_base->_lf__mode_state.current_mode =" + + " _lf_self_base->_lf__mode_state.initial_mode;", + "_lf_self_base->_lf__mode_state.next_mode = NULL;", + "_lf_self_base->_lf__mode_state.mode_change = no_transition;")); } + } - /** - * Generate the declaration of modal models state table. - * - * @param hasModalReactors True if there is modal model reactors, false otherwise - * @param modalReactorCount The number of modal model reactors - * @param modalStateResetCount The number of modal model state resets - */ - public static String generateModeStatesTable( - boolean hasModalReactors, - int modalReactorCount, - int modalStateResetCount - ) { - if (hasModalReactors) { - return String.join("\n", - "// Array of pointers to mode states to be handled in _lf_handle_mode_changes().", - "reactor_mode_state_t* _lf_modal_reactor_states["+modalReactorCount+"];", - "int _lf_modal_reactor_states_size = "+modalReactorCount+";", - (modalStateResetCount > 0 ? - String.join("\n", - "// Array of reset data for state variables nested in modes. Used in _lf_handle_mode_changes().", - "mode_state_variable_reset_data_t _lf_modal_state_reset["+modalStateResetCount+"];", - "int _lf_modal_state_reset_size = "+modalStateResetCount+";") - : "" - )); - } - return ""; + /** + * Generate the declaration of modal models state table. + * + * @param hasModalReactors True if there is modal model reactors, false otherwise + * @param modalReactorCount The number of modal model reactors + * @param modalStateResetCount The number of modal model state resets + */ + public static String generateModeStatesTable( + boolean hasModalReactors, int modalReactorCount, int modalStateResetCount) { + if (hasModalReactors) { + return String.join( + "\n", + "// Array of pointers to mode states to be handled in _lf_handle_mode_changes().", + "reactor_mode_state_t* _lf_modal_reactor_states[" + modalReactorCount + "];", + "int _lf_modal_reactor_states_size = " + modalReactorCount + ";", + (modalStateResetCount > 0 + ? String.join( + "\n", + "// Array of reset data for state variables nested in modes. Used in" + + " _lf_handle_mode_changes().", + "mode_state_variable_reset_data_t _lf_modal_state_reset[" + + modalStateResetCount + + "];", + "int _lf_modal_state_reset_size = " + modalStateResetCount + ";") + : "")); } + return ""; + } - /** - * Generate counter variable declarations used for registering modal reactors. - * - * @param hasModalReactors True if there is modal model reactors, false otherwise - */ - public static String generateModalInitalizationCounters(boolean hasModalReactors) { - if (hasModalReactors) { - return String.join("\n", - "int _lf_modal_reactor_states_count = 0;", - "int _lf_modal_state_reset_count = 0;" - ); - } - return ""; + /** + * Generate counter variable declarations used for registering modal reactors. + * + * @param hasModalReactors True if there is modal model reactors, false otherwise + */ + public static String generateModalInitalizationCounters(boolean hasModalReactors) { + if (hasModalReactors) { + return String.join( + "\n", "int _lf_modal_reactor_states_count = 0;", "int _lf_modal_state_reset_count = 0;"); } + return ""; + } - /** - * Generate code for modal reactor registration and hierarchy. - * - * @param instance The reactor instance. - * @param code The code builder. - */ - public static void generateModeStructure(ReactorInstance instance, CodeBuilder code) { - var parentMode = instance.getMode(false); - var nameOfSelfStruct = CUtil.reactorRef(instance); - // If this instance is enclosed in another mode - if (parentMode != null) { - var parentModeRef = "&"+CUtil.reactorRef(parentMode.getParent())+"->_lf__modes["+parentMode.getParent().modes.indexOf(parentMode)+"]"; - code.pr("// Setup relation to enclosing mode"); + /** + * Generate code for modal reactor registration and hierarchy. + * + * @param instance The reactor instance. + * @param code The code builder. + */ + public static void generateModeStructure(ReactorInstance instance, CodeBuilder code) { + var parentMode = instance.getMode(false); + var nameOfSelfStruct = CUtil.reactorRef(instance); + // If this instance is enclosed in another mode + if (parentMode != null) { + var parentModeRef = + "&" + + CUtil.reactorRef(parentMode.getParent()) + + "->_lf__modes[" + + parentMode.getParent().modes.indexOf(parentMode) + + "]"; + code.pr("// Setup relation to enclosing mode"); - // If this reactor does not have its own modes, all reactions must be linked to enclosing mode - if (instance.modes.isEmpty()) { - int i = 0; - for (ReactionInstance reaction : instance.reactions) { - code.pr(CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+i+".mode = "+parentModeRef+";"); - i++; - } - } else { // Otherwise, only reactions outside modes must be linked and the mode state itself gets a parent relation - code.pr("((self_base_t*)"+nameOfSelfStruct+")->_lf__mode_state.parent_mode = "+parentModeRef+";"); - for (var reaction : (Iterable) instance.reactions.stream().filter(it -> it.getMode(true) == null)::iterator) { - code.pr(CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+instance.reactions.indexOf(reaction)+".mode = "+parentModeRef+";"); - } - } + // If this reactor does not have its own modes, all reactions must be linked to enclosing mode + if (instance.modes.isEmpty()) { + int i = 0; + for (ReactionInstance reaction : instance.reactions) { + code.pr( + CUtil.reactorRef(reaction.getParent()) + + "->_lf__reaction_" + + i + + ".mode = " + + parentModeRef + + ";"); + i++; } - // If this reactor has modes, register for mode change handling - if (!instance.modes.isEmpty()) { - code.pr("// Register for transition handling"); - code.pr("_lf_modal_reactor_states[_lf_modal_reactor_states_count++] = &((self_base_t*)"+nameOfSelfStruct+")->_lf__mode_state;"); + } else { // Otherwise, only reactions outside modes must be linked and the mode state itself + // gets a parent relation + code.pr( + "((self_base_t*)" + + nameOfSelfStruct + + ")->_lf__mode_state.parent_mode = " + + parentModeRef + + ";"); + for (var reaction : + (Iterable) + instance.reactions.stream().filter(it -> it.getMode(true) == null)::iterator) { + code.pr( + CUtil.reactorRef(reaction.getParent()) + + "->_lf__reaction_" + + instance.reactions.indexOf(reaction) + + ".mode = " + + parentModeRef + + ";"); } + } } + // If this reactor has modes, register for mode change handling + if (!instance.modes.isEmpty()) { + code.pr("// Register for transition handling"); + code.pr( + "_lf_modal_reactor_states[_lf_modal_reactor_states_count++] = &((self_base_t*)" + + nameOfSelfStruct + + ")->_lf__mode_state;"); + } + } - /** - * Generate code registering a state variable for automatic reset. - * - * @param modeRef The code to refer to the mode - * @param selfRef The code to refer to the self struct - * @param varName The variable name in the self struct - * @param source The variable that stores the initial value - * @param type The size of the initial value - */ - public static String generateStateResetStructure( - String modeRef, - String selfRef, - String varName, - String source, - String type - ) { - return String.join("\n", - "// Register for automatic reset", - "_lf_modal_state_reset[_lf_modal_state_reset_count].mode = "+modeRef+";", - "_lf_modal_state_reset[_lf_modal_state_reset_count].target = &("+selfRef+"->"+varName+");", - "_lf_modal_state_reset[_lf_modal_state_reset_count].source = &"+source+";", - "_lf_modal_state_reset[_lf_modal_state_reset_count].size = sizeof("+type+");", - "_lf_modal_state_reset_count++;" - ); - } + /** + * Generate code registering a state variable for automatic reset. + * + * @param modeRef The code to refer to the mode + * @param selfRef The code to refer to the self struct + * @param varName The variable name in the self struct + * @param source The variable that stores the initial value + * @param type The size of the initial value + */ + public static String generateStateResetStructure( + String modeRef, String selfRef, String varName, String source, String type) { + return String.join( + "\n", + "// Register for automatic reset", + "_lf_modal_state_reset[_lf_modal_state_reset_count].mode = " + modeRef + ";", + "_lf_modal_state_reset[_lf_modal_state_reset_count].target = &(" + + selfRef + + "->" + + varName + + ");", + "_lf_modal_state_reset[_lf_modal_state_reset_count].source = &" + source + ";", + "_lf_modal_state_reset[_lf_modal_state_reset_count].size = sizeof(" + type + ");", + "_lf_modal_state_reset_count++;"); + } - /** - * Generate code to call {@code _lf_process_mode_changes}. - * - * @param hasModalReactors True if there is modal model reactors, false otherwise - * @param modalStateResetCount The number of modal model state resets - */ - public static String generateLfHandleModeChanges( - boolean hasModalReactors, - int modalStateResetCount - ) { - if (!hasModalReactors) { - return ""; - } - return String.join("\n", - "void _lf_handle_mode_changes() {", - " _lf_process_mode_changes(", - " _lf_modal_reactor_states, ", - " _lf_modal_reactor_states_size, ", - " " + (modalStateResetCount > 0 ? "_lf_modal_state_reset" : "NULL") + ", ", - " " + (modalStateResetCount > 0 ? "_lf_modal_state_reset_size" : "0") + ", ", - " _lf_timer_triggers, ", - " _lf_timer_triggers_size", - " );", - "}" - ); + /** + * Generate code to call {@code _lf_process_mode_changes}. + * + * @param hasModalReactors True if there is modal model reactors, false otherwise + * @param modalStateResetCount The number of modal model state resets + */ + public static String generateLfHandleModeChanges( + boolean hasModalReactors, int modalStateResetCount) { + if (!hasModalReactors) { + return ""; } + return String.join( + "\n", + "void _lf_handle_mode_changes() {", + " _lf_process_mode_changes(", + " _lf_modal_reactor_states, ", + " _lf_modal_reactor_states_size, ", + " " + (modalStateResetCount > 0 ? "_lf_modal_state_reset" : "NULL") + ", ", + " " + (modalStateResetCount > 0 ? "_lf_modal_state_reset_size" : "0") + ", ", + " _lf_timer_triggers, ", + " _lf_timer_triggers_size", + " );", + "}"); + } - /** - * Generate code to call {@code _lf_initialize_modes}. - * - * @param hasModalReactors True if there is modal model reactors, false otherwise - */ - public static String generateLfInitializeModes(boolean hasModalReactors) { - if (!hasModalReactors) { - return ""; - } - return String.join("\n", - "void _lf_initialize_modes() {", - " _lf_initialize_mode_states(", - " _lf_modal_reactor_states, ", - " _lf_modal_reactor_states_size);", - "}" - ); + /** + * Generate code to call {@code _lf_initialize_modes}. + * + * @param hasModalReactors True if there is modal model reactors, false otherwise + */ + public static String generateLfInitializeModes(boolean hasModalReactors) { + if (!hasModalReactors) { + return ""; } + return String.join( + "\n", + "void _lf_initialize_modes() {", + " _lf_initialize_mode_states(", + " _lf_modal_reactor_states, ", + " _lf_modal_reactor_states_size);", + "}"); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index 786b4701de..caaa375056 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -1,8 +1,8 @@ package org.lflang.generator.c; -import org.lflang.generator.ParameterInstance; import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.ParameterInstance; import org.lflang.lf.Initializer; import org.lflang.lf.Parameter; @@ -14,34 +14,39 @@ * @author Hou Seng Wong */ public class CParameterGenerator { - /** - * Return a C expression that can be used to initialize the specified - * parameter instance. If the parameter initializer refers to other - * parameters, then those parameter references are replaced with - * accesses to the self struct of the parents of those parameters. - */ - public static String getInitializer(ParameterInstance p) { - // Handle the bank_index parameter. - if (p.getName().equals("bank_index")) { - return CUtil.bankIndex(p.getParent()); - } - - CTypes ctypes = CTypes.generateParametersIn(p.getParent().getParent()); - Initializer values = p.getActualValue(); - return ctypes.getTargetInitializer(values, p.getDefinition().getType()); + /** + * Return a C expression that can be used to initialize the specified parameter instance. If the + * parameter initializer refers to other parameters, then those parameter references are replaced + * with accesses to the self struct of the parents of those parameters. + */ + public static String getInitializer(ParameterInstance p) { + // Handle the bank_index parameter. + if (p.getName().equals("bank_index")) { + return CUtil.bankIndex(p.getParent()); } - /** - * Generate code for parameters variables of a reactor in the form "parameter.type parameter.name;" - * @param reactor {@link TypeParameterizedReactor} - * @param types A helper class for types - */ - public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { - CodeBuilder code = new CodeBuilder(); - for (Parameter parameter : ASTUtils.allParameters(reactor.reactor())) { - code.prSourceLineNumber(parameter); - code.pr(types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(parameter))) + " " + parameter.getName() + ";"); - } - return code.toString(); + CTypes ctypes = CTypes.generateParametersIn(p.getParent().getParent()); + Initializer values = p.getActualValue(); + return ctypes.getTargetInitializer(values, p.getDefinition().getType()); + } + + /** + * Generate code for parameters variables of a reactor in the form "parameter.type + * parameter.name;" + * + * @param reactor {@link TypeParameterizedReactor} + * @param types A helper class for types + */ + public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { + CodeBuilder code = new CodeBuilder(); + for (Parameter parameter : ASTUtils.allParameters(reactor.reactor())) { + code.prSourceLineNumber(parameter); + code.pr( + types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(parameter))) + + " " + + parameter.getName() + + ";"); } + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index f82bad661c..02697f4a85 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -1,9 +1,11 @@ package org.lflang.generator.c; -import org.lflang.ast.ASTUtils; +import static org.lflang.generator.c.CGenerator.variableStructType; + import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; import org.lflang.Target; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.PortInstance; import org.lflang.lf.Input; @@ -11,9 +13,6 @@ import org.lflang.lf.Port; import org.lflang.lf.ReactorDecl; -import static org.lflang.generator.c.CGenerator.variableStructType; - - /** * Generates C code to declare and initialize ports. * @@ -22,256 +21,267 @@ * @author Hou Seng Wong */ public class CPortGenerator { - /** - * Generate fields in the self struct for input and output ports - */ - public static void generateDeclarations( - TypeParameterizedReactor tpr, - ReactorDecl decl, - CodeBuilder body, - CodeBuilder constructorCode - ) { - generateInputDeclarations(tpr, body, constructorCode); - generateOutputDeclarations(tpr, body, constructorCode); - } + /** Generate fields in the self struct for input and output ports */ + public static void generateDeclarations( + TypeParameterizedReactor tpr, + ReactorDecl decl, + CodeBuilder body, + CodeBuilder constructorCode) { + generateInputDeclarations(tpr, body, constructorCode); + generateOutputDeclarations(tpr, body, constructorCode); + } - /** - * Generate the struct type definitions for the port of the - * reactor - * - * @param port The port to generate the struct - * @param target The target of the code generation (C, CCpp or Python) - * @param errorReporter The error reporter - * @param types The helper object for types related stuff - * @param federatedExtension The code needed to support federated execution - * @param userFacing Whether this struct is to be presented in a user-facing header - * @param decl The reactorDecl if this struct is for the header of this reactor's container; - * null otherwise - * @return The auxiliary struct for the port as a string - */ - public static String generateAuxiliaryStruct( - TypeParameterizedReactor tpr, - Port port, - Target target, - ErrorReporter errorReporter, - CTypes types, - CodeBuilder federatedExtension, - boolean userFacing, - ReactorDecl decl - ) { - assert decl == null || userFacing; - var code = new CodeBuilder(); - code.pr("typedef struct {"); - code.indent(); - // NOTE: The following fields are required to be the first ones so that - // pointer to this struct can be cast to a (lf_port_base_t*) or to - // (token_template_t*) to access these fields for any port. - // IMPORTANT: These must match exactly the fields defined in port.h!! - code.pr(String.join("\n", - "token_type_t type;", // From token_template_t - "lf_token_t* token;", // From token_template_t - "size_t length;", // From token_template_t - "bool is_present;", // From lf_port_base_t - "lf_sparse_io_record_t* sparse_record;", // From lf_port_base_t - "int destination_channel;", // From lf_port_base_t - "int num_destinations;" // From lf_port_base_t - )); - code.pr(valueDeclaration(tpr, port, target, errorReporter, types)); - code.pr(federatedExtension.toString()); - code.unindent(); - var name = decl != null ? localPortName(decl, port.getName()) + /** + * Generate the struct type definitions for the port of the reactor + * + * @param port The port to generate the struct + * @param target The target of the code generation (C, CCpp or Python) + * @param errorReporter The error reporter + * @param types The helper object for types related stuff + * @param federatedExtension The code needed to support federated execution + * @param userFacing Whether this struct is to be presented in a user-facing header + * @param decl The reactorDecl if this struct is for the header of this reactor's container; null + * otherwise + * @return The auxiliary struct for the port as a string + */ + public static String generateAuxiliaryStruct( + TypeParameterizedReactor tpr, + Port port, + Target target, + ErrorReporter errorReporter, + CTypes types, + CodeBuilder federatedExtension, + boolean userFacing, + ReactorDecl decl) { + assert decl == null || userFacing; + var code = new CodeBuilder(); + code.pr("typedef struct {"); + code.indent(); + // NOTE: The following fields are required to be the first ones so that + // pointer to this struct can be cast to a (lf_port_base_t*) or to + // (token_template_t*) to access these fields for any port. + // IMPORTANT: These must match exactly the fields defined in port.h!! + code.pr( + String.join( + "\n", + "token_type_t type;", // From token_template_t + "lf_token_t* token;", // From token_template_t + "size_t length;", // From token_template_t + "bool is_present;", // From lf_port_base_t + "lf_sparse_io_record_t* sparse_record;", // From lf_port_base_t + "int destination_channel;", // From lf_port_base_t + "int num_destinations;" // From lf_port_base_t + )); + code.pr(valueDeclaration(tpr, port, target, errorReporter, types)); + code.pr(federatedExtension.toString()); + code.unindent(); + var name = + decl != null + ? localPortName(decl, port.getName()) : variableStructType(port, tpr, userFacing); - code.pr("} " + name + ";"); - return code.toString(); - } + code.pr("} " + name + ";"); + return code.toString(); + } - public static String localPortName(ReactorDecl decl, String portName) { - return decl.getName().toLowerCase() + "_" + portName + "_t"; - } + public static String localPortName(ReactorDecl decl, String portName) { + return decl.getName().toLowerCase() + "_" + portName + "_t"; + } - /** - * Allocate memory for the input port. - * @param input The input port - * @param reactorSelfStruct The name of the self struct - */ - public static String initializeInputMultiport( - PortInstance input, - String reactorSelfStruct - ) { - var portRefName = CUtil.portRefName(input); - // If the port is a multiport, create an array. - if (input.isMultiport()) { - String result = String.join("\n", - portRefName+"_width = "+input.getWidth()+";", - "// Allocate memory for multiport inputs.", - portRefName+" = ("+variableStructType(input)+"**)_lf_allocate(", - " "+input.getWidth()+", sizeof("+variableStructType(input)+"*),", - " &"+reactorSelfStruct+"->base.allocations); ", - "// Set inputs by default to an always absent default input.", - "for (int i = 0; i < "+input.getWidth()+"; i++) {", - " "+portRefName+"[i] = &"+reactorSelfStruct+"->_lf_default__"+input.getName()+";", - "}" - ); - if (AttributeUtils.isSparse(input.getDefinition())) { - return String.join("\n", result, - "if ("+input.getWidth()+" >= LF_SPARSE_WIDTH_THRESHOLD) {", - " "+portRefName+"__sparse = (lf_sparse_io_record_t*)_lf_allocate(1,", - " sizeof(lf_sparse_io_record_t) + sizeof(size_t) * "+input.getWidth()+"/LF_SPARSE_CAPACITY_DIVIDER,", - " &"+reactorSelfStruct+"->base.allocations);", - " "+portRefName+"__sparse->capacity = "+input.getWidth()+"/LF_SPARSE_CAPACITY_DIVIDER;", - " if (_lf_sparse_io_record_sizes.start == NULL) {", - " _lf_sparse_io_record_sizes = vector_new(1);", - " }", - " vector_push(&_lf_sparse_io_record_sizes, (void*)&"+portRefName+"__sparse->size);", - "}" - ); - } - return result; - } else { - return String.join("\n", - "// width of -2 indicates that it is not a multiport.", - portRefName+"_width = -2;" - ); - } + /** + * Allocate memory for the input port. + * + * @param input The input port + * @param reactorSelfStruct The name of the self struct + */ + public static String initializeInputMultiport(PortInstance input, String reactorSelfStruct) { + var portRefName = CUtil.portRefName(input); + // If the port is a multiport, create an array. + if (input.isMultiport()) { + String result = + String.join( + "\n", + portRefName + "_width = " + input.getWidth() + ";", + "// Allocate memory for multiport inputs.", + portRefName + " = (" + variableStructType(input) + "**)_lf_allocate(", + " " + input.getWidth() + ", sizeof(" + variableStructType(input) + "*),", + " &" + reactorSelfStruct + "->base.allocations); ", + "// Set inputs by default to an always absent default input.", + "for (int i = 0; i < " + input.getWidth() + "; i++) {", + " " + + portRefName + + "[i] = &" + + reactorSelfStruct + + "->_lf_default__" + + input.getName() + + ";", + "}"); + if (AttributeUtils.isSparse(input.getDefinition())) { + return String.join( + "\n", + result, + "if (" + input.getWidth() + " >= LF_SPARSE_WIDTH_THRESHOLD) {", + " " + portRefName + "__sparse = (lf_sparse_io_record_t*)_lf_allocate(1,", + " sizeof(lf_sparse_io_record_t) + sizeof(size_t) * " + + input.getWidth() + + "/LF_SPARSE_CAPACITY_DIVIDER,", + " &" + reactorSelfStruct + "->base.allocations);", + " " + + portRefName + + "__sparse->capacity = " + + input.getWidth() + + "/LF_SPARSE_CAPACITY_DIVIDER;", + " if (_lf_sparse_io_record_sizes.start == NULL) {", + " _lf_sparse_io_record_sizes = vector_new(1);", + " }", + " vector_push(&_lf_sparse_io_record_sizes, (void*)&" + + portRefName + + "__sparse->size);", + "}"); + } + return result; + } else { + return String.join( + "\n", + "// width of -2 indicates that it is not a multiport.", + portRefName + "_width = -2;"); } + } - /** - * Allocate memory for the output port. - * @param output The output port - * @param reactorSelfStruct The name of the self struct - */ - public static String initializeOutputMultiport( - PortInstance output, - String reactorSelfStruct - ) { - var portRefName = CUtil.portRefName(output); - var portStructType = variableStructType(output); - return output.isMultiport() ? - String.join("\n", - portRefName+"_width = "+output.getWidth()+";", - "// Allocate memory for multiport output.", - portRefName+" = ("+portStructType+"*)_lf_allocate(", - " "+output.getWidth()+", sizeof("+portStructType+"),", - " &"+reactorSelfStruct+"->base.allocations); ", - portRefName+"_pointers = ("+portStructType+"**)_lf_allocate(", - " "+output.getWidth()+", sizeof("+portStructType+"*),", - " &"+reactorSelfStruct+"->base.allocations); ", - "// Assign each output port pointer to be used in", - "// reactions to facilitate user access to output ports", - "for(int i=0; i < "+output.getWidth()+"; i++) {", - " "+portRefName+"_pointers[i] = &("+portRefName+"[i]);", - "}" - ) : - String.join("\n", - "// width of -2 indicates that it is not a multiport.", - portRefName+"_width = -2;" - ); - } + /** + * Allocate memory for the output port. + * + * @param output The output port + * @param reactorSelfStruct The name of the self struct + */ + public static String initializeOutputMultiport(PortInstance output, String reactorSelfStruct) { + var portRefName = CUtil.portRefName(output); + var portStructType = variableStructType(output); + return output.isMultiport() + ? String.join( + "\n", + portRefName + "_width = " + output.getWidth() + ";", + "// Allocate memory for multiport output.", + portRefName + " = (" + portStructType + "*)_lf_allocate(", + " " + output.getWidth() + ", sizeof(" + portStructType + "),", + " &" + reactorSelfStruct + "->base.allocations); ", + portRefName + "_pointers = (" + portStructType + "**)_lf_allocate(", + " " + output.getWidth() + ", sizeof(" + portStructType + "*),", + " &" + reactorSelfStruct + "->base.allocations); ", + "// Assign each output port pointer to be used in", + "// reactions to facilitate user access to output ports", + "for(int i=0; i < " + output.getWidth() + "; i++) {", + " " + portRefName + "_pointers[i] = &(" + portRefName + "[i]);", + "}") + : String.join( + "\n", + "// width of -2 indicates that it is not a multiport.", + portRefName + "_width = -2;"); + } - /** - * For the specified port, return a declaration for port struct to - * contain the value of the port. A multiport output with width 4 and - * type int[10], for example, will result in this: - *

    
    -     *     int value[10];
    -     * 
    - * There will be an array of size 4 of structs, each containing this value - * array. - * @param port The port. - * @return A string providing the value field of the port struct. - */ - private static String valueDeclaration( - TypeParameterizedReactor tpr, - Port port, - Target target, - ErrorReporter errorReporter, - CTypes types - ) { - if (port.getType() == null && target.requiresTypes) { - // This should have been caught by the validator. - errorReporter.reportError(port, "Port is required to have a type: " + port.getName()); - return ""; - } - // Do not convert to lf_token_t* using lfTypeToTokenType because there - // will be a separate field pointing to the token. - return types.getVariableDeclaration(tpr, ASTUtils.getInferredType(port), "value", false) + ";"; + /** + * For the specified port, return a declaration for port struct to contain the value of the port. + * A multiport output with width 4 and type int[10], for example, will result in this: + * + *
    
    +   *     int value[10];
    +   * 
    + * + * There will be an array of size 4 of structs, each containing this value array. + * + * @param port The port. + * @return A string providing the value field of the port struct. + */ + private static String valueDeclaration( + TypeParameterizedReactor tpr, + Port port, + Target target, + ErrorReporter errorReporter, + CTypes types) { + if (port.getType() == null && target.requiresTypes) { + // This should have been caught by the validator. + errorReporter.reportError(port, "Port is required to have a type: " + port.getName()); + return ""; } + // Do not convert to lf_token_t* using lfTypeToTokenType because there + // will be a separate field pointing to the token. + return types.getVariableDeclaration(tpr, ASTUtils.getInferredType(port), "value", false) + ";"; + } - /** - * Generate fields in the self struct for input ports - * - * If the port is a multiport, the input field is an array of - * pointers that will be allocated separately for each instance - * because the sizes may be different. Otherwise, it is a simple - * pointer. - * - */ - private static void generateInputDeclarations( - TypeParameterizedReactor tpr, - CodeBuilder body, - CodeBuilder constructorCode - ) { - for (Input input : ASTUtils.allInputs(tpr.reactor())) { - var inputName = input.getName(); - if (ASTUtils.isMultiport(input)) { - body.pr(input, String.join("\n", - "// Multiport input array will be malloc'd later.", - variableStructType(input, tpr, false)+"** _lf_"+inputName+";", - "int _lf_"+inputName+"_width;", - "// Default input (in case it does not get connected)", - variableStructType(input, tpr, false)+" _lf_default__"+inputName+";", - "// Struct to support efficiently reading sparse inputs.", - "lf_sparse_io_record_t* _lf_"+inputName+"__sparse;" - )); - } else { - // input is not a multiport. - body.pr(input, String.join("\n", - variableStructType(input, tpr, false)+"* _lf_"+inputName+";", - "// width of -2 indicates that it is not a multiport.", - "int _lf_"+inputName+"_width;", - "// Default input (in case it does not get connected)", - variableStructType(input, tpr, false)+" _lf_default__"+inputName+";" - )); + /** + * Generate fields in the self struct for input ports + * + *

    If the port is a multiport, the input field is an array of pointers that will be allocated + * separately for each instance because the sizes may be different. Otherwise, it is a simple + * pointer. + */ + private static void generateInputDeclarations( + TypeParameterizedReactor tpr, CodeBuilder body, CodeBuilder constructorCode) { + for (Input input : ASTUtils.allInputs(tpr.reactor())) { + var inputName = input.getName(); + if (ASTUtils.isMultiport(input)) { + body.pr( + input, + String.join( + "\n", + "// Multiport input array will be malloc'd later.", + variableStructType(input, tpr, false) + "** _lf_" + inputName + ";", + "int _lf_" + inputName + "_width;", + "// Default input (in case it does not get connected)", + variableStructType(input, tpr, false) + " _lf_default__" + inputName + ";", + "// Struct to support efficiently reading sparse inputs.", + "lf_sparse_io_record_t* _lf_" + inputName + "__sparse;")); + } else { + // input is not a multiport. + body.pr( + input, + String.join( + "\n", + variableStructType(input, tpr, false) + "* _lf_" + inputName + ";", + "// width of -2 indicates that it is not a multiport.", + "int _lf_" + inputName + "_width;", + "// Default input (in case it does not get connected)", + variableStructType(input, tpr, false) + " _lf_default__" + inputName + ";")); - constructorCode.pr(input, String.join("\n", - "// Set input by default to an always absent default input.", - "self->_lf_"+inputName+" = &self->_lf_default__"+inputName+";" - )); - } - } + constructorCode.pr( + input, + String.join( + "\n", + "// Set input by default to an always absent default input.", + "self->_lf_" + inputName + " = &self->_lf_default__" + inputName + ";")); + } } + } - /** - * Generate fields in the self struct for output ports - */ - private static void generateOutputDeclarations( - TypeParameterizedReactor tpr, - CodeBuilder body, - CodeBuilder constructorCode - ) { - for (Output output : ASTUtils.allOutputs(tpr.reactor())) { - // If the port is a multiport, create an array to be allocated - // at instantiation. - var outputName = output.getName(); - if (ASTUtils.isMultiport(output)) { - body.pr(output, String.join("\n", - "// Array of output ports.", - variableStructType(output, tpr, false)+"* _lf_"+outputName+";", - "int _lf_"+outputName+"_width;", - "// An array of pointers to the individual ports. Useful", - "// for the lf_set macros to work out-of-the-box for", - "// multiports in the body of reactions because their ", - "// value can be accessed via a -> operator (e.g.,foo[i]->value).", - "// So we have to handle multiports specially here a construct that", - "// array of pointers.", - variableStructType(output, tpr, false)+"** _lf_"+outputName+"_pointers;" - )); - } else { - body.pr(output, String.join("\n", - variableStructType(output, tpr, false)+" _lf_"+outputName+";", - "int _lf_"+outputName+"_width;" - )); - } - } + /** Generate fields in the self struct for output ports */ + private static void generateOutputDeclarations( + TypeParameterizedReactor tpr, CodeBuilder body, CodeBuilder constructorCode) { + for (Output output : ASTUtils.allOutputs(tpr.reactor())) { + // If the port is a multiport, create an array to be allocated + // at instantiation. + var outputName = output.getName(); + if (ASTUtils.isMultiport(output)) { + body.pr( + output, + String.join( + "\n", + "// Array of output ports.", + variableStructType(output, tpr, false) + "* _lf_" + outputName + ";", + "int _lf_" + outputName + "_width;", + "// An array of pointers to the individual ports. Useful", + "// for the lf_set macros to work out-of-the-box for", + "// multiports in the body of reactions because their ", + "// value can be accessed via a -> operator (e.g.,foo[i]->value).", + "// So we have to handle multiports specially here a construct that", + "// array of pointers.", + variableStructType(output, tpr, false) + "** _lf_" + outputName + "_pointers;")); + } else { + body.pr( + output, + String.join( + "\n", + variableStructType(output, tpr, false) + " _lf_" + outputName + ";", + "int _lf_" + outputName + "_width;")); + } } + } } diff --git a/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java b/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java index 8ca0404d75..45b81caab6 100644 --- a/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java @@ -1,18 +1,16 @@ package org.lflang.generator.c; -import java.nio.file.Path; +import static org.lflang.util.StringUtil.addDoubleQuotes; +import java.nio.file.Path; import org.lflang.TargetConfig; import org.lflang.TargetProperty.Platform; import org.lflang.generator.CodeBuilder; import org.lflang.util.StringUtil; -import static org.lflang.util.StringUtil.addDoubleQuotes; - /** - * Generates code for preambles for the C and CCpp target. - * This includes #include and #define directives at the top - * of each generated ".c" file. + * Generates code for preambles for the C and CCpp target. This includes #include and #define + * directives at the top of each generated ".c" file. * * @author Edward A. Lee * @author Marten Lohstroh @@ -26,76 +24,69 @@ * @author Anirudh Rengarajan */ public class CPreambleGenerator { - /** Add necessary source files specific to the target language. */ - public static String generateIncludeStatements( - TargetConfig targetConfig, - boolean cppMode - ) { - var tracing = targetConfig.tracing; - CodeBuilder code = new CodeBuilder(); - if (cppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) { - code.pr("extern \"C\" {"); - } - code.pr("#include "); - code.pr("#include \"include/core/platform.h\""); - CCoreFilesUtils.getCTargetHeader().forEach( - it -> code.pr("#include " + StringUtil.addDoubleQuotes(it)) - ); - code.pr("#include \"include/core/reactor.h\""); - code.pr("#include \"include/core/reactor_common.h\""); - if (targetConfig.threading) { - code.pr("#include \"include/core/threaded/scheduler.h\""); - } + /** Add necessary source files specific to the target language. */ + public static String generateIncludeStatements(TargetConfig targetConfig, boolean cppMode) { + var tracing = targetConfig.tracing; + CodeBuilder code = new CodeBuilder(); + if (cppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) { + code.pr("extern \"C\" {"); + } + code.pr("#include "); + code.pr("#include \"include/core/platform.h\""); + CCoreFilesUtils.getCTargetHeader() + .forEach(it -> code.pr("#include " + StringUtil.addDoubleQuotes(it))); + code.pr("#include \"include/core/reactor.h\""); + code.pr("#include \"include/core/reactor_common.h\""); + if (targetConfig.threading) { + code.pr("#include \"include/core/threaded/scheduler.h\""); + } - if (tracing != null) { - code.pr("#include \"include/core/trace.h\""); - } - code.pr("#include \"include/core/mixed_radix.h\""); - code.pr("#include \"include/core/port.h\""); - code.pr("int lf_reactor_c_main(int argc, const char* argv[]);"); - if(targetConfig.fedSetupPreamble != null) { - code.pr("#include \"include/core/federated/federate.h\""); - code.pr("#include \"include/core/federated/net_common.h\""); - } - if (cppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) { - code.pr("}"); - } - return code.toString(); + if (tracing != null) { + code.pr("#include \"include/core/trace.h\""); + } + code.pr("#include \"include/core/mixed_radix.h\""); + code.pr("#include \"include/core/port.h\""); + code.pr("int lf_reactor_c_main(int argc, const char* argv[]);"); + if (targetConfig.fedSetupPreamble != null) { + code.pr("#include \"include/core/federated/federate.h\""); + code.pr("#include \"include/core/federated/net_common.h\""); + } + if (cppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) { + code.pr("}"); } + return code.toString(); + } - public static String generateDefineDirectives( - TargetConfig targetConfig, - Path srcGenPath, - boolean hasModalReactors - ) { - int logLevel = targetConfig.logLevel.ordinal(); - var coordinationType = targetConfig.coordination; - var tracing = targetConfig.tracing; - CodeBuilder code = new CodeBuilder(); - // TODO: Get rid of all of these - code.pr("#define LOG_LEVEL " + logLevel); - code.pr("#define TARGET_FILES_DIRECTORY " + addDoubleQuotes(srcGenPath.toString())); + public static String generateDefineDirectives( + TargetConfig targetConfig, Path srcGenPath, boolean hasModalReactors) { + int logLevel = targetConfig.logLevel.ordinal(); + var coordinationType = targetConfig.coordination; + var tracing = targetConfig.tracing; + CodeBuilder code = new CodeBuilder(); + // TODO: Get rid of all of these + code.pr("#define LOG_LEVEL " + logLevel); + code.pr("#define TARGET_FILES_DIRECTORY " + addDoubleQuotes(srcGenPath.toString())); - if (tracing != null) { - targetConfig.compileDefinitions.put("LF_TRACE", tracing.traceFileName); - } - // if (clockSyncIsOn) { - // code.pr(generateClockSyncDefineDirective( - // targetConfig.clockSync, - // targetConfig.clockSyncOptions - // )); - // } - if (targetConfig.threading) { - targetConfig.compileDefinitions.put("LF_THREADED", "1"); - } else { - targetConfig.compileDefinitions.put("LF_UNTHREADED", "1"); - } - if (targetConfig.threading) { - targetConfig.compileDefinitions.put("LF_THREADED", "1"); - } else { - targetConfig.compileDefinitions.put("LF_UNTHREADED", "1"); - } - code.newLine(); - return code.toString(); + if (tracing != null) { + targetConfig.compileDefinitions.put("LF_TRACE", tracing.traceFileName); + } + // if (clockSyncIsOn) { + // code.pr(generateClockSyncDefineDirective( + // targetConfig.clockSync, + // targetConfig.clockSyncOptions + // )); + // } + if (targetConfig.threading) { + targetConfig.compileDefinitions.put("LF_THREADED", "1"); + } else { + targetConfig.compileDefinitions.put("LF_UNTHREADED", "1"); + } + if (targetConfig.threading) { + targetConfig.compileDefinitions.put("LF_THREADED", "1"); + } else { + targetConfig.compileDefinitions.put("LF_UNTHREADED", "1"); } + code.newLine(); + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 26e6c8ab6f..6fcef92dd6 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -9,11 +9,10 @@ import java.util.List; import java.util.Map; import java.util.Set; - -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; import org.lflang.TargetConfig; +import org.lflang.ast.ASTUtils; import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Action; @@ -37,1154 +36,1335 @@ import org.lflang.util.StringUtil; 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) + protected static String DISABLE_REACTION_INITIALIZATION_MARKER = + "// **** Do not include initialization code in this reaction."; // FIXME: Such markers should + // not exist (#1687) - /** - * Generate necessary initialization code inside the body of the reaction that belongs to reactor decl. - * @param body The body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER. - * @param reaction The initialization code will be generated for this specific reaction - * @param tpr The reactor that has the reaction - * @param reactionIndex The index of the reaction relative to other reactions in the reactor, starting from 0 - */ - public static String generateInitializationForReaction(String body, - Reaction reaction, - TypeParameterizedReactor tpr, - int reactionIndex, - CTypes types, - ErrorReporter errorReporter, - Instantiation mainDef, - boolean requiresTypes) { - // Construct the reactionInitialization code to go into - // the body of the function before the verbatim code. - CodeBuilder reactionInitialization = new CodeBuilder(); + /** + * Generate necessary initialization code inside the body of the reaction that belongs to reactor + * decl. + * + * @param body The body of the reaction. Used to check for the + * DISABLE_REACTION_INITIALIZATION_MARKER. + * @param reaction The initialization code will be generated for this specific reaction + * @param tpr The reactor that has the reaction + * @param reactionIndex The index of the reaction relative to other reactions in the reactor, + * starting from 0 + */ + public static String generateInitializationForReaction( + String body, + Reaction reaction, + TypeParameterizedReactor tpr, + int reactionIndex, + CTypes types, + ErrorReporter errorReporter, + Instantiation mainDef, + boolean requiresTypes) { + // Construct the reactionInitialization code to go into + // the body of the function before the verbatim code. + CodeBuilder reactionInitialization = new CodeBuilder(); - CodeBuilder code = new CodeBuilder(); + CodeBuilder code = new CodeBuilder(); - // Define the "self" struct. - String structType = CUtil.selfType(tpr); - // A null structType means there are no inputs, state, - // or anything else. No need to declare it. - if (structType != null) { - code.pr(String.join("\n", - structType+"* self = ("+structType+"*)instance_args; SUPPRESS_UNUSED_WARNING(self);" - )); - } - - // Do not generate the initialization code if the body is marked - // to not generate it. - if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { - return code.toString(); - } + // Define the "self" struct. + String structType = CUtil.selfType(tpr); + // A null structType means there are no inputs, state, + // or anything else. No need to declare it. + if (structType != null) { + code.pr( + String.join( + "\n", + structType + + "* self = (" + + structType + + "*)instance_args; SUPPRESS_UNUSED_WARNING(self);")); + } - // A reaction may send to or receive from multiple ports of - // a contained reactor. The variables for these ports need to - // all be declared as fields of the same struct. Hence, we first - // collect the fields to be defined in the structs and then - // generate the structs. - Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); + // Do not generate the initialization code if the body is marked + // to not generate it. + if (body.startsWith(DISABLE_REACTION_INITIALIZATION_MARKER)) { + return code.toString(); + } - // Actions may appear twice, first as a trigger, then with the outputs. - // But we need to declare it only once. Collect in this data structure - // the actions that are declared as triggered so that if they appear - // again with the outputs, they are not defined a second time. - // That second redefinition would trigger a compile error. - Set actionsAsTriggers = new LinkedHashSet<>(); + // A reaction may send to or receive from multiple ports of + // a contained reactor. The variables for these ports need to + // all be declared as fields of the same struct. Hence, we first + // collect the fields to be defined in the structs and then + // generate the structs. + Map fieldsForStructsForContainedReactors = new LinkedHashMap<>(); - // Next, add the triggers (input and actions; timers are not needed). - // This defines a local variable in the reaction function whose - // name matches that of the trigger. The value of the local variable - // is a struct with a value and is_present field, the latter a boolean - // that indicates whether the input/action is present. - // If the trigger is an output, then it is an output of a - // contained reactor. In this case, a struct with the name - // of the contained reactor is created with one field that is - // a pointer to a struct with a value and is_present field. - // E.g., if the contained reactor is named 'c' and its output - // port is named 'out', then c.out->value c.out->is_present are - // defined so that they can be used in the verbatim code. - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - if (triggerAsVarRef.getVariable() instanceof Port) { - generatePortVariablesInReaction( - reactionInitialization, - fieldsForStructsForContainedReactors, - triggerAsVarRef, - tpr, - types); - } else if (triggerAsVarRef.getVariable() instanceof Action) { - reactionInitialization.pr(generateActionVariablesInReaction( - (Action) triggerAsVarRef.getVariable(), - tpr, - types - )); - actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); - } - } - } - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - // No triggers are given, which means react to any input. - // Declare an argument for every input. - // NOTE: this does not include contained outputs. - for (Input input : tpr.reactor().getInputs()) { - reactionInitialization.pr(generateInputVariablesInReaction(input, tpr, types)); - } - } - // Define argument for non-triggering inputs. - for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - if (src.getVariable() instanceof Port) { - generatePortVariablesInReaction(reactionInitialization, fieldsForStructsForContainedReactors, src, tpr, types); - } else if (src.getVariable() instanceof Action) { - // It's a bit odd to read but not be triggered by an action, but - // OK, I guess we allow it. - reactionInitialization.pr(generateActionVariablesInReaction( - (Action) src.getVariable(), - tpr, - types - )); - actionsAsTriggers.add((Action) src.getVariable()); - } - } + // Actions may appear twice, first as a trigger, then with the outputs. + // But we need to declare it only once. Collect in this data structure + // the actions that are declared as triggered so that if they appear + // again with the outputs, they are not defined a second time. + // That second redefinition would trigger a compile error. + Set actionsAsTriggers = new LinkedHashSet<>(); - // Define variables for each declared output or action. - // In the case of outputs, the variable is a pointer to where the - // output is stored. This gives the reaction code access to any previous - // value that may have been written to that output in an earlier reaction. - if (reaction.getEffects() != null) { - for (VarRef effect : reaction.getEffects()) { - Variable variable = effect.getVariable(); - if (variable instanceof Action) { - // It is an action, not an output. - // If it has already appeared as trigger, do not redefine it. - if (!actionsAsTriggers.contains(effect.getVariable())) { - reactionInitialization.pr(CGenerator.variableStructType(variable, tpr, false)+"* "+variable.getName()+" = &self->_lf_"+variable.getName()+";"); - } - } else if (effect.getVariable() instanceof Mode) { - // Mode change effect - int idx = ASTUtils.allModes(tpr.reactor()).indexOf((Mode)effect.getVariable()); - String name = effect.getVariable().getName(); - if (idx >= 0) { - reactionInitialization.pr( - "reactor_mode_t* " + name + " = &self->_lf__modes[" + idx + "];\n" - + "lf_mode_change_type_t _lf_" + name + "_change_type = " - + (effect.getTransition() == ModeTransition.HISTORY ? - "history_transition" : "reset_transition") - + ";" - ); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): " + name + " not a valid mode of this reactor." - ); - } - } else { - if (variable instanceof Output) { - reactionInitialization.pr(generateOutputVariablesInReaction( - effect, - tpr, - errorReporter, - requiresTypes - )); - } else if (variable instanceof Input) { - // It is the input of a contained reactor. - generateVariablesForSendingToContainedReactors( - reactionInitialization, - fieldsForStructsForContainedReactors, - effect.getContainer(), - (Input) variable); - } else if (variable instanceof Watchdog) { - reactionInitialization.pr(generateWatchdogVariablesInReaction(effect)); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): effect is not an input, output, or watchdog." - ); - } - } - } - } - // Before the reaction initialization, - // generate the structs used for communication to and from contained reactors. - for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { - String array = ""; - if (containedReactor.getWidthSpec() != null) { - String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); - code.pr("int "+containedReactorWidthVar+" = self->_lf_"+containedReactorWidthVar+";"); - // Windows does not support variables in arrays declared on the stack, - // so we use the maximum size over all bank members. - array = "["+maxContainedReactorBankWidth(containedReactor, null, 0, mainDef)+"]"; - } - code.pr(String.join("\n", - "struct "+containedReactor.getName()+" {", - " "+fieldsForStructsForContainedReactors.get(containedReactor), - "} "+containedReactor.getName()+array+";" - )); + // Next, add the triggers (input and actions; timers are not needed). + // This defines a local variable in the reaction function whose + // name matches that of the trigger. The value of the local variable + // is a struct with a value and is_present field, the latter a boolean + // that indicates whether the input/action is present. + // If the trigger is an output, then it is an output of a + // contained reactor. In this case, a struct with the name + // of the contained reactor is created with one field that is + // a pointer to a struct with a value and is_present field. + // E.g., if the contained reactor is named 'c' and its output + // port is named 'out', then c.out->value c.out->is_present are + // defined so that they can be used in the verbatim code. + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + if (triggerAsVarRef.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, + fieldsForStructsForContainedReactors, + triggerAsVarRef, + tpr, + types); + } else if (triggerAsVarRef.getVariable() instanceof Action) { + reactionInitialization.pr( + generateActionVariablesInReaction( + (Action) triggerAsVarRef.getVariable(), tpr, types)); + actionsAsTriggers.add((Action) triggerAsVarRef.getVariable()); } - // Next generate all the collected setup code. - code.pr(reactionInitialization.toString()); - return code.toString(); + } + } + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + // No triggers are given, which means react to any input. + // Declare an argument for every input. + // NOTE: this does not include contained outputs. + for (Input input : tpr.reactor().getInputs()) { + reactionInitialization.pr(generateInputVariablesInReaction(input, tpr, types)); + } + } + // Define argument for non-triggering inputs. + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (src.getVariable() instanceof Port) { + generatePortVariablesInReaction( + reactionInitialization, fieldsForStructsForContainedReactors, src, tpr, types); + } else if (src.getVariable() instanceof Action) { + // It's a bit odd to read but not be triggered by an action, but + // OK, I guess we allow it. + reactionInitialization.pr( + generateActionVariablesInReaction((Action) src.getVariable(), tpr, types)); + actionsAsTriggers.add((Action) src.getVariable()); + } } - /** - * Return the maximum bank width for the given instantiation within all - * instantiations of its parent reactor. - * On the first call to this method, the breadcrumbs should be null and the max - * argument should be zero. On recursive calls, breadcrumbs is a list of nested - * instantiations, the max is the maximum width found so far. The search for - * instances of the parent reactor will begin with the last instantiation - * in the specified list. - * - * This rather complicated method is used when a reaction sends or receives data - * to or from a bank of contained reactors. There will be an array of structs on - * the self struct of the parent, and the size of the array is conservatively set - * to the maximum of all the identified bank widths. This is a bit wasteful of - * memory, but it avoids having to malloc the array for each instance, and in - * typical usage, there will be few instances or instances that are all the same - * width. - * - * @param containedReactor The contained reactor instantiation. - * @param breadcrumbs null on first call (non-recursive). - * @param max 0 on first call. - */ - public static int maxContainedReactorBankWidth( - Instantiation containedReactor, - LinkedList breadcrumbs, - int max, - Instantiation mainDef - ) { - // If the instantiation is not a bank, return 1. - if (containedReactor.getWidthSpec() == null) { - return 1; - } - // If there is no main, then we just use the default width. - if (mainDef == null) { - return ASTUtils.width(containedReactor.getWidthSpec(), null); - } - LinkedList nestedBreadcrumbs = breadcrumbs; - if (nestedBreadcrumbs == null) { - nestedBreadcrumbs = new LinkedList<>(); - nestedBreadcrumbs.add(mainDef); - } - int result = max; - Reactor parent = (Reactor) containedReactor.eContainer(); - if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { - // The parent is main, so there can't be any other instantiations of it. - return ASTUtils.width(containedReactor.getWidthSpec(), null); - } - // Search for instances of the parent within the tail of the breadcrumbs list. - Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); - for (Instantiation instantiation : container.getInstantiations()) { - // Put this new instantiation at the head of the list. - nestedBreadcrumbs.add(0, instantiation); - if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { - // Found a matching instantiation of the parent. - // Evaluate the original width specification in this context. - int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); - if (candidate > result) { - result = candidate; - } - } else { - // Found some other instantiation, not the parent. - // Search within it for instantiations of the parent. - // Note that we assume here that the parent cannot contain - // instances of itself. - int candidate = maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); - if (candidate > result) { - result = candidate; - } - } - nestedBreadcrumbs.remove(); + // Define variables for each declared output or action. + // In the case of outputs, the variable is a pointer to where the + // output is stored. This gives the reaction code access to any previous + // value that may have been written to that output in an earlier reaction. + if (reaction.getEffects() != null) { + for (VarRef effect : reaction.getEffects()) { + Variable variable = effect.getVariable(); + if (variable instanceof Action) { + // It is an action, not an output. + // If it has already appeared as trigger, do not redefine it. + if (!actionsAsTriggers.contains(effect.getVariable())) { + reactionInitialization.pr( + CGenerator.variableStructType(variable, tpr, false) + + "* " + + variable.getName() + + " = &self->_lf_" + + variable.getName() + + ";"); + } + } else if (effect.getVariable() instanceof Mode) { + // Mode change effect + int idx = ASTUtils.allModes(tpr.reactor()).indexOf((Mode) effect.getVariable()); + String name = effect.getVariable().getName(); + if (idx >= 0) { + reactionInitialization.pr( + "reactor_mode_t* " + + name + + " = &self->_lf__modes[" + + idx + + "];\n" + + "lf_mode_change_type_t _lf_" + + name + + "_change_type = " + + (effect.getTransition() == ModeTransition.HISTORY + ? "history_transition" + : "reset_transition") + + ";"); + } else { + errorReporter.reportError( + reaction, "In generateReaction(): " + name + " not a valid mode of this reactor."); + } + } else { + if (variable instanceof Output) { + reactionInitialization.pr( + generateOutputVariablesInReaction(effect, tpr, errorReporter, requiresTypes)); + } else if (variable instanceof Input) { + // It is the input of a contained reactor. + generateVariablesForSendingToContainedReactors( + reactionInitialization, + fieldsForStructsForContainedReactors, + effect.getContainer(), + (Input) variable); + } else if (variable instanceof Watchdog) { + reactionInitialization.pr(generateWatchdogVariablesInReaction(effect)); + } else { + errorReporter.reportError( + reaction, "In generateReaction(): effect is not an input, output, or watchdog."); + } } - return result; + } } - - /** - * Generate code for the body of a reaction that takes an input and - * schedules an action with the value of that input. - * @param actionName The action to schedule - */ - public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { - // Note that the action.type set by the base class is actually - // the port type. - return isTokenType ? - String.join("\n", - "if ("+ref+"->is_present) {", - " // Put the whole token on the event queue, not just the payload.", - " // This way, the length and element_size are transported.", - " lf_schedule_token("+actionName+", 0, "+ref+"->token);", - "}" - ) : - "lf_schedule_copy("+actionName+", 0, &"+ref+"->value, 1); // Length is 1."; + // Before the reaction initialization, + // generate the structs used for communication to and from contained reactors. + for (Instantiation containedReactor : fieldsForStructsForContainedReactors.keySet()) { + String array = ""; + if (containedReactor.getWidthSpec() != null) { + String containedReactorWidthVar = generateWidthVariable(containedReactor.getName()); + code.pr( + "int " + containedReactorWidthVar + " = self->_lf_" + containedReactorWidthVar + ";"); + // Windows does not support variables in arrays declared on the stack, + // so we use the maximum size over all bank members. + array = "[" + maxContainedReactorBankWidth(containedReactor, null, 0, mainDef) + "]"; + } + code.pr( + String.join( + "\n", + "struct " + containedReactor.getName() + " {", + " " + fieldsForStructsForContainedReactors.get(containedReactor), + "} " + containedReactor.getName() + array + ";")); } + // Next generate all the collected setup code. + code.pr(reactionInitialization.toString()); + return code.toString(); + } - public static String generateForwardBody(String outputName, String targetType, String actionName, boolean isTokenType) { - return isTokenType ? - String.join("\n", - DISABLE_REACTION_INITIALIZATION_MARKER, - "self->_lf_"+outputName+".value = ("+targetType+")self->_lf__"+actionName+".tmplt.token->value;", - "_lf_replace_template_token((token_template_t*)&self->_lf_"+outputName+", (lf_token_t*)self->_lf__"+actionName+".tmplt.token);", - "self->_lf_"+outputName+".is_present = true;" - ) : - "lf_set("+outputName+", "+actionName+"->value);"; + /** + * Return the maximum bank width for the given instantiation within all instantiations of its + * parent reactor. On the first call to this method, the breadcrumbs should be null and the max + * argument should be zero. On recursive calls, breadcrumbs is a list of nested instantiations, + * the max is the maximum width found so far. The search for instances of the parent reactor will + * begin with the last instantiation in the specified list. + * + *

    This rather complicated method is used when a reaction sends or receives data to or from a + * bank of contained reactors. There will be an array of structs on the self struct of the parent, + * and the size of the array is conservatively set to the maximum of all the identified bank + * widths. This is a bit wasteful of memory, but it avoids having to malloc the array for each + * instance, and in typical usage, there will be few instances or instances that are all the same + * width. + * + * @param containedReactor The contained reactor instantiation. + * @param breadcrumbs null on first call (non-recursive). + * @param max 0 on first call. + */ + public static int maxContainedReactorBankWidth( + Instantiation containedReactor, + LinkedList breadcrumbs, + int max, + Instantiation mainDef) { + // If the instantiation is not a bank, return 1. + if (containedReactor.getWidthSpec() == null) { + return 1; } - - /** - * Generate into the specified string builder the code to - * initialize local variables for sending data to an input - * of a contained reactor. This will also, if necessary, - * generate entries for local struct definitions into the - * struct argument. These entries point to where the data - * is stored. - * - * @param builder The string builder. - * @param structs A map from reactor instantiations to a place to write - * struct fields. - * @param definition AST node defining the reactor within which this occurs - * @param input Input of the contained reactor. - */ - private static void generateVariablesForSendingToContainedReactors( - CodeBuilder builder, - Map structs, - Instantiation definition, - Input input - ) { - CodeBuilder structBuilder = structs.get(definition); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(definition, structBuilder); + // If there is no main, then we just use the default width. + if (mainDef == null) { + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + LinkedList nestedBreadcrumbs = breadcrumbs; + if (nestedBreadcrumbs == null) { + nestedBreadcrumbs = new LinkedList<>(); + nestedBreadcrumbs.add(mainDef); + } + int result = max; + Reactor parent = (Reactor) containedReactor.eContainer(); + if (parent == ASTUtils.toDefinition(mainDef.getReactorClass())) { + // The parent is main, so there can't be any other instantiations of it. + return ASTUtils.width(containedReactor.getWidthSpec(), null); + } + // Search for instances of the parent within the tail of the breadcrumbs list. + Reactor container = ASTUtils.toDefinition(nestedBreadcrumbs.get(0).getReactorClass()); + for (Instantiation instantiation : container.getInstantiations()) { + // Put this new instantiation at the head of the list. + nestedBreadcrumbs.add(0, instantiation); + if (ASTUtils.toDefinition(instantiation.getReactorClass()) == parent) { + // Found a matching instantiation of the parent. + // Evaluate the original width specification in this context. + int candidate = ASTUtils.width(containedReactor.getWidthSpec(), nestedBreadcrumbs); + if (candidate > result) { + result = candidate; } - String inputStructType = CGenerator.variableStructType(input, new TypeParameterizedReactor(definition), false); - String defName = definition.getName(); - String defWidth = generateWidthVariable(defName); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); - if (!ASTUtils.isMultiport(input)) { - // Contained reactor's input is not a multiport. - structBuilder.pr(inputStructType+"* "+inputName+";"); - if (definition.getWidthSpec() != null) { - // Contained reactor is a bank. - builder.pr(String.join("\n", - "for (int bankIndex = 0; bankIndex < self->_lf_"+defWidth+"; bankIndex++) {", - " "+defName+"[bankIndex]."+inputName+" = &(self->_lf_"+defName+"[bankIndex]."+inputName+");", - "}" - )); - } else { - // Contained reactor is not a bank. - builder.pr(defName+"."+inputName+" = &(self->_lf_"+defName+"."+inputName+");"); - } - } else { - // Contained reactor's input is a multiport. - structBuilder.pr(String.join("\n", - inputStructType+"** "+inputName+";", - "int "+inputWidth+";" - )); - // If the contained reactor is a bank, then we have to set the - // pointer for each element of the bank. - if (definition.getWidthSpec() != null) { - builder.pr(String.join("\n", - "for (int _i = 0; _i < self->_lf_"+defWidth+"; _i++) {", - " "+defName+"[_i]."+inputName+" = self->_lf_"+defName+"[_i]."+inputName+";", - " "+defName+"[_i]."+inputWidth+" = self->_lf_"+defName+"[_i]."+inputWidth+";", - "}" - )); - } else { - builder.pr(String.join("\n", - defName+"."+inputName+" = self->_lf_"+defName+"."+inputName+";", - defName+"."+inputWidth+" = self->_lf_"+defName+"."+inputWidth+";" - )); - } + } else { + // Found some other instantiation, not the parent. + // Search within it for instantiations of the parent. + // Note that we assume here that the parent cannot contain + // instances of itself. + int candidate = + maxContainedReactorBankWidth(containedReactor, nestedBreadcrumbs, result, mainDef); + if (candidate > result) { + result = candidate; } + } + nestedBreadcrumbs.remove(); } + return result; + } - /** - * Generate into the specified string builder the code to - * initialize local variables for ports in a reaction function - * from the "self" struct. The port may be an input of the - * reactor or an output of a contained reactor. The second - * argument provides, for each contained reactor, a place to - * write the declaration of the output of that reactor that - * is triggering reactions. - * @param builder The place into which to write the code. - * @param structs A map from reactor instantiations to a place to write - * struct fields. - */ - private static void generatePortVariablesInReaction( - CodeBuilder builder, - Map structs, - VarRef port, - TypeParameterizedReactor tpr, - CTypes types - ) { - if (port.getVariable() instanceof Input) { - builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), tpr, types)); - } else { - // port is an output of a contained reactor. - Output output = (Output) port.getVariable(); - String portStructType = CGenerator.variableStructType(output, new TypeParameterizedReactor(port.getContainer()), false); + /** + * Generate code for the body of a reaction that takes an input and schedules an action with the + * value of that input. + * + * @param actionName The action to schedule + */ + public static String generateDelayBody(String ref, String actionName, boolean isTokenType) { + // Note that the action.type set by the base class is actually + // the port type. + return isTokenType + ? String.join( + "\n", + "if (" + ref + "->is_present) {", + " // Put the whole token on the event queue, not just the payload.", + " // This way, the length and element_size are transported.", + " lf_schedule_token(" + actionName + ", 0, " + ref + "->token);", + "}") + : "lf_schedule_copy(" + actionName + ", 0, &" + ref + "->value, 1); // Length is 1."; + } - CodeBuilder structBuilder = structs.get(port.getContainer()); - if (structBuilder == null) { - structBuilder = new CodeBuilder(); - structs.put(port.getContainer(), structBuilder); - } - String subName = port.getContainer().getName(); - String reactorWidth = generateWidthVariable(subName); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - // First define the struct containing the output value and indicator - // of its presence. - if (!ASTUtils.isMultiport(output)) { - // Output is not a multiport. - structBuilder.pr(portStructType+"* "+outputName+";"); - } else { - // Output is a multiport. - structBuilder.pr(String.join("\n", - portStructType+"** "+outputName+";", - "int "+outputWidth+";" - )); - } + public static String generateForwardBody( + String outputName, String targetType, String actionName, boolean isTokenType) { + return isTokenType + ? String.join( + "\n", + DISABLE_REACTION_INITIALIZATION_MARKER, + "self->_lf_" + + outputName + + ".value = (" + + targetType + + ")self->_lf__" + + actionName + + ".tmplt.token->value;", + "_lf_replace_template_token((token_template_t*)&self->_lf_" + + outputName + + ", (lf_token_t*)self->_lf__" + + actionName + + ".tmplt.token);", + "self->_lf_" + outputName + ".is_present = true;") + : "lf_set(" + outputName + ", " + actionName + "->value);"; + } - // Next, initialize the struct with the current values. - if (port.getContainer().getWidthSpec() != null) { - // Output is in a bank. - builder.pr(String.join("\n", - "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+subName+"[i]."+outputName+" = self->_lf_"+subName+"[i]."+outputName+";", - "}" - )); - if (ASTUtils.isMultiport(output)) { - builder.pr(String.join("\n", - "for (int i = 0; i < "+reactorWidth+"; i++) {", - " "+subName+"[i]."+outputWidth+" = self->_lf_"+subName+"[i]."+outputWidth+";", - "}" - )); - } - } else { - // Output is not in a bank. - builder.pr(subName+"."+outputName+" = self->_lf_"+subName+"."+outputName+";"); - if (ASTUtils.isMultiport(output)) { - builder.pr(subName+"."+outputWidth+" = self->_lf_"+subName+"."+outputWidth+";"); - } - } - } + /** + * Generate into the specified string builder the code to initialize local variables for sending + * data to an input of a contained reactor. This will also, if necessary, generate entries for + * local struct definitions into the struct argument. These entries point to where the data is + * stored. + * + * @param builder The string builder. + * @param structs A map from reactor instantiations to a place to write struct fields. + * @param definition AST node defining the reactor within which this occurs + * @param input Input of the contained reactor. + */ + private static void generateVariablesForSendingToContainedReactors( + CodeBuilder builder, + Map structs, + Instantiation definition, + Input input) { + CodeBuilder structBuilder = structs.get(definition); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(definition, structBuilder); } + String inputStructType = + CGenerator.variableStructType(input, new TypeParameterizedReactor(definition), false); + String defName = definition.getName(); + String defWidth = generateWidthVariable(defName); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); + if (!ASTUtils.isMultiport(input)) { + // Contained reactor's input is not a multiport. + structBuilder.pr(inputStructType + "* " + inputName + ";"); + if (definition.getWidthSpec() != null) { + // Contained reactor is a bank. + builder.pr( + String.join( + "\n", + "for (int bankIndex = 0; bankIndex < self->_lf_" + defWidth + "; bankIndex++) {", + " " + + defName + + "[bankIndex]." + + inputName + + " = &(self->_lf_" + + defName + + "[bankIndex]." + + inputName + + ");", + "}")); + } else { + // Contained reactor is not a bank. + builder.pr( + defName + "." + inputName + " = &(self->_lf_" + defName + "." + inputName + ");"); + } + } else { + // Contained reactor's input is a multiport. + structBuilder.pr( + String.join("\n", inputStructType + "** " + inputName + ";", "int " + inputWidth + ";")); + // If the contained reactor is a bank, then we have to set the + // pointer for each element of the bank. + if (definition.getWidthSpec() != null) { + builder.pr( + String.join( + "\n", + "for (int _i = 0; _i < self->_lf_" + defWidth + "; _i++) {", + " " + + defName + + "[_i]." + + inputName + + " = self->_lf_" + + defName + + "[_i]." + + inputName + + ";", + " " + + defName + + "[_i]." + + inputWidth + + " = self->_lf_" + + defName + + "[_i]." + + inputWidth + + ";", + "}")); + } else { + builder.pr( + String.join( + "\n", + defName + "." + inputName + " = self->_lf_" + defName + "." + inputName + ";", + defName + "." + inputWidth + " = self->_lf_" + defName + "." + inputWidth + ";")); + } + } + } + + /** + * Generate into the specified string builder the code to initialize local variables for ports in + * a reaction function from the "self" struct. The port may be an input of the reactor or an + * output of a contained reactor. The second argument provides, for each contained reactor, a + * place to write the declaration of the output of that reactor that is triggering reactions. + * + * @param builder The place into which to write the code. + * @param structs A map from reactor instantiations to a place to write struct fields. + */ + private static void generatePortVariablesInReaction( + CodeBuilder builder, + Map structs, + VarRef port, + TypeParameterizedReactor tpr, + CTypes types) { + if (port.getVariable() instanceof Input) { + builder.pr(generateInputVariablesInReaction((Input) port.getVariable(), tpr, types)); + } else { + // port is an output of a contained reactor. + Output output = (Output) port.getVariable(); + String portStructType = + CGenerator.variableStructType( + output, new TypeParameterizedReactor(port.getContainer()), false); - /** Generate action variables for a reaction. - * @param action The action. - */ - private static String generateActionVariablesInReaction( - Action action, - TypeParameterizedReactor tpr, - CTypes types - ) { - String structType = CGenerator.variableStructType(action, tpr, false); - // If the action has a type, create variables for accessing the value. - InferredType type = ASTUtils.getInferredType(action); - // Pointer to the lf_token_t sent as the payload in the trigger. - String tokenPointer = "(self->_lf__"+action.getName()+".tmplt.token)"; - CodeBuilder builder = new CodeBuilder(); + CodeBuilder structBuilder = structs.get(port.getContainer()); + if (structBuilder == null) { + structBuilder = new CodeBuilder(); + structs.put(port.getContainer(), structBuilder); + } + String subName = port.getContainer().getName(); + String reactorWidth = generateWidthVariable(subName); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + // First define the struct containing the output value and indicator + // of its presence. + if (!ASTUtils.isMultiport(output)) { + // Output is not a multiport. + structBuilder.pr(portStructType + "* " + outputName + ";"); + } else { + // Output is a multiport. + structBuilder.pr( + String.join( + "\n", portStructType + "** " + outputName + ";", "int " + outputWidth + ";")); + } + // Next, initialize the struct with the current values. + if (port.getContainer().getWidthSpec() != null) { + // Output is in a bank. builder.pr( - String.join("\n", - "// Expose the action struct as a local variable whose name matches the action name.", - structType+"* "+action.getName()+" = &self->_lf_"+action.getName()+";", - "// Set the fields of the action struct to match the current trigger.", - action.getName()+"->is_present = (bool)self->_lf__"+action.getName()+".status;", - action.getName()+"->has_value = ("+tokenPointer+" != NULL && "+tokenPointer+"->value != NULL);", - "_lf_replace_template_token((token_template_t*)"+action.getName()+", "+tokenPointer+");") - ); - // Set the value field only if there is a type. - if (!type.isUndefined()) { - // The value field will either be a copy (for primitive types) - // or a pointer (for types ending in *). - builder.pr("if ("+action.getName()+"->has_value) {"); - builder.indent(); - if (CUtil.isTokenType(type, types)) { - builder.pr(action.getName()+"->value = ("+types.getTargetType(type)+")"+tokenPointer+"->value;"); - } else { - builder.pr(action.getName()+"->value = *("+types.getTargetType(type)+"*)"+tokenPointer+"->value;"); - } - builder.unindent(); - builder.pr("}"); + String.join( + "\n", + "for (int i = 0; i < " + reactorWidth + "; i++) {", + " " + + subName + + "[i]." + + outputName + + " = self->_lf_" + + subName + + "[i]." + + outputName + + ";", + "}")); + if (ASTUtils.isMultiport(output)) { + builder.pr( + String.join( + "\n", + "for (int i = 0; i < " + reactorWidth + "; i++) {", + " " + + subName + + "[i]." + + outputWidth + + " = self->_lf_" + + subName + + "[i]." + + outputWidth + + ";", + "}")); } - return builder.toString(); + } else { + // Output is not in a bank. + builder.pr(subName + "." + outputName + " = self->_lf_" + subName + "." + outputName + ";"); + if (ASTUtils.isMultiport(output)) { + builder.pr( + subName + "." + outputWidth + " = self->_lf_" + subName + "." + outputWidth + ";"); + } + } } + } - /** Generate into the specified string builder the code to - * initialize local variables for the specified input port - * in a reaction function from the "self" struct. - * @param input The input statement from the AST. - * @param tpr The reactor. - */ - private static String generateInputVariablesInReaction( - Input input, - TypeParameterizedReactor tpr, - CTypes types - ) { - String structType = CGenerator.variableStructType(input, tpr, false); - InferredType inputType = ASTUtils.getInferredType(input); - CodeBuilder builder = new CodeBuilder(); - String inputName = input.getName(); - String inputWidth = generateWidthVariable(inputName); + /** + * Generate action variables for a reaction. + * + * @param action The action. + */ + private static String generateActionVariablesInReaction( + Action action, TypeParameterizedReactor tpr, CTypes types) { + String structType = CGenerator.variableStructType(action, tpr, false); + // If the action has a type, create variables for accessing the value. + InferredType type = ASTUtils.getInferredType(action); + // Pointer to the lf_token_t sent as the payload in the trigger. + String tokenPointer = "(self->_lf__" + action.getName() + ".tmplt.token)"; + CodeBuilder builder = new CodeBuilder(); - // Create the local variable whose name matches the input name. - // If the input has not been declared mutable, then this is a pointer - // to the upstream output. Otherwise, it is a copy of the upstream output, - // which nevertheless points to the same token and value (hence, as done - // below, we have to use lf_writable_copy()). There are 8 cases, - // depending on whether the input is mutable, whether it is a multiport, - // and whether it is a token type. - // Easy case first. - if (!input.isMutable() && !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, primitive type. - builder.pr(structType+"* "+inputName+" = self->_lf_"+inputName+";"); - } else if (input.isMutable()&& !CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, primitive type. - builder.pr(String.join("\n", - "// Mutable input, so copy the input into a temporary variable.", - "// The input value on the struct is a copy.", - structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", - structType+"* "+inputName+" = &_lf_tmp_"+inputName+";" - )); - } else if (!input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, token type. - builder.pr(String.join("\n", - structType+"* "+inputName+" = self->_lf_"+inputName+";", - "if ("+inputName+"->is_present) {", - " "+inputName+"->length = "+inputName+"->token->length;", - " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", - "} else {", - " "+inputName+"->length = 0;", - "}" - )); - } else if (input.isMutable()&& CUtil.isTokenType(inputType, types) && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, token type. - builder.pr(String.join("\n", - "// Mutable input, so copy the input struct into a temporary variable.", - structType+" _lf_tmp_"+inputName+" = *(self->_lf_"+inputName+");", - structType+"* "+inputName+" = &_lf_tmp_"+inputName+";", - inputName+"->value = NULL;", // Prevent payload from being freed. - "if ("+inputName+"->is_present) {", - " "+inputName+"->length = "+inputName+"->token->length;", - " "+inputName+"->token = lf_writable_copy((lf_port_base_t*)self->_lf_"+inputName+");", - " "+inputName+"->value = ("+types.getTargetType(inputType)+")"+inputName+"->token->value;", - "} else {", - " "+inputName+"->length = 0;", - "}" - )); - } else if (!input.isMutable()&& ASTUtils.isMultiport(input)) { - // Non-mutable, multiport, primitive or token type. - builder.pr(structType+"** "+inputName+" = self->_lf_"+inputName+";"); - } else if (CUtil.isTokenType(inputType, types)) { - // Mutable, multiport, token type - builder.pr(String.join("\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", - " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", - " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", - " // If necessary, copy the tokens.", - " if ("+inputName+"[i]->is_present) {", - " "+inputName+"[i]->length = "+inputName+"[i]->token->length;", - " token_template_t* _lf_input = (token_template_t*)self->_lf_"+inputName+"[i];", - " "+inputName+"[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", - " "+inputName+"[i]->value = ("+types.getTargetType(inputType)+")"+inputName+"[i]->token->value;", - " } else {", - " "+inputName+"[i]->length = 0;", - " }", - "}" - )); - } else { - // Mutable, multiport, primitive type - builder.pr(String.join("\n", - "// Mutable multiport input, so copy the input structs", - "// into an array of temporary variables on the stack.", - structType+" _lf_tmp_"+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - structType+"* "+inputName+"["+CUtil.multiportWidthExpression(input)+"];", - "for (int i = 0; i < "+CUtil.multiportWidthExpression(input)+"; i++) {", - " "+inputName+"[i] = &_lf_tmp_"+inputName+"[i];", - " // Copy the struct, which includes the value.", - " _lf_tmp_"+inputName+"[i] = *(self->_lf_"+inputName+"[i]);", - "}" - )); - } - // Set the _width variable for all cases. This will be -1 - // for a variable-width multiport, which is not currently supported. - // It will be -2 if it is not multiport. - builder.pr("int "+inputWidth+" = self->_lf_"+inputWidth+"; SUPPRESS_UNUSED_WARNING("+inputWidth+");"); - return builder.toString(); + builder.pr( + String.join( + "\n", + "// Expose the action struct as a local variable whose name matches the action name.", + structType + "* " + action.getName() + " = &self->_lf_" + action.getName() + ";", + "// Set the fields of the action struct to match the current trigger.", + action.getName() + "->is_present = (bool)self->_lf__" + action.getName() + ".status;", + action.getName() + + "->has_value = (" + + tokenPointer + + " != NULL && " + + tokenPointer + + "->value != NULL);", + "_lf_replace_template_token((token_template_t*)" + + action.getName() + + ", " + + tokenPointer + + ");")); + // Set the value field only if there is a type. + if (!type.isUndefined()) { + // The value field will either be a copy (for primitive types) + // or a pointer (for types ending in *). + builder.pr("if (" + action.getName() + "->has_value) {"); + builder.indent(); + if (CUtil.isTokenType(type, types)) { + builder.pr( + action.getName() + + "->value = (" + + types.getTargetType(type) + + ")" + + tokenPointer + + "->value;"); + } else { + builder.pr( + action.getName() + + "->value = *(" + + types.getTargetType(type) + + "*)" + + tokenPointer + + "->value;"); + } + builder.unindent(); + builder.pr("}"); } + return builder.toString(); + } - /** - * Generate into the specified string builder the code to - * initialize local variables for outputs in a reaction function - * from the "self" struct. - * @param effect The effect declared by the reaction. This must refer to an output. - * @param tpr The reactor containing the reaction. - */ - public static String generateOutputVariablesInReaction( - VarRef effect, - TypeParameterizedReactor tpr, - ErrorReporter errorReporter, - boolean requiresTypes - ) { - Output output = (Output) effect.getVariable(); - String outputName = output.getName(); - String outputWidth = generateWidthVariable(outputName); - if (output.getType() == null && requiresTypes) { - errorReporter.reportError(output, "Output is required to have a type: " + outputName); - return ""; - } else { - // The container of the output may be a contained reactor or - // the reactor containing the reaction. - String outputStructType = (effect.getContainer() == null) ? - CGenerator.variableStructType(output, tpr, false) - : - CGenerator.variableStructType(output, new TypeParameterizedReactor(effect.getContainer()), false); - if (!ASTUtils.isMultiport(output)) { - // Output port is not a multiport. - return outputStructType+"* "+outputName+" = &self->_lf_"+outputName+";"; - } else { - // Output port is a multiport. - // Set the _width variable. - return String.join("\n", - "int "+outputWidth+" = self->_lf_"+outputWidth+"; SUPPRESS_UNUSED_WARNING("+outputWidth+");", - outputStructType+"** "+outputName+" = self->_lf_"+outputName+"_pointers;" - ); + /** + * Generate into the specified string builder the code to initialize local variables for the + * specified input port in a reaction function from the "self" struct. + * + * @param input The input statement from the AST. + * @param tpr The reactor. + */ + private static String generateInputVariablesInReaction( + Input input, TypeParameterizedReactor tpr, CTypes types) { + String structType = CGenerator.variableStructType(input, tpr, false); + InferredType inputType = ASTUtils.getInferredType(input); + CodeBuilder builder = new CodeBuilder(); + String inputName = input.getName(); + String inputWidth = generateWidthVariable(inputName); - } - } + // Create the local variable whose name matches the input name. + // If the input has not been declared mutable, then this is a pointer + // to the upstream output. Otherwise, it is a copy of the upstream output, + // which nevertheless points to the same token and value (hence, as done + // below, we have to use lf_writable_copy()). There are 8 cases, + // depending on whether the input is mutable, whether it is a multiport, + // and whether it is a token type. + // Easy case first. + if (!input.isMutable() + && !CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, primitive type. + builder.pr(structType + "* " + inputName + " = self->_lf_" + inputName + ";"); + } else if (input.isMutable() + && !CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, primitive type. + builder.pr( + String.join( + "\n", + "// Mutable input, so copy the input into a temporary variable.", + "// The input value on the struct is a copy.", + structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", + structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";")); + } else if (!input.isMutable() + && CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, token type. + builder.pr( + String.join( + "\n", + structType + "* " + inputName + " = self->_lf_" + inputName + ";", + "if (" + inputName + "->is_present) {", + " " + inputName + "->length = " + inputName + "->token->length;", + " " + + inputName + + "->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "->token->value;", + "} else {", + " " + inputName + "->length = 0;", + "}")); + } else if (input.isMutable() + && CUtil.isTokenType(inputType, types) + && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, token type. + builder.pr( + String.join( + "\n", + "// Mutable input, so copy the input struct into a temporary variable.", + structType + " _lf_tmp_" + inputName + " = *(self->_lf_" + inputName + ");", + structType + "* " + inputName + " = &_lf_tmp_" + inputName + ";", + inputName + "->value = NULL;", // Prevent payload from being freed. + "if (" + inputName + "->is_present) {", + " " + inputName + "->length = " + inputName + "->token->length;", + " " + + inputName + + "->token = lf_writable_copy((lf_port_base_t*)self->_lf_" + + inputName + + ");", + " " + + inputName + + "->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "->token->value;", + "} else {", + " " + inputName + "->length = 0;", + "}")); + } else if (!input.isMutable() && ASTUtils.isMultiport(input)) { + // Non-mutable, multiport, primitive or token type. + builder.pr(structType + "** " + inputName + " = self->_lf_" + inputName + ";"); + } else if (CUtil.isTokenType(inputType, types)) { + // Mutable, multiport, token type + builder.pr( + String.join( + "\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType + + " _lf_tmp_" + + inputName + + "[" + + CUtil.multiportWidthExpression(input) + + "];", + structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", + "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", + " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", + " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", + " // If necessary, copy the tokens.", + " if (" + inputName + "[i]->is_present) {", + " " + inputName + "[i]->length = " + inputName + "[i]->token->length;", + " token_template_t* _lf_input = (token_template_t*)self->_lf_" + + inputName + + "[i];", + " " + inputName + "[i]->token = lf_writable_copy((lf_port_base_t*)_lf_input);", + " " + + inputName + + "[i]->value = (" + + types.getTargetType(inputType) + + ")" + + inputName + + "[i]->token->value;", + " } else {", + " " + inputName + "[i]->length = 0;", + " }", + "}")); + } else { + // Mutable, multiport, primitive type + builder.pr( + String.join( + "\n", + "// Mutable multiport input, so copy the input structs", + "// into an array of temporary variables on the stack.", + structType + + " _lf_tmp_" + + inputName + + "[" + + CUtil.multiportWidthExpression(input) + + "];", + structType + "* " + inputName + "[" + CUtil.multiportWidthExpression(input) + "];", + "for (int i = 0; i < " + CUtil.multiportWidthExpression(input) + "; i++) {", + " " + inputName + "[i] = &_lf_tmp_" + inputName + "[i];", + " // Copy the struct, which includes the value.", + " _lf_tmp_" + inputName + "[i] = *(self->_lf_" + inputName + "[i]);", + "}")); } + // Set the _width variable for all cases. This will be -1 + // for a variable-width multiport, which is not currently supported. + // It will be -2 if it is not multiport. + builder.pr( + "int " + + inputWidth + + " = self->_lf_" + + inputWidth + + "; SUPPRESS_UNUSED_WARNING(" + + inputWidth + + ");"); + return builder.toString(); + } - /** - * Generate into the specified string builder the code to initialize local variables for watchdogs - * in a reaction function from the "self" struct. - * - * @param effect The effect declared by the reaction. This must refer to a watchdog. - */ - public static String generateWatchdogVariablesInReaction(VarRef effect) { - Watchdog watchdog = (Watchdog) effect.getVariable(); - String watchdogName = watchdog.getName(); + /** + * Generate into the specified string builder the code to initialize local variables for outputs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to an output. + * @param tpr The reactor containing the reaction. + */ + public static String generateOutputVariablesInReaction( + VarRef effect, + TypeParameterizedReactor tpr, + ErrorReporter errorReporter, + boolean requiresTypes) { + Output output = (Output) effect.getVariable(); + String outputName = output.getName(); + String outputWidth = generateWidthVariable(outputName); + if (output.getType() == null && requiresTypes) { + errorReporter.reportError(output, "Output is required to have a type: " + outputName); + return ""; + } else { + // The container of the output may be a contained reactor or + // the reactor containing the reaction. + String outputStructType = + (effect.getContainer() == null) + ? CGenerator.variableStructType(output, tpr, false) + : CGenerator.variableStructType( + output, new TypeParameterizedReactor(effect.getContainer()), false); + if (!ASTUtils.isMultiport(output)) { + // Output port is not a multiport. + return outputStructType + "* " + outputName + " = &self->_lf_" + outputName + ";"; + } else { + // Output port is a multiport. + // Set the _width variable. return String.join( "\n", - List.of("watchdog_t* " + watchdogName + " = &(self->_lf_watchdog_" + watchdogName + ");") - ); + "int " + + outputWidth + + " = self->_lf_" + + outputWidth + + "; SUPPRESS_UNUSED_WARNING(" + + outputWidth + + ");", + outputStructType + "** " + outputName + " = self->_lf_" + outputName + "_pointers;"); + } } + } - /** - * Generate the fields of the self struct and statements for the constructor - * to create and initialize a reaction_t struct for each reaction in the - * specified reactor and a trigger_t struct for each trigger (input, action, - * timer, or output of a contained reactor). - * @param body The place to put the code for the self struct. - * @param tpr {@link TypeParameterizedReactor} - * @param constructorCode The place to put the constructor code. - */ - public static void generateReactionAndTriggerStructs( - CodeBuilder body, - TypeParameterizedReactor tpr, - CodeBuilder constructorCode, - CTypes types - ) { - var reactionCount = 0; - // Iterate over reactions and create initialize the reaction_t struct - // on the self struct. Also, collect a map from triggers to the reactions - // that are triggered by that trigger. Also, collect a set of sources - // that are read by reactions but do not trigger reactions. - // Finally, collect a set of triggers and sources that are outputs - // of contained reactors. - var triggerMap = new LinkedHashMap>(); - var sourceSet = new LinkedHashSet(); - var outputsOfContainedReactors = new LinkedHashMap(); - var startupReactions = new LinkedHashSet(); - var shutdownReactions = new LinkedHashSet(); - var resetReactions = new LinkedHashSet(); - for (Reaction reaction : ASTUtils.allReactions(tpr.reactor())) { - // Create the reaction_t struct. - body.pr(reaction, "reaction_t _lf__reaction_"+reactionCount+";"); + /** + * Generate into the specified string builder the code to initialize local variables for watchdogs + * in a reaction function from the "self" struct. + * + * @param effect The effect declared by the reaction. This must refer to a watchdog. + */ + public static String generateWatchdogVariablesInReaction(VarRef effect) { + Watchdog watchdog = (Watchdog) effect.getVariable(); + String watchdogName = watchdog.getName(); + return String.join( + "\n", + List.of("watchdog_t* " + watchdogName + " = &(self->_lf_watchdog_" + watchdogName + ");")); + } - // Create the map of triggers to reactions. - for (TriggerRef trigger : reaction.getTriggers()) { - // trigger may not be a VarRef (it could be "startup" or "shutdown"). - if (trigger instanceof VarRef triggerAsVarRef) { - var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); - if (reactionList == null) { - reactionList = new LinkedList<>(); - triggerMap.put(triggerAsVarRef.getVariable(), reactionList); - } - reactionList.add(reactionCount); - if (triggerAsVarRef.getContainer() != null) { - outputsOfContainedReactors.put(triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); - } - } else if (trigger instanceof BuiltinTriggerRef) { - switch(((BuiltinTriggerRef) trigger).getType()) { - case STARTUP: - startupReactions.add(reactionCount); - break; - case SHUTDOWN: - shutdownReactions.add(reactionCount); - break; - case RESET: - resetReactions.add(reactionCount); - break; - } - } - } - // Create the set of sources read but not triggering. - for (VarRef source : reaction.getSources()) { - sourceSet.add(source.getVariable()); - if (source.getContainer() != null) { - outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); - } - } + /** + * Generate the fields of the self struct and statements for the constructor to create and + * initialize a reaction_t struct for each reaction in the specified reactor and a trigger_t + * struct for each trigger (input, action, timer, or output of a contained reactor). + * + * @param body The place to put the code for the self struct. + * @param tpr {@link TypeParameterizedReactor} + * @param constructorCode The place to put the constructor code. + */ + public static void generateReactionAndTriggerStructs( + CodeBuilder body, TypeParameterizedReactor tpr, CodeBuilder constructorCode, CTypes types) { + var reactionCount = 0; + // Iterate over reactions and create initialize the reaction_t struct + // on the self struct. Also, collect a map from triggers to the reactions + // that are triggered by that trigger. Also, collect a set of sources + // that are read by reactions but do not trigger reactions. + // Finally, collect a set of triggers and sources that are outputs + // of contained reactors. + var triggerMap = new LinkedHashMap>(); + var sourceSet = new LinkedHashSet(); + var outputsOfContainedReactors = new LinkedHashMap(); + var startupReactions = new LinkedHashSet(); + var shutdownReactions = new LinkedHashSet(); + var resetReactions = new LinkedHashSet(); + for (Reaction reaction : ASTUtils.allReactions(tpr.reactor())) { + // Create the reaction_t struct. + body.pr(reaction, "reaction_t _lf__reaction_" + reactionCount + ";"); - var deadlineFunctionPointer = "NULL"; - if (reaction.getDeadline() != null) { - // The following has to match the name chosen in generateReactions - var deadlineFunctionName = generateDeadlineFunctionName(tpr, reactionCount); - deadlineFunctionPointer = "&" + deadlineFunctionName; - } + // Create the map of triggers to reactions. + for (TriggerRef trigger : reaction.getTriggers()) { + // trigger may not be a VarRef (it could be "startup" or "shutdown"). + if (trigger instanceof VarRef triggerAsVarRef) { + var reactionList = triggerMap.get(triggerAsVarRef.getVariable()); + if (reactionList == null) { + reactionList = new LinkedList<>(); + triggerMap.put(triggerAsVarRef.getVariable(), reactionList); + } + reactionList.add(reactionCount); + if (triggerAsVarRef.getContainer() != null) { + outputsOfContainedReactors.put( + triggerAsVarRef.getVariable(), triggerAsVarRef.getContainer()); + } + } else if (trigger instanceof BuiltinTriggerRef) { + switch (((BuiltinTriggerRef) trigger).getType()) { + case STARTUP: + startupReactions.add(reactionCount); + break; + case SHUTDOWN: + shutdownReactions.add(reactionCount); + break; + case RESET: + resetReactions.add(reactionCount); + break; + } + } + } + // Create the set of sources read but not triggering. + for (VarRef source : reaction.getSources()) { + sourceSet.add(source.getVariable()); + if (source.getContainer() != null) { + outputsOfContainedReactors.put(source.getVariable(), source.getContainer()); + } + } - // Assign the STP handler - var STPFunctionPointer = "NULL"; - if (reaction.getStp() != null) { - // The following has to match the name chosen in generateReactions - var STPFunctionName = generateStpFunctionName(tpr, reactionCount); - STPFunctionPointer = "&" + STPFunctionName; - } + var deadlineFunctionPointer = "NULL"; + if (reaction.getDeadline() != null) { + // The following has to match the name chosen in generateReactions + var deadlineFunctionName = generateDeadlineFunctionName(tpr, reactionCount); + deadlineFunctionPointer = "&" + deadlineFunctionName; + } - // Set the defaults of the reaction_t struct in the constructor. - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__reaction_"+reactionCount+".index = 0; - // self->_lf__reaction_"+reactionCount+".chain_id = 0; - // self->_lf__reaction_"+reactionCount+".pos = 0; - // self->_lf__reaction_"+reactionCount+".status = inactive; - // self->_lf__reaction_"+reactionCount+".deadline = 0LL; - // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; - constructorCode.pr(reaction, String.join("\n", - "self->_lf__reaction_"+reactionCount+".number = "+reactionCount+";", - "self->_lf__reaction_"+reactionCount+".function = "+CReactionGenerator.generateReactionFunctionName(tpr, reactionCount)+";", - "self->_lf__reaction_"+reactionCount+".self = self;", - "self->_lf__reaction_"+reactionCount+".deadline_violation_handler = "+deadlineFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".STP_handler = "+STPFunctionPointer+";", - "self->_lf__reaction_"+reactionCount+".name = "+addDoubleQuotes("?")+";", - reaction.eContainer() instanceof Mode ? - "self->_lf__reaction_"+reactionCount+".mode = &self->_lf__modes["+tpr.reactor().getModes().indexOf((Mode) reaction.eContainer())+"];" : - "self->_lf__reaction_"+reactionCount+".mode = NULL;" - )); - // Increment the reactionCount even if the reaction is not in the federate - // so that reaction indices are consistent across federates. - reactionCount++; - } + // Assign the STP handler + var STPFunctionPointer = "NULL"; + if (reaction.getStp() != null) { + // The following has to match the name chosen in generateReactions + var STPFunctionName = generateStpFunctionName(tpr, reactionCount); + STPFunctionPointer = "&" + STPFunctionName; + } - // Next, create and initialize the trigger_t objects. - // Start with the timers. - for (Timer timer : ASTUtils.allTimers(tpr.reactor())) { - createTriggerT(body, timer, triggerMap, constructorCode, types); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - constructorCode.pr("self->_lf__"+timer.getName()+".is_timer = true;"); - constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+timer.getName()+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - } + // Set the defaults of the reaction_t struct in the constructor. + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__reaction_"+reactionCount+".index = 0; + // self->_lf__reaction_"+reactionCount+".chain_id = 0; + // self->_lf__reaction_"+reactionCount+".pos = 0; + // self->_lf__reaction_"+reactionCount+".status = inactive; + // self->_lf__reaction_"+reactionCount+".deadline = 0LL; + // self->_lf__reaction_"+reactionCount+".is_STP_violated = false; + constructorCode.pr( + reaction, + String.join( + "\n", + "self->_lf__reaction_" + reactionCount + ".number = " + reactionCount + ";", + "self->_lf__reaction_" + + reactionCount + + ".function = " + + CReactionGenerator.generateReactionFunctionName(tpr, reactionCount) + + ";", + "self->_lf__reaction_" + reactionCount + ".self = self;", + "self->_lf__reaction_" + + reactionCount + + ".deadline_violation_handler = " + + deadlineFunctionPointer + + ";", + "self->_lf__reaction_" + reactionCount + ".STP_handler = " + STPFunctionPointer + ";", + "self->_lf__reaction_" + reactionCount + ".name = " + addDoubleQuotes("?") + ";", + reaction.eContainer() instanceof Mode + ? "self->_lf__reaction_" + + reactionCount + + ".mode = &self->_lf__modes[" + + tpr.reactor().getModes().indexOf((Mode) reaction.eContainer()) + + "];" + : "self->_lf__reaction_" + reactionCount + ".mode = NULL;")); + // Increment the reactionCount even if the reaction is not in the federate + // so that reaction indices are consistent across federates. + reactionCount++; + } - // Handle builtin triggers. - if (startupReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); - } - // Handle shutdown triggers. - if (shutdownReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); - } - if (resetReactions.size() > 0) { - generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); - } + // Next, create and initialize the trigger_t objects. + // Start with the timers. + for (Timer timer : ASTUtils.allTimers(tpr.reactor())) { + createTriggerT(body, timer, triggerMap, constructorCode, types); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + constructorCode.pr("self->_lf__" + timer.getName() + ".is_timer = true;"); + constructorCode.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + + timer.getName() + + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + } - // Next handle actions. - for (Action action : ASTUtils.allActions(tpr.reactor())) { - createTriggerT(body, action, triggerMap, constructorCode, types); - var isPhysical = "true"; - if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { - isPhysical = "false"; - } - var elementSize = "0"; - // If the action type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) - : null; - if (rootType != null && !rootType.equals("void")) { - elementSize = "sizeof(" + rootType + ")"; - } + // Handle builtin triggers. + if (startupReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(startupReactions, "startup", body, constructorCode); + } + // Handle shutdown triggers. + if (shutdownReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(shutdownReactions, "shutdown", body, constructorCode); + } + if (resetReactions.size() > 0) { + generateBuiltinTriggeredReactionsArray(resetReactions, "reset", body, constructorCode); + } - // Since the self struct is allocated using calloc, there is no need to set: - // self->_lf__"+action.getName()+".is_timer = false; - constructorCode.pr(String.join("\n", - "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", - !(action.getPolicy() == null || action.getPolicy().isEmpty()) ? - "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" : - "", - // Need to set the element_size in the trigger_t and the action struct. - "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize - + ";", - "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";" - )); - } + // Next handle actions. + for (Action action : ASTUtils.allActions(tpr.reactor())) { + createTriggerT(body, action, triggerMap, constructorCode, types); + var isPhysical = "true"; + if (action.getOrigin().equals(ActionOrigin.LOGICAL)) { + isPhysical = "false"; + } + var elementSize = "0"; + // If the action type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var rootType = action.getType() != null ? CUtil.rootType(types.getTargetType(action)) : null; + if (rootType != null && !rootType.equals("void")) { + elementSize = "sizeof(" + rootType + ")"; + } - // Next handle inputs. - for (Input input : ASTUtils.allInputs(tpr.reactor())) { - createTriggerT(body, input, triggerMap, constructorCode, types); - } + // Since the self struct is allocated using calloc, there is no need to set: + // self->_lf__"+action.getName()+".is_timer = false; + constructorCode.pr( + String.join( + "\n", + "self->_lf__" + action.getName() + ".is_physical = " + isPhysical + ";", + !(action.getPolicy() == null || action.getPolicy().isEmpty()) + ? "self->_lf__" + action.getName() + ".policy = " + action.getPolicy() + ";" + : "", + // Need to set the element_size in the trigger_t and the action struct. + "self->_lf__" + action.getName() + ".tmplt.type.element_size = " + elementSize + ";", + "self->_lf_" + action.getName() + ".type.element_size = " + elementSize + ";")); + } - // Next handle watchdogs. - for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.reactor())) { - createTriggerT(body, watchdog, triggerMap, constructorCode, types); - } + // Next handle inputs. + for (Input input : ASTUtils.allInputs(tpr.reactor())) { + createTriggerT(body, input, triggerMap, constructorCode, types); } - /** - * Define the trigger_t object on the self struct, an array of - * reaction_t pointers pointing to reactions triggered by this variable, - * and initialize the pointers in the array in the constructor. - * @param body The place to write the self struct entries. - * @param variable The trigger variable (Timer, Action, Watchdog, or Input). - * @param triggerMap A map from Variables to a list of the reaction indices triggered by the - * variable. - * @param constructorCode The place to write the constructor code. - */ - private static void createTriggerT( - CodeBuilder body, - Variable variable, - LinkedHashMap> triggerMap, - CodeBuilder constructorCode, - CTypes types - ) { - var varName = variable.getName(); - // variable is a port, a timer, or an action. - body.pr(variable, "trigger_t _lf__"+varName+";"); - constructorCode.pr(variable, "self->_lf__"+varName+".last = NULL;"); - constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+varName+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + // Next handle watchdogs. + for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.reactor())) { + createTriggerT(body, watchdog, triggerMap, constructorCode, types); + } + } - // Generate the reactions triggered table. - var reactionsTriggered = triggerMap.get(variable); - if (reactionsTriggered != null) { - body.pr(variable, "reaction_t* _lf__"+varName+"_reactions["+reactionsTriggered.size()+"];"); - var count = 0; - for (Integer reactionTriggered : reactionsTriggered) { - constructorCode.prSourceLineNumber(variable); - constructorCode.pr(variable, "self->_lf__"+varName+"_reactions["+count+"] = &self->_lf__reaction_"+reactionTriggered+";"); - count++; - } - // Set up the trigger_t struct's pointer to the reactions. - constructorCode.pr(variable, String.join("\n", - "self->_lf__"+varName+".reactions = &self->_lf__"+varName+"_reactions[0];", - "self->_lf__"+varName+".number_of_reactions = "+count+";" - )); + /** + * Define the trigger_t object on the self struct, an array of reaction_t pointers pointing to + * reactions triggered by this variable, and initialize the pointers in the array in the + * constructor. + * + * @param body The place to write the self struct entries. + * @param variable The trigger variable (Timer, Action, Watchdog, or Input). + * @param triggerMap A map from Variables to a list of the reaction indices triggered by the + * variable. + * @param constructorCode The place to write the constructor code. + */ + private static void createTriggerT( + CodeBuilder body, + Variable variable, + LinkedHashMap> triggerMap, + CodeBuilder constructorCode, + CTypes types) { + var varName = variable.getName(); + // variable is a port, a timer, or an action. + body.pr(variable, "trigger_t _lf__" + varName + ";"); + constructorCode.pr(variable, "self->_lf__" + varName + ".last = NULL;"); + constructorCode.pr( + variable, + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + + varName + + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - // If federated, set the physical_time_of_arrival - constructorCode.pr(variable, CExtensionUtils.surroundWithIfFederated( - "self->_lf__"+varName+".physical_time_of_arrival = NEVER;")); - } - if (variable instanceof Input) { - var rootType = CUtil.rootType(types.getTargetType((Input) variable)); - // Since the self struct is allocated using calloc, there is no need to set falsy fields. - // If the input type is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; + // Generate the reactions triggered table. + var reactionsTriggered = triggerMap.get(variable); + if (reactionsTriggered != null) { + body.pr( + variable, + "reaction_t* _lf__" + varName + "_reactions[" + reactionsTriggered.size() + "];"); + var count = 0; + for (Integer reactionTriggered : reactionsTriggered) { + constructorCode.prSourceLineNumber(variable); + constructorCode.pr( + variable, + "self->_lf__" + + varName + + "_reactions[" + + count + + "] = &self->_lf__reaction_" + + reactionTriggered + + ";"); + count++; + } + // Set up the trigger_t struct's pointer to the reactions. + constructorCode.pr( + variable, + String.join( + "\n", + "self->_lf__" + varName + ".reactions = &self->_lf__" + varName + "_reactions[0];", + "self->_lf__" + varName + ".number_of_reactions = " + count + ";")); - constructorCode.pr("self->_lf__"+varName+".tmplt.type.element_size = "+size+";"); - body.pr( - CExtensionUtils.surroundWithIfFederated( - CExtensionUtils.createPortStatusFieldForInput((Input) variable) - ) - ); - } + // If federated, set the physical_time_of_arrival + constructorCode.pr( + variable, + CExtensionUtils.surroundWithIfFederated( + "self->_lf__" + varName + ".physical_time_of_arrival = NEVER;")); } + if (variable instanceof Input) { + var rootType = CUtil.rootType(types.getTargetType((Input) variable)); + // Since the self struct is allocated using calloc, there is no need to set falsy fields. + // If the input type is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; - public static void generateBuiltinTriggeredReactionsArray( - Set reactions, - String name, - CodeBuilder body, - CodeBuilder constructorCode - ) { - body.pr(String.join("\n", - "trigger_t _lf__"+name+";", - "reaction_t* _lf__"+name+"_reactions["+reactions.size()+"];" - )); - constructorCode.pr(CExtensionUtils.surroundWithIfFederatedDecentralized( - "self->_lf__"+name+".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); - var i = 0; - for (Integer reactionIndex : reactions) { - constructorCode.pr("self->_lf__"+name+"_reactions["+i+++"] = &self->_lf__reaction_"+reactionIndex+";"); - } - constructorCode.pr(String.join("\n", - "self->_lf__"+name+".last = NULL;", - "self->_lf__"+name+".reactions = &self->_lf__"+name+"_reactions[0];", - "self->_lf__"+name+".number_of_reactions = "+reactions.size()+";", - "self->_lf__"+name+".is_timer = false;" - )); + constructorCode.pr("self->_lf__" + varName + ".tmplt.type.element_size = " + size + ";"); + body.pr( + CExtensionUtils.surroundWithIfFederated( + CExtensionUtils.createPortStatusFieldForInput((Input) variable))); } + } - public static String generateBuiltinTriggersTable(int reactionCount, String name) { - return String.join("\n", List.of( - "// Array of pointers to "+name+" triggers.", - (reactionCount > 0 ? - "reaction_t* _lf_"+name+"_reactions["+reactionCount+"]" : - "reaction_t** _lf_"+name+"_reactions = NULL") + ";", - "int _lf_"+name+"_reactions_size = "+reactionCount+";" - )); + public static void generateBuiltinTriggeredReactionsArray( + Set reactions, String name, CodeBuilder body, CodeBuilder constructorCode) { + body.pr( + String.join( + "\n", + "trigger_t _lf__" + name + ";", + "reaction_t* _lf__" + name + "_reactions[" + reactions.size() + "];")); + constructorCode.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "self->_lf__" + name + ".intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + var i = 0; + for (Integer reactionIndex : reactions) { + constructorCode.pr( + "self->_lf__" + + name + + "_reactions[" + + i++ + + "] = &self->_lf__reaction_" + + reactionIndex + + ";"); } + constructorCode.pr( + String.join( + "\n", + "self->_lf__" + name + ".last = NULL;", + "self->_lf__" + name + ".reactions = &self->_lf__" + name + "_reactions[0];", + "self->_lf__" + name + ".number_of_reactions = " + reactions.size() + ";", + "self->_lf__" + name + ".is_timer = false;")); + } - /** - * Generate the _lf_trigger_startup_reactions function. - */ - public static String generateLfTriggerStartupReactions(int startupReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("void _lf_trigger_startup_reactions() {"); - if (startupReactionCount > 0) { - s.append("\n"); - if (hasModalReactors) { - s.append(String.join("\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " if (_lf_startup_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_startup_reset_reactions(", - " _lf_startup_reactions, _lf_startup_reactions_size,", - " NULL, 0,", - " _lf_modal_reactor_states, _lf_modal_reactor_states_size);" - )); - } else { - s.append(String.join("\n", - " for (int i = 0; i < _lf_startup_reactions_size; i++) {", - " if (_lf_startup_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", - " }", - " }" - )); - } - s.append("\n"); - } - s.append("}\n"); - return s.toString(); + public static String generateBuiltinTriggersTable(int reactionCount, String name) { + return String.join( + "\n", + List.of( + "// Array of pointers to " + name + " triggers.", + (reactionCount > 0 + ? "reaction_t* _lf_" + name + "_reactions[" + reactionCount + "]" + : "reaction_t** _lf_" + name + "_reactions = NULL") + + ";", + "int _lf_" + name + "_reactions_size = " + reactionCount + ";")); + } + + /** Generate the _lf_trigger_startup_reactions function. */ + public static String generateLfTriggerStartupReactions( + int startupReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("void _lf_trigger_startup_reactions() {"); + if (startupReactionCount > 0) { + s.append("\n"); + if (hasModalReactors) { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " if (_lf_startup_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_startup_reset_reactions(", + " _lf_startup_reactions, _lf_startup_reactions_size,", + " NULL, 0,", + " _lf_modal_reactor_states, _lf_modal_reactor_states_size);")); + } else { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_startup_reactions_size; i++) {", + " if (_lf_startup_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_startup_reactions[i], -1);", + " }", + " }")); + } + s.append("\n"); } + s.append("}\n"); + return s.toString(); + } - /** - * Generate the _lf_trigger_shutdown_reactions function. - */ - public static String generateLfTriggerShutdownReactions(int shutdownReactionCount, boolean hasModalReactors) { - var s = new StringBuilder(); - s.append("bool _lf_trigger_shutdown_reactions() {\n"); - if (shutdownReactionCount > 0) { - if (hasModalReactors) { - s.append(String.join("\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " if (_lf_shutdown_reactions[i]->mode != NULL) {", - " // Skip reactions in modes", - " continue;", - " }", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions, _lf_shutdown_reactions_size);", - " return true;" - )); - } else { - s.append(String.join("\n", - " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", - " if (_lf_shutdown_reactions[i] != NULL) {", - " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", - " }", - " }", - " return true;" - )); - } - s.append("\n"); - } else { - s.append(" return false;\n"); - } - s.append("}\n"); - return s.toString(); + /** Generate the _lf_trigger_shutdown_reactions function. */ + public static String generateLfTriggerShutdownReactions( + int shutdownReactionCount, boolean hasModalReactors) { + var s = new StringBuilder(); + s.append("bool _lf_trigger_shutdown_reactions() {\n"); + if (shutdownReactionCount > 0) { + if (hasModalReactors) { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " if (_lf_shutdown_reactions[i]->mode != NULL) {", + " // Skip reactions in modes", + " continue;", + " }", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " _lf_handle_mode_shutdown_reactions(_lf_shutdown_reactions," + + " _lf_shutdown_reactions_size);", + " return true;")); + } else { + s.append( + String.join( + "\n", + " for (int i = 0; i < _lf_shutdown_reactions_size; i++) {", + " if (_lf_shutdown_reactions[i] != NULL) {", + " _lf_trigger_reaction(_lf_shutdown_reactions[i], -1);", + " }", + " }", + " return true;")); + } + s.append("\n"); + } else { + s.append(" return false;\n"); } + s.append("}\n"); + return s.toString(); + } - /** - * Generate the _lf_handle_mode_triggered_reactions function. - */ - public static String generateLfModeTriggeredReactions( - int startupReactionCount, - int resetReactionCount, - boolean hasModalReactors - ) { - if (!hasModalReactors) { - return ""; - } - var s = new StringBuilder(); - s.append("void _lf_handle_mode_triggered_reactions() {\n"); - s.append(" _lf_handle_mode_startup_reset_reactions(\n"); - if (startupReactionCount > 0) { - s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - if (resetReactionCount > 0) { - s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); - } else { - s.append(" NULL, 0,\n"); - } - s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); - s.append("}\n"); - return s.toString(); + /** Generate the _lf_handle_mode_triggered_reactions function. */ + public static String generateLfModeTriggeredReactions( + int startupReactionCount, int resetReactionCount, boolean hasModalReactors) { + if (!hasModalReactors) { + return ""; + } + var s = new StringBuilder(); + s.append("void _lf_handle_mode_triggered_reactions() {\n"); + s.append(" _lf_handle_mode_startup_reset_reactions(\n"); + if (startupReactionCount > 0) { + s.append(" _lf_startup_reactions, _lf_startup_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); } + if (resetReactionCount > 0) { + s.append(" _lf_reset_reactions, _lf_reset_reactions_size,\n"); + } else { + s.append(" NULL, 0,\n"); + } + s.append(" _lf_modal_reactor_states, _lf_modal_reactor_states_size);\n"); + s.append("}\n"); + return s.toString(); + } - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param tpr The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - public static String generateReaction( - Reaction reaction, - TypeParameterizedReactor tpr, - int reactionIndex, - Instantiation mainDef, - ErrorReporter errorReporter, - CTypes types, - TargetConfig targetConfig, - boolean requiresType - ) { - var code = new CodeBuilder(); - var body = ASTUtils.toText(getCode(types, reaction, tpr)); - String init = generateInitializationForReaction( - body, reaction, tpr, reactionIndex, - types, errorReporter, mainDef, - requiresType); + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param tpr The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + public static String generateReaction( + Reaction reaction, + TypeParameterizedReactor tpr, + int reactionIndex, + Instantiation mainDef, + ErrorReporter errorReporter, + CTypes types, + TargetConfig targetConfig, + boolean requiresType) { + var code = new CodeBuilder(); + var body = ASTUtils.toText(getCode(types, reaction, tpr)); + String init = + generateInitializationForReaction( + body, reaction, tpr, reactionIndex, types, errorReporter, mainDef, requiresType); - code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetHeader())); + code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetHeader())); - CMethodGenerator.generateMacrosForMethods(tpr, code); - code.pr(generateFunction( + CMethodGenerator.generateMacrosForMethods(tpr, code); + code.pr( + generateFunction( generateReactionFunctionHeader(tpr, reactionIndex), - init, getCode(types, reaction, tpr) - )); - // Now generate code for the late function, if there is one - // Note that this function can only be defined on reactions - // in federates that have inputs from a logical connection. - if (reaction.getStp() != null) { - code.pr(generateFunction( - generateStpFunctionHeader(tpr, reactionIndex), - init, reaction.getStp().getCode())); - } - - // Now generate code for the deadline violation function, if there is one. - if (reaction.getDeadline() != null) { - code.pr(generateFunction( - generateDeadlineFunctionHeader(tpr, reactionIndex), - init, reaction.getDeadline().getCode())); - } - CMethodGenerator.generateMacroUndefsForMethods(tpr.reactor(), code); - code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetUndefHeader())); - return code.toString(); + init, + getCode(types, reaction, tpr))); + // Now generate code for the late function, if there is one + // Note that this function can only be defined on reactions + // in federates that have inputs from a logical connection. + if (reaction.getStp() != null) { + code.pr( + generateFunction( + generateStpFunctionHeader(tpr, reactionIndex), init, reaction.getStp().getCode())); } - private static Code getCode(CTypes types, Reaction r, TypeParameterizedReactor tpr) { - if (r.getCode() != null) return r.getCode(); - Code ret = LfFactory.eINSTANCE.createCode(); - ret.setBody( - CReactorHeaderFileGenerator.nonInlineInitialization(r, tpr) + "\n" - + r.getName() + "( " + CReactorHeaderFileGenerator.reactionArguments(r, tpr) + " );"); - return ret; + // Now generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr( + generateFunction( + generateDeadlineFunctionHeader(tpr, reactionIndex), + init, + reaction.getDeadline().getCode())); } + CMethodGenerator.generateMacroUndefsForMethods(tpr.reactor(), code); + code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetUndefHeader())); + return code.toString(); + } - public static String generateFunction(String header, String init, Code code) { - var function = new CodeBuilder(); - function.pr(header + " {"); - function.indent(); - function.pr(init); - function.prSourceLineNumber(code); - function.pr(ASTUtils.toText(code)); - function.unindent(); - function.pr("}"); - return function.toString(); - } + private static Code getCode(CTypes types, Reaction r, TypeParameterizedReactor tpr) { + if (r.getCode() != null) return r.getCode(); + Code ret = LfFactory.eINSTANCE.createCode(); + ret.setBody( + CReactorHeaderFileGenerator.nonInlineInitialization(r, tpr) + + "\n" + + r.getName() + + "( " + + CReactorHeaderFileGenerator.reactionArguments(r, tpr) + + " );"); + return ret; + } - /** - * Returns the name of the deadline function for reaction. - * @param tpr The reactor with the deadline - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateDeadlineFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { - return CUtil.getName(tpr).toLowerCase() + "_deadline_function" + reactionIndex; - } + public static String generateFunction(String header, String init, Code code) { + var function = new CodeBuilder(); + function.pr(header + " {"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(code); + function.pr(ASTUtils.toText(code)); + function.unindent(); + function.pr("}"); + return function.toString(); + } - /** - * Return the function name for specified reaction of the - * specified reactor. - * @param tpr The reactor - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { - return CUtil.getName(tpr).toLowerCase() + "reaction_function_" + reactionIndex; - } + /** + * Returns the name of the deadline function for reaction. + * + * @param tpr The reactor with the deadline + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateDeadlineFunctionName( + TypeParameterizedReactor tpr, int reactionIndex) { + return CUtil.getName(tpr).toLowerCase() + "_deadline_function" + reactionIndex; + } - /** - * Returns the name of the stp function for reaction. - * @param tpr The reactor with the stp - * @param reactionIndex The number assigned to this reaction deadline - */ - public static String generateStpFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { - return CUtil.getName(tpr).toLowerCase() + "_STP_function" + reactionIndex; - } + /** + * Return the function name for specified reaction of the specified reactor. + * + * @param tpr The reactor + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionName( + TypeParameterizedReactor tpr, int reactionIndex) { + return CUtil.getName(tpr).toLowerCase() + "reaction_function_" + reactionIndex; + } - /** Return the top level C function header for the deadline function numbered "reactionIndex" in "r" - * @param tpr The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the deadline function. - */ - public static String generateDeadlineFunctionHeader(TypeParameterizedReactor tpr, - int reactionIndex) { - String functionName = generateDeadlineFunctionName(tpr, reactionIndex); - return generateFunctionHeader(functionName); - } + /** + * Returns the name of the stp function for reaction. + * + * @param tpr The reactor with the stp + * @param reactionIndex The number assigned to this reaction deadline + */ + public static String generateStpFunctionName(TypeParameterizedReactor tpr, int reactionIndex) { + return CUtil.getName(tpr).toLowerCase() + "_STP_function" + reactionIndex; + } - /** Return the top level C function header for the reaction numbered "reactionIndex" in "r" - * @param tpr The reactor declaration - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateReactionFunctionHeader(TypeParameterizedReactor tpr, - int reactionIndex) { - String functionName = generateReactionFunctionName(tpr, reactionIndex); - return generateFunctionHeader(functionName); - } + /** + * Return the top level C function header for the deadline function numbered "reactionIndex" in + * "r" + * + * @param tpr The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the deadline function. + */ + public static String generateDeadlineFunctionHeader( + TypeParameterizedReactor tpr, int reactionIndex) { + String functionName = generateDeadlineFunctionName(tpr, reactionIndex); + return generateFunctionHeader(functionName); + } - public static String generateStpFunctionHeader(TypeParameterizedReactor tpr, - int reactionIndex) { - String functionName = generateStpFunctionName(tpr, reactionIndex); - return generateFunctionHeader(functionName); - } + /** + * Return the top level C function header for the reaction numbered "reactionIndex" in "r" + * + * @param tpr The reactor declaration + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateReactionFunctionHeader( + TypeParameterizedReactor tpr, int reactionIndex) { + String functionName = generateReactionFunctionName(tpr, reactionIndex); + return generateFunctionHeader(functionName); + } - /** - * Return the start of a function declaration for a function that takes - * a {@code void*} argument and returns void. - * - * @param functionName - * @return - */ - public static String generateFunctionHeader(String functionName) { - return "void " + functionName + "(void* instance_args)"; - } + public static String generateStpFunctionHeader(TypeParameterizedReactor tpr, int reactionIndex) { + String functionName = generateStpFunctionName(tpr, reactionIndex); + return generateFunctionHeader(functionName); + } + + /** + * Return the start of a function declaration for a function that takes a {@code void*} argument + * and returns void. + * + * @param functionName + * @return + */ + public static String generateFunctionHeader(String functionName) { + return "void " + functionName + "(void* instance_args)"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 993168cad9..4f6a29b405 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -6,7 +6,6 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Instantiation; @@ -23,44 +22,61 @@ /** Generate user-visible header files. */ public class CReactorHeaderFileGenerator { - /** Functional interface for generating auxiliary structs such as port structs. */ - public interface GenerateAuxiliaryStructs { - void generate(CodeBuilder b, TypeParameterizedReactor r, boolean userFacing); - } - - /** Return the path to the user-visible header file that would be generated for {@code r}. */ - public static Path outputPath(TypeParameterizedReactor tpr) { - return Path.of(Path.of(tpr.reactor().eResource().getURI().toFileString()) - .getFileName().toString().replaceFirst("[.][^.]+$", "")) - .resolve(tpr.getName() + ".h"); - } - - public static void doGenerate(CTypes types, TypeParameterizedReactor tpr, CFileConfig fileConfig, GenerateAuxiliaryStructs generator, Function topLevelPreamble) throws IOException { - String contents = generateHeaderFile(types, tpr, generator, topLevelPreamble.apply(tpr.reactor())); - FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(tpr))); - } - private static String generateHeaderFile(CTypes types, TypeParameterizedReactor tpr, GenerateAuxiliaryStructs generator, String topLevelPreamble) { - CodeBuilder builder = new CodeBuilder(); - appendIncludeGuard(builder, tpr); - builder.pr(topLevelPreamble); - appendPoundIncludes(builder); - tpr.doDefines(builder); - appendSelfStruct(builder, types, tpr); - generator.generate(builder, tpr, true); - for (Reaction reaction : tpr.reactor().getReactions()) { - appendSignature(builder, types, reaction, tpr); - } - builder.pr("#endif"); - return builder.getCode(); - } - - private static void appendIncludeGuard(CodeBuilder builder, TypeParameterizedReactor r) { - String macro = CUtil.getName(r) + "_H"; - builder.pr("#ifndef " + macro); - builder.pr("#define " + macro); - } - private static void appendPoundIncludes(CodeBuilder builder) { - builder.pr(""" + /** Functional interface for generating auxiliary structs such as port structs. */ + public interface GenerateAuxiliaryStructs { + void generate(CodeBuilder b, TypeParameterizedReactor r, boolean userFacing); + } + + /** Return the path to the user-visible header file that would be generated for {@code r}. */ + public static Path outputPath(TypeParameterizedReactor tpr) { + return Path.of( + Path.of(tpr.reactor().eResource().getURI().toFileString()) + .getFileName() + .toString() + .replaceFirst("[.][^.]+$", "")) + .resolve(tpr.getName() + ".h"); + } + + public static void doGenerate( + CTypes types, + TypeParameterizedReactor tpr, + CFileConfig fileConfig, + GenerateAuxiliaryStructs generator, + Function topLevelPreamble) + throws IOException { + String contents = + generateHeaderFile(types, tpr, generator, topLevelPreamble.apply(tpr.reactor())); + FileUtil.writeToFile(contents, fileConfig.getIncludePath().resolve(outputPath(tpr))); + } + + private static String generateHeaderFile( + CTypes types, + TypeParameterizedReactor tpr, + GenerateAuxiliaryStructs generator, + String topLevelPreamble) { + CodeBuilder builder = new CodeBuilder(); + appendIncludeGuard(builder, tpr); + builder.pr(topLevelPreamble); + appendPoundIncludes(builder); + tpr.doDefines(builder); + appendSelfStruct(builder, types, tpr); + generator.generate(builder, tpr, true); + for (Reaction reaction : tpr.reactor().getReactions()) { + appendSignature(builder, types, reaction, tpr); + } + builder.pr("#endif"); + return builder.getCode(); + } + + private static void appendIncludeGuard(CodeBuilder builder, TypeParameterizedReactor r) { + String macro = CUtil.getName(r) + "_H"; + builder.pr("#ifndef " + macro); + builder.pr("#define " + macro); + } + + private static void appendPoundIncludes(CodeBuilder builder) { + builder.pr( + """ #ifdef __cplusplus extern "C" { #endif @@ -71,135 +87,167 @@ private static void appendPoundIncludes(CodeBuilder builder) { } #endif """); - } - - private static String userFacingSelfType(TypeParameterizedReactor tpr) { - return tpr.getName().toLowerCase() + "_self_t"; - } - - private static void appendSelfStruct(CodeBuilder builder, CTypes types, TypeParameterizedReactor tpr) { - builder.pr("typedef struct " + userFacingSelfType(tpr) + "{"); - for (Parameter p : tpr.reactor().getParameters()) { - builder.pr(types.getTargetType(p) + " " + p.getName() + ";"); - } - for (StateVar s : tpr.reactor().getStateVars()) { - builder.pr(types.getTargetType(s) + " " + s.getName() + ";"); - } - builder.pr("int end[0]; // placeholder; MSVC does not compile empty structs"); - builder.pr("} " + userFacingSelfType(tpr) + ";"); - } - - private static void appendSignature(CodeBuilder builder, CTypes types, Reaction r, TypeParameterizedReactor tpr) { - if (r.getName() != null) builder.pr("void " + r.getName() + "(" + reactionParameters(r, tpr) + ");"); - } - - private static String reactionParameters(Reaction r, TypeParameterizedReactor tpr) { - return Stream.concat(Stream.of(userFacingSelfType(tpr) + "* self"), portVariableStream(r, tpr) - .map(tv -> tv.getType(true) + tv.getName())) - .collect(Collectors.joining(", ")); - } - - private static String getApiSelfStruct(TypeParameterizedReactor tpr) { - return "(" + userFacingSelfType(tpr) + "*) (((char*) self) + sizeof(self_base_t))"; - } - - /** Generate initialization code that is needed if {@code r} is not inlined. */ - public static String nonInlineInitialization(Reaction r, TypeParameterizedReactor reactor) { - var mainDef = LfFactory.eINSTANCE.createInstantiation(); - mainDef.setName(reactor.getName()); - mainDef.setReactorClass(ASTUtils.findMainReactor(reactor.reactor().eResource())); - return portVariableStream(r, reactor) - .map(it -> it.container == null ? "" : it.getWidth() == null ? - String.format("%s %s = (%s) %s;", it.getType(false), it.getAlias(), it.getType(false), it.getRvalue()) - : String.format(""" + } + + private static String userFacingSelfType(TypeParameterizedReactor tpr) { + return tpr.getName().toLowerCase() + "_self_t"; + } + + private static void appendSelfStruct( + CodeBuilder builder, CTypes types, TypeParameterizedReactor tpr) { + builder.pr("typedef struct " + userFacingSelfType(tpr) + "{"); + for (Parameter p : tpr.reactor().getParameters()) { + builder.pr(types.getTargetType(p) + " " + p.getName() + ";"); + } + for (StateVar s : tpr.reactor().getStateVars()) { + builder.pr(types.getTargetType(s) + " " + s.getName() + ";"); + } + builder.pr("int end[0]; // placeholder; MSVC does not compile empty structs"); + builder.pr("} " + userFacingSelfType(tpr) + ";"); + } + + private static void appendSignature( + CodeBuilder builder, CTypes types, Reaction r, TypeParameterizedReactor tpr) { + if (r.getName() != null) + builder.pr("void " + r.getName() + "(" + reactionParameters(r, tpr) + ");"); + } + + private static String reactionParameters(Reaction r, TypeParameterizedReactor tpr) { + return Stream.concat( + Stream.of(userFacingSelfType(tpr) + "* self"), + portVariableStream(r, tpr).map(tv -> tv.getType(true) + tv.getName())) + .collect(Collectors.joining(", ")); + } + + private static String getApiSelfStruct(TypeParameterizedReactor tpr) { + return "(" + userFacingSelfType(tpr) + "*) (((char*) self) + sizeof(self_base_t))"; + } + + /** Generate initialization code that is needed if {@code r} is not inlined. */ + public static String nonInlineInitialization(Reaction r, TypeParameterizedReactor reactor) { + var mainDef = LfFactory.eINSTANCE.createInstantiation(); + mainDef.setName(reactor.getName()); + mainDef.setReactorClass(ASTUtils.findMainReactor(reactor.reactor().eResource())); + return portVariableStream(r, reactor) + .map( + it -> + it.container == null + ? "" + : it.getWidth() == null + ? String.format( + "%s %s = (%s) %s;", + 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; } """, - it.getType(true).replaceFirst("\\*", ""), - it.getAlias(), - CReactionGenerator.maxContainedReactorBankWidth( - reactor.reactor().getInstantiations().stream() - .filter(instantiation -> new TypeParameterizedReactor(instantiation).equals(it.r)) - .findAny().orElseThrow(), - null, 0, mainDef), - "self->_lf_"+it.container.getName()+"_width", - it.getAlias(), - it.getType(true).replaceFirst("\\*", ""), - it.container.getName(), - it.getName())) - .collect(Collectors.joining("\n")); - } - - /** Return a string representation of the arguments passed to the function for {@code r}. */ - public static String reactionArguments(Reaction r, TypeParameterizedReactor reactor) { - return Stream.concat(Stream.of(getApiSelfStruct(reactor)), portVariableStream(r, reactor) + it.getType(true).replaceFirst("\\*", ""), + it.getAlias(), + CReactionGenerator.maxContainedReactorBankWidth( + reactor.reactor().getInstantiations().stream() + .filter( + instantiation -> + new TypeParameterizedReactor(instantiation) + .equals(it.r)) + .findAny() + .orElseThrow(), + null, + 0, + mainDef), + "self->_lf_" + it.container.getName() + "_width", + it.getAlias(), + it.getType(true).replaceFirst("\\*", ""), + it.container.getName(), + it.getName())) + .collect(Collectors.joining("\n")); + } + + /** Return a string representation of the arguments passed to the function for {@code r}. */ + public static String reactionArguments(Reaction r, TypeParameterizedReactor reactor) { + return Stream.concat( + Stream.of(getApiSelfStruct(reactor)), + portVariableStream(r, reactor) .map(it -> String.format("((%s) %s)", it.getType(true), it.getAlias()))) - .collect(Collectors.joining(", ")); - } - - /** Return a stream of all ports referenced by the signature of {@code r}. */ - private static Stream portVariableStream(Reaction r, TypeParameterizedReactor reactorOfReaction) { - return varRefStream(r) - .map(it -> it.getVariable() instanceof TypedVariable tv ? - new PortVariable( - tv, - it.getContainer() != null ? new TypeParameterizedReactor(it.getContainer()) : reactorOfReaction, - it.getContainer()) - : null) - .filter(Objects::nonNull); - } - - /** - * A variable that refers to a port. - * @param tv The variable of the variable reference. - * @param r The reactor in which the port is being used. - * @param container The {@code Instantiation} referenced in the obtaining of {@code tv}, if - * applicable; {@code null} otherwise. - */ - private record PortVariable(TypedVariable tv, TypeParameterizedReactor r, Instantiation container) { - String getType(boolean userFacing) { - var typeName = container == null ? - CGenerator.variableStructType(tv, r, userFacing) - : CPortGenerator.localPortName(container.getReactorClass(), getName()); - var isMultiport = ASTUtils.isMultiport(ASTUtils.allPorts(r.reactor()).stream() - .filter(it -> it.getName().equals(tv.getName())) - .findAny().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(); - } - } - - private static Stream inputVarRefStream(Reaction reaction) { - return varRefStream(Stream.concat(reaction.getTriggers().stream(), reaction.getSources().stream())); - } - - private static Stream varRefStream(Stream toFilter) { - return toFilter.map(it -> it instanceof VarRef v ? v : null) - .filter(Objects::nonNull); - } - - private static Stream outputVarRefStream(Reaction reaction) { - return reaction.getEffects().stream(); - } - - private static Stream varRefStream(Reaction reaction) { - return Stream.concat(inputVarRefStream(reaction), outputVarRefStream(reaction)); - } + .collect(Collectors.joining(", ")); + } + + /** Return a stream of all ports referenced by the signature of {@code r}. */ + private static Stream portVariableStream( + Reaction r, TypeParameterizedReactor reactorOfReaction) { + return varRefStream(r) + .map( + it -> + it.getVariable() instanceof TypedVariable tv + ? new PortVariable( + tv, + it.getContainer() != null + ? new TypeParameterizedReactor(it.getContainer()) + : reactorOfReaction, + it.getContainer()) + : null) + .filter(Objects::nonNull); + } + + /** + * A variable that refers to a port. + * + * @param tv The variable of the variable reference. + * @param r The reactor in which the port is being used. + * @param container The {@code Instantiation} referenced in the obtaining of {@code tv}, if + * applicable; {@code null} otherwise. + */ + private record PortVariable( + TypedVariable tv, TypeParameterizedReactor r, Instantiation container) { + String getType(boolean userFacing) { + var typeName = + container == null + ? CGenerator.variableStructType(tv, r, userFacing) + : CPortGenerator.localPortName(container.getReactorClass(), getName()); + var isMultiport = + ASTUtils.isMultiport( + ASTUtils.allPorts(r.reactor()).stream() + .filter(it -> it.getName().equals(tv.getName())) + .findAny() + .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(); + } + } + + private static Stream inputVarRefStream(Reaction reaction) { + return varRefStream( + Stream.concat(reaction.getTriggers().stream(), reaction.getSources().stream())); + } + + private static Stream varRefStream(Stream toFilter) { + return toFilter.map(it -> it instanceof VarRef v ? v : null).filter(Objects::nonNull); + } + + private static Stream outputVarRefStream(Reaction reaction) { + return reaction.getEffects().stream(); + } + + private static Stream varRefStream(Reaction reaction) { + return Stream.concat(inputVarRefStream(reaction), outputVarRefStream(reaction)); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index f43d975632..69e41d1008 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -7,121 +7,116 @@ import org.lflang.lf.StateVar; public class CStateGenerator { - /** - * Generate code for state variables of a reactor in the form "stateVar.type stateVar.name;" - * @param reactor {@link TypeParameterizedReactor} - * @param types A helper object for types - */ - public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { - CodeBuilder code = new CodeBuilder(); - for (StateVar stateVar : ASTUtils.allStateVars(reactor.reactor())) { - code.prSourceLineNumber(stateVar); - code.pr(types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(stateVar))) + " " + stateVar.getName() + ";"); - } - return code.toString(); + /** + * Generate code for state variables of a reactor in the form "stateVar.type stateVar.name;" + * + * @param reactor {@link TypeParameterizedReactor} + * @param types A helper object for types + */ + public static String generateDeclarations(TypeParameterizedReactor reactor, CTypes types) { + CodeBuilder code = new CodeBuilder(); + for (StateVar stateVar : ASTUtils.allStateVars(reactor.reactor())) { + code.prSourceLineNumber(stateVar); + code.pr( + types.getTargetType(reactor.resolveType(ASTUtils.getInferredType(stateVar))) + + " " + + stateVar.getName() + + ";"); } + return code.toString(); + } - /** - * If the state is initialized with a parameter, then do not use - * a temporary variable. Otherwise, do, because - * static initializers for arrays and structs have to be handled - * this way, and there is no way to tell whether the type of the array - * is a struct. - * - * @param instance {@link ReactorInstance} - * @param stateVar {@link StateVar} - * @param mode {@link ModeInstance} - * @return String - */ - public static String generateInitializer( - ReactorInstance instance, - String selfRef, - StateVar stateVar, - ModeInstance mode, - CTypes types - ) { - var initExpr = getInitializerExpr(stateVar, instance); - String baseInitializer = generateBaseInitializer(instance.tpr, selfRef, stateVar, initExpr, types); - String modalReset = generateModalReset(instance, selfRef, stateVar, initExpr, mode, types); - return String.join("\n", - baseInitializer, - modalReset - ); - } + /** + * If the state is initialized with a parameter, then do not use a temporary variable. Otherwise, + * do, because static initializers for arrays and structs have to be handled this way, and there + * is no way to tell whether the type of the array is a struct. + * + * @param instance {@link ReactorInstance} + * @param stateVar {@link StateVar} + * @param mode {@link ModeInstance} + * @return String + */ + public static String generateInitializer( + ReactorInstance instance, + String selfRef, + StateVar stateVar, + ModeInstance mode, + CTypes types) { + var initExpr = getInitializerExpr(stateVar, instance); + String baseInitializer = + generateBaseInitializer(instance.tpr, selfRef, stateVar, initExpr, types); + String modalReset = generateModalReset(instance, selfRef, stateVar, initExpr, mode, types); + return String.join("\n", baseInitializer, modalReset); + } - private static String generateBaseInitializer( - TypeParameterizedReactor tpr, - String selfRef, - StateVar stateVar, - String initExpr, - CTypes types - ) { - if (ASTUtils.isOfTimeType(stateVar) || - ASTUtils.isParameterized(stateVar) && - !stateVar.getInit().getExprs().isEmpty() - ) { - return selfRef + "->" + stateVar.getName() + " = " + initExpr + ";"; - } else { - var declaration = types.getVariableDeclaration(tpr, - ASTUtils.getInferredType(stateVar), - "_initial", true); - return String.join("\n", - "{ // For scoping", - " static "+declaration+" = "+initExpr+";", - " "+selfRef+"->"+stateVar.getName()+" = _initial;", - "} // End scoping." - ); - } + private static String generateBaseInitializer( + TypeParameterizedReactor tpr, + String selfRef, + StateVar stateVar, + String initExpr, + CTypes types) { + if (ASTUtils.isOfTimeType(stateVar) + || ASTUtils.isParameterized(stateVar) && !stateVar.getInit().getExprs().isEmpty()) { + return selfRef + "->" + stateVar.getName() + " = " + initExpr + ";"; + } else { + var declaration = + types.getVariableDeclaration(tpr, ASTUtils.getInferredType(stateVar), "_initial", true); + return String.join( + "\n", + "{ // For scoping", + " static " + declaration + " = " + initExpr + ";", + " " + selfRef + "->" + stateVar.getName() + " = _initial;", + "} // End scoping."); } + } - private static String generateModalReset( - ReactorInstance instance, - String selfRef, - StateVar stateVar, - String initExpr, - ModeInstance mode, - CTypes types - ) { - if (mode == null || !stateVar.isReset()) { - return ""; - } - var modeRef = "&"+CUtil.reactorRef(mode.getParent())+"->_lf__modes["+mode.getParent().modes.indexOf(mode)+"]"; - var type = types.getTargetType(instance.tpr.resolveType(ASTUtils.getInferredType(stateVar))); - - if (ASTUtils.isOfTimeType(stateVar) || - ASTUtils.isParameterized(stateVar) && - !stateVar.getInit().getExprs().isEmpty()) { - return CModesGenerator.generateStateResetStructure( - modeRef, selfRef, - stateVar.getName(), - initExpr, type); - } else { - CodeBuilder code = new CodeBuilder(); - var source = "_initial"; - var declaration = types.getVariableDeclaration(instance.tpr, - ASTUtils.getInferredType(stateVar), - source, true); - code.pr("{ // For scoping"); - code.indent(); - code.pr("static "+declaration+" = "+initExpr+";"); - code.pr(CModesGenerator.generateStateResetStructure( - modeRef, selfRef, - stateVar.getName(), - source, type)); - code.unindent(); - code.pr("} // End scoping."); - return code.toString(); - } + private static String generateModalReset( + ReactorInstance instance, + String selfRef, + StateVar stateVar, + String initExpr, + ModeInstance mode, + CTypes types) { + if (mode == null || !stateVar.isReset()) { + return ""; } + var modeRef = + "&" + + CUtil.reactorRef(mode.getParent()) + + "->_lf__modes[" + + mode.getParent().modes.indexOf(mode) + + "]"; + var type = types.getTargetType(instance.tpr.resolveType(ASTUtils.getInferredType(stateVar))); - /** - * Return a C expression that can be used to initialize the specified - * state variable within the specified parent. If the state variable - * initializer refers to parameters of the parent, then those parameter - * references are replaced with accesses to the self struct of the parent. - */ - private static String getInitializerExpr(StateVar state, ReactorInstance parent) { - var ctypes = CTypes.generateParametersIn(parent); - return ctypes.getTargetInitializer(state.getInit(), state.getType()); + if (ASTUtils.isOfTimeType(stateVar) + || ASTUtils.isParameterized(stateVar) && !stateVar.getInit().getExprs().isEmpty()) { + return CModesGenerator.generateStateResetStructure( + modeRef, selfRef, stateVar.getName(), initExpr, type); + } else { + CodeBuilder code = new CodeBuilder(); + var source = "_initial"; + var declaration = + types.getVariableDeclaration( + instance.tpr, ASTUtils.getInferredType(stateVar), source, true); + code.pr("{ // For scoping"); + code.indent(); + code.pr("static " + declaration + " = " + initExpr + ";"); + code.pr( + CModesGenerator.generateStateResetStructure( + modeRef, selfRef, stateVar.getName(), source, type)); + code.unindent(); + code.pr("} // End scoping."); + return code.toString(); } + } + + /** + * Return a C expression that can be used to initialize the specified state variable within the + * specified parent. If the state variable initializer refers to parameters of the parent, then + * those parameter references are replaced with accesses to the self struct of the parent. + */ + private static String getInitializerExpr(StateVar state, ReactorInstance parent) { + var ctypes = CTypes.generateParametersIn(parent); + return ctypes.getTargetInitializer(state.getInit(), state.getType()); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java index 57e7556dfe..f0c55389f6 100644 --- a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java @@ -1,7 +1,6 @@ package org.lflang.generator.c; import java.util.List; - import org.lflang.generator.TimerInstance; /** @@ -11,61 +10,71 @@ * @author {Soroush Bateni */ public class CTimerGenerator { - /** - * Generate code to initialize the given timer. - * - * @param timer The timer to initialize for. - */ - public static String generateInitializer(TimerInstance timer) { - var triggerStructName = CUtil.reactorRef(timer.getParent()) + "->_lf__" + timer.getName(); - var offset = CTypes.getInstance().getTargetTimeExpr(timer.getOffset()); - var period = CTypes.getInstance().getTargetTimeExpr(timer.getPeriod()); - var mode = timer.getMode(false); - var modeRef = mode != null ? - "&"+CUtil.reactorRef(mode.getParent())+"->_lf__modes["+mode.getParent().modes.indexOf(mode)+"];" : - "NULL"; + /** + * Generate code to initialize the given timer. + * + * @param timer The timer to initialize for. + */ + public static String generateInitializer(TimerInstance timer) { + var triggerStructName = CUtil.reactorRef(timer.getParent()) + "->_lf__" + timer.getName(); + var offset = CTypes.getInstance().getTargetTimeExpr(timer.getOffset()); + var period = CTypes.getInstance().getTargetTimeExpr(timer.getPeriod()); + var mode = timer.getMode(false); + var modeRef = + mode != null + ? "&" + + CUtil.reactorRef(mode.getParent()) + + "->_lf__modes[" + + mode.getParent().modes.indexOf(mode) + + "];" + : "NULL"; - return String.join("\n", List.of( - "// Initializing timer "+timer.getFullName()+".", - triggerStructName+".offset = "+offset+";", - triggerStructName+".period = "+period+";", - "_lf_timer_triggers[_lf_timer_triggers_count++] = &"+triggerStructName+";", - triggerStructName+".mode = "+modeRef+";" - )); - } + return String.join( + "\n", + List.of( + "// Initializing timer " + timer.getFullName() + ".", + triggerStructName + ".offset = " + offset + ";", + triggerStructName + ".period = " + period + ";", + "_lf_timer_triggers[_lf_timer_triggers_count++] = &" + triggerStructName + ";", + triggerStructName + ".mode = " + modeRef + ";")); + } - /** - * Generate code to declare the timer table. - * - * @param timerCount The total number of timers in the program - */ - public static String generateDeclarations(int timerCount) { - return String.join("\n", List.of( - "// Array of pointers to timer triggers to be scheduled in _lf_initialize_timers().", - (timerCount > 0 ? - "trigger_t* _lf_timer_triggers["+timerCount+"]" : - "trigger_t** _lf_timer_triggers = NULL") + ";", - "int _lf_timer_triggers_size = "+timerCount+";" - )); - } + /** + * Generate code to declare the timer table. + * + * @param timerCount The total number of timers in the program + */ + public static String generateDeclarations(int timerCount) { + return String.join( + "\n", + List.of( + "// Array of pointers to timer triggers to be scheduled in _lf_initialize_timers().", + (timerCount > 0 + ? "trigger_t* _lf_timer_triggers[" + timerCount + "]" + : "trigger_t** _lf_timer_triggers = NULL") + + ";", + "int _lf_timer_triggers_size = " + timerCount + ";")); + } - /** - * Generate code to call {@code _lf_initialize_timer} on each timer. - * - * @param timerCount The total number of timers in the program - */ - public static String generateLfInitializeTimer(int timerCount) { - return String.join("\n", - "void _lf_initialize_timers() {", - timerCount > 0 ? - """ + /** + * Generate code to call {@code _lf_initialize_timer} on each timer. + * + * @param timerCount The total number of timers in the program + */ + public static String generateLfInitializeTimer(int timerCount) { + return String.join( + "\n", + "void _lf_initialize_timers() {", + timerCount > 0 + ? """ for (int i = 0; i < _lf_timer_triggers_size; i++) { if (_lf_timer_triggers[i] != NULL) { _lf_initialize_timer(_lf_timer_triggers[i]); } - }""".indent(4).stripTrailing() : - "", - "}" - ); - } + }""" + .indent(4) + .stripTrailing() + : "", + "}"); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CTracingGenerator.java b/org.lflang/src/org/lflang/generator/c/CTracingGenerator.java index f999d14b3e..8439d562b0 100644 --- a/org.lflang/src/org/lflang/generator/c/CTracingGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTracingGenerator.java @@ -1,13 +1,12 @@ package org.lflang.generator.c; +import static org.lflang.util.StringUtil.addDoubleQuotes; + import java.util.ArrayList; import java.util.List; - -import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.ActionInstance; import org.lflang.generator.ReactorInstance; import org.lflang.generator.TimerInstance; -import static org.lflang.util.StringUtil.addDoubleQuotes; /** * Generates C code to support tracing. @@ -17,47 +16,54 @@ * @author Hou Seng Wong */ public class CTracingGenerator { - /** - * If tracing is turned on, then generate code that records - * the full name of the specified reactor instance in the - * trace table. If tracing is not turned on, do nothing. - * - * If tracing is turned on, record the address of this reaction - * in the _lf_trace_object_descriptions table that is used to generate - * the header information in the trace file. - * - * @param instance The reactor instance. - */ - public static String generateTraceTableEntries( - ReactorInstance instance - ) { - List code = new ArrayList<>(); - var description = CUtil.getShortenedName(instance); - var selfStruct = CUtil.reactorRef(instance); - code.add(registerTraceEvent( - selfStruct, "NULL", - "trace_reactor", description) - ); - for (ActionInstance action : instance.actions) { - code.add(registerTraceEvent( - selfStruct, getTrigger(selfStruct, action.getName()), - "trace_trigger", description + "." + action.getName()) - ); - } - for (TimerInstance timer : instance.timers) { - code.add(registerTraceEvent( - selfStruct, getTrigger(selfStruct, timer.getName()), - "trace_trigger", description + "." + timer.getName()) - ); - } - return String.join("\n", code); + /** + * If tracing is turned on, then generate code that records the full name of the specified reactor + * instance in the trace table. If tracing is not turned on, do nothing. + * + *

    If tracing is turned on, record the address of this reaction in the + * _lf_trace_object_descriptions table that is used to generate the header information in the + * trace file. + * + * @param instance The reactor instance. + */ + public static String generateTraceTableEntries(ReactorInstance instance) { + List code = new ArrayList<>(); + var description = CUtil.getShortenedName(instance); + var selfStruct = CUtil.reactorRef(instance); + code.add(registerTraceEvent(selfStruct, "NULL", "trace_reactor", description)); + for (ActionInstance action : instance.actions) { + code.add( + registerTraceEvent( + selfStruct, + getTrigger(selfStruct, action.getName()), + "trace_trigger", + description + "." + action.getName())); } - - private static String registerTraceEvent(String obj, String trigger, String type, String description) { - return "_lf_register_trace_event("+obj+", "+trigger+", "+type+", "+addDoubleQuotes(description)+");"; + for (TimerInstance timer : instance.timers) { + code.add( + registerTraceEvent( + selfStruct, + getTrigger(selfStruct, timer.getName()), + "trace_trigger", + description + "." + timer.getName())); } + return String.join("\n", code); + } - private static String getTrigger(String obj, String triggerName) { - return "&("+obj+"->_lf__"+triggerName+")"; - } + private static String registerTraceEvent( + String obj, String trigger, String type, String description) { + return "_lf_register_trace_event(" + + obj + + ", " + + trigger + + ", " + + type + + ", " + + addDoubleQuotes(description) + + ");"; + } + + private static String getTrigger(String obj, String triggerName) { + return "&(" + obj + "->_lf__" + triggerName + ")"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index 99df04e9d3..5f4d8d60ef 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -1,4 +1,5 @@ package org.lflang.generator.c; + import static org.lflang.generator.c.CMixedRadixGenerator.db; import static org.lflang.generator.c.CMixedRadixGenerator.dc; import static org.lflang.generator.c.CMixedRadixGenerator.dr; @@ -8,15 +9,14 @@ import static org.lflang.util.StringUtil.addDoubleQuotes; import static org.lflang.util.StringUtil.joinObjects; +import com.google.common.collect.Iterables; import java.util.Arrays; import java.util.HashSet; import java.util.stream.Collectors; - -import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.TargetConfig; - import org.lflang.TargetProperty.LogLevel; +import org.lflang.ast.ASTUtils; import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.PortInstance; @@ -25,8 +25,6 @@ import org.lflang.generator.RuntimeRange; import org.lflang.generator.SendRange; -import com.google.common.collect.Iterables; - /** * Generate code for the "_lf_initialize_trigger_objects" function * @@ -35,1027 +33,1088 @@ * @author Hou Seng Wong */ public class CTriggerObjectsGenerator { - /** - * Generate the _lf_initialize_trigger_objects function for 'federate'. - */ - public static String generateInitializeTriggerObjects( - ReactorInstance main, - TargetConfig targetConfig, - CodeBuilder initializeTriggerObjects, - CodeBuilder startTimeStep, - CTypes types, - String lfModuleName, - int startTimeStepIsPresentCount - ) { - var code = new CodeBuilder(); - code.pr("void _lf_initialize_trigger_objects() {"); - code.indent(); - // Initialize the LF clock. - code.pr(String.join("\n", - "// Initialize the _lf_clock", - "lf_initialize_clock();" - )); - - // Initialize tracing if it is enabled - if (targetConfig.tracing != null) { - var traceFileName = lfModuleName; - if (targetConfig.tracing.traceFileName != null) { - traceFileName = targetConfig.tracing.traceFileName; - } - code.pr(String.join("\n", - "// Initialize tracing", - "start_trace("+ addDoubleQuotes(traceFileName + ".lft") + ");" - )); // .lft is for Lingua Franca trace - } + /** Generate the _lf_initialize_trigger_objects function for 'federate'. */ + public static String generateInitializeTriggerObjects( + ReactorInstance main, + TargetConfig targetConfig, + CodeBuilder initializeTriggerObjects, + CodeBuilder startTimeStep, + CTypes types, + String lfModuleName, + int startTimeStepIsPresentCount) { + var code = new CodeBuilder(); + code.pr("void _lf_initialize_trigger_objects() {"); + code.indent(); + // Initialize the LF clock. + code.pr(String.join("\n", "// Initialize the _lf_clock", "lf_initialize_clock();")); + + // Initialize tracing if it is enabled + if (targetConfig.tracing != null) { + var traceFileName = lfModuleName; + if (targetConfig.tracing.traceFileName != null) { + traceFileName = targetConfig.tracing.traceFileName; + } + code.pr( + String.join( + "\n", + "// Initialize tracing", + "start_trace(" + + addDoubleQuotes(traceFileName + ".lft") + + ");")); // .lft is for Lingua Franca trace + } - // Create the table to initialize is_present fields to false between time steps. - if (startTimeStepIsPresentCount > 0) { - // Allocate the initial (before mutations) array of pointers to _is_present fields. - code.pr(String.join("\n", - "// Create the array that will contain pointers to is_present fields to reset on each step.", - "_lf_is_present_fields_size = "+startTimeStepIsPresentCount+";", - "_lf_is_present_fields = (bool**)calloc("+startTimeStepIsPresentCount+", sizeof(bool*));", - "if (_lf_is_present_fields == NULL) lf_print_error_and_exit(" + addDoubleQuotes("Out of memory!") + ");", - "_lf_is_present_fields_abbreviated = (bool**)calloc("+startTimeStepIsPresentCount+", sizeof(bool*));", - "if (_lf_is_present_fields_abbreviated == NULL) lf_print_error_and_exit(" + addDoubleQuotes("Out of memory!") + ");", - "_lf_is_present_fields_abbreviated_size = 0;" - )); - } + // Create the table to initialize is_present fields to false between time steps. + if (startTimeStepIsPresentCount > 0) { + // Allocate the initial (before mutations) array of pointers to _is_present fields. + code.pr( + String.join( + "\n", + "// Create the array that will contain pointers to is_present fields to reset on each" + + " step.", + "_lf_is_present_fields_size = " + startTimeStepIsPresentCount + ";", + "_lf_is_present_fields = (bool**)calloc(" + + startTimeStepIsPresentCount + + ", sizeof(bool*));", + "if (_lf_is_present_fields == NULL) lf_print_error_and_exit(" + + addDoubleQuotes("Out of memory!") + + ");", + "_lf_is_present_fields_abbreviated = (bool**)calloc(" + + startTimeStepIsPresentCount + + ", sizeof(bool*));", + "if (_lf_is_present_fields_abbreviated == NULL) lf_print_error_and_exit(" + + addDoubleQuotes("Out of memory!") + + ");", + "_lf_is_present_fields_abbreviated_size = 0;")); + } - // Create the table to initialize intended tag fields to 0 between time - // steps. - if (startTimeStepIsPresentCount > 0) { - // Allocate the initial (before mutations) array of pointers to - // intended_tag fields. - // There is a 1-1 map between structs containing is_present and - // intended_tag fields, - // thus, we reuse startTimeStepIsPresentCount as the counter. - code.pr(String.join("\n", - CExtensionUtils.surroundWithIfFederatedDecentralized(""" + // Create the table to initialize intended tag fields to 0 between time + // steps. + if (startTimeStepIsPresentCount > 0) { + // Allocate the initial (before mutations) array of pointers to + // intended_tag fields. + // There is a 1-1 map between structs containing is_present and + // intended_tag fields, + // thus, we reuse startTimeStepIsPresentCount as the counter. + code.pr( + String.join( + "\n", + CExtensionUtils.surroundWithIfFederatedDecentralized( + """ // Create the array that will contain pointers to intended_tag fields to reset on each step. _lf_intended_tag_fields_size = %s; _lf_intended_tag_fields = (tag_t**)malloc(_lf_intended_tag_fields_size * sizeof(tag_t*)); - """.formatted(startTimeStepIsPresentCount) - ) - )); - } - + """ + .formatted(startTimeStepIsPresentCount)))); + } - code.pr(initializeTriggerObjects.toString()); - - code.pr(deferredInitialize( - main, - main.reactions, - targetConfig, - types - )); - code.pr(deferredInitializeNonNested( - main, - main, - main.reactions, - types - )); - // Next, for every input port, populate its "self" struct - // fields with pointers to the output port that sends it data. - code.pr(deferredConnectInputsToOutputs( - main - )); - // Put the code here to set up the tables that drive resetting is_present and - // decrementing reference counts between time steps. This code has to appear - // in _lf_initialize_trigger_objects() after the code that makes connections - // between inputs and outputs. - code.pr(startTimeStep.toString()); - code.pr(setReactionPriorities( - main - )); - code.pr(generateSchedulerInitializer( - main, - targetConfig - )); - - code.pr(""" + code.pr(initializeTriggerObjects.toString()); + + code.pr(deferredInitialize(main, main.reactions, targetConfig, types)); + code.pr(deferredInitializeNonNested(main, main, main.reactions, types)); + // Next, for every input port, populate its "self" struct + // fields with pointers to the output port that sends it data. + code.pr(deferredConnectInputsToOutputs(main)); + // Put the code here to set up the tables that drive resetting is_present and + // decrementing reference counts between time steps. This code has to appear + // in _lf_initialize_trigger_objects() after the code that makes connections + // between inputs and outputs. + code.pr(startTimeStep.toString()); + code.pr(setReactionPriorities(main)); + code.pr(generateSchedulerInitializer(main, targetConfig)); + + code.pr( + """ #ifdef EXECUTABLE_PREAMBLE _lf_executable_preamble(); #endif """); - // Initialize triggers for federated execution. - code.pr(CExtensionUtils.surroundWithIfFederated("initialize_triggers_for_federate();")); + // Initialize triggers for federated execution. + code.pr(CExtensionUtils.surroundWithIfFederated("initialize_triggers_for_federate();")); - code.unindent(); - code.pr("}\n"); - return code.toString(); - } + code.unindent(); + code.pr("}\n"); + return code.toString(); + } - /** - * Generate code to initialize the scheduler for the threaded C runtime. - */ - public static String generateSchedulerInitializer( - ReactorInstance main, - TargetConfig targetConfig - ) { - if (!targetConfig.threading) { - return ""; - } - var code = new CodeBuilder(); - var numReactionsPerLevel = main.assignLevels().getNumReactionsPerLevel(); - var numReactionsPerLevelJoined = Arrays.stream(numReactionsPerLevel) - .map(String::valueOf) - .collect(Collectors.joining(", ")); - code.pr(String.join("\n", + /** Generate code to initialize the scheduler for the threaded C runtime. */ + public static String generateSchedulerInitializer( + ReactorInstance main, TargetConfig targetConfig) { + if (!targetConfig.threading) { + return ""; + } + var code = new CodeBuilder(); + var numReactionsPerLevel = main.assignLevels().getNumReactionsPerLevel(); + var numReactionsPerLevelJoined = + Arrays.stream(numReactionsPerLevel).map(String::valueOf).collect(Collectors.joining(", ")); + code.pr( + String.join( + "\n", "// Initialize the scheduler", - "size_t num_reactions_per_level["+numReactionsPerLevel.length+"] = ", + "size_t num_reactions_per_level[" + numReactionsPerLevel.length + "] = ", " {" + numReactionsPerLevelJoined + "};", "sched_params_t sched_params = (sched_params_t) {", " .num_reactions_per_level = &num_reactions_per_level[0],", - " .num_reactions_per_level_size = (size_t) "+numReactionsPerLevel.length+"};", + " .num_reactions_per_level_size = (size_t) " + + numReactionsPerLevel.length + + "};", "lf_sched_init(", " (size_t)_lf_number_of_workers,", " &sched_params", - ");" - )); - return code.toString(); + ");")); + return code.toString(); + } + + /** + * Set the reaction priorities based on dependency analysis. + * + * @param reactor The reactor on which to do this. + */ + private static String setReactionPriorities(ReactorInstance reactor) { + var code = new CodeBuilder(); + setReactionPriorities(reactor, code); + return code.toString(); + } + + /** + * Set the reaction priorities based on dependency analysis. + * + * @param reactor The reactor on which to do this. + * @param builder Where to write the code. + */ + private static boolean setReactionPriorities(ReactorInstance reactor, CodeBuilder builder) { + var foundOne = false; + // Force calculation of levels if it has not been done. + // FIXME: Comment out this as I think it is redundant. + // If it is NOT redundant then deadline propagation is not correct + // reactor.assignLevels(); + + // We handle four different scenarios + // 1) A reactionInstance has 1 level and 1 deadline + // 2) A reactionInstance has 1 level but multiple deadlines + // 3) A reaction instance has multiple levels but all have the same deadline + // 4) Multiple deadlines and levels + + var prolog = new CodeBuilder(); + var epilog = new CodeBuilder(); + + for (ReactionInstance r : reactor.reactions) { + var levelSet = r.getLevels(); + var deadlineSet = r.getInferredDeadlines(); + + if (levelSet.size() > 1 || deadlineSet.size() > 1) { + // Scenario 2-4 + if (prolog.length() == 0) { + prolog.startScopedBlock(); + epilog.endScopedBlock(); + } + } + if (deadlineSet.size() > 1) { + // Scenario (2) or (4) + var deadlines = + r.getInferredDeadlinesList().stream() + .map(elt -> ("0x" + Long.toString(elt.toNanoSeconds(), 16) + "LL")) + .collect(Collectors.toList()); + + prolog.pr( + "interval_t " + + r.uniqueID() + + "_inferred_deadlines[] = { " + + joinObjects(deadlines, ", ") + + " };"); + } + + if (levelSet.size() > 1) { + // Scenario (3) or (4) + // Cannot use the above set of levels because it is a set, not a list. + prolog.pr( + "int " + + r.uniqueID() + + "_levels[] = { " + + joinObjects(r.getLevelsList(), ", ") + + " };"); + } } - /** - * Set the reaction priorities based on dependency analysis. - * - * @param reactor The reactor on which to do this. - */ - private static String setReactionPriorities( - ReactorInstance reactor - ) { - var code = new CodeBuilder(); - setReactionPriorities(reactor, code); - return code.toString(); + var temp = new CodeBuilder(); + temp.pr("// Set reaction priorities for " + reactor); + temp.startScopedBlock(reactor); + for (ReactionInstance r : reactor.reactions) { + // if (currentFederate.contains(r.getDefinition())) { + foundOne = true; + var levelSet = r.getLevels(); + var deadlineSet = r.getInferredDeadlines(); + + // Get the head of the associated lists. To avoid duplication in + // several of the following cases + var level = r.getLevelsList().get(0); + var inferredDeadline = r.getInferredDeadlinesList().get(0); + var runtimeIdx = CUtil.runtimeIndex(r.getParent()); + + if (levelSet.size() == 1 && deadlineSet.size() == 1) { + // Scenario (1) + + var indexValue = inferredDeadline.toNanoSeconds() << 16 | level; + + var reactionIndex = "0x" + Long.toUnsignedString(indexValue, 16) + "LL"; + + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of level " + level + " and ", + "// deadline " + inferredDeadline.toNanoSeconds() + " shifted left 16 bits.", + CUtil.reactionRef(r) + ".index = " + reactionIndex + ";")); + } else if (levelSet.size() == 1 && deadlineSet.size() > 1) { + // Scenario 2 + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of levels[" + runtimeIdx + "] and ", + "// deadlines[" + runtimeIdx + "] shifted left 16 bits.", + CUtil.reactionRef(r) + + ".index = (" + + r.uniqueID() + + "_inferred_deadlines[" + + runtimeIdx + + "] << 16) | " + + level + + ";")); + + } else if (levelSet.size() > 1 && deadlineSet.size() == 1) { + // Scenarion (3) + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of levels[" + runtimeIdx + "] and ", + "// deadlines[" + runtimeIdx + "] shifted left 16 bits.", + CUtil.reactionRef(r) + + ".index = (" + + inferredDeadline.toNanoSeconds() + + " << 16) | " + + r.uniqueID() + + "_levels[" + + runtimeIdx + + "];")); + + } else if (levelSet.size() > 1 && deadlineSet.size() > 1) { + // Scenario (4) + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of levels[" + runtimeIdx + "] and ", + "// deadlines[" + runtimeIdx + "] shifted left 16 bits.", + CUtil.reactionRef(r) + + ".index = (" + + r.uniqueID() + + "_inferred_deadlines[" + + runtimeIdx + + "] << 16) | " + + r.uniqueID() + + "_levels[" + + runtimeIdx + + "];")); + } } - - /** - * Set the reaction priorities based on dependency analysis. - * - * @param reactor The reactor on which to do this. - * @param builder Where to write the code. - */ - private static boolean setReactionPriorities( - ReactorInstance reactor, - CodeBuilder builder - ) { - var foundOne = false; - // Force calculation of levels if it has not been done. - // FIXME: Comment out this as I think it is redundant. - // If it is NOT redundant then deadline propagation is not correct - // reactor.assignLevels(); - - // We handle four different scenarios - // 1) A reactionInstance has 1 level and 1 deadline - // 2) A reactionInstance has 1 level but multiple deadlines - // 3) A reaction instance has multiple levels but all have the same deadline - // 4) Multiple deadlines and levels - - var prolog = new CodeBuilder(); - var epilog = new CodeBuilder(); - - for (ReactionInstance r : reactor.reactions) { - var levelSet = r.getLevels(); - var deadlineSet = r.getInferredDeadlines(); - - if (levelSet.size() > 1 || deadlineSet.size() > 1) { - // Scenario 2-4 - if (prolog.length() == 0) { - prolog.startScopedBlock(); - epilog.endScopedBlock(); - } - } - if (deadlineSet.size() > 1) { - // Scenario (2) or (4) - var deadlines = r.getInferredDeadlinesList().stream() - .map(elt -> ("0x" + Long.toString(elt.toNanoSeconds(), 16) + "LL")) - .collect(Collectors.toList()); - - prolog.pr("interval_t "+r.uniqueID()+"_inferred_deadlines[] = { "+joinObjects(deadlines, ", ")+" };"); - } - - if (levelSet.size() > 1) { - // Scenario (3) or (4) - // Cannot use the above set of levels because it is a set, not a list. - prolog.pr("int "+r.uniqueID()+"_levels[] = { "+joinObjects(r.getLevelsList(), ", ")+" };"); - } - } - - - var temp = new CodeBuilder(); - temp.pr("// Set reaction priorities for " + reactor); - temp.startScopedBlock(reactor); - for (ReactionInstance r : reactor.reactions) { - //if (currentFederate.contains(r.getDefinition())) { - foundOne = true; - var levelSet = r.getLevels(); - var deadlineSet = r.getInferredDeadlines(); - - // Get the head of the associated lists. To avoid duplication in - // several of the following cases - var level = r.getLevelsList().get(0); - var inferredDeadline = r.getInferredDeadlinesList().get(0); - var runtimeIdx =CUtil.runtimeIndex(r.getParent()); - - if (levelSet.size() == 1 && deadlineSet.size() == 1) { - // Scenario (1) - - var indexValue = inferredDeadline.toNanoSeconds() << 16 | level; - - var reactionIndex = "0x" + Long.toUnsignedString(indexValue, 16) + "LL"; - - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of level "+level+" and ", - "// deadline "+ inferredDeadline.toNanoSeconds()+" shifted left 16 bits.", - CUtil.reactionRef(r)+".index = "+reactionIndex+";" - )); - } else if (levelSet.size() == 1 && deadlineSet.size() > 1) { - // Scenario 2 - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of levels["+runtimeIdx+"] and ", - "// deadlines["+runtimeIdx+"] shifted left 16 bits.", - CUtil.reactionRef(r)+".index = ("+r.uniqueID()+"_inferred_deadlines["+runtimeIdx+"] << 16) | " + - level+";" - )); - - } else if (levelSet.size() > 1 && deadlineSet.size() == 1) { - // Scenarion (3) - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of levels["+runtimeIdx+"] and ", - "// deadlines["+runtimeIdx+"] shifted left 16 bits.", - CUtil.reactionRef(r)+".index = ("+inferredDeadline.toNanoSeconds()+" << 16) | " + - r.uniqueID()+"_levels["+runtimeIdx+"];" - )); - - } else if (levelSet.size() > 1 && deadlineSet.size() > 1) { - // Scenario (4) - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of levels["+runtimeIdx+"] and ", - "// deadlines["+runtimeIdx+"] shifted left 16 bits.", - CUtil.reactionRef(r)+".index = ("+r.uniqueID()+"_inferred_deadlines["+runtimeIdx+"] << 16) | " + - r.uniqueID()+"_levels["+runtimeIdx+"];" - )); - } - - } - for (ReactorInstance child : reactor.children) { - foundOne = setReactionPriorities(child, temp) || foundOne; - } - temp.endScopedBlock(); - - if (foundOne) { - builder.pr(prolog.toString()); - builder.pr(temp.toString()); - builder.pr(epilog.toString()); - } - return foundOne; + for (ReactorInstance child : reactor.children) { + foundOne = setReactionPriorities(child, temp) || foundOne; } + temp.endScopedBlock(); - /** - * Generate assignments of pointers in the "self" struct of a destination - * port's reactor to the appropriate entries in the "self" struct of the - * source reactor. This has to be done after all reactors have been created - * because inputs point to outputs that are arbitrarily far away. - * @param instance The reactor instance. - */ - private static String deferredConnectInputsToOutputs( - ReactorInstance instance - ) { - var code = new CodeBuilder(); - code.pr("// Connect inputs and outputs for reactor "+instance.getFullName()+"."); - // Iterate over all ports of this reactor that depend on reactions. - for (PortInstance input : instance.inputs) { - if (!input.getDependsOnReactions().isEmpty()) { - // Input is written to by reactions in the parent of the port's parent. - code.pr(connectPortToEventualDestinations(input)); - } - } - for (PortInstance output : instance.outputs) { - if (!output.getDependsOnReactions().isEmpty()) { - // Output is written to by reactions in the port's parent. - code.pr(connectPortToEventualDestinations(output)); - } - } - for (ReactorInstance child: instance.children) { - code.pr(deferredConnectInputsToOutputs(child)); - } - return code.toString(); + if (foundOne) { + builder.pr(prolog.toString()); + builder.pr(temp.toString()); + builder.pr(epilog.toString()); } - - /** - * Generate assignments of pointers in the "self" struct of a destination - * port's reactor to the appropriate entries in the "self" struct of the - * source reactor. If this port is an input, then it is being written - * to by a reaction belonging to the parent of the port's parent. - * If it is an output, then it is being written to by a reaction belonging - * to the port's parent. - * @param src A port that is written to by reactions. - */ - private static String connectPortToEventualDestinations( - PortInstance src - ) { - var code = new CodeBuilder(); - for (SendRange srcRange: src.eventualDestinations()) { - for (RuntimeRange dstRange : srcRange.destinations) { - var dst = dstRange.instance; - var destStructType = CGenerator.variableStructType(dst); - - // NOTE: For federated execution, dst.getParent() should always be contained - // by the currentFederate because an AST transformation removes connections - // between ports of distinct federates. So the following check is not - // really necessary. - var mod = (dst.isMultiport() || (src.isInput() && src.isMultiport()))? "" : "&"; - code.pr("// Connect "+srcRange+" to port "+dstRange); - code.startScopedRangeBlock(srcRange, dstRange); - if (src.isInput()) { - // Source port is written to by reaction in port's parent's parent - // and ultimate destination is further downstream. - code.pr(CUtil.portRef(dst, dr, db, dc)+" = ("+destStructType+"*)"+mod+CUtil.portRefNested(src, sr, sb, sc)+";"); - } else if (dst.isOutput()) { - // An output port of a contained reactor is triggering a reaction. - code.pr(CUtil.portRefNested(dst, dr, db, dc)+" = ("+destStructType+"*)&"+CUtil.portRef(src, sr, sb, sc)+";"); - } else { - // An output port is triggering an input port. - code.pr(CUtil.portRef(dst, dr, db, dc)+" = ("+destStructType+"*)&"+CUtil.portRef(src, sr, sb, sc)+";"); - if (AttributeUtils.isSparse(dst.getDefinition())) { - code.pr(CUtil.portRef(dst, dr, db, dc)+"->sparse_record = "+CUtil.portRefName(dst, dr, db, dc)+"__sparse;"); - code.pr(CUtil.portRef(dst, dr, db, dc)+"->destination_channel = "+dc+";"); - } - } - code.endScopedRangeBlock(srcRange, dstRange); - } - } - return code.toString(); + return foundOne; + } + + /** + * Generate assignments of pointers in the "self" struct of a destination port's reactor to the + * appropriate entries in the "self" struct of the source reactor. This has to be done after all + * reactors have been created because inputs point to outputs that are arbitrarily far away. + * + * @param instance The reactor instance. + */ + private static String deferredConnectInputsToOutputs(ReactorInstance instance) { + var code = new CodeBuilder(); + code.pr("// Connect inputs and outputs for reactor " + instance.getFullName() + "."); + // Iterate over all ports of this reactor that depend on reactions. + for (PortInstance input : instance.inputs) { + if (!input.getDependsOnReactions().isEmpty()) { + // Input is written to by reactions in the parent of the port's parent. + code.pr(connectPortToEventualDestinations(input)); + } } - - /** - * For each reaction of the specified reactor, - * set the last_enabling_reaction field of the reaction struct to point - * to the single dominating upstream reaction if there is one, or to be - * NULL if there is none. - * - * @param r The reactor. - */ - private static String deferredOptimizeForSingleDominatingReaction( - ReactorInstance r - ) { - var code = new CodeBuilder(); - for (ReactionInstance reaction : r.reactions) { - // The following code attempts to gather into a loop assignments of successive - // bank members relations between reactions to avoid large chunks of inline code - // when a large bank sends to a large bank or when a large bank receives from - // one reaction that is either multicasting or sending through a multiport. - var start = 0; - var end = 0; - var domStart = 0; - var same = false; // Set to true when finding a string of identical dominating reactions. - ReactionInstance.Runtime previousRuntime = null; - var first = true; //First time through the loop. - for (ReactionInstance.Runtime runtime : reaction.getRuntimeInstances()) { - if (!first) { // Not the first time through the loop. - if (same) { // Previously seen at least two identical dominating. - if (runtime.dominating != previousRuntime.dominating) { - // End of streak of same dominating reaction runtime instance. - code.pr(printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - )); - same = false; - start = runtime.id; - domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; - } - } else if (runtime.dominating == previousRuntime.dominating) { - // Start of a streak of identical dominating reaction runtime instances. - same = true; - } else if (runtime.dominating != null && previousRuntime.dominating != null - && runtime.dominating.getReaction() == previousRuntime.dominating.getReaction() - ) { - // Same dominating reaction even if not the same dominating runtime. - if (runtime.dominating.id != previousRuntime.dominating.id + 1) { - // End of a streak of contiguous runtimes. - printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - ); - same = false; - start = runtime.id; - domStart = runtime.dominating.id; - } - } else { - // Different dominating reaction. - printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - ); - same = false; - start = runtime.id; - domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; - } - } - first = false; - previousRuntime = runtime; - end++; - } - if (end > start) { - printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - ); - } - } - return code.toString(); + for (PortInstance output : instance.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { + // Output is written to by reactions in the port's parent. + code.pr(connectPortToEventualDestinations(output)); + } } - - /** - * Print statement that sets the last_enabling_reaction field of a reaction. - */ - private static String printOptimizeForSingleDominatingReaction( - ReactionInstance.Runtime runtime, - int start, - int end, - int domStart, - boolean same - ) { - var code = new CodeBuilder(); - var dominatingRef = "NULL"; - - if (end > start + 1) { - code.startScopedBlock(); - var reactionRef = CUtil.reactionRef(runtime.getReaction(), "i"); - if (runtime.dominating != null) { - if (same) { - dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; - } else { - dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "j++") + ")"; - } - } - code.pr(String.join("\n", - "// "+runtime.getReaction().getFullName()+" dominating upstream reaction.", - "int j = "+domStart+";", - "for (int i = "+start+"; i < "+end+"; i++) {", - " "+reactionRef+".last_enabling_reaction = "+dominatingRef+";", - "}" - )); - code.endScopedBlock(); - } else if (end == start + 1) { - var reactionRef = CUtil.reactionRef(runtime.getReaction(), "" + start); - if (runtime.dominating != null) { - dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; - } - code.pr(String.join("\n", - "// "+runtime.getReaction().getFullName()+" dominating upstream reaction.", - reactionRef+".last_enabling_reaction = "+dominatingRef+";" - )); - } - return code.toString(); + for (ReactorInstance child : instance.children) { + code.pr(deferredConnectInputsToOutputs(child)); } - - /** - * For the specified reaction, for ports that it writes to, - * fill the trigger table for triggering downstream reactions. - * - * @param reactions The reactions. - */ - private static String deferredFillTriggerTable( - Iterable reactions - ) { - var code = new CodeBuilder(); - for (ReactionInstance reaction : reactions) { - var name = reaction.getParent().getFullName(); - - var reactorSelfStruct = CUtil.reactorRef(reaction.getParent(), sr); - - var foundPort = false; - - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (!foundPort) { - // Need a separate index for the triggers array for each bank member. - code.startScopedBlock(); - code.pr("int triggers_index["+reaction.getParent().getTotalWidth()+"] = { 0 }; // Number of bank members with the reaction."); - foundPort = true; - } - // If the port is a multiport, then its channels may have different sets - // of destinations. For ordinary ports, there will be only one range and - // its width will be 1. - // We generate the code to fill the triggers array first in a temporary code buffer, - // so that we can simultaneously calculate the size of the total array. - for (SendRange srcRange : port.eventualDestinations()) { - var srcNested = port.isInput(); - code.startScopedRangeBlock(srcRange, sr, sb, sc, srcNested); - - var triggerArray = CUtil.reactionRef(reaction, sr)+".triggers[triggers_index["+sr+"]++]"; - // Skip ports whose parent is not in the federation. - // This can happen with reactions in the top-level that have - // as an effect a port in a bank. - code.pr(String.join("\n", - "// Reaction "+reaction.index+" of "+name+" triggers "+srcRange.destinations.size()+" downstream reactions", - "// through port "+port.getFullName()+".", - CUtil.reactionRef(reaction, sr)+".triggered_sizes[triggers_index["+sr+"]] = "+srcRange.destinations.size()+";", - "// For reaction "+reaction.index+" of "+name+", allocate an", - "// array of trigger pointers for downstream reactions through port "+port.getFullName(), - "trigger_t** trigger_array = (trigger_t**)_lf_allocate(", - " "+srcRange.destinations.size()+", sizeof(trigger_t*),", - " &"+reactorSelfStruct+"->base.allocations); ", - triggerArray+" = trigger_array;" - )); - code.endScopedRangeBlock(srcRange); - } - } - var cumulativePortWidth = 0; - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - // If this port does not have any destinations, do not generate code for it. - if (port.eventualDestinations().isEmpty()) continue; - - code.pr("for (int i = 0; i < "+reaction.getParent().getTotalWidth()+"; i++) triggers_index[i] = "+cumulativePortWidth+";"); - for (SendRange srcRange : port.eventualDestinations()) { - var srcNested = srcRange.instance.isInput(); - var multicastCount = 0; - for (RuntimeRange dstRange : srcRange.destinations) { - var dst = dstRange.instance; - - code.startScopedRangeBlock(srcRange, dstRange); - - // If the source is nested, need to take into account the parent's bank index - // when indexing into the triggers array. - var triggerArray = ""; - if (srcNested && port.getParent().getWidth() > 1) { - triggerArray = CUtil.reactionRef(reaction, sr)+".triggers[triggers_index["+sr+"] + "+sc+" + src_range_mr.digits[1] * src_range_mr.radixes[0]]"; - } else { - triggerArray = CUtil.reactionRef(reaction, sr)+".triggers[triggers_index["+sr+"] + "+sc+"]"; - } - - if (dst.isOutput()) { - // Include this destination port only if it has at least one - // reaction in the federation. - var belongs = false; - for (ReactionInstance destinationReaction : dst.getDependentReactions()) { - belongs = true; - } - if (belongs) { - code.pr(String.join("\n", - "// Port "+port.getFullName()+" has reactions in its parent's parent.", - "// Point to the trigger struct for those reactions.", - triggerArray+"["+multicastCount+"] = &"+CUtil.triggerRefNested(dst, dr, db)+";" - )); - } else { - // Put in a NULL pointer. - code.pr(String.join("\n", - "// Port "+port.getFullName()+" has reactions in its parent's parent.", - "// But those are not in the federation.", - triggerArray+"["+multicastCount+"] = NULL;" - )); - } - } else { - // Destination is an input port. - code.pr(String.join("\n", - "// Point to destination port "+dst.getFullName()+"'s trigger struct.", - triggerArray+"["+multicastCount+"] = &"+CUtil.triggerRef(dst, dr)+";" - )); - } - code.endScopedRangeBlock(srcRange, dstRange); - multicastCount++; - } - } - // If the port is an input of a contained reactor, then we have to take - // into account the bank width of the contained reactor. - if (port.getParent() != reaction.getParent()) { - cumulativePortWidth += port.getWidth() * port.getParent().getWidth(); - } else { - cumulativePortWidth += port.getWidth(); - } - } - if (foundPort) code.endScopedBlock(); + return code.toString(); + } + + /** + * Generate assignments of pointers in the "self" struct of a destination port's reactor to the + * appropriate entries in the "self" struct of the source reactor. If this port is an input, then + * it is being written to by a reaction belonging to the parent of the port's parent. If it is an + * output, then it is being written to by a reaction belonging to the port's parent. + * + * @param src A port that is written to by reactions. + */ + private static String connectPortToEventualDestinations(PortInstance src) { + var code = new CodeBuilder(); + for (SendRange srcRange : src.eventualDestinations()) { + for (RuntimeRange dstRange : srcRange.destinations) { + var dst = dstRange.instance; + var destStructType = CGenerator.variableStructType(dst); + + // NOTE: For federated execution, dst.getParent() should always be contained + // by the currentFederate because an AST transformation removes connections + // between ports of distinct federates. So the following check is not + // really necessary. + var mod = (dst.isMultiport() || (src.isInput() && src.isMultiport())) ? "" : "&"; + code.pr("// Connect " + srcRange + " to port " + dstRange); + code.startScopedRangeBlock(srcRange, dstRange); + if (src.isInput()) { + // Source port is written to by reaction in port's parent's parent + // and ultimate destination is further downstream. + code.pr( + CUtil.portRef(dst, dr, db, dc) + + " = (" + + destStructType + + "*)" + + mod + + CUtil.portRefNested(src, sr, sb, sc) + + ";"); + } else if (dst.isOutput()) { + // An output port of a contained reactor is triggering a reaction. + code.pr( + CUtil.portRefNested(dst, dr, db, dc) + + " = (" + + destStructType + + "*)&" + + CUtil.portRef(src, sr, sb, sc) + + ";"); + } else { + // An output port is triggering an input port. + code.pr( + CUtil.portRef(dst, dr, db, dc) + + " = (" + + destStructType + + "*)&" + + CUtil.portRef(src, sr, sb, sc) + + ";"); + if (AttributeUtils.isSparse(dst.getDefinition())) { + code.pr( + CUtil.portRef(dst, dr, db, dc) + + "->sparse_record = " + + CUtil.portRefName(dst, dr, db, dc) + + "__sparse;"); + code.pr(CUtil.portRef(dst, dr, db, dc) + "->destination_channel = " + dc + ";"); + } } - return code.toString(); + code.endScopedRangeBlock(srcRange, dstRange); + } } - - /** - * For each input port of a contained reactor that receives data - * from one or more of the specified reactions, set the num_destinations - * field of the corresponding port structs on the self struct of - * the reaction's parent reactor equal to the total number of - * destination reactors. - * If the port has a token type, this also initializes it with a token. - * @param reactions The reactions. - * @param types The C types. - */ - private static String deferredInputNumDestinations( - Iterable reactions, - CTypes types - ) { - // We need the number of destination _reactors_, not the - // number of destination ports nor the number of destination reactions. - // One of the destination reactors may be the container of this - // instance because it may have a reaction to an output of this instance. - // Since a port may be written to by multiple reactions, - // ensure that this is done only once. - var portsHandled = new HashSet(); - var code = new CodeBuilder(); - for (ReactionInstance reaction : reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.isInput() && !portsHandled.contains(port)) { - // Port is an input of a contained reactor that gets data from a reaction of this reactor. - portsHandled.add(port); - code.pr("// Set number of destination reactors for port "+port.getParent().getName()+"."+port.getName()+"."); - // The input port may itself have multiple destinations. - for (SendRange sendingRange : port.eventualDestinations()) { - code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); - // Syntax is slightly different for a multiport output vs. single port. - var connector = (port.isMultiport())? "->" : "."; - code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); - - // Initialize token types. - var type = ASTUtils.getInferredType(port.getDefinition()); - if (CUtil.isTokenType(type, types)) { - // Create the template token that goes in the port struct. - var rootType = CUtil.rootType(types.getTargetType(type)); - // If the rootType is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; - // If the port is a multiport, then the portRefNested is itself a pointer - // so we want its value, not its address. - var indirection = (port.isMultiport())? "" : "&"; - code.startChannelIteration(port); - code.pr(String.join("\n", - "_lf_initialize_template((token_template_t*)", - " "+indirection+"("+CUtil.portRefNested(port, sr, sb, sc)+"),", - size+");" - )); - code.endChannelIteration(port); - } - - code.endScopedRangeBlock(sendingRange); - } - } + return code.toString(); + } + + /** + * For each reaction of the specified reactor, set the last_enabling_reaction field of the + * reaction struct to point to the single dominating upstream reaction if there is one, or to be + * NULL if there is none. + * + * @param r The reactor. + */ + private static String deferredOptimizeForSingleDominatingReaction(ReactorInstance r) { + var code = new CodeBuilder(); + for (ReactionInstance reaction : r.reactions) { + // The following code attempts to gather into a loop assignments of successive + // bank members relations between reactions to avoid large chunks of inline code + // when a large bank sends to a large bank or when a large bank receives from + // one reaction that is either multicasting or sending through a multiport. + var start = 0; + var end = 0; + var domStart = 0; + var same = false; // Set to true when finding a string of identical dominating reactions. + ReactionInstance.Runtime previousRuntime = null; + var first = true; // First time through the loop. + for (ReactionInstance.Runtime runtime : reaction.getRuntimeInstances()) { + if (!first) { // Not the first time through the loop. + if (same) { // Previously seen at least two identical dominating. + if (runtime.dominating != previousRuntime.dominating) { + // End of streak of same dominating reaction runtime instance. + code.pr( + printOptimizeForSingleDominatingReaction( + previousRuntime, start, end, domStart, same)); + same = false; + start = runtime.id; + domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; } - } - return code.toString(); - } - - /** - * For each output port of the specified reactor, - * set the num_destinations field of port structs on its self struct - * equal to the total number of destination reactors. This is used - * to initialize reference counts in dynamically allocated tokens - * sent to other reactors. - * @param reactor The reactor instance. - */ - private static String deferredOutputNumDestinations( - ReactorInstance reactor - ) { - // Reference counts are decremented by each destination reactor - // at the conclusion of a time step. Hence, the initial reference - // count should equal the number of destination _reactors_, not the - // number of destination ports nor the number of destination reactions. - // One of the destination reactors may be the container of this - // instance because it may have a reaction to an output of this instance. - var code = new CodeBuilder(); - for (PortInstance output : reactor.outputs) { - for (SendRange sendingRange : output.eventualDestinations()) { - code.pr("// For reference counting, set num_destinations for port " + output.getFullName() + "."); - code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); - code.pr(CUtil.portRef(output, sr, sb, sc)+".num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); - code.endScopedRangeBlock(sendingRange); + } else if (runtime.dominating == previousRuntime.dominating) { + // Start of a streak of identical dominating reaction runtime instances. + same = true; + } else if (runtime.dominating != null + && previousRuntime.dominating != null + && runtime.dominating.getReaction() == previousRuntime.dominating.getReaction()) { + // Same dominating reaction even if not the same dominating runtime. + if (runtime.dominating.id != previousRuntime.dominating.id + 1) { + // End of a streak of contiguous runtimes. + printOptimizeForSingleDominatingReaction(previousRuntime, start, end, domStart, same); + same = false; + start = runtime.id; + domStart = runtime.dominating.id; } + } else { + // Different dominating reaction. + printOptimizeForSingleDominatingReaction(previousRuntime, start, end, domStart, same); + same = false; + start = runtime.id; + domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; + } } - return code.toString(); + first = false; + previousRuntime = runtime; + end++; + } + if (end > start) { + printOptimizeForSingleDominatingReaction(previousRuntime, start, end, domStart, same); + } } - - /** - * Perform initialization functions that must be performed after - * all reactor runtime instances have been created. - * This function does not create nested loops over nested banks, - * so each function it calls must handle its own iteration - * over all runtime instance. - * @param reactor The container. - * @param main The top-level reactor. - * @param reactions The list of reactions to consider. - * @param types The C types. - */ - private static String deferredInitializeNonNested( - ReactorInstance reactor, - ReactorInstance main, - Iterable reactions, - CTypes types - ) { - var code = new CodeBuilder(); - code.pr("// **** Start non-nested deferred initialize for "+reactor.getFullName()); - // Initialize the num_destinations fields of port structs on the self struct. - // This needs to be outside the above scoped block because it performs - // its own iteration over ranges. - code.pr(deferredInputNumDestinations( - reactions, - types - )); - - // Second batch of initializes cannot be within a for loop - // iterating over bank members because they iterate over send - // ranges which may span bank members. - if (reactor != main) { - code.pr(deferredOutputNumDestinations( - reactor - )); - } - code.pr(deferredFillTriggerTable( - reactions - )); - code.pr(deferredOptimizeForSingleDominatingReaction( - reactor - )); - for (ReactorInstance child: reactor.children) { - code.pr(deferredInitializeNonNested( - child, - main, - child.reactions, - types - )); + return code.toString(); + } + + /** Print statement that sets the last_enabling_reaction field of a reaction. */ + private static String printOptimizeForSingleDominatingReaction( + ReactionInstance.Runtime runtime, int start, int end, int domStart, boolean same) { + var code = new CodeBuilder(); + var dominatingRef = "NULL"; + + if (end > start + 1) { + code.startScopedBlock(); + var reactionRef = CUtil.reactionRef(runtime.getReaction(), "i"); + if (runtime.dominating != null) { + if (same) { + dominatingRef = + "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; + } else { + dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "j++") + ")"; } - code.pr("// **** End of non-nested deferred initialize for "+reactor.getFullName()); - return code.toString(); + } + code.pr( + String.join( + "\n", + "// " + runtime.getReaction().getFullName() + " dominating upstream reaction.", + "int j = " + domStart + ";", + "for (int i = " + start + "; i < " + end + "; i++) {", + " " + reactionRef + ".last_enabling_reaction = " + dominatingRef + ";", + "}")); + code.endScopedBlock(); + } else if (end == start + 1) { + var reactionRef = CUtil.reactionRef(runtime.getReaction(), "" + start); + if (runtime.dominating != null) { + dominatingRef = + "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; + } + code.pr( + String.join( + "\n", + "// " + runtime.getReaction().getFullName() + " dominating upstream reaction.", + reactionRef + ".last_enabling_reaction = " + dominatingRef + ";")); } - - /** - * For each output of the specified reactor that has a token type - * (type* or type[]), create a template token and put it on the self struct. - * @param reactor The reactor. - */ - private static String deferredCreateTemplateTokens( - ReactorInstance reactor, - CTypes types - ) { - var code = new CodeBuilder(); - // Look for outputs with token types. - for (PortInstance output : reactor.outputs) { - var type = ASTUtils.getInferredType(output.getDefinition()); - if (CUtil.isTokenType(type, types)) { - // Create the template token that goes in the trigger struct. - // Its reference count is zero, enabling it to be used immediately. - var rootType = CUtil.rootType(types.getTargetType(type)); - // If the rootType is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; - code.startChannelIteration(output); - code.pr(String.join("\n", - "_lf_initialize_template((token_template_t*)", - " &("+CUtil.portRef(output)+"),", - size+");" - )); - code.endChannelIteration(output); - } + return code.toString(); + } + + /** + * For the specified reaction, for ports that it writes to, fill the trigger table for triggering + * downstream reactions. + * + * @param reactions The reactions. + */ + private static String deferredFillTriggerTable(Iterable reactions) { + var code = new CodeBuilder(); + for (ReactionInstance reaction : reactions) { + var name = reaction.getParent().getFullName(); + + var reactorSelfStruct = CUtil.reactorRef(reaction.getParent(), sr); + + var foundPort = false; + + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (!foundPort) { + // Need a separate index for the triggers array for each bank member. + code.startScopedBlock(); + code.pr( + "int triggers_index[" + + reaction.getParent().getTotalWidth() + + "] = { 0 }; // Number of bank members with the reaction."); + foundPort = true; } - return code.toString(); - } - - /** - * For the specified reaction, for ports that it writes to, - * set up the arrays that store the results (if necessary) and - * that are used to trigger downstream reactions if an effect is actually - * produced. The port may be an output of the reaction's parent - * or an input to a reactor contained by the parent. - * - * @param reaction The reaction instance. - */ - private static String deferredReactionOutputs( - ReactionInstance reaction, - TargetConfig targetConfig - ) { - var code = new CodeBuilder(); - // val selfRef = CUtil.reactorRef(reaction.getParent()); - var name = reaction.getParent().getFullName(); - // Insert a string name to facilitate debugging. - if (targetConfig.logLevel.compareTo(LogLevel.LOG) >= 0) { - code.pr(CUtil.reactionRef(reaction)+".name = "+addDoubleQuotes(name+" reaction "+reaction.index)+";"); + // If the port is a multiport, then its channels may have different sets + // of destinations. For ordinary ports, there will be only one range and + // its width will be 1. + // We generate the code to fill the triggers array first in a temporary code buffer, + // so that we can simultaneously calculate the size of the total array. + for (SendRange srcRange : port.eventualDestinations()) { + var srcNested = port.isInput(); + code.startScopedRangeBlock(srcRange, sr, sb, sc, srcNested); + + var triggerArray = + CUtil.reactionRef(reaction, sr) + ".triggers[triggers_index[" + sr + "]++]"; + // Skip ports whose parent is not in the federation. + // This can happen with reactions in the top-level that have + // as an effect a port in a bank. + code.pr( + String.join( + "\n", + "// Reaction " + + reaction.index + + " of " + + name + + " triggers " + + srcRange.destinations.size() + + " downstream reactions", + "// through port " + port.getFullName() + ".", + CUtil.reactionRef(reaction, sr) + + ".triggered_sizes[triggers_index[" + + sr + + "]] = " + + srcRange.destinations.size() + + ";", + "// For reaction " + reaction.index + " of " + name + ", allocate an", + "// array of trigger pointers for downstream reactions through port " + + port.getFullName(), + "trigger_t** trigger_array = (trigger_t**)_lf_allocate(", + " " + srcRange.destinations.size() + ", sizeof(trigger_t*),", + " &" + reactorSelfStruct + "->base.allocations); ", + triggerArray + " = trigger_array;")); + code.endScopedRangeBlock(srcRange); } - - var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); - - // Count the output ports and inputs of contained reactors that - // may be set by this reaction. This ignores actions in the effects. - // Collect initialization statements for the output_produced array for the reaction - // to point to the is_present field of the appropriate output. - // These statements must be inserted after the array is malloc'd, - // but we construct them while we are counting outputs. - var outputCount = 0; - var init = new CodeBuilder(); - - init.startScopedBlock(); - init.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { - // Create the entry in the output_produced array for this port. - // If the port is a multiport, then we need to create an entry for each - // individual channel. - - // If the port is an input of a contained reactor, then, if that - // contained reactor is a bank, we will have to iterate over bank - // members. - var bankWidth = 1; - var portRef = ""; - if (effect.isInput()) { - init.pr("// Reaction writes to an input of a contained reactor."); - bankWidth = effect.getParent().getWidth(); - init.startScopedBlock(effect.getParent()); - portRef = CUtil.portRefNestedName(effect); + } + var cumulativePortWidth = 0; + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + // If this port does not have any destinations, do not generate code for it. + if (port.eventualDestinations().isEmpty()) continue; + + code.pr( + "for (int i = 0; i < " + + reaction.getParent().getTotalWidth() + + "; i++) triggers_index[i] = " + + cumulativePortWidth + + ";"); + for (SendRange srcRange : port.eventualDestinations()) { + var srcNested = srcRange.instance.isInput(); + var multicastCount = 0; + for (RuntimeRange dstRange : srcRange.destinations) { + var dst = dstRange.instance; + + code.startScopedRangeBlock(srcRange, dstRange); + + // If the source is nested, need to take into account the parent's bank index + // when indexing into the triggers array. + var triggerArray = ""; + if (srcNested && port.getParent().getWidth() > 1) { + triggerArray = + CUtil.reactionRef(reaction, sr) + + ".triggers[triggers_index[" + + sr + + "] + " + + sc + + " + src_range_mr.digits[1] * src_range_mr.radixes[0]]"; } else { - init.startScopedBlock(); - portRef = CUtil.portRefName(effect); + triggerArray = + CUtil.reactionRef(reaction, sr) + + ".triggers[triggers_index[" + + sr + + "] + " + + sc + + "]"; } - if (effect.isMultiport()) { - // Form is slightly different for inputs vs. outputs. - var connector = "."; - if (effect.isInput()) connector = "->"; - - // Point the output_produced field to where the is_present field of the port is. - init.pr(String.join("\n", - "for (int i = 0; i < "+effect.getWidth()+"; i++) {", - " "+CUtil.reactionRef(reaction)+".output_produced[i + count]", - " = &"+portRef+"[i]"+connector+"is_present;", - "}", - "count += "+effect.getWidth()+";" - )); - outputCount += effect.getWidth() * bankWidth; + if (dst.isOutput()) { + // Include this destination port only if it has at least one + // reaction in the federation. + var belongs = false; + for (ReactionInstance destinationReaction : dst.getDependentReactions()) { + belongs = true; + } + if (belongs) { + code.pr( + String.join( + "\n", + "// Port " + port.getFullName() + " has reactions in its parent's parent.", + "// Point to the trigger struct for those reactions.", + triggerArray + + "[" + + multicastCount + + "] = &" + + CUtil.triggerRefNested(dst, dr, db) + + ";")); + } else { + // Put in a NULL pointer. + code.pr( + String.join( + "\n", + "// Port " + port.getFullName() + " has reactions in its parent's parent.", + "// But those are not in the federation.", + triggerArray + "[" + multicastCount + "] = NULL;")); + } } else { - // The effect is not a multiport. - init.pr(CUtil.reactionRef(reaction)+".output_produced[count++] = &"+portRef+".is_present;"); - outputCount += bankWidth; + // Destination is an input port. + code.pr( + String.join( + "\n", + "// Point to destination port " + dst.getFullName() + "'s trigger struct.", + triggerArray + + "[" + + multicastCount + + "] = &" + + CUtil.triggerRef(dst, dr) + + ";")); } - init.endScopedBlock(); + code.endScopedRangeBlock(srcRange, dstRange); + multicastCount++; + } } - init.endScopedBlock(); - code.pr(String.join("\n", - "// Total number of outputs (single ports and multiport channels)", - "// produced by "+reaction+".", - CUtil.reactionRef(reaction)+".num_outputs = "+outputCount+";" - )); - if (outputCount > 0) { - code.pr(String.join("\n", - "// Allocate memory for triggers[] and triggered_sizes[] on the reaction_t", - "// struct for this reaction.", - CUtil.reactionRef(reaction)+".triggers = (trigger_t***)_lf_allocate(", - " "+outputCount+", sizeof(trigger_t**),", - " &"+reactorSelfStruct+"->base.allocations);", - CUtil.reactionRef(reaction)+".triggered_sizes = (int*)_lf_allocate(", - " "+outputCount+", sizeof(int),", - " &"+reactorSelfStruct+"->base.allocations);", - CUtil.reactionRef(reaction)+".output_produced = (bool**)_lf_allocate(", - " "+outputCount+", sizeof(bool*),", - " &"+reactorSelfStruct+"->base.allocations);" - )); + // If the port is an input of a contained reactor, then we have to take + // into account the bank width of the contained reactor. + if (port.getParent() != reaction.getParent()) { + cumulativePortWidth += port.getWidth() * port.getParent().getWidth(); + } else { + cumulativePortWidth += port.getWidth(); } - - code.pr(String.join("\n", - init.toString(), - "// ** End initialization for reaction "+reaction.index+" of "+name - )); - return code.toString(); + } + if (foundPort) code.endScopedBlock(); } - - /** - * Generate code to allocate the memory needed by reactions for triggering - * downstream reactions. - * @param reactions A list of reactions. - */ - private static String deferredReactionMemory( - Iterable reactions, - TargetConfig targetConfig - ) { - var code = new CodeBuilder(); - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : reactions) { - code.pr(deferredReactionOutputs( - reaction, - targetConfig - )); - var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (PortInstance trigger : Iterables.filter(reaction.triggers, PortInstance.class)) { - // If the port is a multiport, then we need to create an entry for each - // individual port. - if (trigger.isMultiport() && trigger.getParent() != null && trigger.isOutput()) { - // Trigger is an output of a contained reactor or bank. - code.pr(String.join("\n", - "// Allocate memory to store pointers to the multiport output "+trigger.getName()+" ", - "// of a contained reactor "+trigger.getParent().getFullName() - )); - code.startScopedBlock(trigger.getParent()); - - var width = trigger.getWidth(); - var portStructType = CGenerator.variableStructType(trigger); - - code.pr(String.join("\n", - CUtil.reactorRefNested(trigger.getParent())+"."+trigger.getName()+"_width = "+width+";", - CUtil.reactorRefNested(trigger.getParent())+"."+trigger.getName(), - " = ("+portStructType+"**)_lf_allocate(", - " "+width+", sizeof("+portStructType+"*),", - " &"+reactorSelfStruct+"->base.allocations); " - )); - - code.endScopedBlock(); - } + return code.toString(); + } + + /** + * For each input port of a contained reactor that receives data from one or more of the specified + * reactions, set the num_destinations field of the corresponding port structs on the self struct + * of the reaction's parent reactor equal to the total number of destination reactors. If the port + * has a token type, this also initializes it with a token. + * + * @param reactions The reactions. + * @param types The C types. + */ + private static String deferredInputNumDestinations( + Iterable reactions, CTypes types) { + // We need the number of destination _reactors_, not the + // number of destination ports nor the number of destination reactions. + // One of the destination reactors may be the container of this + // instance because it may have a reaction to an output of this instance. + // Since a port may be written to by multiple reactions, + // ensure that this is done only once. + var portsHandled = new HashSet(); + var code = new CodeBuilder(); + for (ReactionInstance reaction : reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.isInput() && !portsHandled.contains(port)) { + // Port is an input of a contained reactor that gets data from a reaction of this reactor. + portsHandled.add(port); + code.pr( + "// Set number of destination reactors for port " + + port.getParent().getName() + + "." + + port.getName() + + "."); + // The input port may itself have multiple destinations. + for (SendRange sendingRange : port.eventualDestinations()) { + code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); + // Syntax is slightly different for a multiport output vs. single port. + var connector = (port.isMultiport()) ? "->" : "."; + code.pr( + CUtil.portRefNested(port, sr, sb, sc) + + connector + + "num_destinations = " + + sendingRange.getNumberOfDestinationReactors() + + ";"); + + // Initialize token types. + var type = ASTUtils.getInferredType(port.getDefinition()); + if (CUtil.isTokenType(type, types)) { + // Create the template token that goes in the port struct. + var rootType = CUtil.rootType(types.getTargetType(type)); + // If the rootType is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; + // If the port is a multiport, then the portRefNested is itself a pointer + // so we want its value, not its address. + var indirection = (port.isMultiport()) ? "" : "&"; + code.startChannelIteration(port); + code.pr( + String.join( + "\n", + "_lf_initialize_template((token_template_t*)", + " " + indirection + "(" + CUtil.portRefNested(port, sr, sb, sc) + "),", + size + ");")); + code.endChannelIteration(port); } + + code.endScopedRangeBlock(sendingRange); + } } - return code.toString(); + } + } + return code.toString(); + } + + /** + * For each output port of the specified reactor, set the num_destinations field of port structs + * on its self struct equal to the total number of destination reactors. This is used to + * initialize reference counts in dynamically allocated tokens sent to other reactors. + * + * @param reactor The reactor instance. + */ + private static String deferredOutputNumDestinations(ReactorInstance reactor) { + // Reference counts are decremented by each destination reactor + // at the conclusion of a time step. Hence, the initial reference + // count should equal the number of destination _reactors_, not the + // number of destination ports nor the number of destination reactions. + // One of the destination reactors may be the container of this + // instance because it may have a reaction to an output of this instance. + var code = new CodeBuilder(); + for (PortInstance output : reactor.outputs) { + for (SendRange sendingRange : output.eventualDestinations()) { + code.pr( + "// For reference counting, set num_destinations for port " + + output.getFullName() + + "."); + code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); + code.pr( + CUtil.portRef(output, sr, sb, sc) + + ".num_destinations = " + + sendingRange.getNumberOfDestinationReactors() + + ";"); + code.endScopedRangeBlock(sendingRange); + } + } + return code.toString(); + } + + /** + * Perform initialization functions that must be performed after all reactor runtime instances + * have been created. This function does not create nested loops over nested banks, so each + * function it calls must handle its own iteration over all runtime instance. + * + * @param reactor The container. + * @param main The top-level reactor. + * @param reactions The list of reactions to consider. + * @param types The C types. + */ + private static String deferredInitializeNonNested( + ReactorInstance reactor, + ReactorInstance main, + Iterable reactions, + CTypes types) { + var code = new CodeBuilder(); + code.pr("// **** Start non-nested deferred initialize for " + reactor.getFullName()); + // Initialize the num_destinations fields of port structs on the self struct. + // This needs to be outside the above scoped block because it performs + // its own iteration over ranges. + code.pr(deferredInputNumDestinations(reactions, types)); + + // Second batch of initializes cannot be within a for loop + // iterating over bank members because they iterate over send + // ranges which may span bank members. + if (reactor != main) { + code.pr(deferredOutputNumDestinations(reactor)); + } + code.pr(deferredFillTriggerTable(reactions)); + code.pr(deferredOptimizeForSingleDominatingReaction(reactor)); + for (ReactorInstance child : reactor.children) { + code.pr(deferredInitializeNonNested(child, main, child.reactions, types)); + } + code.pr("// **** End of non-nested deferred initialize for " + reactor.getFullName()); + return code.toString(); + } + + /** + * For each output of the specified reactor that has a token type (type* or type[]), create a + * template token and put it on the self struct. + * + * @param reactor The reactor. + */ + private static String deferredCreateTemplateTokens(ReactorInstance reactor, CTypes types) { + var code = new CodeBuilder(); + // Look for outputs with token types. + for (PortInstance output : reactor.outputs) { + var type = ASTUtils.getInferredType(output.getDefinition()); + if (CUtil.isTokenType(type, types)) { + // Create the template token that goes in the trigger struct. + // Its reference count is zero, enabling it to be used immediately. + var rootType = CUtil.rootType(types.getTargetType(type)); + // If the rootType is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; + code.startChannelIteration(output); + code.pr( + String.join( + "\n", + "_lf_initialize_template((token_template_t*)", + " &(" + CUtil.portRef(output) + "),", + size + ");")); + code.endChannelIteration(output); + } + } + return code.toString(); + } + + /** + * For the specified reaction, for ports that it writes to, set up the arrays that store the + * results (if necessary) and that are used to trigger downstream reactions if an effect is + * actually produced. The port may be an output of the reaction's parent or an input to a reactor + * contained by the parent. + * + * @param reaction The reaction instance. + */ + private static String deferredReactionOutputs( + ReactionInstance reaction, TargetConfig targetConfig) { + var code = new CodeBuilder(); + // val selfRef = CUtil.reactorRef(reaction.getParent()); + var name = reaction.getParent().getFullName(); + // Insert a string name to facilitate debugging. + if (targetConfig.logLevel.compareTo(LogLevel.LOG) >= 0) { + code.pr( + CUtil.reactionRef(reaction) + + ".name = " + + addDoubleQuotes(name + " reaction " + reaction.index) + + ";"); } - /** - * If any reaction of the specified reactor provides input - * to a contained reactor, then generate code to allocate - * memory to store the data produced by those reactions. - * The allocated memory is pointed to by a field called - * {@code _lf_containername.portname} on the self struct of the reactor. - * @param reactor The reactor. - */ - private static String deferredAllocationForEffectsOnInputs( - ReactorInstance reactor - ) { - var code = new CodeBuilder(); - // Keep track of ports already handled. There may be more than one reaction - // in the container writing to the port, but we want only one memory allocation. - var portsHandled = new HashSet(); - var reactorSelfStruct = CUtil.reactorRef(reactor); - // Find parent reactions that mention multiport inputs of this reactor. - for (ReactionInstance reaction : reactor.reactions) { - for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { - if (effect.getParent().getDepth() > reactor.getDepth() // port of a contained reactor. - && effect.isMultiport() - && !portsHandled.contains(effect) - ) { - code.pr("// A reaction writes to a multiport of a child. Allocate memory."); - portsHandled.add(effect); - code.startScopedBlock(effect.getParent()); - var portStructType = CGenerator.variableStructType(effect); - var effectRef = CUtil.portRefNestedName(effect); - code.pr(String.join("\n", - effectRef+"_width = "+effect.getWidth()+";", - "// Allocate memory to store output of reaction feeding ", - "// a multiport input of a contained reactor.", - effectRef+" = ("+portStructType+"**)_lf_allocate(", - " "+effect.getWidth()+", sizeof("+portStructType+"*),", - " &"+reactorSelfStruct+"->base.allocations); ", - "for (int i = 0; i < "+effect.getWidth()+"; i++) {", - " "+effectRef+"[i] = ("+portStructType+"*)_lf_allocate(", - " 1, sizeof("+portStructType+"),", - " &"+reactorSelfStruct+"->base.allocations); ", - "}" - )); - code.endScopedBlock(); - } - } - } - return code.toString(); + var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); + + // Count the output ports and inputs of contained reactors that + // may be set by this reaction. This ignores actions in the effects. + // Collect initialization statements for the output_produced array for the reaction + // to point to the is_present field of the appropriate output. + // These statements must be inserted after the array is malloc'd, + // but we construct them while we are counting outputs. + var outputCount = 0; + var init = new CodeBuilder(); + + init.startScopedBlock(); + init.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { + // Create the entry in the output_produced array for this port. + // If the port is a multiport, then we need to create an entry for each + // individual channel. + + // If the port is an input of a contained reactor, then, if that + // contained reactor is a bank, we will have to iterate over bank + // members. + var bankWidth = 1; + var portRef = ""; + if (effect.isInput()) { + init.pr("// Reaction writes to an input of a contained reactor."); + bankWidth = effect.getParent().getWidth(); + init.startScopedBlock(effect.getParent()); + portRef = CUtil.portRefNestedName(effect); + } else { + init.startScopedBlock(); + portRef = CUtil.portRefName(effect); + } + + if (effect.isMultiport()) { + // Form is slightly different for inputs vs. outputs. + var connector = "."; + if (effect.isInput()) connector = "->"; + + // Point the output_produced field to where the is_present field of the port is. + init.pr( + String.join( + "\n", + "for (int i = 0; i < " + effect.getWidth() + "; i++) {", + " " + CUtil.reactionRef(reaction) + ".output_produced[i + count]", + " = &" + portRef + "[i]" + connector + "is_present;", + "}", + "count += " + effect.getWidth() + ";")); + outputCount += effect.getWidth() * bankWidth; + } else { + // The effect is not a multiport. + init.pr( + CUtil.reactionRef(reaction) + + ".output_produced[count++] = &" + + portRef + + ".is_present;"); + outputCount += bankWidth; + } + init.endScopedBlock(); + } + init.endScopedBlock(); + code.pr( + String.join( + "\n", + "// Total number of outputs (single ports and multiport channels)", + "// produced by " + reaction + ".", + CUtil.reactionRef(reaction) + ".num_outputs = " + outputCount + ";")); + if (outputCount > 0) { + code.pr( + String.join( + "\n", + "// Allocate memory for triggers[] and triggered_sizes[] on the reaction_t", + "// struct for this reaction.", + CUtil.reactionRef(reaction) + ".triggers = (trigger_t***)_lf_allocate(", + " " + outputCount + ", sizeof(trigger_t**),", + " &" + reactorSelfStruct + "->base.allocations);", + CUtil.reactionRef(reaction) + ".triggered_sizes = (int*)_lf_allocate(", + " " + outputCount + ", sizeof(int),", + " &" + reactorSelfStruct + "->base.allocations);", + CUtil.reactionRef(reaction) + ".output_produced = (bool**)_lf_allocate(", + " " + outputCount + ", sizeof(bool*),", + " &" + reactorSelfStruct + "->base.allocations);")); } - /** - * Perform initialization functions that must be performed after - * all reactor runtime instances have been created. - * This function creates nested loops over nested banks. - * @param reactor The container. - */ - private static String deferredInitialize( - ReactorInstance reactor, - Iterable reactions, - TargetConfig targetConfig, - CTypes types - ) { - var code = new CodeBuilder(); - code.pr("// **** Start deferred initialize for "+reactor.getFullName()); - // First batch of initializations is within a for loop iterating - // over bank members for the reactor's parent. - code.startScopedBlock(reactor); - - // If the child has a multiport that is an effect of some reaction in its container, - // then we have to generate code to allocate memory for arrays pointing to - // its data. If the child is a bank, then memory is allocated for the entire - // bank width because a reaction cannot specify which bank members it writes - // to so we have to assume it can write to any. - code.pr(deferredAllocationForEffectsOnInputs( - reactor - )); - code.pr(deferredReactionMemory( - reactions, - targetConfig - )); - - // For outputs that are not primitive types (of form type* or type[]), - // create a default token on the self struct. - code.pr(deferredCreateTemplateTokens( - reactor, - types - )); - for (ReactorInstance child: reactor.children) { - code.pr(deferredInitialize( - child, - child.reactions, - targetConfig, - types) - ); + code.pr( + String.join( + "\n", + init.toString(), + "// ** End initialization for reaction " + reaction.index + " of " + name)); + return code.toString(); + } + + /** + * Generate code to allocate the memory needed by reactions for triggering downstream reactions. + * + * @param reactions A list of reactions. + */ + private static String deferredReactionMemory( + Iterable reactions, TargetConfig targetConfig) { + var code = new CodeBuilder(); + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : reactions) { + code.pr(deferredReactionOutputs(reaction, targetConfig)); + var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (PortInstance trigger : Iterables.filter(reaction.triggers, PortInstance.class)) { + // If the port is a multiport, then we need to create an entry for each + // individual port. + if (trigger.isMultiport() && trigger.getParent() != null && trigger.isOutput()) { + // Trigger is an output of a contained reactor or bank. + code.pr( + String.join( + "\n", + "// Allocate memory to store pointers to the multiport output " + + trigger.getName() + + " ", + "// of a contained reactor " + trigger.getParent().getFullName())); + code.startScopedBlock(trigger.getParent()); + + var width = trigger.getWidth(); + var portStructType = CGenerator.variableStructType(trigger); + + code.pr( + String.join( + "\n", + CUtil.reactorRefNested(trigger.getParent()) + + "." + + trigger.getName() + + "_width = " + + width + + ";", + CUtil.reactorRefNested(trigger.getParent()) + "." + trigger.getName(), + " = (" + portStructType + "**)_lf_allocate(", + " " + width + ", sizeof(" + portStructType + "*),", + " &" + reactorSelfStruct + "->base.allocations); ")); + + code.endScopedBlock(); } - code.endScopedBlock(); - code.pr("// **** End of deferred initialize for "+reactor.getFullName()); - return code.toString(); + } + } + return code.toString(); + } + + /** + * If any reaction of the specified reactor provides input to a contained reactor, then generate + * code to allocate memory to store the data produced by those reactions. The allocated memory is + * pointed to by a field called {@code _lf_containername.portname} on the self struct of the + * reactor. + * + * @param reactor The reactor. + */ + private static String deferredAllocationForEffectsOnInputs(ReactorInstance reactor) { + var code = new CodeBuilder(); + // Keep track of ports already handled. There may be more than one reaction + // in the container writing to the port, but we want only one memory allocation. + var portsHandled = new HashSet(); + var reactorSelfStruct = CUtil.reactorRef(reactor); + // Find parent reactions that mention multiport inputs of this reactor. + for (ReactionInstance reaction : reactor.reactions) { + for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { + if (effect.getParent().getDepth() > reactor.getDepth() // port of a contained reactor. + && effect.isMultiport() + && !portsHandled.contains(effect)) { + code.pr("// A reaction writes to a multiport of a child. Allocate memory."); + portsHandled.add(effect); + code.startScopedBlock(effect.getParent()); + var portStructType = CGenerator.variableStructType(effect); + var effectRef = CUtil.portRefNestedName(effect); + code.pr( + String.join( + "\n", + effectRef + "_width = " + effect.getWidth() + ";", + "// Allocate memory to store output of reaction feeding ", + "// a multiport input of a contained reactor.", + effectRef + " = (" + portStructType + "**)_lf_allocate(", + " " + effect.getWidth() + ", sizeof(" + portStructType + "*),", + " &" + reactorSelfStruct + "->base.allocations); ", + "for (int i = 0; i < " + effect.getWidth() + "; i++) {", + " " + effectRef + "[i] = (" + portStructType + "*)_lf_allocate(", + " 1, sizeof(" + portStructType + "),", + " &" + reactorSelfStruct + "->base.allocations); ", + "}")); + code.endScopedBlock(); + } + } + } + return code.toString(); + } + + /** + * Perform initialization functions that must be performed after all reactor runtime instances + * have been created. This function creates nested loops over nested banks. + * + * @param reactor The container. + */ + private static String deferredInitialize( + ReactorInstance reactor, + Iterable reactions, + TargetConfig targetConfig, + CTypes types) { + var code = new CodeBuilder(); + code.pr("// **** Start deferred initialize for " + reactor.getFullName()); + // First batch of initializations is within a for loop iterating + // over bank members for the reactor's parent. + code.startScopedBlock(reactor); + + // If the child has a multiport that is an effect of some reaction in its container, + // then we have to generate code to allocate memory for arrays pointing to + // its data. If the child is a bank, then memory is allocated for the entire + // bank width because a reaction cannot specify which bank members it writes + // to so we have to assume it can write to any. + code.pr(deferredAllocationForEffectsOnInputs(reactor)); + code.pr(deferredReactionMemory(reactions, targetConfig)); + + // For outputs that are not primitive types (of form type* or type[]), + // create a default token on the self struct. + code.pr(deferredCreateTemplateTokens(reactor, types)); + for (ReactorInstance child : reactor.children) { + code.pr(deferredInitialize(child, child.reactions, targetConfig, types)); } + code.endScopedBlock(); + code.pr("// **** End of deferred initialize for " + reactor.getFullName()); + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/src/org/lflang/generator/c/CTypes.java index 45edd59bd5..97ea482d83 100644 --- a/org.lflang/src/org/lflang/generator/c/CTypes.java +++ b/org.lflang/src/org/lflang/generator/c/CTypes.java @@ -4,162 +4,150 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; - import org.lflang.InferredType; import org.lflang.TimeUnit; import org.lflang.TimeValue; import org.lflang.generator.ReactorInstance; import org.lflang.generator.TargetTypes; -import org.lflang.lf.Initializer; import org.lflang.lf.ParameterReference; -import org.lflang.lf.Type; public class CTypes implements TargetTypes { - // Regular expression pattern for array types. - // For example, for "foo[10]", the first match will be "foo" and the second "[10]". - // For "foo[]", the first match will be "foo" and the second "". - static final Pattern arrayPattern = Pattern.compile("^\\s*(?:/\\*.*?\\*/)?\\s*(\\w+)\\s*\\[([0-9]*)]\\s*$"); - private static final CTypes INSTANCE = new CTypes(); - - public CTypes() { - } - - @Override - public boolean supportsGenerics() { - return false; - } - - @Override - public String getTargetTimeType() { - return "interval_t"; - } - - @Override - public String getTargetTagType() { - return "tag_t"; - } - - @Override - public String getTargetFixedSizeListType(String baseType, int size) { - return String.format("%s[%d]", baseType, size); - } - - @Override - public String getTargetVariableSizeListType(String baseType) { - return String.format("%s[]", baseType); - } - - @Override - public String getTargetUndefinedType() { - return "/*undefined*/"; - } - - /** - * Given a type, return a C representation of the type. Note that - * C types are very idiosyncratic. For example, {@code int[]} is not always accepted - * as a type, and {@code int*} must be used instead, except when initializing - * a variable using a static initializer, as in {@code int[] foo = {1, 2, 3};}. - * When initializing a variable using a static initializer, use - * {@link #getVariableDeclaration(TypeParameterizedReactor, InferredType, String, boolean)} instead. - * @param type The type. - */ - @Override - public String getTargetType(InferredType type) { - var result = TargetTypes.super.getTargetType(type); - Matcher matcher = arrayPattern.matcher(result); - if (matcher.find()) { - return matcher.group(1) + '*'; - } - return result; - } - - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - throw new UnsupportedOperationException("No context defined"); - } - - @Override - public String getTargetTimeExpr(TimeValue time) { - if (time != null) { - if (time.unit != null) { - return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; - } else { - return Long.valueOf(time.getMagnitude()).toString(); - } - } - return "0"; // FIXME: do this or throw exception? - } - - @Override - public String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); - } - - @Override - public String getVariableSizeListInitExpression(List contents, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); - } - - /** - * Return a variable declaration of the form "{@code type name}". - * The type is as returned by {@link #getTargetType(InferredType)}, except with - * the array syntax {@code [size]} preferred over the pointer syntax - * {@code *} (if applicable). This also includes the variable name - * because C requires the array type specification to be placed after - * the variable name rather than with the type. - * The result is of the form {@code type variable_name[size]} or - * {@code type variable_name} depending on whether the given type - * is an array type, unless the array type has no size (it is given - * as {@code []}. In that case, the returned form depends on the - * third argument, initializer. If true, the then the returned - * declaration will have the form {@code type variable_name[]}, - * and otherwise it will have the form {@code type* variable_name}. - * @param type The type. - * @param variableName The name of the variable. - * @param initializer True to return a form usable in a static initializer. - */ - public String getVariableDeclaration( - TypeParameterizedReactor tpr, - InferredType type, - String variableName, - boolean initializer - ) { - String t = TargetTypes.super.getTargetType(tpr.resolveType(type)); - Matcher matcher = arrayPattern.matcher(t); - String declaration = String.format("%s %s", t, variableName); - if (matcher.find()) { - // For array types, we have to move the [] - // because C is very picky about where this goes. It has to go - // after the variable name. Also, in an initializer, it has to have - // form [], and in a struct definition, it has to use *. - if (matcher.group(2).equals("") && !initializer) { - declaration = String.format("%s* %s", - matcher.group(1), variableName); - } else { - declaration = String.format("%s %s[%s]", - matcher.group(1), variableName, matcher.group(2)); - } - } - return declaration; - } - - // note that this is moved out by #544 - public static String cMacroName(TimeUnit unit) { - return unit.getCanonicalName().toUpperCase(); - } - - public static CTypes getInstance() { - return INSTANCE; - } - - - public static CTypes generateParametersIn(ReactorInstance instance) { - return new CTypes() { - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return CUtil.reactorRef(instance) + "->" + expr.getParameter().getName(); - } - }; - } + // Regular expression pattern for array types. + // For example, for "foo[10]", the first match will be "foo" and the second "[10]". + // For "foo[]", the first match will be "foo" and the second "". + static final Pattern arrayPattern = + Pattern.compile("^\\s*(?:/\\*.*?\\*/)?\\s*(\\w+)\\s*\\[([0-9]*)]\\s*$"); + private static final CTypes INSTANCE = new CTypes(); + + public CTypes() {} + + @Override + public boolean supportsGenerics() { + return false; + } + + @Override + public String getTargetTimeType() { + return "interval_t"; + } + + @Override + public String getTargetTagType() { + return "tag_t"; + } + + @Override + public String getTargetFixedSizeListType(String baseType, int size) { + return String.format("%s[%d]", baseType, size); + } + + @Override + public String getTargetVariableSizeListType(String baseType) { + return String.format("%s[]", baseType); + } + + @Override + public String getTargetUndefinedType() { + return "/*undefined*/"; + } + + /** + * Given a type, return a C representation of the type. Note that C types are very idiosyncratic. + * For example, {@code int[]} is not always accepted as a type, and {@code int*} must be used + * instead, except when initializing a variable using a static initializer, as in {@code int[] foo + * = {1, 2, 3};}. When initializing a variable using a static initializer, use {@link + * #getVariableDeclaration(TypeParameterizedReactor, InferredType, String, boolean)} instead. + * + * @param type The type. + */ + @Override + public String getTargetType(InferredType type) { + var result = TargetTypes.super.getTargetType(type); + Matcher matcher = arrayPattern.matcher(result); + if (matcher.find()) { + return matcher.group(1) + '*'; + } + return result; + } + + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + throw new UnsupportedOperationException("No context defined"); + } + + @Override + public String getTargetTimeExpr(TimeValue time) { + if (time != null) { + if (time.unit != null) { + return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; + } else { + return Long.valueOf(time.getMagnitude()).toString(); + } + } + return "0"; // FIXME: do this or throw exception? + } + + @Override + public String getFixedSizeListInitExpression( + List contents, int listSize, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); + } + + @Override + public String getVariableSizeListInitExpression(List contents, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); + } + + /** + * Return a variable declaration of the form "{@code type name}". The type is as returned by + * {@link #getTargetType(InferredType)}, except with the array syntax {@code [size]} preferred + * over the pointer syntax {@code *} (if applicable). This also includes the variable name because + * C requires the array type specification to be placed after the variable name rather than with + * the type. The result is of the form {@code type variable_name[size]} or {@code type + * variable_name} depending on whether the given type is an array type, unless the array type has + * no size (it is given as {@code []}. In that case, the returned form depends on the third + * argument, initializer. If true, the then the returned declaration will have the form {@code + * type variable_name[]}, and otherwise it will have the form {@code type* variable_name}. + * + * @param type The type. + * @param variableName The name of the variable. + * @param initializer True to return a form usable in a static initializer. + */ + public String getVariableDeclaration( + TypeParameterizedReactor tpr, InferredType type, String variableName, boolean initializer) { + String t = TargetTypes.super.getTargetType(tpr.resolveType(type)); + Matcher matcher = arrayPattern.matcher(t); + String declaration = String.format("%s %s", t, variableName); + if (matcher.find()) { + // For array types, we have to move the [] + // because C is very picky about where this goes. It has to go + // after the variable name. Also, in an initializer, it has to have + // form [], and in a struct definition, it has to use *. + if (matcher.group(2).equals("") && !initializer) { + declaration = String.format("%s* %s", matcher.group(1), variableName); + } else { + declaration = String.format("%s %s[%s]", matcher.group(1), variableName, matcher.group(2)); + } + } + return declaration; + } + + // note that this is moved out by #544 + public static String cMacroName(TimeUnit unit) { + return unit.getCanonicalName().toUpperCase(); + } + + public static CTypes getInstance() { + return INSTANCE; + } + + public static CTypes generateParametersIn(ReactorInstance instance) { + return new CTypes() { + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return CUtil.reactorRef(instance) + "->" + expr.getParameter().getName(); + } + }; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index dbb365e189..3a7f151a2c 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -1,28 +1,28 @@ /* Utilities for C code generation. */ /************* -Copyright (c) 2019-2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator.c; @@ -32,12 +32,10 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.List; import java.util.Objects; import java.util.stream.Collectors; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.InferredType; import org.lflang.TargetConfig; - import org.lflang.generator.ActionInstance; import org.lflang.generator.GeneratorCommandFactory; import org.lflang.generator.LFGeneratorContext; @@ -55,751 +53,741 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.util.LFCommand; /** - * A collection of utilities for C code generation. - * This class codifies the coding conventions for the C target code generator. - * I.e., it defines how variables are named and referenced. + * A collection of utilities for C code generation. This class codifies the coding conventions for + * the C target code generator. I.e., it defines how variables are named and referenced. + * * @author Edward A. Lee */ public class CUtil { - /** - * Suffix that when appended to the name of a federated reactor yields - * the name of its corresponding RTI executable. - */ - public static final String RTI_BIN_SUFFIX = "_RTI"; - - /** - * Suffix that when appended to the name of a federated reactor yields - * the name of its corresponding distribution script. - */ - public static final String RTI_DISTRIBUTION_SCRIPT_SUFFIX = "_distribute.sh"; - - ////////////////////////////////////////////////////// - //// Public methods. - - /** - * Return a reference to the action struct of the specified - * action instance. This action_base_t struct is on the self struct. - * @param instance The action instance. - * @param runtimeIndex An optional index variable name to use to address runtime instances. - */ - public static String actionRef(ActionInstance instance, String runtimeIndex) { - return reactorRef(instance.getParent(), runtimeIndex) - + "->_lf_" - + instance.getName(); - } - - /** - * Return a default name of a variable to refer to the bank index of a reactor - * in a bank. This is has the form uniqueID_i where uniqueID - * is an identifier for the instance that is guaranteed to be different - * from the ID of any other instance in the program. - * If the instance is not a bank, return "0". - * @param instance A reactor instance. - */ - public static String bankIndex(ReactorInstance instance) { - if (!instance.isBank()) return "0"; - return bankIndexName(instance); - } - - /** - * Return a default name of a variable to refer to the bank index of a reactor - * in a bank. This is has the form uniqueID_i where uniqueID - * is an identifier for the instance that is guaranteed to be different - * from the ID of any other instance in the program. - * @param instance A reactor instance. - */ - public static String bankIndexName(ReactorInstance instance) { - return instance.uniqueID() + "_i"; - } - - /** - * Return a default name of a variable to refer to the channel index of a port - * in a bank. This has the form uniqueID_c where uniqueID - * is an identifier for the instance that is guaranteed to be different - * from the ID of any other instance in the program. - * If the port is not a multiport, then return the string "0". - */ - public static String channelIndex(PortInstance port) { - if (!port.isMultiport()) return "0"; - return channelIndexName(port); - } - - /** - * Return a default name of a variable to refer to the channel index of a port - * in a bank. This is has the form uniqueID_c where uniqueID - * is an identifier for the instance that is guaranteed to be different - * from the ID of any other instance in the program. - */ - public static String channelIndexName(PortInstance port) { - return port.uniqueID() + "_c"; - } - - /** - * Return the name of the reactor. A {@code _main} is appended to the name if the - * reactor is main (to allow for instantiations that have the same name as - * the main reactor or the .lf file). - */ - public static String getName(TypeParameterizedReactor reactor) { - String name = reactor.reactor().getName().toLowerCase() + reactor.hashCode(); - if (reactor.reactor().isMain()) { - return name + "_main"; - } - return name; - } - - /** - * Return a reference to the specified port. - * - * The returned string will have one of the following forms: - *

      - *
    • {@code selfStructs[k]->_lf_portName}
    • - *
    • {@code selfStructs[k]->_lf_portName}
    • - *
    • {@code selfStructs[k]->_lf_portName[i]}
    • - *
    • {@code selfStructs[k]->_lf_parent.portName}
    • - *
    • {@code selfStructs[k]->_lf_parent.portName[i]}
    • - *
    • {@code selfStructs[k]->_lf_parent[j].portName}
    • - *
    • {@code selfStructs[k]->_lf_parent[j].portName[i]}
    • - *
    - * - * where {@code k} is the runtime index of either the port's parent - * or the port's parent's parent, the latter when isNested is {@code true}. - * The index {@code j} is present if the parent is a bank, and - * the index {@code i} is present if the port is a multiport. - * - * The first two forms are used if isNested is false, - * and the remaining four are used if isNested is true. - * Set {@code isNested} to {@code true} when referencing a port belonging - * to a contained reactor. - * - * @param port The port. - * @param isNested True to return a reference relative to the parent's parent. - * @param includeChannelIndex True to include the channel index at the end. - * @param runtimeIndex A variable name to use to index the runtime instance or - * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex A variable name to use to index the bank or null to use the - * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. - * @param channelIndex A variable name to use to index the channel or null to - * use the default, the string returned by {@link CUtil#channelIndex(PortInstance)}. - */ - public static String portRef( - PortInstance port, - boolean isNested, - boolean includeChannelIndex, - String runtimeIndex, - String bankIndex, - String channelIndex - ) { - String channel = ""; - if (channelIndex == null) channelIndex = channelIndex(port); - if (port.isMultiport() && includeChannelIndex) { - channel = "[" + channelIndex + "]"; - } - if (isNested) { - return reactorRefNested(port.getParent(), runtimeIndex, bankIndex) + "." + port.getName() + channel; - } else { - String sourceStruct = CUtil.reactorRef(port.getParent(), runtimeIndex); - return sourceStruct + "->_lf_" + port.getName() + channel; - } - } - - /** - * Return a reference to the port on the self struct of the - * port's parent. This is used when an input port triggers a reaction - * in the port's parent or when an output port is written to by - * a reaction in the port's parent. - * This is equivalent to calling {@code portRef(port, false, true, null, null)}. - * @param port An instance of the port to be referenced. - */ - public static String portRef(PortInstance port) { - return portRef(port, false, true, null, null, null); - } - - /** - * Return a reference to the port on the self struct of the - * port's parent using the specified index variables. - * This is used when an input port triggers a reaction - * in the port's parent or when an output port is written to by - * a reaction in the port's parent. - * This is equivalent to calling {@code portRef(port, false, true, bankIndex, channelIndex)}. - * @param port An instance of the port to be referenced. - * @param runtimeIndex A variable name to use to index the runtime instance or - * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex A variable name to use to index the bank or null to use the - * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. - * @param channelIndex A variable name to use to index the channel or null to - * use the default, the string returned by {@link CUtil#channelIndex(PortInstance)}. - */ - public static String portRef( - PortInstance port, String runtimeIndex, String bankIndex, String channelIndex - ) { - return portRef(port, false, true, runtimeIndex, bankIndex, channelIndex); - } - - /** - * Return a reference to a port without any channel indexing. - * This is useful for deriving a reference to the _width variable. - * @param port An instance of the port to be referenced. - */ - public static String portRefName(PortInstance port) { - return portRef(port, false, false, null, null, null); - } - - /** - * Return the portRef without the channel indexing. - * This is useful for deriving a reference to the _width variable. - * - * @param port An instance of the port to be referenced. - * @param runtimeIndex A variable name to use to index the runtime instance or - * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex A variable name to use to index the bank or null to use the - * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. - * @param channelIndex A variable name to use to index the channel or null to - * use the default, the string returned by {@link CUtil#channelIndex(PortInstance)}. - */ - public static String portRefName( - PortInstance port, String runtimeIndex, String bankIndex, String channelIndex - ) { - return portRef(port, false, false, runtimeIndex, bankIndex, channelIndex); - } - - /** - * Return a port reference to a port on the self struct of the - * parent of the port's parent. This is used when an input port - * is written to by a reaction in the parent of the port's parent, - * or when an output port triggers a reaction in the parent of the - * port's parent. This is equivalent to calling - * {@code portRef(port, true, true, null, null, null)}. - * - * @param port The port. - */ - public static String portRefNested(PortInstance port) { - return portRef(port, true, true, null, null, null); - } - - /** - * Return a reference to the port on the self struct of the - * parent of the port's parent. This is used when an input port - * is written to by a reaction in the parent of the port's parent, - * or when an output port triggers a reaction in the parent of the - * port's parent. This is equivalent to calling - * {@code portRef(port, true, true, runtimeIndex, bankIndex, channelIndex)}. - * - * @param port The port. - * @param runtimeIndex A variable name to use to index the runtime instance or - * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex A variable name to use to index the bank or null to use the - * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. - * @param channelIndex A variable name to use to index the channel or null to - * use the default, the string returned by {@link CUtil#channelIndex(PortInstance)}. - */ - public static String portRefNested( - PortInstance port, String runtimeIndex, String bankIndex, String channelIndex - ) { - return portRef(port, true, true, runtimeIndex, bankIndex, channelIndex); - } - - /** - * Return a reference to the port on the self struct of the - * parent of the port's parent, but without the channel indexing, - * even if it is a multiport. This is used when an input port - * is written to by a reaction in the parent of the port's parent, - * or when an output port triggers a reaction in the parent of the - * port's parent. - * This is equivalent to calling {@code portRef(port, true, false, null, null, null)}. - * - * @param port The port. - */ - public static String portRefNestedName(PortInstance port) { - return portRef(port, true, false, null, null, null); - } - - /** - * Return a reference to the port on the self struct of the - * parent of the port's parent, but without the channel indexing, - * even if it is a multiport. This is used when an input port - * is written to by a reaction in the parent of the port's parent, - * or when an output port triggers a reaction in the parent of the - * port's parent. This is equivalent to calling - * {@code portRefNested(port, true, false, runtimeIndex, bankIndex, channelIndex)}. - * - * @param port The port. - * @param runtimeIndex A variable name to use to index the runtime instance or - * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex A variable name to use to index the bank or null to use the - * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. - * @param channelIndex A variable name to use to index the channel or null to - * use the default, the string returned by {@link CUtil#channelIndex(PortInstance)}. - */ - public static String portRefNestedName( - PortInstance port, String runtimeIndex, String bankIndex, String channelIndex - ) { - return portRef(port, true, false, runtimeIndex, bankIndex, channelIndex); - } - - /** - * Return code for referencing a port within a reaction body possibly indexed by - * a bank index and/or a multiport index. If the provided reference is - * not a port, then this returns the string "ERROR: not a port." - * @param reference The reference to the port. - * @param bankIndex A bank index or null or negative if not in a bank. - * @param multiportIndex A multiport index or null or negative if not in a multiport. - */ - public static String portRefInReaction(VarRef reference, Integer bankIndex, Integer multiportIndex) { - if (!(reference.getVariable() instanceof Port)) { - return "ERROR: not a port."; // FIXME: This is not the fail-fast approach, and it seems arbitrary. - } - var prefix = ""; - if (reference.getContainer() != null) { - var bank = ""; - if (reference.getContainer().getWidthSpec() != null && bankIndex != null && bankIndex >= 0) { - bank = "[" + bankIndex + "]"; - } - prefix = reference.getContainer().getName() + bank + "."; - } - var multiport = ""; - if (((Port) reference.getVariable()).getWidthSpec() != null && multiportIndex != null && multiportIndex >= 0) { - multiport = "[" + multiportIndex + "]"; + /** + * Suffix that when appended to the name of a federated reactor yields the name of its + * corresponding RTI executable. + */ + public static final String RTI_BIN_SUFFIX = "_RTI"; + + /** + * Suffix that when appended to the name of a federated reactor yields the name of its + * corresponding distribution script. + */ + public static final String RTI_DISTRIBUTION_SCRIPT_SUFFIX = "_distribute.sh"; + + ////////////////////////////////////////////////////// + //// Public methods. + + /** + * Return a reference to the action struct of the specified action instance. This action_base_t + * struct is on the self struct. + * + * @param instance The action instance. + * @param runtimeIndex An optional index variable name to use to address runtime instances. + */ + public static String actionRef(ActionInstance instance, String runtimeIndex) { + return reactorRef(instance.getParent(), runtimeIndex) + "->_lf_" + instance.getName(); + } + + /** + * Return a default name of a variable to refer to the bank index of a reactor in a bank. This is + * has the form uniqueID_i where uniqueID is an identifier for the instance that is guaranteed to + * be different from the ID of any other instance in the program. If the instance is not a bank, + * return "0". + * + * @param instance A reactor instance. + */ + public static String bankIndex(ReactorInstance instance) { + if (!instance.isBank()) return "0"; + return bankIndexName(instance); + } + + /** + * Return a default name of a variable to refer to the bank index of a reactor in a bank. This is + * has the form uniqueID_i where uniqueID is an identifier for the instance that is guaranteed to + * be different from the ID of any other instance in the program. + * + * @param instance A reactor instance. + */ + public static String bankIndexName(ReactorInstance instance) { + return instance.uniqueID() + "_i"; + } + + /** + * Return a default name of a variable to refer to the channel index of a port in a bank. This has + * the form uniqueID_c where uniqueID is an identifier for the instance that is guaranteed to be + * different from the ID of any other instance in the program. If the port is not a multiport, + * then return the string "0". + */ + public static String channelIndex(PortInstance port) { + if (!port.isMultiport()) return "0"; + return channelIndexName(port); + } + + /** + * Return a default name of a variable to refer to the channel index of a port in a bank. This is + * has the form uniqueID_c where uniqueID is an identifier for the instance that is guaranteed to + * be different from the ID of any other instance in the program. + */ + public static String channelIndexName(PortInstance port) { + return port.uniqueID() + "_c"; + } + + /** + * Return the name of the reactor. A {@code _main} is appended to the name if the reactor is main + * (to allow for instantiations that have the same name as the main reactor or the .lf file). + */ + public static String getName(TypeParameterizedReactor reactor) { + String name = reactor.reactor().getName().toLowerCase() + reactor.hashCode(); + if (reactor.reactor().isMain()) { + return name + "_main"; + } + return name; + } + + /** + * Return a reference to the specified port. + * + *

    The returned string will have one of the following forms: + * + *

      + *
    • {@code selfStructs[k]->_lf_portName} + *
    • {@code selfStructs[k]->_lf_portName} + *
    • {@code selfStructs[k]->_lf_portName[i]} + *
    • {@code selfStructs[k]->_lf_parent.portName} + *
    • {@code selfStructs[k]->_lf_parent.portName[i]} + *
    • {@code selfStructs[k]->_lf_parent[j].portName} + *
    • {@code selfStructs[k]->_lf_parent[j].portName[i]} + *
    + * + * where {@code k} is the runtime index of either the port's parent or the port's parent's parent, + * the latter when isNested is {@code true}. The index {@code j} is present if the parent is a + * bank, and the index {@code i} is present if the port is a multiport. + * + *

    The first two forms are used if isNested is false, and the remaining four are used if + * isNested is true. Set {@code isNested} to {@code true} when referencing a port belonging to a + * contained reactor. + * + * @param port The port. + * @param isNested True to return a reference relative to the parent's parent. + * @param includeChannelIndex True to include the channel index at the end. + * @param runtimeIndex A variable name to use to index the runtime instance or null to use the + * default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex A variable name to use to index the bank or null to use the default, the + * string returned by {@link CUtil#bankIndex(ReactorInstance)}. + * @param channelIndex A variable name to use to index the channel or null to use the default, the + * string returned by {@link CUtil#channelIndex(PortInstance)}. + */ + public static String portRef( + PortInstance port, + boolean isNested, + boolean includeChannelIndex, + String runtimeIndex, + String bankIndex, + String channelIndex) { + String channel = ""; + if (channelIndex == null) channelIndex = channelIndex(port); + if (port.isMultiport() && includeChannelIndex) { + channel = "[" + channelIndex + "]"; + } + if (isNested) { + return reactorRefNested(port.getParent(), runtimeIndex, bankIndex) + + "." + + port.getName() + + channel; + } else { + String sourceStruct = CUtil.reactorRef(port.getParent(), runtimeIndex); + return sourceStruct + "->_lf_" + port.getName() + channel; + } + } + + /** + * Return a reference to the port on the self struct of the port's parent. This is used when an + * input port triggers a reaction in the port's parent or when an output port is written to by a + * reaction in the port's parent. This is equivalent to calling {@code portRef(port, false, true, + * null, null)}. + * + * @param port An instance of the port to be referenced. + */ + public static String portRef(PortInstance port) { + return portRef(port, false, true, null, null, null); + } + + /** + * Return a reference to the port on the self struct of the port's parent using the specified + * index variables. This is used when an input port triggers a reaction in the port's parent or + * when an output port is written to by a reaction in the port's parent. This is equivalent to + * calling {@code portRef(port, false, true, bankIndex, channelIndex)}. + * + * @param port An instance of the port to be referenced. + * @param runtimeIndex A variable name to use to index the runtime instance or null to use the + * default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex A variable name to use to index the bank or null to use the default, the + * string returned by {@link CUtil#bankIndex(ReactorInstance)}. + * @param channelIndex A variable name to use to index the channel or null to use the default, the + * string returned by {@link CUtil#channelIndex(PortInstance)}. + */ + public static String portRef( + PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) { + return portRef(port, false, true, runtimeIndex, bankIndex, channelIndex); + } + + /** + * Return a reference to a port without any channel indexing. This is useful for deriving a + * reference to the _width variable. + * + * @param port An instance of the port to be referenced. + */ + public static String portRefName(PortInstance port) { + return portRef(port, false, false, null, null, null); + } + + /** + * Return the portRef without the channel indexing. This is useful for deriving a reference to the + * _width variable. + * + * @param port An instance of the port to be referenced. + * @param runtimeIndex A variable name to use to index the runtime instance or null to use the + * default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex A variable name to use to index the bank or null to use the default, the + * string returned by {@link CUtil#bankIndex(ReactorInstance)}. + * @param channelIndex A variable name to use to index the channel or null to use the default, the + * string returned by {@link CUtil#channelIndex(PortInstance)}. + */ + public static String portRefName( + PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) { + return portRef(port, false, false, runtimeIndex, bankIndex, channelIndex); + } + + /** + * Return a port reference to a port on the self struct of the parent of the port's parent. This + * is used when an input port is written to by a reaction in the parent of the port's parent, or + * when an output port triggers a reaction in the parent of the port's parent. This is equivalent + * to calling {@code portRef(port, true, true, null, null, null)}. + * + * @param port The port. + */ + public static String portRefNested(PortInstance port) { + return portRef(port, true, true, null, null, null); + } + + /** + * Return a reference to the port on the self struct of the parent of the port's parent. This is + * used when an input port is written to by a reaction in the parent of the port's parent, or when + * an output port triggers a reaction in the parent of the port's parent. This is equivalent to + * calling {@code portRef(port, true, true, runtimeIndex, bankIndex, channelIndex)}. + * + * @param port The port. + * @param runtimeIndex A variable name to use to index the runtime instance or null to use the + * default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex A variable name to use to index the bank or null to use the default, the + * string returned by {@link CUtil#bankIndex(ReactorInstance)}. + * @param channelIndex A variable name to use to index the channel or null to use the default, the + * string returned by {@link CUtil#channelIndex(PortInstance)}. + */ + public static String portRefNested( + PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) { + return portRef(port, true, true, runtimeIndex, bankIndex, channelIndex); + } + + /** + * Return a reference to the port on the self struct of the parent of the port's parent, but + * without the channel indexing, even if it is a multiport. This is used when an input port is + * written to by a reaction in the parent of the port's parent, or when an output port triggers a + * reaction in the parent of the port's parent. This is equivalent to calling {@code portRef(port, + * true, false, null, null, null)}. + * + * @param port The port. + */ + public static String portRefNestedName(PortInstance port) { + return portRef(port, true, false, null, null, null); + } + + /** + * Return a reference to the port on the self struct of the parent of the port's parent, but + * without the channel indexing, even if it is a multiport. This is used when an input port is + * written to by a reaction in the parent of the port's parent, or when an output port triggers a + * reaction in the parent of the port's parent. This is equivalent to calling {@code + * portRefNested(port, true, false, runtimeIndex, bankIndex, channelIndex)}. + * + * @param port The port. + * @param runtimeIndex A variable name to use to index the runtime instance or null to use the + * default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex A variable name to use to index the bank or null to use the default, the + * string returned by {@link CUtil#bankIndex(ReactorInstance)}. + * @param channelIndex A variable name to use to index the channel or null to use the default, the + * string returned by {@link CUtil#channelIndex(PortInstance)}. + */ + public static String portRefNestedName( + PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) { + return portRef(port, true, false, runtimeIndex, bankIndex, channelIndex); + } + + /** + * Return code for referencing a port within a reaction body possibly indexed by a bank index + * and/or a multiport index. If the provided reference is not a port, then this returns the string + * "ERROR: not a port." + * + * @param reference The reference to the port. + * @param bankIndex A bank index or null or negative if not in a bank. + * @param multiportIndex A multiport index or null or negative if not in a multiport. + */ + public static String portRefInReaction( + VarRef reference, Integer bankIndex, Integer multiportIndex) { + if (!(reference.getVariable() instanceof Port)) { + return "ERROR: not a port."; // FIXME: This is not the fail-fast approach, and it seems + // arbitrary. + } + var prefix = ""; + if (reference.getContainer() != null) { + var bank = ""; + if (reference.getContainer().getWidthSpec() != null && bankIndex != null && bankIndex >= 0) { + bank = "[" + bankIndex + "]"; + } + prefix = reference.getContainer().getName() + bank + "."; + } + var multiport = ""; + if (((Port) reference.getVariable()).getWidthSpec() != null + && multiportIndex != null + && multiportIndex >= 0) { + multiport = "[" + multiportIndex + "]"; + } + return prefix + reference.getVariable().getName() + multiport; + } + + /** + * Return a reference to the reaction entry on the self struct of the parent of the specified + * reaction. + * + * @param reaction The reaction. + */ + public static String reactionRef(ReactionInstance reaction) { + return reactionRef(reaction, null); + } + + /** + * Return a reference to the reaction entry on the self struct of the parent of the specified + * reaction. + * + * @param reaction The reaction. + * @param runtimeIndex An index into the array of self structs for the parent. + */ + public static String reactionRef(ReactionInstance reaction, String runtimeIndex) { + return reactorRef(reaction.getParent(), runtimeIndex) + "->_lf__reaction_" + reaction.index; + } + + /** + * Return a reference to the "self" struct of the specified reactor instance. The returned string + * has the form self[j], where self is the name of the array of self structs for this reactor + * instance and j is the expression returned by {@link #runtimeIndex(ReactorInstance)} or 0 if + * there are no banks. + * + * @param instance The reactor instance. + */ + public static String reactorRef(ReactorInstance instance) { + return reactorRef(instance, null); + } + + /** + * Return the name of the array of "self" structs of the specified reactor instance. This is + * similar to {@link #reactorRef(ReactorInstance)} except that it does not index into the array. + * + * @param instance The reactor instance. + */ + public static String reactorRefName(ReactorInstance instance) { + return instance.uniqueID() + "_self"; + } + + /** + * Return a reference to the "self" struct of the specified reactor instance. The returned string + * has the form self[runtimeIndex], where self is the name of the array of self structs for this + * reactor instance. If runtimeIndex is null, then it is replaced by the expression returned by + * {@link #runtimeIndex(ReactorInstance)} or 0 if there are no banks. + * + * @param instance The reactor instance. + * @param runtimeIndex An optional expression to use to address bank members. If this is null, the + * expression used will be that returned by {@link #runtimeIndex(ReactorInstance)}. + */ + public static String reactorRef(ReactorInstance instance, String runtimeIndex) { + if (runtimeIndex == null) runtimeIndex = runtimeIndex(instance); + return reactorRefName(instance) + "[" + runtimeIndex + "]"; + } + + /** + * For situations where a reaction reacts to or reads from an output of a contained reactor or + * sends to an input of a contained reactor, then the container's self struct will have a field + * (or an array of fields if the contained reactor is a bank) that is a struct with fields + * corresponding to those inputs and outputs. This method returns a reference to that struct or + * array of structs. Note that the returned reference is not to the self struct of the contained + * reactor. Use {@link #reactorRef(ReactorInstance)} for that. + * + * @param reactor The contained reactor. + */ + public static String reactorRefNested(ReactorInstance reactor) { + return reactorRefNested(reactor, null, null); + } + + /** + * For situations where a reaction reacts to or reads from an output of a contained reactor or + * sends to an input of a contained reactor, then the container's self struct will have a field + * (or an array of fields if the contained reactor is a bank) that is a struct with fields + * corresponding to those inputs and outputs. This method returns a reference to that struct or + * array of structs. Note that the returned reference is not to the self struct of the contained + * reactor. Use {@link CUtil#reactorRef(ReactorInstance)} for that. + * + * @param reactor The contained reactor. + * @param runtimeIndex A variable name to use to index the runtime instance or null to use the + * default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex A variable name to use to index the bank or null to use the default, the + * string returned by {@link CUtil#bankIndex(ReactorInstance)}. + */ + public static String reactorRefNested( + ReactorInstance reactor, String runtimeIndex, String bankIndex) { + String result = reactorRef(reactor.getParent(), runtimeIndex) + "->_lf_" + reactor.getName(); + if (reactor.isBank()) { + // Need the bank index not the runtimeIndex. + if (bankIndex == null) bankIndex = bankIndex(reactor); + result += "[" + bankIndex + "]"; + } + return result; + } + + /** + * Return an expression that, when evaluated, gives the index of a runtime instance of the + * specified ReactorInstance. If the reactor is not within any banks, then this will return "0". + * Otherwise, it will return an expression that evaluates a mixed-radix number d0%w0, d1%w1, ... , + * dn%wn, where n is the depth minus one of the reactor. The radixes, w0 to wn, are the widths of + * this reactor, its parent reactor, on up to the top-level reactor. Since the top-level reactor + * is never a bank, dn = 0 and wn = 1. The digits, di, are either 0 (of the parent is not a bank) + * or the variable name returned by {@link #bankIndexName(ReactorInstance)} if the parent is a + * bank. The returned expression, when evaluated, will yield the following value: + * + *

    +   *     d0 + w0 * (d1 + w1 * ( ... (dn-1 + wn-1 * dn) ... )
    +   * 
    + * + * @param reactor The reactor. + */ + public static String runtimeIndex(ReactorInstance reactor) { + StringBuilder result = new StringBuilder(); + int width = 0; + int parens = 0; + while (reactor != null) { + if (reactor.isBank() && reactor.getWidth() > 1) { + if (width > 0) { + result.append(" + " + width + " * ("); + parens++; } - return prefix + reference.getVariable().getName() + multiport; - } - - /** - * Return a reference to the reaction entry on the self struct - * of the parent of the specified reaction. - * @param reaction The reaction. - */ - public static String reactionRef(ReactionInstance reaction) { - return reactionRef(reaction, null); - } - - /** - * Return a reference to the reaction entry on the self struct - * of the parent of the specified reaction. - * @param reaction The reaction. - * @param runtimeIndex An index into the array of self structs for the parent. - */ - public static String reactionRef(ReactionInstance reaction, String runtimeIndex) { - return reactorRef(reaction.getParent(), runtimeIndex) - + "->_lf__reaction_" + reaction.index; - } - - /** - * Return a reference to the "self" struct of the specified - * reactor instance. The returned string has the form - * self[j], where self is the name of the array of self structs - * for this reactor instance and j is the expression returned - * by {@link #runtimeIndex(ReactorInstance)} or 0 if there are no banks. - * @param instance The reactor instance. - */ - public static String reactorRef(ReactorInstance instance) { - return reactorRef(instance, null); - } - - /** - * Return the name of the array of "self" structs of the specified - * reactor instance. This is similar to {@link #reactorRef(ReactorInstance)} - * except that it does not index into the array. - * @param instance The reactor instance. - */ - public static String reactorRefName(ReactorInstance instance) { - return instance.uniqueID() + "_self"; - } - - /** - * Return a reference to the "self" struct of the specified - * reactor instance. The returned string has the form - * self[runtimeIndex], where self is the name of the array of self structs - * for this reactor instance. If runtimeIndex is null, then it is replaced by - * the expression returned - * by {@link #runtimeIndex(ReactorInstance)} or 0 if there are no banks. - * @param instance The reactor instance. - * @param runtimeIndex An optional expression to use to address bank members. - * If this is null, the expression used will be that returned by - * {@link #runtimeIndex(ReactorInstance)}. - */ - public static String reactorRef(ReactorInstance instance, String runtimeIndex) { - if (runtimeIndex == null) runtimeIndex = runtimeIndex(instance); - return reactorRefName(instance) + "[" + runtimeIndex + "]"; - } - - /** - * For situations where a reaction reacts to or reads from an output - * of a contained reactor or sends to an input of a contained reactor, - * then the container's self struct will have a field - * (or an array of fields if the contained reactor is a bank) that is - * a struct with fields corresponding to those inputs and outputs. - * This method returns a reference to that struct or array of structs. - * Note that the returned reference is not to the self struct of the - * contained reactor. Use {@link #reactorRef(ReactorInstance)} for that. - * - * @param reactor The contained reactor. - */ - public static String reactorRefNested(ReactorInstance reactor) { - return reactorRefNested(reactor, null, null); - } - - /** - * For situations where a reaction reacts to or reads from an output - * of a contained reactor or sends to an input of a contained reactor, - * then the container's self struct will have a field - * (or an array of fields if the contained reactor is a bank) that is - * a struct with fields corresponding to those inputs and outputs. - * This method returns a reference to that struct or array of structs. - * Note that the returned reference is not to the self struct of the - * contained reactor. Use {@link CUtil#reactorRef(ReactorInstance)} for that. - * - * @param reactor The contained reactor. - * @param runtimeIndex A variable name to use to index the runtime instance or - * null to use the default, the string returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex A variable name to use to index the bank or null to use the - * default, the string returned by {@link CUtil#bankIndex(ReactorInstance)}. - */ - public static String reactorRefNested(ReactorInstance reactor, String runtimeIndex, String bankIndex) { - String result = reactorRef(reactor.getParent(), runtimeIndex) + "->_lf_" + reactor.getName(); - if (reactor.isBank()) { - // Need the bank index not the runtimeIndex. - if (bankIndex == null) bankIndex = bankIndex(reactor); - result += "[" + bankIndex + "]"; - } - return result; - } - - /** - * Return an expression that, when evaluated, gives the index of - * a runtime instance of the specified ReactorInstance. If the reactor - * is not within any banks, then this will return "0". Otherwise, it - * will return an expression that evaluates a mixed-radix number - * d0%w0, d1%w1, ... , dn%wn, where n is the depth minus one of the - * reactor. The radixes, w0 to wn, are the widths of this reactor, - * its parent reactor, on up to the top-level reactor. Since the top-level - * reactor is never a bank, dn = 0 and wn = 1. The digits, di, are - * either 0 (of the parent is not a bank) or the variable name returned - * by {@link #bankIndexName(ReactorInstance)} if the parent is a bank. - * The returned expression, when evaluated, will yield the following value: - * - *
    -     *     d0 + w0 * (d1 + w1 * ( ... (dn-1 + wn-1 * dn) ... )
    -     * 
    - * - * @param reactor The reactor. - */ - public static String runtimeIndex(ReactorInstance reactor) { - StringBuilder result = new StringBuilder(); - int width = 0; - int parens = 0; - while (reactor != null) { - if (reactor.isBank() && reactor.getWidth() > 1) { - if (width > 0) { - result.append(" + " + width + " * ("); - parens++; - } - result.append(bankIndexName(reactor)); - width = reactor.getWidth(); - } - reactor = reactor.getParent(); - } - while (parens-- > 0) { - result.append(")"); - } - if (result.length() == 0) return "0"; - return result.toString(); - } - - /** - * Return a unique type for the "self" struct of the specified - * reactor class from the reactor class. - * @param reactor The reactor class. - * @return The type of a self struct for the specified reactor class. - */ - public static String selfType(TypeParameterizedReactor reactor) { - if (reactor.reactor().isMain()) { - return "_" + CUtil.getName(reactor) + "_main_self_t"; - } - return "_" + CUtil.getName(reactor) + "_self_t"; - } - - /** Construct a unique type for the "self" struct of the class of the given reactor. */ - public static String selfType(ReactorInstance instance) { - return selfType(instance.tpr); - } - - /** - * Return a reference to the trigger_t struct of the specified - * trigger instance (input port or action). This trigger_t struct - * is on the self struct. - * @param instance The port or action instance. - */ - public static String triggerRef(TriggerInstance instance) { - return triggerRef(instance, null); - } - - /** - * Return a reference to the trigger_t struct of the specified - * trigger instance (input port or action). This trigger_t struct - * is on the self struct. - * @param instance The port or action instance. - * @param runtimeIndex An optional index variable name to use to address runtime instances. - */ - public static String triggerRef(TriggerInstance instance, String runtimeIndex) { - return reactorRef(instance.getParent(), runtimeIndex) - + "->_lf__" - + instance.getName(); - } - - /** - * Return a reference to the trigger_t struct for the specified - * port of a contained reactor. - * @param port The output port of a contained reactor. - */ - public static String triggerRefNested(PortInstance port) { - return triggerRefNested(port, null, null); - } - - /** - * Return a reference to the trigger_t struct for the specified - * port of a contained reactor. - * @param port The output port of a contained reactor. - * @param runtimeIndex An optional index variable name to use to index - * the runtime instance of the port's parent's parent, or null to get the - * default returned by {@link CUtil#runtimeIndex(ReactorInstance)}. - * @param bankIndex An optional index variable name to use to index - * the the bank of the port's parent, or null to get the default returned by - * {@link CUtil#bankIndex(ReactorInstance)}. - */ - public static String triggerRefNested(PortInstance port, String runtimeIndex, String bankIndex) { - return reactorRefNested(port.getParent(), runtimeIndex, bankIndex) + "." + port.getName() + "_trigger"; - } - - - ////////////////////////////////////////////////////// - //// FIXME: Not clear what the strategy is with the following inner interface. - // The {@code ReportCommandErrors} interface allows the - // method runBuildCommand to call a protected - // method from the CGenerator if that method is passed - // using a method reference. The method that is passed - // is then interpreted as a ReportCommandErrors instance. - // This is a convenient way to factor out part of the - // internals of the CGenerator while maintaining - // encapsulation, even though the internals of the CGenerator - // might seem to be tightly coupled. FIXME: Delete this comment - - /** - * A {@code ReportCommandErrors} is a way to analyze command - * output and report any errors that it describes. - * FIXME: If the VSCode branch passes code review - * without significant revision, this mechanism will probably be replaced. - */ - public interface ReportCommandErrors { - void report(String errors); - } - - /** - * Run the custom build command specified with the "build" parameter. - * This command is executed in the same directory as the source file. - *

    - * The following environment variables will be available to the command: - *

      - *
    • {@code: LF_CURRENT_WORKING_DIRECTORY}: The directory in which the command is invoked. - *
    • {@code:LF_SOURCE_DIRECTORY}: The directory containing the .lf file being compiled. - *
    • {@code:LF_PACKAGE_DIRECTORY}: The directory that is the root of the package. - *
    • {@code:LF_SOURCE_GEN_DIRECTORY}: The directory in which generated files are placed. - *
    • {@code:LF_BIN_DIRECTORY}: The directory into which to put binaries. - *
    - */ - public static void runBuildCommand( - FileConfig fileConfig, - TargetConfig targetConfig, - GeneratorCommandFactory commandFactory, - ErrorReporter errorReporter, - ReportCommandErrors reportCommandErrors, - LFGeneratorContext.Mode mode - ) { - List commands = getCommands(targetConfig.buildCommands, commandFactory, fileConfig.srcPath); - // If the build command could not be found, abort. - // An error has already been reported in createCommand. - if (commands.stream().anyMatch(Objects::isNull)) return; - - for (LFCommand cmd : commands) { - int returnCode = cmd.run(); - if (returnCode != 0 && mode != LFGeneratorContext.Mode.EPOCH) { - errorReporter.reportError(String.format( - // FIXME: Why is the content of stderr not provided to the user in this error message? - "Build command \"%s\" failed with error code %d.", - targetConfig.buildCommands, returnCode - )); - return; - } - // For warnings (vs. errors), the return code is 0. - // But we still want to mark the IDE. - if (!cmd.getErrors().toString().isEmpty() && mode == LFGeneratorContext.Mode.EPOCH) { - reportCommandErrors.report(cmd.getErrors().toString()); - return; // FIXME: Why do we return here? Even if there are warnings, the build process should proceed. - } - } - } - - - /** - * Remove files in the bin directory that may have been created. - * Call this if a compilation occurs so that files from a previous - * version do not accidentally get executed. - * @param fileConfig - */ - public static void deleteBinFiles(FileConfig fileConfig) { - String name = FileUtil.nameWithoutExtension(fileConfig.srcFile); - String[] files = fileConfig.binPath.toFile().list(); - List federateNames = new LinkedList<>(); // FIXME: put this in ASTUtils? - fileConfig.resource.getAllContents().forEachRemaining(node -> { - if (node instanceof Reactor r) { + result.append(bankIndexName(reactor)); + width = reactor.getWidth(); + } + reactor = reactor.getParent(); + } + while (parens-- > 0) { + result.append(")"); + } + if (result.length() == 0) return "0"; + return result.toString(); + } + + /** + * Return a unique type for the "self" struct of the specified reactor class from the reactor + * class. + * + * @param reactor The reactor class. + * @return The type of a self struct for the specified reactor class. + */ + public static String selfType(TypeParameterizedReactor reactor) { + if (reactor.reactor().isMain()) { + return "_" + CUtil.getName(reactor) + "_main_self_t"; + } + return "_" + CUtil.getName(reactor) + "_self_t"; + } + + /** Construct a unique type for the "self" struct of the class of the given reactor. */ + public static String selfType(ReactorInstance instance) { + return selfType(instance.tpr); + } + + /** + * Return a reference to the trigger_t struct of the specified trigger instance (input port or + * action). This trigger_t struct is on the self struct. + * + * @param instance The port or action instance. + */ + public static String triggerRef(TriggerInstance instance) { + return triggerRef(instance, null); + } + + /** + * Return a reference to the trigger_t struct of the specified trigger instance (input port or + * action). This trigger_t struct is on the self struct. + * + * @param instance The port or action instance. + * @param runtimeIndex An optional index variable name to use to address runtime instances. + */ + public static String triggerRef( + TriggerInstance instance, String runtimeIndex) { + return reactorRef(instance.getParent(), runtimeIndex) + "->_lf__" + instance.getName(); + } + + /** + * Return a reference to the trigger_t struct for the specified port of a contained reactor. + * + * @param port The output port of a contained reactor. + */ + public static String triggerRefNested(PortInstance port) { + return triggerRefNested(port, null, null); + } + + /** + * Return a reference to the trigger_t struct for the specified port of a contained reactor. + * + * @param port The output port of a contained reactor. + * @param runtimeIndex An optional index variable name to use to index the runtime instance of the + * port's parent's parent, or null to get the default returned by {@link + * CUtil#runtimeIndex(ReactorInstance)}. + * @param bankIndex An optional index variable name to use to index the the bank of the port's + * parent, or null to get the default returned by {@link CUtil#bankIndex(ReactorInstance)}. + */ + public static String triggerRefNested(PortInstance port, String runtimeIndex, String bankIndex) { + return reactorRefNested(port.getParent(), runtimeIndex, bankIndex) + + "." + + port.getName() + + "_trigger"; + } + + ////////////////////////////////////////////////////// + //// FIXME: Not clear what the strategy is with the following inner interface. + // The {@code ReportCommandErrors} interface allows the + // method runBuildCommand to call a protected + // method from the CGenerator if that method is passed + // using a method reference. The method that is passed + // is then interpreted as a ReportCommandErrors instance. + // This is a convenient way to factor out part of the + // internals of the CGenerator while maintaining + // encapsulation, even though the internals of the CGenerator + // might seem to be tightly coupled. FIXME: Delete this comment + + /** + * A {@code ReportCommandErrors} is a way to analyze command output and report any errors that it + * describes. FIXME: If the VSCode branch passes code review without significant revision, this + * mechanism will probably be replaced. + */ + public interface ReportCommandErrors { + void report(String errors); + } + + /** + * Run the custom build command specified with the "build" parameter. This command is executed in + * the same directory as the source file. + * + *

    The following environment variables will be available to the command: + * + *

      + *
    • {@code: LF_CURRENT_WORKING_DIRECTORY}: The directory in which the command is invoked. + *
    • {@code:LF_SOURCE_DIRECTORY}: The directory containing the .lf file being compiled. + *
    • {@code:LF_PACKAGE_DIRECTORY}: The directory that is the root of the package. + *
    • {@code:LF_SOURCE_GEN_DIRECTORY}: The directory in which generated files are placed. + *
    • {@code:LF_BIN_DIRECTORY}: The directory into which to put binaries. + *
    + */ + public static void runBuildCommand( + FileConfig fileConfig, + TargetConfig targetConfig, + GeneratorCommandFactory commandFactory, + ErrorReporter errorReporter, + ReportCommandErrors reportCommandErrors, + LFGeneratorContext.Mode mode) { + List commands = + getCommands(targetConfig.buildCommands, commandFactory, fileConfig.srcPath); + // If the build command could not be found, abort. + // An error has already been reported in createCommand. + if (commands.stream().anyMatch(Objects::isNull)) return; + + for (LFCommand cmd : commands) { + int returnCode = cmd.run(); + if (returnCode != 0 && mode != LFGeneratorContext.Mode.EPOCH) { + errorReporter.reportError( + String.format( + // FIXME: Why is the content of stderr not provided to the user in this error + // message? + "Build command \"%s\" failed with error code %d.", + targetConfig.buildCommands, returnCode)); + return; + } + // For warnings (vs. errors), the return code is 0. + // But we still want to mark the IDE. + if (!cmd.getErrors().toString().isEmpty() && mode == LFGeneratorContext.Mode.EPOCH) { + reportCommandErrors.report(cmd.getErrors().toString()); + return; // FIXME: Why do we return here? Even if there are warnings, the build process + // should proceed. + } + } + } + + /** + * Remove files in the bin directory that may have been created. Call this if a compilation occurs + * so that files from a previous version do not accidentally get executed. + * + * @param fileConfig + */ + public static void deleteBinFiles(FileConfig fileConfig) { + String name = FileUtil.nameWithoutExtension(fileConfig.srcFile); + String[] files = fileConfig.binPath.toFile().list(); + List federateNames = new LinkedList<>(); // FIXME: put this in ASTUtils? + fileConfig + .resource + .getAllContents() + .forEachRemaining( + node -> { + if (node instanceof Reactor r) { if (r.isFederated()) { - r.getInstantiations().forEach(inst -> federateNames - .add(inst.getName())); + r.getInstantiations().forEach(inst -> federateNames.add(inst.getName())); } - } - }); - for (String f : files) { - // Delete executable file or launcher script, if any. - // Delete distribution file, if any. - // Delete RTI file, if any. - if (f.equals(name) || f.equals(name + RTI_BIN_SUFFIX) - || f.equals(name + RTI_DISTRIBUTION_SCRIPT_SUFFIX)) { - //noinspection ResultOfMethodCallIgnored - fileConfig.binPath.resolve(f).toFile().delete(); - } - // Delete federate executable files, if any. - for (String federateName : federateNames) { - if (f.equals(name + "_" + federateName)) { - //noinspection ResultOfMethodCallIgnored - fileConfig.binPath.resolve(f).toFile().delete(); - } - } + } + }); + for (String f : files) { + // Delete executable file or launcher script, if any. + // Delete distribution file, if any. + // Delete RTI file, if any. + if (f.equals(name) + || f.equals(name + RTI_BIN_SUFFIX) + || f.equals(name + RTI_DISTRIBUTION_SCRIPT_SUFFIX)) { + //noinspection ResultOfMethodCallIgnored + fileConfig.binPath.resolve(f).toFile().delete(); + } + // Delete federate executable files, if any. + for (String federateName : federateNames) { + if (f.equals(name + "_" + federateName)) { + //noinspection ResultOfMethodCallIgnored + fileConfig.binPath.resolve(f).toFile().delete(); } - } - - ////////////////////////////////////////////////////// - //// Private functions. - - /** - * If the argument is a multiport, then return a string that - * gives the width as an expression, and otherwise, return null. - * The string will be empty if the width is variable (specified - * as '[]'). Otherwise, if is a single term or a sum of terms - * (separated by '+'), where each term is either an integer - * or a parameter reference in the target language. - */ - public static String multiportWidthExpression(Variable variable) { - List spec = multiportWidthTerms(variable); - return spec == null ? null : String.join(" + ", spec); - } - - ////////////////////////////////////////////////////// - //// Private methods. - - /** - * Convert the given commands from strings to their LFCommand - * representation and return a list of LFCommand. - * @param commands A list of commands as strings. - * @param factory A command factory. - * @param dir The directory in which the commands should be executed. - * @return The LFCommand representations of the given commands, - * where {@code null} is a placeholder for commands that cannot be - * executed. - */ - private static List getCommands(List commands, GeneratorCommandFactory factory, Path dir) { - return commands.stream() - .map(cmd -> List.of(cmd.split("\\s+"))) - .filter(tokens -> tokens.size() > 0) - .map(tokens -> factory.createCommand(tokens.get(0), tokens.subList(1, tokens.size()), dir)) - .collect(Collectors.toList()); - } - - /** - * Return target code for a parameter reference, which in - * this case is just the parameter name. - * - * @param param The parameter to generate code for. - * @return Parameter reference in target code. - */ - private static String getTargetReference(Parameter param) { - return param.getName(); - } - - /** - * If the argument is a multiport, return a list of strings - * describing the width of the port, and otherwise, return null. - * If the list is empty, then the width is variable (specified - * as '[]'). Otherwise, it is a list of integers and/or parameter - * references. - * @param variable The port. - * @return The width specification for a multiport or null if it is - * not a multiport. - */ - private static List multiportWidthTerms(Variable variable) { - List result = null; - if (variable instanceof Port) { - if (((Port) variable).getWidthSpec() != null) { - result = new ArrayList<>(); - if (!((Port) variable).getWidthSpec().isOfVariableLength()) { - for (WidthTerm term : ((Port) variable).getWidthSpec().getTerms()) { - if (term.getParameter() != null) { - result.add(getTargetReference(term.getParameter())); - } else { - result.add(String.valueOf(term.getWidth())); - } - } - } + } + } + } + + ////////////////////////////////////////////////////// + //// Private functions. + + /** + * If the argument is a multiport, then return a string that gives the width as an expression, and + * otherwise, return null. The string will be empty if the width is variable (specified as '[]'). + * Otherwise, if is a single term or a sum of terms (separated by '+'), where each term is either + * an integer or a parameter reference in the target language. + */ + public static String multiportWidthExpression(Variable variable) { + List spec = multiportWidthTerms(variable); + return spec == null ? null : String.join(" + ", spec); + } + + ////////////////////////////////////////////////////// + //// Private methods. + + /** + * Convert the given commands from strings to their LFCommand representation and return a list of + * LFCommand. + * + * @param commands A list of commands as strings. + * @param factory A command factory. + * @param dir The directory in which the commands should be executed. + * @return The LFCommand representations of the given commands, where {@code null} is a + * placeholder for commands that cannot be executed. + */ + private static List getCommands( + List commands, GeneratorCommandFactory factory, Path dir) { + return commands.stream() + .map(cmd -> List.of(cmd.split("\\s+"))) + .filter(tokens -> tokens.size() > 0) + .map(tokens -> factory.createCommand(tokens.get(0), tokens.subList(1, tokens.size()), dir)) + .collect(Collectors.toList()); + } + + /** + * Return target code for a parameter reference, which in this case is just the parameter name. + * + * @param param The parameter to generate code for. + * @return Parameter reference in target code. + */ + private static String getTargetReference(Parameter param) { + return param.getName(); + } + + /** + * If the argument is a multiport, return a list of strings describing the width of the port, and + * otherwise, return null. If the list is empty, then the width is variable (specified as '[]'). + * Otherwise, it is a list of integers and/or parameter references. + * + * @param variable The port. + * @return The width specification for a multiport or null if it is not a multiport. + */ + private static List multiportWidthTerms(Variable variable) { + List result = null; + if (variable instanceof Port) { + if (((Port) variable).getWidthSpec() != null) { + result = new ArrayList<>(); + if (!((Port) variable).getWidthSpec().isOfVariableLength()) { + for (WidthTerm term : ((Port) variable).getWidthSpec().getTerms()) { + if (term.getParameter() != null) { + result.add(getTargetReference(term.getParameter())); + } else { + result.add(String.valueOf(term.getWidth())); } + } } - return result; - } - - /** - * Given a type for an input or output, return true if it should be - * carried by a lf_token_t struct rather than the type itself. - * It should be carried by such a struct if the type ends with * - * (it is a pointer) or [] (it is a array with unspecified length). - * @param type The type specification. - */ - public static boolean isTokenType(InferredType type, CTypes types) { - if (type.isUndefined()) return false; - // This is a hacky way to do this. It is now considered to be a bug (#657) - return type.isVariableSizeList || type.astType != null && (!type.astType.getStars().isEmpty() || - type.astType.getCode() != null && type.astType.getCode().getBody().stripTrailing().endsWith("*")); - } - - public static String generateWidthVariable(String var) { - return var + "_width"; - } - - /** If the type specification of the form {@code type[]}, - * {@code type*}, or {@code type}, return the type. - * @param type A string describing the type. - */ - public static String rootType(String type) { - if (type.endsWith("]")) { - return type.substring(0, type.indexOf("[")).trim(); - } else if (type.endsWith("*")) { - return type.substring(0, type.length() - 1).trim(); - } else { - return type.trim(); - } - } - - /** - * Return the full name of the specified instance without - * the leading name of the top-level reactor, unless this - * is the top-level reactor, in which case return its name. - * @param instance The instance. - * @return A shortened instance name. - */ - public static String getShortenedName(ReactorInstance instance) { - var description = instance.getFullName(); - // If not at the top level, strip off the name of the top level. - var period = description.indexOf("."); - if (period > 0) { - description = description.substring(period + 1); - } - return description; - } + } + } + return result; + } + + /** + * Given a type for an input or output, return true if it should be carried by a lf_token_t struct + * rather than the type itself. It should be carried by such a struct if the type ends with * (it + * is a pointer) or [] (it is a array with unspecified length). + * + * @param type The type specification. + */ + public static boolean isTokenType(InferredType type, CTypes types) { + if (type.isUndefined()) return false; + // This is a hacky way to do this. It is now considered to be a bug (#657) + return type.isVariableSizeList + || type.astType != null + && (!type.astType.getStars().isEmpty() + || type.astType.getCode() != null + && type.astType.getCode().getBody().stripTrailing().endsWith("*")); + } + + public static String generateWidthVariable(String var) { + return var + "_width"; + } + + /** + * If the type specification of the form {@code type[]}, {@code type*}, or {@code type}, return + * the type. + * + * @param type A string describing the type. + */ + public static String rootType(String type) { + if (type.endsWith("]")) { + return type.substring(0, type.indexOf("[")).trim(); + } else if (type.endsWith("*")) { + return type.substring(0, type.length() - 1).trim(); + } else { + return type.trim(); + } + } + + /** + * Return the full name of the specified instance without the leading name of the top-level + * reactor, unless this is the top-level reactor, in which case return its name. + * + * @param instance The instance. + * @return A shortened instance name. + */ + public static String getShortenedName(ReactorInstance instance) { + var description = instance.getFullName(); + // If not at the top level, strip off the name of the top level. + var period = description.indexOf("."); + if (period > 0) { + description = description.substring(period + 1); + } + return description; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java index d403c1cddc..f864ca2661 100644 --- a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java @@ -2,15 +2,15 @@ * @file * @author Benjamin Asch * @author Edward A. Lee - * @copyright (c) 2023, The University of California at Berkeley. - * License: BSD 2-clause + * @copyright (c) 2023, The University of California at Berkeley. License: BSD 2-clause * @brief Code generation methods for watchdogs in C. */ package org.lflang.generator.c; import java.util.List; -import org.lflang.ast.ASTUtils; import org.lflang.ErrorReporter; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Mode; @@ -21,11 +21,9 @@ import org.lflang.lf.Watchdog; /** - * @brief Generate C code for watchdogs. - * This class contains a collection of static methods supporting code generation in C - * for watchdogs. These methods are protected because they are intended to be used - * only within the same package. - * + * @brief Generate C code for watchdogs. This class contains a collection of static methods + * supporting code generation in C for watchdogs. These methods are protected because they are + * intended to be used only within the same package. * @author Benjamin Asch * @author Edward A. Lee */ @@ -33,6 +31,7 @@ public class CWatchdogGenerator { /** * Return true if the given reactor has one or more watchdogs. + * * @param reactor The reactor. * @return True if the given reactor has watchdogs. */ @@ -46,9 +45,10 @@ public static boolean hasWatchdogs(Reactor reactor) { // Protected methods /** - * For the specified reactor instance, generate initialization code for each watchdog - * in the reactor. This code initializes the watchdog-related fields on the self struct - * of the reactor instance. + * For the specified reactor instance, generate initialization code for each watchdog in the + * reactor. This code initializes the watchdog-related fields on the self struct of the reactor + * instance. + * * @param code The place to put the code * @param instance The reactor instance * @return The count of watchdogs found in the reactor @@ -58,19 +58,24 @@ protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstan var temp = new CodeBuilder(); var reactorRef = CUtil.reactorRef(instance); int watchdogCount = 0; - for (Watchdog watchdog - : ASTUtils.allWatchdogs(ASTUtils.toDefinition(instance.getDefinition().getReactorClass()))) { + for (Watchdog watchdog : + ASTUtils.allWatchdogs(ASTUtils.toDefinition(instance.getDefinition().getReactorClass()))) { var watchdogField = reactorRef + "->_lf_watchdog_" + watchdog.getName(); - temp.pr(String.join("\n", - "_lf_watchdogs[watchdog_number++] = &" + watchdogField + ";", - watchdogField + ".min_expiration = " - + CTypes.getInstance().getTargetTimeExpr(instance.getTimeValue(watchdog.getTimeout())) - + ";", - watchdogField + ".thread_active = false;", - "if (" + watchdogField + ".base->reactor_mutex == NULL) {", - " " + watchdogField + ".base->reactor_mutex = (lf_mutex_t*)calloc(1, sizeof(lf_mutex_t));", - "}" - )); + temp.pr( + String.join( + "\n", + "_lf_watchdogs[watchdog_number++] = &" + watchdogField + ";", + watchdogField + + ".min_expiration = " + + CTypes.getInstance() + .getTargetTimeExpr(instance.getTimeValue(watchdog.getTimeout())) + + ";", + watchdogField + ".thread_active = false;", + "if (" + watchdogField + ".base->reactor_mutex == NULL) {", + " " + + watchdogField + + ".base->reactor_mutex = (lf_mutex_t*)calloc(1, sizeof(lf_mutex_t));", + "}")); watchdogCount += 1; foundOne = true; } @@ -92,8 +97,10 @@ protected static int generateInitializeWatchdogs(CodeBuilder code, ReactorInstan * @param tpr The reactor declaration */ protected static void generateWatchdogs( - CodeBuilder src, CodeBuilder header, TypeParameterizedReactor tpr, ErrorReporter errorReporter - ) { + CodeBuilder src, + CodeBuilder header, + TypeParameterizedReactor tpr, + ErrorReporter errorReporter) { if (hasWatchdogs(tpr.reactor())) { header.pr("#include \"core/threaded/watchdog.h\""); for (Watchdog watchdog : ASTUtils.allWatchdogs(tpr.reactor())) { @@ -104,6 +111,7 @@ protected static void generateWatchdogs( /** * Generate watchdog definitions in the reactor's self struct. + * * @param body The place to put the definitions * @param tpr The concrete reactor class * @param constructorCode The place to put initialization code. @@ -135,34 +143,31 @@ protected static void generateWatchdogStruct( + watchdogName + ".trigger = &(self->_lf__" + watchdogName - + ");" - ) - ); + + ");")); } } /** * Generate a global table of watchdog structs. + * * @param count The number of watchdogs found. * @return The code that defines the table or a comment if count is 0. */ protected static String generateWatchdogTable(int count) { if (count == 0) { - return String.join("\n", + return String.join( + "\n", "// No watchdogs found.", "typedef void watchdog_t;", "watchdog_t* _lf_watchdogs = NULL;", - "int _lf_watchdog_count = 0;" - ); + "int _lf_watchdog_count = 0;"); } return String.join( "\n", List.of( "// Array of pointers to watchdog structs.", "watchdog_t* _lf_watchdogs[" + count + "];", - "int _lf_watchdog_count = " + count + ";" - ) - ); + "int _lf_watchdog_count = " + count + ";")); } ///////////////////////////////////////////////////////////////// @@ -175,10 +180,7 @@ protected static String generateWatchdogTable(int count) { * @param tpr The concrete reactor class that has the watchdog */ private static String generateInitializationForWatchdog( - Watchdog watchdog, - TypeParameterizedReactor tpr, - ErrorReporter errorReporter - ) { + Watchdog watchdog, TypeParameterizedReactor tpr, ErrorReporter errorReporter) { // Construct the reactionInitialization code to go into // the body of the function before the verbatim code. @@ -219,14 +221,15 @@ private static String generateInitializationForWatchdog( + name + "_change_type = " + (effect.getTransition() == ModeTransition.HISTORY - ? "history_transition" - : "reset_transition") + ? "history_transition" + : "reset_transition") + ";"); } else { - errorReporter.reportError( - watchdog, - "In generateInitializationForWatchdog(): " + name + " not a valid mode of this reactor." - ); + errorReporter.reportError( + watchdog, + "In generateInitializationForWatchdog(): " + + name + + " not a valid mode of this reactor."); } } } @@ -264,11 +267,9 @@ private static String generateFunction(String header, String init, Watchdog watc return function.toString(); } - /** Generate the watchdog handler function. */ private static String generateWatchdogFunction( - Watchdog watchdog, TypeParameterizedReactor tpr, ErrorReporter errorReporter - ) { + Watchdog watchdog, TypeParameterizedReactor tpr, ErrorReporter errorReporter) { return generateFunction( generateWatchdogFunctionHeader(watchdog, tpr), generateInitializationForWatchdog(watchdog, tpr, errorReporter), @@ -282,7 +283,8 @@ private static String generateWatchdogFunction( * @param tpr The concrete reactor class * @return The function name for the watchdog function. */ - private static String generateWatchdogFunctionHeader(Watchdog watchdog, TypeParameterizedReactor tpr) { + private static String generateWatchdogFunctionHeader( + Watchdog watchdog, TypeParameterizedReactor tpr) { String functionName = watchdogFunctionName(watchdog, tpr); return CReactionGenerator.generateFunctionHeader(functionName); } diff --git a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java index 20ed65687b..16f5ceb565 100644 --- a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java +++ b/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java @@ -5,7 +5,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; - import org.lflang.ast.ASTUtils; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; @@ -23,131 +22,125 @@ * @author Soroush Bateni * @author Hou Seng Wong */ - public class InteractingContainedReactors { - /** - * Data structure that for each instantiation of a contained - * reactor. This provides a set of input and output ports that trigger - * reactions of the container, are read by a reaction of the - * container, or that receive data from a reaction of the container. - * For each port, this provides a list of reaction indices that - * are triggered by the port, or an empty list if there are no - * reactions triggered by the port. - */ - // This horrible data structure is a collection, indexed by instantiation - // of a contained reactor, of lists, indexed by ports of the contained reactor - // that are referenced by reactions of the container, of reactions that are - // triggered by the port of the contained reactor. The list is empty if - // the port does not trigger reactions but is read by the reaction or - // is written to by the reaction. - LinkedHashMap< - Instantiation, LinkedHashMap< - Port, LinkedList - > - > portsByContainedReactor = new LinkedHashMap<>(); + /** + * Data structure that for each instantiation of a contained reactor. This provides a set of input + * and output ports that trigger reactions of the container, are read by a reaction of the + * container, or that receive data from a reaction of the container. For each port, this provides + * a list of reaction indices that are triggered by the port, or an empty list if there are no + * reactions triggered by the port. + */ + // This horrible data structure is a collection, indexed by instantiation + // of a contained reactor, of lists, indexed by ports of the contained reactor + // that are referenced by reactions of the container, of reactions that are + // triggered by the port of the contained reactor. The list is empty if + // the port does not trigger reactions but is read by the reaction or + // is written to by the reaction. + LinkedHashMap>> portsByContainedReactor = + new LinkedHashMap<>(); - /** - * Scan the reactions of the specified reactor and record which ports are - * referenced by reactions and which reactions are triggered by such ports. - */ - public InteractingContainedReactors(Reactor reactor) { - var reactionCount = 0; - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // First, handle reactions that produce data sent to inputs - // of contained reactors. - for (VarRef effect : ASTUtils.convertToEmptyListIfNull(reaction.getEffects())) { - // If an effect is an input, then it must be an input - // of a contained reactor. - if (effect.getVariable() instanceof Input) { - // This reaction is not triggered by the port, so - // we do not add it to the list returned by the following. - addPort(effect.getContainer(), (Input) effect.getVariable()); - } - } - // Second, handle reactions that are triggered by outputs - // of contained reactors. - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - // If an trigger is an output, then it must be an output - // of a contained reactor. - if (triggerAsVarRef.getVariable() instanceof Output) { - var list = addPort(triggerAsVarRef.getContainer(), (Output) triggerAsVarRef.getVariable()); - list.add(reactionCount); - } - } - } - // Third, handle reading (but not triggered by) - // outputs of contained reactors. - for (VarRef source : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - if (source.getVariable() instanceof Output) { - // If an source is an output, then it must be an output - // of a contained reactor. - // This reaction is not triggered by the port, so - // we do not add it to the list returned by the following. - addPort(source.getContainer(), (Output) source.getVariable()); - } - } - // Increment the reaction count even if not in the federate for consistency. - reactionCount++; + /** + * Scan the reactions of the specified reactor and record which ports are referenced by reactions + * and which reactions are triggered by such ports. + */ + public InteractingContainedReactors(Reactor reactor) { + var reactionCount = 0; + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // First, handle reactions that produce data sent to inputs + // of contained reactors. + for (VarRef effect : ASTUtils.convertToEmptyListIfNull(reaction.getEffects())) { + // If an effect is an input, then it must be an input + // of a contained reactor. + if (effect.getVariable() instanceof Input) { + // This reaction is not triggered by the port, so + // we do not add it to the list returned by the following. + addPort(effect.getContainer(), (Input) effect.getVariable()); + } + } + // Second, handle reactions that are triggered by outputs + // of contained reactors. + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { + // If an trigger is an output, then it must be an output + // of a contained reactor. + if (triggerAsVarRef.getVariable() instanceof Output) { + var list = + addPort(triggerAsVarRef.getContainer(), (Output) triggerAsVarRef.getVariable()); + list.add(reactionCount); + } + } + } + // Third, handle reading (but not triggered by) + // outputs of contained reactors. + for (VarRef source : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (source.getVariable() instanceof Output) { + // If an source is an output, then it must be an output + // of a contained reactor. + // This reaction is not triggered by the port, so + // we do not add it to the list returned by the following. + addPort(source.getContainer(), (Output) source.getVariable()); } + } + // Increment the reaction count even if not in the federate for consistency. + reactionCount++; } + } - /** - * Return or create the list to which reactions triggered by the specified port - * are to be added. This also records that the port is referenced by the - * container's reactions. - * @param containedReactor The contained reactor. - * @param port The port. - */ - private List addPort(Instantiation containedReactor, Port port) { - // Get or create the entry for the containedReactor. - var containedReactorEntry = portsByContainedReactor.computeIfAbsent( - containedReactor, - k -> new LinkedHashMap<>() - ); - // Get or create the entry for the port. - return containedReactorEntry.computeIfAbsent(port, k -> new LinkedList<>()); - } + /** + * Return or create the list to which reactions triggered by the specified port are to be added. + * This also records that the port is referenced by the container's reactions. + * + * @param containedReactor The contained reactor. + * @param port The port. + */ + private List addPort(Instantiation containedReactor, Port port) { + // Get or create the entry for the containedReactor. + var containedReactorEntry = + portsByContainedReactor.computeIfAbsent(containedReactor, k -> new LinkedHashMap<>()); + // Get or create the entry for the port. + return containedReactorEntry.computeIfAbsent(port, k -> new LinkedList<>()); + } - /** - * Return the set of contained reactors that have ports that are referenced - * by reactions of the container reactor. - */ - public Set containedReactors() { - return portsByContainedReactor.keySet(); - } + /** + * Return the set of contained reactors that have ports that are referenced by reactions of the + * container reactor. + */ + public Set containedReactors() { + return portsByContainedReactor.keySet(); + } - /** - * Return the set of ports of the specified contained reactor that are - * referenced by reactions of the container reactor. Return an empty - * set if there are none. - * @param containedReactor The contained reactor. - */ - public Set portsOfInstance(Instantiation containedReactor) { - Set result = null; - var ports = portsByContainedReactor.get(containedReactor); - if (ports == null) { - result = new LinkedHashSet<>(); - } else { - result = ports.keySet(); - } - return result; + /** + * Return the set of ports of the specified contained reactor that are referenced by reactions of + * the container reactor. Return an empty set if there are none. + * + * @param containedReactor The contained reactor. + */ + public Set portsOfInstance(Instantiation containedReactor) { + Set result = null; + var ports = portsByContainedReactor.get(containedReactor); + if (ports == null) { + result = new LinkedHashSet<>(); + } else { + result = ports.keySet(); } + return result; + } - /** - * Return the indices of the reactions triggered by the specified port - * of the specified contained reactor or an empty list if there are none. - * @param containedReactor The contained reactor. - * @param port The port. - */ - public List reactionsTriggered(Instantiation containedReactor, Port port) { - var ports = portsByContainedReactor.get(containedReactor); - if (ports != null) { - var list = ports.get(port); - if (list != null) { - return list; - } - } - return new LinkedList<>(); + /** + * Return the indices of the reactions triggered by the specified port of the specified contained + * reactor or an empty list if there are none. + * + * @param containedReactor The contained reactor. + * @param port The port. + */ + public List reactionsTriggered(Instantiation containedReactor, Port port) { + var ports = portsByContainedReactor.get(containedReactor); + if (ports != null) { + var list = ports.get(port); + if (list != null) { + return list; + } } + return new LinkedList<>(); + } } diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 5f832e692a..c5e062399b 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -1,12 +1,10 @@ package org.lflang.generator.c; - import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; - -import org.lflang.ast.ASTUtils; import org.lflang.InferredType; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Instantiation; import org.lflang.lf.Reactor; @@ -14,62 +12,79 @@ /** * A reactor class combined with concrete type arguments bound to its type parameters. + * * @param reactor The syntactic reactor class definition * @param typeArgs The type arguments associated with this particular variant of the reactor class. */ public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { - public TypeParameterizedReactor(Instantiation i) { - this(ASTUtils.toDefinition(i.getReactorClass()), addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); - } + public TypeParameterizedReactor(Instantiation i) { + this( + ASTUtils.toDefinition(i.getReactorClass()), + addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); + } - private static Map addTypeArgs(Instantiation instantiation, Reactor r) { - HashMap ret = new HashMap<>(); - if (instantiation.getTypeArgs() != null) { - for (int i = 0; i < r.getTypeParms().size(); i++) { - ret.put(r.getTypeParms().get(i).getLiteral(), instantiation.getTypeArgs().get(i)); - } - } - return ret; + private static Map addTypeArgs(Instantiation instantiation, Reactor r) { + HashMap ret = new HashMap<>(); + if (instantiation.getTypeArgs() != null) { + for (int i = 0; i < r.getTypeParms().size(); i++) { + ret.put(r.getTypeParms().get(i).getLiteral(), instantiation.getTypeArgs().get(i)); + } } + return ret; + } - /** Return the name of the reactor given its type arguments. */ - public String getName() { - // FIXME: Types that are not just a single token need to be escaped or hashed - return reactor.getName() + typeArgs.values().stream().map(ASTUtils::toOriginalText).collect(Collectors.joining("_")); - } + /** Return the name of the reactor given its type arguments. */ + public String getName() { + // FIXME: Types that are not just a single token need to be escaped or hashed + return reactor.getName() + + typeArgs.values().stream().map(ASTUtils::toOriginalText).collect(Collectors.joining("_")); + } - /** #define type names as concrete types. */ - public void doDefines(CodeBuilder b) { - typeArgs.forEach((literal, concreteType) -> b.pr( - "#if defined " + literal + "\n" + - "#undef " + literal + "\n" + - "#endif // " + literal + "\n" + - "#define " + literal + " " + ASTUtils.toOriginalText(concreteType))); - } + /** #define type names as concrete types. */ + public void doDefines(CodeBuilder b) { + typeArgs.forEach( + (literal, concreteType) -> + b.pr( + "#if defined " + + literal + + "\n" + + "#undef " + + literal + + "\n" + + "#endif // " + + literal + + "\n" + + "#define " + + literal + + " " + + ASTUtils.toOriginalText(concreteType))); + } - /** Resolve type arguments if the given type is defined in terms of generics. */ - public Type resolveType(Type t) { - if (t.getId() != null && typeArgs.get(t.getId()) != null) return typeArgs.get(t.getId()); - if (t.getCode() == null) return t; - var arg = typeArgs.get(t.getCode().getBody()); - if (arg != null) return arg; - return t; - } + /** Resolve type arguments if the given type is defined in terms of generics. */ + public Type resolveType(Type t) { + if (t.getId() != null && typeArgs.get(t.getId()) != null) return typeArgs.get(t.getId()); + if (t.getCode() == null) return t; + var arg = typeArgs.get(t.getCode().getBody()); + if (arg != null) return arg; + return t; + } - /** Resolve type arguments if the given type is defined in terms of generics. */ - public InferredType resolveType(InferredType t) { - if (t.astType == null) return t; - return InferredType.fromAST(resolveType(t.astType)); - } + /** Resolve type arguments if the given type is defined in terms of generics. */ + public InferredType resolveType(InferredType t) { + if (t.astType == null) return t; + return InferredType.fromAST(resolveType(t.astType)); + } - @Override - public int hashCode() { - return Math.abs(reactor.hashCode() * 31 + typeArgs.hashCode()); - } + @Override + public int hashCode() { + return Math.abs(reactor.hashCode() * 31 + typeArgs.hashCode()); + } - @Override - public boolean equals(Object obj) { - return obj instanceof TypeParameterizedReactor other && reactor.equals(other.reactor) && typeArgs.equals(other.typeArgs); - } + @Override + public boolean equals(Object obj) { + return obj instanceof TypeParameterizedReactor other + && reactor.equals(other.reactor) + && typeArgs.equals(other.typeArgs); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PyFileConfig.java b/org.lflang/src/org/lflang/generator/python/PyFileConfig.java index bb6a9e9796..7c67b92493 100644 --- a/org.lflang/src/org/lflang/generator/python/PyFileConfig.java +++ b/org.lflang/src/org/lflang/generator/python/PyFileConfig.java @@ -3,33 +3,29 @@ import java.io.IOException; import java.nio.file.Path; import java.util.List; - import org.eclipse.emf.ecore.resource.Resource; - -import org.lflang.FileConfig; import org.lflang.generator.c.CFileConfig; import org.lflang.util.LFCommand; public class PyFileConfig extends CFileConfig { - public PyFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { - super(resource, srcGenBasePath, useHierarchicalBin); - } + public PyFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) + throws IOException { + super(resource, srcGenBasePath, useHierarchicalBin); + } - @Override - public LFCommand getCommand() { - return LFCommand.get("python3", - List.of(srcPkgPath.relativize(getExecutable()).toString()), - true, - srcPkgPath); - } + @Override + public LFCommand getCommand() { + return LFCommand.get( + "python3", List.of(srcPkgPath.relativize(getExecutable()).toString()), true, srcPkgPath); + } - @Override - public Path getExecutable() { - return srcGenPath.resolve(name + getExecutableExtension()); - } + @Override + public Path getExecutable() { + return srcGenPath.resolve(name + getExecutableExtension()); + } - @Override - protected String getExecutableExtension() { - return ".py"; - } + @Override + protected String getExecutableExtension() { + return ".py"; + } } diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index 48cc8f9e10..35aeed6fbb 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -1,28 +1,28 @@ /* Utilities for Python code generation. */ /************* -Copyright (c) 2019-2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator.python; @@ -31,116 +31,126 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.c.CUtil; import org.lflang.lf.Expression; - /** - * A collection of utilities for Python code generation. - * This class inherits from CUtil but overrides a few methods to - * codify the coding conventions for the Python target code generator. + * A collection of utilities for Python code generation. This class inherits from CUtil but + * overrides a few methods to codify the coding conventions for the Python target code generator. * I.e., it defines how some variables are named and referenced. + * * @author Edward A. Lee * @author Soroush Bateni */ public class PyUtil extends CUtil { - /** - * Return the name of the list of Python class instances that contains the - * specified reactor instance. This is similar to - * {@link #reactorRef(ReactorInstance)} except that it does not index into - * the list. - * - * @param instance The reactor instance. - */ - public static String reactorRefName(ReactorInstance instance) { - return instance.uniqueID() + "_lf"; - } - - /** - * Return a reference to the list of Python class instances that contains - * the specified reactor instance. The returned string has the form - * list_name[runtimeIndex], where list_name is the name of the list of - * Python class instances that contains this reactor instance. If - * runtimeIndex is null, then it is replaced by the expression returned by - * {@link runtimeIndex(ReactorInstance)} or 0 if there are no banks. - * - * @param instance The reactor instance. - * @param runtimeIndex An optional expression to use to address bank - * members. If this is null, the expression used will be - * that returned by - * {@link #runtimeIndex(ReactorInstance)}. - */ - public static String reactorRef(ReactorInstance instance, String runtimeIndex) { - if (runtimeIndex == null) runtimeIndex = runtimeIndex(instance); - return PyUtil.reactorRefName(instance) + "[" + runtimeIndex + "]"; - } - - /** - * Return a reference to the list of Python class instances that contains - * the specified reactor instance. The returned string has the form - * list_name[j], where list_name is the name of the list of of Python class - * instances that contains this reactor instance and j is the expression - * returned by {@link #runtimeIndex(ReactorInstance)} or 0 if there are no - * banks. - * - * @param instance The reactor instance. - */ - public static String reactorRef(ReactorInstance instance) { - return PyUtil.reactorRef(instance, null); - } - - /** - * Convert C types to formats used in Py_BuildValue and PyArg_PurseTuple. - * This is unused but will be useful to enable inter-compatibility between - * C and Python reactors. - * @param type C type - */ - public static String pyBuildValueArgumentType(String type) { - switch (type) { - case "int": return "i"; - case "string": return "s"; - case "char": return "b"; - case "short int": return "h"; - case "long": return "l"; - case "unsigned char": return "B"; - case "unsigned short int": return "H"; - case "unsigned int": return "I"; - case "unsigned long": return "k"; - case "long long": return "L"; - case "interval_t": return "L"; - case "unsigned long long": return "K"; - case "double": return "d"; - case "float": return "f"; - case "Py_complex": return "D"; - case "Py_complex*": return "D"; - case "Py_Object": return "O"; - case "Py_Object*": return "O"; - default: return "O"; - } - } - - public static String generateGILAcquireCode() { - return String.join("\n", - "// Acquire the GIL (Global Interpreter Lock) to be able to call Python APIs.", - "PyGILState_STATE gstate;", - "gstate = PyGILState_Ensure();" - ); - } - - public static String generateGILReleaseCode() { - return String.join("\n", - "/* Release the thread. No Python API allowed beyond this point. */", - "PyGILState_Release(gstate);" - ); - } - - /** - * Override to convert some C types to their - * Python equivalent. - * Examples: - * true/false -> True/False - * @param expr A value - * @return A value string in the target language - */ - protected static String getPythonTargetValue(Expression expr) { - return PythonTypes.getInstance().getTargetExpr(expr, InferredType.undefined()); + /** + * Return the name of the list of Python class instances that contains the specified reactor + * instance. This is similar to {@link #reactorRef(ReactorInstance)} except that it does not index + * into the list. + * + * @param instance The reactor instance. + */ + public static String reactorRefName(ReactorInstance instance) { + return instance.uniqueID() + "_lf"; + } + + /** + * Return a reference to the list of Python class instances that contains the specified reactor + * instance. The returned string has the form list_name[runtimeIndex], where list_name is the name + * of the list of Python class instances that contains this reactor instance. If runtimeIndex is + * null, then it is replaced by the expression returned by {@link runtimeIndex(ReactorInstance)} + * or 0 if there are no banks. + * + * @param instance The reactor instance. + * @param runtimeIndex An optional expression to use to address bank members. If this is null, the + * expression used will be that returned by {@link #runtimeIndex(ReactorInstance)}. + */ + public static String reactorRef(ReactorInstance instance, String runtimeIndex) { + if (runtimeIndex == null) runtimeIndex = runtimeIndex(instance); + return PyUtil.reactorRefName(instance) + "[" + runtimeIndex + "]"; + } + + /** + * Return a reference to the list of Python class instances that contains the specified reactor + * instance. The returned string has the form list_name[j], where list_name is the name of the + * list of of Python class instances that contains this reactor instance and j is the expression + * returned by {@link #runtimeIndex(ReactorInstance)} or 0 if there are no banks. + * + * @param instance The reactor instance. + */ + public static String reactorRef(ReactorInstance instance) { + return PyUtil.reactorRef(instance, null); + } + + /** + * Convert C types to formats used in Py_BuildValue and PyArg_PurseTuple. This is unused but will + * be useful to enable inter-compatibility between C and Python reactors. + * + * @param type C type + */ + public static String pyBuildValueArgumentType(String type) { + switch (type) { + case "int": + return "i"; + case "string": + return "s"; + case "char": + return "b"; + case "short int": + return "h"; + case "long": + return "l"; + case "unsigned char": + return "B"; + case "unsigned short int": + return "H"; + case "unsigned int": + return "I"; + case "unsigned long": + return "k"; + case "long long": + return "L"; + case "interval_t": + return "L"; + case "unsigned long long": + return "K"; + case "double": + return "d"; + case "float": + return "f"; + case "Py_complex": + return "D"; + case "Py_complex*": + return "D"; + case "Py_Object": + return "O"; + case "Py_Object*": + return "O"; + default: + return "O"; } + } + + public static String generateGILAcquireCode() { + return String.join( + "\n", + "// Acquire the GIL (Global Interpreter Lock) to be able to call Python APIs.", + "PyGILState_STATE gstate;", + "gstate = PyGILState_Ensure();"); + } + + public static String generateGILReleaseCode() { + return String.join( + "\n", + "/* Release the thread. No Python API allowed beyond this point. */", + "PyGILState_Release(gstate);"); + } + + /** + * Override to convert some C types to their Python equivalent. Examples: true/false -> True/False + * + * @param expr A value + * @return A value string in the target language + */ + protected static String getPythonTargetValue(Expression expr) { + return PythonTypes.getInstance().getTargetExpr(expr, InferredType.undefined()); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java index 13dbed0f0f..5270a4d69e 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java @@ -1,14 +1,17 @@ package org.lflang.generator.python; +import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; -import org.lflang.lf.Reactor; -import org.lflang.generator.c.CGenerator; public class PythonActionGenerator { - public static String generateAliasTypeDef(TypeParameterizedReactor tpr, Action action, - String genericActionType) { + public static String generateAliasTypeDef( + TypeParameterizedReactor tpr, Action action, String genericActionType) { - return "typedef "+genericActionType+" "+CGenerator.variableStructType(action, tpr, false)+";"; - } + return "typedef " + + genericActionType + + " " + + CGenerator.variableStructType(action, tpr, false) + + ";"; + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java index b69cfc7da0..6171f3ca40 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java @@ -1,6 +1,5 @@ package org.lflang.generator.python; - import org.lflang.ast.ASTUtils; import org.lflang.generator.c.CDelayBodyGenerator; import org.lflang.generator.c.CUtil; @@ -10,69 +9,74 @@ public class PythonDelayBodyGenerator extends CDelayBodyGenerator { - public PythonDelayBodyGenerator(PythonTypes types) { - super(types); - } + public PythonDelayBodyGenerator(PythonTypes types) { + super(types); + } - /** - * Generate code for the body of a reaction that takes an input and - * schedules an action with the value of that input. - * @param action The action to schedule - * @param port The port to read from - */ - @Override - public String generateDelayBody(Action action, VarRef port) { - boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(action), types); - String ref = ASTUtils.generateVarRef(port); - // Note that the action.type set by the base class is actually - // the port type. - if (isTokenType) { - return String.join("\n", - "if ("+ref+"->is_present) {", - " // Put the whole token on the event queue, not just the payload.", - " // This way, the length and element_size are transported.", - " lf_schedule_token("+action.getName()+", 0, "+ref+"->token);", - "}" - ); - } else { - return String.join("\n", - "// Create a token.", - "#if NUMBER_OF_WORKERS > 0", - "// Need to lock the mutex first.", - "lf_mutex_lock(&mutex);", - "#endif", - "lf_token_t* t = _lf_new_token((token_type_t*)"+action.getName()+", self->_lf_"+ref+"->value, 1);", - "#if NUMBER_OF_WORKERS > 0", - "lf_mutex_unlock(&mutex);", - "#endif", - "", - "// Pass the token along", - "lf_schedule_token("+action.getName()+", 0, t);" - ); - } + /** + * Generate code for the body of a reaction that takes an input and schedules an action with the + * value of that input. + * + * @param action The action to schedule + * @param port The port to read from + */ + @Override + public String generateDelayBody(Action action, VarRef port) { + boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(action), types); + String ref = ASTUtils.generateVarRef(port); + // Note that the action.type set by the base class is actually + // the port type. + if (isTokenType) { + return String.join( + "\n", + "if (" + ref + "->is_present) {", + " // Put the whole token on the event queue, not just the payload.", + " // This way, the length and element_size are transported.", + " lf_schedule_token(" + action.getName() + ", 0, " + ref + "->token);", + "}"); + } else { + return String.join( + "\n", + "// Create a token.", + "#if NUMBER_OF_WORKERS > 0", + "// Need to lock the mutex first.", + "lf_mutex_lock(&mutex);", + "#endif", + "lf_token_t* t = _lf_new_token((token_type_t*)" + + action.getName() + + ", self->_lf_" + + ref + + "->value, 1);", + "#if NUMBER_OF_WORKERS > 0", + "lf_mutex_unlock(&mutex);", + "#endif", + "", + "// Pass the token along", + "lf_schedule_token(" + action.getName() + ", 0, t);"); } + } - /** - * Generate code for the body of a reaction that is triggered by the - * given action and writes its value to the given port. This realizes - * the receiving end of a logical delay specified with the 'after' - * keyword. - * @param action The action that triggers the reaction - * @param port The port to write to. - */ - @Override - public String generateForwardBody(Action action, VarRef port) { - String outputName = ASTUtils.generateVarRef(port); - if (CUtil.isTokenType(ASTUtils.getInferredType(action), types)) { - return super.generateForwardBody(action, port); - } else { - return "lf_set("+outputName+", "+action.getName()+"->token->value);"; - } + /** + * Generate code for the body of a reaction that is triggered by the given action and writes its + * value to the given port. This realizes the receiving end of a logical delay specified with the + * 'after' keyword. + * + * @param action The action that triggers the reaction + * @param port The port to write to. + */ + @Override + public String generateForwardBody(Action action, VarRef port) { + String outputName = ASTUtils.generateVarRef(port); + if (CUtil.isTokenType(ASTUtils.getInferredType(action), types)) { + return super.generateForwardBody(action, port); + } else { + return "lf_set(" + outputName + ", " + action.getName() + "->token->value);"; } + } - @Override - public void finalizeReactions(Reaction delayReaction, Reaction forwardReaction) { - ASTUtils.addReactionAttribute(delayReaction, "_c_body"); - ASTUtils.addReactionAttribute(forwardReaction, "_c_body"); - } + @Override + public void finalizeReactions(Reaction delayReaction, Reaction forwardReaction) { + ASTUtils.addReactionAttribute(delayReaction, "_c_body"); + ASTUtils.addReactionAttribute(forwardReaction, "_c_body"); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonDockerGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonDockerGenerator.java index ed69ac01fc..9d1bf0fcd4 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonDockerGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonDockerGenerator.java @@ -1,7 +1,5 @@ - package org.lflang.generator.python; -import org.lflang.TargetConfig; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.c.CDockerGenerator; @@ -11,26 +9,25 @@ * @author Hou Seng Wong */ public class PythonDockerGenerator extends CDockerGenerator { - final String defaultBaseImage = "python:slim"; + final String defaultBaseImage = "python:slim"; - public PythonDockerGenerator(LFGeneratorContext context) { - super(context); - } + public PythonDockerGenerator(LFGeneratorContext context) { + super(context); + } - /** - * Generates the contents of the docker file. - */ - @Override - protected String generateDockerFileContent() { - var baseImage = defaultBaseImage; - return String.join("\n", - "# For instructions, see: https://www.lf-lang.org/docs/handbook/containerized-execution?target=py", - "FROM "+baseImage, - "WORKDIR /lingua-franca/"+context.getFileConfig().name, - "RUN set -ex && apt-get update && apt-get install -y python3-pip && pip install cmake", - "COPY . src-gen", - super.generateDefaultCompileCommand(), - "ENTRYPOINT [\"python3\", \"src-gen/"+context.getFileConfig().name+".py\"]" - ); - } + /** Generates the contents of the docker file. */ + @Override + protected String generateDockerFileContent() { + var baseImage = defaultBaseImage; + return String.join( + "\n", + "# For instructions, see:" + + " https://www.lf-lang.org/docs/handbook/containerized-execution?target=py", + "FROM " + baseImage, + "WORKDIR /lingua-franca/" + context.getFileConfig().name, + "RUN set -ex && apt-get update && apt-get install -y python3-pip && pip install cmake", + "COPY . src-gen", + super.generateDefaultCompileCommand(), + "ENTRYPOINT [\"python3\", \"src-gen/" + context.getFileConfig().name + ".py\"]"); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 83053d6897..91fdfaffad 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -34,17 +34,14 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; - -import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.Target; import org.lflang.TargetProperty; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.CodeMap; - import org.lflang.generator.GeneratorResult; import org.lflang.generator.IntegratedBuilder; import org.lflang.generator.LFGeneratorContext; @@ -66,530 +63,516 @@ import org.lflang.util.LFCommand; import org.lflang.util.StringUtil; - /** - * Generator for Python target. This class generates Python code defining each - * reactor - * class given in the input .lf file and imported .lf files. + * Generator for Python target. This class generates Python code defining each reactor class given + * in the input .lf file and imported .lf files. * - * Each class will contain all the reaction functions defined by the user in - * order, with the necessary ports/actions given as parameters. - * Moreover, each class will contain all state variables in native Python - * format. + *

    Each class will contain all the reaction functions defined by the user in order, with the + * necessary ports/actions given as parameters. Moreover, each class will contain all state + * variables in native Python format. * - * A backend is also generated using the CGenerator that interacts with the C - * code library (see CGenerator.xtend). - * The backend is responsible for passing arguments to the Python reactor + *

    A backend is also generated using the CGenerator that interacts with the C code library (see + * CGenerator.xtend). The backend is responsible for passing arguments to the Python reactor * functions. * * @author Soroush Bateni */ public class PythonGenerator extends CGenerator { - // Used to add statements that come before reactor classes and user code - private final CodeBuilder pythonPreamble = new CodeBuilder(); - - // Used to add module requirements to setup.py (delimited with ,) - private final List pythonRequiredModules = new ArrayList<>(); - - private final PythonTypes types; - - public PythonGenerator(LFGeneratorContext context) { - this(context, - new PythonTypes(), - new CCmakeGenerator( - context.getFileConfig(), - List.of("lib/python_action.c", - "lib/python_port.c", - "lib/python_tag.c", - "lib/python_time.c", - "lib/pythontarget.c" - ), - PythonGenerator::setUpMainTarget, - "install(TARGETS)" // No-op - ) - ); - } - - - private PythonGenerator(LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { - super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); - this.targetConfig.compiler = "gcc"; - this.targetConfig.compilerFlags = new ArrayList<>(); - this.targetConfig.linkerFlags = ""; - this.types = types; - } - - /** - * Generic struct for ports with primitive types and - * statically allocated arrays in Lingua Franca. - * This template is defined as - * typedef struct { - * bool is_present; - * lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record. - * int destination_channel; // -1 if there is no destination. - * PyObject* value; - * int num_destinations; - * lf_token_t* token; - * int length; - * void (*destructor) (void* value); - * void* (*copy_constructor) (void* value); - * FEDERATED_GENERIC_EXTENSION - * } generic_port_instance_struct; - * - * See reactor-c/python/lib/pythontarget.h for details. - */ - String genericPortType = "generic_port_instance_struct"; - - /** - * Generic struct for actions. - * This template is defined as - * typedef struct { - * trigger_t* trigger; - * PyObject* value; - * bool is_present; - * bool has_value; - * lf_token_t* token; - * FEDERATED_CAPSULE_EXTENSION - * } generic_action_instance_struct; - * - * See reactor-c/python/lib/pythontarget.h for details. - */ - String genericActionType = "generic_action_instance_struct"; - - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.Python; - } - - private final Set protoNames = new HashSet<>(); - - // ////////////////////////////////////////// - // // Public methods - @Override - public TargetTypes getTargetTypes() { - return types; - } - - // ////////////////////////////////////////// - // // Protected methods - - /** - * Generate all Python classes if they have a reaction - * - */ - public String generatePythonReactorClasses() { - CodeBuilder pythonClasses = new CodeBuilder(); - CodeBuilder pythonClassesInstantiation = new CodeBuilder(); - - // Generate reactor classes in Python - pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); - - // Create empty lists to hold reactor instances - pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); - - // Instantiate generated classes - pythonClassesInstantiation.pr(PythonReactorGenerator.generatePythonClassInstantiations(main, main)); - - return String.join("\n", - pythonClasses.toString(), - "", - "# Instantiate classes", - pythonClassesInstantiation.toString() - ); - } - - /** - * Generate the Python code constructed from reactor classes and - * user-written classes. - * - * @return the code body - */ - public String generatePythonCode(String pyModuleName) { - return String.join("\n", - "import os", - "import sys", - "sys.path.append(os.path.dirname(__file__))", - "# List imported names, but do not use pylint's --extension-pkg-allow-list option", - "# so that these names will be assumed present without having to compile and install.", - "# pylint: disable=no-name-in-module, import-error", - "from "+pyModuleName+" import (", - " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", - ")", - "# pylint: disable=c-extension-no-member", - "import "+pyModuleName+" as lf", - "try:", - " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", - " from LinguaFrancaBase.functions import (", - " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS, USEC,", - " USECS, WEEK, WEEKS", - " )", - " from LinguaFrancaBase.classes import Make", - "except ModuleNotFoundError:", - " print(\"No module named 'LinguaFrancaBase'. \"", - " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", - " sys.exit(1)", - "import copy", - "", - pythonPreamble.toString(), - "", - generatePythonReactorClasses(), - "", - PythonMainFunctionGenerator.generateCode() - ); - } - - /** - * Generate the necessary Python files. - */ - public Map generatePythonFiles( - String lfModuleName, - String pyModuleName, - String pyFileName - ) throws IOException { - Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); - File file = filePath.toFile(); - Files.deleteIfExists(filePath); - // Create the necessary directories - if (!file.getParentFile().exists()) { - if (!file.getParentFile().mkdirs()) { - throw new IOException( - "Failed to create directories required for the Python code generator." - ); - } - } - Map codeMaps = new HashMap<>(); - codeMaps.put(filePath, CodeMap.fromGeneratedCode( - generatePythonCode(pyModuleName))); - FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); - return codeMaps; - } - - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - @Override - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(PythonPreambleGenerator.generateCDefineDirectives( + // Used to add statements that come before reactor classes and user code + private final CodeBuilder pythonPreamble = new CodeBuilder(); + + // Used to add module requirements to setup.py (delimited with ,) + private final List pythonRequiredModules = new ArrayList<>(); + + private final PythonTypes types; + + public PythonGenerator(LFGeneratorContext context) { + this( + context, + new PythonTypes(), + new CCmakeGenerator( + context.getFileConfig(), + List.of( + "lib/python_action.c", + "lib/python_port.c", + "lib/python_tag.c", + "lib/python_time.c", + "lib/pythontarget.c"), + PythonGenerator::setUpMainTarget, + "install(TARGETS)" // No-op + )); + } + + private PythonGenerator( + LFGeneratorContext context, PythonTypes types, CCmakeGenerator cmakeGenerator) { + super(context, false, types, cmakeGenerator, new PythonDelayBodyGenerator(types)); + this.targetConfig.compiler = "gcc"; + this.targetConfig.compilerFlags = new ArrayList<>(); + this.targetConfig.linkerFlags = ""; + this.types = types; + } + + /** + * Generic struct for ports with primitive types and statically allocated arrays in Lingua Franca. + * This template is defined as typedef struct { bool is_present; lf_sparse_io_record_t* + * sparse_record; // NULL if there is no sparse record. int destination_channel; // -1 if there is + * no destination. PyObject* value; int num_destinations; lf_token_t* token; int length; void + * (*destructor) (void* value); void* (*copy_constructor) (void* value); + * FEDERATED_GENERIC_EXTENSION } generic_port_instance_struct; + * + *

    See reactor-c/python/lib/pythontarget.h for details. + */ + String genericPortType = "generic_port_instance_struct"; + + /** + * Generic struct for actions. This template is defined as typedef struct { trigger_t* trigger; + * PyObject* value; bool is_present; bool has_value; lf_token_t* token; + * FEDERATED_CAPSULE_EXTENSION } generic_action_instance_struct; + * + *

    See reactor-c/python/lib/pythontarget.h for details. + */ + String genericActionType = "generic_action_instance_struct"; + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.Python; + } + + private final Set protoNames = new HashSet<>(); + + // ////////////////////////////////////////// + // // Public methods + @Override + public TargetTypes getTargetTypes() { + return types; + } + + // ////////////////////////////////////////// + // // Protected methods + + /** Generate all Python classes if they have a reaction */ + public String generatePythonReactorClasses() { + CodeBuilder pythonClasses = new CodeBuilder(); + CodeBuilder pythonClassesInstantiation = new CodeBuilder(); + + // Generate reactor classes in Python + pythonClasses.pr(PythonReactorGenerator.generatePythonClass(main, main, types)); + + // Create empty lists to hold reactor instances + pythonClassesInstantiation.pr(PythonReactorGenerator.generateListsToHoldClassInstances(main)); + + // Instantiate generated classes + pythonClassesInstantiation.pr( + PythonReactorGenerator.generatePythonClassInstantiations(main, main)); + + return String.join( + "\n", + pythonClasses.toString(), + "", + "# Instantiate classes", + pythonClassesInstantiation.toString()); + } + + /** + * Generate the Python code constructed from reactor classes and user-written classes. + * + * @return the code body + */ + public String generatePythonCode(String pyModuleName) { + return String.join( + "\n", + "import os", + "import sys", + "sys.path.append(os.path.dirname(__file__))", + "# List imported names, but do not use pylint's --extension-pkg-allow-list option", + "# so that these names will be assumed present without having to compile and install.", + "# pylint: disable=no-name-in-module, import-error", + "from " + pyModuleName + " import (", + " Tag, action_capsule_t, port_capsule, request_stop, schedule_copy, start", + ")", + "# pylint: disable=c-extension-no-member", + "import " + pyModuleName + " as lf", + "try:", + " from LinguaFrancaBase.constants import BILLION, FOREVER, NEVER, instant_t, interval_t", + " from LinguaFrancaBase.functions import (", + " DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, MSEC, MSECS, NSEC, NSECS, SEC, SECS," + + " USEC,", + " USECS, WEEK, WEEKS", + " )", + " from LinguaFrancaBase.classes import Make", + "except ModuleNotFoundError:", + " print(\"No module named 'LinguaFrancaBase'. \"", + " \"Install using \\\"pip3 install LinguaFrancaBase\\\".\")", + " sys.exit(1)", + "import copy", + "", + pythonPreamble.toString(), + "", + generatePythonReactorClasses(), + "", + PythonMainFunctionGenerator.generateCode()); + } + + /** Generate the necessary Python files. */ + public Map generatePythonFiles( + String lfModuleName, String pyModuleName, String pyFileName) throws IOException { + Path filePath = fileConfig.getSrcGenPath().resolve(pyFileName); + File file = filePath.toFile(); + Files.deleteIfExists(filePath); + // Create the necessary directories + if (!file.getParentFile().exists()) { + if (!file.getParentFile().mkdirs()) { + throw new IOException( + "Failed to create directories required for the Python code generator."); + } + } + Map codeMaps = new HashMap<>(); + codeMaps.put(filePath, CodeMap.fromGeneratedCode(generatePythonCode(pyModuleName))); + FileUtil.writeToFile(codeMaps.get(filePath).getGeneratedCode(), filePath); + return codeMaps; + } + + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + @Override + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + PythonPreambleGenerator.generateCDefineDirectives( targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); - return code.toString(); - } - - /** - * Override generate top-level preambles, but put the user preambles in the - * .py file rather than the C file. Also handles including the federated - * execution setup preamble specified in the target config. - */ - @Override - protected String generateTopLevelPreambles(Reactor ignored) { - // user preambles - Set models = new LinkedHashSet<>(); - for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { - // The following assumes all reactors have a container. - // This means that generated reactors **have** to be - // added to a resource; not doing so will result in a NPE. - models.add((Model) ASTUtils.toDefinition(r).eContainer()); - } - // Add the main reactor if it is defined - if (this.mainDef != null) { - models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); + return code.toString(); + } + + /** + * Override generate top-level preambles, but put the user preambles in the .py file rather than + * the C file. Also handles including the federated execution setup preamble specified in the + * target config. + */ + @Override + protected String generateTopLevelPreambles(Reactor ignored) { + // user preambles + Set models = new LinkedHashSet<>(); + for (Reactor r : ASTUtils.convertToEmptyListIfNull(reactors)) { + // The following assumes all reactors have a container. + // This means that generated reactors **have** to be + // added to a resource; not doing so will result in a NPE. + models.add((Model) ASTUtils.toDefinition(r).eContainer()); + } + // Add the main reactor if it is defined + if (this.mainDef != null) { + models.add((Model) ASTUtils.toDefinition(this.mainDef.getReactorClass()).eContainer()); + } + for (Model m : models) { + pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); + } + return PythonPreambleGenerator.generateCIncludeStatements( + targetConfig, targetLanguageIsCpp(), hasModalReactors); + } + + @Override + protected void handleProtoFiles() { + for (String name : targetConfig.protoFiles) { + this.processProtoFile(name); + int dotIndex = name.lastIndexOf("."); + String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; + pythonPreamble.pr("import " + rootFilename + "_pb2 as " + rootFilename); + protoNames.add(rootFilename); + } + } + + /** + * Process a given .proto file. + * + *

    Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + @Override + public void processProtoFile(String filename) { + LFCommand protoc = + commandFactory.createCommand( + "protoc", + List.of("--python_out=" + fileConfig.getSrcGenPath(), filename), + fileConfig.srcPath); + + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); + return; + } + int returnCode = protoc.run(); + if (returnCode == 0) { + pythonRequiredModules.add("google-api-python-client"); + } else { + errorReporter.reportError("protoc returns error code " + returnCode); + } + } + + /** + * Generate the aliases for inputs, outputs, and struct type definitions for actions of the + * specified reactor in the specified federate. + * + * @param tpr The concrete reactor class. + */ + @Override + public void generateAuxiliaryStructs( + CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing) { + for (Input input : ASTUtils.allInputs(tpr.reactor())) { + generateAuxiliaryStructsForPort(builder, tpr, input); + } + for (Output output : ASTUtils.allOutputs(tpr.reactor())) { + generateAuxiliaryStructsForPort(builder, tpr, output); + } + for (Action action : ASTUtils.allActions(tpr.reactor())) { + generateAuxiliaryStructsForAction(builder, tpr, action); + } + } + + private void generateAuxiliaryStructsForPort( + CodeBuilder builder, TypeParameterizedReactor tpr, Port port) { + boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); + builder.pr( + port, PythonPortGenerator.generateAliasTypeDef(tpr, port, isTokenType, genericPortType)); + } + + private void generateAuxiliaryStructsForAction( + CodeBuilder builder, TypeParameterizedReactor tpr, Action action) { + builder.pr(action, PythonActionGenerator.generateAliasTypeDef(tpr, action, genericActionType)); + } + + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + @Override + public boolean isOSCompatible() { + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context Context relating to invocation of the code generator. + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + // Set the threading to false by default, unless the user has + // specifically asked for it. + if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = false; + } + int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; + code.pr( + PythonPreambleGenerator.generateCIncludeStatements( + targetConfig, targetLanguageIsCpp(), hasModalReactors)); + super.doGenerate( + resource, + new SubContext( + context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, cGeneratedPercentProgress)); + + if (errorsOccurred()) { + context.unsuccessfulFinish(); + return; + } + + Map codeMaps = new HashMap<>(); + var lfModuleName = fileConfig.name; + // Don't generate code if there is no main reactor + if (this.main != null) { + try { + Map codeMapsForFederate = + generatePythonFiles( + lfModuleName, + generatePythonModuleName(lfModuleName), + generatePythonFileName(lfModuleName)); + codeMaps.putAll(codeMapsForFederate); + copyTargetFiles(); + new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); + if (targetConfig.noCompile) { + System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); } - for (Model m : models) { - pythonPreamble.pr(PythonPreambleGenerator.generatePythonPreambles(m.getPreambles())); - } - return PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors); - } - - @Override - protected void handleProtoFiles() { - for (String name : targetConfig.protoFiles) { - this.processProtoFile(name); - int dotIndex = name.lastIndexOf("."); - String rootFilename = dotIndex > 0 ? name.substring(0, dotIndex) : name; - pythonPreamble.pr("import "+rootFilename+"_pb2 as "+rootFilename); - protoNames.add(rootFilename); - } - } - - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * - * @param filename Name of the file to process. - */ - @Override - public void processProtoFile(String filename) { - LFCommand protoc = commandFactory.createCommand( - "protoc", List.of("--python_out=" - + fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires libprotoc >= 3.6.1"); - return; - } - int returnCode = protoc.run(); - if (returnCode == 0) { - pythonRequiredModules.add("google-api-python-client"); - } else { - errorReporter.reportError( - "protoc returns error code " + returnCode); - } - } - - /** - * Generate the aliases for inputs, outputs, and struct type definitions for - * actions of the specified reactor in the specified federate. - * @param tpr The concrete reactor class. - */ - @Override - public void generateAuxiliaryStructs( - CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing - ) { - for (Input input : ASTUtils.allInputs(tpr.reactor())) { - generateAuxiliaryStructsForPort(builder, tpr, input); - } - for (Output output : ASTUtils.allOutputs(tpr.reactor())) { - generateAuxiliaryStructsForPort(builder, tpr, output); - } - for (Action action : ASTUtils.allActions(tpr.reactor())) { - generateAuxiliaryStructsForAction(builder, tpr, action); - } - } - - private void generateAuxiliaryStructsForPort(CodeBuilder builder, TypeParameterizedReactor tpr, - Port port) { - boolean isTokenType = CUtil.isTokenType(ASTUtils.getInferredType(port), types); - builder.pr(port, - PythonPortGenerator.generateAliasTypeDef(tpr, port, isTokenType, - genericPortType)); - } - - private void generateAuxiliaryStructsForAction(CodeBuilder builder, TypeParameterizedReactor tpr, - Action action) { - builder.pr(action, PythonActionGenerator.generateAliasTypeDef(tpr, action, genericActionType)); - } - - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - @Override - public boolean isOSCompatible() { - return true; - } - - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * - * @param resource The resource containing the source code. - * @param context Context relating to invocation of the code generator. - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - // Set the threading to false by default, unless the user has - // specifically asked for it. - if (!targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = false; - } - int cGeneratedPercentProgress = (IntegratedBuilder.VALIDATED_PERCENT_PROGRESS + 100) / 2; - code.pr(PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors)); - super.doGenerate(resource, new SubContext( - context, - IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, - cGeneratedPercentProgress - )); - - if (errorsOccurred()) { - context.unsuccessfulFinish(); - return; - } - - Map codeMaps = new HashMap<>(); - var lfModuleName = fileConfig.name; - // Don't generate code if there is no main reactor - if (this.main != null) { - try { - Map codeMapsForFederate = generatePythonFiles(lfModuleName, generatePythonModuleName(lfModuleName), generatePythonFileName(lfModuleName)); - codeMaps.putAll(codeMapsForFederate); - copyTargetFiles(); - new PythonValidator(fileConfig, errorReporter, codeMaps, protoNames).doValidate(context); - if (targetConfig.noCompile) { - System.out.println(PythonInfoGenerator.generateSetupInfo(fileConfig)); - } - } catch (Exception e) { - //noinspection ConstantConditions - throw Exceptions.sneakyThrow(e); - } - - System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); - } - - if (errorReporter.getErrorsOccurred()) { - context.unsuccessfulFinish(); - } else { - context.finish(GeneratorResult.Status.COMPILED, codeMaps); - } - } - - @Override - protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new PythonDockerGenerator(context); - } - - /** Generate a reaction function definition for a reactor. - * This function has a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param tpr The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - @Override - protected void generateReaction(CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { - Reactor reactor = ASTUtils.toDefinition(tpr.reactor()); - - // Reactions marked with a {@code @_c_body} attribute are generated in C - if (AttributeUtils.hasCBody(reaction)) { - super.generateReaction(src, reaction, tpr, reactionIndex); - return; - } - src.pr(PythonReactionGenerator.generateCReaction(reaction, tpr, reactor, reactionIndex, mainDef, errorReporter, types)); - } - - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all - * instances - * of the same reactor. This task is left to Python code to allow for more - * liberal - * state variable assignments. - * - * @param instance The reactor class instance - * @return Initialization code fore state variables of instance - */ - @Override - protected void generateStateVariableInitializations(ReactorInstance instance) { - // Do nothing - } - - /** - * Generate runtime initialization code in C for parameters of a given - * reactor instance - * - * @param instance The reactor instance. - */ - @Override - protected void generateParameterInitialization(ReactorInstance instance) { - // Do nothing - // Parameters are initialized in Python - } - - /** - * Do nothing. - * Methods are generated in Python not C. - * @see PythonMethodGenerator - */ - @Override - protected void generateMethods(CodeBuilder src, TypeParameterizedReactor reactor) { } - - /** - * Generate C preambles defined by user for a given reactor - * Since the Python generator expects preambles written in C, - * this function is overridden and does nothing. - * - * @param reactor The given reactor - */ - @Override - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - // Do nothing - } - - @Override - protected void generateReactorClassHeaders(TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { - header.pr(PythonPreambleGenerator.generateCIncludeStatements(targetConfig, targetLanguageIsCpp(), hasModalReactors)); - super.generateReactorClassHeaders(tpr, headerName, header, src); - } - - /** - * Generate code that is executed while the reactor instance is being - * initialized. - * This wraps the reaction functions in a Python function. - * @param instance The reactor instance. - */ - @Override - protected void generateReactorInstanceExtension( - ReactorInstance instance - ) { - initializeTriggerObjects.pr(PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); - } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param selfStructBody The body of the self struct - * @param reactor The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - @Override - protected void generateSelfStructExtension( - CodeBuilder selfStructBody, - Reactor reactor, - CodeBuilder constructorCode - ) { - // Add the name field - selfStructBody.pr("char *_lf_name;"); - int reactionIndex = 0; - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - // Create a PyObject for each reaction - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex)+";"); - if (reaction.getStp() != null) { - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex)+";"); - } - if (reaction.getDeadline() != null) { - selfStructBody.pr("PyObject* "+ PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex)+";"); - } - reactionIndex++; - } - } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - // NOTE: Strangely, a newline is needed at the beginning or indentation - // gets swallowed. - return String.join("\n", - "\n# Generated forwarding reaction for connections with the same destination", - "# but located in mutually exclusive modes.", - dest + ".set(" + source + ".value)\n" - ); - } - - @Override - protected void setUpGeneralParameters() { - super.setUpGeneralParameters(); - if (hasModalReactors) { - targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); - } - } - - @Override - protected void additionalPostProcessingForModes() { - if (!hasModalReactors) { - return; - } - PythonModeGenerator.generateResetReactionsIfNeeded(reactors); - } - - private static String setUpMainTarget(boolean hasMain, String executableName, Stream cSources) { - return ( - """ + } catch (Exception e) { + //noinspection ConstantConditions + throw Exceptions.sneakyThrow(e); + } + + System.out.println(PythonInfoGenerator.generateRunInfo(fileConfig, lfModuleName)); + } + + if (errorReporter.getErrorsOccurred()) { + context.unsuccessfulFinish(); + } else { + context.finish(GeneratorResult.Status.COMPILED, codeMaps); + } + } + + @Override + protected PythonDockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new PythonDockerGenerator(context); + } + + /** + * Generate a reaction function definition for a reactor. This function has a single argument that + * is a void* pointing to a struct that contains parameters, state variables, inputs (triggering + * or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param tpr The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + @Override + protected void generateReaction( + CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) { + Reactor reactor = ASTUtils.toDefinition(tpr.reactor()); + + // Reactions marked with a {@code @_c_body} attribute are generated in C + if (AttributeUtils.hasCBody(reaction)) { + super.generateReaction(src, reaction, tpr, reactionIndex); + return; + } + src.pr( + PythonReactionGenerator.generateCReaction( + reaction, tpr, reactor, reactionIndex, mainDef, errorReporter, types)); + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. This task is + * left to Python code to allow for more liberal state variable assignments. + * + * @param instance The reactor class instance + * @return Initialization code fore state variables of instance + */ + @Override + protected void generateStateVariableInitializations(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate runtime initialization code in C for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + @Override + protected void generateParameterInitialization(ReactorInstance instance) { + // Do nothing + // Parameters are initialized in Python + } + + /** + * Do nothing. Methods are generated in Python not C. + * + * @see PythonMethodGenerator + */ + @Override + protected void generateMethods(CodeBuilder src, TypeParameterizedReactor reactor) {} + + /** + * Generate C preambles defined by user for a given reactor Since the Python generator expects + * preambles written in C, this function is overridden and does nothing. + * + * @param reactor The given reactor + */ + @Override + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + // Do nothing + } + + @Override + protected void generateReactorClassHeaders( + TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) { + header.pr( + PythonPreambleGenerator.generateCIncludeStatements( + targetConfig, targetLanguageIsCpp(), hasModalReactors)); + super.generateReactorClassHeaders(tpr, headerName, header, src); + } + + /** + * Generate code that is executed while the reactor instance is being initialized. This wraps the + * reaction functions in a Python function. + * + * @param instance The reactor instance. + */ + @Override + protected void generateReactorInstanceExtension(ReactorInstance instance) { + initializeTriggerObjects.pr( + PythonReactionGenerator.generateCPythonReactionLinkers(instance, mainDef)); + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param selfStructBody The body of the self struct + * @param reactor The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + @Override + protected void generateSelfStructExtension( + CodeBuilder selfStructBody, Reactor reactor, CodeBuilder constructorCode) { + // Add the name field + selfStructBody.pr("char *_lf_name;"); + int reactionIndex = 0; + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + // Create a PyObject for each reaction + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonReactionFunctionName(reactionIndex) + + ";"); + if (reaction.getStp() != null) { + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonSTPFunctionName(reactionIndex) + + ";"); + } + if (reaction.getDeadline() != null) { + selfStructBody.pr( + "PyObject* " + + PythonReactionGenerator.generateCPythonDeadlineFunctionName(reactionIndex) + + ";"); + } + reactionIndex++; + } + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + // NOTE: Strangely, a newline is needed at the beginning or indentation + // gets swallowed. + return String.join( + "\n", + "\n# Generated forwarding reaction for connections with the same destination", + "# but located in mutually exclusive modes.", + dest + ".set(" + source + ".value)\n"); + } + + @Override + protected void setUpGeneralParameters() { + super.setUpGeneralParameters(); + if (hasModalReactors) { + targetConfig.compileAdditionalSources.add("lib/modal_models/impl.c"); + } + } + + @Override + protected void additionalPostProcessingForModes() { + if (!hasModalReactors) { + return; + } + PythonModeGenerator.generateResetReactionsIfNeeded(reactors); + } + + private static String setUpMainTarget( + boolean hasMain, String executableName, Stream cSources) { + return (""" set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(_LF_GARBAGE_COLLECTED) add_subdirectory(core) @@ -614,74 +597,59 @@ private static String setUpMainTarget(boolean hasMain, String executableName, St 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)) - .replace("executableName", executableName); - // The use of fileConfig.name will break federated execution, but that's fine - } - - /** - * Generate a ({@code key}, {@code val}) tuple pair for the {@code define_macros} field - * of the Extension class constructor from setuptools. - * - * @param key The key of the macro entry - * @param val The value of the macro entry - * @return A ({@code key}, {@code val}) tuple pair as String - */ - private static String generateMacroEntry(String key, String val) { - return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; - } - - /** - * Generate the name of the python module. - * - * Ideally, this function would belong in a class like {@code PyFileConfig} - * that specifies all the paths to the generated code. - * - * @param lfModuleName The name of the LF module. - * @return The name of the python module. - */ - private static String generatePythonModuleName(String lfModuleName) { - return "LinguaFranca" + lfModuleName; - } - - /** - * Generate the python file name given an {@code lfModuleName}. - * - * Ideally, this function would belong in a class like {@code PyFileConfig} - * that specifies all the paths to the generated code. - * - * @param lfModuleName The name of the LF module - * @return The name of the generated python file. - */ - private static String generatePythonFileName(String lfModuleName) { - return lfModuleName + ".py"; - } - - /** - * Copy Python specific target code to the src-gen directory - */ - @Override - protected void copyTargetFiles() throws IOException { - super.copyTargetFiles(); - FileUtil.copyFromClassPath( - "/lib/c/reactor-c/python/include", - fileConfig.getSrcGenPath(), - true, - false - ); - FileUtil.copyFromClassPath( - "/lib/c/reactor-c/python/lib", - fileConfig.getSrcGenPath(), - true, - false - ); - FileUtil.copyFromClassPath( - "/lib/py/lf-python-support/LinguaFrancaBase", - fileConfig.getSrcGenPath(), - true, - false - ); - } - + """) + .replace("", generatePythonModuleName(executableName)) + .replace("executableName", executableName); + // The use of fileConfig.name will break federated execution, but that's fine + } + + /** + * Generate a ({@code key}, {@code val}) tuple pair for the {@code define_macros} field of the + * Extension class constructor from setuptools. + * + * @param key The key of the macro entry + * @param val The value of the macro entry + * @return A ({@code key}, {@code val}) tuple pair as String + */ + private static String generateMacroEntry(String key, String val) { + return "(" + StringUtil.addDoubleQuotes(key) + ", " + StringUtil.addDoubleQuotes(val) + ")"; + } + + /** + * Generate the name of the python module. + * + *

    Ideally, this function would belong in a class like {@code PyFileConfig} that specifies all + * the paths to the generated code. + * + * @param lfModuleName The name of the LF module. + * @return The name of the python module. + */ + private static String generatePythonModuleName(String lfModuleName) { + return "LinguaFranca" + lfModuleName; + } + + /** + * Generate the python file name given an {@code lfModuleName}. + * + *

    Ideally, this function would belong in a class like {@code PyFileConfig} that specifies all + * the paths to the generated code. + * + * @param lfModuleName The name of the LF module + * @return The name of the generated python file. + */ + private static String generatePythonFileName(String lfModuleName) { + return lfModuleName + ".py"; + } + + /** Copy Python specific target code to the src-gen directory */ + @Override + protected void copyTargetFiles() throws IOException { + super.copyTargetFiles(); + FileUtil.copyFromClassPath( + "/lib/c/reactor-c/python/include", fileConfig.getSrcGenPath(), true, false); + FileUtil.copyFromClassPath( + "/lib/c/reactor-c/python/lib", fileConfig.getSrcGenPath(), true, false); + FileUtil.copyFromClassPath( + "/lib/py/lf-python-support/LinguaFrancaBase", fileConfig.getSrcGenPath(), true, false); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonInfoGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonInfoGenerator.java index 23512f447a..01cadbcc5c 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonInfoGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonInfoGenerator.java @@ -4,53 +4,49 @@ import org.lflang.FileConfig; public class PythonInfoGenerator { - /** - * Print information about necessary steps to install the supporting - * Python C extension for the generated program. - * - * @note Only needed if no-compile is set to true - */ - public static String generateSetupInfo(FileConfig fileConfig) { - return String.join("\n", - "", - "#####################################", - "To compile and install the generated code, do:", - " ", - " cd "+fileConfig.getSrcGenPath()+File.separator, - " python3 -m pip install --force-reinstall .", - "" - ); - } + /** + * Print information about necessary steps to install the supporting Python C extension for the + * generated program. + * + * @note Only needed if no-compile is set to true + */ + public static String generateSetupInfo(FileConfig fileConfig) { + return String.join( + "\n", + "", + "#####################################", + "To compile and install the generated code, do:", + " ", + " cd " + fileConfig.getSrcGenPath() + File.separator, + " python3 -m pip install --force-reinstall .", + ""); + } - /** - * Print information on how to execute the generated program. - */ - public static String generateRunInfo(FileConfig fileConfig, String lfModuleName) { - return String.join("\n", - "", - "#####################################", - "To run the generated program, use:", - " ", - " python3 "+fileConfig.getSrcGenPath()+File.separator+lfModuleName+".py", - "", - "#####################################", - "" - ); - } + /** Print information on how to execute the generated program. */ + public static String generateRunInfo(FileConfig fileConfig, String lfModuleName) { + return String.join( + "\n", + "", + "#####################################", + "To run the generated program, use:", + " ", + " python3 " + fileConfig.getSrcGenPath() + File.separator + lfModuleName + ".py", + "", + "#####################################", + ""); + } - /** - * Print information on how to execute the generated federation. - */ - public static String generateFedRunInfo(FileConfig fileConfig) { - return String.join("\n", - "", - "#####################################", - "To run the generated program, run:", - " ", - " bash "+fileConfig.binPath+"/"+fileConfig.name, - "", - "#####################################", - "" - ); - } + /** Print information on how to execute the generated federation. */ + public static String generateFedRunInfo(FileConfig fileConfig) { + return String.join( + "\n", + "", + "#####################################", + "To run the generated program, run:", + " ", + " bash " + fileConfig.binPath + "/" + fileConfig.name, + "", + "#####################################", + ""); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonMainFunctionGenerator.java index a655402408..5a43788138 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonMainFunctionGenerator.java @@ -26,29 +26,26 @@ package org.lflang.generator.python; /** - * Responsible for creating the main function for - * the generated Python target programs. + * Responsible for creating the main function for the generated Python target programs. * * @author Soroush Bateni - * */ public final class PythonMainFunctionGenerator { - /* - * Generate the main function code - */ - public static String generateCode() { - StringBuilder code = new StringBuilder(); - code.append( - "# The main function\n" - + "def main(argv):\n" - + " start(argv)\n" - + "\n" - + "# As is customary in Python programs, the main() function\n" - + "# should only be executed if the main module is active.\n" - + "if __name__==\"__main__\":\n" - + " main(sys.argv)\n" - ); - return code.toString(); - } + /* + * Generate the main function code + */ + public static String generateCode() { + StringBuilder code = new StringBuilder(); + code.append( + "# The main function\n" + + "def main(argv):\n" + + " start(argv)\n" + + "\n" + + "# As is customary in Python programs, the main() function\n" + + "# should only be executed if the main module is active.\n" + + "if __name__==\"__main__\":\n" + + " main(sys.argv)\n"); + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java index a2d1e240d1..e2d2e85a6b 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java @@ -1,7 +1,6 @@ package org.lflang.generator.python; import java.util.stream.Collectors; - import org.lflang.ast.ASTUtils; import org.lflang.lf.Method; import org.lflang.lf.MethodArgument; @@ -14,39 +13,30 @@ */ public class PythonMethodGenerator { - /** - * Generate a Python method definition for {@code method}. - */ - public static String generateMethod(Method method) { - return String.join("\n", - "# Implementation of method "+method.getName()+"().", - "def "+method.getName()+"(self, "+generateMethodArgumentList(method)+"):", - ASTUtils.toText(method.getCode()).indent(4) - ); - } + /** Generate a Python method definition for {@code method}. */ + public static String generateMethod(Method method) { + return String.join( + "\n", + "# Implementation of method " + method.getName() + "().", + "def " + method.getName() + "(self, " + generateMethodArgumentList(method) + "):", + ASTUtils.toText(method.getCode()).indent(4)); + } - /** - * Generate methods for a reactor class. - * - * @param reactor The reactor. - */ - public static String generateMethods( - Reactor reactor - ) { - return ASTUtils.allMethods(reactor) - .stream() - .map(m -> generateMethod(m)) - .collect(Collectors.joining()); - } + /** + * Generate methods for a reactor class. + * + * @param reactor The reactor. + */ + public static String generateMethods(Reactor reactor) { + return ASTUtils.allMethods(reactor).stream() + .map(m -> generateMethod(m)) + .collect(Collectors.joining()); + } - /** - * Generate a list of arguments for {@code method} delimited with ', '. - */ - private static String generateMethodArgumentList(Method method) { - return String.join(", ", - method.getArguments() - .stream() - .map(MethodArgument::getName) - .collect(Collectors.toList())); - } + /** Generate a list of arguments for {@code method} delimited with ', '. */ + private static String generateMethodArgumentList(Method method) { + return String.join( + ", ", + method.getArguments().stream().map(MethodArgument::getName).collect(Collectors.toList())); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java index 90af635727..9bcbe6607d 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java @@ -1,7 +1,6 @@ package org.lflang.generator.python; import java.util.List; - import org.eclipse.emf.ecore.util.EcoreUtil; import org.lflang.generator.CodeBuilder; import org.lflang.lf.BuiltinTrigger; @@ -15,86 +14,94 @@ * Helper class to handle modes in Python programs. * * @author Soroush Bateni - * */ public class PythonModeGenerator { - /** - * Generate reset reactions in modes to reset state variables. - * - * @param reactors A list of reactors in the program, some of which could contain modes. - */ - public static void generateResetReactionsIfNeeded(List reactors) { - for (Reactor reactor : reactors) { - generateStartupReactionsInReactor(reactor); - } + /** + * Generate reset reactions in modes to reset state variables. + * + * @param reactors A list of reactors in the program, some of which could contain modes. + */ + public static void generateResetReactionsIfNeeded(List reactors) { + for (Reactor reactor : reactors) { + generateStartupReactionsInReactor(reactor); } + } - /** - * Generate reset reactions that reset state variables in - *

      - *
    • the reactor, and,
    • - *
    • the modes within the reactor.
    • - *
    - * - * @param reactor The reactor. - */ - private static void generateStartupReactionsInReactor(Reactor reactor) { - - // Create a reaction with a reset trigger - BuiltinTriggerRef resetTrigger = LfFactory.eINSTANCE.createBuiltinTriggerRef(); - resetTrigger.setType(BuiltinTrigger.RESET); - Reaction baseReaction = LfFactory.eINSTANCE.createReaction(); - baseReaction.getTriggers().add(resetTrigger); + /** + * Generate reset reactions that reset state variables in + * + *
      + *
    • the reactor, and, + *
    • the modes within the reactor. + *
    + * + * @param reactor The reactor. + */ + private static void generateStartupReactionsInReactor(Reactor reactor) { - if (!reactor.getStateVars().isEmpty() && reactor.getStateVars().stream().anyMatch(s -> s.isReset())) { - // Create a reaction body that resets all state variables (that are not in a mode) - // to their initial value. - var reactionBody = LfFactory.eINSTANCE.createCode(); - CodeBuilder code = new CodeBuilder(); - code.pr("# Reset the following state variables to their initial value."); - for (var state: reactor.getStateVars()) { - if (state.isReset()) { - code.pr("self."+state.getName()+" = "+ PythonStateGenerator.generatePythonInitializer(state)); - } - } - reactionBody.setBody(code.toString()); - baseReaction.setCode(reactionBody); + // Create a reaction with a reset trigger + BuiltinTriggerRef resetTrigger = LfFactory.eINSTANCE.createBuiltinTriggerRef(); + resetTrigger.setType(BuiltinTrigger.RESET); + Reaction baseReaction = LfFactory.eINSTANCE.createReaction(); + baseReaction.getTriggers().add(resetTrigger); - reactor.getReactions().add(0, baseReaction); + if (!reactor.getStateVars().isEmpty() + && reactor.getStateVars().stream().anyMatch(s -> s.isReset())) { + // Create a reaction body that resets all state variables (that are not in a mode) + // to their initial value. + var reactionBody = LfFactory.eINSTANCE.createCode(); + CodeBuilder code = new CodeBuilder(); + code.pr("# Reset the following state variables to their initial value."); + for (var state : reactor.getStateVars()) { + if (state.isReset()) { + code.pr( + "self." + + state.getName() + + " = " + + PythonStateGenerator.generatePythonInitializer(state)); } + } + reactionBody.setBody(code.toString()); + baseReaction.setCode(reactionBody); + reactor.getReactions().add(0, baseReaction); + } - var reactorModes = reactor.getModes(); - if (!reactorModes.isEmpty()) { - for (Mode mode : reactorModes) { - if (mode.getStateVars().isEmpty() || mode.getStateVars().stream().allMatch(s -> !s.isReset())) { - continue; - } - Reaction reaction = EcoreUtil.copy(baseReaction); - - // Create a reaction body that resets all state variables to their initial value. - var reactionBody = LfFactory.eINSTANCE.createCode(); - CodeBuilder code = new CodeBuilder(); - code.pr("# Reset the following state variables to their initial value."); - for (var state: mode.getStateVars()) { - if (state.isReset()) { - code.pr("self."+state.getName()+" = "+ PythonStateGenerator.generatePythonInitializer(state)); - } - } - reactionBody.setBody(code.toString()); - reaction.setCode(reactionBody); + var reactorModes = reactor.getModes(); + if (!reactorModes.isEmpty()) { + for (Mode mode : reactorModes) { + if (mode.getStateVars().isEmpty() + || mode.getStateVars().stream().allMatch(s -> !s.isReset())) { + continue; + } + Reaction reaction = EcoreUtil.copy(baseReaction); - try { - mode.getReactions().add(0, reaction); - } catch (IndexOutOfBoundsException e) { - // There are no scoping for state variables. - // We add this reaction for now so that it - // still resets state variables even if there - // are no reactions in this mode. - mode.getReactions().add(reaction); - } + // Create a reaction body that resets all state variables to their initial value. + var reactionBody = LfFactory.eINSTANCE.createCode(); + CodeBuilder code = new CodeBuilder(); + code.pr("# Reset the following state variables to their initial value."); + for (var state : mode.getStateVars()) { + if (state.isReset()) { + code.pr( + "self." + + state.getName() + + " = " + + PythonStateGenerator.generatePythonInitializer(state)); + } + } + reactionBody.setBody(code.toString()); + reaction.setCode(reactionBody); - } + try { + mode.getReactions().add(0, reaction); + } catch (IndexOutOfBoundsException e) { + // There are no scoping for state variables. + // We add this reaction for now so that it + // still resets state variables even if there + // are no reactions in this mode. + mode.getReactions().add(reaction); } + } } + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java index 838e7a27a3..0c13b111f7 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java @@ -2,107 +2,103 @@ import java.util.ArrayList; import java.util.List; - import org.lflang.ast.ASTUtils; import org.lflang.generator.ParameterInstance; -import org.lflang.lf.ReactorDecl; import org.lflang.lf.Parameter; - +import org.lflang.lf.ReactorDecl; public class PythonParameterGenerator { - /** - * Generate Python code that instantiates and initializes parameters for a reactor 'decl'. - * - * @param decl The reactor declaration - * @return The generated code as a StringBuilder - */ - public static String generatePythonInstantiations(ReactorDecl decl, PythonTypes types) { - List lines = new ArrayList<>(); - lines.add("# Define parameters and their default values"); + /** + * Generate Python code that instantiates and initializes parameters for a reactor 'decl'. + * + * @param decl The reactor declaration + * @return The generated code as a StringBuilder + */ + public static String generatePythonInstantiations(ReactorDecl decl, PythonTypes types) { + List lines = new ArrayList<>(); + lines.add("# Define parameters and their default values"); - for (Parameter param : getAllParameters(decl)) { - if (!types.getTargetType(param).equals("PyObject*")) { - // If type is given, use it - String type = types.getPythonType(ASTUtils.getInferredType(param)); - lines.add("self._"+param.getName()+":"+type+" = "+generatePythonInitializer(param)); - } else { - // If type is not given, just pass along the initialization - lines.add("self._"+param.getName()+" = "+generatePythonInitializer(param)); - } - } - // Handle parameters that are set in instantiation - lines.addAll(List.of( + for (Parameter param : getAllParameters(decl)) { + if (!types.getTargetType(param).equals("PyObject*")) { + // If type is given, use it + String type = types.getPythonType(ASTUtils.getInferredType(param)); + lines.add( + "self._" + param.getName() + ":" + type + " = " + generatePythonInitializer(param)); + } else { + // If type is not given, just pass along the initialization + lines.add("self._" + param.getName() + " = " + generatePythonInitializer(param)); + } + } + // Handle parameters that are set in instantiation + lines.addAll( + List.of( "# Handle parameters that are set in instantiation", "self.__dict__.update(kwargs)", - "" - )); - return String.join("\n", lines); - } + "")); + return String.join("\n", lines); + } - /** - * Generate Python code getters for parameters of reactor 'decl'. - * - * @param decl The reactor declaration - * @return The generated code as a StringBuilder - */ - public static String generatePythonGetters(ReactorDecl decl) { - List lines = new ArrayList<>(); - for (Parameter param : getAllParameters(decl)) { - if (!param.getName().equals("bank_index")) { - lines.addAll(List.of( - "", - "@property", - "def "+param.getName()+"(self):", - " return self._"+param.getName()+" # pylint: disable=no-member", - "" - )); - } - } - // Create a special property for bank_index - lines.addAll(List.of( + /** + * Generate Python code getters for parameters of reactor 'decl'. + * + * @param decl The reactor declaration + * @return The generated code as a StringBuilder + */ + public static String generatePythonGetters(ReactorDecl decl) { + List lines = new ArrayList<>(); + for (Parameter param : getAllParameters(decl)) { + if (!param.getName().equals("bank_index")) { + lines.addAll( + List.of( + "", + "@property", + "def " + param.getName() + "(self):", + " return self._" + param.getName() + " # pylint: disable=no-member", + "")); + } + } + // Create a special property for bank_index + lines.addAll( + List.of( "", "@property", "def bank_index(self):", " return self._bank_index # pylint: disable=no-member", - "" - )); - lines.add("\n"); - return String.join("\n", lines); - } - - /** - * Return a list of all parameters of reactor 'decl'. - * - * @param decl The reactor declaration - * @return The list of all parameters of 'decl' - */ - private static List getAllParameters(ReactorDecl decl) { - return ASTUtils.allParameters(ASTUtils.toDefinition(decl)); - } + "")); + lines.add("\n"); + return String.join("\n", lines); + } - /** - * Create a Python list for parameter initialization in target code. - * - * @param p The parameter to create initializers for - * @return Initialization code - */ - private static String generatePythonInitializer(Parameter p) { - return PythonTypes.getInstance().getTargetInitializer(p.getInit(), p.getType()); - } + /** + * Return a list of all parameters of reactor 'decl'. + * + * @param decl The reactor declaration + * @return The list of all parameters of 'decl' + */ + private static List getAllParameters(ReactorDecl decl) { + return ASTUtils.allParameters(ASTUtils.toDefinition(decl)); + } - /** - * Return a Python expression that can be used to initialize the specified - * parameter instance. If the parameter initializer refers to other - * parameters, then those parameter references are replaced with - * accesses to the Python reactor instance class of the parents of - * those parameters. - * - * @param p The parameter instance to create initializer for - * @return Initialization code - */ - public static String generatePythonInitializer(ParameterInstance p) { - PythonTypes pyTypes = PythonTypes.generateParametersIn(p.getParent().getParent()); - return pyTypes.getTargetInitializer(p.getActualValue(), p.getDefinition().getType()); - } + /** + * Create a Python list for parameter initialization in target code. + * + * @param p The parameter to create initializers for + * @return Initialization code + */ + private static String generatePythonInitializer(Parameter p) { + return PythonTypes.getInstance().getTargetInitializer(p.getInit(), p.getType()); + } + /** + * Return a Python expression that can be used to initialize the specified parameter instance. If + * the parameter initializer refers to other parameters, then those parameter references are + * replaced with accesses to the Python reactor instance class of the parents of those parameters. + * + * @param p The parameter instance to create initializer for + * @return Initialization code + */ + public static String generatePythonInitializer(ParameterInstance p) { + PythonTypes pyTypes = PythonTypes.generateParametersIn(p.getParent().getParent()); + return pyTypes.getTargetInitializer(p.getActualValue(), p.getDefinition().getType()); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java index 5109c322c3..d8ece7d206 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java @@ -1,237 +1,260 @@ package org.lflang.generator.python; +import static org.lflang.generator.c.CUtil.generateWidthVariable; + +import java.util.List; +import org.lflang.ast.ASTUtils; +import org.lflang.generator.CodeBuilder; +import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.TypeParameterizedReactor; +import org.lflang.lf.Action; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; import org.lflang.lf.Port; -import org.lflang.lf.Action; import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; -import java.util.List; -import org.lflang.ast.ASTUtils; -import org.lflang.generator.CodeBuilder; -import org.lflang.generator.c.CGenerator; -import static org.lflang.generator.c.CUtil.generateWidthVariable; public class PythonPortGenerator { - public static final String NONMULTIPORT_WIDTHSPEC = "-2"; + public static final String NONMULTIPORT_WIDTHSPEC = "-2"; - /** - * Generate code to convert C actions to Python action capsules. See - * pythontarget.h for details. - * @param pyObjects A string containing a list of comma-separated expressions that will create the - * action capsules. - * @param action The action itself. - * @param decl The reactor decl that contains the action. - */ - public static void generateActionVariableToSendToPythonReaction(List pyObjects, - Action action, ReactorDecl decl) { - // Values passed to an action are always stored in the token->value. - // However, sometimes token might not be initialized. Therefore, this function has an internal check for NULL in case token is not initialized. - pyObjects.add(String.format("convert_C_action_to_py(%s)", action.getName())); - } + /** + * Generate code to convert C actions to Python action capsules. See pythontarget.h for details. + * + * @param pyObjects A string containing a list of comma-separated expressions that will create the + * action capsules. + * @param action The action itself. + * @param decl The reactor decl that contains the action. + */ + public static void generateActionVariableToSendToPythonReaction( + List pyObjects, Action action, ReactorDecl decl) { + // Values passed to an action are always stored in the token->value. + // However, sometimes token might not be initialized. Therefore, this function has an internal + // check for NULL in case token is not initialized. + pyObjects.add(String.format("convert_C_action_to_py(%s)", action.getName())); + } - /** - * Generate code to convert C ports to Python ports capsules (@see pythontarget.h). - * - * The port may be an input of the reactor or an output of a contained reactor. - * @param pyObjects A string containing a list of comma-separated expressions that will create the - * port capsules. - * @param port The port itself. - * @param decl The reactor decl that contains the port. - */ - public static String generatePortVariablesToSendToPythonReaction( - List pyObjects, - VarRef port, - ReactorDecl decl - ) { - if (port.getVariable() instanceof Input) { - generateInputVariablesToSendToPythonReaction(pyObjects, (Input) port.getVariable(), decl); - return ""; - } else { - // port is an output of a contained reactor. - return generateVariablesForSendingToContainedReactors(pyObjects, port.getContainer(), (Port) port.getVariable()); - } + /** + * Generate code to convert C ports to Python ports capsules (@see pythontarget.h). + * + *

    The port may be an input of the reactor or an output of a contained reactor. + * + * @param pyObjects A string containing a list of comma-separated expressions that will create the + * port capsules. + * @param port The port itself. + * @param decl The reactor decl that contains the port. + */ + public static String generatePortVariablesToSendToPythonReaction( + List pyObjects, VarRef port, ReactorDecl decl) { + if (port.getVariable() instanceof Input) { + generateInputVariablesToSendToPythonReaction(pyObjects, (Input) port.getVariable(), decl); + return ""; + } else { + // port is an output of a contained reactor. + return generateVariablesForSendingToContainedReactors( + pyObjects, port.getContainer(), (Port) port.getVariable()); } + } - /** Generate into the specified string builder the code to - * send local variables for output ports to a Python reaction function - * from the "self" struct. - * @param output The output port. - */ - public static void generateOutputVariablesToSendToPythonReaction( - List pyObjects, - Output output - ) { - // Unfortunately, for the lf_set macros to work out-of-the-box for - // multiports, we need an array of pointers to the output structs, - // but what we have on the self struct is an array of output structs. - // So we have to handle multiports specially here a construct that - // array of pointers. - // FIXME: The C Generator also has this awkwardness. It makes the code generators - // unnecessarily difficult to maintain, and it may have performance consequences as well. - // Maybe we should change the lf_set macros. - if (!ASTUtils.isMultiport(output)) { - pyObjects.add(generateConvertCPortToPy(output.getName(), NONMULTIPORT_WIDTHSPEC)); - } else { - pyObjects.add(generateConvertCPortToPy(output.getName())); - } + /** + * Generate into the specified string builder the code to send local variables for output ports to + * a Python reaction function from the "self" struct. + * + * @param output The output port. + */ + public static void generateOutputVariablesToSendToPythonReaction( + List pyObjects, Output output) { + // Unfortunately, for the lf_set macros to work out-of-the-box for + // multiports, we need an array of pointers to the output structs, + // but what we have on the self struct is an array of output structs. + // So we have to handle multiports specially here a construct that + // array of pointers. + // FIXME: The C Generator also has this awkwardness. It makes the code generators + // unnecessarily difficult to maintain, and it may have performance consequences as well. + // Maybe we should change the lf_set macros. + if (!ASTUtils.isMultiport(output)) { + pyObjects.add(generateConvertCPortToPy(output.getName(), NONMULTIPORT_WIDTHSPEC)); + } else { + pyObjects.add(generateConvertCPortToPy(output.getName())); } + } - /** Generate into the specified string builder the code to - * send local variables for input ports to a Python reaction function - * from the "self" struct. - * @param input The input port. - */ - public static void generateInputVariablesToSendToPythonReaction( - List pyObjects, - Input input, - ReactorDecl decl - ) { - // Create the local variable whose name matches the input.getName(). - // If the input has not been declared mutable, then this is a pointer - // to the upstream output. Otherwise, it is a copy of the upstream output, - // which nevertheless points to the same token and value. There are 8 cases, - // depending on whether the input is mutable, whether it is a multiport, - // and whether it is a token type. - // Easy case first. - if (!input.isMutable() && !ASTUtils.isMultiport(input)) { - // Non-mutable, non-multiport, primitive type. - pyObjects.add(generateConvertCPortToPy(input.getName())); - } else if (input.isMutable() && !ASTUtils.isMultiport(input)) { - // Mutable, non-multiport, primitive type. - // TODO: handle mutable - pyObjects.add(generateConvertCPortToPy(input.getName())); - } else if (!input.isMutable() && ASTUtils.isMultiport(input)) { - // Non-mutable, multiport, primitive. - // TODO: support multiports - pyObjects.add(generateConvertCPortToPy(input.getName())); - } else { - // Mutable, multiport, primitive type - // TODO: support mutable multiports - pyObjects.add(generateConvertCPortToPy(input.getName())); - } + /** + * Generate into the specified string builder the code to send local variables for input ports to + * a Python reaction function from the "self" struct. + * + * @param input The input port. + */ + public static void generateInputVariablesToSendToPythonReaction( + List pyObjects, Input input, ReactorDecl decl) { + // Create the local variable whose name matches the input.getName(). + // If the input has not been declared mutable, then this is a pointer + // to the upstream output. Otherwise, it is a copy of the upstream output, + // which nevertheless points to the same token and value. There are 8 cases, + // depending on whether the input is mutable, whether it is a multiport, + // and whether it is a token type. + // Easy case first. + if (!input.isMutable() && !ASTUtils.isMultiport(input)) { + // Non-mutable, non-multiport, primitive type. + pyObjects.add(generateConvertCPortToPy(input.getName())); + } else if (input.isMutable() && !ASTUtils.isMultiport(input)) { + // Mutable, non-multiport, primitive type. + // TODO: handle mutable + pyObjects.add(generateConvertCPortToPy(input.getName())); + } else if (!input.isMutable() && ASTUtils.isMultiport(input)) { + // Non-mutable, multiport, primitive. + // TODO: support multiports + pyObjects.add(generateConvertCPortToPy(input.getName())); + } else { + // Mutable, multiport, primitive type + // TODO: support mutable multiports + pyObjects.add(generateConvertCPortToPy(input.getName())); } + } - /** Generate into the specified string builder the code to - * pass local variables for sending data to an input - * of a contained reaction (e.g. for a deadline violation). - * @param definition AST node defining the reactor within which this occurs - * @param port Input of the contained reactor. - */ - public static String generateVariablesForSendingToContainedReactors( - List pyObjects, - Instantiation definition, - Port port - ) { - CodeBuilder code = new CodeBuilder(); - if (definition.getWidthSpec() != null) { - String widthSpec = NONMULTIPORT_WIDTHSPEC; - if (ASTUtils.isMultiport(port)) { - widthSpec = "self->_lf_"+definition.getName()+"[i]."+generateWidthVariable(port.getName()); - } - // Contained reactor is a bank. - // Create a Python list - code.pr(generatePythonListForContainedBank(definition.getName(), port, widthSpec)); - pyObjects.add(definition.getName()+"_py_list"); - } - else { - if (ASTUtils.isMultiport(port)) { - pyObjects.add(generateConvertCPortToPy(definition.getName()+"."+port.getName())); - } else { - pyObjects.add(generateConvertCPortToPy(definition.getName()+"."+port.getName(), NONMULTIPORT_WIDTHSPEC)); - } - } - return code.toString(); + /** + * Generate into the specified string builder the code to pass local variables for sending data to + * an input of a contained reaction (e.g. for a deadline violation). + * + * @param definition AST node defining the reactor within which this occurs + * @param port Input of the contained reactor. + */ + public static String generateVariablesForSendingToContainedReactors( + List pyObjects, Instantiation definition, Port port) { + CodeBuilder code = new CodeBuilder(); + if (definition.getWidthSpec() != null) { + String widthSpec = NONMULTIPORT_WIDTHSPEC; + if (ASTUtils.isMultiport(port)) { + widthSpec = + "self->_lf_" + definition.getName() + "[i]." + generateWidthVariable(port.getName()); + } + // Contained reactor is a bank. + // Create a Python list + code.pr(generatePythonListForContainedBank(definition.getName(), port, widthSpec)); + pyObjects.add(definition.getName() + "_py_list"); + } else { + if (ASTUtils.isMultiport(port)) { + pyObjects.add(generateConvertCPortToPy(definition.getName() + "." + port.getName())); + } else { + pyObjects.add( + generateConvertCPortToPy( + definition.getName() + "." + port.getName(), NONMULTIPORT_WIDTHSPEC)); + } } + return code.toString(); + } + /** + * Generate code that creates a Python list (i.e., []) for contained banks to be passed to Python reactions. + * The Python reaction will then subsequently be able to address each individual bank member of the contained + * bank using an index or an iterator. Each list member will contain the given port + * (which could be a multiport with a width determined by widthSpec). + * + * This is to accommodate reactions like reaction() -> s.out where s is a bank. In this example, + * the generated Python function will have the signature reaction_function_0(self, s_out), where + * s_out is a list of out ports. This will later be turned into the proper s.out format using the + * Python code generated in {@link #generatePythonPortVariableInReaction}. + * + * @param reactorName The name of the bank of reactors (which is the name of the reactor class). + * @param port The port that should be put in the Python list. + * @param widthSpec A string that should be -2 for non-multiports and the width expression for multiports. + */ + public static String generatePythonListForContainedBank( + String reactorName, Port port, String widthSpec) { + return String.join( + "\n", + "PyObject* " + + reactorName + + "_py_list = PyList_New(" + + generateWidthVariable(reactorName) + + ");", + "if(" + reactorName + "_py_list == NULL) {", + " lf_print_error(\"Could not create the list needed for " + reactorName + ".\");", + " if (PyErr_Occurred()) {", + " PyErr_PrintEx(0);", + " PyErr_Clear(); // this will reset the error indicator so we can run Python code" + + " again", + " }", + " /* Release the thread. No Python API allowed beyond this point. */", + " PyGILState_Release(gstate);", + " Py_FinalizeEx();", + " exit(1);", + "}", + "for (int i = 0; i < " + generateWidthVariable(reactorName) + "; i++) {", + " if (PyList_SetItem(" + reactorName + "_py_list,", + " i,", + " " + generateConvertCPortToPy(reactorName + "[i]." + port.getName(), widthSpec), + " ) != 0) {", + " lf_print_error(\"Could not add elements to the list for " + reactorName + ".\");", + " if (PyErr_Occurred()) {", + " PyErr_PrintEx(0);", + " PyErr_Clear(); // this will reset the error indicator so we can run Python" + + " code again", + " }", + " /* Release the thread. No Python API allowed beyond this point. */", + " PyGILState_Release(gstate);", + " Py_FinalizeEx();", + " exit(1);", + " }", + "}"); + } - /** - * Generate code that creates a Python list (i.e., []) for contained banks to be passed to Python reactions. - * The Python reaction will then subsequently be able to address each individual bank member of the contained - * bank using an index or an iterator. Each list member will contain the given port - * (which could be a multiport with a width determined by widthSpec). - * - * This is to accommodate reactions like reaction() -> s.out where s is a bank. In this example, - * the generated Python function will have the signature reaction_function_0(self, s_out), where - * s_out is a list of out ports. This will later be turned into the proper s.out format using the - * Python code generated in {@link #generatePythonPortVariableInReaction}. - * - * @param reactorName The name of the bank of reactors (which is the name of the reactor class). - * @param port The port that should be put in the Python list. - * @param widthSpec A string that should be -2 for non-multiports and the width expression for multiports. - */ - public static String generatePythonListForContainedBank(String reactorName, Port port, String widthSpec) { - return String.join("\n", - "PyObject* "+reactorName+"_py_list = PyList_New("+generateWidthVariable(reactorName)+");", - "if("+reactorName+"_py_list == NULL) {", - " lf_print_error(\"Could not create the list needed for "+reactorName+".\");", - " if (PyErr_Occurred()) {", - " PyErr_PrintEx(0);", - " PyErr_Clear(); // this will reset the error indicator so we can run Python code again", - " }", - " /* Release the thread. No Python API allowed beyond this point. */", - " PyGILState_Release(gstate);", - " Py_FinalizeEx();", - " exit(1);", - "}", - "for (int i = 0; i < "+generateWidthVariable(reactorName)+"; i++) {", - " if (PyList_SetItem("+reactorName+"_py_list,", - " i,", - " "+generateConvertCPortToPy(reactorName + "[i]." + port.getName(), widthSpec), - " ) != 0) {", - " lf_print_error(\"Could not add elements to the list for "+reactorName+".\");", - " if (PyErr_Occurred()) {", - " PyErr_PrintEx(0);", - " PyErr_Clear(); // this will reset the error indicator so we can run Python code again", - " }", - " /* Release the thread. No Python API allowed beyond this point. */", - " PyGILState_Release(gstate);", - " Py_FinalizeEx();", - " exit(1);", - " }", - "}" - ); - } + public static String generateAliasTypeDef( + TypeParameterizedReactor tpr, Port port, boolean isTokenType, String genericPortType) { + return "typedef " + + genericPortType + + " " + + CGenerator.variableStructType(port, tpr, false) + + ";"; + } - public static String generateAliasTypeDef(TypeParameterizedReactor tpr, Port port, boolean isTokenType, String genericPortType) { - return "typedef "+genericPortType+" "+CGenerator.variableStructType(port, tpr, false)+";"; - } - - private static String generateConvertCPortToPy(String port) { - return String.format("convert_C_port_to_py(%s, %s)", port, generateWidthVariable(port)); - } + private static String generateConvertCPortToPy(String port) { + return String.format("convert_C_port_to_py(%s, %s)", port, generateWidthVariable(port)); + } - private static String generateConvertCPortToPy(String port, String widthSpec) { - return String.format("convert_C_port_to_py(%s, %s)", port, widthSpec); - } + private static String generateConvertCPortToPy(String port, String widthSpec) { + return String.format("convert_C_port_to_py(%s, %s)", port, widthSpec); + } - /** - * Generate into the specified string builder (inits) the code to - * initialize local variable for port so that it can be used in the body of - * the Python reaction. - * @param port The port to generate code for. - */ - public static String generatePythonPortVariableInReaction(VarRef port) { - String containerName = port.getContainer().getName(); - String variableName = port.getVariable().getName(); - String tryStatement = "try: "+containerName+" # pylint: disable=used-before-assignment"; - if (port.getContainer().getWidthSpec() != null) { - // It's a bank - return String.join("\n", - tryStatement, - "except NameError: "+containerName+" = [None] * len("+containerName+"_"+variableName+")", - "for i in range(len("+containerName+"_"+variableName+")):", - " if "+containerName+"[i] is None: "+containerName+"[i] = Make()", - " "+containerName+"[i]."+variableName+" = "+containerName+"_"+variableName+"[i]" - ); - } else { - return String.join("\n", - tryStatement, - "except NameError: "+containerName+" = Make()", - containerName+"."+variableName+" = "+containerName+"_"+variableName - ); - } + /** + * Generate into the specified string builder (inits) the code to + * initialize local variable for port so that it can be used in the body of + * the Python reaction. + * @param port The port to generate code for. + */ + public static String generatePythonPortVariableInReaction(VarRef port) { + String containerName = port.getContainer().getName(); + String variableName = port.getVariable().getName(); + String tryStatement = "try: " + containerName + " # pylint: disable=used-before-assignment"; + if (port.getContainer().getWidthSpec() != null) { + // It's a bank + return String.join( + "\n", + tryStatement, + "except NameError: " + + containerName + + " = [None] * len(" + + containerName + + "_" + + variableName + + ")", + "for i in range(len(" + containerName + "_" + variableName + ")):", + " if " + containerName + "[i] is None: " + containerName + "[i] = Make()", + " " + + containerName + + "[i]." + + variableName + + " = " + + containerName + + "_" + + variableName + + "[i]"); + } else { + return String.join( + "\n", + tryStatement, + "except NameError: " + containerName + " = Make()", + containerName + "." + variableName + " = " + containerName + "_" + variableName); } + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java index b69320f6af..bd1291425f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java @@ -3,60 +3,53 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import org.lflang.ast.ASTUtils; import org.lflang.TargetConfig; +import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.generator.c.CPreambleGenerator; import org.lflang.lf.Preamble; - /** - * Generates user-defined preambles and #define and #include directives - * for the Python target. + * Generates user-defined preambles and #define and #include directives for the Python target. * * @author Edward A. Lee * @author Soroush Bateni * @author Hou Seng Wong */ public class PythonPreambleGenerator { - /** - * Generates preambles defined by user for a given reactor. - * The preamble code is put inside the reactor class. - */ - public static String generatePythonPreambles(List preambles) { - List preamblesCode = new ArrayList<>(); - preambles.forEach(p -> preamblesCode.add(ASTUtils.toText(p.getCode()))); - return preamblesCode.size() > 0 ? String.join("\n", + /** + * Generates preambles defined by user for a given reactor. The preamble code is put inside the + * reactor class. + */ + public static String generatePythonPreambles(List preambles) { + List preamblesCode = new ArrayList<>(); + preambles.forEach(p -> preamblesCode.add(ASTUtils.toText(p.getCode()))); + return preamblesCode.size() > 0 + ? String.join( + "\n", "# From the preamble, verbatim:", String.join("\n", preamblesCode), - "# End of preamble." - ) : ""; - } + "# End of preamble.") + : ""; + } - public static String generateCDefineDirectives( - TargetConfig targetConfig, - Path srcGenPath, - boolean hasModalReactors - ) { - // TODO: Delete all of this. It is not used. - CodeBuilder code = new CodeBuilder(); - code.pr(CPreambleGenerator.generateDefineDirectives( - targetConfig, srcGenPath, hasModalReactors) - ); - return code.toString(); - } + public static String generateCDefineDirectives( + TargetConfig targetConfig, Path srcGenPath, boolean hasModalReactors) { + // TODO: Delete all of this. It is not used. + CodeBuilder code = new CodeBuilder(); + code.pr( + CPreambleGenerator.generateDefineDirectives(targetConfig, srcGenPath, hasModalReactors)); + return code.toString(); + } - public static String generateCIncludeStatements( - TargetConfig targetConfig, - boolean CCppMode, - boolean hasModalReactors - ) { - CodeBuilder code = new CodeBuilder(); - code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); - code.pr("#include \"pythontarget.h\""); - if (hasModalReactors) { - code.pr("#include \"include/modal_models/definitions.h\""); - } - return code.toString(); + public static String generateCIncludeStatements( + TargetConfig targetConfig, boolean CCppMode, boolean hasModalReactors) { + CodeBuilder code = new CodeBuilder(); + code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); + code.pr("#include \"pythontarget.h\""); + if (hasModalReactors) { + code.pr("#include \"include/modal_models/definitions.h\""); } + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 3d307b6b52..87f594a71a 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -4,560 +4,632 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; - -import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; import org.lflang.Target; - +import org.lflang.ast.ASTUtils; +import org.lflang.generator.CodeBuilder; +import org.lflang.generator.ReactionInstance; +import org.lflang.generator.ReactorInstance; +import org.lflang.generator.c.CCoreFilesUtils; import org.lflang.generator.c.CReactionGenerator; +import org.lflang.generator.c.CTypes; +import org.lflang.generator.c.CUtil; import org.lflang.generator.c.TypeParameterizedReactor; -import org.lflang.lf.ReactorDecl; -import org.lflang.lf.Reaction; -import org.lflang.lf.Reactor; import org.lflang.lf.Action; import org.lflang.lf.Code; +import org.lflang.lf.Input; +import org.lflang.lf.Instantiation; +import org.lflang.lf.Mode; +import org.lflang.lf.Output; +import org.lflang.lf.Port; +import org.lflang.lf.Reaction; +import org.lflang.lf.Reactor; +import org.lflang.lf.ReactorDecl; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; import org.lflang.util.StringUtil; -import org.lflang.lf.Instantiation; -import org.lflang.lf.Port; -import org.lflang.lf.Input; -import org.lflang.lf.Output; -import org.lflang.generator.c.CCoreFilesUtils; -import org.lflang.generator.c.CTypes; -import org.lflang.generator.c.CUtil; -import org.lflang.generator.CodeBuilder; -import org.lflang.generator.ReactionInstance; -import org.lflang.generator.ReactorInstance; -import org.lflang.lf.Mode; public class PythonReactionGenerator { - /** - * Generate code to call reaction numbered "reactionIndex" in reactor "reactor". - * @param reactor The reactor containing the reaction - * @param reactionIndex The index of the reaction - * @param pyObjects CPython related objects - */ - public static String generateCPythonReactionCaller(TypeParameterizedReactor reactor, - int reactionIndex, - List pyObjects, - String inits) { - String pythonFunctionName = generatePythonReactionFunctionName(reactionIndex); - String cpythonFunctionName = generateCPythonReactionFunctionName(reactionIndex); - return generateCPythonFunctionCaller(CUtil.getName(reactor), pythonFunctionName, cpythonFunctionName, pyObjects, inits); - } - - /** - * Generate code to call deadline function numbered "reactionIndex" in reactor "r". - * @param r The reactor containing the reaction - * @param reactionIndex The index of the reaction - * @param pyObjects CPython related objects - */ - public static String generateCPythonDeadlineCaller(TypeParameterizedReactor r, - int reactionIndex, - List pyObjects) { - String pythonFunctionName = generatePythonDeadlineFunctionName(reactionIndex); - String cpythonFunctionName = generateCPythonDeadlineFunctionName(reactionIndex); - return generateCPythonFunctionCaller(CUtil.getName(r), pythonFunctionName, cpythonFunctionName, pyObjects, ""); - } - - /** - * Generate code to call deadline function numbered "reactionIndex" in reactor "r". - * @param r The reactor containing the reaction - * @param reactionIndex The index of the reaction - * @param pyObjects CPython related objects - */ - public static String generateCPythonSTPCaller(TypeParameterizedReactor r, - int reactionIndex, - List pyObjects) { - String pythonFunctionName = generatePythonSTPFunctionName(reactionIndex); - String cpythonFunctionName = generateCPythonSTPFunctionName(reactionIndex); - return generateCPythonFunctionCaller(CUtil.getName(r), pythonFunctionName, cpythonFunctionName, pyObjects, ""); + /** + * Generate code to call reaction numbered "reactionIndex" in reactor "reactor". + * + * @param reactor The reactor containing the reaction + * @param reactionIndex The index of the reaction + * @param pyObjects CPython related objects + */ + public static String generateCPythonReactionCaller( + TypeParameterizedReactor reactor, int reactionIndex, List pyObjects, String inits) { + String pythonFunctionName = generatePythonReactionFunctionName(reactionIndex); + String cpythonFunctionName = generateCPythonReactionFunctionName(reactionIndex); + return generateCPythonFunctionCaller( + CUtil.getName(reactor), pythonFunctionName, cpythonFunctionName, pyObjects, inits); + } + + /** + * Generate code to call deadline function numbered "reactionIndex" in reactor "r". + * + * @param r The reactor containing the reaction + * @param reactionIndex The index of the reaction + * @param pyObjects CPython related objects + */ + public static String generateCPythonDeadlineCaller( + TypeParameterizedReactor r, int reactionIndex, List pyObjects) { + String pythonFunctionName = generatePythonDeadlineFunctionName(reactionIndex); + String cpythonFunctionName = generateCPythonDeadlineFunctionName(reactionIndex); + return generateCPythonFunctionCaller( + CUtil.getName(r), pythonFunctionName, cpythonFunctionName, pyObjects, ""); + } + + /** + * Generate code to call deadline function numbered "reactionIndex" in reactor "r". + * + * @param r The reactor containing the reaction + * @param reactionIndex The index of the reaction + * @param pyObjects CPython related objects + */ + public static String generateCPythonSTPCaller( + TypeParameterizedReactor r, int reactionIndex, List pyObjects) { + String pythonFunctionName = generatePythonSTPFunctionName(reactionIndex); + String cpythonFunctionName = generateCPythonSTPFunctionName(reactionIndex); + return generateCPythonFunctionCaller( + CUtil.getName(r), pythonFunctionName, cpythonFunctionName, pyObjects, ""); + } + + /** + * Generate code to call a CPython function. + * + * @param reactorDeclName The name of the reactor for debugging purposes + * @param pythonFunctionName The name of the function in the .py file. + * @param cpythonFunctionName The name of the function in self struct of the .c file. + * @param pyObjects CPython related objects + */ + private static String generateCPythonFunctionCaller( + String reactorDeclName, + String pythonFunctionName, + String cpythonFunctionName, + List pyObjects, + String inits) { + String pyObjectsJoined = pyObjects.size() > 0 ? ", " + String.join(", ", pyObjects) : ""; + CodeBuilder code = new CodeBuilder(); + code.pr(PyUtil.generateGILAcquireCode()); + code.pr(inits); + code.pr( + String.join( + "\n", + "LF_PRINT_DEBUG(\"Calling reaction function " + + reactorDeclName + + "." + + pythonFunctionName + + "\");", + "PyObject *rValue = PyObject_CallObject(", + " self->" + cpythonFunctionName + ", ", + " Py_BuildValue(\"(" + "O".repeat(pyObjects.size()) + ")\"" + pyObjectsJoined + ")", + ");", + "if (rValue == NULL) {", + " lf_print_error(\"FATAL: Calling reaction " + + reactorDeclName + + "." + + pythonFunctionName + + " failed.\");", + " if (PyErr_Occurred()) {", + " PyErr_PrintEx(0);", + " PyErr_Clear(); // this will reset the error indicator so we can run Python" + + " code again", + " }", + " " + PyUtil.generateGILReleaseCode(), + " Py_FinalizeEx();", + " exit(1);", + "}", + "", + "/* Release the thread. No Python API allowed beyond this point. */", + PyUtil.generateGILReleaseCode())); + return code.toString(); + } + + /** + * Generate the reaction in the .c file, which calls the Python reaction through the CPython interface. + * + * @param reaction The reaction to generate Python-specific initialization for. + * @param r The reactor to which reaction belongs to. + * @param reactionIndex The index number of the reaction in decl. + * @param mainDef The main reactor. + * @param errorReporter An error reporter. + * @param types A helper class for type-related stuff. + */ + public static String generateCReaction( + Reaction reaction, + TypeParameterizedReactor tpr, + Reactor r, + int reactionIndex, + Instantiation mainDef, + ErrorReporter errorReporter, + CTypes types) { + // Contains the actual comma separated list of inputs to the reaction of type + // generic_port_instance_struct. + // Each input must be cast to (PyObject *) (aka their descriptors for Py_BuildValue are "O") + List pyObjects = new ArrayList<>(); + CodeBuilder code = new CodeBuilder(); + String cPyInit = generateCPythonInitializers(reaction, r, pyObjects, errorReporter); + String cInit = + CReactionGenerator.generateInitializationForReaction( + "", + reaction, + tpr, + reactionIndex, + types, + errorReporter, + mainDef, + Target.Python.requiresTypes); + code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetHeader())); + code.pr( + generateFunction( + CReactionGenerator.generateReactionFunctionHeader(tpr, reactionIndex), + cInit, + reaction.getCode(), + generateCPythonReactionCaller(tpr, reactionIndex, pyObjects, cPyInit))); + + // Generate code for the STP violation handler, if there is one. + if (reaction.getStp() != null) { + code.pr( + generateFunction( + CReactionGenerator.generateStpFunctionHeader(tpr, reactionIndex), + cInit, + reaction.getStp().getCode(), + generateCPythonSTPCaller(tpr, reactionIndex, pyObjects))); } - - /** - * Generate code to call a CPython function. - * @param reactorDeclName The name of the reactor for debugging purposes - * @param pythonFunctionName The name of the function in the .py file. - * @param cpythonFunctionName The name of the function in self struct of the .c file. - * @param pyObjects CPython related objects - */ - private static String generateCPythonFunctionCaller(String reactorDeclName, - String pythonFunctionName, - String cpythonFunctionName, - List pyObjects, - String inits) { - String pyObjectsJoined = pyObjects.size() > 0 ? ", " + String.join(", ", pyObjects) : ""; - CodeBuilder code = new CodeBuilder(); - code.pr(PyUtil.generateGILAcquireCode()); - code.pr(inits); - code.pr(String.join("\n", - "LF_PRINT_DEBUG(\"Calling reaction function "+reactorDeclName+"."+pythonFunctionName+"\");", - "PyObject *rValue = PyObject_CallObject(", - " self->"+cpythonFunctionName+", ", - " Py_BuildValue(\"("+"O".repeat(pyObjects.size())+")\""+pyObjectsJoined+")", - ");", - "if (rValue == NULL) {", - " lf_print_error(\"FATAL: Calling reaction "+reactorDeclName+"."+pythonFunctionName+" failed.\");", - " if (PyErr_Occurred()) {", - " PyErr_PrintEx(0);", - " PyErr_Clear(); // this will reset the error indicator so we can run Python code again", - " }", - " "+PyUtil.generateGILReleaseCode(), - " Py_FinalizeEx();", - " exit(1);", - "}", - "", - "/* Release the thread. No Python API allowed beyond this point. */", - PyUtil.generateGILReleaseCode() - )); - return code.toString(); + // Generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr( + generateFunction( + CReactionGenerator.generateDeadlineFunctionHeader(tpr, reactionIndex), + cInit, + reaction.getDeadline().getCode(), + generateCPythonDeadlineCaller(tpr, reactionIndex, pyObjects))); } - - /** - * Generate the reaction in the .c file, which calls the Python reaction through the CPython interface. - * - * @param reaction The reaction to generate Python-specific initialization for. - * @param r The reactor to which reaction belongs to. - * @param reactionIndex The index number of the reaction in decl. - * @param mainDef The main reactor. - * @param errorReporter An error reporter. - * @param types A helper class for type-related stuff. - */ - public static String generateCReaction( - Reaction reaction, - TypeParameterizedReactor tpr, - Reactor r, - int reactionIndex, - Instantiation mainDef, - ErrorReporter errorReporter, - CTypes types - ) { - // Contains the actual comma separated list of inputs to the reaction of type generic_port_instance_struct. - // Each input must be cast to (PyObject *) (aka their descriptors for Py_BuildValue are "O") - List pyObjects = new ArrayList<>(); - CodeBuilder code = new CodeBuilder(); - String cPyInit = generateCPythonInitializers(reaction, r, pyObjects, errorReporter); - String cInit = CReactionGenerator.generateInitializationForReaction( - "", reaction, tpr, reactionIndex, - types, errorReporter, mainDef, - Target.Python.requiresTypes); + code.pr("#include " + StringUtil.addDoubleQuotes(CCoreFilesUtils.getCTargetSetUndefHeader())); + return code.toString(); + } + + public static String generateFunction(String header, String init, Code code, String pyCaller) { + var function = new CodeBuilder(); + function.pr(header + "{"); + function.indent(); + function.pr(init); + function.prSourceLineNumber(code); + function.pr(pyCaller); + function.unindent(); + function.pr("}"); + return function.toString(); + } + + /** + * Generate necessary Python-specific initialization code for reaction that belongs to reactor + * decl. + * + * @param reaction The reaction to generate Python-specific initialization for. + * @param decl The reactor to which reaction belongs to. + * @param pyObjects A list of expressions that can be used as additional arguments to Py_BuildValue + * (@see docs.python.org/3/c-api). + * We will use as a format string, "(O...O)" where the number of O's is equal to the length of the list. + */ + private static String generateCPythonInitializers( + Reaction reaction, ReactorDecl decl, List pyObjects, ErrorReporter errorReporter) { + Set actionsAsTriggers = new LinkedHashSet<>(); + Reactor reactor = ASTUtils.toDefinition(decl); + CodeBuilder code = new CodeBuilder(); + // Next, add the triggers (input and actions; timers are not needed). + // TODO: handle triggers + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (trigger instanceof VarRef triggerAsVarRef) { code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetHeader())); - code.pr(generateFunction( - CReactionGenerator.generateReactionFunctionHeader(tpr, reactionIndex), - cInit, reaction.getCode(), - generateCPythonReactionCaller(tpr, reactionIndex, pyObjects, cPyInit) - )); - - // Generate code for the STP violation handler, if there is one. - if (reaction.getStp() != null) { - code.pr(generateFunction( - CReactionGenerator.generateStpFunctionHeader(tpr, reactionIndex), - cInit, reaction.getStp().getCode(), - generateCPythonSTPCaller(tpr, reactionIndex, pyObjects) - )); - } - // Generate code for the deadline violation function, if there is one. - if (reaction.getDeadline() != null) { - code.pr(generateFunction( - CReactionGenerator.generateDeadlineFunctionHeader(tpr, reactionIndex), - cInit, reaction.getDeadline().getCode(), - generateCPythonDeadlineCaller(tpr, reactionIndex, pyObjects) - )); - } - code.pr( - "#include " + StringUtil.addDoubleQuotes( - CCoreFilesUtils.getCTargetSetUndefHeader())); - return code.toString(); + generateVariableToSendPythonReaction( + triggerAsVarRef, actionsAsTriggers, decl, pyObjects)); + } } - - public static String generateFunction( - String header, String init, Code code, String pyCaller - ) { - var function = new CodeBuilder(); - function.pr(header + "{"); - function.indent(); - function.pr(init); - function.prSourceLineNumber(code); - function.pr(pyCaller); - function.unindent(); - function.pr("}"); - return function.toString(); + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + // No triggers are given, which means react to any input. + // Declare an argument for every input. + // NOTE: this does not include contained outputs. + for (Input input : reactor.getInputs()) { + PythonPortGenerator.generateInputVariablesToSendToPythonReaction(pyObjects, input, decl); + } } - /** - * Generate necessary Python-specific initialization code for reaction that belongs to reactor - * decl. - * - * @param reaction The reaction to generate Python-specific initialization for. - * @param decl The reactor to which reaction belongs to. - * @param pyObjects A list of expressions that can be used as additional arguments to Py_BuildValue - * (@see docs.python.org/3/c-api). - * We will use as a format string, "(O...O)" where the number of O's is equal to the length of the list. - */ - private static String generateCPythonInitializers(Reaction reaction, - ReactorDecl decl, - List pyObjects, - ErrorReporter errorReporter) { - Set actionsAsTriggers = new LinkedHashSet<>(); - Reactor reactor = ASTUtils.toDefinition(decl); - CodeBuilder code = new CodeBuilder(); - // Next, add the triggers (input and actions; timers are not needed). - // TODO: handle triggers - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (trigger instanceof VarRef triggerAsVarRef) { - code.pr(generateVariableToSendPythonReaction(triggerAsVarRef, actionsAsTriggers, decl, pyObjects)); - } - } - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - // No triggers are given, which means react to any input. - // Declare an argument for every input. - // NOTE: this does not include contained outputs. - for (Input input : reactor.getInputs()) { - PythonPortGenerator.generateInputVariablesToSendToPythonReaction(pyObjects, input, decl); - } - } - - // Next add non-triggering inputs. - for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - code.pr(generateVariableToSendPythonReaction(src, actionsAsTriggers, decl, pyObjects)); - } - - // Next, handle effects - if (reaction.getEffects() != null) { - for (VarRef effect : reaction.getEffects()) { - if (effect.getVariable() instanceof Action) { - // It is an action, not an output. - // If it has already appeared as trigger, do not redefine it. - if (!actionsAsTriggers.contains(effect.getVariable())) { - PythonPortGenerator.generateActionVariableToSendToPythonReaction(pyObjects, - (Action) effect.getVariable(), decl); - } - } else if (effect.getVariable() instanceof Mode) { - String name = effect.getVariable().getName(); - pyObjects.add("convert_C_mode_to_py("+name+",(self_base_t*)self, _lf_"+name+"_change_type)"); - } else { - if (effect.getVariable() instanceof Output) { - PythonPortGenerator.generateOutputVariablesToSendToPythonReaction(pyObjects, (Output) effect.getVariable()); - } else if (effect.getVariable() instanceof Input) { - // It is the input of a contained reactor. - code.pr(PythonPortGenerator.generateVariablesForSendingToContainedReactors(pyObjects, effect.getContainer(), (Input) effect.getVariable())); - } else { - errorReporter.reportError( - reaction, - "In generateReaction(): " + effect.getVariable().getName() + " is neither an input nor an output." - ); - } - } - } - } - return code.toString(); + // Next add non-triggering inputs. + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + code.pr(generateVariableToSendPythonReaction(src, actionsAsTriggers, decl, pyObjects)); } - /** - * Generate parameters and their respective initialization code for a reaction function - * The initialization code is put at the beginning of the reaction before user code - * @param parameters The parameters used for function definition - * @param inits The initialization code for those paramters - * @param decl Reactor declaration - * @param reaction The reaction to be used to generate parameters for - */ - public static void generatePythonReactionParametersAndInitializations(List parameters, CodeBuilder inits, - ReactorDecl decl, Reaction reaction) { - Reactor reactor = ASTUtils.toDefinition(decl); - LinkedHashSet generatedParams = new LinkedHashSet<>(); - - // Handle triggers - for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { - if (!(trigger instanceof VarRef triggerAsVarRef)) { - continue; - } - if (triggerAsVarRef.getVariable() instanceof Port) { - if (triggerAsVarRef.getVariable() instanceof Input) { - if (((Input) triggerAsVarRef.getVariable()).isMutable()) { - generatedParams.add("mutable_"+triggerAsVarRef.getVariable().getName()); - - // Create a deep copy - if (ASTUtils.isMultiport((Input) triggerAsVarRef.getVariable())) { - inits. - pr(triggerAsVarRef.getVariable().getName()+" = [Make() for i in range(len(mutable_"+triggerAsVarRef.getVariable().getName()+"))]"); - inits.pr("for i in range(len(mutable_"+triggerAsVarRef.getVariable().getName()+")):"); - inits.pr(" "+triggerAsVarRef.getVariable().getName()+"[i].value = copy.deepcopy(mutable_"+triggerAsVarRef.getVariable().getName()+"[i].value)"); - } else { - inits.pr(triggerAsVarRef.getVariable().getName()+" = Make()"); - inits. - pr(triggerAsVarRef.getVariable().getName()+".value = copy.deepcopy(mutable_"+triggerAsVarRef.getVariable().getName()+".value)"); - } - } else { - generatedParams.add(triggerAsVarRef.getVariable().getName()); - } - } else { - // Handle contained reactors' ports - generatedParams.add(triggerAsVarRef.getContainer().getName()+"_"+triggerAsVarRef.getVariable().getName()); - inits.pr(PythonPortGenerator.generatePythonPortVariableInReaction(triggerAsVarRef)); - } - } else if (triggerAsVarRef.getVariable() instanceof Action) { - generatedParams.add(triggerAsVarRef.getVariable().getName()); - } - } - - // Handle non-triggering inputs - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - for (Input input : ASTUtils.convertToEmptyListIfNull(reactor.getInputs())) { - generatedParams.add(input.getName()); - if (input.isMutable()) { - // Create a deep copy - inits.pr(input.getName()+" = copy.deepcopy("+input.getName()+")"); - } - } - } - for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { - if (src.getVariable() instanceof Output) { - // Output of a contained reactor - generatedParams.add(src.getContainer().getName()+"_"+src.getVariable().getName()); - inits.pr(PythonPortGenerator.generatePythonPortVariableInReaction(src)); - } else { - generatedParams.add(src.getVariable().getName()); - if (src.getVariable() instanceof Input) { - if (((Input) src.getVariable()).isMutable()) { - // Create a deep copy - inits.pr(src.getVariable().getName()+" = copy.deepcopy("+src.getVariable().getName()+")"); - } - } - } + // Next, handle effects + if (reaction.getEffects() != null) { + for (VarRef effect : reaction.getEffects()) { + if (effect.getVariable() instanceof Action) { + // It is an action, not an output. + // If it has already appeared as trigger, do not redefine it. + if (!actionsAsTriggers.contains(effect.getVariable())) { + PythonPortGenerator.generateActionVariableToSendToPythonReaction( + pyObjects, (Action) effect.getVariable(), decl); + } + } else if (effect.getVariable() instanceof Mode) { + String name = effect.getVariable().getName(); + pyObjects.add( + "convert_C_mode_to_py(" + + name + + ",(self_base_t*)self, _lf_" + + name + + "_change_type)"); + } else { + if (effect.getVariable() instanceof Output) { + PythonPortGenerator.generateOutputVariablesToSendToPythonReaction( + pyObjects, (Output) effect.getVariable()); + } else if (effect.getVariable() instanceof Input) { + // It is the input of a contained reactor. + code.pr( + PythonPortGenerator.generateVariablesForSendingToContainedReactors( + pyObjects, effect.getContainer(), (Input) effect.getVariable())); + } else { + errorReporter.reportError( + reaction, + "In generateReaction(): " + + effect.getVariable().getName() + + " is neither an input nor an output."); + } } - - // Handle effects - for (VarRef effect : ASTUtils.convertToEmptyListIfNull(reaction.getEffects())) { - if (effect.getVariable() instanceof Input) { - generatedParams.add(effect.getContainer().getName()+"_"+effect.getVariable().getName()); - inits.pr(PythonPortGenerator.generatePythonPortVariableInReaction(effect)); + } + } + return code.toString(); + } + + /** + * Generate parameters and their respective initialization code for a reaction function The + * initialization code is put at the beginning of the reaction before user code + * + * @param parameters The parameters used for function definition + * @param inits The initialization code for those paramters + * @param decl Reactor declaration + * @param reaction The reaction to be used to generate parameters for + */ + public static void generatePythonReactionParametersAndInitializations( + List parameters, CodeBuilder inits, ReactorDecl decl, Reaction reaction) { + Reactor reactor = ASTUtils.toDefinition(decl); + LinkedHashSet generatedParams = new LinkedHashSet<>(); + + // Handle triggers + for (TriggerRef trigger : ASTUtils.convertToEmptyListIfNull(reaction.getTriggers())) { + if (!(trigger instanceof VarRef triggerAsVarRef)) { + continue; + } + if (triggerAsVarRef.getVariable() instanceof Port) { + if (triggerAsVarRef.getVariable() instanceof Input) { + if (((Input) triggerAsVarRef.getVariable()).isMutable()) { + generatedParams.add("mutable_" + triggerAsVarRef.getVariable().getName()); + + // Create a deep copy + if (ASTUtils.isMultiport((Input) triggerAsVarRef.getVariable())) { + inits.pr( + triggerAsVarRef.getVariable().getName() + + " = [Make() for i in range(len(mutable_" + + triggerAsVarRef.getVariable().getName() + + "))]"); + inits.pr( + "for i in range(len(mutable_" + triggerAsVarRef.getVariable().getName() + ")):"); + inits.pr( + " " + + triggerAsVarRef.getVariable().getName() + + "[i].value = copy.deepcopy(mutable_" + + triggerAsVarRef.getVariable().getName() + + "[i].value)"); } else { - generatedParams.add(effect.getVariable().getName()); - if (effect.getVariable() instanceof Port) { - if (ASTUtils.isMultiport((Port) effect.getVariable())) { - // Handle multiports - } - } + inits.pr(triggerAsVarRef.getVariable().getName() + " = Make()"); + inits.pr( + triggerAsVarRef.getVariable().getName() + + ".value = copy.deepcopy(mutable_" + + triggerAsVarRef.getVariable().getName() + + ".value)"); } + } else { + generatedParams.add(triggerAsVarRef.getVariable().getName()); + } + } else { + // Handle contained reactors' ports + generatedParams.add( + triggerAsVarRef.getContainer().getName() + + "_" + + triggerAsVarRef.getVariable().getName()); + inits.pr(PythonPortGenerator.generatePythonPortVariableInReaction(triggerAsVarRef)); } - - for (String s : generatedParams) { - parameters.add(s); - } + } else if (triggerAsVarRef.getVariable() instanceof Action) { + generatedParams.add(triggerAsVarRef.getVariable().getName()); + } } - private static String generateVariableToSendPythonReaction(VarRef varRef, - Set actionsAsTriggers, - ReactorDecl decl, - List pyObjects) { - if (varRef.getVariable() instanceof Port) { - return PythonPortGenerator.generatePortVariablesToSendToPythonReaction(pyObjects, varRef, decl); - } else if (varRef.getVariable() instanceof Action) { - actionsAsTriggers.add((Action) varRef.getVariable()); - PythonPortGenerator.generateActionVariableToSendToPythonReaction(pyObjects, (Action) varRef.getVariable(), decl); + // Handle non-triggering inputs + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + for (Input input : ASTUtils.convertToEmptyListIfNull(reactor.getInputs())) { + generatedParams.add(input.getName()); + if (input.isMutable()) { + // Create a deep copy + inits.pr(input.getName() + " = copy.deepcopy(" + input.getName() + ")"); } - return ""; + } } - - /** - * Generate Python code to link cpython functions to python functions for each reaction. - * @param instance The reactor instance. - * @param mainDef The definition of the main reactor - */ - public static String generateCPythonReactionLinkers( - ReactorInstance instance, - Instantiation mainDef - ) { - String nameOfSelfStruct = CUtil.reactorRef(instance); - Reactor reactor = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); - CodeBuilder code = new CodeBuilder(); - - // Initialize the name field to the unique name of the instance - code.pr(nameOfSelfStruct+"->_lf_name = \""+instance.uniqueID()+"_lf\";"); - - for (ReactionInstance reaction : instance.reactions) { - // Reactions marked with a {@code @_c_body} attribute are generated in C - if (AttributeUtils.hasCBody(reaction.getDefinition())) continue; - // Create a PyObject for each reaction - code.pr(generateCPythonReactionLinker(instance, reaction, nameOfSelfStruct)); + for (VarRef src : ASTUtils.convertToEmptyListIfNull(reaction.getSources())) { + if (src.getVariable() instanceof Output) { + // Output of a contained reactor + generatedParams.add(src.getContainer().getName() + "_" + src.getVariable().getName()); + inits.pr(PythonPortGenerator.generatePythonPortVariableInReaction(src)); + } else { + generatedParams.add(src.getVariable().getName()); + if (src.getVariable() instanceof Input) { + if (((Input) src.getVariable()).isMutable()) { + // Create a deep copy + inits.pr( + src.getVariable().getName() + + " = copy.deepcopy(" + + src.getVariable().getName() + + ")"); + } } - return code.toString(); + } } - /** - * Generate Python code to link cpython functions to python functions for a reaction. - * @param instance The reactor instance. - * @param reaction The reaction of this instance to link. - * @param nameOfSelfStruct The name of the self struct in cpython. - */ - public static String generateCPythonReactionLinker( - ReactorInstance instance, - ReactionInstance reaction, - String nameOfSelfStruct - ) { - CodeBuilder code = new CodeBuilder(); - code.pr(generateCPythonFunctionLinker( - nameOfSelfStruct, generateCPythonReactionFunctionName(reaction.index), - instance, generatePythonReactionFunctionName(reaction.index)) - ); - if (reaction.getDefinition().getStp() != null) { - code.pr(generateCPythonFunctionLinker( - nameOfSelfStruct, generateCPythonSTPFunctionName(reaction.index), - instance, generatePythonSTPFunctionName(reaction.index)) - ); - } - if (reaction.getDefinition().getDeadline() != null) { - code.pr(generateCPythonFunctionLinker( - nameOfSelfStruct, generateCPythonDeadlineFunctionName(reaction.index), - instance, generatePythonDeadlineFunctionName(reaction.index)) - ); + // Handle effects + for (VarRef effect : ASTUtils.convertToEmptyListIfNull(reaction.getEffects())) { + if (effect.getVariable() instanceof Input) { + generatedParams.add(effect.getContainer().getName() + "_" + effect.getVariable().getName()); + inits.pr(PythonPortGenerator.generatePythonPortVariableInReaction(effect)); + } else { + generatedParams.add(effect.getVariable().getName()); + if (effect.getVariable() instanceof Port) { + if (ASTUtils.isMultiport((Port) effect.getVariable())) { + // Handle multiports + } } - return code.toString(); + } } - /** - * Generate code to link "pythonFunctionName" to "cpythonFunctionName" in "nameOfSelfStruct" of "instance". - * @param nameOfSelfStruct the self struct name of instance - * @param cpythonFunctionName the name of the cpython function - * @param instance the reactor instance - * @param pythonFunctionName the name of the python function - */ - private static String generateCPythonFunctionLinker(String nameOfSelfStruct, String cpythonFunctionName, ReactorInstance instance, String pythonFunctionName) { - return String.join("\n", - nameOfSelfStruct+"->"+cpythonFunctionName+" = ", - "get_python_function(\"__main__\", ", - " "+nameOfSelfStruct+"->_lf_name,", - " "+CUtil.runtimeIndex(instance)+",", - " \""+pythonFunctionName+"\");", - "if("+nameOfSelfStruct+"->"+cpythonFunctionName+" == NULL) {", - " lf_print_error_and_exit(\"Could not load function "+pythonFunctionName+"\");", - "}" - ); + for (String s : generatedParams) { + parameters.add(s); } - - /** - * Generate the function that is executed whenever the deadline of the reaction - * with the given reaction index is missed - * @param reaction The reaction to generate deadline miss code for - * @param reactionIndex The agreed-upon index of the reaction in the reactor (should match the C generated code) - * @param reactionParameters The parameters to the deadline violation function, which are the same as the reaction function - */ - public static String generatePythonFunction(String pythonFunctionName, String inits, String reactionBody, List reactionParameters) { - String params = reactionParameters.size() > 0 ? ", " + String.join(", ", reactionParameters) : ""; - CodeBuilder code = new CodeBuilder(); - code.pr("def "+pythonFunctionName+"(self"+params+"):"); - code.indent(); - code.pr(inits); - code.pr(reactionBody); - code.pr("return 0"); - return code.toString(); - } - - - /** - * Generate the Python code for reactions in reactor - * @param reactor The reactor - * @param reactions The reactions of reactor - */ - public static String generatePythonReactions(Reactor reactor, List reactions) { - CodeBuilder code = new CodeBuilder(); - int reactionIndex = 0; - for (Reaction reaction : reactions) { - code.pr(generatePythonReaction(reactor, reaction, reactionIndex)); - reactionIndex++; - } - return code.toString(); - } - - /** - * Generate the Python code for reaction in reactor - * @param reactor The reactor - * @param reaction The reaction of reactor - */ - public static String generatePythonReaction(Reactor reactor, Reaction reaction, int reactionIndex) { - // Reactions marked with a {@code @_c_body} attribute are generated in C - if (AttributeUtils.hasCBody(reaction)) return ""; - - CodeBuilder code = new CodeBuilder(); - List reactionParameters = new ArrayList<>(); // Will contain parameters for the function (e.g., Foo(x,y,z,...) - CodeBuilder inits = new CodeBuilder(); // Will contain initialization code for some parameters - PythonReactionGenerator.generatePythonReactionParametersAndInitializations(reactionParameters, inits, reactor, reaction); - code.pr(generatePythonFunction( - generatePythonReactionFunctionName(reactionIndex), - inits.toString(), - ASTUtils.toText(reaction.getCode()), - reactionParameters - )); - // Generate code for the STP violation handler function, if there is one. - if (reaction.getStp() != null) { - code.pr(generatePythonFunction( - generatePythonSTPFunctionName(reactionIndex), - "", - ASTUtils.toText(reaction.getStp().getCode()), - reactionParameters - )); - } - // Generate code for the deadline violation function, if there is one. - if (reaction.getDeadline() != null) { - code.pr(generatePythonFunction( - generatePythonDeadlineFunctionName(reactionIndex), - "", - ASTUtils.toText(reaction.getDeadline().getCode()), - reactionParameters - )); - } - return code.toString(); + } + + private static String generateVariableToSendPythonReaction( + VarRef varRef, Set actionsAsTriggers, ReactorDecl decl, List pyObjects) { + if (varRef.getVariable() instanceof Port) { + return PythonPortGenerator.generatePortVariablesToSendToPythonReaction( + pyObjects, varRef, decl); + } else if (varRef.getVariable() instanceof Action) { + actionsAsTriggers.add((Action) varRef.getVariable()); + PythonPortGenerator.generateActionVariableToSendToPythonReaction( + pyObjects, (Action) varRef.getVariable(), decl); } - - /** Return the function name of the reaction inside the self struct in the .c file. - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateCPythonReactionFunctionName(int reactionIndex) { - return "_lf_py_reaction_function_"+reactionIndex; + return ""; + } + + /** + * Generate Python code to link cpython functions to python functions for each reaction. + * + * @param instance The reactor instance. + * @param mainDef The definition of the main reactor + */ + public static String generateCPythonReactionLinkers( + ReactorInstance instance, Instantiation mainDef) { + String nameOfSelfStruct = CUtil.reactorRef(instance); + Reactor reactor = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); + CodeBuilder code = new CodeBuilder(); + + // Initialize the name field to the unique name of the instance + code.pr(nameOfSelfStruct + "->_lf_name = \"" + instance.uniqueID() + "_lf\";"); + + for (ReactionInstance reaction : instance.reactions) { + // Reactions marked with a {@code @_c_body} attribute are generated in C + if (AttributeUtils.hasCBody(reaction.getDefinition())) continue; + // Create a PyObject for each reaction + code.pr(generateCPythonReactionLinker(instance, reaction, nameOfSelfStruct)); } - - /** Return the function name of the deadline function inside the self struct in the .c file. - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateCPythonDeadlineFunctionName(int reactionIndex) { - return "_lf_py_deadline_function_"+reactionIndex; + return code.toString(); + } + + /** + * Generate Python code to link cpython functions to python functions for a reaction. + * + * @param instance The reactor instance. + * @param reaction The reaction of this instance to link. + * @param nameOfSelfStruct The name of the self struct in cpython. + */ + public static String generateCPythonReactionLinker( + ReactorInstance instance, ReactionInstance reaction, String nameOfSelfStruct) { + CodeBuilder code = new CodeBuilder(); + code.pr( + generateCPythonFunctionLinker( + nameOfSelfStruct, generateCPythonReactionFunctionName(reaction.index), + instance, generatePythonReactionFunctionName(reaction.index))); + if (reaction.getDefinition().getStp() != null) { + code.pr( + generateCPythonFunctionLinker( + nameOfSelfStruct, generateCPythonSTPFunctionName(reaction.index), + instance, generatePythonSTPFunctionName(reaction.index))); } - - /** Return the function name of the STP violation handler function inside the self struct in the .c file. - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generateCPythonSTPFunctionName(int reactionIndex) { - return "_lf_py_STP_function_"+reactionIndex; + if (reaction.getDefinition().getDeadline() != null) { + code.pr( + generateCPythonFunctionLinker( + nameOfSelfStruct, generateCPythonDeadlineFunctionName(reaction.index), + instance, generatePythonDeadlineFunctionName(reaction.index))); } - - /** Return the function name of the reaction in the .py file. - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generatePythonReactionFunctionName(int reactionIndex) { - return "reaction_function_" + reactionIndex; + return code.toString(); + } + + /** + * Generate code to link "pythonFunctionName" to "cpythonFunctionName" in "nameOfSelfStruct" of + * "instance". + * + * @param nameOfSelfStruct the self struct name of instance + * @param cpythonFunctionName the name of the cpython function + * @param instance the reactor instance + * @param pythonFunctionName the name of the python function + */ + private static String generateCPythonFunctionLinker( + String nameOfSelfStruct, + String cpythonFunctionName, + ReactorInstance instance, + String pythonFunctionName) { + return String.join( + "\n", + nameOfSelfStruct + "->" + cpythonFunctionName + " = ", + "get_python_function(\"__main__\", ", + " " + nameOfSelfStruct + "->_lf_name,", + " " + CUtil.runtimeIndex(instance) + ",", + " \"" + pythonFunctionName + "\");", + "if(" + nameOfSelfStruct + "->" + cpythonFunctionName + " == NULL) {", + " lf_print_error_and_exit(\"Could not load function " + pythonFunctionName + "\");", + "}"); + } + + /** + * Generate the function that is executed whenever the deadline of the reaction with the given + * reaction index is missed + * + * @param reaction The reaction to generate deadline miss code for + * @param reactionIndex The agreed-upon index of the reaction in the reactor (should match the C + * generated code) + * @param reactionParameters The parameters to the deadline violation function, which are the same + * as the reaction function + */ + public static String generatePythonFunction( + String pythonFunctionName, + String inits, + String reactionBody, + List reactionParameters) { + String params = + reactionParameters.size() > 0 ? ", " + String.join(", ", reactionParameters) : ""; + CodeBuilder code = new CodeBuilder(); + code.pr("def " + pythonFunctionName + "(self" + params + "):"); + code.indent(); + code.pr(inits); + code.pr(reactionBody); + code.pr("return 0"); + return code.toString(); + } + + /** + * Generate the Python code for reactions in reactor + * + * @param reactor The reactor + * @param reactions The reactions of reactor + */ + public static String generatePythonReactions(Reactor reactor, List reactions) { + CodeBuilder code = new CodeBuilder(); + int reactionIndex = 0; + for (Reaction reaction : reactions) { + code.pr(generatePythonReaction(reactor, reaction, reactionIndex)); + reactionIndex++; } - - /** Return the function name of the deadline function in the .py file. - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generatePythonDeadlineFunctionName(int reactionIndex) { - return "deadline_function_" + reactionIndex; + return code.toString(); + } + + /** + * Generate the Python code for reaction in reactor + * + * @param reactor The reactor + * @param reaction The reaction of reactor + */ + public static String generatePythonReaction( + Reactor reactor, Reaction reaction, int reactionIndex) { + // Reactions marked with a {@code @_c_body} attribute are generated in C + if (AttributeUtils.hasCBody(reaction)) return ""; + + CodeBuilder code = new CodeBuilder(); + List reactionParameters = + new ArrayList<>(); // Will contain parameters for the function (e.g., Foo(x,y,z,...) + CodeBuilder inits = new CodeBuilder(); // Will contain initialization code for some parameters + PythonReactionGenerator.generatePythonReactionParametersAndInitializations( + reactionParameters, inits, reactor, reaction); + code.pr( + generatePythonFunction( + generatePythonReactionFunctionName(reactionIndex), + inits.toString(), + ASTUtils.toText(reaction.getCode()), + reactionParameters)); + // Generate code for the STP violation handler function, if there is one. + if (reaction.getStp() != null) { + code.pr( + generatePythonFunction( + generatePythonSTPFunctionName(reactionIndex), + "", + ASTUtils.toText(reaction.getStp().getCode()), + reactionParameters)); } - - /** Return the function name of the STP violation handler function in the .py file. - * @param reactionIndex The reaction index. - * @return The function name for the reaction. - */ - public static String generatePythonSTPFunctionName(int reactionIndex) { - return "STP_function_" + reactionIndex; + // Generate code for the deadline violation function, if there is one. + if (reaction.getDeadline() != null) { + code.pr( + generatePythonFunction( + generatePythonDeadlineFunctionName(reactionIndex), + "", + ASTUtils.toText(reaction.getDeadline().getCode()), + reactionParameters)); } + return code.toString(); + } + + /** + * Return the function name of the reaction inside the self struct in the .c file. + * + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateCPythonReactionFunctionName(int reactionIndex) { + return "_lf_py_reaction_function_" + reactionIndex; + } + + /** + * Return the function name of the deadline function inside the self struct in the .c file. + * + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateCPythonDeadlineFunctionName(int reactionIndex) { + return "_lf_py_deadline_function_" + reactionIndex; + } + + /** + * Return the function name of the STP violation handler function inside the self struct in the .c + * file. + * + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generateCPythonSTPFunctionName(int reactionIndex) { + return "_lf_py_STP_function_" + reactionIndex; + } + + /** + * Return the function name of the reaction in the .py file. + * + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generatePythonReactionFunctionName(int reactionIndex) { + return "reaction_function_" + reactionIndex; + } + + /** + * Return the function name of the deadline function in the .py file. + * + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generatePythonDeadlineFunctionName(int reactionIndex) { + return "deadline_function_" + reactionIndex; + } + + /** + * Return the function name of the STP violation handler function in the .py file. + * + * @param reactionIndex The reaction index. + * @return The function name for the reaction. + */ + public static String generatePythonSTPFunctionName(int reactionIndex) { + return "STP_function_" + reactionIndex; + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java index 6e1a7f0183..8f2d3fd8ad 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java @@ -11,149 +11,162 @@ import org.lflang.lf.ReactorDecl; public class PythonReactorGenerator { - /** - * Wrapper function for the more elaborate generatePythonReactorClass that keeps track - * of visited reactors to avoid duplicate generation - * @param instance The reactor instance to be generated - */ - public static String generatePythonClass(ReactorInstance instance, ReactorInstance main, PythonTypes types) { - List instantiatedClasses = new ArrayList<>(); - return generatePythonClass(instance, instantiatedClasses, main, types); - } - - /** - * Generate a Python class corresponding to decl - * @param instance The reactor instance to be generated - * @param instantiatedClasses A list of visited instances to avoid generating duplicates - */ - public static String generatePythonClass(ReactorInstance instance, - List instantiatedClasses, - ReactorInstance main, PythonTypes types) { - CodeBuilder pythonClasses = new CodeBuilder(); - ReactorDecl decl = instance.getDefinition().getReactorClass(); - Reactor reactor = ASTUtils.toDefinition(decl); - String className = PyUtil.getName(instance.tpr); - if (instantiatedClasses == null) { - return ""; - } - - if (!instantiatedClasses.contains(className)) { - pythonClasses.pr(generatePythonClassHeader(className)); - // Generate preamble code - pythonClasses.indent(); - pythonClasses.pr(PythonPreambleGenerator.generatePythonPreambles(reactor.getPreambles())); - // Handle runtime initializations - pythonClasses.pr(generatePythonConstructor(decl, types)); - pythonClasses.pr(PythonParameterGenerator.generatePythonGetters(decl)); - // Generate methods - pythonClasses.pr(PythonMethodGenerator.generateMethods(reactor)); - // Generate reactions - List reactionToGenerate = ASTUtils.allReactions(reactor); - pythonClasses.pr(PythonReactionGenerator.generatePythonReactions(reactor, reactionToGenerate)); - pythonClasses.unindent(); - pythonClasses.pr("\n"); - instantiatedClasses.add(className); - } + /** + * Wrapper function for the more elaborate generatePythonReactorClass that keeps track of visited + * reactors to avoid duplicate generation + * + * @param instance The reactor instance to be generated + */ + public static String generatePythonClass( + ReactorInstance instance, ReactorInstance main, PythonTypes types) { + List instantiatedClasses = new ArrayList<>(); + return generatePythonClass(instance, instantiatedClasses, main, types); + } - for (ReactorInstance child : instance.children) { - pythonClasses.pr(generatePythonClass(child, instantiatedClasses, main, types)); - } - return pythonClasses.getCode(); + /** + * Generate a Python class corresponding to decl + * + * @param instance The reactor instance to be generated + * @param instantiatedClasses A list of visited instances to avoid generating duplicates + */ + public static String generatePythonClass( + ReactorInstance instance, + List instantiatedClasses, + ReactorInstance main, + PythonTypes types) { + CodeBuilder pythonClasses = new CodeBuilder(); + ReactorDecl decl = instance.getDefinition().getReactorClass(); + Reactor reactor = ASTUtils.toDefinition(decl); + String className = PyUtil.getName(instance.tpr); + if (instantiatedClasses == null) { + return ""; } - private static String generatePythonClassHeader(String className) { - return String.join("\n", - "# Python class for reactor "+className+"", - "class _"+className+":" - ); + if (!instantiatedClasses.contains(className)) { + pythonClasses.pr(generatePythonClassHeader(className)); + // Generate preamble code + pythonClasses.indent(); + pythonClasses.pr(PythonPreambleGenerator.generatePythonPreambles(reactor.getPreambles())); + // Handle runtime initializations + pythonClasses.pr(generatePythonConstructor(decl, types)); + pythonClasses.pr(PythonParameterGenerator.generatePythonGetters(decl)); + // Generate methods + pythonClasses.pr(PythonMethodGenerator.generateMethods(reactor)); + // Generate reactions + List reactionToGenerate = ASTUtils.allReactions(reactor); + pythonClasses.pr( + PythonReactionGenerator.generatePythonReactions(reactor, reactionToGenerate)); + pythonClasses.unindent(); + pythonClasses.pr("\n"); + instantiatedClasses.add(className); } - /** - * Generate code that instantiates and initializes parameters and state variables for a reactor 'decl'. - * - * @param decl The reactor declaration - * @return The generated code as a StringBuilder - */ - private static String generatePythonConstructor(ReactorDecl decl, PythonTypes types) { - CodeBuilder code = new CodeBuilder(); - code.pr("# Constructor"); - code.pr("def __init__(self, **kwargs):"); - code.indent(); - code.pr(PythonParameterGenerator.generatePythonInstantiations(decl, types)); - code.pr(PythonStateGenerator.generatePythonInstantiations(decl)); - return code.toString(); + for (ReactorInstance child : instance.children) { + pythonClasses.pr(generatePythonClass(child, instantiatedClasses, main, types)); } + return pythonClasses.getCode(); + } - /** - * Generate code to instantiate a Python list that will hold the Python - * class instance of reactor instance. Will recursively do - * the same for the children of instance as well. - * - * @param instance The reactor instance for which the Python list will be created. - */ - public static String generateListsToHoldClassInstances(ReactorInstance instance) { - CodeBuilder code = new CodeBuilder(); - code.pr(PyUtil.reactorRefName(instance)+" = [None] * "+instance.getTotalWidth()); - for (ReactorInstance child : instance.children) { - code.pr(generateListsToHoldClassInstances(child)); - } - return code.toString(); + private static String generatePythonClassHeader(String className) { + return String.join( + "\n", "# Python class for reactor " + className + "", "class _" + className + ":"); + } + + /** + * Generate code that instantiates and initializes parameters and state variables for a reactor + * 'decl'. + * + * @param decl The reactor declaration + * @return The generated code as a StringBuilder + */ + private static String generatePythonConstructor(ReactorDecl decl, PythonTypes types) { + CodeBuilder code = new CodeBuilder(); + code.pr("# Constructor"); + code.pr("def __init__(self, **kwargs):"); + code.indent(); + code.pr(PythonParameterGenerator.generatePythonInstantiations(decl, types)); + code.pr(PythonStateGenerator.generatePythonInstantiations(decl)); + return code.toString(); + } + + /** + * Generate code to instantiate a Python list that will hold the Python + * class instance of reactor instance. Will recursively do + * the same for the children of instance as well. + * + * @param instance The reactor instance for which the Python list will be created. + */ + public static String generateListsToHoldClassInstances(ReactorInstance instance) { + CodeBuilder code = new CodeBuilder(); + code.pr(PyUtil.reactorRefName(instance) + " = [None] * " + instance.getTotalWidth()); + for (ReactorInstance child : instance.children) { + code.pr(generateListsToHoldClassInstances(child)); } + return code.toString(); + } - /** - * Instantiate classes in Python, as well as subclasses. - * Instances are always instantiated as a list of className = [_className, _className, ...] depending on the size of the bank. - * If there is no bank or the size is 1, the instance would be generated as className = [_className] - * @param instance The reactor instance to be instantiated - * @param main The main reactor - */ - public static String generatePythonClassInstantiations(ReactorInstance instance, - ReactorInstance main) { - CodeBuilder code = new CodeBuilder(); + /** + * Instantiate classes in Python, as well as subclasses. Instances are always instantiated as a + * list of className = [_className, _className, ...] depending on the size of the bank. If there + * is no bank or the size is 1, the instance would be generated as className = [_className] + * + * @param instance The reactor instance to be instantiated + * @param main The main reactor + */ + public static String generatePythonClassInstantiations( + ReactorInstance instance, ReactorInstance main) { + CodeBuilder code = new CodeBuilder(); - String className = PyUtil.getName(instance.tpr); + String className = PyUtil.getName(instance.tpr); - if (instance.getWidth() > 0) { - // For each reactor instance, create a list regardless of whether it is a bank or not. - // Non-bank reactor instances will be a list of size 1. - String fullName = instance.getFullName(); - code.pr(String.join("\n", - "# Start initializing "+fullName+" of class "+className, - "for "+PyUtil.bankIndexName(instance)+" in range("+instance.getWidth()+"):" - )); - code.indent(); - // Define a bank_index local variable so that it can be used while - // setting parameter values. - code.pr("bank_index = "+PyUtil.bankIndexName(instance)); - code.pr(generatePythonClassInstantiation(instance, className)); - } + if (instance.getWidth() > 0) { + // For each reactor instance, create a list regardless of whether it is a bank or not. + // Non-bank reactor instances will be a list of size 1. + String fullName = instance.getFullName(); + code.pr( + String.join( + "\n", + "# Start initializing " + fullName + " of class " + className, + "for " + PyUtil.bankIndexName(instance) + " in range(" + instance.getWidth() + "):")); + code.indent(); + // Define a bank_index local variable so that it can be used while + // setting parameter values. + code.pr("bank_index = " + PyUtil.bankIndexName(instance)); + code.pr(generatePythonClassInstantiation(instance, className)); + } - for (ReactorInstance child : instance.children) { - code.pr(generatePythonClassInstantiations(child, main)); - } - code.unindent(); - return code.toString(); + for (ReactorInstance child : instance.children) { + code.pr(generatePythonClassInstantiations(child, main)); } + code.unindent(); + return code.toString(); + } - /** - * Instantiate a class with className in instance. - * @param instance The reactor instance to be instantiated - * @param className The name of the class to instantiate - */ - private static String generatePythonClassInstantiation(ReactorInstance instance, - String className) { - CodeBuilder code = new CodeBuilder(); - code.pr(PyUtil.reactorRef(instance)+" = _"+className+"("); - code.indent(); - // Always add the bank_index - code.pr("_bank_index = "+PyUtil.bankIndex(instance)+","); - for (ParameterInstance param : instance.parameters) { - if (!param.getName().equals("bank_index")) { - code.pr("_"+param.getName()+"="+ PythonParameterGenerator.generatePythonInitializer(param)+","); - } - } - code.unindent(); - code.pr(")"); - return code.toString(); + /** + * Instantiate a class with className in instance. + * + * @param instance The reactor instance to be instantiated + * @param className The name of the class to instantiate + */ + private static String generatePythonClassInstantiation( + ReactorInstance instance, String className) { + CodeBuilder code = new CodeBuilder(); + code.pr(PyUtil.reactorRef(instance) + " = _" + className + "("); + code.indent(); + // Always add the bank_index + code.pr("_bank_index = " + PyUtil.bankIndex(instance) + ","); + for (ParameterInstance param : instance.parameters) { + if (!param.getName().equals("bank_index")) { + code.pr( + "_" + + param.getName() + + "=" + + PythonParameterGenerator.generatePythonInitializer(param) + + ","); + } } + code.unindent(); + code.pr(")"); + return code.toString(); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java index e318a8812c..45dc8cf7d5 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java @@ -2,36 +2,38 @@ import java.util.ArrayList; import java.util.List; - import org.lflang.ast.ASTUtils; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; public class PythonStateGenerator { - /** - * Generate state variable instantiations for reactor "decl" - * @param decl The reactor declaration to generate state variables. - */ - public static String generatePythonInstantiations(ReactorDecl decl) { - List lines = new ArrayList<>(); - lines.add("# Define state variables"); - // Next, handle state variables - for (StateVar state : ASTUtils.allStateVars(ASTUtils.toDefinition(decl))) { - lines.add("self."+state.getName()+" = "+generatePythonInitializer(state)); - } - lines.add(""); - return String.join("\n", lines); + /** + * Generate state variable instantiations for reactor "decl" + * + * @param decl The reactor declaration to generate state variables. + */ + public static String generatePythonInstantiations(ReactorDecl decl) { + List lines = new ArrayList<>(); + lines.add("# Define state variables"); + // Next, handle state variables + for (StateVar state : ASTUtils.allStateVars(ASTUtils.toDefinition(decl))) { + lines.add("self." + state.getName() + " = " + generatePythonInitializer(state)); } + lines.add(""); + return String.join("\n", lines); + } - /** - * Handle initialization for state variable - * @param state a state variable - */ - public static String generatePythonInitializer(StateVar state) { - if (!ASTUtils.isInitialized(state)) { - return "None"; - } - List list = state.getInit().getExprs().stream().map(PyUtil::getPythonTargetValue).toList(); - return list.size() > 1 ? "[" + String.join(", ", list) + "]" : list.get(0); + /** + * Handle initialization for state variable + * + * @param state a state variable + */ + public static String generatePythonInitializer(StateVar state) { + if (!ASTUtils.isInitialized(state)) { + return "None"; } + List list = + state.getInit().getExprs().stream().map(PyUtil::getPythonTargetValue).toList(); + return list.size() > 1 ? "[" + String.join(", ", list) + "]" : list.get(0); + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonTypes.java b/org.lflang/src/org/lflang/generator/python/PythonTypes.java index 5b62ee5f97..66abfabf5f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonTypes.java +++ b/org.lflang/src/org/lflang/generator/python/PythonTypes.java @@ -3,74 +3,74 @@ import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; - import org.lflang.InferredType; import org.lflang.generator.ReactorInstance; import org.lflang.generator.c.CTypes; -import org.lflang.generator.c.CUtil; import org.lflang.lf.ParameterReference; public class PythonTypes extends CTypes { - // Regular expression pattern for pointer types. The star at the end has to be visible. - static final Pattern pointerPatternVariable = Pattern.compile("^\\s*+(\\w+)\\s*\\*\\s*$"); - private static final PythonTypes INSTANCE = new PythonTypes(); + // Regular expression pattern for pointer types. The star at the end has to be visible. + static final Pattern pointerPatternVariable = Pattern.compile("^\\s*+(\\w+)\\s*\\*\\s*$"); + private static final PythonTypes INSTANCE = new PythonTypes(); - @Override - public String getTargetUndefinedType() { - return "PyObject*"; - } + @Override + public String getTargetUndefinedType() { + return "PyObject*"; + } - /** - * This generator inherits types from the CGenerator. - * This function reverts them back to Python types - * For example, the types double is converted to float, - * the * for pointer types is removed, etc. - * @param type The type - * @return The Python equivalent of a C type - */ - public String getPythonType(InferredType type) { - var result = super.getTargetType(type); + /** + * This generator inherits types from the CGenerator. This function reverts them back to Python + * types For example, the types double is converted to float, the * for pointer types is removed, + * etc. + * + * @param type The type + * @return The Python equivalent of a C type + */ + public String getPythonType(InferredType type) { + var result = super.getTargetType(type); - result = switch (result) { - case "double" -> "float"; - case "string" -> "object"; - default -> result; + result = + switch (result) { + case "double" -> "float"; + case "string" -> "object"; + default -> result; }; - var matcher = pointerPatternVariable.matcher(result); - if (matcher.find()) { - return matcher.group(1); - } - - return result; + var matcher = pointerPatternVariable.matcher(result); + if (matcher.find()) { + return matcher.group(1); } - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return "self." + expr.getParameter().getName(); - } + return result; + } - @Override - public String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); - } + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return "self." + expr.getParameter().getName(); + } - @Override - public String getVariableSizeListInitExpression(List contents, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); - } + @Override + public String getFixedSizeListInitExpression( + List contents, int listSize, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); + } - public static PythonTypes getInstance() { - return INSTANCE; - } + @Override + public String getVariableSizeListInitExpression(List contents, boolean withBraces) { + return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); + } - public static PythonTypes generateParametersIn(ReactorInstance instance) { - return new PythonTypes() { - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return PyUtil.reactorRef(instance) + "." + expr.getParameter().getName(); - } - }; - } + public static PythonTypes getInstance() { + return INSTANCE; + } + + public static PythonTypes generateParametersIn(ReactorInstance instance) { + return new PythonTypes() { + @Override + public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { + return PyUtil.reactorRef(instance) + "." + expr.getParameter().getName(); + } + }; + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonValidator.java b/org.lflang/src/org/lflang/generator/python/PythonValidator.java index 989d4181fc..dc87417c51 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonValidator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonValidator.java @@ -1,5 +1,11 @@ package org.lflang.generator.python; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import java.nio.file.Path; import java.util.Collection; import java.util.List; @@ -8,9 +14,7 @@ import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.lsp4j.DiagnosticSeverity; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.generator.CodeMap; @@ -20,13 +24,6 @@ import org.lflang.generator.ValidationStrategy; import org.lflang.util.LFCommand; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - /** * A validator for generated Python. * @@ -34,317 +31,375 @@ */ 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+)\\)" - ); - - /** The JSON parser. */ - private static final ObjectMapper mapper = new ObjectMapper() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - private final Set protoNames; - - /** - * The message format of Pylint's JSON output. - */ - @SuppressWarnings( {"FieldCanBeLocal", "unused"}) // Unused fields are included for completeness. - private static final class PylintMessage { - private String type; - private String module; - private String obj; - private Integer line; - private Integer column; - private Integer endLine; - private Integer endColumn; - private Path path; - private String symbol; - private String message; - private String messageId; - public void setType(String type) { this.type = type; } - public void setModule(String module) { this.module = module; } - public void setObj(String obj) { this.obj = obj; } - public void setLine(int line) { this.line = line; } - public void setColumn(int column) { this.column = column; } - public void setEndLine(int endLine) { this.endLine = endLine; } - public void setEndColumn(int endColumn) { this.endColumn = endColumn; } - public void setPath(String path) { this.path = Path.of(path); } - public void setSymbol(String symbol) { this.symbol = symbol; } - public void setMessage(String message) { this.message = message; } - @JsonProperty("message-id") - public void setMessageId(String messageId) { this.messageId = messageId; } - public Position getStart() { - if (line != null && column != null) return Position.fromZeroBased(line - 1, column); - // Use 0 as fallback for the column. This will cause bugs by taking some positions out of the line - // adjuster's range. - if (line != null) return Position.fromZeroBased(line - 1, 0); - // This fallback will always fail with the line adjuster, but at least the program will not crash. - return Position.ORIGIN; - } - public Position getEnd() { - return endLine == null || endColumn == null ? getStart().plus(" ") : - Position.fromZeroBased(endLine - 1, endColumn); - } - public Path getPath(Path relativeTo) { return relativeTo.resolve(path); } - public DiagnosticSeverity getSeverity() { - // The following is consistent with VS Code's default behavior for pure Python: - // https://code.visualstudio.com/docs/python/linting#_pylint - switch (type.toLowerCase()) { - case "refactor": - return DiagnosticSeverity.Hint; - case "warning": - return DiagnosticSeverity.Warning; - case "error": - case "fatal": - return DiagnosticSeverity.Error; - case "convention": - default: - return DiagnosticSeverity.Information; - } - } + /** 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+)\\)"); + + /** The JSON parser. */ + private static final ObjectMapper mapper = + new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + private final Set protoNames; + + /** The message format of Pylint's JSON output. */ + @SuppressWarnings({"FieldCanBeLocal", "unused"}) // Unused fields are included for completeness. + private static final class PylintMessage { + private String type; + private String module; + private String obj; + private Integer line; + private Integer column; + private Integer endLine; + private Integer endColumn; + private Path path; + private String symbol; + private String message; + private String messageId; + + public void setType(String type) { + this.type = type; } - private static final Pattern PylintNoNamePattern = Pattern.compile("Instance of '(?\\w+)' has no .*"); - - private final FileConfig fileConfig; - private final ErrorReporter errorReporter; - private final ImmutableMap codeMaps; - - /** - * Initialize a {@code PythonValidator} for a build process using {@code fileConfig} and - * report errors to {@code errorReporter}. - * @param fileConfig The file configuration of this build. - * @param errorReporter The reporter to which diagnostics should be sent. - * @param codeMaps A mapping from generated file paths to code maps that map them back to - * LF sources. - * @param protoNames The names of any protocol buffer message types that are used in the LF - * program being built. - */ - public PythonValidator( - FileConfig fileConfig, - ErrorReporter errorReporter, - Map codeMaps, - Set protoNames - ) { - super(errorReporter, codeMaps); - this.fileConfig = fileConfig; - this.errorReporter = errorReporter; - this.codeMaps = ImmutableMap.copyOf(codeMaps); - this.protoNames = ImmutableSet.copyOf(protoNames); + public void setModule(String module) { + this.module = module; } - @Override - protected Collection getPossibleStrategies() { return List.of( + public void setObj(String obj) { + this.obj = obj; + } + + public void setLine(int line) { + this.line = line; + } + + public void setColumn(int column) { + this.column = column; + } + + public void setEndLine(int endLine) { + this.endLine = endLine; + } + + public void setEndColumn(int endColumn) { + this.endColumn = endColumn; + } + + public void setPath(String path) { + this.path = Path.of(path); + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public void setMessage(String message) { + this.message = message; + } + + @JsonProperty("message-id") + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public Position getStart() { + if (line != null && column != null) return Position.fromZeroBased(line - 1, column); + // Use 0 as fallback for the column. This will cause bugs by taking some positions out of the + // line + // adjuster's range. + if (line != null) return Position.fromZeroBased(line - 1, 0); + // This fallback will always fail with the line adjuster, but at least the program will not + // crash. + return Position.ORIGIN; + } + + public Position getEnd() { + return endLine == null || endColumn == null + ? getStart().plus(" ") + : Position.fromZeroBased(endLine - 1, endColumn); + } + + public Path getPath(Path relativeTo) { + return relativeTo.resolve(path); + } + + public DiagnosticSeverity getSeverity() { + // The following is consistent with VS Code's default behavior for pure Python: + // https://code.visualstudio.com/docs/python/linting#_pylint + switch (type.toLowerCase()) { + case "refactor": + return DiagnosticSeverity.Hint; + case "warning": + return DiagnosticSeverity.Warning; + case "error": + case "fatal": + return DiagnosticSeverity.Error; + case "convention": + default: + return DiagnosticSeverity.Information; + } + } + } + + private static final Pattern PylintNoNamePattern = + Pattern.compile("Instance of '(?\\w+)' has no .*"); + + private final FileConfig fileConfig; + private final ErrorReporter errorReporter; + private final ImmutableMap codeMaps; + + /** + * Initialize a {@code PythonValidator} for a build process using {@code fileConfig} and report + * errors to {@code errorReporter}. + * + * @param fileConfig The file configuration of this build. + * @param errorReporter The reporter to which diagnostics should be sent. + * @param codeMaps A mapping from generated file paths to code maps that map them back to LF + * sources. + * @param protoNames The names of any protocol buffer message types that are used in the LF + * program being built. + */ + public PythonValidator( + FileConfig fileConfig, + ErrorReporter errorReporter, + Map codeMaps, + Set protoNames) { + super(errorReporter, codeMaps); + this.fileConfig = fileConfig; + this.errorReporter = errorReporter; + this.codeMaps = ImmutableMap.copyOf(codeMaps); + this.protoNames = ImmutableSet.copyOf(protoNames); + } + + @Override + protected Collection getPossibleStrategies() { + return List.of( new ValidationStrategy() { - @Override - public LFCommand getCommand(Path generatedFile) { - return LFCommand.get( - "python3", - List.of("-c", "import compileall; compileall.compile_dir('.', quiet=1)"), - true, - fileConfig.getSrcGenPkgPath() - ); - } + @Override + public LFCommand getCommand(Path generatedFile) { + return LFCommand.get( + "python3", + List.of("-c", "import compileall; compileall.compile_dir('.', quiet=1)"), + true, + fileConfig.getSrcGenPkgPath()); + } - @Override - public Strategy getErrorReportingStrategy() { - return (a, b, c) -> {}; - } + @Override + public Strategy getErrorReportingStrategy() { + return (a, b, c) -> {}; + } - @Override - public Strategy getOutputReportingStrategy() { - return (String validationOutput, ErrorReporter errorReporter, Map map) -> { - String[] lines = (validationOutput + "\n\n\n").lines().toArray(String[]::new); - for (int i = 0; i < lines.length - 3; i++) { - if (!tryReportTypical(lines, i)) { - tryReportAlternative(lines, i); - } - } - }; - } + @Override + public Strategy getOutputReportingStrategy() { + return (String validationOutput, + ErrorReporter errorReporter, + Map map) -> { + String[] lines = (validationOutput + "\n\n\n").lines().toArray(String[]::new); + for (int i = 0; i < lines.length - 3; i++) { + if (!tryReportTypical(lines, i)) { + tryReportAlternative(lines, i); + } + } + }; + } - /** - * Try to report a typical error message from the Python compiler. - * - * @param lines The lines of output from the compiler. - * @param i The current index at which a message may start. Guaranteed to be less - * than - * {@code lines.length - 3}. - * @return Whether an error message was reported. - */ - private boolean tryReportTypical(String[] lines, int i) { - Matcher main = DIAGNOSTIC_MESSAGE_PATTERN.matcher(lines[i]); - Matcher messageMatcher = MESSAGE.matcher(lines[i + 3]); - String message = messageMatcher.matches() ? messageMatcher.group() : "Syntax Error"; - if (main.matches()) { - int line = Integer.parseInt(main.group("line")); - CodeMap map = codeMaps.get(fileConfig.getSrcGenPkgPath().resolve(Path.of(main.group("path"))).normalize()); - Position genPosition = Position.fromOneBased(line, Integer.MAX_VALUE); // Column is just a placeholder. - if (map == null) { - errorReporter.report(null, DiagnosticSeverity.Error, message, 1); // Undesirable fallback - } else { - for (Path lfFile : map.lfSourcePaths()) { - Position lfPosition = map.adjusted(lfFile, genPosition); - // TODO: We could be more precise than just getting the right line, but the way the output - // is formatted (with leading whitespace possibly trimmed) does not make it easy. - errorReporter.report(lfFile, DiagnosticSeverity.Error, message, lfPosition.getOneBasedLine()); - } - } - return true; + /** + * Try to report a typical error message from the Python compiler. + * + * @param lines The lines of output from the compiler. + * @param i The current index at which a message may start. Guaranteed to be less than + * {@code lines.length - 3}. + * @return Whether an error message was reported. + */ + private boolean tryReportTypical(String[] lines, int i) { + Matcher main = DIAGNOSTIC_MESSAGE_PATTERN.matcher(lines[i]); + Matcher messageMatcher = MESSAGE.matcher(lines[i + 3]); + String message = messageMatcher.matches() ? messageMatcher.group() : "Syntax Error"; + if (main.matches()) { + int line = Integer.parseInt(main.group("line")); + CodeMap map = + codeMaps.get( + fileConfig + .getSrcGenPkgPath() + .resolve(Path.of(main.group("path"))) + .normalize()); + Position genPosition = + Position.fromOneBased(line, Integer.MAX_VALUE); // Column is just a placeholder. + if (map == null) { + errorReporter.report( + null, DiagnosticSeverity.Error, message, 1); // Undesirable fallback + } else { + for (Path lfFile : map.lfSourcePaths()) { + Position lfPosition = map.adjusted(lfFile, genPosition); + // TODO: We could be more precise than just getting the right line, but the way + // the output + // is formatted (with leading whitespace possibly trimmed) does not make it easy. + errorReporter.report( + lfFile, DiagnosticSeverity.Error, message, lfPosition.getOneBasedLine()); } - return false; + } + return true; } + return false; + } - /** - * Try to report an alternative error message from the Python compiler. - * - * @param lines The lines of output from the compiler. - * @param i The current index at which a message may start. - */ - private void tryReportAlternative(String[] lines, int i) { - Matcher main = ALT_DIAGNOSTIC_MESSAGE_PATTERN.matcher(lines[i]); - if (main.matches()) { - int line = Integer.parseInt(main.group("line")); - Iterable relevantMaps = codeMaps.keySet().stream() - .filter(p -> main.group().contains(p.getFileName().toString())) - .map(codeMaps::get)::iterator; - for (CodeMap map : relevantMaps) { // There should almost always be exactly one of these - for (Path lfFile : map.lfSourcePaths()) { - errorReporter.report( - lfFile, - DiagnosticSeverity.Error, - main.group().replace("*** ", "").replace("Sorry: ", ""), - map.adjusted(lfFile, Position.fromOneBased(line, 1)).getOneBasedLine() - ); - } - } + /** + * Try to report an alternative error message from the Python compiler. + * + * @param lines The lines of output from the compiler. + * @param i The current index at which a message may start. + */ + private void tryReportAlternative(String[] lines, int i) { + Matcher main = ALT_DIAGNOSTIC_MESSAGE_PATTERN.matcher(lines[i]); + if (main.matches()) { + int line = Integer.parseInt(main.group("line")); + Iterable relevantMaps = + codeMaps.keySet().stream() + .filter(p -> main.group().contains(p.getFileName().toString())) + .map(codeMaps::get) + ::iterator; + for (CodeMap map : + relevantMaps) { // There should almost always be exactly one of these + for (Path lfFile : map.lfSourcePaths()) { + errorReporter.report( + lfFile, + DiagnosticSeverity.Error, + main.group().replace("*** ", "").replace("Sorry: ", ""), + map.adjusted(lfFile, Position.fromOneBased(line, 1)).getOneBasedLine()); } + } } + } - @Override - public boolean isFullBatch() { - return true; - } + @Override + public boolean isFullBatch() { + return true; + } - @Override - public int getPriority() { - return 0; - } + @Override + public int getPriority() { + return 0; + } }, new ValidationStrategy() { - @Override - public LFCommand getCommand(Path generatedFile) { - return LFCommand.get( - "pylint", - List.of("--output-format=json", generatedFile.getFileName().toString()), - true, - fileConfig.getSrcGenPath() - ); - } + @Override + public LFCommand getCommand(Path generatedFile) { + return LFCommand.get( + "pylint", + List.of("--output-format=json", generatedFile.getFileName().toString()), + true, + fileConfig.getSrcGenPath()); + } - @Override - public Strategy getErrorReportingStrategy() { - return (a, b, c) -> {}; - } + @Override + public Strategy getErrorReportingStrategy() { + return (a, b, c) -> {}; + } - @Override - public Strategy getOutputReportingStrategy() { - return (validationOutput, errorReporter, codeMaps) -> { - if (validationOutput.isBlank()) return; - try { - for (PylintMessage message : mapper.readValue(validationOutput, PylintMessage[].class)) { - if (shouldIgnore(message)) continue; - CodeMap map = codeMaps.get(message.getPath(fileConfig.getSrcGenPath())); - if (map != null) { - for (Path lfFile : map.lfSourcePaths()) { - Function adjust = p -> map.adjusted(lfFile, p); - String humanMessage = DiagnosticReporting.messageOf( - message.message, - message.getPath(fileConfig.getSrcGenPath()), - message.getStart() - ); - Position lfStart = adjust.apply(message.getStart()); - Position lfEnd = adjust.apply(message.getEnd()); - bestEffortReport( - errorReporter, - adjust, - lfStart, - lfEnd, - lfFile, - message.getSeverity(), - humanMessage - ); - } - } - } - } catch (JsonProcessingException e) { - System.err.printf("Failed to parse \"%s\":%n", validationOutput); - e.printStackTrace(); - errorReporter.reportWarning( - "Failed to parse linter output. The Lingua Franca code generator is tested with Pylint " - + "version 2.12.2. Consider updating Pylint if you have an older version." - ); + @Override + public Strategy getOutputReportingStrategy() { + return (validationOutput, errorReporter, codeMaps) -> { + if (validationOutput.isBlank()) return; + try { + for (PylintMessage message : + mapper.readValue(validationOutput, PylintMessage[].class)) { + if (shouldIgnore(message)) continue; + CodeMap map = codeMaps.get(message.getPath(fileConfig.getSrcGenPath())); + if (map != null) { + for (Path lfFile : map.lfSourcePaths()) { + Function adjust = p -> map.adjusted(lfFile, p); + String humanMessage = + DiagnosticReporting.messageOf( + message.message, + message.getPath(fileConfig.getSrcGenPath()), + message.getStart()); + Position lfStart = adjust.apply(message.getStart()); + Position lfEnd = adjust.apply(message.getEnd()); + bestEffortReport( + errorReporter, + adjust, + lfStart, + lfEnd, + lfFile, + message.getSeverity(), + humanMessage); } - }; - } + } + } + } catch (JsonProcessingException e) { + System.err.printf("Failed to parse \"%s\":%n", validationOutput); + e.printStackTrace(); + errorReporter.reportWarning( + "Failed to parse linter output. The Lingua Franca code generator is tested with" + + " Pylint version 2.12.2. Consider updating Pylint if you have an older" + + " version."); + } + }; + } - /** - * Return whether the given message should be ignored. - * @param message A Pylint message that is a candidate to be reported. - * @return whether {@code message} should be reported. - */ - private boolean shouldIgnore(PylintMessage message) { - // Code generation does not preserve whitespace, so this check is unreliable. - if (message.symbol.equals("trailing-whitespace") || message.symbol.equals("line-too-long")) return true; - // This filters out Pylint messages concerning missing members in types defined by protocol buffers. - // FIXME: Make this unnecessary, perhaps using https://github.com/nelfin/pylint-protobuf. - Matcher matcher = PylintNoNamePattern.matcher(message.message); - return message.symbol.equals("no-member") - && matcher.matches() && protoNames.contains(matcher.group("name")); - } + /** + * Return whether the given message should be ignored. + * + * @param message A Pylint message that is a candidate to be reported. + * @return whether {@code message} should be reported. + */ + private boolean shouldIgnore(PylintMessage message) { + // Code generation does not preserve whitespace, so this check is unreliable. + if (message.symbol.equals("trailing-whitespace") + || message.symbol.equals("line-too-long")) return true; + // This filters out Pylint messages concerning missing members in types defined by + // protocol buffers. + // FIXME: Make this unnecessary, perhaps using + // https://github.com/nelfin/pylint-protobuf. + Matcher matcher = PylintNoNamePattern.matcher(message.message); + return message.symbol.equals("no-member") + && matcher.matches() + && protoNames.contains(matcher.group("name")); + } - /** Make a best-effort attempt to place the diagnostic on the correct line. */ - private void bestEffortReport( - ErrorReporter errorReporter, - Function adjust, - Position lfStart, - Position lfEnd, - Path file, - DiagnosticSeverity severity, - String humanMessage - ) { - if (!lfEnd.equals(Position.ORIGIN) && !lfStart.equals(Position.ORIGIN)) { // Ideal case - errorReporter.report(file, severity, humanMessage, lfStart, lfEnd); - } else { // Fallback: Try to report on the correct line, or failing that, just line 1. - if (lfStart.equals(Position.ORIGIN)) lfStart = adjust.apply( - Position.fromZeroBased(lfStart.getZeroBasedLine(), Integer.MAX_VALUE) - ); - // FIXME: It might be better to improve style of generated code instead of quietly returning here. - if (lfStart.equals(Position.ORIGIN) && severity != DiagnosticSeverity.Error) return; - errorReporter.report(file, severity, humanMessage, lfStart.getOneBasedLine()); - } + /** Make a best-effort attempt to place the diagnostic on the correct line. */ + private void bestEffortReport( + ErrorReporter errorReporter, + Function adjust, + Position lfStart, + Position lfEnd, + Path file, + DiagnosticSeverity severity, + String humanMessage) { + if (!lfEnd.equals(Position.ORIGIN) && !lfStart.equals(Position.ORIGIN)) { // Ideal case + errorReporter.report(file, severity, humanMessage, lfStart, lfEnd); + } else { // Fallback: Try to report on the correct line, or failing that, just line 1. + if (lfStart.equals(Position.ORIGIN)) + lfStart = + adjust.apply( + Position.fromZeroBased(lfStart.getZeroBasedLine(), Integer.MAX_VALUE)); + // FIXME: It might be better to improve style of generated code instead of quietly + // returning here. + if (lfStart.equals(Position.ORIGIN) && severity != DiagnosticSeverity.Error) return; + errorReporter.report(file, severity, humanMessage, lfStart.getOneBasedLine()); } + } - @Override - public boolean isFullBatch() { - return false; - } + @Override + public boolean isFullBatch() { + return false; + } - @Override - public int getPriority() { - return 1; - } - } - ); } + @Override + public int getPriority() { + return 1; + } + }); + } - @Override - protected Pair getBuildReportingStrategies() { - return new Pair<>((a, b, c) -> {}, (a, b, c) -> {}); - } + @Override + protected Pair getBuildReportingStrategies() { + return new Pair<>((a, b, c) -> {}, (a, b, c) -> {}); + } } diff --git a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java index 69efcd3fab..ff97860970 100644 --- a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java +++ b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java @@ -31,9 +31,9 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import org.lflang.ast.ASTUtils; import org.lflang.TargetProperty; import org.lflang.TargetProperty.TargetPropertyType; +import org.lflang.ast.ASTUtils; import org.lflang.generator.InvalidLfSourceException; import org.lflang.lf.Array; import org.lflang.lf.Element; @@ -202,14 +202,12 @@ private static CargoDependencySpec parseValue(Element element, boolean isRuntime pair.getValue(), "Expected string literal for key '" + name + "'"); } switch (name) { - case "version" -> version = literal; - case "git" -> gitRepo = literal; - case "rev" -> rev = literal; - case "tag" -> tag = literal; - case "path" -> localPath = literal; - default -> throw new InvalidLfSourceException(pair, - "Unknown key: '" + name - + "'"); + case "version" -> version = literal; + case "git" -> gitRepo = literal; + case "rev" -> rev = literal; + case "tag" -> tag = literal; + case "path" -> localPath = literal; + default -> throw new InvalidLfSourceException(pair, "Unknown key: '" + name + "'"); } } if (isRuntimeCrate || version != null || localPath != null || gitRepo != null) { diff --git a/org.lflang/src/org/lflang/generator/rust/RustTargetConfig.java b/org.lflang/src/org/lflang/generator/rust/RustTargetConfig.java index f2ff9d9c3f..b4e9a1778b 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustTargetConfig.java +++ b/org.lflang/src/org/lflang/generator/rust/RustTargetConfig.java @@ -29,11 +29,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; - import org.eclipse.emf.ecore.EObject; - import org.lflang.ErrorReporter; import org.lflang.TargetProperty.BuildType; @@ -44,83 +41,66 @@ */ public final class RustTargetConfig { - - /** - * List of Cargo features of the generated crate to enable. - */ - private List cargoFeatures = new ArrayList<>(); - - /** - * Map of Cargo dependency to dependency properties. - */ - private Map cargoDependencies = new HashMap<>(); - - /** - * List of top-level modules, those are absolute paths. - */ - private final List rustTopLevelModules = new ArrayList<>(); - - /** - * Cargo profile, default is debug (corresponds to cargo dev profile). - */ - private BuildType profile = BuildType.DEBUG; - - public void setCargoFeatures(List cargoFeatures) { - this.cargoFeatures = cargoFeatures; - } - - public void setCargoDependencies(Map cargoDependencies) { - this.cargoDependencies = cargoDependencies; + /** List of Cargo features of the generated crate to enable. */ + private List cargoFeatures = new ArrayList<>(); + + /** Map of Cargo dependency to dependency properties. */ + private Map cargoDependencies = new HashMap<>(); + + /** List of top-level modules, those are absolute paths. */ + private final List rustTopLevelModules = new ArrayList<>(); + + /** Cargo profile, default is debug (corresponds to cargo dev profile). */ + private BuildType profile = BuildType.DEBUG; + + public void setCargoFeatures(List cargoFeatures) { + this.cargoFeatures = cargoFeatures; + } + + public void setCargoDependencies(Map cargoDependencies) { + this.cargoDependencies = cargoDependencies; + } + + public void addAndCheckTopLevelModule(Path path, EObject errorOwner, ErrorReporter err) { + String fileName = path.getFileName().toString(); + if (!Files.exists(path)) { + err.reportError(errorOwner, "File not found"); + } else if (Files.isRegularFile(path) && !fileName.endsWith(".rs")) { + err.reportError(errorOwner, "Not a rust file"); + } else if (fileName.equals("main.rs")) { + err.reportError(errorOwner, "Cannot use 'main.rs' as a module name (reserved)"); + } else if (fileName.equals("reactors") || fileName.equals("reactors.rs")) { + err.reportError(errorOwner, "Cannot use 'reactors' as a module name (reserved)"); + } else if (Files.isDirectory(path) && !Files.exists(path.resolve("mod.rs"))) { + err.reportError(errorOwner, "Cannot find module descriptor in directory"); } - - public void addAndCheckTopLevelModule(Path path, EObject errorOwner, ErrorReporter err) { - String fileName = path.getFileName().toString(); - if (!Files.exists(path)) { - err.reportError(errorOwner, "File not found"); - } else if (Files.isRegularFile(path) && !fileName.endsWith(".rs")) { - err.reportError(errorOwner, "Not a rust file"); - } else if (fileName.equals("main.rs")) { - err.reportError(errorOwner, "Cannot use 'main.rs' as a module name (reserved)"); - } else if (fileName.equals("reactors") || fileName.equals("reactors.rs")) { - err.reportError(errorOwner, "Cannot use 'reactors' as a module name (reserved)"); - } else if (Files.isDirectory(path) && !Files.exists(path.resolve("mod.rs"))) { - err.reportError(errorOwner, "Cannot find module descriptor in directory"); - } - this.rustTopLevelModules.add(path); - } - - public List getCargoFeatures() { - return cargoFeatures; - } - - /** - * Returns a map of cargo dependencies. - */ - public Map getCargoDependencies() { - return cargoDependencies; - } - - /** - * Returns the list of top-level module files to include in main.rs. - * Those files were checked to exists previously. - */ - public List getRustTopLevelModules() { - return rustTopLevelModules; - } - - /** - * The build type to use. Corresponds to a Cargo profile. - */ - public BuildType getBuildType() { - return profile; - } - - - /** - * Set a build profile chosen based on a cmake profile. - */ - public void setBuildType(BuildType profile) { - this.profile = profile; - } - + this.rustTopLevelModules.add(path); + } + + public List getCargoFeatures() { + return cargoFeatures; + } + + /** Returns a map of cargo dependencies. */ + public Map getCargoDependencies() { + return cargoDependencies; + } + + /** + * Returns the list of top-level module files to include in main.rs. Those files were checked to + * exists previously. + */ + public List getRustTopLevelModules() { + return rustTopLevelModules; + } + + /** The build type to use. Corresponds to a Cargo profile. */ + public BuildType getBuildType() { + return profile; + } + + /** Set a build profile chosen based on a cmake profile. */ + public void setBuildType(BuildType profile) { + this.profile = profile; + } } diff --git a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java index cf89596a56..1e88ba4c12 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java +++ b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java @@ -10,20 +10,19 @@ */ public class TSDockerGenerator extends DockerGenerator { - /** Construct a new Docker generator. */ - public TSDockerGenerator(LFGeneratorContext context) { - super(context); - } + /** Construct a new Docker generator. */ + public TSDockerGenerator(LFGeneratorContext context) { + super(context); + } - /** - * Return the content of the docker file for [tsFileName]. - */ - public String generateDockerFileContent() { - return """ + /** Return the content of the docker file for [tsFileName]. */ + public String generateDockerFileContent() { + return """ |FROM node:alpine |WORKDIR /linguafranca/$name |COPY . . |ENTRYPOINT ["node", "dist/%s.js"] - """.formatted(context.getFileConfig().name); - } + """ + .formatted(context.getFileConfig().name); + } } diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.java b/org.lflang/src/org/lflang/generator/ts/TSTypes.java index 2e2c6a6dff..0fe4fc8a5e 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSTypes.java +++ b/org.lflang/src/org/lflang/generator/ts/TSTypes.java @@ -1,75 +1,73 @@ package org.lflang.generator.ts; import java.util.List; - -import org.lflang.ast.ASTUtils; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.generator.TargetTypes; import org.lflang.generator.UnsupportedGeneratorFeatureException; import org.lflang.lf.StateVar; public class TSTypes implements TargetTypes { - private static TSTypes INSTANCE = new TSTypes(); - - private TSTypes() { - - } - - @Override - public String getTargetType(StateVar s) { - var type = TargetTypes.super.getTargetType(s); - if (!ASTUtils.isInitialized(s)) { - return "%s | undefined".formatted(type); - } else { - return type; - } - } - - @Override - public boolean supportsGenerics() { - return true; - } - - @Override - public String getTargetTimeType() { - return "TimeValue"; - } - - @Override - public String getTargetTagType() { - return "TimeValue"; - } + private static TSTypes INSTANCE = new TSTypes(); - @Override - public String getTargetUndefinedType() { - return "Present"; - } - - public String getTargetTimeExpr(TimeValue value) { - if (value.unit != null) { - return "TimeValue.%s(%s)".formatted(value.unit.getCanonicalName(), value.time); - } else { - // The value must be zero. - return "TimeValue.zero()"; - } - } + private TSTypes() {} - @Override - public String getTargetFixedSizeListType(String baseType, int size) { - throw new UnsupportedGeneratorFeatureException("TypeScript does not support fixed-size array types."); + @Override + public String getTargetType(StateVar s) { + var type = TargetTypes.super.getTargetType(s); + if (!ASTUtils.isInitialized(s)) { + return "%s | undefined".formatted(type); + } else { + return type; } - - @Override - public String getTargetVariableSizeListType(String baseType) { - return "Array<%s>".formatted(baseType); // same as "$baseType[]" - } - - public String getVariableSizeListInitExpression(List contents, boolean withBraces) { - return "[" + String.join(", ", contents) + "]"; - } - - public static TSTypes getInstance() { - return INSTANCE; + } + + @Override + public boolean supportsGenerics() { + return true; + } + + @Override + public String getTargetTimeType() { + return "TimeValue"; + } + + @Override + public String getTargetTagType() { + return "TimeValue"; + } + + @Override + public String getTargetUndefinedType() { + return "Present"; + } + + public String getTargetTimeExpr(TimeValue value) { + if (value.unit != null) { + return "TimeValue.%s(%s)".formatted(value.unit.getCanonicalName(), value.time); + } else { + // The value must be zero. + return "TimeValue.zero()"; } + } + + @Override + public String getTargetFixedSizeListType(String baseType, int size) { + throw new UnsupportedGeneratorFeatureException( + "TypeScript does not support fixed-size array types."); + } + + @Override + public String getTargetVariableSizeListType(String baseType) { + return "Array<%s>".formatted(baseType); // same as "$baseType[]" + } + + public String getVariableSizeListInitExpression(List contents, boolean withBraces) { + return "[" + String.join(", ", contents) + "]"; + } + + public static TSTypes getInstance() { + return INSTANCE; + } } diff --git a/org.lflang/src/org/lflang/graph/DirectedGraph.java b/org.lflang/src/org/lflang/graph/DirectedGraph.java index 771bbca539..0e506dbe30 100644 --- a/org.lflang/src/org/lflang/graph/DirectedGraph.java +++ b/org.lflang/src/org/lflang/graph/DirectedGraph.java @@ -1,25 +1,25 @@ /************* - Copyright (c) 2019, The University of California at Berkeley. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.graph; @@ -27,7 +27,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; - import org.lflang.util.CollectionUtil; /** @@ -38,287 +37,254 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */ public class DirectedGraph implements Graph { - // Note that while both those maps are mutable, the sets - // they use as values may not be. They should only be - // manipulated through CollectionUtil - - // If a node has no neighbors, it is still in the map with an empty set as a value. - - /** - * Adjacency map from vertices to their downstream immediate neighbors. - */ - private final Map> downstreamAdjacentNodes = new LinkedHashMap<>(); - - /** - * Adjacency map from vertices to their upstream immediate neighbors. - */ - private final Map> upstreamAdjacentNodes = new LinkedHashMap<>(); - - - /** - * Mark the graph to have changed so that any cached analysis is refreshed - * accordingly. - */ - protected void graphChanged() { - // To be overridden by subclasses that perform analysis. - } - - - /** - * Return true if this graph has the given node in it. - * - * @param node The node to look for. - */ - @Override - public boolean hasNode(T node) { - return nodes().contains(node); - } - - - /** - * Return all immediate upstream neighbors of a given node. - * - * @param node The node to report the immediate upstream neighbors of. - */ - public Set getUpstreamAdjacentNodes(T node) { - return Collections.unmodifiableSet(this.upstreamAdjacentNodes.getOrDefault(node, Set.of())); - } - - - /** - * Return all immediate downstream neighbors of a given node. - * - * @param node The node to report the immediate downstream neighbors of. - */ - public Set getDownstreamAdjacentNodes(T node) { - return Collections.unmodifiableSet(this.downstreamAdjacentNodes.getOrDefault(node, Set.of())); - } - - - @Override - public void addNode(T node) { - this.graphChanged(); - this.upstreamAdjacentNodes.putIfAbsent(node, Set.of()); - this.downstreamAdjacentNodes.putIfAbsent(node, Set.of()); - } - - - @Override - public void removeNode(T node) { - this.graphChanged(); - this.upstreamAdjacentNodes.remove(node); - this.downstreamAdjacentNodes.remove(node); - // The node also needs to be removed from the sets that represent connections to the node. - CollectionUtil.removeFromValues(this.upstreamAdjacentNodes, node); - CollectionUtil.removeFromValues(this.downstreamAdjacentNodes, node); - } - - - /** - * Add a new directed edge to the graph. The first argument is - * the downstream node, the second argument the upstream node. - * If either argument is null, do nothing. - * - * @param sink The downstream immediate neighbor. - * @param source The upstream immediate neighbor. - */ - @Override - public void addEdge(T sink, T source) { - this.graphChanged(); - if (sink != null && source != null) { - this.downstreamAdjacentNodes.compute(source, (k, set) -> CollectionUtil.plus(set, sink)); - this.upstreamAdjacentNodes.compute(sink, (k, set) -> CollectionUtil.plus(set, source)); - } - } - - - /** - * Add new directed edges to the graph. The first argument is the - * downstream node, the second argument a set of upstream nodes. - * - * @param sink The downstream immediate neighbor. - * @param sources The upstream immediate neighbors. - */ - @Override - public void addEdges(T sink, List sources) { - for (T source : sources) { - this.addEdge(sink, source); - } - } - - - /** - * Remove a directed edge from the graph. - * - * @param sink The downstream immediate neighbor. - * @param source The upstream immediate neighbor. - */ - @Override - public void removeEdge(T sink, T source) { - this.graphChanged(); - this.upstreamAdjacentNodes.computeIfPresent(sink, (k, upstream) -> CollectionUtil.minus(upstream, source)); - this.downstreamAdjacentNodes.computeIfPresent(source, (k, downstream) -> CollectionUtil.minus(downstream, sink)); - } - - - /** - * Obtain a copy of this graph by creating an new instance and copying - * the adjacency maps. - */ - public DirectedGraph copy() { - var graph = new DirectedGraph(); - for (var entry : this.upstreamAdjacentNodes.entrySet()) { - graph.upstreamAdjacentNodes.put(entry.getKey(), CollectionUtil.copy(entry.getValue())); - } - for (var entry : this.downstreamAdjacentNodes.entrySet()) { - graph.downstreamAdjacentNodes.put(entry.getKey(), CollectionUtil.copy(entry.getValue())); - } - return graph; - } - - - /** - * For a given a two adjacency maps, copy missing edges from the first - * map to the second. - * - * @param srcMap The adjacency map to copy edges from. - * @param dstMap The adjacency map to copy edges to. - */ - private void mirror(Map> srcMap, Map> dstMap) { - if (srcMap != null && dstMap != null) { - for (Entry> entry : srcMap.entrySet()) { - var node = entry.getKey(); - var srcEdges = entry.getValue(); - dstMap.compute(node, (_node, dstEdges) -> { - // Node does not exist; add it. - if (dstEdges == null) { - return CollectionUtil.copy(srcEdges); - } - - // Node does exist; add the missing edges. - var set = dstEdges; - for (T edge : srcEdges) { - set = CollectionUtil.plus(set, edge); - } - return set; - }); - } - } - } - - - /** - * Merge another directed graph into this one. - * - * @param another The graph to merge into this one. - */ - public void merge(DirectedGraph another) { - this.graphChanged(); - mirror(another.upstreamAdjacentNodes, this.upstreamAdjacentNodes); - mirror(another.downstreamAdjacentNodes, this.downstreamAdjacentNodes); - } - - - /** - * Return the set of nodes that have no neighbors listed in the given - * adjacency map. - */ - private Set independentNodes(Map> adjacencyMap) { - var independent = new LinkedHashSet(); - for (T node : nodes()) { - var neighbors = adjacencyMap.get(node); - if (neighbors == null || neighbors.size() == 0) { - independent.add(node); - } - } - return independent; + // Note that while both those maps are mutable, the sets + // they use as values may not be. They should only be + // manipulated through CollectionUtil + + // If a node has no neighbors, it is still in the map with an empty set as a value. + + /** Adjacency map from vertices to their downstream immediate neighbors. */ + private final Map> downstreamAdjacentNodes = new LinkedHashMap<>(); + + /** Adjacency map from vertices to their upstream immediate neighbors. */ + private final Map> upstreamAdjacentNodes = new LinkedHashMap<>(); + + /** Mark the graph to have changed so that any cached analysis is refreshed accordingly. */ + protected void graphChanged() { + // To be overridden by subclasses that perform analysis. + } + + /** + * Return true if this graph has the given node in it. + * + * @param node The node to look for. + */ + @Override + public boolean hasNode(T node) { + return nodes().contains(node); + } + + /** + * Return all immediate upstream neighbors of a given node. + * + * @param node The node to report the immediate upstream neighbors of. + */ + public Set getUpstreamAdjacentNodes(T node) { + return Collections.unmodifiableSet(this.upstreamAdjacentNodes.getOrDefault(node, Set.of())); + } + + /** + * Return all immediate downstream neighbors of a given node. + * + * @param node The node to report the immediate downstream neighbors of. + */ + public Set getDownstreamAdjacentNodes(T node) { + return Collections.unmodifiableSet(this.downstreamAdjacentNodes.getOrDefault(node, Set.of())); + } + + @Override + public void addNode(T node) { + this.graphChanged(); + this.upstreamAdjacentNodes.putIfAbsent(node, Set.of()); + this.downstreamAdjacentNodes.putIfAbsent(node, Set.of()); + } + + @Override + public void removeNode(T node) { + this.graphChanged(); + this.upstreamAdjacentNodes.remove(node); + this.downstreamAdjacentNodes.remove(node); + // The node also needs to be removed from the sets that represent connections to the node. + CollectionUtil.removeFromValues(this.upstreamAdjacentNodes, node); + CollectionUtil.removeFromValues(this.downstreamAdjacentNodes, node); + } + + /** + * Add a new directed edge to the graph. The first argument is the downstream node, the second + * argument the upstream node. If either argument is null, do nothing. + * + * @param sink The downstream immediate neighbor. + * @param source The upstream immediate neighbor. + */ + @Override + public void addEdge(T sink, T source) { + this.graphChanged(); + if (sink != null && source != null) { + this.downstreamAdjacentNodes.compute(source, (k, set) -> CollectionUtil.plus(set, sink)); + this.upstreamAdjacentNodes.compute(sink, (k, set) -> CollectionUtil.plus(set, source)); } - - - /** - * Return the root nodes of this graph. - * Root nodes have no upstream neighbors. - */ - public Set rootNodes() { - return independentNodes(this.upstreamAdjacentNodes); + } + + /** + * Add new directed edges to the graph. The first argument is the downstream node, the second + * argument a set of upstream nodes. + * + * @param sink The downstream immediate neighbor. + * @param sources The upstream immediate neighbors. + */ + @Override + public void addEdges(T sink, List sources) { + for (T source : sources) { + this.addEdge(sink, source); } - - - /** - * Return the leaf nodes of this graph. - * Leaf nodes have no downstream neighbors. - */ - public Set leafNodes() { - return independentNodes(this.downstreamAdjacentNodes); + } + + /** + * Remove a directed edge from the graph. + * + * @param sink The downstream immediate neighbor. + * @param source The upstream immediate neighbor. + */ + @Override + public void removeEdge(T sink, T source) { + this.graphChanged(); + this.upstreamAdjacentNodes.computeIfPresent( + sink, (k, upstream) -> CollectionUtil.minus(upstream, source)); + this.downstreamAdjacentNodes.computeIfPresent( + source, (k, downstream) -> CollectionUtil.minus(downstream, sink)); + } + + /** Obtain a copy of this graph by creating an new instance and copying the adjacency maps. */ + public DirectedGraph copy() { + var graph = new DirectedGraph(); + for (var entry : this.upstreamAdjacentNodes.entrySet()) { + graph.upstreamAdjacentNodes.put(entry.getKey(), CollectionUtil.copy(entry.getValue())); } - - - @Override - public int nodeCount() { - return downstreamAdjacentNodes.size(); + for (var entry : this.downstreamAdjacentNodes.entrySet()) { + graph.downstreamAdjacentNodes.put(entry.getKey(), CollectionUtil.copy(entry.getValue())); } - - - @Override - public int edgeCount() { - return this.upstreamAdjacentNodes.values().stream().mapToInt(Set::size).sum(); + return graph; + } + + /** + * For a given a two adjacency maps, copy missing edges from the first map to the second. + * + * @param srcMap The adjacency map to copy edges from. + * @param dstMap The adjacency map to copy edges to. + */ + private void mirror(Map> srcMap, Map> dstMap) { + if (srcMap != null && dstMap != null) { + for (Entry> entry : srcMap.entrySet()) { + var node = entry.getKey(); + var srcEdges = entry.getValue(); + dstMap.compute( + node, + (_node, dstEdges) -> { + // Node does not exist; add it. + if (dstEdges == null) { + return CollectionUtil.copy(srcEdges); + } + + // Node does exist; add the missing edges. + var set = dstEdges; + for (T edge : srcEdges) { + set = CollectionUtil.plus(set, edge); + } + return set; + }); + } } - - - @Override - public Set nodes() { - return Collections.unmodifiableSet(this.downstreamAdjacentNodes.keySet()); + } + + /** + * Merge another directed graph into this one. + * + * @param another The graph to merge into this one. + */ + public void merge(DirectedGraph another) { + this.graphChanged(); + mirror(another.upstreamAdjacentNodes, this.upstreamAdjacentNodes); + mirror(another.downstreamAdjacentNodes, this.downstreamAdjacentNodes); + } + + /** Return the set of nodes that have no neighbors listed in the given adjacency map. */ + private Set independentNodes(Map> adjacencyMap) { + var independent = new LinkedHashSet(); + for (T node : nodes()) { + var neighbors = adjacencyMap.get(node); + if (neighbors == null || neighbors.size() == 0) { + independent.add(node); + } } - - - public void clear() { - this.graphChanged(); - this.downstreamAdjacentNodes.clear(); - this.upstreamAdjacentNodes.clear(); + return independent; + } + + /** Return the root nodes of this graph. Root nodes have no upstream neighbors. */ + public Set rootNodes() { + return independentNodes(this.upstreamAdjacentNodes); + } + + /** Return the leaf nodes of this graph. Leaf nodes have no downstream neighbors. */ + public Set leafNodes() { + return independentNodes(this.downstreamAdjacentNodes); + } + + @Override + public int nodeCount() { + return downstreamAdjacentNodes.size(); + } + + @Override + public int edgeCount() { + return this.upstreamAdjacentNodes.values().stream().mapToInt(Set::size).sum(); + } + + @Override + public Set nodes() { + return Collections.unmodifiableSet(this.downstreamAdjacentNodes.keySet()); + } + + public void clear() { + this.graphChanged(); + this.downstreamAdjacentNodes.clear(); + this.upstreamAdjacentNodes.clear(); + } + + /** Return a textual list of the nodes. */ + @Override + public String toString() { + return nodes().stream().map(Objects::toString).collect(Collectors.joining(", ", "{", "}")); + } + + /** Return the DOT (GraphViz) representation of the graph. */ + @Override + public String toDOT() { + StringBuilder dotRepresentation = new StringBuilder(); + StringBuilder edges = new StringBuilder(); + + // Start the digraph with a left-write rank + dotRepresentation.append("digraph {\n"); + dotRepresentation.append(" rankdir=LF;\n"); + + Set nodes = nodes(); + for (T node : nodes) { + // Draw the node + dotRepresentation.append( + " node_" + + (node.toString().hashCode() & 0xfffffff) + + " [label=\"" + + node.toString() + + "\"]\n"); + + // Draw the edges + Set downstreamNodes = getDownstreamAdjacentNodes(node); + for (T downstreamNode : downstreamNodes) { + edges.append( + " node_" + + (node.toString().hashCode() & 0xfffffff) + + " -> node_" + + (downstreamNode.toString().hashCode() & 0xfffffff) + + "\n"); + } } + // Add the edges to the definition of the graph at the bottom + dotRepresentation.append(edges); - /** - * Return a textual list of the nodes. - */ - @Override - public String toString() { - return nodes().stream().map(Objects::toString).collect(Collectors.joining(", ", "{", "}")); - } + // Close the digraph + dotRepresentation.append("}\n"); - /** - * Return the DOT (GraphViz) representation of the graph. - */ - @Override - public String toDOT() { - StringBuilder dotRepresentation = new StringBuilder(); - StringBuilder edges = new StringBuilder(); - - // Start the digraph with a left-write rank - dotRepresentation.append("digraph {\n"); - dotRepresentation.append(" rankdir=LF;\n"); - - Set nodes = nodes(); - for (T node: nodes) { - // Draw the node - dotRepresentation.append(" node_" + (node.toString().hashCode() & 0xfffffff) - + " [label=\""+ node.toString() +"\"]\n"); - - // Draw the edges - Set downstreamNodes = getDownstreamAdjacentNodes(node); - for (T downstreamNode: downstreamNodes) { - edges.append(" node_" + (node.toString().hashCode() & 0xfffffff) - + " -> node_" + (downstreamNode.toString().hashCode() & 0xfffffff) + "\n"); - } - } - - // Add the edges to the definition of the graph at the bottom - dotRepresentation.append(edges); - - // Close the digraph - dotRepresentation.append("}\n"); - - // Return the DOT representation - return dotRepresentation.toString(); - } + // Return the DOT representation + return dotRepresentation.toString(); + } } diff --git a/org.lflang/src/org/lflang/graph/Graph.java b/org.lflang/src/org/lflang/graph/Graph.java index 4e9a1723d9..07371c1255 100644 --- a/org.lflang/src/org/lflang/graph/Graph.java +++ b/org.lflang/src/org/lflang/graph/Graph.java @@ -1,26 +1,26 @@ /************* - Copyright (c) 2020, The University of California at Berkeley. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2020, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.graph; @@ -35,49 +35,36 @@ */ public interface Graph { - /** - * Return an unmodifiable set of nodes in this graph. - */ - Set nodes(); - - - boolean hasNode(T node); - - - /** Add the given node to the graph. */ - void addNode(T node); - - - /** - * Remove the given node from the graph. This also eliminates any - * edges from upstream and to downstream neighbors of this node. - * - * @param node The node to remove. - */ - void removeNode(T node); - - - // todo order of parameters here is unintuitive... from -> to is more usual - - void addEdge(T to, T from); + /** Return an unmodifiable set of nodes in this graph. */ + Set nodes(); + boolean hasNode(T node); - void addEdges(T to, List from); + /** Add the given node to the graph. */ + void addNode(T node); + /** + * Remove the given node from the graph. This also eliminates any edges from upstream and to + * downstream neighbors of this node. + * + * @param node The node to remove. + */ + void removeNode(T node); - void removeEdge(T to, T from); + // todo order of parameters here is unintuitive... from -> to is more usual + void addEdge(T to, T from); - /** - * Return the number of nodes in this graph. - */ - int nodeCount(); + void addEdges(T to, List from); + void removeEdge(T to, T from); - /** Return the number of directed edges in this graph. */ - int edgeCount(); + /** Return the number of nodes in this graph. */ + int nodeCount(); + /** Return the number of directed edges in this graph. */ + int edgeCount(); - /** Return the DOT (GraphViz) representation of the graph. */ - String toDOT(); + /** Return the DOT (GraphViz) representation of the graph. */ + String toDOT(); } diff --git a/org.lflang/src/org/lflang/graph/InstantiationGraph.java b/org.lflang/src/org/lflang/graph/InstantiationGraph.java index b32c97e2f2..dca5492fd0 100644 --- a/org.lflang/src/org/lflang/graph/InstantiationGraph.java +++ b/org.lflang/src/org/lflang/graph/InstantiationGraph.java @@ -1,35 +1,34 @@ /** * Copyright (c) 2020, The University of California at Berkeley. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + *

    Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + *

    1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. + *

    2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided with + * the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lflang.graph; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterables; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; - import org.eclipse.emf.ecore.resource.Resource; import org.lflang.ast.ASTUtils; import org.lflang.lf.Instantiation; @@ -38,138 +37,124 @@ import org.lflang.lf.ReactorDecl; import org.lflang.util.IteratorUtil; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; - /** - * A graph with vertices that are Reactors (not ReactorInstances) and edges that denote - * dependencies between them. A "dependency" from reactor class A to - * reactor class B (A depends on B) means that A instantiates within - * it at least one instance of B. Note that there a potentially - * confusing and subtle distinction here between an "instantiation" - * and an "instance". They are not the same thing at all. An - * "instantiation" is an AST node representing a statement like - * {@code a = new A();}. This can result in many instances of reactor - * class A (if the containing reactor class is instantiated multiple times). + * A graph with vertices that are Reactors (not ReactorInstances) and edges that denote dependencies + * between them. A "dependency" from reactor class A to reactor class B (A depends on B) means that + * A instantiates within it at least one instance of B. Note that there a potentially confusing and + * subtle distinction here between an "instantiation" and an "instance". They are not the same thing + * at all. An "instantiation" is an AST node representing a statement like {@code a = new A();}. + * This can result in many instances of reactor class A (if the containing reactor class is + * instantiated multiple times). * - * In addition to the graph, this class keeps track of the instantiations - * that induce the dependencies. These can be retrieved using the method - * {@code getInstantiations(Reactor)}. + *

    In addition to the graph, this class keeps track of the instantiations that induce the + * dependencies. These can be retrieved using the method {@code getInstantiations(Reactor)}. * * @author Marten Lohstroh */ public class InstantiationGraph extends PrecedenceGraph { - /** - * A mapping from reactors to the sites of their instantiation. - */ - protected final HashMultimap reactorToInstantiation = - HashMultimap.create(); + /** A mapping from reactors to the sites of their instantiation. */ + protected final HashMultimap reactorToInstantiation = + HashMultimap.create(); - /** - * A mapping from reactor classes to their declarations. - */ - protected final HashMultimap reactorToDecl = - HashMultimap.create(); + /** A mapping from reactor classes to their declarations. */ + protected final HashMultimap reactorToDecl = HashMultimap.create(); - /** - * Return the instantiations that point to a given reactor definition. - * If none are known, returns an empty set. * The returned set may be - * unmodifiable. - */ - public Set getInstantiations(final Reactor definition) { - Set instantiations = this.reactorToInstantiation.get(definition); - if (instantiations != null) { - return instantiations; - } else { - return Collections.emptySet(); - } + /** + * Return the instantiations that point to a given reactor definition. If none are known, returns + * an empty set. * The returned set may be unmodifiable. + */ + public Set getInstantiations(final Reactor definition) { + Set instantiations = this.reactorToInstantiation.get(definition); + if (instantiations != null) { + return instantiations; + } else { + return Collections.emptySet(); } + } - /** - * Return the declarations that point to a given reactor definition. - * A declaration is either a reactor definition or an import statement. - */ - public Set getDeclarations(final Reactor definition) { - return this.reactorToDecl.get(definition); - } + /** + * Return the declarations that point to a given reactor definition. A declaration is either a + * reactor definition or an import statement. + */ + public Set getDeclarations(final Reactor definition) { + return this.reactorToDecl.get(definition); + } - /** - * Return the reactor definitions referenced by instantiations in this graph - * ordered topologically. Each reactor in the returned list is preceded by - * any reactors that it may instantiate. - */ - public List getReactors() { - return this.nodesInTopologicalOrder(); - } + /** + * Return the reactor definitions referenced by instantiations in this graph ordered + * topologically. Each reactor in the returned list is preceded by any reactors that it may + * instantiate. + */ + public List getReactors() { + return this.nodesInTopologicalOrder(); + } - /** - * Construct an instantiation graph based on the given AST and, if the - * detectCycles argument is true, run Tarjan's algorithm to detect cyclic - * dependencies between instantiations. - * @param resource The resource associated with the AST. - * @param detectCycles Whether or not to detect cycles. - */ - public InstantiationGraph(final Resource resource, final boolean detectCycles) { - final Iterable instantiations = Iterables.filter( - IteratorUtil.asIterable(resource.getAllContents()), - Instantiation.class); - Optional main = IteratorUtil - .asFilteredStream(resource.getAllContents(), Reactor.class) - .filter(reactor -> reactor.isMain() || reactor.isFederated()) - .findFirst(); + /** + * Construct an instantiation graph based on the given AST and, if the detectCycles argument is + * true, run Tarjan's algorithm to detect cyclic dependencies between instantiations. + * + * @param resource The resource associated with the AST. + * @param detectCycles Whether or not to detect cycles. + */ + public InstantiationGraph(final Resource resource, final boolean detectCycles) { + final Iterable instantiations = + Iterables.filter(IteratorUtil.asIterable(resource.getAllContents()), Instantiation.class); + Optional main = + IteratorUtil.asFilteredStream(resource.getAllContents(), Reactor.class) + .filter(reactor -> reactor.isMain() || reactor.isFederated()) + .findFirst(); - if (main.isPresent()) { - this.addNode(main.get()); - } - for (final Instantiation i : instantiations) { - this.buildGraph(i, new HashSet<>()); - } - if (detectCycles) { - this.detectCycles(); - } + if (main.isPresent()) { + this.addNode(main.get()); + } + for (final Instantiation i : instantiations) { + this.buildGraph(i, new HashSet<>()); + } + if (detectCycles) { + this.detectCycles(); } + } - /** - * Construct an instantiation graph based on the given AST and, if the - * detectCycles argument is true, run Tarjan's algorithm to detect cyclic - * dependencies between instantiations. - * @param model The root of the AST. - * @param detectCycles Whether or not to detect cycles. - */ - public InstantiationGraph(final Model model, final boolean detectCycles) { - for (final Reactor r : model.getReactors()) { - for (final Instantiation i : r.getInstantiations()) { - this.buildGraph(i, new HashSet<>()); - } - } - if (detectCycles) { - this.detectCycles(); - } + /** + * Construct an instantiation graph based on the given AST and, if the detectCycles argument is + * true, run Tarjan's algorithm to detect cyclic dependencies between instantiations. + * + * @param model The root of the AST. + * @param detectCycles Whether or not to detect cycles. + */ + public InstantiationGraph(final Model model, final boolean detectCycles) { + for (final Reactor r : model.getReactors()) { + for (final Instantiation i : r.getInstantiations()) { + this.buildGraph(i, new HashSet<>()); + } + } + if (detectCycles) { + this.detectCycles(); } + } - /** - * Traverse the AST and build this precedence graph relating the - * encountered instantiations. Also map each reactor to all - * declarations associated with it and each reactor to the sites of - * its instantiations. - */ - private void buildGraph(final Instantiation instantiation, final Set visited) { - final ReactorDecl decl = instantiation.getReactorClass(); - final Reactor reactor = ASTUtils.toDefinition(decl); - if (reactor != null) { - Reactor container = ASTUtils.getEnclosingReactor(instantiation); - if (visited.add(instantiation)) { - this.reactorToInstantiation.put(reactor, instantiation); - this.reactorToDecl.put(reactor, decl); - if (container != null) { - this.addEdge(container, reactor); - } else { - this.addNode(reactor); - } - for (final Instantiation inst : reactor.getInstantiations()) { - this.buildGraph(inst, visited); - } - } + /** + * Traverse the AST and build this precedence graph relating the encountered instantiations. Also + * map each reactor to all declarations associated with it and each reactor to the sites of its + * instantiations. + */ + private void buildGraph(final Instantiation instantiation, final Set visited) { + final ReactorDecl decl = instantiation.getReactorClass(); + final Reactor reactor = ASTUtils.toDefinition(decl); + if (reactor != null) { + Reactor container = ASTUtils.getEnclosingReactor(instantiation); + if (visited.add(instantiation)) { + this.reactorToInstantiation.put(reactor, instantiation); + this.reactorToDecl.put(reactor, decl); + if (container != null) { + this.addEdge(container, reactor); + } else { + this.addNode(reactor); + } + for (final Instantiation inst : reactor.getInstantiations()) { + this.buildGraph(inst, visited); } + } } + } } diff --git a/org.lflang/src/org/lflang/graph/NodeAnnotation.java b/org.lflang/src/org/lflang/graph/NodeAnnotation.java index b8b91c92ad..191967d043 100644 --- a/org.lflang/src/org/lflang/graph/NodeAnnotation.java +++ b/org.lflang/src/org/lflang/graph/NodeAnnotation.java @@ -1,66 +1,54 @@ /** * Copyright (c) 2019, The University of California at Berkeley. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *

    Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + *

    1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + *

    2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided with + * the distribution. + * + *

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lflang.graph; /** - * Note annotations used in Tarjan's algorithm for finding strongly connected - * components. - * + * Note annotations used in Tarjan's algorithm for finding strongly connected components. + * * @author Marten Lohstroh */ public class NodeAnnotation { - /** - * Sequence number that is assigned when this node is discovered. - * A node with a lower index was discovered later than this one; - * a node with a higher index was discovered later than this one. - */ - public int index = -1; - - /** - * Temporary mark do be used in topological sort algorithm. - */ - public boolean hasTempMark = false; - - /** - * Temporary mark do be used in topological sort algorithm. - */ - public boolean hasPermMark = false; - - /** - * The smallest index of any node known to be reachable from this node. - */ - public int lowLink = -1; - - /** - * Whether or not this node is currently on the stack that - * keeps track of visited nodes that potentially form a cycle. - */ - public boolean onStack = false; - - /** - * Whether or not this node has a dependency on itself. - */ - public boolean selfLoop = false; -} + /** + * Sequence number that is assigned when this node is discovered. A node with a lower index was + * discovered later than this one; a node with a higher index was discovered later than this one. + */ + public int index = -1; + + /** Temporary mark do be used in topological sort algorithm. */ + public boolean hasTempMark = false; + + /** Temporary mark do be used in topological sort algorithm. */ + public boolean hasPermMark = false; + /** The smallest index of any node known to be reachable from this node. */ + public int lowLink = -1; + + /** + * Whether or not this node is currently on the stack that keeps track of visited nodes that + * potentially form a cycle. + */ + public boolean onStack = false; + + /** Whether or not this node has a dependency on itself. */ + public boolean selfLoop = false; +} diff --git a/org.lflang/src/org/lflang/graph/NodeAnnotations.java b/org.lflang/src/org/lflang/graph/NodeAnnotations.java index 346149a8c4..6efe85760a 100644 --- a/org.lflang/src/org/lflang/graph/NodeAnnotations.java +++ b/org.lflang/src/org/lflang/graph/NodeAnnotations.java @@ -1,46 +1,42 @@ /** * Copyright (c) 2019, The University of California at Berkeley. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *

    Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + *

    1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + *

    2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided with + * the distribution. + * + *

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lflang.graph; import java.util.HashMap; -/** - * Maps a node in the graph to its annotation. - * Creates a new annotation if no annotation exists. - */ +/** Maps a node in the graph to its annotation. Creates a new annotation if no annotation exists. */ public class NodeAnnotations { private HashMap annotations = new HashMap(); - + public NodeAnnotation get(final T node) { NodeAnnotation annotation = this.annotations.get(node); if (annotation == null) { - annotation = new NodeAnnotation(); - this.annotations.put(node, annotation); + annotation = new NodeAnnotation(); + this.annotations.put(node, annotation); } return annotation; } - + public NodeAnnotation put(final T node, final NodeAnnotation annotation) { return this.annotations.put(node, annotation); } diff --git a/org.lflang/src/org/lflang/graph/PrecedenceGraph.java b/org.lflang/src/org/lflang/graph/PrecedenceGraph.java index 03fd266f6a..80abb21455 100644 --- a/org.lflang/src/org/lflang/graph/PrecedenceGraph.java +++ b/org.lflang/src/org/lflang/graph/PrecedenceGraph.java @@ -1,242 +1,219 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.graph; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.Stack; - import org.eclipse.xtext.xbase.lib.ListExtensions; -import java.util.ArrayList; - -/** - * Elaboration of {@code DirectedGraph} that is capable of identifying strongly - * connected components and topologically sorting its nodes. - * +/** + * Elaboration of {@code DirectedGraph} that is capable of identifying strongly connected components + * and topologically sorting its nodes. + * * @author Marten Lohstroh */ public class PrecedenceGraph extends DirectedGraph { - /** - * Annotations used during the execution of Tarjan's algorithm. - */ - private NodeAnnotations annotations = new NodeAnnotations(); - - /** - * Indicates whether or not the graph has been analyzed for cycles. - * If this variable is false, Tarjan's algorithm need to be ran to find out - * whether or not this graph has cycles. - */ - private boolean cycleAnalysisDone = false; - - /** - * Indicates whether or not the graph has been sorted. - * If this variable is false, a new DFS has to be done to compute a - * topological sort. - */ - private boolean isSorted = false; - - /** - * Index used in Tarjan's algorithm. - */ - private int index = 0; - - /** - * After analysis has completed, this list contains all nodes in reverse - * topological order. - */ - private List sortedNodes = new ArrayList<>(); - - /** - * Stack used in Tarjan's algorithm. - */ - private Stack stack = new Stack<>(); - - /** - * After analysis has completed, this list contains all all sets of nodes - * that are part of the same strongly connected component. - */ - protected List> cycles = new ArrayList<>(); - - /** - * Invalidate cached analysis due to changes in the graph structure. - */ - @Override - public void graphChanged() { - this.cycleAnalysisDone = false; - this.isSorted = false; - } - - /** - * Construct a new dependency graph. - */ - public PrecedenceGraph() {} - - /** - * Topologically sort the nodes in the graph. - */ - private void sortNodes() { - if (!this.isSorted) { - // Cleanup. - this.sortedNodes = new ArrayList<>(); - this.nodes().forEach( - it -> { - this.annotations.get(it).hasTempMark = false; - this.annotations.get(it).hasPermMark = false; - } - ); - - // Start sorting. - for (T node : this.nodes()) { - if (!this.annotations.get(node).hasPermMark) { - // Unmarked node. - this.visit(node); - } - } - this.isSorted = true; + /** Annotations used during the execution of Tarjan's algorithm. */ + private NodeAnnotations annotations = new NodeAnnotations(); + + /** + * Indicates whether or not the graph has been analyzed for cycles. If this variable is false, + * Tarjan's algorithm need to be ran to find out whether or not this graph has cycles. + */ + private boolean cycleAnalysisDone = false; + + /** + * Indicates whether or not the graph has been sorted. If this variable is false, a new DFS has to + * be done to compute a topological sort. + */ + private boolean isSorted = false; + + /** Index used in Tarjan's algorithm. */ + private int index = 0; + + /** After analysis has completed, this list contains all nodes in reverse topological order. */ + private List sortedNodes = new ArrayList<>(); + + /** Stack used in Tarjan's algorithm. */ + private Stack stack = new Stack<>(); + + /** + * After analysis has completed, this list contains all all sets of nodes that are part of the + * same strongly connected component. + */ + protected List> cycles = new ArrayList<>(); + + /** Invalidate cached analysis due to changes in the graph structure. */ + @Override + public void graphChanged() { + this.cycleAnalysisDone = false; + this.isSorted = false; + } + + /** Construct a new dependency graph. */ + public PrecedenceGraph() {} + + /** Topologically sort the nodes in the graph. */ + private void sortNodes() { + if (!this.isSorted) { + // Cleanup. + this.sortedNodes = new ArrayList<>(); + this.nodes() + .forEach( + it -> { + this.annotations.get(it).hasTempMark = false; + this.annotations.get(it).hasPermMark = false; + }); + + // Start sorting. + for (T node : this.nodes()) { + if (!this.annotations.get(node).hasPermMark) { + // Unmarked node. + this.visit(node); } + } + this.isSorted = true; } - - /** - * Recursively visit all nodes reachable from the given node; after all - * those nodes have been visited add the current node to a list which will - * be sorted in reverse order. - */ - private void visit(T node) { - NodeAnnotation annotation = this.annotations.get(node); - if (annotation.hasPermMark) { - return; - } - if (annotation.hasTempMark) { - // Not a DAG. - throw new Error("Cannot order nodes due to cycle in the graph."); - } - annotation.hasTempMark = true; - for (T dep : this.getDownstreamAdjacentNodes(node)) { - visit(dep); - } - annotation.hasTempMark = false; - annotation.hasPermMark = true; - this.sortedNodes.add(node); - } - - /** - * Run Tarjan's algorithm for finding strongly connected components. - * After invoking this method, the detected cycles with be listed - * in the class variable {@code cycles}. - */ - public void detectCycles() { - if (!this.cycleAnalysisDone) { - this.index = 0; - this.stack = new Stack<>(); - this.cycles = new ArrayList<>(); - this.nodes().forEach(it -> { - this.annotations.get(it).index = -1; - }); - for (T node : this.nodes()) { - if (this.annotations.get(node).index == -1) { - this.strongConnect(node); - } - } - this.cycleAnalysisDone = true; - stack = null; - } + } + + /** + * Recursively visit all nodes reachable from the given node; after all those nodes have been + * visited add the current node to a list which will be sorted in reverse order. + */ + private void visit(T node) { + NodeAnnotation annotation = this.annotations.get(node); + if (annotation.hasPermMark) { + return; } - - /** - * Report whether this graph has any cycles in it. - */ - public boolean hasCycles() { - this.detectCycles(); - return this.cycles.size() > 0; + if (annotation.hasTempMark) { + // Not a DAG. + throw new Error("Cannot order nodes due to cycle in the graph."); } - - /** - * Return a list of strongly connected components that exist in this graph. - */ - public List> getCycles() { - this.detectCycles(); - return this.cycles; + annotation.hasTempMark = true; + for (T dep : this.getDownstreamAdjacentNodes(node)) { + visit(dep); } - - /** - * Traverse the graph to visit unvisited dependencies and determine - * whether they are part of a cycle. - */ - public void strongConnect(T node) { - NodeAnnotation annotation = this.annotations.get(node); - annotation.index = this.index; - annotation.lowLink = this.index; - annotation.onStack = true; - this.index++; - this.stack.push(node); - for (T dep : this.getUpstreamAdjacentNodes(node)) { - NodeAnnotation depAnnotation = this.annotations.get(dep); - if (depAnnotation.onStack) { - annotation.lowLink = Math.min(annotation.lowLink, depAnnotation.index); - if (node.equals(dep)) { - annotation.selfLoop = true; - } - } else if (depAnnotation.index == -1) { - strongConnect(dep); - annotation.lowLink = Math.min(annotation.lowLink, depAnnotation.lowLink); - } - } - - if (annotation.lowLink == annotation.index) { - Set scc = new LinkedHashSet<>(); - T dep = null; - do { - dep = this.stack.pop(); - this.annotations.get(dep).onStack = false; - scc.add(dep); - } while (!node.equals(dep)); - // Only report self loops or cycles with two or more nodes. - if (scc.size() > 1 || annotation.selfLoop) { - this.cycles.add(scc); - } + annotation.hasTempMark = false; + annotation.hasPermMark = true; + this.sortedNodes.add(node); + } + + /** + * Run Tarjan's algorithm for finding strongly connected components. After invoking this method, + * the detected cycles with be listed in the class variable {@code cycles}. + */ + public void detectCycles() { + if (!this.cycleAnalysisDone) { + this.index = 0; + this.stack = new Stack<>(); + this.cycles = new ArrayList<>(); + this.nodes() + .forEach( + it -> { + this.annotations.get(it).index = -1; + }); + for (T node : this.nodes()) { + if (this.annotations.get(node).index == -1) { + this.strongConnect(node); } + } + this.cycleAnalysisDone = true; + stack = null; } - - /** - * Return the nodes of this graph in reverse topological order. Each node - * in the returned list is succeeded by the nodes that it depends on. - */ - public List nodesInReverseTopologicalOrder() { - this.sortNodes(); - return this.sortedNodes; + } + + /** Report whether this graph has any cycles in it. */ + public boolean hasCycles() { + this.detectCycles(); + return this.cycles.size() > 0; + } + + /** Return a list of strongly connected components that exist in this graph. */ + public List> getCycles() { + this.detectCycles(); + return this.cycles; + } + + /** + * Traverse the graph to visit unvisited dependencies and determine whether they are part of a + * cycle. + */ + public void strongConnect(T node) { + NodeAnnotation annotation = this.annotations.get(node); + annotation.index = this.index; + annotation.lowLink = this.index; + annotation.onStack = true; + this.index++; + this.stack.push(node); + for (T dep : this.getUpstreamAdjacentNodes(node)) { + NodeAnnotation depAnnotation = this.annotations.get(dep); + if (depAnnotation.onStack) { + annotation.lowLink = Math.min(annotation.lowLink, depAnnotation.index); + if (node.equals(dep)) { + annotation.selfLoop = true; + } + } else if (depAnnotation.index == -1) { + strongConnect(dep); + annotation.lowLink = Math.min(annotation.lowLink, depAnnotation.lowLink); + } } - - /** - * Return the nodes of this graph in reverse topological order. Each node - * in the returned list is preceded by the nodes that it depends on. - */ - public List nodesInTopologicalOrder() { - this.sortNodes(); - return ListExtensions.reverse(this.sortedNodes); + + if (annotation.lowLink == annotation.index) { + Set scc = new LinkedHashSet<>(); + T dep = null; + do { + dep = this.stack.pop(); + this.annotations.get(dep).onStack = false; + scc.add(dep); + } while (!node.equals(dep)); + // Only report self loops or cycles with two or more nodes. + if (scc.size() > 1 || annotation.selfLoop) { + this.cycles.add(scc); + } } + } + + /** + * Return the nodes of this graph in reverse topological order. Each node in the returned list is + * succeeded by the nodes that it depends on. + */ + public List nodesInReverseTopologicalOrder() { + this.sortNodes(); + return this.sortedNodes; + } + + /** + * Return the nodes of this graph in reverse topological order. Each node in the returned list is + * preceded by the nodes that it depends on. + */ + public List nodesInTopologicalOrder() { + this.sortNodes(); + return ListExtensions.reverse(this.sortedNodes); + } } diff --git a/org.lflang/src/org/lflang/graph/TopologyGraph.java b/org.lflang/src/org/lflang/graph/TopologyGraph.java index f790de65a7..31d6de9500 100644 --- a/org.lflang/src/org/lflang/graph/TopologyGraph.java +++ b/org.lflang/src/org/lflang/graph/TopologyGraph.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2020, The University of California at Berkeley. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Collection; - import org.lflang.generator.NamedInstance; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; @@ -39,142 +38,143 @@ import org.lflang.lf.Variable; /** - * A graph with vertices that are ports or reactions and edges that denote - * dependencies between them. - * - * NOTE: This is not used anywhere anymore, but we keep it in case this particular - * graph structure proves useful in the future. - * + * A graph with vertices that are ports or reactions and edges that denote dependencies between + * them. + * + *

    NOTE: This is not used anywhere anymore, but we keep it in case this particular graph + * structure proves useful in the future. + * * @author Marten Lohstroh */ public class TopologyGraph extends PrecedenceGraph> { - /** - * Construct a graph with vertices that are reactions or ports and edges - * that represent (zero-delay) dependencies. - * - * After constructing the graph, run Tarjan's algorithm to detect cyclic - * dependencies between reactions. It is assumed that no instantiation - * cycles are present in the program. Checks for instantiation cycles thus - * must be carried out prior to constructing this graph. - * - * @param reactors The reactor instances to construct the graph for. - */ - public TopologyGraph(Collection reactors) { - for (var r : reactors) { - collectNodesFrom(r); - } - this.detectCycles(); + /** + * Construct a graph with vertices that are reactions or ports and edges that represent + * (zero-delay) dependencies. + * + *

    After constructing the graph, run Tarjan's algorithm to detect cyclic dependencies between + * reactions. It is assumed that no instantiation cycles are present in the program. Checks for + * instantiation cycles thus must be carried out prior to constructing this graph. + * + * @param reactors The reactor instances to construct the graph for. + */ + public TopologyGraph(Collection reactors) { + for (var r : reactors) { + collectNodesFrom(r); } + this.detectCycles(); + } - /** See description on other constructor. */ - public TopologyGraph(ReactorInstance... reactors) { - this(Arrays.asList(reactors)); - } + /** See description on other constructor. */ + public TopologyGraph(ReactorInstance... reactors) { + this(Arrays.asList(reactors)); + } - /** - * Build the graph by recursively visiting reactor instances contained in - * the passed in reactor instance. - * - * @param reactor A reactor instance to harvest dependencies from. - */ - public void collectNodesFrom(ReactorInstance reactor) { - ReactionInstance previousReaction = null; - for (var reaction : reactor.reactions) { - this.addNode(reaction); + /** + * Build the graph by recursively visiting reactor instances contained in the passed in reactor + * instance. + * + * @param reactor A reactor instance to harvest dependencies from. + */ + public void collectNodesFrom(ReactorInstance reactor) { + ReactionInstance previousReaction = null; + for (var reaction : reactor.reactions) { + this.addNode(reaction); - this.addSources(reaction); - this.addEffects(reaction); + this.addSources(reaction); + this.addEffects(reaction); - // If this is not an unordered reaction, then create a dependency - // on any previously defined reaction. - if (!reaction.isUnordered) { - // If there is an earlier reaction in this same reactor, then - // create a link in the reaction graph. - if (previousReaction != null) { - this.addEdge(reaction, previousReaction); - } - previousReaction = reaction; - } - } - // Recursively add nodes and edges from contained reactors. - for (var child : reactor.children) { - collectNodesFrom(child); + // If this is not an unordered reaction, then create a dependency + // on any previously defined reaction. + if (!reaction.isUnordered) { + // If there is an earlier reaction in this same reactor, then + // create a link in the reaction graph. + if (previousReaction != null) { + this.addEdge(reaction, previousReaction); } + previousReaction = reaction; + } } + // Recursively add nodes and edges from contained reactors. + for (var child : reactor.children) { + collectNodesFrom(child); + } + } - /** - * Given a reaction instance, record dependencies implied by its effects. - * - * Excluded from the recorded dependencies are those that are broken by - * physical connections or "after" delays. - * - * @param reaction The reaction to record the dependencies of. - */ - private void addEffects(ReactionInstance reaction) { - for (TriggerInstance effect : reaction.effects) { - if (effect instanceof PortInstance) { - addEdge(effect, reaction); - PortInstance orig = (PortInstance) effect; - for (SendRange sendRange : orig.getDependentPorts()) { - sendRange.destinations.forEach(dest -> { - recordDependency(reaction, orig, dest.instance, sendRange.connection); - }); - } - } + /** + * Given a reaction instance, record dependencies implied by its effects. + * + *

    Excluded from the recorded dependencies are those that are broken by physical connections or + * "after" delays. + * + * @param reaction The reaction to record the dependencies of. + */ + private void addEffects(ReactionInstance reaction) { + for (TriggerInstance effect : reaction.effects) { + if (effect instanceof PortInstance) { + addEdge(effect, reaction); + PortInstance orig = (PortInstance) effect; + for (SendRange sendRange : orig.getDependentPorts()) { + sendRange.destinations.forEach( + dest -> { + recordDependency(reaction, orig, dest.instance, sendRange.connection); + }); } + } } + } - /** - * Given a reaction instance, record dependencies implied by its sources. - * - * Excluded from the recorded dependencies are those that are broken by - * physical connections or "after" delays. - * - * @param reaction The reaction to record the dependencies of. - */ - private void addSources(ReactionInstance reaction) { - for (TriggerInstance source : reaction.sources) { - if (source instanceof PortInstance) { - addEdge(reaction, source); - PortInstance dest = (PortInstance) source; - dest.getDependsOnPorts().forEach(orig -> { - // FIXME: Don't have connection information here, hence the null argument. - // This will like result in invalid cycle detection. - recordDependency(reaction, orig.instance, dest, null); + /** + * Given a reaction instance, record dependencies implied by its sources. + * + *

    Excluded from the recorded dependencies are those that are broken by physical connections or + * "after" delays. + * + * @param reaction The reaction to record the dependencies of. + */ + private void addSources(ReactionInstance reaction) { + for (TriggerInstance source : reaction.sources) { + if (source instanceof PortInstance) { + addEdge(reaction, source); + PortInstance dest = (PortInstance) source; + dest.getDependsOnPorts() + .forEach( + orig -> { + // FIXME: Don't have connection information here, hence the null argument. + // This will like result in invalid cycle detection. + recordDependency(reaction, orig.instance, dest, null); }); - } - } + } } + } - /** - * Record a dependency between two port instances, but only if there is a - * zero-delay path from origin to destination. - * - * @param reaction A reaction that has one of the given ports as a source or - * effect. - * @param orig The upstream port. - * @param dest The downstream port. - * @param connection The connection creating this dependency or null if not - * created by a connection. - */ - private void recordDependency(ReactionInstance reaction, PortInstance orig, - PortInstance dest, Connection connection) { - if (!dependencyBroken(connection)) { - addEdge(dest, orig); - } + /** + * Record a dependency between two port instances, but only if there is a zero-delay path from + * origin to destination. + * + * @param reaction A reaction that has one of the given ports as a source or effect. + * @param orig The upstream port. + * @param dest The downstream port. + * @param connection The connection creating this dependency or null if not created by a + * connection. + */ + private void recordDependency( + ReactionInstance reaction, PortInstance orig, PortInstance dest, Connection connection) { + if (!dependencyBroken(connection)) { + addEdge(dest, orig); } + } - /** - * Report whether or not the given connection breaks dependencies or not. - * - * @param c An AST object that represents a connection. - * @return true if the connection is physical or has a delay. - */ - private boolean dependencyBroken(Connection c) { - if (c != null && (c.isPhysical() || c.getDelay() != null)) { - return true; - } - return false; + /** + * Report whether or not the given connection breaks dependencies or not. + * + * @param c An AST object that represents a connection. + * @return true if the connection is physical or has a delay. + */ + private boolean dependencyBroken(Connection c) { + if (c != null && (c.isPhysical() || c.getDelay() != null)) { + return true; } + return false; + } } diff --git a/org.lflang/src/org/lflang/ide/LFIdeModule.java b/org.lflang/src/org/lflang/ide/LFIdeModule.java index 6c63d9c6e0..81aa863bd1 100644 --- a/org.lflang/src/org/lflang/ide/LFIdeModule.java +++ b/org.lflang/src/org/lflang/ide/LFIdeModule.java @@ -3,9 +3,5 @@ */ package org.lflang.ide; - -/** - * Use this class to register ide components. - */ -public class LFIdeModule extends AbstractLFIdeModule { -} +/** Use this class to register ide components. */ +public class LFIdeModule extends AbstractLFIdeModule {} diff --git a/org.lflang/src/org/lflang/ide/LFIdeSetup.java b/org.lflang/src/org/lflang/ide/LFIdeSetup.java index 2e6b969952..7465bda78b 100644 --- a/org.lflang/src/org/lflang/ide/LFIdeSetup.java +++ b/org.lflang/src/org/lflang/ide/LFIdeSetup.java @@ -6,17 +6,14 @@ import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; -/** - * Initialization support for running Xtext languages as language servers. - */ +/** Initialization support for running Xtext languages as language servers. */ public class LFIdeSetup extends LFStandaloneSetup { - public LFIdeSetup() { - super(new LFRuntimeModule(), new LFIdeModule()); - } - - public static void doSetup() { - new LFIdeSetup().createInjectorAndDoEMFRegistration(); - } + public LFIdeSetup() { + super(new LFRuntimeModule(), new LFIdeModule()); + } + public static void doSetup() { + new LFIdeSetup().createInjectorAndDoEMFRegistration(); + } } diff --git a/org.lflang/src/org/lflang/scoping/LFGlobalScopeProvider.java b/org.lflang/src/org/lflang/scoping/LFGlobalScopeProvider.java index 119ccae842..18c7a3a8af 100644 --- a/org.lflang/src/org/lflang/scoping/LFGlobalScopeProvider.java +++ b/org.lflang/src/org/lflang/scoping/LFGlobalScopeProvider.java @@ -25,134 +25,121 @@ import com.google.common.base.Splitter; import com.google.inject.Inject; import com.google.inject.Provider; - import java.util.LinkedHashSet; import java.util.Set; - import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.resource.IResourceDescription; import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider; import org.eclipse.xtext.util.IResourceScopeCache; - -import org.lflang.lf.LfPackage; import org.lflang.LFResourceDescriptionStrategy; +import org.lflang.lf.LfPackage; /** - * Global scope provider that limits access to only those files that were - * explicitly imported. - *

    - * Adapted from from Xtext manual, Chapter 8.7. + * Global scope provider that limits access to only those files that were explicitly imported. + * + *

    Adapted from from Xtext manual, Chapter 8.7. * * @author Marten Lohstroh - * @see xtext doc + * @see xtext + * doc */ public class LFGlobalScopeProvider extends ImportUriGlobalScopeProvider { - /** - * Splitter used to process user-data annotations of Model nodes. - */ - static final Splitter SPLITTER = Splitter.on(LFResourceDescriptionStrategy.DELIMITER); - - static final String IMPORTED_URIS = "IMPORTED_URIS"; - - static final String IMPORTED_RESOURCES = "IMPORTED_RESOURCES"; - - @Inject - private IResourceDescription.Manager descriptionManager; - - @Inject - private IResourceScopeCache cache; - - /** - * Return the set of URI objects pointing to the resources that must be - * included for compilation. - */ - @Override - protected LinkedHashSet getImportedUris(Resource resource) { - return cache.get(IMPORTED_URIS, resource, - new Provider>() { - /** - * Collect unique URIs in case the cache is not populated yet. - */ - @Override - public LinkedHashSet get() { - var uniqueImportURIs = new LinkedHashSet(5); - collectImportUris(resource, uniqueImportURIs); - uniqueImportURIs.removeIf(uri -> !EcoreUtil2.isValidUri(resource, uri)); - return uniqueImportURIs; - } - - /** - * Helper method to recursively collect unique URIs. - */ - void collectImportUris(Resource resource, LinkedHashSet uniqueImportURIs) { - for (var imported : getImportedResources(resource, uniqueImportURIs)) { - collectImportUris(imported, uniqueImportURIs); - } - } - }); - } - - /** - * Return the resources imported by the given resource. - */ - public Set getImportedResources(Resource resource) { - return cache.get(IMPORTED_RESOURCES, resource, () -> getImportedResources(resource, null)); - } - - /** - * Resolve a resource identifier. - * - * @param uriStr resource identifier to resolve. - * @param resource resource to (initially) resolve it relative to. - */ - protected URI resolve(String uriStr, Resource resource) { - var uriObj = URI.createURI(uriStr); - if (uriObj != null && "lf".equalsIgnoreCase(uriObj.fileExtension())) { - // FIXME: If this doesn't work, try other things: - // (1) Look for a .project file up the file structure and try to - // resolve relative to the directory in which it is found. - // (2) Look for package description files try to resolve relative - // to the paths it includes. - // FIXME: potentially use a cache here to speed things up. - // See OnChangeEvictingCache - return uriObj.resolve(resource.getURI()); - } - return null; + /** Splitter used to process user-data annotations of Model nodes. */ + static final Splitter SPLITTER = Splitter.on(LFResourceDescriptionStrategy.DELIMITER); + + static final String IMPORTED_URIS = "IMPORTED_URIS"; + + static final String IMPORTED_RESOURCES = "IMPORTED_RESOURCES"; + + @Inject private IResourceDescription.Manager descriptionManager; + + @Inject private IResourceScopeCache cache; + + /** + * Return the set of URI objects pointing to the resources that must be included for compilation. + */ + @Override + protected LinkedHashSet getImportedUris(Resource resource) { + return cache.get( + IMPORTED_URIS, + resource, + new Provider>() { + /** Collect unique URIs in case the cache is not populated yet. */ + @Override + public LinkedHashSet get() { + var uniqueImportURIs = new LinkedHashSet(5); + collectImportUris(resource, uniqueImportURIs); + uniqueImportURIs.removeIf(uri -> !EcoreUtil2.isValidUri(resource, uri)); + return uniqueImportURIs; + } + + /** Helper method to recursively collect unique URIs. */ + void collectImportUris(Resource resource, LinkedHashSet uniqueImportURIs) { + for (var imported : getImportedResources(resource, uniqueImportURIs)) { + collectImportUris(imported, uniqueImportURIs); + } + } + }); + } + + /** Return the resources imported by the given resource. */ + public Set getImportedResources(Resource resource) { + return cache.get(IMPORTED_RESOURCES, resource, () -> getImportedResources(resource, null)); + } + + /** + * Resolve a resource identifier. + * + * @param uriStr resource identifier to resolve. + * @param resource resource to (initially) resolve it relative to. + */ + protected URI resolve(String uriStr, Resource resource) { + var uriObj = URI.createURI(uriStr); + if (uriObj != null && "lf".equalsIgnoreCase(uriObj.fileExtension())) { + // FIXME: If this doesn't work, try other things: + // (1) Look for a .project file up the file structure and try to + // resolve relative to the directory in which it is found. + // (2) Look for package description files try to resolve relative + // to the paths it includes. + // FIXME: potentially use a cache here to speed things up. + // See OnChangeEvictingCache + return uriObj.resolve(resource.getURI()); } - - /** - * Return the resources imported by a given resource, excluding those - * already discovered and therefore are present in the given set of - * import URIs. - * - * @param resource The resource to analyze. - * @param uniqueImportURIs The set of discovered import URIs - */ - protected Set getImportedResources(Resource resource, LinkedHashSet uniqueImportURIs) { - var resourceDescription = descriptionManager.getResourceDescription(resource); - var models = resourceDescription.getExportedObjectsByType(LfPackage.Literals.MODEL); - var resources = new LinkedHashSet(); - for (var model : models) { - var userData = model.getUserData(LFResourceDescriptionStrategy.INCLUDES); - if (userData != null) { - for (String uri : SPLITTER.split(userData)) {// Attempt to resolve the URI - var includedUri = this.resolve(uri, resource); - if (includedUri != null) { - try { - if (uniqueImportURIs == null || uniqueImportURIs.add(includedUri)) { - resources.add(resource.getResourceSet().getResource(includedUri, true)); - } - } catch (RuntimeException e) { - System.err.println("Unable to import " + includedUri + ": " + e.getMessage()); - } - } - - } + return null; + } + + /** + * Return the resources imported by a given resource, excluding those already discovered and + * therefore are present in the given set of import URIs. + * + * @param resource The resource to analyze. + * @param uniqueImportURIs The set of discovered import URIs + */ + protected Set getImportedResources( + Resource resource, LinkedHashSet uniqueImportURIs) { + var resourceDescription = descriptionManager.getResourceDescription(resource); + var models = resourceDescription.getExportedObjectsByType(LfPackage.Literals.MODEL); + var resources = new LinkedHashSet(); + for (var model : models) { + var userData = model.getUserData(LFResourceDescriptionStrategy.INCLUDES); + if (userData != null) { + for (String uri : SPLITTER.split(userData)) { // Attempt to resolve the URI + var includedUri = this.resolve(uri, resource); + if (includedUri != null) { + try { + if (uniqueImportURIs == null || uniqueImportURIs.add(includedUri)) { + resources.add(resource.getResourceSet().getResource(includedUri, true)); + } + } catch (RuntimeException e) { + System.err.println("Unable to import " + includedUri + ": " + e.getMessage()); } + } } - return resources; + } } + return resources; + } } diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProvider.java b/org.lflang/src/org/lflang/scoping/LFScopeProvider.java index 9967ddaabe..6a303b0eaf 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProvider.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProvider.java @@ -3,13 +3,10 @@ */ package org.lflang.scoping; - /** * This class contains custom scoping description. - * - * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping - * on how and when to use it. + * + *

    See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping on how and + * when to use it. */ -public class LFScopeProvider extends LFScopeProviderImpl { - -} +public class LFScopeProvider extends LFScopeProviderImpl {} diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java index 0e521e8cc4..c5cbea4e7e 100644 --- a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java +++ b/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java @@ -1,27 +1,27 @@ /************* -Copyright (c) 2020, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2020, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.scoping; @@ -29,16 +29,13 @@ import static org.lflang.ast.ASTUtils.*; import com.google.inject.Inject; - import java.util.ArrayList; - import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.xtext.naming.SimpleNameProvider; import org.eclipse.xtext.scoping.IScope; import org.eclipse.xtext.scoping.Scopes; import org.eclipse.xtext.scoping.impl.SelectableBasedScope; - import org.lflang.lf.Assignment; import org.lflang.lf.Connection; import org.lflang.lf.Deadline; @@ -63,220 +60,220 @@ */ public class LFScopeProviderImpl extends AbstractLFScopeProvider { - @Inject - private SimpleNameProvider nameProvider; + @Inject private SimpleNameProvider nameProvider; - @Inject - private LFGlobalScopeProvider scopeProvider; + @Inject private LFGlobalScopeProvider scopeProvider; - /** - * Enumerate of the kinds of references. - */ - enum RefType { - NULL, - TRIGGER, - SOURCE, - EFFECT, - WATCHDOG, - DEADLINE, - CLEFT, - CRIGHT - } + /** Enumerate of the kinds of references. */ + enum RefType { + NULL, + TRIGGER, + SOURCE, + EFFECT, + WATCHDOG, + DEADLINE, + CLEFT, + CRIGHT + } - /** - * Depending on the provided context, construct the appropriate scope - * for the given reference. - * - * @param context The AST node in which a to-be-resolved reference occurs. - * @param reference The reference to resolve. - */ - @Override - public IScope getScope(EObject context, EReference reference) { - if (context instanceof VarRef) { - return getScopeForVarRef((VarRef) context, reference); - } else if (context instanceof Assignment) { - return getScopeForAssignment((Assignment) context, reference); - } else if (context instanceof Instantiation) { - return getScopeForReactorDecl(context, reference); - } else if (context instanceof Reactor) { - return getScopeForReactorDecl(context, reference); - } else if (context instanceof ImportedReactor) { - return getScopeForImportedReactor((ImportedReactor) context, reference); - } - return super.getScope(context, reference); + /** + * Depending on the provided context, construct the appropriate scope for the given reference. + * + * @param context The AST node in which a to-be-resolved reference occurs. + * @param reference The reference to resolve. + */ + @Override + public IScope getScope(EObject context, EReference reference) { + if (context instanceof VarRef) { + return getScopeForVarRef((VarRef) context, reference); + } else if (context instanceof Assignment) { + return getScopeForAssignment((Assignment) context, reference); + } else if (context instanceof Instantiation) { + return getScopeForReactorDecl(context, reference); + } else if (context instanceof Reactor) { + return getScopeForReactorDecl(context, reference); + } else if (context instanceof ImportedReactor) { + return getScopeForImportedReactor((ImportedReactor) context, reference); } + return super.getScope(context, reference); + } - /** - * Filter out candidates that do not originate from the file listed in - * this particular import statement. - */ - protected IScope getScopeForImportedReactor(ImportedReactor context, EReference reference) { - String importURI = ((Import) context.eContainer()).getImportURI(); - var importedURI = scopeProvider.resolve(importURI == null ? "" : importURI, context.eResource()); - if (importedURI != null) { - var uniqueImportURIs = scopeProvider.getImportedUris(context.eResource()); - var descriptions = scopeProvider.getResourceDescriptions(context.eResource(), uniqueImportURIs); - var description = descriptions.getResourceDescription(importedURI); - return SelectableBasedScope.createScope(IScope.NULLSCOPE, description, null, reference.getEReferenceType(), false); - } - return Scopes.scopeFor(emptyList()); + /** + * Filter out candidates that do not originate from the file listed in this particular import + * statement. + */ + protected IScope getScopeForImportedReactor(ImportedReactor context, EReference reference) { + String importURI = ((Import) context.eContainer()).getImportURI(); + var importedURI = + scopeProvider.resolve(importURI == null ? "" : importURI, context.eResource()); + if (importedURI != null) { + var uniqueImportURIs = scopeProvider.getImportedUris(context.eResource()); + var descriptions = + scopeProvider.getResourceDescriptions(context.eResource(), uniqueImportURIs); + var description = descriptions.getResourceDescription(importedURI); + return SelectableBasedScope.createScope( + IScope.NULLSCOPE, description, null, reference.getEReferenceType(), false); } + return Scopes.scopeFor(emptyList()); + } - /** - * @param obj Instantiation or Reactor that has a ReactorDecl to resolve. - * @param reference The reference to link to a ReactorDecl node. - */ - protected IScope getScopeForReactorDecl(EObject obj, EReference reference) { + /** + * @param obj Instantiation or Reactor that has a ReactorDecl to resolve. + * @param reference The reference to link to a ReactorDecl node. + */ + protected IScope getScopeForReactorDecl(EObject obj, EReference reference) { - // Find the local Model - Model model = null; - EObject container = obj; - while(model == null && container != null) { - container = container.eContainer(); - if (container instanceof Model) { - model = (Model)container; - } - } - if (model == null) { - return Scopes.scopeFor(emptyList()); - } + // Find the local Model + Model model = null; + EObject container = obj; + while (model == null && container != null) { + container = container.eContainer(); + if (container instanceof Model) { + model = (Model) container; + } + } + if (model == null) { + return Scopes.scopeFor(emptyList()); + } - // Collect eligible candidates, all of which are local (i.e., not in other files). - var locals = new ArrayList(model.getReactors()); + // Collect eligible candidates, all of which are local (i.e., not in other files). + var locals = new ArrayList(model.getReactors()); - // Either point to the import statement (if it is renamed) - // or directly to the reactor definition. - for (Import it : model.getImports()) { - for (ImportedReactor ir : it.getReactorClasses()) { - if (ir.getName() != null) { - locals.add(ir); - } else if (ir.getReactorClass() != null) { - locals.add(ir.getReactorClass()); - } - } + // Either point to the import statement (if it is renamed) + // or directly to the reactor definition. + for (Import it : model.getImports()) { + for (ImportedReactor ir : it.getReactorClasses()) { + if (ir.getName() != null) { + locals.add(ir); + } else if (ir.getReactorClass() != null) { + locals.add(ir.getReactorClass()); } - return Scopes.scopeFor(locals); + } } + return Scopes.scopeFor(locals); + } - protected IScope getScopeForAssignment(Assignment assignment, EReference reference) { + protected IScope getScopeForAssignment(Assignment assignment, EReference reference) { - if (reference == LfPackage.Literals.ASSIGNMENT__LHS) { - var defn = toDefinition(((Instantiation) assignment.eContainer()).getReactorClass()); - if (defn != null) { - return Scopes.scopeFor(allParameters(defn)); - } - } - if (reference == LfPackage.Literals.ASSIGNMENT__RHS) { - return Scopes.scopeFor(((Reactor) assignment.eContainer().eContainer()).getParameters()); - } - return Scopes.scopeFor(emptyList()); + if (reference == LfPackage.Literals.ASSIGNMENT__LHS) { + var defn = toDefinition(((Instantiation) assignment.eContainer()).getReactorClass()); + if (defn != null) { + return Scopes.scopeFor(allParameters(defn)); + } + } + if (reference == LfPackage.Literals.ASSIGNMENT__RHS) { + return Scopes.scopeFor(((Reactor) assignment.eContainer().eContainer()).getParameters()); } + return Scopes.scopeFor(emptyList()); + } - protected IScope getScopeForVarRef(VarRef variable, EReference reference) { - if (reference == LfPackage.Literals.VAR_REF__VARIABLE) { - // Resolve hierarchical reference - Reactor reactor; - Mode mode = null; - if (variable.eContainer().eContainer() instanceof Reactor) { - reactor = (Reactor) variable.eContainer().eContainer(); - } else if (variable.eContainer().eContainer() instanceof Mode) { - mode = (Mode) variable.eContainer().eContainer(); - reactor = (Reactor) variable.eContainer().eContainer().eContainer(); - } else { - return Scopes.scopeFor(emptyList()); - } + protected IScope getScopeForVarRef(VarRef variable, EReference reference) { + if (reference == LfPackage.Literals.VAR_REF__VARIABLE) { + // Resolve hierarchical reference + Reactor reactor; + Mode mode = null; + if (variable.eContainer().eContainer() instanceof Reactor) { + reactor = (Reactor) variable.eContainer().eContainer(); + } else if (variable.eContainer().eContainer() instanceof Mode) { + mode = (Mode) variable.eContainer().eContainer(); + reactor = (Reactor) variable.eContainer().eContainer().eContainer(); + } else { + return Scopes.scopeFor(emptyList()); + } - RefType type = getRefType(variable); + RefType type = getRefType(variable); - if (variable.getContainer() != null) { // Resolve hierarchical port reference - var instanceName = nameProvider.getFullyQualifiedName(variable.getContainer()); - var instances = new ArrayList(reactor.getInstantiations()); - if (mode != null) { - instances.addAll(mode.getInstantiations()); - } + if (variable.getContainer() != null) { // Resolve hierarchical port reference + var instanceName = nameProvider.getFullyQualifiedName(variable.getContainer()); + var instances = new ArrayList(reactor.getInstantiations()); + if (mode != null) { + instances.addAll(mode.getInstantiations()); + } - if (instanceName != null) { - for (var instance : instances) { - var defn = toDefinition(instance.getReactorClass()); - if (defn != null && instance.getName().equals(instanceName.toString())) { - switch (type) { - case TRIGGER: - case SOURCE: - case CLEFT: - return Scopes.scopeFor(allOutputs(defn)); - case EFFECT: - case DEADLINE: - case CRIGHT: - return Scopes.scopeFor(allInputs(defn)); - } - } - } - } - return Scopes.scopeFor(emptyList()); - } else { - // Resolve local reference - switch (type) { - case TRIGGER: { - var candidates = new ArrayList(); - if (mode != null) { - candidates.addAll(mode.getActions()); - candidates.addAll(mode.getTimers()); - } - candidates.addAll(allInputs(reactor)); - candidates.addAll(allActions(reactor)); - candidates.addAll(allTimers(reactor)); - candidates.addAll(allWatchdogs(reactor)); - return Scopes.scopeFor(candidates); - } + if (instanceName != null) { + for (var instance : instances) { + var defn = toDefinition(instance.getReactorClass()); + if (defn != null && instance.getName().equals(instanceName.toString())) { + switch (type) { + case TRIGGER: case SOURCE: - return super.getScope(variable, reference); - case EFFECT: { - var candidates = new ArrayList(); - if (mode != null) { - candidates.addAll(mode.getActions()); - candidates.addAll(reactor.getModes()); - } - candidates.addAll(allOutputs(reactor)); - candidates.addAll(allActions(reactor)); - candidates.addAll(allWatchdogs(reactor)); - return Scopes.scopeFor(candidates); - } - case WATCHDOG: - return Scopes.scopeFor(allWatchdogs(reactor)); - case DEADLINE: case CLEFT: - return Scopes.scopeFor(allInputs(reactor)); + return Scopes.scopeFor(allOutputs(defn)); + case EFFECT: + case DEADLINE: case CRIGHT: - return Scopes.scopeFor(allOutputs(reactor)); - default: - return Scopes.scopeFor(emptyList()); - } + return Scopes.scopeFor(allInputs(defn)); + } } - } else { // Resolve instance - return super.getScope(variable, reference); + } } - } - - private RefType getRefType(VarRef variable) { - if (variable.eContainer() instanceof Deadline) { - return RefType.DEADLINE; - } else if (variable.eContainer() instanceof Reaction) { - var reaction = (Reaction) variable.eContainer(); - if (reaction.getTriggers().contains(variable)) { - return RefType.TRIGGER; - } else if (reaction.getSources().contains(variable)) { - return RefType.SOURCE; - } else if (reaction.getEffects().contains(variable)) { - return RefType.EFFECT; + return Scopes.scopeFor(emptyList()); + } else { + // Resolve local reference + switch (type) { + case TRIGGER: + { + var candidates = new ArrayList(); + if (mode != null) { + candidates.addAll(mode.getActions()); + candidates.addAll(mode.getTimers()); + } + candidates.addAll(allInputs(reactor)); + candidates.addAll(allActions(reactor)); + candidates.addAll(allTimers(reactor)); + candidates.addAll(allWatchdogs(reactor)); + return Scopes.scopeFor(candidates); } - } else if (variable.eContainer() instanceof Connection) { - var conn = (Connection) variable.eContainer(); - if (conn.getLeftPorts().contains(variable)) { - return RefType.CLEFT; - } else if (conn.getRightPorts().contains(variable)) { - return RefType.CRIGHT; + case SOURCE: + return super.getScope(variable, reference); + case EFFECT: + { + var candidates = new ArrayList(); + if (mode != null) { + candidates.addAll(mode.getActions()); + candidates.addAll(reactor.getModes()); + } + candidates.addAll(allOutputs(reactor)); + candidates.addAll(allActions(reactor)); + candidates.addAll(allWatchdogs(reactor)); + return Scopes.scopeFor(candidates); } + case WATCHDOG: + return Scopes.scopeFor(allWatchdogs(reactor)); + case DEADLINE: + case CLEFT: + return Scopes.scopeFor(allInputs(reactor)); + case CRIGHT: + return Scopes.scopeFor(allOutputs(reactor)); + default: + return Scopes.scopeFor(emptyList()); } - return RefType.NULL; + } + } else { // Resolve instance + return super.getScope(variable, reference); + } + } + + private RefType getRefType(VarRef variable) { + if (variable.eContainer() instanceof Deadline) { + return RefType.DEADLINE; + } else if (variable.eContainer() instanceof Reaction) { + var reaction = (Reaction) variable.eContainer(); + if (reaction.getTriggers().contains(variable)) { + return RefType.TRIGGER; + } else if (reaction.getSources().contains(variable)) { + return RefType.SOURCE; + } else if (reaction.getEffects().contains(variable)) { + return RefType.EFFECT; + } + } else if (variable.eContainer() instanceof Connection) { + var conn = (Connection) variable.eContainer(); + if (conn.getLeftPorts().contains(variable)) { + return RefType.CLEFT; + } else if (conn.getRightPorts().contains(variable)) { + return RefType.CRIGHT; + } } + return RefType.NULL; + } } diff --git a/org.lflang/src/org/lflang/util/ArduinoUtil.java b/org.lflang/src/org/lflang/util/ArduinoUtil.java index 85eac8ae8f..af741da7f2 100644 --- a/org.lflang/src/org/lflang/util/ArduinoUtil.java +++ b/org.lflang/src/org/lflang/util/ArduinoUtil.java @@ -5,123 +5,153 @@ import java.io.FileWriter; import java.io.IOException; import java.util.List; - +import org.eclipse.xtext.xbase.lib.Exceptions; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.TargetConfig; import org.lflang.generator.GeneratorCommandFactory; import org.lflang.generator.LFGeneratorContext; -import org.eclipse.xtext.xbase.lib.Exceptions; - /** * Utilities for Building using Arduino CLI. * - * We take in a Generator Context, Command Factory, and Error Reporter and - * make subsequent calls to arduino-cli given a FileConfig and TargetConfig. - * - * This should be used immediately after CodeGen to compile if the user provides - * a board type within their LF file. If the user also provides a port with flash enabled, - * we will also attempt to upload the compiled sketch directly to the board. + *

    We take in a Generator Context, Command Factory, and Error Reporter and make subsequent calls + * to arduino-cli given a FileConfig and TargetConfig. + * + *

    This should be used immediately after CodeGen to compile if the user provides a board type + * within their LF file. If the user also provides a port with flash enabled, we will also attempt + * to upload the compiled sketch directly to the board. */ public class ArduinoUtil { - private LFGeneratorContext context; - private GeneratorCommandFactory commandFactory; - private ErrorReporter errorReporter; + private LFGeneratorContext context; + private GeneratorCommandFactory commandFactory; + private ErrorReporter errorReporter; - public ArduinoUtil (LFGeneratorContext context, GeneratorCommandFactory commandFactory, ErrorReporter errorReporter) { - this.context = context; - this.commandFactory = commandFactory; - this.errorReporter = errorReporter; - } + public ArduinoUtil( + LFGeneratorContext context, + GeneratorCommandFactory commandFactory, + ErrorReporter errorReporter) { + this.context = context; + this.commandFactory = commandFactory; + this.errorReporter = errorReporter; + } - /** - * Return true if arduino-cli exists, false otherwise. - */ - private boolean checkArduinoCLIExists() { - LFCommand checkCommand = LFCommand.get("arduino-cli", List.of("version")); - return checkCommand != null && checkCommand.run() == 0; - } + /** Return true if arduino-cli exists, false otherwise. */ + private boolean checkArduinoCLIExists() { + LFCommand checkCommand = LFCommand.get("arduino-cli", List.of("version")); + return checkCommand != null && checkCommand.run() == 0; + } - /** - * Generate an LF style command for Arduino compilation based on FQBN - * @param fileConfig - * @param targetConfig - * @return LFCommand to compile an Arduino program given an FQBN. - * @throws IOException - */ - private LFCommand arduinoCompileCommand(FileConfig fileConfig, TargetConfig targetConfig) throws IOException { - if (!checkArduinoCLIExists()) { - throw new IOException("Must have arduino-cli installed to auto-compile."); - } else { - var srcGenPath = fileConfig.getSrcGenPath(); - try { - // Write to a temporary file to execute since ProcessBuilder does not like spaces and double quotes in its arguments. - File testScript = File.createTempFile("arduino", null); - testScript.deleteOnExit(); - if (!testScript.setExecutable(true)) { - throw new IOException("Failed to make compile script executable"); - } - var fileWriter = new FileWriter(testScript.getAbsoluteFile(), true); - BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); - String board = targetConfig.platformOptions.board != null ? targetConfig.platformOptions.board : "arduino:avr:leonardo"; - String isThreaded = targetConfig.platformOptions.board.contains("mbed") ? "-DLF_THREADED" : "-DLF_UNTHREADED"; - bufferedWriter.write("arduino-cli compile -b " + board + " --build-property " + - "compiler.c.extra_flags=\"" + isThreaded + " -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10\" " + - "--build-property compiler.cpp.extra_flags=\"" + isThreaded + " -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10\" " - + srcGenPath.toString()); - bufferedWriter.close(); - return commandFactory.createCommand( - testScript.getAbsolutePath(), List.of(), null); - } catch (IOException e) { - e.printStackTrace(); - throw new IOException(e); - } + /** + * Generate an LF style command for Arduino compilation based on FQBN + * + * @param fileConfig + * @param targetConfig + * @return LFCommand to compile an Arduino program given an FQBN. + * @throws IOException + */ + private LFCommand arduinoCompileCommand(FileConfig fileConfig, TargetConfig targetConfig) + throws IOException { + if (!checkArduinoCLIExists()) { + throw new IOException("Must have arduino-cli installed to auto-compile."); + } else { + var srcGenPath = fileConfig.getSrcGenPath(); + try { + // Write to a temporary file to execute since ProcessBuilder does not like spaces and double + // quotes in its arguments. + File testScript = File.createTempFile("arduino", null); + testScript.deleteOnExit(); + if (!testScript.setExecutable(true)) { + throw new IOException("Failed to make compile script executable"); } + var fileWriter = new FileWriter(testScript.getAbsoluteFile(), true); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + String board = + targetConfig.platformOptions.board != null + ? targetConfig.platformOptions.board + : "arduino:avr:leonardo"; + String isThreaded = + targetConfig.platformOptions.board.contains("mbed") + ? "-DLF_THREADED" + : "-DLF_UNTHREADED"; + bufferedWriter.write( + "arduino-cli compile -b " + + board + + " --build-property " + + "compiler.c.extra_flags=\"" + + isThreaded + + " -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10" + + " -DINITIAL_REACT_QUEUE_SIZE=10\" --build-property compiler.cpp.extra_flags=\"" + + isThreaded + + " -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10" + + " -DINITIAL_REACT_QUEUE_SIZE=10\" " + + srcGenPath.toString()); + bufferedWriter.close(); + return commandFactory.createCommand(testScript.getAbsolutePath(), List.of(), null); + } catch (IOException e) { + e.printStackTrace(); + throw new IOException(e); + } } + } - /** - * Compiles (and possibly auto-flashes) an Arduino program once code generation is completed. - * @param fileConfig - * @param targetConfig - */ - public void buildArduino(FileConfig fileConfig, TargetConfig targetConfig) { - System.out.println("Retrieving Arduino Compile Script"); - try { - LFCommand command = arduinoCompileCommand(fileConfig, targetConfig); // Use ProcessBuilder for finer control. - int retCode = 0; - retCode = command.run(context.getCancelIndicator()); - if (retCode != 0 && context.getMode() == LFGeneratorContext.Mode.STANDALONE) { - errorReporter.reportError("arduino-cli failed with error code " + retCode); - throw new IOException("arduino-cli failure"); - } - } catch (IOException e){ - Exceptions.sneakyThrow(e); + /** + * Compiles (and possibly auto-flashes) an Arduino program once code generation is completed. + * + * @param fileConfig + * @param targetConfig + */ + public void buildArduino(FileConfig fileConfig, TargetConfig targetConfig) { + System.out.println("Retrieving Arduino Compile Script"); + try { + LFCommand command = + arduinoCompileCommand(fileConfig, targetConfig); // Use ProcessBuilder for finer control. + int retCode = 0; + retCode = command.run(context.getCancelIndicator()); + if (retCode != 0 && context.getMode() == LFGeneratorContext.Mode.STANDALONE) { + errorReporter.reportError("arduino-cli failed with error code " + retCode); + throw new IOException("arduino-cli failure"); + } + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + System.out.println( + "SUCCESS: Compiling generated code for " + fileConfig.name + " finished with no errors."); + if (targetConfig.platformOptions.flash) { + if (targetConfig.platformOptions.port != null) { + System.out.println("Invoking flash command for Arduino"); + LFCommand flash = + commandFactory.createCommand( + "arduino-cli", + List.of( + "upload", + "-b", + targetConfig.platformOptions.board, + "-p", + targetConfig.platformOptions.port), + fileConfig.getSrcGenPath()); + if (flash == null) { + errorReporter.reportError("Could not create arduino-cli flash command."); } - System.out.println("SUCCESS: Compiling generated code for " + fileConfig.name + " finished with no errors."); - if (targetConfig.platformOptions.flash) { - if (targetConfig.platformOptions.port != null) { - System.out.println("Invoking flash command for Arduino"); - LFCommand flash = commandFactory.createCommand( - "arduino-cli", List.of("upload", "-b", targetConfig.platformOptions.board, "-p", targetConfig.platformOptions.port), fileConfig.getSrcGenPath()); - if (flash == null) { - errorReporter.reportError( - "Could not create arduino-cli flash command." - ); - } - int flashRet = flash.run(); - if (flashRet != 0) { - errorReporter.reportError("arduino-cli flash command failed with error code " + flashRet); - } else { - System.out.println("SUCCESS: Flashed board using arduino-cli"); - } - } else { - errorReporter.reportError("Need to provide a port on which to automatically flash."); - } + int flashRet = flash.run(); + if (flashRet != 0) { + errorReporter.reportError("arduino-cli flash command failed with error code " + flashRet); } else { - System.out.println("********"); - System.out.println("To flash your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); + System.out.println("SUCCESS: Flashed board using arduino-cli"); } + } else { + errorReporter.reportError("Need to provide a port on which to automatically flash."); + } + } else { + System.out.println("********"); + System.out.println( + "To flash your program, run the following command to see information about the board you" + + " plugged in:\n\n" + + "\tarduino-cli board list\n\n" + + "Grab the FQBN and PORT from the command and run the following command in the" + + " generated sources directory:\n\n" + + "\tarduino-cli upload -b -p \n"); } + } } diff --git a/org.lflang/src/org/lflang/util/Averager.java b/org.lflang/src/org/lflang/util/Averager.java index 81349c9db1..f156eafb22 100644 --- a/org.lflang/src/org/lflang/util/Averager.java +++ b/org.lflang/src/org/lflang/util/Averager.java @@ -1,27 +1,26 @@ package org.lflang.util; import java.util.Arrays; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; /** Average asynchronously reported numbers and do something with them. */ public class Averager { - private final int n; - private final int[] reports; + private final int n; + private final int[] reports; - /** Create an averager of reports from {@code n} processes. */ - public Averager(int n) { - this.n = n; - reports = new int[n]; - } + /** Create an averager of reports from {@code n} processes. */ + public Averager(int n) { + this.n = n; + reports = new int[n]; + } - /** - * Receive {@code x} from process {@code id} and invoke {@code callback} - * on the mean of the numbers most recently reported by the processes. - */ - public synchronized void report(int id, int x, Procedure1 callback) { - assert 0 <= id && id < n; - reports[id] = x; - callback.apply(Arrays.stream(reports).sum() / n); - } + /** + * Receive {@code x} from process {@code id} and invoke {@code callback} on the mean of the + * numbers most recently reported by the processes. + */ + public synchronized void report(int id, int x, Procedure1 callback) { + assert 0 <= id && id < n; + reports[id] = x; + callback.apply(Arrays.stream(reports).sum() / n); + } } diff --git a/org.lflang/src/org/lflang/util/CollectionUtil.java b/org.lflang/src/org/lflang/util/CollectionUtil.java index 221cbc68ec..8510856c78 100644 --- a/org.lflang/src/org/lflang/util/CollectionUtil.java +++ b/org.lflang/src/org/lflang/util/CollectionUtil.java @@ -14,176 +14,159 @@ /** * Utilities to manipulate collections. * - *

    Most of these methods are using specialized collection - * implementations (possibly unmodifiable) for small collection - * sizes. No guarantee is made on the mutability of the collections - * returned from these functions, meaning, callers should always - * assume they are unmodifiable. Functions that take a collection - * parameter as input to produce a new one with a transformation - * require the input collection to have been obtained from one of - * the utility functions of this class in the first place. + *

    Most of these methods are using specialized collection implementations (possibly unmodifiable) + * for small collection sizes. No guarantee is made on the mutability of the collections returned + * from these functions, meaning, callers should always assume they are unmodifiable. Functions that + * take a collection parameter as input to produce a new one with a transformation require the input + * collection to have been obtained from one of the utility functions of this class in the first + * place. */ public class CollectionUtil { - /** - * Returns a set which contains the elements of the given - * set plus the given element. The returned set should be - * considered unmodifiable. - * - * @param set initial set, nullable - * @param t new element - * @param Type of elements - * @return A new set, or the same - */ - public static Set plus(Set set, T t) { - if (set == null || set.isEmpty()) { - return Set.of(t); - } else if (set.size() == 1) { - if (set.contains(t)) { - return set; - } - // make mutable - set = new LinkedHashSet<>(set); - } // else it's already mutable. - - set.add(t); + /** + * Returns a set which contains the elements of the given set plus the given element. The returned + * set should be considered unmodifiable. + * + * @param set initial set, nullable + * @param t new element + * @param Type of elements + * @return A new set, or the same + */ + public static Set plus(Set set, T t) { + if (set == null || set.isEmpty()) { + return Set.of(t); + } else if (set.size() == 1) { + if (set.contains(t)) { return set; + } + // make mutable + set = new LinkedHashSet<>(set); + } // else it's already mutable. + + set.add(t); + return set; + } + + public static Map plus(Map map, K k, V v) { + if (map == null || map.isEmpty()) { + return Collections.singletonMap(k, v); + } else if (map.size() == 1) { + Entry e = map.entrySet().iterator().next(); + if (e.getKey().equals(k)) { + return Map.of(k, v); + } + // make mutable + map = new LinkedHashMap<>(map); + } // else it's already mutable. + + map.put(k, v); + return map; + } + + /** + * Remove the given value from all the sets that are values in the given map. Use this if the + * values of the map (the sets) were build with {@link #plus(Set, Object)}. + * + *

    In {@link org.lflang.graph.DirectedGraph}, this is used to properly remove nodes from a + * graph. There, we use maps to represent edges, where a value in a map is a set of nodes adjacent + * to the key for that value. Hence, when a node is removed, it needs to be removed not just as a + * key, but it also needs to be removed from the neighbors sets of any other keys that may contain + * it. + * + * @param map A modifiable map + * @param valueToRemove Value to remove + */ + public static void removeFromValues(Map> map, V valueToRemove) { + mapValuesInPlace(map, set -> minus(set, valueToRemove)); + } + + /** + * Apply a transform to the values of the map. If the mapping function returns null, the entry is + * removed. + */ + private static void mapValuesInPlace(Map map, Function mapper) { + Iterator> iterator = map.entrySet().iterator(); + while (iterator.hasNext()) { + Entry e = iterator.next(); + V existing = e.getValue(); + V mapped = mapper.apply(existing); + if (mapped == null) { + iterator.remove(); + } else if (mapped != existing) { + e.setValue(mapped); + } } - - - public static Map plus(Map map, K k, V v) { - if (map == null || map.isEmpty()) { - return Collections.singletonMap(k, v); - } else if (map.size() == 1) { - Entry e = map.entrySet().iterator().next(); - if (e.getKey().equals(k)) { - return Map.of(k, v); - } - // make mutable - map = new LinkedHashMap<>(map); - } // else it's already mutable. - - map.put(k, v); - return map; + } + + /** + * Returns a set that contains the elements of the given set minus one element. An empty set is + * considered empty. + */ + public static Set minus(Set set, T eltToRemove) { + if (set instanceof LinkedHashSet) { + set.remove(eltToRemove); + return set; } - - /** - * Remove the given value from all the sets that are values - * in the given map. Use this if the values of the map (the - * sets) were build with {@link #plus(Set, Object)}. - *

    - * In {@link org.lflang.graph.DirectedGraph}, this is used - * to properly remove nodes from a graph. There, we use - * maps to represent edges, where a value in a map is a - * set of nodes adjacent to the key for that value. - * Hence, when a node is removed, it needs to be removed - * not just as a key, but it also needs to be removed - * from the neighbors sets of any other keys that may contain it. - * - * @param map A modifiable map - * @param valueToRemove Value to remove - */ - public static void removeFromValues(Map> map, V valueToRemove) { - mapValuesInPlace(map, set -> minus(set, valueToRemove)); + if (set == null || set.isEmpty()) { + return Collections.emptySet(); + } else if (set.size() == 1) { + return set.contains(eltToRemove) ? Collections.emptySet() : set; } - - - /** - * Apply a transform to the values of the map. If the mapping - * function returns null, the entry is removed. - */ - private static void mapValuesInPlace(Map map, Function mapper) { - Iterator> iterator = map.entrySet().iterator(); - while (iterator.hasNext()) { - Entry e = iterator.next(); - V existing = e.getValue(); - V mapped = mapper.apply(existing); - if (mapped == null) { - iterator.remove(); - } else if (mapped != existing) { - e.setValue(mapped); - } - } + throw new AssertionError("should be unreachable"); + } + + /** + * Returns a map that is identical to the original map, except the value for key {@code k} is + * transformed using the given function. The transformation function takes the key and current + * value (null if the key is not present) as inputs, and returns the new value to associate to the + * key (null if the mapping should be removed). + * + * @see Map#compute(Object, BiFunction) + */ + public static Map compute(Map map, K k, BiFunction computation) { + if (map == null || map.isEmpty()) { + return Collections.singletonMap(k, computation.apply(k, null)); + } else if (map.size() == 1) { + Entry e = map.entrySet().iterator().next(); + if (e.getKey().equals(k)) { + return Collections.singletonMap(k, computation.apply(k, e.getValue())); + } + // make mutable + map = new LinkedHashMap<>(map); + } // else it's already mutable. + + map.compute(k, computation); + return map; + } + + /** + * Returns a copy of the set. The returned set should be considered unmodifiable. + * + * @param set initial set, nullable + * @param Type of elements + * @return A new set, or the same + */ + public static Set copy(Set set) { + if (set == null || set.size() <= 1) { + return set; // it's unmodifiable + } else { + return new LinkedHashSet<>(set); } - - - /** - * Returns a set that contains the elements of the given - * set minus one element. An empty set is considered empty. - */ - public static Set minus(Set set, T eltToRemove) { - if (set instanceof LinkedHashSet) { - set.remove(eltToRemove); - return set; - } - - if (set == null || set.isEmpty()) { - return Collections.emptySet(); - } else if (set.size() == 1) { - return set.contains(eltToRemove) ? Collections.emptySet() : set; - } - throw new AssertionError("should be unreachable"); + } + + /** + * Returns an immutable Set that contains all argument values. Duplicate elements are removed + * without error (contrary to {@link Set#of()} and friends). + */ + @SafeVarargs + public static Set immutableSetOf(T first, T... rest) { + if (rest.length == 0) { + return Set.of(first); } - - - /** - * Returns a map that is identical to the original map, - * except the value for key {@code k} is transformed using - * the given function. The transformation function takes the - * key and current value (null if the key is not present) as inputs, - * and returns the new value to associate to the key (null if the mapping should be removed). - * - * @see Map#compute(Object, BiFunction) - */ - public static Map compute(Map map, K k, BiFunction computation) { - if (map == null || map.isEmpty()) { - return Collections.singletonMap(k, computation.apply(k, null)); - } else if (map.size() == 1) { - Entry e = map.entrySet().iterator().next(); - if (e.getKey().equals(k)) { - return Collections.singletonMap(k, computation.apply(k, e.getValue())); - } - // make mutable - map = new LinkedHashMap<>(map); - } // else it's already mutable. - - map.compute(k, computation); - return map; - } - - - /** - * Returns a copy of the set. The returned set should be - * considered unmodifiable. - * - * @param set initial set, nullable - * @param Type of elements - * @return A new set, or the same - */ - public static Set copy(Set set) { - if (set == null || set.size() <= 1) { - return set; // it's unmodifiable - } else { - return new LinkedHashSet<>(set); - } - } - - - /** - * Returns an immutable Set that contains all argument values. - * Duplicate elements are removed without error (contrary - * to {@link Set#of()} and friends). - */ - @SafeVarargs - public static Set immutableSetOf(T first, T... rest) { - if (rest.length == 0) { - return Set.of(first); - } - Set result = new LinkedHashSet<>(); - result.add(first); - result.addAll(Arrays.asList(rest)); - return result; - } - + Set result = new LinkedHashSet<>(); + result.add(first); + result.addAll(Arrays.asList(rest)); + return result; + } } diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/src/org/lflang/util/FileUtil.java index eb2550127e..e46a30d501 100644 --- a/org.lflang/src/org/lflang/util/FileUtil.java +++ b/org.lflang/src/org/lflang/util/FileUtil.java @@ -23,9 +23,7 @@ import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -35,890 +33,906 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.util.RuntimeIOException; - import org.lflang.ErrorReporter; import org.lflang.FileConfig; public class FileUtil { - /** - * Return the name of the file excluding its file extension. - * @param file A Path object - * @return The name of the file excluding its file extension. - */ - public static String nameWithoutExtension(Path file) { - String name = file.getFileName().toString(); - int idx = name.lastIndexOf('.'); - return idx < 0 ? name : name.substring(0, idx); - } - - /** - * Return the name of the file associated with the given resource, - * excluding its file extension. - * @param r Any {@code Resource}. - * @return The name of the file associated with the given resource, - * excluding its file extension. - * @throws IOException If the resource has an invalid URI. - */ - public static String nameWithoutExtension(Resource r) throws IOException { - return nameWithoutExtension(toPath(r)); - } - - /** - * Return a java.nio.Path object corresponding to the given URI. - * @throws IOException If the given URI is invalid. - */ - public static Path toPath(URI uri) throws IOException { - return Paths.get(toIPath(uri).toFile().getAbsolutePath()); - } - - /** - * Return a java.nio.Path object corresponding to the given Resource. - * @throws IOException If the given resource has an invalid URI. - */ - public static Path toPath(Resource resource) throws IOException { - return toPath(resource.getURI()); - } - - /** - * Return an org.eclipse.core.runtime.Path object corresponding to the - * given URI. - * @throws IOException If the given URI is invalid. - */ - public static IPath toIPath(URI uri) throws IOException { - if (uri.isPlatform()) { - IPath path = new org.eclipse.core.runtime.Path(uri.toPlatformString(true)); - if (path.segmentCount() == 1) { - return ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment()).getLocation(); - } else { - return ResourcesPlugin.getWorkspace().getRoot().getFile(path).getLocation(); - } - } else if (uri.isFile()) { - return new org.eclipse.core.runtime.Path(uri.toFileString()); - } else { - throw new IOException("Unrecognized file protocol in URI " + uri); - } - } - - /** - * Convert a given path to a unix-style string. - * - * This ensures that '/' is used instead of '\' as file separator. - */ - public static String toUnixString(Path path) { - return path.toString().replace('\\', '/'); - } - - /** - * Parse the string as file location and return it as URI. - * Supports URIs, plain file paths, and paths relative to a model. - * - * @param path the file location as string. - * @param resource the model resource this file should be resolved relatively. May be null. - * @return the (Java) URI or null if no file can be located. - */ - public static java.net.URI locateFile(String path, Resource resource) { - // Check if path is URL + /** + * Return the name of the file excluding its file extension. + * + * @param file A Path object + * @return The name of the file excluding its file extension. + */ + public static String nameWithoutExtension(Path file) { + String name = file.getFileName().toString(); + int idx = name.lastIndexOf('.'); + return idx < 0 ? name : name.substring(0, idx); + } + + /** + * Return the name of the file associated with the given resource, excluding its file extension. + * + * @param r Any {@code Resource}. + * @return The name of the file associated with the given resource, excluding its file extension. + * @throws IOException If the resource has an invalid URI. + */ + public static String nameWithoutExtension(Resource r) throws IOException { + return nameWithoutExtension(toPath(r)); + } + + /** + * Return a java.nio.Path object corresponding to the given URI. + * + * @throws IOException If the given URI is invalid. + */ + public static Path toPath(URI uri) throws IOException { + return Paths.get(toIPath(uri).toFile().getAbsolutePath()); + } + + /** + * Return a java.nio.Path object corresponding to the given Resource. + * + * @throws IOException If the given resource has an invalid URI. + */ + public static Path toPath(Resource resource) throws IOException { + return toPath(resource.getURI()); + } + + /** + * Return an org.eclipse.core.runtime.Path object corresponding to the given URI. + * + * @throws IOException If the given URI is invalid. + */ + public static IPath toIPath(URI uri) throws IOException { + if (uri.isPlatform()) { + IPath path = new org.eclipse.core.runtime.Path(uri.toPlatformString(true)); + if (path.segmentCount() == 1) { + return ResourcesPlugin.getWorkspace() + .getRoot() + .getProject(path.lastSegment()) + .getLocation(); + } else { + return ResourcesPlugin.getWorkspace().getRoot().getFile(path).getLocation(); + } + } else if (uri.isFile()) { + return new org.eclipse.core.runtime.Path(uri.toFileString()); + } else { + throw new IOException("Unrecognized file protocol in URI " + uri); + } + } + + /** + * Convert a given path to a unix-style string. + * + *

    This ensures that '/' is used instead of '\' as file separator. + */ + public static String toUnixString(Path path) { + return path.toString().replace('\\', '/'); + } + + /** + * Parse the string as file location and return it as URI. Supports URIs, plain file paths, and + * paths relative to a model. + * + * @param path the file location as string. + * @param resource the model resource this file should be resolved relatively. May be null. + * @return the (Java) URI or null if no file can be located. + */ + public static java.net.URI locateFile(String path, Resource resource) { + // Check if path is URL + try { + var uri = new java.net.URI(path); + if (uri.getScheme() != null) { // check if path was meant to be a URI + return uri; + } + } catch (Exception e) { + // nothing + } + // Check if path exists as it is + File file = new File(path); + if (file.exists()) { + try { + return file.toURI(); + } catch (Exception e) { + // nothing + } + } + // Check if path is relative to LF file + if (resource != null) { + URI eURI = resource.getURI(); + if (eURI != null) { + java.net.URI sourceURI = null; try { - var uri = new java.net.URI(path); - if(uri.getScheme() != null) { // check if path was meant to be a URI - return uri; - } + if (eURI.isFile()) { + sourceURI = new java.net.URI(eURI.toString()); + sourceURI = + new java.net.URI( + sourceURI.getScheme(), + null, + sourceURI.getPath().substring(0, sourceURI.getPath().lastIndexOf("/")), + null); + } else if (eURI.isPlatformResource()) { + IResource iFile = + ResourcesPlugin.getWorkspace().getRoot().findMember(eURI.toPlatformString(true)); + sourceURI = + iFile != null ? iFile.getRawLocation().toFile().getParentFile().toURI() : null; + } + if (sourceURI != null) { + return sourceURI.resolve(path); + } } catch (Exception e) { - // nothing - } - // Check if path exists as it is - File file = new File(path); - if (file.exists()) { - try { - return file.toURI(); - } catch (Exception e) { - // nothing - } - } - // Check if path is relative to LF file - if (resource != null) { - URI eURI = resource.getURI(); - if (eURI != null) { - java.net.URI sourceURI = null; - try { - if (eURI.isFile()) { - sourceURI = new java.net.URI(eURI.toString()); - sourceURI = new java.net.URI(sourceURI.getScheme(), null, - sourceURI.getPath().substring(0, sourceURI.getPath().lastIndexOf("/")), null); - } else if (eURI.isPlatformResource()) { - IResource iFile = ResourcesPlugin.getWorkspace().getRoot().findMember(eURI.toPlatformString(true)); - sourceURI = iFile != null ? iFile.getRawLocation().toFile().getParentFile().toURI() : null; - } - if (sourceURI != null) { - return sourceURI.resolve(path); - } - } catch (Exception e) { - // nothing - } + // nothing + } + } + } + // fail + return null; + } + + /** + * Recursively copy the contents of the given source directory into the given destination + * directory. Existing files of the destination may be overwritten. + * + * @param srcDir The source directory path. + * @param dstDir The destination directory path. + * @param skipIfUnchanged If true, don't overwrite anything in the destination if its content + * would not be changed. + * @throws IOException If the operation fails. + */ + public static void copyDirectoryContents( + final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + try (Stream stream = Files.walk(srcDir)) { + stream.forEach( + source -> { + // Handling checked exceptions in lambda expressions is + // hard. See + // https://www.baeldung.com/java-lambda-exceptions#handling-checked-exceptions. + // An alternative would be to create a custom Consumer interface and use that + // here. + if (Files.isRegularFile(source)) { // do not copy directories + try { + Path target = dstDir.resolve(srcDir.relativize(source)); + Files.createDirectories(target.getParent()); + copyFile(source, target, skipIfUnchanged); + } catch (IOException e) { + throw new RuntimeIOException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } } - } - // fail + }); + } + } + + /** + * Copy the given source directory into the given destination directory. For example, if the + * source directory is {@code foo/bar} and the destination is {@code baz}, then copies of the + * contents of {@code foo/bar} will be located in {@code baz/bar}. + * + * @param srcDir The source directory path. + * @param dstDir The destination directory path. + * @param skipIfUnchanged If true, don't overwrite anything in the destination if its content + * would not be changed. + * @throws IOException If the operation fails. + */ + public static void copyDirectory( + final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + copyDirectoryContents(srcDir, dstDir.resolve(srcDir.getFileName()), skipIfUnchanged); + } + + /** + * Recursively copy the contents of the given source directory into the given destination + * directory. Existing files of the destination may be overwritten. + * + * @param srcDir The directory to copy files from. + * @param dstDir The directory to copy files to. + * @throws IOException if copy fails. + */ + public static void copyDirectoryContents(final Path srcDir, final Path dstDir) + throws IOException { + copyDirectoryContents(srcDir, dstDir, false); + } + + /** + * Copy a given source file to a given destination file. + * + *

    This also creates new directories on the path to {@code dstFile} that do not yet exist. + * + * @param srcFile The source file path. + * @param dstFile The destination file path. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not + * be changed. + * @throws IOException If the operation fails. + */ + public static void copyFile(Path srcFile, Path dstFile, boolean skipIfUnchanged) + throws IOException { + BufferedInputStream stream = new BufferedInputStream(new FileInputStream(srcFile.toFile())); + try (stream) { + copyInputStream(stream, dstFile, skipIfUnchanged); + } + } + + /** + * Copy a given source file to a given destination file. + * + *

    This also creates new directories for any directories on the path to {@code dstFile} that do + * not yet exist. + * + * @param srcFile The source file path. + * @param dstFile The destination file path. + * @throws IOException if copy fails. + */ + public static void copyFile(Path srcFile, Path dstFile) throws IOException { + copyFile(srcFile, dstFile, false); + } + + /** + * Find the given {@code file} in the package and return the path to the file that was found; null + * if it was not found. + * + * @param file The file to look for. + * @param dstDir The directory to copy it to. + * @param fileConfig The file configuration that specifies where look for the file. + * @return The path to the file that was found, or null if it was not found. + */ + public static Path findAndCopyFile(String file, Path dstDir, FileConfig fileConfig) { + var path = Paths.get(file); + var found = FileUtil.findInPackage(path, fileConfig); + if (found != null) { + try { + FileUtil.copyFile(found, dstDir.resolve(path.getFileName())); + return found; + } catch (IOException e) { return null; - } - - /** - * Recursively copy the contents of the given source directory into the given destination - * directory. Existing files of the destination may be overwritten. - * - * @param srcDir The source directory path. - * @param dstDir The destination directory path. - * @param skipIfUnchanged If true, don't overwrite anything in the destination if its content - * would not be changed. - * @throws IOException If the operation fails. - */ - public static void copyDirectoryContents(final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { - try (Stream stream = Files.walk(srcDir)) { - stream.forEach(source -> { - // Handling checked exceptions in lambda expressions is - // hard. See - // https://www.baeldung.com/java-lambda-exceptions#handling-checked-exceptions. - // An alternative would be to create a custom Consumer interface and use that - // here. - if (Files.isRegularFile(source)) { // do not copy directories - try { - Path target = dstDir.resolve(srcDir.relativize(source)); - Files.createDirectories(target.getParent()); - copyFile(source, target, skipIfUnchanged); - } catch (IOException e) { - throw new RuntimeIOException(e); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } - } - - /** - * Copy the given source directory into the given destination directory. For example, if the - * source directory is {@code foo/bar} and the destination is {@code baz}, then copies of the - * contents of {@code foo/bar} will be located in {@code baz/bar}. - * @param srcDir The source directory path. - * @param dstDir The destination directory path. - * @param skipIfUnchanged If true, don't overwrite anything in the destination if its content - * would not be changed. - * @throws IOException If the operation fails. - */ - public static void copyDirectory( - final Path srcDir, final Path dstDir, final boolean skipIfUnchanged) throws IOException { - copyDirectoryContents(srcDir, dstDir.resolve(srcDir.getFileName()), skipIfUnchanged); - } - - /** - * Recursively copy the contents of the given source directory into the given destination - * directory. Existing files of the destination may be overwritten. - * - * @param srcDir The directory to copy files from. - * @param dstDir The directory to copy files to. - * @throws IOException if copy fails. - */ - public static void copyDirectoryContents(final Path srcDir, final Path dstDir) throws IOException { - copyDirectoryContents(srcDir, dstDir, false); - } - - /** - * Copy a given source file to a given destination file. - * - * This also creates new directories on the path to {@code dstFile} that do not yet exist. - * - * @param srcFile The source file path. - * @param dstFile The destination file path. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content - * would not be changed. - * @throws IOException If the operation fails. - */ - public static void copyFile(Path srcFile, Path dstFile, boolean skipIfUnchanged) throws IOException { - BufferedInputStream stream = new BufferedInputStream(new FileInputStream(srcFile.toFile())); - try (stream) { - copyInputStream(stream, dstFile, skipIfUnchanged); - } - } - - /** - * Copy a given source file to a given destination file. - * - * This also creates new directories for any directories - * on the path to {@code dstFile} that do not yet exist. - * - * @param srcFile The source file path. - * @param dstFile The destination file path. - * @throws IOException if copy fails. - */ - public static void copyFile(Path srcFile, Path dstFile) throws IOException { - copyFile(srcFile, dstFile, false); - } - - /** - * Find the given {@code file} in the package and return the path to the file that was found; null - * if it was not found. - * - * @param file The file to look for. - * @param dstDir The directory to copy it to. - * @param fileConfig The file configuration that specifies where look for the file. - * @return The path to the file that was found, or null if it was not found. - */ - public static Path findAndCopyFile( - String file, - Path dstDir, - FileConfig fileConfig - ) { - var path = Paths.get(file); - var found = FileUtil.findInPackage(path, fileConfig); - if (found != null) { - try { - FileUtil.copyFile(found, dstDir.resolve(path.getFileName())); - return found; - } catch (IOException e) { - return null; - } - } else { - return null; - } - } - - /** - * Given a list of files or directories, attempt to find each entry based on the given generator - * context and copy it to the destination directory. Entries are searched for in the file system - * first, relative to the source file and relative to the package root. Entries that cannot be - * found in the file system are looked for on the class path. - *

    - * If {@code contentsOnly} is true, then for each entry that is a directory, only its contents - * are copied, not the directory itself. - * For example, if the entry is a directory {@code foo/bar} and the destination is {@code baz}, - * then copies of the contents of {@code foo/bar} will be located directly in {@code baz}. - * If {@code contentsOnly} is false, then copies of the contents of {@code foo/bar} will be - * located in {@code baz/bar}. - * - * @param entries The files or directories to copy from. - * @param dstDir The location to copy the files to. - * @param fileConfig The file configuration that specifies where the find entries the given entries. - * @param errorReporter An error reporter to report problems. - */ - public static void copyFilesOrDirectories( - List entries, - Path dstDir, - FileConfig fileConfig, - ErrorReporter errorReporter, - boolean fileEntriesOnly - ) { - for (String fileOrDirectory : entries) { - var path = Paths.get(fileOrDirectory); - var found = FileUtil.findInPackage(path, fileConfig); - if (found != null) { - try { - if (fileEntriesOnly) { - FileUtil.copyFile(found, dstDir.resolve(path.getFileName())); - } else { - FileUtil.copyFromFileSystem(found, dstDir, false); - } - System.out.println("Copied '" + fileOrDirectory + "' from the file system."); - } catch (IOException e) { - errorReporter.reportError( - "Unable to copy '" + fileOrDirectory + "' from the file system. Reason: " + e.toString() - ); - } - } else { - try { - if (fileEntriesOnly) { - copyFileFromClassPath(fileOrDirectory, dstDir, false); - } else { - FileUtil.copyFromClassPath( - fileOrDirectory, - dstDir, - false, - false - ); - System.out.println("Copied '" + fileOrDirectory + "' from the class path."); - } - } catch(IOException e) { - errorReporter.reportError( - "Unable to copy '" + fileOrDirectory + "' from the class path. Reason: " + e.toString() - ); - } - } - } - } - - /** - * If the given {@code entry} is a file, then copy it into the destination. If the {@code entry} - * is a directory and {@code contentsOnly} is true, then copy its contents to the destination - * directory. If the {@code entry} is a directory and {@code contentsOnly} is true, then copy it - * including its contents to the destination directory. - * - * @param entry A file or directory to copy to the destination directory. - * @param dstDir A directory to copy the entry or its contents to. - * @param contentsOnly If true and {@code entry} is a directory, then copy its contents but not - * the directory itself. - * @throws IOException If the operation fails. - */ - public static void copyFromFileSystem(Path entry, Path dstDir, boolean contentsOnly) throws IOException { - if (Files.isDirectory(entry)) { - if (contentsOnly) { - copyDirectoryContents(entry, dstDir); - } else { - copyDirectory(entry, dstDir, false); - } - } else if (Files.isRegularFile(entry)) { - FileUtil.copyFile(entry, dstDir.resolve(entry.getFileName())); - } else { - throw new IllegalArgumentException("Source is neither a directory nor a regular file."); - } - } - /** - * Copy a given input stream to a destination file. - * - * This also creates new directories for any directories on the destination - * path that do not yet exist. - * - * @param source The source input stream. - * @param destination The destination file path. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would - * not be changed. - * @throws IOException If the operation fails. - */ - private static void copyInputStream(InputStream source, Path destination, boolean skipIfUnchanged) throws IOException { - // Read the stream once and keep a copy of all bytes. This is required as a stream cannot be read twice. - final var bytes = source.readAllBytes(); - final var parent = destination.getParent(); - if (Files.isRegularFile(destination)) { - if (skipIfUnchanged) { - if (Arrays.equals(bytes, Files.readAllBytes(destination))) { - // Abort if the file contents are the same. - return; - } - } else { - // Delete the file exists but the contents don't match. - Files.delete(destination); - } - } else if (Files.isDirectory(destination)) { - deleteDirectory(destination); - } else if (!Files.exists(parent)) { - Files.createDirectories(parent); - } - - Files.write(destination, bytes); - } - - /** - * Look up the given {@code entry} in the classpath. If it is found and is a file, copy it into - * the destination directory. If the entry is not found or not a file, throw an exception. - * - * @param entry A file copy to the destination directory. - * @param dstDir A directory to copy the entry to. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would - * not be changed. - * @throws IOException If the operation failed. - */ - public static void copyFileFromClassPath(final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { - final URL resource = FileConfig.class.getResource(entry); - - if (resource == null) { - throw new TargetResourceNotFoundException(entry); - } + } + } else { + return null; + } + } + + /** + * Given a list of files or directories, attempt to find each entry based on the given generator + * context and copy it to the destination directory. Entries are searched for in the file system + * first, relative to the source file and relative to the package root. Entries that cannot be + * found in the file system are looked for on the class path. + * + *

    If {@code contentsOnly} is true, then for each entry that is a directory, only its contents + * are copied, not the directory itself. For example, if the entry is a directory {@code foo/bar} + * and the destination is {@code baz}, then copies of the contents of {@code foo/bar} will be + * located directly in {@code baz}. If {@code contentsOnly} is false, then copies of the contents + * of {@code foo/bar} will be located in {@code baz/bar}. + * + * @param entries The files or directories to copy from. + * @param dstDir The location to copy the files to. + * @param fileConfig The file configuration that specifies where the find entries the given + * entries. + * @param errorReporter An error reporter to report problems. + */ + public static void copyFilesOrDirectories( + List entries, + Path dstDir, + FileConfig fileConfig, + ErrorReporter errorReporter, + boolean fileEntriesOnly) { + for (String fileOrDirectory : entries) { + var path = Paths.get(fileOrDirectory); + var found = FileUtil.findInPackage(path, fileConfig); + if (found != null) { + try { + if (fileEntriesOnly) { + FileUtil.copyFile(found, dstDir.resolve(path.getFileName())); + } else { + FileUtil.copyFromFileSystem(found, dstDir, false); + } + System.out.println("Copied '" + fileOrDirectory + "' from the file system."); + } catch (IOException e) { + errorReporter.reportError( + "Unable to copy '" + + fileOrDirectory + + "' from the file system. Reason: " + + e.toString()); + } + } else { + try { + if (fileEntriesOnly) { + copyFileFromClassPath(fileOrDirectory, dstDir, false); + } else { + FileUtil.copyFromClassPath(fileOrDirectory, dstDir, false, false); + System.out.println("Copied '" + fileOrDirectory + "' from the class path."); + } + } catch (IOException e) { + errorReporter.reportError( + "Unable to copy '" + + fileOrDirectory + + "' from the class path. Reason: " + + e.toString()); + } + } + } + } + + /** + * If the given {@code entry} is a file, then copy it into the destination. If the {@code entry} + * is a directory and {@code contentsOnly} is true, then copy its contents to the destination + * directory. If the {@code entry} is a directory and {@code contentsOnly} is true, then copy it + * including its contents to the destination directory. + * + * @param entry A file or directory to copy to the destination directory. + * @param dstDir A directory to copy the entry or its contents to. + * @param contentsOnly If true and {@code entry} is a directory, then copy its contents but not + * the directory itself. + * @throws IOException If the operation fails. + */ + public static void copyFromFileSystem(Path entry, Path dstDir, boolean contentsOnly) + throws IOException { + if (Files.isDirectory(entry)) { + if (contentsOnly) { + copyDirectoryContents(entry, dstDir); + } else { + copyDirectory(entry, dstDir, false); + } + } else if (Files.isRegularFile(entry)) { + FileUtil.copyFile(entry, dstDir.resolve(entry.getFileName())); + } else { + throw new IllegalArgumentException("Source is neither a directory nor a regular file."); + } + } + /** + * Copy a given input stream to a destination file. + * + *

    This also creates new directories for any directories on the destination path that do not + * yet exist. + * + * @param source The source input stream. + * @param destination The destination file path. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not + * be changed. + * @throws IOException If the operation fails. + */ + private static void copyInputStream(InputStream source, Path destination, boolean skipIfUnchanged) + throws IOException { + // Read the stream once and keep a copy of all bytes. This is required as a stream cannot be + // read twice. + final var bytes = source.readAllBytes(); + final var parent = destination.getParent(); + if (Files.isRegularFile(destination)) { + if (skipIfUnchanged) { + if (Arrays.equals(bytes, Files.readAllBytes(destination))) { + // Abort if the file contents are the same. + return; + } + } else { + // Delete the file exists but the contents don't match. + Files.delete(destination); + } + } else if (Files.isDirectory(destination)) { + deleteDirectory(destination); + } else if (!Files.exists(parent)) { + Files.createDirectories(parent); + } + + Files.write(destination, bytes); + } + + /** + * Look up the given {@code entry} in the classpath. If it is found and is a file, copy it into + * the destination directory. If the entry is not found or not a file, throw an exception. + * + * @param entry A file copy to the destination directory. + * @param dstDir A directory to copy the entry to. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not + * be changed. + * @throws IOException If the operation failed. + */ + public static void copyFileFromClassPath( + final String entry, final Path dstDir, final boolean skipIfUnchanged) throws IOException { + final URL resource = FileConfig.class.getResource(entry); + + if (resource == null) { + throw new TargetResourceNotFoundException(entry); + } + + final URLConnection connection = resource.openConnection(); + if (connection instanceof JarURLConnection) { + if (!copyFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged)) { + throw new IOException("'" + entry + "' is not a file"); + } + } else { + try { + Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); + copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); + } catch (URISyntaxException e) { + // This should never happen as toFileURL should always return a valid URL + throw new IOException("Unexpected error while resolving " + entry + " on the classpath"); + } + } + } + + /** + * Look up the given {@code entry} in the classpath. If it is a file, copy it into the destination + * directory. If the {@code entry} is a directory and {@code contentsOnly} is true, then copy its + * contents to the destination directory. If the {@code entry} is a directory and {@code + * contentsOnly} is true, then copy it including its contents to the destination directory. + * + *

    This also creates new directories for any directories on the destination path that do not + * yet exist. + * + * @param entry The entry to be found on the class path and copied to the given destination. + * @param dstDir The file system path that found files are to be copied to. + * @param skipIfUnchanged If true, don't overwrite the file or directory if its content would not + * be changed + * @param contentsOnly If true and the entry is a directory, then copy its contents but not the + * directory itself. + * @throws IOException If the operation failed. + */ + public static void copyFromClassPath( + final String entry, + final Path dstDir, + final boolean skipIfUnchanged, + final boolean contentsOnly) + throws IOException { + final URL resource = FileConfig.class.getResource(entry); + + if (resource == null) { + throw new TargetResourceNotFoundException(entry); + } + + final URLConnection connection = resource.openConnection(); + if (connection instanceof JarURLConnection) { + boolean copiedFiles = + copyFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged, contentsOnly); + if (!copiedFiles) { + throw new TargetResourceNotFoundException(entry); + } + } else { + try { + Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); + if (path.toFile().isDirectory()) { + if (contentsOnly) { + copyDirectoryContents(path, dstDir, skipIfUnchanged); + } else { + copyDirectory(path, dstDir, skipIfUnchanged); + } - final URLConnection connection = resource.openConnection(); - if (connection instanceof JarURLConnection) { - if (!copyFileFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged)) { - throw new IOException("'" + entry + "' is not a file"); - } } else { - try { - Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); - copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); - } catch(URISyntaxException e) { - // This should never happen as toFileURL should always return a valid URL - throw new IOException("Unexpected error while resolving " + entry + " on the classpath"); - } - } - } - - /** - * Look up the given {@code entry} in the classpath. If it is a file, copy it into the destination - * directory. - * If the {@code entry} is a directory and {@code contentsOnly} is true, then copy its contents - * to the destination directory. If the {@code entry} is a directory and {@code contentsOnly} is - * true, then copy it including its contents to the destination directory. - * - * This also creates new directories for any directories on the destination - * path that do not yet exist. - * - * @param entry The entry to be found on the class path and copied to the given destination. - * @param dstDir The file system path that found files are to be copied to. - * @param skipIfUnchanged If true, don't overwrite the file or directory if its content would not be changed - * @param contentsOnly If true and the entry is a directory, then copy its contents but not the directory itself. - * @throws IOException If the operation failed. - */ - public static void copyFromClassPath( - final String entry, - final Path dstDir, - final boolean skipIfUnchanged, - final boolean contentsOnly - ) throws IOException { - final URL resource = FileConfig.class.getResource(entry); - - if (resource == null) { - throw new TargetResourceNotFoundException(entry); - } - - final URLConnection connection = resource.openConnection(); - if (connection instanceof JarURLConnection) { - boolean copiedFiles = copyFromJar((JarURLConnection) connection, dstDir, skipIfUnchanged, contentsOnly); - if (!copiedFiles) { - throw new TargetResourceNotFoundException(entry); - } + copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); + } + } catch (URISyntaxException e) { + // This should never happen as toFileURL should always return a valid URL + throw new IOException("Unexpected error while resolving " + entry + " on the classpath"); + } + } + } + + /** + * Return true if the given connection points to a file. + * + * @param connection A connection to a JAR file. + * @throws IOException If the connection is faulty. + */ + private static boolean isFileInJar(JarURLConnection connection) throws IOException { + return connection.getJarFile().stream() + .anyMatch(it -> it.getName().equals(connection.getEntryName())); + } + + /** + * Given a JAR file and a {@code srcFile} entry, copy it into the given destination directory. + * + * @param jar The JAR file from which to copy {@code srcFile}. + * @param srcFile The source file to copy from the given {@code jar}. + * @param dstDir The directory to top the source file into. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would * not + * be changed. + * @throws IOException If the operation fails. + */ + private static void copyFileFromJar( + JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { + var entry = jar.getJarEntry(srcFile); + var filename = Paths.get(entry.getName()).getFileName(); + InputStream is = jar.getInputStream(entry); + try (is) { + copyInputStream(is, dstDir.resolve(filename), skipIfUnchanged); + } + } + + /** + * Copy the contents from an entry in a JAR to destination directory in the filesystem. The entry + * may be a file, in which case it will be copied under the same name into the destination + * directory. If the entry is a directory, then if {@code contentsOnly} is true, only the contents + * of the directory will be copied into the destination directory (not the directory itself). A + * directory will be copied as a whole, including its contents, if {@code contentsOnly} is false. + * + *

    This method should only be used in standalone mode (lfc). + * + *

    This also creates new directories for any directories on the destination path that do not + * yet exist. + * + * @param connection a URLConnection to the source entry within the jar + * @param dstDir The file system path that entries are copied to. + * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed. + * @param contentsOnly If true, and the connection points to a directory, copy its contents only + * (not the directory itself). + * @return true if any files were copied + * @throws IOException If the given source cannot be copied. + */ + private static boolean copyFromJar( + JarURLConnection connection, + Path dstDir, + final boolean skipIfUnchanged, + final boolean contentsOnly) + throws IOException { + + if (copyFileFromJar(connection, dstDir, skipIfUnchanged)) { + return true; + } + return copyDirectoryFromJar(connection, dstDir, skipIfUnchanged, contentsOnly); + } + + /** + * Given a connection to a JAR file that points to an entry that is a directory, recursively copy + * all entries located in that directory into the given {@code dstDir}. + * + *

    If {@code contentsOnly} is true, only the contents of the directory will be copied into the + * destination directory (not the directory itself). The directory will be copied as a whole, + * including its contents, if {@code contentsOnly} is false. + * + * @param connection A connection to a JAR file that points to a directory entry. + * @param dstDir The destination directory to copy the matching entries to. + * @param skipIfUnchanged + * @param contentsOnly + * @return + * @throws IOException + */ + private static boolean copyDirectoryFromJar( + JarURLConnection connection, + Path dstDir, + final boolean skipIfUnchanged, + final boolean contentsOnly) + throws IOException { + final JarFile jar = connection.getJarFile(); + final String source = connection.getEntryName(); + + boolean copiedFiles = false; + if (!contentsOnly) { + dstDir = dstDir.resolve(Paths.get(source).getFileName()); + } + // Iterate all entries in the jar file. + for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { + final JarEntry entry = e.nextElement(); + final String entryName = entry.getName(); + if (entryName.startsWith(source)) { + String filename = entry.getName().substring(source.length() + 1); + Path currentFile = dstDir.resolve(filename); + if (entry.isDirectory()) { + Files.createDirectories(currentFile); } else { - try { - Path path = Paths.get(FileLocator.toFileURL(resource).toURI()); - if (path.toFile().isDirectory()) { - if (contentsOnly) { - copyDirectoryContents(path, dstDir, skipIfUnchanged); - } else { - copyDirectory(path, dstDir, skipIfUnchanged); - } - - } else { - copyFile(path, dstDir.resolve(path.getFileName()), skipIfUnchanged); - } - } catch(URISyntaxException e) { - // This should never happen as toFileURL should always return a valid URL - throw new IOException("Unexpected error while resolving " + entry + " on the classpath"); - } - } - } - - /** - * Return true if the given connection points to a file. - * @param connection A connection to a JAR file. - * @throws IOException If the connection is faulty. - */ - private static boolean isFileInJar(JarURLConnection connection) throws IOException { - return connection.getJarFile().stream().anyMatch( - it -> it.getName().equals(connection.getEntryName()) - ); - } - - /** - * Given a JAR file and a {@code srcFile} entry, copy it into the given destination directory. - * - * @param jar The JAR file from which to copy {@code srcFile}. - * @param srcFile The source file to copy from the given {@code jar}. - * @param dstDir The directory to top the source file into. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would - * * not be changed. - * @throws IOException If the operation fails. - */ - private static void copyFileFromJar(JarFile jar, String srcFile, Path dstDir, boolean skipIfUnchanged) throws IOException { - var entry = jar.getJarEntry(srcFile); - var filename = Paths.get(entry.getName()).getFileName(); - InputStream is = jar.getInputStream(entry); - try (is) { - copyInputStream(is, dstDir.resolve(filename), skipIfUnchanged); - } - } - - /** - * Copy the contents from an entry in a JAR to destination directory in the filesystem. The entry - * may be a file, in which case it will be copied under the same name into the destination - * directory. If the entry is a directory, then if {@code contentsOnly} is true, only the - * contents of the directory will be copied into the destination directory (not the directory - * itself). A directory will be copied as a whole, including its contents, if - * {@code contentsOnly} is false. - * - * This method should only be used in standalone mode (lfc). - * - * This also creates new directories for any directories on - * the destination path that do not yet exist. - * - * @param connection a URLConnection to the source entry within the jar - * @param dstDir The file system path that entries are copied to. - * @param skipIfUnchanged If true, don't overwrite the file if its content would not be changed. - * @param contentsOnly If true, and the connection points to a directory, copy its contents only - * (not the directory itself). - * @return true if any files were copied - * @throws IOException If the given source cannot be copied. - */ - private static boolean copyFromJar( - JarURLConnection connection, - Path dstDir, - final boolean skipIfUnchanged, - final boolean contentsOnly - ) throws IOException { - - if (copyFileFromJar(connection, dstDir, skipIfUnchanged)) { - return true; - } - return copyDirectoryFromJar(connection, dstDir, skipIfUnchanged, contentsOnly); - } - - /** - * Given a connection to a JAR file that points to an entry that is a directory, recursively copy - * all entries located in that directory into the given {@code dstDir}. - *

    - * If {@code contentsOnly} is true, only the contents of the directory will be copied into the - * destination directory (not the directory itself). The directory will be copied as a whole, - * including its contents, if {@code contentsOnly} is false. - * @param connection A connection to a JAR file that points to a directory entry. - * @param dstDir The destination directory to copy the matching entries to. - * @param skipIfUnchanged - * @param contentsOnly - * @return - * @throws IOException - */ - private static boolean copyDirectoryFromJar(JarURLConnection connection, - Path dstDir, - final boolean skipIfUnchanged, - final boolean contentsOnly) throws IOException { - final JarFile jar = connection.getJarFile(); - final String source = connection.getEntryName(); - - boolean copiedFiles = false; - if (!contentsOnly) { - dstDir = dstDir.resolve(Paths.get(source).getFileName()); - } - // Iterate all entries in the jar file. - for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { - final JarEntry entry = e.nextElement(); - final String entryName = entry.getName(); - if (entryName.startsWith(source)) { - String filename = entry.getName().substring(source.length() + 1); - Path currentFile = dstDir.resolve(filename); - if (entry.isDirectory()) { - Files.createDirectories(currentFile); - } else { - InputStream is = jar.getInputStream(entry); - try (is) { - copyInputStream(is, currentFile, skipIfUnchanged); - copiedFiles = true; - } - } - } - } - return copiedFiles; - } - - /** - * Given a connection to a JAR file that points to an entry that is a file, copy the file into the - * given {@code dstDir}. - * @param connection A connection to a JAR file that points to a directory entry. - * @param dstDir The destination directory to copy the file to. - * @param skipIfUnchanged - * @return {@code true} the connection entry is a file, and it was copied successfully; - * {@code false} if the connection entry is not a file and the copy operation was aborted. - * @throws IOException If the operation failed. - */ - private static boolean copyFileFromJar( - JarURLConnection connection, - Path dstDir, - final boolean skipIfUnchanged - ) throws IOException { - final JarFile jar = connection.getJarFile(); - final String source = connection.getEntryName(); - - if (!isFileInJar(connection)) { - return false; - } - copyFileFromJar(jar, source, dstDir, skipIfUnchanged); - - return true; - } - - /** - * Delete unused Files from Arduino-CLI based compilation. - * - * Arduino-CLI (the build system) uses lazy compilation (i.e. compiles every file recursively from - * a source directory). This does the work of CMake by explicitly deleting files that - * shouldn't get compiled by the CLI. Generally, we delete all CMake artifacts and multithreaded - * support files (including semaphores and thread folders) - * - * @param dir The folder to search for folders and files to delete. - * @throws IOException If the given folder and unneeded files cannot be deleted. - */ - public static void arduinoDeleteHelper(Path dir, boolean threadingOn) throws IOException { - deleteDirectory(dir.resolve("core/federated")); // TODO: Add Federated Support to Arduino - deleteDirectory(dir.resolve("include/core/federated")); // TODO: Add Federated Support to Arduino - - if (!threadingOn) { - deleteDirectory(dir.resolve("core/threaded")); // No Threaded Support for Arduino - deleteDirectory(dir.resolve("include/core/threaded")); // No Threaded Support for Arduino - deleteDirectory(dir.resolve("core/platform/arduino_mbed")); // No Threaded Support for Arduino - } - - List allPaths = Files.walk(dir) - .sorted(Comparator.reverseOrder()) - .toList(); - for (Path path : allPaths) { - String toCheck = path.toString().toLowerCase(); - if (toCheck.contains("cmake")) { - Files.delete(path); - } - } - } - - /** - * Helper function for getting the string representation of the relative path - * to take to get from one file (currPath) to get to the other (fileName). - * - * Generally, this is useful for converting includes to have relative pathing when - * you lack access to adding additional include paths when compiling. - * - * @param fileName File to search for. - * @param currPath The current path to the file whose include statements we are modifying. - * @param fileStringToFilePath Mapping of File Names to their paths. - */ - private static String fileNameMatchConverter(String fileName, Path currPath, Map fileStringToFilePath) - throws NullPointerException { - // First get the child file - int lastPath = fileName.lastIndexOf(File.separator); - if (lastPath != -1){ - fileName = fileName.substring(lastPath+1); - } - Path p = fileStringToFilePath.get(fileName); - if(p == null) { - return "#include \"" + fileName + "\""; - } - String relativePath = currPath.getParent().relativize(p).toString(); - return "#include \"" + relativePath + "\""; - } - - /** - * Return true if the given path points to a C file, false otherwise. - */ - public static boolean isCFile(Path path) { - String fileName = path.getFileName().toString(); - return fileName.endsWith(".c") || fileName.endsWith(".cpp") || fileName.endsWith(".h"); - } - - /** - * Convert all includes recursively inside files within a specified folder to relative links - * - * @param dir The folder to search for includes to change. - * @throws IOException If the given set of files cannot be relativized. - */ - public static void relativeIncludeHelper(Path dir, Path includePath) throws IOException { - System.out.println("Relativizing all includes in " + dir.toString()); - List includePaths = Files.walk(includePath) + InputStream is = jar.getInputStream(entry); + try (is) { + copyInputStream(is, currentFile, skipIfUnchanged); + copiedFiles = true; + } + } + } + } + return copiedFiles; + } + + /** + * Given a connection to a JAR file that points to an entry that is a file, copy the file into the + * given {@code dstDir}. + * + * @param connection A connection to a JAR file that points to a directory entry. + * @param dstDir The destination directory to copy the file to. + * @param skipIfUnchanged + * @return {@code true} the connection entry is a file, and it was copied successfully; {@code + * false} if the connection entry is not a file and the copy operation was aborted. + * @throws IOException If the operation failed. + */ + private static boolean copyFileFromJar( + JarURLConnection connection, Path dstDir, final boolean skipIfUnchanged) throws IOException { + final JarFile jar = connection.getJarFile(); + final String source = connection.getEntryName(); + + if (!isFileInJar(connection)) { + return false; + } + copyFileFromJar(jar, source, dstDir, skipIfUnchanged); + + return true; + } + + /** + * Delete unused Files from Arduino-CLI based compilation. + * + *

    Arduino-CLI (the build system) uses lazy compilation (i.e. compiles every file recursively + * from a source directory). This does the work of CMake by explicitly deleting files that + * shouldn't get compiled by the CLI. Generally, we delete all CMake artifacts and multithreaded + * support files (including semaphores and thread folders) + * + * @param dir The folder to search for folders and files to delete. + * @throws IOException If the given folder and unneeded files cannot be deleted. + */ + public static void arduinoDeleteHelper(Path dir, boolean threadingOn) throws IOException { + deleteDirectory(dir.resolve("core/federated")); // TODO: Add Federated Support to Arduino + deleteDirectory( + dir.resolve("include/core/federated")); // TODO: Add Federated Support to Arduino + + if (!threadingOn) { + deleteDirectory(dir.resolve("core/threaded")); // No Threaded Support for Arduino + deleteDirectory(dir.resolve("include/core/threaded")); // No Threaded Support for Arduino + deleteDirectory(dir.resolve("core/platform/arduino_mbed")); // No Threaded Support for Arduino + } + + List allPaths = Files.walk(dir).sorted(Comparator.reverseOrder()).toList(); + for (Path path : allPaths) { + String toCheck = path.toString().toLowerCase(); + if (toCheck.contains("cmake")) { + Files.delete(path); + } + } + } + + /** + * Helper function for getting the string representation of the relative path to take to get from + * one file (currPath) to get to the other (fileName). + * + *

    Generally, this is useful for converting includes to have relative pathing when you lack + * access to adding additional include paths when compiling. + * + * @param fileName File to search for. + * @param currPath The current path to the file whose include statements we are modifying. + * @param fileStringToFilePath Mapping of File Names to their paths. + */ + private static String fileNameMatchConverter( + String fileName, Path currPath, Map fileStringToFilePath) + throws NullPointerException { + // First get the child file + int lastPath = fileName.lastIndexOf(File.separator); + if (lastPath != -1) { + fileName = fileName.substring(lastPath + 1); + } + Path p = fileStringToFilePath.get(fileName); + if (p == null) { + return "#include \"" + fileName + "\""; + } + String relativePath = currPath.getParent().relativize(p).toString(); + return "#include \"" + relativePath + "\""; + } + + /** Return true if the given path points to a C file, false otherwise. */ + public static boolean isCFile(Path path) { + String fileName = path.getFileName().toString(); + return fileName.endsWith(".c") || fileName.endsWith(".cpp") || fileName.endsWith(".h"); + } + + /** + * Convert all includes recursively inside files within a specified folder to relative links + * + * @param dir The folder to search for includes to change. + * @throws IOException If the given set of files cannot be relativized. + */ + public static void relativeIncludeHelper(Path dir, Path includePath) throws IOException { + System.out.println("Relativizing all includes in " + dir.toString()); + List includePaths = + Files.walk(includePath) .filter(Files::isRegularFile) .filter(FileUtil::isCFile) .sorted(Comparator.reverseOrder()) .toList(); - List srcPaths = Files.walk(dir) + List srcPaths = + Files.walk(dir) .filter(Files::isRegularFile) .filter(FileUtil::isCFile) .sorted(Comparator.reverseOrder()) .toList(); - Map fileStringToFilePath = new HashMap(); - for (Path path : includePaths) { - String fileName = path.getFileName().toString(); - if (path.getFileName().toString().contains("CMakeLists.txt")) continue; - if (fileStringToFilePath.put(fileName, path) != null) { - throw new IOException("Directory has different files with the same name. Cannot Relativize."); - } - } - Pattern regexExpression = Pattern.compile("#include\s+[\"]([^\"]+)*[\"]"); - for (Path path : srcPaths) { - String fileContents = Files.readString(path); - Matcher matcher = regexExpression.matcher(fileContents); - int lastIndex = 0; - StringBuilder output = new StringBuilder(); - while (matcher.find()) { - output.append(fileContents, lastIndex, matcher.start()) - .append(fileNameMatchConverter(matcher.group(1), path, fileStringToFilePath)); - lastIndex = matcher.end(); - } - if (lastIndex < fileContents.length()) { - output.append(fileContents, lastIndex, fileContents.length()); - } - writeToFile(output.toString(), path); - } - } - - /** - * Delete the given file or directory if it exists. If {@code fileOrDirectory} is a directory, - * deletion is recursive. - * - * @param fileOrDirectory The file or directory to delete. - * @throws IOException If the operation failed. - */ - public static void delete(Path fileOrDirectory) throws IOException { - if (Files.isRegularFile(fileOrDirectory)) { - Files.deleteIfExists(fileOrDirectory); - } - if (Files.isDirectory(fileOrDirectory)) { - deleteDirectory(fileOrDirectory); - } - } - - /** - * Recursively delete a directory if it exists. - * - * @throws IOException If an I/O error occurs. - */ - public static void deleteDirectory(Path dir) throws IOException { - if (Files.isDirectory(dir)) { - System.out.println("Cleaning " + dir); - List pathsToDelete = Files.walk(dir) - .sorted(Comparator.reverseOrder()) - .toList(); - for (Path path : pathsToDelete) { - Files.deleteIfExists(path); - } - } - } - - /** - * Return an absolute path to the given file or directory if it can be found within the package. - * Otherwise, return null. - * - * NOTE: If the given file or directory is given as an absolute path but cannot be found, it is - * interpreted as a relative path with respect to the project root. - * - * @param fileOrDirectory The file or directory to look for. - * @param fileConfig A file configuration that determines where the package is located. - * @return An absolute path of the file or directory was found; null otherwise. - */ - public static Path findInPackage(Path fileOrDirectory, FileConfig fileConfig) { - if (fileOrDirectory.isAbsolute() && Files.exists(fileOrDirectory)) { - return fileOrDirectory; + Map fileStringToFilePath = new HashMap(); + for (Path path : includePaths) { + String fileName = path.getFileName().toString(); + if (path.getFileName().toString().contains("CMakeLists.txt")) continue; + if (fileStringToFilePath.put(fileName, path) != null) { + throw new IOException( + "Directory has different files with the same name. Cannot Relativize."); + } + } + Pattern regexExpression = Pattern.compile("#include\s+[\"]([^\"]+)*[\"]"); + for (Path path : srcPaths) { + String fileContents = Files.readString(path); + Matcher matcher = regexExpression.matcher(fileContents); + int lastIndex = 0; + StringBuilder output = new StringBuilder(); + while (matcher.find()) { + output + .append(fileContents, lastIndex, matcher.start()) + .append(fileNameMatchConverter(matcher.group(1), path, fileStringToFilePath)); + lastIndex = matcher.end(); + } + if (lastIndex < fileContents.length()) { + output.append(fileContents, lastIndex, fileContents.length()); + } + writeToFile(output.toString(), path); + } + } + + /** + * Delete the given file or directory if it exists. If {@code fileOrDirectory} is a directory, + * deletion is recursive. + * + * @param fileOrDirectory The file or directory to delete. + * @throws IOException If the operation failed. + */ + public static void delete(Path fileOrDirectory) throws IOException { + if (Files.isRegularFile(fileOrDirectory)) { + Files.deleteIfExists(fileOrDirectory); + } + if (Files.isDirectory(fileOrDirectory)) { + deleteDirectory(fileOrDirectory); + } + } + + /** + * Recursively delete a directory if it exists. + * + * @throws IOException If an I/O error occurs. + */ + public static void deleteDirectory(Path dir) throws IOException { + if (Files.isDirectory(dir)) { + System.out.println("Cleaning " + dir); + List pathsToDelete = Files.walk(dir).sorted(Comparator.reverseOrder()).toList(); + for (Path path : pathsToDelete) { + Files.deleteIfExists(path); + } + } + } + + /** + * Return an absolute path to the given file or directory if it can be found within the package. + * Otherwise, return null. + * + *

    NOTE: If the given file or directory is given as an absolute path but cannot be found, it is + * interpreted as a relative path with respect to the project root. + * + * @param fileOrDirectory The file or directory to look for. + * @param fileConfig A file configuration that determines where the package is located. + * @return An absolute path of the file or directory was found; null otherwise. + */ + public static Path findInPackage(Path fileOrDirectory, FileConfig fileConfig) { + if (fileOrDirectory.isAbsolute() && Files.exists(fileOrDirectory)) { + return fileOrDirectory; + } else { + Path relPath; + // Disregard root and interpret as relative path + if (fileOrDirectory.isAbsolute()) { + relPath = + Paths.get( + String.valueOf(fileOrDirectory) + .replaceFirst(String.valueOf(fileOrDirectory.getRoot()), "")); + } else { + relPath = fileOrDirectory; + } + + // Look relative to the source file and relative to the package root. + var locations = List.of(fileConfig.srcPath, fileConfig.srcPkgPath); + var found = locations.stream().filter(loc -> Files.exists(loc.resolve(relPath))).findFirst(); + if (found.isPresent()) { + return found.get().resolve(relPath).toAbsolutePath(); + } + } + return null; + } + + /** Get the iResource corresponding to the provided resource if it can be found. */ + public static IResource getIResource(Resource r) throws IOException { + return getIResource(FileUtil.toPath(r).toFile().toURI()); + } + + /** Get the specified path as an Eclipse IResource or null if it is not found. */ + public static IResource getIResource(Path path) { + IResource ret = getIResource(path.toUri()); + if (ret != null) return ret; + try { + // Handle a bug that not everyone can reproduce in which a path originating in the Ecore model + // is a relative + // path prefixed with a segment named "resource". + return ResourcesPlugin.getWorkspace() + .getRoot() + .findMember( + org.eclipse.core.runtime.Path.fromOSString( + path.subpath(1, path.getNameCount()).toString())); + } catch (IllegalStateException e) { + // We are outside of Eclipse. + } + return null; + } + + /** + * Get the specified uri as an Eclipse IResource or null if it is not found. + * + *

    Also returns null if this is not called from within a running Eclipse instance. + * + * @param uri A java.net.uri of the form "file://path". + */ + public static IResource getIResource(java.net.URI uri) { + // For some peculiar reason known only to Eclipse developers, + // the resource cannot be used directly but has to be converted + // a resource relative to the workspace root. + try { + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + + IFile[] files = workspaceRoot.findFilesForLocationURI(uri); + if (files != null && files.length > 0 && files[0] != null) { + return files[0]; + } + } catch (IllegalStateException e) { + // We are outside of Eclipse. + } + return null; + } + + /** + * Write text to a file. + * + * @param text The text to be written. + * @param path The file to write the code to. + * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not + * be changed + */ + public static void writeToFile(String text, Path path, boolean skipIfUnchanged) + throws IOException { + Files.createDirectories(path.getParent()); + final byte[] bytes = text.getBytes(); + if (skipIfUnchanged && Files.isRegularFile(path)) { + if (Arrays.equals(bytes, Files.readAllBytes(path))) { + return; + } + } + Files.write(path, text.getBytes()); + } + + /** + * Write text to a file. + * + * @param text The text to be written. + * @param path The file to write the code to. + */ + public static void writeToFile(String text, Path path) throws IOException { + writeToFile(text, path, false); + } + + /** + * Write text to a file. + * + * @param text The text to be written. + * @param path The file to write the code to. + */ + public static void writeToFile(CharSequence text, Path path) throws IOException { + writeToFile(text.toString(), path, false); + } + + public static void createDirectoryIfDoesNotExist(File dir) { + if (!dir.exists()) dir.mkdirs(); + } + + /** + * Return a list of files ending with "str". + * + * @param currentDir The current directory. + * @param str The pattern to match against. + */ + public static List globFilesEndsWith(Path currentDir, String str) { + List matches = new ArrayList<>(); + File[] files = currentDir.toFile().listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + matches.addAll(globFilesEndsWith(file.toPath(), str)); } else { - Path relPath; - // Disregard root and interpret as relative path - if (fileOrDirectory.isAbsolute()) { - relPath = Paths.get( - String.valueOf(fileOrDirectory).replaceFirst( - String.valueOf(fileOrDirectory.getRoot()), - "") - ); - } else { - relPath = fileOrDirectory; - } - - // Look relative to the source file and relative to the package root. - var locations = List.of(fileConfig.srcPath, fileConfig.srcPkgPath); - var found = locations.stream().filter( - loc -> Files.exists(loc.resolve(relPath)) - ).findFirst(); - if (found.isPresent()) { - return found.get().resolve(relPath).toAbsolutePath(); - } - } - return null; - } - - /** - * Get the iResource corresponding to the provided resource if it can be - * found. - */ - public static IResource getIResource(Resource r) throws IOException { - return getIResource(FileUtil.toPath(r).toFile().toURI()); - } - - /** - * Get the specified path as an Eclipse IResource or null if it is not found. - */ - public static IResource getIResource(Path path) { - IResource ret = getIResource(path.toUri()); - if (ret != null) return ret; - try { - // Handle a bug that not everyone can reproduce in which a path originating in the Ecore model is a relative - // path prefixed with a segment named "resource". - return ResourcesPlugin.getWorkspace().getRoot().findMember(org.eclipse.core.runtime.Path.fromOSString( - path.subpath(1, path.getNameCount()).toString() - )); - } catch (IllegalStateException e) { - // We are outside of Eclipse. - } - return null; - } - - /** - * Get the specified uri as an Eclipse IResource or null if it is not found. - * - * Also returns null if this is not called from within a running Eclipse instance. - * - * @param uri A java.net.uri of the form "file://path". - */ - public static IResource getIResource(java.net.URI uri) { - // For some peculiar reason known only to Eclipse developers, - // the resource cannot be used directly but has to be converted - // a resource relative to the workspace root. - try { - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - - IFile[] files = workspaceRoot.findFilesForLocationURI(uri); - if (files != null && files.length > 0 && files[0] != null) { - return files[0]; - } - } catch (IllegalStateException e) { - // We are outside of Eclipse. - } - return null; - } - - /** - * Write text to a file. - * @param text The text to be written. - * @param path The file to write the code to. - * @param skipIfUnchanged If true, don't overwrite the destination file if its content would not be changed - */ - public static void writeToFile(String text, Path path, boolean skipIfUnchanged) throws IOException { - Files.createDirectories(path.getParent()); - final byte[] bytes = text.getBytes(); - if (skipIfUnchanged && Files.isRegularFile(path)) { - if (Arrays.equals(bytes, Files.readAllBytes(path))) { - return; - } - } - Files.write(path, text.getBytes()); - } - - /** - * Write text to a file. - * @param text The text to be written. - * @param path The file to write the code to. - */ - public static void writeToFile(String text, Path path) throws IOException { - writeToFile(text, path, false); - } - - /** - * Write text to a file. - * @param text The text to be written. - * @param path The file to write the code to. - */ - public static void writeToFile(CharSequence text, Path path) throws IOException { - writeToFile(text.toString(), path, false); - } - - public static void createDirectoryIfDoesNotExist(File dir) { - if (!dir.exists()) dir.mkdirs(); - } - - /** - * Return a list of files ending with "str". - * - * @param currentDir The current directory. - * @param str The pattern to match against. - */ - public static List globFilesEndsWith(Path currentDir, String str) { - List matches = new ArrayList<>(); - File[] files = currentDir.toFile().listFiles(); - if (files != null) { - for (File file : files) { - if (file.isDirectory()) { - matches.addAll(globFilesEndsWith(file.toPath(), str)); - } else { - if (file.getName().endsWith(str)) { - matches.add(file.getAbsoluteFile().toPath()); - } - } - } + if (file.getName().endsWith(str)) { + matches.add(file.getAbsoluteFile().toPath()); + } } - return matches; + } } + return matches; + } } diff --git a/org.lflang/src/org/lflang/util/IteratorUtil.java b/org.lflang/src/org/lflang/util/IteratorUtil.java index 37ddadf56d..559739ed00 100644 --- a/org.lflang/src/org/lflang/util/IteratorUtil.java +++ b/org.lflang/src/org/lflang/util/IteratorUtil.java @@ -4,8 +4,6 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.lflang.lf.Reactor; - /** * A utility class for Iterator. * @@ -14,55 +12,53 @@ */ public final class IteratorUtil { - private IteratorUtil() { - // Don't let anyone instantiate this class. - } + private IteratorUtil() { + // Don't let anyone instantiate this class. + } + + /** + * Turn an iterator into a sequential stream. + * + * @param iterator The iterator to create a sequential stream for. + * @return A stream. + */ + public static Stream asStream(Iterator iterator) { + return asStream(iterator, false); + } - /** - * Turn an iterator into a sequential stream. - * - * @param iterator The iterator to create a sequential stream for. - * @return A stream. - */ - public static Stream asStream(Iterator iterator) { - return asStream(iterator, false); - } + /** + * Given an iterator of type T, turn it into a stream containing only the instances of the given + * class of type S. + * + * @param The type of elements the iterator iterates over. + * @param The type of class to filter out instance of. + * @param iterator An iterator of type T. + * @param cls A given class of type S. + * @return A filtered stream that only has in it instances of the given class. + */ + public static Stream asFilteredStream(Iterator iterator, Class cls) { + return asStream(iterator, false).filter(cls::isInstance).map(cls::cast); + } - /** - * Given an iterator of type T, turn it into a stream containing only the - * instances of the given class of type S. - * - * @param The type of elements the iterator iterates over. - * @param The type of class to filter out instance of. - * @param iterator An iterator of type T. - * @param cls A given class of type S. - * @return A filtered stream that only has in it instances of the given - * class. - */ - public static Stream asFilteredStream(Iterator iterator, - Class cls) { - return asStream(iterator, false).filter(cls::isInstance).map(cls::cast); - } - - /** - * Turn an iterator into a sequential or parallel stream. - * - * @param iterator The iterator to create a stream for. - * @param parallel Whether or not the stream should be parallel. - * @return A stream. - */ - public static Stream asStream(Iterator iterator, boolean parallel) { - Iterable iterable = () -> iterator; - return StreamSupport.stream(iterable.spliterator(), parallel); - } + /** + * Turn an iterator into a sequential or parallel stream. + * + * @param iterator The iterator to create a stream for. + * @param parallel Whether or not the stream should be parallel. + * @return A stream. + */ + public static Stream asStream(Iterator iterator, boolean parallel) { + Iterable iterable = () -> iterator; + return StreamSupport.stream(iterable.spliterator(), parallel); + } - /** - * Function to get Iterable from Iterator. - * - * @param iterator The iterator to get an iterable from. - * @return An iterable. - */ - public static Iterable asIterable(Iterator iterator) { - return () -> iterator; - } + /** + * Function to get Iterable from Iterator. + * + * @param iterator The iterator to get an iterable from. + * @return An iterable. + */ + public static Iterable asIterable(Iterator iterator) { + return () -> iterator; + } } diff --git a/org.lflang/src/org/lflang/util/LFCommand.java b/org.lflang/src/org/lflang/util/LFCommand.java index 4f6927dcf0..4b4116f264 100644 --- a/org.lflang/src/org/lflang/util/LFCommand.java +++ b/org.lflang/src/org/lflang/util/LFCommand.java @@ -1,26 +1,26 @@ /************* - Copyright (c) 2019-2021 TU Dresden - Copyright (c) 2019-2021 UC Berkeley - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2019-2021 TU Dresden + * Copyright (c) 2019-2021 UC Berkeley + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************/ package org.lflang.util; @@ -42,370 +42,353 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; - import org.eclipse.xtext.util.CancelIndicator; /** * An abstraction for an external command - *

    - * This is a wrapper around ProcessBuilder which allows for a more convenient usage in our code base. + * + *

    This is a wrapper around ProcessBuilder which allows for a more convenient usage in our code + * base. */ public class LFCommand { - /** - * The period with which the cancel indicator is - * checked and the output and error streams are - * 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. - */ - private static final int READ_TIMEOUT_MILLISECONDS = 1000; - - protected ProcessBuilder processBuilder; - protected boolean didRun = false; - protected ByteArrayOutputStream output = new ByteArrayOutputStream(); - protected ByteArrayOutputStream errors = new ByteArrayOutputStream(); - protected boolean quiet; - - - /** - * Construct an LFCommand that executes the command carried by {@code pb}. - */ - protected LFCommand(ProcessBuilder pb, boolean quiet) { - this.processBuilder = pb; - this.quiet = quiet; - } - - - /** - * Get the output collected during command execution - */ - public OutputStream getOutput() { return output; } - - - /** - * Get the error output collected during command execution - */ - public OutputStream getErrors() { return errors; } - - /** Get this command's program and arguments. */ - public List command() { return processBuilder.command(); } - - /** Get this command's working directory. */ - public File directory() { return processBuilder.directory(); } - - /** - * Get a String representation of the stored command - */ - public String toString() { return String.join(" ", processBuilder.command()); } - - - /** - * Collect as much output as possible from {@code in} without blocking, print it to - * {@code print} if not quiet, and store it in {@code store}. - */ - private void collectOutput(InputStream in, ByteArrayOutputStream store, PrintStream print) { - byte[] buffer = new byte[64]; - int len; - do { - try { - // This depends on in.available() being - // greater than zero if data is available - // (so that all data is collected) - // and upper-bounded by maximum number of - // bytes that can be read without blocking. - // Only the latter of these two conditions - // is guaranteed by the spec. - len = in.read(buffer, 0, Math.min(in.available(), buffer.length)); - if (len > 0) { - store.write(buffer, 0, len); - if (!quiet) print.write(buffer, 0, len); - } - } catch (IOException e) { - e.printStackTrace(); - break; - } - } while (len > 0); // Do not necessarily continue - // to EOF (len == -1) because a blocking read - // operation is hard to interrupt. - } - - /** - * Handle user cancellation if necessary, and handle any output from {@code process} - * otherwise. - * @param process a {@code Process} - * @param cancelIndicator a flag indicating whether a - * cancellation of {@code process} - * is requested - * directly to stderr and stdout). - */ - private void poll(Process process, CancelIndicator cancelIndicator) { - if (cancelIndicator != null && cancelIndicator.isCanceled()) { - process.descendants().forEach(ProcessHandle::destroyForcibly); - process.destroyForcibly(); - } else { - collectOutput(process.getInputStream(), output, System.out); - collectOutput(process.getErrorStream(), errors, System.err); + /** + * The period with which the cancel indicator is checked and the output and error streams are + * 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. + */ + private static final int READ_TIMEOUT_MILLISECONDS = 1000; + + protected ProcessBuilder processBuilder; + protected boolean didRun = false; + protected ByteArrayOutputStream output = new ByteArrayOutputStream(); + protected ByteArrayOutputStream errors = new ByteArrayOutputStream(); + protected boolean quiet; + + /** Construct an LFCommand that executes the command carried by {@code pb}. */ + protected LFCommand(ProcessBuilder pb, boolean quiet) { + this.processBuilder = pb; + this.quiet = quiet; + } + + /** Get the output collected during command execution */ + public OutputStream getOutput() { + return output; + } + + /** Get the error output collected during command execution */ + public OutputStream getErrors() { + return errors; + } + + /** Get this command's program and arguments. */ + public List command() { + return processBuilder.command(); + } + + /** Get this command's working directory. */ + public File directory() { + return processBuilder.directory(); + } + + /** Get a String representation of the stored command */ + public String toString() { + return String.join(" ", processBuilder.command()); + } + + /** + * Collect as much output as possible from {@code in} without blocking, print it to {@code print} + * if not quiet, and store it in {@code store}. + */ + private void collectOutput(InputStream in, ByteArrayOutputStream store, PrintStream print) { + byte[] buffer = new byte[64]; + int len; + do { + try { + // This depends on in.available() being + // greater than zero if data is available + // (so that all data is collected) + // and upper-bounded by maximum number of + // bytes that can be read without blocking. + // Only the latter of these two conditions + // is guaranteed by the spec. + len = in.read(buffer, 0, Math.min(in.available(), buffer.length)); + if (len > 0) { + store.write(buffer, 0, len); + if (!quiet) print.write(buffer, 0, len); } + } catch (IOException e) { + e.printStackTrace(); + break; + } + } while (len > 0); // Do not necessarily continue + // to EOF (len == -1) because a blocking read + // operation is hard to interrupt. + } + + /** + * Handle user cancellation if necessary, and handle any output from {@code process} otherwise. + * + * @param process a {@code Process} + * @param cancelIndicator a flag indicating whether a cancellation of {@code process} is requested + * directly to stderr and stdout). + */ + private void poll(Process process, CancelIndicator cancelIndicator) { + if (cancelIndicator != null && cancelIndicator.isCanceled()) { + process.descendants().forEach(ProcessHandle::destroyForcibly); + process.destroyForcibly(); + } else { + collectOutput(process.getInputStream(), output, System.out); + collectOutput(process.getErrorStream(), errors, System.err); } - - - /** - * Execute the command. - *

    - * Executing a process directly with {@code processBuilder.start()} could - * lead to a deadlock as the subprocess blocks when output or error - * buffers are full. This method ensures that output and error messages - * are continuously read and forwards them to the system output and - * error streams as well as to the output and error streams hold in - * this class. - *

    - *

    - * If the current operation is cancelled (as indicated - * by cancelIndicator), the subprocess - * is destroyed. Output and error streams until that - * point are still collected. - *

    - * - * @param cancelIndicator The indicator of whether the underlying process - * should be terminated. - * @return the process' return code - * @author Christian Menard - */ - public int run(CancelIndicator cancelIndicator) { - assert !didRun; - didRun = true; - - System.out.println("--- Current working directory: " + processBuilder.directory().toString()); - System.out.println("--- Executing command: " + String.join(" ", processBuilder.command())); - - final Process process = startProcess(); - if (process == null) return -1; - - ScheduledExecutorService poller = Executors.newSingleThreadScheduledExecutor(); - poller.scheduleAtFixedRate( - () -> poll(process, cancelIndicator), - 0, PERIOD_MILLISECONDS, TimeUnit.MILLISECONDS - ); - - try { - final int returnCode = process.waitFor(); - poller.shutdown(); - poller.awaitTermination(READ_TIMEOUT_MILLISECONDS, TimeUnit.MILLISECONDS); - // Finish collecting any remaining data - poll(process, cancelIndicator); - return returnCode; - } catch (InterruptedException e) { - e.printStackTrace(); - return -2; - } + } + + /** + * Execute the command. + * + *

    Executing a process directly with {@code processBuilder.start()} could lead to a deadlock as + * the subprocess blocks when output or error buffers are full. This method ensures that output + * and error messages are continuously read and forwards them to the system output and error + * streams as well as to the output and error streams hold in this class. + * + *

    If the current operation is cancelled (as indicated by cancelIndicator), the + * subprocess is destroyed. Output and error streams until that point are still collected. + * + * @param cancelIndicator The indicator of whether the underlying process should be terminated. + * @return the process' return code + * @author Christian Menard + */ + public int run(CancelIndicator cancelIndicator) { + assert !didRun; + didRun = true; + + System.out.println("--- Current working directory: " + processBuilder.directory().toString()); + System.out.println("--- Executing command: " + String.join(" ", processBuilder.command())); + + final Process process = startProcess(); + if (process == null) return -1; + + ScheduledExecutorService poller = Executors.newSingleThreadScheduledExecutor(); + poller.scheduleAtFixedRate( + () -> poll(process, cancelIndicator), 0, PERIOD_MILLISECONDS, TimeUnit.MILLISECONDS); + + try { + final int returnCode = process.waitFor(); + poller.shutdown(); + poller.awaitTermination(READ_TIMEOUT_MILLISECONDS, TimeUnit.MILLISECONDS); + // Finish collecting any remaining data + poll(process, cancelIndicator); + return returnCode; + } catch (InterruptedException e) { + e.printStackTrace(); + return -2; } - - /** - * Execute the command. Do not allow user cancellation. - * @return the process' return code - */ - public int run() { - return run(null); - } - - - /** - * Add the given variables and their values to the command's environment. - * - * @param variables A map of variable names and their values - */ - public void setEnvironmentVariables(Map variables) { - processBuilder.environment().putAll(variables); + } + + /** + * Execute the command. Do not allow user cancellation. + * + * @return the process' return code + */ + public int run() { + return run(null); + } + + /** + * Add the given variables and their values to the command's environment. + * + * @param variables A map of variable names and their values + */ + public void setEnvironmentVariables(Map variables) { + processBuilder.environment().putAll(variables); + } + + /** + * Add the given variable and its value to the command's environment. + * + * @param variableName name of the variable to add + * @param value the variable's value + */ + public void setEnvironmentVariable(String variableName, String value) { + processBuilder.environment().put(variableName, value); + } + + /** + * Replace the given variable and its value in the command's environment. + * + * @param variableName name of the variable to add + * @param value the variable's value + */ + public void replaceEnvironmentVariable(String variableName, String value) { + processBuilder.environment().remove(variableName); + processBuilder.environment().put(variableName, value); + } + + /** Require this to be quiet, overriding the verbosity specified at construction time. */ + public void setQuiet() { + quiet = true; + } + + /** + * Create a LFCommand instance from a given command and argument list in the current working + * directory. + * + * @see #get(String, List, boolean, Path) + */ + public static LFCommand get(final String cmd, final List args) { + return get(cmd, args, false, Paths.get("")); + } + + /** + * Create a LFCommand instance from a given command and argument list in the current working + * directory. + * + * @see #get(String, List, boolean, Path) + */ + public static LFCommand get(final String cmd, final List args, boolean quiet) { + return get(cmd, args, quiet, Paths.get("")); + } + + /** + * Create a LFCommand instance from a given command, an argument list and a directory. + * + *

    This will check first if the command can actually be found and executed. If the command is + * not found, null is returned. In order to find the command, different methods are applied in the + * following order: + * + *

    1. Check if the given command {@code cmd} is an executable file within {@code dir}. 2. If + * the above fails 'which ' (or 'where ' on Windows) is executed to see if the command + * is available on the PATH. 3. If both points above fail, a third attempt is started using bash + * to indirectly execute the command (see below for an explanation). + * + *

    A bit more context: If the command cannot be found directly, then a second attempt is made + * using a Bash shell with the --login option, which sources the user's ~/.bash_profile, + * ~/.bash_login, or ~/.bashrc (whichever is first found) before running the command. This helps + * to ensure that the user's PATH variable is set according to their usual environment, assuming + * that they use a bash shell. + * + *

    More information: Unfortunately, at least on a Mac if you are running within Eclipse, the + * PATH variable is extremely limited; supposedly, it is given by the default provided in + * /etc/paths, but at least on my machine, it does not even include directories in that file for + * some reason. One way to add a directory like /usr/local/bin to the path once-and-for-all is + * this: + * + *

    sudo launchctl config user path /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin + * + *

    But asking users to do that is not ideal. Hence, we try a more hack-y approach of just + * trying to execute using a bash shell. Also note that while ProcessBuilder can be configured to + * use custom environment variables, these variables do not affect the command that is to be + * executed but merely the environment in which the command executes. + * + * @param cmd The command + * @param args A list of arguments to pass to the command + * @param quiet If true, the commands stdout and stderr will be suppressed + * @param dir The directory in which the command should be executed + * @return Returns an LFCommand if the given command could be found or null otherwise. + */ + public static LFCommand get(final String cmd, final List args, boolean quiet, Path dir) { + assert cmd != null && args != null && dir != null; + dir = dir.toAbsolutePath(); + + // a list containing the command as first element and then all arguments + List cmdList = new ArrayList<>(); + cmdList.add(cmd); + cmdList.addAll(args); + + ProcessBuilder builder = null; + + // First, see if the command is a local executable file + final File cmdFile = dir.resolve(cmd).toFile(); + if (cmdFile.exists() && cmdFile.canExecute()) { + builder = new ProcessBuilder(cmdList); + } else if (findCommand(cmd) != null) { + builder = new ProcessBuilder(cmdList); + } else if (checkIfCommandIsExecutableWithBash(cmd, dir)) { + builder = + new ProcessBuilder( + "bash", "--login", "-c", String.format("\"%s\"", String.join(" ", cmdList))); } - - /** - * Add the given variable and its value to the command's environment. - * - * @param variableName name of the variable to add - * @param value the variable's value - */ - public void setEnvironmentVariable(String variableName, String value) { - processBuilder.environment().put(variableName, value); - } - - /** - * Replace the given variable and its value in the command's environment. - * - * @param variableName name of the variable to add - * @param value the variable's value - */ - public void replaceEnvironmentVariable(String variableName, String value) { - processBuilder.environment().remove(variableName); - processBuilder.environment().put(variableName, value); + if (builder != null) { + builder.directory(dir.toFile()); + return new LFCommand(builder, quiet); } - /** - * Require this to be quiet, overriding the verbosity specified at construction time. - */ - public void setQuiet() { - quiet = true; + return null; + } + + /** + * Search for matches to the given command by following the PATH environment variable. + * + * @param command A command for which to search. + * @return The file locations of matches to the given command. + */ + private static List findCommand(final String command) { + final String whichCmd = System.getProperty("os.name").startsWith("Windows") ? "where" : "which"; + final ProcessBuilder whichBuilder = new ProcessBuilder(List.of(whichCmd, command)); + try { + Process p = whichBuilder.start(); + if (p.waitFor() != 0) return null; + return Arrays.stream(new String(p.getInputStream().readAllBytes()).split("\n")) + .map(String::strip) + .map(File::new) + .filter(File::canExecute) + .collect(Collectors.toList()); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + return null; } - - /** - * Create a LFCommand instance from a given command and argument list in the current working directory. - * - * @see #get(String, List, boolean, Path) - */ - public static LFCommand get(final String cmd, final List args) { - return get(cmd, args, false, Paths.get("")); + } + + /** + * Attempt to start the execution of this command. + * + *

    First collect a list of paths where the executable might be found, then select an executable + * that successfully executes from the list of paths. Return the {@code Process} instance that is + * the result of a successful execution, or {@code null} if no successful execution happened. + * + * @return The {@code Process} that is started by this command, or {@code null} in case of + * failure. + */ + private Process startProcess() { + ArrayDeque commands = new ArrayDeque<>(); + List matchesOnPath = findCommand(processBuilder.command().get(0)); + if (matchesOnPath != null) { + matchesOnPath.stream().map(File::toString).forEach(commands::addLast); } - - /** - * Create a LFCommand instance from a given command and argument list in the current working directory. - * - * @see #get(String, List, boolean, Path) - */ - public static LFCommand get(final String cmd, final List args, boolean quiet) { - return get(cmd, args, quiet, Paths.get("")); - } - - - /** - * Create a LFCommand instance from a given command, an argument list and a directory. - *

    - * This will check first if the command can actually be found and executed. If the command is not found, null is - * returned. In order to find the command, different methods are applied in the following order: - *

    - * 1. Check if the given command {@code cmd} is an executable file within {@code dir}. - * 2. If the above fails 'which ' (or 'where ' on Windows) is executed to see if the command is available - * on the PATH. - * 3. If both points above fail, a third attempt is started using bash to indirectly execute the command (see below - * for an explanation). - *

    - * A bit more context: - * If the command cannot be found directly, then a second attempt is made using a Bash shell with the --login - * option, which sources the user's ~/.bash_profile, ~/.bash_login, or ~/.bashrc (whichever is first found) before - * running the command. This helps to ensure that the user's PATH variable is set according to their usual - * environment, assuming that they use a bash shell. - *

    - * More information: Unfortunately, at least on a Mac if you are running within Eclipse, the PATH variable is - * extremely limited; supposedly, it is given by the default provided in /etc/paths, but at least on my machine, it - * does not even include directories in that file for some reason. One way to add a directory like /usr/local/bin - * to - * the path once-and-for-all is this: - *

    - * sudo launchctl config user path /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin - *

    - * But asking users to do that is not ideal. Hence, we try a more hack-y approach of just trying to execute using a - * bash shell. Also note that while ProcessBuilder can be configured to use custom environment variables, these - * variables do not affect the command that is to be executed but merely the environment in which the command - * executes. - * - * @param cmd The command - * @param args A list of arguments to pass to the command - * @param quiet If true, the commands stdout and stderr will be suppressed - * @param dir The directory in which the command should be executed - * @return Returns an LFCommand if the given command could be found or null otherwise. - */ - public static LFCommand get(final String cmd, final List args, boolean quiet, Path dir) { - assert cmd != null && args != null && dir != null; - dir = dir.toAbsolutePath(); - - // a list containing the command as first element and then all arguments - List cmdList = new ArrayList<>(); - cmdList.add(cmd); - cmdList.addAll(args); - - ProcessBuilder builder = null; - - // First, see if the command is a local executable file - final File cmdFile = dir.resolve(cmd).toFile(); - if (cmdFile.exists() && cmdFile.canExecute()) { - builder = new ProcessBuilder(cmdList); - } else if (findCommand(cmd) != null) { - builder = new ProcessBuilder(cmdList); - } else if (checkIfCommandIsExecutableWithBash(cmd, dir)) { - builder = new ProcessBuilder("bash", "--login", "-c", String.format("\"%s\"", String.join(" ", cmdList))); - } - - if (builder != null) { - builder.directory(dir.toFile()); - return new LFCommand(builder, quiet); - } - - return null; - } - - - /** - * Search for matches to the given command by following the PATH environment variable. - * @param command A command for which to search. - * @return The file locations of matches to the given command. - */ - private static List findCommand(final String command) { - final String whichCmd = System.getProperty("os.name").startsWith("Windows") ? "where" : "which"; - final ProcessBuilder whichBuilder = new ProcessBuilder(List.of(whichCmd, command)); - try { - Process p = whichBuilder.start(); - if (p.waitFor() != 0) return null; - return Arrays.stream(new String(p.getInputStream().readAllBytes()).split("\n")) - .map(String::strip).map(File::new).filter(File::canExecute).collect(Collectors.toList()); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - return null; + while (true) { + try { + return processBuilder.start(); + } catch (IOException e) { + if (commands.isEmpty()) { + e.printStackTrace(); + return null; } + } + processBuilder.command().set(0, commands.removeFirst()); } + } - /** - * Attempt to start the execution of this command. - * - * First collect a list of paths where the executable might be found, - * then select an executable that successfully executes from the - * list of paths. Return the {@code Process} instance that is the - * result of a successful execution, or {@code null} if no successful - * execution happened. - * @return The {@code Process} that is started by this command, or {@code null} in case of failure. - */ - private Process startProcess() { - ArrayDeque commands = new ArrayDeque<>(); - List matchesOnPath = findCommand(processBuilder.command().get(0)); - if (matchesOnPath != null) { - matchesOnPath.stream().map(File::toString).forEach(commands::addLast); - } - while (true) { - try { - return processBuilder.start(); - } catch (IOException e) { - if (commands.isEmpty()) { - e.printStackTrace(); - return null; - } - } - processBuilder.command().set(0, commands.removeFirst()); - } + private static boolean checkIfCommandIsExecutableWithBash(final String command, final Path dir) { + // check first if bash is installed + if (findCommand("bash") == null) { + return false; } - - private static boolean checkIfCommandIsExecutableWithBash(final String command, final Path dir) { - // check first if bash is installed - if (findCommand("bash") == null) { - return false; - } - - // then try to find command with bash - final ProcessBuilder bashBuilder = new ProcessBuilder(List.of( - "bash", - "--login", - "-c", - String.format("\"which %s\"", command) - )); - bashBuilder.directory(dir.toFile()); - try { - int bashReturn = bashBuilder.start().waitFor(); - return bashReturn == 0; - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - return false; - } + // then try to find command with bash + final ProcessBuilder bashBuilder = + new ProcessBuilder( + List.of("bash", "--login", "-c", String.format("\"which %s\"", command))); + bashBuilder.directory(dir.toFile()); + try { + int bashReturn = bashBuilder.start().waitFor(); + return bashReturn == 0; + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + return false; } + } } diff --git a/org.lflang/src/org/lflang/util/StringUtil.java b/org.lflang/src/org/lflang/util/StringUtil.java index 31beef8a9b..516f340c06 100644 --- a/org.lflang/src/org/lflang/util/StringUtil.java +++ b/org.lflang/src/org/lflang/util/StringUtil.java @@ -36,137 +36,133 @@ */ public final class StringUtil { - /** - * Matches the boundary of a camel-case word. That's a zero-length match. - */ - private static final Pattern CAMEL_WORD_BOUNDARY = - Pattern.compile("(? !it.isEmpty()) - .map(it -> it.toLowerCase(Locale.ROOT)) - .collect(Collectors.joining("_")); - } + /** + * Convert a string in Camel case to snake case. E.g. {@code MinimalReactor} will be converted to + * {@code minimal_reactor}. The string is assumed to be a single camel case identifier (no + * whitespace). + */ + public static String camelToSnakeCase(String str) { + return CAMEL_WORD_BOUNDARY + .splitAsStream(str) + .filter(it -> !it.isEmpty()) + .map(it -> it.toLowerCase(Locale.ROOT)) + .collect(Collectors.joining("_")); + } - /** - * If the given string is surrounded by single or double - * quotes, returns what's inside the quotes. Otherwise - * returns the same string. - * - *

    Returns null if the parameter is null. - */ - public static String removeQuotes(String str) { - if (str == null) { - return null; - } - if (str.length() < 2) { - return str; - } - if (hasQuotes(str)) { - return str.substring(1, str.length() - 1); - } - return str; + /** + * If the given string is surrounded by single or double quotes, returns what's inside the quotes. + * Otherwise returns the same string. + * + *

    Returns null if the parameter is null. + */ + public static String removeQuotes(String str) { + if (str == null) { + return null; + } + if (str.length() < 2) { + return str; + } + if (hasQuotes(str)) { + return str.substring(1, str.length() - 1); } + return str; + } - /** - * Return true if the given string is surrounded by single or double - * quotes, - */ - public static boolean hasQuotes(String str) { - if (str == null) { - return false; - } - return str.startsWith("\"") && str.endsWith("\"") || str.startsWith("'") && str.endsWith("'"); + /** Return true if the given string is surrounded by single or double quotes, */ + public static boolean hasQuotes(String str) { + if (str == null) { + return false; } + return str.startsWith("\"") && str.endsWith("\"") || str.startsWith("'") && str.endsWith("'"); + } - /** - * Intelligently trim the white space in a code block. - * - * The leading whitespaces of the first non-empty - * code line is considered as a common prefix across all code lines. If the - * remaining code lines indeed start with this prefix, it removes the prefix - * from the code line. - * - * For examples, this code - *

    {@code
    -     *        int test = 4;
    -     *        if (test == 42) {
    -     *            printf("Hello\n");
    -     *        }
    -     * }
    - * will be trimmed to this: - *
    {@code
    -     * int test = 4;
    -     * if (test == 42) {
    -     *     printf("Hello\n");
    -     * }
    -     * }
    - * - * @param code the code block to be trimmed - * @param firstLineToConsider The first line not to ignore. - * @return trimmed code block - */ - public static String trimCodeBlock(String code, int firstLineToConsider) { - String[] codeLines = code.split("(\r\n?)|\n"); - int prefix = getWhitespacePrefix(code, firstLineToConsider); - StringBuilder buffer = new StringBuilder(); - boolean stillProcessingLeadingBlankLines = true; - for (int i = 0; i < firstLineToConsider; i++) { - var endIndex = codeLines[i].contains("//") ? - codeLines[i].indexOf("//") : codeLines[i].length(); - // The following will break Rust attributes in multiline code blocks - // where they appear next to the opening {= brace. - endIndex = codeLines[i].contains("#") ? - Math.min(endIndex, codeLines[i].indexOf("#")) : endIndex; - String toAppend = codeLines[i].substring(0, endIndex).strip(); - if (!toAppend.isBlank()) buffer.append(toAppend).append("\n"); - } - for (int i = firstLineToConsider; i < codeLines.length; i++) { - final String line = codeLines[i]; - if (!line.isBlank()) stillProcessingLeadingBlankLines = false; - if (stillProcessingLeadingBlankLines) continue; - if (!line.isBlank()) buffer.append(line.substring(prefix)); - buffer.append("\n"); - } - return buffer.toString().stripTrailing(); + /** + * Intelligently trim the white space in a code block. + * + *

    The leading whitespaces of the first non-empty code line is considered as a common prefix + * across all code lines. If the remaining code lines indeed start with this prefix, it removes + * the prefix from the code line. + * + *

    For examples, this code + * + *

    {@code
    +   * int test = 4;
    +   * if (test == 42) {
    +   *     printf("Hello\n");
    +   * }
    +   * }
    + * + * will be trimmed to this: + * + *
    {@code
    +   * int test = 4;
    +   * if (test == 42) {
    +   *     printf("Hello\n");
    +   * }
    +   * }
    + * + * @param code the code block to be trimmed + * @param firstLineToConsider The first line not to ignore. + * @return trimmed code block + */ + public static String trimCodeBlock(String code, int firstLineToConsider) { + String[] codeLines = code.split("(\r\n?)|\n"); + int prefix = getWhitespacePrefix(code, firstLineToConsider); + StringBuilder buffer = new StringBuilder(); + boolean stillProcessingLeadingBlankLines = true; + for (int i = 0; i < firstLineToConsider; i++) { + var endIndex = + codeLines[i].contains("//") ? codeLines[i].indexOf("//") : codeLines[i].length(); + // The following will break Rust attributes in multiline code blocks + // where they appear next to the opening {= brace. + endIndex = + codeLines[i].contains("#") ? Math.min(endIndex, codeLines[i].indexOf("#")) : endIndex; + String toAppend = codeLines[i].substring(0, endIndex).strip(); + if (!toAppend.isBlank()) buffer.append(toAppend).append("\n"); + } + for (int i = firstLineToConsider; i < codeLines.length; i++) { + final String line = codeLines[i]; + if (!line.isBlank()) stillProcessingLeadingBlankLines = false; + if (stillProcessingLeadingBlankLines) continue; + if (!line.isBlank()) buffer.append(line.substring(prefix)); + buffer.append("\n"); } + return buffer.toString().stripTrailing(); + } - private static int getWhitespacePrefix(String code, int firstLineToConsider) { - String[] codeLines = code.split("(\r\n?)|\n"); - int minLength = Integer.MAX_VALUE; - for (int j = firstLineToConsider; j < codeLines.length; j++) { - String line = codeLines[j]; - for (var i = 0; i < line.length(); i++) { - if (!Character.isWhitespace(line.charAt(i))) { - minLength = Math.min(minLength, i); - break; - } - } + private static int getWhitespacePrefix(String code, int firstLineToConsider) { + String[] codeLines = code.split("(\r\n?)|\n"); + int minLength = Integer.MAX_VALUE; + for (int j = firstLineToConsider; j < codeLines.length; j++) { + String line = codeLines[j]; + for (var i = 0; i < line.length(); i++) { + if (!Character.isWhitespace(line.charAt(i))) { + minLength = Math.min(minLength, i); + break; } - return minLength == Integer.MAX_VALUE ? 0 : minLength; + } } + return minLength == Integer.MAX_VALUE ? 0 : minLength; + } - public static String addDoubleQuotes(String str) { - return "\""+str+"\""; - } + public static String addDoubleQuotes(String str) { + return "\"" + str + "\""; + } - public static String joinObjects(List things, String delimiter) { - return things.stream().map(T::toString).collect(Collectors.joining(delimiter)); - } + public static String joinObjects(List things, String delimiter) { + return things.stream().map(T::toString).collect(Collectors.joining(delimiter)); + } - /** Normalize end-of-line sequences to the Linux style. */ - public static String normalizeEol(String s) { - return s.replaceAll("(\\r\\n?)|\\n", "\n"); - } + /** Normalize end-of-line sequences to the Linux style. */ + public static String normalizeEol(String s) { + return s.replaceAll("(\\r\\n?)|\\n", "\n"); + } } diff --git a/org.lflang/src/org/lflang/util/TargetResourceNotFoundException.java b/org.lflang/src/org/lflang/util/TargetResourceNotFoundException.java index dfcc1d671a..acc55fb0f3 100644 --- a/org.lflang/src/org/lflang/util/TargetResourceNotFoundException.java +++ b/org.lflang/src/org/lflang/util/TargetResourceNotFoundException.java @@ -3,12 +3,15 @@ import java.io.IOException; public class TargetResourceNotFoundException extends IOException { - public TargetResourceNotFoundException(String resourcePath) { - super(String.format(""" + public TargetResourceNotFoundException(String resourcePath) { + super( + String.format( + """ A required resource could not be found on the classpath or is an empty directory: %s Perhaps a git submodule is missing or not up to date. Try running 'git submodule update --init --recursive' and rebuild. - Also see https://www.lf-lang.org/docs/handbook/developer-setup. - """, resourcePath)); - } + Also see https://www.lf-lang.org/docs/handbook/developer-setup. + """, + resourcePath)); + } } diff --git a/org.lflang/src/org/lflang/validation/AttributeSpec.java b/org.lflang/src/org/lflang/validation/AttributeSpec.java index 48b10a140a..45c984204e 100644 --- a/org.lflang/src/org/lflang/validation/AttributeSpec.java +++ b/org.lflang/src/org/lflang/validation/AttributeSpec.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2019-2022, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - import org.lflang.ast.ASTUtils; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; @@ -40,191 +39,189 @@ /** * Specification of the structure of an attribute annotation. + * * @author Clément Fournier * @author Shaokai Lin */ public class AttributeSpec { - private final Map paramSpecByName; + private final Map paramSpecByName; - public static final String VALUE_ATTR = "value"; - public static final String NETWORK_MESSAGE_ACTIONS = "network_message_actions"; - public static final String EACH_ATTR = "each"; + public static final String VALUE_ATTR = "value"; + public static final String NETWORK_MESSAGE_ACTIONS = "network_message_actions"; + public static final String EACH_ATTR = "each"; - /** A map from a string to a supported AttributeSpec */ - public static final Map ATTRIBUTE_SPECS_BY_NAME = new HashMap<>(); + /** A map from a string to a supported AttributeSpec */ + public static final Map ATTRIBUTE_SPECS_BY_NAME = new HashMap<>(); - public AttributeSpec(List params) { - if (params != null) { - paramSpecByName = params.stream().collect(Collectors.toMap(it -> it.name, it -> it)); - } else { - paramSpecByName = null; - } + public AttributeSpec(List params) { + if (params != null) { + paramSpecByName = params.stream().collect(Collectors.toMap(it -> it.name, it -> it)); + } else { + paramSpecByName = null; + } + } + + /** Check that the attribute conforms to this spec and whether attr has the correct name. */ + public void check(LFValidator validator, Attribute attr) { + Set seen; + // If there is just one parameter, it is required to be named "value". + if (attr.getAttrParms() != null + && attr.getAttrParms().size() == 1 + && attr.getAttrParms().get(0).getName() == null) { + // If we are in this branch, + // then the user has provided @attr("value"), + // which is a shorthand for @attr(value="value"). + if (paramSpecByName == null) { + validator.error("Attribute doesn't take a parameter.", Literals.ATTRIBUTE__ATTR_NAME); + return; + } + AttrParamSpec valueSpec = paramSpecByName.get(VALUE_ATTR); + if (valueSpec == null) { + validator.error("Attribute doesn't have a 'value' parameter.", Literals.ATTR_PARM__NAME); + return; + } + + valueSpec.check(validator, attr.getAttrParms().get(0)); + seen = Set.of(VALUE_ATTR); + } else { + // Process multiple parameters, each of which has to be named. + seen = processNamedAttrParms(validator, attr); } - /** - * Check that the attribute conforms to this spec and whether - * attr has the correct name. - */ - public void check(LFValidator validator, Attribute attr) { - Set seen; - // If there is just one parameter, it is required to be named "value". - if (attr.getAttrParms() != null - && attr.getAttrParms().size() == 1 - && attr.getAttrParms().get(0).getName() == null) { - // If we are in this branch, - // then the user has provided @attr("value"), - // which is a shorthand for @attr(value="value"). - if (paramSpecByName == null) { - validator.error("Attribute doesn't take a parameter.", Literals.ATTRIBUTE__ATTR_NAME); - return; + // Check if there are any missing parameters required by this attribute. + if (paramSpecByName != null) { + Map missingParams = new HashMap<>(paramSpecByName); + missingParams.keySet().removeAll(seen); + missingParams.forEach( + (name, paramSpec) -> { + if (!paramSpec.isOptional) { + validator.error( + "Missing required attribute parameter '" + name + "'.", + Literals.ATTRIBUTE__ATTR_PARMS); } - AttrParamSpec valueSpec = paramSpecByName.get(VALUE_ATTR); - if (valueSpec == null) { - validator.error("Attribute doesn't have a 'value' parameter.", Literals.ATTR_PARM__NAME); - return; - } - - valueSpec.check(validator, attr.getAttrParms().get(0)); - seen = Set.of(VALUE_ATTR); - } else { - // Process multiple parameters, each of which has to be named. - seen = processNamedAttrParms(validator, attr); + }); + } + } + + /** + * Check whether the attribute parameters are named, whether these names are known, and whether + * the named parameters conform to the param spec (whether the param has the right type, etc.). + * + * @param validator The current validator in use. + * @param attr The attribute being checked. + * @return A set of named attribute parameters the user provides. + */ + private Set processNamedAttrParms(LFValidator validator, Attribute attr) { + Set seen = new HashSet<>(); + if (attr.getAttrParms() != null) { + for (AttrParm parm : attr.getAttrParms()) { + if (paramSpecByName == null) { + validator.error("Attribute does not take parameters.", Literals.ATTRIBUTE__ATTR_NAME); + break; } - - // Check if there are any missing parameters required by this attribute. - if (paramSpecByName != null) { - Map missingParams = new HashMap<>(paramSpecByName); - missingParams.keySet().removeAll(seen); - missingParams.forEach((name, paramSpec) -> { - if (!paramSpec.isOptional) { - validator.error("Missing required attribute parameter '" + name + "'.", Literals.ATTRIBUTE__ATTR_PARMS); - } - }); + if (parm.getName() == null) { + validator.error("Missing name for attribute parameter.", Literals.ATTRIBUTE__ATTR_NAME); + continue; } - } - /** - * Check whether the attribute parameters are named, whether - * these names are known, and whether the named parameters - * conform to the param spec (whether the param has the - * right type, etc.). - * - * @param validator The current validator in use. - * @param attr The attribute being checked. - * @return A set of named attribute parameters the user provides. - */ - private Set processNamedAttrParms(LFValidator validator, Attribute attr) { - Set seen = new HashSet<>(); - if (attr.getAttrParms() != null) { - for (AttrParm parm : attr.getAttrParms()) { - if (paramSpecByName == null) { - validator.error("Attribute does not take parameters.", Literals.ATTRIBUTE__ATTR_NAME); - break; - } - if (parm.getName() == null) { - validator.error("Missing name for attribute parameter.", Literals.ATTRIBUTE__ATTR_NAME); - continue; - } - - AttrParamSpec parmSpec = paramSpecByName.get(parm.getName()); - if (parmSpec == null) { - validator.error("\"" + parm.getName() + "\"" + " is an unknown attribute parameter.", - Literals.ATTRIBUTE__ATTR_NAME); - continue; - } - // Check whether a parameter conforms to its spec. - parmSpec.check(validator, parm); - seen.add(parm.getName()); - } + AttrParamSpec parmSpec = paramSpecByName.get(parm.getName()); + if (parmSpec == null) { + validator.error( + "\"" + parm.getName() + "\"" + " is an unknown attribute parameter.", + Literals.ATTRIBUTE__ATTR_NAME); + continue; } - return seen; + // Check whether a parameter conforms to its spec. + parmSpec.check(validator, parm); + seen.add(parm.getName()); + } } - - /** - * The specification of the attribute parameter. - * - * @param name The name of the attribute parameter - * @param type The type of the parameter - * @param isOptional True if the parameter is optional. - */ - record AttrParamSpec(String name, AttrParamType type, boolean isOptional) { - - // Check if a parameter has the right type. - // Currently, only String, Int, Boolean, Float, and target language are supported. - public void check(LFValidator validator, AttrParm parm) { - switch (type) { - case STRING -> { - if (!StringUtil.hasQuotes(parm.getValue())) { - validator.error("Incorrect type: \"" + parm.getName() + "\"" - + " should have type String.", - Literals.ATTRIBUTE__ATTR_NAME); - } - } - case INT -> { - if (!ASTUtils.isInteger(parm.getValue())) { - validator.error( - "Incorrect type: \"" + parm.getName() + "\"" - + " should have type Int.", - Literals.ATTRIBUTE__ATTR_NAME); - } - } - case BOOLEAN -> { - if (!ASTUtils.isBoolean(parm.getValue())) { - validator.error( - "Incorrect type: \"" + parm.getName() + "\"" - + " should have type Boolean.", - Literals.ATTRIBUTE__ATTR_NAME); - } - } - case FLOAT -> { - if (!ASTUtils.isFloat(parm.getValue())) { - validator.error( - "Incorrect type: \"" + parm.getName() + "\"" - + " should have type Float.", - Literals.ATTRIBUTE__ATTR_NAME); - } - } - default -> throw new IllegalArgumentException("unexpected type"); - } + return seen; + } + + /** + * The specification of the attribute parameter. + * + * @param name The name of the attribute parameter + * @param type The type of the parameter + * @param isOptional True if the parameter is optional. + */ + record AttrParamSpec(String name, AttrParamType type, boolean isOptional) { + + // Check if a parameter has the right type. + // Currently, only String, Int, Boolean, Float, and target language are supported. + public void check(LFValidator validator, AttrParm parm) { + switch (type) { + case STRING -> { + if (!StringUtil.hasQuotes(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type String.", + Literals.ATTRIBUTE__ATTR_NAME); + } } + case INT -> { + if (!ASTUtils.isInteger(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type Int.", + Literals.ATTRIBUTE__ATTR_NAME); + } + } + case BOOLEAN -> { + if (!ASTUtils.isBoolean(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type Boolean.", + Literals.ATTRIBUTE__ATTR_NAME); + } + } + case FLOAT -> { + if (!ASTUtils.isFloat(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type Float.", + Literals.ATTRIBUTE__ATTR_NAME); + } + } + default -> throw new IllegalArgumentException("unexpected type"); + } } - - /** - * The type of attribute parameters currently supported. - */ - enum AttrParamType { - STRING, - INT, - BOOLEAN, - FLOAT, - } - - /* - * The specs of the known annotations are declared here. - * Note: If an attribute only has one parameter, the parameter name should be "value." - */ - static { - // @label("value") - ATTRIBUTE_SPECS_BY_NAME.put("label", new AttributeSpec( - List.of(new AttrParamSpec(VALUE_ATTR, AttrParamType.STRING, false)) - )); - // @sparse - ATTRIBUTE_SPECS_BY_NAME.put("sparse", new AttributeSpec(null)); - // @icon("value") - ATTRIBUTE_SPECS_BY_NAME.put("icon", new AttributeSpec( - List.of(new AttrParamSpec(VALUE_ATTR, AttrParamType.STRING, false)) - )); - // @enclave(each=boolean) - ATTRIBUTE_SPECS_BY_NAME.put("enclave", new AttributeSpec( - List.of(new AttrParamSpec(EACH_ATTR, AttrParamType.BOOLEAN, true)) - )); - - // attributes that are used internally only by the federated code generation - ATTRIBUTE_SPECS_BY_NAME.put("_unordered", new AttributeSpec(null)); - ATTRIBUTE_SPECS_BY_NAME.put("_fed_config", new AttributeSpec( - List.of(new AttrParamSpec(AttributeSpec.NETWORK_MESSAGE_ACTIONS, - AttrParamType.STRING, false)))); - ATTRIBUTE_SPECS_BY_NAME.put("_c_body", new AttributeSpec(null)); - } + } + + /** The type of attribute parameters currently supported. */ + enum AttrParamType { + STRING, + INT, + BOOLEAN, + FLOAT, + } + + /* + * The specs of the known annotations are declared here. + * Note: If an attribute only has one parameter, the parameter name should be "value." + */ + static { + // @label("value") + ATTRIBUTE_SPECS_BY_NAME.put( + "label", + new AttributeSpec(List.of(new AttrParamSpec(VALUE_ATTR, AttrParamType.STRING, false)))); + // @sparse + ATTRIBUTE_SPECS_BY_NAME.put("sparse", new AttributeSpec(null)); + // @icon("value") + ATTRIBUTE_SPECS_BY_NAME.put( + "icon", + new AttributeSpec(List.of(new AttrParamSpec(VALUE_ATTR, AttrParamType.STRING, false)))); + // @enclave(each=boolean) + ATTRIBUTE_SPECS_BY_NAME.put( + "enclave", + new AttributeSpec(List.of(new AttrParamSpec(EACH_ATTR, AttrParamType.BOOLEAN, true)))); + + // attributes that are used internally only by the federated code generation + ATTRIBUTE_SPECS_BY_NAME.put("_unordered", new AttributeSpec(null)); + ATTRIBUTE_SPECS_BY_NAME.put( + "_fed_config", + new AttributeSpec( + List.of( + new AttrParamSpec( + AttributeSpec.NETWORK_MESSAGE_ACTIONS, AttrParamType.STRING, false)))); + ATTRIBUTE_SPECS_BY_NAME.put("_c_body", new AttributeSpec(null)); + } } diff --git a/org.lflang/src/org/lflang/validation/BaseLFValidator.java b/org.lflang/src/org/lflang/validation/BaseLFValidator.java index 34e184a720..bcdc14dd94 100644 --- a/org.lflang/src/org/lflang/validation/BaseLFValidator.java +++ b/org.lflang/src/org/lflang/validation/BaseLFValidator.java @@ -28,55 +28,53 @@ import java.lang.reflect.Method; import java.util.Map; - import org.eclipse.emf.common.util.DiagnosticChain; import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.validation.Check; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.CheckType; -import org.lflang.ast.ASTUtils; import org.lflang.TimeUnit; +import org.lflang.ast.ASTUtils; import org.lflang.lf.LfPackage.Literals; import org.lflang.lf.Time; public class BaseLFValidator extends AbstractLFValidator { - @Check(CheckType.FAST) - public void checkTime(Time time) { - if (!ASTUtils.isValidTime(time)) { - error("Invalid time unit. " + - "Should be one of " + - TimeUnit.list() + ".", Literals.TIME__UNIT); - } + @Check(CheckType.FAST) + public void checkTime(Time time) { + if (!ASTUtils.isValidTime(time)) { + error( + "Invalid time unit. " + "Should be one of " + TimeUnit.list() + ".", Literals.TIME__UNIT); } + } - /** - * Provides convenient access to the inner state of the validator. - *

    - * The validator only gives protected access to its own state. With - * this class, we can grant access to the inner state to other objects. - * - * @author Christian Menard - */ - protected class ValidatorStateAccess { - public EObject getCurrentObject() { - return BaseLFValidator.this.getCurrentObject(); - } + /** + * Provides convenient access to the inner state of the validator. + * + *

    The validator only gives protected access to its own state. With this class, we can grant + * access to the inner state to other objects. + * + * @author Christian Menard + */ + protected class ValidatorStateAccess { + public EObject getCurrentObject() { + return BaseLFValidator.this.getCurrentObject(); + } - public Method getCurrentMethod() { - return BaseLFValidator.this.getCurrentMethod(); - } + public Method getCurrentMethod() { + return BaseLFValidator.this.getCurrentMethod(); + } - public DiagnosticChain getChain() { - return BaseLFValidator.this.getChain(); - } + public DiagnosticChain getChain() { + return BaseLFValidator.this.getChain(); + } - public CheckMode getCheckMode() { - return BaseLFValidator.this.getCheckMode(); - } + public CheckMode getCheckMode() { + return BaseLFValidator.this.getCheckMode(); + } - public Map getContext() { - return BaseLFValidator.this.getContext(); - } + public Map getContext() { + return BaseLFValidator.this.getContext(); } + } } diff --git a/org.lflang/src/org/lflang/validation/LFNamesAreUniqueValidationHelper.java b/org.lflang/src/org/lflang/validation/LFNamesAreUniqueValidationHelper.java index 75020fdc2b..9c6267cb0a 100644 --- a/org.lflang/src/org/lflang/validation/LFNamesAreUniqueValidationHelper.java +++ b/org.lflang/src/org/lflang/validation/LFNamesAreUniqueValidationHelper.java @@ -2,27 +2,24 @@ import org.eclipse.emf.ecore.EClass; import org.eclipse.xtext.validation.NamesAreUniqueValidationHelper; - import org.lflang.lf.LfPackage; public class LFNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper { - /** - * Lump all inputs, outputs, timers, actions, parameters, and - * instantiations in the same cluster type. This ensures that - * names amongst them are checked for uniqueness. - */ - @Override public EClass getAssociatedClusterType(EClass eClass) { - if (LfPackage.Literals.INPUT == eClass || - LfPackage.Literals.OUTPUT == eClass || - LfPackage.Literals.TIMER == eClass || - LfPackage.Literals.ACTION == eClass || - LfPackage.Literals.PARAMETER == eClass || - LfPackage.Literals.INSTANTIATION == eClass - ) { - return LfPackage.Literals.VARIABLE; - } - return super.getAssociatedClusterType(eClass); + /** + * Lump all inputs, outputs, timers, actions, parameters, and instantiations in the same cluster + * type. This ensures that names amongst them are checked for uniqueness. + */ + @Override + public EClass getAssociatedClusterType(EClass eClass) { + if (LfPackage.Literals.INPUT == eClass + || LfPackage.Literals.OUTPUT == eClass + || LfPackage.Literals.TIMER == eClass + || LfPackage.Literals.ACTION == eClass + || LfPackage.Literals.PARAMETER == eClass + || LfPackage.Literals.INSTANTIATION == eClass) { + return LfPackage.Literals.VARIABLE; } - + return super.getAssociatedClusterType(eClass); + } } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 36c09cf678..747b22ffc3 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -2,17 +2,17 @@ /************* * Copyright (c) 2019-2020, The University of California at Berkeley. - + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -28,12 +28,10 @@ import static org.lflang.ast.ASTUtils.inferPortWidth; import static org.lflang.ast.ASTUtils.isGeneric; -import static org.lflang.ast.ASTUtils.isInteger; -import static org.lflang.ast.ASTUtils.isOfTimeType; -import static org.lflang.ast.ASTUtils.isZero; import static org.lflang.ast.ASTUtils.toDefinition; import static org.lflang.ast.ASTUtils.toOriginalText; +import com.google.inject.Inject; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -46,7 +44,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAttribute; @@ -56,13 +53,13 @@ import org.eclipse.xtext.validation.Check; import org.eclipse.xtext.validation.CheckType; import org.eclipse.xtext.validation.ValidationMessageAcceptor; -import org.lflang.ast.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.ModelInfo; import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.TimeValue; +import org.lflang.ast.ASTUtils; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.federated.validation.FedValidator; import org.lflang.generator.NamedInstance; @@ -117,12 +114,10 @@ import org.lflang.lf.WidthTerm; import org.lflang.util.FileUtil; -import com.google.inject.Inject; - /** * Custom validation checks for Lingua Franca programs. * - * Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation + *

    Also see: https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation * * @author Edward A. Lee * @author Marten Lohstroh @@ -133,1763 +128,1853 @@ */ public class LFValidator extends BaseLFValidator { - ////////////////////////////////////////////////////////////// - //// Public check methods. - - // These methods are automatically invoked on AST nodes matching - // the types of their arguments. - // CheckType.FAST ensures that these checks run whenever a file is modified. - // Alternatives are CheckType.NORMAL (when saving) and - // CheckType.EXPENSIVE (only when right-click, validate). - // FIXME: What is the default when nothing is specified? - - // These methods are listed in alphabetical order, and, although - // it is isn't strictly required, follow a naming convention - // checkClass, where Class is the AST class, where possible. - - @Check(CheckType.FAST) - public void checkAction(Action action) { - checkName(action.getName(), Literals.VARIABLE__NAME); - if (action.getOrigin() == ActionOrigin.NONE) { - error( - "Action must have modifier {@code logical} or {@code physical}.", - Literals.ACTION__ORIGIN - ); - } - if (action.getPolicy() != null && - !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { - error( - "Unrecognized spacing violation policy: " + action.getPolicy() + - ". Available policies are: " + - String.join(", ", SPACING_VIOLATION_POLICIES) + ".", - Literals.ACTION__POLICY); - } - checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); - checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); + ////////////////////////////////////////////////////////////// + //// Public check methods. + + // These methods are automatically invoked on AST nodes matching + // the types of their arguments. + // CheckType.FAST ensures that these checks run whenever a file is modified. + // Alternatives are CheckType.NORMAL (when saving) and + // CheckType.EXPENSIVE (only when right-click, validate). + // FIXME: What is the default when nothing is specified? + + // These methods are listed in alphabetical order, and, although + // it is isn't strictly required, follow a naming convention + // checkClass, where Class is the AST class, where possible. + + @Check(CheckType.FAST) + public void checkAction(Action action) { + checkName(action.getName(), Literals.VARIABLE__NAME); + if (action.getOrigin() == ActionOrigin.NONE) { + error( + "Action must have modifier {@code logical} or {@code physical}.", + Literals.ACTION__ORIGIN); } - - - @Check(CheckType.FAST) - public void checkInitializer(Initializer init) { - if (init.isBraces() && target != Target.CPP) { - error("Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); - } else if (init.isParens() && target.mandatesEqualsInitializers()) { - var message = "This syntax is deprecated in the " + target - + " target, use an equal sign instead of parentheses for assignment."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, Literals.INITIALIZER__PARENS); - } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { - var feature = init.isBraces() ? Literals.INITIALIZER__BRACES - : Literals.INITIALIZER__PARENS; - var message = "This syntax is deprecated, do not use parentheses or braces but an equal sign."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, feature); - } + if (action.getPolicy() != null && !SPACING_VIOLATION_POLICIES.contains(action.getPolicy())) { + error( + "Unrecognized spacing violation policy: " + + action.getPolicy() + + ". Available policies are: " + + String.join(", ", SPACING_VIOLATION_POLICIES) + + ".", + Literals.ACTION__POLICY); } - - @Check(CheckType.FAST) - public void checkBracedExpression(BracedListExpression expr) { - if (!target.allowsBracedListExpressions()) { - var message = "Braced expression lists are not a valid expression for the " + target - + " target."; - error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); - } + checkExpressionIsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); + checkExpressionIsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); + } + + @Check(CheckType.FAST) + public void checkInitializer(Initializer init) { + if (init.isBraces() && target != Target.CPP) { + error( + "Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); + } else if (init.isParens() && target.mandatesEqualsInitializers()) { + var message = + "This syntax is deprecated in the " + + target + + " target, use an equal sign instead of parentheses for assignment."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, Literals.INITIALIZER__PARENS); + } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { + var feature = init.isBraces() ? Literals.INITIALIZER__BRACES : Literals.INITIALIZER__PARENS; + var message = + "This syntax is deprecated, do not use parentheses or braces but an equal sign."; + if (init.getExprs().size() == 1) { + message += " (run the formatter to fix this automatically)"; + } + warning(message, feature); } - - @Check(CheckType.FAST) - public void checkAssignment(Assignment assignment) { - - // If the left-hand side is a time parameter, make sure the assignment has units - typeCheck(assignment.getRhs(), ASTUtils.getInferredType(assignment.getLhs()), Literals.ASSIGNMENT__RHS); - // If this assignment overrides a parameter that is used in a deadline, - // report possible overflow. - if (isCBasedTarget() && - this.info.overflowingAssignments.contains(assignment)) { - error( - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.ASSIGNMENT__RHS); - } - + } + + @Check(CheckType.FAST) + public void checkBracedExpression(BracedListExpression expr) { + if (!target.allowsBracedListExpressions()) { + var message = + "Braced expression lists are not a valid expression for the " + target + " target."; + error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); } + } + + @Check(CheckType.FAST) + public void checkAssignment(Assignment assignment) { + + // If the left-hand side is a time parameter, make sure the assignment has units + typeCheck( + assignment.getRhs(), + ASTUtils.getInferredType(assignment.getLhs()), + Literals.ASSIGNMENT__RHS); + // If this assignment overrides a parameter that is used in a deadline, + // report possible overflow. + if (isCBasedTarget() && this.info.overflowingAssignments.contains(assignment)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds.", + Literals.ASSIGNMENT__RHS); + } + } - @Check(CheckType.FAST) - public void checkConnection(Connection connection) { - - // Report if connection is part of a cycle. - Set> cycles = this.info.topologyCycles(); - for (VarRef lp : connection.getLeftPorts()) { - for (VarRef rp : connection.getRightPorts()) { - boolean leftInCycle = false; - - for (NamedInstance it : cycles) { - if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) - || (it.getDefinition().equals(lp.getVariable()) && it.getParent().equals(lp.getContainer()))) { - leftInCycle = true; - break; - } - } - - for (NamedInstance it : cycles) { - if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) - || (it.getDefinition().equals(rp.getVariable()) && it.getParent().equals(rp.getContainer()))) { - if (leftInCycle) { - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - String reactorName = reactor.getName(); - error(String.format("Connection in reactor %s creates", reactorName) + - String.format("a cyclic dependency between %s and %s.", toOriginalText(lp), toOriginalText(rp)), - Literals.CONNECTION__DELAY); - } - } - } - } - } - - // FIXME: look up all ReactorInstance objects that have a definition equal to the - // container of this connection. For each of those occurrences, the widths have to match. - // For the C target, since C has such a weak type system, check that - // the types on both sides of every connection match. For other languages, - // we leave type compatibility that language's compiler or interpreter. - if (isCBasedTarget()) { - Type type = (Type) null; - for (VarRef port : (Iterable) () -> Stream.concat( - connection.getLeftPorts().stream(), - connection.getRightPorts().stream() - ).iterator()) { - // If the variable is not a port, then there is some other - // error. Avoid a class cast exception. - if (port.getVariable() instanceof Port) { - if (type == null) { - type = ((Port) port.getVariable()).getType(); - } else { - var portType = ((Port) port.getVariable()).getType(); - portType = port.getContainer() == null ? portType : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); - if (!sameType(type, portType)) { - error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); - } - } - } - } - } + @Check(CheckType.FAST) + public void checkConnection(Connection connection) { - // Check whether the total width of the left side of the connection - // matches the total width of the right side. This cannot be determined - // here if the width is not given as a constant. In that case, it is up - // to the code generator to check it. - int leftWidth = 0; - for (VarRef port : connection.getLeftPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || leftWidth < 0) { - // Cannot determine the width of the left ports. - leftWidth = -1; - } else { - leftWidth += width; - } - } - int rightWidth = 0; - for (VarRef port : connection.getRightPorts()) { - int width = inferPortWidth(port, null, null); // null args imply incomplete check. - if (width < 0 || rightWidth < 0) { - // Cannot determine the width of the left ports. - rightWidth = -1; - } else { - rightWidth += width; - } - } + // Report if connection is part of a cycle. + Set> cycles = this.info.topologyCycles(); + for (VarRef lp : connection.getLeftPorts()) { + for (VarRef rp : connection.getRightPorts()) { + boolean leftInCycle = false; - if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { - if (connection.isIterated()) { - if (leftWidth == 0 || rightWidth % leftWidth != 0) { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning(String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS - ); - } - } else { - // FIXME: The second argument should be Literals.CONNECTION, but - // stupidly, xtext will not accept that. There seems to be no way to - // report an error for the whole connection statement. - warning(String.format("Left width %s does not match right width %s", leftWidth, rightWidth), - Literals.CONNECTION__LEFT_PORTS - ); - } - } - - Reactor reactor = ASTUtils.getEnclosingReactor(connection); - - // Make sure the right port is not already an effect of a reaction. - for (Reaction reaction : ASTUtils.allReactions(reactor)) { - for (VarRef effect : reaction.getEffects()) { - for (VarRef rightPort : connection.getRightPorts()) { - if (rightPort.getVariable().equals(effect.getVariable()) && // Refers to the same variable - rightPort.getContainer() == effect.getContainer() && // Refers to the same instance - ( reaction.eContainer() instanceof Reactor || // Either is not part of a mode - connection.eContainer() instanceof Reactor || - connection.eContainer() == reaction.eContainer() // Or they are in the same mode - )) { - error("Cannot connect: Port named '" + effect.getVariable().getName() + - "' is already effect of a reaction.", - Literals.CONNECTION__RIGHT_PORTS); - } - } - } + for (NamedInstance it : cycles) { + if ((lp.getContainer() == null && it.getDefinition().equals(lp.getVariable())) + || (it.getDefinition().equals(lp.getVariable()) + && it.getParent().equals(lp.getContainer()))) { + leftInCycle = true; + break; + } } - // Check that the right port does not already have some other - // upstream connection. - for (Connection c : reactor.getConnections()) { - if (c != connection) { - for (VarRef thisRightPort : connection.getRightPorts()) { - for (VarRef thatRightPort : c.getRightPorts()) { - if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) && // Refers to the same variable - thisRightPort.getContainer() == thatRightPort.getContainer() && // Refers to the same instance - ( connection.eContainer() instanceof Reactor || // Or either of the connections in not part of a mode - c.eContainer() instanceof Reactor || - connection.eContainer() == c.eContainer() // Or they are in the same mode - )) { - error( - "Cannot connect: Port named '" + thisRightPort.getVariable().getName() + - "' may only appear once on the right side of a connection.", - Literals.CONNECTION__RIGHT_PORTS); - } - } - } + for (NamedInstance it : cycles) { + if ((rp.getContainer() == null && it.getDefinition().equals(rp.getVariable())) + || (it.getDefinition().equals(rp.getVariable()) + && it.getParent().equals(rp.getContainer()))) { + if (leftInCycle) { + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + String reactorName = reactor.getName(); + error( + String.format("Connection in reactor %s creates", reactorName) + + String.format( + "a cyclic dependency between %s and %s.", + toOriginalText(lp), toOriginalText(rp)), + Literals.CONNECTION__DELAY); } + } } + } + } - // Check the after delay - if (connection.getDelay() != null) { - final var delay = connection.getDelay(); - if (delay instanceof ParameterReference || delay instanceof Time || delay instanceof Literal) { - checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); - } else { - error("After delays can only be given by time literals or parameters.", - Literals.CONNECTION__DELAY); + // FIXME: look up all ReactorInstance objects that have a definition equal to the + // container of this connection. For each of those occurrences, the widths have to match. + // For the C target, since C has such a weak type system, check that + // the types on both sides of every connection match. For other languages, + // we leave type compatibility that language's compiler or interpreter. + if (isCBasedTarget()) { + Type type = (Type) null; + for (VarRef port : + (Iterable) + () -> + Stream.concat( + connection.getLeftPorts().stream(), connection.getRightPorts().stream()) + .iterator()) { + // If the variable is not a port, then there is some other + // error. Avoid a class cast exception. + if (port.getVariable() instanceof Port) { + if (type == null) { + type = ((Port) port.getVariable()).getType(); + } else { + var portType = ((Port) port.getVariable()).getType(); + portType = + port.getContainer() == null + ? portType + : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); + if (!sameType(type, portType)) { + error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); } + } } + } } - @Check(CheckType.FAST) - public void checkDeadline(Deadline deadline) { - if (isCBasedTarget() && - this.info.overflowingDeadlines.contains(deadline)) { - error( - "Deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.DEADLINE__DELAY); - } - checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); + // Check whether the total width of the left side of the connection + // matches the total width of the right side. This cannot be determined + // here if the width is not given as a constant. In that case, it is up + // to the code generator to check it. + int leftWidth = 0; + for (VarRef port : connection.getLeftPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || leftWidth < 0) { + // Cannot determine the width of the left ports. + leftWidth = -1; + } else { + leftWidth += width; + } } - - @Check(CheckType.FAST) - public void checkHost(Host host) { - String addr = host.getAddr(); - String user = host.getUser(); - if (user != null && !user.matches(USERNAME_REGEX)) { - warning( - "Invalid user name.", - Literals.HOST__USER - ); - } - if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { - warning( - "Invalid IP address.", - Literals.HOST__ADDR - ); - } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { - warning( - "Invalid IP address.", - Literals.HOST__ADDR - ); - } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { - warning( - "Invalid host name or fully qualified domain name.", - Literals.HOST__ADDR - ); - } + int rightWidth = 0; + for (VarRef port : connection.getRightPorts()) { + int width = inferPortWidth(port, null, null); // null args imply incomplete check. + if (width < 0 || rightWidth < 0) { + // Cannot determine the width of the left ports. + rightWidth = -1; + } else { + rightWidth += width; + } } - @Check - public void checkImport(Import imp) { - if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { - error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. - return; - } - - // FIXME: report error if resource cannot be resolved. - for (ImportedReactor reactor : imp.getReactorClasses()) { - if (!isUnused(reactor)) { - return; - } - } - warning("Unused import.", Literals.IMPORT__IMPORT_URI); + if (leftWidth != -1 && rightWidth != -1 && leftWidth != rightWidth) { + if (connection.isIterated()) { + if (leftWidth == 0 || rightWidth % leftWidth != 0) { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning( + String.format("Left width %s does not divide right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS); + } + } else { + // FIXME: The second argument should be Literals.CONNECTION, but + // stupidly, xtext will not accept that. There seems to be no way to + // report an error for the whole connection statement. + warning( + String.format("Left width %s does not match right width %s", leftWidth, rightWidth), + Literals.CONNECTION__LEFT_PORTS); + } } - @Check - public void checkImportedReactor(ImportedReactor reactor) { - if (isUnused(reactor)) { - warning("Unused reactor class.", - Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } - - if (info.instantiationGraph.hasCycles()) { - Set cycleSet = new HashSet<>(); - for (Set cycle : info.instantiationGraph.getCycles()) { - cycleSet.addAll(cycle); - } - if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { - error("Imported reactor '" + toDefinition(reactor).getName() + - "' has cyclic instantiation in it.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); - } + Reactor reactor = ASTUtils.getEnclosingReactor(connection); + + // Make sure the right port is not already an effect of a reaction. + for (Reaction reaction : ASTUtils.allReactions(reactor)) { + for (VarRef effect : reaction.getEffects()) { + for (VarRef rightPort : connection.getRightPorts()) { + if (rightPort.getVariable().equals(effect.getVariable()) + && // Refers to the same variable + rightPort.getContainer() == effect.getContainer() + && // Refers to the same instance + (reaction.eContainer() instanceof Reactor + || // Either is not part of a mode + connection.eContainer() instanceof Reactor + || connection.eContainer() + == reaction.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + + effect.getVariable().getName() + + "' is already effect of a reaction.", + Literals.CONNECTION__RIGHT_PORTS); + } } + } } - @Check(CheckType.FAST) - public void checkInput(Input input) { - Reactor parent = (Reactor)input.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); - } - checkName(input.getName(), Literals.VARIABLE__NAME); - if (target.requiresTypes) { - if (input.getType() == null) { - error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); + // Check that the right port does not already have some other + // upstream connection. + for (Connection c : reactor.getConnections()) { + if (c != connection) { + for (VarRef thisRightPort : connection.getRightPorts()) { + for (VarRef thatRightPort : c.getRightPorts()) { + if (thisRightPort.getVariable().equals(thatRightPort.getVariable()) + && // Refers to the same variable + thisRightPort.getContainer() == thatRightPort.getContainer() + && // Refers to the same instance + (connection.eContainer() instanceof Reactor + || // Or either of the connections in not part of a mode + c.eContainer() instanceof Reactor + || connection.eContainer() == c.eContainer() // Or they are in the same mode + )) { + error( + "Cannot connect: Port named '" + + thisRightPort.getVariable().getName() + + "' may only appear once on the right side of a connection.", + Literals.CONNECTION__RIGHT_PORTS); } + } } - - // mutable has no meaning in C++ - if (input.isMutable() && this.target == Target.CPP) { - warning( - "The mutable qualifier has no meaning for the C++ target and should be removed. " + - "In C++, any value can be made mutable by calling get_mutable_copy().", - Literals.INPUT__MUTABLE - ); - } - - // Variable width multiports are not supported (yet?). - if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); - } + } } - @Check(CheckType.FAST) - public void checkInstantiation(Instantiation instantiation) { - checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); - Reactor reactor = toDefinition(instantiation.getReactorClass()); - if (reactor.isMain() || reactor.isFederated()) { - error( - "Cannot instantiate a main (or federated) reactor: " + - instantiation.getReactorClass().getName(), - Literals.INSTANTIATION__REACTOR_CLASS - ); - } + // Check the after delay + if (connection.getDelay() != null) { + final var delay = connection.getDelay(); + if (delay instanceof ParameterReference + || delay instanceof Time + || delay instanceof Literal) { + checkExpressionIsTime(delay, Literals.CONNECTION__DELAY); + } else { + error( + "After delays can only be given by time literals or parameters.", + Literals.CONNECTION__DELAY); + } + } + } + + @Check(CheckType.FAST) + public void checkDeadline(Deadline deadline) { + if (isCBasedTarget() && this.info.overflowingDeadlines.contains(deadline)) { + error( + "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.DEADLINE__DELAY); + } + checkExpressionIsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); + } + + @Check(CheckType.FAST) + public void checkHost(Host host) { + String addr = host.getAddr(); + String user = host.getUser(); + if (user != null && !user.matches(USERNAME_REGEX)) { + warning("Invalid user name.", Literals.HOST__USER); + } + if (host instanceof IPV4Host && !addr.matches(IPV4_REGEX)) { + warning("Invalid IP address.", Literals.HOST__ADDR); + } else if (host instanceof IPV6Host && !addr.matches(IPV6_REGEX)) { + warning("Invalid IP address.", Literals.HOST__ADDR); + } else if (host instanceof NamedHost && !addr.matches(HOST_OR_FQN_REGEX)) { + warning("Invalid host name or fully qualified domain name.", Literals.HOST__ADDR); + } + } - // Report error if this instantiation is part of a cycle. - // FIXME: improve error message. - // FIXME: Also report if there exists a cycle within. - if (this.info.instantiationGraph.getCycles().size() > 0) { - for (Set cycle : this.info.instantiationGraph.getCycles()) { - Reactor container = (Reactor) instantiation.eContainer(); - if (cycle.contains(container) && cycle.contains(reactor)) { - List names = new ArrayList<>(); - for (Reactor r : cycle) { - names.add(r.getName()); - } - - error( - "Instantiation is part of a cycle: " + String.join(", ", names) + ".", - Literals.INSTANTIATION__REACTOR_CLASS - ); - } - } - } - // Variable width multiports are not supported (yet?). - if (instantiation.getWidthSpec() != null - && instantiation.getWidthSpec().isOfVariableLength() - ) { - if (isCBasedTarget()) { - warning("Variable-width banks are for internal use only.", - Literals.INSTANTIATION__WIDTH_SPEC - ); - } else { - error("Variable-width banks are not supported.", - Literals.INSTANTIATION__WIDTH_SPEC - ); - } - } + @Check + public void checkImport(Import imp) { + if (toDefinition(imp.getReactorClasses().get(0)).eResource().getErrors().size() > 0) { + error("Error loading resource.", Literals.IMPORT__IMPORT_URI); // FIXME: print specifics. + return; } - /** Check target parameters, which are key-value pairs. */ - @Check(CheckType.FAST) - public void checkKeyValuePair(KeyValuePair param) { - // Check only if the container's container is a Target. - if (param.eContainer().eContainer() instanceof TargetDecl) { - TargetProperty prop = TargetProperty.forName(param.getName()); - - // Make sure the key is valid. - if (prop == null) { - String options = TargetProperty.getOptions().stream() - .map(p -> p.description).sorted() - .collect(Collectors.joining(", ")); - warning( - "Unrecognized target parameter: " + param.getName() + - ". Recognized parameters are: " + options, - Literals.KEY_VALUE_PAIR__NAME); - } else { - // Check whether the property is supported by the target. - if (!prop.supportedBy.contains(this.target)) { - warning( - "The target parameter: " + param.getName() + - " is not supported by the " + this.target + - " target and will thus be ignored.", - Literals.KEY_VALUE_PAIR__NAME); - } + // FIXME: report error if resource cannot be resolved. + for (ImportedReactor reactor : imp.getReactorClasses()) { + if (!isUnused(reactor)) { + return; + } + } + warning("Unused import.", Literals.IMPORT__IMPORT_URI); + } - // Report problem with the assigned value. - prop.type.check(param.getValue(), param.getName(), this); - } + @Check + public void checkImportedReactor(ImportedReactor reactor) { + if (isUnused(reactor)) { + warning("Unused reactor class.", Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } - for (String it : targetPropertyErrors) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyErrors.clear(); + if (info.instantiationGraph.hasCycles()) { + Set cycleSet = new HashSet<>(); + for (Set cycle : info.instantiationGraph.getCycles()) { + cycleSet.addAll(cycle); + } + if (dependsOnCycle(toDefinition(reactor), cycleSet, new HashSet<>())) { + error( + "Imported reactor '" + + toDefinition(reactor).getName() + + "' has cyclic instantiation in it.", + Literals.IMPORTED_REACTOR__REACTOR_CLASS); + } + } + } - for (String it : targetPropertyWarnings) { - error(it, Literals.KEY_VALUE_PAIR__VALUE); - } - targetPropertyWarnings.clear(); - } + @Check(CheckType.FAST) + public void checkInput(Input input) { + Reactor parent = (Reactor) input.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME); + } + checkName(input.getName(), Literals.VARIABLE__NAME); + if (target.requiresTypes) { + if (input.getType() == null) { + error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - @Check(CheckType.FAST) - public void checkModel(Model model) { - // Since we're doing a fast check, we only want to update - // if the model info hasn't been initialized yet. If it has, - // we use the old information and update it during a normal - // check (see below). - if (!info.updated) { - info.update(model, errorReporter); - } + // mutable has no meaning in C++ + if (input.isMutable() && this.target == Target.CPP) { + warning( + "The mutable qualifier has no meaning for the C++ target and should be removed. " + + "In C++, any value can be made mutable by calling get_mutable_copy().", + Literals.INPUT__MUTABLE); } - @Check(CheckType.NORMAL) - public void updateModelInfo(Model model) { - info.update(model, errorReporter); + // Variable width multiports are not supported (yet?). + if (input.getWidthSpec() != null && input.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } + + @Check(CheckType.FAST) + public void checkInstantiation(Instantiation instantiation) { + checkName(instantiation.getName(), Literals.INSTANTIATION__NAME); + Reactor reactor = toDefinition(instantiation.getReactorClass()); + if (reactor.isMain() || reactor.isFederated()) { + error( + "Cannot instantiate a main (or federated) reactor: " + + instantiation.getReactorClass().getName(), + Literals.INSTANTIATION__REACTOR_CLASS); } - @Check(CheckType.FAST) - public void checkOutput(Output output) { - Reactor parent = (Reactor)output.eContainer(); - if (parent.isMain() || parent.isFederated()) { - error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); - } - checkName(output.getName(), Literals.VARIABLE__NAME); - if (this.target.requiresTypes) { - if (output.getType() == null) { - error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); - } - } + // Report error if this instantiation is part of a cycle. + // FIXME: improve error message. + // FIXME: Also report if there exists a cycle within. + if (this.info.instantiationGraph.getCycles().size() > 0) { + for (Set cycle : this.info.instantiationGraph.getCycles()) { + Reactor container = (Reactor) instantiation.eContainer(); + if (cycle.contains(container) && cycle.contains(reactor)) { + List names = new ArrayList<>(); + for (Reactor r : cycle) { + names.add(r.getName()); + } - // Variable width multiports are not supported (yet?). - if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { - error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + error( + "Instantiation is part of a cycle: " + String.join(", ", names) + ".", + Literals.INSTANTIATION__REACTOR_CLASS); } + } + } + // Variable width multiports are not supported (yet?). + if (instantiation.getWidthSpec() != null && instantiation.getWidthSpec().isOfVariableLength()) { + if (isCBasedTarget()) { + warning( + "Variable-width banks are for internal use only.", Literals.INSTANTIATION__WIDTH_SPEC); + } else { + error("Variable-width banks are not supported.", Literals.INSTANTIATION__WIDTH_SPEC); + } + } + } + + /** Check target parameters, which are key-value pairs. */ + @Check(CheckType.FAST) + public void checkKeyValuePair(KeyValuePair param) { + // Check only if the container's container is a Target. + if (param.eContainer().eContainer() instanceof TargetDecl) { + TargetProperty prop = TargetProperty.forName(param.getName()); + + // Make sure the key is valid. + if (prop == null) { + String options = + TargetProperty.getOptions().stream() + .map(p -> p.description) + .sorted() + .collect(Collectors.joining(", ")); + warning( + "Unrecognized target parameter: " + + param.getName() + + ". Recognized parameters are: " + + options, + Literals.KEY_VALUE_PAIR__NAME); + } else { + // Check whether the property is supported by the target. + if (!prop.supportedBy.contains(this.target)) { + warning( + "The target parameter: " + + param.getName() + + " is not supported by the " + + this.target + + " target and will thus be ignored.", + Literals.KEY_VALUE_PAIR__NAME); + } + + // Report problem with the assigned value. + prop.type.check(param.getValue(), param.getName(), this); + } + + for (String it : targetPropertyErrors) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyErrors.clear(); + + for (String it : targetPropertyWarnings) { + error(it, Literals.KEY_VALUE_PAIR__VALUE); + } + targetPropertyWarnings.clear(); + } + } + + @Check(CheckType.FAST) + public void checkModel(Model model) { + // Since we're doing a fast check, we only want to update + // if the model info hasn't been initialized yet. If it has, + // we use the old information and update it during a normal + // check (see below). + if (!info.updated) { + info.update(model, errorReporter); + } + } + + @Check(CheckType.NORMAL) + public void updateModelInfo(Model model) { + info.update(model, errorReporter); + } + + @Check(CheckType.FAST) + public void checkOutput(Output output) { + Reactor parent = (Reactor) output.eContainer(); + if (parent.isMain() || parent.isFederated()) { + error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME); + } + checkName(output.getName(), Literals.VARIABLE__NAME); + if (this.target.requiresTypes) { + if (output.getType() == null) { + error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE); + } } - @Check(CheckType.FAST) - public void checkParameter(Parameter param) { - checkName(param.getName(), Literals.PARAMETER__NAME); - - if (param.getInit() == null) { - // todo make initialization non-mandatory - // https://github.com/lf-lang/lingua-franca/issues/623 - error("Parameter must have a default value.", Literals.PARAMETER__INIT); - return; - } + // Variable width multiports are not supported (yet?). + if (output.getWidthSpec() != null && output.getWidthSpec().isOfVariableLength()) { + error("Variable-width multiports are not supported.", Literals.PORT__WIDTH_SPEC); + } + } - if (this.target.requiresTypes) { - // Report missing target type. param.inferredType.undefine - if (ASTUtils.getInferredType(param).isUndefined()) { - error("Type declaration missing.", Literals.PARAMETER__TYPE); - } - } + @Check(CheckType.FAST) + public void checkParameter(Parameter param) { + checkName(param.getName(), Literals.PARAMETER__NAME); - if (param.getType() != null) { - typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); - } + if (param.getInit() == null) { + // todo make initialization non-mandatory + // https://github.com/lf-lang/lingua-franca/issues/623 + error("Parameter must have a default value.", Literals.PARAMETER__INIT); + return; + } - if (param.getInit() != null) { - for (Expression expr : param.getInit().getExprs()) { - if (expr instanceof ParameterReference) { - // Initialization using parameters is forbidden. - error("Parameter cannot be initialized using parameter.", - Literals.PARAMETER__INIT); - } - } - } + if (this.target.requiresTypes) { + // Report missing target type. param.inferredType.undefine + if (ASTUtils.getInferredType(param).isUndefined()) { + error("Type declaration missing.", Literals.PARAMETER__TYPE); + } + } - if (this.target == Target.CPP) { - EObject container = param.eContainer(); - Reactor reactor = (Reactor) container; - if (reactor.isMain()) { - // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); - if (cliParams.contains(param.getName())) { - error("Parameter '" + param.getName() - + "' is already in use as command line argument by Lingua Franca,", - Literals.PARAMETER__NAME); - } - } - } + if (param.getType() != null) { + typeCheck(param.getInit(), ASTUtils.getInferredType(param), Literals.PARAMETER__INIT); + } - if (isCBasedTarget() && - this.info.overflowingParameters.contains(param)) { - error( - "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.PARAMETER__INIT); + if (param.getInit() != null) { + for (Expression expr : param.getInit().getExprs()) { + if (expr instanceof ParameterReference) { + // Initialization using parameters is forbidden. + error("Parameter cannot be initialized using parameter.", Literals.PARAMETER__INIT); } + } + } + if (this.target == Target.CPP) { + EObject container = param.eContainer(); + Reactor reactor = (Reactor) container; + if (reactor.isMain()) { + // we need to check for the cli parameters that are always taken + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); + if (cliParams.contains(param.getName())) { + error( + "Parameter '" + + param.getName() + + "' is already in use as command line argument by Lingua Franca,", + Literals.PARAMETER__NAME); + } + } } - @Check(CheckType.FAST) - public void checkPreamble(Preamble preamble) { - if (this.target == Target.CPP) { - if (preamble.getVisibility() == Visibility.NONE) { - error( - "Preambles for the C++ target need a visibility qualifier (private or public)!", - Literals.PREAMBLE__VISIBILITY - ); - } else if (preamble.getVisibility() == Visibility.PRIVATE) { - EObject container = preamble.eContainer(); - if (container != null && container instanceof Reactor) { - Reactor reactor = (Reactor) container; - if (isGeneric(reactor)) { - warning( - "Private preambles in generic reactors are not truly private. " + - "Since the generated code is placed in a *_impl.hh file, it will " + - "be visible on the public interface. Consider using a public " + - "preamble within the reactor or a private preamble on file scope.", - Literals.PREAMBLE__VISIBILITY); - } - } - } - } else if (preamble.getVisibility() != Visibility.NONE) { + if (isCBasedTarget() && this.info.overflowingParameters.contains(param)) { + error( + "Time value used to specify a deadline exceeds the maximum of " + + TimeValue.MAX_LONG_DEADLINE + + " nanoseconds.", + Literals.PARAMETER__INIT); + } + } + + @Check(CheckType.FAST) + public void checkPreamble(Preamble preamble) { + if (this.target == Target.CPP) { + if (preamble.getVisibility() == Visibility.NONE) { + error( + "Preambles for the C++ target need a visibility qualifier (private or public)!", + Literals.PREAMBLE__VISIBILITY); + } else if (preamble.getVisibility() == Visibility.PRIVATE) { + EObject container = preamble.eContainer(); + if (container != null && container instanceof Reactor) { + Reactor reactor = (Reactor) container; + if (isGeneric(reactor)) { warning( - String.format("The %s qualifier has no meaning for the %s target. It should be removed.", - preamble.getVisibility(), this.target.name()), - Literals.PREAMBLE__VISIBILITY - ); + "Private preambles in generic reactors are not truly private. " + + "Since the generated code is placed in a *_impl.hh file, it will " + + "be visible on the public interface. Consider using a public " + + "preamble within the reactor or a private preamble on file scope.", + Literals.PREAMBLE__VISIBILITY); + } } + } + } else if (preamble.getVisibility() != Visibility.NONE) { + warning( + String.format( + "The %s qualifier has no meaning for the %s target. It should be removed.", + preamble.getVisibility(), this.target.name()), + Literals.PREAMBLE__VISIBILITY); } + } - @Check(CheckType.FAST) - public void checkReaction(Reaction reaction) { - - if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { - warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); - } - HashSet triggers = new HashSet<>(); - // Make sure input triggers have no container and output sources do. - for (TriggerRef trigger : reaction.getTriggers()) { - if (trigger instanceof VarRef) { - VarRef triggerVarRef = (VarRef) trigger; - triggers.add(triggerVarRef.getVariable()); - if (triggerVarRef instanceof Input) { - if (triggerVarRef.getContainer() != null) { - error(String.format("Cannot have an input of a contained reactor as a trigger: %s.%s", triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } else if (triggerVarRef.getVariable() instanceof Output) { - if (triggerVarRef.getContainer() == null) { - error(String.format("Cannot have an output of this reactor as a trigger: %s", triggerVarRef.getVariable().getName()), - Literals.REACTION__TRIGGERS); - } - } - } - } - - // Make sure input sources have no container and output sources do. - // Also check that a source is not already listed as a trigger. - for (VarRef source : reaction.getSources()) { - if (triggers.contains(source.getVariable())) { - error(String.format("Source is already listed as a trigger: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - if (source.getVariable() instanceof Input) { - if (source.getContainer() != null) { - error(String.format("Cannot have an input of a contained reactor as a source: %s.%s", source.getContainer().getName(), source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } else if (source.getVariable() instanceof Output) { - if (source.getContainer() == null) { - error(String.format("Cannot have an output of this reactor as a source: %s", source.getVariable().getName()), - Literals.REACTION__SOURCES); - } - } - } - - // Make sure output effects have no container and input effects do. - for (VarRef effect : reaction.getEffects()) { - if (effect.getVariable() instanceof Input) { - if (effect.getContainer() == null) { - error(String.format("Cannot have an input of this reactor as an effect: %s", effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } else if (effect.getVariable() instanceof Output) { - if (effect.getContainer() != null) { - error(String.format("Cannot have an output of a contained reactor as an effect: %s.%s", effect.getContainer().getName(), effect.getVariable().getName()), - Literals.REACTION__EFFECTS); - } - } - } - - // // Report error if this reaction is part of a cycle. - Set> cycles = this.info.topologyCycles(); - Reactor reactor = ASTUtils.getEnclosingReactor(reaction); - boolean reactionInCycle = false; - for (NamedInstance it : cycles) { - if (it.getDefinition().equals(reaction)) { - reactionInCycle = true; - break; - } - } - if (reactionInCycle) { - // Report involved triggers. - List trigs = new ArrayList<>(); - for (TriggerRef t : reaction.getTriggers()) { - if (!(t instanceof VarRef)) { - continue; - } - VarRef tVarRef = (VarRef) t; - boolean triggerExistsInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(tVarRef.getVariable())) { - triggerExistsInCycle = true; - break; - } - } - if (triggerExistsInCycle) { - trigs.add(toOriginalText(tVarRef)); - } - } - if (trigs.size() > 0) { - error(String.format("Reaction triggers involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", trigs)), - Literals.REACTION__TRIGGERS); - } + @Check(CheckType.FAST) + public void checkReaction(Reaction reaction) { - // Report involved sources. - List sources = new ArrayList<>(); - for (VarRef t : reaction.getSources()) { - boolean sourceExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - sourceExistInCycle = true; - break; - } - } - if (sourceExistInCycle) { - sources.add(toOriginalText(t)); - } - } - if (sources.size() > 0) { - error(String.format("Reaction sources involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", sources)), - Literals.REACTION__SOURCES); - } - - // Report involved effects. - List effects = new ArrayList<>(); - for (VarRef t : reaction.getEffects()) { - boolean effectExistInCycle = false; - for (NamedInstance c : cycles) { - if (c.getDefinition().equals(t.getVariable())) { - effectExistInCycle = true; - break; - } - } - if (effectExistInCycle) { - effects.add(toOriginalText(t)); - } - } - if (effects.size() > 0) { - error(String.format("Reaction effects involved in cyclic dependency in reactor %s: %s.", reactor.getName(), String.join(", ", effects)), - Literals.REACTION__EFFECTS); - } - - if (trigs.size() + sources.size() == 0) { - error( - String.format("Cyclic dependency due to preceding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction) - ); - } else if (effects.size() == 0) { - error( - String.format("Cyclic dependency due to succeeding reaction. Consider reordering reactions within reactor %s to avoid causality loop.", reactor.getName()), - reaction.eContainer(), - Literals.REACTOR__REACTIONS, - reactor.getReactions().indexOf(reaction) - ); - } - // Not reporting reactions that are part of cycle _only_ due to reaction ordering. - // Moving them won't help solve the problem. - } - // FIXME: improve error message. + if (reaction.getTriggers() == null || reaction.getTriggers().size() == 0) { + warning("Reaction has no trigger.", Literals.REACTION__TRIGGERS); } - - public void checkReactorName(String name) throws IOException { - // Check for illegal names. - checkName(name, Literals.REACTOR_DECL__NAME); - - // C++ reactors may not be called 'preamble' - if (this.target == Target.CPP && name.equalsIgnoreCase("preamble")) { + HashSet triggers = new HashSet<>(); + // Make sure input triggers have no container and output sources do. + for (TriggerRef trigger : reaction.getTriggers()) { + if (trigger instanceof VarRef) { + VarRef triggerVarRef = (VarRef) trigger; + triggers.add(triggerVarRef.getVariable()); + if (triggerVarRef instanceof Input) { + if (triggerVarRef.getContainer() != null) { error( - "Reactor cannot be named '" + name + "'", - Literals.REACTOR_DECL__NAME - ); + String.format( + "Cannot have an input of a contained reactor as a trigger: %s.%s", + triggerVarRef.getContainer().getName(), triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } + } else if (triggerVarRef.getVariable() instanceof Output) { + if (triggerVarRef.getContainer() == null) { + error( + String.format( + "Cannot have an output of this reactor as a trigger: %s", + triggerVarRef.getVariable().getName()), + Literals.REACTION__TRIGGERS); + } } + } } - @Check(CheckType.FAST) - public void checkReactor(Reactor reactor) throws IOException { - String fileName = FileUtil.nameWithoutExtension(reactor.eResource()); - - if (reactor.isFederated() || reactor.isMain()) { - // Do not allow multiple main/federated reactors. - TreeIterator iter = reactor.eResource().getAllContents(); - int nMain = countMainOrFederated(iter); - if (nMain > 1) { - EAttribute attribute = Literals.REACTOR__MAIN; - if (reactor.isFederated()) { - attribute = Literals.REACTOR__FEDERATED; - } - error( - "Multiple definitions of main or federated reactor.", - attribute - ); - } - - if(reactor.getName() != null && !reactor.getName().equals(fileName)) { - // Make sure that if the name is given, it matches the expected name. - error( - "Name of main reactor must match the file name (or be omitted).", - Literals.REACTOR_DECL__NAME - ); - } - - // check the reactor name indicated by the file name - // Skip this check if the file is named __synthetic0. This Name is used during testing, - // and we would get an unexpected error due to the '__' prefix otherwise. - if (!fileName.equals("__synthetic0")) { - checkReactorName(fileName); - } - } else { - // Not federated or main. - if (reactor.getName() == null) { - error( - "Reactor must be named.", - Literals.REACTOR_DECL__NAME - ); - } else { - checkReactorName(reactor.getName()); - - TreeIterator iter = reactor.eResource().getAllContents(); - int nMain = countMainOrFederated(iter); - if (nMain > 0 && reactor.getName().equals(fileName)) { - error( - "Name conflict with main reactor.", - Literals.REACTOR_DECL__NAME - ); - } - } - } + // Make sure input sources have no container and output sources do. + // Also check that a source is not already listed as a trigger. + for (VarRef source : reaction.getSources()) { + if (triggers.contains(source.getVariable())) { + error( + String.format( + "Source is already listed as a trigger: %s", source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + if (source.getVariable() instanceof Input) { + if (source.getContainer() != null) { + error( + String.format( + "Cannot have an input of a contained reactor as a source: %s.%s", + source.getContainer().getName(), source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } else if (source.getVariable() instanceof Output) { + if (source.getContainer() == null) { + error( + String.format( + "Cannot have an output of this reactor as a source: %s", + source.getVariable().getName()), + Literals.REACTION__SOURCES); + } + } + } + // Make sure output effects have no container and input effects do. + for (VarRef effect : reaction.getEffects()) { + if (effect.getVariable() instanceof Input) { + if (effect.getContainer() == null) { + error( + String.format( + "Cannot have an input of this reactor as an effect: %s", + effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } else if (effect.getVariable() instanceof Output) { + if (effect.getContainer() != null) { + error( + String.format( + "Cannot have an output of a contained reactor as an effect: %s.%s", + effect.getContainer().getName(), effect.getVariable().getName()), + Literals.REACTION__EFFECTS); + } + } + } - Set superClasses = ASTUtils.superClasses(reactor); - if (superClasses == null) { - error( - "Problem with superclasses: Either they form a cycle or are not defined", - Literals.REACTOR_DECL__NAME - ); - // Continue checks, but without any superclasses. - superClasses = new LinkedHashSet<>(); + // // Report error if this reaction is part of a cycle. + Set> cycles = this.info.topologyCycles(); + Reactor reactor = ASTUtils.getEnclosingReactor(reaction); + boolean reactionInCycle = false; + for (NamedInstance it : cycles) { + if (it.getDefinition().equals(reaction)) { + reactionInCycle = true; + break; + } + } + if (reactionInCycle) { + // Report involved triggers. + List trigs = new ArrayList<>(); + for (TriggerRef t : reaction.getTriggers()) { + if (!(t instanceof VarRef)) { + continue; + } + VarRef tVarRef = (VarRef) t; + boolean triggerExistsInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(tVarRef.getVariable())) { + triggerExistsInCycle = true; + break; + } } - - if (reactor.getHost() != null) { - if (!reactor.isFederated()) { - error( - "Cannot assign a host to reactor '" + reactor.getName() + - "' because it is not federated.", - Literals.REACTOR__HOST - ); - } + if (triggerExistsInCycle) { + trigs.add(toOriginalText(tVarRef)); + } + } + if (trigs.size() > 0) { + error( + String.format( + "Reaction triggers involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", trigs)), + Literals.REACTION__TRIGGERS); + } + + // Report involved sources. + List sources = new ArrayList<>(); + for (VarRef t : reaction.getSources()) { + boolean sourceExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + sourceExistInCycle = true; + break; + } } - - List variables = new ArrayList<>(); - variables.addAll(reactor.getInputs()); - variables.addAll(reactor.getOutputs()); - variables.addAll(reactor.getActions()); - variables.addAll(reactor.getTimers()); - - if (!reactor.getSuperClasses().isEmpty() && !target.supportsInheritance()) { - error("The " + target.getDisplayName() + " target does not support reactor inheritance.", - Literals.REACTOR__SUPER_CLASSES); + if (sourceExistInCycle) { + sources.add(toOriginalText(t)); + } + } + if (sources.size() > 0) { + error( + String.format( + "Reaction sources involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", sources)), + Literals.REACTION__SOURCES); + } + + // Report involved effects. + List effects = new ArrayList<>(); + for (VarRef t : reaction.getEffects()) { + boolean effectExistInCycle = false; + for (NamedInstance c : cycles) { + if (c.getDefinition().equals(t.getVariable())) { + effectExistInCycle = true; + break; + } } + if (effectExistInCycle) { + effects.add(toOriginalText(t)); + } + } + if (effects.size() > 0) { + error( + String.format( + "Reaction effects involved in cyclic dependency in reactor %s: %s.", + reactor.getName(), String.join(", ", effects)), + Literals.REACTION__EFFECTS); + } + + if (trigs.size() + sources.size() == 0) { + error( + String.format( + "Cyclic dependency due to preceding reaction. Consider reordering reactions within" + + " reactor %s to avoid causality loop.", + reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction)); + } else if (effects.size() == 0) { + error( + String.format( + "Cyclic dependency due to succeeding reaction. Consider reordering reactions within" + + " reactor %s to avoid causality loop.", + reactor.getName()), + reaction.eContainer(), + Literals.REACTOR__REACTIONS, + reactor.getReactions().indexOf(reaction)); + } + // Not reporting reactions that are part of cycle _only_ due to reaction ordering. + // Moving them won't help solve the problem. + } + // FIXME: improve error message. + } - // Perform checks on super classes. - for (Reactor superClass : superClasses) { - HashSet conflicts = new HashSet<>(); - - // Detect input conflicts - checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); - // Detect output conflicts - checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); - // Detect conflicts - for (Timer timer : superClass.getTimers()) { - List filteredVariables = new ArrayList<>(variables); - filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); - if (hasNameConflict(timer, filteredVariables)) { - conflicts.add(timer); - } else { - variables.add(timer); - } - } - - // Report conflicts. - if (conflicts.size() > 0) { - List names = new ArrayList<>(); - for (Variable it : conflicts) { - names.add(it.getName()); - } - error( - String.format("Cannot extend %s due to the following conflicts: %s.", - superClass.getName(), String.join(",", names)), - Literals.REACTOR__SUPER_CLASSES - ); - } - } + public void checkReactorName(String name) throws IOException { + // Check for illegal names. + checkName(name, Literals.REACTOR_DECL__NAME); + // C++ reactors may not be called 'preamble' + if (this.target == Target.CPP && name.equalsIgnoreCase("preamble")) { + error("Reactor cannot be named '" + name + "'", Literals.REACTOR_DECL__NAME); + } + } + + @Check(CheckType.FAST) + public void checkReactor(Reactor reactor) throws IOException { + String fileName = FileUtil.nameWithoutExtension(reactor.eResource()); + + if (reactor.isFederated() || reactor.isMain()) { + // Do not allow multiple main/federated reactors. + TreeIterator iter = reactor.eResource().getAllContents(); + int nMain = countMainOrFederated(iter); + if (nMain > 1) { + EAttribute attribute = Literals.REACTOR__MAIN; if (reactor.isFederated()) { - if (!target.supportsFederated()) { - error("The " + target.getDisplayName() + " target does not support federated execution.", - Literals.REACTOR__FEDERATED); - } + attribute = Literals.REACTOR__FEDERATED; + } + error("Multiple definitions of main or federated reactor.", attribute); + } + + if (reactor.getName() != null && !reactor.getName().equals(fileName)) { + // Make sure that if the name is given, it matches the expected name. + error( + "Name of main reactor must match the file name (or be omitted).", + Literals.REACTOR_DECL__NAME); + } + + // check the reactor name indicated by the file name + // Skip this check if the file is named __synthetic0. This Name is used during testing, + // and we would get an unexpected error due to the '__' prefix otherwise. + if (!fileName.equals("__synthetic0")) { + checkReactorName(fileName); + } + } else { + // Not federated or main. + if (reactor.getName() == null) { + error("Reactor must be named.", Literals.REACTOR_DECL__NAME); + } else { + checkReactorName(reactor.getName()); + + TreeIterator iter = reactor.eResource().getAllContents(); + int nMain = countMainOrFederated(iter); + if (nMain > 0 && reactor.getName().equals(fileName)) { + error("Name conflict with main reactor.", Literals.REACTOR_DECL__NAME); + } + } + } - FedValidator.validateFederatedReactor(reactor, this.errorReporter); - } + Set superClasses = ASTUtils.superClasses(reactor); + if (superClasses == null) { + error( + "Problem with superclasses: Either they form a cycle or are not defined", + Literals.REACTOR_DECL__NAME); + // Continue checks, but without any superclasses. + superClasses = new LinkedHashSet<>(); } - /** - * Check if the requested serialization is supported. - */ - @Check(CheckType.FAST) - public void checkSerializer(Serializer serializer) { - boolean isValidSerializer = false; - for (SupportedSerializers method : SupportedSerializers.values()) { - if (method.name().equalsIgnoreCase(serializer.getType())){ - isValidSerializer = true; - } - } + if (reactor.getHost() != null) { + if (!reactor.isFederated()) { + error( + "Cannot assign a host to reactor '" + + reactor.getName() + + "' because it is not federated.", + Literals.REACTOR__HOST); + } + } - if (!isValidSerializer) { - error( - "Serializer can be " + Arrays.asList(SupportedSerializers.values()), - Literals.SERIALIZER__TYPE - ); - } + List variables = new ArrayList<>(); + variables.addAll(reactor.getInputs()); + variables.addAll(reactor.getOutputs()); + variables.addAll(reactor.getActions()); + variables.addAll(reactor.getTimers()); + + if (!reactor.getSuperClasses().isEmpty() && !target.supportsInheritance()) { + error( + "The " + target.getDisplayName() + " target does not support reactor inheritance.", + Literals.REACTOR__SUPER_CLASSES); } - @Check(CheckType.FAST) - public void checkState(StateVar stateVar) { - checkName(stateVar.getName(), Literals.STATE_VAR__NAME); - if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { - typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); - } + // Perform checks on super classes. + for (Reactor superClass : superClasses) { + HashSet conflicts = new HashSet<>(); + + // Detect input conflicts + checkConflict(superClass.getInputs(), reactor.getInputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getOutputs(), reactor.getOutputs(), variables, conflicts); + // Detect output conflicts + checkConflict(superClass.getActions(), reactor.getActions(), variables, conflicts); + // Detect conflicts + for (Timer timer : superClass.getTimers()) { + List filteredVariables = new ArrayList<>(variables); + filteredVariables.removeIf(it -> reactor.getTimers().contains(it)); + if (hasNameConflict(timer, filteredVariables)) { + conflicts.add(timer); + } else { + variables.add(timer); + } + } + + // Report conflicts. + if (conflicts.size() > 0) { + List names = new ArrayList<>(); + for (Variable it : conflicts) { + names.add(it.getName()); + } + error( + String.format( + "Cannot extend %s due to the following conflicts: %s.", + superClass.getName(), String.join(",", names)), + Literals.REACTOR__SUPER_CLASSES); + } + } - if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { - // Report if a type is missing - error("State must have a type.", Literals.STATE_VAR__TYPE); - } + if (reactor.isFederated()) { + if (!target.supportsFederated()) { + error( + "The " + target.getDisplayName() + " target does not support federated execution.", + Literals.REACTOR__FEDERATED); + } - if (isCBasedTarget() - && ASTUtils.isListInitializer(stateVar.getInit()) - && stateVar.getInit().getExprs().stream().anyMatch(it -> it instanceof ParameterReference)) { - // In C, if initialization is done with a list, elements cannot - // refer to parameters. - error("List items cannot refer to a parameter.", - Literals.STATE_VAR__INIT); - } + FedValidator.validateFederatedReactor(reactor, this.errorReporter); + } + } + + /** Check if the requested serialization is supported. */ + @Check(CheckType.FAST) + public void checkSerializer(Serializer serializer) { + boolean isValidSerializer = false; + for (SupportedSerializers method : SupportedSerializers.values()) { + if (method.name().equalsIgnoreCase(serializer.getType())) { + isValidSerializer = true; + } + } + if (!isValidSerializer) { + error( + "Serializer can be " + Arrays.asList(SupportedSerializers.values()), + Literals.SERIALIZER__TYPE); } + } - @Check(CheckType.FAST) - public void checkSTPOffset(STP stp) { - if (isCBasedTarget() && - this.info.overflowingSTP.contains(stp)) { - error( - "STP offset exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", - Literals.STP__VALUE); - } + @Check(CheckType.FAST) + public void checkState(StateVar stateVar) { + checkName(stateVar.getName(), Literals.STATE_VAR__NAME); + if (stateVar.getInit() != null && stateVar.getInit().getExprs().size() != 0) { + typeCheck(stateVar.getInit(), ASTUtils.getInferredType(stateVar), Literals.STATE_VAR__INIT); } - @Check(CheckType.FAST) - public void checkTargetDecl(TargetDecl target) throws IOException { - Optional targetOpt = Target.forName(target.getName()); - if (targetOpt.isEmpty()) { - error("Unrecognized target: " + target.getName(), - Literals.TARGET_DECL__NAME); - } else { - this.target = targetOpt.get(); - } - String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); - if (Character.isDigit(lfFileName.charAt(0))) { - errorReporter.reportError("LF file names must not start with a number"); - } + if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { + // Report if a type is missing + error("State must have a type.", Literals.STATE_VAR__TYPE); } - /** - * Check for consistency of the target properties, which are - * defined as KeyValuePairs. - * - * @param targetProperties The target properties defined - * in the current Lingua Franca program. - */ - @Check(CheckType.EXPENSIVE) - public void checkTargetProperties(KeyValuePairs targetProperties) { - validateFastTargetProperty(targetProperties); - validateClockSyncTargetProperties(targetProperties); - validateSchedulerTargetProperties(targetProperties); - validateRos2TargetProperties(targetProperties); - validateKeepalive(targetProperties); - } - - private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { - List properties = targetProperties.getPairs().stream() + if (isCBasedTarget() + && ASTUtils.isListInitializer(stateVar.getInit()) + && stateVar.getInit().getExprs().stream() + .anyMatch(it -> it instanceof ParameterReference)) { + // In C, if initialization is done with a list, elements cannot + // refer to parameters. + error("List items cannot refer to a parameter.", Literals.STATE_VAR__INIT); + } + } + + @Check(CheckType.FAST) + public void checkSTPOffset(STP stp) { + if (isCBasedTarget() && this.info.overflowingSTP.contains(stp)) { + error( + "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", + Literals.STP__VALUE); + } + } + + @Check(CheckType.FAST) + public void checkTargetDecl(TargetDecl target) throws IOException { + Optional targetOpt = Target.forName(target.getName()); + if (targetOpt.isEmpty()) { + error("Unrecognized target: " + target.getName(), Literals.TARGET_DECL__NAME); + } else { + this.target = targetOpt.get(); + } + String lfFileName = FileUtil.nameWithoutExtension(target.eResource()); + if (Character.isDigit(lfFileName.charAt(0))) { + errorReporter.reportError("LF file names must not start with a number"); + } + } + + /** + * Check for consistency of the target properties, which are defined as KeyValuePairs. + * + * @param targetProperties The target properties defined in the current Lingua Franca program. + */ + @Check(CheckType.EXPENSIVE) + public void checkTargetProperties(KeyValuePairs targetProperties) { + validateFastTargetProperty(targetProperties); + validateClockSyncTargetProperties(targetProperties); + validateSchedulerTargetProperties(targetProperties); + validateRos2TargetProperties(targetProperties); + validateKeepalive(targetProperties); + } + + private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { + List properties = + targetProperties.getPairs().stream() .filter(pair -> pair.getName().equals(property.description)) .toList(); - assert (properties.size() <= 1); - return properties.size() > 0 ? properties.get(0) : null; - } - private void validateFastTargetProperty(KeyValuePairs targetProperties) { - KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); - - if (fastTargetProperty != null) { - // Check for federated - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a federated reactor - if (reactor.isFederated()) { - error( - "The fast target property is incompatible with federated programs.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - break; - } - } + assert (properties.size() <= 1); + return properties.size() > 0 ? properties.get(0) : null; + } - // Check for physical actions - for (Reactor reactor : info.model.getReactors()) { - // Check to see if the program has a physical action in a reactor - for (Action action : reactor.getActions()) { - if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { - error( - "The fast target property is incompatible with physical actions.", - fastTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - break; - } - } - } - } - } - - private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair clockSyncTargetProperty = getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); + private void validateFastTargetProperty(KeyValuePairs targetProperties) { + KeyValuePair fastTargetProperty = getKeyValuePair(targetProperties, TargetProperty.FAST); - if (clockSyncTargetProperty != null) { - boolean federatedExists = false; - for (Reactor reactor : info.model.getReactors()) { - if (reactor.isFederated()) { - federatedExists = true; - } - } - if (!federatedExists) { - warning( - "The clock-sync target property is incompatible with non-federated programs.", - clockSyncTargetProperty, - Literals.KEY_VALUE_PAIR__NAME - ); - } + if (fastTargetProperty != null) { + // Check for federated + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a federated reactor + if (reactor.isFederated()) { + error( + "The fast target property is incompatible with federated programs.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + break; + } + } + + // Check for physical actions + for (Reactor reactor : info.model.getReactors()) { + // Check to see if the program has a physical action in a reactor + for (Action action : reactor.getActions()) { + if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) { + error( + "The fast target property is incompatible with physical actions.", + fastTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + break; + } } + } } + } - private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { - KeyValuePair schedulerTargetProperty = getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); - if (schedulerTargetProperty != null) { - String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); - try { - if (!TargetProperty.SchedulerOption.valueOf(schedulerName) - .prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - // Filter reactors that contain at least one reaction that - // has a deadline handler. - if (info.model.getReactors().stream().anyMatch( - // Filter reactors that contain at least one reaction that - // has a deadline handler. - reactor -> ASTUtils.allReactions(reactor).stream().anyMatch( - reaction -> reaction.getDeadline() != null - )) - ) { - warning("This program contains deadlines, but the chosen " - + schedulerName - + " scheduler does not prioritize reaction execution " - + "based on deadlines. This might result in a sub-optimal " - + "scheduling.", schedulerTargetProperty, - Literals.KEY_VALUE_PAIR__VALUE); - } - } - } catch (IllegalArgumentException e) { - // the given scheduler is invalid, but this is already checked by - // checkTargetProperties - } - } - } + private void validateClockSyncTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair clockSyncTargetProperty = + getKeyValuePair(targetProperties, TargetProperty.CLOCK_SYNC); - private void validateKeepalive(KeyValuePairs targetProperties) { - KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); - if (keepalive != null && target == Target.CPP) { - warning("The keepalive property is inferred automatically by the C++ " + - "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); - } + if (clockSyncTargetProperty != null) { + boolean federatedExists = false; + for (Reactor reactor : info.model.getReactors()) { + if (reactor.isFederated()) { + federatedExists = true; + } + } + if (!federatedExists) { + warning( + "The clock-sync target property is incompatible with non-federated programs.", + clockSyncTargetProperty, + Literals.KEY_VALUE_PAIR__NAME); + } } - - private void validateRos2TargetProperties(KeyValuePairs targetProperties) { - KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); - KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); - if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { + } + + private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { + KeyValuePair schedulerTargetProperty = + getKeyValuePair(targetProperties, TargetProperty.SCHEDULER); + if (schedulerTargetProperty != null) { + String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); + try { + if (!TargetProperty.SchedulerOption.valueOf(schedulerName).prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + // Filter reactors that contain at least one reaction that + // has a deadline handler. + if (info.model.getReactors().stream() + .anyMatch( + // Filter reactors that contain at least one reaction that + // has a deadline handler. + reactor -> + ASTUtils.allReactions(reactor).stream() + .anyMatch(reaction -> reaction.getDeadline() != null))) { warning( - "Ignoring ros2-dependencies as ros2 compilation is disabled", - ros2Dependencies, - Literals.KEY_VALUE_PAIR__NAME - ); + "This program contains deadlines, but the chosen " + + schedulerName + + " scheduler does not prioritize reaction execution " + + "based on deadlines. This might result in a sub-optimal " + + "scheduling.", + schedulerTargetProperty, + Literals.KEY_VALUE_PAIR__VALUE); + } } + } catch (IllegalArgumentException e) { + // the given scheduler is invalid, but this is already checked by + // checkTargetProperties + } } - - @Check(CheckType.FAST) - public void checkTimer(Timer timer) { - checkName(timer.getName(), Literals.VARIABLE__NAME); - checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); - checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); + } + + private void validateKeepalive(KeyValuePairs targetProperties) { + KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); + if (keepalive != null && target == Target.CPP) { + warning( + "The keepalive property is inferred automatically by the C++ " + + "runtime and the value given here is ignored", + keepalive, + Literals.KEY_VALUE_PAIR__NAME); } - - @Check(CheckType.FAST) - public void checkType(Type type) { - // FIXME: disallow the use of generics in C - if (this.target == Target.Python) { - if (type != null) { - error( - "Types are not allowed in the Python target", - Literals.TYPE__ID - ); - } - } + } + + private void validateRos2TargetProperties(KeyValuePairs targetProperties) { + KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); + KeyValuePair ros2Dependencies = + getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); + if (ros2Dependencies != null && (ros2 == null || !ASTUtils.toBoolean(ros2.getValue()))) { + warning( + "Ignoring ros2-dependencies as ros2 compilation is disabled", + ros2Dependencies, + Literals.KEY_VALUE_PAIR__NAME); } - - @Check(CheckType.FAST) - public void checkVarRef(VarRef varRef) { - // check correct usage of interleaved - if (varRef.isInterleaved()) { - var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); - if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { - error("This target does not support interleaved port references.", Literals.VAR_REF__INTERLEAVED); - } - if (!(varRef.eContainer() instanceof Connection)) { - error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); - } - - if (varRef.getVariable() instanceof Port) { - // This test only works correctly if the variable is actually a port. If it is not a port, other - // validator rules will produce error messages. - if (varRef.getContainer() == null || varRef.getContainer().getWidthSpec() == null || - ((Port) varRef.getVariable()).getWidthSpec() == null - ) { - error("interleaved can only be used for multiports contained within banks.", Literals.VAR_REF__INTERLEAVED); - } - } - } + } + + @Check(CheckType.FAST) + public void checkTimer(Timer timer) { + checkName(timer.getName(), Literals.VARIABLE__NAME); + checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET); + checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD); + } + + @Check(CheckType.FAST) + public void checkType(Type type) { + // FIXME: disallow the use of generics in C + if (this.target == Target.Python) { + if (type != null) { + error("Types are not allowed in the Python target", Literals.TYPE__ID); + } } - - /** - * Check whether an attribute is supported - * and the validity of the attribute. - * - * @param attr The attribute being checked - */ - @Check(CheckType.FAST) - public void checkAttributes(Attribute attr) { - String name = attr.getAttrName().toString(); - AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); - if (spec == null) { - error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); - return; - } - // Check the validity of the attribute. - spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkVarRef(VarRef varRef) { + // check correct usage of interleaved + if (varRef.isInterleaved()) { + var supportedTargets = List.of(Target.CPP, Target.Python, Target.Rust); + if (!supportedTargets.contains(this.target) && !isCBasedTarget()) { + error( + "This target does not support interleaved port references.", + Literals.VAR_REF__INTERLEAVED); + } + if (!(varRef.eContainer() instanceof Connection)) { + error("interleaved can only be used in connections.", Literals.VAR_REF__INTERLEAVED); + } + + if (varRef.getVariable() instanceof Port) { + // This test only works correctly if the variable is actually a port. If it is not a port, + // other + // validator rules will produce error messages. + if (varRef.getContainer() == null + || varRef.getContainer().getWidthSpec() == null + || ((Port) varRef.getVariable()).getWidthSpec() == null) { + error( + "interleaved can only be used for multiports contained within banks.", + Literals.VAR_REF__INTERLEAVED); + } + } } - - @Check(CheckType.FAST) - public void checkWidthSpec(WidthSpec widthSpec) { - if (!this.target.supportsMultiports()) { - error("Multiports and banks are currently not supported by the given target.", + } + + /** + * Check whether an attribute is supported and the validity of the attribute. + * + * @param attr The attribute being checked + */ + @Check(CheckType.FAST) + public void checkAttributes(Attribute attr) { + String name = attr.getAttrName().toString(); + AttributeSpec spec = AttributeSpec.ATTRIBUTE_SPECS_BY_NAME.get(name); + if (spec == null) { + error("Unknown attribute.", Literals.ATTRIBUTE__ATTR_NAME); + return; + } + // Check the validity of the attribute. + spec.check(this, attr); + } + + @Check(CheckType.FAST) + public void checkWidthSpec(WidthSpec widthSpec) { + if (!this.target.supportsMultiports()) { + error( + "Multiports and banks are currently not supported by the given target.", + Literals.WIDTH_SPEC__TERMS); + } else { + for (WidthTerm term : widthSpec.getTerms()) { + if (term.getParameter() != null) { + if (!this.target.supportsParameterizedWidths()) { + error( + "Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); - } else { - for (WidthTerm term : widthSpec.getTerms()) { - if (term.getParameter() != null) { - if (!this.target.supportsParameterizedWidths()) { - error("Parameterized widths are not supported by this target.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getPort() != null) { - // Widths given with {@code widthof()} are not supported (yet?). - // This feature is currently only used for after delays. - error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); - } else if (term.getCode() != null) { - if (this.target != Target.CPP) { - error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); - } - } else if (term.getWidth() < 0) { - error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); - } - } + } + } else if (term.getPort() != null) { + // Widths given with {@code widthof()} are not supported (yet?). + // This feature is currently only used for after delays. + error("widthof is not supported.", Literals.WIDTH_SPEC__TERMS); + } else if (term.getCode() != null) { + if (this.target != Target.CPP) { + error("This target does not support width given as code.", Literals.WIDTH_SPEC__TERMS); + } + } else if (term.getWidth() < 0) { + error("Width must be a positive integer.", Literals.WIDTH_SPEC__TERMS); } + } } - - @Check(CheckType.FAST) - public void checkReactorIconAttribute(Reactor reactor) { - var path = AttributeUtils.getIconPath(reactor); - if (path != null) { - var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); - // Check file extension - var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); - var extensionStrart = path.lastIndexOf("."); - var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; - if (!validExtensions.contains(extension.toLowerCase())) { - warning("File extension '" + extension + "' is not supported. Provide any of: " + String.join(", ", validExtensions), - param, Literals.ATTR_PARM__VALUE); - return; - } - - // Check file location - var iconLocation = FileUtil.locateFile(path, reactor.eResource()); - if (iconLocation == null) { - warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); - } - if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) && !(new File(iconLocation.getPath()).exists())) { - warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); - } - } + } + + @Check(CheckType.FAST) + public void checkReactorIconAttribute(Reactor reactor) { + var path = AttributeUtils.getIconPath(reactor); + if (path != null) { + var param = AttributeUtils.findAttributeByName(reactor, "icon").getAttrParms().get(0); + // Check file extension + var validExtensions = Set.of("bmp", "png", "gif", "ico", "jpeg"); + var extensionStrart = path.lastIndexOf("."); + var extension = extensionStrart != -1 ? path.substring(extensionStrart + 1) : ""; + if (!validExtensions.contains(extension.toLowerCase())) { + warning( + "File extension '" + + extension + + "' is not supported. Provide any of: " + + String.join(", ", validExtensions), + param, + Literals.ATTR_PARM__VALUE); + return; + } + + // Check file location + var iconLocation = FileUtil.locateFile(path, reactor.eResource()); + if (iconLocation == null) { + warning("Cannot locate icon file.", param, Literals.ATTR_PARM__VALUE); + } + if (("file".equals(iconLocation.getScheme()) || iconLocation.getScheme() == null) + && !(new File(iconLocation.getPath()).exists())) { + warning("Icon does not exist.", param, Literals.ATTR_PARM__VALUE); + } } - - @Check(CheckType.FAST) - public void checkInitialMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); - if (initialModesCount == 0) { - error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); - } else if (initialModesCount > 1) { - reactor.getModes().stream().filter(m -> m.isInitial()).skip(1).forEach(m -> { - error("A modal reactor can only have one initial mode.", - Literals.REACTOR__MODES, reactor.getModes().indexOf(m)); + } + + @Check(CheckType.FAST) + public void checkInitialMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + long initialModesCount = reactor.getModes().stream().filter(m -> m.isInitial()).count(); + if (initialModesCount == 0) { + error("Every modal reactor requires one initial mode.", Literals.REACTOR__MODES, 0); + } else if (initialModesCount > 1) { + reactor.getModes().stream() + .filter(m -> m.isInitial()) + .skip(1) + .forEach( + m -> { + error( + "A modal reactor can only have one initial mode.", + Literals.REACTOR__MODES, + reactor.getModes().indexOf(m)); }); - } + } + } + } + + @Check(CheckType.FAST) + public void checkModeStateNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var stateVar : mode.getStateVars()) { + if (names.contains(stateVar.getName())) { + error( + String.format( + "Duplicate state variable '%s'. (State variables are currently scoped on" + + " reactor level not modes)", + stateVar.getName()), + stateVar, + Literals.STATE_VAR__NAME); + } + names.add(stateVar.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeStateNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getStateVars().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var stateVar : mode.getStateVars()) { - if (names.contains(stateVar.getName())) { - error(String.format("Duplicate state variable '%s'. (State variables are currently scoped on reactor level not modes)", - stateVar.getName()), stateVar, Literals.STATE_VAR__NAME); - } - names.add(stateVar.getName()); - } - } + } + + @Check(CheckType.FAST) + public void checkModeTimerNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var timer : mode.getTimers()) { + if (names.contains(timer.getName())) { + error( + String.format( + "Duplicate Timer '%s'. (Timers are currently scoped on reactor level not" + + " modes)", + timer.getName()), + timer, + Literals.VARIABLE__NAME); + } + names.add(timer.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeTimerNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getTimers().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var timer : mode.getTimers()) { - if (names.contains(timer.getName())) { - error(String.format("Duplicate Timer '%s'. (Timers are currently scoped on reactor level not modes)", - timer.getName()), timer, Literals.VARIABLE__NAME); - } - names.add(timer.getName()); - } - } + } + + @Check(CheckType.FAST) + public void checkModeActionNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var action : mode.getActions()) { + if (names.contains(action.getName())) { + error( + String.format( + "Duplicate Action '%s'. (Actions are currently scoped on reactor level not" + + " modes)", + action.getName()), + action, + Literals.VARIABLE__NAME); + } + names.add(action.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeActionNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var action : mode.getActions()) { - if (names.contains(action.getName())) { - error(String.format("Duplicate Action '%s'. (Actions are currently scoped on reactor level not modes)", - action.getName()), action, Literals.VARIABLE__NAME); - } - names.add(action.getName()); - } - } + } + + @Check(CheckType.FAST) + public void checkModeInstanceNamespace(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var names = new ArrayList(); + reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); + for (var mode : reactor.getModes()) { + for (var instantiation : mode.getInstantiations()) { + if (names.contains(instantiation.getName())) { + error( + String.format( + "Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor" + + " level not modes)", + instantiation.getName()), + instantiation, + Literals.INSTANTIATION__NAME); + } + names.add(instantiation.getName()); } + } } - - @Check(CheckType.FAST) - public void checkModeInstanceNamespace(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var names = new ArrayList(); - reactor.getActions().stream().map(it -> it.getName()).forEach(it -> names.add(it)); - for (var mode : reactor.getModes()) { - for (var instantiation : mode.getInstantiations()) { - if (names.contains(instantiation.getName())) { - error(String.format("Duplicate Instantiation '%s'. (Instantiations are currently scoped on reactor level not modes)", - instantiation.getName()), instantiation, Literals.INSTANTIATION__NAME); - } - names.add(instantiation.getName()); - } + } + + @Check(CheckType.FAST) + public void checkMissingStateResetInMode(Reactor reactor) { + if (!reactor.getModes().isEmpty()) { + var resetModes = new HashSet(); + // Collect all modes that may be reset + for (var m : reactor.getModes()) { + for (var r : m.getReactions()) { + for (var e : r.getEffects()) { + if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { + resetModes.add((Mode) e.getVariable()); } + } } - } - - @Check(CheckType.FAST) - public void checkMissingStateResetInMode(Reactor reactor) { - if (!reactor.getModes().isEmpty()) { - var resetModes = new HashSet(); - // Collect all modes that may be reset - for (var m : reactor.getModes()) { - for (var r : m.getReactions()) { - for (var e : r.getEffects()) { - if (e.getVariable() instanceof Mode && e.getTransition() != ModeTransition.HISTORY) { - resetModes.add((Mode) e.getVariable()); - } - } - } + } + for (var m : resetModes) { + // Check state variables in this mode + if (!m.getStateVars().isEmpty()) { + var hasResetReaction = + m.getReactions().stream() + .anyMatch( + r -> + r.getTriggers().stream() + .anyMatch( + t -> + (t instanceof BuiltinTriggerRef + && ((BuiltinTriggerRef) t).getType() + == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + for (var s : m.getStateVars()) { + if (!s.isReset()) { + error( + "State variable is not reset upon mode entry. It is neither marked for" + + " automatic reset nor is there a reset reaction.", + m, + Literals.MODE__STATE_VARS, + m.getStateVars().indexOf(s)); + } } - for (var m : resetModes) { - // Check state variables in this mode - if (!m.getStateVars().isEmpty()) { - var hasResetReaction = m.getReactions().stream().anyMatch( - r -> r.getTriggers().stream().anyMatch( - t -> (t instanceof BuiltinTriggerRef && - ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - for (var s : m.getStateVars()) { - if (!s.isReset()) { - error("State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction.", - m, Literals.MODE__STATE_VARS, m.getStateVars().indexOf(s)); - } - } - } + } + } + // Check state variables in instantiated reactors + if (!m.getInstantiations().isEmpty()) { + for (var i : m.getInstantiations()) { + var error = new LinkedHashSet(); + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty()) { + var check = toCheck.pop(); + checked.add(check); + if (!check.getStateVars().isEmpty()) { + var hasResetReaction = + check.getReactions().stream() + .anyMatch( + r -> + r.getTriggers().stream() + .anyMatch( + t -> + (t instanceof BuiltinTriggerRef + && ((BuiltinTriggerRef) t).getType() + == BuiltinTrigger.RESET))); + if (!hasResetReaction) { + // Add state vars that are not self-resetting to the error + check.getStateVars().stream() + .filter(s -> !s.isReset()) + .forEachOrdered(error::add); } - // Check state variables in instantiated reactors - if (!m.getInstantiations().isEmpty()) { - for (var i : m.getInstantiations()) { - var error = new LinkedHashSet(); - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty()) { - var check = toCheck.pop(); - checked.add(check); - if (!check.getStateVars().isEmpty()) { - var hasResetReaction = check.getReactions().stream().anyMatch( - r -> r.getTriggers().stream().anyMatch( - t -> (t instanceof BuiltinTriggerRef && - ((BuiltinTriggerRef) t).getType() == BuiltinTrigger.RESET))); - if (!hasResetReaction) { - // Add state vars that are not self-resetting to the error - check.getStateVars().stream().filter(s -> !s.isReset()).forEachOrdered(error::add); - } - } - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } - } - } - if (!error.isEmpty()) { - error("This reactor contains state variables that are not reset upon mode entry: " - + error.stream().map(e -> e.getName() + " in " - + ASTUtils.getEnclosingReactor(e).getName()).collect(Collectors.joining(", ")) - + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " - + "It is unsafe to instantiate this reactor inside a mode entered with reset.", - m, Literals.MODE__INSTANTIATIONS, - m.getInstantiations().indexOf(i)); - } - } + } + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); } + } + } + if (!error.isEmpty()) { + error( + "This reactor contains state variables that are not reset upon mode entry: " + + error.stream() + .map( + e -> e.getName() + " in " + ASTUtils.getEnclosingReactor(e).getName()) + .collect(Collectors.joining(", ")) + + ".\n" + + "The state variables are neither marked for automatic reset nor have a" + + " dedicated reset reaction. It is unsafe to instantiate this reactor inside" + + " a mode entered with reset.", + m, + Literals.MODE__INSTANTIATIONS, + m.getInstantiations().indexOf(i)); } + } } + } } - - @Check(CheckType.FAST) - public void checkStateResetWithoutInitialValue(StateVar state) { - if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { - error("The state variable can not be automatically reset without an initial value.", state, Literals.STATE_VAR__RESET); - } + } + + @Check(CheckType.FAST) + public void checkStateResetWithoutInitialValue(StateVar state) { + if (state.isReset() && (state.getInit() == null || state.getInit().getExprs().isEmpty())) { + error( + "The state variable can not be automatically reset without an initial value.", + state, + Literals.STATE_VAR__RESET); } - - @Check(CheckType.FAST) - public void checkUnspecifiedTransitionType(Reaction reaction) { - for (var effect : reaction.getEffects()) { - var variable = effect.getVariable(); - if (variable instanceof Mode) { - // The transition type is always set to default by Xtext. - // Hence, check if there is an explicit node for the transition type in the AST. - var transitionAssignment = NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); - if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. - var mode = (Mode) variable; - // Check if reset or history transition would make a difference. - var makesDifference = !mode.getStateVars().isEmpty() - || !mode.getTimers().isEmpty() - || !mode.getActions().isEmpty() - || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); - if (!makesDifference && !mode.getInstantiations().isEmpty()) { - // Also check instantiated reactors - for (var i : mode.getInstantiations()) { - var checked = new HashSet(); - var toCheck = new LinkedList(); - toCheck.add((Reactor) i.getReactorClass()); - while (!toCheck.isEmpty() && !makesDifference) { - var check = toCheck.pop(); - checked.add(check); - - makesDifference |= !check.getModes().isEmpty() - || !ASTUtils.allStateVars(check).isEmpty() - || !ASTUtils.allTimers(check).isEmpty() - || !ASTUtils.allActions(check).isEmpty() - || ASTUtils.allConnections(check).stream().anyMatch(c -> c.getDelay() != null); - - // continue with inner - for (var innerInstance : check.getInstantiations()) { - var next = (Reactor) innerInstance.getReactorClass(); - if (!checked.contains(next)) { - toCheck.push(next); - } - } - } - } - } - if (makesDifference) { - warning("You should specify a transition type! " - + "Reset and history transitions have different effects on this target mode. " - + "Currently, a reset type is implicitly assumed.", - reaction, Literals.REACTION__EFFECTS, reaction.getEffects().indexOf(effect)); - } + } + + @Check(CheckType.FAST) + public void checkUnspecifiedTransitionType(Reaction reaction) { + for (var effect : reaction.getEffects()) { + var variable = effect.getVariable(); + if (variable instanceof Mode) { + // The transition type is always set to default by Xtext. + // Hence, check if there is an explicit node for the transition type in the AST. + var transitionAssignment = + NodeModelUtils.findNodesForFeature((EObject) effect, Literals.VAR_REF__TRANSITION); + if (transitionAssignment.isEmpty()) { // Transition type not explicitly specified. + var mode = (Mode) variable; + // Check if reset or history transition would make a difference. + var makesDifference = + !mode.getStateVars().isEmpty() + || !mode.getTimers().isEmpty() + || !mode.getActions().isEmpty() + || mode.getConnections().stream().anyMatch(c -> c.getDelay() != null); + if (!makesDifference && !mode.getInstantiations().isEmpty()) { + // Also check instantiated reactors + for (var i : mode.getInstantiations()) { + var checked = new HashSet(); + var toCheck = new LinkedList(); + toCheck.add((Reactor) i.getReactorClass()); + while (!toCheck.isEmpty() && !makesDifference) { + var check = toCheck.pop(); + checked.add(check); + + makesDifference |= + !check.getModes().isEmpty() + || !ASTUtils.allStateVars(check).isEmpty() + || !ASTUtils.allTimers(check).isEmpty() + || !ASTUtils.allActions(check).isEmpty() + || ASTUtils.allConnections(check).stream() + .anyMatch(c -> c.getDelay() != null); + + // continue with inner + for (var innerInstance : check.getInstantiations()) { + var next = (Reactor) innerInstance.getReactorClass(); + if (!checked.contains(next)) { + toCheck.push(next); + } } + } } + } + if (makesDifference) { + warning( + "You should specify a transition type! " + + "Reset and history transitions have different effects on this target mode. " + + "Currently, a reset type is implicitly assumed.", + reaction, + Literals.REACTION__EFFECTS, + reaction.getEffects().indexOf(effect)); + } } + } + } + } + + ////////////////////////////////////////////////////////////// + //// Public methods. + + /** Return the error reporter for this validator. */ + public ValidatorErrorReporter getErrorReporter() { + return this.errorReporter; + } + + /** Implementation required by xtext to report validation errors. */ + @Override + public ValidationMessageAcceptor getMessageAcceptor() { + return messageAcceptor == null ? this : messageAcceptor; + } + + /** Return a list of error messages for the target declaration. */ + public List getTargetPropertyErrors() { + return this.targetPropertyErrors; + } + + ////////////////////////////////////////////////////////////// + //// Protected methods. + + /** Generate an error message for an AST node. */ + @Override + protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature) { + super.error(message, feature); + } + + ////////////////////////////////////////////////////////////// + //// Private methods. + + /** + * For each input, report a conflict if: 1) the input exists and the type doesn't match; or 2) the + * input has a name clash with variable that is not an input. + * + * @param superVars List of typed variables of a particular kind (i.e., inputs, outputs, or + * actions), found in a super class. + * @param sameKind Typed variables of the same kind, found in the subclass. + * @param allOwn Accumulator of non-conflicting variables incorporated in the subclass. + * @param conflicts Set of variables that are in conflict, to be used by this function to report + * conflicts. + */ + private void checkConflict( + EList superVars, EList sameKind, List allOwn, HashSet conflicts) { + for (T superVar : superVars) { + T match = null; + for (T it : sameKind) { + if (it.getName().equals(superVar.getName())) { + match = it; + break; + } + } + List rest = new ArrayList<>(allOwn); + rest.removeIf(it -> sameKind.contains(it)); + + if ((match != null && superVar.getType() != match.getType()) + || hasNameConflict(superVar, rest)) { + conflicts.add(superVar); + } else { + allOwn.add(superVar); + } + } + } + + /** + * Check the name of a feature for illegal substrings such as reserved identifiers and names with + * double leading underscores. + * + * @param name The name. + * @param feature The feature containing the name (for error reporting). + */ + private void checkName(String name, EStructuralFeature feature) { + + // Raises an error if the string starts with two underscores. + if (name.length() >= 2 && name.substring(0, 2).equals("__")) { + error(UNDERSCORE_MESSAGE + name, feature); } - ////////////////////////////////////////////////////////////// - //// Public methods. - - /** - * Return the error reporter for this validator. - */ - public ValidatorErrorReporter getErrorReporter() { - return this.errorReporter; - } - - /** - * Implementation required by xtext to report validation errors. - */ - @Override - public ValidationMessageAcceptor getMessageAcceptor() { - return messageAcceptor == null ? this : messageAcceptor; - } - - /** - * Return a list of error messages for the target declaration. - */ - public List getTargetPropertyErrors() { - return this.targetPropertyErrors; - } - - ////////////////////////////////////////////////////////////// - //// Protected methods. - - /** - * Generate an error message for an AST node. - */ - @Override - protected void error(java.lang.String message, - org.eclipse.emf.ecore.EStructuralFeature feature) { - super.error(message, feature); - } - - ////////////////////////////////////////////////////////////// - //// Private methods. - - /** - * For each input, report a conflict if: - * 1) the input exists and the type doesn't match; or - * 2) the input has a name clash with variable that is not an input. - * @param superVars List of typed variables of a particular kind (i.e., - * inputs, outputs, or actions), found in a super class. - * @param sameKind Typed variables of the same kind, found in the subclass. - * @param allOwn Accumulator of non-conflicting variables incorporated in the - * subclass. - * @param conflicts Set of variables that are in conflict, to be used by this - * function to report conflicts. - */ - private void checkConflict ( - EList superVars, EList sameKind, List allOwn, HashSet conflicts - ) { - for (T superVar : superVars) { - T match = null; - for (T it : sameKind) { - if (it.getName().equals(superVar.getName())) { - match = it; - break; - } - } - List rest = new ArrayList<>(allOwn); - rest.removeIf(it -> sameKind.contains(it)); + if (this.target.isReservedIdent(name)) { + error(RESERVED_MESSAGE + name, feature); + } - if ((match != null && superVar.getType() != match.getType()) || hasNameConflict(superVar, rest)) { - conflicts.add(superVar); - } else { - allOwn.add(superVar); - } - } + if (this.target == Target.TS) { + // "actions" is a reserved word within a TS reaction + if (name.equals("actions")) { + error(ACTIONS_MESSAGE + name, feature); + } + } + } + + /** + * Check that the initializer is compatible with the type. Note that if the type is inferred it + * will necessarily be compatible so this method is not harmful. + */ + public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { + if (init == null) { + return; } - /** - * Check the name of a feature for illegal substrings such as reserved - * identifiers and names with double leading underscores. - * @param name The name. - * @param feature The feature containing the name (for error reporting). - */ - private void checkName(String name, EStructuralFeature feature) { + // TODO: + // type is list => init is list + // type is fixed with size n => init is fixed with size n + // Specifically for C: list can only be literal or time lists - // Raises an error if the string starts with two underscores. - if (name.length() >= 2 && name.substring(0, 2).equals("__")) { - error(UNDERSCORE_MESSAGE + name, feature); + if (type.isTime) { + if (type.isList) { + // list of times + var exprs = init.getExprs(); + if (exprs.isEmpty()) { + error("Expected at least one time value.", feature); + return; } - - if (this.target.isReservedIdent(name)) { - error(RESERVED_MESSAGE + name, feature); + if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { + exprs = ((BracedListExpression) exprs.get(0)).getItems(); } - - if (this.target == Target.TS) { - // "actions" is a reserved word within a TS reaction - if (name.equals("actions")) { - error(ACTIONS_MESSAGE + name, feature); - } + for (var component : exprs) { + checkExpressionIsTime(component, feature); } + } else { + checkExpressionIsTime(init, feature); + } } + } - - /** - * Check that the initializer is compatible with the type. - * Note that if the type is inferred it will necessarily be compatible - * so this method is not harmful. - */ - public void typeCheck(Initializer init, InferredType type, EStructuralFeature feature) { - if (init == null) { - return; - } - - // TODO: - // type is list => init is list - // type is fixed with size n => init is fixed with size n - // Specifically for C: list can only be literal or time lists - - if (type.isTime) { - if (type.isList) { - // list of times - var exprs = init.getExprs(); - if (exprs.isEmpty()) { - error("Expected at least one time value.", feature); - return; - } - if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { - exprs = ((BracedListExpression) exprs.get(0)).getItems(); - } - for (var component : exprs) { - checkExpressionIsTime(component, feature); - } - } else { - checkExpressionIsTime(init, feature); - } - } + private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { + if (init == null) { + return; } - private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { - if (init == null) { - return; - } - - if (init.getExprs().size() != 1) { - error("Expected exactly one time value.", feature); - } else { - checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); - } + if (init.getExprs().size() != 1) { + error("Expected exactly one time value.", feature); + } else { + checkExpressionIsTime(ASTUtils.asSingleExpr(init), feature); } + } - private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { - if (value == null || value instanceof Time) { - return; - } - - if (value instanceof ParameterReference) { - if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) - && target.requiresTypes) { - error("Referenced parameter is not of time type.", feature); - } - return; - } else if (value instanceof Literal) { - if (ASTUtils.isZero(((Literal) value).getLiteral())) { - return; - } - - if (ASTUtils.isInteger(((Literal) value).getLiteral())) { - error("Missing time unit.", feature); - return; - } - // fallthrough - } - - error("Invalid time value.", feature); + private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { + if (value == null || value instanceof Time) { + return; } - /** - * Return the number of main or federated reactors declared. - * - * @param iter An iterator over all objects in the resource. - */ - private int countMainOrFederated(TreeIterator iter) { - int nMain = 0; - while (iter.hasNext()) { - EObject obj = iter.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor r = (Reactor) obj; - if (r.isMain() || r.isFederated()) { - nMain++; - } - } - return nMain; - } - - /** - * Report whether a given reactor has dependencies on a cyclic - * instantiation pattern. This means the reactor has an instantiation - * in it -- directly or in one of its contained reactors -- that is - * self-referential. - * @param reactor The reactor definition to find out whether it has any - * dependencies on cyclic instantiations. - * @param cycleSet The set of all reactors that are part of an - * instantiation cycle. - * @param visited The set of nodes already visited in this graph traversal. - */ - private boolean dependsOnCycle( - Reactor reactor, Set cycleSet, Set visited - ) { - Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); - if (visited.contains(reactor)) { - return false; - } else { - visited.add(reactor); - for (Reactor it : origins) { - if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { - // Reached a cycle. - return true; - } - } - } - return false; - } - - /** - * Report whether the name of the given element matches any variable in - * the ones to check against. - * @param element The element to compare against all variables in the given iterable. - * @param toCheckAgainst Iterable variables to compare the given element against. - */ - private boolean hasNameConflict(Variable element, - Iterable toCheckAgainst) { - int numNameConflicts = 0; - for (Variable it : toCheckAgainst) { - if (it.getName().equals(element.getName())) { - numNameConflicts++; - } - } - return numNameConflicts > 0; + if (value instanceof ParameterReference) { + if (!ASTUtils.isOfTimeType(((ParameterReference) value).getParameter()) + && target.requiresTypes) { + error("Referenced parameter is not of time type.", feature); + } + return; + } else if (value instanceof Literal) { + if (ASTUtils.isZero(((Literal) value).getLiteral())) { + return; + } + + if (ASTUtils.isInteger(((Literal) value).getLiteral())) { + error("Missing time unit.", feature); + return; + } + // fallthrough } - /** - * Return true if target is C or a C-based target like CCpp. - */ - private boolean isCBasedTarget() { - return (this.target == Target.C || this.target == Target.CCPP); + error("Invalid time value.", feature); + } + + /** + * Return the number of main or federated reactors declared. + * + * @param iter An iterator over all objects in the resource. + */ + private int countMainOrFederated(TreeIterator iter) { + int nMain = 0; + while (iter.hasNext()) { + EObject obj = iter.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor r = (Reactor) obj; + if (r.isMain() || r.isFederated()) { + nMain++; + } } - - /** - * Report whether a given imported reactor is used in this resource or not. - * @param reactor The imported reactor to check whether it is used. - */ - private boolean isUnused(ImportedReactor reactor) { - TreeIterator instantiations = reactor.eResource().getAllContents(); - TreeIterator subclasses = reactor.eResource().getAllContents(); - - boolean instantiationsCheck = true; - while (instantiations.hasNext() && instantiationsCheck) { - EObject obj = instantiations.next(); - if (!(obj instanceof Instantiation)) { - continue; - } - Instantiation inst = (Instantiation) obj; - instantiationsCheck &= (inst.getReactorClass() != reactor && inst.getReactorClass() != reactor.getReactorClass()); - } - - boolean subclassesCheck = true; - while (subclasses.hasNext() && subclassesCheck) { - EObject obj = subclasses.next(); - if (!(obj instanceof Reactor)) { - continue; - } - Reactor subclass = (Reactor) obj; - for (ReactorDecl decl : subclass.getSuperClasses()) { - subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); - } - } - return instantiationsCheck && subclassesCheck; + return nMain; + } + + /** + * Report whether a given reactor has dependencies on a cyclic instantiation pattern. This means + * the reactor has an instantiation in it -- directly or in one of its contained reactors -- that + * is self-referential. + * + * @param reactor The reactor definition to find out whether it has any dependencies on cyclic + * instantiations. + * @param cycleSet The set of all reactors that are part of an instantiation cycle. + * @param visited The set of nodes already visited in this graph traversal. + */ + private boolean dependsOnCycle(Reactor reactor, Set cycleSet, Set visited) { + Set origins = info.instantiationGraph.getUpstreamAdjacentNodes(reactor); + if (visited.contains(reactor)) { + return false; + } else { + visited.add(reactor); + for (Reactor it : origins) { + if (cycleSet.contains(it) || dependsOnCycle(it, cycleSet, visited)) { + // Reached a cycle. + return true; + } + } } - - /** - * Return true if the two types match. Unfortunately, xtext does not - * seem to create a suitable equals() method for Type, so we have to - * do this manually. - */ - private boolean sameType(Type type1, Type type2) { - if (type1 == null) { - return type2 == null; - } - if (type2 == null) { - return type1 == null; - } - // Most common case first. - if (type1.getId() != null) { - if (type1.getStars() != null) { - if (type2.getStars() == null) return false; - if (type1.getStars().size() != type2.getStars().size()) return false; - } - return (type1.getId().equals(type2.getId())); - } - - // Type specification in the grammar is: - // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); - if (type1.isTime()) { - if (!type2.isTime()) return false; - // Ignore the arraySpec because that is checked when connection - // is checked for balance. - return true; - } - // Type must be given in a code body - return type1.getCode().getBody().equals(type2.getCode().getBody()); + return false; + } + + /** + * Report whether the name of the given element matches any variable in the ones to check against. + * + * @param element The element to compare against all variables in the given iterable. + * @param toCheckAgainst Iterable variables to compare the given element against. + */ + private boolean hasNameConflict(Variable element, Iterable toCheckAgainst) { + int numNameConflicts = 0; + for (Variable it : toCheckAgainst) { + if (it.getName().equals(element.getName())) { + numNameConflicts++; + } + } + return numNameConflicts > 0; + } + + /** Return true if target is C or a C-based target like CCpp. */ + private boolean isCBasedTarget() { + return (this.target == Target.C || this.target == Target.CCPP); + } + + /** + * Report whether a given imported reactor is used in this resource or not. + * + * @param reactor The imported reactor to check whether it is used. + */ + private boolean isUnused(ImportedReactor reactor) { + TreeIterator instantiations = reactor.eResource().getAllContents(); + TreeIterator subclasses = reactor.eResource().getAllContents(); + + boolean instantiationsCheck = true; + while (instantiations.hasNext() && instantiationsCheck) { + EObject obj = instantiations.next(); + if (!(obj instanceof Instantiation)) { + continue; + } + Instantiation inst = (Instantiation) obj; + instantiationsCheck &= + (inst.getReactorClass() != reactor + && inst.getReactorClass() != reactor.getReactorClass()); } - ////////////////////////////////////////////////////////////// - //// Private fields. - - /** The error reporter. */ - private ValidatorErrorReporter errorReporter - = new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); - - /** Helper class containing information about the model. */ - private ModelInfo info = new ModelInfo(); - - @Inject(optional = true) - private ValidationMessageAcceptor messageAcceptor; - - /** The declared target. */ - private Target target; - - private List targetPropertyErrors = new ArrayList<>(); - - private List targetPropertyWarnings = new ArrayList<>(); - - ////////////////////////////////////////////////////////////// - //// Private static constants. - - private static String ACTIONS_MESSAGE - = "\"actions\" is a reserved word for the TypeScript target for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " - + "and reactor instantiation): "; - - private static String HOST_OR_FQN_REGEX - = "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; - - /** - * Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). - */ - private static String IPV4_REGEX = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + - "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; - - /** - * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), - * with minor adjustment to allow up to six IPV6 segments (without truncation) in front - * of an embedded IPv4-address. - **/ - private static String IPV6_REGEX = - "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + - "([0-9a-fA-F]{1,4}:){1,7}:|" + - "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + - "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + - "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + - "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + - "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + - "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + - ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + - "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + - "::(ffff(:0{1,4}){0,1}:){0,1}" + IPV4_REGEX + "|" + - "([0-9a-fA-F]{1,4}:){1,4}:" + IPV4_REGEX + "|" + - "([0-9a-fA-F]{1,4}:){1,6}" + IPV4_REGEX + ")"; - - private static String RESERVED_MESSAGE = "Reserved words in the target language are not allowed for objects " - + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation): "; - - private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); - - private static String UNDERSCORE_MESSAGE = "Names of objects (inputs, outputs, actions, timers, parameters, " - + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; - - private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; + boolean subclassesCheck = true; + while (subclasses.hasNext() && subclassesCheck) { + EObject obj = subclasses.next(); + if (!(obj instanceof Reactor)) { + continue; + } + Reactor subclass = (Reactor) obj; + for (ReactorDecl decl : subclass.getSuperClasses()) { + subclassesCheck &= (decl != reactor && decl != reactor.getReactorClass()); + } + } + return instantiationsCheck && subclassesCheck; + } + + /** + * Return true if the two types match. Unfortunately, xtext does not seem to create a suitable + * equals() method for Type, so we have to do this manually. + */ + private boolean sameType(Type type1, Type type2) { + if (type1 == null) { + return type2 == null; + } + if (type2 == null) { + return type1 == null; + } + // Most common case first. + if (type1.getId() != null) { + if (type1.getStars() != null) { + if (type2.getStars() == null) return false; + if (type1.getStars().size() != type2.getStars().size()) return false; + } + return (type1.getId().equals(type2.getId())); + } + // Type specification in the grammar is: + // (time?='time' (arraySpec=ArraySpec)?) | ((id=(DottedName) (stars+='*')* ('<' + // typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? (arraySpec=ArraySpec)?) | code=Code); + if (type1.isTime()) { + if (!type2.isTime()) return false; + // Ignore the arraySpec because that is checked when connection + // is checked for balance. + return true; + } + // Type must be given in a code body + return type1.getCode().getBody().equals(type2.getCode().getBody()); + } + + ////////////////////////////////////////////////////////////// + //// Private fields. + + /** The error reporter. */ + private ValidatorErrorReporter errorReporter = + new ValidatorErrorReporter(getMessageAcceptor(), new ValidatorStateAccess()); + + /** Helper class containing information about the model. */ + private ModelInfo info = new ModelInfo(); + + @Inject(optional = true) + private ValidationMessageAcceptor messageAcceptor; + + /** The declared target. */ + private Target target; + + private List targetPropertyErrors = new ArrayList<>(); + + private List targetPropertyWarnings = new ArrayList<>(); + + ////////////////////////////////////////////////////////////// + //// Private static constants. + + private static String ACTIONS_MESSAGE = + "\"actions\" is a reserved word for the TypeScript target for objects " + + "(inputs, outputs, actions, timers, parameters, state, reactor definitions, " + + "and reactor instantiation): "; + + private static String HOST_OR_FQN_REGEX = + "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$"; + + /** Regular expression to check the validity of IPV4 addresses (due to David M. Syzdek). */ + private static String IPV4_REGEX = + "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; + + /** + * Regular expression to check the validity of IPV6 addresses (due to David M. Syzdek), with minor + * adjustment to allow up to six IPV6 segments (without truncation) in front of an embedded + * IPv4-address. + */ + private static String IPV6_REGEX = + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,7}:|" + + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + + "::(ffff(:0{1,4}){0,1}:){0,1}" + + IPV4_REGEX + + "|" + + "([0-9a-fA-F]{1,4}:){1,4}:" + + IPV4_REGEX + + "|" + + "([0-9a-fA-F]{1,4}:){1,6}" + + IPV4_REGEX + + ")"; + + private static String RESERVED_MESSAGE = + "Reserved words in the target language are not allowed for objects (inputs, outputs, actions," + + " timers, parameters, state, reactor definitions, and reactor instantiation): "; + + private static List SPACING_VIOLATION_POLICIES = List.of("defer", "drop", "replace"); + + private static String UNDERSCORE_MESSAGE = + "Names of objects (inputs, outputs, actions, timers, parameters, " + + "state, reactor definitions, and reactor instantiation) may not start with \"__\": "; + + private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; } diff --git a/org.lflang/src/org/lflang/validation/ValidatorErrorReporter.java b/org.lflang/src/org/lflang/validation/ValidatorErrorReporter.java index ace55683f6..d21458a3a9 100644 --- a/org.lflang/src/org/lflang/validation/ValidatorErrorReporter.java +++ b/org.lflang/src/org/lflang/validation/ValidatorErrorReporter.java @@ -1,16 +1,16 @@ /************* * Copyright (c) 2021, TU Dresden. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -27,155 +27,160 @@ package org.lflang.validation; import java.nio.file.Path; - import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.validation.ValidationMessageAcceptor; - import org.lflang.ErrorReporter; /** - * This class translates messages reported via the ErrorReporrter interface to - * the interface of a given ValidationMessageAcceptor. - * - * Effectively this allows to report errors via the ErrorReporter interface - * during validator checks, while having the validator still track all the - * reported warnings and messages. This is required for some functionality, like - * the construction of an instance graph in LFValidator.checkModel(). Since the - * instance graph is also used in other components, it does not report directly - * to the validator, but uses our custom ErrorReporter interface that we use - * during code generation. This class bridges the gap between the ErrorReporter - * interface and the messages that the validator expects. - * + * This class translates messages reported via the ErrorReporrter interface to the interface of a + * given ValidationMessageAcceptor. + * + *

    Effectively this allows to report errors via the ErrorReporter interface during validator + * checks, while having the validator still track all the reported warnings and messages. This is + * required for some functionality, like the construction of an instance graph in + * LFValidator.checkModel(). Since the instance graph is also used in other components, it does not + * report directly to the validator, but uses our custom ErrorReporter interface that we use during + * code generation. This class bridges the gap between the ErrorReporter interface and the messages + * that the validator expects. + * * @author Christian Menard */ public class ValidatorErrorReporter implements ErrorReporter { - private ValidationMessageAcceptor acceptor; - private BaseLFValidator.ValidatorStateAccess validatorState; - private boolean errorsOccurred = false; - - public ValidatorErrorReporter(ValidationMessageAcceptor acceptor, - BaseLFValidator.ValidatorStateAccess stateAccess) { - this.acceptor = acceptor; - this.validatorState = stateAccess; - } - - /** - * Report the given message as an error on the object currently under - * validation. - */ - @Override - public String reportError(String message) { - errorsOccurred = true; - acceptor.acceptError(message, validatorState.getCurrentObject(), null, - ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return message; - } - - /** - * Report the given message as an error on the given object. - */ - @Override - public String reportError(EObject object, String message) { - errorsOccurred = true; - acceptor.acceptError(message, object, null, - ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return message; - } - - /** - * Report the given message as an error on the current object. - * - * Unfortunately, there is no way to provide a path and a line number to the - * ValidationMessageAcceptor as messages can only be reported directly as - * EObjects. While it is not an ideal solution, this method composes a - * messages indicating the location of the error and reports this on the - * object currently under validation. This way, the error message is not - * lost, but it is not necessarily reported precisely at the location of the - * actual error. - */ - @Override - public String reportError(Path file, Integer line, String message) { - errorsOccurred = true; - String fullMessage = message + " (Reported from " + file.toString() + " on line " - + line.toString() + ")"; - acceptor.acceptError(fullMessage, validatorState.getCurrentObject(), - null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return fullMessage; - } - - /** - * Report the given message as a waring on the object currently under - * validation. - */ - @Override - public String reportWarning(String message) { - acceptor.acceptWarning(message, validatorState.getCurrentObject(), null, - ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return message; - } - - @Override - public String reportInfo(String message) { - acceptor.acceptInfo(message, validatorState.getCurrentObject(), null, - ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return message; - } - - /** - * Report the given message as a warning on the given object. - */ - @Override - public String reportWarning(EObject object, String message) { - acceptor.acceptWarning(message, object, null, - ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return message; - } - - @Override - public String reportInfo(EObject object, String message) { - acceptor.acceptInfo(message, object, null, - ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return message; - } - - - /** - * Report the given message as an warning on the current object. - * - * Unfortunately, there is no way to provide a path and a line number to the - * ValidationMessageAcceptor as messages can only be reported directly as - * EObjects. While it is not an ideal solution, this method composes a - * messages indicating the location of the warning and reports this on the - * object currently under validation. This way, the warning message is not - * lost, but it is not necessarily reported precisely at the location of the - * actual warning. - */ - @Override - public String reportWarning(Path file, Integer line, String message) { - String fullMessage = message + " (Reported from " + file.toString() + " on line " - + line.toString() + ")"; - acceptor.acceptWarning(fullMessage, validatorState.getCurrentObject(), - null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return fullMessage; - } - - @Override - public String reportInfo(Path file, Integer line, String message) { - String fullMessage = message + " (Reported from " + file.toString() + " on line " - + line.toString() + ")"; - acceptor.acceptInfo(fullMessage, validatorState.getCurrentObject(), - null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - return fullMessage; - } - - /** - * Check if errors where reported. - * - * @return true if errors where reported - */ - @Override - public boolean getErrorsOccurred() { - return errorsOccurred; - } + private ValidationMessageAcceptor acceptor; + private BaseLFValidator.ValidatorStateAccess validatorState; + private boolean errorsOccurred = false; + + public ValidatorErrorReporter( + ValidationMessageAcceptor acceptor, BaseLFValidator.ValidatorStateAccess stateAccess) { + this.acceptor = acceptor; + this.validatorState = stateAccess; + } + + /** Report the given message as an error on the object currently under validation. */ + @Override + public String reportError(String message) { + errorsOccurred = true; + acceptor.acceptError( + message, + validatorState.getCurrentObject(), + null, + ValidationMessageAcceptor.INSIGNIFICANT_INDEX, + null); + return message; + } + + /** Report the given message as an error on the given object. */ + @Override + public String reportError(EObject object, String message) { + errorsOccurred = true; + acceptor.acceptError( + message, object, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); + return message; + } + + /** + * Report the given message as an error on the current object. + * + *

    Unfortunately, there is no way to provide a path and a line number to the + * ValidationMessageAcceptor as messages can only be reported directly as EObjects. While it is + * not an ideal solution, this method composes a messages indicating the location of the error and + * reports this on the object currently under validation. This way, the error message is not lost, + * but it is not necessarily reported precisely at the location of the actual error. + */ + @Override + public String reportError(Path file, Integer line, String message) { + errorsOccurred = true; + String fullMessage = + message + " (Reported from " + file.toString() + " on line " + line.toString() + ")"; + acceptor.acceptError( + fullMessage, + validatorState.getCurrentObject(), + null, + ValidationMessageAcceptor.INSIGNIFICANT_INDEX, + null); + return fullMessage; + } + + /** Report the given message as a waring on the object currently under validation. */ + @Override + public String reportWarning(String message) { + acceptor.acceptWarning( + message, + validatorState.getCurrentObject(), + null, + ValidationMessageAcceptor.INSIGNIFICANT_INDEX, + null); + return message; + } + + @Override + public String reportInfo(String message) { + acceptor.acceptInfo( + message, + validatorState.getCurrentObject(), + null, + ValidationMessageAcceptor.INSIGNIFICANT_INDEX, + null); + return message; + } + + /** Report the given message as a warning on the given object. */ + @Override + public String reportWarning(EObject object, String message) { + acceptor.acceptWarning( + message, object, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); + return message; + } + + @Override + public String reportInfo(EObject object, String message) { + acceptor.acceptInfo(message, object, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); + return message; + } + + /** + * Report the given message as an warning on the current object. + * + *

    Unfortunately, there is no way to provide a path and a line number to the + * ValidationMessageAcceptor as messages can only be reported directly as EObjects. While it is + * not an ideal solution, this method composes a messages indicating the location of the warning + * and reports this on the object currently under validation. This way, the warning message is not + * lost, but it is not necessarily reported precisely at the location of the actual warning. + */ + @Override + public String reportWarning(Path file, Integer line, String message) { + String fullMessage = + message + " (Reported from " + file.toString() + " on line " + line.toString() + ")"; + acceptor.acceptWarning( + fullMessage, + validatorState.getCurrentObject(), + null, + ValidationMessageAcceptor.INSIGNIFICANT_INDEX, + null); + return fullMessage; + } + + @Override + public String reportInfo(Path file, Integer line, String message) { + String fullMessage = + message + " (Reported from " + file.toString() + " on line " + line.toString() + ")"; + acceptor.acceptInfo( + fullMessage, + validatorState.getCurrentObject(), + null, + ValidationMessageAcceptor.INSIGNIFICANT_INDEX, + null); + return fullMessage; + } + + /** + * Check if errors where reported. + * + * @return true if errors where reported + */ + @Override + public boolean getErrorsOccurred() { + return errorsOccurred; + } } From 909860689905969e56125007369d5fa315583a82 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 22 May 2023 18:25:25 -0700 Subject: [PATCH 411/709] Initialize source_reactor for reactions writing to contained reactors --- .../src/org/lflang/generator/c/CTriggerObjectsGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index 0767b33bff..60b12c887a 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -665,6 +665,7 @@ private static String deferredInputNumDestinations( // Syntax is slightly different for a multiport output vs. single port. var connector = (port.isMultiport())? "->" : "."; code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"_base.num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); + code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"_base.source_reactor = (self_base_t*)"+CUtil.reactorRef(reaction.getParent(), sb)+";"); // Initialize token types. var type = ASTUtils.getInferredType(port.getDefinition()); From 107eccc03d35413b59c032b9a8fd3c00e219fac6 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 22 May 2023 18:34:47 -0700 Subject: [PATCH 412/709] Apply formatter --- org.lflang/src/lib/c/reactor-c | 2 +- .../lflang/generator/c/CActionGenerator.java | 292 +-- .../lflang/generator/c/CPortGenerator.java | 516 ++--- .../generator/c/CTriggerObjectsGenerator.java | 2016 +++++++++-------- 4 files changed, 1449 insertions(+), 1377 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 72da1e1e33..1784274083 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 72da1e1e331a2c27adc53c5ac8739c172c68dfd3 +Subproject commit 17842740830b1fa92eb012a6d007cc78653115b6 diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 72647f5c0e..9da9d1bb62 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -1,7 +1,9 @@ package org.lflang.generator.c; -import java.util.List; +import static org.lflang.generator.c.CGenerator.variableStructType; + import java.util.ArrayList; +import java.util.List; import org.lflang.ASTUtils; import org.lflang.Target; import org.lflang.generator.ActionInstance; @@ -9,8 +11,7 @@ import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; -import static org.lflang.generator.c.CGenerator.variableStructType; + /** * Generates code for actions (logical or physical) for the C and CCpp target. * @@ -24,156 +25,155 @@ * @author Hou Seng Wong */ public class CActionGenerator { - /** - * For each action of the specified reactor instance, generate initialization code - * for the offset and period fields. - * @param instance The reactor. - */ - public static String generateInitializers( - ReactorInstance instance - ) { - List code = new ArrayList<>(); - for (ActionInstance action : instance.actions) { - if (!action.isShutdown()) { - var triggerStructName = CUtil.reactorRef(action.getParent()) + "->_lf__" + action.getName(); - var minDelay = action.getMinDelay(); - var minSpacing = action.getMinSpacing(); - var offsetInitializer = triggerStructName+".offset = " + CTypes.getInstance().getTargetTimeExpr(minDelay) - + ";"; - var periodInitializer = triggerStructName+".period = " + (minSpacing != null ? - CTypes.getInstance().getTargetTimeExpr(minSpacing) : - CGenerator.UNDEFINED_MIN_SPACING) + ";"; - code.addAll(List.of( - "// Initializing action "+action.getFullName(), - offsetInitializer, - periodInitializer - )); + /** + * For each action of the specified reactor instance, generate initialization code for the offset + * and period fields. + * + * @param instance The reactor. + */ + public static String generateInitializers(ReactorInstance instance) { + List code = new ArrayList<>(); + for (ActionInstance action : instance.actions) { + if (!action.isShutdown()) { + var triggerStructName = CUtil.reactorRef(action.getParent()) + "->_lf__" + action.getName(); + var minDelay = action.getMinDelay(); + var minSpacing = action.getMinSpacing(); + var offsetInitializer = + triggerStructName + + ".offset = " + + CTypes.getInstance().getTargetTimeExpr(minDelay) + + ";"; + var periodInitializer = + triggerStructName + + ".period = " + + (minSpacing != null + ? CTypes.getInstance().getTargetTimeExpr(minSpacing) + : CGenerator.UNDEFINED_MIN_SPACING) + + ";"; + code.addAll( + List.of( + "// Initializing action " + action.getFullName(), + offsetInitializer, + periodInitializer)); - var mode = action.getMode(false); - if (mode != null) { - var modeParent = mode.getParent(); - var modeRef = "&"+CUtil.reactorRef(modeParent)+"->_lf__modes["+modeParent.modes.indexOf(mode)+"];"; - code.add(triggerStructName+".mode = "+modeRef+";"); - } else { - code.add(triggerStructName+".mode = NULL;"); - } - } + var mode = action.getMode(false); + if (mode != null) { + var modeParent = mode.getParent(); + var modeRef = + "&" + + CUtil.reactorRef(modeParent) + + "->_lf__modes[" + + modeParent.modes.indexOf(mode) + + "];"; + code.add(triggerStructName + ".mode = " + modeRef + ";"); + } else { + code.add(triggerStructName + ".mode = NULL;"); } - return String.join("\n", code); + } } + return String.join("\n", code); + } - /** - * Create a template token initialized to the payload size. - * This token is marked to not be freed so that the trigger_t struct - * always has a template token. - * At the start of each time step, we need to initialize the is_present field - * of each action's trigger object to false and free a previously - * allocated token if appropriate. This code sets up the table that does that. - * - * @param selfStruct The variable name of the self struct - * @param actionName The action name - * @param payloadSize The code that returns the size of the action's payload in C. - */ - public static String generateTokenInitializer( - String selfStruct, - String actionName, - String payloadSize - ) { - return String.join("\n", - "_lf_initialize_template((token_template_t*)", - " &("+selfStruct+"->_lf__"+actionName+"),", - payloadSize+");", - selfStruct+"->_lf__"+actionName+".status = absent;" - ); - } + /** + * Create a template token initialized to the payload size. This token is marked to not be freed + * so that the trigger_t struct always has a template token. At the start of each time step, we + * need to initialize the is_present field of each action's trigger object to false and free a + * previously allocated token if appropriate. This code sets up the table that does that. + * + * @param selfStruct The variable name of the self struct + * @param actionName The action name + * @param payloadSize The code that returns the size of the action's payload in C. + */ + public static String generateTokenInitializer( + String selfStruct, String actionName, String payloadSize) { + return String.join( + "\n", + "_lf_initialize_template((token_template_t*)", + " &(" + selfStruct + "->_lf__" + actionName + "),", + payloadSize + ");", + selfStruct + "->_lf__" + actionName + ".status = absent;"); + } - /** - * Generate the declarations of actions in the self struct - * - * @param reactor The reactor to generate declarations for - * @param decl The reactor's declaration - * @param body The content of the self struct - * @param constructorCode The constructor code of the reactor - */ - public static void generateDeclarations( - Reactor reactor, - CodeBuilder body, - CodeBuilder constructorCode - ) { - for (Action action : ASTUtils.allActions(reactor)) { - var actionName = action.getName(); - body.pr(action, CGenerator.variableStructType(action, reactor, false)+" _lf_"+actionName+";"); - // Initialize the trigger pointer and the parent pointer in the action. - constructorCode.pr(action, "self->_lf_"+actionName+"._base.trigger = &self->_lf__"+actionName+";"); - constructorCode.pr(action, "self->_lf_"+actionName+".parent = (self_base_t*)self;"); - } + /** + * Generate the declarations of actions in the self struct + * + * @param reactor The reactor to generate declarations for + * @param decl The reactor's declaration + * @param body The content of the self struct + * @param constructorCode The constructor code of the reactor + */ + public static void generateDeclarations( + Reactor reactor, CodeBuilder body, CodeBuilder constructorCode) { + for (Action action : ASTUtils.allActions(reactor)) { + var actionName = action.getName(); + body.pr( + action, + CGenerator.variableStructType(action, reactor, false) + " _lf_" + actionName + ";"); + // Initialize the trigger pointer and the parent pointer in the action. + constructorCode.pr( + action, "self->_lf_" + actionName + "._base.trigger = &self->_lf__" + actionName + ";"); + constructorCode.pr(action, "self->_lf_" + actionName + ".parent = (self_base_t*)self;"); } + } - /** - * Generate the struct type definitions for the action of the - * reactor - * - * @param decl The reactor declaration - * @param action The action to generate the struct for - * @param target The target of the code generation (C, CCpp or Python) - * @param types The helper object for types related stuff - * @param federatedExtension The code needed to support federated execution - * @return The auxiliary struct for the port as a string - */ - public static String generateAuxiliaryStruct( - Reactor r, - Action action, - Target target, - CTypes types, - CodeBuilder federatedExtension, - boolean userFacing - ) { - var code = new CodeBuilder(); - code.pr("typedef struct {"); - code.indent(); - // NOTE: The following fields are required to be the first ones so that - // pointer to this struct can be cast to a (lf_action_base_t*) or to - // (token_template_t*) to access these fields for any port. - // IMPORTANT: These must match exactly the fields defined in port.h!! - code.pr(String.join("\n", - "token_type_t type;", // From token_template_t - "lf_token_t* token;", // From token_template_t - "size_t length;", // From token_template_t - "bool is_present;", // From lf_port_or_action_t - "lf_action_internal_t _base;", // internal substruct - "self_base_t* parent;",// From lf_port_or_action_t - "bool has_value;" // From lf_action_base_t - )); - code.pr(valueDeclaration(action, target, types)); - code.pr(federatedExtension.toString()); - code.unindent(); - code.pr("} " + variableStructType(action, r, userFacing) + ";"); - return code.toString(); - } + /** + * Generate the struct type definitions for the action of the reactor + * + * @param decl The reactor declaration + * @param action The action to generate the struct for + * @param target The target of the code generation (C, CCpp or Python) + * @param types The helper object for types related stuff + * @param federatedExtension The code needed to support federated execution + * @return The auxiliary struct for the port as a string + */ + public static String generateAuxiliaryStruct( + Reactor r, + Action action, + Target target, + CTypes types, + CodeBuilder federatedExtension, + boolean userFacing) { + var code = new CodeBuilder(); + code.pr("typedef struct {"); + code.indent(); + // NOTE: The following fields are required to be the first ones so that + // pointer to this struct can be cast to a (lf_action_base_t*) or to + // (token_template_t*) to access these fields for any port. + // IMPORTANT: These must match exactly the fields defined in port.h!! + code.pr( + String.join( + "\n", + "token_type_t type;", // From token_template_t + "lf_token_t* token;", // From token_template_t + "size_t length;", // From token_template_t + "bool is_present;", // From lf_port_or_action_t + "lf_action_internal_t _base;", // internal substruct + "self_base_t* parent;", // From lf_port_or_action_t + "bool has_value;" // From lf_action_base_t + )); + code.pr(valueDeclaration(action, target, types)); + code.pr(federatedExtension.toString()); + code.unindent(); + code.pr("} " + variableStructType(action, r, userFacing) + ";"); + return code.toString(); + } - /** - * For the specified action, return a declaration for action struct to - * contain the value of the action. An action of - * type int[10], for example, will result in this: - * ``` - * int* value; - * ``` - * This will return an empty string for an action with no type. - * @param action The action. - * @return A string providing the value field of the action struct. - */ - private static String valueDeclaration( - Action action, - Target target, - CTypes types - ) { - if (target == Target.Python) { - return "PyObject* value;"; - } - // Do not convert to lf_token_t* using lfTypeToTokenType because there - // will be a separate field pointing to the token. - return action.getType() == null && target.requiresTypes ? - "" : - types.getTargetType(action) + " value;"; + /** + * For the specified action, return a declaration for action struct to contain the value of the + * action. An action of type int[10], for example, will result in this: ``` int* value; ``` This + * will return an empty string for an action with no type. + * + * @param action The action. + * @return A string providing the value field of the action struct. + */ + private static String valueDeclaration(Action action, Target target, CTypes types) { + if (target == Target.Python) { + return "PyObject* value;"; } + // Do not convert to lf_token_t* using lfTypeToTokenType because there + // will be a separate field pointing to the token. + return action.getType() == null && target.requiresTypes + ? "" + : types.getTargetType(action) + " value;"; + } } diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java index d315536139..1e9da4e309 100644 --- a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CPortGenerator.java @@ -1,5 +1,7 @@ package org.lflang.generator.c; +import static org.lflang.generator.c.CGenerator.variableStructType; + import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.ErrorReporter; @@ -11,8 +13,6 @@ import org.lflang.lf.Port; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; -import static org.lflang.generator.c.CGenerator.variableStructType; - /** * Generates C code to declare and initialize ports. @@ -22,270 +22,276 @@ * @author Hou Seng Wong */ public class CPortGenerator { - /** - * Generate fields in the self struct for input and output ports - * - * @param reactor - * @param decl - * @param body - * @param constructorCode - */ - public static void generateDeclarations( - Reactor reactor, - ReactorDecl decl, - CodeBuilder body, - CodeBuilder constructorCode - ) { - generateInputDeclarations(reactor, decl, body, constructorCode); - generateOutputDeclarations(reactor, decl, body, constructorCode); - } + /** + * Generate fields in the self struct for input and output ports + * + * @param reactor + * @param decl + * @param body + * @param constructorCode + */ + public static void generateDeclarations( + Reactor reactor, ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode) { + generateInputDeclarations(reactor, decl, body, constructorCode); + generateOutputDeclarations(reactor, decl, body, constructorCode); + } - /** - * Generate the struct type definitions for the port of the - * reactor - * - * @param r The reactor - * @param port The port to generate the struct - * @param target The target of the code generation (C, CCpp or Python) - * @param errorReporter The error reporter - * @param types The helper object for types related stuff - * @param federatedExtension The code needed to support federated execution - * @param userFacing Whether this struct is to be presented in a user-facing header - * @param decl The reactorDecl if this struct is for the header of this reactor's container; - * null otherwise - * @return The auxiliary struct for the port as a string - */ - public static String generateAuxiliaryStruct( - Reactor r, - Port port, - Target target, - ErrorReporter errorReporter, - CTypes types, - CodeBuilder federatedExtension, - boolean userFacing, - ReactorDecl decl - ) { - assert decl == null || userFacing; - var code = new CodeBuilder(); - code.pr("typedef struct {"); - code.indent(); - // NOTE: The following fields are required to be the first ones so that - // pointer to this struct can be cast to a (lf_port_base_t*) or to - // (token_template_t*) to access these fields for any port. - // IMPORTANT: These must match exactly the fields defined in port.h!! - code.pr(String.join("\n", - "token_type_t type;", // From token_template_t - "lf_token_t* token;", // From token_template_t - "size_t length;", // From token_template_t - "bool is_present;", - "lf_port_internal_t _base;" - )); - code.pr(valueDeclaration(port, target, errorReporter, types)); - code.pr(federatedExtension.toString()); - code.unindent(); - var name = decl != null ? localPortName(decl, port.getName()) + /** + * Generate the struct type definitions for the port of the reactor + * + * @param r The reactor + * @param port The port to generate the struct + * @param target The target of the code generation (C, CCpp or Python) + * @param errorReporter The error reporter + * @param types The helper object for types related stuff + * @param federatedExtension The code needed to support federated execution + * @param userFacing Whether this struct is to be presented in a user-facing header + * @param decl The reactorDecl if this struct is for the header of this reactor's container; null + * otherwise + * @return The auxiliary struct for the port as a string + */ + public static String generateAuxiliaryStruct( + Reactor r, + Port port, + Target target, + ErrorReporter errorReporter, + CTypes types, + CodeBuilder federatedExtension, + boolean userFacing, + ReactorDecl decl) { + assert decl == null || userFacing; + var code = new CodeBuilder(); + code.pr("typedef struct {"); + code.indent(); + // NOTE: The following fields are required to be the first ones so that + // pointer to this struct can be cast to a (lf_port_base_t*) or to + // (token_template_t*) to access these fields for any port. + // IMPORTANT: These must match exactly the fields defined in port.h!! + code.pr( + String.join( + "\n", + "token_type_t type;", // From token_template_t + "lf_token_t* token;", // From token_template_t + "size_t length;", // From token_template_t + "bool is_present;", + "lf_port_internal_t _base;")); + code.pr(valueDeclaration(port, target, errorReporter, types)); + code.pr(federatedExtension.toString()); + code.unindent(); + var name = + decl != null + ? localPortName(decl, port.getName()) : variableStructType(port, r, userFacing); - code.pr("} " + name + ";"); - return code.toString(); - } + code.pr("} " + name + ";"); + return code.toString(); + } - public static String localPortName(ReactorDecl decl, String portName) { - return decl.getName().toLowerCase() + "_" + portName + "_t"; - } + public static String localPortName(ReactorDecl decl, String portName) { + return decl.getName().toLowerCase() + "_" + portName + "_t"; + } - /** - * Allocate memory for the input port. - * @param input The input port - * @param reactorSelfStruct The name of the self struct - */ - public static String initializeInputMultiport( - PortInstance input, - String reactorSelfStruct - ) { - var portRefName = CUtil.portRefName(input); - // If the port is a multiport, create an array. - if (input.isMultiport()) { - String result = String.join("\n", - portRefName+"_width = "+input.getWidth()+";", - "// Allocate memory for multiport inputs.", - portRefName+" = ("+variableStructType(input)+"**)_lf_allocate(", - " "+input.getWidth()+", sizeof("+variableStructType(input)+"*),", - " &"+reactorSelfStruct+"->base.allocations); ", - "// Set inputs by default to an always absent default input.", - "for (int i = 0; i < "+input.getWidth()+"; i++) {", - " "+portRefName+"[i] = &"+reactorSelfStruct+"->_lf_default__"+input.getName()+";", - "}" - ); - if (AttributeUtils.isSparse(input.getDefinition())) { - return String.join("\n", result, - "if ("+input.getWidth()+" >= LF_SPARSE_WIDTH_THRESHOLD) {", - " "+portRefName+"__sparse = (lf_sparse_io_record_t*)_lf_allocate(1,", - " sizeof(lf_sparse_io_record_t) + sizeof(size_t) * "+input.getWidth()+"/LF_SPARSE_CAPACITY_DIVIDER,", - " &"+reactorSelfStruct+"->base.allocations);", - " "+portRefName+"__sparse->capacity = "+input.getWidth()+"/LF_SPARSE_CAPACITY_DIVIDER;", - " if (_lf_sparse_io_record_sizes.start == NULL) {", - " _lf_sparse_io_record_sizes = vector_new(1);", - " }", - " vector_push(&_lf_sparse_io_record_sizes, (void*)&"+portRefName+"__sparse->size);", - "}" - ); - } - return result; - } else { - return String.join("\n", - "// width of -2 indicates that it is not a multiport.", - portRefName+"_width = -2;" - ); - } + /** + * Allocate memory for the input port. + * + * @param input The input port + * @param reactorSelfStruct The name of the self struct + */ + public static String initializeInputMultiport(PortInstance input, String reactorSelfStruct) { + var portRefName = CUtil.portRefName(input); + // If the port is a multiport, create an array. + if (input.isMultiport()) { + String result = + String.join( + "\n", + portRefName + "_width = " + input.getWidth() + ";", + "// Allocate memory for multiport inputs.", + portRefName + " = (" + variableStructType(input) + "**)_lf_allocate(", + " " + input.getWidth() + ", sizeof(" + variableStructType(input) + "*),", + " &" + reactorSelfStruct + "->base.allocations); ", + "// Set inputs by default to an always absent default input.", + "for (int i = 0; i < " + input.getWidth() + "; i++) {", + " " + + portRefName + + "[i] = &" + + reactorSelfStruct + + "->_lf_default__" + + input.getName() + + ";", + "}"); + if (AttributeUtils.isSparse(input.getDefinition())) { + return String.join( + "\n", + result, + "if (" + input.getWidth() + " >= LF_SPARSE_WIDTH_THRESHOLD) {", + " " + portRefName + "__sparse = (lf_sparse_io_record_t*)_lf_allocate(1,", + " sizeof(lf_sparse_io_record_t) + sizeof(size_t) * " + + input.getWidth() + + "/LF_SPARSE_CAPACITY_DIVIDER,", + " &" + reactorSelfStruct + "->base.allocations);", + " " + + portRefName + + "__sparse->capacity = " + + input.getWidth() + + "/LF_SPARSE_CAPACITY_DIVIDER;", + " if (_lf_sparse_io_record_sizes.start == NULL) {", + " _lf_sparse_io_record_sizes = vector_new(1);", + " }", + " vector_push(&_lf_sparse_io_record_sizes, (void*)&" + + portRefName + + "__sparse->size);", + "}"); + } + return result; + } else { + return String.join( + "\n", + "// width of -2 indicates that it is not a multiport.", + portRefName + "_width = -2;"); } + } - /** - * Allocate memory for the output port. - * @param output The output port - * @param reactorSelfStruct The name of the self struct - */ - public static String initializeOutputMultiport( - PortInstance output, - String reactorSelfStruct - ) { - var portRefName = CUtil.portRefName(output); - var portStructType = variableStructType(output); - return output.isMultiport() ? - String.join("\n", - portRefName+"_width = "+output.getWidth()+";", - "// Allocate memory for multiport output.", - portRefName+" = ("+portStructType+"*)_lf_allocate(", - " "+output.getWidth()+", sizeof("+portStructType+"),", - " &"+reactorSelfStruct+"->base.allocations); ", - portRefName+"_pointers = ("+portStructType+"**)_lf_allocate(", - " "+output.getWidth()+", sizeof("+portStructType+"*),", - " &"+reactorSelfStruct+"->base.allocations); ", - "// Assign each output port pointer to be used in", - "// reactions to facilitate user access to output ports", - "for(int i=0; i < "+output.getWidth()+"; i++) {", - " "+portRefName+"_pointers[i] = &("+portRefName+"[i]);", - "}" - ) : - String.join("\n", - "// width of -2 indicates that it is not a multiport.", - portRefName+"_width = -2;" - ); - } + /** + * Allocate memory for the output port. + * + * @param output The output port + * @param reactorSelfStruct The name of the self struct + */ + public static String initializeOutputMultiport(PortInstance output, String reactorSelfStruct) { + var portRefName = CUtil.portRefName(output); + var portStructType = variableStructType(output); + return output.isMultiport() + ? String.join( + "\n", + portRefName + "_width = " + output.getWidth() + ";", + "// Allocate memory for multiport output.", + portRefName + " = (" + portStructType + "*)_lf_allocate(", + " " + output.getWidth() + ", sizeof(" + portStructType + "),", + " &" + reactorSelfStruct + "->base.allocations); ", + portRefName + "_pointers = (" + portStructType + "**)_lf_allocate(", + " " + output.getWidth() + ", sizeof(" + portStructType + "*),", + " &" + reactorSelfStruct + "->base.allocations); ", + "// Assign each output port pointer to be used in", + "// reactions to facilitate user access to output ports", + "for(int i=0; i < " + output.getWidth() + "; i++) {", + " " + portRefName + "_pointers[i] = &(" + portRefName + "[i]);", + "}") + : String.join( + "\n", + "// width of -2 indicates that it is not a multiport.", + portRefName + "_width = -2;"); + } - /** - * For the specified port, return a declaration for port struct to - * contain the value of the port. A multiport output with width 4 and - * type int[10], for example, will result in this: - * ``` - * int value[10]; - * ``` - * There will be an array of size 4 of structs, each containing this value - * array. - * @param port The port. - * @return A string providing the value field of the port struct. - */ - private static String valueDeclaration( - Port port, - Target target, - ErrorReporter errorReporter, - CTypes types - ) { - if (port.getType() == null && target.requiresTypes) { - // This should have been caught by the validator. - errorReporter.reportError(port, "Port is required to have a type: " + port.getName()); - return ""; - } - // Do not convert to lf_token_t* using lfTypeToTokenType because there - // will be a separate field pointing to the token. - return types.getVariableDeclaration(ASTUtils.getInferredType(port), "value", false) + ";"; + /** + * For the specified port, return a declaration for port struct to contain the value of the port. + * A multiport output with width 4 and type int[10], for example, will result in this: ``` int + * value[10]; ``` There will be an array of size 4 of structs, each containing this value array. + * + * @param port The port. + * @return A string providing the value field of the port struct. + */ + private static String valueDeclaration( + Port port, Target target, ErrorReporter errorReporter, CTypes types) { + if (port.getType() == null && target.requiresTypes) { + // This should have been caught by the validator. + errorReporter.reportError(port, "Port is required to have a type: " + port.getName()); + return ""; } + // Do not convert to lf_token_t* using lfTypeToTokenType because there + // will be a separate field pointing to the token. + return types.getVariableDeclaration(ASTUtils.getInferredType(port), "value", false) + ";"; + } - /** - * Generate fields in the self struct for input ports - * - * If the port is a multiport, the input field is an array of - * pointers that will be allocated separately for each instance - * because the sizes may be different. Otherwise, it is a simple - * pointer. - * - */ - private static void generateInputDeclarations( - Reactor reactor, - ReactorDecl decl, - CodeBuilder body, - CodeBuilder constructorCode - ) { - for (Input input : ASTUtils.allInputs(reactor)) { - var inputName = input.getName(); - if (ASTUtils.isMultiport(input)) { - body.pr(input, String.join("\n", - "// Multiport input array will be malloc'd later.", - variableStructType(input, reactor, false)+"** _lf_"+inputName+";", - "int _lf_"+inputName+"_width;", - "// Default input (in case it does not get connected)", - variableStructType(input, reactor, false)+" _lf_default__"+inputName+";", - "// Struct to support efficiently reading sparse inputs.", - "lf_sparse_io_record_t* _lf_"+inputName+"__sparse;" - )); - } else { - // input is not a multiport. - body.pr(input, String.join("\n", - variableStructType(input, reactor, false)+"* _lf_"+inputName+";", - "// width of -2 indicates that it is not a multiport.", - "int _lf_"+inputName+"_width;", - "// Default input (in case it does not get connected)", - variableStructType(input, reactor, false)+" _lf_default__"+inputName+";" - )); + /** + * Generate fields in the self struct for input ports + * + *

    If the port is a multiport, the input field is an array of pointers that will be allocated + * separately for each instance because the sizes may be different. Otherwise, it is a simple + * pointer. + */ + private static void generateInputDeclarations( + Reactor reactor, ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode) { + for (Input input : ASTUtils.allInputs(reactor)) { + var inputName = input.getName(); + if (ASTUtils.isMultiport(input)) { + body.pr( + input, + String.join( + "\n", + "// Multiport input array will be malloc'd later.", + variableStructType(input, reactor, false) + "** _lf_" + inputName + ";", + "int _lf_" + inputName + "_width;", + "// Default input (in case it does not get connected)", + variableStructType(input, reactor, false) + " _lf_default__" + inputName + ";", + "// Struct to support efficiently reading sparse inputs.", + "lf_sparse_io_record_t* _lf_" + inputName + "__sparse;")); + } else { + // input is not a multiport. + body.pr( + input, + String.join( + "\n", + variableStructType(input, reactor, false) + "* _lf_" + inputName + ";", + "// width of -2 indicates that it is not a multiport.", + "int _lf_" + inputName + "_width;", + "// Default input (in case it does not get connected)", + variableStructType(input, reactor, false) + " _lf_default__" + inputName + ";")); - constructorCode.pr(input, String.join("\n", - "// Set input by default to an always absent default input.", - "self->_lf_"+inputName+" = &self->_lf_default__"+inputName+";" - )); - } - constructorCode.pr(input, String.join("\n", - "// Set the default source reactor pointer", - "self->_lf_default__"+inputName+"._base.source_reactor = (self_base_t*)self;" - )); - } + constructorCode.pr( + input, + String.join( + "\n", + "// Set input by default to an always absent default input.", + "self->_lf_" + inputName + " = &self->_lf_default__" + inputName + ";")); + } + constructorCode.pr( + input, + String.join( + "\n", + "// Set the default source reactor pointer", + "self->_lf_default__" + inputName + "._base.source_reactor = (self_base_t*)self;")); } + } - /** - * Generate fields in the self struct for output ports - * - * @param reactor - * @param decl - * @param body - * @param constructorCode - */ - private static void generateOutputDeclarations( - Reactor reactor, - ReactorDecl decl, - CodeBuilder body, - CodeBuilder constructorCode - ) { - for (Output output : ASTUtils.allOutputs(reactor)) { - // If the port is a multiport, create an array to be allocated - // at instantiation. - var outputName = output.getName(); - if (ASTUtils.isMultiport(output)) { - body.pr(output, String.join("\n", - "// Array of output ports.", - variableStructType(output, reactor, false)+"* _lf_"+outputName+";", - "int _lf_"+outputName+"_width;", - "// An array of pointers to the individual ports. Useful", - "// for the lf_set macros to work out-of-the-box for", - "// multiports in the body of reactions because their ", - "// value can be accessed via a -> operator (e.g.,foo[i]->value).", - "// So we have to handle multiports specially here a construct that", - "// array of pointers.", - variableStructType(output, reactor, false)+"** _lf_"+outputName+"_pointers;" - )); - } else { - body.pr(output, String.join("\n", - variableStructType(output, reactor, false)+" _lf_"+outputName+";", - "int _lf_"+outputName+"_width;" - )); - } - } + /** + * Generate fields in the self struct for output ports + * + * @param reactor + * @param decl + * @param body + * @param constructorCode + */ + private static void generateOutputDeclarations( + Reactor reactor, ReactorDecl decl, CodeBuilder body, CodeBuilder constructorCode) { + for (Output output : ASTUtils.allOutputs(reactor)) { + // If the port is a multiport, create an array to be allocated + // at instantiation. + var outputName = output.getName(); + if (ASTUtils.isMultiport(output)) { + body.pr( + output, + String.join( + "\n", + "// Array of output ports.", + variableStructType(output, reactor, false) + "* _lf_" + outputName + ";", + "int _lf_" + outputName + "_width;", + "// An array of pointers to the individual ports. Useful", + "// for the lf_set macros to work out-of-the-box for", + "// multiports in the body of reactions because their ", + "// value can be accessed via a -> operator (e.g.,foo[i]->value).", + "// So we have to handle multiports specially here a construct that", + "// array of pointers.", + variableStructType(output, reactor, false) + + "** _lf_" + + outputName + + "_pointers;")); + } else { + body.pr( + output, + String.join( + "\n", + variableStructType(output, reactor, false) + " _lf_" + outputName + ";", + "int _lf_" + outputName + "_width;")); + } } + } } diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index 60b12c887a..0aa503b934 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -1,4 +1,5 @@ package org.lflang.generator.c; + import static org.lflang.generator.c.CMixedRadixGenerator.db; import static org.lflang.generator.c.CMixedRadixGenerator.dc; import static org.lflang.generator.c.CMixedRadixGenerator.dr; @@ -8,15 +9,13 @@ import static org.lflang.util.StringUtil.addDoubleQuotes; import static org.lflang.util.StringUtil.joinObjects; +import com.google.common.collect.Iterables; import java.util.Arrays; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.stream.Collectors; - import org.lflang.ASTUtils; import org.lflang.AttributeUtils; import org.lflang.TargetConfig; - import org.lflang.TargetProperty.LogLevel; import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.CodeBuilder; @@ -26,8 +25,6 @@ import org.lflang.generator.RuntimeRange; import org.lflang.generator.SendRange; -import com.google.common.collect.Iterables; - /** * Generate code for the "_lf_initialize_trigger_objects" function * @@ -36,1029 +33,1098 @@ * @author Hou Seng Wong */ public class CTriggerObjectsGenerator { - /** - * Generate the _lf_initialize_trigger_objects function for 'federate'. - */ - public static String generateInitializeTriggerObjects( - ReactorInstance main, - TargetConfig targetConfig, - CodeBuilder initializeTriggerObjects, - CodeBuilder startTimeStep, - CTypes types, - String lfModuleName, - int startTimeStepIsPresentCount - ) { - var code = new CodeBuilder(); - code.pr("void _lf_initialize_trigger_objects() {"); - code.indent(); - // Initialize the LF clock. - code.pr(String.join("\n", - "// Initialize the _lf_clock", - "lf_initialize_clock();" - )); - - // Initialize tracing if it is enabled - if (targetConfig.tracing != null) { - var traceFileName = lfModuleName; - if (targetConfig.tracing.traceFileName != null) { - traceFileName = targetConfig.tracing.traceFileName; - } - code.pr(String.join("\n", - "// Initialize tracing", - "start_trace("+ addDoubleQuotes(traceFileName + ".lft") + ");" - )); // .lft is for Lingua Franca trace - } + /** Generate the _lf_initialize_trigger_objects function for 'federate'. */ + public static String generateInitializeTriggerObjects( + ReactorInstance main, + TargetConfig targetConfig, + CodeBuilder initializeTriggerObjects, + CodeBuilder startTimeStep, + CTypes types, + String lfModuleName, + int startTimeStepIsPresentCount) { + var code = new CodeBuilder(); + code.pr("void _lf_initialize_trigger_objects() {"); + code.indent(); + // Initialize the LF clock. + code.pr(String.join("\n", "// Initialize the _lf_clock", "lf_initialize_clock();")); + + // Initialize tracing if it is enabled + if (targetConfig.tracing != null) { + var traceFileName = lfModuleName; + if (targetConfig.tracing.traceFileName != null) { + traceFileName = targetConfig.tracing.traceFileName; + } + code.pr( + String.join( + "\n", + "// Initialize tracing", + "start_trace(" + + addDoubleQuotes(traceFileName + ".lft") + + ");")); // .lft is for Lingua Franca trace + } - // Create the table to initialize is_present fields to false between time steps. - if (startTimeStepIsPresentCount > 0) { - // Allocate the initial (before mutations) array of pointers to _is_present fields. - code.pr(String.join("\n", - "// Create the array that will contain pointers to is_present fields to reset on each step.", - "_lf_is_present_fields_size = "+startTimeStepIsPresentCount+";", - "_lf_is_present_fields = (bool**)calloc("+startTimeStepIsPresentCount+", sizeof(bool*));", - "if (_lf_is_present_fields == NULL) lf_print_error_and_exit(" + addDoubleQuotes("Out of memory!") + ");", - "_lf_is_present_fields_abbreviated = (bool**)calloc("+startTimeStepIsPresentCount+", sizeof(bool*));", - "if (_lf_is_present_fields_abbreviated == NULL) lf_print_error_and_exit(" + addDoubleQuotes("Out of memory!") + ");", - "_lf_is_present_fields_abbreviated_size = 0;" - )); - } + // Create the table to initialize is_present fields to false between time steps. + if (startTimeStepIsPresentCount > 0) { + // Allocate the initial (before mutations) array of pointers to _is_present fields. + code.pr( + String.join( + "\n", + "// Create the array that will contain pointers to is_present fields to reset on each" + + " step.", + "_lf_is_present_fields_size = " + startTimeStepIsPresentCount + ";", + "_lf_is_present_fields = (bool**)calloc(" + + startTimeStepIsPresentCount + + ", sizeof(bool*));", + "if (_lf_is_present_fields == NULL) lf_print_error_and_exit(" + + addDoubleQuotes("Out of memory!") + + ");", + "_lf_is_present_fields_abbreviated = (bool**)calloc(" + + startTimeStepIsPresentCount + + ", sizeof(bool*));", + "if (_lf_is_present_fields_abbreviated == NULL) lf_print_error_and_exit(" + + addDoubleQuotes("Out of memory!") + + ");", + "_lf_is_present_fields_abbreviated_size = 0;")); + } - // Create the table to initialize intended tag fields to 0 between time - // steps. - if (startTimeStepIsPresentCount > 0) { - // Allocate the initial (before mutations) array of pointers to - // intended_tag fields. - // There is a 1-1 map between structs containing is_present and - // intended_tag fields, - // thus, we reuse startTimeStepIsPresentCount as the counter. - code.pr(String.join("\n", - CExtensionUtils.surroundWithIfFederatedDecentralized(""" + // Create the table to initialize intended tag fields to 0 between time + // steps. + if (startTimeStepIsPresentCount > 0) { + // Allocate the initial (before mutations) array of pointers to + // intended_tag fields. + // There is a 1-1 map between structs containing is_present and + // intended_tag fields, + // thus, we reuse startTimeStepIsPresentCount as the counter. + code.pr( + String.join( + "\n", + CExtensionUtils.surroundWithIfFederatedDecentralized( + """ // Create the array that will contain pointers to intended_tag fields to reset on each step. _lf_intended_tag_fields_size = %s; _lf_intended_tag_fields = (tag_t**)malloc(_lf_intended_tag_fields_size * sizeof(tag_t*)); - """.formatted(startTimeStepIsPresentCount) - ) - )); - } - + """ + .formatted(startTimeStepIsPresentCount)))); + } - code.pr(initializeTriggerObjects.toString()); - - code.pr(deferredInitialize( - main, - main.reactions, - targetConfig, - types - )); - code.pr(deferredInitializeNonNested( - main, - main, - main.reactions, - types - )); - // Next, for every input port, populate its "self" struct - // fields with pointers to the output port that sends it data. - code.pr(deferredConnectInputsToOutputs( - main - )); - // Put the code here to set up the tables that drive resetting is_present and - // decrementing reference counts between time steps. This code has to appear - // in _lf_initialize_trigger_objects() after the code that makes connections - // between inputs and outputs. - code.pr(startTimeStep.toString()); - code.pr(setReactionPriorities( - main - )); - code.pr(generateSchedulerInitializer( - main, - targetConfig - )); - - code.pr(""" + code.pr(initializeTriggerObjects.toString()); + + code.pr(deferredInitialize(main, main.reactions, targetConfig, types)); + code.pr(deferredInitializeNonNested(main, main, main.reactions, types)); + // Next, for every input port, populate its "self" struct + // fields with pointers to the output port that sends it data. + code.pr(deferredConnectInputsToOutputs(main)); + // Put the code here to set up the tables that drive resetting is_present and + // decrementing reference counts between time steps. This code has to appear + // in _lf_initialize_trigger_objects() after the code that makes connections + // between inputs and outputs. + code.pr(startTimeStep.toString()); + code.pr(setReactionPriorities(main)); + code.pr(generateSchedulerInitializer(main, targetConfig)); + + code.pr( + """ #ifdef EXECUTABLE_PREAMBLE _lf_executable_preamble(); #endif """); - // Initialize triggers for federated execution. - code.pr(CExtensionUtils.surroundWithIfFederated("initialize_triggers_for_federate();")); + // Initialize triggers for federated execution. + code.pr(CExtensionUtils.surroundWithIfFederated("initialize_triggers_for_federate();")); - code.unindent(); - code.pr("}\n"); - return code.toString(); - } + code.unindent(); + code.pr("}\n"); + return code.toString(); + } - /** - * Generate code to initialize the scheduler for the threaded C runtime. - */ - public static String generateSchedulerInitializer( - ReactorInstance main, - TargetConfig targetConfig - ) { - if (!targetConfig.threading) { - return ""; - } - var code = new CodeBuilder(); - var numReactionsPerLevel = main.assignLevels().getNumReactionsPerLevel(); - var numReactionsPerLevelJoined = Arrays.stream(numReactionsPerLevel) - .map(String::valueOf) - .collect(Collectors.joining(", ")); - code.pr(String.join("\n", + /** Generate code to initialize the scheduler for the threaded C runtime. */ + public static String generateSchedulerInitializer( + ReactorInstance main, TargetConfig targetConfig) { + if (!targetConfig.threading) { + return ""; + } + var code = new CodeBuilder(); + var numReactionsPerLevel = main.assignLevels().getNumReactionsPerLevel(); + var numReactionsPerLevelJoined = + Arrays.stream(numReactionsPerLevel).map(String::valueOf).collect(Collectors.joining(", ")); + code.pr( + String.join( + "\n", "// Initialize the scheduler", - "size_t num_reactions_per_level["+numReactionsPerLevel.length+"] = ", + "size_t num_reactions_per_level[" + numReactionsPerLevel.length + "] = ", " {" + numReactionsPerLevelJoined + "};", "sched_params_t sched_params = (sched_params_t) {", " .num_reactions_per_level = &num_reactions_per_level[0],", - " .num_reactions_per_level_size = (size_t) "+numReactionsPerLevel.length+"};", + " .num_reactions_per_level_size = (size_t) " + + numReactionsPerLevel.length + + "};", "lf_sched_init(", " (size_t)_lf_number_of_workers,", " &sched_params", - ");" - )); - return code.toString(); + ");")); + return code.toString(); + } + + /** + * * Set the reaction priorities based on dependency analysis. + * + * @param reactor The reactor on which to do this. + */ + private static String setReactionPriorities(ReactorInstance reactor) { + var code = new CodeBuilder(); + setReactionPriorities(reactor, code); + return code.toString(); + } + + /** + * * Set the reaction priorities based on dependency analysis. + * + * @param reactor The reactor on which to do this. + * @param builder Where to write the code. + */ + private static boolean setReactionPriorities(ReactorInstance reactor, CodeBuilder builder) { + var foundOne = false; + // Force calculation of levels if it has not been done. + // FIXME: Comment out this as I think it is redundant. + // If it is NOT redundant then deadline propagation is not correct + // reactor.assignLevels(); + + // We handle four different scenarios + // 1) A reactionInstance has 1 level and 1 deadline + // 2) A reactionInstance has 1 level but multiple deadlines + // 3) A reaction instance has multiple levels but all have the same deadline + // 4) Multiple deadlines and levels + + var prolog = new CodeBuilder(); + var epilog = new CodeBuilder(); + + for (ReactionInstance r : reactor.reactions) { + var levelSet = r.getLevels(); + var deadlineSet = r.getInferredDeadlines(); + + if (levelSet.size() > 1 || deadlineSet.size() > 1) { + // Scenario 2-4 + if (prolog.length() == 0) { + prolog.startScopedBlock(); + epilog.endScopedBlock(); + } + } + if (deadlineSet.size() > 1) { + // Scenario (2) or (4) + var deadlines = + r.getInferredDeadlinesList().stream() + .map(elt -> ("0x" + Long.toString(elt.toNanoSeconds(), 16) + "LL")) + .collect(Collectors.toList()); + + prolog.pr( + "interval_t " + + r.uniqueID() + + "_inferred_deadlines[] = { " + + joinObjects(deadlines, ", ") + + " };"); + } + + if (levelSet.size() > 1) { + // Scenario (3) or (4) + // Cannot use the above set of levels because it is a set, not a list. + prolog.pr( + "int " + + r.uniqueID() + + "_levels[] = { " + + joinObjects(r.getLevelsList(), ", ") + + " };"); + } } - /** - * * Set the reaction priorities based on dependency analysis. - * - * @param reactor The reactor on which to do this. - */ - private static String setReactionPriorities( - ReactorInstance reactor - ) { - var code = new CodeBuilder(); - setReactionPriorities(reactor, code); - return code.toString(); + var temp = new CodeBuilder(); + temp.pr("// Set reaction priorities for " + reactor); + temp.startScopedBlock(reactor); + for (ReactionInstance r : reactor.reactions) { + // if (currentFederate.contains(r.getDefinition())) { + foundOne = true; + var levelSet = r.getLevels(); + var deadlineSet = r.getInferredDeadlines(); + + // Get the head of the associated lists. To avoid duplication in + // several of the following cases + var level = r.getLevelsList().get(0); + var inferredDeadline = r.getInferredDeadlinesList().get(0); + var runtimeIdx = CUtil.runtimeIndex(r.getParent()); + + if (levelSet.size() == 1 && deadlineSet.size() == 1) { + // Scenario (1) + + var indexValue = inferredDeadline.toNanoSeconds() << 16 | level; + + var reactionIndex = "0x" + Long.toUnsignedString(indexValue, 16) + "LL"; + + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of level " + level + " and ", + "// deadline " + inferredDeadline.toNanoSeconds() + " shifted left 16 bits.", + CUtil.reactionRef(r) + ".index = " + reactionIndex + ";")); + } else if (levelSet.size() == 1 && deadlineSet.size() > 1) { + // Scenario 2 + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of levels[" + runtimeIdx + "] and ", + "// deadlines[" + runtimeIdx + "] shifted left 16 bits.", + CUtil.reactionRef(r) + + ".index = (" + + r.uniqueID() + + "_inferred_deadlines[" + + runtimeIdx + + "] << 16) | " + + level + + ";")); + + } else if (levelSet.size() > 1 && deadlineSet.size() == 1) { + // Scenarion (3) + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of levels[" + runtimeIdx + "] and ", + "// deadlines[" + runtimeIdx + "] shifted left 16 bits.", + CUtil.reactionRef(r) + + ".index = (" + + inferredDeadline.toNanoSeconds() + + " << 16) | " + + r.uniqueID() + + "_levels[" + + runtimeIdx + + "];")); + + } else if (levelSet.size() > 1 && deadlineSet.size() > 1) { + // Scenario (4) + temp.pr( + String.join( + "\n", + CUtil.reactionRef(r) + ".chain_id = " + r.chainID + ";", + "// index is the OR of levels[" + runtimeIdx + "] and ", + "// deadlines[" + runtimeIdx + "] shifted left 16 bits.", + CUtil.reactionRef(r) + + ".index = (" + + r.uniqueID() + + "_inferred_deadlines[" + + runtimeIdx + + "] << 16) | " + + r.uniqueID() + + "_levels[" + + runtimeIdx + + "];")); + } } - - /** - * * Set the reaction priorities based on dependency analysis. - * - * @param reactor The reactor on which to do this. - * @param builder Where to write the code. - */ - private static boolean setReactionPriorities( - ReactorInstance reactor, - CodeBuilder builder - ) { - var foundOne = false; - // Force calculation of levels if it has not been done. - // FIXME: Comment out this as I think it is redundant. - // If it is NOT redundant then deadline propagation is not correct - // reactor.assignLevels(); - - // We handle four different scenarios - // 1) A reactionInstance has 1 level and 1 deadline - // 2) A reactionInstance has 1 level but multiple deadlines - // 3) A reaction instance has multiple levels but all have the same deadline - // 4) Multiple deadlines and levels - - var prolog = new CodeBuilder(); - var epilog = new CodeBuilder(); - - for (ReactionInstance r : reactor.reactions) { - var levelSet = r.getLevels(); - var deadlineSet = r.getInferredDeadlines(); - - if (levelSet.size() > 1 || deadlineSet.size() > 1) { - // Scenario 2-4 - if (prolog.length() == 0) { - prolog.startScopedBlock(); - epilog.endScopedBlock(); - } - } - if (deadlineSet.size() > 1) { - // Scenario (2) or (4) - var deadlines = r.getInferredDeadlinesList().stream() - .map(elt -> ("0x" + Long.toString(elt.toNanoSeconds(), 16) + "LL")) - .collect(Collectors.toList()); - - prolog.pr("interval_t "+r.uniqueID()+"_inferred_deadlines[] = { "+joinObjects(deadlines, ", ")+" };"); - } - - if (levelSet.size() > 1) { - // Scenario (3) or (4) - // Cannot use the above set of levels because it is a set, not a list. - prolog.pr("int "+r.uniqueID()+"_levels[] = { "+joinObjects(r.getLevelsList(), ", ")+" };"); - } - } - - - var temp = new CodeBuilder(); - temp.pr("// Set reaction priorities for " + reactor); - temp.startScopedBlock(reactor); - for (ReactionInstance r : reactor.reactions) { - //if (currentFederate.contains(r.getDefinition())) { - foundOne = true; - var levelSet = r.getLevels(); - var deadlineSet = r.getInferredDeadlines(); - - // Get the head of the associated lists. To avoid duplication in - // several of the following cases - var level = r.getLevelsList().get(0); - var inferredDeadline = r.getInferredDeadlinesList().get(0); - var runtimeIdx =CUtil.runtimeIndex(r.getParent()); - - if (levelSet.size() == 1 && deadlineSet.size() == 1) { - // Scenario (1) - - var indexValue = inferredDeadline.toNanoSeconds() << 16 | level; - - var reactionIndex = "0x" + Long.toUnsignedString(indexValue, 16) + "LL"; - - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of level "+level+" and ", - "// deadline "+ inferredDeadline.toNanoSeconds()+" shifted left 16 bits.", - CUtil.reactionRef(r)+".index = "+reactionIndex+";" - )); - } else if (levelSet.size() == 1 && deadlineSet.size() > 1) { - // Scenario 2 - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of levels["+runtimeIdx+"] and ", - "// deadlines["+runtimeIdx+"] shifted left 16 bits.", - CUtil.reactionRef(r)+".index = ("+r.uniqueID()+"_inferred_deadlines["+runtimeIdx+"] << 16) | " + - level+";" - )); - - } else if (levelSet.size() > 1 && deadlineSet.size() == 1) { - // Scenarion (3) - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of levels["+runtimeIdx+"] and ", - "// deadlines["+runtimeIdx+"] shifted left 16 bits.", - CUtil.reactionRef(r)+".index = ("+inferredDeadline.toNanoSeconds()+" << 16) | " + - r.uniqueID()+"_levels["+runtimeIdx+"];" - )); - - } else if (levelSet.size() > 1 && deadlineSet.size() > 1) { - // Scenario (4) - temp.pr(String.join("\n", - CUtil.reactionRef(r)+".chain_id = "+r.chainID+";", - "// index is the OR of levels["+runtimeIdx+"] and ", - "// deadlines["+runtimeIdx+"] shifted left 16 bits.", - CUtil.reactionRef(r)+".index = ("+r.uniqueID()+"_inferred_deadlines["+runtimeIdx+"] << 16) | " + - r.uniqueID()+"_levels["+runtimeIdx+"];" - )); - } - - } - for (ReactorInstance child : reactor.children) { - foundOne = setReactionPriorities(child, temp) || foundOne; - } - temp.endScopedBlock(); - - if (foundOne) { - builder.pr(prolog.toString()); - builder.pr(temp.toString()); - builder.pr(epilog.toString()); - } - return foundOne; + for (ReactorInstance child : reactor.children) { + foundOne = setReactionPriorities(child, temp) || foundOne; } + temp.endScopedBlock(); - /** - * Generate assignments of pointers in the "self" struct of a destination - * port's reactor to the appropriate entries in the "self" struct of the - * source reactor. This has to be done after all reactors have been created - * because inputs point to outputs that are arbitrarily far away. - * @param instance The reactor instance. - */ - private static String deferredConnectInputsToOutputs( - ReactorInstance instance - ) { - var code = new CodeBuilder(); - code.pr("// Connect inputs and outputs for reactor "+instance.getFullName()+"."); - // Iterate over all ports of this reactor that depend on reactions. - for (PortInstance input : instance.inputs) { - if (!input.getDependsOnReactions().isEmpty()) { - // Input is written to by reactions in the parent of the port's parent. - code.pr(connectPortToEventualDestinations(input)); - } - } - for (PortInstance output : instance.outputs) { - if (!output.getDependsOnReactions().isEmpty()) { - // Output is written to by reactions in the port's parent. - code.pr(connectPortToEventualDestinations(output)); - } - } - for (ReactorInstance child: instance.children) { - code.pr(deferredConnectInputsToOutputs(child)); - } - return code.toString(); + if (foundOne) { + builder.pr(prolog.toString()); + builder.pr(temp.toString()); + builder.pr(epilog.toString()); } - - /** - * Generate assignments of pointers in the "self" struct of a destination - * port's reactor to the appropriate entries in the "self" struct of the - * source reactor. If this port is an input, then it is being written - * to by a reaction belonging to the parent of the port's parent. - * If it is an output, then it is being written to by a reaction belonging - * to the port's parent. - * @param src A port that is written to by reactions. - */ - private static String connectPortToEventualDestinations( - PortInstance src - ) { - var code = new CodeBuilder(); - for (SendRange srcRange: src.eventualDestinations()) { - for (RuntimeRange dstRange : srcRange.destinations) { - var dst = dstRange.instance; - var destStructType = CGenerator.variableStructType(dst); - - // NOTE: For federated execution, dst.getParent() should always be contained - // by the currentFederate because an AST transformation removes connections - // between ports of distinct federates. So the following check is not - // really necessary. - var mod = (dst.isMultiport() || (src.isInput() && src.isMultiport()))? "" : "&"; - code.pr("// Connect "+srcRange+" to port "+dstRange); - code.startScopedRangeBlock(srcRange, dstRange); - if (src.isInput()) { - // Source port is written to by reaction in port's parent's parent - // and ultimate destination is further downstream. - code.pr(CUtil.portRef(dst, dr, db, dc)+" = ("+destStructType+"*)"+mod+CUtil.portRefNested(src, sr, sb, sc)+";"); - } else if (dst.isOutput()) { - // An output port of a contained reactor is triggering a reaction. - code.pr(CUtil.portRefNested(dst, dr, db, dc)+" = ("+destStructType+"*)&"+CUtil.portRef(src, sr, sb, sc)+";"); - } else { - // An output port is triggering an input port. - code.pr(CUtil.portRef(dst, dr, db, dc)+" = ("+destStructType+"*)&"+CUtil.portRef(src, sr, sb, sc)+";"); - if (AttributeUtils.isSparse(dst.getDefinition())) { - code.pr(CUtil.portRef(dst, dr, db, dc)+"->sparse_record = "+CUtil.portRefName(dst, dr, db, dc)+"__sparse;"); - code.pr(CUtil.portRef(dst, dr, db, dc)+"->destination_channel = "+dc+";"); - } - } - code.endScopedRangeBlock(srcRange, dstRange); - } - } - return code.toString(); + return foundOne; + } + + /** + * Generate assignments of pointers in the "self" struct of a destination port's reactor to the + * appropriate entries in the "self" struct of the source reactor. This has to be done after all + * reactors have been created because inputs point to outputs that are arbitrarily far away. + * + * @param instance The reactor instance. + */ + private static String deferredConnectInputsToOutputs(ReactorInstance instance) { + var code = new CodeBuilder(); + code.pr("// Connect inputs and outputs for reactor " + instance.getFullName() + "."); + // Iterate over all ports of this reactor that depend on reactions. + for (PortInstance input : instance.inputs) { + if (!input.getDependsOnReactions().isEmpty()) { + // Input is written to by reactions in the parent of the port's parent. + code.pr(connectPortToEventualDestinations(input)); + } } - - /** - * For each reaction of the specified reactor, - * set the last_enabling_reaction field of the reaction struct to point - * to the single dominating upstream reaction if there is one, or to be - * NULL if there is none. - * - * @param r The reactor. - */ - private static String deferredOptimizeForSingleDominatingReaction( - ReactorInstance r - ) { - var code = new CodeBuilder(); - for (ReactionInstance reaction : r.reactions) { - // The following code attempts to gather into a loop assignments of successive - // bank members relations between reactions to avoid large chunks of inline code - // when a large bank sends to a large bank or when a large bank receives from - // one reaction that is either multicasting or sending through a multiport. - var start = 0; - var end = 0; - var domStart = 0; - var same = false; // Set to true when finding a string of identical dominating reactions. - ReactionInstance.Runtime previousRuntime = null; - var first = true; //First time through the loop. - for (ReactionInstance.Runtime runtime : reaction.getRuntimeInstances()) { - if (!first) { // Not the first time through the loop. - if (same) { // Previously seen at least two identical dominating. - if (runtime.dominating != previousRuntime.dominating) { - // End of streak of same dominating reaction runtime instance. - code.pr(printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - )); - same = false; - start = runtime.id; - domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; - } - } else if (runtime.dominating == previousRuntime.dominating) { - // Start of a streak of identical dominating reaction runtime instances. - same = true; - } else if (runtime.dominating != null && previousRuntime.dominating != null - && runtime.dominating.getReaction() == previousRuntime.dominating.getReaction() - ) { - // Same dominating reaction even if not the same dominating runtime. - if (runtime.dominating.id != previousRuntime.dominating.id + 1) { - // End of a streak of contiguous runtimes. - printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - ); - same = false; - start = runtime.id; - domStart = runtime.dominating.id; - } - } else { - // Different dominating reaction. - printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - ); - same = false; - start = runtime.id; - domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; - } - } - first = false; - previousRuntime = runtime; - end++; - } - if (end > start) { - printOptimizeForSingleDominatingReaction( - previousRuntime, start, end, domStart, same - ); - } - } - return code.toString(); + for (PortInstance output : instance.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { + // Output is written to by reactions in the port's parent. + code.pr(connectPortToEventualDestinations(output)); + } } - - /** - * Print statement that sets the last_enabling_reaction field of a reaction. - */ - private static String printOptimizeForSingleDominatingReaction( - ReactionInstance.Runtime runtime, - int start, - int end, - int domStart, - boolean same - ) { - var code = new CodeBuilder(); - var dominatingRef = "NULL"; - - if (end > start + 1) { - code.startScopedBlock(); - var reactionRef = CUtil.reactionRef(runtime.getReaction(), "i"); - if (runtime.dominating != null) { - if (same) { - dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; - } else { - dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "j++") + ")"; - } - } - code.pr(String.join("\n", - "// "+runtime.getReaction().getFullName()+" dominating upstream reaction.", - "int j = "+domStart+";", - "for (int i = "+start+"; i < "+end+"; i++) {", - " "+reactionRef+".last_enabling_reaction = "+dominatingRef+";", - "}" - )); - code.endScopedBlock(); - } else if (end == start + 1) { - var reactionRef = CUtil.reactionRef(runtime.getReaction(), "" + start); - if (runtime.dominating != null) { - dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; - } - code.pr(String.join("\n", - "// "+runtime.getReaction().getFullName()+" dominating upstream reaction.", - reactionRef+".last_enabling_reaction = "+dominatingRef+";" - )); - } - return code.toString(); + for (ReactorInstance child : instance.children) { + code.pr(deferredConnectInputsToOutputs(child)); } - - /** - * For the specified reaction, for ports that it writes to, - * fill the trigger table for triggering downstream reactions. - * - * @param reactions The reactions. - */ - private static String deferredFillTriggerTable( - Iterable reactions - ) { - var code = new CodeBuilder(); - for (ReactionInstance reaction : reactions) { - var name = reaction.getParent().getFullName(); - - var reactorSelfStruct = CUtil.reactorRef(reaction.getParent(), sr); - - var foundPort = false; - - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (!foundPort) { - // Need a separate index for the triggers array for each bank member. - code.startScopedBlock(); - code.pr("int triggers_index["+reaction.getParent().getTotalWidth()+"] = { 0 }; // Number of bank members with the reaction."); - foundPort = true; - } - // If the port is a multiport, then its channels may have different sets - // of destinations. For ordinary ports, there will be only one range and - // its width will be 1. - // We generate the code to fill the triggers array first in a temporary code buffer, - // so that we can simultaneously calculate the size of the total array. - for (SendRange srcRange : port.eventualDestinations()) { - var srcNested = port.isInput(); - code.startScopedRangeBlock(srcRange, sr, sb, sc, srcNested); - - var triggerArray = CUtil.reactionRef(reaction, sr)+".triggers[triggers_index["+sr+"]++]"; - // Skip ports whose parent is not in the federation. - // This can happen with reactions in the top-level that have - // as an effect a port in a bank. - code.pr(String.join("\n", - "// Reaction "+reaction.index+" of "+name+" triggers "+srcRange.destinations.size()+" downstream reactions", - "// through port "+port.getFullName()+".", - CUtil.reactionRef(reaction, sr)+".triggered_sizes[triggers_index["+sr+"]] = "+srcRange.destinations.size()+";", - "// For reaction "+reaction.index+" of "+name+", allocate an", - "// array of trigger pointers for downstream reactions through port "+port.getFullName(), - "trigger_t** trigger_array = (trigger_t**)_lf_allocate(", - " "+srcRange.destinations.size()+", sizeof(trigger_t*),", - " &"+reactorSelfStruct+"->base.allocations); ", - triggerArray+" = trigger_array;" - )); - code.endScopedRangeBlock(srcRange); - } - } - var cumulativePortWidth = 0; - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - // If this port does not have any destinations, do not generate code for it. - if (port.eventualDestinations().isEmpty()) continue; - - code.pr("for (int i = 0; i < "+reaction.getParent().getTotalWidth()+"; i++) triggers_index[i] = "+cumulativePortWidth+";"); - for (SendRange srcRange : port.eventualDestinations()) { - var srcNested = srcRange.instance.isInput(); - var multicastCount = 0; - for (RuntimeRange dstRange : srcRange.destinations) { - var dst = dstRange.instance; - - code.startScopedRangeBlock(srcRange, dstRange); - - // If the source is nested, need to take into account the parent's bank index - // when indexing into the triggers array. - var triggerArray = ""; - if (srcNested && port.getParent().getWidth() > 1) { - triggerArray = CUtil.reactionRef(reaction, sr)+".triggers[triggers_index["+sr+"] + "+sc+" + src_range_mr.digits[1] * src_range_mr.radixes[0]]"; - } else { - triggerArray = CUtil.reactionRef(reaction, sr)+".triggers[triggers_index["+sr+"] + "+sc+"]"; - } - - if (dst.isOutput()) { - // Include this destination port only if it has at least one - // reaction in the federation. - var belongs = false; - for (ReactionInstance destinationReaction : dst.getDependentReactions()) { - belongs = true; - } - if (belongs) { - code.pr(String.join("\n", - "// Port "+port.getFullName()+" has reactions in its parent's parent.", - "// Point to the trigger struct for those reactions.", - triggerArray+"["+multicastCount+"] = &"+CUtil.triggerRefNested(dst, dr, db)+";" - )); - } else { - // Put in a NULL pointer. - code.pr(String.join("\n", - "// Port "+port.getFullName()+" has reactions in its parent's parent.", - "// But those are not in the federation.", - triggerArray+"["+multicastCount+"] = NULL;" - )); - } - } else { - // Destination is an input port. - code.pr(String.join("\n", - "// Point to destination port "+dst.getFullName()+"'s trigger struct.", - triggerArray+"["+multicastCount+"] = &"+CUtil.triggerRef(dst, dr)+";" - )); - } - code.endScopedRangeBlock(srcRange, dstRange); - multicastCount++; - } - } - // If the port is an input of a contained reactor, then we have to take - // into account the bank width of the contained reactor. - if (port.getParent() != reaction.getParent()) { - cumulativePortWidth += port.getWidth() * port.getParent().getWidth(); - } else { - cumulativePortWidth += port.getWidth(); - } - } - if (foundPort) code.endScopedBlock(); + return code.toString(); + } + + /** + * Generate assignments of pointers in the "self" struct of a destination port's reactor to the + * appropriate entries in the "self" struct of the source reactor. If this port is an input, then + * it is being written to by a reaction belonging to the parent of the port's parent. If it is an + * output, then it is being written to by a reaction belonging to the port's parent. + * + * @param src A port that is written to by reactions. + */ + private static String connectPortToEventualDestinations(PortInstance src) { + var code = new CodeBuilder(); + for (SendRange srcRange : src.eventualDestinations()) { + for (RuntimeRange dstRange : srcRange.destinations) { + var dst = dstRange.instance; + var destStructType = CGenerator.variableStructType(dst); + + // NOTE: For federated execution, dst.getParent() should always be contained + // by the currentFederate because an AST transformation removes connections + // between ports of distinct federates. So the following check is not + // really necessary. + var mod = (dst.isMultiport() || (src.isInput() && src.isMultiport())) ? "" : "&"; + code.pr("// Connect " + srcRange + " to port " + dstRange); + code.startScopedRangeBlock(srcRange, dstRange); + if (src.isInput()) { + // Source port is written to by reaction in port's parent's parent + // and ultimate destination is further downstream. + code.pr( + CUtil.portRef(dst, dr, db, dc) + + " = (" + + destStructType + + "*)" + + mod + + CUtil.portRefNested(src, sr, sb, sc) + + ";"); + } else if (dst.isOutput()) { + // An output port of a contained reactor is triggering a reaction. + code.pr( + CUtil.portRefNested(dst, dr, db, dc) + + " = (" + + destStructType + + "*)&" + + CUtil.portRef(src, sr, sb, sc) + + ";"); + } else { + // An output port is triggering an input port. + code.pr( + CUtil.portRef(dst, dr, db, dc) + + " = (" + + destStructType + + "*)&" + + CUtil.portRef(src, sr, sb, sc) + + ";"); + if (AttributeUtils.isSparse(dst.getDefinition())) { + code.pr( + CUtil.portRef(dst, dr, db, dc) + + "->sparse_record = " + + CUtil.portRefName(dst, dr, db, dc) + + "__sparse;"); + code.pr(CUtil.portRef(dst, dr, db, dc) + "->destination_channel = " + dc + ";"); + } } - return code.toString(); + code.endScopedRangeBlock(srcRange, dstRange); + } } - - /** - * For each input port of a contained reactor that receives data - * from one or more of the specified reactions, set the num_destinations - * field of the corresponding port structs on the self struct of - * the reaction's parent reactor equal to the total number of - * destination reactors. - * If the port has a token type, this also initializes it with a token. - * @param reactions The reactions. - * @param types The C types. - */ - private static String deferredInputNumDestinations( - Iterable reactions, - CTypes types - ) { - // We need the number of destination _reactors_, not the - // number of destination ports nor the number of destination reactions. - // One of the destination reactors may be the container of this - // instance because it may have a reaction to an output of this instance. - // Since a port may be written to by multiple reactions, - // ensure that this is done only once. - var portsHandled = new HashSet(); - var code = new CodeBuilder(); - for (ReactionInstance reaction : reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.isInput() && !portsHandled.contains(port)) { - // Port is an input of a contained reactor that gets data from a reaction of this reactor. - portsHandled.add(port); - code.pr("// Set number of destination reactors for port "+port.getParent().getName()+"."+port.getName()+"."); - // The input port may itself have multiple destinations. - for (SendRange sendingRange : port.eventualDestinations()) { - code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); - // Syntax is slightly different for a multiport output vs. single port. - var connector = (port.isMultiport())? "->" : "."; - code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"_base.num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); - code.pr(CUtil.portRefNested(port, sr, sb, sc)+connector+"_base.source_reactor = (self_base_t*)"+CUtil.reactorRef(reaction.getParent(), sb)+";"); - - // Initialize token types. - var type = ASTUtils.getInferredType(port.getDefinition()); - if (CUtil.isTokenType(type, types)) { - // Create the template token that goes in the port struct. - var rootType = CUtil.rootType(types.getTargetType(type)); - // If the rootType is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; - // If the port is a multiport, then the portRefNested is itself a pointer - // so we want its value, not its address. - var indirection = (port.isMultiport())? "" : "&"; - code.startChannelIteration(port); - code.pr(String.join("\n", - "_lf_initialize_template((token_template_t*)", - " "+indirection+"("+CUtil.portRefNested(port, sr, sb, sc)+"),", - size+");" - )); - code.endChannelIteration(port); - } - - code.endScopedRangeBlock(sendingRange); - } - } + return code.toString(); + } + + /** + * For each reaction of the specified reactor, set the last_enabling_reaction field of the + * reaction struct to point to the single dominating upstream reaction if there is one, or to be + * NULL if there is none. + * + * @param r The reactor. + */ + private static String deferredOptimizeForSingleDominatingReaction(ReactorInstance r) { + var code = new CodeBuilder(); + for (ReactionInstance reaction : r.reactions) { + // The following code attempts to gather into a loop assignments of successive + // bank members relations between reactions to avoid large chunks of inline code + // when a large bank sends to a large bank or when a large bank receives from + // one reaction that is either multicasting or sending through a multiport. + var start = 0; + var end = 0; + var domStart = 0; + var same = false; // Set to true when finding a string of identical dominating reactions. + ReactionInstance.Runtime previousRuntime = null; + var first = true; // First time through the loop. + for (ReactionInstance.Runtime runtime : reaction.getRuntimeInstances()) { + if (!first) { // Not the first time through the loop. + if (same) { // Previously seen at least two identical dominating. + if (runtime.dominating != previousRuntime.dominating) { + // End of streak of same dominating reaction runtime instance. + code.pr( + printOptimizeForSingleDominatingReaction( + previousRuntime, start, end, domStart, same)); + same = false; + start = runtime.id; + domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; } - } - return code.toString(); - } - - /** - * For each output port of the specified reactor, - * set the num_destinations field of port structs on its self struct - * equal to the total number of destination reactors. This is used - * to initialize reference counts in dynamically allocated tokens - * sent to other reactors. - * @param reactor The reactor instance. - */ - private static String deferredOutputNumDestinations( - ReactorInstance reactor - ) { - // Reference counts are decremented by each destination reactor - // at the conclusion of a time step. Hence, the initial reference - // count should equal the number of destination _reactors_, not the - // number of destination ports nor the number of destination reactions. - // One of the destination reactors may be the container of this - // instance because it may have a reaction to an output of this instance. - var code = new CodeBuilder(); - for (PortInstance output : reactor.outputs) { - for (SendRange sendingRange : output.eventualDestinations()) { - code.pr("// For reference counting, set num_destinations for port " + output.getFullName() + "."); - code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); - code.pr(CUtil.portRef(output, sr, sb, sc)+"._base.num_destinations = "+sendingRange.getNumberOfDestinationReactors()+";"); - code.pr(CUtil.portRef(output, sr, sb, sc)+"._base.source_reactor = (self_base_t*)"+CUtil.reactorRef(reactor, sb)+";"); - code.endScopedRangeBlock(sendingRange); + } else if (runtime.dominating == previousRuntime.dominating) { + // Start of a streak of identical dominating reaction runtime instances. + same = true; + } else if (runtime.dominating != null + && previousRuntime.dominating != null + && runtime.dominating.getReaction() == previousRuntime.dominating.getReaction()) { + // Same dominating reaction even if not the same dominating runtime. + if (runtime.dominating.id != previousRuntime.dominating.id + 1) { + // End of a streak of contiguous runtimes. + printOptimizeForSingleDominatingReaction(previousRuntime, start, end, domStart, same); + same = false; + start = runtime.id; + domStart = runtime.dominating.id; } + } else { + // Different dominating reaction. + printOptimizeForSingleDominatingReaction(previousRuntime, start, end, domStart, same); + same = false; + start = runtime.id; + domStart = (runtime.dominating != null) ? runtime.dominating.id : 0; + } } - return code.toString(); + first = false; + previousRuntime = runtime; + end++; + } + if (end > start) { + printOptimizeForSingleDominatingReaction(previousRuntime, start, end, domStart, same); + } } - - /** - * Perform initialization functions that must be performed after - * all reactor runtime instances have been created. - * This function does not create nested loops over nested banks, - * so each function it calls must handle its own iteration - * over all runtime instance. - * @param reactor The container. - * @param main The top-level reactor. - * @param reactions The list of reactions to consider. - * @param types The C types. - */ - private static String deferredInitializeNonNested( - ReactorInstance reactor, - ReactorInstance main, - Iterable reactions, - CTypes types - ) { - var code = new CodeBuilder(); - code.pr("// **** Start non-nested deferred initialize for "+reactor.getFullName()); - // Initialize the num_destinations fields of port structs on the self struct. - // This needs to be outside the above scoped block because it performs - // its own iteration over ranges. - code.pr(deferredInputNumDestinations( - reactions, - types - )); - - // Second batch of initializes cannot be within a for loop - // iterating over bank members because they iterate over send - // ranges which may span bank members. - if (reactor != main) { - code.pr(deferredOutputNumDestinations( - reactor - )); - } - code.pr(deferredFillTriggerTable( - reactions - )); - code.pr(deferredOptimizeForSingleDominatingReaction( - reactor - )); - for (ReactorInstance child: reactor.children) { - code.pr(deferredInitializeNonNested( - child, - main, - child.reactions, - types - )); + return code.toString(); + } + + /** Print statement that sets the last_enabling_reaction field of a reaction. */ + private static String printOptimizeForSingleDominatingReaction( + ReactionInstance.Runtime runtime, int start, int end, int domStart, boolean same) { + var code = new CodeBuilder(); + var dominatingRef = "NULL"; + + if (end > start + 1) { + code.startScopedBlock(); + var reactionRef = CUtil.reactionRef(runtime.getReaction(), "i"); + if (runtime.dominating != null) { + if (same) { + dominatingRef = + "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; + } else { + dominatingRef = "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "j++") + ")"; } - code.pr("// **** End of non-nested deferred initialize for "+reactor.getFullName()); - return code.toString(); + } + code.pr( + String.join( + "\n", + "// " + runtime.getReaction().getFullName() + " dominating upstream reaction.", + "int j = " + domStart + ";", + "for (int i = " + start + "; i < " + end + "; i++) {", + " " + reactionRef + ".last_enabling_reaction = " + dominatingRef + ";", + "}")); + code.endScopedBlock(); + } else if (end == start + 1) { + var reactionRef = CUtil.reactionRef(runtime.getReaction(), "" + start); + if (runtime.dominating != null) { + dominatingRef = + "&(" + CUtil.reactionRef(runtime.dominating.getReaction(), "" + domStart) + ")"; + } + code.pr( + String.join( + "\n", + "// " + runtime.getReaction().getFullName() + " dominating upstream reaction.", + reactionRef + ".last_enabling_reaction = " + dominatingRef + ";")); } - - /** - * For each output of the specified reactor that has a token type - * (type* or type[]), create a template token and put it on the self struct. - * @param reactor The reactor. - */ - private static String deferredCreateTemplateTokens( - ReactorInstance reactor, - CTypes types - ) { - var code = new CodeBuilder(); - // Look for outputs with token types. - for (PortInstance output : reactor.outputs) { - var type = ASTUtils.getInferredType(output.getDefinition()); - if (CUtil.isTokenType(type, types)) { - // Create the template token that goes in the trigger struct. - // Its reference count is zero, enabling it to be used immediately. - var rootType = CUtil.rootType(types.getTargetType(type)); - // If the rootType is 'void', we need to avoid generating the code - // 'sizeof(void)', which some compilers reject. - var size = (rootType.equals("void")) ? "0" : "sizeof("+rootType+")"; - code.startChannelIteration(output); - code.pr(String.join("\n", - "_lf_initialize_template((token_template_t*)", - " &("+CUtil.portRef(output)+"),", - size+");" - )); - code.endChannelIteration(output); - } + return code.toString(); + } + + /** + * For the specified reaction, for ports that it writes to, fill the trigger table for triggering + * downstream reactions. + * + * @param reactions The reactions. + */ + private static String deferredFillTriggerTable(Iterable reactions) { + var code = new CodeBuilder(); + for (ReactionInstance reaction : reactions) { + var name = reaction.getParent().getFullName(); + + var reactorSelfStruct = CUtil.reactorRef(reaction.getParent(), sr); + + var foundPort = false; + + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (!foundPort) { + // Need a separate index for the triggers array for each bank member. + code.startScopedBlock(); + code.pr( + "int triggers_index[" + + reaction.getParent().getTotalWidth() + + "] = { 0 }; // Number of bank members with the reaction."); + foundPort = true; } - return code.toString(); - } - - /** - * For the specified reaction, for ports that it writes to, - * set up the arrays that store the results (if necessary) and - * that are used to trigger downstream reactions if an effect is actually - * produced. The port may be an output of the reaction's parent - * or an input to a reactor contained by the parent. - * - * @param reaction The reaction instance. - */ - private static String deferredReactionOutputs( - ReactionInstance reaction, - TargetConfig targetConfig - ) { - var code = new CodeBuilder(); - // val selfRef = CUtil.reactorRef(reaction.getParent()); - var name = reaction.getParent().getFullName(); - // Insert a string name to facilitate debugging. - if (targetConfig.logLevel.compareTo(LogLevel.LOG) >= 0) { - code.pr(CUtil.reactionRef(reaction)+".name = "+addDoubleQuotes(name+" reaction "+reaction.index)+";"); + // If the port is a multiport, then its channels may have different sets + // of destinations. For ordinary ports, there will be only one range and + // its width will be 1. + // We generate the code to fill the triggers array first in a temporary code buffer, + // so that we can simultaneously calculate the size of the total array. + for (SendRange srcRange : port.eventualDestinations()) { + var srcNested = port.isInput(); + code.startScopedRangeBlock(srcRange, sr, sb, sc, srcNested); + + var triggerArray = + CUtil.reactionRef(reaction, sr) + ".triggers[triggers_index[" + sr + "]++]"; + // Skip ports whose parent is not in the federation. + // This can happen with reactions in the top-level that have + // as an effect a port in a bank. + code.pr( + String.join( + "\n", + "// Reaction " + + reaction.index + + " of " + + name + + " triggers " + + srcRange.destinations.size() + + " downstream reactions", + "// through port " + port.getFullName() + ".", + CUtil.reactionRef(reaction, sr) + + ".triggered_sizes[triggers_index[" + + sr + + "]] = " + + srcRange.destinations.size() + + ";", + "// For reaction " + reaction.index + " of " + name + ", allocate an", + "// array of trigger pointers for downstream reactions through port " + + port.getFullName(), + "trigger_t** trigger_array = (trigger_t**)_lf_allocate(", + " " + srcRange.destinations.size() + ", sizeof(trigger_t*),", + " &" + reactorSelfStruct + "->base.allocations); ", + triggerArray + " = trigger_array;")); + code.endScopedRangeBlock(srcRange); } - - var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); - - // Count the output ports and inputs of contained reactors that - // may be set by this reaction. This ignores actions in the effects. - // Collect initialization statements for the output_produced array for the reaction - // to point to the is_present field of the appropriate output. - // These statements must be inserted after the array is malloc'd, - // but we construct them while we are counting outputs. - var outputCount = 0; - var init = new CodeBuilder(); - - init.startScopedBlock(); - init.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { - // Create the entry in the output_produced array for this port. - // If the port is a multiport, then we need to create an entry for each - // individual channel. - - // If the port is an input of a contained reactor, then, if that - // contained reactor is a bank, we will have to iterate over bank - // members. - var bankWidth = 1; - var portRef = ""; - if (effect.isInput()) { - init.pr("// Reaction writes to an input of a contained reactor."); - bankWidth = effect.getParent().getWidth(); - init.startScopedBlock(effect.getParent()); - portRef = CUtil.portRefNestedName(effect); + } + var cumulativePortWidth = 0; + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + // If this port does not have any destinations, do not generate code for it. + if (port.eventualDestinations().isEmpty()) continue; + + code.pr( + "for (int i = 0; i < " + + reaction.getParent().getTotalWidth() + + "; i++) triggers_index[i] = " + + cumulativePortWidth + + ";"); + for (SendRange srcRange : port.eventualDestinations()) { + var srcNested = srcRange.instance.isInput(); + var multicastCount = 0; + for (RuntimeRange dstRange : srcRange.destinations) { + var dst = dstRange.instance; + + code.startScopedRangeBlock(srcRange, dstRange); + + // If the source is nested, need to take into account the parent's bank index + // when indexing into the triggers array. + var triggerArray = ""; + if (srcNested && port.getParent().getWidth() > 1) { + triggerArray = + CUtil.reactionRef(reaction, sr) + + ".triggers[triggers_index[" + + sr + + "] + " + + sc + + " + src_range_mr.digits[1] * src_range_mr.radixes[0]]"; } else { - init.startScopedBlock(); - portRef = CUtil.portRefName(effect); + triggerArray = + CUtil.reactionRef(reaction, sr) + + ".triggers[triggers_index[" + + sr + + "] + " + + sc + + "]"; } - if (effect.isMultiport()) { - // Form is slightly different for inputs vs. outputs. - var connector = "."; - if (effect.isInput()) connector = "->"; - - // Point the output_produced field to where the is_present field of the port is. - init.pr(String.join("\n", - "for (int i = 0; i < "+effect.getWidth()+"; i++) {", - " "+CUtil.reactionRef(reaction)+".output_produced[i + count]", - " = &"+portRef+"[i]"+connector+"is_present;", - "}", - "count += "+effect.getWidth()+";" - )); - outputCount += effect.getWidth() * bankWidth; + if (dst.isOutput()) { + // Include this destination port only if it has at least one + // reaction in the federation. + var belongs = false; + for (ReactionInstance destinationReaction : dst.getDependentReactions()) { + belongs = true; + } + if (belongs) { + code.pr( + String.join( + "\n", + "// Port " + port.getFullName() + " has reactions in its parent's parent.", + "// Point to the trigger struct for those reactions.", + triggerArray + + "[" + + multicastCount + + "] = &" + + CUtil.triggerRefNested(dst, dr, db) + + ";")); + } else { + // Put in a NULL pointer. + code.pr( + String.join( + "\n", + "// Port " + port.getFullName() + " has reactions in its parent's parent.", + "// But those are not in the federation.", + triggerArray + "[" + multicastCount + "] = NULL;")); + } } else { - // The effect is not a multiport. - init.pr(CUtil.reactionRef(reaction)+".output_produced[count++] = &"+portRef+".is_present;"); - outputCount += bankWidth; + // Destination is an input port. + code.pr( + String.join( + "\n", + "// Point to destination port " + dst.getFullName() + "'s trigger struct.", + triggerArray + + "[" + + multicastCount + + "] = &" + + CUtil.triggerRef(dst, dr) + + ";")); } - init.endScopedBlock(); + code.endScopedRangeBlock(srcRange, dstRange); + multicastCount++; + } } - init.endScopedBlock(); - code.pr(String.join("\n", - "// Total number of outputs (single ports and multiport channels)", - "// produced by "+reaction+".", - CUtil.reactionRef(reaction)+".num_outputs = "+outputCount+";" - )); - if (outputCount > 0) { - code.pr(String.join("\n", - "// Allocate memory for triggers[] and triggered_sizes[] on the reaction_t", - "// struct for this reaction.", - CUtil.reactionRef(reaction)+".triggers = (trigger_t***)_lf_allocate(", - " "+outputCount+", sizeof(trigger_t**),", - " &"+reactorSelfStruct+"->base.allocations);", - CUtil.reactionRef(reaction)+".triggered_sizes = (int*)_lf_allocate(", - " "+outputCount+", sizeof(int),", - " &"+reactorSelfStruct+"->base.allocations);", - CUtil.reactionRef(reaction)+".output_produced = (bool**)_lf_allocate(", - " "+outputCount+", sizeof(bool*),", - " &"+reactorSelfStruct+"->base.allocations);" - )); + // If the port is an input of a contained reactor, then we have to take + // into account the bank width of the contained reactor. + if (port.getParent() != reaction.getParent()) { + cumulativePortWidth += port.getWidth() * port.getParent().getWidth(); + } else { + cumulativePortWidth += port.getWidth(); } - - code.pr(String.join("\n", - init.toString(), - "// ** End initialization for reaction "+reaction.index+" of "+name - )); - return code.toString(); + } + if (foundPort) code.endScopedBlock(); } - - /** - * Generate code to allocate the memory needed by reactions for triggering - * downstream reactions. - * @param reactions A list of reactions. - */ - private static String deferredReactionMemory( - Iterable reactions, - TargetConfig targetConfig - ) { - var code = new CodeBuilder(); - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : reactions) { - code.pr(deferredReactionOutputs( - reaction, - targetConfig - )); - var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (PortInstance trigger : Iterables.filter(reaction.triggers, PortInstance.class)) { - // If the port is a multiport, then we need to create an entry for each - // individual port. - if (trigger.isMultiport() && trigger.getParent() != null && trigger.isOutput()) { - // Trigger is an output of a contained reactor or bank. - code.pr(String.join("\n", - "// Allocate memory to store pointers to the multiport output "+trigger.getName()+" ", - "// of a contained reactor "+trigger.getParent().getFullName() - )); - code.startScopedBlock(trigger.getParent()); - - var width = trigger.getWidth(); - var portStructType = CGenerator.variableStructType(trigger); - - code.pr(String.join("\n", - CUtil.reactorRefNested(trigger.getParent())+"."+trigger.getName()+"_width = "+width+";", - CUtil.reactorRefNested(trigger.getParent())+"."+trigger.getName(), - " = ("+portStructType+"**)_lf_allocate(", - " "+width+", sizeof("+portStructType+"*),", - " &"+reactorSelfStruct+"->base.allocations); " - )); - - code.endScopedBlock(); - } + return code.toString(); + } + + /** + * For each input port of a contained reactor that receives data from one or more of the specified + * reactions, set the num_destinations field of the corresponding port structs on the self struct + * of the reaction's parent reactor equal to the total number of destination reactors. If the port + * has a token type, this also initializes it with a token. + * + * @param reactions The reactions. + * @param types The C types. + */ + private static String deferredInputNumDestinations( + Iterable reactions, CTypes types) { + // We need the number of destination _reactors_, not the + // number of destination ports nor the number of destination reactions. + // One of the destination reactors may be the container of this + // instance because it may have a reaction to an output of this instance. + // Since a port may be written to by multiple reactions, + // ensure that this is done only once. + var portsHandled = new HashSet(); + var code = new CodeBuilder(); + for (ReactionInstance reaction : reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.isInput() && !portsHandled.contains(port)) { + // Port is an input of a contained reactor that gets data from a reaction of this reactor. + portsHandled.add(port); + code.pr( + "// Set number of destination reactors for port " + + port.getParent().getName() + + "." + + port.getName() + + "."); + // The input port may itself have multiple destinations. + for (SendRange sendingRange : port.eventualDestinations()) { + code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); + // Syntax is slightly different for a multiport output vs. single port. + var connector = (port.isMultiport()) ? "->" : "."; + code.pr( + CUtil.portRefNested(port, sr, sb, sc) + + connector + + "_base.num_destinations = " + + sendingRange.getNumberOfDestinationReactors() + + ";"); + code.pr( + CUtil.portRefNested(port, sr, sb, sc) + + connector + + "_base.source_reactor = (self_base_t*)" + + CUtil.reactorRef(reaction.getParent(), sb) + + ";"); + + // Initialize token types. + var type = ASTUtils.getInferredType(port.getDefinition()); + if (CUtil.isTokenType(type, types)) { + // Create the template token that goes in the port struct. + var rootType = CUtil.rootType(types.getTargetType(type)); + // If the rootType is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; + // If the port is a multiport, then the portRefNested is itself a pointer + // so we want its value, not its address. + var indirection = (port.isMultiport()) ? "" : "&"; + code.startChannelIteration(port); + code.pr( + String.join( + "\n", + "_lf_initialize_template((token_template_t*)", + " " + indirection + "(" + CUtil.portRefNested(port, sr, sb, sc) + "),", + size + ");")); + code.endChannelIteration(port); } + + code.endScopedRangeBlock(sendingRange); + } } - return code.toString(); + } + } + return code.toString(); + } + + /** + * For each output port of the specified reactor, set the num_destinations field of port structs + * on its self struct equal to the total number of destination reactors. This is used to + * initialize reference counts in dynamically allocated tokens sent to other reactors. + * + * @param reactor The reactor instance. + */ + private static String deferredOutputNumDestinations(ReactorInstance reactor) { + // Reference counts are decremented by each destination reactor + // at the conclusion of a time step. Hence, the initial reference + // count should equal the number of destination _reactors_, not the + // number of destination ports nor the number of destination reactions. + // One of the destination reactors may be the container of this + // instance because it may have a reaction to an output of this instance. + var code = new CodeBuilder(); + for (PortInstance output : reactor.outputs) { + for (SendRange sendingRange : output.eventualDestinations()) { + code.pr( + "// For reference counting, set num_destinations for port " + + output.getFullName() + + "."); + code.startScopedRangeBlock(sendingRange, sr, sb, sc, sendingRange.instance.isInput()); + code.pr( + CUtil.portRef(output, sr, sb, sc) + + "._base.num_destinations = " + + sendingRange.getNumberOfDestinationReactors() + + ";"); + code.pr( + CUtil.portRef(output, sr, sb, sc) + + "._base.source_reactor = (self_base_t*)" + + CUtil.reactorRef(reactor, sb) + + ";"); + code.endScopedRangeBlock(sendingRange); + } + } + return code.toString(); + } + + /** + * Perform initialization functions that must be performed after all reactor runtime instances + * have been created. This function does not create nested loops over nested banks, so each + * function it calls must handle its own iteration over all runtime instance. + * + * @param reactor The container. + * @param main The top-level reactor. + * @param reactions The list of reactions to consider. + * @param types The C types. + */ + private static String deferredInitializeNonNested( + ReactorInstance reactor, + ReactorInstance main, + Iterable reactions, + CTypes types) { + var code = new CodeBuilder(); + code.pr("// **** Start non-nested deferred initialize for " + reactor.getFullName()); + // Initialize the num_destinations fields of port structs on the self struct. + // This needs to be outside the above scoped block because it performs + // its own iteration over ranges. + code.pr(deferredInputNumDestinations(reactions, types)); + + // Second batch of initializes cannot be within a for loop + // iterating over bank members because they iterate over send + // ranges which may span bank members. + if (reactor != main) { + code.pr(deferredOutputNumDestinations(reactor)); + } + code.pr(deferredFillTriggerTable(reactions)); + code.pr(deferredOptimizeForSingleDominatingReaction(reactor)); + for (ReactorInstance child : reactor.children) { + code.pr(deferredInitializeNonNested(child, main, child.reactions, types)); + } + code.pr("// **** End of non-nested deferred initialize for " + reactor.getFullName()); + return code.toString(); + } + + /** + * For each output of the specified reactor that has a token type (type* or type[]), create a + * template token and put it on the self struct. + * + * @param reactor The reactor. + */ + private static String deferredCreateTemplateTokens(ReactorInstance reactor, CTypes types) { + var code = new CodeBuilder(); + // Look for outputs with token types. + for (PortInstance output : reactor.outputs) { + var type = ASTUtils.getInferredType(output.getDefinition()); + if (CUtil.isTokenType(type, types)) { + // Create the template token that goes in the trigger struct. + // Its reference count is zero, enabling it to be used immediately. + var rootType = CUtil.rootType(types.getTargetType(type)); + // If the rootType is 'void', we need to avoid generating the code + // 'sizeof(void)', which some compilers reject. + var size = (rootType.equals("void")) ? "0" : "sizeof(" + rootType + ")"; + code.startChannelIteration(output); + code.pr( + String.join( + "\n", + "_lf_initialize_template((token_template_t*)", + " &(" + CUtil.portRef(output) + "),", + size + ");")); + code.endChannelIteration(output); + } + } + return code.toString(); + } + + /** + * For the specified reaction, for ports that it writes to, set up the arrays that store the + * results (if necessary) and that are used to trigger downstream reactions if an effect is + * actually produced. The port may be an output of the reaction's parent or an input to a reactor + * contained by the parent. + * + * @param reaction The reaction instance. + */ + private static String deferredReactionOutputs( + ReactionInstance reaction, TargetConfig targetConfig) { + var code = new CodeBuilder(); + // val selfRef = CUtil.reactorRef(reaction.getParent()); + var name = reaction.getParent().getFullName(); + // Insert a string name to facilitate debugging. + if (targetConfig.logLevel.compareTo(LogLevel.LOG) >= 0) { + code.pr( + CUtil.reactionRef(reaction) + + ".name = " + + addDoubleQuotes(name + " reaction " + reaction.index) + + ";"); } - /** - * If any reaction of the specified reactor provides input - * to a contained reactor, then generate code to allocate - * memory to store the data produced by those reactions. - * The allocated memory is pointed to by a field called - * `_lf_containername.portname` on the self struct of the reactor. - * @param reactor The reactor. - */ - private static String deferredAllocationForEffectsOnInputs( - ReactorInstance reactor - ) { - var code = new CodeBuilder(); - // Keep track of ports already handled. There may be more than one reaction - // in the container writing to the port, but we want only one memory allocation. - var portsHandled = new HashSet(); - var reactorSelfStruct = CUtil.reactorRef(reactor); - // Find parent reactions that mention multiport inputs of this reactor. - for (ReactionInstance reaction : reactor.reactions) { - for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { - if (effect.getParent().getDepth() > reactor.getDepth() // port of a contained reactor. - && effect.isMultiport() - && !portsHandled.contains(effect) - ) { - code.pr("// A reaction writes to a multiport of a child. Allocate memory."); - portsHandled.add(effect); - code.startScopedBlock(effect.getParent()); - var portStructType = CGenerator.variableStructType(effect); - var effectRef = CUtil.portRefNestedName(effect); - code.pr(String.join("\n", - effectRef+"_width = "+effect.getWidth()+";", - "// Allocate memory to store output of reaction feeding ", - "// a multiport input of a contained reactor.", - effectRef+" = ("+portStructType+"**)_lf_allocate(", - " "+effect.getWidth()+", sizeof("+portStructType+"*),", - " &"+reactorSelfStruct+"->base.allocations); ", - "for (int i = 0; i < "+effect.getWidth()+"; i++) {", - " "+effectRef+"[i] = ("+portStructType+"*)_lf_allocate(", - " 1, sizeof("+portStructType+"),", - " &"+reactorSelfStruct+"->base.allocations); ", - "}" - )); - code.endScopedBlock(); - } - } - } - return code.toString(); + var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); + + // Count the output ports and inputs of contained reactors that + // may be set by this reaction. This ignores actions in the effects. + // Collect initialization statements for the output_produced array for the reaction + // to point to the is_present field of the appropriate output. + // These statements must be inserted after the array is malloc'd, + // but we construct them while we are counting outputs. + var outputCount = 0; + var init = new CodeBuilder(); + + init.startScopedBlock(); + init.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { + // Create the entry in the output_produced array for this port. + // If the port is a multiport, then we need to create an entry for each + // individual channel. + + // If the port is an input of a contained reactor, then, if that + // contained reactor is a bank, we will have to iterate over bank + // members. + var bankWidth = 1; + var portRef = ""; + if (effect.isInput()) { + init.pr("// Reaction writes to an input of a contained reactor."); + bankWidth = effect.getParent().getWidth(); + init.startScopedBlock(effect.getParent()); + portRef = CUtil.portRefNestedName(effect); + } else { + init.startScopedBlock(); + portRef = CUtil.portRefName(effect); + } + + if (effect.isMultiport()) { + // Form is slightly different for inputs vs. outputs. + var connector = "."; + if (effect.isInput()) connector = "->"; + + // Point the output_produced field to where the is_present field of the port is. + init.pr( + String.join( + "\n", + "for (int i = 0; i < " + effect.getWidth() + "; i++) {", + " " + CUtil.reactionRef(reaction) + ".output_produced[i + count]", + " = &" + portRef + "[i]" + connector + "is_present;", + "}", + "count += " + effect.getWidth() + ";")); + outputCount += effect.getWidth() * bankWidth; + } else { + // The effect is not a multiport. + init.pr( + CUtil.reactionRef(reaction) + + ".output_produced[count++] = &" + + portRef + + ".is_present;"); + outputCount += bankWidth; + } + init.endScopedBlock(); + } + init.endScopedBlock(); + code.pr( + String.join( + "\n", + "// Total number of outputs (single ports and multiport channels)", + "// produced by " + reaction + ".", + CUtil.reactionRef(reaction) + ".num_outputs = " + outputCount + ";")); + if (outputCount > 0) { + code.pr( + String.join( + "\n", + "// Allocate memory for triggers[] and triggered_sizes[] on the reaction_t", + "// struct for this reaction.", + CUtil.reactionRef(reaction) + ".triggers = (trigger_t***)_lf_allocate(", + " " + outputCount + ", sizeof(trigger_t**),", + " &" + reactorSelfStruct + "->base.allocations);", + CUtil.reactionRef(reaction) + ".triggered_sizes = (int*)_lf_allocate(", + " " + outputCount + ", sizeof(int),", + " &" + reactorSelfStruct + "->base.allocations);", + CUtil.reactionRef(reaction) + ".output_produced = (bool**)_lf_allocate(", + " " + outputCount + ", sizeof(bool*),", + " &" + reactorSelfStruct + "->base.allocations);")); } - /** - * Perform initialization functions that must be performed after - * all reactor runtime instances have been created. - * This function creates nested loops over nested banks. - * @param reactor The container. - */ - private static String deferredInitialize( - ReactorInstance reactor, - Iterable reactions, - TargetConfig targetConfig, - CTypes types - ) { - var code = new CodeBuilder(); - code.pr("// **** Start deferred initialize for "+reactor.getFullName()); - // First batch of initializations is within a for loop iterating - // over bank members for the reactor's parent. - code.startScopedBlock(reactor); - - // If the child has a multiport that is an effect of some reaction in its container, - // then we have to generate code to allocate memory for arrays pointing to - // its data. If the child is a bank, then memory is allocated for the entire - // bank width because a reaction cannot specify which bank members it writes - // to so we have to assume it can write to any. - code.pr(deferredAllocationForEffectsOnInputs( - reactor - )); - code.pr(deferredReactionMemory( - reactions, - targetConfig - )); - - // For outputs that are not primitive types (of form type* or type[]), - // create a default token on the self struct. - code.pr(deferredCreateTemplateTokens( - reactor, - types - )); - for (ReactorInstance child: reactor.children) { - code.pr(deferredInitialize( - child, - child.reactions, - targetConfig, - types) - ); + code.pr( + String.join( + "\n", + init.toString(), + "// ** End initialization for reaction " + reaction.index + " of " + name)); + return code.toString(); + } + + /** + * Generate code to allocate the memory needed by reactions for triggering downstream reactions. + * + * @param reactions A list of reactions. + */ + private static String deferredReactionMemory( + Iterable reactions, TargetConfig targetConfig) { + var code = new CodeBuilder(); + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : reactions) { + code.pr(deferredReactionOutputs(reaction, targetConfig)); + var reactorSelfStruct = CUtil.reactorRef(reaction.getParent()); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (PortInstance trigger : Iterables.filter(reaction.triggers, PortInstance.class)) { + // If the port is a multiport, then we need to create an entry for each + // individual port. + if (trigger.isMultiport() && trigger.getParent() != null && trigger.isOutput()) { + // Trigger is an output of a contained reactor or bank. + code.pr( + String.join( + "\n", + "// Allocate memory to store pointers to the multiport output " + + trigger.getName() + + " ", + "// of a contained reactor " + trigger.getParent().getFullName())); + code.startScopedBlock(trigger.getParent()); + + var width = trigger.getWidth(); + var portStructType = CGenerator.variableStructType(trigger); + + code.pr( + String.join( + "\n", + CUtil.reactorRefNested(trigger.getParent()) + + "." + + trigger.getName() + + "_width = " + + width + + ";", + CUtil.reactorRefNested(trigger.getParent()) + "." + trigger.getName(), + " = (" + portStructType + "**)_lf_allocate(", + " " + width + ", sizeof(" + portStructType + "*),", + " &" + reactorSelfStruct + "->base.allocations); ")); + + code.endScopedBlock(); } - code.endScopedBlock(); - code.pr("// **** End of deferred initialize for "+reactor.getFullName()); - return code.toString(); + } + } + return code.toString(); + } + + /** + * If any reaction of the specified reactor provides input to a contained reactor, then generate + * code to allocate memory to store the data produced by those reactions. The allocated memory is + * pointed to by a field called `_lf_containername.portname` on the self struct of the reactor. + * + * @param reactor The reactor. + */ + private static String deferredAllocationForEffectsOnInputs(ReactorInstance reactor) { + var code = new CodeBuilder(); + // Keep track of ports already handled. There may be more than one reaction + // in the container writing to the port, but we want only one memory allocation. + var portsHandled = new HashSet(); + var reactorSelfStruct = CUtil.reactorRef(reactor); + // Find parent reactions that mention multiport inputs of this reactor. + for (ReactionInstance reaction : reactor.reactions) { + for (PortInstance effect : Iterables.filter(reaction.effects, PortInstance.class)) { + if (effect.getParent().getDepth() > reactor.getDepth() // port of a contained reactor. + && effect.isMultiport() + && !portsHandled.contains(effect)) { + code.pr("// A reaction writes to a multiport of a child. Allocate memory."); + portsHandled.add(effect); + code.startScopedBlock(effect.getParent()); + var portStructType = CGenerator.variableStructType(effect); + var effectRef = CUtil.portRefNestedName(effect); + code.pr( + String.join( + "\n", + effectRef + "_width = " + effect.getWidth() + ";", + "// Allocate memory to store output of reaction feeding ", + "// a multiport input of a contained reactor.", + effectRef + " = (" + portStructType + "**)_lf_allocate(", + " " + effect.getWidth() + ", sizeof(" + portStructType + "*),", + " &" + reactorSelfStruct + "->base.allocations); ", + "for (int i = 0; i < " + effect.getWidth() + "; i++) {", + " " + effectRef + "[i] = (" + portStructType + "*)_lf_allocate(", + " 1, sizeof(" + portStructType + "),", + " &" + reactorSelfStruct + "->base.allocations); ", + "}")); + code.endScopedBlock(); + } + } + } + return code.toString(); + } + + /** + * Perform initialization functions that must be performed after all reactor runtime instances + * have been created. This function creates nested loops over nested banks. + * + * @param reactor The container. + */ + private static String deferredInitialize( + ReactorInstance reactor, + Iterable reactions, + TargetConfig targetConfig, + CTypes types) { + var code = new CodeBuilder(); + code.pr("// **** Start deferred initialize for " + reactor.getFullName()); + // First batch of initializations is within a for loop iterating + // over bank members for the reactor's parent. + code.startScopedBlock(reactor); + + // If the child has a multiport that is an effect of some reaction in its container, + // then we have to generate code to allocate memory for arrays pointing to + // its data. If the child is a bank, then memory is allocated for the entire + // bank width because a reaction cannot specify which bank members it writes + // to so we have to assume it can write to any. + code.pr(deferredAllocationForEffectsOnInputs(reactor)); + code.pr(deferredReactionMemory(reactions, targetConfig)); + + // For outputs that are not primitive types (of form type* or type[]), + // create a default token on the self struct. + code.pr(deferredCreateTemplateTokens(reactor, types)); + for (ReactorInstance child : reactor.children) { + code.pr(deferredInitialize(child, child.reactions, targetConfig, types)); } + code.endScopedBlock(); + code.pr("// **** End of deferred initialize for " + reactor.getFullName()); + return code.toString(); + } } From 7fd300344d590b84b5961effb90f17de132c9313 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 23:03:18 -0700 Subject: [PATCH 413/709] Change default line length to 100 for LF files. --- test/C/src/ActionWithNoReaction.lf | 5 ++-- test/C/src/After.lf | 3 +- test/C/src/AfterCycles.lf | 4 +-- test/C/src/AfterZero.lf | 3 +- test/C/src/Alignment.lf | 3 +- test/C/src/ArrayAsParameter.lf | 5 ++-- test/C/src/ArrayAsType.lf | 4 +-- test/C/src/Composition.lf | 3 +- test/C/src/CompositionAfter.lf | 3 +- test/C/src/CompositionInheritance.lf | 3 +- test/C/src/DanglingOutput.lf | 4 +-- test/C/src/Deadline.lf | 5 ++-- test/C/src/DeadlineHandledAbove.lf | 4 +-- test/C/src/DelayArrayWithAfter.lf | 3 +- test/C/src/DelayInt.lf | 4 +-- test/C/src/DelayString.lf | 3 +- test/C/src/DoubleInvocation.lf | 9 +++--- test/C/src/DoublePort.lf | 9 ++---- test/C/src/DoubleReaction.lf | 4 +-- test/C/src/DoubleTrigger.lf | 3 +- test/C/src/FloatLiteral.lf | 3 +- test/C/src/GetTime.lf | 4 +-- test/C/src/Import.lf | 3 +- test/C/src/ImportComposition.lf | 3 +- test/C/src/ImportRenamed.lf | 3 +- test/C/src/InheritanceAction.lf | 3 +- test/C/src/MovingAverage.lf | 5 ++-- test/C/src/MultipleContained.lf | 3 +- test/C/src/MultipleOutputs.lf | 7 ++--- test/C/src/PingPong.lf | 17 +++++------ test/C/src/ReadOutputOfContainedReactor.lf | 3 +- test/C/src/RepeatedInheritance.lf | 8 ++--- test/C/src/RequestStop.lf | 3 +- test/C/src/ScheduleLogicalAction.lf | 4 +-- test/C/src/SendingInside.lf | 4 +-- test/C/src/SendsPointerTest.lf | 4 +-- test/C/src/SetArray.lf | 4 +-- test/C/src/SimpleDeadline.lf | 5 ++-- test/C/src/SlowingClock.lf | 7 ++--- test/C/src/SlowingClockPhysical.lf | 9 +++--- test/C/src/Starvation.lf | 4 +-- test/C/src/StopZero.lf | 4 +-- test/C/src/Stride.lf | 4 +-- test/C/src/StructPrint.lf | 4 +-- test/C/src/TestForPreviousOutput.lf | 4 +-- test/C/src/TimeLimit.lf | 5 ++-- test/C/src/TimeoutZero.lf | 3 +- test/C/src/TriggerDownstreamOnlyIfPresent2.lf | 5 +--- test/C/src/arduino/AnalogReadSerial.lf | 7 ++--- test/C/src/arduino/Blink.lf | 5 ++-- test/C/src/arduino/BlinkAttemptThreading.lf | 7 ++--- test/C/src/arduino/BlinkMBED.lf | 5 ++-- test/C/src/arduino/Fade.lf | 9 +++--- test/C/src/arduino/ReadAnalogVoltage.lf | 9 +++--- test/C/src/concurrent/AsyncCallback.lf | 10 +++---- test/C/src/concurrent/AsyncCallbackDrop.lf | 7 ++--- test/C/src/concurrent/AsyncCallbackReplace.lf | 7 ++--- test/C/src/concurrent/CompositionThreaded.lf | 3 +- .../DeadlineHandledAboveThreaded.lf | 4 +-- test/C/src/concurrent/DeadlineThreaded.lf | 5 ++-- .../src/concurrent/DoubleReactionThreaded.lf | 4 +-- test/C/src/concurrent/ImportThreaded.lf | 3 +- test/C/src/concurrent/PingPongThreaded.lf | 20 +++++-------- .../C/src/concurrent/SendingInsideThreaded.lf | 4 +-- test/C/src/concurrent/StarvationThreaded.lf | 5 ++-- test/C/src/concurrent/StopThreaded.lf | 4 +-- test/C/src/concurrent/StopZeroThreaded.lf | 3 +- test/C/src/concurrent/Threaded.lf | 19 +++++------- test/C/src/concurrent/ThreadedMultiport.lf | 3 +- test/C/src/concurrent/ThreadedThreaded.lf | 16 +++++----- test/C/src/concurrent/TimeLimitThreaded.lf | 4 +-- test/C/src/concurrent/TimeoutThreaded.lf | 3 +- test/C/src/concurrent/TimeoutZeroThreaded.lf | 4 +-- test/C/src/concurrent/Tracing.lf | 3 +- test/C/src/docker/PingPongContainerized.lf | 17 +++++------ .../DistributedCountContainerized.lf | 7 ++--- .../DistributedDoublePortContainerized.lf | 5 ++-- ...stributedStopDecentralizedContainerized.lf | 3 +- test/C/src/federated/BroadcastFeedback.lf | 4 +-- .../BroadcastFeedbackWithHierarchy.lf | 4 +-- test/C/src/federated/CycleDetection.lf | 4 +-- .../DecentralizedP2PUnbalancedTimeout.lf | 11 +++---- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 15 ++++------ test/C/src/federated/DistributedCount.lf | 7 ++--- .../DistributedCountDecentralized.lf | 10 +++---- .../src/federated/DistributedCountPhysical.lf | 8 ++--- .../DistributedCountPhysicalAfterDelay.lf | 9 +++--- .../DistributedCountPhysicalDecentralized.lf | 8 ++--- test/C/src/federated/DistributedDoublePort.lf | 9 ++---- .../DistributedLogicalActionUpstreamLong.lf | 4 +-- .../src/federated/DistributedLoopedAction.lf | 6 ++-- .../DistributedLoopedActionDecentralized.lf | 23 ++++++--------- .../DistributedLoopedPhysicalAction.lf | 16 +++++----- ...ibutedLoopedPhysicalActionDecentralized.lf | 3 +- .../federated/DistributedMultiportToken.lf | 4 +-- .../src/federated/DistributedNetworkOrder.lf | 7 ++--- .../DistributedPhysicalActionUpstream.lf | 4 +-- .../DistributedPhysicalActionUpstreamLong.lf | 4 +-- test/C/src/federated/DistributedStop.lf | 3 +- .../federated/DistributedStopDecentralized.lf | 3 +- test/C/src/federated/DistributedStopZero.lf | 3 +- .../DistributedStopZeroDecentralized.lf | 3 +- test/C/src/federated/HelloDistributed.lf | 11 +++---- .../federated/LoopDistributedCentralized.lf | 3 +- .../LoopDistributedCentralizedPrecedence.lf | 4 +-- ...stributedCentralizedPrecedenceHierarchy.lf | 5 ++-- .../federated/LoopDistributedDecentralized.lf | 3 +- test/C/src/federated/LoopDistributedDouble.lf | 3 +- test/C/src/federated/PhysicalSTP.lf | 5 +--- test/C/src/federated/PingPongDistributed.lf | 17 +++++------ .../federated/PingPongDistributedPhysical.lf | 18 +++++------- test/C/src/federated/TopLevelArtifacts.lf | 7 ++--- test/C/src/federated/failing/ClockSync.lf | 29 ++++++++----------- test/C/src/lib/Imported.lf | 4 +-- test/C/src/lib/ImportedAgain.lf | 4 +-- test/C/src/lib/ImportedComposition.lf | 4 +-- test/C/src/lib/LoopedActionSender.lf | 7 ++--- test/C/src/lib/TestCount.lf | 5 ++-- .../src/modal_models/BanksModalStateReset.lf | 8 ++--- test/C/src/modal_models/Count3Modes.lf | 6 ++-- test/C/src/modal_models/MixedReactions.lf | 4 +-- .../src/modal_models/ModalNestedReactions.lf | 11 ++----- test/C/src/multiport/BankMulticast.lf | 4 +-- .../src/multiport/BankReactionsInContainer.lf | 4 +-- test/C/src/multiport/BankSelfBroadcast.lf | 6 ++-- test/C/src/multiport/MultiportFromBank.lf | 8 ++--- .../multiport/MultiportFromBankHierarchy.lf | 4 +-- .../MultiportFromBankHierarchyAfter.lf | 4 +-- .../C/src/multiport/MultiportFromHierarchy.lf | 3 +- test/C/src/multiport/MultiportIn.lf | 4 +-- .../src/multiport/MultiportInParameterized.lf | 7 ++--- test/C/src/multiport/MultiportMutableInput.lf | 5 ++-- .../multiport/MultiportMutableInputArray.lf | 7 ++--- test/C/src/multiport/MultiportToBank.lf | 7 ++--- test/C/src/multiport/MultiportToBankAfter.lf | 3 +- test/C/src/multiport/MultiportToBankDouble.lf | 8 ++--- .../src/multiport/MultiportToBankHierarchy.lf | 4 +-- test/C/src/multiport/MultiportToHierarchy.lf | 5 ++-- .../multiport/MultiportToMultiportArray.lf | 3 +- test/C/src/multiport/MultiportToPort.lf | 3 +- .../ReactionToContainedBankMultiport.lf | 3 +- test/C/src/multiport/ReactionsToNested.lf | 3 +- test/C/src/multiport/SparseFallback.lf | 4 +-- .../TriggerDownstreamOnlyIfPresent.lf | 5 +--- .../serialization/PersonProtocolBuffers.lf | 18 +++++------- test/C/src/serialization/ProtoNoPacking.lf | 18 +++++------- .../ROSBuiltInSerializationSharedPtr.lf | 13 ++++----- test/C/src/target/CMakeInclude.lf | 3 +- test/C/src/target/DistributedCMakeInclude.lf | 5 ++-- .../DistributedCMakeIncludeSeparateCompile.lf | 6 ++-- test/C/src/target/HelloWorldCCPP.lf | 4 +-- test/C/src/target/HelloWorldFederatedCCPP.lf | 4 +-- test/C/src/target/HelloWorldThreadedCPP.lf | 4 +-- test/Cpp/src/ActionWithNoReaction.lf | 5 ++-- test/Cpp/src/After.lf | 3 +- test/Cpp/src/AfterZero.lf | 3 +- test/Cpp/src/Alignment.lf | 3 +- test/Cpp/src/ArrayAsParameter.lf | 3 +- test/Cpp/src/ArrayAsType.lf | 4 +-- test/Cpp/src/ArrayParallel.lf | 6 ++-- test/Cpp/src/ArrayPrint.lf | 5 ++-- test/Cpp/src/ArrayScale.lf | 5 ++-- test/Cpp/src/Composition.lf | 3 +- test/Cpp/src/CompositionAfter.lf | 3 +- test/Cpp/src/DanglingOutput.lf | 4 +-- test/Cpp/src/Deadline.lf | 5 ++-- test/Cpp/src/DeadlineHandledAbove.lf | 4 +-- test/Cpp/src/DoubleInvocation.lf | 12 ++++---- test/Cpp/src/DoublePort.lf | 5 ++-- test/Cpp/src/DoubleReaction.lf | 4 +-- test/Cpp/src/DoubleTrigger.lf | 3 +- test/Cpp/src/GetTime.lf | 4 +-- test/Cpp/src/Import.lf | 3 +- test/Cpp/src/ImportComposition.lf | 3 +- test/Cpp/src/ImportRenamed.lf | 3 +- test/Cpp/src/ManualDelayedReaction.lf | 6 ++-- test/Cpp/src/MovingAverage.lf | 6 ++-- test/Cpp/src/MultipleContained.lf | 3 +- test/Cpp/src/PreambleTest.lf | 14 ++++----- test/Cpp/src/ReadOutputOfContainedReactor.lf | 3 +- test/Cpp/src/ScheduleLogicalAction.lf | 4 +-- test/Cpp/src/SendingInside.lf | 4 +-- test/Cpp/src/SimpleDeadline.lf | 5 ++-- test/Cpp/src/SlowingClock.lf | 7 ++--- test/Cpp/src/SlowingClockPhysical.lf | 9 +++--- test/Cpp/src/Stride.lf | 4 +-- test/Cpp/src/StructParallel.lf | 6 ++-- test/Cpp/src/StructScale.lf | 5 ++-- test/Cpp/src/TestForPreviousOutput.lf | 4 +-- test/Cpp/src/TimeLimit.lf | 5 ++-- .../src/TriggerDownstreamOnlyIfPresent2.lf | 3 +- .../Cpp/src/concurrent/CompositionThreaded.lf | 3 +- .../DeadlineHandledAboveThreaded.lf | 4 +-- test/Cpp/src/concurrent/DeadlineThreaded.lf | 5 ++-- .../src/concurrent/DoubleReactionThreaded.lf | 4 +-- test/Cpp/src/concurrent/ImportThreaded.lf | 3 +- .../src/concurrent/SendingInsideThreaded.lf | 4 +-- test/Cpp/src/concurrent/Threaded.lf | 14 ++++----- test/Cpp/src/concurrent/ThreadedThreaded.lf | 14 ++++----- test/Cpp/src/concurrent/TimeLimitThreaded.lf | 7 ++--- test/Cpp/src/lib/Imported.lf | 4 +-- test/Cpp/src/lib/ImportedAgain.lf | 4 +-- test/Cpp/src/lib/ImportedComposition.lf | 4 +-- test/Cpp/src/lib/LoopedActionSender.lf | 7 ++--- test/Cpp/src/multiport/BankSelfBroadcast.lf | 6 ++-- .../src/multiport/IndexIntoMultiportInput.lf | 5 ++-- .../src/multiport/IndexIntoMultiportOutput.lf | 5 ++-- test/Cpp/src/multiport/MultiportFromBank.lf | 4 +-- .../multiport/MultiportFromBankHierarchy.lf | 4 +-- .../MultiportFromBankHierarchyAfter.lf | 4 +-- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/Cpp/src/multiport/MultiportIn.lf | 4 +-- .../src/multiport/MultiportToBankHierarchy.lf | 4 +-- .../Cpp/src/multiport/MultiportToHierarchy.lf | 5 ++-- .../multiport/MultiportToMultiportArray.lf | 3 +- test/Cpp/src/multiport/MultiportToPort.lf | 3 +- .../ReadMultiportOutputOfContainedBank.lf | 3 +- .../multiport/ReadOutputOfContainedBank.lf | 3 +- .../src/target/BraceAndParenInitialization.lf | 6 ++-- test/Cpp/src/target/CMakeInclude.lf | 3 +- test/Cpp/src/target/PreambleFile.lf | 14 ++++----- test/Python/src/ActionWithNoReaction.lf | 5 ++-- test/Python/src/After.lf | 3 +- test/Python/src/AfterCycles.lf | 4 +-- test/Python/src/ArrayAsType.lf | 4 +-- test/Python/src/ArrayFree.lf | 8 ++--- test/Python/src/ArrayParallel.lf | 6 ++-- test/Python/src/ArrayPrint.lf | 4 +-- test/Python/src/ArrayScale.lf | 7 ++--- test/Python/src/Composition.lf | 3 +- test/Python/src/CompositionAfter.lf | 3 +- test/Python/src/CompositionInheritance.lf | 3 +- test/Python/src/DanglingOutput.lf | 4 +-- test/Python/src/Deadline.lf | 5 ++-- test/Python/src/DeadlineHandledAbove.lf | 4 +-- test/Python/src/DelayArrayWithAfter.lf | 3 +- test/Python/src/DelayString.lf | 3 +- test/Python/src/DoubleInvocation.lf | 9 +++--- test/Python/src/DoubleReaction.lf | 4 +-- test/Python/src/GetTime.lf | 4 +-- test/Python/src/Hello.lf | 14 ++++----- test/Python/src/Import.lf | 3 +- test/Python/src/ImportComposition.lf | 3 +- test/Python/src/ImportRenamed.lf | 3 +- test/Python/src/ManualDelayedReaction.lf | 9 +++--- test/Python/src/MovingAverage.lf | 5 ++-- test/Python/src/MultipleContained.lf | 3 +- test/Python/src/PingPong.lf | 17 +++++------ test/Python/src/Preamble.lf | 4 +-- .../src/ReadOutputOfContainedReactor.lf | 3 +- test/Python/src/ScheduleLogicalAction.lf | 4 +-- test/Python/src/SendingInside.lf | 4 +-- test/Python/src/SetArray.lf | 5 ++-- test/Python/src/SimpleDeadline.lf | 5 ++-- test/Python/src/SlowingClock.lf | 6 ++-- test/Python/src/Stride.lf | 4 +-- test/Python/src/StructAsState.lf | 3 +- test/Python/src/StructPrint.lf | 4 +-- test/Python/src/TestForPreviousOutput.lf | 4 +-- test/Python/src/TimeLimit.lf | 5 ++-- .../src/TriggerDownstreamOnlyIfPresent.lf | 5 +--- .../src/TriggerDownstreamOnlyIfPresent2.lf | 5 +--- test/Python/src/concurrent/AsyncCallback.lf | 5 ++-- .../src/concurrent/AsyncCallbackNoTimer.lf | 12 ++++---- .../src/docker/PingPongContainerized.lf | 17 +++++------ .../DistributedCountContainerized.lf | 7 ++--- .../DistributedDoublePortContainerized.lf | 5 ++-- .../Python/src/federated/BroadcastFeedback.lf | 4 +-- .../BroadcastFeedbackWithHierarchy.lf | 4 +-- test/Python/src/federated/CycleDetection.lf | 4 +-- .../DecentralizedP2PUnbalancedTimeout.lf | 7 ++--- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 11 ++++--- test/Python/src/federated/DistributedCount.lf | 7 ++--- .../DistributedCountDecentralized.lf | 10 +++---- .../src/federated/DistributedCountPhysical.lf | 8 ++--- .../DistributedCountPhysicalAfterDelay.lf | 8 ++--- .../DistributedCountPhysicalDecentralized.lf | 8 ++--- .../src/federated/DistributedDoublePort.lf | 9 ++---- .../src/federated/DistributedLoopedAction.lf | 6 ++-- ...ibutedLoopedPhysicalActionDecentralized.lf | 3 +- .../federated/DistributedMultiportToken.lf | 4 +-- .../federated/DistributedStructParallel.lf | 4 +-- .../src/federated/DistributedStructPrint.lf | 4 +-- .../src/federated/DistributedStructScale.lf | 4 +-- test/Python/src/federated/HelloDistributed.lf | 10 +++---- ...stributedCentralizedPrecedenceHierarchy.lf | 5 ++-- test/Python/src/federated/PhysicalSTP.lf | 5 +--- .../src/federated/PingPongDistributed.lf | 16 +++++----- test/Python/src/lib/Imported.lf | 4 +-- test/Python/src/lib/ImportedAgain.lf | 4 +-- test/Python/src/lib/ImportedComposition.lf | 4 +-- test/Python/src/lib/LoopedActionSender.lf | 7 ++--- test/Python/src/lib/TestCount.lf | 5 ++-- test/Python/src/lib/TestCountMultiport.lf | 11 ++++--- .../src/modal_models/BanksModalStateReset.lf | 8 ++--- .../src/modal_models/ConvertCaseTest.lf | 4 +-- test/Python/src/modal_models/ModalActions.lf | 7 ++--- .../src/modal_models/ModalCycleBreaker.lf | 8 ++--- .../src/modal_models/ModalNestedReactions.lf | 5 +--- .../src/modal_models/ModalStartupShutdown.lf | 3 +- .../src/modal_models/ModalStateReset.lf | 3 +- .../src/modal_models/ModalStateResetAuto.lf | 3 +- test/Python/src/modal_models/ModalTimers.lf | 3 +- .../MultipleOutputFeeder_2Connections.lf | 10 +++---- ...ultipleOutputFeeder_ReactionConnections.lf | 14 ++++----- .../src/multiport/BankReactionsInContainer.lf | 4 +-- .../Python/src/multiport/MultiportFromBank.lf | 8 ++--- .../multiport/MultiportFromBankHierarchy.lf | 4 +-- .../MultiportFromBankHierarchyAfter.lf | 4 +-- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/Python/src/multiport/MultiportIn.lf | 4 +-- .../src/multiport/MultiportInParameterized.lf | 4 +-- .../src/multiport/MultiportMutableInput.lf | 5 ++-- .../multiport/MultiportMutableInputArray.lf | 7 ++--- .../src/multiport/MultiportToBankAfter.lf | 3 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +-- .../src/multiport/MultiportToHierarchy.lf | 5 ++-- .../multiport/MultiportToMultiportArray.lf | 3 +- test/Python/src/multiport/MultiportToPort.lf | 3 +- .../Python/src/multiport/ReactionsToNested.lf | 3 +- .../serialization/PersonProtocolBuffers.lf | 18 +++++------- .../src/serialization/ProtoNoPacking.lf | 18 +++++------- test/Python/src/target/AfterNoTypes.lf | 4 +-- test/Rust/src/ActionValuesCleanup.lf | 4 +-- .../src/CompositionInitializationOrder.lf | 3 +- test/Rust/src/DependencyOnChildPort.lf | 4 +-- test/Rust/src/DependencyUseAccessible.lf | 3 +- test/Rust/src/Import.lf | 3 +- test/Rust/src/ImportPreambleItem.lf | 7 ++--- ...ysicalActionCanBeScheduledSynchronously.lf | 3 +- .../src/PhysicalActionKeepaliveIsSmart.lf | 4 +-- .../PhysicalActionWakesSleepingScheduler.lf | 14 ++++----- test/Rust/src/ReactionLabels.lf | 4 +-- test/Rust/src/ReservedKeywords.lf | 3 +- test/Rust/src/StateInitializerVisibility.lf | 4 +-- test/Rust/src/Stop.lf | 7 ++--- test/Rust/src/StopNoEvent.lf | 5 +--- test/Rust/src/StopTimeout.lf | 3 +- test/Rust/src/StopTimeoutExact.lf | 4 +-- test/Rust/src/StructAsState.lf | 4 +-- test/Rust/src/generics/GenericReactor.lf | 4 +-- test/Rust/src/lib/Imported.lf | 4 +-- test/Rust/src/lib/ImportedAgain.lf | 4 +-- test/Rust/src/lib/SomethingWithAPreamble.lf | 4 +-- test/Rust/src/multiport/CycledLhs_SelfLoop.lf | 8 ++--- test/Rust/src/multiport/CycledLhs_Single.lf | 14 ++++----- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/Rust/src/multiport/MultiportIn.lf | 4 +-- .../src/multiport/MultiportToMultiport2.lf | 3 +- .../src/target/BuildProfileDefaultIsDev.lf | 4 +-- test/Rust/src/target/BuildProfileRelease.lf | 4 +-- test/Rust/src/target/CargoDependency.lf | 3 +- .../src/target/CargoDependencyOnRuntime.lf | 3 +- test/TypeScript/src/ActionWithNoReaction.lf | 5 ++-- test/TypeScript/src/After.lf | 3 +- test/TypeScript/src/ArrayAsType.lf | 5 ++-- test/TypeScript/src/ArrayPrint.lf | 5 ++-- test/TypeScript/src/ArrayScale.lf | 7 ++--- test/TypeScript/src/Composition.lf | 3 +- test/TypeScript/src/CompositionAfter.lf | 3 +- test/TypeScript/src/DanglingOutput.lf | 4 +-- test/TypeScript/src/Deadline.lf | 5 ++-- test/TypeScript/src/DeadlineHandledAbove.lf | 4 +-- test/TypeScript/src/DelayInt.lf | 4 +-- test/TypeScript/src/DoubleInvocation.lf | 9 +++--- test/TypeScript/src/DoubleReaction.lf | 4 +-- test/TypeScript/src/DoubleTrigger.lf | 3 +- test/TypeScript/src/GetTime.lf | 8 ++--- test/TypeScript/src/Import.lf | 3 +- test/TypeScript/src/MovingAverage.lf | 5 ++-- test/TypeScript/src/MultipleContained.lf | 3 +- .../src/ReadOutputOfContainedReactor.lf | 3 +- test/TypeScript/src/Schedule.lf | 3 +- test/TypeScript/src/ScheduleLogicalAction.lf | 4 +-- test/TypeScript/src/SendingInside.lf | 4 +-- test/TypeScript/src/SendsPointerTest.lf | 4 +-- test/TypeScript/src/SimpleDeadline.lf | 5 ++-- test/TypeScript/src/SlowingClockPhysical.lf | 14 ++++----- test/TypeScript/src/Stop.lf | 3 +- test/TypeScript/src/Stride.lf | 4 +-- test/TypeScript/src/StructPrint.lf | 4 +-- test/TypeScript/src/TestForPreviousOutput.lf | 4 +-- test/TypeScript/src/TimeLimit.lf | 7 ++--- .../src/federated/DistributedCount.lf | 7 ++--- .../src/federated/DistributedDoublePort.lf | 9 ++---- .../src/federated/DistributedLoopedAction.lf | 6 ++-- .../DistributedLoopedPhysicalAction.lf | 8 ++--- .../src/federated/DistributedStop.lf | 3 +- .../src/federated/DistributedStopZero.lf | 4 +-- .../src/federated/HelloDistributed.lf | 11 +++---- .../federated/LoopDistributedCentralized.lf | 3 +- .../src/federated/LoopDistributedDouble.lf | 3 +- .../src/federated/TopLevelArtifacts.lf | 7 ++--- test/TypeScript/src/lib/Imported.lf | 4 +-- test/TypeScript/src/lib/ImportedAgain.lf | 4 +-- test/TypeScript/src/lib/LoopedActionSender.lf | 7 ++--- test/TypeScript/src/lib/TestCount.lf | 5 ++-- .../TypeScript/src/multiport/BankMulticast.lf | 4 +-- .../src/multiport/BankReactionsInContainer.lf | 4 +-- .../src/multiport/BankSelfBroadcast.lf | 6 ++-- .../src/multiport/MultiportFromBank.lf | 4 +-- .../multiport/MultiportFromBankHierarchy.lf | 4 +-- .../MultiportFromBankHierarchyAfter.lf | 4 +-- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/TypeScript/src/multiport/MultiportIn.lf | 4 +-- .../src/multiport/MultiportInParameterized.lf | 4 +-- .../src/multiport/MultiportMutableInput.lf | 5 ++-- .../multiport/MultiportMutableInputArray.lf | 7 ++--- .../src/multiport/MultiportToBankAfter.lf | 3 +- .../src/multiport/MultiportToBankDouble.lf | 8 ++--- .../src/multiport/MultiportToBankHierarchy.lf | 4 +-- .../src/multiport/MultiportToHierarchy.lf | 5 ++-- .../multiport/MultiportToMultiportArray.lf | 3 +- .../src/multiport/MultiportToPort.lf | 3 +- .../src/multiport/ReactionsToNested.lf | 3 +- .../src/serialization/ProtoNoPacking.lf | 10 +++---- test/TypeScript/src/target/AfterNoTypes.lf | 3 +- 417 files changed, 962 insertions(+), 1361 deletions(-) diff --git a/test/C/src/ActionWithNoReaction.lf b/test/C/src/ActionWithNoReaction.lf index 8ac720167d..1cfe5bfba2 100644 --- a/test/C/src/ActionWithNoReaction.lf +++ b/test/C/src/ActionWithNoReaction.lf @@ -1,6 +1,5 @@ -// This checks that action can be created even if there is no reaction. This -// test passes merely by compiling and executing without a segfault. Its other -// functionality is tested by other tests. +// This checks that action can be created even if there is no reaction. This test passes merely by +// compiling and executing without a segfault. Its other functionality is tested by other tests. target C { fast: true, timeout: 3 sec diff --git a/test/C/src/After.lf b/test/C/src/After.lf index d3663457e4..a066cfcb35 100644 --- a/test/C/src/After.lf +++ b/test/C/src/After.lf @@ -1,5 +1,4 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target C { fast: false, timeout: 3 sec diff --git a/test/C/src/AfterCycles.lf b/test/C/src/AfterCycles.lf index d7d621046b..c79e33bb31 100644 --- a/test/C/src/AfterCycles.lf +++ b/test/C/src/AfterCycles.lf @@ -1,5 +1,5 @@ -// This tests that "after" does not introduce spurious cycles. Success if -// running without detected a cycle. +// This tests that "after" does not introduce spurious cycles. Success if running without detected a +// cycle. target C reactor Source { diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf index 378114c730..265f866b59 100644 --- a/test/C/src/AfterZero.lf +++ b/test/C/src/AfterZero.lf @@ -1,5 +1,4 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target C { fast: false, timeout: 3 sec diff --git a/test/C/src/Alignment.lf b/test/C/src/Alignment.lf index a2b9b523fb..e63ff904b8 100644 --- a/test/C/src/Alignment.lf +++ b/test/C/src/Alignment.lf @@ -1,5 +1,4 @@ -// This test checks that the downstream reaction is not invoked more than once -// at a logical time. +// This test checks that the downstream reaction is not invoked more than once at a logical time. target C { logging: LOG, timeout: 1 sec diff --git a/test/C/src/ArrayAsParameter.lf b/test/C/src/ArrayAsParameter.lf index a9df29cb03..17718f0135 100644 --- a/test/C/src/ArrayAsParameter.lf +++ b/test/C/src/ArrayAsParameter.lf @@ -1,6 +1,5 @@ -// Source has an array as a parameter, the elements of which it passes to Print. -// The length of the array has to also be a parameter because C arrays do not -// encode their own length. +// Source has an array as a parameter, the elements of which it passes to Print. The length of the +// array has to also be a parameter because C arrays do not encode their own length. target C reactor Source(sequence: int[] = {0, 1, 2}, n_sequence: int = 3) { diff --git a/test/C/src/ArrayAsType.lf b/test/C/src/ArrayAsType.lf index c95e5bf385..a24f34e0a6 100644 --- a/test/C/src/ArrayAsType.lf +++ b/test/C/src/ArrayAsType.lf @@ -1,5 +1,5 @@ -// Source produces a statically allocated array, which it passes to Print. The -// destination references the array directly. +// Source produces a statically allocated array, which it passes to Print. The destination +// references the array directly. target C reactor Source { diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index 7c024a9eba..0f79a7465c 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index cb98ef7d7e..98a0703138 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index 06221e9788..3b3f9ea905 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/DanglingOutput.lf b/test/C/src/DanglingOutput.lf index 6305f17644..d13de1dac2 100644 --- a/test/C/src/DanglingOutput.lf +++ b/test/C/src/DanglingOutput.lf @@ -1,5 +1,5 @@ -// This tests that an output that is not connected to anything does not result -// in a compilation error. Passing the test is just compiling and running. +// This tests that an output that is not connected to anything does not result in a compilation +// error. Passing the test is just compiling and running. target C reactor Source { diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index 21ea7df141..bd48928bdc 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -1,6 +1,5 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target C { timeout: 6 sec } diff --git a/test/C/src/DeadlineHandledAbove.lf b/test/C/src/DeadlineHandledAbove.lf index 3b0dc49198..939d90b1d6 100644 --- a/test/C/src/DeadlineHandledAbove.lf +++ b/test/C/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target C preamble {= diff --git a/test/C/src/DelayArrayWithAfter.lf b/test/C/src/DelayArrayWithAfter.lf index c94be3b9a1..cc270d9bb8 100644 --- a/test/C/src/DelayArrayWithAfter.lf +++ b/test/C/src/DelayArrayWithAfter.lf @@ -1,5 +1,4 @@ -// This tests transport of dynamically allocated arrays over connections with -// 'after'. +// This tests transport of dynamically allocated arrays over connections with 'after'. target C { timeout: 5 sec, fast: true diff --git a/test/C/src/DelayInt.lf b/test/C/src/DelayInt.lf index 78ca793716..74eb50f1f4 100644 --- a/test/C/src/DelayInt.lf +++ b/test/C/src/DelayInt.lf @@ -6,9 +6,7 @@ reactor Delay(delay: time = 100 msec) { output out: int logical action a: int - reaction(a) -> out {= - if (a->has_value && a->is_present) lf_set(out, a->value); - =} + reaction(a) -> out {= if (a->has_value && a->is_present) lf_set(out, a->value); =} reaction(in) -> a {= // Use specialized form of schedule for integer payloads. diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index 1b4204cfc4..c5252bde55 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -1,5 +1,4 @@ -// This tests actions with immutable payloads that are neither malloc'd nor -// freed. +// This tests actions with immutable payloads that are neither malloc'd nor freed. target C preamble {= diff --git a/test/C/src/DoubleInvocation.lf b/test/C/src/DoubleInvocation.lf index 973c8b18f6..687b03a603 100644 --- a/test/C/src/DoubleInvocation.lf +++ b/test/C/src/DoubleInvocation.lf @@ -1,8 +1,7 @@ -// This illustrates a very strange bug that showed up and has now been fixed. -// This test ensures it does not reappear. At logical time zero, the two Print -// reactors used to be fired twice each at the same logical time. They should -// only be fired once. This behavior was oddly eliminated by either of the -// following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at +// the same logical time. They should only be fired once. This behavior was oddly eliminated by +// either of the following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. // * Sending only position, not velocity from Ball. target C { diff --git a/test/C/src/DoublePort.lf b/test/C/src/DoublePort.lf index c8bf9811f8..3baab84667 100644 --- a/test/C/src/DoublePort.lf +++ b/test/C/src/DoublePort.lf @@ -1,7 +1,6 @@ /** - * Test the case where two upstream reactors pass messages to a downstream - * reactor on two different ports. One message carries a microstep delay - * relative to the other. + * Test the case where two upstream reactors pass messages to a downstream reactor on two different + * ports. One message carries a microstep delay relative to the other. * * @author Soroush Bateni */ @@ -36,9 +35,7 @@ reactor Print { } =} - reaction(shutdown) {= - printf("SUCCESS: messages were at least one microstep apart.\n"); - =} + reaction(shutdown) {= printf("SUCCESS: messages were at least one microstep apart.\n"); =} } main reactor DoublePort { diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index 8da6210825..0c78b9805d 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index 68ad603168..9106853af3 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -1,5 +1,4 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice -// at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/FloatLiteral.lf b/test/C/src/FloatLiteral.lf index 576a20d1ac..3c8bfa6037 100644 --- a/test/C/src/FloatLiteral.lf +++ b/test/C/src/FloatLiteral.lf @@ -1,7 +1,6 @@ target C -// This test verifies that floating-point literals are handled correctly. -main reactor { +main reactor { // This test verifies that floating-point literals are handled correctly. preamble {= #include =} diff --git a/test/C/src/GetTime.lf b/test/C/src/GetTime.lf index 18e70ebf79..77a8f980f9 100644 --- a/test/C/src/GetTime.lf +++ b/test/C/src/GetTime.lf @@ -1,5 +1,5 @@ -// This file includes code documented on the Wiki. For this test, success is -// just compiling and running. +// This file includes code documented on the Wiki. For this test, success is just compiling and +// running. target C { timeout: 2 sec, fast: false diff --git a/test/C/src/Import.lf b/test/C/src/Import.lf index dceb0e7813..7df0fd24b6 100644 --- a/test/C/src/Import.lf +++ b/test/C/src/Import.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target C import Imported from "lib/Imported.lf" diff --git a/test/C/src/ImportComposition.lf b/test/C/src/ImportComposition.lf index 22a1bfef87..635a3b2b8f 100644 --- a/test/C/src/ImportComposition.lf +++ b/test/C/src/ImportComposition.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target C import ImportedComposition from "lib/ImportedComposition.lf" diff --git a/test/C/src/ImportRenamed.lf b/test/C/src/ImportRenamed.lf index e28e6ba4ca..7d549f04dd 100644 --- a/test/C/src/ImportRenamed.lf +++ b/test/C/src/ImportRenamed.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target C import Imported as X from "lib/Imported.lf" diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 680ffe2f75..22c4904695 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { fast: true } diff --git a/test/C/src/MovingAverage.lf b/test/C/src/MovingAverage.lf index a8309aa9d3..a477e55804 100644 --- a/test/C/src/MovingAverage.lf +++ b/test/C/src/MovingAverage.lf @@ -1,6 +1,5 @@ -// Demonstration of a state variable that is an array. The MovingAverage reactor -// computes the moving average of the last four inputs and produces that as -// output. The source is a counting sequence. +// Demonstration of a state variable that is an array. The MovingAverage reactor computes the moving +// average of the last four inputs and produces that as output. The source is a counting sequence. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/MultipleContained.lf b/test/C/src/MultipleContained.lf index 540052ba87..f0fe73c6d5 100644 --- a/test/C/src/MultipleContained.lf +++ b/test/C/src/MultipleContained.lf @@ -1,5 +1,4 @@ -// Test that a reaction can react to and send two multiple ports of a contained -// reactor. +// Test that a reaction can react to and send two multiple ports of a contained reactor. target C reactor Contained { diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index 37b5ddba9f..b7609ab803 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -1,7 +1,6 @@ -// This test checks for one of the issues arised in the solution of EECS149 Lab -// Chapter 7. In this case, a reactor has two output ports, the first one of -// which is dangling. The generated code should not have any segmentation -// faults. +// This test checks for one of the issues arised in the solution of EECS149 Lab Chapter 7. In this +// case, a reactor has two output ports, the first one of which is dangling. The generated code +// should not have any segmentation faults. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/PingPong.lf b/test/C/src/PingPong.lf index 2f1699a51d..e51f0160b8 100644 --- a/test/C/src/PingPong.lf +++ b/test/C/src/PingPong.lf @@ -1,23 +1,20 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * - Unthreaded: 97 msec * - Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ diff --git a/test/C/src/ReadOutputOfContainedReactor.lf b/test/C/src/ReadOutputOfContainedReactor.lf index ce2129069b..ba4490e237 100644 --- a/test/C/src/ReadOutputOfContainedReactor.lf +++ b/test/C/src/ReadOutputOfContainedReactor.lf @@ -1,5 +1,4 @@ -// Test reacting to and reading outputs from a contained reactor in various -// permutations. +// Test reacting to and reading outputs from a contained reactor in various permutations. target C reactor Contained { diff --git a/test/C/src/RepeatedInheritance.lf b/test/C/src/RepeatedInheritance.lf index b61147aa38..422ada69d8 100644 --- a/test/C/src/RepeatedInheritance.lf +++ b/test/C/src/RepeatedInheritance.lf @@ -1,6 +1,6 @@ /** - * This tests for the situation where a reactor extends two other reactors that - * each extend a common reactor. + * This tests for the situation where a reactor extends two other reactors that each extend a common + * reactor. * @author{Edward A. Lee} */ target C { @@ -27,9 +27,7 @@ reactor A extends B, C { input a: int output out: int - reaction(a, b, c, d) -> out {= - lf_set(out, a->value + b->value + c->value + d->value); - =} + reaction(a, b, c, d) -> out {= lf_set(out, a->value + b->value + c->value + d->value); =} } main reactor { diff --git a/test/C/src/RequestStop.lf b/test/C/src/RequestStop.lf index 83c59d1d27..1724f3ab92 100644 --- a/test/C/src/RequestStop.lf +++ b/test/C/src/RequestStop.lf @@ -1,5 +1,4 @@ -// Test verifying that lf_request_stop() called in a shutdown reaction is -// ignored. +// Test verifying that lf_request_stop() called in a shutdown reaction is ignored. target C main reactor { diff --git a/test/C/src/ScheduleLogicalAction.lf b/test/C/src/ScheduleLogicalAction.lf index 762f8c6f52..25fce8619d 100644 --- a/test/C/src/ScheduleLogicalAction.lf +++ b/test/C/src/ScheduleLogicalAction.lf @@ -1,5 +1,5 @@ -// This checks that a logical action is scheduled the specified logical time -// after the current logical time. +// This checks that a logical action is scheduled the specified logical time after the current +// logical time. target C { fast: true, timeout: 3 sec diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index b1e8f25f93..920f371d4a 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/SendsPointerTest.lf b/test/C/src/SendsPointerTest.lf index 1f17bd1388..0cfa6dc48c 100644 --- a/test/C/src/SendsPointerTest.lf +++ b/test/C/src/SendsPointerTest.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Print. -// Reference counting ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. Reference counting +// ensures that the struct is freed. target C preamble {= typedef int* int_pointer; =} diff --git a/test/C/src/SetArray.lf b/test/C/src/SetArray.lf index f30457f9f8..188fccba1f 100644 --- a/test/C/src/SetArray.lf +++ b/test/C/src/SetArray.lf @@ -1,5 +1,5 @@ -// This tests SET_ARRAY() This tests the use of the "polymorphic" delay reactor -// on a struct. It delays by a logical time any pointer datatype. +// This tests SET_ARRAY() This tests the use of the "polymorphic" delay reactor on a struct. It +// delays by a logical time any pointer datatype. target C reactor Source { diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index fba3e03cbc..e8ce362823 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -1,6 +1,5 @@ -// Test local deadline, where a deadline is associated with a reaction -// definition. This test triggers a reaction exactly once with a deadline -// violation. +// Test local deadline, where a deadline is associated with a reaction definition. This test +// triggers a reaction exactly once with a deadline violation. target C preamble {= diff --git a/test/C/src/SlowingClock.lf b/test/C/src/SlowingClock.lf index d4a1e1d5f4..36a1f01aef 100644 --- a/test/C/src/SlowingClock.lf +++ b/test/C/src/SlowingClock.lf @@ -1,8 +1,7 @@ /** - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a logical action with a minimum delay of 100 msec. The use of the - * logical action ensures the elapsed time jumps exactly from 0 to 100, 300, - * 600, and 1000 msec. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a logical + * action with a minimum delay of 100 msec. The use of the logical action ensures the elapsed time + * jumps exactly from 0 to 100, 300, 600, and 1000 msec. */ target C { timeout: 1 sec, diff --git a/test/C/src/SlowingClockPhysical.lf b/test/C/src/SlowingClockPhysical.lf index 0e82730112..7af44f3481 100644 --- a/test/C/src/SlowingClockPhysical.lf +++ b/test/C/src/SlowingClockPhysical.lf @@ -1,9 +1,8 @@ /** - * /* Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a physical action with a minimum delay of 100 msec. The use of the - * physical action makes the elapsed time jumps from 0 to approximately 100 - * msec, to approximatly 300 msec thereafter, drifting away further with each - * new event. + * /* Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a physical + * action with a minimum delay of 100 msec. The use of the physical action makes the elapsed time + * jumps from 0 to approximately 100 msec, to approximatly 300 msec thereafter, drifting away + * further with each new event. */ target C { timeout: 1500 msec diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index 8f4c1423a5..c4ff41693e 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -1,6 +1,6 @@ /** - * Test that the starvation functionality in absence of the "keepalive: true" - * target property indeed works as expected. + * Test that the starvation functionality in absence of the "keepalive: true" target property indeed + * works as expected. * * @author Soroush Bateni */ diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index e845c6de48..1a317dd45e 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -1,6 +1,6 @@ /** - * Test for lf_request_stop() at tag (0,0). This also tests for logically - * simultaneous calls to lf_request_stop(). + * Test for lf_request_stop() at tag (0,0). This also tests for logically simultaneous calls to + * lf_request_stop(). * * @author Soroush Bateni */ diff --git a/test/C/src/Stride.lf b/test/C/src/Stride.lf index 62b9077878..c57c2e0aad 100644 --- a/test/C/src/Stride.lf +++ b/test/C/src/Stride.lf @@ -1,5 +1,5 @@ -// This example illustrates state variables and parameters on the wiki. For this -// test, success is just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this test, success is +// just compiling and running. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/StructPrint.lf b/test/C/src/StructPrint.lf index 6af0d60c4f..5c2f10513e 100644 --- a/test/C/src/StructPrint.lf +++ b/test/C/src/StructPrint.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Print. -// Reference counting ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. Reference counting +// ensures that the struct is freed. target C { files: ["include/hello.h"] } diff --git a/test/C/src/TestForPreviousOutput.lf b/test/C/src/TestForPreviousOutput.lf index 583c6cbb74..825f559d13 100644 --- a/test/C/src/TestForPreviousOutput.lf +++ b/test/C/src/TestForPreviousOutput.lf @@ -1,5 +1,5 @@ -// This tests the mechanism for testing whether a previous reaction has produced -// a given output. The output should always be 42. +// This tests the mechanism for testing whether a previous reaction has produced a given output. The +// output should always be 42. target C preamble {= diff --git a/test/C/src/TimeLimit.lf b/test/C/src/TimeLimit.lf index ae178d53b5..3245725361 100644 --- a/test/C/src/TimeLimit.lf +++ b/test/C/src/TimeLimit.lf @@ -1,6 +1,5 @@ -// Test that the stop function can be used to internally impose a a time limit. -// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt -// or getting the wrong data. +// Test that the stop function can be used to internally impose a a time limit. Correct output for +// this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. target C { fast: true } diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index 771d321a40..a9cd25a886 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -1,6 +1,5 @@ /** - * A test for the timeout functionality in Lingua Franca. This variant tests - * timeout at (0,0). + * A test for the timeout functionality in Lingua Franca. This variant tests timeout at (0,0). * * @author Soroush Bateni */ diff --git a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf index bc62b214e9..5f843930b8 100644 --- a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,7 +1,4 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target C { timeout: 1 sec, fast: true diff --git a/test/C/src/arduino/AnalogReadSerial.lf b/test/C/src/arduino/AnalogReadSerial.lf index 220cb47d47..c2fc4ef475 100644 --- a/test/C/src/arduino/AnalogReadSerial.lf +++ b/test/C/src/arduino/AnalogReadSerial.lf @@ -1,8 +1,7 @@ /** - * This example reads an analog input on pin 0, prints the result to the Serial - * Monitor. Graphical representation is available using Serial Plotter (Tools > - * Serial Plotter menu). Attach the center pin of a potentiometer to pin A0, and - * the outside pins to +5V and ground. + * This example reads an analog input on pin 0, prints the result to the Serial Monitor. Graphical + * representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center + * pin of a potentiometer to pin A0, and the outside pins to +5V and ground. */ target C { platform: { diff --git a/test/C/src/arduino/Blink.lf b/test/C/src/arduino/Blink.lf index 809aa55884..4ed02cdc2a 100644 --- a/test/C/src/arduino/Blink.lf +++ b/test/C/src/arduino/Blink.lf @@ -1,7 +1,6 @@ /** - * This example demonstrates a very simple blink program that will turn on and - * off an LED on the Arduino Board with a 50% duty cycle switching every - * half-second. + * This example demonstrates a very simple blink program that will turn on and off an LED on the + * Arduino Board with a 50% duty cycle switching every half-second. */ target C { platform: { diff --git a/test/C/src/arduino/BlinkAttemptThreading.lf b/test/C/src/arduino/BlinkAttemptThreading.lf index 8f71009edf..31fd99989d 100644 --- a/test/C/src/arduino/BlinkAttemptThreading.lf +++ b/test/C/src/arduino/BlinkAttemptThreading.lf @@ -1,8 +1,7 @@ /** - * This example demonstrates a very simple blink program that will turn on and - * off an LED on the Arduino Board with a 50% duty cycle switching every - * half-second. Note: if we try to enable threading, the system will give us a - * warning and default back to no threading. + * This example demonstrates a very simple blink program that will turn on and off an LED on the + * Arduino Board with a 50% duty cycle switching every half-second. Note: if we try to enable + * threading, the system will give us a warning and default back to no threading. */ target C { platform: { diff --git a/test/C/src/arduino/BlinkMBED.lf b/test/C/src/arduino/BlinkMBED.lf index f9702d27cc..5330e018a0 100644 --- a/test/C/src/arduino/BlinkMBED.lf +++ b/test/C/src/arduino/BlinkMBED.lf @@ -1,7 +1,6 @@ /** - * This example demonstrates a very simple blink program that will turn on and - * off an LED on the Arduino Board with a 50% duty cycle switching every - * half-second. + * This example demonstrates a very simple blink program that will turn on and off an LED on the + * Arduino Board with a 50% duty cycle switching every half-second. */ target C { platform: { diff --git a/test/C/src/arduino/Fade.lf b/test/C/src/arduino/Fade.lf index d23aabd646..74d3fa0c8c 100644 --- a/test/C/src/arduino/Fade.lf +++ b/test/C/src/arduino/Fade.lf @@ -1,9 +1,8 @@ /** - * This example shows how to fade an LED on pin 9 using the analogWrite() - * function. The analogWrite() function uses PWM, so if you want to change the - * pin you're using, be sure to use another PWM capable pin. On most Arduino, - * the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and - * ~11. + * This example shows how to fade an LED on pin 9 using the analogWrite() function. The + * analogWrite() function uses PWM, so if you want to change the pin you're using, be sure to use + * another PWM capable pin. On most Arduino, the PWM pins are identified with a "~" sign, like ~3, + * ~5, ~6, ~9, ~10 and ~11. */ target C { platform: { diff --git a/test/C/src/arduino/ReadAnalogVoltage.lf b/test/C/src/arduino/ReadAnalogVoltage.lf index 77be8e8b06..2a56719f66 100644 --- a/test/C/src/arduino/ReadAnalogVoltage.lf +++ b/test/C/src/arduino/ReadAnalogVoltage.lf @@ -1,9 +1,8 @@ /** - * This example reads an analog input on pin 0, converts it to voltage, and - * prints the result to the Serial Monitor. Graphical representation is - * available using Serial Plotter (Tools > Serial Plotter menu). Attach the - * center pin of a potentiometer to pin A0, and the outside pins to +5V and - * ground. + * This example reads an analog input on pin 0, converts it to voltage, and prints the result to the + * Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial + * Plotter menu). Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V + * and ground. */ target C { platform: { diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index 58120446d4..18268c574a 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -1,11 +1,9 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test case - * assumes that target is multithreaded. This test will not work with the - * unthreaded C target because that target does not implement any mutex - * protecting the event queue. + * Test asynchronous callbacks that trigger a physical action. This test case assumes that target is + * multithreaded. This test will not work with the unthreaded C target because that target does not + * implement any mutex protecting the event queue. * - * Note: This test uses the LF platform support to enable it to run on multiple - * platforms. + * Note: This test uses the LF platform support to enable it to run on multiple platforms. */ target C { tracing: true, diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index b0c5c502f2..d7d0858699 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -1,7 +1,6 @@ -// Test asynchronous callbacks that trigger a physical action with a DROP -// policy. This test case assumes that the target is multithreaded. This test -// will not work with the unthreaded C target because that target does not -// implement any mutex protecting the event queue. +// Test asynchronous callbacks that trigger a physical action with a DROP policy. This test case +// assumes that the target is multithreaded. This test will not work with the unthreaded C target +// because that target does not implement any mutex protecting the event queue. target C { keepalive: true, // To silence warning. timeout: 2 sec diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index 7bac7496b5..ba75b3e3db 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -1,7 +1,6 @@ -// Test asynchronous callbacks that trigger a physical action with a "replace" -// policy. This test case assumes that the target is multithreaded. This test -// will not work with the unthreaded C target because that target does not -// implement any mutex protecting the event queue. +// Test asynchronous callbacks that trigger a physical action with a "replace" policy. This test +// case assumes that the target is multithreaded. This test will not work with the unthreaded C +// target because that target does not implement any mutex protecting the event queue. target C { keepalive: true, timeout: 2 sec diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index cf0bafeb82..01185fa6b3 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index ad14879080..5f698d1c95 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target C preamble {= diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index ffc1be2701..ff5961b0d9 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -1,6 +1,5 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target C { timeout: 6 sec } diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index ba6c38ca19..eb46b4f7d6 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/concurrent/ImportThreaded.lf b/test/C/src/concurrent/ImportThreaded.lf index df804157c5..b10a222f1a 100644 --- a/test/C/src/concurrent/ImportThreaded.lf +++ b/test/C/src/concurrent/ImportThreaded.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target C import Imported from "../lib/Imported.lf" diff --git a/test/C/src/concurrent/PingPongThreaded.lf b/test/C/src/concurrent/PingPongThreaded.lf index 4fae17911e..37d7b97574 100644 --- a/test/C/src/concurrent/PingPongThreaded.lf +++ b/test/C/src/concurrent/PingPongThreaded.lf @@ -1,23 +1,19 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - * Unthreaded: 97 msec Threaded: 265 msec (168 msec with optimization of - * executing immediately) + * Unthreaded: 97 msec Threaded: 265 msec (168 msec with optimization of executing immediately) * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index e5185ecfc8..dc0892195b 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index d1e78e5ced..2e50b71a58 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -1,7 +1,6 @@ /** - * Test that the starvation functionality in absence of the "keepalive: true" - * target property indeed works as expected. This version uses the threaded - * runtime. + * Test that the starvation functionality in absence of the "keepalive: true" target property indeed + * works as expected. This version uses the threaded runtime. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index 1deb1c4ff6..7beb0cb747 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -1,6 +1,6 @@ /** - * A test for the lf_request_stop() functionality in Lingua Franca. This version - * of the test is threaded. + * A test for the lf_request_stop() functionality in Lingua Franca. This version of the test is + * threaded. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index 7afd4b0069..22f5635e6c 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() at tag (0,0). This version uses the threaded - * runtime. + * Test for lf_request_stop() at tag (0,0). This version uses the threaded runtime. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/Threaded.lf b/test/C/src/concurrent/Threaded.lf index 01f67c1bd4..4daa36f6fd 100644 --- a/test/C/src/concurrent/Threaded.lf +++ b/test/C/src/concurrent/Threaded.lf @@ -1,16 +1,13 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded -// version, showing that without threads, this takes more than 800 msec to -// complete 200 msec of logical time. See ThreadedMultiport for a parameterized -// version of this. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing +// that without threads, this takes more than 800 msec to complete 200 msec of logical time. See +// ThreadedMultiport for a parameterized version of this. target C { timeout: 2 sec, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "" + flags: "" // Disable compiler optimization so that TakeTime actually takes time. } reactor Source { diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index 2878393dac..cbf8459b08 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -1,8 +1,7 @@ // Check multiport capabilities on Outputs. target C { timeout: 2 sec, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "" + flags: "" // Disable compiler optimization so that TakeTime actually takes time. } reactor Source(width: int = 4) { diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 4037e8c193..0ff1f1e09b 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -1,15 +1,13 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. See ThreadedMultiport for a -// parameterized version of this. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. See ThreadedMultiport for a parameterized version +// of this. target C { timeout: 2 sec, tracing: true, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "" + flags: "" // Disable compiler optimization so that TakeTime actually takes time. } reactor Source { diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index 8d3824af47..07bd3c9257 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -1,5 +1,5 @@ -// Test that the stop function can be used to internally impose a a time limit. -// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt. +// Test that the stop function can be used to internally impose a a time limit. Correct output for +// this 1, 2, 3, 4. Failure for this test is failing to halt. target C { fast: true } diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 82ef231ed9..41fd8d1147 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -1,6 +1,5 @@ /** - * A test for the timeout functionality in Lingua Franca. This version of the - * test is threaded. + * A test for the timeout functionality in Lingua Franca. This version of the test is threaded. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index 7865b486a9..9df91b99ba 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -1,6 +1,6 @@ /** - * A test for the timeout functionality in Lingua Franca. This variant tests - * timeout at (0,0) and uses the threaded runtime. + * A test for the timeout functionality in Lingua Franca. This variant tests timeout at (0,0) and + * uses the threaded runtime. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index cbc4513732..2d13fbf259 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -2,8 +2,7 @@ target C { timeout: 2 sec, tracing: true, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "", + flags: "", // Disable compiler optimization so that TakeTime actually takes time. logging: DEBUG } diff --git a/test/C/src/docker/PingPongContainerized.lf b/test/C/src/docker/PingPongContainerized.lf index e9ea8a0b56..10062bb3eb 100644 --- a/test/C/src/docker/PingPongContainerized.lf +++ b/test/C/src/docker/PingPongContainerized.lf @@ -1,22 +1,19 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - Unthreaded: 97 msec * - Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index 4a120c5e1e..13ae54fd80 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { diff --git a/test/C/src/docker/federated/DistributedDoublePortContainerized.lf b/test/C/src/docker/federated/DistributedDoublePortContainerized.lf index d856b6a600..6227b8b00a 100644 --- a/test/C/src/docker/federated/DistributedDoublePortContainerized.lf +++ b/test/C/src/docker/federated/DistributedDoublePortContainerized.lf @@ -1,7 +1,6 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federte on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federte on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni */ diff --git a/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf index b72052a888..342dde28e0 100644 --- a/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with decentralized - * coordination. + * Test for lf_request_stop() in federated execution with decentralized coordination. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/BroadcastFeedback.lf b/test/C/src/federated/BroadcastFeedback.lf index 2bef908d2d..b38bb399d7 100644 --- a/test/C/src/federated/BroadcastFeedback.lf +++ b/test/C/src/federated/BroadcastFeedback.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target C { timeout: 1 sec, build-type: RelWithDebInfo diff --git a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf index d9edbc954b..7ac7edecb1 100644 --- a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target C { timeout: 1 sec } diff --git a/test/C/src/federated/CycleDetection.lf b/test/C/src/federated/CycleDetection.lf index d22837bc1f..fb5bf39a7c 100644 --- a/test/C/src/federated/CycleDetection.lf +++ b/test/C/src/federated/CycleDetection.lf @@ -1,6 +1,6 @@ /** - * Check whether the internally generated network and control reactions - * introduce a cycle or not. The failure for this test is not being compiled. + * Check whether the internally generated network and control reactions introduce a cycle or not. + * The failure for this test is not being compiled. * @author Edward A. Lee */ target C diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 9dea4032aa..2d007d2b09 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -1,8 +1,7 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed about lost messages. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed about lost messages. * * The test fails if the federation does not exit. */ @@ -22,9 +21,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { lf_set(y, self->count); =} - reaction(shutdown) {= - lf_print("SUCCESS: the source exited successfully."); - =} + reaction(shutdown) {= lf_print("SUCCESS: the source exited successfully."); =} } reactor Destination { diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 8468e1dc81..fc45db9d74 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -1,11 +1,10 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed. * - * The test fails if the federation does not exit amenably. This variant has a - * physical connection between source and destination. + * The test fails if the federation does not exit amenably. This variant has a physical connection + * between source and destination. */ target C { timeout: 1 msec, @@ -23,9 +22,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { lf_set(y, self->count); =} - reaction(shutdown) {= - lf_print("SUCCESS: the source exited successfully."); - =} + reaction(shutdown) {= lf_print("SUCCESS: the source exited successfully."); =} } reactor Destination { diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 2ebdda169a..472e7f83a0 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { diff --git a/test/C/src/federated/DistributedCountDecentralized.lf b/test/C/src/federated/DistributedCountDecentralized.lf index 631dfab0c0..473e959392 100644 --- a/test/C/src/federated/DistributedCountDecentralized.lf +++ b/test/C/src/federated/DistributedCountDecentralized.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { @@ -48,6 +47,5 @@ reactor Print { federated reactor DistributedCountDecentralized { c = new Count() p = new Print() - // Indicating a 'logical' connection with a large enough delay. - c.out -> p.in after 200 msec + c.out -> p.in after 200 msec // Indicating a 'logical' connection with a large enough delay. } diff --git a/test/C/src/federated/DistributedCountPhysical.lf b/test/C/src/federated/DistributedCountPhysical.lf index 9e1e15f775..77355720ff 100644 --- a/test/C/src/federated/DistributedCountPhysical.lf +++ b/test/C/src/federated/DistributedCountPhysical.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf index b0da42218a..eeb2792425 100644 --- a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,7 +1,7 @@ /** - * Test a distributed system where a federation receives messages only over - * connections that are marked 'physical' (using the ~> arrow) with an after - * delay. The receiver verifies that the after delay is correctly imposed. + * Test a distributed system where a federation receives messages only over connections that are + * marked 'physical' (using the ~> arrow) with an after delay. The receiver verifies that the after + * delay is correctly imposed. * * @author Edward A. Lee * @author Soroush Bateni @@ -46,6 +46,5 @@ reactor Print { federated reactor at localhost { c = new Count(offset = 200 msec, period = 0) p = new Print() - // Indicating a 'physical' connection with a 400 msec after delay. - c.out ~> p.in after 400 msec + c.out ~> p.in after 400 msec // Indicating a 'physical' connection with a 400 msec after delay. } diff --git a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf index e821e4fb70..b9a606ba0b 100644 --- a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/DistributedDoublePort.lf b/test/C/src/federated/DistributedDoublePort.lf index 87de1ddb28..3394c383b6 100644 --- a/test/C/src/federated/DistributedDoublePort.lf +++ b/test/C/src/federated/DistributedDoublePort.lf @@ -1,7 +1,6 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federate on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federate on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni */ @@ -36,9 +35,7 @@ reactor Print { } =} - reaction(shutdown) {= - lf_print("SUCCESS: messages were at least one microstep apart."); - =} + reaction(shutdown) {= lf_print("SUCCESS: messages were at least one microstep apart."); =} } federated reactor DistributedDoublePort { diff --git a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf index acbbaf4035..a8c3805f34 100644 --- a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf @@ -1,6 +1,6 @@ /** - * Test that a rapidly produced logical action in an upstream federate can be - * properly handled in a long chain of federates. + * Test that a rapidly produced logical action in an upstream federate can be properly handled in a + * long chain of federates. */ target C { timeout: 1 msec diff --git a/test/C/src/federated/DistributedLoopedAction.lf b/test/C/src/federated/DistributedLoopedAction.lf index 8218e73646..a398fb8b8d 100644 --- a/test/C/src/federated/DistributedLoopedAction.lf +++ b/test/C/src/federated/DistributedLoopedAction.lf @@ -1,6 +1,5 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni */ @@ -20,8 +19,7 @@ reactor Receiver( state breaks: int = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more - // sensible log output. + // but forces the logical time to advance Comment this line for a more sensible log output. reaction(in) {= printf("At tag (%lld, %u) received value %d.\n", lf_time_logical_elapsed(), diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index 17842809fa..5a51465e5c 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -1,15 +1,13 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. The purpose of this test is to check whether the - * functionalities pertinent to dynamic STP offset adjustments are present and - * functioning to a degree. + * Test a sender-receiver network system that relies on microsteps being taken into account. The + * purpose of this test is to check whether the functionalities pertinent to dynamic STP offset + * adjustments are present and functioning to a degree. * - * This version of the test does not use a centralized coordinator to advance - * tag. Therefore, the receiver will rely on an STP offset (initially zero) to - * wait long enough for messages to arrive before advancing its tag. In this - * test, the STP offset is initially zero and gradually raised every time an STP - * violation is perceived until no STP violation is observed. Therefore, the - * exact outcome of the test will depend on actual runtime timing. + * This version of the test does not use a centralized coordinator to advance tag. Therefore, the + * receiver will rely on an STP offset (initially zero) to wait long enough for messages to arrive + * before advancing its tag. In this test, the STP offset is initially zero and gradually raised + * every time an STP violation is perceived until no STP violation is observed. Therefore, the exact + * outcome of the test will depend on actual runtime timing. * * @author Soroush Bateni */ @@ -116,10 +114,7 @@ reactor STPReceiver( federated reactor DistributedLoopedActionDecentralized { sender = new Sender(take_a_break_after = 10, break_interval = 400 msec) - stpReceiver = new STPReceiver( - take_a_break_after = 10, - break_interval = 400 msec - ) + stpReceiver = new STPReceiver(take_a_break_after = 10, break_interval = 400 msec) sender.out -> stpReceiver.in } diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index 454577ff35..d1990c05ad 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -1,11 +1,10 @@ /** - * Test a sender-receiver network system that is similar to - * DistributedLoopedAction, but it uses a physical action rather than a logical - * action. This also demonstrates the advance-message-interval coordination - * option. This specifies the time period between Time Advance Notice (TAN) - * messages sent to the RTI (a form of null message that must be sent because of - * the physical action). The presence of this option also silences a warning - * about having a physical action that triggers an output. + * Test a sender-receiver network system that is similar to DistributedLoopedAction, but it uses a + * physical action rather than a logical action. This also demonstrates the advance-message-interval + * coordination option. This specifies the time period between Time Advance Notice (TAN) messages + * sent to the RTI (a form of null message that must be sent because of the physical action). The + * presence of this option also silences a warning about having a physical action that triggers an + * output. * * @author Soroush Bateni */ @@ -45,8 +44,7 @@ reactor Receiver( state breaks: int = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more - // sensible log output. + // but forces the logical time to advance Comment this line for a more sensible log output. reaction(in) {= tag_t current_tag = lf_tag(); lf_print("At tag (%lld, %u) received %d.", diff --git a/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf b/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf index 8b22bc70be..38c4e016fe 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf @@ -1,6 +1,5 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedMultiportToken.lf b/test/C/src/federated/DistributedMultiportToken.lf index dfb791d861..c3a370cb66 100644 --- a/test/C/src/federated/DistributedMultiportToken.lf +++ b/test/C/src/federated/DistributedMultiportToken.lf @@ -1,5 +1,5 @@ -// Check multiport connections between federates where the message is carried by -// a Token (in this case, with an array of char). +// Check multiport connections between federates where the message is carried by a Token (in this +// case, with an array of char). target C { timeout: 1 sec, coordination: centralized diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index 42f3da6134..09ea7665c9 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -1,10 +1,9 @@ /** * This is a test for send_timed_message, which is an internal API. * - * This test sends a second message at time 5 msec that has the same intended - * tag as a message that it had previously sent at time 0 msec. This results in - * a warning, but the message microstep is incremented and correctly received - * one microstep later. + * This test sends a second message at time 5 msec that has the same intended tag as a message that + * it had previously sent at time 0 msec. This results in a warning, but the message microstep is + * incremented and correctly received one microstep later. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedPhysicalActionUpstream.lf b/test/C/src/federated/DistributedPhysicalActionUpstream.lf index 520142b466..f41aa0dae3 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstream.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstream.lf @@ -1,6 +1,6 @@ /** - * Test that a rapidly produced physical action in an upstream federate can be - * properly handled in federated execution. + * Test that a rapidly produced physical action in an upstream federate can be properly handled in + * federated execution. */ target C { timeout: 10 secs, diff --git a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf index 5cee1171cc..a77727d9ce 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf @@ -1,6 +1,6 @@ /** - * Test that a rapidly produced physical action in an upstream federate can be - * properly handled in a long chain of federates. + * Test that a rapidly produced physical action in an upstream federate can be properly handled in a + * long chain of federates. */ target C { timeout: 1 sec, diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index 2d4a616664..7d906a0efe 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with centralized - * coordination. + * Test for lf_request_stop() in federated execution with centralized coordination. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedStopDecentralized.lf b/test/C/src/federated/DistributedStopDecentralized.lf index bcf866aad6..f26dfe256a 100644 --- a/test/C/src/federated/DistributedStopDecentralized.lf +++ b/test/C/src/federated/DistributedStopDecentralized.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with decentralized - * coordination. + * Test for lf_request_stop() in federated execution with decentralized coordination. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedStopZero.lf b/test/C/src/federated/DistributedStopZero.lf index 67141bc624..82f49b9b91 100644 --- a/test/C/src/federated/DistributedStopZero.lf +++ b/test/C/src/federated/DistributedStopZero.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with centralized - * coordination at tag (0,0). + * Test for lf_request_stop() in federated execution with centralized coordination at tag (0,0). * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedStopZeroDecentralized.lf b/test/C/src/federated/DistributedStopZeroDecentralized.lf index fe7a6e28cd..ae37fb3fc3 100644 --- a/test/C/src/federated/DistributedStopZeroDecentralized.lf +++ b/test/C/src/federated/DistributedStopZeroDecentralized.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with decentralized - * coordination at tag (0,0). + * Test for lf_request_stop() in federated execution with decentralized coordination at tag (0,0). * * @author Soroush Bateni */ diff --git a/test/C/src/federated/HelloDistributed.lf b/test/C/src/federated/HelloDistributed.lf index 909ce53b43..f0d74eead3 100644 --- a/test/C/src/federated/HelloDistributed.lf +++ b/test/C/src/federated/HelloDistributed.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C @@ -49,7 +48,5 @@ federated reactor HelloDistributed at localhost { d = new Destination() // Reactor d is in federate Destination s.out -> d.in // This version preserves the timestamp. - reaction(startup) {= - lf_print("Printing something in top-level federated reactor."); - =} + reaction(startup) {= lf_print("Printing something in top-level federated reactor."); =} } diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index 7fdc972b5a..15a1c46934 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -1,6 +1,5 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf index f9b088b7d1..9956d2ef34 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf @@ -1,6 +1,6 @@ /** - * This tests that the precedence order of reaction invocation is kept when a - * feedback loop is present in centralized coordination. + * This tests that the precedence order of reaction invocation is kept when a feedback loop is + * present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 17177aadb3..0e214813cd 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,7 +1,6 @@ /** - * This tests that the precedence order of reaction invocation is kept in the - * hierarchy of reactors when a feedback loop is present in centralized - * coordination. + * This tests that the precedence order of reaction invocation is kept in the hierarchy of reactors + * when a feedback loop is present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index 4350c984b3..98d7a54eab 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -1,6 +1,5 @@ /** - * This tests a feedback loop with physical actions and decentralized - * coordination. + * This tests a feedback loop with physical actions and decentralized coordination. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 9a49b5bde8..8646a477bf 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -1,6 +1,5 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index 11b7a259cf..4e8a6c7a5d 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -1,7 +1,4 @@ -/** - * This is a test that detects STP violations according to the physical time of - * message arrival. - */ +/** This is a test that detects STP violations according to the physical time of message arrival. */ target C { timeout: 1900 msec, coordination: decentralized diff --git a/test/C/src/federated/PingPongDistributed.lf b/test/C/src/federated/PingPongDistributed.lf index e16de50ed2..147768f12d 100644 --- a/test/C/src/federated/PingPongDistributed.lf +++ b/test/C/src/federated/PingPongDistributed.lf @@ -1,21 +1,18 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. * - * This version is distributed, communicating using logical connections over - * sockets. + * This version is distributed, communicating using logical connections over sockets. * - * See [Benchmarks wiki - * page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). + * See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). * * This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs - * and can be run on different machines. + * This is a distributed version, where Ping and Pong run in separate programs and can be run on + * different machines. * - * There is no parallelism in this application, so it does not benefit from - * being being distributed. + * There is no parallelism in this application, so it does not benefit from being being distributed. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/PingPongDistributedPhysical.lf b/test/C/src/federated/PingPongDistributedPhysical.lf index d9ba517c59..16769ec929 100644 --- a/test/C/src/federated/PingPongDistributedPhysical.lf +++ b/test/C/src/federated/PingPongDistributedPhysical.lf @@ -1,26 +1,24 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. * - * This version is distributed, communicating using physical connections over - * sockets. + * This version is distributed, communicating using physical connections over sockets. * * This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs - * and can be run on different machines. + * This is a distributed version, where Ping and Pong run in separate programs and can be run on + * different machines. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - Unthreaded: 97 msec * - Threaded: 265 msec * - Distributed: 53 seconds * - * There is no parallelism in this application, so it does not benefit from - * being being distributed. + * There is no parallelism in this application, so it does not benefit from being being distributed. * - * These measurements are total execution time, including startup and shutdown, - * of all three programs. + * These measurements are total execution time, including startup and shutdown, of all three + * programs. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 05932b1937..42a7cb3a37 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -1,11 +1,10 @@ /** - * Test whether top-level reactions, actions, and ports are handled - * appropriately. + * Test whether top-level reactions, actions, and ports are handled appropriately. * * Currently, these artifacts are replicated on all federates. * - * @note This just tests for the correctness of the code generation. These - * top-level artifacts might be disallowed in the future. + * @note This just tests for the correctness of the code generation. These top-level artifacts might + * be disallowed in the future. */ target C { timeout: 1 msec diff --git a/test/C/src/federated/failing/ClockSync.lf b/test/C/src/federated/failing/ClockSync.lf index 1231ce9cbf..a6c1e254d3 100644 --- a/test/C/src/federated/failing/ClockSync.lf +++ b/test/C/src/federated/failing/ClockSync.lf @@ -1,8 +1,8 @@ /** - * This program tests clock synchronization. It checks the clock synchronization - * error and fails if it exceeds a threshold. Note that failures could occur - * here intermittently because clock synchronization accuracy depends on many - * conditions. But the threshold is quite high, so failures should be rare. + * This program tests clock synchronization. It checks the clock synchronization error and fails if + * it exceeds a threshold. Note that failures could occur here intermittently because clock + * synchronization accuracy depends on many conditions. But the threshold is quite high, so failures + * should be rare. * @author Edward A. Lee */ target C { @@ -10,21 +10,16 @@ target C { timeout: 10 sec, clock-sync: on, // Turn on runtime clock synchronization. clock-sync-options: { - // Forces all federates to perform clock sync. - local-federates-on: true, - // Collect useful statistics like average network delay and the standard - // deviation for the network delay over one clock synchronization cycle. - // Generates a warning if the standard deviation is higher than the - // clock sync guard. Artificially offsets clocks by multiples of 200 - // msec. + local-federates-on: true, // Forces all federates to perform clock sync. + // Collect useful statistics like average network delay and the standard deviation for the + // network delay over one clock synchronization cycle. Generates a warning if the standard + // deviation is higher than the clock sync guard. Artificially offsets clocks by multiples + // of 200 msec. collect-stats: true, test-offset: 200 msec, - // Period with which runtime clock sync is performed. - period: 5 msec, - // Number of messages exchanged to perform clock sync. - trials: 10, - // Attenuation applied to runtime clock sync adjustments. - attenuation: 10 + period: 5 msec, // Period with which runtime clock sync is performed. + trials: 10, // Number of messages exchanged to perform clock sync. + attenuation: 10 // Attenuation applied to runtime clock sync adjustments. } } diff --git a/test/C/src/lib/Imported.lf b/test/C/src/lib/Imported.lf index b6cb3200c8..1c86f0cff8 100644 --- a/test/C/src/lib/Imported.lf +++ b/test/C/src/lib/Imported.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target C import ImportedAgain from "./ImportedAgain.lf" diff --git a/test/C/src/lib/ImportedAgain.lf b/test/C/src/lib/ImportedAgain.lf index 07f2cc9faa..af57afcace 100644 --- a/test/C/src/lib/ImportedAgain.lf +++ b/test/C/src/lib/ImportedAgain.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target C reactor ImportedAgain { diff --git a/test/C/src/lib/ImportedComposition.lf b/test/C/src/lib/ImportedComposition.lf index d10e7fdcd2..66a8845233 100644 --- a/test/C/src/lib/ImportedComposition.lf +++ b/test/C/src/lib/ImportedComposition.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target C reactor Gain { diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index b996fe6ac5..60af8480c7 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -6,10 +6,9 @@ target C /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { output out: int diff --git a/test/C/src/lib/TestCount.lf b/test/C/src/lib/TestCount.lf index d3f29aec6c..e5cb1d601d 100644 --- a/test/C/src/lib/TestCount.lf +++ b/test/C/src/lib/TestCount.lf @@ -1,7 +1,6 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. diff --git a/test/C/src/modal_models/BanksModalStateReset.lf b/test/C/src/modal_models/BanksModalStateReset.lf index 8e075715c8..95abf317fd 100644 --- a/test/C/src/modal_models/BanksModalStateReset.lf +++ b/test/C/src/modal_models/BanksModalStateReset.lf @@ -1,7 +1,4 @@ -/** - * Modal Reactor Test. Tests reset of state variables in modes with banks of - * reactors. - */ +/** Modal Reactor Test. Tests reset of state variables in modes with banks of reactors. */ target C { fast: false, timeout: 4 sec @@ -48,8 +45,7 @@ main reactor { reset2.count2 -> test.events - // Trigger mode change (separately because of #1278) - reaction(stepper) -> reset1.next {= + reaction(stepper) -> reset1.next {= // Trigger mode change (separately because of #1278) for(int i = 0; i < reset1_width; i++) { lf_set(reset1[i].next, true); } diff --git a/test/C/src/modal_models/Count3Modes.lf b/test/C/src/modal_models/Count3Modes.lf index 862915abed..6f597053e0 100644 --- a/test/C/src/modal_models/Count3Modes.lf +++ b/test/C/src/modal_models/Count3Modes.lf @@ -36,11 +36,9 @@ main reactor { state expected_value: int = 1 - // Trigger - reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} + reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger - // Check - reaction(stepper) counter.count {= + reaction(stepper) counter.count {= // Check printf("%d\n", counter.count->value); if (!counter.count->is_present) { diff --git a/test/C/src/modal_models/MixedReactions.lf b/test/C/src/modal_models/MixedReactions.lf index 78ea39c95c..54d97fe156 100644 --- a/test/C/src/modal_models/MixedReactions.lf +++ b/test/C/src/modal_models/MixedReactions.lf @@ -1,6 +1,6 @@ /** - * Modal Reactor Test. Tests reactions that are defined between and after modes - * and should be ordered accordingly. + * Modal Reactor Test. Tests reactions that are defined between and after modes and should be + * ordered accordingly. */ target C { fast: true, diff --git a/test/C/src/modal_models/ModalNestedReactions.lf b/test/C/src/modal_models/ModalNestedReactions.lf index 454acbfc75..dcc61ae9c6 100644 --- a/test/C/src/modal_models/ModalNestedReactions.lf +++ b/test/C/src/modal_models/ModalNestedReactions.lf @@ -1,7 +1,4 @@ -/** - * Modal Reactor Test. Checks disabling of reactions indirectly nested in an - * inactive mode - */ +/** Modal Reactor Test. Checks disabling of reactions indirectly nested in an inactive mode */ target C { fast: false, timeout: 2 sec @@ -47,11 +44,9 @@ main reactor { timer stepper(0, 250 msec) counter = new CounterCycle() - // Trigger - reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} + reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger - // Check - reaction(stepper) counter.count, counter.only_in_two {= + reaction(stepper) counter.count, counter.only_in_two {= // Check printf("%d\n", counter.count->value); if (!counter.count->is_present) { diff --git a/test/C/src/multiport/BankMulticast.lf b/test/C/src/multiport/BankMulticast.lf index cb6c5dfe38..35b4124c73 100644 --- a/test/C/src/multiport/BankMulticast.lf +++ b/test/C/src/multiport/BankMulticast.lf @@ -1,6 +1,6 @@ /** - * This tests that a contained bank can send not only to a local connection, but - * also multicast via the container's output port. + * This tests that a contained bank can send not only to a local connection, but also multicast via + * the container's output port. */ target C { timeout: 3 sec, diff --git a/test/C/src/multiport/BankReactionsInContainer.lf b/test/C/src/multiport/BankReactionsInContainer.lf index 98d7cf4e1f..1e93ed7478 100644 --- a/test/C/src/multiport/BankReactionsInContainer.lf +++ b/test/C/src/multiport/BankReactionsInContainer.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target C { timeout: 1 sec } diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index e1ffb4b2dd..a242a246cc 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport - * input of the same reactors in the bank so that each reactor in the bank - * receives the output produced by itself and each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport input of the same + * reactors in the bank so that each reactor in the bank receives the output produced by itself and + * each other reactor. * * @author Edward A. Lee */ diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index 1b49786060..3554380d8a 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { timeout: 2 sec, fast: true @@ -8,9 +8,7 @@ target C { reactor Source(check_override: int = 0, bank_index: int = 0) { output out: int - reaction(startup) -> out {= - lf_set(out, self->bank_index * self->check_override); - =} + reaction(startup) -> out {= lf_set(out, self->bank_index * self->check_override); =} } reactor Destination(port_width: int = 3) { diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index e8ee6194b5..295032cb8d 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf index af657cf0b1..c67fea9b45 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index 8323210946..0f606e4750 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input, where the former is a hierarchical -// reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index b87a91a79b..e62d32b0c6 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version fo the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportInParameterized.lf b/test/C/src/multiport/MultiportInParameterized.lf index bf7ec93f6e..fa8b64855c 100644 --- a/test/C/src/multiport/MultiportInParameterized.lf +++ b/test/C/src/multiport/MultiportInParameterized.lf @@ -1,5 +1,5 @@ -// This is a version of the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version of the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target C { timeout: 2 sec, fast: true @@ -60,7 +60,6 @@ main reactor { a.out -> t2.in a.out -> t3.in a.out -> t4.in - // I.e.: t1.out -> b.in[0]; t2.out -> b.in[1]; t3.out -> b.in[2]; dt4.out -> - // b.in[3]; + // I.e.: t1.out -> b.in[0]; t2.out -> b.in[1]; t3.out -> b.in[2]; dt4.out -> b.in[3]; t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/C/src/multiport/MultiportMutableInput.lf b/test/C/src/multiport/MultiportMutableInput.lf index e1f8d579c2..e5c398def4 100644 --- a/test/C/src/multiport/MultiportMutableInput.lf +++ b/test/C/src/multiport/MultiportMutableInput.lf @@ -1,6 +1,5 @@ -// Source produces a ints on a multiport, which it passes to Scale. Scale -// requests a writable copy. It modifies it and passes it to Print. It gets -// freed after Print is done with it. +// Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. +// It modifies it and passes it to Print. It gets freed after Print is done with it. target C reactor Source { diff --git a/test/C/src/multiport/MultiportMutableInputArray.lf b/test/C/src/multiport/MultiportMutableInputArray.lf index 90907e4f44..d27f97f93c 100644 --- a/test/C/src/multiport/MultiportMutableInputArray.lf +++ b/test/C/src/multiport/MultiportMutableInputArray.lf @@ -1,7 +1,6 @@ -// Source produces a dynamically allocated arrays on a multiport, which it -// passes to Scale. Scale requests a writable copy, which, instead of copying, -// it just gets ownership of the original array. It modifies it and passes it to -// Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated arrays on a multiport, which it passes to Scale. Scale +// requests a writable copy, which, instead of copying, it just gets ownership of the original +// array. It modifies it and passes it to Print. It gets freed after Print is done with it. target C reactor Source { diff --git a/test/C/src/multiport/MultiportToBank.lf b/test/C/src/multiport/MultiportToBank.lf index 86146b9818..b4ef84e9dc 100644 --- a/test/C/src/multiport/MultiportToBank.lf +++ b/test/C/src/multiport/MultiportToBank.lf @@ -14,10 +14,9 @@ reactor Source(width: int = 2) { } =} - // Test also that multiple appearances of the same effect port do not result - // in multiple allocations of memory for the port. - reaction(dummy) -> - out {= // Contents of the reactions does not matter (either could be empty) + // Test also that multiple appearances of the same effect port do not result in multiple + // allocations of memory for the port. + reaction(dummy) -> out {= // Contents of the reactions does not matter (either could be empty) for(int i = 0; i < out_width; i++) { lf_set(out[i], i); } diff --git a/test/C/src/multiport/MultiportToBankAfter.lf b/test/C/src/multiport/MultiportToBankAfter.lf index ba26142243..9ad4b04d71 100644 --- a/test/C/src/multiport/MultiportToBankAfter.lf +++ b/test/C/src/multiport/MultiportToBankAfter.lf @@ -1,5 +1,4 @@ -// Check multiport output to bank of recipients where the width of the bank is -// inferred. +// Check multiport output to bank of recipients where the width of the bank is inferred. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index 444f02d170..5cf16f77a0 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients where the source has two -// reactions that write to the output. +// Check multiport output to bank of recipients where the source has two reactions that write to the +// output. target C { timeout: 2 sec, fast: true @@ -14,8 +14,8 @@ reactor Source { } =} - // Test also that multiple appearances of the same effect port do not result - // in multiple allocations of memory for the port. + // Test also that multiple appearances of the same effect port do not result in multiple + // allocations of memory for the port. reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) for(int i = 0; i < out_width; i++) { diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index fbdc531bf0..93acb2081d 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index 41ca505077..bde5ee1169 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -1,6 +1,5 @@ -// Check multiport output to multiport input, where the latter is a hierarchical -// reactor. Note that the destination reactor has width wider than the sender, -// so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +// the destination reactor has width wider than the sender, so one input is dangling. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToMultiportArray.lf b/test/C/src/multiport/MultiportToMultiportArray.lf index 9d86a4a522..5cfac7368d 100644 --- a/test/C/src/multiport/MultiportToMultiportArray.lf +++ b/test/C/src/multiport/MultiportToMultiportArray.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToPort.lf b/test/C/src/multiport/MultiportToPort.lf index 1784f2503c..a89c162e12 100644 --- a/test/C/src/multiport/MultiportToPort.lf +++ b/test/C/src/multiport/MultiportToPort.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index d84b21c191..458d963bb9 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -1,5 +1,4 @@ -// Test reaction sending messages to a contained bank of reactors with a -// multiport input. +// Test reaction sending messages to a contained bank of reactors with a multiport input. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/multiport/ReactionsToNested.lf b/test/C/src/multiport/ReactionsToNested.lf index 4270f55c2d..db8c1da63d 100644 --- a/test/C/src/multiport/ReactionsToNested.lf +++ b/test/C/src/multiport/ReactionsToNested.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { timeout: 1 sec } diff --git a/test/C/src/multiport/SparseFallback.lf b/test/C/src/multiport/SparseFallback.lf index a7788858d8..1326f9ca99 100644 --- a/test/C/src/multiport/SparseFallback.lf +++ b/test/C/src/multiport/SparseFallback.lf @@ -1,6 +1,6 @@ /** - * Test reading of sparse inputs on a multiport where the density of writes to - * the multiport is high enough to force the fallback policy to kick in. + * Test reading of sparse inputs on a multiport where the density of writes to the multiport is high + * enough to force the fallback policy to kick in. */ target C { timeout: 20 ms diff --git a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf index 917982af39..d4a37bbaee 100644 --- a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf +++ b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf @@ -1,7 +1,4 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target C { timeout: 1 sec, fast: true diff --git a/test/C/src/serialization/PersonProtocolBuffers.lf b/test/C/src/serialization/PersonProtocolBuffers.lf index a01243d846..f2572fc72f 100644 --- a/test/C/src/serialization/PersonProtocolBuffers.lf +++ b/test/C/src/serialization/PersonProtocolBuffers.lf @@ -1,23 +1,21 @@ /** - * This example demonstrates a very simple use of protocol buffers within a - * reactor. It encodes and decodes a very simple protocol buffer definition in - * Person.proto. This reactor is heavily based on the examples at - * https://github.com/protobuf-c/protobuf-c/wiki/Examples. This example just + * This example demonstrates a very simple use of protocol buffers within a reactor. It encodes and + * decodes a very simple protocol buffer definition in Person.proto. This reactor is heavily based + * on the examples at https://github.com/protobuf-c/protobuf-c/wiki/Examples. This example just * packs and unpacks a message. * * To run this example first install the protocol buffers compiler from - * https://github.com/protocolbuffers/protobuf. It is also available from - * homebrew on a Mac via + * https://github.com/protocolbuffers/protobuf. It is also available from homebrew on a Mac via * * $ brew install protobuf * - * Building protobuf from source is slow, so avoid doing that if possible. Next - * install the C plugin for protocol buffers from + * Building protobuf from source is slow, so avoid doing that if possible. Next install the C plugin + * for protocol buffers from * * https://github.com/protobuf-c/protobuf-c * - * The code generator assumes that executables are installed within the PATH. On - * a Mac, this is typically at /usr/local/bin. + * The code generator assumes that executables are installed within the PATH. On a Mac, this is + * typically at /usr/local/bin. */ target C { protobufs: Person.proto diff --git a/test/C/src/serialization/ProtoNoPacking.lf b/test/C/src/serialization/ProtoNoPacking.lf index 283e4feafb..91464570fc 100644 --- a/test/C/src/serialization/ProtoNoPacking.lf +++ b/test/C/src/serialization/ProtoNoPacking.lf @@ -1,22 +1,20 @@ /** - * This example creates a Protocol Buffer message and passes it to another - * reactor without packing and unpacking. This demonstrates that local - * communication, within one shared-memory machine, need not incur the overhead - * of packing and unpacking. + * This example creates a Protocol Buffer message and passes it to another reactor without packing + * and unpacking. This demonstrates that local communication, within one shared-memory machine, need + * not incur the overhead of packing and unpacking. * * To run this example first install the protocol buffers compiler from - * https://github.com/protocolbuffers/protobuf. It is also available from - * homebrew on a Mac via + * https://github.com/protocolbuffers/protobuf. It is also available from homebrew on a Mac via * * $ brew install protobuf * - * Building protobuf from source is slow, so avoid doing that if possible. Next - * install the C plugin for protocol buffers from + * Building protobuf from source is slow, so avoid doing that if possible. Next install the C plugin + * for protocol buffers from * * https://github.com/protobuf-c/protobuf-c * - * The code generator assumes that executables are installed within the PATH. On - * a Mac, this is typically at /usr/local/bin. + * The code generator assumes that executables are installed within the PATH. On a Mac, this is + * typically at /usr/local/bin. */ target C { protobufs: [ProtoHelloWorld.proto] diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index 97b5a12554..dc5902885e 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -1,13 +1,12 @@ /** - * This test showcases the infrastructure that is built into the CCpp target - * that can automatically serialize and deserialize ROS2 messages (with a - * shared_ptr type) in federated programs. + * This test showcases the infrastructure that is built into the CCpp target that can automatically + * serialize and deserialize ROS2 messages (with a shared_ptr type) in federated programs. * - * This test contains a sender-receiver federated program in which the 'sender' - * federate sends a std_msgs::msg::Int32 message to the 'receiver' federate. + * This test contains a sender-receiver federated program in which the 'sender' federate sends a + * std_msgs::msg::Int32 message to the 'receiver' federate. * - * To run this test, make sure that your terminal is properly sourced for ROS2. - * See https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. + * To run this test, make sure that your terminal is properly sourced for ROS2. See + * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. * * Then you can use lfc to compile this program: * diff --git a/test/C/src/target/CMakeInclude.lf b/test/C/src/target/CMakeInclude.lf index 411f07ee0f..6b9d3b2ecc 100644 --- a/test/C/src/target/CMakeInclude.lf +++ b/test/C/src/target/CMakeInclude.lf @@ -1,6 +1,5 @@ /** - * Test that cmake-include is working correctly. The failure for this test is - * failure to compile. + * Test that cmake-include is working correctly. The failure for this test is failure to compile. */ target C { cmake-include: [ diff --git a/test/C/src/target/DistributedCMakeInclude.lf b/test/C/src/target/DistributedCMakeInclude.lf index da02652ebf..486dafa608 100644 --- a/test/C/src/target/DistributedCMakeInclude.lf +++ b/test/C/src/target/DistributedCMakeInclude.lf @@ -1,7 +1,6 @@ /** - * Test that cmake-include in a federated program works correctly. Both - * federates should see FOO = 3.14. The failure for this test is failure to - * compile. + * Test that cmake-include in a federated program works correctly. Both federates should see FOO = + * 3.14. The failure for this test is failure to compile. */ target C { timeout: 0 sec, diff --git a/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf b/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf index c23e57972a..f1cf671c03 100644 --- a/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf +++ b/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf @@ -1,7 +1,7 @@ /** - * Test that cmake-include in an included file is being imported correctly, and - * that the imported cmake-includes are applied separately for each federate. - * The failure for this test is failure to compile. + * Test that cmake-include in an included file is being imported correctly, and that the imported + * cmake-includes are applied separately for each federate. The failure for this test is failure to + * compile. */ target C { timeout: 0 sec diff --git a/test/C/src/target/HelloWorldCCPP.lf b/test/C/src/target/HelloWorldCCPP.lf index 91d1cd61d1..917ca4308a 100644 --- a/test/C/src/target/HelloWorldCCPP.lf +++ b/test/C/src/target/HelloWorldCCPP.lf @@ -1,6 +1,6 @@ /** - * A variant of HelloWorld.lf that tests the CCpp target in conjunction with the - * CMake build system. This test should not pass if it does not compile. + * A variant of HelloWorld.lf that tests the CCpp target in conjunction with the CMake build system. + * This test should not pass if it does not compile. */ target CCpp { tracing: true, diff --git a/test/C/src/target/HelloWorldFederatedCCPP.lf b/test/C/src/target/HelloWorldFederatedCCPP.lf index 1ffa1a68b2..54c285c700 100644 --- a/test/C/src/target/HelloWorldFederatedCCPP.lf +++ b/test/C/src/target/HelloWorldFederatedCCPP.lf @@ -1,6 +1,6 @@ /** - * A variant of HelloWorld.lf that tests the federated runtime with the CCpp - * target. This test should not pass if it does not compile. + * A variant of HelloWorld.lf that tests the federated runtime with the CCpp target. This test + * should not pass if it does not compile. */ target CCpp { tracing: true, diff --git a/test/C/src/target/HelloWorldThreadedCPP.lf b/test/C/src/target/HelloWorldThreadedCPP.lf index 44bc439683..259ea9d320 100644 --- a/test/C/src/target/HelloWorldThreadedCPP.lf +++ b/test/C/src/target/HelloWorldThreadedCPP.lf @@ -1,6 +1,6 @@ /** - * A variant of HelloWorld.lf that tests the threaded CCpp target. This test - * should not pass if it does not compile. + * A variant of HelloWorld.lf that tests the threaded CCpp target. This test should not pass if it + * does not compile. */ target CCpp { tracing: true, diff --git a/test/Cpp/src/ActionWithNoReaction.lf b/test/Cpp/src/ActionWithNoReaction.lf index c43e567d3c..f4c0fa8a01 100644 --- a/test/Cpp/src/ActionWithNoReaction.lf +++ b/test/Cpp/src/ActionWithNoReaction.lf @@ -1,6 +1,5 @@ -// This checks that action can be created even if there is no reaction. This -// test passes merely by compiling and executing without a segfault. Its other -// functionality is tested by other tests. +// This checks that action can be created even if there is no reaction. This test passes merely by +// compiling and executing without a segfault. Its other functionality is tested by other tests. target Cpp { fast: true, timeout: 3 sec diff --git a/test/Cpp/src/After.lf b/test/Cpp/src/After.lf index bbcc287b78..40f9e3a54b 100644 --- a/test/Cpp/src/After.lf +++ b/test/Cpp/src/After.lf @@ -1,5 +1,4 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target Cpp { fast: false, timeout: 3 sec diff --git a/test/Cpp/src/AfterZero.lf b/test/Cpp/src/AfterZero.lf index 152b87cfc2..59ba9b4fb3 100644 --- a/test/Cpp/src/AfterZero.lf +++ b/test/Cpp/src/AfterZero.lf @@ -1,5 +1,4 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target Cpp { fast: false, timeout: 3 sec diff --git a/test/Cpp/src/Alignment.lf b/test/Cpp/src/Alignment.lf index 1bd3562f41..0ab486903c 100644 --- a/test/Cpp/src/Alignment.lf +++ b/test/Cpp/src/Alignment.lf @@ -1,5 +1,4 @@ -// This test checks that the downstream reaction is not invoked more than once -// at a logical time. +// This test checks that the downstream reaction is not invoked more than once at a logical time. target Cpp { logging: LOG, timeout: 1 sec, diff --git a/test/Cpp/src/ArrayAsParameter.lf b/test/Cpp/src/ArrayAsParameter.lf index 85cd0630bf..e36a63a201 100644 --- a/test/Cpp/src/ArrayAsParameter.lf +++ b/test/Cpp/src/ArrayAsParameter.lf @@ -1,5 +1,4 @@ -// Source has an variable sized list as a parameter, the elements of which it -// passes to Print. +// Source has an variable sized list as a parameter, the elements of which it passes to Print. target Cpp reactor Source(sequence: std::vector = {0, 1, 2}) { diff --git a/test/Cpp/src/ArrayAsType.lf b/test/Cpp/src/ArrayAsType.lf index 9a61e0e439..d678fc1d0b 100644 --- a/test/Cpp/src/ArrayAsType.lf +++ b/test/Cpp/src/ArrayAsType.lf @@ -1,5 +1,5 @@ -// Source produces a statically allocated array, which it passes to Print. The -// destination references the array directly. +// Source produces a statically allocated array, which it passes to Print. The destination +// references the array directly. target Cpp reactor Source { diff --git a/test/Cpp/src/ArrayParallel.lf b/test/Cpp/src/ArrayParallel.lf index 9e5e356a9d..c8272b64a2 100644 --- a/test/Cpp/src/ArrayParallel.lf +++ b/test/Cpp/src/ArrayParallel.lf @@ -1,6 +1,6 @@ -// Source allocates an array dynamically and then sends it to two reactors, each -// of which want to modify it. NOTE: Ideally, only one copy would be made, but -// this is not supported yet by the C++ runtime. +// Source allocates an array dynamically and then sends it to two reactors, each of which want to +// modify it. NOTE: Ideally, only one copy would be made, but this is not supported yet by the C++ +// runtime. target Cpp import Scale from "ArrayScale.lf" diff --git a/test/Cpp/src/ArrayPrint.lf b/test/Cpp/src/ArrayPrint.lf index 3bdf494107..59395d37d7 100644 --- a/test/Cpp/src/ArrayPrint.lf +++ b/test/Cpp/src/ArrayPrint.lf @@ -1,6 +1,5 @@ -// Source produces a dynamically allocated array, which it passes to Print. The -// ownership semantics of values ensure that the array is automatically deleted -// if it does have no owner. +// Source produces a dynamically allocated array, which it passes to Print. The ownership semantics +// of values ensure that the array is automatically deleted if it does have no owner. target Cpp reactor Source { diff --git a/test/Cpp/src/ArrayScale.lf b/test/Cpp/src/ArrayScale.lf index b52e7305b7..44db608e92 100644 --- a/test/Cpp/src/ArrayScale.lf +++ b/test/Cpp/src/ArrayScale.lf @@ -1,6 +1,5 @@ -// Source produces a dynamically allocated array, which it passes to Scale. -// Scale requests a writable copy. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated array, which it passes to Scale. Scale requests a +// writable copy. It modifies it and passes it to Print. It gets freed after Print is done with it. target Cpp import Source, Print from "ArrayPrint.lf" diff --git a/test/Cpp/src/Composition.lf b/test/Cpp/src/Composition.lf index 0a341d5e4f..4c5baeb870 100644 --- a/test/Cpp/src/Composition.lf +++ b/test/Cpp/src/Composition.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target Cpp { fast: true, timeout: 10 sec diff --git a/test/Cpp/src/CompositionAfter.lf b/test/Cpp/src/CompositionAfter.lf index 15d68e13ea..ea1b27fd5e 100644 --- a/test/Cpp/src/CompositionAfter.lf +++ b/test/Cpp/src/CompositionAfter.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target Cpp { fast: true, timeout: 10 sec diff --git a/test/Cpp/src/DanglingOutput.lf b/test/Cpp/src/DanglingOutput.lf index 1c8a45531a..499fa0e504 100644 --- a/test/Cpp/src/DanglingOutput.lf +++ b/test/Cpp/src/DanglingOutput.lf @@ -1,5 +1,5 @@ -// This tests that an output that is not connected to anything does not result -// in a compilation error. Passing the test is just compiling and running. +// This tests that an output that is not connected to anything does not result in a compilation +// error. Passing the test is just compiling and running. target Cpp reactor Source { diff --git a/test/Cpp/src/Deadline.lf b/test/Cpp/src/Deadline.lf index 19a41ff057..5a6448195d 100644 --- a/test/Cpp/src/Deadline.lf +++ b/test/Cpp/src/Deadline.lf @@ -1,6 +1,5 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target Cpp { timeout: 4 sec } diff --git a/test/Cpp/src/DeadlineHandledAbove.lf b/test/Cpp/src/DeadlineHandledAbove.lf index b2a6c7658a..e39ae3db09 100644 --- a/test/Cpp/src/DeadlineHandledAbove.lf +++ b/test/Cpp/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target Cpp reactor Deadline(threshold: time = 100 msec) { diff --git a/test/Cpp/src/DoubleInvocation.lf b/test/Cpp/src/DoubleInvocation.lf index 956b54bb17..236b0f425d 100644 --- a/test/Cpp/src/DoubleInvocation.lf +++ b/test/Cpp/src/DoubleInvocation.lf @@ -1,11 +1,9 @@ -// This illustrates a very strange bug that showed up and has now been fixed. -// This test ensures it does not reappear. At logical time zero, the two Print -// reactors used to be fired twice each at the same logical time. They should -// only be fired once. This behavior was oddly eliminated by either of the -// following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at +// the same logical time. They should only be fired once. This behavior was oddly eliminated by +// either of the following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. -// * Sending only position, not velocity from Ball. (copied from the c version -// of the test) +// * Sending only position, not velocity from Ball. (copied from the c version of the test) target Cpp { timeout: 5 sec, fast: true diff --git a/test/Cpp/src/DoublePort.lf b/test/Cpp/src/DoublePort.lf index faaa474db5..b28f70db4d 100644 --- a/test/Cpp/src/DoublePort.lf +++ b/test/Cpp/src/DoublePort.lf @@ -1,7 +1,6 @@ /** - * Test the case where two upstream reactors pass messages to a downstream - * reactor on two different ports. One message carries a microstep delay - * relative to the other. + * Test the case where two upstream reactors pass messages to a downstream reactor on two different + * ports. One message carries a microstep delay relative to the other. * * @author Maiko Brants */ diff --git a/test/Cpp/src/DoubleReaction.lf b/test/Cpp/src/DoubleReaction.lf index 1128d63f97..3642fa027a 100644 --- a/test/Cpp/src/DoubleReaction.lf +++ b/test/Cpp/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index 5db4818048..b39f0a559e 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -1,5 +1,4 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice -// at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. target Cpp main reactor DoubleTrigger { diff --git a/test/Cpp/src/GetTime.lf b/test/Cpp/src/GetTime.lf index 5437fc78dd..e9ba6922d5 100644 --- a/test/Cpp/src/GetTime.lf +++ b/test/Cpp/src/GetTime.lf @@ -1,5 +1,5 @@ -// This file includes code documented on the Wiki. For this test, success is -// just compiling and running. +// This file includes code documented on the Wiki. For this test, success is just compiling and +// running. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/Import.lf b/test/Cpp/src/Import.lf index a7434a2b4d..020877a883 100644 --- a/test/Cpp/src/Import.lf +++ b/test/Cpp/src/Import.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target Cpp import Imported from "lib/Imported.lf" diff --git a/test/Cpp/src/ImportComposition.lf b/test/Cpp/src/ImportComposition.lf index 0559edacd1..492b77d96d 100644 --- a/test/Cpp/src/ImportComposition.lf +++ b/test/Cpp/src/ImportComposition.lf @@ -1,8 +1,7 @@ /** * @author Maiko Brants TU Dresden * - * This tests the ability to import a reactor definition that itself imports a - * reactor definition. + * This tests the ability to import a reactor definition that itself imports a reactor definition. * * modeled after the C version of this test */ diff --git a/test/Cpp/src/ImportRenamed.lf b/test/Cpp/src/ImportRenamed.lf index e7338e6346..ea21c06964 100644 --- a/test/Cpp/src/ImportRenamed.lf +++ b/test/Cpp/src/ImportRenamed.lf @@ -1,8 +1,7 @@ /** * @author Maiko Brants TU Dresden * - * This tests the ability to import a reactor definition that itself imports a - * reactor definition. + * This tests the ability to import a reactor definition that itself imports a reactor definition. * * modeled after the C version of this test */ diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index 3c55bdcaf1..e17d4eac13 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -1,7 +1,6 @@ target Cpp -// That's the stuff that shall be generated for the after -reactor GeneratedDelay { +reactor GeneratedDelay { // That's the stuff that shall be generated for the after input y_in: int output y_out: int state y_state: int = 0 @@ -17,8 +16,7 @@ reactor Source { output out: int timer t - // reaction(t) -> out after 100 msec {= - reaction(t) -> out {= out.set(1); =} + reaction(t) -> out {= out.set(1); =} // reaction(t) -> out after 100 msec {= } reactor Sink { diff --git a/test/Cpp/src/MovingAverage.lf b/test/Cpp/src/MovingAverage.lf index af202ca0a0..2ccaa87406 100644 --- a/test/Cpp/src/MovingAverage.lf +++ b/test/Cpp/src/MovingAverage.lf @@ -1,6 +1,6 @@ -// Demonstration of a state variable that is a fixed size list. The -// MovingAverage reactor computes the moving average of the last four inputs and -// produces that as output. The source is a counting sequence. +// Demonstration of a state variable that is a fixed size list. The MovingAverage reactor computes +// the moving average of the last four inputs and produces that as output. The source is a counting +// sequence. target Cpp { timeout: 1 sec, fast: true diff --git a/test/Cpp/src/MultipleContained.lf b/test/Cpp/src/MultipleContained.lf index e6db9eb7be..8831bb3d6d 100644 --- a/test/Cpp/src/MultipleContained.lf +++ b/test/Cpp/src/MultipleContained.lf @@ -1,5 +1,4 @@ -// Test that a reaction can react to and send two multiple ports of a contained -// reactor. +// Test that a reaction can react to and send two multiple ports of a contained reactor. target Cpp reactor Contained { diff --git a/test/Cpp/src/PreambleTest.lf b/test/Cpp/src/PreambleTest.lf index 6e056639fa..66b479397d 100644 --- a/test/Cpp/src/PreambleTest.lf +++ b/test/Cpp/src/PreambleTest.lf @@ -1,20 +1,18 @@ target Cpp main reactor { - // This declaration is required on the public reactor interface and - // therefore needs to be placed in the generated header. This goes to - // Preamble/Preamble.hh. + // This declaration is required on the public reactor interface and therefore needs to be placed + // in the generated header. This goes to Preamble/Preamble.hh. public preamble {= struct MyStruct { int foo; std::string bar; }; =} - // this is only used inside reactions and therefore goes to the generated - // source file This function is only used inside a reaction and therefore is - // part of the private interface. Moreover, we need to make sure that the - // function is only defined once within a source file. This goes to - // Preamble/Preamble.cc + // this is only used inside reactions and therefore goes to the generated source file This + // function is only used inside a reaction and therefore is part of the private interface. + // Moreover, we need to make sure that the function is only defined once within a source file. + // This goes to Preamble/Preamble.cc private preamble {= int add_42(int i) { return i + 42; diff --git a/test/Cpp/src/ReadOutputOfContainedReactor.lf b/test/Cpp/src/ReadOutputOfContainedReactor.lf index c7e85083b4..7d16b24cb7 100644 --- a/test/Cpp/src/ReadOutputOfContainedReactor.lf +++ b/test/Cpp/src/ReadOutputOfContainedReactor.lf @@ -1,5 +1,4 @@ -// Test reacting to and reading outputs from a contained reactor in various -// permutations. +// Test reacting to and reading outputs from a contained reactor in various permutations. target Cpp reactor Contained { diff --git a/test/Cpp/src/ScheduleLogicalAction.lf b/test/Cpp/src/ScheduleLogicalAction.lf index 96fd5382b7..2e2f9f99f5 100644 --- a/test/Cpp/src/ScheduleLogicalAction.lf +++ b/test/Cpp/src/ScheduleLogicalAction.lf @@ -1,8 +1,8 @@ /** * @author Maiko Brants TU Dresden * - * This checks that a logical action is scheduled the specified logical time - * after the current logical time. + * This checks that a logical action is scheduled the specified logical time after the current + * logical time. * * Modeled after the C version of this test. */ diff --git a/test/Cpp/src/SendingInside.lf b/test/Cpp/src/SendingInside.lf index 2f73122bc8..4b04d48bc7 100644 --- a/test/Cpp/src/SendingInside.lf +++ b/test/Cpp/src/SendingInside.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/SimpleDeadline.lf b/test/Cpp/src/SimpleDeadline.lf index be10b55d43..c14ba2adea 100644 --- a/test/Cpp/src/SimpleDeadline.lf +++ b/test/Cpp/src/SimpleDeadline.lf @@ -1,6 +1,5 @@ -// Test local deadline, where a deadline is associated with a reaction -// definition. This test triggers a reaction exactly once with a deadline -// violation. +// Test local deadline, where a deadline is associated with a reaction definition. This test +// triggers a reaction exactly once with a deadline violation. target Cpp reactor Deadline(threshold: time = 100 msec) { diff --git a/test/Cpp/src/SlowingClock.lf b/test/Cpp/src/SlowingClock.lf index adbe93e418..13228f17a1 100644 --- a/test/Cpp/src/SlowingClock.lf +++ b/test/Cpp/src/SlowingClock.lf @@ -1,10 +1,9 @@ /** * @author Maiko Brants TU Dresden * - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a logical action with a minimum delay of 100 msec. The use of the - * logical action ensures the elapsed time jumps exactly from 0 to 100, 300, - * 600, and 1000 msec. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a logical + * action with a minimum delay of 100 msec. The use of the logical action ensures the elapsed time + * jumps exactly from 0 to 100, 300, 600, and 1000 msec. * * Modeled after the C version of this test. */ diff --git a/test/Cpp/src/SlowingClockPhysical.lf b/test/Cpp/src/SlowingClockPhysical.lf index 919f9d6cdf..7486a00a91 100644 --- a/test/Cpp/src/SlowingClockPhysical.lf +++ b/test/Cpp/src/SlowingClockPhysical.lf @@ -1,11 +1,10 @@ /** * @author Maiko Brants TU Dresden * - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a physical action with a minimum delay of 100 msec. The use of the - * physical action makes the elapsed time jumps from 0 to approximately 100 - * msec, to approximatly 300 msec thereafter, drifting away further with each - * new event. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a physical + * action with a minimum delay of 100 msec. The use of the physical action makes the elapsed time + * jumps from 0 to approximately 100 msec, to approximatly 300 msec thereafter, drifting away + * further with each new event. * * Modeled after the C version of this test. */ diff --git a/test/Cpp/src/Stride.lf b/test/Cpp/src/Stride.lf index 5f469e4c70..7aabd9b399 100644 --- a/test/Cpp/src/Stride.lf +++ b/test/Cpp/src/Stride.lf @@ -1,5 +1,5 @@ -// This example illustrates state variables and parameters on the wiki. For this -// test, success is just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this test, success is +// just compiling and running. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/StructParallel.lf b/test/Cpp/src/StructParallel.lf index e709057f02..ab50ab0e93 100644 --- a/test/Cpp/src/StructParallel.lf +++ b/test/Cpp/src/StructParallel.lf @@ -1,6 +1,6 @@ -// Source allocates an array dynamically and then sends it to two reactors, each -// of which want to modify it. NOTE: Ideally, only one copy would be made, but -// this requires is currently not supported by the C++ runtime. +// Source allocates an array dynamically and then sends it to two reactors, each of which want to +// modify it. NOTE: Ideally, only one copy would be made, but this requires is currently not +// supported by the C++ runtime. target Cpp import Scale from "StructScale.lf" diff --git a/test/Cpp/src/StructScale.lf b/test/Cpp/src/StructScale.lf index 776dad14b1..ed472eced6 100644 --- a/test/Cpp/src/StructScale.lf +++ b/test/Cpp/src/StructScale.lf @@ -1,6 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Scale. -// Scale requests a writable copy. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated struct, which it passes to Scale. Scale requests a +// writable copy. It modifies it and passes it to Print. It gets freed after Print is done with it. target Cpp import Source, Print from "StructPrint.lf" diff --git a/test/Cpp/src/TestForPreviousOutput.lf b/test/Cpp/src/TestForPreviousOutput.lf index 7be315e5a4..3a5b9bd697 100644 --- a/test/Cpp/src/TestForPreviousOutput.lf +++ b/test/Cpp/src/TestForPreviousOutput.lf @@ -1,5 +1,5 @@ -// This tests the mechanism for testing whether a previous reaction has produced -// a given output. The output should always be 42. +// This tests the mechanism for testing whether a previous reaction has produced a given output. The +// output should always be 42. target Cpp reactor Source { diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index 8b33dcd967..8383d4bf26 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -1,6 +1,5 @@ -// Test that the stop function can be used to internally to impose a a time -// limit. Correct output for this 1, 2, 3, 4. Failure for this test is failing -// to halt or getting the wrong data. +// Test that the stop function can be used to internally to impose a a time limit. Correct output +// for this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. target Cpp { fast: true } diff --git a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf index b8c304b164..1a360411ae 100644 --- a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,6 +1,5 @@ /** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. + * This test checks that a downstream reaction is triggered only if its trigger is present. * * @author Maiko Brants TU Dresden * diff --git a/test/Cpp/src/concurrent/CompositionThreaded.lf b/test/Cpp/src/concurrent/CompositionThreaded.lf index 42817e8b1d..07738e3e45 100644 --- a/test/Cpp/src/concurrent/CompositionThreaded.lf +++ b/test/Cpp/src/concurrent/CompositionThreaded.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target Cpp { fast: true, timeout: 10 sec diff --git a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf index bb380fe14c..fe39ebcb98 100644 --- a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target Cpp reactor Deadline(threshold: time = 100 msec) { diff --git a/test/Cpp/src/concurrent/DeadlineThreaded.lf b/test/Cpp/src/concurrent/DeadlineThreaded.lf index cb794f5050..131167fa77 100644 --- a/test/Cpp/src/concurrent/DeadlineThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineThreaded.lf @@ -1,6 +1,5 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target Cpp { timeout: 4 sec } diff --git a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf index d68f2e8b60..c8b1fa06a3 100644 --- a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf +++ b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/concurrent/ImportThreaded.lf b/test/Cpp/src/concurrent/ImportThreaded.lf index ae8f2405cd..d032b196fe 100644 --- a/test/Cpp/src/concurrent/ImportThreaded.lf +++ b/test/Cpp/src/concurrent/ImportThreaded.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target Cpp import Imported from "../lib/Imported.lf" diff --git a/test/Cpp/src/concurrent/SendingInsideThreaded.lf b/test/Cpp/src/concurrent/SendingInsideThreaded.lf index 51ca511e26..acd34f147f 100644 --- a/test/Cpp/src/concurrent/SendingInsideThreaded.lf +++ b/test/Cpp/src/concurrent/SendingInsideThreaded.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/concurrent/Threaded.lf b/test/Cpp/src/concurrent/Threaded.lf index 9ad4fcbe56..f0a72fc2ed 100644 --- a/test/Cpp/src/concurrent/Threaded.lf +++ b/test/Cpp/src/concurrent/Threaded.lf @@ -1,11 +1,9 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded -// version, showing that without threads, this takes more than 800 msec to -// complete 200 msec of logical time. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing +// that without threads, this takes more than 800 msec to complete 200 msec of logical time. target Cpp { timeout: 2 sec } diff --git a/test/Cpp/src/concurrent/ThreadedThreaded.lf b/test/Cpp/src/concurrent/ThreadedThreaded.lf index f8b21a6121..e8d50e7a33 100644 --- a/test/Cpp/src/concurrent/ThreadedThreaded.lf +++ b/test/Cpp/src/concurrent/ThreadedThreaded.lf @@ -1,11 +1,9 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded -// version, showing that without threads, this takes more than 800 msec to -// complete 200 msec of logical time. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing +// that without threads, this takes more than 800 msec to complete 200 msec of logical time. target Cpp { timeout: 2 sec } diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index 47371f72d7..bd9959b9a0 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -1,7 +1,6 @@ -// Test that the stop function can be used to internally to impose a a time -// limit. This is also used to test performance (number of reactions per -// second). Correct output for this 1, 2, 3, 4. Failure for this test is failing -// to halt or getting the wrong data. +// Test that the stop function can be used to internally to impose a a time limit. This is also used +// to test performance (number of reactions per second). Correct output for this 1, 2, 3, 4. Failure +// for this test is failing to halt or getting the wrong data. target Cpp { fast: true } diff --git a/test/Cpp/src/lib/Imported.lf b/test/Cpp/src/lib/Imported.lf index 96a540c171..9c29c48be2 100644 --- a/test/Cpp/src/lib/Imported.lf +++ b/test/Cpp/src/lib/Imported.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target Cpp import ImportedAgain from "ImportedAgain.lf" diff --git a/test/Cpp/src/lib/ImportedAgain.lf b/test/Cpp/src/lib/ImportedAgain.lf index 048bdef364..83495dc480 100644 --- a/test/Cpp/src/lib/ImportedAgain.lf +++ b/test/Cpp/src/lib/ImportedAgain.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target Cpp reactor ImportedAgain { diff --git a/test/Cpp/src/lib/ImportedComposition.lf b/test/Cpp/src/lib/ImportedComposition.lf index 3619ff7ed8..97ddb436d0 100644 --- a/test/Cpp/src/lib/ImportedComposition.lf +++ b/test/Cpp/src/lib/ImportedComposition.lf @@ -1,8 +1,8 @@ /** * @author Maiko Brants TU Dresden * - * This is used by the test for the ability to import a reactor definition that - * itself imports a reactor definition. + * This is used by the test for the ability to import a reactor definition that itself imports a + * reactor definition. * * modeled after the C version of this test */ diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index 3c1cc13631..572e00d6c4 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -8,10 +8,9 @@ target Cpp /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { output out: int diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index 07da948506..417d5b325e 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport - * input of the same reactors in the bank so that each reactor in the bank - * receives the output produced by itself and each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport input of the same + * reactors in the bank so that each reactor in the bank receives the output produced by itself and + * each other reactor. * * @author Edward A. Lee * @author Christian Menard diff --git a/test/Cpp/src/multiport/IndexIntoMultiportInput.lf b/test/Cpp/src/multiport/IndexIntoMultiportInput.lf index 26f9275b56..068724b781 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportInput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportInput.lf @@ -2,9 +2,8 @@ * This test was first described by Peter Donovan in * https://github.com/lf-lang/lingua-franca/issues/1321 * - * It simply tests if passthrough connections work as expected in the C++ - * target. Such a connection directly connects an input to an output of the same - * reactor, without any reactions in between. + * It simply tests if passthrough connections work as expected in the C++ target. Such a connection + * directly connects an input to an output of the same reactor, without any reactions in between. */ target Cpp diff --git a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf index 964e2e7095..dd5a5759e1 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf @@ -2,9 +2,8 @@ * This test was first described by Peter Donovan in * https://github.com/lf-lang/lingua-franca/issues/1321 * - * It simply tests if passthrough connections work as expected in the C++ - * target. Such a connection directly connects an input to an output of the same - * reactor, without any reactions in between. + * It simply tests if passthrough connections work as expected in the C++ target. Such a connection + * directly connects an input to an output of the same reactor, without any reactions in between. */ target Cpp diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index b7339a9184..d1cf2a9d36 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf index 673ef6889a..1b4c53bf83 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index fe27c74f35..1786e5292d 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index fae914b609..75eadf542b 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input, where the former is a hierarchical -// reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index 39fce6f8ff..af2f4eab18 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version fo the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf index f9cef6a676..1c520d6759 100644 --- a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index 573a0e06da..ff641336ae 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -1,6 +1,5 @@ -// Check multiport output to multiport input, where the latter is a hierarchical -// reactor. Note that the destination reactor has width wider than the sender, -// so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +// the destination reactor has width wider than the sender, so one input is dangling. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToMultiportArray.lf b/test/Cpp/src/multiport/MultiportToMultiportArray.lf index 6c96d17150..0da837bb17 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportArray.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportArray.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToPort.lf b/test/Cpp/src/multiport/MultiportToPort.lf index c2b0bd66ef..48804f575e 100644 --- a/test/Cpp/src/multiport/MultiportToPort.lf +++ b/test/Cpp/src/multiport/MultiportToPort.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf index 6fa6dbb87b..c4bdb80d9d 100644 --- a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf @@ -1,5 +1,4 @@ -// Test reacting to and reading outputs from a contained reactor bank with a -// multiport +// Test reacting to and reading outputs from a contained reactor bank with a multiport target Cpp reactor Contained(bank_index: size_t = 0) { diff --git a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf index 18179b9086..db27bf5a6f 100644 --- a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf @@ -1,5 +1,4 @@ -// Test reacting to and reading outputs from a contained reactor bank in various -// permutations. +// Test reacting to and reading outputs from a contained reactor bank in various permutations. target Cpp reactor Contained(bank_index: size_t = 0) { diff --git a/test/Cpp/src/target/BraceAndParenInitialization.lf b/test/Cpp/src/target/BraceAndParenInitialization.lf index 003b6d509d..488a2719f5 100644 --- a/test/Cpp/src/target/BraceAndParenInitialization.lf +++ b/test/Cpp/src/target/BraceAndParenInitialization.lf @@ -6,10 +6,8 @@ reactor Foo( param_list_3: std::vector(4, 2), // list containing [2,2,2,2] param_list_4: std::vector{4, 2} // list containing [4,2] ) { - // list containing [42,42,42,42,42,42] - state state_list_1: std::vector(6, 42) - // list containing [6,42] - state state_list_2: std::vector{6, 42} + state state_list_1: std::vector(6, 42) // list containing [42,42,42,42,42,42] + state state_list_2: std::vector{6, 42} // list containing [6,42] reaction(startup) {= std::cerr << "Hello!\n"; diff --git a/test/Cpp/src/target/CMakeInclude.lf b/test/Cpp/src/target/CMakeInclude.lf index a6e883a2d9..b1adacc966 100644 --- a/test/Cpp/src/target/CMakeInclude.lf +++ b/test/Cpp/src/target/CMakeInclude.lf @@ -1,6 +1,5 @@ /** - * Test that cmake-include is working correctly. The failure for this test is - * failure to compile. + * Test that cmake-include is working correctly. The failure for this test is failure to compile. */ target Cpp { cmake-include: [ diff --git a/test/Cpp/src/target/PreambleFile.lf b/test/Cpp/src/target/PreambleFile.lf index 9dc6dcc748..db9ff5e712 100644 --- a/test/Cpp/src/target/PreambleFile.lf +++ b/test/Cpp/src/target/PreambleFile.lf @@ -1,7 +1,7 @@ target Cpp -// These declarations are used by multiple reactors within this file and should -// be placed in a header. This goes to PreampleFile/preamble.hh. +// These declarations are used by multiple reactors within this file and should be placed in a +// header. This goes to PreampleFile/preamble.hh. public preamble {= struct MyStruct { int foo; @@ -11,9 +11,8 @@ public preamble {= int add_42(int i); =} -// This definition is used by multiple reactors within this file. Since the same -// function can only be defined once, this needs to go to a source file. This -// goes to PreampleFile/preamble.cc. +// This definition is used by multiple reactors within this file. Since the same function can only +// be defined once, this needs to go to a source file. This goes to PreampleFile/preamble.cc. private preamble {= int add_42(int i) { return i + 42; @@ -30,9 +29,8 @@ reactor Source { } reactor Print { - // This helper function is only used within the Print reactor and is - // therefore part of its private interface. This goes to - // PreambleFile/Print.cc + // This helper function is only used within the Print reactor and is therefore part of its + // private interface. This goes to PreambleFile/Print.cc private preamble {= void print(const MyStruct& x) { std::cout << "Received " << x.foo << " and '" << x.bar << "'\n"; diff --git a/test/Python/src/ActionWithNoReaction.lf b/test/Python/src/ActionWithNoReaction.lf index c9ed8b1f77..1b0ee74893 100644 --- a/test/Python/src/ActionWithNoReaction.lf +++ b/test/Python/src/ActionWithNoReaction.lf @@ -1,6 +1,5 @@ -# This checks that action can be created even if there is no reaction. This test -# passes merely by compiling and executing without a segfault. Its other -# functionality is tested by other tests. +# This checks that action can be created even if there is no reaction. This test passes merely by +# compiling and executing without a segfault. Its other functionality is tested by other tests. target Python { fast: true, timeout: 3 sec diff --git a/test/Python/src/After.lf b/test/Python/src/After.lf index 0c8b931543..8ed92b2061 100644 --- a/test/Python/src/After.lf +++ b/test/Python/src/After.lf @@ -1,5 +1,4 @@ -# This checks that the after keyword adjusts logical time, not using physical -# time. +# This checks that the after keyword adjusts logical time, not using physical time. target Python { fast: false, timeout: 3 sec diff --git a/test/Python/src/AfterCycles.lf b/test/Python/src/AfterCycles.lf index cd0f0dd98e..e062d013ee 100644 --- a/test/Python/src/AfterCycles.lf +++ b/test/Python/src/AfterCycles.lf @@ -1,5 +1,5 @@ -# This tests that "after" does not introduce spurious cycles. Success if running -# without detected a cycle. +# This tests that "after" does not introduce spurious cycles. Success if running without detected a +# cycle. target Python reactor Source { diff --git a/test/Python/src/ArrayAsType.lf b/test/Python/src/ArrayAsType.lf index dc3b2f6e26..37d5d66cf7 100644 --- a/test/Python/src/ArrayAsType.lf +++ b/test/Python/src/ArrayAsType.lf @@ -1,5 +1,5 @@ -# Source produces a statically allocated array, which it passes to Print. The -# destination references the array directly. +# Source produces a statically allocated array, which it passes to Print. The destination references +# the array directly. target Python reactor Source { diff --git a/test/Python/src/ArrayFree.lf b/test/Python/src/ArrayFree.lf index 2ea2777c12..147e9537a8 100644 --- a/test/Python/src/ArrayFree.lf +++ b/test/Python/src/ArrayFree.lf @@ -1,7 +1,7 @@ -# Source produces a dynamically allocated array, which it passes to Free. Free -# requests a writable copy, which, instead of copying, it just gets ownership of -# the original array. It then does nothing further with it. This test checks -# that the memory gets freed automatically even with the mutable input. +# Source produces a dynamically allocated array, which it passes to Free. Free requests a writable +# copy, which, instead of copying, it just gets ownership of the original array. It then does +# nothing further with it. This test checks that the memory gets freed automatically even with the +# mutable input. target Python import Source, Print from "ArrayPrint.lf" diff --git a/test/Python/src/ArrayParallel.lf b/test/Python/src/ArrayParallel.lf index 1ae1a0ac77..5e75898f14 100644 --- a/test/Python/src/ArrayParallel.lf +++ b/test/Python/src/ArrayParallel.lf @@ -1,6 +1,6 @@ -# Source allocates an array dynamically and then sends it to two reactors, each -# of which want to modify it. NOTE: Ideally, only one copy would be made, but -# this requires modifying the precedence graph between reactions. +# Source allocates an array dynamically and then sends it to two reactors, each of which want to +# modify it. NOTE: Ideally, only one copy would be made, but this requires modifying the precedence +# graph between reactions. target Python import Scale from "ArrayScale.lf" diff --git a/test/Python/src/ArrayPrint.lf b/test/Python/src/ArrayPrint.lf index 4420311b93..254d9c352d 100644 --- a/test/Python/src/ArrayPrint.lf +++ b/test/Python/src/ArrayPrint.lf @@ -1,5 +1,5 @@ -# Source produces a dynamically allocated array, which it passes to Print. -# Reference counting ensures that the array is freed. +# Source produces a dynamically allocated array, which it passes to Print. Reference counting +# ensures that the array is freed. target Python reactor Source { diff --git a/test/Python/src/ArrayScale.lf b/test/Python/src/ArrayScale.lf index 2b69aebe77..10f5a747e6 100644 --- a/test/Python/src/ArrayScale.lf +++ b/test/Python/src/ArrayScale.lf @@ -1,7 +1,6 @@ -# Source produces a dynamically allocated array, which it passes to Scale. Scale -# requests a writable copy, which, instead of copying, it just gets ownership of -# the original array. It modifies it and passes it to Print. It gets freed after -# Print is done with it. +# Source produces a dynamically allocated array, which it passes to Scale. Scale requests a writable +# copy, which, instead of copying, it just gets ownership of the original array. It modifies it and +# passes it to Print. It gets freed after Print is done with it. target Python import Print, Source from "ArrayPrint.lf" diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index d1bef93ed2..a5b9cac96f 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -1,5 +1,4 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { fast: true, timeout: 10 sec diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index 00b95e3ab9..74217559db 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -1,5 +1,4 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { fast: true, timeout: 10 sec diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index 4b0e4a38c9..aeaa9e30bb 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -1,5 +1,4 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { fast: true, timeout: 10 sec diff --git a/test/Python/src/DanglingOutput.lf b/test/Python/src/DanglingOutput.lf index 03709fef13..7894f73835 100644 --- a/test/Python/src/DanglingOutput.lf +++ b/test/Python/src/DanglingOutput.lf @@ -1,5 +1,5 @@ -# This tests that an output that is not connected to anything does not result in -# a compilation error. Passing the test is just compiling and running. +# This tests that an output that is not connected to anything does not result in a compilation +# error. Passing the test is just compiling and running. target Python reactor Source { diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index ceab2b28e2..154a755327 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -1,6 +1,5 @@ -# This example illustrates local deadline handling. Even numbers are sent by the -# Source immediately, whereas odd numbers are sent after a big enough delay to -# violate the deadline. +# This example illustrates local deadline handling. Even numbers are sent by the Source immediately, +# whereas odd numbers are sent after a big enough delay to violate the deadline. target Python { timeout: 6 sec } diff --git a/test/Python/src/DeadlineHandledAbove.lf b/test/Python/src/DeadlineHandledAbove.lf index 1259253cea..39c927ee08 100644 --- a/test/Python/src/DeadlineHandledAbove.lf +++ b/test/Python/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -# Test a deadline where the deadline violation produces an output and the -# container reacts to that output. +# Test a deadline where the deadline violation produces an output and the container reacts to that +# output. target Python preamble {= import time =} diff --git a/test/Python/src/DelayArrayWithAfter.lf b/test/Python/src/DelayArrayWithAfter.lf index 1e6ac1f317..52245e314f 100644 --- a/test/Python/src/DelayArrayWithAfter.lf +++ b/test/Python/src/DelayArrayWithAfter.lf @@ -1,5 +1,4 @@ -# This tests transport of dynamically allocated arrays over connections with -# 'after'. +# This tests transport of dynamically allocated arrays over connections with 'after'. target Python { timeout: 5 sec, fast: true diff --git a/test/Python/src/DelayString.lf b/test/Python/src/DelayString.lf index d1201dec02..e7e7531888 100644 --- a/test/Python/src/DelayString.lf +++ b/test/Python/src/DelayString.lf @@ -1,5 +1,4 @@ -# This tests actions with immutable payloads that are neither malloc'd nor -# freed. +# This tests actions with immutable payloads that are neither malloc'd nor freed. target Python reactor DelayString2(delay = 100 msec) { diff --git a/test/Python/src/DoubleInvocation.lf b/test/Python/src/DoubleInvocation.lf index aaecfa31cb..78d31883ea 100644 --- a/test/Python/src/DoubleInvocation.lf +++ b/test/Python/src/DoubleInvocation.lf @@ -1,8 +1,7 @@ -# This illustrates a very strange bug that showed up and has now been fixed. -# This test ensures it does not reappear. At logical time zero, the two Print -# reactors used to be fired twice each at the same logical time. They should -# only be fired once. This behavior was oddly eliminated by either of the -# following actions, neither of which should affect this behavior: +# This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +# does not reappear. At logical time zero, the two Print reactors used to be fired twice each at the +# same logical time. They should only be fired once. This behavior was oddly eliminated by either of +# the following actions, neither of which should affect this behavior: # * Removing the startup reaction in Print. # * Sending only position, not velocity from Ball. target Python { diff --git a/test/Python/src/DoubleReaction.lf b/test/Python/src/DoubleReaction.lf index c20a032a9a..7af73da6ec 100644 --- a/test/Python/src/DoubleReaction.lf +++ b/test/Python/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -# Test that two simultaneous inputs that trigger a reaction trigger it only -# once. Correct output for this 2, 4, 6, 8, etc. +# Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output for +# this 2, 4, 6, 8, etc. target Python { timeout: 10 sec, fast: true diff --git a/test/Python/src/GetTime.lf b/test/Python/src/GetTime.lf index 7829cb0db5..8c22851395 100644 --- a/test/Python/src/GetTime.lf +++ b/test/Python/src/GetTime.lf @@ -1,5 +1,5 @@ -# This file includes code documented on the Wiki. For this test, success is just -# compiling and running. +# This file includes code documented on the Wiki. For this test, success is just compiling and +# running. target Python { timeout: 2 sec, fast: false diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index 271ed180ca..8e60df4ae5 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -1,8 +1,7 @@ -# This test checks that logical time is incremented an appropriate amount as a -# result of an invocation of the schedule() function at runtime. It also -# performs various smoke tests of timing aligned reactions. The first instance -# has a period of 4 seconds, the second of 2 seconds, and the third (composite) -# or 1 second. +# This test checks that logical time is incremented an appropriate amount as a result of an +# invocation of the schedule() function at runtime. It also performs various smoke tests of timing +# aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, and the +# third (composite) or 1 second. target Python { timeout: 10 sec, fast: true @@ -43,10 +42,7 @@ reactor Inside(period = 1 sec, message = "Composite default message.") { } main reactor Hello { - first_instance = new Reschedule( - period = 4 sec, - message = "Hello from first_instance." - ) + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance.") second_instance = new Reschedule(message = "Hello from second_instance.") composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/Python/src/Import.lf b/test/Python/src/Import.lf index 95844fa5c0..4c17403320 100644 --- a/test/Python/src/Import.lf +++ b/test/Python/src/Import.lf @@ -1,5 +1,4 @@ -# This tests the ability to import a reactor definition that itself imports a -# reactor definition. +# This tests the ability to import a reactor definition that itself imports a reactor definition. target Python import Imported from "lib/Imported.lf" diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 369fbcab44..8063e7c938 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -1,5 +1,4 @@ -# This tests the ability to import a reactor definition that itself imports a -# reactor definition. +# This tests the ability to import a reactor definition that itself imports a reactor definition. target Python import ImportedComposition from "lib/ImportedComposition.lf" diff --git a/test/Python/src/ImportRenamed.lf b/test/Python/src/ImportRenamed.lf index e9db8a2afb..ab6f1c8078 100644 --- a/test/Python/src/ImportRenamed.lf +++ b/test/Python/src/ImportRenamed.lf @@ -1,5 +1,4 @@ -# This tests the ability to import a reactor definition that itself imports a -# reactor definition. +# This tests the ability to import a reactor definition that itself imports a reactor definition. target Python import Imported as X from "lib/Imported.lf" diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index a9e39829eb..57a4d2efbb 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -1,12 +1,11 @@ target Python { - # Set keepalive to false since this is a test and schedule is called on a - # physical action from within a reaction. This is one of the special rare - # cases where the user might want to manually override keepalive. + # Set keepalive to false since this is a test and schedule is called on a physical action from + # within a reaction. This is one of the special rare cases where the user might want to manually + # override keepalive. keepalive: false } -# That's the stuff that shall be generated for the after -reactor GeneratedDelay { +reactor GeneratedDelay { # That's the stuff that shall be generated for the after input y_in output y_out state y_state = 0 diff --git a/test/Python/src/MovingAverage.lf b/test/Python/src/MovingAverage.lf index 3dbd5636c3..963cb72db1 100644 --- a/test/Python/src/MovingAverage.lf +++ b/test/Python/src/MovingAverage.lf @@ -1,6 +1,5 @@ -# Demonstration of a state variable that is a list. The MovingAverage reactor -# computes the moving average of the last four inputs and produces that as -# output. The source is a counting sequence. +# Demonstration of a state variable that is a list. The MovingAverage reactor computes the moving +# average of the last four inputs and produces that as output. The source is a counting sequence. target Python { timeout: 1 sec, fast: true diff --git a/test/Python/src/MultipleContained.lf b/test/Python/src/MultipleContained.lf index 27950ccd88..ae9cb0e96b 100644 --- a/test/Python/src/MultipleContained.lf +++ b/test/Python/src/MultipleContained.lf @@ -1,5 +1,4 @@ -# Test that a reaction can react to and send two multiple ports of a contained -# reactor. +# Test that a reaction can react to and send two multiple ports of a contained reactor. target Python reactor Contained { diff --git a/test/Python/src/PingPong.lf b/test/Python/src/PingPong.lf index f5f80511ae..72c5e19563 100644 --- a/test/Python/src/PingPong.lf +++ b/test/Python/src/PingPong.lf @@ -1,22 +1,19 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ diff --git a/test/Python/src/Preamble.lf b/test/Python/src/Preamble.lf index c2bd38ed6b..e158ea03b3 100644 --- a/test/Python/src/Preamble.lf +++ b/test/Python/src/Preamble.lf @@ -1,5 +1,5 @@ -# Preambles are put inside the Python reactor class Therefore, accessing them -# requires the use of self. +# Preambles are put inside the Python reactor class Therefore, accessing them requires the use of +# self. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/ReadOutputOfContainedReactor.lf b/test/Python/src/ReadOutputOfContainedReactor.lf index 1cb73667ce..4052d70e77 100644 --- a/test/Python/src/ReadOutputOfContainedReactor.lf +++ b/test/Python/src/ReadOutputOfContainedReactor.lf @@ -1,5 +1,4 @@ -# Test reacting to and reading outputs from a contained reactor in various -# permutations. +# Test reacting to and reading outputs from a contained reactor in various permutations. target Python reactor Contained { diff --git a/test/Python/src/ScheduleLogicalAction.lf b/test/Python/src/ScheduleLogicalAction.lf index 3f99c65777..b60471f676 100644 --- a/test/Python/src/ScheduleLogicalAction.lf +++ b/test/Python/src/ScheduleLogicalAction.lf @@ -1,5 +1,5 @@ -# This checks that a logical action is scheduled the specified logical time -# after the current logical time. +# This checks that a logical action is scheduled the specified logical time after the current +# logical time. target Python { fast: true, timeout: 3 sec diff --git a/test/Python/src/SendingInside.lf b/test/Python/src/SendingInside.lf index 8bcc66c005..e6645fbc44 100644 --- a/test/Python/src/SendingInside.lf +++ b/test/Python/src/SendingInside.lf @@ -1,5 +1,5 @@ -# This tests a reactor that contains another reactor and also has its own -# reaction that routes inputs to the contained reactor. +# This tests a reactor that contains another reactor and also has its own reaction that routes +# inputs to the contained reactor. target Python { timeout: 10 sec, fast: true diff --git a/test/Python/src/SetArray.lf b/test/Python/src/SetArray.lf index 4766d529f7..8906312c04 100644 --- a/test/Python/src/SetArray.lf +++ b/test/Python/src/SetArray.lf @@ -1,6 +1,5 @@ -# This tests passing lists as port values This tests the use of the -# "polymorphic" delay reactor on a struct. It delays by a logical time any -# pointer datatype. +# This tests passing lists as port values This tests the use of the "polymorphic" delay reactor on a +# struct. It delays by a logical time any pointer datatype. target Python reactor Source { diff --git a/test/Python/src/SimpleDeadline.lf b/test/Python/src/SimpleDeadline.lf index a714124129..f1065e9508 100644 --- a/test/Python/src/SimpleDeadline.lf +++ b/test/Python/src/SimpleDeadline.lf @@ -1,6 +1,5 @@ -# Test local deadline, where a deadline is associated with a reaction -# definition. This test triggers a reaction exactly once with a deadline -# violation. +# Test local deadline, where a deadline is associated with a reaction definition. This test triggers +# a reaction exactly once with a deadline violation. target Python reactor Deadline(threshold = 100 msec) { diff --git a/test/Python/src/SlowingClock.lf b/test/Python/src/SlowingClock.lf index 972421437a..72f6657ffb 100644 --- a/test/Python/src/SlowingClock.lf +++ b/test/Python/src/SlowingClock.lf @@ -1,7 +1,7 @@ /** - * Output events at logical times 100, 300, 600, and 1000 msec after the start - * time. This uses a logical action with a minimum delay of 100 msec and - * additional delays provided as arguments to the schedule() function. + * Output events at logical times 100, 300, 600, and 1000 msec after the start time. This uses a + * logical action with a minimum delay of 100 msec and additional delays provided as arguments to + * the schedule() function. */ target Python { timeout: 1 sec, diff --git a/test/Python/src/Stride.lf b/test/Python/src/Stride.lf index 86c68bab5a..4d1ec22218 100644 --- a/test/Python/src/Stride.lf +++ b/test/Python/src/Stride.lf @@ -1,5 +1,5 @@ -# This example illustrates state variables and parameters on the wiki. For this -# test, success is just compiling and running. +# This example illustrates state variables and parameters on the wiki. For this test, success is +# just compiling and running. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/StructAsState.lf b/test/Python/src/StructAsState.lf index b6f38f8589..dc6bc3c70b 100644 --- a/test/Python/src/StructAsState.lf +++ b/test/Python/src/StructAsState.lf @@ -1,5 +1,4 @@ -# Check that a state variable can have a statically initialized struct as a -# value. +# Check that a state variable can have a statically initialized struct as a value. target Python main reactor StructAsState { diff --git a/test/Python/src/StructPrint.lf b/test/Python/src/StructPrint.lf index 3c0138f937..414e87c64d 100644 --- a/test/Python/src/StructPrint.lf +++ b/test/Python/src/StructPrint.lf @@ -1,5 +1,5 @@ -# Source produces a dynamically allocated class object, which it passes to -# Print. Reference counting ensures that the struct is freed. +# Source produces a dynamically allocated class object, which it passes to Print. Reference counting +# ensures that the struct is freed. target Python { files: ["include/hello.py"] } diff --git a/test/Python/src/TestForPreviousOutput.lf b/test/Python/src/TestForPreviousOutput.lf index 9e8ad43c26..1c17308c04 100644 --- a/test/Python/src/TestForPreviousOutput.lf +++ b/test/Python/src/TestForPreviousOutput.lf @@ -1,5 +1,5 @@ -# This tests the mechanism for testing whether a previous reaction has produced -# a given output. The output should always be 42. +# This tests the mechanism for testing whether a previous reaction has produced a given output. The +# output should always be 42. target Python reactor Source { diff --git a/test/Python/src/TimeLimit.lf b/test/Python/src/TimeLimit.lf index beb7602db9..95120083d8 100644 --- a/test/Python/src/TimeLimit.lf +++ b/test/Python/src/TimeLimit.lf @@ -1,6 +1,5 @@ -# Test that the stop function can be used to internally impose a a time limit. -# Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt -# or getting the wrong data. +# Test that the stop function can be used to internally impose a a time limit. Correct output for +# this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. target Python { fast: true } diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf index b65f732652..a4ae089e46 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf @@ -1,7 +1,4 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target Python { timeout: 1 sec, fast: true diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf index b9a9184296..7f94ab374a 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,7 +1,4 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target Python { timeout: 1 sec, fast: true diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index 5ef4167bed..a85905c5fd 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -1,7 +1,6 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test - * periodically creates a concurrent Python thread that schedule a physical - * action twice. + * Test asynchronous callbacks that trigger a physical action. This test periodically creates a + * concurrent Python thread that schedule a physical action twice. */ target Python { timeout: 2 sec diff --git a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf index 4e481d1d34..a51ff9acdb 100644 --- a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf +++ b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf @@ -1,11 +1,11 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test creates - * a concurrent Python thread that schedule a physical action twice. + * Test asynchronous callbacks that trigger a physical action. This test creates a concurrent Python + * thread that schedule a physical action twice. * - * There are no timers in this test to drive the logical time forward. This is - * important in the Python target since the user Python threads should be - * allowed to execute independently of the underlying C core runtime, without - * the C runtime polling the Python context with a reaction to a timer. + * There are no timers in this test to drive the logical time forward. This is important in the + * Python target since the user Python threads should be allowed to execute independently of the + * underlying C core runtime, without the C runtime polling the Python context with a reaction to a + * timer. */ target Python { timeout: 2 sec diff --git a/test/Python/src/docker/PingPongContainerized.lf b/test/Python/src/docker/PingPongContainerized.lf index 0346162390..4b9c772e2e 100644 --- a/test/Python/src/docker/PingPongContainerized.lf +++ b/test/Python/src/docker/PingPongContainerized.lf @@ -1,22 +1,19 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index 5f8a348d24..c2f9f7b0d5 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python { diff --git a/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf b/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf index d6605a2e6e..1aa2b1e640 100644 --- a/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf +++ b/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf @@ -1,7 +1,6 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federte on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federte on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni */ diff --git a/test/Python/src/federated/BroadcastFeedback.lf b/test/Python/src/federated/BroadcastFeedback.lf index 75d313e61d..06fcd95037 100644 --- a/test/Python/src/federated/BroadcastFeedback.lf +++ b/test/Python/src/federated/BroadcastFeedback.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target Python { timeout: 1 sec } diff --git a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf index ad2a11c10c..d3e371b037 100644 --- a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target Python { timeout: 1 sec } diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index cf9b6d6b54..5039f3f375 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -1,6 +1,6 @@ /** - * Check whether the internally generated network and control reactions - * introduce a cycle or not. The failure for this test is not being compiled. + * Check whether the internally generated network and control reactions introduce a cycle or not. + * The failure for this test is not being compiled. * @author Edward A. Lee */ target Python diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 48ff7a4ca7..a56a8f07ba 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -1,8 +1,7 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed about lost messages. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed about lost messages. * * The test fails if the federation does not exit. */ diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 4eb881694f..d065783f5a 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -1,11 +1,10 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed. * - * The test fails if the federation does not exit amenably. This variant has a - * physical connection between source and destination. + * The test fails if the federation does not exit amenably. This variant has a physical connection + * between source and destination. */ target Python { timeout: 1 msec, diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index 7713256520..6492c4fa32 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python { diff --git a/test/Python/src/federated/DistributedCountDecentralized.lf b/test/Python/src/federated/DistributedCountDecentralized.lf index e86adf9946..92cae03850 100644 --- a/test/Python/src/federated/DistributedCountDecentralized.lf +++ b/test/Python/src/federated/DistributedCountDecentralized.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ # reason for failing: in_.intended_tag are not supported in python target @@ -41,6 +40,5 @@ reactor Print { federated reactor DistributedCountDecentralized { c = new Count() p = new Print() - # Indicating a 'logical' connection with a large enough delay. - c.out -> p.in_ after 200 msec + c.out -> p.in_ after 200 msec # Indicating a 'logical' connection with a large enough delay. } diff --git a/test/Python/src/federated/DistributedCountPhysical.lf b/test/Python/src/federated/DistributedCountPhysical.lf index 69bc2faee9..c6ef7e2425 100644 --- a/test/Python/src/federated/DistributedCountPhysical.lf +++ b/test/Python/src/federated/DistributedCountPhysical.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf index 105413d0a0..065cfa83c4 100644 --- a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf index 0008479138..1b73f7e8e6 100644 --- a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedDoublePort.lf b/test/Python/src/federated/DistributedDoublePort.lf index 9eb24209e6..fe0a71dcc1 100644 --- a/test/Python/src/federated/DistributedDoublePort.lf +++ b/test/Python/src/federated/DistributedDoublePort.lf @@ -1,7 +1,6 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federte on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federte on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni */ @@ -40,9 +39,7 @@ reactor Print { self.sys.exit(1) =} - reaction(shutdown) {= - print("SUCCESS: messages were at least one microstep apart.") - =} + reaction(shutdown) {= print("SUCCESS: messages were at least one microstep apart.") =} } federated reactor DistributedDoublePort { diff --git a/test/Python/src/federated/DistributedLoopedAction.lf b/test/Python/src/federated/DistributedLoopedAction.lf index 8f71d15363..a7564d5b28 100644 --- a/test/Python/src/federated/DistributedLoopedAction.lf +++ b/test/Python/src/federated/DistributedLoopedAction.lf @@ -1,6 +1,5 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni */ @@ -18,8 +17,7 @@ reactor Receiver(take_a_break_after = 10, break_interval = 400 msec) { state breaks = 0 timer t(0, 1 msec) # This will impact the performance - # but forces the logical time to advance Comment this line for a more - # sensible log output. + # but forces the logical time to advance Comment this line for a more sensible log output. reaction(in_) {= print("At tag ({}, {}) received value {}.".format( lf.time.logical_elapsed(), diff --git a/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf b/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf index 626a416480..0cf1b5d22e 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf @@ -1,6 +1,5 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni */ diff --git a/test/Python/src/federated/DistributedMultiportToken.lf b/test/Python/src/federated/DistributedMultiportToken.lf index 284e1c21a3..974f6f62fa 100644 --- a/test/Python/src/federated/DistributedMultiportToken.lf +++ b/test/Python/src/federated/DistributedMultiportToken.lf @@ -1,5 +1,5 @@ -# Check multiport connections between federates where the message is carried by -# a Token (in this case, with an array of char). +# Check multiport connections between federates where the message is carried by a Token (in this +# case, with an array of char). target Python { timeout: 1 sec, coordination: centralized diff --git a/test/Python/src/federated/DistributedStructParallel.lf b/test/Python/src/federated/DistributedStructParallel.lf index 300eb5fe9b..34a2f84e32 100644 --- a/test/Python/src/federated/DistributedStructParallel.lf +++ b/test/Python/src/federated/DistributedStructParallel.lf @@ -1,5 +1,5 @@ -# Source allocates a class object and then sends it to two reactors, each of -# which want to modify it. +# Source allocates a class object and then sends it to two reactors, each of which want to modify +# it. target Python { files: ["../include/hello.py"], timeout: 2 secs diff --git a/test/Python/src/federated/DistributedStructPrint.lf b/test/Python/src/federated/DistributedStructPrint.lf index 2c727d318e..b424dabacf 100644 --- a/test/Python/src/federated/DistributedStructPrint.lf +++ b/test/Python/src/federated/DistributedStructPrint.lf @@ -1,5 +1,5 @@ -# Source produces a dynamically allocated class object, which it passes to -# Print. Reference counting ensures that the struct is freed. +# Source produces a dynamically allocated class object, which it passes to Print. Reference counting +# ensures that the struct is freed. target Python { files: ["../include/hello.py"], timeout: 2 sec diff --git a/test/Python/src/federated/DistributedStructScale.lf b/test/Python/src/federated/DistributedStructScale.lf index c733367493..88867178f0 100644 --- a/test/Python/src/federated/DistributedStructScale.lf +++ b/test/Python/src/federated/DistributedStructScale.lf @@ -1,5 +1,5 @@ -# Source produces a dynamically allocated class object, which it passes to -# Scale. Scale modifies it and passes it to Print. +# Source produces a dynamically allocated class object, which it passes to Scale. Scale modifies it +# and passes it to Print. target Python { files: ["../include/hello.py"], timeout: 2 sec diff --git a/test/Python/src/federated/HelloDistributed.lf b/test/Python/src/federated/HelloDistributed.lf index ef99c3f793..a56bef1062 100644 --- a/test/Python/src/federated/HelloDistributed.lf +++ b/test/Python/src/federated/HelloDistributed.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python @@ -40,8 +39,7 @@ reactor Destination { } federated reactor HelloDistributed at localhost { - # reaction(startup) {= print("Printing something in top-level federated - # reactor.") + # reaction(startup) {= print("Printing something in top-level federated reactor.") # =} Reactor s is in federate Source s = new Source() d = new Destination() # Reactor d is in federate Destination diff --git a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 2719fd57ba..d61fcc9100 100644 --- a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,7 +1,6 @@ /** - * This tests that the precedence order of reaction invocation is kept in the - * hierarchy of reactors when a feedback loop is present in centralized - * coordination. + * This tests that the precedence order of reaction invocation is kept in the hierarchy of reactors + * when a feedback loop is present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/PhysicalSTP.lf b/test/Python/src/federated/PhysicalSTP.lf index 5edc61df34..50ee659eb3 100644 --- a/test/Python/src/federated/PhysicalSTP.lf +++ b/test/Python/src/federated/PhysicalSTP.lf @@ -1,7 +1,4 @@ -/** - * This is a test that detects STP violations according to the physical time of - * message arrival. - */ +/** This is a test that detects STP violations according to the physical time of message arrival. */ target Python { timeout: 1900 msec, coordination: decentralized diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index 0f58cbf7db..0fc7cf3353 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -1,21 +1,19 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs - * and can be run on different machines. + * This is a distributed version, where Ping and Pong run in separate programs and can be run on + * different machines. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec Distributed: 53 seconds * - * There is no parallelism in this application, so it does not benefit from - * being being distributed. + * There is no parallelism in this application, so it does not benefit from being being distributed. * - * These measurements are total execution time, including startup and shutdown, - * of all three programs. + * These measurements are total execution time, including startup and shutdown, of all three + * programs. * * @author Edward A. Lee */ diff --git a/test/Python/src/lib/Imported.lf b/test/Python/src/lib/Imported.lf index 71d7558383..f59f1e9dee 100644 --- a/test/Python/src/lib/Imported.lf +++ b/test/Python/src/lib/Imported.lf @@ -1,5 +1,5 @@ -# This is used by the test for the ability to import a reactor definition that -# itself imports a reactor definition. +# This is used by the test for the ability to import a reactor definition that itself imports a +# reactor definition. target Python import ImportedAgain from "./ImportedAgain.lf" diff --git a/test/Python/src/lib/ImportedAgain.lf b/test/Python/src/lib/ImportedAgain.lf index cb877da53c..f29a5e6c83 100644 --- a/test/Python/src/lib/ImportedAgain.lf +++ b/test/Python/src/lib/ImportedAgain.lf @@ -1,5 +1,5 @@ -# This is used by the test for the ability to import a reactor definition that -# itself imports a reactor definition. +# This is used by the test for the ability to import a reactor definition that itself imports a +# reactor definition. target Python reactor ImportedAgain { # import Imported from "Imported.lf" diff --git a/test/Python/src/lib/ImportedComposition.lf b/test/Python/src/lib/ImportedComposition.lf index 56010ce509..be1cdfb1a8 100644 --- a/test/Python/src/lib/ImportedComposition.lf +++ b/test/Python/src/lib/ImportedComposition.lf @@ -1,5 +1,5 @@ -# This is used by the test for the ability to import a reactor definition that -# itself imports a reactor definition. +# This is used by the test for the ability to import a reactor definition that itself imports a +# reactor definition. target Python reactor Gain { diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index 9d4048d0ea..674256ea45 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -6,10 +6,9 @@ target Python /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after = 10, break_interval = 400 msec) { output out diff --git a/test/Python/src/lib/TestCount.lf b/test/Python/src/lib/TestCount.lf index de611cbc69..eb214fe25d 100644 --- a/test/Python/src/lib/TestCount.lf +++ b/test/Python/src/lib/TestCount.lf @@ -1,7 +1,6 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. diff --git a/test/Python/src/lib/TestCountMultiport.lf b/test/Python/src/lib/TestCountMultiport.lf index c30572e4d5..d584401bfa 100644 --- a/test/Python/src/lib/TestCountMultiport.lf +++ b/test/Python/src/lib/TestCountMultiport.lf @@ -1,13 +1,12 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. This version has a multiport input, and each - * input is expected to be present and incremented over the previous input. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. This version has + * a multiport input, and each input is expected to be present and incremented over the previous + * input. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. - * @param num_inputs The number of inputs expected on each channel. Default is - * 1. + * @param num_inputs The number of inputs expected on each channel. Default is 1. */ target Python diff --git a/test/Python/src/modal_models/BanksModalStateReset.lf b/test/Python/src/modal_models/BanksModalStateReset.lf index f96a7bd638..00a1a7ca4f 100644 --- a/test/Python/src/modal_models/BanksModalStateReset.lf +++ b/test/Python/src/modal_models/BanksModalStateReset.lf @@ -1,7 +1,4 @@ -/** - * Modal Reactor Test. Tests reset of state variables in modes with banks of - * reactors. - */ +/** Modal Reactor Test. Tests reset of state variables in modes with banks of reactors. */ target Python { fast: false, timeout: 4 sec @@ -48,8 +45,7 @@ main reactor { reset2.count2 -> test.events - # Trigger mode change (separately because of #1278) - reaction(stepper) -> reset1.next {= + reaction(stepper) -> reset1.next {= # Trigger mode change (separately because of #1278) for i in range(len(reset1)): reset1[i].next.set(True) =} diff --git a/test/Python/src/modal_models/ConvertCaseTest.lf b/test/Python/src/modal_models/ConvertCaseTest.lf index f3bdee59fe..3f31a7100b 100644 --- a/test/Python/src/modal_models/ConvertCaseTest.lf +++ b/test/Python/src/modal_models/ConvertCaseTest.lf @@ -113,9 +113,7 @@ main reactor { history_processor.discard.set(True) =} - reaction(reset_processor.converted) {= - print(f"Reset: {reset_processor.converted.value}") - =} + reaction(reset_processor.converted) {= print(f"Reset: {reset_processor.converted.value}") =} reaction(history_processor.converted) {= print(f"History: {history_processor.converted.value}") diff --git a/test/Python/src/modal_models/ModalActions.lf b/test/Python/src/modal_models/ModalActions.lf index b74f92f3c9..2d148e89ef 100644 --- a/test/Python/src/modal_models/ModalActions.lf +++ b/test/Python/src/modal_models/ModalActions.lf @@ -1,6 +1,6 @@ /** - * Modal Reactor Test. Tests actions, their suspension during mode inactivity - * and continuation of delays with history transitions. + * Modal Reactor Test. Tests actions, their suspension during mode inactivity and continuation of + * delays with history transitions. */ target Python { fast: false, @@ -90,6 +90,5 @@ main reactor { modal.action2_exec -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalCycleBreaker.lf b/test/Python/src/modal_models/ModalCycleBreaker.lf index 1ceb2eb5d0..d3af61d142 100644 --- a/test/Python/src/modal_models/ModalCycleBreaker.lf +++ b/test/Python/src/modal_models/ModalCycleBreaker.lf @@ -1,8 +1,8 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work - * if they are located in separate modes. + * Tests if connections in the same reactor that have the same destination work if they are located + * in separate modes. */ target Python { fast: false, @@ -16,9 +16,7 @@ reactor Modal { input in2 output out - # Defining reaction to in2 before in1 would cause cycle if no mode were - # present - mode Two { + mode Two { # Defining reaction to in2 before in1 would cause cycle if no mode were present timer wait(150 msec, 1 sec) reaction(in2) {= =} diff --git a/test/Python/src/modal_models/ModalNestedReactions.lf b/test/Python/src/modal_models/ModalNestedReactions.lf index d699adc737..67247ac12f 100644 --- a/test/Python/src/modal_models/ModalNestedReactions.lf +++ b/test/Python/src/modal_models/ModalNestedReactions.lf @@ -1,7 +1,4 @@ -/** - * Modal Reactor Test. Checks disabling of reactions indirectly nested in an - * inactive mode - */ +/** Modal Reactor Test. Checks disabling of reactions indirectly nested in an inactive mode */ target Python { fast: false, timeout: 2 sec diff --git a/test/Python/src/modal_models/ModalStartupShutdown.lf b/test/Python/src/modal_models/ModalStartupShutdown.lf index c7a868eeca..ba8439e276 100644 --- a/test/Python/src/modal_models/ModalStartupShutdown.lf +++ b/test/Python/src/modal_models/ModalStartupShutdown.lf @@ -137,6 +137,5 @@ main reactor { modal.shutdown5 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalStateReset.lf b/test/Python/src/modal_models/ModalStateReset.lf index 11b7425b63..d52161cede 100644 --- a/test/Python/src/modal_models/ModalStateReset.lf +++ b/test/Python/src/modal_models/ModalStateReset.lf @@ -87,6 +87,5 @@ main reactor { modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalStateResetAuto.lf b/test/Python/src/modal_models/ModalStateResetAuto.lf index 492e12259b..a8348592a5 100644 --- a/test/Python/src/modal_models/ModalStateResetAuto.lf +++ b/test/Python/src/modal_models/ModalStateResetAuto.lf @@ -83,6 +83,5 @@ main reactor { modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalTimers.lf b/test/Python/src/modal_models/ModalTimers.lf index 271a19ec38..8198e5dcb1 100644 --- a/test/Python/src/modal_models/ModalTimers.lf +++ b/test/Python/src/modal_models/ModalTimers.lf @@ -62,6 +62,5 @@ main reactor { modal.mode_switch, modal.timer1, modal.timer2 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index 3dd42f67ce..274d97a9f7 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -1,8 +1,8 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work - * if they are located in separate modes. + * Tests if connections in the same reactor that have the same destination work if they are located + * in separate modes. */ target Python { fast: false, @@ -66,9 +66,7 @@ main reactor { modal.count -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change - # Print - reaction(modal.count) {= print(modal.count.value) =} + reaction(modal.count) {= print(modal.count.value) =} # Print } diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 86f5668357..bda602904e 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -1,8 +1,8 @@ /** * Modal Reactor Test. * - * Tests if a connection and a reaction in the same reactor can have the same - * destination if they are located in separate modes. + * Tests if a connection and a reaction in the same reactor can have the same destination if they + * are located in separate modes. */ target Python { fast: false, @@ -23,9 +23,7 @@ reactor Modal { mode Two { counter2 = new Counter(period = 100 msec) - reaction(counter2.value) -> count {= - count.set(counter2.value.value * 10) - =} + reaction(counter2.value) -> count {= count.set(counter2.value.value * 10) =} reaction(next) -> history(One) {= One.set() =} } @@ -69,9 +67,7 @@ main reactor { modal.count -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change - # Print - reaction(modal.count) {= print(modal.count.value) =} + reaction(modal.count) {= print(modal.count.value) =} # Print } diff --git a/test/Python/src/multiport/BankReactionsInContainer.lf b/test/Python/src/multiport/BankReactionsInContainer.lf index 7316463c3d..c4eabf8d19 100644 --- a/test/Python/src/multiport/BankReactionsInContainer.lf +++ b/test/Python/src/multiport/BankReactionsInContainer.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target Python { timeout: 1 sec } diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 92d9363df5..092458f76d 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { timeout: 2 sec, fast: true @@ -8,9 +8,7 @@ target Python { reactor Source(check_override = 0, bank_index = 0) { output out - reaction(startup) -> out {= - out.set(self.bank_index * self.check_override) - =} + reaction(startup) -> out {= out.set(self.bank_index * self.check_override) =} } reactor Destination { diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index 27ecb3c80b..13cf078224 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf index 6b03d766ea..2466b78574 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportFromHierarchy.lf b/test/Python/src/multiport/MultiportFromHierarchy.lf index 4116587f01..83cdcad88a 100644 --- a/test/Python/src/multiport/MultiportFromHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromHierarchy.lf @@ -1,5 +1,4 @@ -# Check multiport output to multiport input, where the former is a hierarchical -# reactor. +# Check multiport output to multiport input, where the former is a hierarchical reactor. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportIn.lf b/test/Python/src/multiport/MultiportIn.lf index 35bdee7341..feb5ef6d03 100644 --- a/test/Python/src/multiport/MultiportIn.lf +++ b/test/Python/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -# This is a version fo the Threaded test that uses a multiport input at the -# destination. Its purpose is to test multiport inputs. +# This is a version fo the Threaded test that uses a multiport input at the destination. Its purpose +# is to test multiport inputs. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportInParameterized.lf b/test/Python/src/multiport/MultiportInParameterized.lf index 28b15808e3..ca10b50175 100644 --- a/test/Python/src/multiport/MultiportInParameterized.lf +++ b/test/Python/src/multiport/MultiportInParameterized.lf @@ -1,5 +1,5 @@ -# This is a version of the Threaded test that uses a multiport input at the -# destination. Its purpose is to test multiport inputs. +# This is a version of the Threaded test that uses a multiport input at the destination. Its purpose +# is to test multiport inputs. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportMutableInput.lf b/test/Python/src/multiport/MultiportMutableInput.lf index f931900ef7..e12855db04 100644 --- a/test/Python/src/multiport/MultiportMutableInput.lf +++ b/test/Python/src/multiport/MultiportMutableInput.lf @@ -1,6 +1,5 @@ -# Source produces a ints on a multiport, which it passes to Scale. Scale -# requests a writable copy. It modifies it and passes it to Print. It gets freed -# after Print is done with it. +# Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. +# It modifies it and passes it to Print. It gets freed after Print is done with it. target Python reactor Source { diff --git a/test/Python/src/multiport/MultiportMutableInputArray.lf b/test/Python/src/multiport/MultiportMutableInputArray.lf index 9efa3eeebf..5e37ccd6b2 100644 --- a/test/Python/src/multiport/MultiportMutableInputArray.lf +++ b/test/Python/src/multiport/MultiportMutableInputArray.lf @@ -1,7 +1,6 @@ -# Source produces a list on a multiport, which it passes to Scale. Scale -# requests a writable copy, which, instead of copying, it just gets ownership of -# the original list. It modifies it and passes it to Print. It gets freed after -# Print is done with it. +# Source produces a list on a multiport, which it passes to Scale. Scale requests a writable copy, +# which, instead of copying, it just gets ownership of the original list. It modifies it and passes +# it to Print. It gets freed after Print is done with it. target Python reactor Source { diff --git a/test/Python/src/multiport/MultiportToBankAfter.lf b/test/Python/src/multiport/MultiportToBankAfter.lf index 85fc91e513..6d3f6e7ed4 100644 --- a/test/Python/src/multiport/MultiportToBankAfter.lf +++ b/test/Python/src/multiport/MultiportToBankAfter.lf @@ -1,5 +1,4 @@ -# Check multiport output to bank of recipients where the width of the bank is -# inferred. +# Check multiport output to bank of recipients where the width of the bank is inferred. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index f70fa8ad92..bef01b8d89 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index 2a9e25a5e6..1e525b621d 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -1,6 +1,5 @@ -# Check multiport output to multiport input, where the latter is a hierarchical -# reactor. Note that the destination reactor has width wider than the sender, so -# one input is dangling. +# Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +# the destination reactor has width wider than the sender, so one input is dangling. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToMultiportArray.lf b/test/Python/src/multiport/MultiportToMultiportArray.lf index 5eb043570d..42e885ea37 100644 --- a/test/Python/src/multiport/MultiportToMultiportArray.lf +++ b/test/Python/src/multiport/MultiportToMultiportArray.lf @@ -1,5 +1,4 @@ -# Check multiport output to multiport input. Destination port is wider than -# sending port. +# Check multiport output to multiport input. Destination port is wider than sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToPort.lf b/test/Python/src/multiport/MultiportToPort.lf index ebfbf81991..893ad600b0 100644 --- a/test/Python/src/multiport/MultiportToPort.lf +++ b/test/Python/src/multiport/MultiportToPort.lf @@ -1,5 +1,4 @@ -# Check multiport output to multiport input. Destination port is wider than -# sending port. +# Check multiport output to multiport input. Destination port is wider than sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/ReactionsToNested.lf b/test/Python/src/multiport/ReactionsToNested.lf index 2c207dffb0..5d1046fa24 100644 --- a/test/Python/src/multiport/ReactionsToNested.lf +++ b/test/Python/src/multiport/ReactionsToNested.lf @@ -1,5 +1,4 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { timeout: 1 sec } diff --git a/test/Python/src/serialization/PersonProtocolBuffers.lf b/test/Python/src/serialization/PersonProtocolBuffers.lf index 2d5519fbcb..530df50d8d 100644 --- a/test/Python/src/serialization/PersonProtocolBuffers.lf +++ b/test/Python/src/serialization/PersonProtocolBuffers.lf @@ -1,23 +1,21 @@ /** - * This example demonstrates a very simple use of protocol buffers within a - * reactor. It encodes and decodes a very simple protocol buffer definition in - * Person.proto. This reactor is heavily based on the examples at - * https://github.com/protobuf-c/protobuf-c/wiki/Examples. This example just + * This example demonstrates a very simple use of protocol buffers within a reactor. It encodes and + * decodes a very simple protocol buffer definition in Person.proto. This reactor is heavily based + * on the examples at https://github.com/protobuf-c/protobuf-c/wiki/Examples. This example just * packs and unpacks a message. * * To run this example first install the protocol buffers compiler from - * https://github.com/protocolbuffers/protobuf. It is also available from - * homebrew on a Mac via + * https://github.com/protocolbuffers/protobuf. It is also available from homebrew on a Mac via * * $ brew install protobuf * - * Building protobuf from source is slow, so avoid doing that if possible. Next, - * install the Google APIs for Python + * Building protobuf from source is slow, so avoid doing that if possible. Next, install the Google + * APIs for Python * * $ pip3 install --upgrade google-api-python-client * - * The code generator assumes that executables are installed within the PATH. On - * a Mac, this is typically at /usr/local/bin. + * The code generator assumes that executables are installed within the PATH. On a Mac, this is + * typically at /usr/local/bin. */ target Python { protobufs: Person.proto diff --git a/test/Python/src/serialization/ProtoNoPacking.lf b/test/Python/src/serialization/ProtoNoPacking.lf index 6cf4a0b789..92e04fd5f5 100644 --- a/test/Python/src/serialization/ProtoNoPacking.lf +++ b/test/Python/src/serialization/ProtoNoPacking.lf @@ -1,22 +1,20 @@ /** - * This example creates a Protocol Buffer message and passes it to another - * reactor without packing and unpacking. This demonstrates that local - * communication, within one shared-memory machine, need not incur the overhead - * of packing and unpacking. + * This example creates a Protocol Buffer message and passes it to another reactor without packing + * and unpacking. This demonstrates that local communication, within one shared-memory machine, need + * not incur the overhead of packing and unpacking. * * To run this example first install the protocol buffers compiler from - * https://github.com/protocolbuffers/protobuf. It is also available from - * homebrew on a Mac via + * https://github.com/protocolbuffers/protobuf. It is also available from homebrew on a Mac via * * $ brew install protobuf * - * Building protobuf from source is slow, so avoid doing that if possible. Next, - * install the Google APIs for Python + * Building protobuf from source is slow, so avoid doing that if possible. Next, install the Google + * APIs for Python * * $ pip3 install --upgrade google-api-python-client * - * The code generator assumes that executables are installed within the PATH. On - * a Mac, this is typically at /usr/local/bin. + * The code generator assumes that executables are installed within the PATH. On a Mac, this is + * typically at /usr/local/bin. */ target Python { protobufs: ProtoHelloWorld.proto diff --git a/test/Python/src/target/AfterNoTypes.lf b/test/Python/src/target/AfterNoTypes.lf index 44aaa89c73..fb5597e863 100644 --- a/test/Python/src/target/AfterNoTypes.lf +++ b/test/Python/src/target/AfterNoTypes.lf @@ -1,5 +1,5 @@ -# This test demonstrates that after can be used on connections with ports that -# have no types. The test passes if the compile is succeeded +# This test demonstrates that after can be used on connections with ports that have no types. The +# test passes if the compile is succeeded target Python { fast: false, timeout: 3 sec diff --git a/test/Rust/src/ActionValuesCleanup.lf b/test/Rust/src/ActionValuesCleanup.lf index f4bab7a2b5..6bda6e9fd6 100644 --- a/test/Rust/src/ActionValuesCleanup.lf +++ b/test/Rust/src/ActionValuesCleanup.lf @@ -22,9 +22,7 @@ main reactor ActionValuesCleanup { logical action act: FooDrop state count: u32 = 0 - reaction(startup) -> act {= - ctx.schedule_with_v(act, Some(FooDrop { }), Asap) - =} + reaction(startup) -> act {= ctx.schedule_with_v(act, Some(FooDrop { }), Asap) =} reaction(act) -> act {= ctx.use_ref(act, |v| println!("{:?}", v)); diff --git a/test/Rust/src/CompositionInitializationOrder.lf b/test/Rust/src/CompositionInitializationOrder.lf index 4c2a428f10..283923d9be 100644 --- a/test/Rust/src/CompositionInitializationOrder.lf +++ b/test/Rust/src/CompositionInitializationOrder.lf @@ -1,5 +1,4 @@ -// This test asserts the relative execution order of startup reactions within a -// composite reactor. +// This test asserts the relative execution order of startup reactions within a composite reactor. target Rust main reactor CompositionInitializationOrder { diff --git a/test/Rust/src/DependencyOnChildPort.lf b/test/Rust/src/DependencyOnChildPort.lf index ed8b6b2120..18ad405da2 100644 --- a/test/Rust/src/DependencyOnChildPort.lf +++ b/test/Rust/src/DependencyOnChildPort.lf @@ -18,9 +18,7 @@ main reactor { reaction(startup) -> box0.inp {= ctx.set(box0__inp, 444); =} - reaction(box1.out) {= - assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; - =} + reaction(box1.out) {= assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; =} reaction(shutdown) {= assert!(self.done, "reaction was not executed"); diff --git a/test/Rust/src/DependencyUseAccessible.lf b/test/Rust/src/DependencyUseAccessible.lf index 9b67fb510e..28afec9bc6 100644 --- a/test/Rust/src/DependencyUseAccessible.lf +++ b/test/Rust/src/DependencyUseAccessible.lf @@ -12,8 +12,7 @@ reactor Source { reaction(t1) -> clock, o1 {= ctx.set(clock, 1); ctx.set(o1, 10) =} - // has a dependency but doesn't use it - reaction(t2) -> clock, o2 {= ctx.set(clock, 2); =} + reaction(t2) -> clock, o2 {= ctx.set(clock, 2); =} // has a dependency but doesn't use it } reactor Sink { diff --git a/test/Rust/src/Import.lf b/test/Rust/src/Import.lf index dd40ad064d..15837b9c4c 100644 --- a/test/Rust/src/Import.lf +++ b/test/Rust/src/Import.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target Rust import Imported from "lib/Imported.lf" diff --git a/test/Rust/src/ImportPreambleItem.lf b/test/Rust/src/ImportPreambleItem.lf index e532f74c70..2abd438fb6 100644 --- a/test/Rust/src/ImportPreambleItem.lf +++ b/test/Rust/src/ImportPreambleItem.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target Rust import SomethingWithAPreamble from "lib/SomethingWithAPreamble.lf" @@ -7,7 +6,5 @@ import SomethingWithAPreamble from "lib/SomethingWithAPreamble.lf" main reactor { r = new SomethingWithAPreamble() - reaction(startup) -> r.a {= - ctx.set(r__a, super::something_with_a_preamble::some_fun()); - =} + reaction(startup) -> r.a {= ctx.set(r__a, super::something_with_a_preamble::some_fun()); =} } diff --git a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf index 206a3d7d1c..faa4f54252 100644 --- a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf +++ b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf @@ -1,5 +1,4 @@ -// Tests that physical actions can be scheduled like logical actions within the -// body of reactions. +// Tests that physical actions can be scheduled like logical actions within the body of reactions. target Rust main reactor { diff --git a/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf b/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf index 1e578892d1..a34daa21e0 100644 --- a/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf +++ b/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf @@ -1,5 +1,5 @@ -// Tests that the scheduler ends up shutting down if there are no live Sender -// that can send messages back to the scheduler. +// Tests that the scheduler ends up shutting down if there are no live Sender that can send messages +// back to the scheduler. target Rust { keepalive: true } diff --git a/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf b/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf index 27b5f36af8..f1f8c154b0 100644 --- a/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf +++ b/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf @@ -1,11 +1,9 @@ -// Tests that, given a logical event scheduled far away in the future (which -// puts the scheduler to sleep), and a physical action being triggered -// asynchronously during that sleep time, the scheduler wakes up and processes -// the physical action before the logical action. This test is unfortunately not -// very reliable, as the sleeping thread may wake up very late depending on the -// platform and the weather. The test has already failed in CI on macos, because -// the action was triggered at (T0+135ms), that is, 115ms later than the -// expected wake up time (T0+20ms). +// Tests that, given a logical event scheduled far away in the future (which puts the scheduler to +// sleep), and a physical action being triggered asynchronously during that sleep time, the +// scheduler wakes up and processes the physical action before the logical action. This test is +// unfortunately not very reliable, as the sleeping thread may wake up very late depending on the +// platform and the weather. The test has already failed in CI on macos, because the action was +// triggered at (T0+135ms), that is, 115ms later than the expected wake up time (T0+20ms). target Rust main reactor { diff --git a/test/Rust/src/ReactionLabels.lf b/test/Rust/src/ReactionLabels.lf index c696ab85c2..6547792d8c 100644 --- a/test/Rust/src/ReactionLabels.lf +++ b/test/Rust/src/ReactionLabels.lf @@ -1,5 +1,5 @@ -// There was a bug whereby reaction labels mess up generated code. Labels are -// used as debug info by the runtime. +// There was a bug whereby reaction labels mess up generated code. Labels are used as debug info by +// the runtime. target Rust main reactor { diff --git a/test/Rust/src/ReservedKeywords.lf b/test/Rust/src/ReservedKeywords.lf index 5d30ba63a4..ef11dda278 100644 --- a/test/Rust/src/ReservedKeywords.lf +++ b/test/Rust/src/ReservedKeywords.lf @@ -1,5 +1,4 @@ -// Tests that rust keywords may be used as identifiers in LF and are properly -// escaped by the emitter +// Tests that rust keywords may be used as identifiers in LF and are properly escaped by the emitter target Rust reactor box { diff --git a/test/Rust/src/StateInitializerVisibility.lf b/test/Rust/src/StateInitializerVisibility.lf index d192f0ca98..f7da9a48d4 100644 --- a/test/Rust/src/StateInitializerVisibility.lf +++ b/test/Rust/src/StateInitializerVisibility.lf @@ -1,5 +1,5 @@ -// Tests that state vars are accessible within initializers of other state vars -// declared further down. +// Tests that state vars are accessible within initializers of other state vars declared further +// down. target Rust main reactor { diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index c43f8c30ff..80960ef142 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -8,10 +8,9 @@ target Rust { } /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after: u32 = 10, break_interval: time = 400 msec) { output out: u32 diff --git a/test/Rust/src/StopNoEvent.lf b/test/Rust/src/StopNoEvent.lf index ae84b0bfbd..5ee2639fa2 100644 --- a/test/Rust/src/StopNoEvent.lf +++ b/test/Rust/src/StopNoEvent.lf @@ -1,7 +1,4 @@ -/** - * Tests that `shutdown` is triggered even if the program exits because of an - * empty event queue. - */ +/** Tests that `shutdown` is triggered even if the program exits because of an empty event queue. */ target Rust main reactor StopNoEvent { diff --git a/test/Rust/src/StopTimeout.lf b/test/Rust/src/StopTimeout.lf index 16fec44bb3..7ebf1595e4 100644 --- a/test/Rust/src/StopTimeout.lf +++ b/test/Rust/src/StopTimeout.lf @@ -1,6 +1,5 @@ /** - * Tests that `shutdown` is triggered even if the program exits because of - * timeout target property. + * Tests that `shutdown` is triggered even if the program exits because of timeout target property. */ target Rust { timeout: 30 msec diff --git a/test/Rust/src/StopTimeoutExact.lf b/test/Rust/src/StopTimeoutExact.lf index 2b9eb85cda..cd81e7923d 100644 --- a/test/Rust/src/StopTimeoutExact.lf +++ b/test/Rust/src/StopTimeoutExact.lf @@ -1,6 +1,6 @@ /** - * Tests that when a timeout coincides with a scheduled event, all scheduled - * reactions are properly executed (in addition to the shutdown ones). + * Tests that when a timeout coincides with a scheduled event, all scheduled reactions are properly + * executed (in addition to the shutdown ones). */ target Rust { timeout: 50 msec diff --git a/test/Rust/src/StructAsState.lf b/test/Rust/src/StructAsState.lf index 9b35e7a3fb..22565b58e9 100644 --- a/test/Rust/src/StructAsState.lf +++ b/test/Rust/src/StructAsState.lf @@ -1,5 +1,5 @@ -// Check that a state variable can have a statically initialized struct as a -// value. Check how preambles work +// Check that a state variable can have a statically initialized struct as a value. Check how +// preambles work target Rust main reactor StructAsState { diff --git a/test/Rust/src/generics/GenericReactor.lf b/test/Rust/src/generics/GenericReactor.lf index 3190524a5b..9715d7e0a3 100644 --- a/test/Rust/src/generics/GenericReactor.lf +++ b/test/Rust/src/generics/GenericReactor.lf @@ -18,9 +18,7 @@ main reactor { reaction(startup) -> box0.inp {= ctx.set(box0__inp, 444); =} - reaction(box1.out) {= - assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; - =} + reaction(box1.out) {= assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; =} reaction(shutdown) {= assert!(self.done, "reaction was not executed"); diff --git a/test/Rust/src/lib/Imported.lf b/test/Rust/src/lib/Imported.lf index 989f9d7168..8a33aa04b8 100644 --- a/test/Rust/src/lib/Imported.lf +++ b/test/Rust/src/lib/Imported.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target Rust import ImportedAgain from "ImportedAgain.lf" diff --git a/test/Rust/src/lib/ImportedAgain.lf b/test/Rust/src/lib/ImportedAgain.lf index 7e61e9a575..d1bd87c4f1 100644 --- a/test/Rust/src/lib/ImportedAgain.lf +++ b/test/Rust/src/lib/ImportedAgain.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target Rust reactor ImportedAgain { diff --git a/test/Rust/src/lib/SomethingWithAPreamble.lf b/test/Rust/src/lib/SomethingWithAPreamble.lf index 961a64f32d..d63f7c381a 100644 --- a/test/Rust/src/lib/SomethingWithAPreamble.lf +++ b/test/Rust/src/lib/SomethingWithAPreamble.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target Rust reactor SomethingWithAPreamble { diff --git a/test/Rust/src/multiport/CycledLhs_SelfLoop.lf b/test/Rust/src/multiport/CycledLhs_SelfLoop.lf index 925fafce21..5eb3cc226c 100644 --- a/test/Rust/src/multiport/CycledLhs_SelfLoop.lf +++ b/test/Rust/src/multiport/CycledLhs_SelfLoop.lf @@ -1,5 +1,5 @@ -// test a cycled connection which has ports of the same reactor on the LHS and -// rhs (single port)+ -> multiport +// test a cycled connection which has ports of the same reactor on the LHS and rhs (single port)+ -> +// multiport target Rust { timeout: 16 usec } @@ -10,9 +10,7 @@ reactor Test { logical action act: u32 state last: u32 = 1 - reaction(startup) -> act {= - ctx.schedule_with_v(act, Some(1), after!(1 us)); - =} + reaction(startup) -> act {= ctx.schedule_with_v(act, Some(1), after!(1 us)); =} reaction(act) -> out {= ctx.set_opt(out, ctx.get(act)); =} diff --git a/test/Rust/src/multiport/CycledLhs_Single.lf b/test/Rust/src/multiport/CycledLhs_Single.lf index 2fdd5c605c..62723bda42 100644 --- a/test/Rust/src/multiport/CycledLhs_Single.lf +++ b/test/Rust/src/multiport/CycledLhs_Single.lf @@ -1,5 +1,5 @@ -// test a cycled connection which has ports of the same reactor on the LHS and -// rhs (multiport)+ -> multiport +// test a cycled connection which has ports of the same reactor on the LHS and rhs (multiport)+ -> +// multiport target Rust { timeout: 16 usec } @@ -10,9 +10,7 @@ reactor Test { logical action act: {= (u32, u32) =} state last: u32 = 1 - reaction(startup) -> act {= - ctx.schedule_with_v(act, Some((0, 1)), after!(1 us)); - =} + reaction(startup) -> act {= ctx.schedule_with_v(act, Some((0, 1)), after!(1 us)); =} reaction(act) -> out {= let (a, b) = ctx.get(act).unwrap(); @@ -41,9 +39,9 @@ reactor Test { } /** - * 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + - * 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = - * 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 + * 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = + * 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + * + 987 = 1597 987 + 1597 = 2584 */ main reactor { t = new Test() diff --git a/test/Rust/src/multiport/MultiportFromHierarchy.lf b/test/Rust/src/multiport/MultiportFromHierarchy.lf index d2af4253c4..400dfff7d9 100644 --- a/test/Rust/src/multiport/MultiportFromHierarchy.lf +++ b/test/Rust/src/multiport/MultiportFromHierarchy.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input, where the former is a hierarchical -// reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target Rust { timeout: 2 sec } diff --git a/test/Rust/src/multiport/MultiportIn.lf b/test/Rust/src/multiport/MultiportIn.lf index 4ebf1c56d5..27b3522449 100644 --- a/test/Rust/src/multiport/MultiportIn.lf +++ b/test/Rust/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version fo the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target Rust { timeout: 2 sec, fast: true diff --git a/test/Rust/src/multiport/MultiportToMultiport2.lf b/test/Rust/src/multiport/MultiportToMultiport2.lf index a1e2db235d..0c79ee17d4 100644 --- a/test/Rust/src/multiport/MultiportToMultiport2.lf +++ b/test/Rust/src/multiport/MultiportToMultiport2.lf @@ -1,5 +1,4 @@ -// test a sparse connection between multiports (some channels are left -// disconnected) +// test a sparse connection between multiports (some channels are left disconnected) target Rust reactor Source(width: usize = 2) { diff --git a/test/Rust/src/target/BuildProfileDefaultIsDev.lf b/test/Rust/src/target/BuildProfileDefaultIsDev.lf index b27f66a2d0..e45c442406 100644 --- a/test/Rust/src/target/BuildProfileDefaultIsDev.lf +++ b/test/Rust/src/target/BuildProfileDefaultIsDev.lf @@ -1,5 +1,5 @@ -// Tests that the default build profile is dev. A proxy for checking this is to -// check that debug assertions are enabled. +// Tests that the default build profile is dev. A proxy for checking this is to check that debug +// assertions are enabled. target Rust main reactor { diff --git a/test/Rust/src/target/BuildProfileRelease.lf b/test/Rust/src/target/BuildProfileRelease.lf index 2e28f8ee5f..20712f0721 100644 --- a/test/Rust/src/target/BuildProfileRelease.lf +++ b/test/Rust/src/target/BuildProfileRelease.lf @@ -1,5 +1,5 @@ -// Tests that the we can enable the release profile A proxy for checking this is -// to check that debug assertions are disabled. +// Tests that the we can enable the release profile A proxy for checking this is to check that debug +// assertions are disabled. target Rust { build-type: "Release" } diff --git a/test/Rust/src/target/CargoDependency.lf b/test/Rust/src/target/CargoDependency.lf index c0ba4c88e8..a425958fab 100644 --- a/test/Rust/src/target/CargoDependency.lf +++ b/test/Rust/src/target/CargoDependency.lf @@ -1,5 +1,4 @@ -// This tests the ability to depend on crates with carg if this compiles it's -// fine +// This tests the ability to depend on crates with carg if this compiles it's fine target Rust { cargo-dependencies: { rand: "0.8", diff --git a/test/Rust/src/target/CargoDependencyOnRuntime.lf b/test/Rust/src/target/CargoDependencyOnRuntime.lf index a6168df15c..2d3473f474 100644 --- a/test/Rust/src/target/CargoDependencyOnRuntime.lf +++ b/test/Rust/src/target/CargoDependencyOnRuntime.lf @@ -1,5 +1,4 @@ -// This tests the ability to depend on crates with carg if this compiles it's -// fine +// This tests the ability to depend on crates with carg if this compiles it's fine target Rust { cargo-dependencies: { reactor_rt: { diff --git a/test/TypeScript/src/ActionWithNoReaction.lf b/test/TypeScript/src/ActionWithNoReaction.lf index 4e95418d48..f8dab33ef6 100644 --- a/test/TypeScript/src/ActionWithNoReaction.lf +++ b/test/TypeScript/src/ActionWithNoReaction.lf @@ -1,6 +1,5 @@ -// This checks that action can be created even if there is no reaction. This -// test passes merely by compiling and executing without a segfault. Its other -// functionality is tested by other tests. +// This checks that action can be created even if there is no reaction. This test passes merely by +// compiling and executing without a segfault. Its other functionality is tested by other tests. target TypeScript { fast: true, timeout: 3 sec diff --git a/test/TypeScript/src/After.lf b/test/TypeScript/src/After.lf index 8a872103e9..525ff817f1 100644 --- a/test/TypeScript/src/After.lf +++ b/test/TypeScript/src/After.lf @@ -1,5 +1,4 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target TypeScript { fast: true, timeout: 3 sec diff --git a/test/TypeScript/src/ArrayAsType.lf b/test/TypeScript/src/ArrayAsType.lf index 9e30764307..3ff1e9e31a 100644 --- a/test/TypeScript/src/ArrayAsType.lf +++ b/test/TypeScript/src/ArrayAsType.lf @@ -1,6 +1,5 @@ -// In TypeScript this test is almost exactly the same as ArrayAsType. Source -// produces a statically allocated array, which it passes to Print. The -// destination references the array directly. +// In TypeScript this test is almost exactly the same as ArrayAsType. Source produces a statically +// allocated array, which it passes to Print. The destination references the array directly. target TypeScript reactor Source { diff --git a/test/TypeScript/src/ArrayPrint.lf b/test/TypeScript/src/ArrayPrint.lf index 93b6486506..ba77fa47c6 100644 --- a/test/TypeScript/src/ArrayPrint.lf +++ b/test/TypeScript/src/ArrayPrint.lf @@ -1,6 +1,5 @@ -// In TypeScript this test is almost exactly the same as ArrayAsType. Source -// produces a dynamically allocated array, which it passes to Print. Reference -// counting ensures that the array is freed. +// In TypeScript this test is almost exactly the same as ArrayAsType. Source produces a dynamically +// allocated array, which it passes to Print. Reference counting ensures that the array is freed. target TypeScript reactor Source { diff --git a/test/TypeScript/src/ArrayScale.lf b/test/TypeScript/src/ArrayScale.lf index 107ef8cf2f..0b29b9f918 100644 --- a/test/TypeScript/src/ArrayScale.lf +++ b/test/TypeScript/src/ArrayScale.lf @@ -1,7 +1,6 @@ -// Source produces a dynamically allocated array, which it passes to Scale. -// Scale requests a writable copy, which, instead of copying, it just gets -// ownership of the original array. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated array, which it passes to Scale. Scale requests a +// writable copy, which, instead of copying, it just gets ownership of the original array. It +// modifies it and passes it to Print. It gets freed after Print is done with it. target TypeScript import Source, Print from "ArrayPrint.lf" diff --git a/test/TypeScript/src/Composition.lf b/test/TypeScript/src/Composition.lf index e74bbe9aa9..f3dc9ae5da 100644 --- a/test/TypeScript/src/Composition.lf +++ b/test/TypeScript/src/Composition.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target TypeScript { timeout: 5 sec } diff --git a/test/TypeScript/src/CompositionAfter.lf b/test/TypeScript/src/CompositionAfter.lf index 8840298c2d..474f1525dd 100644 --- a/test/TypeScript/src/CompositionAfter.lf +++ b/test/TypeScript/src/CompositionAfter.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source that checks against its own -// count. +// This test connects a simple counting source that checks against its own count. target TypeScript { fast: true, timeout: 10 sec diff --git a/test/TypeScript/src/DanglingOutput.lf b/test/TypeScript/src/DanglingOutput.lf index f3f67e6529..c07115ea93 100644 --- a/test/TypeScript/src/DanglingOutput.lf +++ b/test/TypeScript/src/DanglingOutput.lf @@ -1,5 +1,5 @@ -// This tests that an output that is not connected to anything does not result -// in a compilation error. Passing the test is just compiling and running. +// This tests that an output that is not connected to anything does not result in a compilation +// error. Passing the test is just compiling and running. target TypeScript reactor Source { diff --git a/test/TypeScript/src/Deadline.lf b/test/TypeScript/src/Deadline.lf index 9f3086f1f5..b4586090f3 100644 --- a/test/TypeScript/src/Deadline.lf +++ b/test/TypeScript/src/Deadline.lf @@ -1,6 +1,5 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target TypeScript { timeout: 4 sec } diff --git a/test/TypeScript/src/DeadlineHandledAbove.lf b/test/TypeScript/src/DeadlineHandledAbove.lf index ba47fd7aac..a87a677048 100644 --- a/test/TypeScript/src/DeadlineHandledAbove.lf +++ b/test/TypeScript/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/DelayInt.lf b/test/TypeScript/src/DelayInt.lf index 224a7eab4a..2910a5b6b5 100644 --- a/test/TypeScript/src/DelayInt.lf +++ b/test/TypeScript/src/DelayInt.lf @@ -1,5 +1,5 @@ -// This tests actions with payloads by delaying an input by a fixed amount. This -// is a start at handling dynamic memory allocation for such actions. +// This tests actions with payloads by delaying an input by a fixed amount. This is a start at +// handling dynamic memory allocation for such actions. target TypeScript reactor Delay(delay: time = 100 msec) { diff --git a/test/TypeScript/src/DoubleInvocation.lf b/test/TypeScript/src/DoubleInvocation.lf index 9557857ee2..92369ca913 100644 --- a/test/TypeScript/src/DoubleInvocation.lf +++ b/test/TypeScript/src/DoubleInvocation.lf @@ -1,8 +1,7 @@ -// This illustrates a very strange bug that showed up and has now been fixed. -// This test ensures it does not reappear. At logical time zero, the two Print -// reactors used to be fired twice each at the same logical time. They should -// only be fired once. This behavior was oddly eliminated by either of the -// following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at +// the same logical time. They should only be fired once. This behavior was oddly eliminated by +// either of the following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. // * Sending only position, not velocity from Ball. target TypeScript { diff --git a/test/TypeScript/src/DoubleReaction.lf b/test/TypeScript/src/DoubleReaction.lf index b172166613..67f2632920 100644 --- a/test/TypeScript/src/DoubleReaction.lf +++ b/test/TypeScript/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target TypeScript { timeout: 10 sec, fast: true diff --git a/test/TypeScript/src/DoubleTrigger.lf b/test/TypeScript/src/DoubleTrigger.lf index fc8921622c..dafbd7f453 100644 --- a/test/TypeScript/src/DoubleTrigger.lf +++ b/test/TypeScript/src/DoubleTrigger.lf @@ -1,5 +1,4 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice -// at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. target TypeScript { fast: true, timeout: 1 sec diff --git a/test/TypeScript/src/GetTime.lf b/test/TypeScript/src/GetTime.lf index 2fee5dfc20..8e14c563a0 100644 --- a/test/TypeScript/src/GetTime.lf +++ b/test/TypeScript/src/GetTime.lf @@ -1,8 +1,8 @@ -// This file includes code documented on the Wiki. For this test, success is -// just compiling and running. +// This file includes code documented on the Wiki. For this test, success is just compiling and +// running. target TypeScript { - // FIXME the C version of this test is fast, but in TS it's illegal to - // subtract TimeValues and get a negative result fast: true + // FIXME the C version of this test is fast, but in TS it's illegal to subtract TimeValues and + // get a negative result fast: true timeout: 2 sec } diff --git a/test/TypeScript/src/Import.lf b/test/TypeScript/src/Import.lf index 6a914e03c0..afdc8465ca 100644 --- a/test/TypeScript/src/Import.lf +++ b/test/TypeScript/src/Import.lf @@ -1,5 +1,4 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/MovingAverage.lf b/test/TypeScript/src/MovingAverage.lf index 19e767e3e2..b8018d92c2 100644 --- a/test/TypeScript/src/MovingAverage.lf +++ b/test/TypeScript/src/MovingAverage.lf @@ -1,6 +1,5 @@ -// Demonstration of a state variable that is an array. The MovingAverage reactor -// computes the moving average of the last four inputs and produces that as -// output. The source is a counting sequence. +// Demonstration of a state variable that is an array. The MovingAverage reactor computes the moving +// average of the last four inputs and produces that as output. The source is a counting sequence. target TypeScript { timeout: 1 sec, fast: true diff --git a/test/TypeScript/src/MultipleContained.lf b/test/TypeScript/src/MultipleContained.lf index 1bbeb82162..4c5fb53db8 100644 --- a/test/TypeScript/src/MultipleContained.lf +++ b/test/TypeScript/src/MultipleContained.lf @@ -1,5 +1,4 @@ -// Test that a reaction can react to and send two multiple ports of a contained -// reactor. +// Test that a reaction can react to and send two multiple ports of a contained reactor. target TypeScript reactor Contained { diff --git a/test/TypeScript/src/ReadOutputOfContainedReactor.lf b/test/TypeScript/src/ReadOutputOfContainedReactor.lf index 01b725e181..8591fe96bc 100644 --- a/test/TypeScript/src/ReadOutputOfContainedReactor.lf +++ b/test/TypeScript/src/ReadOutputOfContainedReactor.lf @@ -1,5 +1,4 @@ -// Test reacting to and reading outputs from a contained reactor in various -// permutations. +// Test reacting to and reading outputs from a contained reactor in various permutations. target TypeScript reactor Contained { diff --git a/test/TypeScript/src/Schedule.lf b/test/TypeScript/src/Schedule.lf index 27739f29a5..66464ccf70 100644 --- a/test/TypeScript/src/Schedule.lf +++ b/test/TypeScript/src/Schedule.lf @@ -1,5 +1,4 @@ -// TypeScript translated example from Schedule section of the C Reactor Target -// wiki page. +// TypeScript translated example from Schedule section of the C Reactor Target wiki page. target TypeScript reactor ScheduleLogicalAction { diff --git a/test/TypeScript/src/ScheduleLogicalAction.lf b/test/TypeScript/src/ScheduleLogicalAction.lf index 84e8fbe1cb..ee49204288 100644 --- a/test/TypeScript/src/ScheduleLogicalAction.lf +++ b/test/TypeScript/src/ScheduleLogicalAction.lf @@ -1,5 +1,5 @@ -// This checks that a logical action is scheduled the specified logical time -// after the current logical time. +// This checks that a logical action is scheduled the specified logical time after the current +// logical time. target TypeScript { fast: true, timeout: 3 sec diff --git a/test/TypeScript/src/SendingInside.lf b/test/TypeScript/src/SendingInside.lf index ca4b6489b3..a22f637deb 100644 --- a/test/TypeScript/src/SendingInside.lf +++ b/test/TypeScript/src/SendingInside.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target TypeScript { timeout: 10 sec, fast: true diff --git a/test/TypeScript/src/SendsPointerTest.lf b/test/TypeScript/src/SendsPointerTest.lf index 3c80613b52..6bdbf514af 100644 --- a/test/TypeScript/src/SendsPointerTest.lf +++ b/test/TypeScript/src/SendsPointerTest.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated object, which it passes to Print. -// Reference counting ensures that the struct is freed. +// Source produces a dynamically allocated object, which it passes to Print. Reference counting +// ensures that the struct is freed. target TypeScript reactor SendsPointer { diff --git a/test/TypeScript/src/SimpleDeadline.lf b/test/TypeScript/src/SimpleDeadline.lf index a518e04e5e..d02fe0044c 100644 --- a/test/TypeScript/src/SimpleDeadline.lf +++ b/test/TypeScript/src/SimpleDeadline.lf @@ -1,6 +1,5 @@ -// Test local deadline, where a deadline is associated with a reaction -// definition. This test triggers a reaction exactly once with a deadline -// violation. +// Test local deadline, where a deadline is associated with a reaction definition. This test +// triggers a reaction exactly once with a deadline violation. target TypeScript reactor Deadline(threshold: time = 100 msec) { diff --git a/test/TypeScript/src/SlowingClockPhysical.lf b/test/TypeScript/src/SlowingClockPhysical.lf index 53bc3f9da4..f1c65a92b7 100644 --- a/test/TypeScript/src/SlowingClockPhysical.lf +++ b/test/TypeScript/src/SlowingClockPhysical.lf @@ -1,12 +1,10 @@ /** - * Output events at physical times at least 100, 300, and 600 msec after the - * start time. This uses a physical action with a minimum interarrival time of - * 100 msec. The reactor increases the interarrival time with each invocation of - * the schedule() function. The timestamps of the events will be exact because - * the physical time at which schedule() is called is always way smaller than - * the time of the last invocation (or start time) plus the minimum interarrival - * time. Hence, the minimum interarrival time always determines the time of the - * next event. + * Output events at physical times at least 100, 300, and 600 msec after the start time. This uses a + * physical action with a minimum interarrival time of 100 msec. The reactor increases the + * interarrival time with each invocation of the schedule() function. The timestamps of the events + * will be exact because the physical time at which schedule() is called is always way smaller than + * the time of the last invocation (or start time) plus the minimum interarrival time. Hence, the + * minimum interarrival time always determines the time of the next event. */ target TypeScript { timeout: 1 sec diff --git a/test/TypeScript/src/Stop.lf b/test/TypeScript/src/Stop.lf index 6104c418d5..3464239b0a 100644 --- a/test/TypeScript/src/Stop.lf +++ b/test/TypeScript/src/Stop.lf @@ -1,6 +1,5 @@ /** - * A test for the util.requestStop() functionality in TypeScript target Lingua - * Franca. + * A test for the util.requestStop() functionality in TypeScript target Lingua Franca. * * @author Soroush Bateni * @author Byeong-gil Jun diff --git a/test/TypeScript/src/Stride.lf b/test/TypeScript/src/Stride.lf index 04d7805d0b..dd0ef5359e 100644 --- a/test/TypeScript/src/Stride.lf +++ b/test/TypeScript/src/Stride.lf @@ -1,5 +1,5 @@ -// This example illustrates state variables and parameters on the wiki. For this -// test, success is just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this test, success is +// just compiling and running. target TypeScript { timeout: 2 sec, fast: true diff --git a/test/TypeScript/src/StructPrint.lf b/test/TypeScript/src/StructPrint.lf index e75d9ead37..201f788779 100644 --- a/test/TypeScript/src/StructPrint.lf +++ b/test/TypeScript/src/StructPrint.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Print. -// Reference counting ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. Reference counting +// ensures that the struct is freed. target TypeScript reactor Source { diff --git a/test/TypeScript/src/TestForPreviousOutput.lf b/test/TypeScript/src/TestForPreviousOutput.lf index c0eb21e6f0..0c37653ad0 100644 --- a/test/TypeScript/src/TestForPreviousOutput.lf +++ b/test/TypeScript/src/TestForPreviousOutput.lf @@ -1,5 +1,5 @@ -// This tests the mechanism for testing whether a previous reaction has produced -// a given output. The output should always be 42. +// This tests the mechanism for testing whether a previous reaction has produced a given output. The +// output should always be 42. target TypeScript reactor Source { diff --git a/test/TypeScript/src/TimeLimit.lf b/test/TypeScript/src/TimeLimit.lf index 05a2a5a3b3..c837a4cbb4 100644 --- a/test/TypeScript/src/TimeLimit.lf +++ b/test/TypeScript/src/TimeLimit.lf @@ -1,7 +1,6 @@ -// Test that the stop function can be used to internally impose a a time limit. -// This is also used to test performance (number of reactions per second). -// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt -// or getting the wrong data. +// Test that the stop function can be used to internally impose a a time limit. This is also used to +// test performance (number of reactions per second). Correct output for this 1, 2, 3, 4. Failure +// for this test is failing to halt or getting the wrong data. target TypeScript { fast: true, logging: INFO diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf index 50f510cdcd..a85228f606 100644 --- a/test/TypeScript/src/federated/DistributedCount.lf +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee * @author Hokeun Kim */ diff --git a/test/TypeScript/src/federated/DistributedDoublePort.lf b/test/TypeScript/src/federated/DistributedDoublePort.lf index d3a2636661..056216e687 100644 --- a/test/TypeScript/src/federated/DistributedDoublePort.lf +++ b/test/TypeScript/src/federated/DistributedDoublePort.lf @@ -1,7 +1,6 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federte on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federte on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni * @author Hokeun Kim @@ -40,9 +39,7 @@ reactor Print { } =} - reaction(shutdown) {= - console.log("SUCCESS: messages were at least one microstep apart."); - =} + reaction(shutdown) {= console.log("SUCCESS: messages were at least one microstep apart."); =} } federated reactor DistributedDoublePort { diff --git a/test/TypeScript/src/federated/DistributedLoopedAction.lf b/test/TypeScript/src/federated/DistributedLoopedAction.lf index 02a7f5dc62..46170a0d1f 100644 --- a/test/TypeScript/src/federated/DistributedLoopedAction.lf +++ b/test/TypeScript/src/federated/DistributedLoopedAction.lf @@ -1,6 +1,5 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni * @author Hokeun Kim @@ -18,8 +17,7 @@ reactor Receiver(takeBreakAfter: number = 10, breakInterval: time = 400 msec) { state breaks: number = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more - // sensible log output. + // but forces the logical time to advance Comment this line for a more sensible log output. reaction(inp) {= console.log("At tag (" + util.getElapsedLogicalTime() + ", " + util.getCurrentTag().microstep + ") received value " + inp); totalReceivedMessages++; diff --git a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf index 842f13f74c..aa14ba553d 100644 --- a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf @@ -1,7 +1,6 @@ /** - * Test a sender-receiver network system that is similar to - * DistributedLoopedAction, but it uses a physical action rather than a logical - * action. + * Test a sender-receiver network system that is similar to DistributedLoopedAction, but it uses a + * physical action rather than a logical action. * * @author Soroush Bateni * @author Hokeun Kim @@ -36,8 +35,7 @@ reactor Receiver(takeBreakAfter: number = 10, breakInterval: time = 550 msec) { state breaks: number = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more - // sensible log output. + // but forces the logical time to advance Comment this line for a more sensible log output. reaction(inp) {= console.log("At tag (" + util.getElapsedLogicalTime() + ", " + util.getCurrentTag().microstep + ") received value " + inp); totalReceivedMessages++; diff --git a/test/TypeScript/src/federated/DistributedStop.lf b/test/TypeScript/src/federated/DistributedStop.lf index c0dd04149a..6815501b4a 100644 --- a/test/TypeScript/src/federated/DistributedStop.lf +++ b/test/TypeScript/src/federated/DistributedStop.lf @@ -1,6 +1,5 @@ /** - * Test for util.requestStop() in federated execution with centralized - * coordination. + * Test for util.requestStop() in federated execution with centralized coordination. * * @author Soroush Bateni * @author Byeong-gil Jun diff --git a/test/TypeScript/src/federated/DistributedStopZero.lf b/test/TypeScript/src/federated/DistributedStopZero.lf index b3086b02f7..c85c3a21cf 100644 --- a/test/TypeScript/src/federated/DistributedStopZero.lf +++ b/test/TypeScript/src/federated/DistributedStopZero.lf @@ -1,6 +1,6 @@ /** - * Test for util.requestStop() in federated execution with centralized - * coordination at tag ((0 secs, 0 nsecs), 0). + * Test for util.requestStop() in federated execution with centralized coordination at tag ((0 secs, + * 0 nsecs), 0). * * @author Soroush Bateni * @author Byeong-gil Jun diff --git a/test/TypeScript/src/federated/HelloDistributed.lf b/test/TypeScript/src/federated/HelloDistributed.lf index 1189270ab1..a8376910c1 100644 --- a/test/TypeScript/src/federated/HelloDistributed.lf +++ b/test/TypeScript/src/federated/HelloDistributed.lf @@ -1,8 +1,7 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee * @author Hokeun Kim */ @@ -45,7 +44,5 @@ federated reactor HelloDistributed at localhost { d = new Destination() // Reactor d is in federate Destination s.out -> d.inp // This version preserves the timestamp. - reaction(startup) {= - console.log("Printing something in top-level federated reactor."); - =} + reaction(startup) {= console.log("Printing something in top-level federated reactor."); =} } diff --git a/test/TypeScript/src/federated/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/LoopDistributedCentralized.lf index bb52679489..042d917106 100644 --- a/test/TypeScript/src/federated/LoopDistributedCentralized.lf +++ b/test/TypeScript/src/federated/LoopDistributedCentralized.lf @@ -1,6 +1,5 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee * @author Hokeun Kim diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf index 2c791377f7..ac82edbd0d 100644 --- a/test/TypeScript/src/federated/LoopDistributedDouble.lf +++ b/test/TypeScript/src/federated/LoopDistributedDouble.lf @@ -1,6 +1,5 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee * @author Hokeun Kim diff --git a/test/TypeScript/src/federated/TopLevelArtifacts.lf b/test/TypeScript/src/federated/TopLevelArtifacts.lf index 917da033f5..cd5909a1f7 100644 --- a/test/TypeScript/src/federated/TopLevelArtifacts.lf +++ b/test/TypeScript/src/federated/TopLevelArtifacts.lf @@ -1,11 +1,10 @@ /** - * Test whether top-level reactions, actions, and ports are handled - * appropriately. + * Test whether top-level reactions, actions, and ports are handled appropriately. * * Currently, these artifacts are replicated on all federates. * - * @note This just tests for the correctness of the code generation. These - * top-level artifacts might be disallowed in the future. + * @note This just tests for the correctness of the code generation. These top-level artifacts might + * be disallowed in the future. * @author Youri Su */ target TypeScript { diff --git a/test/TypeScript/src/lib/Imported.lf b/test/TypeScript/src/lib/Imported.lf index b19cd366a9..52ed1e4c85 100644 --- a/test/TypeScript/src/lib/Imported.lf +++ b/test/TypeScript/src/lib/Imported.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/lib/ImportedAgain.lf b/test/TypeScript/src/lib/ImportedAgain.lf index e0093e3b10..a98513b692 100644 --- a/test/TypeScript/src/lib/ImportedAgain.lf +++ b/test/TypeScript/src/lib/ImportedAgain.lf @@ -1,5 +1,5 @@ -// This is used by the test for the ability to import a reactor definition that -// itself imports a reactor definition. +// This is used by the test for the ability to import a reactor definition that itself imports a +// reactor definition. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/lib/LoopedActionSender.lf b/test/TypeScript/src/lib/LoopedActionSender.lf index 7da4c133b0..eb441ff2e8 100644 --- a/test/TypeScript/src/lib/LoopedActionSender.lf +++ b/test/TypeScript/src/lib/LoopedActionSender.lf @@ -7,10 +7,9 @@ target TypeScript /** - * @param takeBreakAfter: Indicates how many messages are sent in consecutive - * superdense time - * @param breakInterval: Determines how long the reactor should take a break - * after sending takeBreakAfter messages. + * @param takeBreakAfter: Indicates how many messages are sent in consecutive superdense time + * @param breakInterval: Determines how long the reactor should take a break after sending + * takeBreakAfter messages. */ reactor Sender(takeBreakAfter: number = 10, breakInterval: time = 400 msec) { output out: number diff --git a/test/TypeScript/src/lib/TestCount.lf b/test/TypeScript/src/lib/TestCount.lf index 822b4c64b1..d5181f10f0 100644 --- a/test/TypeScript/src/lib/TestCount.lf +++ b/test/TypeScript/src/lib/TestCount.lf @@ -1,7 +1,6 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. diff --git a/test/TypeScript/src/multiport/BankMulticast.lf b/test/TypeScript/src/multiport/BankMulticast.lf index 610306e30e..84a7acb6c6 100644 --- a/test/TypeScript/src/multiport/BankMulticast.lf +++ b/test/TypeScript/src/multiport/BankMulticast.lf @@ -1,6 +1,6 @@ /** - * This tests that a contained bank can send not only to a local connection, but - * also multicast via the container's output port. + * This tests that a contained bank can send not only to a local connection, but also multicast via + * the container's output port. */ target TypeScript { timeout: 3 sec diff --git a/test/TypeScript/src/multiport/BankReactionsInContainer.lf b/test/TypeScript/src/multiport/BankReactionsInContainer.lf index b14ca33f70..485f1074f1 100644 --- a/test/TypeScript/src/multiport/BankReactionsInContainer.lf +++ b/test/TypeScript/src/multiport/BankReactionsInContainer.lf @@ -1,6 +1,4 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target TypeScript { timeout: 1 sec } diff --git a/test/TypeScript/src/multiport/BankSelfBroadcast.lf b/test/TypeScript/src/multiport/BankSelfBroadcast.lf index cf5af4bee3..50d6683592 100644 --- a/test/TypeScript/src/multiport/BankSelfBroadcast.lf +++ b/test/TypeScript/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport - * input of the same reactors in the bank so that each reactor in the bank - * receives the output produced by itself and each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport input of the same + * reactors in the bank so that each reactor in the bank receives the output produced by itself and + * each other reactor. * * @author Edward A. Lee * @author Christian Menard diff --git a/test/TypeScript/src/multiport/MultiportFromBank.lf b/test/TypeScript/src/multiport/MultiportFromBank.lf index 18896eed2a..53f8c523ee 100644 --- a/test/TypeScript/src/multiport/MultiportFromBank.lf +++ b/test/TypeScript/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf index ffc394b26c..c896494897 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf index 96b25104a4..1462f157a5 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf index 5627652b2f..b294dc3995 100644 --- a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input, where the former is a hierarchical -// reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportIn.lf b/test/TypeScript/src/multiport/MultiportIn.lf index 97a36c08d2..346eeffa11 100644 --- a/test/TypeScript/src/multiport/MultiportIn.lf +++ b/test/TypeScript/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version of the test that uses a multiport input at the destination. -// Its purpose is to test multiport inputs. +// This is a version of the test that uses a multiport input at the destination. Its purpose is to +// test multiport inputs. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportInParameterized.lf b/test/TypeScript/src/multiport/MultiportInParameterized.lf index fb11c5e102..3ff15c14dc 100644 --- a/test/TypeScript/src/multiport/MultiportInParameterized.lf +++ b/test/TypeScript/src/multiport/MultiportInParameterized.lf @@ -1,5 +1,5 @@ -// This is a version of the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version of the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportMutableInput.lf b/test/TypeScript/src/multiport/MultiportMutableInput.lf index 11120e8d30..c570b5b245 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInput.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInput.lf @@ -1,6 +1,5 @@ -// Source produces a ints on a multiport, which it passes to Scale. Scale -// requests a writable copy. It modifies it and passes it to Print. It gets -// freed after Print is done with it. +// Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. +// It modifies it and passes it to Print. It gets freed after Print is done with it. target TypeScript reactor Source { diff --git a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf index 382f444df7..d91b6aa8ac 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf @@ -1,7 +1,6 @@ -// Source produces a dynamically allocated arrays on a multiport, which it -// passes to Scale. Scale requests a writable copy, which, instead of copying, -// it just gets ownership of the original array. It modifies it and passes it to -// Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated arrays on a multiport, which it passes to Scale. Scale +// requests a writable copy, which, instead of copying, it just gets ownership of the original +// array. It modifies it and passes it to Print. It gets freed after Print is done with it. target TypeScript reactor Source { diff --git a/test/TypeScript/src/multiport/MultiportToBankAfter.lf b/test/TypeScript/src/multiport/MultiportToBankAfter.lf index ee10df94c6..b8005863ff 100644 --- a/test/TypeScript/src/multiport/MultiportToBankAfter.lf +++ b/test/TypeScript/src/multiport/MultiportToBankAfter.lf @@ -1,5 +1,4 @@ -// Check multiport output to bank of recipients where the width of the bank is -// inferred. +// Check multiport output to bank of recipients where the width of the bank is inferred. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToBankDouble.lf b/test/TypeScript/src/multiport/MultiportToBankDouble.lf index e618dd898d..32b5e86b7c 100644 --- a/test/TypeScript/src/multiport/MultiportToBankDouble.lf +++ b/test/TypeScript/src/multiport/MultiportToBankDouble.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients where the source has two -// reactions that write to the output. +// Check multiport output to bank of recipients where the source has two reactions that write to the +// output. target TypeScript { timeout: 2 sec } @@ -13,8 +13,8 @@ reactor Source { } =} - // Test also that multiple appearances of the same effect port do not result - // in multiple allocations of memory for the port. + // Test also that multiple appearances of the same effect port do not result in multiple + // allocations of memory for the port. reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) for (let i = 0; i < out.length; i++) { diff --git a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf index 7420704ce1..a2e60ef8c2 100644 --- a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToHierarchy.lf b/test/TypeScript/src/multiport/MultiportToHierarchy.lf index c620000872..01edeb3192 100644 --- a/test/TypeScript/src/multiport/MultiportToHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToHierarchy.lf @@ -1,6 +1,5 @@ -// Check multiport output to multiport input, where the latter is a hierarchical -// reactor. Note that the destination reactor has width wider than the sender, -// so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +// the destination reactor has width wider than the sender, so one input is dangling. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf index 737603a5bd..ba1f578f09 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToPort.lf b/test/TypeScript/src/multiport/MultiportToPort.lf index a00d482fe8..caf87f1d3b 100644 --- a/test/TypeScript/src/multiport/MultiportToPort.lf +++ b/test/TypeScript/src/multiport/MultiportToPort.lf @@ -1,5 +1,4 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/ReactionsToNested.lf b/test/TypeScript/src/multiport/ReactionsToNested.lf index 055e08d086..514973762a 100644 --- a/test/TypeScript/src/multiport/ReactionsToNested.lf +++ b/test/TypeScript/src/multiport/ReactionsToNested.lf @@ -1,5 +1,4 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target TypeScript { timeout: 1 sec } diff --git a/test/TypeScript/src/serialization/ProtoNoPacking.lf b/test/TypeScript/src/serialization/ProtoNoPacking.lf index d0867da282..02c6f71c0e 100644 --- a/test/TypeScript/src/serialization/ProtoNoPacking.lf +++ b/test/TypeScript/src/serialization/ProtoNoPacking.lf @@ -1,12 +1,10 @@ /** - * This example creates a Protocol Buffer message and passes it to another - * reactor without packing and unpacking. This demonstrates that local - * communication, within one shared-memory machine, need not incur the overhead - * of packing and unpacking. + * This example creates a Protocol Buffer message and passes it to another reactor without packing + * and unpacking. This demonstrates that local communication, within one shared-memory machine, need + * not incur the overhead of packing and unpacking. * * To run this example first install the protocol buffers compiler from - * https://github.com/protocolbuffers/protobuf. It is also available from - * homebrew on a Mac via + * https://github.com/protocolbuffers/protobuf. It is also available from homebrew on a Mac via * * $ brew install protobuf * diff --git a/test/TypeScript/src/target/AfterNoTypes.lf b/test/TypeScript/src/target/AfterNoTypes.lf index b3477bbf55..5d698cb3e0 100644 --- a/test/TypeScript/src/target/AfterNoTypes.lf +++ b/test/TypeScript/src/target/AfterNoTypes.lf @@ -1,5 +1,4 @@ -// This test demonstrates that after can be used on connections with ports that -// have no types. +// This test demonstrates that after can be used on connections with ports that have no types. target TypeScript { fast: false, timeout: 3 sec From 7171392a8d03f0f226d78048d4f1b721cc8536e4 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 5 Oct 2022 19:26:01 -0700 Subject: [PATCH 414/709] Reformat LF tests with 2 spaces of indentation. --- README.md | 2 - REQUIREMENTS.md | 34 ++--- test/C/src/ActionWithNoReaction.lf | 40 +++--- test/C/src/After.lf | 3 +- test/C/src/AfterCycles.lf | 4 +- test/C/src/AfterZero.lf | 3 +- test/C/src/Alignment.lf | 3 +- test/C/src/ArrayAsParameter.lf | 5 +- test/C/src/ArrayAsType.lf | 4 +- test/C/src/ArrayParallel.lf | 18 +-- test/C/src/Composition.lf | 3 +- test/C/src/CompositionAfter.lf | 3 +- test/C/src/CompositionGain.lf | 40 +++--- test/C/src/CompositionInheritance.lf | 3 +- test/C/src/CountTest.lf | 12 +- test/C/src/DanglingOutput.lf | 24 ++-- test/C/src/Deadline.lf | 5 +- test/C/src/DeadlineAnytime.lf | 30 ++--- test/C/src/DeadlineHandledAbove.lf | 4 +- test/C/src/DelayArrayWithAfter.lf | 3 +- test/C/src/DelayInt.lf | 4 +- test/C/src/DelayString.lf | 3 +- test/C/src/DelayedReaction.lf | 30 ++--- test/C/src/Determinism.lf | 60 ++++----- test/C/src/DoubleInvocation.lf | 9 +- test/C/src/DoublePort.lf | 9 +- test/C/src/DoubleReaction.lf | 4 +- test/C/src/DoubleTrigger.lf | 3 +- test/C/src/FloatLiteral.lf | 3 +- test/C/src/GetTime.lf | 28 ++-- test/C/src/Hierarchy.lf | 64 ++++----- test/C/src/Import.lf | 6 +- test/C/src/ImportComposition.lf | 3 +- test/C/src/ImportRenamed.lf | 10 +- test/C/src/InheritanceAction.lf | 3 +- test/C/src/Microsteps.lf | 62 ++++----- test/C/src/Minimal.lf | 2 +- test/C/src/MovingAverage.lf | 5 +- test/C/src/MultipleContained.lf | 3 +- test/C/src/MultipleOutputs.lf | 7 +- test/C/src/PingPong.lf | 17 ++- test/C/src/Preamble.lf | 30 ++--- test/C/src/ReadOutputOfContainedReactor.lf | 3 +- test/C/src/RepeatedInheritance.lf | 26 ++-- test/C/src/RequestStop.lf | 3 +- test/C/src/Schedule.lf | 28 ++-- test/C/src/ScheduleLogicalAction.lf | 4 +- test/C/src/ScheduleValue.lf | 28 ++-- test/C/src/SendingInside.lf | 4 +- test/C/src/SendingInside2.lf | 22 +-- test/C/src/SendsPointerTest.lf | 4 +- test/C/src/SetArray.lf | 4 +- test/C/src/SimpleDeadline.lf | 5 +- test/C/src/SimpleImport.lf | 4 +- test/C/src/SlowingClock.lf | 7 +- test/C/src/SlowingClockPhysical.lf | 9 +- test/C/src/StartupOutFromInside.lf | 20 +-- test/C/src/Starvation.lf | 4 +- test/C/src/StopZero.lf | 4 +- test/C/src/Stride.lf | 4 +- test/C/src/StructPrint.lf | 4 +- test/C/src/TestForPreviousOutput.lf | 54 ++++---- test/C/src/TimeLimit.lf | 5 +- test/C/src/TimeoutZero.lf | 3 +- test/C/src/TriggerDownstreamOnlyIfPresent2.lf | 5 +- test/C/src/Wcet.lf | 58 ++++---- test/C/src/arduino/AnalogReadSerial.lf | 7 +- test/C/src/arduino/Blink.lf | 5 +- test/C/src/arduino/BlinkAttemptThreading.lf | 7 +- test/C/src/arduino/BlinkMBED.lf | 5 +- test/C/src/arduino/Fade.lf | 9 +- test/C/src/arduino/ReadAnalogVoltage.lf | 9 +- test/C/src/concurrent/AsyncCallback.lf | 10 +- test/C/src/concurrent/AsyncCallbackDrop.lf | 7 +- test/C/src/concurrent/AsyncCallbackReplace.lf | 7 +- test/C/src/concurrent/CompositionThreaded.lf | 3 +- .../DeadlineHandledAboveThreaded.lf | 4 +- test/C/src/concurrent/DeadlineThreaded.lf | 5 +- test/C/src/concurrent/DeterminismThreaded.lf | 60 ++++----- .../src/concurrent/DoubleReactionThreaded.lf | 4 +- test/C/src/concurrent/ImportThreaded.lf | 6 +- test/C/src/concurrent/MinimalThreaded.lf | 4 +- test/C/src/concurrent/PingPongThreaded.lf | 20 +-- .../C/src/concurrent/SendingInsideThreaded.lf | 4 +- test/C/src/concurrent/StarvationThreaded.lf | 5 +- test/C/src/concurrent/StopThreaded.lf | 4 +- test/C/src/concurrent/StopZeroThreaded.lf | 3 +- test/C/src/concurrent/Threaded.lf | 19 +-- test/C/src/concurrent/ThreadedMultiport.lf | 3 +- test/C/src/concurrent/ThreadedThreaded.lf | 16 ++- test/C/src/concurrent/TimeLimitThreaded.lf | 4 +- test/C/src/concurrent/TimeoutThreaded.lf | 3 +- test/C/src/concurrent/TimeoutZeroThreaded.lf | 4 +- test/C/src/concurrent/Tracing.lf | 3 +- test/C/src/concurrent/Workers.lf | 16 +-- .../src/docker/FilesPropertyContainerized.lf | 14 +- test/C/src/docker/HelloWorldContainerized.lf | 14 +- test/C/src/docker/PingPongContainerized.lf | 12 +- .../DistributedCountContainerized.lf | 7 +- .../DistributedDoublePortContainerized.lf | 18 +-- .../DistributedMultiportContainerized.lf | 12 +- ...stributedStopDecentralizedContainerized.lf | 10 +- test/C/src/federated/BroadcastFeedback.lf | 4 +- .../BroadcastFeedbackWithHierarchy.lf | 4 +- test/C/src/federated/ChainWithDelay.lf | 12 +- test/C/src/federated/CycleDetection.lf | 4 +- .../DecentralizedP2PUnbalancedTimeout.lf | 11 +- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 15 ++- test/C/src/federated/DistributedCount.lf | 7 +- .../DistributedCountDecentralized.lf | 10 +- .../src/federated/DistributedCountPhysical.lf | 8 +- .../DistributedCountPhysicalAfterDelay.lf | 9 +- .../DistributedCountPhysicalDecentralized.lf | 8 +- test/C/src/federated/DistributedDoublePort.lf | 9 +- .../DistributedLogicalActionUpstreamLong.lf | 4 +- .../src/federated/DistributedLoopedAction.lf | 6 +- .../DistributedLoopedActionDecentralized.lf | 23 ++-- .../DistributedLoopedPhysicalAction.lf | 16 ++- ...ibutedLoopedPhysicalActionDecentralized.lf | 10 +- .../federated/DistributedMultiportToken.lf | 4 +- .../src/federated/DistributedNetworkOrder.lf | 7 +- .../DistributedPhysicalActionUpstream.lf | 4 +- .../DistributedPhysicalActionUpstreamLong.lf | 4 +- test/C/src/federated/DistributedStop.lf | 3 +- .../federated/DistributedStopDecentralized.lf | 8 +- test/C/src/federated/DistributedStopZero.lf | 126 +++++++++--------- .../DistributedStopZeroDecentralized.lf | 6 +- test/C/src/federated/HelloDistributed.lf | 11 +- .../federated/LoopDistributedCentralized.lf | 3 +- .../LoopDistributedCentralizedPrecedence.lf | 4 +- ...stributedCentralizedPrecedenceHierarchy.lf | 5 +- .../federated/LoopDistributedDecentralized.lf | 3 +- test/C/src/federated/LoopDistributedDouble.lf | 3 +- test/C/src/federated/ParallelDestinations.lf | 18 +-- test/C/src/federated/ParallelSources.lf | 18 +-- .../src/federated/ParallelSourcesMultiport.lf | 30 ++--- test/C/src/federated/PhysicalSTP.lf | 5 +- test/C/src/federated/PingPongDistributed.lf | 17 ++- .../federated/PingPongDistributedPhysical.lf | 18 +-- test/C/src/federated/SimpleFederated.lf | 16 +-- test/C/src/federated/StopAtShutdown.lf | 24 ++-- test/C/src/federated/TopLevelArtifacts.lf | 7 +- test/C/src/federated/failing/ClockSync.lf | 29 ++-- test/C/src/lib/Imported.lf | 6 +- test/C/src/lib/ImportedAgain.lf | 16 +-- test/C/src/lib/ImportedComposition.lf | 20 +-- test/C/src/lib/LoopedActionSender.lf | 7 +- test/C/src/lib/TestCount.lf | 5 +- .../src/modal_models/BanksModalStateReset.lf | 8 +- test/C/src/modal_models/Count3Modes.lf | 6 +- test/C/src/modal_models/MixedReactions.lf | 4 +- .../src/modal_models/ModalNestedReactions.lf | 94 ++++++------- test/C/src/multiport/BankGangedConnections.lf | 24 ++-- test/C/src/multiport/BankMulticast.lf | 30 ++--- .../src/multiport/BankReactionsInContainer.lf | 4 +- test/C/src/multiport/BankSelfBroadcast.lf | 6 +- test/C/src/multiport/MultiportFromBank.lf | 8 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 10 +- .../C/src/multiport/MultiportFromHierarchy.lf | 3 +- test/C/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 7 +- test/C/src/multiport/MultiportMutableInput.lf | 5 +- .../multiport/MultiportMutableInputArray.lf | 7 +- test/C/src/multiport/MultiportToBank.lf | 7 +- test/C/src/multiport/MultiportToBankAfter.lf | 3 +- test/C/src/multiport/MultiportToBankDouble.lf | 8 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- test/C/src/multiport/MultiportToHierarchy.lf | 5 +- .../multiport/MultiportToMultiportArray.lf | 3 +- test/C/src/multiport/MultiportToPort.lf | 3 +- test/C/src/multiport/PipelineAfter.lf | 44 +++--- .../ReactionToContainedBankMultiport.lf | 3 +- test/C/src/multiport/ReactionsToNested.lf | 3 +- test/C/src/multiport/SparseFallback.lf | 4 +- .../TriggerDownstreamOnlyIfPresent.lf | 5 +- .../serialization/PersonProtocolBuffers.lf | 36 ++--- test/C/src/serialization/ProtoNoPacking.lf | 28 ++-- .../ROSBuiltInSerializationSharedPtr.lf | 13 +- test/C/src/target/CMakeInclude.lf | 32 ++--- test/C/src/target/DistributedCMakeInclude.lf | 30 ++--- .../DistributedCMakeIncludeSeparateCompile.lf | 6 +- test/C/src/target/Files.lf | 16 +-- test/C/src/target/HelloWorldCCPP.lf | 4 +- test/C/src/target/HelloWorldFederatedCCPP.lf | 10 +- test/C/src/target/HelloWorldThreadedCPP.lf | 6 +- test/C/src/target/Platform.lf | 4 +- test/C/src/target/lib/ImportedCMakeInclude.lf | 22 +-- test/Cpp/src/ActionWithNoReaction.lf | 40 +++--- test/Cpp/src/After.lf | 3 +- test/Cpp/src/AfterZero.lf | 3 +- test/Cpp/src/Alignment.lf | 3 +- test/Cpp/src/ArrayAsParameter.lf | 3 +- test/Cpp/src/ArrayAsType.lf | 74 +++++----- test/Cpp/src/ArrayParallel.lf | 18 +-- test/Cpp/src/ArrayPrint.lf | 5 +- test/Cpp/src/ArrayScale.lf | 5 +- test/Cpp/src/Composition.lf | 3 +- test/Cpp/src/CompositionAfter.lf | 3 +- test/Cpp/src/CompositionGain.lf | 40 +++--- test/Cpp/src/DanglingOutput.lf | 24 ++-- test/Cpp/src/Deadline.lf | 5 +- test/Cpp/src/DeadlineHandledAbove.lf | 4 +- test/Cpp/src/DelayedReaction.lf | 28 ++-- test/Cpp/src/Determinism.lf | 60 ++++----- test/Cpp/src/DoubleInvocation.lf | 12 +- test/Cpp/src/DoublePort.lf | 5 +- test/Cpp/src/DoubleReaction.lf | 4 +- test/Cpp/src/DoubleTrigger.lf | 3 +- test/Cpp/src/GetTime.lf | 28 ++-- test/Cpp/src/HelloWorld.lf | 6 +- test/Cpp/src/Hierarchy.lf | 60 ++++----- test/Cpp/src/Import.lf | 6 +- test/Cpp/src/ImportComposition.lf | 3 +- test/Cpp/src/ImportRenamed.lf | 10 +- test/Cpp/src/ManualDelayedReaction.lf | 6 +- test/Cpp/src/Microsteps.lf | 66 ++++----- test/Cpp/src/Minimal.lf | 2 +- test/Cpp/src/MovingAverage.lf | 6 +- test/Cpp/src/MultipleContained.lf | 46 +++---- test/Cpp/src/PreambleTest.lf | 46 +++---- test/Cpp/src/ReadOutputOfContainedReactor.lf | 3 +- test/Cpp/src/Schedule.lf | 32 ++--- test/Cpp/src/ScheduleLogicalAction.lf | 4 +- test/Cpp/src/SendingInside.lf | 4 +- test/Cpp/src/SendingInside2.lf | 22 +-- test/Cpp/src/SimpleDeadline.lf | 5 +- test/Cpp/src/SimpleImport.lf | 4 +- test/Cpp/src/SlowingClock.lf | 7 +- test/Cpp/src/SlowingClockPhysical.lf | 9 +- test/Cpp/src/StartupOutFromInside.lf | 20 +-- test/Cpp/src/Stride.lf | 4 +- test/Cpp/src/StructAsState.lf | 18 +-- test/Cpp/src/StructAsType.lf | 20 +-- test/Cpp/src/StructAsTypeDirect.lf | 18 +-- test/Cpp/src/StructParallel.lf | 20 +-- test/Cpp/src/StructScale.lf | 5 +- test/Cpp/src/TestForPreviousOutput.lf | 56 ++++---- test/Cpp/src/TimeLimit.lf | 5 +- .../src/TriggerDownstreamOnlyIfPresent2.lf | 3 +- .../Cpp/src/concurrent/CompositionThreaded.lf | 3 +- .../DeadlineHandledAboveThreaded.lf | 4 +- test/Cpp/src/concurrent/DeadlineThreaded.lf | 5 +- .../Cpp/src/concurrent/DeterminismThreaded.lf | 60 ++++----- .../src/concurrent/DoubleReactionThreaded.lf | 4 +- test/Cpp/src/concurrent/ImportThreaded.lf | 6 +- test/Cpp/src/concurrent/MinimalThreaded.lf | 2 +- .../src/concurrent/SendingInsideThreaded.lf | 4 +- test/Cpp/src/concurrent/Threaded.lf | 14 +- test/Cpp/src/concurrent/ThreadedThreaded.lf | 14 +- test/Cpp/src/concurrent/TimeLimitThreaded.lf | 7 +- test/Cpp/src/concurrent/Workers.lf | 18 +-- test/Cpp/src/lib/Imported.lf | 6 +- test/Cpp/src/lib/ImportedAgain.lf | 20 +-- test/Cpp/src/lib/ImportedComposition.lf | 20 +-- test/Cpp/src/lib/LoopedActionSender.lf | 7 +- test/Cpp/src/multiport/BankSelfBroadcast.lf | 6 +- .../src/multiport/IndexIntoMultiportInput.lf | 56 ++++---- .../src/multiport/IndexIntoMultiportOutput.lf | 5 +- test/Cpp/src/multiport/MultiportFromBank.lf | 4 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 4 +- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/Cpp/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- .../Cpp/src/multiport/MultiportToHierarchy.lf | 5 +- .../multiport/MultiportToMultiportArray.lf | 3 +- test/Cpp/src/multiport/MultiportToPort.lf | 3 +- test/Cpp/src/multiport/PipelineAfter.lf | 44 +++--- .../ReadMultiportOutputOfContainedBank.lf | 3 +- .../multiport/ReadOutputOfContainedBank.lf | 3 +- .../src/target/BraceAndParenInitialization.lf | 6 +- test/Cpp/src/target/CMakeInclude.lf | 22 +-- test/Cpp/src/target/PreambleFile.lf | 60 ++++----- test/Python/src/ActionWithNoReaction.lf | 40 +++--- test/Python/src/After.lf | 3 +- test/Python/src/AfterCycles.lf | 4 +- test/Python/src/ArrayAsType.lf | 4 +- test/Python/src/ArrayFree.lf | 8 +- test/Python/src/ArrayParallel.lf | 18 +-- test/Python/src/ArrayPrint.lf | 4 +- test/Python/src/ArrayScale.lf | 7 +- test/Python/src/Composition.lf | 3 +- test/Python/src/CompositionAfter.lf | 3 +- test/Python/src/CompositionGain.lf | 38 +++--- test/Python/src/CompositionInheritance.lf | 3 +- test/Python/src/DanglingOutput.lf | 24 ++-- test/Python/src/Deadline.lf | 5 +- test/Python/src/DeadlineHandledAbove.lf | 4 +- test/Python/src/DelayArrayWithAfter.lf | 3 +- test/Python/src/DelayString.lf | 3 +- test/Python/src/DelayedReaction.lf | 28 ++-- test/Python/src/Determinism.lf | 54 ++++---- test/Python/src/DoubleInvocation.lf | 9 +- test/Python/src/DoubleReaction.lf | 4 +- test/Python/src/GetTime.lf | 28 ++-- test/Python/src/Hello.lf | 14 +- test/Python/src/Hierarchy.lf | 62 ++++----- test/Python/src/Import.lf | 6 +- test/Python/src/ImportComposition.lf | 3 +- test/Python/src/ImportRenamed.lf | 10 +- test/Python/src/ManualDelayedReaction.lf | 9 +- test/Python/src/Microsteps.lf | 54 ++++---- test/Python/src/Minimal.lf | 2 +- test/Python/src/MovingAverage.lf | 5 +- test/Python/src/MultipleContained.lf | 3 +- test/Python/src/PingPong.lf | 17 ++- test/Python/src/Preamble.lf | 30 ++--- .../src/ReadOutputOfContainedReactor.lf | 3 +- test/Python/src/Schedule.lf | 26 ++-- test/Python/src/ScheduleLogicalAction.lf | 4 +- test/Python/src/ScheduleValue.lf | 24 ++-- test/Python/src/SendingInside.lf | 4 +- test/Python/src/SendingInside2.lf | 20 +-- test/Python/src/SetArray.lf | 5 +- test/Python/src/SimpleDeadline.lf | 5 +- test/Python/src/SimpleImport.lf | 4 +- test/Python/src/SlowingClock.lf | 6 +- test/Python/src/StartupOutFromInside.lf | 18 +-- test/Python/src/Stride.lf | 4 +- test/Python/src/StructAsState.lf | 3 +- test/Python/src/StructPrint.lf | 4 +- test/Python/src/TestForPreviousOutput.lf | 50 +++---- test/Python/src/TimeLimit.lf | 5 +- .../src/TriggerDownstreamOnlyIfPresent.lf | 5 +- .../src/TriggerDownstreamOnlyIfPresent2.lf | 5 +- test/Python/src/Wcet.lf | 56 ++++---- test/Python/src/concurrent/AsyncCallback.lf | 5 +- .../src/concurrent/AsyncCallbackNoTimer.lf | 12 +- .../src/docker/HelloWorldContainerized.lf | 4 +- .../src/docker/PingPongContainerized.lf | 12 +- .../DistributedCountContainerized.lf | 7 +- .../DistributedDoublePortContainerized.lf | 18 +-- .../DistributedMultiportContainerized.lf | 12 +- .../DistributedSendClassContainerized.lf | 10 +- ...stributedStopDecentralizedContainerized.lf | 10 +- .../Python/src/federated/BroadcastFeedback.lf | 4 +- .../BroadcastFeedbackWithHierarchy.lf | 4 +- test/Python/src/federated/ChainWithDelay.lf | 12 +- test/Python/src/federated/CycleDetection.lf | 4 +- .../DecentralizedP2PUnbalancedTimeout.lf | 7 +- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 11 +- test/Python/src/federated/DistributedCount.lf | 7 +- .../DistributedCountDecentralized.lf | 10 +- .../src/federated/DistributedCountPhysical.lf | 8 +- .../DistributedCountPhysicalAfterDelay.lf | 8 +- .../DistributedCountPhysicalDecentralized.lf | 8 +- .../src/federated/DistributedDoublePort.lf | 9 +- .../src/federated/DistributedLoopedAction.lf | 6 +- ...ibutedLoopedPhysicalActionDecentralized.lf | 10 +- .../federated/DistributedMultiportToken.lf | 4 +- .../src/federated/DistributedNoReact.lf | 20 +-- .../federated/DistributedStopDecentralized.lf | 8 +- .../src/federated/DistributedStructAsType.lf | 10 +- .../DistributedStructAsTypeDirect.lf | 10 +- .../federated/DistributedStructParallel.lf | 22 +-- .../src/federated/DistributedStructPrint.lf | 10 +- .../src/federated/DistributedStructScale.lf | 14 +- test/Python/src/federated/HelloDistributed.lf | 10 +- ...stributedCentralizedPrecedenceHierarchy.lf | 5 +- .../src/federated/ParallelDestinations.lf | 18 +-- test/Python/src/federated/ParallelSources.lf | 18 +-- .../src/federated/ParallelSourcesMultiport.lf | 30 ++--- test/Python/src/federated/PhysicalSTP.lf | 5 +- .../src/federated/PingPongDistributed.lf | 16 ++- test/Python/src/lib/Imported.lf | 6 +- test/Python/src/lib/ImportedAgain.lf | 14 +- test/Python/src/lib/ImportedComposition.lf | 20 +-- test/Python/src/lib/LoopedActionSender.lf | 7 +- test/Python/src/lib/TestCount.lf | 5 +- test/Python/src/lib/TestCountMultiport.lf | 11 +- .../modal_models/BanksCount3ModesSimple.lf | 40 +++--- .../src/modal_models/BanksModalStateReset.lf | 8 +- .../src/modal_models/ConvertCaseTest.lf | 4 +- test/Python/src/modal_models/ModalActions.lf | 7 +- .../src/modal_models/ModalCycleBreaker.lf | 8 +- .../src/modal_models/ModalNestedReactions.lf | 92 ++++++------- .../src/modal_models/ModalStartupShutdown.lf | 3 +- .../src/modal_models/ModalStateReset.lf | 3 +- .../src/modal_models/ModalStateResetAuto.lf | 3 +- test/Python/src/modal_models/ModalTimers.lf | 3 +- .../MultipleOutputFeeder_2Connections.lf | 10 +- ...ultipleOutputFeeder_ReactionConnections.lf | 14 +- .../src/multiport/BankReactionsInContainer.lf | 4 +- test/Python/src/multiport/BroadcastAfter.lf | 10 +- .../Python/src/multiport/MultiportFromBank.lf | 8 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 10 +- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/Python/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 4 +- .../src/multiport/MultiportMutableInput.lf | 5 +- .../multiport/MultiportMutableInputArray.lf | 7 +- .../src/multiport/MultiportToBankAfter.lf | 3 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- .../src/multiport/MultiportToHierarchy.lf | 5 +- .../multiport/MultiportToMultiportArray.lf | 3 +- test/Python/src/multiport/MultiportToPort.lf | 3 +- test/Python/src/multiport/PipelineAfter.lf | 40 +++--- .../Python/src/multiport/ReactionsToNested.lf | 3 +- .../serialization/PersonProtocolBuffers.lf | 28 ++-- .../src/serialization/ProtoNoPacking.lf | 30 ++--- test/Python/src/target/AfterNoTypes.lf | 4 +- test/Rust/src/ActionIsPresentDouble.lf | 28 ++-- test/Rust/src/ActionValuesCleanup.lf | 4 +- .../src/CompositionInitializationOrder.lf | 10 +- test/Rust/src/DependencyOnChildPort.lf | 4 +- test/Rust/src/DependencyThroughChildPort.lf | 70 +++++----- test/Rust/src/DependencyUseAccessible.lf | 60 ++++----- test/Rust/src/DependencyUseNonTrigger.lf | 18 +-- test/Rust/src/Import.lf | 6 +- test/Rust/src/ImportPreambleItem.lf | 4 +- test/Rust/src/Minimal.lf | 2 +- ...ysicalActionCanBeScheduledSynchronously.lf | 34 ++--- .../src/PhysicalActionKeepaliveIsSmart.lf | 30 ++--- .../PhysicalActionWakesSleepingScheduler.lf | 28 ++-- test/Rust/src/PhysicalActionWithKeepalive.lf | 34 ++--- test/Rust/src/Preamble.lf | 12 +- test/Rust/src/ReactionLabels.lf | 4 +- test/Rust/src/ReservedKeywords.lf | 3 +- test/Rust/src/SingleFileGeneration.lf | 30 ++--- test/Rust/src/StateDefaultValue.lf | 18 +-- test/Rust/src/StateInitializerVisibility.lf | 4 +- test/Rust/src/Stop.lf | 7 +- test/Rust/src/StopAsync.lf | 22 +-- test/Rust/src/StopCleanup.lf | 30 ++--- test/Rust/src/StopDuringStartup.lf | 20 +-- test/Rust/src/StopNoEvent.lf | 2 +- test/Rust/src/StopTimeout.lf | 10 +- test/Rust/src/StopTimeoutExact.lf | 4 +- test/Rust/src/StopTopology.lf | 24 ++-- test/Rust/src/StructAsState.lf | 4 +- test/Rust/src/concurrent/Workers.lf | 16 +-- test/Rust/src/generics/GenericReactor.lf | 4 +- test/Rust/src/lib/Imported.lf | 6 +- test/Rust/src/lib/ImportedAgain.lf | 10 +- test/Rust/src/lib/SomethingWithAPreamble.lf | 12 +- test/Rust/src/multiport/CycledLhs_SelfLoop.lf | 8 +- test/Rust/src/multiport/CycledLhs_Single.lf | 14 +- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/Rust/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportToMultiport2.lf | 3 +- .../src/target/BuildProfileDefaultIsDev.lf | 8 +- test/Rust/src/target/BuildProfileRelease.lf | 10 +- test/Rust/src/target/CargoDependency.lf | 18 +-- .../src/target/CargoDependencyOnRuntime.lf | 10 +- test/Rust/src/target/ModuleDependency.lf | 14 +- .../target/ModuleDependencyWithDirModule.lf | 16 +-- test/TypeScript/src/ActionWithNoReaction.lf | 40 +++--- test/TypeScript/src/After.lf | 3 +- test/TypeScript/src/ArrayAsType.lf | 5 +- test/TypeScript/src/ArrayPrint.lf | 5 +- test/TypeScript/src/ArrayScale.lf | 7 +- test/TypeScript/src/Composition.lf | 3 +- test/TypeScript/src/CompositionAfter.lf | 3 +- test/TypeScript/src/DanglingOutput.lf | 24 ++-- test/TypeScript/src/Deadline.lf | 5 +- test/TypeScript/src/DeadlineHandledAbove.lf | 4 +- test/TypeScript/src/DelayInt.lf | 4 +- test/TypeScript/src/DelayedReaction.lf | 28 ++-- test/TypeScript/src/Determinism.lf | 58 ++++---- test/TypeScript/src/DoubleInvocation.lf | 9 +- test/TypeScript/src/DoubleReaction.lf | 4 +- test/TypeScript/src/DoubleTrigger.lf | 3 +- test/TypeScript/src/GetTime.lf | 26 ++-- test/TypeScript/src/HelloWorld.lf | 6 +- test/TypeScript/src/Hierarchy.lf | 70 +++++----- test/TypeScript/src/Import.lf | 8 +- test/TypeScript/src/Microsteps.lf | 58 ++++---- test/TypeScript/src/Minimal.lf | 4 +- test/TypeScript/src/MovingAverage.lf | 5 +- test/TypeScript/src/MultipleContained.lf | 48 +++---- test/TypeScript/src/Preamble.lf | 28 ++-- .../src/ReadOutputOfContainedReactor.lf | 3 +- test/TypeScript/src/Schedule.lf | 30 ++--- test/TypeScript/src/ScheduleLogicalAction.lf | 4 +- test/TypeScript/src/SendingInside.lf | 4 +- test/TypeScript/src/SendingInside2.lf | 20 +-- test/TypeScript/src/SendsPointerTest.lf | 4 +- test/TypeScript/src/SimpleDeadline.lf | 5 +- test/TypeScript/src/SimpleImport.lf | 4 +- test/TypeScript/src/SlowingClockPhysical.lf | 14 +- test/TypeScript/src/Stop.lf | 3 +- test/TypeScript/src/Stride.lf | 4 +- test/TypeScript/src/StructPrint.lf | 4 +- test/TypeScript/src/TestForPreviousOutput.lf | 54 ++++---- test/TypeScript/src/TimeLimit.lf | 7 +- test/TypeScript/src/Wcet.lf | 58 ++++---- .../src/docker/HelloWorldContainerized.lf | 4 +- .../src/federated/ChainWithDelay.lf | 12 +- .../src/federated/DistributedCount.lf | 7 +- .../src/federated/DistributedDoublePort.lf | 9 +- .../src/federated/DistributedLoopedAction.lf | 6 +- .../DistributedLoopedPhysicalAction.lf | 8 +- .../src/federated/DistributedStop.lf | 3 +- .../src/federated/DistributedStopZero.lf | 98 +++++++------- .../src/federated/HelloDistributed.lf | 11 +- .../federated/LoopDistributedCentralized.lf | 3 +- .../src/federated/LoopDistributedDouble.lf | 3 +- .../src/federated/SimpleFederated.lf | 14 +- .../src/federated/StopAtShutdown.lf | 24 ++-- .../src/federated/TopLevelArtifacts.lf | 7 +- test/TypeScript/src/lib/Imported.lf | 8 +- test/TypeScript/src/lib/ImportedAgain.lf | 16 +-- test/TypeScript/src/lib/LoopedActionSender.lf | 7 +- test/TypeScript/src/lib/TestCount.lf | 5 +- .../TypeScript/src/multiport/BankMulticast.lf | 28 ++-- .../src/multiport/BankReactionsInContainer.lf | 4 +- .../src/multiport/BankSelfBroadcast.lf | 6 +- test/TypeScript/src/multiport/Broadcast.lf | 24 ++-- .../src/multiport/MultiportFromBank.lf | 4 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 8 +- .../src/multiport/MultiportFromHierarchy.lf | 3 +- test/TypeScript/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 4 +- .../src/multiport/MultiportMutableInput.lf | 5 +- .../multiport/MultiportMutableInputArray.lf | 7 +- .../src/multiport/MultiportToBank.lf | 32 ++--- .../src/multiport/MultiportToBankAfter.lf | 3 +- .../src/multiport/MultiportToBankDouble.lf | 8 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- .../src/multiport/MultiportToHierarchy.lf | 5 +- .../multiport/MultiportToMultiportArray.lf | 3 +- .../src/multiport/MultiportToPort.lf | 3 +- .../TypeScript/src/multiport/PipelineAfter.lf | 40 +++--- .../src/multiport/ReactionsToNested.lf | 3 +- .../src/serialization/ProtoNoPacking.lf | 42 +++--- test/TypeScript/src/target/AfterNoTypes.lf | 3 +- 529 files changed, 3735 insertions(+), 3411 deletions(-) diff --git a/README.md b/README.md index 4825e78573..8c04a318a5 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,3 @@ Lingua Franca (LF) is a polyglot coordination language for concurrent and possib See [lf-lang.org](https://lf-lang.org) for installation instructions and documentation. See also the [wiki](https://github.com/icyphy/lingua-franca/wiki) for further information on ongoing projects. See our [Publications and Presentations](https://www.lf-lang.org/publications-and-presentations). - - diff --git a/REQUIREMENTS.md b/REQUIREMENTS.md index 9a63d0e71a..ddeff25a77 100644 --- a/REQUIREMENTS.md +++ b/REQUIREMENTS.md @@ -11,7 +11,7 @@ This document includes information about supported operating systems and externa | Windows | >= 10 1903 | Y | Y | Y | Y | ### **Dependencies** - - Java >= 11 +- Java >= 11 In order to develop the core Lingua Franca, the only basic requirement is to have Java >= 11 installed. You should be able to download and run the provided Eclipse development project (see [Downloading and Building](https://github.com/icyphy/lingua-franca/wiki/Downloading-and-Building)). This will get you as far as modifying the under-the-hood code of Lingua Franca, and contributing to the ongoing open-source effort. Please see [Contribution](). @@ -20,7 +20,7 @@ With Java (>= 11), you should also be able to use the provided Eclipse IDE produ However, to compile the generated code and to create a binary (which is done by default), each target language in Lingua Franca has an additional set of requirements, which are listed in this section. We also include a list of tested operating systems in the format of a compact table below. -**Note:** Compiling the generated code is generally automatically done in the Eclipse IDE or while using the `lfc` command line tool. This default behavior can be disabled, however, using the [no-compile](https://github.com/icyphy/lingua-franca/wiki/target-specification#no-compile) target property in your Lingua Franca program or by using the `-n` argument for the `lfc` command line tool (see [Command Line Tools](https://github.com/icyphy/lingua-franca/wiki/Command-Line-Tools)). +**Note:** Compiling the generated code is generally automatically done in the Eclipse IDE or while using the `lfc` command line tool. This default behavior can be disabled, however, using the [no-compile](https://github.com/icyphy/lingua-franca/wiki/target-specification#no-compile) target property in your Lingua Franca program or by using the `-n` argument for the `lfc` command line tool (see [Command Line Tools](https://github.com/icyphy/lingua-franca/wiki/Command-Line-Tools)). ### Supported Operating Systems @@ -34,24 +34,24 @@ However, to compile the generated code and to create a binary (which is done by ### Dependencies **C:** - - A C compiler (e.g., gcc >= 7, clang, or MSVC >= 14.20) - - CMAKE >= 3.13 (follow https://cmake.org/install/ for installation instructions) - - **Windows Only:** Visual Studio >= 2019 and Windows SDK >= 10.0.18362.0 - - **Programs using Protocol Buffers:** protoc-c 1.3.3 - see https://github.com/icyphy/lingua-franca/wiki/Protobufs. +- A C compiler (e.g., gcc >= 7, clang, or MSVC >= 14.20) +- CMAKE >= 3.13 (follow https://cmake.org/install/ for installation instructions) +- **Windows Only:** Visual Studio >= 2019 and Windows SDK >= 10.0.18362.0 +- **Programs using Protocol Buffers:** protoc-c 1.3.3 - see https://github.com/icyphy/lingua-franca/wiki/Protobufs. **C++:** - - g++ >= 7 or MSVC >= 14.20 - 1920 (Visual Studio 2019) - - CMAKE >= 3.16 (follow https://cmake.org/install/ for installation instructions) - - **Windows Only:** Visual Studio >= 2019 and Windows SDK >= 10.0.18362.0 +- g++ >= 7 or MSVC >= 14.20 - 1920 (Visual Studio 2019) +- CMAKE >= 3.16 (follow https://cmake.org/install/ for installation instructions) +- **Windows Only:** Visual Studio >= 2019 and Windows SDK >= 10.0.18362.0 **Python:** - - A C compiler (e.g., gcc >= 7, clang, or MSVC >= 14.20) - - Python >= 3.6 - - pip >= 20.0.2 - - setuptools >= 45.2.0-1 - - **Windows Only:** Visual Studio >= 2019 and Windows SDK >= 10.0.18362.0 - - **Programs using Protocol Buffers:** protoc >= 3.6.1 +- A C compiler (e.g., gcc >= 7, clang, or MSVC >= 14.20) +- Python >= 3.6 +- pip >= 20.0.2 +- setuptools >= 45.2.0-1 +- **Windows Only:** Visual Studio >= 2019 and Windows SDK >= 10.0.18362.0 +- **Programs using Protocol Buffers:** protoc >= 3.6.1 **TypeScript:** - - pnpm >= 6 or npm >= 6.14.4 - - **Programs using Protocol Buffers:** protoc >= 3.6.1 (for using protobuf and data serialization - see https://github.com/icyphy/lingua-franca/wiki/Protobufs) +- pnpm >= 6 or npm >= 6.14.4 +- **Programs using Protocol Buffers:** protoc >= 3.6.1 (for using protobuf and data serialization - see https://github.com/icyphy/lingua-franca/wiki/Protobufs) diff --git a/test/C/src/ActionWithNoReaction.lf b/test/C/src/ActionWithNoReaction.lf index 1cfe5bfba2..87f1c707c2 100644 --- a/test/C/src/ActionWithNoReaction.lf +++ b/test/C/src/ActionWithNoReaction.lf @@ -1,36 +1,36 @@ // This checks that action can be created even if there is no reaction. This test passes merely by // compiling and executing without a segfault. Its other functionality is tested by other tests. target C { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x: int - output y: int - logical action a: int* + input x: int + output y: int + logical action a: int* - reaction(x) -> y, a {= // reaction(a) {= =} - lf_set(y, 2*x->value); - lf_schedule(a, MSEC(500)); - =} + reaction(x) -> y, a {= // reaction(a) {= =} + lf_set(y, 2*x->value); + lf_schedule(a, MSEC(500)); + =} } reactor print { - input x: int + input x: int - reaction(x) {= - printf("Result is %d\n", x->value); - printf("Current logical time is: %lld\n", lf_time_logical_elapsed()); - printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); - =} + reaction(x) {= + printf("Result is %d\n", x->value); + printf("Current logical time is: %lld\n", lf_time_logical_elapsed()); + printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); + =} } main reactor ActionWithNoReaction { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= lf_set(f.x, 42); =} + reaction(t) -> f.x {= lf_set(f.x, 42); =} } diff --git a/test/C/src/After.lf b/test/C/src/After.lf index a066cfcb35..d3663457e4 100644 --- a/test/C/src/After.lf +++ b/test/C/src/After.lf @@ -1,4 +1,5 @@ -// This checks that the after keyword adjusts logical time, not using physical time. +// This checks that the after keyword adjusts logical time, not using physical +// time. target C { fast: false, timeout: 3 sec diff --git a/test/C/src/AfterCycles.lf b/test/C/src/AfterCycles.lf index c79e33bb31..d7d621046b 100644 --- a/test/C/src/AfterCycles.lf +++ b/test/C/src/AfterCycles.lf @@ -1,5 +1,5 @@ -// This tests that "after" does not introduce spurious cycles. Success if running without detected a -// cycle. +// This tests that "after" does not introduce spurious cycles. Success if +// running without detected a cycle. target C reactor Source { diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf index 265f866b59..378114c730 100644 --- a/test/C/src/AfterZero.lf +++ b/test/C/src/AfterZero.lf @@ -1,4 +1,5 @@ -// This checks that the after keyword adjusts logical time, not using physical time. +// This checks that the after keyword adjusts logical time, not using physical +// time. target C { fast: false, timeout: 3 sec diff --git a/test/C/src/Alignment.lf b/test/C/src/Alignment.lf index e63ff904b8..a2b9b523fb 100644 --- a/test/C/src/Alignment.lf +++ b/test/C/src/Alignment.lf @@ -1,4 +1,5 @@ -// This test checks that the downstream reaction is not invoked more than once at a logical time. +// This test checks that the downstream reaction is not invoked more than once +// at a logical time. target C { logging: LOG, timeout: 1 sec diff --git a/test/C/src/ArrayAsParameter.lf b/test/C/src/ArrayAsParameter.lf index 17718f0135..a9df29cb03 100644 --- a/test/C/src/ArrayAsParameter.lf +++ b/test/C/src/ArrayAsParameter.lf @@ -1,5 +1,6 @@ -// Source has an array as a parameter, the elements of which it passes to Print. The length of the -// array has to also be a parameter because C arrays do not encode their own length. +// Source has an array as a parameter, the elements of which it passes to Print. +// The length of the array has to also be a parameter because C arrays do not +// encode their own length. target C reactor Source(sequence: int[] = {0, 1, 2}, n_sequence: int = 3) { diff --git a/test/C/src/ArrayAsType.lf b/test/C/src/ArrayAsType.lf index a24f34e0a6..c95e5bf385 100644 --- a/test/C/src/ArrayAsType.lf +++ b/test/C/src/ArrayAsType.lf @@ -1,5 +1,5 @@ -// Source produces a statically allocated array, which it passes to Print. The destination -// references the array directly. +// Source produces a statically allocated array, which it passes to Print. The +// destination references the array directly. target C reactor Source { diff --git a/test/C/src/ArrayParallel.lf b/test/C/src/ArrayParallel.lf index cc7b9c0e2b..6275924b82 100644 --- a/test/C/src/ArrayParallel.lf +++ b/test/C/src/ArrayParallel.lf @@ -10,13 +10,13 @@ import Scale from "ArrayScale.lf" import Source, Print from "ArrayPrint.lf" main reactor ArrayParallel { - s = new Source() - c1 = new Scale() - c2 = new Scale(scale = 3) - p1 = new Print(scale = 2) - p2 = new Print(scale = 3) - s.out -> c1.in - s.out -> c2.in - c1.out -> p1.in - c2.out -> p2.in + s = new Source() + c1 = new Scale() + c2 = new Scale(scale = 3) + p1 = new Print(scale = 2) + p2 = new Print(scale = 3) + s.out -> c1.in + s.out -> c2.in + c1.out -> p1.in + c2.out -> p2.in } diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index 0f79a7465c..7c024a9eba 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index 98a0703138..cb98ef7d7e 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/CompositionGain.lf b/test/C/src/CompositionGain.lf index 31cd7e5123..0b0ead780f 100644 --- a/test/C/src/CompositionGain.lf +++ b/test/C/src/CompositionGain.lf @@ -2,33 +2,33 @@ target C reactor Gain { - input gainin: int - output y: int + input gainin: int + output y: int - reaction(gainin) -> y {= - printf("Gain received %d\n", gainin->value); - lf_set(y, gainin->value * 2); - =} + reaction(gainin) -> y {= + printf("Gain received %d\n", gainin->value); + lf_set(y, gainin->value * 2); + =} } reactor Wrapper { - input x: int - output y: int - gain = new Gain() - x -> gain.gainin - gain.y -> y + input x: int + output y: int + gain = new Gain() + x -> gain.gainin + gain.y -> y } main reactor CompositionGain { - wrapper = new Wrapper() + wrapper = new Wrapper() - reaction(startup) -> wrapper.x {= lf_set(wrapper.x, 42); =} + reaction(startup) -> wrapper.x {= lf_set(wrapper.x, 42); =} - reaction(wrapper.y) {= - printf("Received %d\n", wrapper.y->value); - if (wrapper.y->value != 42 * 2) { - fprintf(stderr, "ERROR: Received value should have been %d.\n", 42 * 2); - exit(2); - } - =} + reaction(wrapper.y) {= + printf("Received %d\n", wrapper.y->value); + if (wrapper.y->value != 42 * 2) { + fprintf(stderr, "ERROR: Received value should have been %d.\n", 42 * 2); + exit(2); + } + =} } diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index 3b3f9ea905..06221e9788 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/CountTest.lf b/test/C/src/CountTest.lf index 323302d132..7ac4349d2a 100644 --- a/test/C/src/CountTest.lf +++ b/test/C/src/CountTest.lf @@ -1,14 +1,14 @@ target C { - timeout: 3 sec, - tracing: true, - fast: true + timeout: 3 sec, + tracing: true, + fast: true } import Count from "lib/Count.lf" import TestCount from "lib/TestCount.lf" main reactor CountTest { - count = new Count() - test = new TestCount(num_inputs = 4) - count.out -> test.in + count = new Count() + test = new TestCount(num_inputs = 4) + count.out -> test.in } diff --git a/test/C/src/DanglingOutput.lf b/test/C/src/DanglingOutput.lf index d13de1dac2..8c39ad5612 100644 --- a/test/C/src/DanglingOutput.lf +++ b/test/C/src/DanglingOutput.lf @@ -3,24 +3,24 @@ target C reactor Source { - output out: int - timer t + output out: int + timer t - reaction(t) -> out {= lf_set(out, 1); =} + reaction(t) -> out {= lf_set(out, 1); =} } reactor Gain { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - printf("Received %d.\n", in->value); - lf_set(out, in->value * 2); - =} + reaction(in) -> out {= + printf("Received %d.\n", in->value); + lf_set(out, in->value * 2); + =} } main reactor DanglingOutput { - source = new Source() - container = new Gain() - source.out -> container.in + source = new Source() + container = new Gain() + source.out -> container.in } diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index bd48928bdc..21ea7df141 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -1,5 +1,6 @@ -// This example illustrates local deadline handling. Even numbers are sent by the Source -// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by +// the Source immediately, whereas odd numbers are sent after a big enough delay +// to violate the deadline. target C { timeout: 6 sec } diff --git a/test/C/src/DeadlineAnytime.lf b/test/C/src/DeadlineAnytime.lf index 37540fd10b..bc5ac67188 100644 --- a/test/C/src/DeadlineAnytime.lf +++ b/test/C/src/DeadlineAnytime.lf @@ -2,25 +2,25 @@ target C reactor A { - state i: int - logical action a + state i: int + logical action a - reaction(startup) -> a {= - self->i = 0; - while (!lf_check_deadline(self, true)); - =} deadline(10 msec) {= lf_schedule(a, 0); =} + reaction(startup) -> a {= + self->i = 0; + while (!lf_check_deadline(self, true)); + =} deadline(10 msec) {= lf_schedule(a, 0); =} - reaction(a) {= self->i = 42; =} + reaction(a) {= self->i = 42; =} - reaction(shutdown) {= - if (self->i == 42) { - printf("SUCCESS\n"); - } else { - lf_print_error_and_exit("Expected 42, but got %d", self->i); - } - =} + reaction(shutdown) {= + if (self->i == 42) { + printf("SUCCESS\n"); + } else { + lf_print_error_and_exit("Expected 42, but got %d", self->i); + } + =} } main reactor { - a = new A() + a = new A() } diff --git a/test/C/src/DeadlineHandledAbove.lf b/test/C/src/DeadlineHandledAbove.lf index 939d90b1d6..3b0dc49198 100644 --- a/test/C/src/DeadlineHandledAbove.lf +++ b/test/C/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the container reacts to that -// output. +// Test a deadline where the deadline violation produces an output and the +// container reacts to that output. target C preamble {= diff --git a/test/C/src/DelayArrayWithAfter.lf b/test/C/src/DelayArrayWithAfter.lf index cc270d9bb8..c94be3b9a1 100644 --- a/test/C/src/DelayArrayWithAfter.lf +++ b/test/C/src/DelayArrayWithAfter.lf @@ -1,4 +1,5 @@ -// This tests transport of dynamically allocated arrays over connections with 'after'. +// This tests transport of dynamically allocated arrays over connections with +// 'after'. target C { timeout: 5 sec, fast: true diff --git a/test/C/src/DelayInt.lf b/test/C/src/DelayInt.lf index 74eb50f1f4..78ca793716 100644 --- a/test/C/src/DelayInt.lf +++ b/test/C/src/DelayInt.lf @@ -6,7 +6,9 @@ reactor Delay(delay: time = 100 msec) { output out: int logical action a: int - reaction(a) -> out {= if (a->has_value && a->is_present) lf_set(out, a->value); =} + reaction(a) -> out {= + if (a->has_value && a->is_present) lf_set(out, a->value); + =} reaction(in) -> a {= // Use specialized form of schedule for integer payloads. diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index c5252bde55..1b4204cfc4 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -1,4 +1,5 @@ -// This tests actions with immutable payloads that are neither malloc'd nor freed. +// This tests actions with immutable payloads that are neither malloc'd nor +// freed. target C preamble {= diff --git a/test/C/src/DelayedReaction.lf b/test/C/src/DelayedReaction.lf index 2dcf80f106..dbdec1a2e8 100644 --- a/test/C/src/DelayedReaction.lf +++ b/test/C/src/DelayedReaction.lf @@ -2,27 +2,27 @@ target C reactor Source { - output out: int - timer t + output out: int + timer t - reaction(t) -> out {= lf_set(out, 1); =} + reaction(t) -> out {= lf_set(out, 1); =} } reactor Sink { - input in: int + input in: int - reaction(in) {= - interval_t elapsed = lf_time_logical_elapsed(); - printf("Nanoseconds since start: %lld.\n", elapsed); - if (elapsed != 100000000LL) { - printf("ERROR: Expected 100000000 but.\n"); - exit(1); - } - =} + reaction(in) {= + interval_t elapsed = lf_time_logical_elapsed(); + printf("Nanoseconds since start: %lld.\n", elapsed); + if (elapsed != 100000000LL) { + printf("ERROR: Expected 100000000 but.\n"); + exit(1); + } + =} } main reactor DelayedReaction { - source = new Source() - sink = new Sink() - source.out -> sink.in after 100 msec + source = new Source() + sink = new Sink() + source.out -> sink.in after 100 msec } diff --git a/test/C/src/Determinism.lf b/test/C/src/Determinism.lf index fea5290373..a063b108f0 100644 --- a/test/C/src/Determinism.lf +++ b/test/C/src/Determinism.lf @@ -1,46 +1,46 @@ target C reactor Source { - output y: int - timer t + output y: int + timer t - reaction(t) -> y {= lf_set(y, 1); =} + reaction(t) -> y {= lf_set(y, 1); =} } reactor Destination { - input x: int - input y: int + input x: int + input y: int - reaction(x, y) {= - int sum = 0; - if (x->is_present) { - sum += x->value; - } - if (y->is_present) { - sum += y->value; - } - printf("Received %d.\n", sum); - if (sum != 2) { - printf("FAILURE: Expected 2.\n"); - exit(4); - } - =} + reaction(x, y) {= + int sum = 0; + if (x->is_present) { + sum += x->value; + } + if (y->is_present) { + sum += y->value; + } + printf("Received %d.\n", sum); + if (sum != 2) { + printf("FAILURE: Expected 2.\n"); + exit(4); + } + =} } reactor Pass { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= lf_set(y, x->value); =} + reaction(x) -> y {= lf_set(y, x->value); =} } main reactor Determinism { - s = new Source() - d = new Destination() - p1 = new Pass() - p2 = new Pass() - s.y -> d.y - s.y -> p1.x - p1.y -> p2.x - p2.y -> d.x + s = new Source() + d = new Destination() + p1 = new Pass() + p2 = new Pass() + s.y -> d.y + s.y -> p1.x + p1.y -> p2.x + p2.y -> d.x } diff --git a/test/C/src/DoubleInvocation.lf b/test/C/src/DoubleInvocation.lf index 687b03a603..973c8b18f6 100644 --- a/test/C/src/DoubleInvocation.lf +++ b/test/C/src/DoubleInvocation.lf @@ -1,7 +1,8 @@ -// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it -// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at -// the same logical time. They should only be fired once. This behavior was oddly eliminated by -// either of the following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. +// This test ensures it does not reappear. At logical time zero, the two Print +// reactors used to be fired twice each at the same logical time. They should +// only be fired once. This behavior was oddly eliminated by either of the +// following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. // * Sending only position, not velocity from Ball. target C { diff --git a/test/C/src/DoublePort.lf b/test/C/src/DoublePort.lf index 3baab84667..c8bf9811f8 100644 --- a/test/C/src/DoublePort.lf +++ b/test/C/src/DoublePort.lf @@ -1,6 +1,7 @@ /** - * Test the case where two upstream reactors pass messages to a downstream reactor on two different - * ports. One message carries a microstep delay relative to the other. + * Test the case where two upstream reactors pass messages to a downstream + * reactor on two different ports. One message carries a microstep delay + * relative to the other. * * @author Soroush Bateni */ @@ -35,7 +36,9 @@ reactor Print { } =} - reaction(shutdown) {= printf("SUCCESS: messages were at least one microstep apart.\n"); =} + reaction(shutdown) {= + printf("SUCCESS: messages were at least one microstep apart.\n"); + =} } main reactor DoublePort { diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index 0c78b9805d..8da6210825 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output -// for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only +// once. Correct output for this 2, 4, 6, 8, etc. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index 9106853af3..68ad603168 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -1,4 +1,5 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice +// at the same tag. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/FloatLiteral.lf b/test/C/src/FloatLiteral.lf index 3c8bfa6037..576a20d1ac 100644 --- a/test/C/src/FloatLiteral.lf +++ b/test/C/src/FloatLiteral.lf @@ -1,6 +1,7 @@ target C -main reactor { // This test verifies that floating-point literals are handled correctly. +// This test verifies that floating-point literals are handled correctly. +main reactor { preamble {= #include =} diff --git a/test/C/src/GetTime.lf b/test/C/src/GetTime.lf index 77a8f980f9..324195ddc9 100644 --- a/test/C/src/GetTime.lf +++ b/test/C/src/GetTime.lf @@ -1,26 +1,26 @@ // This file includes code documented on the Wiki. For this test, success is just compiling and // running. target C { - timeout: 2 sec, - fast: false + timeout: 2 sec, + fast: false } main reactor GetTime { - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) {= - instant_t logical = lf_time_logical(); - printf("Logical time is %lld.\n", logical); + reaction(t) {= + instant_t logical = lf_time_logical(); + printf("Logical time is %lld.\n", logical); - interval_t elapsed = lf_time_logical_elapsed(); - printf("Elapsed logical time is %lld.\n", elapsed); + interval_t elapsed = lf_time_logical_elapsed(); + printf("Elapsed logical time is %lld.\n", elapsed); - instant_t physical = lf_time_physical(); - printf("Physical time is %lld.\n", physical); + instant_t physical = lf_time_physical(); + printf("Physical time is %lld.\n", physical); - instant_t elapsed_physical = lf_time_physical_elapsed(); - printf("Elapsed physical time is %lld.\n", elapsed_physical); + instant_t elapsed_physical = lf_time_physical_elapsed(); + printf("Elapsed physical time is %lld.\n", elapsed_physical); - printf("Time lag is %lld.\n", physical - logical); - =} + printf("Time lag is %lld.\n", physical - logical); + =} } diff --git a/test/C/src/Hierarchy.lf b/test/C/src/Hierarchy.lf index ea14165e24..71aa7f9269 100644 --- a/test/C/src/Hierarchy.lf +++ b/test/C/src/Hierarchy.lf @@ -2,50 +2,50 @@ target C reactor Source { - output out: int - timer t + output out: int + timer t - reaction(t) -> out {= lf_set(out, 1); =} + reaction(t) -> out {= lf_set(out, 1); =} } reactor Gain { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - printf("Gain received %d.\n", in->value); - lf_set(out, in->value * 2); - =} + reaction(in) -> out {= + printf("Gain received %d.\n", in->value); + lf_set(out, in->value * 2); + =} } reactor Print { - input in: int - - reaction(in) {= - printf("Received: %d.\n", in->value); - if (in->value != 2) { - printf("Expected 2.\n"); - exit(1); - } - =} + input in: int + + reaction(in) {= + printf("Received: %d.\n", in->value); + if (in->value != 2) { + printf("Expected 2.\n"); + exit(1); + } + =} } reactor GainContainer { - input in: int - output out: int - output out2: int - gain = new Gain() - in -> gain.in - gain.out -> out - gain.out -> out2 + input in: int + output out: int + output out2: int + gain = new Gain() + in -> gain.in + gain.out -> out + gain.out -> out2 } main reactor Hierarchy { - source = new Source() - container = new GainContainer() - print = new Print() - print2 = new Print() - source.out -> container.in - container.out -> print.in - container.out2 -> print2.in + source = new Source() + container = new GainContainer() + print = new Print() + print2 = new Print() + source.out -> container.in + container.out -> print.in + container.out2 -> print2.in } diff --git a/test/C/src/Import.lf b/test/C/src/Import.lf index 7df0fd24b6..812f14edaa 100644 --- a/test/C/src/Import.lf +++ b/test/C/src/Import.lf @@ -4,8 +4,8 @@ target C import Imported from "lib/Imported.lf" main reactor Import { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= lf_set(a.x, 42); =} + reaction(t) -> a.x {= lf_set(a.x, 42); =} } diff --git a/test/C/src/ImportComposition.lf b/test/C/src/ImportComposition.lf index 635a3b2b8f..22a1bfef87 100644 --- a/test/C/src/ImportComposition.lf +++ b/test/C/src/ImportComposition.lf @@ -1,4 +1,5 @@ -// This tests the ability to import a reactor definition that itself imports a reactor definition. +// This tests the ability to import a reactor definition that itself imports a +// reactor definition. target C import ImportedComposition from "lib/ImportedComposition.lf" diff --git a/test/C/src/ImportRenamed.lf b/test/C/src/ImportRenamed.lf index 7d549f04dd..6ddee69dfa 100644 --- a/test/C/src/ImportRenamed.lf +++ b/test/C/src/ImportRenamed.lf @@ -6,10 +6,10 @@ import Imported as Y from "lib/Imported.lf" import ImportedAgain as Z from "lib/ImportedAgain.lf" main reactor { - timer t - a = new X() - b = new Y() - c = new Z() + timer t + a = new X() + b = new Y() + c = new Z() - reaction(t) -> a.x {= lf_set(a.x, 42); =} + reaction(t) -> a.x {= lf_set(a.x, 42); =} } diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 22c4904695..680ffe2f75 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target C { fast: true } diff --git a/test/C/src/Microsteps.lf b/test/C/src/Microsteps.lf index 795a4801a7..1e5cca7bf3 100644 --- a/test/C/src/Microsteps.lf +++ b/test/C/src/Microsteps.lf @@ -1,41 +1,41 @@ target C reactor Destination { - input x: int - input y: int + input x: int + input y: int - reaction(x, y) {= - interval_t elapsed = lf_time_logical_elapsed(); - printf("Time since start: %lld.\n", elapsed); - if (elapsed != 0LL) { - printf("Expected elapsed time to be 0, but it was %lld.\n", elapsed); - exit(1); - } - int count = 0; - if (x->is_present) { - printf(" x is present.\n"); - count++; - } - if (y->is_present) { - printf(" y is present.\n"); - count++; - } - if (count != 1) { - printf("Expected exactly one input to be present but got %d.\n", count); - exit(1); - } - =} + reaction(x, y) {= + interval_t elapsed = lf_time_logical_elapsed(); + printf("Time since start: %lld.\n", elapsed); + if (elapsed != 0LL) { + printf("Expected elapsed time to be 0, but it was %lld.\n", elapsed); + exit(1); + } + int count = 0; + if (x->is_present) { + printf(" x is present.\n"); + count++; + } + if (y->is_present) { + printf(" y is present.\n"); + count++; + } + if (count != 1) { + printf("Expected exactly one input to be present but got %d.\n", count); + exit(1); + } + =} } main reactor Microsteps { - timer start - logical action repeat - d = new Destination() + timer start + logical action repeat + d = new Destination() - reaction(start) -> d.x, repeat {= - lf_set(d.x, 1); - lf_schedule(repeat, 0); - =} + reaction(start) -> d.x, repeat {= + lf_set(d.x, 1); + lf_schedule(repeat, 0); + =} - reaction(repeat) -> d.y {= lf_set(d.y, 1); =} + reaction(repeat) -> d.y {= lf_set(d.y, 1); =} } diff --git a/test/C/src/Minimal.lf b/test/C/src/Minimal.lf index 350f92a795..b2534ab993 100644 --- a/test/C/src/Minimal.lf +++ b/test/C/src/Minimal.lf @@ -2,5 +2,5 @@ target C main reactor Minimal { - reaction(startup) {= printf("Hello World.\n"); =} + reaction(startup) {= printf("Hello World.\n"); =} } diff --git a/test/C/src/MovingAverage.lf b/test/C/src/MovingAverage.lf index a477e55804..a8309aa9d3 100644 --- a/test/C/src/MovingAverage.lf +++ b/test/C/src/MovingAverage.lf @@ -1,5 +1,6 @@ -// Demonstration of a state variable that is an array. The MovingAverage reactor computes the moving -// average of the last four inputs and produces that as output. The source is a counting sequence. +// Demonstration of a state variable that is an array. The MovingAverage reactor +// computes the moving average of the last four inputs and produces that as +// output. The source is a counting sequence. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/MultipleContained.lf b/test/C/src/MultipleContained.lf index f0fe73c6d5..540052ba87 100644 --- a/test/C/src/MultipleContained.lf +++ b/test/C/src/MultipleContained.lf @@ -1,4 +1,5 @@ -// Test that a reaction can react to and send two multiple ports of a contained reactor. +// Test that a reaction can react to and send two multiple ports of a contained +// reactor. target C reactor Contained { diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index b7609ab803..37b5ddba9f 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -1,6 +1,7 @@ -// This test checks for one of the issues arised in the solution of EECS149 Lab Chapter 7. In this -// case, a reactor has two output ports, the first one of which is dangling. The generated code -// should not have any segmentation faults. +// This test checks for one of the issues arised in the solution of EECS149 Lab +// Chapter 7. In this case, a reactor has two output ports, the first one of +// which is dangling. The generated code should not have any segmentation +// faults. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/PingPong.lf b/test/C/src/PingPong.lf index e51f0160b8..2f1699a51d 100644 --- a/test/C/src/PingPong.lf +++ b/test/C/src/PingPong.lf @@ -1,20 +1,23 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. This is based on https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure + * message-passing overhead. This is based on + * https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the causality loop. + * Ping introduces a microstep delay using a logical action to break the + * causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * - Unthreaded: 97 msec * - Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from being being threaded, - * just some additional overhead. + * There is no parallelism in this application, so it does not benefit from + * being being threaded, just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. These are about an - * order of magnitude faster than anything reported in the paper. + * These measurements are total execution time, including startup and shutdown. + * These are about an order of magnitude faster than anything reported in the + * paper. * * @author Edward A. Lee */ diff --git a/test/C/src/Preamble.lf b/test/C/src/Preamble.lf index 01b4b371b6..28fa5a7d5e 100644 --- a/test/C/src/Preamble.lf +++ b/test/C/src/Preamble.lf @@ -1,21 +1,21 @@ target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } main reactor Preamble { - preamble {= - #include - int add_42(int i) { - return i + 42; - } - =} - timer t + preamble {= + #include + int add_42(int i) { + return i + 42; + } + =} + timer t - reaction(t) {= - char* s = "42"; - int i = atoi(s); - printf("Converted string %s to int %d.\n", s, i); - printf("42 plus 42 is %d.\n", add_42(42)); - =} + reaction(t) {= + char* s = "42"; + int i = atoi(s); + printf("Converted string %s to int %d.\n", s, i); + printf("42 plus 42 is %d.\n", add_42(42)); + =} } diff --git a/test/C/src/ReadOutputOfContainedReactor.lf b/test/C/src/ReadOutputOfContainedReactor.lf index ba4490e237..ce2129069b 100644 --- a/test/C/src/ReadOutputOfContainedReactor.lf +++ b/test/C/src/ReadOutputOfContainedReactor.lf @@ -1,4 +1,5 @@ -// Test reacting to and reading outputs from a contained reactor in various permutations. +// Test reacting to and reading outputs from a contained reactor in various +// permutations. target C reactor Contained { diff --git a/test/C/src/RepeatedInheritance.lf b/test/C/src/RepeatedInheritance.lf index 422ada69d8..47d4e46e63 100644 --- a/test/C/src/RepeatedInheritance.lf +++ b/test/C/src/RepeatedInheritance.lf @@ -4,36 +4,36 @@ * @author{Edward A. Lee} */ target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } import Count from "lib/Count.lf" import TestCount from "lib/TestCount.lf" reactor D { - input d: int + input d: int } reactor C extends D { - input c: int + input c: int } reactor B extends D { - input b: int + input b: int } reactor A extends B, C { - input a: int - output out: int + input a: int + output out: int - reaction(a, b, c, d) -> out {= lf_set(out, a->value + b->value + c->value + d->value); =} + reaction(a, b, c, d) -> out {= lf_set(out, a->value + b->value + c->value + d->value); =} } main reactor { - c = new Count() - a = new A() - t = new TestCount(start = 4, stride = 4, num_inputs = 6) - (c.out)+ -> a.a, a.b, a.c, a.d - a.out -> t.in + c = new Count() + a = new A() + t = new TestCount(start = 4, stride = 4, num_inputs = 6) + (c.out)+ -> a.a, a.b, a.c, a.d + a.out -> t.in } diff --git a/test/C/src/RequestStop.lf b/test/C/src/RequestStop.lf index 1724f3ab92..83c59d1d27 100644 --- a/test/C/src/RequestStop.lf +++ b/test/C/src/RequestStop.lf @@ -1,4 +1,5 @@ -// Test verifying that lf_request_stop() called in a shutdown reaction is ignored. +// Test verifying that lf_request_stop() called in a shutdown reaction is +// ignored. target C main reactor { diff --git a/test/C/src/Schedule.lf b/test/C/src/Schedule.lf index 91d3e2db2b..a806170d74 100644 --- a/test/C/src/Schedule.lf +++ b/test/C/src/Schedule.lf @@ -2,24 +2,24 @@ target C reactor Schedule2 { - input x: int - logical action a + input x: int + logical action a - reaction(x) -> a {= lf_schedule(a, MSEC(200)); =} + reaction(x) -> a {= lf_schedule(a, MSEC(200)); =} - reaction(a) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Action triggered at logical time %lld nsec after start.\n", elapsed_time); - if (elapsed_time != 200000000LL) { - printf("Expected action time to be 200 msec. It was %lld nsec.\n", elapsed_time); - exit(1); - } - =} + reaction(a) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Action triggered at logical time %lld nsec after start.\n", elapsed_time); + if (elapsed_time != 200000000LL) { + printf("Expected action time to be 200 msec. It was %lld nsec.\n", elapsed_time); + exit(1); + } + =} } main reactor { - a = new Schedule2() - timer t + a = new Schedule2() + timer t - reaction(t) -> a.x {= lf_set(a.x, 1); =} + reaction(t) -> a.x {= lf_set(a.x, 1); =} } diff --git a/test/C/src/ScheduleLogicalAction.lf b/test/C/src/ScheduleLogicalAction.lf index 25fce8619d..762f8c6f52 100644 --- a/test/C/src/ScheduleLogicalAction.lf +++ b/test/C/src/ScheduleLogicalAction.lf @@ -1,5 +1,5 @@ -// This checks that a logical action is scheduled the specified logical time after the current -// logical time. +// This checks that a logical action is scheduled the specified logical time +// after the current logical time. target C { fast: true, timeout: 3 sec diff --git a/test/C/src/ScheduleValue.lf b/test/C/src/ScheduleValue.lf index 8481d47d61..2ef4333db8 100644 --- a/test/C/src/ScheduleValue.lf +++ b/test/C/src/ScheduleValue.lf @@ -1,6 +1,6 @@ /** Test of schedule_value. */ target C { - timeout: 3 sec + timeout: 3 sec } preamble {= @@ -15,19 +15,19 @@ preamble {= =} main reactor ScheduleValue { - logical action a: char* + logical action a: char* - reaction(startup) -> a {= - char* value = (char*)malloc(6); - strcpy(value, "Hello"); - lf_schedule_value(a, 0, value, 6); - =} + reaction(startup) -> a {= + char* value = (char*)malloc(6); + strcpy(value, "Hello"); + lf_schedule_value(a, 0, value, 6); + =} - reaction(a) {= - printf("Received: %s\n", a->value); - if (strcmp(a->value, "Hello") != 0) { - fprintf(stderr, "FAILURE: Should have received 'Hello'\n"); - exit(1); - } - =} + reaction(a) {= + printf("Received: %s\n", a->value); + if (strcmp(a->value, "Hello") != 0) { + fprintf(stderr, "FAILURE: Should have received 'Hello'\n"); + exit(1); + } + =} } diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index 920f371d4a..b1e8f25f93 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own reaction that routes -// inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own +// reaction that routes inputs to the contained reactor. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/SendingInside2.lf b/test/C/src/SendingInside2.lf index f65342de52..e1b684ff74 100644 --- a/test/C/src/SendingInside2.lf +++ b/test/C/src/SendingInside2.lf @@ -1,20 +1,20 @@ target C reactor Printer { - input x: int + input x: int - reaction(x) {= - printf("Inside reactor received: %d\n", x->value); - if (x->value != 1) { - fprintf(stderr, "ERROR: Expected 1.\n"); - exit(1); - } - =} + reaction(x) {= + printf("Inside reactor received: %d\n", x->value); + if (x->value != 1) { + fprintf(stderr, "ERROR: Expected 1.\n"); + exit(1); + } + =} } main reactor SendingInside2 { - timer t - p = new Printer() + timer t + p = new Printer() - reaction(t) -> p.x {= lf_set(p.x, 1); =} + reaction(t) -> p.x {= lf_set(p.x, 1); =} } diff --git a/test/C/src/SendsPointerTest.lf b/test/C/src/SendsPointerTest.lf index 0cfa6dc48c..1f17bd1388 100644 --- a/test/C/src/SendsPointerTest.lf +++ b/test/C/src/SendsPointerTest.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Print. Reference counting -// ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. +// Reference counting ensures that the struct is freed. target C preamble {= typedef int* int_pointer; =} diff --git a/test/C/src/SetArray.lf b/test/C/src/SetArray.lf index 188fccba1f..f30457f9f8 100644 --- a/test/C/src/SetArray.lf +++ b/test/C/src/SetArray.lf @@ -1,5 +1,5 @@ -// This tests SET_ARRAY() This tests the use of the "polymorphic" delay reactor on a struct. It -// delays by a logical time any pointer datatype. +// This tests SET_ARRAY() This tests the use of the "polymorphic" delay reactor +// on a struct. It delays by a logical time any pointer datatype. target C reactor Source { diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index e8ce362823..fba3e03cbc 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -1,5 +1,6 @@ -// Test local deadline, where a deadline is associated with a reaction definition. This test -// triggers a reaction exactly once with a deadline violation. +// Test local deadline, where a deadline is associated with a reaction +// definition. This test triggers a reaction exactly once with a deadline +// violation. target C preamble {= diff --git a/test/C/src/SimpleImport.lf b/test/C/src/SimpleImport.lf index 71258bd678..7a1a517c02 100644 --- a/test/C/src/SimpleImport.lf +++ b/test/C/src/SimpleImport.lf @@ -3,6 +3,6 @@ target C import HelloWorld2 from "HelloWorld.lf" main reactor SimpleImport { - a = new HelloWorld2() - b = new HelloWorld2() + a = new HelloWorld2() + b = new HelloWorld2() } diff --git a/test/C/src/SlowingClock.lf b/test/C/src/SlowingClock.lf index 36a1f01aef..d4a1e1d5f4 100644 --- a/test/C/src/SlowingClock.lf +++ b/test/C/src/SlowingClock.lf @@ -1,7 +1,8 @@ /** - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a logical - * action with a minimum delay of 100 msec. The use of the logical action ensures the elapsed time - * jumps exactly from 0 to 100, 300, 600, and 1000 msec. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 + * msec on a logical action with a minimum delay of 100 msec. The use of the + * logical action ensures the elapsed time jumps exactly from 0 to 100, 300, + * 600, and 1000 msec. */ target C { timeout: 1 sec, diff --git a/test/C/src/SlowingClockPhysical.lf b/test/C/src/SlowingClockPhysical.lf index 7af44f3481..0e82730112 100644 --- a/test/C/src/SlowingClockPhysical.lf +++ b/test/C/src/SlowingClockPhysical.lf @@ -1,8 +1,9 @@ /** - * /* Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a physical - * action with a minimum delay of 100 msec. The use of the physical action makes the elapsed time - * jumps from 0 to approximately 100 msec, to approximatly 300 msec thereafter, drifting away - * further with each new event. + * /* Events are scheduled with increasing additional delays of 0, 100, 300, 600 + * msec on a physical action with a minimum delay of 100 msec. The use of the + * physical action makes the elapsed time jumps from 0 to approximately 100 + * msec, to approximatly 300 msec thereafter, drifting away further with each + * new event. */ target C { timeout: 1500 msec diff --git a/test/C/src/StartupOutFromInside.lf b/test/C/src/StartupOutFromInside.lf index cad2d282bf..1e9a8a822a 100644 --- a/test/C/src/StartupOutFromInside.lf +++ b/test/C/src/StartupOutFromInside.lf @@ -1,19 +1,19 @@ target C reactor Bar { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} } main reactor StartupOutFromInside { - bar = new Bar() + bar = new Bar() - reaction(startup) bar.out {= - printf("Output from bar: %d\n", bar.out->value); - if (bar.out->value != 42) { - fprintf(stderr, "Expected 42!\n"); - exit(1); - } - =} + reaction(startup) bar.out {= + printf("Output from bar: %d\n", bar.out->value); + if (bar.out->value != 42) { + fprintf(stderr, "Expected 42!\n"); + exit(1); + } + =} } diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index c4ff41693e..8f4c1423a5 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -1,6 +1,6 @@ /** - * Test that the starvation functionality in absence of the "keepalive: true" target property indeed - * works as expected. + * Test that the starvation functionality in absence of the "keepalive: true" + * target property indeed works as expected. * * @author Soroush Bateni */ diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index 1a317dd45e..e845c6de48 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -1,6 +1,6 @@ /** - * Test for lf_request_stop() at tag (0,0). This also tests for logically simultaneous calls to - * lf_request_stop(). + * Test for lf_request_stop() at tag (0,0). This also tests for logically + * simultaneous calls to lf_request_stop(). * * @author Soroush Bateni */ diff --git a/test/C/src/Stride.lf b/test/C/src/Stride.lf index c57c2e0aad..62b9077878 100644 --- a/test/C/src/Stride.lf +++ b/test/C/src/Stride.lf @@ -1,5 +1,5 @@ -// This example illustrates state variables and parameters on the wiki. For this test, success is -// just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this +// test, success is just compiling and running. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/StructPrint.lf b/test/C/src/StructPrint.lf index 5c2f10513e..6af0d60c4f 100644 --- a/test/C/src/StructPrint.lf +++ b/test/C/src/StructPrint.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Print. Reference counting -// ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. +// Reference counting ensures that the struct is freed. target C { files: ["include/hello.h"] } diff --git a/test/C/src/TestForPreviousOutput.lf b/test/C/src/TestForPreviousOutput.lf index 825f559d13..890b47361d 100644 --- a/test/C/src/TestForPreviousOutput.lf +++ b/test/C/src/TestForPreviousOutput.lf @@ -13,40 +13,40 @@ preamble {= =} reactor Source { - output out: int + output out: int - reaction(startup) -> out {= - // Set a seed for random number generation based on the current time. - srand(time(0)); - // Randomly produce an output or not. - if (rand() % 2) { - lf_set(out, 21); - } - =} + reaction(startup) -> out {= + // Set a seed for random number generation based on the current time. + srand(time(0)); + // Randomly produce an output or not. + if (rand() % 2) { + lf_set(out, 21); + } + =} - reaction(startup) -> out {= - if (out->is_present) { - lf_set(out, 2 * out->value); - } else { - lf_set(out, 42); - } - =} + reaction(startup) -> out {= + if (out->is_present) { + lf_set(out, 2 * out->value); + } else { + lf_set(out, 42); + } + =} } reactor Sink { - input in: int + input in: int - reaction(in) {= - printf("Received %d.\n", in->value); - if (in->value != 42) { - fprintf(stderr, "FAILED: Expected 42.\n"); - exit(1); - } - =} + reaction(in) {= + printf("Received %d.\n", in->value); + if (in->value != 42) { + fprintf(stderr, "FAILED: Expected 42.\n"); + exit(1); + } + =} } main reactor TestForPreviousOutput { - s = new Source() - d = new Sink() - s.out -> d.in + s = new Source() + d = new Sink() + s.out -> d.in } diff --git a/test/C/src/TimeLimit.lf b/test/C/src/TimeLimit.lf index 3245725361..ae178d53b5 100644 --- a/test/C/src/TimeLimit.lf +++ b/test/C/src/TimeLimit.lf @@ -1,5 +1,6 @@ -// Test that the stop function can be used to internally impose a a time limit. Correct output for -// this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. +// Test that the stop function can be used to internally impose a a time limit. +// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt +// or getting the wrong data. target C { fast: true } diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index a9cd25a886..771d321a40 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -1,5 +1,6 @@ /** - * A test for the timeout functionality in Lingua Franca. This variant tests timeout at (0,0). + * A test for the timeout functionality in Lingua Franca. This variant tests + * timeout at (0,0). * * @author Soroush Bateni */ diff --git a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf index 5f843930b8..bc62b214e9 100644 --- a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,4 +1,7 @@ -/** This test checks that a downstream reaction is triggered only if its trigger is present. */ +/** + * This test checks that a downstream reaction is triggered only if its trigger + * is present. + */ target C { timeout: 1 sec, fast: true diff --git a/test/C/src/Wcet.lf b/test/C/src/Wcet.lf index d21268ea79..984f95244f 100644 --- a/test/C/src/Wcet.lf +++ b/test/C/src/Wcet.lf @@ -2,44 +2,44 @@ target C reactor Source { - output out1: int - output out2: int - timer t - - reaction(t) -> out1, out2 {= - lf_set(out1, 5); - lf_set(out2, 10); - =} + output out1: int + output out2: int + timer t + + reaction(t) -> out1, out2 {= + lf_set(out1, 5); + lf_set(out2, 10); + =} } reactor Work { - input in1: int - input in2: int - output out: int - - reaction(in1, in2) -> out {= - int ret; - if (in1->value > 10) { - ret = in2->value * in1->value; - } else { - ret = in2->value + in1->value; - } - lf_set(out, ret); - =} + input in1: int + input in2: int + output out: int + + reaction(in1, in2) -> out {= + int ret; + if (in1->value > 10) { + ret = in2->value * in1->value; + } else { + ret = in2->value + in1->value; + } + lf_set(out, ret); + =} } reactor Print { - input in: int + input in: int - reaction(in) {= printf("Received: %d\n", in->value); =} + reaction(in) {= printf("Received: %d\n", in->value); =} } main reactor Wcet { - source = new Source() - work = new Work() - print = new Print() + source = new Source() + work = new Work() + print = new Print() - source.out1 -> work.in1 - source.out2 -> work.in2 - work.out -> print.in + source.out1 -> work.in1 + source.out2 -> work.in2 + work.out -> print.in } diff --git a/test/C/src/arduino/AnalogReadSerial.lf b/test/C/src/arduino/AnalogReadSerial.lf index c2fc4ef475..220cb47d47 100644 --- a/test/C/src/arduino/AnalogReadSerial.lf +++ b/test/C/src/arduino/AnalogReadSerial.lf @@ -1,7 +1,8 @@ /** - * This example reads an analog input on pin 0, prints the result to the Serial Monitor. Graphical - * representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center - * pin of a potentiometer to pin A0, and the outside pins to +5V and ground. + * This example reads an analog input on pin 0, prints the result to the Serial + * Monitor. Graphical representation is available using Serial Plotter (Tools > + * Serial Plotter menu). Attach the center pin of a potentiometer to pin A0, and + * the outside pins to +5V and ground. */ target C { platform: { diff --git a/test/C/src/arduino/Blink.lf b/test/C/src/arduino/Blink.lf index 4ed02cdc2a..809aa55884 100644 --- a/test/C/src/arduino/Blink.lf +++ b/test/C/src/arduino/Blink.lf @@ -1,6 +1,7 @@ /** - * This example demonstrates a very simple blink program that will turn on and off an LED on the - * Arduino Board with a 50% duty cycle switching every half-second. + * This example demonstrates a very simple blink program that will turn on and + * off an LED on the Arduino Board with a 50% duty cycle switching every + * half-second. */ target C { platform: { diff --git a/test/C/src/arduino/BlinkAttemptThreading.lf b/test/C/src/arduino/BlinkAttemptThreading.lf index 31fd99989d..8f71009edf 100644 --- a/test/C/src/arduino/BlinkAttemptThreading.lf +++ b/test/C/src/arduino/BlinkAttemptThreading.lf @@ -1,7 +1,8 @@ /** - * This example demonstrates a very simple blink program that will turn on and off an LED on the - * Arduino Board with a 50% duty cycle switching every half-second. Note: if we try to enable - * threading, the system will give us a warning and default back to no threading. + * This example demonstrates a very simple blink program that will turn on and + * off an LED on the Arduino Board with a 50% duty cycle switching every + * half-second. Note: if we try to enable threading, the system will give us a + * warning and default back to no threading. */ target C { platform: { diff --git a/test/C/src/arduino/BlinkMBED.lf b/test/C/src/arduino/BlinkMBED.lf index 5330e018a0..f9702d27cc 100644 --- a/test/C/src/arduino/BlinkMBED.lf +++ b/test/C/src/arduino/BlinkMBED.lf @@ -1,6 +1,7 @@ /** - * This example demonstrates a very simple blink program that will turn on and off an LED on the - * Arduino Board with a 50% duty cycle switching every half-second. + * This example demonstrates a very simple blink program that will turn on and + * off an LED on the Arduino Board with a 50% duty cycle switching every + * half-second. */ target C { platform: { diff --git a/test/C/src/arduino/Fade.lf b/test/C/src/arduino/Fade.lf index 74d3fa0c8c..d23aabd646 100644 --- a/test/C/src/arduino/Fade.lf +++ b/test/C/src/arduino/Fade.lf @@ -1,8 +1,9 @@ /** - * This example shows how to fade an LED on pin 9 using the analogWrite() function. The - * analogWrite() function uses PWM, so if you want to change the pin you're using, be sure to use - * another PWM capable pin. On most Arduino, the PWM pins are identified with a "~" sign, like ~3, - * ~5, ~6, ~9, ~10 and ~11. + * This example shows how to fade an LED on pin 9 using the analogWrite() + * function. The analogWrite() function uses PWM, so if you want to change the + * pin you're using, be sure to use another PWM capable pin. On most Arduino, + * the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and + * ~11. */ target C { platform: { diff --git a/test/C/src/arduino/ReadAnalogVoltage.lf b/test/C/src/arduino/ReadAnalogVoltage.lf index 2a56719f66..77be8e8b06 100644 --- a/test/C/src/arduino/ReadAnalogVoltage.lf +++ b/test/C/src/arduino/ReadAnalogVoltage.lf @@ -1,8 +1,9 @@ /** - * This example reads an analog input on pin 0, converts it to voltage, and prints the result to the - * Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial - * Plotter menu). Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V - * and ground. + * This example reads an analog input on pin 0, converts it to voltage, and + * prints the result to the Serial Monitor. Graphical representation is + * available using Serial Plotter (Tools > Serial Plotter menu). Attach the + * center pin of a potentiometer to pin A0, and the outside pins to +5V and + * ground. */ target C { platform: { diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index 18268c574a..58120446d4 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -1,9 +1,11 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test case assumes that target is - * multithreaded. This test will not work with the unthreaded C target because that target does not - * implement any mutex protecting the event queue. + * Test asynchronous callbacks that trigger a physical action. This test case + * assumes that target is multithreaded. This test will not work with the + * unthreaded C target because that target does not implement any mutex + * protecting the event queue. * - * Note: This test uses the LF platform support to enable it to run on multiple platforms. + * Note: This test uses the LF platform support to enable it to run on multiple + * platforms. */ target C { tracing: true, diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index d7d0858699..b0c5c502f2 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -1,6 +1,7 @@ -// Test asynchronous callbacks that trigger a physical action with a DROP policy. This test case -// assumes that the target is multithreaded. This test will not work with the unthreaded C target -// because that target does not implement any mutex protecting the event queue. +// Test asynchronous callbacks that trigger a physical action with a DROP +// policy. This test case assumes that the target is multithreaded. This test +// will not work with the unthreaded C target because that target does not +// implement any mutex protecting the event queue. target C { keepalive: true, // To silence warning. timeout: 2 sec diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index ba75b3e3db..7bac7496b5 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -1,6 +1,7 @@ -// Test asynchronous callbacks that trigger a physical action with a "replace" policy. This test -// case assumes that the target is multithreaded. This test will not work with the unthreaded C -// target because that target does not implement any mutex protecting the event queue. +// Test asynchronous callbacks that trigger a physical action with a "replace" +// policy. This test case assumes that the target is multithreaded. This test +// will not work with the unthreaded C target because that target does not +// implement any mutex protecting the event queue. target C { keepalive: true, timeout: 2 sec diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index 01185fa6b3..cf0bafeb82 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target C { fast: true, timeout: 10 sec diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index 5f698d1c95..ad14879080 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the container reacts to that -// output. +// Test a deadline where the deadline violation produces an output and the +// container reacts to that output. target C preamble {= diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index ff5961b0d9..ffc1be2701 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -1,5 +1,6 @@ -// This example illustrates local deadline handling. Even numbers are sent by the Source -// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by +// the Source immediately, whereas odd numbers are sent after a big enough delay +// to violate the deadline. target C { timeout: 6 sec } diff --git a/test/C/src/concurrent/DeterminismThreaded.lf b/test/C/src/concurrent/DeterminismThreaded.lf index c141f36330..a0df17b15c 100644 --- a/test/C/src/concurrent/DeterminismThreaded.lf +++ b/test/C/src/concurrent/DeterminismThreaded.lf @@ -1,46 +1,46 @@ target C reactor Source { - output y: int - timer t + output y: int + timer t - reaction(t) -> y {= lf_set(y, 1); =} + reaction(t) -> y {= lf_set(y, 1); =} } reactor Destination { - input x: int - input y: int + input x: int + input y: int - reaction(x, y) {= - int sum = 0; - if (x->is_present) { - sum += x->value; - } - if (y->is_present) { - sum += y->value; - } - printf("Received %d.\n", sum); - if (sum != 2) { - printf("FAILURE: Expected 2.\n"); - exit(4); - } - =} + reaction(x, y) {= + int sum = 0; + if (x->is_present) { + sum += x->value; + } + if (y->is_present) { + sum += y->value; + } + printf("Received %d.\n", sum); + if (sum != 2) { + printf("FAILURE: Expected 2.\n"); + exit(4); + } + =} } reactor Pass { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= lf_set(y, x->value); =} + reaction(x) -> y {= lf_set(y, x->value); =} } main reactor { - s = new Source() - d = new Destination() - p1 = new Pass() - p2 = new Pass() - s.y -> d.y - s.y -> p1.x - p1.y -> p2.x - p2.y -> d.x + s = new Source() + d = new Destination() + p1 = new Pass() + p2 = new Pass() + s.y -> d.y + s.y -> p1.x + p1.y -> p2.x + p2.y -> d.x } diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index eb46b4f7d6..ba6c38ca19 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output -// for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only +// once. Correct output for this 2, 4, 6, 8, etc. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/concurrent/ImportThreaded.lf b/test/C/src/concurrent/ImportThreaded.lf index b10a222f1a..a40fd11fb7 100644 --- a/test/C/src/concurrent/ImportThreaded.lf +++ b/test/C/src/concurrent/ImportThreaded.lf @@ -4,8 +4,8 @@ target C import Imported from "../lib/Imported.lf" main reactor ImportThreaded { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= lf_set(a.x, 42); =} + reaction(t) -> a.x {= lf_set(a.x, 42); =} } diff --git a/test/C/src/concurrent/MinimalThreaded.lf b/test/C/src/concurrent/MinimalThreaded.lf index 5252d0465f..dacafdcb73 100644 --- a/test/C/src/concurrent/MinimalThreaded.lf +++ b/test/C/src/concurrent/MinimalThreaded.lf @@ -2,7 +2,7 @@ target C main reactor MinimalThreaded { - timer t + timer t - reaction(t) {= printf("Hello World.\n"); =} + reaction(t) {= printf("Hello World.\n"); =} } diff --git a/test/C/src/concurrent/PingPongThreaded.lf b/test/C/src/concurrent/PingPongThreaded.lf index 37d7b97574..4fae17911e 100644 --- a/test/C/src/concurrent/PingPongThreaded.lf +++ b/test/C/src/concurrent/PingPongThreaded.lf @@ -1,19 +1,23 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. This is based on https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure + * message-passing overhead. This is based on + * https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the causality loop. + * Ping introduces a microstep delay using a logical action to break the + * causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - * Unthreaded: 97 msec Threaded: 265 msec (168 msec with optimization of executing immediately) + * Unthreaded: 97 msec Threaded: 265 msec (168 msec with optimization of + * executing immediately) * - * There is no parallelism in this application, so it does not benefit from being being threaded, - * just some additional overhead. + * There is no parallelism in this application, so it does not benefit from + * being being threaded, just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. These are about an - * order of magnitude faster than anything reported in the paper. + * These measurements are total execution time, including startup and shutdown. + * These are about an order of magnitude faster than anything reported in the + * paper. * * @author Edward A. Lee */ diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index dc0892195b..e5185ecfc8 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own reaction that routes -// inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own +// reaction that routes inputs to the contained reactor. target C { timeout: 10 sec, fast: true diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index 2e50b71a58..d1e78e5ced 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -1,6 +1,7 @@ /** - * Test that the starvation functionality in absence of the "keepalive: true" target property indeed - * works as expected. This version uses the threaded runtime. + * Test that the starvation functionality in absence of the "keepalive: true" + * target property indeed works as expected. This version uses the threaded + * runtime. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index 7beb0cb747..1deb1c4ff6 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -1,6 +1,6 @@ /** - * A test for the lf_request_stop() functionality in Lingua Franca. This version of the test is - * threaded. + * A test for the lf_request_stop() functionality in Lingua Franca. This version + * of the test is threaded. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index 22f5635e6c..7afd4b0069 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -1,5 +1,6 @@ /** - * Test for lf_request_stop() at tag (0,0). This version uses the threaded runtime. + * Test for lf_request_stop() at tag (0,0). This version uses the threaded + * runtime. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/Threaded.lf b/test/C/src/concurrent/Threaded.lf index 4daa36f6fd..01f67c1bd4 100644 --- a/test/C/src/concurrent/Threaded.lf +++ b/test/C/src/concurrent/Threaded.lf @@ -1,13 +1,16 @@ -// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime -// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that -// without parallel execution, there is no way this can keep up with real time since in every 200 -// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing -// that without threads, this takes more than 800 msec to complete 200 msec of logical time. See -// ThreadedMultiport for a parameterized version of this. +// Check for speedup of multithreaded execution on multicore machines. Each +// instance of TakeTime takes 200 ms to transport the input to the output. Four +// of them are instantiated. Note that without parallel execution, there is no +// way this can keep up with real time since in every 200 msec cycle it has 800 +// msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded +// version, showing that without threads, this takes more than 800 msec to +// complete 200 msec of logical time. See ThreadedMultiport for a parameterized +// version of this. target C { timeout: 2 sec, - flags: "" // Disable compiler optimization so that TakeTime actually takes time. + // Disable compiler optimization so that TakeTime actually takes time. + flags: "" } reactor Source { diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index cbf8459b08..2878393dac 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -1,7 +1,8 @@ // Check multiport capabilities on Outputs. target C { timeout: 2 sec, - flags: "" // Disable compiler optimization so that TakeTime actually takes time. + // Disable compiler optimization so that TakeTime actually takes time. + flags: "" } reactor Source(width: int = 4) { diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 0ff1f1e09b..4037e8c193 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -1,13 +1,15 @@ -// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime -// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that -// without parallel execution, there is no way this can keep up with real time since in every 200 -// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. See ThreadedMultiport for a parameterized version -// of this. +// Check for speedup of multithreaded execution on multicore machines. Each +// instance of TakeTime takes 200 ms to transport the input to the output. Four +// of them are instantiated. Note that without parallel execution, there is no +// way this can keep up with real time since in every 200 msec cycle it has 800 +// msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. See ThreadedMultiport for a +// parameterized version of this. target C { timeout: 2 sec, tracing: true, - flags: "" // Disable compiler optimization so that TakeTime actually takes time. + // Disable compiler optimization so that TakeTime actually takes time. + flags: "" } reactor Source { diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index 07bd3c9257..8d3824af47 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -1,5 +1,5 @@ -// Test that the stop function can be used to internally impose a a time limit. Correct output for -// this 1, 2, 3, 4. Failure for this test is failing to halt. +// Test that the stop function can be used to internally impose a a time limit. +// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt. target C { fast: true } diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 41fd8d1147..82ef231ed9 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -1,5 +1,6 @@ /** - * A test for the timeout functionality in Lingua Franca. This version of the test is threaded. + * A test for the timeout functionality in Lingua Franca. This version of the + * test is threaded. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index 9df91b99ba..7865b486a9 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -1,6 +1,6 @@ /** - * A test for the timeout functionality in Lingua Franca. This variant tests timeout at (0,0) and - * uses the threaded runtime. + * A test for the timeout functionality in Lingua Franca. This variant tests + * timeout at (0,0) and uses the threaded runtime. * * @author Soroush Bateni */ diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index 2d13fbf259..cbc4513732 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -2,7 +2,8 @@ target C { timeout: 2 sec, tracing: true, - flags: "", // Disable compiler optimization so that TakeTime actually takes time. + // Disable compiler optimization so that TakeTime actually takes time. + flags: "", logging: DEBUG } diff --git a/test/C/src/concurrent/Workers.lf b/test/C/src/concurrent/Workers.lf index 8bf88dd6f5..90dbecb468 100644 --- a/test/C/src/concurrent/Workers.lf +++ b/test/C/src/concurrent/Workers.lf @@ -1,13 +1,13 @@ target C { - workers: 16 + workers: 16 } main reactor { - reaction(startup) {= - if (NUMBER_OF_WORKERS != 16) { - lf_print_error_and_exit("Expected to have 16 workers."); - } else { - lf_print("Using 16 workers."); - } - =} + reaction(startup) {= + if (NUMBER_OF_WORKERS != 16) { + lf_print_error_and_exit("Expected to have 16 workers."); + } else { + lf_print("Using 16 workers."); + } + =} } diff --git a/test/C/src/docker/FilesPropertyContainerized.lf b/test/C/src/docker/FilesPropertyContainerized.lf index f9a1a240f3..ca50fc8ac6 100644 --- a/test/C/src/docker/FilesPropertyContainerized.lf +++ b/test/C/src/docker/FilesPropertyContainerized.lf @@ -1,15 +1,15 @@ target C { - files: "../include/hello.h", - docker: true + files: "../include/hello.h", + docker: true } preamble {= - #include "hello.h" + #include "hello.h" =} main reactor { - reaction(startup) {= - hello_t hello; - printf("SUCCESS\n"); - =} + reaction(startup) {= + hello_t hello; + printf("SUCCESS\n"); + =} } diff --git a/test/C/src/docker/HelloWorldContainerized.lf b/test/C/src/docker/HelloWorldContainerized.lf index 9a0b2e8403..f486c7bb9a 100644 --- a/test/C/src/docker/HelloWorldContainerized.lf +++ b/test/C/src/docker/HelloWorldContainerized.lf @@ -1,14 +1,14 @@ target C { - tracing: { // To test generating a custom trace file name. - trace-file-name: "HelloWorldTrace" - }, - logging: error, - docker: true, - build-type: Debug + tracing: { // To test generating a custom trace file name. + trace-file-name: "HelloWorldTrace" + }, + logging: error, + docker: true, + build-type: Debug } import HelloWorld2 from "../HelloWorld.lf" main reactor { - a = new HelloWorld2() + a = new HelloWorld2() } diff --git a/test/C/src/docker/PingPongContainerized.lf b/test/C/src/docker/PingPongContainerized.lf index 10062bb3eb..5cce20321f 100644 --- a/test/C/src/docker/PingPongContainerized.lf +++ b/test/C/src/docker/PingPongContainerized.lf @@ -18,16 +18,16 @@ * @author Edward A. Lee */ target C { - fast: true, - docker: true + fast: true, + docker: true } import Ping from "../PingPong.lf" import Pong from "../PingPong.lf" main reactor PingPongContainerized { - ping = new Ping() - pong = new Pong() - ping.send -> pong.receive - pong.send -> ping.receive + ping = new Ping() + pong = new Pong() + ping.send -> pong.receive + pong.send -> ping.receive } diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index 13ae54fd80..4a120c5e1e 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { diff --git a/test/C/src/docker/federated/DistributedDoublePortContainerized.lf b/test/C/src/docker/federated/DistributedDoublePortContainerized.lf index 6227b8b00a..c9273862c5 100644 --- a/test/C/src/docker/federated/DistributedDoublePortContainerized.lf +++ b/test/C/src/docker/federated/DistributedDoublePortContainerized.lf @@ -5,10 +5,10 @@ * @author Soroush Bateni */ target C { - timeout: 900 msec, - logging: DEBUG, - coordination: centralized, - docker: true + timeout: 900 msec, + logging: DEBUG, + coordination: centralized, + docker: true } import Count from "../../lib/Count.lf" @@ -16,9 +16,9 @@ import CountMicrostep from "../../federated/DistributedDoublePort.lf" import Print from "../../federated/DistributedDoublePort.lf" federated reactor DistributedDoublePortContainerized at rti { - c = new Count() - cm = new CountMicrostep() - p = new Print() - c.out -> p.in // Indicating a 'logical' connection. - cm.out -> p.in2 + c = new Count() + cm = new CountMicrostep() + p = new Print() + c.out -> p.in // Indicating a 'logical' connection. + cm.out -> p.in2 } diff --git a/test/C/src/docker/federated/DistributedMultiportContainerized.lf b/test/C/src/docker/federated/DistributedMultiportContainerized.lf index c162e5189f..ec27e0dea3 100644 --- a/test/C/src/docker/federated/DistributedMultiportContainerized.lf +++ b/test/C/src/docker/federated/DistributedMultiportContainerized.lf @@ -1,14 +1,14 @@ // Check multiport connections between federates. target C { - timeout: 1 sec, - coordination: centralized, - docker: true + timeout: 1 sec, + coordination: centralized, + docker: true } import Source, Destination from "../../federated/DistributedMultiport.lf" federated reactor DistributedMultiportContainerized at rti { - s = new Source() - d = new Destination() - s.out -> d.in + s = new Source() + d = new Destination() + s.out -> d.in } diff --git a/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf index 342dde28e0..5480a6f06c 100644 --- a/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -4,14 +4,14 @@ * @author Soroush Bateni */ target C { - coordination: decentralized, - docker: true + coordination: decentralized, + docker: true } import Sender, Receiver from "../../federated/DistributedStop.lf" federated reactor DistributedStopDecentralizedContainerized at rti { - sender = new Sender() - receiver = new Receiver() - sender.out -> receiver.in + sender = new Sender() + receiver = new Receiver() + sender.out -> receiver.in } diff --git a/test/C/src/federated/BroadcastFeedback.lf b/test/C/src/federated/BroadcastFeedback.lf index b38bb399d7..2bef908d2d 100644 --- a/test/C/src/federated/BroadcastFeedback.lf +++ b/test/C/src/federated/BroadcastFeedback.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target C { timeout: 1 sec, build-type: RelWithDebInfo diff --git a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf index 7ac7edecb1..d9edbc954b 100644 --- a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target C { timeout: 1 sec } diff --git a/test/C/src/federated/ChainWithDelay.lf b/test/C/src/federated/ChainWithDelay.lf index 2638756e19..c0a4c6a2a9 100644 --- a/test/C/src/federated/ChainWithDelay.lf +++ b/test/C/src/federated/ChainWithDelay.lf @@ -4,7 +4,7 @@ * @author Edward A. Lee */ target C { - timeout: 3 msec + timeout: 3 msec } import Count from "../lib/Count.lf" @@ -12,9 +12,9 @@ import InternalDelay from "../lib/InternalDelay.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - c = new Count(period = 1 msec) - i = new InternalDelay(delay = 500 usec) - t = new TestCount(num_inputs = 3) - c.out -> i.in - i.out -> t.in + c = new Count(period = 1 msec) + i = new InternalDelay(delay = 500 usec) + t = new TestCount(num_inputs = 3) + c.out -> i.in + i.out -> t.in } diff --git a/test/C/src/federated/CycleDetection.lf b/test/C/src/federated/CycleDetection.lf index fb5bf39a7c..d22837bc1f 100644 --- a/test/C/src/federated/CycleDetection.lf +++ b/test/C/src/federated/CycleDetection.lf @@ -1,6 +1,6 @@ /** - * Check whether the internally generated network and control reactions introduce a cycle or not. - * The failure for this test is not being compiled. + * Check whether the internally generated network and control reactions + * introduce a cycle or not. The failure for this test is not being compiled. * @author Edward A. Lee */ target C diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 2d007d2b09..9dea4032aa 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -1,7 +1,8 @@ /** - * Test a source-destination scenario where the source falls behind real-time, and reaches the - * timeout much later than the destination. In this test, the destination closes the connection - * early, causing the transmission to fail. Warnings will be printed about lost messages. + * Test a source-destination scenario where the source falls behind real-time, + * and reaches the timeout much later than the destination. In this test, the + * destination closes the connection early, causing the transmission to fail. + * Warnings will be printed about lost messages. * * The test fails if the federation does not exit. */ @@ -21,7 +22,9 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { lf_set(y, self->count); =} - reaction(shutdown) {= lf_print("SUCCESS: the source exited successfully."); =} + reaction(shutdown) {= + lf_print("SUCCESS: the source exited successfully."); + =} } reactor Destination { diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index fc45db9d74..8468e1dc81 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -1,10 +1,11 @@ /** - * Test a source-destination scenario where the source falls behind real-time, and reaches the - * timeout much later than the destination. In this test, the destination closes the connection - * early, causing the transmission to fail. Warnings will be printed. + * Test a source-destination scenario where the source falls behind real-time, + * and reaches the timeout much later than the destination. In this test, the + * destination closes the connection early, causing the transmission to fail. + * Warnings will be printed. * - * The test fails if the federation does not exit amenably. This variant has a physical connection - * between source and destination. + * The test fails if the federation does not exit amenably. This variant has a + * physical connection between source and destination. */ target C { timeout: 1 msec, @@ -22,7 +23,9 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { lf_set(y, self->count); =} - reaction(shutdown) {= lf_print("SUCCESS: the source exited successfully."); =} + reaction(shutdown) {= + lf_print("SUCCESS: the source exited successfully."); + =} } reactor Destination { diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 472e7f83a0..2ebdda169a 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { diff --git a/test/C/src/federated/DistributedCountDecentralized.lf b/test/C/src/federated/DistributedCountDecentralized.lf index 473e959392..631dfab0c0 100644 --- a/test/C/src/federated/DistributedCountDecentralized.lf +++ b/test/C/src/federated/DistributedCountDecentralized.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { @@ -47,5 +48,6 @@ reactor Print { federated reactor DistributedCountDecentralized { c = new Count() p = new Print() - c.out -> p.in after 200 msec // Indicating a 'logical' connection with a large enough delay. + // Indicating a 'logical' connection with a large enough delay. + c.out -> p.in after 200 msec } diff --git a/test/C/src/federated/DistributedCountPhysical.lf b/test/C/src/federated/DistributedCountPhysical.lf index 77355720ff..9e1e15f775 100644 --- a/test/C/src/federated/DistributedCountPhysical.lf +++ b/test/C/src/federated/DistributedCountPhysical.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages only over connections that are marked 'physical' (using the ~> - * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is - * needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages only over connections that are + * marked 'physical' (using the ~> arrow). Therefore, no additional coordination + * of the advancement of time (HLA or Ptides) is needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf index eeb2792425..b0da42218a 100644 --- a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,7 +1,7 @@ /** - * Test a distributed system where a federation receives messages only over connections that are - * marked 'physical' (using the ~> arrow) with an after delay. The receiver verifies that the after - * delay is correctly imposed. + * Test a distributed system where a federation receives messages only over + * connections that are marked 'physical' (using the ~> arrow) with an after + * delay. The receiver verifies that the after delay is correctly imposed. * * @author Edward A. Lee * @author Soroush Bateni @@ -46,5 +46,6 @@ reactor Print { federated reactor at localhost { c = new Count(offset = 200 msec, period = 0) p = new Print() - c.out ~> p.in after 400 msec // Indicating a 'physical' connection with a 400 msec after delay. + // Indicating a 'physical' connection with a 400 msec after delay. + c.out ~> p.in after 400 msec } diff --git a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf index b9a606ba0b..e821e4fb70 100644 --- a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages only over connections that are marked 'physical' (using the ~> - * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is - * needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages only over connections that are + * marked 'physical' (using the ~> arrow). Therefore, no additional coordination + * of the advancement of time (HLA or Ptides) is needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/DistributedDoublePort.lf b/test/C/src/federated/DistributedDoublePort.lf index 3394c383b6..87de1ddb28 100644 --- a/test/C/src/federated/DistributedDoublePort.lf +++ b/test/C/src/federated/DistributedDoublePort.lf @@ -1,6 +1,7 @@ /** - * Test the case for when two upstream federates send messages to a downstream federate on two - * different ports. One message should carry a microstep delay relative to the other message. + * Test the case for when two upstream federates send messages to a downstream + * federate on two different ports. One message should carry a microstep delay + * relative to the other message. * * @author Soroush Bateni */ @@ -35,7 +36,9 @@ reactor Print { } =} - reaction(shutdown) {= lf_print("SUCCESS: messages were at least one microstep apart."); =} + reaction(shutdown) {= + lf_print("SUCCESS: messages were at least one microstep apart."); + =} } federated reactor DistributedDoublePort { diff --git a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf index a8c3805f34..acbbaf4035 100644 --- a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf @@ -1,6 +1,6 @@ /** - * Test that a rapidly produced logical action in an upstream federate can be properly handled in a - * long chain of federates. + * Test that a rapidly produced logical action in an upstream federate can be + * properly handled in a long chain of federates. */ target C { timeout: 1 msec diff --git a/test/C/src/federated/DistributedLoopedAction.lf b/test/C/src/federated/DistributedLoopedAction.lf index a398fb8b8d..8218e73646 100644 --- a/test/C/src/federated/DistributedLoopedAction.lf +++ b/test/C/src/federated/DistributedLoopedAction.lf @@ -1,5 +1,6 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken into account. + * Test a sender-receiver network system that relies on microsteps being taken + * into account. * * @author Soroush Bateni */ @@ -19,7 +20,8 @@ reactor Receiver( state breaks: int = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more sensible log output. + // but forces the logical time to advance Comment this line for a more + // sensible log output. reaction(in) {= printf("At tag (%lld, %u) received value %d.\n", lf_time_logical_elapsed(), diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index 5a51465e5c..17842809fa 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -1,13 +1,15 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken into account. The - * purpose of this test is to check whether the functionalities pertinent to dynamic STP offset - * adjustments are present and functioning to a degree. + * Test a sender-receiver network system that relies on microsteps being taken + * into account. The purpose of this test is to check whether the + * functionalities pertinent to dynamic STP offset adjustments are present and + * functioning to a degree. * - * This version of the test does not use a centralized coordinator to advance tag. Therefore, the - * receiver will rely on an STP offset (initially zero) to wait long enough for messages to arrive - * before advancing its tag. In this test, the STP offset is initially zero and gradually raised - * every time an STP violation is perceived until no STP violation is observed. Therefore, the exact - * outcome of the test will depend on actual runtime timing. + * This version of the test does not use a centralized coordinator to advance + * tag. Therefore, the receiver will rely on an STP offset (initially zero) to + * wait long enough for messages to arrive before advancing its tag. In this + * test, the STP offset is initially zero and gradually raised every time an STP + * violation is perceived until no STP violation is observed. Therefore, the + * exact outcome of the test will depend on actual runtime timing. * * @author Soroush Bateni */ @@ -114,7 +116,10 @@ reactor STPReceiver( federated reactor DistributedLoopedActionDecentralized { sender = new Sender(take_a_break_after = 10, break_interval = 400 msec) - stpReceiver = new STPReceiver(take_a_break_after = 10, break_interval = 400 msec) + stpReceiver = new STPReceiver( + take_a_break_after = 10, + break_interval = 400 msec + ) sender.out -> stpReceiver.in } diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index d1990c05ad..454577ff35 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -1,10 +1,11 @@ /** - * Test a sender-receiver network system that is similar to DistributedLoopedAction, but it uses a - * physical action rather than a logical action. This also demonstrates the advance-message-interval - * coordination option. This specifies the time period between Time Advance Notice (TAN) messages - * sent to the RTI (a form of null message that must be sent because of the physical action). The - * presence of this option also silences a warning about having a physical action that triggers an - * output. + * Test a sender-receiver network system that is similar to + * DistributedLoopedAction, but it uses a physical action rather than a logical + * action. This also demonstrates the advance-message-interval coordination + * option. This specifies the time period between Time Advance Notice (TAN) + * messages sent to the RTI (a form of null message that must be sent because of + * the physical action). The presence of this option also silences a warning + * about having a physical action that triggers an output. * * @author Soroush Bateni */ @@ -44,7 +45,8 @@ reactor Receiver( state breaks: int = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more sensible log output. + // but forces the logical time to advance Comment this line for a more + // sensible log output. reaction(in) {= tag_t current_tag = lf_tag(); lf_print("At tag (%lld, %u) received %d.", diff --git a/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf b/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf index 38c4e016fe..0397d3336d 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf @@ -4,15 +4,15 @@ * @author Soroush Bateni */ target C { - timeout: 1 sec, - coordination: decentralized + timeout: 1 sec, + coordination: decentralized } import Sender, Receiver from "DistributedLoopedPhysicalAction.lf" federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedMultiportToken.lf b/test/C/src/federated/DistributedMultiportToken.lf index c3a370cb66..dfb791d861 100644 --- a/test/C/src/federated/DistributedMultiportToken.lf +++ b/test/C/src/federated/DistributedMultiportToken.lf @@ -1,5 +1,5 @@ -// Check multiport connections between federates where the message is carried by a Token (in this -// case, with an array of char). +// Check multiport connections between federates where the message is carried by +// a Token (in this case, with an array of char). target C { timeout: 1 sec, coordination: centralized diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index 09ea7665c9..42f3da6134 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -1,9 +1,10 @@ /** * This is a test for send_timed_message, which is an internal API. * - * This test sends a second message at time 5 msec that has the same intended tag as a message that - * it had previously sent at time 0 msec. This results in a warning, but the message microstep is - * incremented and correctly received one microstep later. + * This test sends a second message at time 5 msec that has the same intended + * tag as a message that it had previously sent at time 0 msec. This results in + * a warning, but the message microstep is incremented and correctly received + * one microstep later. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedPhysicalActionUpstream.lf b/test/C/src/federated/DistributedPhysicalActionUpstream.lf index f41aa0dae3..520142b466 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstream.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstream.lf @@ -1,6 +1,6 @@ /** - * Test that a rapidly produced physical action in an upstream federate can be properly handled in - * federated execution. + * Test that a rapidly produced physical action in an upstream federate can be + * properly handled in federated execution. */ target C { timeout: 10 secs, diff --git a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf index a77727d9ce..5cee1171cc 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf @@ -1,6 +1,6 @@ /** - * Test that a rapidly produced physical action in an upstream federate can be properly handled in a - * long chain of federates. + * Test that a rapidly produced physical action in an upstream federate can be + * properly handled in a long chain of federates. */ target C { timeout: 1 sec, diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index 7d906a0efe..2d4a616664 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -1,5 +1,6 @@ /** - * Test for lf_request_stop() in federated execution with centralized coordination. + * Test for lf_request_stop() in federated execution with centralized + * coordination. * * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedStopDecentralized.lf b/test/C/src/federated/DistributedStopDecentralized.lf index f26dfe256a..c54bedd38c 100644 --- a/test/C/src/federated/DistributedStopDecentralized.lf +++ b/test/C/src/federated/DistributedStopDecentralized.lf @@ -4,14 +4,14 @@ * @author Soroush Bateni */ target C { - coordination: decentralized + coordination: decentralized } import Sender, Receiver from "DistributedStop.lf" federated reactor DistributedStopDecentralized { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedStopZero.lf b/test/C/src/federated/DistributedStopZero.lf index 82f49b9b91..2e0529ea1d 100644 --- a/test/C/src/federated/DistributedStopZero.lf +++ b/test/C/src/federated/DistributedStopZero.lf @@ -6,79 +6,79 @@ target C reactor Sender { - output out: int - timer t(0, 1 usec) + output out: int + timer t(0, 1 usec) - reaction(t) -> out {= - printf("Sending 42 at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); + reaction(t) -> out {= + printf("Sending 42 at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Sender failed to stop the federation in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Sender failed to stop the federation in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } reactor Receiver { - input in: int + input in: int - reaction(in) {= - printf("Received %d at (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} + reaction(in) {= + printf("Received %d at (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} - reaction(shutdown) {= - // Sender should have requested stop earlier than the receiver. - // Therefore, the shutdown events must occur at (0, 0) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Receiver failed to stop the federation in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + // Sender should have requested stop earlier than the receiver. + // Therefore, the shutdown events must occur at (0, 0) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Receiver failed to stop the federation in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedStopZeroDecentralized.lf b/test/C/src/federated/DistributedStopZeroDecentralized.lf index ae37fb3fc3..ac67ef8f20 100644 --- a/test/C/src/federated/DistributedStopZeroDecentralized.lf +++ b/test/C/src/federated/DistributedStopZeroDecentralized.lf @@ -8,8 +8,8 @@ target C import Sender, Receiver from "DistributedStopZero.lf" federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/HelloDistributed.lf b/test/C/src/federated/HelloDistributed.lf index f0d74eead3..909ce53b43 100644 --- a/test/C/src/federated/HelloDistributed.lf +++ b/test/C/src/federated/HelloDistributed.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target C @@ -48,5 +49,7 @@ federated reactor HelloDistributed at localhost { d = new Destination() // Reactor d is in federate Destination s.out -> d.in // This version preserves the timestamp. - reaction(startup) {= lf_print("Printing something in top-level federated reactor."); =} + reaction(startup) {= + lf_print("Printing something in top-level federated reactor."); + =} } diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index 15a1c46934..7fdc972b5a 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -1,5 +1,6 @@ /** - * This tests a feedback loop with physical actions and centralized coordination. + * This tests a feedback loop with physical actions and centralized + * coordination. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf index 9956d2ef34..f9b088b7d1 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf @@ -1,6 +1,6 @@ /** - * This tests that the precedence order of reaction invocation is kept when a feedback loop is - * present in centralized coordination. + * This tests that the precedence order of reaction invocation is kept when a + * feedback loop is present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 0e214813cd..17177aadb3 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,6 +1,7 @@ /** - * This tests that the precedence order of reaction invocation is kept in the hierarchy of reactors - * when a feedback loop is present in centralized coordination. + * This tests that the precedence order of reaction invocation is kept in the + * hierarchy of reactors when a feedback loop is present in centralized + * coordination. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index 98d7a54eab..4350c984b3 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -1,5 +1,6 @@ /** - * This tests a feedback loop with physical actions and decentralized coordination. + * This tests a feedback loop with physical actions and decentralized + * coordination. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 8646a477bf..9a49b5bde8 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -1,5 +1,6 @@ /** - * This tests a feedback loop with physical actions and centralized coordination. + * This tests a feedback loop with physical actions and centralized + * coordination. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/ParallelDestinations.lf b/test/C/src/federated/ParallelDestinations.lf index ee0a171cc4..1d76627853 100644 --- a/test/C/src/federated/ParallelDestinations.lf +++ b/test/C/src/federated/ParallelDestinations.lf @@ -1,23 +1,23 @@ /** Test parallel connections for federated execution. */ target C { - timeout: 2 sec + timeout: 2 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Source { - output[2] out: int - c1 = new Count() - c2 = new Count() + output[2] out: int + c1 = new Count() + c2 = new Count() - c1.out, c2.out -> out + c1.out, c2.out -> out } federated reactor { - s = new Source() - t1 = new TestCount(num_inputs = 3) - t2 = new TestCount(num_inputs = 3) + s = new Source() + t1 = new TestCount(num_inputs = 3) + t2 = new TestCount(num_inputs = 3) - s.out -> t1.in, t2.in + s.out -> t1.in, t2.in } diff --git a/test/C/src/federated/ParallelSources.lf b/test/C/src/federated/ParallelSources.lf index dab021efae..adcab8c689 100644 --- a/test/C/src/federated/ParallelSources.lf +++ b/test/C/src/federated/ParallelSources.lf @@ -1,24 +1,24 @@ /** Test parallel connections for federated execution. */ target C { - timeout: 2 sec + timeout: 2 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Destination { - input[2] in: int + input[2] in: int - t1 = new TestCount(num_inputs = 3) - t2 = new TestCount(num_inputs = 3) + t1 = new TestCount(num_inputs = 3) + t2 = new TestCount(num_inputs = 3) - in -> t1.in, t2.in + in -> t1.in, t2.in } federated reactor { - c1 = new Count() - c2 = new Count() - d = new Destination() + c1 = new Count() + c2 = new Count() + d = new Destination() - c1.out, c2.out -> d.in + c1.out, c2.out -> d.in } diff --git a/test/C/src/federated/ParallelSourcesMultiport.lf b/test/C/src/federated/ParallelSourcesMultiport.lf index 601d18c444..7d76c31522 100644 --- a/test/C/src/federated/ParallelSourcesMultiport.lf +++ b/test/C/src/federated/ParallelSourcesMultiport.lf @@ -1,34 +1,34 @@ /** Test parallel connections for federated execution. */ target C { - timeout: 2 sec + timeout: 2 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Source { - output[2] out: int - c1 = new Count() - c2 = new Count() + output[2] out: int + c1 = new Count() + c2 = new Count() - c1.out, c2.out -> out + c1.out, c2.out -> out } reactor Destination1 { - input[3] in: int + input[3] in: int - t1 = new TestCount(num_inputs = 3) - t2 = new TestCount(num_inputs = 3) - t3 = new TestCount(num_inputs = 3) + t1 = new TestCount(num_inputs = 3) + t2 = new TestCount(num_inputs = 3) + t3 = new TestCount(num_inputs = 3) - in -> t1.in, t2.in, t3.in + in -> t1.in, t2.in, t3.in } federated reactor { - s1 = new Source() - s2 = new Source() - d1 = new Destination1() - t4 = new TestCount(num_inputs = 3) + s1 = new Source() + s2 = new Source() + d1 = new Destination1() + t4 = new TestCount(num_inputs = 3) - s1.out, s2.out -> d1.in, t4.in + s1.out, s2.out -> d1.in, t4.in } diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index 4e8a6c7a5d..11b7a259cf 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -1,4 +1,7 @@ -/** This is a test that detects STP violations according to the physical time of message arrival. */ +/** + * This is a test that detects STP violations according to the physical time of + * message arrival. + */ target C { timeout: 1900 msec, coordination: decentralized diff --git a/test/C/src/federated/PingPongDistributed.lf b/test/C/src/federated/PingPongDistributed.lf index 147768f12d..e16de50ed2 100644 --- a/test/C/src/federated/PingPongDistributed.lf +++ b/test/C/src/federated/PingPongDistributed.lf @@ -1,18 +1,21 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. + * Basic benchmark from the Savina benchmark suite that is intended to measure + * message-passing overhead. * - * This version is distributed, communicating using logical connections over sockets. + * This version is distributed, communicating using logical connections over + * sockets. * - * See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). + * See [Benchmarks wiki + * page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). * * This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs and can be run on - * different machines. + * This is a distributed version, where Ping and Pong run in separate programs + * and can be run on different machines. * - * There is no parallelism in this application, so it does not benefit from being being distributed. + * There is no parallelism in this application, so it does not benefit from + * being being distributed. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/PingPongDistributedPhysical.lf b/test/C/src/federated/PingPongDistributedPhysical.lf index 16769ec929..d9ba517c59 100644 --- a/test/C/src/federated/PingPongDistributedPhysical.lf +++ b/test/C/src/federated/PingPongDistributedPhysical.lf @@ -1,24 +1,26 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. + * Basic benchmark from the Savina benchmark suite that is intended to measure + * message-passing overhead. * - * This version is distributed, communicating using physical connections over sockets. + * This version is distributed, communicating using physical connections over + * sockets. * * This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs and can be run on - * different machines. + * This is a distributed version, where Ping and Pong run in separate programs + * and can be run on different machines. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - Unthreaded: 97 msec * - Threaded: 265 msec * - Distributed: 53 seconds * - * There is no parallelism in this application, so it does not benefit from being being distributed. + * There is no parallelism in this application, so it does not benefit from + * being being distributed. * - * These measurements are total execution time, including startup and shutdown, of all three - * programs. + * These measurements are total execution time, including startup and shutdown, + * of all three programs. * * @author Edward A. Lee */ diff --git a/test/C/src/federated/SimpleFederated.lf b/test/C/src/federated/SimpleFederated.lf index 1a13a49d21..cb6a798f8b 100644 --- a/test/C/src/federated/SimpleFederated.lf +++ b/test/C/src/federated/SimpleFederated.lf @@ -1,17 +1,17 @@ target C { - timeout: 2 secs, - build-type: RelWithDebInfo + timeout: 2 secs, + build-type: RelWithDebInfo } reactor Fed { - input in: int - output out: int + input in: int + output out: int } federated reactor { - fed1 = new Fed() - fed2 = new Fed() + fed1 = new Fed() + fed2 = new Fed() - fed1.out -> fed2.in - fed2.out -> fed1.in + fed1.out -> fed2.in + fed2.out -> fed1.in } diff --git a/test/C/src/federated/StopAtShutdown.lf b/test/C/src/federated/StopAtShutdown.lf index aef59ef3a1..2ac97d6805 100644 --- a/test/C/src/federated/StopAtShutdown.lf +++ b/test/C/src/federated/StopAtShutdown.lf @@ -6,30 +6,30 @@ * @author Steven Wong */ target C { - timeout: 2 sec + timeout: 2 sec } reactor A { - input in: int + input in: int - reaction(startup) {= lf_print("Hello World!"); =} + reaction(startup) {= lf_print("Hello World!"); =} - reaction(in) {= lf_print("Got it"); =} + reaction(in) {= lf_print("Got it"); =} - reaction(shutdown) {= lf_request_stop(); =} + reaction(shutdown) {= lf_request_stop(); =} } reactor B { - output out: int - timer t(1 sec) + output out: int + timer t(1 sec) - reaction(t) -> out {= lf_set(out, 1); =} + reaction(t) -> out {= lf_set(out, 1); =} - reaction(shutdown) {= lf_request_stop(); =} + reaction(shutdown) {= lf_request_stop(); =} } federated reactor { - a = new A() - b = new B() - b.out -> a.in + a = new A() + b = new B() + b.out -> a.in } diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 42a7cb3a37..05932b1937 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -1,10 +1,11 @@ /** - * Test whether top-level reactions, actions, and ports are handled appropriately. + * Test whether top-level reactions, actions, and ports are handled + * appropriately. * * Currently, these artifacts are replicated on all federates. * - * @note This just tests for the correctness of the code generation. These top-level artifacts might - * be disallowed in the future. + * @note This just tests for the correctness of the code generation. These + * top-level artifacts might be disallowed in the future. */ target C { timeout: 1 msec diff --git a/test/C/src/federated/failing/ClockSync.lf b/test/C/src/federated/failing/ClockSync.lf index a6c1e254d3..1231ce9cbf 100644 --- a/test/C/src/federated/failing/ClockSync.lf +++ b/test/C/src/federated/failing/ClockSync.lf @@ -1,8 +1,8 @@ /** - * This program tests clock synchronization. It checks the clock synchronization error and fails if - * it exceeds a threshold. Note that failures could occur here intermittently because clock - * synchronization accuracy depends on many conditions. But the threshold is quite high, so failures - * should be rare. + * This program tests clock synchronization. It checks the clock synchronization + * error and fails if it exceeds a threshold. Note that failures could occur + * here intermittently because clock synchronization accuracy depends on many + * conditions. But the threshold is quite high, so failures should be rare. * @author Edward A. Lee */ target C { @@ -10,16 +10,21 @@ target C { timeout: 10 sec, clock-sync: on, // Turn on runtime clock synchronization. clock-sync-options: { - local-federates-on: true, // Forces all federates to perform clock sync. - // Collect useful statistics like average network delay and the standard deviation for the - // network delay over one clock synchronization cycle. Generates a warning if the standard - // deviation is higher than the clock sync guard. Artificially offsets clocks by multiples - // of 200 msec. + // Forces all federates to perform clock sync. + local-federates-on: true, + // Collect useful statistics like average network delay and the standard + // deviation for the network delay over one clock synchronization cycle. + // Generates a warning if the standard deviation is higher than the + // clock sync guard. Artificially offsets clocks by multiples of 200 + // msec. collect-stats: true, test-offset: 200 msec, - period: 5 msec, // Period with which runtime clock sync is performed. - trials: 10, // Number of messages exchanged to perform clock sync. - attenuation: 10 // Attenuation applied to runtime clock sync adjustments. + // Period with which runtime clock sync is performed. + period: 5 msec, + // Number of messages exchanged to perform clock sync. + trials: 10, + // Attenuation applied to runtime clock sync adjustments. + attenuation: 10 } } diff --git a/test/C/src/lib/Imported.lf b/test/C/src/lib/Imported.lf index 1c86f0cff8..30e17cd94e 100644 --- a/test/C/src/lib/Imported.lf +++ b/test/C/src/lib/Imported.lf @@ -5,8 +5,8 @@ target C import ImportedAgain from "./ImportedAgain.lf" reactor Imported { - input x: int - a = new ImportedAgain() + input x: int + a = new ImportedAgain() - reaction(x) -> a.x {= lf_set(a.x, x->value); =} + reaction(x) -> a.x {= lf_set(a.x, x->value); =} } diff --git a/test/C/src/lib/ImportedAgain.lf b/test/C/src/lib/ImportedAgain.lf index af57afcace..dbde5e9fb0 100644 --- a/test/C/src/lib/ImportedAgain.lf +++ b/test/C/src/lib/ImportedAgain.lf @@ -3,13 +3,13 @@ target C reactor ImportedAgain { - input x: int + input x: int - reaction(x) {= - printf("Received: %d.\n", x->value); - if (x->value != 42) { - printf("ERROR: Expected input to be 42. Got: %d.\n", x->value); - exit(1); - } - =} + reaction(x) {= + printf("Received: %d.\n", x->value); + if (x->value != 42) { + printf("ERROR: Expected input to be 42. Got: %d.\n", x->value); + exit(1); + } + =} } diff --git a/test/C/src/lib/ImportedComposition.lf b/test/C/src/lib/ImportedComposition.lf index 66a8845233..d434f4eb6a 100644 --- a/test/C/src/lib/ImportedComposition.lf +++ b/test/C/src/lib/ImportedComposition.lf @@ -3,18 +3,18 @@ target C reactor Gain { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= lf_set(y, x->value * 2); =} + reaction(x) -> y {= lf_set(y, x->value * 2); =} } reactor ImportedComposition { - input x: int - output y: int - g1 = new Gain() - g2 = new Gain() - x -> g1.x after 10 msec - g1.y -> g2.x after 30 msec - g2.y -> y after 15 msec + input x: int + output y: int + g1 = new Gain() + g2 = new Gain() + x -> g1.x after 10 msec + g1.y -> g2.x after 30 msec + g2.y -> y after 15 msec } diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index 60af8480c7..b996fe6ac5 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -6,9 +6,10 @@ target C /** - * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break after sending - * take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in + * consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break + * after sending take_a_break_after messages. */ reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { output out: int diff --git a/test/C/src/lib/TestCount.lf b/test/C/src/lib/TestCount.lf index e5cb1d601d..d3f29aec6c 100644 --- a/test/C/src/lib/TestCount.lf +++ b/test/C/src/lib/TestCount.lf @@ -1,6 +1,7 @@ /** - * Test that a counting sequence of inputs starts with the specified start parameter value, - * increments by the specified stride, and receives the specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start + * parameter value, increments by the specified stride, and receives the + * specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. diff --git a/test/C/src/modal_models/BanksModalStateReset.lf b/test/C/src/modal_models/BanksModalStateReset.lf index 95abf317fd..8e075715c8 100644 --- a/test/C/src/modal_models/BanksModalStateReset.lf +++ b/test/C/src/modal_models/BanksModalStateReset.lf @@ -1,4 +1,7 @@ -/** Modal Reactor Test. Tests reset of state variables in modes with banks of reactors. */ +/** + * Modal Reactor Test. Tests reset of state variables in modes with banks of + * reactors. + */ target C { fast: false, timeout: 4 sec @@ -45,7 +48,8 @@ main reactor { reset2.count2 -> test.events - reaction(stepper) -> reset1.next {= // Trigger mode change (separately because of #1278) + // Trigger mode change (separately because of #1278) + reaction(stepper) -> reset1.next {= for(int i = 0; i < reset1_width; i++) { lf_set(reset1[i].next, true); } diff --git a/test/C/src/modal_models/Count3Modes.lf b/test/C/src/modal_models/Count3Modes.lf index 6f597053e0..862915abed 100644 --- a/test/C/src/modal_models/Count3Modes.lf +++ b/test/C/src/modal_models/Count3Modes.lf @@ -36,9 +36,11 @@ main reactor { state expected_value: int = 1 - reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger + // Trigger + reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} - reaction(stepper) counter.count {= // Check + // Check + reaction(stepper) counter.count {= printf("%d\n", counter.count->value); if (!counter.count->is_present) { diff --git a/test/C/src/modal_models/MixedReactions.lf b/test/C/src/modal_models/MixedReactions.lf index 54d97fe156..78ea39c95c 100644 --- a/test/C/src/modal_models/MixedReactions.lf +++ b/test/C/src/modal_models/MixedReactions.lf @@ -1,6 +1,6 @@ /** - * Modal Reactor Test. Tests reactions that are defined between and after modes and should be - * ordered accordingly. + * Modal Reactor Test. Tests reactions that are defined between and after modes + * and should be ordered accordingly. */ target C { fast: true, diff --git a/test/C/src/modal_models/ModalNestedReactions.lf b/test/C/src/modal_models/ModalNestedReactions.lf index dcc61ae9c6..f42ad4573f 100644 --- a/test/C/src/modal_models/ModalNestedReactions.lf +++ b/test/C/src/modal_models/ModalNestedReactions.lf @@ -1,68 +1,68 @@ /** Modal Reactor Test. Checks disabling of reactions indirectly nested in an inactive mode */ target C { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } reactor CounterCycle { - input next: bool + input next: bool - output count: int - output only_in_two: bool - output never: int + output count: int + output only_in_two: bool + output never: int - initial mode One { - reaction(next) -> count, reset(Two) {= - lf_set(count, 1); - lf_set_mode(Two); - =} - } + initial mode One { + reaction(next) -> count, reset(Two) {= + lf_set(count, 1); + lf_set_mode(Two); + =} + } - mode Two { - fwd = new Forward() - next -> fwd.in - fwd.out -> only_in_two - reaction(next) -> count, reset(One) {= - lf_set(count, 2); - lf_set_mode(One); - =} - } + mode Two { + fwd = new Forward() + next -> fwd.in + fwd.out -> only_in_two + reaction(next) -> count, reset(One) {= + lf_set(count, 2); + lf_set_mode(One); + =} + } - mode Three { - reaction(next) -> never {= lf_set(never, true); =} - } + mode Three { + reaction(next) -> never {= lf_set(never, true); =} + } } reactor Forward { - input in: bool - output out: bool + input in: bool + output out: bool - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } main reactor { - timer stepper(0, 250 msec) - counter = new CounterCycle() + timer stepper(0, 250 msec) + counter = new CounterCycle() - reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger + reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger - reaction(stepper) counter.count, counter.only_in_two {= // Check - printf("%d\n", counter.count->value); + reaction(stepper) counter.count, counter.only_in_two {= // Check + printf("%d\n", counter.count->value); - if (!counter.count->is_present) { - printf("ERROR: Missing mode change.\n"); - exit(1); - } else if (counter.only_in_two->is_present && counter.count->value != 2) { - printf("ERROR: Indirectly nested reaction was not properly deactivated.\n"); - exit(2); - } else if (!counter.only_in_two->is_present && counter.count->value == 2) { - printf("ERROR: Missing output from indirectly nested reaction.\n"); - exit(3); - } - =} + if (!counter.count->is_present) { + printf("ERROR: Missing mode change.\n"); + exit(1); + } else if (counter.only_in_two->is_present && counter.count->value != 2) { + printf("ERROR: Indirectly nested reaction was not properly deactivated.\n"); + exit(2); + } else if (!counter.only_in_two->is_present && counter.count->value == 2) { + printf("ERROR: Missing output from indirectly nested reaction.\n"); + exit(3); + } + =} - reaction(counter.never) {= - printf("ERROR: Detected output from unreachable mode.\n"); - exit(4); - =} + reaction(counter.never) {= + printf("ERROR: Detected output from unreachable mode.\n"); + exit(4); + =} } diff --git a/test/C/src/multiport/BankGangedConnections.lf b/test/C/src/multiport/BankGangedConnections.lf index f8cd730cae..231014c55e 100644 --- a/test/C/src/multiport/BankGangedConnections.lf +++ b/test/C/src/multiport/BankGangedConnections.lf @@ -1,27 +1,27 @@ target C { - timeout: 0 sec + timeout: 0 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Through { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } reactor Bank { - input in: int - output out: int - t = new Through() - in, t.out -> t.in, out + input in: int + output out: int + t = new Through() + in, t.out -> t.in, out } main reactor { - b = new[2] Bank() - s = new Count() - t = new TestCount() - s.out, b.out -> b.in, t.in + b = new[2] Bank() + s = new Count() + t = new TestCount() + s.out, b.out -> b.in, t.in } diff --git a/test/C/src/multiport/BankMulticast.lf b/test/C/src/multiport/BankMulticast.lf index 35b4124c73..312a073464 100644 --- a/test/C/src/multiport/BankMulticast.lf +++ b/test/C/src/multiport/BankMulticast.lf @@ -3,36 +3,36 @@ * the container's output port. */ target C { - timeout: 3 sec, - fast: true + timeout: 3 sec, + fast: true } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Foo { - input in: int - output out: int + input in: int + output out: int - c = new Count() - c.out -> out + c = new Count() + c.out -> out - d = new TestCount(num_inputs = 4) - in -> d.in + d = new TestCount(num_inputs = 4) + in -> d.in } reactor Bar { - output[4] out: int + output[4] out: int - foo = new[4] Foo() + foo = new[4] Foo() - foo.out -> foo.in - foo.out -> out + foo.out -> foo.in + foo.out -> out } main reactor { - bar = new Bar() + bar = new Bar() - d = new[4] TestCount(num_inputs = 4) - bar.out -> d.in + d = new[4] TestCount(num_inputs = 4) + bar.out -> d.in } diff --git a/test/C/src/multiport/BankReactionsInContainer.lf b/test/C/src/multiport/BankReactionsInContainer.lf index 1e93ed7478..98d7cf4e1f 100644 --- a/test/C/src/multiport/BankReactionsInContainer.lf +++ b/test/C/src/multiport/BankReactionsInContainer.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target C { timeout: 1 sec } diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index a242a246cc..e1ffb4b2dd 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport input of the same - * reactors in the bank so that each reactor in the bank receives the output produced by itself and - * each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport + * input of the same reactors in the bank so that each reactor in the bank + * receives the output produced by itself and each other reactor. * * @author Edward A. Lee */ diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index 3554380d8a..1b49786060 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target C { timeout: 2 sec, fast: true @@ -8,7 +8,9 @@ target C { reactor Source(check_override: int = 0, bank_index: int = 0) { output out: int - reaction(startup) -> out {= lf_set(out, self->bank_index * self->check_override); =} + reaction(startup) -> out {= + lf_set(out, self->bank_index * self->check_override); + =} } reactor Destination(port_width: int = 3) { diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index 295032cb8d..e8ee6194b5 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf index c67fea9b45..dab31049a8 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,15 +1,15 @@ // Check multiport output to bank of recipients. Here, the bank is smaller than the width of the // sending port. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Destination from "MultiportFromBank.lf" import Container from "MultiportFromBankHierarchy.lf" main reactor MultiportFromBankHierarchyAfter { - a = new Container(port_width = 4) - b = new Destination(port_width = 4) - a.out -> b.in after 1 sec + a = new Container(port_width = 4) + b = new Destination(port_width = 4) + a.out -> b.in after 1 sec } diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index 0f606e4750..8323210946 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical +// reactor. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index e62d32b0c6..b87a91a79b 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version fo the Threaded test that uses a multiport input at the destination. Its -// purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the +// destination. Its purpose is to test multiport inputs. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportInParameterized.lf b/test/C/src/multiport/MultiportInParameterized.lf index fa8b64855c..bf7ec93f6e 100644 --- a/test/C/src/multiport/MultiportInParameterized.lf +++ b/test/C/src/multiport/MultiportInParameterized.lf @@ -1,5 +1,5 @@ -// This is a version of the Threaded test that uses a multiport input at the destination. Its -// purpose is to test multiport inputs. +// This is a version of the Threaded test that uses a multiport input at the +// destination. Its purpose is to test multiport inputs. target C { timeout: 2 sec, fast: true @@ -60,6 +60,7 @@ main reactor { a.out -> t2.in a.out -> t3.in a.out -> t4.in - // I.e.: t1.out -> b.in[0]; t2.out -> b.in[1]; t3.out -> b.in[2]; dt4.out -> b.in[3]; + // I.e.: t1.out -> b.in[0]; t2.out -> b.in[1]; t3.out -> b.in[2]; dt4.out -> + // b.in[3]; t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/C/src/multiport/MultiportMutableInput.lf b/test/C/src/multiport/MultiportMutableInput.lf index e5c398def4..e1f8d579c2 100644 --- a/test/C/src/multiport/MultiportMutableInput.lf +++ b/test/C/src/multiport/MultiportMutableInput.lf @@ -1,5 +1,6 @@ -// Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. -// It modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a ints on a multiport, which it passes to Scale. Scale +// requests a writable copy. It modifies it and passes it to Print. It gets +// freed after Print is done with it. target C reactor Source { diff --git a/test/C/src/multiport/MultiportMutableInputArray.lf b/test/C/src/multiport/MultiportMutableInputArray.lf index d27f97f93c..90907e4f44 100644 --- a/test/C/src/multiport/MultiportMutableInputArray.lf +++ b/test/C/src/multiport/MultiportMutableInputArray.lf @@ -1,6 +1,7 @@ -// Source produces a dynamically allocated arrays on a multiport, which it passes to Scale. Scale -// requests a writable copy, which, instead of copying, it just gets ownership of the original -// array. It modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated arrays on a multiport, which it +// passes to Scale. Scale requests a writable copy, which, instead of copying, +// it just gets ownership of the original array. It modifies it and passes it to +// Print. It gets freed after Print is done with it. target C reactor Source { diff --git a/test/C/src/multiport/MultiportToBank.lf b/test/C/src/multiport/MultiportToBank.lf index b4ef84e9dc..86146b9818 100644 --- a/test/C/src/multiport/MultiportToBank.lf +++ b/test/C/src/multiport/MultiportToBank.lf @@ -14,9 +14,10 @@ reactor Source(width: int = 2) { } =} - // Test also that multiple appearances of the same effect port do not result in multiple - // allocations of memory for the port. - reaction(dummy) -> out {= // Contents of the reactions does not matter (either could be empty) + // Test also that multiple appearances of the same effect port do not result + // in multiple allocations of memory for the port. + reaction(dummy) -> + out {= // Contents of the reactions does not matter (either could be empty) for(int i = 0; i < out_width; i++) { lf_set(out[i], i); } diff --git a/test/C/src/multiport/MultiportToBankAfter.lf b/test/C/src/multiport/MultiportToBankAfter.lf index 9ad4b04d71..ba26142243 100644 --- a/test/C/src/multiport/MultiportToBankAfter.lf +++ b/test/C/src/multiport/MultiportToBankAfter.lf @@ -1,4 +1,5 @@ -// Check multiport output to bank of recipients where the width of the bank is inferred. +// Check multiport output to bank of recipients where the width of the bank is +// inferred. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index 5cf16f77a0..444f02d170 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients where the source has two reactions that write to the -// output. +// Check multiport output to bank of recipients where the source has two +// reactions that write to the output. target C { timeout: 2 sec, fast: true @@ -14,8 +14,8 @@ reactor Source { } =} - // Test also that multiple appearances of the same effect port do not result in multiple - // allocations of memory for the port. + // Test also that multiple appearances of the same effect port do not result + // in multiple allocations of memory for the port. reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) for(int i = 0; i < out_width; i++) { diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index 93acb2081d..fbdc531bf0 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index bde5ee1169..41ca505077 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,6 @@ -// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that -// the destination reactor has width wider than the sender, so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical +// reactor. Note that the destination reactor has width wider than the sender, +// so one input is dangling. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToMultiportArray.lf b/test/C/src/multiport/MultiportToMultiportArray.lf index 5cfac7368d..9d86a4a522 100644 --- a/test/C/src/multiport/MultiportToMultiportArray.lf +++ b/test/C/src/multiport/MultiportToMultiportArray.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input. Destination port is wider than sending port. +// Check multiport output to multiport input. Destination port is wider than +// sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToPort.lf b/test/C/src/multiport/MultiportToPort.lf index a89c162e12..1784f2503c 100644 --- a/test/C/src/multiport/MultiportToPort.lf +++ b/test/C/src/multiport/MultiportToPort.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input. Destination port is wider than sending port. +// Check multiport output to multiport input. Destination port is wider than +// sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/PipelineAfter.lf b/test/C/src/multiport/PipelineAfter.lf index a9f9085873..e3256c5cb8 100644 --- a/test/C/src/multiport/PipelineAfter.lf +++ b/test/C/src/multiport/PipelineAfter.lf @@ -1,38 +1,38 @@ target C reactor Source { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= lf_set(out, 40); =} + reaction(startup) -> out {= lf_set(out, 40); =} } reactor Compute { - input in: unsigned - output out: unsigned + input in: unsigned + output out: unsigned - reaction(in) -> out {= lf_set(out, in->value + 2); =} + reaction(in) -> out {= lf_set(out, in->value + 2); =} } reactor Sink { - input in: unsigned - - reaction(in) {= - printf("Received %d\n", in->value); - if (in->value != 42) { - printf("ERROR: expected 42!\n"); - exit(1); - } - if (lf_time_logical_elapsed() != SEC(1)) { - printf("ERROR: Expected to receive input after one second.\n"); - exit(2); - } - =} + input in: unsigned + + reaction(in) {= + printf("Received %d\n", in->value); + if (in->value != 42) { + printf("ERROR: expected 42!\n"); + exit(1); + } + if (lf_time_logical_elapsed() != SEC(1)) { + printf("ERROR: Expected to receive input after one second.\n"); + exit(2); + } + =} } main reactor { - source = new Source() - compute = new Compute() - sink = new Sink() + source = new Source() + compute = new Compute() + sink = new Sink() - source.out, compute.out -> compute.in, sink.in after 500 msec + source.out, compute.out -> compute.in, sink.in after 500 msec } diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index 458d963bb9..d84b21c191 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -1,4 +1,5 @@ -// Test reaction sending messages to a contained bank of reactors with a multiport input. +// Test reaction sending messages to a contained bank of reactors with a +// multiport input. target C { timeout: 1 sec, fast: true diff --git a/test/C/src/multiport/ReactionsToNested.lf b/test/C/src/multiport/ReactionsToNested.lf index db8c1da63d..4270f55c2d 100644 --- a/test/C/src/multiport/ReactionsToNested.lf +++ b/test/C/src/multiport/ReactionsToNested.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target C { timeout: 1 sec } diff --git a/test/C/src/multiport/SparseFallback.lf b/test/C/src/multiport/SparseFallback.lf index 1326f9ca99..a7788858d8 100644 --- a/test/C/src/multiport/SparseFallback.lf +++ b/test/C/src/multiport/SparseFallback.lf @@ -1,6 +1,6 @@ /** - * Test reading of sparse inputs on a multiport where the density of writes to the multiport is high - * enough to force the fallback policy to kick in. + * Test reading of sparse inputs on a multiport where the density of writes to + * the multiport is high enough to force the fallback policy to kick in. */ target C { timeout: 20 ms diff --git a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf index d4a37bbaee..917982af39 100644 --- a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf +++ b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf @@ -1,4 +1,7 @@ -/** This test checks that a downstream reaction is triggered only if its trigger is present. */ +/** + * This test checks that a downstream reaction is triggered only if its trigger + * is present. + */ target C { timeout: 1 sec, fast: true diff --git a/test/C/src/serialization/PersonProtocolBuffers.lf b/test/C/src/serialization/PersonProtocolBuffers.lf index f2572fc72f..ffc346db3d 100644 --- a/test/C/src/serialization/PersonProtocolBuffers.lf +++ b/test/C/src/serialization/PersonProtocolBuffers.lf @@ -18,29 +18,29 @@ * typically at /usr/local/bin. */ target C { - protobufs: Person.proto + protobufs: Person.proto } main reactor { - reaction(startup) {= - Person person = PERSON__INIT; // Macro to create the protocol buffer - uint8_t* buffer; // Buffer to store the serialized data - unsigned len; // Length of the packed message + reaction(startup) {= + Person person = PERSON__INIT; // Macro to create the protocol buffer + uint8_t* buffer; // Buffer to store the serialized data + unsigned len; // Length of the packed message - person.name = "Lingua Franca"; - person.id = 1; - person.email = "eal@berkeley.edu"; + person.name = "Lingua Franca"; + person.id = 1; + person.email = "eal@berkeley.edu"; - // Pack the message into buffer. - len = person__get_packed_size(&person); - buffer = (uint8_t*)malloc(len); - person__pack(&person, buffer); + // Pack the message into buffer. + len = person__get_packed_size(&person); + buffer = (uint8_t*)malloc(len); + person__pack(&person, buffer); - // Now unpack the message from buffer. - Person *unpacked = person__unpack(NULL, len, buffer); + // Now unpack the message from buffer. + Person *unpacked = person__unpack(NULL, len, buffer); - // Extract and print the unpacked message. - printf("Name: %s\n", unpacked->name); - free(buffer); // Free the allocated serialized buffer - =} + // Extract and print the unpacked message. + printf("Name: %s\n", unpacked->name); + free(buffer); // Free the allocated serialized buffer + =} } diff --git a/test/C/src/serialization/ProtoNoPacking.lf b/test/C/src/serialization/ProtoNoPacking.lf index 91464570fc..57b610e337 100644 --- a/test/C/src/serialization/ProtoNoPacking.lf +++ b/test/C/src/serialization/ProtoNoPacking.lf @@ -17,29 +17,29 @@ * typically at /usr/local/bin. */ target C { - protobufs: [ProtoHelloWorld.proto] + protobufs: [ProtoHelloWorld.proto] } reactor SourceProto { - output out: ProtoHelloWorld + output out: ProtoHelloWorld - reaction(startup) -> out {= - out->value.name = "Hello World"; - out->value.number = 42; - SET_PRESENT(out); - =} + reaction(startup) -> out {= + out->value.name = "Hello World"; + out->value.number = 42; + SET_PRESENT(out); + =} } reactor SinkProto { - input in: ProtoHelloWorld + input in: ProtoHelloWorld - reaction(in) {= - printf("Received: name=\"%s\", number=%d.\n", in->value.name, in->value.number); - =} + reaction(in) {= + printf("Received: name=\"%s\", number=%d.\n", in->value.name, in->value.number); + =} } main reactor ProtoNoPacking { - s = new SourceProto() - d = new SinkProto() - s.out -> d.in + s = new SourceProto() + d = new SinkProto() + s.out -> d.in } diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index dc5902885e..97b5a12554 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -1,12 +1,13 @@ /** - * This test showcases the infrastructure that is built into the CCpp target that can automatically - * serialize and deserialize ROS2 messages (with a shared_ptr type) in federated programs. + * This test showcases the infrastructure that is built into the CCpp target + * that can automatically serialize and deserialize ROS2 messages (with a + * shared_ptr type) in federated programs. * - * This test contains a sender-receiver federated program in which the 'sender' federate sends a - * std_msgs::msg::Int32 message to the 'receiver' federate. + * This test contains a sender-receiver federated program in which the 'sender' + * federate sends a std_msgs::msg::Int32 message to the 'receiver' federate. * - * To run this test, make sure that your terminal is properly sourced for ROS2. See - * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. + * To run this test, make sure that your terminal is properly sourced for ROS2. + * See https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. * * Then you can use lfc to compile this program: * diff --git a/test/C/src/target/CMakeInclude.lf b/test/C/src/target/CMakeInclude.lf index 6b9d3b2ecc..e1215fa85e 100644 --- a/test/C/src/target/CMakeInclude.lf +++ b/test/C/src/target/CMakeInclude.lf @@ -2,28 +2,28 @@ * Test that cmake-include is working correctly. The failure for this test is failure to compile. */ target C { - cmake-include: [ - "../include/mlib-cmake-extension.cmake", - "../include/foo-cmake-compile-definition.txt" - ], - timeout: 0 sec + cmake-include: [ + "../include/mlib-cmake-extension.cmake", + "../include/foo-cmake-compile-definition.txt" + ], + timeout: 0 sec } reactor Foo { - preamble {= - #include - =} + preamble {= + #include + =} - reaction(startup) {= - lf_print("Maximum of 4.20 and %.2f is %.2f", FOO, fmax(4.20, FOO)); + reaction(startup) {= + lf_print("Maximum of 4.20 and %.2f is %.2f", FOO, fmax(4.20, FOO)); - // Check if BAR is defined, which is an error condition (@see federated/DistributedCMakeIncludeSeparateCompile.lf). - #ifdef BAR - #error "I found definition for BAR in Foo. Failed to compile federates separately." - #endif // BAR - =} + // Check if BAR is defined, which is an error condition (@see federated/DistributedCMakeIncludeSeparateCompile.lf). + #ifdef BAR + #error "I found definition for BAR in Foo. Failed to compile federates separately." + #endif // BAR + =} } main reactor { - f = new Foo() + f = new Foo() } diff --git a/test/C/src/target/DistributedCMakeInclude.lf b/test/C/src/target/DistributedCMakeInclude.lf index 486dafa608..e9b393f3d1 100644 --- a/test/C/src/target/DistributedCMakeInclude.lf +++ b/test/C/src/target/DistributedCMakeInclude.lf @@ -3,29 +3,29 @@ * 3.14. The failure for this test is failure to compile. */ target C { - timeout: 0 sec, - cmake-include: "include/bar-cmake-compile-definition.cmake" + timeout: 0 sec, + cmake-include: "include/bar-cmake-compile-definition.cmake" } import Baz from "lib/ImportedCMakeInclude.lf" reactor Bar { - baz = new Baz() - preamble {= - #include - =} + baz = new Baz() + preamble {= + #include + =} - reaction(startup) {= - lf_print("Maximum of 4.20 and %.2f is %.2f", BAR, fmax(4.20, BAR)); + reaction(startup) {= + lf_print("Maximum of 4.20 and %.2f is %.2f", BAR, fmax(4.20, BAR)); - // Check if FOO is defined, which is an error condition (@see DistributedCMakeIncludeSeparateCompile.lf). - #ifdef FOO - #error "I found definition for FOO in Bar. Failed to compile federates separately." - #endif // FOO - =} + // Check if FOO is defined, which is an error condition (@see DistributedCMakeIncludeSeparateCompile.lf). + #ifdef FOO + #error "I found definition for FOO in Bar. Failed to compile federates separately." + #endif // FOO + =} } federated reactor { - f1 = new Bar() - f2 = new Bar() + f1 = new Bar() + f2 = new Bar() } diff --git a/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf b/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf index f1cf671c03..12711c3203 100644 --- a/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf +++ b/test/C/src/target/DistributedCMakeIncludeSeparateCompile.lf @@ -4,13 +4,13 @@ * compile. */ target C { - timeout: 0 sec + timeout: 0 sec } import Foo from "CMakeInclude.lf" import Bar from "DistributedCMakeInclude.lf" federated reactor { - f1 = new Foo() - b1 = new Bar() + f1 = new Foo() + b1 = new Bar() } diff --git a/test/C/src/target/Files.lf b/test/C/src/target/Files.lf index a89ad56da4..e49bd80684 100644 --- a/test/C/src/target/Files.lf +++ b/test/C/src/target/Files.lf @@ -1,17 +1,17 @@ /** Test the files target property. */ target C { - files: ["../include", "include/dummy.h"] + files: ["../include", "include/dummy.h"] } preamble {= - #include "include/hello.h" - #include "dummy.h" + #include "include/hello.h" + #include "dummy.h" =} main reactor { - reaction(startup) {= - hello_t t; - dummy_t d; - lf_print("SUCCESS."); - =} + reaction(startup) {= + hello_t t; + dummy_t d; + lf_print("SUCCESS."); + =} } diff --git a/test/C/src/target/HelloWorldCCPP.lf b/test/C/src/target/HelloWorldCCPP.lf index 917ca4308a..91d1cd61d1 100644 --- a/test/C/src/target/HelloWorldCCPP.lf +++ b/test/C/src/target/HelloWorldCCPP.lf @@ -1,6 +1,6 @@ /** - * A variant of HelloWorld.lf that tests the CCpp target in conjunction with the CMake build system. - * This test should not pass if it does not compile. + * A variant of HelloWorld.lf that tests the CCpp target in conjunction with the + * CMake build system. This test should not pass if it does not compile. */ target CCpp { tracing: true, diff --git a/test/C/src/target/HelloWorldFederatedCCPP.lf b/test/C/src/target/HelloWorldFederatedCCPP.lf index 54c285c700..25124a18fc 100644 --- a/test/C/src/target/HelloWorldFederatedCCPP.lf +++ b/test/C/src/target/HelloWorldFederatedCCPP.lf @@ -3,14 +3,14 @@ * should not pass if it does not compile. */ target CCpp { - tracing: true, - coordination: centralized, - timeout: 1 sec + tracing: true, + coordination: centralized, + timeout: 1 sec } import HelloWorld from "HelloWorldCCPP.lf" federated reactor { - a = new HelloWorld() - b = new HelloWorld() // Create a non-singleton federation + a = new HelloWorld() + b = new HelloWorld() // Create a non-singleton federation } diff --git a/test/C/src/target/HelloWorldThreadedCPP.lf b/test/C/src/target/HelloWorldThreadedCPP.lf index 259ea9d320..e6e2a257e8 100644 --- a/test/C/src/target/HelloWorldThreadedCPP.lf +++ b/test/C/src/target/HelloWorldThreadedCPP.lf @@ -3,12 +3,12 @@ * does not compile. */ target CCpp { - tracing: true, - logging: DEBUG + tracing: true, + logging: DEBUG } import HelloWorld from "HelloWorldCCPP.lf" main reactor { - a = new HelloWorld() + a = new HelloWorld() } diff --git a/test/C/src/target/Platform.lf b/test/C/src/target/Platform.lf index 79e163b2af..00895a749f 100644 --- a/test/C/src/target/Platform.lf +++ b/test/C/src/target/Platform.lf @@ -1,8 +1,8 @@ /** Test that the cross-compile capability works as expected. */ target C { - platform: "Mac" + platform: "Mac" } main reactor { - reaction(startup) {= lf_print("Hello, Mac!"); =} + reaction(startup) {= lf_print("Hello, Mac!"); =} } diff --git a/test/C/src/target/lib/ImportedCMakeInclude.lf b/test/C/src/target/lib/ImportedCMakeInclude.lf index fc44313fad..e272c2aa96 100644 --- a/test/C/src/target/lib/ImportedCMakeInclude.lf +++ b/test/C/src/target/lib/ImportedCMakeInclude.lf @@ -1,18 +1,18 @@ target C { - cmake-include: "../include/baz-cmake-compile-definition.cmake" + cmake-include: "../include/baz-cmake-compile-definition.cmake" } reactor Baz { - preamble {= - #include - =} + preamble {= + #include + =} - reaction(startup) {= - lf_print("Maximum of 4.20 and %.2f is %.2f", BAZ, fmax(4.20, BAZ)); + reaction(startup) {= + lf_print("Maximum of 4.20 and %.2f is %.2f", BAZ, fmax(4.20, BAZ)); - // Check if FOO is defined, which is an error condition (@see DistributedCMakeIncludeSeparateCompile.lf). - #ifdef FOO - #error "I found definition for FOO in Baz. Failed to compile federates separately." - #endif // FOO - =} + // Check if FOO is defined, which is an error condition (@see DistributedCMakeIncludeSeparateCompile.lf). + #ifdef FOO + #error "I found definition for FOO in Baz. Failed to compile federates separately." + #endif // FOO + =} } diff --git a/test/Cpp/src/ActionWithNoReaction.lf b/test/Cpp/src/ActionWithNoReaction.lf index f4c0fa8a01..78f1011544 100644 --- a/test/Cpp/src/ActionWithNoReaction.lf +++ b/test/Cpp/src/ActionWithNoReaction.lf @@ -1,36 +1,36 @@ // This checks that action can be created even if there is no reaction. This test passes merely by // compiling and executing without a segfault. Its other functionality is tested by other tests. target Cpp { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x: int - output y: int - logical action a + input x: int + output y: int + logical action a - reaction(x) -> y, a {= - y.set(2*(*x.get())); - a.schedule(500ms); - =} + reaction(x) -> y, a {= + y.set(2*(*x.get())); + a.schedule(500ms); + =} } reactor print { - input x: int + input x: int - reaction(x) {= - std::cout << "Result is " << *x.get() << '\n'; - std::cout << "Current logical time is: " << get_elapsed_logical_time() << '\n'; - std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; - =} + reaction(x) {= + std::cout << "Result is " << *x.get() << '\n'; + std::cout << "Current logical time is: " << get_elapsed_logical_time() << '\n'; + std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x - reaction(t) -> f.x {= f.x.set(42); =} + reaction(t) -> f.x {= f.x.set(42); =} } diff --git a/test/Cpp/src/After.lf b/test/Cpp/src/After.lf index 40f9e3a54b..bbcc287b78 100644 --- a/test/Cpp/src/After.lf +++ b/test/Cpp/src/After.lf @@ -1,4 +1,5 @@ -// This checks that the after keyword adjusts logical time, not using physical time. +// This checks that the after keyword adjusts logical time, not using physical +// time. target Cpp { fast: false, timeout: 3 sec diff --git a/test/Cpp/src/AfterZero.lf b/test/Cpp/src/AfterZero.lf index 59ba9b4fb3..152b87cfc2 100644 --- a/test/Cpp/src/AfterZero.lf +++ b/test/Cpp/src/AfterZero.lf @@ -1,4 +1,5 @@ -// This checks that the after keyword adjusts logical time, not using physical time. +// This checks that the after keyword adjusts logical time, not using physical +// time. target Cpp { fast: false, timeout: 3 sec diff --git a/test/Cpp/src/Alignment.lf b/test/Cpp/src/Alignment.lf index 0ab486903c..1bd3562f41 100644 --- a/test/Cpp/src/Alignment.lf +++ b/test/Cpp/src/Alignment.lf @@ -1,4 +1,5 @@ -// This test checks that the downstream reaction is not invoked more than once at a logical time. +// This test checks that the downstream reaction is not invoked more than once +// at a logical time. target Cpp { logging: LOG, timeout: 1 sec, diff --git a/test/Cpp/src/ArrayAsParameter.lf b/test/Cpp/src/ArrayAsParameter.lf index e36a63a201..85cd0630bf 100644 --- a/test/Cpp/src/ArrayAsParameter.lf +++ b/test/Cpp/src/ArrayAsParameter.lf @@ -1,4 +1,5 @@ -// Source has an variable sized list as a parameter, the elements of which it passes to Print. +// Source has an variable sized list as a parameter, the elements of which it +// passes to Print. target Cpp reactor Source(sequence: std::vector = {0, 1, 2}) { diff --git a/test/Cpp/src/ArrayAsType.lf b/test/Cpp/src/ArrayAsType.lf index d678fc1d0b..0c7ba0f16b 100644 --- a/test/Cpp/src/ArrayAsType.lf +++ b/test/Cpp/src/ArrayAsType.lf @@ -3,49 +3,49 @@ target Cpp reactor Source { - output out: int[3] - - reaction(startup) -> out {= - // create a statically allocated array - std::array result = {3, 4, 5}; - // send a copy - out.set(result); - =} + output out: int[3] + + reaction(startup) -> out {= + // create a statically allocated array + std::array result = {3, 4, 5}; + // send a copy + out.set(result); + =} } reactor Print { - input in: int[3] - - reaction(in) {= - int expected = 3; - bool failed = false; - - // get a reference to the result to avoid a copy - auto& result = *in.get(); - - std::cout << "Received: ["; - for (int i = 0; i < 3; i++) { - std::cout << result[i]; - if (i < 2) { - std::cout << ", "; - } - - // check whether values match expectation. - if (result[i] != expected) { - failed = true; - } - expected++; + input in: int[3] + + reaction(in) {= + int expected = 3; + bool failed = false; + + // get a reference to the result to avoid a copy + auto& result = *in.get(); + + std::cout << "Received: ["; + for (int i = 0; i < 3; i++) { + std::cout << result[i]; + if (i < 2) { + std::cout << ", "; } - std::cout << "]\n"; - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); + + // check whether values match expectation. + if (result[i] != expected) { + failed = true; } - =} + expected++; + } + std::cout << "]\n"; + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/Cpp/src/ArrayParallel.lf b/test/Cpp/src/ArrayParallel.lf index c8272b64a2..739614442c 100644 --- a/test/Cpp/src/ArrayParallel.lf +++ b/test/Cpp/src/ArrayParallel.lf @@ -7,13 +7,13 @@ import Scale from "ArrayScale.lf" import Source, Print from "ArrayPrint.lf" main reactor ArrayParallel { - s = new Source() - c1 = new Scale() - c2 = new Scale(scale = 3) - p1 = new Print(scale = 2) - p2 = new Print(scale = 3) - s.out -> c1.in - s.out -> c2.in - c1.out -> p1.in - c2.out -> p2.in + s = new Source() + c1 = new Scale() + c2 = new Scale(scale = 3) + p1 = new Print(scale = 2) + p2 = new Print(scale = 3) + s.out -> c1.in + s.out -> c2.in + c1.out -> p1.in + c2.out -> p2.in } diff --git a/test/Cpp/src/ArrayPrint.lf b/test/Cpp/src/ArrayPrint.lf index 59395d37d7..3bdf494107 100644 --- a/test/Cpp/src/ArrayPrint.lf +++ b/test/Cpp/src/ArrayPrint.lf @@ -1,5 +1,6 @@ -// Source produces a dynamically allocated array, which it passes to Print. The ownership semantics -// of values ensure that the array is automatically deleted if it does have no owner. +// Source produces a dynamically allocated array, which it passes to Print. The +// ownership semantics of values ensure that the array is automatically deleted +// if it does have no owner. target Cpp reactor Source { diff --git a/test/Cpp/src/ArrayScale.lf b/test/Cpp/src/ArrayScale.lf index 44db608e92..b52e7305b7 100644 --- a/test/Cpp/src/ArrayScale.lf +++ b/test/Cpp/src/ArrayScale.lf @@ -1,5 +1,6 @@ -// Source produces a dynamically allocated array, which it passes to Scale. Scale requests a -// writable copy. It modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated array, which it passes to Scale. +// Scale requests a writable copy. It modifies it and passes it to Print. It +// gets freed after Print is done with it. target Cpp import Source, Print from "ArrayPrint.lf" diff --git a/test/Cpp/src/Composition.lf b/test/Cpp/src/Composition.lf index 4c5baeb870..0a341d5e4f 100644 --- a/test/Cpp/src/Composition.lf +++ b/test/Cpp/src/Composition.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target Cpp { fast: true, timeout: 10 sec diff --git a/test/Cpp/src/CompositionAfter.lf b/test/Cpp/src/CompositionAfter.lf index ea1b27fd5e..15d68e13ea 100644 --- a/test/Cpp/src/CompositionAfter.lf +++ b/test/Cpp/src/CompositionAfter.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target Cpp { fast: true, timeout: 10 sec diff --git a/test/Cpp/src/CompositionGain.lf b/test/Cpp/src/CompositionGain.lf index a59b869786..bd4804fcc6 100644 --- a/test/Cpp/src/CompositionGain.lf +++ b/test/Cpp/src/CompositionGain.lf @@ -2,33 +2,33 @@ target Cpp reactor Gain { - input gainin: int - output y: int + input gainin: int + output y: int - reaction(gainin) -> y {= - reactor::log::Info() << "Gain received " << *gainin.get(); - y.set(*gainin.get()*2); - =} + reaction(gainin) -> y {= + reactor::log::Info() << "Gain received " << *gainin.get(); + y.set(*gainin.get()*2); + =} } reactor Wrapper { - input x: int - output y: int - gain = new Gain() - x -> gain.gainin - gain.y -> y + input x: int + output y: int + gain = new Gain() + x -> gain.gainin + gain.y -> y } main reactor CompositionGain { - wrapper = new Wrapper() + wrapper = new Wrapper() - reaction(startup) -> wrapper.x {= wrapper.x.set(42); =} + reaction(startup) -> wrapper.x {= wrapper.x.set(42); =} - reaction(wrapper.y) {= - reactor::log::Info() << "Received " << *wrapper.y.get(); - if (*wrapper.y.get() != 42*2) { - reactor::log::Error() << "Received value should have been " << 42 * 2; - exit(2); - } - =} + reaction(wrapper.y) {= + reactor::log::Info() << "Received " << *wrapper.y.get(); + if (*wrapper.y.get() != 42*2) { + reactor::log::Error() << "Received value should have been " << 42 * 2; + exit(2); + } + =} } diff --git a/test/Cpp/src/DanglingOutput.lf b/test/Cpp/src/DanglingOutput.lf index 499fa0e504..537eff1cde 100644 --- a/test/Cpp/src/DanglingOutput.lf +++ b/test/Cpp/src/DanglingOutput.lf @@ -3,24 +3,24 @@ target Cpp reactor Source { - output out: int - timer t + output out: int + timer t - reaction(t) -> out {= out.set(1); =} + reaction(t) -> out {= out.set(1); =} } reactor Gain { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - std::cout << "Received " << *in.get() << std::endl; - out.set(*in.get() * 2); - =} + reaction(in) -> out {= + std::cout << "Received " << *in.get() << std::endl; + out.set(*in.get() * 2); + =} } main reactor DanglingOutput { - source = new Source() - container = new Gain() - source.out -> container.in + source = new Source() + container = new Gain() + source.out -> container.in } diff --git a/test/Cpp/src/Deadline.lf b/test/Cpp/src/Deadline.lf index 5a6448195d..19a41ff057 100644 --- a/test/Cpp/src/Deadline.lf +++ b/test/Cpp/src/Deadline.lf @@ -1,5 +1,6 @@ -// This example illustrates local deadline handling. Even numbers are sent by the Source -// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by +// the Source immediately, whereas odd numbers are sent after a big enough delay +// to violate the deadline. target Cpp { timeout: 4 sec } diff --git a/test/Cpp/src/DeadlineHandledAbove.lf b/test/Cpp/src/DeadlineHandledAbove.lf index e39ae3db09..b2a6c7658a 100644 --- a/test/Cpp/src/DeadlineHandledAbove.lf +++ b/test/Cpp/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the container reacts to that -// output. +// Test a deadline where the deadline violation produces an output and the +// container reacts to that output. target Cpp reactor Deadline(threshold: time = 100 msec) { diff --git a/test/Cpp/src/DelayedReaction.lf b/test/Cpp/src/DelayedReaction.lf index d7fdabb2f8..c5e937a8e7 100644 --- a/test/Cpp/src/DelayedReaction.lf +++ b/test/Cpp/src/DelayedReaction.lf @@ -2,26 +2,26 @@ target Cpp reactor Source { - output out: void + output out: void - reaction(startup) -> out {= out.set(); =} + reaction(startup) -> out {= out.set(); =} } reactor Sink { - input in: void + input in: void - reaction(in) {= - auto elapsed = get_elapsed_logical_time(); - std::cout << "Nanoseconds since start: " << elapsed << '\n'; - if (elapsed != 100ms) { - std::cerr << "ERROR: Expected 100000000 nsecs.\n"; - exit(1); - } - =} + reaction(in) {= + auto elapsed = get_elapsed_logical_time(); + std::cout << "Nanoseconds since start: " << elapsed << '\n'; + if (elapsed != 100ms) { + std::cerr << "ERROR: Expected 100000000 nsecs.\n"; + exit(1); + } + =} } main reactor DelayedReaction { - source = new Source() - sink = new Sink() - source.out -> sink.in after 100 msec + source = new Source() + sink = new Sink() + source.out -> sink.in after 100 msec } diff --git a/test/Cpp/src/Determinism.lf b/test/Cpp/src/Determinism.lf index 916c54c8c0..063a25519d 100644 --- a/test/Cpp/src/Determinism.lf +++ b/test/Cpp/src/Determinism.lf @@ -1,46 +1,46 @@ target Cpp reactor Source { - output y: int - timer t + output y: int + timer t - reaction(t) -> y {= y.set(1); =} + reaction(t) -> y {= y.set(1); =} } reactor Destination { - input x: int - input y: int + input x: int + input y: int - reaction(x, y) {= - int sum = 0; - if (x.is_present()) { - sum += *x.get(); - } - if (y.is_present()) { - sum += *y.get(); - } - std::cout << "Received " << sum << std::endl; - if (sum != 2) { - std::cerr << "FAILURE: Expected 2." << std::endl; - exit(4); - } - =} + reaction(x, y) {= + int sum = 0; + if (x.is_present()) { + sum += *x.get(); + } + if (y.is_present()) { + sum += *y.get(); + } + std::cout << "Received " << sum << std::endl; + if (sum != 2) { + std::cerr << "FAILURE: Expected 2." << std::endl; + exit(4); + } + =} } reactor Pass { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(x.get()); =} + reaction(x) -> y {= y.set(x.get()); =} } main reactor Determinism { - s = new Source() - d = new Destination() - p1 = new Pass() - p2 = new Pass() - s.y -> d.y - s.y -> p1.x - p1.y -> p2.x - p2.y -> d.x + s = new Source() + d = new Destination() + p1 = new Pass() + p2 = new Pass() + s.y -> d.y + s.y -> p1.x + p1.y -> p2.x + p2.y -> d.x } diff --git a/test/Cpp/src/DoubleInvocation.lf b/test/Cpp/src/DoubleInvocation.lf index 236b0f425d..956b54bb17 100644 --- a/test/Cpp/src/DoubleInvocation.lf +++ b/test/Cpp/src/DoubleInvocation.lf @@ -1,9 +1,11 @@ -// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it -// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at -// the same logical time. They should only be fired once. This behavior was oddly eliminated by -// either of the following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. +// This test ensures it does not reappear. At logical time zero, the two Print +// reactors used to be fired twice each at the same logical time. They should +// only be fired once. This behavior was oddly eliminated by either of the +// following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. -// * Sending only position, not velocity from Ball. (copied from the c version of the test) +// * Sending only position, not velocity from Ball. (copied from the c version +// of the test) target Cpp { timeout: 5 sec, fast: true diff --git a/test/Cpp/src/DoublePort.lf b/test/Cpp/src/DoublePort.lf index b28f70db4d..faaa474db5 100644 --- a/test/Cpp/src/DoublePort.lf +++ b/test/Cpp/src/DoublePort.lf @@ -1,6 +1,7 @@ /** - * Test the case where two upstream reactors pass messages to a downstream reactor on two different - * ports. One message carries a microstep delay relative to the other. + * Test the case where two upstream reactors pass messages to a downstream + * reactor on two different ports. One message carries a microstep delay + * relative to the other. * * @author Maiko Brants */ diff --git a/test/Cpp/src/DoubleReaction.lf b/test/Cpp/src/DoubleReaction.lf index 3642fa027a..1128d63f97 100644 --- a/test/Cpp/src/DoubleReaction.lf +++ b/test/Cpp/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output -// for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only +// once. Correct output for this 2, 4, 6, 8, etc. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index b39f0a559e..5db4818048 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -1,4 +1,5 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice +// at the same tag. target Cpp main reactor DoubleTrigger { diff --git a/test/Cpp/src/GetTime.lf b/test/Cpp/src/GetTime.lf index e9ba6922d5..a61b299d45 100644 --- a/test/Cpp/src/GetTime.lf +++ b/test/Cpp/src/GetTime.lf @@ -1,25 +1,25 @@ // This file includes code documented on the Wiki. For this test, success is just compiling and // running. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } main reactor GetTime { - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) {= - auto logical = get_logical_time(); - std::cout << "Logical time is " << logical << std::endl; + reaction(t) {= + auto logical = get_logical_time(); + std::cout << "Logical time is " << logical << std::endl; - auto elapsed = get_elapsed_logical_time(); - auto elapsed_secs = std::chrono::duration_cast(elapsed); - std::cout << "Elapsed logical time is " << elapsed_secs << std::endl; + auto elapsed = get_elapsed_logical_time(); + auto elapsed_secs = std::chrono::duration_cast(elapsed); + std::cout << "Elapsed logical time is " << elapsed_secs << std::endl; - auto physical = get_physical_time(); - std::cout << "Physical time is " << physical << std::endl; + auto physical = get_physical_time(); + std::cout << "Physical time is " << physical << std::endl; - auto diff = physical - logical; - std::cout << "Time lag is " << diff << std::endl; - =} + auto diff = physical - logical; + std::cout << "Time lag is " << diff << std::endl; + =} } diff --git a/test/Cpp/src/HelloWorld.lf b/test/Cpp/src/HelloWorld.lf index 8d32d55553..071cc5c968 100644 --- a/test/Cpp/src/HelloWorld.lf +++ b/test/Cpp/src/HelloWorld.lf @@ -1,11 +1,11 @@ target Cpp reactor HelloWorld2 { - timer t + timer t - reaction(t) {= std::cout << "Hello World." << std::endl; =} + reaction(t) {= std::cout << "Hello World." << std::endl; =} } main reactor { - a = new HelloWorld2() + a = new HelloWorld2() } diff --git a/test/Cpp/src/Hierarchy.lf b/test/Cpp/src/Hierarchy.lf index 7767b98311..d207a20c31 100644 --- a/test/Cpp/src/Hierarchy.lf +++ b/test/Cpp/src/Hierarchy.lf @@ -2,48 +2,48 @@ target Cpp reactor Source { - output out: int - timer t + output out: int + timer t - reaction(t) -> out {= out.set(1); =} + reaction(t) -> out {= out.set(1); =} } reactor Gain { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= out.set((*in.get()) * 2); =} + reaction(in) -> out {= out.set((*in.get()) * 2); =} } reactor Print { - input in: int - - reaction(in) {= - auto value = *in.get(); - std::cout << "Received: " << value << std::endl; - if (value != 2) { - std::cerr << "Expected 2." << std::endl; - exit(1); - } - =} + input in: int + + reaction(in) {= + auto value = *in.get(); + std::cout << "Received: " << value << std::endl; + if (value != 2) { + std::cerr << "Expected 2." << std::endl; + exit(1); + } + =} } reactor GainContainer { - input in: int - output out: int - output out2: int - gain = new Gain() - in -> gain.in - gain.out -> out - gain.out -> out2 + input in: int + output out: int + output out2: int + gain = new Gain() + in -> gain.in + gain.out -> out + gain.out -> out2 } main reactor Hierarchy { - source = new Source() - container = new GainContainer() - print = new Print() - print2 = new Print() - source.out -> container.in - container.out -> print.in - container.out -> print2.in + source = new Source() + container = new GainContainer() + print = new Print() + print2 = new Print() + source.out -> container.in + container.out -> print.in + container.out -> print2.in } diff --git a/test/Cpp/src/Import.lf b/test/Cpp/src/Import.lf index 020877a883..c77f8382c5 100644 --- a/test/Cpp/src/Import.lf +++ b/test/Cpp/src/Import.lf @@ -4,8 +4,8 @@ target Cpp import Imported from "lib/Imported.lf" main reactor Import { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= a.x.set(42); =} + reaction(t) -> a.x {= a.x.set(42); =} } diff --git a/test/Cpp/src/ImportComposition.lf b/test/Cpp/src/ImportComposition.lf index 492b77d96d..0559edacd1 100644 --- a/test/Cpp/src/ImportComposition.lf +++ b/test/Cpp/src/ImportComposition.lf @@ -1,7 +1,8 @@ /** * @author Maiko Brants TU Dresden * - * This tests the ability to import a reactor definition that itself imports a reactor definition. + * This tests the ability to import a reactor definition that itself imports a + * reactor definition. * * modeled after the C version of this test */ diff --git a/test/Cpp/src/ImportRenamed.lf b/test/Cpp/src/ImportRenamed.lf index ea21c06964..4ec5dc132e 100644 --- a/test/Cpp/src/ImportRenamed.lf +++ b/test/Cpp/src/ImportRenamed.lf @@ -12,10 +12,10 @@ import Imported as Y from "lib/Imported.lf" import ImportedAgain as Z from "lib/ImportedAgain.lf" main reactor { - timer t - a = new X() - b = new Y() - c = new Z() + timer t + a = new X() + b = new Y() + c = new Z() - reaction(t) -> a.x {= a.x.set(42); =} + reaction(t) -> a.x {= a.x.set(42); =} } diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index e17d4eac13..3c55bdcaf1 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -1,6 +1,7 @@ target Cpp -reactor GeneratedDelay { // That's the stuff that shall be generated for the after +// That's the stuff that shall be generated for the after +reactor GeneratedDelay { input y_in: int output y_out: int state y_state: int = 0 @@ -16,7 +17,8 @@ reactor Source { output out: int timer t - reaction(t) -> out {= out.set(1); =} // reaction(t) -> out after 100 msec {= + // reaction(t) -> out after 100 msec {= + reaction(t) -> out {= out.set(1); =} } reactor Sink { diff --git a/test/Cpp/src/Microsteps.lf b/test/Cpp/src/Microsteps.lf index f4fb8c10e4..fedf9c145f 100644 --- a/test/Cpp/src/Microsteps.lf +++ b/test/Cpp/src/Microsteps.lf @@ -1,43 +1,43 @@ target Cpp reactor Destination { - input x: int - input y: int + input x: int + input y: int - reaction(x, y) {= - auto elapsed = get_elapsed_logical_time(); - std::cout << "Time since start: " << elapsed << std::endl; - if (elapsed != reactor::Duration::zero()) { - std::cerr << "Expected elapsed time to be 0, but it was " << - elapsed << std::endl; - exit(1); - } - int count{0}; - if (x.is_present()) { - std::cout << " x is present." << std::endl; - count++; - } - if (y.is_present()) { - std::cout << " y is present." << std::endl; - count++; - } - if (count != 1) { - std::cerr << "Expected exactly one input to be present but got " - << count << std::endl; - exit(1); - } - =} + reaction(x, y) {= + auto elapsed = get_elapsed_logical_time(); + std::cout << "Time since start: " << elapsed << std::endl; + if (elapsed != reactor::Duration::zero()) { + std::cerr << "Expected elapsed time to be 0, but it was " << + elapsed << std::endl; + exit(1); + } + int count{0}; + if (x.is_present()) { + std::cout << " x is present." << std::endl; + count++; + } + if (y.is_present()) { + std::cout << " y is present." << std::endl; + count++; + } + if (count != 1) { + std::cerr << "Expected exactly one input to be present but got " + << count << std::endl; + exit(1); + } + =} } main reactor Microsteps { - timer start - logical action repeat: void - d = new Destination() + timer start + logical action repeat: void + d = new Destination() - reaction(start) -> d.x, repeat {= - d.x.set(1); - repeat.schedule(); - =} + reaction(start) -> d.x, repeat {= + d.x.set(1); + repeat.schedule(); + =} - reaction(repeat) -> d.y {= d.y.set(1); =} + reaction(repeat) -> d.y {= d.y.set(1); =} } diff --git a/test/Cpp/src/Minimal.lf b/test/Cpp/src/Minimal.lf index 77238dbd30..d49bea2620 100644 --- a/test/Cpp/src/Minimal.lf +++ b/test/Cpp/src/Minimal.lf @@ -2,5 +2,5 @@ target Cpp main reactor Minimal { - reaction(startup) {= std::cout << "Hello World!\n"; =} + reaction(startup) {= std::cout << "Hello World!\n"; =} } diff --git a/test/Cpp/src/MovingAverage.lf b/test/Cpp/src/MovingAverage.lf index 2ccaa87406..af202ca0a0 100644 --- a/test/Cpp/src/MovingAverage.lf +++ b/test/Cpp/src/MovingAverage.lf @@ -1,6 +1,6 @@ -// Demonstration of a state variable that is a fixed size list. The MovingAverage reactor computes -// the moving average of the last four inputs and produces that as output. The source is a counting -// sequence. +// Demonstration of a state variable that is a fixed size list. The +// MovingAverage reactor computes the moving average of the last four inputs and +// produces that as output. The source is a counting sequence. target Cpp { timeout: 1 sec, fast: true diff --git a/test/Cpp/src/MultipleContained.lf b/test/Cpp/src/MultipleContained.lf index 8831bb3d6d..bfe71c9b02 100644 --- a/test/Cpp/src/MultipleContained.lf +++ b/test/Cpp/src/MultipleContained.lf @@ -2,34 +2,34 @@ target Cpp reactor Contained { - output trigger: int - input in1: int - input in2: int + output trigger: int + input in1: int + input in2: int - reaction(startup) -> trigger {= trigger.set(42); =} + reaction(startup) -> trigger {= trigger.set(42); =} - reaction(in1) {= - std::cout << "in1 received " << *in1.get() << '\n'; - if (*in1.get() != 42) { - std::cerr << "FAILED: Expected 42.\n"; - exit(1); - } - =} + reaction(in1) {= + std::cout << "in1 received " << *in1.get() << '\n'; + if (*in1.get() != 42) { + std::cerr << "FAILED: Expected 42.\n"; + exit(1); + } + =} - reaction(in2) {= - std::cout << "in2 received " << *in2.get() << '\n'; - if (*in2.get() != 42) { - std::cerr << "FAILED: Expected 42.\n"; - exit(1); - } - =} + reaction(in2) {= + std::cout << "in2 received " << *in2.get() << '\n'; + if (*in2.get() != 42) { + std::cerr << "FAILED: Expected 42.\n"; + exit(1); + } + =} } main reactor MultipleContained { - c = new Contained() + c = new Contained() - reaction(c.trigger) -> c.in1, c.in2 {= - c.in1.set(c.trigger.get()); - c.in2.set(c.trigger.get()); - =} + reaction(c.trigger) -> c.in1, c.in2 {= + c.in1.set(c.trigger.get()); + c.in2.set(c.trigger.get()); + =} } diff --git a/test/Cpp/src/PreambleTest.lf b/test/Cpp/src/PreambleTest.lf index 66b479397d..60a0128b29 100644 --- a/test/Cpp/src/PreambleTest.lf +++ b/test/Cpp/src/PreambleTest.lf @@ -1,29 +1,29 @@ target Cpp main reactor { - // This declaration is required on the public reactor interface and therefore needs to be placed - // in the generated header. This goes to Preamble/Preamble.hh. - public preamble {= - struct MyStruct { - int foo; - std::string bar; - }; - =} - // this is only used inside reactions and therefore goes to the generated source file This - // function is only used inside a reaction and therefore is part of the private interface. - // Moreover, we need to make sure that the function is only defined once within a source file. - // This goes to Preamble/Preamble.cc - private preamble {= - int add_42(int i) { - return i + 42; - } - =} - logical action a: MyStruct + // This declaration is required on the public reactor interface and therefore needs to be placed + // in the generated header. This goes to Preamble/Preamble.hh. + public preamble {= + struct MyStruct { + int foo; + std::string bar; + }; + =} + // this is only used inside reactions and therefore goes to the generated source file This + // function is only used inside a reaction and therefore is part of the private interface. + // Moreover, we need to make sure that the function is only defined once within a source file. + // This goes to Preamble/Preamble.cc + private preamble {= + int add_42(int i) { + return i + 42; + } + =} + logical action a: MyStruct - reaction(startup) -> a {= a.schedule({add_42(42), "baz"}); =} + reaction(startup) -> a {= a.schedule({add_42(42), "baz"}); =} - reaction(a) {= - auto& value = *a.get(); - std::cout << "Received " << value.foo << " and '" << value.bar << "'\n"; - =} + reaction(a) {= + auto& value = *a.get(); + std::cout << "Received " << value.foo << " and '" << value.bar << "'\n"; + =} } diff --git a/test/Cpp/src/ReadOutputOfContainedReactor.lf b/test/Cpp/src/ReadOutputOfContainedReactor.lf index 7d16b24cb7..c7e85083b4 100644 --- a/test/Cpp/src/ReadOutputOfContainedReactor.lf +++ b/test/Cpp/src/ReadOutputOfContainedReactor.lf @@ -1,4 +1,5 @@ -// Test reacting to and reading outputs from a contained reactor in various permutations. +// Test reacting to and reading outputs from a contained reactor in various +// permutations. target Cpp reactor Contained { diff --git a/test/Cpp/src/Schedule.lf b/test/Cpp/src/Schedule.lf index 754368c072..67de9fb876 100644 --- a/test/Cpp/src/Schedule.lf +++ b/test/Cpp/src/Schedule.lf @@ -2,26 +2,26 @@ target Cpp reactor ScheduleTest { - input x: int - logical action a: void + input x: int + logical action a: void - reaction(x) -> a {= a.schedule(200ms); =} + reaction(x) -> a {= a.schedule(200ms); =} - reaction(a) {= - auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Action triggered at logical time " << elapsed_time.count() - << " after start" << std::endl; - if (elapsed_time != 200ms) { - std::cerr << "Expected action time to be 200 msec. It was " - << elapsed_time.count() << "nsec!" << std::endl; - exit(1); - } - =} + reaction(a) {= + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Action triggered at logical time " << elapsed_time.count() + << " after start" << std::endl; + if (elapsed_time != 200ms) { + std::cerr << "Expected action time to be 200 msec. It was " + << elapsed_time.count() << "nsec!" << std::endl; + exit(1); + } + =} } main reactor Schedule { - a = new ScheduleTest() - timer t + a = new ScheduleTest() + timer t - reaction(t) -> a.x {= a.x.set(1); =} + reaction(t) -> a.x {= a.x.set(1); =} } diff --git a/test/Cpp/src/ScheduleLogicalAction.lf b/test/Cpp/src/ScheduleLogicalAction.lf index 2e2f9f99f5..96fd5382b7 100644 --- a/test/Cpp/src/ScheduleLogicalAction.lf +++ b/test/Cpp/src/ScheduleLogicalAction.lf @@ -1,8 +1,8 @@ /** * @author Maiko Brants TU Dresden * - * This checks that a logical action is scheduled the specified logical time after the current - * logical time. + * This checks that a logical action is scheduled the specified logical time + * after the current logical time. * * Modeled after the C version of this test. */ diff --git a/test/Cpp/src/SendingInside.lf b/test/Cpp/src/SendingInside.lf index 4b04d48bc7..2f73122bc8 100644 --- a/test/Cpp/src/SendingInside.lf +++ b/test/Cpp/src/SendingInside.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own reaction that routes -// inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own +// reaction that routes inputs to the contained reactor. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/SendingInside2.lf b/test/Cpp/src/SendingInside2.lf index 1656c77f9d..29b6da59aa 100644 --- a/test/Cpp/src/SendingInside2.lf +++ b/test/Cpp/src/SendingInside2.lf @@ -1,20 +1,20 @@ target Cpp reactor Printer { - input x: int + input x: int - reaction(x) {= - std::cout << "Inside reactor received: " << *x.get() << std::endl; - if (*x.get() != 1) { - std::cerr << "ERROR: Expected 1." << std::endl; - exit(1); - } - =} + reaction(x) {= + std::cout << "Inside reactor received: " << *x.get() << std::endl; + if (*x.get() != 1) { + std::cerr << "ERROR: Expected 1." << std::endl; + exit(1); + } + =} } main reactor SendingInside2 { - timer t - p = new Printer() + timer t + p = new Printer() - reaction(t) -> p.x {= p.x.set(1); =} + reaction(t) -> p.x {= p.x.set(1); =} } diff --git a/test/Cpp/src/SimpleDeadline.lf b/test/Cpp/src/SimpleDeadline.lf index c14ba2adea..be10b55d43 100644 --- a/test/Cpp/src/SimpleDeadline.lf +++ b/test/Cpp/src/SimpleDeadline.lf @@ -1,5 +1,6 @@ -// Test local deadline, where a deadline is associated with a reaction definition. This test -// triggers a reaction exactly once with a deadline violation. +// Test local deadline, where a deadline is associated with a reaction +// definition. This test triggers a reaction exactly once with a deadline +// violation. target Cpp reactor Deadline(threshold: time = 100 msec) { diff --git a/test/Cpp/src/SimpleImport.lf b/test/Cpp/src/SimpleImport.lf index 0054bf1040..eadef75f9c 100644 --- a/test/Cpp/src/SimpleImport.lf +++ b/test/Cpp/src/SimpleImport.lf @@ -3,6 +3,6 @@ target Cpp import HelloWorld2 from "HelloWorld.lf" main reactor SimpleImport { - a = new HelloWorld2() - b = new HelloWorld2() + a = new HelloWorld2() + b = new HelloWorld2() } diff --git a/test/Cpp/src/SlowingClock.lf b/test/Cpp/src/SlowingClock.lf index 13228f17a1..adbe93e418 100644 --- a/test/Cpp/src/SlowingClock.lf +++ b/test/Cpp/src/SlowingClock.lf @@ -1,9 +1,10 @@ /** * @author Maiko Brants TU Dresden * - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a logical - * action with a minimum delay of 100 msec. The use of the logical action ensures the elapsed time - * jumps exactly from 0 to 100, 300, 600, and 1000 msec. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 + * msec on a logical action with a minimum delay of 100 msec. The use of the + * logical action ensures the elapsed time jumps exactly from 0 to 100, 300, + * 600, and 1000 msec. * * Modeled after the C version of this test. */ diff --git a/test/Cpp/src/SlowingClockPhysical.lf b/test/Cpp/src/SlowingClockPhysical.lf index 7486a00a91..919f9d6cdf 100644 --- a/test/Cpp/src/SlowingClockPhysical.lf +++ b/test/Cpp/src/SlowingClockPhysical.lf @@ -1,10 +1,11 @@ /** * @author Maiko Brants TU Dresden * - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a physical - * action with a minimum delay of 100 msec. The use of the physical action makes the elapsed time - * jumps from 0 to approximately 100 msec, to approximatly 300 msec thereafter, drifting away - * further with each new event. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 + * msec on a physical action with a minimum delay of 100 msec. The use of the + * physical action makes the elapsed time jumps from 0 to approximately 100 + * msec, to approximatly 300 msec thereafter, drifting away further with each + * new event. * * Modeled after the C version of this test. */ diff --git a/test/Cpp/src/StartupOutFromInside.lf b/test/Cpp/src/StartupOutFromInside.lf index 1832d01d92..b8b43b78b9 100644 --- a/test/Cpp/src/StartupOutFromInside.lf +++ b/test/Cpp/src/StartupOutFromInside.lf @@ -6,19 +6,19 @@ target Cpp reactor Bar { - output out: int + output out: int - reaction(startup) -> out {= out.set(42); =} + reaction(startup) -> out {= out.set(42); =} } main reactor StartupOutFromInside { - bar = new Bar() + bar = new Bar() - reaction(startup) bar.out {= - reactor::log::Info() << "Output from bar: " << *bar.out.get(); - if(*bar.out.get() != 42) { - reactor::log::Error() << "Expected 42!"; - exit(1); - } - =} + reaction(startup) bar.out {= + reactor::log::Info() << "Output from bar: " << *bar.out.get(); + if(*bar.out.get() != 42) { + reactor::log::Error() << "Expected 42!"; + exit(1); + } + =} } diff --git a/test/Cpp/src/Stride.lf b/test/Cpp/src/Stride.lf index 7aabd9b399..5f469e4c70 100644 --- a/test/Cpp/src/Stride.lf +++ b/test/Cpp/src/Stride.lf @@ -1,5 +1,5 @@ -// This example illustrates state variables and parameters on the wiki. For this test, success is -// just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this +// test, success is just compiling and running. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/StructAsState.lf b/test/Cpp/src/StructAsState.lf index fd48d50d25..f8171a2ec6 100644 --- a/test/Cpp/src/StructAsState.lf +++ b/test/Cpp/src/StructAsState.lf @@ -2,17 +2,17 @@ target Cpp public preamble {= - #include "include/hello.h" + #include "include/hello.h" =} main reactor StructAsState { - state s: Hello{"Earth", 42} + state s: Hello{"Earth", 42} - reaction(startup) {= - std::cout << "State s.name=" << s.name << ", s.value=" << s.value << '\n'; - if (s.value != 42 && s.name != "Earth") { - std::cerr << "ERROR: Expected 42 and Earth!\n"; - exit(1); - } - =} + reaction(startup) {= + std::cout << "State s.name=" << s.name << ", s.value=" << s.value << '\n'; + if (s.value != 42 && s.name != "Earth") { + std::cerr << "ERROR: Expected 42 and Earth!\n"; + exit(1); + } + =} } diff --git a/test/Cpp/src/StructAsType.lf b/test/Cpp/src/StructAsType.lf index 9d853b98b2..fee53b7062 100644 --- a/test/Cpp/src/StructAsType.lf +++ b/test/Cpp/src/StructAsType.lf @@ -4,21 +4,21 @@ target Cpp import Print from "StructPrint.lf" public preamble {= - #include "include/hello.h" + #include "include/hello.h" =} reactor StaticSource { - output out: Hello + output out: Hello - reaction(startup) -> out {= - Hello hello{"Earth", 42}; - // this implicitly sends a dynamically allocated copy of the hello object - out.set(hello); - =} + reaction(startup) -> out {= + Hello hello{"Earth", 42}; + // this implicitly sends a dynamically allocated copy of the hello object + out.set(hello); + =} } main reactor StructAsType { - s = new StaticSource() - p = new Print() - s.out -> p.in + s = new StaticSource() + p = new Print() + s.out -> p.in } diff --git a/test/Cpp/src/StructAsTypeDirect.lf b/test/Cpp/src/StructAsTypeDirect.lf index e31b1190b4..00aae7c565 100644 --- a/test/Cpp/src/StructAsTypeDirect.lf +++ b/test/Cpp/src/StructAsTypeDirect.lf @@ -4,20 +4,20 @@ target Cpp import Print from "StructPrint.lf" public preamble {= - #include "include/hello.h" + #include "include/hello.h" =} reactor DirectSource { - output out: Hello + output out: Hello - reaction(startup) -> out {= - // this implicitly creates a new hello object which is then send - out.set({"Earth", 42}); - =} + reaction(startup) -> out {= + // this implicitly creates a new hello object which is then send + out.set({"Earth", 42}); + =} } main reactor { - s = new DirectSource() - p = new Print() - s.out -> p.in + s = new DirectSource() + p = new Print() + s.out -> p.in } diff --git a/test/Cpp/src/StructParallel.lf b/test/Cpp/src/StructParallel.lf index ab50ab0e93..375fa41bb2 100644 --- a/test/Cpp/src/StructParallel.lf +++ b/test/Cpp/src/StructParallel.lf @@ -7,17 +7,17 @@ import Scale from "StructScale.lf" import Source, Print from "StructPrint.lf" public preamble {= - #include "include/hello.h" + #include "include/hello.h" =} main reactor { - s = new Source() - c1 = new Scale() - c2 = new Scale(scale = 3) - p1 = new Print(expected_value = 84) - p2 = new Print(expected_value = 126) - s.out -> c1.in - s.out -> c2.in - c1.out -> p1.in - c2.out -> p2.in + s = new Source() + c1 = new Scale() + c2 = new Scale(scale = 3) + p1 = new Print(expected_value = 84) + p2 = new Print(expected_value = 126) + s.out -> c1.in + s.out -> c2.in + c1.out -> p1.in + c2.out -> p2.in } diff --git a/test/Cpp/src/StructScale.lf b/test/Cpp/src/StructScale.lf index ed472eced6..776dad14b1 100644 --- a/test/Cpp/src/StructScale.lf +++ b/test/Cpp/src/StructScale.lf @@ -1,5 +1,6 @@ -// Source produces a dynamically allocated struct, which it passes to Scale. Scale requests a -// writable copy. It modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated struct, which it passes to Scale. +// Scale requests a writable copy. It modifies it and passes it to Print. It +// gets freed after Print is done with it. target Cpp import Source, Print from "StructPrint.lf" diff --git a/test/Cpp/src/TestForPreviousOutput.lf b/test/Cpp/src/TestForPreviousOutput.lf index 3a5b9bd697..e181c4d791 100644 --- a/test/Cpp/src/TestForPreviousOutput.lf +++ b/test/Cpp/src/TestForPreviousOutput.lf @@ -3,41 +3,41 @@ target Cpp reactor Source { - output out: int + output out: int - reaction(startup) -> out {= - // Set a seed for random number generation based on the current time. - std::srand(std::time(nullptr)); - // Randomly produce an output or not. - if (std::rand() % 2) { - out.set(21); - } - =} + reaction(startup) -> out {= + // Set a seed for random number generation based on the current time. + std::srand(std::time(nullptr)); + // Randomly produce an output or not. + if (std::rand() % 2) { + out.set(21); + } + =} - reaction(startup) -> out {= - if (out.is_present()) { - int previous_output = *out.get(); - out.set(2 * previous_output); - } else { - out.set(42); - } - =} + reaction(startup) -> out {= + if (out.is_present()) { + int previous_output = *out.get(); + out.set(2 * previous_output); + } else { + out.set(42); + } + =} } reactor Sink { - input in: int + input in: int - reaction(in) {= - std::cout << "Received: " << *in.get() << '\n'; - if (*in.get() != 42) { - std::cerr << "FAILED: Expected 42.\n"; - exit(1); - } - =} + reaction(in) {= + std::cout << "Received: " << *in.get() << '\n'; + if (*in.get() != 42) { + std::cerr << "FAILED: Expected 42.\n"; + exit(1); + } + =} } main reactor TestForPreviousOutput { - s = new Source() - d = new Sink() - s.out -> d.in + s = new Source() + d = new Sink() + s.out -> d.in } diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index 8383d4bf26..8b33dcd967 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -1,5 +1,6 @@ -// Test that the stop function can be used to internally to impose a a time limit. Correct output -// for this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. +// Test that the stop function can be used to internally to impose a a time +// limit. Correct output for this 1, 2, 3, 4. Failure for this test is failing +// to halt or getting the wrong data. target Cpp { fast: true } diff --git a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf index 1a360411ae..b8c304b164 100644 --- a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,5 +1,6 @@ /** - * This test checks that a downstream reaction is triggered only if its trigger is present. + * This test checks that a downstream reaction is triggered only if its trigger + * is present. * * @author Maiko Brants TU Dresden * diff --git a/test/Cpp/src/concurrent/CompositionThreaded.lf b/test/Cpp/src/concurrent/CompositionThreaded.lf index 07738e3e45..42817e8b1d 100644 --- a/test/Cpp/src/concurrent/CompositionThreaded.lf +++ b/test/Cpp/src/concurrent/CompositionThreaded.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target Cpp { fast: true, timeout: 10 sec diff --git a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf index fe39ebcb98..bb380fe14c 100644 --- a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the container reacts to that -// output. +// Test a deadline where the deadline violation produces an output and the +// container reacts to that output. target Cpp reactor Deadline(threshold: time = 100 msec) { diff --git a/test/Cpp/src/concurrent/DeadlineThreaded.lf b/test/Cpp/src/concurrent/DeadlineThreaded.lf index 131167fa77..cb794f5050 100644 --- a/test/Cpp/src/concurrent/DeadlineThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineThreaded.lf @@ -1,5 +1,6 @@ -// This example illustrates local deadline handling. Even numbers are sent by the Source -// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by +// the Source immediately, whereas odd numbers are sent after a big enough delay +// to violate the deadline. target Cpp { timeout: 4 sec } diff --git a/test/Cpp/src/concurrent/DeterminismThreaded.lf b/test/Cpp/src/concurrent/DeterminismThreaded.lf index 48a224db11..b97d9fd1fe 100644 --- a/test/Cpp/src/concurrent/DeterminismThreaded.lf +++ b/test/Cpp/src/concurrent/DeterminismThreaded.lf @@ -1,46 +1,46 @@ target Cpp reactor Source { - output y: int - timer t + output y: int + timer t - reaction(t) -> y {= y.set(1); =} + reaction(t) -> y {= y.set(1); =} } reactor Destination { - input x: int - input y: int + input x: int + input y: int - reaction(x, y) {= - int sum = 0; - if (x.is_present()) { - sum += *x.get(); - } - if (y.is_present()) { - sum += *y.get(); - } - std::cout << "Received " << sum << std::endl; - if (sum != 2) { - std::cerr << "FAILURE: Expected 2." << std::endl; - exit(4); - } - =} + reaction(x, y) {= + int sum = 0; + if (x.is_present()) { + sum += *x.get(); + } + if (y.is_present()) { + sum += *y.get(); + } + std::cout << "Received " << sum << std::endl; + if (sum != 2) { + std::cerr << "FAILURE: Expected 2." << std::endl; + exit(4); + } + =} } reactor Pass { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(x.get()); =} + reaction(x) -> y {= y.set(x.get()); =} } main reactor { - s = new Source() - d = new Destination() - p1 = new Pass() - p2 = new Pass() - s.y -> d.y - s.y -> p1.x - p1.y -> p2.x - p2.y -> d.x + s = new Source() + d = new Destination() + p1 = new Pass() + p2 = new Pass() + s.y -> d.y + s.y -> p1.x + p1.y -> p2.x + p2.y -> d.x } diff --git a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf index c8b1fa06a3..d68f2e8b60 100644 --- a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf +++ b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output -// for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only +// once. Correct output for this 2, 4, 6, 8, etc. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/concurrent/ImportThreaded.lf b/test/Cpp/src/concurrent/ImportThreaded.lf index d032b196fe..791291fc10 100644 --- a/test/Cpp/src/concurrent/ImportThreaded.lf +++ b/test/Cpp/src/concurrent/ImportThreaded.lf @@ -4,8 +4,8 @@ target Cpp import Imported from "../lib/Imported.lf" main reactor { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= a.x.set(42); =} + reaction(t) -> a.x {= a.x.set(42); =} } diff --git a/test/Cpp/src/concurrent/MinimalThreaded.lf b/test/Cpp/src/concurrent/MinimalThreaded.lf index f13148781d..a0184d5261 100644 --- a/test/Cpp/src/concurrent/MinimalThreaded.lf +++ b/test/Cpp/src/concurrent/MinimalThreaded.lf @@ -2,5 +2,5 @@ target Cpp main reactor { - reaction(startup) {= std::cout << "Hello World!\n"; =} + reaction(startup) {= std::cout << "Hello World!\n"; =} } diff --git a/test/Cpp/src/concurrent/SendingInsideThreaded.lf b/test/Cpp/src/concurrent/SendingInsideThreaded.lf index acd34f147f..51ca511e26 100644 --- a/test/Cpp/src/concurrent/SendingInsideThreaded.lf +++ b/test/Cpp/src/concurrent/SendingInsideThreaded.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own reaction that routes -// inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own +// reaction that routes inputs to the contained reactor. target Cpp { timeout: 10 sec, fast: true diff --git a/test/Cpp/src/concurrent/Threaded.lf b/test/Cpp/src/concurrent/Threaded.lf index f0a72fc2ed..9ad4fcbe56 100644 --- a/test/Cpp/src/concurrent/Threaded.lf +++ b/test/Cpp/src/concurrent/Threaded.lf @@ -1,9 +1,11 @@ -// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime -// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that -// without parallel execution, there is no way this can keep up with real time since in every 200 -// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing -// that without threads, this takes more than 800 msec to complete 200 msec of logical time. +// Check for speedup of multithreaded execution on multicore machines. Each +// instance of TakeTime takes 200 ms to transport the input to the output. Four +// of them are instantiated. Note that without parallel execution, there is no +// way this can keep up with real time since in every 200 msec cycle it has 800 +// msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded +// version, showing that without threads, this takes more than 800 msec to +// complete 200 msec of logical time. target Cpp { timeout: 2 sec } diff --git a/test/Cpp/src/concurrent/ThreadedThreaded.lf b/test/Cpp/src/concurrent/ThreadedThreaded.lf index e8d50e7a33..f8b21a6121 100644 --- a/test/Cpp/src/concurrent/ThreadedThreaded.lf +++ b/test/Cpp/src/concurrent/ThreadedThreaded.lf @@ -1,9 +1,11 @@ -// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime -// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that -// without parallel execution, there is no way this can keep up with real time since in every 200 -// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing -// that without threads, this takes more than 800 msec to complete 200 msec of logical time. +// Check for speedup of multithreaded execution on multicore machines. Each +// instance of TakeTime takes 200 ms to transport the input to the output. Four +// of them are instantiated. Note that without parallel execution, there is no +// way this can keep up with real time since in every 200 msec cycle it has 800 +// msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded +// version, showing that without threads, this takes more than 800 msec to +// complete 200 msec of logical time. target Cpp { timeout: 2 sec } diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index bd9959b9a0..47371f72d7 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -1,6 +1,7 @@ -// Test that the stop function can be used to internally to impose a a time limit. This is also used -// to test performance (number of reactions per second). Correct output for this 1, 2, 3, 4. Failure -// for this test is failing to halt or getting the wrong data. +// Test that the stop function can be used to internally to impose a a time +// limit. This is also used to test performance (number of reactions per +// second). Correct output for this 1, 2, 3, 4. Failure for this test is failing +// to halt or getting the wrong data. target Cpp { fast: true } diff --git a/test/Cpp/src/concurrent/Workers.lf b/test/Cpp/src/concurrent/Workers.lf index 88579d4ba7..43b7d8a114 100644 --- a/test/Cpp/src/concurrent/Workers.lf +++ b/test/Cpp/src/concurrent/Workers.lf @@ -1,14 +1,14 @@ target Cpp { - workers: 16 + workers: 16 } main reactor { - reaction(startup) {= - if (environment()->num_workers() != 16) { - std::cout << "Expected to have 16 workers.\n"; - exit(1); - } else { - std::cout << "Using 16 workers.\n"; - } - =} + reaction(startup) {= + if (environment()->num_workers() != 16) { + std::cout << "Expected to have 16 workers.\n"; + exit(1); + } else { + std::cout << "Using 16 workers.\n"; + } + =} } diff --git a/test/Cpp/src/lib/Imported.lf b/test/Cpp/src/lib/Imported.lf index 9c29c48be2..abf2464b96 100644 --- a/test/Cpp/src/lib/Imported.lf +++ b/test/Cpp/src/lib/Imported.lf @@ -5,8 +5,8 @@ target Cpp import ImportedAgain from "ImportedAgain.lf" reactor Imported { - input x: int - a = new ImportedAgain() + input x: int + a = new ImportedAgain() - reaction(x) -> a.x {= a.x.set(x.get()); =} + reaction(x) -> a.x {= a.x.set(x.get()); =} } diff --git a/test/Cpp/src/lib/ImportedAgain.lf b/test/Cpp/src/lib/ImportedAgain.lf index 83495dc480..a5e0ba3ceb 100644 --- a/test/Cpp/src/lib/ImportedAgain.lf +++ b/test/Cpp/src/lib/ImportedAgain.lf @@ -3,15 +3,15 @@ target Cpp reactor ImportedAgain { - input x: int + input x: int - reaction(x) {= - auto value = *x.get(); - if (value != 42) { - std::cerr << "ERROR: Expected input to be 42. Got: " << value << std::endl; - exit(1); - } else { - std::cout << "Received " << value << std::endl; - } - =} + reaction(x) {= + auto value = *x.get(); + if (value != 42) { + std::cerr << "ERROR: Expected input to be 42. Got: " << value << std::endl; + exit(1); + } else { + std::cout << "Received " << value << std::endl; + } + =} } diff --git a/test/Cpp/src/lib/ImportedComposition.lf b/test/Cpp/src/lib/ImportedComposition.lf index 97ddb436d0..cc3ccba591 100644 --- a/test/Cpp/src/lib/ImportedComposition.lf +++ b/test/Cpp/src/lib/ImportedComposition.lf @@ -9,18 +9,18 @@ target Cpp reactor Gain { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(*x.get() * 2); =} + reaction(x) -> y {= y.set(*x.get() * 2); =} } reactor ImportedComposition { - input x: int - output y: int - g1 = new Gain() - g2 = new Gain() - x -> g1.x after 10 msec - g1.y -> g2.x after 30 msec - g2.y -> y after 15 msec + input x: int + output y: int + g1 = new Gain() + g2 = new Gain() + x -> g1.x after 10 msec + g1.y -> g2.x after 30 msec + g2.y -> y after 15 msec } diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index 572e00d6c4..3c1cc13631 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -8,9 +8,10 @@ target Cpp /** - * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break after sending - * take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in + * consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break + * after sending take_a_break_after messages. */ reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { output out: int diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index 417d5b325e..07da948506 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport input of the same - * reactors in the bank so that each reactor in the bank receives the output produced by itself and - * each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport + * input of the same reactors in the bank so that each reactor in the bank + * receives the output produced by itself and each other reactor. * * @author Edward A. Lee * @author Christian Menard diff --git a/test/Cpp/src/multiport/IndexIntoMultiportInput.lf b/test/Cpp/src/multiport/IndexIntoMultiportInput.lf index 068724b781..8deaef2c2a 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportInput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportInput.lf @@ -8,46 +8,46 @@ target Cpp reactor ReactorWithMultiport { - input[3] in: int - - reaction(startup, in) {= - bool error{false}; - for (size_t i{0}; i < in.size(); i++) { - if (in[i].is_present()) { - if (*in[i].get() != i) { - reactor::log::Error() << "received wrong input on port " << i; - } - } else { - error = true; - reactor::log::Error() << "input " << i << " is not present"; + input[3] in: int + + reaction(startup, in) {= + bool error{false}; + for (size_t i{0}; i < in.size(); i++) { + if (in[i].is_present()) { + if (*in[i].get() != i) { + reactor::log::Error() << "received wrong input on port " << i; } + } else { + error = true; + reactor::log::Error() << "input " << i << " is not present"; } - if (error) { - exit(1); - } - reactor::log::Info() << "success"; - =} + } + if (error) { + exit(1); + } + reactor::log::Info() << "success"; + =} } reactor MultiportSplitter { - output[3] out: int + output[3] out: int - input in0: int - input in1: int - input in2: int + input in0: int + input in1: int + input in2: int - in0, in1, in2 -> out + in0, in1, in2 -> out } main reactor IndexIntoMultiportInput { - splitter = new MultiportSplitter() - receiver = new ReactorWithMultiport() + splitter = new MultiportSplitter() + receiver = new ReactorWithMultiport() - splitter.out -> receiver.in + splitter.out -> receiver.in - reaction(startup) -> splitter.in0 {= splitter.in0.set(0); =} + reaction(startup) -> splitter.in0 {= splitter.in0.set(0); =} - reaction(startup) -> splitter.in1 {= splitter.in1.set(1); =} + reaction(startup) -> splitter.in1 {= splitter.in1.set(1); =} - reaction(startup) -> splitter.in2 {= splitter.in2.set(2); =} + reaction(startup) -> splitter.in2 {= splitter.in2.set(2); =} } diff --git a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf index dd5a5759e1..964e2e7095 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf @@ -2,8 +2,9 @@ * This test was first described by Peter Donovan in * https://github.com/lf-lang/lingua-franca/issues/1321 * - * It simply tests if passthrough connections work as expected in the C++ target. Such a connection - * directly connects an input to an output of the same reactor, without any reactions in between. + * It simply tests if passthrough connections work as expected in the C++ + * target. Such a connection directly connects an input to an output of the same + * reactor, without any reactions in between. */ target Cpp diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index d1cf2a9d36..b7339a9184 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf index 1b4c53bf83..673ef6889a 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index 1786e5292d..fe27c74f35 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index 75eadf542b..fae914b609 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical +// reactor. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index af2f4eab18..39fce6f8ff 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version fo the Threaded test that uses a multiport input at the destination. Its -// purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the +// destination. Its purpose is to test multiport inputs. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf index 1c520d6759..f9cef6a676 100644 --- a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index ff641336ae..573a0e06da 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,6 @@ -// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that -// the destination reactor has width wider than the sender, so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical +// reactor. Note that the destination reactor has width wider than the sender, +// so one input is dangling. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToMultiportArray.lf b/test/Cpp/src/multiport/MultiportToMultiportArray.lf index 0da837bb17..6c96d17150 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportArray.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportArray.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input. Destination port is wider than sending port. +// Check multiport output to multiport input. Destination port is wider than +// sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToPort.lf b/test/Cpp/src/multiport/MultiportToPort.lf index 48804f575e..c2b0bd66ef 100644 --- a/test/Cpp/src/multiport/MultiportToPort.lf +++ b/test/Cpp/src/multiport/MultiportToPort.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input. Destination port is wider than sending port. +// Check multiport output to multiport input. Destination port is wider than +// sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/PipelineAfter.lf b/test/Cpp/src/multiport/PipelineAfter.lf index d708d727ff..b160ab8104 100644 --- a/test/Cpp/src/multiport/PipelineAfter.lf +++ b/test/Cpp/src/multiport/PipelineAfter.lf @@ -1,38 +1,38 @@ target Cpp reactor Source { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(40); =} + reaction(startup) -> out {= out.set(40); =} } reactor Compute { - input in: unsigned - output out: unsigned + input in: unsigned + output out: unsigned - reaction(in) -> out {= out.set(*in.get() + 2); =} + reaction(in) -> out {= out.set(*in.get() + 2); =} } reactor Sink { - input in: unsigned - - reaction(in) {= - std::cout << "Received " << *in.get() << '\n'; - if (*in.get() != 42) { - std::cerr << "Error: expected 42!\n"; - exit(1); - } - if (get_elapsed_logical_time() != 1s) { - std::cerr << "ERROR: Expected to receive input after 1 second.\n"; - exit(2); - } - =} + input in: unsigned + + reaction(in) {= + std::cout << "Received " << *in.get() << '\n'; + if (*in.get() != 42) { + std::cerr << "Error: expected 42!\n"; + exit(1); + } + if (get_elapsed_logical_time() != 1s) { + std::cerr << "ERROR: Expected to receive input after 1 second.\n"; + exit(2); + } + =} } main reactor { - source = new Source() - compute = new Compute() - sink = new Sink() + source = new Source() + compute = new Compute() + sink = new Sink() - source.out, compute.out -> compute.in, sink.in after 500 msec + source.out, compute.out -> compute.in, sink.in after 500 msec } diff --git a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf index c4bdb80d9d..6fa6dbb87b 100644 --- a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf @@ -1,4 +1,5 @@ -// Test reacting to and reading outputs from a contained reactor bank with a multiport +// Test reacting to and reading outputs from a contained reactor bank with a +// multiport target Cpp reactor Contained(bank_index: size_t = 0) { diff --git a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf index db27bf5a6f..18179b9086 100644 --- a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf @@ -1,4 +1,5 @@ -// Test reacting to and reading outputs from a contained reactor bank in various permutations. +// Test reacting to and reading outputs from a contained reactor bank in various +// permutations. target Cpp reactor Contained(bank_index: size_t = 0) { diff --git a/test/Cpp/src/target/BraceAndParenInitialization.lf b/test/Cpp/src/target/BraceAndParenInitialization.lf index 488a2719f5..003b6d509d 100644 --- a/test/Cpp/src/target/BraceAndParenInitialization.lf +++ b/test/Cpp/src/target/BraceAndParenInitialization.lf @@ -6,8 +6,10 @@ reactor Foo( param_list_3: std::vector(4, 2), // list containing [2,2,2,2] param_list_4: std::vector{4, 2} // list containing [4,2] ) { - state state_list_1: std::vector(6, 42) // list containing [42,42,42,42,42,42] - state state_list_2: std::vector{6, 42} // list containing [6,42] + // list containing [42,42,42,42,42,42] + state state_list_1: std::vector(6, 42) + // list containing [6,42] + state state_list_2: std::vector{6, 42} reaction(startup) {= std::cerr << "Hello!\n"; diff --git a/test/Cpp/src/target/CMakeInclude.lf b/test/Cpp/src/target/CMakeInclude.lf index b1adacc966..1291e56425 100644 --- a/test/Cpp/src/target/CMakeInclude.lf +++ b/test/Cpp/src/target/CMakeInclude.lf @@ -2,19 +2,19 @@ * Test that cmake-include is working correctly. The failure for this test is failure to compile. */ target Cpp { - cmake-include: [ - "../include/mlib-cmake-extension.cmake", - "../include/bar-cmake-compile-definition.txt" - ], - timeout: 0 sec + cmake-include: [ + "../include/mlib-cmake-extension.cmake", + "../include/bar-cmake-compile-definition.txt" + ], + timeout: 0 sec } main reactor { - private preamble {= - #include - =} + private preamble {= + #include + =} - reaction(startup) {= - std::cout << "Maximum of 4.20 and " << BAR << " is " << fmax(4.20, BAR) << std::endl; - =} + reaction(startup) {= + std::cout << "Maximum of 4.20 and " << BAR << " is " << fmax(4.20, BAR) << std::endl; + =} } diff --git a/test/Cpp/src/target/PreambleFile.lf b/test/Cpp/src/target/PreambleFile.lf index db9ff5e712..53f6ff49da 100644 --- a/test/Cpp/src/target/PreambleFile.lf +++ b/test/Cpp/src/target/PreambleFile.lf @@ -3,50 +3,50 @@ target Cpp // These declarations are used by multiple reactors within this file and should be placed in a // header. This goes to PreampleFile/preamble.hh. public preamble {= - struct MyStruct { - int foo; - std::string bar; - }; + struct MyStruct { + int foo; + std::string bar; + }; - int add_42(int i); + int add_42(int i); =} // This definition is used by multiple reactors within this file. Since the same function can only // be defined once, this needs to go to a source file. This goes to PreampleFile/preamble.cc. private preamble {= - int add_42(int i) { - return i + 42; - } + int add_42(int i) { + return i + 42; + } =} reactor Source { - output x: MyStruct + output x: MyStruct - reaction(startup) -> x {= - int a = add_42(0); - x.set({a, "baz"}); - =} + reaction(startup) -> x {= + int a = add_42(0); + x.set({a, "baz"}); + =} } reactor Print { - // This helper function is only used within the Print reactor and is therefore part of its - // private interface. This goes to PreambleFile/Print.cc - private preamble {= - void print(const MyStruct& x) { - std::cout << "Received " << x.foo << " and '" << x.bar << "'\n"; - } - =} - input x: MyStruct - - reaction(x) {= - MyStruct value = *x.get(); // implicit copy - value.foo = add_42(value.foo); - print(value); - =} + // This helper function is only used within the Print reactor and is therefore part of its private + // interface. This goes to PreambleFile/Print.cc + private preamble {= + void print(const MyStruct& x) { + std::cout << "Received " << x.foo << " and '" << x.bar << "'\n"; + } + =} + input x: MyStruct + + reaction(x) {= + MyStruct value = *x.get(); // implicit copy + value.foo = add_42(value.foo); + print(value); + =} } main reactor PreambleFile { - s = new Source() - p = new Print() - s.x -> p.x + s = new Source() + p = new Print() + s.x -> p.x } diff --git a/test/Python/src/ActionWithNoReaction.lf b/test/Python/src/ActionWithNoReaction.lf index 1b0ee74893..a219377e6e 100644 --- a/test/Python/src/ActionWithNoReaction.lf +++ b/test/Python/src/ActionWithNoReaction.lf @@ -1,36 +1,36 @@ # This checks that action can be created even if there is no reaction. This test passes merely by # compiling and executing without a segfault. Its other functionality is tested by other tests. target Python { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x - output y - logical action a + input x + output y + logical action a - reaction(x) -> y, a {= # reaction(a) {= =} - y.set(2*x.value) - a.schedule(MSEC(500)) - =} + reaction(x) -> y, a {= # reaction(a) {= =} + y.set(2*x.value) + a.schedule(MSEC(500)) + =} } reactor print { - input x + input x - reaction(x) {= - print("Result is {:d}\n".format(x.value)) - print("Current logical time is: {:d}\n".format(lf.time.logical_elapsed())) - print("Current physical time is: {:d}\n".format(lf.time.physical_elapsed())) - =} + reaction(x) {= + print("Result is {:d}\n".format(x.value)) + print("Current logical time is: {:d}\n".format(lf.time.logical_elapsed())) + print("Current physical time is: {:d}\n".format(lf.time.physical_elapsed())) + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= f.x.set(42) =} + reaction(t) -> f.x {= f.x.set(42) =} } diff --git a/test/Python/src/After.lf b/test/Python/src/After.lf index 8ed92b2061..0c8b931543 100644 --- a/test/Python/src/After.lf +++ b/test/Python/src/After.lf @@ -1,4 +1,5 @@ -# This checks that the after keyword adjusts logical time, not using physical time. +# This checks that the after keyword adjusts logical time, not using physical +# time. target Python { fast: false, timeout: 3 sec diff --git a/test/Python/src/AfterCycles.lf b/test/Python/src/AfterCycles.lf index e062d013ee..cd0f0dd98e 100644 --- a/test/Python/src/AfterCycles.lf +++ b/test/Python/src/AfterCycles.lf @@ -1,5 +1,5 @@ -# This tests that "after" does not introduce spurious cycles. Success if running without detected a -# cycle. +# This tests that "after" does not introduce spurious cycles. Success if running +# without detected a cycle. target Python reactor Source { diff --git a/test/Python/src/ArrayAsType.lf b/test/Python/src/ArrayAsType.lf index 37d5d66cf7..dc3b2f6e26 100644 --- a/test/Python/src/ArrayAsType.lf +++ b/test/Python/src/ArrayAsType.lf @@ -1,5 +1,5 @@ -# Source produces a statically allocated array, which it passes to Print. The destination references -# the array directly. +# Source produces a statically allocated array, which it passes to Print. The +# destination references the array directly. target Python reactor Source { diff --git a/test/Python/src/ArrayFree.lf b/test/Python/src/ArrayFree.lf index 147e9537a8..2ea2777c12 100644 --- a/test/Python/src/ArrayFree.lf +++ b/test/Python/src/ArrayFree.lf @@ -1,7 +1,7 @@ -# Source produces a dynamically allocated array, which it passes to Free. Free requests a writable -# copy, which, instead of copying, it just gets ownership of the original array. It then does -# nothing further with it. This test checks that the memory gets freed automatically even with the -# mutable input. +# Source produces a dynamically allocated array, which it passes to Free. Free +# requests a writable copy, which, instead of copying, it just gets ownership of +# the original array. It then does nothing further with it. This test checks +# that the memory gets freed automatically even with the mutable input. target Python import Source, Print from "ArrayPrint.lf" diff --git a/test/Python/src/ArrayParallel.lf b/test/Python/src/ArrayParallel.lf index 5e75898f14..1316f14ee5 100644 --- a/test/Python/src/ArrayParallel.lf +++ b/test/Python/src/ArrayParallel.lf @@ -7,13 +7,13 @@ import Scale from "ArrayScale.lf" import Source, Print from "ArrayPrint.lf" main reactor ArrayParallel { - s = new Source() - c1 = new Scale() - c2 = new Scale(scale = 3) - p1 = new Print(scale = 2) - p2 = new Print(scale = 3) - s.out -> c1._in - s.out -> c2._in - c1.out -> p1._in - c2.out -> p2._in + s = new Source() + c1 = new Scale() + c2 = new Scale(scale = 3) + p1 = new Print(scale = 2) + p2 = new Print(scale = 3) + s.out -> c1._in + s.out -> c2._in + c1.out -> p1._in + c2.out -> p2._in } diff --git a/test/Python/src/ArrayPrint.lf b/test/Python/src/ArrayPrint.lf index 254d9c352d..4420311b93 100644 --- a/test/Python/src/ArrayPrint.lf +++ b/test/Python/src/ArrayPrint.lf @@ -1,5 +1,5 @@ -# Source produces a dynamically allocated array, which it passes to Print. Reference counting -# ensures that the array is freed. +# Source produces a dynamically allocated array, which it passes to Print. +# Reference counting ensures that the array is freed. target Python reactor Source { diff --git a/test/Python/src/ArrayScale.lf b/test/Python/src/ArrayScale.lf index 10f5a747e6..2b69aebe77 100644 --- a/test/Python/src/ArrayScale.lf +++ b/test/Python/src/ArrayScale.lf @@ -1,6 +1,7 @@ -# Source produces a dynamically allocated array, which it passes to Scale. Scale requests a writable -# copy, which, instead of copying, it just gets ownership of the original array. It modifies it and -# passes it to Print. It gets freed after Print is done with it. +# Source produces a dynamically allocated array, which it passes to Scale. Scale +# requests a writable copy, which, instead of copying, it just gets ownership of +# the original array. It modifies it and passes it to Print. It gets freed after +# Print is done with it. target Python import Print, Source from "ArrayPrint.lf" diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index a5b9cac96f..d1bef93ed2 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -1,4 +1,5 @@ -# This test connects a simple counting source to tester that checks against its own count. +# This test connects a simple counting source to tester that checks against its +# own count. target Python { fast: true, timeout: 10 sec diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index 74217559db..00b95e3ab9 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -1,4 +1,5 @@ -# This test connects a simple counting source to tester that checks against its own count. +# This test connects a simple counting source to tester that checks against its +# own count. target Python { fast: true, timeout: 10 sec diff --git a/test/Python/src/CompositionGain.lf b/test/Python/src/CompositionGain.lf index 6bc0f74c74..e3630f3169 100644 --- a/test/Python/src/CompositionGain.lf +++ b/test/Python/src/CompositionGain.lf @@ -2,32 +2,32 @@ target Python reactor Gain { - input gainin - output y + input gainin + output y - reaction(gainin) -> y {= - print("Gain received " + str(gainin.value)) - y.set(gainin.value * 2) - =} + reaction(gainin) -> y {= + print("Gain received " + str(gainin.value)) + y.set(gainin.value * 2) + =} } reactor Wrapper { - input x - output y - gain = new Gain() - x -> gain.gainin - gain.y -> y + input x + output y + gain = new Gain() + x -> gain.gainin + gain.y -> y } main reactor { - wrapper = new Wrapper() + wrapper = new Wrapper() - reaction(startup) -> wrapper.x {= wrapper_x.set(42) =} + reaction(startup) -> wrapper.x {= wrapper_x.set(42) =} - reaction(wrapper.y) {= - print("Received " + str(wrapper_y.value)) - if (wrapper_y.value != 42 * 2): - sys.stderr.write("ERROR: Received value should have been ", str(42 * 2)) - exit(2) - =} + reaction(wrapper.y) {= + print("Received " + str(wrapper_y.value)) + if (wrapper_y.value != 42 * 2): + sys.stderr.write("ERROR: Received value should have been ", str(42 * 2)) + exit(2) + =} } diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index aeaa9e30bb..4b0e4a38c9 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -1,4 +1,5 @@ -# This test connects a simple counting source to tester that checks against its own count. +# This test connects a simple counting source to tester that checks against its +# own count. target Python { fast: true, timeout: 10 sec diff --git a/test/Python/src/DanglingOutput.lf b/test/Python/src/DanglingOutput.lf index 7894f73835..f6fe938765 100644 --- a/test/Python/src/DanglingOutput.lf +++ b/test/Python/src/DanglingOutput.lf @@ -3,24 +3,24 @@ target Python reactor Source { - output out - timer t + output out + timer t - reaction(t) -> out {= out.set(1); =} + reaction(t) -> out {= out.set(1); =} } reactor Gain { - input _in - output out + input _in + output out - reaction(_in) -> out {= - print("Received ", _in.value) - out.set(_in.value * 2) - =} + reaction(_in) -> out {= + print("Received ", _in.value) + out.set(_in.value * 2) + =} } main reactor DanglingOutput { - source = new Source() - container = new Gain() - source.out -> container._in + source = new Source() + container = new Gain() + source.out -> container._in } diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index 154a755327..ceab2b28e2 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -1,5 +1,6 @@ -# This example illustrates local deadline handling. Even numbers are sent by the Source immediately, -# whereas odd numbers are sent after a big enough delay to violate the deadline. +# This example illustrates local deadline handling. Even numbers are sent by the +# Source immediately, whereas odd numbers are sent after a big enough delay to +# violate the deadline. target Python { timeout: 6 sec } diff --git a/test/Python/src/DeadlineHandledAbove.lf b/test/Python/src/DeadlineHandledAbove.lf index 39c927ee08..1259253cea 100644 --- a/test/Python/src/DeadlineHandledAbove.lf +++ b/test/Python/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -# Test a deadline where the deadline violation produces an output and the container reacts to that -# output. +# Test a deadline where the deadline violation produces an output and the +# container reacts to that output. target Python preamble {= import time =} diff --git a/test/Python/src/DelayArrayWithAfter.lf b/test/Python/src/DelayArrayWithAfter.lf index 52245e314f..1e6ac1f317 100644 --- a/test/Python/src/DelayArrayWithAfter.lf +++ b/test/Python/src/DelayArrayWithAfter.lf @@ -1,4 +1,5 @@ -# This tests transport of dynamically allocated arrays over connections with 'after'. +# This tests transport of dynamically allocated arrays over connections with +# 'after'. target Python { timeout: 5 sec, fast: true diff --git a/test/Python/src/DelayString.lf b/test/Python/src/DelayString.lf index e7e7531888..d1201dec02 100644 --- a/test/Python/src/DelayString.lf +++ b/test/Python/src/DelayString.lf @@ -1,4 +1,5 @@ -# This tests actions with immutable payloads that are neither malloc'd nor freed. +# This tests actions with immutable payloads that are neither malloc'd nor +# freed. target Python reactor DelayString2(delay = 100 msec) { diff --git a/test/Python/src/DelayedReaction.lf b/test/Python/src/DelayedReaction.lf index fc3a47f04a..c62b4a3857 100644 --- a/test/Python/src/DelayedReaction.lf +++ b/test/Python/src/DelayedReaction.lf @@ -2,26 +2,26 @@ target Python reactor Source { - output out - timer t + output out + timer t - reaction(t) -> out {= out.set(1) =} + reaction(t) -> out {= out.set(1) =} } reactor Sink { - input _in + input _in - reaction(_in) {= - elapsed = lf.time.logical_elapsed() - print("Nanoseconds since start: ", elapsed) - if elapsed != 100000000: - sys.stderr.write("ERROR: Expected 100000000 but.\n") - exit(1) - =} + reaction(_in) {= + elapsed = lf.time.logical_elapsed() + print("Nanoseconds since start: ", elapsed) + if elapsed != 100000000: + sys.stderr.write("ERROR: Expected 100000000 but.\n") + exit(1) + =} } main reactor DelayedReaction { - source = new Source() - sink = new Sink() - source.out -> sink._in after 100 msec + source = new Source() + sink = new Sink() + source.out -> sink._in after 100 msec } diff --git a/test/Python/src/Determinism.lf b/test/Python/src/Determinism.lf index 1a88bac2e8..fdfe446e3d 100644 --- a/test/Python/src/Determinism.lf +++ b/test/Python/src/Determinism.lf @@ -1,43 +1,43 @@ target Python reactor Source { - output y - timer t + output y + timer t - reaction(t) -> y {= y.set(1) =} + reaction(t) -> y {= y.set(1) =} } reactor Destination { - input x - input y + input x + input y - reaction(x, y) {= - sm = 0 - if x.is_present: - sm += x.value - if y.is_present: - sm += y.value - print("Received ", sm); - if sm != 2: - sys.stderr.write("FAILURE: Expected 2.\n") - exit(4) - =} + reaction(x, y) {= + sm = 0 + if x.is_present: + sm += x.value + if y.is_present: + sm += y.value + print("Received ", sm); + if sm != 2: + sys.stderr.write("FAILURE: Expected 2.\n") + exit(4) + =} } reactor Pass { - input x - output y + input x + output y - reaction(x) -> y {= y.set(x.value) =} + reaction(x) -> y {= y.set(x.value) =} } main reactor Determinism { - s = new Source() - d = new Destination() - p1 = new Pass() - p2 = new Pass() - s.y -> d.y - s.y -> p1.x - p1.y -> p2.x - p2.y -> d.x + s = new Source() + d = new Destination() + p1 = new Pass() + p2 = new Pass() + s.y -> d.y + s.y -> p1.x + p1.y -> p2.x + p2.y -> d.x } diff --git a/test/Python/src/DoubleInvocation.lf b/test/Python/src/DoubleInvocation.lf index 78d31883ea..aaecfa31cb 100644 --- a/test/Python/src/DoubleInvocation.lf +++ b/test/Python/src/DoubleInvocation.lf @@ -1,7 +1,8 @@ -# This illustrates a very strange bug that showed up and has now been fixed. This test ensures it -# does not reappear. At logical time zero, the two Print reactors used to be fired twice each at the -# same logical time. They should only be fired once. This behavior was oddly eliminated by either of -# the following actions, neither of which should affect this behavior: +# This illustrates a very strange bug that showed up and has now been fixed. +# This test ensures it does not reappear. At logical time zero, the two Print +# reactors used to be fired twice each at the same logical time. They should +# only be fired once. This behavior was oddly eliminated by either of the +# following actions, neither of which should affect this behavior: # * Removing the startup reaction in Print. # * Sending only position, not velocity from Ball. target Python { diff --git a/test/Python/src/DoubleReaction.lf b/test/Python/src/DoubleReaction.lf index 7af73da6ec..c20a032a9a 100644 --- a/test/Python/src/DoubleReaction.lf +++ b/test/Python/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -# Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output for -# this 2, 4, 6, 8, etc. +# Test that two simultaneous inputs that trigger a reaction trigger it only +# once. Correct output for this 2, 4, 6, 8, etc. target Python { timeout: 10 sec, fast: true diff --git a/test/Python/src/GetTime.lf b/test/Python/src/GetTime.lf index 8c22851395..b24d667aec 100644 --- a/test/Python/src/GetTime.lf +++ b/test/Python/src/GetTime.lf @@ -1,26 +1,26 @@ # This file includes code documented on the Wiki. For this test, success is just compiling and # running. target Python { - timeout: 2 sec, - fast: false + timeout: 2 sec, + fast: false } main reactor GetTime { - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) {= - logical = lf.time.logical() - print("Logical time is ", logical) + reaction(t) {= + logical = lf.time.logical() + print("Logical time is ", logical) - elapsed = lf.time.logical_elapsed() - print("Elapsed logical time is ", elapsed) + elapsed = lf.time.logical_elapsed() + print("Elapsed logical time is ", elapsed) - physical = lf.time.physical() - print("Physical time is ", physical) + physical = lf.time.physical() + print("Physical time is ", physical) - elapsed_physical = lf.time.physical_elapsed() - print("Elapsed physical time is ", elapsed_physical) + elapsed_physical = lf.time.physical_elapsed() + print("Elapsed physical time is ", elapsed_physical) - print("Time lag is ", physical - logical) - =} + print("Time lag is ", physical - logical) + =} } diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index 8e60df4ae5..271ed180ca 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -1,7 +1,8 @@ -# This test checks that logical time is incremented an appropriate amount as a result of an -# invocation of the schedule() function at runtime. It also performs various smoke tests of timing -# aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, and the -# third (composite) or 1 second. +# This test checks that logical time is incremented an appropriate amount as a +# result of an invocation of the schedule() function at runtime. It also +# performs various smoke tests of timing aligned reactions. The first instance +# has a period of 4 seconds, the second of 2 seconds, and the third (composite) +# or 1 second. target Python { timeout: 10 sec, fast: true @@ -42,7 +43,10 @@ reactor Inside(period = 1 sec, message = "Composite default message.") { } main reactor Hello { - first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance.") + first_instance = new Reschedule( + period = 4 sec, + message = "Hello from first_instance." + ) second_instance = new Reschedule(message = "Hello from second_instance.") composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/Python/src/Hierarchy.lf b/test/Python/src/Hierarchy.lf index 9563d62e31..f8206f81db 100644 --- a/test/Python/src/Hierarchy.lf +++ b/test/Python/src/Hierarchy.lf @@ -2,49 +2,49 @@ target Python reactor Source { - output out - timer t + output out + timer t - reaction(t) -> out {= out.set(1) =} + reaction(t) -> out {= out.set(1) =} } reactor Gain { - input _in - output out + input _in + output out - reaction(_in) -> out {= - print("Gain received ", _in.value) - out.set(_in.value * 2) - =} + reaction(_in) -> out {= + print("Gain received ", _in.value) + out.set(_in.value * 2) + =} } reactor Print { - input _in - - reaction(_in) {= - print("Received: ", _in.value) - if _in.value != 2: - sys.stderr.write("Expected 2.\n") - exit(1) - =} + input _in + + reaction(_in) {= + print("Received: ", _in.value) + if _in.value != 2: + sys.stderr.write("Expected 2.\n") + exit(1) + =} } reactor GainContainer { - input _in - output out - output out2 - gain = new Gain() - _in -> gain._in - gain.out -> out - gain.out -> out2 + input _in + output out + output out2 + gain = new Gain() + _in -> gain._in + gain.out -> out + gain.out -> out2 } main reactor Hierarchy { - source = new Source() - container = new GainContainer() - print = new Print() - print2 = new Print() - source.out -> container._in - container.out -> print._in - container.out -> print2._in + source = new Source() + container = new GainContainer() + print = new Print() + print2 = new Print() + source.out -> container._in + container.out -> print._in + container.out -> print2._in } diff --git a/test/Python/src/Import.lf b/test/Python/src/Import.lf index 4c17403320..fc225f1cb0 100644 --- a/test/Python/src/Import.lf +++ b/test/Python/src/Import.lf @@ -4,8 +4,8 @@ target Python import Imported from "lib/Imported.lf" main reactor Import { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= a.x.set(42) =} + reaction(t) -> a.x {= a.x.set(42) =} } diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 8063e7c938..369fbcab44 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -1,4 +1,5 @@ -# This tests the ability to import a reactor definition that itself imports a reactor definition. +# This tests the ability to import a reactor definition that itself imports a +# reactor definition. target Python import ImportedComposition from "lib/ImportedComposition.lf" diff --git a/test/Python/src/ImportRenamed.lf b/test/Python/src/ImportRenamed.lf index ab6f1c8078..0d7433028f 100644 --- a/test/Python/src/ImportRenamed.lf +++ b/test/Python/src/ImportRenamed.lf @@ -6,10 +6,10 @@ import Imported as Y from "lib/Imported.lf" import ImportedAgain as Z from "lib/ImportedAgain.lf" main reactor { - timer t - a = new X() - b = new Y() - c = new Z() + timer t + a = new X() + b = new Y() + c = new Z() - reaction(t) -> a.x {= a.x.set(42) =} + reaction(t) -> a.x {= a.x.set(42) =} } diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index 57a4d2efbb..a9e39829eb 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -1,11 +1,12 @@ target Python { - # Set keepalive to false since this is a test and schedule is called on a physical action from - # within a reaction. This is one of the special rare cases where the user might want to manually - # override keepalive. + # Set keepalive to false since this is a test and schedule is called on a + # physical action from within a reaction. This is one of the special rare + # cases where the user might want to manually override keepalive. keepalive: false } -reactor GeneratedDelay { # That's the stuff that shall be generated for the after +# That's the stuff that shall be generated for the after +reactor GeneratedDelay { input y_in output y_out state y_state = 0 diff --git a/test/Python/src/Microsteps.lf b/test/Python/src/Microsteps.lf index 292118f61e..3913cc9c4b 100644 --- a/test/Python/src/Microsteps.lf +++ b/test/Python/src/Microsteps.lf @@ -1,37 +1,37 @@ target Python reactor Destination { - input x - input y + input x + input y - reaction(x, y) {= - elapsed = lf.time.logical_elapsed() - print("Time since start: ", elapsed) - if elapsed != 0: - sys.stderr.write("Expected elapsed time to be 0, but it was {:d}.".format(elapsed)) - exit(1) - count = 0 - if x.is_present: - print("x is present.") - count += 1 - if y.is_present: - print("y is present.") - count += 1 - if count != 1: - sys.stderr.write("Expected exactly one input to be present but got {:d}.".format(count)) - exit(1) - =} + reaction(x, y) {= + elapsed = lf.time.logical_elapsed() + print("Time since start: ", elapsed) + if elapsed != 0: + sys.stderr.write("Expected elapsed time to be 0, but it was {:d}.".format(elapsed)) + exit(1) + count = 0 + if x.is_present: + print("x is present.") + count += 1 + if y.is_present: + print("y is present.") + count += 1 + if count != 1: + sys.stderr.write("Expected exactly one input to be present but got {:d}.".format(count)) + exit(1) + =} } main reactor Microsteps { - timer start - logical action repeat - d = new Destination() + timer start + logical action repeat + d = new Destination() - reaction(start) -> d.x, repeat {= - d.x.set(1) - repeat.schedule(0) - =} + reaction(start) -> d.x, repeat {= + d.x.set(1) + repeat.schedule(0) + =} - reaction(repeat) -> d.y {= d.y.set(1) =} + reaction(repeat) -> d.y {= d.y.set(1) =} } diff --git a/test/Python/src/Minimal.lf b/test/Python/src/Minimal.lf index 63b089c41c..c0f3f9f6fa 100644 --- a/test/Python/src/Minimal.lf +++ b/test/Python/src/Minimal.lf @@ -2,5 +2,5 @@ target Python main reactor Minimal { - reaction(startup) {= print("Hello World.") =} + reaction(startup) {= print("Hello World.") =} } diff --git a/test/Python/src/MovingAverage.lf b/test/Python/src/MovingAverage.lf index 963cb72db1..3dbd5636c3 100644 --- a/test/Python/src/MovingAverage.lf +++ b/test/Python/src/MovingAverage.lf @@ -1,5 +1,6 @@ -# Demonstration of a state variable that is a list. The MovingAverage reactor computes the moving -# average of the last four inputs and produces that as output. The source is a counting sequence. +# Demonstration of a state variable that is a list. The MovingAverage reactor +# computes the moving average of the last four inputs and produces that as +# output. The source is a counting sequence. target Python { timeout: 1 sec, fast: true diff --git a/test/Python/src/MultipleContained.lf b/test/Python/src/MultipleContained.lf index ae9cb0e96b..27950ccd88 100644 --- a/test/Python/src/MultipleContained.lf +++ b/test/Python/src/MultipleContained.lf @@ -1,4 +1,5 @@ -# Test that a reaction can react to and send two multiple ports of a contained reactor. +# Test that a reaction can react to and send two multiple ports of a contained +# reactor. target Python reactor Contained { diff --git a/test/Python/src/PingPong.lf b/test/Python/src/PingPong.lf index 72c5e19563..f5f80511ae 100644 --- a/test/Python/src/PingPong.lf +++ b/test/Python/src/PingPong.lf @@ -1,19 +1,22 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. This is based on https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure + * message-passing overhead. This is based on + * https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the causality loop. + * Ping introduces a microstep delay using a logical action to break the + * causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from being being threaded, - * just some additional overhead. + * There is no parallelism in this application, so it does not benefit from + * being being threaded, just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. These are about an - * order of magnitude faster than anything reported in the paper. + * These measurements are total execution time, including startup and shutdown. + * These are about an order of magnitude faster than anything reported in the + * paper. * * @author Edward A. Lee */ diff --git a/test/Python/src/Preamble.lf b/test/Python/src/Preamble.lf index e158ea03b3..6cbd9d9299 100644 --- a/test/Python/src/Preamble.lf +++ b/test/Python/src/Preamble.lf @@ -1,23 +1,23 @@ # Preambles are put inside the Python reactor class Therefore, accessing them requires the use of # self. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } main reactor Preamble { - preamble {= - import platform - def add_42(self, i): - return i + 42 - =} - timer t + preamble {= + import platform + def add_42(self, i): + return i + 42 + =} + timer t - reaction(t) {= - s = "42"; - i = int(s) - print("Converted string {:s} to int {:d}.".format(s, i)) - print("42 plus 42 is ", self.add_42(42)) - print("Your platform is ", self.platform.system()) - =} + reaction(t) {= + s = "42"; + i = int(s) + print("Converted string {:s} to int {:d}.".format(s, i)) + print("42 plus 42 is ", self.add_42(42)) + print("Your platform is ", self.platform.system()) + =} } diff --git a/test/Python/src/ReadOutputOfContainedReactor.lf b/test/Python/src/ReadOutputOfContainedReactor.lf index 4052d70e77..1cb73667ce 100644 --- a/test/Python/src/ReadOutputOfContainedReactor.lf +++ b/test/Python/src/ReadOutputOfContainedReactor.lf @@ -1,4 +1,5 @@ -# Test reacting to and reading outputs from a contained reactor in various permutations. +# Test reacting to and reading outputs from a contained reactor in various +# permutations. target Python reactor Contained { diff --git a/test/Python/src/Schedule.lf b/test/Python/src/Schedule.lf index 15806af2e3..b79a7298bd 100644 --- a/test/Python/src/Schedule.lf +++ b/test/Python/src/Schedule.lf @@ -2,23 +2,23 @@ target Python reactor Schedule2 { - input x - logical action a + input x + logical action a - reaction(x) -> a {= a.schedule(MSEC(200)) =} + reaction(x) -> a {= a.schedule(MSEC(200)) =} - reaction(a) {= - elapsed_time = lf.time.logical_elapsed() - print("Action triggered at logical time {:d} nsec after start.".format(elapsed_time)) - if elapsed_time != 200000000: - sys.stderr.write("Expected action time to be 200 msec. It was {:d} nsec.\n".format(elapsed_time)) - exit(1) - =} + reaction(a) {= + elapsed_time = lf.time.logical_elapsed() + print("Action triggered at logical time {:d} nsec after start.".format(elapsed_time)) + if elapsed_time != 200000000: + sys.stderr.write("Expected action time to be 200 msec. It was {:d} nsec.\n".format(elapsed_time)) + exit(1) + =} } main reactor { - a = new Schedule2() - timer t + a = new Schedule2() + timer t - reaction(t) -> a.x {= a.x.set(1) =} + reaction(t) -> a.x {= a.x.set(1) =} } diff --git a/test/Python/src/ScheduleLogicalAction.lf b/test/Python/src/ScheduleLogicalAction.lf index b60471f676..3f99c65777 100644 --- a/test/Python/src/ScheduleLogicalAction.lf +++ b/test/Python/src/ScheduleLogicalAction.lf @@ -1,5 +1,5 @@ -# This checks that a logical action is scheduled the specified logical time after the current -# logical time. +# This checks that a logical action is scheduled the specified logical time +# after the current logical time. target Python { fast: true, timeout: 3 sec diff --git a/test/Python/src/ScheduleValue.lf b/test/Python/src/ScheduleValue.lf index 3dc2a28717..02fb0a3b1f 100644 --- a/test/Python/src/ScheduleValue.lf +++ b/test/Python/src/ScheduleValue.lf @@ -1,20 +1,20 @@ /** Test of schedule_value. */ target Python { - timeout: 3 sec + timeout: 3 sec } main reactor ScheduleValue { - logical action a + logical action a - reaction(startup) -> a {= - value = "Hello" - a.schedule(0, value) - =} + reaction(startup) -> a {= + value = "Hello" + a.schedule(0, value) + =} - reaction(a) {= - print("Received: ", a.value) - if a.value != "Hello": - sys.stderr.write("FAILURE: Should have received 'Hello'\n") - exit(1) - =} + reaction(a) {= + print("Received: ", a.value) + if a.value != "Hello": + sys.stderr.write("FAILURE: Should have received 'Hello'\n") + exit(1) + =} } diff --git a/test/Python/src/SendingInside.lf b/test/Python/src/SendingInside.lf index e6645fbc44..8bcc66c005 100644 --- a/test/Python/src/SendingInside.lf +++ b/test/Python/src/SendingInside.lf @@ -1,5 +1,5 @@ -# This tests a reactor that contains another reactor and also has its own reaction that routes -# inputs to the contained reactor. +# This tests a reactor that contains another reactor and also has its own +# reaction that routes inputs to the contained reactor. target Python { timeout: 10 sec, fast: true diff --git a/test/Python/src/SendingInside2.lf b/test/Python/src/SendingInside2.lf index db941c67d4..cdf99e6a2d 100644 --- a/test/Python/src/SendingInside2.lf +++ b/test/Python/src/SendingInside2.lf @@ -1,19 +1,19 @@ target Python reactor Printer { - input x + input x - reaction(x) {= - print("Inside reactor received: ", x.value) - if x.value != 1: - sys.stderr.write("ERROR: Expected 1.\n") - exit(1) - =} + reaction(x) {= + print("Inside reactor received: ", x.value) + if x.value != 1: + sys.stderr.write("ERROR: Expected 1.\n") + exit(1) + =} } main reactor SendingInside2 { - timer t - p = new Printer() + timer t + p = new Printer() - reaction(t) -> p.x {= p.x.set(1) =} + reaction(t) -> p.x {= p.x.set(1) =} } diff --git a/test/Python/src/SetArray.lf b/test/Python/src/SetArray.lf index 8906312c04..4766d529f7 100644 --- a/test/Python/src/SetArray.lf +++ b/test/Python/src/SetArray.lf @@ -1,5 +1,6 @@ -# This tests passing lists as port values This tests the use of the "polymorphic" delay reactor on a -# struct. It delays by a logical time any pointer datatype. +# This tests passing lists as port values This tests the use of the +# "polymorphic" delay reactor on a struct. It delays by a logical time any +# pointer datatype. target Python reactor Source { diff --git a/test/Python/src/SimpleDeadline.lf b/test/Python/src/SimpleDeadline.lf index f1065e9508..a714124129 100644 --- a/test/Python/src/SimpleDeadline.lf +++ b/test/Python/src/SimpleDeadline.lf @@ -1,5 +1,6 @@ -# Test local deadline, where a deadline is associated with a reaction definition. This test triggers -# a reaction exactly once with a deadline violation. +# Test local deadline, where a deadline is associated with a reaction +# definition. This test triggers a reaction exactly once with a deadline +# violation. target Python reactor Deadline(threshold = 100 msec) { diff --git a/test/Python/src/SimpleImport.lf b/test/Python/src/SimpleImport.lf index 1183070e24..ee97177f06 100644 --- a/test/Python/src/SimpleImport.lf +++ b/test/Python/src/SimpleImport.lf @@ -3,6 +3,6 @@ target Python import HelloWorld2 from "HelloWorld.lf" main reactor SimpleImport { - a = new HelloWorld2() - b = new HelloWorld2() + a = new HelloWorld2() + b = new HelloWorld2() } diff --git a/test/Python/src/SlowingClock.lf b/test/Python/src/SlowingClock.lf index 72f6657ffb..972421437a 100644 --- a/test/Python/src/SlowingClock.lf +++ b/test/Python/src/SlowingClock.lf @@ -1,7 +1,7 @@ /** - * Output events at logical times 100, 300, 600, and 1000 msec after the start time. This uses a - * logical action with a minimum delay of 100 msec and additional delays provided as arguments to - * the schedule() function. + * Output events at logical times 100, 300, 600, and 1000 msec after the start + * time. This uses a logical action with a minimum delay of 100 msec and + * additional delays provided as arguments to the schedule() function. */ target Python { timeout: 1 sec, diff --git a/test/Python/src/StartupOutFromInside.lf b/test/Python/src/StartupOutFromInside.lf index e539f6b63e..eff09b1a77 100644 --- a/test/Python/src/StartupOutFromInside.lf +++ b/test/Python/src/StartupOutFromInside.lf @@ -1,18 +1,18 @@ target Python reactor Bar { - output out + output out - reaction(startup) -> out {= out.set(42) =} + reaction(startup) -> out {= out.set(42) =} } main reactor StartupOutFromInside { - bar = new Bar() + bar = new Bar() - reaction(startup) bar.out {= - print("Output from bar: ", bar.out.value) - if bar.out.value != 42: - sys.stderr.write("Expected 42!\n") - exit(1) - =} + reaction(startup) bar.out {= + print("Output from bar: ", bar.out.value) + if bar.out.value != 42: + sys.stderr.write("Expected 42!\n") + exit(1) + =} } diff --git a/test/Python/src/Stride.lf b/test/Python/src/Stride.lf index 4d1ec22218..86c68bab5a 100644 --- a/test/Python/src/Stride.lf +++ b/test/Python/src/Stride.lf @@ -1,5 +1,5 @@ -# This example illustrates state variables and parameters on the wiki. For this test, success is -# just compiling and running. +# This example illustrates state variables and parameters on the wiki. For this +# test, success is just compiling and running. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/StructAsState.lf b/test/Python/src/StructAsState.lf index dc6bc3c70b..b6f38f8589 100644 --- a/test/Python/src/StructAsState.lf +++ b/test/Python/src/StructAsState.lf @@ -1,4 +1,5 @@ -# Check that a state variable can have a statically initialized struct as a value. +# Check that a state variable can have a statically initialized struct as a +# value. target Python main reactor StructAsState { diff --git a/test/Python/src/StructPrint.lf b/test/Python/src/StructPrint.lf index 414e87c64d..3c0138f937 100644 --- a/test/Python/src/StructPrint.lf +++ b/test/Python/src/StructPrint.lf @@ -1,5 +1,5 @@ -# Source produces a dynamically allocated class object, which it passes to Print. Reference counting -# ensures that the struct is freed. +# Source produces a dynamically allocated class object, which it passes to +# Print. Reference counting ensures that the struct is freed. target Python { files: ["include/hello.py"] } diff --git a/test/Python/src/TestForPreviousOutput.lf b/test/Python/src/TestForPreviousOutput.lf index 1c17308c04..d2a0661768 100644 --- a/test/Python/src/TestForPreviousOutput.lf +++ b/test/Python/src/TestForPreviousOutput.lf @@ -3,38 +3,38 @@ target Python reactor Source { - output out - preamble {= import random =} + output out + preamble {= import random =} - reaction(startup) -> out {= - # Set a seed for random number generation based on the current time. - self.random.seed() - # Randomly produce an output or not. - if self.random.choice([0,1]) == 1: - out.set(21) - =} + reaction(startup) -> out {= + # Set a seed for random number generation based on the current time. + self.random.seed() + # Randomly produce an output or not. + if self.random.choice([0,1]) == 1: + out.set(21) + =} - reaction(startup) -> out {= - if out.is_present: - out.set(2 * out.value) - else: - out.set(42) - =} + reaction(startup) -> out {= + if out.is_present: + out.set(2 * out.value) + else: + out.set(42) + =} } reactor Sink { - input _in + input _in - reaction(_in) {= - print("Received ", _in.value) - if _in.value != 42: - sys.stderr.write("FAILED: Expected 42.\n") - exit(1) - =} + reaction(_in) {= + print("Received ", _in.value) + if _in.value != 42: + sys.stderr.write("FAILED: Expected 42.\n") + exit(1) + =} } main reactor TestForPreviousOutput { - s = new Source() - d = new Sink() - s.out -> d._in + s = new Source() + d = new Sink() + s.out -> d._in } diff --git a/test/Python/src/TimeLimit.lf b/test/Python/src/TimeLimit.lf index 95120083d8..beb7602db9 100644 --- a/test/Python/src/TimeLimit.lf +++ b/test/Python/src/TimeLimit.lf @@ -1,5 +1,6 @@ -# Test that the stop function can be used to internally impose a a time limit. Correct output for -# this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. +# Test that the stop function can be used to internally impose a a time limit. +# Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt +# or getting the wrong data. target Python { fast: true } diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf index a4ae089e46..b65f732652 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf @@ -1,4 +1,7 @@ -/** This test checks that a downstream reaction is triggered only if its trigger is present. */ +/** + * This test checks that a downstream reaction is triggered only if its trigger + * is present. + */ target Python { timeout: 1 sec, fast: true diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf index 7f94ab374a..b9a9184296 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,4 +1,7 @@ -/** This test checks that a downstream reaction is triggered only if its trigger is present. */ +/** + * This test checks that a downstream reaction is triggered only if its trigger + * is present. + */ target Python { timeout: 1 sec, fast: true diff --git a/test/Python/src/Wcet.lf b/test/Python/src/Wcet.lf index ef539b47aa..57216ca078 100644 --- a/test/Python/src/Wcet.lf +++ b/test/Python/src/Wcet.lf @@ -2,43 +2,43 @@ target Python reactor Source { - output out1 - output out2 - timer t - - reaction(t) -> out1, out2 {= - out1.set(5) - out2.set(10) - =} + output out1 + output out2 + timer t + + reaction(t) -> out1, out2 {= + out1.set(5) + out2.set(10) + =} } reactor Work { - input in1 - input in2 - output out - - reaction(in1, in2) -> out {= - ret = 0 - if in1.value > 10: - ret = in2.value * in1.value - else: - ret = in2.value + in1.value - out.set(ret) - =} + input in1 + input in2 + output out + + reaction(in1, in2) -> out {= + ret = 0 + if in1.value > 10: + ret = in2.value * in1.value + else: + ret = in2.value + in1.value + out.set(ret) + =} } reactor Print { - input p_in + input p_in - reaction(p_in) {= print("Received: ", p_in.value) =} + reaction(p_in) {= print("Received: ", p_in.value) =} } main reactor Wcet { - source = new Source() - work = new Work() - print = new Print() + source = new Source() + work = new Work() + print = new Print() - source.out1 -> work.in1 - source.out2 -> work.in2 - work.out -> print.p_in + source.out1 -> work.in1 + source.out2 -> work.in2 + work.out -> print.p_in } diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index a85905c5fd..5ef4167bed 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -1,6 +1,7 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test periodically creates a - * concurrent Python thread that schedule a physical action twice. + * Test asynchronous callbacks that trigger a physical action. This test + * periodically creates a concurrent Python thread that schedule a physical + * action twice. */ target Python { timeout: 2 sec diff --git a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf index a51ff9acdb..4e481d1d34 100644 --- a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf +++ b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf @@ -1,11 +1,11 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test creates a concurrent Python - * thread that schedule a physical action twice. + * Test asynchronous callbacks that trigger a physical action. This test creates + * a concurrent Python thread that schedule a physical action twice. * - * There are no timers in this test to drive the logical time forward. This is important in the - * Python target since the user Python threads should be allowed to execute independently of the - * underlying C core runtime, without the C runtime polling the Python context with a reaction to a - * timer. + * There are no timers in this test to drive the logical time forward. This is + * important in the Python target since the user Python threads should be + * allowed to execute independently of the underlying C core runtime, without + * the C runtime polling the Python context with a reaction to a timer. */ target Python { timeout: 2 sec diff --git a/test/Python/src/docker/HelloWorldContainerized.lf b/test/Python/src/docker/HelloWorldContainerized.lf index 1518dd0583..26e684c580 100644 --- a/test/Python/src/docker/HelloWorldContainerized.lf +++ b/test/Python/src/docker/HelloWorldContainerized.lf @@ -1,9 +1,9 @@ target Python { - docker: true + docker: true } import HelloWorld2 from "../HelloWorld.lf" main reactor { - a = new HelloWorld2() + a = new HelloWorld2() } diff --git a/test/Python/src/docker/PingPongContainerized.lf b/test/Python/src/docker/PingPongContainerized.lf index 4b9c772e2e..1539a12615 100644 --- a/test/Python/src/docker/PingPongContainerized.lf +++ b/test/Python/src/docker/PingPongContainerized.lf @@ -18,16 +18,16 @@ * @author Edward A. Lee */ target Python { - fast: true, - docker: true + fast: true, + docker: true } import Ping from "../PingPong.lf" import Pong from "../PingPong.lf" main reactor PingPongContainerized { - ping = new Ping() - pong = new Pong() - ping.send -> pong.receive - pong.send -> ping.receive + ping = new Ping() + pong = new Pong() + ping.send -> pong.receive + pong.send -> ping.receive } diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index c2f9f7b0d5..5f8a348d24 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python { diff --git a/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf b/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf index 1aa2b1e640..6ae8fa6492 100644 --- a/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf +++ b/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf @@ -5,10 +5,10 @@ * @author Soroush Bateni */ target Python { - timeout: 900 msec, - logging: DEBUG, - coordination: centralized, - docker: true + timeout: 900 msec, + logging: DEBUG, + coordination: centralized, + docker: true } import Count from "../../lib/Count.lf" @@ -16,9 +16,9 @@ import CountMicrostep from "../../federated/DistributedDoublePort.lf" import Print from "../../federated/DistributedDoublePort.lf" federated reactor DistributedDoublePortContainerized at rti { - c = new Count() - cm = new CountMicrostep() - p = new Print() - c.out -> p.in_ # Indicating a 'logical' connection. - cm.out -> p.in2 + c = new Count() + cm = new CountMicrostep() + p = new Print() + c.out -> p.in_ # Indicating a 'logical' connection. + cm.out -> p.in2 } diff --git a/test/Python/src/docker/federated/DistributedMultiportContainerized.lf b/test/Python/src/docker/federated/DistributedMultiportContainerized.lf index f0c9870bd6..b4333d8c00 100644 --- a/test/Python/src/docker/federated/DistributedMultiportContainerized.lf +++ b/test/Python/src/docker/federated/DistributedMultiportContainerized.lf @@ -1,14 +1,14 @@ # Check multiport connections between federates. target Python { - timeout: 1 sec, - coordination: centralized, - docker: true + timeout: 1 sec, + coordination: centralized, + docker: true } import Source, Destination from "../../federated/DistributedMultiport.lf" federated reactor DistributedMultiportContainerized at rti { - s = new Source() - d = new Destination() - s.out -> d.in_ + s = new Source() + d = new Destination() + s.out -> d.in_ } diff --git a/test/Python/src/docker/federated/DistributedSendClassContainerized.lf b/test/Python/src/docker/federated/DistributedSendClassContainerized.lf index 5f6ccd66dd..797a017146 100644 --- a/test/Python/src/docker/federated/DistributedSendClassContainerized.lf +++ b/test/Python/src/docker/federated/DistributedSendClassContainerized.lf @@ -1,12 +1,12 @@ target Python { - coordination: centralized, - docker: true + coordination: centralized, + docker: true } import A, B from "../../federated/DistributedSendClass.lf" federated reactor at rti { - a = new A() - b = new B() - b.o -> a.o + a = new A() + b = new B() + b.o -> a.o } diff --git a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf index 11e24746cd..911f0f3055 100644 --- a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -5,14 +5,14 @@ * @author Soroush Bateni */ target Python { - coordination: decentralized, - docker: true + coordination: decentralized, + docker: true } import Sender, Receiver from "../../federated/DistributedStop.lf" federated reactor DistributedStopDecentralizedContainerized at rti { - sender = new Sender() - receiver = new Receiver() - sender.out -> receiver.in_ + sender = new Sender() + receiver = new Receiver() + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/BroadcastFeedback.lf b/test/Python/src/federated/BroadcastFeedback.lf index 06fcd95037..75d313e61d 100644 --- a/test/Python/src/federated/BroadcastFeedback.lf +++ b/test/Python/src/federated/BroadcastFeedback.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target Python { timeout: 1 sec } diff --git a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf index d3e371b037..ad2a11c10c 100644 --- a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target Python { timeout: 1 sec } diff --git a/test/Python/src/federated/ChainWithDelay.lf b/test/Python/src/federated/ChainWithDelay.lf index b8fb6208a9..8199b0b319 100644 --- a/test/Python/src/federated/ChainWithDelay.lf +++ b/test/Python/src/federated/ChainWithDelay.lf @@ -4,7 +4,7 @@ * @author Edward A. Lee */ target Python { - timeout: 3 msec + timeout: 3 msec } import Count from "../lib/Count.lf" @@ -12,9 +12,9 @@ import InternalDelay from "../lib/InternalDelay.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - c = new Count(period = 1 msec) - i = new InternalDelay(delay = 500 usec) - t = new TestCount(num_inputs = 3) - c.out -> i.in_ - i.out -> t.in_ + c = new Count(period = 1 msec) + i = new InternalDelay(delay = 500 usec) + t = new TestCount(num_inputs = 3) + c.out -> i.in_ + i.out -> t.in_ } diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index 5039f3f375..cf9b6d6b54 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -1,6 +1,6 @@ /** - * Check whether the internally generated network and control reactions introduce a cycle or not. - * The failure for this test is not being compiled. + * Check whether the internally generated network and control reactions + * introduce a cycle or not. The failure for this test is not being compiled. * @author Edward A. Lee */ target Python diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf index a56a8f07ba..48ff7a4ca7 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -1,7 +1,8 @@ /** - * Test a source-destination scenario where the source falls behind real-time, and reaches the - * timeout much later than the destination. In this test, the destination closes the connection - * early, causing the transmission to fail. Warnings will be printed about lost messages. + * Test a source-destination scenario where the source falls behind real-time, + * and reaches the timeout much later than the destination. In this test, the + * destination closes the connection early, causing the transmission to fail. + * Warnings will be printed about lost messages. * * The test fails if the federation does not exit. */ diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index d065783f5a..4eb881694f 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -1,10 +1,11 @@ /** - * Test a source-destination scenario where the source falls behind real-time, and reaches the - * timeout much later than the destination. In this test, the destination closes the connection - * early, causing the transmission to fail. Warnings will be printed. + * Test a source-destination scenario where the source falls behind real-time, + * and reaches the timeout much later than the destination. In this test, the + * destination closes the connection early, causing the transmission to fail. + * Warnings will be printed. * - * The test fails if the federation does not exit amenably. This variant has a physical connection - * between source and destination. + * The test fails if the federation does not exit amenably. This variant has a + * physical connection between source and destination. */ target Python { timeout: 1 msec, diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index 6492c4fa32..7713256520 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python { diff --git a/test/Python/src/federated/DistributedCountDecentralized.lf b/test/Python/src/federated/DistributedCountDecentralized.lf index 92cae03850..e86adf9946 100644 --- a/test/Python/src/federated/DistributedCountDecentralized.lf +++ b/test/Python/src/federated/DistributedCountDecentralized.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ # reason for failing: in_.intended_tag are not supported in python target @@ -40,5 +41,6 @@ reactor Print { federated reactor DistributedCountDecentralized { c = new Count() p = new Print() - c.out -> p.in_ after 200 msec # Indicating a 'logical' connection with a large enough delay. + # Indicating a 'logical' connection with a large enough delay. + c.out -> p.in_ after 200 msec } diff --git a/test/Python/src/federated/DistributedCountPhysical.lf b/test/Python/src/federated/DistributedCountPhysical.lf index c6ef7e2425..69bc2faee9 100644 --- a/test/Python/src/federated/DistributedCountPhysical.lf +++ b/test/Python/src/federated/DistributedCountPhysical.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages only over connections that are marked 'physical' (using the ~> - * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is - * needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages only over connections that are + * marked 'physical' (using the ~> arrow). Therefore, no additional coordination + * of the advancement of time (HLA or Ptides) is needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf index 065cfa83c4..105413d0a0 100644 --- a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages only over connections that are marked 'physical' (using the ~> - * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is - * needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages only over connections that are + * marked 'physical' (using the ~> arrow). Therefore, no additional coordination + * of the advancement of time (HLA or Ptides) is needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf index 1b73f7e8e6..0008479138 100644 --- a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,8 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages only over connections that are marked 'physical' (using the ~> - * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is - * needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages only over connections that are + * marked 'physical' (using the ~> arrow). Therefore, no additional coordination + * of the advancement of time (HLA or Ptides) is needed. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedDoublePort.lf b/test/Python/src/federated/DistributedDoublePort.lf index fe0a71dcc1..9eb24209e6 100644 --- a/test/Python/src/federated/DistributedDoublePort.lf +++ b/test/Python/src/federated/DistributedDoublePort.lf @@ -1,6 +1,7 @@ /** - * Test the case for when two upstream federates send messages to a downstream federte on two - * different ports. One message should carry a microstep delay relative to the other message. + * Test the case for when two upstream federates send messages to a downstream + * federte on two different ports. One message should carry a microstep delay + * relative to the other message. * * @author Soroush Bateni */ @@ -39,7 +40,9 @@ reactor Print { self.sys.exit(1) =} - reaction(shutdown) {= print("SUCCESS: messages were at least one microstep apart.") =} + reaction(shutdown) {= + print("SUCCESS: messages were at least one microstep apart.") + =} } federated reactor DistributedDoublePort { diff --git a/test/Python/src/federated/DistributedLoopedAction.lf b/test/Python/src/federated/DistributedLoopedAction.lf index a7564d5b28..8f71d15363 100644 --- a/test/Python/src/federated/DistributedLoopedAction.lf +++ b/test/Python/src/federated/DistributedLoopedAction.lf @@ -1,5 +1,6 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken into account. + * Test a sender-receiver network system that relies on microsteps being taken + * into account. * * @author Soroush Bateni */ @@ -17,7 +18,8 @@ reactor Receiver(take_a_break_after = 10, break_interval = 400 msec) { state breaks = 0 timer t(0, 1 msec) # This will impact the performance - # but forces the logical time to advance Comment this line for a more sensible log output. + # but forces the logical time to advance Comment this line for a more + # sensible log output. reaction(in_) {= print("At tag ({}, {}) received value {}.".format( lf.time.logical_elapsed(), diff --git a/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf b/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf index 0cf1b5d22e..773d483004 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf @@ -4,15 +4,15 @@ * @author Soroush Bateni */ target Python { - timeout: 1 sec, - coordination: decentralized + timeout: 1 sec, + coordination: decentralized } import Sender, Receiver from "DistributedLoopedPhysicalAction.lf" federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in_ + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/DistributedMultiportToken.lf b/test/Python/src/federated/DistributedMultiportToken.lf index 974f6f62fa..284e1c21a3 100644 --- a/test/Python/src/federated/DistributedMultiportToken.lf +++ b/test/Python/src/federated/DistributedMultiportToken.lf @@ -1,5 +1,5 @@ -# Check multiport connections between federates where the message is carried by a Token (in this -# case, with an array of char). +# Check multiport connections between federates where the message is carried by +# a Token (in this case, with an array of char). target Python { timeout: 1 sec, coordination: centralized diff --git a/test/Python/src/federated/DistributedNoReact.lf b/test/Python/src/federated/DistributedNoReact.lf index d5692a6cec..39f51b609a 100644 --- a/test/Python/src/federated/DistributedNoReact.lf +++ b/test/Python/src/federated/DistributedNoReact.lf @@ -1,25 +1,25 @@ target Python { - timeout: 2 sec + timeout: 2 sec } preamble {= - class C: - def __init__(self): - pass + class C: + def __init__(self): + pass =} reactor A { - input o + input o } reactor B { - output o + output o - reaction(startup) -> o {= o.set(C()) =} + reaction(startup) -> o {= o.set(C()) =} } federated reactor { - a = new A() - b = new B() - b.o -> a.o + a = new A() + b = new B() + b.o -> a.o } diff --git a/test/Python/src/federated/DistributedStopDecentralized.lf b/test/Python/src/federated/DistributedStopDecentralized.lf index e6afa6384b..d76154f487 100644 --- a/test/Python/src/federated/DistributedStopDecentralized.lf +++ b/test/Python/src/federated/DistributedStopDecentralized.lf @@ -7,14 +7,14 @@ # reason for failing: lf_tag().microstep and lf.tag_compare() are not not # supported in python target target Python { - coordination: decentralized + coordination: decentralized } import Sender, Receiver from "DistributedStop.lf" federated reactor DistributedStopDecentralized { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in_ + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/DistributedStructAsType.lf b/test/Python/src/federated/DistributedStructAsType.lf index eeebf1b7e7..36a3151289 100644 --- a/test/Python/src/federated/DistributedStructAsType.lf +++ b/test/Python/src/federated/DistributedStructAsType.lf @@ -1,6 +1,6 @@ target Python { - files: ../include/hello.py, - timeout: 2 secs + files: ../include/hello.py, + timeout: 2 secs } import Source, Print from "../StructAsType.lf" @@ -8,7 +8,7 @@ import Source, Print from "../StructAsType.lf" preamble {= import hello =} federated reactor { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/federated/DistributedStructAsTypeDirect.lf b/test/Python/src/federated/DistributedStructAsTypeDirect.lf index abb1d936ce..b74ba275b5 100644 --- a/test/Python/src/federated/DistributedStructAsTypeDirect.lf +++ b/test/Python/src/federated/DistributedStructAsTypeDirect.lf @@ -1,6 +1,6 @@ target Python { - files: ../include/hello.py, - timeout: 2 secs + files: ../include/hello.py, + timeout: 2 secs } import Source, Print from "../StructAsTypeDirect.lf" @@ -8,7 +8,7 @@ import Source, Print from "../StructAsTypeDirect.lf" preamble {= import hello =} federated reactor { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/federated/DistributedStructParallel.lf b/test/Python/src/federated/DistributedStructParallel.lf index 34a2f84e32..332f315bec 100644 --- a/test/Python/src/federated/DistributedStructParallel.lf +++ b/test/Python/src/federated/DistributedStructParallel.lf @@ -1,8 +1,8 @@ # Source allocates a class object and then sends it to two reactors, each of which want to modify # it. target Python { - files: ["../include/hello.py"], - timeout: 2 secs + files: ["../include/hello.py"], + timeout: 2 secs } import Source from "../StructScale.lf" @@ -11,13 +11,13 @@ import Check, Print from "../StructParallel.lf" preamble {= import hello =} federated reactor { - s = new Source() - c1 = new Print() - c2 = new Print(scale = 3) - p1 = new Check(expected = 84) - p2 = new Check(expected = 126) - s.out -> c1._in - s.out -> c2._in - c1.out -> p1._in - c2.out -> p2._in + s = new Source() + c1 = new Print() + c2 = new Print(scale = 3) + p1 = new Check(expected = 84) + p2 = new Check(expected = 126) + s.out -> c1._in + s.out -> c2._in + c1.out -> p1._in + c2.out -> p2._in } diff --git a/test/Python/src/federated/DistributedStructPrint.lf b/test/Python/src/federated/DistributedStructPrint.lf index b424dabacf..829b298b28 100644 --- a/test/Python/src/federated/DistributedStructPrint.lf +++ b/test/Python/src/federated/DistributedStructPrint.lf @@ -1,8 +1,8 @@ # Source produces a dynamically allocated class object, which it passes to Print. Reference counting # ensures that the struct is freed. target Python { - files: ["../include/hello.py"], - timeout: 2 sec + files: ["../include/hello.py"], + timeout: 2 sec } import Print, Check from "../StructPrint.lf" @@ -10,7 +10,7 @@ import Print, Check from "../StructPrint.lf" preamble {= import hello =} federated reactor { - s = new Print() - p = new Check() - s.out -> p._in + s = new Print() + p = new Check() + s.out -> p._in } diff --git a/test/Python/src/federated/DistributedStructScale.lf b/test/Python/src/federated/DistributedStructScale.lf index 88867178f0..5156de1644 100644 --- a/test/Python/src/federated/DistributedStructScale.lf +++ b/test/Python/src/federated/DistributedStructScale.lf @@ -1,8 +1,8 @@ # Source produces a dynamically allocated class object, which it passes to Scale. Scale modifies it # and passes it to Print. target Python { - files: ["../include/hello.py"], - timeout: 2 sec + files: ["../include/hello.py"], + timeout: 2 sec } import Source, TestInput, Print from "../StructScale.lf" @@ -10,9 +10,9 @@ import Source, TestInput, Print from "../StructScale.lf" preamble {= import hello =} federated reactor { - s = new Source() - c = new Print() - p = new TestInput(expected = 84) - s.out -> c._in - c.out -> p._in + s = new Source() + c = new Print() + p = new TestInput(expected = 84) + s.out -> c._in + c.out -> p._in } diff --git a/test/Python/src/federated/HelloDistributed.lf b/test/Python/src/federated/HelloDistributed.lf index a56bef1062..ef99c3f793 100644 --- a/test/Python/src/federated/HelloDistributed.lf +++ b/test/Python/src/federated/HelloDistributed.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python @@ -39,7 +40,8 @@ reactor Destination { } federated reactor HelloDistributed at localhost { - # reaction(startup) {= print("Printing something in top-level federated reactor.") + # reaction(startup) {= print("Printing something in top-level federated + # reactor.") # =} Reactor s is in federate Source s = new Source() d = new Destination() # Reactor d is in federate Destination diff --git a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index d61fcc9100..2719fd57ba 100644 --- a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,6 +1,7 @@ /** - * This tests that the precedence order of reaction invocation is kept in the hierarchy of reactors - * when a feedback loop is present in centralized coordination. + * This tests that the precedence order of reaction invocation is kept in the + * hierarchy of reactors when a feedback loop is present in centralized + * coordination. * * @author Edward A. Lee * @author Soroush Bateni diff --git a/test/Python/src/federated/ParallelDestinations.lf b/test/Python/src/federated/ParallelDestinations.lf index d7e4dcd6fe..4c65ba4351 100644 --- a/test/Python/src/federated/ParallelDestinations.lf +++ b/test/Python/src/federated/ParallelDestinations.lf @@ -1,23 +1,23 @@ /** Test parallel connections for federated execution. */ target Python { - timeout: 2 sec + timeout: 2 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Source { - output[2] out - c1 = new Count() - c2 = new Count() + output[2] out + c1 = new Count() + c2 = new Count() - c1.out, c2.out -> out + c1.out, c2.out -> out } federated reactor { - s = new Source() - t1 = new TestCount(num_inputs = 3) - t2 = new TestCount(num_inputs = 3) + s = new Source() + t1 = new TestCount(num_inputs = 3) + t2 = new TestCount(num_inputs = 3) - s.out -> t1.in_, t2.in_ + s.out -> t1.in_, t2.in_ } diff --git a/test/Python/src/federated/ParallelSources.lf b/test/Python/src/federated/ParallelSources.lf index d4cf67ebe8..222cb6dab1 100644 --- a/test/Python/src/federated/ParallelSources.lf +++ b/test/Python/src/federated/ParallelSources.lf @@ -1,24 +1,24 @@ /** Test parallel connections for federated execution. */ target Python { - timeout: 2 sec + timeout: 2 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Destination { - input[2] in_ + input[2] in_ - t1 = new TestCount(num_inputs = 3) - t2 = new TestCount(num_inputs = 3) + t1 = new TestCount(num_inputs = 3) + t2 = new TestCount(num_inputs = 3) - in_ -> t1.in_, t2.in_ + in_ -> t1.in_, t2.in_ } federated reactor { - c1 = new Count() - c2 = new Count() - d = new Destination() + c1 = new Count() + c2 = new Count() + d = new Destination() - c1.out, c2.out -> d.in_ + c1.out, c2.out -> d.in_ } diff --git a/test/Python/src/federated/ParallelSourcesMultiport.lf b/test/Python/src/federated/ParallelSourcesMultiport.lf index f19b33281c..553b1f95ee 100644 --- a/test/Python/src/federated/ParallelSourcesMultiport.lf +++ b/test/Python/src/federated/ParallelSourcesMultiport.lf @@ -1,34 +1,34 @@ /** Test parallel connections for federated execution. */ target Python { - timeout: 2 sec + timeout: 2 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Source { - output[2] out - c1 = new Count() - c2 = new Count() + output[2] out + c1 = new Count() + c2 = new Count() - c1.out, c2.out -> out + c1.out, c2.out -> out } reactor Destination1 { - input[3] in_ + input[3] in_ - t1 = new TestCount(num_inputs = 3) - t2 = new TestCount(num_inputs = 3) - t3 = new TestCount(num_inputs = 3) + t1 = new TestCount(num_inputs = 3) + t2 = new TestCount(num_inputs = 3) + t3 = new TestCount(num_inputs = 3) - in_ -> t1.in_, t2.in_, t3.in_ + in_ -> t1.in_, t2.in_, t3.in_ } federated reactor { - s1 = new Source() - s2 = new Source() - d1 = new Destination1() - t4 = new TestCount(num_inputs = 3) + s1 = new Source() + s2 = new Source() + d1 = new Destination1() + t4 = new TestCount(num_inputs = 3) - s1.out, s2.out -> d1.in_, t4.in_ + s1.out, s2.out -> d1.in_, t4.in_ } diff --git a/test/Python/src/federated/PhysicalSTP.lf b/test/Python/src/federated/PhysicalSTP.lf index 50ee659eb3..5edc61df34 100644 --- a/test/Python/src/federated/PhysicalSTP.lf +++ b/test/Python/src/federated/PhysicalSTP.lf @@ -1,4 +1,7 @@ -/** This is a test that detects STP violations according to the physical time of message arrival. */ +/** + * This is a test that detects STP violations according to the physical time of + * message arrival. + */ target Python { timeout: 1900 msec, coordination: decentralized diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index 0fc7cf3353..0f58cbf7db 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -1,19 +1,21 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. This is based on https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure + * message-passing overhead. This is based on + * https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs and can be run on - * different machines. + * This is a distributed version, where Ping and Pong run in separate programs + * and can be run on different machines. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec Distributed: 53 seconds * - * There is no parallelism in this application, so it does not benefit from being being distributed. + * There is no parallelism in this application, so it does not benefit from + * being being distributed. * - * These measurements are total execution time, including startup and shutdown, of all three - * programs. + * These measurements are total execution time, including startup and shutdown, + * of all three programs. * * @author Edward A. Lee */ diff --git a/test/Python/src/lib/Imported.lf b/test/Python/src/lib/Imported.lf index f59f1e9dee..e23b300991 100644 --- a/test/Python/src/lib/Imported.lf +++ b/test/Python/src/lib/Imported.lf @@ -5,8 +5,8 @@ target Python import ImportedAgain from "./ImportedAgain.lf" reactor Imported { - input x - a = new ImportedAgain() + input x + a = new ImportedAgain() - reaction(x) -> a.x {= a.x.set(x.value) =} + reaction(x) -> a.x {= a.x.set(x.value) =} } diff --git a/test/Python/src/lib/ImportedAgain.lf b/test/Python/src/lib/ImportedAgain.lf index f29a5e6c83..9371712337 100644 --- a/test/Python/src/lib/ImportedAgain.lf +++ b/test/Python/src/lib/ImportedAgain.lf @@ -3,12 +3,12 @@ target Python reactor ImportedAgain { # import Imported from "Imported.lf" - input x # y = new Imported(); // FIXME: Address this bug + input x # y = new Imported(); // FIXME: Address this bug - reaction(x) {= - print("Received: " + str(x.value)) - if (x.value != 42): - print("ERROR: Expected input to be 42. Got: " + x.value) - exit(1) - =} + reaction(x) {= + print("Received: " + str(x.value)) + if (x.value != 42): + print("ERROR: Expected input to be 42. Got: " + x.value) + exit(1) + =} } diff --git a/test/Python/src/lib/ImportedComposition.lf b/test/Python/src/lib/ImportedComposition.lf index be1cdfb1a8..5eeb39420f 100644 --- a/test/Python/src/lib/ImportedComposition.lf +++ b/test/Python/src/lib/ImportedComposition.lf @@ -3,18 +3,18 @@ target Python reactor Gain { - input x - output y + input x + output y - reaction(x) -> y {= y.set(x.value * 2) =} + reaction(x) -> y {= y.set(x.value * 2) =} } reactor ImportedComposition { - input x - output y - g1 = new Gain() - g2 = new Gain() - x -> g1.x after 10 msec - g1.y -> g2.x after 30 msec - g2.y -> y after 15 msec + input x + output y + g1 = new Gain() + g2 = new Gain() + x -> g1.x after 10 msec + g1.y -> g2.x after 30 msec + g2.y -> y after 15 msec } diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index 674256ea45..9d4048d0ea 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -6,9 +6,10 @@ target Python /** - * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break after sending - * take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in + * consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break + * after sending take_a_break_after messages. */ reactor Sender(take_a_break_after = 10, break_interval = 400 msec) { output out diff --git a/test/Python/src/lib/TestCount.lf b/test/Python/src/lib/TestCount.lf index eb214fe25d..de611cbc69 100644 --- a/test/Python/src/lib/TestCount.lf +++ b/test/Python/src/lib/TestCount.lf @@ -1,6 +1,7 @@ /** - * Test that a counting sequence of inputs starts with the specified start parameter value, - * increments by the specified stride, and receives the specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start + * parameter value, increments by the specified stride, and receives the + * specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. diff --git a/test/Python/src/lib/TestCountMultiport.lf b/test/Python/src/lib/TestCountMultiport.lf index d584401bfa..c30572e4d5 100644 --- a/test/Python/src/lib/TestCountMultiport.lf +++ b/test/Python/src/lib/TestCountMultiport.lf @@ -1,12 +1,13 @@ /** - * Test that a counting sequence of inputs starts with the specified start parameter value, - * increments by the specified stride, and receives the specified number of inputs. This version has - * a multiport input, and each input is expected to be present and incremented over the previous - * input. + * Test that a counting sequence of inputs starts with the specified start + * parameter value, increments by the specified stride, and receives the + * specified number of inputs. This version has a multiport input, and each + * input is expected to be present and incremented over the previous input. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. - * @param num_inputs The number of inputs expected on each channel. Default is 1. + * @param num_inputs The number of inputs expected on each channel. Default is + * 1. */ target Python diff --git a/test/Python/src/modal_models/BanksCount3ModesSimple.lf b/test/Python/src/modal_models/BanksCount3ModesSimple.lf index a2142d2e36..f36a82178a 100644 --- a/test/Python/src/modal_models/BanksCount3ModesSimple.lf +++ b/test/Python/src/modal_models/BanksCount3ModesSimple.lf @@ -1,31 +1,31 @@ /** Modal Reactor Test. Tests cycling through modes with banks of reactors. */ target Python { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } import TraceTesting from "util/TraceTesting.lf" import CounterCycle from "Count3Modes.lf" main reactor { - timer stepper(0, 250 msec) - counters = new[3] CounterCycle() - test = new TraceTesting(events_size = 3, trace = ( // keep-format - 0,1,1,1,1,1,1, - 250000000,1,2,1,2,1,2, - 250000000,1,3,1,3,1,3, - 250000000,1,1,1,1,1,1, - 250000000,1,2,1,2,1,2, - 250000000,1,3,1,3,1,3, - 250000000,1,1,1,1,1,1, - 250000000,1,2,1,2,1,2, - 250000000,1,3,1,3,1,3 - ), training = False) + timer stepper(0, 250 msec) + counters = new[3] CounterCycle() + test = new TraceTesting(events_size = 3, trace = ( // keep-format + 0,1,1,1,1,1,1, + 250000000,1,2,1,2,1,2, + 250000000,1,3,1,3,1,3, + 250000000,1,1,1,1,1,1, + 250000000,1,2,1,2,1,2, + 250000000,1,3,1,3,1,3, + 250000000,1,1,1,1,1,1, + 250000000,1,2,1,2,1,2, + 250000000,1,3,1,3,1,3 + ), training = False) - counters.count -> test.events + counters.count -> test.events - reaction(stepper) -> counters.next {= # Trigger - for counter in counters: - counter.next.set(True) - =} + reaction(stepper) -> counters.next {= # Trigger + for counter in counters: + counter.next.set(True) + =} } diff --git a/test/Python/src/modal_models/BanksModalStateReset.lf b/test/Python/src/modal_models/BanksModalStateReset.lf index 00a1a7ca4f..f96a7bd638 100644 --- a/test/Python/src/modal_models/BanksModalStateReset.lf +++ b/test/Python/src/modal_models/BanksModalStateReset.lf @@ -1,4 +1,7 @@ -/** Modal Reactor Test. Tests reset of state variables in modes with banks of reactors. */ +/** + * Modal Reactor Test. Tests reset of state variables in modes with banks of + * reactors. + */ target Python { fast: false, timeout: 4 sec @@ -45,7 +48,8 @@ main reactor { reset2.count2 -> test.events - reaction(stepper) -> reset1.next {= # Trigger mode change (separately because of #1278) + # Trigger mode change (separately because of #1278) + reaction(stepper) -> reset1.next {= for i in range(len(reset1)): reset1[i].next.set(True) =} diff --git a/test/Python/src/modal_models/ConvertCaseTest.lf b/test/Python/src/modal_models/ConvertCaseTest.lf index 3f31a7100b..f3bdee59fe 100644 --- a/test/Python/src/modal_models/ConvertCaseTest.lf +++ b/test/Python/src/modal_models/ConvertCaseTest.lf @@ -113,7 +113,9 @@ main reactor { history_processor.discard.set(True) =} - reaction(reset_processor.converted) {= print(f"Reset: {reset_processor.converted.value}") =} + reaction(reset_processor.converted) {= + print(f"Reset: {reset_processor.converted.value}") + =} reaction(history_processor.converted) {= print(f"History: {history_processor.converted.value}") diff --git a/test/Python/src/modal_models/ModalActions.lf b/test/Python/src/modal_models/ModalActions.lf index 2d148e89ef..b74f92f3c9 100644 --- a/test/Python/src/modal_models/ModalActions.lf +++ b/test/Python/src/modal_models/ModalActions.lf @@ -1,6 +1,6 @@ /** - * Modal Reactor Test. Tests actions, their suspension during mode inactivity and continuation of - * delays with history transitions. + * Modal Reactor Test. Tests actions, their suspension during mode inactivity + * and continuation of delays with history transitions. */ target Python { fast: false, @@ -90,5 +90,6 @@ main reactor { modal.action2_exec -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} } diff --git a/test/Python/src/modal_models/ModalCycleBreaker.lf b/test/Python/src/modal_models/ModalCycleBreaker.lf index d3af61d142..1ceb2eb5d0 100644 --- a/test/Python/src/modal_models/ModalCycleBreaker.lf +++ b/test/Python/src/modal_models/ModalCycleBreaker.lf @@ -1,8 +1,8 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work if they are located - * in separate modes. + * Tests if connections in the same reactor that have the same destination work + * if they are located in separate modes. */ target Python { fast: false, @@ -16,7 +16,9 @@ reactor Modal { input in2 output out - mode Two { # Defining reaction to in2 before in1 would cause cycle if no mode were present + # Defining reaction to in2 before in1 would cause cycle if no mode were + # present + mode Two { timer wait(150 msec, 1 sec) reaction(in2) {= =} diff --git a/test/Python/src/modal_models/ModalNestedReactions.lf b/test/Python/src/modal_models/ModalNestedReactions.lf index 67247ac12f..2a9dc780f0 100644 --- a/test/Python/src/modal_models/ModalNestedReactions.lf +++ b/test/Python/src/modal_models/ModalNestedReactions.lf @@ -1,67 +1,67 @@ /** Modal Reactor Test. Checks disabling of reactions indirectly nested in an inactive mode */ target Python { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } reactor CounterCycle { - input next + input next - output count - output only_in_two - output never + output count + output only_in_two + output never - initial mode One { - reaction(next) -> count, reset(Two) {= - count.set(1) - Two.set() - =} - } + initial mode One { + reaction(next) -> count, reset(Two) {= + count.set(1) + Two.set() + =} + } - mode Two { - fwd = new Forward() - next -> fwd.inp - fwd.out -> only_in_two - reaction(next) -> count, reset(One) {= - count.set(2) - One.set() - =} - } + mode Two { + fwd = new Forward() + next -> fwd.inp + fwd.out -> only_in_two + reaction(next) -> count, reset(One) {= + count.set(2) + One.set() + =} + } - mode Three { - reaction(next) -> never {= never.set(True) =} - } + mode Three { + reaction(next) -> never {= never.set(True) =} + } } reactor Forward { - input inp - output out + input inp + output out - reaction(inp) -> out {= out.set(inp.value) =} + reaction(inp) -> out {= out.set(inp.value) =} } main reactor { - timer stepper(0, 250 msec) - counter = new CounterCycle() + timer stepper(0, 250 msec) + counter = new CounterCycle() - reaction(stepper) -> counter.next {= counter.next.set(True) =} # Trigger + reaction(stepper) -> counter.next {= counter.next.set(True) =} # Trigger - reaction(stepper) counter.count, counter.only_in_two {= # Check - print(counter.count.value) + reaction(stepper) counter.count, counter.only_in_two {= # Check + print(counter.count.value) - if counter.count.is_present is not True: - sys.stderr.write("ERROR: Missing mode change.\n") - exit(1) - elif counter.only_in_two.is_present and (counter.count.value != 2): - sys.stderr.write("ERROR: Indirectly nested reaction was not properly deactivated.\n") - exit(2) - elif counter.only_in_two.is_present is not True and (counter.count.value == 2): - sys.stderr.write("ERROR: Missing output from indirectly nested reaction.\n") - exit(3) - =} + if counter.count.is_present is not True: + sys.stderr.write("ERROR: Missing mode change.\n") + exit(1) + elif counter.only_in_two.is_present and (counter.count.value != 2): + sys.stderr.write("ERROR: Indirectly nested reaction was not properly deactivated.\n") + exit(2) + elif counter.only_in_two.is_present is not True and (counter.count.value == 2): + sys.stderr.write("ERROR: Missing output from indirectly nested reaction.\n") + exit(3) + =} - reaction(counter.never) {= - sys.stderr.write("ERROR: Detected output from unreachable mode.\n") - exit(4) - =} + reaction(counter.never) {= + sys.stderr.write("ERROR: Detected output from unreachable mode.\n") + exit(4) + =} } diff --git a/test/Python/src/modal_models/ModalStartupShutdown.lf b/test/Python/src/modal_models/ModalStartupShutdown.lf index ba8439e276..c7a868eeca 100644 --- a/test/Python/src/modal_models/ModalStartupShutdown.lf +++ b/test/Python/src/modal_models/ModalStartupShutdown.lf @@ -137,5 +137,6 @@ main reactor { modal.shutdown5 -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} } diff --git a/test/Python/src/modal_models/ModalStateReset.lf b/test/Python/src/modal_models/ModalStateReset.lf index d52161cede..11b7425b63 100644 --- a/test/Python/src/modal_models/ModalStateReset.lf +++ b/test/Python/src/modal_models/ModalStateReset.lf @@ -87,5 +87,6 @@ main reactor { modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} } diff --git a/test/Python/src/modal_models/ModalStateResetAuto.lf b/test/Python/src/modal_models/ModalStateResetAuto.lf index a8348592a5..492e12259b 100644 --- a/test/Python/src/modal_models/ModalStateResetAuto.lf +++ b/test/Python/src/modal_models/ModalStateResetAuto.lf @@ -83,5 +83,6 @@ main reactor { modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} } diff --git a/test/Python/src/modal_models/ModalTimers.lf b/test/Python/src/modal_models/ModalTimers.lf index 8198e5dcb1..271a19ec38 100644 --- a/test/Python/src/modal_models/ModalTimers.lf +++ b/test/Python/src/modal_models/ModalTimers.lf @@ -62,5 +62,6 @@ main reactor { modal.mode_switch, modal.timer1, modal.timer2 -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} } diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index 274d97a9f7..3dd42f67ce 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -1,8 +1,8 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work if they are located - * in separate modes. + * Tests if connections in the same reactor that have the same destination work + * if they are located in separate modes. */ target Python { fast: false, @@ -66,7 +66,9 @@ main reactor { modal.count -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} - reaction(modal.count) {= print(modal.count.value) =} # Print + # Print + reaction(modal.count) {= print(modal.count.value) =} } diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index bda602904e..86f5668357 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -1,8 +1,8 @@ /** * Modal Reactor Test. * - * Tests if a connection and a reaction in the same reactor can have the same destination if they - * are located in separate modes. + * Tests if a connection and a reaction in the same reactor can have the same + * destination if they are located in separate modes. */ target Python { fast: false, @@ -23,7 +23,9 @@ reactor Modal { mode Two { counter2 = new Counter(period = 100 msec) - reaction(counter2.value) -> count {= count.set(counter2.value.value * 10) =} + reaction(counter2.value) -> count {= + count.set(counter2.value.value * 10) + =} reaction(next) -> history(One) {= One.set() =} } @@ -67,7 +69,9 @@ main reactor { modal.count -> test.events - reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change + # Trigger mode change + reaction(stepper) -> modal.next {= modal.next.set(True) =} - reaction(modal.count) {= print(modal.count.value) =} # Print + # Print + reaction(modal.count) {= print(modal.count.value) =} } diff --git a/test/Python/src/multiport/BankReactionsInContainer.lf b/test/Python/src/multiport/BankReactionsInContainer.lf index c4eabf8d19..7316463c3d 100644 --- a/test/Python/src/multiport/BankReactionsInContainer.lf +++ b/test/Python/src/multiport/BankReactionsInContainer.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target Python { timeout: 1 sec } diff --git a/test/Python/src/multiport/BroadcastAfter.lf b/test/Python/src/multiport/BroadcastAfter.lf index a2e1e2e6ef..21cbf4d885 100644 --- a/test/Python/src/multiport/BroadcastAfter.lf +++ b/test/Python/src/multiport/BroadcastAfter.lf @@ -1,12 +1,12 @@ target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source, Destination from "Broadcast.lf" main reactor { - a = new Source() - b = new[4] Destination(delay = 1 sec) - (a.out)+ -> b._in after 1 sec + a = new Source() + b = new[4] Destination(delay = 1 sec) + (a.out)+ -> b._in after 1 sec } diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 092458f76d..92d9363df5 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -# sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than +# the width of the sending port. target Python { timeout: 2 sec, fast: true @@ -8,7 +8,9 @@ target Python { reactor Source(check_override = 0, bank_index = 0) { output out - reaction(startup) -> out {= out.set(self.bank_index * self.check_override) =} + reaction(startup) -> out {= + out.set(self.bank_index * self.check_override) + =} } reactor Destination { diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index 13cf078224..27ecb3c80b 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -# sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than +# the width of the sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf index 2466b78574..d23f294dde 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,15 +1,15 @@ # Check multiport output to bank of recipients. Here, the bank is smaller than the width of the # sending port. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Container from "MultiportFromBankHierarchy.lf" import Destination from "MultiportFromBank.lf" main reactor MultiportFromBankHierarchyAfter { - a = new Container() - b = new Destination() - a.out -> b._in after 1 sec + a = new Container() + b = new Destination() + a.out -> b._in after 1 sec } diff --git a/test/Python/src/multiport/MultiportFromHierarchy.lf b/test/Python/src/multiport/MultiportFromHierarchy.lf index 83cdcad88a..4116587f01 100644 --- a/test/Python/src/multiport/MultiportFromHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromHierarchy.lf @@ -1,4 +1,5 @@ -# Check multiport output to multiport input, where the former is a hierarchical reactor. +# Check multiport output to multiport input, where the former is a hierarchical +# reactor. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportIn.lf b/test/Python/src/multiport/MultiportIn.lf index feb5ef6d03..35bdee7341 100644 --- a/test/Python/src/multiport/MultiportIn.lf +++ b/test/Python/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -# This is a version fo the Threaded test that uses a multiport input at the destination. Its purpose -# is to test multiport inputs. +# This is a version fo the Threaded test that uses a multiport input at the +# destination. Its purpose is to test multiport inputs. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportInParameterized.lf b/test/Python/src/multiport/MultiportInParameterized.lf index ca10b50175..28b15808e3 100644 --- a/test/Python/src/multiport/MultiportInParameterized.lf +++ b/test/Python/src/multiport/MultiportInParameterized.lf @@ -1,5 +1,5 @@ -# This is a version of the Threaded test that uses a multiport input at the destination. Its purpose -# is to test multiport inputs. +# This is a version of the Threaded test that uses a multiport input at the +# destination. Its purpose is to test multiport inputs. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportMutableInput.lf b/test/Python/src/multiport/MultiportMutableInput.lf index e12855db04..f931900ef7 100644 --- a/test/Python/src/multiport/MultiportMutableInput.lf +++ b/test/Python/src/multiport/MultiportMutableInput.lf @@ -1,5 +1,6 @@ -# Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. -# It modifies it and passes it to Print. It gets freed after Print is done with it. +# Source produces a ints on a multiport, which it passes to Scale. Scale +# requests a writable copy. It modifies it and passes it to Print. It gets freed +# after Print is done with it. target Python reactor Source { diff --git a/test/Python/src/multiport/MultiportMutableInputArray.lf b/test/Python/src/multiport/MultiportMutableInputArray.lf index 5e37ccd6b2..9efa3eeebf 100644 --- a/test/Python/src/multiport/MultiportMutableInputArray.lf +++ b/test/Python/src/multiport/MultiportMutableInputArray.lf @@ -1,6 +1,7 @@ -# Source produces a list on a multiport, which it passes to Scale. Scale requests a writable copy, -# which, instead of copying, it just gets ownership of the original list. It modifies it and passes -# it to Print. It gets freed after Print is done with it. +# Source produces a list on a multiport, which it passes to Scale. Scale +# requests a writable copy, which, instead of copying, it just gets ownership of +# the original list. It modifies it and passes it to Print. It gets freed after +# Print is done with it. target Python reactor Source { diff --git a/test/Python/src/multiport/MultiportToBankAfter.lf b/test/Python/src/multiport/MultiportToBankAfter.lf index 6d3f6e7ed4..85fc91e513 100644 --- a/test/Python/src/multiport/MultiportToBankAfter.lf +++ b/test/Python/src/multiport/MultiportToBankAfter.lf @@ -1,4 +1,5 @@ -# Check multiport output to bank of recipients where the width of the bank is inferred. +# Check multiport output to bank of recipients where the width of the bank is +# inferred. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index bef01b8d89..f70fa8ad92 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -# sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than +# the width of the sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index 1e525b621d..2a9e25a5e6 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,6 @@ -# Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that -# the destination reactor has width wider than the sender, so one input is dangling. +# Check multiport output to multiport input, where the latter is a hierarchical +# reactor. Note that the destination reactor has width wider than the sender, so +# one input is dangling. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToMultiportArray.lf b/test/Python/src/multiport/MultiportToMultiportArray.lf index 42e885ea37..5eb043570d 100644 --- a/test/Python/src/multiport/MultiportToMultiportArray.lf +++ b/test/Python/src/multiport/MultiportToMultiportArray.lf @@ -1,4 +1,5 @@ -# Check multiport output to multiport input. Destination port is wider than sending port. +# Check multiport output to multiport input. Destination port is wider than +# sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToPort.lf b/test/Python/src/multiport/MultiportToPort.lf index 893ad600b0..ebfbf81991 100644 --- a/test/Python/src/multiport/MultiportToPort.lf +++ b/test/Python/src/multiport/MultiportToPort.lf @@ -1,4 +1,5 @@ -# Check multiport output to multiport input. Destination port is wider than sending port. +# Check multiport output to multiport input. Destination port is wider than +# sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/PipelineAfter.lf b/test/Python/src/multiport/PipelineAfter.lf index ba423299d9..43048f04ca 100644 --- a/test/Python/src/multiport/PipelineAfter.lf +++ b/test/Python/src/multiport/PipelineAfter.lf @@ -1,36 +1,36 @@ target Python reactor Source { - output out + output out - reaction(startup) -> out {= out.set(40) =} + reaction(startup) -> out {= out.set(40) =} } reactor Compute { - input inp - output out + input inp + output out - reaction(inp) -> out {= out.set(inp.value + 2) =} + reaction(inp) -> out {= out.set(inp.value + 2) =} } reactor Sink { - input inp - - reaction(inp) {= - print(f"Received {inp.value}") - if inp.value != 42: - sys.stderr.write("ERROR: expected 42!\n") - exit(1) - if lf.time.logical_elapsed() != SEC(1): - sys.stderr.write("ERROR: Expected to receive input after one second.\n") - exit(2) - =} + input inp + + reaction(inp) {= + print(f"Received {inp.value}") + if inp.value != 42: + sys.stderr.write("ERROR: expected 42!\n") + exit(1) + if lf.time.logical_elapsed() != SEC(1): + sys.stderr.write("ERROR: Expected to receive input after one second.\n") + exit(2) + =} } main reactor { - source = new Source() - compute = new Compute() - sink = new Sink() + source = new Source() + compute = new Compute() + sink = new Sink() - source.out, compute.out -> compute.inp, sink.inp after 500 msec + source.out, compute.out -> compute.inp, sink.inp after 500 msec } diff --git a/test/Python/src/multiport/ReactionsToNested.lf b/test/Python/src/multiport/ReactionsToNested.lf index 5d1046fa24..2c207dffb0 100644 --- a/test/Python/src/multiport/ReactionsToNested.lf +++ b/test/Python/src/multiport/ReactionsToNested.lf @@ -1,4 +1,5 @@ -# This test connects a simple counting source to tester that checks against its own count. +# This test connects a simple counting source to tester that checks against its +# own count. target Python { timeout: 1 sec } diff --git a/test/Python/src/serialization/PersonProtocolBuffers.lf b/test/Python/src/serialization/PersonProtocolBuffers.lf index 530df50d8d..eb14cc8f9c 100644 --- a/test/Python/src/serialization/PersonProtocolBuffers.lf +++ b/test/Python/src/serialization/PersonProtocolBuffers.lf @@ -18,25 +18,25 @@ * typically at /usr/local/bin. */ target Python { - protobufs: Person.proto + protobufs: Person.proto } main reactor { - reaction(startup) {= - person = Person.Person() + reaction(startup) {= + person = Person.Person() - person.name = "Lingua Franca" - person.id = 1 - person.email = "eal@berkeley.edu" + person.name = "Lingua Franca" + person.id = 1 + person.email = "eal@berkeley.edu" - # Pack the message into buffer. - serialized_msg = person.SerializeToString() + # Pack the message into buffer. + serialized_msg = person.SerializeToString() - # Now unpack the message from buffer. - unpacked = Person.Person() - unpacked.ParseFromString(serialized_msg) + # Now unpack the message from buffer. + unpacked = Person.Person() + unpacked.ParseFromString(serialized_msg) - # Extract and print the unpacked message. - print("Name: ", unpacked.name) - =} + # Extract and print the unpacked message. + print("Name: ", unpacked.name) + =} } diff --git a/test/Python/src/serialization/ProtoNoPacking.lf b/test/Python/src/serialization/ProtoNoPacking.lf index 92e04fd5f5..9800645687 100644 --- a/test/Python/src/serialization/ProtoNoPacking.lf +++ b/test/Python/src/serialization/ProtoNoPacking.lf @@ -17,30 +17,30 @@ * typically at /usr/local/bin. */ target Python { - protobufs: ProtoHelloWorld.proto + protobufs: ProtoHelloWorld.proto } reactor SourceProto { - output out + output out - reaction(startup) -> out {= - message = ProtoHelloWorld.ProtoHelloWorld() - message.name = "Hello World" - message.number = 42 - out.set(message) - =} + reaction(startup) -> out {= + message = ProtoHelloWorld.ProtoHelloWorld() + message.name = "Hello World" + message.number = 42 + out.set(message) + =} } reactor SinkProto { - input _in + input _in - reaction(_in) {= - print("Received: name='{:s}', number={:d}.".format(_in.value.name, _in.value.number)) - =} + reaction(_in) {= + print("Received: name='{:s}', number={:d}.".format(_in.value.name, _in.value.number)) + =} } main reactor ProtoNoPacking { - s = new SourceProto() - d = new SinkProto() - s.out -> d._in + s = new SourceProto() + d = new SinkProto() + s.out -> d._in } diff --git a/test/Python/src/target/AfterNoTypes.lf b/test/Python/src/target/AfterNoTypes.lf index fb5597e863..44aaa89c73 100644 --- a/test/Python/src/target/AfterNoTypes.lf +++ b/test/Python/src/target/AfterNoTypes.lf @@ -1,5 +1,5 @@ -# This test demonstrates that after can be used on connections with ports that have no types. The -# test passes if the compile is succeeded +# This test demonstrates that after can be used on connections with ports that +# have no types. The test passes if the compile is succeeded target Python { fast: false, timeout: 3 sec diff --git a/test/Rust/src/ActionIsPresentDouble.lf b/test/Rust/src/ActionIsPresentDouble.lf index 361378a6bc..4aec9776be 100644 --- a/test/Rust/src/ActionIsPresentDouble.lf +++ b/test/Rust/src/ActionIsPresentDouble.lf @@ -2,20 +2,20 @@ target Rust main reactor ActionIsPresentDouble { - logical action act0 - logical action act1(100 msec) + logical action act0 + logical action act1(100 msec) - reaction(startup) -> act0, act1 {= - ctx.schedule(act0, after!(100 ms)); - ctx.schedule(act1, after!(0 ms)); - ctx.schedule(act1, Asap); - =} + reaction(startup) -> act0, act1 {= + ctx.schedule(act0, after!(100 ms)); + ctx.schedule(act1, after!(0 ms)); + ctx.schedule(act1, Asap); + =} - reaction(act1, act0) {= - assert!(ctx.is_present(act0)); - assert!(ctx.is_present(act1)); - if ctx.get_tag() == tag!(T0 + 100 ms) { - println!("success"); - } - =} + reaction(act1, act0) {= + assert!(ctx.is_present(act0)); + assert!(ctx.is_present(act1)); + if ctx.get_tag() == tag!(T0 + 100 ms) { + println!("success"); + } + =} } diff --git a/test/Rust/src/ActionValuesCleanup.lf b/test/Rust/src/ActionValuesCleanup.lf index 6bda6e9fd6..f4bab7a2b5 100644 --- a/test/Rust/src/ActionValuesCleanup.lf +++ b/test/Rust/src/ActionValuesCleanup.lf @@ -22,7 +22,9 @@ main reactor ActionValuesCleanup { logical action act: FooDrop state count: u32 = 0 - reaction(startup) -> act {= ctx.schedule_with_v(act, Some(FooDrop { }), Asap) =} + reaction(startup) -> act {= + ctx.schedule_with_v(act, Some(FooDrop { }), Asap) + =} reaction(act) -> act {= ctx.use_ref(act, |v| println!("{:?}", v)); diff --git a/test/Rust/src/CompositionInitializationOrder.lf b/test/Rust/src/CompositionInitializationOrder.lf index 283923d9be..5bb11f7d9c 100644 --- a/test/Rust/src/CompositionInitializationOrder.lf +++ b/test/Rust/src/CompositionInitializationOrder.lf @@ -2,16 +2,16 @@ target Rust main reactor CompositionInitializationOrder { - c1 = new Component1() - c2 = new Component2() + c1 = new Component1() + c2 = new Component2() - reaction(startup) {= println!("parent woke up"); =} + reaction(startup) {= println!("parent woke up"); =} } reactor Component2 { - reaction(startup) {= println!("c2 woke up"); =} + reaction(startup) {= println!("c2 woke up"); =} } reactor Component1 { - reaction(startup) {= println!("c1 woke up"); =} + reaction(startup) {= println!("c1 woke up"); =} } diff --git a/test/Rust/src/DependencyOnChildPort.lf b/test/Rust/src/DependencyOnChildPort.lf index 18ad405da2..ed8b6b2120 100644 --- a/test/Rust/src/DependencyOnChildPort.lf +++ b/test/Rust/src/DependencyOnChildPort.lf @@ -18,7 +18,9 @@ main reactor { reaction(startup) -> box0.inp {= ctx.set(box0__inp, 444); =} - reaction(box1.out) {= assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; =} + reaction(box1.out) {= + assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; + =} reaction(shutdown) {= assert!(self.done, "reaction was not executed"); diff --git a/test/Rust/src/DependencyThroughChildPort.lf b/test/Rust/src/DependencyThroughChildPort.lf index 0e708cf878..851472503f 100644 --- a/test/Rust/src/DependencyThroughChildPort.lf +++ b/test/Rust/src/DependencyThroughChildPort.lf @@ -1,44 +1,44 @@ target Rust reactor Destination { - input x: u32 - input y: u32 - - state exec_count: u32 - - reaction(x, y) {= - let tag = ctx.get_tag(); - println!( - "Time since start: {}, microstep: {}", - tag.offset_from_t0.as_nanos(), - tag.microstep, - ); - - if tag == tag!(T0) { - assert!(ctx.is_present(x)); - assert_eq!(self.exec_count, 0); - } else { - assert_tag_is!(ctx, (T0, 1)); - assert!(ctx.is_present(y)); - assert_eq!(self.exec_count, 1); - } - self.exec_count += 1; - =} - - reaction(shutdown) {= - assert!(self.exec_count == 2, "reaction was not executed twice"); - println!("success"); - =} + input x: u32 + input y: u32 + + state exec_count: u32 + + reaction(x, y) {= + let tag = ctx.get_tag(); + println!( + "Time since start: {}, microstep: {}", + tag.offset_from_t0.as_nanos(), + tag.microstep, + ); + + if tag == tag!(T0) { + assert!(ctx.is_present(x)); + assert_eq!(self.exec_count, 0); + } else { + assert_tag_is!(ctx, (T0, 1)); + assert!(ctx.is_present(y)); + assert_eq!(self.exec_count, 1); + } + self.exec_count += 1; + =} + + reaction(shutdown) {= + assert!(self.exec_count == 2, "reaction was not executed twice"); + println!("success"); + =} } main reactor { - logical action repeat - d = new Destination() + logical action repeat + d = new Destination() - reaction(startup) -> d.x, repeat {= - ctx.set(d__x, 1); - ctx.schedule(repeat, Asap); - =} + reaction(startup) -> d.x, repeat {= + ctx.set(d__x, 1); + ctx.schedule(repeat, Asap); + =} - reaction(repeat) -> d.y {= ctx.set(d__y, 1); =} + reaction(repeat) -> d.y {= ctx.set(d__y, 1); =} } diff --git a/test/Rust/src/DependencyUseAccessible.lf b/test/Rust/src/DependencyUseAccessible.lf index 28afec9bc6..6e288af8e8 100644 --- a/test/Rust/src/DependencyUseAccessible.lf +++ b/test/Rust/src/DependencyUseAccessible.lf @@ -2,45 +2,45 @@ target Rust reactor Source { - output clock: u32 - output o1: u32 - output o2: u32 - timer t1(35 msec) - timer t2(70 msec) + output clock: u32 + output o1: u32 + output o2: u32 + timer t1(35 msec) + timer t2(70 msec) - reaction(startup) -> clock {= ctx.set(clock, 0); =} + reaction(startup) -> clock {= ctx.set(clock, 0); =} - reaction(t1) -> clock, o1 {= ctx.set(clock, 1); ctx.set(o1, 10) =} + reaction(t1) -> clock, o1 {= ctx.set(clock, 1); ctx.set(o1, 10) =} - reaction(t2) -> clock, o2 {= ctx.set(clock, 2); =} // has a dependency but doesn't use it + reaction(t2) -> clock, o2 {= ctx.set(clock, 2); =} // has a dependency but doesn't use it } reactor Sink { - input clock: u32 - input in1: u32 - input in2: u32 - - reaction(clock) in1, in2 {= - match ctx.get(clock) { - Some(0) | Some(2) => { - assert_eq!(None, ctx.get(in1)); - assert_eq!(None, ctx.get(in2)); - }, - Some(1) => { - assert_eq!(Some(10), ctx.get(in1)); - assert_eq!(None, ctx.get(in2)); - }, - c => panic!("No such signal expected {:?}", c) - } - =} + input clock: u32 + input in1: u32 + input in2: u32 + + reaction(clock) in1, in2 {= + match ctx.get(clock) { + Some(0) | Some(2) => { + assert_eq!(None, ctx.get(in1)); + assert_eq!(None, ctx.get(in2)); + }, + Some(1) => { + assert_eq!(Some(10), ctx.get(in1)); + assert_eq!(None, ctx.get(in2)); + }, + c => panic!("No such signal expected {:?}", c) + } + =} } main reactor { - source = new Source() - sink = new Sink() + source = new Source() + sink = new Sink() - source.clock -> sink.clock + source.clock -> sink.clock - source.o1 -> sink.in1 - source.o2 -> sink.in2 + source.o1 -> sink.in1 + source.o2 -> sink.in2 } diff --git a/test/Rust/src/DependencyUseNonTrigger.lf b/test/Rust/src/DependencyUseNonTrigger.lf index 53496d6896..656ad1f768 100644 --- a/test/Rust/src/DependencyUseNonTrigger.lf +++ b/test/Rust/src/DependencyUseNonTrigger.lf @@ -2,23 +2,23 @@ target Rust reactor Source { - output clock: u32 + output clock: u32 - reaction(startup) -> clock {= ctx.set(clock, 0); =} + reaction(startup) -> clock {= ctx.set(clock, 0); =} } reactor Sink { - input clock: u32 - input bogus: u32 + input clock: u32 + input bogus: u32 - reaction(bogus) clock {= panic!("Should not be executed") =} + reaction(bogus) clock {= panic!("Should not be executed") =} - reaction(shutdown) {= println!("Success") =} + reaction(shutdown) {= println!("Success") =} } main reactor { - source = new Source() - sink = new Sink() + source = new Source() + sink = new Sink() - source.clock -> sink.clock + source.clock -> sink.clock } diff --git a/test/Rust/src/Import.lf b/test/Rust/src/Import.lf index 15837b9c4c..c14618ba6e 100644 --- a/test/Rust/src/Import.lf +++ b/test/Rust/src/Import.lf @@ -4,8 +4,8 @@ target Rust import Imported from "lib/Imported.lf" main reactor Import { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= ctx.set(a__x, 42); =} + reaction(t) -> a.x {= ctx.set(a__x, 42); =} } diff --git a/test/Rust/src/ImportPreambleItem.lf b/test/Rust/src/ImportPreambleItem.lf index 2abd438fb6..922ea74b1a 100644 --- a/test/Rust/src/ImportPreambleItem.lf +++ b/test/Rust/src/ImportPreambleItem.lf @@ -4,7 +4,7 @@ target Rust import SomethingWithAPreamble from "lib/SomethingWithAPreamble.lf" main reactor { - r = new SomethingWithAPreamble() + r = new SomethingWithAPreamble() - reaction(startup) -> r.a {= ctx.set(r__a, super::something_with_a_preamble::some_fun()); =} + reaction(startup) -> r.a {= ctx.set(r__a, super::something_with_a_preamble::some_fun()); =} } diff --git a/test/Rust/src/Minimal.lf b/test/Rust/src/Minimal.lf index 77c7c791f6..02fd0d3eb3 100644 --- a/test/Rust/src/Minimal.lf +++ b/test/Rust/src/Minimal.lf @@ -2,5 +2,5 @@ target Rust main reactor Minimal { - reaction(startup) {= println!("Hello World."); =} + reaction(startup) {= println!("Hello World."); =} } diff --git a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf index faa4f54252..de06f462eb 100644 --- a/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf +++ b/test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf @@ -2,26 +2,26 @@ target Rust main reactor { - physical action act: u32 + physical action act: u32 - state count: u32 + state count: u32 - reaction(startup) -> act {= - ctx.schedule(act, Asap); - ctx.schedule(act, after!(20 ms)); - =} + reaction(startup) -> act {= + ctx.schedule(act, Asap); + ctx.schedule(act, after!(20 ms)); + =} - reaction(act) {= - println!("---- Invocation at {}", ctx.get_tag()); - self.count += 1; + reaction(act) {= + println!("---- Invocation at {}", ctx.get_tag()); + self.count += 1; - // If the physical time is used then it is unlikely to be - // exactly TO + 20 ms. - assert_ne!(ctx.get_elapsed_logical_time(), delay!(20 ms)); - =} + // If the physical time is used then it is unlikely to be + // exactly TO + 20 ms. + assert_ne!(ctx.get_elapsed_logical_time(), delay!(20 ms)); + =} - reaction(shutdown) {= - assert_eq!(self.count, 2); - println!("success"); - =} + reaction(shutdown) {= + assert_eq!(self.count, 2); + println!("success"); + =} } diff --git a/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf b/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf index a34daa21e0..a10abd9a7a 100644 --- a/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf +++ b/test/Rust/src/PhysicalActionKeepaliveIsSmart.lf @@ -1,24 +1,24 @@ // Tests that the scheduler ends up shutting down if there are no live Sender that can send messages // back to the scheduler. target Rust { - keepalive: true + keepalive: true } main reactor { - physical action act: u32 + physical action act: u32 - reaction(startup) -> act {= - std::thread::spawn(|| { - std::thread::sleep(delay!(1 sec)); - // this is a regular thread which doesn't have a reference to the scheduler - }); - =} + reaction(startup) -> act {= + std::thread::spawn(|| { + std::thread::sleep(delay!(1 sec)); + // this is a regular thread which doesn't have a reference to the scheduler + }); + =} - reaction(shutdown) {= - assert!( - ctx.get_elapsed_logical_time() < Duration::from_millis(500), - "Should shutdown before the other thread catches up" - ); - println!("success"); - =} + reaction(shutdown) {= + assert!( + ctx.get_elapsed_logical_time() < Duration::from_millis(500), + "Should shutdown before the other thread catches up" + ); + println!("success"); + =} } diff --git a/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf b/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf index f1f8c154b0..de6a92c72f 100644 --- a/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf +++ b/test/Rust/src/PhysicalActionWakesSleepingScheduler.lf @@ -7,21 +7,21 @@ target Rust main reactor { - timer t(250 msec) // this is unused but important - physical action act: u32 + timer t(250 msec) // this is unused but important + physical action act: u32 - reaction(startup) -> act {= - let act = act.clone(); - ctx.spawn_physical_thread(move |link| { - std::thread::sleep(delay!(20 msec)); - link.schedule_physical(&act, Asap); - }); - =} + reaction(startup) -> act {= + let act = act.clone(); + ctx.spawn_physical_thread(move |link| { + std::thread::sleep(delay!(20 msec)); + link.schedule_physical(&act, Asap); + }); + =} - reaction(act) {= - println!("---- Invocation at {}", ctx.get_tag()); + reaction(act) {= + println!("---- Invocation at {}", ctx.get_tag()); - assert!(ctx.get_elapsed_logical_time() < delay!(250 msec)); - println!("success") - =} + assert!(ctx.get_elapsed_logical_time() < delay!(250 msec)); + println!("success") + =} } diff --git a/test/Rust/src/PhysicalActionWithKeepalive.lf b/test/Rust/src/PhysicalActionWithKeepalive.lf index 8ed4c01a06..a1abdd7743 100644 --- a/test/Rust/src/PhysicalActionWithKeepalive.lf +++ b/test/Rust/src/PhysicalActionWithKeepalive.lf @@ -1,25 +1,25 @@ target Rust { - keepalive: true + keepalive: true } main reactor { - physical action act: u32 + physical action act: u32 - reaction(startup) -> act {= - let act = act.clone(); - ctx.spawn_physical_thread(move |link| { - std::thread::sleep(Duration::from_millis(20)); - link.schedule_physical_with_v(&act, Some(434), Asap); - }); - =} + reaction(startup) -> act {= + let act = act.clone(); + ctx.spawn_physical_thread(move |link| { + std::thread::sleep(Duration::from_millis(20)); + link.schedule_physical_with_v(&act, Some(434), Asap); + }); + =} - reaction(act) {= - let value = ctx.get(act).unwrap(); - println!("---- saw {} at {}", value, ctx.get_tag()); + reaction(act) {= + let value = ctx.get(act).unwrap(); + println!("---- saw {} at {}", value, ctx.get_tag()); - let elapsed_time = ctx.get_elapsed_logical_time(); - assert!(elapsed_time >= delay!(20 ms)); - println!("success"); - ctx.request_stop(Asap); - =} + let elapsed_time = ctx.get_elapsed_logical_time(); + assert!(elapsed_time >= delay!(20 ms)); + println!("success"); + ctx.request_stop(Asap); + =} } diff --git a/test/Rust/src/Preamble.lf b/test/Rust/src/Preamble.lf index c8c186491d..68e2a2f709 100644 --- a/test/Rust/src/Preamble.lf +++ b/test/Rust/src/Preamble.lf @@ -1,11 +1,11 @@ target Rust main reactor Preamble { - preamble {= - fn add_42(i: i32) -> i32 { - return i + 42; - } - =} + preamble {= + fn add_42(i: i32) -> i32 { + return i + 42; + } + =} - reaction(startup) {= println!("42 plus 42 is {}.\n", add_42(42)); =} + reaction(startup) {= println!("42 plus 42 is {}.\n", add_42(42)); =} } diff --git a/test/Rust/src/ReactionLabels.lf b/test/Rust/src/ReactionLabels.lf index 6547792d8c..41c7ec57dd 100644 --- a/test/Rust/src/ReactionLabels.lf +++ b/test/Rust/src/ReactionLabels.lf @@ -3,7 +3,7 @@ target Rust main reactor { - timer t(0) + timer t(0) - reaction(t) {= println!("success"); =} // @label foo + reaction(t) {= println!("success"); =} // @label foo } diff --git a/test/Rust/src/ReservedKeywords.lf b/test/Rust/src/ReservedKeywords.lf index ef11dda278..5d30ba63a4 100644 --- a/test/Rust/src/ReservedKeywords.lf +++ b/test/Rust/src/ReservedKeywords.lf @@ -1,4 +1,5 @@ -// Tests that rust keywords may be used as identifiers in LF and are properly escaped by the emitter +// Tests that rust keywords may be used as identifiers in LF and are properly +// escaped by the emitter target Rust reactor box { diff --git a/test/Rust/src/SingleFileGeneration.lf b/test/Rust/src/SingleFileGeneration.lf index 096e4d2dcd..a3cfdc89f8 100644 --- a/test/Rust/src/SingleFileGeneration.lf +++ b/test/Rust/src/SingleFileGeneration.lf @@ -1,30 +1,30 @@ // The same as CompositionWithPorts.lf, but as a single file project target Rust { - single-file-project: true + single-file-project: true } reactor Source { - output out: i32 + output out: i32 - reaction(startup) -> out {= ctx.set(out, 76600) =} + reaction(startup) -> out {= ctx.set(out, 76600) =} } reactor Sink { - input inport: i32 + input inport: i32 - reaction(inport) {= - if let Some(value) = ctx.get(inport) { - println!("received {}", value); - assert_eq!(76600, value); - } else { - unreachable!(); - } - =} + reaction(inport) {= + if let Some(value) = ctx.get(inport) { + println!("received {}", value); + assert_eq!(76600, value); + } else { + unreachable!(); + } + =} } main reactor { - source = new Source() - sink = new Sink() + source = new Source() + sink = new Sink() - source.out -> sink.inport + source.out -> sink.inport } diff --git a/test/Rust/src/StateDefaultValue.lf b/test/Rust/src/StateDefaultValue.lf index a9eeb1d457..f16549b6db 100644 --- a/test/Rust/src/StateDefaultValue.lf +++ b/test/Rust/src/StateDefaultValue.lf @@ -1,14 +1,14 @@ target Rust main reactor { - // missing initializers are taken to mean "initialize to Default::default()" - state foo_default: u32 - state vec_default: Vec - state option: Option> + // missing initializers are taken to mean "initialize to Default::default()" + state foo_default: u32 + state vec_default: Vec + state option: Option> - reaction(startup) {= - assert_eq!(self.foo_default, 0); - assert_eq!(self.vec_default, vec![]); - assert_eq!(self.option, None); - =} + reaction(startup) {= + assert_eq!(self.foo_default, 0); + assert_eq!(self.vec_default, vec![]); + assert_eq!(self.option, None); + =} } diff --git a/test/Rust/src/StateInitializerVisibility.lf b/test/Rust/src/StateInitializerVisibility.lf index f7da9a48d4..d192f0ca98 100644 --- a/test/Rust/src/StateInitializerVisibility.lf +++ b/test/Rust/src/StateInitializerVisibility.lf @@ -1,5 +1,5 @@ -// Tests that state vars are accessible within initializers of other state vars declared further -// down. +// Tests that state vars are accessible within initializers of other state vars +// declared further down. target Rust main reactor { diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index 80960ef142..c43f8c30ff 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -8,9 +8,10 @@ target Rust { } /** - * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break after sending - * take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in + * consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break + * after sending take_a_break_after messages. */ reactor Sender(take_a_break_after: u32 = 10, break_interval: time = 400 msec) { output out: u32 diff --git a/test/Rust/src/StopAsync.lf b/test/Rust/src/StopAsync.lf index 6f54ceecde..ca2be1c8a6 100644 --- a/test/Rust/src/StopAsync.lf +++ b/test/Rust/src/StopAsync.lf @@ -1,16 +1,16 @@ target Rust main reactor { - reaction(startup) {= - ctx.spawn_physical_thread(|ctx| { - std::thread::sleep(delay!(140 msec)); - ctx.request_stop(Asap); - }); - =} + reaction(startup) {= + ctx.spawn_physical_thread(|ctx| { + std::thread::sleep(delay!(140 msec)); + ctx.request_stop(Asap); + }); + =} - reaction(shutdown) {= - assert!(ctx.is_shutdown()); - assert!(ctx.get_elapsed_logical_time() > delay!(140 msec)); - println!("success"); - =} + reaction(shutdown) {= + assert!(ctx.is_shutdown()); + assert!(ctx.get_elapsed_logical_time() > delay!(140 msec)); + println!("success"); + =} } diff --git a/test/Rust/src/StopCleanup.lf b/test/Rust/src/StopCleanup.lf index 5bb89fffc2..c9f36bb013 100644 --- a/test/Rust/src/StopCleanup.lf +++ b/test/Rust/src/StopCleanup.lf @@ -2,28 +2,28 @@ target Rust reactor Sender { - output out: u32 + output out: u32 - reaction(startup) -> out {= - assert_tag_is!(ctx, (T0, 0)); - ctx.set(out, 43); - ctx.request_stop(Asap); // requested for (T0, 1) - =} + reaction(startup) -> out {= + assert_tag_is!(ctx, (T0, 0)); + ctx.set(out, 43); + ctx.request_stop(Asap); // requested for (T0, 1) + =} } reactor Consumer { - input in_: u32 + input in_: u32 - reaction(shutdown) in_ {= - assert!(ctx.get(in_).is_none(), "Port should have been cleaned up before shutdown"); - assert_tag_is!(ctx, (T0, 1)); - assert!(ctx.get_elapsed_logical_time().is_zero(), "Should be called on startup step"); - =} + reaction(shutdown) in_ {= + assert!(ctx.get(in_).is_none(), "Port should have been cleaned up before shutdown"); + assert_tag_is!(ctx, (T0, 1)); + assert!(ctx.get_elapsed_logical_time().is_zero(), "Should be called on startup step"); + =} } main reactor StopCleanup { - consumer = new Consumer() - producer = new Sender() + consumer = new Consumer() + producer = new Sender() - producer.out -> consumer.in_ + producer.out -> consumer.in_ } diff --git a/test/Rust/src/StopDuringStartup.lf b/test/Rust/src/StopDuringStartup.lf index 4e78a12e11..149a2fe7e0 100644 --- a/test/Rust/src/StopDuringStartup.lf +++ b/test/Rust/src/StopDuringStartup.lf @@ -1,17 +1,17 @@ // tests that a request_stop called during startup is acted upon. target Rust { - timeout: 30 msec + timeout: 30 msec } main reactor { - reaction(startup) {= - ctx.request_stop(Asap); // requested for (T0, 1) - assert_tag_is!(ctx, T0); - =} + reaction(startup) {= + ctx.request_stop(Asap); // requested for (T0, 1) + assert_tag_is!(ctx, T0); + =} - reaction(shutdown) {= - assert!(ctx.is_shutdown()); - assert_tag_is!(ctx, (T0, 1)); - println!("success"); - =} + reaction(shutdown) {= + assert!(ctx.is_shutdown()); + assert_tag_is!(ctx, (T0, 1)); + println!("success"); + =} } diff --git a/test/Rust/src/StopNoEvent.lf b/test/Rust/src/StopNoEvent.lf index 5ee2639fa2..9dc96d3533 100644 --- a/test/Rust/src/StopNoEvent.lf +++ b/test/Rust/src/StopNoEvent.lf @@ -2,5 +2,5 @@ target Rust main reactor StopNoEvent { - reaction(shutdown) {= println!("success"); =} + reaction(shutdown) {= println!("success"); =} } diff --git a/test/Rust/src/StopTimeout.lf b/test/Rust/src/StopTimeout.lf index 7ebf1595e4..0cd9423156 100644 --- a/test/Rust/src/StopTimeout.lf +++ b/test/Rust/src/StopTimeout.lf @@ -2,12 +2,12 @@ * Tests that `shutdown` is triggered even if the program exits because of timeout target property. */ target Rust { - timeout: 30 msec + timeout: 30 msec } main reactor StopTimeout { - reaction(shutdown) {= - assert_tag_is!(ctx, T0 + 30 ms); - println!("Success!"); // if this is not printed the test failed - =} + reaction(shutdown) {= + assert_tag_is!(ctx, T0 + 30 ms); + println!("Success!"); // if this is not printed the test failed + =} } diff --git a/test/Rust/src/StopTimeoutExact.lf b/test/Rust/src/StopTimeoutExact.lf index cd81e7923d..2b9eb85cda 100644 --- a/test/Rust/src/StopTimeoutExact.lf +++ b/test/Rust/src/StopTimeoutExact.lf @@ -1,6 +1,6 @@ /** - * Tests that when a timeout coincides with a scheduled event, all scheduled reactions are properly - * executed (in addition to the shutdown ones). + * Tests that when a timeout coincides with a scheduled event, all scheduled + * reactions are properly executed (in addition to the shutdown ones). */ target Rust { timeout: 50 msec diff --git a/test/Rust/src/StopTopology.lf b/test/Rust/src/StopTopology.lf index 2d10ee83a8..7f92eb4a82 100644 --- a/test/Rust/src/StopTopology.lf +++ b/test/Rust/src/StopTopology.lf @@ -1,20 +1,20 @@ /** Tests that shutdown wave occurs in topological order like a normal wave. */ target Rust { - timeout: 30 msec + timeout: 30 msec } main reactor StopTopology { - timer end(30 msec) // collides with timeout - state count: u32 + timer end(30 msec) // collides with timeout + state count: u32 - reaction(end) {= - assert_eq!(self.count, 0); - self.count += 1; - =} + reaction(end) {= + assert_eq!(self.count, 0); + self.count += 1; + =} - reaction(shutdown) {= - // executes after because of priority - assert_eq!(self.count, 1); - println!("success"); - =} + reaction(shutdown) {= + // executes after because of priority + assert_eq!(self.count, 1); + println!("success"); + =} } diff --git a/test/Rust/src/StructAsState.lf b/test/Rust/src/StructAsState.lf index 22565b58e9..9b35e7a3fb 100644 --- a/test/Rust/src/StructAsState.lf +++ b/test/Rust/src/StructAsState.lf @@ -1,5 +1,5 @@ -// Check that a state variable can have a statically initialized struct as a value. Check how -// preambles work +// Check that a state variable can have a statically initialized struct as a +// value. Check how preambles work target Rust main reactor StructAsState { diff --git a/test/Rust/src/concurrent/Workers.lf b/test/Rust/src/concurrent/Workers.lf index 497b60fd53..fd330a73cb 100644 --- a/test/Rust/src/concurrent/Workers.lf +++ b/test/Rust/src/concurrent/Workers.lf @@ -1,13 +1,13 @@ target Rust { - workers: 16 + workers: 16 } main reactor { - reaction(startup) {= - if (ctx.num_workers() != 16) { - panic!("Expected to have 16 workers."); - } else { - println!("Using 16 workers."); - } - =} + reaction(startup) {= + if (ctx.num_workers() != 16) { + panic!("Expected to have 16 workers."); + } else { + println!("Using 16 workers."); + } + =} } diff --git a/test/Rust/src/generics/GenericReactor.lf b/test/Rust/src/generics/GenericReactor.lf index 9715d7e0a3..3190524a5b 100644 --- a/test/Rust/src/generics/GenericReactor.lf +++ b/test/Rust/src/generics/GenericReactor.lf @@ -18,7 +18,9 @@ main reactor { reaction(startup) -> box0.inp {= ctx.set(box0__inp, 444); =} - reaction(box1.out) {= assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; =} + reaction(box1.out) {= + assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; + =} reaction(shutdown) {= assert!(self.done, "reaction was not executed"); diff --git a/test/Rust/src/lib/Imported.lf b/test/Rust/src/lib/Imported.lf index 8a33aa04b8..b72cfdf533 100644 --- a/test/Rust/src/lib/Imported.lf +++ b/test/Rust/src/lib/Imported.lf @@ -5,8 +5,8 @@ target Rust import ImportedAgain from "ImportedAgain.lf" reactor Imported { - input x: u32 - a = new ImportedAgain() + input x: u32 + a = new ImportedAgain() - reaction(x) -> a.x {= ctx.set(a__x, ctx.get(x).unwrap()); =} + reaction(x) -> a.x {= ctx.set(a__x, ctx.get(x).unwrap()); =} } diff --git a/test/Rust/src/lib/ImportedAgain.lf b/test/Rust/src/lib/ImportedAgain.lf index d1bd87c4f1..1f9d236318 100644 --- a/test/Rust/src/lib/ImportedAgain.lf +++ b/test/Rust/src/lib/ImportedAgain.lf @@ -3,10 +3,10 @@ target Rust reactor ImportedAgain { - input x: u32 + input x: u32 - reaction(x) {= - assert_eq!(Some(42), ctx.get(x)); - println!("success"); - =} + reaction(x) {= + assert_eq!(Some(42), ctx.get(x)); + println!("success"); + =} } diff --git a/test/Rust/src/lib/SomethingWithAPreamble.lf b/test/Rust/src/lib/SomethingWithAPreamble.lf index d63f7c381a..af5caa871b 100644 --- a/test/Rust/src/lib/SomethingWithAPreamble.lf +++ b/test/Rust/src/lib/SomethingWithAPreamble.lf @@ -3,10 +3,10 @@ target Rust reactor SomethingWithAPreamble { - input a: u32 - preamble {= - pub fn some_fun() -> u32 { - 4 - } - =} + input a: u32 + preamble {= + pub fn some_fun() -> u32 { + 4 + } + =} } diff --git a/test/Rust/src/multiport/CycledLhs_SelfLoop.lf b/test/Rust/src/multiport/CycledLhs_SelfLoop.lf index 5eb3cc226c..925fafce21 100644 --- a/test/Rust/src/multiport/CycledLhs_SelfLoop.lf +++ b/test/Rust/src/multiport/CycledLhs_SelfLoop.lf @@ -1,5 +1,5 @@ -// test a cycled connection which has ports of the same reactor on the LHS and rhs (single port)+ -> -// multiport +// test a cycled connection which has ports of the same reactor on the LHS and +// rhs (single port)+ -> multiport target Rust { timeout: 16 usec } @@ -10,7 +10,9 @@ reactor Test { logical action act: u32 state last: u32 = 1 - reaction(startup) -> act {= ctx.schedule_with_v(act, Some(1), after!(1 us)); =} + reaction(startup) -> act {= + ctx.schedule_with_v(act, Some(1), after!(1 us)); + =} reaction(act) -> out {= ctx.set_opt(out, ctx.get(act)); =} diff --git a/test/Rust/src/multiport/CycledLhs_Single.lf b/test/Rust/src/multiport/CycledLhs_Single.lf index 62723bda42..2fdd5c605c 100644 --- a/test/Rust/src/multiport/CycledLhs_Single.lf +++ b/test/Rust/src/multiport/CycledLhs_Single.lf @@ -1,5 +1,5 @@ -// test a cycled connection which has ports of the same reactor on the LHS and rhs (multiport)+ -> -// multiport +// test a cycled connection which has ports of the same reactor on the LHS and +// rhs (multiport)+ -> multiport target Rust { timeout: 16 usec } @@ -10,7 +10,9 @@ reactor Test { logical action act: {= (u32, u32) =} state last: u32 = 1 - reaction(startup) -> act {= ctx.schedule_with_v(act, Some((0, 1)), after!(1 us)); =} + reaction(startup) -> act {= + ctx.schedule_with_v(act, Some((0, 1)), after!(1 us)); + =} reaction(act) -> out {= let (a, b) = ctx.get(act).unwrap(); @@ -39,9 +41,9 @@ reactor Test { } /** - * 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = - * 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 - * + 987 = 1597 987 + 1597 = 2584 + * 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + + * 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = + * 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 */ main reactor { t = new Test() diff --git a/test/Rust/src/multiport/MultiportFromHierarchy.lf b/test/Rust/src/multiport/MultiportFromHierarchy.lf index 400dfff7d9..d2af4253c4 100644 --- a/test/Rust/src/multiport/MultiportFromHierarchy.lf +++ b/test/Rust/src/multiport/MultiportFromHierarchy.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical +// reactor. target Rust { timeout: 2 sec } diff --git a/test/Rust/src/multiport/MultiportIn.lf b/test/Rust/src/multiport/MultiportIn.lf index 27b3522449..4ebf1c56d5 100644 --- a/test/Rust/src/multiport/MultiportIn.lf +++ b/test/Rust/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version fo the Threaded test that uses a multiport input at the destination. Its -// purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the +// destination. Its purpose is to test multiport inputs. target Rust { timeout: 2 sec, fast: true diff --git a/test/Rust/src/multiport/MultiportToMultiport2.lf b/test/Rust/src/multiport/MultiportToMultiport2.lf index 0c79ee17d4..a1e2db235d 100644 --- a/test/Rust/src/multiport/MultiportToMultiport2.lf +++ b/test/Rust/src/multiport/MultiportToMultiport2.lf @@ -1,4 +1,5 @@ -// test a sparse connection between multiports (some channels are left disconnected) +// test a sparse connection between multiports (some channels are left +// disconnected) target Rust reactor Source(width: usize = 2) { diff --git a/test/Rust/src/target/BuildProfileDefaultIsDev.lf b/test/Rust/src/target/BuildProfileDefaultIsDev.lf index e45c442406..083794bdfc 100644 --- a/test/Rust/src/target/BuildProfileDefaultIsDev.lf +++ b/test/Rust/src/target/BuildProfileDefaultIsDev.lf @@ -3,8 +3,8 @@ target Rust main reactor { - reaction(startup) {= - assert!(cfg!(debug_assertions), "debug assertions should be enabled"); - println!("success"); - =} + reaction(startup) {= + assert!(cfg!(debug_assertions), "debug assertions should be enabled"); + println!("success"); + =} } diff --git a/test/Rust/src/target/BuildProfileRelease.lf b/test/Rust/src/target/BuildProfileRelease.lf index 20712f0721..da19c0bc79 100644 --- a/test/Rust/src/target/BuildProfileRelease.lf +++ b/test/Rust/src/target/BuildProfileRelease.lf @@ -1,12 +1,12 @@ // Tests that the we can enable the release profile A proxy for checking this is to check that debug // assertions are disabled. target Rust { - build-type: "Release" + build-type: "Release" } main reactor { - reaction(startup) {= - assert!(!cfg!(debug_assertions), "debug assertions should be disabled"); - println!("success"); - =} + reaction(startup) {= + assert!(!cfg!(debug_assertions), "debug assertions should be disabled"); + println!("success"); + =} } diff --git a/test/Rust/src/target/CargoDependency.lf b/test/Rust/src/target/CargoDependency.lf index a425958fab..5a9b37cf5e 100644 --- a/test/Rust/src/target/CargoDependency.lf +++ b/test/Rust/src/target/CargoDependency.lf @@ -1,16 +1,16 @@ // This tests the ability to depend on crates with carg if this compiles it's fine target Rust { - cargo-dependencies: { - rand: "0.8", - regex: { - version: "1" - } + cargo-dependencies: { + rand: "0.8", + regex: { + version: "1" } + } } main reactor { - reaction(startup) {= - use rand::rngs::StdRng; - use regex::*; - =} + reaction(startup) {= + use rand::rngs::StdRng; + use regex::*; + =} } diff --git a/test/Rust/src/target/CargoDependencyOnRuntime.lf b/test/Rust/src/target/CargoDependencyOnRuntime.lf index 2d3473f474..26aa2c5eb3 100644 --- a/test/Rust/src/target/CargoDependencyOnRuntime.lf +++ b/test/Rust/src/target/CargoDependencyOnRuntime.lf @@ -1,12 +1,12 @@ // This tests the ability to depend on crates with carg if this compiles it's fine target Rust { - cargo-dependencies: { - reactor_rt: { - features: ["parallel-runtime"] - } + cargo-dependencies: { + reactor_rt: { + features: ["parallel-runtime"] } + } } main reactor { - reaction(startup) {= println!("success") =} + reaction(startup) {= println!("success") =} } diff --git a/test/Rust/src/target/ModuleDependency.lf b/test/Rust/src/target/ModuleDependency.lf index 43945fda06..e3d22914c8 100644 --- a/test/Rust/src/target/ModuleDependency.lf +++ b/test/Rust/src/target/ModuleDependency.lf @@ -1,14 +1,14 @@ // Test that we can include modules into main target Rust { - rust-include: "some_module.rs" + rust-include: "some_module.rs" } main reactor { - timer t(0) + timer t(0) - reaction(t) {= - use crate::some_module::*; - assert_eq!("hihihi", from_some_module()); - println!("success"); - =} + reaction(t) {= + use crate::some_module::*; + assert_eq!("hihihi", from_some_module()); + println!("success"); + =} } diff --git a/test/Rust/src/target/ModuleDependencyWithDirModule.lf b/test/Rust/src/target/ModuleDependencyWithDirModule.lf index 3820594198..237904ed74 100644 --- a/test/Rust/src/target/ModuleDependencyWithDirModule.lf +++ b/test/Rust/src/target/ModuleDependencyWithDirModule.lf @@ -1,15 +1,15 @@ // The same as CompositionWithPorts.lf, but as a single file project target Rust { - rust-include: "testmod" + rust-include: "testmod" } main reactor { - timer t(0) + timer t(0) - reaction(t) {= - use crate::testmod::*; - assert_eq!(44, something()); - assert_eq!("other", other::from_other()); - println!("success"); - =} + reaction(t) {= + use crate::testmod::*; + assert_eq!(44, something()); + assert_eq!("other", other::from_other()); + println!("success"); + =} } diff --git a/test/TypeScript/src/ActionWithNoReaction.lf b/test/TypeScript/src/ActionWithNoReaction.lf index f8dab33ef6..14d6aa8801 100644 --- a/test/TypeScript/src/ActionWithNoReaction.lf +++ b/test/TypeScript/src/ActionWithNoReaction.lf @@ -1,36 +1,36 @@ // This checks that action can be created even if there is no reaction. This test passes merely by // compiling and executing without a segfault. Its other functionality is tested by other tests. target TypeScript { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x: number - output y: number - logical action a + input x: number + output y: number + logical action a - reaction(x) -> y, a {= - y = 2 * (x as number); - actions.a.schedule(TimeValue.msec(500), null) - =} + reaction(x) -> y, a {= + y = 2 * (x as number); + actions.a.schedule(TimeValue.msec(500), null) + =} } reactor print { - input x: number + input x: number - reaction(x) {= - console.log("Result is " + (x as number)); - console.log("Current logical time is " + util.getElapsedLogicalTime()); - console.log("Current physical time is: " + util.getElapsedPhysicalTime()); - =} + reaction(x) {= + console.log("Result is " + (x as number)); + console.log("Current logical time is " + util.getElapsedLogicalTime()); + console.log("Current physical time is: " + util.getElapsedPhysicalTime()); + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= f.x = 42; =} + reaction(t) -> f.x {= f.x = 42; =} } diff --git a/test/TypeScript/src/After.lf b/test/TypeScript/src/After.lf index 525ff817f1..8a872103e9 100644 --- a/test/TypeScript/src/After.lf +++ b/test/TypeScript/src/After.lf @@ -1,4 +1,5 @@ -// This checks that the after keyword adjusts logical time, not using physical time. +// This checks that the after keyword adjusts logical time, not using physical +// time. target TypeScript { fast: true, timeout: 3 sec diff --git a/test/TypeScript/src/ArrayAsType.lf b/test/TypeScript/src/ArrayAsType.lf index 3ff1e9e31a..9e30764307 100644 --- a/test/TypeScript/src/ArrayAsType.lf +++ b/test/TypeScript/src/ArrayAsType.lf @@ -1,5 +1,6 @@ -// In TypeScript this test is almost exactly the same as ArrayAsType. Source produces a statically -// allocated array, which it passes to Print. The destination references the array directly. +// In TypeScript this test is almost exactly the same as ArrayAsType. Source +// produces a statically allocated array, which it passes to Print. The +// destination references the array directly. target TypeScript reactor Source { diff --git a/test/TypeScript/src/ArrayPrint.lf b/test/TypeScript/src/ArrayPrint.lf index ba77fa47c6..93b6486506 100644 --- a/test/TypeScript/src/ArrayPrint.lf +++ b/test/TypeScript/src/ArrayPrint.lf @@ -1,5 +1,6 @@ -// In TypeScript this test is almost exactly the same as ArrayAsType. Source produces a dynamically -// allocated array, which it passes to Print. Reference counting ensures that the array is freed. +// In TypeScript this test is almost exactly the same as ArrayAsType. Source +// produces a dynamically allocated array, which it passes to Print. Reference +// counting ensures that the array is freed. target TypeScript reactor Source { diff --git a/test/TypeScript/src/ArrayScale.lf b/test/TypeScript/src/ArrayScale.lf index 0b29b9f918..107ef8cf2f 100644 --- a/test/TypeScript/src/ArrayScale.lf +++ b/test/TypeScript/src/ArrayScale.lf @@ -1,6 +1,7 @@ -// Source produces a dynamically allocated array, which it passes to Scale. Scale requests a -// writable copy, which, instead of copying, it just gets ownership of the original array. It -// modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated array, which it passes to Scale. +// Scale requests a writable copy, which, instead of copying, it just gets +// ownership of the original array. It modifies it and passes it to Print. It +// gets freed after Print is done with it. target TypeScript import Source, Print from "ArrayPrint.lf" diff --git a/test/TypeScript/src/Composition.lf b/test/TypeScript/src/Composition.lf index f3dc9ae5da..e74bbe9aa9 100644 --- a/test/TypeScript/src/Composition.lf +++ b/test/TypeScript/src/Composition.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target TypeScript { timeout: 5 sec } diff --git a/test/TypeScript/src/CompositionAfter.lf b/test/TypeScript/src/CompositionAfter.lf index 474f1525dd..8840298c2d 100644 --- a/test/TypeScript/src/CompositionAfter.lf +++ b/test/TypeScript/src/CompositionAfter.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source that checks against its own count. +// This test connects a simple counting source that checks against its own +// count. target TypeScript { fast: true, timeout: 10 sec diff --git a/test/TypeScript/src/DanglingOutput.lf b/test/TypeScript/src/DanglingOutput.lf index c07115ea93..8c9f884dd0 100644 --- a/test/TypeScript/src/DanglingOutput.lf +++ b/test/TypeScript/src/DanglingOutput.lf @@ -3,24 +3,24 @@ target TypeScript reactor Source { - output out: number - timer t + output out: number + timer t - reaction(t) -> out {= out = 1; =} + reaction(t) -> out {= out = 1; =} } reactor Gain { - input x: number - output out: number + input x: number + output out: number - reaction(x) -> out {= - console.log("Received " + x); - out = (x as number) * 2; - =} + reaction(x) -> out {= + console.log("Received " + x); + out = (x as number) * 2; + =} } main reactor DanglingOutput { - source = new Source() - container = new Gain() - source.out -> container.x + source = new Source() + container = new Gain() + source.out -> container.x } diff --git a/test/TypeScript/src/Deadline.lf b/test/TypeScript/src/Deadline.lf index b4586090f3..9f3086f1f5 100644 --- a/test/TypeScript/src/Deadline.lf +++ b/test/TypeScript/src/Deadline.lf @@ -1,5 +1,6 @@ -// This example illustrates local deadline handling. Even numbers are sent by the Source -// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by +// the Source immediately, whereas odd numbers are sent after a big enough delay +// to violate the deadline. target TypeScript { timeout: 4 sec } diff --git a/test/TypeScript/src/DeadlineHandledAbove.lf b/test/TypeScript/src/DeadlineHandledAbove.lf index a87a677048..ba47fd7aac 100644 --- a/test/TypeScript/src/DeadlineHandledAbove.lf +++ b/test/TypeScript/src/DeadlineHandledAbove.lf @@ -1,5 +1,5 @@ -// Test a deadline where the deadline violation produces an output and the container reacts to that -// output. +// Test a deadline where the deadline violation produces an output and the +// container reacts to that output. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/DelayInt.lf b/test/TypeScript/src/DelayInt.lf index 2910a5b6b5..224a7eab4a 100644 --- a/test/TypeScript/src/DelayInt.lf +++ b/test/TypeScript/src/DelayInt.lf @@ -1,5 +1,5 @@ -// This tests actions with payloads by delaying an input by a fixed amount. This is a start at -// handling dynamic memory allocation for such actions. +// This tests actions with payloads by delaying an input by a fixed amount. This +// is a start at handling dynamic memory allocation for such actions. target TypeScript reactor Delay(delay: time = 100 msec) { diff --git a/test/TypeScript/src/DelayedReaction.lf b/test/TypeScript/src/DelayedReaction.lf index 9ec7135f5a..1622b4069c 100644 --- a/test/TypeScript/src/DelayedReaction.lf +++ b/test/TypeScript/src/DelayedReaction.lf @@ -2,26 +2,26 @@ target TypeScript reactor Source { - output out: number - timer t + output out: number + timer t - reaction(t) -> out {= out = 1; =} + reaction(t) -> out {= out = 1; =} } reactor Sink { - input x: number + input x: number - reaction(x) {= - let elapsed = util.getElapsedLogicalTime(); - console.log("Nanoseconds since start: " + elapsed); - if (! elapsed.isEqualTo(TimeValue.msec(100))) { - util.requestErrorStop("ERROR: Expected 100 msecs but got" + elapsed) - } - =} + reaction(x) {= + let elapsed = util.getElapsedLogicalTime(); + console.log("Nanoseconds since start: " + elapsed); + if (! elapsed.isEqualTo(TimeValue.msec(100))) { + util.requestErrorStop("ERROR: Expected 100 msecs but got" + elapsed) + } + =} } main reactor DelayedReaction { - source = new Source() - sink = new Sink() - source.out -> sink.x after 100 msec + source = new Source() + sink = new Sink() + source.out -> sink.x after 100 msec } diff --git a/test/TypeScript/src/Determinism.lf b/test/TypeScript/src/Determinism.lf index 51381216c6..d0fc8db2a5 100644 --- a/test/TypeScript/src/Determinism.lf +++ b/test/TypeScript/src/Determinism.lf @@ -1,45 +1,45 @@ target TypeScript reactor Source { - output y: number - timer t + output y: number + timer t - reaction(t) -> y {= y = 1; =} + reaction(t) -> y {= y = 1; =} } reactor Destination { - input x: number - input y: number + input x: number + input y: number - reaction(x, y) {= - let sum = 0; - if (x !== undefined) { - sum += x; - } - if (y !== undefined) { - sum += y; - } - console.log("Received " + sum); - if (sum != 2) { - util.requestErrorStop("FAILURE: Expected 2.") - } - =} + reaction(x, y) {= + let sum = 0; + if (x !== undefined) { + sum += x; + } + if (y !== undefined) { + sum += y; + } + console.log("Received " + sum); + if (sum != 2) { + util.requestErrorStop("FAILURE: Expected 2.") + } + =} } reactor Pass { - input x: number - output y: number + input x: number + output y: number - reaction(x) -> y {= y = x as number; =} + reaction(x) -> y {= y = x as number; =} } main reactor Determinism { - s = new Source() - d = new Destination() - p1 = new Pass() - p2 = new Pass() - s.y -> d.y - s.y -> p1.x - p1.y -> p2.x - p2.y -> d.x + s = new Source() + d = new Destination() + p1 = new Pass() + p2 = new Pass() + s.y -> d.y + s.y -> p1.x + p1.y -> p2.x + p2.y -> d.x } diff --git a/test/TypeScript/src/DoubleInvocation.lf b/test/TypeScript/src/DoubleInvocation.lf index 92369ca913..9557857ee2 100644 --- a/test/TypeScript/src/DoubleInvocation.lf +++ b/test/TypeScript/src/DoubleInvocation.lf @@ -1,7 +1,8 @@ -// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it -// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at -// the same logical time. They should only be fired once. This behavior was oddly eliminated by -// either of the following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. +// This test ensures it does not reappear. At logical time zero, the two Print +// reactors used to be fired twice each at the same logical time. They should +// only be fired once. This behavior was oddly eliminated by either of the +// following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. // * Sending only position, not velocity from Ball. target TypeScript { diff --git a/test/TypeScript/src/DoubleReaction.lf b/test/TypeScript/src/DoubleReaction.lf index 67f2632920..b172166613 100644 --- a/test/TypeScript/src/DoubleReaction.lf +++ b/test/TypeScript/src/DoubleReaction.lf @@ -1,5 +1,5 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output -// for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only +// once. Correct output for this 2, 4, 6, 8, etc. target TypeScript { timeout: 10 sec, fast: true diff --git a/test/TypeScript/src/DoubleTrigger.lf b/test/TypeScript/src/DoubleTrigger.lf index dafbd7f453..fc8921622c 100644 --- a/test/TypeScript/src/DoubleTrigger.lf +++ b/test/TypeScript/src/DoubleTrigger.lf @@ -1,4 +1,5 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice +// at the same tag. target TypeScript { fast: true, timeout: 1 sec diff --git a/test/TypeScript/src/GetTime.lf b/test/TypeScript/src/GetTime.lf index 8e14c563a0..d168c4c594 100644 --- a/test/TypeScript/src/GetTime.lf +++ b/test/TypeScript/src/GetTime.lf @@ -1,24 +1,24 @@ // This file includes code documented on the Wiki. For this test, success is just compiling and // running. target TypeScript { - // FIXME the C version of this test is fast, but in TS it's illegal to subtract TimeValues and - // get a negative result fast: true - timeout: 2 sec + // FIXME the C version of this test is fast, but in TS it's illegal to subtract TimeValues and get + // a negative result fast: true + timeout: 2 sec } main reactor GetTime { - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) {= - let logical = util.getCurrentLogicalTime(); - console.log("Logical time is " + logical); + reaction(t) {= + let logical = util.getCurrentLogicalTime(); + console.log("Logical time is " + logical); - let elapsed = util.getElapsedLogicalTime(); - console.log("Elapsed logical time is " + elapsed); + let elapsed = util.getElapsedLogicalTime(); + console.log("Elapsed logical time is " + elapsed); - let physical = util.getCurrentPhysicalTime(); - console.log("Physical time is " + physical); + let physical = util.getCurrentPhysicalTime(); + console.log("Physical time is " + physical); - console.log("Time lag is " + physical.subtract(logical)); - =} + console.log("Time lag is " + physical.subtract(logical)); + =} } diff --git a/test/TypeScript/src/HelloWorld.lf b/test/TypeScript/src/HelloWorld.lf index 85d560e3a7..2fe705929b 100644 --- a/test/TypeScript/src/HelloWorld.lf +++ b/test/TypeScript/src/HelloWorld.lf @@ -1,11 +1,11 @@ target TypeScript reactor HelloWorldInside { - timer t + timer t - reaction(t) {= console.log("Hello World."); =} + reaction(t) {= console.log("Hello World."); =} } main reactor HelloWorld { - a = new HelloWorldInside() + a = new HelloWorldInside() } diff --git a/test/TypeScript/src/Hierarchy.lf b/test/TypeScript/src/Hierarchy.lf index 4f3ea06e98..7a7b2d72ee 100644 --- a/test/TypeScript/src/Hierarchy.lf +++ b/test/TypeScript/src/Hierarchy.lf @@ -2,53 +2,53 @@ target TypeScript reactor Source { - output out: number - timer t + output out: number + timer t - reaction(t) -> out {= - console.log("Producing from source"); - out = 1; - =} + reaction(t) -> out {= + console.log("Producing from source"); + out = 1; + =} } reactor Gain { - input x: number - output out: number + input x: number + output out: number - reaction(x) -> out {= - console.log("Gain received " + x); - out = (x as number) * 2; - =} + reaction(x) -> out {= + console.log("Gain received " + x); + out = (x as number) * 2; + =} } reactor Print { - input x: number - - reaction(x) {= - x = x as number; - console.log("Received: " + x); - if (x != 2) { - util.requestErrorStop("Expected 2.") - } - =} + input x: number + + reaction(x) {= + x = x as number; + console.log("Received: " + x); + if (x != 2) { + util.requestErrorStop("Expected 2.") + } + =} } reactor GainContainer { - input x: number - output out: number - output out2: number - gain = new Gain() - x -> gain.x - gain.out -> out - gain.out -> out2 + input x: number + output out: number + output out2: number + gain = new Gain() + x -> gain.x + gain.out -> out + gain.out -> out2 } main reactor Hierarchy { - source = new Source() - container = new GainContainer() - print = new Print() - print2 = new Print() - source.out -> container.x - container.out -> print.x - container.out -> print2.x + source = new Source() + container = new GainContainer() + print = new Print() + print2 = new Print() + source.out -> container.x + container.out -> print.x + container.out -> print2.x } diff --git a/test/TypeScript/src/Import.lf b/test/TypeScript/src/Import.lf index afdc8465ca..aecf259f71 100644 --- a/test/TypeScript/src/Import.lf +++ b/test/TypeScript/src/Import.lf @@ -1,13 +1,13 @@ // This tests the ability to import a reactor definition that itself imports a reactor definition. target TypeScript { - timeout: 2 sec + timeout: 2 sec } import Imported from "lib/Imported.lf" main reactor Import { - timer t - a = new Imported() + timer t + a = new Imported() - reaction(t) -> a.x {= a.x = 42; =} + reaction(t) -> a.x {= a.x = 42; =} } diff --git a/test/TypeScript/src/Microsteps.lf b/test/TypeScript/src/Microsteps.lf index 44130af36b..a04b454a92 100644 --- a/test/TypeScript/src/Microsteps.lf +++ b/test/TypeScript/src/Microsteps.lf @@ -1,39 +1,39 @@ target TypeScript reactor Destination { - input x: number - input y: number + input x: number + input y: number - reaction(x, y) {= - let elapsed = util.getElapsedLogicalTime(); - console.log("Time since start: " + elapsed); - if (! elapsed.isEqualTo(TimeValue.zero())) { - util.requestErrorStop("Expected elapsed time to be 0, but it was " + elapsed); - } - let count = 0; - if (x) { - console.log("x is present."); - count++; - } - if (y) { - console.log("y is present."); - count++; - } - if (count != 1) { - util.requestErrorStop("Expected exactly one input to be present but got " + count) - } - =} + reaction(x, y) {= + let elapsed = util.getElapsedLogicalTime(); + console.log("Time since start: " + elapsed); + if (! elapsed.isEqualTo(TimeValue.zero())) { + util.requestErrorStop("Expected elapsed time to be 0, but it was " + elapsed); + } + let count = 0; + if (x) { + console.log("x is present."); + count++; + } + if (y) { + console.log("y is present."); + count++; + } + if (count != 1) { + util.requestErrorStop("Expected exactly one input to be present but got " + count) + } + =} } main reactor Microsteps { - timer start - logical action repeat - d = new Destination() + timer start + logical action repeat + d = new Destination() - reaction(start) -> d.x, repeat {= - d.x = 1; - actions.repeat.schedule(0, null); - =} + reaction(start) -> d.x, repeat {= + d.x = 1; + actions.repeat.schedule(0, null); + =} - reaction(repeat) -> d.y {= d.y = 1; =} + reaction(repeat) -> d.y {= d.y = 1; =} } diff --git a/test/TypeScript/src/Minimal.lf b/test/TypeScript/src/Minimal.lf index 737ec70336..54a1aa7ae9 100644 --- a/test/TypeScript/src/Minimal.lf +++ b/test/TypeScript/src/Minimal.lf @@ -2,7 +2,7 @@ target TypeScript main reactor Minimal { - timer t + timer t - reaction(t) {= console.log("Hello World."); =} + reaction(t) {= console.log("Hello World."); =} } diff --git a/test/TypeScript/src/MovingAverage.lf b/test/TypeScript/src/MovingAverage.lf index b8018d92c2..19e767e3e2 100644 --- a/test/TypeScript/src/MovingAverage.lf +++ b/test/TypeScript/src/MovingAverage.lf @@ -1,5 +1,6 @@ -// Demonstration of a state variable that is an array. The MovingAverage reactor computes the moving -// average of the last four inputs and produces that as output. The source is a counting sequence. +// Demonstration of a state variable that is an array. The MovingAverage reactor +// computes the moving average of the last four inputs and produces that as +// output. The source is a counting sequence. target TypeScript { timeout: 1 sec, fast: true diff --git a/test/TypeScript/src/MultipleContained.lf b/test/TypeScript/src/MultipleContained.lf index 4c5fb53db8..d381c2c697 100644 --- a/test/TypeScript/src/MultipleContained.lf +++ b/test/TypeScript/src/MultipleContained.lf @@ -2,35 +2,35 @@ target TypeScript reactor Contained { - output trigger: number - input in1: number - input in2: number + output trigger: number + input in1: number + input in2: number - reaction(startup) -> trigger {= trigger = 42; =} + reaction(startup) -> trigger {= trigger = 42; =} - reaction(in1) {= - in1 = in1 as number; - console.log("in1 received " + in1); - if (in1 != 42) { - util.requestErrorStop("FAILED: Expected 42.") - } - =} + reaction(in1) {= + in1 = in1 as number; + console.log("in1 received " + in1); + if (in1 != 42) { + util.requestErrorStop("FAILED: Expected 42.") + } + =} - reaction(in2) {= - in2 = in2 as number; - console.log("in2 received " + in2); - if (in2 != 42) { - util.requestErrorStop("FAILED: Expected 42.") - } - =} + reaction(in2) {= + in2 = in2 as number; + console.log("in2 received " + in2); + if (in2 != 42) { + util.requestErrorStop("FAILED: Expected 42.") + } + =} } main reactor MultipleContained { - c = new Contained() + c = new Contained() - reaction(c.trigger) -> c.in1, c.in2 {= - c.trigger = c.trigger as number; - c.in1 = c.trigger; - c.in2 = c.trigger; - =} + reaction(c.trigger) -> c.in1, c.in2 {= + c.trigger = c.trigger as number; + c.in1 = c.trigger; + c.in2 = c.trigger; + =} } diff --git a/test/TypeScript/src/Preamble.lf b/test/TypeScript/src/Preamble.lf index fbbe9a67b4..51cd0a1868 100644 --- a/test/TypeScript/src/Preamble.lf +++ b/test/TypeScript/src/Preamble.lf @@ -1,20 +1,20 @@ target TypeScript { - timeout: 2 sec + timeout: 2 sec } main reactor Preamble { - preamble {= - function add42( i:number) { - return i + 42; - } - =} - timer t + preamble {= + function add42( i:number) { + return i + 42; + } + =} + timer t - reaction(t) {= - let s = "42"; - let radix = 10; - let i = parseInt(s, radix); - console.log("Converted string " + s + " to number " + i); - console.log("42 plus 42 is " + add42(42)); - =} + reaction(t) {= + let s = "42"; + let radix = 10; + let i = parseInt(s, radix); + console.log("Converted string " + s + " to number " + i); + console.log("42 plus 42 is " + add42(42)); + =} } diff --git a/test/TypeScript/src/ReadOutputOfContainedReactor.lf b/test/TypeScript/src/ReadOutputOfContainedReactor.lf index 8591fe96bc..01b725e181 100644 --- a/test/TypeScript/src/ReadOutputOfContainedReactor.lf +++ b/test/TypeScript/src/ReadOutputOfContainedReactor.lf @@ -1,4 +1,5 @@ -// Test reacting to and reading outputs from a contained reactor in various permutations. +// Test reacting to and reading outputs from a contained reactor in various +// permutations. target TypeScript reactor Contained { diff --git a/test/TypeScript/src/Schedule.lf b/test/TypeScript/src/Schedule.lf index 66464ccf70..fa779cc5bd 100644 --- a/test/TypeScript/src/Schedule.lf +++ b/test/TypeScript/src/Schedule.lf @@ -2,25 +2,25 @@ target TypeScript reactor ScheduleLogicalAction { - input x: number - logical action a + input x: number + logical action a - reaction(x) -> a {= actions.a.schedule(TimeValue.msec(200), null) =} + reaction(x) -> a {= actions.a.schedule(TimeValue.msec(200), null) =} - reaction(a) {= - let elapsedTime = util.getElapsedLogicalTime(); - console.log("Action triggered at logical time " + elapsedTime + " (sec, nsec) after start."); - if (!elapsedTime.isEqualTo(TimeValue.msec(200))) { - util.requestErrorStop("Expected action time to be 200 msec. It was " + elapsedTime + " (sec, nsec).") - } else { - console.log("Success! Action time was " + elapsedTime); - } - =} + reaction(a) {= + let elapsedTime = util.getElapsedLogicalTime(); + console.log("Action triggered at logical time " + elapsedTime + " (sec, nsec) after start."); + if (!elapsedTime.isEqualTo(TimeValue.msec(200))) { + util.requestErrorStop("Expected action time to be 200 msec. It was " + elapsedTime + " (sec, nsec).") + } else { + console.log("Success! Action time was " + elapsedTime); + } + =} } main reactor { - a = new ScheduleLogicalAction() - timer t + a = new ScheduleLogicalAction() + timer t - reaction(t) -> a.x {= a.x = 1; =} + reaction(t) -> a.x {= a.x = 1; =} } diff --git a/test/TypeScript/src/ScheduleLogicalAction.lf b/test/TypeScript/src/ScheduleLogicalAction.lf index ee49204288..84e8fbe1cb 100644 --- a/test/TypeScript/src/ScheduleLogicalAction.lf +++ b/test/TypeScript/src/ScheduleLogicalAction.lf @@ -1,5 +1,5 @@ -// This checks that a logical action is scheduled the specified logical time after the current -// logical time. +// This checks that a logical action is scheduled the specified logical time +// after the current logical time. target TypeScript { fast: true, timeout: 3 sec diff --git a/test/TypeScript/src/SendingInside.lf b/test/TypeScript/src/SendingInside.lf index a22f637deb..ca4b6489b3 100644 --- a/test/TypeScript/src/SendingInside.lf +++ b/test/TypeScript/src/SendingInside.lf @@ -1,5 +1,5 @@ -// This tests a reactor that contains another reactor and also has its own reaction that routes -// inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own +// reaction that routes inputs to the contained reactor. target TypeScript { timeout: 10 sec, fast: true diff --git a/test/TypeScript/src/SendingInside2.lf b/test/TypeScript/src/SendingInside2.lf index f013b75549..a537191e4b 100644 --- a/test/TypeScript/src/SendingInside2.lf +++ b/test/TypeScript/src/SendingInside2.lf @@ -1,19 +1,19 @@ target TypeScript reactor Printer { - input x: number + input x: number - reaction(x) {= - console.log("Inside reactor received:" + x ); - if (x != 1) { - util.requestErrorStop("ERROR: Expected 1."); - } - =} + reaction(x) {= + console.log("Inside reactor received:" + x ); + if (x != 1) { + util.requestErrorStop("ERROR: Expected 1."); + } + =} } main reactor SendingInside2 { - timer t - p = new Printer() + timer t + p = new Printer() - reaction(t) -> p.x {= p.x = 1; =} + reaction(t) -> p.x {= p.x = 1; =} } diff --git a/test/TypeScript/src/SendsPointerTest.lf b/test/TypeScript/src/SendsPointerTest.lf index 6bdbf514af..3c80613b52 100644 --- a/test/TypeScript/src/SendsPointerTest.lf +++ b/test/TypeScript/src/SendsPointerTest.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated object, which it passes to Print. Reference counting -// ensures that the struct is freed. +// Source produces a dynamically allocated object, which it passes to Print. +// Reference counting ensures that the struct is freed. target TypeScript reactor SendsPointer { diff --git a/test/TypeScript/src/SimpleDeadline.lf b/test/TypeScript/src/SimpleDeadline.lf index d02fe0044c..a518e04e5e 100644 --- a/test/TypeScript/src/SimpleDeadline.lf +++ b/test/TypeScript/src/SimpleDeadline.lf @@ -1,5 +1,6 @@ -// Test local deadline, where a deadline is associated with a reaction definition. This test -// triggers a reaction exactly once with a deadline violation. +// Test local deadline, where a deadline is associated with a reaction +// definition. This test triggers a reaction exactly once with a deadline +// violation. target TypeScript reactor Deadline(threshold: time = 100 msec) { diff --git a/test/TypeScript/src/SimpleImport.lf b/test/TypeScript/src/SimpleImport.lf index 364c2f2ab3..72b6baa031 100644 --- a/test/TypeScript/src/SimpleImport.lf +++ b/test/TypeScript/src/SimpleImport.lf @@ -3,6 +3,6 @@ target TypeScript import HelloWorldInside from "HelloWorld.lf" main reactor SimpleImport { - a = new HelloWorldInside() - b = new HelloWorldInside() + a = new HelloWorldInside() + b = new HelloWorldInside() } diff --git a/test/TypeScript/src/SlowingClockPhysical.lf b/test/TypeScript/src/SlowingClockPhysical.lf index f1c65a92b7..53bc3f9da4 100644 --- a/test/TypeScript/src/SlowingClockPhysical.lf +++ b/test/TypeScript/src/SlowingClockPhysical.lf @@ -1,10 +1,12 @@ /** - * Output events at physical times at least 100, 300, and 600 msec after the start time. This uses a - * physical action with a minimum interarrival time of 100 msec. The reactor increases the - * interarrival time with each invocation of the schedule() function. The timestamps of the events - * will be exact because the physical time at which schedule() is called is always way smaller than - * the time of the last invocation (or start time) plus the minimum interarrival time. Hence, the - * minimum interarrival time always determines the time of the next event. + * Output events at physical times at least 100, 300, and 600 msec after the + * start time. This uses a physical action with a minimum interarrival time of + * 100 msec. The reactor increases the interarrival time with each invocation of + * the schedule() function. The timestamps of the events will be exact because + * the physical time at which schedule() is called is always way smaller than + * the time of the last invocation (or start time) plus the minimum interarrival + * time. Hence, the minimum interarrival time always determines the time of the + * next event. */ target TypeScript { timeout: 1 sec diff --git a/test/TypeScript/src/Stop.lf b/test/TypeScript/src/Stop.lf index 3464239b0a..6104c418d5 100644 --- a/test/TypeScript/src/Stop.lf +++ b/test/TypeScript/src/Stop.lf @@ -1,5 +1,6 @@ /** - * A test for the util.requestStop() functionality in TypeScript target Lingua Franca. + * A test for the util.requestStop() functionality in TypeScript target Lingua + * Franca. * * @author Soroush Bateni * @author Byeong-gil Jun diff --git a/test/TypeScript/src/Stride.lf b/test/TypeScript/src/Stride.lf index dd0ef5359e..04d7805d0b 100644 --- a/test/TypeScript/src/Stride.lf +++ b/test/TypeScript/src/Stride.lf @@ -1,5 +1,5 @@ -// This example illustrates state variables and parameters on the wiki. For this test, success is -// just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this +// test, success is just compiling and running. target TypeScript { timeout: 2 sec, fast: true diff --git a/test/TypeScript/src/StructPrint.lf b/test/TypeScript/src/StructPrint.lf index 201f788779..e75d9ead37 100644 --- a/test/TypeScript/src/StructPrint.lf +++ b/test/TypeScript/src/StructPrint.lf @@ -1,5 +1,5 @@ -// Source produces a dynamically allocated struct, which it passes to Print. Reference counting -// ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. +// Reference counting ensures that the struct is freed. target TypeScript reactor Source { diff --git a/test/TypeScript/src/TestForPreviousOutput.lf b/test/TypeScript/src/TestForPreviousOutput.lf index 0c37653ad0..c088ac1d6d 100644 --- a/test/TypeScript/src/TestForPreviousOutput.lf +++ b/test/TypeScript/src/TestForPreviousOutput.lf @@ -3,40 +3,40 @@ target TypeScript reactor Source { - output out: number + output out: number - reaction(startup) -> out {= - // Note: Math.random can't be seeded - // Randomly produce an output or not. - if (Math.random() > 0.5) { - out = 21; - } - =} + reaction(startup) -> out {= + // Note: Math.random can't be seeded + // Randomly produce an output or not. + if (Math.random() > 0.5) { + out = 21; + } + =} - reaction(startup) -> out {= - let previous_output = out; - if (previous_output) { - out = 2 * previous_output; - } else { - out = 42; - } - =} + reaction(startup) -> out {= + let previous_output = out; + if (previous_output) { + out = 2 * previous_output; + } else { + out = 42; + } + =} } reactor Sink { - input x: number + input x: number - reaction(x) {= - x = x as number; - console.log("Received " + x); - if (x != 42) { - util.requestErrorStop("FAILED: Expected 42.") - } - =} + reaction(x) {= + x = x as number; + console.log("Received " + x); + if (x != 42) { + util.requestErrorStop("FAILED: Expected 42.") + } + =} } main reactor TestForPreviousOutput { - s = new Source() - d = new Sink() - s.out -> d.x + s = new Source() + d = new Sink() + s.out -> d.x } diff --git a/test/TypeScript/src/TimeLimit.lf b/test/TypeScript/src/TimeLimit.lf index c837a4cbb4..05a2a5a3b3 100644 --- a/test/TypeScript/src/TimeLimit.lf +++ b/test/TypeScript/src/TimeLimit.lf @@ -1,6 +1,7 @@ -// Test that the stop function can be used to internally impose a a time limit. This is also used to -// test performance (number of reactions per second). Correct output for this 1, 2, 3, 4. Failure -// for this test is failing to halt or getting the wrong data. +// Test that the stop function can be used to internally impose a a time limit. +// This is also used to test performance (number of reactions per second). +// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt +// or getting the wrong data. target TypeScript { fast: true, logging: INFO diff --git a/test/TypeScript/src/Wcet.lf b/test/TypeScript/src/Wcet.lf index 34fdd18dfc..a68e54c877 100644 --- a/test/TypeScript/src/Wcet.lf +++ b/test/TypeScript/src/Wcet.lf @@ -2,44 +2,44 @@ target TypeScript reactor Source { - output out1: number - output out2: number - timer t - - reaction(t) -> out1, out2 {= - out1 = 5; - out2 = 10; - =} + output out1: number + output out2: number + timer t + + reaction(t) -> out1, out2 {= + out1 = 5; + out2 = 10; + =} } reactor Work { - input in1: number - input in2: number - output out: number - - reaction(in1, in2) -> out {= - let ret:number; - if ((in1 as number) > 10) { - ret = (in2 as number) * (in1 as number); - } else { - ret = (in2 as number) + (in1 as number); - } - out = ret; - =} + input in1: number + input in2: number + output out: number + + reaction(in1, in2) -> out {= + let ret:number; + if ((in1 as number) > 10) { + ret = (in2 as number) * (in1 as number); + } else { + ret = (in2 as number) + (in1 as number); + } + out = ret; + =} } reactor Print { - input x: number + input x: number - reaction(x) {= console.log("Received: " + x); =} + reaction(x) {= console.log("Received: " + x); =} } main reactor Wcet { - source = new Source() - work = new Work() - print = new Print() + source = new Source() + work = new Work() + print = new Print() - source.out1 -> work.in1 - source.out2 -> work.in2 - work.out -> print.x + source.out1 -> work.in1 + source.out2 -> work.in2 + work.out -> print.x } diff --git a/test/TypeScript/src/docker/HelloWorldContainerized.lf b/test/TypeScript/src/docker/HelloWorldContainerized.lf index 75de9313a7..66b96312e9 100644 --- a/test/TypeScript/src/docker/HelloWorldContainerized.lf +++ b/test/TypeScript/src/docker/HelloWorldContainerized.lf @@ -1,9 +1,9 @@ target TypeScript { - docker: true + docker: true } import HelloWorldInside from "../HelloWorld.lf" main reactor HelloWorldContainerized { - a = new HelloWorldInside() + a = new HelloWorldInside() } diff --git a/test/TypeScript/src/federated/ChainWithDelay.lf b/test/TypeScript/src/federated/ChainWithDelay.lf index 286506258f..7c37d47d7f 100644 --- a/test/TypeScript/src/federated/ChainWithDelay.lf +++ b/test/TypeScript/src/federated/ChainWithDelay.lf @@ -5,7 +5,7 @@ * @author Youri Su */ target TypeScript { - timeout: 3 msec + timeout: 3 msec } import Count from "../lib/Count.lf" @@ -13,9 +13,9 @@ import InternalDelay from "../lib/InternalDelay.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - c = new Count(period = 1 msec) - i = new InternalDelay(delay = 500 usec) - t = new TestCount(numInputs = 3) - c.out -> i.inp - i.out -> t.inp + c = new Count(period = 1 msec) + i = new InternalDelay(delay = 500 usec) + t = new TestCount(numInputs = 3) + c.out -> i.inp + i.out -> t.inp } diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf index a85228f606..50f510cdcd 100644 --- a/test/TypeScript/src/federated/DistributedCount.lf +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee * @author Hokeun Kim */ diff --git a/test/TypeScript/src/federated/DistributedDoublePort.lf b/test/TypeScript/src/federated/DistributedDoublePort.lf index 056216e687..d3a2636661 100644 --- a/test/TypeScript/src/federated/DistributedDoublePort.lf +++ b/test/TypeScript/src/federated/DistributedDoublePort.lf @@ -1,6 +1,7 @@ /** - * Test the case for when two upstream federates send messages to a downstream federte on two - * different ports. One message should carry a microstep delay relative to the other message. + * Test the case for when two upstream federates send messages to a downstream + * federte on two different ports. One message should carry a microstep delay + * relative to the other message. * * @author Soroush Bateni * @author Hokeun Kim @@ -39,7 +40,9 @@ reactor Print { } =} - reaction(shutdown) {= console.log("SUCCESS: messages were at least one microstep apart."); =} + reaction(shutdown) {= + console.log("SUCCESS: messages were at least one microstep apart."); + =} } federated reactor DistributedDoublePort { diff --git a/test/TypeScript/src/federated/DistributedLoopedAction.lf b/test/TypeScript/src/federated/DistributedLoopedAction.lf index 46170a0d1f..02a7f5dc62 100644 --- a/test/TypeScript/src/federated/DistributedLoopedAction.lf +++ b/test/TypeScript/src/federated/DistributedLoopedAction.lf @@ -1,5 +1,6 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken into account. + * Test a sender-receiver network system that relies on microsteps being taken + * into account. * * @author Soroush Bateni * @author Hokeun Kim @@ -17,7 +18,8 @@ reactor Receiver(takeBreakAfter: number = 10, breakInterval: time = 400 msec) { state breaks: number = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more sensible log output. + // but forces the logical time to advance Comment this line for a more + // sensible log output. reaction(inp) {= console.log("At tag (" + util.getElapsedLogicalTime() + ", " + util.getCurrentTag().microstep + ") received value " + inp); totalReceivedMessages++; diff --git a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf index aa14ba553d..842f13f74c 100644 --- a/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/TypeScript/src/federated/DistributedLoopedPhysicalAction.lf @@ -1,6 +1,7 @@ /** - * Test a sender-receiver network system that is similar to DistributedLoopedAction, but it uses a - * physical action rather than a logical action. + * Test a sender-receiver network system that is similar to + * DistributedLoopedAction, but it uses a physical action rather than a logical + * action. * * @author Soroush Bateni * @author Hokeun Kim @@ -35,7 +36,8 @@ reactor Receiver(takeBreakAfter: number = 10, breakInterval: time = 550 msec) { state breaks: number = 0 timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more sensible log output. + // but forces the logical time to advance Comment this line for a more + // sensible log output. reaction(inp) {= console.log("At tag (" + util.getElapsedLogicalTime() + ", " + util.getCurrentTag().microstep + ") received value " + inp); totalReceivedMessages++; diff --git a/test/TypeScript/src/federated/DistributedStop.lf b/test/TypeScript/src/federated/DistributedStop.lf index 6815501b4a..c0dd04149a 100644 --- a/test/TypeScript/src/federated/DistributedStop.lf +++ b/test/TypeScript/src/federated/DistributedStop.lf @@ -1,5 +1,6 @@ /** - * Test for util.requestStop() in federated execution with centralized coordination. + * Test for util.requestStop() in federated execution with centralized + * coordination. * * @author Soroush Bateni * @author Byeong-gil Jun diff --git a/test/TypeScript/src/federated/DistributedStopZero.lf b/test/TypeScript/src/federated/DistributedStopZero.lf index c85c3a21cf..846b98343c 100644 --- a/test/TypeScript/src/federated/DistributedStopZero.lf +++ b/test/TypeScript/src/federated/DistributedStopZero.lf @@ -8,66 +8,66 @@ target TypeScript reactor Sender { - output out: number - timer t(0, 1 usec) + output out: number + timer t(0, 1 usec) - reaction(t) -> out {= - console.log(`Sending 42 at ${util.getElapsedLogicalTime()}, ` - + `${util.getCurrentTag().microstep}).`); - out = 42; + reaction(t) -> out {= + console.log(`Sending 42 at ${util.getElapsedLogicalTime()}, ` + + `${util.getCurrentTag().microstep}).`); + out = 42; - let zero = util.getStartTag(); - if (util.getCurrentTag().isSimultaneousWith(zero)) { - // Request stop at ((0 secs, 0 nsecs), 0) - console.log(`Requesting stop at ${util.getElapsedLogicalTime()}, ` - + `${util.getCurrentTag().microstep}).`); - util.requestStop(); - } - =} + let zero = util.getStartTag(); + if (util.getCurrentTag().isSimultaneousWith(zero)) { + // Request stop at ((0 secs, 0 nsecs), 0) + console.log(`Requesting stop at ${util.getElapsedLogicalTime()}, ` + + `${util.getCurrentTag().microstep}).`); + util.requestStop(); + } + =} - reaction(shutdown) {= - if (!util.getElapsedLogicalTime().isEqualTo(TimeValue.usec(0))|| - util.getCurrentTag().microstep !== 1) { - util.requestErrorStop(`ERROR: Sender failed to stop the federation in time. ` - + `Stopping at (${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); - } - console.log(`SUCCESS: Successfully stopped the federation at ` - + `(${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); - =} + reaction(shutdown) {= + if (!util.getElapsedLogicalTime().isEqualTo(TimeValue.usec(0))|| + util.getCurrentTag().microstep !== 1) { + util.requestErrorStop(`ERROR: Sender failed to stop the federation in time. ` + + `Stopping at (${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); + } + console.log(`SUCCESS: Successfully stopped the federation at ` + + `(${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); + =} } reactor Receiver { - input in1: number + input in1: number - reaction(in1) {= - console.log(`Received ${in1} at (${util.getElapsedLogicalTime()}, ` + reaction(in1) {= + console.log(`Received ${in1} at (${util.getElapsedLogicalTime()}, ` + + `${util.getCurrentTag().microstep}).`); + let zero = util.getStartTag(); + if (util.getCurrentTag().isSimultaneousWith(zero)) { + // Request stop at ((0 secs, 0 nsecs), 0) + console.log(`Requesting stop at ${util.getElapsedLogicalTime()}, ` + `${util.getCurrentTag().microstep}).`); - let zero = util.getStartTag(); - if (util.getCurrentTag().isSimultaneousWith(zero)) { - // Request stop at ((0 secs, 0 nsecs), 0) - console.log(`Requesting stop at ${util.getElapsedLogicalTime()}, ` - + `${util.getCurrentTag().microstep}).`); - util.requestStop(); - } - =} + util.requestStop(); + } + =} - reaction(shutdown) {= - // Sender should have requested stop earlier than the receiver. - // Therefore, the shutdown events must occur at ((0 secs, 0 nsecs), 0) on the - // receiver. - if (!util.getElapsedLogicalTime().isEqualTo(TimeValue.usec(0)) || - util.getCurrentTag().microstep !== 1) { - util.requestErrorStop(`ERROR: Receiver failed to stop the federation at the right time. ` - + `Stopping at (${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); - } - console.log(`SUCCESS: Successfully stopped the federation at ` - + `(${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); - =} + reaction(shutdown) {= + // Sender should have requested stop earlier than the receiver. + // Therefore, the shutdown events must occur at ((0 secs, 0 nsecs), 0) on the + // receiver. + if (!util.getElapsedLogicalTime().isEqualTo(TimeValue.usec(0)) || + util.getCurrentTag().microstep !== 1) { + util.requestErrorStop(`ERROR: Receiver failed to stop the federation at the right time. ` + + `Stopping at (${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); + } + console.log(`SUCCESS: Successfully stopped the federation at ` + + `(${util.getElapsedLogicalTime()}, ${util.getCurrentTag().microstep}).`); + =} } federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in1 + sender.out -> receiver.in1 } diff --git a/test/TypeScript/src/federated/HelloDistributed.lf b/test/TypeScript/src/federated/HelloDistributed.lf index a8376910c1..1189270ab1 100644 --- a/test/TypeScript/src/federated/HelloDistributed.lf +++ b/test/TypeScript/src/federated/HelloDistributed.lf @@ -1,7 +1,8 @@ /** - * Test a particularly simple form of a distributed deterministic system where a federation that - * receives timestamped messages has only those messages as triggers. Therefore, no additional - * coordination of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a + * federation that receives timestamped messages has only those messages as + * triggers. Therefore, no additional coordination of the advancement of time + * (HLA or Ptides) is needed. * @author Edward A. Lee * @author Hokeun Kim */ @@ -44,5 +45,7 @@ federated reactor HelloDistributed at localhost { d = new Destination() // Reactor d is in federate Destination s.out -> d.inp // This version preserves the timestamp. - reaction(startup) {= console.log("Printing something in top-level federated reactor."); =} + reaction(startup) {= + console.log("Printing something in top-level federated reactor."); + =} } diff --git a/test/TypeScript/src/federated/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/LoopDistributedCentralized.lf index 042d917106..bb52679489 100644 --- a/test/TypeScript/src/federated/LoopDistributedCentralized.lf +++ b/test/TypeScript/src/federated/LoopDistributedCentralized.lf @@ -1,5 +1,6 @@ /** - * This tests a feedback loop with physical actions and centralized coordination. + * This tests a feedback loop with physical actions and centralized + * coordination. * * @author Edward A. Lee * @author Hokeun Kim diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf index ac82edbd0d..2c791377f7 100644 --- a/test/TypeScript/src/federated/LoopDistributedDouble.lf +++ b/test/TypeScript/src/federated/LoopDistributedDouble.lf @@ -1,5 +1,6 @@ /** - * This tests a feedback loop with physical actions and centralized coordination. + * This tests a feedback loop with physical actions and centralized + * coordination. * * @author Edward A. Lee * @author Hokeun Kim diff --git a/test/TypeScript/src/federated/SimpleFederated.lf b/test/TypeScript/src/federated/SimpleFederated.lf index 804eec10aa..e85627d073 100644 --- a/test/TypeScript/src/federated/SimpleFederated.lf +++ b/test/TypeScript/src/federated/SimpleFederated.lf @@ -1,16 +1,16 @@ target TypeScript { - timeout: 2 secs + timeout: 2 secs } reactor Fed { - input inp: number - output out: number + input inp: number + output out: number } federated reactor { - fed1 = new Fed() - fed2 = new Fed() + fed1 = new Fed() + fed2 = new Fed() - fed1.out -> fed2.inp - fed2.out -> fed1.inp + fed1.out -> fed2.inp + fed2.out -> fed1.inp } diff --git a/test/TypeScript/src/federated/StopAtShutdown.lf b/test/TypeScript/src/federated/StopAtShutdown.lf index 44ca12aa04..200e773e82 100644 --- a/test/TypeScript/src/federated/StopAtShutdown.lf +++ b/test/TypeScript/src/federated/StopAtShutdown.lf @@ -4,30 +4,30 @@ * Original bug discovered by Steven Wong */ target TypeScript { - timeout: 2 sec + timeout: 2 sec } reactor A { - input inp: number + input inp: number - reaction(startup) {= console.log("Hello World!"); =} + reaction(startup) {= console.log("Hello World!"); =} - reaction(inp) {= console.log("Got it"); =} + reaction(inp) {= console.log("Got it"); =} - reaction(shutdown) {= util.requestStop(); =} + reaction(shutdown) {= util.requestStop(); =} } reactor B { - output out: number - timer t(1 sec) + output out: number + timer t(1 sec) - reaction(t) -> out {= out = 1; =} + reaction(t) -> out {= out = 1; =} - reaction(shutdown) {= util.requestStop(); =} + reaction(shutdown) {= util.requestStop(); =} } federated reactor { - a = new A() - b = new B() - b.out -> a.inp + a = new A() + b = new B() + b.out -> a.inp } diff --git a/test/TypeScript/src/federated/TopLevelArtifacts.lf b/test/TypeScript/src/federated/TopLevelArtifacts.lf index cd5909a1f7..917da033f5 100644 --- a/test/TypeScript/src/federated/TopLevelArtifacts.lf +++ b/test/TypeScript/src/federated/TopLevelArtifacts.lf @@ -1,10 +1,11 @@ /** - * Test whether top-level reactions, actions, and ports are handled appropriately. + * Test whether top-level reactions, actions, and ports are handled + * appropriately. * * Currently, these artifacts are replicated on all federates. * - * @note This just tests for the correctness of the code generation. These top-level artifacts might - * be disallowed in the future. + * @note This just tests for the correctness of the code generation. These + * top-level artifacts might be disallowed in the future. * @author Youri Su */ target TypeScript { diff --git a/test/TypeScript/src/lib/Imported.lf b/test/TypeScript/src/lib/Imported.lf index 52ed1e4c85..9b8506f39b 100644 --- a/test/TypeScript/src/lib/Imported.lf +++ b/test/TypeScript/src/lib/Imported.lf @@ -1,14 +1,14 @@ // This is used by the test for the ability to import a reactor definition that itself imports a // reactor definition. target TypeScript { - timeout: 2 sec + timeout: 2 sec } import ImportedAgain from "ImportedAgain.lf" reactor Imported { - input x: number - a = new ImportedAgain() + input x: number + a = new ImportedAgain() - reaction(x) -> a.x {= a.x = (x as number); =} + reaction(x) -> a.x {= a.x = (x as number); =} } diff --git a/test/TypeScript/src/lib/ImportedAgain.lf b/test/TypeScript/src/lib/ImportedAgain.lf index a98513b692..e10ab4aa53 100644 --- a/test/TypeScript/src/lib/ImportedAgain.lf +++ b/test/TypeScript/src/lib/ImportedAgain.lf @@ -1,16 +1,16 @@ // This is used by the test for the ability to import a reactor definition that itself imports a // reactor definition. target TypeScript { - timeout: 2 sec + timeout: 2 sec } reactor ImportedAgain { - input x: number + input x: number - reaction(x) {= - console.log("Received: " + x); - if ((x as number) != 42) { - util.requestErrorStop("ERROR: Expected input to be 42. Got: " + x); - } - =} + reaction(x) {= + console.log("Received: " + x); + if ((x as number) != 42) { + util.requestErrorStop("ERROR: Expected input to be 42. Got: " + x); + } + =} } diff --git a/test/TypeScript/src/lib/LoopedActionSender.lf b/test/TypeScript/src/lib/LoopedActionSender.lf index eb441ff2e8..7da4c133b0 100644 --- a/test/TypeScript/src/lib/LoopedActionSender.lf +++ b/test/TypeScript/src/lib/LoopedActionSender.lf @@ -7,9 +7,10 @@ target TypeScript /** - * @param takeBreakAfter: Indicates how many messages are sent in consecutive superdense time - * @param breakInterval: Determines how long the reactor should take a break after sending - * takeBreakAfter messages. + * @param takeBreakAfter: Indicates how many messages are sent in consecutive + * superdense time + * @param breakInterval: Determines how long the reactor should take a break + * after sending takeBreakAfter messages. */ reactor Sender(takeBreakAfter: number = 10, breakInterval: time = 400 msec) { output out: number diff --git a/test/TypeScript/src/lib/TestCount.lf b/test/TypeScript/src/lib/TestCount.lf index d5181f10f0..822b4c64b1 100644 --- a/test/TypeScript/src/lib/TestCount.lf +++ b/test/TypeScript/src/lib/TestCount.lf @@ -1,6 +1,7 @@ /** - * Test that a counting sequence of inputs starts with the specified start parameter value, - * increments by the specified stride, and receives the specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start + * parameter value, increments by the specified stride, and receives the + * specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. diff --git a/test/TypeScript/src/multiport/BankMulticast.lf b/test/TypeScript/src/multiport/BankMulticast.lf index 84a7acb6c6..64a944deea 100644 --- a/test/TypeScript/src/multiport/BankMulticast.lf +++ b/test/TypeScript/src/multiport/BankMulticast.lf @@ -3,35 +3,35 @@ * the container's output port. */ target TypeScript { - timeout: 3 sec + timeout: 3 sec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Foo { - input inp: number - output out: number + input inp: number + output out: number - c = new Count() - c.out -> out + c = new Count() + c.out -> out - d = new TestCount(numInputs = 4) - inp -> d.inp + d = new TestCount(numInputs = 4) + inp -> d.inp } reactor Bar { - output[4] out: number + output[4] out: number - foo = new[4] Foo() + foo = new[4] Foo() - foo.out -> foo.inp - foo.out -> out + foo.out -> foo.inp + foo.out -> out } main reactor { - bar = new Bar() + bar = new Bar() - d = new[4] TestCount(numInputs = 4) - bar.out -> d.inp + d = new[4] TestCount(numInputs = 4) + bar.out -> d.inp } diff --git a/test/TypeScript/src/multiport/BankReactionsInContainer.lf b/test/TypeScript/src/multiport/BankReactionsInContainer.lf index 485f1074f1..b14ca33f70 100644 --- a/test/TypeScript/src/multiport/BankReactionsInContainer.lf +++ b/test/TypeScript/src/multiport/BankReactionsInContainer.lf @@ -1,4 +1,6 @@ -/** This tests an output that is broadcast back to a multiport input of a bank. */ +/** + * This tests an output that is broadcast back to a multiport input of a bank. + */ target TypeScript { timeout: 1 sec } diff --git a/test/TypeScript/src/multiport/BankSelfBroadcast.lf b/test/TypeScript/src/multiport/BankSelfBroadcast.lf index 50d6683592..cf5af4bee3 100644 --- a/test/TypeScript/src/multiport/BankSelfBroadcast.lf +++ b/test/TypeScript/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport input of the same - * reactors in the bank so that each reactor in the bank receives the output produced by itself and - * each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport + * input of the same reactors in the bank so that each reactor in the bank + * receives the output produced by itself and each other reactor. * * @author Edward A. Lee * @author Christian Menard diff --git a/test/TypeScript/src/multiport/Broadcast.lf b/test/TypeScript/src/multiport/Broadcast.lf index b1fbacb029..c43b81f736 100644 --- a/test/TypeScript/src/multiport/Broadcast.lf +++ b/test/TypeScript/src/multiport/Broadcast.lf @@ -1,24 +1,24 @@ target TypeScript reactor Source { - output out: number + output out: number - reaction(startup) -> out {= out = 42; =} + reaction(startup) -> out {= out = 42; =} } reactor Sink { - input inp: number + input inp: number - reaction(inp) {= - console.log("Received " + inp); - if (inp != 42) { - util.requestErrorStop("Error: expected " + 42); - } - =} + reaction(inp) {= + console.log("Received " + inp); + if (inp != 42) { + util.requestErrorStop("Error: expected " + 42); + } + =} } main reactor { - source = new Source() - sink = new[4] Sink() - (source.out)+ -> sink.inp + source = new Source() + sink = new[4] Sink() + (source.out)+ -> sink.inp } diff --git a/test/TypeScript/src/multiport/MultiportFromBank.lf b/test/TypeScript/src/multiport/MultiportFromBank.lf index 53f8c523ee..18896eed2a 100644 --- a/test/TypeScript/src/multiport/MultiportFromBank.lf +++ b/test/TypeScript/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf index c896494897..ffc394b26c 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf index 1462f157a5..b960ff2bc1 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,14 +1,14 @@ // Check multiport output to bank of recipients. Here, the bank is smaller than the width of the // sending port. target TypeScript { - timeout: 2 sec + timeout: 2 sec } import Destination from "MultiportFromBank.lf" import Container from "MultiportFromBankHierarchy.lf" main reactor MultiportFromBankHierarchyAfter { - a = new Container(portWidth = 4) - b = new Destination(portWidth = 4) - a.out -> b.inp after 1 sec + a = new Container(portWidth = 4) + b = new Destination(portWidth = 4) + a.out -> b.inp after 1 sec } diff --git a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf index b294dc3995..5627652b2f 100644 --- a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical +// reactor. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportIn.lf b/test/TypeScript/src/multiport/MultiportIn.lf index 346eeffa11..97a36c08d2 100644 --- a/test/TypeScript/src/multiport/MultiportIn.lf +++ b/test/TypeScript/src/multiport/MultiportIn.lf @@ -1,5 +1,5 @@ -// This is a version of the test that uses a multiport input at the destination. Its purpose is to -// test multiport inputs. +// This is a version of the test that uses a multiport input at the destination. +// Its purpose is to test multiport inputs. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportInParameterized.lf b/test/TypeScript/src/multiport/MultiportInParameterized.lf index 3ff15c14dc..fb11c5e102 100644 --- a/test/TypeScript/src/multiport/MultiportInParameterized.lf +++ b/test/TypeScript/src/multiport/MultiportInParameterized.lf @@ -1,5 +1,5 @@ -// This is a version of the Threaded test that uses a multiport input at the destination. Its -// purpose is to test multiport inputs. +// This is a version of the Threaded test that uses a multiport input at the +// destination. Its purpose is to test multiport inputs. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportMutableInput.lf b/test/TypeScript/src/multiport/MultiportMutableInput.lf index c570b5b245..11120e8d30 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInput.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInput.lf @@ -1,5 +1,6 @@ -// Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. -// It modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a ints on a multiport, which it passes to Scale. Scale +// requests a writable copy. It modifies it and passes it to Print. It gets +// freed after Print is done with it. target TypeScript reactor Source { diff --git a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf index d91b6aa8ac..382f444df7 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf @@ -1,6 +1,7 @@ -// Source produces a dynamically allocated arrays on a multiport, which it passes to Scale. Scale -// requests a writable copy, which, instead of copying, it just gets ownership of the original -// array. It modifies it and passes it to Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated arrays on a multiport, which it +// passes to Scale. Scale requests a writable copy, which, instead of copying, +// it just gets ownership of the original array. It modifies it and passes it to +// Print. It gets freed after Print is done with it. target TypeScript reactor Source { diff --git a/test/TypeScript/src/multiport/MultiportToBank.lf b/test/TypeScript/src/multiport/MultiportToBank.lf index e0e864cedd..efc4fcca4d 100644 --- a/test/TypeScript/src/multiport/MultiportToBank.lf +++ b/test/TypeScript/src/multiport/MultiportToBank.lf @@ -1,28 +1,28 @@ target TypeScript reactor Source { - output[4] out: number + output[4] out: number - reaction(startup) -> out {= - for (let i = 0 ; i < out.length; i++) { - out[i] = i; - } - =} + reaction(startup) -> out {= + for (let i = 0 ; i < out.length; i++) { + out[i] = i; + } + =} } reactor Sink { - input inp: number + input inp: number - reaction(inp) {= - console.log("Received " + inp); - if (inp != this.getBankIndex()) { - util.requestErrorStop("Error: expected " + this.getBankIndex()); - } - =} + reaction(inp) {= + console.log("Received " + inp); + if (inp != this.getBankIndex()) { + util.requestErrorStop("Error: expected " + this.getBankIndex()); + } + =} } main reactor MultiportToBank { - source = new Source() - sink = new[4] Sink() - source.out -> sink.inp + source = new Source() + sink = new[4] Sink() + source.out -> sink.inp } diff --git a/test/TypeScript/src/multiport/MultiportToBankAfter.lf b/test/TypeScript/src/multiport/MultiportToBankAfter.lf index b8005863ff..ee10df94c6 100644 --- a/test/TypeScript/src/multiport/MultiportToBankAfter.lf +++ b/test/TypeScript/src/multiport/MultiportToBankAfter.lf @@ -1,4 +1,5 @@ -// Check multiport output to bank of recipients where the width of the bank is inferred. +// Check multiport output to bank of recipients where the width of the bank is +// inferred. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToBankDouble.lf b/test/TypeScript/src/multiport/MultiportToBankDouble.lf index 32b5e86b7c..e618dd898d 100644 --- a/test/TypeScript/src/multiport/MultiportToBankDouble.lf +++ b/test/TypeScript/src/multiport/MultiportToBankDouble.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients where the source has two reactions that write to the -// output. +// Check multiport output to bank of recipients where the source has two +// reactions that write to the output. target TypeScript { timeout: 2 sec } @@ -13,8 +13,8 @@ reactor Source { } =} - // Test also that multiple appearances of the same effect port do not result in multiple - // allocations of memory for the port. + // Test also that multiple appearances of the same effect port do not result + // in multiple allocations of memory for the port. reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) for (let i = 0; i < out.length; i++) { diff --git a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf index a2e60ef8c2..7420704ce1 100644 --- a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the -// sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than +// the width of the sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToHierarchy.lf b/test/TypeScript/src/multiport/MultiportToHierarchy.lf index 01edeb3192..c620000872 100644 --- a/test/TypeScript/src/multiport/MultiportToHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,6 @@ -// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that -// the destination reactor has width wider than the sender, so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical +// reactor. Note that the destination reactor has width wider than the sender, +// so one input is dangling. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf index ba1f578f09..737603a5bd 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input. Destination port is wider than sending port. +// Check multiport output to multiport input. Destination port is wider than +// sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/MultiportToPort.lf b/test/TypeScript/src/multiport/MultiportToPort.lf index caf87f1d3b..a00d482fe8 100644 --- a/test/TypeScript/src/multiport/MultiportToPort.lf +++ b/test/TypeScript/src/multiport/MultiportToPort.lf @@ -1,4 +1,5 @@ -// Check multiport output to multiport input. Destination port is wider than sending port. +// Check multiport output to multiport input. Destination port is wider than +// sending port. target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/multiport/PipelineAfter.lf b/test/TypeScript/src/multiport/PipelineAfter.lf index b11455cb47..5835193d9c 100644 --- a/test/TypeScript/src/multiport/PipelineAfter.lf +++ b/test/TypeScript/src/multiport/PipelineAfter.lf @@ -1,36 +1,36 @@ target TypeScript reactor Source { - output out: number + output out: number - reaction(startup) -> out {= out = 40; =} + reaction(startup) -> out {= out = 40; =} } reactor Compute { - input inp: number - output out: number + input inp: number + output out: number - reaction(inp) -> out {= out = (inp as number) + 2; =} + reaction(inp) -> out {= out = (inp as number) + 2; =} } reactor Sink { - input inp: number - - reaction(inp) {= - console.log("Received " + inp); - if (inp != 42) { - util.requestErrorStop("ERROR: expected 42!"); - } - if (!util.getElapsedLogicalTime().isEqualTo(TimeValue.sec(1))) { - util.requestErrorStop("ERROR: Expected to receive input after one second."); - } - =} + input inp: number + + reaction(inp) {= + console.log("Received " + inp); + if (inp != 42) { + util.requestErrorStop("ERROR: expected 42!"); + } + if (!util.getElapsedLogicalTime().isEqualTo(TimeValue.sec(1))) { + util.requestErrorStop("ERROR: Expected to receive input after one second."); + } + =} } main reactor { - source = new Source() - compute = new Compute() - sink = new Sink() + source = new Source() + compute = new Compute() + sink = new Sink() - source.out, compute.out -> compute.inp, sink.inp after 500 msec + source.out, compute.out -> compute.inp, sink.inp after 500 msec } diff --git a/test/TypeScript/src/multiport/ReactionsToNested.lf b/test/TypeScript/src/multiport/ReactionsToNested.lf index 514973762a..055e08d086 100644 --- a/test/TypeScript/src/multiport/ReactionsToNested.lf +++ b/test/TypeScript/src/multiport/ReactionsToNested.lf @@ -1,4 +1,5 @@ -// This test connects a simple counting source to tester that checks against its own count. +// This test connects a simple counting source to tester that checks against its +// own count. target TypeScript { timeout: 1 sec } diff --git a/test/TypeScript/src/serialization/ProtoNoPacking.lf b/test/TypeScript/src/serialization/ProtoNoPacking.lf index 02c6f71c0e..8e35981c6c 100644 --- a/test/TypeScript/src/serialization/ProtoNoPacking.lf +++ b/test/TypeScript/src/serialization/ProtoNoPacking.lf @@ -11,36 +11,36 @@ * Building protobuf from source is slow, so avoid doing that if possible. */ target TypeScript { - protobufs: ProtoHelloWorld.proto + protobufs: ProtoHelloWorld.proto } reactor SourceProto { - output out: ProtoHelloWorld.ProtoHelloWorld + output out: ProtoHelloWorld.ProtoHelloWorld - reaction(startup) -> out {= - // The contents of a compiled proto file are imported in - // TypeScript as "import * as <.protoFileName>". So the constructor - // for class ProtoHelloWorld from the file ProtoHelloWorld.proto is - // ProtoHelloWorld.ProtoHelloWorld() - let helloObject = new ProtoHelloWorld.ProtoHelloWorld(); - helloObject.setName("Hello World"); - helloObject.setNumber(42); - out = helloObject; - =} + reaction(startup) -> out {= + // The contents of a compiled proto file are imported in + // TypeScript as "import * as <.protoFileName>". So the constructor + // for class ProtoHelloWorld from the file ProtoHelloWorld.proto is + // ProtoHelloWorld.ProtoHelloWorld() + let helloObject = new ProtoHelloWorld.ProtoHelloWorld(); + helloObject.setName("Hello World"); + helloObject.setNumber(42); + out = helloObject; + =} } reactor SinkProto { - input x: ProtoHelloWorld.ProtoHelloWorld + input x: ProtoHelloWorld.ProtoHelloWorld - reaction(x) {= - if (x !== undefined) { - console.log(`Received: name=${x.getName()}, number=${x.getNumber()}.`) - } - =} + reaction(x) {= + if (x !== undefined) { + console.log(`Received: name=${x.getName()}, number=${x.getNumber()}.`) + } + =} } main reactor ProtoNoPacking { - s = new SourceProto() - d = new SinkProto() - s.out -> d.x + s = new SourceProto() + d = new SinkProto() + s.out -> d.x } diff --git a/test/TypeScript/src/target/AfterNoTypes.lf b/test/TypeScript/src/target/AfterNoTypes.lf index 5d698cb3e0..b3477bbf55 100644 --- a/test/TypeScript/src/target/AfterNoTypes.lf +++ b/test/TypeScript/src/target/AfterNoTypes.lf @@ -1,4 +1,5 @@ -// This test demonstrates that after can be used on connections with ports that have no types. +// This test demonstrates that after can be used on connections with ports that +// have no types. target TypeScript { fast: false, timeout: 3 sec From 66e95e6b8abe990d900d431c7ac85d713d78b46c Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 17 May 2023 23:21:16 -0700 Subject: [PATCH 415/709] Reformat all integration tests. --- build.gradle | 2 +- .../src/org/lflang/ast/FormattingUtils.java | 4 +- test/C/src/ActionDelay.lf | 60 ++-- test/C/src/ActionIsPresent.lf | 38 +-- test/C/src/After.lf | 73 +++-- test/C/src/AfterCycles.lf | 98 +++---- test/C/src/AfterOverlapped.lf | 64 ++--- test/C/src/AfterZero.lf | 83 +++--- test/C/src/Alignment.lf | 165 ++++++----- test/C/src/ArrayAsParameter.lf | 67 +++-- test/C/src/ArrayAsType.lf | 62 ++-- test/C/src/ArrayFree.lf | 38 +-- test/C/src/ArrayFreeMultiple.lf | 60 ++-- test/C/src/ArrayParallel.lf | 10 +- test/C/src/ArrayPrint.lf | 84 +++--- test/C/src/ArrayScale.lf | 37 ++- test/C/src/CharLiteralInitializer.lf | 14 +- test/C/src/Composition.lf | 59 ++-- test/C/src/CompositionAfter.lf | 47 ++-- test/C/src/CompositionInheritance.lf | 81 +++--- test/C/src/CountSelf.lf | 30 +- test/C/src/Deadline.lf | 91 +++--- test/C/src/DeadlineHandledAbove.lf | 76 ++--- test/C/src/DeadlineInherited.lf | 30 +- test/C/src/DeadlinePriority.lf | 28 +- test/C/src/DeadlineWithAfterDelay.lf | 38 +-- test/C/src/DeadlineWithBanks.lf | 85 +++--- test/C/src/DeadlineZero.lf | 26 +- test/C/src/DelayArray.lf | 91 +++--- test/C/src/DelayArrayWithAfter.lf | 107 ++++--- test/C/src/DelayInt.lf | 96 ++++--- test/C/src/DelayPointer.lf | 106 +++---- test/C/src/DelayString.lf | 73 +++-- test/C/src/DelayStruct.lf | 80 +++--- test/C/src/DelayStructWithAfter.lf | 42 +-- test/C/src/DelayStructWithAfterOverlapped.lf | 76 ++--- test/C/src/DelayedAction.lf | 36 +-- test/C/src/DoubleInvocation.lf | 75 +++-- test/C/src/DoublePort.lf | 59 ++-- test/C/src/DoubleReaction.lf | 68 ++--- test/C/src/DoubleTrigger.lf | 43 ++- test/C/src/FilePkgReader.lf | 78 ++--- test/C/src/FileReader.lf | 64 ++--- test/C/src/FloatLiteral.lf | 39 ++- test/C/src/Gain.lf | 48 ++-- test/C/src/GetMicroStep.lf | 26 +- test/C/src/Hello.lf | 89 +++--- test/C/src/HelloWorld.lf | 36 +-- test/C/src/Hierarchy2.lf | 86 +++--- test/C/src/IdentifierLength.lf | 52 ++-- test/C/src/ImportComposition.lf | 47 ++-- test/C/src/InheritanceAction.lf | 49 ++-- test/C/src/ManualDelayedReaction.lf | 70 +++-- test/C/src/Methods.lf | 30 +- test/C/src/MethodsRecursive.lf | 22 +- test/C/src/MethodsSameName.lf | 38 +-- test/C/src/MovingAverage.lf | 79 +++--- test/C/src/MultipleContained.lf | 65 +++-- test/C/src/MultipleOutputs.lf | 47 ++-- test/C/src/NativeListsAndTimes.lf | 41 ++- test/C/src/NestedTriggeredReactions.lf | 40 +-- test/C/src/ParameterHierarchy.lf | 20 +- test/C/src/ParameterizedState.lf | 6 +- test/C/src/PeriodicDesugared.lf | 30 +- test/C/src/PhysicalConnection.lf | 28 +- test/C/src/PingPong.lf | 83 +++--- test/C/src/PreambleFileLevel.lf | 7 +- test/C/src/PreambleInherited.lf | 10 +- test/C/src/ReadOutputOfContainedReactor.lf | 75 +++-- test/C/src/RequestStop.lf | 17 +- test/C/src/ScheduleLogicalAction.lf | 62 ++-- test/C/src/ScheduleValue.lf | 16 +- test/C/src/SelfLoop.lf | 56 ++-- test/C/src/SendingInside.lf | 42 +-- test/C/src/SendsPointerTest.lf | 36 +-- test/C/src/SetArray.lf | 68 ++--- test/C/src/SetToken.lf | 30 +- test/C/src/SimpleDeadline.lf | 67 +++-- test/C/src/SlowingClock.lf | 65 +++-- test/C/src/SlowingClockPhysical.lf | 69 +++-- test/C/src/Starvation.lf | 98 +++---- test/C/src/Stop.lf | 88 +++--- test/C/src/StopZero.lf | 172 +++++------ test/C/src/Stride.lf | 46 +-- test/C/src/StructAsState.lf | 28 +- test/C/src/StructAsType.lf | 50 ++-- test/C/src/StructAsTypeDirect.lf | 38 +-- test/C/src/StructParallel.lf | 81 +++--- test/C/src/StructPrint.lf | 46 +-- test/C/src/StructScale.lf | 90 +++--- test/C/src/SubclassesAndStartup.lf | 54 ++-- test/C/src/TestForPreviousOutput.lf | 14 +- test/C/src/TimeLimit.lf | 67 +++-- test/C/src/TimeState.lf | 6 +- test/C/src/Timeout.lf | 62 ++-- test/C/src/TimeoutZero.lf | 65 +++-- test/C/src/ToReactionNested.lf | 44 +-- test/C/src/TriggerDownstreamOnlyIfPresent2.lf | 49 ++-- test/C/src/UnconnectedInput.lf | 60 ++-- test/C/src/arduino/AnalogReadSerial.lf | 25 +- test/C/src/arduino/Blink.lf | 23 +- test/C/src/arduino/BlinkAttemptThreading.lf | 27 +- test/C/src/arduino/BlinkMBED.lf | 23 +- test/C/src/arduino/DigitalReadSerial.lf | 29 +- test/C/src/arduino/Fade.lf | 45 ++- test/C/src/arduino/ReadAnalogVoltage.lf | 37 ++- test/C/src/concurrent/AsyncCallback.lf | 118 ++++---- test/C/src/concurrent/AsyncCallbackDrop.lf | 119 ++++---- test/C/src/concurrent/AsyncCallbackReplace.lf | 119 ++++---- test/C/src/concurrent/CompositionThreaded.lf | 47 ++-- .../DeadlineHandledAboveThreaded.lf | 76 ++--- test/C/src/concurrent/DeadlineThreaded.lf | 91 +++--- test/C/src/concurrent/DelayIntThreaded.lf | 90 +++--- .../src/concurrent/DoubleReactionThreaded.lf | 68 ++--- test/C/src/concurrent/GainThreaded.lf | 48 ++-- test/C/src/concurrent/HelloThreaded.lf | 89 +++--- test/C/src/concurrent/PingPongThreaded.lf | 86 +++--- test/C/src/concurrent/ScheduleAt.lf | 160 +++++------ test/C/src/concurrent/ScheduleTwice.lf | 54 ++-- .../C/src/concurrent/ScheduleTwiceThreaded.lf | 48 ++-- .../C/src/concurrent/SendingInsideThreaded.lf | 42 +-- test/C/src/concurrent/StarvationThreaded.lf | 99 ++++--- test/C/src/concurrent/StopThreaded.lf | 96 +++---- test/C/src/concurrent/StopZeroThreaded.lf | 171 ++++++----- test/C/src/concurrent/Threaded.lf | 97 ++++--- test/C/src/concurrent/ThreadedMultiport.lf | 101 ++++--- test/C/src/concurrent/ThreadedThreaded.lf | 96 ++++--- test/C/src/concurrent/TimeLimitThreaded.lf | 66 ++--- test/C/src/concurrent/TimeoutThreaded.lf | 65 +++-- test/C/src/concurrent/TimeoutZeroThreaded.lf | 66 ++--- test/C/src/concurrent/Tracing.lf | 147 +++++----- .../DistributedCountContainerized.lf | 25 +- test/C/src/federated/BroadcastFeedback.lf | 42 ++- .../BroadcastFeedbackWithHierarchy.lf | 48 ++-- test/C/src/federated/CycleDetection.lf | 76 ++--- test/C/src/federated/DecentralizedP2PComm.lf | 78 +++-- .../DecentralizedP2PUnbalancedTimeout.lf | 69 +++-- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 67 +++-- test/C/src/federated/DistributedBank.lf | 22 +- .../federated/DistributedBankToMultiport.lf | 38 +-- test/C/src/federated/DistributedCount.lf | 53 ++-- .../DistributedCountDecentralized.lf | 74 +++-- .../DistributedCountDecentralizedLate.lf | 97 ++++--- ...tributedCountDecentralizedLateHierarchy.lf | 137 +++++---- .../src/federated/DistributedCountPhysical.lf | 76 ++--- .../DistributedCountPhysicalAfterDelay.lf | 69 +++-- .../DistributedCountPhysicalDecentralized.lf | 76 ++--- test/C/src/federated/DistributedDoublePort.lf | 59 ++-- .../DistributedLogicalActionUpstreamLong.lf | 92 +++--- .../src/federated/DistributedLoopedAction.lf | 101 ++++--- .../DistributedLoopedActionDecentralized.lf | 194 ++++++------- .../DistributedLoopedPhysicalAction.lf | 129 ++++----- test/C/src/federated/DistributedMultiport.lf | 56 ++-- .../federated/DistributedMultiportToBank.lf | 52 ++-- .../federated/DistributedMultiportToken.lf | 64 ++--- .../src/federated/DistributedNetworkOrder.lf | 101 ++++--- .../DistributedPhysicalActionUpstream.lf | 76 ++--- .../DistributedPhysicalActionUpstreamLong.lf | 132 ++++----- test/C/src/federated/DistributedStop.lf | 193 +++++++------ test/C/src/federated/DistributedToken.lf | 147 +++++----- .../C/src/federated/FederatedFilePkgReader.lf | 90 +++--- test/C/src/federated/FederatedFileReader.lf | 90 +++--- test/C/src/federated/FeedbackDelay.lf | 88 +++--- test/C/src/federated/FeedbackDelaySimple.lf | 54 ++-- test/C/src/federated/HelloDistributed.lf | 71 +++-- test/C/src/federated/LevelPattern.lf | 50 ++-- .../federated/LoopDistributedCentralized.lf | 67 +++-- .../federated/LoopDistributedCentralized2.lf | 107 ++++--- ...oopDistributedCentralizedPhysicalAction.lf | 107 ++++--- .../LoopDistributedCentralizedPrecedence.lf | 78 ++--- ...stributedCentralizedPrecedenceHierarchy.lf | 93 +++--- .../federated/LoopDistributedDecentralized.lf | 121 ++++---- test/C/src/federated/LoopDistributedDouble.lf | 153 +++++----- test/C/src/federated/PhysicalSTP.lf | 65 ++--- test/C/src/federated/PingPongDistributed.lf | 25 +- .../federated/PingPongDistributedPhysical.lf | 96 ++++--- test/C/src/federated/TopLevelArtifacts.lf | 45 ++- .../failing/SimpleFederatedAuthenticated.lf | 25 +- test/C/src/lib/Count.lf | 8 +- test/C/src/lib/FileLevelPreamble.lf | 9 +- test/C/src/lib/InternalDelay.lf | 10 +- test/C/src/lib/LoopedActionSender.lf | 47 ++-- test/C/src/lib/PassThrough.lf | 6 +- test/C/src/lib/Test.lf | 20 +- test/C/src/lib/TestCount.lf | 45 ++- test/C/src/lib/TestCountMultiport.lf | 66 ++--- .../modal_models/BanksCount3ModesComplex.lf | 116 ++++---- .../modal_models/BanksCount3ModesSimple.lf | 47 ++-- .../src/modal_models/BanksModalStateReset.lf | 96 +++---- test/C/src/modal_models/ConvertCaseTest.lf | 234 ++++++++------- test/C/src/modal_models/Count3Modes.lf | 96 ++++--- test/C/src/modal_models/MixedReactions.lf | 68 ++--- test/C/src/modal_models/ModalActions.lf | 150 +++++----- test/C/src/modal_models/ModalAfter.lf | 146 +++++----- test/C/src/modal_models/ModalCycleBreaker.lf | 101 ++++--- .../src/modal_models/ModalNestedReactions.lf | 2 +- .../src/modal_models/ModalStartupShutdown.lf | 266 +++++++++--------- test/C/src/modal_models/ModalStateReset.lf | 136 +++++---- .../C/src/modal_models/ModalStateResetAuto.lf | 132 +++++---- test/C/src/modal_models/ModalTimers.lf | 100 ++++--- .../MultipleOutputFeeder_2Connections.lf | 95 +++---- ...ultipleOutputFeeder_ReactionConnections.lf | 97 +++---- test/C/src/modal_models/util/TraceTesting.lf | 116 ++++---- test/C/src/multiport/BankIndexInitializer.lf | 48 ++-- .../src/multiport/BankMultiportToReaction.lf | 50 ++-- .../src/multiport/BankReactionsInContainer.lf | 112 ++++---- test/C/src/multiport/BankSelfBroadcast.lf | 62 ++-- test/C/src/multiport/BankToBank.lf | 58 ++-- test/C/src/multiport/BankToBankMultiport.lf | 68 ++--- .../src/multiport/BankToBankMultiportAfter.lf | 68 ++--- test/C/src/multiport/BankToMultiport.lf | 46 +-- test/C/src/multiport/BankToReaction.lf | 24 +- test/C/src/multiport/Broadcast.lf | 48 ++-- test/C/src/multiport/BroadcastAfter.lf | 56 ++-- .../C/src/multiport/BroadcastMultipleAfter.lf | 62 ++-- test/C/src/multiport/DualBanks.lf | 54 ++-- test/C/src/multiport/DualBanksMultiport.lf | 66 ++--- test/C/src/multiport/FullyConnected.lf | 58 ++-- .../multiport/FullyConnectedAddressable.lf | 80 +++--- .../FullyConnectedAddressableAfter.lf | 8 +- test/C/src/multiport/MultiportFromBank.lf | 56 ++-- .../multiport/MultiportFromBankHierarchy.lf | 20 +- .../C/src/multiport/MultiportFromHierarchy.lf | 89 +++--- test/C/src/multiport/MultiportFromReaction.lf | 68 ++--- test/C/src/multiport/MultiportIn.lf | 92 +++--- .../src/multiport/MultiportInParameterized.lf | 95 ++++--- test/C/src/multiport/MultiportMutableInput.lf | 63 ++--- .../multiport/MultiportMutableInputArray.lf | 107 ++++--- test/C/src/multiport/MultiportOut.lf | 98 +++---- test/C/src/multiport/MultiportToBank.lf | 73 +++-- test/C/src/multiport/MultiportToBankAfter.lf | 67 +++-- test/C/src/multiport/MultiportToBankDouble.lf | 75 +++-- .../src/multiport/MultiportToBankHierarchy.lf | 66 ++--- test/C/src/multiport/MultiportToHierarchy.lf | 79 +++--- test/C/src/multiport/MultiportToMultiport.lf | 74 ++--- test/C/src/multiport/MultiportToMultiport2.lf | 50 ++-- .../multiport/MultiportToMultiport2After.lf | 52 ++-- .../multiport/MultiportToMultiportArray.lf | 85 +++--- .../MultiportToMultiportParameter.lf | 74 ++--- test/C/src/multiport/MultiportToPort.lf | 63 ++--- test/C/src/multiport/MultiportToReaction.lf | 64 ++--- test/C/src/multiport/NestedBanks.lf | 92 +++--- .../C/src/multiport/NestedInterleavedBanks.lf | 44 +-- .../src/multiport/ReactionToContainedBank.lf | 22 +- .../src/multiport/ReactionToContainedBank2.lf | 26 +- .../ReactionToContainedBankMultiport.lf | 27 +- test/C/src/multiport/ReactionsToNested.lf | 47 ++-- test/C/src/multiport/Sparse.lf | 70 ++--- test/C/src/multiport/SparseFallback.lf | 74 ++--- .../TriggerDownstreamOnlyIfPresent.lf | 67 +++-- .../BankMultiportToReactionNoInlining.lf | 34 +-- .../no_inlining/BankToReactionNoInlining.lf | 14 +- test/C/src/no_inlining/Count.lf | 14 +- test/C/src/no_inlining/CountHierarchy.lf | 20 +- test/C/src/no_inlining/IntPrint.lf | 18 +- .../MultiportToReactionNoInlining.lf | 46 +-- .../serialization/ROSBuiltInSerialization.lf | 68 +++-- .../ROSBuiltInSerializationSharedPtr.lf | 67 +++-- test/C/src/target/FederatedFiles.lf | 12 +- test/C/src/target/HelloWorldCCPP.lf | 40 +-- test/C/src/token/TokenContainedPrint.lf | 30 +- test/C/src/token/TokenContainedPrintBank.lf | 47 ++-- test/C/src/token/TokenContainedSource.lf | 54 ++-- test/C/src/token/TokenContainedSourceBank.lf | 61 ++-- test/C/src/token/TokenDelayTest.lf | 12 +- test/C/src/token/TokenMutable.lf | 26 +- test/C/src/token/TokenSourcePrint.lf | 8 +- test/C/src/token/TokenSourceScalePrint.lf | 16 +- test/C/src/token/lib/Token.lf | 130 +++++---- test/C/src/zephyr/HelloZephyr.lf | 4 +- test/C/src/zephyr/Timer.lf | 16 +- test/C/src/zephyr/lib/Led.lf | 52 ++-- test/Cpp/src/ActionDelay.lf | 64 ++--- test/Cpp/src/ActionIsPresent.lf | 40 +-- test/Cpp/src/ActionValues.lf | 70 ++--- test/Cpp/src/After.lf | 79 +++--- test/Cpp/src/AfterOverlapped.lf | 56 ++-- test/Cpp/src/AfterZero.lf | 89 +++--- test/Cpp/src/Alignment.lf | 163 ++++++----- test/Cpp/src/ArrayAsParameter.lf | 61 ++-- test/Cpp/src/ArrayPrint.lf | 87 +++--- test/Cpp/src/ArrayScale.lf | 39 ++- test/Cpp/src/CharLiteralInitializer.lf | 14 +- test/Cpp/src/Composition.lf | 61 ++-- test/Cpp/src/CompositionAfter.lf | 61 ++-- test/Cpp/src/CountTest.lf | 28 +- test/Cpp/src/Deadline.lf | 91 +++--- test/Cpp/src/DeadlineHandledAbove.lf | 62 ++-- test/Cpp/src/DelayInt.lf | 80 +++--- test/Cpp/src/DelayedAction.lf | 34 +-- test/Cpp/src/DoubleInvocation.lf | 78 +++-- test/Cpp/src/DoublePort.lf | 81 +++--- test/Cpp/src/DoubleReaction.lf | 70 ++--- test/Cpp/src/DoubleTrigger.lf | 39 ++- test/Cpp/src/FloatLiteral.lf | 31 +- test/Cpp/src/Gain.lf | 34 +-- test/Cpp/src/GetMicroStep.lf | 40 +-- test/Cpp/src/Hello.lf | 80 +++--- test/Cpp/src/Hierarchy2.lf | 88 +++--- test/Cpp/src/ImportComposition.lf | 53 ++-- test/Cpp/src/ManualDelayedReaction.lf | 52 ++-- test/Cpp/src/Methods.lf | 32 +-- test/Cpp/src/MovingAverage.lf | 106 +++---- test/Cpp/src/NativeListsAndTimes.lf | 51 ++-- test/Cpp/src/NestedTriggeredReactions.lf | 44 +-- test/Cpp/src/ParameterHierarchy.lf | 23 +- test/Cpp/src/ParameterizedState.lf | 16 +- test/Cpp/src/ParametersOutOfOrder.lf | 18 +- test/Cpp/src/PeriodicDesugared.lf | 42 +-- test/Cpp/src/PhysicalConnection.lf | 52 ++-- test/Cpp/src/Pipeline.lf | 62 ++-- test/Cpp/src/ReadOutputOfContainedReactor.lf | 79 +++--- test/Cpp/src/ScheduleLogicalAction.lf | 62 ++-- test/Cpp/src/SelfLoop.lf | 56 ++-- test/Cpp/src/SendingInside.lf | 42 +-- test/Cpp/src/SimpleDeadline.lf | 57 ++-- test/Cpp/src/SlowingClock.lf | 57 ++-- test/Cpp/src/SlowingClockPhysical.lf | 63 ++--- test/Cpp/src/Stride.lf | 32 +-- test/Cpp/src/StructPrint.lf | 51 ++-- test/Cpp/src/StructScale.lf | 31 +- test/Cpp/src/TimeLimit.lf | 67 +++-- test/Cpp/src/TimeState.lf | 6 +- test/Cpp/src/Timeout_Test.lf | 48 ++-- test/Cpp/src/TimerIsPresent.lf | 86 +++--- test/Cpp/src/ToReactionNested.lf | 46 +-- .../src/TriggerDownstreamOnlyIfPresent2.lf | 47 ++-- test/Cpp/src/concurrent/AsyncCallback.lf | 100 +++---- test/Cpp/src/concurrent/AsyncCallback2.lf | 66 ++--- .../Cpp/src/concurrent/CompositionThreaded.lf | 61 ++-- .../DeadlineHandledAboveThreaded.lf | 62 ++-- test/Cpp/src/concurrent/DeadlineThreaded.lf | 91 +++--- test/Cpp/src/concurrent/DelayIntThreaded.lf | 80 +++--- .../src/concurrent/DoubleReactionThreaded.lf | 70 ++--- test/Cpp/src/concurrent/GainThreaded.lf | 34 +-- test/Cpp/src/concurrent/HelloThreaded.lf | 80 +++--- .../src/concurrent/SendingInsideThreaded.lf | 42 +-- test/Cpp/src/concurrent/Threaded.lf | 104 ++++--- test/Cpp/src/concurrent/ThreadedThreaded.lf | 86 +++--- test/Cpp/src/concurrent/TimeLimitThreaded.lf | 69 +++-- test/Cpp/src/enclave/EnclaveBank.lf | 36 +-- test/Cpp/src/enclave/EnclaveBankEach.lf | 39 ++- test/Cpp/src/enclave/EnclaveBroadcast.lf | 48 ++-- test/Cpp/src/enclave/EnclaveCommunication.lf | 58 ++-- test/Cpp/src/enclave/EnclaveCommunication2.lf | 56 ++-- .../enclave/EnclaveCommunicationDelayed.lf | 58 ++-- .../enclave/EnclaveCommunicationDelayed2.lf | 56 ++-- .../EnclaveCommunicationDelayedLocalEvents.lf | 68 ++--- .../EnclaveCommunicationLocalEvents.lf | 68 ++--- .../EnclaveCommunicationMultiportToBank.lf | 90 +++--- ...laveCommunicationMultiportToBankDelayed.lf | 90 +++--- ...EnclaveCommunicationMultiportToBankEach.lf | 90 +++--- ...CommunicationMultiportToBankEachDelayed.lf | 90 +++--- ...ommunicationMultiportToBankEachPhysical.lf | 90 +++--- ...aveCommunicationMultiportToBankPhysical.lf | 90 +++--- .../enclave/EnclaveCommunicationPhysical.lf | 58 ++-- ...EnclaveCommunicationPhysicalLocalEvents.lf | 68 ++--- test/Cpp/src/enclave/EnclaveCycle.lf | 100 +++---- test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf | 104 +++---- test/Cpp/src/enclave/EnclaveHelloWorld.lf | 8 +- test/Cpp/src/enclave/EnclaveHierarchy.lf | 44 ++- .../Cpp/src/enclave/EnclaveMultiportToPort.lf | 69 +++-- .../src/enclave/EnclaveMultiportToPort2.lf | 67 +++-- test/Cpp/src/enclave/EnclaveShutdown.lf | 48 ++-- .../enclave/EnclaveSparseUpstreamEvents.lf | 78 ++--- .../EnclaveSparseUpstreamEventsDelayed.lf | 78 ++--- .../EnclaveSparseUpstreamEventsPhysical.lf | 78 ++--- test/Cpp/src/enclave/EnclaveTimeout.lf | 40 +-- .../enclave/EnclaveUpstreamPhysicalAction.lf | 114 ++++---- .../EnclaveUpstreamPhysicalActionDelayed.lf | 114 ++++---- test/Cpp/src/enclave/FastAndSlow.lf | 44 ++- test/Cpp/src/lib/Count.lf | 14 +- test/Cpp/src/lib/LoopedActionSender.lf | 35 ++- test/Cpp/src/multiport/BankSelfBroadcast.lf | 56 ++-- test/Cpp/src/multiport/BankToBank.lf | 59 ++-- test/Cpp/src/multiport/BankToBankMultiport.lf | 78 ++--- .../src/multiport/BankToBankMultiportAfter.lf | 94 +++---- test/Cpp/src/multiport/BankToMultiport.lf | 44 +-- test/Cpp/src/multiport/Broadcast.lf | 42 +-- test/Cpp/src/multiport/BroadcastAfter.lf | 54 ++-- .../src/multiport/BroadcastMultipleAfter.lf | 60 ++-- test/Cpp/src/multiport/FullyConnected.lf | 60 ++-- .../multiport/FullyConnectedAddressable.lf | 82 +++--- .../FullyConnectedAddressableAfter.lf | 8 +- .../src/multiport/IndexIntoMultiportOutput.lf | 95 ++++--- test/Cpp/src/multiport/Multiport.lf | 91 +++--- test/Cpp/src/multiport/MultiportFromBank.lf | 54 ++-- .../multiport/MultiportFromBankHierarchy.lf | 60 ++-- .../MultiportFromBankHierarchyAfter.lf | 70 ++--- .../src/multiport/MultiportFromHierarchy.lf | 91 +++--- test/Cpp/src/multiport/MultiportIn.lf | 90 +++--- .../Cpp/src/multiport/MultiportMultipleSet.lf | 82 +++--- test/Cpp/src/multiport/MultiportOut.lf | 98 +++---- test/Cpp/src/multiport/MultiportToBank.lf | 34 +-- .../Cpp/src/multiport/MultiportToBankAfter.lf | 42 +-- .../src/multiport/MultiportToBankHierarchy.lf | 66 ++--- .../Cpp/src/multiport/MultiportToHierarchy.lf | 87 +++--- .../Cpp/src/multiport/MultiportToMultiport.lf | 52 ++-- .../src/multiport/MultiportToMultiport2.lf | 44 +-- .../multiport/MultiportToMultiport2After.lf | 54 ++-- .../multiport/MultiportToMultiportArray.lf | 89 +++--- .../multiport/MultiportToMultiportPhysical.lf | 62 ++-- test/Cpp/src/multiport/MultiportToPort.lf | 63 ++--- .../ReadMultiportOutputOfContainedBank.lf | 103 ++++--- .../multiport/ReadOutputOfContainedBank.lf | 91 +++--- test/Cpp/src/multiport/SparseMultiport.lf | 110 ++++---- test/Cpp/src/multiport/WidthGivenByCode.lf | 54 ++-- .../multiport/WriteInputOfContainedBank.lf | 46 +-- .../WriteMultiportInputOfContainedBank.lf | 50 ++-- test/Cpp/src/properties/Fast.lf | 38 +-- test/Cpp/src/properties/Timeout.lf | 44 +-- test/Cpp/src/properties/TimeoutZero.lf | 44 +-- test/Cpp/src/target/AfterVoid.lf | 56 ++-- .../src/target/BraceAndParenInitialization.lf | 40 ++- .../src/target/CliParserGenericArguments.lf | 84 +++--- test/Cpp/src/target/CombinedTypeNames.lf | 27 +- test/Cpp/src/target/GenericAfter.lf | 18 +- test/Cpp/src/target/GenericDelay.lf | 18 +- .../src/target/GenericParameterAndState.lf | 26 +- test/Cpp/src/target/InitializerSyntax.lf | 146 +++++----- .../src/target/MultipleContainedGeneric.lf | 49 ++-- test/Cpp/src/target/PointerParameters.lf | 20 +- test/Python/src/ActionDelay.lf | 58 ++-- test/Python/src/ActionIsPresent.lf | 42 +-- test/Python/src/After.lf | 73 +++-- test/Python/src/AfterCycles.lf | 92 +++--- test/Python/src/AfterOverlapped.lf | 54 ++-- test/Python/src/ArrayAsParameter.lf | 56 ++-- test/Python/src/ArrayAsType.lf | 34 +-- test/Python/src/ArrayFree.lf | 32 +-- test/Python/src/ArrayPrint.lf | 34 +-- test/Python/src/ArrayScale.lf | 31 +- test/Python/src/CompareTags.lf | 46 +-- test/Python/src/Composition.lf | 57 ++-- test/Python/src/CompositionAfter.lf | 45 ++- test/Python/src/CompositionInheritance.lf | 77 +++-- test/Python/src/CountSelf.lf | 48 ++-- test/Python/src/CountTest.lf | 38 +-- test/Python/src/Deadline.lf | 79 +++--- test/Python/src/DeadlineHandledAbove.lf | 58 ++-- test/Python/src/DelayArray.lf | 59 ++-- test/Python/src/DelayArrayWithAfter.lf | 77 +++-- test/Python/src/DelayInt.lf | 84 +++--- test/Python/src/DelayString.lf | 49 ++-- test/Python/src/DelayStruct.lf | 50 ++-- test/Python/src/DelayStructWithAfter.lf | 26 +- .../src/DelayStructWithAfterOverlapped.lf | 54 ++-- test/Python/src/DelayedAction.lf | 34 +-- test/Python/src/DoubleInvocation.lf | 71 +++-- test/Python/src/DoubleReaction.lf | 62 ++-- test/Python/src/FloatLiteral.lf | 31 +- test/Python/src/Gain.lf | 44 +-- test/Python/src/GetMicroStep.lf | 28 +- test/Python/src/Hello.lf | 74 +++-- test/Python/src/HelloWorld.lf | 26 +- test/Python/src/Hierarchy2.lf | 88 +++--- test/Python/src/IdentifierLength.lf | 52 ++-- test/Python/src/ImportComposition.lf | 41 ++- test/Python/src/ManualDelayedReaction.lf | 67 +++-- test/Python/src/Methods.lf | 30 +- test/Python/src/MethodsRecursive.lf | 22 +- test/Python/src/MethodsSameName.lf | 38 +-- test/Python/src/MovingAverage.lf | 75 +++-- test/Python/src/MultipleContained.lf | 61 ++-- test/Python/src/NativeListsAndTimes.lf | 43 ++- test/Python/src/ParameterizedState.lf | 6 +- test/Python/src/PeriodicDesugared.lf | 28 +- test/Python/src/PingPong.lf | 89 +++--- test/Python/src/Pipeline.lf | 90 +++--- .../src/ReadOutputOfContainedReactor.lf | 67 +++-- test/Python/src/ScheduleLogicalAction.lf | 60 ++-- test/Python/src/SelfLoop.lf | 52 ++-- test/Python/src/SendingInside.lf | 40 +-- test/Python/src/SetArray.lf | 29 +- test/Python/src/SimpleDeadline.lf | 51 ++-- test/Python/src/SlowingClock.lf | 54 ++-- test/Python/src/SlowingClockPhysical.lf | 67 +++-- test/Python/src/Stride.lf | 44 +-- test/Python/src/StructAsState.lf | 29 +- test/Python/src/StructAsType.lf | 32 +-- test/Python/src/StructAsTypeDirect.lf | 38 +-- test/Python/src/StructParallel.lf | 57 ++-- test/Python/src/StructPrint.lf | 30 +- test/Python/src/StructScale.lf | 51 ++-- test/Python/src/SubclassesAndStartup.lf | 48 ++-- test/Python/src/TimeLimit.lf | 63 ++--- test/Python/src/TimeState.lf | 6 +- test/Python/src/Timers.lf | 24 +- .../src/TriggerDownstreamOnlyIfPresent.lf | 61 ++-- .../src/TriggerDownstreamOnlyIfPresent2.lf | 49 ++-- test/Python/src/UnconnectedInput.lf | 72 ++--- test/Python/src/concurrent/AsyncCallback.lf | 95 ++++--- .../src/concurrent/AsyncCallbackNoTimer.lf | 100 +++---- .../src/docker/FilesPropertyContainerized.lf | 42 +-- .../DistributedCountContainerized.lf | 21 +- ...stributedStopDecentralizedContainerized.lf | 3 +- .../Python/src/federated/BroadcastFeedback.lf | 38 ++- .../BroadcastFeedbackWithHierarchy.lf | 48 ++-- test/Python/src/federated/CycleDetection.lf | 74 ++--- .../src/federated/DecentralizedP2PComm.lf | 72 ++--- .../DecentralizedP2PUnbalancedTimeout.lf | 77 +++-- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 63 ++--- test/Python/src/federated/DistributedBank.lf | 30 +- .../federated/DistributedBankToMultiport.lf | 40 +-- test/Python/src/federated/DistributedCount.lf | 55 ++-- .../DistributedCountDecentralized.lf | 58 ++-- .../DistributedCountDecentralizedLate.lf | 99 ++++--- ...ributedCountDecentralizedLateDownstream.lf | 140 +++++---- ...tributedCountDecentralizedLateHierarchy.lf | 41 ++- .../src/federated/DistributedCountPhysical.lf | 70 ++--- .../DistributedCountPhysicalAfterDelay.lf | 70 ++--- .../DistributedCountPhysicalDecentralized.lf | 72 ++--- .../src/federated/DistributedDoublePort.lf | 67 +++-- .../src/federated/DistributedLoopedAction.lf | 92 +++--- .../DistributedLoopedPhysicalAction.lf | 123 ++++---- .../src/federated/DistributedMultiport.lf | 60 ++-- .../federated/DistributedMultiportToBank.lf | 54 ++-- .../federated/DistributedMultiportToken.lf | 50 ++-- .../src/federated/DistributedSendClass.lf | 20 +- test/Python/src/federated/DistributedStop.lf | 181 ++++++------ .../federated/DistributedStopDecentralized.lf | 6 +- .../src/federated/DistributedStopZero.lf | 132 +++++---- test/Python/src/federated/HelloDistributed.lf | 62 ++-- ...stributedCentralizedPrecedenceHierarchy.lf | 87 +++--- test/Python/src/federated/PhysicalSTP.lf | 69 +++-- .../src/federated/PingPongDistributed.lf | 88 +++--- test/Python/src/federated/StopAtShutdown.lf | 24 +- test/Python/src/lib/Count.lf | 14 +- test/Python/src/lib/InternalDelay.lf | 10 +- test/Python/src/lib/LoopedActionSender.lf | 35 ++- test/Python/src/lib/Test.lf | 18 +- test/Python/src/lib/TestCount.lf | 41 ++- test/Python/src/lib/TestCountMultiport.lf | 61 ++-- .../modal_models/BanksCount3ModesComplex.lf | 108 ++++--- .../src/modal_models/BanksModalStateReset.lf | 92 +++--- .../src/modal_models/ConvertCaseTest.lf | 197 +++++++------ test/Python/src/modal_models/Count3Modes.lf | 84 +++--- test/Python/src/modal_models/ModalActions.lf | 145 +++++----- test/Python/src/modal_models/ModalAfter.lf | 141 +++++----- .../src/modal_models/ModalCycleBreaker.lf | 96 ++++--- .../src/modal_models/ModalStartupShutdown.lf | 261 +++++++++-------- .../src/modal_models/ModalStateReset.lf | 137 +++++---- .../src/modal_models/ModalStateResetAuto.lf | 133 +++++---- test/Python/src/modal_models/ModalTimers.lf | 95 ++++--- .../MultipleOutputFeeder_2Connections.lf | 96 ++++--- ...ultipleOutputFeeder_ReactionConnections.lf | 98 ++++--- .../src/modal_models/util/TraceTesting.lf | 98 +++---- .../src/multiport/BankIndexInitializer.lf | 42 +-- .../src/multiport/BankReactionsInContainer.lf | 106 ++++--- test/Python/src/multiport/BankToBank.lf | 54 ++-- .../src/multiport/BankToBankMultiport.lf | 76 ++--- .../src/multiport/BankToBankMultiportAfter.lf | 10 +- test/Python/src/multiport/BankToMultiport.lf | 42 +-- test/Python/src/multiport/Broadcast.lf | 50 ++-- .../src/multiport/BroadcastMultipleAfter.lf | 52 ++-- .../Python/src/multiport/MultiportFromBank.lf | 56 ++-- .../multiport/MultiportFromBankHierarchy.lf | 24 +- .../src/multiport/MultiportFromHierarchy.lf | 85 +++--- .../src/multiport/MultiportFromReaction.lf | 64 ++--- test/Python/src/multiport/MultiportIn.lf | 86 +++--- .../src/multiport/MultiportInParameterized.lf | 96 +++---- .../src/multiport/MultiportMutableInput.lf | 61 ++-- .../multiport/MultiportMutableInputArray.lf | 59 ++-- test/Python/src/multiport/MultiportOut.lf | 90 +++--- test/Python/src/multiport/MultiportToBank.lf | 50 ++-- .../src/multiport/MultiportToBankAfter.lf | 49 ++-- .../src/multiport/MultiportToBankHierarchy.lf | 50 ++-- .../src/multiport/MultiportToHierarchy.lf | 75 +++-- .../src/multiport/MultiportToMultiport.lf | 32 +-- .../src/multiport/MultiportToMultiport2.lf | 40 +-- .../multiport/MultiportToMultiport2After.lf | 36 +-- .../multiport/MultiportToMultiportArray.lf | 77 +++-- .../MultiportToMultiportParameter.lf | 10 +- test/Python/src/multiport/MultiportToPort.lf | 57 ++-- .../src/multiport/MultiportToReaction.lf | 58 ++-- test/Python/src/multiport/NestedBanks.lf | 90 +++--- .../src/multiport/NestedInterleavedBanks.lf | 42 +-- .../Python/src/multiport/ReactionsToNested.lf | 47 ++-- test/Python/src/target/AfterNoTypes.lf | 74 ++--- test/Rust/src/ActionDelay.lf | 38 +-- test/Rust/src/ActionImplicitDelay.lf | 24 +- test/Rust/src/ActionIsPresent.lf | 44 +-- test/Rust/src/ActionScheduleMicrostep.lf | 32 +-- test/Rust/src/ActionValues.lf | 46 +-- test/Rust/src/ActionValuesCleanup.lf | 74 +++-- test/Rust/src/CompositionWithPorts.lf | 28 +- test/Rust/src/CtorParamDefault.lf | 12 +- test/Rust/src/CtorParamMixed.lf | 26 +- test/Rust/src/CtorParamSimple.lf | 12 +- test/Rust/src/DependencyOnChildPort.lf | 28 +- test/Rust/src/DependencyUseOnLogicalAction.lf | 82 +++--- test/Rust/src/FloatLiteral.lf | 21 +- test/Rust/src/MainReactorParam.lf | 6 +- test/Rust/src/MovingAverage.lf | 88 +++--- test/Rust/src/NativeListsAndTimes.lf | 75 +++-- test/Rust/src/PortConnectionInSelfInChild.lf | 36 +-- test/Rust/src/PortConnectionInSelfOutSelf.lf | 42 +-- .../Rust/src/PortConnectionOutChildOutSelf.lf | 48 ++-- test/Rust/src/PortRefCleanup.lf | 62 ++-- test/Rust/src/PortValueCleanup.lf | 52 ++-- test/Rust/src/ReservedKeywords.lf | 27 +- test/Rust/src/StateInitializerVisibility.lf | 18 +- test/Rust/src/Stop.lf | 115 ++++---- test/Rust/src/StopIdempotence.lf | 26 +- test/Rust/src/StopTimeoutExact.lf | 30 +- test/Rust/src/StructAsState.lf | 44 +-- test/Rust/src/StructAsType.lf | 50 ++-- test/Rust/src/TimeState.lf | 6 +- test/Rust/src/TimerDefaults.lf | 14 +- test/Rust/src/TimerIsPresent.lf | 86 +++--- test/Rust/src/TimerPeriodic.lf | 22 +- test/Rust/src/Timers.lf | 20 +- test/Rust/src/TypeVarLengthList.lf | 18 +- test/Rust/src/concurrent/AsyncCallback.lf | 108 +++---- test/Rust/src/generics/CtorParamGeneric.lf | 22 +- .../Rust/src/generics/CtorParamGenericInst.lf | 42 ++- test/Rust/src/generics/GenericComplexType.lf | 22 +- test/Rust/src/generics/GenericReactor.lf | 28 +- .../src/multiport/ConnectionToSelfBank.lf | 24 +- .../multiport/ConnectionToSelfMultiport.lf | 30 +- test/Rust/src/multiport/CycledLhs_SelfLoop.lf | 46 ++- test/Rust/src/multiport/CycledLhs_Single.lf | 72 +++-- test/Rust/src/multiport/FullyConnected.lf | 26 +- .../multiport/FullyConnectedAddressable.lf | 84 +++--- test/Rust/src/multiport/MultiportFromBank.lf | 28 +- .../src/multiport/MultiportFromHierarchy.lf | 71 +++-- test/Rust/src/multiport/MultiportIn.lf | 84 +++--- test/Rust/src/multiport/MultiportOut.lf | 94 +++---- test/Rust/src/multiport/MultiportToBank.lf | 40 +-- .../src/multiport/MultiportToBankHierarchy.lf | 48 ++-- .../src/multiport/MultiportToMultiport.lf | 32 +-- .../src/multiport/MultiportToMultiport2.lf | 41 ++- .../multiport/ReadOutputOfContainedBank.lf | 77 +++-- test/Rust/src/multiport/WidthWithParameter.lf | 16 +- .../multiport/WriteInputOfContainedBank.lf | 34 ++- test/Rust/src/target/CliFeature.lf | 6 +- .../target/MainParameterCanBeExpression.lf | 14 +- test/TypeScript/src/ActionDelay.lf | 60 ++-- test/TypeScript/src/After.lf | 47 ++-- test/TypeScript/src/ArrayAsParameter.lf | 44 +-- test/TypeScript/src/ArrayAsType.lf | 69 +++-- test/TypeScript/src/ArrayPrint.lf | 69 +++-- test/TypeScript/src/ArrayScale.lf | 35 ++- test/TypeScript/src/Composition.lf | 43 ++- test/TypeScript/src/CompositionAfter.lf | 45 ++- test/TypeScript/src/CountTest.lf | 26 +- test/TypeScript/src/Deadline.lf | 79 +++--- test/TypeScript/src/DeadlineHandledAbove.lf | 68 ++--- test/TypeScript/src/DelayInt.lf | 90 +++--- test/TypeScript/src/DelayedAction.lf | 32 +-- test/TypeScript/src/DoubleInvocation.lf | 73 +++-- test/TypeScript/src/DoubleReaction.lf | 66 ++--- test/TypeScript/src/DoubleTrigger.lf | 35 ++- test/TypeScript/src/FloatLiteral.lf | 27 +- test/TypeScript/src/Gain.lf | 46 +-- test/TypeScript/src/Hello.lf | 77 +++-- test/TypeScript/src/Hierarchy2.lf | 84 +++--- test/TypeScript/src/MovingAverage.lf | 95 ++++--- test/TypeScript/src/NativeListsAndTimes.lf | 39 ++- test/TypeScript/src/ParameterizedState.lf | 6 +- test/TypeScript/src/PeriodicDesugared.lf | 36 +-- test/TypeScript/src/PhysicalConnection.lf | 26 +- .../src/ReadOutputOfContainedReactor.lf | 69 +++-- test/TypeScript/src/ScheduleLogicalAction.lf | 62 ++-- test/TypeScript/src/SendingInside.lf | 40 +-- test/TypeScript/src/SendsPointerTest.lf | 36 +-- test/TypeScript/src/SimpleDeadline.lf | 61 ++-- test/TypeScript/src/SlowingClock.lf | 44 +-- test/TypeScript/src/SlowingClockPhysical.lf | 60 ++-- test/TypeScript/src/Stop.lf | 83 +++--- test/TypeScript/src/Stride.lf | 32 +-- test/TypeScript/src/StructAsState.lf | 26 +- test/TypeScript/src/StructAsType.lf | 48 ++-- test/TypeScript/src/StructAsTypeDirect.lf | 48 ++-- test/TypeScript/src/StructPrint.lf | 48 ++-- test/TypeScript/src/StructScale.lf | 34 ++- test/TypeScript/src/TimeLimit.lf | 51 ++-- test/TypeScript/src/TimeState.lf | 6 +- .../src/concurrent/AsyncCallback.lf | 74 ++--- .../DistributedCountContainerized.lf | 10 +- .../src/federated/DistributedCount.lf | 51 ++-- .../src/federated/DistributedCountPhysical.lf | 72 ++--- .../DistributedCountPhysicalAfterDelay.lf | 61 ++-- .../src/federated/DistributedDoublePort.lf | 65 ++--- .../src/federated/DistributedLoopedAction.lf | 86 +++--- .../DistributedLoopedPhysicalAction.lf | 104 ++++--- .../src/federated/DistributedStop.lf | 161 ++++++----- .../src/federated/HelloDistributed.lf | 67 +++-- .../federated/LoopDistributedCentralized.lf | 89 +++--- .../src/federated/LoopDistributedDouble.lf | 121 ++++---- .../src/federated/PingPongDistributed.lf | 76 ++--- .../federated/PingPongDistributedPhysical.lf | 90 +++--- .../src/federated/TopLevelArtifacts.lf | 45 ++- test/TypeScript/src/lib/Count.lf | 8 +- test/TypeScript/src/lib/InternalDelay.lf | 10 +- test/TypeScript/src/lib/LoopedActionSender.lf | 37 ++- test/TypeScript/src/lib/TestCount.lf | 45 ++- .../src/multiport/BankMultiportToReaction.lf | 48 ++-- .../src/multiport/BankReactionsInContainer.lf | 110 ++++---- .../src/multiport/BankSelfBroadcast.lf | 52 ++-- test/TypeScript/src/multiport/BankToBank.lf | 53 ++-- .../src/multiport/BankToBankMultiport.lf | 64 ++--- .../src/multiport/BankToBankMultiportAfter.lf | 64 ++--- .../src/multiport/BankToMultiport.lf | 40 +-- .../src/multiport/BankToReaction.lf | 22 +- .../src/multiport/BroadcastAfter.lf | 50 ++-- .../src/multiport/BroadcastMultipleAfter.lf | 56 ++-- .../src/multiport/FullyConnected.lf | 60 ++-- .../src/multiport/MultiportFromBank.lf | 48 ++-- .../multiport/MultiportFromBankHierarchy.lf | 18 +- .../src/multiport/MultiportFromHierarchy.lf | 85 +++--- .../src/multiport/MultiportFromReaction.lf | 64 ++--- test/TypeScript/src/multiport/MultiportIn.lf | 92 +++--- .../src/multiport/MultiportInParameterized.lf | 94 +++---- .../src/multiport/MultiportMutableInput.lf | 63 ++--- .../multiport/MultiportMutableInputArray.lf | 117 ++++---- test/TypeScript/src/multiport/MultiportOut.lf | 94 +++---- .../src/multiport/MultiportToBankAfter.lf | 61 ++-- .../src/multiport/MultiportToBankDouble.lf | 69 +++-- .../src/multiport/MultiportToBankHierarchy.lf | 60 ++-- .../src/multiport/MultiportToHierarchy.lf | 75 +++-- .../src/multiport/MultiportToMultiport.lf | 50 ++-- .../src/multiport/MultiportToMultiport2.lf | 40 +-- .../multiport/MultiportToMultiport2After.lf | 52 ++-- .../multiport/MultiportToMultiportArray.lf | 85 +++--- .../MultiportToMultiportParameter.lf | 62 ++-- .../src/multiport/MultiportToPort.lf | 57 ++-- .../src/multiport/MultiportToReaction.lf | 60 ++-- test/TypeScript/src/multiport/NestedBanks.lf | 92 +++--- .../src/multiport/ReactionToContainedBank.lf | 20 +- .../src/multiport/ReactionsToNested.lf | 47 ++-- test/TypeScript/src/target/AfterNoTypes.lf | 41 ++- 732 files changed, 22019 insertions(+), 22657 deletions(-) diff --git a/build.gradle b/build.gradle index 348949c01e..37a497f632 100644 --- a/build.gradle +++ b/build.gradle @@ -96,7 +96,7 @@ spotless { // define the steps to apply to those files trimTrailingWhitespace() - indentWithSpaces() // or spaces. Takes an integer argument if you don't like 4 + indentWithSpaces(2) // or spaces. Takes an integer argument if you don't like 4 endWithNewline() } diff --git a/org.lflang/src/org/lflang/ast/FormattingUtils.java b/org.lflang/src/org/lflang/ast/FormattingUtils.java index 9b47440391..7ec3d7d59a 100644 --- a/org.lflang/src/org/lflang/ast/FormattingUtils.java +++ b/org.lflang/src/org/lflang/ast/FormattingUtils.java @@ -29,9 +29,9 @@ public class FormattingUtils { private static final Pattern MULTILINE_COMMENT = Pattern.compile("\\s*/\\*\\v?(\\V*\\v+)*\\V*"); /** The number of spaces to prepend to a line per indentation level. */ - private static final int INDENTATION = 4; + private static final int INDENTATION = 2; - public static final int DEFAULT_LINE_LENGTH = 80; + public static final int DEFAULT_LINE_LENGTH = 100; static final int MAX_WHITESPACE_USED_FOR_ALIGNMENT = 20; diff --git a/test/C/src/ActionDelay.lf b/test/C/src/ActionDelay.lf index 86e510080a..4951f806c2 100644 --- a/test/C/src/ActionDelay.lf +++ b/test/C/src/ActionDelay.lf @@ -2,47 +2,47 @@ target C reactor GeneratedDelay { - input y_in: int - output y_out: int - state y_state: int = 0 - logical action act(100 msec) + input y_in: int + output y_out: int + state y_state: int = 0 + logical action act(100 msec) - reaction(y_in) -> act {= - self->y_state = y_in->value; - lf_schedule(act, MSEC(0)); - =} + reaction(y_in) -> act {= + self->y_state = y_in->value; + lf_schedule(act, MSEC(0)); + =} - reaction(act) -> y_out {= lf_set(y_out, self->y_state); =} + reaction(act) -> y_out {= lf_set(y_out, self->y_state); =} } reactor Source { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, 1); =} + reaction(startup) -> out {= lf_set(out, 1); =} } reactor Sink { - input in: int - - reaction(in) {= - interval_t elapsed_logical = lf_time_logical_elapsed(); - interval_t logical = lf_time_logical(); - interval_t physical = lf_time_physical(); - printf("Logical, physical, and elapsed logical: %lld %lld %lld.\n", logical, physical, elapsed_logical); - if (elapsed_logical != MSEC(100)) { - printf("FAILURE: Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); - exit(1); - } else { - printf("SUCCESS. Elapsed logical time is 100 msec.\n"); - } - =} + input in: int + + reaction(in) {= + interval_t elapsed_logical = lf_time_logical_elapsed(); + interval_t logical = lf_time_logical(); + interval_t physical = lf_time_physical(); + printf("Logical, physical, and elapsed logical: %lld %lld %lld.\n", logical, physical, elapsed_logical); + if (elapsed_logical != MSEC(100)) { + printf("FAILURE: Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); + exit(1); + } else { + printf("SUCCESS. Elapsed logical time is 100 msec.\n"); + } + =} } main reactor ActionDelay { - source = new Source() - sink = new Sink() - g = new GeneratedDelay() + source = new Source() + sink = new Sink() + g = new GeneratedDelay() - source.out -> g.y_in - g.y_out -> sink.in + source.out -> g.y_in + g.y_out -> sink.in } diff --git a/test/C/src/ActionIsPresent.lf b/test/C/src/ActionIsPresent.lf index b94108949e..2c0bff1293 100644 --- a/test/C/src/ActionIsPresent.lf +++ b/test/C/src/ActionIsPresent.lf @@ -2,27 +2,27 @@ target C main reactor ActionIsPresent(offset: time = 1 nsec, period: time = 500 msec) { - logical action a - state success: bool = false + logical action a + state success: bool = false - reaction(startup, a) -> a {= - if (!a->is_present) { - if (self->offset == 0) { - printf("Hello World!\n"); - self->success = true; - } else { - lf_schedule(a, self->offset); - } - } else { - printf("Hello World 2!\n"); + reaction(startup, a) -> a {= + if (!a->is_present) { + if (self->offset == 0) { + printf("Hello World!\n"); self->success = true; + } else { + lf_schedule(a, self->offset); } - =} + } else { + printf("Hello World 2!\n"); + self->success = true; + } + =} - reaction(shutdown) {= - if (!self->success) { - fprintf(stderr, "Failed to print 'Hello World'\n"); - exit(1); - } - =} + reaction(shutdown) {= + if (!self->success) { + fprintf(stderr, "Failed to print 'Hello World'\n"); + exit(1); + } + =} } diff --git a/test/C/src/After.lf b/test/C/src/After.lf index d3663457e4..e7aeba5b8d 100644 --- a/test/C/src/After.lf +++ b/test/C/src/After.lf @@ -1,52 +1,51 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target C { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor foo { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= lf_set(y, 2*x->value); =} + reaction(x) -> y {= lf_set(y, 2*x->value); =} } reactor print { - state expected_time: time = 10 msec - state received: int = 0 - input x: int + state expected_time: time = 10 msec + state received: int = 0 + input x: int - reaction(x) {= - self->received++; - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Result is %d\n", x->value); - if (x->value != 84) { - printf("ERROR: Expected result to be 84.\n"); - exit(1); - } - printf("Current logical time is: %lld\n", elapsed_time); - printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); - if (elapsed_time != self->expected_time) { - printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); - exit(2); - } - self->expected_time += SEC(1); - =} + reaction(x) {= + self->received++; + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Result is %d\n", x->value); + if (x->value != 84) { + printf("ERROR: Expected result to be 84.\n"); + exit(1); + } + printf("Current logical time is: %lld\n", elapsed_time); + printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); + if (elapsed_time != self->expected_time) { + printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); + exit(2); + } + self->expected_time += SEC(1); + =} - reaction(shutdown) {= - if (self->received == 0) { - printf("ERROR: Final reactor received no data.\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (self->received == 0) { + printf("ERROR: Final reactor received no data.\n"); + exit(3); + } + =} } main reactor After { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= lf_set(f.x, 42); =} + reaction(t) -> f.x {= lf_set(f.x, 42); =} } diff --git a/test/C/src/AfterCycles.lf b/test/C/src/AfterCycles.lf index d7d621046b..3a7301a7a2 100644 --- a/test/C/src/AfterCycles.lf +++ b/test/C/src/AfterCycles.lf @@ -1,61 +1,61 @@ -// This tests that "after" does not introduce spurious cycles. Success if -// running without detected a cycle. +// This tests that "after" does not introduce spurious cycles. Success if running without detected a +// cycle. target C reactor Source { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= lf_set(out, 1); =} + reaction(startup) -> out {= lf_set(out, 1); =} } reactor Work { - input in: unsigned - output out: unsigned + input in: unsigned + output out: unsigned - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } main reactor AfterCycles { - state count: int = 0 - s = new Source() - w0 = new Work() - w1 = new Work() - - s.out -> w0.in after 10 msec - s.out -> w1.in after 20 msec - - reaction(w0.out) {= - self->count++; - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Received %d from worker 0 at time %lld.\n", w0.out->value, elapsed_time); - if (elapsed_time != MSEC(10)) { - fprintf(stderr, "Time should have been 10000000.\n"); - exit(1); - } - if (w0.out->value != 1) { - fprintf(stderr, "Value should have been 1.\n"); - exit(4); - } - =} - - reaction(w1.out) {= - self->count++; - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Received %d from worker 1 at time %lld.\n", w1.out->value, elapsed_time); - if (elapsed_time != MSEC(20)) { - fprintf(stderr, "Time should have been 20000000.\n"); - exit(3); - } - if (w1.out->value != 1) { - fprintf(stderr, "Value should have been 1.\n"); - exit(4); - } - =} - - reaction(shutdown) {= - if (self->count != 2) { - fprintf(stderr, "Top-level reactions should have been triggered but were not.\n"); - exit(5); - } - =} + state count: int = 0 + s = new Source() + w0 = new Work() + w1 = new Work() + + s.out -> w0.in after 10 msec + s.out -> w1.in after 20 msec + + reaction(w0.out) {= + self->count++; + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Received %d from worker 0 at time %lld.\n", w0.out->value, elapsed_time); + if (elapsed_time != MSEC(10)) { + fprintf(stderr, "Time should have been 10000000.\n"); + exit(1); + } + if (w0.out->value != 1) { + fprintf(stderr, "Value should have been 1.\n"); + exit(4); + } + =} + + reaction(w1.out) {= + self->count++; + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Received %d from worker 1 at time %lld.\n", w1.out->value, elapsed_time); + if (elapsed_time != MSEC(20)) { + fprintf(stderr, "Time should have been 20000000.\n"); + exit(3); + } + if (w1.out->value != 1) { + fprintf(stderr, "Value should have been 1.\n"); + exit(4); + } + =} + + reaction(shutdown) {= + if (self->count != 2) { + fprintf(stderr, "Top-level reactions should have been triggered but were not.\n"); + exit(5); + } + =} } diff --git a/test/C/src/AfterOverlapped.lf b/test/C/src/AfterOverlapped.lf index 0925dc5164..b1124c4274 100644 --- a/test/C/src/AfterOverlapped.lf +++ b/test/C/src/AfterOverlapped.lf @@ -1,46 +1,46 @@ // This the after keyword with overlapped time intervals. target C { - fast: true, - timeout: 5 sec + fast: true, + timeout: 5 sec } import Count from "lib/Count.lf" reactor Test { - input c: int - state i: int = 0 - state received: int = 0 + input c: int + state i: int = 0 + state received: int = 0 - reaction(c) {= - self->received++; - printf("Received %d.\n", c->value); - (self->i)++; - if (c->value != self->i) { - printf("ERROR: Expected %d but got %d\n.", self->i, c->value); - exit(1); - } - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Current logical time is: %lld\n", elapsed_time); + reaction(c) {= + self->received++; + printf("Received %d.\n", c->value); + (self->i)++; + if (c->value != self->i) { + printf("ERROR: Expected %d but got %d\n.", self->i, c->value); + exit(1); + } + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Current logical time is: %lld\n", elapsed_time); - interval_t expected_logical_time = SEC(2) + SEC(1)*(c->value - 1); - if (elapsed_time != expected_logical_time) { - printf("ERROR: Expected logical time to be %lld but got %lld\n.", - expected_logical_time, elapsed_time - ); - exit(1); - } - =} + interval_t expected_logical_time = SEC(2) + SEC(1)*(c->value - 1); + if (elapsed_time != expected_logical_time) { + printf("ERROR: Expected logical time to be %lld but got %lld\n.", + expected_logical_time, elapsed_time + ); + exit(1); + } + =} - reaction(shutdown) {= - if (self->received == 0) { - printf("ERROR: Final reactor received no data.\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (self->received == 0) { + printf("ERROR: Final reactor received no data.\n"); + exit(3); + } + =} } main reactor AfterOverlapped { - count = new Count() - test = new Test() - count.out -> test.c after 2 sec + count = new Count() + test = new Test() + count.out -> test.c after 2 sec } diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf index 378114c730..547222246c 100644 --- a/test/C/src/AfterZero.lf +++ b/test/C/src/AfterZero.lf @@ -1,57 +1,56 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target C { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor foo { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= SET(y, 2*x->value); =} + reaction(x) -> y {= SET(y, 2*x->value); =} } reactor print { - state expected_time: time = 0 - state received: int = 0 - input x: int + state expected_time: time = 0 + state received: int = 0 + input x: int - reaction(x) {= - self->received++; - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Result is %d\n", x->value); - if (x->value != 84) { - printf("ERROR: Expected result to be 84.\n"); - exit(1); - } - printf("Current logical time is: %lld\n", elapsed_time); - printf("Current microstep is: %lld\n", lf_tag().microstep); - printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); - if (elapsed_time != self->expected_time) { - printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); - exit(2); - } - if (lf_tag().microstep != 1) { - printf("ERROR: Expected microstep to be 1\n"); - exit(3); - } - self->expected_time += SEC(1); - =} + reaction(x) {= + self->received++; + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Result is %d\n", x->value); + if (x->value != 84) { + printf("ERROR: Expected result to be 84.\n"); + exit(1); + } + printf("Current logical time is: %lld\n", elapsed_time); + printf("Current microstep is: %lld\n", lf_tag().microstep); + printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); + if (elapsed_time != self->expected_time) { + printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); + exit(2); + } + if (lf_tag().microstep != 1) { + printf("ERROR: Expected microstep to be 1\n"); + exit(3); + } + self->expected_time += SEC(1); + =} - reaction(shutdown) {= - if (self->received == 0) { - printf("ERROR: Final reactor received no data.\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (self->received == 0) { + printf("ERROR: Final reactor received no data.\n"); + exit(3); + } + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 0 + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 0 - reaction(t) -> f.x {= SET(f.x, 42); =} + reaction(t) -> f.x {= SET(f.x, 42); =} } diff --git a/test/C/src/Alignment.lf b/test/C/src/Alignment.lf index a2b9b523fb..1c5c907a37 100644 --- a/test/C/src/Alignment.lf +++ b/test/C/src/Alignment.lf @@ -1,105 +1,104 @@ -// This test checks that the downstream reaction is not invoked more than once -// at a logical time. +// This test checks that the downstream reaction is not invoked more than once at a logical time. target C { - logging: LOG, - timeout: 1 sec + logging: LOG, + timeout: 1 sec } reactor Source { - output out: int - state count: int = 1 - timer t(0, 100 msec) + output out: int + state count: int = 1 + timer t(0, 100 msec) - reaction(t) -> out {= lf_set(out, self->count++); =} + reaction(t) -> out {= lf_set(out, self->count++); =} } reactor Sieve { - input in: int - output out: bool - state primes: int* = {= NULL =} - state last_prime: int = 0 + input in: int + output out: bool + state primes: int* = {= NULL =} + state last_prime: int = 0 - reaction(startup) {= - // There are 1229 primes between 1 and 10,000. - self->primes = (int*)calloc(1229, sizeof(int)); - // Primes 1 and 2 are not on the list. - self->primes[0] = 3; - =} + reaction(startup) {= + // There are 1229 primes between 1 and 10,000. + self->primes = (int*)calloc(1229, sizeof(int)); + // Primes 1 and 2 are not on the list. + self->primes[0] = 3; + =} - reaction(in) -> out {= - // Reject inputs that are out of bounds. - if (in->value <= 0 || in->value > 10000) { - lf_print_warning("Sieve: Input value out of range: %d.", in->value); + reaction(in) -> out {= + // Reject inputs that are out of bounds. + if (in->value <= 0 || in->value > 10000) { + lf_print_warning("Sieve: Input value out of range: %d.", in->value); + } + // Primes 1 and 2 are not on the list. + if (in->value == 1 || in->value == 2) { + lf_set(out, true); + return; + } + // If the input is greater than the last found prime, then + // we have to expand the list of primes before checking to + // see whether this is prime. + int candidate = self->primes[self->last_prime]; + while (in->value > self->primes[self->last_prime]) { + // The next prime is always odd, so we can increment by two. + candidate += 2; + bool prime = true; + for (int i = 0; i < self->last_prime; i++) { + if (candidate % self->primes[i] == 0) { + // Candidate is not prime. Break and add 2 + prime = false; + break; + } + } + // If the candidate is not divisible by any prime in the list, it is prime. + if (prime) { + self->last_prime++; + self->primes[self->last_prime] = candidate; + lf_print("Sieve: Found prime: %d.", candidate); } - // Primes 1 and 2 are not on the list. - if (in->value == 1 || in->value == 2) { + } + // We are now assured that the input is less than or + // equal to the last prime on the list. + // See whether the input is an already found prime. + for (int i = self->last_prime; i >= 0; i--) { + // Search the primes from the end, where they are sparser. + if (self->primes[i] == in->value) { lf_set(out, true); return; } - // If the input is greater than the last found prime, then - // we have to expand the list of primes before checking to - // see whether this is prime. - int candidate = self->primes[self->last_prime]; - while (in->value > self->primes[self->last_prime]) { - // The next prime is always odd, so we can increment by two. - candidate += 2; - bool prime = true; - for (int i = 0; i < self->last_prime; i++) { - if (candidate % self->primes[i] == 0) { - // Candidate is not prime. Break and add 2 - prime = false; - break; - } - } - // If the candidate is not divisible by any prime in the list, it is prime. - if (prime) { - self->last_prime++; - self->primes[self->last_prime] = candidate; - lf_print("Sieve: Found prime: %d.", candidate); - } - } - // We are now assured that the input is less than or - // equal to the last prime on the list. - // See whether the input is an already found prime. - for (int i = self->last_prime; i >= 0; i--) { - // Search the primes from the end, where they are sparser. - if (self->primes[i] == in->value) { - lf_set(out, true); - return; - } - } - =} + } + =} } reactor Destination { - input ok: bool - input in: int - state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} + input ok: bool + input in: int + state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} - reaction(ok, in) {= - tag_t current_tag = lf_tag(); - if (ok->is_present && in->is_present) { - lf_print("Destination: Input %d is prime at tag (%lld, %d).", - in->value, - current_tag.time - lf_time_start(), current_tag.microstep - ); - } - if (lf_tag_compare(current_tag, self->last_invoked) <= 0) { - lf_print_error_and_exit("Invoked at tag (%lld, %d), " - "but previously invoked at tag (%lld, %d).", - current_tag.time - lf_time_start(), current_tag.microstep, - self->last_invoked.time - lf_time_start(), self->last_invoked.microstep - ); - } - self->last_invoked = current_tag; - =} + reaction(ok, in) {= + tag_t current_tag = lf_tag(); + if (ok->is_present && in->is_present) { + lf_print("Destination: Input %d is prime at tag (%lld, %d).", + in->value, + current_tag.time - lf_time_start(), current_tag.microstep + ); + } + if (lf_tag_compare(current_tag, self->last_invoked) <= 0) { + lf_print_error_and_exit("Invoked at tag (%lld, %d), " + "but previously invoked at tag (%lld, %d).", + current_tag.time - lf_time_start(), current_tag.microstep, + self->last_invoked.time - lf_time_start(), self->last_invoked.microstep + ); + } + self->last_invoked = current_tag; + =} } main reactor { - source = new Source() - sieve = new Sieve() - destination = new Destination() - source.out -> sieve.in - sieve.out -> destination.ok - source.out -> destination.in + source = new Source() + sieve = new Sieve() + destination = new Destination() + source.out -> sieve.in + sieve.out -> destination.ok + source.out -> destination.in } diff --git a/test/C/src/ArrayAsParameter.lf b/test/C/src/ArrayAsParameter.lf index a9df29cb03..a513cbee9f 100644 --- a/test/C/src/ArrayAsParameter.lf +++ b/test/C/src/ArrayAsParameter.lf @@ -1,47 +1,46 @@ -// Source has an array as a parameter, the elements of which it passes to Print. -// The length of the array has to also be a parameter because C arrays do not -// encode their own length. +// Source has an array as a parameter, the elements of which it passes to Print. The length of the +// array has to also be a parameter because C arrays do not encode their own length. target C reactor Source(sequence: int[] = {0, 1, 2}, n_sequence: int = 3) { - output out: int - state count: int = 0 - logical action next + output out: int + state count: int = 0 + logical action next - reaction(startup, next) -> out, next {= - lf_set(out, self->sequence[self->count]); - self->count++; - if (self->count < self->n_sequence) { - lf_schedule(next, 0); - } - =} + reaction(startup, next) -> out, next {= + lf_set(out, self->sequence[self->count]); + self->count++; + if (self->count < self->n_sequence) { + lf_schedule(next, 0); + } + =} } reactor Print { - input in: int - state count: int = 1 - state received: int = 0 + input in: int + state count: int = 1 + state received: int = 0 - reaction(in) {= - self->received++; - printf("Received: %d\n", in->value); - if (in->value != self->count) { - printf("ERROR: Expected %d.\n", self->count); - exit(1); - } - self->count++; - =} + reaction(in) {= + self->received++; + printf("Received: %d\n", in->value); + if (in->value != self->count) { + printf("ERROR: Expected %d.\n", self->count); + exit(1); + } + self->count++; + =} - reaction(shutdown) {= - if (self->received == 0) { - printf("ERROR: Final reactor received no data.\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (self->received == 0) { + printf("ERROR: Final reactor received no data.\n"); + exit(3); + } + =} } main reactor ArrayAsParameter { - s = new Source(sequence = {1, 2, 3, 4}, n_sequence = 4) - p = new Print() - s.out -> p.in + s = new Source(sequence = {1, 2, 3, 4}, n_sequence = 4) + p = new Print() + s.out -> p.in } diff --git a/test/C/src/ArrayAsType.lf b/test/C/src/ArrayAsType.lf index c95e5bf385..07dc9d1843 100644 --- a/test/C/src/ArrayAsType.lf +++ b/test/C/src/ArrayAsType.lf @@ -1,44 +1,44 @@ -// Source produces a statically allocated array, which it passes to Print. The -// destination references the array directly. +// Source produces a statically allocated array, which it passes to Print. The destination +// references the array directly. target C reactor Source { - output out: int[3] + output out: int[3] - reaction(startup) -> out {= - out->value[0] = 0; - out->value[1] = 1; - out->value[2] = 2; - SET_PRESENT(out); - =} + reaction(startup) -> out {= + out->value[0] = 0; + out->value[1] = 1; + out->value[2] = 2; + SET_PRESENT(out); + =} } reactor Print(scale: int = 1) { // The scale parameter is just for testing. - input in: int[3] + input in: int[3] - reaction(in) {= - int count = 0; // For testing. - bool failed = false; // For testing. - printf("Received: ["); - for (int i = 0; i < 3; i++) { - if (i > 0) printf(", "); - printf("%d", in->value[i]); - // For testing, check whether values match expectation. - if (in->value[i] != self->scale * count) { - failed = true; - } - count++; // For testing. + reaction(in) {= + int count = 0; // For testing. + bool failed = false; // For testing. + printf("Received: ["); + for (int i = 0; i < 3; i++) { + if (i > 0) printf(", "); + printf("%d", in->value[i]); + // For testing, check whether values match expectation. + if (in->value[i] != self->scale * count) { + failed = true; } - printf("]\n"); - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); - } - =} + count++; // For testing. + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } main reactor ArrayAsType { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/ArrayFree.lf b/test/C/src/ArrayFree.lf index 11b31c123f..ced36f82f7 100644 --- a/test/C/src/ArrayFree.lf +++ b/test/C/src/ArrayFree.lf @@ -1,31 +1,31 @@ -// Source produces a dynamically allocated array, which it passes to Free. Free -// requests a writable copy, which, instead of copying, it just gets ownership -// of the original array. It then does nothing further with it. This test checks -// that the memory gets freed automatically even with the mutable input. +// Source produces a dynamically allocated array, which it passes to Free. Free requests a writable +// copy, which, instead of copying, it just gets ownership of the original array. It then does +// nothing further with it. This test checks that the memory gets freed automatically even with the +// mutable input. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import Source, Print from "ArrayPrint.lf" import Scale from "ArrayScale.lf" reactor Free(scale: int = 2, size: int = 3) { - mutable input in: int[] + mutable input in: int[] - reaction(in) {= - for(int i = 0; i < self->size; i++) { - in->value[i] *= self->scale; - } - =} + reaction(in) {= + for(int i = 0; i < self->size; i++) { + in->value[i] *= self->scale; + } + =} } main reactor ArrayFree { - s = new Source() - c = new Free() - c2 = new Scale() - p = new Print(scale = 2) - s.out -> c.in - s.out -> c2.in - c2.out -> p.in + s = new Source() + c = new Free() + c2 = new Scale() + p = new Print(scale = 2) + s.out -> c.in + s.out -> c2.in + c2.out -> p.in } diff --git a/test/C/src/ArrayFreeMultiple.lf b/test/C/src/ArrayFreeMultiple.lf index 7b933ce518..292f5cdb10 100644 --- a/test/C/src/ArrayFreeMultiple.lf +++ b/test/C/src/ArrayFreeMultiple.lf @@ -1,47 +1,47 @@ -// Source produces a dynamically allocated array, which it passes to Free. Free -// requests a writable copy, which, instead of copying, it just gets ownership -// of the original array. It then does nothing further with it. This test checks -// that the memory gets freed automatically even with the mutable input. +// Source produces a dynamically allocated array, which it passes to Free. Free requests a writable +// copy, which, instead of copying, it just gets ownership of the original array. It then does +// nothing further with it. This test checks that the memory gets freed automatically even with the +// mutable input. target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } import Scale from "ArrayScale.lf" import Print from "ArrayPrint.lf" reactor Source { - output out: int[] - state c: int = 0 - timer t(0, 1 sec) + output out: int[] + state c: int = 0 + timer t(0, 1 sec) - reaction(t) -> out {= - // Dynamically allocate an output array of length 3. - SET_NEW_ARRAY(out, 3); + reaction(t) -> out {= + // Dynamically allocate an output array of length 3. + SET_NEW_ARRAY(out, 3); - // Above allocates the array, which then must be populated. - out->value[0] = self->c++; - out->value[1] = self->c++; - out->value[2] = self->c++; - =} + // Above allocates the array, which then must be populated. + out->value[0] = self->c++; + out->value[1] = self->c++; + out->value[2] = self->c++; + =} } reactor Free(scale: int = 2) { - mutable input in: int[] + mutable input in: int[] - reaction(in) {= - for(int i = 0; i < in->length; i++) { - in->value[i] *= self->scale; - } - =} + reaction(in) {= + for(int i = 0; i < in->length; i++) { + in->value[i] *= self->scale; + } + =} } main reactor ArrayFreeMultiple { - s = new Source() - c = new Free() - c2 = new Scale() - p = new Print(scale = 2) - s.out -> c.in - s.out -> c2.in - c2.out -> p.in + s = new Source() + c = new Free() + c2 = new Scale() + p = new Print(scale = 2) + s.out -> c.in + s.out -> c2.in + c2.out -> p.in } diff --git a/test/C/src/ArrayParallel.lf b/test/C/src/ArrayParallel.lf index 6275924b82..3edb9c659e 100644 --- a/test/C/src/ArrayParallel.lf +++ b/test/C/src/ArrayParallel.lf @@ -1,9 +1,9 @@ -// Source allocates an array dynamically and then sends it to two reactors, each -// of which want to modify it. NOTE: Ideally, only one copy would be made, but -// this requires modifying the precedence graph between reactions. +// Source allocates an array dynamically and then sends it to two reactors, each of which want to +// modify it. NOTE: Ideally, only one copy would be made, but this requires modifying the precedence +// graph between reactions. target C { - timeout: 3 sec, - fast: true + timeout: 3 sec, + fast: true } import Scale from "ArrayScale.lf" diff --git a/test/C/src/ArrayPrint.lf b/test/C/src/ArrayPrint.lf index 937bc51bea..9cbf0e2fd6 100644 --- a/test/C/src/ArrayPrint.lf +++ b/test/C/src/ArrayPrint.lf @@ -1,57 +1,55 @@ -// Source produces a dynamically allocated array, which it passes to Print. -// Reference counting ensures that the array is freed. The array size here must -// be known to all reactors. +// Source produces a dynamically allocated array, which it passes to Print. Reference counting +// ensures that the array is freed. The array size here must be known to all reactors. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source(size: int = 3) { - output out: int[] - state count: int = 0 - timer t(0, 1 sec) + output out: int[] + state count: int = 0 + timer t(0, 1 sec) - reaction(t) -> out {= - // Dynamically allocate an output array of length 3. - // Note that the receiving reactors need to know that the length is 3. - // A better design is given at: - // https://www.lf-lang.org/docs/handbook/target-language-details?target=c#dynamically-allocated-data - SET_NEW_ARRAY(out, 3); + reaction(t) -> out {= + // Dynamically allocate an output array of length 3. + // Note that the receiving reactors need to know that the length is 3. + // A better design is given at: + // https://www.lf-lang.org/docs/handbook/target-language-details?target=c#dynamically-allocated-data + SET_NEW_ARRAY(out, 3); - // Above allocates the array, which then must be populated. - out->value[0] = self->count++; - out->value[1] = self->count++; - out->value[2] = self->count++; - =} + // Above allocates the array, which then must be populated. + out->value[0] = self->count++; + out->value[1] = self->count++; + out->value[2] = self->count++; + =} } -// The scale parameter is just for testing. -reactor Print(scale: int = 1, size: int = 3) { - input in: int[] - state count: int = 0 +reactor Print(scale: int = 1, size: int = 3) { // The scale parameter is just for testing. + input in: int[] + state count: int = 0 - reaction(in) {= - bool failed = false; // For testing. - printf("Received: ["); - for (int i = 0; i < self->size; i++) { - if (i > 0) printf(", "); - printf("%d", in->value[i]); - // For testing, check whether values match expectation. - if (in->value[i] != self->scale * self->count) { - failed = true; - } - self->count++; // For testing. + reaction(in) {= + bool failed = false; // For testing. + printf("Received: ["); + for (int i = 0; i < self->size; i++) { + if (i > 0) printf(", "); + printf("%d", in->value[i]); + // For testing, check whether values match expectation. + if (in->value[i] != self->scale * self->count) { + failed = true; } - printf("]\n"); - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); - } - =} + self->count++; // For testing. + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } main reactor ArrayPrint { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/ArrayScale.lf b/test/C/src/ArrayScale.lf index 63edfc421c..06744dbcf1 100644 --- a/test/C/src/ArrayScale.lf +++ b/test/C/src/ArrayScale.lf @@ -1,30 +1,29 @@ -// Source produces a dynamically allocated array, which it passes to Scale. -// Scale requests a writable copy, which, instead of copying, it just gets -// ownership of the original array. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated array, which it passes to Scale. Scale requests a +// writable copy, which, instead of copying, it just gets ownership of the original array. It +// modifies it and passes it to Print. It gets freed after Print is done with it. target C { - timeout: 3 sec, - fast: true + timeout: 3 sec, + fast: true } import Print, Source from "ArrayPrint.lf" reactor Scale(scale: int = 2) { - mutable input in: int[] - output out: int[] + mutable input in: int[] + output out: int[] - reaction(in) -> out {= - for(int i = 0; i < in->length; i++) { - in->value[i] *= self->scale; - } - lf_set_token(out, in->token); - =} + reaction(in) -> out {= + for(int i = 0; i < in->length; i++) { + in->value[i] *= self->scale; + } + lf_set_token(out, in->token); + =} } main reactor ArrayScale { - s = new Source() - c = new Scale() - p = new Print(scale = 2) - s.out -> c.in - c.out -> p.in + s = new Source() + c = new Scale() + p = new Print(scale = 2) + s.out -> c.in + c.out -> p.in } diff --git a/test/C/src/CharLiteralInitializer.lf b/test/C/src/CharLiteralInitializer.lf index 319af0224c..ab0c12b1d8 100644 --- a/test/C/src/CharLiteralInitializer.lf +++ b/test/C/src/CharLiteralInitializer.lf @@ -2,12 +2,12 @@ target C main reactor CharLiteralInitializer { - state c: char = 'x' + state c: char = 'x' - reaction(startup) {= - if (self->c != 'x') { - fprintf(stderr, "FAILED: Expected 'x', got %c.\n", self->c); - exit(1); - } - =} + reaction(startup) {= + if (self->c != 'x') { + fprintf(stderr, "FAILED: Expected 'x', got %c.\n", self->c); + exit(1); + } + =} } diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index 7c024a9eba..823bd1a2fe 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -1,45 +1,44 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - printf("Source sending %d.\n", self->count); - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + printf("Source sending %d.\n", self->count); + lf_set(y, self->count); + =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - fprintf(stderr, "FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + fprintf(stderr, "FAILURE: Expected %d\n", self->count); + exit(1); + } + =} - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "FAILURE: No data received.\n"); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "FAILURE: No data received.\n"); + } + =} } main reactor Composition { - s = new Source() + s = new Source() - d = new Test() - s.y -> d.x + d = new Test() + s.y -> d.x } diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index cb98ef7d7e..c0ce81f46b 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -1,37 +1,36 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d\n", self->count); + exit(1); + } + =} } main reactor CompositionAfter(delay: time = 5 sec) { - s = new Source() - d = new Test() - s.y -> d.x after delay + s = new Source() + d = new Test() + s.y -> d.x after delay } diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index 06221e9788..cd345149d5 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -1,56 +1,55 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - input foo: int - output y: int - timer t(1 sec, period) - state count: int = 0 - - reaction(t) -> y {= - printf("Hello World. At time %lld, my count is: %d.\n", lf_time_logical_elapsed(), self->count); - lf_set(y, self->count); - =} + input foo: int + output y: int + timer t(1 sec, period) + state count: int = 0 + + reaction(t) -> y {= + printf("Hello World. At time %lld, my count is: %d.\n", lf_time_logical_elapsed(), self->count); + lf_set(y, self->count); + =} } reactor SourceExtended extends Source { - output y2: int - timer t2(1 sec, 3 sec) - - reaction(t2) -> y2 {= - (self->count)++; - printf("At time %lld, source sending %d.\n", lf_time_logical_elapsed(), self->count); - lf_set(y2, self->count); - =} + output y2: int + timer t2(1 sec, 3 sec) + + reaction(t2) -> y2 {= + (self->count)++; + printf("At time %lld, source sending %d.\n", lf_time_logical_elapsed(), self->count); + lf_set(y2, self->count); + =} } reactor Test { - input x: int - state count: int = 0 - - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - fprintf(stderr, "FAILURE: Expected %d\n", self->count); - exit(1); - } - =} - - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "FAILURE: No data received.\n"); - } - =} + input x: int + state count: int = 0 + + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + fprintf(stderr, "FAILURE: Expected %d\n", self->count); + exit(1); + } + =} + + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "FAILURE: No data received.\n"); + } + =} } main reactor CompositionInheritance { - s = new SourceExtended(period = 2 sec) + s = new SourceExtended(period = 2 sec) - d = new Test() - s.y2 -> d.x + d = new Test() + s.y2 -> d.x } diff --git a/test/C/src/CountSelf.lf b/test/C/src/CountSelf.lf index 1ef27187ae..ec910c1066 100644 --- a/test/C/src/CountSelf.lf +++ b/test/C/src/CountSelf.lf @@ -1,28 +1,28 @@ // This tests actions with payloads by delaying an input by a fixed amount. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import TestCount from "lib/TestCount.lf" reactor CountSelf2(delay: time = 100 msec) { - output out: int - logical action a: int + output out: int + logical action a: int - reaction(startup) -> a, out {= - lf_set(out, 0); - lf_schedule_int(a, self->delay, 1); - =} + reaction(startup) -> a, out {= + lf_set(out, 0); + lf_schedule_int(a, self->delay, 1); + =} - reaction(a) -> a, out {= - lf_set(out, a->value); - lf_schedule_int(a, self->delay, a->value + 1); - =} + reaction(a) -> a, out {= + lf_set(out, a->value); + lf_schedule_int(a, self->delay, a->value + 1); + =} } main reactor { - d = new CountSelf2() - t = new TestCount(num_inputs = 11, start = 0) - d.out -> t.in + d = new CountSelf2() + t = new TestCount(num_inputs = 11, start = 0) + d.out -> t.in } diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index 21ea7df141..76d5bf564e 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -1,62 +1,61 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target C { - timeout: 6 sec + timeout: 6 sec } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} reactor Source(period: time = 3 sec) { - output y: int - timer t(0, period) - state count: int = 0 + output y: int + timer t(0, period) + state count: int = 0 - reaction(t) -> y {= - if (2 * (self->count / 2) != self->count) { - // The count variable is odd. - // Take time to cause a deadline violation. - lf_sleep(MSEC(1500)); - } - printf("Source sends: %d.\n", self->count); - lf_set(y, self->count); - (self->count)++; - =} + reaction(t) -> y {= + if (2 * (self->count / 2) != self->count) { + // The count variable is odd. + // Take time to cause a deadline violation. + lf_sleep(MSEC(1500)); + } + printf("Source sends: %d.\n", self->count); + lf_set(y, self->count); + (self->count)++; + =} } reactor Destination(timeout: time = 1 sec) { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - printf("Destination receives: %d\n", x->value); - if (2 * (self->count / 2) != self->count) { - // The count variable is odd, so the deadline should have been violated. - printf("ERROR: Failed to detect deadline.\n"); - exit(1); - } - (self->count)++; - =} deadline(timeout) {= - printf("Destination deadline handler receives: %d\n", x->value); - if (2 * (self->count / 2) == self->count) { - // The count variable is even, so the deadline should not have been violated. - printf("ERROR: Deadline miss handler invoked without deadline violation.\n"); - exit(2); - } - (self->count)++; - =} + reaction(x) {= + printf("Destination receives: %d\n", x->value); + if (2 * (self->count / 2) != self->count) { + // The count variable is odd, so the deadline should have been violated. + printf("ERROR: Failed to detect deadline.\n"); + exit(1); + } + (self->count)++; + =} deadline(timeout) {= + printf("Destination deadline handler receives: %d\n", x->value); + if (2 * (self->count / 2) == self->count) { + // The count variable is even, so the deadline should not have been violated. + printf("ERROR: Deadline miss handler invoked without deadline violation.\n"); + exit(2); + } + (self->count)++; + =} } main reactor Deadline { - s = new Source() - d = new Destination(timeout = 1 sec) - s.y -> d.x + s = new Source() + d = new Destination(timeout = 1 sec) + s.y -> d.x } diff --git a/test/C/src/DeadlineHandledAbove.lf b/test/C/src/DeadlineHandledAbove.lf index 3b0dc49198..df20467cad 100644 --- a/test/C/src/DeadlineHandledAbove.lf +++ b/test/C/src/DeadlineHandledAbove.lf @@ -1,52 +1,52 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target C preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} reactor Deadline(threshold: time = 100 msec) { - input x: int - output deadline_violation: bool + input x: int + output deadline_violation: bool - reaction(x) -> deadline_violation {= - printf("ERROR: Deadline violation was not detected!\n"); - exit(1); - =} deadline(threshold) {= - printf("Deadline violation detected.\n"); - lf_set(deadline_violation, true); - =} + reaction(x) -> deadline_violation {= + printf("ERROR: Deadline violation was not detected!\n"); + exit(1); + =} deadline(threshold) {= + printf("Deadline violation detected.\n"); + lf_set(deadline_violation, true); + =} } main reactor DeadlineHandledAbove { - state violation_detected: bool = false - d = new Deadline(threshold = 10 msec) + state violation_detected: bool = false + d = new Deadline(threshold = 10 msec) - reaction(startup) -> d.x {= - lf_nanosleep(MSEC(200)); - lf_set(d.x, 42); - =} + reaction(startup) -> d.x {= + lf_nanosleep(MSEC(200)); + lf_set(d.x, 42); + =} - reaction(d.deadline_violation) {= - if (d.deadline_violation->value) { - printf("Output successfully produced by deadline miss handler.\n"); - self->violation_detected = true; - } - =} + reaction(d.deadline_violation) {= + if (d.deadline_violation->value) { + printf("Output successfully produced by deadline miss handler.\n"); + self->violation_detected = true; + } + =} - reaction(shutdown) {= - if (self->violation_detected) { - printf("SUCCESS. Test passes.\n"); - } else { - printf("FAILURE. Container did not react to deadline violation.\n"); - exit(2); - } - =} + reaction(shutdown) {= + if (self->violation_detected) { + printf("SUCCESS. Test passes.\n"); + } else { + printf("FAILURE. Container did not react to deadline violation.\n"); + exit(2); + } + =} } diff --git a/test/C/src/DeadlineInherited.lf b/test/C/src/DeadlineInherited.lf index 3d3c8ac96b..de718e34a0 100644 --- a/test/C/src/DeadlineInherited.lf +++ b/test/C/src/DeadlineInherited.lf @@ -1,32 +1,32 @@ // Test to verify that deadline priority are inherited target C { - timeout: 1 sec, - threading: false + timeout: 1 sec, + threading: false } preamble {= extern int global_cnt; =} reactor NoDeadline { - preamble {= int global_cnt = 0; =} - timer t(0 msec, 100 msec) + preamble {= int global_cnt = 0; =} + timer t(0 msec, 100 msec) - reaction(t) {= global_cnt++; =} + reaction(t) {= global_cnt++; =} } reactor WithDeadline { - timer t(0 msec, 100 msec) + timer t(0 msec, 100 msec) - reaction(t) {= =} + reaction(t) {= =} - reaction(t) {= - if (global_cnt != 0) { - lf_print_error_and_exit("Deadline reaction was not executed first. cnt=%i", global_cnt); - } - global_cnt--; - =} deadline(100 sec) {= =} + reaction(t) {= + if (global_cnt != 0) { + lf_print_error_and_exit("Deadline reaction was not executed first. cnt=%i", global_cnt); + } + global_cnt--; + =} deadline(100 sec) {= =} } main reactor { - a = new NoDeadline() - b = new WithDeadline() + a = new NoDeadline() + b = new WithDeadline() } diff --git a/test/C/src/DeadlinePriority.lf b/test/C/src/DeadlinePriority.lf index 2aa5c8136f..21a810e786 100644 --- a/test/C/src/DeadlinePriority.lf +++ b/test/C/src/DeadlinePriority.lf @@ -1,30 +1,30 @@ // Test to verify that deadline gives priority target C { - timeout: 1 sec, - threading: false + timeout: 1 sec, + threading: false } preamble {= extern int global_cnt; =} reactor NoDeadline { - preamble {= int global_cnt = 0; =} - timer t(0 msec, 100 msec) + preamble {= int global_cnt = 0; =} + timer t(0 msec, 100 msec) - reaction(t) {= global_cnt++; =} + reaction(t) {= global_cnt++; =} } reactor WithDeadline { - timer t(0 msec, 100 msec) + timer t(0 msec, 100 msec) - reaction(t) {= - if (global_cnt != 0) { - lf_print_error_and_exit("Deadline reaction was not executed first. cnt=%i", global_cnt); - } - global_cnt--; - =} deadline(100 sec) {= =} + reaction(t) {= + if (global_cnt != 0) { + lf_print_error_and_exit("Deadline reaction was not executed first. cnt=%i", global_cnt); + } + global_cnt--; + =} deadline(100 sec) {= =} } main reactor { - a = new NoDeadline() - b = new WithDeadline() + a = new NoDeadline() + b = new WithDeadline() } diff --git a/test/C/src/DeadlineWithAfterDelay.lf b/test/C/src/DeadlineWithAfterDelay.lf index 5e33e129e6..af4d1cc8c8 100644 --- a/test/C/src/DeadlineWithAfterDelay.lf +++ b/test/C/src/DeadlineWithAfterDelay.lf @@ -1,36 +1,36 @@ // Test to verify that deadline priority are inherited when using after delays target C { - timeout: 1 sec, - threading: false + timeout: 1 sec, + threading: false } preamble {= extern int global_cnt; =} reactor Source { - preamble {= int global_cnt = 0; =} + preamble {= int global_cnt = 0; =} - output out: int - timer t(0 msec, 100 msec) + output out: int + timer t(0 msec, 100 msec) - reaction(t) -> out {= - lf_set(out, 1); - global_cnt++; - =} + reaction(t) -> out {= + lf_set(out, 1); + global_cnt++; + =} } reactor SinkWithDeadline { - input in: int + input in: int - reaction(in) {= - global_cnt--; - if (global_cnt != 0) { - lf_print_error_and_exit("Deadline reaction was not executed first. cnt=%i", global_cnt); - } - =} deadline(100 sec) {= =} + reaction(in) {= + global_cnt--; + if (global_cnt != 0) { + lf_print_error_and_exit("Deadline reaction was not executed first. cnt=%i", global_cnt); + } + =} deadline(100 sec) {= =} } main reactor { - a = new Source() - b = new SinkWithDeadline() - a.out -> b.in after 100 msec // a.out -> b.in + a = new Source() + b = new SinkWithDeadline() + a.out -> b.in after 100 msec // a.out -> b.in } diff --git a/test/C/src/DeadlineWithBanks.lf b/test/C/src/DeadlineWithBanks.lf index 7a9445ec8d..2e1fd9bcca 100644 --- a/test/C/src/DeadlineWithBanks.lf +++ b/test/C/src/DeadlineWithBanks.lf @@ -1,65 +1,64 @@ /** - * This program verifies that reactions inside banks inherit the correct - * priority from their downstream reactions. A global variable is used to check - * execution order. Threading is disabled + * This program verifies that reactions inside banks inherit the correct priority from their + * downstream reactions. A global variable is used to check execution order. Threading is disabled */ target C { - threading: false, - timeout: 300 msec, - build-type: Debug + threading: false, + timeout: 300 msec, + build-type: Debug } preamble {= extern volatile int global_cnt; =} reactor Bank(bank_index: int = 0) { - preamble {= volatile int global_cnt = 0; =} + preamble {= volatile int global_cnt = 0; =} - timer t(0, 100 msec) - output out: int + timer t(0, 100 msec) + output out: int - reaction(t) -> out {= - int exp_cnt; - switch(self->bank_index) { - case 0: { - exp_cnt = 3; - break; - } - case 1: { - exp_cnt = 1; - break; - } - case 2: { - exp_cnt = 0; - break; - } - case 3: { - exp_cnt = 2; - break; - } + reaction(t) -> out {= + int exp_cnt; + switch(self->bank_index) { + case 0: { + exp_cnt = 3; + break; } - if (global_cnt != exp_cnt) { - lf_print_error_and_exit("global_cnt=%i expected=%i\n", global_cnt, exp_cnt); + case 1: { + exp_cnt = 1; + break; } - global_cnt++; - - if (self->bank_index==0) { - global_cnt=0; + case 2: { + exp_cnt = 0; + break; + } + case 3: { + exp_cnt = 2; + break; } - =} + } + if (global_cnt != exp_cnt) { + lf_print_error_and_exit("global_cnt=%i expected=%i\n", global_cnt, exp_cnt); + } + global_cnt++; + + if (self->bank_index==0) { + global_cnt=0; + } + =} } reactor Sink(dead: time = 0) { - input in: int + input in: int - reaction(in) {= =} deadline(dead) {= =} + reaction(in) {= =} deadline(dead) {= =} } main reactor { - rp = new[4] Bank() - s1 = new Sink(dead = 14 msec) - s2 = new Sink(dead = 12 msec) - s3 = new Sink(dead = 11 msec) - s4 = new Sink(dead = 13 msec) + rp = new[4] Bank() + s1 = new Sink(dead = 14 msec) + s2 = new Sink(dead = 12 msec) + s3 = new Sink(dead = 11 msec) + s4 = new Sink(dead = 13 msec) - rp.out -> s1.in, s2.in, s3.in, s4.in + rp.out -> s1.in, s2.in, s3.in, s4.in } diff --git a/test/C/src/DeadlineZero.lf b/test/C/src/DeadlineZero.lf index 3ae49a9409..26f556a800 100644 --- a/test/C/src/DeadlineZero.lf +++ b/test/C/src/DeadlineZero.lf @@ -1,27 +1,27 @@ // Tests that specified deadlines with zero duration are always violated. target C { - timeout: 1 sec + timeout: 1 sec } reactor Detector { - input trigger: int - state cnt: int = 0 + input trigger: int + state cnt: int = 0 - reaction(trigger) {= - printf("ERROR: failed to detect zero-duration deadline at iteration %d.\n", self->cnt); - exit(1); - =} deadline(0 msec) {= self->cnt++; =} + reaction(trigger) {= + printf("ERROR: failed to detect zero-duration deadline at iteration %d.\n", self->cnt); + exit(1); + =} deadline(0 msec) {= self->cnt++; =} } reactor Generator { - output pulse: int - timer t(0, 100 msec) + output pulse: int + timer t(0, 100 msec) - reaction(t) -> pulse {= lf_set(pulse, 0); =} + reaction(t) -> pulse {= lf_set(pulse, 0); =} } main reactor { - g = new Generator() - d = new Detector() - g.pulse -> d.trigger + g = new Generator() + d = new Detector() + g.pulse -> d.trigger } diff --git a/test/C/src/DelayArray.lf b/test/C/src/DelayArray.lf index 72eb734888..62f36b059e 100644 --- a/test/C/src/DelayArray.lf +++ b/test/C/src/DelayArray.lf @@ -1,63 +1,62 @@ -// This tests delaying an array type. The array length has to be agreed upon by -// all reactors. +// This tests delaying an array type. The array length has to be agreed upon by all reactors. target C { - build-type: RelWithDebInfo + build-type: RelWithDebInfo } reactor DelayPointer(delay: time = 100 msec) { - input in: int[] - output out: int[] - logical action a: int[] + input in: int[] + output out: int[] + logical action a: int[] - reaction(in) -> a {= lf_schedule_token(a, self->delay, in->token); =} + reaction(in) -> a {= lf_schedule_token(a, self->delay, in->token); =} - reaction(a) -> out {= lf_set_token(out, a->token); =} + reaction(a) -> out {= lf_set_token(out, a->token); =} } reactor Source { - output out: int[] - - reaction(startup) -> out {= - // Dynamically allocate an output array of length 3. - // Note that the receiving reactors need to know that the length is 3. - // A better design is given at: - // https://www.lf-lang.org/docs/handbook/target-language-details?target=c#dynamically-allocated-data - int* array = (int*)malloc(3 * sizeof(int)); - for (size_t i = 0; i < 3; i++) { - array[i] = i; - } - lf_set(out, array); - =} + output out: int[] + + reaction(startup) -> out {= + // Dynamically allocate an output array of length 3. + // Note that the receiving reactors need to know that the length is 3. + // A better design is given at: + // https://www.lf-lang.org/docs/handbook/target-language-details?target=c#dynamically-allocated-data + int* array = (int*)malloc(3 * sizeof(int)); + for (size_t i = 0; i < 3; i++) { + array[i] = i; + } + lf_set(out, array); + =} } reactor Print(scale: int = 1) { // The scale parameter is just for testing. - input in: int[] - - reaction(in) {= - int count = 0; // For testing. - bool failed = false; // For testing. - printf("Received: ["); - for (int i = 0; i < 3; i++) { - if (i > 0) printf(", "); - printf("%d", in->value[i]); - // For testing, check whether values match expectation. - if (in->value[i] != self->scale * count) { - failed = true; - } - count++; // For testing. - } - printf("]\n"); - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); + input in: int[] + + reaction(in) {= + int count = 0; // For testing. + bool failed = false; // For testing. + printf("Received: ["); + for (int i = 0; i < 3; i++) { + if (i > 0) printf(", "); + printf("%d", in->value[i]); + // For testing, check whether values match expectation. + if (in->value[i] != self->scale * count) { + failed = true; } - =} + count++; // For testing. + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } main reactor DelayArray { - s = new Source() - d = new DelayPointer() - p = new Print() - s.out -> d.in - d.out -> p.in + s = new Source() + d = new DelayPointer() + p = new Print() + s.out -> d.in + d.out -> p.in } diff --git a/test/C/src/DelayArrayWithAfter.lf b/test/C/src/DelayArrayWithAfter.lf index c94be3b9a1..094d264b08 100644 --- a/test/C/src/DelayArrayWithAfter.lf +++ b/test/C/src/DelayArrayWithAfter.lf @@ -1,70 +1,69 @@ -// This tests transport of dynamically allocated arrays over connections with -// 'after'. +// This tests transport of dynamically allocated arrays over connections with 'after'. target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out: int[] - state iteration: int = 1 - timer t(0, 1 sec) + output out: int[] + state iteration: int = 1 + timer t(0, 1 sec) - reaction(t) -> out {= - // Dynamically allocate an output array of length 3. - SET_NEW_ARRAY(out, 3); - printf("At time %lld, sending array at address %p\n", lf_time_logical_elapsed(), out->value); + reaction(t) -> out {= + // Dynamically allocate an output array of length 3. + SET_NEW_ARRAY(out, 3); + printf("At time %lld, sending array at address %p\n", lf_time_logical_elapsed(), out->value); - // Above allocates the array, which then must be populated. - out->value[0] = 1 * self->iteration; - out->value[1] = 2 * self->iteration; - out->value[2] = 3 * self->iteration; - self->iteration++; - =} + // Above allocates the array, which then must be populated. + out->value[0] = 1 * self->iteration; + out->value[1] = 2 * self->iteration; + out->value[2] = 3 * self->iteration; + self->iteration++; + =} } reactor Print(scale: int = 1) { // The scale parameter is just for testing. - input in: int[] - state iteration: int = 1 - state inputs_received: int = 0 + input in: int[] + state iteration: int = 1 + state inputs_received: int = 0 - reaction(in) {= - self->inputs_received++; - int count = 1; // For testing. - bool failed = false; // For testing. - printf("At time %lld, received array at address %p\n", lf_time_logical_elapsed(), in->value); - printf("Received: ["); - for (int i = 0; i < in->length; i++) { - if (i > 0) printf(", "); - printf("%d", in->value[i]); - // For testing, check whether values match expectation. - if (in->value[i] != self->scale * count * self->iteration) { - failed = true; - } - count++; // For testing. + reaction(in) {= + self->inputs_received++; + int count = 1; // For testing. + bool failed = false; // For testing. + printf("At time %lld, received array at address %p\n", lf_time_logical_elapsed(), in->value); + printf("Received: ["); + for (int i = 0; i < in->length; i++) { + if (i > 0) printf(", "); + printf("%d", in->value[i]); + // For testing, check whether values match expectation. + if (in->value[i] != self->scale * count * self->iteration) { + failed = true; } - printf("]\n"); - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); - } - if (count != 4) { - printf("ERROR: Received array length is not 3!\n"); - exit(2); - } - self->iteration++; - =} + count++; // For testing. + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + if (count != 4) { + printf("ERROR: Received array length is not 3!\n"); + exit(2); + } + self->iteration++; + =} - reaction(shutdown) {= - if (self->inputs_received == 0) { - printf("ERROR: Print reactor received no inputs.\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (self->inputs_received == 0) { + printf("ERROR: Print reactor received no inputs.\n"); + exit(3); + } + =} } main reactor DelayArrayWithAfter { - s = new Source() - p = new Print() - s.out -> p.in after 1500 msec + s = new Source() + p = new Print() + s.out -> p.in after 1500 msec } diff --git a/test/C/src/DelayInt.lf b/test/C/src/DelayInt.lf index 78ca793716..a8fce5fe4e 100644 --- a/test/C/src/DelayInt.lf +++ b/test/C/src/DelayInt.lf @@ -2,60 +2,58 @@ target C reactor Delay(delay: time = 100 msec) { - input in: int - output out: int - logical action a: int - - reaction(a) -> out {= - if (a->has_value && a->is_present) lf_set(out, a->value); - =} - - reaction(in) -> a {= - // Use specialized form of schedule for integer payloads. - lf_schedule_int(a, self->delay, in->value); - =} + input in: int + output out: int + logical action a: int + + reaction(a) -> out {= if (a->has_value && a->is_present) lf_set(out, a->value); =} + + reaction(in) -> a {= + // Use specialized form of schedule for integer payloads. + lf_schedule_int(a, self->delay, in->value); + =} } reactor Test { - input in: int - state start_time: time = 0 - state received_value: bool = false - - reaction(startup) {= - // Record the logical time at the start. - self->start_time = lf_time_logical(); - =} - - reaction(in) {= - printf("Received: %d.\n", in->value); - self->received_value = true; - // Check the time of the input. - instant_t current_time = lf_time_logical(); - interval_t elapsed = current_time - self->start_time; - printf("After %lld nsec of logical time.\n", elapsed); - if (elapsed != 100000000LL) { - printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); - exit(1); - } - if (in->value != 42) { - printf("ERROR: Expected input value to be 42. It was %d.\n", in->value); - exit(2); - } - =} - - reaction(shutdown) {= - printf("Checking that communication occurred.\n"); - if (!self->received_value) { - printf("ERROR: No communication occurred!\n"); - exit(3); - } - =} + input in: int + state start_time: time = 0 + state received_value: bool = false + + reaction(startup) {= + // Record the logical time at the start. + self->start_time = lf_time_logical(); + =} + + reaction(in) {= + printf("Received: %d.\n", in->value); + self->received_value = true; + // Check the time of the input. + instant_t current_time = lf_time_logical(); + interval_t elapsed = current_time - self->start_time; + printf("After %lld nsec of logical time.\n", elapsed); + if (elapsed != 100000000LL) { + printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); + exit(1); + } + if (in->value != 42) { + printf("ERROR: Expected input value to be 42. It was %d.\n", in->value); + exit(2); + } + =} + + reaction(shutdown) {= + printf("Checking that communication occurred.\n"); + if (!self->received_value) { + printf("ERROR: No communication occurred!\n"); + exit(3); + } + =} } main reactor DelayInt { - d = new Delay() - t = new Test() - d.out -> t.in + d = new Delay() + t = new Test() + d.out -> t.in - reaction(startup) -> d.in {= lf_set(d.in, 42); =} + reaction(startup) -> d.in {= lf_set(d.in, 42); =} } diff --git a/test/C/src/DelayPointer.lf b/test/C/src/DelayPointer.lf index c6313c199d..d0dba9d68e 100644 --- a/test/C/src/DelayPointer.lf +++ b/test/C/src/DelayPointer.lf @@ -2,72 +2,72 @@ target C reactor DelayPointer2(delay: time = 100 msec) { - input in: int* - output out: int* - logical action a: int* + input in: int* + output out: int* + logical action a: int* - reaction(a) -> out {= - // Using lf_set_token delegates responsibility for - // freeing the allocated memory downstream. - lf_set_token(out, a->token); - =} + reaction(a) -> out {= + // Using lf_set_token delegates responsibility for + // freeing the allocated memory downstream. + lf_set_token(out, a->token); + =} - reaction(in) -> a {= - // Schedule the actual token from the input rather than - // a new token with a copy of the input value. - lf_schedule_token(a, self->delay, in->token); - =} + reaction(in) -> a {= + // Schedule the actual token from the input rather than + // a new token with a copy of the input value. + lf_schedule_token(a, self->delay, in->token); + =} } reactor Source { - output out: int* + output out: int* - reaction(startup) -> out {= - SET_NEW(out); - *(out->value) = 42; - =} + reaction(startup) -> out {= + SET_NEW(out); + *(out->value) = 42; + =} } reactor Test { - input in: int* - state start_time: time = 0 - state received_value: bool = false + input in: int* + state start_time: time = 0 + state received_value: bool = false - reaction(startup) {= - // Record the logical time at the start. - self->start_time = lf_time_logical(); - =} + reaction(startup) {= + // Record the logical time at the start. + self->start_time = lf_time_logical(); + =} - reaction(in) {= - printf("Received: %d.\n", *(in->value)); - self->received_value = true; - // Check the time of the input. - instant_t current_time = lf_time_logical(); - interval_t elapsed = current_time - self->start_time; - printf("After %lld nsec of logical time.\n", elapsed); - if (elapsed != 100000000LL) { - printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); - exit(1); - } - if (*(in->value) != 42) { - printf("ERROR: Expected input value to be 42. It was %d.\n", *(in->value)); - exit(2); - } - =} + reaction(in) {= + printf("Received: %d.\n", *(in->value)); + self->received_value = true; + // Check the time of the input. + instant_t current_time = lf_time_logical(); + interval_t elapsed = current_time - self->start_time; + printf("After %lld nsec of logical time.\n", elapsed); + if (elapsed != 100000000LL) { + printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); + exit(1); + } + if (*(in->value) != 42) { + printf("ERROR: Expected input value to be 42. It was %d.\n", *(in->value)); + exit(2); + } + =} - reaction(shutdown) {= - printf("Checking that communication occurred.\n"); - if (!self->received_value) { - printf("ERROR: No communication occurred!\n"); - exit(3); - } - =} + reaction(shutdown) {= + printf("Checking that communication occurred.\n"); + if (!self->received_value) { + printf("ERROR: No communication occurred!\n"); + exit(3); + } + =} } main reactor { - s = new Source() - d = new DelayPointer2() - t = new Test() - s.out -> d.in - d.out -> t.in + s = new Source() + d = new DelayPointer2() + t = new Test() + s.out -> d.in + d.out -> t.in } diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index 1b4204cfc4..9eb5417375 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -1,53 +1,52 @@ -// This tests actions with immutable payloads that are neither malloc'd nor -// freed. +// This tests actions with immutable payloads that are neither malloc'd nor freed. target C preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include + #ifdef __cplusplus + } + #endif =} reactor DelayString2(delay: time = 100 msec) { - input in: string - output out: string - logical action a: string + input in: string + output out: string + logical action a: string - reaction(a) -> out {= lf_set(out, a->value); =} + reaction(a) -> out {= lf_set(out, a->value); =} - reaction(in) -> a {= - // The following copies the char*, not the string. - lf_schedule_copy(a, self->delay, &(in->value), 1); - =} + reaction(in) -> a {= + // The following copies the char*, not the string. + lf_schedule_copy(a, self->delay, &(in->value), 1); + =} } reactor Test { - input in: string - - reaction(in) {= - printf("Received: %s.\n", in->value); - // Check the time of the input. - interval_t elapsed = lf_time_logical_elapsed(); - printf("After %lld nsec of logical time.\n", elapsed); - if (elapsed != 100000000LL) { - printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); - exit(1); - } - if (strcmp(in->value, "Hello") != 0) { - printf("ERROR: Expected input value to be \"Hello\". It was \"%s\".\n", in->value); - exit(2); - } - =} + input in: string + + reaction(in) {= + printf("Received: %s.\n", in->value); + // Check the time of the input. + interval_t elapsed = lf_time_logical_elapsed(); + printf("After %lld nsec of logical time.\n", elapsed); + if (elapsed != 100000000LL) { + printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); + exit(1); + } + if (strcmp(in->value, "Hello") != 0) { + printf("ERROR: Expected input value to be \"Hello\". It was \"%s\".\n", in->value); + exit(2); + } + =} } main reactor { - d = new DelayString2() - t = new Test() - d.out -> t.in + d = new DelayString2() + t = new Test() + d.out -> t.in - reaction(startup) -> d.in {= lf_set(d.in, "Hello"); =} + reaction(startup) -> d.in {= lf_set(d.in, "Hello"); =} } diff --git a/test/C/src/DelayStruct.lf b/test/C/src/DelayStruct.lf index 0a92171d35..6394ddbc1f 100644 --- a/test/C/src/DelayStruct.lf +++ b/test/C/src/DelayStruct.lf @@ -1,60 +1,60 @@ // Test delaying a struct pointer type. target C { - files: ["include/hello.h"] + files: ["include/hello.h"] } preamble {= - #include "hello.h" - #include + #include "hello.h" + #include =} reactor DelayPointer(delay: time = 100 msec) { - input in: hello_t* - output out: hello_t* - logical action a: hello_t* - - reaction(a) -> out {= - // Using lf_set_token delegates responsibility for - // freeing the allocated memory downstream. - lf_set_token(out, a->token); - =} - - reaction(in) -> a {= - // Schedule the actual token from the input rather than - // a new token with a copy of the input value. - lf_schedule_token(a, self->delay, in->token); - =} + input in: hello_t* + output out: hello_t* + logical action a: hello_t* + + reaction(a) -> out {= + // Using lf_set_token delegates responsibility for + // freeing the allocated memory downstream. + lf_set_token(out, a->token); + =} + + reaction(in) -> a {= + // Schedule the actual token from the input rather than + // a new token with a copy of the input value. + lf_schedule_token(a, self->delay, in->token); + =} } reactor Source { - output out: hello_t* + output out: hello_t* - reaction(startup) -> out {= - // Dynamically allocate an output struct. - SET_NEW(out); + reaction(startup) -> out {= + // Dynamically allocate an output struct. + SET_NEW(out); - // Above allocates a struct, which then must be populated. - out->value->name = "Earth"; - out->value->value = 42; - =} + // Above allocates a struct, which then must be populated. + out->value->name = "Earth"; + out->value->value = 42; + =} } reactor Print(expected: int = 42) { // expected parameter is for testing. - input in: hello_t* - - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); - if (in->value->value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - =} + input in: hello_t* + + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); + if (in->value->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + =} } main reactor DelayStruct { - s = new Source() - d = new DelayPointer() - p = new Print() - s.out -> d.in - d.out -> p.in + s = new Source() + d = new DelayPointer() + p = new Print() + s.out -> d.in + d.out -> p.in } diff --git a/test/C/src/DelayStructWithAfter.lf b/test/C/src/DelayStructWithAfter.lf index 6693a437e6..e3cf5b5b59 100644 --- a/test/C/src/DelayStructWithAfter.lf +++ b/test/C/src/DelayStructWithAfter.lf @@ -1,39 +1,39 @@ // This tests delaying a struct using after. target C { - files: include/hello.h + files: include/hello.h } preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { - output out: hello_t* + output out: hello_t* - reaction(startup) -> out {= - // Dynamically allocate an output struct. - SET_NEW(out); + reaction(startup) -> out {= + // Dynamically allocate an output struct. + SET_NEW(out); - // Above allocates a struct, which then must be populated. - out->value->name = "Earth"; - out->value->value = 42; - =} + // Above allocates a struct, which then must be populated. + out->value->name = "Earth"; + out->value->value = 42; + =} } reactor Print(expected: int = 42) { // expected parameter is for testing. - input in: hello_t* + input in: hello_t* - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); - if (in->value->value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - =} + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); + if (in->value->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + =} } main reactor DelayStructWithAfter { - s = new Source() - p = new Print() - s.out -> p.in after 100 msec + s = new Source() + p = new Print() + s.out -> p.in after 100 msec } diff --git a/test/C/src/DelayStructWithAfterOverlapped.lf b/test/C/src/DelayStructWithAfterOverlapped.lf index 8161022653..d10772a964 100644 --- a/test/C/src/DelayStructWithAfterOverlapped.lf +++ b/test/C/src/DelayStructWithAfterOverlapped.lf @@ -1,53 +1,53 @@ // This tests delaying a struct using after. target C { - timeout: 5 sec, - fast: true, - files: ["include/hello.h"] + timeout: 5 sec, + fast: true, + files: ["include/hello.h"] } preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { - output out: hello_t* - timer t(0, 1 sec) - state s: int = 0 - - reaction(t) -> out {= - self->s++; - // Dynamically allocate an output struct. - SET_NEW(out); - - // Above allocates a struct, which then must be populated. - out->value->name = "Earth"; - out->value->value = 42 * self->s; - =} + output out: hello_t* + timer t(0, 1 sec) + state s: int = 0 + + reaction(t) -> out {= + self->s++; + // Dynamically allocate an output struct. + SET_NEW(out); + + // Above allocates a struct, which then must be populated. + out->value->name = "Earth"; + out->value->value = 42 * self->s; + =} } reactor Print { // expected parameter is for testing. - input in: hello_t* - state s: int = 0 - - reaction(in) {= - self->s++; - printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); - if (in->value->value != 42 * self->s) { - printf("ERROR: Expected value to be %d.\n", 42 * self->s); - exit(1); - } - =} - - reaction(shutdown) {= - if (self->s == 0) { - printf("ERROR: Print received no data.\n"); - exit(2); - } - =} + input in: hello_t* + state s: int = 0 + + reaction(in) {= + self->s++; + printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); + if (in->value->value != 42 * self->s) { + printf("ERROR: Expected value to be %d.\n", 42 * self->s); + exit(1); + } + =} + + reaction(shutdown) {= + if (self->s == 0) { + printf("ERROR: Print received no data.\n"); + exit(2); + } + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p.in after 1500 msec + s = new Source() + p = new Print() + s.out -> p.in after 1500 msec } diff --git a/test/C/src/DelayedAction.lf b/test/C/src/DelayedAction.lf index 28a3e81ac5..ff7ce075f4 100644 --- a/test/C/src/DelayedAction.lf +++ b/test/C/src/DelayedAction.lf @@ -1,25 +1,25 @@ target C { - fast: true, - timeout: 5 sec + fast: true, + timeout: 5 sec } main reactor DelayedAction { - timer t(0, 1 sec) - logical action a - state count: int = 0 + timer t(0, 1 sec) + logical action a + state count: int = 0 - reaction(t) -> a {= lf_schedule(a, MSEC(100)); =} + reaction(t) -> a {= lf_schedule(a, MSEC(100)); =} - reaction(a) {= - interval_t elapsed = lf_time_logical_elapsed(); - interval_t elapsed_physical = lf_time_physical_elapsed(); - printf("Nanoseconds since start: %lld.\n", elapsed); - printf("Physical nanoseconds since start: %lld.\n", elapsed_physical); - interval_t expected = self->count * 1000000000LL + 100000000LL; - self->count++; - if (elapsed != expected) { - printf("Expected %lld but got %lld.\n", expected, elapsed); - exit(1); - } - =} + reaction(a) {= + interval_t elapsed = lf_time_logical_elapsed(); + interval_t elapsed_physical = lf_time_physical_elapsed(); + printf("Nanoseconds since start: %lld.\n", elapsed); + printf("Physical nanoseconds since start: %lld.\n", elapsed_physical); + interval_t expected = self->count * 1000000000LL + 100000000LL; + self->count++; + if (elapsed != expected) { + printf("Expected %lld but got %lld.\n", expected, elapsed); + exit(1); + } + =} } diff --git a/test/C/src/DoubleInvocation.lf b/test/C/src/DoubleInvocation.lf index 973c8b18f6..98c0d51e20 100644 --- a/test/C/src/DoubleInvocation.lf +++ b/test/C/src/DoubleInvocation.lf @@ -1,54 +1,53 @@ -// This illustrates a very strange bug that showed up and has now been fixed. -// This test ensures it does not reappear. At logical time zero, the two Print -// reactors used to be fired twice each at the same logical time. They should -// only be fired once. This behavior was oddly eliminated by either of the -// following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at +// the same logical time. They should only be fired once. This behavior was oddly eliminated by +// either of the following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. // * Sending only position, not velocity from Ball. target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Ball { - output position: int - output velocity: int - state p: int = 200 - timer trigger(0, 1 sec) + output position: int + output velocity: int + state p: int = 200 + timer trigger(0, 1 sec) - reaction(trigger) -> position, velocity {= - lf_set(position, self->p); - lf_set(velocity, -1); - self->p -= 1; - =} + reaction(trigger) -> position, velocity {= + lf_set(position, self->p); + lf_set(velocity, -1); + self->p -= 1; + =} } reactor Print { - input velocity: int - input position: int - state previous: int = -1 + input velocity: int + input position: int + state previous: int = -1 - reaction(startup) {= - printf("####### Print startup\n"); - =} + reaction(startup) {= + printf("####### Print startup\n"); + =} - reaction(position, velocity) {= - if (position->is_present) { - printf("Position: %d.\n", position->value); - } - if (position->value == self->previous) { - printf("ERROR: Multiple firings at the same logical time!\n"); - exit(1); - } - =} + reaction(position, velocity) {= + if (position->is_present) { + printf("Position: %d.\n", position->value); + } + if (position->value == self->previous) { + printf("ERROR: Multiple firings at the same logical time!\n"); + exit(1); + } + =} } main reactor DoubleInvocation { - b1 = new Ball() - p = new Print() - plot = new Print() - b1.position -> p.position - b1.velocity -> p.velocity - b1.position -> plot.position - b1.velocity -> plot.velocity + b1 = new Ball() + p = new Print() + plot = new Print() + b1.position -> p.position + b1.velocity -> p.velocity + b1.position -> plot.position + b1.velocity -> plot.velocity } diff --git a/test/C/src/DoublePort.lf b/test/C/src/DoublePort.lf index c8bf9811f8..545c7fba1f 100644 --- a/test/C/src/DoublePort.lf +++ b/test/C/src/DoublePort.lf @@ -1,50 +1,47 @@ /** - * Test the case where two upstream reactors pass messages to a downstream - * reactor on two different ports. One message carries a microstep delay - * relative to the other. + * Test the case where two upstream reactors pass messages to a downstream reactor on two different + * ports. One message carries a microstep delay relative to the other. * * @author Soroush Bateni */ target C { - timeout: 900 msec, - fast: true + timeout: 900 msec, + fast: true } import Count from "lib/Count.lf" reactor CountMicrostep { - state count: int = 1 - output out: int - logical action act: int - timer t(0, 1 sec) + state count: int = 1 + output out: int + logical action act: int + timer t(0, 1 sec) - reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} + reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} - reaction(act) -> out {= lf_set(out, act->value); =} + reaction(act) -> out {= lf_set(out, act->value); =} } reactor Print { - input in: int - input in2: int - - reaction(in, in2) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("At tag (%lld, %u), received in = %d and in2 = %d.\n", elapsed_time, lf_tag().microstep, in->value, in2->value); - if (in->is_present && in2->is_present) { - fprintf(stderr, "ERROR: invalid logical simultaneity.\n"); - exit(1); - } - =} - - reaction(shutdown) {= - printf("SUCCESS: messages were at least one microstep apart.\n"); - =} + input in: int + input in2: int + + reaction(in, in2) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("At tag (%lld, %u), received in = %d and in2 = %d.\n", elapsed_time, lf_tag().microstep, in->value, in2->value); + if (in->is_present && in2->is_present) { + fprintf(stderr, "ERROR: invalid logical simultaneity.\n"); + exit(1); + } + =} + + reaction(shutdown) {= printf("SUCCESS: messages were at least one microstep apart.\n"); =} } main reactor DoublePort { - c = new Count() - cm = new CountMicrostep() - p = new Print() - c.out -> p.in - cm.out -> p.in2 + c = new Count() + cm = new CountMicrostep() + p = new Print() + c.out -> p.in + cm.out -> p.in2 } diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index 8da6210825..4dd17db7c4 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -1,47 +1,47 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Destination { - input x: int - input w: int - state s: int = 2 + input x: int + input w: int + state s: int = 2 - reaction(x, w) {= - int sum = 0; - if (x->is_present) { - sum += x->value; - } - if (w->is_present) { - sum += w->value; - } - printf("Sum of inputs is: %d\n", sum); - if (sum != self->s) { - printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); - exit(1); - } - self->s += 2; - =} + reaction(x, w) {= + int sum = 0; + if (x->is_present) { + sum += x->value; + } + if (w->is_present) { + sum += w->value; + } + printf("Sum of inputs is: %d\n", sum); + if (sum != self->s) { + printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); + exit(1); + } + self->s += 2; + =} } main reactor DoubleReaction { - c1 = new Clock() - c2 = new Clock() - d = new Destination() - c1.y -> d.x - c2.y -> d.w + c1 = new Clock() + c2 = new Clock() + d = new Destination() + c1.y -> d.x + c2.y -> d.w } diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index 68ad603168..c36eaa0362 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -1,29 +1,28 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice -// at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } main reactor DoubleTrigger { - timer t1 - timer t2 - state s: int = 0 + timer t1 + timer t2 + state s: int = 0 - reaction(t1, t2) {= - self->s++; - if (self->s > 1) { - printf("FAILURE: Reaction got triggered twice.\n"); - exit(1); - } - =} + reaction(t1, t2) {= + self->s++; + if (self->s > 1) { + printf("FAILURE: Reaction got triggered twice.\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (self->s == 1) { - printf("SUCCESS.\n"); - } else { - printf("FAILURE: Reaction was never triggered.\n"); - exit(1); - } - =} + reaction(shutdown) {= + if (self->s == 1) { + printf("SUCCESS.\n"); + } else { + printf("FAILURE: Reaction was never triggered.\n"); + exit(1); + } + =} } diff --git a/test/C/src/FilePkgReader.lf b/test/C/src/FilePkgReader.lf index df2c03ab78..7fdd2d62d2 100644 --- a/test/C/src/FilePkgReader.lf +++ b/test/C/src/FilePkgReader.lf @@ -2,46 +2,46 @@ target C reactor Source { - output out: char* // Use char*, not string, so memory is freed. - - reaction(startup) -> out {= - char* file_path = - LF_PACKAGE_DIRECTORY - LF_FILE_SEPARATOR "src" - LF_FILE_SEPARATOR "lib" - LF_FILE_SEPARATOR "FileReader.txt"; - - FILE* file = fopen(file_path, "rb"); - if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); - - // Determine the file size - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - // Allocate memory for the buffer - char* buffer = (char *) malloc(file_size + 1); - if (buffer == NULL) lf_print_error_and_exit("Out of memory."); - - // Read the file into the buffer - fread(buffer, file_size, 1, file); - buffer[file_size] = '\0'; - fclose(file); - - lf_set(out, buffer); - =} + output out: char* // Use char*, not string, so memory is freed. + + reaction(startup) -> out {= + char* file_path = + LF_PACKAGE_DIRECTORY + LF_FILE_SEPARATOR "src" + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + lf_set(out, buffer); + =} } main reactor { - preamble {= - #include - =} - s = new Source() - - reaction(s.out) {= - printf("Received: %s\n", s.out->value); - if (strcmp("Hello World", s.out->value) != 0) { - lf_print_error_and_exit("Expected 'Hello World'"); - } - =} + preamble {= + #include + =} + s = new Source() + + reaction(s.out) {= + printf("Received: %s\n", s.out->value); + if (strcmp("Hello World", s.out->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} } diff --git a/test/C/src/FileReader.lf b/test/C/src/FileReader.lf index 10be772fb7..4bd093eedf 100644 --- a/test/C/src/FileReader.lf +++ b/test/C/src/FileReader.lf @@ -2,45 +2,45 @@ target C reactor Source { - output out: char* // Use char*, not string, so memory is freed. + output out: char* // Use char*, not string, so memory is freed. - reaction(startup) -> out {= - char* file_path = - LF_SOURCE_DIRECTORY - LF_FILE_SEPARATOR "lib" - LF_FILE_SEPARATOR "FileReader.txt"; + reaction(startup) -> out {= + char* file_path = + LF_SOURCE_DIRECTORY + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; - FILE* file = fopen(file_path, "rb"); - if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); - // Determine the file size - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); - // Allocate memory for the buffer - char* buffer = (char *) malloc(file_size + 1); - if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); - // Read the file into the buffer - fread(buffer, file_size, 1, file); - buffer[file_size] = '\0'; - fclose(file); + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); - lf_set(out, buffer); - =} + lf_set(out, buffer); + =} } main reactor { - preamble {= - #include - =} - s = new Source() - - reaction(s.out) {= - printf("Received: %s\n", s.out->value); - if (strcmp("Hello World", s.out->value) != 0) { - lf_print_error_and_exit("Expected 'Hello World'"); - } - =} + preamble {= + #include + =} + s = new Source() + + reaction(s.out) {= + printf("Received: %s\n", s.out->value); + if (strcmp("Hello World", s.out->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} } diff --git a/test/C/src/FloatLiteral.lf b/test/C/src/FloatLiteral.lf index 576a20d1ac..dd6a39fc95 100644 --- a/test/C/src/FloatLiteral.lf +++ b/test/C/src/FloatLiteral.lf @@ -1,25 +1,24 @@ target C -// This test verifies that floating-point literals are handled correctly. -main reactor { - preamble {= - #include - =} +main reactor { // This test verifies that floating-point literals are handled correctly. + preamble {= + #include + =} - state N: double = 6.0221409e+23 - state charge: double = -1.6021766E-19 - state minus_epsilon: double = -.01e0 - state expected: double = .964853323188E5 + state N: double = 6.0221409e+23 + state charge: double = -1.6021766E-19 + state minus_epsilon: double = -.01e0 + state expected: double = .964853323188E5 - reaction(startup) {= - double F = - self->N * self->charge; - if (fabs(F - self->expected) < fabs(self->minus_epsilon)) { - lf_print("The Faraday constant is roughly %f.", F); - } else { - lf_print_error_and_exit( - "ERROR: Expected %f but computed %f.", - self->expected, F - ); - } - =} + reaction(startup) {= + double F = - self->N * self->charge; + if (fabs(F - self->expected) < fabs(self->minus_epsilon)) { + lf_print("The Faraday constant is roughly %f.", F); + } else { + lf_print_error_and_exit( + "ERROR: Expected %f but computed %f.", + self->expected, F + ); + } + =} } diff --git a/test/C/src/Gain.lf b/test/C/src/Gain.lf index 7cac5eaae6..5df74e2e01 100644 --- a/test/C/src/Gain.lf +++ b/test/C/src/Gain.lf @@ -2,38 +2,38 @@ target C reactor Scale(scale: int = 2) { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= lf_set(y, x->value * self->scale); =} + reaction(x) -> y {= lf_set(y, x->value * self->scale); =} } reactor Test { - input x: int - state received_value: bool = false + input x: int + state received_value: bool = false - reaction(x) {= - printf("Received %d.\n", x->value); - self->received_value = true; - if (x->value != 2) { - printf("ERROR: Expected 2!\n"); - exit(1); - } - =} + reaction(x) {= + printf("Received %d.\n", x->value); + self->received_value = true; + if (x->value != 2) { + printf("ERROR: Expected 2!\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (!self->received_value) { - printf("ERROR: No value received by Test reactor!\n"); - } else { - printf("Test passes.\n"); - } - =} + reaction(shutdown) {= + if (!self->received_value) { + printf("ERROR: No value received by Test reactor!\n"); + } else { + printf("Test passes.\n"); + } + =} } main reactor Gain { - g = new Scale() - d = new Test() - g.y -> d.x + g = new Scale() + d = new Test() + g.y -> d.x - reaction(startup) -> g.x {= lf_set(g.x, 1); =} + reaction(startup) -> g.x {= lf_set(g.x, 1); =} } diff --git a/test/C/src/GetMicroStep.lf b/test/C/src/GetMicroStep.lf index 0a428fd07d..65a60f7174 100644 --- a/test/C/src/GetMicroStep.lf +++ b/test/C/src/GetMicroStep.lf @@ -2,20 +2,20 @@ target C main reactor GetMicroStep { - state s: int = 1 + state s: int = 1 - logical action l + logical action l - reaction(startup) -> l {= lf_schedule(l, 0); =} + reaction(startup) -> l {= lf_schedule(l, 0); =} - reaction(l) -> l {= - microstep_t microstep = lf_tag().microstep; - if (microstep != self->s) { - lf_print_error_and_exit("expected microstep %d, got %d instead.", self->s, microstep); - } - self->s += 1; - if (self->s < 10) { - lf_schedule(l, 0); - } - =} + reaction(l) -> l {= + microstep_t microstep = lf_tag().microstep; + if (microstep != self->s) { + lf_print_error_and_exit("expected microstep %d, got %d instead.", self->s, microstep); + } + self->s += 1; + if (self->s < 10) { + lf_schedule(l, 0); + } + =} } diff --git a/test/C/src/Hello.lf b/test/C/src/Hello.lf index 7784e2f86f..32f822e711 100644 --- a/test/C/src/Hello.lf +++ b/test/C/src/Hello.lf @@ -1,63 +1,56 @@ -// This test checks that logical time is incremented an appropriate amount as a -// result of an invocation of the lf_schedule() function at runtime. It also -// performs various smoke tests of timing aligned reactions. The first instance -// has a period of 4 seconds, the second of 2 seconds, and the third (composite) -// or 1 second. +// This test checks that logical time is incremented an appropriate amount as a result of an +// invocation of the lf_schedule() function at runtime. It also performs various smoke tests of +// timing aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, +// and the third (composite) or 1 second. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } preamble {= - #include + #include =} reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { - state count: int = 0 - state previous_time: time = 0 - timer t(1 sec, period) - logical action a + state count: int = 0 + state previous_time: time = 0 + timer t(1 sec, period) + logical action a - reaction(t) -> a {= - printf("%s\n", self->message); - lf_schedule(a, MSEC(200)); - // Print the current time. - self->previous_time = lf_time_logical(); - time_t secs = self->previous_time/BILLION; - printf("Current time is %lld\n", self->previous_time); - printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); - =} + reaction(t) -> a {= + printf("%s\n", self->message); + lf_schedule(a, MSEC(200)); + // Print the current time. + self->previous_time = lf_time_logical(); + time_t secs = self->previous_time/BILLION; + printf("Current time is %lld\n", self->previous_time); + printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); + =} - reaction(a) {= - (self->count)++; - printf("***** action %d at time %lld\n", self->count, lf_time_logical()); - // Check the a_has_value variable. - if (a->has_value) { - printf("FAILURE: Expected a_has_value to be false, but it was true.\n"); - exit(2); - } - long long time = lf_time_logical(); - if (time - self->previous_time != 200000000ll) { - printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", - time - self->previous_time - ); - exit(1); - } - =} + reaction(a) {= + (self->count)++; + printf("***** action %d at time %lld\n", self->count, lf_time_logical()); + // Check the a_has_value variable. + if (a->has_value) { + printf("FAILURE: Expected a_has_value to be false, but it was true.\n"); + exit(2); + } + long long time = lf_time_logical(); + if (time - self->previous_time != 200000000ll) { + printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", + time - self->previous_time + ); + exit(1); + } + =} } -reactor Inside( - period: time = 1 sec, - message: string = "Composite default message." -) { - third_instance = new Reschedule(period = period, message = message) +reactor Inside(period: time = 1 sec, message: string = "Composite default message.") { + third_instance = new Reschedule(period = period, message = message) } main reactor Hello { - first_instance = new Reschedule( - period = 4 sec, - message = "Hello from first_instance." - ) - second_instance = new Reschedule(message = "Hello from second_instance.") - composite_instance = new Inside(message = "Hello from composite_instance.") + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance.") + second_instance = new Reschedule(message = "Hello from second_instance.") + composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/C/src/HelloWorld.lf b/test/C/src/HelloWorld.lf index 7de913c8ad..07b49b0afd 100644 --- a/test/C/src/HelloWorld.lf +++ b/test/C/src/HelloWorld.lf @@ -1,28 +1,28 @@ target C { - tracing: { // To test generating a custom trace file name. - trace-file-name: "HelloWorldTrace" - }, - logging: error, - build-type: Debug + tracing: { // To test generating a custom trace file name. + trace-file-name: "HelloWorldTrace" + }, + logging: error, + build-type: Debug } reactor HelloWorld2 { - state success: bool = false + state success: bool = false - reaction(startup) {= - printf("Hello World.\n"); - self->success = true; - =} + reaction(startup) {= + printf("Hello World.\n"); + self->success = true; + =} - reaction(shutdown) {= - printf("Shutdown invoked.\n"); - if (!self->success) { - fprintf(stderr, "ERROR: startup reaction not executed.\n"); - exit(1); - } - =} + reaction(shutdown) {= + printf("Shutdown invoked.\n"); + if (!self->success) { + fprintf(stderr, "ERROR: startup reaction not executed.\n"); + exit(1); + } + =} } main reactor HelloWorld { - a = new HelloWorld2() + a = new HelloWorld2() } diff --git a/test/C/src/Hierarchy2.lf b/test/C/src/Hierarchy2.lf index 0a4f20d4bc..daa7b832f8 100644 --- a/test/C/src/Hierarchy2.lf +++ b/test/C/src/Hierarchy2.lf @@ -1,68 +1,68 @@ // Test data transport across hierarchy. target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out: int - timer t(0, 1 sec) + output out: int + timer t(0, 1 sec) - reaction(t) -> out {= lf_set(out, 1); =} + reaction(t) -> out {= lf_set(out, 1); =} } reactor Count { - output out: int - timer t(0, 1 sec) - state i: int = 0 + output out: int + timer t(0, 1 sec) + state i: int = 0 - reaction(t) -> out {= - (self->i)++; - lf_set(out, self->i); - =} + reaction(t) -> out {= + (self->i)++; + lf_set(out, self->i); + =} } reactor Add { - input in1: int - input in2: int - output out: int + input in1: int + input in2: int + output out: int - reaction(in1, in2) -> out {= - int result = 0; - if (in1->is_present) result += in1->value; - if (in2->is_present) result += in2->value; - lf_set(out, result); - =} + reaction(in1, in2) -> out {= + int result = 0; + if (in1->is_present) result += in1->value; + if (in2->is_present) result += in2->value; + lf_set(out, result); + =} } reactor Print { - input in: int - state expected: int = 2 + input in: int + state expected: int = 2 - reaction(in) {= - printf("Received: %d.\n", in->value); - if (in->value != self->expected) { - printf("Expected %d.\n", self->expected); - exit(1); - } - self->expected++; - =} + reaction(in) {= + printf("Received: %d.\n", in->value); + if (in->value != self->expected) { + printf("Expected %d.\n", self->expected); + exit(1); + } + self->expected++; + =} } reactor AddCount { - input in: int - output out: int - count = new Count() - add = new Add() - in -> add.in1 - count.out -> add.in2 - add.out -> out + input in: int + output out: int + count = new Count() + add = new Add() + in -> add.in1 + count.out -> add.in2 + add.out -> out } main reactor Hierarchy2 { - source = new Source() - addCount = new AddCount() - print = new Print() - source.out -> addCount.in - addCount.out -> print.in + source = new Source() + addCount = new AddCount() + print = new Print() + source.out -> addCount.in + addCount.out -> print.in } diff --git a/test/C/src/IdentifierLength.lf b/test/C/src/IdentifierLength.lf index 8fa38b96f0..6e4b34e976 100644 --- a/test/C/src/IdentifierLength.lf +++ b/test/C/src/IdentifierLength.lf @@ -1,42 +1,36 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor A_Really_Long_Name_For_A_Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Another_Really_Long_Name_For_A_Test_Class { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d\n", self->count); + exit(1); + } + =} } main reactor IdentifierLength { - a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source( - - ) - another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class( - - ) - a_really_long_name_for_a_source_instance.y - -> another_really_long_name_for_a_test_instance.x + a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source() + another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class() + a_really_long_name_for_a_source_instance.y -> another_really_long_name_for_a_test_instance.x } diff --git a/test/C/src/ImportComposition.lf b/test/C/src/ImportComposition.lf index 22a1bfef87..c80bf87eab 100644 --- a/test/C/src/ImportComposition.lf +++ b/test/C/src/ImportComposition.lf @@ -1,33 +1,32 @@ -// This tests the ability to import a reactor definition that itself imports a -// reactor definition. +// This tests the ability to import a reactor definition that itself imports a reactor definition. target C import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { - a = new ImportedComposition() - state received: bool = false + a = new ImportedComposition() + state received: bool = false - reaction(startup) -> a.x {= lf_set(a.x, 42); =} + reaction(startup) -> a.x {= lf_set(a.x, 42); =} - reaction(a.y) {= - interval_t receive_time = lf_time_logical_elapsed(); - printf("Received %d at time %lld\n", a.y->value, receive_time); - self->received = true; - if (receive_time != 55000000LL) { - fprintf(stderr, "ERROR: Received time should have been 55,000,000.\n"); - exit(1); - } - if (a.y->value != 42 * 2 * 2) { - fprintf(stderr, "ERROR: Received value should have been %d.\n", 42 * 2 * 2); - exit(2); - } - =} + reaction(a.y) {= + interval_t receive_time = lf_time_logical_elapsed(); + printf("Received %d at time %lld\n", a.y->value, receive_time); + self->received = true; + if (receive_time != 55000000LL) { + fprintf(stderr, "ERROR: Received time should have been 55,000,000.\n"); + exit(1); + } + if (a.y->value != 42 * 2 * 2) { + fprintf(stderr, "ERROR: Received value should have been %d.\n", 42 * 2 * 2); + exit(2); + } + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Nothing received.\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Nothing received.\n"); + exit(3); + } + =} } diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 680ffe2f75..f6a87ef360 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -1,42 +1,41 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - fast: true + fast: true } reactor Source { - logical action foo: int - output y: int + logical action foo: int + output y: int - reaction(foo) -> y {= lf_set(y, foo->value); =} + reaction(foo) -> y {= lf_set(y, foo->value); =} } reactor SourceExtended extends Source { - reaction(startup) -> foo {= lf_schedule_int(foo, 0, 42); =} + reaction(startup) -> foo {= lf_schedule_int(foo, 0, 42); =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != 42) { - fprintf(stderr, "FAILURE: Expected 42\n"); - exit(1); - } - =} + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != 42) { + fprintf(stderr, "FAILURE: Expected 42\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "FAILURE: No data received.\n"); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "FAILURE: No data received.\n"); + } + =} } main reactor { - s = new SourceExtended() - d = new Test() - s.y -> d.x + s = new SourceExtended() + d = new Test() + s.y -> d.x } diff --git a/test/C/src/ManualDelayedReaction.lf b/test/C/src/ManualDelayedReaction.lf index 72c57105ce..61e2519fc3 100644 --- a/test/C/src/ManualDelayedReaction.lf +++ b/test/C/src/ManualDelayedReaction.lf @@ -1,54 +1,52 @@ target C { - // Set keepalive to false since this is a test and schedule is called on a - // physical action from within a reaction. This is one of the special rare - // cases where the user might want to manually override keepalive. - keepalive: false + // Set keepalive to false since this is a test and schedule is called on a physical action from + // within a reaction. This is one of the special rare cases where the user might want to manually + // override keepalive. + keepalive: false } -// That's the stuff that shall be generated for the after -reactor GeneratedDelay { - input y_in: int - output y_out: int - state y_state: int = 0 +reactor GeneratedDelay { // That's the stuff that shall be generated for the after + input y_in: int + output y_out: int + state y_state: int = 0 - physical action act(0 msec) // TODO: delay in act or the schedule call? + physical action act(0 msec) // TODO: delay in act or the schedule call? - reaction(y_in) -> act {= - self->y_state = y_in->value; - lf_schedule(act, MSEC(100)); - =} + reaction(y_in) -> act {= + self->y_state = y_in->value; + lf_schedule(act, MSEC(100)); + =} - reaction(act) -> y_out {= lf_set(y_out, self->y_state); =} + reaction(act) -> y_out {= lf_set(y_out, self->y_state); =} } reactor Source { - output out: int - timer t + output out: int + timer t - // reaction(t) -> out after 100 msec - reaction(t) -> out {= lf_set(out, 1); =} + reaction(t) -> out {= lf_set(out, 1); =} // reaction(t) -> out after 100 msec } reactor Sink { - input in: int - - reaction(in) {= - interval_t elapsed_logical = lf_time_logical_elapsed(); - interval_t logical = lf_time_logical(); - interval_t physical = lf_time_physical(); - printf("Nanoseconds since start: %lld %lld %lld.\n", logical, physical, elapsed_logical); - if (elapsed_logical < MSEC(100)) { - printf("Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); - exit(1); - } - =} deadline(200 msec) {= =} + input in: int + + reaction(in) {= + interval_t elapsed_logical = lf_time_logical_elapsed(); + interval_t logical = lf_time_logical(); + interval_t physical = lf_time_physical(); + printf("Nanoseconds since start: %lld %lld %lld.\n", logical, physical, elapsed_logical); + if (elapsed_logical < MSEC(100)) { + printf("Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); + exit(1); + } + =} deadline(200 msec) {= =} } main reactor ManualDelayedReaction { - source = new Source() - sink = new Sink() - g = new GeneratedDelay() + source = new Source() + sink = new Sink() + g = new GeneratedDelay() - source.out -> g.y_in // source.out -> sink.in; rewritten above - g.y_out -> sink.in + source.out -> g.y_in // source.out -> sink.in; rewritten above + g.y_out -> sink.in } diff --git a/test/C/src/Methods.lf b/test/C/src/Methods.lf index edbdd2f7f6..45bb9fa4ba 100644 --- a/test/C/src/Methods.lf +++ b/test/C/src/Methods.lf @@ -1,23 +1,23 @@ target C main reactor { - state foo: int = 2 + state foo: int = 2 - method getFoo(): int {= return self->foo; =} + method getFoo(): int {= return self->foo; =} - method add(x: int) {= self->foo += x; =} + method add(x: int) {= self->foo += x; =} - reaction(startup) {= - lf_print("Foo is initialized to %d", getFoo()); - if (getFoo() != 2) { - lf_print_error_and_exit("Expected 2!"); - } + reaction(startup) {= + lf_print("Foo is initialized to %d", getFoo()); + if (getFoo() != 2) { + lf_print_error_and_exit("Expected 2!"); + } - add(40); - int a = getFoo(); - lf_print("2 + 40 = %d", a); - if (a != 42) { - lf_print_error_and_exit("Expected 42!"); - } - =} + add(40); + int a = getFoo(); + lf_print("2 + 40 = %d", a); + if (a != 42) { + lf_print_error_and_exit("Expected 42!"); + } + =} } diff --git a/test/C/src/MethodsRecursive.lf b/test/C/src/MethodsRecursive.lf index 5465e0c92c..3f2ec1fd00 100644 --- a/test/C/src/MethodsRecursive.lf +++ b/test/C/src/MethodsRecursive.lf @@ -2,18 +2,18 @@ target C main reactor { - state foo: int = 2 + state foo: int = 2 - method fib(n: int): int {= // Return the n-th Fibonacci number. - if (n <= 1) return 1; - return add(fib(n-1), fib(n-2)); - =} + method fib(n: int): int {= // Return the n-th Fibonacci number. + if (n <= 1) return 1; + return add(fib(n-1), fib(n-2)); + =} - method add(x: int, y: int): int {= return x + y; =} + method add(x: int, y: int): int {= return x + y; =} - reaction(startup) {= - for (int n = 1; n < 10; n++) { - lf_print("%d-th Fibonacci number is %d", n, fib(n)); - } - =} + reaction(startup) {= + for (int n = 1; n < 10; n++) { + lf_print("%d-th Fibonacci number is %d", n, fib(n)); + } + =} } diff --git a/test/C/src/MethodsSameName.lf b/test/C/src/MethodsSameName.lf index b274d153c8..349f62fc55 100644 --- a/test/C/src/MethodsSameName.lf +++ b/test/C/src/MethodsSameName.lf @@ -2,31 +2,31 @@ target C reactor Foo { - state foo: int = 2 + state foo: int = 2 - method add(x: int) {= self->foo += x; =} + method add(x: int) {= self->foo += x; =} - reaction(startup) {= - add(40); - lf_print("Foo: 2 + 40 = %d", self->foo); - if (self->foo != 42) { - lf_print_error_and_exit("Expected 42!"); - } - =} + reaction(startup) {= + add(40); + lf_print("Foo: 2 + 40 = %d", self->foo); + if (self->foo != 42) { + lf_print_error_and_exit("Expected 42!"); + } + =} } main reactor { - state foo: int = 2 + state foo: int = 2 - a = new Foo() + a = new Foo() - method add(x: int) {= self->foo += x; =} + method add(x: int) {= self->foo += x; =} - reaction(startup) {= - add(40); - lf_print("Main: 2 + 40 = %d", self->foo); - if (self->foo != 42) { - lf_print_error_and_exit("Expected 42!"); - } - =} + reaction(startup) {= + add(40); + lf_print("Main: 2 + 40 = %d", self->foo); + if (self->foo != 42) { + lf_print_error_and_exit("Expected 42!"); + } + =} } diff --git a/test/C/src/MovingAverage.lf b/test/C/src/MovingAverage.lf index a8309aa9d3..53e761f61b 100644 --- a/test/C/src/MovingAverage.lf +++ b/test/C/src/MovingAverage.lf @@ -1,53 +1,52 @@ -// Demonstration of a state variable that is an array. The MovingAverage reactor -// computes the moving average of the last four inputs and produces that as -// output. The source is a counting sequence. +// Demonstration of a state variable that is an array. The MovingAverage reactor computes the moving +// average of the last four inputs and produces that as output. The source is a counting sequence. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import TestDouble from "lib/Test.lf" reactor MASource { - output out: double - state count: int = 0 - timer clock(0, 200 msec) - - reaction(clock) -> out {= - lf_set(out, self->count); - self->count++; - =} + output out: double + state count: int = 0 + timer clock(0, 200 msec) + + reaction(clock) -> out {= + lf_set(out, self->count); + self->count++; + =} } reactor MovingAverageImpl { - state delay_line: double[] = {0.0, 0.0, 0.0} - state index: int = 0 - input in: double - output out: double - - reaction(in) -> out {= - // Calculate the output. - double sum = in->value; - for (int i = 0; i < 3; i++) { - sum += self->delay_line[i]; - } - lf_set(out, sum/4.0); - - // Insert the input in the delay line. - self->delay_line[self->index] = in->value; - - // Update the index for the next input. - self->index++; - if (self->index >= 3) { - self->index = 0; - } - =} + state delay_line: double[] = {0.0, 0.0, 0.0} + state index: int = 0 + input in: double + output out: double + + reaction(in) -> out {= + // Calculate the output. + double sum = in->value; + for (int i = 0; i < 3; i++) { + sum += self->delay_line[i]; + } + lf_set(out, sum/4.0); + + // Insert the input in the delay line. + self->delay_line[self->index] = in->value; + + // Update the index for the next input. + self->index++; + if (self->index >= 3) { + self->index = 0; + } + =} } main reactor MovingAverage { - s = new MASource() - m = new MovingAverageImpl() - p = new TestDouble(expected = {0.0, 0.25, 0.75, 1.5, 2.5, 3.5}) - s.out -> m.in - m.out -> p.in + s = new MASource() + m = new MovingAverageImpl() + p = new TestDouble(expected = {0.0, 0.25, 0.75, 1.5, 2.5, 3.5}) + s.out -> m.in + m.out -> p.in } diff --git a/test/C/src/MultipleContained.lf b/test/C/src/MultipleContained.lf index 540052ba87..384543e56f 100644 --- a/test/C/src/MultipleContained.lf +++ b/test/C/src/MultipleContained.lf @@ -1,45 +1,44 @@ -// Test that a reaction can react to and send two multiple ports of a contained -// reactor. +// Test that a reaction can react to and send two multiple ports of a contained reactor. target C reactor Contained { - output trigger: int - input in1: int - input in2: int - state count: int = 0 + output trigger: int + input in1: int + input in2: int + state count: int = 0 - reaction(startup) -> trigger {= lf_set(trigger, 42); =} + reaction(startup) -> trigger {= lf_set(trigger, 42); =} - reaction(in1) {= - printf("in1 received %d.\n", in1->value); - if (in1->value != 42) { - fprintf(stderr, "FAILED: Expected 42.\n"); - exit(1); - } - self->count++; - =} + reaction(in1) {= + printf("in1 received %d.\n", in1->value); + if (in1->value != 42) { + fprintf(stderr, "FAILED: Expected 42.\n"); + exit(1); + } + self->count++; + =} - reaction(in2) {= - printf("in2 received %d.\n", in2->value); - if (in2->value != 42) { - fprintf(stderr, "FAILED: Expected 42.\n"); - exit(1); - } - self->count++; - =} + reaction(in2) {= + printf("in2 received %d.\n", in2->value); + if (in2->value != 42) { + fprintf(stderr, "FAILED: Expected 42.\n"); + exit(1); + } + self->count++; + =} - reaction(shutdown) {= - if (self->count != 2) { - lf_print_error_and_exit("FAILED: Expected two inputs!"); - } - =} + reaction(shutdown) {= + if (self->count != 2) { + lf_print_error_and_exit("FAILED: Expected two inputs!"); + } + =} } main reactor MultipleContained { - c = new Contained() + c = new Contained() - reaction(c.trigger) -> c.in1, c.in2 {= - lf_set(c.in1, c.trigger->value); - lf_set(c.in2, c.trigger->value); - =} + reaction(c.trigger) -> c.in1, c.in2 {= + lf_set(c.in1, c.trigger->value); + lf_set(c.in2, c.trigger->value); + =} } diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index 37b5ddba9f..4682ce8eef 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -1,35 +1,34 @@ -// This test checks for one of the issues arised in the solution of EECS149 Lab -// Chapter 7. In this case, a reactor has two output ports, the first one of -// which is dangling. The generated code should not have any segmentation -// faults. +// This test checks for one of the issues arised in the solution of EECS149 Lab Chapter 7. In this +// case, a reactor has two output ports, the first one of which is dangling. The generated code +// should not have any segmentation faults. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor C { - output x: int - output z: int - timer t(0, 100 msec) + output x: int + output z: int + timer t(0, 100 msec) - reaction(t) -> x, z {= - lf_set(x, 42); - lf_set(z, 44); - =} + reaction(t) -> x, z {= + lf_set(x, 42); + lf_set(z, 44); + =} } main reactor { - c = new C() - state triggered: bool = true + c = new C() + state triggered: bool = true - reaction(c.z) {= - lf_print("c.z = %d", c.z->value); - self->triggered = true; - =} + reaction(c.z) {= + lf_print("c.z = %d", c.z->value); + self->triggered = true; + =} - reaction(shutdown) {= - if (!self->triggered) { - lf_print_error_and_exit("Reaction never triggered.\n"); - } - =} + reaction(shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("Reaction never triggered.\n"); + } + =} } diff --git a/test/C/src/NativeListsAndTimes.lf b/test/C/src/NativeListsAndTimes.lf index a1d09beb6c..fa82f181a1 100644 --- a/test/C/src/NativeListsAndTimes.lf +++ b/test/C/src/NativeListsAndTimes.lf @@ -1,27 +1,26 @@ target C -// This test passes if it is successfully compiled into valid target code. -main reactor( - x: int = 0, - y: time = 0, // Units are missing but not required - z = 1 msec, // Type is missing but not required - p: int[] = {1, 2, 3, 4}, // List of integers - q: interval_t[] = {1 msec, 2 msec, 3 msec}, // list of time values - g: time[] = {1 msec, 2 msec} // List of time values +main reactor( // This test passes if it is successfully compiled into valid target code. + x: int = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required + p: int[] = {1, 2, 3, 4}, // List of integers + q: interval_t[] = {1 msec, 2 msec, 3 msec}, // list of time values + g: time[] = {1 msec, 2 msec} // List of time values ) { - state s: time = y // Reference to explicitly typed time parameter - state t: time = z // Reference to implicitly typed time parameter - state v: bool // Uninitialized boolean state variable - state w: time // Uninitialized time state variable - timer tick(0) // Units missing but not required - timer tock(1 sec) // Implicit type time - timer toe(z) // Implicit type time - state baz = p // Implicit type int[] - state period = z // Implicit type time + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter + state v: bool // Uninitialized boolean state variable + state w: time // Uninitialized time state variable + timer tick(0) // Units missing but not required + timer tock(1 sec) // Implicit type time + timer toe(z) // Implicit type time + state baz = p // Implicit type int[] + state period = z // Implicit type time - state empty_list: int[] + state empty_list: int[] - reaction(tick) {= - // Target code - =} + reaction(tick) {= + // Target code + =} } diff --git a/test/C/src/NestedTriggeredReactions.lf b/test/C/src/NestedTriggeredReactions.lf index df52d36a14..730bc1db08 100644 --- a/test/C/src/NestedTriggeredReactions.lf +++ b/test/C/src/NestedTriggeredReactions.lf @@ -1,39 +1,39 @@ target C reactor Container { - input in: bool + input in: bool - state triggered: bool = false + state triggered: bool = false - contained = new Contained() + contained = new Contained() - in -> contained.in + in -> contained.in - reaction(in) {= self->triggered = true; =} + reaction(in) {= self->triggered = true; =} - reaction(shutdown) {= - if (!self->triggered) { - lf_print_error_and_exit("The Container reaction was not triggered!"); - } - =} + reaction(shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("The Container reaction was not triggered!"); + } + =} } reactor Contained { - input in: bool + input in: bool - state triggered: bool = false + state triggered: bool = false - reaction(in) {= self->triggered = true; =} + reaction(in) {= self->triggered = true; =} - reaction(shutdown) {= - if (!self->triggered) { - lf_print_error_and_exit("The Contained reaction was not triggered!"); - } - =} + reaction(shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("The Contained reaction was not triggered!"); + } + =} } main reactor { - container = new Container() + container = new Container() - reaction(startup) -> container.in {= lf_set(container.in, true); =} + reaction(startup) -> container.in {= lf_set(container.in, true); =} } diff --git a/test/C/src/ParameterHierarchy.lf b/test/C/src/ParameterHierarchy.lf index 825f9f5a60..ef71b43eeb 100644 --- a/test/C/src/ParameterHierarchy.lf +++ b/test/C/src/ParameterHierarchy.lf @@ -2,23 +2,23 @@ target C reactor Deep(p0: int = 0) { - reaction(startup) {= - if (self->p0 != 42) { - lf_print_error_and_exit("Parameter value is %d. Should have been 42.", self->p0); - } else { - lf_print("Success."); - } - =} + reaction(startup) {= + if (self->p0 != 42) { + lf_print_error_and_exit("Parameter value is %d. Should have been 42.", self->p0); + } else { + lf_print("Success."); + } + =} } reactor Intermediate(p1: int = 10) { - a0 = new Deep(p0 = p1) + a0 = new Deep(p0 = p1) } reactor Another(p2: int = 20) { - a1 = new Intermediate(p1 = p2) + a1 = new Intermediate(p1 = p2) } main reactor ParameterHierarchy { - a2 = new Another(p2 = 42) + a2 = new Another(p2 = 42) } diff --git a/test/C/src/ParameterizedState.lf b/test/C/src/ParameterizedState.lf index 3d92345ca9..5b601a740b 100644 --- a/test/C/src/ParameterizedState.lf +++ b/test/C/src/ParameterizedState.lf @@ -1,11 +1,11 @@ target C reactor Foo(bar: int = 42) { - state baz = bar + state baz = bar - reaction(startup) {= printf("Baz: %d\n", self->baz); =} + reaction(startup) {= printf("Baz: %d\n", self->baz); =} } main reactor { - a = new Foo() + a = new Foo() } diff --git a/test/C/src/PeriodicDesugared.lf b/test/C/src/PeriodicDesugared.lf index 46eb97db9c..c31b81e534 100644 --- a/test/C/src/PeriodicDesugared.lf +++ b/test/C/src/PeriodicDesugared.lf @@ -1,23 +1,23 @@ target C { - fast: true, - timeout: 1 sec + fast: true, + timeout: 1 sec } main reactor(offset: time = 0, period: time = 500 msec) { - logical action init(offset) - logical action recur(period) + logical action init(offset) + logical action recur(period) - reaction(startup) -> init, recur {= - if (self->offset == 0) { - printf("Hello World!\n"); - lf_schedule(recur, 0); - } else { - lf_schedule(init, 0); - } - =} - - reaction(init, recur) -> recur {= + reaction(startup) -> init, recur {= + if (self->offset == 0) { printf("Hello World!\n"); lf_schedule(recur, 0); - =} + } else { + lf_schedule(init, 0); + } + =} + + reaction(init, recur) -> recur {= + printf("Hello World!\n"); + lf_schedule(recur, 0); + =} } diff --git a/test/C/src/PhysicalConnection.lf b/test/C/src/PhysicalConnection.lf index 2cac10c240..3276b1e11c 100644 --- a/test/C/src/PhysicalConnection.lf +++ b/test/C/src/PhysicalConnection.lf @@ -2,26 +2,26 @@ target C reactor Source { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} } reactor Destination { - input in: int + input in: int - reaction(in) {= - interval_t time = lf_time_logical_elapsed(); - printf("Received %d at logical time %lld.\n", in->value, time); - if (time <= 0LL) { - fprintf(stderr, "ERROR: Logical time should have been greater than zero.\n"); - exit(1); - } - =} + reaction(in) {= + interval_t time = lf_time_logical_elapsed(); + printf("Received %d at logical time %lld.\n", in->value, time); + if (time <= 0LL) { + fprintf(stderr, "ERROR: Logical time should have been greater than zero.\n"); + exit(1); + } + =} } main reactor PhysicalConnection { - source = new Source() - destination = new Destination() - source.out ~> destination.in + source = new Source() + destination = new Destination() + source.out ~> destination.in } diff --git a/test/C/src/PingPong.lf b/test/C/src/PingPong.lf index 2f1699a51d..c3e0a69357 100644 --- a/test/C/src/PingPong.lf +++ b/test/C/src/PingPong.lf @@ -1,71 +1,68 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * - Unthreaded: 97 msec * - Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ target C { - fast: true + fast: true } reactor Ping(count: int = 10) { - input receive: int - output send: int - state pingsLeft: int = count - logical action serve + input receive: int + output send: int + state pingsLeft: int = count + logical action serve - reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} + reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} - reaction(receive) -> serve {= - if (self->pingsLeft > 0) { - lf_schedule(serve, 0); - } else { - lf_request_stop(); - } - =} + reaction(receive) -> serve {= + if (self->pingsLeft > 0) { + lf_schedule(serve, 0); + } else { + lf_request_stop(); + } + =} } reactor Pong(expected: int = 10) { - input receive: int - output send: int - state count: int = 0 + input receive: int + output send: int + state count: int = 0 - reaction(receive) -> send {= - self->count++; - lf_set(send, receive->value); - =} + reaction(receive) -> send {= + self->count++; + lf_set(send, receive->value); + =} - reaction(shutdown) {= - if (self->count != self->expected) { - fprintf(stderr, "ERROR: Pong expected to receive %d inputs, but it received %d.\n", - self->expected, self->count - ); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->count != self->expected) { + fprintf(stderr, "ERROR: Pong expected to receive %d inputs, but it received %d.\n", + self->expected, self->count + ); + exit(1); + } + printf("Success.\n"); + =} } main reactor PingPong { - ping = new Ping() - pong = new Pong() - ping.send -> pong.receive - pong.send -> ping.receive + ping = new Ping() + pong = new Pong() + ping.send -> pong.receive + pong.send -> ping.receive } diff --git a/test/C/src/PreambleFileLevel.lf b/test/C/src/PreambleFileLevel.lf index ed2def967a..e9ea7b33b9 100644 --- a/test/C/src/PreambleFileLevel.lf +++ b/test/C/src/PreambleFileLevel.lf @@ -1,7 +1,4 @@ -/** - * Test for ensuring that file-level preambles are inherited when a file is - * imported. - */ +/** Test for ensuring that file-level preambles are inherited when a file is imported. */ target C import FileLevelPreamble from "lib/FileLevelPreamble.lf" @@ -10,5 +7,5 @@ reactor B extends FileLevelPreamble { } main reactor { - b = new B() + b = new B() } diff --git a/test/C/src/PreambleInherited.lf b/test/C/src/PreambleInherited.lf index c7db161962..83f4a59d44 100644 --- a/test/C/src/PreambleInherited.lf +++ b/test/C/src/PreambleInherited.lf @@ -2,16 +2,16 @@ target C reactor A { - preamble {= - #define FOO 2 - =} + preamble {= + #define FOO 2 + =} - reaction(startup) {= printf("FOO: %d\n", FOO); =} + reaction(startup) {= printf("FOO: %d\n", FOO); =} } reactor B extends A { } main reactor { - b = new B() + b = new B() } diff --git a/test/C/src/ReadOutputOfContainedReactor.lf b/test/C/src/ReadOutputOfContainedReactor.lf index ce2129069b..eb8dba11bf 100644 --- a/test/C/src/ReadOutputOfContainedReactor.lf +++ b/test/C/src/ReadOutputOfContainedReactor.lf @@ -1,50 +1,49 @@ -// Test reacting to and reading outputs from a contained reactor in various -// permutations. +// Test reacting to and reading outputs from a contained reactor in various permutations. target C reactor Contained { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} } main reactor ReadOutputOfContainedReactor { - c = new Contained() - state count: int = 0 + c = new Contained() + state count: int = 0 - reaction(startup) c.out {= - printf("Startup reaction reading output of contained reactor: %d.\n", c.out->value); - if (c.out->value != 42) { - fprintf(stderr, "Expected 42!\n"); - exit(2); - } - self->count++; - =} + reaction(startup) c.out {= + printf("Startup reaction reading output of contained reactor: %d.\n", c.out->value); + if (c.out->value != 42) { + fprintf(stderr, "Expected 42!\n"); + exit(2); + } + self->count++; + =} - reaction(c.out) {= - printf("Reading output of contained reactor: %d.\n", c.out->value); - if (c.out->value != 42) { - fprintf(stderr, "Expected 42!\n"); - exit(3); - } - self->count++; - =} + reaction(c.out) {= + printf("Reading output of contained reactor: %d.\n", c.out->value); + if (c.out->value != 42) { + fprintf(stderr, "Expected 42!\n"); + exit(3); + } + self->count++; + =} - reaction(startup, c.out) {= - printf("Alternate triggering reading output of contained reactor: %d.\n", c.out->value); - if (c.out->value != 42) { - fprintf(stderr, "Expected 42!\n"); - exit(4); - } - self->count++; - =} + reaction(startup, c.out) {= + printf("Alternate triggering reading output of contained reactor: %d.\n", c.out->value); + if (c.out->value != 42) { + fprintf(stderr, "Expected 42!\n"); + exit(4); + } + self->count++; + =} - reaction(shutdown) {= - if (self->count != 3) { - printf("FAILURE: One of the reactions failed to trigger.\n"); - exit(1); - } else { - printf("Test passes.\n"); - } - =} + reaction(shutdown) {= + if (self->count != 3) { + printf("FAILURE: One of the reactions failed to trigger.\n"); + exit(1); + } else { + printf("Test passes.\n"); + } + =} } diff --git a/test/C/src/RequestStop.lf b/test/C/src/RequestStop.lf index 83c59d1d27..07e6806f72 100644 --- a/test/C/src/RequestStop.lf +++ b/test/C/src/RequestStop.lf @@ -1,13 +1,12 @@ -// Test verifying that lf_request_stop() called in a shutdown reaction is -// ignored. +// Test verifying that lf_request_stop() called in a shutdown reaction is ignored. target C main reactor { - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - lf_print("Shutdown invoked at tag (%lld, %d). Calling lf_request_stop(), which should have no effect.", - current_tag.time - lf_time_start(), current_tag.microstep - ); - lf_request_stop(); - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + lf_print("Shutdown invoked at tag (%lld, %d). Calling lf_request_stop(), which should have no effect.", + current_tag.time - lf_time_start(), current_tag.microstep + ); + lf_request_stop(); + =} } diff --git a/test/C/src/ScheduleLogicalAction.lf b/test/C/src/ScheduleLogicalAction.lf index 762f8c6f52..4a301977a3 100644 --- a/test/C/src/ScheduleLogicalAction.lf +++ b/test/C/src/ScheduleLogicalAction.lf @@ -1,46 +1,46 @@ -// This checks that a logical action is scheduled the specified logical time -// after the current logical time. +// This checks that a logical action is scheduled the specified logical time after the current +// logical time. target C { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x: int - output y: int - logical action a: int* + input x: int + output y: int + logical action a: int* - reaction(x) -> y, a {= - lf_set(y, 2*x->value); - // The following uses physical time, incorrectly. - lf_schedule(a, MSEC(500)); - =} + reaction(x) -> y, a {= + lf_set(y, 2*x->value); + // The following uses physical time, incorrectly. + lf_schedule(a, MSEC(500)); + =} - reaction(a) -> y {= lf_set(y, -42); =} + reaction(a) -> y {= lf_set(y, -42); =} } reactor print { - state expected_time: time = 0 - input x: int + state expected_time: time = 0 + input x: int - reaction(x) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("Result is %d\n", x->value); - printf("Current logical time is: %lld\n", elapsed_time); - printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); - if (elapsed_time != self->expected_time) { - printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); - exit(1); - } - self->expected_time += MSEC(500); - =} + reaction(x) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("Result is %d\n", x->value); + printf("Current logical time is: %lld\n", elapsed_time); + printf("Current physical time is: %lld\n", lf_time_physical_elapsed()); + if (elapsed_time != self->expected_time) { + printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); + exit(1); + } + self->expected_time += MSEC(500); + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x - reaction(t) -> f.x {= lf_set(f.x, 42); =} + reaction(t) -> f.x {= lf_set(f.x, 42); =} } diff --git a/test/C/src/ScheduleValue.lf b/test/C/src/ScheduleValue.lf index 2ef4333db8..05532c145f 100644 --- a/test/C/src/ScheduleValue.lf +++ b/test/C/src/ScheduleValue.lf @@ -4,14 +4,14 @@ target C { } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include - #include - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include + #include + #ifdef __cplusplus + } + #endif =} main reactor ScheduleValue { diff --git a/test/C/src/SelfLoop.lf b/test/C/src/SelfLoop.lf index 855be46792..cf200024ce 100644 --- a/test/C/src/SelfLoop.lf +++ b/test/C/src/SelfLoop.lf @@ -1,40 +1,40 @@ target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Self { - input x: int - output y: int - logical action a: int - state expected: int = 43 + input x: int + output y: int + logical action a: int + state expected: int = 43 - reaction(a) -> y {= - printf("a = %d\n", a->value); - lf_set(y, a->value + 1); - =} + reaction(a) -> y {= + printf("a = %d\n", a->value); + lf_set(y, a->value + 1); + =} - reaction(x) -> a {= - printf("x = %d\n", x->value); - if (x->value != self->expected) { - fprintf(stderr, "Expected %d.\n", self->expected); - exit(1); - } - self->expected++; - lf_schedule_int(a, MSEC(100), x->value); - =} + reaction(x) -> a {= + printf("x = %d\n", x->value); + if (x->value != self->expected) { + fprintf(stderr, "Expected %d.\n", self->expected); + exit(1); + } + self->expected++; + lf_schedule_int(a, MSEC(100), x->value); + =} - reaction(startup) -> a {= lf_schedule_int(a, 0, 42); =} + reaction(startup) -> a {= lf_schedule_int(a, 0, 42); =} - reaction(shutdown) {= - if (self->expected <= 43) { - fprintf(stderr, "Received no data.\n"); - exit(2); - } - =} + reaction(shutdown) {= + if (self->expected <= 43) { + fprintf(stderr, "Received no data.\n"); + exit(2); + } + =} } main reactor SelfLoop { - u = new Self() - u.y -> u.x + u = new Self() + u.y -> u.x } diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index b1e8f25f93..5371e8892a 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -1,31 +1,31 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Printer { - input x: int - state count: int = 1 + input x: int + state count: int = 1 - reaction(x) {= - printf("Inside reactor received: %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d.\n", self->count); - exit(1); - } - self->count++; - =} + reaction(x) {= + printf("Inside reactor received: %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d.\n", self->count); + exit(1); + } + self->count++; + =} } main reactor SendingInside { - state count: int = 0 - timer t(0, 1 sec) - p = new Printer() + state count: int = 0 + timer t(0, 1 sec) + p = new Printer() - reaction(t) -> p.x {= - (self->count)++; - lf_set(p.x, self->count); - =} + reaction(t) -> p.x {= + (self->count)++; + lf_set(p.x, self->count); + =} } diff --git a/test/C/src/SendsPointerTest.lf b/test/C/src/SendsPointerTest.lf index 1f17bd1388..0ec366cadb 100644 --- a/test/C/src/SendsPointerTest.lf +++ b/test/C/src/SendsPointerTest.lf @@ -1,32 +1,32 @@ -// Source produces a dynamically allocated struct, which it passes to Print. -// Reference counting ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. Reference counting +// ensures that the struct is freed. target C preamble {= typedef int* int_pointer; =} reactor SendsPointer { - output out: int_pointer + output out: int_pointer - reaction(startup) -> out {= - static int my_constant = 42; - lf_set(out, &my_constant); - =} + reaction(startup) -> out {= + static int my_constant = 42; + lf_set(out, &my_constant); + =} } reactor Print(expected: int = 42) { // expected parameter is for testing. - input in: int_pointer + input in: int_pointer - reaction(in) {= - printf("Received: %d\n", *in->value); - if (*in->value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - =} + reaction(in) {= + printf("Received: %d\n", *in->value); + if (*in->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + =} } main reactor SendsPointerTest { - s = new SendsPointer() - p = new Print() - s.out -> p.in + s = new SendsPointer() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/SetArray.lf b/test/C/src/SetArray.lf index f30457f9f8..72c2e938de 100644 --- a/test/C/src/SetArray.lf +++ b/test/C/src/SetArray.lf @@ -1,48 +1,48 @@ -// This tests SET_ARRAY() This tests the use of the "polymorphic" delay reactor -// on a struct. It delays by a logical time any pointer datatype. +// This tests SET_ARRAY() This tests the use of the "polymorphic" delay reactor on a struct. It +// delays by a logical time any pointer datatype. target C reactor Source { - output out: int[] + output out: int[] - reaction(startup) -> out {= - // Dynamically allocate an output array of length 3. - int* array = (int*)malloc(3 * sizeof(int)); - SET_ARRAY(out, array, sizeof(int), 3); + reaction(startup) -> out {= + // Dynamically allocate an output array of length 3. + int* array = (int*)malloc(3 * sizeof(int)); + SET_ARRAY(out, array, sizeof(int), 3); - // Above allocates the array, which then must be populated. - out->value[0] = 0; - out->value[1] = 1; - out->value[2] = 2; - =} + // Above allocates the array, which then must be populated. + out->value[0] = 0; + out->value[1] = 1; + out->value[2] = 2; + =} } reactor Print(scale: int = 1) { // The scale parameter is just for testing. - input in: int[] + input in: int[] - reaction(in) {= - int count = 0; // For testing. - bool failed = false; // For testing. - printf("Received: ["); - for (int i = 0; i < in->length; i++) { - if (i > 0) printf(", "); - printf("%d", in->value[i]); - // For testing, check whether values match expectation. - if (in->value[i] != self->scale * count) { - failed = true; - } - count++; // For testing. + reaction(in) {= + int count = 0; // For testing. + bool failed = false; // For testing. + printf("Received: ["); + for (int i = 0; i < in->length; i++) { + if (i > 0) printf(", "); + printf("%d", in->value[i]); + // For testing, check whether values match expectation. + if (in->value[i] != self->scale * count) { + failed = true; } - printf("]\n"); - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); - } - =} + count++; // For testing. + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/SetToken.lf b/test/C/src/SetToken.lf index b9af4bff20..3ac1958b83 100644 --- a/test/C/src/SetToken.lf +++ b/test/C/src/SetToken.lf @@ -2,28 +2,28 @@ target C reactor Source { - output out: int* - logical action a: int + output out: int* + logical action a: int - reaction(startup) -> a {= lf_schedule_int(a, MSEC(200), 42); =} + reaction(startup) -> a {= lf_schedule_int(a, MSEC(200), 42); =} - reaction(a) -> out {= lf_set_token(out, a->token); =} + reaction(a) -> out {= lf_set_token(out, a->token); =} } reactor Print(expected: int = 42) { // expected parameter is for testing. - input in: int* + input in: int* - reaction(in) {= - printf("Received %d\n", *(in->value)); - if (*(in->value) != 42) { - printf("ERROR: Expected value to be 42.\n"); - exit(1); - } - =} + reaction(in) {= + printf("Received %d\n", *(in->value)); + if (*(in->value) != 42) { + printf("ERROR: Expected value to be 42.\n"); + exit(1); + } + =} } main reactor SetToken { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index fba3e03cbc..6ae30cfb45 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -1,50 +1,49 @@ -// Test local deadline, where a deadline is associated with a reaction -// definition. This test triggers a reaction exactly once with a deadline -// violation. +// Test local deadline, where a deadline is associated with a reaction definition. This test +// triggers a reaction exactly once with a deadline violation. target C preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} reactor Deadline(threshold: time = 100 msec) { - input x: int - output deadlineViolation: bool + input x: int + output deadlineViolation: bool - reaction(x) -> deadlineViolation {= - printf("ERROR: Deadline violation was not detected!\n"); - exit(1); - =} deadline(threshold) {= - printf("Deadline violation detected.\n"); - lf_set(deadlineViolation, true); - =} + reaction(x) -> deadlineViolation {= + printf("ERROR: Deadline violation was not detected!\n"); + exit(1); + =} deadline(threshold) {= + printf("Deadline violation detected.\n"); + lf_set(deadlineViolation, true); + =} } reactor Print { - input in: bool + input in: bool - reaction(in) {= - if (in) { - printf("Output successfully produced by deadline handler.\n"); - } - =} + reaction(in) {= + if (in) { + printf("Output successfully produced by deadline handler.\n"); + } + =} } main reactor SimpleDeadline { - timer start - d = new Deadline(threshold = 10 msec) - p = new Print() - d.deadlineViolation -> p.in + timer start + d = new Deadline(threshold = 10 msec) + p = new Print() + d.deadlineViolation -> p.in - reaction(start) -> d.x {= - instant_t sleep_time_ns = 20000000; - lf_sleep(sleep_time_ns); - lf_set(d.x, 42); - =} + reaction(start) -> d.x {= + instant_t sleep_time_ns = 20000000; + lf_sleep(sleep_time_ns); + lf_set(d.x, 42); + =} } diff --git a/test/C/src/SlowingClock.lf b/test/C/src/SlowingClock.lf index d4a1e1d5f4..c7ba2266fc 100644 --- a/test/C/src/SlowingClock.lf +++ b/test/C/src/SlowingClock.lf @@ -1,44 +1,43 @@ /** - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a logical action with a minimum delay of 100 msec. The use of the - * logical action ensures the elapsed time jumps exactly from 0 to 100, 300, - * 600, and 1000 msec. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a logical + * action with a minimum delay of 100 msec. The use of the logical action ensures the elapsed time + * jumps exactly from 0 to 100, 300, 600, and 1000 msec. */ target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } main reactor SlowingClock { - logical action a(100 msec) - state interval: time = 100 msec - state expected_time: time = 100 msec + logical action a(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec - reaction(startup) -> a {= lf_schedule(a, 0); =} + reaction(startup) -> a {= lf_schedule(a, 0); =} - reaction(a) -> a {= - instant_t elapsed_logical_time = lf_time_logical_elapsed(); - printf("Logical time since start: \%lld nsec.\n", - elapsed_logical_time + reaction(a) -> a {= + instant_t elapsed_logical_time = lf_time_logical_elapsed(); + printf("Logical time since start: \%lld nsec.\n", + elapsed_logical_time + ); + if (elapsed_logical_time != self->expected_time) { + printf("ERROR: Expected time to be: \%lld nsec.\n", + self->expected_time ); - if (elapsed_logical_time != self->expected_time) { - printf("ERROR: Expected time to be: \%lld nsec.\n", - self->expected_time - ); - exit(1); - } - lf_schedule(a, self->interval); - self->expected_time += MSEC(100) + self->interval; - self->interval += MSEC(100); - =} + exit(1); + } + lf_schedule(a, self->interval); + self->expected_time += MSEC(100) + self->interval; + self->interval += MSEC(100); + =} - reaction(shutdown) {= - if (self->expected_time != MSEC(1500)) { - printf("ERROR: Expected the next expected time to be: 1500000000 nsec.\n"); - printf("It was: \%lld nsec.\n", self->expected_time); - exit(2); - } else { - printf("Test passes.\n"); - } - =} + reaction(shutdown) {= + if (self->expected_time != MSEC(1500)) { + printf("ERROR: Expected the next expected time to be: 1500000000 nsec.\n"); + printf("It was: \%lld nsec.\n", self->expected_time); + exit(2); + } else { + printf("Test passes.\n"); + } + =} } diff --git a/test/C/src/SlowingClockPhysical.lf b/test/C/src/SlowingClockPhysical.lf index 0e82730112..9ec8d48ef9 100644 --- a/test/C/src/SlowingClockPhysical.lf +++ b/test/C/src/SlowingClockPhysical.lf @@ -1,46 +1,45 @@ /** - * /* Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a physical action with a minimum delay of 100 msec. The use of the - * physical action makes the elapsed time jumps from 0 to approximately 100 - * msec, to approximatly 300 msec thereafter, drifting away further with each - * new event. + * /* Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a physical + * action with a minimum delay of 100 msec. The use of the physical action makes the elapsed time + * jumps from 0 to approximately 100 msec, to approximatly 300 msec thereafter, drifting away + * further with each new event. */ target C { - timeout: 1500 msec + timeout: 1500 msec } main reactor SlowingClockPhysical { - physical action a(100 msec) - state interval: time = 100 msec - state expected_time: time = 100 msec + physical action a(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec - reaction(startup) -> a {= - self->expected_time = MSEC(100); - lf_schedule(a, 0); - =} + reaction(startup) -> a {= + self->expected_time = MSEC(100); + lf_schedule(a, 0); + =} - reaction(a) -> a {= - instant_t elapsed_logical_time = lf_time_logical_elapsed(); - printf("Logical time since start: \%lld nsec.\n", - elapsed_logical_time + reaction(a) -> a {= + instant_t elapsed_logical_time = lf_time_logical_elapsed(); + printf("Logical time since start: \%lld nsec.\n", + elapsed_logical_time + ); + if (elapsed_logical_time < self->expected_time) { + printf("ERROR: Expected logical time to be at least: \%lld nsec.\n", + self->expected_time ); - if (elapsed_logical_time < self->expected_time) { - printf("ERROR: Expected logical time to be at least: \%lld nsec.\n", - self->expected_time - ); - exit(1); - } - self->interval += MSEC(100); - self->expected_time = MSEC(100) + self->interval; - lf_schedule(a, self->interval); - printf("Scheduling next to occur approximately after: \%lld nsec.\n", self->interval); - =} + exit(1); + } + self->interval += MSEC(100); + self->expected_time = MSEC(100) + self->interval; + lf_schedule(a, self->interval); + printf("Scheduling next to occur approximately after: \%lld nsec.\n", self->interval); + =} - reaction(shutdown) {= - if (self->expected_time < MSEC(500)) { - printf("ERROR: Expected the next expected time to be at least: 500000000 nsec.\n"); - printf("It was: \%lld nsec.\n", self->expected_time); - exit(2); - } - =} + reaction(shutdown) {= + if (self->expected_time < MSEC(500)) { + printf("ERROR: Expected the next expected time to be at least: 500000000 nsec.\n"); + printf("It was: \%lld nsec.\n", self->expected_time); + exit(2); + } + =} } diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index 8f4c1423a5..da56c2d4f7 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -1,68 +1,68 @@ /** - * Test that the starvation functionality in absence of the "keepalive: true" - * target property indeed works as expected. + * Test that the starvation functionality in absence of the "keepalive: true" target property indeed + * works as expected. * * @author Soroush Bateni */ target C reactor SuperDenseSender(number_of_iterations: int = 10) { - logical action loop - output out: int - state iterator: int = 0 + logical action loop + output out: int + state iterator: int = 0 - reaction(startup, loop) -> out {= - if (self->iterator < self->number_of_iterations) { - lf_schedule(loop, 0); - } - self->iterator++; - lf_set(out, 42); - =} + reaction(startup, loop) -> out {= + if (self->iterator < self->number_of_iterations) { + lf_schedule(loop, 0); + } + self->iterator++; + lf_set(out, 42); + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == lf_time_start() - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Sender successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - lf_time_start(), - current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == lf_time_start() + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Sender successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - lf_time_start(), + current_tag.microstep); + exit(1); + } + =} } reactor SuperDenseReceiver(number_of_iterations: int = 10) { - input in: int + input in: int - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("Received %d at tag (%lld, %u).\n", - in->value, - current_tag.time - lf_time_start(), - current_tag.microstep); - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("Received %d at tag (%lld, %u).\n", + in->value, + current_tag.time - lf_time_start(), + current_tag.microstep); + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == lf_time_start() - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Receiver successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - lf_time_start(), - current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == lf_time_start() + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Receiver successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - lf_time_start(), + current_tag.microstep); + exit(1); + } + =} } main reactor Starvation { - sender = new SuperDenseSender() - receiver = new SuperDenseReceiver() + sender = new SuperDenseSender() + receiver = new SuperDenseReceiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/Stop.lf b/test/C/src/Stop.lf index 1731bced42..a9586ecee7 100644 --- a/test/C/src/Stop.lf +++ b/test/C/src/Stop.lf @@ -4,59 +4,59 @@ * @author Soroush Bateni */ target C { - timeout: 11 msec + timeout: 11 msec } import Sender from "lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state reaction_invoked_correctly: bool = false + input in: int + state reaction_invoked_correctly: bool = false - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - // The reaction should not have been called at tags larger than (10 msec, 9) - fprintf(stderr, "ERROR: Invoked reaction(in) at tag bigger than shutdown.\n"); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { - // Call lf_request_stop() at relative tag (10 msec, 8) - printf("Requesting stop.\n"); - lf_request_stop(); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { - // Check that this reaction is indeed also triggered at (10 msec, 9) - self->reaction_invoked_correctly = true; - } - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + // The reaction should not have been called at tags larger than (10 msec, 9) + fprintf(stderr, "ERROR: Invoked reaction(in) at tag bigger than shutdown.\n"); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { + // Call lf_request_stop() at relative tag (10 msec, 8) + printf("Requesting stop.\n"); + lf_request_stop(); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { + // Check that this reaction is indeed also triggered at (10 msec, 9) + self->reaction_invoked_correctly = true; + } + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - // Check to see if shutdown is called at relative tag (10 msec, 9) - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && - self->reaction_invoked_correctly == true) { - printf("SUCCESS: successfully enforced stop.\n"); - } else if(lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } else if (self->reaction_invoked_correctly == false) { - // Check to see if reactions were called correctly - fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + // Check to see if shutdown is called at relative tag (10 msec, 9) + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && + self->reaction_invoked_correctly == true) { + printf("SUCCESS: successfully enforced stop.\n"); + } else if(lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } else if (self->reaction_invoked_correctly == false) { + // Check to see if reactions were called correctly + fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } + =} } main reactor { - consumer = new Consumer() - producer = new Sender(break_interval = 1 msec) + consumer = new Consumer() + producer = new Sender(break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index e845c6de48..ad22467a89 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -1,106 +1,106 @@ /** - * Test for lf_request_stop() at tag (0,0). This also tests for logically - * simultaneous calls to lf_request_stop(). + * Test for lf_request_stop() at tag (0,0). This also tests for logically simultaneous calls to + * lf_request_stop(). * * @author Soroush Bateni */ target C reactor Sender { - output out: int - state reaction_invoked_correctly: bool = false - timer t(0, 1 usec) - logical action act + output out: int + state reaction_invoked_correctly: bool = false + timer t(0, 1 usec) + logical action act - reaction(t) -> out, act {= - printf("Sending 42 at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - lf_schedule(act, 0); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } else if (lf_tag_compare(lf_tag(), one) > 0) { - fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - =} + reaction(t) -> out, act {= + printf("Sending 42 at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + lf_schedule(act, 0); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } else if (lf_tag_compare(lf_tag(), one) > 0) { + fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + =} - reaction(act) {= - // Reaction should be invoked at (0,1) - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), one) == 0) { - self->reaction_invoked_correctly = true; - } - =} + reaction(act) {= + // Reaction should be invoked at (0,1) + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), one) == 0) { + self->reaction_invoked_correctly = true; + } + =} - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Sender failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } else if (self->reaction_invoked_correctly == false) { - fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Sender failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } else if (self->reaction_invoked_correctly == false) { + fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } reactor Receiver { - input in: int + input in: int - reaction(in) {= - printf("Received %d at (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} + reaction(in) {= + printf("Received %d at (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} - reaction(shutdown) {= - // Shutdown events must occur at (0, 1) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + // Shutdown events must occur at (0, 1) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } main reactor StopZero { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/Stride.lf b/test/C/src/Stride.lf index 62b9077878..c4016d5059 100644 --- a/test/C/src/Stride.lf +++ b/test/C/src/Stride.lf @@ -1,36 +1,36 @@ -// This example illustrates state variables and parameters on the wiki. For this -// test, success is just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this test, success is +// just compiling and running. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Count(stride: int = 1) { - state count: int = 1 - output y: int - timer t(0, 100 msec) + state count: int = 1 + output y: int + timer t(0, 100 msec) - reaction(t) -> y {= - lf_set(y, self->count); - self->count += self->stride; - =} + reaction(t) -> y {= + lf_set(y, self->count); + self->count += self->stride; + =} } reactor Display { - input x: int - state expected: int = 1 // for testing. + input x: int + state expected: int = 1 // for testing. - reaction(x) {= - printf("Received: %d.\n", x->value); - if (x->value != self->expected) { - fprintf(stderr, "ERROR: Expected %d\n", self->expected); - } - self->expected += 2; - =} + reaction(x) {= + printf("Received: %d.\n", x->value); + if (x->value != self->expected) { + fprintf(stderr, "ERROR: Expected %d\n", self->expected); + } + self->expected += 2; + =} } main reactor Stride { - c = new Count(stride = 2) - d = new Display() - c.y -> d.x + c = new Count(stride = 2) + d = new Display() + c.y -> d.x } diff --git a/test/C/src/StructAsState.lf b/test/C/src/StructAsState.lf index 119762c14c..c26429e1a7 100644 --- a/test/C/src/StructAsState.lf +++ b/test/C/src/StructAsState.lf @@ -1,23 +1,21 @@ -// Check that a state variable can have a statically initialized struct as a -// value. +// Check that a state variable can have a statically initialized struct as a value. target C preamble {= - typedef struct hello_t { - char* name; - int value; - } hello_t; + typedef struct hello_t { + char* name; + int value; + } hello_t; =} main reactor StructAsState { - // Notice that target code delimiters are no longer necessary. - state s: hello_t = {"Earth", 42} + state s: hello_t = {"Earth", 42} // Notice that target code delimiters are no longer necessary. - reaction(startup) {= - printf("State s.name=\"%s\", value=%d.\n", self->s.name, self->s.value); - if (self->s.value != 42) { - fprintf(stderr, "FAILED: Expected 42.\n"); - exit(1); - } - =} + reaction(startup) {= + printf("State s.name=\"%s\", value=%d.\n", self->s.name, self->s.value); + if (self->s.value != 42) { + fprintf(stderr, "FAILED: Expected 42.\n"); + exit(1); + } + =} } diff --git a/test/C/src/StructAsType.lf b/test/C/src/StructAsType.lf index 8674685530..eded331cb9 100644 --- a/test/C/src/StructAsType.lf +++ b/test/C/src/StructAsType.lf @@ -1,42 +1,42 @@ // Source produces a struct directly, rather than a pointer to a struct. target C { - files: include/hello.h + files: include/hello.h } preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { - output out: hello_t + output out: hello_t - reaction(startup) -> out {= - // Create the struct on the stack and then copy - // it to the output as follows: - struct hello_t temp = {"Earth", 42}; - lf_set(out, temp); - // Alternatively, you can anonymously create the struct, but in this case, - // parentheses around the second argument to lf_set() are needed because - // lf_set() is a macro and it will get confused by the comma in the argument - // and think that three arguments are being provided. - // lf_set(out, ((hello_t){"Earth", 42})); - =} + reaction(startup) -> out {= + // Create the struct on the stack and then copy + // it to the output as follows: + struct hello_t temp = {"Earth", 42}; + lf_set(out, temp); + // Alternatively, you can anonymously create the struct, but in this case, + // parentheses around the second argument to lf_set() are needed because + // lf_set() is a macro and it will get confused by the comma in the argument + // and think that three arguments are being provided. + // lf_set(out, ((hello_t){"Earth", 42})); + =} } reactor Print(expected: int = 42) { // expected parameter is for testing. - input in: hello_t + input in: hello_t - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value.name, in->value.value); - if (in->value.value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - =} + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value.name, in->value.value); + if (in->value.value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + =} } main reactor StructAsType { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/StructAsTypeDirect.lf b/test/C/src/StructAsTypeDirect.lf index 29472f057b..b12e46b08e 100644 --- a/test/C/src/StructAsTypeDirect.lf +++ b/test/C/src/StructAsTypeDirect.lf @@ -1,36 +1,36 @@ // Source produces a struct directly, rather than a pointer to a struct. target C { - files: include/hello.h + files: include/hello.h } preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { - output out: hello_t + output out: hello_t - reaction(startup) -> out {= - out->value.name = "Earth"; - out->value.value = 42; - SET_PRESENT(out); - =} + reaction(startup) -> out {= + out->value.name = "Earth"; + out->value.value = 42; + SET_PRESENT(out); + =} } reactor Print(expected: int = 42) { // expected parameter is for testing. - input in: hello_t + input in: hello_t - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value.name, in->value.value); - if (in->value.value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - =} + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value.name, in->value.value); + if (in->value.value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/C/src/StructParallel.lf b/test/C/src/StructParallel.lf index 3c8e61a3a2..237f42366e 100644 --- a/test/C/src/StructParallel.lf +++ b/test/C/src/StructParallel.lf @@ -1,59 +1,58 @@ -// Source allocates an array dynamically and then sends it to two reactors, each -// of which want to modify it. NOTE: Ideally, only one copy would be made, but -// this requires modifying the precedence graph between reactions. +// Source allocates an array dynamically and then sends it to two reactors, each of which want to +// modify it. NOTE: Ideally, only one copy would be made, but this requires modifying the precedence +// graph between reactions. target C { - files: ["include/hello.h"] + files: ["include/hello.h"] } import Source from "StructScale.lf" preamble {= - #include "hello.h" + #include "hello.h" =} reactor Check(expected: int = 42) { - input in: hello_t* - state invoked: bool = false - - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); - if (in->value->value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - self->invoked = true; - =} - - reaction(shutdown) {= - if (self->invoked == false) { - fprintf(stderr, "ERROR: No data received.\n"); - exit(2); - } - =} + input in: hello_t* + state invoked: bool = false + + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); + if (in->value->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + self->invoked = true; + =} + + reaction(shutdown) {= + if (self->invoked == false) { + fprintf(stderr, "ERROR: No data received.\n"); + exit(2); + } + =} } reactor Print(scale: int = 2) { - // Mutable keyword indicates that this reactor wants a writable copy of the - // input. - mutable input in: hello_t* + // Mutable keyword indicates that this reactor wants a writable copy of the input. + mutable input in: hello_t* - output out: hello_t* + output out: hello_t* - reaction(in) -> out {= - in->value->value *= self->scale; - printf("Print received name = %s, value = %d\n", in->value->name, in->value->value); - lf_set_token(out, in->token); - =} + reaction(in) -> out {= + in->value->value *= self->scale; + printf("Print received name = %s, value = %d\n", in->value->name, in->value->value); + lf_set_token(out, in->token); + =} } main reactor StructParallel { - s = new Source() - c1 = new Print() - c2 = new Print(scale = 3) - p1 = new Check(expected = 84) - p2 = new Check(expected = 126) - s.out -> c1.in - s.out -> c2.in - c1.out -> p1.in - c2.out -> p2.in + s = new Source() + c1 = new Print() + c2 = new Print(scale = 3) + p1 = new Check(expected = 84) + p2 = new Check(expected = 126) + s.out -> c1.in + s.out -> c2.in + c1.out -> p1.in + c2.out -> p2.in } diff --git a/test/C/src/StructPrint.lf b/test/C/src/StructPrint.lf index 6af0d60c4f..43d699860b 100644 --- a/test/C/src/StructPrint.lf +++ b/test/C/src/StructPrint.lf @@ -1,39 +1,39 @@ -// Source produces a dynamically allocated struct, which it passes to Print. -// Reference counting ensures that the struct is freed. +// Source produces a dynamically allocated struct, which it passes to Print. Reference counting +// ensures that the struct is freed. target C { - files: ["include/hello.h"] + files: ["include/hello.h"] } preamble {= - #include "hello.h" + #include "hello.h" =} reactor Print { - output out: hello_t* + output out: hello_t* - reaction(startup) -> out {= - // Dynamically allocate an output struct. - SET_NEW(out); - // Above allocates a struct, which then must be populated. - out->value->name = "Earth"; - out->value->value = 42; - =} + reaction(startup) -> out {= + // Dynamically allocate an output struct. + SET_NEW(out); + // Above allocates a struct, which then must be populated. + out->value->name = "Earth"; + out->value->value = 42; + =} } reactor Check(expected: int = 42) { // expected parameter is for testing. - input in: hello_t* + input in: hello_t* - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); - if (in->value->value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - =} + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); + if (in->value->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + =} } main reactor { - s = new Print() - p = new Check() - s.out -> p.in + s = new Print() + p = new Check() + s.out -> p.in } diff --git a/test/C/src/StructScale.lf b/test/C/src/StructScale.lf index 3b92bab002..bbc4d5d078 100644 --- a/test/C/src/StructScale.lf +++ b/test/C/src/StructScale.lf @@ -1,65 +1,63 @@ -// Source produces a dynamically allocated struct, which it passes to Scale. -// Scale requests a writable copy, which, instead of copying, it just gets -// ownership of the original struct. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated struct, which it passes to Scale. Scale requests a +// writable copy, which, instead of copying, it just gets ownership of the original struct. It +// modifies it and passes it to Print. It gets freed after Print is done with it. target C { - files: ["include/hello.h"] + files: ["include/hello.h"] } preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { - output out: hello_t* - - reaction(startup) -> out {= - // Dynamically allocate an output struct. - SET_NEW(out); - // Above allocates a struct, which then must be populated. - out->value->name = "Earth"; - out->value->value = 42; - =} + output out: hello_t* + + reaction(startup) -> out {= + // Dynamically allocate an output struct. + SET_NEW(out); + // Above allocates a struct, which then must be populated. + out->value->name = "Earth"; + out->value->value = 42; + =} } reactor TestInput(expected: int = 42) { // expected parameter is for testing. - input in: hello_t* - state invoked: bool = false - - reaction(in) {= - printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); - if (in->value->value != self->expected) { - printf("ERROR: Expected value to be %d.\n", self->expected); - exit(1); - } - self->invoked = true; - =} - - reaction(shutdown) {= - if (self->invoked == false) { - fprintf(stderr, "ERROR: No data received.\n"); - exit(2); - } - =} + input in: hello_t* + state invoked: bool = false + + reaction(in) {= + printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); + if (in->value->value != self->expected) { + printf("ERROR: Expected value to be %d.\n", self->expected); + exit(1); + } + self->invoked = true; + =} + + reaction(shutdown) {= + if (self->invoked == false) { + fprintf(stderr, "ERROR: No data received.\n"); + exit(2); + } + =} } reactor Print(scale: int = 2) { - // Mutable keyword indicates that this reactor wants a writable copy of the - // input. - mutable input in: hello_t* + // Mutable keyword indicates that this reactor wants a writable copy of the input. + mutable input in: hello_t* - output out: hello_t* + output out: hello_t* - reaction(in) -> out {= - in->value->value *= self->scale; - lf_set_token(out, in->token); - =} + reaction(in) -> out {= + in->value->value *= self->scale; + lf_set_token(out, in->token); + =} } main reactor StructScale { - s = new Source() - c = new Print() - p = new TestInput(expected = 84) - s.out -> c.in - c.out -> p.in + s = new Source() + c = new Print() + p = new TestInput(expected = 84) + s.out -> c.in + c.out -> p.in } diff --git a/test/C/src/SubclassesAndStartup.lf b/test/C/src/SubclassesAndStartup.lf index 2dbc1f688f..46e184e378 100644 --- a/test/C/src/SubclassesAndStartup.lf +++ b/test/C/src/SubclassesAndStartup.lf @@ -1,42 +1,42 @@ target C reactor Super { - state count: int = 0 + state count: int = 0 - reaction(startup) {= - printf("%s(Super) started\n", self->name); - self->count++; - =} + reaction(startup) {= + printf("%s(Super) started\n", self->name); + self->count++; + =} - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "No startup reaction was invoked!\n"); - exit(3); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "No startup reaction was invoked!\n"); + exit(3); + } + =} } reactor SubA(name: string = "SubA") extends Super { - reaction(startup) {= - printf("%s started\n", self->name); - if (self->count == 0) { - fprintf(stderr, "Base class startup reaction was not invoked!\n"); - exit(1); - } - =} + reaction(startup) {= + printf("%s started\n", self->name); + if (self->count == 0) { + fprintf(stderr, "Base class startup reaction was not invoked!\n"); + exit(1); + } + =} } reactor SubB(name: string = "SubB") extends Super { - reaction(startup) {= - printf("%s started\n", self->name); - if (self->count == 0) { - fprintf(stderr, "Base class startup reaction was not invoked!\n"); - exit(2); - } - =} + reaction(startup) {= + printf("%s started\n", self->name); + if (self->count == 0) { + fprintf(stderr, "Base class startup reaction was not invoked!\n"); + exit(2); + } + =} } main reactor SubclassesAndStartup { - a = new SubA() - b = new SubB() + a = new SubA() + b = new SubB() } diff --git a/test/C/src/TestForPreviousOutput.lf b/test/C/src/TestForPreviousOutput.lf index 890b47361d..0151715df0 100644 --- a/test/C/src/TestForPreviousOutput.lf +++ b/test/C/src/TestForPreviousOutput.lf @@ -3,13 +3,13 @@ target C preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include + #ifdef __cplusplus + } + #endif =} reactor Source { diff --git a/test/C/src/TimeLimit.lf b/test/C/src/TimeLimit.lf index ae178d53b5..efffe62f98 100644 --- a/test/C/src/TimeLimit.lf +++ b/test/C/src/TimeLimit.lf @@ -1,49 +1,48 @@ -// Test that the stop function can be used to internally impose a a time limit. -// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt -// or getting the wrong data. +// Test that the stop function can be used to internally impose a a time limit. Correct output for +// this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. target C { - fast: true + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); + lf_set(y, self->count); + =} } reactor Destination { - input x: int - state s: int = 1 + input x: int + state s: int = 1 - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - printf("Error: Expected %d and got %d.\n", self->s, x->value); - exit(1); - } - self->s++; - =} + reaction(x) {= + // printf("%d\n", x->value); + if (x->value != self->s) { + printf("Error: Expected %d and got %d.\n", self->s, x->value); + exit(1); + } + self->s++; + =} - reaction(shutdown) {= - printf("**** shutdown reaction invoked.\n"); - if (self->s != 12) { - fprintf(stderr, "ERROR: Expected 12 but got %d.\n", self->s); - exit(1); - } - =} + reaction(shutdown) {= + printf("**** shutdown reaction invoked.\n"); + if (self->s != 12) { + fprintf(stderr, "ERROR: Expected 12 but got %d.\n", self->s); + exit(1); + } + =} } main reactor TimeLimit(period: time = 1 sec) { - timer stop(10 sec) - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + timer stop(10 sec) + c = new Clock(period = period) + d = new Destination() + c.y -> d.x - reaction(stop) {= lf_request_stop(); =} + reaction(stop) {= lf_request_stop(); =} } diff --git a/test/C/src/TimeState.lf b/test/C/src/TimeState.lf index cb0a9627f3..d3aaf2029a 100644 --- a/test/C/src/TimeState.lf +++ b/test/C/src/TimeState.lf @@ -1,11 +1,11 @@ target C reactor Foo(bar: int = 42) { - state baz: time = 500 msec + state baz: time = 500 msec - reaction(startup) {= printf("Baz: %lld\n", self->baz); =} + reaction(startup) {= printf("Baz: %lld\n", self->baz); =} } main reactor { - a = new Foo() + a = new Foo() } diff --git a/test/C/src/Timeout.lf b/test/C/src/Timeout.lf index d56d86a951..e6198c4c13 100644 --- a/test/C/src/Timeout.lf +++ b/test/C/src/Timeout.lf @@ -4,46 +4,46 @@ * @author Soroush Bateni */ target C { - timeout: 11 msec + timeout: 11 msec } import Sender from "lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state success: bool = false + input in: int + state success: bool = false - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } + =} } main reactor Timeout { - consumer = new Consumer() - producer = new Sender(break_interval = 1 msec) + consumer = new Consumer() + producer = new Sender(break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index 771d321a40..414a4460b0 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -1,50 +1,49 @@ /** - * A test for the timeout functionality in Lingua Franca. This variant tests - * timeout at (0,0). + * A test for the timeout functionality in Lingua Franca. This variant tests timeout at (0,0). * * @author Soroush Bateni */ target C { - timeout: 0 sec + timeout: 0 sec } import Sender from "lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state success: bool = false + input in: int + state success: bool = false - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } + =} } main reactor { - consumer = new Consumer() - producer = new Sender(break_interval = 1 msec) + consumer = new Consumer() + producer = new Sender(break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/C/src/ToReactionNested.lf b/test/C/src/ToReactionNested.lf index 11b3577c84..14be00164d 100644 --- a/test/C/src/ToReactionNested.lf +++ b/test/C/src/ToReactionNested.lf @@ -1,36 +1,36 @@ target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } import Count from "lib/Count.lf" reactor CountContainer { - output out: int - c1 = new Count() - c1.out -> out + output out: int + c1 = new Count() + c1.out -> out } main reactor { - state count: int = 1 - state received: bool = false + state count: int = 1 + state received: bool = false - s = new CountContainer() + s = new CountContainer() - reaction(s.out) {= - if (s.out->is_present) { - lf_print("Received %d.", s.out->value); - if (self->count != s.out->value) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->received = true; + reaction(s.out) {= + if (s.out->is_present) { + lf_print("Received %d.", s.out->value); + if (self->count != s.out->value) { + lf_print_error_and_exit("Expected %d.", self->count); } - self->count++; - =} + self->received = true; + } + self->count++; + =} - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("No inputs present."); - } - =} + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("No inputs present."); + } + =} } diff --git a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf index bc62b214e9..25eb13e564 100644 --- a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,39 +1,36 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source { - output[2] out: int - state count: int = 0 - timer t(0, 200 msec) + output[2] out: int + state count: int = 0 + timer t(0, 200 msec) - reaction(t) -> out {= - if (self->count++ % 2 == 0) { - lf_set(out[0], self->count); - } else { - lf_set(out[1], self->count); - } - =} + reaction(t) -> out {= + if (self->count++ % 2 == 0) { + lf_set(out[0], self->count); + } else { + lf_set(out[1], self->count); + } + =} } reactor Destination { - input in: int + input in: int - reaction(in) {= - if (!in->is_present) { - fprintf(stderr, "Reaction to input of triggered even though all inputs are absent!\n"); - exit(1); - } - =} + reaction(in) {= + if (!in->is_present) { + fprintf(stderr, "Reaction to input of triggered even though all inputs are absent!\n"); + exit(1); + } + =} } main reactor TriggerDownstreamOnlyIfPresent2 { - s = new Source() - d = new[2] Destination() - s.out -> d.in + s = new Source() + d = new[2] Destination() + s.out -> d.in } diff --git a/test/C/src/UnconnectedInput.lf b/test/C/src/UnconnectedInput.lf index 21e8cc5a69..88f7554149 100644 --- a/test/C/src/UnconnectedInput.lf +++ b/test/C/src/UnconnectedInput.lf @@ -1,48 +1,48 @@ // Test unconnected input. target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out: int - timer t(0, 1 sec) - state s: int = 1 + output out: int + timer t(0, 1 sec) + state s: int = 1 - reaction(t) -> out {= lf_set(out, self->s++); =} + reaction(t) -> out {= lf_set(out, self->s++); =} } reactor Add { - input in1: int - input in2: int - output out: int + input in1: int + input in2: int + output out: int - reaction(in1, in2) -> out {= - int result = 0; - if (in1->is_present) result += in1->value; - if (in2->is_present) result += in2->value; - lf_set(out, result); - =} + reaction(in1, in2) -> out {= + int result = 0; + if (in1->is_present) result += in1->value; + if (in2->is_present) result += in2->value; + lf_set(out, result); + =} } reactor Print { - input in: int - state expected: int = 1 + input in: int + state expected: int = 1 - reaction(in) {= - printf("Received: %d.\n", in->value); - if (in->value != self->expected) { - printf("ERROR: Expected %d.\n", self->expected); - exit(1); - } - self->expected++; - =} + reaction(in) {= + printf("Received: %d.\n", in->value); + if (in->value != self->expected) { + printf("ERROR: Expected %d.\n", self->expected); + exit(1); + } + self->expected++; + =} } main reactor UnconnectedInput { - source = new Source() - add = new Add() - print = new Print() - source.out -> add.in2 - add.out -> print.in + source = new Source() + add = new Add() + print = new Print() + source.out -> add.in2 + add.out -> print.in } diff --git a/test/C/src/arduino/AnalogReadSerial.lf b/test/C/src/arduino/AnalogReadSerial.lf index 220cb47d47..b5d83d09de 100644 --- a/test/C/src/arduino/AnalogReadSerial.lf +++ b/test/C/src/arduino/AnalogReadSerial.lf @@ -1,21 +1,20 @@ /** - * This example reads an analog input on pin 0, prints the result to the Serial - * Monitor. Graphical representation is available using Serial Plotter (Tools > - * Serial Plotter menu). Attach the center pin of a potentiometer to pin A0, and - * the outside pins to +5V and ground. + * This example reads an analog input on pin 0, prints the result to the Serial Monitor. Graphical + * representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center + * pin of a potentiometer to pin A0, and the outside pins to +5V and ground. */ target C { - platform: { - name: "arduino", - board: "arduino:avr:mega" - } + platform: { + name: "arduino", + board: "arduino:avr:mega" + } } main reactor AnalogReadSerial { - timer t1(0, 1 msec) + timer t1(0, 1 msec) - reaction(t1) {= - int sensorValue = analogRead(A0); - Serial.println(sensorValue); - =} + reaction(t1) {= + int sensorValue = analogRead(A0); + Serial.println(sensorValue); + =} } diff --git a/test/C/src/arduino/Blink.lf b/test/C/src/arduino/Blink.lf index 809aa55884..2612e72a62 100644 --- a/test/C/src/arduino/Blink.lf +++ b/test/C/src/arduino/Blink.lf @@ -1,22 +1,21 @@ /** - * This example demonstrates a very simple blink program that will turn on and - * off an LED on the Arduino Board with a 50% duty cycle switching every - * half-second. + * This example demonstrates a very simple blink program that will turn on and off an LED on the + * Arduino Board with a 50% duty cycle switching every half-second. */ target C { - platform: { - name: "arduino", - board: "arduino:avr:mega" - } + platform: { + name: "arduino", + board: "arduino:avr:mega" + } } main reactor Blink { - timer t1(0, 1 sec) - timer t2(500 msec, 1 sec) + timer t1(0, 1 sec) + timer t2(500 msec, 1 sec) - reaction(startup) {= pinMode(LED_BUILTIN, OUTPUT); =} + reaction(startup) {= pinMode(LED_BUILTIN, OUTPUT); =} - reaction(t1) {= digitalWrite(LED_BUILTIN, HIGH); =} + reaction(t1) {= digitalWrite(LED_BUILTIN, HIGH); =} - reaction(t2) {= digitalWrite(LED_BUILTIN, LOW); =} + reaction(t2) {= digitalWrite(LED_BUILTIN, LOW); =} } diff --git a/test/C/src/arduino/BlinkAttemptThreading.lf b/test/C/src/arduino/BlinkAttemptThreading.lf index 8f71009edf..4c4dac927c 100644 --- a/test/C/src/arduino/BlinkAttemptThreading.lf +++ b/test/C/src/arduino/BlinkAttemptThreading.lf @@ -1,24 +1,23 @@ /** - * This example demonstrates a very simple blink program that will turn on and - * off an LED on the Arduino Board with a 50% duty cycle switching every - * half-second. Note: if we try to enable threading, the system will give us a - * warning and default back to no threading. + * This example demonstrates a very simple blink program that will turn on and off an LED on the + * Arduino Board with a 50% duty cycle switching every half-second. Note: if we try to enable + * threading, the system will give us a warning and default back to no threading. */ target C { - platform: { - name: "arduino", - board: "arduino:avr:mega" - }, - threading: true + platform: { + name: "arduino", + board: "arduino:avr:mega" + }, + threading: true } main reactor BlinkAttemptThreading { - timer t1(0, 1 sec) - timer t2(500 msec, 1 sec) + timer t1(0, 1 sec) + timer t2(500 msec, 1 sec) - reaction(startup) {= pinMode(LED_BUILTIN, OUTPUT); =} + reaction(startup) {= pinMode(LED_BUILTIN, OUTPUT); =} - reaction(t1) {= digitalWrite(LED_BUILTIN, HIGH); =} + reaction(t1) {= digitalWrite(LED_BUILTIN, HIGH); =} - reaction(t2) {= digitalWrite(LED_BUILTIN, LOW); =} + reaction(t2) {= digitalWrite(LED_BUILTIN, LOW); =} } diff --git a/test/C/src/arduino/BlinkMBED.lf b/test/C/src/arduino/BlinkMBED.lf index f9702d27cc..3b2c84427e 100644 --- a/test/C/src/arduino/BlinkMBED.lf +++ b/test/C/src/arduino/BlinkMBED.lf @@ -1,22 +1,21 @@ /** - * This example demonstrates a very simple blink program that will turn on and - * off an LED on the Arduino Board with a 50% duty cycle switching every - * half-second. + * This example demonstrates a very simple blink program that will turn on and off an LED on the + * Arduino Board with a 50% duty cycle switching every half-second. */ target C { - platform: { - name: "arduino", - board: "arduino:mbed:nano33ble" - } + platform: { + name: "arduino", + board: "arduino:mbed:nano33ble" + } } main reactor BlinkMBED { - timer t1(0, 1 sec) - timer t2(500 msec, 1 sec) + timer t1(0, 1 sec) + timer t2(500 msec, 1 sec) - reaction(startup) {= pinMode(LED_BUILTIN, OUTPUT); =} + reaction(startup) {= pinMode(LED_BUILTIN, OUTPUT); =} - reaction(t1) {= digitalWrite(LED_BUILTIN, HIGH); =} + reaction(t1) {= digitalWrite(LED_BUILTIN, HIGH); =} - reaction(t2) {= digitalWrite(LED_BUILTIN, LOW); =} + reaction(t2) {= digitalWrite(LED_BUILTIN, LOW); =} } diff --git a/test/C/src/arduino/DigitalReadSerial.lf b/test/C/src/arduino/DigitalReadSerial.lf index d79f86ad9b..e521585a5d 100644 --- a/test/C/src/arduino/DigitalReadSerial.lf +++ b/test/C/src/arduino/DigitalReadSerial.lf @@ -1,23 +1,20 @@ -/** - * This example reads a digital input on pin 2, prints the result to the Serial - * Monitor - */ +/** This example reads a digital input on pin 2, prints the result to the Serial Monitor */ target C { - platform: { - name: "arduino", - board: "arduino:avr:mega" - } + platform: { + name: "arduino", + board: "arduino:avr:mega" + } } main reactor DigitalReadSerial { - timer t1(0, 1 msec) - state pushButton: int = 2 + timer t1(0, 1 msec) + state pushButton: int = 2 - reaction(startup) {= pinMode(self->pushButton, INPUT); =} + reaction(startup) {= pinMode(self->pushButton, INPUT); =} - reaction(t1) {= - int buttonState = digitalRead(self->pushButton); - // print out the state of the button: - Serial.println(buttonState); - =} + reaction(t1) {= + int buttonState = digitalRead(self->pushButton); + // print out the state of the button: + Serial.println(buttonState); + =} } diff --git a/test/C/src/arduino/Fade.lf b/test/C/src/arduino/Fade.lf index d23aabd646..5be1e79a79 100644 --- a/test/C/src/arduino/Fade.lf +++ b/test/C/src/arduino/Fade.lf @@ -1,32 +1,31 @@ /** - * This example shows how to fade an LED on pin 9 using the analogWrite() - * function. The analogWrite() function uses PWM, so if you want to change the - * pin you're using, be sure to use another PWM capable pin. On most Arduino, - * the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and - * ~11. + * This example shows how to fade an LED on pin 9 using the analogWrite() function. The + * analogWrite() function uses PWM, so if you want to change the pin you're using, be sure to use + * another PWM capable pin. On most Arduino, the PWM pins are identified with a "~" sign, like ~3, + * ~5, ~6, ~9, ~10 and ~11. */ target C { - platform: { - name: "arduino", - board: "arduino:avr:mega" - } + platform: { + name: "arduino", + board: "arduino:avr:mega" + } } main reactor Fade { - timer t1(0, 30 msec) - state led: int = 9 - state brightness: int = 9 - state fadeAmount: int = 5 + timer t1(0, 30 msec) + state led: int = 9 + state brightness: int = 9 + state fadeAmount: int = 5 - reaction(startup) {= pinMode(self->led, OUTPUT); =} + reaction(startup) {= pinMode(self->led, OUTPUT); =} - reaction(t1) {= - analogWrite(self->led, self->brightness); - // change the brightness for next time through the loop: - self->brightness += self->fadeAmount; - // reverse the direction of the fading at the ends of the fade: - if (self->brightness <= 0 || self->brightness >= 255) { - self->fadeAmount = -self->fadeAmount; - } - =} + reaction(t1) {= + analogWrite(self->led, self->brightness); + // change the brightness for next time through the loop: + self->brightness += self->fadeAmount; + // reverse the direction of the fading at the ends of the fade: + if (self->brightness <= 0 || self->brightness >= 255) { + self->fadeAmount = -self->fadeAmount; + } + =} } diff --git a/test/C/src/arduino/ReadAnalogVoltage.lf b/test/C/src/arduino/ReadAnalogVoltage.lf index 77be8e8b06..4dbffbbb83 100644 --- a/test/C/src/arduino/ReadAnalogVoltage.lf +++ b/test/C/src/arduino/ReadAnalogVoltage.lf @@ -1,28 +1,27 @@ /** - * This example reads an analog input on pin 0, converts it to voltage, and - * prints the result to the Serial Monitor. Graphical representation is - * available using Serial Plotter (Tools > Serial Plotter menu). Attach the - * center pin of a potentiometer to pin A0, and the outside pins to +5V and - * ground. + * This example reads an analog input on pin 0, converts it to voltage, and prints the result to the + * Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial + * Plotter menu). Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V + * and ground. */ target C { - platform: { - name: "arduino", - board: "arduino:avr:mega" - } + platform: { + name: "arduino", + board: "arduino:avr:mega" + } } main reactor ReadAnalogVoltage { - logical action a + logical action a - reaction(startup) -> a {= lf_schedule(a, 0); =} + reaction(startup) -> a {= lf_schedule(a, 0); =} - reaction(a) -> a {= - int sensorValue = analogRead(A0); - // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): - float voltage = sensorValue * (5.0 / 1023.0); - // print out the value you read: - Serial.println(voltage); - lf_schedule(a, 0); - =} + reaction(a) -> a {= + int sensorValue = analogRead(A0); + // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): + float voltage = sensorValue * (5.0 / 1023.0); + // print out the value you read: + Serial.println(voltage); + lf_schedule(a, 0); + =} } diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index 58120446d4..d43dbc2a90 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -1,74 +1,72 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test case - * assumes that target is multithreaded. This test will not work with the - * unthreaded C target because that target does not implement any mutex - * protecting the event queue. + * Test asynchronous callbacks that trigger a physical action. This test case assumes that target is + * multithreaded. This test will not work with the unthreaded C target because that target does not + * implement any mutex protecting the event queue. * - * Note: This test uses the LF platform support to enable it to run on multiple - * platforms. + * Note: This test uses the LF platform support to enable it to run on multiple platforms. */ target C { - tracing: true, - timeout: 2 sec, - keepalive: true + tracing: true, + timeout: 2 sec, + keepalive: true } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} main reactor AsyncCallback { - preamble {= - void callback(void* a) { - // Schedule twice. If the action is not physical, these should - // get consolidated into a single action triggering. If it is, - // then they cause two separate triggerings with close but not - // equal time stamps. The minimum time between these is determined - // by the argument in the physical action definition. - lf_schedule(a, 0LL); - lf_schedule(a, 0LL); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - instant_t sleep_time = 100000000; - lf_sleep(sleep_time); - callback(a); - return NULL; - } - lf_thread_t threadId; - =} - timer t(0, 200 msec) - state thread_id: lf_thread_t = 0 - state expected_time: time = 100 msec - state toggle: bool = false + preamble {= + void callback(void* a) { + // Schedule twice. If the action is not physical, these should + // get consolidated into a single action triggering. If it is, + // then they cause two separate triggerings with close but not + // equal time stamps. The minimum time between these is determined + // by the argument in the physical action definition. + lf_schedule(a, 0LL); + lf_schedule(a, 0LL); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + instant_t sleep_time = 100000000; + lf_sleep(sleep_time); + callback(a); + return NULL; + } + lf_thread_t threadId; + =} + timer t(0, 200 msec) + state thread_id: lf_thread_t = 0 + state expected_time: time = 100 msec + state toggle: bool = false - physical action a(100 msec): int - state i: int = 0 + physical action a(100 msec): int + state i: int = 0 - reaction(t) -> a {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, a); - =} + reaction(t) -> a {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, a); + =} - reaction(a) {= - instant_t elapsed_time = lf_time_logical_elapsed(); - printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", - self->i++, elapsed_time); - if (elapsed_time <= self->expected_time) { - printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); - exit(1); - } - if (self->toggle) { - self->toggle = false; - self->expected_time += 200000000LL; - } else { - self->toggle = true; - } - =} + reaction(a) {= + instant_t elapsed_time = lf_time_logical_elapsed(); + printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", + self->i++, elapsed_time); + if (elapsed_time <= self->expected_time) { + printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); + exit(1); + } + if (self->toggle) { + self->toggle = false; + self->expected_time += 200000000LL; + } else { + self->toggle = true; + } + =} } diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index b0c5c502f2..245048d910 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -1,71 +1,70 @@ -// Test asynchronous callbacks that trigger a physical action with a DROP -// policy. This test case assumes that the target is multithreaded. This test -// will not work with the unthreaded C target because that target does not -// implement any mutex protecting the event queue. +// Test asynchronous callbacks that trigger a physical action with a DROP policy. This test case +// assumes that the target is multithreaded. This test will not work with the unthreaded C target +// because that target does not implement any mutex protecting the event queue. target C { - keepalive: true, // To silence warning. - timeout: 2 sec + keepalive: true, // To silence warning. + timeout: 2 sec } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} main reactor { - preamble {= - void callback(void* a) { - // Schedule twice in rapid succession. - // The second value should be dropped because the - // timestamps will not be sufficiently separated. - // The minimum time between these is determined - // by the argument in the physical action definition. - lf_schedule_int(a, 0, 0); - lf_schedule_int(a, 0, 1); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - instant_t sleep_time = 100000000; - lf_sleep(sleep_time); - callback(a); - return NULL; - } - lf_thread_t threadId; - =} - timer t(0, 200 msec) - state thread_id: lf_thread_t = 0 - state expected_time: time = 100 msec - state toggle: bool = false + preamble {= + void callback(void* a) { + // Schedule twice in rapid succession. + // The second value should be dropped because the + // timestamps will not be sufficiently separated. + // The minimum time between these is determined + // by the argument in the physical action definition. + lf_schedule_int(a, 0, 0); + lf_schedule_int(a, 0, 1); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + instant_t sleep_time = 100000000; + lf_sleep(sleep_time); + callback(a); + return NULL; + } + lf_thread_t threadId; + =} + timer t(0, 200 msec) + state thread_id: lf_thread_t = 0 + state expected_time: time = 100 msec + state toggle: bool = false - physical action a(100 msec, 100 msec, "drop"): int - state i: int = 0 + physical action a(100 msec, 100 msec, "drop"): int + state i: int = 0 - reaction(t) -> a {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, a); - =} + reaction(t) -> a {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, a); + =} - reaction(a) {= - instant_t elapsed_time = lf_time_logical_elapsed(); - printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); - if (elapsed_time <= self->expected_time) { - printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); - exit(1); - } - if (a->value != 0) { - printf("ERROR: Received: %d, expected 0 because the second event should have been dropped.\n", a->value); - exit(2); - } - if (self->toggle) { - self->toggle = false; - self->expected_time += 200000000LL; - } else { - self->toggle = true; - } - =} + reaction(a) {= + instant_t elapsed_time = lf_time_logical_elapsed(); + printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); + if (elapsed_time <= self->expected_time) { + printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); + exit(1); + } + if (a->value != 0) { + printf("ERROR: Received: %d, expected 0 because the second event should have been dropped.\n", a->value); + exit(2); + } + if (self->toggle) { + self->toggle = false; + self->expected_time += 200000000LL; + } else { + self->toggle = true; + } + =} } diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index 7bac7496b5..2809012ac9 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -1,71 +1,70 @@ -// Test asynchronous callbacks that trigger a physical action with a "replace" -// policy. This test case assumes that the target is multithreaded. This test -// will not work with the unthreaded C target because that target does not -// implement any mutex protecting the event queue. +// Test asynchronous callbacks that trigger a physical action with a "replace" policy. This test +// case assumes that the target is multithreaded. This test will not work with the unthreaded C +// target because that target does not implement any mutex protecting the event queue. target C { - keepalive: true, - timeout: 2 sec + keepalive: true, + timeout: 2 sec } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} main reactor { - preamble {= - void callback(void* a) { - // Schedule twice in rapid succession. - // The second value should be dropped because the - // timestamps will not be sufficiently separated. - // The minimum time between these is determined - // by the argument in the physical action definition. - lf_schedule_int(a, 0, 0); - lf_schedule_int(a, 0, 1); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - instant_t sleep_time = 100000000; - lf_sleep(sleep_time); - callback(a); - return NULL; - } - lf_thread_t threadId; - =} - timer t(0, 200 msec) - state thread_id: lf_thread_t = 0 - state expected_time: time = 100 msec - state toggle: bool = false + preamble {= + void callback(void* a) { + // Schedule twice in rapid succession. + // The second value should be dropped because the + // timestamps will not be sufficiently separated. + // The minimum time between these is determined + // by the argument in the physical action definition. + lf_schedule_int(a, 0, 0); + lf_schedule_int(a, 0, 1); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + instant_t sleep_time = 100000000; + lf_sleep(sleep_time); + callback(a); + return NULL; + } + lf_thread_t threadId; + =} + timer t(0, 200 msec) + state thread_id: lf_thread_t = 0 + state expected_time: time = 100 msec + state toggle: bool = false - physical action a(100 msec, 100 msec, "replace"): int - state i: int = 0 + physical action a(100 msec, 100 msec, "replace"): int + state i: int = 0 - reaction(t) -> a {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, a); - =} + reaction(t) -> a {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, a); + =} - reaction(a) {= - instant_t elapsed_time = lf_time_logical_elapsed(); - printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); - if (elapsed_time <= self->expected_time) { - printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); - exit(1); - } - if (a->value != 1) { - printf("ERROR: Received: %d, expected 1 because the second event should have replaced the first.\n", a->value); - exit(2); - } - if (self->toggle) { - self->toggle = false; - self->expected_time += 200000000LL; - } else { - self->toggle = true; - } - =} + reaction(a) {= + instant_t elapsed_time = lf_time_logical_elapsed(); + printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); + if (elapsed_time <= self->expected_time) { + printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); + exit(1); + } + if (a->value != 1) { + printf("ERROR: Received: %d, expected 1 because the second event should have replaced the first.\n", a->value); + exit(2); + } + if (self->toggle) { + self->toggle = false; + self->expected_time += 200000000LL; + } else { + self->toggle = true; + } + =} } diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index cf0bafeb82..ed40610e62 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -1,37 +1,36 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d\n", self->count); + exit(1); + } + =} } main reactor CompositionThreaded { - s = new Source() - d = new Test() - s.y -> d.x + s = new Source() + d = new Test() + s.y -> d.x } diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index ad14879080..175745baa5 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -1,52 +1,52 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target C preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} reactor Deadline(threshold: time = 100 msec) { - input x: int - output deadline_violation: bool + input x: int + output deadline_violation: bool - reaction(x) -> deadline_violation {= - printf("ERROR: Deadline violation was not detected!\n"); - exit(1); - =} deadline(threshold) {= - printf("Deadline violation detected.\n"); - lf_set(deadline_violation, true); - =} + reaction(x) -> deadline_violation {= + printf("ERROR: Deadline violation was not detected!\n"); + exit(1); + =} deadline(threshold) {= + printf("Deadline violation detected.\n"); + lf_set(deadline_violation, true); + =} } main reactor { - state violation_detected: bool = false - d = new Deadline(threshold = 10 msec) + state violation_detected: bool = false + d = new Deadline(threshold = 10 msec) - reaction(startup) -> d.x {= - lf_sleep(MSEC(200)); - lf_set(d.x, 42); - =} + reaction(startup) -> d.x {= + lf_sleep(MSEC(200)); + lf_set(d.x, 42); + =} - reaction(d.deadline_violation) {= - if (d.deadline_violation) { - printf("Output successfully produced by deadline miss handler.\n"); - self->violation_detected = true; - } - =} + reaction(d.deadline_violation) {= + if (d.deadline_violation) { + printf("Output successfully produced by deadline miss handler.\n"); + self->violation_detected = true; + } + =} - reaction(shutdown) {= - if (self->violation_detected) { - printf("SUCCESS. Test passes.\n"); - } else { - printf("FAILURE. Container did not react to deadline violation.\n"); - exit(2); - } - =} + reaction(shutdown) {= + if (self->violation_detected) { + printf("SUCCESS. Test passes.\n"); + } else { + printf("FAILURE. Container did not react to deadline violation.\n"); + exit(2); + } + =} } diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index ffc1be2701..b3b86dfb23 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -1,62 +1,61 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target C { - timeout: 6 sec + timeout: 6 sec } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "platform.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "platform.h" + #ifdef __cplusplus + } + #endif =} reactor Source(period: time = 3000 msec) { - output y: int - timer t(0, period) - state count: int = 0 + output y: int + timer t(0, period) + state count: int = 0 - reaction(t) -> y {= - if (2 * (self->count / 2) != self->count) { - // The count variable is odd. - // Take time to cause a deadline violation. - lf_sleep(MSEC(210)); - } - printf("Source sends: %d.\n", self->count); - lf_set(y, self->count); - (self->count)++; - =} + reaction(t) -> y {= + if (2 * (self->count / 2) != self->count) { + // The count variable is odd. + // Take time to cause a deadline violation. + lf_sleep(MSEC(210)); + } + printf("Source sends: %d.\n", self->count); + lf_set(y, self->count); + (self->count)++; + =} } reactor Destination(timeout: time = 1 sec) { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - printf("Destination receives: %d\n", x->value); - if (2 * (self->count / 2) != self->count) { - // The count variable is odd, so the deadline should have been violated. - printf("ERROR: Failed to detect deadline.\n"); - exit(1); - } - (self->count)++; - =} deadline(timeout) {= - printf("Destination deadline handler receives: %d\n", x->value); - if (2 * (self->count / 2) == self->count) { - // The count variable is even, so the deadline should not have been violated. - printf("ERROR: Unexpected deadline violation.\n"); - exit(2); - } - (self->count)++; - =} + reaction(x) {= + printf("Destination receives: %d\n", x->value); + if (2 * (self->count / 2) != self->count) { + // The count variable is odd, so the deadline should have been violated. + printf("ERROR: Failed to detect deadline.\n"); + exit(1); + } + (self->count)++; + =} deadline(timeout) {= + printf("Destination deadline handler receives: %d\n", x->value); + if (2 * (self->count / 2) == self->count) { + // The count variable is even, so the deadline should not have been violated. + printf("ERROR: Unexpected deadline violation.\n"); + exit(2); + } + (self->count)++; + =} } main reactor { - s = new Source() - d = new Destination(timeout = 200 msec) - s.y -> d.x + s = new Source() + d = new Destination(timeout = 200 msec) + s.y -> d.x } diff --git a/test/C/src/concurrent/DelayIntThreaded.lf b/test/C/src/concurrent/DelayIntThreaded.lf index 449b17eb60..57d3987386 100644 --- a/test/C/src/concurrent/DelayIntThreaded.lf +++ b/test/C/src/concurrent/DelayIntThreaded.lf @@ -2,58 +2,58 @@ target C reactor Delay(delay: time = 100 msec) { - input in: int - output out: int - logical action a: int + input in: int + output out: int + logical action a: int - reaction(a) -> out {= lf_set(out, a->value); =} + reaction(a) -> out {= lf_set(out, a->value); =} - reaction(in) -> a {= - // Use specialized form of schedule for integer payloads. - lf_schedule_int(a, self->delay, in->value); - =} + reaction(in) -> a {= + // Use specialized form of schedule for integer payloads. + lf_schedule_int(a, self->delay, in->value); + =} } reactor Test { - input in: int - state start_time: time = 0 - state received_value: bool = false - - reaction(startup) {= - // Record the logical time at the start. - self->start_time = lf_time_logical(); - =} - - reaction(in) {= - printf("Received: %d.\n", in->value); - self->received_value = true; - // Check the time of the input. - instant_t current_time = lf_time_logical(); - interval_t elapsed = current_time - self->start_time; - printf("After %lld nsec of logical time.\n", elapsed); - if (elapsed != 100000000LL) { - printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); - exit(1); - } - if (in->value != 42) { - printf("ERROR: Expected input value to be 42. It was %d.\n", in->value); - exit(2); - } - =} - - reaction(shutdown) {= - printf("Checking that communication occurred.\n"); - if (!self->received_value) { - printf("ERROR: No communication occurred!\n"); - exit(3); - } - =} + input in: int + state start_time: time = 0 + state received_value: bool = false + + reaction(startup) {= + // Record the logical time at the start. + self->start_time = lf_time_logical(); + =} + + reaction(in) {= + printf("Received: %d.\n", in->value); + self->received_value = true; + // Check the time of the input. + instant_t current_time = lf_time_logical(); + interval_t elapsed = current_time - self->start_time; + printf("After %lld nsec of logical time.\n", elapsed); + if (elapsed != 100000000LL) { + printf("ERROR: Expected elapsed time to be 100000000. It was %lld.\n", elapsed); + exit(1); + } + if (in->value != 42) { + printf("ERROR: Expected input value to be 42. It was %d.\n", in->value); + exit(2); + } + =} + + reaction(shutdown) {= + printf("Checking that communication occurred.\n"); + if (!self->received_value) { + printf("ERROR: No communication occurred!\n"); + exit(3); + } + =} } main reactor { - d = new Delay() - t = new Test() - d.out -> t.in + d = new Delay() + t = new Test() + d.out -> t.in - reaction(startup) -> d.in {= lf_set(d.in, 42); =} + reaction(startup) -> d.in {= lf_set(d.in, 42); =} } diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index ba6c38ca19..25eeb9f846 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -1,47 +1,47 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Destination { - input x: int - input w: int - state s: int = 2 + input x: int + input w: int + state s: int = 2 - reaction(x, w) {= - int sum = 0; - if (x->is_present) { - sum += x->value; - } - if (w->is_present) { - sum += w->value; - } - printf("Sum of inputs is: %d\n", sum); - if (sum != self->s) { - printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); - exit(1); - } - self->s += 2; - =} + reaction(x, w) {= + int sum = 0; + if (x->is_present) { + sum += x->value; + } + if (w->is_present) { + sum += w->value; + } + printf("Sum of inputs is: %d\n", sum); + if (sum != self->s) { + printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); + exit(1); + } + self->s += 2; + =} } main reactor DoubleReactionThreaded { - c1 = new Clock() - c2 = new Clock() - d = new Destination() - c1.y -> d.x - c2.y -> d.w + c1 = new Clock() + c2 = new Clock() + d = new Destination() + c1.y -> d.x + c2.y -> d.w } diff --git a/test/C/src/concurrent/GainThreaded.lf b/test/C/src/concurrent/GainThreaded.lf index d9d6ec7673..f1407793bd 100644 --- a/test/C/src/concurrent/GainThreaded.lf +++ b/test/C/src/concurrent/GainThreaded.lf @@ -2,38 +2,38 @@ target C reactor Scale(scale: int = 2) { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= lf_set(y, x->value * self->scale); =} + reaction(x) -> y {= lf_set(y, x->value * self->scale); =} } reactor Test { - input x: int - state received_value: bool = false + input x: int + state received_value: bool = false - reaction(x) {= - printf("Received %d.\n", x->value); - self->received_value = true; - if (x->value != 2) { - printf("ERROR: Expected 2!\n"); - exit(1); - } - =} + reaction(x) {= + printf("Received %d.\n", x->value); + self->received_value = true; + if (x->value != 2) { + printf("ERROR: Expected 2!\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (!self->received_value) { - printf("ERROR: No value received by Test reactor!\n"); - } else { - printf("Test passes.\n"); - } - =} + reaction(shutdown) {= + if (!self->received_value) { + printf("ERROR: No value received by Test reactor!\n"); + } else { + printf("Test passes.\n"); + } + =} } main reactor { - g = new Scale() - d = new Test() - g.y -> d.x + g = new Scale() + d = new Test() + g.y -> d.x - reaction(startup) -> g.x {= lf_set(g.x, 1); =} + reaction(startup) -> g.x {= lf_set(g.x, 1); =} } diff --git a/test/C/src/concurrent/HelloThreaded.lf b/test/C/src/concurrent/HelloThreaded.lf index 285811a17d..afe424aaaf 100644 --- a/test/C/src/concurrent/HelloThreaded.lf +++ b/test/C/src/concurrent/HelloThreaded.lf @@ -1,63 +1,56 @@ -// This test checks that logical time is incremented an appropriate amount as a -// result of an invocation of the lf_schedule() function at runtime. It also -// performs various smoke tests of timing aligned reactions. The first instance -// has a period of 4 seconds, the second of 2 seconds, and the third (composite) -// or 1 second. +// This test checks that logical time is incremented an appropriate amount as a result of an +// invocation of the lf_schedule() function at runtime. It also performs various smoke tests of +// timing aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, +// and the third (composite) or 1 second. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } preamble {= - #include + #include =} reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { - state count: int = 0 - state previous_time: time = 0 - timer t(1 sec, period) - logical action a + state count: int = 0 + state previous_time: time = 0 + timer t(1 sec, period) + logical action a - reaction(t) -> a {= - printf("%s\n", self->message); - lf_schedule(a, MSEC(200)); - // Print the current time. - self->previous_time = lf_time_logical(); - time_t secs = self->previous_time/BILLION; - printf("Current time is %lld\n", self->previous_time); - printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); - =} + reaction(t) -> a {= + printf("%s\n", self->message); + lf_schedule(a, MSEC(200)); + // Print the current time. + self->previous_time = lf_time_logical(); + time_t secs = self->previous_time/BILLION; + printf("Current time is %lld\n", self->previous_time); + printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); + =} - reaction(a) {= - (self->count)++; - printf("***** action %d at time %lld\n", self->count, lf_time_logical()); - // Check the a_has_value variable. - if (a->has_value) { - printf("FAILURE: Expected a->has_value to be false, but it was true.\n"); - exit(2); - } - long long time = lf_time_logical(); - if (time - self->previous_time != 200000000ll) { - printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", - time - self->previous_time - ); - exit(1); - } - =} + reaction(a) {= + (self->count)++; + printf("***** action %d at time %lld\n", self->count, lf_time_logical()); + // Check the a_has_value variable. + if (a->has_value) { + printf("FAILURE: Expected a->has_value to be false, but it was true.\n"); + exit(2); + } + long long time = lf_time_logical(); + if (time - self->previous_time != 200000000ll) { + printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", + time - self->previous_time + ); + exit(1); + } + =} } -reactor Inside( - period: time = 1 sec, - message: string = "Composite default message." -) { - third_instance = new Reschedule(period = period, message = message) +reactor Inside(period: time = 1 sec, message: string = "Composite default message.") { + third_instance = new Reschedule(period = period, message = message) } main reactor HelloThreaded { - first_instance = new Reschedule( - period = 4 sec, - message = "Hello from first_instance." - ) - second_instance = new Reschedule(message = "Hello from second_instance.") - composite_instance = new Inside(message = "Hello from composite_instance.") + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance.") + second_instance = new Reschedule(message = "Hello from second_instance.") + composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/C/src/concurrent/PingPongThreaded.lf b/test/C/src/concurrent/PingPongThreaded.lf index 4fae17911e..4d6532acdd 100644 --- a/test/C/src/concurrent/PingPongThreaded.lf +++ b/test/C/src/concurrent/PingPongThreaded.lf @@ -1,71 +1,67 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - * Unthreaded: 97 msec Threaded: 265 msec (168 msec with optimization of - * executing immediately) + * Unthreaded: 97 msec Threaded: 265 msec (168 msec with optimization of executing immediately) * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ target C { - fast: true + fast: true } reactor Ping(count: int = 10) { - input receive: int - output send: int - state pingsLeft: int = count - logical action serve + input receive: int + output send: int + state pingsLeft: int = count + logical action serve - reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} + reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} - reaction(receive) -> serve {= - if (self->pingsLeft > 0) { - lf_schedule(serve, 0); - } else { - lf_request_stop(); - } - =} + reaction(receive) -> serve {= + if (self->pingsLeft > 0) { + lf_schedule(serve, 0); + } else { + lf_request_stop(); + } + =} } reactor Pong(expected: int = 10) { - input receive: int - output send: int - state count: int = 0 + input receive: int + output send: int + state count: int = 0 - reaction(receive) -> send {= - self->count++; - lf_set(send, receive->value); - =} + reaction(receive) -> send {= + self->count++; + lf_set(send, receive->value); + =} - reaction(shutdown) {= - if (self->count != self->expected) { - fprintf(stderr, "Pong expected to receive %d inputs, but it received %d.\n", - self->expected, self->count - ); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->count != self->expected) { + fprintf(stderr, "Pong expected to receive %d inputs, but it received %d.\n", + self->expected, self->count + ); + exit(1); + } + printf("Success.\n"); + =} } main reactor PingPongThreaded { - ping = new Ping() - pong = new Pong() - ping.send -> pong.receive - pong.send -> ping.receive + ping = new Ping() + pong = new Pong() + ping.send -> pong.receive + pong.send -> ping.receive } diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index 2ef6af7af6..37aea62afb 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -1,106 +1,88 @@ /** - * Test _lf_schedule_at_tag which is an internal API function not meant to be - * used in user code. + * Test _lf_schedule_at_tag which is an internal API function not meant to be used in user code. * * @author Soroush Bateni */ target C { - timeout: 1 sec, - keepalive: true + timeout: 1 sec, + keepalive: true } reactor Scheduler { - preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "include/core/reactor_common.h" - #ifdef __cplusplus - } - #endif - =} - logical action act - // List of microsteps. Size = 16 - state microstep_delay_list: uint32_t[] = { - 0, - 1, - 1, - 2, - 2, - 0, - 0, - 1, - 1, - 0, - 2, - 3, - 3, - 4, - 4, - 5 + preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "include/core/reactor_common.h" + #ifdef __cplusplus } + #endif + =} + logical action act + // List of microsteps. Size = 16 + state microstep_delay_list: uint32_t[] = {0, 1, 1, 2, 2, 0, 0, 1, 1, 0, 2, 3, 3, 4, 4, 5} - state times: int[] = { - 0, - 0, - 0, - 0, - 0, - 400 msec, - 400 msec, - 400 msec, - 400 msec, // List of the corresponding times. Size = 16 - 800 msec, - 800 msec, - 800 msec, - 800 msec, - 900 msec, - 900 msec, - 900 msec - } - // Size = 9 - state action_hit_list_microstep: int[] = {1, 2, 0, 1, 0, 2, 3, 4, 5} - state action_hit_list_times: int[] = { - 0, - 0, - 400 msec, - 400 msec, - 800 msec, - 800 msec, - 800 msec, - 900 msec, - 900 msec - } - // Size = 9 - state action_hit_list_index: int = 0 + state times: int[] = { + 0, + 0, + 0, + 0, + 0, + 400 msec, + 400 msec, + 400 msec, + 400 msec, // List of the corresponding times. Size = 16 + 800 msec, + 800 msec, + 800 msec, + 800 msec, + 900 msec, + 900 msec, + 900 msec + } + // Size = 9 + state action_hit_list_microstep: int[] = {1, 2, 0, 1, 0, 2, 3, 4, 5} + state action_hit_list_times: int[] = { + 0, + 0, + 400 msec, + 400 msec, + 800 msec, + 800 msec, + 800 msec, + 900 msec, + 900 msec + } + // Size = 9 + state action_hit_list_index: int = 0 - reaction(startup) -> act {= - for (int i=0; i < 16; i++) { - _lf_schedule_at_tag(act->trigger, - (tag_t) { .time = self->times[i] + lf_time_logical(), .microstep = self->microstep_delay_list[i]}, - NULL); - } - =} + reaction(startup) -> act {= + for (int i=0; i < 16; i++) { + _lf_schedule_at_tag(act->trigger, + (tag_t) { .time = self->times[i] + lf_time_logical(), .microstep = self->microstep_delay_list[i]}, + NULL); + } + =} - reaction(act) {= - microstep_t microstep = lf_tag().microstep; - instant_t elapsed_time = lf_time_logical_elapsed(); - if (elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && - microstep == self->action_hit_list_microstep[self->action_hit_list_index]) { - self->action_hit_list_index++; - } - printf("Triggered at tag (%lld, %u).\n", elapsed_time, microstep); - =} + reaction(act) {= + microstep_t microstep = lf_tag().microstep; + instant_t elapsed_time = lf_time_logical_elapsed(); + if (elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && + microstep == self->action_hit_list_microstep[self->action_hit_list_index]) { + self->action_hit_list_index++; + } + printf("Triggered at tag (%lld, %u).\n", elapsed_time, microstep); + =} - reaction(shutdown) {= - if (self->action_hit_list_index != 9) { - fprintf(stderr, "ERROR: incorrect number of actions were correctly scheduled: %d.", self->action_hit_list_index); - exit(1); - } - printf("SUCCESS: successfully scheduled all the events.\n"); - =} + reaction(shutdown) {= + if (self->action_hit_list_index != 9) { + fprintf(stderr, "ERROR: incorrect number of actions were correctly scheduled: %d.", self->action_hit_list_index); + exit(1); + } + printf("SUCCESS: successfully scheduled all the events.\n"); + =} } main reactor ScheduleAt { - sender = new Scheduler() + sender = new Scheduler() } diff --git a/test/C/src/concurrent/ScheduleTwice.lf b/test/C/src/concurrent/ScheduleTwice.lf index e19f4d02d5..06a1c2c1cb 100644 --- a/test/C/src/concurrent/ScheduleTwice.lf +++ b/test/C/src/concurrent/ScheduleTwice.lf @@ -1,34 +1,34 @@ target C main reactor ScheduleTwice { - logical action a: int - state rc_count: int = 0 - preamble {= - #define VERBOSE - =} + logical action a: int + state rc_count: int = 0 + preamble {= + #define VERBOSE + =} - reaction(startup) -> a {= - lf_schedule_int(a, MSEC(100), 42); - lf_schedule_int(a, MSEC(100), 84); - =} + reaction(startup) -> a {= + lf_schedule_int(a, MSEC(100), 42); + lf_schedule_int(a, MSEC(100), 84); + =} - reaction(a) {= - printf("Received %d at tag(%lld, %u).\n", a->value, lf_time_logical_elapsed(), lf_tag().microstep); - if (lf_tag().microstep == 0 && a->value != 42) { - fprintf(stderr, "ERROR: Expected 42 at microstep 0.\n"); - exit(1); - } - if (lf_tag().microstep == 1 && a->value != 84) { - fprintf(stderr, "ERROR: Expected 84 at microstep 1.\n"); - exit(1); - } - self->rc_count++; - =} + reaction(a) {= + printf("Received %d at tag(%lld, %u).\n", a->value, lf_time_logical_elapsed(), lf_tag().microstep); + if (lf_tag().microstep == 0 && a->value != 42) { + fprintf(stderr, "ERROR: Expected 42 at microstep 0.\n"); + exit(1); + } + if (lf_tag().microstep == 1 && a->value != 84) { + fprintf(stderr, "ERROR: Expected 84 at microstep 1.\n"); + exit(1); + } + self->rc_count++; + =} - reaction(shutdown) {= - if (self->rc_count < 2) { - fprintf(stderr, "Didn't see two events.\n"); - exit(2); - } - =} + reaction(shutdown) {= + if (self->rc_count < 2) { + fprintf(stderr, "Didn't see two events.\n"); + exit(2); + } + =} } diff --git a/test/C/src/concurrent/ScheduleTwiceThreaded.lf b/test/C/src/concurrent/ScheduleTwiceThreaded.lf index 499e0e4999..d7e3d926f3 100644 --- a/test/C/src/concurrent/ScheduleTwiceThreaded.lf +++ b/test/C/src/concurrent/ScheduleTwiceThreaded.lf @@ -1,31 +1,31 @@ target C main reactor { - logical action a: int - state rc_count: int = 0 + logical action a: int + state rc_count: int = 0 - reaction(startup) -> a {= - lf_schedule_int(a, MSEC(100), 42); - lf_schedule_int(a, MSEC(100), 84); - =} + reaction(startup) -> a {= + lf_schedule_int(a, MSEC(100), 42); + lf_schedule_int(a, MSEC(100), 84); + =} - reaction(a) {= - printf("Received %d at tag(%lld, %u).\n", a->value, lf_time_logical_elapsed(), lf_tag().microstep); - if (lf_tag().microstep == 0 && a->value != 42) { - fprintf(stderr, "ERROR: Expected 42 at microstep 0.\n"); - exit(1); - } - if (lf_tag().microstep == 1 && a->value != 84) { - fprintf(stderr, "ERROR: Expected 84 at microstep 1.\n"); - exit(1); - } - self->rc_count++; - =} + reaction(a) {= + printf("Received %d at tag(%lld, %u).\n", a->value, lf_time_logical_elapsed(), lf_tag().microstep); + if (lf_tag().microstep == 0 && a->value != 42) { + fprintf(stderr, "ERROR: Expected 42 at microstep 0.\n"); + exit(1); + } + if (lf_tag().microstep == 1 && a->value != 84) { + fprintf(stderr, "ERROR: Expected 84 at microstep 1.\n"); + exit(1); + } + self->rc_count++; + =} - reaction(shutdown) {= - if (self->rc_count < 2) { - fprintf(stderr, "Didn't see two events.\n"); - exit(2); - } - =} + reaction(shutdown) {= + if (self->rc_count < 2) { + fprintf(stderr, "Didn't see two events.\n"); + exit(2); + } + =} } diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index e5185ecfc8..e651f0fc69 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -1,31 +1,31 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target C { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Printer { - input x: int - state count: int = 1 + input x: int + state count: int = 1 - reaction(x) {= - printf("Inside reactor received: %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d.\n", self->count); - exit(1); - } - self->count++; - =} + reaction(x) {= + printf("Inside reactor received: %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d.\n", self->count); + exit(1); + } + self->count++; + =} } main reactor SendingInsideThreaded { - state count: int = 0 - timer t(0, 1 sec) - p = new Printer() + state count: int = 0 + timer t(0, 1 sec) + p = new Printer() - reaction(t) -> p.x {= - (self->count)++; - lf_set(p.x, self->count); - =} + reaction(t) -> p.x {= + (self->count)++; + lf_set(p.x, self->count); + =} } diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index d1e78e5ced..5152b4daa0 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -1,69 +1,68 @@ /** - * Test that the starvation functionality in absence of the "keepalive: true" - * target property indeed works as expected. This version uses the threaded - * runtime. + * Test that the starvation functionality in absence of the "keepalive: true" target property indeed + * works as expected. This version uses the threaded runtime. * * @author Soroush Bateni */ target C reactor SuperDenseSender(number_of_iterations: int = 10) { - logical action loop - output out: int - state iterator: int = 0 + logical action loop + output out: int + state iterator: int = 0 - reaction(startup, loop) -> out {= - if (self->iterator < self->number_of_iterations) { - lf_schedule(loop, 0); - } - self->iterator++; - lf_set(out, 42); - =} + reaction(startup, loop) -> out {= + if (self->iterator < self->number_of_iterations) { + lf_schedule(loop, 0); + } + self->iterator++; + lf_set(out, 42); + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == lf_time_start() - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Sender successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - lf_time_start(), - current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == lf_time_start() + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Sender successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - lf_time_start(), + current_tag.microstep); + exit(1); + } + =} } reactor SuperDenseReceiver(number_of_iterations: int = 10) { - input in: int + input in: int - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("Received %d at tag (%lld, %u).\n", - in->value, - current_tag.time - lf_time_start(), - current_tag.microstep); - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("Received %d at tag (%lld, %u).\n", + in->value, + current_tag.time - lf_time_start(), + current_tag.microstep); + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == lf_time_start() - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Receiver successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - lf_time_start(), - current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == lf_time_start() + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Receiver successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - lf_time_start(), + current_tag.microstep); + exit(1); + } + =} } main reactor StarvationThreaded { - sender = new[8] SuperDenseSender() - receiver = new[8] SuperDenseReceiver() + sender = new[8] SuperDenseSender() + receiver = new[8] SuperDenseReceiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index 1deb1c4ff6..3c00bff39f 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -1,65 +1,65 @@ /** - * A test for the lf_request_stop() functionality in Lingua Franca. This version - * of the test is threaded. + * A test for the lf_request_stop() functionality in Lingua Franca. This version of the test is + * threaded. * * @author Soroush Bateni */ target C { - timeout: 11 msec, - build-type: RelWithDebInfo // logging: DEBUG + timeout: 11 msec, + build-type: RelWithDebInfo // logging: DEBUG } import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state reaction_invoked_correctly: bool = false + input in: int + state reaction_invoked_correctly: bool = false - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - // The reaction should not have been called at tags larger than (10 - // msec, 9) - char time[255]; - lf_print_error_and_exit("Invoked reaction(in) at tag (%llu, %d) which is bigger than shutdown.", - current_tag.time - lf_time_start(), current_tag.microstep); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { - // Call lf_request_stop() at relative tag (10 msec, 8) - lf_print("Requesting stop."); - lf_request_stop(); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { - // Check that this reaction is indeed also triggered at (10 msec, 9) - // printf("Reaction invoked.\n"); - self->reaction_invoked_correctly = true; - } - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + // The reaction should not have been called at tags larger than (10 + // msec, 9) + char time[255]; + lf_print_error_and_exit("Invoked reaction(in) at tag (%llu, %d) which is bigger than shutdown.", + current_tag.time - lf_time_start(), current_tag.microstep); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { + // Call lf_request_stop() at relative tag (10 msec, 8) + lf_print("Requesting stop."); + lf_request_stop(); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { + // Check that this reaction is indeed also triggered at (10 msec, 9) + // printf("Reaction invoked.\n"); + self->reaction_invoked_correctly = true; + } + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - lf_print("Shutdown invoked at tag (%lld, %u).", current_tag.time - lf_time_start(), current_tag.microstep); - // Check to see if shutdown is called at relative tag (10 msec, 9) - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && - self->reaction_invoked_correctly == true) { - lf_print("SUCCESS: successfully enforced stop."); - } else if(lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - lf_print_error_and_exit("Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.", - current_tag.time - lf_time_start(), current_tag.microstep); - } else if (self->reaction_invoked_correctly == false) { - // Check to see if reactions were called correctly - lf_print_error_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", - current_tag.time - lf_time_start(), current_tag.microstep); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + lf_print("Shutdown invoked at tag (%lld, %u).", current_tag.time - lf_time_start(), current_tag.microstep); + // Check to see if shutdown is called at relative tag (10 msec, 9) + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && + self->reaction_invoked_correctly == true) { + lf_print("SUCCESS: successfully enforced stop."); + } else if(lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + lf_print_error_and_exit("Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.", + current_tag.time - lf_time_start(), current_tag.microstep); + } else if (self->reaction_invoked_correctly == false) { + // Check to see if reactions were called correctly + lf_print_error_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", + current_tag.time - lf_time_start(), current_tag.microstep); + } + =} } main reactor { - consumer = new[4] Consumer() - producer = new[4] Sender(break_interval = 1 msec) + consumer = new[4] Consumer() + producer = new[4] Sender(break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index 7afd4b0069..80713d15ac 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -1,106 +1,105 @@ /** - * Test for lf_request_stop() at tag (0,0). This version uses the threaded - * runtime. + * Test for lf_request_stop() at tag (0,0). This version uses the threaded runtime. * * @author Soroush Bateni */ target C reactor Sender { - output out: int - state reaction_invoked_correctly: bool = false - timer t(0, 1 usec) - logical action act + output out: int + state reaction_invoked_correctly: bool = false + timer t(0, 1 usec) + logical action act - reaction(t) -> out, act {= - printf("Sending 42 at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - lf_schedule(act, 0); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } else if (lf_tag_compare(lf_tag(), one) > 0) { - fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - =} + reaction(t) -> out, act {= + printf("Sending 42 at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + lf_schedule(act, 0); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } else if (lf_tag_compare(lf_tag(), one) > 0) { + fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + =} - reaction(act) {= - // Reaction should be invoked at (0,1) - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), one) == 0) { - self->reaction_invoked_correctly = true; - } - =} + reaction(act) {= + // Reaction should be invoked at (0,1) + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), one) == 0) { + self->reaction_invoked_correctly = true; + } + =} - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Sender failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } else if (self->reaction_invoked_correctly == false) { - fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Sender failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } else if (self->reaction_invoked_correctly == false) { + fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } reactor Receiver { - input in: int + input in: int - reaction(in) {= - printf("Received %d at (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} + reaction(in) {= + printf("Received %d at (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} - reaction(shutdown) {= - // Shutdown events must occur at (0, 1) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + // Shutdown events must occur at (0, 1) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } main reactor StopZeroThreaded { - sender = new[4] Sender() - receiver = new[4] Receiver() + sender = new[4] Sender() + receiver = new[4] Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/concurrent/Threaded.lf b/test/C/src/concurrent/Threaded.lf index 01f67c1bd4..0b5f20a79c 100644 --- a/test/C/src/concurrent/Threaded.lf +++ b/test/C/src/concurrent/Threaded.lf @@ -1,67 +1,64 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded -// version, showing that without threads, this takes more than 800 msec to -// complete 200 msec of logical time. See ThreadedMultiport for a parameterized -// version of this. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing +// that without threads, this takes more than 800 msec to complete 200 msec of logical time. See +// ThreadedMultiport for a parameterized version of this. target C { - timeout: 2 sec, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "" + timeout: 2 sec, + flags: "" // Disable compiler optimization so that TakeTime actually takes time. } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor TakeTime { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < 100000000; i++) { - offset++; - } - lf_set(out, in->value + offset); - =} + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < 100000000; i++) { + offset++; + } + lf_set(out, in->value + offset); + =} } reactor Destination(width: int = 4) { - state s: int = 400000000 - input[width] in: int + state s: int = 400000000 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += in_width; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += in_width; + =} } main reactor(width: int = 4) { - a = new Source() - t = new[width] TakeTime() - (a.out)+ -> t.in - b = new Destination(width = width) - t.out -> b.in + a = new Source() + t = new[width] TakeTime() + (a.out)+ -> t.in + b = new Destination(width = width) + t.out -> b.in } diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index 2878393dac..b6bb6fbe8a 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -1,70 +1,69 @@ // Check multiport capabilities on Outputs. target C { - timeout: 2 sec, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "" + timeout: 2 sec, + flags: "" // Disable compiler optimization so that TakeTime actually takes time. } reactor Source(width: int = 4) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], self->s); - } - self->s++; - =} + reaction(t) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s); + } + self->s++; + =} } reactor Computation(iterations: int = 100000000) { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < self->iterations; i++) { - offset++; - } - lf_set(out, in->value + offset); - =} + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < self->iterations; i++) { + offset++; + } + lf_set(out, in->value + offset); + =} } reactor Destination(width: int = 4, iterations: int = 100000000) { - state s: int = 0 - input[width] in: int + state s: int = 0 + input[width] in: int - reaction(in) {= - int expected = self->iterations * self->width + self->s; - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != expected) { - printf("ERROR: Expected %d.\n", expected); - exit(1); - } - self->s += self->width; - =} + reaction(in) {= + int expected = self->iterations * self->width + self->s; + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != expected) { + printf("ERROR: Expected %d.\n", expected); + exit(1); + } + self->s += self->width; + =} - reaction(shutdown) {= - if (self->s == 0) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s == 0) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor ThreadedMultiport(width: int = 4, iterations: int = 100000000) { - a = new Source(width = width) - t = new[width] Computation(iterations = iterations) - b = new Destination(width = width, iterations = iterations) - a.out -> t.in - t.out -> b.in + a = new Source(width = width) + t = new[width] Computation(iterations = iterations) + b = new Destination(width = width, iterations = iterations) + a.out -> t.in + t.out -> b.in } diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 4037e8c193..b644256401 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -1,66 +1,64 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. See ThreadedMultiport for a -// parameterized version of this. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. See ThreadedMultiport for a parameterized version +// of this. target C { - timeout: 2 sec, - tracing: true, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "" + timeout: 2 sec, + tracing: true, + flags: "" // Disable compiler optimization so that TakeTime actually takes time. } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor TakeTime { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < 100000000; i++) { - offset++; - } - lf_set(out, in->value + offset); - =} + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < 100000000; i++) { + offset++; + } + lf_set(out, in->value + offset); + =} } reactor Destination(width: int = 4) { - state s: int = 400000000 - input[width] in: int + state s: int = 400000000 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += in_width; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += in_width; + =} } main reactor ThreadedThreaded(width: int = 4) { - a = new Source() - t = new[width] TakeTime() - (a.out)+ -> t.in - b = new Destination(width = width) - t.out -> b.in + a = new Source() + t = new[width] TakeTime() + (a.out)+ -> t.in + b = new Destination(width = width) + t.out -> b.in } diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index 8d3824af47..e1a08b06ab 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -1,48 +1,48 @@ -// Test that the stop function can be used to internally impose a a time limit. -// Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt. +// Test that the stop function can be used to internally impose a a time limit. Correct output for +// this 1, 2, 3, 4. Failure for this test is failing to halt. target C { - fast: true + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); + lf_set(y, self->count); + =} } reactor Destination { - input x: int - state s: int = 1 + input x: int + state s: int = 1 - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - printf("Error: Expected %d and got %d.\n", self->s, x->value); - exit(1); - } - self->s++; - =} + reaction(x) {= + // printf("%d\n", x->value); + if (x->value != self->s) { + printf("Error: Expected %d and got %d.\n", self->s, x->value); + exit(1); + } + self->s++; + =} - reaction(shutdown) {= - printf("**** shutdown reaction invoked.\n"); - if (self->s != 12) { - fprintf(stderr, "ERROR: Expected 12 but got %d.\n", self->s); - exit(1); - } - =} + reaction(shutdown) {= + printf("**** shutdown reaction invoked.\n"); + if (self->s != 12) { + fprintf(stderr, "ERROR: Expected 12 but got %d.\n", self->s); + exit(1); + } + =} } main reactor(period: time = 1 sec) { - timer stop(10 sec) - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + timer stop(10 sec) + c = new Clock(period = period) + d = new Destination() + c.y -> d.x - reaction(stop) {= lf_request_stop(); =} + reaction(stop) {= lf_request_stop(); =} } diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 82ef231ed9..fe733bef56 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -1,50 +1,49 @@ /** - * A test for the timeout functionality in Lingua Franca. This version of the - * test is threaded. + * A test for the timeout functionality in Lingua Franca. This version of the test is threaded. * * @author Soroush Bateni */ target C { - timeout: 11 msec + timeout: 11 msec } import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state success: bool = false + input in: int + state success: bool = false - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } + =} } main reactor { - consumer = new[4] Consumer() - producer = new[4] Sender(break_interval = 1 msec) + consumer = new[4] Consumer() + producer = new[4] Sender(break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index 7865b486a9..5a33aa3c4c 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -1,50 +1,50 @@ /** - * A test for the timeout functionality in Lingua Franca. This variant tests - * timeout at (0,0) and uses the threaded runtime. + * A test for the timeout functionality in Lingua Franca. This variant tests timeout at (0,0) and + * uses the threaded runtime. * * @author Soroush Bateni */ target C { - timeout: 0 sec + timeout: 0 sec } import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state success: bool = false + input in: int + state success: bool = false - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } - =} + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } + =} } main reactor { - consumer = new[4] Consumer() - producer = new[4] Sender(break_interval = 1 msec) + consumer = new[4] Consumer() + producer = new[4] Sender(break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index cbc4513732..25d0157ab5 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -1,99 +1,98 @@ // Version of ThreadedThreaded used to test tracing functions. target C { - timeout: 2 sec, - tracing: true, - // Disable compiler optimization so that TakeTime actually takes time. - flags: "", - logging: DEBUG + timeout: 2 sec, + tracing: true, + flags: "", // Disable compiler optimization so that TakeTime actually takes time. + logging: DEBUG } preamble {= - #include + #include =} reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor TakeTime(bank_index: int = 0) { - input in: int - output out: int - state event: char* = "No ID" + input in: int + output out: int + state event: char* = "No ID" - reaction(startup) {= - // Construct an id string for a user trace event. - const char* format = "Count completed by reactor %d."; - size_t length = strlen(format) + 2; - self->event = (char*)malloc(sizeof(char) * (length + 1)); - snprintf(self->event, length, format, self->bank_index); + reaction(startup) {= + // Construct an id string for a user trace event. + const char* format = "Count completed by reactor %d."; + size_t length = strlen(format) + 2; + self->event = (char*)malloc(sizeof(char) * (length + 1)); + snprintf(self->event, length, format, self->bank_index); - // Register the user trace event. - if (!register_user_trace_event(self->event)) { - fprintf(stderr, "ERROR: Failed to register trace event.\n"); - exit(1); - } - =} + // Register the user trace event. + if (!register_user_trace_event(self->event)) { + fprintf(stderr, "ERROR: Failed to register trace event.\n"); + exit(1); + } + =} - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < 100000000; i++) { - offset++; - } - tracepoint_user_event(self->event); - lf_set(out, in->value + offset); - =} + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < 100000000; i++) { + offset++; + } + tracepoint_user_event(self->event); + lf_set(out, in->value + offset); + =} - reaction(shutdown) {= - // NOTE: Can't actually free this because the tracepoint - // code runs after shutdown events are processed and the - // string id of the event may get corrupted. - // free(self->event); - =} + reaction(shutdown) {= + // NOTE: Can't actually free this because the tracepoint + // code runs after shutdown events are processed and the + // string id of the event may get corrupted. + // free(self->event); + =} } reactor Destination(width: int = 4) { - state s: int = 400000000 - state count: int = 0 - input[width] in: int + state s: int = 400000000 + state count: int = 0 + input[width] in: int - reaction(startup) {= - // Register the user value event. - if (!register_user_trace_event("Number of Destination invocations")) { - fprintf(stderr, "ERROR: Failed to register trace event.\n"); - exit(1); - } - =} + reaction(startup) {= + // Register the user value event. + if (!register_user_trace_event("Number of Destination invocations")) { + fprintf(stderr, "ERROR: Failed to register trace event.\n"); + exit(1); + } + =} - reaction(in) {= - self->count++; - tracepoint_user_value("Number of Destination invocations", self->count); - int sum = 0; - for (int i = 0; i < in_width; i++) { - sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += in_width; - =} + reaction(in) {= + self->count++; + tracepoint_user_value("Number of Destination invocations", self->count); + int sum = 0; + for (int i = 0; i < in_width; i++) { + sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += in_width; + =} } main reactor(width: int = 4) { - a = new Source() - t = new[width] TakeTime() - (a.out)+ -> t.in - b = new Destination(width = width) - t.out -> b.in + a = new Source() + t = new[width] TakeTime() + (a.out)+ -> t.in + b = new Destination(width = width) + t.out -> b.in } diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index 4a120c5e1e..d7f5fc2cdb 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -1,24 +1,21 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { - timeout: 5 sec, - logging: DEBUG, - coordination: centralized, - docker: true + timeout: 5 sec, + logging: DEBUG, + coordination: centralized, + docker: true } import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" -federated reactor DistributedCountContainerized( - offset: time = 200 msec -) at rti { - c = new Count() - p = new Print() - c.out -> p.in after offset +federated reactor DistributedCountContainerized(offset: time = 200 msec) at rti { + c = new Count() + p = new Print() + c.out -> p.in after offset } diff --git a/test/C/src/federated/BroadcastFeedback.lf b/test/C/src/federated/BroadcastFeedback.lf index 2bef908d2d..b1fa201ed5 100644 --- a/test/C/src/federated/BroadcastFeedback.lf +++ b/test/C/src/federated/BroadcastFeedback.lf @@ -1,33 +1,31 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target C { - timeout: 1 sec, - build-type: RelWithDebInfo + timeout: 1 sec, + build-type: RelWithDebInfo } reactor SenderAndReceiver { - output out: int - input[2] in: int - state received: bool = false + output out: int + input[2] in: int + state received: bool = false - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} - reaction(in) {= - if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { - lf_print("SUCCESS"); - self->received = true; - } - =} + reaction(in) {= + if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { + lf_print("SUCCESS"); + self->received = true; + } + =} - reaction(shutdown) {= - if (!self->received == true) { - lf_print_error_and_exit("Failed to receive broadcast"); - } - =} + reaction(shutdown) {= + if (!self->received == true) { + lf_print_error_and_exit("Failed to receive broadcast"); + } + =} } federated reactor { - s = new[2] SenderAndReceiver() - (s.out)+ -> s.in + s = new[2] SenderAndReceiver() + (s.out)+ -> s.in } diff --git a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf index d9edbc954b..fe269ce401 100644 --- a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -1,40 +1,38 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target C { - timeout: 1 sec + timeout: 1 sec } reactor SenderAndReceiver { - output out: int - input[2] in: int - state received: bool = false + output out: int + input[2] in: int + state received: bool = false - r = new Receiver() - in -> r.in + r = new Receiver() + in -> r.in - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} } reactor Receiver { - input[2] in: int - state received: bool = false + input[2] in: int + state received: bool = false - reaction(in) {= - if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { - lf_print("SUCCESS"); - self->received = true; - } - =} + reaction(in) {= + if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { + lf_print("SUCCESS"); + self->received = true; + } + =} - reaction(shutdown) {= - if (!self->received == true) { - lf_print_error_and_exit("Failed to receive broadcast"); - } - =} + reaction(shutdown) {= + if (!self->received == true) { + lf_print_error_and_exit("Failed to receive broadcast"); + } + =} } federated reactor { - s = new[2] SenderAndReceiver() - (s.out)+ -> s.in + s = new[2] SenderAndReceiver() + (s.out)+ -> s.in } diff --git a/test/C/src/federated/CycleDetection.lf b/test/C/src/federated/CycleDetection.lf index d22837bc1f..5e6b3b868d 100644 --- a/test/C/src/federated/CycleDetection.lf +++ b/test/C/src/federated/CycleDetection.lf @@ -1,58 +1,58 @@ /** - * Check whether the internally generated network and control reactions - * introduce a cycle or not. The failure for this test is not being compiled. + * Check whether the internally generated network and control reactions introduce a cycle or not. + * The failure for this test is not being compiled. * @author Edward A. Lee */ target C reactor CAReplica { - input local_update: int - input remote_update: int - input query: int + input local_update: int + input remote_update: int + input query: int - state balance: int = 0 + state balance: int = 0 - output response: int + output response: int - reaction(local_update, remote_update) {= - if (local_update->is_present) { - self->balance += local_update->value; - } - if (remote_update->is_present) { - self->balance += remote_update->value; - } - =} + reaction(local_update, remote_update) {= + if (local_update->is_present) { + self->balance += local_update->value; + } + if (remote_update->is_present) { + self->balance += remote_update->value; + } + =} - reaction(query) -> response {= lf_set(response, self->balance); =} + reaction(query) -> response {= lf_set(response, self->balance); =} } reactor UserInput { - input balance: int - output deposit: int + input balance: int + output deposit: int - reaction(startup) -> deposit {= lf_set(deposit, 100); =} + reaction(startup) -> deposit {= lf_set(deposit, 100); =} - reaction(balance) {= - if (balance->value != 200) { - lf_print_error_and_exit("Did not receive the expected balance. Expected: 200. Got: %d.", balance->value); - } - lf_print("Balance: %d", balance->value); - lf_request_stop(); - =} + reaction(balance) {= + if (balance->value != 200) { + lf_print_error_and_exit("Did not receive the expected balance. Expected: 200. Got: %d.", balance->value); + } + lf_print("Balance: %d", balance->value); + lf_request_stop(); + =} - reaction(shutdown) {= lf_print("Test passed!"); =} + reaction(shutdown) {= lf_print("Test passed!"); =} } federated reactor { - u1 = new UserInput() - r1 = new CAReplica() - u2 = new UserInput() - r2 = new CAReplica() - (u1.deposit)+ -> r1.query, r1.local_update - r1.response -> u1.balance - u1.deposit -> r2.remote_update - - (u2.deposit)+ -> r2.query, r2.local_update - r2.response -> u2.balance - u2.deposit -> r1.remote_update + u1 = new UserInput() + r1 = new CAReplica() + u2 = new UserInput() + r2 = new CAReplica() + (u1.deposit)+ -> r1.query, r1.local_update + r1.response -> u1.balance + u1.deposit -> r2.remote_update + + (u2.deposit)+ -> r2.query, r2.local_update + r2.response -> u2.balance + u2.deposit -> r1.remote_update } diff --git a/test/C/src/federated/DecentralizedP2PComm.lf b/test/C/src/federated/DecentralizedP2PComm.lf index 0ca6a10e6f..bb96cb32d2 100644 --- a/test/C/src/federated/DecentralizedP2PComm.lf +++ b/test/C/src/federated/DecentralizedP2PComm.lf @@ -1,52 +1,48 @@ target C { - timeout: 1 sec, - tracing: true, - clock-sync: off, - coordination: decentralized + timeout: 1 sec, + tracing: true, + clock-sync: off, + coordination: decentralized } -reactor Platform( - start: int = 0, - expected_start: int = 0, - stp_offset_param: time = 0 -) { - input in: int - output out: int - timer t(0, 100 msec) - state count: int = start - state expected: int = expected_start +reactor Platform(start: int = 0, expected_start: int = 0, stp_offset_param: time = 0) { + input in: int + output out: int + timer t(0, 100 msec) + state count: int = start + state expected: int = expected_start - reaction(t) -> out {= lf_set(out, self->count++); =} + reaction(t) -> out {= lf_set(out, self->count++); =} - reaction(in) {= - lf_print("Received %d.", in->value); - if (in->value != self->expected_start++) { - lf_print_error_and_exit("Expected %d but got %d.", - self->expected_start - 1, - in->value - ); - } - =} STP(stp_offset_param) {= - lf_print("Received %d late.", in->value); - tag_t current_tag = lf_tag(); - self->expected_start++; - lf_print_error("STP offset was violated by (%lld, %u).", - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->expected_start++) { + lf_print_error_and_exit("Expected %d but got %d.", + self->expected_start - 1, + in->value ); - =} + } + =} STP(stp_offset_param) {= + lf_print("Received %d late.", in->value); + tag_t current_tag = lf_tag(); + self->expected_start++; + lf_print_error("STP offset was violated by (%lld, %u).", + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep + ); + =} - reaction(shutdown) {= - lf_print("Shutdown invoked."); - if (self->expected == self->expected_start) { - lf_print_error_and_exit("Did not receive anything."); - } - =} + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->expected == self->expected_start) { + lf_print_error_and_exit("Did not receive anything."); + } + =} } federated reactor DecentralizedP2PComm { - a = new Platform(expected_start = 100, stp_offset_param = 10 msec) - b = new Platform(start = 100, stp_offset_param = 10 msec) - a.out -> b.in - b.out -> a.in + a = new Platform(expected_start = 100, stp_offset_param = 10 msec) + b = new Platform(start = 100, stp_offset_param = 10 msec) + a.out -> b.in + b.out -> a.in } diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 9dea4032aa..d6a372d56b 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -1,55 +1,52 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed about lost messages. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed about lost messages. * * The test fails if the federation does not exit. */ target C { - timeout: 1 msec, - coordination: decentralized + timeout: 1 msec, + coordination: decentralized } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - lf_print("Sending %d.", self->count); - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + lf_print("Sending %d.", self->count); + lf_set(y, self->count); + =} - reaction(shutdown) {= - lf_print("SUCCESS: the source exited successfully."); - =} + reaction(shutdown) {= lf_print("SUCCESS: the source exited successfully."); =} } reactor Destination { - input x: int - state s: int = 1 + input x: int + state s: int = 1 - reaction(x) {= - lf_print("Received %d", x->value); - tag_t current_tag = lf_tag(); - if (x->value != self->s) { - lf_print_error_and_exit("At tag (%lld, %u) expected %d and got %d.", - current_tag.time - lf_time_start(), current_tag.microstep, self->s, x->value - ); - } - self->s++; - =} + reaction(x) {= + lf_print("Received %d", x->value); + tag_t current_tag = lf_tag(); + if (x->value != self->s) { + lf_print_error_and_exit("At tag (%lld, %u) expected %d and got %d.", + current_tag.time - lf_time_start(), current_tag.microstep, self->s, x->value + ); + } + self->s++; + =} - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - lf_print("Approx. time per reaction: %lldns", lf_time_physical_elapsed()/(self->s+1)); - =} + reaction(shutdown) {= + lf_print("**** shutdown reaction invoked."); + lf_print("Approx. time per reaction: %lldns", lf_time_physical_elapsed()/(self->s+1)); + =} } federated reactor(period: time = 10 usec) { - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + c = new Clock(period = period) + d = new Destination() + c.y -> d.x } diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 8468e1dc81..bb3b6544c0 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -1,53 +1,50 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed. * - * The test fails if the federation does not exit amenably. This variant has a - * physical connection between source and destination. + * The test fails if the federation does not exit amenably. This variant has a physical connection + * between source and destination. */ target C { - timeout: 1 msec, - coordination: decentralized + timeout: 1 msec, + coordination: decentralized } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - (self->count)++; - //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); - lf_set(y, self->count); - =} + reaction(t) -> y {= + (self->count)++; + //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); + lf_set(y, self->count); + =} - reaction(shutdown) {= - lf_print("SUCCESS: the source exited successfully."); - =} + reaction(shutdown) {= lf_print("SUCCESS: the source exited successfully."); =} } reactor Destination { - input x: int - state s: int = 1 + input x: int + state s: int = 1 - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - lf_print_error_and_exit("Expected %d and got %d.", self->s, x->value); - } - self->s++; - =} + reaction(x) {= + // printf("%d\n", x->value); + if (x->value != self->s) { + lf_print_error_and_exit("Expected %d and got %d.", self->s, x->value); + } + self->s++; + =} - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - lf_print("Approx. time per reaction: %lldns", lf_time_physical_elapsed()/(self->s+1)); - =} + reaction(shutdown) {= + lf_print("**** shutdown reaction invoked."); + lf_print("Approx. time per reaction: %lldns", lf_time_physical_elapsed()/(self->s+1)); + =} } federated reactor(period: time = 10 usec) { - c = new Clock(period = period) - d = new Destination() - c.y ~> d.x + c = new Clock(period = period) + d = new Destination() + c.y ~> d.x } diff --git a/test/C/src/federated/DistributedBank.lf b/test/C/src/federated/DistributedBank.lf index 84acb00031..85bc8875b7 100644 --- a/test/C/src/federated/DistributedBank.lf +++ b/test/C/src/federated/DistributedBank.lf @@ -1,22 +1,22 @@ // Check bank of federates. target C { - timeout: 1 sec, - coordination: centralized + timeout: 1 sec, + coordination: centralized } reactor Node { - timer t(0, 100 msec) - state count: int = 0 + timer t(0, 100 msec) + state count: int = 0 - reaction(t) {= lf_print("Hello world %d.", self->count++); =} + reaction(t) {= lf_print("Hello world %d.", self->count++); =} - reaction(shutdown) {= - if (self->count == 0) { - lf_print_error_and_exit("Timer reactions did not execute."); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + lf_print_error_and_exit("Timer reactions did not execute."); + } + =} } federated reactor DistributedBank { - n = new[2] Node() + n = new[2] Node() } diff --git a/test/C/src/federated/DistributedBankToMultiport.lf b/test/C/src/federated/DistributedBankToMultiport.lf index 796db0718e..fdc1b67b84 100644 --- a/test/C/src/federated/DistributedBankToMultiport.lf +++ b/test/C/src/federated/DistributedBankToMultiport.lf @@ -1,33 +1,33 @@ // Check multiport to bank connections between federates. target C { - timeout: 3 sec + timeout: 3 sec } import Count from "../lib/Count.lf" reactor Destination { - input[2] in: int - state count: int = 1 + input[2] in: int + state count: int = 1 - reaction(in) {= - for (int i = 0; i < in_width; i++) { - lf_print("Received %d.", in[i]->value); - if (self->count != in[i]->value) { - lf_print_error_and_exit("Expected %d.", self->count); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + lf_print("Received %d.", in[i]->value); + if (self->count != in[i]->value) { + lf_print_error_and_exit("Expected %d.", self->count); } - self->count++; - =} + } + self->count++; + =} - reaction(shutdown) {= - if (self->count == 0) { - lf_print_error_and_exit("No data received."); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + lf_print_error_and_exit("No data received."); + } + =} } federated reactor { - s = new[2] Count() - d = new Destination() - s.out -> d.in + s = new[2] Count() + d = new Destination() + s.out -> d.in } diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 2ebdda169a..9e1a1b2e93 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -1,42 +1,41 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { - timeout: 5 sec, - coordination: centralized + timeout: 5 sec, + coordination: centralized } import Count from "../lib/Count.lf" reactor Print { - input in: int - state c: int = 1 + input in: int + state c: int = 1 - reaction(in) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - lf_print("At time %lld, received %d", elapsed_time, in->value); - if (in->value != self->c) { - lf_print_error_and_exit("Expected to receive %d.", self->c); - } - if (elapsed_time != MSEC(200) + SEC(1) * (self->c - 1) ) { - lf_print_error_and_exit("Expected received time to be %lld.", MSEC(200) * self->c); - } - self->c++; - =} + reaction(in) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + lf_print("At time %lld, received %d", elapsed_time, in->value); + if (in->value != self->c) { + lf_print_error_and_exit("Expected to receive %d.", self->c); + } + if (elapsed_time != MSEC(200) + SEC(1) * (self->c - 1) ) { + lf_print_error_and_exit("Expected received time to be %lld.", MSEC(200) * self->c); + } + self->c++; + =} - reaction(shutdown) {= - if (self->c != 6) { - lf_print_error_and_exit("Expected to receive 5 items."); - } - =} + reaction(shutdown) {= + if (self->c != 6) { + lf_print_error_and_exit("Expected to receive 5 items."); + } + =} } federated reactor DistributedCount(offset: time = 200 msec) { - c = new Count() - p = new Print() - c.out -> p.in after offset + c = new Count() + p = new Print() + c.out -> p.in after offset } diff --git a/test/C/src/federated/DistributedCountDecentralized.lf b/test/C/src/federated/DistributedCountDecentralized.lf index 631dfab0c0..0b99861269 100644 --- a/test/C/src/federated/DistributedCountDecentralized.lf +++ b/test/C/src/federated/DistributedCountDecentralized.lf @@ -1,53 +1,51 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C { - timeout: 5 sec, - coordination: decentralized + timeout: 5 sec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor Print { - input in: int - state c: int = 1 + input in: int + state c: int = 1 - reaction(in) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("At tag (%lld, %u), received %d. " - "The original intended tag of the message was (%lld, %u).\n", - (long long int)elapsed_time, - lf_tag().microstep, - in->value, - (long long int)(in->intended_tag.time - lf_time_start()), - in->intended_tag.microstep); - if (in->value != self->c) { - printf("Expected to receive %d.\n", self->c); - exit(1); - } - if (elapsed_time != MSEC(200) + SEC(1) * (self->c - 1)) { - printf("Expected received time to be %lld.\n", MSEC(200) * self->c); - exit(3); - } - self->c++; - =} + reaction(in) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("At tag (%lld, %u), received %d. " + "The original intended tag of the message was (%lld, %u).\n", + (long long int)elapsed_time, + lf_tag().microstep, + in->value, + (long long int)(in->intended_tag.time - lf_time_start()), + in->intended_tag.microstep); + if (in->value != self->c) { + printf("Expected to receive %d.\n", self->c); + exit(1); + } + if (elapsed_time != MSEC(200) + SEC(1) * (self->c - 1)) { + printf("Expected received time to be %lld.\n", MSEC(200) * self->c); + exit(3); + } + self->c++; + =} - reaction(shutdown) {= - if (self->c != 6) { - fprintf(stderr, "Expected to receive 5 items.\n"); - exit(2); - } - printf("SUCCESS: Successfully received 5 items.\n"); - =} + reaction(shutdown) {= + if (self->c != 6) { + fprintf(stderr, "Expected to receive 5 items.\n"); + exit(2); + } + printf("SUCCESS: Successfully received 5 items.\n"); + =} } federated reactor DistributedCountDecentralized { - c = new Count() - p = new Print() - // Indicating a 'logical' connection with a large enough delay. - c.out -> p.in after 200 msec + c = new Count() + p = new Print() + c.out -> p.in after 200 msec // Indicating a 'logical' connection with a large enough delay. } diff --git a/test/C/src/federated/DistributedCountDecentralizedLate.lf b/test/C/src/federated/DistributedCountDecentralizedLate.lf index 878bc89796..d08edbdb52 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLate.lf @@ -1,66 +1,65 @@ /** - * Test a form of a distributed deterministic system where a federate that - * receives timestamped messages has a timer in addition to the messages as - * triggers. Therefore, careful coordination of the advancement of time using - * Ptides is needed. + * Test a form of a distributed deterministic system where a federate that receives timestamped + * messages has a timer in addition to the messages as triggers. Therefore, careful coordination of + * the advancement of time using Ptides is needed. * @author Edward A. Lee * @author Soroush Bateni */ target C { - timeout: 4900 msec, - coordination: decentralized + timeout: 4900 msec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor Print { - input in: int // STP () - state success: int = 0 // STP(in, 30 msec); - state success_stp_violation: int = 0 - // Force a timer to be invoke periodically to ensure logical time will - // advance in the absence of incoming messages. - timer t(0, 10 msec) - state c: int = 0 + input in: int // STP () + state success: int = 0 // STP(in, 30 msec); + state success_stp_violation: int = 0 + // Force a timer to be invoke periodically to ensure logical time will advance in the absence of + // incoming messages. + timer t(0, 10 msec) + state c: int = 0 - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep, - in->value, - in->intended_tag.time - lf_time_start(), - in->intended_tag.microstep); - if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, - (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { - self->success++; // Message was on-time - } - self->c++; - =} STP(0) {= - tag_t current_tag = lf_tag(); - printf("At tag (%lld, %u), message has violated the STP offset by (%lld, %u).\n", - current_tag.time - lf_time_start(), current_tag.microstep, - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); - self->success_stp_violation++; - self->c++; - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep, + in->value, + in->intended_tag.time - lf_time_start(), + in->intended_tag.microstep); + if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, + (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { + self->success++; // Message was on-time + } + self->c++; + =} STP(0) {= + tag_t current_tag = lf_tag(); + printf("At tag (%lld, %u), message has violated the STP offset by (%lld, %u).\n", + current_tag.time - lf_time_start(), current_tag.microstep, + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep); + self->success_stp_violation++; + self->c++; + =} - reaction(t) {= - // Do nothing. - =} + reaction(t) {= + // Do nothing. + =} - reaction(shutdown) {= - if ((self->success + self->success_stp_violation) != 5) { - fprintf(stderr, "Failed to detect STP violations in messages.\n"); - exit(1); - } else { - printf("Successfully detected STP violation (%d violations, %d on-time).\n", self->success_stp_violation, self->success); - } - =} + reaction(shutdown) {= + if ((self->success + self->success_stp_violation) != 5) { + fprintf(stderr, "Failed to detect STP violations in messages.\n"); + exit(1); + } else { + printf("Successfully detected STP violation (%d violations, %d on-time).\n", self->success_stp_violation, self->success); + } + =} } federated reactor { - c = new Count() - p = new Print() - c.out -> p.in // Indicating a 'logical' connection. + c = new Count() + p = new Print() + c.out -> p.in // Indicating a 'logical' connection. } diff --git a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf index 31ab87e110..baf267ca74 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -1,97 +1,92 @@ /** - * Test a form of a distributed deterministic system where a federate that - * receives timestamped messages has a timer in addition to the messages as - * triggers. Therefore, careful coordination of the advancement of time using - * Ptides is needed. In addition, this test shows that the STP violation of the - * reaction is passed down the hierarchy until it is handled. + * Test a form of a distributed deterministic system where a federate that receives timestamped + * messages has a timer in addition to the messages as triggers. Therefore, careful coordination of + * the advancement of time using Ptides is needed. In addition, this test shows that the STP + * violation of the reaction is passed down the hierarchy until it is handled. * * @author Edward A. Lee * @author Soroush Bateni */ target C { - timeout: 4900 msec, - coordination: decentralized + timeout: 4900 msec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor ImportantActuator { - input in: int - state success: int = 0 - state success_stp_violation: int = 0 - // Force a timer to be invoke periodically - timer t(0, 10 msec) - // to ensure logical time will advance in the absence of incoming messages. - state c: int = 0 + input in: int + state success: int = 0 + state success_stp_violation: int = 0 + timer t(0, 10 msec) // Force a timer to be invoke periodically + state c: int = 0 // to ensure logical time will advance in the absence of incoming messages. - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep, - in->value, - in->intended_tag.time - lf_time_start(), - in->intended_tag.microstep); - if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, - (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { - self->success++; // Message was on-time - } - self->c++; - =} STP(0) {= - tag_t current_tag = lf_tag(); - printf("Message violated STP offset by (%lld, %u).\n", - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); - self->success_stp_violation++; - self->c++; - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep, + in->value, + in->intended_tag.time - lf_time_start(), + in->intended_tag.microstep); + if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, + (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { + self->success++; // Message was on-time + } + self->c++; + =} STP(0) {= + tag_t current_tag = lf_tag(); + printf("Message violated STP offset by (%lld, %u).\n", + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep); + self->success_stp_violation++; + self->c++; + =} - reaction(t) {= - // Do nothing. - =} + reaction(t) {= + // Do nothing. + =} - reaction(shutdown) {= - if ((self->success + self->success_stp_violation) != 5) { - fprintf(stderr, "Failed to detect STP violations in messages.\n"); - exit(1); - } else { - printf("Successfully detected STP violations (%d violations, %d on-time).\n", self->success_stp_violation, self->success); - } - =} + reaction(shutdown) {= + if ((self->success + self->success_stp_violation) != 5) { + fprintf(stderr, "Failed to detect STP violations in messages.\n"); + exit(1); + } else { + printf("Successfully detected STP violations (%d violations, %d on-time).\n", self->success_stp_violation, self->success); + } + =} } reactor Print { - input in: int + input in: int - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", - current_tag.time - lf_time_start(), - current_tag.microstep, - in->value, - in->intended_tag.time - lf_time_start(), - in->intended_tag.microstep); - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", + current_tag.time - lf_time_start(), + current_tag.microstep, + in->value, + in->intended_tag.time - lf_time_start(), + in->intended_tag.microstep); + =} } reactor Receiver { - input in: int - // Force a timer to be invoke periodically - timer t(0, 10 msec) - // to ensure logical time will advance in the absence of incoming messages. - state c: int = 0 - p = new Print() - a = new ImportantActuator() - in -> p.in - in -> a.in + input in: int + timer t(0, 10 msec) // Force a timer to be invoke periodically + state c: int = 0 // to ensure logical time will advance in the absence of incoming messages. + p = new Print() + a = new ImportantActuator() + in -> p.in + in -> a.in - reaction(t) {= - // Do nothing. - =} + reaction(t) {= + // Do nothing. + =} } federated reactor { - c = new Count() - r = new Receiver() - c.out -> r.in // Indicating a 'logical' connection. + c = new Count() + r = new Receiver() + c.out -> r.in // Indicating a 'logical' connection. } diff --git a/test/C/src/federated/DistributedCountPhysical.lf b/test/C/src/federated/DistributedCountPhysical.lf index 9e1e15f775..9baa1dd1cc 100644 --- a/test/C/src/federated/DistributedCountPhysical.lf +++ b/test/C/src/federated/DistributedCountPhysical.lf @@ -1,57 +1,57 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni */ target C { - timeout: 1 sec + timeout: 1 sec } reactor Count { - timer t(200 msec, 1 sec) - state s: int = 0 - output out: int + timer t(200 msec, 1 sec) + state s: int = 0 + output out: int - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor Print { - input in: int - state c: int = 0 + input in: int + state c: int = 0 - reaction(in) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("At time %lld, received %d.\n", elapsed_time, in->value); - if (in->value != self->c) { - fprintf(stderr, "ERROR: Expected to receive %d.\n", self->c); - exit(1); - } - if (!(elapsed_time > (SEC(1) * self->c) + MSEC(200))) { - fprintf(stderr, "ERROR: Expected received time to be strictly greater than %lld. " - "Got %lld.\n", MSEC(200) * self->c, elapsed_time); - exit(3); - } - self->c++; - =} + reaction(in) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("At time %lld, received %d.\n", elapsed_time, in->value); + if (in->value != self->c) { + fprintf(stderr, "ERROR: Expected to receive %d.\n", self->c); + exit(1); + } + if (!(elapsed_time > (SEC(1) * self->c) + MSEC(200))) { + fprintf(stderr, "ERROR: Expected received time to be strictly greater than %lld. " + "Got %lld.\n", MSEC(200) * self->c, elapsed_time); + exit(3); + } + self->c++; + =} - reaction(shutdown) {= - if (self->c != 1) { - fprintf(stderr, "ERROR: Expected to receive 1 item. Received %d.\n", self->c); - exit(2); - } - printf("SUCCESS: Successfully received 1 item.\n"); - =} + reaction(shutdown) {= + if (self->c != 1) { + fprintf(stderr, "ERROR: Expected to receive 1 item. Received %d.\n", self->c); + exit(2); + } + printf("SUCCESS: Successfully received 1 item.\n"); + =} } federated reactor at localhost { - c = new Count() - p = new Print() - c.out ~> p.in // Indicating a 'physical' connection. + c = new Count() + p = new Print() + c.out ~> p.in // Indicating a 'physical' connection. } diff --git a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf index b0da42218a..9eb2a1acff 100644 --- a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,7 +1,7 @@ /** - * Test a distributed system where a federation receives messages only over - * connections that are marked 'physical' (using the ~> arrow) with an after - * delay. The receiver verifies that the after delay is correctly imposed. + * Test a distributed system where a federation receives messages only over connections that are + * marked 'physical' (using the ~> arrow) with an after delay. The receiver verifies that the after + * delay is correctly imposed. * * @author Edward A. Lee * @author Soroush Bateni @@ -11,41 +11,40 @@ target C import Count from "../lib/Count.lf" reactor Print { - input in: int - state c: int = 1 + input in: int + state c: int = 1 - reaction(in) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("At time " PRINTF_TIME ", received %d.\n", elapsed_time, in->value); - if (in->value != self->c) { - fprintf(stderr, "ERROR: Expected to receive %d.\n", self->c); - exit(1); - } - if (!(elapsed_time > MSEC(600))) { - fprintf(stderr, "ERROR: Expected received time to be strictly greater than " - PRINTF_TIME ".\n", MSEC(600) - ); - exit(3); - } - self->c++; - lf_request_stop(); - =} + reaction(in) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("At time " PRINTF_TIME ", received %d.\n", elapsed_time, in->value); + if (in->value != self->c) { + fprintf(stderr, "ERROR: Expected to receive %d.\n", self->c); + exit(1); + } + if (!(elapsed_time > MSEC(600))) { + fprintf(stderr, "ERROR: Expected received time to be strictly greater than " + PRINTF_TIME ".\n", MSEC(600) + ); + exit(3); + } + self->c++; + lf_request_stop(); + =} - reaction(shutdown) {= - if (self->c != 2) { - fprintf( - stderr, "ERROR: Expected to receive 1 item. Received %d.\n", - self->c - 1 - ); - exit(2); - } - printf("SUCCESS: Successfully received 1 item.\n"); - =} + reaction(shutdown) {= + if (self->c != 2) { + fprintf( + stderr, "ERROR: Expected to receive 1 item. Received %d.\n", + self->c - 1 + ); + exit(2); + } + printf("SUCCESS: Successfully received 1 item.\n"); + =} } federated reactor at localhost { - c = new Count(offset = 200 msec, period = 0) - p = new Print() - // Indicating a 'physical' connection with a 400 msec after delay. - c.out ~> p.in after 400 msec + c = new Count(offset = 200 msec, period = 0) + p = new Print() + c.out ~> p.in after 400 msec // Indicating a 'physical' connection with a 400 msec after delay. } diff --git a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf index e821e4fb70..581d0f9670 100644 --- a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,57 +1,57 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni */ target C { - timeout: 1 sec, - coordination: decentralized + timeout: 1 sec, + coordination: decentralized } reactor Count { - timer t(200 msec, 1 sec) - state s: int = 0 - output out: int + timer t(200 msec, 1 sec) + state s: int = 0 + output out: int - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor Print { - input in: int - state c: int = 0 + input in: int + state c: int = 0 - reaction(in) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - printf("At time %lld, received %d.\n", elapsed_time, in->value); - if (in->value != self->c) { - fprintf(stderr, "ERROR: Expected to receive %d.\n", self->c); - exit(1); - } - if (!(elapsed_time > (SEC(1) * self->c) + MSEC(200))) { - fprintf(stderr, "ERROR: Expected received time to be strictly greater than %lld.\n", MSEC(200) * self->c); - exit(3); - } - self->c++; - =} + reaction(in) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + printf("At time %lld, received %d.\n", elapsed_time, in->value); + if (in->value != self->c) { + fprintf(stderr, "ERROR: Expected to receive %d.\n", self->c); + exit(1); + } + if (!(elapsed_time > (SEC(1) * self->c) + MSEC(200))) { + fprintf(stderr, "ERROR: Expected received time to be strictly greater than %lld.\n", MSEC(200) * self->c); + exit(3); + } + self->c++; + =} - reaction(shutdown) {= - if (self->c != 1) { - fprintf(stderr, "ERROR: Expected to receive 1 item. Received %d.\n", self->c); - exit(2); - } - printf("SUCCESS: Successfully received 1 item.\n"); - =} + reaction(shutdown) {= + if (self->c != 1) { + fprintf(stderr, "ERROR: Expected to receive 1 item. Received %d.\n", self->c); + exit(2); + } + printf("SUCCESS: Successfully received 1 item.\n"); + =} } federated reactor at localhost { - c = new Count() - p = new Print() - c.out ~> p.in // Indicating a 'physical' connection. + c = new Count() + p = new Print() + c.out ~> p.in // Indicating a 'physical' connection. } diff --git a/test/C/src/federated/DistributedDoublePort.lf b/test/C/src/federated/DistributedDoublePort.lf index 87de1ddb28..e478f8c596 100644 --- a/test/C/src/federated/DistributedDoublePort.lf +++ b/test/C/src/federated/DistributedDoublePort.lf @@ -1,50 +1,47 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federate on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federate on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni */ target C { - timeout: 900 msec, - logging: DEBUG, - coordination: centralized + timeout: 900 msec, + logging: DEBUG, + coordination: centralized } import Count from "../lib/Count.lf" reactor CountMicrostep { - state count: int = 1 - output out: int - logical action act: int - timer t(0, 1 sec) + state count: int = 1 + output out: int + logical action act: int + timer t(0, 1 sec) - reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} + reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} - reaction(act) -> out {= lf_set(out, act->value); =} + reaction(act) -> out {= lf_set(out, act->value); =} } reactor Print { - input in: int - input in2: int - - reaction(in, in2) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - lf_print("At tag (%lld, %u), received in = %d and in2 = %d.", elapsed_time, lf_tag().microstep, in->value, in2->value); - if (in->is_present && in2->is_present) { - lf_print_error_and_exit("ERROR: invalid logical simultaneity."); - } - =} - - reaction(shutdown) {= - lf_print("SUCCESS: messages were at least one microstep apart."); - =} + input in: int + input in2: int + + reaction(in, in2) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + lf_print("At tag (%lld, %u), received in = %d and in2 = %d.", elapsed_time, lf_tag().microstep, in->value, in2->value); + if (in->is_present && in2->is_present) { + lf_print_error_and_exit("ERROR: invalid logical simultaneity."); + } + =} + + reaction(shutdown) {= lf_print("SUCCESS: messages were at least one microstep apart."); =} } federated reactor DistributedDoublePort { - c = new Count() - cm = new CountMicrostep() - p = new Print() - c.out -> p.in // Indicating a 'logical' connection. - cm.out -> p.in2 + c = new Count() + cm = new CountMicrostep() + p = new Print() + c.out -> p.in // Indicating a 'logical' connection. + cm.out -> p.in2 } diff --git a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf index acbbaf4035..87dd86229e 100644 --- a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf @@ -1,62 +1,62 @@ /** - * Test that a rapidly produced logical action in an upstream federate can be - * properly handled in a long chain of federates. + * Test that a rapidly produced logical action in an upstream federate can be properly handled in a + * long chain of federates. */ target C { - timeout: 1 msec + timeout: 1 msec } import PassThrough from "../lib/PassThrough.lf" import TestCount from "../lib/TestCount.lf" reactor WithLogicalAction { - output out: int - state thread_id: lf_thread_t = 0 - state counter: int = 1 - logical action act(0): int + output out: int + state thread_id: lf_thread_t = 0 + state counter: int = 1 + logical action act(0): int - reaction(startup, act) -> act, out {= - lf_set(out, self->counter); - lf_schedule_int(act, USEC(50), self->counter++); - =} + reaction(startup, act) -> act, out {= + lf_set(out, self->counter); + lf_schedule_int(act, USEC(50), self->counter++); + =} } federated reactor { - a = new WithLogicalAction() - test = new TestCount(num_inputs = 21) + a = new WithLogicalAction() + test = new TestCount(num_inputs = 21) - passThroughs1 = new PassThrough() - passThroughs2 = new PassThrough() - passThroughs3 = new PassThrough() - passThroughs4 = new PassThrough() - passThroughs5 = new PassThrough() - passThroughs6 = new PassThrough() - passThroughs7 = new PassThrough() - passThroughs8 = new PassThrough() - passThroughs9 = new PassThrough() - passThroughs10 = new PassThrough() + passThroughs1 = new PassThrough() + passThroughs2 = new PassThrough() + passThroughs3 = new PassThrough() + passThroughs4 = new PassThrough() + passThroughs5 = new PassThrough() + passThroughs6 = new PassThrough() + passThroughs7 = new PassThrough() + passThroughs8 = new PassThrough() + passThroughs9 = new PassThrough() + passThroughs10 = new PassThrough() - a.out, - passThroughs1.out, - passThroughs2.out, - passThroughs3.out, - passThroughs4.out, - passThroughs5.out, - passThroughs6.out, - passThroughs7.out, - passThroughs8.out, - passThroughs9.out, - passThroughs10.out - -> - passThroughs1.in, - passThroughs2.in, - passThroughs3.in, - passThroughs4.in, - passThroughs5.in, - passThroughs6.in, - passThroughs7.in, - passThroughs8.in, - passThroughs9.in, - passThroughs10.in, - test.in + a.out, + passThroughs1.out, + passThroughs2.out, + passThroughs3.out, + passThroughs4.out, + passThroughs5.out, + passThroughs6.out, + passThroughs7.out, + passThroughs8.out, + passThroughs9.out, + passThroughs10.out + -> + passThroughs1.in, + passThroughs2.in, + passThroughs3.in, + passThroughs4.in, + passThroughs5.in, + passThroughs6.in, + passThroughs7.in, + passThroughs8.in, + passThroughs9.in, + passThroughs10.in, + test.in } diff --git a/test/C/src/federated/DistributedLoopedAction.lf b/test/C/src/federated/DistributedLoopedAction.lf index 8218e73646..db26c1b462 100644 --- a/test/C/src/federated/DistributedLoopedAction.lf +++ b/test/C/src/federated/DistributedLoopedAction.lf @@ -1,67 +1,62 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni */ target C { - timeout: 1 sec + timeout: 1 sec } import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver( - take_a_break_after: int = 10, - break_interval: time = 400 msec -) { - input in: int - state received_messages: int = 0 - state total_received_messages: int = 0 - state breaks: int = 0 - timer t(0, 1 msec) // This will impact the performance - - // but forces the logical time to advance Comment this line for a more - // sensible log output. - reaction(in) {= - printf("At tag (%lld, %u) received value %d.\n", - lf_time_logical_elapsed(), - lf_tag().microstep, - in->value); - self->total_received_messages++; - if (in->value != self->received_messages++) { - fprintf(stderr,"ERROR: received messages out of order.\n"); - // exit(1); - } - if (lf_time_logical_elapsed() != self->breaks * self->break_interval) { - fprintf(stderr,"ERROR: received messages at an incorrect time: %lld.\n", lf_time_logical_elapsed()); - // exit(2); - } - - if (self->received_messages == self->take_a_break_after) { - // Sender is taking a break; - self->breaks++; - self->received_messages = 0; - } - =} - - reaction(t) {= - // Do nothing - =} - - reaction(shutdown) {= - if (self->breaks != 3 || - (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) - ) { - fprintf(stderr,"ERROR: test failed.\n"); - exit(4); - } - printf("SUCCESS: Successfully received all messages from the sender.\n"); - =} +reactor Receiver(take_a_break_after: int = 10, break_interval: time = 400 msec) { + input in: int + state received_messages: int = 0 + state total_received_messages: int = 0 + state breaks: int = 0 + timer t(0, 1 msec) // This will impact the performance + + // but forces the logical time to advance Comment this line for a more sensible log output. + reaction(in) {= + printf("At tag (%lld, %u) received value %d.\n", + lf_time_logical_elapsed(), + lf_tag().microstep, + in->value); + self->total_received_messages++; + if (in->value != self->received_messages++) { + fprintf(stderr,"ERROR: received messages out of order.\n"); + // exit(1); + } + if (lf_time_logical_elapsed() != self->breaks * self->break_interval) { + fprintf(stderr,"ERROR: received messages at an incorrect time: %lld.\n", lf_time_logical_elapsed()); + // exit(2); + } + + if (self->received_messages == self->take_a_break_after) { + // Sender is taking a break; + self->breaks++; + self->received_messages = 0; + } + =} + + reaction(t) {= + // Do nothing + =} + + reaction(shutdown) {= + if (self->breaks != 3 || + (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) + ) { + fprintf(stderr,"ERROR: test failed.\n"); + exit(4); + } + printf("SUCCESS: Successfully received all messages from the sender.\n"); + =} } federated reactor DistributedLoopedAction { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index 17842809fa..0d364f026d 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -1,125 +1,117 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. The purpose of this test is to check whether the - * functionalities pertinent to dynamic STP offset adjustments are present and - * functioning to a degree. + * Test a sender-receiver network system that relies on microsteps being taken into account. The + * purpose of this test is to check whether the functionalities pertinent to dynamic STP offset + * adjustments are present and functioning to a degree. * - * This version of the test does not use a centralized coordinator to advance - * tag. Therefore, the receiver will rely on an STP offset (initially zero) to - * wait long enough for messages to arrive before advancing its tag. In this - * test, the STP offset is initially zero and gradually raised every time an STP - * violation is perceived until no STP violation is observed. Therefore, the - * exact outcome of the test will depend on actual runtime timing. + * This version of the test does not use a centralized coordinator to advance tag. Therefore, the + * receiver will rely on an STP offset (initially zero) to wait long enough for messages to arrive + * before advancing its tag. In this test, the STP offset is initially zero and gradually raised + * every time an STP violation is perceived until no STP violation is observed. Therefore, the exact + * outcome of the test will depend on actual runtime timing. * * @author Soroush Bateni */ target C { - timeout: 1 sec, - coordination: decentralized + timeout: 1 sec, + coordination: decentralized } import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver( - take_a_break_after: int = 10, - break_interval: time = 400 msec -) { - input in: int - state received_messages: int = 0 - state total_received_messages: int = 0 - state breaks: int = 0 +reactor Receiver(take_a_break_after: int = 10, break_interval: time = 400 msec) { + input in: int + state received_messages: int = 0 + state total_received_messages: int = 0 + state breaks: int = 0 - reaction(in) {= - tag_t current_tag = lf_tag(); - lf_print("At tag (%lld, %u) received value %d with STP violation (%lld, %u).", - current_tag.time - lf_time_start(), - current_tag.microstep, - in->value, - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep - ); - self->total_received_messages++; - if (in->value != lf_tag().microstep) { - lf_print_warning("Received incorrect value %d. Expected %d.", in->value, lf_tag().microstep); - // exit(1); // The receiver should tolerate this type of error - // in this test because messages on the network can - // arrive late. Note that with an accurate STP offset, - // this type of error should be extremely rare. + reaction(in) {= + tag_t current_tag = lf_tag(); + lf_print("At tag (%lld, %u) received value %d with STP violation (%lld, %u).", + current_tag.time - lf_time_start(), + current_tag.microstep, + in->value, + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep + ); + self->total_received_messages++; + if (in->value != lf_tag().microstep) { + lf_print_warning("Received incorrect value %d. Expected %d.", in->value, lf_tag().microstep); + // exit(1); // The receiver should tolerate this type of error + // in this test because messages on the network can + // arrive late. Note that with an accurate STP offset, + // this type of error should be extremely rare. - } - if (in->value != self->received_messages) { - lf_print_warning("Skipped expected value %d. Received value %d.", self->received_messages, in->value); - self->received_messages = in->value; - // exit(1); // The receiver should tolerate this type of error - // in this test because multiple messages arriving - // at a given tag (t, m) can overwrite each other. - // Because messages arrive in order, only the last - // value that is received on the port at a given tag - // can be observed. Note that with an accurate STP - // offset, this type of error should be extremely - // rare. - // FIXME: Messages should not be dropped or - // overwritten. - } - self->received_messages++; - if (self->received_messages == self->take_a_break_after) { - // Sender is taking a break; - self->breaks++; - self->received_messages = 0; - } - =} + } + if (in->value != self->received_messages) { + lf_print_warning("Skipped expected value %d. Received value %d.", self->received_messages, in->value); + self->received_messages = in->value; + // exit(1); // The receiver should tolerate this type of error + // in this test because multiple messages arriving + // at a given tag (t, m) can overwrite each other. + // Because messages arrive in order, only the last + // value that is received on the port at a given tag + // can be observed. Note that with an accurate STP + // offset, this type of error should be extremely + // rare. + // FIXME: Messages should not be dropped or + // overwritten. + } + self->received_messages++; + if (self->received_messages == self->take_a_break_after) { + // Sender is taking a break; + self->breaks++; + self->received_messages = 0; + } + =} - reaction(shutdown) {= - if (self->breaks != 3 || - (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) - ) { - lf_print_error_and_exit("Test failed. Breaks: %d, Messages: %d.", self->breaks, self->total_received_messages); - } - lf_print("SUCCESS: Successfully received all messages from the sender. Breaks: %d, Messages: %d.", self->breaks, self->total_received_messages); - =} + reaction(shutdown) {= + if (self->breaks != 3 || + (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) + ) { + lf_print_error_and_exit("Test failed. Breaks: %d, Messages: %d.", self->breaks, self->total_received_messages); + } + lf_print("SUCCESS: Successfully received all messages from the sender. Breaks: %d, Messages: %d.", self->breaks, self->total_received_messages); + =} } reactor STPReceiver( - take_a_break_after: int = 10, - break_interval: time = 400 msec, - stp_offset: time = 0 + take_a_break_after: int = 10, + break_interval: time = 400 msec, + stp_offset: time = 0 ) { - input in: int - state last_time_updated_stp: time = 0 - receiver = new Receiver(take_a_break_after = 10, break_interval = 400 msec) - timer t(0, 1 msec) // Force advancement of logical time + input in: int + state last_time_updated_stp: time = 0 + receiver = new Receiver(take_a_break_after = 10, break_interval = 400 msec) + timer t(0, 1 msec) // Force advancement of logical time - reaction(in) -> receiver.in {= - lf_print("Received %d.", in->value); - lf_set(receiver.in, in->value); - =} STP(stp_offset) {= - lf_print("Received %d late.", in->value); - tag_t current_tag = lf_tag(); - lf_print("STP violation of (%lld, %u) perceived on the input.", - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); - lf_set(receiver.in, in->value); - // Only update the STP offset once per - // time step. - if (current_tag.time != self->last_time_updated_stp) { - lf_print("Raising the STP offset by %lld.", MSEC(10)); - self->stp_offset += MSEC(10); - lf_set_stp_offset(MSEC(10)); - self->last_time_updated_stp = current_tag.time; - } - =} + reaction(in) -> receiver.in {= + lf_print("Received %d.", in->value); + lf_set(receiver.in, in->value); + =} STP(stp_offset) {= + lf_print("Received %d late.", in->value); + tag_t current_tag = lf_tag(); + lf_print("STP violation of (%lld, %u) perceived on the input.", + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep); + lf_set(receiver.in, in->value); + // Only update the STP offset once per + // time step. + if (current_tag.time != self->last_time_updated_stp) { + lf_print("Raising the STP offset by %lld.", MSEC(10)); + self->stp_offset += MSEC(10); + lf_set_stp_offset(MSEC(10)); + self->last_time_updated_stp = current_tag.time; + } + =} - reaction(t) {= - // Do nothing - =} + reaction(t) {= + // Do nothing + =} } federated reactor DistributedLoopedActionDecentralized { - sender = new Sender(take_a_break_after = 10, break_interval = 400 msec) - stpReceiver = new STPReceiver( - take_a_break_after = 10, - break_interval = 400 msec - ) + sender = new Sender(take_a_break_after = 10, break_interval = 400 msec) + stpReceiver = new STPReceiver(take_a_break_after = 10, break_interval = 400 msec) - sender.out -> stpReceiver.in + sender.out -> stpReceiver.in } diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index 454577ff35..dd7375cdb7 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -1,87 +1,82 @@ /** - * Test a sender-receiver network system that is similar to - * DistributedLoopedAction, but it uses a physical action rather than a logical - * action. This also demonstrates the advance-message-interval coordination - * option. This specifies the time period between Time Advance Notice (TAN) - * messages sent to the RTI (a form of null message that must be sent because of - * the physical action). The presence of this option also silences a warning - * about having a physical action that triggers an output. + * Test a sender-receiver network system that is similar to DistributedLoopedAction, but it uses a + * physical action rather than a logical action. This also demonstrates the advance-message-interval + * coordination option. This specifies the time period between Time Advance Notice (TAN) messages + * sent to the RTI (a form of null message that must be sent because of the physical action). The + * presence of this option also silences a warning about having a physical action that triggers an + * output. * * @author Soroush Bateni */ target C { - timeout: 1 sec, - coordination-options: { // Silences warning. - advance-message-interval: 10 msec - } + timeout: 1 sec, + coordination-options: { // Silences warning. + advance-message-interval: 10 msec + } } reactor Sender(take_a_break_after: int = 10, break_interval: time = 550 msec) { - output out: int - physical action act - state sent_messages: int = 0 + output out: int + physical action act + state sent_messages: int = 0 - reaction(startup, act) -> act, out {= - // Send a message on out - lf_set(out, self->sent_messages); - self->sent_messages++; - if (self->sent_messages < self->take_a_break_after) { - lf_schedule(act, 0); - } else { - // Take a break - self->sent_messages = 0; - lf_schedule(act, self->break_interval); - } - =} + reaction(startup, act) -> act, out {= + // Send a message on out + lf_set(out, self->sent_messages); + self->sent_messages++; + if (self->sent_messages < self->take_a_break_after) { + lf_schedule(act, 0); + } else { + // Take a break + self->sent_messages = 0; + lf_schedule(act, self->break_interval); + } + =} } -reactor Receiver( - take_a_break_after: int = 10, - break_interval: time = 550 msec -) { - input in: int - state received_messages: int = 0 - state total_received_messages: int = 0 - state breaks: int = 0 - timer t(0, 1 msec) // This will impact the performance +reactor Receiver(take_a_break_after: int = 10, break_interval: time = 550 msec) { + input in: int + state received_messages: int = 0 + state total_received_messages: int = 0 + state breaks: int = 0 + timer t(0, 1 msec) // This will impact the performance - // but forces the logical time to advance Comment this line for a more - // sensible log output. - reaction(in) {= - tag_t current_tag = lf_tag(); - lf_print("At tag (%lld, %u) received %d.", - current_tag.time - lf_time_start(), - current_tag.microstep, - in->value); - self->total_received_messages++; - if (in->value != self->received_messages++) { - lf_print_error_and_exit("Expected %d.", self->received_messages - 1); - } + // but forces the logical time to advance Comment this line for a more sensible log output. + reaction(in) {= + tag_t current_tag = lf_tag(); + lf_print("At tag (%lld, %u) received %d.", + current_tag.time - lf_time_start(), + current_tag.microstep, + in->value); + self->total_received_messages++; + if (in->value != self->received_messages++) { + lf_print_error_and_exit("Expected %d.", self->received_messages - 1); + } - if (self->received_messages == self->take_a_break_after) { - // Sender is taking a break; - self->breaks++; - self->received_messages = 0; - } - =} + if (self->received_messages == self->take_a_break_after) { + // Sender is taking a break; + self->breaks++; + self->received_messages = 0; + } + =} - reaction(t) {= - // Do nothing - =} + reaction(t) {= + // Do nothing + =} - reaction(shutdown) {= - if (self->breaks != 2 || - (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) - ) { - lf_print_error_and_exit("Test failed. Breaks: %d, Messages: %d.", self->breaks, self->total_received_messages); - } - lf_print("SUCCESS: Successfully received all messages from the sender."); - =} + reaction(shutdown) {= + if (self->breaks != 2 || + (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) + ) { + lf_print_error_and_exit("Test failed. Breaks: %d, Messages: %d.", self->breaks, self->total_received_messages); + } + lf_print("SUCCESS: Successfully received all messages from the sender."); + =} } federated reactor DistributedLoopedPhysicalAction { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedMultiport.lf b/test/C/src/federated/DistributedMultiport.lf index 3853629731..7590710339 100644 --- a/test/C/src/federated/DistributedMultiport.lf +++ b/test/C/src/federated/DistributedMultiport.lf @@ -1,45 +1,45 @@ // Check multiport connections between federates. target C { - timeout: 1 sec, - coordination: centralized + timeout: 1 sec, + coordination: centralized } reactor Source { - output[4] out: int - timer t(0, 100 msec) - state count: int = 0 + output[4] out: int + timer t(0, 100 msec) + state count: int = 0 - reaction(t) -> out {= - for (int i = 0; i < out_width; i++) { - lf_set(out[i], self->count++); - } - =} + reaction(t) -> out {= + for (int i = 0; i < out_width; i++) { + lf_set(out[i], self->count++); + } + =} } reactor Destination { - input[4] in: int - state count: int = 0 + input[4] in: int + state count: int = 0 - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - lf_print("Received %d.", in[i]->value); - if (in[i]->value != self->count++) { - lf_print_error_and_exit("Expected %d.", self->count - 1); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + lf_print("Received %d.", in[i]->value); + if (in[i]->value != self->count++) { + lf_print_error_and_exit("Expected %d.", self->count - 1); } } - =} + } + =} - reaction(shutdown) {= - if (self->count == 0) { - lf_print_error_and_exit("No data received."); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + lf_print_error_and_exit("No data received."); + } + =} } federated reactor DistributedMultiport { - s = new Source() - d = new Destination() - s.out -> d.in + s = new Source() + d = new Destination() + s.out -> d.in } diff --git a/test/C/src/federated/DistributedMultiportToBank.lf b/test/C/src/federated/DistributedMultiportToBank.lf index 0accaf8c60..c7a3b7dd5f 100644 --- a/test/C/src/federated/DistributedMultiportToBank.lf +++ b/test/C/src/federated/DistributedMultiportToBank.lf @@ -1,41 +1,41 @@ // Check multiport to bank connections between federates. target C { - timeout: 1 sec + timeout: 1 sec } reactor Source { - output[2] out: int - timer t(0, 100 msec) - state count: int = 0 + output[2] out: int + timer t(0, 100 msec) + state count: int = 0 - reaction(t) -> out {= - for (int i = 0; i < out_width; i++) { - lf_set(out[i], self->count); - } - self->count++; - =} + reaction(t) -> out {= + for (int i = 0; i < out_width; i++) { + lf_set(out[i], self->count); + } + self->count++; + =} } reactor Destination { - input in: int - state count: int = 0 + input in: int + state count: int = 0 - reaction(in) {= - lf_print("Received %d.", in->value); - if (self->count++ != in->value) { - lf_print_error_and_exit("Expected %d.", self->count - 1); - } - =} + reaction(in) {= + lf_print("Received %d.", in->value); + if (self->count++ != in->value) { + lf_print_error_and_exit("Expected %d.", self->count - 1); + } + =} - reaction(shutdown) {= - if (self->count == 0) { - lf_print_error_and_exit("No data received."); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + lf_print_error_and_exit("No data received."); + } + =} } federated reactor DistributedMultiportToBank { - s = new Source() - d = new[2] Destination() - s.out -> d.in + s = new Source() + d = new[2] Destination() + s.out -> d.in } diff --git a/test/C/src/federated/DistributedMultiportToken.lf b/test/C/src/federated/DistributedMultiportToken.lf index dfb791d861..821f48d17a 100644 --- a/test/C/src/federated/DistributedMultiportToken.lf +++ b/test/C/src/federated/DistributedMultiportToken.lf @@ -1,46 +1,46 @@ -// Check multiport connections between federates where the message is carried by -// a Token (in this case, with an array of char). +// Check multiport connections between federates where the message is carried by a Token (in this +// case, with an array of char). target C { - timeout: 1 sec, - coordination: centralized + timeout: 1 sec, + coordination: centralized } reactor Source { - output[4] out: char* - timer t(0, 200 msec) - state count: int = 0 + output[4] out: char* + timer t(0, 200 msec) + state count: int = 0 - reaction(t) -> out {= - for (int i = 0; i < out_width; i++) { - // With NULL, 0 arguments, snprintf tells us how many bytes are needed. - // Add one for the null terminator. - int length = snprintf(NULL, 0, "Hello %d", self->count) + 1; - // Dynamically allocate memory for the output. - SET_NEW_ARRAY(out[i], length); - // Populate the output string and increment the count. - snprintf(out[i]->value, length, "Hello %d", self->count++); - lf_print("MessageGenerator: At time %lld, send message: %s.", - lf_time_logical_elapsed(), - out[i]->value - ); - } - =} + reaction(t) -> out {= + for (int i = 0; i < out_width; i++) { + // With NULL, 0 arguments, snprintf tells us how many bytes are needed. + // Add one for the null terminator. + int length = snprintf(NULL, 0, "Hello %d", self->count) + 1; + // Dynamically allocate memory for the output. + SET_NEW_ARRAY(out[i], length); + // Populate the output string and increment the count. + snprintf(out[i]->value, length, "Hello %d", self->count++); + lf_print("MessageGenerator: At time %lld, send message: %s.", + lf_time_logical_elapsed(), + out[i]->value + ); + } + =} } reactor Destination { - input[4] in: char* + input[4] in: char* - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - lf_print("Received %s.", in[i]->value); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + lf_print("Received %s.", in[i]->value); } - =} + } + =} } federated reactor DistributedMultiportToken { - s = new Source() - d = new Destination() - s.out -> d.in + s = new Source() + d = new Destination() + s.out -> d.in } diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index 42f3da6134..851c363d77 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -1,76 +1,75 @@ /** * This is a test for send_timed_message, which is an internal API. * - * This test sends a second message at time 5 msec that has the same intended - * tag as a message that it had previously sent at time 0 msec. This results in - * a warning, but the message microstep is incremented and correctly received - * one microstep later. + * This test sends a second message at time 5 msec that has the same intended tag as a message that + * it had previously sent at time 0 msec. This results in a warning, but the message microstep is + * incremented and correctly received one microstep later. * * @author Soroush Bateni */ target C { - timeout: 1 sec, - build-type: RelWithDebInfo // Release with debug info + timeout: 1 sec, + build-type: RelWithDebInfo // Release with debug info } preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "federate.h" - #ifdef __cplusplus - } - #endif + #ifdef __cplusplus + extern "C" { + #endif + #include "federate.h" + #ifdef __cplusplus + } + #endif =} reactor Sender { - output out: int - timer t(0, 1 msec) + output out: int + timer t(0, 1 msec) - reaction(t) -> out {= - int payload = 1; - if (lf_time_logical_elapsed() == 0LL) { - send_timed_message(MSEC(10), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), - (unsigned char*)&payload); - } else if (lf_time_logical_elapsed() == MSEC(5)) { - payload = 2; - send_timed_message(MSEC(5), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), - (unsigned char*)&payload); - } - =} + reaction(t) -> out {= + int payload = 1; + if (lf_time_logical_elapsed() == 0LL) { + send_timed_message(MSEC(10), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + (unsigned char*)&payload); + } else if (lf_time_logical_elapsed() == MSEC(5)) { + payload = 2; + send_timed_message(MSEC(5), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + (unsigned char*)&payload); + } + =} } reactor Receiver { - input in: int - state success: int = 0 + input in: int + state success: int = 0 - reaction(in) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == (lf_time_start() + MSEC(10))) { - if (current_tag.microstep == 0 && in->value == 1) { - self->success++; - } else if (current_tag.microstep == 1 && in->value == 2) { - self->success++; - } + reaction(in) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == (lf_time_start() + MSEC(10))) { + if (current_tag.microstep == 0 && in->value == 1) { + self->success++; + } else if (current_tag.microstep == 1 && in->value == 2) { + self->success++; } - printf("Received %d at tag (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + } + printf("Received %d at tag (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + =} - reaction(shutdown) {= - if (self->success != 2) { - fprintf(stderr, "ERROR: Failed to receive messages.\n"); - exit(1); - } - printf("SUCCESS.\n"); - =} + reaction(shutdown) {= + if (self->success != 2) { + fprintf(stderr, "ERROR: Failed to receive messages.\n"); + exit(1); + } + printf("SUCCESS.\n"); + =} } federated reactor DistributedNetworkOrder { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedPhysicalActionUpstream.lf b/test/C/src/federated/DistributedPhysicalActionUpstream.lf index 520142b466..e4c8ad1e68 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstream.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstream.lf @@ -1,58 +1,58 @@ /** - * Test that a rapidly produced physical action in an upstream federate can be - * properly handled in federated execution. + * Test that a rapidly produced physical action in an upstream federate can be properly handled in + * federated execution. */ target C { - timeout: 10 secs, - coordination-options: { - advance-message-interval: 30 msec - } + timeout: 10 secs, + coordination-options: { + advance-message-interval: 30 msec + } } import PassThrough from "../lib/PassThrough.lf" import TestCount from "../lib/TestCount.lf" preamble {= - extern int _counter; - void callback(void *a); - void* take_time(void* a); + extern int _counter; + void callback(void *a); + void* take_time(void* a); =} reactor WithPhysicalAction { - preamble {= - int _counter = 1; - void callback(void *a) { - lf_schedule_int(a, 0, _counter++); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - while (_counter < 15) { - instant_t sleep_time = MSEC(10); - lf_sleep(sleep_time); - callback(a); - } - return NULL; + preamble {= + int _counter = 1; + void callback(void *a) { + lf_schedule_int(a, 0, _counter++); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + while (_counter < 15) { + instant_t sleep_time = MSEC(10); + lf_sleep(sleep_time); + callback(a); } - =} + return NULL; + } + =} - output out: int - state thread_id: lf_thread_t = 0 - physical action act(0): int + output out: int + state thread_id: lf_thread_t = 0 + physical action act(0): int - reaction(startup) -> act {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, act); - =} + reaction(startup) -> act {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, act); + =} - reaction(act) -> out {= lf_set(out, act->value); =} + reaction(act) -> out {= lf_set(out, act->value); =} } federated reactor { - a = new WithPhysicalAction() - m1 = new PassThrough() - m2 = new PassThrough() - test = new TestCount(num_inputs = 14) - a.out -> m1.in - m1.out -> m2.in - m2.out -> test.in + a = new WithPhysicalAction() + m1 = new PassThrough() + m2 = new PassThrough() + test = new TestCount(num_inputs = 14) + a.out -> m1.in + m1.out -> m2.in + m2.out -> test.in } diff --git a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf index 5cee1171cc..4fe2407b54 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf @@ -1,87 +1,87 @@ /** - * Test that a rapidly produced physical action in an upstream federate can be - * properly handled in a long chain of federates. + * Test that a rapidly produced physical action in an upstream federate can be properly handled in a + * long chain of federates. */ target C { - timeout: 1 sec, - coordination-options: { - advance-message-interval: 500 usec - } + timeout: 1 sec, + coordination-options: { + advance-message-interval: 500 usec + } } import PassThrough from "../lib/PassThrough.lf" import TestCount from "../lib/TestCount.lf" preamble {= - extern int _counter; - void callback(void *a); - void* take_time(void* a); + extern int _counter; + void callback(void *a); + void* take_time(void* a); =} reactor WithPhysicalAction { - preamble {= - int _counter = 1; - void callback(void *a) { - lf_schedule_int(a, 0, _counter++); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - while (_counter < 20) { - instant_t sleep_time = USEC(50); - lf_sleep(sleep_time); - callback(a); - } - return NULL; + preamble {= + int _counter = 1; + void callback(void *a) { + lf_schedule_int(a, 0, _counter++); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + while (_counter < 20) { + instant_t sleep_time = USEC(50); + lf_sleep(sleep_time); + callback(a); } - =} - output out: int - state thread_id: lf_thread_t = 0 - physical action act(0): int + return NULL; + } + =} + output out: int + state thread_id: lf_thread_t = 0 + physical action act(0): int - reaction(startup) -> act {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, act); - =} + reaction(startup) -> act {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, act); + =} - reaction(act) -> out {= lf_set(out, act->value); =} + reaction(act) -> out {= lf_set(out, act->value); =} } federated reactor { - a = new WithPhysicalAction() - test = new TestCount(num_inputs = 19) + a = new WithPhysicalAction() + test = new TestCount(num_inputs = 19) - passThroughs1 = new PassThrough() - passThroughs2 = new PassThrough() - passThroughs3 = new PassThrough() - passThroughs4 = new PassThrough() - passThroughs5 = new PassThrough() - passThroughs6 = new PassThrough() - passThroughs7 = new PassThrough() - passThroughs8 = new PassThrough() - passThroughs9 = new PassThrough() - passThroughs10 = new PassThrough() + passThroughs1 = new PassThrough() + passThroughs2 = new PassThrough() + passThroughs3 = new PassThrough() + passThroughs4 = new PassThrough() + passThroughs5 = new PassThrough() + passThroughs6 = new PassThrough() + passThroughs7 = new PassThrough() + passThroughs8 = new PassThrough() + passThroughs9 = new PassThrough() + passThroughs10 = new PassThrough() - a.out, - passThroughs1.out, - passThroughs2.out, - passThroughs3.out, - passThroughs4.out, - passThroughs5.out, - passThroughs6.out, - passThroughs7.out, - passThroughs8.out, - passThroughs9.out, - passThroughs10.out - -> - passThroughs1.in, - passThroughs2.in, - passThroughs3.in, - passThroughs4.in, - passThroughs5.in, - passThroughs6.in, - passThroughs7.in, - passThroughs8.in, - passThroughs9.in, - passThroughs10.in, - test.in + a.out, + passThroughs1.out, + passThroughs2.out, + passThroughs3.out, + passThroughs4.out, + passThroughs5.out, + passThroughs6.out, + passThroughs7.out, + passThroughs8.out, + passThroughs9.out, + passThroughs10.out + -> + passThroughs1.in, + passThroughs2.in, + passThroughs3.in, + passThroughs4.in, + passThroughs5.in, + passThroughs6.in, + passThroughs7.in, + passThroughs8.in, + passThroughs9.in, + passThroughs10.in, + test.in } diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index 2d4a616664..4af4685169 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -1,119 +1,118 @@ /** - * Test for lf_request_stop() in federated execution with centralized - * coordination. + * Test for lf_request_stop() in federated execution with centralized coordination. * * @author Soroush Bateni */ target C reactor Sender { - output out: int - timer t(0, 1 usec) - logical action act - state reaction_invoked_correctly: bool = false + output out: int + timer t(0, 1 usec) + logical action act + state reaction_invoked_correctly: bool = false - reaction(t, act) -> out, act {= - lf_print("Sending 42 at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - if (lf_tag().microstep == 0) { - // Instead of having a separate reaction - // for 'act' like Stop.lf, we trigger the - // same reaction to test lf_request_stop() being - // called multiple times - lf_schedule(act, 0); - } - if (lf_time_logical_elapsed() == USEC(1)) { - // Call lf_request_stop() both at (1 usec, 0) and - // (1 usec, 1) - lf_print("Requesting stop at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } + reaction(t, act) -> out, act {= + lf_print("Sending 42 at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + if (lf_tag().microstep == 0) { + // Instead of having a separate reaction + // for 'act' like Stop.lf, we trigger the + // same reaction to test lf_request_stop() being + // called multiple times + lf_schedule(act, 0); + } + if (lf_time_logical_elapsed() == USEC(1)) { + // Call lf_request_stop() both at (1 usec, 0) and + // (1 usec, 1) + lf_print("Requesting stop at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } - tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), _1usec1) == 0) { - // The reaction was invoked at (1 usec, 1) as expected - self->reaction_invoked_correctly = true; - } else if (lf_tag_compare(lf_tag(), _1usec1) > 0) { - // The reaction should not have been invoked at tags larger than (1 usec, 1) - lf_print_error_and_exit("ERROR: Invoked reaction(t, act) at tag bigger than shutdown."); - } - =} + tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), _1usec1) == 0) { + // The reaction was invoked at (1 usec, 1) as expected + self->reaction_invoked_correctly = true; + } else if (lf_tag_compare(lf_tag(), _1usec1) > 0) { + // The reaction should not have been invoked at tags larger than (1 usec, 1) + lf_print_error_and_exit("ERROR: Invoked reaction(t, act) at tag bigger than shutdown."); + } + =} - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(1) || - lf_tag().microstep != 1) { - lf_print_error_and_exit("ERROR: Sender failed to stop the federation in time. " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } else if (self->reaction_invoked_correctly == false) { - lf_print_error_and_exit("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } - lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(1) || + lf_tag().microstep != 1) { + lf_print_error_and_exit("ERROR: Sender failed to stop the federation in time. " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } else if (self->reaction_invoked_correctly == false) { + lf_print_error_and_exit("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } + lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } reactor Receiver( - stp_offset: time = 10 msec // Used in the decentralized variant of the test + stp_offset: time = 10 msec // Used in the decentralized variant of the test ) { - input in: int - state reaction_invoked_correctly: bool = false + input in: int + state reaction_invoked_correctly: bool = false - reaction(in) {= - lf_print("Received %d at (%lld, %u).", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - if (lf_time_logical_elapsed() == USEC(1)) { - lf_print("Requesting stop at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - // The receiver should receive a message at tag - // (1 usec, 1) and trigger this reaction - self->reaction_invoked_correctly = true; - } + reaction(in) {= + lf_print("Received %d at (%lld, %u).", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + if (lf_time_logical_elapsed() == USEC(1)) { + lf_print("Requesting stop at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + // The receiver should receive a message at tag + // (1 usec, 1) and trigger this reaction + self->reaction_invoked_correctly = true; + } - tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), _1usec1) > 0) { - self->reaction_invoked_correctly = false; - } - =} + tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), _1usec1) > 0) { + self->reaction_invoked_correctly = false; + } + =} - reaction(shutdown) {= - // Sender should have requested stop earlier than the receiver. - // Therefore, the shutdown events must occur at (1000, 0) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(1) || - lf_tag().microstep != 1) { - lf_print_error_and_exit("Receiver failed to stop the federation at the right time. " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } else if (self->reaction_invoked_correctly == false) { - lf_print_error_and_exit("Receiver reaction(in) was not invoked the correct number of times. " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } - lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} + reaction(shutdown) {= + // Sender should have requested stop earlier than the receiver. + // Therefore, the shutdown events must occur at (1000, 0) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(1) || + lf_tag().microstep != 1) { + lf_print_error_and_exit("Receiver failed to stop the federation at the right time. " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } else if (self->reaction_invoked_correctly == false) { + lf_print_error_and_exit("Receiver reaction(in) was not invoked the correct number of times. " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } + lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} } federated reactor DistributedStop { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in + sender.out -> receiver.in } diff --git a/test/C/src/federated/DistributedToken.lf b/test/C/src/federated/DistributedToken.lf index 1068bd5f85..14ce0b94e0 100644 --- a/test/C/src/federated/DistributedToken.lf +++ b/test/C/src/federated/DistributedToken.lf @@ -1,53 +1,50 @@ /** - * Distributed LF program where a MessageGenerator creates a string message that - * is sent via the RTI (runtime infrastructure) to a receiver that prints the - * message. The type is char*, so this tests the transport of token-encapsulated - * messages. Three executable programs are generated, Distributed, - * Distributed_Sender, and Distributed_Receiver. The RTI is realized in the - * first of these and is identified as a "launcher," so it launches the other - * two programs. + * Distributed LF program where a MessageGenerator creates a string message that is sent via the RTI + * (runtime infrastructure) to a receiver that prints the message. The type is char*, so this tests + * the transport of token-encapsulated messages. Three executable programs are generated, + * Distributed, Distributed_Sender, and Distributed_Receiver. The RTI is realized in the first of + * these and is identified as a "launcher," so it launches the other two programs. * - * This program uses a 'logical' connection -> with a STP violation handler, - * decentralized coordination, and an 'after' that is sufficiently large to get - * deterministic timestamps. Hence, it realizes a 'poor man's Ptides' that does - * not require clock synchronization nor HLA-style centralized control over the - * advancement of time. + * This program uses a 'logical' connection -> with a STP violation handler, decentralized + * coordination, and an 'after' that is sufficiently large to get deterministic timestamps. Hence, + * it realizes a 'poor man's Ptides' that does not require clock synchronization nor HLA-style + * centralized control over the advancement of time. * * @author Edward A. Lee */ target C { - timeout: 5 secs, - coordination: decentralized + timeout: 5 secs, + coordination: decentralized } /** - * Reactor that generates a sequence of messages, one per second. The message - * will be a string consisting of a root string followed by a count. + * Reactor that generates a sequence of messages, one per second. The message will be a string + * consisting of a root string followed by a count. * @param root The root string. * @output message The message. */ reactor MessageGenerator(root: string = "") { - // Output type char* instead of string is used for dynamically allocated - // character arrays (as opposed to static constant strings). - output message: char* - state count: int = 1 - // Send first message after 1 sec so that the startup reactions do not - // factor into the transport time measurement on the first message. - timer t(1 sec, 1 sec) + // Output type char* instead of string is used for dynamically allocated character arrays (as + // opposed to static constant strings). + output message: char* + state count: int = 1 + // Send first message after 1 sec so that the startup reactions do not factor into the transport + // time measurement on the first message. + timer t(1 sec, 1 sec) - reaction(t) -> message {= - // With NULL, 0 arguments, snprintf tells us how many bytes are needed. - // Add one for the null terminator. - int length = snprintf(NULL, 0, "%s %d", self->root, self->count) + 1; - // Dynamically allocate memory for the output. - SET_NEW_ARRAY(message, length); - // Populate the output string and increment the count. - snprintf(message->value, length, "%s %d", self->root, self->count++); - printf("MessageGenerator: At time %lld, send message: %s\n", - lf_time_logical_elapsed(), - message->value - ); - =} + reaction(t) -> message {= + // With NULL, 0 arguments, snprintf tells us how many bytes are needed. + // Add one for the null terminator. + int length = snprintf(NULL, 0, "%s %d", self->root, self->count) + 1; + // Dynamically allocate memory for the output. + SET_NEW_ARRAY(message, length); + // Populate the output string and increment the count. + snprintf(message->value, length, "%s %d", self->root, self->count++); + printf("MessageGenerator: At time %lld, send message: %s\n", + lf_time_logical_elapsed(), + message->value + ); + =} } /** @@ -56,48 +53,48 @@ reactor MessageGenerator(root: string = "") { * @input message The message. */ reactor PrintMessage { - input message: char* - state count: int = 0 + input message: char* + state count: int = 0 - reaction(message) {= - printf("PrintMessage: At (elapsed) logical time %lld, receiver receives: %s\n", - lf_time_logical_elapsed(), - message->value - ); - // Check the trailing number only of the message. - self->count++; - int trailing_number = atoi(&message->value[12]); - if (trailing_number != self->count) { - printf("ERROR: Expected message to be 'Hello World %d'.\n", self->count); - exit(1); - } - =} STP(0) {= - printf("PrintMessage: At (elapsed) tag (%lld, %u), receiver receives: %s\n" - "Original intended tag was (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep, - message->value, - message->intended_tag.time - lf_time_start(), - message->intended_tag.microstep); - // Check the trailing number only of the message. - self->count++; - int trailing_number = atoi(&message->value[12]); - if (trailing_number != self->count) { - printf("ERROR: Expected message to be 'Hello World %d'.\n", self->count); - exit(1); - } - =} + reaction(message) {= + printf("PrintMessage: At (elapsed) logical time %lld, receiver receives: %s\n", + lf_time_logical_elapsed(), + message->value + ); + // Check the trailing number only of the message. + self->count++; + int trailing_number = atoi(&message->value[12]); + if (trailing_number != self->count) { + printf("ERROR: Expected message to be 'Hello World %d'.\n", self->count); + exit(1); + } + =} STP(0) {= + printf("PrintMessage: At (elapsed) tag (%lld, %u), receiver receives: %s\n" + "Original intended tag was (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep, + message->value, + message->intended_tag.time - lf_time_start(), + message->intended_tag.microstep); + // Check the trailing number only of the message. + self->count++; + int trailing_number = atoi(&message->value[12]); + if (trailing_number != self->count) { + printf("ERROR: Expected message to be 'Hello World %d'.\n", self->count); + exit(1); + } + =} - reaction(shutdown) {= - if (self->count == 0) { - printf("ERROR: No messages received.\n"); - exit(2); - } - =} + reaction(shutdown) {= + if (self->count == 0) { + printf("ERROR: No messages received.\n"); + exit(2); + } + =} } federated reactor DistributedToken { - msg = new MessageGenerator(root = "Hello World") - dsp = new PrintMessage() - msg.message -> dsp.message after 40 msec + msg = new MessageGenerator(root = "Hello World") + dsp = new PrintMessage() + msg.message -> dsp.message after 40 msec } diff --git a/test/C/src/federated/FederatedFilePkgReader.lf b/test/C/src/federated/FederatedFilePkgReader.lf index 597ebbf96a..e4396b7783 100644 --- a/test/C/src/federated/FederatedFilePkgReader.lf +++ b/test/C/src/federated/FederatedFilePkgReader.lf @@ -1,57 +1,57 @@ /** Test reading a file at a location relative to the source file. */ target C { - timeout: 0 s + timeout: 0 s } reactor Source { - output out: char* // Use char*, not string, so memory is freed. - - reaction(startup) -> out {= - char* file_path = - LF_PACKAGE_DIRECTORY - LF_FILE_SEPARATOR "src" - LF_FILE_SEPARATOR "lib" - LF_FILE_SEPARATOR "FileReader.txt"; - - FILE* file = fopen(file_path, "rb"); - if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); - - // Determine the file size - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - // Allocate memory for the buffer - char* buffer = (char *) malloc(file_size + 1); - if (buffer == NULL) lf_print_error_and_exit("Out of memory."); - - // Read the file into the buffer - fread(buffer, file_size, 1, file); - buffer[file_size] = '\0'; - fclose(file); - - // For federated version, have to use lf_set_array so array size is know - // to the serializer. - lf_set_array(out, buffer, file_size + 1); - =} + output out: char* // Use char*, not string, so memory is freed. + + reaction(startup) -> out {= + char* file_path = + LF_PACKAGE_DIRECTORY + LF_FILE_SEPARATOR "src" + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + // For federated version, have to use lf_set_array so array size is know + // to the serializer. + lf_set_array(out, buffer, file_size + 1); + =} } reactor Check { - preamble {= - #include - =} - input in: char* - - reaction(in) {= - printf("Received: %s\n", in->value); - if (strcmp("Hello World", in->value) != 0) { - lf_print_error_and_exit("Expected 'Hello World'"); - } - =} + preamble {= + #include + =} + input in: char* + + reaction(in) {= + printf("Received: %s\n", in->value); + if (strcmp("Hello World", in->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} } federated reactor { - s = new Source() - c = new Check() - s.out -> c.in + s = new Source() + c = new Check() + s.out -> c.in } diff --git a/test/C/src/federated/FederatedFileReader.lf b/test/C/src/federated/FederatedFileReader.lf index 6ba2da763f..9a2534195a 100644 --- a/test/C/src/federated/FederatedFileReader.lf +++ b/test/C/src/federated/FederatedFileReader.lf @@ -1,57 +1,57 @@ /** Test reading a file at a location relative to the source file. */ target C { - timeout: 0 s + timeout: 0 s } reactor Source { - output out: char* // Use char*, not string, so memory is freed. - - reaction(startup) -> out {= - char* file_path = - LF_SOURCE_DIRECTORY - LF_FILE_SEPARATOR ".." - LF_FILE_SEPARATOR "lib" - LF_FILE_SEPARATOR "FileReader.txt"; - - FILE* file = fopen(file_path, "rb"); - if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); - - // Determine the file size - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - // Allocate memory for the buffer - char* buffer = (char *) malloc(file_size + 1); - if (buffer == NULL) lf_print_error_and_exit("Out of memory."); - - // Read the file into the buffer - fread(buffer, file_size, 1, file); - buffer[file_size] = '\0'; - fclose(file); - - // For federated version, have to use lf_set_array so array size is know - // to the serializer. - lf_set_array(out, buffer, file_size + 1); - =} + output out: char* // Use char*, not string, so memory is freed. + + reaction(startup) -> out {= + char* file_path = + LF_SOURCE_DIRECTORY + LF_FILE_SEPARATOR ".." + LF_FILE_SEPARATOR "lib" + LF_FILE_SEPARATOR "FileReader.txt"; + + FILE* file = fopen(file_path, "rb"); + if (file == NULL) lf_print_error_and_exit("Error opening file at path %s.", file_path); + + // Determine the file size + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the buffer + char* buffer = (char *) malloc(file_size + 1); + if (buffer == NULL) lf_print_error_and_exit("Out of memory."); + + // Read the file into the buffer + fread(buffer, file_size, 1, file); + buffer[file_size] = '\0'; + fclose(file); + + // For federated version, have to use lf_set_array so array size is know + // to the serializer. + lf_set_array(out, buffer, file_size + 1); + =} } reactor Check { - preamble {= - #include - =} - input in: char* - - reaction(in) {= - printf("Received: %s\n", in->value); - if (strcmp("Hello World", in->value) != 0) { - lf_print_error_and_exit("Expected 'Hello World'"); - } - =} + preamble {= + #include + =} + input in: char* + + reaction(in) {= + printf("Received: %s\n", in->value); + if (strcmp("Hello World", in->value) != 0) { + lf_print_error_and_exit("Expected 'Hello World'"); + } + =} } federated reactor { - s = new Source() - c = new Check() - s.out -> c.in + s = new Source() + c = new Check() + s.out -> c.in } diff --git a/test/C/src/federated/FeedbackDelay.lf b/test/C/src/federated/FeedbackDelay.lf index 997a4ad012..abfe5f1d6c 100644 --- a/test/C/src/federated/FeedbackDelay.lf +++ b/test/C/src/federated/FeedbackDelay.lf @@ -1,66 +1,66 @@ target C { - timeout: 1 sec, - logging: DEBUG + timeout: 1 sec, + logging: DEBUG } reactor PhysicalPlant { - input control: double - output sensor: double - timer t(0, 33 msec) - state last_sensor_time: time = 0 - state previous_sensor_time: time = 0 + input control: double + output sensor: double + timer t(0, 33 msec) + state last_sensor_time: time = 0 + state previous_sensor_time: time = 0 - reaction(t) -> sensor {= - lf_set(sensor, 42); - self->previous_sensor_time = self->last_sensor_time; - self->last_sensor_time = lf_time_physical(); - =} + reaction(t) -> sensor {= + lf_set(sensor, 42); + self->previous_sensor_time = self->last_sensor_time; + self->last_sensor_time = lf_time_physical(); + =} - reaction(control) {= - instant_t control_time = lf_time_physical(); - lf_print("Latency %lld.", control_time - self->previous_sensor_time); - lf_print("Logical time: %lld.", lf_time_logical_elapsed()); - =} STP(33 msec) {= lf_print_warning("STP violation."); =} + reaction(control) {= + instant_t control_time = lf_time_physical(); + lf_print("Latency %lld.", control_time - self->previous_sensor_time); + lf_print("Logical time: %lld.", lf_time_logical_elapsed()); + =} STP(33 msec) {= lf_print_warning("STP violation."); =} } reactor Controller { - input sensor: double - output control: double + input sensor: double + output control: double - state latest_control: double = 0.0 - state first: bool = true + state latest_control: double = 0.0 + state first: bool = true - output request_for_planning: double - input planning: double + output request_for_planning: double + input planning: double - reaction(planning) {= self->latest_control = planning->value; =} + reaction(planning) {= self->latest_control = planning->value; =} - reaction(sensor) -> control, request_for_planning {= - if (!self->first) { - lf_set(control, self->latest_control); - } - self->first = false; - lf_set(request_for_planning, sensor->value); - =} + reaction(sensor) -> control, request_for_planning {= + if (!self->first) { + lf_set(control, self->latest_control); + } + self->first = false; + lf_set(request_for_planning, sensor->value); + =} } reactor Planner { - input request: double - output response: double + input request: double + output response: double - reaction(request) -> response {= - lf_sleep(MSEC(10)); - lf_set(response, request->value); - =} + reaction(request) -> response {= + lf_sleep(MSEC(10)); + lf_set(response, request->value); + =} } federated reactor { - p = new PhysicalPlant() - c = new Controller() - pl = new Planner() + p = new PhysicalPlant() + c = new Controller() + pl = new Planner() - p.sensor -> c.sensor - c.request_for_planning -> pl.request - pl.response -> c.planning after 0 - c.control -> p.control + p.sensor -> c.sensor + c.request_for_planning -> pl.request + pl.response -> c.planning after 0 + c.control -> p.control } diff --git a/test/C/src/federated/FeedbackDelaySimple.lf b/test/C/src/federated/FeedbackDelaySimple.lf index 0c9b147cda..7f4756c49d 100644 --- a/test/C/src/federated/FeedbackDelaySimple.lf +++ b/test/C/src/federated/FeedbackDelaySimple.lf @@ -1,39 +1,39 @@ target C { - timeout: 1 sec + timeout: 1 sec } reactor Loop { - input in: int - output out: int - timer t(0, 100 msec) - state count: int = 1 + input in: int + output out: int + timer t(0, 100 msec) + state count: int = 1 - reaction(in) {= - lf_print("Received %d.", in->value); - if (in->value != self->count) { - lf_print_error_and_exit( - "Expected %d. Got %d.", - self->count, - in->value - ); - } - self->count++; - =} + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit( + "Expected %d. Got %d.", + self->count, + in->value + ); + } + self->count++; + =} - reaction(t) -> out {= lf_set(out, self->count); =} + reaction(t) -> out {= lf_set(out, self->count); =} - reaction(shutdown) {= - if (self->count != 11) { - lf_print_error_and_exit( - "Expected 11 messages. Got %d.", - self->count - ); - } - =} + reaction(shutdown) {= + if (self->count != 11) { + lf_print_error_and_exit( + "Expected 11 messages. Got %d.", + self->count + ); + } + =} } federated reactor { - l = new Loop() + l = new Loop() - l.out -> l.in after 0 + l.out -> l.in after 0 } diff --git a/test/C/src/federated/HelloDistributed.lf b/test/C/src/federated/HelloDistributed.lf index 909ce53b43..d2c4ea4c16 100644 --- a/test/C/src/federated/HelloDistributed.lf +++ b/test/C/src/federated/HelloDistributed.lf @@ -1,55 +1,52 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target C preamble {= - #include + #include =} reactor Source { - output out: string + output out: string - reaction(startup) -> out {= - lf_print("Sending 'Hello World!' message from source federate."); - lf_set(out, "Hello World!"); - lf_request_stop(); - =} + reaction(startup) -> out {= + lf_print("Sending 'Hello World!' message from source federate."); + lf_set(out, "Hello World!"); + lf_request_stop(); + =} } reactor Destination { - input in: string - state received: bool = false - - reaction(startup) {= lf_print("Destination started."); =} - - reaction(in) {= - lf_print("At logical time %lld, destination received: %s", lf_time_logical_elapsed(), in->value); - if (strcmp(in->value, "Hello World!") != 0) { - fprintf(stderr, "ERROR: Expected to receive 'Hello World!'\n"); - exit(1); - } - self->received = true; - =} - - reaction(shutdown) {= - lf_print("Shutdown invoked."); - if (!self->received) { - lf_print_error_and_exit("Destination did not receive the message."); - } - =} + input in: string + state received: bool = false + + reaction(startup) {= lf_print("Destination started."); =} + + reaction(in) {= + lf_print("At logical time %lld, destination received: %s", lf_time_logical_elapsed(), in->value); + if (strcmp(in->value, "Hello World!") != 0) { + fprintf(stderr, "ERROR: Expected to receive 'Hello World!'\n"); + exit(1); + } + self->received = true; + =} + + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (!self->received) { + lf_print_error_and_exit("Destination did not receive the message."); + } + =} } federated reactor HelloDistributed at localhost { - s = new Source() // Reactor s is in federate Source - d = new Destination() // Reactor d is in federate Destination - s.out -> d.in // This version preserves the timestamp. + s = new Source() // Reactor s is in federate Source + d = new Destination() // Reactor d is in federate Destination + s.out -> d.in // This version preserves the timestamp. - reaction(startup) {= - lf_print("Printing something in top-level federated reactor."); - =} + reaction(startup) {= lf_print("Printing something in top-level federated reactor."); =} } diff --git a/test/C/src/federated/LevelPattern.lf b/test/C/src/federated/LevelPattern.lf index 9f1ba16b7e..cdbcc46ffe 100644 --- a/test/C/src/federated/LevelPattern.lf +++ b/test/C/src/federated/LevelPattern.lf @@ -1,48 +1,48 @@ /** - * This test verifies that the artificial dependencies introduced by level-based - * scheduling do not, by themselves, introduce deadlocks in federated execution. + * This test verifies that the artificial dependencies introduced by level-based scheduling do not, + * by themselves, introduce deadlocks in federated execution. * * @author Edward A. Lee */ target C { - timeout: 1 s + timeout: 1 s } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" reactor Through { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } reactor A { - input in1: int - input in2: int - output out1: int - output out2: int + input in1: int + input in2: int + output out1: int + output out2: int - i1 = new Through() - i1.out -> out1 + i1 = new Through() + i1.out -> out1 - i2 = new Through() - i2.out -> out2 + i2 = new Through() + i2.out -> out2 - reaction(in1) -> i1.in {= lf_set(i1.in, in1->value); =} + reaction(in1) -> i1.in {= lf_set(i1.in, in1->value); =} - reaction(in2) -> i2.in {= lf_set(i2.in, in2->value); =} + reaction(in2) -> i2.in {= lf_set(i2.in, in2->value); =} } federated reactor { - c = new Count() - test = new TestCount(num_inputs = 2) - b = new A() - t = new Through() - - c.out -> b.in1 - b.out1 -> t.in - t.out -> b.in2 - b.out2 -> test.in + c = new Count() + test = new TestCount(num_inputs = 2) + b = new A() + t = new Through() + + c.out -> b.in1 + b.out1 -> t.in + t.out -> b.in2 + b.out2 -> test.in } diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index 7fdc972b5a..c8b08ee317 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -1,50 +1,49 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee */ target C { - flags: "-Wall", - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 4 sec, - logging: DEBUG + flags: "-Wall", + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 4 sec, + logging: DEBUG } reactor Looper(incr: int = 1, delay: time = 0 msec) { - input in: int - output out: int - physical action a(delay) - state count: int = 0 + input in: int + output out: int + physical action a(delay) + state count: int = 0 - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) -> out {= - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(t) -> out {= + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - if (self->count != 5 * self->incr) { - lf_print_error_and_exit("Failed to receive all five expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + if (self->count != 5 * self->incr) { + lf_print_error_and_exit("Failed to receive all five expected inputs."); + } + =} } federated reactor LoopDistributedCentralized(delay: time = 0) { - left = new Looper() - right = new Looper(incr = -1) - left.out -> right.in - right.out -> left.in + left = new Looper() + right = new Looper(incr = -1) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/federated/LoopDistributedCentralized2.lf b/test/C/src/federated/LoopDistributedCentralized2.lf index 82412e16fe..e83fc1e308 100644 --- a/test/C/src/federated/LoopDistributedCentralized2.lf +++ b/test/C/src/federated/LoopDistributedCentralized2.lf @@ -1,77 +1,76 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee */ target C { - flags: "-Wall", - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 4 sec + flags: "-Wall", + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 4 sec } reactor Looper(incr: int = 1, delay: time = 0 msec) { - input in: int - output out: int - physical action a(delay) - state count: int = 0 + input in: int + output out: int + physical action a(delay) + state count: int = 0 - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) -> out {= - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(t) -> out {= + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - if (self->count != 5 * self->incr) { - lf_print_error_and_exit("Failed to receive all five expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + if (self->count != 5 * self->incr) { + lf_print_error_and_exit("Failed to receive all five expected inputs."); + } + =} } reactor Looper2(incr: int = 1, delay: time = 0 msec) { - input in: int - output out: int - physical action a(delay) - state count: int = 0 + input in: int + output out: int + physical action a(delay) + state count: int = 0 - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} - reaction(t) -> out {= - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(t) -> out {= + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - if (self->count != 5 * self->incr) { - lf_print_error_and_exit("Failed to receive all five expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + if (self->count != 5 * self->incr) { + lf_print_error_and_exit("Failed to receive all five expected inputs."); + } + =} } federated reactor(delay: time = 0) { - left = new Looper() - right = new Looper2(incr = -1) - left.out -> right.in - right.out -> left.in + left = new Looper() + right = new Looper2(incr = -1) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf index b4501cd555..5b9d47fd88 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf @@ -1,74 +1,73 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee */ target C { - flags: "-Wall", - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 5 sec + flags: "-Wall", + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 5 sec } preamble {= - #include // Defines sleep() - extern bool stop; - void* ping(void* actionref); + #include // Defines sleep() + extern bool stop; + void* ping(void* actionref); =} reactor Looper(incr: int = 1, delay: time = 0 msec) { - preamble {= - bool stop = false; - // Thread to trigger an action once every second. - void* ping(void* actionref) { - while(!stop) { - lf_print("Scheduling action."); - lf_schedule(actionref, 0); - sleep(1); - } - return NULL; + preamble {= + bool stop = false; + // Thread to trigger an action once every second. + void* ping(void* actionref) { + while(!stop) { + lf_print("Scheduling action."); + lf_schedule(actionref, 0); + sleep(1); } - =} - input in: int - output out: int - physical action a(delay) - state count: int = 0 + return NULL; + } + =} + input in: int + output out: int + physical action a(delay) + state count: int = 0 - reaction(startup) -> a {= - // Start the thread that listens for Enter or Return. - lf_thread_t thread_id; - lf_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); - =} + reaction(startup) -> a {= + // Start the thread that listens for Enter or Return. + lf_thread_t thread_id; + lf_print("Starting thread."); + lf_thread_create(&thread_id, &ping, a); + =} - reaction(a) -> out {= - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(a) -> out {= + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - // Stop the thread that is scheduling actions. - stop = true; - if (self->count != 5 * self->incr) { - lf_print_error_and_exit("Failed to receive all five expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + // Stop the thread that is scheduling actions. + stop = true; + if (self->count != 5 * self->incr) { + lf_print_error_and_exit("Failed to receive all five expected inputs."); + } + =} } federated reactor(delay: time = 0) { - left = new Looper() - right = new Looper(incr = -1) - left.out -> right.in - right.out -> left.in + left = new Looper() + right = new Looper(incr = -1) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf index f9b088b7d1..9d4ed9e4fe 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf @@ -1,56 +1,56 @@ /** - * This tests that the precedence order of reaction invocation is kept when a - * feedback loop is present in centralized coordination. + * This tests that the precedence order of reaction invocation is kept when a feedback loop is + * present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni */ target C { - flags: "-Wall", - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 5 sec + flags: "-Wall", + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 5 sec } reactor Looper(incr: int = 1, delay: time = 0 msec) { - input in: int - output out: int - state count: int = 0 - state received_count: int = 0 - timer t(0, 1 sec) + input in: int + output out: int + state count: int = 0 + state received_count: int = 0 + timer t(0, 1 sec) - reaction(t) -> out {= - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(t) -> out {= + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - self->received_count = self->count; - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + self->received_count = self->count; + =} - reaction(t) {= - if (self->received_count != self->count) { - lf_print_error_and_exit("reaction(t) was invoked before reaction(in). Precedence order was not kept."); - } - =} + reaction(t) {= + if (self->received_count != self->count) { + lf_print_error_and_exit("reaction(t) was invoked before reaction(in). Precedence order was not kept."); + } + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - if (self->count != 6 * self->incr) { - lf_print_error_and_exit("Failed to receive all six expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + if (self->count != 6 * self->incr) { + lf_print_error_and_exit("Failed to receive all six expected inputs."); + } + =} } federated reactor(delay: time = 0) { - left = new Looper() - right = new Looper(incr = -1) - left.out -> right.in - right.out -> left.in + left = new Looper() + right = new Looper(incr = -1) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 17177aadb3..da6054251c 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,70 +1,69 @@ /** - * This tests that the precedence order of reaction invocation is kept in the - * hierarchy of reactors when a feedback loop is present in centralized - * coordination. + * This tests that the precedence order of reaction invocation is kept in the hierarchy of reactors + * when a feedback loop is present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni */ target C { - flags: "-Wall", - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 5 sec + flags: "-Wall", + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 5 sec } reactor Contained(incr: int = 1) { - timer t(0, 1 sec) - input in: int - state count: int = 0 - state received_count: int = 0 + timer t(0, 1 sec) + input in: int + state count: int = 0 + state received_count: int = 0 - reaction(t) {= self->count += self->incr; =} + reaction(t) {= self->count += self->incr; =} - reaction(in) {= self->received_count = self->count; =} + reaction(in) {= self->received_count = self->count; =} - reaction(t) {= - if (self->received_count != self->count) { - lf_print_error_and_exit("reaction(t) was invoked before reaction(in). Precedence order was not kept."); - } - =} + reaction(t) {= + if (self->received_count != self->count) { + lf_print_error_and_exit("reaction(t) was invoked before reaction(in). Precedence order was not kept."); + } + =} } reactor Looper(incr: int = 1, delay: time = 0 msec) { - input in: int - output out: int - state count: int = 0 - timer t(0, 1 sec) + input in: int + output out: int + state count: int = 0 + timer t(0, 1 sec) - c = new Contained(incr = incr) - in -> c.in + c = new Contained(incr = incr) + in -> c.in - reaction(t) -> out {= - lf_print("Sending network output %d", self->count); - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(t) -> out {= + lf_print("Sending network output %d", self->count); + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - if (self->count != 6 * self->incr) { - lf_print_error_and_exit("Failed to receive all six expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + if (self->count != 6 * self->incr) { + lf_print_error_and_exit("Failed to receive all six expected inputs."); + } + =} } federated reactor(delay: time = 0) { - left = new Looper() - right = new Looper(incr = -1) - left.out -> right.in - right.out -> left.in + left = new Looper() + right = new Looper(incr = -1) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index 4350c984b3..387ec55325 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -1,81 +1,80 @@ /** - * This tests a feedback loop with physical actions and decentralized - * coordination. + * This tests a feedback loop with physical actions and decentralized coordination. * * @author Edward A. Lee */ target C { - coordination: decentralized, - timeout: 5 sec + coordination: decentralized, + timeout: 5 sec } preamble {= - #include // Defines sleep() - extern bool stop; - void* ping(void* actionref); + #include // Defines sleep() + extern bool stop; + void* ping(void* actionref); =} reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { - preamble {= - bool stop = false; - // Thread to trigger an action once every second. - void* ping(void* actionref) { - while(!stop) { - lf_print("Scheduling action."); - lf_schedule(actionref, 0); - sleep(1); - } - return NULL; + preamble {= + bool stop = false; + // Thread to trigger an action once every second. + void* ping(void* actionref) { + while(!stop) { + lf_print("Scheduling action."); + lf_schedule(actionref, 0); + sleep(1); } - =} - input in: int - output out: int - physical action a(stp_offset) - state count: int = 0 + return NULL; + } + =} + input in: int + output out: int + physical action a(stp_offset) + state count: int = 0 - reaction(startup) -> a {= - // Start the thread that listens for Enter or Return. - lf_thread_t thread_id; - lf_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); - =} + reaction(startup) -> a {= + // Start the thread that listens for Enter or Return. + lf_thread_t thread_id; + lf_print("Starting thread."); + lf_thread_create(&thread_id, &ping, a); + =} - reaction(a) -> out {= - lf_print("Setting out."); - lf_set(out, self->count); - self->count += self->incr; - =} + reaction(a) -> out {= + lf_print("Setting out."); + lf_set(out, self->count); + self->count += self->incr; + =} - reaction(in) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} STP(stp_offset) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} deadline(10 msec) {= - instant_t time_lag = lf_time_physical() - lf_time_logical(); - char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 - lf_comma_separated_time(time_buffer, time_lag); - lf_print("Deadline miss. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} + reaction(in) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} STP(stp_offset) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} deadline(10 msec) {= + instant_t time_lag = lf_time_physical() - lf_time_logical(); + char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 + lf_comma_separated_time(time_buffer, time_lag); + lf_print("Deadline miss. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - // Stop the thread that is scheduling actions. - stop = true; - if (self->count != 5 * self->incr) { - lf_print_error_and_exit("Failed to receive all five expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + // Stop the thread that is scheduling actions. + stop = true; + if (self->count != 5 * self->incr) { + lf_print_error_and_exit("Failed to receive all five expected inputs."); + } + =} } federated reactor LoopDistributedDecentralized(delay: time = 0) { - left = new Looper(stp_offset = 900 usec) - right = new Looper(incr = -1, stp_offset = 2400 usec) - left.out -> right.in - right.out -> left.in + left = new Looper(stp_offset = 900 usec) + right = new Looper(incr = -1, stp_offset = 2400 usec) + left.out -> right.in + right.out -> left.in } diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 9a49b5bde8..69c84799c7 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -1,99 +1,98 @@ /** - * This tests a feedback loop with physical actions and centralized - * coordination. + * This tests a feedback loop with physical actions and centralized coordination. * * @author Edward A. Lee */ target C { - flags: "-Wall", - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 5 sec + flags: "-Wall", + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 5 sec } preamble {= - #include // Defines sleep() - extern bool stop; - void* ping(void* actionref); + #include // Defines sleep() + extern bool stop; + void* ping(void* actionref); =} reactor Looper(incr: int = 1, delay: time = 0 msec) { - preamble {= - bool stop = false; - // Thread to trigger an action once every second. - void* ping(void* actionref) { - while(!stop) { - lf_print("Scheduling action."); - lf_schedule(actionref, 0); - sleep(1); - } - return NULL; + preamble {= + bool stop = false; + // Thread to trigger an action once every second. + void* ping(void* actionref) { + while(!stop) { + lf_print("Scheduling action."); + lf_schedule(actionref, 0); + sleep(1); } - =} - input in: int - input in2: int - output out: int - output out2: int - physical action a(delay) - state count: int = 0 - timer t(0, 1 sec) + return NULL; + } + =} + input in: int + input in2: int + output out: int + output out2: int + physical action a(delay) + state count: int = 0 + timer t(0, 1 sec) - reaction(startup) -> a {= - // Start the thread that listens for Enter or Return. - lf_thread_t thread_id; - lf_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); - =} + reaction(startup) -> a {= + // Start the thread that listens for Enter or Return. + lf_thread_t thread_id; + lf_print("Starting thread."); + lf_thread_create(&thread_id, &ping, a); + =} - reaction(a) -> out, out2 {= - if (self->count%2 == 0) { - lf_set(out, self->count); - } else { - lf_set(out2, self->count); - } - self->count += self->incr; - =} + reaction(a) -> out, out2 {= + if (self->count%2 == 0) { + lf_set(out, self->count); + } else { + lf_set(out2, self->count); + } + self->count += self->incr; + =} - reaction(in) {= - tag_t current_tag = lf_tag(); - lf_print("Received %d at logical time (%lld, %d).", - in->value, - current_tag.time - lf_time_start(), current_tag.microstep - ); - =} + reaction(in) {= + tag_t current_tag = lf_tag(); + lf_print("Received %d at logical time (%lld, %d).", + in->value, + current_tag.time - lf_time_start(), current_tag.microstep + ); + =} - reaction(in2) {= - tag_t current_tag = lf_tag(); - lf_print("Received %d on in2 at logical time (%lld, %d).", - in2->value, - current_tag.time - lf_time_start(), current_tag.microstep - ); - =} + reaction(in2) {= + tag_t current_tag = lf_tag(); + lf_print("Received %d on in2 at logical time (%lld, %d).", + in2->value, + current_tag.time - lf_time_start(), current_tag.microstep + ); + =} - reaction(t) {= - tag_t current_tag = lf_tag(); - lf_print("Timer triggered at logical time (%lld, %d).", - current_tag.time - lf_time_start(), current_tag.microstep - ); - =} + reaction(t) {= + tag_t current_tag = lf_tag(); + lf_print("Timer triggered at logical time (%lld, %d).", + current_tag.time - lf_time_start(), current_tag.microstep + ); + =} - reaction(shutdown) {= - lf_print("******* Shutdown invoked."); - // Stop the thread that is scheduling actions. - stop = true; - if (self->count != 5 * self->incr) { - lf_print_error_and_exit("Failed to receive all five expected inputs."); - } - =} + reaction(shutdown) {= + lf_print("******* Shutdown invoked."); + // Stop the thread that is scheduling actions. + stop = true; + if (self->count != 5 * self->incr) { + lf_print_error_and_exit("Failed to receive all five expected inputs."); + } + =} } federated reactor(delay: time = 0) { - left = new Looper() - right = new Looper(incr = -1) - left.out -> right.in - right.out -> left.in - right.out2 -> left.in2 - left.out2 -> right.in2 + left = new Looper() + right = new Looper(incr = -1) + left.out -> right.in + right.out -> left.in + right.out2 -> left.in2 + left.out2 -> right.in2 } diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index 11b7a259cf..130ca02996 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -1,47 +1,44 @@ -/** - * This is a test that detects STP violations according to the physical time of - * message arrival. - */ +/** This is a test that detects STP violations according to the physical time of message arrival. */ target C { - timeout: 1900 msec, - coordination: decentralized + timeout: 1900 msec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor Print(STP_offset_param: time = 0) { - input in: int - state c: int = 1 + input in: int + state c: int = 1 - reaction(in) {= - interval_t elapsed_time = lf_time_logical_elapsed(); - lf_print("At time %lld, received %d", elapsed_time, in->value); - if (in->value != self->c) { - lf_print_error_and_exit("Expected to receive %d.", self->c); - } - instant_t STP_discrepency = lf_time_logical() + self->STP_offset_param - in->physical_time_of_arrival; - if (STP_discrepency < 0) { - lf_print("The message has violated the STP offset by %lld in physical time.", -1 * STP_discrepency); - self->c++; - } else { - lf_print_error_and_exit("Message arrived %lld early.", STP_discrepency); - } - =} STP(STP_offset_param) {= - // This STP handler should never be invoked because the only source of event - // for Print is the Count reactor. - lf_print_error_and_exit("Logical STP violation was detected. Only physical STP violations are possible."); - =} + reaction(in) {= + interval_t elapsed_time = lf_time_logical_elapsed(); + lf_print("At time %lld, received %d", elapsed_time, in->value); + if (in->value != self->c) { + lf_print_error_and_exit("Expected to receive %d.", self->c); + } + instant_t STP_discrepency = lf_time_logical() + self->STP_offset_param - in->physical_time_of_arrival; + if (STP_discrepency < 0) { + lf_print("The message has violated the STP offset by %lld in physical time.", -1 * STP_discrepency); + self->c++; + } else { + lf_print_error_and_exit("Message arrived %lld early.", STP_discrepency); + } + =} STP(STP_offset_param) {= + // This STP handler should never be invoked because the only source of event + // for Print is the Count reactor. + lf_print_error_and_exit("Logical STP violation was detected. Only physical STP violations are possible."); + =} - reaction(shutdown) {= - if (self->c != 3) { - lf_print_error_and_exit("Expected to receive 2 items but got %d.", self->c); - } - =} + reaction(shutdown) {= + if (self->c != 3) { + lf_print_error_and_exit("Expected to receive 2 items but got %d.", self->c); + } + =} } federated reactor { - c = new Count(offset = 1 msec, period = 1 sec) - p = new Print(STP_offset_param = 1 usec) + c = new Count(offset = 1 msec, period = 1 sec) + p = new Print(STP_offset_param = 1 usec) - c.out -> p.in + c.out -> p.in } diff --git a/test/C/src/federated/PingPongDistributed.lf b/test/C/src/federated/PingPongDistributed.lf index e16de50ed2..5fcc1bf32b 100644 --- a/test/C/src/federated/PingPongDistributed.lf +++ b/test/C/src/federated/PingPongDistributed.lf @@ -1,21 +1,18 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. * - * This version is distributed, communicating using logical connections over - * sockets. + * This version is distributed, communicating using logical connections over sockets. * - * See [Benchmarks wiki - * page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). + * See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). * * This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs - * and can be run on different machines. + * This is a distributed version, where Ping and Pong run in separate programs and can be run on + * different machines. * - * There is no parallelism in this application, so it does not benefit from - * being being distributed. + * There is no parallelism in this application, so it does not benefit from being being distributed. * * @author Edward A. Lee */ @@ -24,8 +21,8 @@ target C import Ping, Pong from "PingPongDistributedPhysical.lf" federated reactor(count: int = 10) { - ping = new Ping(count = count) - pong = new Pong(expected = count) - ping.send -> pong.receive - pong.send -> ping.receive + ping = new Ping(count = count) + pong = new Pong(expected = count) + ping.send -> pong.receive + pong.send -> ping.receive } diff --git a/test/C/src/federated/PingPongDistributedPhysical.lf b/test/C/src/federated/PingPongDistributedPhysical.lf index d9ba517c59..63ea109a14 100644 --- a/test/C/src/federated/PingPongDistributedPhysical.lf +++ b/test/C/src/federated/PingPongDistributedPhysical.lf @@ -1,79 +1,77 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. * - * This version is distributed, communicating using physical connections over - * sockets. + * This version is distributed, communicating using physical connections over sockets. * * This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs - * and can be run on different machines. + * This is a distributed version, where Ping and Pong run in separate programs and can be run on + * different machines. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * - Unthreaded: 97 msec * - Threaded: 265 msec * - Distributed: 53 seconds * - * There is no parallelism in this application, so it does not benefit from - * being being distributed. + * There is no parallelism in this application, so it does not benefit from being being distributed. * - * These measurements are total execution time, including startup and shutdown, - * of all three programs. + * These measurements are total execution time, including startup and shutdown, of all three + * programs. * * @author Edward A. Lee */ target C reactor Ping(count: int = 10) { - input receive: int - output send: int - state pingsLeft: int = count - logical action serve + input receive: int + output send: int + state pingsLeft: int = count + logical action serve - reaction(startup, serve) -> send {= - printf("At logical time %lld, Ping sending %d.\n", lf_time_logical_elapsed(), self->pingsLeft); - lf_set(send, self->pingsLeft--); - =} + reaction(startup, serve) -> send {= + printf("At logical time %lld, Ping sending %d.\n", lf_time_logical_elapsed(), self->pingsLeft); + lf_set(send, self->pingsLeft--); + =} - reaction(receive) -> serve {= - if (self->pingsLeft > 0) { - lf_schedule(serve, 0); - } else { - lf_request_stop(); - } - =} + reaction(receive) -> serve {= + if (self->pingsLeft > 0) { + lf_schedule(serve, 0); + } else { + lf_request_stop(); + } + =} } reactor Pong(expected: int = 10) { - input receive: int - output send: int - state count: int = 0 + input receive: int + output send: int + state count: int = 0 - reaction(receive) -> send {= - self->count++; - printf("At logical time %lld, Pong received %d.\n", lf_time_logical_elapsed(), receive->value); - lf_set(send, receive->value); - if (self->count == self->expected) { - lf_request_stop(); - } - =} + reaction(receive) -> send {= + self->count++; + printf("At logical time %lld, Pong received %d.\n", lf_time_logical_elapsed(), receive->value); + lf_set(send, receive->value); + if (self->count == self->expected) { + lf_request_stop(); + } + =} - reaction(shutdown) {= - if (self->count != self->expected) { - fprintf(stderr, "Pong expected to receive %d inputs, but it received %d.\n", - self->expected, self->count - ); - exit(1); - } - printf("Pong received %d pings.\n", self->count); - =} + reaction(shutdown) {= + if (self->count != self->expected) { + fprintf(stderr, "Pong expected to receive %d inputs, but it received %d.\n", + self->expected, self->count + ); + exit(1); + } + printf("Pong received %d pings.\n", self->count); + =} } federated reactor(count: int = 10) { - ping = new Ping(count = count) - pong = new Pong(expected = count) - ping.send ~> pong.receive - pong.send ~> ping.receive + ping = new Ping(count = count) + pong = new Pong(expected = count) + ping.send ~> pong.receive + pong.send ~> ping.receive } diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 05932b1937..8332821089 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -1,41 +1,40 @@ /** - * Test whether top-level reactions, actions, and ports are handled - * appropriately. + * Test whether top-level reactions, actions, and ports are handled appropriately. * * Currently, these artifacts are replicated on all federates. * - * @note This just tests for the correctness of the code generation. These - * top-level artifacts might be disallowed in the future. + * @note This just tests for the correctness of the code generation. These top-level artifacts might + * be disallowed in the future. */ target C { - timeout: 1 msec + timeout: 1 msec } import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - state successes: int = 0 - timer t(0, 1 sec) - logical action act(0) + state successes: int = 0 + timer t(0, 1 sec) + logical action act(0) - c = new Count() - tc = new TestCount() - c.out -> tc.in + c = new Count() + tc = new TestCount() + c.out -> tc.in - reaction(startup) {= self->successes++; =} + reaction(startup) {= self->successes++; =} - reaction(t) -> act {= - self->successes++; - lf_schedule(act, 0); - =} + reaction(t) -> act {= + self->successes++; + lf_schedule(act, 0); + =} - reaction(act) {= self->successes++; =} + reaction(act) {= self->successes++; =} - reaction(shutdown) {= - if (self->successes != 3) { - lf_print_error_and_exit("Failed to properly execute top-level reactions"); - } - lf_print("SUCCESS!"); - =} + reaction(shutdown) {= + if (self->successes != 3) { + lf_print_error_and_exit("Failed to properly execute top-level reactions"); + } + lf_print("SUCCESS!"); + =} } diff --git a/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf b/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf index f6ce5edcc1..bf6ff377e6 100644 --- a/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf +++ b/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf @@ -1,23 +1,20 @@ -/** - * This simple test checks if federate authentication works by adding `auth` - * target property. - */ +/** This simple test checks if federate authentication works by adding `auth` target property. */ target C { - timeout: 2 secs, - build-type: RelWithDebInfo, - auth: true, - logging: DEBUG + timeout: 2 secs, + build-type: RelWithDebInfo, + auth: true, + logging: DEBUG } reactor Fed { - input in: int - output out: int + input in: int + output out: int } federated reactor { - fed1 = new Fed() - fed2 = new Fed() + fed1 = new Fed() + fed2 = new Fed() - fed1.out -> fed2.in - fed2.out -> fed1.in + fed1.out -> fed2.in + fed2.out -> fed1.in } diff --git a/test/C/src/lib/Count.lf b/test/C/src/lib/Count.lf index 70291e783f..5b8d7b5844 100644 --- a/test/C/src/lib/Count.lf +++ b/test/C/src/lib/Count.lf @@ -1,9 +1,9 @@ target C reactor Count(offset: time = 0, period: time = 1 sec) { - state count: int = 1 - output out: int - timer t(offset, period) + state count: int = 1 + output out: int + timer t(offset, period) - reaction(t) -> out {= lf_set(out, self->count++); =} + reaction(t) -> out {= lf_set(out, self->count++); =} } diff --git a/test/C/src/lib/FileLevelPreamble.lf b/test/C/src/lib/FileLevelPreamble.lf index 846ed66163..f11186979d 100644 --- a/test/C/src/lib/FileLevelPreamble.lf +++ b/test/C/src/lib/FileLevelPreamble.lf @@ -1,13 +1,10 @@ -/** - * Test for ensuring that file-level preambles are inherited when a file is - * imported. - */ +/** Test for ensuring that file-level preambles are inherited when a file is imported. */ target C preamble {= - #define FOO 2 + #define FOO 2 =} reactor FileLevelPreamble { - reaction(startup) {= printf("FOO: %d\n", FOO); =} + reaction(startup) {= printf("FOO: %d\n", FOO); =} } diff --git a/test/C/src/lib/InternalDelay.lf b/test/C/src/lib/InternalDelay.lf index fbbf2f0cb6..fe03eec9b9 100644 --- a/test/C/src/lib/InternalDelay.lf +++ b/test/C/src/lib/InternalDelay.lf @@ -1,11 +1,11 @@ target C reactor InternalDelay(delay: int = 10 msec) { - input in: int - output out: int - logical action d: int + input in: int + output out: int + logical action d: int - reaction(in) -> d {= lf_schedule_int(d, self->delay, in->value); =} + reaction(in) -> d {= lf_schedule_int(d, self->delay, in->value); =} - reaction(d) -> out {= lf_set(out, d->value); =} + reaction(d) -> out {= lf_set(out, d->value); =} } diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index b996fe6ac5..e4f52c75c3 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -6,31 +6,30 @@ target C /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { - output out: int - logical action act - state sent_messages: int = 0 + output out: int + logical action act + state sent_messages: int = 0 - reaction(startup, act) -> act, out {= - // Send a message on out - /* printf("At tag (%lld, %u) sending value %d.\n", - lf_time_logical_elapsed(), - lf_tag().microstep, - self->sent_messages - ); */ - lf_set(out, self->sent_messages); - self->sent_messages++; - if (self->sent_messages < self->take_a_break_after) { - lf_schedule(act, 0); - } else { - // Take a break - self->sent_messages=0; - lf_schedule(act, self->break_interval); - } - =} + reaction(startup, act) -> act, out {= + // Send a message on out + /* printf("At tag (%lld, %u) sending value %d.\n", + lf_time_logical_elapsed(), + lf_tag().microstep, + self->sent_messages + ); */ + lf_set(out, self->sent_messages); + self->sent_messages++; + if (self->sent_messages < self->take_a_break_after) { + lf_schedule(act, 0); + } else { + // Take a break + self->sent_messages=0; + lf_schedule(act, self->break_interval); + } + =} } diff --git a/test/C/src/lib/PassThrough.lf b/test/C/src/lib/PassThrough.lf index 54185901e2..90d9138c09 100644 --- a/test/C/src/lib/PassThrough.lf +++ b/test/C/src/lib/PassThrough.lf @@ -2,8 +2,8 @@ target C reactor PassThrough { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } diff --git a/test/C/src/lib/Test.lf b/test/C/src/lib/Test.lf index 3ad7518d4e..6feab88015 100644 --- a/test/C/src/lib/Test.lf +++ b/test/C/src/lib/Test.lf @@ -1,15 +1,15 @@ target C reactor TestDouble(expected: double[] = {1.0, 1.0, 1.0, 1.0}) { - input in: double - state count: int = 0 + input in: double + state count: int = 0 - reaction(in) {= - printf("Received: %f\n", in->value); - if (in->value != self->expected[self->count]) { - printf("ERROR: Expected %f.\n", self->expected[self->count]); - exit(1); - } - self->count++; - =} + reaction(in) {= + printf("Received: %f\n", in->value); + if (in->value != self->expected[self->count]) { + printf("ERROR: Expected %f.\n", self->expected[self->count]); + exit(1); + } + self->count++; + =} } diff --git a/test/C/src/lib/TestCount.lf b/test/C/src/lib/TestCount.lf index d3f29aec6c..570cc7fe3e 100644 --- a/test/C/src/lib/TestCount.lf +++ b/test/C/src/lib/TestCount.lf @@ -1,7 +1,6 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. @@ -10,26 +9,26 @@ target C reactor TestCount(start: int = 1, stride: int = 1, num_inputs: int = 1) { - state count: int = start - state inputs_received: int = 0 - input in: int + state count: int = start + state inputs_received: int = 0 + input in: int - reaction(in) {= - lf_print("Received %d.", in->value); - if (in->value != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count += self->stride; - self->inputs_received++; - =} + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count += self->stride; + self->inputs_received++; + =} - reaction(shutdown) {= - lf_print("Shutdown invoked."); - if (self->inputs_received != self->num_inputs) { - lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", - self->num_inputs, - self->inputs_received - ); - } - =} + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", + self->num_inputs, + self->inputs_received + ); + } + =} } diff --git a/test/C/src/lib/TestCountMultiport.lf b/test/C/src/lib/TestCountMultiport.lf index 5a2db4b029..69ec75adec 100644 --- a/test/C/src/lib/TestCountMultiport.lf +++ b/test/C/src/lib/TestCountMultiport.lf @@ -1,47 +1,41 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. This version has a multiport input, and each - * input is expected to be present and incremented over the previous input. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. This version has + * a multiport input, and each input is expected to be present and incremented over the previous + * input. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. - * @param num_inputs The number of inputs expected on each channel. Default is - * 1. + * @param num_inputs The number of inputs expected on each channel. Default is 1. */ target C -reactor TestCountMultiport( - start: int = 1, - stride: int = 1, - num_inputs: int = 1, - width: int = 2 -) { - state count: int = start - state inputs_received: int = 0 - input[width] in: int +reactor TestCountMultiport(start: int = 1, stride: int = 1, num_inputs: int = 1, width: int = 2) { + state count: int = start + state inputs_received: int = 0 + input[width] in: int - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (!in[i]->is_present) { - lf_print_error_and_exit("No input on channel %d.", i); - } - lf_print("Received %d on channel %d.", in[i]->value, i); - if (in[i]->value != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count += self->stride; + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (!in[i]->is_present) { + lf_print_error_and_exit("No input on channel %d.", i); } - self->inputs_received++; - =} - - reaction(shutdown) {= - lf_print("Shutdown invoked."); - if (self->inputs_received != self->num_inputs) { - lf_print_error_and_exit("Expected to receive %d inputs, but only got %d.", - self->num_inputs, - self->inputs_received - ); + lf_print("Received %d on channel %d.", in[i]->value, i); + if (in[i]->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); } - =} + self->count += self->stride; + } + self->inputs_received++; + =} + + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but only got %d.", + self->num_inputs, + self->inputs_received + ); + } + =} } diff --git a/test/C/src/modal_models/BanksCount3ModesComplex.lf b/test/C/src/modal_models/BanksCount3ModesComplex.lf index 47805f1009..b8afa7064f 100644 --- a/test/C/src/modal_models/BanksCount3ModesComplex.lf +++ b/test/C/src/modal_models/BanksCount3ModesComplex.lf @@ -1,82 +1,78 @@ -/** - * Modal Reactor Test. Tests cycling through modes with banks of reactors and - * complex nesting. - */ +/** Modal Reactor Test. Tests cycling through modes with banks of reactors and complex nesting. */ target C { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } import TraceTesting from "util/TraceTesting.lf" import CounterCycle from "Count3Modes.lf" reactor MetaCounter { - input next: bool - output[2] always: int - output[2] mode1: int - output[2] mode2: int - output[2] never: int + input next: bool + output[2] always: int + output[2] mode1: int + output[2] mode2: int + output[2] never: int - outer_counters = new[2] CounterCycle() - (next)+ -> outer_counters.next - outer_counters.count -> always + outer_counters = new[2] CounterCycle() + (next)+ -> outer_counters.next + outer_counters.count -> always - initial mode One { - mode1_counters = new[2] CounterCycle() + initial mode One { + mode1_counters = new[2] CounterCycle() - (next)+ -> mode1_counters.next - mode1_counters.count -> mode1 + (next)+ -> mode1_counters.next + mode1_counters.count -> mode1 - timer t1(500 msec, 250 msec) - reaction(t1) -> reset(Two) {= lf_set_mode(Two); =} - } + timer t1(500 msec, 250 msec) + reaction(t1) -> reset(Two) {= lf_set_mode(Two); =} + } - mode Two { - mode2_counters = new[2] CounterCycle() + mode Two { + mode2_counters = new[2] CounterCycle() - (next)+ -> mode2_counters.next - mode2_counters.count -> mode2 + (next)+ -> mode2_counters.next + mode2_counters.count -> mode2 - timer t2(500 msec, 250 msec) - reaction(t2) -> history(One) {= lf_set_mode(One); =} - } + timer t2(500 msec, 250 msec) + reaction(t2) -> history(One) {= lf_set_mode(One); =} + } - mode Three { - mode3_counters = new[2] CounterCycle() + mode Three { + mode3_counters = new[2] CounterCycle() - (next)+ -> mode3_counters.next - mode3_counters.count -> never - } + (next)+ -> mode3_counters.next + mode3_counters.count -> never + } } main reactor { - timer stepper(0, 250 msec) - counters = new[2] MetaCounter() - test = new TraceTesting( // keep-format - events_size = 16, - trace_size = 429, - trace = { - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,0,3,0,3,0,3,0,3,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,0,1,0,1,0,1,0,1,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0 - }, training = false) + timer stepper(0, 250 msec) + counters = new[2] MetaCounter() + test = new TraceTesting( // keep-format + events_size = 16, + trace_size = 429, + trace = { + 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,0,3,0,3,0,3,0,3,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,0,1,0,1,0,1,0,1,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0 + }, training = false) - counters.always, counters.mode1, counters.mode2, counters.never - -> test.events + counters.always, counters.mode1, counters.mode2, counters.never -> test.events - reaction(stepper) -> counters.next {= // Trigger - for(int i = 0; i < 2; i++) { - lf_set(counters[i].next, true); - } - =} + reaction(stepper) -> counters.next {= // Trigger + for(int i = 0; i < 2; i++) { + lf_set(counters[i].next, true); + } + =} } diff --git a/test/C/src/modal_models/BanksCount3ModesSimple.lf b/test/C/src/modal_models/BanksCount3ModesSimple.lf index 40c2ba50a8..8ca84403c9 100644 --- a/test/C/src/modal_models/BanksCount3ModesSimple.lf +++ b/test/C/src/modal_models/BanksCount3ModesSimple.lf @@ -1,37 +1,32 @@ /** Modal Reactor Test. Tests cycling through modes with banks of reactors. */ target C { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } import TraceTesting from "util/TraceTesting.lf" import CounterCycle from "Count3Modes.lf" main reactor { - timer stepper(0, 250 msec) - counters = new[3] CounterCycle() - test = new TraceTesting( - events_size = 3, - trace_size = 63, - trace = { // keep-format - 0,1,1,1,1,1,1, - 250000000,1,2,1,2,1,2, - 250000000,1,3,1,3,1,3, - 250000000,1,1,1,1,1,1, - 250000000,1,2,1,2,1,2, - 250000000,1,3,1,3,1,3, - 250000000,1,1,1,1,1,1, - 250000000,1,2,1,2,1,2, - 250000000,1,3,1,3,1,3 - }, - training = false - ) + timer stepper(0, 250 msec) + counters = new[3] CounterCycle() + test = new TraceTesting(events_size = 3, trace_size = 63, trace = { // keep-format + 0,1,1,1,1,1,1, + 250000000,1,2,1,2,1,2, + 250000000,1,3,1,3,1,3, + 250000000,1,1,1,1,1,1, + 250000000,1,2,1,2,1,2, + 250000000,1,3,1,3,1,3, + 250000000,1,1,1,1,1,1, + 250000000,1,2,1,2,1,2, + 250000000,1,3,1,3,1,3 + }, training = false) - counters.count -> test.events + counters.count -> test.events - reaction(stepper) -> counters.next {= // Trigger - for(int i = 0; i < 3; i++) { - lf_set(counters[i].next, true); - } - =} + reaction(stepper) -> counters.next {= // Trigger + for(int i = 0; i < 3; i++) { + lf_set(counters[i].next, true); + } + =} } diff --git a/test/C/src/modal_models/BanksModalStateReset.lf b/test/C/src/modal_models/BanksModalStateReset.lf index 8e075715c8..d8130611c7 100644 --- a/test/C/src/modal_models/BanksModalStateReset.lf +++ b/test/C/src/modal_models/BanksModalStateReset.lf @@ -1,10 +1,7 @@ -/** - * Modal Reactor Test. Tests reset of state variables in modes with banks of - * reactors. - */ +/** Modal Reactor Test. Tests reset of state variables in modes with banks of reactors. */ target C { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" @@ -12,52 +9,51 @@ import Modal as ResetReaction from "ModalStateReset.lf" import Modal as AutoReset from "ModalStateResetAuto.lf" main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - reset1 = new[2] ResetReaction() - reset2 = new[2] AutoReset() - test = new TraceTesting(events_size = 16, trace_size = 627, trace = { // keep-format - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, - 250000000,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, - 250000000,0,0,0,0,0,0,0,0,1,2,1,2,0,0,0,0, 0,0,0,0,0,0,0,0,1,2,1,2,0,0,0,0, - 250000000,0,0,0,0,0,0,0,0,1,3,1,3,0,0,0,0, 0,0,0,0,0,0,0,0,1,3,1,3,0,0,0,0, - 250000000,1,1,1,1,1,0,1,0,1,4,1,4,0,0,0,0, 1,1,1,1,1,0,1,0,1,4,1,4,0,0,0,0, - 0,0,1,0,1,0,0,0,0,0,4,0,4,1,-2,1,-2, 0,1,0,1,0,0,0,0,0,4,0,4,1,-2,1,-2, - 250000000,0,1,0,1,0,0,0,0,0,4,0,4,1,-1,1,-1, 0,1,0,1,0,0,0,0,0,4,0,4,1,-1,1,-1, - 250000000,0,1,0,1,0,0,0,0,0,4,0,4,1,0,1,0, 0,1,0,1,0,0,0,0,0,4,0,4,1,0,1,0, - 250000000,0,1,0,1,0,0,0,0,0,4,0,4,1,1,1,1, 0,1,0,1,0,0,0,0,0,4,0,4,1,1,1,1, - 250000000,1,1,1,1,1,1,1,1,0,4,0,4,1,2,1,2, 1,1,1,1,1,1,1,1,0,4,0,4,1,2,1,2, - 250000000,0,1,0,1,0,1,0,1,1,5,1,5,0,2,0,2, 0,1,0,1,0,1,0,1,1,5,1,5,0,2,0,2, - 250000000,0,1,0,1,0,1,0,1,1,6,1,6,0,2,0,2, 0,1,0,1,0,1,0,1,1,6,1,6,0,2,0,2, - 250000000,0,1,0,1,0,1,0,1,1,7,1,7,0,2,0,2, 0,1,0,1,0,1,0,1,1,7,1,7,0,2,0,2, - 250000000,1,1,1,1,1,2,1,2,1,8,1,8,0,2,0,2, 1,1,1,1,1,2,1,2,1,8,1,8,0,2,0,2, - 0,0,1,0,1,0,2,0,2,0,8,0,8,1,-2,1,-2, 0,1,0,1,0,2,0,2,0,8,0,8,1,-2,1,-2, - 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, 0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, - 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, 0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, - 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, 0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, - 250000000,1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2, 1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2 - }, training = false) + reset1 = new[2] ResetReaction() + reset2 = new[2] AutoReset() + test = new TraceTesting(events_size = 16, trace_size = 627, trace = { // keep-format + 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0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8,1,-2,1,-2, + 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, 0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, + 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, 0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, + 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, 0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, + 250000000,1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2, 1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2 + }, training = false) - reset1.mode_switch, - reset1.count0, - reset1.count1, - reset1.count2, - reset2.mode_switch, - reset2.count0, - reset2.count1, - reset2.count2 - -> test.events + reset1.mode_switch, + reset1.count0, + reset1.count1, + reset1.count2, + reset2.mode_switch, + reset2.count0, + reset2.count1, + reset2.count2 + -> test.events - // Trigger mode change (separately because of #1278) - reaction(stepper) -> reset1.next {= - for(int i = 0; i < reset1_width; i++) { - lf_set(reset1[i].next, true); - } - =} + reaction(stepper) -> reset1.next {= // Trigger mode change (separately because of #1278) + for(int i = 0; i < reset1_width; i++) { + lf_set(reset1[i].next, true); + } + =} - reaction(stepper) -> reset2.next {= - for(int i = 0; i < reset2_width; i++) { - lf_set(reset2[i].next, true); - } - =} + reaction(stepper) -> reset2.next {= + for(int i = 0; i < reset2_width; i++) { + lf_set(reset2[i].next, true); + } + =} } diff --git a/test/C/src/modal_models/ConvertCaseTest.lf b/test/C/src/modal_models/ConvertCaseTest.lf index 3f644eb133..24afa7439e 100644 --- a/test/C/src/modal_models/ConvertCaseTest.lf +++ b/test/C/src/modal_models/ConvertCaseTest.lf @@ -1,145 +1,135 @@ /** Modal Reactor Test. Tests nested reactors with modes. */ target C { - fast: false, - timeout: 4 sec // logging: debug + fast: false, + timeout: 4 sec // logging: debug } import TraceTesting from "util/TraceTesting.lf" reactor ResetProcessor { - input discard: bool - input character: char - output converted: int - - initial mode Converting { - converter = new Converter() - character -> converter.raw - converter.converted -> converted - reaction(discard) -> reset(Discarding) {= lf_set_mode(Discarding); =} - } - - mode Discarding { - reaction(character) -> converted {= lf_set(converted, '_'); =} - - reaction(character) -> reset(Converting) {= lf_set_mode(Converting); =} - } + input discard: bool + input character: char + output converted: int + + initial mode Converting { + converter = new Converter() + character -> converter.raw + converter.converted -> converted + reaction(discard) -> reset(Discarding) {= lf_set_mode(Discarding); =} + } + + mode Discarding { + reaction(character) -> converted {= lf_set(converted, '_'); =} + + reaction(character) -> reset(Converting) {= lf_set_mode(Converting); =} + } } reactor HistoryProcessor { - input discard: bool - input character: char - output converted: int - - initial mode Converting { - converter = new Converter() - character -> converter.raw - converter.converted -> converted - reaction(discard) -> reset(Discarding) {= lf_set_mode(Discarding); =} - } - - mode Discarding { - reaction(character) -> converted {= lf_set(converted, '_'); =} - - reaction(character) -> history(Converting) {= - lf_set_mode(Converting); - =} - } + input discard: bool + input character: char + output converted: int + + initial mode Converting { + converter = new Converter() + character -> converter.raw + converter.converted -> converted + reaction(discard) -> reset(Discarding) {= lf_set_mode(Discarding); =} + } + + mode Discarding { + reaction(character) -> converted {= lf_set(converted, '_'); =} + + reaction(character) -> history(Converting) {= lf_set_mode(Converting); =} + } } reactor Converter { - input raw: char - output converted: int - - initial mode Upper { - reaction(raw) -> converted, reset(Lower) {= - char c = raw->value; - if (c >= 'a' && c <= 'z') { - lf_set(converted, c - 32); - } else { - lf_set(converted, c); - } - if (c == ' ') { - lf_set_mode(Lower); - } - =} - } - - mode Lower { - reaction(raw) -> converted, reset(Upper) {= - char c = raw->value; - if (c >= 'A' && c <= 'Z') { - lf_set(converted, c + 32); - } else { - lf_set(converted, c); - } - if (c == ' ') { - lf_set_mode(Upper); - } - =} - } + input raw: char + output converted: int + + initial mode Upper { + reaction(raw) -> converted, reset(Lower) {= + char c = raw->value; + if (c >= 'a' && c <= 'z') { + lf_set(converted, c - 32); + } else { + lf_set(converted, c); + } + if (c == ' ') { + lf_set_mode(Lower); + } + =} + } + + mode Lower { + reaction(raw) -> converted, reset(Upper) {= + char c = raw->value; + if (c >= 'A' && c <= 'Z') { + lf_set(converted, c + 32); + } else { + lf_set(converted, c); + } + if (c == ' ') { + lf_set_mode(Upper); + } + =} + } } reactor InputFeeder(message: string = "") { - output character: char - state idx: int = 0 + output character: char + state idx: int = 0 - timer t(0, 250 msec) + timer t(0, 250 msec) - preamble {= - #include - =} + preamble {= + #include + =} - reaction(t) -> character {= - if (self->idx < strlen(self->message)) { - lf_set(character, *(self->message + self->idx)); - self->idx++; - } - =} + reaction(t) -> character {= + if (self->idx < strlen(self->message)) { + lf_set(character, *(self->message + self->idx)); + self->idx++; + } + =} } main reactor { - timer stepper(500 msec, 1 sec) - - feeder = new InputFeeder(message = "Hello World!") - reset_processor = new ResetProcessor() - history_processor = new HistoryProcessor() - - feeder.character -> reset_processor.character - feeder.character -> history_processor.character - - test = new TraceTesting( - events_size = 2, - trace_size = 60, - trace = { // keep-format - 0,1,72,1,72, - 250000000,1,69,1,69, - 250000000,1,76,1,76, - 250000000,1,95,1,95, - 250000000,1,79,1,79, - 250000000,1,32,1,32, - 250000000,1,119,1,119, - 250000000,1,95,1,95, - 250000000,1,82,1,114, - 250000000,1,76,1,108, - 250000000,1,68,1,100, - 250000000,1,95,1,95 - }, - training = false - ) - - reset_processor.converted, history_processor.converted -> test.events - - // Trigger mode change - reaction(stepper) -> reset_processor.discard, history_processor.discard {= - lf_set(reset_processor.discard, true); - lf_set(history_processor.discard, true); - =} - - reaction(reset_processor.converted) {= - printf("Reset: %c\n", reset_processor.converted->value); - =} - - reaction(history_processor.converted) {= - printf("History: %c\n", history_processor.converted->value); - =} + timer stepper(500 msec, 1 sec) + + feeder = new InputFeeder(message = "Hello World!") + reset_processor = new ResetProcessor() + history_processor = new HistoryProcessor() + + feeder.character -> reset_processor.character + feeder.character -> history_processor.character + + test = new TraceTesting(events_size = 2, trace_size = 60, trace = { // keep-format + 0,1,72,1,72, + 250000000,1,69,1,69, + 250000000,1,76,1,76, + 250000000,1,95,1,95, + 250000000,1,79,1,79, + 250000000,1,32,1,32, + 250000000,1,119,1,119, + 250000000,1,95,1,95, + 250000000,1,82,1,114, + 250000000,1,76,1,108, + 250000000,1,68,1,100, + 250000000,1,95,1,95 + }, training = false) + + reset_processor.converted, history_processor.converted -> test.events + + reaction(stepper) -> reset_processor.discard, history_processor.discard {= // Trigger mode change + lf_set(reset_processor.discard, true); + lf_set(history_processor.discard, true); + =} + + reaction(reset_processor.converted) {= printf("Reset: %c\n", reset_processor.converted->value); =} + + reaction(history_processor.converted) {= + printf("History: %c\n", history_processor.converted->value); + =} } diff --git a/test/C/src/modal_models/Count3Modes.lf b/test/C/src/modal_models/Count3Modes.lf index 862915abed..93e5119759 100644 --- a/test/C/src/modal_models/Count3Modes.lf +++ b/test/C/src/modal_models/Count3Modes.lf @@ -1,60 +1,58 @@ /** Modal Reactor Test. Tests cycling through modes. */ target C { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } reactor CounterCycle { - input next: bool - output count: int - - initial mode One { - reaction(next) -> count, reset(Two) {= - lf_set(count, 1); - lf_set_mode(Two); - =} - } + input next: bool + output count: int - mode Two { - reaction(next) -> count, reset(Three) {= - lf_set(count, 2); - lf_set_mode(Three); - =} - } + initial mode One { + reaction(next) -> count, reset(Two) {= + lf_set(count, 1); + lf_set_mode(Two); + =} + } - mode Three { - reaction(next) -> count, reset(One) {= - lf_set(count, 3); - lf_set_mode(One); - =} - } + mode Two { + reaction(next) -> count, reset(Three) {= + lf_set(count, 2); + lf_set_mode(Three); + =} + } + + mode Three { + reaction(next) -> count, reset(One) {= + lf_set(count, 3); + lf_set_mode(One); + =} + } } main reactor { - timer stepper(0, 250 msec) - counter = new CounterCycle() - - state expected_value: int = 1 - - // Trigger - reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} - - // Check - reaction(stepper) counter.count {= - printf("%d\n", counter.count->value); - - if (!counter.count->is_present) { - printf("ERROR: Missing mode change.\n"); - exit(1); - } else if (counter.count->value != self->expected_value) { - printf("ERROR: Wrong mode.\n"); - exit(2); - } - - if (self->expected_value == 3) { - self->expected_value = 1; - } else { - self->expected_value++; - } - =} + timer stepper(0, 250 msec) + counter = new CounterCycle() + + state expected_value: int = 1 + + reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger + + reaction(stepper) counter.count {= // Check + printf("%d\n", counter.count->value); + + if (!counter.count->is_present) { + printf("ERROR: Missing mode change.\n"); + exit(1); + } else if (counter.count->value != self->expected_value) { + printf("ERROR: Wrong mode.\n"); + exit(2); + } + + if (self->expected_value == 3) { + self->expected_value = 1; + } else { + self->expected_value++; + } + =} } diff --git a/test/C/src/modal_models/MixedReactions.lf b/test/C/src/modal_models/MixedReactions.lf index 78ea39c95c..274cf77573 100644 --- a/test/C/src/modal_models/MixedReactions.lf +++ b/test/C/src/modal_models/MixedReactions.lf @@ -1,46 +1,46 @@ /** - * Modal Reactor Test. Tests reactions that are defined between and after modes - * and should be ordered accordingly. + * Modal Reactor Test. Tests reactions that are defined between and after modes and should be + * ordered accordingly. */ target C { - fast: true, - timeout: 110 msec + fast: true, + timeout: 110 msec } main reactor { - state x: int = 0 - state first: bool = true + state x: int = 0 + state first: bool = true - timer t(0, 100 msec) + timer t(0, 100 msec) - reaction(t) {= self->x = self->x * 10 + 1; =} + reaction(t) {= self->x = self->x * 10 + 1; =} - reaction(t) {= self->x = self->x * 10 + 2; =} + reaction(t) {= self->x = self->x * 10 + 2; =} - initial mode A { - reaction(t) -> reset(B) {= - self->x = self->x * 10 + 3; - lf_set_mode(B); - =} - } - - reaction(t) {= self->x = self->x * 10 + 4; =} - - mode B { - reaction(t) {= self->x = self->x * 10 + 5; =} - } - - reaction(t) {= - printf("%d\n", self->x); - if (self->first) { - if (self->x != 1234) { - printf("ERROR: Wrong reaction order.\n"); - exit(1); - } - self->first = false; - } else if (self->x != 12341245) { - printf("ERROR: Wrong reaction order.\n"); - exit(2); - } + initial mode A { + reaction(t) -> reset(B) {= + self->x = self->x * 10 + 3; + lf_set_mode(B); =} + } + + reaction(t) {= self->x = self->x * 10 + 4; =} + + mode B { + reaction(t) {= self->x = self->x * 10 + 5; =} + } + + reaction(t) {= + printf("%d\n", self->x); + if (self->first) { + if (self->x != 1234) { + printf("ERROR: Wrong reaction order.\n"); + exit(1); + } + self->first = false; + } else if (self->x != 12341245) { + printf("ERROR: Wrong reaction order.\n"); + exit(2); + } + =} } diff --git a/test/C/src/modal_models/ModalActions.lf b/test/C/src/modal_models/ModalActions.lf index e687d4bafd..594273bb6f 100644 --- a/test/C/src/modal_models/ModalActions.lf +++ b/test/C/src/modal_models/ModalActions.lf @@ -1,100 +1,94 @@ /** - * Modal Reactor Test. Tests actions, their suspension during mode inactivity - * and continuation of delays with history transitions. + * Modal Reactor Test. Tests actions, their suspension during mode inactivity and continuation of + * delays with history transitions. */ target C { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool + input next: bool - output mode_switch: int - output action1_sched: int - output action1_exec: int - output action2_sched: int - output action2_exec: int + output mode_switch: int + output action1_sched: int + output action1_exec: int + output action2_sched: int + output action2_exec: int - initial mode One { - timer T1(0, 750 msec) - logical action delay1(500 msec) - reaction(T1) -> delay1, action1_sched {= - printf("Scheduled Action\n"); - lf_schedule(delay1, 0); - lf_set(action1_sched, 1); - =} + initial mode One { + timer T1(0, 750 msec) + logical action delay1(500 msec) + reaction(T1) -> delay1, action1_sched {= + printf("Scheduled Action\n"); + lf_schedule(delay1, 0); + lf_set(action1_sched, 1); + =} - reaction(delay1) -> action1_exec {= - printf("Executed Action\n"); - lf_set(action1_exec, 1); - =} + reaction(delay1) -> action1_exec {= + printf("Executed Action\n"); + lf_set(action1_exec, 1); + =} - reaction(next) -> reset(Two), mode_switch {= - printf("Transitioning to mode Two (reset)\n"); - lf_set(mode_switch, 1); - lf_set_mode(Two); - =} - } + reaction(next) -> reset(Two), mode_switch {= + printf("Transitioning to mode Two (reset)\n"); + lf_set(mode_switch, 1); + lf_set_mode(Two); + =} + } - mode Two { - timer T2(0, 750 msec) - logical action delay2(500 msec) - reaction(T2) -> delay2, action2_sched {= - printf("Scheduled Action2\n"); - lf_schedule(delay2, 0); - lf_set(action2_sched, 1); - =} + mode Two { + timer T2(0, 750 msec) + logical action delay2(500 msec) + reaction(T2) -> delay2, action2_sched {= + printf("Scheduled Action2\n"); + lf_schedule(delay2, 0); + lf_set(action2_sched, 1); + =} - reaction(delay2) -> action2_exec {= - printf("Executed Action2\n"); - lf_set(action2_exec, 1); - =} + reaction(delay2) -> action2_exec {= + printf("Executed Action2\n"); + lf_set(action2_exec, 1); + =} - reaction(next) -> history(One), mode_switch {= - printf("Transitioning to mode One (continue)\n"); - lf_set(mode_switch, 1); - lf_set_mode(One); - =} - } + reaction(next) -> history(One), mode_switch {= + printf("Transitioning to mode One (continue)\n"); + lf_set(mode_switch, 1); + lf_set_mode(One); + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting( - events_size = 5, - trace_size = 165, - trace = { // keep-format - 0,0,0,1,1,0,0,0,0,0,0, - 500000000,0,0,0,1,1,1,0,0,0,0, - 250000000,0,0,1,1,0,1,0,0,0,0, - 250000000,1,1,0,1,0,1,0,0,0,0, - 0,0,1,0,1,0,1,1,1,0,0, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1, - 250000000,0,1,0,1,1,1,0,1,0,1, - 250000000,0,1,1,1,0,1,0,1,0,1, - 500000000,1,1,0,1,1,1,0,1,0,1, - 0,0,1,0,1,0,1,1,1,0,1, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 5, trace_size = 165, trace = { // keep-format + 0,0,0,1,1,0,0,0,0,0,0, + 500000000,0,0,0,1,1,1,0,0,0,0, + 250000000,0,0,1,1,0,1,0,0,0,0, + 250000000,1,1,0,1,0,1,0,0,0,0, + 0,0,1,0,1,0,1,1,1,0,0, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1, + 250000000,0,1,0,1,1,1,0,1,0,1, + 250000000,0,1,1,1,0,1,0,1,0,1, + 500000000,1,1,0,1,1,1,0,1,0,1, + 0,0,1,0,1,0,1,1,1,0,1, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1 + }, training = false) - modal.mode_switch, - modal.action1_sched, - modal.action1_exec, - modal.action2_sched, - modal.action2_exec - -> test.events + modal.mode_switch, + modal.action1_sched, + modal.action1_exec, + modal.action2_sched, + modal.action2_exec + -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change } diff --git a/test/C/src/modal_models/ModalAfter.lf b/test/C/src/modal_models/ModalAfter.lf index f5cc8d229e..f0ddd8ea6e 100644 --- a/test/C/src/modal_models/ModalAfter.lf +++ b/test/C/src/modal_models/ModalAfter.lf @@ -1,105 +1,95 @@ /** - * Modal Reactor Test. Tests after delays, its suspension during mode inactivity - * and continuation with history transitions. + * Modal Reactor Test. Tests after delays, its suspension during mode inactivity and continuation + * with history transitions. */ target C { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool + input next: bool - output mode_switch: int - output produced1: int - output consumed1: int - output produced2: int - output consumed2: int + output mode_switch: int + output produced1: int + output consumed1: int + output produced2: int + output consumed2: int - initial mode One { - producer1 = new Producer(mode_id = 1) - consumer1 = new Consumer(mode_id = 1) - producer1.product -> produced1 - producer1.product -> consumer1.product after 500 msec - consumer1.report -> consumed1 - reaction(next) -> reset(Two), mode_switch {= - printf("Transitioning to mode Two (reset)\n"); - lf_set(mode_switch, 1); - lf_set_mode(Two); - =} - } + initial mode One { + producer1 = new Producer(mode_id = 1) + consumer1 = new Consumer(mode_id = 1) + producer1.product -> produced1 + producer1.product -> consumer1.product after 500 msec + consumer1.report -> consumed1 + reaction(next) -> reset(Two), mode_switch {= + printf("Transitioning to mode Two (reset)\n"); + lf_set(mode_switch, 1); + lf_set_mode(Two); + =} + } - mode Two { - producer2 = new Producer(mode_id = 2) - consumer2 = new Consumer(mode_id = 2) - producer2.product -> produced2 - producer2.product -> consumer2.product after 500 msec - consumer2.report -> consumed2 - reaction(next) -> history(One), mode_switch {= - printf("Transitioning to mode One (continue)\n"); - lf_set(mode_switch, 1); - lf_set_mode(One); - =} - } + mode Two { + producer2 = new Producer(mode_id = 2) + consumer2 = new Consumer(mode_id = 2) + producer2.product -> produced2 + producer2.product -> consumer2.product after 500 msec + consumer2.report -> consumed2 + reaction(next) -> history(One), mode_switch {= + printf("Transitioning to mode One (continue)\n"); + lf_set(mode_switch, 1); + lf_set_mode(One); + =} + } } reactor Producer(mode_id: int = 0) { - output product: int + output product: int - timer t(0, 750 msec) + timer t(0, 750 msec) - reaction(t) -> product {= - printf("Produced in %d\n", self->mode_id); - lf_set(product, 1); - =} + reaction(t) -> product {= + printf("Produced in %d\n", self->mode_id); + lf_set(product, 1); + =} } reactor Consumer(mode_id: int = 0) { - input product: int - output report: int + input product: int + output report: int - reaction(product) -> report {= - printf("Consumed in %d\n", self->mode_id); - lf_set(report, 1); - =} + reaction(product) -> report {= + printf("Consumed in %d\n", self->mode_id); + lf_set(report, 1); + =} } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting( - events_size = 5, - trace_size = 165, - trace = { // keep-format - 0,0,0,1,1,0,0,0,0,0,0, - 500000000,0,0,0,1,1,1,0,0,0,0, - 250000000,0,0,1,1,0,1,0,0,0,0, - 250000000,1,1,0,1,0,1,0,0,0,0, - 0,0,1,0,1,0,1,1,1,0,0, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1, - 250000000,0,1,0,1,1,1,0,1,0,1, - 250000000,0,1,1,1,0,1,0,1,0,1, - 500000000,1,1,0,1,1,1,0,1,0,1, - 0,0,1,0,1,0,1,1,1,0,1, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 5, trace_size = 165, trace = { // keep-format + 0,0,0,1,1,0,0,0,0,0,0, + 500000000,0,0,0,1,1,1,0,0,0,0, + 250000000,0,0,1,1,0,1,0,0,0,0, + 250000000,1,1,0,1,0,1,0,0,0,0, + 0,0,1,0,1,0,1,1,1,0,0, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1, + 250000000,0,1,0,1,1,1,0,1,0,1, + 250000000,0,1,1,1,0,1,0,1,0,1, + 500000000,1,1,0,1,1,1,0,1,0,1, + 0,0,1,0,1,0,1,1,1,0,1, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1 + }, training = false) - modal.mode_switch, - modal.produced1, - modal.consumed1, - modal.produced2, - modal.consumed2 - -> test.events + modal.mode_switch, modal.produced1, modal.consumed1, modal.produced2, modal.consumed2 + -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change } diff --git a/test/C/src/modal_models/ModalCycleBreaker.lf b/test/C/src/modal_models/ModalCycleBreaker.lf index aae727b23d..c411fcbe3b 100644 --- a/test/C/src/modal_models/ModalCycleBreaker.lf +++ b/test/C/src/modal_models/ModalCycleBreaker.lf @@ -1,80 +1,73 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work - * if they are located in separate modes. + * Tests if connections in the same reactor that have the same destination work if they are located + * in separate modes. */ target C { - fast: false, - timeout: 1 sec + fast: false, + timeout: 1 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input in1: int - input in2: int - output out: int + input in1: int + input in2: int + output out: int - // Defining reaction to in2 before in1 would cause cycle if no mode were - // present - mode Two { - timer wait(150 msec, 1 sec) - reaction(in2) {= - // lf_set(out, in2->value); - =} + mode Two { // Defining reaction to in2 before in1 would cause cycle if no mode were present + timer wait(150 msec, 1 sec) + reaction(in2) {= + // lf_set(out, in2->value); + =} - reaction(wait) -> reset(One) {= - lf_set_mode(One); - printf("Switching to mode One\n"); - =} - } + reaction(wait) -> reset(One) {= + lf_set_mode(One); + printf("Switching to mode One\n"); + =} + } - initial mode One { - reaction(in1) -> out {= lf_set(out, in1->value); =} + initial mode One { + reaction(in1) -> out {= lf_set(out, in1->value); =} - reaction(in1) -> reset(Two) {= - if (in1->value % 5 == 4) { - lf_set_mode(Two); - printf("Switching to mode Two\n"); - } - =} - } + reaction(in1) -> reset(Two) {= + if (in1->value % 5 == 4) { + lf_set_mode(Two); + printf("Switching to mode Two\n"); + } + =} + } } reactor Counter(period: time = 1 sec) { - output value: int + output value: int - timer t(0, period) - state curval: int = 0 + timer t(0, period) + state curval: int = 0 - reaction(t) -> value {= lf_set(value, self->curval++); =} + reaction(t) -> value {= lf_set(value, self->curval++); =} } main reactor { - counter = new Counter(period = 100 msec) - modal = new Modal() - test = new TraceTesting( - events_size = 1, - trace_size = 27, - trace = { // keep-format - 0,1,0, - 100000000,1,1, - 100000000,1,2, - 100000000,1,3, - 100000000,1,4, - 200000000,1,6, - 100000000,1,7, - 100000000,1,8, - 100000000,1,9 - }, - training = false - ) + counter = new Counter(period = 100 msec) + modal = new Modal() + test = new TraceTesting(events_size = 1, trace_size = 27, trace = { // keep-format + 0,1,0, + 100000000,1,1, + 100000000,1,2, + 100000000,1,3, + 100000000,1,4, + 200000000,1,6, + 100000000,1,7, + 100000000,1,8, + 100000000,1,9 + }, training = false) - counter.value -> modal.in1 - modal.out -> modal.in2 + counter.value -> modal.in1 + modal.out -> modal.in2 - modal.out -> test.events + modal.out -> test.events - reaction(modal.out) {= printf("%d\n", modal.out->value); =} // Print + reaction(modal.out) {= printf("%d\n", modal.out->value); =} // Print } diff --git a/test/C/src/modal_models/ModalNestedReactions.lf b/test/C/src/modal_models/ModalNestedReactions.lf index f42ad4573f..c17c8abb8b 100644 --- a/test/C/src/modal_models/ModalNestedReactions.lf +++ b/test/C/src/modal_models/ModalNestedReactions.lf @@ -46,7 +46,7 @@ main reactor { reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} // Trigger - reaction(stepper) counter.count, counter.only_in_two {= // Check + reaction(stepper) counter.count, counter.only_in_two {= // Check printf("%d\n", counter.count->value); if (!counter.count->is_present) { diff --git a/test/C/src/modal_models/ModalStartupShutdown.lf b/test/C/src/modal_models/ModalStartupShutdown.lf index d39117882a..389856c9e7 100644 --- a/test/C/src/modal_models/ModalStartupShutdown.lf +++ b/test/C/src/modal_models/ModalStartupShutdown.lf @@ -1,147 +1,141 @@ /** Modal Reactor Test. Test startup/shutdown reactions in modes. */ target C { - fast: false, - timeout: 3000 msec + fast: false, + timeout: 3000 msec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool - - output mode_switch: int - output startup1: int - output startup2: int - output shutdown2: int - output shutdown3: int - output startup4: int - output reset4: int - output shutdown4: int - output startup5: int - output reset5: int - output shutdown5: int - - initial mode One { - reaction(startup) -> startup1 {= - printf("Startup 1 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(startup1, 1); - =} - - reaction(next) -> reset(Two), mode_switch {= - printf("Transitioning to mode 1\n"); - lf_set(mode_switch, 2); - lf_set_mode(Two); - =} - } - - mode Two { - reaction(startup) -> startup2 {= - printf("Startup 2 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(startup2, 1); - =} - - reaction(next) -> reset(Three), mode_switch {= - printf("Transitioning to mode 3\n"); - lf_set(mode_switch, 3); - lf_set_mode(Three); - =} - - reaction(shutdown) -> shutdown2 {= - printf("Shutdown 2 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(shutdown2, 1); - =} - } - - mode Three { - reaction(next) -> reset(Four), mode_switch {= - printf("Transitioning to mode 4\n"); - lf_set(mode_switch, 4); - lf_set_mode(Four); - =} - - reaction(shutdown) -> shutdown3 {= - printf("Shutdown 3 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(shutdown3, 1); - =} - } - - mode Four { - reaction(startup) -> startup4 {= - printf("Startup 4 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(startup4, 1); - =} - - reaction(reset) -> reset4 {= - printf("Reset 4 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(reset4, 1); - =} - - reaction(next) -> reset(Four), mode_switch {= - printf("Transitioning to mode 4\n"); - lf_set(mode_switch, 4); - lf_set_mode(Four); - =} - - reaction(shutdown) -> shutdown4 {= - printf("Shutdown 4 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(shutdown4, 1); - =} - } - - mode Five { // Unreachable! - reaction(startup) -> startup5 {= - printf("Startup 5 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(startup5, 1); - =} - - reaction(reset) -> reset5 {= - printf("Reset 5 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(reset5, 1); - =} - - reaction(shutdown) -> shutdown5 {= - printf("Shutdown 5 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_set(shutdown5, 1); - =} - } + input next: bool + + output mode_switch: int + output startup1: int + output startup2: int + output shutdown2: int + output shutdown3: int + output startup4: int + output reset4: int + output shutdown4: int + output startup5: int + output reset5: int + output shutdown5: int + + initial mode One { + reaction(startup) -> startup1 {= + printf("Startup 1 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(startup1, 1); + =} + + reaction(next) -> reset(Two), mode_switch {= + printf("Transitioning to mode 1\n"); + lf_set(mode_switch, 2); + lf_set_mode(Two); + =} + } + + mode Two { + reaction(startup) -> startup2 {= + printf("Startup 2 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(startup2, 1); + =} + + reaction(next) -> reset(Three), mode_switch {= + printf("Transitioning to mode 3\n"); + lf_set(mode_switch, 3); + lf_set_mode(Three); + =} + + reaction(shutdown) -> shutdown2 {= + printf("Shutdown 2 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(shutdown2, 1); + =} + } + + mode Three { + reaction(next) -> reset(Four), mode_switch {= + printf("Transitioning to mode 4\n"); + lf_set(mode_switch, 4); + lf_set_mode(Four); + =} + + reaction(shutdown) -> shutdown3 {= + printf("Shutdown 3 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(shutdown3, 1); + =} + } + + mode Four { + reaction(startup) -> startup4 {= + printf("Startup 4 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(startup4, 1); + =} + + reaction(reset) -> reset4 {= + printf("Reset 4 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(reset4, 1); + =} + + reaction(next) -> reset(Four), mode_switch {= + printf("Transitioning to mode 4\n"); + lf_set(mode_switch, 4); + lf_set_mode(Four); + =} + + reaction(shutdown) -> shutdown4 {= + printf("Shutdown 4 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(shutdown4, 1); + =} + } + + mode Five { // Unreachable! + reaction(startup) -> startup5 {= + printf("Startup 5 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(startup5, 1); + =} + + reaction(reset) -> reset5 {= + printf("Reset 5 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(reset5, 1); + =} + + reaction(shutdown) -> shutdown5 {= + printf("Shutdown 5 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); + lf_set(shutdown5, 1); + =} + } } main reactor { - timer stepper(500 msec, 500 msec) - - modal = new Modal() - test = new TraceTesting( - events_size = 11, - trace_size = 253, - trace = { // keep-format - 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 500000000,1,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,2,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 500000000,1,3,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,4,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, - 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, - 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0 - }, - training = false - ) - - modal.mode_switch, - modal.startup1, - modal.startup2, - modal.shutdown2, - modal.shutdown3, - modal.startup4, - modal.reset4, - modal.shutdown4, - modal.startup5, - modal.reset5, - modal.shutdown5 - -> test.events - - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + timer stepper(500 msec, 500 msec) + + modal = new Modal() + test = new TraceTesting(events_size = 11, trace_size = 253, trace = { // keep-format + 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 500000000,1,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,2,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 500000000,1,3,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,4,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, + 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, + 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0 + }, training = false) + + modal.mode_switch, + modal.startup1, + modal.startup2, + modal.shutdown2, + modal.shutdown3, + modal.startup4, + modal.reset4, + modal.shutdown4, + modal.startup5, + modal.reset5, + modal.shutdown5 + -> test.events + + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change } diff --git a/test/C/src/modal_models/ModalStateReset.lf b/test/C/src/modal_models/ModalStateReset.lf index c098f088d5..46f94958cd 100644 --- a/test/C/src/modal_models/ModalStateReset.lf +++ b/test/C/src/modal_models/ModalStateReset.lf @@ -1,94 +1,88 @@ /** Modal Reactor Test. Tests reset of state variables in modes. */ target C { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool + input next: bool - output mode_switch: int - output count0: int - output count1: int - output count2: int + output mode_switch: int + output count0: int + output count1: int + output count2: int - state counter0: int = 0 + state counter0: int = 0 - reaction(next) -> count0 {= - printf("Counter0: %d\n", self->counter0); - lf_set(count0, self->counter0++); - =} + reaction(next) -> count0 {= + printf("Counter0: %d\n", self->counter0); + lf_set(count0, self->counter0++); + =} - initial mode One { - state counter1: int = 0 - timer T1(0 msec, 250 msec) - reaction(reset) {= self->counter1 = 0; =} + initial mode One { + state counter1: int = 0 + timer T1(0 msec, 250 msec) + reaction(reset) {= self->counter1 = 0; =} - reaction(T1) -> count1 {= - printf("Counter1: %d\n", self->counter1); - lf_set(count1, self->counter1++); - =} + reaction(T1) -> count1 {= + printf("Counter1: %d\n", self->counter1); + lf_set(count1, self->counter1++); + =} - reaction(next) -> reset(Two), mode_switch {= - printf("Transitioning to mode Two (reset)\n"); - lf_set(mode_switch, 1); - lf_set_mode(Two); - =} - } + reaction(next) -> reset(Two), mode_switch {= + printf("Transitioning to mode Two (reset)\n"); + lf_set(mode_switch, 1); + lf_set_mode(Two); + =} + } - mode Two { - state counter2: int = -2 - timer T2(0 msec, 250 msec) - reaction(reset) {= self->counter2 = -2; =} + mode Two { + state counter2: int = -2 + timer T2(0 msec, 250 msec) + reaction(reset) {= self->counter2 = -2; =} - reaction(T2) -> count2 {= - printf("Counter2: %d\n", self->counter2); - lf_set(count2, self->counter2++); - =} + reaction(T2) -> count2 {= + printf("Counter2: %d\n", self->counter2); + lf_set(count2, self->counter2++); + =} - reaction(next) -> history(One), mode_switch {= - printf("Transitioning to mode One (continue)\n"); - lf_set(mode_switch, 1); - lf_set_mode(One); - =} - } + reaction(next) -> history(One), mode_switch {= + printf("Transitioning to mode One (continue)\n"); + lf_set(mode_switch, 1); + lf_set_mode(One); + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting( - events_size = 4, - trace_size = 171, - trace = { // keep-format - 0,0,0,0,0,1,0,0,0, - 250000000,0,0,0,0,1,1,0,0, - 250000000,0,0,0,0,1,2,0,0, - 250000000,0,0,0,0,1,3,0,0, - 250000000,1,1,1,0,1,4,0,0, - 0,0,1,0,0,0,4,1,-2, - 250000000,0,1,0,0,0,4,1,-1, - 250000000,0,1,0,0,0,4,1,0, - 250000000,0,1,0,0,0,4,1,1, - 250000000,1,1,1,1,0,4,1,2, - 250000000,0,1,0,1,1,5,0,2, - 250000000,0,1,0,1,1,6,0,2, - 250000000,0,1,0,1,1,7,0,2, - 250000000,1,1,1,2,1,8,0,2, - 0,0,1,0,2,0,8,1,-2, - 250000000,0,1,0,2,0,8,1,-1, - 250000000,0,1,0,2,0,8,1,0, - 250000000,0,1,0,2,0,8,1,1, - 250000000,1,1,1,3,0,8,1,2 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 4, trace_size = 171, trace = { // keep-format + 0,0,0,0,0,1,0,0,0, + 250000000,0,0,0,0,1,1,0,0, + 250000000,0,0,0,0,1,2,0,0, + 250000000,0,0,0,0,1,3,0,0, + 250000000,1,1,1,0,1,4,0,0, + 0,0,1,0,0,0,4,1,-2, + 250000000,0,1,0,0,0,4,1,-1, + 250000000,0,1,0,0,0,4,1,0, + 250000000,0,1,0,0,0,4,1,1, + 250000000,1,1,1,1,0,4,1,2, + 250000000,0,1,0,1,1,5,0,2, + 250000000,0,1,0,1,1,6,0,2, + 250000000,0,1,0,1,1,7,0,2, + 250000000,1,1,1,2,1,8,0,2, + 0,0,1,0,2,0,8,1,-2, + 250000000,0,1,0,2,0,8,1,-1, + 250000000,0,1,0,2,0,8,1,0, + 250000000,0,1,0,2,0,8,1,1, + 250000000,1,1,1,3,0,8,1,2 + }, training = false) - modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events + modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change } diff --git a/test/C/src/modal_models/ModalStateResetAuto.lf b/test/C/src/modal_models/ModalStateResetAuto.lf index a82fd18212..be13d7b58e 100644 --- a/test/C/src/modal_models/ModalStateResetAuto.lf +++ b/test/C/src/modal_models/ModalStateResetAuto.lf @@ -1,90 +1,84 @@ /** Modal Reactor Test. Tests reset of state variables in modes. */ target C { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool + input next: bool - output mode_switch: int - output count0: int - output count1: int - output count2: int + output mode_switch: int + output count0: int + output count1: int + output count2: int - state counter0: int = 0 + state counter0: int = 0 - reaction(next) -> count0 {= - printf("Counter0: %d\n", self->counter0); - lf_set(count0, self->counter0++); - =} + reaction(next) -> count0 {= + printf("Counter0: %d\n", self->counter0); + lf_set(count0, self->counter0++); + =} - initial mode One { - state counter1: int = 0 - timer T1(0 msec, 250 msec) - reaction(T1) -> count1 {= - printf("Counter1: %d\n", self->counter1); - lf_set(count1, self->counter1++); - =} + initial mode One { + state counter1: int = 0 + timer T1(0 msec, 250 msec) + reaction(T1) -> count1 {= + printf("Counter1: %d\n", self->counter1); + lf_set(count1, self->counter1++); + =} - reaction(next) -> reset(Two), mode_switch {= - printf("Transitioning to mode Two (reset)\n"); - lf_set(mode_switch, 1); - lf_set_mode(Two); - =} - } + reaction(next) -> reset(Two), mode_switch {= + printf("Transitioning to mode Two (reset)\n"); + lf_set(mode_switch, 1); + lf_set_mode(Two); + =} + } - mode Two { - reset state counter2: int = -2 - timer T2(0 msec, 250 msec) - reaction(T2) -> count2 {= - printf("Counter2: %d\n", self->counter2); - lf_set(count2, self->counter2++); - =} + mode Two { + reset state counter2: int = -2 + timer T2(0 msec, 250 msec) + reaction(T2) -> count2 {= + printf("Counter2: %d\n", self->counter2); + lf_set(count2, self->counter2++); + =} - reaction(next) -> history(One), mode_switch {= - printf("Transitioning to mode One (continue)\n"); - lf_set(mode_switch, 1); - lf_set_mode(One); - =} - } + reaction(next) -> history(One), mode_switch {= + printf("Transitioning to mode One (continue)\n"); + lf_set(mode_switch, 1); + lf_set_mode(One); + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting( - events_size = 4, - trace_size = 171, - trace = { // keep-format - 0,0,0,0,0,1,0,0,0, - 250000000,0,0,0,0,1,1,0,0, - 250000000,0,0,0,0,1,2,0,0, - 250000000,0,0,0,0,1,3,0,0, - 250000000,1,1,1,0,1,4,0,0, - 0,0,1,0,0,0,4,1,-2, - 250000000,0,1,0,0,0,4,1,-1, - 250000000,0,1,0,0,0,4,1,0, - 250000000,0,1,0,0,0,4,1,1, - 250000000,1,1,1,1,0,4,1,2, - 250000000,0,1,0,1,1,5,0,2, - 250000000,0,1,0,1,1,6,0,2, - 250000000,0,1,0,1,1,7,0,2, - 250000000,1,1,1,2,1,8,0,2, - 0,0,1,0,2,0,8,1,-2, - 250000000,0,1,0,2,0,8,1,-1, - 250000000,0,1,0,2,0,8,1,0, - 250000000,0,1,0,2,0,8,1,1, - 250000000,1,1,1,3,0,8,1,2 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 4, trace_size = 171, trace = { // keep-format + 0,0,0,0,0,1,0,0,0, + 250000000,0,0,0,0,1,1,0,0, + 250000000,0,0,0,0,1,2,0,0, + 250000000,0,0,0,0,1,3,0,0, + 250000000,1,1,1,0,1,4,0,0, + 0,0,1,0,0,0,4,1,-2, + 250000000,0,1,0,0,0,4,1,-1, + 250000000,0,1,0,0,0,4,1,0, + 250000000,0,1,0,0,0,4,1,1, + 250000000,1,1,1,1,0,4,1,2, + 250000000,0,1,0,1,1,5,0,2, + 250000000,0,1,0,1,1,6,0,2, + 250000000,0,1,0,1,1,7,0,2, + 250000000,1,1,1,2,1,8,0,2, + 0,0,1,0,2,0,8,1,-2, + 250000000,0,1,0,2,0,8,1,-1, + 250000000,0,1,0,2,0,8,1,0, + 250000000,0,1,0,2,0,8,1,1, + 250000000,1,1,1,3,0,8,1,2 + }, training = false) - modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events + modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change } diff --git a/test/C/src/modal_models/ModalTimers.lf b/test/C/src/modal_models/ModalTimers.lf index 954a677de4..0ceaddd3a6 100644 --- a/test/C/src/modal_models/ModalTimers.lf +++ b/test/C/src/modal_models/ModalTimers.lf @@ -1,72 +1,66 @@ /** Modal Reactor Test. Tests timers, their deactivation and reset in modes. */ target C { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool + input next: bool - output mode_switch: int - output timer1: int - output timer2: int + output mode_switch: int + output timer1: int + output timer2: int - initial mode One { - timer T1(0, 750 msec) - reaction(T1) -> timer1 {= - printf("T1\n"); - lf_set(timer1, 1); - =} + initial mode One { + timer T1(0, 750 msec) + reaction(T1) -> timer1 {= + printf("T1\n"); + lf_set(timer1, 1); + =} - reaction(next) -> reset(Two), mode_switch {= - printf("Transitioning to mode Two (reset)\n"); - lf_set(mode_switch, 1); - lf_set_mode(Two); - =} - } + reaction(next) -> reset(Two), mode_switch {= + printf("Transitioning to mode Two (reset)\n"); + lf_set(mode_switch, 1); + lf_set_mode(Two); + =} + } - mode Two { - timer T2(0, 750 msec) - reaction(T2) -> timer2 {= - printf("T2\n"); - lf_set(timer2, 1); - =} + mode Two { + timer T2(0, 750 msec) + reaction(T2) -> timer2 {= + printf("T2\n"); + lf_set(timer2, 1); + =} - reaction(next) -> history(One), mode_switch {= - printf("Transitioning to mode One (continue)\n"); - lf_set(mode_switch, 1); - lf_set_mode(One); - =} - } + reaction(next) -> history(One), mode_switch {= + printf("Transitioning to mode One (continue)\n"); + lf_set(mode_switch, 1); + lf_set_mode(One); + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting( - events_size = 3, - trace_size = 77, - trace = { // keep-format - 0,0,0,1,1,0,0, - 750000000,0,0,1,1,0,0, - 250000000,1,1,0,1,0,0, - 0,0,1,0,1,1,1, - 750000000,0,1,0,1,1,1, - 250000000,1,1,0,1,0,1, - 500000000,0,1,1,1,0,1, - 500000000,1,1,0,1,0,1, - 0,0,1,0,1,1,1, - 750000000,0,1,0,1,1,1, - 250000000,1,1,0,1,0,1 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 3, trace_size = 77, trace = { // keep-format + 0,0,0,1,1,0,0, + 750000000,0,0,1,1,0,0, + 250000000,1,1,0,1,0,0, + 0,0,1,0,1,1,1, + 750000000,0,1,0,1,1,1, + 250000000,1,1,0,1,0,1, + 500000000,0,1,1,1,0,1, + 500000000,1,1,0,1,0,1, + 0,0,1,0,1,1,1, + 750000000,0,1,0,1,1,1, + 250000000,1,1,0,1,0,1 + }, training = false) - modal.mode_switch, modal.timer1, modal.timer2 -> test.events + modal.mode_switch, modal.timer1, modal.timer2 -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change } diff --git a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf index 31de4fe6bd..198ba0fd37 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -1,76 +1,69 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work - * if they are located in separate modes. + * Tests if connections in the same reactor that have the same destination work if they are located + * in separate modes. */ target C { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool - output count: int + input next: bool + output count: int - initial mode One { - counter1 = new Counter(period = 250 msec) - counter1.value -> count - reaction(next) -> reset(Two) {= lf_set_mode(Two); =} - } + initial mode One { + counter1 = new Counter(period = 250 msec) + counter1.value -> count + reaction(next) -> reset(Two) {= lf_set_mode(Two); =} + } - mode Two { - counter2 = new Counter(period = 100 msec) - counter2.value -> count - reaction(next) -> history(One) {= lf_set_mode(One); =} - } + mode Two { + counter2 = new Counter(period = 100 msec) + counter2.value -> count + reaction(next) -> history(One) {= lf_set_mode(One); =} + } } reactor Counter(period: time = 1 sec) { - output value: int + output value: int - timer t(0, period) - reset state curval: int = 0 + timer t(0, period) + reset state curval: int = 0 - reaction(t) -> value {= lf_set(value, self->curval++); =} + reaction(t) -> value {= lf_set(value, self->curval++); =} } main reactor { - timer stepper(500 msec, 500 msec) + timer stepper(500 msec, 500 msec) - modal = new Modal() - test = new TraceTesting( - events_size = 1, - trace_size = 51, - trace = { // keep-format - 0,1,0, - 250000000,1,1, - 250000000,1,2, - 0,1,0, - 100000000,1,1, - 100000000,1,2, - 100000000,1,3, - 100000000,1,4, - 100000000,1,5, - 250000000,1,3, - 250000000,1,4, - 0,1,0, - 100000000,1,1, - 100000000,1,2, - 100000000,1,3, - 100000000,1,4, - 100000000,1,5 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 1, trace_size = 51, trace = { // keep-format + 0,1,0, + 250000000,1,1, + 250000000,1,2, + 0,1,0, + 100000000,1,1, + 100000000,1,2, + 100000000,1,3, + 100000000,1,4, + 100000000,1,5, + 250000000,1,3, + 250000000,1,4, + 0,1,0, + 100000000,1,1, + 100000000,1,2, + 100000000,1,3, + 100000000,1,4, + 100000000,1,5 + }, training = false) - modal.count -> test.events + modal.count -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change - // Print - reaction(modal.count) {= printf("%d\n", modal.count->value); =} + reaction(modal.count) {= printf("%d\n", modal.count->value); =} // Print } diff --git a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index f89073dfc1..fe3c4dde17 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -1,79 +1,70 @@ /** * Modal Reactor Test. * - * Tests if a connection and a reaction in the same reactor can have the same - * destination if they are located in separate modes. + * Tests if a connection and a reaction in the same reactor can have the same destination if they + * are located in separate modes. */ target C { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next: bool - output count: int + input next: bool + output count: int - initial mode One { - counter1 = new Counter(period = 250 msec) - counter1.value -> count - reaction(next) -> reset(Two) {= lf_set_mode(Two); =} - } + initial mode One { + counter1 = new Counter(period = 250 msec) + counter1.value -> count + reaction(next) -> reset(Two) {= lf_set_mode(Two); =} + } - mode Two { - counter2 = new Counter(period = 100 msec) - reaction(counter2.value) -> count {= - lf_set(count, counter2.value->value * 10); - =} + mode Two { + counter2 = new Counter(period = 100 msec) + reaction(counter2.value) -> count {= lf_set(count, counter2.value->value * 10); =} - reaction(next) -> history(One) {= lf_set_mode(One); =} - } + reaction(next) -> history(One) {= lf_set_mode(One); =} + } } reactor Counter(period: time = 1 sec) { - output value: int + output value: int - timer t(0, period) - reset state curval: int = 0 + timer t(0, period) + reset state curval: int = 0 - reaction(t) -> value {= lf_set(value, self->curval++); =} + reaction(t) -> value {= lf_set(value, self->curval++); =} } main reactor { - timer stepper(500 msec, 500 msec) + timer stepper(500 msec, 500 msec) - modal = new Modal() - test = new TraceTesting( - events_size = 1, - trace_size = 51, - trace = { // keep-format - 0,1,0, - 250000000,1,1, - 250000000,1,2, - 0,1,0, - 100000000,1,10, - 100000000,1,20, - 100000000,1,30, - 100000000,1,40, - 100000000,1,50, - 250000000,1,3, - 250000000,1,4, - 0,1,0, - 100000000,1,10, - 100000000,1,20, - 100000000,1,30, - 100000000,1,40, - 100000000,1,50 - }, - training = false - ) + modal = new Modal() + test = new TraceTesting(events_size = 1, trace_size = 51, trace = { // keep-format + 0,1,0, + 250000000,1,1, + 250000000,1,2, + 0,1,0, + 100000000,1,10, + 100000000,1,20, + 100000000,1,30, + 100000000,1,40, + 100000000,1,50, + 250000000,1,3, + 250000000,1,4, + 0,1,0, + 100000000,1,10, + 100000000,1,20, + 100000000,1,30, + 100000000,1,40, + 100000000,1,50 + }, training = false) - modal.count -> test.events + modal.count -> test.events - // Trigger mode change - reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} + reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} // Trigger mode change - // Print - reaction(modal.count) {= printf("%d\n", modal.count->value); =} + reaction(modal.count) {= printf("%d\n", modal.count->value); =} // Print } diff --git a/test/C/src/modal_models/util/TraceTesting.lf b/test/C/src/modal_models/util/TraceTesting.lf index c63de35f2a..38b78b4173 100644 --- a/test/C/src/modal_models/util/TraceTesting.lf +++ b/test/C/src/modal_models/util/TraceTesting.lf @@ -2,79 +2,79 @@ target C reactor TraceTesting( - events_size: int = 0, - trace_size: int = 0, - trace: int[] = 0, - training: bool = false + events_size: int = 0, + trace_size: int = 0, + trace: int[] = 0, + training: bool = false ) { - input[events_size] events: int + input[events_size] events: int - state last_reaction_time: int = 0 - state trace_idx: int = 0 - state recorded_events: int* = 0 - state recorded_events_next: int = 0 + state last_reaction_time: int = 0 + state trace_idx: int = 0 + state recorded_events: int* = 0 + state recorded_events_next: int = 0 - reaction(startup) {= self->last_reaction_time = lf_time_logical(); =} + reaction(startup) {= self->last_reaction_time = lf_time_logical(); =} - reaction(events) {= - // Time passed since last reaction - int curr_reaction_delay = lf_time_logical() - self->last_reaction_time; + reaction(events) {= + // Time passed since last reaction + int curr_reaction_delay = lf_time_logical() - self->last_reaction_time; - if (self->training) { - // Save time - self->recorded_events = (int*) realloc(self->recorded_events, sizeof(int) * (self->recorded_events_next + 1 + 2 * self->events_size)); - self->recorded_events[self->recorded_events_next++] = curr_reaction_delay; - } else { - if (self->trace_idx >= self->trace_size) { - printf("ERROR: Trace Error: Current execution exceeds given trace.\n"); - exit(1); - } + if (self->training) { + // Save time + self->recorded_events = (int*) realloc(self->recorded_events, sizeof(int) * (self->recorded_events_next + 1 + 2 * self->events_size)); + self->recorded_events[self->recorded_events_next++] = curr_reaction_delay; + } else { + if (self->trace_idx >= self->trace_size) { + printf("ERROR: Trace Error: Current execution exceeds given trace.\n"); + exit(1); + } - int trace_reaction_delay = self->trace[self->trace_idx++]; + int trace_reaction_delay = self->trace[self->trace_idx++]; - if (curr_reaction_delay != trace_reaction_delay) { - printf("ERROR: Trace Mismatch: Unexpected reaction timing. (delay: %d, expected: %d)\n", curr_reaction_delay, trace_reaction_delay); - exit(2); - } + if (curr_reaction_delay != trace_reaction_delay) { + printf("ERROR: Trace Mismatch: Unexpected reaction timing. (delay: %d, expected: %d)\n", curr_reaction_delay, trace_reaction_delay); + exit(2); } + } - for (int i = 0; i < self->events_size; i++) { - int curr_present = events[i]->is_present; - int curr_value = events[i]->value; + for (int i = 0; i < self->events_size; i++) { + int curr_present = events[i]->is_present; + int curr_value = events[i]->value; - if (self->training) { - // Save event - self->recorded_events[self->recorded_events_next++] = curr_present; - self->recorded_events[self->recorded_events_next++] = curr_value; - } else { - int trace_present = self->trace[self->trace_idx++]; - int trace_value = self->trace[self->trace_idx++]; + if (self->training) { + // Save event + self->recorded_events[self->recorded_events_next++] = curr_present; + self->recorded_events[self->recorded_events_next++] = curr_value; + } else { + int trace_present = self->trace[self->trace_idx++]; + int trace_value = self->trace[self->trace_idx++]; - if (trace_present != curr_present) { - printf("ERROR: Trace Mismatch: Unexpected event presence. (event: %d, presence: %d, expected: %d)\n", i, curr_present, trace_present); - exit(3); - } else if (curr_present && trace_value != curr_value) { - printf("ERROR: Trace Mismatch: Unexpected event value. (event: %d, presence: %d, expected: %d)\n", i, curr_value, trace_value); - exit(4); - } + if (trace_present != curr_present) { + printf("ERROR: Trace Mismatch: Unexpected event presence. (event: %d, presence: %d, expected: %d)\n", i, curr_present, trace_present); + exit(3); + } else if (curr_present && trace_value != curr_value) { + printf("ERROR: Trace Mismatch: Unexpected event value. (event: %d, presence: %d, expected: %d)\n", i, curr_value, trace_value); + exit(4); } } + } - self->last_reaction_time = lf_time_logical(); - =} + self->last_reaction_time = lf_time_logical(); + =} - reaction(shutdown) {= - if (self->training) { - printf("Recorded event trace (%d): (", self->recorded_events_next); - for (int i = 0; i < self->recorded_events_next; i++) { - printf("%d", self->recorded_events[i]); - if (i < self->recorded_events_next - 1) { - printf(","); - } + reaction(shutdown) {= + if (self->training) { + printf("Recorded event trace (%d): (", self->recorded_events_next); + for (int i = 0; i < self->recorded_events_next; i++) { + printf("%d", self->recorded_events[i]); + if (i < self->recorded_events_next - 1) { + printf(","); } - printf(")\n"); - - free(self->recorded_events); } - =} + printf(")\n"); + + free(self->recorded_events); + } + =} } diff --git a/test/C/src/multiport/BankIndexInitializer.lf b/test/C/src/multiport/BankIndexInitializer.lf index e6c52e8efe..4c24c2d92b 100644 --- a/test/C/src/multiport/BankIndexInitializer.lf +++ b/test/C/src/multiport/BankIndexInitializer.lf @@ -4,38 +4,38 @@ target C preamble {= extern int table[4]; =} reactor Source(bank_index: int = 0, value: int = 0) { - preamble {= int table[] = {4, 3, 2, 1}; =} + preamble {= int table[] = {4, 3, 2, 1}; =} - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, self->value); =} + reaction(startup) -> out {= lf_set(out, self->value); =} } reactor Sink(width: int = 4) { - input[width] in: int - state received: bool = false - - reaction(in) {= - for (int idx = 0; idx < in_width; idx++) { - if (in[idx]->is_present) { - printf("Received on channel %d: %d\n", idx, in[idx]->value); - self->received = true; - if (in[idx]->value != 4 - idx) { - lf_print_error_and_exit("Expected %d.", 4 - idx); - } + input[width] in: int + state received: bool = false + + reaction(in) {= + for (int idx = 0; idx < in_width; idx++) { + if (in[idx]->is_present) { + printf("Received on channel %d: %d\n", idx, in[idx]->value); + self->received = true; + if (in[idx]->value != 4 - idx) { + lf_print_error_and_exit("Expected %d.", 4 - idx); } } - =} - - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("Sink received no data."); - } - =} + } + =} + + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("Sink received no data."); + } + =} } main reactor(width: int = 4) { - source = new[width] Source(value = {= table[bank_index] =}) - sink = new Sink(width = width) - source.out -> sink.in + source = new[width] Source(value = {= table[bank_index] =}) + sink = new Sink(width = width) + source.out -> sink.in } diff --git a/test/C/src/multiport/BankMultiportToReaction.lf b/test/C/src/multiport/BankMultiportToReaction.lf index 731cd6891b..c5923c7073 100644 --- a/test/C/src/multiport/BankMultiportToReaction.lf +++ b/test/C/src/multiport/BankMultiportToReaction.lf @@ -1,41 +1,41 @@ target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } import Count from "../lib/Count.lf" reactor DoubleCount { - output[2] out: int - c1 = new Count() - c2 = new Count() - c1.out, c2.out -> out + output[2] out: int + c1 = new Count() + c2 = new Count() + c1.out, c2.out -> out } main reactor { - state count: int = 1 - state received: bool = false + state count: int = 1 + state received: bool = false - s = new[2] DoubleCount() + s = new[2] DoubleCount() - reaction(s.out) {= - for (int i = 0; i < s_width; i++) { - for (int j = 0; j < s[0].out_width; j++) { - if (s[i].out[j]->is_present) { - lf_print("Received %d.", s[i].out[j]->value); - if (self->count != s[i].out[j]->value) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->received = true; + reaction(s.out) {= + for (int i = 0; i < s_width; i++) { + for (int j = 0; j < s[0].out_width; j++) { + if (s[i].out[j]->is_present) { + lf_print("Received %d.", s[i].out[j]->value); + if (self->count != s[i].out[j]->value) { + lf_print_error_and_exit("Expected %d.", self->count); } + self->received = true; } } - self->count++; - =} + } + self->count++; + =} - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("No inputs present."); - } - =} + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("No inputs present."); + } + =} } diff --git a/test/C/src/multiport/BankReactionsInContainer.lf b/test/C/src/multiport/BankReactionsInContainer.lf index 98d7cf4e1f..71d566ac4b 100644 --- a/test/C/src/multiport/BankReactionsInContainer.lf +++ b/test/C/src/multiport/BankReactionsInContainer.lf @@ -1,77 +1,75 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target C { - timeout: 1 sec + timeout: 1 sec } reactor R(bank_index: int = 0) { - output[2] out: int - input[2] in: int - state received: bool = false + output[2] out: int + input[2] in: int + state received: bool = false - reaction(startup) -> out {= - for (int i = 0; i < out_width; i++) { - int value = self->bank_index * 2 + i; - lf_set(out[i], value); - lf_print("Inner sending %d to bank %d channel %d.", - value, self->bank_index, i - ); - } - =} + reaction(startup) -> out {= + for (int i = 0; i < out_width; i++) { + int value = self->bank_index * 2 + i; + lf_set(out[i], value); + lf_print("Inner sending %d to bank %d channel %d.", + value, self->bank_index, i + ); + } + =} - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - lf_print("Inner received %d in bank %d, channel %d", in[i]->value, self->bank_index, i); - self->received = true; - if (in[i]->value != self->bank_index * 2 + i) { - lf_print_error_and_exit("Expected %d.", self->bank_index * 2 + i); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + lf_print("Inner received %d in bank %d, channel %d", in[i]->value, self->bank_index, i); + self->received = true; + if (in[i]->value != self->bank_index * 2 + i) { + lf_print_error_and_exit("Expected %d.", self->bank_index * 2 + i); } } - =} + } + =} - reaction(shutdown) {= - lf_print("Inner shutdown invoked."); - if (!self->received) { - lf_print_error_and_exit("Received no input."); - } - =} + reaction(shutdown) {= + lf_print("Inner shutdown invoked."); + if (!self->received) { + lf_print_error_and_exit("Received no input."); + } + =} } main reactor { - s = new[2] R() - state received: bool = false + s = new[2] R() + state received: bool = false - reaction(startup) -> s.in {= - int count = 0; - for (int i = 0; i < s_width; i++) { - for (int j = 0; j < s[i].in_width; j++) { - lf_print("Sending %d to bank %d channel %d.", count, i, j); - lf_set(s[i].in[j], count++); - } + reaction(startup) -> s.in {= + int count = 0; + for (int i = 0; i < s_width; i++) { + for (int j = 0; j < s[i].in_width; j++) { + lf_print("Sending %d to bank %d channel %d.", count, i, j); + lf_set(s[i].in[j], count++); } - =} + } + =} - reaction(s.out) {= - for (int j = 0; j < s_width; j++) { - for (int i = 0; i < s[j].out_width; i++) { - if (s[j].out[i]->is_present) { - lf_print("Outer received %d on bank %d channel %d.", s[j].out[i]->value, j, i); - self->received = true; - if (s[j].out[i]->value != j * 2 + i) { - lf_print_error_and_exit("Expected %d.", j * 2 + i); - } + reaction(s.out) {= + for (int j = 0; j < s_width; j++) { + for (int i = 0; i < s[j].out_width; i++) { + if (s[j].out[i]->is_present) { + lf_print("Outer received %d on bank %d channel %d.", s[j].out[i]->value, j, i); + self->received = true; + if (s[j].out[i]->value != j * 2 + i) { + lf_print_error_and_exit("Expected %d.", j * 2 + i); } } } - =} + } + =} - reaction(shutdown) {= - lf_print("Outer shutdown invoked."); - if (!self->received) { - lf_print_error_and_exit("Received no input."); - } - =} + reaction(shutdown) {= + lf_print("Outer shutdown invoked."); + if (!self->received) { + lf_print_error_and_exit("Received no input."); + } + =} } diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index e1ffb4b2dd..52b7a678f2 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -1,48 +1,48 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport - * input of the same reactors in the bank so that each reactor in the bank - * receives the output produced by itself and each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport input of the same + * reactors in the bank so that each reactor in the bank receives the output produced by itself and + * each other reactor. * * @author Edward A. Lee */ target C reactor A(bank_index: int = 0) { - input[4] in: int - output out: int - state received: bool = false + input[4] in: int + output out: int + state received: bool = false - reaction(startup) -> out {= lf_set(out, self->bank_index); =} + reaction(startup) -> out {= lf_set(out, self->bank_index); =} - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - lf_print( - "Reactor %d received %d on channel %d.", - self->bank_index, in[i]->value, i - ); - if (in[i]->value != i) { - lf_print_error_and_exit("Expected %d.", i); - } - self->received = true; - } else { - lf_print( - "Reactor %d channel %d is absent.", - self->bank_index, i - ); + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + lf_print( + "Reactor %d received %d on channel %d.", + self->bank_index, in[i]->value, i + ); + if (in[i]->value != i) { lf_print_error_and_exit("Expected %d.", i); } + self->received = true; + } else { + lf_print( + "Reactor %d channel %d is absent.", + self->bank_index, i + ); + lf_print_error_and_exit("Expected %d.", i); } - =} + } + =} - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("No inputs received."); - } - =} + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("No inputs received."); + } + =} } main reactor { - a = new[4] A() - (a.out)+ -> a.in + a = new[4] A() + (a.out)+ -> a.in } diff --git a/test/C/src/multiport/BankToBank.lf b/test/C/src/multiport/BankToBank.lf index beb3a32fa8..0b2c2ff5b5 100644 --- a/test/C/src/multiport/BankToBank.lf +++ b/test/C/src/multiport/BankToBank.lf @@ -1,44 +1,44 @@ // Check bank of reactors sending to bank of reactors. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(bank_index: int = 0) { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - lf_set(out, self->s); - self->s += self->bank_index; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s += self->bank_index; + =} } reactor Destination(bank_index: int = 0) { - state s: int = 0 - input in: int + state s: int = 0 + input in: int - reaction(in) {= - printf("Destination %d received: %d.\n", self->bank_index, in->value); - if (in->value != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += self->bank_index; - =} + reaction(in) {= + printf("Destination %d received: %d.\n", self->bank_index, in->value); + if (in->value != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += self->bank_index; + =} - reaction(shutdown) {= - if (self->s == 0 && self->bank_index != 0) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s == 0 && self->bank_index != 0) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(1); + } + printf("Success.\n"); + =} } main reactor BankToBank(width: int = 4) { - a = new[width] Source() - b = new[width] Destination() - a.out -> b.in + a = new[width] Source() + b = new[width] Destination() + a.out -> b.in } diff --git a/test/C/src/multiport/BankToBankMultiport.lf b/test/C/src/multiport/BankToBankMultiport.lf index 681538f116..502e5ed064 100644 --- a/test/C/src/multiport/BankToBankMultiport.lf +++ b/test/C/src/multiport/BankToBankMultiport.lf @@ -1,49 +1,49 @@ // Check bank of reactors sending to bank of reactors with multiports. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 1) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], self->s++); - } - =} + reaction(t) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s++); + } + =} } reactor Destination(width: int = 1) { - state s: int = 6 - input[width] in: int + state s: int = 6 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor BankToBankMultiport(bank_width: int = 4) { - a = new[bank_width] Source(width = 4) - b = new[bank_width] Destination(width = 4) - a.out -> b.in + a = new[bank_width] Source(width = 4) + b = new[bank_width] Destination(width = 4) + a.out -> b.in } diff --git a/test/C/src/multiport/BankToBankMultiportAfter.lf b/test/C/src/multiport/BankToBankMultiportAfter.lf index db0ff7771e..9338be1f8c 100644 --- a/test/C/src/multiport/BankToBankMultiportAfter.lf +++ b/test/C/src/multiport/BankToBankMultiportAfter.lf @@ -1,49 +1,49 @@ // Check bank of reactors sending to bank of reactors with multiports. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 1) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], self->s++); - } - =} + reaction(t) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s++); + } + =} } reactor Destination(width: int = 1) { - state s: int = 6 - input[width] in: int + state s: int = 6 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor(bank_width: int = 4) { - a = new[bank_width] Source(width = 4) - b = new[bank_width] Destination(width = 4) - a.out -> b.in after 200 msec + a = new[bank_width] Source(width = 4) + b = new[bank_width] Destination(width = 4) + a.out -> b.in after 200 msec } diff --git a/test/C/src/multiport/BankToMultiport.lf b/test/C/src/multiport/BankToMultiport.lf index f72c104df7..b45d812974 100644 --- a/test/C/src/multiport/BankToMultiport.lf +++ b/test/C/src/multiport/BankToMultiport.lf @@ -2,38 +2,38 @@ target C reactor Source(bank_index: int = 0) { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, self->bank_index); =} + reaction(startup) -> out {= lf_set(out, self->bank_index); =} } reactor Sink(width: int = 4) { - input[width] in: int - state received: bool = false + input[width] in: int + state received: bool = false - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - printf("Received on channel %d: %d\n", i, in[i]->value); - self->received = true; - if (in[i]->value != i) { - fprintf(stderr, "ERROR: expected %d\n", i); - exit(1); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + printf("Received on channel %d: %d\n", i, in[i]->value); + self->received = true; + if (in[i]->value != i) { + fprintf(stderr, "ERROR: expected %d\n", i); + exit(1); } } - =} + } + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Sink received no data\n"); - exit(1); - } - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Sink received no data\n"); + exit(1); + } + =} } main reactor BankToMultiport(width: int = 5) { - source = new[width] Source() - sink = new Sink(width = width) - source.out -> sink.in + source = new[width] Source() + sink = new Sink(width = width) + source.out -> sink.in } diff --git a/test/C/src/multiport/BankToReaction.lf b/test/C/src/multiport/BankToReaction.lf index 4e59352bd5..59c3282a36 100644 --- a/test/C/src/multiport/BankToReaction.lf +++ b/test/C/src/multiport/BankToReaction.lf @@ -1,22 +1,22 @@ target C { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } import Count from "../lib/Count.lf" main reactor { - state count: int = 1 + state count: int = 1 - s = new[2] Count() + s = new[2] Count() - reaction(s.out) {= - for (int i = 0; i < s_width; i++) { - lf_print("Received %d.", s[i].out->value); - if (self->count != s[i].out->value) { - lf_print_error_and_exit("Expected %d.", self->count); - } + reaction(s.out) {= + for (int i = 0; i < s_width; i++) { + lf_print("Received %d.", s[i].out->value); + if (self->count != s[i].out->value) { + lf_print_error_and_exit("Expected %d.", self->count); } - self->count++; - =} + } + self->count++; + =} } diff --git a/test/C/src/multiport/Broadcast.lf b/test/C/src/multiport/Broadcast.lf index e3471da5f6..d2b4b34d48 100644 --- a/test/C/src/multiport/Broadcast.lf +++ b/test/C/src/multiport/Broadcast.lf @@ -1,38 +1,38 @@ target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - if (in->value != 42) { - printf("ERROR: Expected 42.\n"); - exit(1); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + if (in->value != 42) { + printf("ERROR: Expected 42.\n"); + exit(1); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(1); + } + printf("Success.\n"); + =} } main reactor { - a = new Source() - b = new[4] Destination() - (a.out)+ -> b.in + a = new Source() + b = new[4] Destination() + (a.out)+ -> b.in } diff --git a/test/C/src/multiport/BroadcastAfter.lf b/test/C/src/multiport/BroadcastAfter.lf index c1be635e55..cb3c9306f6 100644 --- a/test/C/src/multiport/BroadcastAfter.lf +++ b/test/C/src/multiport/BroadcastAfter.lf @@ -1,42 +1,42 @@ target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, 42); =} + reaction(startup) -> out {= lf_set(out, 42); =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - if (in->value != 42) { - printf("ERROR: Expected 42.\n"); - exit(1); - } - if (lf_time_logical_elapsed() != SEC(1)) { - printf("ERROR: Expected to receive input after one second.\n"); - exit(2); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + if (in->value != 42) { + printf("ERROR: Expected 42.\n"); + exit(1); + } + if (lf_time_logical_elapsed() != SEC(1)) { + printf("ERROR: Expected to receive input after one second.\n"); + exit(2); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(3); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(3); + } + printf("Success.\n"); + =} } main reactor { - a = new Source() - b = new[4] Destination() - (a.out)+ -> b.in after 1 sec + a = new Source() + b = new[4] Destination() + (a.out)+ -> b.in after 1 sec } diff --git a/test/C/src/multiport/BroadcastMultipleAfter.lf b/test/C/src/multiport/BroadcastMultipleAfter.lf index 97d853e4ce..6304f27492 100644 --- a/test/C/src/multiport/BroadcastMultipleAfter.lf +++ b/test/C/src/multiport/BroadcastMultipleAfter.lf @@ -1,45 +1,45 @@ target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(value: int = 42) { - output out: int + output out: int - reaction(startup) -> out {= lf_set(out, self->value); =} + reaction(startup) -> out {= lf_set(out, self->value); =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - int expected = (self->bank_index % 3) + 1; - if (in->value != expected) { - printf("ERROR: Expected %d.\n", expected); - exit(1); - } - if (lf_time_logical_elapsed() != SEC(1)) { - printf("ERROR: Expected to receive input after one second.\n"); - exit(2); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + int expected = (self->bank_index % 3) + 1; + if (in->value != expected) { + printf("ERROR: Expected %d.\n", expected); + exit(1); + } + if (lf_time_logical_elapsed() != SEC(1)) { + printf("ERROR: Expected to receive input after one second.\n"); + exit(2); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(3); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(3); + } + printf("Success.\n"); + =} } main reactor { - a1 = new Source(value = 1) - a2 = new Source(value = 2) - a3 = new Source(value = 3) - b = new[9] Destination() - (a1.out, a2.out, a3.out)+ -> b.in after 1 sec + a1 = new Source(value = 1) + a2 = new Source(value = 2) + a3 = new Source(value = 3) + b = new[9] Destination() + (a1.out, a2.out, a3.out)+ -> b.in after 1 sec } diff --git a/test/C/src/multiport/DualBanks.lf b/test/C/src/multiport/DualBanks.lf index 3cb5d38887..f674626dc8 100644 --- a/test/C/src/multiport/DualBanks.lf +++ b/test/C/src/multiport/DualBanks.lf @@ -1,42 +1,42 @@ target C reactor Base(bank_index: int = 0) { - input I: int - state received: bool = false + input I: int + state received: bool = false - reaction(shutdown) {= - if(!self->received) { - lf_print_error_and_exit("Bank member %d received no input.", - self->bank_index - ); - } - =} + reaction(shutdown) {= + if(!self->received) { + lf_print_error_and_exit("Bank member %d received no input.", + self->bank_index + ); + } + =} } reactor Hello extends Base { - reaction(I) {= - printf("Hello %d\n", self->bank_index); - self->received = true; - =} + reaction(I) {= + printf("Hello %d\n", self->bank_index); + self->received = true; + =} } reactor World extends Base { - reaction(I) {= - printf("World %d\n", self->bank_index); - self->received = true; - =} + reaction(I) {= + printf("World %d\n", self->bank_index); + self->received = true; + =} } main reactor { - hellos = new[3] Hello() - worlds = new[3] World() + hellos = new[3] Hello() + worlds = new[3] World() - reaction(startup) -> hellos.I, worlds.I {= - for(int i = 0; i < hellos_width; i++) { - lf_set(hellos[i].I, true); - } - for(int i = 0; i < worlds_width; i++) { - lf_set(worlds[i].I, true); - } - =} + reaction(startup) -> hellos.I, worlds.I {= + for(int i = 0; i < hellos_width; i++) { + lf_set(hellos[i].I, true); + } + for(int i = 0; i < worlds_width; i++) { + lf_set(worlds[i].I, true); + } + =} } diff --git a/test/C/src/multiport/DualBanksMultiport.lf b/test/C/src/multiport/DualBanksMultiport.lf index a5c2120a79..d1975b6789 100644 --- a/test/C/src/multiport/DualBanksMultiport.lf +++ b/test/C/src/multiport/DualBanksMultiport.lf @@ -1,48 +1,48 @@ target C reactor Base(bank_index: int = 0) { - input[2] I: int - state received: bool = false + input[2] I: int + state received: bool = false - reaction(shutdown) {= - if(!self->received) { - lf_print_error_and_exit("Bank member %d did not receive all inputs.", - self->bank_index - ); - } - =} + reaction(shutdown) {= + if(!self->received) { + lf_print_error_and_exit("Bank member %d did not receive all inputs.", + self->bank_index + ); + } + =} } reactor Hello extends Base { - reaction(I) {= - if (I[0]->is_present && I[1]->is_present) { - printf("Hello %d\n", self->bank_index); - self->received = true; - } - =} + reaction(I) {= + if (I[0]->is_present && I[1]->is_present) { + printf("Hello %d\n", self->bank_index); + self->received = true; + } + =} } reactor World extends Base { - reaction(I) {= - if (I[0]->is_present && I[1]->is_present) { - printf("World %d\n", self->bank_index); - self->received = true; - } - =} + reaction(I) {= + if (I[0]->is_present && I[1]->is_present) { + printf("World %d\n", self->bank_index); + self->received = true; + } + =} } main reactor { - hellos = new[3] Hello() - worlds = new[3] World() + hellos = new[3] Hello() + worlds = new[3] World() - reaction(startup) -> hellos.I, worlds.I {= - for(int i = 0; i < hellos_width; i++) { - lf_set(hellos[i].I[0], true); - lf_set(hellos[i].I[1], true); - } - for(int i = 0; i < worlds_width; i++) { - lf_set(worlds[i].I[0], true); - lf_set(worlds[i].I[1], true); - } - =} + reaction(startup) -> hellos.I, worlds.I {= + for(int i = 0; i < hellos_width; i++) { + lf_set(hellos[i].I[0], true); + lf_set(hellos[i].I[1], true); + } + for(int i = 0; i < worlds_width; i++) { + lf_set(worlds[i].I[0], true); + lf_set(worlds[i].I[1], true); + } + =} } diff --git a/test/C/src/multiport/FullyConnected.lf b/test/C/src/multiport/FullyConnected.lf index 758ecf1580..d65b64f18f 100644 --- a/test/C/src/multiport/FullyConnected.lf +++ b/test/C/src/multiport/FullyConnected.lf @@ -1,41 +1,41 @@ target C reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { - input[num_nodes] in: int - output out: int + input[num_nodes] in: int + output out: int - state received: bool = false + state received: bool = false - reaction(startup) -> out {= - lf_print("Hello from node %d!", self->bank_index); - // broadcast my ID to everyone - lf_set(out, self->bank_index); - =} + reaction(startup) -> out {= + lf_print("Hello from node %d!", self->bank_index); + // broadcast my ID to everyone + lf_set(out, self->bank_index); + =} - reaction(in) {= - printf("Node %d received messages from ", self->bank_index); - size_t count = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - self->received = true; - count++; - printf("%d, ", in[i]->value); - } + reaction(in) {= + printf("Node %d received messages from ", self->bank_index); + size_t count = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + self->received = true; + count++; + printf("%d, ", in[i]->value); } - printf("\n"); - if (count != self->num_nodes) { - lf_print_error_and_exit("Received fewer messages than expected!"); - } - =} + } + printf("\n"); + if (count != self->num_nodes) { + lf_print_error_and_exit("Received fewer messages than expected!"); + } + =} - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("Received no input!"); - } - =} + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("Received no input!"); + } + =} } main reactor(num_nodes: size_t = 4) { - nodes = new[num_nodes] Node(num_nodes = num_nodes) - (nodes.out)+ -> nodes.in + nodes = new[num_nodes] Node(num_nodes = num_nodes) + (nodes.out)+ -> nodes.in } diff --git a/test/C/src/multiport/FullyConnectedAddressable.lf b/test/C/src/multiport/FullyConnectedAddressable.lf index 91b0f5caac..2fd5e03ad2 100644 --- a/test/C/src/multiport/FullyConnectedAddressable.lf +++ b/test/C/src/multiport/FullyConnectedAddressable.lf @@ -2,53 +2,53 @@ target C reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { - input[num_nodes] in: int - output[num_nodes] out: int + input[num_nodes] in: int + output[num_nodes] out: int - state received: int = 0 - state triggered: bool = false + state received: int = 0 + state triggered: bool = false - reaction(startup) -> out {= - int outChannel = (self->bank_index + 1) % self->num_nodes; - lf_print("Node %d sending %d out on channel %d.", - self->bank_index, self->bank_index, outChannel - ); - // broadcast my ID to everyone - lf_set(out[outChannel], self->bank_index); - =} + reaction(startup) -> out {= + int outChannel = (self->bank_index + 1) % self->num_nodes; + lf_print("Node %d sending %d out on channel %d.", + self->bank_index, self->bank_index, outChannel + ); + // broadcast my ID to everyone + lf_set(out[outChannel], self->bank_index); + =} - reaction(in) {= - self->triggered = true; - printf("Node %d received messages from ", self->bank_index); - size_t count = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - count++; - printf("%d, ", in[i]->value); - self->received = in[i]->value; - } + reaction(in) {= + self->triggered = true; + printf("Node %d received messages from ", self->bank_index); + size_t count = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + count++; + printf("%d, ", in[i]->value); + self->received = in[i]->value; } - printf("\n"); - int expected = self->bank_index == 0 ? self->num_nodes - 1 : self->bank_index - 1; - if (count != 1) { - lf_print_error_and_exit("Received %d messages, but expecting only one!"); - } - if (self->received != expected) { - lf_print_error_and_exit("Received %d, but expected %d!", self->received, expected); - } - =} + } + printf("\n"); + int expected = self->bank_index == 0 ? self->num_nodes - 1 : self->bank_index - 1; + if (count != 1) { + lf_print_error_and_exit("Received %d messages, but expecting only one!"); + } + if (self->received != expected) { + lf_print_error_and_exit("Received %d, but expected %d!", self->received, expected); + } + =} - reaction(shutdown) {= - if (!self->triggered) { - lf_print_error_and_exit("Received no input!"); - } - =} + reaction(shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("Received no input!"); + } + =} } main reactor(num_nodes: size_t = 4) { - nodes1 = new[num_nodes] Node(num_nodes = num_nodes) - nodes1.out -> interleaved (nodes1.in) + nodes1 = new[num_nodes] Node(num_nodes = num_nodes) + nodes1.out -> interleaved (nodes1.in) - nodes2 = new[num_nodes] Node(num_nodes = num_nodes) - interleaved (nodes2.out) -> nodes2.in + nodes2 = new[num_nodes] Node(num_nodes = num_nodes) + interleaved (nodes2.out) -> nodes2.in } diff --git a/test/C/src/multiport/FullyConnectedAddressableAfter.lf b/test/C/src/multiport/FullyConnectedAddressableAfter.lf index 1d30430deb..e71c5194bb 100644 --- a/test/C/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/C/src/multiport/FullyConnectedAddressableAfter.lf @@ -4,9 +4,9 @@ target C import Node from "FullyConnectedAddressable.lf" main reactor(num_nodes: size_t = 4) { - nodes1 = new[num_nodes] Node(num_nodes = num_nodes) - nodes1.out -> interleaved (nodes1.in) after 200 msec + nodes1 = new[num_nodes] Node(num_nodes = num_nodes) + nodes1.out -> interleaved (nodes1.in) after 200 msec - nodes2 = new[num_nodes] Node(num_nodes = num_nodes) - interleaved (nodes2.out) -> nodes2.in after 400 msec + nodes2 = new[num_nodes] Node(num_nodes = num_nodes) + interleaved (nodes2.out) -> nodes2.in after 400 msec } diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index 1b49786060..2bdb344cf0 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -1,44 +1,42 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(check_override: int = 0, bank_index: int = 0) { - output out: int + output out: int - reaction(startup) -> out {= - lf_set(out, self->bank_index * self->check_override); - =} + reaction(startup) -> out {= lf_set(out, self->bank_index * self->check_override); =} } reactor Destination(port_width: int = 3) { - input[port_width] in: int - state received: bool = false + input[port_width] in: int + state received: bool = false - reaction(in) {= - for (int i = 0; i < in_width; i++) { - printf("Destination channel %d received %d.\n", i, in[i]->value); - if (i != in[i]->value) { - printf("ERROR: Expected %d.\n", i); - exit(1); - } - } - self->received = true; - =} - - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination received no input!\n"); + reaction(in) {= + for (int i = 0; i < in_width; i++) { + printf("Destination channel %d received %d.\n", i, in[i]->value); + if (i != in[i]->value) { + printf("ERROR: Expected %d.\n", i); exit(1); } - printf("Success.\n"); - =} + } + self->received = true; + =} + + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportFromBank(width: int = 4) { - a = new[width] Source(check_override = 1) - b = new Destination(port_width = width) - a.out -> b.in + a = new[width] Source(check_override = 1) + b = new Destination(port_width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index e8ee6194b5..073f76ad7a 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -1,20 +1,20 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source, Destination from "MultiportFromBank.lf" reactor Container(port_width: int = 3) { - output[port_width] out: int - s = new[port_width] Source(check_override = 1) - s.out -> out + output[port_width] out: int + s = new[port_width] Source(check_override = 1) + s.out -> out } main reactor(width: int = 4) { - a = new Container(port_width = width) - b = new Destination(port_width = width) - a.out -> b.in + a = new Container(port_width = width) + b = new Destination(port_width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index 8323210946..c7a6b36277 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -1,62 +1,61 @@ -// Check multiport output to multiport input, where the former is a hierarchical -// reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 3) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 - - reaction(t) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], self->s++); - } - =} + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 + + reaction(t) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s++); + } + =} } reactor Destination(width: int = 3) { - state s: int = 6 - input[width] in: int - - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} - - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + state s: int = 6 + input[width] in: int + + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} + + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } reactor Container(width: int = 3) { - output[width] out: int - src = new InsideContainer(width = width) - src.out -> out + output[width] out: int + src = new InsideContainer(width = width) + src.out -> out } reactor InsideContainer(width: int = 3) { - output[width] out: int - src = new Source(width = width) - src.out -> out + output[width] out: int + src = new Source(width = width) + src.out -> out } main reactor MultiportFromHierarchy(width: int = 4) { - a = new Container(width = width) - b = new Destination(width = width) - a.out -> b.in + a = new Container(width = width) + b = new Destination(width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportFromReaction.lf b/test/C/src/multiport/MultiportFromReaction.lf index 33cbfffd83..0b0b83aa71 100644 --- a/test/C/src/multiport/MultiportFromReaction.lf +++ b/test/C/src/multiport/MultiportFromReaction.lf @@ -1,46 +1,46 @@ // Check reaction to multiport input of a contained reactor. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Destination(width: int = 1) { - state s: int = 6 - input[width] in: int + state s: int = 6 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportFromReaction(width: int = 4) { - timer t(0, 200 msec) - state s: int = 0 - b = new Destination(width = width) + timer t(0, 200 msec) + state s: int = 0 + b = new Destination(width = width) - reaction(t) -> b.in {= - for(int i = 0; i < b.in_width; i++) { - printf("Before lf_set, b.in[%d]->is_present has value %d\n", i, b.in[i]->is_present); - lf_set(b.in[i], self->s++); - printf("AFTER set, b.in[%d]->is_present has value %d\n", i, b.in[i]->is_present); - printf("AFTER set, b.in[%d]->value has value %d\n", i, b.in[i]->value); - } - =} + reaction(t) -> b.in {= + for(int i = 0; i < b.in_width; i++) { + printf("Before lf_set, b.in[%d]->is_present has value %d\n", i, b.in[i]->is_present); + lf_set(b.in[i], self->s++); + printf("AFTER set, b.in[%d]->is_present has value %d\n", i, b.in[i]->is_present); + printf("AFTER set, b.in[%d]->value has value %d\n", i, b.in[i]->value); + } + =} } diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index b87a91a79b..cba7094684 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -1,64 +1,64 @@ -// This is a version fo the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor Computation { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } reactor Destination { - state s: int = 0 - input[4] in: int + state s: int = 0 + input[4] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 4; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 4; + =} - reaction(shutdown) {= - if (self->s == 0) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s == 0) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportIn { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1.in - a.out -> t2.in - a.out -> t3.in - a.out -> t4.in - t1.out, t2.out, t3.out, t4.out -> b.in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1.in + a.out -> t2.in + a.out -> t3.in + a.out -> t4.in + t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/C/src/multiport/MultiportInParameterized.lf b/test/C/src/multiport/MultiportInParameterized.lf index bf7ec93f6e..d2026c8aca 100644 --- a/test/C/src/multiport/MultiportInParameterized.lf +++ b/test/C/src/multiport/MultiportInParameterized.lf @@ -1,66 +1,65 @@ -// This is a version of the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version of the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor Computation { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= lf_set(out, in->value); =} + reaction(in) -> out {= lf_set(out, in->value); =} } reactor Destination(width: int = 1) { - state s: int = 0 - input[width] in: int + state s: int = 0 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 4; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 4; + =} - reaction(shutdown) {= - if (self->s == 0) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s == 0) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination(width = 4) - a.out -> t1.in - a.out -> t2.in - a.out -> t3.in - a.out -> t4.in - // I.e.: t1.out -> b.in[0]; t2.out -> b.in[1]; t3.out -> b.in[2]; dt4.out -> - // b.in[3]; - t1.out, t2.out, t3.out, t4.out -> b.in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination(width = 4) + a.out -> t1.in + a.out -> t2.in + a.out -> t3.in + a.out -> t4.in + // I.e.: t1.out -> b.in[0]; t2.out -> b.in[1]; t3.out -> b.in[2]; dt4.out -> b.in[3]; + t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/C/src/multiport/MultiportMutableInput.lf b/test/C/src/multiport/MultiportMutableInput.lf index e1f8d579c2..187b4d47be 100644 --- a/test/C/src/multiport/MultiportMutableInput.lf +++ b/test/C/src/multiport/MultiportMutableInput.lf @@ -1,49 +1,48 @@ -// Source produces a ints on a multiport, which it passes to Scale. Scale -// requests a writable copy. It modifies it and passes it to Print. It gets -// freed after Print is done with it. +// Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. +// It modifies it and passes it to Print. It gets freed after Print is done with it. target C reactor Source { - output[2] out: int + output[2] out: int - reaction(startup) -> out {= - lf_set(out[0], 21); - lf_set(out[1], 42); - =} + reaction(startup) -> out {= + lf_set(out[0], 21); + lf_set(out[1], 42); + =} } reactor Print(scale: int = 1) { // The scale parameter is just for testing. - input[2] in: int + input[2] in: int - reaction(in) {= - int expected = 42; - for(int j = 0; j < 2; j++) { - lf_print("Received on channel %d: %d", j, in[j]->value); - if (in[j]->value != expected) { - lf_print_error_and_exit("ERROR: Expected %d!\n", expected); - } - expected *=2; + reaction(in) {= + int expected = 42; + for(int j = 0; j < 2; j++) { + lf_print("Received on channel %d: %d", j, in[j]->value); + if (in[j]->value != expected) { + lf_print_error_and_exit("ERROR: Expected %d!\n", expected); } - =} + expected *=2; + } + =} } reactor Scale(scale: int = 2) { - mutable input[2] in: int - output[2] out: int + mutable input[2] in: int + output[2] out: int - reaction(in) -> out {= - for(int j = 0; j < 2; j++) { - // Modify the input, allowed because mutable. - in[j]->value *= self->scale; - lf_set(out[j], in[j]->value); - } - =} + reaction(in) -> out {= + for(int j = 0; j < 2; j++) { + // Modify the input, allowed because mutable. + in[j]->value *= self->scale; + lf_set(out[j], in[j]->value); + } + =} } main reactor { - s = new Source() - c = new Scale() - p = new Print(scale = 2) - s.out -> c.in - c.out -> p.in + s = new Source() + c = new Scale() + p = new Print(scale = 2) + s.out -> c.in + c.out -> p.in } diff --git a/test/C/src/multiport/MultiportMutableInputArray.lf b/test/C/src/multiport/MultiportMutableInputArray.lf index 90907e4f44..07f8a97365 100644 --- a/test/C/src/multiport/MultiportMutableInputArray.lf +++ b/test/C/src/multiport/MultiportMutableInputArray.lf @@ -1,77 +1,76 @@ -// Source produces a dynamically allocated arrays on a multiport, which it -// passes to Scale. Scale requests a writable copy, which, instead of copying, -// it just gets ownership of the original array. It modifies it and passes it to -// Print. It gets freed after Print is done with it. +// Source produces a dynamically allocated arrays on a multiport, which it passes to Scale. Scale +// requests a writable copy, which, instead of copying, it just gets ownership of the original +// array. It modifies it and passes it to Print. It gets freed after Print is done with it. target C reactor Source { - output[2] out: int[] + output[2] out: int[] - reaction(startup) -> out {= - // Dynamically allocate an output array of length 3. - SET_NEW_ARRAY(out[0], 3); + reaction(startup) -> out {= + // Dynamically allocate an output array of length 3. + SET_NEW_ARRAY(out[0], 3); - // Above allocates the array, which then must be populated. - out[0]->value[0] = 0; - out[0]->value[1] = 1; - out[0]->value[2] = 2; + // Above allocates the array, which then must be populated. + out[0]->value[0] = 0; + out[0]->value[1] = 1; + out[0]->value[2] = 2; - // Dynamically allocate an output array of length 3. - SET_NEW_ARRAY(out[1], 3); + // Dynamically allocate an output array of length 3. + SET_NEW_ARRAY(out[1], 3); - // Above allocates the array, which then must be populated. - out[1]->value[0] = 3; - out[1]->value[1] = 4; - out[1]->value[2] = 5; - =} + // Above allocates the array, which then must be populated. + out[1]->value[0] = 3; + out[1]->value[1] = 4; + out[1]->value[2] = 5; + =} } reactor Print(scale: int = 1) { // The scale parameter is just for testing. - input[2] in: int[] + input[2] in: int[] - reaction(in) {= - int count = 0; // For testing. - bool failed = false; // For testing. - for(int j = 0; j < 2; j++) { - printf("Received on channel %d: [", j); - for (int i = 0; i < in[j]->length; i++) { - if (i > 0) printf(", "); - printf("%d", in[j]->value[i]); - // For testing, check whether values match expectation. - if (in[j]->value[i] != self->scale * count) { - failed = true; - } - count++; // For testing. + reaction(in) {= + int count = 0; // For testing. + bool failed = false; // For testing. + for(int j = 0; j < 2; j++) { + printf("Received on channel %d: [", j); + for (int i = 0; i < in[j]->length; i++) { + if (i > 0) printf(", "); + printf("%d", in[j]->value[i]); + // For testing, check whether values match expectation. + if (in[j]->value[i] != self->scale * count) { + failed = true; } - printf("]\n"); + count++; // For testing. } - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); - } - =} + printf("]\n"); + } + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } reactor Scale(scale: int = 2) { - mutable input[2] in: int[] - output[2] out: int[] + mutable input[2] in: int[] + output[2] out: int[] - reaction(in) -> out {= - for(int j = 0; j < in_width; j++) { - for(int i = 0; i < in[j]->length; i++) { - if (in[j]->is_present) { - in[j]->value[i] *= self->scale; - } + reaction(in) -> out {= + for(int j = 0; j < in_width; j++) { + for(int i = 0; i < in[j]->length; i++) { + if (in[j]->is_present) { + in[j]->value[i] *= self->scale; } - lf_set_token(out[j], in[j]->token); } - =} + lf_set_token(out[j], in[j]->token); + } + =} } main reactor { - s = new Source() - c = new Scale() - p = new Print(scale = 2) - s.out -> c.in - c.out -> p.in + s = new Source() + c = new Scale() + p = new Print(scale = 2) + s.out -> c.in + c.out -> p.in } diff --git a/test/C/src/multiport/MultiportOut.lf b/test/C/src/multiport/MultiportOut.lf index 38365d217a..bb756937e5 100644 --- a/test/C/src/multiport/MultiportOut.lf +++ b/test/C/src/multiport/MultiportOut.lf @@ -1,68 +1,68 @@ // Check multiport capabilities on Outputs. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[4] out: int - state s: int = 0 + timer t(0, 200 msec) + output[4] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < 4; i++) { - lf_set(out[i], self->s); - } - self->s++; - =} + reaction(t) -> out {= + for(int i = 0; i < 4; i++) { + lf_set(out[i], self->s); + } + self->s++; + =} } reactor Computation { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - // No need to sleep for this test. - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - lf_set(out, in->value); - =} + reaction(in) -> out {= + // No need to sleep for this test. + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + lf_set(out, in->value); + =} } reactor Destination { - state s: int = 0 - input[4] in: int + state s: int = 0 + input[4] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 4; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 4; + =} - reaction(shutdown) {= - if (self->s == 0) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s == 0) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1.in, t2.in, t3.in, t4.in - t1.out, t2.out, t3.out, t4.out -> b.in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1.in, t2.in, t3.in, t4.in + t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/C/src/multiport/MultiportToBank.lf b/test/C/src/multiport/MultiportToBank.lf index 86146b9818..4e0e89d05e 100644 --- a/test/C/src/multiport/MultiportToBank.lf +++ b/test/C/src/multiport/MultiportToBank.lf @@ -1,53 +1,52 @@ // Check multiport output to bank of recipients. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 2) { - output[width] out: int // Connected to a bank of Destination reactors - input dummy: int // Not connected to anything + output[width] out: int // Connected to a bank of Destination reactors + input dummy: int // Not connected to anything - reaction(startup) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} - // Test also that multiple appearances of the same effect port do not result - // in multiple allocations of memory for the port. - reaction(dummy) -> - out {= // Contents of the reactions does not matter (either could be empty) - for(int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + // Test also that multiple appearances of the same effect port do not result in multiple + // allocations of memory for the port. + reaction(dummy) -> out {= // Contents of the reactions does not matter (either could be empty) + for(int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - if (self->bank_index != in->value) { - printf("ERROR: Expected %d.\n", self->bank_index); - exit(1); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + if (self->bank_index != in->value) { + printf("ERROR: Expected %d.\n", self->bank_index); + exit(1); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportToBank(width: int = 3) { - a = new Source(width = width) - b = new[width] Destination() - a.out -> b.in + a = new Source(width = width) + b = new[width] Destination() + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToBankAfter.lf b/test/C/src/multiport/MultiportToBankAfter.lf index ba26142243..52945d1c67 100644 --- a/test/C/src/multiport/MultiportToBankAfter.lf +++ b/test/C/src/multiport/MultiportToBankAfter.lf @@ -1,48 +1,47 @@ -// Check multiport output to bank of recipients where the width of the bank is -// inferred. +// Check multiport output to bank of recipients where the width of the bank is inferred. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 2) { - output[width] out: int + output[width] out: int - reaction(startup) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - if (self->bank_index != in->value) { - printf("ERROR: Expected %d.\n", self->bank_index); - exit(1); - } - if (lf_time_logical_elapsed() != SEC(1)) { - printf("ERROR: Expected to receive input after one second.\n"); - exit(2); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + if (self->bank_index != in->value) { + printf("ERROR: Expected %d.\n", self->bank_index); + exit(1); + } + if (lf_time_logical_elapsed() != SEC(1)) { + printf("ERROR: Expected to receive input after one second.\n"); + exit(2); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(3); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(3); + } + printf("Success.\n"); + =} } main reactor(width: int = 3) { - a = new Source(width = width) - b = new[width] Destination() - a.out -> b.in after 1 sec // Width of the bank of delays will be inferred. + a = new Source(width = width) + b = new[width] Destination() + a.out -> b.in after 1 sec // Width of the bank of delays will be inferred. } diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index 444f02d170..baf752b338 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -1,53 +1,52 @@ -// Check multiport output to bank of recipients where the source has two -// reactions that write to the output. +// Check multiport output to bank of recipients where the source has two reactions that write to the +// output. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[3] out: int // Connected to a bank of Destination reactors + output[3] out: int // Connected to a bank of Destination reactors - reaction(startup) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} - // Test also that multiple appearances of the same effect port do not result - // in multiple allocations of memory for the port. - reaction(startup) -> - out {= // Contents of the reactions does not matter (either could be empty) - for(int i = 0; i < out_width; i++) { - lf_set(out[i], i * 2); - } - =} + // Test also that multiple appearances of the same effect port do not result in multiple + // allocations of memory for the port. + reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) + for(int i = 0; i < out_width; i++) { + lf_set(out[i], i * 2); + } + =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - if (self->bank_index * 2 != in->value) { - printf("ERROR: Expected %d.\n", self->bank_index * 2); - exit(1); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + if (self->bank_index * 2 != in->value) { + printf("ERROR: Expected %d.\n", self->bank_index * 2); + exit(1); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(1); + } + printf("Success.\n"); + =} } main reactor { - a = new Source() - b = new[3] Destination() - a.out -> b.in + a = new Source() + b = new[3] Destination() + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index fbdc531bf0..dcb3b41811 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -1,50 +1,50 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 2) { - output[width] out: int + output[width] out: int - reaction(startup) -> out {= - for(int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} } reactor Destination(bank_index: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Destination %d received %d.\n", self->bank_index, in->value); - if (self->bank_index != in->value) { - printf("ERROR: Expected %d.\n", self->bank_index); - exit(1); - } - self->received = true; - =} + reaction(in) {= + printf("Destination %d received %d.\n", self->bank_index, in->value); + if (self->bank_index != in->value) { + printf("ERROR: Expected %d.\n", self->bank_index); + exit(1); + } + self->received = true; + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); + exit(1); + } + printf("Success.\n"); + =} } reactor Container(width: int = 2) { - input[width] in: int - c = new[width] Destination() - in -> c.in + input[width] in: int + c = new[width] Destination() + in -> c.in } main reactor MultiportToBankHierarchy(width: int = 3) { - a = new Source(width = width) - b = new Container(width = width) - a.out -> b.in + a = new Source(width = width) + b = new Container(width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index 41ca505077..2abaca76eb 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -1,57 +1,56 @@ -// Check multiport output to multiport input, where the latter is a hierarchical -// reactor. Note that the destination reactor has width wider than the sender, -// so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +// the destination reactor has width wider than the sender, so one input is dangling. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 2) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < 4; i++) { - lf_set(out[i], self->s++); - } - =} + reaction(t) -> out {= + for(int i = 0; i < 4; i++) { + lf_set(out[i], self->s++); + } + =} } reactor Destination(width: int = 4) { - state s: int = 6 - input[width] in: int + state s: int = 6 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } reactor Container(width: int = 4) { - input[width] in: int - dst = new Destination() - in -> dst.in + input[width] in: int + dst = new Destination() + in -> dst.in } main reactor MultiportToHierarchy(width: int = 4) { - a = new Source(width = width) - b = new Container(width = width) - a.out -> b.in + a = new Source(width = width) + b = new Container(width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToMultiport.lf b/test/C/src/multiport/MultiportToMultiport.lf index 375fa080e2..c24b8b59de 100644 --- a/test/C/src/multiport/MultiportToMultiport.lf +++ b/test/C/src/multiport/MultiportToMultiport.lf @@ -1,52 +1,52 @@ // Check multiport output to multiport input. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 1) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < out_width; i++) { - printf("Before lf_set, out[%d]->is_present has value %d\n", i, out[i]->is_present); - lf_set(out[i], self->s++); - printf("AFTER set, out[%d]->is_present has value %d\n", i, out[i]->is_present); - printf("AFTER set, out[%d]->value has value %d\n", i, out[i]->value); - } - =} + reaction(t) -> out {= + for(int i = 0; i < out_width; i++) { + printf("Before lf_set, out[%d]->is_present has value %d\n", i, out[i]->is_present); + lf_set(out[i], self->s++); + printf("AFTER set, out[%d]->is_present has value %d\n", i, out[i]->is_present); + printf("AFTER set, out[%d]->value has value %d\n", i, out[i]->value); + } + =} } reactor Destination(width: int = 1) { - state s: int = 6 - input[width] in: int + state s: int = 6 + input[width] in: int - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportToMultiport(width: int = 4) { - a = new Source(width = width) - b = new Destination(width = width) - a.out -> b.in + a = new Source(width = width) + b = new Destination(width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToMultiport2.lf b/test/C/src/multiport/MultiportToMultiport2.lf index 76858a2a86..4247995caa 100644 --- a/test/C/src/multiport/MultiportToMultiport2.lf +++ b/test/C/src/multiport/MultiportToMultiport2.lf @@ -2,40 +2,36 @@ target C reactor Source(width: int = 2) { - output[width] out: int + output[width] out: int - reaction(startup) -> out {= - for (int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for (int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} } reactor Destination(width: int = 2) { - input[width] in: int + input[width] in: int - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - printf("Received on channel %d: %d\n", i, in[i]->value); - // NOTE: For testing purposes, this assumes the specific - // widths instantiated below. - if (in[i]->value != i % 3) { - fprintf(stderr, "ERROR: expected %d!\n", i % 3); - exit(1); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + printf("Received on channel %d: %d\n", i, in[i]->value); + // NOTE: For testing purposes, this assumes the specific + // widths instantiated below. + if (in[i]->value != i % 3) { + fprintf(stderr, "ERROR: expected %d!\n", i % 3); + exit(1); } } - =} + } + =} } -main reactor MultiportToMultiport2( - width1: int = 3, - width2: int = 2, - width3: int = 5 -) { - a1 = new Source(width = width1) - a2 = new Source(width = width2) - b = new Destination(width = width3) - a1.out, a2.out -> b.in +main reactor MultiportToMultiport2(width1: int = 3, width2: int = 2, width3: int = 5) { + a1 = new Source(width = width1) + a2 = new Source(width = width2) + b = new Destination(width = width3) + a1.out, a2.out -> b.in } diff --git a/test/C/src/multiport/MultiportToMultiport2After.lf b/test/C/src/multiport/MultiportToMultiport2After.lf index 49585ea1b0..2d626610cf 100644 --- a/test/C/src/multiport/MultiportToMultiport2After.lf +++ b/test/C/src/multiport/MultiportToMultiport2After.lf @@ -2,40 +2,40 @@ target C reactor Source(width: int = 2) { - output[width] out: int + output[width] out: int - reaction(startup) -> out {= - for (int i = 0; i < out_width; i++) { - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for (int i = 0; i < out_width; i++) { + lf_set(out[i], i); + } + =} } reactor Destination(width: int = 2) { - input[width] in: int + input[width] in: int - reaction(in) {= - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - printf("Received on channel %d: %d\n", i, in[i]->value); - // NOTE: For testing purposes, this assumes the specific - // widths instantiated below. - if (in[i]->value != i % 3) { - fprintf(stderr, "ERROR: expected %d!\n", i % 3); - exit(1); - } + reaction(in) {= + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + printf("Received on channel %d: %d\n", i, in[i]->value); + // NOTE: For testing purposes, this assumes the specific + // widths instantiated below. + if (in[i]->value != i % 3) { + fprintf(stderr, "ERROR: expected %d!\n", i % 3); + exit(1); } } - if (lf_time_logical_elapsed() != SEC(1)) { - printf("ERROR: Expected to receive input after one second.\n"); - exit(2); - } - =} + } + if (lf_time_logical_elapsed() != SEC(1)) { + printf("ERROR: Expected to receive input after one second.\n"); + exit(2); + } + =} } main reactor MultiportToMultiport2After { - a1 = new Source(width = 3) - a2 = new Source(width = 2) - b = new Destination(width = 5) - a1.out, a2.out -> b.in after 1 sec + a1 = new Source(width = 3) + a2 = new Source(width = 2) + b = new Destination(width = 5) + a1.out, a2.out -> b.in after 1 sec } diff --git a/test/C/src/multiport/MultiportToMultiportArray.lf b/test/C/src/multiport/MultiportToMultiportArray.lf index 9d86a4a522..203e4fb04f 100644 --- a/test/C/src/multiport/MultiportToMultiportArray.lf +++ b/test/C/src/multiport/MultiportToMultiportArray.lf @@ -1,60 +1,59 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[2] out: int[] - state s: int = 0 + timer t(0, 200 msec) + output[2] out: int[] + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < 2; i++) { - // Dynamically allocate an output array of length 3. - SET_NEW_ARRAY(out[i], 3); + reaction(t) -> out {= + for(int i = 0; i < 2; i++) { + // Dynamically allocate an output array of length 3. + SET_NEW_ARRAY(out[i], 3); - // Above allocates the array, which then must be populated. - out[i]->value[0] = self->s++; - out[i]->value[1] = self->s++; - out[i]->value[2] = self->s++; - } - =} + // Above allocates the array, which then must be populated. + out[i]->value[0] = self->s++; + out[i]->value[1] = self->s++; + out[i]->value[2] = self->s++; + } + =} } reactor Destination { - state s: int = 15 - input[2] in: int[] + state s: int = 15 + input[2] in: int[] - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) { - for (int j = 0; j < in[i]->length; j++) { - sum += in[i]->value[j]; - } + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) { + for (int j = 0; j < in[i]->length; j++) { + sum += in[i]->value[j]; } } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 36; - =} + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 36; + =} - reaction(shutdown) {= - if (self->s <= 15) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 15) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportToMultiportArray { - a = new Source() - b = new Destination() - a.out -> b.in + a = new Source() + b = new Destination() + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToMultiportParameter.lf b/test/C/src/multiport/MultiportToMultiportParameter.lf index d1c96e5ddd..fe311cd7fa 100644 --- a/test/C/src/multiport/MultiportToMultiportParameter.lf +++ b/test/C/src/multiport/MultiportToMultiportParameter.lf @@ -1,52 +1,52 @@ // Check multiport output to multiport input. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 1) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < out_width; i++) { - printf("Before lf_set, out[%d]->is_present has value %d\n", i, out[i]->is_present); - lf_set(out[i], self->s++); - printf("AFTER set, out[%d]->is_present has value %d\n", i, out[i]->is_present); - printf("AFTER set, out[%d]->value has value %d\n", i, out[i]->value); - } - =} + reaction(t) -> out {= + for(int i = 0; i < out_width; i++) { + printf("Before lf_set, out[%d]->is_present has value %d\n", i, out[i]->is_present); + lf_set(out[i], self->s++); + printf("AFTER set, out[%d]->is_present has value %d\n", i, out[i]->is_present); + printf("AFTER set, out[%d]->value has value %d\n", i, out[i]->value); + } + =} } reactor Destination(width: int = 1) { - state s: int = 6 - input[width] in: int // Width is one larger than that of the source. + state s: int = 6 + input[width] in: int // Width is one larger than that of the source. - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - if (in[i]->is_present) sum += in[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + if (in[i]->is_present) sum += in[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor(width: int = 4) { - a = new Source(width = width) - b = new Destination(width = width) - a.out -> b.in + a = new Source(width = width) + b = new Destination(width = width) + a.out -> b.in } diff --git a/test/C/src/multiport/MultiportToPort.lf b/test/C/src/multiport/MultiportToPort.lf index 1784f2503c..60523029cf 100644 --- a/test/C/src/multiport/MultiportToPort.lf +++ b/test/C/src/multiport/MultiportToPort.lf @@ -1,46 +1,45 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[2] out: int + output[2] out: int - reaction(startup) -> out {= - for(int i = 0; i < out_width; i++) { - printf("Source sending %d.\n", i); - lf_set(out[i], i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out_width; i++) { + printf("Source sending %d.\n", i); + lf_set(out[i], i); + } + =} } reactor Destination(expected: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - printf("Received: %d.\n", in->value); - self->received = true; - if (in->value != self->expected) { - printf("ERROR: Expected %d.\n", self->expected); - exit(1); - } - =} + reaction(in) {= + printf("Received: %d.\n", in->value); + self->received = true; + if (in->value != self->expected) { + printf("ERROR: Expected %d.\n", self->expected); + exit(1); + } + =} - reaction(shutdown) {= - if (!self->received) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (!self->received) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } main reactor MultiportToPort { - a = new Source() - b1 = new Destination() - b2 = new Destination(expected = 1) - a.out -> b1.in, b2.in + a = new Source() + b1 = new Destination() + b2 = new Destination(expected = 1) + a.out -> b1.in, b2.in } diff --git a/test/C/src/multiport/MultiportToReaction.lf b/test/C/src/multiport/MultiportToReaction.lf index 9281633079..77eba059f3 100644 --- a/test/C/src/multiport/MultiportToReaction.lf +++ b/test/C/src/multiport/MultiportToReaction.lf @@ -1,44 +1,44 @@ // Check reaction to multiport output of a contained reactor. target C { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: int = 1) { - timer t(0, 200 msec) - state s: int = 0 - output[width] out: int + timer t(0, 200 msec) + state s: int = 0 + output[width] out: int - reaction(t) -> out {= - printf("Sending.\n"); - for(int i = 0; i < out_width; i++) { - lf_set(out[i], self->s++); - } - =} + reaction(t) -> out {= + printf("Sending.\n"); + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s++); + } + =} } main reactor MultiportToReaction { - state s: int = 6 - b = new Source(width = 4) + state s: int = 6 + b = new Source(width = 4) - reaction(b.out) {= - int sum = 0; - for (int i = 0; i < b.out_width; i++) { - if (b.out[i]->is_present) sum += b.out[i]->value; - } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} + reaction(b.out) {= + int sum = 0; + for (int i = 0; i < b.out_width; i++) { + if (b.out[i]->is_present) sum += b.out[i]->value; + } + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } diff --git a/test/C/src/multiport/NestedBanks.lf b/test/C/src/multiport/NestedBanks.lf index bef08727f3..5c2953c2a4 100644 --- a/test/C/src/multiport/NestedBanks.lf +++ b/test/C/src/multiport/NestedBanks.lf @@ -5,78 +5,78 @@ target C main reactor { - a = new[2] A() - c = new[3] C() - d = new D() - e = new E() + a = new[2] A() + c = new[3] C() + d = new D() + e = new E() - (a.x)+ -> c.z, d.u, e.t + (a.x)+ -> c.z, d.u, e.t } reactor A(bank_index: int = 0) { - output[4] x: int - b = new[2] B(a_bank_index = bank_index) - b.y -> x + output[4] x: int + b = new[2] B(a_bank_index = bank_index) + b.y -> x } reactor B(a_bank_index: int = 0, bank_index: int = 0) { - output[2] y: int + output[2] y: int - reaction(startup) -> y {= - int base = self->a_bank_index * 4 + self->bank_index * 2; - lf_set(y[0], base); - lf_set(y[1], base + 1); - =} + reaction(startup) -> y {= + int base = self->a_bank_index * 4 + self->bank_index * 2; + lf_set(y[0], base); + lf_set(y[1], base + 1); + =} } reactor C(bank_index: int = 0) { - input[2] z: int - f = new F(c_bank_index = bank_index) - g = new G(c_bank_index = bank_index) - z -> f.w, g.s + input[2] z: int + f = new F(c_bank_index = bank_index) + g = new G(c_bank_index = bank_index) + z -> f.w, g.s } reactor D { - input[2] u: int + input[2] u: int - reaction(u) {= - for (int i = 0; i < u_width; i++) { - lf_print("d.u[%d] received %d.", i, u[i]->value); - if (u[i]->value != 6 + i) { - lf_print_error_and_exit("Expected %d but received %d.", 6 + i, u[i]->value); - } + reaction(u) {= + for (int i = 0; i < u_width; i++) { + lf_print("d.u[%d] received %d.", i, u[i]->value); + if (u[i]->value != 6 + i) { + lf_print_error_and_exit("Expected %d but received %d.", 6 + i, u[i]->value); } - =} + } + =} } reactor E { - input[8] t: int + input[8] t: int - reaction(t) {= - for (int i = 0; i < t_width; i++) { - lf_print("e.t[%d] received %d.", i, t[i]->value); - } - =} + reaction(t) {= + for (int i = 0; i < t_width; i++) { + lf_print("e.t[%d] received %d.", i, t[i]->value); + } + =} } reactor F(c_bank_index: int = 0) { - input w: int + input w: int - reaction(w) {= - lf_print("c[%d].f.w received %d.", self->c_bank_index, w->value); - if (w->value != self->c_bank_index * 2) { - lf_print_error_and_exit("Expected %d but received %d.", self->c_bank_index * 2, w->value); - } - =} + reaction(w) {= + lf_print("c[%d].f.w received %d.", self->c_bank_index, w->value); + if (w->value != self->c_bank_index * 2) { + lf_print_error_and_exit("Expected %d but received %d.", self->c_bank_index * 2, w->value); + } + =} } reactor G(c_bank_index: int = 0) { - input s: int + input s: int - reaction(s) {= - lf_print("c[%d].g.s received %d.", self->c_bank_index, s->value); - if (s->value != self->c_bank_index * 2 + 1) { - lf_print_error_and_exit("Expected %d but received %d.", self->c_bank_index * 2 + 1, s->value); - } - =} + reaction(s) {= + lf_print("c[%d].g.s received %d.", self->c_bank_index, s->value); + if (s->value != self->c_bank_index * 2 + 1) { + lf_print_error_and_exit("Expected %d but received %d.", self->c_bank_index * 2 + 1, s->value); + } + =} } diff --git a/test/C/src/multiport/NestedInterleavedBanks.lf b/test/C/src/multiport/NestedInterleavedBanks.lf index 8e3056bd88..2d8f10e518 100644 --- a/test/C/src/multiport/NestedInterleavedBanks.lf +++ b/test/C/src/multiport/NestedInterleavedBanks.lf @@ -5,38 +5,38 @@ target C reactor A(bank_index: int = 0, outer_bank_index: int = 0) { - output[2] p: int + output[2] p: int - reaction(startup) -> p {= - for (int i = 0; i < p_width; i++) { - lf_set(p[i], self->outer_bank_index * 4 + self->bank_index * 2 + i + 1); - lf_print("A sending %d.", p[i]->value); - } - =} + reaction(startup) -> p {= + for (int i = 0; i < p_width; i++) { + lf_set(p[i], self->outer_bank_index * 4 + self->bank_index * 2 + i + 1); + lf_print("A sending %d.", p[i]->value); + } + =} } reactor B(bank_index: int = 0) { - output[4] q: int - a = new[2] A(outer_bank_index = bank_index) - interleaved (a.p) -> q + output[4] q: int + a = new[2] A(outer_bank_index = bank_index) + interleaved (a.p) -> q } reactor C { - input[8] i: int + input[8] i: int - reaction(i) {= - int expected[] = {1, 3, 2, 4, 5, 7, 6, 8}; - for(int j = 0; j < i_width; j++) { - lf_print("C received %d.", i[j]->value); - if (i[j]->value != expected[j]) { - lf_print_error_and_exit("Expected %d.", expected[j]); - } + reaction(i) {= + int expected[] = {1, 3, 2, 4, 5, 7, 6, 8}; + for(int j = 0; j < i_width; j++) { + lf_print("C received %d.", i[j]->value); + if (i[j]->value != expected[j]) { + lf_print_error_and_exit("Expected %d.", expected[j]); } - =} + } + =} } main reactor { - b = new[2] B() - c = new C() - b.q -> c.i + b = new[2] B() + c = new C() + b.q -> c.i } diff --git a/test/C/src/multiport/ReactionToContainedBank.lf b/test/C/src/multiport/ReactionToContainedBank.lf index 30f3f5564c..e448913d79 100644 --- a/test/C/src/multiport/ReactionToContainedBank.lf +++ b/test/C/src/multiport/ReactionToContainedBank.lf @@ -1,21 +1,21 @@ // Test reaction sending messages to a contained bank of reactors. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import TestCount from "../lib/TestCount.lf" main reactor ReactionToContainedBank(width: int = 2) { - timer t(0, 100 msec) - state count: int = 1 + timer t(0, 100 msec) + state count: int = 1 - test = new[width] TestCount(num_inputs = 11) + test = new[width] TestCount(num_inputs = 11) - reaction(t) -> test.in {= - for (int i = 0; i < self->width; i++) { - lf_set(test[i].in, self->count); - } - self->count++; - =} + reaction(t) -> test.in {= + for (int i = 0; i < self->width; i++) { + lf_set(test[i].in, self->count); + } + self->count++; + =} } diff --git a/test/C/src/multiport/ReactionToContainedBank2.lf b/test/C/src/multiport/ReactionToContainedBank2.lf index e03e884558..a36e575b21 100644 --- a/test/C/src/multiport/ReactionToContainedBank2.lf +++ b/test/C/src/multiport/ReactionToContainedBank2.lf @@ -1,26 +1,26 @@ // Test reaction sending messages to a contained bank of reactors. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import TestCount from "../lib/TestCount.lf" reactor ReactionToContainedBank(width: int = 2) { - timer t(0, 100 msec) - state count: int = 1 + timer t(0, 100 msec) + state count: int = 1 - test = new[width] TestCount(num_inputs = 11) + test = new[width] TestCount(num_inputs = 11) - reaction(t) -> test.in {= - for (int i = 0; i < self->width; i++) { - lf_set(test[i].in, self->count); - } - self->count++; - =} + reaction(t) -> test.in {= + for (int i = 0; i < self->width; i++) { + lf_set(test[i].in, self->count); + } + self->count++; + =} } main reactor(width: int = 2) { - a = new ReactionToContainedBank(width = width) - b = new ReactionToContainedBank(width = 4) + a = new ReactionToContainedBank(width = width) + b = new ReactionToContainedBank(width = 4) } diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index d84b21c191..e778f125c9 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -1,24 +1,23 @@ -// Test reaction sending messages to a contained bank of reactors with a -// multiport input. +// Test reaction sending messages to a contained bank of reactors with a multiport input. target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import TestCountMultiport from "../lib/TestCountMultiport.lf" main reactor(width: int = 2) { - timer t(0, 100 msec) - state count: int = 1 + timer t(0, 100 msec) + state count: int = 1 - test = new[width] TestCountMultiport(num_inputs = 11, width = width) + test = new[width] TestCountMultiport(num_inputs = 11, width = width) - reaction(t) -> test.in {= - for (int i = 0; i < self->width; i++) { - for (int j = 0; j < self->width; j++) { - lf_set(test[j].in[i], self->count); - } - self->count++; + reaction(t) -> test.in {= + for (int i = 0; i < self->width; i++) { + for (int j = 0; j < self->width; j++) { + lf_set(test[j].in[i], self->count); } - =} + self->count++; + } + =} } diff --git a/test/C/src/multiport/ReactionsToNested.lf b/test/C/src/multiport/ReactionsToNested.lf index 4270f55c2d..71a76444b6 100644 --- a/test/C/src/multiport/ReactionsToNested.lf +++ b/test/C/src/multiport/ReactionsToNested.lf @@ -1,39 +1,38 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target C { - timeout: 1 sec + timeout: 1 sec } reactor T(expected: int = 0) { - input z: int - state received: bool = false + input z: int + state received: bool = false - reaction(z) {= - lf_print("T received %d", z->value); - self->received = true; - if (z->value != self->expected) { - lf_print_error_and_exit("Expected %d", self->expected); - } - =} + reaction(z) {= + lf_print("T received %d", z->value); + self->received = true; + if (z->value != self->expected) { + lf_print_error_and_exit("Expected %d", self->expected); + } + =} - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("No input received"); - } - =} + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("No input received"); + } + =} } reactor D { - input[2] y: int - t1 = new T(expected = 42) - t2 = new T(expected = 43) - y -> t1.z, t2.z + input[2] y: int + t1 = new T(expected = 42) + t2 = new T(expected = 43) + y -> t1.z, t2.z } main reactor { - d = new D() + d = new D() - reaction(startup) -> d.y {= lf_set(d.y[0], 42); =} + reaction(startup) -> d.y {= lf_set(d.y[0], 42); =} - reaction(startup) -> d.y {= lf_set(d.y[1], 43); =} + reaction(startup) -> d.y {= lf_set(d.y[1], 43); =} } diff --git a/test/C/src/multiport/Sparse.lf b/test/C/src/multiport/Sparse.lf index 537daabb4b..3ebda275b1 100644 --- a/test/C/src/multiport/Sparse.lf +++ b/test/C/src/multiport/Sparse.lf @@ -1,50 +1,50 @@ /** Test reading of sparse inputs on a multiport. */ target C { - timeout: 20 ms + timeout: 20 ms } reactor SparseSource(width: int = 20) { - output[width] out: int - state count: int = 0 - timer t(0, 1 msec) + output[width] out: int + state count: int = 0 + timer t(0, 1 msec) - reaction(t) -> out {= - int next_count = self->count + 1; - if (next_count >= self->width) { - next_count = 0; - } - lf_set(out[next_count], next_count); - lf_set(out[self->count], self->count); - self->count = next_count; - =} + reaction(t) -> out {= + int next_count = self->count + 1; + if (next_count >= self->width) { + next_count = 0; + } + lf_set(out[next_count], next_count); + lf_set(out[self->count], self->count); + self->count = next_count; + =} } reactor SparseSink(width: int = 20) { - input[width] in: int + input[width] in: int - reaction(in) {= - struct lf_multiport_iterator_t i = lf_multiport_iterator(in); - lf_print("--------"); - // Ensure inputs are seen in order. - int previous = -1; - int channel = lf_multiport_next(&i); - while(channel >= 0) { - lf_print("Received %d on channel %d", in[channel]->value, channel); - // The value of the input should equal the channel number. - if (in[channel]->value != channel) { - lf_print_error_and_exit("Expected %d", channel); - } - if (channel <= previous) { - lf_print_error_and_exit("Input channels not read in order."); - } - previous = channel; - channel = lf_multiport_next(&i); + reaction(in) {= + struct lf_multiport_iterator_t i = lf_multiport_iterator(in); + lf_print("--------"); + // Ensure inputs are seen in order. + int previous = -1; + int channel = lf_multiport_next(&i); + while(channel >= 0) { + lf_print("Received %d on channel %d", in[channel]->value, channel); + // The value of the input should equal the channel number. + if (in[channel]->value != channel) { + lf_print_error_and_exit("Expected %d", channel); + } + if (channel <= previous) { + lf_print_error_and_exit("Input channels not read in order."); } - =} + previous = channel; + channel = lf_multiport_next(&i); + } + =} } main reactor(width: int = 20) { - s = new SparseSource(width = width) - d = new SparseSink(width = width) - s.out -> d.in + s = new SparseSource(width = width) + d = new SparseSink(width = width) + s.out -> d.in } diff --git a/test/C/src/multiport/SparseFallback.lf b/test/C/src/multiport/SparseFallback.lf index a7788858d8..a5a0bf4284 100644 --- a/test/C/src/multiport/SparseFallback.lf +++ b/test/C/src/multiport/SparseFallback.lf @@ -1,53 +1,53 @@ /** - * Test reading of sparse inputs on a multiport where the density of writes to - * the multiport is high enough to force the fallback policy to kick in. + * Test reading of sparse inputs on a multiport where the density of writes to the multiport is high + * enough to force the fallback policy to kick in. */ target C { - timeout: 20 ms + timeout: 20 ms } reactor SparseSource(width: int = 20) { - output[width] out: int - state count: int = 0 - timer t(0, 1 msec) + output[width] out: int + state count: int = 0 + timer t(0, 1 msec) - reaction(t) -> out {= - int next_count = self->count + 1; - if (next_count >= self->width) { - next_count = 0; - } - lf_set(out[self->count], self->count); - lf_set(out[next_count], next_count); - self->count = next_count; - =} + reaction(t) -> out {= + int next_count = self->count + 1; + if (next_count >= self->width) { + next_count = 0; + } + lf_set(out[self->count], self->count); + lf_set(out[next_count], next_count); + self->count = next_count; + =} } reactor SparseSink(width: int = 20) { - input[width] in: int + input[width] in: int - reaction(in) {= - struct lf_multiport_iterator_t i = lf_multiport_iterator(in); - lf_print("--------"); - // Ensure inputs are seen in order. - int previous = -1; - int channel = lf_multiport_next(&i); - while(channel >= 0) { - lf_print("Received %d on channel %d", in[channel]->value, channel); - // The value of the input should equal the channel number. - if (in[channel]->value != channel) { - lf_print_error_and_exit("Expected %d", channel); - } - if (channel <= previous) { - lf_print_error_and_exit("Input channels not read in order."); - } - previous = channel; - channel = lf_multiport_next(&i); + reaction(in) {= + struct lf_multiport_iterator_t i = lf_multiport_iterator(in); + lf_print("--------"); + // Ensure inputs are seen in order. + int previous = -1; + int channel = lf_multiport_next(&i); + while(channel >= 0) { + lf_print("Received %d on channel %d", in[channel]->value, channel); + // The value of the input should equal the channel number. + if (in[channel]->value != channel) { + lf_print_error_and_exit("Expected %d", channel); + } + if (channel <= previous) { + lf_print_error_and_exit("Input channels not read in order."); } - =} + previous = channel; + channel = lf_multiport_next(&i); + } + =} } main reactor(width: int = 10) { - s = new SparseSource(width = width) - d = new SparseSink(width = width) - s.out -> d.in + s = new SparseSource(width = width) + d = new SparseSink(width = width) + s.out -> d.in } diff --git a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf index 917982af39..9acf39c95c 100644 --- a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf +++ b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf @@ -1,49 +1,46 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target C { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source { - output a: int - output b: int - state count: int = 0 - timer t(0, 200 msec) + output a: int + output b: int + state count: int = 0 + timer t(0, 200 msec) - reaction(t) -> a, b {= - if (self->count++ % 2 == 0) { - lf_set(a, self->count); - } else { - lf_set(b, self->count); - } - =} + reaction(t) -> a, b {= + if (self->count++ % 2 == 0) { + lf_set(a, self->count); + } else { + lf_set(b, self->count); + } + =} } reactor Destination { - input a: int - input b: int + input a: int + input b: int - reaction(a) {= - if (!a->is_present) { - fprintf(stderr, "Reaction to a triggered even though all inputs are absent!\n"); - exit(1); - } - =} + reaction(a) {= + if (!a->is_present) { + fprintf(stderr, "Reaction to a triggered even though all inputs are absent!\n"); + exit(1); + } + =} - reaction(b) {= - if (!b->is_present) { - fprintf(stderr, "Reaction to b triggered even though all inputs are absent!\n"); - exit(2); - } - =} + reaction(b) {= + if (!b->is_present) { + fprintf(stderr, "Reaction to b triggered even though all inputs are absent!\n"); + exit(2); + } + =} } main reactor TriggerDownstreamOnlyIfPresent { - s = new[2] Source() - d = new[2] Destination() - s.a -> d.a - s.b -> d.b + s = new[2] Source() + d = new[2] Destination() + s.a -> d.a + s.b -> d.b } diff --git a/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf b/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf index e69e0af0b4..4ed83a1700 100644 --- a/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf +++ b/test/C/src/no_inlining/BankMultiportToReactionNoInlining.lf @@ -1,30 +1,30 @@ target C { - timeout: 5 sec, - fast: true, - cmake-include: ["../../c/bank_multiport_to_reaction_no_inlining.cmake"], - files: ["../../c"] + timeout: 5 sec, + fast: true, + cmake-include: ["../../c/bank_multiport_to_reaction_no_inlining.cmake"], + files: ["../../c"] } import Count from "../lib/Count.lf" reactor DoubleCount { - output[2] out: int - c1 = new Count() - c2 = new Count() - c1.out, c2.out -> out + output[2] out: int + c1 = new Count() + c2 = new Count() + c1.out, c2.out -> out } main reactor { - state count: int = 1 - state received: bool = false + state count: int = 1 + state received: bool = false - s = new[2] DoubleCount() + s = new[2] DoubleCount() - reaction(s.out) named check + reaction(s.out) named check - reaction(shutdown) {= - if (!self->received) { - lf_print_error_and_exit("No inputs present."); - } - =} + reaction(shutdown) {= + if (!self->received) { + lf_print_error_and_exit("No inputs present."); + } + =} } diff --git a/test/C/src/no_inlining/BankToReactionNoInlining.lf b/test/C/src/no_inlining/BankToReactionNoInlining.lf index 4956bf68cd..d7277d31a2 100644 --- a/test/C/src/no_inlining/BankToReactionNoInlining.lf +++ b/test/C/src/no_inlining/BankToReactionNoInlining.lf @@ -1,16 +1,16 @@ target C { - timeout: 5 sec, - fast: true, - cmake-include: ["../../c/bank_to_reaction_no_inlining.cmake"], - files: ["../../c"] + timeout: 5 sec, + fast: true, + cmake-include: ["../../c/bank_to_reaction_no_inlining.cmake"], + files: ["../../c"] } import Count from "../lib/Count.lf" main reactor { - state count: int = 1 + state count: int = 1 - s = new[2] Count() + s = new[2] Count() - reaction(s.out) named check + reaction(s.out) named check } diff --git a/test/C/src/no_inlining/Count.lf b/test/C/src/no_inlining/Count.lf index f8fd51bec7..b57615db92 100644 --- a/test/C/src/no_inlining/Count.lf +++ b/test/C/src/no_inlining/Count.lf @@ -1,16 +1,16 @@ target C { - cmake-include: ["../../c/count.cmake"], - files: ["../../c"] + cmake-include: ["../../c/count.cmake"], + files: ["../../c"] } main reactor Count { - timer t(0, 1 msec) + timer t(0, 1 msec) - state count: int + state count: int - reaction(t) named increment + reaction(t) named increment - reaction(t) named check_done + reaction(t) named check_done - reaction(shutdown) {= printf("%s", "shutting down\n"); =} + reaction(shutdown) {= printf("%s", "shutting down\n"); =} } diff --git a/test/C/src/no_inlining/CountHierarchy.lf b/test/C/src/no_inlining/CountHierarchy.lf index 771222af2f..706ca75c35 100644 --- a/test/C/src/no_inlining/CountHierarchy.lf +++ b/test/C/src/no_inlining/CountHierarchy.lf @@ -1,23 +1,23 @@ target C { - cmake-include: ["../../c/count_hierarchy.cmake"], - files: ["../../c"] + cmake-include: ["../../c/count_hierarchy.cmake"], + files: ["../../c"] } reactor Timer(m: time = 0, n: time = 0) { - output out: int - timer t(m, n) + output out: int + timer t(m, n) - reaction(t) -> out {= lf_set(out, 0); =} + reaction(t) -> out {= lf_set(out, 0); =} } main reactor { - t = new Timer(m = 0, n = 1 msec) + t = new Timer(m = 0, n = 1 msec) - state count: int + state count: int - reaction(t.out) named increment + reaction(t.out) named increment - reaction(t.out) named check_done + reaction(t.out) named check_done - reaction(shutdown) {= printf("%s", "shutting down\n"); =} + reaction(shutdown) {= printf("%s", "shutting down\n"); =} } diff --git a/test/C/src/no_inlining/IntPrint.lf b/test/C/src/no_inlining/IntPrint.lf index fa6ab8c757..fd7639d45d 100644 --- a/test/C/src/no_inlining/IntPrint.lf +++ b/test/C/src/no_inlining/IntPrint.lf @@ -1,22 +1,22 @@ target C { - cmake-include: ["../../c/sendreceive.cmake"], - files: ["../../c"] + cmake-include: ["../../c/sendreceive.cmake"], + files: ["../../c"] } reactor Print { - output out: int + output out: int - reaction(startup) -> out named send + reaction(startup) -> out named send } reactor Check(expected: int = 42) { // expected parameter is for testing. - input in: int + input in: int - reaction(in) named receive + reaction(in) named receive } main reactor { - s = new Print() - p = new Check() - s.out -> p.in + s = new Print() + p = new Check() + s.out -> p.in } diff --git a/test/C/src/no_inlining/MultiportToReactionNoInlining.lf b/test/C/src/no_inlining/MultiportToReactionNoInlining.lf index 3c5f18d62a..98811fd9db 100644 --- a/test/C/src/no_inlining/MultiportToReactionNoInlining.lf +++ b/test/C/src/no_inlining/MultiportToReactionNoInlining.lf @@ -1,35 +1,35 @@ // Check reaction to multiport output of a contained reactor. target C { - timeout: 2 sec, - fast: true, - cmake-include: ["../../c/multiport_to_reaction_no_inlining.cmake"], - files: ["../../c"] + timeout: 2 sec, + fast: true, + cmake-include: ["../../c/multiport_to_reaction_no_inlining.cmake"], + files: ["../../c"] } reactor Source(width: int = 1) { - timer t(0, 200 msec) - state s: int = 0 - output[width] out: int + timer t(0, 200 msec) + state s: int = 0 + output[width] out: int - reaction(t) -> out {= - printf("Sending.\n"); - for(int i = 0; i < out_width; i++) { - lf_set(out[i], self->s++); - } - =} + reaction(t) -> out {= + printf("Sending.\n"); + for(int i = 0; i < out_width; i++) { + lf_set(out[i], self->s++); + } + =} } main reactor { - state s: int = 6 - b = new Source(width = 4) + state s: int = 6 + b = new Source(width = 4) - reaction(b.out) named check + reaction(b.out) named check - reaction(shutdown) {= - if (self->s <= 6) { - fprintf(stderr, "ERROR: Destination received no input!\n"); - exit(1); - } - printf("Success.\n"); - =} + reaction(shutdown) {= + if (self->s <= 6) { + fprintf(stderr, "ERROR: Destination received no input!\n"); + exit(1); + } + printf("Success.\n"); + =} } diff --git a/test/C/src/serialization/ROSBuiltInSerialization.lf b/test/C/src/serialization/ROSBuiltInSerialization.lf index 095aadacd2..6054a50fa2 100644 --- a/test/C/src/serialization/ROSBuiltInSerialization.lf +++ b/test/C/src/serialization/ROSBuiltInSerialization.lf @@ -1,13 +1,12 @@ /** - * This test showcases the infrastructure that is built into the CCpp target - * that can automatically serialize and deserialize ROS2 messages in federated - * programs. + * This test showcases the infrastructure that is built into the CCpp target that can automatically + * serialize and deserialize ROS2 messages in federated programs. * - * This test contains a sender-receiver federated program in which the 'sender' - * federate sends a std_msgs::msg::Int32 message to the 'receiver' federate. + * This test contains a sender-receiver federated program in which the 'sender' federate sends a + * std_msgs::msg::Int32 message to the 'receiver' federate. * - * To run this test, make sure that your terminal is properly sourced for ROS2. - * See https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. + * To run this test, make sure that your terminal is properly sourced for ROS2. See + * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. * * Then you can use lfc to compile this program: * @@ -20,49 +19,48 @@ * @author Soroush Bateni */ target CCpp { - cmake-include: "include/CMakeListsExtension.txt", - timeout: 2 sec + cmake-include: "include/CMakeListsExtension.txt", + timeout: 2 sec } preamble {= - #include "std_msgs/msg/int32.hpp" + #include "std_msgs/msg/int32.hpp" =} reactor Sender { - output out: std_msgs::msg::Int32 + output out: std_msgs::msg::Int32 - // state serialized_msg_pcl:rclcpp::SerializedMessage({=0u=}); - state count: int = 0 + state count: int = 0 // state serialized_msg_pcl:rclcpp::SerializedMessage({=0u=}); - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) -> out {= - std_msgs::msg::Int32 ros_message; - ros_message.data = self->count++; - lf_set(out, ros_message); - =} + reaction(t) -> out {= + std_msgs::msg::Int32 ros_message; + ros_message.data = self->count++; + lf_set(out, ros_message); + =} } reactor Receiver { - input in: std_msgs::msg::Int32 - state count: int = 0 + input in: std_msgs::msg::Int32 + state count: int = 0 - reaction(in) {= - // Print the ROS2 message data - lf_print( - "Serialized integer after deserialization: %d", - in->value.data - ); - if (in->value.data != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count++; - =} + reaction(in) {= + // Print the ROS2 message data + lf_print( + "Serialized integer after deserialization: %d", + in->value.data + ); + if (in->value.data != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count++; + =} } federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in after 100 msec serializer "ros2" + sender.out -> receiver.in after 100 msec serializer "ros2" } diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index 97b5a12554..e407f18bb9 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -1,13 +1,12 @@ /** - * This test showcases the infrastructure that is built into the CCpp target - * that can automatically serialize and deserialize ROS2 messages (with a - * shared_ptr type) in federated programs. + * This test showcases the infrastructure that is built into the CCpp target that can automatically + * serialize and deserialize ROS2 messages (with a shared_ptr type) in federated programs. * - * This test contains a sender-receiver federated program in which the 'sender' - * federate sends a std_msgs::msg::Int32 message to the 'receiver' federate. + * This test contains a sender-receiver federated program in which the 'sender' federate sends a + * std_msgs::msg::Int32 message to the 'receiver' federate. * - * To run this test, make sure that your terminal is properly sourced for ROS2. - * See https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. + * To run this test, make sure that your terminal is properly sourced for ROS2. See + * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. * * Then you can use lfc to compile this program: * @@ -20,48 +19,48 @@ * @author Soroush Bateni */ target CCpp { - cmake-include: "include/CMakeListsExtension.txt", - timeout: 2 sec + cmake-include: "include/CMakeListsExtension.txt", + timeout: 2 sec } preamble {= - #include "std_msgs/msg/int32.hpp" + #include "std_msgs/msg/int32.hpp" =} reactor Sender { - output out: std::shared_ptr + output out: std::shared_ptr - state count: int = 0 + state count: int = 0 - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) -> out {= - auto ros_message = std::make_shared(); - ros_message->data = self->count++; - lf_set(out, ros_message); - =} + reaction(t) -> out {= + auto ros_message = std::make_shared(); + ros_message->data = self->count++; + lf_set(out, ros_message); + =} } reactor Receiver { - input in: std::shared_ptr - state count: int = 0 + input in: std::shared_ptr + state count: int = 0 - reaction(in) {= - // Print the ROS2 message data - lf_print( - "Serialized integer after deserialization: %d", - in->value->data - ); - if (in->value->data != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count++; - =} + reaction(in) {= + // Print the ROS2 message data + lf_print( + "Serialized integer after deserialization: %d", + in->value->data + ); + if (in->value->data != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count++; + =} } federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in serializer "ros2" + sender.out -> receiver.in serializer "ros2" } diff --git a/test/C/src/target/FederatedFiles.lf b/test/C/src/target/FederatedFiles.lf index ebc1ff210e..9fb4440a02 100644 --- a/test/C/src/target/FederatedFiles.lf +++ b/test/C/src/target/FederatedFiles.lf @@ -1,14 +1,14 @@ -// This test references a header file in reactor-c, which has to be obtained -// from the class path. This test is successful if it compiles. +// This test references a header file in reactor-c, which has to be obtained from the class path. +// This test is successful if it compiles. target C { - files: "/lib/c/reactor-c/util/sensor_simulator.h", - timeout: 1 s + files: "/lib/c/reactor-c/util/sensor_simulator.h", + timeout: 1 s } reactor Foo { - reaction(startup) {= lf_print("Hello World"); =} + reaction(startup) {= lf_print("Hello World"); =} } federated reactor { - f = new Foo() + f = new Foo() } diff --git a/test/C/src/target/HelloWorldCCPP.lf b/test/C/src/target/HelloWorldCCPP.lf index 91d1cd61d1..1b3a9b023f 100644 --- a/test/C/src/target/HelloWorldCCPP.lf +++ b/test/C/src/target/HelloWorldCCPP.lf @@ -1,32 +1,32 @@ /** - * A variant of HelloWorld.lf that tests the CCpp target in conjunction with the - * CMake build system. This test should not pass if it does not compile. + * A variant of HelloWorld.lf that tests the CCpp target in conjunction with the CMake build system. + * This test should not pass if it does not compile. */ target CCpp { - tracing: true, - logging: DEBUG + tracing: true, + logging: DEBUG } reactor HelloWorld { - preamble {= - #include - =} - state success: bool = false + preamble {= + #include + =} + state success: bool = false - reaction(startup) {= - std::cout << "Hello World." << std::endl; - self->success = true; - =} + reaction(startup) {= + std::cout << "Hello World." << std::endl; + self->success = true; + =} - reaction(shutdown) {= - printf("Shutdown invoked.\n"); - if (!self->success) { - fprintf(stderr, "ERROR: startup reaction not executed.\n"); - exit(1); - } - =} + reaction(shutdown) {= + printf("Shutdown invoked.\n"); + if (!self->success) { + fprintf(stderr, "ERROR: startup reaction not executed.\n"); + exit(1); + } + =} } main reactor { - a = new HelloWorld() + a = new HelloWorld() } diff --git a/test/C/src/token/TokenContainedPrint.lf b/test/C/src/token/TokenContainedPrint.lf index 29e6005c4c..586e7283a2 100644 --- a/test/C/src/token/TokenContainedPrint.lf +++ b/test/C/src/token/TokenContainedPrint.lf @@ -3,27 +3,27 @@ * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenPrint from "lib/Token.lf" main reactor { - state count: int = 0 - timer t(0, 1 ms) + state count: int = 0 + timer t(0, 1 ms) - p = new TokenPrint() + p = new TokenPrint() - reaction(startup) -> p.in {= - lf_set_destructor(p.in, int_array_destructor); - lf_set_copy_constructor(p.in, int_array_copy_constructor); - =} + reaction(startup) -> p.in {= + lf_set_destructor(p.in, int_array_destructor); + lf_set_copy_constructor(p.in, int_array_copy_constructor); + =} - reaction(t) -> p.in {= - int_array_t* array = int_array_constructor(3); - for (size_t i = 0; i < array->length; i++) { - array->data[i] = self->count++; - } - lf_set(p.in, array); - =} + reaction(t) -> p.in {= + int_array_t* array = int_array_constructor(3); + for (size_t i = 0; i < array->length; i++) { + array->data[i] = self->count++; + } + lf_set(p.in, array); + =} } diff --git a/test/C/src/token/TokenContainedPrintBank.lf b/test/C/src/token/TokenContainedPrintBank.lf index 991a94b5a7..69ae534b20 100644 --- a/test/C/src/token/TokenContainedPrintBank.lf +++ b/test/C/src/token/TokenContainedPrintBank.lf @@ -1,36 +1,35 @@ /** - * Basic test of token type passed from a reaction to a bank of contained - * destinations. + * Basic test of token type passed from a reaction to a bank of contained destinations. * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenPrint from "lib/Token.lf" main reactor { - state count: int = 0 - timer t(0, 1 ms) - p = new[2] TokenPrint() + state count: int = 0 + timer t(0, 1 ms) + p = new[2] TokenPrint() - reaction(startup) -> p.in {= - for (int j = 0; j < p_width; j++) { - lf_set_destructor(p[j].in, int_array_destructor); - lf_set_copy_constructor(p[j].in, int_array_copy_constructor); - } - =} + reaction(startup) -> p.in {= + for (int j = 0; j < p_width; j++) { + lf_set_destructor(p[j].in, int_array_destructor); + lf_set_copy_constructor(p[j].in, int_array_copy_constructor); + } + =} - reaction(t) -> p.in {= - int_array_t* array = int_array_constructor(3); - for (size_t i = 0; i < array->length; i++) { - array->data[i] = self->count++; - } - // Sending the array to more than one destination, so we need - // to wrap it in a token. - lf_token_t* token = lf_new_token(p[0].in, array, 1); - for (int j = 0; j < p_width; j++) { - lf_set_token(p[j].in, token); - } - =} + reaction(t) -> p.in {= + int_array_t* array = int_array_constructor(3); + for (size_t i = 0; i < array->length; i++) { + array->data[i] = self->count++; + } + // Sending the array to more than one destination, so we need + // to wrap it in a token. + lf_token_t* token = lf_new_token(p[0].in, array, 1); + for (int j = 0; j < p_width; j++) { + lf_set_token(p[j].in, token); + } + =} } diff --git a/test/C/src/token/TokenContainedSource.lf b/test/C/src/token/TokenContainedSource.lf index 66095b8a0b..72fd079032 100644 --- a/test/C/src/token/TokenContainedSource.lf +++ b/test/C/src/token/TokenContainedSource.lf @@ -4,40 +4,40 @@ * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenSource from "lib/Token.lf" main reactor(scale: int = 1) { - state count: int = 0 - state input_received: bool = false + state count: int = 0 + state input_received: bool = false - s = new TokenSource() + s = new TokenSource() - reaction(s.out) {= - self->input_received = true; - bool failed = false; // For testing. - printf("Received: ["); - for (int i = 0; i < s.out->value->length; i++) { - if (i > 0) printf(", "); - printf("%d", s.out->value->data[i]); - // For testing, check whether values match expectation. - if (s.out->value->data[i] != self->scale * self->count) { - failed = true; - } - self->count++; + reaction(s.out) {= + self->input_received = true; + bool failed = false; // For testing. + printf("Received: ["); + for (int i = 0; i < s.out->value->length; i++) { + if (i > 0) printf(", "); + printf("%d", s.out->value->data[i]); + // For testing, check whether values match expectation. + if (s.out->value->data[i] != self->scale * self->count) { + failed = true; } - printf("]\n"); - if (failed) { - printf("ERROR: Value received does not match expectation!\n"); - exit(1); - } - =} + self->count++; + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received does not match expectation!\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (!self->input_received) { - lf_print_error_and_exit("TokenPrint: No result received!"); - } - =} + reaction(shutdown) {= + if (!self->input_received) { + lf_print_error_and_exit("TokenPrint: No result received!"); + } + =} } diff --git a/test/C/src/token/TokenContainedSourceBank.lf b/test/C/src/token/TokenContainedSourceBank.lf index 615695890b..0a0b4383c7 100644 --- a/test/C/src/token/TokenContainedSourceBank.lf +++ b/test/C/src/token/TokenContainedSourceBank.lf @@ -1,47 +1,46 @@ /** - * Basic test of token type passed from a bank of contained sources to a - * reaction. + * Basic test of token type passed from a bank of contained sources to a reaction. * @author Hou Seng (Steven) Wong (housengw@berkeley.edu) * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenSource from "lib/Token.lf" main reactor(scale: int = 1) { - state count: int = 0 - state input_received: bool = false + state count: int = 0 + state input_received: bool = false - s = new[2] TokenSource() + s = new[2] TokenSource() - reaction(s.out) {= - self->input_received = true; - bool failed = false; // For testing. - for (int j = 0; j < s_width; j++) { - printf("Received from %d: [", j); - if (j > 0) self->count -= s[j].out->value->length; - for (int i = 0; i < s[j].out->value->length; i++) { - if (i > 0) printf(", "); - printf("%d", s[j].out->value->data[i]); - // For testing, check whether values match expectation. - if (s[j].out->value->data[i] != self->scale * self->count) { - failed = true; - } - self->count++; + reaction(s.out) {= + self->input_received = true; + bool failed = false; // For testing. + for (int j = 0; j < s_width; j++) { + printf("Received from %d: [", j); + if (j > 0) self->count -= s[j].out->value->length; + for (int i = 0; i < s[j].out->value->length; i++) { + if (i > 0) printf(", "); + printf("%d", s[j].out->value->data[i]); + // For testing, check whether values match expectation. + if (s[j].out->value->data[i] != self->scale * self->count) { + failed = true; } - printf("]\n"); + self->count++; } - if (failed) { - printf("ERROR: Value received does not match expectation!\n"); - exit(1); - } - =} + printf("]\n"); + } + if (failed) { + printf("ERROR: Value received does not match expectation!\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (!self->input_received) { - lf_print_error_and_exit("TokenPrint: No result received!"); - } - =} + reaction(shutdown) {= + if (!self->input_received) { + lf_print_error_and_exit("TokenPrint: No result received!"); + } + =} } diff --git a/test/C/src/token/TokenDelayTest.lf b/test/C/src/token/TokenDelayTest.lf index 5fcd03f4cf..9070ab5f87 100644 --- a/test/C/src/token/TokenDelayTest.lf +++ b/test/C/src/token/TokenDelayTest.lf @@ -3,15 +3,15 @@ * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenSource, TokenPrint, TokenDelay from "lib/Token.lf" main reactor { - s = new TokenSource() - d = new TokenDelay() - p = new TokenPrint() - s.out -> d.in - d.out -> p.in + s = new TokenSource() + d = new TokenDelay() + p = new TokenPrint() + s.out -> d.in + d.out -> p.in } diff --git a/test/C/src/token/TokenMutable.lf b/test/C/src/token/TokenMutable.lf index 47fad08bcd..7169f421c8 100644 --- a/test/C/src/token/TokenMutable.lf +++ b/test/C/src/token/TokenMutable.lf @@ -1,23 +1,23 @@ /** - * Test of token scaled by two scale factors with a mutable inputs. The total - * memory allocated in this test should be the greater than in - * TokenSourcePrint.lf because two destinations have mutable inputs. + * Test of token scaled by two scale factors with a mutable inputs. The total memory allocated in + * this test should be the greater than in TokenSourcePrint.lf because two destinations have mutable + * inputs. * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenSource, TokenPrint, TokenScale from "lib/Token.lf" main reactor { - s = new TokenSource() - g2 = new TokenScale(scale = 2) - g3 = new TokenScale(scale = 3) - p2 = new TokenPrint(scale = 2) - p3 = new TokenPrint(scale = 3) - s.out -> g2.in - s.out -> g3.in - g2.out -> p2.in - g3.out -> p3.in + s = new TokenSource() + g2 = new TokenScale(scale = 2) + g3 = new TokenScale(scale = 3) + p2 = new TokenPrint(scale = 2) + p3 = new TokenPrint(scale = 3) + s.out -> g2.in + s.out -> g3.in + g2.out -> p2.in + g3.out -> p3.in } diff --git a/test/C/src/token/TokenSourcePrint.lf b/test/C/src/token/TokenSourcePrint.lf index ef3d69bbfb..7a46f74c20 100644 --- a/test/C/src/token/TokenSourcePrint.lf +++ b/test/C/src/token/TokenSourcePrint.lf @@ -4,13 +4,13 @@ * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenSource, TokenPrint from "lib/Token.lf" main reactor { - s = new TokenSource() - p = new TokenPrint() - s.out -> p.in + s = new TokenSource() + p = new TokenPrint() + s.out -> p.in } diff --git a/test/C/src/token/TokenSourceScalePrint.lf b/test/C/src/token/TokenSourceScalePrint.lf index 8c601168e0..01d57936ff 100644 --- a/test/C/src/token/TokenSourceScalePrint.lf +++ b/test/C/src/token/TokenSourceScalePrint.lf @@ -1,19 +1,19 @@ /** - * Test of token scaled by a scale factor with a mutable input. The total memory - * allocated in this test should be the same as in TokenSourcePrint.lf. + * Test of token scaled by a scale factor with a mutable input. The total memory allocated in this + * test should be the same as in TokenSourcePrint.lf. * @author Hou Seng (Steven) Wong (housengw@berkeley.edu) * @author Edward A. Lee (eal@berkeley.edu) */ target C { - timeout: 2 ms + timeout: 2 ms } import TokenSource, TokenPrint, TokenScale from "lib/Token.lf" main reactor { - s = new TokenSource() - g2 = new TokenScale(scale = 2) - p2 = new TokenPrint(scale = 2) - s.out -> g2.in - g2.out -> p2.in + s = new TokenSource() + g2 = new TokenScale(scale = 2) + p2 = new TokenPrint(scale = 2) + s.out -> g2.in + g2.out -> p2.in } diff --git a/test/C/src/token/lib/Token.lf b/test/C/src/token/lib/Token.lf index 7b8d2a83ee..f5f0bc5d27 100644 --- a/test/C/src/token/lib/Token.lf +++ b/test/C/src/token/lib/Token.lf @@ -4,100 +4,98 @@ * @author Edward A. Lee (eal@berkeley.edu) */ target C { - files: ["../include/array.h"] + files: ["../include/array.h"] } preamble {= - #include "array.h" + #include "array.h" =} /** - * @brief Produce a sequence of arrays of length 3 with increasing values. - * Values are produced at intervals of 1 ms. The first arrray has value [0, 1, - * 2], the second has value [3, 4, 5], etc. The output token will have a - * destructor and copy constructor associated with it so that its memory can be - * managed automatically by the C runtime. + * @brief Produce a sequence of arrays of length 3 with increasing values. Values are produced at + * intervals of 1 ms. The first arrray has value [0, 1, 2], the second has value [3, 4, 5], etc. The + * output token will have a destructor and copy constructor associated with it so that its memory + * can be managed automatically by the C runtime. */ reactor TokenSource { - output out: int_array_t* - state count: int = 0 - timer t(0, 1 ms) + output out: int_array_t* + state count: int = 0 + timer t(0, 1 ms) - reaction(startup) -> out {= - lf_set_destructor(out, int_array_destructor); - lf_set_copy_constructor(out, int_array_copy_constructor); - =} + reaction(startup) -> out {= + lf_set_destructor(out, int_array_destructor); + lf_set_copy_constructor(out, int_array_copy_constructor); + =} - reaction(t) -> out {= - int_array_t* array = int_array_constructor(3); - for (size_t i = 0; i < array->length; i++) { - array->data[i] = self->count++; - } - lf_set(out, array); - =} + reaction(t) -> out {= + int_array_t* array = int_array_constructor(3); + for (size_t i = 0; i < array->length; i++) { + array->data[i] = self->count++; + } + lf_set(out, array); + =} } /** - * @brief Print input array values and test for expected value. The expected - * value is a scaled version of the sequence of values produced by the - * TokenSource, where the scaling factor is given by the scale parameter. + * @brief Print input array values and test for expected value. The expected value is a scaled + * version of the sequence of values produced by the TokenSource, where the scaling factor is given + * by the scale parameter. */ reactor TokenPrint(scale: int = 1) { - input in: int_array_t* - state count: int = 0 - state input_received: bool = false + input in: int_array_t* + state count: int = 0 + state input_received: bool = false - reaction(in) {= - self->input_received = true; - bool failed = false; // For testing. - printf("TokenPrint received: ["); - for (int i = 0; i < in->value->length; i++) { - if (i > 0) printf(", "); - printf("%d", in->value->data[i]); - // For testing, check whether values match expectation. - if (in->value->data[i] != self->scale * self->count) { - failed = true; - } - self->count++; - } - printf("]\n"); - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); + reaction(in) {= + self->input_received = true; + bool failed = false; // For testing. + printf("TokenPrint received: ["); + for (int i = 0; i < in->value->length; i++) { + if (i > 0) printf(", "); + printf("%d", in->value->data[i]); + // For testing, check whether values match expectation. + if (in->value->data[i] != self->scale * self->count) { + failed = true; } - =} + self->count++; + } + printf("]\n"); + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} - reaction(shutdown) {= - if (!self->input_received) { - lf_print_error_and_exit("TokenPrint: No input received!"); - } - =} + reaction(shutdown) {= + if (!self->input_received) { + lf_print_error_and_exit("TokenPrint: No input received!"); + } + =} } /** - * @brief Multiply an input array by the scale factor given as a parameter. The - * input is declared mutable so, if possible, the input token will be modified - * rather than allocating a new token. + * @brief Multiply an input array by the scale factor given as a parameter. The input is declared + * mutable so, if possible, the input token will be modified rather than allocating a new token. */ reactor TokenScale(scale: int = 2) { - mutable input in: int_array_t* - output out: int_array_t* + mutable input in: int_array_t* + output out: int_array_t* - reaction(in) -> out {= - for (int i = 0; i < in->value->length; i++) { - in->value->data[i] *= self->scale; - } - lf_set_token(out, in->token); - =} + reaction(in) -> out {= + for (int i = 0; i < in->value->length; i++) { + in->value->data[i] *= self->scale; + } + lf_set_token(out, in->token); + =} } /** @brief Delay a token using a logical action. The delay is 1 ms. */ reactor TokenDelay { - input in: int_array_t* - output out: int_array_t* - logical action a: int_array_t* + input in: int_array_t* + output out: int_array_t* + logical action a: int_array_t* - reaction(a) -> out {= lf_set_token(out, a->token); =} + reaction(a) -> out {= lf_set_token(out, a->token); =} - reaction(in) -> a {= lf_schedule_token(a, MSEC(1), in->token); =} + reaction(in) -> a {= lf_schedule_token(a, MSEC(1), in->token); =} } diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index 3ce632796b..aae4f62252 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -1,7 +1,7 @@ target C { - platform: "Zephyr" + platform: "Zephyr" } main reactor { - reaction(startup) {= printf("Hello World!\n"); =} + reaction(startup) {= printf("Hello World!\n"); =} } diff --git a/test/C/src/zephyr/Timer.lf b/test/C/src/zephyr/Timer.lf index d3cb3f96de..56f2d9002f 100644 --- a/test/C/src/zephyr/Timer.lf +++ b/test/C/src/zephyr/Timer.lf @@ -1,14 +1,14 @@ target C { - platform: { - name: Zephyr, - board: qemu_cortex_m3 - }, - threading: false, - timeout: 10 sec + platform: { + name: Zephyr, + board: qemu_cortex_m3 + }, + threading: false, + timeout: 10 sec } main reactor { - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) {= printf("Hello\n"); =} + reaction(t) {= printf("Hello\n"); =} } diff --git a/test/C/src/zephyr/lib/Led.lf b/test/C/src/zephyr/lib/Led.lf index 04999cf14b..e634fac745 100644 --- a/test/C/src/zephyr/lib/Led.lf +++ b/test/C/src/zephyr/lib/Led.lf @@ -1,32 +1,32 @@ target C reactor NrfLeds { - preamble {= - #include - #include - #define LED0_NODE DT_ALIAS(led0) - #define LED1_NODE DT_ALIAS(led1) - #define LED2_NODE DT_ALIAS(led2) - #define LED3_NODE DT_ALIAS(led3) - static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); - static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); - static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); - static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios); - =} - timer t(0, 100 msec) + preamble {= + #include + #include + #define LED0_NODE DT_ALIAS(led0) + #define LED1_NODE DT_ALIAS(led1) + #define LED2_NODE DT_ALIAS(led2) + #define LED3_NODE DT_ALIAS(led3) + static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); + static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); + static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); + static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios); + =} + timer t(0, 100 msec) - reaction(startup) {= - gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); - gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); - gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); - gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE); - =} + reaction(startup) {= + gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE); + =} - reaction(t) {= - printf("Hello\n"); - gpio_pin_toggle_dt(&led0); - gpio_pin_toggle_dt(&led1); - gpio_pin_toggle_dt(&led2); - gpio_pin_toggle_dt(&led3); - =} + reaction(t) {= + printf("Hello\n"); + gpio_pin_toggle_dt(&led0); + gpio_pin_toggle_dt(&led1); + gpio_pin_toggle_dt(&led2); + gpio_pin_toggle_dt(&led3); + =} } diff --git a/test/Cpp/src/ActionDelay.lf b/test/Cpp/src/ActionDelay.lf index 14210e1009..03b6b8beb9 100644 --- a/test/Cpp/src/ActionDelay.lf +++ b/test/Cpp/src/ActionDelay.lf @@ -2,49 +2,49 @@ target Cpp reactor GeneratedDelay { - input y_in: int - output y_out: int - state y_state: int = 0 - logical action act(100 msec): void + input y_in: int + output y_out: int + state y_state: int = 0 + logical action act(100 msec): void - reaction(y_in) -> act {= - y_state = *y_in.get(); - act.schedule(); - =} + reaction(y_in) -> act {= + y_state = *y_in.get(); + act.schedule(); + =} - reaction(act) -> y_out {= y_out.set(y_state); =} + reaction(act) -> y_out {= y_out.set(y_state); =} } reactor Source { - output out: int + output out: int - reaction(startup) -> out {= out.set(1); =} + reaction(startup) -> out {= out.set(1); =} } reactor Sink { - input in: int - - reaction(in) {= - auto elapsed_logical = get_elapsed_logical_time(); - auto logical = get_logical_time(); - auto physical = get_physical_time(); - std::cout << "logical time: " << logical << '\n'; - std::cout << "physical time: " << physical << '\n'; - std::cout << "elapsed logical time: " << elapsed_logical << '\n'; - if (elapsed_logical != 100ms) { - std::cerr << "ERROR: Expected 100 msecs but got " << elapsed_logical << '\n'; - exit(1); - } else { - std::cout << "SUCCESS. Elapsed logical time is 100 msec.\n"; - } - =} + input in: int + + reaction(in) {= + auto elapsed_logical = get_elapsed_logical_time(); + auto logical = get_logical_time(); + auto physical = get_physical_time(); + std::cout << "logical time: " << logical << '\n'; + std::cout << "physical time: " << physical << '\n'; + std::cout << "elapsed logical time: " << elapsed_logical << '\n'; + if (elapsed_logical != 100ms) { + std::cerr << "ERROR: Expected 100 msecs but got " << elapsed_logical << '\n'; + exit(1); + } else { + std::cout << "SUCCESS. Elapsed logical time is 100 msec.\n"; + } + =} } main reactor ActionDelay { - source = new Source() - sink = new Sink() - g = new GeneratedDelay() + source = new Source() + sink = new Sink() + g = new GeneratedDelay() - source.out -> g.y_in - g.y_out -> sink.in + source.out -> g.y_in + g.y_out -> sink.in } diff --git a/test/Cpp/src/ActionIsPresent.lf b/test/Cpp/src/ActionIsPresent.lf index e98c2a2a32..4a75c262c7 100644 --- a/test/Cpp/src/ActionIsPresent.lf +++ b/test/Cpp/src/ActionIsPresent.lf @@ -2,28 +2,28 @@ target Cpp main reactor ActionIsPresent(offset: time = 1 nsec, period: time(500 msec)) { - logical action a - state success: bool = false - state zero: time = 0 nsec + logical action a + state success: bool = false + state zero: time = 0 nsec - reaction(startup, a) -> a {= - if (!a.is_present()) { - if (offset == zero) { - std::cout << "Hello World!" << '\n'; - success = true; - } else { - a.schedule(offset); - } - } else { - std::cout << "Hello World 2!" << '\n'; + reaction(startup, a) -> a {= + if (!a.is_present()) { + if (offset == zero) { + std::cout << "Hello World!" << '\n'; success = true; + } else { + a.schedule(offset); } - =} + } else { + std::cout << "Hello World 2!" << '\n'; + success = true; + } + =} - reaction(shutdown) {= - if (!success) { - std::cerr << "Failed to print 'Hello World!'" << '\n'; - exit(1); - } - =} + reaction(shutdown) {= + if (!success) { + std::cerr << "Failed to print 'Hello World!'" << '\n'; + exit(1); + } + =} } diff --git a/test/Cpp/src/ActionValues.lf b/test/Cpp/src/ActionValues.lf index 8d115c60fa..6e40e2d526 100644 --- a/test/Cpp/src/ActionValues.lf +++ b/test/Cpp/src/ActionValues.lf @@ -2,46 +2,46 @@ target Cpp main reactor ActionValues { - state r1done: bool = false - state r2done: bool = false - logical action act(100 msec): int + state r1done: bool = false + state r2done: bool = false + logical action act(100 msec): int - reaction(startup) -> act {= - act.schedule(100); // scheduled in 100 ms - std::chrono::milliseconds delay(50); - act.schedule(-100, delay); // scheduled in 150 ms, value is overwritten - =} + reaction(startup) -> act {= + act.schedule(100); // scheduled in 100 ms + std::chrono::milliseconds delay(50); + act.schedule(-100, delay); // scheduled in 150 ms, value is overwritten + =} - reaction(act) {= - auto elapsed = get_elapsed_logical_time(); + reaction(act) {= + auto elapsed = get_elapsed_logical_time(); - std::cout << "[@" << elapsed << '\n'; - std::cout << " action transmitted: " << *act.get() << '\n'; - std::cout << "]\n"; + std::cout << "[@" << elapsed << '\n'; + std::cout << " action transmitted: " << *act.get() << '\n'; + std::cout << "]\n"; - if (elapsed == 100ms) { - if (*act.get() != 100) { - std::cerr << "ERROR: Expected action value to be 100\n"; - exit(1); - } - r1done = true; - } else { - if (elapsed != 150ms) { - std::cerr << "ERROR: Unexpected reaction invocation at " << elapsed << '\n'; - exit(1); - } - if (*act.get() != -100) { - std::cerr << "ERROR: Expected action value to be -100\n"; - exit(1); - } - r2done = true; + if (elapsed == 100ms) { + if (*act.get() != 100) { + std::cerr << "ERROR: Expected action value to be 100\n"; + exit(1); } - =} - - reaction(shutdown) {= - if (!r1done || !r2done) { - std::cerr << "ERROR: Expected 2 reaction invocations\n"; + r1done = true; + } else { + if (elapsed != 150ms) { + std::cerr << "ERROR: Unexpected reaction invocation at " << elapsed << '\n'; exit(1); } - =} + if (*act.get() != -100) { + std::cerr << "ERROR: Expected action value to be -100\n"; + exit(1); + } + r2done = true; + } + =} + + reaction(shutdown) {= + if (!r1done || !r2done) { + std::cerr << "ERROR: Expected 2 reaction invocations\n"; + exit(1); + } + =} } diff --git a/test/Cpp/src/After.lf b/test/Cpp/src/After.lf index bbcc287b78..30405a258b 100644 --- a/test/Cpp/src/After.lf +++ b/test/Cpp/src/After.lf @@ -1,55 +1,54 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target Cpp { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor foo { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(2*(*x.get())); =} + reaction(x) -> y {= y.set(2*(*x.get())); =} } reactor print { - state expected_time: time = 10 msec - state i: int = 0 - input x: int + state expected_time: time = 10 msec + state i: int = 0 + input x: int - reaction(x) {= - i++; - auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Result is " << *x.get() << '\n'; - if (*x.get() != 84) { - std::cerr << "ERROR: Expected result to be 84.\n"; - exit(1); - } - std::cout << "Current logical time is: " << elapsed_time << '\n'; - std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; - if (elapsed_time != expected_time) { - std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; - exit(2); - } - expected_time += 1s; - =} + reaction(x) {= + i++; + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Result is " << *x.get() << '\n'; + if (*x.get() != 84) { + std::cerr << "ERROR: Expected result to be 84.\n"; + exit(1); + } + std::cout << "Current logical time is: " << elapsed_time << '\n'; + std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; + if (elapsed_time != expected_time) { + std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; + exit(2); + } + expected_time += 1s; + =} - reaction(shutdown) {= - if (i == 0) { - std::cerr << "ERROR: Final reactor received no data.\n"; - exit(3); - } - =} + reaction(shutdown) {= + if (i == 0) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= - f.x.set(42); - std::cout << "Timer!\n"; - =} + reaction(t) -> f.x {= + f.x.set(42); + std::cout << "Timer!\n"; + =} } diff --git a/test/Cpp/src/AfterOverlapped.lf b/test/Cpp/src/AfterOverlapped.lf index 6a85eaf5bc..0ef3c57da5 100644 --- a/test/Cpp/src/AfterOverlapped.lf +++ b/test/Cpp/src/AfterOverlapped.lf @@ -1,43 +1,43 @@ // This the after keyword with overlapped time intervals. target Cpp { - fast: true, - timeout: 5 sec + fast: true, + timeout: 5 sec } import Count from "lib/Count.lf" reactor Test { - input c: int - state i: int = 0 + input c: int + state i: int = 0 - reaction(c) {= - std::cout << "Received " << *c.get() << '\n'; - i++; - if (*c.get() != i) { - std::cerr << "ERROR: Expected " << i << " but got " << *c.get() << '\n'; - exit(1); - } - auto elapsed_time = get_elapsed_logical_time(); + reaction(c) {= + std::cout << "Received " << *c.get() << '\n'; + i++; + if (*c.get() != i) { + std::cerr << "ERROR: Expected " << i << " but got " << *c.get() << '\n'; + exit(1); + } + auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Elapsed logical time is: " << elapsed_time << '\n'; + std::cout << "Elapsed logical time is: " << elapsed_time << '\n'; - auto expected = 2s + ((*c.get() - 1) * 1s); - if (elapsed_time != expected) { - std::cerr << "ERROR: Expected logical time to be " << expected << '\n'; - exit(1); - } - =} + auto expected = 2s + ((*c.get() - 1) * 1s); + if (elapsed_time != expected) { + std::cerr << "ERROR: Expected logical time to be " << expected << '\n'; + exit(1); + } + =} - reaction(shutdown) {= - if (i == 0) { - std::cerr << "ERROR: Final reactor received no data.\n"; - exit(3); - } - =} + reaction(shutdown) {= + if (i == 0) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} } main reactor { - count = new Count() - test = new Test() - count.c -> test.c after 2 sec + count = new Count() + test = new Test() + count.c -> test.c after 2 sec } diff --git a/test/Cpp/src/AfterZero.lf b/test/Cpp/src/AfterZero.lf index 152b87cfc2..a52ce7cedb 100644 --- a/test/Cpp/src/AfterZero.lf +++ b/test/Cpp/src/AfterZero.lf @@ -1,60 +1,59 @@ -// This checks that the after keyword adjusts logical time, not using physical -// time. +// This checks that the after keyword adjusts logical time, not using physical time. target Cpp { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor foo { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(2*(*x.get())); =} + reaction(x) -> y {= y.set(2*(*x.get())); =} } reactor print { - state expected_time: time = 0 - state i: int = 0 - input x: int + state expected_time: time = 0 + state i: int = 0 + input x: int - reaction(x) {= - i++; - auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Result is " << *x.get() << '\n'; - if (*x.get() != 84) { - std::cerr << "ERROR: Expected result to be 84.\n"; - exit(1); - } - std::cout << "Current logical time is: " << elapsed_time << '\n'; - std::cout << "Current microstep is: " << get_microstep() << '\n'; - std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; - if (elapsed_time != expected_time) { - std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; - exit(2); - } - if (get_microstep() != 1) { - std::cerr << "Expected microstrp to be 1\n"; - exit(3); - } - expected_time += 1s; - =} + reaction(x) {= + i++; + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Result is " << *x.get() << '\n'; + if (*x.get() != 84) { + std::cerr << "ERROR: Expected result to be 84.\n"; + exit(1); + } + std::cout << "Current logical time is: " << elapsed_time << '\n'; + std::cout << "Current microstep is: " << get_microstep() << '\n'; + std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; + if (elapsed_time != expected_time) { + std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; + exit(2); + } + if (get_microstep() != 1) { + std::cerr << "Expected microstrp to be 1\n"; + exit(3); + } + expected_time += 1s; + =} - reaction(shutdown) {= - if (i == 0) { - std::cerr << "ERROR: Final reactor received no data.\n"; - exit(3); - } - =} + reaction(shutdown) {= + if (i == 0) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 0 + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 0 - reaction(t) -> f.x {= - f.x.set(42); - std::cout << "Timer!\n"; - =} + reaction(t) -> f.x {= + f.x.set(42); + std::cout << "Timer!\n"; + =} } diff --git a/test/Cpp/src/Alignment.lf b/test/Cpp/src/Alignment.lf index 1bd3562f41..674c29c34c 100644 --- a/test/Cpp/src/Alignment.lf +++ b/test/Cpp/src/Alignment.lf @@ -1,105 +1,104 @@ -// This test checks that the downstream reaction is not invoked more than once -// at a logical time. +// This test checks that the downstream reaction is not invoked more than once at a logical time. target Cpp { - logging: LOG, - timeout: 1 sec, - build-type: Debug + logging: LOG, + timeout: 1 sec, + build-type: Debug } reactor Source { - output out: int - state count: int = 1 - timer t(0, 100 msec) + output out: int + state count: int = 1 + timer t(0, 100 msec) - reaction(t) -> out {= - count++; - out.set(count); - =} + reaction(t) -> out {= + count++; + out.set(count); + =} } reactor Sieve { - private preamble {= - #include "reactor-cpp/logging.hh" - =} - input in: int - output out: bool - state primes: std::vector + private preamble {= + #include "reactor-cpp/logging.hh" + =} + input in: int + output out: bool + state primes: std::vector - reaction(startup) {= - // There are 1229 primes between 1 and 10,000. - // Primes 1 and 2 are not on the list. - primes.push_back(3); - =} + reaction(startup) {= + // There are 1229 primes between 1 and 10,000. + // Primes 1 and 2 are not on the list. + primes.push_back(3); + =} - reaction(in) -> out {= - // Reject out of bounds inputs - if(*in.get() <= 0 || *in.get() > 10000) { - reactor::log::Warn() << "Sieve: Input value out of range: " << *in.get(); - } - // Primes 1 and 2 are not on the list. - if (*in.get() == 1 || *in.get() == 2) { - out.set(true); - return; - } - // If the input is greater than the last found prime, then - // we have to expand the list of primes before checking to - // see whether this is prime. - int candidate = primes.back(); - reactor::log::Info() << "Sieve: Checking prime: " << candidate; - while (*in.get() > primes.back()) { - candidate += 2; - bool prime = true; - for (auto i : primes) { - if(candidate % i == 0) { - // Candidate is not prime. Break and add 2 by starting the loop again - prime = false; - break; - } - } - // If the candidate is not divisible by any prime in the list, it is prime - if (prime) { - primes.push_back(candidate); - reactor::log::Info() << "Sieve: Found prime: " << candidate; + reaction(in) -> out {= + // Reject out of bounds inputs + if(*in.get() <= 0 || *in.get() > 10000) { + reactor::log::Warn() << "Sieve: Input value out of range: " << *in.get(); + } + // Primes 1 and 2 are not on the list. + if (*in.get() == 1 || *in.get() == 2) { + out.set(true); + return; + } + // If the input is greater than the last found prime, then + // we have to expand the list of primes before checking to + // see whether this is prime. + int candidate = primes.back(); + reactor::log::Info() << "Sieve: Checking prime: " << candidate; + while (*in.get() > primes.back()) { + candidate += 2; + bool prime = true; + for (auto i : primes) { + if(candidate % i == 0) { + // Candidate is not prime. Break and add 2 by starting the loop again + prime = false; + break; } } + // If the candidate is not divisible by any prime in the list, it is prime + if (prime) { + primes.push_back(candidate); + reactor::log::Info() << "Sieve: Found prime: " << candidate; + } + } - // We are now assured that the input is less than or - // equal to the last prime on the list. - // See whether the input is an already found prime. - // Search the primes from the end, where they are sparser. - for (auto i = primes.rbegin(); i != primes.rend(); ++i) { - if(*i == *in.get()) { - out.set(true); - return; - } + // We are now assured that the input is less than or + // equal to the last prime on the list. + // See whether the input is an already found prime. + // Search the primes from the end, where they are sparser. + for (auto i = primes.rbegin(); i != primes.rend(); ++i) { + if(*i == *in.get()) { + out.set(true); + return; } - =} + } + =} } reactor Destination { - input ok: bool - input in: int - state last_invoked: {= reactor::TimePoint =} + input ok: bool + input in: int + state last_invoked: {= reactor::TimePoint =} - reaction(ok, in) {= - if (ok.is_present() && in.is_present()) { - reactor::log::Info() << "Destination: Input " << *in.get() << " is a prime at logical time ( " - << get_elapsed_logical_time() << " )"; - } - if( get_logical_time() <= last_invoked) { - reactor::log::Error() << "Invoked at logical time (" << get_logical_time() << ") " - << "but previously invoked at logical time (" << get_elapsed_logical_time() << ")"; - } + reaction(ok, in) {= + if (ok.is_present() && in.is_present()) { + reactor::log::Info() << "Destination: Input " << *in.get() << " is a prime at logical time ( " + << get_elapsed_logical_time() << " )"; + } + if( get_logical_time() <= last_invoked) { + reactor::log::Error() << "Invoked at logical time (" << get_logical_time() << ") " + << "but previously invoked at logical time (" << get_elapsed_logical_time() << ")"; + } - last_invoked = get_logical_time(); - =} + last_invoked = get_logical_time(); + =} } main reactor { - source = new Source() - sieve = new Sieve() - destination = new Destination() - source.out -> sieve.in - sieve.out -> destination.ok - source.out -> destination.in + source = new Source() + sieve = new Sieve() + destination = new Destination() + source.out -> sieve.in + sieve.out -> destination.ok + source.out -> destination.in } diff --git a/test/Cpp/src/ArrayAsParameter.lf b/test/Cpp/src/ArrayAsParameter.lf index 85cd0630bf..d2bf3c5ef9 100644 --- a/test/Cpp/src/ArrayAsParameter.lf +++ b/test/Cpp/src/ArrayAsParameter.lf @@ -1,44 +1,43 @@ -// Source has an variable sized list as a parameter, the elements of which it -// passes to Print. +// Source has an variable sized list as a parameter, the elements of which it passes to Print. target Cpp reactor Source(sequence: std::vector = {0, 1, 2}) { - output out: size_t - state count: size_t = 0 - logical action next: void + output out: size_t + state count: size_t = 0 + logical action next: void - reaction(startup, next) -> out, next {= - out.set(sequence[count]); - count++; - if (count < sequence.size()) { - next.schedule(); - } - =} + reaction(startup, next) -> out, next {= + out.set(sequence[count]); + count++; + if (count < sequence.size()) { + next.schedule(); + } + =} } reactor Print { - input in: size_t - state count: size_t = 1 + input in: size_t + state count: size_t = 1 - reaction(in) {= - std::cout << "Received: " << *in.get() << '\n'; - if (*in.get() != count) { - std::cerr << "ERROR: Expected " << count << '\n'; - exit(1); - } - count++; - =} + reaction(in) {= + std::cout << "Received: " << *in.get() << '\n'; + if (*in.get() != count) { + std::cerr << "ERROR: Expected " << count << '\n'; + exit(1); + } + count++; + =} - reaction(shutdown) {= - if (count == 1) { - std::cerr << "ERROR: Final reactor received no data.\n"; - exit(3); - } - =} + reaction(shutdown) {= + if (count == 1) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} } main reactor ArrayAsParameter { - s = new Source(sequence = {1, 2, 3, 4}) - p = new Print() - s.out -> p.in + s = new Source(sequence = {1, 2, 3, 4}) + p = new Print() + s.out -> p.in } diff --git a/test/Cpp/src/ArrayPrint.lf b/test/Cpp/src/ArrayPrint.lf index 3bdf494107..c0cbcff6fc 100644 --- a/test/Cpp/src/ArrayPrint.lf +++ b/test/Cpp/src/ArrayPrint.lf @@ -1,56 +1,55 @@ -// Source produces a dynamically allocated array, which it passes to Print. The -// ownership semantics of values ensure that the array is automatically deleted -// if it does have no owner. +// Source produces a dynamically allocated array, which it passes to Print. The ownership semantics +// of values ensure that the array is automatically deleted if it does have no owner. target Cpp reactor Source { - output out: int[3] - - reaction(startup) -> out {= - // create a dynamically allocated mutable array - auto result = reactor::make_mutable_value>(); - (*result)[0] = 0; - (*result)[1] = 1; - (*result)[2] = 2; - // Send the array and move ownership. This implicitly converts the mutable - // value to an immutable value. - out.set(std::move(result)); - =} + output out: int[3] + + reaction(startup) -> out {= + // create a dynamically allocated mutable array + auto result = reactor::make_mutable_value>(); + (*result)[0] = 0; + (*result)[1] = 1; + (*result)[2] = 2; + // Send the array and move ownership. This implicitly converts the mutable + // value to an immutable value. + out.set(std::move(result)); + =} } reactor Print(scale: int = 1) { - input in: int[3] - - reaction(in) {= - int expected = 0; - bool failed = false; - - // get a reference to the result to avoid a copy - auto& result = *in.get(); - - std::cout << "Received: ["; - for (int i = 0; i < 3; i++) { - std::cout << result[i]; - if (i < 2) { - std::cout << ", "; - } - - // check whether values match expectation. - if (result[i] != expected * scale) { - failed = true; - } - expected++; + input in: int[3] + + reaction(in) {= + int expected = 0; + bool failed = false; + + // get a reference to the result to avoid a copy + auto& result = *in.get(); + + std::cout << "Received: ["; + for (int i = 0; i < 3; i++) { + std::cout << result[i]; + if (i < 2) { + std::cout << ", "; } - std::cout << "]\n"; - if (failed) { - printf("ERROR: Value received by Print does not match expectation!\n"); - exit(1); + + // check whether values match expectation. + if (result[i] != expected * scale) { + failed = true; } - =} + expected++; + } + std::cout << "]\n"; + if (failed) { + printf("ERROR: Value received by Print does not match expectation!\n"); + exit(1); + } + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/Cpp/src/ArrayScale.lf b/test/Cpp/src/ArrayScale.lf index b52e7305b7..89bdf68ab9 100644 --- a/test/Cpp/src/ArrayScale.lf +++ b/test/Cpp/src/ArrayScale.lf @@ -1,31 +1,30 @@ -// Source produces a dynamically allocated array, which it passes to Scale. -// Scale requests a writable copy. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated array, which it passes to Scale. Scale requests a +// writable copy. It modifies it and passes it to Print. It gets freed after Print is done with it. target Cpp import Source, Print from "ArrayPrint.lf" reactor Scale(scale: int = 2) { - input in: int[3] + input in: int[3] - output out: int[3] + output out: int[3] - reaction(in) -> out {= - // create a mutable copy of the received input - auto array = in.get().get_mutable_copy(); - // NOTE: Ideally, no copy copy would be made here, as there is only - // one recipient for the value, but this is not supported yet by the C++ runtime. - for(int i = 0; i < array->size(); i++) { - (*array)[i] = (*array)[i] * scale; - } - out.set(std::move(array)); - =} + reaction(in) -> out {= + // create a mutable copy of the received input + auto array = in.get().get_mutable_copy(); + // NOTE: Ideally, no copy copy would be made here, as there is only + // one recipient for the value, but this is not supported yet by the C++ runtime. + for(int i = 0; i < array->size(); i++) { + (*array)[i] = (*array)[i] * scale; + } + out.set(std::move(array)); + =} } main reactor ArrayScale { - s = new Source() - c = new Scale(scale = 2) - p = new Print(scale = 2) - s.out -> c.in - c.out -> p.in + s = new Source() + c = new Scale(scale = 2) + p = new Print(scale = 2) + s.out -> c.in + c.out -> p.in } diff --git a/test/Cpp/src/CharLiteralInitializer.lf b/test/Cpp/src/CharLiteralInitializer.lf index e01e5973a6..3a104b2bb3 100644 --- a/test/Cpp/src/CharLiteralInitializer.lf +++ b/test/Cpp/src/CharLiteralInitializer.lf @@ -2,12 +2,12 @@ target Cpp main reactor CharLiteralInitializer { - state c: char = 'x' + state c: char = 'x' - reaction(startup) {= - if (c != 'x') { - std::cout << "FAILED: Expected 'x', got " << c << '\n'; - exit(1); - } - =} + reaction(startup) {= + if (c != 'x') { + std::cout << "FAILED: Expected 'x', got " << c << '\n'; + exit(1); + } + =} } diff --git a/test/Cpp/src/Composition.lf b/test/Cpp/src/Composition.lf index 0a341d5e4f..79105666d5 100644 --- a/test/Cpp/src/Composition.lf +++ b/test/Cpp/src/Composition.lf @@ -1,45 +1,44 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target Cpp { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - count++; - y.set(count); - =} + reaction(t) -> y {= + count++; + y.set(count); + =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - count++; - auto value = *x.get(); - std::cout << "Received " << value << std::endl; - if (value != count) { - std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); - } - =} + reaction(x) {= + count++; + auto value = *x.get(); + std::cout << "Received " << value << std::endl; + if (value != count) { + std::cerr << "FAILURE: Expected " << count << std::endl; + exit(1); + } + =} - reaction(shutdown) {= - if (count != 5) { - std::cerr << "ERROR: expected to receive 5 values but got " << count << '\n'; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 5) { + std::cerr << "ERROR: expected to receive 5 values but got " << count << '\n'; + exit(1); + } + =} } main reactor Composition { - s = new Source() - d = new Test() - s.y -> d.x + s = new Source() + d = new Test() + s.y -> d.x } diff --git a/test/Cpp/src/CompositionAfter.lf b/test/Cpp/src/CompositionAfter.lf index 15d68e13ea..265cc3b249 100644 --- a/test/Cpp/src/CompositionAfter.lf +++ b/test/Cpp/src/CompositionAfter.lf @@ -1,45 +1,44 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target Cpp { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - count++; - y.set(count); - =} + reaction(t) -> y {= + count++; + y.set(count); + =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - count++; - auto value = *x.get(); - std::cout << "Received " << value << std::endl; - if (value != count) { - std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); - } - =} + reaction(x) {= + count++; + auto value = *x.get(); + std::cout << "Received " << value << std::endl; + if (value != count) { + std::cerr << "FAILURE: Expected " << count << std::endl; + exit(1); + } + =} - reaction(shutdown) {= - if (count != 3) { - std::cerr << "ERROR: expected to receive 3 values but got " << count << '\n'; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 3) { + std::cerr << "ERROR: expected to receive 3 values but got " << count << '\n'; + exit(1); + } + =} } main reactor(delay: time = 5 sec) { - s = new Source() - d = new Test() - s.y -> d.x after delay + s = new Source() + d = new Test() + s.y -> d.x after delay } diff --git a/test/Cpp/src/CountTest.lf b/test/Cpp/src/CountTest.lf index 838d84a998..d272ee39ca 100644 --- a/test/Cpp/src/CountTest.lf +++ b/test/Cpp/src/CountTest.lf @@ -1,25 +1,25 @@ target Cpp { - timeout: 3 sec, - fast: true + timeout: 3 sec, + fast: true } import Count from "lib/Count.lf" reactor Test { - input c: int - state i: int = 0 + input c: int + state i: int = 0 - reaction(c) {= - i++; - if (*c.get() != i) { - std::cerr << "ERROR: Expected " << i << " but got " << *c.get() << std::endl; - exit(1); - } - =} + reaction(c) {= + i++; + if (*c.get() != i) { + std::cerr << "ERROR: Expected " << i << " but got " << *c.get() << std::endl; + exit(1); + } + =} } main reactor CountTest { - count = new Count() - test = new Test() - count.c -> test.c + count = new Count() + test = new Test() + count.c -> test.c } diff --git a/test/Cpp/src/Deadline.lf b/test/Cpp/src/Deadline.lf index 19a41ff057..90f0a70af6 100644 --- a/test/Cpp/src/Deadline.lf +++ b/test/Cpp/src/Deadline.lf @@ -1,59 +1,58 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target Cpp { - timeout: 4 sec + timeout: 4 sec } reactor Source(period: time = 2 sec) { - private preamble {= - #include - =} - output y: int - timer t(0, period) - state count: int = 0 + private preamble {= + #include + =} + output y: int + timer t(0, period) + state count: int = 0 - reaction(t) -> y {= - if (count % 2 == 1) { - // The count variable is odd. - // Take time to cause a deadline violation. - std::this_thread::sleep_for(400ms); - } - std::cout << "Source sends: " << count << std::endl; - y.set(count); - count++; - =} + reaction(t) -> y {= + if (count % 2 == 1) { + // The count variable is odd. + // Take time to cause a deadline violation. + std::this_thread::sleep_for(400ms); + } + std::cout << "Source sends: " << count << std::endl; + y.set(count); + count++; + =} } reactor Destination(timeout: time = 1 sec) { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - std::cout << "Destination receives: " << *x.get() << std::endl; - if (count % 2 == 1) { - // The count variable is odd, so the deadline should have been - // violated - std::cerr << "ERROR: Failed to detect deadline." << std::endl; - exit(1); - } - count++; - =} deadline(timeout) {= - std::cout << "Destination deadline handler receives: " - << *x.get() << std::endl; - if (count % 2 == 0) { - // The count variable is even, so the deadline should not have - // been violated. - std::cerr << "ERROR: Deadline handler invoked without deadline " - << "violation." << std::endl; - exit(2); - } - count++; - =} + reaction(x) {= + std::cout << "Destination receives: " << *x.get() << std::endl; + if (count % 2 == 1) { + // The count variable is odd, so the deadline should have been + // violated + std::cerr << "ERROR: Failed to detect deadline." << std::endl; + exit(1); + } + count++; + =} deadline(timeout) {= + std::cout << "Destination deadline handler receives: " + << *x.get() << std::endl; + if (count % 2 == 0) { + // The count variable is even, so the deadline should not have + // been violated. + std::cerr << "ERROR: Deadline handler invoked without deadline " + << "violation." << std::endl; + exit(2); + } + count++; + =} } main reactor Deadline { - s = new Source() - d = new Destination(timeout = 200 msec) - s.y -> d.x + s = new Source() + d = new Destination(timeout = 200 msec) + s.y -> d.x } diff --git a/test/Cpp/src/DeadlineHandledAbove.lf b/test/Cpp/src/DeadlineHandledAbove.lf index b2a6c7658a..17ed373ab0 100644 --- a/test/Cpp/src/DeadlineHandledAbove.lf +++ b/test/Cpp/src/DeadlineHandledAbove.lf @@ -1,42 +1,42 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target Cpp reactor Deadline(threshold: time = 100 msec) { - input x: int - output deadline_violation: bool + input x: int + output deadline_violation: bool - reaction(x) -> deadline_violation {= - std::cerr << "ERROR: Deadline violation was not detected!" << std::endl; - exit(1); - =} deadline(threshold) {= - std::cout << "Deadline violation detected." << std::endl; - deadline_violation.set(true); - =} + reaction(x) -> deadline_violation {= + std::cerr << "ERROR: Deadline violation was not detected!" << std::endl; + exit(1); + =} deadline(threshold) {= + std::cout << "Deadline violation detected." << std::endl; + deadline_violation.set(true); + =} } main reactor DeadlineHandledAbove { - state violation_detected: bool = {= false =} - d = new Deadline(threshold = 10 msec) + state violation_detected: bool = {= false =} + d = new Deadline(threshold = 10 msec) - reaction(startup) -> d.x {= - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - d.x.set(42); - =} + reaction(startup) -> d.x {= + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + d.x.set(42); + =} - reaction(d.deadline_violation) {= - if (*d.deadline_violation.get()) { - std::cout << "Output successfully produced by deadline miss handler." << std::endl; - violation_detected = true; - } - =} + reaction(d.deadline_violation) {= + if (*d.deadline_violation.get()) { + std::cout << "Output successfully produced by deadline miss handler." << std::endl; + violation_detected = true; + } + =} - reaction(shutdown) {= - if (violation_detected) { - std::cout << "SUCCESS. Test passes." << std::endl; - } else { - std::cerr << "ERROR. Container did not react to deadline violation." << std::endl; - exit(2); - } - =} + reaction(shutdown) {= + if (violation_detected) { + std::cout << "SUCCESS. Test passes." << std::endl; + } else { + std::cerr << "ERROR. Container did not react to deadline violation." << std::endl; + exit(2); + } + =} } diff --git a/test/Cpp/src/DelayInt.lf b/test/Cpp/src/DelayInt.lf index f58e5ef45b..d9c2e0afe7 100644 --- a/test/Cpp/src/DelayInt.lf +++ b/test/Cpp/src/DelayInt.lf @@ -2,53 +2,53 @@ target Cpp reactor Delay(delay: time = 100 msec) { - input in: int - output out: int - logical action d: int + input in: int + output out: int + logical action d: int - reaction(in) -> d {= d.schedule(in.get(), delay); =} + reaction(in) -> d {= d.schedule(in.get(), delay); =} - reaction(d) -> out {= - if (d.is_present()) { - out.set(d.get()); - } - =} + reaction(d) -> out {= + if (d.is_present()) { + out.set(d.get()); + } + =} } reactor Test { - input in: int - state start_time: {= reactor::TimePoint =} - timer start - - reaction(start) {= - // Record the logical time at the start. - start_time = get_logical_time(); - =} - - reaction(in) {= - std::cout << "Received: " << *in.get() << std::endl; - // Check the time of the input. - auto current_time = get_logical_time(); - auto elapsed = current_time - start_time; - std::cout << "After " << elapsed << " of logical time." << std::endl; - if (elapsed != 100ms) { - std::cerr << "ERROR: Expected elapsed time to be 100000000 nsecs. " - << "It was " << elapsed << std::endl; - exit(1); - } - if (*in.get() != 42) { - std::cerr << "ERROR: Expected input value to be 42. " - << "It was " << *in.get() << std::endl; - exit(2); - } - =} + input in: int + state start_time: {= reactor::TimePoint =} + timer start + + reaction(start) {= + // Record the logical time at the start. + start_time = get_logical_time(); + =} + + reaction(in) {= + std::cout << "Received: " << *in.get() << std::endl; + // Check the time of the input. + auto current_time = get_logical_time(); + auto elapsed = current_time - start_time; + std::cout << "After " << elapsed << " of logical time." << std::endl; + if (elapsed != 100ms) { + std::cerr << "ERROR: Expected elapsed time to be 100000000 nsecs. " + << "It was " << elapsed << std::endl; + exit(1); + } + if (*in.get() != 42) { + std::cerr << "ERROR: Expected input value to be 42. " + << "It was " << *in.get() << std::endl; + exit(2); + } + =} } main reactor DelayInt { - timer t - d = new Delay() - test = new Test() - d.out -> test.in + timer t + d = new Delay() + test = new Test() + d.out -> test.in - reaction(t) -> d.in {= d.in.set(42); =} + reaction(t) -> d.in {= d.in.set(42); =} } diff --git a/test/Cpp/src/DelayedAction.lf b/test/Cpp/src/DelayedAction.lf index 1ce1aea63f..d8f908cc73 100644 --- a/test/Cpp/src/DelayedAction.lf +++ b/test/Cpp/src/DelayedAction.lf @@ -1,25 +1,25 @@ target Cpp { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } main reactor DelayedAction { - timer t(0, 1 sec) - logical action a: void - state count: int = 0 + timer t(0, 1 sec) + logical action a: void + state count: int = 0 - reaction(t) -> a {= a.schedule(100ms); =} + reaction(t) -> a {= a.schedule(100ms); =} - reaction(a) {= - auto elapsed = get_elapsed_logical_time(); - std::cout << "Nanoseconds since start: " << elapsed << std::endl; + reaction(a) {= + auto elapsed = get_elapsed_logical_time(); + std::cout << "Nanoseconds since start: " << elapsed << std::endl; - auto expected = count * 1s + 100ms; - count++; - if (elapsed != expected) { - std::cerr << "Expected " << expected << " but got " - << elapsed << std::endl; - exit(1); - } - =} + auto expected = count * 1s + 100ms; + count++; + if (elapsed != expected) { + std::cerr << "Expected " << expected << " but got " + << elapsed << std::endl; + exit(1); + } + =} } diff --git a/test/Cpp/src/DoubleInvocation.lf b/test/Cpp/src/DoubleInvocation.lf index 956b54bb17..52496dbd9c 100644 --- a/test/Cpp/src/DoubleInvocation.lf +++ b/test/Cpp/src/DoubleInvocation.lf @@ -1,55 +1,53 @@ -// This illustrates a very strange bug that showed up and has now been fixed. -// This test ensures it does not reappear. At logical time zero, the two Print -// reactors used to be fired twice each at the same logical time. They should -// only be fired once. This behavior was oddly eliminated by either of the -// following actions, neither of which should affect this behavior: +// This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +// does not reappear. At logical time zero, the two Print reactors used to be fired twice each at +// the same logical time. They should only be fired once. This behavior was oddly eliminated by +// either of the following actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. -// * Sending only position, not velocity from Ball. (copied from the c version -// of the test) +// * Sending only position, not velocity from Ball. (copied from the c version of the test) target Cpp { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Ball { - output position: int - output velocity: int - state p: int = 200 - timer trigger(0, 1 sec) + output position: int + output velocity: int + state p: int = 200 + timer trigger(0, 1 sec) - reaction(trigger) -> position, velocity {= - position.set(p); - velocity.set(-1); - p -= 1; - =} + reaction(trigger) -> position, velocity {= + position.set(p); + velocity.set(-1); + p -= 1; + =} } reactor Print { - input velocity: int - input position: int - state previous: int = -1 + input velocity: int + input position: int + state previous: int = -1 - reaction(startup) {= - reactor::log::Info() << "####### Print startup"; - =} + reaction(startup) {= + reactor::log::Info() << "####### Print startup"; + =} - reaction(position, velocity) {= - if (position.is_present()) { - reactor::log::Info() << "Position: " << *position.get(); - } - if (*position.get() == previous) { - reactor::log::Error() << "Multiple firings at the same logical time!"; - exit(1); - } - =} + reaction(position, velocity) {= + if (position.is_present()) { + reactor::log::Info() << "Position: " << *position.get(); + } + if (*position.get() == previous) { + reactor::log::Error() << "Multiple firings at the same logical time!"; + exit(1); + } + =} } main reactor DoubleInvocation { - b1 = new Ball() - p = new Print() - plot = new Print() - b1.position -> p.position - b1.velocity -> p.velocity - b1.position -> plot.position - b1.velocity -> plot.velocity + b1 = new Ball() + p = new Print() + plot = new Print() + b1.position -> p.position + b1.velocity -> p.velocity + b1.position -> plot.position + b1.velocity -> plot.velocity } diff --git a/test/Cpp/src/DoublePort.lf b/test/Cpp/src/DoublePort.lf index faaa474db5..79a385873c 100644 --- a/test/Cpp/src/DoublePort.lf +++ b/test/Cpp/src/DoublePort.lf @@ -1,60 +1,59 @@ /** - * Test the case where two upstream reactors pass messages to a downstream - * reactor on two different ports. One message carries a microstep delay - * relative to the other. + * Test the case where two upstream reactors pass messages to a downstream reactor on two different + * ports. One message carries a microstep delay relative to the other. * * @author Maiko Brants */ target Cpp { - timeout: 900 msec, - fast: true + timeout: 900 msec, + fast: true } import Count from "lib/Count.lf" reactor CountMicrostep { - state count: int = 1 - output out: int - logical action act: int - timer t(0, 1 sec) + state count: int = 1 + output out: int + logical action act: int + timer t(0, 1 sec) - reaction(t) -> act {= - act.schedule( count); - count++; - =} + reaction(t) -> act {= + act.schedule( count); + count++; + =} - reaction(act) -> out {= out.set(act.get()); =} + reaction(act) -> out {= out.set(act.get()); =} } reactor Print { - input in: int - input in2: int - - reaction(in, in2) {= - if(in.is_present()){ - reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() - << "), received in = " << *in.get(); - } else if (in2.is_present()){ - reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() - << "), received in2 = " << *in2.get(); - } - - - if ( in.is_present() && in2.is_present()) { - reactor::log::Error() << "ERROR: invalid logical simultaneity."; - exit(1); - } - =} - - reaction(shutdown) {= - reactor::log::Info() << "SUCCESS: messages were at least one microstep apart."; - =} + input in: int + input in2: int + + reaction(in, in2) {= + if(in.is_present()){ + reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() + << "), received in = " << *in.get(); + } else if (in2.is_present()){ + reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() + << "), received in2 = " << *in2.get(); + } + + + if ( in.is_present() && in2.is_present()) { + reactor::log::Error() << "ERROR: invalid logical simultaneity."; + exit(1); + } + =} + + reaction(shutdown) {= + reactor::log::Info() << "SUCCESS: messages were at least one microstep apart."; + =} } main reactor DoublePort { - c = new Count() - cm = new CountMicrostep() - p = new Print() - c.c -> p.in - cm.out -> p.in2 + c = new Count() + cm = new CountMicrostep() + p = new Print() + c.c -> p.in + cm.out -> p.in2 } diff --git a/test/Cpp/src/DoubleReaction.lf b/test/Cpp/src/DoubleReaction.lf index 1128d63f97..f8002be54d 100644 --- a/test/Cpp/src/DoubleReaction.lf +++ b/test/Cpp/src/DoubleReaction.lf @@ -1,48 +1,48 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target Cpp { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - count++; - y.set(count); - =} + reaction(t) -> y {= + count++; + y.set(count); + =} } reactor Destination { - input x: int - input w: int - state s: int = 2 + input x: int + input w: int + state s: int = 2 - reaction(x, w) {= - int sum = 0; - if (x.is_present()) { - sum += *x.get(); - } - if (w.is_present()) { - sum += *w.get(); - } - std::cout << "Sum of inputs is: " << sum << std::endl; - if (sum != s) { - std::cerr << "FAILURE: Expected sum to be " << s - << "but it was " << sum << std::endl; - exit(1); - } - s += 2; - =} + reaction(x, w) {= + int sum = 0; + if (x.is_present()) { + sum += *x.get(); + } + if (w.is_present()) { + sum += *w.get(); + } + std::cout << "Sum of inputs is: " << sum << std::endl; + if (sum != s) { + std::cerr << "FAILURE: Expected sum to be " << s + << "but it was " << sum << std::endl; + exit(1); + } + s += 2; + =} } main reactor DoubleReaction { - c1 = new Clock() - c2 = new Clock() - d = new Destination() - c1.y -> d.x - c2.y -> d.w + c1 = new Clock() + c2 = new Clock() + d = new Destination() + c1.y -> d.x + c2.y -> d.w } diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index 5db4818048..f55ffcfedd 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -1,26 +1,25 @@ -// Test that two simultaneous triggers don't cause a reaction to execute twice -// at the same tag. +// Test that two simultaneous triggers don't cause a reaction to execute twice at the same tag. target Cpp main reactor DoubleTrigger { - timer t1 - timer t2 - state s: int = 0 + timer t1 + timer t2 + state s: int = 0 - reaction(t1, t2) {= - s++; - if (s > 1) { - std::cout << "FAILURE: Reaction got triggered twice." << std::endl; - exit(1); - } - =} + reaction(t1, t2) {= + s++; + if (s > 1) { + std::cout << "FAILURE: Reaction got triggered twice." << std::endl; + exit(1); + } + =} - reaction(shutdown) {= - if (s == 1) { - std::cout << "SUCCESS" << std::endl; - } else { - std::cerr << "FAILURE: Reaction was never triggered." << std::endl; - exit(1); - } - =} + reaction(shutdown) {= + if (s == 1) { + std::cout << "SUCCESS" << std::endl; + } else { + std::cerr << "FAILURE: Reaction was never triggered." << std::endl; + exit(1); + } + =} } diff --git a/test/Cpp/src/FloatLiteral.lf b/test/Cpp/src/FloatLiteral.lf index 6ad95f9e55..4f57e36caa 100644 --- a/test/Cpp/src/FloatLiteral.lf +++ b/test/Cpp/src/FloatLiteral.lf @@ -1,20 +1,19 @@ target Cpp -// This test verifies that floating-point literals are handled correctly. -main reactor { - state N: double = 6.0221409e+23 - state charge: double = -1.6021766E-19 - state minus_epsilon: double = -.01e0 - state expected: double = .964853323188E5 +main reactor { // This test verifies that floating-point literals are handled correctly. + state N: double = 6.0221409e+23 + state charge: double = -1.6021766E-19 + state minus_epsilon: double = -.01e0 + state expected: double = .964853323188E5 - reaction(startup) {= - auto F = - N * charge; - if (std::abs(F - expected) < std::abs(minus_epsilon)) { - std::cout << "The Faraday constant is roughly " << F << ".\n"; - } else { - std::cerr << "ERROR: Expected " << expected - << " but computed " << F << ".\n"; - exit(1); - } - =} + reaction(startup) {= + auto F = - N * charge; + if (std::abs(F - expected) < std::abs(minus_epsilon)) { + std::cout << "The Faraday constant is roughly " << F << ".\n"; + } else { + std::cerr << "ERROR: Expected " << expected + << " but computed " << F << ".\n"; + exit(1); + } + =} } diff --git a/test/Cpp/src/Gain.lf b/test/Cpp/src/Gain.lf index 4b123cc992..1a5d6eeedd 100644 --- a/test/Cpp/src/Gain.lf +++ b/test/Cpp/src/Gain.lf @@ -2,30 +2,30 @@ target Cpp reactor Scale(scale: int = 2) { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(*x.get() * scale); =} + reaction(x) -> y {= y.set(*x.get() * scale); =} } reactor Test { - input x: int + input x: int - reaction(x) {= - auto value = *x.get(); - std::cout << "Received " << value << std::endl; - if (value != 2) { - std::cerr << "Expected 2!" << std::endl; - exit(1); - } - =} + reaction(x) {= + auto value = *x.get(); + std::cout << "Received " << value << std::endl; + if (value != 2) { + std::cerr << "Expected 2!" << std::endl; + exit(1); + } + =} } main reactor Gain { - g = new Scale() - t = new Test() - g.y -> t.x - timer tim + g = new Scale() + t = new Test() + g.y -> t.x + timer tim - reaction(tim) -> g.x {= g.x.set(1); =} + reaction(tim) -> g.x {= g.x.set(1); =} } diff --git a/test/Cpp/src/GetMicroStep.lf b/test/Cpp/src/GetMicroStep.lf index 8370a21403..5bec79df3c 100644 --- a/test/Cpp/src/GetMicroStep.lf +++ b/test/Cpp/src/GetMicroStep.lf @@ -2,28 +2,28 @@ target Cpp main reactor GetMicroStep { - state s: {= reactor::mstep_t =} = 1 + state s: {= reactor::mstep_t =} = 1 - logical action l + logical action l - reaction(startup) -> l {= l.schedule(reactor::Duration::zero()); =} + reaction(startup) -> l {= l.schedule(reactor::Duration::zero()); =} - reaction(l) -> l {= - auto microstep = get_microstep(); - if (microstep != s) { - std::cerr << "Error: expected microstep " << s << ", got " << microstep << "instead\n"; - exit(1); - } - if (s++ < 10) { - l.schedule(); - } - =} + reaction(l) -> l {= + auto microstep = get_microstep(); + if (microstep != s) { + std::cerr << "Error: expected microstep " << s << ", got " << microstep << "instead\n"; + exit(1); + } + if (s++ < 10) { + l.schedule(); + } + =} - reaction(shutdown) {= - if (s != 11) { - std::cerr << "Error: unexpected state!\n"; - exit(2); - } - std::cout << "Success!\n"; - =} + reaction(shutdown) {= + if (s != 11) { + std::cerr << "Error: unexpected state!\n"; + exit(2); + } + std::cout << "Success!\n"; + =} } diff --git a/test/Cpp/src/Hello.lf b/test/Cpp/src/Hello.lf index f74acf6688..0bf2f029da 100644 --- a/test/Cpp/src/Hello.lf +++ b/test/Cpp/src/Hello.lf @@ -1,56 +1,46 @@ -// This test checks that logical time is incremented an appropriate amount as a -// result of an invocation of the schedule() function at runtime. It also -// performs various smoke tests of timing aligned reactions. The first instance -// has a period of 4 seconds, the second of 2 seconds, and the third (composite) -// or 1 second. +// This test checks that logical time is incremented an appropriate amount as a result of an +// invocation of the schedule() function at runtime. It also performs various smoke tests of timing +// aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, and the +// third (composite) or 1 second. target Cpp { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } -reactor HelloCpp( - period: time = 2 sec, - message: {= std::string =} = "Hello C++" -) { - state count: int = 0 - state previous_time: {= reactor::TimePoint =} - timer t(1 sec, period) - logical action a: void +reactor HelloCpp(period: time = 2 sec, message: {= std::string =} = "Hello C++") { + state count: int = 0 + state previous_time: {= reactor::TimePoint =} + timer t(1 sec, period) + logical action a: void - reaction(t) -> a {= - std::cout << message << std::endl; - a.schedule(200ms); // No payload. - // Print the current time. - previous_time = get_logical_time(); - std::cout << "Current time is " << previous_time << std::endl; - =} + reaction(t) -> a {= + std::cout << message << std::endl; + a.schedule(200ms); // No payload. + // Print the current time. + previous_time = get_logical_time(); + std::cout << "Current time is " << previous_time << std::endl; + =} - reaction(a) {= - count++; - auto time = get_logical_time(); - std::cout << "***** action " << count << " at time " - << time << std::endl; - auto diff = time - previous_time; - if (diff != 200ms) { - std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " - << "but got " << diff << std::endl; - exit(1); - } - =} + reaction(a) {= + count++; + auto time = get_logical_time(); + std::cout << "***** action " << count << " at time " + << time << std::endl; + auto diff = time - previous_time; + if (diff != 200ms) { + std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " + << "but got " << diff << std::endl; + exit(1); + } + =} } -reactor Inside( - period: time = 1 sec, - message: std::string = "Composite default message." -) { - third_instance = new HelloCpp(period = period, message = message) +reactor Inside(period: time = 1 sec, message: std::string = "Composite default message.") { + third_instance = new HelloCpp(period = period, message = message) } main reactor Hello { - first_instance = new HelloCpp( - period = 4 sec, - message = "Hello from first_instance." - ) - second_instance = new HelloCpp(message = "Hello from second_instance.") - composite_instance = new Inside(message = "Hello from composite_instance.") + first_instance = new HelloCpp(period = 4 sec, message = "Hello from first_instance.") + second_instance = new HelloCpp(message = "Hello from second_instance.") + composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/Cpp/src/Hierarchy2.lf b/test/Cpp/src/Hierarchy2.lf index db81bf4971..478c82db97 100644 --- a/test/Cpp/src/Hierarchy2.lf +++ b/test/Cpp/src/Hierarchy2.lf @@ -1,69 +1,69 @@ // Test data transport across hierarchy. target Cpp { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out: int - timer t(0, 1 sec) + output out: int + timer t(0, 1 sec) - reaction(t) -> out {= out.set(1); =} + reaction(t) -> out {= out.set(1); =} } reactor Count { - output out: int - timer t(0, 1 sec) - state i: int = 0 + output out: int + timer t(0, 1 sec) + state i: int = 0 - reaction(t) -> out {= - i++; - out.set(i); - =} + reaction(t) -> out {= + i++; + out.set(i); + =} } reactor Add { - input in1: int - input in2: int - output out: int + input in1: int + input in2: int + output out: int - reaction(in1, in2) -> out {= - int result = 0; - if (in1.is_present()) result += *in1.get(); - if (in2.is_present()) result += *in2.get(); - out.set(result); - =} + reaction(in1, in2) -> out {= + int result = 0; + if (in1.is_present()) result += *in1.get(); + if (in2.is_present()) result += *in2.get(); + out.set(result); + =} } reactor Print { - input in: int - state expected: int = 2 + input in: int + state expected: int = 2 - reaction(in) {= - auto value = *in.get(); - std::cout << "Received: " << value << std::endl; - if (value != expected) { - std::cerr << "Expected " << expected << std::endl; - exit(1); - } - expected++; - =} + reaction(in) {= + auto value = *in.get(); + std::cout << "Received: " << value << std::endl; + if (value != expected) { + std::cerr << "Expected " << expected << std::endl; + exit(1); + } + expected++; + =} } reactor AddCount { - input in: int - output out: int - count = new Count() - add = new Add() - in -> add.in1 - count.out -> add.in2 - add.out -> out + input in: int + output out: int + count = new Count() + add = new Add() + in -> add.in1 + count.out -> add.in2 + add.out -> out } main reactor Hierarchy2 { - source = new Source() - addCount = new AddCount() - print = new Print() - source.out -> addCount.in - addCount.out -> print.in + source = new Source() + addCount = new AddCount() + print = new Print() + source.out -> addCount.in + addCount.out -> print.in } diff --git a/test/Cpp/src/ImportComposition.lf b/test/Cpp/src/ImportComposition.lf index 0559edacd1..88dfdff0a9 100644 --- a/test/Cpp/src/ImportComposition.lf +++ b/test/Cpp/src/ImportComposition.lf @@ -1,8 +1,7 @@ /** * @author Maiko Brants TU Dresden * - * This tests the ability to import a reactor definition that itself imports a - * reactor definition. + * This tests the ability to import a reactor definition that itself imports a reactor definition. * * modeled after the C version of this test */ @@ -11,33 +10,33 @@ target Cpp import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { - public preamble {= - #include "reactor-cpp/logging.hh" - =} + public preamble {= + #include "reactor-cpp/logging.hh" + =} - imp_comp = new ImportedComposition() - state received: bool = false + imp_comp = new ImportedComposition() + state received: bool = false - reaction(startup) -> imp_comp.x {= imp_comp.x.set(42); =} + reaction(startup) -> imp_comp.x {= imp_comp.x.set(42); =} - reaction(imp_comp.y) {= - auto receive_time = get_elapsed_logical_time(); - reactor::log::Info() << "Received " << *imp_comp.y.get() << " at time " << receive_time; - received = true; - if(receive_time != 55ms) { - reactor::log::Error() << "ERROR: Received time should have been: 55,000,000."; - exit(1); - } - if(*imp_comp.y.get() != 42*2*2) { - reactor::log::Error() << "ERROR: Received value should have been: " << 42*2*2 << "."; - exit(2); - } - =} + reaction(imp_comp.y) {= + auto receive_time = get_elapsed_logical_time(); + reactor::log::Info() << "Received " << *imp_comp.y.get() << " at time " << receive_time; + received = true; + if(receive_time != 55ms) { + reactor::log::Error() << "ERROR: Received time should have been: 55,000,000."; + exit(1); + } + if(*imp_comp.y.get() != 42*2*2) { + reactor::log::Error() << "ERROR: Received value should have been: " << 42*2*2 << "."; + exit(2); + } + =} - reaction(shutdown) {= - if(!received){ - reactor::log::Error() << "ERROR: Nothing received."; - exit(3); - } - =} + reaction(shutdown) {= + if(!received){ + reactor::log::Error() << "ERROR: Nothing received."; + exit(3); + } + =} } diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index 3c55bdcaf1..f3b8991136 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -1,44 +1,42 @@ target Cpp -// That's the stuff that shall be generated for the after -reactor GeneratedDelay { - input y_in: int - output y_out: int - state y_state: int = 0 +reactor GeneratedDelay { // That's the stuff that shall be generated for the after + input y_in: int + output y_out: int + state y_state: int = 0 - logical action act(100 msec): int + logical action act(100 msec): int - reaction(y_in) -> act {= act.schedule(y_in.get()); =} + reaction(y_in) -> act {= act.schedule(y_in.get()); =} - reaction(act) -> y_out {= y_out.set(act.get()); =} + reaction(act) -> y_out {= y_out.set(act.get()); =} } reactor Source { - output out: int - timer t + output out: int + timer t - // reaction(t) -> out after 100 msec {= - reaction(t) -> out {= out.set(1); =} + reaction(t) -> out {= out.set(1); =} // reaction(t) -> out after 100 msec {= } reactor Sink { - input in: int - - reaction(in) {= - auto elapsed_logical = get_elapsed_logical_time(); - std::cout << "Elapsed logical time: " << elapsed_logical << '\n'; - if (elapsed_logical != 100ms) { - std::cerr << "ERROR: Expected 100 ms\n"; - exit(1); - } - =} + input in: int + + reaction(in) {= + auto elapsed_logical = get_elapsed_logical_time(); + std::cout << "Elapsed logical time: " << elapsed_logical << '\n'; + if (elapsed_logical != 100ms) { + std::cerr << "ERROR: Expected 100 ms\n"; + exit(1); + } + =} } main reactor ManualDelayedReaction { - source = new Source() - sink = new Sink() - g = new GeneratedDelay() + source = new Source() + sink = new Sink() + g = new GeneratedDelay() - source.out -> g.y_in // source.out -> sink.in; rewritten above - g.y_out -> sink.in + source.out -> g.y_in // source.out -> sink.in; rewritten above + g.y_out -> sink.in } diff --git a/test/Cpp/src/Methods.lf b/test/Cpp/src/Methods.lf index ff94460b62..6b60012640 100644 --- a/test/Cpp/src/Methods.lf +++ b/test/Cpp/src/Methods.lf @@ -1,24 +1,24 @@ target Cpp main reactor { - state foo: int = 2 + state foo: int = 2 - const method getFoo(): int {= return foo; =} + const method getFoo(): int {= return foo; =} - method add(x: int) {= foo += x; =} + method add(x: int) {= foo += x; =} - reaction(startup) {= - std::cout << "Foo is initialized to " << getFoo() << '\n'; - if (getFoo() != 2) { - std::cerr << "Error: expected 2!\n"; - exit(1); - } + reaction(startup) {= + std::cout << "Foo is initialized to " << getFoo() << '\n'; + if (getFoo() != 2) { + std::cerr << "Error: expected 2!\n"; + exit(1); + } - add(40); - std::cout << "2 + 40 = " << getFoo() << '\n'; - if (getFoo() != 42) { - std::cerr << "Error: expected 42!\n"; - exit(2); - } - =} + add(40); + std::cout << "2 + 40 = " << getFoo() << '\n'; + if (getFoo() != 42) { + std::cerr << "Error: expected 42!\n"; + exit(2); + } + =} } diff --git a/test/Cpp/src/MovingAverage.lf b/test/Cpp/src/MovingAverage.lf index af202ca0a0..817c80c920 100644 --- a/test/Cpp/src/MovingAverage.lf +++ b/test/Cpp/src/MovingAverage.lf @@ -1,73 +1,73 @@ -// Demonstration of a state variable that is a fixed size list. The -// MovingAverage reactor computes the moving average of the last four inputs and -// produces that as output. The source is a counting sequence. +// Demonstration of a state variable that is a fixed size list. The MovingAverage reactor computes +// the moving average of the last four inputs and produces that as output. The source is a counting +// sequence. target Cpp { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source { - output out: double - state count: int = 0 - timer clock(0, 200 msec) + output out: double + state count: int = 0 + timer clock(0, 200 msec) - reaction(clock) -> out {= - out.set(count); - count++; - =} + reaction(clock) -> out {= + out.set(count); + count++; + =} } reactor MovingAverageImpl { - state delay_line: double[3]{0.0, 0.0, 0.0} - state index: int = 0 - input in: double - output out: double + state delay_line: double[3]{0.0, 0.0, 0.0} + state index: int = 0 + input in: double + output out: double - reaction(in) -> out {= - // Calculate the output. - double sum = *in.get(); - for (int i = 0; i < 3; i++) { - sum += delay_line[i]; - } - out.set(sum/4.0); + reaction(in) -> out {= + // Calculate the output. + double sum = *in.get(); + for (int i = 0; i < 3; i++) { + sum += delay_line[i]; + } + out.set(sum/4.0); - // Insert the input in the delay line. - delay_line[index] = *in.get(); + // Insert the input in the delay line. + delay_line[index] = *in.get(); - // Update the index for the next input. - index++; - if (index >= 3) { - index = 0; - } - =} + // Update the index for the next input. + index++; + if (index >= 3) { + index = 0; + } + =} } reactor Print { - input in: double - state count: int = 0 + input in: double + state count: int = 0 - reaction(in) {= - std::cout << "Received: " << *in.get() << '\n'; - constexpr double expected[6] = {0.0, 0.25, 0.75, 1.5, 2.5, 3.5}; - if (*in.get() != expected[count]) { - std::cerr << "ERROR: Expected " << expected[count] << '\n'; - exit(1); - } - count++; - =} + reaction(in) {= + std::cout << "Received: " << *in.get() << '\n'; + constexpr double expected[6] = {0.0, 0.25, 0.75, 1.5, 2.5, 3.5}; + if (*in.get() != expected[count]) { + std::cerr << "ERROR: Expected " << expected[count] << '\n'; + exit(1); + } + count++; + =} - reaction(shutdown) {= - if(count != 6) { - std::cerr << "ERROR: Expected 6 values but got " << count << '\n'; - exit(2); - } - =} + reaction(shutdown) {= + if(count != 6) { + std::cerr << "ERROR: Expected 6 values but got " << count << '\n'; + exit(2); + } + =} } main reactor MovingAverage { - s = new Source() - m = new MovingAverageImpl() - p = new Print() - s.out -> m.in - m.out -> p.in + s = new Source() + m = new MovingAverageImpl() + p = new Print() + s.out -> m.in + m.out -> p.in } diff --git a/test/Cpp/src/NativeListsAndTimes.lf b/test/Cpp/src/NativeListsAndTimes.lf index f9ddfa4bd7..59d0101087 100644 --- a/test/Cpp/src/NativeListsAndTimes.lf +++ b/test/Cpp/src/NativeListsAndTimes.lf @@ -1,34 +1,33 @@ target Cpp -// This test passes if it is successfully compiled into valid target code. -reactor Foo( - x: int = 0, - y: time = 0, // Units are missing but not required - z = 1 msec, // Type is missing but not required - p: int[]{1, 2, 3, 4}, // List of integers - q: {= std::vector =}{1 msec, 2 msec, 3 msec}, - g: time[]{1 msec, 2 msec}, // List of time values - g2: int[] = {} +reactor Foo( // This test passes if it is successfully compiled into valid target code. + x: int = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required + p: int[]{1, 2, 3, 4}, // List of integers + q: {= std::vector =}{1 msec, 2 msec, 3 msec}, + g: time[]{1 msec, 2 msec}, // List of time values + g2: int[] = {} ) { - state s: time = y // Reference to explicitly typed time parameter - state t: time = z // Reference to implicitly typed time parameter - state v: bool // Uninitialized boolean state variable - state w: time // Uninitialized time state variable - timer tick(0) // Units missing but not required - timer tock(1 sec) // Implicit type time - timer toe(z) // Implicit type time - state baz = p // Implicit type int[] - state period = z // Implicit type time - state times: std::vector< // a list of lists - std::vector<{= reactor::Duration =}> - >{q, g} - state empty_list: int[] = {} + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter + state v: bool // Uninitialized boolean state variable + state w: time // Uninitialized time state variable + timer tick(0) // Units missing but not required + timer tock(1 sec) // Implicit type time + timer toe(z) // Implicit type time + state baz = p // Implicit type int[] + state period = z // Implicit type time + state times: std::vector< // a list of lists + std::vector<{= reactor::Duration =}> + >{q, g} + state empty_list: int[] = {} - reaction(tick) {= - // Target code - =} + reaction(tick) {= + // Target code + =} } main reactor NativeListsAndTimes { - foo = new Foo() + foo = new Foo() } diff --git a/test/Cpp/src/NestedTriggeredReactions.lf b/test/Cpp/src/NestedTriggeredReactions.lf index 783dcefc7e..22ea978545 100644 --- a/test/Cpp/src/NestedTriggeredReactions.lf +++ b/test/Cpp/src/NestedTriggeredReactions.lf @@ -1,41 +1,41 @@ target Cpp reactor Container { - input in: void + input in: void - state triggered: bool = false + state triggered: bool = false - contained = new Contained() + contained = new Contained() - in -> contained.in + in -> contained.in - reaction(in) {= triggered = true; =} + reaction(in) {= triggered = true; =} - reaction(shutdown) {= - if (!triggered) { - reactor::log::Error() << "The Container reaction was not triggered!"; - exit(1); - } - =} + reaction(shutdown) {= + if (!triggered) { + reactor::log::Error() << "The Container reaction was not triggered!"; + exit(1); + } + =} } reactor Contained { - input in: void + input in: void - state triggered: bool = false + state triggered: bool = false - reaction(in) {= triggered = true; =} + reaction(in) {= triggered = true; =} - reaction(shutdown) {= - if (!triggered) { - reactor::log::Error() << "The Contained reaction was not triggered!"; - exit(1); - } - =} + reaction(shutdown) {= + if (!triggered) { + reactor::log::Error() << "The Contained reaction was not triggered!"; + exit(1); + } + =} } main reactor { - container = new Container() + container = new Container() - reaction(startup) -> container.in {= container.in.set(); =} + reaction(startup) -> container.in {= container.in.set(); =} } diff --git a/test/Cpp/src/ParameterHierarchy.lf b/test/Cpp/src/ParameterHierarchy.lf index c183cbca03..dcef563d68 100644 --- a/test/Cpp/src/ParameterHierarchy.lf +++ b/test/Cpp/src/ParameterHierarchy.lf @@ -8,25 +8,24 @@ target Cpp reactor Deep(p: int = 0) { - reaction(startup) {= - if(p != 42) { - reactor::log::Error() << "Parameter value is: " << p << ". Should have been 42."; - exit(1); - } else { - reactor::log::Info() << "Success."; - } - =} + reaction(startup) {= + if(p != 42) { + reactor::log::Error() << "Parameter value is: " << p << ". Should have been 42."; + exit(1); + } else { + reactor::log::Info() << "Success."; + } + =} } reactor Intermediate(p: int = 10) { - a = new Deep(p = p) + a = new Deep(p = p) } reactor Another(p: int = 20) { - // also test forwarding parameters via target code blocks - a = new Intermediate(p = {= p =}) + a = new Intermediate(p = {= p =}) // also test forwarding parameters via target code blocks } main reactor ParameterHierarchy { - a = new Intermediate(p = 42) + a = new Intermediate(p = 42) } diff --git a/test/Cpp/src/ParameterizedState.lf b/test/Cpp/src/ParameterizedState.lf index 1c39043a75..9bea16475f 100644 --- a/test/Cpp/src/ParameterizedState.lf +++ b/test/Cpp/src/ParameterizedState.lf @@ -1,16 +1,16 @@ target Cpp reactor Foo(bar: int = 4) { - state baz = bar + state baz = bar - reaction(startup) {= - std::cout << "Baz: " << baz << std::endl; - if (baz != 42) { - exit(1); - } - =} + reaction(startup) {= + std::cout << "Baz: " << baz << std::endl; + if (baz != 42) { + exit(1); + } + =} } main reactor ParameterizedState { - a = new Foo(bar = 42) + a = new Foo(bar = 42) } diff --git a/test/Cpp/src/ParametersOutOfOrder.lf b/test/Cpp/src/ParametersOutOfOrder.lf index 7ef28b914a..4fa2a933ba 100644 --- a/test/Cpp/src/ParametersOutOfOrder.lf +++ b/test/Cpp/src/ParametersOutOfOrder.lf @@ -1,16 +1,16 @@ -// This is a smoke test to see if parameters can be initiailized out of -// definition order. Compilation without errors is success. +// This is a smoke test to see if parameters can be initiailized out of definition order. +// Compilation without errors is success. target Cpp reactor Foo(a: int = 0, b: std::string = "", c: float = 0.0) { - reaction(startup) {= - if (a != 42 || b != "bar" || c < 3.1) { - reactor::log::Error() << "received an unexpected parameter!"; - exit(1); - } - =} + reaction(startup) {= + if (a != 42 || b != "bar" || c < 3.1) { + reactor::log::Error() << "received an unexpected parameter!"; + exit(1); + } + =} } main reactor { - foo = new Foo(c = 3.14, b = "bar", a = 42) + foo = new Foo(c = 3.14, b = "bar", a = 42) } diff --git a/test/Cpp/src/PeriodicDesugared.lf b/test/Cpp/src/PeriodicDesugared.lf index 2823835687..23d815b46d 100644 --- a/test/Cpp/src/PeriodicDesugared.lf +++ b/test/Cpp/src/PeriodicDesugared.lf @@ -1,29 +1,29 @@ target Cpp { - fast: true, - timeout: 5 secs + fast: true, + timeout: 5 secs } main reactor(offset: time = 50 msec, period: time = 500 msec) { - logical action init(offset): void - logical action recur(period): void - state expected = offset + logical action init(offset): void + logical action recur(period): void + state expected = offset - reaction(startup) -> init {= - std::cout << "Hello from Periodic!\n"; - init.schedule(); - =} + reaction(startup) -> init {= + std::cout << "Hello from Periodic!\n"; + init.schedule(); + =} - reaction(init) -> recur {= recur.schedule(); =} + reaction(init) -> recur {= recur.schedule(); =} - reaction(init, recur) -> recur {= - std::cout << "Periodic trigger!\n"; - auto logical_time = get_elapsed_logical_time(); - std::cout << "Elapsed logical time: " << logical_time << '\n'; - if (logical_time != expected) { - std::cerr << "ERROR: expected " << expected << '\n'; - exit(1); - } - expected += period; - recur.schedule(); - =} + reaction(init, recur) -> recur {= + std::cout << "Periodic trigger!\n"; + auto logical_time = get_elapsed_logical_time(); + std::cout << "Elapsed logical time: " << logical_time << '\n'; + if (logical_time != expected) { + std::cerr << "ERROR: expected " << expected << '\n'; + exit(1); + } + expected += period; + recur.schedule(); + =} } diff --git a/test/Cpp/src/PhysicalConnection.lf b/test/Cpp/src/PhysicalConnection.lf index a3b6b864c7..c42b827765 100644 --- a/test/Cpp/src/PhysicalConnection.lf +++ b/test/Cpp/src/PhysicalConnection.lf @@ -2,37 +2,37 @@ target Cpp reactor Source { - output out: int + output out: int - reaction(startup) -> out {= out.set(42); =} + reaction(startup) -> out {= out.set(42); =} } reactor Destination { - input in: int - - state received: bool(false) - - reaction(in) {= - auto time = get_elapsed_logical_time(); - reactor::log::Info() << "Received " << *in.get() << " at logical time " << time; - if (time == reactor::Duration::zero()) { - reactor::log::Error() << "Logical time should have been greater than zero."; - exit(1); - } - - received = true; - =} - - reaction(shutdown) {= - if (!received) { - reactor::log::Error() << "Nothing received."; - exit(2); - } - =} + input in: int + + state received: bool(false) + + reaction(in) {= + auto time = get_elapsed_logical_time(); + reactor::log::Info() << "Received " << *in.get() << " at logical time " << time; + if (time == reactor::Duration::zero()) { + reactor::log::Error() << "Logical time should have been greater than zero."; + exit(1); + } + + received = true; + =} + + reaction(shutdown) {= + if (!received) { + reactor::log::Error() << "Nothing received."; + exit(2); + } + =} } main reactor { - source = new Source() - destination = new Destination() - source.out ~> destination.in + source = new Source() + destination = new Destination() + source.out ~> destination.in } diff --git a/test/Cpp/src/Pipeline.lf b/test/Cpp/src/Pipeline.lf index cc86ef67a0..49cc4dd212 100644 --- a/test/Cpp/src/Pipeline.lf +++ b/test/Cpp/src/Pipeline.lf @@ -1,44 +1,44 @@ target Cpp { - timeout: 2 sec + timeout: 2 sec } import Computation from "concurrent/Threaded.lf" reactor Print { - input in: int - state count: int = 0 - - reaction(in) {= - std::cout << "Received: " << *in.get() << '\n'; - if (*in.get() != count) { - std::cerr << "ERROR: Expected " << count << '\n'; - exit(1); - } - count++; - =} - - reaction(shutdown) {= - if (count == 1) { - std::cerr << "ERROR: Final reactor received no data.\n"; - exit(3); - } - =} + input in: int + state count: int = 0 + + reaction(in) {= + std::cout << "Received: " << *in.get() << '\n'; + if (*in.get() != count) { + std::cerr << "ERROR: Expected " << count << '\n'; + exit(1); + } + count++; + =} + + reaction(shutdown) {= + if (count == 1) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} } main reactor Pipeline { - timer t(0, 200 msec) - state count: int = 0 + timer t(0, 200 msec) + state count: int = 0 - c1 = new Computation() - c2 = new Computation() - c3 = new Computation() - c4 = new Computation() - p = new Print() + c1 = new Computation() + c2 = new Computation() + c3 = new Computation() + c4 = new Computation() + p = new Print() - c1.out -> c2.in after 200 msec - c2.out -> c3.in after 200 msec - c3.out -> c4.in after 200 msec - c4.out -> p.in + c1.out -> c2.in after 200 msec + c2.out -> c3.in after 200 msec + c3.out -> c4.in after 200 msec + c4.out -> p.in - reaction(t) -> c1.in {= c1.in.set(count++); =} + reaction(t) -> c1.in {= c1.in.set(count++); =} } diff --git a/test/Cpp/src/ReadOutputOfContainedReactor.lf b/test/Cpp/src/ReadOutputOfContainedReactor.lf index c7e85083b4..4e0f17f46e 100644 --- a/test/Cpp/src/ReadOutputOfContainedReactor.lf +++ b/test/Cpp/src/ReadOutputOfContainedReactor.lf @@ -1,52 +1,51 @@ -// Test reacting to and reading outputs from a contained reactor in various -// permutations. +// Test reacting to and reading outputs from a contained reactor in various permutations. target Cpp reactor Contained { - output out: int + output out: int - reaction(startup) -> out {= out.set(42); =} + reaction(startup) -> out {= out.set(42); =} } main reactor ReadOutputOfContainedReactor { - c = new Contained() - state count: int = 0 + c = new Contained() + state count: int = 0 - reaction(startup) c.out {= - std::cout << "Startup reaction reading output of contained " - << "reactor: " << *c.out.get() << std::endl; - if (*c.out.get() != 42) { - std::cout << "FAILURE: expected 42" << std::endl; - exit(2); - } - count++; - =} + reaction(startup) c.out {= + std::cout << "Startup reaction reading output of contained " + << "reactor: " << *c.out.get() << std::endl; + if (*c.out.get() != 42) { + std::cout << "FAILURE: expected 42" << std::endl; + exit(2); + } + count++; + =} - reaction(c.out) {= - std::cout << "Reading output of contained reactor: " << *c.out.get() - << std::endl; - if (*c.out.get() != 42) { - std::cout << "FAILURE: expected 42" << std::endl; - exit(2); - } - count++; - =} + reaction(c.out) {= + std::cout << "Reading output of contained reactor: " << *c.out.get() + << std::endl; + if (*c.out.get() != 42) { + std::cout << "FAILURE: expected 42" << std::endl; + exit(2); + } + count++; + =} - reaction(startup, c.out) {= - std::cout << "Alternate triggering reading output of contained " - << "reactor: " << *c.out.get() << std::endl; - if (*c.out.get() != 42) { - std::cout << "FAILURE: expected 42" << std::endl; - exit(2); - } - count++; - =} + reaction(startup, c.out) {= + std::cout << "Alternate triggering reading output of contained " + << "reactor: " << *c.out.get() << std::endl; + if (*c.out.get() != 42) { + std::cout << "FAILURE: expected 42" << std::endl; + exit(2); + } + count++; + =} - reaction(shutdown) {= - if (count != 3) { - std::cerr << "ERROR: One of the reactions failed to trigger." - << std::endl; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 3) { + std::cerr << "ERROR: One of the reactions failed to trigger." + << std::endl; + exit(1); + } + =} } diff --git a/test/Cpp/src/ScheduleLogicalAction.lf b/test/Cpp/src/ScheduleLogicalAction.lf index 96fd5382b7..a64eac9fe7 100644 --- a/test/Cpp/src/ScheduleLogicalAction.lf +++ b/test/Cpp/src/ScheduleLogicalAction.lf @@ -1,52 +1,52 @@ /** * @author Maiko Brants TU Dresden * - * This checks that a logical action is scheduled the specified logical time - * after the current logical time. + * This checks that a logical action is scheduled the specified logical time after the current + * logical time. * * Modeled after the C version of this test. */ target Cpp { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x: int - output y: int - logical action a: void + input x: int + output y: int + logical action a: void - reaction(x) -> y, a {= - y.set( 2*(*x.get())); - // The following uses physical time, incorrectly. - a.schedule(500ms); - =} + reaction(x) -> y, a {= + y.set( 2*(*x.get())); + // The following uses physical time, incorrectly. + a.schedule(500ms); + =} - reaction(a) -> y {= y.set(-42); =} + reaction(a) -> y {= y.set(-42); =} } reactor print { - state expected_time: time = 0 - input x: int + state expected_time: time = 0 + input x: int - reaction(x) {= - auto elapsed_time = get_elapsed_logical_time(); - reactor::log::Info() << "Result is " << *x.get(); - reactor::log::Info() << "Current logical time is: " << elapsed_time; - reactor::log::Info() << "Current physical time is: " << get_elapsed_physical_time().count(); - if(elapsed_time != expected_time) { - reactor::log::Error() << "ERROR: Expected logical time to be " << expected_time; - exit(1); - } - expected_time += 500ms; - =} + reaction(x) {= + auto elapsed_time = get_elapsed_logical_time(); + reactor::log::Info() << "Result is " << *x.get(); + reactor::log::Info() << "Current logical time is: " << elapsed_time; + reactor::log::Info() << "Current physical time is: " << get_elapsed_physical_time().count(); + if(elapsed_time != expected_time) { + reactor::log::Error() << "ERROR: Expected logical time to be " << expected_time; + exit(1); + } + expected_time += 500ms; + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x - reaction(t) -> f.x {= f.x.set(42); =} + reaction(t) -> f.x {= f.x.set(42); =} } diff --git a/test/Cpp/src/SelfLoop.lf b/test/Cpp/src/SelfLoop.lf index 2be47e3d4e..8d3188e937 100644 --- a/test/Cpp/src/SelfLoop.lf +++ b/test/Cpp/src/SelfLoop.lf @@ -4,42 +4,42 @@ * Modeled after the C version of this test. */ target Cpp { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Self { - input x: int - output y: int - logical action a: int - state expected: int = 43 + input x: int + output y: int + logical action a: int + state expected: int = 43 - reaction(a) -> y {= - reactor::log::Info() << "a = " << *a.get(); - y.set(*a.get()+1); - =} + reaction(a) -> y {= + reactor::log::Info() << "a = " << *a.get(); + y.set(*a.get()+1); + =} - reaction(x) -> a {= - reactor::log::Info() << "x = " << *x.get(); - if(*x.get() != expected){ - reactor::log::Error() << "Expected " << expected; - exit(1); - } - expected++; - a.schedule(x.get(), 100ms); - =} + reaction(x) -> a {= + reactor::log::Info() << "x = " << *x.get(); + if(*x.get() != expected){ + reactor::log::Error() << "Expected " << expected; + exit(1); + } + expected++; + a.schedule(x.get(), 100ms); + =} - reaction(startup) -> a {= a.schedule(42, 0ns); =} + reaction(startup) -> a {= a.schedule(42, 0ns); =} - reaction(shutdown) {= - if(expected <= 43) { - reactor::log::Error() << "Received no data."; - exit(2); - } - =} + reaction(shutdown) {= + if(expected <= 43) { + reactor::log::Error() << "Received no data."; + exit(2); + } + =} } main reactor SelfLoop { - u = new Self() - u.y -> u.x + u = new Self() + u.y -> u.x } diff --git a/test/Cpp/src/SendingInside.lf b/test/Cpp/src/SendingInside.lf index 2f73122bc8..42d15f2f68 100644 --- a/test/Cpp/src/SendingInside.lf +++ b/test/Cpp/src/SendingInside.lf @@ -1,31 +1,31 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target Cpp { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Printer { - input x: int - state count: int = 1 + input x: int + state count: int = 1 - reaction(x) {= - std::cout << "Inside reactor received: " << *x.get() << std::endl; - if (*x.get() != count) { - std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); - } - count++; - =} + reaction(x) {= + std::cout << "Inside reactor received: " << *x.get() << std::endl; + if (*x.get() != count) { + std::cerr << "FAILURE: Expected " << count << std::endl; + exit(1); + } + count++; + =} } main reactor SendingInside { - state count: int = 0 - timer t(0, 1 sec) - p = new Printer() + state count: int = 0 + timer t(0, 1 sec) + p = new Printer() - reaction(t) -> p.x {= - count++; - p.x.set(count); - =} + reaction(t) -> p.x {= + count++; + p.x.set(count); + =} } diff --git a/test/Cpp/src/SimpleDeadline.lf b/test/Cpp/src/SimpleDeadline.lf index be10b55d43..57538f5e9f 100644 --- a/test/Cpp/src/SimpleDeadline.lf +++ b/test/Cpp/src/SimpleDeadline.lf @@ -1,42 +1,41 @@ -// Test local deadline, where a deadline is associated with a reaction -// definition. This test triggers a reaction exactly once with a deadline -// violation. +// Test local deadline, where a deadline is associated with a reaction definition. This test +// triggers a reaction exactly once with a deadline violation. target Cpp reactor Deadline(threshold: time = 100 msec) { - private preamble {= - #include - =} - input x: int - output deadlineViolation: bool + private preamble {= + #include + =} + input x: int + output deadlineViolation: bool - reaction(x) -> deadlineViolation {= - std::cerr << "ERROR: Deadline violation was not detected!" << std::endl; - exit(1); - =} deadline(threshold) {= - std::cout << "Deadline violation detected." << std::endl; - deadlineViolation.set(true); - =} + reaction(x) -> deadlineViolation {= + std::cerr << "ERROR: Deadline violation was not detected!" << std::endl; + exit(1); + =} deadline(threshold) {= + std::cout << "Deadline violation detected." << std::endl; + deadlineViolation.set(true); + =} } reactor Print { - input in: bool + input in: bool - reaction(in) {= - if (*in.get()) { - std::cout << "Output successfully produced by deadline handler." - << std::endl; - } - =} + reaction(in) {= + if (*in.get()) { + std::cout << "Output successfully produced by deadline handler." + << std::endl; + } + =} } main reactor SimpleDeadline { - d = new Deadline(threshold = 10 msec) - p = new Print() - d.deadlineViolation -> p.in + d = new Deadline(threshold = 10 msec) + p = new Print() + d.deadlineViolation -> p.in - reaction(startup) -> d.x {= - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - d.x.set(42); - =} + reaction(startup) -> d.x {= + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + d.x.set(42); + =} } diff --git a/test/Cpp/src/SlowingClock.lf b/test/Cpp/src/SlowingClock.lf index adbe93e418..19d475ffe3 100644 --- a/test/Cpp/src/SlowingClock.lf +++ b/test/Cpp/src/SlowingClock.lf @@ -1,43 +1,42 @@ /** * @author Maiko Brants TU Dresden * - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a logical action with a minimum delay of 100 msec. The use of the - * logical action ensures the elapsed time jumps exactly from 0 to 100, 300, - * 600, and 1000 msec. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a logical + * action with a minimum delay of 100 msec. The use of the logical action ensures the elapsed time + * jumps exactly from 0 to 100, 300, 600, and 1000 msec. * * Modeled after the C version of this test. */ target Cpp { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } main reactor SlowingClock { - logical action a(100 msec) - state interval: time = 100 msec - state expected_time: time = 100 msec + logical action a(100 msec) + state interval: time = 100 msec + state expected_time: time = 100 msec - reaction(startup) -> a {= a.schedule(0ns); =} + reaction(startup) -> a {= a.schedule(0ns); =} - reaction(a) -> a {= - auto elapsed_logical_time = get_elapsed_logical_time(); - reactor::log::Info() << "Logical time since start: " << elapsed_logical_time; - if(elapsed_logical_time != expected_time) { - reactor::log::Error() << "Expected time to be: " << expected_time; - exit(1); - } - a.schedule(interval); - expected_time += 100ms + interval; - interval += 100ms; - =} + reaction(a) -> a {= + auto elapsed_logical_time = get_elapsed_logical_time(); + reactor::log::Info() << "Logical time since start: " << elapsed_logical_time; + if(elapsed_logical_time != expected_time) { + reactor::log::Error() << "Expected time to be: " << expected_time; + exit(1); + } + a.schedule(interval); + expected_time += 100ms + interval; + interval += 100ms; + =} - reaction(shutdown) {= - if(expected_time != 1500ms){ - reactor::log::Error() << "Expected the next expected time to be: 1500000000 nsec."; - reactor::log::Error() << "It was: " << expected_time; - } else { - reactor::log::Info() << "Test passes."; - } - =} + reaction(shutdown) {= + if(expected_time != 1500ms){ + reactor::log::Error() << "Expected the next expected time to be: 1500000000 nsec."; + reactor::log::Error() << "It was: " << expected_time; + } else { + reactor::log::Info() << "Test passes."; + } + =} } diff --git a/test/Cpp/src/SlowingClockPhysical.lf b/test/Cpp/src/SlowingClockPhysical.lf index 919f9d6cdf..2d5529f851 100644 --- a/test/Cpp/src/SlowingClockPhysical.lf +++ b/test/Cpp/src/SlowingClockPhysical.lf @@ -1,46 +1,45 @@ /** * @author Maiko Brants TU Dresden * - * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a physical action with a minimum delay of 100 msec. The use of the - * physical action makes the elapsed time jumps from 0 to approximately 100 - * msec, to approximatly 300 msec thereafter, drifting away further with each - * new event. + * Events are scheduled with increasing additional delays of 0, 100, 300, 600 msec on a physical + * action with a minimum delay of 100 msec. The use of the physical action makes the elapsed time + * jumps from 0 to approximately 100 msec, to approximatly 300 msec thereafter, drifting away + * further with each new event. * * Modeled after the C version of this test. */ target Cpp { - timeout: 1500 msec + timeout: 1500 msec } main reactor SlowingClockPhysical { - physical action a - state interval: time = 100 msec - state expected_time: time = 100 msec + physical action a + state interval: time = 100 msec + state expected_time: time = 100 msec - reaction(startup) -> a {= - expected_time=100ms; - a.schedule(100ms); - =} + reaction(startup) -> a {= + expected_time=100ms; + a.schedule(100ms); + =} - reaction(a) -> a {= - auto elapsed_logical_time{get_elapsed_logical_time()}; - reactor::log::Info() << "Logical time since start: " << elapsed_logical_time; - if(elapsed_logical_time < expected_time){ - reactor::log::Error() << "Expected logical time to be at least: " << expected_time; - exit(1); - } - interval += 100ms; - expected_time = 100ms + interval; - a.schedule(interval); - reactor::log::Info() << "Scheduling next to occur approximately after: " << interval; - =} + reaction(a) -> a {= + auto elapsed_logical_time{get_elapsed_logical_time()}; + reactor::log::Info() << "Logical time since start: " << elapsed_logical_time; + if(elapsed_logical_time < expected_time){ + reactor::log::Error() << "Expected logical time to be at least: " << expected_time; + exit(1); + } + interval += 100ms; + expected_time = 100ms + interval; + a.schedule(interval); + reactor::log::Info() << "Scheduling next to occur approximately after: " << interval; + =} - reaction(shutdown) {= - if(expected_time < 500ms){ - reactor::log::Error() << "Expected the next expected time to be at least: 500000000 nsec."; - reactor::log::Error() << "It was: " << expected_time; - exit(2); - } - =} + reaction(shutdown) {= + if(expected_time < 500ms){ + reactor::log::Error() << "Expected the next expected time to be at least: 500000000 nsec."; + reactor::log::Error() << "It was: " << expected_time; + exit(2); + } + =} } diff --git a/test/Cpp/src/Stride.lf b/test/Cpp/src/Stride.lf index 5f469e4c70..be44540bb4 100644 --- a/test/Cpp/src/Stride.lf +++ b/test/Cpp/src/Stride.lf @@ -1,29 +1,29 @@ -// This example illustrates state variables and parameters on the wiki. For this -// test, success is just compiling and running. +// This example illustrates state variables and parameters on the wiki. For this test, success is +// just compiling and running. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Count(stride: int = 1) { - state count: int = 0 - output y: int - timer t(0, 100 msec) + state count: int = 0 + output y: int + timer t(0, 100 msec) - reaction(t) -> y {= - y.set(count); - count += stride; - =} + reaction(t) -> y {= + y.set(count); + count += stride; + =} } reactor Display { - input x: int + input x: int - reaction(x) {= std::cout << "Received " << *x.get() << std::endl; =} + reaction(x) {= std::cout << "Received " << *x.get() << std::endl; =} } main reactor Stride { - c = new Count(stride = 2) - d = new Display() - c.y -> d.x + c = new Count(stride = 2) + d = new Display() + c.y -> d.x } diff --git a/test/Cpp/src/StructPrint.lf b/test/Cpp/src/StructPrint.lf index 4ee404b8bf..e59ef45dda 100644 --- a/test/Cpp/src/StructPrint.lf +++ b/test/Cpp/src/StructPrint.lf @@ -2,41 +2,38 @@ target Cpp public preamble {= - #include "include/hello.h" + #include "include/hello.h" =} reactor Source { - output out: Hello + output out: Hello - reaction(startup) -> out {= - // create an dynamically allocated mutable Hello object - auto hello = reactor::make_mutable_value(); - hello->name = "Earth"; - hello->value = 42; - // this implicitly converts the mutable value to an immutable value - out.set(std::move(hello)); - =} + reaction(startup) -> out {= + // create an dynamically allocated mutable Hello object + auto hello = reactor::make_mutable_value(); + hello->name = "Earth"; + hello->value = 42; + // this implicitly converts the mutable value to an immutable value + out.set(std::move(hello)); + =} } -reactor Print( - expected_value: int = 42, - expected_name: {= std::string =} = "Earth" -) { - input in: Hello +reactor Print(expected_value: int = 42, expected_name: {= std::string =} = "Earth") { + input in: Hello - reaction(in) {= - // get a reference to the received struct for convenience - auto& s = *in.get(); - std::cout << "Received: name = " << s.name << ", value = " << s.value << '\n'; - if (s.value != expected_value || s.name != expected_name) { - std::cerr << "ERROR: Expected name = " << expected_name << ", value = " << expected_value << '\n'; - exit(1); - } - =} + reaction(in) {= + // get a reference to the received struct for convenience + auto& s = *in.get(); + std::cout << "Received: name = " << s.name << ", value = " << s.value << '\n'; + if (s.value != expected_value || s.name != expected_name) { + std::cerr << "ERROR: Expected name = " << expected_name << ", value = " << expected_value << '\n'; + exit(1); + } + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p.in + s = new Source() + p = new Print() + s.out -> p.in } diff --git a/test/Cpp/src/StructScale.lf b/test/Cpp/src/StructScale.lf index 776dad14b1..de3bef6579 100644 --- a/test/Cpp/src/StructScale.lf +++ b/test/Cpp/src/StructScale.lf @@ -1,30 +1,29 @@ -// Source produces a dynamically allocated struct, which it passes to Scale. -// Scale requests a writable copy. It modifies it and passes it to Print. It -// gets freed after Print is done with it. +// Source produces a dynamically allocated struct, which it passes to Scale. Scale requests a +// writable copy. It modifies it and passes it to Print. It gets freed after Print is done with it. target Cpp import Source, Print from "StructPrint.lf" public preamble {= - #include "include/hello.h" + #include "include/hello.h" =} reactor Scale(scale: int = 2) { - input in: Hello + input in: Hello - output out: Hello + output out: Hello - reaction(in) -> out {= - auto hello = in.get().get_mutable_copy(); - hello->value *= scale; - out.set(std::move(hello)); - =} + reaction(in) -> out {= + auto hello = in.get().get_mutable_copy(); + hello->value *= scale; + out.set(std::move(hello)); + =} } main reactor StructScale { - s = new Source() - c = new Scale() - p = new Print(expected_value = 84) - s.out -> c.in - c.out -> p.in + s = new Source() + c = new Scale() + p = new Print(expected_value = 84) + s.out -> c.in + c.out -> p.in } diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index 8b33dcd967..a25ebdf07c 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -1,49 +1,48 @@ -// Test that the stop function can be used to internally to impose a a time -// limit. Correct output for this 1, 2, 3, 4. Failure for this test is failing -// to halt or getting the wrong data. +// Test that the stop function can be used to internally to impose a a time limit. Correct output +// for this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. target Cpp { - fast: true + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - count++; - //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; - y.set(count); - =} + reaction(t) -> y {= + count++; + //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; + y.set(count); + =} } reactor Destination { - input x: int - state s: int = 1 + input x: int + state s: int = 1 - reaction(x) {= - //std::cout << "Received " << *x.get() << '\n'; - if (*x.get() != s) { - std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; - exit(1); - } - s++; - =} + reaction(x) {= + //std::cout << "Received " << *x.get() << '\n'; + if (*x.get() != s) { + std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; + exit(1); + } + s++; + =} - reaction(shutdown) {= - std::cout << "**** shutdown reaction invoked.\n"; - if (s != 12) { - std::cerr << "ERROR: Expected 12 but got " << s << '\n'; - exit(1); - } - =} + reaction(shutdown) {= + std::cout << "**** shutdown reaction invoked.\n"; + if (s != 12) { + std::cerr << "ERROR: Expected 12 but got " << s << '\n'; + exit(1); + } + =} } main reactor TimeLimit(period: time = 1 sec) { - timer stop(10 sec) - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + timer stop(10 sec) + c = new Clock(period = period) + d = new Destination() + c.y -> d.x - reaction(stop) {= environment()->sync_shutdown(); =} + reaction(stop) {= environment()->sync_shutdown(); =} } diff --git a/test/Cpp/src/TimeState.lf b/test/Cpp/src/TimeState.lf index aefac79b1c..01f28e7f85 100644 --- a/test/Cpp/src/TimeState.lf +++ b/test/Cpp/src/TimeState.lf @@ -1,11 +1,11 @@ target Cpp reactor Foo(bar: time = 42 msec) { - state baz = bar + state baz = bar - reaction(startup) {= std::cout << "Baz: " << baz << std::endl; =} + reaction(startup) {= std::cout << "Baz: " << baz << std::endl; =} } main reactor { - a = new Foo() + a = new Foo() } diff --git a/test/Cpp/src/Timeout_Test.lf b/test/Cpp/src/Timeout_Test.lf index c3fe1ffbf9..95971d113a 100644 --- a/test/Cpp/src/Timeout_Test.lf +++ b/test/Cpp/src/Timeout_Test.lf @@ -6,39 +6,39 @@ * Modeled after the C version of this test. */ target Cpp { - timeout: 11 msec + timeout: 11 msec } import Sender from "lib/LoopedActionSender.lf" reactor Consumer { - input in: int - state success: bool = false + input in: int + state success: bool = false - reaction(in) {= - auto current{get_elapsed_logical_time()}; - if(current > 11ms ){ - reactor::log::Error() << "Received at: " << current.count() << ". Failed to enforce timeout."; - exit(1); - } else if(current == 11ms) { - success=true; - } - =} + reaction(in) {= + auto current{get_elapsed_logical_time()}; + if(current > 11ms ){ + reactor::log::Error() << "Received at: " << current.count() << ". Failed to enforce timeout."; + exit(1); + } else if(current == 11ms) { + success=true; + } + =} - reaction(shutdown) {= - reactor::log::Info() << "Shutdown invoked at " << get_elapsed_logical_time(); - if((get_elapsed_logical_time() == 11ms ) && (success == true)){ - reactor::log::Info() << "SUCCESS: successfully enforced timeout."; - } else { - reactor::log::Error() << "Shutdown invoked at: " << get_elapsed_logical_time() << ". Failed to enforce timeout."; - exit(1); - } - =} + reaction(shutdown) {= + reactor::log::Info() << "Shutdown invoked at " << get_elapsed_logical_time(); + if((get_elapsed_logical_time() == 11ms ) && (success == true)){ + reactor::log::Info() << "SUCCESS: successfully enforced timeout."; + } else { + reactor::log::Error() << "Shutdown invoked at: " << get_elapsed_logical_time() << ". Failed to enforce timeout."; + exit(1); + } + =} } main reactor Timeout_Test { - consumer = new Consumer() - producer = new Sender(take_a_break_after = 10, break_interval = 1 msec) + consumer = new Consumer() + producer = new Sender(take_a_break_after = 10, break_interval = 1 msec) - producer.out -> consumer.in + producer.out -> consumer.in } diff --git a/test/Cpp/src/TimerIsPresent.lf b/test/Cpp/src/TimerIsPresent.lf index 4745078dc5..b87b22281e 100644 --- a/test/Cpp/src/TimerIsPresent.lf +++ b/test/Cpp/src/TimerIsPresent.lf @@ -1,54 +1,54 @@ target Cpp { - timeout: 1 sec + timeout: 1 sec } main reactor { - timer t1(0, 50 msec) - timer t2(33 msec, 33 msec) - - reaction(startup) t1, t2 {= - if (!startup.is_present()) { - reactor::log::Error() << "Startup is not present."; - exit(1); - } - - if (!t1.is_present()) { - reactor::log::Error() << "t1 is not present at startup."; + timer t1(0, 50 msec) + timer t2(33 msec, 33 msec) + + reaction(startup) t1, t2 {= + if (!startup.is_present()) { + reactor::log::Error() << "Startup is not present."; + exit(1); + } + + if (!t1.is_present()) { + reactor::log::Error() << "t1 is not present at startup."; + exit(1); + } + + if (t2.is_present()) { + reactor::log::Error() << "t2 is present at startup."; + exit(1); + } + =} + + reaction(t1, t2) {= + if (t1.is_present() && t2.is_present()) { + reactor::log::Error() << "t1 and t2 are both present."; + exit(1); + } + + if (!t1.is_present() && !t2.is_present()) { + reactor::log::Error() << "Neither t1 nor t2 are both present."; + exit(1); + } + =} + + reaction(shutdown) t1, t2 {= + if (!shutdown.is_present()) { + reactor::log::Error() << "Shutdown is not present."; + exit(1); + } + + if (!t1.is_present()) { + reactor::log::Error() << "t1 is not present at shutdown."; exit(1); } if (t2.is_present()) { - reactor::log::Error() << "t2 is present at startup."; + reactor::log::Error() << "t2 is present at shutdown"; exit(1); } - =} - - reaction(t1, t2) {= - if (t1.is_present() && t2.is_present()) { - reactor::log::Error() << "t1 and t2 are both present."; - exit(1); - } - - if (!t1.is_present() && !t2.is_present()) { - reactor::log::Error() << "Neither t1 nor t2 are both present."; - exit(1); - } - =} - - reaction(shutdown) t1, t2 {= - if (!shutdown.is_present()) { - reactor::log::Error() << "Shutdown is not present."; - exit(1); - } - - if (!t1.is_present()) { - reactor::log::Error() << "t1 is not present at shutdown."; - exit(1); - } - - if (t2.is_present()) { - reactor::log::Error() << "t2 is present at shutdown"; - exit(1); - } - =} + =} } diff --git a/test/Cpp/src/ToReactionNested.lf b/test/Cpp/src/ToReactionNested.lf index 5b048bc0a7..6a1997972a 100644 --- a/test/Cpp/src/ToReactionNested.lf +++ b/test/Cpp/src/ToReactionNested.lf @@ -1,37 +1,37 @@ target Cpp { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } import Count from "lib/Count.lf" reactor CountContainer { - output out: int - c1 = new Count() - c1.c -> out + output out: int + c1 = new Count() + c1.c -> out } main reactor { - state count: int = 1 - state received: bool = false + state count: int = 1 + state received: bool = false - s = new CountContainer() + s = new CountContainer() - reaction(s.out) {= - if (s.out.is_present()){ - reactor::log::Info() << "Received " << *s.out.get(); - if(count != *s.out.get()){ - reactor::log::Error() << "Expected " << count; - } - received = true; + reaction(s.out) {= + if (s.out.is_present()){ + reactor::log::Info() << "Received " << *s.out.get(); + if(count != *s.out.get()){ + reactor::log::Error() << "Expected " << count; } - count++; - =} + received = true; + } + count++; + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "No inputs present."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "No inputs present."; + exit(1); + } + =} } diff --git a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf index b8c304b164..8bac112717 100644 --- a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,43 +1,42 @@ /** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. + * This test checks that a downstream reaction is triggered only if its trigger is present. * * @author Maiko Brants TU Dresden * * Modeled after the C version of this test. */ target Cpp { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source { - output[2] out: int - state count: int = 0 - timer t(0, 200 msec) + output[2] out: int + state count: int = 0 + timer t(0, 200 msec) - reaction(t) -> out {= - if(count++ % 2 == 0) { - out[0].set(count); - } else { - out[1].set(count); - } - =} + reaction(t) -> out {= + if(count++ % 2 == 0) { + out[0].set(count); + } else { + out[1].set(count); + } + =} } reactor Destination { - input in: int + input in: int - reaction(in) {= - if(!in.is_present()){ - reactor::log::Error() << "Reaction to input of triggered even though all inputs are absent!"; - exit(1); - } - =} + reaction(in) {= + if(!in.is_present()){ + reactor::log::Error() << "Reaction to input of triggered even though all inputs are absent!"; + exit(1); + } + =} } main reactor TriggerDownstreamOnlyIfPresent2 { - s = new Source() - d = new[2] Destination() - s.out -> d.in + s = new Source() + d = new[2] Destination() + s.out -> d.in } diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index 1258f69ce5..fff5b229e0 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -1,62 +1,62 @@ // Test asynchronous callbacks that trigger a physical action. target Cpp { - timeout: 2 sec, - cmake-include: "AsyncCallback.cmake" + timeout: 2 sec, + cmake-include: "AsyncCallback.cmake" } main reactor AsyncCallback { - public preamble {= - #include - =} + public preamble {= + #include + =} - timer t(0, 200 msec) - state thread: {= std::thread =} - state expected_time: time = 100 msec - state toggle: bool = false + timer t(0, 200 msec) + state thread: {= std::thread =} + state expected_time: time = 100 msec + state toggle: bool = false - physical action a: int - state i: int = 0 + physical action a: int + state i: int = 0 - reaction(t) -> a {= - // make sure to join the old thread first - if(thread.joinable()) { - thread.join(); - } + reaction(t) -> a {= + // make sure to join the old thread first + if(thread.joinable()) { + thread.join(); + } - // start new thread - this->thread = std::thread([&] () { - // Simulate time passing before a callback occurs - std::this_thread::sleep_for(100ms); - // Schedule twice. If the action is not physical, these should - // get consolidated into a single action triggering. If it is, - // then they cause two separate triggerings with close but not - // equal time stamps. - a.schedule(0); - a.schedule(0); - }); - =} + // start new thread + this->thread = std::thread([&] () { + // Simulate time passing before a callback occurs + std::this_thread::sleep_for(100ms); + // Schedule twice. If the action is not physical, these should + // get consolidated into a single action triggering. If it is, + // then they cause two separate triggerings with close but not + // equal time stamps. + a.schedule(0); + a.schedule(0); + }); + =} - reaction(a) {= - auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Asynchronous callback " << i++ << ": Assigned logical " - << "time greater than start time by " << elapsed_time << std::endl; - if (elapsed_time <= expected_time) { - std::cerr << "ERROR: Expected logical time to be larger than " - << expected_time << std::endl; - exit(1); - } - if (toggle) { - toggle = false; - expected_time += 200ms; - } else { - toggle = true; - } - =} + reaction(a) {= + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Asynchronous callback " << i++ << ": Assigned logical " + << "time greater than start time by " << elapsed_time << std::endl; + if (elapsed_time <= expected_time) { + std::cerr << "ERROR: Expected logical time to be larger than " + << expected_time << std::endl; + exit(1); + } + if (toggle) { + toggle = false; + expected_time += 200ms; + } else { + toggle = true; + } + =} - reaction(shutdown) {= - // make sure to join the thread before shutting down - if(thread.joinable()) { - thread.join(); - } - =} + reaction(shutdown) {= + // make sure to join the thread before shutting down + if(thread.joinable()) { + thread.join(); + } + =} } diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index c89b8ab712..d2f34ea4e6 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -1,43 +1,43 @@ // Test asynchronous callbacks that trigger a non-physical action. target Cpp { - timeout: 2 sec, - cmake-include: "AsyncCallback.cmake" + timeout: 2 sec, + cmake-include: "AsyncCallback.cmake" } main reactor AsyncCallback2 { - private preamble {= - #include - =} + private preamble {= + #include + =} - timer t(0, 200 msec) - state expected_time: time = 0 + timer t(0, 200 msec) + state expected_time: time = 0 - logical action a: int - state i: int = 0 + logical action a: int + state i: int = 0 - reaction(t) -> a {= - // start new thread - auto thread = std::thread([&] () { - // Simulate time passing before a callback occurs - std::this_thread::sleep_for(100ms); - // Schedule twice. If the action is not physical, these should - // get consolidated into a single action triggering. If it is, - // then they cause two separate triggerings with close but not - // equal time stamps. - a.schedule(0); - a.schedule(0); - }); - thread.join(); - =} + reaction(t) -> a {= + // start new thread + auto thread = std::thread([&] () { + // Simulate time passing before a callback occurs + std::this_thread::sleep_for(100ms); + // Schedule twice. If the action is not physical, these should + // get consolidated into a single action triggering. If it is, + // then they cause two separate triggerings with close but not + // equal time stamps. + a.schedule(0); + a.schedule(0); + }); + thread.join(); + =} - reaction(a) {= - auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Asynchronous callback " << i++ << ": Assigned logical " - << "time greater than start time by " << elapsed_time << std::endl; - if (elapsed_time != expected_time) { - std::cerr << "ERROR: Expected logical time to be " << expected_time << std::endl; - exit(1); - } - expected_time += 200ms; - =} + reaction(a) {= + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Asynchronous callback " << i++ << ": Assigned logical " + << "time greater than start time by " << elapsed_time << std::endl; + if (elapsed_time != expected_time) { + std::cerr << "ERROR: Expected logical time to be " << expected_time << std::endl; + exit(1); + } + expected_time += 200ms; + =} } diff --git a/test/Cpp/src/concurrent/CompositionThreaded.lf b/test/Cpp/src/concurrent/CompositionThreaded.lf index 42817e8b1d..01cb2b9b17 100644 --- a/test/Cpp/src/concurrent/CompositionThreaded.lf +++ b/test/Cpp/src/concurrent/CompositionThreaded.lf @@ -1,45 +1,44 @@ -// This test connects a simple counting source to tester that checks against its -// own count. +// This test connects a simple counting source to tester that checks against its own count. target Cpp { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period: time = 2 sec) { - output y: int - timer t(1 sec, period) - state count: int = 0 + output y: int + timer t(1 sec, period) + state count: int = 0 - reaction(t) -> y {= - count++; - y.set(count); - =} + reaction(t) -> y {= + count++; + y.set(count); + =} } reactor Test { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - count++; - auto value = *x.get(); - std::cout << "Received " << value << std::endl; - if (value != count) { - std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); - } - =} + reaction(x) {= + count++; + auto value = *x.get(); + std::cout << "Received " << value << std::endl; + if (value != count) { + std::cerr << "FAILURE: Expected " << count << std::endl; + exit(1); + } + =} - reaction(shutdown) {= - if (count != 5) { - std::cerr << "ERROR: expected to receive 5 values but got " << count << '\n'; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 5) { + std::cerr << "ERROR: expected to receive 5 values but got " << count << '\n'; + exit(1); + } + =} } main reactor { - s = new Source() - d = new Test() - s.y -> d.x + s = new Source() + d = new Test() + s.y -> d.x } diff --git a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf index bb380fe14c..548a5d477b 100644 --- a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -1,42 +1,42 @@ -// Test a deadline where the deadline violation produces an output and the -// container reacts to that output. +// Test a deadline where the deadline violation produces an output and the container reacts to that +// output. target Cpp reactor Deadline(threshold: time = 100 msec) { - input x: int - output deadline_violation: bool + input x: int + output deadline_violation: bool - reaction(x) -> deadline_violation {= - std::cerr << "ERROR: Deadline violation was not detected!" << std::endl; - exit(1); - =} deadline(threshold) {= - std::cout << "Deadline violation detected." << std::endl; - deadline_violation.set(true); - =} + reaction(x) -> deadline_violation {= + std::cerr << "ERROR: Deadline violation was not detected!" << std::endl; + exit(1); + =} deadline(threshold) {= + std::cout << "Deadline violation detected." << std::endl; + deadline_violation.set(true); + =} } main reactor { - state violation_detected: bool = {= false =} - d = new Deadline(threshold = 10 msec) + state violation_detected: bool = {= false =} + d = new Deadline(threshold = 10 msec) - reaction(startup) -> d.x {= - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - d.x.set(42); - =} + reaction(startup) -> d.x {= + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + d.x.set(42); + =} - reaction(d.deadline_violation) {= - if (*d.deadline_violation.get()) { - std::cout << "Output successfully produced by deadline miss handler." << std::endl; - violation_detected = true; - } - =} + reaction(d.deadline_violation) {= + if (*d.deadline_violation.get()) { + std::cout << "Output successfully produced by deadline miss handler." << std::endl; + violation_detected = true; + } + =} - reaction(shutdown) {= - if (violation_detected) { - std::cout << "SUCCESS. Test passes." << std::endl; - } else { - std::cerr << "ERROR. Container did not react to deadline violation." << std::endl; - exit(2); - } - =} + reaction(shutdown) {= + if (violation_detected) { + std::cout << "SUCCESS. Test passes." << std::endl; + } else { + std::cerr << "ERROR. Container did not react to deadline violation." << std::endl; + exit(2); + } + =} } diff --git a/test/Cpp/src/concurrent/DeadlineThreaded.lf b/test/Cpp/src/concurrent/DeadlineThreaded.lf index cb794f5050..3a202fd568 100644 --- a/test/Cpp/src/concurrent/DeadlineThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineThreaded.lf @@ -1,59 +1,58 @@ -// This example illustrates local deadline handling. Even numbers are sent by -// the Source immediately, whereas odd numbers are sent after a big enough delay -// to violate the deadline. +// This example illustrates local deadline handling. Even numbers are sent by the Source +// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline. target Cpp { - timeout: 4 sec + timeout: 4 sec } reactor Source(period: time = 2 sec) { - private preamble {= - #include - =} - output y: int - timer t(0, period) - state count: int = 0 + private preamble {= + #include + =} + output y: int + timer t(0, period) + state count: int = 0 - reaction(t) -> y {= - if (count % 2 == 1) { - // The count variable is odd. - // Take time to cause a deadline violation. - std::this_thread::sleep_for(200ms); - } - std::cout << "Source sends: " << count << std::endl; - y.set(count); - count++; - =} + reaction(t) -> y {= + if (count % 2 == 1) { + // The count variable is odd. + // Take time to cause a deadline violation. + std::this_thread::sleep_for(200ms); + } + std::cout << "Source sends: " << count << std::endl; + y.set(count); + count++; + =} } reactor Destination(timeout: time = 1 sec) { - input x: int - state count: int = 0 + input x: int + state count: int = 0 - reaction(x) {= - std::cout << "Destination receives: " << *x.get() << std::endl; - if (count % 2 == 1) { - // The count variable is odd, so the deadline should have been - // violated - std::cerr << "ERROR: Failed to detect deadline." << std::endl; - exit(1); - } - count++; - =} deadline(timeout) {= - std::cout << "Destination deadline handler receives: " - << *x.get() << std::endl; - if (count % 2 == 0) { - // The count variable is even, so the deadline should not have - // been violated. - std::cerr << "ERROR: Deadline handler invoked without deadline " - << "violation." << std::endl; - exit(2); - } - count++; - =} + reaction(x) {= + std::cout << "Destination receives: " << *x.get() << std::endl; + if (count % 2 == 1) { + // The count variable is odd, so the deadline should have been + // violated + std::cerr << "ERROR: Failed to detect deadline." << std::endl; + exit(1); + } + count++; + =} deadline(timeout) {= + std::cout << "Destination deadline handler receives: " + << *x.get() << std::endl; + if (count % 2 == 0) { + // The count variable is even, so the deadline should not have + // been violated. + std::cerr << "ERROR: Deadline handler invoked without deadline " + << "violation." << std::endl; + exit(2); + } + count++; + =} } main reactor { - s = new Source() - d = new Destination(timeout = 200 msec) - s.y -> d.x + s = new Source() + d = new Destination(timeout = 200 msec) + s.y -> d.x } diff --git a/test/Cpp/src/concurrent/DelayIntThreaded.lf b/test/Cpp/src/concurrent/DelayIntThreaded.lf index 319cae8b76..dc3c2746ee 100644 --- a/test/Cpp/src/concurrent/DelayIntThreaded.lf +++ b/test/Cpp/src/concurrent/DelayIntThreaded.lf @@ -2,53 +2,53 @@ target Cpp reactor Delay(delay: time = 100 msec) { - input in: int - output out: int - logical action d: int + input in: int + output out: int + logical action d: int - reaction(in) -> d {= d.schedule(in.get(), delay); =} + reaction(in) -> d {= d.schedule(in.get(), delay); =} - reaction(d) -> out {= - if (d.is_present()) { - out.set(d.get()); - } - =} + reaction(d) -> out {= + if (d.is_present()) { + out.set(d.get()); + } + =} } reactor Test { - input in: int - state start_time: {= reactor::TimePoint =} - timer start - - reaction(start) {= - // Record the logical time at the start. - start_time = get_logical_time(); - =} - - reaction(in) {= - std::cout << "Received: " << *in.get() << std::endl; - // Check the time of the input. - auto current_time = get_logical_time(); - auto elapsed = current_time - start_time; - std::cout << "After " << elapsed << " of logical time." << std::endl; - if (elapsed != 100ms) { - std::cerr << "ERROR: Expected elapsed time to be 100000000 nsecs. " - << "It was " << elapsed << std::endl; - exit(1); - } - if (*in.get() != 42) { - std::cerr << "ERROR: Expected input value to be 42. " - << "It was " << *in.get() << std::endl; - exit(2); - } - =} + input in: int + state start_time: {= reactor::TimePoint =} + timer start + + reaction(start) {= + // Record the logical time at the start. + start_time = get_logical_time(); + =} + + reaction(in) {= + std::cout << "Received: " << *in.get() << std::endl; + // Check the time of the input. + auto current_time = get_logical_time(); + auto elapsed = current_time - start_time; + std::cout << "After " << elapsed << " of logical time." << std::endl; + if (elapsed != 100ms) { + std::cerr << "ERROR: Expected elapsed time to be 100000000 nsecs. " + << "It was " << elapsed << std::endl; + exit(1); + } + if (*in.get() != 42) { + std::cerr << "ERROR: Expected input value to be 42. " + << "It was " << *in.get() << std::endl; + exit(2); + } + =} } main reactor { - timer t - d = new Delay() - test = new Test() - d.out -> test.in + timer t + d = new Delay() + test = new Test() + d.out -> test.in - reaction(t) -> d.in {= d.in.set(42); =} + reaction(t) -> d.in {= d.in.set(42); =} } diff --git a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf index d68f2e8b60..489782ed94 100644 --- a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf +++ b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf @@ -1,48 +1,48 @@ -// Test that two simultaneous inputs that trigger a reaction trigger it only -// once. Correct output for this 2, 4, 6, 8, etc. +// Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output +// for this 2, 4, 6, 8, etc. target Cpp { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - count++; - y.set(count); - =} + reaction(t) -> y {= + count++; + y.set(count); + =} } reactor Destination { - input x: int - input w: int - state s: int = 2 + input x: int + input w: int + state s: int = 2 - reaction(x, w) {= - int sum = 0; - if (x.is_present()) { - sum += *x.get(); - } - if (w.is_present()) { - sum += *w.get(); - } - std::cout << "Sum of inputs is: " << sum << std::endl; - if (sum != s) { - std::cerr << "FAILURE: Expected sum to be " << s - << "but it was " << sum << std::endl; - exit(1); - } - s += 2; - =} + reaction(x, w) {= + int sum = 0; + if (x.is_present()) { + sum += *x.get(); + } + if (w.is_present()) { + sum += *w.get(); + } + std::cout << "Sum of inputs is: " << sum << std::endl; + if (sum != s) { + std::cerr << "FAILURE: Expected sum to be " << s + << "but it was " << sum << std::endl; + exit(1); + } + s += 2; + =} } main reactor { - c1 = new Clock() - c2 = new Clock() - d = new Destination() - c1.y -> d.x - c2.y -> d.w + c1 = new Clock() + c2 = new Clock() + d = new Destination() + c1.y -> d.x + c2.y -> d.w } diff --git a/test/Cpp/src/concurrent/GainThreaded.lf b/test/Cpp/src/concurrent/GainThreaded.lf index e88801f5a1..ca1a7cc676 100644 --- a/test/Cpp/src/concurrent/GainThreaded.lf +++ b/test/Cpp/src/concurrent/GainThreaded.lf @@ -2,30 +2,30 @@ target Cpp reactor Scale(scale: int = 2) { - input x: int - output y: int + input x: int + output y: int - reaction(x) -> y {= y.set(*x.get() * scale); =} + reaction(x) -> y {= y.set(*x.get() * scale); =} } reactor Test { - input x: int + input x: int - reaction(x) {= - auto value = *x.get(); - std::cout << "Received " << value << std::endl; - if (value != 2) { - std::cerr << "Expected 2!" << std::endl; - exit(1); - } - =} + reaction(x) {= + auto value = *x.get(); + std::cout << "Received " << value << std::endl; + if (value != 2) { + std::cerr << "Expected 2!" << std::endl; + exit(1); + } + =} } main reactor { - g = new Scale() - t = new Test() - g.y -> t.x - timer tim + g = new Scale() + t = new Test() + g.y -> t.x + timer tim - reaction(tim) -> g.x {= g.x.set(1); =} + reaction(tim) -> g.x {= g.x.set(1); =} } diff --git a/test/Cpp/src/concurrent/HelloThreaded.lf b/test/Cpp/src/concurrent/HelloThreaded.lf index 2c849b94dc..790aadf913 100644 --- a/test/Cpp/src/concurrent/HelloThreaded.lf +++ b/test/Cpp/src/concurrent/HelloThreaded.lf @@ -1,56 +1,46 @@ -// This test checks that logical time is incremented an appropriate amount as a -// result of an invocation of the schedule() function at runtime. It also -// performs various smoke tests of timing aligned reactions. The first instance -// has a period of 4 seconds, the second of 2 seconds, and the third (composite) -// or 1 second. +// This test checks that logical time is incremented an appropriate amount as a result of an +// invocation of the schedule() function at runtime. It also performs various smoke tests of timing +// aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, and the +// third (composite) or 1 second. target Cpp { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } -reactor HelloCpp( - period: time = 2 sec, - message: {= std::string =} = "Hello C++" -) { - state count: int = 0 - state previous_time: {= reactor::TimePoint =} - timer t(1 sec, period) - logical action a: void +reactor HelloCpp(period: time = 2 sec, message: {= std::string =} = "Hello C++") { + state count: int = 0 + state previous_time: {= reactor::TimePoint =} + timer t(1 sec, period) + logical action a: void - reaction(t) -> a {= - std::cout << message << std::endl; - a.schedule(200ms); // No payload. - // Print the current time. - previous_time = get_logical_time(); - std::cout << "Current time is " << previous_time << std::endl; - =} + reaction(t) -> a {= + std::cout << message << std::endl; + a.schedule(200ms); // No payload. + // Print the current time. + previous_time = get_logical_time(); + std::cout << "Current time is " << previous_time << std::endl; + =} - reaction(a) {= - count++; - auto time = get_logical_time(); - std::cout << "***** action " << count << " at time " - << time << std::endl; - auto diff = time - previous_time; - if (diff != 200ms) { - std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " - << "but got " << diff << std::endl; - exit(1); - } - =} + reaction(a) {= + count++; + auto time = get_logical_time(); + std::cout << "***** action " << count << " at time " + << time << std::endl; + auto diff = time - previous_time; + if (diff != 200ms) { + std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " + << "but got " << diff << std::endl; + exit(1); + } + =} } -reactor Inside( - period: time = 1 sec, - message: {= std::string =} = "Composite default message." -) { - third_instance = new HelloCpp(period = period, message = message) +reactor Inside(period: time = 1 sec, message: {= std::string =} = "Composite default message.") { + third_instance = new HelloCpp(period = period, message = message) } main reactor { - first_instance = new HelloCpp( - period = 4 sec, - message = "Hello from first_instance." - ) - second_instance = new HelloCpp(message = "Hello from second_instance.") - composite_instance = new Inside(message = "Hello from composite_instance.") + first_instance = new HelloCpp(period = 4 sec, message = "Hello from first_instance.") + second_instance = new HelloCpp(message = "Hello from second_instance.") + composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/Cpp/src/concurrent/SendingInsideThreaded.lf b/test/Cpp/src/concurrent/SendingInsideThreaded.lf index 51ca511e26..f4b4dd2560 100644 --- a/test/Cpp/src/concurrent/SendingInsideThreaded.lf +++ b/test/Cpp/src/concurrent/SendingInsideThreaded.lf @@ -1,31 +1,31 @@ -// This tests a reactor that contains another reactor and also has its own -// reaction that routes inputs to the contained reactor. +// This tests a reactor that contains another reactor and also has its own reaction that routes +// inputs to the contained reactor. target Cpp { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Printer { - input x: int - state count: int = 1 + input x: int + state count: int = 1 - reaction(x) {= - std::cout << "Inside reactor received: " << *x.get() << std::endl; - if (*x.get() != count) { - std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); - } - count++; - =} + reaction(x) {= + std::cout << "Inside reactor received: " << *x.get() << std::endl; + if (*x.get() != count) { + std::cerr << "FAILURE: Expected " << count << std::endl; + exit(1); + } + count++; + =} } main reactor { - state count: int = 0 - timer t(0, 1 sec) - p = new Printer() + state count: int = 0 + timer t(0, 1 sec) + p = new Printer() - reaction(t) -> p.x {= - count++; - p.x.set(count); - =} + reaction(t) -> p.x {= + count++; + p.x.set(count); + =} } diff --git a/test/Cpp/src/concurrent/Threaded.lf b/test/Cpp/src/concurrent/Threaded.lf index 9ad4fcbe56..382c3bfa7c 100644 --- a/test/Cpp/src/concurrent/Threaded.lf +++ b/test/Cpp/src/concurrent/Threaded.lf @@ -1,70 +1,68 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded -// version, showing that without threads, this takes more than 800 msec to -// complete 200 msec of logical time. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing +// that without threads, this takes more than 800 msec to complete 200 msec of logical time. target Cpp { - timeout: 2 sec + timeout: 2 sec } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - out.set(s); - s++; - =} + reaction(t) -> out {= + out.set(s); + s++; + =} } reactor Computation { - private preamble {= - #include - =} - input in: int - output out: int + private preamble {= + #include + =} + input in: int + output out: int - reaction(in) -> out {= - std::this_thread::sleep_for(200ms); - out.set(in.get()); - =} + reaction(in) -> out {= + std::this_thread::sleep_for(200ms); + out.set(in.get()); + =} } reactor Destination { - state s: int = 0 - input in1: int - input in2: int - input in3: int - input in4: int + state s: int = 0 + input in1: int + input in2: int + input in3: int + input in4: int - reaction(in1, in2, in3, in4) {= - int sum = *in1.get() + *in2.get() + *in3.get() + *in4.get(); - std::cout << "Sum of received: " << sum << '\n'; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << '\n'; - exit(1); - } - s += 4; - =} + reaction(in1, in2, in3, in4) {= + int sum = *in1.get() + *in2.get() + *in3.get() + *in4.get(); + std::cout << "Sum of received: " << sum << '\n'; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << '\n'; + exit(1); + } + s += 4; + =} } main reactor { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1.in - a.out -> t2.in - a.out -> t3.in - a.out -> t4.in - t1.out -> b.in1 - t2.out -> b.in2 - t3.out -> b.in3 - t4.out -> b.in4 + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1.in + a.out -> t2.in + a.out -> t3.in + a.out -> t4.in + t1.out -> b.in1 + t2.out -> b.in2 + t3.out -> b.in3 + t4.out -> b.in4 } diff --git a/test/Cpp/src/concurrent/ThreadedThreaded.lf b/test/Cpp/src/concurrent/ThreadedThreaded.lf index f8b21a6121..8e51ef0ccb 100644 --- a/test/Cpp/src/concurrent/ThreadedThreaded.lf +++ b/test/Cpp/src/concurrent/ThreadedThreaded.lf @@ -1,61 +1,59 @@ -// Check for speedup of multithreaded execution on multicore machines. Each -// instance of TakeTime takes 200 ms to transport the input to the output. Four -// of them are instantiated. Note that without parallel execution, there is no -// way this can keep up with real time since in every 200 msec cycle it has 800 -// msec of work to do. On a quad-core machine, however, it does pretty well, -// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded -// version, showing that without threads, this takes more than 800 msec to -// complete 200 msec of logical time. +// Check for speedup of multithreaded execution on multicore machines. Each instance of TakeTime +// takes 200 ms to transport the input to the output. Four of them are instantiated. Note that +// without parallel execution, there is no way this can keep up with real time since in every 200 +// msec cycle it has 800 msec of work to do. On a quad-core machine, however, it does pretty well, +// completing 800 msec of work in about 225 msec. NOTE: This is the non-threaded version, showing +// that without threads, this takes more than 800 msec to complete 200 msec of logical time. target Cpp { - timeout: 2 sec + timeout: 2 sec } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - out.set(s); - s++; - =} + reaction(t) -> out {= + out.set(s); + s++; + =} } reactor Computation { - private preamble {= - #include - =} - input in: int - output out: int + private preamble {= + #include + =} + input in: int + output out: int - reaction(in) -> out {= - std::this_thread::sleep_for(200ms); - out.set(in.get()); - =} + reaction(in) -> out {= + std::this_thread::sleep_for(200ms); + out.set(in.get()); + =} } reactor Destination { - state s: int = 0 - input[4] in: int + state s: int = 0 + input[4] in: int - reaction(in) {= - int sum = 0; - for (std::size_t i = 0; i < in.size(); i++) { - if (in[i].is_present()) sum += *in[i].get(); - } - std::cout << "Sum of received: " << sum << '\n'; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << '\n'; - exit(1); - } - s += 4; - =} + reaction(in) {= + int sum = 0; + for (std::size_t i = 0; i < in.size(); i++) { + if (in[i].is_present()) sum += *in[i].get(); + } + std::cout << "Sum of received: " << sum << '\n'; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << '\n'; + exit(1); + } + s += 4; + =} } main reactor { - a = new Source() - t = new[4] Computation() - b = new Destination() - (a.out)+ -> t.in - t.out -> b.in + a = new Source() + t = new[4] Computation() + b = new Destination() + (a.out)+ -> t.in + t.out -> b.in } diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index 47371f72d7..195ccef79f 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -1,50 +1,49 @@ -// Test that the stop function can be used to internally to impose a a time -// limit. This is also used to test performance (number of reactions per -// second). Correct output for this 1, 2, 3, 4. Failure for this test is failing -// to halt or getting the wrong data. +// Test that the stop function can be used to internally to impose a a time limit. This is also used +// to test performance (number of reactions per second). Correct output for this 1, 2, 3, 4. Failure +// for this test is failing to halt or getting the wrong data. target Cpp { - fast: true + fast: true } reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 + output y: int + timer t(offset, period) + state count: int = 0 - reaction(t) -> y {= - count++; - //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; - y.set(count); - =} + reaction(t) -> y {= + count++; + //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; + y.set(count); + =} } reactor Destination { - input x: int - state s: int = 1 + input x: int + state s: int = 1 - reaction(x) {= - //std::cout << "Received " << *x.get() << '\n'; - if (*x.get() != s) { - std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; - exit(1); - } - s++; - =} + reaction(x) {= + //std::cout << "Received " << *x.get() << '\n'; + if (*x.get() != s) { + std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; + exit(1); + } + s++; + =} - reaction(shutdown) {= - std::cout << "**** shutdown reaction invoked.\n"; - if (s != 12) { - std::cerr << "ERROR: Expected 12 but got " << s << '\n'; - exit(1); - } - =} + reaction(shutdown) {= + std::cout << "**** shutdown reaction invoked.\n"; + if (s != 12) { + std::cerr << "ERROR: Expected 12 but got " << s << '\n'; + exit(1); + } + =} } main reactor(period: time = 1 sec) { - timer stop(10 sec) - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + timer stop(10 sec) + c = new Clock(period = period) + d = new Destination() + c.y -> d.x - reaction(stop) {= environment()->sync_shutdown(); =} + reaction(stop) {= environment()->sync_shutdown(); =} } diff --git a/test/Cpp/src/enclave/EnclaveBank.lf b/test/Cpp/src/enclave/EnclaveBank.lf index 8894526927..64d1cba5a2 100644 --- a/test/Cpp/src/enclave/EnclaveBank.lf +++ b/test/Cpp/src/enclave/EnclaveBank.lf @@ -1,29 +1,29 @@ // This is a smoke test for an enclaved bank target Cpp { - timeout: 3 sec + timeout: 3 sec } reactor Node( - bank_index: size_t = 0, - id: std::string = {= "node" + std::to_string(bank_index) =}, - period: time = 500 msec, - duration: time = 10 msec + bank_index: size_t = 0, + id: std::string = {= "node" + std::to_string(bank_index) =}, + period: time = 500 msec, + duration: time = 10 msec ) { - logical action a: void + logical action a: void - reaction(startup, a) -> a {= - reactor::log::Info() << id << " reaction executes."; - std::this_thread::sleep_for(duration); - reactor::log::Info() << id << " reaction done."; - a.schedule(period); - =} deadline(period) {= - reactor::log::Error() << id << " deadline was violated!"; - exit(1); - =} + reaction(startup, a) -> a {= + reactor::log::Info() << id << " reaction executes."; + std::this_thread::sleep_for(duration); + reactor::log::Info() << id << " reaction done."; + a.schedule(period); + =} deadline(period) {= + reactor::log::Error() << id << " deadline was violated!"; + exit(1); + =} } main reactor { - slow = new Node(id = "slow", period = 1 sec, duration = 500 msec) - @enclave - nodes = new[2] Node() + slow = new Node(id = "slow", period = 1 sec, duration = 500 msec) + @enclave + nodes = new[2] Node() } diff --git a/test/Cpp/src/enclave/EnclaveBankEach.lf b/test/Cpp/src/enclave/EnclaveBankEach.lf index c6cdeac564..e4c497f422 100644 --- a/test/Cpp/src/enclave/EnclaveBankEach.lf +++ b/test/Cpp/src/enclave/EnclaveBankEach.lf @@ -1,30 +1,29 @@ -// This is a smoke test for an enclaved bank where each individual instance is -// an enclave +// This is a smoke test for an enclaved bank where each individual instance is an enclave target Cpp { - timeout: 1 sec + timeout: 1 sec } reactor Node( - bank_index: size_t = 0, - id: std::string = {= "node" + std::to_string(bank_index) =}, - period: {= reactor::Duration =} = {= 100ms * (bank_index+1) =}, - duration: {= reactor::Duration =} = {= 50ms + 100ms * bank_index =} + bank_index: size_t = 0, + id: std::string = {= "node" + std::to_string(bank_index) =}, + period: {= reactor::Duration =} = {= 100ms * (bank_index+1) =}, + duration: {= reactor::Duration =} = {= 50ms + 100ms * bank_index =} ) { - logical action a: void + logical action a: void - reaction(startup, a) -> a {= - reactor::log::Info() << id << " reaction executes."; - std::this_thread::sleep_for(duration); - reactor::log::Info() << id << " reaction done."; - a.schedule(period); - =} deadline(600 msec) {= - reactor::log::Error() << id << " deadline was violated!"; - exit(1); - =} + reaction(startup, a) -> a {= + reactor::log::Info() << id << " reaction executes."; + std::this_thread::sleep_for(duration); + reactor::log::Info() << id << " reaction done."; + a.schedule(period); + =} deadline(600 msec) {= + reactor::log::Error() << id << " deadline was violated!"; + exit(1); + =} } main reactor { - slow = new Node(id = "slow", period = {= 1s =}, duration = {= 700ms =}) - @enclave(each = true) - nodes = new[2] Node() + slow = new Node(id = "slow", period = {= 1s =}, duration = {= 700ms =}) + @enclave(each = true) + nodes = new[2] Node() } diff --git a/test/Cpp/src/enclave/EnclaveBroadcast.lf b/test/Cpp/src/enclave/EnclaveBroadcast.lf index 04a2a77941..cc4a110f13 100644 --- a/test/Cpp/src/enclave/EnclaveBroadcast.lf +++ b/test/Cpp/src/enclave/EnclaveBroadcast.lf @@ -1,39 +1,39 @@ target Cpp { - timeout: 1 sec + timeout: 1 sec } reactor Source { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(42); =} + reaction(startup) -> out {= out.set(42); =} } reactor Sink(bank_index: size_t = 0) { - input in: unsigned + input in: unsigned - state received: bool = false + state received: bool = false - reaction(in) {= - received = true; - std::cout << "Received " << *in.get() << '\n'; - if (*in.get() != 42) { - std::cerr << "Error: expected " << 42 << "!\n"; - exit(1); - } - =} + reaction(in) {= + received = true; + std::cout << "Received " << *in.get() << '\n'; + if (*in.get() != 42) { + std::cerr << "Error: expected " << 42 << "!\n"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: Sink " << bank_index << " didn't receive anything.\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: Sink " << bank_index << " didn't receive anything.\n"; + exit(2); + } + =} } main reactor { - @enclave - source = new Source() - @enclave(each = true) - sink = new[4] Sink() - (source.out)+ -> sink.in + @enclave + source = new Source() + @enclave(each = true) + sink = new[4] Sink() + (source.out)+ -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunication.lf b/test/Cpp/src/enclave/EnclaveCommunication.lf index b780dad109..17c8ee9242 100644 --- a/test/Cpp/src/enclave/EnclaveCommunication.lf +++ b/test/Cpp/src/enclave/EnclaveCommunication.lf @@ -1,44 +1,44 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunication2.lf b/test/Cpp/src/enclave/EnclaveCommunication2.lf index 648223fb0b..9451f455e2 100644 --- a/test/Cpp/src/enclave/EnclaveCommunication2.lf +++ b/test/Cpp/src/enclave/EnclaveCommunication2.lf @@ -1,43 +1,43 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - src = new Src() - @enclave - sink = new Sink() + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf index 6bbab0a700..36afcecd34 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayed.lf @@ -1,44 +1,44 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 100ms * value + 50ms; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value + 50ms; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in after 50 ms + src.out -> sink.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf index 9cfa3f0a11..5c51a84850 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayed2.lf @@ -1,43 +1,43 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 100ms * value + 50ms; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value + 50ms; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - src = new Src() - @enclave - sink = new Sink() + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in after 50 ms + src.out -> sink.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf index fa9c7b25e4..5c2ea549ea 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf @@ -1,47 +1,47 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 50 ms) - input in: int - state received: bool = false - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 100ms * value + 50ms; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value + 50ms; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in after 50 ms + src.out -> sink.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf index 3a0edfd7e5..a8a93dabbe 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationLocalEvents.lf @@ -1,47 +1,47 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 50 ms) - input in: int - state received: bool = false - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf index 4a74085dbc..a853b023a3 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBank.lf @@ -1,57 +1,57 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output[4] out: int - state counter: int = 0 - - reaction(t) -> out {= - for (auto& port : out) { - port.set(counter++); - } - =} + timer t(0, 100 ms) + output[4] out: int + state counter: int = 0 + + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50 ms) - input in: int - state received: bool = false - state iteration: int = 0 - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * iteration; - if (value != iteration*4 + bank_index) { - reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; - exit(1); - } - iteration++; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expected value at " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + state iteration: int = 0 + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new[4] Sink() + @enclave + src = new Src() + @enclave + sink = new[4] Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf index 682b812d4a..3b716ddbb7 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankDelayed.lf @@ -1,57 +1,57 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output[4] out: int - state counter: int = 0 - - reaction(t) -> out {= - for (auto& port : out) { - port.set(counter++); - } - =} + timer t(0, 100 ms) + output[4] out: int + state counter: int = 0 + + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50 ms) - input in: int - state received: bool = false - state iteration: int = 0 - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * iteration + 50ms; - if (value != iteration*4 + bank_index) { - reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; - exit(1); - } - iteration++; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expected value at " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + state iteration: int = 0 + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration + 50ms; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new[4] Sink() + @enclave + src = new Src() + @enclave + sink = new[4] Sink() - src.out -> sink.in after 50 ms + src.out -> sink.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf index e926019572..bf1dcc9a6d 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEach.lf @@ -1,57 +1,57 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output[4] out: int - state counter: int = 0 - - reaction(t) -> out {= - for (auto& port : out) { - port.set(counter++); - } - =} + timer t(0, 100 ms) + output[4] out: int + state counter: int = 0 + + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50 ms) - input in: int - state received: bool = false - state iteration: int = 0 - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * iteration; - if (value != iteration*4 + bank_index) { - reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; - exit(1); - } - iteration++; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expected value at " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + state iteration: int = 0 + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave(each = true) - sink = new[4] Sink() + @enclave + src = new Src() + @enclave(each = true) + sink = new[4] Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf index 238edf7bfc..0da4f978d7 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachDelayed.lf @@ -1,57 +1,57 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output[4] out: int - state counter: int = 0 - - reaction(t) -> out {= - for (auto& port : out) { - port.set(counter++); - } - =} + timer t(0, 100 ms) + output[4] out: int + state counter: int = 0 + + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50 ms) - input in: int - state received: bool = false - state iteration: int = 0 - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * iteration + 50ms; - if (value != iteration*4 + bank_index) { - reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; - exit(1); - } - iteration++; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expected value at " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + state iteration: int = 0 + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration + 50ms; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave(each = true) - sink = new[4] Sink() + @enclave + src = new Src() + @enclave(each = true) + sink = new[4] Sink() - src.out -> sink.in after 50 ms + src.out -> sink.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf index 15eb6faf68..87d498d3c8 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankEachPhysical.lf @@ -1,57 +1,57 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output[4] out: int - state counter: int = 0 - - reaction(t) -> out {= - for (auto& port : out) { - port.set(counter++); - } - =} + timer t(0, 100 ms) + output[4] out: int + state counter: int = 0 + + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50 ms) - input in: int - state received: bool = false - state iteration: int = 0 - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * iteration; - if (value != iteration*4 + bank_index) { - reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; - exit(1); - } - iteration++; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expected value not before " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + state iteration: int = 0 + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave(each = true) - sink = new[4] Sink() + @enclave + src = new Src() + @enclave(each = true) + sink = new[4] Sink() - src.out ~> sink.in + src.out ~> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf index 3867a7a627..84b933d475 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationMultiportToBankPhysical.lf @@ -1,57 +1,57 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output[4] out: int - state counter: int = 0 - - reaction(t) -> out {= - for (auto& port : out) { - port.set(counter++); - } - =} + timer t(0, 100 ms) + output[4] out: int + state counter: int = 0 + + reaction(t) -> out {= + for (auto& port : out) { + port.set(counter++); + } + =} } reactor Sink(bank_index: std::size_t = 0) { - timer t(0, 50 ms) - input in: int - state received: bool = false - state iteration: int = 0 - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * iteration; - if (value != iteration*4 + bank_index) { - reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; - exit(1); - } - iteration++; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expected value not before " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + state iteration: int = 0 + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * iteration; + if (value != iteration*4 + bank_index) { + reactor::log::Error() << "Expected to recive " << iteration*4 + bank_index; + exit(1); + } + iteration++; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new[4] Sink() + @enclave + src = new Src() + @enclave + sink = new[4] Sink() - src.out ~> sink.in + src.out ~> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf index ee3ab7f80b..19e49b0642 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysical.lf @@ -1,44 +1,44 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * value; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expecded value not before " << expected; - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expecded value not before " << expected; + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out ~> sink.in + src.out ~> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf index aa9c042502..e4467680db 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationPhysicalLocalEvents.lf @@ -1,47 +1,47 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Src { - timer t(0, 100 ms) - output out: int - state counter: int = 0 + timer t(0, 100 ms) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 50 ms) - input in: int - state received: bool = false - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); - auto expected = 100ms * value; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expecded value not before " << expected; - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} + timer t(0, 50 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time(); + auto expected = 100ms * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expecded value not before " << expected; + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out ~> sink.in + src.out ~> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveCycle.lf b/test/Cpp/src/enclave/EnclaveCycle.lf index d073c801c8..5643ba824c 100644 --- a/test/Cpp/src/enclave/EnclaveCycle.lf +++ b/test/Cpp/src/enclave/EnclaveCycle.lf @@ -1,67 +1,67 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Ping { - timer t(0, 100 ms) - input in: int - output out: int - state counter: int = 0 - state received: bool = false + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Ping Received " << value; - auto expected = 50ms + 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Ping Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } reactor Pong { - input in: int - output out: int - state received: bool = false + input in: int + output out: int + state received: bool = false - reaction(in) -> out {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Pong Received " << value; - auto expected = 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - out.set(value); - =} + reaction(in) -> out {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Pong Received " << value; + auto expected = 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + out.set(value); + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - @enclave - ping = new Ping() - @enclave - pong = new Pong() + @enclave + ping = new Ping() + @enclave + pong = new Pong() - ping.out -> pong.in - pong.out -> ping.in after 50 ms + ping.out -> pong.in + pong.out -> ping.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf b/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf index f347aa53a4..5a0310573d 100644 --- a/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf +++ b/test/Cpp/src/enclave/EnclaveCycleTwoTimers.lf @@ -1,70 +1,70 @@ target Cpp { - timeout: 1 s, - workers: 1 + timeout: 1 s, + workers: 1 } reactor Ping { - timer t(0, 100 ms) - input in: int - output out: int - state counter: int = 0 - state received: bool = false + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Ping Received " << value; - auto expected = 50ms + 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Ping Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } reactor Pong { - timer t(0, 100 ms) - input in: int - output out: int - state counter: int = 0 - state received: bool = false + timer t(0, 100 ms) + input in: int + output out: int + state counter: int = 0 + state received: bool = false - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Pong Received " << value; - auto expected = 50ms + 100ms * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Pong Received " << value; + auto expected = 50ms + 100ms * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} } main reactor { - @enclave - ping = new Ping() - @enclave - pong = new Pong() + @enclave + ping = new Ping() + @enclave + pong = new Pong() - ping.out -> pong.in after 50 ms - pong.out -> ping.in after 50 ms + ping.out -> pong.in after 50 ms + pong.out -> ping.in after 50 ms } diff --git a/test/Cpp/src/enclave/EnclaveHelloWorld.lf b/test/Cpp/src/enclave/EnclaveHelloWorld.lf index 7ca051533b..7947dd0bf4 100644 --- a/test/Cpp/src/enclave/EnclaveHelloWorld.lf +++ b/test/Cpp/src/enclave/EnclaveHelloWorld.lf @@ -1,12 +1,12 @@ target Cpp reactor Hello(msg: std::string = "World") { - reaction(startup) {= reactor::log::Info() << "Hello " << msg << '!'; =} + reaction(startup) {= reactor::log::Info() << "Hello " << msg << '!'; =} } main reactor(msg1: std::string = "World", msg2: std::string = "Enclave") { - hello1 = new Hello(msg = msg1) + hello1 = new Hello(msg = msg1) - @enclave - hello2 = new Hello(msg = msg2) + @enclave + hello2 = new Hello(msg = msg2) } diff --git a/test/Cpp/src/enclave/EnclaveHierarchy.lf b/test/Cpp/src/enclave/EnclaveHierarchy.lf index 9063942575..3fd3b6d528 100644 --- a/test/Cpp/src/enclave/EnclaveHierarchy.lf +++ b/test/Cpp/src/enclave/EnclaveHierarchy.lf @@ -1,41 +1,37 @@ // This is a smoke test for nested enclaves target Cpp { - timeout: 3 sec + timeout: 3 sec } -reactor Node( - id: std::string = "node", - period: time = 100 msec, - duration: time = 50 msec -) { - timer t(0, period) +reactor Node(id: std::string = "node", period: time = 100 msec, duration: time = 50 msec) { + timer t(0, period) - reaction(t) {= - reactor::log::Info() << id << " reaction executes."; - std::this_thread::sleep_for(duration); - reactor::log::Info() << id << " reaction done."; - =} deadline(300 msec) {= - reactor::log::Error() << id << " deadline was violated!"; - exit(1); - =} + reaction(t) {= + reactor::log::Info() << id << " reaction executes."; + std::this_thread::sleep_for(duration); + reactor::log::Info() << id << " reaction done."; + =} deadline(300 msec) {= + reactor::log::Error() << id << " deadline was violated!"; + exit(1); + =} } reactor MiddleNode { - @enclave - inner = new Node(id = "inner", period = 1 sec, duration = 400 msec) + @enclave + inner = new Node(id = "inner", period = 1 sec, duration = 400 msec) - middle = new Node(id = "middle", period = 200 msec, duration = 70 msec) + middle = new Node(id = "middle", period = 200 msec, duration = 70 msec) } reactor OuterNode { - @enclave - middle = new MiddleNode() + @enclave + middle = new MiddleNode() - outer = new Node(id = "outer", period = 500 msec, duration = 200 msec) + outer = new Node(id = "outer", period = 500 msec, duration = 200 msec) } main reactor { - outer = new OuterNode() - @enclave - node = new Node(id = "node", period = 2 sec, duration = 500 msec) + outer = new OuterNode() + @enclave + node = new Node(id = "node", period = 2 sec, duration = 500 msec) } diff --git a/test/Cpp/src/enclave/EnclaveMultiportToPort.lf b/test/Cpp/src/enclave/EnclaveMultiportToPort.lf index 027de94bfb..e5eb8dac90 100644 --- a/test/Cpp/src/enclave/EnclaveMultiportToPort.lf +++ b/test/Cpp/src/enclave/EnclaveMultiportToPort.lf @@ -1,49 +1,48 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[2] out: int + output[2] out: int - reaction(startup) -> out {= - for(int i = 0; i < out.size(); i++) { - std::cout << "Source sending " << i << ".\n"; - out[i].set(i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out.size(); i++) { + std::cout << "Source sending " << i << ".\n"; + out[i].set(i); + } + =} } reactor Destination(expected: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - std::cout << "Received: " << *in.get() << ".\n"; - received = true; - if (*in.get() != expected) { - std::cerr << "ERROR: Expected " << expected << ".\n"; - exit(1); - } - =} + reaction(in) {= + std::cout << "Received: " << *in.get() << ".\n"; + received = true; + if (*in.get() != expected) { + std::cerr << "ERROR: Expected " << expected << ".\n"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor { - @enclave - a = new Source() - @enclave - b1 = new Destination() - @enclave - b2 = new Destination(expected = 1) - a.out -> b1.in, b2.in + @enclave + a = new Source() + @enclave + b1 = new Destination() + @enclave + b2 = new Destination(expected = 1) + a.out -> b1.in, b2.in } diff --git a/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf b/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf index 5d8d72494d..7f3c5ff938 100644 --- a/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf +++ b/test/Cpp/src/enclave/EnclaveMultiportToPort2.lf @@ -1,48 +1,47 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[2] out: int + output[2] out: int - reaction(startup) -> out {= - for(int i = 0; i < out.size(); i++) { - std::cout << "Source sending " << i << ".\n"; - out[i].set(i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out.size(); i++) { + std::cout << "Source sending " << i << ".\n"; + out[i].set(i); + } + =} } reactor Destination(expected: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - std::cout << "Received: " << *in.get() << ".\n"; - received = true; - if (*in.get() != expected) { - std::cerr << "ERROR: Expected " << expected << ".\n"; - exit(1); - } - =} + reaction(in) {= + std::cout << "Received: " << *in.get() << ".\n"; + received = true; + if (*in.get() != expected) { + std::cerr << "ERROR: Expected " << expected << ".\n"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor { - @enclave - a = new Source() - @enclave - b1 = new Destination() - b2 = new Destination(expected = 1) - a.out -> b1.in, b2.in + @enclave + a = new Source() + @enclave + b1 = new Destination() + b2 = new Destination(expected = 1) + a.out -> b1.in, b2.in } diff --git a/test/Cpp/src/enclave/EnclaveShutdown.lf b/test/Cpp/src/enclave/EnclaveShutdown.lf index 831adcde9c..c0c0aa1c64 100644 --- a/test/Cpp/src/enclave/EnclaveShutdown.lf +++ b/test/Cpp/src/enclave/EnclaveShutdown.lf @@ -1,37 +1,33 @@ target Cpp -reactor Node( - message: std::string = "Hello", - period: time = 1 sec, - stop: time = 3 sec -) { - timer t(0, period) - timer s(stop) +reactor Node(message: std::string = "Hello", period: time = 1 sec, stop: time = 3 sec) { + timer t(0, period) + timer s(stop) - reaction(t) {= reactor::log::Info() << message; =} + reaction(t) {= reactor::log::Info() << message; =} - reaction(s) {= request_stop(); =} + reaction(s) {= request_stop(); =} - reaction(shutdown) {= - reactor::log::Info() << "Goodbye!"; + reaction(shutdown) {= + reactor::log::Info() << "Goodbye!"; - if (get_elapsed_logical_time() != stop || get_microstep() != 1) { - reactor::log::Error() << "Expected to shut down at [" << stop << ", 1]"; - exit(1); - } - =} + if (get_elapsed_logical_time() != stop || get_microstep() != 1) { + reactor::log::Error() << "Expected to shut down at [" << stop << ", 1]"; + exit(1); + } + =} } main reactor { - @enclave - node1 = new Node(message = "Hello Foo!") - @enclave - node2 = new Node(message = "Hello Bar!", stop = 2 sec) + @enclave + node1 = new Node(message = "Hello Foo!") + @enclave + node2 = new Node(message = "Hello Bar!", stop = 2 sec) - reaction(shutdown) {= - if (get_elapsed_logical_time() != 0s || get_microstep() != 1) { - reactor::log::Error() << "Expected to shut down at [0, 1]e"; - exit(1); - } - =} + reaction(shutdown) {= + if (get_elapsed_logical_time() != 0s || get_microstep() != 1) { + reactor::log::Error() << "Expected to shut down at [0, 1]e"; + exit(1); + } + =} } diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf index 431c2cd60a..6f713a7d88 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEvents.lf @@ -1,52 +1,52 @@ -// The purpose of this test is to check that the downstream enclave can -// progress, even if there are only sparse upstream events. +// The purpose of this test is to check that the downstream enclave can progress, even if there are +// only sparse upstream events. target Cpp { - timeout: 12 s, - workers: 1 + timeout: 12 s, + workers: 1 } reactor Src { - timer t(0, 4 s) - output out: int - state counter: int = 0 + timer t(0, 4 s) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 100 ms) - input in: int - state received: bool = false - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 4s * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= - reactor::log::Error() << "Deadline violated."; - exit(2); - =} + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 4s * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf index 691e80f4bf..dd2e0d04d7 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsDelayed.lf @@ -1,52 +1,52 @@ -// The purpose of this test is to check that the downstream enclave respects the -// after delay when aquiring tags from its upstream. +// The purpose of this test is to check that the downstream enclave respects the after delay when +// aquiring tags from its upstream. target Cpp { - timeout: 12 s, - workers: 1 + timeout: 12 s, + workers: 1 } reactor Src { - timer t(0, 4 s) - output out: int - state counter: int = 0 + timer t(0, 4 s) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 100 ms) - input in: int - state received: bool = false - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 2s + 4s * value; - if (get_elapsed_logical_time() != expected) { - reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= - reactor::log::Error() << "Deadline violated."; - exit(2); - =} + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s + 4s * value; + if (get_elapsed_logical_time() != expected) { + reactor::log::Error() << "Expected value at " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in after 2 s + src.out -> sink.in after 2 s } diff --git a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf index 10b5a8c4af..895e50d6c8 100644 --- a/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf +++ b/test/Cpp/src/enclave/EnclaveSparseUpstreamEventsPhysical.lf @@ -1,52 +1,52 @@ -// The purpose of this test is to check that the downstream enclave advances -// time independenty of the upstraem if the connection is physical. +// The purpose of this test is to check that the downstream enclave advances time independenty of +// the upstraem if the connection is physical. target Cpp { - timeout: 12 s, - workers: 1 + timeout: 12 s, + workers: 1 } reactor Src { - timer t(0, 4 s) - output out: int - state counter: int = 0 + timer t(0, 4 s) + output out: int + state counter: int = 0 - reaction(t) -> out {= out.set(counter++); =} + reaction(t) -> out {= out.set(counter++); =} } reactor Sink { - timer t(0, 100 ms) - input in: int - state received: bool = false - - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 4s * value; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} - - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} - - reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= - reactor::log::Error() << "Deadline violated."; - exit(2); - =} + timer t(0, 100 ms) + input in: int + state received: bool = false + + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 4s * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} + + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} + + reaction(t) {= reactor::log::Info() << "Tick"; =} deadline(2 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out ~> sink.in + src.out ~> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveTimeout.lf b/test/Cpp/src/enclave/EnclaveTimeout.lf index dc87acbd26..1e9614baa5 100644 --- a/test/Cpp/src/enclave/EnclaveTimeout.lf +++ b/test/Cpp/src/enclave/EnclaveTimeout.lf @@ -1,32 +1,32 @@ target Cpp { - timeout: 1 sec + timeout: 1 sec } reactor Node(message: std::string = "Hello", period: time = 1 sec) { - timer t(0, period) + timer t(0, period) - reaction(t) {= reactor::log::Info() << message; =} + reaction(t) {= reactor::log::Info() << message; =} - reaction(shutdown) {= - reactor::log::Info() << "Goodbye!"; + reaction(shutdown) {= + reactor::log::Info() << "Goodbye!"; - if (get_elapsed_logical_time() != 1s || get_microstep() != 0) { - reactor::log::Error() << "Expected to shut down at [1s, 0]"; - exit(1); - } - =} + if (get_elapsed_logical_time() != 1s || get_microstep() != 0) { + reactor::log::Error() << "Expected to shut down at [1s, 0]"; + exit(1); + } + =} } main reactor { - @enclave - node1 = new Node(message = "Hello Foo!") - @enclave - node2 = new Node(message = "Hello Bar!") + @enclave + node1 = new Node(message = "Hello Foo!") + @enclave + node2 = new Node(message = "Hello Bar!") - reaction(shutdown) {= - if (get_elapsed_logical_time() != 1s || get_microstep() != 0) { - reactor::log::Error() << "Expected to shut down at [1s, 0]e"; - exit(1); - } - =} + reaction(shutdown) {= + if (get_elapsed_logical_time() != 1s || get_microstep() != 0) { + reactor::log::Error() << "Expected to shut down at [1s, 0]e"; + exit(1); + } + =} } diff --git a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf index 18ac74b091..a82755181f 100644 --- a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf +++ b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalAction.lf @@ -1,77 +1,77 @@ -// The purpose of this test is to check that the downstream enclave can -// progress, even if there are only sparse upstream events. +// The purpose of this test is to check that the downstream enclave can progress, even if there are +// only sparse upstream events. target Cpp { - timeout: 10 s, - workers: 1 + timeout: 10 s, + workers: 1 } reactor Src { - public preamble {= - #include - =} + public preamble {= + #include + =} - state thread: std::thread{} + state thread: std::thread{} - physical action a: int - output out: int + physical action a: int + output out: int - reaction(startup) -> a {= - // start new thread - this->thread = std::thread([&] () { - for (int i{0}; i < 3; i++) { - a.schedule(i); - std::this_thread::sleep_for(2s); - } - }); - =} + reaction(startup) -> a {= + // start new thread + this->thread = std::thread([&] () { + for (int i{0}; i < 3; i++) { + a.schedule(i); + std::this_thread::sleep_for(2s); + } + }); + =} - reaction(a) -> out {= out.set(a.get()); =} + reaction(a) -> out {= out.set(a.get()); =} - reaction(shutdown) {= - // make sure to join the thread before shutting down - if(thread.joinable()) { - thread.join(); - } - =} + reaction(shutdown) {= + // make sure to join the thread before shutting down + if(thread.joinable()) { + thread.join(); + } + =} } reactor Sink { - timer t(0, 100 ms) - input in: int - state received: bool = false + timer t(0, 100 ms) + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 2s * value; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} - reaction(t) {= - reactor::log::Info() << "Tick - " << "logical time: " << get_elapsed_logical_time() - << "; physical time: " << get_elapsed_physical_time(); - =} deadline(1 s) {= - reactor::log::Error() << "Deadline violated."; - exit(2); - =} + reaction(t) {= + reactor::log::Info() << "Tick - " << "logical time: " << get_elapsed_logical_time() + << "; physical time: " << get_elapsed_physical_time(); + =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in + src.out -> sink.in } diff --git a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf index f87895f960..afc391bca2 100644 --- a/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf +++ b/test/Cpp/src/enclave/EnclaveUpstreamPhysicalActionDelayed.lf @@ -1,77 +1,77 @@ -// The purpose of this test is to check that the downstream enclave can -// progress, even if there are only sparse upstream events. +// The purpose of this test is to check that the downstream enclave can progress, even if there are +// only sparse upstream events. target Cpp { - timeout: 10 s, - workers: 1 + timeout: 10 s, + workers: 1 } reactor Src { - public preamble {= - #include - =} + public preamble {= + #include + =} - state thread: std::thread{} + state thread: std::thread{} - physical action a: int - output out: int + physical action a: int + output out: int - reaction(startup) -> a {= - // start new thread - this->thread = std::thread([&] () { - for (int i{0}; i < 3; i++) { - a.schedule(i); - std::this_thread::sleep_for(2s); - } - }); - =} + reaction(startup) -> a {= + // start new thread + this->thread = std::thread([&] () { + for (int i{0}; i < 3; i++) { + a.schedule(i); + std::this_thread::sleep_for(2s); + } + }); + =} - reaction(a) -> out {= out.set(a.get()); =} + reaction(a) -> out {= out.set(a.get()); =} - reaction(shutdown) {= - // make sure to join the thread before shutting down - if(thread.joinable()) { - thread.join(); - } - =} + reaction(shutdown) {= + // make sure to join the thread before shutting down + if(thread.joinable()) { + thread.join(); + } + =} } reactor Sink { - timer t(0, 100 ms) - input in: int - state received: bool = false + timer t(0, 100 ms) + input in: int + state received: bool = false - reaction(in) {= - received = true; - auto value = *in.get(); - reactor::log::Info() << "Received " << value; - auto expected = 2s * value; - if (get_elapsed_logical_time() < expected) { - reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); - exit(1); - } - =} + reaction(in) {= + received = true; + auto value = *in.get(); + reactor::log::Info() << "Received " << value; + auto expected = 2s * value; + if (get_elapsed_logical_time() < expected) { + reactor::log::Error() << "Expected value not before " << expected << " but received it at " << get_elapsed_logical_time(); + exit(1); + } + =} - reaction(shutdown) {= - if(!received) { - reactor::log::Error() << "Nothing received."; - exit(1); - } - =} + reaction(shutdown) {= + if(!received) { + reactor::log::Error() << "Nothing received."; + exit(1); + } + =} - reaction(t) {= - reactor::log::Info() << "Tick - " << "logical time: " << get_elapsed_logical_time() - << "; physical time: " << get_elapsed_physical_time(); - =} deadline(1 s) {= - reactor::log::Error() << "Deadline violated."; - exit(2); - =} + reaction(t) {= + reactor::log::Info() << "Tick - " << "logical time: " << get_elapsed_logical_time() + << "; physical time: " << get_elapsed_physical_time(); + =} deadline(1 s) {= + reactor::log::Error() << "Deadline violated."; + exit(2); + =} } main reactor { - @enclave - src = new Src() - @enclave - sink = new Sink() + @enclave + src = new Src() + @enclave + sink = new Sink() - src.out -> sink.in after 2 s + src.out -> sink.in after 2 s } diff --git a/test/Cpp/src/enclave/FastAndSlow.lf b/test/Cpp/src/enclave/FastAndSlow.lf index 73b6869394..3d421223e6 100644 --- a/test/Cpp/src/enclave/FastAndSlow.lf +++ b/test/Cpp/src/enclave/FastAndSlow.lf @@ -1,37 +1,33 @@ -// This is a basic test for enclaved execution. The deadlines shiuld never be -// violated for the test to pass. +// This is a basic test for enclaved execution. The deadlines shiuld never be violated for the test +// to pass. target Cpp { - timeout: 3 sec + timeout: 3 sec } reactor Slow { - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(t) {= - reactor::log::Info() << "Slow reaction starts"; - std::this_thread::sleep_for(700ms); - reactor::log::Info() << "Slow reaction ends"; - =} deadline(200 msec) {= - reactor::log::Error() << "Slow deadline was violated!"; - exit(1); - =} + reaction(t) {= + reactor::log::Info() << "Slow reaction starts"; + std::this_thread::sleep_for(700ms); + reactor::log::Info() << "Slow reaction ends"; + =} deadline(200 msec) {= + reactor::log::Error() << "Slow deadline was violated!"; + exit(1); + =} } reactor Fast { - timer t(0 msec, 100 msec) + timer t(0 msec, 100 msec) - reaction(t) {= - reactor::log::Info() << "Fast reaction executes"; - =} deadline( - 200 msec - ) {= - reactor::log::Error() << "Fast deadline was violated!"; - exit(2); - =} + reaction(t) {= reactor::log::Info() << "Fast reaction executes"; =} deadline(200 msec) {= + reactor::log::Error() << "Fast deadline was violated!"; + exit(2); + =} } main reactor { - slow = new Slow() - @enclave - fast = new Fast() + slow = new Slow() + @enclave + fast = new Fast() } diff --git a/test/Cpp/src/lib/Count.lf b/test/Cpp/src/lib/Count.lf index 7b56233019..4bb993db42 100644 --- a/test/Cpp/src/lib/Count.lf +++ b/test/Cpp/src/lib/Count.lf @@ -1,12 +1,12 @@ target Cpp reactor Count { - output c: int - timer t(0, 1 sec) - state i: int = 0 + output c: int + timer t(0, 1 sec) + state i: int = 0 - reaction(t) -> c {= - i++; - c.set(i); - =} + reaction(t) -> c {= + i++; + c.set(i); + =} } diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index 3c1cc13631..00dee5631d 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -8,25 +8,24 @@ target Cpp /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { - output out: int - logical action act - state sent_messages: int = 0 + output out: int + logical action act + state sent_messages: int = 0 - reaction(startup, act) -> act, out {= - out.set(sent_messages); - sent_messages++; - if(sent_messages < take_a_break_after){ - act.schedule(0ns); - } else { - // Take a break - sent_messages=0; - act.schedule(break_interval); - } - =} + reaction(startup, act) -> act, out {= + out.set(sent_messages); + sent_messages++; + if(sent_messages < take_a_break_after){ + act.schedule(0ns); + } else { + // Take a break + sent_messages=0; + act.schedule(break_interval); + } + =} } diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index 07da948506..9fcf4c51d0 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -1,7 +1,7 @@ /** - * Test a bank of reactors that broadcast a single output back to a multiport - * input of the same reactors in the bank so that each reactor in the bank - * receives the output produced by itself and each other reactor. + * Test a bank of reactors that broadcast a single output back to a multiport input of the same + * reactors in the bank so that each reactor in the bank receives the output produced by itself and + * each other reactor. * * @author Edward A. Lee * @author Christian Menard @@ -9,40 +9,40 @@ target Cpp reactor A(bank_index: size_t = 0) { - input[4] in: size_t - output out: size_t - state received: bool = false + input[4] in: size_t + output out: size_t + state received: bool = false - reaction(startup) -> out {= out.set(bank_index); =} + reaction(startup) -> out {= out.set(bank_index); =} - reaction(in) {= - for (size_t i = 0; i < in.size(); i++) { - if (in[i].is_present()) { - std::cout << "Reactor " << bank_index << " received " - << *in[i].get() << " on channel " << i << '\n'; + reaction(in) {= + for (size_t i = 0; i < in.size(); i++) { + if (in[i].is_present()) { + std::cout << "Reactor " << bank_index << " received " + << *in[i].get() << " on channel " << i << '\n'; - if (*in[i].get() != i) { - std::cerr << "ERROR: Expected " << i << '\n'; - exit(1); - } - received = true; - } else { - std::cout << "Reactor " << bank_index << " channel " << i << " is absent.\n"; + if (*in[i].get() != i) { std::cerr << "ERROR: Expected " << i << '\n'; exit(1); } + received = true; + } else { + std::cout << "Reactor " << bank_index << " channel " << i << " is absent.\n"; + std::cerr << "ERROR: Expected " << i << '\n'; + exit(1); } - =} + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: No inputs received.\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: No inputs received.\n"; + exit(2); + } + =} } main reactor { - a = new[4] A() - (a.out)+ -> a.in + a = new[4] A() + (a.out)+ -> a.in } diff --git a/test/Cpp/src/multiport/BankToBank.lf b/test/Cpp/src/multiport/BankToBank.lf index f70cfd83e4..d9fe3f437c 100644 --- a/test/Cpp/src/multiport/BankToBank.lf +++ b/test/Cpp/src/multiport/BankToBank.lf @@ -1,45 +1,44 @@ // Check bank of reactors sending to bank of reactors. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(bank_index: size_t = 0) { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= - out.set(s); - s += bank_index; - =} + reaction(t) -> out {= + out.set(s); + s += bank_index; + =} } reactor Destination(bank_index: size_t = 0) { - state s: int = 0 - input in: int + state s: int = 0 + input in: int - reaction(in) {= - std::cout << "Destination " << bank_index << " received: " << *in.get() << "\n"; - if (*in.get() != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += bank_index; - =} + reaction(in) {= + std::cout << "Destination " << bank_index << " received: " << *in.get() << "\n"; + if (*in.get() != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += bank_index; + =} - reaction(shutdown) {= - if (s == 0 && bank_index != 0) { - std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (s == 0 && bank_index != 0) { + std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor BankToBank(width: int = 4) { - // FIXME: Should set the width to "width" rather than "4". - a = new[4] Source() - b = new[4] Destination() - a.out -> b.in + a = new[4] Source() // FIXME: Should set the width to "width" rather than "4". + b = new[4] Destination() + a.out -> b.in } diff --git a/test/Cpp/src/multiport/BankToBankMultiport.lf b/test/Cpp/src/multiport/BankToBankMultiport.lf index bdb3e9a880..faffacb0cf 100644 --- a/test/Cpp/src/multiport/BankToBankMultiport.lf +++ b/test/Cpp/src/multiport/BankToBankMultiport.lf @@ -1,51 +1,51 @@ // Check bank of reactors sending to bank of reactors with multiports. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: size_t = 1) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 - - reaction(t) -> out {= - for(size_t i = 0; i < out.size(); i++) { - out[i].set(s++); - } - =} + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 + + reaction(t) -> out {= + for(size_t i = 0; i < out.size(); i++) { + out[i].set(s++); + } + =} } reactor Destination(width: size_t = 1) { - state s: int = 6 - input[width] in: int - - reaction(in) {= - int sum = 0; - - for (auto i : in.present_indices_unsorted()) { - sum += *in[i].get(); - } - - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 16; - =} - - reaction(shutdown) {= - if (s <= 6) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + state s: int = 6 + input[width] in: int + + reaction(in) {= + int sum = 0; + + for (auto i : in.present_indices_unsorted()) { + sum += *in[i].get(); + } + + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 16; + =} + + reaction(shutdown) {= + if (s <= 6) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor(bank_width: size_t = 4) { - a = new[bank_width] Source(width = 4) - b = new[bank_width] Destination(width = 4) - a.out -> b.in + a = new[bank_width] Source(width = 4) + b = new[bank_width] Destination(width = 4) + a.out -> b.in } diff --git a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf index 78d832a5ea..6c9c81c5b4 100644 --- a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf @@ -1,59 +1,59 @@ // Check bank of reactors sending to bank of reactors with multiports. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: size_t = 1) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 - - reaction(t) -> out {= - for(size_t i = 0; i < out.size(); i++) { - out[i].set(s++); - } - =} + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 + + reaction(t) -> out {= + for(size_t i = 0; i < out.size(); i++) { + out[i].set(s++); + } + =} } reactor Destination(width: size_t = 1) { - state s: int = 6 - state iterations: unsigned = 0 - input[width] in: int - - reaction(in) {= - iterations++; - auto lt = get_elapsed_logical_time(); - auto expected = iterations * 200ms; - if (expected != lt) { - std::cerr << "ERROR: Expected logical time to be " << expected << " but got " << lt << '\n'; - exit(1); - } - - int sum = 0; - for (auto i : in.present_indices_unsorted()) { - sum += *in[i].get(); - } - - std::cout << "Sum of received: " << sum << '\n'; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << '\n'; - exit(1); - } - s += 16; - =} - - reaction(shutdown) {= - if (s <= 6) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + state s: int = 6 + state iterations: unsigned = 0 + input[width] in: int + + reaction(in) {= + iterations++; + auto lt = get_elapsed_logical_time(); + auto expected = iterations * 200ms; + if (expected != lt) { + std::cerr << "ERROR: Expected logical time to be " << expected << " but got " << lt << '\n'; + exit(1); + } + + int sum = 0; + for (auto i : in.present_indices_unsorted()) { + sum += *in[i].get(); + } + + std::cout << "Sum of received: " << sum << '\n'; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << '\n'; + exit(1); + } + s += 16; + =} + + reaction(shutdown) {= + if (s <= 6) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor(bank_width: size_t = 4) { - a = new[bank_width] Source(width = 4) - b = new[bank_width] Destination(width = 4) - a.out -> b.in after 200 msec + a = new[bank_width] Source(width = 4) + b = new[bank_width] Destination(width = 4) + a.out -> b.in after 200 msec } diff --git a/test/Cpp/src/multiport/BankToMultiport.lf b/test/Cpp/src/multiport/BankToMultiport.lf index 6b1acf7591..af338a32a2 100644 --- a/test/Cpp/src/multiport/BankToMultiport.lf +++ b/test/Cpp/src/multiport/BankToMultiport.lf @@ -2,36 +2,36 @@ target Cpp reactor Source(bank_index: size_t = 0) { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(bank_index); =} + reaction(startup) -> out {= out.set(bank_index); =} } reactor Sink { - input[4] in: unsigned - state received: bool = false + input[4] in: unsigned + state received: bool = false - reaction(in) {= - for (unsigned i = 0; i < in.size(); i++) { - received = true; - std::cout << "Received " << *in[i].get() << '\n'; - if (*in[i].get() != i) { - std::cerr << "Error: expected " << i << "!\n"; - exit(1); - } + reaction(in) {= + for (unsigned i = 0; i < in.size(); i++) { + received = true; + std::cout << "Received " << *in[i].get() << '\n'; + if (*in[i].get() != i) { + std::cerr << "Error: expected " << i << "!\n"; + exit(1); } - =} + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: received no input!\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: received no input!\n"; + exit(2); + } + =} } main reactor BankToMultiport { - source = new[4] Source() - sink = new Sink() - source.out -> sink.in + source = new[4] Source() + sink = new Sink() + source.out -> sink.in } diff --git a/test/Cpp/src/multiport/Broadcast.lf b/test/Cpp/src/multiport/Broadcast.lf index 202a30c5f7..e6dcbf9607 100644 --- a/test/Cpp/src/multiport/Broadcast.lf +++ b/test/Cpp/src/multiport/Broadcast.lf @@ -1,34 +1,34 @@ target Cpp reactor Source { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(42); =} + reaction(startup) -> out {= out.set(42); =} } reactor Sink(bank_index: size_t = 0) { - input in: unsigned - state received: bool = false + input in: unsigned + state received: bool = false - reaction(in) {= - received = true; - std::cout << "Received " << *in.get() << '\n'; - if (*in.get() != 42) { - std::cerr << "Error: expected " << 42 << "!\n"; - exit(1); - } - =} + reaction(in) {= + received = true; + std::cout << "Received " << *in.get() << '\n'; + if (*in.get() != 42) { + std::cerr << "Error: expected " << 42 << "!\n"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: Sink " << bank_index << " didn't receive anything.\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: Sink " << bank_index << " didn't receive anything.\n"; + exit(2); + } + =} } main reactor { - source = new Source() - sink = new[4] Sink() - (source.out)+ -> sink.in + source = new Source() + sink = new[4] Sink() + (source.out)+ -> sink.in } diff --git a/test/Cpp/src/multiport/BroadcastAfter.lf b/test/Cpp/src/multiport/BroadcastAfter.lf index 6cb7f84f4d..73cccc1904 100644 --- a/test/Cpp/src/multiport/BroadcastAfter.lf +++ b/test/Cpp/src/multiport/BroadcastAfter.lf @@ -1,41 +1,41 @@ target Cpp { - fast: true + fast: true } reactor Source { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(42); =} + reaction(startup) -> out {= out.set(42); =} } reactor Sink(bank_index: size_t = 0) { - input in: unsigned - state received: bool = false + input in: unsigned + state received: bool = false - reaction(in) {= - std::cout << bank_index << " received " << *in.get() << '\n'; - if (*in.get() != 42) { - std::cerr << "Error: expected " << 42 << "!\n"; - exit(1); - } - if (get_elapsed_logical_time() != 1s) { - std::cerr << "ERROR: Expected to receive input after one second.\n"; - exit(2); - } - received = true; - =} + reaction(in) {= + std::cout << bank_index << " received " << *in.get() << '\n'; + if (*in.get() != 42) { + std::cerr << "Error: expected " << 42 << "!\n"; + exit(1); + } + if (get_elapsed_logical_time() != 1s) { + std::cerr << "ERROR: Expected to receive input after one second.\n"; + exit(2); + } + received = true; + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor { - source = new Source() - sink = new[4] Sink() - (source.out)+ -> sink.in after 1 sec + source = new Source() + sink = new[4] Sink() + (source.out)+ -> sink.in after 1 sec } diff --git a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf index 065e9bf403..f24a5f7c8c 100644 --- a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf @@ -1,44 +1,44 @@ target Cpp { - fast: true + fast: true } reactor Source(value: unsigned = 42) { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(value); =} + reaction(startup) -> out {= out.set(value); =} } reactor Sink(bank_index: size_t = 0) { - input in: unsigned - state received: bool = false + input in: unsigned + state received: bool = false - reaction(in) {= - std::cout << bank_index << " received " << *in.get() << '\n'; - auto expected = (bank_index % 3) + 1; - if (*in.get() != expected) { - std::cerr << "Error: expected " << expected << "!\n"; - exit(1); - } - if (get_elapsed_logical_time() != 1s) { - std::cerr << "ERROR: Expected to receive input after one second.\n"; - exit(2); - } - received = true; - =} + reaction(in) {= + std::cout << bank_index << " received " << *in.get() << '\n'; + auto expected = (bank_index % 3) + 1; + if (*in.get() != expected) { + std::cerr << "Error: expected " << expected << "!\n"; + exit(1); + } + if (get_elapsed_logical_time() != 1s) { + std::cerr << "ERROR: Expected to receive input after one second.\n"; + exit(2); + } + received = true; + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor { - source1 = new Source(value = 1) - source2 = new Source(value = 2) - source3 = new Source(value = 3) - sink = new[9] Sink() - (source1.out, source2.out, source3.out)+ -> sink.in after 1 sec + source1 = new Source(value = 1) + source2 = new Source(value = 2) + source3 = new Source(value = 3) + sink = new[9] Sink() + (source1.out, source2.out, source3.out)+ -> sink.in after 1 sec } diff --git a/test/Cpp/src/multiport/FullyConnected.lf b/test/Cpp/src/multiport/FullyConnected.lf index 0b0a66405e..09826be5f2 100644 --- a/test/Cpp/src/multiport/FullyConnected.lf +++ b/test/Cpp/src/multiport/FullyConnected.lf @@ -1,42 +1,42 @@ target Cpp reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { - input[num_nodes] in: size_t - output out: size_t + input[num_nodes] in: size_t + output out: size_t - state received: bool = false + state received: bool = false - reaction(startup) -> out {= - std::cout << "Hello from node " << bank_index << "!\n"; - // broadcast my ID to everyone - out.set(bank_index); - =} + reaction(startup) -> out {= + std::cout << "Hello from node " << bank_index << "!\n"; + // broadcast my ID to everyone + out.set(bank_index); + =} - reaction(in) {= - std::cout << "Node " << bank_index << " received messages from "; - received = true; - size_t count{0}; - for (auto i: in.present_indices_unsorted()) { - count++; - std::cout << *in[i].get() << ", "; - } + reaction(in) {= + std::cout << "Node " << bank_index << " received messages from "; + received = true; + size_t count{0}; + for (auto i: in.present_indices_unsorted()) { + count++; + std::cout << *in[i].get() << ", "; + } - std::cout << '\n'; - if (count != num_nodes) { - std::cerr << "ERROR: received less messages than expected!"; - exit(1); - } - =} + std::cout << '\n'; + if (count != num_nodes) { + std::cerr << "ERROR: received less messages than expected!"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: received no input!\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: received no input!\n"; + exit(2); + } + =} } main reactor(num_nodes: size_t = 4) { - nodes = new[num_nodes] Node(num_nodes = num_nodes) - (nodes.out)+ -> nodes.in + nodes = new[num_nodes] Node(num_nodes = num_nodes) + (nodes.out)+ -> nodes.in } diff --git a/test/Cpp/src/multiport/FullyConnectedAddressable.lf b/test/Cpp/src/multiport/FullyConnectedAddressable.lf index 5385c44222..ed148437a5 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressable.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressable.lf @@ -2,49 +2,49 @@ target Cpp reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { - input[num_nodes] in: size_t - output[num_nodes] out: size_t - - state received: bool = false - - reaction(startup) -> out {= - std::cout << "Hello from node " << bank_index << "!\n"; - // send my ID only to my right neighbour - out[(bank_index + 1) % num_nodes].set(bank_index); - =} - - reaction(in) {= - std::cout << "Node " << bank_index << " received messages from "; - received = true; - size_t count{0}; - size_t result{0}; - for (auto i : in.present_indices_unsorted()) { - count++; - result = *in[i].get(); - std::cout << result << ", "; - } - - std::cout << '\n'; - - size_t expected = bank_index == 0 ? num_nodes - 1 : bank_index - 1; - if (count != 1 || result != expected) { - std::cerr << "ERROR: received an unexpected message!\n"; - exit(1); - } - =} - - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: received no input!\n"; - exit(2); - } - =} + input[num_nodes] in: size_t + output[num_nodes] out: size_t + + state received: bool = false + + reaction(startup) -> out {= + std::cout << "Hello from node " << bank_index << "!\n"; + // send my ID only to my right neighbour + out[(bank_index + 1) % num_nodes].set(bank_index); + =} + + reaction(in) {= + std::cout << "Node " << bank_index << " received messages from "; + received = true; + size_t count{0}; + size_t result{0}; + for (auto i : in.present_indices_unsorted()) { + count++; + result = *in[i].get(); + std::cout << result << ", "; + } + + std::cout << '\n'; + + size_t expected = bank_index == 0 ? num_nodes - 1 : bank_index - 1; + if (count != 1 || result != expected) { + std::cerr << "ERROR: received an unexpected message!\n"; + exit(1); + } + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: received no input!\n"; + exit(2); + } + =} } main reactor(num_nodes: size_t = 4) { - nodes1 = new[num_nodes] Node(num_nodes = num_nodes) - nodes1.out -> interleaved (nodes1.in) + nodes1 = new[num_nodes] Node(num_nodes = num_nodes) + nodes1.out -> interleaved (nodes1.in) - nodes2 = new[num_nodes] Node(num_nodes = num_nodes) - interleaved (nodes2.out) -> nodes2.in + nodes2 = new[num_nodes] Node(num_nodes = num_nodes) + interleaved (nodes2.out) -> nodes2.in } diff --git a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf index c6fcb4c9e6..e33511a41a 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf @@ -4,9 +4,9 @@ target Cpp import Node from "FullyConnectedAddressable.lf" main reactor(num_nodes: size_t = 4) { - nodes1 = new[num_nodes] Node(num_nodes = num_nodes) - nodes1.out -> interleaved (nodes1.in) after 200 msec + nodes1 = new[num_nodes] Node(num_nodes = num_nodes) + nodes1.out -> interleaved (nodes1.in) after 200 msec - nodes2 = new[num_nodes] Node(num_nodes = num_nodes) - interleaved (nodes2.out) -> nodes2.in after 400 msec + nodes2 = new[num_nodes] Node(num_nodes = num_nodes) + interleaved (nodes2.out) -> nodes2.in after 400 msec } diff --git a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf index 964e2e7095..70b89fa728 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf @@ -2,71 +2,70 @@ * This test was first described by Peter Donovan in * https://github.com/lf-lang/lingua-franca/issues/1321 * - * It simply tests if passthrough connections work as expected in the C++ - * target. Such a connection directly connects an input to an output of the same - * reactor, without any reactions in between. + * It simply tests if passthrough connections work as expected in the C++ target. Such a connection + * directly connects an input to an output of the same reactor, without any reactions in between. */ target Cpp reactor ReactorWithMultiport(width: size_t = 3) { - output[width] out: int + output[width] out: int - reaction(startup) -> out {= - for (size_t i{0}; i < width; i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (size_t i{0}; i < width; i++) { + out[i].set(i); + } + =} } reactor MultiportSplitter(width: size_t = 3) { - input[width] in: int + input[width] in: int - output out0: int - output out1: int - output out2: int + output out0: int + output out1: int + output out2: int - in -> out0, out1, out2 + in -> out0, out1, out2 } main reactor IndexIntoMultiportOutput { - source = new ReactorWithMultiport() - splitter = new MultiportSplitter() + source = new ReactorWithMultiport() + splitter = new MultiportSplitter() - source.out -> splitter.in + source.out -> splitter.in - state received0: bool = false - state received1: bool = false - state received2: bool = false + state received0: bool = false + state received1: bool = false + state received2: bool = false - reaction(splitter.out0) {= - received0 = true; - if (*splitter.out0.get() != 0) { - reactor::log::Error() << "expeced 0"; - exit(1); - } - =} + reaction(splitter.out0) {= + received0 = true; + if (*splitter.out0.get() != 0) { + reactor::log::Error() << "expeced 0"; + exit(1); + } + =} - reaction(splitter.out1) {= - received1 = true; - if (*splitter.out1.get() != 1) { - reactor::log::Error() << "expeced 1"; - exit(1); - } - =} + reaction(splitter.out1) {= + received1 = true; + if (*splitter.out1.get() != 1) { + reactor::log::Error() << "expeced 1"; + exit(1); + } + =} - reaction(splitter.out2) {= - received2 = true; - if (*splitter.out2.get() != 2) { - reactor::log::Error() << "expeced 2"; - exit(1); - } - =} + reaction(splitter.out2) {= + received2 = true; + if (*splitter.out2.get() != 2) { + reactor::log::Error() << "expeced 2"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received0 || !received1 || !received2) { - reactor::log::Error() << "missed a message"; - } else { - reactor::log::Info() << "success"; - } - =} + reaction(shutdown) {= + if (!received0 || !received1 || !received2) { + reactor::log::Error() << "missed a message"; + } else { + reactor::log::Info() << "success"; + } + =} } diff --git a/test/Cpp/src/multiport/Multiport.lf b/test/Cpp/src/multiport/Multiport.lf index a63924c67c..32bc20b810 100644 --- a/test/Cpp/src/multiport/Multiport.lf +++ b/test/Cpp/src/multiport/Multiport.lf @@ -1,66 +1,65 @@ -// The Multiport tests the present_indices_unsorted() function in the -// reactor::Multiport class. This method returnes all present ports this test -// checks if the returned list of indices is correctly generated by the runtime. -// For that we manually recreate this list and check if they are identical. If -// they are not identical the Multiport and Port Class do not correctly exchange +// The Multiport tests the present_indices_unsorted() function in the reactor::Multiport class. This +// method returnes all present ports this test checks if the returned list of indices is correctly +// generated by the runtime. For that we manually recreate this list and check if they are +// identical. If they are not identical the Multiport and Port Class do not correctly exchange // information. // // Author: Tassilo Tanneberger target Cpp reactor Test { - input[3000] sink: void - output[3000] source: void + input[3000] sink: void + output[3000] source: void - reaction(sink) -> source {= - for (auto i: sink.present_indices_unsorted()) { - source[i].set(); - } - =} + reaction(sink) -> source {= + for (auto i: sink.present_indices_unsorted()) { + source[i].set(); + } + =} } main reactor Multiport { - test = new Test() - state received: bool = false + test = new Test() + state received: bool = false - reaction(startup) -> test.sink {= - for (auto i = 0; i < 30; i++) { - auto semi_random_index = (i * 100) % 3000; - test.sink[semi_random_index].set(); - } - =} + reaction(startup) -> test.sink {= + for (auto i = 0; i < 30; i++) { + auto semi_random_index = (i * 100) % 3000; + test.sink[semi_random_index].set(); + } + =} - reaction(test.source) {= - received = true; - std::vector positions; + reaction(test.source) {= + received = true; + std::vector positions; - for (auto i = 0; i < 30; i++) { - auto semi_random_index = (i * 100) % 3000; - positions.push_back(semi_random_index); - } + for (auto i = 0; i < 30; i++) { + auto semi_random_index = (i * 100) % 3000; + positions.push_back(semi_random_index); + } - auto received_indices = test.source.present_indices_unsorted(); + auto received_indices = test.source.present_indices_unsorted(); - if (positions.size() != received_indices.size()) { - std::cerr << "positions size:" << positions.size() - << " indices size:" << received_indices.size() << std::endl; - throw std::runtime_error("not matching sizes"); - } + if (positions.size() != received_indices.size()) { + std::cerr << "positions size:" << positions.size() + << " indices size:" << received_indices.size() << std::endl; + throw std::runtime_error("not matching sizes"); + } - for (auto i = 0; i < positions.size(); i++) { - if (positions[i] != received_indices[i]) { - std::cerr << "mismatch detected:" << positions[i] << " and " << received_indices[i] << std::endl; - throw std::runtime_error("indices do not match"); - } + for (auto i = 0; i < positions.size(); i++) { + if (positions[i] != received_indices[i]) { + std::cerr << "mismatch detected:" << positions[i] << " and " << received_indices[i] << std::endl; + throw std::runtime_error("indices do not match"); } + } - std::cout << "[SUCCESS] all indices match" << std::endl; - =} + std::cout << "[SUCCESS] all indices match" << std::endl; + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: received no input!\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: received no input!\n"; + exit(2); + } + =} } diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index b7339a9184..65d3554b3f 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -1,42 +1,42 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(bank_index: size_t = 0) { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(bank_index); =} + reaction(startup) -> out {= out.set(bank_index); =} } reactor Destination(port_width: size_t = 2) { - input[port_width] in: unsigned - state received: bool = false + input[port_width] in: unsigned + state received: bool = false - reaction(in) {= - for (size_t i = 0; i < in.size(); i++) { - std::cout << "Destination channel " << i << " received " << *in[i].get() << ".\n"; - if (i != *in[i].get()) { - std::cerr << "ERROR: Expected " << i << ".\n"; - exit(1); - } - } - received = true; - =} - - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination received no input!\n"; + reaction(in) {= + for (size_t i = 0; i < in.size(); i++) { + std::cout << "Destination channel " << i << " received " << *in[i].get() << ".\n"; + if (i != *in[i].get()) { + std::cerr << "ERROR: Expected " << i << ".\n"; exit(1); } - std::cout << "Success.\n"; - =} + } + received = true; + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor(width: size_t = 4) { - a = new[width] Source() - b = new Destination(port_width = width) - a.out -> b.in + a = new[width] Source() + b = new Destination(port_width = width) + a.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf index 673ef6889a..3814b6c510 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf @@ -1,48 +1,48 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(bank_index: size_t = 0) { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(bank_index); =} + reaction(startup) -> out {= out.set(bank_index); =} } reactor Container { - output[3] out: unsigned - s = new[3] Source() - s.out -> out + output[3] out: unsigned + s = new[3] Source() + s.out -> out } reactor Destination { - input[3] in: unsigned - state received: bool = false + input[3] in: unsigned + state received: bool = false - reaction(in) {= - for (size_t i = 0; i < in.size(); i++) { - std::cout << "Destination channel " << i << " received " << *in[i].get() << ".\n"; - if (i != *in[i].get()) { - std::cerr << "ERROR: Expected " << i << ".\n"; - exit(1); - } - } - received = true; - =} - - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination received no input!\n"; + reaction(in) {= + for (size_t i = 0; i < in.size(); i++) { + std::cout << "Destination channel " << i << " received " << *in[i].get() << ".\n"; + if (i != *in[i].get()) { + std::cerr << "ERROR: Expected " << i << ".\n"; exit(1); } - std::cout << "Success.\n"; - =} + } + received = true; + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor { - a = new Container() - b = new Destination() - a.out -> b.in + a = new Container() + b = new Destination() + a.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index fe27c74f35..d745d5ebd0 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,53 +1,53 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(bank_index: size_t = 0) { - output out: int + output out: int - reaction(startup) -> out {= out.set(bank_index); =} + reaction(startup) -> out {= out.set(bank_index); =} } reactor Container { - output[3] out: int - s = new[3] Source() - s.out -> out + output[3] out: int + s = new[3] Source() + s.out -> out } reactor Destination { - input[3] in: int - state received: bool = false + input[3] in: int + state received: bool = false - reaction(in) {= - for (int i = 0; i < in.size(); i++) { - int value = *in[i].get(); - std::cout << "Destination channel " << i << " received " << value << '\n'; - if (i != value) { - std::cerr << "ERROR: Expected " << i << '\n'; - exit(1); - } - } - if (get_elapsed_logical_time() != 1s) { - std::cerr << "ERROR: Expected to receive input after one second.\n"; - exit(2); - } - received = true; - =} - - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination received no input!\n"; + reaction(in) {= + for (int i = 0; i < in.size(); i++) { + int value = *in[i].get(); + std::cout << "Destination channel " << i << " received " << value << '\n'; + if (i != value) { + std::cerr << "ERROR: Expected " << i << '\n'; exit(1); } - std::cout << "Success.\n"; - =} + } + if (get_elapsed_logical_time() != 1s) { + std::cerr << "ERROR: Expected to receive input after one second.\n"; + exit(2); + } + received = true; + =} + + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor MultiportFromBankHierarchyAfter { - a = new Container() - b = new Destination() - a.out -> b.in after 1 sec + a = new Container() + b = new Destination() + a.out -> b.in after 1 sec } diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index fae914b609..21726e1238 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -1,63 +1,62 @@ -// Check multiport output to multiport input, where the former is a hierarchical -// reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[4] out: int - state s: int = 0 - - reaction(t) -> out {= - for(int i = 0; i < 4; i++) { - out[i].set(s++); - } - =} + timer t(0, 200 msec) + output[4] out: int + state s: int = 0 + + reaction(t) -> out {= + for(int i = 0; i < 4; i++) { + out[i].set(s++); + } + =} } reactor Destination { - state s: int = 6 - input[4] in: int - - reaction(in) {= - int sum = 0; - for (auto i : in.present_indices_unsorted()) { - sum += *in[i].get(); - } - - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 16; - =} - - reaction(shutdown) {= - if (s <= 6) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + state s: int = 6 + input[4] in: int + + reaction(in) {= + int sum = 0; + for (auto i : in.present_indices_unsorted()) { + sum += *in[i].get(); + } + + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 16; + =} + + reaction(shutdown) {= + if (s <= 6) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } reactor Container { - output[4] out: int - src = new InsideContainer() - src.out -> out + output[4] out: int + src = new InsideContainer() + src.out -> out } reactor InsideContainer { - output[4] out: int - src = new Source() - src.out -> out + output[4] out: int + src = new Source() + src.out -> out } main reactor MultiportFromHierarchy { - a = new Container() - b = new Destination() - a.out -> b.in + a = new Container() + b = new Destination() + a.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index 39fce6f8ff..5e6750a886 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -1,61 +1,61 @@ -// This is a version fo the Threaded test that uses a multiport input at the -// destination. Its purpose is to test multiport inputs. +// This is a version fo the Threaded test that uses a multiport input at the destination. Its +// purpose is to test multiport inputs. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output out: int - state s: int = 0 + timer t(0, 200 msec) + output out: int + state s: int = 0 - reaction(t) -> out {= out.set(s++); =} + reaction(t) -> out {= out.set(s++); =} } reactor Computation { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= out.set(*in.get()); =} + reaction(in) -> out {= out.set(*in.get()); =} } reactor Destination { - state s: int = 0 - input[4] in: int - - reaction(in) {= - int sum = 0; - for (int i = 0; i < in.size(); i++) { - sum += *in[i].get(); - } - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 4; - =} - - reaction(shutdown) {= - if (s == 0) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + state s: int = 0 + input[4] in: int + + reaction(in) {= + int sum = 0; + for (int i = 0; i < in.size(); i++) { + sum += *in[i].get(); + } + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 4; + =} + + reaction(shutdown) {= + if (s == 0) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor MultiportIn { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1.in - a.out -> t2.in - a.out -> t3.in - a.out -> t4.in - t1.out, t2.out, t3.out, t4.out -> b.in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1.in + a.out -> t2.in + a.out -> t3.in + a.out -> t4.in + t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportMultipleSet.lf b/test/Cpp/src/multiport/MultiportMultipleSet.lf index ca7495cc91..74ef376070 100644 --- a/test/Cpp/src/multiport/MultiportMultipleSet.lf +++ b/test/Cpp/src/multiport/MultiportMultipleSet.lf @@ -1,60 +1,60 @@ target Cpp { - timeout: 1 s + timeout: 1 s } reactor Producer { - timer t(0, 100 ms) + timer t(0, 100 ms) - output[10] out: int + output[10] out: int - state odd: bool(true) + state odd: bool(true) - reaction(t) -> out {= - for (int i{odd ? 1 : 0}; i < 10; i += 2) { - for (int j{0}; j < 10; j++) { - out[i].set(j); - } + reaction(t) -> out {= + for (int i{odd ? 1 : 0}; i < 10; i += 2) { + for (int j{0}; j < 10; j++) { + out[i].set(j); } + } - odd = !odd; - =} + odd = !odd; + =} } reactor Consumer { - state odd: bool(true) - input[10] in: int - - reaction(in) {= - int count = 0; - int last = -1; - - for (int i : in.present_indices_unsorted()) { - count++; - if (odd && i%2 == 0) { - reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; - exit(1); - } - if (!odd && i%2 == 1) { - reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; - exit(2); - } - if (9 != *in[i].get()) { - reactor::log::Error() << "Expected 9 but got " << *in[i].get(); - exit(3); - } + state odd: bool(true) + input[10] in: int + + reaction(in) {= + int count = 0; + int last = -1; + + for (int i : in.present_indices_unsorted()) { + count++; + if (odd && i%2 == 0) { + reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; + exit(1); } - if (count != 5) { - reactor::log::Error() << "Expected count to be 5, but got " << count; - exit(4); + if (!odd && i%2 == 1) { + reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; + exit(2); } - - odd = !odd; - =} + if (9 != *in[i].get()) { + reactor::log::Error() << "Expected 9 but got " << *in[i].get(); + exit(3); + } + } + if (count != 5) { + reactor::log::Error() << "Expected count to be 5, but got " << count; + exit(4); + } + + odd = !odd; + =} } main reactor { - c = new Consumer() - p = new Producer() + c = new Consumer() + p = new Producer() - p.out -> c.in + p.out -> c.in } diff --git a/test/Cpp/src/multiport/MultiportOut.lf b/test/Cpp/src/multiport/MultiportOut.lf index 53f2a5bb23..1e03e75fdb 100644 --- a/test/Cpp/src/multiport/MultiportOut.lf +++ b/test/Cpp/src/multiport/MultiportOut.lf @@ -1,68 +1,68 @@ // Check multiport capabilities on Outputs. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[4] out: int - state s: int = 0 + timer t(0, 200 msec) + output[4] out: int + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < 4; i++) { - out[i].set(s); - } - s++; - =} + reaction(t) -> out {= + for(int i = 0; i < 4; i++) { + out[i].set(s); + } + s++; + =} } reactor Computation { - input in: int - output out: int + input in: int + output out: int - reaction(in) -> out {= - // No need to sleep for this test. - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - out.set(*in.get()); - =} + reaction(in) -> out {= + // No need to sleep for this test. + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + out.set(*in.get()); + =} } reactor Destination { - state s: int = 0 - input[4] in: int + state s: int = 0 + input[4] in: int - reaction(in) {= - int sum = 0; - for (auto i : in.present_indices_unsorted()) { - sum += *in[i].get(); - } - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 4; - =} + reaction(in) {= + int sum = 0; + for (auto i : in.present_indices_unsorted()) { + sum += *in[i].get(); + } + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 4; + =} - reaction(shutdown) {= - if (s == 0) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (s == 0) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1.in, t2.in, t3.in, t4.in - t1.out, t2.out, t3.out, t4.out -> b.in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1.in, t2.in, t3.in, t4.in + t1.out, t2.out, t3.out, t4.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportToBank.lf b/test/Cpp/src/multiport/MultiportToBank.lf index fa2f79419f..adb7b73b34 100644 --- a/test/Cpp/src/multiport/MultiportToBank.lf +++ b/test/Cpp/src/multiport/MultiportToBank.lf @@ -1,29 +1,29 @@ target Cpp reactor Source { - output[4] out: unsigned + output[4] out: unsigned - reaction(startup) -> out {= - for (unsigned i = 0 ; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (unsigned i = 0 ; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Sink(bank_index: size_t = 0) { - input in: unsigned + input in: unsigned - reaction(in) {= - std::cout << "Received " << *in.get() << '\n'; - if (*in.get() != bank_index) { - std::cerr << "Error: expected " << bank_index << "!\n"; - exit(1); - } - =} + reaction(in) {= + std::cout << "Received " << *in.get() << '\n'; + if (*in.get() != bank_index) { + std::cerr << "Error: expected " << bank_index << "!\n"; + exit(1); + } + =} } main reactor MultiportToBank { - source = new Source() - sink = new[4] Sink() - source.out -> sink.in + source = new Source() + sink = new[4] Sink() + source.out -> sink.in } diff --git a/test/Cpp/src/multiport/MultiportToBankAfter.lf b/test/Cpp/src/multiport/MultiportToBankAfter.lf index c05730680f..423d9ee433 100644 --- a/test/Cpp/src/multiport/MultiportToBankAfter.lf +++ b/test/Cpp/src/multiport/MultiportToBankAfter.lf @@ -1,33 +1,33 @@ target Cpp reactor Source { - output[4] out: unsigned + output[4] out: unsigned - reaction(startup) -> out {= - for (unsigned i = 0 ; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (unsigned i = 0 ; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Sink(bank_index: size_t = 0) { - input in: unsigned + input in: unsigned - reaction(in) {= - std::cout << "Received " << *in.get() << '\n'; - if (*in.get() != bank_index) { - std::cerr << "Error: expected " << bank_index << "!\n"; - exit(1); - } - if (get_elapsed_logical_time() != 1s) { - std::cerr << "ERROR: Expected to receive input after one second.\n"; - exit(2); - } - =} + reaction(in) {= + std::cout << "Received " << *in.get() << '\n'; + if (*in.get() != bank_index) { + std::cerr << "Error: expected " << bank_index << "!\n"; + exit(1); + } + if (get_elapsed_logical_time() != 1s) { + std::cerr << "ERROR: Expected to receive input after one second.\n"; + exit(2); + } + =} } main reactor MultiportToBankAfter { - source = new Source() - sink = new[4] Sink() - source.out -> sink.in after 1 sec + source = new Source() + sink = new[4] Sink() + source.out -> sink.in after 1 sec } diff --git a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf index f9cef6a676..e58531e70c 100644 --- a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf @@ -1,50 +1,50 @@ -// Check multiport output to bank of recipients. Here, the bank is smaller than -// the width of the sending port. +// Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +// sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[3] out: unsigned + output[3] out: unsigned - reaction(startup) -> out {= - for(size_t i = 0; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for(size_t i = 0; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Destination(bank_index: size_t = 0) { - input in: unsigned - state received: bool = false + input in: unsigned + state received: bool = false - reaction(in) {= - std::cout << "Destination " << bank_index << " received " << *in.get() << ".\n"; - if (bank_index != *in.get()) { - std::cerr << "ERROR: Expected " << bank_index << ".\n"; - exit(1); - } - received = true; - =} + reaction(in) {= + std::cout << "Destination " << bank_index << " received " << *in.get() << ".\n"; + if (bank_index != *in.get()) { + std::cerr << "ERROR: Expected " << bank_index << ".\n"; + exit(1); + } + received = true; + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } reactor Container { - input[3] in: unsigned - c = new[3] Destination() - in -> c.in + input[3] in: unsigned + c = new[3] Destination() + in -> c.in } main reactor MultiportToBankHierarchy { - a = new Source() - b = new Container() - a.out -> b.in + a = new Source() + b = new Container() + a.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index 573a0e06da..6e7a8e757b 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -1,58 +1,57 @@ -// Check multiport output to multiport input, where the latter is a hierarchical -// reactor. Note that the destination reactor has width wider than the sender, -// so one input is dangling. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +// the destination reactor has width wider than the sender, so one input is dangling. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width: size_t = 4) { - timer t(0, 200 msec) - output[width] out: int - state s: int = 0 - - reaction(t) -> out {= - for(size_t i = 0; i < 4; i++) { - out[i].set(s++); - } - =} + timer t(0, 200 msec) + output[width] out: int + state s: int = 0 + + reaction(t) -> out {= + for(size_t i = 0; i < 4; i++) { + out[i].set(s++); + } + =} } reactor Destination(width: size_t = 4) { - state s: int = 6 - input[width] in: int - - reaction(in) {= - int sum = 0; - for (auto i : in.present_indices_unsorted()) { - sum += *in[i].get(); - } - - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 16; - =} - - reaction(shutdown) {= - if (s <= 6) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + state s: int = 6 + input[width] in: int + + reaction(in) {= + int sum = 0; + for (auto i : in.present_indices_unsorted()) { + sum += *in[i].get(); + } + + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 16; + =} + + reaction(shutdown) {= + if (s <= 6) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } reactor Container(width: size_t = 4) { - input[width] in: int - dst = new Destination() - in -> dst.in + input[width] in: int + dst = new Destination() + in -> dst.in } main reactor MultiportToHierarchy(width: size_t = 4) { - a = new Source(width = width) - b = new Container(width = width) - a.out -> b.in + a = new Source(width = width) + b = new Container(width = width) + a.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportToMultiport.lf b/test/Cpp/src/multiport/MultiportToMultiport.lf index 37a1ee5222..b018299508 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport.lf @@ -1,40 +1,40 @@ target Cpp reactor Source { - output[4] out: unsigned + output[4] out: unsigned - reaction(startup) -> out {= - for (unsigned i = 0; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (unsigned i = 0; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Sink { - input[4] in: unsigned - state received: bool = false + input[4] in: unsigned + state received: bool = false - reaction(in) {= - for (unsigned i = 0; i < in.size(); i++) { - std::cout << "Received " << *in[i].get() << '\n'; - received = true; - if (*in[i].get() != i) { - std::cerr << "Error: expected " << i << "!\n"; - exit(1); - } + reaction(in) {= + for (unsigned i = 0; i < in.size(); i++) { + std::cout << "Received " << *in[i].get() << '\n'; + received = true; + if (*in[i].get() != i) { + std::cerr << "Error: expected " << i << "!\n"; + exit(1); } - =} + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "Error: No data received!\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "Error: No data received!\n"; + exit(2); + } + =} } main reactor MultiportToMultiport { - source = new Source() - sink = new Sink() - source.out -> sink.in + source = new Source() + sink = new Sink() + source.out -> sink.in } diff --git a/test/Cpp/src/multiport/MultiportToMultiport2.lf b/test/Cpp/src/multiport/MultiportToMultiport2.lf index 165f3201ce..eafe9fee3c 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2.lf @@ -2,35 +2,35 @@ target Cpp reactor Source(width: size_t = 2) { - output[width] out: size_t + output[width] out: size_t - reaction(startup) -> out {= - for (size_t i = 0; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (size_t i = 0; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Destination(width: size_t = 2) { - input[width] in: size_t + input[width] in: size_t - reaction(in) {= - for (auto i: in.present_indices_unsorted()) { - size_t value = *in[i].get(); - std::cout << "Received on channel " << i << ": " << value << '\n'; - // NOTE: For testing purposes, this assumes the specific - // widths instantiated below. - if (value != i % 3) { - std::cerr << "ERROR: expected " << i % 3 << '\n'; - exit(1); - } + reaction(in) {= + for (auto i: in.present_indices_unsorted()) { + size_t value = *in[i].get(); + std::cout << "Received on channel " << i << ": " << value << '\n'; + // NOTE: For testing purposes, this assumes the specific + // widths instantiated below. + if (value != i % 3) { + std::cerr << "ERROR: expected " << i % 3 << '\n'; + exit(1); } - =} + } + =} } main reactor MultiportToMultiport2 { - a1 = new Source(width = 3) - a2 = new Source(width = 2) - b = new Destination(width = 5) - a1.out, a2.out -> b.in + a1 = new Source(width = 3) + a2 = new Source(width = 2) + b = new Destination(width = 5) + a1.out, a2.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportToMultiport2After.lf b/test/Cpp/src/multiport/MultiportToMultiport2After.lf index 781275b2f4..ed64200076 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2After.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2After.lf @@ -2,41 +2,41 @@ target Cpp reactor Source(width: size_t = 2) { - output[width] out: size_t + output[width] out: size_t - reaction(startup) -> out {= - for (size_t i = 0; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (size_t i = 0; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Destination(width: size_t = 2) { - input[width] in: size_t + input[width] in: size_t - reaction(in) {= - for (size_t i = 0; i < in.size(); i++) { - if (in[i].is_present()) { - size_t value = *in[i].get(); - std::cout << "Received on channel " << i << ": " << value << '\n'; - // NOTE: For testing purposes, this assumes the specific - // widths instantiated below. - if (value != i % 3) { - std::cerr << "ERROR: expected " << i % 3 << '\n'; - exit(1); - } + reaction(in) {= + for (size_t i = 0; i < in.size(); i++) { + if (in[i].is_present()) { + size_t value = *in[i].get(); + std::cout << "Received on channel " << i << ": " << value << '\n'; + // NOTE: For testing purposes, this assumes the specific + // widths instantiated below. + if (value != i % 3) { + std::cerr << "ERROR: expected " << i % 3 << '\n'; + exit(1); } } - if (get_elapsed_logical_time() != 1s) { - std::cerr << "ERROR: Expected to receive input after one second.\n"; - exit(2); - } - =} + } + if (get_elapsed_logical_time() != 1s) { + std::cerr << "ERROR: Expected to receive input after one second.\n"; + exit(2); + } + =} } main reactor { - a1 = new Source(width = 3) - a2 = new Source(width = 2) - b = new Destination(width = 5) - a1.out, a2.out -> b.in after 1 sec + a1 = new Source(width = 3) + a2 = new Source(width = 2) + b = new Destination(width = 5) + a1.out, a2.out -> b.in after 1 sec } diff --git a/test/Cpp/src/multiport/MultiportToMultiportArray.lf b/test/Cpp/src/multiport/MultiportToMultiportArray.lf index 6c96d17150..fce25b346b 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportArray.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportArray.lf @@ -1,60 +1,59 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[2] out: int[3] - state s: int = 0 + timer t(0, 200 msec) + output[2] out: int[3] + state s: int = 0 - reaction(t) -> out {= - for(int i = 0; i < 2; i++) { - // Dynamically allocate a new output array - auto a = reactor::make_mutable_value>(); - // initialize it - (*a)[0] = s++; - (*a)[1] = s++; - (*a)[2] = s++; - // and send it - out[i].set(std::move(a)); - } - =} + reaction(t) -> out {= + for(int i = 0; i < 2; i++) { + // Dynamically allocate a new output array + auto a = reactor::make_mutable_value>(); + // initialize it + (*a)[0] = s++; + (*a)[1] = s++; + (*a)[2] = s++; + // and send it + out[i].set(std::move(a)); + } + =} } reactor Destination { - state s: int = 15 - input[2] in: int[3] + state s: int = 15 + input[2] in: int[3] - reaction(in) {= - int sum = 0; - for (auto i : in.present_indices_unsorted()) { - const auto& a = *in[i].get(); - for (int j = 0; j < a.size(); j++) { - sum += a[j]; - } - } - std::cout << "Sum of received: " << sum << '\n'; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << '\n'; - exit(1); + reaction(in) {= + int sum = 0; + for (auto i : in.present_indices_unsorted()) { + const auto& a = *in[i].get(); + for (int j = 0; j < a.size(); j++) { + sum += a[j]; } - s += 36; - =} + } + std::cout << "Sum of received: " << sum << '\n'; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << '\n'; + exit(1); + } + s += 36; + =} - reaction(shutdown) {= - if (s <= 15) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (s <= 15) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor MultiportToMultiportArray { - a = new Source() - b = new Destination() - a.out -> b.in + a = new Source() + b = new Destination() + a.out -> b.in } diff --git a/test/Cpp/src/multiport/MultiportToMultiportPhysical.lf b/test/Cpp/src/multiport/MultiportToMultiportPhysical.lf index 43cdcbc713..7418bee409 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportPhysical.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportPhysical.lf @@ -1,44 +1,44 @@ target Cpp reactor Source { - output[4] out: unsigned + output[4] out: unsigned - reaction(startup) -> out {= - for (unsigned i = 0; i < out.size(); i++) { - out[i].set(i); - } - =} + reaction(startup) -> out {= + for (unsigned i = 0; i < out.size(); i++) { + out[i].set(i); + } + =} } reactor Sink { - input[4] in: unsigned - state received: int(-1) + input[4] in: unsigned + state received: int(-1) - reaction(in) {= - auto present_ports = in.present_indices_unsorted(); - if (present_ports.size() != 1) { - reactor::log::Error() << "Expected only one value, but got " << present_ports.size(); - exit(1); - } - int idx = present_ports[0]; - std::cout << "Received " << *in[idx].get() << '\n'; - if (idx <= received) { - reactor::log::Error() << "Received index " << idx << " after " << received; - exit(2); - } - received = idx; - =} + reaction(in) {= + auto present_ports = in.present_indices_unsorted(); + if (present_ports.size() != 1) { + reactor::log::Error() << "Expected only one value, but got " << present_ports.size(); + exit(1); + } + int idx = present_ports[0]; + std::cout << "Received " << *in[idx].get() << '\n'; + if (idx <= received) { + reactor::log::Error() << "Received index " << idx << " after " << received; + exit(2); + } + received = idx; + =} - reaction(shutdown) {= - if (received != 3) { - std::cerr << "Error: No data received!\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (received != 3) { + std::cerr << "Error: No data received!\n"; + exit(2); + } + =} } main reactor { - source = new Source() - sink = new Sink() - source.out ~> sink.in + source = new Source() + sink = new Sink() + source.out ~> sink.in } diff --git a/test/Cpp/src/multiport/MultiportToPort.lf b/test/Cpp/src/multiport/MultiportToPort.lf index c2b0bd66ef..ed69542aa7 100644 --- a/test/Cpp/src/multiport/MultiportToPort.lf +++ b/test/Cpp/src/multiport/MultiportToPort.lf @@ -1,46 +1,45 @@ -// Check multiport output to multiport input. Destination port is wider than -// sending port. +// Check multiport output to multiport input. Destination port is wider than sending port. target Cpp { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[2] out: int + output[2] out: int - reaction(startup) -> out {= - for(int i = 0; i < out.size(); i++) { - std::cout << "Source sending " << i << ".\n"; - out[i].set(i); - } - =} + reaction(startup) -> out {= + for(int i = 0; i < out.size(); i++) { + std::cout << "Source sending " << i << ".\n"; + out[i].set(i); + } + =} } reactor Destination(expected: int = 0) { - input in: int - state received: bool = false + input in: int + state received: bool = false - reaction(in) {= - std::cout << "Received: " << *in.get() << ".\n"; - received = true; - if (*in.get() != expected) { - std::cerr << "ERROR: Expected " << expected << ".\n"; - exit(1); - } - =} + reaction(in) {= + std::cout << "Received: " << *in.get() << ".\n"; + received = true; + if (*in.get() != expected) { + std::cerr << "ERROR: Expected " << expected << ".\n"; + exit(1); + } + =} - reaction(shutdown) {= - if (!received) { - std::cerr << "ERROR: Destination received no input!\n"; - exit(1); - } - std::cout << "Success.\n"; - =} + reaction(shutdown) {= + if (!received) { + std::cerr << "ERROR: Destination received no input!\n"; + exit(1); + } + std::cout << "Success.\n"; + =} } main reactor MultiportToPort { - a = new Source() - b1 = new Destination() - b2 = new Destination(expected = 1) - a.out -> b1.in, b2.in + a = new Source() + b1 = new Destination() + b2 = new Destination(expected = 1) + a.out -> b1.in, b2.in } diff --git a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf index 6fa6dbb87b..329ac18ed7 100644 --- a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf @@ -1,70 +1,69 @@ -// Test reacting to and reading outputs from a contained reactor bank with a -// multiport +// Test reacting to and reading outputs from a contained reactor bank with a multiport target Cpp reactor Contained(bank_index: size_t = 0) { - output[3] out: unsigned + output[3] out: unsigned - reaction(startup) -> out {= - for (size_t i = 0; i < 3; i++) { - out[i].set(bank_index * i); - } - =} + reaction(startup) -> out {= + for (size_t i = 0; i < 3; i++) { + out[i].set(bank_index * i); + } + =} } main reactor { - c = new[3] Contained() - state count: int = 0 + c = new[3] Contained() + state count: int = 0 - reaction(startup) c.out {= - for (size_t i = 0; i < c.size(); i++) { - for (size_t j = 0; j < c[i].out.size(); j++) { - unsigned result = *c[i].out[j].get(); - std::cout << "Startup reaction reading output of contained " - << "reactor: " << result << std::endl; - if (result != i * j) { - std::cout << "FAILURE: expected " << i * j << std::endl; - exit(2); - } + reaction(startup) c.out {= + for (size_t i = 0; i < c.size(); i++) { + for (size_t j = 0; j < c[i].out.size(); j++) { + unsigned result = *c[i].out[j].get(); + std::cout << "Startup reaction reading output of contained " + << "reactor: " << result << std::endl; + if (result != i * j) { + std::cout << "FAILURE: expected " << i * j << std::endl; + exit(2); } } - count++; - =} + } + count++; + =} - reaction(c.out) {= - for (size_t i = 0; i < c.size(); i++) { - for (size_t j = 0; j < c[i].out.size(); j++) { - unsigned result = *c[i].out[j].get(); - std::cout << "Reading output of contained reactor: " << result << std::endl; - if (result != i * j) { - std::cout << "FAILURE: expected " << i * j << std::endl; - exit(2); - } + reaction(c.out) {= + for (size_t i = 0; i < c.size(); i++) { + for (size_t j = 0; j < c[i].out.size(); j++) { + unsigned result = *c[i].out[j].get(); + std::cout << "Reading output of contained reactor: " << result << std::endl; + if (result != i * j) { + std::cout << "FAILURE: expected " << i * j << std::endl; + exit(2); } } - count++; - =} + } + count++; + =} - reaction(startup, c.out) {= - for (size_t i = 0; i < c.size(); i++) { - for (size_t j = 0; j < c[i].out.size(); j++) { - unsigned result = *c[i].out[j].get(); - std::cout << "Alternate triggering reading output of contained " - << "reactor: " << result << std::endl; - if (result != i * j) { - std::cout << "FAILURE: expected " << i * j << std::endl; - exit(2); - } + reaction(startup, c.out) {= + for (size_t i = 0; i < c.size(); i++) { + for (size_t j = 0; j < c[i].out.size(); j++) { + unsigned result = *c[i].out[j].get(); + std::cout << "Alternate triggering reading output of contained " + << "reactor: " << result << std::endl; + if (result != i * j) { + std::cout << "FAILURE: expected " << i * j << std::endl; + exit(2); } } - count++; - =} + } + count++; + =} - reaction(shutdown) {= - if (count != 3) { - std::cerr << "ERROR: One of the reactions failed to trigger." - << std::endl; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 3) { + std::cerr << "ERROR: One of the reactions failed to trigger." + << std::endl; + exit(1); + } + =} } diff --git a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf index 18179b9086..b9a485ac7d 100644 --- a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf @@ -1,61 +1,60 @@ -// Test reacting to and reading outputs from a contained reactor bank in various -// permutations. +// Test reacting to and reading outputs from a contained reactor bank in various permutations. target Cpp reactor Contained(bank_index: size_t = 0) { - output out: unsigned + output out: unsigned - reaction(startup) -> out {= out.set(42 * bank_index); =} + reaction(startup) -> out {= out.set(42 * bank_index); =} } main reactor { - c = new[4] Contained() - state count: int = 0 + c = new[4] Contained() + state count: int = 0 - reaction(startup) c.out {= - for (size_t i = 0; i < c.size(); i++) { - unsigned result = *c[i].out.get(); - std::cout << "Startup reaction reading output of contained " - << "reactor: " << result << std::endl; - if (result != 42 * i) { - std::cout << "FAILURE: expected " << 42 * i << std::endl; - exit(2); - } + reaction(startup) c.out {= + for (size_t i = 0; i < c.size(); i++) { + unsigned result = *c[i].out.get(); + std::cout << "Startup reaction reading output of contained " + << "reactor: " << result << std::endl; + if (result != 42 * i) { + std::cout << "FAILURE: expected " << 42 * i << std::endl; + exit(2); } - count++; - =} + } + count++; + =} - reaction(c.out) {= - for (size_t i = 0; i < c.size(); i++) { - unsigned result = *c[i].out.get(); - std::cout << "Reading output of contained reactor: " << result - << std::endl; - if (result != 42 * i) { - std::cout << "FAILURE: expected " << 42 * i << std::endl; - exit(2); - } + reaction(c.out) {= + for (size_t i = 0; i < c.size(); i++) { + unsigned result = *c[i].out.get(); + std::cout << "Reading output of contained reactor: " << result + << std::endl; + if (result != 42 * i) { + std::cout << "FAILURE: expected " << 42 * i << std::endl; + exit(2); } - count++; - =} + } + count++; + =} - reaction(startup, c.out) {= - for (size_t i = 0; i < c.size(); i++) { - unsigned result = *c[i].out.get(); - std::cout << "Alternate triggering reading output of contained " - << "reactor: " << result << std::endl; - if (result != 42 * i) { - std::cout << "FAILURE: expected " << 42 * i << std::endl; - exit(2); - } + reaction(startup, c.out) {= + for (size_t i = 0; i < c.size(); i++) { + unsigned result = *c[i].out.get(); + std::cout << "Alternate triggering reading output of contained " + << "reactor: " << result << std::endl; + if (result != 42 * i) { + std::cout << "FAILURE: expected " << 42 * i << std::endl; + exit(2); } - count++; - =} + } + count++; + =} - reaction(shutdown) {= - if (count != 3) { - std::cerr << "ERROR: One of the reactions failed to trigger." - << std::endl; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 3) { + std::cerr << "ERROR: One of the reactions failed to trigger." + << std::endl; + exit(1); + } + =} } diff --git a/test/Cpp/src/multiport/SparseMultiport.lf b/test/Cpp/src/multiport/SparseMultiport.lf index c0ffff2e12..f126ce385d 100644 --- a/test/Cpp/src/multiport/SparseMultiport.lf +++ b/test/Cpp/src/multiport/SparseMultiport.lf @@ -1,49 +1,31 @@ target Cpp { - timeout: 1 s + timeout: 1 s } reactor Producer { - timer t(0, 100 ms) + timer t(0, 100 ms) - output[10] out: int + output[10] out: int - state odd: bool(true) + state odd: bool(true) - reaction(t) -> out {= - for (int i{odd ? 1 : 0}; i < 10; i += 2) { - out[i].set(i); - } + reaction(t) -> out {= + for (int i{odd ? 1 : 0}; i < 10; i += 2) { + out[i].set(i); + } - odd = !odd; - =} + odd = !odd; + =} } reactor Consumer { - state odd: bool(true) - input[10] in: int - - reaction(in) {= - reactor::log::Info() << "Received:"; - for (int i{0}; i < 10; i++) { - if (in[i].is_present()) { - if (odd && i%2 == 0) { - reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; - exit(1); - } - if (!odd && i%2 == 1) { - reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; - exit(1); - } - reactor::log::Info() << "- " << i; - } - } - =} + state odd: bool(true) + input[10] in: int - reaction(in) {= - int count = 0; - int last = -1; - for (int i : in.present_indices_sorted()) { - count++; + reaction(in) {= + reactor::log::Info() << "Received:"; + for (int i{0}; i < 10; i++) { + if (in[i].is_present()) { if (odd && i%2 == 0) { reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; exit(1); @@ -52,34 +34,52 @@ reactor Consumer { reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; exit(1); } - if (i < last) { - reactor::log::Error() << "Received index out of order! " << i << " after " << last; - exit(1); - } + reactor::log::Info() << "- " << i; } - for (int i : in.present_indices_unsorted()) { - count++; - if (odd && i%2 == 0) { - reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; - exit(1); - } - if (!odd && i%2 == 1) { - reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; - exit(1); - } + } + =} + + reaction(in) {= + int count = 0; + int last = -1; + for (int i : in.present_indices_sorted()) { + count++; + if (odd && i%2 == 0) { + reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; + exit(1); + } + if (!odd && i%2 == 1) { + reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; + exit(1); + } + if (i < last) { + reactor::log::Error() << "Received index out of order! " << i << " after " << last; + exit(1); + } + } + for (int i : in.present_indices_unsorted()) { + count++; + if (odd && i%2 == 0) { + reactor::log::Error() << "Expected values only on odd ports, but received one on port " << i; + exit(1); } - if (count != 10) { - reactor::log::Error() << "Expected count to be 10, but got " << count; + if (!odd && i%2 == 1) { + reactor::log::Error() << "Expected values only on even ports, but received one on port " << i; exit(1); } + } + if (count != 10) { + reactor::log::Error() << "Expected count to be 10, but got " << count; + exit(1); + } - odd = !odd; - =} + odd = !odd; + =} } main reactor { - c = new Consumer() - p = new Producer() + c = new Consumer() + p = new Producer() - p.out -> c.in + p.out -> c.in } diff --git a/test/Cpp/src/multiport/WidthGivenByCode.lf b/test/Cpp/src/multiport/WidthGivenByCode.lf index 10a2a59489..6bfc814650 100644 --- a/test/Cpp/src/multiport/WidthGivenByCode.lf +++ b/test/Cpp/src/multiport/WidthGivenByCode.lf @@ -1,37 +1,37 @@ target Cpp reactor Foo(a: size_t = 8, b: size_t = 2) { - input[{= a*b =}] in: size_t - output[{= a/b =}] out: size_t + input[{= a*b =}] in: size_t + output[{= a/b =}] out: size_t - reaction(startup) in -> out {= - if (in.size() != a*b) { - std::cerr << "ERROR: expected in to have a width of " << a*b << '\n'; - exit(1); - } - if (out.size() != a/b) { - std::cerr << "ERROR: expected out to have a width of " << a/b << '\n'; - exit(2); - } - =} + reaction(startup) in -> out {= + if (in.size() != a*b) { + std::cerr << "ERROR: expected in to have a width of " << a*b << '\n'; + exit(1); + } + if (out.size() != a/b) { + std::cerr << "ERROR: expected out to have a width of " << a/b << '\n'; + exit(2); + } + =} } main reactor { - foo1 = new Foo() - foo2 = new Foo(a = 10, b = 3) - foo3 = new Foo(a = 9, b = 9) - foo_bank = new[{= 42 =}] Foo() + foo1 = new Foo() + foo2 = new Foo(a = 10, b = 3) + foo3 = new Foo(a = 9, b = 9) + foo_bank = new[{= 42 =}] Foo() - reaction(startup) foo_bank.out {= - if (foo_bank.size() != 42) { - std::cerr << "ERROR: expected foo_bank to have a width of " << 42 << '\n'; - exit(3); - } - for (auto& foo : foo_bank) { - if (foo.out.size() != 4) { - std::cerr << "ERROR: expected foo_bank.out to have a width of " << 4 << '\n'; - exit(4); - } + reaction(startup) foo_bank.out {= + if (foo_bank.size() != 42) { + std::cerr << "ERROR: expected foo_bank to have a width of " << 42 << '\n'; + exit(3); + } + for (auto& foo : foo_bank) { + if (foo.out.size() != 4) { + std::cerr << "ERROR: expected foo_bank.out to have a width of " << 4 << '\n'; + exit(4); } - =} + } + =} } diff --git a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf index b8f8d50958..87258ae953 100644 --- a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf @@ -2,33 +2,33 @@ target Cpp reactor Contained(bank_index: size_t = 0) { - input in: unsigned - state count: int = 0 + input in: unsigned + state count: int = 0 - reaction(in) {= - unsigned result = *in.get(); - std::cout << "Instance " << bank_index << " received " << result << '\n'; - if (result != bank_index * 42) { - std::cout << "FAILURE: expected " << 42 * bank_index << '\n'; - exit(2); - } - count++; - =} + reaction(in) {= + unsigned result = *in.get(); + std::cout << "Instance " << bank_index << " received " << result << '\n'; + if (result != bank_index * 42) { + std::cout << "FAILURE: expected " << 42 * bank_index << '\n'; + exit(2); + } + count++; + =} - reaction(shutdown) {= - if (count != 1) { - std::cerr << "ERROR: One of the reactions failed to trigger.\n"; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 1) { + std::cerr << "ERROR: One of the reactions failed to trigger.\n"; + exit(1); + } + =} } main reactor { - c = new[4] Contained() + c = new[4] Contained() - reaction(startup) -> c.in {= - for (size_t i = 0; i < c.size(); i++) { - c[i].in.set(i*42); - } - =} + reaction(startup) -> c.in {= + for (size_t i = 0; i < c.size(); i++) { + c[i].in.set(i*42); + } + =} } diff --git a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf index 5ffe567dfb..2bb7c12b9a 100644 --- a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf @@ -2,37 +2,37 @@ target Cpp reactor Contained(bank_index: size_t = 0) { - input[4] in: unsigned - state count: int = 0 + input[4] in: unsigned + state count: int = 0 - reaction(in) {= - for (size_t i = 0; i < 3; i++) { - unsigned result = *in[i].get(); - std::cout << "Instance " << bank_index << " received " << result << '\n'; - if (result != bank_index * i) { - std::cout << "FAILURE: expected " << i * bank_index << '\n'; - exit(2); - } + reaction(in) {= + for (size_t i = 0; i < 3; i++) { + unsigned result = *in[i].get(); + std::cout << "Instance " << bank_index << " received " << result << '\n'; + if (result != bank_index * i) { + std::cout << "FAILURE: expected " << i * bank_index << '\n'; + exit(2); } - count++; - =} + } + count++; + =} - reaction(shutdown) {= - if (count != 1) { - std::cerr << "ERROR: One of the reactions failed to trigger.\n"; - exit(1); - } - =} + reaction(shutdown) {= + if (count != 1) { + std::cerr << "ERROR: One of the reactions failed to trigger.\n"; + exit(1); + } + =} } main reactor { - c = new[4] Contained() + c = new[4] Contained() - reaction(startup) -> c.in {= - for (size_t i = 0; i < c.size(); i++) { - for (size_t j = 0; j < c[i].in.size(); j++) { - c[i].in[j].set(i*j); - } + reaction(startup) -> c.in {= + for (size_t i = 0; i < c.size(); i++) { + for (size_t j = 0; j < c[i].in.size(); j++) { + c[i].in[j].set(i*j); } - =} + } + =} } diff --git a/test/Cpp/src/properties/Fast.lf b/test/Cpp/src/properties/Fast.lf index 1d4ba25d2f..97e40f05b8 100644 --- a/test/Cpp/src/properties/Fast.lf +++ b/test/Cpp/src/properties/Fast.lf @@ -1,28 +1,28 @@ target Cpp { - fast: true + fast: true } main reactor { - logical action a + logical action a - state triggered: bool = false + state triggered: bool = false - reaction(startup) -> a {= a.schedule(2s); =} + reaction(startup) -> a {= a.schedule(2s); =} - reaction(a) {= - triggered = true; - if (get_elapsed_physical_time() >= 2s) { - std::cout << "ERROR: needed more than 2s to process the reaction\n"; - exit(1); - } - =} + reaction(a) {= + triggered = true; + if (get_elapsed_physical_time() >= 2s) { + std::cout << "ERROR: needed more than 2s to process the reaction\n"; + exit(1); + } + =} - reaction(shutdown) {= - if (triggered) { - std::cout << "SUCCESS!\n"; - } else { - std::cout << "ERROR: reaction was not invoked!\n"; - exit(2); - } - =} + reaction(shutdown) {= + if (triggered) { + std::cout << "SUCCESS!\n"; + } else { + std::cout << "ERROR: reaction was not invoked!\n"; + exit(2); + } + =} } diff --git a/test/Cpp/src/properties/Timeout.lf b/test/Cpp/src/properties/Timeout.lf index 57c55ad24c..3fd5982952 100644 --- a/test/Cpp/src/properties/Timeout.lf +++ b/test/Cpp/src/properties/Timeout.lf @@ -1,31 +1,31 @@ target Cpp { - timeout: 1 sec + timeout: 1 sec } main reactor { - timer t(1 sec, 1 sec) + timer t(1 sec, 1 sec) - state triggered: bool = false + state triggered: bool = false - reaction(t) {= - triggered = true; - if (get_elapsed_logical_time() != 1s) { - std::cout << "ERROR: triggered reaction at an unexpected tag"; - exit(1); - } - =} + reaction(t) {= + triggered = true; + if (get_elapsed_logical_time() != 1s) { + std::cout << "ERROR: triggered reaction at an unexpected tag"; + exit(1); + } + =} - reaction(shutdown) {= - if (get_elapsed_logical_time() != 1s || get_microstep() != 0) { - std::cout << "ERROR: shutdown invoked at an unexpected tag"; - exit(2); - } + reaction(shutdown) {= + if (get_elapsed_logical_time() != 1s || get_microstep() != 0) { + std::cout << "ERROR: shutdown invoked at an unexpected tag"; + exit(2); + } - if (triggered) { - std::cout << "SUCCESS!\n"; - } else { - std::cout << "ERROR: reaction was not invoked!\n"; - exit(2); - } - =} + if (triggered) { + std::cout << "SUCCESS!\n"; + } else { + std::cout << "ERROR: reaction was not invoked!\n"; + exit(2); + } + =} } diff --git a/test/Cpp/src/properties/TimeoutZero.lf b/test/Cpp/src/properties/TimeoutZero.lf index 9d04fa8048..c49db95731 100644 --- a/test/Cpp/src/properties/TimeoutZero.lf +++ b/test/Cpp/src/properties/TimeoutZero.lf @@ -1,31 +1,31 @@ target Cpp { - timeout: 0 sec + timeout: 0 sec } main reactor { - timer t(0, 1 sec) + timer t(0, 1 sec) - state triggered: bool = false + state triggered: bool = false - reaction(t) {= - triggered = true; - if (get_elapsed_logical_time() != 0s) { - std::cout << "ERROR: triggered reaction at an unexpected tag"; - exit(1); - } - =} + reaction(t) {= + triggered = true; + if (get_elapsed_logical_time() != 0s) { + std::cout << "ERROR: triggered reaction at an unexpected tag"; + exit(1); + } + =} - reaction(shutdown) {= - if (get_elapsed_logical_time() != 0s || get_microstep() != 0) { - std::cout << "ERROR: shutdown invoked at an unexpected tag"; - exit(2); - } + reaction(shutdown) {= + if (get_elapsed_logical_time() != 0s || get_microstep() != 0) { + std::cout << "ERROR: shutdown invoked at an unexpected tag"; + exit(2); + } - if (triggered) { - std::cout << "SUCCESS!\n"; - } else { - std::cout << "ERROR: reaction was not invoked!\n"; - exit(2); - } - =} + if (triggered) { + std::cout << "SUCCESS!\n"; + } else { + std::cout << "ERROR: reaction was not invoked!\n"; + exit(2); + } + =} } diff --git a/test/Cpp/src/target/AfterVoid.lf b/test/Cpp/src/target/AfterVoid.lf index 555e024e6b..dbb0041a3e 100644 --- a/test/Cpp/src/target/AfterVoid.lf +++ b/test/Cpp/src/target/AfterVoid.lf @@ -1,44 +1,44 @@ // This checks that the after keyword also works with void ports target Cpp { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor foo { - timer t(0, 1 sec) - output y: void + timer t(0, 1 sec) + output y: void - reaction(t) -> y {= y.set(); =} + reaction(t) -> y {= y.set(); =} } reactor print { - state expected_time: time = 10 msec - state i: int = 0 - input x: void + state expected_time: time = 10 msec + state i: int = 0 + input x: void - reaction(x) {= - i++; - auto elapsed_time = get_elapsed_logical_time(); - std::cout << "Current logical time is: " << elapsed_time << '\n'; - std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; - if (elapsed_time != expected_time) { - std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; - exit(2); - } - expected_time += 1s; - =} + reaction(x) {= + i++; + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Current logical time is: " << elapsed_time << '\n'; + std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; + if (elapsed_time != expected_time) { + std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; + exit(2); + } + expected_time += 1s; + =} - reaction(shutdown) {= - if (i == 0) { - std::cerr << "ERROR: Final reactor received no data.\n"; - exit(3); - } - =} + reaction(shutdown) {= + if (i == 0) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} } main reactor { - f = new foo() - p = new print() + f = new foo() + p = new print() - f.y -> p.x after 10 msec + f.y -> p.x after 10 msec } diff --git a/test/Cpp/src/target/BraceAndParenInitialization.lf b/test/Cpp/src/target/BraceAndParenInitialization.lf index 003b6d509d..e6ab2168f3 100644 --- a/test/Cpp/src/target/BraceAndParenInitialization.lf +++ b/test/Cpp/src/target/BraceAndParenInitialization.lf @@ -1,30 +1,28 @@ target Cpp reactor Foo( - param_list_1: std::vector(4, 2), // list containing [2,2,2,2] - param_list_2: std::vector{4, 2}, // list containing [4,2] - param_list_3: std::vector(4, 2), // list containing [2,2,2,2] - param_list_4: std::vector{4, 2} // list containing [4,2] + param_list_1: std::vector(4, 2), // list containing [2,2,2,2] + param_list_2: std::vector{4, 2}, // list containing [4,2] + param_list_3: std::vector(4, 2), // list containing [2,2,2,2] + param_list_4: std::vector{4, 2} // list containing [4,2] ) { - // list containing [42,42,42,42,42,42] - state state_list_1: std::vector(6, 42) - // list containing [6,42] - state state_list_2: std::vector{6, 42} + state state_list_1: std::vector(6, 42) // list containing [42,42,42,42,42,42] + state state_list_2: std::vector{6, 42} // list containing [6,42] - reaction(startup) {= - std::cerr << "Hello!\n"; - if (param_list_1.size() != 4 || param_list_1[0] != 2 || - param_list_2.size() != 2 || param_list_2[0] != 4 || - param_list_3.size() != 3 || param_list_3[0] != 5 || - param_list_4.size() != 2 || param_list_4[0] != 3 || - state_list_1.size() != 6 || state_list_1[0] != 42 || - state_list_2.size() != 2 || state_list_2[0] != 6) { - std::cerr << "Error!\n"; - exit(1); - } - =} + reaction(startup) {= + std::cerr << "Hello!\n"; + if (param_list_1.size() != 4 || param_list_1[0] != 2 || + param_list_2.size() != 2 || param_list_2[0] != 4 || + param_list_3.size() != 3 || param_list_3[0] != 5 || + param_list_4.size() != 2 || param_list_4[0] != 3 || + state_list_1.size() != 6 || state_list_1[0] != 42 || + state_list_2.size() != 2 || state_list_2[0] != 6) { + std::cerr << "Error!\n"; + exit(1); + } + =} } main reactor { - foo = new Foo(param_list_3 = {= std::vector(3, 5) =}, param_list_4 = {3, 5}) + foo = new Foo(param_list_3 = {= std::vector(3, 5) =}, param_list_4 = {3, 5}) } diff --git a/test/Cpp/src/target/CliParserGenericArguments.lf b/test/Cpp/src/target/CliParserGenericArguments.lf index 9a008ebcab..4ab5729088 100644 --- a/test/Cpp/src/target/CliParserGenericArguments.lf +++ b/test/Cpp/src/target/CliParserGenericArguments.lf @@ -6,57 +6,57 @@ target Cpp public preamble {= - using unsigned_long = unsigned long; - using long_long = long long; - using uns_long_long = unsigned long long; - using long_double = long double; + using unsigned_long = unsigned long; + using long_long = long long; + using uns_long_long = unsigned long long; + using long_double = long double; - #include - #include - using namespace std; - class CustomClass { - public: - std::string name; - CustomClass(std::string new_name="John") : name{new_name} - {} - std::string get_name() const {return this->name;} - void set_name(std::string updated_name){this->name = updated_name;} - }; + #include + #include + using namespace std; + class CustomClass { + public: + std::string name; + CustomClass(std::string new_name="John") : name{new_name} + {} + std::string get_name() const {return this->name;} + void set_name(std::string updated_name){this->name = updated_name;} + }; - ostream& operator<<(ostream& os, const CustomClass& cc); + ostream& operator<<(ostream& os, const CustomClass& cc); - stringstream& operator>>(stringstream& in, CustomClass& cc); + stringstream& operator>>(stringstream& in, CustomClass& cc); =} private preamble {= - stringstream& operator>>(stringstream& in, CustomClass& cc) - { - cc.set_name(in.str()); - return in; - } + stringstream& operator>>(stringstream& in, CustomClass& cc) + { + cc.set_name(in.str()); + return in; + } - ostream& operator<<(ostream& os, const CustomClass& cc) - { - os << cc.get_name(); - return os; - } + ostream& operator<<(ostream& os, const CustomClass& cc) + { + os << cc.get_name(); + return os; + } =} main reactor CliParserGenericArguments( - int_value: int = 10, - signed_value: signed = -10, - unsigned_value: unsigned = 11, - long_value: long = -100, - unsigned_long_value: {= unsigned_long =} = 42, - long_long_value: {= long_long =} = -42, - ull_value: {= uns_long_long =} = 42, - bool_value: bool = false, - char_value: char = 'T', - double_value: double = 4.2, - long_double_value: {= long_double =} = 4.2, - float_value: float = 10.5, - string_value: string = "This is a testvalue", - custom_class_value: {= CustomClass =}("Peter") + int_value: int = 10, + signed_value: signed = -10, + unsigned_value: unsigned = 11, + long_value: long = -100, + unsigned_long_value: {= unsigned_long =} = 42, + long_long_value: {= long_long =} = -42, + ull_value: {= uns_long_long =} = 42, + bool_value: bool = false, + char_value: char = 'T', + double_value: double = 4.2, + long_double_value: {= long_double =} = 4.2, + float_value: float = 10.5, + string_value: string = "This is a testvalue", + custom_class_value: {= CustomClass =}("Peter") ) { - reaction(startup) {= std::cout << "Hello World!\n"; =} + reaction(startup) {= std::cout << "Hello World!\n"; =} } diff --git a/test/Cpp/src/target/CombinedTypeNames.lf b/test/Cpp/src/target/CombinedTypeNames.lf index d55c70a823..e4ae72cfcd 100644 --- a/test/Cpp/src/target/CombinedTypeNames.lf +++ b/test/Cpp/src/target/CombinedTypeNames.lf @@ -1,22 +1,19 @@ -// This test simply checks if combined type names consisting of multiple words -// (such as `unsigned int`) can be used correctly in LF code. +// This test simply checks if combined type names consisting of multiple words (such as `unsigned +// int`) can be used correctly in LF code. target Cpp -reactor Foo( - bar: {= unsigned int =} = 0, - baz: {= const unsigned int* =} = {= nullptr =} -) { - state s_bar: {= unsigned int =} = bar - state s_baz: {= const unsigned int* =} = baz +reactor Foo(bar: {= unsigned int =} = 0, baz: {= const unsigned int* =} = {= nullptr =}) { + state s_bar: {= unsigned int =} = bar + state s_baz: {= const unsigned int* =} = baz - reaction(startup) {= - if (bar != 42 || s_bar != 42 || *baz != 42 || *s_baz != 42) { - reactor::log::Error() << "Unexpected value!"; - exit(1); - } - =} + reaction(startup) {= + if (bar != 42 || s_bar != 42 || *baz != 42 || *s_baz != 42) { + reactor::log::Error() << "Unexpected value!"; + exit(1); + } + =} } main reactor(bar: {= unsigned int =} = 42) { - foo = new Foo(bar = bar, baz = {= &bar =}) + foo = new Foo(bar = bar, baz = {= &bar =}) } diff --git a/test/Cpp/src/target/GenericAfter.lf b/test/Cpp/src/target/GenericAfter.lf index 25a91e7877..3de5c1dba8 100644 --- a/test/Cpp/src/target/GenericAfter.lf +++ b/test/Cpp/src/target/GenericAfter.lf @@ -3,19 +3,19 @@ target Cpp import Test from "../DelayInt.lf" reactor Delay(delay: time(0)) { - output out: T - input in: T - logical action a(delay): T + output out: T + input in: T + logical action a(delay): T - reaction(a) -> out {= out.set(a.get()); =} + reaction(a) -> out {= out.set(a.get()); =} - reaction(in) -> a {= a.schedule(in.get()); =} + reaction(in) -> a {= a.schedule(in.get()); =} } main reactor { - d = new Delay(delay = 50 msec) - test = new Test() - d.out -> test.in after 50 msec + d = new Delay(delay = 50 msec) + test = new Test() + d.out -> test.in after 50 msec - reaction(startup) -> d.in {= d.in.set(42); =} + reaction(startup) -> d.in {= d.in.set(42); =} } diff --git a/test/Cpp/src/target/GenericDelay.lf b/test/Cpp/src/target/GenericDelay.lf index 5efa81b011..5134f8cde6 100644 --- a/test/Cpp/src/target/GenericDelay.lf +++ b/test/Cpp/src/target/GenericDelay.lf @@ -3,19 +3,19 @@ target Cpp import Test from "../DelayInt.lf" reactor Delay(delay: time = 0) { - output out: T - input in: T - logical action a(delay): T + output out: T + input in: T + logical action a(delay): T - reaction(a) -> out {= out.set(a.get()); =} + reaction(a) -> out {= out.set(a.get()); =} - reaction(in) -> a {= a.schedule(in.get()); =} + reaction(in) -> a {= a.schedule(in.get()); =} } main reactor { - d = new Delay(delay = 100 msec) - test = new Test() - d.out -> test.in + d = new Delay(delay = 100 msec) + test = new Test() + d.out -> test.in - reaction(startup) -> d.in {= d.in.set(42); =} + reaction(startup) -> d.in {= d.in.set(42); =} } diff --git a/test/Cpp/src/target/GenericParameterAndState.lf b/test/Cpp/src/target/GenericParameterAndState.lf index 6803eb9509..76cb2f9c3d 100644 --- a/test/Cpp/src/target/GenericParameterAndState.lf +++ b/test/Cpp/src/target/GenericParameterAndState.lf @@ -1,21 +1,21 @@ target Cpp reactor Foo(bar: T = 0, expected: T = 14542135) { - state baz: T = bar + state baz: T = bar - reaction(startup) {= - if (bar != expected) { - std::cerr << "ERROR: Expected baz=" << expected << " but got baz=" << bar << '\n'; - exit(1); - } - if (baz != expected) { - std::cerr << "ERROR: Expected baz=" << expected << " but got baz=" << baz << '\n'; - exit(1); - } - =} + reaction(startup) {= + if (bar != expected) { + std::cerr << "ERROR: Expected baz=" << expected << " but got baz=" << bar << '\n'; + exit(1); + } + if (baz != expected) { + std::cerr << "ERROR: Expected baz=" << expected << " but got baz=" << baz << '\n'; + exit(1); + } + =} } main reactor { - foo = new Foo(bar = 42, expected = 42) - bar = new Foo(expected = 0) // default value is used + foo = new Foo(bar = 42, expected = 42) + bar = new Foo(expected = 0) // default value is used } diff --git a/test/Cpp/src/target/InitializerSyntax.lf b/test/Cpp/src/target/InitializerSyntax.lf index 54ae268457..998c711f1f 100644 --- a/test/Cpp/src/target/InitializerSyntax.lf +++ b/test/Cpp/src/target/InitializerSyntax.lf @@ -1,89 +1,89 @@ target Cpp public preamble {= - #include - struct TestType { - int x; + #include + struct TestType { + int x; - // constructor #1 - TestType() : x(42) {} - // constructor #2 - TestType(int x) : x(x) {} - // constructor #3 - TestType(std::initializer_list l) : x(l.size()) {} - // constructor #4 - TestType(const TestType& t) : x(t.x + 10) { } - // constructor #5 - TestType(TestType&& t) : x(t.x + 20) { } + // constructor #1 + TestType() : x(42) {} + // constructor #2 + TestType(int x) : x(x) {} + // constructor #3 + TestType(std::initializer_list l) : x(l.size()) {} + // constructor #4 + TestType(const TestType& t) : x(t.x + 10) { } + // constructor #5 + TestType(TestType&& t) : x(t.x + 20) { } - TestType& operator=(const TestType& t) { - std::cout << "assign\n"; - this->x = t.x + 30; - return *this; - } - TestType& operator=(TestType&& t) { - this->x = t.x + 40; - return *this; - } + TestType& operator=(const TestType& t) { + std::cout << "assign\n"; + this->x = t.x + 30; + return *this; + } + TestType& operator=(TestType&& t) { + this->x = t.x + 40; + return *this; + } - ~TestType() = default; - }; + ~TestType() = default; + }; =} reactor TestReactor( - /** - * FIXME: should work without an explicit initialization, see - * https://github.com/lf-lang/lingua-franca/issues/623 - */ - // p_default: TestType, constructor #1 - p_default: TestType(), - p_empty: TestType(), // constructor #1 - p_value: TestType(24), // constructor #2 - p_init_empty: TestType{}, // constructor #1 - p_init_empty2: TestType({}), // constructor #1 - p_init_some: TestType{2, 6, 6, 3, 1}, // constructor #1 - p_assign_init_empty: TestType = {}, // constructor #1 - p_assign_init_some: TestType = {4, 2, 1} // constructor #3 + /** + * FIXME: should work without an explicit initialization, see + * https://github.com/lf-lang/lingua-franca/issues/623 + */ + // p_default: TestType, constructor #1 + p_default: TestType(), + p_empty: TestType(), // constructor #1 + p_value: TestType(24), // constructor #2 + p_init_empty: TestType{}, // constructor #1 + p_init_empty2: TestType({}), // constructor #1 + p_init_some: TestType{2, 6, 6, 3, 1}, // constructor #1 + p_assign_init_empty: TestType = {}, // constructor #1 + p_assign_init_some: TestType = {4, 2, 1} // constructor #3 ) { - state s_default: TestType // constructor #1 - state s_empty: TestType() // constructor #1 - state s_value: TestType(24) // constructor #2 - state s_init_empty: TestType{} // constructor #1 - state s_init_empty2: TestType({}) // constructor #3 - state s_init_some: TestType{3, 12, 40} // constructor #3 - state s_assign_init_empty: TestType = {} // constructor #3 - state s_assign_init_some: TestType = {4, 3, 2, 1} // constructor #3 - state s_copy1: TestType(p_default) // constructor #4 - state s_copy2: TestType{p_default} // constructor #4 - state s_copy3: TestType = p_default // constructor #4 + state s_default: TestType // constructor #1 + state s_empty: TestType() // constructor #1 + state s_value: TestType(24) // constructor #2 + state s_init_empty: TestType{} // constructor #1 + state s_init_empty2: TestType({}) // constructor #3 + state s_init_some: TestType{3, 12, 40} // constructor #3 + state s_assign_init_empty: TestType = {} // constructor #3 + state s_assign_init_some: TestType = {4, 3, 2, 1} // constructor #3 + state s_copy1: TestType(p_default) // constructor #4 + state s_copy2: TestType{p_default} // constructor #4 + state s_copy3: TestType = p_default // constructor #4 - reaction(startup) {= - reactor::validate(p_default.x == 62, "p_default should be default constructed and then moved"); - reactor::validate(p_empty.x == 62, "p_empty should be default constructed and then moved"); - reactor::validate(p_value.x == 44, "p_value should be constructed from 24 and then moved"); - reactor::validate(p_init_empty.x == 62, "p_init_empty should be default constructed and then moved"); - reactor::validate(p_init_empty2.x == 20, "p_init_empty2 should be constructed with 0 and then moved"); - reactor::validate(p_init_some.x == 25, "p_init_some should be constructed with 3 and then moved"); - reactor::validate(p_assign_init_empty.x == 62, "p_assign_init_empty should be default constructed and then moved"); - reactor::validate(p_assign_init_some.x == 23, "p_assign_init_some should be constructed with 4 and then moved"); + reaction(startup) {= + reactor::validate(p_default.x == 62, "p_default should be default constructed and then moved"); + reactor::validate(p_empty.x == 62, "p_empty should be default constructed and then moved"); + reactor::validate(p_value.x == 44, "p_value should be constructed from 24 and then moved"); + reactor::validate(p_init_empty.x == 62, "p_init_empty should be default constructed and then moved"); + reactor::validate(p_init_empty2.x == 20, "p_init_empty2 should be constructed with 0 and then moved"); + reactor::validate(p_init_some.x == 25, "p_init_some should be constructed with 3 and then moved"); + reactor::validate(p_assign_init_empty.x == 62, "p_assign_init_empty should be default constructed and then moved"); + reactor::validate(p_assign_init_some.x == 23, "p_assign_init_some should be constructed with 4 and then moved"); - reactor::validate(s_default.x == 42, "s_default should be default constructed"); - reactor::validate(s_empty.x == 42, "s_empty should be default constructed"); - reactor::validate(s_value.x == 24, "s_value should be constructed with 24"); - reactor::validate(s_init_empty.x == 42, "s_init_empty should be default constructed"); - reactor::validate(s_init_empty2.x == 0, "s_init_empty2 should be constructed with 0"); - reactor::validate(s_init_some.x == 3, "s_init_some should be constructed with 3"); - // NOTE: This is a strange corner case. Since the equal assignment will be translated to a () initializers (e.g. :foo(42)), - // the initialization here in LF behaves differently from what one might expect. When writing `Foo foo = {}`, - // the default constructor would be called instead of the initializer list constructor. - reactor::validate(s_assign_init_empty.x == 0, "s_assign_init_empty should be constructed with 0"); - reactor::validate(s_assign_init_some.x == 4, "s_assign_init_some should be constructed with 4"); - reactor::validate(s_copy1.x == 72, "s_copy1 should be copy constructed from p_default"); - reactor::validate(s_copy2.x == 72, "s_copy1 should be copy constructed from p_default"); - reactor::validate(s_copy3.x == 72, "s_copy1 should be copy constructed from p_default"); - =} + reactor::validate(s_default.x == 42, "s_default should be default constructed"); + reactor::validate(s_empty.x == 42, "s_empty should be default constructed"); + reactor::validate(s_value.x == 24, "s_value should be constructed with 24"); + reactor::validate(s_init_empty.x == 42, "s_init_empty should be default constructed"); + reactor::validate(s_init_empty2.x == 0, "s_init_empty2 should be constructed with 0"); + reactor::validate(s_init_some.x == 3, "s_init_some should be constructed with 3"); + // NOTE: This is a strange corner case. Since the equal assignment will be translated to a () initializers (e.g. :foo(42)), + // the initialization here in LF behaves differently from what one might expect. When writing `Foo foo = {}`, + // the default constructor would be called instead of the initializer list constructor. + reactor::validate(s_assign_init_empty.x == 0, "s_assign_init_empty should be constructed with 0"); + reactor::validate(s_assign_init_some.x == 4, "s_assign_init_some should be constructed with 4"); + reactor::validate(s_copy1.x == 72, "s_copy1 should be copy constructed from p_default"); + reactor::validate(s_copy2.x == 72, "s_copy1 should be copy constructed from p_default"); + reactor::validate(s_copy3.x == 72, "s_copy1 should be copy constructed from p_default"); + =} } main reactor { - test = new TestReactor() + test = new TestReactor() } diff --git a/test/Cpp/src/target/MultipleContainedGeneric.lf b/test/Cpp/src/target/MultipleContainedGeneric.lf index ab2b2e0956..5a767dc3c1 100644 --- a/test/Cpp/src/target/MultipleContainedGeneric.lf +++ b/test/Cpp/src/target/MultipleContainedGeneric.lf @@ -1,36 +1,35 @@ -// Test that a reaction can react to and send two multiple ports of a contained -// reactor. +// Test that a reaction can react to and send two multiple ports of a contained reactor. target Cpp reactor Contained { - output trigger: T - input in1: T - input in2: T + output trigger: T + input in1: T + input in2: T - reaction(startup) -> trigger {= trigger.set(42); =} + reaction(startup) -> trigger {= trigger.set(42); =} - reaction(in1) {= - std::cout << "in1 received " << *in1.get() << '\n'; - if (*in1.get() != 42) { - std::cerr << "FAILED: Expected 42.\n"; - exit(1); - } - =} + reaction(in1) {= + std::cout << "in1 received " << *in1.get() << '\n'; + if (*in1.get() != 42) { + std::cerr << "FAILED: Expected 42.\n"; + exit(1); + } + =} - reaction(in2) {= - std::cout << "in2 received " << *in2.get() << '\n'; - if (*in2.get() != 42) { - std::cerr << "FAILED: Expected 42.\n"; - exit(1); - } - =} + reaction(in2) {= + std::cout << "in2 received " << *in2.get() << '\n'; + if (*in2.get() != 42) { + std::cerr << "FAILED: Expected 42.\n"; + exit(1); + } + =} } main reactor { - c = new Contained() + c = new Contained() - reaction(c.trigger) -> c.in1, c.in2 {= - c.in1.set(c.trigger.get()); - c.in2.set(c.trigger.get()); - =} + reaction(c.trigger) -> c.in1, c.in2 {= + c.in1.set(c.trigger.get()); + c.in2.set(c.trigger.get()); + =} } diff --git a/test/Cpp/src/target/PointerParameters.lf b/test/Cpp/src/target/PointerParameters.lf index a769f20da3..2de286aaa4 100644 --- a/test/Cpp/src/target/PointerParameters.lf +++ b/test/Cpp/src/target/PointerParameters.lf @@ -1,18 +1,18 @@ -// This is a smoke test to see if pointers can be used as parameters. -// Compilation without errors is success. +// This is a smoke test to see if pointers can be used as parameters. Compilation without errors is +// success. target Cpp reactor Foo(ptr: int* = {= nullptr =}) { - reaction(startup) {= - if (ptr == nullptr || *ptr != 42) { - reactor::log::Error() << "received an unexpected value!"; - exit(1); - } - =} + reaction(startup) {= + if (ptr == nullptr || *ptr != 42) { + reactor::log::Error() << "received an unexpected value!"; + exit(1); + } + =} } main reactor { - private preamble {= int a{42}; =} + private preamble {= int a{42}; =} - foo = new Foo(ptr = {= &a =}) + foo = new Foo(ptr = {= &a =}) } diff --git a/test/Python/src/ActionDelay.lf b/test/Python/src/ActionDelay.lf index 60efa42f57..ba46edf9c4 100644 --- a/test/Python/src/ActionDelay.lf +++ b/test/Python/src/ActionDelay.lf @@ -2,46 +2,46 @@ target Python reactor GeneratedDelay { - input y_in - output y_out - state y_state = 0 - logical action act(100 msec) + input y_in + output y_out + state y_state = 0 + logical action act(100 msec) - reaction(y_in) -> act {= - self.y_state = y_in.value - act.schedule(MSEC(0)) - =} + reaction(y_in) -> act {= + self.y_state = y_in.value + act.schedule(MSEC(0)) + =} - reaction(act) -> y_out {= y_out.set(self.y_state) =} + reaction(act) -> y_out {= y_out.set(self.y_state) =} } reactor Source { - output out + output out - reaction(startup) -> out {= out.set(1) =} + reaction(startup) -> out {= out.set(1) =} } reactor Sink { - input _in - - reaction(_in) {= - elapsed_logical = lf.time.logical_elapsed() - logical = lf.time.logical() - physical = lf.time.physical() - print("Logical, physical, and elapsed logical: ", logical, physical, elapsed_logical) - if elapsed_logical != MSEC(100): - sys.stderr.write("FAILURE: Expected " + str(MSEC(100)) + " but got " + str(elapsed_logical) + ".\n") - exit(1) - else: - print("SUCCESS. Elapsed logical time is 100 msec.\n") - =} + input _in + + reaction(_in) {= + elapsed_logical = lf.time.logical_elapsed() + logical = lf.time.logical() + physical = lf.time.physical() + print("Logical, physical, and elapsed logical: ", logical, physical, elapsed_logical) + if elapsed_logical != MSEC(100): + sys.stderr.write("FAILURE: Expected " + str(MSEC(100)) + " but got " + str(elapsed_logical) + ".\n") + exit(1) + else: + print("SUCCESS. Elapsed logical time is 100 msec.\n") + =} } main reactor ActionDelay { - source = new Source() - sink = new Sink() - g = new GeneratedDelay() + source = new Source() + sink = new Sink() + g = new GeneratedDelay() - source.out -> g.y_in - g.y_out -> sink._in + source.out -> g.y_in + g.y_out -> sink._in } diff --git a/test/Python/src/ActionIsPresent.lf b/test/Python/src/ActionIsPresent.lf index ceb52d10b8..3bdd419700 100644 --- a/test/Python/src/ActionIsPresent.lf +++ b/test/Python/src/ActionIsPresent.lf @@ -2,28 +2,28 @@ target Python main reactor ActionIsPresent(offset = 1 nsec, period = 500 msec) { - logical action a - state first_time = True - state success = False + logical action a + state first_time = True + state success = False - reaction(startup, a) -> a {= - # The is_present field should be initially False - if a.is_present is not True: - if self.offset == 0: - print("Hello World!") - self.success = True - else: - a.schedule(self.offset) - self.first_time = False + reaction(startup, a) -> a {= + # The is_present field should be initially False + if a.is_present is not True: + if self.offset == 0: + print("Hello World!") + self.success = True else: - print("Hello World 2!") - if self.first_time is not True: - self.success = True - =} + a.schedule(self.offset) + self.first_time = False + else: + print("Hello World 2!") + if self.first_time is not True: + self.success = True + =} - reaction(shutdown) {= - if self.success is not True: - sys.stderr.write("Failed to print 'Hello World'\n") - exit(1) - =} + reaction(shutdown) {= + if self.success is not True: + sys.stderr.write("Failed to print 'Hello World'\n") + exit(1) + =} } diff --git a/test/Python/src/After.lf b/test/Python/src/After.lf index 0c8b931543..d1f720ddfa 100644 --- a/test/Python/src/After.lf +++ b/test/Python/src/After.lf @@ -1,50 +1,49 @@ -# This checks that the after keyword adjusts logical time, not using physical -# time. +# This checks that the after keyword adjusts logical time, not using physical time. target Python { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor foo { - input x - output y + input x + output y - reaction(x) -> y {= y.set(2*x.value) =} + reaction(x) -> y {= y.set(2*x.value) =} } reactor print { - state expected_time = 10 msec - state received = 0 - input x - - reaction(x) {= - self.received+=1 - elapsed_time = lf.time.logical_elapsed() - print("Result is " + str(x.value)) - if x.value != 84: - sys.stderr.write("ERROR: Expected result to be 84.\n") - exit(1) - - print("Current logical time is: " + str(elapsed_time)) - print("Current physical time is: " + str(lf.time.physical_elapsed())) - if elapsed_time != self.expected_time: - sys.stderr.write("ERROR: Expected logical time to be " + self.expected_time) - exit(2) - self.expected_time += SEC(1) - =} - - reaction(shutdown) {= - if (self.received == 0): - sys.stderr.write("ERROR: Final reactor received no data.\n") - exit(3) - =} + state expected_time = 10 msec + state received = 0 + input x + + reaction(x) {= + self.received+=1 + elapsed_time = lf.time.logical_elapsed() + print("Result is " + str(x.value)) + if x.value != 84: + sys.stderr.write("ERROR: Expected result to be 84.\n") + exit(1) + + print("Current logical time is: " + str(elapsed_time)) + print("Current physical time is: " + str(lf.time.physical_elapsed())) + if elapsed_time != self.expected_time: + sys.stderr.write("ERROR: Expected logical time to be " + self.expected_time) + exit(2) + self.expected_time += SEC(1) + =} + + reaction(shutdown) {= + if (self.received == 0): + sys.stderr.write("ERROR: Final reactor received no data.\n") + exit(3) + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= f.x.set(42) =} + reaction(t) -> f.x {= f.x.set(42) =} } diff --git a/test/Python/src/AfterCycles.lf b/test/Python/src/AfterCycles.lf index cd0f0dd98e..38ee982c6e 100644 --- a/test/Python/src/AfterCycles.lf +++ b/test/Python/src/AfterCycles.lf @@ -1,58 +1,58 @@ -# This tests that "after" does not introduce spurious cycles. Success if running -# without detected a cycle. +# This tests that "after" does not introduce spurious cycles. Success if running without detected a +# cycle. target Python reactor Source { - output out + output out - reaction(startup) -> out {= out.set(1) =} + reaction(startup) -> out {= out.set(1) =} } reactor Work { - input _in - output out + input _in + output out - reaction(_in) -> out {= out.set(_in.value) =} + reaction(_in) -> out {= out.set(_in.value) =} } main reactor AfterCycles { - state count = 0 - s = new Source() - w0 = new Work() - w1 = new Work() - - s.out -> w0._in after 10 msec - s.out -> w1._in after 20 msec - - reaction(w0.out) {= - self.count+=1 - elapsed_time = lf.time.logical_elapsed() - print("Received {:d} from worker 0 at time {:d}.".format(w0.out.value, elapsed_time)) - if elapsed_time != MSEC(10): - sys.stderr.write("Time should have been 10000000.\n") - exit(1) - - if w0.out.value != 1: - sys.stderr.write("Value should have been 1.\n") - exit(4) - =} - - reaction(w1.out) {= - self.count+=1 - elapsed_time = lf.time.logical_elapsed() - print("Received {:d} from worker 1 at time {:d}.".format(w1.out.value, elapsed_time)) - if elapsed_time != MSEC(20): - sys.stderr.write("Time should have been 20000000.\n") - exit(3) - - if w1.out.value != 1: - sys.stderr.write("Value should have been 1.\n") - exit(4) - =} - - reaction(shutdown) {= - if self.count != 2: - sys.stderr.write("Top-level reactions should have been triggered but were not.\n") - exit(5) - =} + state count = 0 + s = new Source() + w0 = new Work() + w1 = new Work() + + s.out -> w0._in after 10 msec + s.out -> w1._in after 20 msec + + reaction(w0.out) {= + self.count+=1 + elapsed_time = lf.time.logical_elapsed() + print("Received {:d} from worker 0 at time {:d}.".format(w0.out.value, elapsed_time)) + if elapsed_time != MSEC(10): + sys.stderr.write("Time should have been 10000000.\n") + exit(1) + + if w0.out.value != 1: + sys.stderr.write("Value should have been 1.\n") + exit(4) + =} + + reaction(w1.out) {= + self.count+=1 + elapsed_time = lf.time.logical_elapsed() + print("Received {:d} from worker 1 at time {:d}.".format(w1.out.value, elapsed_time)) + if elapsed_time != MSEC(20): + sys.stderr.write("Time should have been 20000000.\n") + exit(3) + + if w1.out.value != 1: + sys.stderr.write("Value should have been 1.\n") + exit(4) + =} + + reaction(shutdown) {= + if self.count != 2: + sys.stderr.write("Top-level reactions should have been triggered but were not.\n") + exit(5) + =} } diff --git a/test/Python/src/AfterOverlapped.lf b/test/Python/src/AfterOverlapped.lf index 32657f1cdb..ec090046f4 100644 --- a/test/Python/src/AfterOverlapped.lf +++ b/test/Python/src/AfterOverlapped.lf @@ -1,41 +1,41 @@ # This the after keyword with overlapped time intervals. target Python { - fast: true, - timeout: 5 sec + fast: true, + timeout: 5 sec } import Count from "lib/Count.lf" reactor Test { - input c - state i = 0 - state received = 0 + input c + state i = 0 + state received = 0 - reaction(c) {= - self.received += 1 - print(f"Received {c.value}.") - self.i += 1 - if c.value != self.i: - sys.stderr.write("ERROR: Expected {:d} but got {:d}\n.".format(self.i, c.value)); - exit(1) - elapsed_time = lf.time.logical_elapsed() - print("Current logical time is: ", elapsed_time) + reaction(c) {= + self.received += 1 + print(f"Received {c.value}.") + self.i += 1 + if c.value != self.i: + sys.stderr.write("ERROR: Expected {:d} but got {:d}\n.".format(self.i, c.value)); + exit(1) + elapsed_time = lf.time.logical_elapsed() + print("Current logical time is: ", elapsed_time) - expected_logical_time = SEC(2) + SEC(1)*(c.value - 1) - if elapsed_time != expected_logical_time: - sys.stderr.write("ERROR: Expected logical time to be {:d} but got {:d}\n.".format(expected_logical_time, elapsed_time)) - exit(1) - =} + expected_logical_time = SEC(2) + SEC(1)*(c.value - 1) + if elapsed_time != expected_logical_time: + sys.stderr.write("ERROR: Expected logical time to be {:d} but got {:d}\n.".format(expected_logical_time, elapsed_time)) + exit(1) + =} - reaction(shutdown) {= - if self.received == 0: - sys.stderr.write("ERROR: Final reactor received no data.\n") - exit(3) - =} + reaction(shutdown) {= + if self.received == 0: + sys.stderr.write("ERROR: Final reactor received no data.\n") + exit(3) + =} } main reactor AfterOverlapped { - count = new Count() - test = new Test() - count.out -> test.c after 2 sec + count = new Count() + test = new Test() + count.out -> test.c after 2 sec } diff --git a/test/Python/src/ArrayAsParameter.lf b/test/Python/src/ArrayAsParameter.lf index 359e38b7a3..ad5fe3c15e 100644 --- a/test/Python/src/ArrayAsParameter.lf +++ b/test/Python/src/ArrayAsParameter.lf @@ -2,41 +2,41 @@ target Python reactor Source(sequence(0, 1, 2)) { - output out - state count = 0 - logical action next + output out + state count = 0 + logical action next - reaction(startup, next) -> out, next {= - out.set(self.sequence[self.count]) - self.count+=1 - if self.count < len(self.sequence): - next.schedule(0) - =} + reaction(startup, next) -> out, next {= + out.set(self.sequence[self.count]) + self.count+=1 + if self.count < len(self.sequence): + next.schedule(0) + =} } reactor Print { - input _in - state count = 1 - state received = 0 + input _in + state count = 1 + state received = 0 - reaction(_in) {= - self.received+=1 - print("Received: {:d}\n".format(_in.value)) - if _in.value != self.count: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count)) - exit(1) - self.count+=1 - =} + reaction(_in) {= + self.received+=1 + print("Received: {:d}\n".format(_in.value)) + if _in.value != self.count: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count)) + exit(1) + self.count+=1 + =} - reaction(shutdown) {= - if self.received == 0: - sys.stderr.write("ERROR: Final reactor received no data.\n") - exit(3) - =} + reaction(shutdown) {= + if self.received == 0: + sys.stderr.write("ERROR: Final reactor received no data.\n") + exit(3) + =} } main reactor ArrayAsParameter { - s = new Source(sequence(1, 2, 3, 4)) - p = new Print() - s.out -> p._in + s = new Source(sequence(1, 2, 3, 4)) + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/ArrayAsType.lf b/test/Python/src/ArrayAsType.lf index dc3b2f6e26..de1490d332 100644 --- a/test/Python/src/ArrayAsType.lf +++ b/test/Python/src/ArrayAsType.lf @@ -1,29 +1,29 @@ -# Source produces a statically allocated array, which it passes to Print. The -# destination references the array directly. +# Source produces a statically allocated array, which it passes to Print. The destination references +# the array directly. target Python reactor Source { - output out + output out - reaction(startup) -> out {= - # Pass on a tuple to out - out.set((0, 2.8, "hello")) - =} + reaction(startup) -> out {= + # Pass on a tuple to out + out.set((0, 2.8, "hello")) + =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input _in + input _in - reaction(_in) {= - print("Received: [%s]" % ", ".join(map(str, _in.value))) - if _in.value != (0, 2.8, "hello"): - sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") - exit(1) - =} + reaction(_in) {= + print("Received: [%s]" % ", ".join(map(str, _in.value))) + if _in.value != (0, 2.8, "hello"): + sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") + exit(1) + =} } main reactor ArrayAsType { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/ArrayFree.lf b/test/Python/src/ArrayFree.lf index 2ea2777c12..24f9b4b754 100644 --- a/test/Python/src/ArrayFree.lf +++ b/test/Python/src/ArrayFree.lf @@ -1,27 +1,27 @@ -# Source produces a dynamically allocated array, which it passes to Free. Free -# requests a writable copy, which, instead of copying, it just gets ownership of -# the original array. It then does nothing further with it. This test checks -# that the memory gets freed automatically even with the mutable input. +# Source produces a dynamically allocated array, which it passes to Free. Free requests a writable +# copy, which, instead of copying, it just gets ownership of the original array. It then does +# nothing further with it. This test checks that the memory gets freed automatically even with the +# mutable input. target Python import Source, Print from "ArrayPrint.lf" import Scale from "ArrayScale.lf" reactor Free(scale = 2) { - mutable input _in + mutable input _in - reaction(_in) {= - for i in range(len(_in.value)): - _in.value[i] *= self.scale - =} + reaction(_in) {= + for i in range(len(_in.value)): + _in.value[i] *= self.scale + =} } main reactor ArrayFree { - s = new Source() - c = new Free() - c2 = new Scale() - p = new Print(scale = 2) - s.out -> c._in - s.out -> c2._in - c2.out -> p._in + s = new Source() + c = new Free() + c2 = new Scale() + p = new Print(scale = 2) + s.out -> c._in + s.out -> c2._in + c2.out -> p._in } diff --git a/test/Python/src/ArrayPrint.lf b/test/Python/src/ArrayPrint.lf index 4420311b93..f13d44c7bf 100644 --- a/test/Python/src/ArrayPrint.lf +++ b/test/Python/src/ArrayPrint.lf @@ -1,29 +1,29 @@ -# Source produces a dynamically allocated array, which it passes to Print. -# Reference counting ensures that the array is freed. +# Source produces a dynamically allocated array, which it passes to Print. Reference counting +# ensures that the array is freed. target Python reactor Source { - output out + output out - reaction(startup) -> out {= - # Dynamically allocate an output array of length 3 and populate it. - out.set([0,1,2]) - =} + reaction(startup) -> out {= + # Dynamically allocate an output array of length 3 and populate it. + out.set([0,1,2]) + =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input _in + input _in - reaction(_in) {= - print("Received: [%s]" % ", ".join(map(str, _in.value))) - if _in.value != [x * self.scale for x in [0, 1, 2]]: - sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") - exit(1) - =} + reaction(_in) {= + print("Received: [%s]" % ", ".join(map(str, _in.value))) + if _in.value != [x * self.scale for x in [0, 1, 2]]: + sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") + exit(1) + =} } main reactor ArrayPrint { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/ArrayScale.lf b/test/Python/src/ArrayScale.lf index 2b69aebe77..a174053b2c 100644 --- a/test/Python/src/ArrayScale.lf +++ b/test/Python/src/ArrayScale.lf @@ -1,26 +1,25 @@ -# Source produces a dynamically allocated array, which it passes to Scale. Scale -# requests a writable copy, which, instead of copying, it just gets ownership of -# the original array. It modifies it and passes it to Print. It gets freed after -# Print is done with it. +# Source produces a dynamically allocated array, which it passes to Scale. Scale requests a writable +# copy, which, instead of copying, it just gets ownership of the original array. It modifies it and +# passes it to Print. It gets freed after Print is done with it. target Python import Print, Source from "ArrayPrint.lf" reactor Scale(scale = 2) { - mutable input _in - output out + mutable input _in + output out - reaction(_in) -> out {= - for i in range(len(_in.value)): - _in.value[i] *= self.scale - out.set(_in.value) - =} + reaction(_in) -> out {= + for i in range(len(_in.value)): + _in.value[i] *= self.scale + out.set(_in.value) + =} } main reactor ArrayScale { - s = new Source() - c = new Scale() - p = new Print(scale = 2) - s.out -> c._in - c.out -> p._in + s = new Source() + c = new Scale() + p = new Print(scale = 2) + s.out -> c._in + c.out -> p._in } diff --git a/test/Python/src/CompareTags.lf b/test/Python/src/CompareTags.lf index fc6449dbff..462d57864e 100644 --- a/test/Python/src/CompareTags.lf +++ b/test/Python/src/CompareTags.lf @@ -1,31 +1,31 @@ # Tests the lf.tag_compare() function in the python target. target Python { - timeout: 10 msec, - fast: false + timeout: 10 msec, + fast: false } main reactor CompareTags { - preamble {= import sys =} - timer t(0, 1 msec) - logical action l + preamble {= import sys =} + timer t(0, 1 msec) + logical action l - reaction(t) -> l {= - tag1 = lf.tag() - tag2 = lf.tag() - if (lf.tag_compare(tag1, tag2) != 0 or not tag1 == tag2 or tag1 != tag2): - self.sys.stderr.write("Tags should be equal\n") - self.sys.exit(1) - l.schedule(0, tag1) - =} + reaction(t) -> l {= + tag1 = lf.tag() + tag2 = lf.tag() + if (lf.tag_compare(tag1, tag2) != 0 or not tag1 == tag2 or tag1 != tag2): + self.sys.stderr.write("Tags should be equal\n") + self.sys.exit(1) + l.schedule(0, tag1) + =} - reaction(l) {= - tag3 = lf.tag() - tag1 = l.value - if (lf.tag_compare(tag1, tag3) != -1 or not tag1 < tag3 or tag1 >= tag3): - self.sys.stderr.write("tag1 should be lesser than tag3\n") - self.sys.exit(1) - if (lf.tag_compare(tag3, tag1) != 1 or not tag3 > tag1 or tag3 <= tag1): - self.sys.stderr.write("tag3 should be greater than tag1\n") - self.sys.exit(1) - =} + reaction(l) {= + tag3 = lf.tag() + tag1 = l.value + if (lf.tag_compare(tag1, tag3) != -1 or not tag1 < tag3 or tag1 >= tag3): + self.sys.stderr.write("tag1 should be lesser than tag3\n") + self.sys.exit(1) + if (lf.tag_compare(tag3, tag1) != 1 or not tag3 > tag1 or tag3 <= tag1): + self.sys.stderr.write("tag3 should be greater than tag1\n") + self.sys.exit(1) + =} } diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index d1bef93ed2..d4b36c0a76 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -1,44 +1,43 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period = 2 sec) { - output y - timer t(1 sec, period) - state count = 0 + output y + timer t(1 sec, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - print("Source sending " + str(self.count)) - #print("y value is " + str(y.value)) - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + print("Source sending " + str(self.count)) + #print("y value is " + str(y.value)) + y.set(self.count) + =} } reactor Test { - input x - state count = 0 + input x + state count = 0 - reaction(x) {= - self.count += 1 - print("Recieved " + str(x.value)) - if (x.value != self.count): - sys.stderr.write("FAILURE: Expected " + str(self.count) + "\n") - exit(1) - =} + reaction(x) {= + self.count += 1 + print("Recieved " + str(x.value)) + if (x.value != self.count): + sys.stderr.write("FAILURE: Expected " + str(self.count) + "\n") + exit(1) + =} - reaction(shutdown) {= - if(self.count == 0): - sys.stderr.write("FAILURE: No data received.\n") - =} + reaction(shutdown) {= + if(self.count == 0): + sys.stderr.write("FAILURE: No data received.\n") + =} } main reactor Composition { - s = new Source() + s = new Source() - d = new Test() - s.y -> d.x + d = new Test() + s.y -> d.x } diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index 00b95e3ab9..49b2f0012a 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -1,36 +1,35 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period = 2 sec) { - output y - timer t(1 sec, period) - state count = 0 + output y + timer t(1 sec, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + y.set(self.count) + =} } reactor Test { - input x - state count = 0 + input x + state count = 0 - reaction(x) {= - self.count += 1 - print("Received ", x.value) - if x.value != self.count: - sys.stderr.write("FAILURE: Expected %d\n", self.count) - exit(1) - =} + reaction(x) {= + self.count += 1 + print("Received ", x.value) + if x.value != self.count: + sys.stderr.write("FAILURE: Expected %d\n", self.count) + exit(1) + =} } main reactor(delay = 5 sec) { - s = new Source() - d = new Test() - s.y -> d.x after delay + s = new Source() + d = new Test() + s.y -> d.x after delay } diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index 4b0e4a38c9..8765192cc7 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -1,54 +1,53 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec } reactor Source(period = 2 sec) { - input foo - output y - timer t(1 sec, period) - state count = 0 - - reaction(t) -> y {= - print("Hello World. My count is: ", self.count) - y.set(self.count) - =} + input foo + output y + timer t(1 sec, period) + state count = 0 + + reaction(t) -> y {= + print("Hello World. My count is: ", self.count) + y.set(self.count) + =} } reactor SourceExtended extends Source { - output y2 - timer t2(1 sec, 3 sec) - - reaction(t2) -> y2 {= - self.count += 1 - print("Source sending ", self.count) - y2.set(self.count) - =} + output y2 + timer t2(1 sec, 3 sec) + + reaction(t2) -> y2 {= + self.count += 1 + print("Source sending ", self.count) + y2.set(self.count) + =} } reactor Test { - input x - state count = 0 - - reaction(x) {= - self.count += 1 - print("Received ", x.value) - if x.value != self.count: - sys.stderr.write("FAILURE: Expected %d\n", self.count) - exit(1) - =} - - reaction(shutdown) {= - if self.count == 0: - sys.stderr.write("FAILURE: No data received.\n") - =} + input x + state count = 0 + + reaction(x) {= + self.count += 1 + print("Received ", x.value) + if x.value != self.count: + sys.stderr.write("FAILURE: Expected %d\n", self.count) + exit(1) + =} + + reaction(shutdown) {= + if self.count == 0: + sys.stderr.write("FAILURE: No data received.\n") + =} } main reactor { - s = new SourceExtended() + s = new SourceExtended() - d = new Test() - s.y2 -> d.x + d = new Test() + s.y2 -> d.x } diff --git a/test/Python/src/CountSelf.lf b/test/Python/src/CountSelf.lf index 74219e6fe0..8fe1d4915b 100644 --- a/test/Python/src/CountSelf.lf +++ b/test/Python/src/CountSelf.lf @@ -1,40 +1,40 @@ # This tests actions with payloads by delaying an input by a fixed amount. target Python { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor CountSelf2(delay = 100 msec) { - output out - logical action a + output out + logical action a - reaction(startup) -> a, out {= - out.set(0) - a.schedule(self.delay, 1) - =} + reaction(startup) -> a, out {= + out.set(0) + a.schedule(self.delay, 1) + =} - reaction(a) -> a, out {= - out.set(a.value) - a.schedule(self.delay, a.value + 1) - =} + reaction(a) -> a, out {= + out.set(a.value) + a.schedule(self.delay, a.value + 1) + =} } reactor Test { - input _in - state count = 0 + input _in + state count = 0 - reaction(_in) {= - print("Received: {:d}".format(_in.value)) - if _in.value != self.count: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count)) - exit(1) + reaction(_in) {= + print("Received: {:d}".format(_in.value)) + if _in.value != self.count: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count)) + exit(1) - self.count+=1 - =} + self.count+=1 + =} } main reactor { - d = new CountSelf2() - t = new Test() - d.out -> t._in + d = new CountSelf2() + t = new Test() + d.out -> t._in } diff --git a/test/Python/src/CountTest.lf b/test/Python/src/CountTest.lf index 06c4a6fdb6..6e178cbcb0 100644 --- a/test/Python/src/CountTest.lf +++ b/test/Python/src/CountTest.lf @@ -1,31 +1,31 @@ target Python { - timeout: 3 sec, - fast: true + timeout: 3 sec, + fast: true } import Count from "lib/Count.lf" reactor Test { - input c - state i = 0 + input c + state i = 0 - reaction(c) {= - print("Received ", c.value) - self.i +=1 - if c.value != self.i: - sys.stderr.write("ERROR: Expected {:d} but got {:d}\n.".format(self.i, c.value)) - exit(1) - =} + reaction(c) {= + print("Received ", c.value) + self.i +=1 + if c.value != self.i: + sys.stderr.write("ERROR: Expected {:d} but got {:d}\n.".format(self.i, c.value)) + exit(1) + =} - reaction(shutdown) {= - if self.i != 4: - sys.stderr.write("ERROR: Test should have reacted 4 times, but reacted {:d} times.\n".format(self.i)) - exit(2) - =} + reaction(shutdown) {= + if self.i != 4: + sys.stderr.write("ERROR: Test should have reacted 4 times, but reacted {:d} times.\n".format(self.i)) + exit(2) + =} } main reactor CountTest { - count = new Count() - test = new Test() - count.out -> test.c + count = new Count() + test = new Test() + count.out -> test.c } diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index ceab2b28e2..1104c80e86 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -1,53 +1,52 @@ -# This example illustrates local deadline handling. Even numbers are sent by the -# Source immediately, whereas odd numbers are sent after a big enough delay to -# violate the deadline. +# This example illustrates local deadline handling. Even numbers are sent by the Source immediately, +# whereas odd numbers are sent after a big enough delay to violate the deadline. target Python { - timeout: 6 sec + timeout: 6 sec } preamble {= import time =} reactor Source(period = 3 sec) { - output y - timer t(0, period) - state count = 0 - - reaction(t) -> y {= - if self.count % 2 != 0: - # The count variable is odd. - # Take time to cause a deadline violation. - time.sleep(1.5) - - print("Source sends: ", self.count) - y.set(self.count) - self.count += 1 - =} + output y + timer t(0, period) + state count = 0 + + reaction(t) -> y {= + if self.count % 2 != 0: + # The count variable is odd. + # Take time to cause a deadline violation. + time.sleep(1.5) + + print("Source sends: ", self.count) + y.set(self.count) + self.count += 1 + =} } reactor Destination(timeout = 1 sec) { - input x - state count = 0 - - reaction(x) {= - print("Destination receives: ", x.value) - if self.count % 2 != 0: - # The count variable is odd, so the deadline should have been violated. - sys.stderr.write("ERROR: Failed to detect deadline.\n") - exit(1) - - self.count += 1 - =} deadline(timeout) {= - print("Destination deadline handler receives: ", x.value) - if self.count % 2 == 0: - # The count variable is even, so the deadline should not have been violated. - sys.stderr.write("ERROR: Deadline miss handler invoked without deadline violation.\n") - exit(2) - self.count += 1 - =} + input x + state count = 0 + + reaction(x) {= + print("Destination receives: ", x.value) + if self.count % 2 != 0: + # The count variable is odd, so the deadline should have been violated. + sys.stderr.write("ERROR: Failed to detect deadline.\n") + exit(1) + + self.count += 1 + =} deadline(timeout) {= + print("Destination deadline handler receives: ", x.value) + if self.count % 2 == 0: + # The count variable is even, so the deadline should not have been violated. + sys.stderr.write("ERROR: Deadline miss handler invoked without deadline violation.\n") + exit(2) + self.count += 1 + =} } main reactor Deadline { - s = new Source() - d = new Destination(timeout = 1 sec) - s.y -> d.x + s = new Source() + d = new Destination(timeout = 1 sec) + s.y -> d.x } diff --git a/test/Python/src/DeadlineHandledAbove.lf b/test/Python/src/DeadlineHandledAbove.lf index 1259253cea..575b9df49e 100644 --- a/test/Python/src/DeadlineHandledAbove.lf +++ b/test/Python/src/DeadlineHandledAbove.lf @@ -1,42 +1,42 @@ -# Test a deadline where the deadline violation produces an output and the -# container reacts to that output. +# Test a deadline where the deadline violation produces an output and the container reacts to that +# output. target Python preamble {= import time =} reactor Deadline(threshold = 100 msec) { - input x - output deadline_violation + input x + output deadline_violation - reaction(x) -> deadline_violation {= - sys.stderr.write("ERROR: Deadline violation was not detected!\n") - exit(1) - =} deadline(threshold) {= - print("Deadline violation detected.") - deadline_violation.set(True) - =} + reaction(x) -> deadline_violation {= + sys.stderr.write("ERROR: Deadline violation was not detected!\n") + exit(1) + =} deadline(threshold) {= + print("Deadline violation detected.") + deadline_violation.set(True) + =} } main reactor DeadlineHandledAbove { - state violation_detected = False - d = new Deadline(threshold = 10 msec) + state violation_detected = False + d = new Deadline(threshold = 10 msec) - reaction(startup) -> d.x {= - time.sleep(0.2) - d.x.set(42) - =} + reaction(startup) -> d.x {= + time.sleep(0.2) + d.x.set(42) + =} - reaction(d.deadline_violation) {= - if d.deadline_violation.value is True: - print("Output successfully produced by deadline miss handler.") - self.violation_detected = True - =} + reaction(d.deadline_violation) {= + if d.deadline_violation.value is True: + print("Output successfully produced by deadline miss handler.") + self.violation_detected = True + =} - reaction(shutdown) {= - if self.violation_detected is True: - print("SUCCESS. Test passes.") - else: - sys.stderr.write("FAILURE. Container did not react to deadline violation.\n") - exit(2) - =} + reaction(shutdown) {= + if self.violation_detected is True: + print("SUCCESS. Test passes.") + else: + sys.stderr.write("FAILURE. Container did not react to deadline violation.\n") + exit(2) + =} } diff --git a/test/Python/src/DelayArray.lf b/test/Python/src/DelayArray.lf index 945b786cca..b931821682 100644 --- a/test/Python/src/DelayArray.lf +++ b/test/Python/src/DelayArray.lf @@ -2,44 +2,43 @@ target Python reactor DelayPointer(delay = 100 msec) { - # The Python target does not require explicit type allocation for types - # other than time - mutable input _in - output out - logical action a - - reaction(_in) -> a {= - # mutable input guarantees in will not be freed. - a.schedule(self.delay, _in.value); - =} - - reaction(a) -> out {= out.set(a.value); =} + # The Python target does not require explicit type allocation for types other than time + mutable input _in + output out + logical action a + + reaction(_in) -> a {= + # mutable input guarantees in will not be freed. + a.schedule(self.delay, _in.value); + =} + + reaction(a) -> out {= out.set(a.value); =} } reactor Source { - output out + output out - reaction(startup) -> out {= - # Send an output list of length 3. - out.set([0, 1, 2]) - =} + reaction(startup) -> out {= + # Send an output list of length 3. + out.set([0, 1, 2]) + =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input _in - - reaction(_in) {= - print("Received: [%s]" % ", ".join(map(str, _in.value))) - if _in.value != [x * self.scale for x in [0, 1, 2]]: - sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") - exit(1) - =} + input _in + + reaction(_in) {= + print("Received: [%s]" % ", ".join(map(str, _in.value))) + if _in.value != [x * self.scale for x in [0, 1, 2]]: + sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") + exit(1) + =} } main reactor DelayArray { - s = new Source() - d = new DelayPointer() - p = new Print() - s.out -> d._in - d.out -> p._in + s = new Source() + d = new DelayPointer() + p = new Print() + s.out -> d._in + d.out -> p._in } diff --git a/test/Python/src/DelayArrayWithAfter.lf b/test/Python/src/DelayArrayWithAfter.lf index 1e6ac1f317..1567074c22 100644 --- a/test/Python/src/DelayArrayWithAfter.lf +++ b/test/Python/src/DelayArrayWithAfter.lf @@ -1,52 +1,51 @@ -# This tests transport of dynamically allocated arrays over connections with -# 'after'. +# This tests transport of dynamically allocated arrays over connections with 'after'. target Python { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out - state iteration = 1 - timer t(0, 1 sec) + output out + state iteration = 1 + timer t(0, 1 sec) - reaction(t) -> out {= - out.set([(x * self.iteration) for x in [1,2,3]]) - print("At time {:d}, sending list ".format(lf.time.logical_elapsed()), out.value) + reaction(t) -> out {= + out.set([(x * self.iteration) for x in [1,2,3]]) + print("At time {:d}, sending list ".format(lf.time.logical_elapsed()), out.value) - self.iteration += 1 - =} + self.iteration += 1 + =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input _in - state iteration = 1 - state inputs_received = 0 - - reaction(_in) {= - self.inputs_received += 1 - - print("At time {:d}, received list ".format(lf.time.logical_elapsed()), _in.value) - print("Received: [%s]" % ", ".join(map(str, _in.value))) - if _in.value != [(x * self.scale * self.iteration) for x in [1, 2, 3]]: - sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") - exit(1) - if len(_in.value) != 3: - sys.stderr.write("ERROR: Received list length is not 3!\n") - exit(2) - - self.iteration += 1 - =} - - reaction(shutdown) {= - if self.inputs_received == 0: - sys.stderr.write("ERROR: Print reactor received no inputs.\n") - exit(3) - =} + input _in + state iteration = 1 + state inputs_received = 0 + + reaction(_in) {= + self.inputs_received += 1 + + print("At time {:d}, received list ".format(lf.time.logical_elapsed()), _in.value) + print("Received: [%s]" % ", ".join(map(str, _in.value))) + if _in.value != [(x * self.scale * self.iteration) for x in [1, 2, 3]]: + sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") + exit(1) + if len(_in.value) != 3: + sys.stderr.write("ERROR: Received list length is not 3!\n") + exit(2) + + self.iteration += 1 + =} + + reaction(shutdown) {= + if self.inputs_received == 0: + sys.stderr.write("ERROR: Print reactor received no inputs.\n") + exit(3) + =} } main reactor DelayArrayWithAfter { - s = new Source() - p = new Print() - s.out -> p._in after 1500 msec + s = new Source() + p = new Print() + s.out -> p._in after 1500 msec } diff --git a/test/Python/src/DelayInt.lf b/test/Python/src/DelayInt.lf index fae554bd30..52d78dd47e 100644 --- a/test/Python/src/DelayInt.lf +++ b/test/Python/src/DelayInt.lf @@ -2,55 +2,55 @@ target Python reactor Delay(delay = 100 msec) { - input _in - output out - logical action a + input _in + output out + logical action a - reaction(a) -> out {= - if (a.value is not None) and a.is_present: - out.set(a.value) - =} + reaction(a) -> out {= + if (a.value is not None) and a.is_present: + out.set(a.value) + =} - reaction(_in) -> a {= a.schedule(self.delay, _in.value) =} + reaction(_in) -> a {= a.schedule(self.delay, _in.value) =} } reactor Test { - input _in - state start_time = 0 - state received_value = False - - reaction(startup) {= - # Record the logical time at the start. - self.start_time = lf.time.logical() - =} - - reaction(_in) {= - print("Received: ", _in.value) - self.received_value = True - # Check the time of the input. - current_time = lf.time.logical() - elapsed = current_time - self.start_time - print("After {:d} nsec of logical time.\n".format(elapsed)) - if elapsed != 100000000: - sys.stderr.write("ERROR: Expected elapsed time to be 100000000. It was {:d}.\n".format(elapsed)) - exit(1) - if _in.value != 42: - sys.stderr.write("ERROR: Expected input value to be 42. It was {:d}.\n".format(_in.value)) - exit(2) - =} - - reaction(shutdown) {= - print("Checking that communication occurred.") - if self.received_value is not True: - sys.stderr.write("ERROR: No communication occurred!\n") - exit(3) - =} + input _in + state start_time = 0 + state received_value = False + + reaction(startup) {= + # Record the logical time at the start. + self.start_time = lf.time.logical() + =} + + reaction(_in) {= + print("Received: ", _in.value) + self.received_value = True + # Check the time of the input. + current_time = lf.time.logical() + elapsed = current_time - self.start_time + print("After {:d} nsec of logical time.\n".format(elapsed)) + if elapsed != 100000000: + sys.stderr.write("ERROR: Expected elapsed time to be 100000000. It was {:d}.\n".format(elapsed)) + exit(1) + if _in.value != 42: + sys.stderr.write("ERROR: Expected input value to be 42. It was {:d}.\n".format(_in.value)) + exit(2) + =} + + reaction(shutdown) {= + print("Checking that communication occurred.") + if self.received_value is not True: + sys.stderr.write("ERROR: No communication occurred!\n") + exit(3) + =} } main reactor DelayInt { - d = new Delay() - t = new Test() - d.out -> t._in + d = new Delay() + t = new Test() + d.out -> t._in - reaction(startup) -> d._in {= d._in.set(42) =} + reaction(startup) -> d._in {= d._in.set(42) =} } diff --git a/test/Python/src/DelayString.lf b/test/Python/src/DelayString.lf index d1201dec02..e5462b60e8 100644 --- a/test/Python/src/DelayString.lf +++ b/test/Python/src/DelayString.lf @@ -1,39 +1,38 @@ -# This tests actions with immutable payloads that are neither malloc'd nor -# freed. +# This tests actions with immutable payloads that are neither malloc'd nor freed. target Python reactor DelayString2(delay = 100 msec) { - input _in - output out - logical action a + input _in + output out + logical action a - reaction(a) -> out {= out.set(a.value) =} + reaction(a) -> out {= out.set(a.value) =} - reaction(_in) -> a {= a.schedule(self.delay, _in.value) =} + reaction(_in) -> a {= a.schedule(self.delay, _in.value) =} } reactor Test { - input _in - state start_time = 0 + input _in + state start_time = 0 - reaction(_in) {= - print("Received: ", _in.value) - # Check the time of the input. - elapsed = lf.time.logical_elapsed() - print("After {:d} nsec of logical time.\n".format(elapsed)) - if elapsed != 100000000: - sys.stderr.write("ERROR: Expected elapsed time to be 100000000. It was {:d}.\n".format(elapsed)) - exit(1) - if _in.value != "Hello": - sys.stderr.write("ERROR: Expected input value to be 'Hello'. It was '{:s}'.\n".format(_in.value)) - exit(2) - =} + reaction(_in) {= + print("Received: ", _in.value) + # Check the time of the input. + elapsed = lf.time.logical_elapsed() + print("After {:d} nsec of logical time.\n".format(elapsed)) + if elapsed != 100000000: + sys.stderr.write("ERROR: Expected elapsed time to be 100000000. It was {:d}.\n".format(elapsed)) + exit(1) + if _in.value != "Hello": + sys.stderr.write("ERROR: Expected input value to be 'Hello'. It was '{:s}'.\n".format(_in.value)) + exit(2) + =} } main reactor { - d = new DelayString2() - t = new Test() - d.out -> t._in + d = new DelayString2() + t = new Test() + d.out -> t._in - reaction(startup) -> d._in {= d._in.set("Hello") =} + reaction(startup) -> d._in {= d._in.set("Hello") =} } diff --git a/test/Python/src/DelayStruct.lf b/test/Python/src/DelayStruct.lf index e578a42699..94d232011b 100644 --- a/test/Python/src/DelayStruct.lf +++ b/test/Python/src/DelayStruct.lf @@ -1,45 +1,45 @@ # Test delaying a struct pointer type. target Python { - files: ["include/hello.py"] + files: ["include/hello.py"] } preamble {= import hello =} reactor DelayPointer(delay = 100 msec) { - input _in - output out - logical action a + input _in + output out + logical action a - reaction(a) -> out {= out.set(a.value); =} + reaction(a) -> out {= out.set(a.value); =} - reaction(_in) -> a {= - # Schedule the actual token from the input rather than - # a new token with a copy of the input value. - a.schedule(self.delay, _in.value); - =} + reaction(_in) -> a {= + # Schedule the actual token from the input rather than + # a new token with a copy of the input value. + a.schedule(self.delay, _in.value); + =} } reactor Source { - output out + output out - reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} + reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } reactor Print(expected = 42) { # expected parameter is for testing. - input _in - - reaction(_in) {= - print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + input _in + + reaction(_in) {= + print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } main reactor DelayStruct { - s = new Source() - d = new DelayPointer() - p = new Print() - s.out -> d._in - d.out -> p._in + s = new Source() + d = new DelayPointer() + p = new Print() + s.out -> d._in + d.out -> p._in } diff --git a/test/Python/src/DelayStructWithAfter.lf b/test/Python/src/DelayStructWithAfter.lf index 5bb945cb3c..b7d34f127a 100644 --- a/test/Python/src/DelayStructWithAfter.lf +++ b/test/Python/src/DelayStructWithAfter.lf @@ -1,29 +1,29 @@ # This tests delaying a struct using after. target Python { - files: include/hello.py + files: include/hello.py } preamble {= import hello =} reactor Source { - output out + output out - reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} + reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } reactor Print(expected = 42) { # expected parameter is for testing. - input _in + input _in - reaction(_in) {= - print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + reaction(_in) {= + print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } main reactor DelayStructWithAfter { - s = new Source() - p = new Print() - s.out -> p._in after 100 msec + s = new Source() + p = new Print() + s.out -> p._in after 100 msec } diff --git a/test/Python/src/DelayStructWithAfterOverlapped.lf b/test/Python/src/DelayStructWithAfterOverlapped.lf index 072012a106..ed9270de31 100644 --- a/test/Python/src/DelayStructWithAfterOverlapped.lf +++ b/test/Python/src/DelayStructWithAfterOverlapped.lf @@ -1,44 +1,44 @@ # This tests delaying a struct using after. target Python { - timeout: 5 sec, - fast: true, - files: ["include/hello.py"] + timeout: 5 sec, + fast: true, + files: ["include/hello.py"] } preamble {= import hello =} reactor Source { - output out - timer t(0, 1 sec) - state s = 0 + output out + timer t(0, 1 sec) + state s = 0 - reaction(t) -> out {= - self.s += 1 - out.set(hello.hello("Earth", 42 * self.s)) - =} + reaction(t) -> out {= + self.s += 1 + out.set(hello.hello("Earth", 42 * self.s)) + =} } reactor Print { # expected parameter is for testing. - input _in - state s = 0 + input _in + state s = 0 - reaction(_in) {= - self.s += 1 - print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) - if _in.value.value != 42 * self.s: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(42 * self.s)) - exit(1) - =} + reaction(_in) {= + self.s += 1 + print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) + if _in.value.value != 42 * self.s: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(42 * self.s)) + exit(1) + =} - reaction(shutdown) {= - if self.s == 0: - sys.stderr.write("ERROR: Print received no data.\n") - exit(2) - =} + reaction(shutdown) {= + if self.s == 0: + sys.stderr.write("ERROR: Print received no data.\n") + exit(2) + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p._in after 1500 msec + s = new Source() + p = new Print() + s.out -> p._in after 1500 msec } diff --git a/test/Python/src/DelayedAction.lf b/test/Python/src/DelayedAction.lf index 06c488b9c5..5bab6bc7c8 100644 --- a/test/Python/src/DelayedAction.lf +++ b/test/Python/src/DelayedAction.lf @@ -1,24 +1,24 @@ target Python { - fast: true, - timeout: 5 sec + fast: true, + timeout: 5 sec } main reactor DelayedAction { - timer t(0, 1 sec) - logical action a - state count = 0 + timer t(0, 1 sec) + logical action a + state count = 0 - reaction(t) -> a {= a.schedule(MSEC(100)) =} + reaction(t) -> a {= a.schedule(MSEC(100)) =} - reaction(a) {= - elapsed = lf.time.logical_elapsed() - elapsed_physical = lf.time.physical_elapsed() - print("Nanoseconds since start: ", elapsed) - print("Physical nanoseconds since start: ", elapsed_physical) - expected = self.count * 1000000000 + 100000000 - self.count += 1 - if elapsed != expected: - sys.stderr.write("Expected {:d} but got {:d}.\n".format(expected, elapsed)) - exit(1) - =} + reaction(a) {= + elapsed = lf.time.logical_elapsed() + elapsed_physical = lf.time.physical_elapsed() + print("Nanoseconds since start: ", elapsed) + print("Physical nanoseconds since start: ", elapsed_physical) + expected = self.count * 1000000000 + 100000000 + self.count += 1 + if elapsed != expected: + sys.stderr.write("Expected {:d} but got {:d}.\n".format(expected, elapsed)) + exit(1) + =} } diff --git a/test/Python/src/DoubleInvocation.lf b/test/Python/src/DoubleInvocation.lf index aaecfa31cb..36327d815f 100644 --- a/test/Python/src/DoubleInvocation.lf +++ b/test/Python/src/DoubleInvocation.lf @@ -1,52 +1,51 @@ -# This illustrates a very strange bug that showed up and has now been fixed. -# This test ensures it does not reappear. At logical time zero, the two Print -# reactors used to be fired twice each at the same logical time. They should -# only be fired once. This behavior was oddly eliminated by either of the -# following actions, neither of which should affect this behavior: +# This illustrates a very strange bug that showed up and has now been fixed. This test ensures it +# does not reappear. At logical time zero, the two Print reactors used to be fired twice each at the +# same logical time. They should only be fired once. This behavior was oddly eliminated by either of +# the following actions, neither of which should affect this behavior: # * Removing the startup reaction in Print. # * Sending only position, not velocity from Ball. target Python { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Ball { - output position - output velocity - state p = 200 - timer trigger(0, 1 sec) + output position + output velocity + state p = 200 + timer trigger(0, 1 sec) - reaction(trigger) -> position, velocity {= - position.set(self.p) - velocity.set(-1) - self.p -= 1 - =} + reaction(trigger) -> position, velocity {= + position.set(self.p) + velocity.set(-1) + self.p -= 1 + =} } reactor Print { - input velocity - input position - state previous = -1 + input velocity + input position + state previous = -1 - reaction(startup) {= - print("####### Print startup\n") - =} + reaction(startup) {= + print("####### Print startup\n") + =} - reaction(position, velocity) {= - if position.is_present: - print("Position: ", position.value) - if position.value == self.previous: - sys.stderr.write("ERROR: Multiple firings at the same logical time!\n") - exit(1) - =} + reaction(position, velocity) {= + if position.is_present: + print("Position: ", position.value) + if position.value == self.previous: + sys.stderr.write("ERROR: Multiple firings at the same logical time!\n") + exit(1) + =} } main reactor DoubleInvocation { - b1 = new Ball() - p = new Print() - plot = new Print() - b1.position -> p.position - b1.velocity -> p.velocity - b1.position -> plot.position - b1.velocity -> plot.velocity + b1 = new Ball() + p = new Print() + plot = new Print() + b1.position -> p.position + b1.velocity -> p.velocity + b1.position -> plot.position + b1.velocity -> plot.velocity } diff --git a/test/Python/src/DoubleReaction.lf b/test/Python/src/DoubleReaction.lf index c20a032a9a..855dbdfe6a 100644 --- a/test/Python/src/DoubleReaction.lf +++ b/test/Python/src/DoubleReaction.lf @@ -1,44 +1,44 @@ -# Test that two simultaneous inputs that trigger a reaction trigger it only -# once. Correct output for this 2, 4, 6, 8, etc. +# Test that two simultaneous inputs that trigger a reaction trigger it only once. Correct output for +# this 2, 4, 6, 8, etc. target Python { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Clock(offset = 0, period = 1 sec) { - output y - timer t(offset, period) - state count = 0 + output y + timer t(offset, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + y.set(self.count) + =} } reactor Destination { - input x - input w - state s = 2 + input x + input w + state s = 2 - reaction(x, w) {= - sm = 0 - if x.is_present: - sm += x.value - if w.is_present: - sm += w.value - print("Sum of inputs is: ", sm) - if sm != self.s: - sys.stderr.write("FAILURE: Expected sum to be {:d}, but it was {:d}.\n".format(self.s, sm)); - exit(1) - self.s += 2 - =} + reaction(x, w) {= + sm = 0 + if x.is_present: + sm += x.value + if w.is_present: + sm += w.value + print("Sum of inputs is: ", sm) + if sm != self.s: + sys.stderr.write("FAILURE: Expected sum to be {:d}, but it was {:d}.\n".format(self.s, sm)); + exit(1) + self.s += 2 + =} } main reactor DoubleReaction { - c1 = new Clock() - c2 = new Clock() - d = new Destination() - c1.y -> d.x - c2.y -> d.w + c1 = new Clock() + c2 = new Clock() + d = new Destination() + c1.y -> d.x + c2.y -> d.w } diff --git a/test/Python/src/FloatLiteral.lf b/test/Python/src/FloatLiteral.lf index b55953d135..8d1edd93f1 100644 --- a/test/Python/src/FloatLiteral.lf +++ b/test/Python/src/FloatLiteral.lf @@ -1,20 +1,19 @@ target Python -# This test verifies that floating-point literals are handled correctly. -main reactor { - state N = 6.0221409e+23 - state charge = -1.6021766E-19 - state minus_epsilon = -.01e0 - state expected = .964853323188E5 +main reactor { # This test verifies that floating-point literals are handled correctly. + state N = 6.0221409e+23 + state charge = -1.6021766E-19 + state minus_epsilon = -.01e0 + state expected = .964853323188E5 - reaction(startup) {= - F = - self.N * self.charge - if abs(F - self.expected) < abs(self.minus_epsilon): - print("The Faraday constant is roughly {}.".format(F)) - else: - sys.stderr.write("ERROR: Expected {} but got {}.".format( - self.expected, F - )) - exit(1) - =} + reaction(startup) {= + F = - self.N * self.charge + if abs(F - self.expected) < abs(self.minus_epsilon): + print("The Faraday constant is roughly {}.".format(F)) + else: + sys.stderr.write("ERROR: Expected {} but got {}.".format( + self.expected, F + )) + exit(1) + =} } diff --git a/test/Python/src/Gain.lf b/test/Python/src/Gain.lf index d69d4d2a65..769d08f78e 100644 --- a/test/Python/src/Gain.lf +++ b/test/Python/src/Gain.lf @@ -2,36 +2,36 @@ target Python reactor Scale(scale = 2) { - input x - output y + input x + output y - reaction(x) -> y {= y.set(x.value * self.scale) =} + reaction(x) -> y {= y.set(x.value * self.scale) =} } reactor Test { - input x - state received_value = 0 + input x + state received_value = 0 - reaction(x) {= - print("Received " + str(x.value)) - self.received_value = True - if x.value != 2: - sys.stderr.write("ERROR: Expected 2!") - exit(1) - =} + reaction(x) {= + print("Received " + str(x.value)) + self.received_value = True + if x.value != 2: + sys.stderr.write("ERROR: Expected 2!") + exit(1) + =} - reaction(shutdown) {= - if self.received_value is None: - sys.stderr.write("ERROR: No value received by Test reactor!") - else: - sys.stderr.write("Test passes.") - =} + reaction(shutdown) {= + if self.received_value is None: + sys.stderr.write("ERROR: No value received by Test reactor!") + else: + sys.stderr.write("Test passes.") + =} } main reactor Gain { - g = new Scale() - d = new Test() - g.y -> d.x + g = new Scale() + d = new Test() + g.y -> d.x - reaction(startup) -> g.x {= g.x.set(1) =} + reaction(startup) -> g.x {= g.x.set(1) =} } diff --git a/test/Python/src/GetMicroStep.lf b/test/Python/src/GetMicroStep.lf index 124c692ef8..345c953f95 100644 --- a/test/Python/src/GetMicroStep.lf +++ b/test/Python/src/GetMicroStep.lf @@ -1,23 +1,23 @@ # Tests the get_microstep() function in the python target. target Python { - fast: false + fast: false } main reactor GetMicroStep { - preamble {= import sys =} - state s = 1 + preamble {= import sys =} + state s = 1 - logical action l # timer t(0, 1 msec); + logical action l # timer t(0, 1 msec); - reaction(startup) -> l {= l.schedule(0); =} + reaction(startup) -> l {= l.schedule(0); =} - reaction(l) -> l {= - microstep = lf.tag().microstep - if microstep != self.s: - self.sys.stderr.write(f"expected microstep {self.s}, got {microstep} instead\n") - self.sys.exit(1) - self.s += 1 - if self.s < 10: - l.schedule(0) - =} + reaction(l) -> l {= + microstep = lf.tag().microstep + if microstep != self.s: + self.sys.stderr.write(f"expected microstep {self.s}, got {microstep} instead\n") + self.sys.exit(1) + self.s += 1 + if self.s < 10: + l.schedule(0) + =} } diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index 271ed180ca..4f9dd68f47 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -1,52 +1,48 @@ -# This test checks that logical time is incremented an appropriate amount as a -# result of an invocation of the schedule() function at runtime. It also -# performs various smoke tests of timing aligned reactions. The first instance -# has a period of 4 seconds, the second of 2 seconds, and the third (composite) -# or 1 second. +# This test checks that logical time is incremented an appropriate amount as a result of an +# invocation of the schedule() function at runtime. It also performs various smoke tests of timing +# aligned reactions. The first instance has a period of 4 seconds, the second of 2 seconds, and the +# third (composite) or 1 second. target Python { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Reschedule(period = 2 sec, message = "Hello Python") { - state count = 0 - state previous_time = 0 - timer t(1 sec, period) - logical action a + state count = 0 + state previous_time = 0 + timer t(1 sec, period) + logical action a - reaction(t) -> a {= - print(self.message) - a.schedule(MSEC(200)) - # Print the current time. - self.previous_time = lf.time.logical() - secs = self.previous_time/BILLION - print("Current time is ", self.previous_time) - print("Which is {:f} Plus {:d} nanoseconds.\n".format(secs, self.previous_time % BILLION)) - =} + reaction(t) -> a {= + print(self.message) + a.schedule(MSEC(200)) + # Print the current time. + self.previous_time = lf.time.logical() + secs = self.previous_time/BILLION + print("Current time is ", self.previous_time) + print("Which is {:f} Plus {:d} nanoseconds.\n".format(secs, self.previous_time % BILLION)) + =} - reaction(a) {= - self.count += 1 - print("***** action {:d} at time {:d}\n".format(self.count, lf.time.logical())) - # Check if a.value is not None. - if a.value is not None: - sys.stderr.write("FAILURE: Expected a.value to be None, but it exists.\n") - exit(2) - tm = lf.time.logical() - if (tm - self.previous_time) != 200000000: - sys.stderr.write("FAILURE: Expected 200ms of logical time to elapse but got {:d} nanoseconds.\n".format(tm - self.previous_time)) - exit(1) - =} + reaction(a) {= + self.count += 1 + print("***** action {:d} at time {:d}\n".format(self.count, lf.time.logical())) + # Check if a.value is not None. + if a.value is not None: + sys.stderr.write("FAILURE: Expected a.value to be None, but it exists.\n") + exit(2) + tm = lf.time.logical() + if (tm - self.previous_time) != 200000000: + sys.stderr.write("FAILURE: Expected 200ms of logical time to elapse but got {:d} nanoseconds.\n".format(tm - self.previous_time)) + exit(1) + =} } reactor Inside(period = 1 sec, message = "Composite default message.") { - third_instance = new Reschedule(period = period, message = message) + third_instance = new Reschedule(period = period, message = message) } main reactor Hello { - first_instance = new Reschedule( - period = 4 sec, - message = "Hello from first_instance." - ) - second_instance = new Reschedule(message = "Hello from second_instance.") - composite_instance = new Inside(message = "Hello from composite_instance.") + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance.") + second_instance = new Reschedule(message = "Hello from second_instance.") + composite_instance = new Inside(message = "Hello from composite_instance.") } diff --git a/test/Python/src/HelloWorld.lf b/test/Python/src/HelloWorld.lf index 523ff9ce2b..486bea5990 100644 --- a/test/Python/src/HelloWorld.lf +++ b/test/Python/src/HelloWorld.lf @@ -1,23 +1,23 @@ target Python { - tracing: true + tracing: true } reactor HelloWorld2 { - state success = False + state success = False - reaction(startup) {= - print("Hello World.") - self.success = True - =} + reaction(startup) {= + print("Hello World.") + self.success = True + =} - reaction(shutdown) {= - print("Shutdown invoked.") - if not self.success: - sys.stderr.write("ERROR: startup reaction not executed.\n") - sys.exit(1) - =} + reaction(shutdown) {= + print("Shutdown invoked.") + if not self.success: + sys.stderr.write("ERROR: startup reaction not executed.\n") + sys.exit(1) + =} } main reactor HelloWorld { - a = new HelloWorld2() + a = new HelloWorld2() } diff --git a/test/Python/src/Hierarchy2.lf b/test/Python/src/Hierarchy2.lf index a1792712fa..cec5bf4c9f 100644 --- a/test/Python/src/Hierarchy2.lf +++ b/test/Python/src/Hierarchy2.lf @@ -1,69 +1,69 @@ # Test data transport across hierarchy. target Python { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out - timer t(0, 1 sec) + output out + timer t(0, 1 sec) - reaction(t) -> out {= out.set(1) =} + reaction(t) -> out {= out.set(1) =} } reactor Count { - output out - timer t(0, 1 sec) - state i = 0 + output out + timer t(0, 1 sec) + state i = 0 - reaction(t) -> out {= - self.i += 1 - out.set(self.i) - =} + reaction(t) -> out {= + self.i += 1 + out.set(self.i) + =} } reactor Add { - input in1 - input in2 - output out + input in1 + input in2 + output out - reaction(in1, in2) -> out {= - result = 0 - if in1.is_present: - result += in1.value - if in2.is_present: - result += in2.value - out.set(result) - =} + reaction(in1, in2) -> out {= + result = 0 + if in1.is_present: + result += in1.value + if in2.is_present: + result += in2.value + out.set(result) + =} } reactor Print { - input _in - state expected = 2 + input _in + state expected = 2 - reaction(_in) {= - print("Received: ", _in.value) - if _in.value != self.expected: - sys.stderr.write("Expected {:d}.\n".format(self.expected)) - exit(1) - self.expected+=1 - =} + reaction(_in) {= + print("Received: ", _in.value) + if _in.value != self.expected: + sys.stderr.write("Expected {:d}.\n".format(self.expected)) + exit(1) + self.expected+=1 + =} } reactor AddCount { - input _in - output out - count = new Count() - add = new Add() - _in -> add.in1 - count.out -> add.in2 - add.out -> out + input _in + output out + count = new Count() + add = new Add() + _in -> add.in1 + count.out -> add.in2 + add.out -> out } main reactor Hierarchy2 { - source = new Source() - addCount = new AddCount() - print = new Print() - source.out -> addCount._in - addCount.out -> print._in + source = new Source() + addCount = new AddCount() + print = new Print() + source.out -> addCount._in + addCount.out -> print._in } diff --git a/test/Python/src/IdentifierLength.lf b/test/Python/src/IdentifierLength.lf index 62b31141a0..e80c3e3f7a 100644 --- a/test/Python/src/IdentifierLength.lf +++ b/test/Python/src/IdentifierLength.lf @@ -1,43 +1,39 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_The_Maximum_For_The_Python_Target( - period = 2 sec + period = 2 sec ) { - output y - timer t(1 sec, period) - state count = 0 + output y + timer t(1 sec, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + y.set(self.count) + =} } reactor Another_Really_Long_Name_For_A_Test_Class { - input x - state count = 0 + input x + state count = 0 - reaction(x) {= - self.count += 1 - print("Received ", x.value) - if x.value != self.count: - sys.stderr.write("FAILURE: Expected {:d}.\n".format(self.count)) - exit(1) - =} + reaction(x) {= + self.count += 1 + print("Received ", x.value) + if x.value != self.count: + sys.stderr.write("FAILURE: Expected {:d}.\n".format(self.count)) + exit(1) + =} } main reactor IdentifierLength { - a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_The_Maximum_For_The_Python_Target( + a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_The_Maximum_For_The_Python_Target( - ) - another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class( - - ) - a_really_long_name_for_a_source_instance.y - -> another_really_long_name_for_a_test_instance.x + ) + another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class() + a_really_long_name_for_a_source_instance.y -> another_really_long_name_for_a_test_instance.x } diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 369fbcab44..5558db6163 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -1,30 +1,29 @@ -# This tests the ability to import a reactor definition that itself imports a -# reactor definition. +# This tests the ability to import a reactor definition that itself imports a reactor definition. target Python import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { - a = new ImportedComposition() - state received = False + a = new ImportedComposition() + state received = False - reaction(startup) -> a.x {= a.x.set(42) =} + reaction(startup) -> a.x {= a.x.set(42) =} - reaction(a.y) {= - receive_time = lf.time.logical_elapsed() - print("Received {:d} at time {:d}".format(a.y.value, receive_time)) - self.received = True - if receive_time != 55000000: - sys.stderr.write("ERROR: Received time should have been 55,000,000.\n") - exit(1) - if a.y.value != 42 * 2 * 2: - sys.stderr.write("ERROR: Received value should have been {:d}.\n".format(42 * 2 * 2)) - exit(2) - =} + reaction(a.y) {= + receive_time = lf.time.logical_elapsed() + print("Received {:d} at time {:d}".format(a.y.value, receive_time)) + self.received = True + if receive_time != 55000000: + sys.stderr.write("ERROR: Received time should have been 55,000,000.\n") + exit(1) + if a.y.value != 42 * 2 * 2: + sys.stderr.write("ERROR: Received value should have been {:d}.\n".format(42 * 2 * 2)) + exit(2) + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write("ERROR: Nothing received.\n"); - exit(3) - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write("ERROR: Nothing received.\n"); + exit(3) + =} } diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index a9e39829eb..573c588b67 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -1,52 +1,51 @@ target Python { - # Set keepalive to false since this is a test and schedule is called on a - # physical action from within a reaction. This is one of the special rare - # cases where the user might want to manually override keepalive. - keepalive: false + # Set keepalive to false since this is a test and schedule is called on a physical action from + # within a reaction. This is one of the special rare cases where the user might want to manually + # override keepalive. + keepalive: false } -# That's the stuff that shall be generated for the after -reactor GeneratedDelay { - input y_in - output y_out - state y_state = 0 +reactor GeneratedDelay { # That's the stuff that shall be generated for the after + input y_in + output y_out + state y_state = 0 - physical action act(0 msec) # TODO: delay in act or the schedule call? + physical action act(0 msec) # TODO: delay in act or the schedule call? - reaction(y_in) -> act {= - self.y_state = y_in.value - act.schedule(MSEC(100)) - =} + reaction(y_in) -> act {= + self.y_state = y_in.value + act.schedule(MSEC(100)) + =} - reaction(act) -> y_out {= y_out.set(self.y_state) =} + reaction(act) -> y_out {= y_out.set(self.y_state) =} } reactor Source { - output out - timer t + output out + timer t - reaction(t) -> out {= out.set(1) =} # reaction(t) -> out after 100 msec + reaction(t) -> out {= out.set(1) =} # reaction(t) -> out after 100 msec } reactor Sink { - input s_in - - reaction(s_in) {= - elapsed_logical = lf.time.logical_elapsed() - logical = lf.time.logical() - physical = lf.time.physical() - print("Nanoseconds since start: {:d} {:d} {:d}.\n".format(logical, physical, elapsed_logical)) - if elapsed_logical < MSEC(100): - sys.stderr.write("Expected {:d} but got {:d}.\n".format(MSEC(100), elapsed_logical)) - exit(1) - =} deadline(200 msec) {= =} + input s_in + + reaction(s_in) {= + elapsed_logical = lf.time.logical_elapsed() + logical = lf.time.logical() + physical = lf.time.physical() + print("Nanoseconds since start: {:d} {:d} {:d}.\n".format(logical, physical, elapsed_logical)) + if elapsed_logical < MSEC(100): + sys.stderr.write("Expected {:d} but got {:d}.\n".format(MSEC(100), elapsed_logical)) + exit(1) + =} deadline(200 msec) {= =} } main reactor ManualDelayedReaction { - source = new Source() - sink = new Sink() - g = new GeneratedDelay() + source = new Source() + sink = new Sink() + g = new GeneratedDelay() - source.out -> g.y_in # source.out -> sink.s_in; rewritten above - g.y_out -> sink.s_in + source.out -> g.y_in # source.out -> sink.s_in; rewritten above + g.y_out -> sink.s_in } diff --git a/test/Python/src/Methods.lf b/test/Python/src/Methods.lf index 5e0023fe8f..54bdacc825 100644 --- a/test/Python/src/Methods.lf +++ b/test/Python/src/Methods.lf @@ -2,23 +2,23 @@ target Python main reactor { - state foo = 2 + state foo = 2 - method getFoo() {= return self.foo =} + method getFoo() {= return self.foo =} - method add(x) {= self.foo += x =} + method add(x) {= self.foo += x =} - reaction(startup) {= - print(f"Foo is initialized to {self.getFoo()}") - if self.getFoo() != 2: - sys.stderr.write("Expected 2!"); - exit(1) + reaction(startup) {= + print(f"Foo is initialized to {self.getFoo()}") + if self.getFoo() != 2: + sys.stderr.write("Expected 2!"); + exit(1) - self.add(40) - a = self.getFoo() - print(f"2 + 40 = {a}") - if a != 42: - sys.stderr.write("Expected 42!"); - exit(1) - =} + self.add(40) + a = self.getFoo() + print(f"2 + 40 = {a}") + if a != 42: + sys.stderr.write("Expected 42!"); + exit(1) + =} } diff --git a/test/Python/src/MethodsRecursive.lf b/test/Python/src/MethodsRecursive.lf index 81afc86bea..a1fa182792 100644 --- a/test/Python/src/MethodsRecursive.lf +++ b/test/Python/src/MethodsRecursive.lf @@ -2,18 +2,18 @@ target Python main reactor { - state foo = 2 + state foo = 2 - method fib(n) {= # Return the n-th Fibonacci number. - if n <= 1: - return 1 - return self.add(self.fib(n-1), self.fib(n-2)) - =} + method fib(n) {= # Return the n-th Fibonacci number. + if n <= 1: + return 1 + return self.add(self.fib(n-1), self.fib(n-2)) + =} - method add(x, y) {= return x + y =} + method add(x, y) {= return x + y =} - reaction(startup) {= - for n in range(1, 10): - print(f"{n}-th Fibonacci number is {self.fib(n)}") - =} + reaction(startup) {= + for n in range(1, 10): + print(f"{n}-th Fibonacci number is {self.fib(n)}") + =} } diff --git a/test/Python/src/MethodsSameName.lf b/test/Python/src/MethodsSameName.lf index a80f521356..aedf19bef0 100644 --- a/test/Python/src/MethodsSameName.lf +++ b/test/Python/src/MethodsSameName.lf @@ -2,31 +2,31 @@ target Python reactor Foo { - state foo = 2 + state foo = 2 - method add(x) {= self.foo += x =} + method add(x) {= self.foo += x =} - reaction(startup) {= - self.add(40) - print(f"Foo: 2 + 40 = {self.foo}") - if self.foo != 42: - sys.stderr.write("Expected 42!") - exit(1) - =} + reaction(startup) {= + self.add(40) + print(f"Foo: 2 + 40 = {self.foo}") + if self.foo != 42: + sys.stderr.write("Expected 42!") + exit(1) + =} } main reactor { - state foo = 2 + state foo = 2 - a = new Foo() + a = new Foo() - method add(x) {= self.foo += x =} + method add(x) {= self.foo += x =} - reaction(startup) {= - self.add(40) - print(f"Main: 2 + 40 = {self.foo}") - if self.foo != 42: - sys.stderr.write("Expected 42!") - exit(1) - =} + reaction(startup) {= + self.add(40) + print(f"Main: 2 + 40 = {self.foo}") + if self.foo != 42: + sys.stderr.write("Expected 42!") + exit(1) + =} } diff --git a/test/Python/src/MovingAverage.lf b/test/Python/src/MovingAverage.lf index 3dbd5636c3..efaff22c10 100644 --- a/test/Python/src/MovingAverage.lf +++ b/test/Python/src/MovingAverage.lf @@ -1,51 +1,50 @@ -# Demonstration of a state variable that is a list. The MovingAverage reactor -# computes the moving average of the last four inputs and produces that as -# output. The source is a counting sequence. +# Demonstration of a state variable that is a list. The MovingAverage reactor computes the moving +# average of the last four inputs and produces that as output. The source is a counting sequence. target Python { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } import TestDouble from "lib/Test.lf" reactor MASource { - output out - state count = 0 - timer clock(0, 200 msec) - - reaction(clock) -> out {= - out.set(self.count) - self.count +=1 - =} + output out + state count = 0 + timer clock(0, 200 msec) + + reaction(clock) -> out {= + out.set(self.count) + self.count +=1 + =} } reactor MovingAverageImpl { - state delay_line(0.0, 0.0, 0.0) - state index = 0 - input m_in - output out - - reaction(m_in) -> out {= - # Calculate the output. - sm = m_in.value - sm += sum(self.delay_line) - - out.set(sm/4.0) - - # Insert the input in the delay line. - self.delay_line[self.index] = m_in.value - - # Update the index for the next input. - self.index +=1 - if self.index >= 3: - self.index = 0 - =} + state delay_line(0.0, 0.0, 0.0) + state index = 0 + input m_in + output out + + reaction(m_in) -> out {= + # Calculate the output. + sm = m_in.value + sm += sum(self.delay_line) + + out.set(sm/4.0) + + # Insert the input in the delay line. + self.delay_line[self.index] = m_in.value + + # Update the index for the next input. + self.index +=1 + if self.index >= 3: + self.index = 0 + =} } main reactor MovingAverage { - s = new MASource() - m = new MovingAverageImpl() - p = new TestDouble(expected(0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) - s.out -> m.m_in - m.out -> p.t_in + s = new MASource() + m = new MovingAverageImpl() + p = new TestDouble(expected(0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) + s.out -> m.m_in + m.out -> p.t_in } diff --git a/test/Python/src/MultipleContained.lf b/test/Python/src/MultipleContained.lf index 27950ccd88..515962986f 100644 --- a/test/Python/src/MultipleContained.lf +++ b/test/Python/src/MultipleContained.lf @@ -1,43 +1,42 @@ -# Test that a reaction can react to and send two multiple ports of a contained -# reactor. +# Test that a reaction can react to and send two multiple ports of a contained reactor. target Python reactor Contained { - output trigger - state count = 0 - input in1 - input in2 + output trigger + state count = 0 + input in1 + input in2 - reaction(startup) -> trigger {= trigger.set(42) =} + reaction(startup) -> trigger {= trigger.set(42) =} - reaction(in1) {= - print("in1 received ", in1.value); - if in1.value != 42: - sys.stderr.write("FAILED: Expected 42.\n") - exit(1) - self.count += 1 - =} + reaction(in1) {= + print("in1 received ", in1.value); + if in1.value != 42: + sys.stderr.write("FAILED: Expected 42.\n") + exit(1) + self.count += 1 + =} - reaction(in2) {= - print("in2 received ", in2.value) - if in2.value != 42: - sys.stderr.write("FAILED: Expected 42.\n") - exit(1) - self.count += 1 - =} + reaction(in2) {= + print("in2 received ", in2.value) + if in2.value != 42: + sys.stderr.write("FAILED: Expected 42.\n") + exit(1) + self.count += 1 + =} - reaction(shutdown) {= - if self.count != 2: - sys.stderr.write("FAILED: Should have received two inputs.\n") - exit(1) - =} + reaction(shutdown) {= + if self.count != 2: + sys.stderr.write("FAILED: Should have received two inputs.\n") + exit(1) + =} } main reactor MultipleContained { - c = new Contained() + c = new Contained() - reaction(c.trigger) -> c.in1, c.in2 {= - c.in1.set(c.trigger.value) - c.in2.set(c.trigger.value) - =} + reaction(c.trigger) -> c.in1, c.in2 {= + c.in1.set(c.trigger.value) + c.in2.set(c.trigger.value) + =} } diff --git a/test/Python/src/NativeListsAndTimes.lf b/test/Python/src/NativeListsAndTimes.lf index b7b52b3d0a..775d074343 100644 --- a/test/Python/src/NativeListsAndTimes.lf +++ b/test/Python/src/NativeListsAndTimes.lf @@ -1,27 +1,26 @@ target Python -# This test passes if it is successfully compiled into valid target code. -main reactor( - x = 0, - y = 0, # Units are missing but not required - z = 1 msec, # Type is missing but not required - p(1, 2, 3, 4), # List of integers - q(1 msec, 2 msec, 3 msec), # list of time values - g(1 msec, 2 msec) # List of time values +main reactor( # This test passes if it is successfully compiled into valid target code. + x = 0, + y = 0, # Units are missing but not required + z = 1 msec, # Type is missing but not required + p(1, 2, 3, 4), # List of integers + q(1 msec, 2 msec, 3 msec), # list of time values + g(1 msec, 2 msec) # List of time values ) { - state s = y # Reference to explicitly typed time parameter - state t = z # Reference to implicitly typed time parameter - state v # Uninitialized boolean state variable - state w # Uninitialized time state variable - timer tick(0) # Units missing but not required - timer tock(1 sec) # Implicit type time - timer toe(z) # Implicit type time - state baz = p # Implicit type int[] - state period = z # Implicit type time - state bar(1 msec, 2 msec, 3 msec) # list of time values - state notype(1, 2, 3, 4) + state s = y # Reference to explicitly typed time parameter + state t = z # Reference to implicitly typed time parameter + state v # Uninitialized boolean state variable + state w # Uninitialized time state variable + timer tick(0) # Units missing but not required + timer tock(1 sec) # Implicit type time + timer toe(z) # Implicit type time + state baz = p # Implicit type int[] + state period = z # Implicit type time + state bar(1 msec, 2 msec, 3 msec) # list of time values + state notype(1, 2, 3, 4) - reaction(tick) {= - # Target code - =} + reaction(tick) {= + # Target code + =} } diff --git a/test/Python/src/ParameterizedState.lf b/test/Python/src/ParameterizedState.lf index e8805b027f..32791918de 100644 --- a/test/Python/src/ParameterizedState.lf +++ b/test/Python/src/ParameterizedState.lf @@ -1,11 +1,11 @@ target Python reactor Foo(bar = 42) { - state baz = bar + state baz = bar - reaction(startup) {= print("Baz: ", self.baz) =} + reaction(startup) {= print("Baz: ", self.baz) =} } main reactor { - a = new Foo() + a = new Foo() } diff --git a/test/Python/src/PeriodicDesugared.lf b/test/Python/src/PeriodicDesugared.lf index b003ffc9f8..7c6f6768f2 100644 --- a/test/Python/src/PeriodicDesugared.lf +++ b/test/Python/src/PeriodicDesugared.lf @@ -1,22 +1,22 @@ target Python { - fast: true, - timeout: 1 sec + fast: true, + timeout: 1 sec } main reactor(offset = 0, period = 500 msec) { - logical action init(offset) - logical action recur(period) + logical action init(offset) + logical action recur(period) - reaction(startup) -> init, recur {= - if self.offset == 0: - print("Hello World!") - recur.schedule(0) - else: - init.schedule(0) - =} - - reaction(init, recur) -> recur {= + reaction(startup) -> init, recur {= + if self.offset == 0: print("Hello World!") recur.schedule(0) - =} + else: + init.schedule(0) + =} + + reaction(init, recur) -> recur {= + print("Hello World!") + recur.schedule(0) + =} } diff --git a/test/Python/src/PingPong.lf b/test/Python/src/PingPong.lf index f5f80511ae..5be9cfb50b 100644 --- a/test/Python/src/PingPong.lf +++ b/test/Python/src/PingPong.lf @@ -1,74 +1,71 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * Ping introduces a microstep delay using a logical action to break the - * causality loop. + * Ping introduces a microstep delay using a logical action to break the causality loop. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec * - * There is no parallelism in this application, so it does not benefit from - * being being threaded, just some additional overhead. + * There is no parallelism in this application, so it does not benefit from being being threaded, + * just some additional overhead. * - * These measurements are total execution time, including startup and shutdown. - * These are about an order of magnitude faster than anything reported in the - * paper. + * These measurements are total execution time, including startup and shutdown. These are about an + * order of magnitude faster than anything reported in the paper. * * @author Edward A. Lee */ target Python { - fast: true + fast: true } reactor Ping(count = 10) { - input receive - output send - state pingsLeft = count - logical action serve + input receive + output send + state pingsLeft = count + logical action serve - reaction(startup, serve) -> send {= - send.set(self.pingsLeft) - self.pingsLeft -= 1 - =} + reaction(startup, serve) -> send {= + send.set(self.pingsLeft) + self.pingsLeft -= 1 + =} - reaction(receive) -> serve {= - if self.pingsLeft > 0: - serve.schedule(0) - else: - request_stop() - =} + reaction(receive) -> serve {= + if self.pingsLeft > 0: + serve.schedule(0) + else: + request_stop() + =} } reactor Pong(expected = 10) { - input receive - output send - state count = 0 + input receive + output send + state count = 0 - reaction(receive) -> send {= - self.count += 1 - send.set(receive.value) - =} + reaction(receive) -> send {= + self.count += 1 + send.set(receive.value) + =} - reaction(shutdown) {= - if self.count != self.expected: - sys.stderr.write( - "ERROR: Pong expected to receive {} inputs, but it received {}.\n".format( - self.expected, - self.count - ) + reaction(shutdown) {= + if self.count != self.expected: + sys.stderr.write( + "ERROR: Pong expected to receive {} inputs, but it received {}.\n".format( + self.expected, + self.count ) - sys.exit(1) - print("Success.") - =} + ) + sys.exit(1) + print("Success.") + =} } main reactor PingPong { - ping = new Ping() - pong = new Pong() - ping.send -> pong.receive - pong.send -> ping.receive + ping = new Ping() + pong = new Pong() + ping.send -> pong.receive + pong.send -> ping.receive } diff --git a/test/Python/src/Pipeline.lf b/test/Python/src/Pipeline.lf index 18436561b8..fb72fd1026 100644 --- a/test/Python/src/Pipeline.lf +++ b/test/Python/src/Pipeline.lf @@ -1,58 +1,58 @@ target Python { - timeout: 2 sec + timeout: 2 sec } reactor TakeTime { - input _in - output out + input _in + output out - reaction(_in) -> out {= - offset = 0 - for i in range(10000): - offset+=1 + reaction(_in) -> out {= + offset = 0 + for i in range(10000): + offset+=1 - out.set(_in.value + offset) - =} + out.set(_in.value + offset) + =} } reactor Print { - input _in - state count = 0 - state received = 0 - - reaction(_in) {= - self.received += 1 - print("Received: {:d} at logical time {:d}".format(_in.value, lf.time.logical_elapsed())) - if _in.value != (self.count + 40000): - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count + 40000)) - exit(1) - self.count+=1 - =} - - reaction(shutdown) {= - if self.received == 0: - sys.stderr.write("ERROR: Final reactor received no data.\n") - exit(3) - =} + input _in + state count = 0 + state received = 0 + + reaction(_in) {= + self.received += 1 + print("Received: {:d} at logical time {:d}".format(_in.value, lf.time.logical_elapsed())) + if _in.value != (self.count + 40000): + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count + 40000)) + exit(1) + self.count+=1 + =} + + reaction(shutdown) {= + if self.received == 0: + sys.stderr.write("ERROR: Final reactor received no data.\n") + exit(3) + =} } main reactor Pipeline { - timer t(0, 200 msec) - state count = 0 - - c1 = new TakeTime() - c2 = new TakeTime() - c3 = new TakeTime() - c4 = new TakeTime() - p = new Print() - - c1.out -> c2._in after 200 msec - c2.out -> c3._in after 200 msec - c3.out -> c4._in after 200 msec - c4.out -> p._in - - reaction(t) -> c1._in {= - c1._in.set(self.count) - self.count += 1 - =} + timer t(0, 200 msec) + state count = 0 + + c1 = new TakeTime() + c2 = new TakeTime() + c3 = new TakeTime() + c4 = new TakeTime() + p = new Print() + + c1.out -> c2._in after 200 msec + c2.out -> c3._in after 200 msec + c3.out -> c4._in after 200 msec + c4.out -> p._in + + reaction(t) -> c1._in {= + c1._in.set(self.count) + self.count += 1 + =} } diff --git a/test/Python/src/ReadOutputOfContainedReactor.lf b/test/Python/src/ReadOutputOfContainedReactor.lf index 1cb73667ce..c67243b0d5 100644 --- a/test/Python/src/ReadOutputOfContainedReactor.lf +++ b/test/Python/src/ReadOutputOfContainedReactor.lf @@ -1,46 +1,45 @@ -# Test reacting to and reading outputs from a contained reactor in various -# permutations. +# Test reacting to and reading outputs from a contained reactor in various permutations. target Python reactor Contained { - output out + output out - reaction(startup) -> out {= out.set(42) =} + reaction(startup) -> out {= out.set(42) =} } main reactor ReadOutputOfContainedReactor { - c = new Contained() - state count = 0 + c = new Contained() + state count = 0 - reaction(startup) c.out {= - print("Startup reaction reading output of contained reactor: ", c.out.value) - if c.out.value != 42: - sys.stderr.write("Expected 42!\n") - exit(2) - self.count += 1 - =} + reaction(startup) c.out {= + print("Startup reaction reading output of contained reactor: ", c.out.value) + if c.out.value != 42: + sys.stderr.write("Expected 42!\n") + exit(2) + self.count += 1 + =} - reaction(c.out) {= - print("Reading output of contained reactor:", c.out.value) - if c.out.value != 42: - sys.stderr.write("Expected 42!\n") - exit(3) - self.count += 1 - =} + reaction(c.out) {= + print("Reading output of contained reactor:", c.out.value) + if c.out.value != 42: + sys.stderr.write("Expected 42!\n") + exit(3) + self.count += 1 + =} - reaction(startup, c.out) {= - print("Alternate triggering reading output of contained reactor: ", c.out.value) - if c.out.value != 42: - sys.stderr.write("Expected 42!\n") - exit(4) - self.count += 1 - =} + reaction(startup, c.out) {= + print("Alternate triggering reading output of contained reactor: ", c.out.value) + if c.out.value != 42: + sys.stderr.write("Expected 42!\n") + exit(4) + self.count += 1 + =} - reaction(shutdown) {= - if self.count != 3: - print("FAILURE: One of the reactions failed to trigger.\n") - exit(1) - else: - print("Test passes.") - =} + reaction(shutdown) {= + if self.count != 3: + print("FAILURE: One of the reactions failed to trigger.\n") + exit(1) + else: + print("Test passes.") + =} } diff --git a/test/Python/src/ScheduleLogicalAction.lf b/test/Python/src/ScheduleLogicalAction.lf index 3f99c65777..c1328ee85e 100644 --- a/test/Python/src/ScheduleLogicalAction.lf +++ b/test/Python/src/ScheduleLogicalAction.lf @@ -1,45 +1,45 @@ -# This checks that a logical action is scheduled the specified logical time -# after the current logical time. +# This checks that a logical action is scheduled the specified logical time after the current +# logical time. target Python { - fast: true, - timeout: 3 sec + fast: true, + timeout: 3 sec } reactor foo { - input x - output y - logical action a + input x + output y + logical action a - reaction(x) -> y, a {= - y.set(2*x.value) - # The following uses physical time, incorrectly. - a.schedule(MSEC(500)) - =} + reaction(x) -> y, a {= + y.set(2*x.value) + # The following uses physical time, incorrectly. + a.schedule(MSEC(500)) + =} - reaction(a) -> y {= y.set(-42) =} + reaction(a) -> y {= y.set(-42) =} } reactor print { - state expected_time = 0 - input x + state expected_time = 0 + input x - reaction(x) {= - elapsed_time = lf.time.logical_elapsed() - print("Result is ", x.value) - print("Current logical time is: ", elapsed_time) - print("Current physical time is: ", lf.time.physical_elapsed()) - if elapsed_time != self.expected_time: - sys.stderr.write("ERROR: Expected logical time to be {:d}.\n".format(self.expected_time)) - exit(1); - self.expected_time += MSEC(500) - =} + reaction(x) {= + elapsed_time = lf.time.logical_elapsed() + print("Result is ", x.value) + print("Current logical time is: ", elapsed_time) + print("Current physical time is: ", lf.time.physical_elapsed()) + if elapsed_time != self.expected_time: + sys.stderr.write("ERROR: Expected logical time to be {:d}.\n".format(self.expected_time)) + exit(1); + self.expected_time += MSEC(500) + =} } main reactor { - f = new foo() - p = new print() - timer t(0, 1 sec) - f.y -> p.x + f = new foo() + p = new print() + timer t(0, 1 sec) + f.y -> p.x - reaction(t) -> f.x {= f.x.set(42) =} + reaction(t) -> f.x {= f.x.set(42) =} } diff --git a/test/Python/src/SelfLoop.lf b/test/Python/src/SelfLoop.lf index 2b607b09c8..f4fd756bb2 100644 --- a/test/Python/src/SelfLoop.lf +++ b/test/Python/src/SelfLoop.lf @@ -1,38 +1,38 @@ target Python { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Self { - input x - output y - logical action a - state expected = 43 + input x + output y + logical action a + state expected = 43 - reaction(a) -> y {= - print("a = ", a.value) - y.set(a.value + 1) - =} + reaction(a) -> y {= + print("a = ", a.value) + y.set(a.value + 1) + =} - reaction(x) -> a {= - print("x = ", x.value) - if x.value != self.expected: - sys.stderr.write("Expected {:d}.\n".format(self.expected)) - exit(1) - self.expected += 1 - a.schedule(MSEC(100), x.value) - =} + reaction(x) -> a {= + print("x = ", x.value) + if x.value != self.expected: + sys.stderr.write("Expected {:d}.\n".format(self.expected)) + exit(1) + self.expected += 1 + a.schedule(MSEC(100), x.value) + =} - reaction(startup) -> a {= a.schedule(0, 42) =} + reaction(startup) -> a {= a.schedule(0, 42) =} - reaction(shutdown) {= - if self.expected <= 43: - sys.stderr.write("Received no data.\n") - exit(2) - =} + reaction(shutdown) {= + if self.expected <= 43: + sys.stderr.write("Received no data.\n") + exit(2) + =} } main reactor SelfLoop { - u = new Self() - u.y -> u.x + u = new Self() + u.y -> u.x } diff --git a/test/Python/src/SendingInside.lf b/test/Python/src/SendingInside.lf index 8bcc66c005..0edc80bf73 100644 --- a/test/Python/src/SendingInside.lf +++ b/test/Python/src/SendingInside.lf @@ -1,30 +1,30 @@ -# This tests a reactor that contains another reactor and also has its own -# reaction that routes inputs to the contained reactor. +# This tests a reactor that contains another reactor and also has its own reaction that routes +# inputs to the contained reactor. target Python { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true } reactor Printer { - input x - state count = 1 + input x + state count = 1 - reaction(x) {= - print("Inside reactor received: ", x.value) - if x.value != self.count: - sys.stderr.write("FAILURE: Expected {:d}.\n".format(self.count)) - exit(1) - self.count += 1 - =} + reaction(x) {= + print("Inside reactor received: ", x.value) + if x.value != self.count: + sys.stderr.write("FAILURE: Expected {:d}.\n".format(self.count)) + exit(1) + self.count += 1 + =} } main reactor SendingInside { - state count = 0 - timer t(0, 1 sec) - p = new Printer() + state count = 0 + timer t(0, 1 sec) + p = new Printer() - reaction(t) -> p.x {= - self.count += 1 - p.x.set(self.count) - =} + reaction(t) -> p.x {= + self.count += 1 + p.x.set(self.count) + =} } diff --git a/test/Python/src/SetArray.lf b/test/Python/src/SetArray.lf index 4766d529f7..c27408647b 100644 --- a/test/Python/src/SetArray.lf +++ b/test/Python/src/SetArray.lf @@ -1,27 +1,26 @@ -# This tests passing lists as port values This tests the use of the -# "polymorphic" delay reactor on a struct. It delays by a logical time any -# pointer datatype. +# This tests passing lists as port values This tests the use of the "polymorphic" delay reactor on a +# struct. It delays by a logical time any pointer datatype. target Python reactor Source { - output out + output out - reaction(startup) -> out {= out.set([0,1,2]) =} + reaction(startup) -> out {= out.set([0,1,2]) =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input _in + input _in - reaction(_in) {= - print("Recieved ", _in.value) - if _in.value != [self.scale*count for count in range(len(_in.value))]: - sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") - exit(1) - =} + reaction(_in) {= + print("Recieved ", _in.value) + if _in.value != [self.scale*count for count in range(len(_in.value))]: + sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") + exit(1) + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/SimpleDeadline.lf b/test/Python/src/SimpleDeadline.lf index a714124129..1a9d42f48d 100644 --- a/test/Python/src/SimpleDeadline.lf +++ b/test/Python/src/SimpleDeadline.lf @@ -1,39 +1,38 @@ -# Test local deadline, where a deadline is associated with a reaction -# definition. This test triggers a reaction exactly once with a deadline -# violation. +# Test local deadline, where a deadline is associated with a reaction definition. This test triggers +# a reaction exactly once with a deadline violation. target Python reactor Deadline(threshold = 100 msec) { - input x - output deadlineViolation + input x + output deadlineViolation - reaction(x) -> deadlineViolation {= - sys.stderr.write("ERROR: Deadline violation was not detected!\n") - exit(1) - =} deadline(threshold) {= - print("Deadline violation detected.") - deadlineViolation.set(True) - =} + reaction(x) -> deadlineViolation {= + sys.stderr.write("ERROR: Deadline violation was not detected!\n") + exit(1) + =} deadline(threshold) {= + print("Deadline violation detected.") + deadlineViolation.set(True) + =} } reactor Print { - input _in + input _in - reaction(_in) {= - if _in.value is True: - print("Output successfully produced by deadline handler.") - =} + reaction(_in) {= + if _in.value is True: + print("Output successfully produced by deadline handler.") + =} } main reactor SimpleDeadline { - timer start - d = new Deadline(threshold = 10 msec) - p = new Print() - d.deadlineViolation -> p._in - preamble {= import time =} + timer start + d = new Deadline(threshold = 10 msec) + p = new Print() + d.deadlineViolation -> p._in + preamble {= import time =} - reaction(start) -> d.x {= - self.time.sleep(0.02) - d.x.set(42) - =} + reaction(start) -> d.x {= + self.time.sleep(0.02) + d.x.set(42) + =} } diff --git a/test/Python/src/SlowingClock.lf b/test/Python/src/SlowingClock.lf index 972421437a..b53c59d713 100644 --- a/test/Python/src/SlowingClock.lf +++ b/test/Python/src/SlowingClock.lf @@ -1,38 +1,38 @@ /** - * Output events at logical times 100, 300, 600, and 1000 msec after the start - * time. This uses a logical action with a minimum delay of 100 msec and - * additional delays provided as arguments to the schedule() function. + * Output events at logical times 100, 300, 600, and 1000 msec after the start time. This uses a + * logical action with a minimum delay of 100 msec and additional delays provided as arguments to + * the schedule() function. */ target Python { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } main reactor SlowingClock { - logical action a(100 msec) - state interval = 100 msec - state expected_time = 100 msec + logical action a(100 msec) + state interval = 100 msec + state expected_time = 100 msec - reaction(startup) -> a {= a.schedule(0) =} + reaction(startup) -> a {= a.schedule(0) =} - reaction(a) -> a {= - elapsed_logical_time = lf.time.logical_elapsed() - print("Logical time since start: {:d} nsec.\n".format(elapsed_logical_time)) - if elapsed_logical_time != self.expected_time: - sys.stderr.write("ERROR: Expected time to be: {:d} nsec.\n".format(self.expected_time)) - exit(1) + reaction(a) -> a {= + elapsed_logical_time = lf.time.logical_elapsed() + print("Logical time since start: {:d} nsec.\n".format(elapsed_logical_time)) + if elapsed_logical_time != self.expected_time: + sys.stderr.write("ERROR: Expected time to be: {:d} nsec.\n".format(self.expected_time)) + exit(1) - a.schedule(self.interval) - self.expected_time += MSEC(100) + self.interval - self.interval += MSEC(100) - =} + a.schedule(self.interval) + self.expected_time += MSEC(100) + self.interval + self.interval += MSEC(100) + =} - reaction(shutdown) {= - if self.expected_time != MSEC(1500): - sys.stderr.write("ERROR: Expected the next expected time to be: 1500000000 nsec.\n") - sys.stderr.write("It was: {:d} nsec.\n".format(self.expected_time)) - exit(2) - else: - print("Test passes.") - =} + reaction(shutdown) {= + if self.expected_time != MSEC(1500): + sys.stderr.write("ERROR: Expected the next expected time to be: 1500000000 nsec.\n") + sys.stderr.write("It was: {:d} nsec.\n".format(self.expected_time)) + exit(2) + else: + print("Test passes.") + =} } diff --git a/test/Python/src/SlowingClockPhysical.lf b/test/Python/src/SlowingClockPhysical.lf index dbb9da705f..39d75b4c6d 100644 --- a/test/Python/src/SlowingClockPhysical.lf +++ b/test/Python/src/SlowingClockPhysical.lf @@ -1,45 +1,42 @@ /** - * Output events at physical times at least 100, 300, and 600 msec after the - * start time. This uses a physical action with a minimum interarrival time of - * 100 msec. The reactor increases the interarrival time with each invocation of - * the schedule() function. The timestamps of the events will be exact because - * the physical time at which schedule() is called is always way smaller than - * the time of the last invocation (or start time) plus the minimum interarrival - * time. Hence, the minimum interarrival time always determines the time of the - * next event. + * Output events at physical times at least 100, 300, and 600 msec after the start time. This uses a + * physical action with a minimum interarrival time of 100 msec. The reactor increases the + * interarrival time with each invocation of the schedule() function. The timestamps of the events + * will be exact because the physical time at which schedule() is called is always way smaller than + * the time of the last invocation (or start time) plus the minimum interarrival time. Hence, the + * minimum interarrival time always determines the time of the next event. */ target Python { - timeout: 1500 msec + timeout: 1500 msec } main reactor SlowingClockPhysical { - # first offset and minimum interarrival time. - physical action a(100 msec, 100 msec) - state interval = 100 msec - state expected_time = 100 msec + physical action a(100 msec, 100 msec) # first offset and minimum interarrival time. + state interval = 100 msec + state expected_time = 100 msec - reaction(startup) -> a {= - self.expected_time = MSEC(100) - a.schedule(0) - =} + reaction(startup) -> a {= + self.expected_time = MSEC(100) + a.schedule(0) + =} - reaction(a) -> a {= - elapsed_logical_time = lf.time.logical_elapsed() - print("Logical time since start: {:d} nsec.".format(elapsed_logical_time)) - if elapsed_logical_time < self.expected_time: - sys.stderr.write("ERROR: Expected logical time to be at least: {:d} nsec.\n".format(self.expected_time)) - exit(1) - self.interval += MSEC(100) - self.expected_time = MSEC(100) + self.interval - a.schedule(self.interval) - print("Scheduling next to occur after: {:d} nsec.".format(self.interval)) - =} + reaction(a) -> a {= + elapsed_logical_time = lf.time.logical_elapsed() + print("Logical time since start: {:d} nsec.".format(elapsed_logical_time)) + if elapsed_logical_time < self.expected_time: + sys.stderr.write("ERROR: Expected logical time to be at least: {:d} nsec.\n".format(self.expected_time)) + exit(1) + self.interval += MSEC(100) + self.expected_time = MSEC(100) + self.interval + a.schedule(self.interval) + print("Scheduling next to occur after: {:d} nsec.".format(self.interval)) + =} - reaction(shutdown) {= - if self.expected_time < MSEC(500): - sys.stderr.write("ERROR: Expected the next expected time to be at least: 500000000 nsec.\n"); - sys.stderr.write("It was: {:d} nsec.\n".format(self.expected_time)) - exit(2) - print("Success") - =} + reaction(shutdown) {= + if self.expected_time < MSEC(500): + sys.stderr.write("ERROR: Expected the next expected time to be at least: 500000000 nsec.\n"); + sys.stderr.write("It was: {:d} nsec.\n".format(self.expected_time)) + exit(2) + print("Success") + =} } diff --git a/test/Python/src/Stride.lf b/test/Python/src/Stride.lf index 86c68bab5a..db83ecc2e6 100644 --- a/test/Python/src/Stride.lf +++ b/test/Python/src/Stride.lf @@ -1,35 +1,35 @@ -# This example illustrates state variables and parameters on the wiki. For this -# test, success is just compiling and running. +# This example illustrates state variables and parameters on the wiki. For this test, success is +# just compiling and running. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Count(stride = 1) { - state count = 1 - output y - timer t(0, 100 msec) + state count = 1 + output y + timer t(0, 100 msec) - reaction(t) -> y {= - y.set(self.count) - self.count += self.stride - =} + reaction(t) -> y {= + y.set(self.count) + self.count += self.stride + =} } reactor Display { - input x - state expected = 1 # for testing. + input x + state expected = 1 # for testing. - reaction(x) {= - print("Received: ", x.value) - if x.value != self.expected: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.expected)) - self.expected += 2 - =} + reaction(x) {= + print("Received: ", x.value) + if x.value != self.expected: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.expected)) + self.expected += 2 + =} } main reactor Stride { - c = new Count(stride = 2) - d = new Display() - c.y -> d.x + c = new Count(stride = 2) + d = new Display() + c.y -> d.x } diff --git a/test/Python/src/StructAsState.lf b/test/Python/src/StructAsState.lf index b6f38f8589..f7d725325d 100644 --- a/test/Python/src/StructAsState.lf +++ b/test/Python/src/StructAsState.lf @@ -1,20 +1,19 @@ -# Check that a state variable can have a statically initialized struct as a -# value. +# Check that a state variable can have a statically initialized struct as a value. target Python main reactor StructAsState { - preamble {= - class hello: - def __init__(self, name, value): - self.name = name - self.value = value - =} - state s = {= self.hello("Earth", 42) =} + preamble {= + class hello: + def __init__(self, name, value): + self.name = name + self.value = value + =} + state s = {= self.hello("Earth", 42) =} - reaction(startup) {= - print("State s.name=\"{:s}\", value={:d}.".format(self.s.name, self.s.value)) - if self.s.value != 42: - sys.stderr.write("FAILED: Expected 42.\n") - exit(1) - =} + reaction(startup) {= + print("State s.name=\"{:s}\", value={:d}.".format(self.s.name, self.s.value)) + if self.s.value != 42: + sys.stderr.write("FAILED: Expected 42.\n") + exit(1) + =} } diff --git a/test/Python/src/StructAsType.lf b/test/Python/src/StructAsType.lf index 46951ec86a..cd200a86ff 100644 --- a/test/Python/src/StructAsType.lf +++ b/test/Python/src/StructAsType.lf @@ -1,31 +1,31 @@ target Python { - files: include/hello.py + files: include/hello.py } preamble {= import hello =} reactor Source { - output out + output out - reaction(startup) -> out {= - temp = hello.hello("Earth", 42) - out.set(temp) - =} + reaction(startup) -> out {= + temp = hello.hello("Earth", 42) + out.set(temp) + =} } reactor Print(expected = 42) { # expected parameter is for testing. - input _in + input _in - reaction(_in) {= - print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + reaction(_in) {= + print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } main reactor StructAsType { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/StructAsTypeDirect.lf b/test/Python/src/StructAsTypeDirect.lf index 921b7e4390..9e44cc6f34 100644 --- a/test/Python/src/StructAsTypeDirect.lf +++ b/test/Python/src/StructAsTypeDirect.lf @@ -1,34 +1,34 @@ target Python { - files: include/hello.py + files: include/hello.py } preamble {= import hello =} reactor Source { - output out + output out - reaction(startup) -> out {= - out_value = out.value - out_value = hello.hello() - out_value.name = "Earth" - out_value.value = 42 - out.set(out_value) - =} + reaction(startup) -> out {= + out_value = out.value + out_value = hello.hello() + out_value.name = "Earth" + out_value.value = 42 + out.set(out_value) + =} } reactor Print(expected = 42) { # expected parameter is for testing. - input _in + input _in - reaction(_in) {= - print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + reaction(_in) {= + print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } main reactor { - s = new Source() - p = new Print() - s.out -> p._in + s = new Source() + p = new Print() + s.out -> p._in } diff --git a/test/Python/src/StructParallel.lf b/test/Python/src/StructParallel.lf index bac79a6abe..1f5a51fa50 100644 --- a/test/Python/src/StructParallel.lf +++ b/test/Python/src/StructParallel.lf @@ -1,7 +1,7 @@ -# Source allocates a class object and then sends it to two reactors, each of -# which want to modify it. +# Source allocates a class object and then sends it to two reactors, each of which want to modify +# it. target Python { - files: ["include/hello.py"] + files: ["include/hello.py"] } import Source from "StructScale.lf" @@ -9,38 +9,37 @@ import Source from "StructScale.lf" preamble {= import hello =} reactor Check(expected = 42) { - input _in - - reaction(_in) {= - print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + input _in + + reaction(_in) {= + print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } reactor Print(scale = 2) { - # Mutable keyword indicates that this reactor wants a writable copy of the - # input. - mutable input _in + # Mutable keyword indicates that this reactor wants a writable copy of the input. + mutable input _in - output out + output out - reaction(_in) -> out {= - print(_in.value.value) - _in.value.value *= self.scale; - out.set(_in.value) - =} + reaction(_in) -> out {= + print(_in.value.value) + _in.value.value *= self.scale; + out.set(_in.value) + =} } main reactor StructParallel { - s = new Source() - c1 = new Print() - c2 = new Print(scale = 3) - p1 = new Check(expected = 84) - p2 = new Check(expected = 126) - s.out -> c1._in - s.out -> c2._in - c1.out -> p1._in - c2.out -> p2._in + s = new Source() + c1 = new Print() + c2 = new Print(scale = 3) + p1 = new Check(expected = 84) + p2 = new Check(expected = 126) + s.out -> c1._in + s.out -> c2._in + c1.out -> p1._in + c2.out -> p2._in } diff --git a/test/Python/src/StructPrint.lf b/test/Python/src/StructPrint.lf index 3c0138f937..191f72bc6d 100644 --- a/test/Python/src/StructPrint.lf +++ b/test/Python/src/StructPrint.lf @@ -1,30 +1,30 @@ -# Source produces a dynamically allocated class object, which it passes to -# Print. Reference counting ensures that the struct is freed. +# Source produces a dynamically allocated class object, which it passes to Print. Reference counting +# ensures that the struct is freed. target Python { - files: ["include/hello.py"] + files: ["include/hello.py"] } preamble {= import hello =} reactor Print { - output out + output out - reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} + reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } reactor Check(expected = 42) { # expected parameter is for testing. - input _in + input _in - reaction(_in) {= - print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + reaction(_in) {= + print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } main reactor { - s = new Print() - p = new Check() - s.out -> p._in + s = new Print() + p = new Check() + s.out -> p._in } diff --git a/test/Python/src/StructScale.lf b/test/Python/src/StructScale.lf index 120c6fde65..ce4a25bc67 100644 --- a/test/Python/src/StructScale.lf +++ b/test/Python/src/StructScale.lf @@ -1,45 +1,44 @@ -# Source produces a dynamically allocated class object, which it passes to -# Scale. Scale modifies it and passes it to Print. +# Source produces a dynamically allocated class object, which it passes to Scale. Scale modifies it +# and passes it to Print. target Python { - files: ["include/hello.py"] + files: ["include/hello.py"] } preamble {= import hello =} reactor Source { - output out + output out - reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} + reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } reactor TestInput(expected = 42) { # expected parameter is for testing. - input _in - - reaction(_in) {= - print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) - if _in.value.value != self.expected: - sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) - exit(1) - =} + input _in + + reaction(_in) {= + print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) + if _in.value.value != self.expected: + sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) + exit(1) + =} } reactor Print(scale = 2) { - # Mutable keyword indicates that this reactor wants a writable copy of the - # input. - mutable input _in + # Mutable keyword indicates that this reactor wants a writable copy of the input. + mutable input _in - output out + output out - reaction(_in) -> out {= - _in.value.value *= self.scale; - out.set(_in.value) - =} + reaction(_in) -> out {= + _in.value.value *= self.scale; + out.set(_in.value) + =} } main reactor StructScale { - s = new Source() - c = new Print() - p = new TestInput(expected = 84) - s.out -> c._in - c.out -> p._in + s = new Source() + c = new Print() + p = new TestInput(expected = 84) + s.out -> c._in + c.out -> p._in } diff --git a/test/Python/src/SubclassesAndStartup.lf b/test/Python/src/SubclassesAndStartup.lf index a98e580851..794ad83d53 100644 --- a/test/Python/src/SubclassesAndStartup.lf +++ b/test/Python/src/SubclassesAndStartup.lf @@ -1,39 +1,39 @@ target Python reactor Super { - state count = 0 + state count = 0 - reaction(startup) {= - print("{:s}(Super) started".format(self.name)) - self.count += 1 - =} + reaction(startup) {= + print("{:s}(Super) started".format(self.name)) + self.count += 1 + =} - reaction(shutdown) {= - if self.count == 0: - sys.stderr.write("No startup reaction was invoked!\n") - exit(3) - =} + reaction(shutdown) {= + if self.count == 0: + sys.stderr.write("No startup reaction was invoked!\n") + exit(3) + =} } reactor SubA(name = "SubA") extends Super { - reaction(startup) {= - print("{:s} started".format(self.name)) - if self.count == 0: - sys.stderr.write("Base class startup reaction was not invoked!\n") - exit(1) - =} + reaction(startup) {= + print("{:s} started".format(self.name)) + if self.count == 0: + sys.stderr.write("Base class startup reaction was not invoked!\n") + exit(1) + =} } reactor SubB(name = "SubB") extends Super { - reaction(startup) {= - print("{:s} started".format(self.name)) - if self.count == 0: - sys.stderr.write("Base class startup reaction was not invoked!\n") - exit(2) - =} + reaction(startup) {= + print("{:s} started".format(self.name)) + if self.count == 0: + sys.stderr.write("Base class startup reaction was not invoked!\n") + exit(2) + =} } main reactor SubclassesAndStartup { - a = new SubA() - b = new SubB() + a = new SubA() + b = new SubB() } diff --git a/test/Python/src/TimeLimit.lf b/test/Python/src/TimeLimit.lf index beb7602db9..54b0bbc7fb 100644 --- a/test/Python/src/TimeLimit.lf +++ b/test/Python/src/TimeLimit.lf @@ -1,47 +1,46 @@ -# Test that the stop function can be used to internally impose a a time limit. -# Correct output for this 1, 2, 3, 4. Failure for this test is failing to halt -# or getting the wrong data. +# Test that the stop function can be used to internally impose a a time limit. Correct output for +# this 1, 2, 3, 4. Failure for this test is failing to halt or getting the wrong data. target Python { - fast: true + fast: true } reactor Clock(offset = 0, period = 1 sec) { - output y - timer t(offset, period) - state count = 0 + output y + timer t(offset, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - # print("Reacting at time ", lf.time.logical_elapsed()) - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + # print("Reacting at time ", lf.time.logical_elapsed()) + y.set(self.count) + =} } reactor Destination { - input x - state s = 1 + input x + state s = 1 - reaction(x) {= - # print(x.value) - if x.value != self.s: - sys.stderr.write("ERROR: Expected {:d} and got {:d}.\n".format(self.s, x.value)) - exit(1) - self.s += 1 - =} + reaction(x) {= + # print(x.value) + if x.value != self.s: + sys.stderr.write("ERROR: Expected {:d} and got {:d}.\n".format(self.s, x.value)) + exit(1) + self.s += 1 + =} - reaction(shutdown) {= - print("**** shutdown reaction invoked.") - if self.s != 12: - sys.stderr.write("ERROR: Expected 12 but got {:d}.\n".format(self.s)) - exit(1) - =} + reaction(shutdown) {= + print("**** shutdown reaction invoked.") + if self.s != 12: + sys.stderr.write("ERROR: Expected 12 but got {:d}.\n".format(self.s)) + exit(1) + =} } main reactor TimeLimit(period = 1 sec) { - timer stop(10 sec) - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + timer stop(10 sec) + c = new Clock(period = period) + d = new Destination() + c.y -> d.x - reaction(stop) {= request_stop() =} + reaction(stop) {= request_stop() =} } diff --git a/test/Python/src/TimeState.lf b/test/Python/src/TimeState.lf index 72ad9f0ebd..6a82c5fbf9 100644 --- a/test/Python/src/TimeState.lf +++ b/test/Python/src/TimeState.lf @@ -1,11 +1,11 @@ target Python reactor Foo(bar = 42) { - state baz = 500 msec + state baz = 500 msec - reaction(startup) {= print("Baz: ", self.baz) =} + reaction(startup) {= print("Baz: ", self.baz) =} } main reactor { - a = new Foo() + a = new Foo() } diff --git a/test/Python/src/Timers.lf b/test/Python/src/Timers.lf index f6cbba747a..fb533ee3f6 100644 --- a/test/Python/src/Timers.lf +++ b/test/Python/src/Timers.lf @@ -1,21 +1,21 @@ /** Test whether timers with different periods are triggered correctly. */ target Python { - timeout: 2 sec + timeout: 2 sec } main reactor { - timer t(0, 1 sec) - timer t2(0, 2 sec) - state counter = 0 + timer t(0, 1 sec) + timer t2(0, 2 sec) + state counter = 0 - reaction(t2) {= self.counter += 2 =} + reaction(t2) {= self.counter += 2 =} - reaction(t) {= self.counter -= 1 =} + reaction(t) {= self.counter -= 1 =} - reaction(shutdown) {= - if self.counter != 1: - sys.stderr.write("Error: Expected {:d} and got {:d}.\n".format(1, self.counter)) - exit(1) - print("SUCCESS.") - =} + reaction(shutdown) {= + if self.counter != 1: + sys.stderr.write("Error: Expected {:d} and got {:d}.\n".format(1, self.counter)) + exit(1) + print("SUCCESS.") + =} } diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf index b65f732652..6f7fdcc8bf 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf @@ -1,46 +1,43 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target Python { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source { - output a - output b - state count = 0 - timer t(0, 200 msec) + output a + output b + state count = 0 + timer t(0, 200 msec) - reaction(t) -> a, b {= - if (self.count % 2) == 0: - a.set(self.count) - else: - b.set(self.count) - =} + reaction(t) -> a, b {= + if (self.count % 2) == 0: + a.set(self.count) + else: + b.set(self.count) + =} } reactor Destination { - input a - input b + input a + input b - reaction(a) {= - if a.is_present is not True: - sys.stderr.write("Reaction to a triggered even though all inputs are absent!\n") - exit(1) - =} + reaction(a) {= + if a.is_present is not True: + sys.stderr.write("Reaction to a triggered even though all inputs are absent!\n") + exit(1) + =} - reaction(b) {= - if b.is_present is not True: - sys.stderr.write("Reaction to b triggered even though all inputs are absent!\n") - exit(2) - =} + reaction(b) {= + if b.is_present is not True: + sys.stderr.write("Reaction to b triggered even though all inputs are absent!\n") + exit(2) + =} } main reactor TriggerDownstreamOnlyIfPresent { - s = new[2] Source() - d = new[2] Destination() - s.a -> d.a - s.b -> d.b + s = new[2] Source() + d = new[2] Destination() + s.a -> d.a + s.b -> d.b } diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf index b9a9184296..2975045571 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf @@ -1,40 +1,37 @@ -/** - * This test checks that a downstream reaction is triggered only if its trigger - * is present. - */ +/** This test checks that a downstream reaction is triggered only if its trigger is present. */ target Python { - timeout: 1 sec, - fast: true + timeout: 1 sec, + fast: true } reactor Source { - output[2] out - state count = 0 - timer t(0, 200 msec) + output[2] out + state count = 0 + timer t(0, 200 msec) - reaction(t) -> out {= - if (self.count % 2) == 0: - self.count += 1 - out[0].set(self.count) - else: - out[1].set(self.count) - =} + reaction(t) -> out {= + if (self.count % 2) == 0: + self.count += 1 + out[0].set(self.count) + else: + out[1].set(self.count) + =} } reactor Destination { - input _in + input _in - reaction(_in) {= - if _in.is_present is not True: - sys.stderr.write("Reaction to input of triggered even though all inputs are absent!\n") - exit(1) - =} + reaction(_in) {= + if _in.is_present is not True: + sys.stderr.write("Reaction to input of triggered even though all inputs are absent!\n") + exit(1) + =} - reaction(shutdown) {= print("SUCCESS.") =} + reaction(shutdown) {= print("SUCCESS.") =} } main reactor TriggerDownstreamOnlyIfPresent2 { - s = new Source() - d = new[2] Destination() - s.out -> d._in + s = new Source() + d = new[2] Destination() + s.out -> d._in } diff --git a/test/Python/src/UnconnectedInput.lf b/test/Python/src/UnconnectedInput.lf index 66f459138b..f518731c20 100644 --- a/test/Python/src/UnconnectedInput.lf +++ b/test/Python/src/UnconnectedInput.lf @@ -1,53 +1,53 @@ # Test unconnected input. target Python { - timeout: 5 sec, - fast: true + timeout: 5 sec, + fast: true } reactor Source { - output out - timer t(0, 1 sec) - state s = 1 - - reaction(t) -> out {= - out.set(self.s) - self.s += 1 - =} + output out + timer t(0, 1 sec) + state s = 1 + + reaction(t) -> out {= + out.set(self.s) + self.s += 1 + =} } reactor Add { - input in1 - input in2 - output out - - reaction(in1, in2) -> out {= - result = 0 - if in1.is_present: - result += in1.value - if in2.is_present: - result += in2.value - out.set(result) - =} + input in1 + input in2 + output out + + reaction(in1, in2) -> out {= + result = 0 + if in1.is_present: + result += in1.value + if in2.is_present: + result += in2.value + out.set(result) + =} } reactor Print { - input _in - state expected = 1 + input _in + state expected = 1 - reaction(_in) {= - print("Received: ", _in.value) - if _in.value != self.expected: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.expected)) - exit(1) + reaction(_in) {= + print("Received: ", _in.value) + if _in.value != self.expected: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.expected)) + exit(1) - self.expected +=1 - =} + self.expected +=1 + =} } main reactor UnconnectedInput { - source = new Source() - add = new Add() - print = new Print() - source.out -> add.in2 - add.out -> print._in + source = new Source() + add = new Add() + print = new Print() + source.out -> add.in2 + add.out -> print._in } diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index 5ef4167bed..bc61fb8c53 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -1,60 +1,59 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test - * periodically creates a concurrent Python thread that schedule a physical - * action twice. + * Test asynchronous callbacks that trigger a physical action. This test periodically creates a + * concurrent Python thread that schedule a physical action twice. */ target Python { - timeout: 2 sec + timeout: 2 sec } main reactor AsyncCallback { - preamble {= - # Note that preamble code is generated inside the reactor class in Python - import time - import threading + preamble {= + # Note that preamble code is generated inside the reactor class in Python + import time + import threading - def callback(self, a): - # Schedule twice. If the action is not physical, these should - # get consolidated into a single action triggering. If it is, - # then they cause two separate triggerings with close but not - # equal time stamps. The minimum time between these is determined - # by the argument in the physical action definition. - a.schedule(0) - a.schedule(0) + def callback(self, a): + # Schedule twice. If the action is not physical, these should + # get consolidated into a single action triggering. If it is, + # then they cause two separate triggerings with close but not + # equal time stamps. The minimum time between these is determined + # by the argument in the physical action definition. + a.schedule(0) + a.schedule(0) - # Simulate time passing before a callback occurs. - def take_time(self, a): - # The best Python can offer short of directly using ctypes to call nanosleep - self.time.sleep(0.1) - self.callback(a) - return None - =} - timer t(0, 200 msec) - state threads = {= list() =} - state expected_time = 100 msec - state toggle = False + # Simulate time passing before a callback occurs. + def take_time(self, a): + # The best Python can offer short of directly using ctypes to call nanosleep + self.time.sleep(0.1) + self.callback(a) + return None + =} + timer t(0, 200 msec) + state threads = {= list() =} + state expected_time = 100 msec + state toggle = False - physical action a(100 msec) - state i = 0 + physical action a(100 msec) + state i = 0 - reaction(t) -> a {= - # start new thread, provide callback - x = self.threading.Thread(target=self.take_time, args=(a,)) - self.threads.append(x) - x.start() - =} + reaction(t) -> a {= + # start new thread, provide callback + x = self.threading.Thread(target=self.take_time, args=(a,)) + self.threads.append(x) + x.start() + =} - reaction(a) {= - elapsed_time = lf.time.logical_elapsed() - print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); - self.i += 1 - if elapsed_time <= self.expected_time: - sys.stderr.write("ERROR: Expected logical time to be larger than {:d}.".format(self.expected_time)); - exit(1) - if self.toggle: - self.toggle = False - self.expected_time += 200000000 - else: - self.toggle = True - =} + reaction(a) {= + elapsed_time = lf.time.logical_elapsed() + print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); + self.i += 1 + if elapsed_time <= self.expected_time: + sys.stderr.write("ERROR: Expected logical time to be larger than {:d}.".format(self.expected_time)); + exit(1) + if self.toggle: + self.toggle = False + self.expected_time += 200000000 + else: + self.toggle = True + =} } diff --git a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf index 4e481d1d34..971b4db6ce 100644 --- a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf +++ b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf @@ -1,64 +1,64 @@ /** - * Test asynchronous callbacks that trigger a physical action. This test creates - * a concurrent Python thread that schedule a physical action twice. + * Test asynchronous callbacks that trigger a physical action. This test creates a concurrent Python + * thread that schedule a physical action twice. * - * There are no timers in this test to drive the logical time forward. This is - * important in the Python target since the user Python threads should be - * allowed to execute independently of the underlying C core runtime, without - * the C runtime polling the Python context with a reaction to a timer. + * There are no timers in this test to drive the logical time forward. This is important in the + * Python target since the user Python threads should be allowed to execute independently of the + * underlying C core runtime, without the C runtime polling the Python context with a reaction to a + * timer. */ target Python { - timeout: 2 sec + timeout: 2 sec } main reactor { - preamble {= - # Note that preamble code is generated inside the reactor class in Python - import time - import threading + preamble {= + # Note that preamble code is generated inside the reactor class in Python + import time + import threading - def callback(self, a): - # Schedule twice. If the action is not physical, these should - # get consolidated into a single action triggering. If it is, - # then they cause two separate triggerings with close but not - # equal time stamps. The minimum time between these is determined - # by the argument in the physical action definition. - a.schedule(0) - a.schedule(0) + def callback(self, a): + # Schedule twice. If the action is not physical, these should + # get consolidated into a single action triggering. If it is, + # then they cause two separate triggerings with close but not + # equal time stamps. The minimum time between these is determined + # by the argument in the physical action definition. + a.schedule(0) + a.schedule(0) - # Simulate time passing before a callback occurs. - def take_time(self, a): - # The best Python can offer short of directly using ctypes to call nanosleep - self.time.sleep(0.1) - self.callback(a) - return None - =} + # Simulate time passing before a callback occurs. + def take_time(self, a): + # The best Python can offer short of directly using ctypes to call nanosleep + self.time.sleep(0.1) + self.callback(a) + return None + =} - state threads = {= list() =} - state expected_time = 100 msec - state toggle = False + state threads = {= list() =} + state expected_time = 100 msec + state toggle = False - physical action a(100 msec) - state i = 0 + physical action a(100 msec) + state i = 0 - reaction(startup) -> a {= - # start new thread, provide callback - x = self.threading.Thread(target=self.take_time, args=(a,)) - self.threads.append(x) - x.start() - =} + reaction(startup) -> a {= + # start new thread, provide callback + x = self.threading.Thread(target=self.take_time, args=(a,)) + self.threads.append(x) + x.start() + =} - reaction(a) {= - elapsed_time = lf.time.logical_elapsed() - print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); - self.i += 1 - if elapsed_time <= self.expected_time: - sys.stderr.write("ERROR: Expected logical time to be larger than {:d}.".format(self.expected_time)); - exit(1) - if self.toggle: - self.toggle = False - self.expected_time += 200000000 - else: - self.toggle = True - =} + reaction(a) {= + elapsed_time = lf.time.logical_elapsed() + print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); + self.i += 1 + if elapsed_time <= self.expected_time: + sys.stderr.write("ERROR: Expected logical time to be larger than {:d}.".format(self.expected_time)); + exit(1) + if self.toggle: + self.toggle = False + self.expected_time += 200000000 + else: + self.toggle = True + =} } diff --git a/test/Python/src/docker/FilesPropertyContainerized.lf b/test/Python/src/docker/FilesPropertyContainerized.lf index c34736af48..534f1416a5 100644 --- a/test/Python/src/docker/FilesPropertyContainerized.lf +++ b/test/Python/src/docker/FilesPropertyContainerized.lf @@ -1,32 +1,32 @@ target Python { - files: "../include/hello.py", - docker: true + files: "../include/hello.py", + docker: true } preamble {= + try: + import hello + except: + lf_request_stop() +=} + +main reactor { + preamble {= try: import hello except: lf_request_stop() -=} - -main reactor { - preamble {= - try: - import hello - except: - lf_request_stop() - =} - state passed = False - timer t(1 msec) + =} + state passed = False + timer t(1 msec) - reaction(t) {= self.passed = True =} + reaction(t) {= self.passed = True =} - reaction(shutdown) {= - if not self.passed: - print("Failed to import file listed in files target property") - exit(1) - else: - print("PASSED") - =} + reaction(shutdown) {= + if not self.passed: + print("Failed to import file listed in files target property") + exit(1) + else: + print("PASSED") + =} } diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index 5f8a348d24..48b71bd046 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -1,22 +1,21 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python { - timeout: 5 sec, - logging: DEBUG, - coordination: centralized, - docker: true + timeout: 5 sec, + logging: DEBUG, + coordination: centralized, + docker: true } import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" federated reactor DistributedCountContainerized(offset = 200 msec) at rti { - c = new Count() - p = new Print() - c.out -> p.in_ after offset + c = new Count() + p = new Print() + c.out -> p.in_ after offset } diff --git a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf index 911f0f3055..1fc26b13bc 100644 --- a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with decentralized - * coordination. + * Test for lf_request_stop() in federated execution with decentralized coordination. * * @author Soroush Bateni */ diff --git a/test/Python/src/federated/BroadcastFeedback.lf b/test/Python/src/federated/BroadcastFeedback.lf index 75d313e61d..b33b13742b 100644 --- a/test/Python/src/federated/BroadcastFeedback.lf +++ b/test/Python/src/federated/BroadcastFeedback.lf @@ -1,31 +1,29 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target Python { - timeout: 1 sec + timeout: 1 sec } reactor SenderAndReceiver { - output out - input[2] inp - state received = False + output out + input[2] inp + state received = False - reaction(startup) -> out {= out.set(42) =} + reaction(startup) -> out {= out.set(42) =} - reaction(inp) {= - if inp[0].is_present and inp[1].is_present and inp[0].value == 42 and inp[1].value == 42: - print("SUCCESS") - self.received = True - =} + reaction(inp) {= + if inp[0].is_present and inp[1].is_present and inp[0].value == 42 and inp[1].value == 42: + print("SUCCESS") + self.received = True + =} - reaction(shutdown) {= - if not self.received: - print("Failed to receive broadcast") - sys.exit(1) - =} + reaction(shutdown) {= + if not self.received: + print("Failed to receive broadcast") + sys.exit(1) + =} } federated reactor { - s = new[2] SenderAndReceiver() - (s.out)+ -> s.inp + s = new[2] SenderAndReceiver() + (s.out)+ -> s.inp } diff --git a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf index ad2a11c10c..5f50210a22 100644 --- a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -1,40 +1,38 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target Python { - timeout: 1 sec + timeout: 1 sec } reactor SenderAndReceiver { - output out - input[2] in_ - state received = False + output out + input[2] in_ + state received = False - r = new Receiver() - in_ -> r.in_ + r = new Receiver() + in_ -> r.in_ - reaction(startup) -> out {= out.set(42) =} + reaction(startup) -> out {= out.set(42) =} } reactor Receiver { - preamble {= import sys =} - input[2] in_ - state received = False + preamble {= import sys =} + input[2] in_ + state received = False - reaction(in_) {= - if in_[0].is_present and in_[1].is_present and in_[0].value == 42 and in_[1].value == 42: - print("SUCCESS") - self.received = True - =} + reaction(in_) {= + if in_[0].is_present and in_[1].is_present and in_[0].value == 42 and in_[1].value == 42: + print("SUCCESS") + self.received = True + =} - reaction(shutdown) {= - if not self.received: - print("Failed to receive broadcast") - self.sys.exit(1) - =} + reaction(shutdown) {= + if not self.received: + print("Failed to receive broadcast") + self.sys.exit(1) + =} } federated reactor { - s = new[2] SenderAndReceiver() - (s.out)+ -> s.in_ + s = new[2] SenderAndReceiver() + (s.out)+ -> s.in_ } diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index cf9b6d6b54..7161b963f8 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -1,57 +1,57 @@ /** - * Check whether the internally generated network and control reactions - * introduce a cycle or not. The failure for this test is not being compiled. + * Check whether the internally generated network and control reactions introduce a cycle or not. + * The failure for this test is not being compiled. * @author Edward A. Lee */ target Python reactor CAReplica { - input local_update - input remote_update - input query + input local_update + input remote_update + input query - state balance = 0 + state balance = 0 - output response + output response - reaction(local_update, remote_update) {= - if local_update.is_present: - self.balance += local_update.value - if remote_update.is_present: - self.balance += remote_update.value - =} + reaction(local_update, remote_update) {= + if local_update.is_present: + self.balance += local_update.value + if remote_update.is_present: + self.balance += remote_update.value + =} - reaction(query) -> response {= response.set(self.balance) =} + reaction(query) -> response {= response.set(self.balance) =} } reactor UserInput { - preamble {= import sys =} - input balance - output deposit + preamble {= import sys =} + input balance + output deposit - reaction(startup) -> deposit {= deposit.set(100) =} + reaction(startup) -> deposit {= deposit.set(100) =} - reaction(balance) {= - if balance.value != 200: - self.sys.stderr.write("Did not receive the expected balance. Expected: 200. Got: {}.\n".format(balance.value)) - self.sys.exit(1) - print("Balance: {}".format(balance.value)) - lf_request_stop() - =} + reaction(balance) {= + if balance.value != 200: + self.sys.stderr.write("Did not receive the expected balance. Expected: 200. Got: {}.\n".format(balance.value)) + self.sys.exit(1) + print("Balance: {}".format(balance.value)) + lf_request_stop() + =} - reaction(shutdown) {= print("Test passed!") =} + reaction(shutdown) {= print("Test passed!") =} } federated reactor { - u1 = new UserInput() - r1 = new CAReplica() - u2 = new UserInput() - r2 = new CAReplica() - (u1.deposit)+ -> r1.query, r1.local_update - r1.response -> u1.balance - u1.deposit -> r2.remote_update - - (u2.deposit)+ -> r2.query, r2.local_update - r2.response -> u2.balance - u2.deposit -> r1.remote_update + u1 = new UserInput() + r1 = new CAReplica() + u2 = new UserInput() + r2 = new CAReplica() + (u1.deposit)+ -> r1.query, r1.local_update + r1.response -> u1.balance + u1.deposit -> r2.remote_update + + (u2.deposit)+ -> r2.query, r2.local_update + r2.response -> u2.balance + u2.deposit -> r1.remote_update } diff --git a/test/Python/src/federated/DecentralizedP2PComm.lf b/test/Python/src/federated/DecentralizedP2PComm.lf index 2725386915..922b3a7008 100644 --- a/test/Python/src/federated/DecentralizedP2PComm.lf +++ b/test/Python/src/federated/DecentralizedP2PComm.lf @@ -1,47 +1,47 @@ target Python { - timeout: 1 sec, - tracing: true, - clock-sync: off, - coordination: decentralized + timeout: 1 sec, + tracing: true, + clock-sync: off, + coordination: decentralized } reactor Platform(start = 0, expected_start = 0, stp_offset_param = 0) { - preamble {= import sys =} - input in_ - output out - timer t(0, 100 msec) - state count = start - state expected = expected_start + preamble {= import sys =} + input in_ + output out + timer t(0, 100 msec) + state count = start + state expected = expected_start - reaction(t) -> out {= - out.set(self.count) - self.count += 1 - =} + reaction(t) -> out {= + out.set(self.count) + self.count += 1 + =} - reaction(in_) {= - print("Received {}.".format(in_.value)) - if in_.value != self.expected: - self.sys.stderr.write("Expected {} but got {}.\n".format(self.expected_start, in_.value)) - self.sys.exit(1) - self.expected += 1 - =} STP(stp_offset_param) {= - print("Received {} late.".format(in_.value)) - current_tag = lf.tag() - self.expected += 1 - self.sys.stderr.write("STP offset was violated by ({}, {}).".format(current_tag.time - in_.intended_tag.time, current_tag.microstep - in_.intended_tag.microstep)) - =} + reaction(in_) {= + print("Received {}.".format(in_.value)) + if in_.value != self.expected: + self.sys.stderr.write("Expected {} but got {}.\n".format(self.expected_start, in_.value)) + self.sys.exit(1) + self.expected += 1 + =} STP(stp_offset_param) {= + print("Received {} late.".format(in_.value)) + current_tag = lf.tag() + self.expected += 1 + self.sys.stderr.write("STP offset was violated by ({}, {}).".format(current_tag.time - in_.intended_tag.time, current_tag.microstep - in_.intended_tag.microstep)) + =} - reaction(shutdown) {= - print("Shutdown invoked.") - if self.expected == self.expected_start: - self.sys.stderr.write("Did not receive anything.\n") - self.sys.exit(1) - =} + reaction(shutdown) {= + print("Shutdown invoked.") + if self.expected == self.expected_start: + self.sys.stderr.write("Did not receive anything.\n") + self.sys.exit(1) + =} } federated reactor DecentralizedP2PComm { - a = new Platform(expected_start = 100, stp_offset_param = 10 msec) - b = new Platform(start = 100, stp_offset_param = 10 msec) - a.out -> b.in_ - b.out -> a.in_ + a = new Platform(expected_start = 100, stp_offset_param = 10 msec) + b = new Platform(start = 100, stp_offset_param = 10 msec) + a.out -> b.in_ + b.out -> a.in_ } diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 48ff7a4ca7..a91a9fd9ec 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -1,57 +1,56 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed about lost messages. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed about lost messages. * * The test fails if the federation does not exit. */ target Python { - timeout: 1 msec, - coordination: decentralized + timeout: 1 msec, + coordination: decentralized } # reason for failing: lf_tag() not supported by the python target reactor Clock(offset = 0, period = 1 sec) { - output y - timer t(offset, period) - state count = 0 + output y + timer t(offset, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - print("Sending {}.".format(self.count)) - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + print("Sending {}.".format(self.count)) + y.set(self.count) + =} - reaction(shutdown) {= print("SUCCESS: the source exited successfully.") =} + reaction(shutdown) {= print("SUCCESS: the source exited successfully.") =} } reactor Destination { - preamble {= import sys =} - input x - state s = 1 - state startup_logical_time - - reaction(startup) {= self.startup_logical_time = lf.time.logical() =} - - reaction(x) {= - print("Received {}".format(x.value)) - current_tag = lf.tag() - if x.value != self.s: - error_msg = "At tag ({}, {}) expected {} and got {}.".format(current_tag.time - self.startup_logical_time, current_tag.microstep, self.s, x.value) - self.sys.stderr.write(error_msg) - self.sys.exit(1) - self.s += 1 - =} - - reaction(shutdown) {= - print("**** shutdown reaction invoked.") - print("Approx. time per reaction: {}ns".format(lf.time.physical_elapsed()//(self.s+1))) - =} + preamble {= import sys =} + input x + state s = 1 + state startup_logical_time + + reaction(startup) {= self.startup_logical_time = lf.time.logical() =} + + reaction(x) {= + print("Received {}".format(x.value)) + current_tag = lf.tag() + if x.value != self.s: + error_msg = "At tag ({}, {}) expected {} and got {}.".format(current_tag.time - self.startup_logical_time, current_tag.microstep, self.s, x.value) + self.sys.stderr.write(error_msg) + self.sys.exit(1) + self.s += 1 + =} + + reaction(shutdown) {= + print("**** shutdown reaction invoked.") + print("Approx. time per reaction: {}ns".format(lf.time.physical_elapsed()//(self.s+1))) + =} } federated reactor(period = 10 usec) { - c = new Clock(period = period) - d = new Destination() - c.y -> d.x + c = new Clock(period = period) + d = new Destination() + c.y -> d.x } diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 4eb881694f..15069f0aea 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -1,50 +1,49 @@ /** - * Test a source-destination scenario where the source falls behind real-time, - * and reaches the timeout much later than the destination. In this test, the - * destination closes the connection early, causing the transmission to fail. - * Warnings will be printed. + * Test a source-destination scenario where the source falls behind real-time, and reaches the + * timeout much later than the destination. In this test, the destination closes the connection + * early, causing the transmission to fail. Warnings will be printed. * - * The test fails if the federation does not exit amenably. This variant has a - * physical connection between source and destination. + * The test fails if the federation does not exit amenably. This variant has a physical connection + * between source and destination. */ target Python { - timeout: 1 msec, - coordination: decentralized + timeout: 1 msec, + coordination: decentralized } reactor Clock(offset = 0, period = 1 sec) { - output y - timer t(offset, period) - state count = 0 + output y + timer t(offset, period) + state count = 0 - reaction(t) -> y {= - self.count += 1 - y.set(self.count) - =} + reaction(t) -> y {= + self.count += 1 + y.set(self.count) + =} - reaction(shutdown) {= print("SUCCESS: the source exited successfully.") =} + reaction(shutdown) {= print("SUCCESS: the source exited successfully.") =} } reactor Destination { - preamble {= import sys =} - input x - state s = 1 + preamble {= import sys =} + input x + state s = 1 - reaction(x) {= - if x.value != self.s: - self.sys.stderr.write("Expected {} and got {}.".format(self.s, x.value)) - self.sys.exit(1) - self.s += 1 - =} + reaction(x) {= + if x.value != self.s: + self.sys.stderr.write("Expected {} and got {}.".format(self.s, x.value)) + self.sys.exit(1) + self.s += 1 + =} - reaction(shutdown) {= - print("**** shutdown reaction invoked.") - print("Approx. time per reaction: {}ns".format(lf.time.physical_elapsed()//(self.s+1))) - =} + reaction(shutdown) {= + print("**** shutdown reaction invoked.") + print("Approx. time per reaction: {}ns".format(lf.time.physical_elapsed()//(self.s+1))) + =} } federated reactor(period = 10 usec) { - c = new Clock(period = period) - d = new Destination() - c.y ~> d.x + c = new Clock(period = period) + d = new Destination() + c.y ~> d.x } diff --git a/test/Python/src/federated/DistributedBank.lf b/test/Python/src/federated/DistributedBank.lf index de9ea298e4..65115acafb 100644 --- a/test/Python/src/federated/DistributedBank.lf +++ b/test/Python/src/federated/DistributedBank.lf @@ -1,26 +1,26 @@ # Check bank of federates. target Python { - timeout: 1 sec, - coordination: centralized + timeout: 1 sec, + coordination: centralized } reactor Node { - preamble {= import sys =} - timer t(0, 100 msec) - state count = 0 + preamble {= import sys =} + timer t(0, 100 msec) + state count = 0 - reaction(t) {= - print("Hello world {}.".format(self.count)) - self.count += 1 - =} + reaction(t) {= + print("Hello world {}.".format(self.count)) + self.count += 1 + =} - reaction(shutdown) {= - if self.count == 0: - self.sys.stderr.write("Timer reactions did not execute.\n") - self.sys.exit(1) - =} + reaction(shutdown) {= + if self.count == 0: + self.sys.stderr.write("Timer reactions did not execute.\n") + self.sys.exit(1) + =} } federated reactor DistributedBank { - n = new[2] Node() + n = new[2] Node() } diff --git a/test/Python/src/federated/DistributedBankToMultiport.lf b/test/Python/src/federated/DistributedBankToMultiport.lf index 493e73a3b1..534e623d19 100644 --- a/test/Python/src/federated/DistributedBankToMultiport.lf +++ b/test/Python/src/federated/DistributedBankToMultiport.lf @@ -1,33 +1,33 @@ # Check multiport to bank connections between federates. target Python { - timeout: 3 sec + timeout: 3 sec } import Count from "../lib/Count.lf" reactor Destination { - preamble {= import sys =} - input[2] in_ - state count = 1 + preamble {= import sys =} + input[2] in_ + state count = 1 - reaction(in_) {= - for i in range(len(in_)): - print("Received {}.".format(in_[i].value)) - if self.count != in_[i].value: - self.sys.stderr.write("Expected {}.\n".format(self.count)) - self.sys.exit(1) - self.count += 1 - =} - - reaction(shutdown) {= - if self.count == 0: - self.sys.stderr.write("No data received.\n") + reaction(in_) {= + for i in range(len(in_)): + print("Received {}.".format(in_[i].value)) + if self.count != in_[i].value: + self.sys.stderr.write("Expected {}.\n".format(self.count)) self.sys.exit(1) - =} + self.count += 1 + =} + + reaction(shutdown) {= + if self.count == 0: + self.sys.stderr.write("No data received.\n") + self.sys.exit(1) + =} } federated reactor { - s = new[2] Count() - d = new Destination() - s.out -> d.in_ + s = new[2] Count() + d = new Destination() + s.out -> d.in_ } diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index 7713256520..20c8beedc5 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -1,43 +1,42 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python { - timeout: 5 sec, - coordination: centralized + timeout: 5 sec, + coordination: centralized } import Count from "../lib/Count.lf" reactor Print { - preamble {= import sys =} - input in_ - state c = 1 + preamble {= import sys =} + input in_ + state c = 1 - reaction(in_) {= - elapsed_time = lf.time.logical_elapsed() - print("At time {}, received {}".format(elapsed_time, in_.value)) - if in_.value != self.c: - print("Expected to receive {}.".format(self.c)) - self.sys.exit(1) - if elapsed_time != MSEC(200) + SEC(1) * (self.c - 1): - print("Expected received time to be {}.".format(MSEC(200) * self.c)) - self.sys.exit(1) - self.c += 1 - =} + reaction(in_) {= + elapsed_time = lf.time.logical_elapsed() + print("At time {}, received {}".format(elapsed_time, in_.value)) + if in_.value != self.c: + print("Expected to receive {}.".format(self.c)) + self.sys.exit(1) + if elapsed_time != MSEC(200) + SEC(1) * (self.c - 1): + print("Expected received time to be {}.".format(MSEC(200) * self.c)) + self.sys.exit(1) + self.c += 1 + =} - reaction(shutdown) {= - if self.c != 6: - print("Expected to receive 5 items.") - self.sys.exit(1) - =} + reaction(shutdown) {= + if self.c != 6: + print("Expected to receive 5 items.") + self.sys.exit(1) + =} } federated reactor DistributedCount(offset = 200 msec) { - c = new Count() - p = new Print() - c.out -> p.in_ after offset + c = new Count() + p = new Print() + c.out -> p.in_ after offset } diff --git a/test/Python/src/federated/DistributedCountDecentralized.lf b/test/Python/src/federated/DistributedCountDecentralized.lf index e86adf9946..6b664335dd 100644 --- a/test/Python/src/federated/DistributedCountDecentralized.lf +++ b/test/Python/src/federated/DistributedCountDecentralized.lf @@ -1,46 +1,44 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ # reason for failing: in_.intended_tag are not supported in python target target Python { - timeout: 5 sec, - coordination: decentralized + timeout: 5 sec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor Print { - preamble {= import sys =} - input in_ - state c = 1 + preamble {= import sys =} + input in_ + state c = 1 - reaction(in_) {= - print(f"At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), received {in_.value}. " - f"The original intended tag of the message was ({in_.intended_tag.time-lf.time.start()}, {in_.intended_tag.microstep}).") - if in_.value != self.c: - print("Expected to receive {}.".format(self.c)) - self.sys.exit(1) - if lf.time.logical_elapsed() != MSEC(200) + SEC(1) * (self.c - 1): - print("Expected received time to be {}.".format(MSEC(200) * self.c)) - self.sys.exit(3) - self.c += 1 - =} + reaction(in_) {= + print(f"At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), received {in_.value}. " + f"The original intended tag of the message was ({in_.intended_tag.time-lf.time.start()}, {in_.intended_tag.microstep}).") + if in_.value != self.c: + print("Expected to receive {}.".format(self.c)) + self.sys.exit(1) + if lf.time.logical_elapsed() != MSEC(200) + SEC(1) * (self.c - 1): + print("Expected received time to be {}.".format(MSEC(200) * self.c)) + self.sys.exit(3) + self.c += 1 + =} - reaction(shutdown) {= - if self.c != 6: - self.sys.stderr.write("Expected to receive 5 items.\n") - self.sys.exit(2) - print("SUCCESS: Successfully received 5 items.") - =} + reaction(shutdown) {= + if self.c != 6: + self.sys.stderr.write("Expected to receive 5 items.\n") + self.sys.exit(2) + print("SUCCESS: Successfully received 5 items.") + =} } federated reactor DistributedCountDecentralized { - c = new Count() - p = new Print() - # Indicating a 'logical' connection with a large enough delay. - c.out -> p.in_ after 200 msec + c = new Count() + p = new Print() + c.out -> p.in_ after 200 msec # Indicating a 'logical' connection with a large enough delay. } diff --git a/test/Python/src/federated/DistributedCountDecentralizedLate.lf b/test/Python/src/federated/DistributedCountDecentralizedLate.lf index e3a6899e78..b0cedf9a80 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLate.lf @@ -1,70 +1,65 @@ /** - * Test a form of a distributed deterministic system where a federate that - * receives timestamped messages has a timer in addition to the messages as - * triggers. Therefore, careful coordination of the advancement of time using - * Ptides is needed. + * Test a form of a distributed deterministic system where a federate that receives timestamped + * messages has a timer in addition to the messages as triggers. Therefore, careful coordination of + * the advancement of time using Ptides is needed. * @author Edward A. Lee * @author Soroush Bateni */ target Python { - timeout: 4900 msec, - coordination: decentralized + timeout: 4900 msec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor Print { - preamble {= import sys =} - # STP () - input in_ - # STP(in, 30 msec); - state success = 0 - state success_stp_violation = 0 - # Force a timer to be invoke periodically - timer t(0, 10 usec) - # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + preamble {= import sys =} + input in_ # STP () + state success = 0 # STP(in, 30 msec); + state success_stp_violation = 0 + timer t(0, 10 usec) # Force a timer to be invoke periodically + state c = 0 # to ensure logical time will advance in the absence of incoming messages. - reaction(in_) {= - current_tag = lf.tag() - print("At tag ({}, {}) received {}. Intended tag is ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep, - in_.value, - in_.intended_tag.time - lf.time.start(), - in_.intended_tag.microstep - ) - ) - if (lf.tag() == Tag(SEC(1), 0)): - self.success += 1 # Message was on-time - self.c += 1 - =} STP(0) {= - current_tag = lf.tag() - print("At tag ({}, {}), message has violated the STP offset by ({}, {}).".format( - current_tag.time - lf.time.start(), current_tag.microstep, - current_tag.time - in_.intended_tag.time, - current_tag.microstep - in_.intended_tag.microstep - ) + reaction(in_) {= + current_tag = lf.tag() + print("At tag ({}, {}) received {}. Intended tag is ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep, + in_.value, + in_.intended_tag.time - lf.time.start(), + in_.intended_tag.microstep ) - self.success_stp_violation += 1 - self.c += 1 - =} + ) + if (lf.tag() == Tag(SEC(1), 0)): + self.success += 1 # Message was on-time + self.c += 1 + =} STP(0) {= + current_tag = lf.tag() + print("At tag ({}, {}), message has violated the STP offset by ({}, {}).".format( + current_tag.time - lf.time.start(), current_tag.microstep, + current_tag.time - in_.intended_tag.time, + current_tag.microstep - in_.intended_tag.microstep + ) + ) + self.success_stp_violation += 1 + self.c += 1 + =} - reaction(t) {= - # Do nothing. - =} + reaction(t) {= + # Do nothing. + =} - reaction(shutdown) {= - if self.success + self.success_stp_violation != 5: - self.sys.stderr.write("Failed to detect STP violations in messages.\n") - self.sys.exit(1) - else: - print("Successfully detected STP violation ({} violations, {} on-time).".format(self.success_stp_violation, self.success)) - =} + reaction(shutdown) {= + if self.success + self.success_stp_violation != 5: + self.sys.stderr.write("Failed to detect STP violations in messages.\n") + self.sys.exit(1) + else: + print("Successfully detected STP violation ({} violations, {} on-time).".format(self.success_stp_violation, self.success)) + =} } federated reactor { - c = new Count() - p = new Print() - c.out -> p.in_ # Indicating a 'logical' connection. + c = new Count() + p = new Print() + c.out -> p.in_ # Indicating a 'logical' connection. } diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf b/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf index c1c641827f..a82d66675b 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf @@ -1,102 +1,94 @@ /** - * Test a form of a distributed deterministic system where a federate that - * receives timestamped messages has a timer in addition to the messages as - * triggers. Therefore, careful coordination of the advancement of time using - * Ptides is needed. In addition, this test shows that the STP violation is - * passed down the hierarchy until it is handled. + * Test a form of a distributed deterministic system where a federate that receives timestamped + * messages has a timer in addition to the messages as triggers. Therefore, careful coordination of + * the advancement of time using Ptides is needed. In addition, this test shows that the STP + * violation is passed down the hierarchy until it is handled. * - * An STP violation occurs if when a message with intended tag g1 arrives on a - * port p after the receiving federate has progressed far enough that it cannot - * process an event with tag g1 on the port p. This test has a fast timer (10 - * usec period) in the receiving federate so that the receiving federate is - * continually advancing its current tag, and hence an STP violation is more - * likely to occur. Furthermore, this test sets the STP threshold to 0, which - * makes the violation extremely likely to occur. It could still not occur, - * however, if the message arrives between ticks of the 10 usec timer. + * An STP violation occurs if when a message with intended tag g1 arrives on a port p after the + * receiving federate has progressed far enough that it cannot process an event with tag g1 on the + * port p. This test has a fast timer (10 usec period) in the receiving federate so that the + * receiving federate is continually advancing its current tag, and hence an STP violation is more + * likely to occur. Furthermore, this test sets the STP threshold to 0, which makes the violation + * extremely likely to occur. It could still not occur, however, if the message arrives between + * ticks of the 10 usec timer. * * @author Edward A. Lee * @author Soroush Bateni */ target Python { - # 9 msec headroom for the last (probably tardy) message to arrive. - timeout: 1900 msec, - coordination: decentralized + timeout: 1900 msec, # 9 msec headroom for the last (probably tardy) message to arrive. + coordination: decentralized } import Count from "../lib/Count.lf" reactor ImportantActuator { - input inp - # Count messages that arrive without STP violation. - state success = 0 - state success_stp_violation = 0 - # Force a timer to be invoked periodically - timer t(0, 10 usec) - # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + input inp + state success = 0 # Count messages that arrive without STP violation. + state success_stp_violation = 0 + timer t(0, 10 usec) # Force a timer to be invoked periodically + state c = 0 # to ensure logical time will advance in the absence of incoming messages. - reaction(inp) {= - current_tag = lf.tag() - print(f"ImportantActuator: At tag ({lf.tag().time}, {lf.tag().microstep}) received {inp.value}. " - f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") - if lf.tag() == Tag((SEC(1) * self.c) + + lf.time.start(), 0): - self.success += 1 # Message was on-time - else: - self.sys.stderr.write("Normal reaction was invoked, but current tag doesn't match expected tag.") - self.sys.exit(1) - self.c += 1 - =} STP(0) {= - current_tag = lf.tag() - print(f"ImportantActuator: At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), message has violated the STP offset " - f"by ({lf.tag().time - inp.intended_tag.time}, {lf.tag().microstep - inp.intended_tag.microstep}).") - self.success_stp_violation += 1 - self.c += 1 - =} + reaction(inp) {= + current_tag = lf.tag() + print(f"ImportantActuator: At tag ({lf.tag().time}, {lf.tag().microstep}) received {inp.value}. " + f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") + if lf.tag() == Tag((SEC(1) * self.c) + + lf.time.start(), 0): + self.success += 1 # Message was on-time + else: + self.sys.stderr.write("Normal reaction was invoked, but current tag doesn't match expected tag.") + self.sys.exit(1) + self.c += 1 + =} STP(0) {= + current_tag = lf.tag() + print(f"ImportantActuator: At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), message has violated the STP offset " + f"by ({lf.tag().time - inp.intended_tag.time}, {lf.tag().microstep - inp.intended_tag.microstep}).") + self.success_stp_violation += 1 + self.c += 1 + =} - reaction(t) {= - # Do nothing. - =} + reaction(t) {= + # Do nothing. + =} - reaction(shutdown) {= - if (self.success + self.success_stp_violation) != 2: - self.sys.stderr.write("Failed to detect STP violation in messages.") - self.sys.exit(1) - else: - print(f"Successfully detected STP violations ({self.success_stp_violation} violations, {self.success} on-time).") - =} + reaction(shutdown) {= + if (self.success + self.success_stp_violation) != 2: + self.sys.stderr.write("Failed to detect STP violation in messages.") + self.sys.exit(1) + else: + print(f"Successfully detected STP violations ({self.success_stp_violation} violations, {self.success} on-time).") + =} } reactor Print { - input inp + input inp - reaction(inp) {= - current_tag = lf.tag(); - print(f"Print reactor: at tag ({lf.time.logical_elapsed()}, lf.tag().microstep) received {inp.value}. " - f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") - =} + reaction(inp) {= + current_tag = lf.tag(); + print(f"Print reactor: at tag ({lf.time.logical_elapsed()}, lf.tag().microstep) received {inp.value}. " + f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") + =} } reactor Receiver { - input inp - # Force a timer to be invoke periodically - timer t(0, 10 msec) - # to ensure logical time will advance in the absence of incoming messages. - state c = 0 - p = new Print() - a = new ImportantActuator() + input inp + timer t(0, 10 msec) # Force a timer to be invoke periodically + state c = 0 # to ensure logical time will advance in the absence of incoming messages. + p = new Print() + a = new ImportantActuator() - reaction(inp) -> p.inp, a.inp {= - p.inp.set(inp.value + 1) - a.inp.set(inp.value + 1) - =} + reaction(inp) -> p.inp, a.inp {= + p.inp.set(inp.value + 1) + a.inp.set(inp.value + 1) + =} - reaction(t) {= - # Do nothing. - =} + reaction(t) {= + # Do nothing. + =} } federated reactor { - c = new Count(period = 1 sec) - r = new Receiver() - c.out -> r.inp # Indicating a 'logical' connection. + c = new Count(period = 1 sec) + r = new Receiver() + c.out -> r.inp # Indicating a 'logical' connection. } diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf index d806ab5453..8d480a0122 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -1,39 +1,36 @@ /** - * Test a form of a distributed deterministic system where a federate that - * receives timestamped messages has a timer in addition to the messages as - * triggers. Therefore, careful coordination of the advancement of time using - * Ptides is needed. In addition, this test shows that the STP violation of the - * reaction is passed down the hierarchy until it is handled. + * Test a form of a distributed deterministic system where a federate that receives timestamped + * messages has a timer in addition to the messages as triggers. Therefore, careful coordination of + * the advancement of time using Ptides is needed. In addition, this test shows that the STP + * violation of the reaction is passed down the hierarchy until it is handled. * * @author Edward A. Lee * @author Soroush Bateni */ target Python { - timeout: 4900 msec, - coordination: decentralized + timeout: 4900 msec, + coordination: decentralized } import Count from "../lib/Count.lf" import ImportantActuator, Print from "DistributedCountDecentralizedLateDownstream.lf" reactor Receiver { - input inp - # Force a timer to be invoke periodically - timer t(0, 10 msec) - # to ensure logical time will advance in the absence of incoming messages. - state c = 0 - p = new Print() - a = new ImportantActuator() - inp -> p.inp - inp -> a.inp + input inp + timer t(0, 10 msec) # Force a timer to be invoke periodically + state c = 0 # to ensure logical time will advance in the absence of incoming messages. + p = new Print() + a = new ImportantActuator() + inp -> p.inp + inp -> a.inp - reaction(t) {= - # Do nothing. - =} + reaction(t) {= + # Do nothing. + =} } federated reactor { - c = new Count() - r = new Receiver() - c.out -> r.inp # Indicating a 'logical' connection. + c = new Count() + r = new Receiver() + c.out -> r.inp # Indicating a 'logical' connection. } diff --git a/test/Python/src/federated/DistributedCountPhysical.lf b/test/Python/src/federated/DistributedCountPhysical.lf index 69bc2faee9..af59f4da8f 100644 --- a/test/Python/src/federated/DistributedCountPhysical.lf +++ b/test/Python/src/federated/DistributedCountPhysical.lf @@ -1,54 +1,54 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni */ target Python { - timeout: 1 sec + timeout: 1 sec } reactor Count { - timer t(200 msec, 1 sec) - state s = 0 - output out + timer t(200 msec, 1 sec) + state s = 0 + output out - reaction(t) -> out {= - out.set(self.s) - self.s += 1; - =} + reaction(t) -> out {= + out.set(self.s) + self.s += 1; + =} } reactor Print { - preamble {= import sys =} - input in_ - state c = 0 + preamble {= import sys =} + input in_ + state c = 0 - reaction(in_) {= - elapsed_time = lf.time.logical_elapsed() - print("At time {}, received {}.".format(elapsed_time, in_.value)) - if in_.value != self.c: - self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) - self.sys.exit(1) - if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): - self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}. Got {}.\n".format(MSEC(200) * self.c, elapsed_time)) - self.sys.exit(3) - self.c += 1 - =} + reaction(in_) {= + elapsed_time = lf.time.logical_elapsed() + print("At time {}, received {}.".format(elapsed_time, in_.value)) + if in_.value != self.c: + self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) + self.sys.exit(1) + if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): + self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}. Got {}.\n".format(MSEC(200) * self.c, elapsed_time)) + self.sys.exit(3) + self.c += 1 + =} - reaction(shutdown) {= - if (self.c != 1): - self.sys.stderr.write("ERROR: Expected to receive 1 item. Received {}.\n".format(self.c)) - self.sys.exit(2) - print("SUCCESS: Successfully received 1 item."); - =} + reaction(shutdown) {= + if (self.c != 1): + self.sys.stderr.write("ERROR: Expected to receive 1 item. Received {}.\n".format(self.c)) + self.sys.exit(2) + print("SUCCESS: Successfully received 1 item."); + =} } federated reactor at localhost { - c = new Count() - p = new Print() - c.out ~> p.in_ # Indicating a 'physical' connection. + c = new Count() + p = new Print() + c.out ~> p.in_ # Indicating a 'physical' connection. } diff --git a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf index 105413d0a0..dd753fca44 100644 --- a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,54 +1,54 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni */ target Python { - timeout: 1 sec + timeout: 1 sec } reactor Count { - timer t(200 msec, 1 sec) - state s = 0 - output out + timer t(200 msec, 1 sec) + state s = 0 + output out - reaction(t) -> out {= - out.set(self.s) - self.s += 1; - =} + reaction(t) -> out {= + out.set(self.s) + self.s += 1; + =} } reactor Print { - preamble {= import sys =} - input in_ - state c = 0 + preamble {= import sys =} + input in_ + state c = 0 - reaction(in_) {= - elapsed_time = lf.time.logical_elapsed() - print("At time {}, received {}.".format(elapsed_time, in_.value)) - if in_.value != self.c: - self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) - self.sys.exit(1) - if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): - self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}. Got {}.\n".format(MSEC(200) * self.c, elapsed_time)) - self.sys.exit(3) - self.c += 1 - =} + reaction(in_) {= + elapsed_time = lf.time.logical_elapsed() + print("At time {}, received {}.".format(elapsed_time, in_.value)) + if in_.value != self.c: + self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) + self.sys.exit(1) + if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): + self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}. Got {}.\n".format(MSEC(200) * self.c, elapsed_time)) + self.sys.exit(3) + self.c += 1 + =} - reaction(shutdown) {= - if (self.c != 1): - self.sys.stderr.write("ERROR: Expected to receive 1 item. Received {}.\n".format(self.c)) - self.sys.exit(2) - print("SUCCESS: Successfully received 1 item."); - =} + reaction(shutdown) {= + if (self.c != 1): + self.sys.stderr.write("ERROR: Expected to receive 1 item. Received {}.\n".format(self.c)) + self.sys.exit(2) + print("SUCCESS: Successfully received 1 item."); + =} } federated reactor at localhost { - c = new Count() - p = new Print() - c.out ~> p.in_ after 400 msec # Indicating a 'physical' connection. + c = new Count() + p = new Print() + c.out ~> p.in_ after 400 msec # Indicating a 'physical' connection. } diff --git a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf index 0008479138..49041a5c7a 100644 --- a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,55 +1,55 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages only over connections that are - * marked 'physical' (using the ~> arrow). Therefore, no additional coordination - * of the advancement of time (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages only over connections that are marked 'physical' (using the ~> + * arrow). Therefore, no additional coordination of the advancement of time (HLA or Ptides) is + * needed. * * @author Edward A. Lee * @author Soroush Bateni */ target Python { - timeout: 1 sec, - coordination: decentralized + timeout: 1 sec, + coordination: decentralized } reactor Count { - timer t(200 msec, 1 sec) - state s = 0 - output out + timer t(200 msec, 1 sec) + state s = 0 + output out - reaction(t) -> out {= - out.set(self.s) - self.s += 1 - =} + reaction(t) -> out {= + out.set(self.s) + self.s += 1 + =} } reactor Print { - preamble {= import sys =} - input in_ - state c = 0 + preamble {= import sys =} + input in_ + state c = 0 - reaction(in_) {= - elapsed_time = lf.time.logical_elapsed() - print("At time {}, received {}.".format(elapsed_time, in_.value)) - if in_.value != self.c: - self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) - self.sys.exit(1) - if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): - self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}.\n".format(MSEC(200) * self.c)) - self.sys.exit(3) - self.c += 1 - =} + reaction(in_) {= + elapsed_time = lf.time.logical_elapsed() + print("At time {}, received {}.".format(elapsed_time, in_.value)) + if in_.value != self.c: + self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) + self.sys.exit(1) + if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): + self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}.\n".format(MSEC(200) * self.c)) + self.sys.exit(3) + self.c += 1 + =} - reaction(shutdown) {= - if self.c != 1: - self.sys.stderr.write("ERROR: Expected to receive 1 item. Received {}.\n".format(self.c)) - self.sys.exit(2) - print("SUCCESS: Successfully received 1 item.") - =} + reaction(shutdown) {= + if self.c != 1: + self.sys.stderr.write("ERROR: Expected to receive 1 item. Received {}.\n".format(self.c)) + self.sys.exit(2) + print("SUCCESS: Successfully received 1 item.") + =} } federated reactor at localhost { - c = new Count() - p = new Print() - c.out ~> p.in_ # Indicating a 'physical' connection. + c = new Count() + p = new Print() + c.out ~> p.in_ # Indicating a 'physical' connection. } diff --git a/test/Python/src/federated/DistributedDoublePort.lf b/test/Python/src/federated/DistributedDoublePort.lf index 9eb24209e6..3e0d25c4a0 100644 --- a/test/Python/src/federated/DistributedDoublePort.lf +++ b/test/Python/src/federated/DistributedDoublePort.lf @@ -1,54 +1,51 @@ /** - * Test the case for when two upstream federates send messages to a downstream - * federte on two different ports. One message should carry a microstep delay - * relative to the other message. + * Test the case for when two upstream federates send messages to a downstream federte on two + * different ports. One message should carry a microstep delay relative to the other message. * * @author Soroush Bateni */ target Python { - timeout: 900 msec, - logging: DEBUG, - coordination: centralized + timeout: 900 msec, + logging: DEBUG, + coordination: centralized } import Count from "../lib/Count.lf" reactor CountMicrostep { - state count = 1 - output out - logical action act - timer t(0, 1 sec) + state count = 1 + output out + logical action act + timer t(0, 1 sec) - reaction(t) -> act {= - act.schedule(0, self.count) - self.count += 1 - =} + reaction(t) -> act {= + act.schedule(0, self.count) + self.count += 1 + =} - reaction(act) -> out {= out.set(act.value) =} + reaction(act) -> out {= out.set(act.value) =} } reactor Print { - preamble {= import sys =} - input in_ - input in2 - - reaction(in_, in2) {= - current_tag = lf.tag() - print("At tag ({}, {}), received in_ = {} and in2 = {}.".format(current_tag.time, current_tag.microstep, in_.value, in2.value)) - if in_.is_present and in2.is_present: - self.sys.stderr.write("ERROR: invalid logical simultaneity.") - self.sys.exit(1) - =} - - reaction(shutdown) {= - print("SUCCESS: messages were at least one microstep apart.") - =} + preamble {= import sys =} + input in_ + input in2 + + reaction(in_, in2) {= + current_tag = lf.tag() + print("At tag ({}, {}), received in_ = {} and in2 = {}.".format(current_tag.time, current_tag.microstep, in_.value, in2.value)) + if in_.is_present and in2.is_present: + self.sys.stderr.write("ERROR: invalid logical simultaneity.") + self.sys.exit(1) + =} + + reaction(shutdown) {= print("SUCCESS: messages were at least one microstep apart.") =} } federated reactor DistributedDoublePort { - c = new Count() - cm = new CountMicrostep() - p = new Print() - c.out -> p.in_ # Indicating a 'logical' connection. - cm.out -> p.in2 + c = new Count() + cm = new CountMicrostep() + p = new Print() + c.out -> p.in_ # Indicating a 'logical' connection. + cm.out -> p.in2 } diff --git a/test/Python/src/federated/DistributedLoopedAction.lf b/test/Python/src/federated/DistributedLoopedAction.lf index 8f71d15363..c278f04922 100644 --- a/test/Python/src/federated/DistributedLoopedAction.lf +++ b/test/Python/src/federated/DistributedLoopedAction.lf @@ -1,63 +1,61 @@ /** - * Test a sender-receiver network system that relies on microsteps being taken - * into account. + * Test a sender-receiver network system that relies on microsteps being taken into account. * * @author Soroush Bateni */ target Python { - timeout: 1 sec + timeout: 1 sec } import Sender from "../lib/LoopedActionSender.lf" reactor Receiver(take_a_break_after = 10, break_interval = 400 msec) { - preamble {= import sys =} - input in_ - state received_messages = 0 - state total_received_messages = 0 - state breaks = 0 - timer t(0, 1 msec) # This will impact the performance - - # but forces the logical time to advance Comment this line for a more - # sensible log output. - reaction(in_) {= - print("At tag ({}, {}) received value {}.".format( - lf.time.logical_elapsed(), - lf.tag().microstep, - in_.value - ) + preamble {= import sys =} + input in_ + state received_messages = 0 + state total_received_messages = 0 + state breaks = 0 + timer t(0, 1 msec) # This will impact the performance + + # but forces the logical time to advance Comment this line for a more sensible log output. + reaction(in_) {= + print("At tag ({}, {}) received value {}.".format( + lf.time.logical_elapsed(), + lf.tag().microstep, + in_.value ) - self.total_received_messages += 1 - if in_.value != self.received_messages: - self.sys.stderr.write("ERROR: received messages out of order.\n") - # exit(1); - self.received_messages += 1 - if lf.time.logical_elapsed() != self.breaks * self.break_interval: - self.sys.stderr.write("ERROR: received messages at an incorrect time: {}.\n".format(lf.time.logical_elapsed())) - # exit(2); - - if self.received_messages == self.take_a_break_after: - # Sender is taking a break; - self.breaks += 1 - self.received_messages = 0 - =} - - reaction(t) {= - # Do nothing - =} - - reaction(shutdown) {= - print(((SEC(1)/self.break_interval)+1) * self.take_a_break_after) - if self.breaks != 3 or (self.total_received_messages != ((SEC(1)//self.break_interval)+1) * self.take_a_break_after): - self.sys.stderr.write("ERROR: test failed.\n") - exit(4) - print("SUCCESS: Successfully received all messages from the sender.") - =} + ) + self.total_received_messages += 1 + if in_.value != self.received_messages: + self.sys.stderr.write("ERROR: received messages out of order.\n") + # exit(1); + self.received_messages += 1 + if lf.time.logical_elapsed() != self.breaks * self.break_interval: + self.sys.stderr.write("ERROR: received messages at an incorrect time: {}.\n".format(lf.time.logical_elapsed())) + # exit(2); + + if self.received_messages == self.take_a_break_after: + # Sender is taking a break; + self.breaks += 1 + self.received_messages = 0 + =} + + reaction(t) {= + # Do nothing + =} + + reaction(shutdown) {= + print(((SEC(1)/self.break_interval)+1) * self.take_a_break_after) + if self.breaks != 3 or (self.total_received_messages != ((SEC(1)//self.break_interval)+1) * self.take_a_break_after): + self.sys.stderr.write("ERROR: test failed.\n") + exit(4) + print("SUCCESS: Successfully received all messages from the sender.") + =} } federated reactor DistributedLoopedAction { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in_ + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf index d992e3d841..fa72e4c264 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf @@ -1,84 +1,83 @@ /** - * Test a sender-receiver network system that is similar to - * DistributedLoopedAction, but it uses a physical action rather than a logical - * action. This also demonstrates the advance-message-interval coordination - * option. This specifies the time period between Time Advance Notice (TAN) - * messages sent to the RTI (a form of null message that must be sent because of - * the physical action). The presence of this option also silences a warning - * about having a physical action that triggers an output. + * Test a sender-receiver network system that is similar to DistributedLoopedAction, but it uses a + * physical action rather than a logical action. This also demonstrates the advance-message-interval + * coordination option. This specifies the time period between Time Advance Notice (TAN) messages + * sent to the RTI (a form of null message that must be sent because of the physical action). The + * presence of this option also silences a warning about having a physical action that triggers an + * output. * * @author Soroush Bateni */ target Python { - timeout: 1 sec, - keepalive: true + timeout: 1 sec, + keepalive: true } reactor Sender(take_a_break_after = 10, break_interval = 550 msec) { - output out - physical action act - state sent_messages = 0 + output out + physical action act + state sent_messages = 0 - reaction(startup, act) -> act, out {= - # Send a message on out - out.set(self.sent_messages) - self.sent_messages += 1 - if self.sent_messages < self.take_a_break_after: - act.schedule(0) - else: - # Take a break - self.sent_messages = 0 - act.schedule(self.break_interval) - =} + reaction(startup, act) -> act, out {= + # Send a message on out + out.set(self.sent_messages) + self.sent_messages += 1 + if self.sent_messages < self.take_a_break_after: + act.schedule(0) + else: + # Take a break + self.sent_messages = 0 + act.schedule(self.break_interval) + =} } reactor Receiver(take_a_break_after = 10, break_interval = 550 msec) { - preamble {= import sys =} - input in_ - state received_messages = 0 - state total_received_messages = 0 - state breaks = 0 - timer t(0, 1 msec) # This will impact the performance - # but forces the logical time to advance Comment this line for a more - # sensible log output. - state base_logical_time + preamble {= import sys =} + input in_ + state received_messages = 0 + state total_received_messages = 0 + state breaks = 0 + # This will impact the performance + timer t(0, 1 msec) + # but forces the logical time to advance Comment this line for a more sensible log output. + state base_logical_time - reaction(startup) {= self.base_logical_time = lf.time.logical() =} + reaction(startup) {= self.base_logical_time = lf.time.logical() =} - reaction(in_) {= - current_tag = lf.tag() - print("At tag ({}, {}) received {}".format( - current_tag.time - self.base_logical_time, - current_tag.microstep, - in_.value) - ) - self.total_received_messages += 1 - if in_.value != self.received_messages: - self.sys.stderr.write("Expected {}.".format(self.received_messages - 1)) - self.sys.exit(1) - self.received_messages += 1 + reaction(in_) {= + current_tag = lf.tag() + print("At tag ({}, {}) received {}".format( + current_tag.time - self.base_logical_time, + current_tag.microstep, + in_.value) + ) + self.total_received_messages += 1 + if in_.value != self.received_messages: + self.sys.stderr.write("Expected {}.".format(self.received_messages - 1)) + self.sys.exit(1) + self.received_messages += 1 - if self.received_messages == self.take_a_break_after: - # Sender is taking a break; - self.breaks += 1 - self.received_messages = 0 - =} + if self.received_messages == self.take_a_break_after: + # Sender is taking a break; + self.breaks += 1 + self.received_messages = 0 + =} - reaction(t) {= - # Do nothing - =} + reaction(t) {= + # Do nothing + =} - reaction(shutdown) {= - if self.breaks != 2 or (self.total_received_messages != ((SEC(1)//self.break_interval)+1) * self.take_a_break_after): - self.sys.stderr.write("Test failed. Breaks: {}, Messages: {}.".format(self.breaks, self.total_received_messages)) - self.sys.exit(1) - print("SUCCESS: Successfully received all messages from the sender.") - =} + reaction(shutdown) {= + if self.breaks != 2 or (self.total_received_messages != ((SEC(1)//self.break_interval)+1) * self.take_a_break_after): + self.sys.stderr.write("Test failed. Breaks: {}, Messages: {}.".format(self.breaks, self.total_received_messages)) + self.sys.exit(1) + print("SUCCESS: Successfully received all messages from the sender.") + =} } federated reactor DistributedLoopedPhysicalAction { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in_ + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/DistributedMultiport.lf b/test/Python/src/federated/DistributedMultiport.lf index 7250f838ef..bd1f24820d 100644 --- a/test/Python/src/federated/DistributedMultiport.lf +++ b/test/Python/src/federated/DistributedMultiport.lf @@ -1,45 +1,45 @@ # Check multiport connections between federates. target Python { - timeout: 1 sec, - coordination: centralized + timeout: 1 sec, + coordination: centralized } reactor Source { - output[4] out - timer t(0, 100 msec) - state count = 0 + output[4] out + timer t(0, 100 msec) + state count = 0 - reaction(t) -> out {= - for i in range(len(out)): - out[i].set(self.count) - self.count += 1 - =} + reaction(t) -> out {= + for i in range(len(out)): + out[i].set(self.count) + self.count += 1 + =} } reactor Destination { - preamble {= import sys =} - input[4] in_ - state count = 0 + preamble {= import sys =} + input[4] in_ + state count = 0 - reaction(in_) {= - for i in range(len(in_)): - if in_[i].is_present: - print("Received {}.".format(in_[i].value)) - if in_[i].value != self.count: - self.sys.stderr.write("Expected {}.\n".format(self.count)) - self.sys.exit(1) - self.count += 1 - =} + reaction(in_) {= + for i in range(len(in_)): + if in_[i].is_present: + print("Received {}.".format(in_[i].value)) + if in_[i].value != self.count: + self.sys.stderr.write("Expected {}.\n".format(self.count)) + self.sys.exit(1) + self.count += 1 + =} - reaction(shutdown) {= - if self.count == 0: - self.sys.stderr.write("No data received.") - self.sys.exit(1) - =} + reaction(shutdown) {= + if self.count == 0: + self.sys.stderr.write("No data received.") + self.sys.exit(1) + =} } federated reactor DistributedMultiport { - s = new Source() - d = new Destination() - s.out -> d.in_ + s = new Source() + d = new Destination() + s.out -> d.in_ } diff --git a/test/Python/src/federated/DistributedMultiportToBank.lf b/test/Python/src/federated/DistributedMultiportToBank.lf index 69c87b7f0c..b9b65686ef 100644 --- a/test/Python/src/federated/DistributedMultiportToBank.lf +++ b/test/Python/src/federated/DistributedMultiportToBank.lf @@ -1,42 +1,42 @@ # Check multiport to bank connections between federates. target Python { - timeout: 1 sec + timeout: 1 sec } reactor Source { - output[2] out - timer t(0, 100 msec) - state count = 0 + output[2] out + timer t(0, 100 msec) + state count = 0 - reaction(t) -> out {= - for i in range(len(out)): - out[i].set(self.count) - self.count += 1 - =} + reaction(t) -> out {= + for i in range(len(out)): + out[i].set(self.count) + self.count += 1 + =} } reactor Destination { - preamble {= import sys =} - input in_ - state count = 0 + preamble {= import sys =} + input in_ + state count = 0 - reaction(in_) {= - print("Received {}.".format(in_.value)) - if self.count != in_.value: - self.sys.stderr.write("Expected {}.\n".format(self.count)) - self.sys.exit(1) - self.count += 1 - =} + reaction(in_) {= + print("Received {}.".format(in_.value)) + if self.count != in_.value: + self.sys.stderr.write("Expected {}.\n".format(self.count)) + self.sys.exit(1) + self.count += 1 + =} - reaction(shutdown) {= - if self.count == 0: - self.sys.stderr.write("No data received.") - self.sys.exit(1) - =} + reaction(shutdown) {= + if self.count == 0: + self.sys.stderr.write("No data received.") + self.sys.exit(1) + =} } federated reactor DistributedMultiportToBank { - s = new Source() - d = new[2] Destination() - s.out -> d.in_ + s = new Source() + d = new[2] Destination() + s.out -> d.in_ } diff --git a/test/Python/src/federated/DistributedMultiportToken.lf b/test/Python/src/federated/DistributedMultiportToken.lf index 284e1c21a3..bd380f22fe 100644 --- a/test/Python/src/federated/DistributedMultiportToken.lf +++ b/test/Python/src/federated/DistributedMultiportToken.lf @@ -1,39 +1,39 @@ -# Check multiport connections between federates where the message is carried by -# a Token (in this case, with an array of char). +# Check multiport connections between federates where the message is carried by a Token (in this +# case, with an array of char). target Python { - timeout: 1 sec, - coordination: centralized + timeout: 1 sec, + coordination: centralized } reactor Source { - output[4] out - timer t(0, 200 msec) - state count = 0 + output[4] out + timer t(0, 200 msec) + state count = 0 - reaction(t) -> out {= - for i in range(len(out)): - self.count += 1 - out[i].set("Hello {}".format(self.count)) - print("MessageGenerator: At time {}, send message: {}.".format( - lf.time.logical_elapsed(), - out[i].value - ) + reaction(t) -> out {= + for i in range(len(out)): + self.count += 1 + out[i].set("Hello {}".format(self.count)) + print("MessageGenerator: At time {}, send message: {}.".format( + lf.time.logical_elapsed(), + out[i].value ) - =} + ) + =} } reactor Destination { - input[4] in_ + input[4] in_ - reaction(in_) {= - for i in range(len(in_)): - if in_[i].is_present: - print("Received {}.".format(in_[i].value)) - =} + reaction(in_) {= + for i in range(len(in_)): + if in_[i].is_present: + print("Received {}.".format(in_[i].value)) + =} } federated reactor DistributedMultiportToken { - s = new Source() - d = new Destination() - s.out -> d.in_ + s = new Source() + d = new Destination() + s.out -> d.in_ } diff --git a/test/Python/src/federated/DistributedSendClass.lf b/test/Python/src/federated/DistributedSendClass.lf index fd056bb0c0..f607d156e3 100644 --- a/test/Python/src/federated/DistributedSendClass.lf +++ b/test/Python/src/federated/DistributedSendClass.lf @@ -1,25 +1,25 @@ target Python preamble {= - class C: - def __init__(self): - pass + class C: + def __init__(self): + pass =} reactor A { - input o + input o - reaction(o) {= lf_request_stop() =} + reaction(o) {= lf_request_stop() =} } reactor B { - output o + output o - reaction(startup) -> o {= o.set(C()) =} + reaction(startup) -> o {= o.set(C()) =} } federated reactor { - a = new A() - b = new B() - b.o -> a.o + a = new A() + b = new B() + b.o -> a.o } diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 06dfe96c36..76bbe16d46 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -1,6 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with centralized - * coordination. + * Test for lf_request_stop() in federated execution with centralized coordination. * * @author Soroush Bateni */ @@ -9,107 +8,107 @@ target Python preamble {= import sys =} reactor Sender { - output out - timer t(0, 1 usec) - logical action act - state reaction_invoked_correctly = False + output out + timer t(0, 1 usec) + logical action act + state reaction_invoked_correctly = False - reaction(t, act) -> out, act {= - tag = lf.tag() - print("Sending 42 at ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - out.set(42) - if lf.tag().microstep == 0: - # Instead of having a separate reaction - # for 'act' like Stop.lf, we trigger the - # same reaction to test lf_request_stop() being - # called multiple times - act.schedule(0) - if tag.time == USEC(1): - # Call lf_request_stop() both at (1 usec, 0) and - # (1 usec, 1) - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - lf_request_stop() + reaction(t, act) -> out, act {= + tag = lf.tag() + print("Sending 42 at ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + out.set(42) + if lf.tag().microstep == 0: + # Instead of having a separate reaction + # for 'act' like Stop.lf, we trigger the + # same reaction to test lf_request_stop() being + # called multiple times + act.schedule(0) + if tag.time == USEC(1): + # Call lf_request_stop() both at (1 usec, 0) and + # (1 usec, 1) + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + lf_request_stop() - _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) - if lf.tag_compare(lf.tag(), _1usec1) == 0: - # The reaction was invoked at (1 usec, 1) as expected - self.reaction_invoked_correctly = True - elif lf.tag_compare(lf.tag(), _1usec1) > 0: - # The reaction should not have been invoked at tags larger than (1 usec, 1) - sys.stderr.write("ERROR: Invoked reaction(t, act) at tag bigger than shutdown.\n") - sys.exit(1) - =} + _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) + if lf.tag_compare(lf.tag(), _1usec1) == 0: + # The reaction was invoked at (1 usec, 1) as expected + self.reaction_invoked_correctly = True + elif lf.tag_compare(lf.tag(), _1usec1) > 0: + # The reaction should not have been invoked at tags larger than (1 usec, 1) + sys.stderr.write("ERROR: Invoked reaction(t, act) at tag bigger than shutdown.\n") + sys.exit(1) + =} - reaction(shutdown) {= - if lf.time.logical_elapsed() != USEC(1) or lf.tag().microstep != 1: - sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - sys.exit(1) - elif not self.reaction_invoked_correctly: - sys.stderr.write("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - =} + reaction(shutdown) {= + if lf.time.logical_elapsed() != USEC(1) or lf.tag().microstep != 1: + sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + sys.exit(1) + elif not self.reaction_invoked_correctly: + sys.stderr.write("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + =} } reactor Receiver( - stp_offset = 10 msec # Used in the decentralized variant of the test + stp_offset = 10 msec # Used in the decentralized variant of the test ) { - input in_ - state reaction_invoked_correctly = False + input in_ + state reaction_invoked_correctly = False - reaction(in_) {= - tag = lf.tag() - print("Received {} at ({}, {}).".format( - in_.value, - lf.time.logical_elapsed(), - lf.tag().microstep)) - if lf.time.logical_elapsed() == USEC(1): - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - lf_request_stop() - # The receiver should receive a message at tag - # (1 usec, 1) and trigger this reaction - self.reaction_invoked_correctly = True + reaction(in_) {= + tag = lf.tag() + print("Received {} at ({}, {}).".format( + in_.value, + lf.time.logical_elapsed(), + lf.tag().microstep)) + if lf.time.logical_elapsed() == USEC(1): + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + lf_request_stop() + # The receiver should receive a message at tag + # (1 usec, 1) and trigger this reaction + self.reaction_invoked_correctly = True - _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) - if lf.tag_compare(lf.tag(), _1usec1) > 0: - self.reaction_invoked_correctly = False - =} + _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) + if lf.tag_compare(lf.tag(), _1usec1) > 0: + self.reaction_invoked_correctly = False + =} - reaction(shutdown) {= - # Sender should have requested stop earlier than the receiver. - # Therefore, the shutdown events must occur at (1000, 0) on the - # receiver. - if lf.time.logical_elapsed() != USEC(1) or lf.tag().microstep != 1: - sys.stderr.write("Error: Receiver failed to stop the federation at the right time. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - sys.exit(1) - elif not self.reaction_invoked_correctly: - sys.stderr.write("Error: Receiver reaction(in) was not invoked the correct number of times. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - =} + reaction(shutdown) {= + # Sender should have requested stop earlier than the receiver. + # Therefore, the shutdown events must occur at (1000, 0) on the + # receiver. + if lf.time.logical_elapsed() != USEC(1) or lf.tag().microstep != 1: + sys.stderr.write("Error: Receiver failed to stop the federation at the right time. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + sys.exit(1) + elif not self.reaction_invoked_correctly: + sys.stderr.write("Error: Receiver reaction(in) was not invoked the correct number of times. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + =} } federated reactor DistributedStop { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in_ + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/DistributedStopDecentralized.lf b/test/Python/src/federated/DistributedStopDecentralized.lf index d76154f487..42d3182985 100644 --- a/test/Python/src/federated/DistributedStopDecentralized.lf +++ b/test/Python/src/federated/DistributedStopDecentralized.lf @@ -1,11 +1,9 @@ /** - * Test for lf_request_stop() in federated execution with decentralized - * coordination. + * Test for lf_request_stop() in federated execution with decentralized coordination. * * @author Soroush Bateni */ -# reason for failing: lf_tag().microstep and lf.tag_compare() are not not -# supported in python target +# reason for failing: lf_tag().microstep and lf.tag_compare() are not not supported in python target target Python { coordination: decentralized } diff --git a/test/Python/src/federated/DistributedStopZero.lf b/test/Python/src/federated/DistributedStopZero.lf index 089a839105..2f1c348e4d 100644 --- a/test/Python/src/federated/DistributedStopZero.lf +++ b/test/Python/src/federated/DistributedStopZero.lf @@ -1,90 +1,88 @@ /** - * Test for lf_request_stop() in federated execution with centralized - * coordination at tag (0,0). + * Test for lf_request_stop() in federated execution with centralized coordination at tag (0,0). * * @author Soroush Bateni */ -# reason for failing: lf_tag().microstep and lf.tag_compare() are not not -# supported in python target +# reason for failing: lf_tag().microstep and lf.tag_compare() are not not supported in python target target Python preamble {= import sys =} reactor Sender { - output out - timer t(0, 1 usec) - state startup_logical_time + output out + timer t(0, 1 usec) + state startup_logical_time - reaction(startup) {= self.startup_logical_time = lf.time.logical() =} + reaction(startup) {= self.startup_logical_time = lf.time.logical() =} - reaction(t) -> out {= - tag = lf.tag() - print("Sending 42 at ({}, {}).".format( - tag.time, - tag.microstep)) - out.set(42) - zero = Tag(time=self.startup_logical_time, microstep=0) - if lf.tag_compare(lf.tag(), zero) == 0: - # Request stop at (0,0) - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - lf.tag().microstep)) - lf_request_stop() - =} + reaction(t) -> out {= + tag = lf.tag() + print("Sending 42 at ({}, {}).".format( + tag.time, + tag.microstep)) + out.set(42) + zero = Tag(time=self.startup_logical_time, microstep=0) + if lf.tag_compare(lf.tag(), zero) == 0: + # Request stop at (0,0) + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + lf.tag().microstep)) + lf_request_stop() + =} - reaction(shutdown) {= - tag = lf.tag() - if tag.time != USEC(0) or tag.microstep != 1: - sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( - tag.time, - tag.microstep)) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( - tag.time, - tag.microstep)) - =} + reaction(shutdown) {= + tag = lf.tag() + if tag.time != USEC(0) or tag.microstep != 1: + sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( + tag.time, + tag.microstep)) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( + tag.time, + tag.microstep)) + =} } reactor Receiver { - input in_ - state startup_logical_time + input in_ + state startup_logical_time - reaction(startup) {= self.startup_logical_time = lf.time.logical() =} + reaction(startup) {= self.startup_logical_time = lf.time.logical() =} - reaction(in_) {= - tag = lf.tag() - print("Received {} at ({}, {}).\n".format( - in_.value, - tag.time, - tag.microstep)) - zero = Tag(time=self.startup_logical_time, microstep=0) - if lf.tag_compare(lf.tag(), zero) == 0: - # Request stop at (0,0) - print("Requesting stop at ({}, {}).".format( - tag.time, - tag.microstep)) - lf_request_stop() - =} + reaction(in_) {= + tag = lf.tag() + print("Received {} at ({}, {}).\n".format( + in_.value, + tag.time, + tag.microstep)) + zero = Tag(time=self.startup_logical_time, microstep=0) + if lf.tag_compare(lf.tag(), zero) == 0: + # Request stop at (0,0) + print("Requesting stop at ({}, {}).".format( + tag.time, + tag.microstep)) + lf_request_stop() + =} - reaction(shutdown) {= - # Sender should have requested stop earlier than the receiver. - # Therefore, the shutdown events must occur at (1000, 0) on the - # receiver. - tag = lf.tag() - if tag.time != USEC(0) or tag.microstep != 1: - sys.stderr.write("ERROR: Receiver failed to stop the federation in time. Stopping at ({}, {}).\n".format( - tag.time, - tag.microstep)) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).\n".format( - tag.time, - tag.microstep)) - =} + reaction(shutdown) {= + # Sender should have requested stop earlier than the receiver. + # Therefore, the shutdown events must occur at (1000, 0) on the + # receiver. + tag = lf.tag() + if tag.time != USEC(0) or tag.microstep != 1: + sys.stderr.write("ERROR: Receiver failed to stop the federation in time. Stopping at ({}, {}).\n".format( + tag.time, + tag.microstep)) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).\n".format( + tag.time, + tag.microstep)) + =} } federated reactor { - sender = new Sender() - receiver = new Receiver() + sender = new Sender() + receiver = new Receiver() - sender.out -> receiver.in_ + sender.out -> receiver.in_ } diff --git a/test/Python/src/federated/HelloDistributed.lf b/test/Python/src/federated/HelloDistributed.lf index ef99c3f793..fdcdc0e91c 100644 --- a/test/Python/src/federated/HelloDistributed.lf +++ b/test/Python/src/federated/HelloDistributed.lf @@ -1,49 +1,47 @@ /** - * Test a particularly simple form of a distributed deterministic system where a - * federation that receives timestamped messages has only those messages as - * triggers. Therefore, no additional coordination of the advancement of time - * (HLA or Ptides) is needed. + * Test a particularly simple form of a distributed deterministic system where a federation that + * receives timestamped messages has only those messages as triggers. Therefore, no additional + * coordination of the advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ target Python reactor Source { - output out + output out - reaction(startup) -> out {= - print("Sending 'Hello World!' message from source federate."); - out.set("Hello World!") - lf_request_stop() - =} + reaction(startup) -> out {= + print("Sending 'Hello World!' message from source federate."); + out.set("Hello World!") + lf_request_stop() + =} } reactor Destination { - input _in - state received = False + input _in + state received = False - reaction(startup) {= print("Destination started.") =} + reaction(startup) {= print("Destination started.") =} - reaction(_in) {= - print(f"At logical time {lf.time.logical_elapsed()}, destination received {_in.value}") - if _in.value != "Hello World!": - sys.stderr.write("ERROR: Expected to receive 'Hello World!'\n"); - exit(1) - self.received = True - =} + reaction(_in) {= + print(f"At logical time {lf.time.logical_elapsed()}, destination received {_in.value}") + if _in.value != "Hello World!": + sys.stderr.write("ERROR: Expected to receive 'Hello World!'\n"); + exit(1) + self.received = True + =} - reaction(shutdown) {= - print("Shutdown invoked.") - if self.received is not True: - sys.stderr.write("ERROR: Destination did not receive the message.") - exit(1) - =} + reaction(shutdown) {= + print("Shutdown invoked.") + if self.received is not True: + sys.stderr.write("ERROR: Destination did not receive the message.") + exit(1) + =} } federated reactor HelloDistributed at localhost { - # reaction(startup) {= print("Printing something in top-level federated - # reactor.") - # =} Reactor s is in federate Source - s = new Source() - d = new Destination() # Reactor d is in federate Destination - s.out -> d._in # This version preserves the timestamp. + # reaction(startup) {= print("Printing something in top-level federated reactor.") + # =} Reactor s is in federate Source + s = new Source() + d = new Destination() # Reactor d is in federate Destination + s.out -> d._in # This version preserves the timestamp. } diff --git a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 2719fd57ba..732311e6d2 100644 --- a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,67 +1,66 @@ /** - * This tests that the precedence order of reaction invocation is kept in the - * hierarchy of reactors when a feedback loop is present in centralized - * coordination. + * This tests that the precedence order of reaction invocation is kept in the hierarchy of reactors + * when a feedback loop is present in centralized coordination. * * @author Edward A. Lee * @author Soroush Bateni */ target Python { - coordination: centralized, - coordination-options: { - advance-message-interval: 100 msec - }, - timeout: 5 sec + coordination: centralized, + coordination-options: { + advance-message-interval: 100 msec + }, + timeout: 5 sec } reactor Contained(incr = 1) { - timer t(0, 1 sec) - input inp - state count = 0 - state received_count = 0 + timer t(0, 1 sec) + input inp + state count = 0 + state received_count = 0 - reaction(t) {= self.count += self.incr =} + reaction(t) {= self.count += self.incr =} - reaction(inp) {= self.received_count = self.count =} + reaction(inp) {= self.received_count = self.count =} - reaction(t) {= - if self.received_count != self.count: - self.sys.stderr.write("reaction(t) was invoked before reaction(in). Precedence order was not kept.") - self.sys.exit(1) - =} + reaction(t) {= + if self.received_count != self.count: + self.sys.stderr.write("reaction(t) was invoked before reaction(in). Precedence order was not kept.") + self.sys.exit(1) + =} } reactor Looper(incr = 1, delay = 0 msec) { - input inp - output out - state count = 0 - timer t(0, 1 sec) + input inp + output out + state count = 0 + timer t(0, 1 sec) - c = new Contained(incr = incr) - inp -> c.inp + c = new Contained(incr = incr) + inp -> c.inp - reaction(t) -> out {= - print(f"Sending network output {self.count}") - out.set(self.count) - self.count += self.incr - =} + reaction(t) -> out {= + print(f"Sending network output {self.count}") + out.set(self.count) + self.count += self.incr + =} - reaction(inp) {= - time_lag = lf.time.physical() - lf.time.logical() - print(f"Received {inp.value}. Logical time is behind physical time by {time_lag:,} nsec.") - =} + reaction(inp) {= + time_lag = lf.time.physical() - lf.time.logical() + print(f"Received {inp.value}. Logical time is behind physical time by {time_lag:,} nsec.") + =} - reaction(shutdown) {= - print("******* Shutdown invoked.") - if self.count != 6 * self.incr: - self.sys.stderr.write("Failed to receive all six expected inputs.") - self.sys.exit(1) - =} + reaction(shutdown) {= + print("******* Shutdown invoked.") + if self.count != 6 * self.incr: + self.sys.stderr.write("Failed to receive all six expected inputs.") + self.sys.exit(1) + =} } federated reactor(delay = 0) { - left = new Looper() - right = new Looper(incr = -1) - left.out -> right.inp - right.out -> left.inp + left = new Looper() + right = new Looper(incr = -1) + left.out -> right.inp + right.out -> left.inp } diff --git a/test/Python/src/federated/PhysicalSTP.lf b/test/Python/src/federated/PhysicalSTP.lf index 5edc61df34..a51319c6b3 100644 --- a/test/Python/src/federated/PhysicalSTP.lf +++ b/test/Python/src/federated/PhysicalSTP.lf @@ -1,50 +1,47 @@ -/** - * This is a test that detects STP violations according to the physical time of - * message arrival. - */ +/** This is a test that detects STP violations according to the physical time of message arrival. */ target Python { - timeout: 1900 msec, - coordination: decentralized + timeout: 1900 msec, + coordination: decentralized } import Count from "../lib/Count.lf" reactor Print(STP_offset = 0) { - preamble {= import sys =} - input in_ - state c = 1 + preamble {= import sys =} + input in_ + state c = 1 - reaction(in_) {= - elapsed_time = lf.time.logical_elapsed() - print("At time {}, received {}".format(elapsed_time, in_.value)) - print(f"Physical time of arrival: {in_.physical_time_of_arrival}") - if in_.value != self.c: - self.sys.stderr.write("Expected to receive {}.\n".format(self.c)) - self.sys.exit(1) - STP_discrepency = lf.time.logical() + self.STP_offset - in_.physical_time_of_arrival - if STP_discrepency < 0: - print("The message has violated the STP offset by {} in physical time.".format(-1 * STP_discrepency)) - self.c += 1 - else: - self.sys.stderr.write("Message arrived {} early.\n".format(STP_discrepency)) - self.sys.exit(1) - =} STP(STP_offset) {= - # This STP handler should never be invoked because the only source of event - # for Print is the Count reactor. - self.sys.stderr.write("Logical STP violation was detected. Only physical STP violations are possible.\n") + reaction(in_) {= + elapsed_time = lf.time.logical_elapsed() + print("At time {}, received {}".format(elapsed_time, in_.value)) + print(f"Physical time of arrival: {in_.physical_time_of_arrival}") + if in_.value != self.c: + self.sys.stderr.write("Expected to receive {}.\n".format(self.c)) self.sys.exit(1) - =} + STP_discrepency = lf.time.logical() + self.STP_offset - in_.physical_time_of_arrival + if STP_discrepency < 0: + print("The message has violated the STP offset by {} in physical time.".format(-1 * STP_discrepency)) + self.c += 1 + else: + self.sys.stderr.write("Message arrived {} early.\n".format(STP_discrepency)) + self.sys.exit(1) + =} STP(STP_offset) {= + # This STP handler should never be invoked because the only source of event + # for Print is the Count reactor. + self.sys.stderr.write("Logical STP violation was detected. Only physical STP violations are possible.\n") + self.sys.exit(1) + =} - reaction(shutdown) {= - if self.c != 3: - self.sys.stderr.write("Expected to receive 2 items but got {}.\n".format(self.c)) - self.sys.exit(1) - =} + reaction(shutdown) {= + if self.c != 3: + self.sys.stderr.write("Expected to receive 2 items but got {}.\n".format(self.c)) + self.sys.exit(1) + =} } federated reactor { - c = new Count(offset = 1 msec, period = 1 sec) - p = new Print(STP_offset = 1 usec) + c = new Count(offset = 1 msec, period = 1 sec) + p = new Print(STP_offset = 1 usec) - c.out -> p.in_ + c.out -> p.in_ } diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index 0f58cbf7db..41a76a9a7e 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -1,72 +1,70 @@ /** - * Basic benchmark from the Savina benchmark suite that is intended to measure - * message-passing overhead. This is based on - * https://www.scala-lang.org/old/node/54 See + * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing + * overhead. This is based on https://www.scala-lang.org/old/node/54 See * https://shamsimam.github.io/papers/2014-agere-savina.pdf. * - * This is a distributed version, where Ping and Pong run in separate programs - * and can be run on different machines. + * This is a distributed version, where Ping and Pong run in separate programs and can be run on + * different machines. * * To get a sense, some (informal) results for 1,000,000 ping-pongs on my Mac: * * Unthreaded: 97 msec Threaded: 265 msec Distributed: 53 seconds * - * There is no parallelism in this application, so it does not benefit from - * being being distributed. + * There is no parallelism in this application, so it does not benefit from being being distributed. * - * These measurements are total execution time, including startup and shutdown, - * of all three programs. + * These measurements are total execution time, including startup and shutdown, of all three + * programs. * * @author Edward A. Lee */ target Python reactor Ping(count = 10) { - input receive - output send - state pingsLeft = count - logical action serve + input receive + output send + state pingsLeft = count + logical action serve - reaction(startup, serve) -> send {= - print("At logical time {}, Ping sending {}.\n".format(lf.time.logical_elapsed(), self.pingsLeft)) - send.set(self.pingsLeft) - self.pingsLeft -= 1 - =} + reaction(startup, serve) -> send {= + print("At logical time {}, Ping sending {}.\n".format(lf.time.logical_elapsed(), self.pingsLeft)) + send.set(self.pingsLeft) + self.pingsLeft -= 1 + =} - reaction(receive) -> serve {= - if self.pingsLeft > 0: - serve.schedule(0) - else: - lf_request_stop() - =} + reaction(receive) -> serve {= + if self.pingsLeft > 0: + serve.schedule(0) + else: + lf_request_stop() + =} } reactor Pong(expected = 10) { - preamble {= import sys =} + preamble {= import sys =} - input receive - output send - state count = 0 + input receive + output send + state count = 0 - reaction(receive) -> send {= - self.count += 1 - print("At logical time {}, Pong received {}.\n".format(lf.time.logical_elapsed(), receive.value)) - send.set(receive.value) - if self.count == self.expected: - lf_request_stop() - =} + reaction(receive) -> send {= + self.count += 1 + print("At logical time {}, Pong received {}.\n".format(lf.time.logical_elapsed(), receive.value)) + send.set(receive.value) + if self.count == self.expected: + lf_request_stop() + =} - reaction(shutdown) {= - if self.count != self.expected: - print("Pong expected to receive {} inputs, but it received {}.\n".format(self.expected, self.count), file=self.sys.stderr) - self.sys.exit(1) - print("Pong received {} pings.\n".format(self.count)) - =} + reaction(shutdown) {= + if self.count != self.expected: + print("Pong expected to receive {} inputs, but it received {}.\n".format(self.expected, self.count), file=self.sys.stderr) + self.sys.exit(1) + print("Pong received {} pings.\n".format(self.count)) + =} } federated reactor(count = 10) { - ping = new Ping(count = count) - pong = new Pong(expected = count) - ping.send ~> pong.receive - pong.send ~> ping.receive + ping = new Ping(count = count) + pong = new Pong(expected = count) + ping.send ~> pong.receive + pong.send ~> ping.receive } diff --git a/test/Python/src/federated/StopAtShutdown.lf b/test/Python/src/federated/StopAtShutdown.lf index 3179c44592..958ee269ca 100644 --- a/test/Python/src/federated/StopAtShutdown.lf +++ b/test/Python/src/federated/StopAtShutdown.lf @@ -6,30 +6,30 @@ * @author Steven Wong */ target Python { - timeout: 2 sec + timeout: 2 sec } reactor A { - input in_ + input in_ - reaction(startup) {= print("Hello World!") =} + reaction(startup) {= print("Hello World!") =} - reaction(in_) {= print("Got it") =} + reaction(in_) {= print("Got it") =} - reaction(shutdown) {= lf_request_stop() =} + reaction(shutdown) {= lf_request_stop() =} } reactor B { - output out - timer t(1 sec) + output out + timer t(1 sec) - reaction(t) -> out {= out.set(1) =} + reaction(t) -> out {= out.set(1) =} - reaction(shutdown) {= lf_request_stop() =} + reaction(shutdown) {= lf_request_stop() =} } federated reactor { - a = new A() - b = new B() - b.out -> a.in_ + a = new A() + b = new B() + b.out -> a.in_ } diff --git a/test/Python/src/lib/Count.lf b/test/Python/src/lib/Count.lf index 26b53ce13b..2f86fabf60 100644 --- a/test/Python/src/lib/Count.lf +++ b/test/Python/src/lib/Count.lf @@ -1,12 +1,12 @@ target Python reactor Count(offset = 0, period = 1 sec) { - state count = 1 - output out - timer t(offset, period) + state count = 1 + output out + timer t(offset, period) - reaction(t) -> out {= - out.set(self.count) - self.count += 1 - =} + reaction(t) -> out {= + out.set(self.count) + self.count += 1 + =} } diff --git a/test/Python/src/lib/InternalDelay.lf b/test/Python/src/lib/InternalDelay.lf index a9796aa8d9..964ec6b5a3 100644 --- a/test/Python/src/lib/InternalDelay.lf +++ b/test/Python/src/lib/InternalDelay.lf @@ -1,11 +1,11 @@ target Python reactor InternalDelay(delay = 10 msec) { - input in_ - output out - logical action d + input in_ + output out + logical action d - reaction(in_) -> d {= d.schedule(self.delay, in_.value) =} + reaction(in_) -> d {= d.schedule(self.delay, in_.value) =} - reaction(d) -> out {= out.set(d.value) =} + reaction(d) -> out {= out.set(d.value) =} } diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index 9d4048d0ea..e3b7dfa961 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -6,25 +6,24 @@ target Python /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after = 10, break_interval = 400 msec) { - output out - logical action act - state sent_messages = 0 + output out + logical action act + state sent_messages = 0 - reaction(startup, act) -> act, out {= - # Send a message on out - out.set(self.sent_messages) - self.sent_messages += 1 - if self.sent_messages < self.take_a_break_after: - act.schedule(0) - else: - # Take a break - self.sent_messages=0; - act.schedule(self.break_interval) - =} + reaction(startup, act) -> act, out {= + # Send a message on out + out.set(self.sent_messages) + self.sent_messages += 1 + if self.sent_messages < self.take_a_break_after: + act.schedule(0) + else: + # Take a break + self.sent_messages=0; + act.schedule(self.break_interval) + =} } diff --git a/test/Python/src/lib/Test.lf b/test/Python/src/lib/Test.lf index 301ed9c8e6..6cbc45bfcb 100644 --- a/test/Python/src/lib/Test.lf +++ b/test/Python/src/lib/Test.lf @@ -1,14 +1,14 @@ target Python reactor TestDouble(expected(1.0, 1.0, 1.0, 1.0)) { - input t_in - state count = 0 + input t_in + state count = 0 - reaction(t_in) {= - print("Received: ", t_in.value) - if t_in.value != self.expected[self.count]: - sys.stderr.write("ERROR: Expected {:f}.\n".format(self.expected[self.count])) - exit(1) - self.count += 1 - =} + reaction(t_in) {= + print("Received: ", t_in.value) + if t_in.value != self.expected[self.count]: + sys.stderr.write("ERROR: Expected {:f}.\n".format(self.expected[self.count])) + exit(1) + self.count += 1 + =} } diff --git a/test/Python/src/lib/TestCount.lf b/test/Python/src/lib/TestCount.lf index de611cbc69..a079ff2e37 100644 --- a/test/Python/src/lib/TestCount.lf +++ b/test/Python/src/lib/TestCount.lf @@ -1,7 +1,6 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. @@ -10,24 +9,24 @@ target Python reactor TestCount(start = 1, stride = 1, num_inputs = 1) { - preamble {= import sys =} - state count = start - state inputs_received = 0 - input in_ + preamble {= import sys =} + state count = start + state inputs_received = 0 + input in_ - reaction(in_) {= - print("Received {}.".format(in_.value)) - if in_.value != self.count: - print("Expected {}.".format(self.count)) - self.sys.exit(1) - self.count += self.stride; - self.inputs_received += 1; - =} + reaction(in_) {= + print("Received {}.".format(in_.value)) + if in_.value != self.count: + print("Expected {}.".format(self.count)) + self.sys.exit(1) + self.count += self.stride; + self.inputs_received += 1; + =} - reaction(shutdown) {= - print("Shutdown invoked.") - if self.inputs_received != self.num_inputs: - print("Expected to receive {} inputs, but got {}.".format(self.num_inputs, self.inputs_received)) - self.sys.exit(1) - =} + reaction(shutdown) {= + print("Shutdown invoked.") + if self.inputs_received != self.num_inputs: + print("Expected to receive {} inputs, but got {}.".format(self.num_inputs, self.inputs_received)) + self.sys.exit(1) + =} } diff --git a/test/Python/src/lib/TestCountMultiport.lf b/test/Python/src/lib/TestCountMultiport.lf index c30572e4d5..d5b0a635cd 100644 --- a/test/Python/src/lib/TestCountMultiport.lf +++ b/test/Python/src/lib/TestCountMultiport.lf @@ -1,42 +1,41 @@ /** - * Test that a counting sequence of inputs starts with the specified start - * parameter value, increments by the specified stride, and receives the - * specified number of inputs. This version has a multiport input, and each - * input is expected to be present and incremented over the previous input. + * Test that a counting sequence of inputs starts with the specified start parameter value, + * increments by the specified stride, and receives the specified number of inputs. This version has + * a multiport input, and each input is expected to be present and incremented over the previous + * input. * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. - * @param num_inputs The number of inputs expected on each channel. Default is - * 1. + * @param num_inputs The number of inputs expected on each channel. Default is 1. */ target Python reactor TestCountMultiport(start = 1, stride = 1, num_inputs = 1, width = 2) { - preamble {= import sys =} - state count = start - state inputs_received = 0 - input[width] inp + preamble {= import sys =} + state count = start + state inputs_received = 0 + input[width] inp - reaction(inp) {= - for i in range(in_width): - if not inp[i].is_present: - print("No input on channel {}.".format(i)) - self.sys.exit(1) - print("Received {} on channel {}.".format(inp[i].value, i)) - if inp[i].value != self.count: - print("Expected {}.".format(self.count)) - self.sys.exit(1) - self.count += self.stride - self.inputs_received += 1 - =} - - reaction(shutdown) {= - print("Shutdown invoked.") - if self.inputs_received != self.num_inputs: - print("Expected to receive {} inputs, but only got {}.".format( - self.num_inputs, - self.inputs_received - )) + reaction(inp) {= + for i in range(in_width): + if not inp[i].is_present: + print("No input on channel {}.".format(i)) + self.sys.exit(1) + print("Received {} on channel {}.".format(inp[i].value, i)) + if inp[i].value != self.count: + print("Expected {}.".format(self.count)) self.sys.exit(1) - =} + self.count += self.stride + self.inputs_received += 1 + =} + + reaction(shutdown) {= + print("Shutdown invoked.") + if self.inputs_received != self.num_inputs: + print("Expected to receive {} inputs, but only got {}.".format( + self.num_inputs, + self.inputs_received + )) + self.sys.exit(1) + =} } diff --git a/test/Python/src/modal_models/BanksCount3ModesComplex.lf b/test/Python/src/modal_models/BanksCount3ModesComplex.lf index 59b41ef75f..97447dc0b5 100644 --- a/test/Python/src/modal_models/BanksCount3ModesComplex.lf +++ b/test/Python/src/modal_models/BanksCount3ModesComplex.lf @@ -1,78 +1,74 @@ -/** - * Modal Reactor Test. Tests cycling through modes with banks of reactors and - * complex nesting. - */ +/** Modal Reactor Test. Tests cycling through modes with banks of reactors and complex nesting. */ target Python { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } import TraceTesting from "util/TraceTesting.lf" import CounterCycle from "Count3Modes.lf" reactor MetaCounter { - input next - output[2] always - output[2] mode1 - output[2] mode2 - output[2] never + input next + output[2] always + output[2] mode1 + output[2] mode2 + output[2] never - outer_counters = new[2] CounterCycle() - (next)+ -> outer_counters.next - outer_counters.count -> always + outer_counters = new[2] CounterCycle() + (next)+ -> outer_counters.next + outer_counters.count -> always - initial mode One { - mode1_counters = new[2] CounterCycle() + initial mode One { + mode1_counters = new[2] CounterCycle() - (next)+ -> mode1_counters.next - mode1_counters.count -> mode1 + (next)+ -> mode1_counters.next + mode1_counters.count -> mode1 - timer t1(500 msec, 250 msec) - reaction(t1) -> reset(Two) {= Two.set() =} - } + timer t1(500 msec, 250 msec) + reaction(t1) -> reset(Two) {= Two.set() =} + } - mode Two { - mode2_counters = new[2] CounterCycle() + mode Two { + mode2_counters = new[2] CounterCycle() - (next)+ -> mode2_counters.next - mode2_counters.count -> mode2 + (next)+ -> mode2_counters.next + mode2_counters.count -> mode2 - timer t2(500 msec, 250 msec) - reaction(t2) -> history(One) {= One.set() =} - } + timer t2(500 msec, 250 msec) + reaction(t2) -> history(One) {= One.set() =} + } - mode Three { - mode3_counters = new[2] CounterCycle() + mode Three { + mode3_counters = new[2] CounterCycle() - (next)+ -> mode3_counters.next - mode3_counters.count -> never - } + (next)+ -> mode3_counters.next + mode3_counters.count -> never + } } main reactor { - timer stepper(0, 250 msec) - counters = new[2] MetaCounter() - test = new TraceTesting(events_size = 16, trace = ( // keep-format - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,0,3,0,3,0,3,0,3,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,0,1,0,1,0,1,0,1,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, - 250000000,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, - 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, - 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0 - ), training = False) + timer stepper(0, 250 msec) + counters = new[2] MetaCounter() + test = new TraceTesting(events_size = 16, trace = ( // keep-format + 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,0,3,0,3,0,3,0,3,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,0,1,0,1,0,1,0,1,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,2,0,2,0,2,0,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 250000000,1,2,1,2,1,2,1,2,0,2,0,2,0,2,0,2,1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0, + 250000000,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,0,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0, + 250000000,1,1,1,1,1,1,1,1,0,3,0,3,0,3,0,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0 + ), training = False) - counters.always, counters.mode1, counters.mode2, counters.never - -> test.events + counters.always, counters.mode1, counters.mode2, counters.never -> test.events - reaction(stepper) -> counters.next {= # Trigger - for i in range(len(counters)): - counters[i].next.set(True) - =} + reaction(stepper) -> counters.next {= # Trigger + for i in range(len(counters)): + counters[i].next.set(True) + =} } diff --git a/test/Python/src/modal_models/BanksModalStateReset.lf b/test/Python/src/modal_models/BanksModalStateReset.lf index f96a7bd638..65080b5da9 100644 --- a/test/Python/src/modal_models/BanksModalStateReset.lf +++ b/test/Python/src/modal_models/BanksModalStateReset.lf @@ -1,10 +1,7 @@ -/** - * Modal Reactor Test. Tests reset of state variables in modes with banks of - * reactors. - */ +/** Modal Reactor Test. Tests reset of state variables in modes with banks of reactors. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" @@ -12,50 +9,49 @@ import Modal as ResetReaction from "ModalStateReset.lf" import Modal as AutoReset from "ModalStateResetAuto.lf" main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - reset1 = new[2] ResetReaction() - reset2 = new[2] AutoReset() - test = new TraceTesting(events_size = 16, trace = ( // keep-format - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,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,1,-2,1,-2, - 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, 0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, - 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, 0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, - 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, 0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, - 250000000,1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2, 1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2 - ), training = False) + reset1 = new[2] ResetReaction() + reset2 = new[2] AutoReset() + test = new TraceTesting(events_size = 16, trace = ( // keep-format + 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, + 250000000,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, + 250000000,0,0,0,0,0,0,0,0,1,2,1,2,0,0,0,0, 0,0,0,0,0,0,0,0,1,2,1,2,0,0,0,0, + 250000000,0,0,0,0,0,0,0,0,1,3,1,3,0,0,0,0, 0,0,0,0,0,0,0,0,1,3,1,3,0,0,0,0, + 250000000,1,1,1,1,1,0,1,0,1,4,1,4,0,0,0,0, 1,1,1,1,1,0,1,0,1,4,1,4,0,0,0,0, + 0,0,1,0,1,0,0,0,0,0,4,0,4,1,-2,1,-2, 0,1,0,1,0,0,0,0,0,4,0,4,1,-2,1,-2, + 250000000,0,1,0,1,0,0,0,0,0,4,0,4,1,-1,1,-1, 0,1,0,1,0,0,0,0,0,4,0,4,1,-1,1,-1, + 250000000,0,1,0,1,0,0,0,0,0,4,0,4,1,0,1,0, 0,1,0,1,0,0,0,0,0,4,0,4,1,0,1,0, + 250000000,0,1,0,1,0,0,0,0,0,4,0,4,1,1,1,1, 0,1,0,1,0,0,0,0,0,4,0,4,1,1,1,1, + 250000000,1,1,1,1,1,1,1,1,0,4,0,4,1,2,1,2, 1,1,1,1,1,1,1,1,0,4,0,4,1,2,1,2, + 250000000,0,1,0,1,0,1,0,1,1,5,1,5,0,2,0,2, 0,1,0,1,0,1,0,1,1,5,1,5,0,2,0,2, + 250000000,0,1,0,1,0,1,0,1,1,6,1,6,0,2,0,2, 0,1,0,1,0,1,0,1,1,6,1,6,0,2,0,2, + 250000000,0,1,0,1,0,1,0,1,1,7,1,7,0,2,0,2, 0,1,0,1,0,1,0,1,1,7,1,7,0,2,0,2, + 250000000,1,1,1,1,1,2,1,2,1,8,1,8,0,2,0,2, 1,1,1,1,1,2,1,2,1,8,1,8,0,2,0,2, + 0,0,1,0,1,0,2,0,2,0,8,0,8,1,-2,1,-2, 0,1,0,1,0,2,0,2,0,8,0,8,1,-2,1,-2, + 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, 0,1,0,1,0,2,0,2,0,8,0,8,1,-1,1,-1, + 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, 0,1,0,1,0,2,0,2,0,8,0,8,1,0,1,0, + 250000000,0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, 0,1,0,1,0,2,0,2,0,8,0,8,1,1,1,1, + 250000000,1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2, 1,1,1,1,1,3,1,3,0,8,0,8,1,2,1,2 + ), training = False) - reset1.mode_switch, - reset1.count0, - reset1.count1, - reset1.count2, - reset2.mode_switch, - reset2.count0, - reset2.count1, - reset2.count2 - -> test.events + reset1.mode_switch, + reset1.count0, + reset1.count1, + reset1.count2, + reset2.mode_switch, + reset2.count0, + reset2.count1, + reset2.count2 + -> test.events - # Trigger mode change (separately because of #1278) - reaction(stepper) -> reset1.next {= - for i in range(len(reset1)): - reset1[i].next.set(True) - =} + reaction(stepper) -> reset1.next {= # Trigger mode change (separately because of #1278) + for i in range(len(reset1)): + reset1[i].next.set(True) + =} - reaction(stepper) -> reset2.next {= - for i in range(len(reset2)): - reset2[i].next.set(True) - =} + reaction(stepper) -> reset2.next {= + for i in range(len(reset2)): + reset2[i].next.set(True) + =} } diff --git a/test/Python/src/modal_models/ConvertCaseTest.lf b/test/Python/src/modal_models/ConvertCaseTest.lf index f3bdee59fe..85e6c6f5e9 100644 --- a/test/Python/src/modal_models/ConvertCaseTest.lf +++ b/test/Python/src/modal_models/ConvertCaseTest.lf @@ -1,123 +1,118 @@ /** Modal Reactor Test. Tests nested reactors with modes. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor ResetProcessor { - input discard - input character - output converted - - initial mode Converting { - converter = new Converter() - character -> converter.raw - converter.converted -> converted - reaction(discard) -> reset(Discarding) {= Discarding.set() =} - } - - mode Discarding { - reaction(character) -> converted {= converted.set('_') =} - - reaction(character) -> reset(Converting) {= Converting.set() =} - } + input discard + input character + output converted + + initial mode Converting { + converter = new Converter() + character -> converter.raw + converter.converted -> converted + reaction(discard) -> reset(Discarding) {= Discarding.set() =} + } + + mode Discarding { + reaction(character) -> converted {= converted.set('_') =} + + reaction(character) -> reset(Converting) {= Converting.set() =} + } } reactor HistoryProcessor { - input discard - input character - output converted - - initial mode Converting { - converter = new Converter() - character -> converter.raw - converter.converted -> converted - reaction(discard) -> reset(Discarding) {= Discarding.set() =} - } - - mode Discarding { - reaction(character) -> converted {= converted.set('_') =} - - reaction(character) -> history(Converting) {= Converting.set() =} - } + input discard + input character + output converted + + initial mode Converting { + converter = new Converter() + character -> converter.raw + converter.converted -> converted + reaction(discard) -> reset(Discarding) {= Discarding.set() =} + } + + mode Discarding { + reaction(character) -> converted {= converted.set('_') =} + + reaction(character) -> history(Converting) {= Converting.set() =} + } } reactor Converter { - input raw - output converted - - initial mode Upper { - reaction(raw) -> converted, reset(Lower) {= - character = raw.value.upper() - converted.set(character) - if character == ' ': - Lower.set() - =} - } - - mode Lower { - reaction(raw) -> converted, reset(Upper) {= - character = raw.value.lower() - converted.set(character) - if character == ' ': - Upper.set() - =} - } + input raw + output converted + + initial mode Upper { + reaction(raw) -> converted, reset(Lower) {= + character = raw.value.upper() + converted.set(character) + if character == ' ': + Lower.set() + =} + } + + mode Lower { + reaction(raw) -> converted, reset(Upper) {= + character = raw.value.lower() + converted.set(character) + if character == ' ': + Upper.set() + =} + } } reactor InputFeeder(message = "") { - output character - state idx = 0 + output character + state idx = 0 - timer t(0, 250 msec) + timer t(0, 250 msec) - reaction(t) -> character {= - if self.idx < len(self.message): - character.set(self.message[self.idx]) - self.idx += 1 - =} + reaction(t) -> character {= + if self.idx < len(self.message): + character.set(self.message[self.idx]) + self.idx += 1 + =} } main reactor { - timer stepper(500 msec, 1 sec) - - feeder = new InputFeeder(message = "Hello World!") - reset_processor = new ResetProcessor() - history_processor = new HistoryProcessor() - - feeder.character -> reset_processor.character - feeder.character -> history_processor.character - - test = new TraceTesting(events_size = 2, trace = ( // keep-format - 0, True, 'H', True, 'H', - 250000000, True, 'E', True, 'E', - 250000000, True, 'L', True, 'L', - 250000000, True, '_', True, '_', - 250000000, True, 'O', True, 'O', - 250000000, True, ' ', True, ' ', - 250000000, True, 'w', True, 'w', - 250000000, True, '_', True, '_', - 250000000, True, 'R', True, 'r', - 250000000, True, 'L', True, 'l', - 250000000, True, 'D', True, 'd', - 250000000, True, '_', True, '_' - ), training = False) - - reset_processor.converted, history_processor.converted -> test.events - - # Trigger mode change - reaction(stepper) -> reset_processor.discard, history_processor.discard {= - reset_processor.discard.set(True) - history_processor.discard.set(True) - =} - - reaction(reset_processor.converted) {= - print(f"Reset: {reset_processor.converted.value}") - =} - - reaction(history_processor.converted) {= - print(f"History: {history_processor.converted.value}") - =} + timer stepper(500 msec, 1 sec) + + feeder = new InputFeeder(message = "Hello World!") + reset_processor = new ResetProcessor() + history_processor = new HistoryProcessor() + + feeder.character -> reset_processor.character + feeder.character -> history_processor.character + + test = new TraceTesting(events_size = 2, trace = ( // keep-format + 0, True, 'H', True, 'H', + 250000000, True, 'E', True, 'E', + 250000000, True, 'L', True, 'L', + 250000000, True, '_', True, '_', + 250000000, True, 'O', True, 'O', + 250000000, True, ' ', True, ' ', + 250000000, True, 'w', True, 'w', + 250000000, True, '_', True, '_', + 250000000, True, 'R', True, 'r', + 250000000, True, 'L', True, 'l', + 250000000, True, 'D', True, 'd', + 250000000, True, '_', True, '_' + ), training = False) + + reset_processor.converted, history_processor.converted -> test.events + + reaction(stepper) -> reset_processor.discard, history_processor.discard {= # Trigger mode change + reset_processor.discard.set(True) + history_processor.discard.set(True) + =} + + reaction(reset_processor.converted) {= print(f"Reset: {reset_processor.converted.value}") =} + + reaction(history_processor.converted) {= print(f"History: {history_processor.converted.value}") =} } diff --git a/test/Python/src/modal_models/Count3Modes.lf b/test/Python/src/modal_models/Count3Modes.lf index 7e2e9d98e2..77fb09d1c0 100644 --- a/test/Python/src/modal_models/Count3Modes.lf +++ b/test/Python/src/modal_models/Count3Modes.lf @@ -1,56 +1,56 @@ /** Modal Reactor Test. Tests cycling through modes. */ target Python { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } reactor CounterCycle { - input next - output count - - initial mode One { - reaction(next) -> count, reset(Two) {= - count.set(1) - Two.set() - =} - } - - mode Two { - reaction(next) -> count, reset(Three) {= - count.set(2) - Three.set() - =} - } - - mode Three { - reaction(next) -> count, reset(One) {= - count.set(3) - One.set() - =} - } + input next + output count + + initial mode One { + reaction(next) -> count, reset(Two) {= + count.set(1) + Two.set() + =} + } + + mode Two { + reaction(next) -> count, reset(Three) {= + count.set(2) + Three.set() + =} + } + + mode Three { + reaction(next) -> count, reset(One) {= + count.set(3) + One.set() + =} + } } main reactor { - timer stepper(0, 250 msec) - counter = new CounterCycle() + timer stepper(0, 250 msec) + counter = new CounterCycle() - state expected_value = 1 + state expected_value = 1 - reaction(stepper) -> counter.next {= counter.next.set(True) =} # Trigger + reaction(stepper) -> counter.next {= counter.next.set(True) =} # Trigger - reaction(stepper) counter.count {= # Check - print(f"{counter.count.value}") + reaction(stepper) counter.count {= # Check + print(f"{counter.count.value}") - if counter.count.is_present is not True: - sys.stderr.write("ERROR: Missing mode change.\n") - exit(1) - elif counter.count.value != self.expected_value: - sys.stderr.write("ERROR: Wrong mode.\n") - exit(2) + if counter.count.is_present is not True: + sys.stderr.write("ERROR: Missing mode change.\n") + exit(1) + elif counter.count.value != self.expected_value: + sys.stderr.write("ERROR: Wrong mode.\n") + exit(2) - if self.expected_value == 3: - self.expected_value = 1 - else: - self.expected_value += 1 - =} + if self.expected_value == 3: + self.expected_value = 1 + else: + self.expected_value += 1 + =} } diff --git a/test/Python/src/modal_models/ModalActions.lf b/test/Python/src/modal_models/ModalActions.lf index b74f92f3c9..fd4adf8eb8 100644 --- a/test/Python/src/modal_models/ModalActions.lf +++ b/test/Python/src/modal_models/ModalActions.lf @@ -1,95 +1,94 @@ /** - * Modal Reactor Test. Tests actions, their suspension during mode inactivity - * and continuation of delays with history transitions. + * Modal Reactor Test. Tests actions, their suspension during mode inactivity and continuation of + * delays with history transitions. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next + input next - output mode_switch - output action1_sched - output action1_exec - output action2_sched - output action2_exec + output mode_switch + output action1_sched + output action1_exec + output action2_sched + output action2_exec - initial mode One { - timer T1(0, 750 msec) - logical action delay1(500 msec) - reaction(T1) -> delay1, action1_sched {= - print("Scheduled Action") - delay1.schedule(0) - action1_sched.set(1) - =} + initial mode One { + timer T1(0, 750 msec) + logical action delay1(500 msec) + reaction(T1) -> delay1, action1_sched {= + print("Scheduled Action") + delay1.schedule(0) + action1_sched.set(1) + =} - reaction(delay1) -> action1_exec {= - print("Executed Action") - action1_exec.set(1) - =} + reaction(delay1) -> action1_exec {= + print("Executed Action") + action1_exec.set(1) + =} - reaction(next) -> reset(Two), mode_switch {= - print("Transitioning to mode Two (reset)") - mode_switch.set(1) - Two.set() - =} - } + reaction(next) -> reset(Two), mode_switch {= + print("Transitioning to mode Two (reset)") + mode_switch.set(1) + Two.set() + =} + } - mode Two { - timer T2(0, 750 msec) - logical action delay2(500 msec) - reaction(T2) -> delay2, action2_sched {= - print("Scheduled Action2") - delay2.schedule(0) - action2_sched.set(1) - =} + mode Two { + timer T2(0, 750 msec) + logical action delay2(500 msec) + reaction(T2) -> delay2, action2_sched {= + print("Scheduled Action2") + delay2.schedule(0) + action2_sched.set(1) + =} - reaction(delay2) -> action2_exec {= - print("Executed Action2") - action2_exec.set(1) - =} + reaction(delay2) -> action2_exec {= + print("Executed Action2") + action2_exec.set(1) + =} - reaction(next) -> history(One), mode_switch {= - print("Transitioning to mode One (continue)") - mode_switch.set(1) - One.set() - =} - } + reaction(next) -> history(One), mode_switch {= + print("Transitioning to mode One (continue)") + mode_switch.set(1) + One.set() + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting(events_size = 5, trace = ( // keep-format - 0,0,0,1,1,0,0,0,0,0,0, - 500000000,0,0,0,1,1,1,0,0,0,0, - 250000000,0,0,1,1,0,1,0,0,0,0, - 250000000,1,1,0,1,0,1,0,0,0,0, - 0,0,1,0,1,0,1,1,1,0,0, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1, - 250000000,0,1,0,1,1,1,0,1,0,1, - 250000000,0,1,1,1,0,1,0,1,0,1, - 500000000,1,1,0,1,1,1,0,1,0,1, - 0,0,1,0,1,0,1,1,1,0,1, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 5, trace = ( // keep-format + 0,0,0,1,1,0,0,0,0,0,0, + 500000000,0,0,0,1,1,1,0,0,0,0, + 250000000,0,0,1,1,0,1,0,0,0,0, + 250000000,1,1,0,1,0,1,0,0,0,0, + 0,0,1,0,1,0,1,1,1,0,0, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1, + 250000000,0,1,0,1,1,1,0,1,0,1, + 250000000,0,1,1,1,0,1,0,1,0,1, + 500000000,1,1,0,1,1,1,0,1,0,1, + 0,0,1,0,1,0,1,1,1,0,1, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1 + ), training = False) - modal.mode_switch, - modal.action1_sched, - modal.action1_exec, - modal.action2_sched, - modal.action2_exec - -> test.events + modal.mode_switch, + modal.action1_sched, + modal.action1_exec, + modal.action2_sched, + modal.action2_exec + -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalAfter.lf b/test/Python/src/modal_models/ModalAfter.lf index 19c84f33d5..f6290e9bee 100644 --- a/test/Python/src/modal_models/ModalAfter.lf +++ b/test/Python/src/modal_models/ModalAfter.lf @@ -1,100 +1,95 @@ /** - * Modal Reactor Test. Tests after delays, its suspension during mode inactivity - * and continuation with history transitions. + * Modal Reactor Test. Tests after delays, its suspension during mode inactivity and continuation + * with history transitions. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next + input next - output mode_switch - output produced1 - output consumed1 - output produced2 - output consumed2 + output mode_switch + output produced1 + output consumed1 + output produced2 + output consumed2 - initial mode One { - producer1 = new Producer(mode_id = 1) - consumer1 = new Consumer(mode_id = 1) - producer1.product -> produced1 - producer1.product -> consumer1.product after 500 msec - consumer1.report -> consumed1 - reaction(next) -> reset(Two), mode_switch {= - print("Transitioning to mode Two (reset)") - mode_switch.set(1) - Two.set() - =} - } + initial mode One { + producer1 = new Producer(mode_id = 1) + consumer1 = new Consumer(mode_id = 1) + producer1.product -> produced1 + producer1.product -> consumer1.product after 500 msec + consumer1.report -> consumed1 + reaction(next) -> reset(Two), mode_switch {= + print("Transitioning to mode Two (reset)") + mode_switch.set(1) + Two.set() + =} + } - mode Two { - producer2 = new Producer(mode_id = 2) - consumer2 = new Consumer(mode_id = 2) - producer2.product -> produced2 - producer2.product -> consumer2.product after 500 msec - consumer2.report -> consumed2 - reaction(next) -> history(One), mode_switch {= - print("Transitioning to mode One (continue)") - mode_switch.set(1) - One.set() - =} - } + mode Two { + producer2 = new Producer(mode_id = 2) + consumer2 = new Consumer(mode_id = 2) + producer2.product -> produced2 + producer2.product -> consumer2.product after 500 msec + consumer2.report -> consumed2 + reaction(next) -> history(One), mode_switch {= + print("Transitioning to mode One (continue)") + mode_switch.set(1) + One.set() + =} + } } reactor Producer(mode_id = 0) { - output product + output product - timer t(0, 750 msec) + timer t(0, 750 msec) - reaction(t) -> product {= - print(f"Produced in {self.mode_id}") - product.set(1) - =} + reaction(t) -> product {= + print(f"Produced in {self.mode_id}") + product.set(1) + =} } reactor Consumer(mode_id = 0) { - input product - output report + input product + output report - reaction(product) -> report {= - print("Consumed in {self.mode_id}") - report.set(1) - =} + reaction(product) -> report {= + print("Consumed in {self.mode_id}") + report.set(1) + =} } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting(events_size = 5, trace = ( // keep-format - 0,0,0,1,1,0,0,0,0,0,0, - 500000000,0,0,0,1,1,1,0,0,0,0, - 250000000,0,0,1,1,0,1,0,0,0,0, - 250000000,1,1,0,1,0,1,0,0,0,0, - 0,0,1,0,1,0,1,1,1,0,0, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1, - 250000000,0,1,0,1,1,1,0,1,0,1, - 250000000,0,1,1,1,0,1,0,1,0,1, - 500000000,1,1,0,1,1,1,0,1,0,1, - 0,0,1,0,1,0,1,1,1,0,1, - 500000000,0,1,0,1,0,1,0,1,1,1, - 250000000,0,1,0,1,0,1,1,1,0,1, - 250000000,1,1,0,1,0,1,0,1,0,1 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 5, trace = ( // keep-format + 0,0,0,1,1,0,0,0,0,0,0, + 500000000,0,0,0,1,1,1,0,0,0,0, + 250000000,0,0,1,1,0,1,0,0,0,0, + 250000000,1,1,0,1,0,1,0,0,0,0, + 0,0,1,0,1,0,1,1,1,0,0, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1, + 250000000,0,1,0,1,1,1,0,1,0,1, + 250000000,0,1,1,1,0,1,0,1,0,1, + 500000000,1,1,0,1,1,1,0,1,0,1, + 0,0,1,0,1,0,1,1,1,0,1, + 500000000,0,1,0,1,0,1,0,1,1,1, + 250000000,0,1,0,1,0,1,1,1,0,1, + 250000000,1,1,0,1,0,1,0,1,0,1 + ), training = False) - modal.mode_switch, - modal.produced1, - modal.consumed1, - modal.produced2, - modal.consumed2 - -> test.events + modal.mode_switch, modal.produced1, modal.consumed1, modal.produced2, modal.consumed2 + -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalCycleBreaker.lf b/test/Python/src/modal_models/ModalCycleBreaker.lf index 1ceb2eb5d0..97155b1534 100644 --- a/test/Python/src/modal_models/ModalCycleBreaker.lf +++ b/test/Python/src/modal_models/ModalCycleBreaker.lf @@ -1,75 +1,73 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work - * if they are located in separate modes. + * Tests if connections in the same reactor that have the same destination work if they are located + * in separate modes. */ target Python { - fast: false, - timeout: 1 sec + fast: false, + timeout: 1 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input in1 - input in2 - output out + input in1 + input in2 + output out - # Defining reaction to in2 before in1 would cause cycle if no mode were - # present - mode Two { - timer wait(150 msec, 1 sec) - reaction(in2) {= =} + mode Two { # Defining reaction to in2 before in1 would cause cycle if no mode were present + timer wait(150 msec, 1 sec) + reaction(in2) {= =} - reaction(wait) -> reset(One) {= - One.set() - print("Switching to mode One") - =} - } + reaction(wait) -> reset(One) {= + One.set() + print("Switching to mode One") + =} + } - initial mode One { - reaction(in1) -> out {= out.set(in1.value) =} + initial mode One { + reaction(in1) -> out {= out.set(in1.value) =} - reaction(in1) -> reset(Two) {= - if in1.value % 5 == 4: - Two.set() - print("Switching to mode Two") - =} - } + reaction(in1) -> reset(Two) {= + if in1.value % 5 == 4: + Two.set() + print("Switching to mode Two") + =} + } } reactor Counter(period = 1 sec) { - output value + output value - timer t(0, period) - state curval = 0 + timer t(0, period) + state curval = 0 - reaction(t) -> value {= - value.set(self.curval) - self.curval += 1 - =} + reaction(t) -> value {= + value.set(self.curval) + self.curval += 1 + =} } main reactor { - counter = new Counter(period = 100 msec) - modal = new Modal() - test = new TraceTesting(events_size = 1, trace = ( // keep-format - 0,1,0, - 100000000,1,1, - 100000000,1,2, - 100000000,1,3, - 100000000,1,4, - 200000000,1,6, - 100000000,1,7, - 100000000,1,8, - 100000000,1,9 - ), training = False) + counter = new Counter(period = 100 msec) + modal = new Modal() + test = new TraceTesting(events_size = 1, trace = ( // keep-format + 0,1,0, + 100000000,1,1, + 100000000,1,2, + 100000000,1,3, + 100000000,1,4, + 200000000,1,6, + 100000000,1,7, + 100000000,1,8, + 100000000,1,9 + ), training = False) - counter.value -> modal.in1 - modal.out -> modal.in2 + counter.value -> modal.in1 + modal.out -> modal.in2 - modal.out -> test.events + modal.out -> test.events - reaction(modal.out) {= print(modal.out.value) =} # Print + reaction(modal.out) {= print(modal.out.value) =} # Print } diff --git a/test/Python/src/modal_models/ModalStartupShutdown.lf b/test/Python/src/modal_models/ModalStartupShutdown.lf index c7a868eeca..cd0770ef5f 100644 --- a/test/Python/src/modal_models/ModalStartupShutdown.lf +++ b/test/Python/src/modal_models/ModalStartupShutdown.lf @@ -1,142 +1,141 @@ /** Modal Reactor Test. Test startup/shutdown reactions in modes. */ target Python { - fast: false, - timeout: 3000 msec + fast: false, + timeout: 3000 msec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next - - output mode_switch - output startup1 - output startup2 - output shutdown2 - output shutdown3 - output startup4 - output reset4 - output shutdown4 - output startup5 - output reset5 - output shutdown5 - - initial mode One { - reaction(startup) -> startup1 {= - print(f"Startup 1 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - startup1.set(1) - =} - - reaction(next) -> reset(Two), mode_switch {= - print("Transitioning to mode 2") - mode_switch.set(2) - Two.set() - =} - } - - mode Two { - reaction(startup) -> startup2 {= - print(f"Startup 2 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - startup2.set(1) - =} - - reaction(next) -> reset(Three), mode_switch {= - print("Transitioning to mode 3") - mode_switch.set(3) - Three.set() - =} - - reaction(shutdown) -> shutdown2 {= - print(f"Shutdown 2 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - shutdown2.set(1) - =} - } - - mode Three { - reaction(next) -> reset(Four), mode_switch {= - print("Transitioning to mode 4") - mode_switch.set(4) - Four.set() - =} - - reaction(shutdown) -> shutdown3 {= - print(f"Shutdown 3 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - shutdown3.set(1) - =} - } - - mode Four { - reaction(startup) -> startup4 {= - print(f"Startup 4 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - startup4.set(1) - =} - - reaction(reset) -> reset4 {= - print(f"Reset 4 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - reset4.set(1) - =} - - reaction(next) -> reset(Four), mode_switch {= - print("Transitioning to mode 4") - mode_switch.set(4) - Four.set() - =} - - reaction(shutdown) -> shutdown4 {= - print(f"Shutdown 4 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - shutdown4.set(1) - =} - } - - mode Five { # Unreachable! - reaction(startup) -> startup5 {= - print(f"Startup 5 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - startup5.set(1) - =} - - reaction(reset) -> reset5 {= - print(f"Reset 5 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - reset5.set(1) - =} - - reaction(shutdown) -> shutdown5 {= - print(f"Shutdown 5 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") - shutdown5.set(1) - =} - } + input next + + output mode_switch + output startup1 + output startup2 + output shutdown2 + output shutdown3 + output startup4 + output reset4 + output shutdown4 + output startup5 + output reset5 + output shutdown5 + + initial mode One { + reaction(startup) -> startup1 {= + print(f"Startup 1 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + startup1.set(1) + =} + + reaction(next) -> reset(Two), mode_switch {= + print("Transitioning to mode 2") + mode_switch.set(2) + Two.set() + =} + } + + mode Two { + reaction(startup) -> startup2 {= + print(f"Startup 2 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + startup2.set(1) + =} + + reaction(next) -> reset(Three), mode_switch {= + print("Transitioning to mode 3") + mode_switch.set(3) + Three.set() + =} + + reaction(shutdown) -> shutdown2 {= + print(f"Shutdown 2 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + shutdown2.set(1) + =} + } + + mode Three { + reaction(next) -> reset(Four), mode_switch {= + print("Transitioning to mode 4") + mode_switch.set(4) + Four.set() + =} + + reaction(shutdown) -> shutdown3 {= + print(f"Shutdown 3 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + shutdown3.set(1) + =} + } + + mode Four { + reaction(startup) -> startup4 {= + print(f"Startup 4 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + startup4.set(1) + =} + + reaction(reset) -> reset4 {= + print(f"Reset 4 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + reset4.set(1) + =} + + reaction(next) -> reset(Four), mode_switch {= + print("Transitioning to mode 4") + mode_switch.set(4) + Four.set() + =} + + reaction(shutdown) -> shutdown4 {= + print(f"Shutdown 4 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + shutdown4.set(1) + =} + } + + mode Five { # Unreachable! + reaction(startup) -> startup5 {= + print(f"Startup 5 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + startup5.set(1) + =} + + reaction(reset) -> reset5 {= + print(f"Reset 5 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + reset5.set(1) + =} + + reaction(shutdown) -> shutdown5 {= + print(f"Shutdown 5 at ({lf.time.logical_elapsed()}, {lf.tag().microstep}).") + shutdown5.set(1) + =} + } } main reactor { - timer stepper(500 msec, 500 msec) - - modal = new Modal() - test = new TraceTesting(events_size = 11, trace = ( // keep-format - 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 500000000,1,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,2,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 500000000,1,3,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,4,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, - 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, - 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, - 500000000,1,4,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0 - ), training = False) - - modal.mode_switch, - modal.startup1, - modal.startup2, - modal.shutdown2, - modal.shutdown3, - modal.startup4, - modal.reset4, - modal.shutdown4, - modal.startup5, - modal.reset5, - modal.shutdown5 - -> test.events - - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + timer stepper(500 msec, 500 msec) + + modal = new Modal() + test = new TraceTesting(events_size = 11, trace = ( // keep-format + 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 500000000,1,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,2,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 500000000,1,3,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,4,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, + 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, + 0,0,4,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, + 500000000,1,4,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0 + ), training = False) + + modal.mode_switch, + modal.startup1, + modal.startup2, + modal.shutdown2, + modal.shutdown3, + modal.startup4, + modal.reset4, + modal.shutdown4, + modal.startup5, + modal.reset5, + modal.shutdown5 + -> test.events + + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalStateReset.lf b/test/Python/src/modal_models/ModalStateReset.lf index 11b7425b63..76f94b259b 100644 --- a/test/Python/src/modal_models/ModalStateReset.lf +++ b/test/Python/src/modal_models/ModalStateReset.lf @@ -1,92 +1,91 @@ /** Modal Reactor Test. Tests reset of state variables in modes. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next + input next - output mode_switch - output count0 - output count1 - output count2 + output mode_switch + output count0 + output count1 + output count2 - state counter0 = 0 + state counter0 = 0 - reaction(next) -> count0 {= - print(f"Counter0: {self.counter0}") - count0.set(self.counter0) - self.counter0 += 1 - =} + reaction(next) -> count0 {= + print(f"Counter0: {self.counter0}") + count0.set(self.counter0) + self.counter0 += 1 + =} - initial mode One { - state counter1 = 0 - timer T1(0 msec, 250 msec) - reaction(reset) {= self.counter1 = 0 =} + initial mode One { + state counter1 = 0 + timer T1(0 msec, 250 msec) + reaction(reset) {= self.counter1 = 0 =} - reaction(T1) -> count1 {= - print(f"Counter1: {self.counter1}") - count1.set(self.counter1) - self.counter1 += 1 - =} + reaction(T1) -> count1 {= + print(f"Counter1: {self.counter1}") + count1.set(self.counter1) + self.counter1 += 1 + =} - reaction(next) -> reset(Two), mode_switch {= - print("Transitioning to mode Two (reset)") - mode_switch.set(1) - Two.set() - =} - } + reaction(next) -> reset(Two), mode_switch {= + print("Transitioning to mode Two (reset)") + mode_switch.set(1) + Two.set() + =} + } - mode Two { - state counter2 = -2 - timer T2(0 msec, 250 msec) - reaction(reset) {= self.counter2 = -2 =} + mode Two { + state counter2 = -2 + timer T2(0 msec, 250 msec) + reaction(reset) {= self.counter2 = -2 =} - reaction(T2) -> count2 {= - print(f"Counter2: {self.counter2}") - count2.set(self.counter2) - self.counter2 += 1 - =} + reaction(T2) -> count2 {= + print(f"Counter2: {self.counter2}") + count2.set(self.counter2) + self.counter2 += 1 + =} - reaction(next) -> history(One), mode_switch {= - print("Transitioning to mode One (continue)") - mode_switch.set(1) - One.set() - =} - } + reaction(next) -> history(One), mode_switch {= + print("Transitioning to mode One (continue)") + mode_switch.set(1) + One.set() + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting(events_size = 4, trace = ( // keep-format - 0,0,0,0,0,1,0,0,0, - 250000000,0,0,0,0,1,1,0,0, - 250000000,0,0,0,0,1,2,0,0, - 250000000,0,0,0,0,1,3,0,0, - 250000000,1,1,1,0,1,4,0,0, - 0,0,1,0,0,0,4,1,-2, - 250000000,0,1,0,0,0,4,1,-1, - 250000000,0,1,0,0,0,4,1,0, - 250000000,0,1,0,0,0,4,1,1, - 250000000,1,1,1,1,0,4,1,2, - 250000000,0,1,0,1,1,5,0,2, - 250000000,0,1,0,1,1,6,0,2, - 250000000,0,1,0,1,1,7,0,2, - 250000000,1,1,1,2,1,8,0,2, - 0,0,1,0,2,0,8,1,-2, - 250000000,0,1,0,2,0,8,1,-1, - 250000000,0,1,0,2,0,8,1,0, - 250000000,0,1,0,2,0,8,1,1, - 250000000,1,1,1,3,0,8,1,2 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 4, trace = ( // keep-format + 0,0,0,0,0,1,0,0,0, + 250000000,0,0,0,0,1,1,0,0, + 250000000,0,0,0,0,1,2,0,0, + 250000000,0,0,0,0,1,3,0,0, + 250000000,1,1,1,0,1,4,0,0, + 0,0,1,0,0,0,4,1,-2, + 250000000,0,1,0,0,0,4,1,-1, + 250000000,0,1,0,0,0,4,1,0, + 250000000,0,1,0,0,0,4,1,1, + 250000000,1,1,1,1,0,4,1,2, + 250000000,0,1,0,1,1,5,0,2, + 250000000,0,1,0,1,1,6,0,2, + 250000000,0,1,0,1,1,7,0,2, + 250000000,1,1,1,2,1,8,0,2, + 0,0,1,0,2,0,8,1,-2, + 250000000,0,1,0,2,0,8,1,-1, + 250000000,0,1,0,2,0,8,1,0, + 250000000,0,1,0,2,0,8,1,1, + 250000000,1,1,1,3,0,8,1,2 + ), training = False) - modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events + modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalStateResetAuto.lf b/test/Python/src/modal_models/ModalStateResetAuto.lf index 492e12259b..ab09f7f325 100644 --- a/test/Python/src/modal_models/ModalStateResetAuto.lf +++ b/test/Python/src/modal_models/ModalStateResetAuto.lf @@ -1,88 +1,87 @@ /** Modal Reactor Test. Tests reset of state variables in modes. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next + input next - output mode_switch - output count0 - output count1 - output count2 + output mode_switch + output count0 + output count1 + output count2 - state counter0 = 0 + state counter0 = 0 - reaction(next) -> count0 {= - print(f"Counter0: {self.counter0}") - count0.set(self.counter0) - self.counter0 += 1 - =} + reaction(next) -> count0 {= + print(f"Counter0: {self.counter0}") + count0.set(self.counter0) + self.counter0 += 1 + =} - initial mode One { - state counter1 = 0 - timer T1(0 msec, 250 msec) - reaction(T1) -> count1 {= - print(f"Counter1: {self.counter1}") - count1.set(self.counter1) - self.counter1 += 1 - =} + initial mode One { + state counter1 = 0 + timer T1(0 msec, 250 msec) + reaction(T1) -> count1 {= + print(f"Counter1: {self.counter1}") + count1.set(self.counter1) + self.counter1 += 1 + =} - reaction(next) -> reset(Two), mode_switch {= - print("Transitioning to mode Two (reset)") - mode_switch.set(1) - Two.set() - =} - } + reaction(next) -> reset(Two), mode_switch {= + print("Transitioning to mode Two (reset)") + mode_switch.set(1) + Two.set() + =} + } - mode Two { - reset state counter2 = -2 - timer T2(0 msec, 250 msec) - reaction(T2) -> count2 {= - print(f"Counter2: {self.counter2}") - count2.set(self.counter2) - self.counter2 += 1 - =} + mode Two { + reset state counter2 = -2 + timer T2(0 msec, 250 msec) + reaction(T2) -> count2 {= + print(f"Counter2: {self.counter2}") + count2.set(self.counter2) + self.counter2 += 1 + =} - reaction(next) -> history(One), mode_switch {= - print("Transitioning to mode One (continue)") - mode_switch.set(1) - One.set() - =} - } + reaction(next) -> history(One), mode_switch {= + print("Transitioning to mode One (continue)") + mode_switch.set(1) + One.set() + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting(events_size = 4, trace = ( // keep-format - 0,0,0,0,0,1,0,0,0, - 250000000,0,0,0,0,1,1,0,0, - 250000000,0,0,0,0,1,2,0,0, - 250000000,0,0,0,0,1,3,0,0, - 250000000,1,1,1,0,1,4,0,0, - 0,0,1,0,0,0,4,1,-2, - 250000000,0,1,0,0,0,4,1,-1, - 250000000,0,1,0,0,0,4,1,0, - 250000000,0,1,0,0,0,4,1,1, - 250000000,1,1,1,1,0,4,1,2, - 250000000,0,1,0,1,1,5,0,2, - 250000000,0,1,0,1,1,6,0,2, - 250000000,0,1,0,1,1,7,0,2, - 250000000,1,1,1,2,1,8,0,2, - 0,0,1,0,2,0,8,1,-2, - 250000000,0,1,0,2,0,8,1,-1, - 250000000,0,1,0,2,0,8,1,0, - 250000000,0,1,0,2,0,8,1,1, - 250000000,1,1,1,3,0,8,1,2 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 4, trace = ( // keep-format + 0,0,0,0,0,1,0,0,0, + 250000000,0,0,0,0,1,1,0,0, + 250000000,0,0,0,0,1,2,0,0, + 250000000,0,0,0,0,1,3,0,0, + 250000000,1,1,1,0,1,4,0,0, + 0,0,1,0,0,0,4,1,-2, + 250000000,0,1,0,0,0,4,1,-1, + 250000000,0,1,0,0,0,4,1,0, + 250000000,0,1,0,0,0,4,1,1, + 250000000,1,1,1,1,0,4,1,2, + 250000000,0,1,0,1,1,5,0,2, + 250000000,0,1,0,1,1,6,0,2, + 250000000,0,1,0,1,1,7,0,2, + 250000000,1,1,1,2,1,8,0,2, + 0,0,1,0,2,0,8,1,-2, + 250000000,0,1,0,2,0,8,1,-1, + 250000000,0,1,0,2,0,8,1,0, + 250000000,0,1,0,2,0,8,1,1, + 250000000,1,1,1,3,0,8,1,2 + ), training = False) - modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events + modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/ModalTimers.lf b/test/Python/src/modal_models/ModalTimers.lf index 271a19ec38..9f92a876fb 100644 --- a/test/Python/src/modal_models/ModalTimers.lf +++ b/test/Python/src/modal_models/ModalTimers.lf @@ -1,67 +1,66 @@ /** Modal Reactor Test. Tests timers, their deactivation and reset in modes. */ target Python { - fast: false, - timeout: 4 sec + fast: false, + timeout: 4 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next + input next - output mode_switch - output timer1 - output timer2 + output mode_switch + output timer1 + output timer2 - initial mode One { - timer T1(0, 750 msec) - reaction(T1) -> timer1 {= - print(f"T1: at tag ({lf.time.logical_elapsed()}, {lf.tag().microstep})") - timer1.set(1) - =} + initial mode One { + timer T1(0, 750 msec) + reaction(T1) -> timer1 {= + print(f"T1: at tag ({lf.time.logical_elapsed()}, {lf.tag().microstep})") + timer1.set(1) + =} - reaction(next) -> reset(Two), mode_switch {= - print("Transitioning to mode Two (reset)") - mode_switch.set(1) - Two.set() - =} - } + reaction(next) -> reset(Two), mode_switch {= + print("Transitioning to mode Two (reset)") + mode_switch.set(1) + Two.set() + =} + } - mode Two { - timer T2(0, 750 msec) - reaction(T2) -> timer2 {= - print(f"T2: at tag ({lf.time.logical_elapsed()}, {lf.tag().microstep})") - timer2.set(1) - =} + mode Two { + timer T2(0, 750 msec) + reaction(T2) -> timer2 {= + print(f"T2: at tag ({lf.time.logical_elapsed()}, {lf.tag().microstep})") + timer2.set(1) + =} - reaction(next) -> history(One), mode_switch {= - print("Transitioning to mode One (continue)") - mode_switch.set(1) - One.set() - =} - } + reaction(next) -> history(One), mode_switch {= + print("Transitioning to mode One (continue)") + mode_switch.set(1) + One.set() + =} + } } main reactor { - timer stepper(1 sec, 1 sec) + timer stepper(1 sec, 1 sec) - modal = new Modal() - test = new TraceTesting(events_size = 3, trace = ( // keep-format - 0,0,0,1,1,0,0, - 750000000,0,0,1,1,0,0, - 250000000,1,1,0,1,0,0, - 0,0,1,0,1,1,1, - 750000000,0,1,0,1,1,1, - 250000000,1,1,0,1,0,1, - 500000000,0,1,1,1,0,1, - 500000000,1,1,0,1,0,1, - 0,0,1,0,1,1,1, - 750000000,0,1,0,1,1,1, - 250000000,1,1,0,1,0,1 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 3, trace = ( // keep-format + 0,0,0,1,1,0,0, + 750000000,0,0,1,1,0,0, + 250000000,1,1,0,1,0,0, + 0,0,1,0,1,1,1, + 750000000,0,1,0,1,1,1, + 250000000,1,1,0,1,0,1, + 500000000,0,1,1,1,0,1, + 500000000,1,1,0,1,0,1, + 0,0,1,0,1,1,1, + 750000000,0,1,0,1,1,1, + 250000000,1,1,0,1,0,1 + ), training = False) - modal.mode_switch, modal.timer1, modal.timer2 -> test.events + modal.mode_switch, modal.timer1, modal.timer2 -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change } diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index 3dd42f67ce..9eebec636f 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -1,74 +1,72 @@ /** * Modal Reactor Test. * - * Tests if connections in the same reactor that have the same destination work - * if they are located in separate modes. + * Tests if connections in the same reactor that have the same destination work if they are located + * in separate modes. */ target Python { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next - output count + input next + output count - initial mode One { - counter1 = new Counter(period = 250 msec) - counter1.value -> count - reaction(next) -> reset(Two) {= Two.set() =} - } + initial mode One { + counter1 = new Counter(period = 250 msec) + counter1.value -> count + reaction(next) -> reset(Two) {= Two.set() =} + } - mode Two { - counter2 = new Counter(period = 100 msec) - counter2.value -> count - reaction(next) -> history(One) {= One.set() =} - } + mode Two { + counter2 = new Counter(period = 100 msec) + counter2.value -> count + reaction(next) -> history(One) {= One.set() =} + } } reactor Counter(period = 1 sec) { - output value + output value - timer t(0, period) - reset state curval = 0 + timer t(0, period) + reset state curval = 0 - reaction(t) -> value {= - value.set(self.curval) - self.curval += 1 - =} + reaction(t) -> value {= + value.set(self.curval) + self.curval += 1 + =} } main reactor { - timer stepper(500 msec, 500 msec) + timer stepper(500 msec, 500 msec) - modal = new Modal() - test = new TraceTesting(events_size = 1, trace = ( // keep-format - 0,1,0, - 250000000,1,1, - 250000000,1,2, - 0,1,0, - 100000000,1,1, - 100000000,1,2, - 100000000,1,3, - 100000000,1,4, - 100000000,1,5, - 250000000,1,3, - 250000000,1,4, - 0,1,0, - 100000000,1,1, - 100000000,1,2, - 100000000,1,3, - 100000000,1,4, - 100000000,1,5 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 1, trace = ( // keep-format + 0,1,0, + 250000000,1,1, + 250000000,1,2, + 0,1,0, + 100000000,1,1, + 100000000,1,2, + 100000000,1,3, + 100000000,1,4, + 100000000,1,5, + 250000000,1,3, + 250000000,1,4, + 0,1,0, + 100000000,1,1, + 100000000,1,2, + 100000000,1,3, + 100000000,1,4, + 100000000,1,5 + ), training = False) - modal.count -> test.events + modal.count -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change - # Print - reaction(modal.count) {= print(modal.count.value) =} + reaction(modal.count) {= print(modal.count.value) =} # Print } diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 86f5668357..1b1c0429a1 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -1,77 +1,73 @@ /** * Modal Reactor Test. * - * Tests if a connection and a reaction in the same reactor can have the same - * destination if they are located in separate modes. + * Tests if a connection and a reaction in the same reactor can have the same destination if they + * are located in separate modes. */ target Python { - fast: false, - timeout: 2 sec + fast: false, + timeout: 2 sec } import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next - output count + input next + output count - initial mode One { - counter1 = new Counter(period = 250 msec) - counter1.value -> count - reaction(next) -> reset(Two) {= Two.set() =} - } + initial mode One { + counter1 = new Counter(period = 250 msec) + counter1.value -> count + reaction(next) -> reset(Two) {= Two.set() =} + } - mode Two { - counter2 = new Counter(period = 100 msec) - reaction(counter2.value) -> count {= - count.set(counter2.value.value * 10) - =} + mode Two { + counter2 = new Counter(period = 100 msec) + reaction(counter2.value) -> count {= count.set(counter2.value.value * 10) =} - reaction(next) -> history(One) {= One.set() =} - } + reaction(next) -> history(One) {= One.set() =} + } } reactor Counter(period = 1 sec) { - output value + output value - timer t(0, period) - reset state curval = 0 + timer t(0, period) + reset state curval = 0 - reaction(t) -> value {= - value.set(self.curval) - self.curval += 1 - =} + reaction(t) -> value {= + value.set(self.curval) + self.curval += 1 + =} } main reactor { - timer stepper(500 msec, 500 msec) + timer stepper(500 msec, 500 msec) - modal = new Modal() - test = new TraceTesting(events_size = 1, trace = ( // keep-format - 0,1,0, - 250000000,1,1, - 250000000,1,2, - 0,1,0, - 100000000,1,10, - 100000000,1,20, - 100000000,1,30, - 100000000,1,40, - 100000000,1,50, - 250000000,1,3, - 250000000,1,4, - 0,1,0, - 100000000,1,10, - 100000000,1,20, - 100000000,1,30, - 100000000,1,40, - 100000000,1,50 - ), training = False) + modal = new Modal() + test = new TraceTesting(events_size = 1, trace = ( // keep-format + 0,1,0, + 250000000,1,1, + 250000000,1,2, + 0,1,0, + 100000000,1,10, + 100000000,1,20, + 100000000,1,30, + 100000000,1,40, + 100000000,1,50, + 250000000,1,3, + 250000000,1,4, + 0,1,0, + 100000000,1,10, + 100000000,1,20, + 100000000,1,30, + 100000000,1,40, + 100000000,1,50 + ), training = False) - modal.count -> test.events + modal.count -> test.events - # Trigger mode change - reaction(stepper) -> modal.next {= modal.next.set(True) =} + reaction(stepper) -> modal.next {= modal.next.set(True) =} # Trigger mode change - # Print - reaction(modal.count) {= print(modal.count.value) =} + reaction(modal.count) {= print(modal.count.value) =} # Print } diff --git a/test/Python/src/modal_models/util/TraceTesting.lf b/test/Python/src/modal_models/util/TraceTesting.lf index 305ff31a5b..02781b42fe 100644 --- a/test/Python/src/modal_models/util/TraceTesting.lf +++ b/test/Python/src/modal_models/util/TraceTesting.lf @@ -2,61 +2,61 @@ target Python reactor TraceTesting(events_size = 0, trace = {= [] =}, training = False) { - input[events_size] events + input[events_size] events - state last_reaction_time = 0 - state trace_idx = 0 - state recorded_events = {= [] =} - state recorded_events_next = 0 + state last_reaction_time = 0 + state trace_idx = 0 + state recorded_events = {= [] =} + state recorded_events_next = 0 - reaction(startup) {= self.last_reaction_time = lf.time.logical() =} + reaction(startup) {= self.last_reaction_time = lf.time.logical() =} - reaction(events) {= - # Time passed since last reaction - curr_reaction_delay = lf.time.logical() - self.last_reaction_time + reaction(events) {= + # Time passed since last reaction + curr_reaction_delay = lf.time.logical() - self.last_reaction_time + + if self.training: + # Save the time + self.recorded_events.append(curr_reaction_delay) + else: + if self.trace_idx >= len(self.trace): + sys.stderr.write("ERROR: Trace Error: Current execution exceeds given trace.\n") + exit(1) + + trace_reaction_delay = self.trace[self.trace_idx] + self.trace_idx += 1 + + if curr_reaction_delay != trace_reaction_delay: + sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected reaction timing. (delay: {curr_reaction_delay}, expected: {trace_reaction_delay})\n") + exit(2) + + for i in range(self.events_size): + curr_present = events[i].is_present + curr_value = events[i].value if self.training: - # Save the time - self.recorded_events.append(curr_reaction_delay) + # Save the event + self.recorded_events.append(curr_present) + self.recorded_events.append(curr_value) else: - if self.trace_idx >= len(self.trace): - sys.stderr.write("ERROR: Trace Error: Current execution exceeds given trace.\n") - exit(1) - - trace_reaction_delay = self.trace[self.trace_idx] + trace_present = self.trace[self.trace_idx] + self.trace_idx += 1 + trace_value = self.trace[self.trace_idx] self.trace_idx += 1 - if curr_reaction_delay != trace_reaction_delay: - sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected reaction timing. (delay: {curr_reaction_delay}, expected: {trace_reaction_delay})\n") - exit(2) - - for i in range(self.events_size): - curr_present = events[i].is_present - curr_value = events[i].value - - if self.training: - # Save the event - self.recorded_events.append(curr_present) - self.recorded_events.append(curr_value) - else: - trace_present = self.trace[self.trace_idx] - self.trace_idx += 1 - trace_value = self.trace[self.trace_idx] - self.trace_idx += 1 - - if trace_present != curr_present: - sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected event presence. (event: {i}, presence: {curr_present}, expected: {trace_present})\n") - exit(3) - elif curr_present and trace_value != curr_value: - sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected event presence. (event: {i}, value: {curr_value}, expected: {trace_value})\n") - exit(4) - - self.last_reaction_time = lf.time.logical() - =} - - reaction(shutdown) {= - if self.training: - print(f"Recorded event trace ({self.recorded_events_next}):") - print(self.recorded_events) - =} + if trace_present != curr_present: + sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected event presence. (event: {i}, presence: {curr_present}, expected: {trace_present})\n") + exit(3) + elif curr_present and trace_value != curr_value: + sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected event presence. (event: {i}, value: {curr_value}, expected: {trace_value})\n") + exit(4) + + self.last_reaction_time = lf.time.logical() + =} + + reaction(shutdown) {= + if self.training: + print(f"Recorded event trace ({self.recorded_events_next}):") + print(self.recorded_events) + =} } diff --git a/test/Python/src/multiport/BankIndexInitializer.lf b/test/Python/src/multiport/BankIndexInitializer.lf index 52ef58bb1d..7a717e3c57 100644 --- a/test/Python/src/multiport/BankIndexInitializer.lf +++ b/test/Python/src/multiport/BankIndexInitializer.lf @@ -4,34 +4,34 @@ target Python preamble {= table = [4, 3, 2, 1] =} reactor Source(bank_index = 0, value = 0) { - output out + output out - reaction(startup) -> out {= out.set(self.value) =} + reaction(startup) -> out {= out.set(self.value) =} } reactor Sink(width = 4) { - input[width] _in - state received = False + input[width] _in + state received = False - reaction(_in) {= - for (idx, port) in enumerate(_in): - if port.is_present is True: - print("Received on channel {:d}: {:d}".format(idx, port.value)) - self.received = True - if port.value != 4 - idx: - sys.stderr.write("ERROR: expected {:d}\n".format(4 - idx)) - exit(1) - =} + reaction(_in) {= + for (idx, port) in enumerate(_in): + if port.is_present is True: + print("Received on channel {:d}: {:d}".format(idx, port.value)) + self.received = True + if port.value != 4 - idx: + sys.stderr.write("ERROR: expected {:d}\n".format(4 - idx)) + exit(1) + =} - reaction(shutdown) {= - if self.received is False: - sys.stderr.write("ERROR: Sink received no data\n") - exit(1) - =} + reaction(shutdown) {= + if self.received is False: + sys.stderr.write("ERROR: Sink received no data\n") + exit(1) + =} } main reactor(width = 4) { - source = new[width] Source(value = {= table[bank_index] =}) - sink = new Sink(width = width) - source.out -> sink._in + source = new[width] Source(value = {= table[bank_index] =}) + sink = new Sink(width = width) + source.out -> sink._in } diff --git a/test/Python/src/multiport/BankReactionsInContainer.lf b/test/Python/src/multiport/BankReactionsInContainer.lf index 7316463c3d..147eddfef4 100644 --- a/test/Python/src/multiport/BankReactionsInContainer.lf +++ b/test/Python/src/multiport/BankReactionsInContainer.lf @@ -1,68 +1,66 @@ -/** - * This tests an output that is broadcast back to a multiport input of a bank. - */ +/** This tests an output that is broadcast back to a multiport input of a bank. */ target Python { - timeout: 1 sec + timeout: 1 sec } reactor R(bank_index = 0) { - output[2] out - input[2] inp - state received = False + output[2] out + input[2] inp + state received = False - reaction(startup) -> out {= - for (i, p) in enumerate(out): - value = self.bank_index * 2 + i - p.set(value) - print(f"Inner sending {value} to bank {self.bank_index} channel {i}.") - =} + reaction(startup) -> out {= + for (i, p) in enumerate(out): + value = self.bank_index * 2 + i + p.set(value) + print(f"Inner sending {value} to bank {self.bank_index} channel {i}.") + =} - reaction(inp) {= - for (i, p) in enumerate(inp): - if p.is_present: - print(f"Inner received {p.value} in bank {self.bank_index}, channel {i}") - self.received = True - if p.value != (self.bank_index * 2 + i): - sys.stderr.write(f"ERROR: Expected {self.bank_index * 2 + i}.\n") - exit(1) - =} + reaction(inp) {= + for (i, p) in enumerate(inp): + if p.is_present: + print(f"Inner received {p.value} in bank {self.bank_index}, channel {i}") + self.received = True + if p.value != (self.bank_index * 2 + i): + sys.stderr.write(f"ERROR: Expected {self.bank_index * 2 + i}.\n") + exit(1) + =} - reaction(shutdown) {= - print("Inner shutdown invoked.") - if self.received is not True: - sys.stderr.write(f"ERROR: Received no input.") - exit(1) - =} + reaction(shutdown) {= + print("Inner shutdown invoked.") + if self.received is not True: + sys.stderr.write(f"ERROR: Received no input.") + exit(1) + =} } main reactor { - s = new[2] R() - state received = False + s = new[2] R() + state received = False - reaction(startup) -> s.inp {= - count = 0 - for i in range(len(s)): - for (j, p) in enumerate(s[i].inp): - print(f"Sending {count} to bank {i} channel {j}.") - p.set(count) - count+=1 - =} + reaction(startup) -> s.inp {= + count = 0 + for i in range(len(s)): + for (j, p) in enumerate(s[i].inp): + print(f"Sending {count} to bank {i} channel {j}.") + p.set(count) + count+=1 + =} - reaction(s.out) {= - for i in range(len(s)): - for (j, p) in enumerate(s[i].out): - if p.is_present: - print(f"Outer received {p.value} on bank {i} channel {j}.") - self.received = True - if p.value != i * 2 + j: - sys.stderr.write(f"ERROR: Expected {i*2+j}.\n") - exit(1) - =} + reaction(s.out) {= + for i in range(len(s)): + for (j, p) in enumerate(s[i].out): + if p.is_present: + print(f"Outer received {p.value} on bank {i} channel {j}.") + self.received = True + if p.value != i * 2 + j: + sys.stderr.write(f"ERROR: Expected {i*2+j}.\n") + exit(1) + =} - reaction(shutdown) {= - print("Outer shutdown invoked.") - if self.received is not True: - sys.stderr.write(f"ERROR: Received no input.\n") - exit(1) - =} + reaction(shutdown) {= + print("Outer shutdown invoked.") + if self.received is not True: + sys.stderr.write(f"ERROR: Received no input.\n") + exit(1) + =} } diff --git a/test/Python/src/multiport/BankToBank.lf b/test/Python/src/multiport/BankToBank.lf index 6e3ddc734d..c1924f6a53 100644 --- a/test/Python/src/multiport/BankToBank.lf +++ b/test/Python/src/multiport/BankToBank.lf @@ -1,42 +1,42 @@ # Check bank of reactors sending to bank of reactors. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(bank_index = 0) { - timer t(0, 200 msec) - output out - state s = 0 + timer t(0, 200 msec) + output out + state s = 0 - reaction(t) -> out {= - out.set(self.s) - self.s += self.bank_index - =} + reaction(t) -> out {= + out.set(self.s) + self.s += self.bank_index + =} } reactor Destination(bank_index = 0) { - state s = 0 - input _in + state s = 0 + input _in - reaction(_in) {= - print("Destination " + str(self.bank_index) + " received: " + str(_in.value)) - if (_in.value != self.s): - sys.stderr.write("ERROR: Expected " + str(self.s)) - exit(1) - self.s += self.bank_index - =} + reaction(_in) {= + print("Destination " + str(self.bank_index) + " received: " + str(_in.value)) + if (_in.value != self.s): + sys.stderr.write("ERROR: Expected " + str(self.s)) + exit(1) + self.s += self.bank_index + =} - reaction(shutdown) {= - if self.s == 0 and self.bank_index != 0: - sys.stderr.write("ERROR: Destination " + self.bank_index + " received no input!") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.s == 0 and self.bank_index != 0: + sys.stderr.write("ERROR: Destination " + self.bank_index + " received no input!") + exit(1) + print("Success.") + =} } main reactor BankToBank(width = 4) { - a = new[width] Source() - b = new[width] Destination() - a.out -> b._in + a = new[width] Source() + b = new[width] Destination() + a.out -> b._in } diff --git a/test/Python/src/multiport/BankToBankMultiport.lf b/test/Python/src/multiport/BankToBankMultiport.lf index f335e53858..ace36af77f 100644 --- a/test/Python/src/multiport/BankToBankMultiport.lf +++ b/test/Python/src/multiport/BankToBankMultiport.lf @@ -1,50 +1,50 @@ # Check bank of reactors sending to bank of reactors with multiports. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width = 1) { - timer t(0, 200 msec) - output[width] out - state s = 0 - - reaction(t) -> out {= - for port in out: - port.set(self.s) - self.s += 1 - =} + timer t(0, 200 msec) + output[width] out + state s = 0 + + reaction(t) -> out {= + for port in out: + port.set(self.s) + self.s += 1 + =} } reactor Destination(width = 1) { - state s = 6 - input[width] _in - - reaction(_in) {= - sm = 0 - for port in _in: - if port.is_present: - sm += port.value - - print("Sum of received: ", sm) - if sm != self.s: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) - exit(1) - - self.s += 16 - =} - - reaction(shutdown) {= - if self.s <= 6: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - - print("Success.") - =} + state s = 6 + input[width] _in + + reaction(_in) {= + sm = 0 + for port in _in: + if port.is_present: + sm += port.value + + print("Sum of received: ", sm) + if sm != self.s: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) + exit(1) + + self.s += 16 + =} + + reaction(shutdown) {= + if self.s <= 6: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + + print("Success.") + =} } main reactor BankToBankMultiport(bank_width = 4) { - a = new[bank_width] Source(width = 4) - b = new[bank_width] Destination(width = 4) - a.out -> b._in + a = new[bank_width] Source(width = 4) + b = new[bank_width] Destination(width = 4) + a.out -> b._in } diff --git a/test/Python/src/multiport/BankToBankMultiportAfter.lf b/test/Python/src/multiport/BankToBankMultiportAfter.lf index 9d6e946122..4f42b8dac2 100644 --- a/test/Python/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Python/src/multiport/BankToBankMultiportAfter.lf @@ -1,13 +1,13 @@ # Check bank of reactors sending to bank of reactors with multiports. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source, Destination from "BankToBankMultiport.lf" main reactor BankToBankMultiportAfter(bank_width = 4) { - a = new[bank_width] Source(width = 4) - b = new[bank_width] Destination(width = 4) - a.out -> b._in after 200 msec + a = new[bank_width] Source(width = 4) + b = new[bank_width] Destination(width = 4) + a.out -> b._in after 200 msec } diff --git a/test/Python/src/multiport/BankToMultiport.lf b/test/Python/src/multiport/BankToMultiport.lf index 769e0ea2fc..45719b6a13 100644 --- a/test/Python/src/multiport/BankToMultiport.lf +++ b/test/Python/src/multiport/BankToMultiport.lf @@ -2,34 +2,34 @@ target Python reactor Source(bank_index = 0) { - output out + output out - reaction(startup) -> out {= out.set(self.bank_index) =} + reaction(startup) -> out {= out.set(self.bank_index) =} } reactor Sink(width = 4) { - input[width] _in - state received = False + input[width] _in + state received = False - reaction(_in) {= - for (idx, port) in enumerate(_in): - if port.is_present is True: - print("Received on channel {:d}: {:d}".format(idx, port.value)) - self.received = True - if port.value != idx: - sys.stderr.write("ERROR: expected {:d}\n".format(idx)) - exit(1) - =} + reaction(_in) {= + for (idx, port) in enumerate(_in): + if port.is_present is True: + print("Received on channel {:d}: {:d}".format(idx, port.value)) + self.received = True + if port.value != idx: + sys.stderr.write("ERROR: expected {:d}\n".format(idx)) + exit(1) + =} - reaction(shutdown) {= - if self.received is False: - sys.stderr.write("ERROR: Sink received no data\n") - exit(1) - =} + reaction(shutdown) {= + if self.received is False: + sys.stderr.write("ERROR: Sink received no data\n") + exit(1) + =} } main reactor BankToMultiport(width = 5) { - source = new[width] Source() - sink = new Sink(width = width) - source.out -> sink._in + source = new[width] Source() + sink = new Sink(width = width) + source.out -> sink._in } diff --git a/test/Python/src/multiport/Broadcast.lf b/test/Python/src/multiport/Broadcast.lf index 2e507d607f..09643f3679 100644 --- a/test/Python/src/multiport/Broadcast.lf +++ b/test/Python/src/multiport/Broadcast.lf @@ -1,40 +1,40 @@ target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(value = 42) { - output out + output out - reaction(startup) -> out {= out.set(self.value) =} + reaction(startup) -> out {= out.set(self.value) =} } reactor Destination(bank_index = 0, delay = 0) { - input _in - state received = False + input _in + state received = False - reaction(_in) {= - print(f"Destination {self.bank_index} received {_in.value}.") - if (_in.value != 42): - sys.stderr.write("ERROR: Expected 42.\n") - exit(1) + reaction(_in) {= + print(f"Destination {self.bank_index} received {_in.value}.") + if (_in.value != 42): + sys.stderr.write("ERROR: Expected 42.\n") + exit(1) - if lf.time.logical_elapsed() != self.delay: - sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") - exit(2) - self.received = True - =} + if lf.time.logical_elapsed() != self.delay: + sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") + exit(2) + self.received = True + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write(f"ERROR: Destination {self.bank_index} received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write(f"ERROR: Destination {self.bank_index} received no input!\n") + exit(1) + print("Success.") + =} } main reactor { - a = new Source() - b = new[4] Destination() - (a.out)+ -> b._in + a = new Source() + b = new[4] Destination() + (a.out)+ -> b._in } diff --git a/test/Python/src/multiport/BroadcastMultipleAfter.lf b/test/Python/src/multiport/BroadcastMultipleAfter.lf index 9fc327e6fd..eba9455f39 100644 --- a/test/Python/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Python/src/multiport/BroadcastMultipleAfter.lf @@ -1,39 +1,39 @@ target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source from "Broadcast.lf" reactor Destination(bank_index = 0, delay = 0) { - input _in - state received = False + input _in + state received = False - reaction(_in) {= - print(f"Destination {self.bank_index} received {_in.value}.") - expected = (self.bank_index % 3) + 1 - if (_in.value != expected): - sys.stderr.write("ERROR: Expected 42.\n") - exit(1) + reaction(_in) {= + print(f"Destination {self.bank_index} received {_in.value}.") + expected = (self.bank_index % 3) + 1 + if (_in.value != expected): + sys.stderr.write("ERROR: Expected 42.\n") + exit(1) - if lf.time.logical_elapsed() != self.delay: - sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") - exit(2) - self.received = True - =} + if lf.time.logical_elapsed() != self.delay: + sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") + exit(2) + self.received = True + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write(f"ERROR: Destination {self.bank_index} received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write(f"ERROR: Destination {self.bank_index} received no input!\n") + exit(1) + print("Success.") + =} } main reactor { - a1 = new Source(value = 1) - a2 = new Source(value = 2) - a3 = new Source(value = 3) - b = new[9] Destination(delay = 1 sec) - (a1.out, a2.out, a3.out)+ -> b._in after 1 sec + a1 = new Source(value = 1) + a2 = new Source(value = 2) + a3 = new Source(value = 3) + b = new[9] Destination(delay = 1 sec) + (a1.out, a2.out, a3.out)+ -> b._in after 1 sec } diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 92d9363df5..f1ca4769ee 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -1,43 +1,41 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(check_override = 0, bank_index = 0) { - output out + output out - reaction(startup) -> out {= - out.set(self.bank_index * self.check_override) - =} + reaction(startup) -> out {= out.set(self.bank_index * self.check_override) =} } reactor Destination { - input[3] _in - state received = 0 - - reaction(_in) {= - for (idx, port) in enumerate(_in): - print("Destination channel " + str(idx) + " received " + str(port.value)) - if idx != port.value: - sys.stderr.write("ERROR: Expected " + str(idx)) - exit(1) - - self.received = True - =} - - reaction(shutdown) {= - if self.received is False: - sys.stderr.write("ERROR: Destination received no input!\n") + input[3] _in + state received = 0 + + reaction(_in) {= + for (idx, port) in enumerate(_in): + print("Destination channel " + str(idx) + " received " + str(port.value)) + if idx != port.value: + sys.stderr.write("ERROR: Expected " + str(idx)) exit(1) - print("Success.") - =} + self.received = True + =} + + reaction(shutdown) {= + if self.received is False: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + + print("Success.") + =} } main reactor MultiportFromBank { - a = new[3] Source(check_override = 1) - b = new Destination() - a.out -> b._in + a = new[3] Source(check_override = 1) + b = new Destination() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index 27ecb3c80b..d47481b817 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -1,26 +1,26 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Destination from "MultiportFromBank.lf" reactor Source(bank_index = 0) { - output out + output out - reaction(startup) -> out {= out.set(self.bank_index) =} + reaction(startup) -> out {= out.set(self.bank_index) =} } reactor Container { - output[3] out - s = new[3] Source() - s.out -> out + output[3] out + s = new[3] Source() + s.out -> out } main reactor MultiportFromBankHierarchy { - a = new Container() - b = new Destination() - a.out -> b._in + a = new Container() + b = new Destination() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportFromHierarchy.lf b/test/Python/src/multiport/MultiportFromHierarchy.lf index 4116587f01..342ae198c3 100644 --- a/test/Python/src/multiport/MultiportFromHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromHierarchy.lf @@ -1,60 +1,59 @@ -# Check multiport output to multiport input, where the former is a hierarchical -# reactor. +# Check multiport output to multiport input, where the former is a hierarchical reactor. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[4] out - state s = 0 - - reaction(t) -> out {= - for port in out: - port.set(self.s) - self.s = self.s + 1 - =} + timer t(0, 200 msec) + output[4] out + state s = 0 + + reaction(t) -> out {= + for port in out: + port.set(self.s) + self.s = self.s + 1 + =} } reactor Destination { - state s = 6 - input[4] _in - - reaction(_in) {= - sm = 0 - for port in _in: - if port.is_present: - sm += port.value - print("Sum of received: " + str(sm)) - if (sm != self.s): - sys.stderr.write("ERROR: Expected " + str(self.s) + ".\n") - exit(1) - self.s += 16 - =} - - reaction(shutdown) {= - if self.s <= 6: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success.") - =} + state s = 6 + input[4] _in + + reaction(_in) {= + sm = 0 + for port in _in: + if port.is_present: + sm += port.value + print("Sum of received: " + str(sm)) + if (sm != self.s): + sys.stderr.write("ERROR: Expected " + str(self.s) + ".\n") + exit(1) + self.s += 16 + =} + + reaction(shutdown) {= + if self.s <= 6: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success.") + =} } reactor Container { - output[4] out - src = new InsideContainer() - src.out -> out + output[4] out + src = new InsideContainer() + src.out -> out } reactor InsideContainer { - output[4] out - src = new Source() - src.out -> out + output[4] out + src = new Source() + src.out -> out } main reactor MultiportFromHierarchy { - a = new Container() - b = new Destination() - a.out -> b._in + a = new Container() + b = new Destination() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportFromReaction.lf b/test/Python/src/multiport/MultiportFromReaction.lf index 05b280b126..2b8266cffc 100644 --- a/test/Python/src/multiport/MultiportFromReaction.lf +++ b/test/Python/src/multiport/MultiportFromReaction.lf @@ -1,45 +1,45 @@ # Check reaction to multiport input of a contained reactor. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Destination(width = 1) { - state s = 6 - input[width] _in + state s = 6 + input[width] _in - reaction(_in) {= - sm = 0; - for port in _in: - if port.is_present: - sm += port.value - print("Sum of received: ", sm) - if sm != self.s: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) - exit(1) + reaction(_in) {= + sm = 0; + for port in _in: + if port.is_present: + sm += port.value + print("Sum of received: ", sm) + if sm != self.s: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) + exit(1) - self.s += 16 - =} + self.s += 16 + =} - reaction(shutdown) {= - if self.s <= 6: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.s <= 6: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success.") + =} } main reactor MultiportFromReaction { - timer t(0, 200 msec) - state s = 0 - b = new Destination(width = 4) + timer t(0, 200 msec) + state s = 0 + b = new Destination(width = 4) - reaction(t) -> b._in {= - for (idx, port) in enumerate(b._in): - print("Before SET, b.in[{:d}].is_present has value {:d}".format(idx, port.is_present)) - port.set(self.s) - self.s += 1 - print("AFTER set, b.in[{:d}].is_present has value {:d}".format(idx, port.is_present)) - print("AFTER set, b.in[{:d}].value has value {:d}".format(idx, port.value)) - =} + reaction(t) -> b._in {= + for (idx, port) in enumerate(b._in): + print("Before SET, b.in[{:d}].is_present has value {:d}".format(idx, port.is_present)) + port.set(self.s) + self.s += 1 + print("AFTER set, b.in[{:d}].is_present has value {:d}".format(idx, port.is_present)) + print("AFTER set, b.in[{:d}].value has value {:d}".format(idx, port.value)) + =} } diff --git a/test/Python/src/multiport/MultiportIn.lf b/test/Python/src/multiport/MultiportIn.lf index 35bdee7341..9045be7792 100644 --- a/test/Python/src/multiport/MultiportIn.lf +++ b/test/Python/src/multiport/MultiportIn.lf @@ -1,64 +1,64 @@ -# This is a version fo the Threaded test that uses a multiport input at the -# destination. Its purpose is to test multiport inputs. +# This is a version fo the Threaded test that uses a multiport input at the destination. Its purpose +# is to test multiport inputs. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output out - state s = 0 + timer t(0, 200 msec) + output out + state s = 0 - reaction(t) -> out {= - out.set(self.s) - self.s+=1 - =} + reaction(t) -> out {= + out.set(self.s) + self.s+=1 + =} } reactor Computation { - input _in - output out + input _in + output out - reaction(_in) -> out {= out.set(_in.value) =} + reaction(_in) -> out {= out.set(_in.value) =} } reactor Destination { - state s = 0 - input[4] _in + state s = 0 + input[4] _in - reaction(_in) {= - sum = 0 - for port in _in: - sum += port.value + reaction(_in) {= + sum = 0 + for port in _in: + sum += port.value - print("Sum of received: " + str(sum)) - if sum != self.s: - sys.stderr.write("ERROR: Expected " + str(self.s)) - exit(1) + print("Sum of received: " + str(sum)) + if sum != self.s: + sys.stderr.write("ERROR: Expected " + str(self.s)) + exit(1) - self.s += 4 - =} + self.s += 4 + =} - reaction(shutdown) {= - if self.s == 0: - sys.stderr.write("ERROR: Destination received no input!") - exit(1) + reaction(shutdown) {= + if self.s == 0: + sys.stderr.write("ERROR: Destination received no input!") + exit(1) - print("Success.") - =} + print("Success.") + =} } main reactor MultiportIn { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1._in - a.out -> t2._in - a.out -> t3._in - a.out -> t4._in - t1.out, t2.out, t3.out, t4.out -> b._in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1._in + a.out -> t2._in + a.out -> t3._in + a.out -> t4._in + t1.out, t2.out, t3.out, t4.out -> b._in } diff --git a/test/Python/src/multiport/MultiportInParameterized.lf b/test/Python/src/multiport/MultiportInParameterized.lf index 28b15808e3..206fa512ac 100644 --- a/test/Python/src/multiport/MultiportInParameterized.lf +++ b/test/Python/src/multiport/MultiportInParameterized.lf @@ -1,63 +1,63 @@ -# This is a version of the Threaded test that uses a multiport input at the -# destination. Its purpose is to test multiport inputs. +# This is a version of the Threaded test that uses a multiport input at the destination. Its purpose +# is to test multiport inputs. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output out - state s = 0 - - reaction(t) -> out {= - out.set(self.s) - self.s += 1 - =} + timer t(0, 200 msec) + output out + state s = 0 + + reaction(t) -> out {= + out.set(self.s) + self.s += 1 + =} } reactor Computation { - input _in - output out + input _in + output out - reaction(_in) -> out {= out.set(_in.value) =} + reaction(_in) -> out {= out.set(_in.value) =} } reactor Destination(width = 1) { - state s = 0 - input[width] _in - - reaction(_in) {= - sm = 0 - for port in _in: - sm += port.value - print("Sum of received: ", sm) - if sm != self.s: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) - exit(1) - self.s += 4 - =} - - reaction(shutdown) {= - if self.s == 0: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success."); - =} + state s = 0 + input[width] _in + + reaction(_in) {= + sm = 0 + for port in _in: + sm += port.value + print("Sum of received: ", sm) + if sm != self.s: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) + exit(1) + self.s += 4 + =} + + reaction(shutdown) {= + if self.s == 0: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success."); + =} } main reactor MultiportInParameterized { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination(width = 4) - a.out -> t1._in - a.out -> t2._in - a.out -> t3._in - a.out -> t4._in - # I.e.: t1.out -> b._in[0]; t2.out -> b._in[1]; t3.out -> b._in[2]; dt4.out - # -> b._in[3]; - t1.out, t2.out, t3.out, t4.out -> b._in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination(width = 4) + a.out -> t1._in + a.out -> t2._in + a.out -> t3._in + a.out -> t4._in + # I.e.: t1.out -> b._in[0]; t2.out -> b._in[1]; t3.out -> b._in[2]; dt4.out + # -> b._in[3]; + t1.out, t2.out, t3.out, t4.out -> b._in } diff --git a/test/Python/src/multiport/MultiportMutableInput.lf b/test/Python/src/multiport/MultiportMutableInput.lf index f931900ef7..a8e15b8bd6 100644 --- a/test/Python/src/multiport/MultiportMutableInput.lf +++ b/test/Python/src/multiport/MultiportMutableInput.lf @@ -1,47 +1,46 @@ -# Source produces a ints on a multiport, which it passes to Scale. Scale -# requests a writable copy. It modifies it and passes it to Print. It gets freed -# after Print is done with it. +# Source produces a ints on a multiport, which it passes to Scale. Scale requests a writable copy. +# It modifies it and passes it to Print. It gets freed after Print is done with it. target Python reactor Source { - output[2] out + output[2] out - reaction(startup) -> out {= - out[0].set(21) - out[1].set(42) - =} + reaction(startup) -> out {= + out[0].set(21) + out[1].set(42) + =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input[2] _in + input[2] _in - reaction(_in) {= - expected = 42 - for (idx, port) in enumerate(_in): - print("Received on channel {:d}: ".format(idx), port.value) - if port.value != expected: - sys.stderr.write("ERROR: Expected {:d}!\n".format(expected)) - exit(1) - expected *= 2 - =} + reaction(_in) {= + expected = 42 + for (idx, port) in enumerate(_in): + print("Received on channel {:d}: ".format(idx), port.value) + if port.value != expected: + sys.stderr.write("ERROR: Expected {:d}!\n".format(expected)) + exit(1) + expected *= 2 + =} } reactor Scale(scale = 2) { - mutable input[2] _in - output[2] out + mutable input[2] _in + output[2] out - reaction(_in) -> out {= - for (idx, port) in enumerate(_in): - # Modify the input, allowed because mutable. - port.value *= self.scale - out[idx].set(port.value) - =} + reaction(_in) -> out {= + for (idx, port) in enumerate(_in): + # Modify the input, allowed because mutable. + port.value *= self.scale + out[idx].set(port.value) + =} } main reactor MultiportMutableInput { - s = new Source() - c = new Scale() - p = new Print(scale = 2) - s.out -> c._in - c.out -> p._in + s = new Source() + c = new Scale() + p = new Print(scale = 2) + s.out -> c._in + c.out -> p._in } diff --git a/test/Python/src/multiport/MultiportMutableInputArray.lf b/test/Python/src/multiport/MultiportMutableInputArray.lf index 9efa3eeebf..9e6a7630de 100644 --- a/test/Python/src/multiport/MultiportMutableInputArray.lf +++ b/test/Python/src/multiport/MultiportMutableInputArray.lf @@ -1,46 +1,45 @@ -# Source produces a list on a multiport, which it passes to Scale. Scale -# requests a writable copy, which, instead of copying, it just gets ownership of -# the original list. It modifies it and passes it to Print. It gets freed after -# Print is done with it. +# Source produces a list on a multiport, which it passes to Scale. Scale requests a writable copy, +# which, instead of copying, it just gets ownership of the original list. It modifies it and passes +# it to Print. It gets freed after Print is done with it. target Python reactor Source { - output[2] out + output[2] out - reaction(startup) -> out {= - out[0].set([0,1,2]) - out[1].set([3,4,5]) - =} + reaction(startup) -> out {= + out[0].set([0,1,2]) + out[1].set([3,4,5]) + =} } reactor Print(scale = 1) { # The scale parameter is just for testing. - input[2] _in + input[2] _in - reaction(_in) {= - for (idx, port) in enumerate(_in): - print("Received on channel ", port.value) - if port.value != [(self.scale*i) for i in range(3*idx,(3*idx)+3)]: - sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") - exit(1) - =} + reaction(_in) {= + for (idx, port) in enumerate(_in): + print("Received on channel ", port.value) + if port.value != [(self.scale*i) for i in range(3*idx,(3*idx)+3)]: + sys.stderr.write("ERROR: Value received by Print does not match expectation!\n") + exit(1) + =} } reactor Scale(scale = 2) { - mutable input[2] _in - output[2] out + mutable input[2] _in + output[2] out - reaction(_in) -> out {= - for (idx, port) in enumerate(_in): - if port.is_present: - port.value = [value*self.scale for value in port.value] - out[idx].set(port.value) - =} + reaction(_in) -> out {= + for (idx, port) in enumerate(_in): + if port.is_present: + port.value = [value*self.scale for value in port.value] + out[idx].set(port.value) + =} } main reactor MultiportMutableInputArray { - s = new Source() - c = new Scale() - p = new Print(scale = 2) - s.out -> c._in - c.out -> p._in + s = new Source() + c = new Scale() + p = new Print(scale = 2) + s.out -> c._in + c.out -> p._in } diff --git a/test/Python/src/multiport/MultiportOut.lf b/test/Python/src/multiport/MultiportOut.lf index 3d29c5188a..0e84fed165 100644 --- a/test/Python/src/multiport/MultiportOut.lf +++ b/test/Python/src/multiport/MultiportOut.lf @@ -1,63 +1,63 @@ # Check multiport capabilities on Outputs. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[4] out - state s = 0 + timer t(0, 200 msec) + output[4] out + state s = 0 - reaction(t) -> out {= - for port in out: - port.set(self.s) + reaction(t) -> out {= + for port in out: + port.set(self.s) - self.s+=1 - =} + self.s+=1 + =} } reactor Computation { - input _in - output out + input _in + output out - reaction(_in) -> out {= out.set(_in.value) =} + reaction(_in) -> out {= out.set(_in.value) =} } reactor Destination { - state s = 0 - input[4] _in - - reaction(_in) {= - sum = 0 - for port in _in: - if port.is_present: - sum += port.value - - print("Sum of received: " + str(sum)) - if sum != self.s: - sys.stderr.write("ERROR: Expected " + str(self.s)) - exit(1) - - self.s += 4 - =} - - reaction(shutdown) {= - if self.s == 0: - sys.stderr.write("ERROR: Destination received no input!") - exit(1) - - print("Success.") - =} + state s = 0 + input[4] _in + + reaction(_in) {= + sum = 0 + for port in _in: + if port.is_present: + sum += port.value + + print("Sum of received: " + str(sum)) + if sum != self.s: + sys.stderr.write("ERROR: Expected " + str(self.s)) + exit(1) + + self.s += 4 + =} + + reaction(shutdown) {= + if self.s == 0: + sys.stderr.write("ERROR: Destination received no input!") + exit(1) + + print("Success.") + =} } main reactor MultiportOut { - a = new Source() - t1 = new Computation() - t2 = new Computation() - t3 = new Computation() - t4 = new Computation() - b = new Destination() - a.out -> t1._in, t2._in, t3._in, t4._in - t1.out, t2.out, t3.out, t4.out -> b._in + a = new Source() + t1 = new Computation() + t2 = new Computation() + t3 = new Computation() + t4 = new Computation() + b = new Destination() + a.out -> t1._in, t2._in, t3._in, t4._in + t1.out, t2.out, t3.out, t4.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToBank.lf b/test/Python/src/multiport/MultiportToBank.lf index 12d68d6662..8ac3e28321 100644 --- a/test/Python/src/multiport/MultiportToBank.lf +++ b/test/Python/src/multiport/MultiportToBank.lf @@ -1,40 +1,40 @@ # Check multiport output to bank of recipients. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[3] out + output[3] out - reaction(startup) -> out {= - for (idx, port) in enumerate(out): - port.set(idx) - =} + reaction(startup) -> out {= + for (idx, port) in enumerate(out): + port.set(idx) + =} } reactor Destination(bank_index = 0) { - input _in - state received = 0 + input _in + state received = 0 - reaction(_in) {= - print("Destination " + str(self.bank_index) + " received " + str(_in.value)) - if self.bank_index != _in.value: - sys.stderr.write("ERROR: Expected " + str(self.bank_index)) - exit(1) - self.received = True - =} + reaction(_in) {= + print("Destination " + str(self.bank_index) + " received " + str(_in.value)) + if self.bank_index != _in.value: + sys.stderr.write("ERROR: Expected " + str(self.bank_index)) + exit(1) + self.received = True + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write("ERROR: Destination " + str(self.bank_index) + " received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write("ERROR: Destination " + str(self.bank_index) + " received no input!\n") + exit(1) + print("Success.") + =} } main reactor MultiportToBank { - a = new Source() - b = new[3] Destination() - a.out -> b._in + a = new Source() + b = new[3] Destination() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToBankAfter.lf b/test/Python/src/multiport/MultiportToBankAfter.lf index 85fc91e513..e48624e853 100644 --- a/test/Python/src/multiport/MultiportToBankAfter.lf +++ b/test/Python/src/multiport/MultiportToBankAfter.lf @@ -1,37 +1,36 @@ -# Check multiport output to bank of recipients where the width of the bank is -# inferred. +# Check multiport output to bank of recipients where the width of the bank is inferred. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source from "MultiportToBank.lf" reactor Destination(bank_index = 0) { - input _in - state received = False + input _in + state received = False - reaction(_in) {= - print("Destination {:d} received {:d}.".format(self.bank_index, _in.value)) - if self.bank_index != _in.value: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.bank_index)) - exit(1) - if lf.time.logical_elapsed() != SEC(1): - sys.stderr.write("ERROR: Expected to receive input after one second.\n") - exit(2) - self.received = True - =} + reaction(_in) {= + print("Destination {:d} received {:d}.".format(self.bank_index, _in.value)) + if self.bank_index != _in.value: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.bank_index)) + exit(1) + if lf.time.logical_elapsed() != SEC(1): + sys.stderr.write("ERROR: Expected to receive input after one second.\n") + exit(2) + self.received = True + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write("ERROR: Destination {:d} received no input!\n".format(self.bank_index)) - exit(3) - print("Success.") - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write("ERROR: Destination {:d} received no input!\n".format(self.bank_index)) + exit(3) + print("Success.") + =} } main reactor MultiportToBankAfter { - a = new Source() - b = new[3] Destination() - a.out -> b._in after 1 sec # Width of the bank of delays will be inferred. + a = new Source() + b = new[3] Destination() + a.out -> b._in after 1 sec # Width of the bank of delays will be inferred. } diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index f70fa8ad92..8dde25e5da 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -1,40 +1,40 @@ -# Check multiport output to bank of recipients. Here, the bank is smaller than -# the width of the sending port. +# Check multiport output to bank of recipients. Here, the bank is smaller than the width of the +# sending port. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source from "MultiportToBank.lf" reactor Destination(bank_index = 0) { - input _in - state received = False + input _in + state received = False - reaction(_in) {= - print("Destination {:d} received {:d}.\n".format(self.bank_index, _in.value)) - if self.bank_index != _in.value: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.bank_index)) - exit(1) - self.received = True - =} + reaction(_in) {= + print("Destination {:d} received {:d}.\n".format(self.bank_index, _in.value)) + if self.bank_index != _in.value: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.bank_index)) + exit(1) + self.received = True + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write("ERROR: Destination {:d} received no input!\n".format(self.bank_index)) - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write("ERROR: Destination {:d} received no input!\n".format(self.bank_index)) + exit(1) + print("Success.") + =} } reactor Container { - input[3] _in - c = new[3] Destination() - _in -> c._in + input[3] _in + c = new[3] Destination() + _in -> c._in } main reactor MultiportToBankHierarchy { - a = new Source() - b = new Container() - a.out -> b._in + a = new Source() + b = new Container() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index 2a9e25a5e6..e5820481b5 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -1,55 +1,54 @@ -# Check multiport output to multiport input, where the latter is a hierarchical -# reactor. Note that the destination reactor has width wider than the sender, so -# one input is dangling. +# Check multiport output to multiport input, where the latter is a hierarchical reactor. Note that +# the destination reactor has width wider than the sender, so one input is dangling. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[4] out - state s = 0 + timer t(0, 200 msec) + output[4] out + state s = 0 - reaction(t) -> out {= - for port in out: - port.set(self.s) - self.s += 1 - =} + reaction(t) -> out {= + for port in out: + port.set(self.s) + self.s += 1 + =} } reactor Destination(width = 4) { - state s = 6 - input[width] _in + state s = 6 + input[width] _in - reaction(_in) {= - sm = 0 - for port in _in: - if port.is_present: - sm += port.value - print("Sum of received: ", sm) - if sm != self.s: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) - exit(1) - self.s += 16 - =} + reaction(_in) {= + sm = 0 + for port in _in: + if port.is_present: + sm += port.value + print("Sum of received: ", sm) + if sm != self.s: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) + exit(1) + self.s += 16 + =} - reaction(shutdown) {= - if self.s <= 6: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.s <= 6: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success.") + =} } reactor Container(width = 4) { - input[width] _in - dst = new Destination() - _in -> dst._in + input[width] _in + dst = new Destination() + _in -> dst._in } main reactor MultiportToHierarchy { - a = new Source() - b = new Container() - a.out -> b._in + a = new Source() + b = new Container() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToMultiport.lf b/test/Python/src/multiport/MultiportToMultiport.lf index b16e832e7e..33fa418feb 100644 --- a/test/Python/src/multiport/MultiportToMultiport.lf +++ b/test/Python/src/multiport/MultiportToMultiport.lf @@ -1,28 +1,28 @@ # Check multiport output to multiport input. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Destination from "MultiportToHierarchy.lf" reactor Source(width = 1) { - timer t(0, 200 msec) - output[width] out - state s = 0 + timer t(0, 200 msec) + output[width] out + state s = 0 - reaction(t) -> out {= - for i in range(len(out)): - print("Before SET, out[{:d}]->is_present has value %d".format(i), out[i].is_present) - out[i].set(self.s) - self.s += 1 - print("AFTER set, out[{:d}]->is_present has value ".format(i), out[i].is_present) - print("AFTER set, out[{:d}]->value has value ".format(i), out[i].value) - =} + reaction(t) -> out {= + for i in range(len(out)): + print("Before SET, out[{:d}]->is_present has value %d".format(i), out[i].is_present) + out[i].set(self.s) + self.s += 1 + print("AFTER set, out[{:d}]->is_present has value ".format(i), out[i].is_present) + print("AFTER set, out[{:d}]->value has value ".format(i), out[i].value) + =} } main reactor MultiportToMultiport { - a = new Source(width = 4) - b = new Destination(width = 4) - a.out -> b._in + a = new Source(width = 4) + b = new Destination(width = 4) + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToMultiport2.lf b/test/Python/src/multiport/MultiportToMultiport2.lf index cb6da65f35..2a92c3ef3c 100644 --- a/test/Python/src/multiport/MultiportToMultiport2.lf +++ b/test/Python/src/multiport/MultiportToMultiport2.lf @@ -2,32 +2,32 @@ target Python reactor Source(width = 2) { - output[width] out + output[width] out - reaction(startup) -> out {= - for (idx, port) in enumerate(out): - port.set(idx) - =} + reaction(startup) -> out {= + for (idx, port) in enumerate(out): + port.set(idx) + =} } reactor Destination(width = 2) { - input[width] _in + input[width] _in - reaction(_in) {= - for (idx, port) in enumerate(_in): - if port.is_present: - print("Received on channel {:d}: ".format(idx), port.value) - # NOTE: For testing purposes, this assumes the specific - # widths instantiated below. - if port.value != idx % 3: - sys.stderr.write("ERROR: expected {:d}!\n".format(idx % 3)) - exit(1) - =} + reaction(_in) {= + for (idx, port) in enumerate(_in): + if port.is_present: + print("Received on channel {:d}: ".format(idx), port.value) + # NOTE: For testing purposes, this assumes the specific + # widths instantiated below. + if port.value != idx % 3: + sys.stderr.write("ERROR: expected {:d}!\n".format(idx % 3)) + exit(1) + =} } main reactor MultiportToMultiport2 { - a1 = new Source(width = 3) - a2 = new Source(width = 2) - b = new Destination(width = 5) - a1.out, a2.out -> b._in + a1 = new Source(width = 3) + a2 = new Source(width = 2) + b = new Destination(width = 5) + a1.out, a2.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToMultiport2After.lf b/test/Python/src/multiport/MultiportToMultiport2After.lf index 0e7ee9aef2..423a3b8b2e 100644 --- a/test/Python/src/multiport/MultiportToMultiport2After.lf +++ b/test/Python/src/multiport/MultiportToMultiport2After.lf @@ -4,26 +4,26 @@ target Python import Source from "MultiportToMultiport2.lf" reactor Destination(width = 2) { - input[width] _in + input[width] _in - reaction(_in) {= - for (idx, port) in enumerate(_in): - if port.is_present: - print("Received on channel {:d}: ".format(idx), port.value) - # NOTE: For testing purposes, this assumes the specific - # widths instantiated below. - if port.value != idx % 3: - sys.stderr.write("ERROR: expected {:d}!\n".format(idx % 3)) - exit(1) - if lf.time.logical_elapsed() != SEC(1): - sys.stderr.write("ERROR: Expected to receive input after one second.\n") - exit(2) - =} + reaction(_in) {= + for (idx, port) in enumerate(_in): + if port.is_present: + print("Received on channel {:d}: ".format(idx), port.value) + # NOTE: For testing purposes, this assumes the specific + # widths instantiated below. + if port.value != idx % 3: + sys.stderr.write("ERROR: expected {:d}!\n".format(idx % 3)) + exit(1) + if lf.time.logical_elapsed() != SEC(1): + sys.stderr.write("ERROR: Expected to receive input after one second.\n") + exit(2) + =} } main reactor MultiportToMultiport2After { - a1 = new Source(width = 3) - a2 = new Source(width = 2) - b = new Destination(width = 5) - a1.out, a2.out -> b._in after 1 sec + a1 = new Source(width = 3) + a2 = new Source(width = 2) + b = new Destination(width = 5) + a1.out, a2.out -> b._in after 1 sec } diff --git a/test/Python/src/multiport/MultiportToMultiportArray.lf b/test/Python/src/multiport/MultiportToMultiportArray.lf index 5eb043570d..4be3c1b68d 100644 --- a/test/Python/src/multiport/MultiportToMultiportArray.lf +++ b/test/Python/src/multiport/MultiportToMultiportArray.lf @@ -1,50 +1,49 @@ -# Check multiport output to multiport input. Destination port is wider than -# sending port. +# Check multiport output to multiport input. Destination port is wider than sending port. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - timer t(0, 200 msec) - output[2] out - state s = 0 - - reaction(t) -> out {= - for port in out: - port.set([self.s, self.s + 1, self.s + 2]) - self.s += 3 - =} + timer t(0, 200 msec) + output[2] out + state s = 0 + + reaction(t) -> out {= + for port in out: + port.set([self.s, self.s + 1, self.s + 2]) + self.s += 3 + =} } reactor Destination { - state s = 15 - input[2] _in - - reaction(_in) {= - sm = 0 - for port in _in: - if port.is_present: - sm += sum(port.value) - - print("Sum of received: ", sm); - if sm != self.s: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) - exit(1) - - self.s += 36 - =} - - reaction(shutdown) {= - if self.s <= 15: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success.") - =} + state s = 15 + input[2] _in + + reaction(_in) {= + sm = 0 + for port in _in: + if port.is_present: + sm += sum(port.value) + + print("Sum of received: ", sm); + if sm != self.s: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) + exit(1) + + self.s += 36 + =} + + reaction(shutdown) {= + if self.s <= 15: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success.") + =} } main reactor MultiportToMultiportArray { - a = new Source() - b = new Destination() - a.out -> b._in + a = new Source() + b = new Destination() + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToMultiportParameter.lf b/test/Python/src/multiport/MultiportToMultiportParameter.lf index b47905bb6e..ac6b3663dc 100644 --- a/test/Python/src/multiport/MultiportToMultiportParameter.lf +++ b/test/Python/src/multiport/MultiportToMultiportParameter.lf @@ -1,14 +1,14 @@ # Check multiport output to multiport input. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } import Source from "MultiportToMultiport.lf" import Destination from "MultiportToHierarchy.lf" main reactor MultiportToMultiportParameter(width = 4) { - a = new Source(width = width) - b = new Destination(width = width) - a.out -> b._in + a = new Source(width = width) + b = new Destination(width = width) + a.out -> b._in } diff --git a/test/Python/src/multiport/MultiportToPort.lf b/test/Python/src/multiport/MultiportToPort.lf index ebfbf81991..cc8efe50d6 100644 --- a/test/Python/src/multiport/MultiportToPort.lf +++ b/test/Python/src/multiport/MultiportToPort.lf @@ -1,43 +1,42 @@ -# Check multiport output to multiport input. Destination port is wider than -# sending port. +# Check multiport output to multiport input. Destination port is wider than sending port. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source { - output[2] out + output[2] out - reaction(startup) -> out {= - for (idx, port) in enumerate(out): - print("Source sending ", idx) - port.set(idx) - =} + reaction(startup) -> out {= + for (idx, port) in enumerate(out): + print("Source sending ", idx) + port.set(idx) + =} } reactor Destination(expected = 0) { - input _in - state received = False + input _in + state received = False - reaction(_in) {= - print("Received: ", _in.value) - self.received = True - if _in.value != self.expected: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.expected)) - exit(1) - =} + reaction(_in) {= + print("Received: ", _in.value) + self.received = True + if _in.value != self.expected: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.expected)) + exit(1) + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success.") + =} } main reactor MultiportToPort { - a = new Source() - b1 = new Destination() - b2 = new Destination(expected = 1) - a.out -> b1._in, b2._in + a = new Source() + b1 = new Destination() + b2 = new Destination(expected = 1) + a.out -> b1._in, b2._in } diff --git a/test/Python/src/multiport/MultiportToReaction.lf b/test/Python/src/multiport/MultiportToReaction.lf index b45ee9ac9e..811f233038 100644 --- a/test/Python/src/multiport/MultiportToReaction.lf +++ b/test/Python/src/multiport/MultiportToReaction.lf @@ -1,41 +1,41 @@ # Check reaction to multiport output of a contained reactor. target Python { - timeout: 2 sec, - fast: true + timeout: 2 sec, + fast: true } reactor Source(width = 1) { - timer t(0, 200 msec) - state s = 0 - output[width] out + timer t(0, 200 msec) + state s = 0 + output[width] out - reaction(t) -> out {= - for port in out: - port.set(self.s) - self.s += 1 - =} + reaction(t) -> out {= + for port in out: + port.set(self.s) + self.s += 1 + =} } main reactor { - state s = 6 - b = new Source(width = 4) + state s = 6 + b = new Source(width = 4) - reaction(b.out) {= - sm = 0 - for port in b.out: - if port.is_present: - sm += port.value - print("Sum of received: ", sm) - if sm != self.s: - sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) - exit(1) - self.s += 16 - =} + reaction(b.out) {= + sm = 0 + for port in b.out: + if port.is_present: + sm += port.value + print("Sum of received: ", sm) + if sm != self.s: + sys.stderr.write("ERROR: Expected {:d}.\n".format(self.s)) + exit(1) + self.s += 16 + =} - reaction(shutdown) {= - if self.s <= 6: - sys.stderr.write("ERROR: Destination received no input!\n") - exit(1) - print("Success.") - =} + reaction(shutdown) {= + if self.s <= 6: + sys.stderr.write("ERROR: Destination received no input!\n") + exit(1) + print("Success.") + =} } diff --git a/test/Python/src/multiport/NestedBanks.lf b/test/Python/src/multiport/NestedBanks.lf index 1e863043e6..bc2c08db54 100644 --- a/test/Python/src/multiport/NestedBanks.lf +++ b/test/Python/src/multiport/NestedBanks.lf @@ -5,76 +5,76 @@ target Python main reactor { - a = new[2] A() - c = new[3] C() - d = new D() - e = new E() + a = new[2] A() + c = new[3] C() + d = new D() + e = new E() - (a.x)+ -> c.z, d.u, e.t + (a.x)+ -> c.z, d.u, e.t } reactor A(bank_index = 0) { - output[4] x - b = new[2] B(a_bank_index = bank_index) - b.y -> x + output[4] x + b = new[2] B(a_bank_index = bank_index) + b.y -> x } reactor B(a_bank_index = 0, bank_index = 0) { - output[2] y + output[2] y - reaction(startup) -> y {= - base = self.a_bank_index * 4 + self.bank_index * 2 - y[0].set(base) - y[1].set(base + 1) - =} + reaction(startup) -> y {= + base = self.a_bank_index * 4 + self.bank_index * 2 + y[0].set(base) + y[1].set(base + 1) + =} } reactor C(bank_index = 0) { - input[2] z - f = new F(c_bank_index = bank_index) - g = new G(c_bank_index = bank_index) - z -> f.w, g.s + input[2] z + f = new F(c_bank_index = bank_index) + g = new G(c_bank_index = bank_index) + z -> f.w, g.s } reactor D { - input[2] u + input[2] u - reaction(u) {= - for (i, p) in enumerate(u): - print(f"d.u[{i}] received {p.value}.") - if p.value != (6 + i): - sys.stderr.write(f"ERROR: Expected {6 + i} but received {p.value}.\n") - exit(1) - =} + reaction(u) {= + for (i, p) in enumerate(u): + print(f"d.u[{i}] received {p.value}.") + if p.value != (6 + i): + sys.stderr.write(f"ERROR: Expected {6 + i} but received {p.value}.\n") + exit(1) + =} } reactor E { - input[8] t + input[8] t - reaction(t) {= - for (i, p) in enumerate(t): - print(f"e.t[{i}] received {p.value}.") - =} + reaction(t) {= + for (i, p) in enumerate(t): + print(f"e.t[{i}] received {p.value}.") + =} } reactor F(c_bank_index = 0) { - input w + input w - reaction(w) {= - print(f"c[{self.c_bank_index}].f.w received {w.value}.") - if w.value != self.c_bank_index * 2: - sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2} but received {w.value}.\n") - exit(1) - =} + reaction(w) {= + print(f"c[{self.c_bank_index}].f.w received {w.value}.") + if w.value != self.c_bank_index * 2: + sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2} but received {w.value}.\n") + exit(1) + =} } reactor G(c_bank_index = 0) { - input s + input s - reaction(s) {= - print(f"c[{self.c_bank_index}].g.s received {s.value}.") - if s.value != (self.c_bank_index * 2 + 1): - sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2 + 1} but received {s.value}.\n") - exit(1) - =} + reaction(s) {= + print(f"c[{self.c_bank_index}].g.s received {s.value}.") + if s.value != (self.c_bank_index * 2 + 1): + sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2 + 1} but received {s.value}.\n") + exit(1) + =} } diff --git a/test/Python/src/multiport/NestedInterleavedBanks.lf b/test/Python/src/multiport/NestedInterleavedBanks.lf index 9be37badcd..ea124666af 100644 --- a/test/Python/src/multiport/NestedInterleavedBanks.lf +++ b/test/Python/src/multiport/NestedInterleavedBanks.lf @@ -5,36 +5,36 @@ target Python reactor A(bank_index = 0, outer_bank_index = 0) { - output[2] p + output[2] p - reaction(startup) -> p {= - for i, port in enumerate(p): - port.set(self.outer_bank_index * 4 + self.bank_index * 2 + i + 1) - print(f"A sending {port.value}.") - =} + reaction(startup) -> p {= + for i, port in enumerate(p): + port.set(self.outer_bank_index * 4 + self.bank_index * 2 + i + 1) + print(f"A sending {port.value}.") + =} } reactor B(bank_index = 0) { - output[4] q - a = new[2] A(outer_bank_index = bank_index) - interleaved (a.p) -> q + output[4] q + a = new[2] A(outer_bank_index = bank_index) + interleaved (a.p) -> q } reactor C { - input[8] i + input[8] i - reaction(i) {= - expected = [1, 3, 2, 4, 5, 7, 6, 8] - for j, port in enumerate(i): - print(f"C received {port.value}.") - if port.value != expected[j]: - sys.stderr.write(f"ERROR: Expected {expected[j]}.\n") - exit(1) - =} + reaction(i) {= + expected = [1, 3, 2, 4, 5, 7, 6, 8] + for j, port in enumerate(i): + print(f"C received {port.value}.") + if port.value != expected[j]: + sys.stderr.write(f"ERROR: Expected {expected[j]}.\n") + exit(1) + =} } main reactor { - b = new[2] B() - c = new C() - b.q -> c.i + b = new[2] B() + c = new C() + b.q -> c.i } diff --git a/test/Python/src/multiport/ReactionsToNested.lf b/test/Python/src/multiport/ReactionsToNested.lf index 2c207dffb0..1f05d5ba5b 100644 --- a/test/Python/src/multiport/ReactionsToNested.lf +++ b/test/Python/src/multiport/ReactionsToNested.lf @@ -1,39 +1,38 @@ -# This test connects a simple counting source to tester that checks against its -# own count. +# This test connects a simple counting source to tester that checks against its own count. target Python { - timeout: 1 sec + timeout: 1 sec } reactor T(expected = 0) { - input z - state received = False + input z + state received = False - reaction(z) {= - print(f"T received {z.value}.") - self.received = True - if z.value != self.expected: - sys.stderr.write(f"ERROR: Expected {self.response}") - exit(1) - =} + reaction(z) {= + print(f"T received {z.value}.") + self.received = True + if z.value != self.expected: + sys.stderr.write(f"ERROR: Expected {self.response}") + exit(1) + =} - reaction(shutdown) {= - if self.received is not True: - sys.stderr.write(f"ERROR: No input received.") - exit(1) - =} + reaction(shutdown) {= + if self.received is not True: + sys.stderr.write(f"ERROR: No input received.") + exit(1) + =} } reactor D { - input[2] y - t1 = new T(expected = 42) - t2 = new T(expected = 43) - y -> t1.z, t2.z + input[2] y + t1 = new T(expected = 42) + t2 = new T(expected = 43) + y -> t1.z, t2.z } main reactor { - d = new D() + d = new D() - reaction(startup) -> d.y {= d.y[0].set(42) =} + reaction(startup) -> d.y {= d.y[0].set(42) =} - reaction(startup) -> d.y {= d.y[1].set(43) =} + reaction(startup) -> d.y {= d.y[1].set(43) =} } diff --git a/test/Python/src/target/AfterNoTypes.lf b/test/Python/src/target/AfterNoTypes.lf index 44aaa89c73..ef92444c34 100644 --- a/test/Python/src/target/AfterNoTypes.lf +++ b/test/Python/src/target/AfterNoTypes.lf @@ -1,50 +1,50 @@ -# This test demonstrates that after can be used on connections with ports that -# have no types. The test passes if the compile is succeeded +# This test demonstrates that after can be used on connections with ports that have no types. The +# test passes if the compile is succeeded target Python { - fast: false, - timeout: 3 sec + fast: false, + timeout: 3 sec } reactor Foo { - input x - output y + input x + output y - reaction(x) -> y {= y.set(2*x.value); =} + reaction(x) -> y {= y.set(2*x.value); =} } reactor Print { - state expected_time = 10 msec - state received = 0 - input x - - reaction(x) {= - self.received+=1 - elapsed_time = lf.time.logical_elapsed() - print("Result is " + str(x.value)) - if x.value != 84: - sys.stderr.write("ERROR: Expected result to be 84.\n") - exit(1) - - print("Current logical time is: " + str(elapsed_time)) - print("Current physical time is: " + str(lf.time.physical_elapsed())) - if elapsed_time != self.expected_time: - sys.stderr.write("ERROR: Expected logical time to be " + self.expected_time) - exit(2) - self.expected_time += SEC(1) - =} - - reaction(shutdown) {= - if (self.received == 0): - sys.stderr.write("ERROR: Final reactor received no data.\n") - exit(3) - =} + state expected_time = 10 msec + state received = 0 + input x + + reaction(x) {= + self.received+=1 + elapsed_time = lf.time.logical_elapsed() + print("Result is " + str(x.value)) + if x.value != 84: + sys.stderr.write("ERROR: Expected result to be 84.\n") + exit(1) + + print("Current logical time is: " + str(elapsed_time)) + print("Current physical time is: " + str(lf.time.physical_elapsed())) + if elapsed_time != self.expected_time: + sys.stderr.write("ERROR: Expected logical time to be " + self.expected_time) + exit(2) + self.expected_time += SEC(1) + =} + + reaction(shutdown) {= + if (self.received == 0): + sys.stderr.write("ERROR: Final reactor received no data.\n") + exit(3) + =} } main reactor { - f = new Foo() - p = new Print() - timer t(0, 1 sec) - f.y -> p.x after 10 msec + f = new Foo() + p = new Print() + timer t(0, 1 sec) + f.y -> p.x after 10 msec - reaction(t) -> f.x {= f.x.set(42) =} + reaction(t) -> f.x {= f.x.set(42) =} } diff --git a/test/Rust/src/ActionDelay.lf b/test/Rust/src/ActionDelay.lf index 75c7ab909f..e45f315c93 100644 --- a/test/Rust/src/ActionDelay.lf +++ b/test/Rust/src/ActionDelay.lf @@ -2,27 +2,27 @@ target Rust main reactor ActionDelay { - logical action act0 - logical action act1(100 msec) - state count: u32 = 0 + logical action act0 + logical action act1(100 msec) + state count: u32 = 0 - reaction(startup) -> act0, act1 {= - ctx.schedule(act0, after!(100 ms)); - ctx.schedule(act1, after!(40 ms)); - =} + reaction(startup) -> act0, act1 {= + ctx.schedule(act0, after!(100 ms)); + ctx.schedule(act1, after!(40 ms)); + =} - reaction(act0) {= - assert_tag_is!(ctx, T0 + 100 ms); - self.count += 1; - =} + reaction(act0) {= + assert_tag_is!(ctx, T0 + 100 ms); + self.count += 1; + =} - reaction(act1) {= - assert_tag_is!(ctx, T0 + 140 ms); - self.count += 1; - =} + reaction(act1) {= + assert_tag_is!(ctx, T0 + 140 ms); + self.count += 1; + =} - reaction(shutdown) {= - assert_eq!(2, self.count); - println!("SUCCESS") - =} + reaction(shutdown) {= + assert_eq!(2, self.count); + println!("SUCCESS") + =} } diff --git a/test/Rust/src/ActionImplicitDelay.lf b/test/Rust/src/ActionImplicitDelay.lf index 9a3a900d93..46b4a4d767 100644 --- a/test/Rust/src/ActionImplicitDelay.lf +++ b/test/Rust/src/ActionImplicitDelay.lf @@ -2,18 +2,18 @@ target Rust main reactor ActionImplicitDelay { - logical action act(40 msec) - state count: u64 = 1 + logical action act(40 msec) + state count: u64 = 1 - reaction(startup) -> act {= ctx.schedule(act, Asap); =} + reaction(startup) -> act {= ctx.schedule(act, Asap); =} - reaction(act) -> act {= - assert_tag_is!(ctx, T0 + (40 * self.count) ms); - self.count += 1; - if self.count <= 3 { - ctx.schedule(act, Asap); - } else { - println!("SUCCESS") - } - =} + reaction(act) -> act {= + assert_tag_is!(ctx, T0 + (40 * self.count) ms); + self.count += 1; + if self.count <= 3 { + ctx.schedule(act, Asap); + } else { + println!("SUCCESS") + } + =} } diff --git a/test/Rust/src/ActionIsPresent.lf b/test/Rust/src/ActionIsPresent.lf index 3a1e556c5a..a581fe7574 100644 --- a/test/Rust/src/ActionIsPresent.lf +++ b/test/Rust/src/ActionIsPresent.lf @@ -2,28 +2,28 @@ target Rust main reactor ActionIsPresent { - logical action a - state success: bool = false - state tried: bool = false + logical action a + state success: bool = false + state tried: bool = false - reaction(startup, a) -> a {= - if !ctx.is_present(a) { - assert_tag_is!(ctx, T0); - assert!(!self.tried, "Already tried, is_present does not work properly."); - self.tried = true; - // was triggered by startup - println!("Startup reaction @ {}", ctx.get_tag()); - ctx.schedule(a, after!(1 ns)); - } else { - assert_tag_is!(ctx, T0 + 1 ns); - // was triggered by schedule above - println!("Scheduled reaction @ {}", ctx.get_tag()); - self.success = true; - } - =} + reaction(startup, a) -> a {= + if !ctx.is_present(a) { + assert_tag_is!(ctx, T0); + assert!(!self.tried, "Already tried, is_present does not work properly."); + self.tried = true; + // was triggered by startup + println!("Startup reaction @ {}", ctx.get_tag()); + ctx.schedule(a, after!(1 ns)); + } else { + assert_tag_is!(ctx, T0 + 1 ns); + // was triggered by schedule above + println!("Scheduled reaction @ {}", ctx.get_tag()); + self.success = true; + } + =} - reaction(shutdown) {= - assert!(self.success, "What happened!?"); - println!("success"); - =} + reaction(shutdown) {= + assert!(self.success, "What happened!?"); + println!("success"); + =} } diff --git a/test/Rust/src/ActionScheduleMicrostep.lf b/test/Rust/src/ActionScheduleMicrostep.lf index 53bf8781b9..db1210190f 100644 --- a/test/Rust/src/ActionScheduleMicrostep.lf +++ b/test/Rust/src/ActionScheduleMicrostep.lf @@ -2,22 +2,22 @@ target Rust main reactor ActionScheduleMicrostep { - logical action act - state count: u32 = 1 + logical action act + state count: u32 = 1 - reaction(startup) -> act {= - assert_tag_is!(ctx, T0); - // executes at (T0, 0) - ctx.schedule(act, Asap); - =} + reaction(startup) -> act {= + assert_tag_is!(ctx, T0); + // executes at (T0, 0) + ctx.schedule(act, Asap); + =} - reaction(act) -> act {= - assert_tag_is!(ctx, (T0, self.count)); - self.count += 1; - if self.count <= 3 { - ctx.schedule(act, Asap); - } else { - println!("SUCCESS") - } - =} + reaction(act) -> act {= + assert_tag_is!(ctx, (T0, self.count)); + self.count += 1; + if self.count <= 3 { + ctx.schedule(act, Asap); + } else { + println!("SUCCESS") + } + =} } diff --git a/test/Rust/src/ActionValues.lf b/test/Rust/src/ActionValues.lf index 007da1fb5a..8e8fb9f958 100644 --- a/test/Rust/src/ActionValues.lf +++ b/test/Rust/src/ActionValues.lf @@ -2,31 +2,31 @@ target Rust main reactor ActionValues { - state r1done: bool = false - state r2done: bool = false - logical action act(100 msec): i32 + state r1done: bool = false + state r2done: bool = false + logical action act(100 msec): i32 - reaction(startup) -> act {= - ctx.schedule_with_v(act, Some(100), Asap); // scheduled in 100 ms - // scheduled in 150 ms, value is overwritten - ctx.schedule_with_v(act, Some(-100), after!(50 ms)); - =} + reaction(startup) -> act {= + ctx.schedule_with_v(act, Some(100), Asap); // scheduled in 100 ms + // scheduled in 150 ms, value is overwritten + ctx.schedule_with_v(act, Some(-100), after!(50 ms)); + =} - reaction(act) {= - println!("At {}, received {:?}", ctx.get_tag(), ctx.get(act)); + reaction(act) {= + println!("At {}, received {:?}", ctx.get_tag(), ctx.get(act)); - if ctx.get_tag() == tag!(T0 + 100 ms) { - assert_eq!(Some(100), ctx.get(act)); - self.r1done = true; - } else { - assert_tag_is!(ctx, T0 + 150 ms); - assert_eq!(Some(-100), ctx.get(act)); - self.r2done = true; - } - =} + if ctx.get_tag() == tag!(T0 + 100 ms) { + assert_eq!(Some(100), ctx.get(act)); + self.r1done = true; + } else { + assert_tag_is!(ctx, T0 + 150 ms); + assert_eq!(Some(-100), ctx.get(act)); + self.r2done = true; + } + =} - reaction(shutdown) {= - assert!(self.r1done && self.r2done); - println!("Success") - =} + reaction(shutdown) {= + assert!(self.r1done && self.r2done); + println!("Success") + =} } diff --git a/test/Rust/src/ActionValuesCleanup.lf b/test/Rust/src/ActionValuesCleanup.lf index f4bab7a2b5..6ad9bd1b38 100644 --- a/test/Rust/src/ActionValuesCleanup.lf +++ b/test/Rust/src/ActionValuesCleanup.lf @@ -2,49 +2,47 @@ target Rust main reactor ActionValuesCleanup { - preamble {= - use std::sync::atomic::AtomicBool; - use std::sync::atomic::Ordering; - // set to true when destructor is called - static mut DROPPED: AtomicBool = AtomicBool::new(false); + preamble {= + use std::sync::atomic::AtomicBool; + use std::sync::atomic::Ordering; + // set to true when destructor is called + static mut DROPPED: AtomicBool = AtomicBool::new(false); - #[derive(Clone, Debug)] - struct FooDrop { } - impl std::ops::Drop for FooDrop { - fn drop(&mut self) { - unsafe { - DROPPED.store(true, Ordering::SeqCst); - } + #[derive(Clone, Debug)] + struct FooDrop { } + impl std::ops::Drop for FooDrop { + fn drop(&mut self) { + unsafe { + DROPPED.store(true, Ordering::SeqCst); } } - =} + } + =} - logical action act: FooDrop - state count: u32 = 0 + logical action act: FooDrop + state count: u32 = 0 - reaction(startup) -> act {= - ctx.schedule_with_v(act, Some(FooDrop { }), Asap) - =} + reaction(startup) -> act {= ctx.schedule_with_v(act, Some(FooDrop { }), Asap) =} - reaction(act) -> act {= - ctx.use_ref(act, |v| println!("{:?}", v)); - if self.count == 0 { - self.count = 1; - assert!(ctx.is_present(act)); - assert!(ctx.use_ref(act, |v| v.is_some())); - ctx.schedule(act, Asap); - } else if self.count == 1 { - assert!(ctx.is_present(act)); - assert!(ctx.use_ref(act, |v| v.is_none())); - assert!(unsafe { DROPPED.load(Ordering::SeqCst) }); - self.count = 2; - } else { - unreachable!(); - } - =} + reaction(act) -> act {= + ctx.use_ref(act, |v| println!("{:?}", v)); + if self.count == 0 { + self.count = 1; + assert!(ctx.is_present(act)); + assert!(ctx.use_ref(act, |v| v.is_some())); + ctx.schedule(act, Asap); + } else if self.count == 1 { + assert!(ctx.is_present(act)); + assert!(ctx.use_ref(act, |v| v.is_none())); + assert!(unsafe { DROPPED.load(Ordering::SeqCst) }); + self.count = 2; + } else { + unreachable!(); + } + =} - reaction(shutdown) {= - assert_eq!(2, self.count, "expected 2 invocations"); - println!("success"); - =} + reaction(shutdown) {= + assert_eq!(2, self.count, "expected 2 invocations"); + println!("success"); + =} } diff --git a/test/Rust/src/CompositionWithPorts.lf b/test/Rust/src/CompositionWithPorts.lf index d91e8f3370..94fc2de449 100644 --- a/test/Rust/src/CompositionWithPorts.lf +++ b/test/Rust/src/CompositionWithPorts.lf @@ -1,27 +1,27 @@ target Rust reactor Source { - output out: i32 + output out: i32 - reaction(startup) -> out {= ctx.set(out, 76600) =} + reaction(startup) -> out {= ctx.set(out, 76600) =} } reactor Sink { - input inport: i32 + input inport: i32 - reaction(inport) {= - if let Some(value) = ctx.get(inport) { - println!("received {}", value); - assert_eq!(76600, value); - } else { - unreachable!(); - } - =} + reaction(inport) {= + if let Some(value) = ctx.get(inport) { + println!("received {}", value); + assert_eq!(76600, value); + } else { + unreachable!(); + } + =} } main reactor CompositionWithPorts { - source = new Source() - sink = new Sink() + source = new Source() + sink = new Sink() - source.out -> sink.inport + source.out -> sink.inport } diff --git a/test/Rust/src/CtorParamDefault.lf b/test/Rust/src/CtorParamDefault.lf index a7d2d868bc..aeaad8a957 100644 --- a/test/Rust/src/CtorParamDefault.lf +++ b/test/Rust/src/CtorParamDefault.lf @@ -1,14 +1,14 @@ target Rust reactor Print(value: i32 = 42) { - state v: i32 = value + state v: i32 = value - reaction(startup) {= - assert_eq!(42, self.v); - println!("success"); - =} + reaction(startup) {= + assert_eq!(42, self.v); + println!("success"); + =} } main reactor CtorParamDefault { - p = new Print() + p = new Print() } diff --git a/test/Rust/src/CtorParamMixed.lf b/test/Rust/src/CtorParamMixed.lf index 5de7a3dc4c..33c4730eb9 100644 --- a/test/Rust/src/CtorParamMixed.lf +++ b/test/Rust/src/CtorParamMixed.lf @@ -1,22 +1,18 @@ target Rust -reactor Print( - value: i32 = 42, - name: String = {= "xxx".into() =}, - other: bool = false -) { - state value = value - state name = name - state other = other +reactor Print(value: i32 = 42, name: String = {= "xxx".into() =}, other: bool = false) { + state value = value + state name = name + state other = other - reaction(startup) {= - assert_eq!(42, self.value); - assert_eq!("x2hr", self.name.as_str()); - assert_eq!(true, self.other); - println!("success"); - =} + reaction(startup) {= + assert_eq!(42, self.value); + assert_eq!("x2hr", self.name.as_str()); + assert_eq!(true, self.other); + println!("success"); + =} } main reactor CtorParamMixed { - p = new Print(other = true, name = {= "x2hr".into() =}) + p = new Print(other = true, name = {= "x2hr".into() =}) } diff --git a/test/Rust/src/CtorParamSimple.lf b/test/Rust/src/CtorParamSimple.lf index bbf38c04a0..09a3046af3 100644 --- a/test/Rust/src/CtorParamSimple.lf +++ b/test/Rust/src/CtorParamSimple.lf @@ -1,14 +1,14 @@ target Rust reactor Print(value: i32 = 42) { - state v: i32 = value + state v: i32 = value - reaction(startup) {= - assert_eq!(self.v, 23); - println!("success"); - =} + reaction(startup) {= + assert_eq!(self.v, 23); + println!("success"); + =} } main reactor CtorParamSimple { - p = new Print(value = 23) + p = new Print(value = 23) } diff --git a/test/Rust/src/DependencyOnChildPort.lf b/test/Rust/src/DependencyOnChildPort.lf index ed8b6b2120..2758af8604 100644 --- a/test/Rust/src/DependencyOnChildPort.lf +++ b/test/Rust/src/DependencyOnChildPort.lf @@ -2,28 +2,26 @@ target Rust reactor Box { - input inp: u32 - output out: u32 + input inp: u32 + output out: u32 - inp -> out + inp -> out } main reactor { - state done: bool = false + state done: bool = false - box0 = new Box() - box1 = new Box() + box0 = new Box() + box1 = new Box() - box0.out -> box1.inp + box0.out -> box1.inp - reaction(startup) -> box0.inp {= ctx.set(box0__inp, 444); =} + reaction(startup) -> box0.inp {= ctx.set(box0__inp, 444); =} - reaction(box1.out) {= - assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; - =} + reaction(box1.out) {= assert!(ctx.get_elapsed_logical_time().is_zero()); self.done = true; =} - reaction(shutdown) {= - assert!(self.done, "reaction was not executed"); - println!("success"); - =} + reaction(shutdown) {= + assert!(self.done, "reaction was not executed"); + println!("success"); + =} } diff --git a/test/Rust/src/DependencyUseOnLogicalAction.lf b/test/Rust/src/DependencyUseOnLogicalAction.lf index 6278ec76f7..f1b244901e 100644 --- a/test/Rust/src/DependencyUseOnLogicalAction.lf +++ b/test/Rust/src/DependencyUseOnLogicalAction.lf @@ -1,47 +1,47 @@ /** Test that use-dependencies may be declared on logical actions and timers. */ target Rust { - timeout: 10 msec + timeout: 10 msec } main reactor { - logical action clock: u32 - - logical action a - - timer t(0, 2 msec) - - state tick: u32 = 0 - - reaction(startup) -> clock, a {= - ctx.schedule(a, after!(3 ms)); // out of order on purpose - ctx.schedule(a, after!(1 ms)); - ctx.schedule(a, after!(5 ms)); - - // not scheduled on milli 1 (action is) - ctx.schedule_with_v(clock, Some(2), after!(2 ms)); - ctx.schedule_with_v(clock, Some(3), after!(3 ms)); - ctx.schedule_with_v(clock, Some(4), after!(4 ms)); - ctx.schedule_with_v(clock, Some(5), after!(5 ms)); - // not scheduled on milli 6 (timer is) - =} - - reaction(clock) a, t {= - match ctx.get(clock) { - Some(2) | Some(4) => { - assert!(ctx.is_present(t)); // t is there on even millis - assert!(!ctx.is_present(a)); // - }, - Some(3) | Some(5) => { - assert!(!ctx.is_present(t)); - assert!(ctx.is_present(a)); - }, - it => unreachable!("{:?}", it) - } - self.tick += 1; - =} - - reaction(shutdown) {= - assert_eq!(self.tick, 4); - println!("success"); - =} + logical action clock: u32 + + logical action a + + timer t(0, 2 msec) + + state tick: u32 = 0 + + reaction(startup) -> clock, a {= + ctx.schedule(a, after!(3 ms)); // out of order on purpose + ctx.schedule(a, after!(1 ms)); + ctx.schedule(a, after!(5 ms)); + + // not scheduled on milli 1 (action is) + ctx.schedule_with_v(clock, Some(2), after!(2 ms)); + ctx.schedule_with_v(clock, Some(3), after!(3 ms)); + ctx.schedule_with_v(clock, Some(4), after!(4 ms)); + ctx.schedule_with_v(clock, Some(5), after!(5 ms)); + // not scheduled on milli 6 (timer is) + =} + + reaction(clock) a, t {= + match ctx.get(clock) { + Some(2) | Some(4) => { + assert!(ctx.is_present(t)); // t is there on even millis + assert!(!ctx.is_present(a)); // + }, + Some(3) | Some(5) => { + assert!(!ctx.is_present(t)); + assert!(ctx.is_present(a)); + }, + it => unreachable!("{:?}", it) + } + self.tick += 1; + =} + + reaction(shutdown) {= + assert_eq!(self.tick, 4); + println!("success"); + =} } diff --git a/test/Rust/src/FloatLiteral.lf b/test/Rust/src/FloatLiteral.lf index b1dd37ca5e..a0d61c9fdf 100644 --- a/test/Rust/src/FloatLiteral.lf +++ b/test/Rust/src/FloatLiteral.lf @@ -1,15 +1,14 @@ target Rust -// This test verifies that floating-point literals are handled correctly. -main reactor { - state N: f64 = 6.0221409e+23 - state charge: f64 = -1.6021766E-19 - state minus_epsilon: f64 = -.01e0 - state expected: f64 = .964853323188E5 +main reactor { // This test verifies that floating-point literals are handled correctly. + state N: f64 = 6.0221409e+23 + state charge: f64 = -1.6021766E-19 + state minus_epsilon: f64 = -.01e0 + state expected: f64 = .964853323188E5 - reaction(startup) {= - let F = - self.N * self.charge; - println!("The Faraday constant is roughly {}.", F); - assert!((F - self.expected).abs() < (self.minus_epsilon).abs()); - =} + reaction(startup) {= + let F = - self.N * self.charge; + println!("The Faraday constant is roughly {}.", F); + assert!((F - self.expected).abs() < (self.minus_epsilon).abs()); + =} } diff --git a/test/Rust/src/MainReactorParam.lf b/test/Rust/src/MainReactorParam.lf index 0c9f189548..2081466a37 100644 --- a/test/Rust/src/MainReactorParam.lf +++ b/test/Rust/src/MainReactorParam.lf @@ -1,8 +1,8 @@ target Rust main reactor(one: u64 = 1152921504606846976, two: u64 = {= 1 << 60 =}) { - state one = one - state two = two + state one = one + state two = two - reaction(startup) {= assert_eq!(self.one, self.two); =} + reaction(startup) {= assert_eq!(self.one, self.two); =} } diff --git a/test/Rust/src/MovingAverage.lf b/test/Rust/src/MovingAverage.lf index 3dcbb69c98..22d10cabe0 100644 --- a/test/Rust/src/MovingAverage.lf +++ b/test/Rust/src/MovingAverage.lf @@ -1,66 +1,64 @@ -// Demonstration of a state variable that is a fixed size list. The -// MovingAverage reactor computes the moving average of the last four inputs and -// produces that as output. The source is a counting sequence. +// Demonstration of a state variable that is a fixed size list. The MovingAverage reactor computes +// the moving average of the last four inputs and produces that as output. The source is a counting +// sequence. target Rust { - timeout: 50 msec + timeout: 50 msec } reactor Source { - output out: f64 - state count: u32 = 0 - timer clock(0, 10 msec) + output out: f64 + state count: u32 = 0 + timer clock(0, 10 msec) - reaction(clock) -> out {= - ctx.set(out, self.count.into()); - self.count += 1; - =} + reaction(clock) -> out {= + ctx.set(out, self.count.into()); + self.count += 1; + =} } reactor MovingAverageImpl { - state delay_line: {= [f64 ; 4] =} = {= [ 0.0 ; 4 ] =} - state index: usize = 0 - input in_: f64 - output out: f64 + state delay_line: {= [f64 ; 4] =} = {= [ 0.0 ; 4 ] =} + state index: usize = 0 + input in_: f64 + output out: f64 - reaction(in_) -> out {= - let in_ = ctx.get(in_).unwrap(); + reaction(in_) -> out {= + let in_ = ctx.get(in_).unwrap(); - // Insert the input in the delay line. - self.delay_line[self.index] = in_; - // Update the index for the next input. - self.index = (self.index + 1) % 4; + // Insert the input in the delay line. + self.delay_line[self.index] = in_; + // Update the index for the next input. + self.index = (self.index + 1) % 4; - // Calculate the output. - let sum: f64 = self.delay_line.iter().sum(); - ctx.set(out, sum / 4.0); - =} + // Calculate the output. + let sum: f64 = self.delay_line.iter().sum(); + ctx.set(out, sum / 4.0); + =} } reactor Print { - input in_: f64 - state count: usize = 0 + input in_: f64 + state count: usize = 0 - preamble {= - const EXPECTED: [ f64 ; 6 ] = [0.0, 0.25, 0.75, 1.5, 2.5, 3.5]; - =} + preamble {= const EXPECTED: [ f64 ; 6 ] = [0.0, 0.25, 0.75, 1.5, 2.5, 3.5]; =} - reaction(in_) {= - let in_ = ctx.get(in_).unwrap(); - println!("Received {}", in_); - assert_eq!(in_, EXPECTED[self.count]); - self.count += 1; - =} + reaction(in_) {= + let in_ = ctx.get(in_).unwrap(); + println!("Received {}", in_); + assert_eq!(in_, EXPECTED[self.count]); + self.count += 1; + =} - reaction(shutdown) {= - assert_eq!(self.count, 6); - println!("Success."); - =} + reaction(shutdown) {= + assert_eq!(self.count, 6); + println!("Success."); + =} } main reactor MovingAverage { - s = new Source() - m = new MovingAverageImpl() - p = new Print() - s.out -> m.in_ - m.out -> p.in_ + s = new Source() + m = new MovingAverageImpl() + p = new Print() + s.out -> m.in_ + m.out -> p.in_ } diff --git a/test/Rust/src/NativeListsAndTimes.lf b/test/Rust/src/NativeListsAndTimes.lf index 79fd56e004..21c44e17d8 100644 --- a/test/Rust/src/NativeListsAndTimes.lf +++ b/test/Rust/src/NativeListsAndTimes.lf @@ -1,46 +1,45 @@ target Rust -// This test passes if it is successfully compiled into valid target code. -reactor Foo( - x: i32 = 0, - y: time = 0, // Units are missing but not required - z = 1 msec, // Type is missing but not required - p: i32[](1, 2, 3, 4), // List of integers - p2: i32[] = {= vec![1] =}, // List of integers with single element - // todo // p2: i32[](1), // List of integers with single element p3: - // i32[](), // Empty list of integers List of time values - q: Vec(1 msec, 2 msec, 3 msec), - g: time[](1 msec, 2 msec) // List of time values +reactor Foo( // This test passes if it is successfully compiled into valid target code. + x: i32 = 0, + y: time = 0, // Units are missing but not required + z = 1 msec, // Type is missing but not required + p: i32[](1, 2, 3, 4), // List of integers + p2: i32[] = {= vec![1] =}, // List of integers with single element + // todo // p2: i32[](1), // List of integers with single element p3: i32[](), // Empty list of + // integers List of time values + q: Vec(1 msec, 2 msec, 3 msec), + g: time[](1 msec, 2 msec) // List of time values ) { - state s: time = y // Reference to explicitly typed time parameter - state t: time = z // Reference to implicitly typed time parameter - state v: bool // Uninitialized boolean state variable - state w: time // Uninitialized time state variable - timer tick(0) // Units missing but not required - timer tock(1 sec) // Implicit type time - timer toe(z) // Implicit type time - /** - * fixme following should be equivalent: - * - state baz(p); - * - state baz: i32[4](p); - * - state baz: i32[4]({=p=}); - * - * because the initializer is the same modulo fat braces - */ - // state baz(p); // Implicit type i32[] fixme this interplays badly with - // syntax for array init Implicit type time - state period = z - state times: Vec>(q, g) // a list of lists + state s: time = y // Reference to explicitly typed time parameter + state t: time = z // Reference to implicitly typed time parameter + state v: bool // Uninitialized boolean state variable + state w: time // Uninitialized time state variable + timer tick(0) // Units missing but not required + timer tock(1 sec) // Implicit type time + timer toe(z) // Implicit type time + /** + * fixme following should be equivalent: + * - state baz(p); + * - state baz: i32[4](p); + * - state baz: i32[4]({=p=}); + * + * because the initializer is the same modulo fat braces + */ + // state baz(p); // Implicit type i32[] fixme this interplays badly with syntax for array init + // Implicit type time + state period = z + state times: Vec>(q, g) // a list of lists - /** - * reactor Foo (p: i32[](1, 2)) { state baz(p); // Implicit type i32[] state - * baz({=p=}); // Implicit type i32[] } - */ - reaction(tick) {= - // Target code - =} + /** + * reactor Foo (p: i32[](1, 2)) { state baz(p); // Implicit type i32[] state baz({=p=}); // + * Implicit type i32[] } + */ + reaction(tick) {= + // Target code + =} } main reactor NativeListsAndTimes { - foo = new Foo() + foo = new Foo() } diff --git a/test/Rust/src/PortConnectionInSelfInChild.lf b/test/Rust/src/PortConnectionInSelfInChild.lf index 7fd66783f1..8deee3f39c 100644 --- a/test/Rust/src/PortConnectionInSelfInChild.lf +++ b/test/Rust/src/PortConnectionInSelfInChild.lf @@ -2,31 +2,31 @@ target Rust reactor Child { - input inp: i32 - state done: bool = false + input inp: i32 + state done: bool = false - reaction(inp) {= - assert_eq!(ctx.get(inp), Some(76600)); - self.done = true; - =} + reaction(inp) {= + assert_eq!(ctx.get(inp), Some(76600)); + self.done = true; + =} - reaction(shutdown) {= - assert!(self.done); - println!("Success") - =} + reaction(shutdown) {= + assert!(self.done); + println!("Success") + =} } reactor Parent { - input inp: i32 - child = new Child() - inp -> child.inp + input inp: i32 + child = new Child() + inp -> child.inp } main reactor { - parent = new Parent() + parent = new Parent() - reaction(startup) -> parent.inp {= - ctx.set(parent__inp, 76600); - println!("out := 76600") - =} + reaction(startup) -> parent.inp {= + ctx.set(parent__inp, 76600); + println!("out := 76600") + =} } diff --git a/test/Rust/src/PortConnectionInSelfOutSelf.lf b/test/Rust/src/PortConnectionInSelfOutSelf.lf index 2e33b0e498..d398e89f0f 100644 --- a/test/Rust/src/PortConnectionInSelfOutSelf.lf +++ b/test/Rust/src/PortConnectionInSelfOutSelf.lf @@ -2,38 +2,38 @@ target Rust reactor Source { - output out: i32 + output out: i32 - reaction(startup) -> out {= - ctx.set(out, 76600); - println!("out := 76600") - =} + reaction(startup) -> out {= + ctx.set(out, 76600); + println!("out := 76600") + =} } reactor TestCase { - input inp: i32 - output out: i32 - inp -> out + input inp: i32 + output out: i32 + inp -> out } reactor Sink { - input inp: i32 - state done: bool = false + input inp: i32 + state done: bool = false - reaction(inp) {= - assert_eq!(ctx.get(inp), Some(76600)); - println!("Success"); - self.done = true; - =} + reaction(inp) {= + assert_eq!(ctx.get(inp), Some(76600)); + println!("Success"); + self.done = true; + =} - reaction(shutdown) {= assert!(self.done, "reaction was not executed") =} + reaction(shutdown) {= assert!(self.done, "reaction was not executed") =} } main reactor { - source = new Source() - middle = new TestCase() - sink = new Sink() + source = new Source() + middle = new TestCase() + sink = new Sink() - source.out -> middle.inp - middle.out -> sink.inp + source.out -> middle.inp + middle.out -> sink.inp } diff --git a/test/Rust/src/PortConnectionOutChildOutSelf.lf b/test/Rust/src/PortConnectionOutChildOutSelf.lf index 4d58153d97..6935eb4256 100644 --- a/test/Rust/src/PortConnectionOutChildOutSelf.lf +++ b/test/Rust/src/PortConnectionOutChildOutSelf.lf @@ -2,44 +2,44 @@ target Rust reactor Child { - output out: i32 + output out: i32 - reaction(startup) -> out {= - ctx.set(out, 76600); - println!("out := 76600") - =} + reaction(startup) -> out {= + ctx.set(out, 76600); + println!("out := 76600") + =} } reactor Parent { - output out: i32 + output out: i32 - child = new Child() - child.out -> out + child = new Child() + child.out -> out } reactor Sink { - input inp: i32 - state done: bool = false + input inp: i32 + state done: bool = false - reaction(inp) {= - assert_eq!(ctx.get(inp), Some(76600)); - println!("Success"); - self.done = true; - =} + reaction(inp) {= + assert_eq!(ctx.get(inp), Some(76600)); + println!("Success"); + self.done = true; + =} - reaction(shutdown) {= assert!(self.done, "reaction was not executed") =} + reaction(shutdown) {= assert!(self.done, "reaction was not executed") =} } main reactor { - parent = new Parent() + parent = new Parent() - state done: bool = false + state done: bool = false - reaction(parent.out) {= - assert_eq!(ctx.get(parent__out), Some(76600)); - println!("Success"); - self.done = true; - =} + reaction(parent.out) {= + assert_eq!(ctx.get(parent__out), Some(76600)); + println!("Success"); + self.done = true; + =} - reaction(shutdown) {= assert!(self.done, "reaction was not executed") =} + reaction(shutdown) {= assert!(self.done, "reaction was not executed") =} } diff --git a/test/Rust/src/PortRefCleanup.lf b/test/Rust/src/PortRefCleanup.lf index 30573ceee9..3704998794 100644 --- a/test/Rust/src/PortRefCleanup.lf +++ b/test/Rust/src/PortRefCleanup.lf @@ -2,39 +2,39 @@ target Rust reactor Box { - input inp: u32 - output out: u32 + input inp: u32 + output out: u32 - inp -> out + inp -> out } main reactor { - boxr = new Box() - - timer t1(0) - timer t2(15 msec) - - state reaction_num: u32 = 0 - state done: bool = false - - reaction(t1) -> boxr.inp {= - ctx.set(boxr__inp, 150); - self.reaction_num += 1; - =} - - reaction(boxr.out, t2) {= - if self.reaction_num == 1 { - assert!(matches!(ctx.get(boxr__out), Some(150))); - } else { - assert_eq!(self.reaction_num, 2); - assert!(ctx.get(boxr__out).is_none(), "value should have been cleaned up"); - self.done = true; - } - self.reaction_num += 1; - =} - - reaction(shutdown) {= - assert!(self.done, "reaction was not executed"); - println!("success"); - =} + boxr = new Box() + + timer t1(0) + timer t2(15 msec) + + state reaction_num: u32 = 0 + state done: bool = false + + reaction(t1) -> boxr.inp {= + ctx.set(boxr__inp, 150); + self.reaction_num += 1; + =} + + reaction(boxr.out, t2) {= + if self.reaction_num == 1 { + assert!(matches!(ctx.get(boxr__out), Some(150))); + } else { + assert_eq!(self.reaction_num, 2); + assert!(ctx.get(boxr__out).is_none(), "value should have been cleaned up"); + self.done = true; + } + self.reaction_num += 1; + =} + + reaction(shutdown) {= + assert!(self.done, "reaction was not executed"); + println!("success"); + =} } diff --git a/test/Rust/src/PortValueCleanup.lf b/test/Rust/src/PortValueCleanup.lf index 9a11372cfb..5200956cdc 100644 --- a/test/Rust/src/PortValueCleanup.lf +++ b/test/Rust/src/PortValueCleanup.lf @@ -2,38 +2,38 @@ target Rust reactor Source { - output out: u32 + output out: u32 - reaction(startup) -> out {= ctx.set(out, 150); =} + reaction(startup) -> out {= ctx.set(out, 150); =} } reactor Sink { - timer t2(15 msec) - - input in: u32 - state reaction_num: u32 = 0 - state done: bool = false - - reaction(in, t2) {= - if self.reaction_num == 0 { - assert!(matches!(ctx.get(r#in), Some(150))); - } else { - assert_eq!(self.reaction_num, 1); - assert!(ctx.get(r#in).is_none(), "value should have been cleaned up"); - self.done = true; - } - self.reaction_num += 1; - =} - - reaction(shutdown) {= - assert!(self.done, "reaction was not executed"); - println!("success"); - =} + timer t2(15 msec) + + input in: u32 + state reaction_num: u32 = 0 + state done: bool = false + + reaction(in, t2) {= + if self.reaction_num == 0 { + assert!(matches!(ctx.get(r#in), Some(150))); + } else { + assert_eq!(self.reaction_num, 1); + assert!(ctx.get(r#in).is_none(), "value should have been cleaned up"); + self.done = true; + } + self.reaction_num += 1; + =} + + reaction(shutdown) {= + assert!(self.done, "reaction was not executed"); + println!("success"); + =} } main reactor { - source = new Source() - sink = new Sink() + source = new Source() + sink = new Sink() - source.out -> sink.in + source.out -> sink.in } diff --git a/test/Rust/src/ReservedKeywords.lf b/test/Rust/src/ReservedKeywords.lf index 5d30ba63a4..33e4df4586 100644 --- a/test/Rust/src/ReservedKeywords.lf +++ b/test/Rust/src/ReservedKeywords.lf @@ -1,26 +1,25 @@ -// Tests that rust keywords may be used as identifiers in LF and are properly -// escaped by the emitter +// Tests that rust keywords may be used as identifiers in LF and are properly escaped by the emitter target Rust reactor box { - input in: u32 - output struct: u32 + input in: u32 + output struct: u32 - in -> struct + in -> struct - state foo: bool = true // not escaped + state foo: bool = true // not escaped - reaction(in) {= - ctx.get(r#in); - =} + reaction(in) {= + ctx.get(r#in); + =} } main reactor ReservedKeywords(struct: u32 = 0) { - box = new box() + box = new box() - timer t1(0) - timer t2(15 msec) + timer t1(0) + timer t2(15 msec) - // not in types, this wouldn't be useful. state reaction_num: struct(0); - reaction(box.struct, t2) {= =} + // not in types, this wouldn't be useful. state reaction_num: struct(0); + reaction(box.struct, t2) {= =} } diff --git a/test/Rust/src/StateInitializerVisibility.lf b/test/Rust/src/StateInitializerVisibility.lf index d192f0ca98..276fd54027 100644 --- a/test/Rust/src/StateInitializerVisibility.lf +++ b/test/Rust/src/StateInitializerVisibility.lf @@ -1,14 +1,14 @@ -// Tests that state vars are accessible within initializers of other state vars -// declared further down. +// Tests that state vars are accessible within initializers of other state vars declared further +// down. target Rust main reactor { - state foo: u32 = 123 - state x: u32 = {= *&foo =} + state foo: u32 = 123 + state x: u32 = {= *&foo =} - reaction(startup) {= - assert_eq!(self.x, self.foo); - assert_eq!(self.x, 123); - println!("success"); - =} + reaction(startup) {= + assert_eq!(self.x, self.foo); + assert_eq!(self.x, 123); + println!("success"); + =} } diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index c43f8c30ff..b70a034c12 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -4,83 +4,82 @@ * @author Soroush Bateni */ target Rust { - timeout: 11 msec + timeout: 11 msec } /** - * @param take_a_break_after: Indicates how many messages are sent in - * consecutive superdense time - * @param break_interval: Determines how long the reactor should take a break - * after sending take_a_break_after messages. + * @param take_a_break_after: Indicates how many messages are sent in consecutive superdense time + * @param break_interval: Determines how long the reactor should take a break after sending + * take_a_break_after messages. */ reactor Sender(take_a_break_after: u32 = 10, break_interval: time = 400 msec) { - output out: u32 - logical action act - state sent_messages: u32 = 0 + output out: u32 + logical action act + state sent_messages: u32 = 0 - state take_a_break_after = take_a_break_after - state break_interval = break_interval + state take_a_break_after = take_a_break_after + state break_interval = break_interval - reaction(startup, act) -> act, out {= - // Send a message on out - println!("At tag {} sending value {}.\n", ctx.get_tag(), self.sent_messages); + reaction(startup, act) -> act, out {= + // Send a message on out + println!("At tag {} sending value {}.\n", ctx.get_tag(), self.sent_messages); - ctx.set(out, self.sent_messages); - self.sent_messages += 1; + ctx.set(out, self.sent_messages); + self.sent_messages += 1; - if self.sent_messages < self.take_a_break_after { - ctx.schedule(act, Asap); - } else { - // Take a break - self.sent_messages = 0; - ctx.schedule(act, After(self.break_interval)); - } - =} + if self.sent_messages < self.take_a_break_after { + ctx.schedule(act, Asap); + } else { + // Take a break + self.sent_messages = 0; + ctx.schedule(act, After(self.break_interval)); + } + =} } reactor Consumer { - input in_: u32 - state reaction_invoked_correctly: bool = false + input in_: u32 + state reaction_invoked_correctly: bool = false - reaction(in_) {= - let current_tag = ctx.get_tag(); + reaction(in_) {= + let current_tag = ctx.get_tag(); - if current_tag > tag!(T0 + 10 ms, 9) { - // The reaction should not have been called at tags larger than (10 msec, 9) - panic!("ERROR: Invoked reaction(in) at tag bigger than shutdown."); - } else if current_tag == tag!(T0 + 10 ms, 8) { - // Call request_stop() at relative tag (10 msec, 8) - println!("Requesting stop."); - ctx.request_stop(Asap); - return; - } else if current_tag == tag!(T0 + 10 ms, 9) { - // Check that this reaction is indeed also triggered at (10 msec, 9) - self.reaction_invoked_correctly = true; - return; - } - println!("Tag is {}.", current_tag); - =} + if current_tag > tag!(T0 + 10 ms, 9) { + // The reaction should not have been called at tags larger than (10 msec, 9) + panic!("ERROR: Invoked reaction(in) at tag bigger than shutdown."); + } else if current_tag == tag!(T0 + 10 ms, 8) { + // Call request_stop() at relative tag (10 msec, 8) + println!("Requesting stop."); + ctx.request_stop(Asap); + return; + } else if current_tag == tag!(T0 + 10 ms, 9) { + // Check that this reaction is indeed also triggered at (10 msec, 9) + self.reaction_invoked_correctly = true; + return; + } + println!("Tag is {}.", current_tag); + =} - reaction(shutdown) {= - let current_tag = ctx.get_tag(); + reaction(shutdown) {= + let current_tag = ctx.get_tag(); - println!("Shutdown invoked at tag {}.\n", current_tag); + println!("Shutdown invoked at tag {}.\n", current_tag); - // Check to see if shutdown is called at relative tag (10 msec, 9) - if current_tag == tag!(T0 + 10 ms, 9) && self.reaction_invoked_correctly { - println!("SUCCESS: successfully enforced stop."); - } else if current_tag > tag!(T0 + 10 ms, 9) { - panic!("ERROR: Shutdown invoked at tag {}. Failed to enforce timeout at (T0 + 10ms, 9).", current_tag); - } else if !self.reaction_invoked_correctly { - // Check to see if reactions were called correctly - panic!("ERROR: Failed to invoke reaction(in) at tag {}.", current_tag); - } - =} + // Check to see if shutdown is called at relative tag (10 msec, 9) + if current_tag == tag!(T0 + 10 ms, 9) && self.reaction_invoked_correctly { + println!("SUCCESS: successfully enforced stop."); + } else if current_tag > tag!(T0 + 10 ms, 9) { + panic!("ERROR: Shutdown invoked at tag {}. Failed to enforce timeout at (T0 + 10ms, 9).", current_tag); + } else if !self.reaction_invoked_correctly { + // Check to see if reactions were called correctly + panic!("ERROR: Failed to invoke reaction(in) at tag {}.", current_tag); + } + =} } main reactor Stop { - consumer = new Consumer() - producer = new Sender(break_interval = 1 msec) + consumer = new Consumer() + producer = new Sender(break_interval = 1 msec) - producer.out -> consumer.in_ + producer.out -> consumer.in_ } diff --git a/test/Rust/src/StopIdempotence.lf b/test/Rust/src/StopIdempotence.lf index 1f79347758..c5f4dcf342 100644 --- a/test/Rust/src/StopIdempotence.lf +++ b/test/Rust/src/StopIdempotence.lf @@ -1,21 +1,21 @@ /** Tests that ports are cleaned up before the shutdown wave executes. */ target Rust { - timeout: 30 msec + timeout: 30 msec } main reactor StopIdempotence { - state count: u32 = 0 + state count: u32 = 0 - reaction(startup) {= - ctx.request_stop(Asap); // requested for (T0, 1) - assert_tag_is!(ctx, T0); - =} + reaction(startup) {= + ctx.request_stop(Asap); // requested for (T0, 1) + assert_tag_is!(ctx, T0); + =} - reaction(shutdown) {= - ctx.request_stop(Asap); // requested for (T0, 1) - assert_eq!(self.count, 0, "Shutdown was run several times"); - self.count += 1; - assert_tag_is!(ctx, (T0, 1)); - println!("success"); - =} + reaction(shutdown) {= + ctx.request_stop(Asap); // requested for (T0, 1) + assert_eq!(self.count, 0, "Shutdown was run several times"); + self.count += 1; + assert_tag_is!(ctx, (T0, 1)); + println!("success"); + =} } diff --git a/test/Rust/src/StopTimeoutExact.lf b/test/Rust/src/StopTimeoutExact.lf index 2b9eb85cda..0261e8b0d9 100644 --- a/test/Rust/src/StopTimeoutExact.lf +++ b/test/Rust/src/StopTimeoutExact.lf @@ -1,25 +1,25 @@ /** - * Tests that when a timeout coincides with a scheduled event, all scheduled - * reactions are properly executed (in addition to the shutdown ones). + * Tests that when a timeout coincides with a scheduled event, all scheduled reactions are properly + * executed (in addition to the shutdown ones). */ target Rust { - timeout: 50 msec + timeout: 50 msec } main reactor StopTimeoutExact { - timer t(0, 10 msec) // the fifth triggering will coincide with the timeout + timer t(0, 10 msec) // the fifth triggering will coincide with the timeout - state reacted_on_shutdown: bool = false + state reacted_on_shutdown: bool = false - reaction(t) {= - if ctx.get_tag() == tag!(T0 + 50 ms) { - self.reacted_on_shutdown = true; - } - =} + reaction(t) {= + if ctx.get_tag() == tag!(T0 + 50 ms) { + self.reacted_on_shutdown = true; + } + =} - reaction(shutdown) {= - assert_tag_is!(ctx, T0 + 50 ms); - assert!(self.reacted_on_shutdown, "Reaction was not executed"); - println!("Success!"); // if this is not printed the test failed - =} + reaction(shutdown) {= + assert_tag_is!(ctx, T0 + 50 ms); + assert!(self.reacted_on_shutdown, "Reaction was not executed"); + println!("Success!"); // if this is not printed the test failed + =} } diff --git a/test/Rust/src/StructAsState.lf b/test/Rust/src/StructAsState.lf index 9b35e7a3fb..574d3ff59f 100644 --- a/test/Rust/src/StructAsState.lf +++ b/test/Rust/src/StructAsState.lf @@ -1,27 +1,27 @@ -// Check that a state variable can have a statically initialized struct as a -// value. Check how preambles work +// Check that a state variable can have a statically initialized struct as a value. Check how +// preambles work target Rust main reactor StructAsState { - preamble {= - struct Hello { - name: String, - value: i32, - } - =} - /** - * notice this uses parentheses todo - * - state s: Hello(name= "Earth".into(), value= 42); - * - state s: Hello(name: "Earth".into(), value: 42); - * - state s: Hello { name: "Earth".into(), value: 42 }; - */ - state s: Hello = {= Hello { name: "Earth".into(), value: 42 } =} + preamble {= + struct Hello { + name: String, + value: i32, + } + =} + /** + * notice this uses parentheses todo + * - state s: Hello(name= "Earth".into(), value= 42); + * - state s: Hello(name: "Earth".into(), value: 42); + * - state s: Hello { name: "Earth".into(), value: 42 }; + */ + state s: Hello = {= Hello { name: "Earth".into(), value: 42 } =} - reaction(startup) {= - println!("State s.name=\"{}\", s.value={}.", self.s.name, self.s.value); - if self.s.value != 42 { - eprintln!("FAILED: Expected 42."); - std::process::exit(1); - } - =} + reaction(startup) {= + println!("State s.name=\"{}\", s.value={}.", self.s.name, self.s.value); + if self.s.value != 42 { + eprintln!("FAILED: Expected 42."); + std::process::exit(1); + } + =} } diff --git a/test/Rust/src/StructAsType.lf b/test/Rust/src/StructAsType.lf index 0c8ed51456..93450959b5 100644 --- a/test/Rust/src/StructAsType.lf +++ b/test/Rust/src/StructAsType.lf @@ -2,38 +2,38 @@ target Rust reactor Source { - output out: Hello + output out: Hello - preamble {= - pub struct Hello { - pub name: String, - pub value: i32, - } - =} + preamble {= + pub struct Hello { + pub name: String, + pub value: i32, + } + =} - reaction(startup) -> out {= - // Create the struct on the stack and then copy - // it to the output - ctx.set(out, Hello { name: "Earth".into(), value: 42 }) - =} + reaction(startup) -> out {= + // Create the struct on the stack and then copy + // it to the output + ctx.set(out, Hello { name: "Earth".into(), value: 42 }) + =} } reactor Print(expected: i32 = 42) { // expected parameter is for testing. - input inp: {= super::source::Hello =} - state expected: i32 = expected + input inp: {= super::source::Hello =} + state expected: i32 = expected - reaction(inp) {= - ctx.use_ref_opt(inp, |hello| { - println!("Received: name=\"{}\", value={}.", hello.name, hello.value); - if hello.value != self.expected { - panic!("ERROR: Expected value to be {}.\n", self.expected); - } - }); - =} + reaction(inp) {= + ctx.use_ref_opt(inp, |hello| { + println!("Received: name=\"{}\", value={}.", hello.name, hello.value); + if hello.value != self.expected { + panic!("ERROR: Expected value to be {}.\n", self.expected); + } + }); + =} } main reactor StructAsType { - s = new Source() - p = new Print() - s.out -> p.inp + s = new Source() + p = new Print() + s.out -> p.inp } diff --git a/test/Rust/src/TimeState.lf b/test/Rust/src/TimeState.lf index efffb00c2f..3de9934e28 100644 --- a/test/Rust/src/TimeState.lf +++ b/test/Rust/src/TimeState.lf @@ -1,11 +1,11 @@ target Rust reactor Foo { - state baz: time = 500 msec + state baz: time = 500 msec - reaction(startup) {= assert_eq!(500, self.baz.as_millis()); =} + reaction(startup) {= assert_eq!(500, self.baz.as_millis()); =} } main reactor TimeState { - a = new Foo() + a = new Foo() } diff --git a/test/Rust/src/TimerDefaults.lf b/test/Rust/src/TimerDefaults.lf index bbc920bf4a..f6f02b1e49 100644 --- a/test/Rust/src/TimerDefaults.lf +++ b/test/Rust/src/TimerDefaults.lf @@ -1,12 +1,12 @@ target Rust main reactor TimerDefaults { - state i: i32 = 0 - timer t + state i: i32 = 0 + timer t - reaction(t) {= - assert_tag_is!(ctx, T0); - println!("Tick {} after {} ms", self.i, ctx.get_elapsed_physical_time().as_millis()); - self.i += 1; - =} + reaction(t) {= + assert_tag_is!(ctx, T0); + println!("Tick {} after {} ms", self.i, ctx.get_elapsed_physical_time().as_millis()); + self.i += 1; + =} } diff --git a/test/Rust/src/TimerIsPresent.lf b/test/Rust/src/TimerIsPresent.lf index 1e87c11f51..18977c42cf 100644 --- a/test/Rust/src/TimerIsPresent.lf +++ b/test/Rust/src/TimerIsPresent.lf @@ -1,52 +1,52 @@ // Tests the is_present function for timers. target Rust { - timeout: 7 msec + timeout: 7 msec } main reactor { - timer a(0, 5 msec) - timer b(1 msec, 5 msec) - timer c(1 msec) + timer a(0, 5 msec) + timer b(1 msec, 5 msec) + timer c(1 msec) - state success: bool = false - state tick: u32 = 0 + state success: bool = false + state tick: u32 = 0 - reaction(startup, a, b, c) {= - match self.tick { - 0 => { // startup - assert_tag_is!(ctx, T0); - assert!(ctx.is_present(a)); - assert!(!ctx.is_present(b)); - assert!(!ctx.is_present(c)); - }, - 1 => { // 1 msec - assert_tag_is!(ctx, T0 + 1 ms); - assert!(!ctx.is_present(a)); - assert!(ctx.is_present(b)); - assert!(ctx.is_present(c)); - }, - 2 => { // 5 msec (a triggers) - assert_tag_is!(ctx, T0 + 5 ms); - assert!(ctx.is_present(a)); - assert!(!ctx.is_present(b)); - assert!(!ctx.is_present(c)); - }, - 3 => { // 6 msec (b triggers) - assert_tag_is!(ctx, T0 + 6 ms); - assert!(!ctx.is_present(a)); - assert!(ctx.is_present(b)); - assert!(!ctx.is_present(c)); - self.success = true; - }, - _ => { - unreachable!("unexpected reaction invocation"); - } - } - self.tick += 1; - =} + reaction(startup, a, b, c) {= + match self.tick { + 0 => { // startup + assert_tag_is!(ctx, T0); + assert!(ctx.is_present(a)); + assert!(!ctx.is_present(b)); + assert!(!ctx.is_present(c)); + }, + 1 => { // 1 msec + assert_tag_is!(ctx, T0 + 1 ms); + assert!(!ctx.is_present(a)); + assert!(ctx.is_present(b)); + assert!(ctx.is_present(c)); + }, + 2 => { // 5 msec (a triggers) + assert_tag_is!(ctx, T0 + 5 ms); + assert!(ctx.is_present(a)); + assert!(!ctx.is_present(b)); + assert!(!ctx.is_present(c)); + }, + 3 => { // 6 msec (b triggers) + assert_tag_is!(ctx, T0 + 6 ms); + assert!(!ctx.is_present(a)); + assert!(ctx.is_present(b)); + assert!(!ctx.is_present(c)); + self.success = true; + }, + _ => { + unreachable!("unexpected reaction invocation"); + } + } + self.tick += 1; + =} - reaction(shutdown) {= - assert!(self.success); - println!("success"); - =} + reaction(shutdown) {= + assert!(self.success); + println!("success"); + =} } diff --git a/test/Rust/src/TimerPeriodic.lf b/test/Rust/src/TimerPeriodic.lf index c6dce10a73..2015bb9d19 100644 --- a/test/Rust/src/TimerPeriodic.lf +++ b/test/Rust/src/TimerPeriodic.lf @@ -1,18 +1,18 @@ target Rust { - timeout: 15 msec // fast: true + timeout: 15 msec // fast: true } main reactor TimerPeriodic { - state i: i32 = 0 - timer t2(0, 3 msec) + state i: i32 = 0 + timer t2(0, 3 msec) - reaction(t2) {= - println!("Tick {} at {}", self.i, ctx.get_tag()); - self.i += 1; - =} + reaction(t2) {= + println!("Tick {} at {}", self.i, ctx.get_tag()); + self.i += 1; + =} - reaction(shutdown) {= - assert_eq!(self.i, 6); - println!("success"); - =} + reaction(shutdown) {= + assert_eq!(self.i, 6); + println!("success"); + =} } diff --git a/test/Rust/src/Timers.lf b/test/Rust/src/Timers.lf index 1ef5fc0ae5..16b359966c 100644 --- a/test/Rust/src/Timers.lf +++ b/test/Rust/src/Timers.lf @@ -1,19 +1,19 @@ /** Test whether timers with different periods are triggered correctly. */ target Rust { - timeout: 2 sec + timeout: 2 sec } main reactor Timers { - timer t(0, 1 sec) - timer t2(0, 2 sec) - state counter: i32 = 0 + timer t(0, 1 sec) + timer t2(0, 2 sec) + state counter: i32 = 0 - reaction(t2) {= self.counter += 2; =} + reaction(t2) {= self.counter += 2; =} - reaction(t) {= self.counter -= 1; =} + reaction(t) {= self.counter -= 1; =} - reaction(shutdown) {= - assert_eq!(1, self.counter); - println!("SUCCESS.") - =} + reaction(shutdown) {= + assert_eq!(1, self.counter); + println!("SUCCESS.") + =} } diff --git a/test/Rust/src/TypeVarLengthList.lf b/test/Rust/src/TypeVarLengthList.lf index 37ff36df56..41e964aa0c 100644 --- a/test/Rust/src/TypeVarLengthList.lf +++ b/test/Rust/src/TypeVarLengthList.lf @@ -3,13 +3,13 @@ target Rust // this thing must compile needs to be modified when // https://github.com/lf-lang/lingua-franca/discussions/492 is implemented main reactor TypeVarLengthList { - state l0: i32[] = {= Vec::new() =} // generates l0: Vec::new() - // generates l1: vec![1, 2] - /** - * - state l2: i32[](1); // generates l2: 1 // doesn't compile... - * - state l3: i32[](); // doesn't parse... - * - * - state l1: Vec(1, 2); // does not compile... - */ - state l1: i32[](1, 2) + state l0: i32[] = {= Vec::new() =} // generates l0: Vec::new() + // generates l1: vec![1, 2] + /** + * - state l2: i32[](1); // generates l2: 1 // doesn't compile... + * - state l3: i32[](); // doesn't parse... + * + * - state l1: Vec(1, 2); // does not compile... + */ + state l1: i32[](1, 2) } diff --git a/test/Rust/src/concurrent/AsyncCallback.lf b/test/Rust/src/concurrent/AsyncCallback.lf index dccbcf37c0..64ced0d2be 100644 --- a/test/Rust/src/concurrent/AsyncCallback.lf +++ b/test/Rust/src/concurrent/AsyncCallback.lf @@ -1,60 +1,60 @@ // Test asynchronous callbacks that trigger a physical action. target Rust { - timeout: 1000 ms, - cargo-features: ["cli"] + timeout: 1000 ms, + cargo-features: ["cli"] } main reactor AsyncCallback(period: time = 10 msec) { - preamble {= use std::thread; =} - - timer t(0, period) - state thread: Option> - state expected_time: time = period - state period: time = period - state toggle: bool = false - - physical action act - state i: u32 = 0 - - reaction(t) -> act {= - let act = act.clone(); - let period = self.period; - if let Some(old_thread) = self.thread.take() { - old_thread.join().ok(); - } - // start new thread - let new_thread = ctx.spawn_physical_thread(move |ctx| { - // Simulate time passing before a callback occurs - thread::sleep(period); - // Schedule twice. If the action is not physical, these should - // get consolidated into a single action triggering. If it is, - // then they cause two separate triggerings with close but not - // equal time stamps. - ctx.schedule_physical(&act, Asap).ok(); - ctx.schedule_physical(&act, Asap).ok(); - }); - - self.thread.replace(new_thread); - =} - - reaction(act) {= - let elapsed_time = ctx.get_elapsed_logical_time(); - let i = self.i; - println!("Asynchronous callback {}: Assigned logical time greater than start time by {} ms", - i, elapsed_time.as_millis()); - assert!(elapsed_time > self.expected_time,"ERROR: Expected logical time to be larger than {} ms", self.expected_time.as_millis()); - - self.i += 1; - if self.toggle { - self.expected_time += self.period; - } - self.toggle = !self.toggle; - =} - - reaction(shutdown) {= - if let Some(thread) = self.thread.take() { - thread.join().ok(); - } - println!("success"); - =} + preamble {= use std::thread; =} + + timer t(0, period) + state thread: Option> + state expected_time: time = period + state period: time = period + state toggle: bool = false + + physical action act + state i: u32 = 0 + + reaction(t) -> act {= + let act = act.clone(); + let period = self.period; + if let Some(old_thread) = self.thread.take() { + old_thread.join().ok(); + } + // start new thread + let new_thread = ctx.spawn_physical_thread(move |ctx| { + // Simulate time passing before a callback occurs + thread::sleep(period); + // Schedule twice. If the action is not physical, these should + // get consolidated into a single action triggering. If it is, + // then they cause two separate triggerings with close but not + // equal time stamps. + ctx.schedule_physical(&act, Asap).ok(); + ctx.schedule_physical(&act, Asap).ok(); + }); + + self.thread.replace(new_thread); + =} + + reaction(act) {= + let elapsed_time = ctx.get_elapsed_logical_time(); + let i = self.i; + println!("Asynchronous callback {}: Assigned logical time greater than start time by {} ms", + i, elapsed_time.as_millis()); + assert!(elapsed_time > self.expected_time,"ERROR: Expected logical time to be larger than {} ms", self.expected_time.as_millis()); + + self.i += 1; + if self.toggle { + self.expected_time += self.period; + } + self.toggle = !self.toggle; + =} + + reaction(shutdown) {= + if let Some(thread) = self.thread.take() { + thread.join().ok(); + } + println!("success"); + =} } diff --git a/test/Rust/src/generics/CtorParamGeneric.lf b/test/Rust/src/generics/CtorParamGeneric.lf index 1c8b1cab24..44d630a152 100644 --- a/test/Rust/src/generics/CtorParamGeneric.lf +++ b/test/Rust/src/generics/CtorParamGeneric.lf @@ -2,21 +2,21 @@ target Rust reactor Generic<{= T: Default + Eq + Sync + std::fmt::Debug =}>( - value: T = {= Default::default() =} + value: T = {= Default::default() =} ) { - input in: T - state v: T = value + input in: T + state v: T = value - reaction(in) {= - ctx.use_ref_opt(r#in, |i| { - assert_eq!(&self.v, i); - println!("success"); - }); - =} + reaction(in) {= + ctx.use_ref_opt(r#in, |i| { + assert_eq!(&self.v, i); + println!("success"); + }); + =} } main reactor { - p = new Generic(value = 23) + p = new Generic(value = 23) - reaction(startup) -> p.in {= ctx.set(p__in, 23); =} + reaction(startup) -> p.in {= ctx.set(p__in, 23); =} } diff --git a/test/Rust/src/generics/CtorParamGenericInst.lf b/test/Rust/src/generics/CtorParamGenericInst.lf index 86f696185c..8c5d2522aa 100644 --- a/test/Rust/src/generics/CtorParamGenericInst.lf +++ b/test/Rust/src/generics/CtorParamGenericInst.lf @@ -1,37 +1,33 @@ -// this one is deeper than CtorParamGeneric, it illustrates the use of ctor -// parameters within the argument list of a further child instance. +// this one is deeper than CtorParamGeneric, it illustrates the use of ctor parameters within the +// argument list of a further child instance. target Rust -reactor Generic2< - {= T: Default + Eq + Sync + std::fmt::Debug + Send + 'static =} ->( - value: T = {= Default::default() =} +reactor Generic2<{= T: Default + Eq + Sync + std::fmt::Debug + Send + 'static =}>( + value: T = {= Default::default() =} ) { - input in: T - state v: T = value + input in: T + state v: T = value - reaction(in) {= - ctx.use_ref_opt(r#in, |i| { - assert_eq!(&self.v, i); - println!("success"); - }); - =} + reaction(in) {= + ctx.use_ref_opt(r#in, |i| { + assert_eq!(&self.v, i); + println!("success"); + }); + =} } -reactor Generic< - {= T: Default + Eq + Sync + std::fmt::Debug + Copy + Send + 'static =} ->( - value: T = {= Default::default() =} +reactor Generic<{= T: Default + Eq + Sync + std::fmt::Debug + Copy + Send + 'static =}>( + value: T = {= Default::default() =} ) { - input in: T + input in: T - inner = new Generic2(value = value) + inner = new Generic2(value = value) - in -> inner.in + in -> inner.in } main reactor { - p = new Generic(value = 23) + p = new Generic(value = 23) - reaction(startup) -> p.in {= ctx.set(p__in, 23); =} + reaction(startup) -> p.in {= ctx.set(p__in, 23); =} } diff --git a/test/Rust/src/generics/GenericComplexType.lf b/test/Rust/src/generics/GenericComplexType.lf index 67453e6530..34765ade72 100644 --- a/test/Rust/src/generics/GenericComplexType.lf +++ b/test/Rust/src/generics/GenericComplexType.lf @@ -2,21 +2,21 @@ target Rust reactor R { - input in: Vec

    For targets that provide a threaded and an unthreaded runtime, this configures using the + * unthreaded runtime. For targets that do not distinguish threaded and unthreaded runtime, the + * number of workers is set to 1. + * + * @param test The test to configure. + * @return True if successful, false otherwise. + */ + public static boolean disableThreading(LFTest test) { + test.getContext().getArgs().setProperty("threading", "false"); + test.getContext().getArgs().setProperty("workers", "1"); + return true; + } - public static boolean makeZephyrCompatible(LFTest test) { - test.getContext().getArgs().setProperty("tracing", "false"); - test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; - test.getContext().getTargetConfig().platformOptions.flash = false; - test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; - return true; - } + public static boolean makeZephyrCompatibleUnthreaded(LFTest test) { + test.getContext().getArgs().setProperty("tracing", "false"); + test.getContext().getTargetConfig().threading = false; + test.getContext().getTargetConfig().setByUser.add(TargetProperty.THREADING); + test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; + test.getContext().getTargetConfig().platformOptions.flash = false; + test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + return true; + } - /** - * Make no changes to the configuration. - * - * @param ignoredTest The test to configure. - * @return True - */ - public static boolean noChanges(LFTest ignoredTest) { - return true; - } + public static boolean makeZephyrCompatible(LFTest test) { + test.getContext().getArgs().setProperty("tracing", "false"); + test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; + test.getContext().getTargetConfig().platformOptions.flash = false; + test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + return true; + } - /** - * Given a test category, return true if it is compatible with single-threaded execution. - */ - public static boolean compatibleWithThreadingOff(TestCategory category) { + /** + * Make no changes to the configuration. + * + * @param ignoredTest The test to configure. + * @return True + */ + public static boolean noChanges(LFTest ignoredTest) { + return true; + } + + /** Given a test category, return true if it is compatible with single-threaded execution. */ + public static boolean compatibleWithThreadingOff(TestCategory category) { - // CONCURRENT, FEDERATED, DOCKER_FEDERATED, DOCKER - // are not compatible with single-threaded execution. - // ARDUINO and ZEPHYR have their own test suites, so we don't need to rerun. - boolean excluded = category == TestCategory.CONCURRENT + // CONCURRENT, FEDERATED, DOCKER_FEDERATED, DOCKER + // are not compatible with single-threaded execution. + // ARDUINO and ZEPHYR have their own test suites, so we don't need to rerun. + boolean excluded = + category == TestCategory.CONCURRENT || category == TestCategory.SERIALIZATION || category == TestCategory.FEDERATED || category == TestCategory.DOCKER_FEDERATED @@ -109,8 +106,8 @@ public static boolean compatibleWithThreadingOff(TestCategory category) { || category == TestCategory.ARDUINO || category == TestCategory.ZEPHYR; - // SERIALIZATION and TARGET tests are excluded on Windows. - excluded |= TestBase.isWindows() && (category == TestCategory.TARGET); - return !excluded; - } + // SERIALIZATION and TARGET tests are excluded on Windows. + excluded |= TestBase.isWindows() && (category == TestCategory.TARGET); + return !excluded; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index c1e2e5e3f5..db5eb46fc3 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -1,35 +1,32 @@ /************* -Copyright (c) 2023, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2023, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.tests.runtime; import java.util.List; - import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - import org.lflang.Target; import org.lflang.tests.Configurators; import org.lflang.tests.RuntimeTest; @@ -42,29 +39,31 @@ */ public class CZephyrTest extends RuntimeTest { - public CZephyrTest() { - super(Target.C); - } + public CZephyrTest() { + super(Target.C); + } - @Test - public void buildZephyrTests() { - Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - super.runTestsFor(List.of(Target.C), - Message.DESC_ZEPHYR, - TestCategory.ZEPHYR::equals, - Configurators::makeZephyrCompatible, - TestLevel.BUILD, - false); - } - @Test - public void buildGenericTests() { - Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - super.runTestsFor(List.of(Target.C), - Message.DESC_GENERIC, - TestCategory.GENERIC::equals, - Configurators::makeZephyrCompatibleUnthreaded, - TestLevel.BUILD, - false); - } -} + @Test + public void buildZephyrTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor( + List.of(Target.C), + Message.DESC_ZEPHYR, + TestCategory.ZEPHYR::equals, + Configurators::makeZephyrCompatible, + TestLevel.BUILD, + false); + } + @Test + public void buildGenericTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor( + List.of(Target.C), + Message.DESC_GENERIC, + TestCategory.GENERIC::equals, + Configurators::makeZephyrCompatibleUnthreaded, + TestLevel.BUILD, + false); + } +} diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 3d2b77dd4c..af805491da 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -1,27 +1,27 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; import java.util.ArrayList; @@ -32,7 +32,6 @@ import java.util.Objects; import java.util.Properties; import java.util.Set; - import org.lflang.TargetProperty.BuildType; import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.TargetProperty.CoordinationType; @@ -48,458 +47,382 @@ /** * A class for keeping the current target configuration. * - * Class members of type String are initialized as empty strings, - * unless otherwise stated. + *

    Class members of type String are initialized as empty strings, unless otherwise stated. + * * @author Marten Lohstroh */ public class TargetConfig { - /** - * The target of this configuration (e.g., C, TypeScript, Python). - */ - public final Target target; - - /** - * Create a new target configuration based on the given target declaration AST node only. - * @param target AST node of a target declaration. - */ - public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can - this.target = Target.fromDecl(target); + /** The target of this configuration (e.g., C, TypeScript, Python). */ + public final Target target; + + /** + * Create a new target configuration based on the given target declaration AST node only. + * + * @param target AST node of a target declaration. + */ + public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can + this.target = Target.fromDecl(target); + } + + /** + * Create a new target configuration based on the given commandline arguments and target + * declaration AST node. + * + * @param cliArgs Arguments passed on the commandline. + * @param target AST node of a target declaration. + * @param errorReporter An error reporter to report problems. + */ + public TargetConfig(Properties cliArgs, TargetDecl target, ErrorReporter errorReporter) { + this(target); + if (target.getConfig() != null) { + List pairs = target.getConfig().getPairs(); + TargetProperty.set(this, pairs != null ? pairs : List.of(), errorReporter); } - - /** - * Create a new target configuration based on the given commandline arguments and target - * declaration AST node. - * @param cliArgs Arguments passed on the commandline. - * @param target AST node of a target declaration. - * @param errorReporter An error reporter to report problems. - */ - public TargetConfig( - Properties cliArgs, - TargetDecl target, - ErrorReporter errorReporter - ) { - this(target); - if (target.getConfig() != null) { - List pairs = target.getConfig().getPairs(); - TargetProperty.set(this, pairs != null ? pairs : List.of(), errorReporter); - } - if (cliArgs.containsKey("no-compile")) { - this.noCompile = true; - } - if (cliArgs.containsKey("docker")) { - var arg = cliArgs.getProperty("docker"); - if (Boolean.parseBoolean(arg)) { - this.dockerOptions = new DockerOptions(); - } else { - this.dockerOptions = null; - } - // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. - } - if (cliArgs.containsKey("build-type")) { - this.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); - } - if (cliArgs.containsKey("logging")) { - this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); - } - if (cliArgs.containsKey("workers")) { - this.workers = Integer.parseInt(cliArgs.getProperty("workers")); - } - if (cliArgs.containsKey("threading")) { - this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); - } - if (cliArgs.containsKey("target-compiler")) { - this.compiler = cliArgs.getProperty("target-compiler"); - } - if (cliArgs.containsKey("tracing")) { - this.tracing = new TracingOptions(); - } - if (cliArgs.containsKey("scheduler")) { - this.schedulerType = SchedulerOption.valueOf( - cliArgs.getProperty("scheduler") - ); - this.setByUser.add(TargetProperty.SCHEDULER); - } - if (cliArgs.containsKey("target-flags")) { - this.compilerFlags.clear(); - if (!cliArgs.getProperty("target-flags").isEmpty()) { - this.compilerFlags.addAll(List.of( - cliArgs.getProperty("target-flags").split(" ") - )); - } - } - if (cliArgs.containsKey("runtime-version")) { - this.runtimeVersion = cliArgs.getProperty("runtime-version"); - } - if (cliArgs.containsKey("external-runtime-path")) { - this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); - } - if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { - this.keepalive = Boolean.parseBoolean( - cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); - } - if (cliArgs.containsKey(BuildParm.PRINT_STATISTICS.getKey())) { - this.printStatistics = true; - } + if (cliArgs.containsKey("no-compile")) { + this.noCompile = true; + } + if (cliArgs.containsKey("docker")) { + var arg = cliArgs.getProperty("docker"); + if (Boolean.parseBoolean(arg)) { + this.dockerOptions = new DockerOptions(); + } else { + this.dockerOptions = null; + } + // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. + } + if (cliArgs.containsKey("build-type")) { + this.cmakeBuildType = + (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); + } + if (cliArgs.containsKey("logging")) { + this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); + } + if (cliArgs.containsKey("workers")) { + this.workers = Integer.parseInt(cliArgs.getProperty("workers")); + } + if (cliArgs.containsKey("threading")) { + this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); + } + if (cliArgs.containsKey("target-compiler")) { + this.compiler = cliArgs.getProperty("target-compiler"); + } + if (cliArgs.containsKey("tracing")) { + this.tracing = new TracingOptions(); + } + if (cliArgs.containsKey("scheduler")) { + this.schedulerType = SchedulerOption.valueOf(cliArgs.getProperty("scheduler")); + this.setByUser.add(TargetProperty.SCHEDULER); + } + if (cliArgs.containsKey("target-flags")) { + this.compilerFlags.clear(); + if (!cliArgs.getProperty("target-flags").isEmpty()) { + this.compilerFlags.addAll(List.of(cliArgs.getProperty("target-flags").split(" "))); + } + } + if (cliArgs.containsKey("runtime-version")) { + this.runtimeVersion = cliArgs.getProperty("runtime-version"); + } + if (cliArgs.containsKey("external-runtime-path")) { + this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); + } + if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { + this.keepalive = + Boolean.parseBoolean(cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); } + if (cliArgs.containsKey(BuildParm.PRINT_STATISTICS.getKey())) { + this.printStatistics = true; + } + } - /** - * Keep track of every target property that is explicitly set by the user. - */ - public Set setByUser = new HashSet<>(); + /** Keep track of every target property that is explicitly set by the user. */ + public Set setByUser = new HashSet<>(); - /** - * A list of custom build commands that replace the default build process of - * directly invoking a designated compiler. A common usage of this target - * property is to set the command to build on the basis of a Makefile. - */ - public List buildCommands = new ArrayList<>(); + /** + * A list of custom build commands that replace the default build process of directly invoking a + * designated compiler. A common usage of this target property is to set the command to build on + * the basis of a Makefile. + */ + public List buildCommands = new ArrayList<>(); - /** - * The mode of clock synchronization to be used in federated programs. - * The default is 'initial'. - */ - public ClockSyncMode clockSync = ClockSyncMode.INIT; + /** + * The mode of clock synchronization to be used in federated programs. The default is 'initial'. + */ + public ClockSyncMode clockSync = ClockSyncMode.INIT; - /** - * Clock sync options. - */ - public ClockSyncOptions clockSyncOptions = new ClockSyncOptions(); + /** Clock sync options. */ + public ClockSyncOptions clockSyncOptions = new ClockSyncOptions(); - /** - * Parameter passed to cmake. The default is 'Release'. - */ - public BuildType cmakeBuildType = BuildType.RELEASE; + /** Parameter passed to cmake. The default is 'Release'. */ + public BuildType cmakeBuildType = BuildType.RELEASE; - /** - * Optional additional extensions to include in the generated CMakeLists.txt. - */ - public List cmakeIncludes = new ArrayList<>(); + /** Optional additional extensions to include in the generated CMakeLists.txt. */ + public List cmakeIncludes = new ArrayList<>(); - /** - * The compiler to invoke, unless a build command has been specified. - */ - public String compiler = ""; + /** The compiler to invoke, unless a build command has been specified. */ + public String compiler = ""; - /** - * Additional sources to add to the compile command if appropriate. - */ - public List compileAdditionalSources = new ArrayList<>(); + /** Additional sources to add to the compile command if appropriate. */ + public List compileAdditionalSources = new ArrayList<>(); - /** - * Additional (preprocessor) definitions to add to the compile command if appropriate. - * - * The first string is the definition itself, and the second string is the value to attribute to that definition, if any. - * The second value could be left empty. - */ - public Map compileDefinitions = new HashMap<>(); + /** + * Additional (preprocessor) definitions to add to the compile command if appropriate. + * + *

    The first string is the definition itself, and the second string is the value to attribute + * to that definition, if any. The second value could be left empty. + */ + public Map compileDefinitions = new HashMap<>(); - /** - * Additional libraries to add to the compile command using the "-l" command-line option. - */ - public List compileLibraries = new ArrayList<>(); + /** Additional libraries to add to the compile command using the "-l" command-line option. */ + public List compileLibraries = new ArrayList<>(); - /** - * Flags to pass to the compiler, unless a build command has been specified. - */ - public List compilerFlags = new ArrayList<>(); + /** Flags to pass to the compiler, unless a build command has been specified. */ + public List compilerFlags = new ArrayList<>(); - /** - * The type of coordination used during the execution of a federated program. - * The default is 'centralized'. - */ - public CoordinationType coordination = CoordinationType.CENTRALIZED; + /** + * The type of coordination used during the execution of a federated program. The default is + * 'centralized'. + */ + public CoordinationType coordination = CoordinationType.CENTRALIZED; + + /** Docker options. */ + public DockerOptions dockerOptions = null; - /** - * Docker options. - */ - public DockerOptions dockerOptions = null; + /** Coordination options. */ + public CoordinationOptions coordinationOptions = new CoordinationOptions(); - /** - * Coordination options. - */ - public CoordinationOptions coordinationOptions = new CoordinationOptions(); + /** Link to an external runtime library instead of the default one. */ + public String externalRuntimePath = null; - /** - * Link to an external runtime library instead of the default one. - */ - public String externalRuntimePath = null; + /** + * If true, configure the execution environment such that it does not wait for physical time to + * match logical time. The default is false. + */ + public boolean fastMode = false; - /** - * If true, configure the execution environment such that it does not - * wait for physical time to match logical time. The default is false. - */ - public boolean fastMode = false; + /** List of files to be copied to src-gen. */ + public List files = new ArrayList<>(); - /** - * List of files to be copied to src-gen. - */ - public List files = new ArrayList<>(); + /** + * If true, configure the execution environment to keep executing if there are no more events on + * the event queue. The default is false. + */ + public boolean keepalive = false; - /** - * If true, configure the execution environment to keep executing if there - * are no more events on the event queue. The default is false. - */ - public boolean keepalive = false; + /** The level of logging during execution. The default is INFO. */ + public LogLevel logLevel = LogLevel.INFO; - /** - * The level of logging during execution. The default is INFO. - */ - public LogLevel logLevel = LogLevel.INFO; + /** Flags to pass to the linker, unless a build command has been specified. */ + public String linkerFlags = ""; - /** - * Flags to pass to the linker, unless a build command has been specified. - */ - public String linkerFlags = ""; + /** If true, do not invoke the target compiler or build command. The default is false. */ + public boolean noCompile = false; - /** - * If true, do not invoke the target compiler or build command. - * The default is false. - */ - public boolean noCompile = false; + /** If true, do not perform runtime validation. The default is false. */ + public boolean noRuntimeValidation = false; - /** - * If true, do not perform runtime validation. The default is false. - */ - public boolean noRuntimeValidation = false; + /** + * Set the target platform config. This tells the build system what platform-specific support + * files it needs to incorporate at compile time. + * + *

    This is now a wrapped class to account for overloaded definitions of defining platform + * (either a string or dictionary of values) + */ + public PlatformOptions platformOptions = new PlatformOptions(); - /** - * Set the target platform config. - * This tells the build system what platform-specific support - * files it needs to incorporate at compile time. - * - * This is now a wrapped class to account for overloaded definitions - * of defining platform (either a string or dictionary of values) - */ - public PlatformOptions platformOptions = new PlatformOptions(); + /** If true, instruct the runtime to collect and print execution statistics. */ + public boolean printStatistics = false; - /** - * If true, instruct the runtime to collect and print execution statistics. - */ - public boolean printStatistics = false; + /** List of proto files to be processed by the code generator. */ + public List protoFiles = new ArrayList<>(); - /** - * List of proto files to be processed by the code generator. - */ - public List protoFiles = new ArrayList<>(); + /** If true, generate ROS2 specific code. */ + public boolean ros2 = false; - /** - * If true, generate ROS2 specific code. - */ - public boolean ros2 = false; + /** Additional ROS2 packages that the LF program depends on. */ + public List ros2Dependencies = null; + + /** The version of the runtime library to be used in the generated target. */ + public String runtimeVersion = null; + + /** Whether all reactors are to be generated into a single target language file. */ + public boolean singleFileProject = false; + + /** What runtime scheduler to use. */ + public SchedulerOption schedulerType = SchedulerOption.getDefault(); + + /** + * The number of worker threads to deploy. The default is zero, which indicates that the runtime + * is allowed to freely choose the number of workers. + */ + public int workers = 0; + + /** Indicate whether HMAC authentication is used. */ + public boolean auth = false; + + /** Indicate whether the runtime should use multithreaded execution. */ + public boolean threading = true; + + /** The timeout to be observed during execution of the program. */ + public TimeValue timeout; + + /** If non-null, configure the runtime environment to perform tracing. The default is null. */ + public TracingOptions tracing = null; + + /** + * If true, the resulting binary will output a graph visualizing all reaction dependencies. + * + *

    This option is currently only used for C++ and Rust. This export function is a valuable tool + * for debugging LF programs and helps to understand the dependencies inferred by the runtime. + */ + public boolean exportDependencyGraph = false; + + /** + * If true, the resulting binary will output a yaml file describing the whole reactor structure of + * the program. + * + *

    This option is currently only used for C++. This export function is a valuable tool for + * debugging LF programs and performing external analysis. + */ + public boolean exportToYaml = false; + + /** Rust-specific configuration. */ + public final RustTargetConfig rust = + new RustTargetConfig(); // FIXME: https://issue.lf-lang.org/1558 + + /** Path to a C file used by the Python target to setup federated execution. */ + public String fedSetupPreamble = null; // FIXME: https://issue.lf-lang.org/1558 + + /** Settings related to clock synchronization. */ + public static class ClockSyncOptions { /** - * Additional ROS2 packages that the LF program depends on. + * Dampen the adjustments to the clock synchronization offset by this rate. The default is 10. */ - public List ros2Dependencies = null; + public int attenuation = 10; /** - * The version of the runtime library to be used in the generated target. + * Whether to collect statistics while performing clock synchronization. This setting is only + * considered when clock synchronization has been activated. The default is true. */ - public String runtimeVersion = null; - - /** Whether all reactors are to be generated into a single target language file. */ - public boolean singleFileProject = false; + public boolean collectStats = true; - /** What runtime scheduler to use. */ - public SchedulerOption schedulerType = SchedulerOption.getDefault(); + /** Enable clock synchronization for federates on the same machine. Default is false. */ + public boolean localFederatesOn = false; /** - * The number of worker threads to deploy. The default is zero, which indicates that - * the runtime is allowed to freely choose the number of workers. + * Interval at which clock synchronization is initiated by the RTI (will be passed to it as an + * argument on the command-line). The default is 5 milliseconds. */ - public int workers = 0; + public TimeValue period = new TimeValue(5, TimeUnit.MILLI); /** - * Indicate whether HMAC authentication is used. + * Indicate the number of exchanges to be had per each clock synchronization round. See + * /lib/core/federated/clock-sync.h for more details. The default is 10. */ - public boolean auth = false; + public int trials = 10; /** - * Indicate whether the runtime should use multithreaded execution. + * Used to create an artificial clock synchronization error for the purpose of testing. The + * default is null. */ - public boolean threading = true; + public TimeValue testOffset; + } + + /** Settings related to coordination of federated execution. */ + public static class CoordinationOptions { /** - * The timeout to be observed during execution of the program. + * For centralized coordination, if a federate has a physical action that can trigger an output, + * directly or indirectly, then it will send NET (next event tag) messages to the RTI + * periodically as its physical clock advances. This option sets the amount of time to wait + * between sending such messages. Increasing this value results in downstream federates that lag + * further behind physical time (if the "after" delays are insufficient). The default is null, + * which means it is up the implementation to choose an interval. */ - public TimeValue timeout; + public TimeValue advance_message_interval = null; + } + /** Settings related to Docker options. */ + public static class DockerOptions { /** - * If non-null, configure the runtime environment to perform tracing. - * The default is null. + * The base image and tag from which to build the Docker image. The default is "alpine:latest". */ - public TracingOptions tracing = null; + public String from = "alpine:latest"; + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DockerOptions that = (DockerOptions) o; + return from.equals(that.from); + } + } + + /** Settings related to Platform Options. */ + public static class PlatformOptions { /** - * If true, the resulting binary will output a graph visualizing all reaction dependencies. - * - * This option is currently only used for C++ and Rust. This export function is a valuable tool - * for debugging LF programs and helps to understand the dependencies inferred by the runtime. + * The base platform we build our LF Files on. Should be set to AUTO by default unless + * developing for specific OS/Embedded Platform */ - public boolean exportDependencyGraph = false; - + public Platform platform = Platform.AUTO; /** - * If true, the resulting binary will output a yaml file describing the whole reactor structure - * of the program. - * - * This option is currently only used for C++. This export function is a valuable tool for debugging - * LF programs and performing external analysis. + * The string value used to determine what type of embedded board we work with and can be used + * to simplify the build process. For example, when we want to flash to an Arduino Nano 33 BLE + * board, we can use the string arduino:mbed_nano:nano33ble */ - public boolean exportToYaml = false; - - /** Rust-specific configuration. */ - public final RustTargetConfig rust = new RustTargetConfig(); // FIXME: https://issue.lf-lang.org/1558 - - /** Path to a C file used by the Python target to setup federated execution. */ - public String fedSetupPreamble = null; // FIXME: https://issue.lf-lang.org/1558 + public String board = null; /** - * Settings related to clock synchronization. + * The string value used to determine the port on which to flash the compiled program (i.e. + * /dev/cu.usbmodem21301) */ - public static class ClockSyncOptions { - - /** - * Dampen the adjustments to the clock synchronization offset by this rate. - * The default is 10. - */ - public int attenuation = 10; - - /** - * Whether to collect statistics while performing clock synchronization. - * This setting is only considered when clock synchronization has been activated. - * The default is true. - */ - public boolean collectStats = true; - - /** - * Enable clock synchronization for federates on the same machine. - * Default is false. - */ - public boolean localFederatesOn = false; - - - /** - * Interval at which clock synchronization is initiated by the RTI (will be passed - * to it as an argument on the command-line). - * The default is 5 milliseconds. - */ - public TimeValue period = new TimeValue(5, TimeUnit.MILLI); - - /** - * Indicate the number of exchanges to be had per each clock synchronization round. - * See /lib/core/federated/clock-sync.h for more details. - * The default is 10. - */ - public int trials = 10; - - /** - * Used to create an artificial clock synchronization error for the purpose of testing. - * The default is null. - */ - public TimeValue testOffset; - } + public String port = null; /** - * Settings related to coordination of federated execution. + * The baud rate used as a parameter to certain embedded platforms. 9600 is a standard rate + * amongst systems like Arduino, so it's the default value. */ - public static class CoordinationOptions { - - /** - * For centralized coordination, if a federate has a physical action that can trigger - * an output, directly or indirectly, then it will send NET (next event tag) messages - * to the RTI periodically as its physical clock advances. This option sets the amount - * of time to wait between sending such messages. Increasing this value results in - * downstream federates that lag further behind physical time (if the "after" delays - * are insufficient). - * The default is null, which means it is up the implementation to choose an interval. - */ - public TimeValue advance_message_interval = null; - } + public int baudRate = 9600; /** - * Settings related to Docker options. + * The boolean statement used to determine whether we should automatically attempt to flash once + * we compile. This may require the use of board and port values depending on the infrastructure + * you use to flash the boards. */ - public static class DockerOptions { - /** - * The base image and tag from which to build the Docker image. The default is "alpine:latest". - */ - public String from = "alpine:latest"; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - DockerOptions that = (DockerOptions) o; - return from.equals(that.from); - } - } + public boolean flash = false; /** - * Settings related to Platform Options. + * The int value is used to determine the number of needed threads for the user application in + * Zephyr. */ - public static class PlatformOptions { - - /** - * The base platform we build our LF Files on. Should be set to AUTO by default unless developing for specific OS/Embedded Platform - */ - public Platform platform = Platform.AUTO; - - /** - * The string value used to determine what type of embedded board we work with and can be used to simplify the build process. For example, - * when we want to flash to an Arduino Nano 33 BLE board, we can use the string arduino:mbed_nano:nano33ble - */ - public String board = null; - - - /** - * The string value used to determine the port on which to flash the compiled program (i.e. /dev/cu.usbmodem21301) - */ - public String port = null; - - /** - * The baud rate used as a parameter to certain embedded platforms. 9600 is a standard rate amongst systems like Arduino, so it's the default value. - */ - public int baudRate = 9600; - - /** - * The boolean statement used to determine whether we should automatically attempt to flash once we compile. This may require the use of board and - * port values depending on the infrastructure you use to flash the boards. - */ - public boolean flash = false; - - /** - * The int value is used to determine the number of needed threads for the user application in Zephyr. - */ - public int userThreads = 0; - } + public int userThreads = 0; + } + /** Settings related to tracing options. */ + public static class TracingOptions { /** - * Settings related to tracing options. + * The name to use as the root of the trace file produced. This defaults to the name of the .lf + * file. */ - public static class TracingOptions { - /** - * The name to use as the root of the trace file produced. - * This defaults to the name of the .lf file. - */ - public String traceFileName = null; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TracingOptions that = (TracingOptions) o; - return Objects.equals(traceFileName, that.traceFileName); // traceFileName may be null - } + public String traceFileName = null; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TracingOptions that = (TracingOptions) o; + return Objects.equals(traceFileName, that.traceFileName); // traceFileName may be null } + } } diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index d874a97ee1..916b29b115 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1,30 +1,31 @@ /************* -Copyright (c) 2019, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang; +import com.google.common.collect.ImmutableList; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; @@ -33,7 +34,6 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; - import org.eclipse.xtext.util.RuntimeIOException; import org.lflang.TargetConfig.DockerOptions; import org.lflang.TargetConfig.PlatformOptions; @@ -51,1824 +51,1765 @@ import org.lflang.util.StringUtil; import org.lflang.validation.LFValidator; -import com.google.common.collect.ImmutableList; - /** - * A target properties along with a type and a list of supporting targets - * that supports it, as well as a function for configuration updates. + * A target properties along with a type and a list of supporting targets that supports it, as well + * as a function for configuration updates. * * @author Marten Lohstroh */ public enum TargetProperty { - /** - * Directive to allow including OpenSSL libraries and process HMAC authentication. - */ - AUTH("auth", PrimitiveType.BOOLEAN, - Arrays.asList(Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.auth), - (config, value, err) -> { - config.auth = ASTUtils.toBoolean(value); - }), - /** - * Directive to let the generator use the custom build command. - */ - BUILD("build", UnionType.STRING_OR_STRING_ARRAY, - Arrays.asList(Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.buildCommands), - (config, value, err) -> { - config.buildCommands = ASTUtils.elementToListOfStrings(value); - }), - - /** - * Directive to specify the target build type such as 'Release' or 'Debug'. - * This is also used in the Rust target to select a Cargo profile. - */ - BUILD_TYPE("build-type", UnionType.BUILD_TYPE_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Rust), - (config) -> ASTUtils.toElement(config.cmakeBuildType.toString()), - (config, value, err) -> { - config.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION - .forName(ASTUtils.elementToSingleString(value)); - // set it there too, because the default is different. - config.rust.setBuildType(config.cmakeBuildType); - }), - - /** - * Directive to let the federate execution handle clock synchronization in software. - */ - CLOCK_SYNC("clock-sync", UnionType.CLOCK_SYNC_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.clockSync.toString()), - (config, value, err) -> { - config.clockSync = (ClockSyncMode) UnionType.CLOCK_SYNC_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - /** - * Key-value pairs giving options for clock synchronization. - */ - CLOCK_SYNC_OPTIONS("clock-sync-options", - DictionaryType.CLOCK_SYNC_OPTION_DICT, Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (ClockSyncOption opt : ClockSyncOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case ATTENUATION: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.attenuation)); - break; - case COLLECT_STATS: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.collectStats)); - break; - case LOCAL_FEDERATES_ON: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.localFederatesOn)); - break; - case PERIOD: - if (config.clockSyncOptions.period == null) continue; // don't set if null - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.period)); - break; - case TEST_OFFSET: - if (config.clockSyncOptions.testOffset == null) continue; // don't set if null - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.testOffset)); - break; - case TRIALS: - pair.setValue(ASTUtils.toElement(config.clockSyncOptions.trials)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - // kvp will never be empty - return e; - }, - (config, value, err) -> { - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - ClockSyncOption option = (ClockSyncOption) DictionaryType.CLOCK_SYNC_OPTION_DICT - .forName(entry.getName()); - switch (option) { - case ATTENUATION: - config.clockSyncOptions.attenuation = ASTUtils - .toInteger(entry.getValue()); - break; - case COLLECT_STATS: - config.clockSyncOptions.collectStats = ASTUtils - .toBoolean(entry.getValue()); - break; - case LOCAL_FEDERATES_ON: - config.clockSyncOptions.localFederatesOn = ASTUtils - .toBoolean(entry.getValue()); - break; - case PERIOD: - config.clockSyncOptions.period = ASTUtils - .toTimeValue(entry.getValue()); - break; - case TEST_OFFSET: - config.clockSyncOptions.testOffset = ASTUtils - .toTimeValue(entry.getValue()); - break; - case TRIALS: - config.clockSyncOptions.trials = ASTUtils - .toInteger(entry.getValue()); - break; - default: - break; - } - } - }), - - /** - * Directive to specify a cmake to be included by the generated build - * systems. - * - * This gives full control over the C/C++ build as any cmake parameters - * can be adjusted in the included file. - */ - CMAKE_INCLUDE("cmake-include", UnionType.FILE_OR_FILE_ARRAY, - Arrays.asList(Target.CPP, Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.cmakeIncludes), - (config, value, err) -> { - config.cmakeIncludes = ASTUtils.elementToListOfStrings(value); - }, - // FIXME: This merging of lists is potentially dangerous since - // the incoming list of cmake-includes can belong to a .lf file that is - // located in a different location, and keeping just filename - // strings like this without absolute paths is incorrect. - (config, value, err) -> { - config.cmakeIncludes.addAll(ASTUtils.elementToListOfStrings(value)); - }), - /** - * Directive to specify the target compiler. - */ - COMPILER("compiler", PrimitiveType.STRING, Target.ALL, - (config) -> ASTUtils.toElement(config.compiler), - (config, value, err) -> { - config.compiler = ASTUtils.elementToSingleString(value); - }), - - /** - * Directive to specify compile-time definitions. - */ - COMPILE_DEFINITIONS("compile-definitions", StringDictionaryType.COMPILE_DEFINITION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.compileDefinitions), - (config, value, err) -> { - config.compileDefinitions = ASTUtils.elementToStringMaps(value); - }), - - /** - * Directive to generate a Dockerfile. This is either a boolean, - * true or false, or a dictionary of options. - */ - DOCKER("docker", UnionType.DOCKER_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), - (config) -> { - if (config.dockerOptions == null) { - return null; - } else if(config.dockerOptions.equals(new DockerOptions())) { - // default configuration - return ASTUtils.toElement(true); - } else { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (DockerOption opt : DockerOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case FROM: - if (config.dockerOptions.from == null) continue; - pair.setValue(ASTUtils.toElement(config.dockerOptions.from)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - } - }, - (config, value, err) -> setDockerProperty(config, value), - (config, value, err) -> setDockerProperty(config, value)), - - /** - * Directive for specifying a path to an external runtime to be used for the - * compiled binary. - */ - EXTERNAL_RUNTIME_PATH("external-runtime-path", PrimitiveType.STRING, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.externalRuntimePath), - (config, value, err) -> { - config.externalRuntimePath = ASTUtils.elementToSingleString(value); - }), - - /** - * Directive to let the execution engine allow logical time to elapse - * faster than physical time. - */ - FAST("fast", PrimitiveType.BOOLEAN, Target.ALL, - (config) -> ASTUtils.toElement(config.fastMode), - (config, value, err) -> { - config.fastMode = ASTUtils.toBoolean(value); - }), - - /** - * Directive to stage particular files on the class path to be - * processed by the code generator. - */ - FILES("files", UnionType.FILE_OR_FILE_ARRAY, List.of(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.files), - (config, value, err) -> { - config.files = ASTUtils.elementToListOfStrings(value); - }, - // FIXME: This merging of lists is potentially dangerous since - // the incoming list of files can belong to a .lf file that is - // located in a different location, and keeping just filename - // strings like this without absolute paths is incorrect. - (config, value, err) -> { - config.files.addAll(ASTUtils.elementToListOfStrings(value)); - }), - - /** - * Flags to be passed on to the target compiler. - */ - FLAGS("flags", UnionType.STRING_OR_STRING_ARRAY, - Arrays.asList(Target.C, Target.CCPP), - (config) -> ASTUtils.toElement(config.compilerFlags), - (config, value, err) -> { - config.compilerFlags = ASTUtils.elementToListOfStrings(value); - }), - - /** - * Directive to specify the coordination mode - */ - COORDINATION("coordination", UnionType.COORDINATION_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.coordination.toString()), - (config, value, err) -> { - config.coordination = (CoordinationType) UnionType.COORDINATION_UNION - .forName(ASTUtils.elementToSingleString(value)); - }, - (config, value, err) -> { - config.coordination = (CoordinationType) UnionType.COORDINATION_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - - /** - * Key-value pairs giving options for clock synchronization. - */ - COORDINATION_OPTIONS("coordination-options", - DictionaryType.COORDINATION_OPTION_DICT, Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), - (config) -> { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (CoordinationOption opt : CoordinationOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case ADVANCE_MESSAGE_INTERVAL: - if (config.coordinationOptions.advance_message_interval == null) continue; - pair.setValue(ASTUtils.toElement(config.coordinationOptions.advance_message_interval)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - }, - (config, value, err) -> { - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - CoordinationOption option = (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT - .forName(entry.getName()); - switch (option) { - case ADVANCE_MESSAGE_INTERVAL: - config.coordinationOptions.advance_message_interval = ASTUtils - .toTimeValue(entry.getValue()); - break; - default: - break; - } - } - }, - (config, value, err) -> { - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - CoordinationOption option = (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT - .forName(entry.getName()); - switch (option) { - case ADVANCE_MESSAGE_INTERVAL: - config.coordinationOptions.advance_message_interval = ASTUtils - .toTimeValue(entry.getValue()); - break; - default: - break; - } - } - }), - - /** - * Directive to let the execution engine remain active also if there - * are no more events in the event queue. - */ - KEEPALIVE("keepalive", PrimitiveType.BOOLEAN, Target.ALL, - (config) -> ASTUtils.toElement(config.keepalive), - (config, value, err) -> { - config.keepalive = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify the grain at which to report log messages during execution. - */ - LOGGING("logging", UnionType.LOGGING_UNION, Target.ALL, - (config) -> ASTUtils.toElement(config.logLevel.toString()), - (config, value, err) -> { - config.logLevel = (LogLevel) UnionType.LOGGING_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - - /** - * Directive to not invoke the target compiler. - */ - NO_COMPILE("no-compile", PrimitiveType.BOOLEAN, - Arrays.asList(Target.C, Target.CPP, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.noCompile), - (config, value, err) -> { - config.noCompile = ASTUtils.toBoolean(value); - }), - - /** - * Directive to disable validation of reactor rules at runtime. - */ - NO_RUNTIME_VALIDATION("no-runtime-validation", PrimitiveType.BOOLEAN, - Arrays.asList(Target.CPP), - (config) -> ASTUtils.toElement(config.noRuntimeValidation), - (config, value, err) -> { - config.noRuntimeValidation = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify the platform for cross code generation. This is either a string of the platform - * or a dictionary of options that includes the string name. - */ - PLATFORM("platform", UnionType.PLATFORM_STRING_OR_DICTIONARY, Target.ALL, - (config) -> { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (PlatformOption opt : PlatformOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case NAME: - pair.setValue(ASTUtils.toElement(config.platformOptions.platform.toString())); - break; - case BAUDRATE: - pair.setValue(ASTUtils.toElement(config.platformOptions.baudRate)); - break; - case BOARD: - pair.setValue(ASTUtils.toElement(config.platformOptions.board)); - break; - case FLASH: - pair.setValue(ASTUtils.toElement(config.platformOptions.flash)); - break; - case PORT: - pair.setValue(ASTUtils.toElement(config.platformOptions.port)); - break; - case USER_THREADS: - pair.setValue(ASTUtils.toElement(config.platformOptions.userThreads)); - break; - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - }, - (config, value, err) -> { - if (value.getLiteral() != null) { - config.platformOptions = new PlatformOptions(); - config.platformOptions.platform = (Platform) UnionType.PLATFORM_UNION - .forName(ASTUtils.elementToSingleString(value)); - } else { - config.platformOptions= new PlatformOptions(); - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - PlatformOption option = (PlatformOption) DictionaryType.PLATFORM_DICT - .forName(entry.getName()); - switch (option) { - case NAME: - Platform p = (Platform) UnionType.PLATFORM_UNION - .forName(ASTUtils.elementToSingleString(entry.getValue())); - if(p == null) { - String s = "Unidentified Platform Type, LF supports the following platform types: " + Arrays.asList(Platform.values()).toString(); - err.reportError(s); - throw new AssertionError(s); - } - config.platformOptions.platform = p; - break; - case BAUDRATE: - config.platformOptions.baudRate = ASTUtils.toInteger(entry.getValue()); - break; - case BOARD: - config.platformOptions.board = ASTUtils.elementToSingleString(entry.getValue()); - break; - case FLASH: - config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()); - break; - case PORT: - config.platformOptions.port = ASTUtils.elementToSingleString(entry.getValue()); - break; - case USER_THREADS: - config.platformOptions.userThreads = ASTUtils.toInteger(entry.getValue()); - break; - default: - break; - } - } - } - }), - - /** - * Directive to instruct the runtime to collect and print execution statistics. - */ - PRINT_STATISTICS("print-statistics", PrimitiveType.BOOLEAN, - Arrays.asList(Target.CPP), - (config) -> ASTUtils.toElement(config.printStatistics), - (config, value, err) -> { - config.printStatistics = ASTUtils.toBoolean(value); - }), - - /** - * Directive for specifying .proto files that need to be compiled and their - * code included in the sources. - */ - PROTOBUFS("protobufs", UnionType.FILE_OR_FILE_ARRAY, - Arrays.asList(Target.C, Target.CCPP, Target.TS, Target.Python), - (config) -> ASTUtils.toElement(config.protoFiles), - (config, value, err) -> { - config.protoFiles = ASTUtils.elementToListOfStrings(value); - }), - - - /** - * Directive to specify that ROS2 specific code is generated, - */ - ROS2("ros2", PrimitiveType.BOOLEAN, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.ros2), - (config, value, err) -> { - config.ros2 = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify additional ROS2 packages that this LF program depends on. - */ - ROS2_DEPENDENCIES("ros2-dependencies", ArrayType.STRING_ARRAY, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.ros2Dependencies), - (config, value, err) -> { - config.ros2Dependencies = ASTUtils.elementToListOfStrings(value); - }), - - /** - * Directive for specifying a specific version of the reactor runtime library. - */ - RUNTIME_VERSION("runtime-version", PrimitiveType.STRING, - Arrays.asList(Target.CPP), - (config) -> ASTUtils.toElement(config.runtimeVersion), - (config, value, err) -> { - config.runtimeVersion = ASTUtils.elementToSingleString(value); - }), - - - /** - * Directive for specifying a specific runtime scheduler, if supported. - */ - SCHEDULER("scheduler", UnionType.SCHEDULER_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.schedulerType.toString()), - (config, value, err) -> { - config.schedulerType = (SchedulerOption) UnionType.SCHEDULER_UNION - .forName(ASTUtils.elementToSingleString(value)); - }), - - /** - * Directive to specify that all code is generated in a single file. - */ - SINGLE_FILE_PROJECT("single-file-project", PrimitiveType.BOOLEAN, - List.of(Target.Rust), - (config) -> ASTUtils.toElement(config.singleFileProject), - (config, value, err) -> { - config.singleFileProject = ASTUtils.toBoolean(value); - }), - - /** - * Directive to indicate whether the runtime should use multi-threading. - */ - THREADING("threading", PrimitiveType.BOOLEAN, - List.of(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.threading), - (config, value, err) -> { - config.threading = ASTUtils.toBoolean(value); - }), - - /** - * Directive to specify the number of worker threads used by the runtime. - */ - WORKERS("workers", PrimitiveType.NON_NEGATIVE_INTEGER, - List.of(Target.C, Target.CCPP, Target.Python, Target.CPP, Target.Rust), - (config) -> ASTUtils.toElement(config.workers), - (config, value, err) -> { - config.workers = ASTUtils.toInteger(value); - }), - - /** - * Directive to specify the execution timeout. - */ - TIMEOUT("timeout", PrimitiveType.TIME_VALUE, Target.ALL, - (config) -> ASTUtils.toElement(config.timeout), - (config, value, err) -> { - config.timeout = ASTUtils.toTimeValue(value); - }, - (config, value, err) -> { - config.timeout = ASTUtils.toTimeValue(value); - }), - - /** - * Directive to enable tracing. - */ - TRACING("tracing", UnionType.TRACING_UNION, - Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), - (config) -> { - if (config.tracing == null) { - return null; - } else if (config.tracing.equals(new TracingOptions())) { - // default values - return ASTUtils.toElement(true); - } else { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (TracingOption opt : TracingOption.values()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(opt.toString()); - switch (opt) { - case TRACE_FILE_NAME: - if (config.tracing.traceFileName == null) continue; - pair.setValue(ASTUtils.toElement(config.tracing.traceFileName)); - } - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - if (kvp.getPairs().isEmpty()) return null; - return e; - } - }, - (config, value, err) -> { - if (value.getLiteral() != null) { - if (ASTUtils.toBoolean(value)) { - config.tracing = new TracingOptions(); - } else { - config.tracing = null; - } - } else { - config.tracing = new TracingOptions(); - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - TracingOption option = (TracingOption) DictionaryType.TRACING_DICT - .forName(entry.getName()); - switch (option) { - case TRACE_FILE_NAME: - config.tracing.traceFileName = ASTUtils.elementToSingleString(entry.getValue()); - break; - default: - break; - } - } - } - }), - - /** - * Directive to let the runtime export its internal dependency graph. - * - * This is a debugging feature and currently only used for C++ and Rust programs. - */ - EXPORT_DEPENDENCY_GRAPH("export-dependency-graph", PrimitiveType.BOOLEAN, - List.of(Target.CPP, Target.Rust), - (config) -> ASTUtils.toElement(config.exportDependencyGraph), - (config, value, err) -> { - config.exportDependencyGraph = ASTUtils.toBoolean(value); - }), - - /** - * Directive to let the runtime export the program structure to a yaml file. - * - * This is a debugging feature and currently only used for C++ programs. - */ - EXPORT_TO_YAML("export-to-yaml", PrimitiveType.BOOLEAN, - List.of(Target.CPP), - (config) -> ASTUtils.toElement(config.exportToYaml), - (config, value, err) -> { - config.exportToYaml = ASTUtils.toBoolean(value); - }), - - /** - * List of module files to link into the crate as top-level. - * For instance, a {@code target Rust { rust-modules: [ "foo.rs" ] }} - * will cause the file to be copied into the generated project, - * and the generated `main.rs` will include it with a `mod foo;`. - * If one of the paths is a directory, it must contain a `mod.rs` - * file, and all its contents are copied. - */ - RUST_INCLUDE("rust-include", - UnionType.FILE_OR_FILE_ARRAY, - List.of(Target.Rust), - (config) -> { - // do not check paths here, and simply copy the absolute path over - List paths = config.rust.getRustTopLevelModules(); - if (paths.isEmpty()) return null; - else if (paths.size() == 1) { - return ASTUtils.toElement(paths.get(0).toString()); - } else { - Element e = LfFactory.eINSTANCE.createElement(); - Array arr = LfFactory.eINSTANCE.createArray(); - for (Path p : paths) { - arr.getElements().add(ASTUtils.toElement(p.toString())); - } - e.setArray(arr); - return e; - } - }, - (config, value, err) -> { - Path referencePath; - try { - referencePath = FileUtil.toPath(value.eResource().getURI()).toAbsolutePath(); - } catch (IOException e) { - err.reportError(value, "Invalid path? " + e.getMessage()); - throw new RuntimeIOException(e); - } - - // we'll resolve relative paths to check that the files - // are as expected. - - if (value.getLiteral() != null) { - Path resolved = referencePath.resolveSibling(StringUtil.removeQuotes(value.getLiteral())); - - config.rust.addAndCheckTopLevelModule(resolved, value, err); - } else if (value.getArray() != null) { - for (Element element : value.getArray().getElements()) { - String literal = StringUtil.removeQuotes(element.getLiteral()); - Path resolved = referencePath.resolveSibling(literal); - config.rust.addAndCheckTopLevelModule(resolved, element, err); - } - } - }), - - /** - * Directive for specifying Cargo features of the generated - * program to enable. - */ - CARGO_FEATURES("cargo-features", ArrayType.STRING_ARRAY, - List.of(Target.Rust), - (config) -> ASTUtils.toElement(config.rust.getCargoFeatures()), - (config, value, err) -> { - config.rust.setCargoFeatures(ASTUtils.elementToListOfStrings(value)); - }), - - /** - * Dependency specifications for Cargo. This property looks like this: - *

    {@code
    -     * cargo-dependencies: {
    -     *    // Name-of-the-crate: "version"
    -     *    rand: "0.8",
    -     *    // Equivalent to using an explicit map:
    -     *    rand: {
    -     *      version: "0.8"
    -     *    },
    -     *    // The map allows specifying more details
    -     *    rand: {
    -     *      // A path to a local unpublished crate.
    -     *      // Note 'path' is mutually exclusive with 'version'.
    -     *      path: "/home/me/Git/local-rand-clone"
    -     *    },
    -     *    rand: {
    -     *      version: "0.8",
    -     *      // you can specify cargo features
    -     *      features: ["some-cargo-feature",]
    -     *    }
    -     * }
    -     * }
    - */ - CARGO_DEPENDENCIES("cargo-dependencies", - CargoDependenciesPropertyType.INSTANCE, - List.of(Target.Rust), - (config) -> { - var deps = config.rust.getCargoDependencies(); - if (deps.size() == 0) return null; - else { - Element e = LfFactory.eINSTANCE.createElement(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (var ent : deps.entrySet()) { - KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); - pair.setName(ent.getKey()); - pair.setValue(CargoDependencySpec.extractSpec(ent.getValue())); - kvp.getPairs().add(pair); - } - e.setKeyvalue(kvp); - return e; - } - }, - (config, value, err) -> { - config.rust.setCargoDependencies(CargoDependencySpec.parseAll(value)); - }), - - /** - * Directs the C or Python target to include the associated C file used for - * setting up federated execution before processing the first tag. - */ - FED_SETUP("_fed_setup", PrimitiveType.FILE, - Arrays.asList(Target.C, Target.CCPP, Target.Python), - (config) -> ASTUtils.toElement(config.fedSetupPreamble), - (config, value, err) -> - config.fedSetupPreamble = StringUtil.removeQuotes(ASTUtils.elementToSingleString(value)) - ) - ; - - /** - * Update {@code config}.dockerOptions based on value. - */ - private static void setDockerProperty(TargetConfig config, Element value) { - if (value.getLiteral() != null) { - if (ASTUtils.toBoolean(value)) { - config.dockerOptions = new DockerOptions(); - } else { - config.dockerOptions = null; + /** Directive to allow including OpenSSL libraries and process HMAC authentication. */ + AUTH( + "auth", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.auth), + (config, value, err) -> { + config.auth = ASTUtils.toBoolean(value); + }), + /** Directive to let the generator use the custom build command. */ + BUILD( + "build", + UnionType.STRING_OR_STRING_ARRAY, + Arrays.asList(Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.buildCommands), + (config, value, err) -> { + config.buildCommands = ASTUtils.elementToListOfStrings(value); + }), + + /** + * Directive to specify the target build type such as 'Release' or 'Debug'. This is also used in + * the Rust target to select a Cargo profile. + */ + BUILD_TYPE( + "build-type", + UnionType.BUILD_TYPE_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Rust), + (config) -> ASTUtils.toElement(config.cmakeBuildType.toString()), + (config, value, err) -> { + config.cmakeBuildType = + (BuildType) UnionType.BUILD_TYPE_UNION.forName(ASTUtils.elementToSingleString(value)); + // set it there too, because the default is different. + config.rust.setBuildType(config.cmakeBuildType); + }), + + /** Directive to let the federate execution handle clock synchronization in software. */ + CLOCK_SYNC( + "clock-sync", + UnionType.CLOCK_SYNC_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.clockSync.toString()), + (config, value, err) -> { + config.clockSync = + (ClockSyncMode) + UnionType.CLOCK_SYNC_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + /** Key-value pairs giving options for clock synchronization. */ + CLOCK_SYNC_OPTIONS( + "clock-sync-options", + DictionaryType.CLOCK_SYNC_OPTION_DICT, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (ClockSyncOption opt : ClockSyncOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case ATTENUATION: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.attenuation)); + break; + case COLLECT_STATS: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.collectStats)); + break; + case LOCAL_FEDERATES_ON: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.localFederatesOn)); + break; + case PERIOD: + if (config.clockSyncOptions.period == null) continue; // don't set if null + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.period)); + break; + case TEST_OFFSET: + if (config.clockSyncOptions.testOffset == null) continue; // don't set if null + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.testOffset)); + break; + case TRIALS: + pair.setValue(ASTUtils.toElement(config.clockSyncOptions.trials)); + break; + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + // kvp will never be empty + return e; + }, + (config, value, err) -> { + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + ClockSyncOption option = + (ClockSyncOption) DictionaryType.CLOCK_SYNC_OPTION_DICT.forName(entry.getName()); + switch (option) { + case ATTENUATION: + config.clockSyncOptions.attenuation = ASTUtils.toInteger(entry.getValue()); + break; + case COLLECT_STATS: + config.clockSyncOptions.collectStats = ASTUtils.toBoolean(entry.getValue()); + break; + case LOCAL_FEDERATES_ON: + config.clockSyncOptions.localFederatesOn = ASTUtils.toBoolean(entry.getValue()); + break; + case PERIOD: + config.clockSyncOptions.period = ASTUtils.toTimeValue(entry.getValue()); + break; + case TEST_OFFSET: + config.clockSyncOptions.testOffset = ASTUtils.toTimeValue(entry.getValue()); + break; + case TRIALS: + config.clockSyncOptions.trials = ASTUtils.toInteger(entry.getValue()); + break; + default: + break; + } + } + }), + + /** + * Directive to specify a cmake to be included by the generated build systems. + * + *

    This gives full control over the C/C++ build as any cmake parameters can be adjusted in the + * included file. + */ + CMAKE_INCLUDE( + "cmake-include", + UnionType.FILE_OR_FILE_ARRAY, + Arrays.asList(Target.CPP, Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.cmakeIncludes), + (config, value, err) -> { + config.cmakeIncludes = ASTUtils.elementToListOfStrings(value); + }, + // FIXME: This merging of lists is potentially dangerous since + // the incoming list of cmake-includes can belong to a .lf file that is + // located in a different location, and keeping just filename + // strings like this without absolute paths is incorrect. + (config, value, err) -> { + config.cmakeIncludes.addAll(ASTUtils.elementToListOfStrings(value)); + }), + /** Directive to specify the target compiler. */ + COMPILER( + "compiler", + PrimitiveType.STRING, + Target.ALL, + (config) -> ASTUtils.toElement(config.compiler), + (config, value, err) -> { + config.compiler = ASTUtils.elementToSingleString(value); + }), + + /** Directive to specify compile-time definitions. */ + COMPILE_DEFINITIONS( + "compile-definitions", + StringDictionaryType.COMPILE_DEFINITION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.compileDefinitions), + (config, value, err) -> { + config.compileDefinitions = ASTUtils.elementToStringMaps(value); + }), + + /** + * Directive to generate a Dockerfile. This is either a boolean, true or false, or a dictionary of + * options. + */ + DOCKER( + "docker", + UnionType.DOCKER_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), + (config) -> { + if (config.dockerOptions == null) { + return null; + } else if (config.dockerOptions.equals(new DockerOptions())) { + // default configuration + return ASTUtils.toElement(true); + } else { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (DockerOption opt : DockerOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case FROM: + if (config.dockerOptions.from == null) continue; + pair.setValue(ASTUtils.toElement(config.dockerOptions.from)); + break; } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + } + }, + (config, value, err) -> setDockerProperty(config, value), + (config, value, err) -> setDockerProperty(config, value)), + + /** Directive for specifying a path to an external runtime to be used for the compiled binary. */ + EXTERNAL_RUNTIME_PATH( + "external-runtime-path", + PrimitiveType.STRING, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.externalRuntimePath), + (config, value, err) -> { + config.externalRuntimePath = ASTUtils.elementToSingleString(value); + }), + + /** + * Directive to let the execution engine allow logical time to elapse faster than physical time. + */ + FAST( + "fast", + PrimitiveType.BOOLEAN, + Target.ALL, + (config) -> ASTUtils.toElement(config.fastMode), + (config, value, err) -> { + config.fastMode = ASTUtils.toBoolean(value); + }), + + /** + * Directive to stage particular files on the class path to be processed by the code generator. + */ + FILES( + "files", + UnionType.FILE_OR_FILE_ARRAY, + List.of(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.files), + (config, value, err) -> { + config.files = ASTUtils.elementToListOfStrings(value); + }, + // FIXME: This merging of lists is potentially dangerous since + // the incoming list of files can belong to a .lf file that is + // located in a different location, and keeping just filename + // strings like this without absolute paths is incorrect. + (config, value, err) -> { + config.files.addAll(ASTUtils.elementToListOfStrings(value)); + }), + + /** Flags to be passed on to the target compiler. */ + FLAGS( + "flags", + UnionType.STRING_OR_STRING_ARRAY, + Arrays.asList(Target.C, Target.CCPP), + (config) -> ASTUtils.toElement(config.compilerFlags), + (config, value, err) -> { + config.compilerFlags = ASTUtils.elementToListOfStrings(value); + }), + + /** Directive to specify the coordination mode */ + COORDINATION( + "coordination", + UnionType.COORDINATION_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.coordination.toString()), + (config, value, err) -> { + config.coordination = + (CoordinationType) + UnionType.COORDINATION_UNION.forName(ASTUtils.elementToSingleString(value)); + }, + (config, value, err) -> { + config.coordination = + (CoordinationType) + UnionType.COORDINATION_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + + /** Key-value pairs giving options for clock synchronization. */ + COORDINATION_OPTIONS( + "coordination-options", + DictionaryType.COORDINATION_OPTION_DICT, + Arrays.asList(Target.C, Target.CCPP, Target.Python, Target.TS), + (config) -> { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (CoordinationOption opt : CoordinationOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case ADVANCE_MESSAGE_INTERVAL: + if (config.coordinationOptions.advance_message_interval == null) continue; + pair.setValue( + ASTUtils.toElement(config.coordinationOptions.advance_message_interval)); + break; + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + }, + (config, value, err) -> { + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + CoordinationOption option = + (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT.forName(entry.getName()); + switch (option) { + case ADVANCE_MESSAGE_INTERVAL: + config.coordinationOptions.advance_message_interval = + ASTUtils.toTimeValue(entry.getValue()); + break; + default: + break; + } + } + }, + (config, value, err) -> { + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + CoordinationOption option = + (CoordinationOption) DictionaryType.COORDINATION_OPTION_DICT.forName(entry.getName()); + switch (option) { + case ADVANCE_MESSAGE_INTERVAL: + config.coordinationOptions.advance_message_interval = + ASTUtils.toTimeValue(entry.getValue()); + break; + default: + break; + } + } + }), + + /** + * Directive to let the execution engine remain active also if there are no more events in the + * event queue. + */ + KEEPALIVE( + "keepalive", + PrimitiveType.BOOLEAN, + Target.ALL, + (config) -> ASTUtils.toElement(config.keepalive), + (config, value, err) -> { + config.keepalive = ASTUtils.toBoolean(value); + }), + + /** Directive to specify the grain at which to report log messages during execution. */ + LOGGING( + "logging", + UnionType.LOGGING_UNION, + Target.ALL, + (config) -> ASTUtils.toElement(config.logLevel.toString()), + (config, value, err) -> { + config.logLevel = + (LogLevel) UnionType.LOGGING_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + + /** Directive to not invoke the target compiler. */ + NO_COMPILE( + "no-compile", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.C, Target.CPP, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.noCompile), + (config, value, err) -> { + config.noCompile = ASTUtils.toBoolean(value); + }), + + /** Directive to disable validation of reactor rules at runtime. */ + NO_RUNTIME_VALIDATION( + "no-runtime-validation", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.noRuntimeValidation), + (config, value, err) -> { + config.noRuntimeValidation = ASTUtils.toBoolean(value); + }), + + /** + * Directive to specify the platform for cross code generation. This is either a string of the + * platform or a dictionary of options that includes the string name. + */ + PLATFORM( + "platform", + UnionType.PLATFORM_STRING_OR_DICTIONARY, + Target.ALL, + (config) -> { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (PlatformOption opt : PlatformOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case NAME: + pair.setValue(ASTUtils.toElement(config.platformOptions.platform.toString())); + break; + case BAUDRATE: + pair.setValue(ASTUtils.toElement(config.platformOptions.baudRate)); + break; + case BOARD: + pair.setValue(ASTUtils.toElement(config.platformOptions.board)); + break; + case FLASH: + pair.setValue(ASTUtils.toElement(config.platformOptions.flash)); + break; + case PORT: + pair.setValue(ASTUtils.toElement(config.platformOptions.port)); + break; + case USER_THREADS: + pair.setValue(ASTUtils.toElement(config.platformOptions.userThreads)); + break; + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + }, + (config, value, err) -> { + if (value.getLiteral() != null) { + config.platformOptions = new PlatformOptions(); + config.platformOptions.platform = + (Platform) UnionType.PLATFORM_UNION.forName(ASTUtils.elementToSingleString(value)); } else { - config.dockerOptions = new DockerOptions(); - for (KeyValuePair entry : value.getKeyvalue().getPairs()) { - DockerOption option = (DockerOption) DictionaryType.DOCKER_DICT - .forName(entry.getName()); - switch (option) { - case FROM: - config.dockerOptions.from = ASTUtils.elementToSingleString(entry.getValue()); - break; - default: - break; + config.platformOptions = new PlatformOptions(); + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + PlatformOption option = + (PlatformOption) DictionaryType.PLATFORM_DICT.forName(entry.getName()); + switch (option) { + case NAME: + Platform p = + (Platform) + UnionType.PLATFORM_UNION.forName( + ASTUtils.elementToSingleString(entry.getValue())); + if (p == null) { + String s = + "Unidentified Platform Type, LF supports the following platform types: " + + Arrays.asList(Platform.values()).toString(); + err.reportError(s); + throw new AssertionError(s); } + config.platformOptions.platform = p; + break; + case BAUDRATE: + config.platformOptions.baudRate = ASTUtils.toInteger(entry.getValue()); + break; + case BOARD: + config.platformOptions.board = ASTUtils.elementToSingleString(entry.getValue()); + break; + case FLASH: + config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()); + break; + case PORT: + config.platformOptions.port = ASTUtils.elementToSingleString(entry.getValue()); + break; + case USER_THREADS: + config.platformOptions.userThreads = ASTUtils.toInteger(entry.getValue()); + break; + default: + break; } + } + } + }), + + /** Directive to instruct the runtime to collect and print execution statistics. */ + PRINT_STATISTICS( + "print-statistics", + PrimitiveType.BOOLEAN, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.printStatistics), + (config, value, err) -> { + config.printStatistics = ASTUtils.toBoolean(value); + }), + + /** + * Directive for specifying .proto files that need to be compiled and their code included in the + * sources. + */ + PROTOBUFS( + "protobufs", + UnionType.FILE_OR_FILE_ARRAY, + Arrays.asList(Target.C, Target.CCPP, Target.TS, Target.Python), + (config) -> ASTUtils.toElement(config.protoFiles), + (config, value, err) -> { + config.protoFiles = ASTUtils.elementToListOfStrings(value); + }), + + /** Directive to specify that ROS2 specific code is generated, */ + ROS2( + "ros2", + PrimitiveType.BOOLEAN, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.ros2), + (config, value, err) -> { + config.ros2 = ASTUtils.toBoolean(value); + }), + + /** Directive to specify additional ROS2 packages that this LF program depends on. */ + ROS2_DEPENDENCIES( + "ros2-dependencies", + ArrayType.STRING_ARRAY, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.ros2Dependencies), + (config, value, err) -> { + config.ros2Dependencies = ASTUtils.elementToListOfStrings(value); + }), + + /** Directive for specifying a specific version of the reactor runtime library. */ + RUNTIME_VERSION( + "runtime-version", + PrimitiveType.STRING, + Arrays.asList(Target.CPP), + (config) -> ASTUtils.toElement(config.runtimeVersion), + (config, value, err) -> { + config.runtimeVersion = ASTUtils.elementToSingleString(value); + }), + + /** Directive for specifying a specific runtime scheduler, if supported. */ + SCHEDULER( + "scheduler", + UnionType.SCHEDULER_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.schedulerType.toString()), + (config, value, err) -> { + config.schedulerType = + (SchedulerOption) + UnionType.SCHEDULER_UNION.forName(ASTUtils.elementToSingleString(value)); + }), + + /** Directive to specify that all code is generated in a single file. */ + SINGLE_FILE_PROJECT( + "single-file-project", + PrimitiveType.BOOLEAN, + List.of(Target.Rust), + (config) -> ASTUtils.toElement(config.singleFileProject), + (config, value, err) -> { + config.singleFileProject = ASTUtils.toBoolean(value); + }), + + /** Directive to indicate whether the runtime should use multi-threading. */ + THREADING( + "threading", + PrimitiveType.BOOLEAN, + List.of(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.threading), + (config, value, err) -> { + config.threading = ASTUtils.toBoolean(value); + }), + + /** Directive to specify the number of worker threads used by the runtime. */ + WORKERS( + "workers", + PrimitiveType.NON_NEGATIVE_INTEGER, + List.of(Target.C, Target.CCPP, Target.Python, Target.CPP, Target.Rust), + (config) -> ASTUtils.toElement(config.workers), + (config, value, err) -> { + config.workers = ASTUtils.toInteger(value); + }), + + /** Directive to specify the execution timeout. */ + TIMEOUT( + "timeout", + PrimitiveType.TIME_VALUE, + Target.ALL, + (config) -> ASTUtils.toElement(config.timeout), + (config, value, err) -> { + config.timeout = ASTUtils.toTimeValue(value); + }, + (config, value, err) -> { + config.timeout = ASTUtils.toTimeValue(value); + }), + + /** Directive to enable tracing. */ + TRACING( + "tracing", + UnionType.TRACING_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), + (config) -> { + if (config.tracing == null) { + return null; + } else if (config.tracing.equals(new TracingOptions())) { + // default values + return ASTUtils.toElement(true); + } else { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (TracingOption opt : TracingOption.values()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(opt.toString()); + switch (opt) { + case TRACE_FILE_NAME: + if (config.tracing.traceFileName == null) continue; + pair.setValue(ASTUtils.toElement(config.tracing.traceFileName)); + } + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + if (kvp.getPairs().isEmpty()) return null; + return e; + } + }, + (config, value, err) -> { + if (value.getLiteral() != null) { + if (ASTUtils.toBoolean(value)) { + config.tracing = new TracingOptions(); + } else { + config.tracing = null; + } + } else { + config.tracing = new TracingOptions(); + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + TracingOption option = + (TracingOption) DictionaryType.TRACING_DICT.forName(entry.getName()); + switch (option) { + case TRACE_FILE_NAME: + config.tracing.traceFileName = ASTUtils.elementToSingleString(entry.getValue()); + break; + default: + break; + } + } + } + }), + + /** + * Directive to let the runtime export its internal dependency graph. + * + *

    This is a debugging feature and currently only used for C++ and Rust programs. + */ + EXPORT_DEPENDENCY_GRAPH( + "export-dependency-graph", + PrimitiveType.BOOLEAN, + List.of(Target.CPP, Target.Rust), + (config) -> ASTUtils.toElement(config.exportDependencyGraph), + (config, value, err) -> { + config.exportDependencyGraph = ASTUtils.toBoolean(value); + }), + + /** + * Directive to let the runtime export the program structure to a yaml file. + * + *

    This is a debugging feature and currently only used for C++ programs. + */ + EXPORT_TO_YAML( + "export-to-yaml", + PrimitiveType.BOOLEAN, + List.of(Target.CPP), + (config) -> ASTUtils.toElement(config.exportToYaml), + (config, value, err) -> { + config.exportToYaml = ASTUtils.toBoolean(value); + }), + + /** + * List of module files to link into the crate as top-level. For instance, a {@code target Rust { + * rust-modules: [ "foo.rs" ] }} will cause the file to be copied into the generated project, and + * the generated `main.rs` will include it with a `mod foo;`. If one of the paths is a directory, + * it must contain a `mod.rs` file, and all its contents are copied. + */ + RUST_INCLUDE( + "rust-include", + UnionType.FILE_OR_FILE_ARRAY, + List.of(Target.Rust), + (config) -> { + // do not check paths here, and simply copy the absolute path over + List paths = config.rust.getRustTopLevelModules(); + if (paths.isEmpty()) return null; + else if (paths.size() == 1) { + return ASTUtils.toElement(paths.get(0).toString()); + } else { + Element e = LfFactory.eINSTANCE.createElement(); + Array arr = LfFactory.eINSTANCE.createArray(); + for (Path p : paths) { + arr.getElements().add(ASTUtils.toElement(p.toString())); + } + e.setArray(arr); + return e; + } + }, + (config, value, err) -> { + Path referencePath; + try { + referencePath = FileUtil.toPath(value.eResource().getURI()).toAbsolutePath(); + } catch (IOException e) { + err.reportError(value, "Invalid path? " + e.getMessage()); + throw new RuntimeIOException(e); } - } - - /** - * String representation of this target property. - */ - public final String description; - - /** - * List of targets that support this property. If a property is used for - * a target that does not support it, a warning reported during - * validation. - */ - public final List supportedBy; - - /** - * The type of values that can be assigned to this property. - */ - public final TargetPropertyType type; - /** - * Function that given a configuration object and an Element AST node - * sets the configuration. It is assumed that validation already - * occurred, so this code should be straightforward. - */ - public final PropertyParser setter; + // we'll resolve relative paths to check that the files + // are as expected. - /** - * Function that given a configuration object and an Element AST node - * sets the configuration. It is assumed that validation already - * occurred, so this code should be straightforward. - */ - public final PropertyParser updater; + if (value.getLiteral() != null) { + Path resolved = referencePath.resolveSibling(StringUtil.removeQuotes(value.getLiteral())); + + config.rust.addAndCheckTopLevelModule(resolved, value, err); + } else if (value.getArray() != null) { + for (Element element : value.getArray().getElements()) { + String literal = StringUtil.removeQuotes(element.getLiteral()); + Path resolved = referencePath.resolveSibling(literal); + config.rust.addAndCheckTopLevelModule(resolved, element, err); + } + } + }), + + /** Directive for specifying Cargo features of the generated program to enable. */ + CARGO_FEATURES( + "cargo-features", + ArrayType.STRING_ARRAY, + List.of(Target.Rust), + (config) -> ASTUtils.toElement(config.rust.getCargoFeatures()), + (config, value, err) -> { + config.rust.setCargoFeatures(ASTUtils.elementToListOfStrings(value)); + }), + + /** + * Dependency specifications for Cargo. This property looks like this: + * + *

    {@code
    +   * cargo-dependencies: {
    +   *    // Name-of-the-crate: "version"
    +   *    rand: "0.8",
    +   *    // Equivalent to using an explicit map:
    +   *    rand: {
    +   *      version: "0.8"
    +   *    },
    +   *    // The map allows specifying more details
    +   *    rand: {
    +   *      // A path to a local unpublished crate.
    +   *      // Note 'path' is mutually exclusive with 'version'.
    +   *      path: "/home/me/Git/local-rand-clone"
    +   *    },
    +   *    rand: {
    +   *      version: "0.8",
    +   *      // you can specify cargo features
    +   *      features: ["some-cargo-feature",]
    +   *    }
    +   * }
    +   * }
    + */ + CARGO_DEPENDENCIES( + "cargo-dependencies", + CargoDependenciesPropertyType.INSTANCE, + List.of(Target.Rust), + (config) -> { + var deps = config.rust.getCargoDependencies(); + if (deps.size() == 0) return null; + else { + Element e = LfFactory.eINSTANCE.createElement(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (var ent : deps.entrySet()) { + KeyValuePair pair = LfFactory.eINSTANCE.createKeyValuePair(); + pair.setName(ent.getKey()); + pair.setValue(CargoDependencySpec.extractSpec(ent.getValue())); + kvp.getPairs().add(pair); + } + e.setKeyvalue(kvp); + return e; + } + }, + (config, value, err) -> { + config.rust.setCargoDependencies(CargoDependencySpec.parseAll(value)); + }), + + /** + * Directs the C or Python target to include the associated C file used for setting up federated + * execution before processing the first tag. + */ + FED_SETUP( + "_fed_setup", + PrimitiveType.FILE, + Arrays.asList(Target.C, Target.CCPP, Target.Python), + (config) -> ASTUtils.toElement(config.fedSetupPreamble), + (config, value, err) -> + config.fedSetupPreamble = StringUtil.removeQuotes(ASTUtils.elementToSingleString(value))); + + /** Update {@code config}.dockerOptions based on value. */ + private static void setDockerProperty(TargetConfig config, Element value) { + if (value.getLiteral() != null) { + if (ASTUtils.toBoolean(value)) { + config.dockerOptions = new DockerOptions(); + } else { + config.dockerOptions = null; + } + } else { + config.dockerOptions = new DockerOptions(); + for (KeyValuePair entry : value.getKeyvalue().getPairs()) { + DockerOption option = (DockerOption) DictionaryType.DOCKER_DICT.forName(entry.getName()); + switch (option) { + case FROM: + config.dockerOptions.from = ASTUtils.elementToSingleString(entry.getValue()); + break; + default: + break; + } + } + } + } + + /** String representation of this target property. */ + public final String description; + + /** + * List of targets that support this property. If a property is used for a target that does not + * support it, a warning reported during validation. + */ + public final List supportedBy; + + /** The type of values that can be assigned to this property. */ + public final TargetPropertyType type; + + /** + * Function that given a configuration object and an Element AST node sets the configuration. It + * is assumed that validation already occurred, so this code should be straightforward. + */ + public final PropertyParser setter; + + /** + * Function that given a configuration object and an Element AST node sets the configuration. It + * is assumed that validation already occurred, so this code should be straightforward. + */ + public final PropertyParser updater; + + @FunctionalInterface + private interface PropertyParser { + + /** + * Parse the given element into the given target config. May use the error reporter to report + * format errors. + */ + void parseIntoTargetConfig(TargetConfig config, Element element, ErrorReporter err); + } + + public final PropertyGetter getter; + + @FunctionalInterface + private interface PropertyGetter { + + /** + * Read this property from the target config and build an element which represents it for the + * AST. May return null if the given value of this property is the same as the default. + */ + Element getPropertyElement(TargetConfig config); + } + + /** + * Private constructor for target properties. + * + * @param description String representation of this property. + * @param type The type that values assigned to this property should conform to. + * @param supportedBy List of targets that support this property. + * @param setter Function for configuration updates. + */ + TargetProperty( + String description, + TargetPropertyType type, + List supportedBy, + PropertyGetter getter, + PropertyParser setter) { + this.description = description; + this.type = type; + this.supportedBy = supportedBy; + this.getter = getter; + this.setter = setter; + this.updater = setter; // (Re)set by default + } + + /** + * Private constructor for target properties. This will take an additional `updater`, which will + * be used to merge target properties from imported resources. + * + * @param description String representation of this property. + * @param type The type that values assigned to this property should conform to. + * @param supportedBy List of targets that support this property. + * @param setter Function for setting configuration values. + * @param updater Function for updating configuration values. + */ + TargetProperty( + String description, + TargetPropertyType type, + List supportedBy, + PropertyGetter getter, + PropertyParser setter, + PropertyParser updater) { + this.description = description; + this.type = type; + this.supportedBy = supportedBy; + this.getter = getter; + this.setter = setter; + this.updater = updater; + } + + /** + * Return the name of the property in lingua franca. This is suitable for use as a key in a target + * properties block. It may be an invalid identifier in other languages (may contains dashes + * {@code -}). + */ + public String getDisplayName() { + return description; + } + + /** + * Set the given configuration using the given target properties. + * + * @param config The configuration object to update. + * @param properties AST node that holds all the target properties. + * @param err Error reporter on which property format errors will be reported + */ + public static void set(TargetConfig config, List properties, ErrorReporter err) { + properties.forEach( + property -> { + TargetProperty p = forName(property.getName()); + if (p != null) { + // Mark the specified target property as set by the user + config.setByUser.add(p); + try { + p.setter.parseIntoTargetConfig(config, property.getValue(), err); + } catch (InvalidLfSourceException e) { + err.reportError(e.getNode(), e.getProblem()); + } + } + }); + } + + /** + * Extracts all properties as a list of key-value pairs from a TargetConfig. Only extracts + * properties explicitly set by user. + * + * @param config The TargetConfig to extract from. + * @return The extracted properties. + */ + public static List extractProperties(TargetConfig config) { + var res = new LinkedList(); + for (TargetProperty p : config.setByUser) { + KeyValuePair kv = LfFactory.eINSTANCE.createKeyValuePair(); + kv.setName(p.toString()); + kv.setValue(p.getter.getPropertyElement(config)); + if (kv.getValue() != null) res.add(kv); + } + return res; + } + + /** + * Constructs a TargetDecl by extracting the fields of the given TargetConfig. + * + * @param target The target to generate for. + * @param config The TargetConfig to extract from. + * @return A generated TargetDecl. + */ + public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { + TargetDecl decl = LfFactory.eINSTANCE.createTargetDecl(); + KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); + for (KeyValuePair p : extractProperties(config)) { + kvp.getPairs().add(p); + } + decl.setName(target.toString()); + decl.setConfig(kvp); + return decl; + } + + /** + * Update the given configuration using the given target properties. + * + * @param config The configuration object to update. + * @param properties AST node that holds all the target properties. + */ + public static void update(TargetConfig config, List properties, ErrorReporter err) { + properties.forEach( + property -> { + TargetProperty p = forName(property.getName()); + if (p != null) { + // Mark the specified target property as set by the user + config.setByUser.add(p); + p.updater.parseIntoTargetConfig(config, property.getValue(), err); + } + }); + } + + /** + * Update one of the target properties, given by 'propertyName'. For convenience, a list of target + * properties (e.g., taken from a file or resource) can be passed without any filtering. This + * function will do nothing if the list of target properties doesn't include the property given by + * 'propertyName'. + * + * @param config The target config to apply the update to. + * @param property The target property. + * @param properties AST node that holds all the target properties. + * @param err Error reporter on which property format errors will be reported + */ + public static void updateOne( + TargetConfig config, + TargetProperty property, + List properties, + ErrorReporter err) { + properties.stream() + .filter(p -> p.getName().equals(property.getDisplayName())) + .findFirst() + .map(KeyValuePair::getValue) + .ifPresent(value -> property.updater.parseIntoTargetConfig(config, value, err)); + } + + /** + * Return the entry that matches the given string. + * + * @param name The string to match against. + */ + public static TargetProperty forName(String name) { + return Target.match(name, TargetProperty.values()); + } + + /** + * Return a list with all target properties. + * + * @return All existing target properties. + */ + public static List getOptions() { + return Arrays.asList(TargetProperty.values()); + } + + /** Return the description. */ + @Override + public String toString() { + return this.description; + } + + // Inner classes for the various supported types. + + /** Dictionary type that allows for keys that will be interpreted as strings and string values. */ + public enum StringDictionaryType implements TargetPropertyType { + COMPILE_DEFINITION(); - @FunctionalInterface - private interface PropertyParser { + @Override + public boolean validate(Element e) { + if (e.getKeyvalue() != null) { + return true; + } + return false; + } - /** - * Parse the given element into the given target config. - * May use the error reporter to report format errors. - */ - void parseIntoTargetConfig(TargetConfig config, Element element, ErrorReporter err); + @Override + public void check(Element e, String name, LFValidator v) { + KeyValuePairs kv = e.getKeyvalue(); + if (kv == null) { + TargetPropertyType.produceError(name, this.toString(), v); + } else { + for (KeyValuePair pair : kv.getPairs()) { + String key = pair.getName(); + Element val = pair.getValue(); + + // Make sure the type is string + PrimitiveType.STRING.check(val, name + "." + key, v); + } + } } + } - public final PropertyGetter getter; + /** Interface for dictionary elements. It associates an entry with a type. */ + public interface DictionaryElement { - @FunctionalInterface - private interface PropertyGetter { + TargetPropertyType getType(); + } - /** - * Read this property from the target config and build an element which represents it for the AST. - * May return null if the given value of this property is the same as the default. - */ - Element getPropertyElement(TargetConfig config); - } + /** + * A dictionary type with a predefined set of possible keys and assignable types. + * + * @author Marten Lohstroh + */ + public enum DictionaryType implements TargetPropertyType { + CLOCK_SYNC_OPTION_DICT(Arrays.asList(ClockSyncOption.values())), + DOCKER_DICT(Arrays.asList(DockerOption.values())), + PLATFORM_DICT(Arrays.asList(PlatformOption.values())), + COORDINATION_OPTION_DICT(Arrays.asList(CoordinationOption.values())), + TRACING_DICT(Arrays.asList(TracingOption.values())); - /** - * Private constructor for target properties. - * - * @param description String representation of this property. - * @param type The type that values assigned to this property - * should conform to. - * @param supportedBy List of targets that support this property. - * @param setter Function for configuration updates. - */ - TargetProperty(String description, TargetPropertyType type, - List supportedBy, - PropertyGetter getter, - PropertyParser setter) { - this.description = description; - this.type = type; - this.supportedBy = supportedBy; - this.getter = getter; - this.setter = setter; - this.updater = setter; // (Re)set by default - } + /** The keys and assignable types that are allowed in this dictionary. */ + public List options; /** - * Private constructor for target properties. This will take an additional - * `updater`, which will be used to merge target properties from imported resources. + * A dictionary type restricted to sets of predefined keys and types of values. * - * @param description String representation of this property. - * @param type The type that values assigned to this property - * should conform to. - * @param supportedBy List of targets that support this property. - * @param setter Function for setting configuration values. - * @param updater Function for updating configuration values. - */ - TargetProperty(String description, TargetPropertyType type, - List supportedBy, - PropertyGetter getter, - PropertyParser setter, - PropertyParser updater) { - this.description = description; - this.type = type; - this.supportedBy = supportedBy; - this.getter = getter; - this.setter = setter; - this.updater = updater; - } - - /** - * Return the name of the property in lingua franca. This - * is suitable for use as a key in a target properties block. - * It may be an invalid identifier in other languages (may - * contains dashes {@code -}). + * @param options The dictionary elements allowed by this type. */ - public String getDisplayName() { - return description; + private DictionaryType(List options) { + this.options = options; } /** - * Set the given configuration using the given target properties. + * Return the dictionary element of which the key matches the given string. * - * @param config The configuration object to update. - * @param properties AST node that holds all the target properties. - * @param err Error reporter on which property format errors will be reported + * @param name The string to match against. + * @return The matching dictionary element (or null if there is none). */ - public static void set(TargetConfig config, List properties, ErrorReporter err) { - properties.forEach(property -> { - TargetProperty p = forName(property.getName()); - if (p != null) { - // Mark the specified target property as set by the user - config.setByUser.add(p); - try { - p.setter.parseIntoTargetConfig(config, property.getValue(), err); - } catch (InvalidLfSourceException e) { - err.reportError(e.getNode(), e.getProblem()); - } - } - }); + public DictionaryElement forName(String name) { + return Target.match(name, options); } - /** - * Extracts all properties as a list of key-value pairs from a TargetConfig. Only extracts properties explicitly set by user. - * @param config The TargetConfig to extract from. - * @return The extracted properties. - */ - public static List extractProperties(TargetConfig config) { - var res = new LinkedList(); - for (TargetProperty p : config.setByUser) { - KeyValuePair kv = LfFactory.eINSTANCE.createKeyValuePair(); - kv.setName(p.toString()); - kv.setValue(p.getter.getPropertyElement(config)); - if (kv.getValue() != null) - res.add(kv); + /** Recursively check that the passed in element conforms to the rules of this dictionary. */ + @Override + public void check(Element e, String name, LFValidator v) { + KeyValuePairs kv = e.getKeyvalue(); + if (kv == null) { + TargetPropertyType.produceError(name, this.toString(), v); + } else { + for (KeyValuePair pair : kv.getPairs()) { + String key = pair.getName(); + Element val = pair.getValue(); + Optional match = + this.options.stream() + .filter(element -> key.equalsIgnoreCase(element.toString())) + .findAny(); + if (match.isPresent()) { + // Make sure the type is correct, too. + TargetPropertyType type = match.get().getType(); + type.check(val, name + "." + key, v); + } else { + // No match found; report error. + TargetPropertyType.produceError(name, this.toString(), v); + } } - return res; + } } - /** - * Constructs a TargetDecl by extracting the fields of the given TargetConfig. - * @param target The target to generate for. - * @param config The TargetConfig to extract from. - * @return A generated TargetDecl. - */ - public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { - TargetDecl decl = LfFactory.eINSTANCE.createTargetDecl(); - KeyValuePairs kvp = LfFactory.eINSTANCE.createKeyValuePairs(); - for (KeyValuePair p : extractProperties(config)) { - kvp.getPairs().add(p); - } - decl.setName(target.toString()); - decl.setConfig(kvp); - return decl; + /** Return true if the given element represents a dictionary, false otherwise. */ + @Override + public boolean validate(Element e) { + if (e.getKeyvalue() != null) { + return true; + } + return false; } - /** - * Update the given configuration using the given target properties. - * - * @param config The configuration object to update. - * @param properties AST node that holds all the target properties. - */ - public static void update(TargetConfig config, List properties, ErrorReporter err) { - properties.forEach(property -> { - TargetProperty p = forName(property.getName()); - if (p != null) { - // Mark the specified target property as set by the user - config.setByUser.add(p); - p.updater.parseIntoTargetConfig(config, property.getValue(), err); - } - }); + /** Return a human-readable description of this type. */ + @Override + public String toString() { + return "a dictionary with one or more of the following keys: " + + options.stream().map(option -> option.toString()).collect(Collectors.joining(", ")); } - - /** - * Update one of the target properties, given by 'propertyName'. - * For convenience, a list of target properties (e.g., taken from - * a file or resource) can be passed without any filtering. This - * function will do nothing if the list of target properties doesn't - * include the property given by 'propertyName'. + } + /** + * A type that can assume one of several types. + * + * @author Marten Lohstroh + */ + public enum UnionType implements TargetPropertyType { + STRING_OR_STRING_ARRAY(Arrays.asList(PrimitiveType.STRING, ArrayType.STRING_ARRAY), null), + PLATFORM_STRING_OR_DICTIONARY( + Arrays.asList(PrimitiveType.STRING, DictionaryType.PLATFORM_DICT), null), + FILE_OR_FILE_ARRAY(Arrays.asList(PrimitiveType.FILE, ArrayType.FILE_ARRAY), null), + BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), + COORDINATION_UNION(Arrays.asList(CoordinationType.values()), CoordinationType.CENTRALIZED), + SCHEDULER_UNION(Arrays.asList(SchedulerOption.values()), SchedulerOption.getDefault()), + LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), + PLATFORM_UNION(Arrays.asList(Platform.values()), Platform.AUTO), + CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), ClockSyncMode.INIT), + DOCKER_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.DOCKER_DICT), null), + TRACING_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.TRACING_DICT), null); + + /** The constituents of this type union. */ + public final List> options; + + /** The default type, if there is one. */ + private final Enum defaultOption; + + /** + * Private constructor for creating unions types. * - * @param config The target config to apply the update to. - * @param property The target property. - * @param properties AST node that holds all the target properties. - * @param err Error reporter on which property format errors will be reported + * @param options The types that that are part of the union. + * @param defaultOption The default type. */ - public static void updateOne(TargetConfig config, TargetProperty property, List properties, ErrorReporter err) { - properties.stream() - .filter(p -> p.getName().equals(property.getDisplayName())) - .findFirst() - .map(KeyValuePair::getValue) - .ifPresent(value -> property.updater.parseIntoTargetConfig( - config, - value, - err - )); + private UnionType(List> options, Enum defaultOption) { + this.options = options; + this.defaultOption = defaultOption; } /** - * Return the entry that matches the given string. - * @param name The string to match against. - */ - public static TargetProperty forName(String name) { - return Target.match(name, TargetProperty.values()); - } - - /** - * Return a list with all target properties. + * Return the type among those in this type union that matches the given name. * - * @return All existing target properties. + * @param name The string to match against. + * @return The matching dictionary element (or null if there is none). */ - public static List getOptions() { - return Arrays.asList(TargetProperty.values()); + public Enum forName(String name) { + return Target.match(name, options); } - /** - * Return the description. - */ + /** Recursively check that the passed in element conforms to the rules of this union. */ @Override - public String toString() { - return this.description; + public void check(Element e, String name, LFValidator v) { + Optional> match = this.match(e); + if (match.isPresent()) { + // Go deeper if the element is an array or dictionary. + Enum type = match.get(); + if (type instanceof DictionaryType) { + ((DictionaryType) type).check(e, name, v); + } else if (type instanceof ArrayType) { + ((ArrayType) type).check(e, name, v); + } else if (type instanceof PrimitiveType) { + ((PrimitiveType) type).check(e, name, v); + } else if (!(type instanceof Enum)) { + throw new RuntimeException("Encountered an unknown type."); + } + } else { + // No match found; report error. + TargetPropertyType.produceError(name, this.toString(), v); + } } - // Inner classes for the various supported types. - /** - * Dictionary type that allows for keys that will be interpreted as strings - * and string values. + * Internal method for matching a given element against the allowable types. + * + * @param e AST node that represents the value of a target property. + * @return The matching type wrapped in an Optional object. */ - public enum StringDictionaryType implements TargetPropertyType { - COMPILE_DEFINITION(); - @Override - public boolean validate(Element e) { - if (e.getKeyvalue() != null) { - return true; - } - return false; - } - - @Override - public void check(Element e, String name, LFValidator v) { - KeyValuePairs kv = e.getKeyvalue(); - if (kv == null) { - TargetPropertyType.produceError(name, this.toString(), v); - } else { - for (KeyValuePair pair : kv.getPairs()) { - String key = pair.getName(); - Element val = pair.getValue(); - - // Make sure the type is string - PrimitiveType.STRING.check(val, name + "." + key, v); + private Optional> match(Element e) { + return this.options.stream() + .filter( + option -> { + if (option instanceof TargetPropertyType) { + return ((TargetPropertyType) option).validate(e); + } else { + return ASTUtils.elementToSingleString(e).equalsIgnoreCase(option.toString()); } - } - - } + }) + .findAny(); } /** - * Interface for dictionary elements. It associates an entry with a type. + * Return true if this union has an option that matches the given element. + * + * @param e The element to match against this type. */ - public interface DictionaryElement { - - TargetPropertyType getType(); + @Override + public boolean validate(Element e) { + if (this.match(e).isPresent()) { + return true; + } + return false; } /** - * A dictionary type with a predefined set of possible keys and assignable - * types. - * - * @author Marten Lohstroh - * + * Return a human-readable description of this type. If three is a default option, then indicate + * it. */ - public enum DictionaryType implements TargetPropertyType { - CLOCK_SYNC_OPTION_DICT(Arrays.asList(ClockSyncOption.values())), - DOCKER_DICT(Arrays.asList(DockerOption.values())), - PLATFORM_DICT(Arrays.asList(PlatformOption.values())), - COORDINATION_OPTION_DICT(Arrays.asList(CoordinationOption.values())), - TRACING_DICT(Arrays.asList(TracingOption.values())); - - /** - * The keys and assignable types that are allowed in this dictionary. - */ - public List options; - - /** - * A dictionary type restricted to sets of predefined keys and types of - * values. - * - * @param options The dictionary elements allowed by this type. - */ - private DictionaryType(List options) { - this.options = options; - } - - /** - * Return the dictionary element of which the key matches the given - * string. - * - * @param name The string to match against. - * @return The matching dictionary element (or null if there is none). - */ - public DictionaryElement forName(String name) { - return Target.match(name, options); - } - - /** - * Recursively check that the passed in element conforms to the rules of - * this dictionary. - */ - @Override - public void check(Element e, String name, LFValidator v) { - KeyValuePairs kv = e.getKeyvalue(); - if (kv == null) { - TargetPropertyType.produceError(name, this.toString(), v); - } else { - for (KeyValuePair pair : kv.getPairs()) { - String key = pair.getName(); - Element val = pair.getValue(); - Optional match = this.options.stream() - .filter(element -> key.equalsIgnoreCase(element.toString())).findAny(); - if (match.isPresent()) { - // Make sure the type is correct, too. - TargetPropertyType type = match.get().getType(); - type.check(val, name + "." + key, v); + @Override + public String toString() { + return "one of the following: " + + options.stream() + .map( + option -> { + if (option == this.defaultOption) { + return option.toString() + " (default)"; } else { - // No match found; report error. - TargetPropertyType.produceError(name, - this.toString(), v); + return option.toString(); } - } - } - } - - /** - * Return true if the given element represents a dictionary, false - * otherwise. - */ - @Override - public boolean validate(Element e) { - if (e.getKeyvalue() != null) { - return true; - } - return false; - } - - /** - * Return a human-readable description of this type. - */ - @Override - public String toString() { - return "a dictionary with one or more of the following keys: " - + options.stream().map(option -> option.toString()) - .collect(Collectors.joining(", ")); - } + }) + .collect(Collectors.joining(", ")); } - /** - * A type that can assume one of several types. - * - * @author Marten Lohstroh - * - */ - public enum UnionType implements TargetPropertyType { - STRING_OR_STRING_ARRAY( - Arrays.asList(PrimitiveType.STRING, ArrayType.STRING_ARRAY), - null), - PLATFORM_STRING_OR_DICTIONARY( - Arrays.asList(PrimitiveType.STRING, DictionaryType.PLATFORM_DICT), - null), - FILE_OR_FILE_ARRAY( - Arrays.asList(PrimitiveType.FILE, ArrayType.FILE_ARRAY), null), - BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), - COORDINATION_UNION(Arrays.asList(CoordinationType.values()), - CoordinationType.CENTRALIZED), - SCHEDULER_UNION(Arrays.asList(SchedulerOption.values()), SchedulerOption.getDefault()), - LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), - PLATFORM_UNION(Arrays.asList(Platform.values()), Platform.AUTO), - CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), - ClockSyncMode.INIT), - DOCKER_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.DOCKER_DICT), - null), - TRACING_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.TRACING_DICT), - null); - - /** - * The constituents of this type union. - */ - public final List> options; - - /** - * The default type, if there is one. - */ - private final Enum defaultOption; - - /** - * Private constructor for creating unions types. - * - * @param options The types that that are part of the union. - * @param defaultOption The default type. - */ - private UnionType(List> options, Enum defaultOption) { - this.options = options; - this.defaultOption = defaultOption; - } - - /** - * Return the type among those in this type union that matches the given - * name. - * - * @param name The string to match against. - * @return The matching dictionary element (or null if there is none). - */ - public Enum forName(String name) { - return Target.match(name, options); - } - - /** - * Recursively check that the passed in element conforms to the rules of - * this union. - */ - @Override - public void check(Element e, String name, LFValidator v) { - Optional> match = this.match(e); - if (match.isPresent()) { - // Go deeper if the element is an array or dictionary. - Enum type = match.get(); - if (type instanceof DictionaryType) { - ((DictionaryType) type).check(e, name, v); - } else if (type instanceof ArrayType) { - ((ArrayType) type).check(e, name, v); - } else if (type instanceof PrimitiveType) { - ((PrimitiveType) type).check(e, name, v); - } else if (!(type instanceof Enum)) { - throw new RuntimeException("Encountered an unknown type."); - } - } else { - // No match found; report error. - TargetPropertyType.produceError(name, this.toString(), v); - } - } - - /** - * Internal method for matching a given element against the allowable - * types. - * - * @param e AST node that represents the value of a target property. - * @return The matching type wrapped in an Optional object. - */ - private Optional> match(Element e) { - return this.options.stream().filter(option -> { - if (option instanceof TargetPropertyType) { - return ((TargetPropertyType) option).validate(e); - } else { - return ASTUtils.elementToSingleString(e) - .equalsIgnoreCase(option.toString()); - } - }).findAny(); - } + } - /** - * Return true if this union has an option that matches the given - * element. - * @param e The element to match against this type. - */ - @Override - public boolean validate(Element e) { - if (this.match(e).isPresent()) { - return true; - } - return false; - } - - /** - * Return a human-readable description of this type. If three is a - * default option, then indicate it. - */ - @Override - public String toString() { - return "one of the following: " + options.stream().map(option -> { - if (option == this.defaultOption) { - return option.toString() + " (default)"; - } else { - return option.toString(); - } - }).collect(Collectors.joining(", ")); - } + /** + * An array type of which the elements confirm to a given type. + * + * @author Marten Lohstroh + */ + public enum ArrayType implements TargetPropertyType { + STRING_ARRAY(PrimitiveType.STRING), + FILE_ARRAY(PrimitiveType.FILE); - } + /** Type parameter of this array type. */ + public TargetPropertyType type; /** - * An array type of which the elements confirm to a given type. - * - * @author Marten Lohstroh + * Private constructor to create a new array type. * + * @param type The type of elements in the array. */ - public enum ArrayType implements TargetPropertyType { - STRING_ARRAY(PrimitiveType.STRING), - FILE_ARRAY(PrimitiveType.FILE); - - /** - * Type parameter of this array type. - */ - public TargetPropertyType type; - - /** - * Private constructor to create a new array type. - * - * @param type The type of elements in the array. - */ - private ArrayType(TargetPropertyType type) { - this.type = type; - } - - /** - * Check that the passed in element represents an array and ensure that - * its elements are all of the correct type. - */ - @Override - public void check(Element e, String name, LFValidator v) { - Array array = e.getArray(); - if (array == null) { - TargetPropertyType.produceError(name, this.toString(), v); - } else { - List elements = array.getElements(); - for (int i = 0; i < elements.size(); i++) { - this.type.check(elements.get(i), name + "[" + i + "]", v); - } - } - } - - /** - * Return true of the given element is an array. - */ - @Override - public boolean validate(Element e) { - if (e.getArray() != null) { - return true; - } - return false; - } - - /** - * Return a human-readable description of this type. - */ - @Override - public String toString() { - return "an array of which each element is " + this.type.toString(); - } + private ArrayType(TargetPropertyType type) { + this.type = type; } /** - * Enumeration of Cmake build types. These are also mapped - * to Cargo profiles for the Rust target (see {@link org.lflang.generator.rust.RustTargetConfig}) - * - * @author Christian Menard + * Check that the passed in element represents an array and ensure that its elements are all of + * the correct type. */ - public enum BuildType { - RELEASE("Release"), - DEBUG("Debug"), - TEST("Test"), - REL_WITH_DEB_INFO("RelWithDebInfo"), - MIN_SIZE_REL("MinSizeRel"); - - /** - * Alias used in toString method. - */ - private final String alias; - - /** - * Private constructor for Cmake build types. - */ - BuildType(String alias) { - this.alias = alias; + @Override + public void check(Element e, String name, LFValidator v) { + Array array = e.getArray(); + if (array == null) { + TargetPropertyType.produceError(name, this.toString(), v); + } else { + List elements = array.getElements(); + for (int i = 0; i < elements.size(); i++) { + this.type.check(elements.get(i), name + "[" + i + "]", v); } + } + } - /** - * Return the alias. - */ - @Override - public String toString() { - return this.alias; - } + /** Return true of the given element is an array. */ + @Override + public boolean validate(Element e) { + if (e.getArray() != null) { + return true; + } + return false; } - /** - * Enumeration of coordination types. - * - * @author Marten Lohstroh - */ - public enum CoordinationType { - CENTRALIZED, DECENTRALIZED; - - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } + /** Return a human-readable description of this type. */ + @Override + public String toString() { + return "an array of which each element is " + this.type.toString(); + } + } + + /** + * Enumeration of Cmake build types. These are also mapped to Cargo profiles for the Rust target + * (see {@link org.lflang.generator.rust.RustTargetConfig}) + * + * @author Christian Menard + */ + public enum BuildType { + RELEASE("Release"), + DEBUG("Debug"), + TEST("Test"), + REL_WITH_DEB_INFO("RelWithDebInfo"), + MIN_SIZE_REL("MinSizeRel"); + + /** Alias used in toString method. */ + private final String alias; + + /** Private constructor for Cmake build types. */ + BuildType(String alias) { + this.alias = alias; + } + + /** Return the alias. */ + @Override + public String toString() { + return this.alias; + } + } + + /** + * Enumeration of coordination types. + * + * @author Marten Lohstroh + */ + public enum CoordinationType { + CENTRALIZED, + DECENTRALIZED; + + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); + } + } + + /** + * Enumeration of clock synchronization modes. + * + *

    - OFF: The clock synchronization is universally off. - STARTUP: Clock synchronization occurs + * at startup only. - ON: Clock synchronization occurs at startup and at runtime. + * + * @author Edward A. Lee + */ + public enum ClockSyncMode { + OFF, + INIT, + ON; // TODO Discuss initial in now a mode keyword (same as startup) and cannot be used as target + // property value, thus changed it to init + // FIXME I could not test if this change breaks anything + + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); } + } + /** + * An interface for types associated with target properties. + * + * @author Marten Lohstroh + */ + public interface TargetPropertyType { /** - * Enumeration of clock synchronization modes. + * Return true if the the given Element is a valid instance of this type. * - * - OFF: The clock synchronization is universally off. - * - STARTUP: Clock synchronization occurs at startup only. - * - ON: Clock synchronization occurs at startup and at runtime. - * - * @author Edward A. Lee + * @param e The Element to validate. + * @return True if the element conforms to this type, false otherwise. */ - public enum ClockSyncMode { - OFF, INIT, ON; // TODO Discuss initial in now a mode keyword (same as startup) and cannot be used as target property value, thus changed it to init - // FIXME I could not test if this change breaks anything - - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } - } + public boolean validate(Element e); /** - * An interface for types associated with target properties. + * Check (recursively) the given Element against its associated type(s) and add found problems + * to the given list of errors. * - * @author Marten Lohstroh + * @param e The Element to type check. + * @param name The name of the target property. + * @param v A reference to the validator to report errors to. */ - public interface TargetPropertyType { - - /** - * Return true if the the given Element is a valid instance of this - * type. - * - * @param e The Element to validate. - * @return True if the element conforms to this type, false otherwise. - */ - public boolean validate(Element e); - - /** - * Check (recursively) the given Element against its associated type(s) - * and add found problems to the given list of errors. - * - * @param e The Element to type check. - * @param name The name of the target property. - * @param v A reference to the validator to report errors to. - */ - public void check(Element e, String name, LFValidator v); - - /** - * Helper function to produce an error during type checking. - * - * @param name The description of the target property. - * @param description The description of the type. - * @param v A reference to the validator to report errors to. - */ - public static void produceError(String name, String description, - LFValidator v) { - v.getTargetPropertyErrors().add("Target property '" + name - + "' is required to be " + description + "."); - } - } + public void check(Element e, String name, LFValidator v); /** - * Primitive types for target properties, each with a description used in - * error messages and predicate used for validating values. + * Helper function to produce an error during type checking. * - * @author Marten Lohstroh + * @param name The description of the target property. + * @param description The description of the type. + * @param v A reference to the validator to report errors to. */ - public enum PrimitiveType implements TargetPropertyType { - BOOLEAN("'true' or 'false'", - v -> ASTUtils.elementToSingleString(v).equalsIgnoreCase("true") - || ASTUtils.elementToSingleString(v).equalsIgnoreCase("false")), - INTEGER("an integer", v -> { - try { - Integer.parseInt(ASTUtils.elementToSingleString(v)); - } catch (NumberFormatException e) { - return false; - } - return true; + public static void produceError(String name, String description, LFValidator v) { + v.getTargetPropertyErrors() + .add("Target property '" + name + "' is required to be " + description + "."); + } + } + + /** + * Primitive types for target properties, each with a description used in error messages and + * predicate used for validating values. + * + * @author Marten Lohstroh + */ + public enum PrimitiveType implements TargetPropertyType { + BOOLEAN( + "'true' or 'false'", + v -> + ASTUtils.elementToSingleString(v).equalsIgnoreCase("true") + || ASTUtils.elementToSingleString(v).equalsIgnoreCase("false")), + INTEGER( + "an integer", + v -> { + try { + Integer.parseInt(ASTUtils.elementToSingleString(v)); + } catch (NumberFormatException e) { + return false; + } + return true; }), - NON_NEGATIVE_INTEGER("a non-negative integer", v -> { - try { - int result = Integer.parseInt(ASTUtils.elementToSingleString(v)); - if (result < 0) - return false; - } catch (NumberFormatException e) { - return false; - } - return true; + NON_NEGATIVE_INTEGER( + "a non-negative integer", + v -> { + try { + int result = Integer.parseInt(ASTUtils.elementToSingleString(v)); + if (result < 0) return false; + } catch (NumberFormatException e) { + return false; + } + return true; }), - TIME_VALUE("a time value with units", v -> - v.getKeyvalue() == null && v.getArray() == null - && v.getLiteral() == null && v.getId() == null + TIME_VALUE( + "a time value with units", + v -> + v.getKeyvalue() == null + && v.getArray() == null + && v.getLiteral() == null + && v.getId() == null && (v.getTime() == 0 || v.getUnit() != null)), - STRING("a string", v -> v.getLiteral() != null && !isCharLiteral(v.getLiteral()) || v.getId() != null), - FILE("a path to a file", STRING.validator); - - /** - * A description of this type, featured in error messages. - */ - private final String description; - - /** - * A predicate for determining whether a given Element conforms to this - * type. - */ - public final Predicate validator; - - /** - * Private constructor to create a new primitive type. - * @param description A textual description of the type that should - * start with "a/an". - * @param validator A predicate that returns true if a given Element - * conforms to this type. - */ - private PrimitiveType(String description, - Predicate validator) { - this.description = description; - this.validator = validator; - } + STRING( + "a string", + v -> v.getLiteral() != null && !isCharLiteral(v.getLiteral()) || v.getId() != null), + FILE("a path to a file", STRING.validator); - /** - * Return true if the the given Element is a valid instance of this type. - */ - public boolean validate(Element e) { - return this.validator.test(e); - } + /** A description of this type, featured in error messages. */ + private final String description; - /** - * Check (recursively) the given Element against its associated type(s) - * and add found problems to the given list of errors. - * - * @param e The element to type check. - * @param name The name of the target property. - * @param v The LFValidator to append errors to. - */ - public void check(Element e, String name, LFValidator v) { - if (!this.validate(e)) { - TargetPropertyType.produceError(name, this.description, v); - } - // If this is a file, perform an additional check to make sure - // the file actually exists. - // FIXME: premature because we first need a mechanism for looking up files! - // Looking in the same directory is too restrictive. Disabling this check for now. - /* - if (this == FILE) { - String file = ASTUtils.toSingleString(e); - - if (!FileConfig.fileExists(file, FileConfig.toPath(e.eResource().getURI()).toFile().getParent())) { - v.targetPropertyWarnings - .add("Could not find file: '" + file + "'."); - } - } - */ - } - - /** - * Return a textual description of this type. - */ - @Override - public String toString() { - return this.description; - } - - - private static boolean isCharLiteral(String s) { - return s.length() > 2 - && '\'' == s.charAt(0) - && '\'' == s.charAt(s.length() - 1); - } - } + /** A predicate for determining whether a given Element conforms to this type. */ + public final Predicate validator; /** - * Clock synchronization options. - * @author Marten Lohstroh + * Private constructor to create a new primitive type. + * + * @param description A textual description of the type that should start with "a/an". + * @param validator A predicate that returns true if a given Element conforms to this type. */ - public enum ClockSyncOption implements DictionaryElement { - ATTENUATION("attenuation", PrimitiveType.NON_NEGATIVE_INTEGER), - LOCAL_FEDERATES_ON("local-federates-on", PrimitiveType.BOOLEAN), - PERIOD("period", PrimitiveType.TIME_VALUE), - TEST_OFFSET("test-offset", PrimitiveType.TIME_VALUE), - TRIALS("trials", PrimitiveType.NON_NEGATIVE_INTEGER), - COLLECT_STATS("collect-stats", PrimitiveType.BOOLEAN); - - public final PrimitiveType type; - - private final String description; - - private ClockSyncOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } - - - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + private PrimitiveType(String description, Predicate validator) { + this.description = description; + this.validator = validator; + } - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + /** Return true if the the given Element is a valid instance of this type. */ + public boolean validate(Element e) { + return this.validator.test(e); } /** - * Docker options. - * @author Edward A. Lee - */ - public enum DockerOption implements DictionaryElement { - FROM("FROM", PrimitiveType.STRING); - - public final PrimitiveType type; - - private final String description; - - private DockerOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } - - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + * Check (recursively) the given Element against its associated type(s) and add found problems + * to the given list of errors. + * + * @param e The element to type check. + * @param name The name of the target property. + * @param v The LFValidator to append errors to. + */ + public void check(Element e, String name, LFValidator v) { + if (!this.validate(e)) { + TargetPropertyType.produceError(name, this.description, v); + } + // If this is a file, perform an additional check to make sure + // the file actually exists. + // FIXME: premature because we first need a mechanism for looking up files! + // Looking in the same directory is too restrictive. Disabling this check for now. + /* + if (this == FILE) { + String file = ASTUtils.toSingleString(e); + + if (!FileConfig.fileExists(file, FileConfig.toPath(e.eResource().getURI()).toFile().getParent())) { + v.targetPropertyWarnings + .add("Could not find file: '" + file + "'."); + } + } + */ + } - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + /** Return a textual description of this type. */ + @Override + public String toString() { + return this.description; } + private static boolean isCharLiteral(String s) { + return s.length() > 2 && '\'' == s.charAt(0) && '\'' == s.charAt(s.length() - 1); + } + } + + /** + * Clock synchronization options. + * + * @author Marten Lohstroh + */ + public enum ClockSyncOption implements DictionaryElement { + ATTENUATION("attenuation", PrimitiveType.NON_NEGATIVE_INTEGER), + LOCAL_FEDERATES_ON("local-federates-on", PrimitiveType.BOOLEAN), + PERIOD("period", PrimitiveType.TIME_VALUE), + TEST_OFFSET("test-offset", PrimitiveType.TIME_VALUE), + TRIALS("trials", PrimitiveType.NON_NEGATIVE_INTEGER), + COLLECT_STATS("collect-stats", PrimitiveType.BOOLEAN); + + public final PrimitiveType type; + + private final String description; + + private ClockSyncOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; + } - /** - * Platform options. - * @author Anirudh Rengarajan - */ - public enum PlatformOption implements DictionaryElement { - NAME("name", PrimitiveType.STRING), - BAUDRATE("baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), - BOARD("board", PrimitiveType.STRING), - FLASH("flash", PrimitiveType.BOOLEAN), - PORT("port", PrimitiveType.STRING), - USER_THREADS("user-threads", PrimitiveType.NON_NEGATIVE_INTEGER); + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; + } - public final PrimitiveType type; + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } - private final String description; + /** + * Docker options. + * + * @author Edward A. Lee + */ + public enum DockerOption implements DictionaryElement { + FROM("FROM", PrimitiveType.STRING); - private PlatformOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } + public final PrimitiveType type; + private final String description; - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + private DockerOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; + } - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; } - /** - * Coordination options. - * @author Edward A. Lee - */ - public enum CoordinationOption implements DictionaryElement { - ADVANCE_MESSAGE_INTERVAL("advance-message-interval", PrimitiveType.TIME_VALUE); + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } + + /** + * Platform options. + * + * @author Anirudh Rengarajan + */ + public enum PlatformOption implements DictionaryElement { + NAME("name", PrimitiveType.STRING), + BAUDRATE("baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), + BOARD("board", PrimitiveType.STRING), + FLASH("flash", PrimitiveType.BOOLEAN), + PORT("port", PrimitiveType.STRING), + USER_THREADS("user-threads", PrimitiveType.NON_NEGATIVE_INTEGER); + + public final PrimitiveType type; + + private final String description; + + private PlatformOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; + } - public final PrimitiveType type; + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; + } - private final String description; + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } - private CoordinationOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } + /** + * Coordination options. + * + * @author Edward A. Lee + */ + public enum CoordinationOption implements DictionaryElement { + ADVANCE_MESSAGE_INTERVAL("advance-message-interval", PrimitiveType.TIME_VALUE); + public final PrimitiveType type; - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + private final String description; - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + private CoordinationOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; } - /** - * Log levels in descending order of severity. - * @author Marten Lohstroh - */ - public enum LogLevel { - ERROR, WARN, INFO, LOG, DEBUG; - - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; } - /** - * Enumeration of supported platforms - */ - public enum Platform { - AUTO, - ARDUINO, - NRF52("Nrf52"), - LINUX("Linux"), - MAC("Darwin"), - ZEPHYR("Zephyr"), - WINDOWS("Windows"); - - String cMakeName; - Platform() { - this.cMakeName = this.toString(); - } - Platform(String cMakeName) { - this.cMakeName = cMakeName; - } + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } + + /** + * Log levels in descending order of severity. + * + * @author Marten Lohstroh + */ + public enum LogLevel { + ERROR, + WARN, + INFO, + LOG, + DEBUG; + + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); + } + } + + /** Enumeration of supported platforms */ + public enum Platform { + AUTO, + ARDUINO, + NRF52("Nrf52"), + LINUX("Linux"), + MAC("Darwin"), + ZEPHYR("Zephyr"), + WINDOWS("Windows"); + + String cMakeName; + + Platform() { + this.cMakeName = this.toString(); + } - /** - * Return the name in lower case. - */ - @Override - public String toString() { - return this.name().toLowerCase(); - } + Platform(String cMakeName) { + this.cMakeName = cMakeName; + } - /** - * Get the CMake name for the platform. - */ - public String getcMakeName() { - return this.cMakeName; - } + /** Return the name in lower case. */ + @Override + public String toString() { + return this.name().toLowerCase(); } - /** - * Supported schedulers. - * @author Soroush Bateni - */ - public enum SchedulerOption { - NP(false), // Non-preemptive - ADAPTIVE(false, List.of( + /** Get the CMake name for the platform. */ + public String getcMakeName() { + return this.cMakeName; + } + } + + /** + * Supported schedulers. + * + * @author Soroush Bateni + */ + public enum SchedulerOption { + NP(false), // Non-preemptive + ADAPTIVE( + false, + List.of( Path.of("scheduler_adaptive.c"), Path.of("worker_assignments.h"), Path.of("worker_states.h"), - Path.of("data_collection.h") - )), - GEDF_NP(true), // Global EDF non-preemptive - GEDF_NP_CI(true); // Global EDF non-preemptive with chain ID - // PEDF_NP(true); // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) - - /** - * Indicate whether or not the scheduler prioritizes reactions by deadline. - */ - private final boolean prioritizesDeadline; - - /** Relative paths to files required by this scheduler. */ - private final List relativePaths; - - SchedulerOption(boolean prioritizesDeadline) { - this(prioritizesDeadline, null); - } + Path.of("data_collection.h"))), + GEDF_NP(true), // Global EDF non-preemptive + GEDF_NP_CI(true); // Global EDF non-preemptive with chain ID + // PEDF_NP(true); // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) - SchedulerOption(boolean prioritizesDeadline, List relativePaths) { - this.prioritizesDeadline = prioritizesDeadline; - this.relativePaths = relativePaths; - } + /** Indicate whether or not the scheduler prioritizes reactions by deadline. */ + private final boolean prioritizesDeadline; - /** - * Return true if the scheduler prioritizes reactions by deadline. - */ - public boolean prioritizesDeadline() { - return this.prioritizesDeadline; - } + /** Relative paths to files required by this scheduler. */ + private final List relativePaths; - public List getRelativePaths() { - return relativePaths != null ? ImmutableList.copyOf(relativePaths) : - List.of(Path.of("scheduler_" + this + ".c")); - } + SchedulerOption(boolean prioritizesDeadline) { + this(prioritizesDeadline, null); + } - public static SchedulerOption getDefault() { - return NP; - } + SchedulerOption(boolean prioritizesDeadline, List relativePaths) { + this.prioritizesDeadline = prioritizesDeadline; + this.relativePaths = relativePaths; } - /** - * Tracing options. - * @author Edward A. Lee - */ - public enum TracingOption implements DictionaryElement { - TRACE_FILE_NAME("trace-file-name", PrimitiveType.STRING); + /** Return true if the scheduler prioritizes reactions by deadline. */ + public boolean prioritizesDeadline() { + return this.prioritizesDeadline; + } - public final PrimitiveType type; + public List getRelativePaths() { + return relativePaths != null + ? ImmutableList.copyOf(relativePaths) + : List.of(Path.of("scheduler_" + this + ".c")); + } - private final String description; + public static SchedulerOption getDefault() { + return NP; + } + } - private TracingOption(String alias, PrimitiveType type) { - this.description = alias; - this.type = type; - } + /** + * Tracing options. + * + * @author Edward A. Lee + */ + public enum TracingOption implements DictionaryElement { + TRACE_FILE_NAME("trace-file-name", PrimitiveType.STRING); - /** - * Return the description of this dictionary element. - */ - @Override - public String toString() { - return this.description; - } + public final PrimitiveType type; - /** - * Return the type associated with this dictionary element. - */ - public TargetPropertyType getType() { - return this.type; - } + private final String description; + + private TracingOption(String alias, PrimitiveType type) { + this.description = alias; + this.type = type; } + /** Return the description of this dictionary element. */ + @Override + public String toString() { + return this.description; + } + + /** Return the type associated with this dictionary element. */ + public TargetPropertyType getType() { + return this.type; + } + } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 01adccc8ca..0f9c25952c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1,26 +1,26 @@ /************* -Copyright (c) 2019-2021, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ + * Copyright (c) 2019-2021, The University of California at Berkeley. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ***************/ package org.lflang.generator.c; @@ -34,6 +34,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import static org.lflang.ASTUtils.toText; import static org.lflang.util.StringUtil.addDoubleQuotes; +import com.google.common.collect.Iterables; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -44,35 +45,28 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; - import org.lflang.ASTUtils; -import org.lflang.generator.CodeMap; -import org.lflang.generator.DockerComposeGenerator; import org.lflang.FileConfig; import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; import org.lflang.TargetProperty.PlatformOption; - -import org.lflang.federated.extensions.CExtensionUtils; - import org.lflang.ast.DelayedConnectionTransformation; - +import org.lflang.federated.extensions.CExtensionUtils; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.CodeMap; +import org.lflang.generator.DelayBodyGenerator; +import org.lflang.generator.DockerComposeGenerator; import org.lflang.generator.DockerGenerator; import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorUtils; - -import org.lflang.generator.DelayBodyGenerator; - import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFResource; import org.lflang.generator.ParameterInstance; @@ -87,7 +81,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Mode; -import org.lflang.lf.Model; import org.lflang.lf.Port; import org.lflang.lf.Preamble; import org.lflang.lf.Reaction; @@ -98,201 +91,168 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; -import com.google.common.collect.Iterables; - /** - * Generator for C target. This class generates C code defining each reactor - * class given in the input .lf file and imported .lf files. The generated code - * has the following components: + * Generator for C target. This class generates C code defining each reactor class given in the + * input .lf file and imported .lf files. The generated code has the following components: * - * * A typedef for inputs, outputs, and actions of each reactor class. These - * define the types of the variables that reactions use to access inputs and - * action values and to set output values. + *

    * A typedef for inputs, outputs, and actions of each reactor class. These define the types of + * the variables that reactions use to access inputs and action values and to set output values. * - * * A typedef for a "self" struct for each reactor class. One instance of this - * struct will be created for each reactor instance. See below for details. + *

    * A typedef for a "self" struct for each reactor class. One instance of this struct will be + * created for each reactor instance. See below for details. * - * * A function definition for each reaction in each reactor class. These - * functions take an instance of the self struct as an argument. + *

    * A function definition for each reaction in each reactor class. These functions take an + * instance of the self struct as an argument. * - * * A constructor function for each reactor class. This is used to create - * a new instance of the reactor. + *

    * A constructor function for each reactor class. This is used to create a new instance of the + * reactor. * - * After these, the main generated function is `_lf_initialize_trigger_objects()`. - * This function creates the instances of reactors (using their constructors) - * and makes connections between them. + *

    After these, the main generated function is `_lf_initialize_trigger_objects()`. This function + * creates the instances of reactors (using their constructors) and makes connections between them. * - * A few other smaller functions are also generated. + *

    A few other smaller functions are also generated. * - * ## Self Struct + *

    ## Self Struct * - * The "self" struct has fields for each of the following: + *

    The "self" struct has fields for each of the following: * - * * parameter: the field name and type match the parameter. - * * state: the field name and type match the state. - * * action: the field name prepends the action name with "_lf_". - * A second field for the action is also created to house the trigger_t object. - * That second field prepends the action name with "_lf__". - * * output: the field name prepends the output name with "_lf_". - * * input: the field name prepends the output name with "_lf_". - * A second field for the input is also created to house the trigger_t object. - * That second field prepends the input name with "_lf__". + *

    * parameter: the field name and type match the parameter. * state: the field name and type + * match the state. * action: the field name prepends the action name with "_lf_". A second field + * for the action is also created to house the trigger_t object. That second field prepends the + * action name with "_lf__". * output: the field name prepends the output name with "_lf_". * input: + * the field name prepends the output name with "_lf_". A second field for the input is also created + * to house the trigger_t object. That second field prepends the input name with "_lf__". * - * If, in addition, the reactor contains other reactors and reacts to their outputs, - * then there will be a struct within the self struct for each such contained reactor. - * The name of that self struct will be the name of the contained reactor prepended with "_lf_". - * That inside struct will contain pointers the outputs of the contained reactors - * that are read together with pointers to booleans indicating whether those outputs are present. + *

    If, in addition, the reactor contains other reactors and reacts to their outputs, then there + * will be a struct within the self struct for each such contained reactor. The name of that self + * struct will be the name of the contained reactor prepended with "_lf_". That inside struct will + * contain pointers the outputs of the contained reactors that are read together with pointers to + * booleans indicating whether those outputs are present. * - * If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to - * trigger_t object (see reactor.h) for the shutdown event and an action struct named - * _lf_shutdown on the self struct. + *

    If, in addition, the reactor has a reaction to shutdown, then there will be a pointer to + * trigger_t object (see reactor.h) for the shutdown event and an action struct named _lf_shutdown + * on the self struct. * - * ## Reaction Functions + *

    ## Reaction Functions * - * For each reaction in a reactor class, this generator will produce a C function - * that expects a pointer to an instance of the "self" struct as an argument. - * This function will contain verbatim the C code specified in the reaction, but - * before that C code, the generator inserts a few lines of code that extract from the - * self struct the variables that that code has declared it will use. For example, if - * the reaction declares that it is triggered by or uses an input named "x" of type - * int, the function will contain a line like this: - * ``` - * r_x_t* x = self->_lf_x; - * ``` - * where `r` is the full name of the reactor class and the struct type `r_x_t` - * has fields `is_present` and `value`, where the type of `value` matches the port type. - * If the programmer fails to declare that it uses x, then the absence of the - * above code will trigger a compile error when the verbatim code attempts to read `x`. + *

    For each reaction in a reactor class, this generator will produce a C function that expects a + * pointer to an instance of the "self" struct as an argument. This function will contain verbatim + * the C code specified in the reaction, but before that C code, the generator inserts a few lines + * of code that extract from the self struct the variables that that code has declared it will use. + * For example, if the reaction declares that it is triggered by or uses an input named "x" of type + * int, the function will contain a line like this: ``` r_x_t* x = self->_lf_x; ``` where `r` is the + * full name of the reactor class and the struct type `r_x_t` has fields `is_present` and `value`, + * where the type of `value` matches the port type. If the programmer fails to declare that it uses + * x, then the absence of the above code will trigger a compile error when the verbatim code + * attempts to read `x`. * - * ## Constructor + *

    ## Constructor * - * For each reactor class, this generator will create a constructor function named - * `new_r`, where `r` is the reactor class name. This function will malloc and return - * a pointer to an instance of the "self" struct. This struct initially represents - * an unconnected reactor. To establish connections between reactors, additional - * information needs to be inserted (see below). The self struct is made visible - * to the body of a reaction as a variable named "self". The self struct contains the - * following: + *

    For each reactor class, this generator will create a constructor function named `new_r`, where + * `r` is the reactor class name. This function will malloc and return a pointer to an instance of + * the "self" struct. This struct initially represents an unconnected reactor. To establish + * connections between reactors, additional information needs to be inserted (see below). The self + * struct is made visible to the body of a reaction as a variable named "self". The self struct + * contains the following: * - * * Parameters: For each parameter `p` of the reactor, there will be a field `p` - * with the type and value of the parameter. So C code in the body of a reaction - * can access parameter values as `self->p`. + *

    * Parameters: For each parameter `p` of the reactor, there will be a field `p` with the type + * and value of the parameter. So C code in the body of a reaction can access parameter values as + * `self->p`. * - * * State variables: For each state variable `s` of the reactor, there will be a field `s` - * with the type and value of the state variable. So C code in the body of a reaction - * can access state variables as `self->s`. + *

    * State variables: For each state variable `s` of the reactor, there will be a field `s` with + * the type and value of the state variable. So C code in the body of a reaction can access state + * variables as `self->s`. * - * The self struct also contains various fields that the user is not intended to - * use. The names of these fields begin with at least two underscores. They are: + *

    The self struct also contains various fields that the user is not intended to use. The names + * of these fields begin with at least two underscores. They are: * - * * Outputs: For each output named `out`, there will be a field `_lf_out` that is - * a struct containing a value field whose type matches that of the output. - * The output value is stored here. That struct also has a field `is_present` - * that is a boolean indicating whether the output has been set. - * This field is reset to false at the start of every time - * step. There is also a field `num_destinations` whose value matches the - * number of downstream reactors that use this variable. This field must be - * set when connections are made or changed. It is used to determine for - * a mutable input destination whether a copy needs to be made. + *

    * Outputs: For each output named `out`, there will be a field `_lf_out` that is a struct + * containing a value field whose type matches that of the output. The output value is stored here. + * That struct also has a field `is_present` that is a boolean indicating whether the output has + * been set. This field is reset to false at the start of every time step. There is also a field + * `num_destinations` whose value matches the number of downstream reactors that use this variable. + * This field must be set when connections are made or changed. It is used to determine for a + * mutable input destination whether a copy needs to be made. * - * * Inputs: For each input named `in` of type T, there is a field named `_lf_in` - * that is a pointer struct with a value field of type T. The struct pointed - * to also has an `is_present` field of type bool that indicates whether the - * input is present. + *

    * Inputs: For each input named `in` of type T, there is a field named `_lf_in` that is a + * pointer struct with a value field of type T. The struct pointed to also has an `is_present` field + * of type bool that indicates whether the input is present. * - * * Outputs of contained reactors: If a reactor reacts to outputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields pointing to those outputs. For example, - * if `r` has an output `out` of type T, then there will be field in `_lf_r` - * named `out` that points to a struct containing a value field - * of type T and a field named `is_present` of type bool. + *

    * Outputs of contained reactors: If a reactor reacts to outputs of a contained reactor `r`, + * then the self struct will contain a nested struct named `_lf_r` that has fields pointing to those + * outputs. For example, if `r` has an output `out` of type T, then there will be field in `_lf_r` + * named `out` that points to a struct containing a value field of type T and a field named + * `is_present` of type bool. * - * * Inputs of contained reactors: If a reactor sends to inputs of a - * contained reactor `r`, then the self struct will contain a nested struct - * named `_lf_r` that has fields for storing the values provided to those - * inputs. For example, if R has an input `in` of type T, then there will - * be field in _lf_R named `in` that is a struct with a value field - * of type T and a field named `is_present` of type bool. + *

    * Inputs of contained reactors: If a reactor sends to inputs of a contained reactor `r`, then + * the self struct will contain a nested struct named `_lf_r` that has fields for storing the values + * provided to those inputs. For example, if R has an input `in` of type T, then there will be field + * in _lf_R named `in` that is a struct with a value field of type T and a field named `is_present` + * of type bool. * - * * Actions: If the reactor has an action a (logical or physical), then there - * will be a field in the self struct named `_lf_a` and another named `_lf__a`. - * The type of the first is specific to the action and contains a `value` - * field with the type and value of the action (if it has a value). That - * struct also has a `has_value` field, an `is_present` field, and a - * `token` field (which is NULL if the action carries no value). - * The `_lf__a` field is of type trigger_t. - * That struct contains various things, including an array of reactions - * sensitive to this trigger and a lf_token_t struct containing the value of - * the action, if it has a value. See reactor.h in the C library for - * details. + *

    * Actions: If the reactor has an action a (logical or physical), then there will be a field in + * the self struct named `_lf_a` and another named `_lf__a`. The type of the first is specific to + * the action and contains a `value` field with the type and value of the action (if it has a + * value). That struct also has a `has_value` field, an `is_present` field, and a `token` field + * (which is NULL if the action carries no value). The `_lf__a` field is of type trigger_t. That + * struct contains various things, including an array of reactions sensitive to this trigger and a + * lf_token_t struct containing the value of the action, if it has a value. See reactor.h in the C + * library for details. * - * * Reactions: Each reaction will have several fields in the self struct. - * Each of these has a name that begins with `_lf__reaction_i`, where i is - * the number of the reaction, starting with 0. The fields are: - * * _lf__reaction_i: The struct that is put onto the reaction queue to - * execute the reaction (see reactor.h in the C library). + *

    * Reactions: Each reaction will have several fields in the self struct. Each of these has a + * name that begins with `_lf__reaction_i`, where i is the number of the reaction, starting with 0. + * The fields are: * _lf__reaction_i: The struct that is put onto the reaction queue to execute the + * reaction (see reactor.h in the C library). * - * * Timers: For each timer t, there is are two fields in the self struct: - * * _lf__t: The trigger_t struct for this timer (see reactor.h). - * * _lf__t_reactions: An array of reactions (pointers to the - * reaction_t structs on this self struct) sensitive to this timer. + *

    * Timers: For each timer t, there is are two fields in the self struct: * _lf__t: The + * trigger_t struct for this timer (see reactor.h). * _lf__t_reactions: An array of reactions + * (pointers to the reaction_t structs on this self struct) sensitive to this timer. * - * * Triggers: For each Timer, Action, Input, and Output of a contained - * reactor that triggers reactions, there will be a trigger_t struct - * on the self struct with name `_lf__t`, where t is the name of the trigger. + *

    * Triggers: For each Timer, Action, Input, and Output of a contained reactor that triggers + * reactions, there will be a trigger_t struct on the self struct with name `_lf__t`, where t is the + * name of the trigger. * - * ## Connections Between Reactors + *

    ## Connections Between Reactors * - * Establishing connections between reactors involves two steps. - * First, each destination (e.g. an input port) must have pointers to - * the source (the output port). As explained above, for an input named - * `in`, the field `_lf_in->value` is a pointer to the output data being read. - * In addition, `_lf_in->is_present` is a pointer to the corresponding - * `out->is_present` field of the output reactor's self struct. + *

    Establishing connections between reactors involves two steps. First, each destination (e.g. an + * input port) must have pointers to the source (the output port). As explained above, for an input + * named `in`, the field `_lf_in->value` is a pointer to the output data being read. In addition, + * `_lf_in->is_present` is a pointer to the corresponding `out->is_present` field of the output + * reactor's self struct. * - * In addition, the `reaction_i` struct on the self struct has a `triggers` - * field that records all the trigger_t structs for ports and actions - * that are triggered by the i-th reaction. The triggers field is - * an array of arrays of pointers to trigger_t structs. - * The length of the outer array is the number of output channels - * (single ports plus multiport widths) that the reaction effects - * plus the number of input port channels of contained - * reactors that it effects. Each inner array has a length equal to the - * number of final destinations of that output channel or input channel. - * The reaction_i struct has an array triggered_sizes that indicates - * the sizes of these inner arrays. The num_outputs field of the - * reaction_i struct gives the length of the triggered_sizes and - * (outer) triggers arrays. The num_outputs field is equal to the - * total number of single ports and multiport channels that the reaction - * writes to. + *

    In addition, the `reaction_i` struct on the self struct has a `triggers` field that records + * all the trigger_t structs for ports and actions that are triggered by the i-th reaction. The + * triggers field is an array of arrays of pointers to trigger_t structs. The length of the outer + * array is the number of output channels (single ports plus multiport widths) that the reaction + * effects plus the number of input port channels of contained reactors that it effects. Each inner + * array has a length equal to the number of final destinations of that output channel or input + * channel. The reaction_i struct has an array triggered_sizes that indicates the sizes of these + * inner arrays. The num_outputs field of the reaction_i struct gives the length of the + * triggered_sizes and (outer) triggers arrays. The num_outputs field is equal to the total number + * of single ports and multiport channels that the reaction writes to. * - * ## Runtime Tables + *

    ## Runtime Tables * - * This generator creates an populates the following tables used at run time. - * These tables may have to be resized and adjusted when mutations occur. + *

    This generator creates an populates the following tables used at run time. These tables may + * have to be resized and adjusted when mutations occur. * - * * _lf_is_present_fields: An array of pointers to booleans indicating whether an - * event is present. The _lf_start_time_step() function in reactor_common.c uses - * this to mark every event absent at the start of a time step. The size of this - * table is contained in the variable _lf_is_present_fields_size. - * * This table is accompanied by another list, _lf_is_present_fields_abbreviated, - * which only contains the is_present fields that have been set to true in the - * current tag. This list can allow a performance improvement if most ports are - * seldom present because only fields that have been set to true need to be - * reset to false. + *

    * _lf_is_present_fields: An array of pointers to booleans indicating whether an event is + * present. The _lf_start_time_step() function in reactor_common.c uses this to mark every event + * absent at the start of a time step. The size of this table is contained in the variable + * _lf_is_present_fields_size. * This table is accompanied by another list, + * _lf_is_present_fields_abbreviated, which only contains the is_present fields that have been set + * to true in the current tag. This list can allow a performance improvement if most ports are + * seldom present because only fields that have been set to true need to be reset to false. * - * * _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown - * reactions. The length of this table is in the _lf_shutdown_triggers_size - * variable. + *

    * _lf_shutdown_triggers: An array of pointers to trigger_t structs for shutdown reactions. The + * length of this table is in the _lf_shutdown_triggers_size variable. * - * * _lf_timer_triggers: An array of pointers to trigger_t structs for timers that - * need to be started when the program runs. The length of this table is in the - * _lf_timer_triggers_size variable. + *

    * _lf_timer_triggers: An array of pointers to trigger_t structs for timers that need to be + * started when the program runs. The length of this table is in the _lf_timer_triggers_size + * variable. * - * * _lf_action_table: For a federated execution, each federate will have this table - * that maps port IDs to the corresponding action struct, which can be cast to - * action_base_t. + *

    * _lf_action_table: For a federated execution, each federate will have this table that maps + * port IDs to the corresponding action struct, which can be cast to action_base_t. * * @author Edward A. Lee * @author Marten Lohstroh @@ -307,1129 +267,1135 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY @SuppressWarnings("StaticPseudoFunctionalStyleMethod") public class CGenerator extends GeneratorBase { - // Regular expression pattern for compiler error messages with resource - // and line number information. The first match will a resource URI in the - // form of "file:/path/file.lf". The second match will be a line number. - // The third match is a character position within the line. - // The fourth match will be the error message. - static final Pattern compileErrorPattern = Pattern.compile( - "^(?.*):(?\\d+):(?\\d+):(?.*)$" - ); - - public static int UNDEFINED_MIN_SPACING = -1; - - //////////////////////////////////////////// - //// Protected fields - - /** The main place to put generated code. */ - protected CodeBuilder code = new CodeBuilder(); - - /** Place to collect code to initialize the trigger objects for all reactor instances. */ - protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); - - protected final CFileConfig fileConfig; - - /** - * Count of the number of is_present fields of the self struct that - * need to be reinitialized in _lf_start_time_step(). - */ - protected int startTimeStepIsPresentCount = 0; - - //////////////////////////////////////////// - //// Private fields - /** - * Extra lines that need to go into the generated CMakeLists.txt. - */ - private String cMakeExtras = ""; - - /** Place to collect code to execute at the start of a time step. */ - private CodeBuilder startTimeStep = new CodeBuilder(); - - /** Count of the number of token pointers that need to have their - * reference count decremented in _lf_start_time_step(). - */ - private int timerCount = 0; - private int startupReactionCount = 0; - private int shutdownReactionCount = 0; - private int resetReactionCount = 0; - private int modalReactorCount = 0; - private int modalStateResetCount = 0; - private int watchdogCount = 0; - - // Indicate whether the generator is in Cpp mode or not - private final boolean CCppMode; - - private final CTypes types; - - private final CCmakeGenerator cmakeGenerator; - - protected CGenerator( - LFGeneratorContext context, - boolean CCppMode, - CTypes types, - CCmakeGenerator cmakeGenerator, - DelayBodyGenerator delayBodyGenerator - ) { - super(context); - this.fileConfig = (CFileConfig) context.getFileConfig(); - this.CCppMode = CCppMode; - this.types = types; - this.cmakeGenerator = cmakeGenerator; - - // Register the delayed connection transformation to be applied by GeneratorBase. - // transform both after delays and physical connections - registerTransformation(new DelayedConnectionTransformation(delayBodyGenerator, types, fileConfig.resource, true, true)); + // Regular expression pattern for compiler error messages with resource + // and line number information. The first match will a resource URI in the + // form of "file:/path/file.lf". The second match will be a line number. + // The third match is a character position within the line. + // The fourth match will be the error message. + static final Pattern compileErrorPattern = + Pattern.compile("^(?.*):(?\\d+):(?\\d+):(?.*)$"); + + public static int UNDEFINED_MIN_SPACING = -1; + + //////////////////////////////////////////// + //// Protected fields + + /** The main place to put generated code. */ + protected CodeBuilder code = new CodeBuilder(); + + /** Place to collect code to initialize the trigger objects for all reactor instances. */ + protected CodeBuilder initializeTriggerObjects = new CodeBuilder(); + + protected final CFileConfig fileConfig; + + /** + * Count of the number of is_present fields of the self struct that need to be reinitialized in + * _lf_start_time_step(). + */ + protected int startTimeStepIsPresentCount = 0; + + //////////////////////////////////////////// + //// Private fields + /** Extra lines that need to go into the generated CMakeLists.txt. */ + private String cMakeExtras = ""; + + /** Place to collect code to execute at the start of a time step. */ + private CodeBuilder startTimeStep = new CodeBuilder(); + + /** + * Count of the number of token pointers that need to have their reference count decremented in + * _lf_start_time_step(). + */ + private int timerCount = 0; + + private int startupReactionCount = 0; + private int shutdownReactionCount = 0; + private int resetReactionCount = 0; + private int modalReactorCount = 0; + private int modalStateResetCount = 0; + private int watchdogCount = 0; + + // Indicate whether the generator is in Cpp mode or not + private final boolean CCppMode; + + private final CTypes types; + + private final CCmakeGenerator cmakeGenerator; + + protected CGenerator( + LFGeneratorContext context, + boolean CCppMode, + CTypes types, + CCmakeGenerator cmakeGenerator, + DelayBodyGenerator delayBodyGenerator) { + super(context); + this.fileConfig = (CFileConfig) context.getFileConfig(); + this.CCppMode = CCppMode; + this.types = types; + this.cmakeGenerator = cmakeGenerator; + + // Register the delayed connection transformation to be applied by GeneratorBase. + // transform both after delays and physical connections + registerTransformation( + new DelayedConnectionTransformation( + delayBodyGenerator, types, fileConfig.resource, true, true)); + } + + public CGenerator(LFGeneratorContext context, boolean ccppMode) { + this( + context, + ccppMode, + new CTypes(), + new CCmakeGenerator(context.getFileConfig(), List.of()), + new CDelayBodyGenerator(new CTypes())); + } + + /** + * Look for physical actions in all resources. If found, set threads to be at least one to allow + * asynchronous schedule calls. + */ + public void accommodatePhysicalActionsIfPresent() { + // If there are any physical actions, ensure the threaded engine is used and that + // keepalive is set to true, unless the user has explicitly set it to false. + for (Resource resource : GeneratorUtils.getResources(reactors)) { + for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { + if (ActionOrigin.PHYSICAL.equals(action.getOrigin())) { + // If the unthreaded runtime is not requested by the user, use the threaded runtime + // instead + // because it is the only one currently capable of handling asynchronous events. + if (!targetConfig.threading + && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { + targetConfig.threading = true; + errorReporter.reportWarning( + action, + "Using the threaded C runtime to allow for asynchronous handling of physical action" + + " " + + action.getName()); + return; + } + } + } } - - public CGenerator(LFGeneratorContext context, boolean ccppMode) { - this( - context, - ccppMode, - new CTypes(), - new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes()) - ); + } + + /** + * Return true if the host operating system is compatible and otherwise report an error and return + * false. + */ + protected boolean isOSCompatible() { + if (GeneratorUtils.isHostWindows()) { + if (CCppMode) { + errorReporter.reportError( + "LF programs with a CCpp target are currently not supported on Windows. " + + "Exiting code generation."); + return false; + } } + return true; + } + + /** + * Generate C code from the Lingua Franca model contained by the specified resource. This is the + * main entry point for code generation. + * + * @param resource The resource containing the source code. + * @param context The context in which the generator is invoked, including whether it is cancelled + * and whether it is a standalone context + */ + @Override + public void doGenerate(Resource resource, LFGeneratorContext context) { + super.doGenerate(resource, context); + if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; + if (!isOSCompatible()) return; // Incompatible OS and configuration - /** - * Look for physical actions in all resources. - * If found, set threads to be at least one to allow asynchronous schedule calls. - */ - public void accommodatePhysicalActionsIfPresent() { - // If there are any physical actions, ensure the threaded engine is used and that - // keepalive is set to true, unless the user has explicitly set it to false. - for (Resource resource : GeneratorUtils.getResources(reactors)) { - for (Action action : ASTUtils.allElementsOfClass(resource, Action.class)) { - if (ActionOrigin.PHYSICAL.equals(action.getOrigin())) { - // If the unthreaded runtime is not requested by the user, use the threaded runtime instead - // because it is the only one currently capable of handling asynchronous events. - if (!targetConfig.threading && !targetConfig.setByUser.contains(TargetProperty.THREADING)) { - targetConfig.threading = true; - errorReporter.reportWarning( - action, - "Using the threaded C runtime to allow for asynchronous handling of physical action " + - action.getName() - ); - return; - } - } - } - } + // Perform set up that does not generate code + setUpGeneralParameters(); + + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); + FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); + handleProtoFiles(); + + // Derive target filename from the .lf filename. + var lfModuleName = fileConfig.name; + var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); + var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; + try { + generateCodeFor(lfModuleName); + copyTargetFiles(); + generateHeaders(); + code.writeToFile(targetFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); } - /** - * Return true if the host operating system is compatible and - * otherwise report an error and return false. - */ - protected boolean isOSCompatible() { - if (GeneratorUtils.isHostWindows()) { - if (CCppMode) { - errorReporter.reportError( - "LF programs with a CCpp target are currently not supported on Windows. " + - "Exiting code generation." - ); - return false; - } - } - return true; + // Create docker file. + if (targetConfig.dockerOptions != null && mainDef != null) { + try { + var dockerData = getDockerGenerator(context).generateDockerData(); + dockerData.writeDockerFile(); + (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); + } catch (IOException e) { + throw new RuntimeException("Error while writing Docker files", e); + } } - /** - * Generate C code from the Lingua Franca model contained by the - * specified resource. This is the main entry point for code - * generation. - * @param resource The resource containing the source code. - * @param context The context in which the generator is - * invoked, including whether it is cancelled and - * whether it is a standalone context - */ - @Override - public void doGenerate(Resource resource, LFGeneratorContext context) { - super.doGenerate(resource, context); - if (!GeneratorUtils.canGenerate(errorsOccurred(), mainDef, errorReporter, context)) return; - if (!isOSCompatible()) return; // Incompatible OS and configuration - - // Perform set up that does not generate code - setUpGeneralParameters(); - - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getSrcGenPath().toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.binPath.toFile()); - FileUtil.createDirectoryIfDoesNotExist(fileConfig.getIncludePath().toFile()); - handleProtoFiles(); - - // Derive target filename from the .lf filename. - var lfModuleName = fileConfig.name; - var cFilename = CCompiler.getTargetFileName(lfModuleName, this.CCppMode, targetConfig); - var targetFile = fileConfig.getSrcGenPath() + File.separator + cFilename; - try { - generateCodeFor(lfModuleName); - copyTargetFiles(); - generateHeaders(); - code.writeToFile(targetFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - - // Create docker file. - if (targetConfig.dockerOptions != null && mainDef != null) { - try { - var dockerData = getDockerGenerator(context).generateDockerData(); - dockerData.writeDockerFile(); - (new DockerComposeGenerator(context)).writeDockerComposeFile(List.of(dockerData)); - } catch (IOException e) { - throw new RuntimeException("Error while writing Docker files", e); - } - } - - // If cmake is requested, generate the CMakeLists.txt - if (targetConfig.platformOptions.platform != Platform.ARDUINO) { - var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; - var sources = new HashSet<>(ASTUtils.recursiveChildren(main)).stream() - .map(CUtil::getName).map(it -> it + (CCppMode ? ".cpp" : ".c")) - .collect(Collectors.toList()); - sources.add(cFilename); - var cmakeCode = cmakeGenerator.generateCMakeCode( - sources, - lfModuleName, - errorReporter, - CCppMode, - mainDef != null, - cMakeExtras, - targetConfig - ); - try { - cmakeCode.writeToFile(cmakeFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - } else { - try { - Path include = fileConfig.getSrcGenPath().resolve("include/"); - Path src = fileConfig.getSrcGenPath().resolve("src/"); - FileUtil.arduinoDeleteHelper(src, targetConfig.threading); - FileUtil.relativeIncludeHelper(src, include); - FileUtil.relativeIncludeHelper(include, include); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); - } - - if (!targetConfig.noCompile) { - ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); - arduinoUtil.buildArduino(fileConfig, targetConfig); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } else { - System.out.println("********"); - System.out.println("To compile your program, run the following command to see information about the board you plugged in:\n\n\tarduino-cli board list\n\nGrab the FQBN and PORT from the command and run the following command in the generated sources directory:\n\n\tarduino-cli compile -b --build-property compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\nTo flash/upload your generated sketch to the board, run the following command in the generated sources directory:\n\n\tarduino-cli upload -b -p \n"); - // System.out.println("For a list of all boards installed on your computer, you can use the following command:\n\n\tarduino-cli board listall\n"); - context.finish( - GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null) - ); - } - GeneratorUtils.refreshProject(resource, context.getMode()); - return; - } + // If cmake is requested, generate the CMakeLists.txt + if (targetConfig.platformOptions.platform != Platform.ARDUINO) { + var cmakeFile = fileConfig.getSrcGenPath() + File.separator + "CMakeLists.txt"; + var sources = + new HashSet<>(ASTUtils.recursiveChildren(main)) + .stream() + .map(CUtil::getName) + .map(it -> it + (CCppMode ? ".cpp" : ".c")) + .collect(Collectors.toList()); + sources.add(cFilename); + var cmakeCode = + cmakeGenerator.generateCMakeCode( + sources, + lfModuleName, + errorReporter, + CCppMode, + mainDef != null, + cMakeExtras, + targetConfig); + try { + cmakeCode.writeToFile(cmakeFile); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } + } else { + try { + Path include = fileConfig.getSrcGenPath().resolve("include/"); + Path src = fileConfig.getSrcGenPath().resolve("src/"); + FileUtil.arduinoDeleteHelper(src, targetConfig.threading); + FileUtil.relativeIncludeHelper(src, include); + FileUtil.relativeIncludeHelper(include, include); + } catch (IOException e) { + //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored + Exceptions.sneakyThrow(e); + } - // Dump the additional compile definitions to a file to keep the generated project - // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can - // take over and do the rest of compilation. - try { - String compileDefs = targetConfig.compileDefinitions.keySet().stream() - .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) - .collect(Collectors.joining("\n")) + "\n"; - FileUtil.writeToFile( - compileDefs, - Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt") - ); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + if (!targetConfig.noCompile) { + ArduinoUtil arduinoUtil = new ArduinoUtil(context, commandFactory, errorReporter); + arduinoUtil.buildArduino(fileConfig, targetConfig); + context.finish(GeneratorResult.Status.COMPILED, null); + } else { + System.out.println("********"); + System.out.println( + "To compile your program, run the following command to see information about the board" + + " you plugged in:\n\n" + + "\tarduino-cli board list\n\n" + + "Grab the FQBN and PORT from the command and run the following command in the" + + " generated sources directory:\n\n" + + "\tarduino-cli compile -b --build-property" + + " compiler.c.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' --build-property" + + " compiler.cpp.extra_flags='-DLF_UNTHREADED -DPLATFORM_ARDUINO" + + " -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10' .\n\n" + + "To flash/upload your generated sketch to the board, run the following command in" + + " the generated sources directory:\n\n" + + "\tarduino-cli upload -b -p \n"); + // System.out.println("For a list of all boards installed on your computer, you can use the + // following command:\n\n\tarduino-cli board listall\n"); + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + } + GeneratorUtils.refreshProject(resource, context.getMode()); + return; + } - // Create a .vscode/settings.json file in the target directory so that VSCode can - // immediately compile the generated code. - try { - String compileDefs = targetConfig.compileDefinitions.keySet().stream() - .map(key -> "\"-D" + key + "=" + targetConfig.compileDefinitions.get(key) + "\"") - .collect(Collectors.joining(",\n")); - String settings = "{\n" - + "\"cmake.configureArgs\": [\n" - + compileDefs - + "\n]\n}\n"; - Path vscodePath = Path.of(fileConfig.getSrcGenPath() + File.separator + ".vscode"); - if (!Files.exists(vscodePath)) - Files.createDirectory(vscodePath); - FileUtil.writeToFile( - settings, - Path.of(fileConfig.getSrcGenPath() - + File.separator + ".vscode" - + File.separator + "settings.json") - ); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } + // Dump the additional compile definitions to a file to keep the generated project + // self-contained. In this way, third-party build tools like PlatformIO, west, arduino-cli can + // take over and do the rest of compilation. + try { + String compileDefs = + targetConfig.compileDefinitions.keySet().stream() + .map(key -> key + "=" + targetConfig.compileDefinitions.get(key)) + .collect(Collectors.joining("\n")) + + "\n"; + FileUtil.writeToFile( + compileDefs, + Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt")); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } - // If this code generator is directly compiling the code, compile it now so that we - // clean it up after, removing the #line directives after errors have been reported. - if ( - !targetConfig.noCompile && targetConfig.dockerOptions == null - && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) - // This code is unreachable in LSP_FAST mode, so that check is omitted. - && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM - ) { - // FIXME: Currently, a lack of main is treated as a request to not produce - // a binary and produce a .o file instead. There should be a way to control - // this. - // Create an anonymous Runnable class and add it to the compileThreadPool - // so that compilation can happen in parallel. - var cleanCode = code.removeLines("#line"); - - var execName = lfModuleName; - var threadFileConfig = fileConfig; - var generator = this; // FIXME: currently only passed to report errors with line numbers in the Eclipse IDE - var CppMode = CCppMode; - // generatingContext.reportProgress( - // String.format("Generated code for %d/%d executables. Compiling...", federateCount, federates.size()), - // 100 * federateCount / federates.size() - // ); // FIXME: Move to FedGenerator - // Create the compiler to be used later - - var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); - try { - if (!cCompiler.runCCompiler(generator, context)) { - // If compilation failed, remove any bin files that may have been created. - CUtil.deleteBinFiles(threadFileConfig); - // If finish has already been called, it is illegal and makes no sense. However, - // if finish has already been called, then this must be a federated execution. - context.unsuccessfulFinish(); - } else { - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - cleanCode.writeToFile(targetFile); - } catch (IOException e) { - Exceptions.sneakyThrow(e); - } - } + // Create a .vscode/settings.json file in the target directory so that VSCode can + // immediately compile the generated code. + try { + String compileDefs = + targetConfig.compileDefinitions.keySet().stream() + .map(key -> "\"-D" + key + "=" + targetConfig.compileDefinitions.get(key) + "\"") + .collect(Collectors.joining(",\n")); + String settings = "{\n" + "\"cmake.configureArgs\": [\n" + compileDefs + "\n]\n}\n"; + Path vscodePath = Path.of(fileConfig.getSrcGenPath() + File.separator + ".vscode"); + if (!Files.exists(vscodePath)) Files.createDirectory(vscodePath); + FileUtil.writeToFile( + settings, + Path.of( + fileConfig.getSrcGenPath() + + File.separator + + ".vscode" + + File.separator + + "settings.json")); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } - // If a build directive has been given, invoke it now. - // Note that the code does not get cleaned in this case. - if (!targetConfig.noCompile) { - if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { - CUtil.runBuildCommand( - fileConfig, - targetConfig, - commandFactory, - errorReporter, - this::reportCommandErrors, - context.getMode() - ); - context.finish( - GeneratorResult.Status.COMPILED, null - ); - } - if (!errorsOccurred()){ - System.out.println("Compiled binary is in " + fileConfig.binPath); - } + // If this code generator is directly compiling the code, compile it now so that we + // clean it up after, removing the #line directives after errors have been reported. + if (!targetConfig.noCompile + && targetConfig.dockerOptions == null + && IterableExtensions.isNullOrEmpty(targetConfig.buildCommands) + // This code is unreachable in LSP_FAST mode, so that check is omitted. + && context.getMode() != LFGeneratorContext.Mode.LSP_MEDIUM) { + // FIXME: Currently, a lack of main is treated as a request to not produce + // a binary and produce a .o file instead. There should be a way to control + // this. + // Create an anonymous Runnable class and add it to the compileThreadPool + // so that compilation can happen in parallel. + var cleanCode = code.removeLines("#line"); + + var execName = lfModuleName; + var threadFileConfig = fileConfig; + var generator = + this; // FIXME: currently only passed to report errors with line numbers in the Eclipse + // IDE + var CppMode = CCppMode; + // generatingContext.reportProgress( + // String.format("Generated code for %d/%d executables. Compiling...", federateCount, + // federates.size()), + // 100 * federateCount / federates.size() + // ); // FIXME: Move to FedGenerator + // Create the compiler to be used later + + var cCompiler = new CCompiler(targetConfig, threadFileConfig, errorReporter, CppMode); + try { + if (!cCompiler.runCCompiler(generator, context)) { + // If compilation failed, remove any bin files that may have been created. + CUtil.deleteBinFiles(threadFileConfig); + // If finish has already been called, it is illegal and makes no sense. However, + // if finish has already been called, then this must be a federated execution. + context.unsuccessfulFinish(); } else { - context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); + context.finish(GeneratorResult.Status.COMPILED, null); } + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + } - // In case we are in Eclipse, make sure the generated code is visible. - GeneratorUtils.refreshProject(resource, context.getMode()); + // If a build directive has been given, invoke it now. + // Note that the code does not get cleaned in this case. + if (!targetConfig.noCompile) { + if (!IterableExtensions.isNullOrEmpty(targetConfig.buildCommands)) { + CUtil.runBuildCommand( + fileConfig, + targetConfig, + commandFactory, + errorReporter, + this::reportCommandErrors, + context.getMode()); + context.finish(GeneratorResult.Status.COMPILED, null); + } + if (!errorsOccurred()) { + System.out.println("Compiled binary is in " + fileConfig.binPath); + } + } else { + context.finish(GeneratorResult.GENERATED_NO_EXECUTABLE.apply(context, null)); } - private void generateCodeFor( - String lfModuleName - ) throws IOException { - startTimeStepIsPresentCount = 0; - code.pr(generateDirectives()); - code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); - // Generate code for each reactor. - generateReactorDefinitions(); - - // Generate main instance, if there is one. - // Note that any main reactors in imported files are ignored. - // Skip generation if there are cycles. - if (main != null) { - initializeTriggerObjects.pr(String.join("\n", - "int _lf_startup_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", - "int _lf_shutdown_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", - "int _lf_reset_reactions_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", - "int _lf_timer_triggers_count = 0;", - "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", - "int bank_index;", - "SUPPRESS_UNUSED_WARNING(bank_index);", - "int watchdog_number = 0;", - "SUPPRESS_UNUSED_WARNING(watchdog_number);")); - // Add counters for modal initialization - initializeTriggerObjects.pr(CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); - - // Create an array of arrays to store all self structs. - // This is needed because connections cannot be established until - // all reactor instances have self structs because ports that - // receive data reference the self structs of the originating - // reactors, which are arbitarily far away in the program graph. - generateSelfStructs(main); - generateReactorInstance(main); - - if (targetConfig.fedSetupPreamble != null) { - if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); - code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); - if (targetLanguageIsCpp()) code.pr("}"); - } + // In case we are in Eclipse, make sure the generated code is visible. + GeneratorUtils.refreshProject(resource, context.getMode()); + } + + private void generateCodeFor(String lfModuleName) throws IOException { + startTimeStepIsPresentCount = 0; + code.pr(generateDirectives()); + code.pr(new CMainFunctionGenerator(targetConfig).generateCode()); + // Generate code for each reactor. + generateReactorDefinitions(); + + // Generate main instance, if there is one. + // Note that any main reactors in imported files are ignored. + // Skip generation if there are cycles. + if (main != null) { + initializeTriggerObjects.pr( + String.join( + "\n", + "int _lf_startup_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_startup_reactions_count);", + "int _lf_shutdown_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_shutdown_reactions_count);", + "int _lf_reset_reactions_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_reset_reactions_count);", + "int _lf_timer_triggers_count = 0;", + "SUPPRESS_UNUSED_WARNING(_lf_timer_triggers_count);", + "int bank_index;", + "SUPPRESS_UNUSED_WARNING(bank_index);", + "int watchdog_number = 0;", + "SUPPRESS_UNUSED_WARNING(watchdog_number);")); + // Add counters for modal initialization + initializeTriggerObjects.pr( + CModesGenerator.generateModalInitalizationCounters(hasModalReactors)); + + // Create an array of arrays to store all self structs. + // This is needed because connections cannot be established until + // all reactor instances have self structs because ports that + // receive data reference the self structs of the originating + // reactors, which are arbitarily far away in the program graph. + generateSelfStructs(main); + generateReactorInstance(main); + + if (targetConfig.fedSetupPreamble != null) { + if (targetLanguageIsCpp()) code.pr("extern \"C\" {"); + code.pr("#include \"" + targetConfig.fedSetupPreamble + "\""); + if (targetLanguageIsCpp()) code.pr("}"); + } - // If there are timers, create a table of timers to be initialized. - code.pr(CTimerGenerator.generateDeclarations(timerCount)); - - // If there are startup reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); - - // If there are shutdown reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); - - // If there are reset reactions, create a table of triggers. - code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); - - // If there are watchdogs, create a table of triggers. - code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); - - // If there are modes, create a table of mode state to be checked for transitions. - code.pr(CModesGenerator.generateModeStatesTable( - hasModalReactors, - modalReactorCount, - modalStateResetCount - )); - - // Generate function to initialize the trigger objects for all reactors. - code.pr(CTriggerObjectsGenerator.generateInitializeTriggerObjects( - main, - targetConfig, - initializeTriggerObjects, - startTimeStep, - types, - lfModuleName, - startTimeStepIsPresentCount - )); - - // Generate function to trigger startup reactions for all reactors. - code.pr(CReactionGenerator.generateLfTriggerStartupReactions(startupReactionCount, hasModalReactors)); - - // Generate function to schedule timers for all reactors. - code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); - - // Generate a function that will either do nothing - // (if there is only one federate or the coordination - // is set to decentralized) or, if there are - // downstream federates, will notify the RTI - // that the specified logical time is complete. - if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) code.pr("extern \"C\""); - code.pr(String.join("\n", - "void logical_tag_complete(tag_t tag_to_send) {", - CExtensionUtils.surroundWithIfFederatedCentralized( - " _lf_logical_tag_complete(tag_to_send);" - ), - "}" - )); - - // Generate function to schedule shutdown reactions if any - // reactors have reactions to shutdown. - code.pr(CReactionGenerator.generateLfTriggerShutdownReactions(shutdownReactionCount, hasModalReactors)); - - // Generate an empty termination function for non-federated - // execution. For federated execution, an implementation is - // provided in federate.c. That implementation will resign - // from the federation and close any open sockets. - code.pr(""" + // If there are timers, create a table of timers to be initialized. + code.pr(CTimerGenerator.generateDeclarations(timerCount)); + + // If there are startup reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(startupReactionCount, "startup")); + + // If there are shutdown reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(shutdownReactionCount, "shutdown")); + + // If there are reset reactions, create a table of triggers. + code.pr(CReactionGenerator.generateBuiltinTriggersTable(resetReactionCount, "reset")); + + // If there are watchdogs, create a table of triggers. + code.pr(CWatchdogGenerator.generateWatchdogTable(watchdogCount)); + + // If there are modes, create a table of mode state to be checked for transitions. + code.pr( + CModesGenerator.generateModeStatesTable( + hasModalReactors, modalReactorCount, modalStateResetCount)); + + // Generate function to initialize the trigger objects for all reactors. + code.pr( + CTriggerObjectsGenerator.generateInitializeTriggerObjects( + main, + targetConfig, + initializeTriggerObjects, + startTimeStep, + types, + lfModuleName, + startTimeStepIsPresentCount)); + + // Generate function to trigger startup reactions for all reactors. + code.pr( + CReactionGenerator.generateLfTriggerStartupReactions( + startupReactionCount, hasModalReactors)); + + // Generate function to schedule timers for all reactors. + code.pr(CTimerGenerator.generateLfInitializeTimer(timerCount)); + + // Generate a function that will either do nothing + // (if there is only one federate or the coordination + // is set to decentralized) or, if there are + // downstream federates, will notify the RTI + // that the specified logical time is complete. + if (CCppMode || targetConfig.platformOptions.platform == Platform.ARDUINO) + code.pr("extern \"C\""); + code.pr( + String.join( + "\n", + "void logical_tag_complete(tag_t tag_to_send) {", + CExtensionUtils.surroundWithIfFederatedCentralized( + " _lf_logical_tag_complete(tag_to_send);"), + "}")); + + // Generate function to schedule shutdown reactions if any + // reactors have reactions to shutdown. + code.pr( + CReactionGenerator.generateLfTriggerShutdownReactions( + shutdownReactionCount, hasModalReactors)); + + // Generate an empty termination function for non-federated + // execution. For federated execution, an implementation is + // provided in federate.c. That implementation will resign + // from the federation and close any open sockets. + code.pr( + """ #ifndef FEDERATED void terminate_execution() {} - #endif""" - ); - - - // Generate functions for modes - code.pr(CModesGenerator.generateLfInitializeModes( - hasModalReactors - )); - code.pr(CModesGenerator.generateLfHandleModeChanges( - hasModalReactors, - modalStateResetCount - )); - code.pr(CReactionGenerator.generateLfModeTriggeredReactions( - startupReactionCount, - resetReactionCount, - hasModalReactors - )); - } - } - - @Override - public void checkModalReactorSupport(boolean __) { - // Modal reactors are currently only supported for non federated applications - super.checkModalReactorSupport(true); + #endif"""); + + // Generate functions for modes + code.pr(CModesGenerator.generateLfInitializeModes(hasModalReactors)); + code.pr(CModesGenerator.generateLfHandleModeChanges(hasModalReactors, modalStateResetCount)); + code.pr( + CReactionGenerator.generateLfModeTriggeredReactions( + startupReactionCount, resetReactionCount, hasModalReactors)); } - - @Override - protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { - return String.join("\n", - "// Generated forwarding reaction for connections with the same destination", - "// but located in mutually exclusive modes.", - "lf_set("+dest+", "+source+"->value);" - ); - } - - /** Set the scheduler type in the target config as needed. */ - private void pickScheduler() { - // Don't use a scheduler that does not prioritize reactions based on deadlines - // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. - if (!targetConfig.schedulerType.prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - if (hasDeadlines(reactors)) { - if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { - targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; - } - } + } + + @Override + public void checkModalReactorSupport(boolean __) { + // Modal reactors are currently only supported for non federated applications + super.checkModalReactorSupport(true); + } + + @Override + protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) { + return String.join( + "\n", + "// Generated forwarding reaction for connections with the same destination", + "// but located in mutually exclusive modes.", + "lf_set(" + dest + ", " + source + "->value);"); + } + + /** Set the scheduler type in the target config as needed. */ + private void pickScheduler() { + // Don't use a scheduler that does not prioritize reactions based on deadlines + // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. + if (!targetConfig.schedulerType.prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (hasDeadlines(reactors)) { + if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { + targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; } + } } + } - private boolean hasDeadlines(List reactors) { - for (Reactor reactor : reactors) { - for (Reaction reaction : allReactions(reactor)) { - if (reaction.getDeadline() != null) { - return true; - } - } + private boolean hasDeadlines(List reactors) { + for (Reactor reactor : reactors) { + for (Reaction reaction : allReactions(reactor)) { + if (reaction.getDeadline() != null) { + return true; } - return false; + } } - - /** - * Look at the 'reactor' eResource. - * If it is an imported .lf file, incorporate it into the current - * program in the following manner: - * - Merge its target property with `targetConfig` - * - If there are any preambles, add them to the preambles of the reactor. - */ - private void inspectReactorEResource(ReactorDecl reactor) { - // If the reactor is imported, look at the - // target definition of the .lf file in which the reactor is imported from and - // append any cmake-include. - // Check if the reactor definition is imported - if (reactor.eResource() != mainDef.getReactorClass().eResource()) { - // Find the LFResource corresponding to this eResource - LFResource lfResource = null; - for (var resource : resources) { - if (resource.getEResource() == reactor.eResource()) { - lfResource = resource; - break; - } - } - if (lfResource != null) { - // Copy the user files and cmake-includes to the src-gen path of the main .lf file - copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); - // Merge the CMake includes from the imported file into the target config - lfResource.getTargetConfig().cmakeIncludes.forEach(incl -> { - if (!this.targetConfig.cmakeIncludes.contains(incl)) { - this.targetConfig.cmakeIncludes.add(incl); - } - }); - } + return false; + } + + /** + * Look at the 'reactor' eResource. If it is an imported .lf file, incorporate it into the current + * program in the following manner: - Merge its target property with `targetConfig` - If there are + * any preambles, add them to the preambles of the reactor. + */ + private void inspectReactorEResource(ReactorDecl reactor) { + // If the reactor is imported, look at the + // target definition of the .lf file in which the reactor is imported from and + // append any cmake-include. + // Check if the reactor definition is imported + if (reactor.eResource() != mainDef.getReactorClass().eResource()) { + // Find the LFResource corresponding to this eResource + LFResource lfResource = null; + for (var resource : resources) { + if (resource.getEResource() == reactor.eResource()) { + lfResource = resource; + break; } + } + if (lfResource != null) { + // Copy the user files and cmake-includes to the src-gen path of the main .lf file + copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig()); + // Merge the CMake includes from the imported file into the target config + lfResource + .getTargetConfig() + .cmakeIncludes + .forEach( + incl -> { + if (!this.targetConfig.cmakeIncludes.contains(incl)) { + this.targetConfig.cmakeIncludes.add(incl); + } + }); + } } - - /** - * Copy all files or directories listed in the target property `files`, `cmake-include`, - * and `_fed_setup` into the src-gen folder of the main .lf file - * - * @param targetConfig The targetConfig to read the target properties from. - * @param fileConfig The fileConfig used to make the copy and resolve paths. - */ - @Override - protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { - super.copyUserFiles(targetConfig, fileConfig); - // Must use class variable to determine destination! - var destination = this.fileConfig.getSrcGenPath(); - - FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true); - - // FIXME: Unclear what the following does, but it does not appear to belong here. - if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { - try { - FileUtil.copyFile(fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), - destination.resolve(targetConfig.fedSetupPreamble)); - } catch (IOException e) { - errorReporter.reportError("Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); - } - } + } + + /** + * Copy all files or directories listed in the target property `files`, `cmake-include`, and + * `_fed_setup` into the src-gen folder of the main .lf file + * + * @param targetConfig The targetConfig to read the target properties from. + * @param fileConfig The fileConfig used to make the copy and resolve paths. + */ + @Override + protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { + super.copyUserFiles(targetConfig, fileConfig); + // Must use class variable to determine destination! + var destination = this.fileConfig.getSrcGenPath(); + + FileUtil.copyFilesOrDirectories( + targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true); + + // FIXME: Unclear what the following does, but it does not appear to belong here. + if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) { + try { + FileUtil.copyFile( + fileConfig.srcFile.getParent().resolve(targetConfig.fedSetupPreamble), + destination.resolve(targetConfig.fedSetupPreamble)); + } catch (IOException e) { + errorReporter.reportError( + "Failed to find _fed_setup file " + targetConfig.fedSetupPreamble); + } } - - /** - * Generate code for defining all reactors that belong to the federate, - * including all the child reactors down the hierarchy. Duplicate - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. - */ - private void generateReactorDefinitions() throws IOException { - var generatedReactors = new LinkedHashSet(); - if (this.main != null) { - generateReactorChildren(this.main, generatedReactors); - } - - if (this.mainDef != null) { - generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); - } - - if (mainDef == null) { - // Generate code for each reactor that was not instantiated in main or its children. - for (Reactor r : reactors) { - // Get the declarations for reactors that are instantiated somewhere. - // A declaration is either a reactor definition or an import statement.; - var declarations = this.instantiationGraph.getDeclarations(r); - // If the reactor has no instantiations and there is no main reactor, then - // generate code for it anyway (at a minimum, this means that the compiler is invoked - // so that reaction bodies are checked). - if (declarations.isEmpty()) { - generateReactorClass(r); - } - } - } + } + + /** + * Generate code for defining all reactors that belong to the federate, including all the child + * reactors down the hierarchy. Duplicate Duplicates are avoided. + * + *

    Imported reactors' original .lf file is incorporated in the following manner: - If there are + * any cmake-include files, add them to the current list of cmake-include files. - If there are + * any preambles, add them to the preambles of the reactor. + */ + private void generateReactorDefinitions() throws IOException { + var generatedReactors = new LinkedHashSet(); + if (this.main != null) { + generateReactorChildren(this.main, generatedReactors); } - /** Generate user-visible header files for all reactors instantiated. */ - private void generateHeaders() throws IOException { - FileUtil.deleteDirectory(fileConfig.getIncludePath()); - FileUtil.copyFromClassPath( - fileConfig.getRuntimeIncludePath(), - fileConfig.getIncludePath(), - false, - true - ); - for (Reactor r : reactors) { - CReactorHeaderFileGenerator.doGenerate( - types, r, fileConfig, - (builder, rr, userFacing) -> { - generateAuxiliaryStructs(builder, rr, userFacing); - if (userFacing) { - ASTUtils.allInstantiations(r).stream().map(Instantiation::getReactorClass).collect(Collectors.toSet()).forEach(it -> { - ASTUtils.allPorts(ASTUtils.toDefinition(it)) - .forEach(p -> builder.pr(CPortGenerator.generateAuxiliaryStruct( - ASTUtils.toDefinition(it), p, getTarget(), errorReporter, types, new CodeBuilder(), true, it - ))); - }); - } - }, - this::generateTopLevelPreambles); - } - FileUtil.copyDirectoryContents(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + if (this.mainDef != null) { + generateReactorClass(ASTUtils.toDefinition(this.mainDef.getReactorClass())); } - /** - * Generate code for the children of 'reactor' that belong to 'federate'. - * Duplicates are avoided. - * - * Imported reactors' original .lf file is - * incorporated in the following manner: - * - If there are any cmake-include files, add them to the current list - * of cmake-include files. - * - If there are any preambles, add them to the preambles of the reactor. - * - * @param reactor Used to extract children from - */ - private void generateReactorChildren( - ReactorInstance reactor, - LinkedHashSet generatedReactors - ) throws IOException { - for (ReactorInstance r : reactor.children) { - if (r.reactorDeclaration != null && - !generatedReactors.contains(r.reactorDefinition)) { - generatedReactors.add(r.reactorDefinition); - generateReactorChildren(r, generatedReactors); - inspectReactorEResource(r.reactorDeclaration); - generateReactorClass(r.reactorDefinition); - } + if (mainDef == null) { + // Generate code for each reactor that was not instantiated in main or its children. + for (Reactor r : reactors) { + // Get the declarations for reactors that are instantiated somewhere. + // A declaration is either a reactor definition or an import statement.; + var declarations = this.instantiationGraph.getDeclarations(r); + // If the reactor has no instantiations and there is no main reactor, then + // generate code for it anyway (at a minimum, this means that the compiler is invoked + // so that reaction bodies are checked). + if (declarations.isEmpty()) { + generateReactorClass(r); } + } } - - /** - * Choose which platform files to compile with according to the OS. - * If there is no main reactor, then compilation will produce a .o file requiring further linking. - * Also, if useCmake is set to true, we don't need to add platform files. The CMakeLists.txt file - * will detect and use the appropriate platform file based on the platform that cmake is invoked on. - */ - private void pickCompilePlatform() { - var osName = System.getProperty("os.name").toLowerCase(); - // if platform target was set, use given platform instead - if (targetConfig.platformOptions.platform != Platform.AUTO) { - osName = targetConfig.platformOptions.platform.toString(); - } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { - errorReporter.reportError("Platform " + osName + " is not supported"); - } + } + + /** Generate user-visible header files for all reactors instantiated. */ + private void generateHeaders() throws IOException { + FileUtil.deleteDirectory(fileConfig.getIncludePath()); + FileUtil.copyFromClassPath( + fileConfig.getRuntimeIncludePath(), fileConfig.getIncludePath(), false, true); + for (Reactor r : reactors) { + CReactorHeaderFileGenerator.doGenerate( + types, + r, + fileConfig, + (builder, rr, userFacing) -> { + generateAuxiliaryStructs(builder, rr, userFacing); + if (userFacing) { + ASTUtils.allInstantiations(r).stream() + .map(Instantiation::getReactorClass) + .collect(Collectors.toSet()) + .forEach( + it -> { + ASTUtils.allPorts(ASTUtils.toDefinition(it)) + .forEach( + p -> + builder.pr( + CPortGenerator.generateAuxiliaryStruct( + ASTUtils.toDefinition(it), + p, + getTarget(), + errorReporter, + types, + new CodeBuilder(), + true, + it))); + }); + } + }, + this::generateTopLevelPreambles); } - - /** - * Copy target-specific header file to the src-gen directory. - */ - protected void copyTargetFiles() throws IOException { - // Copy the core lib - String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); - Path dest = fileConfig.getSrcGenPath(); - if (targetConfig.platformOptions.platform == Platform.ARDUINO) { - dest = dest.resolve("src"); + FileUtil.copyDirectoryContents( + fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false); + } + + /** + * Generate code for the children of 'reactor' that belong to 'federate'. Duplicates are avoided. + * + *

    Imported reactors' original .lf file is incorporated in the following manner: - If there are + * any cmake-include files, add them to the current list of cmake-include files. - If there are + * any preambles, add them to the preambles of the reactor. + * + * @param reactor Used to extract children from + */ + private void generateReactorChildren( + ReactorInstance reactor, LinkedHashSet generatedReactors) throws IOException { + for (ReactorInstance r : reactor.children) { + if (r.reactorDeclaration != null && !generatedReactors.contains(r.reactorDefinition)) { + generatedReactors.add(r.reactorDefinition); + generateReactorChildren(r, generatedReactors); + inspectReactorEResource(r.reactorDeclaration); + generateReactorClass(r.reactorDefinition); } - if (coreLib != null) { - FileUtil.copyDirectoryContents(Path.of(coreLib), dest, true); - } else { - FileUtil.copyFromClassPath( - "/lib/c/reactor-c/core", - dest, - true, - false - ); - FileUtil.copyFromClassPath( - "/lib/c/reactor-c/lib", - dest, - true, - false - ); - } - - // For the Zephyr target, copy default config and board files. - if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - FileUtil.copyFromClassPath( - "/lib/platform/zephyr/boards", - fileConfig.getSrcGenPath(), - false, - false - ); - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/prj_lf.conf", - fileConfig.getSrcGenPath(), - true - ); - - FileUtil.copyFileFromClassPath( - "/lib/platform/zephyr/Kconfig", - fileConfig.getSrcGenPath(), - true - ); - } } - - //////////////////////////////////////////// - //// Code generators. - - /** - * Generate a reactor class definition for the specified federate. - * A class definition has four parts: - * - * * Preamble code, if any, specified in the Lingua Franca file. - * * A "self" struct type definition (see the class documentation above). - * * A function for each reaction. - * * A constructor for creating an instance. - * for deleting an instance. - * - * If the reactor is the main reactor, then - * the generated code may be customized. Specifically, - * if the main reactor has reactions, these reactions - * will not be generated if they are triggered by or send - * data to contained reactors that are not in the federate. - * @param reactor The parsed reactor data structure. - */ - private void generateReactorClass(Reactor reactor) throws IOException { - // FIXME: Currently we're not reusing definitions for declarations that point to the same definition. - CodeBuilder header = new CodeBuilder(); - CodeBuilder src = new CodeBuilder(); - final String headerName = CUtil.getName(reactor) + ".h"; - var guardMacro = headerName.toUpperCase().replace(".", "_"); - header.pr("#ifndef " + guardMacro); - header.pr("#define " + guardMacro); - generateReactorClassHeaders(reactor, headerName, header, src); - header.pr(generateTopLevelPreambles(reactor)); - generateUserPreamblesForReactor(reactor, src); - generateReactorClassBody(reactor, header, src); - header.pr("#endif // " + guardMacro); - FileUtil.writeToFile(CodeMap.fromGeneratedCode(header.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(headerName), true); - var extension = targetConfig.platformOptions.platform == Platform.ARDUINO ? ".ino" : - CCppMode ? ".cpp" : ".c"; - FileUtil.writeToFile(CodeMap.fromGeneratedCode(src.toString()).getGeneratedCode(), fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), true); + } + + /** + * Choose which platform files to compile with according to the OS. If there is no main reactor, + * then compilation will produce a .o file requiring further linking. Also, if useCmake is set to + * true, we don't need to add platform files. The CMakeLists.txt file will detect and use the + * appropriate platform file based on the platform that cmake is invoked on. + */ + private void pickCompilePlatform() { + var osName = System.getProperty("os.name").toLowerCase(); + // if platform target was set, use given platform instead + if (targetConfig.platformOptions.platform != Platform.AUTO) { + osName = targetConfig.platformOptions.platform.toString(); + } else if (Stream.of("mac", "darwin", "win", "nux").noneMatch(osName::contains)) { + errorReporter.reportError("Platform " + osName + " is not supported"); } - - protected void generateReactorClassHeaders(Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { - if (CCppMode) { - src.pr("extern \"C\" {"); - header.pr("extern \"C\" {"); - } - header.pr("#include \"include/core/reactor.h\""); - src.pr("#include \"include/api/api.h\""); - src.pr("#include \"include/api/set.h\""); - generateIncludes(reactor); - if (CCppMode) { - src.pr("}"); - header.pr("}"); - } - src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); - src.pr("#include \"" + headerName + "\""); - ASTUtils.allNestedClasses(reactor).map(CUtil::getName) - .map(name -> "#include \"" + name + ".h\"") - .forEach(header::pr); + } + + /** Copy target-specific header file to the src-gen directory. */ + protected void copyTargetFiles() throws IOException { + // Copy the core lib + String coreLib = LFGeneratorContext.BuildParm.EXTERNAL_RUNTIME_PATH.getValue(context); + Path dest = fileConfig.getSrcGenPath(); + if (targetConfig.platformOptions.platform == Platform.ARDUINO) { + dest = dest.resolve("src"); } - - private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { - // Some of the following methods create lines of code that need to - // go into the constructor. Collect those lines of code here: - var constructorCode = new CodeBuilder(); - generateAuxiliaryStructs(header, reactor, false); - // The following must go before the self struct so the #include watchdog.h ends up in the header. - CWatchdogGenerator.generateWatchdogs(src, header, reactor, errorReporter); - generateSelfStruct(header, reactor, constructorCode); - generateMethods(src, reactor); - generateReactions(src, reactor); - generateConstructor(src, header, reactor, constructorCode); + if (coreLib != null) { + FileUtil.copyDirectoryContents(Path.of(coreLib), dest, true); + } else { + FileUtil.copyFromClassPath("/lib/c/reactor-c/core", dest, true, false); + FileUtil.copyFromClassPath("/lib/c/reactor-c/lib", dest, true, false); } - /** - * Generate methods for {@code reactor}. - */ - protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { - CMethodGenerator.generateMethods(reactor, src, types); - } + // For the Zephyr target, copy default config and board files. + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyFromClassPath( + "/lib/platform/zephyr/boards", fileConfig.getSrcGenPath(), false, false); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", fileConfig.getSrcGenPath(), true); - /** - * Generates preambles defined by user for a given reactor - * @param reactor The given reactor - */ - protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { - for (Preamble p : ASTUtils.allPreambles(reactor)) { - src.pr("// *********** From the preamble, verbatim:"); - src.prSourceLineNumber(p.getCode()); - src.pr(toText(p.getCode())); - src.pr("\n// *********** End of preamble."); - } + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath(), true); } - - /** - * Generate a constructor for the specified reactor in the specified federate. - * @param reactor The parsed reactor data structure. - * @param constructorCode Lines of code previously generated that need to - * go into the constructor. - */ - protected void generateConstructor( - CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode - ) { - header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); - src.pr(CConstructorGenerator.generateConstructor( - reactor, - constructorCode.toString() - )); + } + + //////////////////////////////////////////// + //// Code generators. + + /** + * Generate a reactor class definition for the specified federate. A class definition has four + * parts: + * + *

    * Preamble code, if any, specified in the Lingua Franca file. * A "self" struct type + * definition (see the class documentation above). * A function for each reaction. * A constructor + * for creating an instance. for deleting an instance. + * + *

    If the reactor is the main reactor, then the generated code may be customized. Specifically, + * if the main reactor has reactions, these reactions will not be generated if they are triggered + * by or send data to contained reactors that are not in the federate. + * + * @param reactor The parsed reactor data structure. + */ + private void generateReactorClass(Reactor reactor) throws IOException { + // FIXME: Currently we're not reusing definitions for declarations that point to the same + // definition. + CodeBuilder header = new CodeBuilder(); + CodeBuilder src = new CodeBuilder(); + final String headerName = CUtil.getName(reactor) + ".h"; + var guardMacro = headerName.toUpperCase().replace(".", "_"); + header.pr("#ifndef " + guardMacro); + header.pr("#define " + guardMacro); + generateReactorClassHeaders(reactor, headerName, header, src); + header.pr(generateTopLevelPreambles(reactor)); + generateUserPreamblesForReactor(reactor, src); + generateReactorClassBody(reactor, header, src); + header.pr("#endif // " + guardMacro); + FileUtil.writeToFile( + CodeMap.fromGeneratedCode(header.toString()).getGeneratedCode(), + fileConfig.getSrcGenPath().resolve(headerName), + true); + var extension = + targetConfig.platformOptions.platform == Platform.ARDUINO + ? ".ino" + : CCppMode ? ".cpp" : ".c"; + FileUtil.writeToFile( + CodeMap.fromGeneratedCode(src.toString()).getGeneratedCode(), + fileConfig.getSrcGenPath().resolve(CUtil.getName(reactor) + extension), + true); + } + + protected void generateReactorClassHeaders( + Reactor reactor, String headerName, CodeBuilder header, CodeBuilder src) { + if (CCppMode) { + src.pr("extern \"C\" {"); + header.pr("extern \"C\" {"); } - - protected void generateIncludes(Reactor r) { - code.pr("#include \"" + CUtil.getName(r) + ".h\""); + header.pr("#include \"include/core/reactor.h\""); + src.pr("#include \"include/api/api.h\""); + src.pr("#include \"include/api/set.h\""); + generateIncludes(reactor); + if (CCppMode) { + src.pr("}"); + header.pr("}"); } - - /** - * Generate the struct type definitions for inputs, outputs, and - * actions of the specified reactor. - */ - protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { - // In the case where there are incoming - // p2p logical connections in decentralized - // federated execution, there will be an - // intended_tag field added to accommodate - // the case where a reaction triggered by a - // port or action is late due to network - // latency, etc.. - var federatedExtension = new CodeBuilder(); - federatedExtension.pr(""" + src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(reactor) + "\""); + src.pr("#include \"" + headerName + "\""); + ASTUtils.allNestedClasses(reactor) + .map(CUtil::getName) + .map(name -> "#include \"" + name + ".h\"") + .forEach(header::pr); + } + + private void generateReactorClassBody(Reactor reactor, CodeBuilder header, CodeBuilder src) { + // Some of the following methods create lines of code that need to + // go into the constructor. Collect those lines of code here: + var constructorCode = new CodeBuilder(); + generateAuxiliaryStructs(header, reactor, false); + // The following must go before the self struct so the #include watchdog.h ends up in the + // header. + CWatchdogGenerator.generateWatchdogs(src, header, reactor, errorReporter); + generateSelfStruct(header, reactor, constructorCode); + generateMethods(src, reactor); + generateReactions(src, reactor); + generateConstructor(src, header, reactor, constructorCode); + } + + /** Generate methods for {@code reactor}. */ + protected void generateMethods(CodeBuilder src, ReactorDecl reactor) { + CMethodGenerator.generateMethods(reactor, src, types); + } + + /** + * Generates preambles defined by user for a given reactor + * + * @param reactor The given reactor + */ + protected void generateUserPreamblesForReactor(Reactor reactor, CodeBuilder src) { + for (Preamble p : ASTUtils.allPreambles(reactor)) { + src.pr("// *********** From the preamble, verbatim:"); + src.prSourceLineNumber(p.getCode()); + src.pr(toText(p.getCode())); + src.pr("\n// *********** End of preamble."); + } + } + + /** + * Generate a constructor for the specified reactor in the specified federate. + * + * @param reactor The parsed reactor data structure. + * @param constructorCode Lines of code previously generated that need to go into the constructor. + */ + protected void generateConstructor( + CodeBuilder src, CodeBuilder header, Reactor reactor, CodeBuilder constructorCode) { + header.pr(CConstructorGenerator.generateConstructorPrototype(reactor)); + src.pr(CConstructorGenerator.generateConstructor(reactor, constructorCode.toString())); + } + + protected void generateIncludes(Reactor r) { + code.pr("#include \"" + CUtil.getName(r) + ".h\""); + } + + /** + * Generate the struct type definitions for inputs, outputs, and actions of the specified reactor. + */ + protected void generateAuxiliaryStructs(CodeBuilder builder, Reactor r, boolean userFacing) { + // In the case where there are incoming + // p2p logical connections in decentralized + // federated execution, there will be an + // intended_tag field added to accommodate + // the case where a reaction triggered by a + // port or action is late due to network + // latency, etc.. + var federatedExtension = new CodeBuilder(); + federatedExtension.pr( + """ #ifdef FEDERATED #ifdef FEDERATED_DECENTRALIZED %s intended_tag; #endif %s physical_time_of_arrival; #endif - """.formatted(types.getTargetTagType(), types.getTargetTimeType()) - ); - for (Port p : allPorts(r)) { - builder.pr(CPortGenerator.generateAuxiliaryStruct( - r, - p, - getTarget(), - errorReporter, - types, - federatedExtension, - userFacing, - null - )); - } - // The very first item on this struct needs to be - // a trigger_t* because the struct will be cast to (trigger_t*) - // by the lf_schedule() functions to get to the trigger. - for (Action action : allActions(r)) { - builder.pr(CActionGenerator.generateAuxiliaryStruct( - r, - action, - getTarget(), - types, - federatedExtension, - userFacing - )); - } + """ + .formatted(types.getTargetTagType(), types.getTargetTimeType())); + for (Port p : allPorts(r)) { + builder.pr( + CPortGenerator.generateAuxiliaryStruct( + r, p, getTarget(), errorReporter, types, federatedExtension, userFacing, null)); } - - /** - * Generate the self struct type definition for the specified reactor - * in the specified federate. - * @param decl The parsed reactor data structure. - * @param constructorCode Place to put lines of code that need to - * go into the constructor. - */ - private void generateSelfStruct(CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { - var reactor = toDefinition(decl); - var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); - - // Construct the typedef for the "self" struct. - // Create a type name for the self struct. - var body = new CodeBuilder(); - - // Extensions can add functionality to the CGenerator - generateSelfStructExtension(body, decl, constructorCode); - - // Next handle parameters. - body.pr(CParameterGenerator.generateDeclarations(reactor, types)); - - // Next handle states. - body.pr(CStateGenerator.generateDeclarations(reactor, types)); - - // Next handle actions. - CActionGenerator.generateDeclarations(reactor, body, constructorCode); - - // Next handle inputs and outputs. - CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); - - // If there are contained reactors that either receive inputs - // from reactions of this reactor or produce outputs that trigger - // reactions of this reactor, then we need to create a struct - // inside the self struct for each contained reactor. That - // struct has a place to hold the data produced by this reactor's - // reactions and a place to put pointers to data produced by - // the contained reactors. - generateInteractingContainedReactors(reactor, body, constructorCode); - - // Next, generate the fields needed for each reaction. - CReactionGenerator.generateReactionAndTriggerStructs( - body, - reactor, - constructorCode, - types - ); - - // Generate the fields needed for each watchdog. - CWatchdogGenerator.generateWatchdogStruct(body, decl, constructorCode); - - // Next, generate fields for modes - CModesGenerator.generateDeclarations(reactor, body, constructorCode); - - // The first field has to always be a pointer to the list of - // of allocated memory that must be freed when the reactor is freed. - // This means that the struct can be safely cast to self_base_t. - builder.pr("typedef struct {"); - builder.indent(); - builder.pr("struct self_base_t base;"); - builder.pr(body.toString()); - builder.unindent(); - builder.pr("} " + selfType + ";"); + // The very first item on this struct needs to be + // a trigger_t* because the struct will be cast to (trigger_t*) + // by the lf_schedule() functions to get to the trigger. + for (Action action : allActions(r)) { + builder.pr( + CActionGenerator.generateAuxiliaryStruct( + r, action, getTarget(), types, federatedExtension, userFacing)); } - - /** - * Generate structs and associated code for contained reactors that - * send or receive data to or from the container's reactions. - * - * If there are contained reactors that either receive inputs - * from reactions of this reactor or produce outputs that trigger - * reactions of this reactor, then we need to create a struct - * inside the self struct of the container for each contained reactor. - * That struct has a place to hold the data produced by the container reactor's - * reactions and a place to put pointers to data produced by - * the contained reactors. - * - * @param reactor The reactor. - * @param body The place to put the struct definition for the contained reactors. - * @param constructorCode The place to put matching code that goes in the container's constructor. - */ - private void generateInteractingContainedReactors( - Reactor reactor, - CodeBuilder body, - CodeBuilder constructorCode - ) { - // The contents of the struct will be collected first so that - // we avoid duplicate entries and then the struct will be constructed. - var contained = new InteractingContainedReactors(reactor); - // Next generate the relevant code. - for (Instantiation containedReactor : contained.containedReactors()) { - Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); - // First define an _width variable in case it is a bank. - var array = ""; - var width = -2; - // If the instantiation is a bank, find the maximum bank width - // to define an array. - if (containedReactor.getWidthSpec() != null) { - width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); - array = "[" + width + "]"; - } - // NOTE: The following needs to be done for each instance - // so that the width can be parameter, not in the constructor. - // Here, we conservatively use a width that is the largest of all isntances. - constructorCode.pr(String.join("\n", - "// Set the _width variable for all cases. This will be -2", - "// if the reactor is not a bank of reactors.", - "self->_lf_"+containedReactor.getName()+"_width = "+width+";" - )); - - // Generate one struct for each contained reactor that interacts. - body.pr("struct {"); - body.indent(); - for (Port port : contained.portsOfInstance(containedReactor)) { - if (port instanceof Input) { - // If the variable is a multiport, then the place to store the data has - // to be malloc'd at initialization. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+" "+port.getName()+";"); - } else { - // Is a multiport. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - } else { - // Must be an output port. - // Outputs of contained reactors are pointers to the source of data on the - // self struct of the container. - if (!ASTUtils.isMultiport(port)) { - // Not a multiport. - body.pr(port, variableStructType(port, containedReactorType, false)+"* "+port.getName()+";"); - } else { - // Is a multiport. - // Here, we will use an array of pointers. - // Memory will be malloc'd in initialization. - body.pr(port, String.join("\n", - variableStructType(port, containedReactorType, false)+"** "+port.getName()+";", - "int "+port.getName()+"_width;" - )); - } - body.pr(port, "trigger_t "+port.getName()+"_trigger;"); - var reactorIndex = ""; - if (containedReactor.getWidthSpec() != null) { - reactorIndex = "[reactor_index]"; - constructorCode.pr("for (int reactor_index = 0; reactor_index < self->_lf_"+containedReactor.getName()+"_width; reactor_index++) {"); - constructorCode.indent(); - } - var portOnSelf = "self->_lf_"+containedReactor.getName()+reactorIndex+"."+port.getName(); - - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederatedDecentralized( - portOnSelf+"_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};" - ) - ); - - var triggered = contained.reactionsTriggered(containedReactor, port); - //noinspection StatementWithEmptyBody - if (triggered.size() > 0) { - body.pr(port, "reaction_t* "+port.getName()+"_reactions["+triggered.size()+"];"); - var triggeredCount = 0; - for (Integer index : triggered) { - constructorCode.pr(port, portOnSelf+"_reactions["+triggeredCount+++"] = &self->_lf__reaction_"+index+";"); - } - constructorCode.pr(port, portOnSelf+"_trigger.reactions = "+portOnSelf+"_reactions;"); - } else { - // Since the self struct is created using calloc, there is no need to set - // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL - } - // Since the self struct is created using calloc, there is no need to set falsy fields. - constructorCode.pr(port, String.join("\n", - portOnSelf+"_trigger.last = NULL;", - portOnSelf+"_trigger.number_of_reactions = "+triggered.size()+";" - )); - - - // Set the physical_time_of_arrival - constructorCode.pr( - port, - CExtensionUtils.surroundWithIfFederated( - portOnSelf+"_trigger.physical_time_of_arrival = NEVER;" - ) - ); - - if (containedReactor.getWidthSpec() != null) { - constructorCode.unindent(); - constructorCode.pr("}"); - } - } + } + + /** + * Generate the self struct type definition for the specified reactor in the specified federate. + * + * @param decl The parsed reactor data structure. + * @param constructorCode Place to put lines of code that need to go into the constructor. + */ + private void generateSelfStruct( + CodeBuilder builder, ReactorDecl decl, CodeBuilder constructorCode) { + var reactor = toDefinition(decl); + var selfType = CUtil.selfType(ASTUtils.toDefinition(decl)); + + // Construct the typedef for the "self" struct. + // Create a type name for the self struct. + var body = new CodeBuilder(); + + // Extensions can add functionality to the CGenerator + generateSelfStructExtension(body, decl, constructorCode); + + // Next handle parameters. + body.pr(CParameterGenerator.generateDeclarations(reactor, types)); + + // Next handle states. + body.pr(CStateGenerator.generateDeclarations(reactor, types)); + + // Next handle actions. + CActionGenerator.generateDeclarations(reactor, body, constructorCode); + + // Next handle inputs and outputs. + CPortGenerator.generateDeclarations(reactor, decl, body, constructorCode); + + // If there are contained reactors that either receive inputs + // from reactions of this reactor or produce outputs that trigger + // reactions of this reactor, then we need to create a struct + // inside the self struct for each contained reactor. That + // struct has a place to hold the data produced by this reactor's + // reactions and a place to put pointers to data produced by + // the contained reactors. + generateInteractingContainedReactors(reactor, body, constructorCode); + + // Next, generate the fields needed for each reaction. + CReactionGenerator.generateReactionAndTriggerStructs(body, reactor, constructorCode, types); + + // Generate the fields needed for each watchdog. + CWatchdogGenerator.generateWatchdogStruct(body, decl, constructorCode); + + // Next, generate fields for modes + CModesGenerator.generateDeclarations(reactor, body, constructorCode); + + // The first field has to always be a pointer to the list of + // of allocated memory that must be freed when the reactor is freed. + // This means that the struct can be safely cast to self_base_t. + builder.pr("typedef struct {"); + builder.indent(); + builder.pr("struct self_base_t base;"); + builder.pr(body.toString()); + builder.unindent(); + builder.pr("} " + selfType + ";"); + } + + /** + * Generate structs and associated code for contained reactors that send or receive data to or + * from the container's reactions. + * + *

    If there are contained reactors that either receive inputs from reactions of this reactor or + * produce outputs that trigger reactions of this reactor, then we need to create a struct inside + * the self struct of the container for each contained reactor. That struct has a place to hold + * the data produced by the container reactor's reactions and a place to put pointers to data + * produced by the contained reactors. + * + * @param reactor The reactor. + * @param body The place to put the struct definition for the contained reactors. + * @param constructorCode The place to put matching code that goes in the container's constructor. + */ + private void generateInteractingContainedReactors( + Reactor reactor, CodeBuilder body, CodeBuilder constructorCode) { + // The contents of the struct will be collected first so that + // we avoid duplicate entries and then the struct will be constructed. + var contained = new InteractingContainedReactors(reactor); + // Next generate the relevant code. + for (Instantiation containedReactor : contained.containedReactors()) { + Reactor containedReactorType = ASTUtils.toDefinition(containedReactor.getReactorClass()); + // First define an _width variable in case it is a bank. + var array = ""; + var width = -2; + // If the instantiation is a bank, find the maximum bank width + // to define an array. + if (containedReactor.getWidthSpec() != null) { + width = CReactionGenerator.maxContainedReactorBankWidth(containedReactor, null, 0, mainDef); + array = "[" + width + "]"; + } + // NOTE: The following needs to be done for each instance + // so that the width can be parameter, not in the constructor. + // Here, we conservatively use a width that is the largest of all isntances. + constructorCode.pr( + String.join( + "\n", + "// Set the _width variable for all cases. This will be -2", + "// if the reactor is not a bank of reactors.", + "self->_lf_" + containedReactor.getName() + "_width = " + width + ";")); + + // Generate one struct for each contained reactor that interacts. + body.pr("struct {"); + body.indent(); + for (Port port : contained.portsOfInstance(containedReactor)) { + if (port instanceof Input) { + // If the variable is a multiport, then the place to store the data has + // to be malloc'd at initialization. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, + variableStructType(port, containedReactorType, false) + " " + port.getName() + ";"); + } else { + // Is a multiport. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedReactorType, false) + + "** " + + port.getName() + + ";", + "int " + port.getName() + "_width;")); + } + } else { + // Must be an output port. + // Outputs of contained reactors are pointers to the source of data on the + // self struct of the container. + if (!ASTUtils.isMultiport(port)) { + // Not a multiport. + body.pr( + port, + variableStructType(port, containedReactorType, false) + + "* " + + port.getName() + + ";"); + } else { + // Is a multiport. + // Here, we will use an array of pointers. + // Memory will be malloc'd in initialization. + body.pr( + port, + String.join( + "\n", + variableStructType(port, containedReactorType, false) + + "** " + + port.getName() + + ";", + "int " + port.getName() + "_width;")); + } + body.pr(port, "trigger_t " + port.getName() + "_trigger;"); + var reactorIndex = ""; + if (containedReactor.getWidthSpec() != null) { + reactorIndex = "[reactor_index]"; + constructorCode.pr( + "for (int reactor_index = 0; reactor_index < self->_lf_" + + containedReactor.getName() + + "_width; reactor_index++) {"); + constructorCode.indent(); + } + var portOnSelf = + "self->_lf_" + containedReactor.getName() + reactorIndex + "." + port.getName(); + + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederatedDecentralized( + portOnSelf + + "_trigger.intended_tag = (tag_t) { .time = NEVER, .microstep = 0u};")); + + var triggered = contained.reactionsTriggered(containedReactor, port); + //noinspection StatementWithEmptyBody + if (triggered.size() > 0) { + body.pr( + port, "reaction_t* " + port.getName() + "_reactions[" + triggered.size() + "];"); + var triggeredCount = 0; + for (Integer index : triggered) { + constructorCode.pr( + port, + portOnSelf + + "_reactions[" + + triggeredCount++ + + "] = &self->_lf__reaction_" + + index + + ";"); } - body.unindent(); - body.pr(String.join("\n", - "} _lf_"+containedReactor.getName()+array+";", - "int _lf_"+containedReactor.getName()+"_width;" - )); + constructorCode.pr( + port, portOnSelf + "_trigger.reactions = " + portOnSelf + "_reactions;"); + } else { + // Since the self struct is created using calloc, there is no need to set + // self->_lf_"+containedReactor.getName()+"."+port.getName()+"_trigger.reactions = NULL + } + // Since the self struct is created using calloc, there is no need to set falsy fields. + constructorCode.pr( + port, + String.join( + "\n", + portOnSelf + "_trigger.last = NULL;", + portOnSelf + "_trigger.number_of_reactions = " + triggered.size() + ";")); + + // Set the physical_time_of_arrival + constructorCode.pr( + port, + CExtensionUtils.surroundWithIfFederated( + portOnSelf + "_trigger.physical_time_of_arrival = NEVER;")); + + if (containedReactor.getWidthSpec() != null) { + constructorCode.unindent(); + constructorCode.pr("}"); + } } + } + body.unindent(); + body.pr( + String.join( + "\n", + "} _lf_" + containedReactor.getName() + array + ";", + "int _lf_" + containedReactor.getName() + "_width;")); } - - /** - * This function is provided to allow extensions of the CGenerator to append the structure of the self struct - * @param body The body of the self struct - * @param decl The reactor declaration for the self struct - * @param constructorCode Code that is executed when the reactor is instantiated - */ - protected void generateSelfStructExtension( - CodeBuilder body, - ReactorDecl decl, - CodeBuilder constructorCode - ) { - // Do nothing - } - - /** Generate reaction functions definition for a reactor. - * These functions have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param r The reactor. - */ - public void generateReactions(CodeBuilder src, Reactor r) { - var reactionIndex = 0; - var reactor = ASTUtils.toDefinition(r); - for (Reaction reaction : allReactions(reactor)) { - generateReaction(src, reaction, r, reactionIndex); - // Increment reaction index even if the reaction is not in the federate - // so that across federates, the reaction indices are consistent. - reactionIndex++; - } + } + + /** + * This function is provided to allow extensions of the CGenerator to append the structure of the + * self struct + * + * @param body The body of the self struct + * @param decl The reactor declaration for the self struct + * @param constructorCode Code that is executed when the reactor is instantiated + */ + protected void generateSelfStructExtension( + CodeBuilder body, ReactorDecl decl, CodeBuilder constructorCode) { + // Do nothing + } + + /** + * Generate reaction functions definition for a reactor. These functions have a single argument + * that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param r The reactor. + */ + public void generateReactions(CodeBuilder src, Reactor r) { + var reactionIndex = 0; + var reactor = ASTUtils.toDefinition(r); + for (Reaction reaction : allReactions(reactor)) { + generateReaction(src, reaction, r, reactionIndex); + // Increment reaction index even if the reaction is not in the federate + // so that across federates, the reaction indices are consistent. + reactionIndex++; } - - /** Generate a reaction function definition for a reactor. - * This function will have a single argument that is a void* pointing to - * a struct that contains parameters, state variables, inputs (triggering or not), - * actions (triggering or produced), and outputs. - * @param reaction The reaction. - * @param r The reactor. - * @param reactionIndex The position of the reaction within the reactor. - */ - protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { - src.pr(CReactionGenerator.generateReaction( + } + + /** + * Generate a reaction function definition for a reactor. This function will have a single + * argument that is a void* pointing to a struct that contains parameters, state variables, inputs + * (triggering or not), actions (triggering or produced), and outputs. + * + * @param reaction The reaction. + * @param r The reactor. + * @param reactionIndex The position of the reaction within the reactor. + */ + protected void generateReaction( + CodeBuilder src, Reaction reaction, Reactor r, int reactionIndex) { + src.pr( + CReactionGenerator.generateReaction( reaction, r, reactionIndex, @@ -1437,707 +1403,746 @@ protected void generateReaction(CodeBuilder src, Reaction reaction, Reactor r, i errorReporter, types, targetConfig, - getTarget().requiresTypes - )); - } - - /** - * Record startup, shutdown, and reset reactions. - * @param instance A reactor instance. - */ - private void recordBuiltinTriggers(ReactorInstance instance) { - // For each reaction instance, allocate the arrays that will be used to - // trigger downstream reactions. - for (ReactionInstance reaction : instance.reactions) { - var reactor = reaction.getParent(); - var temp = new CodeBuilder(); - var foundOne = false; - - var reactionRef = CUtil.reactionRef(reaction); - - // Next handle triggers of the reaction that come from a multiport output - // of a contained reactor. Also, handle startup and shutdown triggers. - for (TriggerInstance trigger : reaction.triggers) { - if (trigger.isStartup()) { - temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &"+reactionRef+";"); - startupReactionCount += reactor.getTotalWidth(); - foundOne = true; - } else if (trigger.isShutdown()) { - temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &"+reactionRef+";"); - foundOne = true; - shutdownReactionCount += reactor.getTotalWidth(); - - if (targetConfig.tracing != null) { - var description = CUtil.getShortenedName(reactor); - var reactorRef = CUtil.reactorRef(reactor); - temp.pr(String.join("\n", - "_lf_register_trace_event("+reactorRef+", &("+reactorRef+"->_lf__shutdown),", - "trace_trigger, "+addDoubleQuotes(description+".shutdown")+");" - )); - } - } else if (trigger.isReset()) { - temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &"+reactionRef+";"); - resetReactionCount += reactor.getTotalWidth(); - foundOne = true; - } - } - if (foundOne) initializeTriggerObjects.pr(temp.toString()); + getTarget().requiresTypes)); + } + + /** + * Record startup, shutdown, and reset reactions. + * + * @param instance A reactor instance. + */ + private void recordBuiltinTriggers(ReactorInstance instance) { + // For each reaction instance, allocate the arrays that will be used to + // trigger downstream reactions. + for (ReactionInstance reaction : instance.reactions) { + var reactor = reaction.getParent(); + var temp = new CodeBuilder(); + var foundOne = false; + + var reactionRef = CUtil.reactionRef(reaction); + + // Next handle triggers of the reaction that come from a multiport output + // of a contained reactor. Also, handle startup and shutdown triggers. + for (TriggerInstance trigger : reaction.triggers) { + if (trigger.isStartup()) { + temp.pr("_lf_startup_reactions[_lf_startup_reactions_count++] = &" + reactionRef + ";"); + startupReactionCount += reactor.getTotalWidth(); + foundOne = true; + } else if (trigger.isShutdown()) { + temp.pr("_lf_shutdown_reactions[_lf_shutdown_reactions_count++] = &" + reactionRef + ";"); + foundOne = true; + shutdownReactionCount += reactor.getTotalWidth(); + + if (targetConfig.tracing != null) { + var description = CUtil.getShortenedName(reactor); + var reactorRef = CUtil.reactorRef(reactor); + temp.pr( + String.join( + "\n", + "_lf_register_trace_event(" + + reactorRef + + ", &(" + + reactorRef + + "->_lf__shutdown),", + "trace_trigger, " + addDoubleQuotes(description + ".shutdown") + ");")); + } + } else if (trigger.isReset()) { + temp.pr("_lf_reset_reactions[_lf_reset_reactions_count++] = &" + reactionRef + ";"); + resetReactionCount += reactor.getTotalWidth(); + foundOne = true; } + } + if (foundOne) initializeTriggerObjects.pr(temp.toString()); } - - /** - * Generate code to set up the tables used in _lf_start_time_step to decrement reference - * counts and mark outputs absent between time steps. This function puts the code - * into startTimeStep. - */ - private void generateStartTimeStep(ReactorInstance instance) { - // Avoid generating dead code if nothing is relevant. - var foundOne = false; - var temp = new CodeBuilder(); - var containerSelfStructName = CUtil.reactorRef(instance); - - // Handle inputs that get sent data from a reaction rather than from - // another contained reactor and reactions that are triggered by an - // output of a contained reactor. - // Note that there may be more than one reaction reacting to the same - // port so we have to avoid listing the port more than once. - var portsSeen = new LinkedHashSet(); - for (ReactionInstance reaction : instance.reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - portsSeen.add(port); - // This reaction is sending to an input. Must be - // the input of a contained reactor in the federate. - // NOTE: If instance == main and the federate is within a bank, - // this assumes that the reaction writes only to the bank member in the federate. - foundOne = true; - - temp.pr("// Add port "+port.getFullName()+" to array of is_present fields."); - - if (!instance.equals(port.getParent())) { - // The port belongs to contained reactor, so we also have - // iterate over the instance bank members. - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); - temp.startScopedBankChannelIteration(port, null); - } else { - temp.startScopedBankChannelIteration(port, "count"); - } - var portRef = CUtil.portRefNested(port); - var con = (port.isMultiport()) ? "->" : "."; - - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"is_present;"); - // Intended_tag is only applicable to ports in federated execution. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+portRef+con+"intended_tag;" - ) - ); - - startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); - - if (!instance.equals(port.getParent())) { - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); - temp.endScopedBankChannelIteration(port, null); - } else { - temp.endScopedBankChannelIteration(port, "count"); - } - } - } + } + + /** + * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts + * and mark outputs absent between time steps. This function puts the code into startTimeStep. + */ + private void generateStartTimeStep(ReactorInstance instance) { + // Avoid generating dead code if nothing is relevant. + var foundOne = false; + var temp = new CodeBuilder(); + var containerSelfStructName = CUtil.reactorRef(instance); + + // Handle inputs that get sent data from a reaction rather than from + // another contained reactor and reactions that are triggered by an + // output of a contained reactor. + // Note that there may be more than one reaction reacting to the same + // port so we have to avoid listing the port more than once. + var portsSeen = new LinkedHashSet(); + for (ReactionInstance reaction : instance.reactions) { + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + portsSeen.add(port); + // This reaction is sending to an input. Must be + // the input of a contained reactor in the federate. + // NOTE: If instance == main and the federate is within a bank, + // this assumes that the reaction writes only to the bank member in the federate. + foundOne = true; + + temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); + + if (!instance.equals(port.getParent())) { + // The port belongs to contained reactor, so we also have + // iterate over the instance bank members. + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(instance); + temp.startScopedBankChannelIteration(port, null); + } else { + temp.startScopedBankChannelIteration(port, "count"); + } + var portRef = CUtil.portRefNested(port); + var con = (port.isMultiport()) ? "->" : "."; + + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "is_present;"); + // Intended_tag is only applicable to ports in federated execution. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + portRef + + con + + "intended_tag;")); + + startTimeStepIsPresentCount += port.getWidth() * port.getParent().getTotalWidth(); + + if (!instance.equals(port.getParent())) { + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + temp.endScopedBankChannelIteration(port, null); + } else { + temp.endScopedBankChannelIteration(port, "count"); + } } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; + } + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; + + for (ActionInstance action : instance.actions) { + foundOne = true; + temp.startScopedBlock(instance); + + temp.pr( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of is_present fields.", + "_lf_is_present_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".is_present;")); + + // Intended_tag is only applicable to actions in federated execution with decentralized + // coordination. + temp.pr( + CExtensionUtils.surroundWithIfFederatedDecentralized( + String.join( + "\n", + "// Add action " + action.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + startTimeStepIsPresentCount + "] ", + " = &" + + containerSelfStructName + + "->_lf_" + + action.getName() + + ".intended_tag;"))); + + startTimeStepIsPresentCount += action.getParent().getTotalWidth(); + temp.endScopedBlock(); + } + if (foundOne) startTimeStep.pr(temp.toString()); + temp = new CodeBuilder(); + foundOne = false; - for (ActionInstance action : instance.actions) { - foundOne = true; - temp.startScopedBlock(instance); + // Next, set up the table to mark each output of each contained reactor absent. + for (ReactorInstance child : instance.children) { + if (child.outputs.size() > 0) { - temp.pr(String.join("\n", - "// Add action "+action.getFullName()+" to array of is_present fields.", - "_lf_is_present_fields["+startTimeStepIsPresentCount+"] ", - " = &"+containerSelfStructName+"->_lf_"+action.getName()+".is_present;" - )); + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(child); - // Intended_tag is only applicable to actions in federated execution with decentralized coordination. + var channelCount = 0; + for (PortInstance output : child.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { + foundOne = true; + temp.pr("// Add port " + output.getFullName() + " to array of is_present fields."); + temp.startChannelIteration(output); + temp.pr( + "_lf_is_present_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".is_present;"); + + // Intended_tag is only applicable to ports in federated execution with decentralized + // coordination. temp.pr( CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add action " + action.getFullName() - + " to array of intended_tag fields.", - "_lf_intended_tag_fields[" - + startTimeStepIsPresentCount + "] ", - " = &" + containerSelfStructName - + "->_lf_" + action.getName() - + ".intended_tag;" - ))); - - startTimeStepIsPresentCount += action.getParent().getTotalWidth(); - temp.endScopedBlock(); + String.join( + "\n", + "// Add port " + output.getFullName() + " to array of intended_tag fields.", + "_lf_intended_tag_fields[" + + startTimeStepIsPresentCount + + " + count] = &" + + CUtil.portRef(output) + + ".intended_tag;"))); + + temp.pr("count++;"); + channelCount += output.getWidth(); + temp.endChannelIteration(output); + } } - if (foundOne) startTimeStep.pr(temp.toString()); - temp = new CodeBuilder(); - foundOne = false; - - // Next, set up the table to mark each output of each contained reactor absent. - for (ReactorInstance child : instance.children) { - if (child.outputs.size() > 0) { - - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(child); - - var channelCount = 0; - for (PortInstance output : child.outputs) { - if (!output.getDependsOnReactions().isEmpty()){ - foundOne = true; - temp.pr("// Add port "+output.getFullName()+" to array of is_present fields."); - temp.startChannelIteration(output); - temp.pr("_lf_is_present_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".is_present;"); - - // Intended_tag is only applicable to ports in federated execution with decentralized coordination. - temp.pr( - CExtensionUtils.surroundWithIfFederatedDecentralized( - String.join("\n", - "// Add port "+output.getFullName()+" to array of intended_tag fields.", - "_lf_intended_tag_fields["+startTimeStepIsPresentCount+" + count] = &"+CUtil.portRef(output)+".intended_tag;" - ))); - - temp.pr("count++;"); - channelCount += output.getWidth(); - temp.endChannelIteration(output); - } - } - startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); - temp.endScopedBlock(); - temp.endScopedBlock(); - } - } - if (foundOne) startTimeStep.pr(temp.toString()); + startTimeStepIsPresentCount += channelCount * child.getTotalWidth(); + temp.endScopedBlock(); + temp.endScopedBlock(); + } } - - /** - * For each timer in the given reactor, generate initialization code for the offset - * and period fields. - * - * This method will also populate the global _lf_timer_triggers array, which is - * used to start all timers at the start of execution. - * - * @param instance A reactor instance. - */ - private void generateTimerInitializations(ReactorInstance instance) { - for (TimerInstance timer : instance.timers) { - if (!timer.isStartup()) { - initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); - timerCount += timer.getParent().getTotalWidth(); - } - } + if (foundOne) startTimeStep.pr(temp.toString()); + } + + /** + * For each timer in the given reactor, generate initialization code for the offset and period + * fields. + * + *

    This method will also populate the global _lf_timer_triggers array, which is used to start + * all timers at the start of execution. + * + * @param instance A reactor instance. + */ + private void generateTimerInitializations(ReactorInstance instance) { + for (TimerInstance timer : instance.timers) { + if (!timer.isStartup()) { + initializeTriggerObjects.pr(CTimerGenerator.generateInitializer(timer)); + timerCount += timer.getParent().getTotalWidth(); + } } - - /** - * Process a given .proto file. - * - * Run, if possible, the proto-c protocol buffer code generator to produce - * the required .h and .c files. - * @param filename Name of the file to process. - */ - public void processProtoFile(String filename) { - var protoc = commandFactory.createCommand( + } + + /** + * Process a given .proto file. + * + *

    Run, if possible, the proto-c protocol buffer code generator to produce the required .h and + * .c files. + * + * @param filename Name of the file to process. + */ + public void processProtoFile(String filename) { + var protoc = + commandFactory.createCommand( "protoc-c", - List.of("--c_out="+this.fileConfig.getSrcGenPath(), filename), + List.of("--c_out=" + this.fileConfig.getSrcGenPath(), filename), fileConfig.srcPath); - if (protoc == null) { - errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); - return; - } - var returnCode = protoc.run(); - if (returnCode == 0) { - var nameSansProto = filename.substring(0, filename.length() - 6); - targetConfig.compileAdditionalSources.add( - fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString() - ); - - targetConfig.compileLibraries.add("-l"); - targetConfig.compileLibraries.add("protobuf-c"); - targetConfig.compilerFlags.add("-lprotobuf-c"); - } else { - errorReporter.reportError("protoc-c returns error code " + returnCode); - } + if (protoc == null) { + errorReporter.reportError("Processing .proto files requires protoc-c >= 1.3.3."); + return; } - - /** - * Construct a unique type for the struct of the specified - * typed variable (port or action) of the specified reactor class. - * This is required to be the same as the type name returned by - * {@link #variableStructType(TriggerInstance)}. - */ - public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { - return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) +"_"+variable.getName()+"_t"; + var returnCode = protoc.run(); + if (returnCode == 0) { + var nameSansProto = filename.substring(0, filename.length() - 6); + targetConfig.compileAdditionalSources.add( + fileConfig.getSrcGenPath().resolve(nameSansProto + ".pb-c.c").toString()); + + targetConfig.compileLibraries.add("-l"); + targetConfig.compileLibraries.add("protobuf-c"); + targetConfig.compilerFlags.add("-lprotobuf-c"); + } else { + errorReporter.reportError("protoc-c returns error code " + returnCode); } - - /** - * Construct a unique type for the struct of the specified - * instance (port or action). - * This is required to be the same as the type name returned by - * {@link #variableStructType(Variable, Reactor, boolean)}. - * @param portOrAction The port or action instance. - * @return The name of the self struct. - */ - public static String variableStructType(TriggerInstance portOrAction) { - return CUtil.getName(portOrAction.getParent().reactorDefinition)+"_"+portOrAction.getName()+"_t"; + } + + /** + * Construct a unique type for the struct of the specified typed variable (port or action) of the + * specified reactor class. This is required to be the same as the type name returned by {@link + * #variableStructType(TriggerInstance)}. + */ + public static String variableStructType(Variable variable, Reactor reactor, boolean userFacing) { + return (userFacing ? reactor.getName().toLowerCase() : CUtil.getName(reactor)) + + "_" + + variable.getName() + + "_t"; + } + + /** + * Construct a unique type for the struct of the specified instance (port or action). This is + * required to be the same as the type name returned by {@link #variableStructType(Variable, + * Reactor, boolean)}. + * + * @param portOrAction The port or action instance. + * @return The name of the self struct. + */ + public static String variableStructType(TriggerInstance portOrAction) { + return CUtil.getName(portOrAction.getParent().reactorDefinition) + + "_" + + portOrAction.getName() + + "_t"; + } + + /** + * If tracing is turned on, then generate code that records the full name of the specified reactor + * instance in the trace table. If tracing is not turned on, do nothing. + * + * @param instance The reactor instance. + */ + private void generateTraceTableEntries(ReactorInstance instance) { + if (targetConfig.tracing != null) { + initializeTriggerObjects.pr(CTracingGenerator.generateTraceTableEntries(instance)); } - - /** - * If tracing is turned on, then generate code that records - * the full name of the specified reactor instance in the - * trace table. If tracing is not turned on, do nothing. - * @param instance The reactor instance. - */ - private void generateTraceTableEntries(ReactorInstance instance) { - if (targetConfig.tracing != null) { - initializeTriggerObjects.pr( - CTracingGenerator.generateTraceTableEntries(instance) - ); - } + } + + /** + * Generate code to instantiate the specified reactor instance and initialize it. + * + * @param instance A reactor instance. + */ + public void generateReactorInstance(ReactorInstance instance) { + var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); + var fullName = instance.getFullName(); + initializeTriggerObjects.pr( + "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); + // Generate the instance self struct containing parameters, state variables, + // and outputs (the "self" struct). + initializeTriggerObjects.pr( + CUtil.reactorRefName(instance) + + "[" + + CUtil.runtimeIndex(instance) + + "] = new_" + + CUtil.getName(reactorClass) + + "();"); + // Generate code to initialize the "self" struct in the + // _lf_initialize_trigger_objects function. + generateTraceTableEntries(instance); + generateReactorInstanceExtension(instance); + generateParameterInitialization(instance); + initializeOutputMultiports(instance); + initializeInputMultiports(instance); + recordBuiltinTriggers(instance); + watchdogCount += + CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); + + // Next, initialize the "self" struct with state variables. + // These values may be expressions that refer to the parameter values defined above. + generateStateVariableInitializations(instance); + + // Generate trigger objects for the instance. + generateTimerInitializations(instance); + generateActionInitializations(instance); + generateInitializeActionToken(instance); + generateSetDeadline(instance); + generateModeStructure(instance); + + // Recursively generate code for the children. + for (ReactorInstance child : instance.children) { + // If this reactor is a placeholder for a bank of reactors, then generate + // an array of instances of reactors and create an enclosing for loop. + // Need to do this for each of the builders into which the code writes. + startTimeStep.startScopedBlock(child); + initializeTriggerObjects.startScopedBlock(child); + generateReactorInstance(child); + initializeTriggerObjects.endScopedBlock(); + startTimeStep.endScopedBlock(); } - /** - * Generate code to instantiate the specified reactor instance and - * initialize it. - * @param instance A reactor instance. - */ - public void generateReactorInstance(ReactorInstance instance) { - var reactorClass = ASTUtils.toDefinition(instance.getDefinition().getReactorClass()); - var fullName = instance.getFullName(); - initializeTriggerObjects.pr( - "// ***** Start initializing " + fullName + " of class " + reactorClass.getName()); - // Generate the instance self struct containing parameters, state variables, - // and outputs (the "self" struct). - initializeTriggerObjects.pr(CUtil.reactorRefName(instance)+"["+CUtil.runtimeIndex(instance)+"] = new_"+CUtil.getName(reactorClass)+"();"); - // Generate code to initialize the "self" struct in the - // _lf_initialize_trigger_objects function. - generateTraceTableEntries(instance); - generateReactorInstanceExtension(instance); - generateParameterInitialization(instance); - initializeOutputMultiports(instance); - initializeInputMultiports(instance); - recordBuiltinTriggers(instance); - watchdogCount += CWatchdogGenerator.generateInitializeWatchdogs(initializeTriggerObjects, instance); - - // Next, initialize the "self" struct with state variables. - // These values may be expressions that refer to the parameter values defined above. - generateStateVariableInitializations(instance); - - // Generate trigger objects for the instance. - generateTimerInitializations(instance); - generateActionInitializations(instance); - generateInitializeActionToken(instance); - generateSetDeadline(instance); - generateModeStructure(instance); - - // Recursively generate code for the children. - for (ReactorInstance child : instance.children) { - // If this reactor is a placeholder for a bank of reactors, then generate - // an array of instances of reactors and create an enclosing for loop. - // Need to do this for each of the builders into which the code writes. - startTimeStep.startScopedBlock(child); - initializeTriggerObjects.startScopedBlock(child); - generateReactorInstance(child); - initializeTriggerObjects.endScopedBlock(); - startTimeStep.endScopedBlock(); + // For this instance, define what must be done at the start of + // each time step. This sets up the tables that are used by the + // _lf_start_time_step() function in reactor_common.c. + // Note that this function is also run once at the end + // so that it can deallocate any memory. + generateStartTimeStep(instance); + initializeTriggerObjects.pr("//***** End initializing " + fullName); + } + + /** + * For each action of the specified reactor instance, generate initialization code for the offset + * and period fields. + * + * @param instance The reactor. + */ + private void generateActionInitializations(ReactorInstance instance) { + initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + } + + /** + * Initialize actions by creating a lf_token_t in the self struct. This has the information + * required to allocate memory for the action payload. Skip any action that is not actually used + * as a trigger. + * + * @param reactor The reactor containing the actions. + */ + private void generateInitializeActionToken(ReactorInstance reactor) { + for (ActionInstance action : reactor.actions) { + // Skip this step if the action is not in use. + if (action.getParent().getTriggers().contains(action)) { + var type = getInferredType(action.getDefinition()); + var payloadSize = "0"; + if (!type.isUndefined()) { + var typeStr = types.getTargetType(type); + if (CUtil.isTokenType(type, types)) { + typeStr = CUtil.rootType(typeStr); + } + if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { + payloadSize = "sizeof(" + typeStr + ")"; + } } - // For this instance, define what must be done at the start of - // each time step. This sets up the tables that are used by the - // _lf_start_time_step() function in reactor_common.c. - // Note that this function is also run once at the end - // so that it can deallocate any memory. - generateStartTimeStep(instance); - initializeTriggerObjects.pr("//***** End initializing " + fullName); - } - - /** - * For each action of the specified reactor instance, generate initialization code - * for the offset and period fields. - * @param instance The reactor. - */ - private void generateActionInitializations(ReactorInstance instance) { - initializeTriggerObjects.pr(CActionGenerator.generateInitializers(instance)); + var selfStruct = CUtil.reactorRef(action.getParent()); + initializeTriggerObjects.pr( + CActionGenerator.generateTokenInitializer(selfStruct, action.getName(), payloadSize)); + } } - - /** - * Initialize actions by creating a lf_token_t in the self struct. - * This has the information required to allocate memory for the action payload. - * Skip any action that is not actually used as a trigger. - * @param reactor The reactor containing the actions. - */ - private void generateInitializeActionToken(ReactorInstance reactor) { - for (ActionInstance action : reactor.actions) { - // Skip this step if the action is not in use. - if (action.getParent().getTriggers().contains(action) - ) { - var type = getInferredType(action.getDefinition()); - var payloadSize = "0"; - if (!type.isUndefined()) { - var typeStr = types.getTargetType(type); - if (CUtil.isTokenType(type, types)) { - typeStr = CUtil.rootType(typeStr); - } - if (typeStr != null && !typeStr.equals("") && !typeStr.equals("void")) { - payloadSize = "sizeof("+typeStr+")"; - } - } - - var selfStruct = CUtil.reactorRef(action.getParent()); - initializeTriggerObjects.pr( - CActionGenerator.generateTokenInitializer( - selfStruct, action.getName(), payloadSize - ) - ); - } + } + + /** + * Generate code that is executed while the reactor instance is being initialized. This is + * provided as an extension point for subclasses. Normally, the reactions argument is the full + * list of reactions, but for the top-level of a federate, will be a subset of reactions that is + * relevant to the federate. + * + * @param instance The reactor instance. + */ + protected void generateReactorInstanceExtension(ReactorInstance instance) { + // Do nothing + } + + /** + * Generate code that initializes the state variables for a given instance. Unlike parameters, + * state variables are uniformly initialized for all instances of the same reactor. + * + * @param instance The reactor class instance + */ + protected void generateStateVariableInitializations(ReactorInstance instance) { + var reactorClass = instance.getDefinition().getReactorClass(); + var selfRef = CUtil.reactorRef(instance); + for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { + if (isInitialized(stateVar)) { + var mode = + stateVar.eContainer() instanceof Mode + ? instance.lookupModeInstance((Mode) stateVar.eContainer()) + : instance.getMode(false); + initializeTriggerObjects.pr( + CStateGenerator.generateInitializer(instance, selfRef, stateVar, mode, types)); + if (mode != null && stateVar.isReset()) { + modalStateResetCount += instance.getTotalWidth(); } + } } - - /** - * Generate code that is executed while the reactor instance is being initialized. - * This is provided as an extension point for subclasses. - * Normally, the reactions argument is the full list of reactions, - * but for the top-level of a federate, will be a subset of reactions that - * is relevant to the federate. - * @param instance The reactor instance. - */ - protected void generateReactorInstanceExtension(ReactorInstance instance) { - // Do nothing - } - - /** - * Generate code that initializes the state variables for a given instance. - * Unlike parameters, state variables are uniformly initialized for all instances - * of the same reactor. - * @param instance The reactor class instance - */ - protected void generateStateVariableInitializations(ReactorInstance instance) { - var reactorClass = instance.getDefinition().getReactorClass(); - var selfRef = CUtil.reactorRef(instance); - for (StateVar stateVar : allStateVars(toDefinition(reactorClass))) { - if (isInitialized(stateVar)) { - var mode = stateVar.eContainer() instanceof Mode ? - instance.lookupModeInstance((Mode) stateVar.eContainer()) : - instance.getMode(false); - initializeTriggerObjects.pr(CStateGenerator.generateInitializer( - instance, - selfRef, - stateVar, - mode, - types - )); - if (mode != null && stateVar.isReset()) { - modalStateResetCount += instance.getTotalWidth(); - } - } - } + } + + /** + * Generate code to set the deadline field of the reactions in the specified reactor instance. + * + * @param instance The reactor instance. + */ + private void generateSetDeadline(ReactorInstance instance) { + for (ReactionInstance reaction : instance.reactions) { + var selfRef = CUtil.reactorRef(reaction.getParent()) + "->_lf__reaction_" + reaction.index; + if (reaction.declaredDeadline != null) { + var deadline = reaction.declaredDeadline.maxDelay; + initializeTriggerObjects.pr( + selfRef + ".deadline = " + types.getTargetTimeExpr(deadline) + ";"); + } else { // No deadline. + initializeTriggerObjects.pr(selfRef + ".deadline = NEVER;"); + } } - - /** - * Generate code to set the deadline field of the reactions in the - * specified reactor instance. - * @param instance The reactor instance. - */ - private void generateSetDeadline(ReactorInstance instance) { - for (ReactionInstance reaction : instance.reactions) { - var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; - if (reaction.declaredDeadline != null) { - var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); - } else { // No deadline. - initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); - } - } + } + + /** + * Generate code to initialize modes. + * + * @param instance The reactor instance. + */ + private void generateModeStructure(ReactorInstance instance) { + CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); + if (!instance.modes.isEmpty()) { + modalReactorCount += instance.getTotalWidth(); } - - /** - * Generate code to initialize modes. - * @param instance The reactor instance. - */ - private void generateModeStructure(ReactorInstance instance) { - CModesGenerator.generateModeStructure(instance, initializeTriggerObjects); - if (!instance.modes.isEmpty()) { - modalReactorCount += instance.getTotalWidth(); - } + } + + /** + * Generate runtime initialization code for parameters of a given reactor instance + * + * @param instance The reactor instance. + */ + protected void generateParameterInitialization(ReactorInstance instance) { + var selfRef = CUtil.reactorRef(instance); + // Set the local bank_index variable so that initializers can use it. + initializeTriggerObjects.pr( + "bank_index = " + + CUtil.bankIndex(instance) + + ";" + + " SUPPRESS_UNUSED_WARNING(bank_index);"); + for (ParameterInstance parameter : instance.parameters) { + // NOTE: we now use the resolved literal value. For better efficiency, we could + // store constants in a global array and refer to its elements to avoid duplicate + // memory allocations. + // NOTE: If the parameter is initialized with a static initializer for an array + // or struct (the initialization expression is surrounded by { ... }), then we + // have to declare a static variable to ensure that the memory is put in data space + // and not on the stack. + // FIXME: Is there a better way to determine this than the string comparison? + var initializer = CParameterGenerator.getInitializer(parameter); + if (initializer.startsWith("{")) { + var temporaryVariableName = parameter.uniqueID(); + initializeTriggerObjects.pr( + String.join( + "\n", + "static " + + types.getVariableDeclaration(parameter.type, temporaryVariableName, true) + + " = " + + initializer + + ";", + selfRef + "->" + parameter.getName() + " = " + temporaryVariableName + ";")); + } else { + initializeTriggerObjects.pr( + selfRef + "->" + parameter.getName() + " = " + initializer + ";"); + } } - - /** - * Generate runtime initialization code for parameters of a given reactor instance - * @param instance The reactor instance. - */ - protected void generateParameterInitialization(ReactorInstance instance) { - var selfRef = CUtil.reactorRef(instance); - // Set the local bank_index variable so that initializers can use it. - initializeTriggerObjects.pr("bank_index = "+CUtil.bankIndex(instance)+";" - + " SUPPRESS_UNUSED_WARNING(bank_index);"); - for (ParameterInstance parameter : instance.parameters) { - // NOTE: we now use the resolved literal value. For better efficiency, we could - // store constants in a global array and refer to its elements to avoid duplicate - // memory allocations. - // NOTE: If the parameter is initialized with a static initializer for an array - // or struct (the initialization expression is surrounded by { ... }), then we - // have to declare a static variable to ensure that the memory is put in data space - // and not on the stack. - // FIXME: Is there a better way to determine this than the string comparison? - var initializer = CParameterGenerator.getInitializer(parameter); - if (initializer.startsWith("{")) { - var temporaryVariableName = parameter.uniqueID(); - initializeTriggerObjects.pr(String.join("\n", - "static "+types.getVariableDeclaration(parameter.type, temporaryVariableName, true)+" = "+initializer+";", - selfRef+"->"+parameter.getName()+" = "+temporaryVariableName+";" - )); - } else { - initializeTriggerObjects.pr(selfRef+"->"+parameter.getName()+" = "+initializer+";"); - } - } + } + + /** + * Generate code that mallocs memory for any output multiports. + * + * @param reactor The reactor instance. + */ + private void initializeOutputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance output : reactor.outputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeOutputMultiport(output, reactorSelfStruct)); } - - /** - * Generate code that mallocs memory for any output multiports. - * @param reactor The reactor instance. - */ - private void initializeOutputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance output : reactor.outputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeOutputMultiport( - output, - reactorSelfStruct - )); - } + } + + /** + * Allocate memory for inputs. + * + * @param reactor The reactor. + */ + private void initializeInputMultiports(ReactorInstance reactor) { + var reactorSelfStruct = CUtil.reactorRef(reactor); + for (PortInstance input : reactor.inputs) { + initializeTriggerObjects.pr( + CPortGenerator.initializeInputMultiport(input, reactorSelfStruct)); } - - /** - * Allocate memory for inputs. - * @param reactor The reactor. - */ - private void initializeInputMultiports(ReactorInstance reactor) { - var reactorSelfStruct = CUtil.reactorRef(reactor); - for (PortInstance input : reactor.inputs) { - initializeTriggerObjects.pr(CPortGenerator.initializeInputMultiport( - input, - reactorSelfStruct - )); - } + } + + @Override + public TargetTypes getTargetTypes() { + return types; + } + + /** + * Get the Docker generator. + * + * @param context + * @return + */ + protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { + return new CDockerGenerator(context); + } + + // ////////////////////////////////////////// + // // Protected methods. + + // Perform set up that does not generate code + protected void setUpGeneralParameters() { + accommodatePhysicalActionsIfPresent(); + targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); + // Create the main reactor instance if there is a main reactor. + createMainReactorInstance(); + if (hasModalReactors) { + // So that each separate compile knows about modal reactors, do this: + targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); } - - @Override - public TargetTypes getTargetTypes() { - return types; + if (targetConfig.threading + && targetConfig.platformOptions.platform == Platform.ARDUINO + && (targetConfig.platformOptions.board == null + || !targetConfig.platformOptions.board.contains("mbed"))) { + // non-MBED boards should not use threading + System.out.println( + "Threading is incompatible on your current Arduino flavor. Setting threading to false."); + targetConfig.threading = false; } - /** - * Get the Docker generator. - * @param context - * @return - */ - protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { - return new CDockerGenerator(context); + if (targetConfig.platformOptions.platform == Platform.ARDUINO + && !targetConfig.noCompile + && targetConfig.platformOptions.board == null) { + System.out.println( + "To enable compilation for the Arduino platform, you must specify the fully-qualified" + + " board name (FQBN) in the target property. For example, platform: {name: arduino," + + " board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target" + + " code only."); + targetConfig.noCompile = true; } - // ////////////////////////////////////////// - // // Protected methods. - - // Perform set up that does not generate code - protected void setUpGeneralParameters() { - accommodatePhysicalActionsIfPresent(); - targetConfig.compileDefinitions.put("LOG_LEVEL", targetConfig.logLevel.ordinal() + ""); - targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); - // Create the main reactor instance if there is a main reactor. - createMainReactorInstance(); - if (hasModalReactors) { - // So that each separate compile knows about modal reactors, do this: - targetConfig.compileDefinitions.put("MODAL_REACTORS", "TRUE"); - } - if (targetConfig.threading && targetConfig.platformOptions.platform == Platform.ARDUINO - && (targetConfig.platformOptions.board == null || !targetConfig.platformOptions.board.contains("mbed"))) { - //non-MBED boards should not use threading - System.out.println("Threading is incompatible on your current Arduino flavor. Setting threading to false."); - targetConfig.threading = false; - } - - if (targetConfig.platformOptions.platform == Platform.ARDUINO && !targetConfig.noCompile - && targetConfig.platformOptions.board == null) { - System.out.println("To enable compilation for the Arduino platform, you must specify the fully-qualified board name (FQBN) in the target property. For example, platform: {name: arduino, board: arduino:avr:leonardo}. Entering \"no-compile\" mode and generating target code only."); - targetConfig.noCompile = true; - } - - if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.threading - && targetConfig.platformOptions.userThreads >= 0) { - targetConfig.compileDefinitions.put( - PlatformOption.USER_THREADS.name(), - String.valueOf(targetConfig.platformOptions.userThreads) - ); - } else if (targetConfig.platformOptions.userThreads > 0) { - errorReporter.reportWarning("Specifying user threads is only for threaded Lingua Franca on the Zephyr platform. This option will be ignored."); - } - - if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake - pickScheduler(); - // FIXME: this and pickScheduler should be combined. - targetConfig.compileDefinitions.put( - "SCHEDULER", - targetConfig.schedulerType.name() - ); - targetConfig.compileDefinitions.put( - "NUMBER_OF_WORKERS", - String.valueOf(targetConfig.workers) - ); - } - pickCompilePlatform(); + if (targetConfig.platformOptions.platform == Platform.ZEPHYR + && targetConfig.threading + && targetConfig.platformOptions.userThreads >= 0) { + targetConfig.compileDefinitions.put( + PlatformOption.USER_THREADS.name(), + String.valueOf(targetConfig.platformOptions.userThreads)); + } else if (targetConfig.platformOptions.userThreads > 0) { + errorReporter.reportWarning( + "Specifying user threads is only for threaded Lingua Franca on the Zephyr platform. This" + + " option will be ignored."); } - protected void handleProtoFiles() { - // Handle .proto files. - for (String file : targetConfig.protoFiles) { - this.processProtoFile(file); - } + if (targetConfig.threading) { // FIXME: This logic is duplicated in CMake + pickScheduler(); + // FIXME: this and pickScheduler should be combined. + targetConfig.compileDefinitions.put("SCHEDULER", targetConfig.schedulerType.name()); + targetConfig.compileDefinitions.put( + "NUMBER_OF_WORKERS", String.valueOf(targetConfig.workers)); } + pickCompilePlatform(); + } - /** - * Generate code that needs to appear at the top of the generated - * C file, such as #define and #include statements. - */ - public String generateDirectives() { - CodeBuilder code = new CodeBuilder(); - code.prComment("Code generated by the Lingua Franca compiler from:"); - code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); - code.pr(CPreambleGenerator.generateDefineDirectives( - targetConfig, - fileConfig.getSrcGenPath(), - hasModalReactors - )); - code.pr(CPreambleGenerator.generateIncludeStatements( - targetConfig, - CCppMode - )); - return code.toString(); + protected void handleProtoFiles() { + // Handle .proto files. + for (String file : targetConfig.protoFiles) { + this.processProtoFile(file); } - - /** - * Generate top-level preamble code. - */ - protected String generateTopLevelPreambles(Reactor reactor) { - CodeBuilder builder = new CodeBuilder(); - var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; - builder.pr("#ifndef " + guard); - builder.pr("#define " + guard); - // Reactors that are instantiated by the specified reactor need to have - // their file-level preambles included. This needs to also include file-level - // preambles of base classes of those reactors. - Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) - .flatMap(it -> ASTUtils.allFileLevelPreambles(it).stream()) - .collect(Collectors.toSet()) - .forEach(it -> builder.pr(toText(it.getCode()))); - for (String file : targetConfig.protoFiles) { - var dotIndex = file.lastIndexOf("."); - var rootFilename = file; - if (dotIndex > 0) { - rootFilename = file.substring(0, dotIndex); - } - code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); - } - builder.pr("#endif"); - return builder.toString(); + } + + /** + * Generate code that needs to appear at the top of the generated C file, such as #define and + * #include statements. + */ + public String generateDirectives() { + CodeBuilder code = new CodeBuilder(); + code.prComment("Code generated by the Lingua Franca compiler from:"); + code.prComment("file:/" + FileUtil.toUnixString(fileConfig.srcFile)); + code.pr( + CPreambleGenerator.generateDefineDirectives( + targetConfig, fileConfig.getSrcGenPath(), hasModalReactors)); + code.pr(CPreambleGenerator.generateIncludeStatements(targetConfig, CCppMode)); + return code.toString(); + } + + /** Generate top-level preamble code. */ + protected String generateTopLevelPreambles(Reactor reactor) { + CodeBuilder builder = new CodeBuilder(); + var guard = "TOP_LEVEL_PREAMBLE_" + reactor.eContainer().hashCode() + "_H"; + builder.pr("#ifndef " + guard); + builder.pr("#define " + guard); + // Reactors that are instantiated by the specified reactor need to have + // their file-level preambles included. This needs to also include file-level + // preambles of base classes of those reactors. + Stream.concat(Stream.of(reactor), ASTUtils.allNestedClasses(reactor)) + .flatMap(it -> ASTUtils.allFileLevelPreambles(it).stream()) + .collect(Collectors.toSet()) + .forEach(it -> builder.pr(toText(it.getCode()))); + for (String file : targetConfig.protoFiles) { + var dotIndex = file.lastIndexOf("."); + var rootFilename = file; + if (dotIndex > 0) { + rootFilename = file.substring(0, dotIndex); + } + code.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); + builder.pr("#include " + addDoubleQuotes(rootFilename + ".pb-c.h")); } - - protected boolean targetLanguageIsCpp() { - return CCppMode; + builder.pr("#endif"); + return builder.toString(); + } + + protected boolean targetLanguageIsCpp() { + return CCppMode; + } + + /** + * Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if + * the line is recognized as the first line of an error message. Otherwise, return null. + * + * @param line A line of output from a compiler or other external tool that might generate errors. + * @return If the line is recognized as the start of an error message, then return a class + * containing the path to the file on which the error occurred (or null if there is none), the + * line number (or the string "1" if there is none), the character position (or the string "0" + * if there is none), and the message (or an empty string if there is none). + */ + @Override + public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + var matcher = compileErrorPattern.matcher(line); + if (matcher.find()) { + var result = new ErrorFileAndLine(); + result.filepath = matcher.group("path"); + result.line = matcher.group("line"); + result.character = matcher.group("column"); + result.message = matcher.group("message"); + + if (!result.message.toLowerCase().contains("error:")) { + result.isError = false; + } + return result; } - - /** Given a line of text from the output of a compiler, return - * an instance of ErrorFileAndLine if the line is recognized as - * the first line of an error message. Otherwise, return null. - * @param line A line of output from a compiler or other external - * tool that might generate errors. - * @return If the line is recognized as the start of an error message, - * then return a class containing the path to the file on which the - * error occurred (or null if there is none), the line number (or the - * string "1" if there is none), the character position (or the string - * "0" if there is none), and the message (or an empty string if there - * is none). - */ - @Override - public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { - var matcher = compileErrorPattern.matcher(line); - if (matcher.find()) { - var result = new ErrorFileAndLine(); - result.filepath = matcher.group("path"); - result.line = matcher.group("line"); - result.character = matcher.group("column"); - result.message = matcher.group("message"); - - if (!result.message.toLowerCase().contains("error:")) { - result.isError = false; - } - return result; + return null; + } + + //////////////////////////////////////////// + //// Private methods. + + /** Returns the Target enum for this generator */ + @Override + public Target getTarget() { + return Target.C; + } + + //////////////////////////////////////////////////////////// + //// Private methods + + /** + * If a main or federated reactor has been declared, create a ReactorInstance for this top level. + * This will also assign levels to reactions, then, if the program is federated, perform an AST + * transformation to disconnect connections between federates. + */ + private void createMainReactorInstance() { + if (this.mainDef != null) { + if (this.main == null) { + // Recursively build instances. + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + var reactionInstanceGraph = this.main.assignLevels(); + if (reactionInstanceGraph.nodeCount() > 0) { + errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); + return; } - return null; - } - - //////////////////////////////////////////// - //// Private methods. - - /** Returns the Target enum for this generator */ - @Override - public Target getTarget() { - return Target.C; - } - - //////////////////////////////////////////////////////////// - //// Private methods - - /** - * If a main or federated reactor has been declared, create a ReactorInstance - * for this top level. This will also assign levels to reactions, then, - * if the program is federated, perform an AST transformation to disconnect - * connections between federates. - */ - private void createMainReactorInstance() { - if (this.mainDef != null) { - if (this.main == null) { - // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); - var reactionInstanceGraph = this.main.assignLevels(); - if (reactionInstanceGraph.nodeCount() > 0) { - errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); - return; - } - if (hasDeadlines) { - this.main.assignDeadlines(); - } - // Inform the run-time of the breadth/parallelism of the reaction graph - var breadth = reactionInstanceGraph.getBreadth(); - if (breadth == 0) { - errorReporter.reportWarning("The program has no reactions"); - } else { - targetConfig.compileDefinitions.put( - "LF_REACTION_GRAPH_BREADTH", - String.valueOf(reactionInstanceGraph.getBreadth()) - ); - } - } + if (hasDeadlines) { + this.main.assignDeadlines(); } - } - - /** - * Generate an array of self structs for the reactor - * and one for each of its children. - * @param r The reactor instance. - */ - private void generateSelfStructs(ReactorInstance r) { - initializeTriggerObjects.pr(CUtil.selfType(r)+"* "+CUtil.reactorRefName(r)+"["+r.getTotalWidth()+"];"); - initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING("+CUtil.reactorRefName(r)+");"); - for (ReactorInstance child : r.children) { - generateSelfStructs(child); + // Inform the run-time of the breadth/parallelism of the reaction graph + var breadth = reactionInstanceGraph.getBreadth(); + if (breadth == 0) { + errorReporter.reportWarning("The program has no reactions"); + } else { + targetConfig.compileDefinitions.put( + "LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())); } + } + } + } + + /** + * Generate an array of self structs for the reactor and one for each of its children. + * + * @param r The reactor instance. + */ + private void generateSelfStructs(ReactorInstance r) { + initializeTriggerObjects.pr( + CUtil.selfType(r) + "* " + CUtil.reactorRefName(r) + "[" + r.getTotalWidth() + "];"); + initializeTriggerObjects.pr("SUPPRESS_UNUSED_WARNING(" + CUtil.reactorRefName(r) + ");"); + for (ReactorInstance child : r.children) { + generateSelfStructs(child); } + } } From a3a6d5b510556dcf69c4efc0599ab893501ce13d Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 23 May 2023 14:59:39 -0700 Subject: [PATCH 429/709] Add makeZephyrCompatible configurator --- org.lflang.tests/src/org/lflang/tests/Configurators.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index 21cb85fb43..a5db8f2abf 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -72,6 +72,14 @@ public static boolean makeZephyrCompatibleUnthreaded(LFTest test) { test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; return true; } + + public static boolean makeZephyrCompatible(LFTest test) { + test.getContext().getArgs().setProperty("tracing", "false"); + test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; + test.getContext().getTargetConfig().platformOptions.flash = false; + test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + return true; + } /** * Make no changes to the configuration. * From 24e581aeb66c3d3d3fc65905e908cc259389f5c4 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 23 May 2023 16:20:56 -0700 Subject: [PATCH 430/709] Run formatter --- test/C/src/zephyr/Timer.lf | 1 - test/C/src/zephyr/UserThreads.lf | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/C/src/zephyr/Timer.lf b/test/C/src/zephyr/Timer.lf index d3cb3f96de..a3dd0e68cc 100644 --- a/test/C/src/zephyr/Timer.lf +++ b/test/C/src/zephyr/Timer.lf @@ -3,7 +3,6 @@ target C { name: Zephyr, board: qemu_cortex_m3 }, - threading: false, timeout: 10 sec } diff --git a/test/C/src/zephyr/UserThreads.lf b/test/C/src/zephyr/UserThreads.lf index 744abb5748..115d8114a7 100644 --- a/test/C/src/zephyr/UserThreads.lf +++ b/test/C/src/zephyr/UserThreads.lf @@ -10,15 +10,15 @@ target C { } main reactor { - preamble {= + preamble {= + #include "platform.h" void func(void* arg) { lf_print("Hello from user thread"); - } + } - lf_thread_t thread_ids[3]; + lf_thread_t thread_ids[4]; =} - reaction(startup) {= int res; @@ -29,7 +29,7 @@ main reactor { } } - res = lf_thread_create(&thread_ids[i], &func, NULL); + res = lf_thread_create(&thread_ids[3], &func, NULL); if (res == 0) { lf_print_error_and_exit("Could create more threads than specified."); } else { From 6b09905194ae6d90c4145eef18e7cca37a751daf Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 16:51:17 -0700 Subject: [PATCH 431/709] Delete check (subsumed by spotlessCheck in CI). --- .../src/org/lflang/tests/compiler/RoundTripTests.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java index 8087d552a8..1beb54b81a 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java @@ -5,7 +5,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.fail; -import java.nio.file.Files; import java.nio.file.Path; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; @@ -58,10 +57,5 @@ private void run(Path file) throws Exception { "The reformatted version of %s was not equivalent to the original file.%n" + "Formatted file:%n%s%n%n", file, squishedTestCase)); - final String normalTestCase = FormattingUtils.render(originalModel); - Assertions.assertEquals( - Files.readString(file).replaceAll("\\r\\n?", "\n"), - normalTestCase, - "File is not formatted properly, or formatter is bugged. Check " + file); } } From 9195543920fafaaca7a2ad00db36f4e5f1b59624 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 17:15:57 -0700 Subject: [PATCH 432/709] Rename spotlessCheck workflow. --- .github/workflows/check-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index e47bf5513c..8c022f90a5 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -1,4 +1,4 @@ -name: Check if all files are formatted correctly with spotless +name: Spotless check on: workflow_call: From e40d53f68aa3e8f655b774e41f1c36889612de7e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 00:01:15 -0700 Subject: [PATCH 433/709] Refactor a bit. Also, undo a stray edit from earlier commit. --- .github/workflows/cancel.yml | 2 +- org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java | 2 +- org.lflang/src/org/lflang/generator/CodeMap.java | 4 ++++ .../src/org/lflang/generator/python/PythonValidator.java | 2 +- test/Python/src/ImportComposition.lf | 1 - .../federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf | 1 - test/Python/src/target/AfterNoTypes.lf | 1 - 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml index 00733bb5b8..49765257c9 100644 --- a/.github/workflows/cancel.yml +++ b/.github/workflows/cancel.yml @@ -2,7 +2,7 @@ name: Cancel previous jobs on: workflow_call: - + jobs: cancel: name: run diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java b/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java index 9ccc3d408d..fe52d6016c 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java @@ -92,7 +92,7 @@ void typescriptValidationTest() throws IOException { */ private void targetLanguageValidationTest(Target target, ErrorInserter.Builder builder) throws IOException { - long seed = 2290053266328212836L;//new Random().nextLong(); + long seed = new Random().nextLong(); System.out.printf( "Running validation tests for %s with random seed %d.%n", target.getDisplayName(), seed); Random random = new Random(seed); diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/src/org/lflang/generator/CodeMap.java index 9d196c7daa..7e5e603510 100644 --- a/org.lflang/src/org/lflang/generator/CodeMap.java +++ b/org.lflang/src/org/lflang/generator/CodeMap.java @@ -274,6 +274,10 @@ public Range adjusted(Path lfFile, Range generatedFileRange) { return start.compareTo(end) <= 0 ? new Range(start, end) : new Range(start, start); } + public int firstNonWhitespace(int line) { + return getGeneratedCode().lines().skip(line - 1).findFirst().orElse("").lastIndexOf(" ") + 1; + } + /* ------------------------- PRIVATE METHODS ------------------------- */ private CodeMap( diff --git a/org.lflang/src/org/lflang/generator/python/PythonValidator.java b/org.lflang/src/org/lflang/generator/python/PythonValidator.java index 12da60fd39..37893d270b 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonValidator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonValidator.java @@ -271,7 +271,7 @@ private void tryReportAlternative(String[] lines, int i) { lfFile, DiagnosticSeverity.Error, main.group().replace("*** ", "").replace("Sorry: ", ""), - map.adjusted(lfFile, Position.fromOneBased(line, map.getGeneratedCode().lines().skip(line - 1).findFirst().orElse("").lastIndexOf(" ") + 1)).getOneBasedLine()); + map.adjusted(lfFile, Position.fromOneBased(line, map.firstNonWhitespace(line))).getOneBasedLine()); } } } diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 08906537f3..5558db6163 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -10,7 +10,6 @@ main reactor ImportComposition { reaction(startup) -> a.x {= a.x.set(42) =} reaction(a.y) {= - +++++; receive_time = lf.time.logical_elapsed() print("Received {:d} at time {:d}".format(a.y.value, receive_time)) self.received = True diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 2dc3bcfb34..15069f0aea 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -30,7 +30,6 @@ reactor Destination { state s = 1 reaction(x) {= - +++++; if x.value != self.s: self.sys.stderr.write("Expected {} and got {}.".format(self.s, x.value)) self.sys.exit(1) diff --git a/test/Python/src/target/AfterNoTypes.lf b/test/Python/src/target/AfterNoTypes.lf index bc7e810030..ef92444c34 100644 --- a/test/Python/src/target/AfterNoTypes.lf +++ b/test/Python/src/target/AfterNoTypes.lf @@ -19,7 +19,6 @@ reactor Print { reaction(x) {= self.received+=1 - +++++; elapsed_time = lf.time.logical_elapsed() print("Result is " + str(x.value)) if x.value != 84: From ceb9b7e3bea980c1aeb8d128666425d72592e7a7 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 23 May 2023 17:29:50 -0700 Subject: [PATCH 434/709] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca6573968c..dc9832cf35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: needs: cancel check-format: - uses: lf-lang/lingua-franca/.github/workflows/check-format.yml@ci-check-formatting + uses: lf-lang/lingua-franca/.github/workflows/check-format.yml@master needs: cancel # Run the unit tests. From f90dd83dc1bd8c542d82a2030e6b0072756bea28 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 20:27:57 -0700 Subject: [PATCH 435/709] Format. --- .../src/org/lflang/generator/python/PythonValidator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonValidator.java b/org.lflang/src/org/lflang/generator/python/PythonValidator.java index 37893d270b..7d040bace0 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonValidator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonValidator.java @@ -271,7 +271,9 @@ private void tryReportAlternative(String[] lines, int i) { lfFile, DiagnosticSeverity.Error, main.group().replace("*** ", "").replace("Sorry: ", ""), - map.adjusted(lfFile, Position.fromOneBased(line, map.firstNonWhitespace(line))).getOneBasedLine()); + map.adjusted( + lfFile, Position.fromOneBased(line, map.firstNonWhitespace(line))) + .getOneBasedLine()); } } } From daa1467728abf028ad53d484ac2d9592b44d08da Mon Sep 17 00:00:00 2001 From: Kagamihara Nadeshiko Date: Tue, 23 May 2023 20:43:52 -0700 Subject: [PATCH 436/709] Optimise gradle by applying intellij recommendations @petervdonovan mentioned that build time is slow with gradle and most of the time spent is related not to building/execution but initialisation and configuration. While I didn't find a profiler that tells me what exactly causes the long configuration time, it does appear that some time-consuming configurations were carried out regardless of whether or not they are needed (i.e. same time is needed for `buildAll` and `help`). This commit applied some of the optimations suggested by IntelliJ that prevents unnecessary configurations from running, and drastically improved the configuration time for `buildAll` locally. --- build.gradle | 4 +- org.lflang/build.gradle | 116 ++++++++++++++++++++-------------------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/build.gradle b/build.gradle index 348949c01e..563377e3d3 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ subprojects { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 - configurations.all { + configurations.configureEach { exclude group: 'asm' } @@ -115,4 +115,4 @@ spotless { formatAnnotations() } } -tasks.withType(SpotlessTask) { it.dependsOn(":org.lflang:jarCliTools") } +tasks.withType(SpotlessTask).configureEach { it.dependsOn(":org.lflang:jarCliTools") } diff --git a/org.lflang/build.gradle b/org.lflang/build.gradle index 5155c0a6e2..8d4f6a41c9 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/build.gradle @@ -42,7 +42,7 @@ dependencies { mwe2 "org.eclipse.xtext:org.eclipse.xtext.xtext.generator:${xtextVersion}" } -task generateXtextLanguage(type: JavaExec) { +tasks.register('generateXtextLanguage', JavaExec) { main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher' classpath = configurations.mwe2 inputs.file "src/org/lflang/GenerateLinguaFranca.mwe2" @@ -90,10 +90,10 @@ configurations { } } -task getSubmoduleVersions(type: Exec) { +tasks.register('getSubmoduleVersions', Exec) { description('Run a Git command to get the current status of submodules') workingDir project.rootDir - // This will make gradle execute git submodule status every time updateRustRuntime is called + // This will make gradle execute git submodule status every time updateRustRuntime is called outputs.upToDateWhen { false } def command = "git submodule status" @@ -119,7 +119,7 @@ task getSubmoduleVersions(type: Exec) { } } -task updateRustRuntime { +tasks.register('updateRustRuntime') { description('Record the VCS revisions of the language runtimes into a properties file available at runtime.') dependsOn getSubmoduleVersions @@ -138,7 +138,7 @@ task updateRustRuntime { sourceSets.main.output.dir tasks.updateRustRuntime.outputFile, builtBy: updateRustRuntime tasks.processResources.dependsOn(updateRustRuntime) -task checkRuntimeVersionFileUpToDate { +tasks.register('checkRuntimeVersionFileUpToDate') { description('Check that the runtime version recorded in the built Jar for LFC matches the version of the checked out submodule') dependsOn getSubmoduleVersions inputs.file updateRustRuntime.outputFile @@ -168,13 +168,13 @@ task checkRuntimeVersionFileUpToDate { apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' -task buildAll() { +tasks.register('buildAll') { apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' mainClassName = 'org.lflang.cli.Lfc' } -task jarCliTools(type: ShadowJar) { +tasks.register('jarCliTools', ShadowJar) { manifest { attributes('Main-Class': 'org.lflang.cli.Lfc') } @@ -186,7 +186,7 @@ task jarCliTools(type: ShadowJar) { // the classes manually, minimize does not see the dependency. While we can add an exclude // rule, this does not seem to work very well and causes problems when compiling for a // second time. Also see https://github.com/lf-lang/lingua-franca/pull/1285 - transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer){ + transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer) { resource = 'plugin.properties' } from sourceSets.main.output @@ -200,7 +200,7 @@ buildAll.finalizedBy jarCliTools // to escape cli flags which start with --.For instance --args ' --help'. // Otherwise they're parsed as arguments to the Gradle CLI, not lfc. -task runLfc(type: JavaExec) { +tasks.register('runLfc', JavaExec) { // builds and runs lfc description = "Build and run lfc, use --args to pass arguments" group = "application" @@ -209,7 +209,7 @@ task runLfc(type: JavaExec) { workingDir = '..' } -task runLff(type: JavaExec) { +tasks.register('runLff', JavaExec) { // builds and runs lff description = "Build and run lff, use --args to pass arguments" group = "application" @@ -218,75 +218,75 @@ task runLff(type: JavaExec) { workingDir = '..' } -task generateLanguageDiagramServer { - description 'Creates a jar that implements a language server with diagram support for LF.' +tasks.register('generateLanguageDiagramServer') { + description 'Creates a jar that implements a language server with diagram support for LF.' apply plugin: 'java' apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' mainClassName = "org.lflang.diagram.lsp.LanguageDiagramServer" - + compileJava { options.compilerArgs << '-Xlint:unchecked' } shadowJar { archiveClassifier = 'lds' - + // Handling of service loader registrations via META-INF/services/* mergeServiceFiles() // Merge properties - transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer){ + transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer) { resource = 'plugin.properties' } // Exclude files that are known to be dispensable for a language server exclude( - '*._trace', - '*.ecore', - '*.ecorediag', - '*.g', - '*.genmodel', - '*.html', - '*.mwe2', - '*.profile', - '*.xtext', - '*readme.txt', - '.api_description', - '.options', - 'about.*', - 'about_*', - 'about_files/*', - 'ant_tasks/*', - 'cheatsheets/*', - 'com/*/*.java', - 'de/*/*.java', - 'docs/*', - 'log4j.properties', - 'META-INF/*.DSA', - 'META-INF/*.RSA', - 'META-INF/*.SF', - 'META-INF/changelog.txt', - 'META-INF/DEPENDENCIES', - 'META-INF/eclipse.inf', - 'META-INF/INDEX.LIST', - 'META-INF/maven/*', - 'META-INF/NOTICE', - 'META-INF/NOTICE.txt', - 'META-INF/p2.inf', - 'META-INF/versions/*/module-info.class', - 'modeling32.png', - 'module-info.class', - 'org/*/*.java', - 'OSGI-INF/l10n/bundle.properties', - 'plugin.xml', - 'profile.list', - 'schema/*', - 'systembundle.properties', - 'xtend-gen/*', - 'xtext32.png', + '*._trace', + '*.ecore', + '*.ecorediag', + '*.g', + '*.genmodel', + '*.html', + '*.mwe2', + '*.profile', + '*.xtext', + '*readme.txt', + '.api_description', + '.options', + 'about.*', + 'about_*', + 'about_files/*', + 'ant_tasks/*', + 'cheatsheets/*', + 'com/*/*.java', + 'de/*/*.java', + 'docs/*', + 'log4j.properties', + 'META-INF/*.DSA', + 'META-INF/*.RSA', + 'META-INF/*.SF', + 'META-INF/changelog.txt', + 'META-INF/DEPENDENCIES', + 'META-INF/eclipse.inf', + 'META-INF/INDEX.LIST', + 'META-INF/maven/*', + 'META-INF/NOTICE', + 'META-INF/NOTICE.txt', + 'META-INF/p2.inf', + 'META-INF/versions/*/module-info.class', + 'modeling32.png', + 'module-info.class', + 'org/*/*.java', + 'OSGI-INF/l10n/bundle.properties', + 'plugin.xml', + 'profile.list', + 'schema/*', + 'systembundle.properties', + 'xtend-gen/*', + 'xtext32.png', ) // Minimizing should be enabled with caution because some classes are only From f61362b2b489ed9f7c430d443ef56ea89338a0e3 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 21:00:23 -0700 Subject: [PATCH 437/709] Fix validator check for C generics. --- .../org/lflang/validation/LFValidator.java | 15 ++++--- test/C/src/generics/TypeCheck.lf | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 test/C/src/generics/TypeCheck.lf diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 747b22ffc3..b9df7e1e18 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -216,6 +216,13 @@ public void checkAssignment(Assignment assignment) { } } + private Type portTypeIfResolvable(VarRef port) { + var portType = ((Port) port.getVariable()).getType(); + return port.getContainer() == null + ? portType + : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); + } + @Check(CheckType.FAST) public void checkConnection(Connection connection) { @@ -270,13 +277,9 @@ public void checkConnection(Connection connection) { // error. Avoid a class cast exception. if (port.getVariable() instanceof Port) { if (type == null) { - type = ((Port) port.getVariable()).getType(); + type = portTypeIfResolvable(port); } else { - var portType = ((Port) port.getVariable()).getType(); - portType = - port.getContainer() == null - ? portType - : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); + var portType = portTypeIfResolvable(port); if (!sameType(type, portType)) { error("Types do not match.", Literals.CONNECTION__LEFT_PORTS); } diff --git a/test/C/src/generics/TypeCheck.lf b/test/C/src/generics/TypeCheck.lf new file mode 100644 index 0000000000..72575ca9ea --- /dev/null +++ b/test/C/src/generics/TypeCheck.lf @@ -0,0 +1,43 @@ +/** Check that two reactors that use generics can be connected together. */ +target C { + fast: true +} + +reactor Count(offset: time = 0, period: time = 1 sec) { + state count: int = 1 + output out: int + timer t(offset, period) + + reaction(t) -> out {= lf_set(out, self->count++); =} +} + +reactor TestCount(start: int = 1, num_inputs: int = 1) { + state count: int = 0 + state inputs_received: int = 0 + input in: T + + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count++; + self->inputs_received++; + =} + + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", + self->num_inputs, + self->inputs_received + ); + } + =} +} + +main reactor { + count = new Count() + testcount = new TestCount() + count.out -> testcount.in +} From 752432f0ad4c9380b68ea99fb2be0a244e335838 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 21:15:08 -0700 Subject: [PATCH 438/709] Add timeout. --- test/C/src/generics/TypeCheck.lf | 1 + 1 file changed, 1 insertion(+) diff --git a/test/C/src/generics/TypeCheck.lf b/test/C/src/generics/TypeCheck.lf index 72575ca9ea..8aa3d42f8d 100644 --- a/test/C/src/generics/TypeCheck.lf +++ b/test/C/src/generics/TypeCheck.lf @@ -1,5 +1,6 @@ /** Check that two reactors that use generics can be connected together. */ target C { + timeout: 3 sec, fast: true } From 67c7bce5ce75e4b39df9aa17851e4e70027cf9ee Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 21:28:37 -0700 Subject: [PATCH 439/709] Add comment. --- org.lflang/src/org/lflang/validation/LFValidator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index b9df7e1e18..555d6d0da3 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -216,6 +216,7 @@ public void checkAssignment(Assignment assignment) { } } + /** Resolve the port type if it is known. */ private Type portTypeIfResolvable(VarRef port) { var portType = ((Port) port.getVariable()).getType(); return port.getContainer() == null From b7f494fb05058cf9a2bb33c568974e055b5f789a Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 21:31:02 -0700 Subject: [PATCH 440/709] Fix test. --- test/C/src/generics/TypeCheck.lf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/C/src/generics/TypeCheck.lf b/test/C/src/generics/TypeCheck.lf index 8aa3d42f8d..3080af48ea 100644 --- a/test/C/src/generics/TypeCheck.lf +++ b/test/C/src/generics/TypeCheck.lf @@ -13,7 +13,7 @@ reactor Count(offset: time = 0, period: time = 1 sec) { } reactor TestCount(start: int = 1, num_inputs: int = 1) { - state count: int = 0 + state count: int = start state inputs_received: int = 0 input in: T @@ -39,6 +39,6 @@ reactor TestCount(start: int = 1, num_inputs: int = 1) { main reactor { count = new Count() - testcount = new TestCount() + testcount = new TestCount(num_inputs = 4) count.out -> testcount.in } From b7bd75b3e6153c84a15737ba7120345928297647 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 23 May 2023 22:31:45 -0700 Subject: [PATCH 441/709] Update submodule pointer --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 845daae394..83b1cef7fd 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 845daae39479b8c06d15c1215aca575a4728a599 +Subproject commit 83b1cef7fd4209b3e25b6a310ce8f964277d9692 From 19d54baa77c05f442fddd629600113f71a8f4b59 Mon Sep 17 00:00:00 2001 From: Jakio815 Date: Wed, 24 May 2023 15:44:19 +0900 Subject: [PATCH 442/709] Move to not failing --- .../C/src/federated/{failing => }/SimpleFederatedAuthenticated.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/federated/{failing => }/SimpleFederatedAuthenticated.lf (100%) diff --git a/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf b/test/C/src/federated/SimpleFederatedAuthenticated.lf similarity index 100% rename from test/C/src/federated/failing/SimpleFederatedAuthenticated.lf rename to test/C/src/federated/SimpleFederatedAuthenticated.lf From de51be1ad4cebd650f6c7089dd4bb1d6676bb6da Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 24 May 2023 13:12:29 +0200 Subject: [PATCH 443/709] Fixed race condition in C++ enclave coordination This pulls in https://github.com/lf-lang/reactor-cpp/pull/49 to fix https://github.com/lf-lang/lingua-franca/issues/1746 --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a13eda638f..c7b736296c 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a13eda638fd5a4a71c8d42ef5fa20ef692370f87 +Subproject commit c7b736296cd365ec90996259d637d926090a133c From bc7033d94ed14dbd8814b12c2a7cb8a9e294abe9 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 24 May 2023 13:18:01 +0200 Subject: [PATCH 444/709] Revert "Fixed race condition in C++ enclave coordination" This reverts commit de51be1ad4cebd650f6c7089dd4bb1d6676bb6da. --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index c7b736296c..a13eda638f 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit c7b736296cd365ec90996259d637d926090a133c +Subproject commit a13eda638fd5a4a71c8d42ef5fa20ef692370f87 From 5e9150b7a52b1580c079b3cdc14132b0b4540162 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 24 May 2023 13:12:29 +0200 Subject: [PATCH 445/709] Fixed race condition in C++ enclave coordination This pulls in https://github.com/lf-lang/reactor-cpp/pull/49 to fix https://github.com/lf-lang/lingua-franca/issues/1746 --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a13eda638f..b607f1f640 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a13eda638fd5a4a71c8d42ef5fa20ef692370f87 +Subproject commit b607f1f64083ab531e7a676b29de75f076aa1cde From 849b9dfddee75f3f934605f02203532099a6ae88 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 24 May 2023 18:59:29 +0200 Subject: [PATCH 446/709] initial gradle setup cleanup --- build.gradle | 118 ------- lfc/build.gradle | 52 ++++ .../src/org/lflang/cli/Lfc.java | 0 org.lflang.tests/build.gradle | 75 ----- org.lflang/build.gradle | 287 +++--------------- settings.gradle | 6 +- 6 files changed, 95 insertions(+), 443 deletions(-) delete mode 100644 build.gradle create mode 100644 lfc/build.gradle rename {org.lflang => lfc}/src/org/lflang/cli/Lfc.java (100%) delete mode 100644 org.lflang.tests/build.gradle diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 563377e3d3..0000000000 --- a/build.gradle +++ /dev/null @@ -1,118 +0,0 @@ -import com.diffplug.gradle.spotless.SpotlessTask -import lfformat.LfFormatStep - -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath "org.xtext:xtext-gradle-plugin:${xtextGradleVersion}" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}" - } -} - -plugins { - id "com.github.johnrengelman.shadow" version "${shadowJarVersion}" - id 'java' - id 'jacoco' - id "com.diffplug.spotless" version "${spotlessVersion}" -} - -subprojects { - repositories { - mavenCentral() - } - - apply plugin: 'kotlin' - compileKotlin { - destinationDir = compileJava.destinationDir - kotlinOptions { - jvmTarget = kotlinJvmTarget - } - } - compileTestKotlin { - kotlinOptions { - jvmTarget = kotlinJvmTarget - } - } - - dependencies { - implementation platform("org.eclipse.xtext:xtext-dev-bom:${xtextVersion}") - // https://mvnrepository.com/artifact/com.google.inject/guice - implementation group: 'com.google.inject', name: 'guice', version: guiceVersion - // https://picocli.info/ - implementation group: 'info.picocli', name: 'picocli', version: picocliVersion - // https://mvnrepository.com/artifact/com.google.code.gson/gson - implementation group: 'com.google.code.gson', name: 'gson', version: gsonVersion - implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlinVersion - implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion - } - - apply from: "${rootDir}/gradle/source-layout.gradle" - apply plugin: 'eclipse' - - // generate xtend sources before kotlin compilation - compileKotlin.dependsOn(":org.lflang:generateXtextLanguage") - - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - - configurations.configureEach { - exclude group: 'asm' - } - - // Delete generated sources on `gradle clean` - clean.doFirst { - project.logger.info("Deleting ${projectDir}/src-gen") - delete "${projectDir}/src-gen/" - } -} - -// Our CI uses --tests filters, which fails if some -// subprojects have no matching test. -// -// https://stackoverflow.com/questions/26147480/how-to-make-gradle-not-to-mark-build-failed-if-no-tests-are-found -subprojects { - test { - filter { - setFailOnNoMatchingTests(false) - } - testLogging { - // print exception message when a test fails. - exceptionFormat "full" - } - } -} - - -spotless { - repositories { - mavenCentral() - } - - format 'misc', { - // define the files to apply `misc` to - target '*.gradle', '*.md', '.gitignore' - - // define the steps to apply to those files - trimTrailingWhitespace() - indentWithSpaces() // or spaces. Takes an integer argument if you don't like 4 - endWithNewline() - } - - format 'linguaFranca', { - addStep(LfFormatStep.create(project.projectDir)) - target 'test/*/src/**/*.lf' // you have to set the target manually - targetExclude 'test/**/failing/**' - } - - java { - target 'org.lflang*/src/**/*.java', 'buildSrc/**/*.java' - // The following is quoted from https://github.com/google/google-java-format - // "Note: There is no configurability as to the formatter's algorithm for formatting. - // This is a deliberate design decision to unify our code formatting on a single format." - googleJavaFormat(googleJavaFormatVersion).reflowLongStrings() - formatAnnotations() - } -} -tasks.withType(SpotlessTask).configureEach { it.dependsOn(":org.lflang:jarCliTools") } diff --git a/lfc/build.gradle b/lfc/build.gradle new file mode 100644 index 0000000000..7dd8ee764b --- /dev/null +++ b/lfc/build.gradle @@ -0,0 +1,52 @@ +plugins { + id 'java' + id 'application' +} + +sourceSets { + main { + java { + srcDirs = ['src'] + } + } +} + +repositories { + mavenCentral() + // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. + maven { + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + } +} + +dependencies { + implementation "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}" + implementation "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:${xtextVersion}" + implementation "org.eclipse.xtext:org.eclipse.xtext.ide:${xtextVersion}" + // https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources + implementation group: 'org.eclipse.platform', name: 'org.eclipse.core.resources', version: "${resourcesVersion}" + // https://mvnrepository.com/artifact/org.eclipse.emf/org.eclipse.emf.mwe2.launch + implementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.mwe2.launch', version: "${mwe2LaunchVersion}" + // https://mvnrepository.com/artifact/org.eclipse.lsp4j/org.eclipse.lsp4j + implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: "${lsp4jVersion}" + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.4' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.4' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.4' + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:${klighdVersion}") { + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' + } + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:${klighdVersion}") { + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' + } + implementation group: 'info.picocli', name: 'picocli', version: picocliVersion + implementation project(':org.lflang') +} + +application { + mainClass = 'org.lflang.cli.Lfc' + tasks.run.workingDir = rootProject.projectDir +} + +build.finalizedBy installDist \ No newline at end of file diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/lfc/src/org/lflang/cli/Lfc.java similarity index 100% rename from org.lflang/src/org/lflang/cli/Lfc.java rename to lfc/src/org/lflang/cli/Lfc.java diff --git a/org.lflang.tests/build.gradle b/org.lflang.tests/build.gradle deleted file mode 100644 index 97f664c1a8..0000000000 --- a/org.lflang.tests/build.gradle +++ /dev/null @@ -1,75 +0,0 @@ -repositories { - mavenCentral() - // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - } -} -dependencies { - implementation project(':org.lflang') - testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}" - testImplementation "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}" - testImplementation "org.junit.platform:junit-platform-commons:${jUnitPlatformVersion}" - testImplementation "org.junit.platform:junit-platform-engine:${jUnitPlatformVersion}" - testImplementation "org.opentest4j:opentest4j:${openTest4jVersion}" - testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:${xtextVersion}" - testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:${xtextVersion}" -} - -apply plugin: 'java' -apply plugin: 'jacoco' - -jacoco { - toolVersion = jacocoVersion - reportsDirectory = file("$buildDir/reports/jacoco") //default directory where jacoco generates test reports -} - - -jacocoTestReport { - reports { - xml.required = true - csv.required = false - html.destination file("${buildDir}/reports/html/jacoco") - xml.destination file("${buildDir}/reports/xml/jacoco") - } - def fileFilter = [ 'org/lflang/services/**', - 'org/lflang/linguaFranca/impl/**', - 'org/lflang/serializer/**', - 'org/lflang/linguaFranca/util/**', - 'org/lflang/linguaFranca/**', - 'org/lflang/parser/antlr/**' - ] - def mainCls = fileTree(dir: "$project.buildDir/../../org.lflang/build/classes/java/main", excludes: fileFilter) - def javaSrc = "$project.buildDir/../../org.lflang/src" - - classDirectories.from = files(mainCls) - sourceDirectories.from = files([javaSrc]) -} - -test { - testLogging { - events "passed", "skipped", "failed" - showStandardStreams = true - } - // Pass the scheduler property on to the Java VM - systemProperty 'scheduler', System.getProperty('scheduler') - systemProperty 'runtime', System.getProperty('runtime') - // Suggested by Gradle documentation: https://guides.gradle.org/performance/#parallel_test_execution - maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 - useJUnitPlatform() - finalizedBy jacocoTestReport - workingDir = ".." - filter { - setFailOnNoMatchingTests(true) - } -} - -test.dependsOn("compileKotlin") - -task runSingleTest(type: JavaExec) { - description = "Execute a single test, use with eg --args test/Python/src/Minimal.lf" - group = "test" - classpath = sourceSets.test.runtimeClasspath - workingDir = ".." - mainClass = 'org.lflang.tests.RunSingleTestMain' -} diff --git a/org.lflang/build.gradle b/org.lflang/build.gradle index 8d4f6a41c9..f93af170ad 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/build.gradle @@ -1,4 +1,36 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +plugins { + id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" + id 'java-library' +} + +sourceSets { + main { + java { + srcDirs = ['src', 'src-gen'] + } + kotlin { + srcDirs = ['src', 'src-gen'] + } + resources { + srcDirs = ['src-gen', 'src'] + include 'lib/' + include 'org/lflang/LF.xtextbin' + include 'org/lflang/parser/antlr/internal/InternalLF.tokens' + } + } +} + +compileKotlin { + destinationDir = compileJava.destinationDir + kotlinOptions { + jvmTarget = kotlinJvmTarget + } +} +compileTestKotlin { + kotlinOptions { + jvmTarget = kotlinJvmTarget + } +} repositories { mavenCentral() @@ -7,6 +39,7 @@ repositories { url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" } } + dependencies { implementation "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}" implementation "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:${xtextVersion}" @@ -28,6 +61,7 @@ dependencies { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } + implementation group: 'info.picocli', name: 'picocli', version: picocliVersion } configurations { @@ -51,252 +85,9 @@ tasks.register('generateXtextLanguage', JavaExec) { args += "src/org/lflang/GenerateLinguaFranca.mwe2" args += "-p" args += "rootPath=/${projectDir}/.." - - // Currently we don't need to delete any generated files because we use the - // Java/Xtend implementations. However, if we commit to porting such files - // to Kotlin, we might to reintroduce the deletion mechanism below. - /*doLast { - def filesToDelete = [ - "org.lflang.validation.LFValidator", - "org.lflang.LFRuntimeModule", - "org.lflang.LFStandaloneSetup", - "org.lflang.generator.LFGenerator", - "org.lflang.scoping.LFScopeProvider" - ] - - filesToDelete.each { qname -> - def path = qname.replace('.', '/') - def ktFile = file("src/${path}.kt") - def javaFile = file("src/${path}.java") - def xtendFile = file("src/${path}.xtend") - - if (ktFile.exists() || xtendFile.exists()) { - def chosenLang = ktFile.exists() ? "Kotlin" : "Xtend" - project.logger.info("deleting ${projectDir.relativePath(javaFile)}, the ${chosenLang} file prevails") - project.delete(javaFile) // generated by Xtend - } else { - project.logger.info("no ${projectDir.relativePath(ktFile)}, leaving the Java implementation in") - } - } - }*/ -} -processResources.dependsOn(generateXtextLanguage) -clean.dependsOn(cleanGenerateXtextLanguage) -eclipse.classpath.plusConfigurations += [configurations.mwe2] - -configurations { - cli_impl { - extendsFrom implementation - } -} - -tasks.register('getSubmoduleVersions', Exec) { - description('Run a Git command to get the current status of submodules') - workingDir project.rootDir - // This will make gradle execute git submodule status every time updateRustRuntime is called - outputs.upToDateWhen { false } - - def command = "git submodule status" - if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { - commandLine 'cmd', '/c', command - } else { - commandLine 'sh', '-c', command - } - standardOutput = new ByteArrayOutputStream() - - ext.outputFile = file("$project.buildDir/submodule-status.properties") - outputs.file(outputFile) - - doLast { - def matcher = standardOutput.toString() =~ ~"(?m)^[-+ ]?([0-9a-f]+) org.lflang/src/lib/\\w+/reactor-([-a-zA-Z]+)" - def properties = new StringBuilder() - while (matcher.find()) { - def rev = matcher.group(1) - def language = matcher.group(2) - properties << "$language = $rev\n" - } - outputFile.text = properties - } -} - -tasks.register('updateRustRuntime') { - description('Record the VCS revisions of the language runtimes into a properties file available at runtime.') - - dependsOn getSubmoduleVersions - // If the output of the git submodule status did not change (the getSubmoduleVersions task), then this task is considered up to date. - inputs.files(getSubmoduleVersions.outputs) - ext.outputFile = file("$project.projectDir/src/lib/rs/runtime-version.properties") - outputs.file(outputFile) - - doLast { - def upToDateProps = new Properties() - getSubmoduleVersions.outputFile.withReader { r -> upToDateProps.load(r) } - outputFile.text = "rs = " + upToDateProps.get("rs") + "\n" - } -} -// add the generated file as an output -sourceSets.main.output.dir tasks.updateRustRuntime.outputFile, builtBy: updateRustRuntime -tasks.processResources.dependsOn(updateRustRuntime) - -tasks.register('checkRuntimeVersionFileUpToDate') { - description('Check that the runtime version recorded in the built Jar for LFC matches the version of the checked out submodule') - dependsOn getSubmoduleVersions - inputs.file updateRustRuntime.outputFile - - doLast { - def rtProps = new Properties() - updateRustRuntime.outputFile.withReader { r -> rtProps.load(r) } - def upToDateProps = new Properties() - getSubmoduleVersions.outputFile.withReader { r -> upToDateProps.load(r) } - - upToDateProps.each { language, rev -> - def actualLanguage = rtProps.get(language) - if (actualLanguage == null) - return - if (actualLanguage != rev) { - logger.error("Runtime for $language is not checked out at correct revision:\n" + - "expected: $rev\n" + - "actual: $actualLanguage\n" + - "You may need to call `./gradlew updateRustRuntime`.") - } else { - logger.info("Success: Runtime for $language is checked out at expected revision $rev") - } - } - } -} - -apply plugin: 'application' -apply plugin: 'com.github.johnrengelman.shadow' - -tasks.register('buildAll') { - apply plugin: 'application' - apply plugin: 'com.github.johnrengelman.shadow' - mainClassName = 'org.lflang.cli.Lfc' -} - -tasks.register('jarCliTools', ShadowJar) { - manifest { - attributes('Main-Class': 'org.lflang.cli.Lfc') - } - configurations = [project.configurations.cli_impl] - exclude 'test/*' - exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA' - // We should use minimize() here to reduce the size of the JAR, but it causes problems - // with regard to our Kotlin classes. Since we don't use imports to load them but load - // the classes manually, minimize does not see the dependency. While we can add an exclude - // rule, this does not seem to work very well and causes problems when compiling for a - // second time. Also see https://github.com/lf-lang/lingua-franca/pull/1285 - transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer) { - resource = 'plugin.properties' - } - from sourceSets.main.output -} - -buildAll.finalizedBy jarCliTools - -// Tasks for running specific CLI tools. -// The working directory will be the root directory of the lingua franca project -// CLI arguments can be passed to lfc by using --args. Note that you need -// to escape cli flags which start with --.For instance --args ' --help'. -// Otherwise they're parsed as arguments to the Gradle CLI, not lfc. - -tasks.register('runLfc', JavaExec) { - // builds and runs lfc - description = "Build and run lfc, use --args to pass arguments" - group = "application" - classpath = sourceSets.main.runtimeClasspath - mainClass = 'org.lflang.cli.Lfc' - workingDir = '..' -} - -tasks.register('runLff', JavaExec) { - // builds and runs lff - description = "Build and run lff, use --args to pass arguments" - group = "application" - classpath = sourceSets.main.runtimeClasspath - mainClass = 'org.lflang.cli.Lff' - workingDir = '..' -} - -tasks.register('generateLanguageDiagramServer') { - description 'Creates a jar that implements a language server with diagram support for LF.' - - apply plugin: 'java' - apply plugin: 'application' - apply plugin: 'com.github.johnrengelman.shadow' - - mainClassName = "org.lflang.diagram.lsp.LanguageDiagramServer" - - compileJava { - options.compilerArgs << '-Xlint:unchecked' - } - - shadowJar { - archiveClassifier = 'lds' - - // Handling of service loader registrations via META-INF/services/* - mergeServiceFiles() - - // Merge properties - transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer) { - resource = 'plugin.properties' - } - - // Exclude files that are known to be dispensable for a language server - exclude( - '*._trace', - '*.ecore', - '*.ecorediag', - '*.g', - '*.genmodel', - '*.html', - '*.mwe2', - '*.profile', - '*.xtext', - '*readme.txt', - '.api_description', - '.options', - 'about.*', - 'about_*', - 'about_files/*', - 'ant_tasks/*', - 'cheatsheets/*', - 'com/*/*.java', - 'de/*/*.java', - 'docs/*', - 'log4j.properties', - 'META-INF/*.DSA', - 'META-INF/*.RSA', - 'META-INF/*.SF', - 'META-INF/changelog.txt', - 'META-INF/DEPENDENCIES', - 'META-INF/eclipse.inf', - 'META-INF/INDEX.LIST', - 'META-INF/maven/*', - 'META-INF/NOTICE', - 'META-INF/NOTICE.txt', - 'META-INF/p2.inf', - 'META-INF/versions/*/module-info.class', - 'modeling32.png', - 'module-info.class', - 'org/*/*.java', - 'OSGI-INF/l10n/bundle.properties', - 'plugin.xml', - 'profile.list', - 'schema/*', - 'systembundle.properties', - 'xtend-gen/*', - 'xtext32.png', - ) - - // Minimizing should be enabled with caution because some classes are only - // loaded via services (e.g. diagram syntheses and some xtext aspects) - // and would be removed when minimized - // minimize() { - // exclude(dependency('log4j:log4j:.*')) - // exclude(dependency('org.eclipse.xtext:.*ide:.*')) - // } - } } -generateLanguageDiagramServer.finalizedBy shadowJar \ No newline at end of file +compileJava.dependsOn(generateXtextLanguage) +compileKotlin.dependsOn(generateXtextLanguage) +processResources.dependsOn(generateXtextLanguage) +clean.dependsOn(cleanGenerateXtextLanguage) \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7f3458275f..94d44e8d96 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ -include 'org.lflang' -include 'org.lflang.tests' +rootProject.name = 'org.lflang' +include('org.lflang', 'lfc') + + From 27f7d55a378ab30f8b79ce3d4dd38235e5394532 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Wed, 24 May 2023 11:56:39 -0700 Subject: [PATCH 447/709] Moved Watchdog.lf into failing temporarily while we figure this out --- test/C/src/concurrent/{ => failing}/Watchdog.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/concurrent/{ => failing}/Watchdog.lf (100%) diff --git a/test/C/src/concurrent/Watchdog.lf b/test/C/src/concurrent/failing/Watchdog.lf similarity index 100% rename from test/C/src/concurrent/Watchdog.lf rename to test/C/src/concurrent/failing/Watchdog.lf From c2b9ce218621e13a94522bc6ec44498e64dea705 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 12:17:38 -0700 Subject: [PATCH 448/709] Skip tests for changes specific to other targets. --- .github/workflows/all-c.yml | 80 +++++++++++++++++++++++++++ .github/workflows/all-cpp.yml | 59 ++++++++++++++++++++ .github/workflows/all-py.yml | 47 ++++++++++++++++ .github/workflows/all-rs.yml | 54 ++++++++++++++++++ .github/workflows/all-ts.yml | 47 ++++++++++++++++ .github/workflows/{ci.yml => all.yml} | 8 +-- 6 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/all-c.yml create mode 100644 .github/workflows/all-cpp.yml create mode 100644 .github/workflows/all-py.yml create mode 100644 .github/workflows/all-rs.yml create mode 100644 .github/workflows/all-ts.yml rename .github/workflows/{ci.yml => all.yml} (95%) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml new file mode 100644 index 0000000000..03a2fe00b3 --- /dev/null +++ b/.github/workflows/all-c.yml @@ -0,0 +1,80 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + # Trigger this workflow on push events, but only on master. + push: + branches: + - master + # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + pull_request: + branches-ignore: + - 'nightly' + paths-ignore: + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/cpp/**' + - 'org.lflang/src/lib/py/**' + - 'org.lflang/src/lib/rs/**' + - 'org.lflang/src/lib/ts/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Cancel previous workflow runs. + cancel: + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + +# Check that automatic code formatting works. +# TODO: Uncomment after fed-gen is merged. +# format: +# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master +# needs: cancel + + # Run the unit tests. + unit-tests: + uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master + needs: cancel + + # Run the C benchmark tests. + c-benchmark-tests: + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'C' + needs: cancel + + # Run the C integration tests. + c-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + needs: cancel + + # Run the C Arduino integration tests. + c-arduino-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master + needs: cancel + + # Run the C Zephyr integration tests. + c-zephyr-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + needs: cancel + + # Run the CCpp integration tests. + ccpp-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + with: + use-cpp: true + needs: cancel + + # Run the Python integration tests. + py-tests: + uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master + needs: cancel + + # Run the serialization tests + serialization-tests: + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + needs: cancel diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml new file mode 100644 index 0000000000..cd3cfebe9c --- /dev/null +++ b/.github/workflows/all-cpp.yml @@ -0,0 +1,59 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + # Trigger this workflow on push events, but only on master. + push: + branches: + - master + # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + pull_request: + branches-ignore: + - 'nightly' + paths-ignore: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' + - 'org.lflang/src/lib/py/**' + - 'org.lflang/src/lib/rs/**' + - 'org.lflang/src/lib/ts/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Cancel previous workflow runs. + cancel: + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + +# Check that automatic code formatting works. +# TODO: Uncomment after fed-gen is merged. +# format: +# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master +# needs: cancel + + # Run the C++ benchmark tests. + cpp-benchmark-tests: + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'Cpp' + needs: cancel + + # Run the C++ integration tests. + cpp-tests: + uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml@master + needs: cancel + + # Run the C++ integration tests on ROS2. + cpp-ros2-tests: + uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml@master + needs: cancel + + # Run the serialization tests + serialization-tests: + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + needs: cancel diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml new file mode 100644 index 0000000000..5b6b8a29a0 --- /dev/null +++ b/.github/workflows/all-py.yml @@ -0,0 +1,47 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + # Trigger this workflow on push events, but only on master. + push: + branches: + - master + # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + pull_request: + branches-ignore: + - 'nightly' + paths-ignore: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' + - 'org.lflang/src/lib/cpp/**' + - 'org.lflang/src/lib/rs/**' + - 'org.lflang/src/lib/ts/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Cancel previous workflow runs. + cancel: + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + +# Check that automatic code formatting works. +# TODO: Uncomment after fed-gen is merged. +# format: +# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master +# needs: cancel + + # Run the Python integration tests. + py-tests: + uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master + needs: cancel + + # Run the serialization tests + serialization-tests: + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + needs: cancel diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml new file mode 100644 index 0000000000..3924a5d09f --- /dev/null +++ b/.github/workflows/all-rs.yml @@ -0,0 +1,54 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + # Trigger this workflow on push events, but only on master. + push: + branches: + - master + # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + pull_request: + branches-ignore: + - 'nightly' + paths-ignore: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' + - 'org.lflang/src/lib/cpp/**' + - 'org.lflang/src/lib/py/**' + - 'org.lflang/src/lib/ts/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Cancel previous workflow runs. + cancel: + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + +# Check that automatic code formatting works. +# TODO: Uncomment after fed-gen is merged. +# format: +# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master +# needs: cancel + + # Run the Rust integration tests. + rs-tests: + uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml@master + needs: cancel + + # Run the Rust benchmark tests. + rs-benchmark-tests: + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'Rust' + needs: cancel + + # Run the serialization tests + serialization-tests: + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + needs: cancel diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml new file mode 100644 index 0000000000..d29d5d5599 --- /dev/null +++ b/.github/workflows/all-ts.yml @@ -0,0 +1,47 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + # Trigger this workflow on push events, but only on master. + push: + branches: + - master + # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + pull_request: + branches-ignore: + - 'nightly' + paths-ignore: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' + - 'org.lflang/src/lib/cpp/**' + - 'org.lflang/src/lib/py/**' + - 'org.lflang/src/lib/rs/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Cancel previous workflow runs. + cancel: + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + +# Check that automatic code formatting works. +# TODO: Uncomment after fed-gen is merged. +# format: +# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master +# needs: cancel + + # Run the TypeScript integration tests. + ts-tests: + uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@master + needs: cancel + + # Run the serialization tests + serialization-tests: + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + needs: cancel diff --git a/.github/workflows/ci.yml b/.github/workflows/all.yml similarity index 95% rename from .github/workflows/ci.yml rename to .github/workflows/all.yml index dc9832cf35..1238a97bcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/all.yml @@ -6,10 +6,6 @@ on: push: branches: - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. - pull_request: - branches-ignore: - - 'nightly' env: # 2020.11 @@ -60,12 +56,12 @@ jobs: c-tests: uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master needs: cancel - + # Run the C Arduino integration tests. c-arduino-tests: uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master needs: cancel - + # Run the C Zephyr integration tests. c-zephyr-tests: uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master From 9de16d56917084f9ceed28cff7e7a6a36d30ab4f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 12:33:57 -0700 Subject: [PATCH 449/709] More aggressively reduce the amount of tests run. --- .github/workflows/all-c.yml | 13 ++-- .github/workflows/all-cpp.yml | 13 +--- .github/workflows/all-non-target-specific.yml | 65 +++++++++++++++++++ .github/workflows/all-py.yml | 13 +--- .github/workflows/all-rs.yml | 13 +--- .github/workflows/all-ts.yml | 13 +--- 6 files changed, 81 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/all-non-target-specific.yml diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index 03a2fe00b3..9541214f8e 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -10,15 +10,10 @@ on: pull_request: branches-ignore: - 'nightly' - paths-ignore: - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/cpp/**' - - 'org.lflang/src/lib/py/**' - - 'org.lflang/src/lib/rs/**' - - 'org.lflang/src/lib/ts/**' + paths: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' env: # 2020.11 diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index cd3cfebe9c..2df8b7eab6 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -10,16 +10,9 @@ on: pull_request: branches-ignore: - 'nightly' - paths-ignore: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' - - 'org.lflang/src/lib/py/**' - - 'org.lflang/src/lib/rs/**' - - 'org.lflang/src/lib/ts/**' + paths: + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/lib/cpp/**' env: # 2020.11 diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml new file mode 100644 index 0000000000..17938b20db --- /dev/null +++ b/.github/workflows/all-non-target-specific.yml @@ -0,0 +1,65 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + # Trigger this workflow on push events, but only on master. + push: + branches: + - master + paths-ignore: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' + - 'org.lflang/src/lib/cpp/**' + - 'org.lflang/src/lib/py/**' + - 'org.lflang/src/lib/rs/**' + - 'org.lflang/src/lib/ts/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Cancel previous workflow runs. + cancel: + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + + # Test the Gradle build. + build: + uses: lf-lang/lingua-franca/.github/workflows/build.yml@master + needs: cancel + + # Build the tools used for processing execution traces + build-tracing-tools: + uses: lf-lang/lingua-franca/.github/workflows/build-trace-tools.yml@master + needs: cancel + +# Check that automatic code formatting works. +# TODO: Uncomment after fed-gen is merged. +# format: +# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master +# needs: cancel + + # Run the unit tests. + unit-tests: + uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master + needs: cancel + + # Run tests for the standalone compiler. + cli-tests: + uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@master + needs: cancel + + # Run language server tests. + lsp-tests: + uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@master + needs: cancel + + # Run the serialization tests + serialization-tests: + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + needs: cancel diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 5b6b8a29a0..22dade8922 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -10,16 +10,9 @@ on: pull_request: branches-ignore: - 'nightly' - paths-ignore: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' - - 'org.lflang/src/lib/cpp/**' - - 'org.lflang/src/lib/rs/**' - - 'org.lflang/src/lib/ts/**' + paths: + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/lib/py/**' env: # 2020.11 diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 3924a5d09f..12df37e060 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -10,16 +10,9 @@ on: pull_request: branches-ignore: - 'nightly' - paths-ignore: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' - - 'org.lflang/src/lib/cpp/**' - - 'org.lflang/src/lib/py/**' - - 'org.lflang/src/lib/ts/**' + paths: + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/lib/rs/**' env: # 2020.11 diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index d29d5d5599..1875fc8e76 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -10,16 +10,9 @@ on: pull_request: branches-ignore: - 'nightly' - paths-ignore: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' - - 'org.lflang/src/lib/cpp/**' - - 'org.lflang/src/lib/py/**' - - 'org.lflang/src/lib/rs/**' + paths: + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/ts/**' env: # 2020.11 From 3510231faca219a7d959151bf0cae2db2180b604 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 12:41:00 -0700 Subject: [PATCH 450/709] Update names. --- .github/workflows/all-c.yml | 2 +- .github/workflows/all-cpp.yml | 2 +- .github/workflows/all-non-target-specific.yml | 4 +++- .github/workflows/all-py.yml | 2 +- .github/workflows/all-rs.yml | 2 +- .github/workflows/all-ts.yml | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index 9541214f8e..7e44da4bc4 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -1,5 +1,5 @@ # Main workflow for testing the Lingua Franca compiler. -name: CI +name: C on: # Trigger this workflow on push events, but only on master. diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index 2df8b7eab6..479ffd61d7 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -1,5 +1,5 @@ # Main workflow for testing the Lingua Franca compiler. -name: CI +name: Cpp on: # Trigger this workflow on push events, but only on master. diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 17938b20db..be0e01e3c1 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,11 +1,13 @@ # Main workflow for testing the Lingua Franca compiler. -name: CI +name: Non-target-specific on: # Trigger this workflow on push events, but only on master. push: branches: - master + # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + pull_request: paths-ignore: - 'org.lflang/src/org/lflang/generator/c/**' - 'org.lflang/src/org/lflang/generator/cpp/**' diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 22dade8922..5b329f96a1 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -1,5 +1,5 @@ # Main workflow for testing the Lingua Franca compiler. -name: CI +name: Python on: # Trigger this workflow on push events, but only on master. diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 12df37e060..6b833efcd5 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -1,5 +1,5 @@ # Main workflow for testing the Lingua Franca compiler. -name: CI +name: Rust on: # Trigger this workflow on push events, but only on master. diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index 1875fc8e76..7affdf1f64 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -1,5 +1,5 @@ # Main workflow for testing the Lingua Franca compiler. -name: CI +name: TypeScript on: # Trigger this workflow on push events, but only on master. From e721efa96a06e4cb194a67716f5003db86464729 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 22 May 2023 14:01:12 -0700 Subject: [PATCH 451/709] Add manual trigger. --- .github/workflows/all-c.yml | 5 +++-- .github/workflows/all-cpp.yml | 1 + .github/workflows/all-non-target-specific.yml | 1 + .github/workflows/all-py.yml | 1 + .github/workflows/all-rs.yml | 1 + .github/workflows/all-ts.yml | 1 + .github/workflows/all.yml | 1 + 7 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index 7e44da4bc4..f5f00cad55 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -2,14 +2,15 @@ name: C on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: - - master + - master # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. pull_request: branches-ignore: - - 'nightly' + - 'nightly' paths: - 'org.lflang/src/org/lflang/generator/c/**' - 'org.lflang/src/lib/c/**' diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index 479ffd61d7..e21492722d 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -2,6 +2,7 @@ name: Cpp on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index be0e01e3c1..d3a0ced5da 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -2,6 +2,7 @@ name: Non-target-specific on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 5b329f96a1..82a6f089c6 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -2,6 +2,7 @@ name: Python on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 6b833efcd5..13393cb2aa 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -2,6 +2,7 @@ name: Rust on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index 7affdf1f64..f14b1cfc0a 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -2,6 +2,7 @@ name: TypeScript on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 1238a97bcd..134ea4798f 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -2,6 +2,7 @@ name: CI on: + workflow_dispatch: # Allow the workflow to be triggered manually. # Trigger this workflow on push events, but only on master. push: branches: From 3dae6487343b4531c77d189d51e02cd255148e6c Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 11:03:01 -0700 Subject: [PATCH 452/709] Remove redundant push trigger. --- .github/workflows/all-c.yml | 7 +------ .github/workflows/all-cpp.yml | 7 +------ .github/workflows/all-non-target-specific.yml | 7 +------ .github/workflows/all-py.yml | 7 +------ .github/workflows/all-rs.yml | 7 +------ .github/workflows/all-ts.yml | 7 +------ .github/workflows/all.yml | 3 +-- 7 files changed, 7 insertions(+), 38 deletions(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index f5f00cad55..5a5d24e931 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -2,12 +2,7 @@ name: C on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. - push: - branches: - - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + workflow_dispatch: pull_request: branches-ignore: - 'nightly' diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index e21492722d..5c1906bc31 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -2,12 +2,7 @@ name: Cpp on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. - push: - branches: - - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + workflow_dispatch: pull_request: branches-ignore: - 'nightly' diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index d3a0ced5da..871b610446 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -2,12 +2,7 @@ name: Non-target-specific on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. - push: - branches: - - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + workflow_dispatch: pull_request: paths-ignore: - 'org.lflang/src/org/lflang/generator/c/**' diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 82a6f089c6..327a8a07b3 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -2,12 +2,7 @@ name: Python on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. - push: - branches: - - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + workflow_dispatch: pull_request: branches-ignore: - 'nightly' diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 13393cb2aa..d4a9a46966 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -2,12 +2,7 @@ name: Rust on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. - push: - branches: - - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + workflow_dispatch: pull_request: branches-ignore: - 'nightly' diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index f14b1cfc0a..56174b1079 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -2,12 +2,7 @@ name: TypeScript on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. - push: - branches: - - master - # Trigger this workflow also on pull_request events, but ignore the 'nightly' branch. + workflow_dispatch: pull_request: branches-ignore: - 'nightly' diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 134ea4798f..cf393ebaac 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -2,8 +2,7 @@ name: CI on: - workflow_dispatch: # Allow the workflow to be triggered manually. - # Trigger this workflow on push events, but only on master. + workflow_dispatch: push: branches: - master From 7e469a9c2f62fe939517322689bf25c9759e00d5 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 11:24:04 -0700 Subject: [PATCH 453/709] Remove incorrect comments. --- .github/workflows/all-c.yml | 1 - .github/workflows/all-cpp.yml | 1 - .github/workflows/all-non-target-specific.yml | 1 - .github/workflows/all-py.yml | 1 - .github/workflows/all-rs.yml | 1 - .github/workflows/all-ts.yml | 1 - 6 files changed, 6 deletions(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index 5a5d24e931..f0fdaa328e 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -1,4 +1,3 @@ -# Main workflow for testing the Lingua Franca compiler. name: C on: diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index 5c1906bc31..2138765523 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -1,4 +1,3 @@ -# Main workflow for testing the Lingua Franca compiler. name: Cpp on: diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 871b610446..a417009a4a 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,4 +1,3 @@ -# Main workflow for testing the Lingua Franca compiler. name: Non-target-specific on: diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 327a8a07b3..87a8a150af 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -1,4 +1,3 @@ -# Main workflow for testing the Lingua Franca compiler. name: Python on: diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index d4a9a46966..06e52499c8 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -1,4 +1,3 @@ -# Main workflow for testing the Lingua Franca compiler. name: Rust on: diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index 56174b1079..f00935b93c 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -1,4 +1,3 @@ -# Main workflow for testing the Lingua Franca compiler. name: TypeScript on: From 4f5fa0f6f6ecce156330ba34f5efa522aef20709 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 18:05:47 -0700 Subject: [PATCH 454/709] Factor out of all-c.yml. --- .github/workflows/all-c.yml | 39 ++++++--------------------------- .github/workflows/only-c.yml | 40 ++++++++++++++++++++++++++++++++++ .github/workflows/only-cpp.yml | 0 .github/workflows/only-py.yml | 0 .github/workflows/only-rs.yml | 0 .github/workflows/only-ts.yml | 0 6 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/only-c.yml create mode 100644 .github/workflows/only-cpp.yml create mode 100644 .github/workflows/only-py.yml create mode 100644 .github/workflows/only-rs.yml create mode 100644 .github/workflows/only-ts.yml diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index f0fdaa328e..02a30e0753 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -9,6 +9,7 @@ on: - 'org.lflang/src/org/lflang/generator/c/**' - 'org.lflang/src/lib/c/**' - 'org.lflang/src/lib/platform/**' + - '**' # Delete me env: # 2020.11 @@ -17,7 +18,7 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml # Check that automatic code formatting works. # TODO: Uncomment after fed-gen is merged. @@ -27,44 +28,18 @@ jobs: # Run the unit tests. unit-tests: - uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml needs: cancel - # Run the C benchmark tests. - c-benchmark-tests: - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'C' - needs: cancel - - # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master - needs: cancel - - # Run the C Arduino integration tests. - c-arduino-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master - needs: cancel - - # Run the C Zephyr integration tests. - c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master - needs: cancel - - # Run the CCpp integration tests. - ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master - with: - use-cpp: true - needs: cancel + uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master - needs: cancel + uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml + needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml new file mode 100644 index 0000000000..9073b51d7b --- /dev/null +++ b/.github/workflows/only-c.yml @@ -0,0 +1,40 @@ +name: C + +on: + workflow_dispatch: + pull_request: + branches-ignore: + - 'nightly' + paths: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Run the C benchmark tests. + c-benchmark-tests: + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'C' + + # Run the C integration tests. + c-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + + # Run the C Arduino integration tests. + c-arduino-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master + + # Run the C Zephyr integration tests. + c-zephyr-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + + # Run the CCpp integration tests. + ccpp-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + with: + use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml new file mode 100644 index 0000000000..e69de29bb2 From b180129c5828f395e7ca67dc63fab8aef04edaeb Mon Sep 17 00:00:00 2001 From: Peter Donovan <33707478+petervdonovan@users.noreply.github.com> Date: Tue, 23 May 2023 18:07:50 -0700 Subject: [PATCH 455/709] Apply suggestions from code review Co-authored-by: Marten Lohstroh --- .github/workflows/all-c.yml | 2 +- .github/workflows/all-cpp.yml | 2 +- .github/workflows/all-non-target-specific.yml | 2 +- .github/workflows/all-py.yml | 2 +- .github/workflows/all-rs.yml | 2 +- .github/workflows/all-ts.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index 02a30e0753..35f68165bd 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -1,4 +1,4 @@ -name: C +name: C-based tests on: workflow_dispatch: diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index 2138765523..0c960a0b48 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -1,4 +1,4 @@ -name: Cpp +name: Cpp-based tests on: workflow_dispatch: diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index a417009a4a..43293b40eb 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,4 +1,4 @@ -name: Non-target-specific +name: Non-target-specific tests on: workflow_dispatch: diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 87a8a150af..ae216866a9 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -1,4 +1,4 @@ -name: Python +name: Python-based tests on: workflow_dispatch: diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 06e52499c8..ab4eb747f1 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -1,4 +1,4 @@ -name: Rust +name: Rust-based tests on: workflow_dispatch: diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index f00935b93c..ccdcd48469 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -1,4 +1,4 @@ -name: TypeScript +name: TypeScript-based tests on: workflow_dispatch: From 7ddbe6c33d65c3196e11889164293418d461cb5d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 18:30:44 -0700 Subject: [PATCH 456/709] Reduce duplication. --- .github/workflows/all-c.yml | 9 ++----- .github/workflows/all-cpp.yml | 25 +++---------------- .github/workflows/all-non-target-specific.yml | 6 ----- .github/workflows/all-py.yml | 13 +++------- .github/workflows/all-rs.yml | 20 +++------------ .github/workflows/all-ts.yml | 13 +++------- .github/workflows/only-c.yml | 15 +++-------- .github/workflows/only-cpp.yml | 23 +++++++++++++++++ .github/workflows/only-py.yml | 13 ++++++++++ .github/workflows/only-rs.yml | 19 ++++++++++++++ .github/workflows/only-ts.yml | 13 ++++++++++ 11 files changed, 86 insertions(+), 83 deletions(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index 35f68165bd..e84b209438 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -20,19 +20,14 @@ jobs: cancel: uses: lf-lang/lingua-franca/.github/workflows/cancel.yml -# Check that automatic code formatting works. -# TODO: Uncomment after fed-gen is merged. -# format: -# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master -# needs: cancel - # Run the unit tests. unit-tests: uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml needs: cancel c-tests: - uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml + uses: lf-lang/lingua-franca/.github/workflows/only-c.yml + needs: cancel # Run the Python integration tests. py-tests: diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index 0c960a0b48..cf9f37572b 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -16,32 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml -# Check that automatic code formatting works. -# TODO: Uncomment after fed-gen is merged. -# format: -# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master -# needs: cancel - - # Run the C++ benchmark tests. - cpp-benchmark-tests: - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'Cpp' - needs: cancel - - # Run the C++ integration tests. cpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml@master - needs: cancel - - # Run the C++ integration tests on ROS2. - cpp-ros2-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/only-cpp.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 43293b40eb..faa6c04b49 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -35,12 +35,6 @@ jobs: uses: lf-lang/lingua-franca/.github/workflows/build-trace-tools.yml@master needs: cancel -# Check that automatic code formatting works. -# TODO: Uncomment after fed-gen is merged. -# format: -# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master -# needs: cancel - # Run the unit tests. unit-tests: uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index ae216866a9..ab0de0d3ea 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -16,20 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml -# Check that automatic code formatting works. -# TODO: Uncomment after fed-gen is merged. -# format: -# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master -# needs: cancel - - # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/only-py.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index ab4eb747f1..80ee654996 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -16,27 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml -# Check that automatic code formatting works. -# TODO: Uncomment after fed-gen is merged. -# format: -# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master -# needs: cancel - - # Run the Rust integration tests. rs-tests: - uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml@master - needs: cancel - - # Run the Rust benchmark tests. - rs-benchmark-tests: - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'Rust' + uses: lf-lang/lingua-franca/.github/workflows/only-rs.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index ccdcd48469..1c0faf75af 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -16,20 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cancel.yml -# Check that automatic code formatting works. -# TODO: Uncomment after fed-gen is merged. -# format: -# uses: lf-lang/lingua-franca/.github/workflows/format.yml@master -# needs: cancel - - # Run the TypeScript integration tests. ts-tests: - uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/only-ts.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 9073b51d7b..a48561a463 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -2,13 +2,6 @@ name: C on: workflow_dispatch: - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' env: # 2020.11 @@ -23,18 +16,18 @@ jobs: # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml # Run the C Arduino integration tests. c-arduino-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml # Run the C Zephyr integration tests. c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml with: use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index e69de29bb2..ef0fa0de32 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -0,0 +1,23 @@ +name: C++ + +on: + workflow_dispatch: + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Run the C++ benchmark tests. + cpp-benchmark-tests: + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'Cpp' + + # Run the C++ integration tests. + cpp-tests: + uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml + + # Run the C++ integration tests on ROS2. + cpp-ros2-tests: + uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index e69de29bb2..e03d967278 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -0,0 +1,13 @@ +name: Python + +on: + workflow_dispatch: + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Run the Python integration tests. + py-tests: + uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index e69de29bb2..abd885ba49 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -0,0 +1,19 @@ +name: Rust + +on: + workflow_dispatch: + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Run the Rust integration tests. + rs-tests: + uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml + + # Run the Rust benchmark tests. + rs-benchmark-tests: + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'Rust' diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index e69de29bb2..2a9b93140a 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -0,0 +1,13 @@ +name: Rust + +on: + workflow_dispatch: + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + # Run the TypeScript integration tests. + ts-tests: + uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml From 366599e09cc632fc90354f96a0d43a2d6eb1ad2a Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 18:52:42 -0700 Subject: [PATCH 457/709] Try again to make workflow files valid. --- .github/actions/build-rti-docker/action.yml | 4 +-- .github/actions/install-rti/action.yml | 3 +- .github/actions/setup-zephyr/action.yml | 4 +-- .github/workflows/all-c.yml | 10 +++--- .github/workflows/all-cpp.yml | 8 ++--- .github/workflows/all-non-target-specific.yml | 14 ++++---- .github/workflows/all-py.yml | 6 ++-- .github/workflows/all-rs.yml | 6 ++-- .github/workflows/all-ts.yml | 6 ++-- .github/workflows/all.yml | 34 +++++++++---------- .github/workflows/cancel.yml | 2 +- .github/workflows/nightly-build.yml | 2 +- .github/workflows/only-c.yml | 9 ++--- .github/workflows/only-cpp.yml | 5 +-- .github/workflows/only-py.yml | 3 +- .github/workflows/only-rs.yml | 3 +- .github/workflows/only-ts.yml | 3 +- build.gradle | 2 +- org.lflang/src/lib/c/reactor-c | 2 +- 19 files changed, 65 insertions(+), 61 deletions(-) diff --git a/.github/actions/build-rti-docker/action.yml b/.github/actions/build-rti-docker/action.yml index a44afd8375..643f726181 100644 --- a/.github/actions/build-rti-docker/action.yml +++ b/.github/actions/build-rti-docker/action.yml @@ -2,6 +2,6 @@ name: Build RTI docker image description: Build and install runs: using: "composite" - steps: + steps: - run: .github/actions/build-rti-docker/build-rti-image.sh - shell: bash \ No newline at end of file + shell: bash diff --git a/.github/actions/install-rti/action.yml b/.github/actions/install-rti/action.yml index 65b55b8e3b..895daf26b6 100644 --- a/.github/actions/install-rti/action.yml +++ b/.github/actions/install-rti/action.yml @@ -2,7 +2,6 @@ name: Install RTI description: Build and install runs: using: "composite" - steps: + steps: - run: .github/actions/install-rti/install.sh shell: bash - \ No newline at end of file diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 7d835049dc..e77ac6c0e4 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -4,7 +4,7 @@ runs: using: "composite" steps: - name: Dependencies - run: | + run: | sudo apt-get update && sudo apt-get upgrade sudo apt-get install -y --no-install-recommends git cmake ninja-build gperf \ ccache dfu-util device-tree-compiler wget \ @@ -32,4 +32,4 @@ runs: pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-0.15.2/" >> $GITHUB_ENV - shell: bash \ No newline at end of file + shell: bash diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index e84b209438..b946cfe66e 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -18,23 +18,23 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml + uses: ./.github/workflows/cancel.yml # Run the unit tests. unit-tests: - uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml + uses: ./.github/workflows/unit-tests.yml needs: cancel c-tests: - uses: lf-lang/lingua-franca/.github/workflows/only-c.yml + uses: ./.github/workflows/only-c.yml needs: cancel # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml + uses: ./.github/workflows/py-tests.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index cf9f37572b..f1bc279024 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -1,4 +1,4 @@ -name: Cpp-based tests +name: Cpp-based tests on: workflow_dispatch: @@ -16,13 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml + uses: ./.github/workflows/cancel.yml cpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/only-cpp.yml + uses: ./.github/workflows/only-cpp.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index faa6c04b49..49bd93dfcc 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -23,34 +23,34 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: ./.github/workflows/cancel.yml # Test the Gradle build. build: - uses: lf-lang/lingua-franca/.github/workflows/build.yml@master + uses: ./.github/workflows/build.yml needs: cancel # Build the tools used for processing execution traces build-tracing-tools: - uses: lf-lang/lingua-franca/.github/workflows/build-trace-tools.yml@master + uses: ./.github/workflows/build-trace-tools.yml needs: cancel # Run the unit tests. unit-tests: - uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master + uses: ./.github/workflows/unit-tests.yml needs: cancel # Run tests for the standalone compiler. cli-tests: - uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@master + uses: ./.github/workflows/cli-tests.yml needs: cancel # Run language server tests. lsp-tests: - uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@master + uses: ./.github/workflows/lsp-tests.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index ab0de0d3ea..539040f8a5 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -16,13 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml + uses: ./.github/workflows/cancel.yml py-tests: - uses: lf-lang/lingua-franca/.github/workflows/only-py.yml + uses: ./.github/workflows/only-py.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 80ee654996..80c10912ce 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -16,13 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml + uses: ./.github/workflows/cancel.yml rs-tests: - uses: lf-lang/lingua-franca/.github/workflows/only-rs.yml + uses: ./.github/workflows/only-rs.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index 1c0faf75af..3687187a83 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -16,13 +16,13 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml + uses: ./.github/workflows/cancel.yml ts-tests: - uses: lf-lang/lingua-franca/.github/workflows/only-ts.yml + uses: ./.github/workflows/only-ts.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index cf393ebaac..3ca846d2ad 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -14,30 +14,30 @@ env: jobs: # Cancel previous workflow runs. cancel: - uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master + uses: ./.github/workflows/cancel.yml # Test the Gradle build. build: - uses: lf-lang/lingua-franca/.github/workflows/build.yml@master + uses: ./.github/workflows/build.yml needs: cancel # Build the tools used for processing execution traces build-tracing-tools: - uses: lf-lang/lingua-franca/.github/workflows/build-trace-tools.yml@master + uses: ./.github/workflows/build-trace-tools.yml needs: cancel check-format: - uses: lf-lang/lingua-franca/.github/workflows/check-format.yml@master + uses: ./.github/workflows/check-format.yml needs: cancel # Run the unit tests. unit-tests: - uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master + uses: ./.github/workflows/unit-tests.yml needs: cancel # Run tests for the standalone compiler. cli-tests: - uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@master + uses: ./.github/workflows/cli-tests.yml needs: cancel # Run the C benchmark tests. @@ -49,27 +49,27 @@ jobs: # Run language server tests. lsp-tests: - uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@master + uses: ./.github/workflows/lsp-tests.yml needs: cancel # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: ./.github/workflows/c-tests.yml needs: cancel # Run the C Arduino integration tests. c-arduino-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master + uses: ./.github/workflows/c-arduino-tests.yml needs: cancel # Run the C Zephyr integration tests. c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + uses: ./.github/workflows/c-zephyr-tests.yml needs: cancel # Run the CCpp integration tests. ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: ./.github/workflows/c-tests.yml with: use-cpp: true needs: cancel @@ -83,22 +83,22 @@ jobs: # Run the C++ integration tests. cpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml@master + uses: ./.github/workflows/cpp-tests.yml needs: cancel # Run the C++ integration tests on ROS2. cpp-ros2-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml@master + uses: ./.github/workflows/cpp-ros2-tests.yml needs: cancel # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master + uses: ./.github/workflows/py-tests.yml needs: cancel # Run the Rust integration tests. rs-tests: - uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml@master + uses: ./.github/workflows/rs-tests.yml needs: cancel # Run the Rust benchmark tests. @@ -110,10 +110,10 @@ jobs: # Run the TypeScript integration tests. ts-tests: - uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@master + uses: ./.github/workflows/ts-tests.yml needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: ./.github/workflows/serialization-tests.yml needs: cancel diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml index 00733bb5b8..49765257c9 100644 --- a/.github/workflows/cancel.yml +++ b/.github/workflows/cancel.yml @@ -2,7 +2,7 @@ name: Cancel previous jobs on: workflow_call: - + jobs: cancel: name: run diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index d79d88be82..9ffb82c581 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -8,7 +8,7 @@ on: jobs: build: - uses: lf-lang/lingua-franca/.github/workflows/build.yml@master + uses: ./.github/workflows/build.yml with: nightly: true secrets: diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index a48561a463..f360a8525e 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -2,6 +2,7 @@ name: C on: workflow_dispatch: + workflow_call: env: # 2020.11 @@ -16,18 +17,18 @@ jobs: # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml + uses: ./.github/workflows/c-tests.yml # Run the C Arduino integration tests. c-arduino-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml + uses: ./.github/workflows/c-arduino-tests.yml # Run the C Zephyr integration tests. c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml + uses: ./.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml + uses: ./.github/workflows/c-tests.yml with: use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index ef0fa0de32..ecedfd52b8 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -2,6 +2,7 @@ name: C++ on: workflow_dispatch: + workflow_call: env: # 2020.11 @@ -16,8 +17,8 @@ jobs: # Run the C++ integration tests. cpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml + uses: ./.github/workflows/cpp-tests.yml # Run the C++ integration tests on ROS2. cpp-ros2-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml + uses: ./.github/workflows/cpp-ros2-tests.yml diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index e03d967278..b595502b21 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -2,6 +2,7 @@ name: Python on: workflow_dispatch: + workflow_call: env: # 2020.11 @@ -10,4 +11,4 @@ env: jobs: # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml + uses: ./.github/workflows/py-tests.yml diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index abd885ba49..dc5fce56ba 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -2,6 +2,7 @@ name: Rust on: workflow_dispatch: + workflow_call: env: # 2020.11 @@ -10,7 +11,7 @@ env: jobs: # Run the Rust integration tests. rs-tests: - uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml + uses: ./.github/workflows/rs-tests.yml # Run the Rust benchmark tests. rs-benchmark-tests: diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 2a9b93140a..4f2b176d1f 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -2,6 +2,7 @@ name: Rust on: workflow_dispatch: + workflow_call: env: # 2020.11 @@ -10,4 +11,4 @@ env: jobs: # Run the TypeScript integration tests. ts-tests: - uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml + uses: ./.github/workflows/ts-tests.yml diff --git a/build.gradle b/build.gradle index 563377e3d3..f1ddbf9b96 100644 --- a/build.gradle +++ b/build.gradle @@ -92,7 +92,7 @@ spotless { format 'misc', { // define the files to apply `misc` to - target '*.gradle', '*.md', '.gitignore' + target '*.gradle', '*.md', '.gitignore', '**/*.yml' // define the steps to apply to those files trimTrailingWhitespace() diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 880fb34310..83b1cef7fd 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 880fb343109d150cd853208c368641863050df4f +Subproject commit 83b1cef7fd4209b3e25b6a310ce8f964277d9692 From 0b157b05bee8bd033a6a5067d4d4526f7c687002 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 19:22:54 -0700 Subject: [PATCH 458/709] Reuse the other workflows in all.yml. --- .github/workflows/all-non-target-specific.yml | 1 + .github/workflows/all.yml | 94 +++---------------- 2 files changed, 14 insertions(+), 81 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 49bd93dfcc..ff9ae06b13 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -2,6 +2,7 @@ name: Non-target-specific tests on: workflow_dispatch: + workflow_call: pull_request: paths-ignore: - 'org.lflang/src/org/lflang/generator/c/**' diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 3ca846d2ad..10042c135a 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -16,104 +16,36 @@ jobs: cancel: uses: ./.github/workflows/cancel.yml - # Test the Gradle build. - build: - uses: ./.github/workflows/build.yml - needs: cancel - - # Build the tools used for processing execution traces - build-tracing-tools: - uses: ./.github/workflows/build-trace-tools.yml - needs: cancel - check-format: uses: ./.github/workflows/check-format.yml needs: cancel - # Run the unit tests. - unit-tests: - uses: ./.github/workflows/unit-tests.yml - needs: cancel - - # Run tests for the standalone compiler. - cli-tests: - uses: ./.github/workflows/cli-tests.yml + # Run the non-target-specific tests. + non-target-specific: + uses: ./.github/workflows/all-non-target-specific.yml needs: cancel - # Run the C benchmark tests. - c-benchmark-tests: - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'C' - needs: cancel - - # Run language server tests. - lsp-tests: - uses: ./.github/workflows/lsp-tests.yml - needs: cancel - - # Run the C integration tests. + # Run the C tests. c-tests: - uses: ./.github/workflows/c-tests.yml - needs: cancel - - # Run the C Arduino integration tests. - c-arduino-tests: - uses: ./.github/workflows/c-arduino-tests.yml + uses: ./.github/workflows/only-c.yml needs: cancel - # Run the C Zephyr integration tests. - c-zephyr-tests: - uses: ./.github/workflows/c-zephyr-tests.yml - needs: cancel - - # Run the CCpp integration tests. - ccpp-tests: - uses: ./.github/workflows/c-tests.yml - with: - use-cpp: true - needs: cancel - - # Run the C++ benchmark tests. - cpp-benchmark-tests: - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'Cpp' - needs: cancel - - # Run the C++ integration tests. + # Run the C++ tests. cpp-tests: - uses: ./.github/workflows/cpp-tests.yml + uses: ./.github/workflows/only-cpp.yml needs: cancel - # Run the C++ integration tests on ROS2. - cpp-ros2-tests: - uses: ./.github/workflows/cpp-ros2-tests.yml - needs: cancel - - # Run the Python integration tests. + # Run the Python tests. py-tests: - uses: ./.github/workflows/py-tests.yml + uses: ./.github/workflows/only-py.yml needs: cancel - # Run the Rust integration tests. + # Run the Rust tests. rs-tests: - uses: ./.github/workflows/rs-tests.yml - needs: cancel - - # Run the Rust benchmark tests. - rs-benchmark-tests: - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'Rust' + uses: ./.github/workflows/only-rs.yml needs: cancel - # Run the TypeScript integration tests. + # Run the TypeScript tests. ts-tests: - uses: ./.github/workflows/ts-tests.yml - needs: cancel - - # Run the serialization tests - serialization-tests: - uses: ./.github/workflows/serialization-tests.yml + uses: ./.github/workflows/only-ts.yml needs: cancel From ce0d66cf82513d15e8f9f02a935b90508c928773 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 21:16:50 -0700 Subject: [PATCH 459/709] Remove tests from non-target-specific. These tests are already in the target-specific tests. --- .github/workflows/all-non-target-specific.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index ff9ae06b13..e11cc82cf5 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -36,11 +36,6 @@ jobs: uses: ./.github/workflows/build-trace-tools.yml needs: cancel - # Run the unit tests. - unit-tests: - uses: ./.github/workflows/unit-tests.yml - needs: cancel - # Run tests for the standalone compiler. cli-tests: uses: ./.github/workflows/cli-tests.yml @@ -50,8 +45,3 @@ jobs: lsp-tests: uses: ./.github/workflows/lsp-tests.yml needs: cancel - - # Run the serialization tests - serialization-tests: - uses: ./.github/workflows/serialization-tests.yml - needs: cancel From ac2bf54c2fb383fd6e6d64b0d713cf854f5240be Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 23 May 2023 22:25:47 -0700 Subject: [PATCH 460/709] Do not run multiple instances of same job at once. Multiple instances on different refs can run at once, but on on the same ref. --- .github/workflows/all-c.yml | 5 ++++- .github/workflows/all-cpp.yml | 4 ++++ .github/workflows/all-non-target-specific.yml | 4 ++++ .github/workflows/all-py.yml | 4 ++++ .github/workflows/all-rs.yml | 4 ++++ .github/workflows/all-ts.yml | 4 ++++ .github/workflows/build-trace-tools.yml | 4 ++++ .github/workflows/build.yml | 4 ++++ .github/workflows/c-arduino-tests.yml | 4 ++++ .github/workflows/c-tests.yml | 4 ++++ .github/workflows/c-zephyr-tests.yml | 4 ++++ .github/workflows/check-format.yml | 4 ++++ .github/workflows/cli-tests.yml | 4 ++++ .github/workflows/cpp-ros2-tests.yml | 5 +++++ .github/workflows/cpp-tests.yml | 5 +++++ .github/workflows/lsp-tests.yml | 4 ++++ .github/workflows/nightly-build.yml | 4 ++++ .github/workflows/only-c.yml | 4 ++++ .github/workflows/only-cpp.yml | 4 ++++ .github/workflows/only-py.yml | 4 ++++ .github/workflows/only-rs.yml | 4 ++++ .github/workflows/only-ts.yml | 4 ++++ .github/workflows/py-tests.yml | 4 ++++ .github/workflows/rs-tests.yml | 4 ++++ .github/workflows/serialization-tests.yml | 4 ++++ .github/workflows/ts-tests.yml | 4 ++++ .github/workflows/unit-tests.yml | 4 ++++ 27 files changed, 110 insertions(+), 1 deletion(-) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml index b946cfe66e..7249009852 100644 --- a/.github/workflows/all-c.yml +++ b/.github/workflows/all-c.yml @@ -9,7 +9,10 @@ on: - 'org.lflang/src/org/lflang/generator/c/**' - 'org.lflang/src/lib/c/**' - 'org.lflang/src/lib/platform/**' - - '**' # Delete me + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} env: # 2020.11 diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml index f1bc279024..c9b207d72e 100644 --- a/.github/workflows/all-cpp.yml +++ b/.github/workflows/all-cpp.yml @@ -9,6 +9,10 @@ on: - 'org.lflang/src/org/lflang/generator/cpp/**' - 'org.lflang/src/lib/cpp/**' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index e11cc82cf5..db05bd982f 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -17,6 +17,10 @@ on: - 'org.lflang/src/lib/rs/**' - 'org.lflang/src/lib/ts/**' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml index 539040f8a5..40b9250a7a 100644 --- a/.github/workflows/all-py.yml +++ b/.github/workflows/all-py.yml @@ -9,6 +9,10 @@ on: - 'org.lflang/src/org/lflang/generator/python/**' - 'org.lflang/src/lib/py/**' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/all-rs.yml b/.github/workflows/all-rs.yml index 80c10912ce..3328c27d72 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/all-rs.yml @@ -9,6 +9,10 @@ on: - 'org.lflang/src/org/lflang/generator/rust/**' - 'org.lflang/src/lib/rs/**' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml index 3687187a83..1e4e9edbd7 100644 --- a/.github/workflows/all-ts.yml +++ b/.github/workflows/all-ts.yml @@ -9,6 +9,10 @@ on: - 'org.lflang/src/org/lflang/generator/ts/**' - 'org.lflang/src/lib/ts/**' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/build-trace-tools.yml b/.github/workflows/build-trace-tools.yml index 2490e9b75e..bd69f7be68 100644 --- a/.github/workflows/build-trace-tools.yml +++ b/.github/workflows/build-trace-tools.yml @@ -3,6 +3,10 @@ name: Build the tools for processing execution traces on: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 767df01fa1..2417cece56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,10 @@ on: required: false workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 167e8f6f1c..8c77d6e52d 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -17,6 +17,10 @@ on: required: false type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 0764128a1b..c29b3c0a61 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -17,6 +17,10 @@ on: required: false type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 3b7a76feee..49f204bb44 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -17,6 +17,10 @@ on: required: false type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index 8c022f90a5..8fc44a98df 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -3,6 +3,10 @@ name: Spotless check on: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 056e32c04c..3d23f0bd9f 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -3,6 +3,10 @@ name: CLI tests on: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index bfb3e12cb8..c81ca59f02 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -9,6 +9,11 @@ on: runtime-ref: required: false type: string + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 3fe74ae393..e3f957ab2d 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -9,6 +9,11 @@ on: runtime-ref: required: false type: string + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index bf32254b0f..7418bde69d 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -3,6 +3,10 @@ name: Language server tests on: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 9ffb82c581..469e9dc600 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -6,6 +6,10 @@ on: - cron: '0 5 * * *' workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: build: uses: ./.github/workflows/build.yml diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index f360a8525e..530e3e2aca 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -4,6 +4,10 @@ on: workflow_dispatch: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index ecedfd52b8..23cdc4b117 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -4,6 +4,10 @@ on: workflow_dispatch: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index b595502b21..809c4cf4ed 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -4,6 +4,10 @@ on: workflow_dispatch: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index dc5fce56ba..bd9efc79d7 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -4,6 +4,10 @@ on: workflow_dispatch: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 4f2b176d1f..63d0eb77ac 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -4,6 +4,10 @@ on: workflow_dispatch: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 3f6e521fd1..c65e8fe27b 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -13,6 +13,10 @@ on: required: false type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index 720efaa29c..e8d30dbfee 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -16,6 +16,10 @@ on: required: false type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 89f1ad735c..8aadae65b7 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -7,6 +7,10 @@ on: required: false type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 4342082868..3ca800349c 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -3,6 +3,10 @@ name: TypeScript tests on: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 1caec5c1ac..331627e262 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -3,6 +3,10 @@ name: Unit tests on: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: run: strategy: From 896bd6533688f9be9eba2ea246f1dbf6e0c4b84d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 11:12:25 -0700 Subject: [PATCH 461/709] Address the redundancy problem. --- .github/workflows/all-c.yml | 43 ---------------- .github/workflows/all-cpp.yml | 32 ------------ .github/workflows/all-py.yml | 32 ------------ .github/workflows/all-ts.yml | 32 ------------ .github/workflows/all.yml | 51 ------------------- ...c.yml => non-target-specific-extended.yml} | 2 +- .../{all-rs.yml => non-target-specific.yml} | 18 ++----- .github/workflows/only-c.yml | 7 +++ .github/workflows/only-cpp.yml | 6 +++ .github/workflows/only-py.yml | 6 +++ .github/workflows/only-rs.yml | 6 +++ .github/workflows/only-ts.yml | 6 +++ 12 files changed, 37 insertions(+), 204 deletions(-) delete mode 100644 .github/workflows/all-c.yml delete mode 100644 .github/workflows/all-cpp.yml delete mode 100644 .github/workflows/all-py.yml delete mode 100644 .github/workflows/all-ts.yml delete mode 100644 .github/workflows/all.yml rename .github/workflows/{all-non-target-specific.yml => non-target-specific-extended.yml} (96%) rename .github/workflows/{all-rs.yml => non-target-specific.yml} (54%) diff --git a/.github/workflows/all-c.yml b/.github/workflows/all-c.yml deleted file mode 100644 index 7249009852..0000000000 --- a/.github/workflows/all-c.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: C-based tests - -on: - workflow_dispatch: - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - -env: - # 2020.11 - vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 - -jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml - - # Run the unit tests. - unit-tests: - uses: ./.github/workflows/unit-tests.yml - needs: cancel - - c-tests: - uses: ./.github/workflows/only-c.yml - needs: cancel - - # Run the Python integration tests. - py-tests: - uses: ./.github/workflows/py-tests.yml - needs: cancel - - # Run the serialization tests - serialization-tests: - uses: ./.github/workflows/serialization-tests.yml - needs: cancel diff --git a/.github/workflows/all-cpp.yml b/.github/workflows/all-cpp.yml deleted file mode 100644 index c9b207d72e..0000000000 --- a/.github/workflows/all-cpp.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Cpp-based tests - -on: - workflow_dispatch: - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/lib/cpp/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - -env: - # 2020.11 - vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 - -jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml - - cpp-tests: - uses: ./.github/workflows/only-cpp.yml - needs: cancel - - # Run the serialization tests - serialization-tests: - uses: ./.github/workflows/serialization-tests.yml - needs: cancel diff --git a/.github/workflows/all-py.yml b/.github/workflows/all-py.yml deleted file mode 100644 index 40b9250a7a..0000000000 --- a/.github/workflows/all-py.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Python-based tests - -on: - workflow_dispatch: - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/lib/py/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - -env: - # 2020.11 - vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 - -jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml - - py-tests: - uses: ./.github/workflows/only-py.yml - needs: cancel - - # Run the serialization tests - serialization-tests: - uses: ./.github/workflows/serialization-tests.yml - needs: cancel diff --git a/.github/workflows/all-ts.yml b/.github/workflows/all-ts.yml deleted file mode 100644 index 1e4e9edbd7..0000000000 --- a/.github/workflows/all-ts.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: TypeScript-based tests - -on: - workflow_dispatch: - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/ts/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - -env: - # 2020.11 - vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 - -jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml - - ts-tests: - uses: ./.github/workflows/only-ts.yml - needs: cancel - - # Run the serialization tests - serialization-tests: - uses: ./.github/workflows/serialization-tests.yml - needs: cancel diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml deleted file mode 100644 index 10042c135a..0000000000 --- a/.github/workflows/all.yml +++ /dev/null @@ -1,51 +0,0 @@ -# Main workflow for testing the Lingua Franca compiler. -name: CI - -on: - workflow_dispatch: - push: - branches: - - master - -env: - # 2020.11 - vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 - -jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml - - check-format: - uses: ./.github/workflows/check-format.yml - needs: cancel - - # Run the non-target-specific tests. - non-target-specific: - uses: ./.github/workflows/all-non-target-specific.yml - needs: cancel - - # Run the C tests. - c-tests: - uses: ./.github/workflows/only-c.yml - needs: cancel - - # Run the C++ tests. - cpp-tests: - uses: ./.github/workflows/only-cpp.yml - needs: cancel - - # Run the Python tests. - py-tests: - uses: ./.github/workflows/only-py.yml - needs: cancel - - # Run the Rust tests. - rs-tests: - uses: ./.github/workflows/only-rs.yml - needs: cancel - - # Run the TypeScript tests. - ts-tests: - uses: ./.github/workflows/only-ts.yml - needs: cancel diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/non-target-specific-extended.yml similarity index 96% rename from .github/workflows/all-non-target-specific.yml rename to .github/workflows/non-target-specific-extended.yml index db05bd982f..63571ae210 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -1,4 +1,4 @@ -name: Non-target-specific tests +name: Additional non-target-specific tests on: workflow_dispatch: diff --git a/.github/workflows/all-rs.yml b/.github/workflows/non-target-specific.yml similarity index 54% rename from .github/workflows/all-rs.yml rename to .github/workflows/non-target-specific.yml index 3328c27d72..cdf5762eea 100644 --- a/.github/workflows/all-rs.yml +++ b/.github/workflows/non-target-specific.yml @@ -1,13 +1,10 @@ -name: Rust-based tests +name: Non-target-specific tests on: workflow_dispatch: pull_request: branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/lib/rs/**' + - 'nightly' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -18,15 +15,10 @@ env: vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml - - rs-tests: - uses: ./.github/workflows/only-rs.yml - needs: cancel + # Run the unit tests. + unit-tests: + uses: ./.github/workflows/unit-tests.yml # Run the serialization tests serialization-tests: uses: ./.github/workflows/serialization-tests.yml - needs: cancel diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 530e3e2aca..f59f2c151b 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -3,6 +3,13 @@ name: C on: workflow_dispatch: workflow_call: + pull_request: + branches-ignore: + - 'nightly' + paths: + - 'org.lflang/src/org/lflang/generator/c/**' + - 'org.lflang/src/lib/c/**' + - 'org.lflang/src/lib/platform/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index 23cdc4b117..c7a36cb1a3 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -3,6 +3,12 @@ name: C++ on: workflow_dispatch: workflow_call: + pull_request: + branches-ignore: + - 'nightly' + paths: + - 'org.lflang/src/org/lflang/generator/cpp/**' + - 'org.lflang/src/lib/cpp/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index 809c4cf4ed..0c5f2ed4c9 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -3,6 +3,12 @@ name: Python on: workflow_dispatch: workflow_call: + pull_request: + branches-ignore: + - 'nightly' + paths: + - 'org.lflang/src/org/lflang/generator/python/**' + - 'org.lflang/src/lib/py/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index bd9efc79d7..2f0158767b 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -3,6 +3,12 @@ name: Rust on: workflow_dispatch: workflow_call: + pull_request: + branches-ignore: + - 'nightly' + paths: + - 'org.lflang/src/org/lflang/generator/rust/**' + - 'org.lflang/src/lib/rs/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 63d0eb77ac..fafedb3885 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -3,6 +3,12 @@ name: Rust on: workflow_dispatch: workflow_call: + pull_request: + branches-ignore: + - 'nightly' + paths: + - 'org.lflang/src/org/lflang/generator/ts/**' + - 'org.lflang/src/lib/ts/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} From e74ee4ac6ee0cefa4d81010b90ed880df5eae4e1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 11:29:02 -0700 Subject: [PATCH 462/709] Do not run on all platforms if PR is still a draft. --- .github/workflows/c-arduino-tests.yml | 6 +++++- .github/workflows/c-tests.yml | 8 ++++++-- .github/workflows/cpp-tests.yml | 6 +++++- .github/workflows/only-c.yml | 5 +++++ .github/workflows/only-cpp.yml | 5 +++++ .github/workflows/only-py.yml | 2 ++ .github/workflows/only-rs.yml | 3 +++ .github/workflows/only-ts.yml | 2 ++ .github/workflows/py-tests.yml | 6 +++++- .github/workflows/rs-tests.yml | 6 +++++- .github/workflows/ts-tests.yml | 7 ++++++- 11 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 8c77d6e52d..348ca06d4c 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -16,6 +16,10 @@ on: scheduler: required: false type: string + all-platforms: + required: false + default: true + type: boolean concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -25,7 +29,7 @@ jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest"]')) || 'ubuntu-latest' }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index c29b3c0a61..8f641e6482 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -16,16 +16,20 @@ on: scheduler: required: false type: string + all-platforms: + required: false + default: true + type: boolean concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: - run: + c-tests: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index e3f957ab2d..1f8001cf7d 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -9,6 +9,10 @@ on: runtime-ref: required: false type: string + all-platforms: + required: false + default: true + type: boolean concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -18,7 +22,7 @@ jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index f59f2c151b..f720bb5006 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -29,10 +29,14 @@ jobs: # Run the C integration tests. c-tests: uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Arduino integration tests. c-arduino-tests: uses: ./.github/workflows/c-arduino-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. c-zephyr-tests: @@ -43,3 +47,4 @@ jobs: uses: ./.github/workflows/c-tests.yml with: use-cpp: true + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index c7a36cb1a3..75b89cadff 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -24,11 +24,16 @@ jobs: uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Cpp' + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests. cpp-tests: uses: ./.github/workflows/cpp-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests on ROS2. cpp-ros2-tests: uses: ./.github/workflows/cpp-ros2-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index 0c5f2ed4c9..71003f0dad 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -22,3 +22,5 @@ jobs: # Run the Python integration tests. py-tests: uses: ./.github/workflows/py-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 2f0158767b..7b6dbe7042 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -22,9 +22,12 @@ jobs: # Run the Rust integration tests. rs-tests: uses: ./.github/workflows/rs-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run the Rust benchmark tests. rs-benchmark-tests: uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Rust' + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index fafedb3885..ee5b5444b8 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -22,3 +22,5 @@ jobs: # Run the TypeScript integration tests. ts-tests: uses: ./.github/workflows/ts-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index c65e8fe27b..edc5f67e04 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -12,6 +12,10 @@ on: reactor-c-py-ref: required: false type: string + all-platforms: + required: false + default: true + type: boolean concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -21,7 +25,7 @@ jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index e8d30dbfee..3f9515af58 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -15,6 +15,10 @@ on: only if this workflow is being run from the reactor-rs repository. required: false type: string + all-platforms: + required: false + default: true + type: boolean concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -24,7 +28,7 @@ jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} rust: [stable] runs-on: ${{ matrix.platform }} steps: diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 3ca800349c..130a1106ed 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -2,6 +2,11 @@ name: TypeScript tests on: workflow_call: + inputs: + all-platforms: + required: false + default: true + type: boolean concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -11,7 +16,7 @@ jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository From a4ce7d812a7c0ecb95f40ee3f2972a952b754340 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 11:42:01 -0700 Subject: [PATCH 463/709] Fix overzealous concurrency limit. --- .github/workflows/build-trace-tools.yml | 4 ---- .github/workflows/build.yml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/.github/workflows/build-trace-tools.yml b/.github/workflows/build-trace-tools.yml index bd69f7be68..2490e9b75e 100644 --- a/.github/workflows/build-trace-tools.yml +++ b/.github/workflows/build-trace-tools.yml @@ -3,10 +3,6 @@ name: Build the tools for processing execution traces on: workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2417cece56..767df01fa1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,10 +12,6 @@ on: required: false workflow_dispatch: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: runs-on: ubuntu-latest From c07d598716e1574242d537cd4ca27fa947a4d934 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 11:53:13 -0700 Subject: [PATCH 464/709] More removals of concurrency limits. --- .github/workflows/c-arduino-tests.yml | 4 ---- .github/workflows/c-tests.yml | 4 ---- .github/workflows/c-zephyr-tests.yml | 4 ---- .github/workflows/cli-tests.yml | 4 ---- .github/workflows/cpp-ros2-tests.yml | 4 ---- .github/workflows/cpp-tests.yml | 4 ---- .github/workflows/lsp-tests.yml | 4 ---- .github/workflows/nightly-build.yml | 4 ---- .github/workflows/non-target-specific-extended.yml | 7 ------- .github/workflows/py-tests.yml | 4 ---- .github/workflows/rs-tests.yml | 4 ---- .github/workflows/serialization-tests.yml | 4 ---- .github/workflows/ts-tests.yml | 4 ---- .github/workflows/unit-tests.yml | 4 ---- 14 files changed, 59 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 348ca06d4c..d2ef2be8e7 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -21,10 +21,6 @@ on: default: true type: boolean -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 8f641e6482..4dd617054d 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -21,10 +21,6 @@ on: default: true type: boolean -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: c-tests: strategy: diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 49f204bb44..3b7a76feee 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -17,10 +17,6 @@ on: required: false type: string -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 3d23f0bd9f..056e32c04c 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -3,10 +3,6 @@ name: CLI tests on: workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index c81ca59f02..93054676b5 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -10,10 +10,6 @@ on: required: false type: string -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 1f8001cf7d..aaf87185ee 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -14,10 +14,6 @@ on: default: true type: boolean -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index 7418bde69d..bf32254b0f 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -3,10 +3,6 @@ name: Language server tests on: workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 469e9dc600..9ffb82c581 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -6,10 +6,6 @@ on: - cron: '0 5 * * *' workflow_dispatch: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: build: uses: ./.github/workflows/build.yml diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 63571ae210..2be9c863c3 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -26,26 +26,19 @@ env: vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 jobs: - # Cancel previous workflow runs. - cancel: - uses: ./.github/workflows/cancel.yml # Test the Gradle build. build: uses: ./.github/workflows/build.yml - needs: cancel # Build the tools used for processing execution traces build-tracing-tools: uses: ./.github/workflows/build-trace-tools.yml - needs: cancel # Run tests for the standalone compiler. cli-tests: uses: ./.github/workflows/cli-tests.yml - needs: cancel # Run language server tests. lsp-tests: uses: ./.github/workflows/lsp-tests.yml - needs: cancel diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index edc5f67e04..bb6dcf5f87 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -17,10 +17,6 @@ on: default: true type: boolean -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index 3f9515af58..01f20899ed 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -20,10 +20,6 @@ on: default: true type: boolean -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 8aadae65b7..89f1ad735c 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -7,10 +7,6 @@ on: required: false type: string -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: runs-on: ubuntu-latest diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 130a1106ed..c97955ff9c 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -8,10 +8,6 @@ on: default: true type: boolean -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 331627e262..1caec5c1ac 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -3,10 +3,6 @@ name: Unit tests on: workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: strategy: From 60f966148a6e6bf4f5835137933a7b9db7320a6f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 14:22:35 -0700 Subject: [PATCH 465/709] Fix syntax error. --- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/c-tests.yml | 2 +- .github/workflows/cpp-tests.yml | 2 +- .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index d2ef2be8e7..ceb90159bc 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -25,7 +25,7 @@ jobs: run: strategy: matrix: - platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest"]')) || 'ubuntu-latest' }} + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 4dd617054d..199fb3b8dd 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -25,7 +25,7 @@ jobs: c-tests: strategy: matrix: - platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index aaf87185ee..4b402ed845 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -18,7 +18,7 @@ jobs: run: strategy: matrix: - platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index bb6dcf5f87..e8ea1eac77 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -21,7 +21,7 @@ jobs: run: strategy: matrix: - platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index 01f20899ed..dae04b2dc8 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -24,7 +24,7 @@ jobs: run: strategy: matrix: - platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} rust: [stable] runs-on: ${{ matrix.platform }} steps: diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index c97955ff9c..c70a356a13 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -12,7 +12,7 @@ jobs: run: strategy: matrix: - platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || 'ubuntu-latest' }} + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository From ddcd858da5b129fe7bd190b74fbd98e6dfb7fa0b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 14:41:49 -0700 Subject: [PATCH 466/709] More "do not run on all platforms." --- .github/workflows/build-trace-tools.yml | 7 ++++++- .github/workflows/cli-tests.yml | 7 ++++++- .github/workflows/lsp-tests.yml | 7 ++++++- .github/workflows/non-target-specific-extended.yml | 6 ++++++ .github/workflows/non-target-specific.yml | 2 ++ .github/workflows/unit-tests.yml | 7 ++++++- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-trace-tools.yml b/.github/workflows/build-trace-tools.yml index 2490e9b75e..86d8724481 100644 --- a/.github/workflows/build-trace-tools.yml +++ b/.github/workflows/build-trace-tools.yml @@ -2,12 +2,17 @@ name: Build the tools for processing execution traces on: workflow_call: + inputs: + all-platforms: + required: false + default: true + type: boolean jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 056e32c04c..2a2c3e32e4 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -2,12 +2,17 @@ name: CLI tests on: workflow_call: + inputs: + all-platforms: + required: false + default: true + type: boolean jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index bf32254b0f..76ecd3f7eb 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -2,12 +2,17 @@ name: Language server tests on: workflow_call: + inputs: + all-platforms: + required: false + default: true + type: boolean jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: # Uninstall operations are needed because the language server is able to use multiple diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 2be9c863c3..772101dece 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -34,11 +34,17 @@ jobs: # Build the tools used for processing execution traces build-tracing-tools: uses: ./.github/workflows/build-trace-tools.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run tests for the standalone compiler. cli-tests: uses: ./.github/workflows/cli-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. lsp-tests: uses: ./.github/workflows/lsp-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index cdf5762eea..8f522afdef 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -18,6 +18,8 @@ jobs: # Run the unit tests. unit-tests: uses: ./.github/workflows/unit-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Run the serialization tests serialization-tests: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 1caec5c1ac..dd7613f8af 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -2,12 +2,17 @@ name: Unit tests on: workflow_call: + inputs: + all-platforms: + required: false + default: true + type: boolean jobs: run: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v3 From 89b3bf7971bffe482213657f53a597f444bc57ed Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 16:36:22 -0700 Subject: [PATCH 467/709] Depend on whether workflow is ready for review. --- .github/workflows/all.yml | 55 +++++++++++++++++++++++ .github/workflows/non-target-specific.yml | 1 + .github/workflows/only-c.yml | 9 +++- .github/workflows/only-cpp.yml | 6 ++- .github/workflows/only-py.yml | 3 +- .github/workflows/only-rs.yml | 4 +- .github/workflows/only-ts.yml | 3 +- 7 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/all.yml diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml new file mode 100644 index 0000000000..dd36e09ee0 --- /dev/null +++ b/.github/workflows/all.yml @@ -0,0 +1,55 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + + check-format: + if: !github.event.pull_request.draft + uses: ./.github/workflows/check-format.yml + + # Run the non-target-specific tests. + non-target-specific: + if: !github.event.pull_request.draft + uses: ./.github/workflows/non-target-specific.yml + + # Run the non-target-specific tests. + non-target-specific-extended: + if: !github.event.pull_request.draft + uses: ./.github/workflows/non-target-specific-extended.yml + + # Run the C tests. + c-tests: + if: !github.event.pull_request.draft + uses: ./.github/workflows/only-c.yml + + # Run the C++ tests. + cpp-tests: + if: !github.event.pull_request.draft + uses: ./.github/workflows/only-cpp.yml + + # Run the Python tests. + py-tests: + if: !github.event.pull_request.draft + uses: ./.github/workflows/only-py.yml + + # Run the Rust tests. + rs-tests: + if: !github.event.pull_request.draft + uses: ./.github/workflows/only-rs.yml + + # Run the TypeScript tests. + ts-tests: + if: !github.event.pull_request.draft + uses: ./.github/workflows/only-ts.yml diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index 8f522afdef..10be3de7d0 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -2,6 +2,7 @@ name: Non-target-specific tests on: workflow_dispatch: + workflow_call: pull_request: branches-ignore: - 'nightly' diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index f720bb5006..38bb01f86f 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -11,8 +11,10 @@ on: - 'org.lflang/src/lib/c/**' - 'org.lflang/src/lib/platform/**' + + concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} env: @@ -22,28 +24,33 @@ env: jobs: # Run the C benchmark tests. c-benchmark-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'C' # Run the C integration tests. c-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Arduino integration tests. c-arduino-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. c-zephyr-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. ccpp-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index 75b89cadff..e2ac03f499 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -11,7 +11,7 @@ on: - 'org.lflang/src/lib/cpp/**' concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} env: @@ -21,19 +21,21 @@ env: jobs: # Run the C++ benchmark tests. cpp-benchmark-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Cpp' - all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests. cpp-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests on ROS2. cpp-ros2-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-ros2-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index 71003f0dad..edc9057760 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -11,7 +11,7 @@ on: - 'org.lflang/src/lib/py/**' concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} env: @@ -22,5 +22,6 @@ jobs: # Run the Python integration tests. py-tests: uses: ./.github/workflows/py-tests.yml + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 7b6dbe7042..a52424b586 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -11,7 +11,7 @@ on: - 'org.lflang/src/lib/rs/**' concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} env: @@ -21,12 +21,14 @@ env: jobs: # Run the Rust integration tests. rs-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/rs-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the Rust benchmark tests. rs-benchmark-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Rust' diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index ee5b5444b8..6623eafd11 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -11,7 +11,7 @@ on: - 'org.lflang/src/lib/ts/**' concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} env: @@ -21,6 +21,7 @@ env: jobs: # Run the TypeScript integration tests. ts-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/ts-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} From 1ce9e1440cfda888c17311ab6af9fee9457164f5 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 16:46:35 -0700 Subject: [PATCH 468/709] Split the "all" workflow (workaround). This is a workaround for another arbitrary limit. See https://github.com/orgs/community/discussions/32192. --- .github/workflows/all-non-target-specific.yml | 26 +++++++++++++++++++ .../workflows/{all.yml => all-targets.yml} | 14 ---------- .../non-target-specific-extended.yml | 4 +++ 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/all-non-target-specific.yml rename .github/workflows/{all.yml => all-targets.yml} (66%) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml new file mode 100644 index 0000000000..25f1316314 --- /dev/null +++ b/.github/workflows/all-non-target-specific.yml @@ -0,0 +1,26 @@ +# Main workflow for testing the Lingua Franca compiler. +name: CI + +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + +env: + # 2020.11 + vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 + +jobs: + + # Run the non-target-specific tests. + non-target-specific: + if: !github.event.pull_request.draft + uses: ./.github/workflows/non-target-specific.yml + + # Run the non-target-specific tests. + non-target-specific-extended: + if: !github.event.pull_request.draft + uses: ./.github/workflows/non-target-specific-extended.yml diff --git a/.github/workflows/all.yml b/.github/workflows/all-targets.yml similarity index 66% rename from .github/workflows/all.yml rename to .github/workflows/all-targets.yml index dd36e09ee0..2041a5c44e 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all-targets.yml @@ -15,20 +15,6 @@ env: jobs: - check-format: - if: !github.event.pull_request.draft - uses: ./.github/workflows/check-format.yml - - # Run the non-target-specific tests. - non-target-specific: - if: !github.event.pull_request.draft - uses: ./.github/workflows/non-target-specific.yml - - # Run the non-target-specific tests. - non-target-specific-extended: - if: !github.event.pull_request.draft - uses: ./.github/workflows/non-target-specific-extended.yml - # Run the C tests. c-tests: if: !github.event.pull_request.draft diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 772101dece..fb4caef58a 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -37,6 +37,10 @@ jobs: with: all-platforms: ${{ !github.event.pull_request.draft }} + check-format: + if: !github.event.pull_request.draft + uses: ./.github/workflows/check-format.yml + # Run tests for the standalone compiler. cli-tests: uses: ./.github/workflows/cli-tests.yml From 25edb0075d01ae4e8154d0795832114050a09c48 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 16:50:32 -0700 Subject: [PATCH 469/709] Fix syntax error. --- .github/workflows/all-non-target-specific.yml | 4 ++-- .github/workflows/all-targets.yml | 10 +++++----- .github/workflows/non-target-specific-extended.yml | 8 ++++---- .github/workflows/non-target-specific.yml | 2 +- .github/workflows/only-c.yml | 6 +++--- .github/workflows/only-cpp.yml | 4 +--- .github/workflows/only-py.yml | 2 +- .github/workflows/only-rs.yml | 3 +-- .github/workflows/only-ts.yml | 2 +- 9 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 25f1316314..ec3258253a 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -17,10 +17,10 @@ jobs: # Run the non-target-specific tests. non-target-specific: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/non-target-specific.yml # Run the non-target-specific tests. non-target-specific-extended: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/non-target-specific-extended.yml diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 2041a5c44e..6c3d31d3f3 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -17,25 +17,25 @@ jobs: # Run the C tests. c-tests: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-c.yml # Run the C++ tests. cpp-tests: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-cpp.yml # Run the Python tests. py-tests: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-py.yml # Run the Rust tests. rs-tests: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-rs.yml # Run the TypeScript tests. ts-tests: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-ts.yml diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index fb4caef58a..5353406235 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -35,20 +35,20 @@ jobs: build-tracing-tools: uses: ./.github/workflows/build-trace-tools.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} check-format: - if: !github.event.pull_request.draft + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/check-format.yml # Run tests for the standalone compiler. cli-tests: uses: ./.github/workflows/cli-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. lsp-tests: uses: ./.github/workflows/lsp-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index 10be3de7d0..f6f6bcabc2 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -20,7 +20,7 @@ jobs: unit-tests: uses: ./.github/workflows/unit-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run the serialization tests serialization-tests: diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 38bb01f86f..d4ef34820d 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -34,14 +34,14 @@ jobs: if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Arduino integration tests. c-arduino-tests: if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. c-zephyr-tests: @@ -54,4 +54,4 @@ jobs: uses: ./.github/workflows/c-tests.yml with: use-cpp: true - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index e2ac03f499..36f5682944 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -31,11 +31,9 @@ jobs: if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests on ROS2. cpp-ros2-tests: if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-ros2-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index edc9057760..f43a521e30 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -24,4 +24,4 @@ jobs: uses: ./.github/workflows/py-tests.yml if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index a52424b586..71adaa36ae 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -24,7 +24,7 @@ jobs: if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/rs-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run the Rust benchmark tests. rs-benchmark-tests: @@ -32,4 +32,3 @@ jobs: uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Rust' - all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 6623eafd11..6d7cd0098c 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -24,4 +24,4 @@ jobs: if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/ts-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} From 833d8a3437ce6d7c06d9d283b38fc2c33817d629 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 17:13:47 -0700 Subject: [PATCH 470/709] Update non-target-specific-extended.yml. --- .github/workflows/non-target-specific-extended.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 5353406235..4a486f9ff7 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -29,26 +29,30 @@ jobs: # Test the Gradle build. build: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/build.yml # Build the tools used for processing execution traces build-tracing-tools: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/build-trace-tools.yml with: all-platforms: ${{ !github.event.pull_request.draft }} check-format: - if: ${{ !github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/check-format.yml # Run tests for the standalone compiler. cli-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/cli-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. lsp-tests: + if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} uses: ./.github/workflows/lsp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} From b255db743da07431e6f01021e6390e5bb42970b2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 17:20:08 -0700 Subject: [PATCH 471/709] Address deadlock reported by GH actions. --- .github/workflows/check-format.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index 8fc44a98df..8c022f90a5 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -3,10 +3,6 @@ name: Spotless check on: workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - jobs: run: runs-on: ubuntu-latest From 01a9215b39f16f838798200faa8cdf13853e6a58 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 17:28:37 -0700 Subject: [PATCH 472/709] Try to address unwanted cancellation. --- .github/workflows/all-non-target-specific.yml | 7 +++++-- .github/workflows/all-targets.yml | 7 +++++-- .github/workflows/non-target-specific-extended.yml | 4 ---- .github/workflows/non-target-specific.yml | 4 ---- .github/workflows/only-c.yml | 6 ------ .github/workflows/only-cpp.yml | 4 ---- .github/workflows/only-py.yml | 4 ---- .github/workflows/only-rs.yml | 4 ---- .github/workflows/only-ts.yml | 4 ---- 9 files changed, 10 insertions(+), 34 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index ec3258253a..896ffc71b4 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,5 +1,4 @@ -# Main workflow for testing the Lingua Franca compiler. -name: CI +name: Non-target-specific on: workflow_dispatch: @@ -13,6 +12,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the non-target-specific tests. diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 6c3d31d3f3..f0e0b32f42 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -1,5 +1,4 @@ -# Main workflow for testing the Lingua Franca compiler. -name: CI +name: Target-specific on: workflow_dispatch: @@ -13,6 +12,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the C tests. diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 4a486f9ff7..c667a5b9ca 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -17,10 +17,6 @@ on: - 'org.lflang/src/lib/rs/**' - 'org.lflang/src/lib/ts/**' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index f6f6bcabc2..3e5fb4a341 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -7,10 +7,6 @@ on: branches-ignore: - 'nightly' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index d4ef34820d..07f54ff510 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -11,12 +11,6 @@ on: - 'org.lflang/src/lib/c/**' - 'org.lflang/src/lib/platform/**' - - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index 36f5682944..d95a895ca2 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -10,10 +10,6 @@ on: - 'org.lflang/src/org/lflang/generator/cpp/**' - 'org.lflang/src/lib/cpp/**' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index f43a521e30..48dd61b92b 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -10,10 +10,6 @@ on: - 'org.lflang/src/org/lflang/generator/python/**' - 'org.lflang/src/lib/py/**' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 71adaa36ae..6bc206e42c 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -10,10 +10,6 @@ on: - 'org.lflang/src/org/lflang/generator/rust/**' - 'org.lflang/src/lib/rs/**' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 6d7cd0098c..65ce523413 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -10,10 +10,6 @@ on: - 'org.lflang/src/org/lflang/generator/ts/**' - 'org.lflang/src/lib/ts/**' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 From 0de92d2faef21a89fb728bf80fad6acf454601b8 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 17:53:58 -0700 Subject: [PATCH 473/709] Try again to run all tests when ready for review. --- .github/workflows/non-target-specific-extended.yml | 10 +++++----- .github/workflows/only-c.yml | 10 +++++----- .github/workflows/only-cpp.yml | 6 +++--- .github/workflows/only-py.yml | 2 +- .github/workflows/only-rs.yml | 4 ++-- .github/workflows/only-ts.yml | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index c667a5b9ca..f790d8397d 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -25,30 +25,30 @@ jobs: # Test the Gradle build. build: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/build.yml # Build the tools used for processing execution traces build-tracing-tools: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/build-trace-tools.yml with: all-platforms: ${{ !github.event.pull_request.draft }} check-format: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/check-format.yml # Run tests for the standalone compiler. cli-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/cli-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. lsp-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/lsp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 07f54ff510..a73c76f35a 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -18,33 +18,33 @@ env: jobs: # Run the C benchmark tests. c-benchmark-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'C' # Run the C integration tests. c-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Arduino integration tests. c-arduino-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. c-zephyr-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. ccpp-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index d95a895ca2..f1ffce2d82 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -17,19 +17,19 @@ env: jobs: # Run the C++ benchmark tests. cpp-benchmark-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Cpp' # Run the C++ integration tests. cpp-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests on ROS2. cpp-ros2-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-ros2-tests.yml diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index 48dd61b92b..c8bc858651 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -18,6 +18,6 @@ jobs: # Run the Python integration tests. py-tests: uses: ./.github/workflows/py-tests.yml - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 6bc206e42c..7b009144ab 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -17,14 +17,14 @@ env: jobs: # Run the Rust integration tests. rs-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/rs-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the Rust benchmark tests. rs-benchmark-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Rust' diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 65ce523413..5af88bc471 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -17,7 +17,7 @@ env: jobs: # Run the TypeScript integration tests. ts-tests: - if: ${{ github.event_name == 'workflow_call' || github.event.pull_request.draft }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} uses: ./.github/workflows/ts-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} From c892ab62a7e313d2e7485e4749d31499d7dab6a0 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 18:23:22 -0700 Subject: [PATCH 474/709] Try again to run all tests. --- .github/workflows/all-non-target-specific.yml | 4 ++++ .github/workflows/all-targets.yml | 10 ++++++++++ .github/workflows/non-target-specific-extended.yml | 13 ++++++++----- .github/workflows/non-target-specific.yml | 5 +++++ .github/workflows/only-c.yml | 13 ++++++++----- .github/workflows/only-cpp.yml | 9 ++++++--- .github/workflows/only-py.yml | 5 ++++- .github/workflows/only-rs.yml | 7 +++++-- .github/workflows/only-ts.yml | 5 ++++- 9 files changed, 54 insertions(+), 17 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 896ffc71b4..27f0ba9994 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -22,8 +22,12 @@ jobs: non-target-specific: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/non-target-specific.yml + with: + all: true # Run the non-target-specific tests. non-target-specific-extended: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/non-target-specific-extended.yml + with: + all: true diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index f0e0b32f42..9bba174ed2 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -22,23 +22,33 @@ jobs: c-tests: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-c.yml + with: + all: true # Run the C++ tests. cpp-tests: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-cpp.yml + with: + all: true # Run the Python tests. py-tests: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-py.yml + with: + all: true # Run the Rust tests. rs-tests: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-rs.yml + with: + all: true # Run the TypeScript tests. ts-tests: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-ts.yml + with: + all: true diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index f790d8397d..085bfcd567 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -3,6 +3,9 @@ name: Additional non-target-specific tests on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: paths-ignore: - 'org.lflang/src/org/lflang/generator/c/**' @@ -25,30 +28,30 @@ jobs: # Test the Gradle build. build: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/build.yml # Build the tools used for processing execution traces build-tracing-tools: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/build-trace-tools.yml with: all-platforms: ${{ !github.event.pull_request.draft }} check-format: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/check-format.yml # Run tests for the standalone compiler. cli-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/cli-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. lsp-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/lsp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index 3e5fb4a341..7835f6122b 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -3,6 +3,9 @@ name: Non-target-specific tests on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: branches-ignore: - 'nightly' @@ -14,10 +17,12 @@ env: jobs: # Run the unit tests. unit-tests: + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/unit-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the serialization tests serialization-tests: + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/serialization-tests.yml diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index a73c76f35a..448daff830 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -3,6 +3,9 @@ name: C on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: branches-ignore: - 'nightly' @@ -18,33 +21,33 @@ env: jobs: # Run the C benchmark tests. c-benchmark-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'C' # Run the C integration tests. c-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Arduino integration tests. c-arduino-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. c-zephyr-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. ccpp-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index f1ffce2d82..2a2be6dcb5 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -3,6 +3,9 @@ name: C++ on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: branches-ignore: - 'nightly' @@ -17,19 +20,19 @@ env: jobs: # Run the C++ benchmark tests. cpp-benchmark-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Cpp' # Run the C++ integration tests. cpp-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests on ROS2. cpp-ros2-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-ros2-tests.yml diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index c8bc858651..136b41219c 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -3,6 +3,9 @@ name: Python on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: branches-ignore: - 'nightly' @@ -18,6 +21,6 @@ jobs: # Run the Python integration tests. py-tests: uses: ./.github/workflows/py-tests.yml - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 7b009144ab..5387f10785 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -3,6 +3,9 @@ name: Rust on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: branches-ignore: - 'nightly' @@ -17,14 +20,14 @@ env: jobs: # Run the Rust integration tests. rs-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/rs-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the Rust benchmark tests. rs-benchmark-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'Rust' diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 5af88bc471..1d33172d69 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -3,6 +3,9 @@ name: Rust on: workflow_dispatch: workflow_call: + inputs: + all: + type: boolean pull_request: branches-ignore: - 'nightly' @@ -17,7 +20,7 @@ env: jobs: # Run the TypeScript integration tests. ts-tests: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft }} + if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/ts-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} From 43550582d801dfefa23670dc394e44595c7ccce0 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 18:35:12 -0700 Subject: [PATCH 475/709] Rename main workflows. --- .github/workflows/all-non-target-specific.yml | 2 +- .github/workflows/all-targets.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 27f0ba9994..18102e87be 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,4 +1,4 @@ -name: Non-target-specific +name: CI (non-target-specific) on: workflow_dispatch: diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 9bba174ed2..16df3b7c83 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -1,4 +1,4 @@ -name: Target-specific +name: CI (target-specific) on: workflow_dispatch: From 6b3b9252e89f62988128131cc75605e9ca2a246b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 24 May 2023 18:41:41 -0700 Subject: [PATCH 476/709] Try again to implement cancellation. In presence of reusable workflows I have found jobs getting canceled due to detected "deadlocks" according to GH actions. It might have something to do with reused workflows inheriting the caller's value for github.workflow? --- .github/workflows/non-target-specific-extended.yml | 4 ++++ .github/workflows/non-target-specific.yml | 4 ++++ .github/workflows/only-c.yml | 4 ++++ .github/workflows/only-cpp.yml | 4 ++++ .github/workflows/only-py.yml | 4 ++++ .github/workflows/only-rs.yml | 4 ++++ .github/workflows/only-ts.yml | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 085bfcd567..2b3bfe8c12 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -24,6 +24,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-non-target-specific-extended-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Test the Gradle build. diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index 7835f6122b..f662451186 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -14,6 +14,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-non-target-specific-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the unit tests. unit-tests: diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 448daff830..c635aba13c 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -18,6 +18,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-c-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the C benchmark tests. c-benchmark-tests: diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index 2a2be6dcb5..22bc7fb814 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -17,6 +17,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-cpp-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the C++ benchmark tests. cpp-benchmark-tests: diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index 136b41219c..5adf989661 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -17,6 +17,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-py-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the Python integration tests. py-tests: diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 5387f10785..1dd0dfbf56 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -17,6 +17,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-rs-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the Rust integration tests. rs-tests: diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 1d33172d69..f6afde4b0b 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -17,6 +17,10 @@ env: # 2020.11 vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 +concurrency: + group: only-ts-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: # Run the TypeScript integration tests. ts-tests: From c3a130d2f73c420c03aa7bfa7dc038b624fda172 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 09:15:30 +0200 Subject: [PATCH 477/709] delete unused files --- org.lflang/.antlr-generator-3.2.0-patch.jar | Bin 1484649 -> 0 bytes org.lflang/about.html | 81 -------------------- org.lflang/build.properties | 20 ----- 3 files changed, 101 deletions(-) delete mode 100644 org.lflang/.antlr-generator-3.2.0-patch.jar delete mode 100644 org.lflang/about.html delete mode 100644 org.lflang/build.properties diff --git a/org.lflang/.antlr-generator-3.2.0-patch.jar b/org.lflang/.antlr-generator-3.2.0-patch.jar deleted file mode 100644 index 90516fd7ac76a3ec685e046f91eb762e68e20586..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1484649 zcmbrl1CV81w=I~qZL89*v~Am{^hw*cZQHhOJG0U@DznmE@Ba7R*Wc~#`d>uvh#hfa zpD`xZnrp7LPn@A34GIPW1Ox>HWN$ek0`z~opn<@EWJOg3=_KXE7(OR}fE4}{3I$~M z2Z~B{ETI1fZuRFz`*Z&{R8~+mBi#P9jB_HKtds0iloLF>x9k)g zEjlY6ER2H^I?qGGFIM+HCPp@O@Ux$WN; z(Z7pd$=S&LFaH0zX3ZQ7ZEOtx))dhHk?()uUH(>R{~wgURTknuyx3Sc8vi8)?056VwIRUF+0e}NFZ_QtkN?5{HzEHsKPOvT>%TbqXMX5?3TIX9GM-g_EvcqLOzPj6y(P96edU7oLI{#;WtQv`PhJ0C8H$kVLvdYn7r zLiA&z4jid5x8pGFbCfhkB)J;ol``#Xl&NFIa0*w2`S%ja^aoubR+iljG5zP=4xH*M znfFw+*0=MFnzL8YS*-RA14%TT`orUvaw~QYtdyg64z!e3oSZR`@MjvJ(*~Jn$)r<>YQBe(`0D1UWhU9F|NwLEAe9DCe9O;+ifc)$2?#0VW7?w}`$w z98f3&jz6POWvVRQZw$E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gp#wO^6se#_vw%;Z~R6Am9%6y`N!<1G_Me~25e>a@WoMs80 zwxp3By31jTMk%#gEU!HXX37pMq}|?{KPWDIA`Tr=Z#>gN{NG~n=lu;FEsL@m=~L!#XtJ!}fY~zY^&0q4oV@xj*@?(TCY1Z+-9mB4 zpxIFmv))&QX%<#%%Qe#xA|A5&p_1@s*z% zPpS%`E0}-A`{Eu5$fm@6nWWC2-4@VGjVP{=t4#{t?FkY)RFyVa{~$G56iaatYH;Z= z>yThnF*_NLYH(F=E>U2CZ_k@GV<*bUvbm_AdgcW#Ph99x4Z4n)ivsHqC;7Vchkv`R zb+8&z?Dal>VQyn~mB*7FD!edIjV29Rg(_U8Pk3)VXf0sTRD}_tT%tgQlfSura5KtR zfrqN_U*TMyScRJ_bZOOnSDa-dxJ3||f?s`60cI!LVJa`VdU}|Btgt=n zo$mllJyKnLp`VpLdy@;+P@R(CB*c@_`t8~Vnnki0ZghG5 zsdyC_r$@MM@3Uk%lr#yXwsHk9=d*MarAV9hG2D+ZV>=jcZfe+$PaAFpssVHrL~!Or z5iV*HOKo#3M`1uIF8LQjL-!6vG{Gjps2X#V1Rqh4!zM1aJRS%Y9)tI#UCzTXDlq9v z5NJWV2SlCt*W2xnushD{fJ%wh6ai6iJ%VrWe?rO-!f(g8$CqgJuT&S29E~7c1Tox6 z?0yQeZAR2X<*R8H(O5d0dWk!qzwl&Bbg+Z5rqYhc=aZvK9D)TOojEz3a|U8o=L{pe zd}utRq!nzLuF8wf;xDp}46Lcc^s1L09YY5q+#Z`M3@%YVWJ0~X{V#;>{05_M-wDzftJ|SAN5S2MR(!>?Ik9gn?o|50bbO;Dn)~zQ8=oDi#y8@0h76i!`xx4fm)DG% QGin|_fqUSNv#iel1NWwaUjP6A diff --git a/org.lflang/about.html b/org.lflang/about.html deleted file mode 100644 index 777f15cf39..0000000000 --- a/org.lflang/about.html +++ /dev/null @@ -1,81 +0,0 @@ - - - - - About - - -

    About This Content

    - -

    License

    - -

    - Lingua Franca is a polyglot coordination language for defining and composing reactors. -

    - -

    - For more information about Lingua-Franca, see https://github.com/icyphy/lingua-franca/wiki -

    - -

    - The Lingua-Franca toolkit is licensed under the BSD 2-Clause License: -

    - -

    - Copyright (c) 2020, The University of California at Berkeley, - The Technical University of Dresden, - and Volkan Yazici . -

    - -

    - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: -

    - -
      -
    1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -
    2. -
    3. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. -
    4. -
    - -

    - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - OF SUCH DAMAGE. -

    - -

    - SPDX-License-Identifier: BSD-2-Clause -

    - - - diff --git a/org.lflang/build.properties b/org.lflang/build.properties deleted file mode 100644 index 09be7967da..0000000000 --- a/org.lflang/build.properties +++ /dev/null @@ -1,20 +0,0 @@ -source.. = src/,\ - src-gen/ -bin.includes = model/generated/,\ - .,\ - META-INF/,\ - plugin.xml,\ - about.html -bin.excludes = **/*.mwe2,\ - **/*.xtend \ - src/lib -additional.bundles = org.eclipse.xtext.xbase,\ - org.eclipse.xtext.common.types,\ - org.eclipse.xtext.xtext.generator,\ - org.eclipse.emf.codegen.ecore,\ - org.eclipse.emf.mwe.utils,\ - org.eclipse.emf.mwe2.launch,\ - org.eclipse.emf.mwe2.lib,\ - org.objectweb.asm,\ - org.apache.log4j,\ - com.ibm.icu From 42d867df4175f6e430ae4aa611d4093906f4b0ab Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 09:22:18 +0200 Subject: [PATCH 478/709] update gitignore --- .gitignore | 4 ++++ org.lflang/.gitignore | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 org.lflang/.gitignore diff --git a/.gitignore b/.gitignore index bb35405752..b075a77ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,7 @@ gradle-app.setting **/build/ # End of https://www.toptal.com/developers/gitignore/api/intellij,gradle,eclipse,maven,visualstudiocode + +### xtext artifaccts +*.jar +org/lflang/model/ \ No newline at end of file diff --git a/org.lflang/.gitignore b/org.lflang/.gitignore deleted file mode 100644 index 0447b0d4ac..0000000000 --- a/org.lflang/.gitignore +++ /dev/null @@ -1 +0,0 @@ -model/ From 12f7e2c89d7d58ad93b1982db263e19dc31b4f45 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 11:12:39 +0200 Subject: [PATCH 479/709] gradle like source code layout --- .gitignore | 2 +- lfc/build.gradle | 2 +- org.lflang/{ => core}/build.gradle | 12 ++++++------ .../src/main/java}/org/lflang/AttributeUtils.java | 0 .../src/main/java}/org/lflang/CommonExtensions.kt | 0 .../main/java}/org/lflang/DefaultErrorReporter.java | 0 .../src/main/java}/org/lflang/ErrorReporter.java | 0 .../src/main/java}/org/lflang/FileConfig.java | 0 .../main/java}/org/lflang/FileConfigExtensions.kt | 0 .../main/java}/org/lflang/GenerateLinguaFranca.mwe2 | 6 ++++-- .../src/main/java}/org/lflang/InferredType.java | 0 .../org/lflang/LFResourceDescriptionStrategy.java | 0 .../main/java}/org/lflang/LFResourceProvider.java | 0 .../src/main/java}/org/lflang/LFRuntimeModule.java | 0 .../src/main/java}/org/lflang/LFStandaloneSetup.java | 0 .../org/lflang/LFSyntaxErrorMessageProvider.java | 0 .../src/main/java}/org/lflang/LinguaFranca.xtext | 0 .../src/main/java}/org/lflang/LocalStrings.java | 0 .../main/java}/org/lflang/MainConflictChecker.java | 0 .../src/main/java}/org/lflang/ModelInfo.java | 0 .../main/java}/org/lflang/StringsBundle.properties | 0 .../src/main/java}/org/lflang/Target.java | 0 .../src/main/java}/org/lflang/TargetConfig.java | 0 .../src/main/java}/org/lflang/TargetProperty.java | 0 .../src/main/java}/org/lflang/TimeUnit.java | 0 .../src/main/java}/org/lflang/TimeValue.java | 0 .../src/main/java}/org/lflang/ast/ASTUtils.java | 0 .../src/main/java}/org/lflang/ast/AstExtensions.kt | 0 .../main/java}/org/lflang/ast/AstTransformation.java | 0 .../lflang/ast/DelayedConnectionTransformation.java | 0 .../main/java}/org/lflang/ast/FormattingUtils.java | 0 .../src/main/java}/org/lflang/ast/IsEqual.java | 0 .../main/java}/org/lflang/ast/MalleableString.java | 0 .../src/main/java}/org/lflang/ast/ToLf.java | 0 .../src/main/java}/org/lflang/ast/ToText.java | 0 .../src/main/java}/org/lflang/cli/CliBase.java | 0 .../java}/org/lflang/cli/LFStandaloneModule.java | 0 .../src/main/java}/org/lflang/cli/Lff.java | 0 .../src/main/java}/org/lflang/cli/ReportingUtil.kt | 0 .../org/lflang/cli/StandaloneErrorReporter.java | 0 .../org/lflang/cli/StandaloneIssueAcceptor.java | 0 .../main/java}/org/lflang/cli/VersionProvider.java | 0 .../org/lflang/diagram/lsp/LFLanguageServer.java | 0 .../diagram/lsp/LFLanguageServerExtension.java | 0 .../lflang/diagram/lsp/LanguageDiagramServer.java | 0 .../main/java}/org/lflang/diagram/lsp/Progress.java | 0 .../synthesis/AbstractSynthesisExtensions.java | 0 .../diagram/synthesis/LinguaFrancaSynthesis.java | 0 .../synthesis/ReactorParameterDisplayModes.java | 0 .../diagram/synthesis/SynthesisRegistration.java | 0 .../diagram/synthesis/action/AbstractAction.java | 0 .../synthesis/action/CollapseAllReactorsAction.java | 0 .../synthesis/action/ExpandAllReactorsAction.java | 0 .../diagram/synthesis/action/FilterCycleAction.java | 0 .../action/MemorizingExpandCollapseAction.java | 0 .../diagram/synthesis/action/ShowCycleAction.java | 0 .../postprocessor/ReactionPortAdjustment.java | 0 .../styles/LinguaFrancaShapeExtensions.java | 0 .../styles/LinguaFrancaStyleExtensions.java | 0 .../synthesis/styles/ReactorFigureComponents.java | 0 .../diagram/synthesis/util/CycleVisualization.java | 0 .../util/InterfaceDependenciesVisualization.java | 0 .../diagram/synthesis/util/LayoutPostProcessing.java | 0 .../lflang/diagram/synthesis/util/ModeDiagrams.java | 0 .../diagram/synthesis/util/NamedInstanceUtil.java | 0 .../lflang/diagram/synthesis/util/ReactorIcons.java | 0 .../synthesis/util/SynthesisErrorReporter.java | 0 .../diagram/synthesis/util/UtilityExtensions.java | 0 .../org/lflang/federated/extensions/CExtension.java | 0 .../lflang/federated/extensions/CExtensionUtils.java | 0 .../federated/extensions/FedTargetExtension.java | 0 .../extensions/FedTargetExtensionFactory.java | 0 .../lflang/federated/extensions/PythonExtension.java | 0 .../org/lflang/federated/extensions/TSExtension.java | 0 .../org/lflang/federated/generator/FedASTUtils.java | 0 .../federated/generator/FedConnectionInstance.java | 0 .../org/lflang/federated/generator/FedEmitter.java | 0 .../lflang/federated/generator/FedFileConfig.java | 0 .../org/lflang/federated/generator/FedGenerator.java | 0 .../lflang/federated/generator/FedImportEmitter.java | 0 .../lflang/federated/generator/FedMainEmitter.java | 0 .../federated/generator/FedPreambleEmitter.java | 0 .../federated/generator/FedReactorEmitter.java | 0 .../lflang/federated/generator/FedTargetConfig.java | 0 .../lflang/federated/generator/FedTargetEmitter.java | 0 .../org/lflang/federated/generator/FedUtils.java | 0 .../lflang/federated/generator/FederateInstance.java | 0 .../generator/LineAdjustingErrorReporter.java | 0 .../generator/SynchronizedErrorReporter.java | 0 .../org/lflang/federated/launcher/BuildConfig.java | 0 .../org/lflang/federated/launcher/CBuildConfig.java | 0 .../federated/launcher/FedLauncherGenerator.java | 0 .../org/lflang/federated/launcher/PyBuildConfig.java | 0 .../org/lflang/federated/launcher/RtiConfig.java | 0 .../org/lflang/federated/launcher/TsBuildConfig.java | 0 .../serialization/FedNativePythonSerialization.java | 0 .../serialization/FedROS2CPPSerialization.java | 0 .../federated/serialization/FedSerialization.java | 0 .../serialization/SupportedSerializers.java | 0 .../lflang/federated/validation/FedValidator.java | 0 .../java}/org/lflang/formatting2/LFFormatter.java | 0 .../java}/org/lflang/generator/ActionInstance.java | 0 .../main/java}/org/lflang/generator/CodeBuilder.java | 0 .../src/main/java}/org/lflang/generator/CodeMap.java | 0 .../java}/org/lflang/generator/DeadlineInstance.java | 0 .../org/lflang/generator/DelayBodyGenerator.java | 0 .../org/lflang/generator/DiagnosticReporting.java | 0 .../org/lflang/generator/DockerComposeGenerator.java | 0 .../main/java}/org/lflang/generator/DockerData.java | 0 .../java}/org/lflang/generator/DockerGenerator.java | 0 .../lflang/generator/FedDockerComposeGenerator.java | 0 .../org/lflang/generator/GenerationException.java | 0 .../java}/org/lflang/generator/GeneratorBase.java | 0 .../lflang/generator/GeneratorCommandFactory.java | 0 .../org/lflang/generator/GeneratorExtensions.kt | 0 .../java}/org/lflang/generator/GeneratorResult.java | 0 .../java}/org/lflang/generator/GeneratorUtils.java | 0 .../java}/org/lflang/generator/GeneratorUtils.kt | 0 .../generator/HumanReadableReportingStrategy.java | 0 .../org/lflang/generator/IntegratedBuilder.java | 0 .../lflang/generator/InvalidLfSourceException.java | 0 .../org/lflang/generator/InvalidSourceException.java | 0 .../main/java}/org/lflang/generator/LFGenerator.java | 0 .../org/lflang/generator/LFGeneratorContext.java | 0 .../main/java}/org/lflang/generator/LFResource.java | 0 .../org/lflang/generator/LanguageRuntimeVersions.kt | 0 .../generator/LanguageServerErrorReporter.java | 0 .../org/lflang/generator/LfExpressionVisitor.java | 0 .../main/java}/org/lflang/generator/MainContext.java | 0 .../java}/org/lflang/generator/MixedRadixInt.java | 0 .../java}/org/lflang/generator/ModeInstance.java | 0 .../java}/org/lflang/generator/NamedInstance.java | 0 .../org/lflang/generator/ParameterInstance.java | 0 .../java}/org/lflang/generator/PortInstance.java | 0 .../main/java}/org/lflang/generator/Position.java | 0 .../src/main/java}/org/lflang/generator/Range.java | 0 .../java}/org/lflang/generator/ReactionInstance.java | 0 .../org/lflang/generator/ReactionInstanceGraph.java | 0 .../java}/org/lflang/generator/ReactorInstance.java | 0 .../java}/org/lflang/generator/RuntimeRange.java | 0 .../main/java}/org/lflang/generator/SendRange.java | 0 .../main/java}/org/lflang/generator/SubContext.java | 0 .../main/java}/org/lflang/generator/TargetTypes.java | 0 .../java}/org/lflang/generator/TimerInstance.java | 0 .../java}/org/lflang/generator/TriggerInstance.java | 0 .../UnsupportedGeneratorFeatureException.java | 0 .../org/lflang/generator/ValidationStrategy.java | 0 .../main/java}/org/lflang/generator/Validator.java | 0 .../java}/org/lflang/generator/WatchdogInstance.java | 0 .../org/lflang/generator/c/CActionGenerator.java | 0 .../org/lflang/generator/c/CCmakeGenerator.java | 0 .../main/java}/org/lflang/generator/c/CCompiler.java | 0 .../lflang/generator/c/CConstructorGenerator.java | 0 .../org/lflang/generator/c/CCoreFilesUtils.java | 0 .../org/lflang/generator/c/CDelayBodyGenerator.java | 0 .../org/lflang/generator/c/CDockerGenerator.java | 0 .../java}/org/lflang/generator/c/CFileConfig.java | 0 .../java}/org/lflang/generator/c/CGenerator.java | 0 .../lflang/generator/c/CMainFunctionGenerator.java | 0 .../org/lflang/generator/c/CMethodGenerator.java | 0 .../org/lflang/generator/c/CMixedRadixGenerator.java | 0 .../org/lflang/generator/c/CModesGenerator.java | 0 .../org/lflang/generator/c/CParameterGenerator.java | 0 .../java}/org/lflang/generator/c/CPortGenerator.java | 0 .../org/lflang/generator/c/CPreambleGenerator.java | 0 .../org/lflang/generator/c/CReactionGenerator.java | 0 .../generator/c/CReactorHeaderFileGenerator.java | 0 .../org/lflang/generator/c/CStateGenerator.java | 0 .../org/lflang/generator/c/CTimerGenerator.java | 0 .../org/lflang/generator/c/CTracingGenerator.java | 0 .../lflang/generator/c/CTriggerObjectsGenerator.java | 0 .../main/java}/org/lflang/generator/c/CTypes.java | 0 .../src/main/java}/org/lflang/generator/c/CUtil.java | 0 .../org/lflang/generator/c/CWatchdogGenerator.java | 0 .../generator/c/InteractingContainedReactors.java | 0 .../lflang/generator/c/TypeParameterizedReactor.java | 0 .../org/lflang/generator/cpp/CppActionGenerator.kt | 0 .../generator/cpp/CppAssembleMethodGenerator.kt | 0 .../lflang/generator/cpp/CppConnectionGenerator.kt | 0 .../java}/org/lflang/generator/cpp/CppExtensions.kt | 0 .../java}/org/lflang/generator/cpp/CppFileConfig.kt | 0 .../java}/org/lflang/generator/cpp/CppGenerator.kt | 0 .../org/lflang/generator/cpp/CppInstanceGenerator.kt | 0 .../org/lflang/generator/cpp/CppMethodGenerator.kt | 0 .../lflang/generator/cpp/CppParameterGenerator.kt | 0 .../org/lflang/generator/cpp/CppPlatformGenerator.kt | 0 .../org/lflang/generator/cpp/CppPortGenerator.kt | 0 .../org/lflang/generator/cpp/CppPreambleGenerator.kt | 0 .../org/lflang/generator/cpp/CppReactionGenerator.kt | 0 .../org/lflang/generator/cpp/CppReactorGenerator.kt | 0 .../org/lflang/generator/cpp/CppRos2Generator.kt | 0 .../org/lflang/generator/cpp/CppRos2NodeGenerator.kt | 0 .../lflang/generator/cpp/CppRos2PackageGenerator.kt | 0 .../generator/cpp/CppStandaloneCmakeGenerator.kt | 0 .../lflang/generator/cpp/CppStandaloneGenerator.kt | 0 .../generator/cpp/CppStandaloneMainGenerator.kt | 0 .../org/lflang/generator/cpp/CppStateGenerator.kt | 0 .../org/lflang/generator/cpp/CppTimerGenerator.kt | 0 .../main/java}/org/lflang/generator/cpp/CppTypes.kt | 0 .../java}/org/lflang/generator/cpp/CppValidator.kt | 0 .../org/lflang/generator/python/PyFileConfig.java | 0 .../java}/org/lflang/generator/python/PyUtil.java | 0 .../generator/python/PythonActionGenerator.java | 0 .../generator/python/PythonDelayBodyGenerator.java | 0 .../generator/python/PythonDockerGenerator.java | 0 .../org/lflang/generator/python/PythonGenerator.java | 0 .../lflang/generator/python/PythonInfoGenerator.java | 0 .../python/PythonMainFunctionGenerator.java | 0 .../generator/python/PythonMethodGenerator.java | 0 .../lflang/generator/python/PythonModeGenerator.java | 0 .../generator/python/PythonParameterGenerator.java | 0 .../lflang/generator/python/PythonPortGenerator.java | 0 .../generator/python/PythonPreambleGenerator.java | 0 .../generator/python/PythonReactionGenerator.java | 0 .../generator/python/PythonReactorGenerator.java | 0 .../generator/python/PythonStateGenerator.java | 0 .../org/lflang/generator/python/PythonTypes.java | 0 .../org/lflang/generator/python/PythonValidator.java | 0 .../lflang/generator/rust/CargoDependencySpec.java | 0 .../java}/org/lflang/generator/rust/PortEmitter.kt | 0 .../lflang/generator/rust/RustCargoTomlEmitter.kt | 0 .../java}/org/lflang/generator/rust/RustEmitter.kt | 0 .../org/lflang/generator/rust/RustEmitterBase.kt | 0 .../org/lflang/generator/rust/RustFileConfig.kt | 0 .../java}/org/lflang/generator/rust/RustGenerator.kt | 0 .../org/lflang/generator/rust/RustMainFileEmitter.kt | 0 .../java}/org/lflang/generator/rust/RustModel.kt | 0 .../org/lflang/generator/rust/RustReactorEmitter.kt | 0 .../org/lflang/generator/rust/RustTargetConfig.java | 0 .../java}/org/lflang/generator/rust/RustTypes.kt | 0 .../java}/org/lflang/generator/rust/RustValidator.kt | 0 .../org/lflang/generator/ts/TSActionGenerator.kt | 0 .../org/lflang/generator/ts/TSConnectionGenerator.kt | 0 .../lflang/generator/ts/TSConstructorGenerator.kt | 0 .../org/lflang/generator/ts/TSDelayBodyGenerator.kt | 0 .../org/lflang/generator/ts/TSDockerGenerator.java | 0 .../java}/org/lflang/generator/ts/TSExtensions.kt | 0 .../java}/org/lflang/generator/ts/TSFileConfig.kt | 0 .../java}/org/lflang/generator/ts/TSGenerator.kt | 0 .../lflang/generator/ts/TSImportPreambleGenerator.kt | 0 .../org/lflang/generator/ts/TSInstanceGenerator.kt | 0 .../org/lflang/generator/ts/TSParameterGenerator.kt | 0 .../generator/ts/TSParameterPreambleGenerator.kt | 0 .../java}/org/lflang/generator/ts/TSPortGenerator.kt | 0 .../org/lflang/generator/ts/TSReactionGenerator.kt | 0 .../org/lflang/generator/ts/TSReactorGenerator.kt | 0 .../org/lflang/generator/ts/TSStateGenerator.kt | 0 .../org/lflang/generator/ts/TSTimerGenerator.kt | 0 .../main/java}/org/lflang/generator/ts/TSTypes.java | 0 .../java}/org/lflang/generator/ts/TSValidator.kt | 0 .../main/java}/org/lflang/graph/DirectedGraph.java | 0 .../src/main/java}/org/lflang/graph/Graph.java | 0 .../java}/org/lflang/graph/InstantiationGraph.java | 0 .../main/java}/org/lflang/graph/NodeAnnotation.java | 0 .../main/java}/org/lflang/graph/NodeAnnotations.java | 0 .../main/java}/org/lflang/graph/PrecedenceGraph.java | 0 .../main/java}/org/lflang/graph/TopologyGraph.java | 0 .../src/main/java}/org/lflang/ide/LFIdeModule.java | 0 .../src/main/java}/org/lflang/ide/LFIdeSetup.java | 0 .../org/lflang/scoping/LFGlobalScopeProvider.java | 0 .../java}/org/lflang/scoping/LFScopeProvider.java | 0 .../org/lflang/scoping/LFScopeProviderImpl.java | 0 .../src/main/java}/org/lflang/util/ArduinoUtil.java | 0 .../src/main/java}/org/lflang/util/Averager.java | 0 .../main/java}/org/lflang/util/CollectionUtil.java | 0 .../src/main/java}/org/lflang/util/FileUtil.java | 0 .../src/main/java}/org/lflang/util/IteratorUtil.java | 0 .../src/main/java}/org/lflang/util/LFCommand.java | 0 .../src/main/java}/org/lflang/util/StringUtil.java | 0 .../lflang/util/TargetResourceNotFoundException.java | 0 .../java}/org/lflang/validation/AttributeSpec.java | 0 .../java}/org/lflang/validation/BaseLFValidator.java | 0 .../validation/LFNamesAreUniqueValidationHelper.java | 0 .../java}/org/lflang/validation/LFValidator.java | 0 .../lflang/validation/ValidatorErrorReporter.java | 0 settings.gradle | 2 +- 276 files changed, 13 insertions(+), 11 deletions(-) rename org.lflang/{ => core}/build.gradle (90%) rename org.lflang/{src => core/src/main/java}/org/lflang/AttributeUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/CommonExtensions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/DefaultErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/FileConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/FileConfigExtensions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/GenerateLinguaFranca.mwe2 (94%) rename org.lflang/{src => core/src/main/java}/org/lflang/InferredType.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LFResourceDescriptionStrategy.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LFResourceProvider.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LFRuntimeModule.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LFStandaloneSetup.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LFSyntaxErrorMessageProvider.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LinguaFranca.xtext (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/LocalStrings.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/MainConflictChecker.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ModelInfo.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/StringsBundle.properties (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/Target.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/TargetConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/TargetProperty.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/TimeUnit.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/TimeValue.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/ASTUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/AstExtensions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/AstTransformation.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/DelayedConnectionTransformation.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/FormattingUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/IsEqual.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/MalleableString.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/ToLf.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ast/ToText.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/CliBase.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/LFStandaloneModule.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/Lff.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/ReportingUtil.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/StandaloneErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/StandaloneIssueAcceptor.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/cli/VersionProvider.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/lsp/LFLanguageServer.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/lsp/LFLanguageServerExtension.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/lsp/LanguageDiagramServer.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/lsp/Progress.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/SynthesisRegistration.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/action/AbstractAction.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/action/FilterCycleAction.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/action/ShowCycleAction.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/CycleVisualization.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/ModeDiagrams.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/ReactorIcons.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/diagram/synthesis/util/UtilityExtensions.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/extensions/CExtension.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/extensions/CExtensionUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/extensions/FedTargetExtension.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/extensions/FedTargetExtensionFactory.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/extensions/PythonExtension.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/extensions/TSExtension.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedASTUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedConnectionInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedEmitter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedFileConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedImportEmitter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedMainEmitter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedPreambleEmitter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedReactorEmitter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedTargetConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedTargetEmitter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FedUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/FederateInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/LineAdjustingErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/generator/SynchronizedErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/launcher/BuildConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/launcher/CBuildConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/launcher/FedLauncherGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/launcher/PyBuildConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/launcher/RtiConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/launcher/TsBuildConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/serialization/FedNativePythonSerialization.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/serialization/FedROS2CPPSerialization.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/serialization/FedSerialization.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/serialization/SupportedSerializers.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/federated/validation/FedValidator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/formatting2/LFFormatter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ActionInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/CodeBuilder.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/CodeMap.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/DeadlineInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/DelayBodyGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/DiagnosticReporting.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/DockerComposeGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/DockerData.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/DockerGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/FedDockerComposeGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GenerationException.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GeneratorBase.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GeneratorCommandFactory.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GeneratorExtensions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GeneratorResult.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GeneratorUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/GeneratorUtils.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/HumanReadableReportingStrategy.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/IntegratedBuilder.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/InvalidLfSourceException.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/InvalidSourceException.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/LFGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/LFGeneratorContext.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/LFResource.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/LanguageRuntimeVersions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/LanguageServerErrorReporter.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/LfExpressionVisitor.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/MainContext.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/MixedRadixInt.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ModeInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/NamedInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ParameterInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/PortInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/Position.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/Range.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ReactionInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ReactionInstanceGraph.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ReactorInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/RuntimeRange.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/SendRange.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/SubContext.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/TargetTypes.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/TimerInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/TriggerInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/UnsupportedGeneratorFeatureException.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ValidationStrategy.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/Validator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/WatchdogInstance.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CActionGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CCmakeGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CCompiler.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CConstructorGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CCoreFilesUtils.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CDelayBodyGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CDockerGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CFileConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CMainFunctionGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CMethodGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CMixedRadixGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CModesGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CParameterGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CPortGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CPreambleGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CReactionGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CReactorHeaderFileGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CStateGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CTimerGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CTracingGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CTriggerObjectsGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CTypes.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/CWatchdogGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/InteractingContainedReactors.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/c/TypeParameterizedReactor.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppActionGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppConnectionGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppExtensions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppFileConfig.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppInstanceGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppMethodGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppParameterGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppPlatformGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppPortGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppPreambleGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppReactionGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppReactorGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppRos2Generator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppRos2NodeGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppRos2PackageGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppStandaloneGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppStateGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppTimerGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppTypes.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/cpp/CppValidator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PyFileConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PyUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonActionGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonDelayBodyGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonDockerGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonInfoGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonMainFunctionGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonMethodGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonModeGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonParameterGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonPortGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonPreambleGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonReactionGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonReactorGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonStateGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonTypes.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/python/PythonValidator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/CargoDependencySpec.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/PortEmitter.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustCargoTomlEmitter.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustEmitter.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustEmitterBase.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustFileConfig.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustMainFileEmitter.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustModel.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustReactorEmitter.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustTargetConfig.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustTypes.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/rust/RustValidator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSActionGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSConnectionGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSConstructorGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSDelayBodyGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSDockerGenerator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSExtensions.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSFileConfig.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSImportPreambleGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSInstanceGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSParameterGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSParameterPreambleGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSPortGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSReactionGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSReactorGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSStateGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSTimerGenerator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSTypes.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/generator/ts/TSValidator.kt (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/DirectedGraph.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/Graph.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/InstantiationGraph.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/NodeAnnotation.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/NodeAnnotations.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/PrecedenceGraph.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/graph/TopologyGraph.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ide/LFIdeModule.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/ide/LFIdeSetup.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/scoping/LFGlobalScopeProvider.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/scoping/LFScopeProvider.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/scoping/LFScopeProviderImpl.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/ArduinoUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/Averager.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/CollectionUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/FileUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/IteratorUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/LFCommand.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/StringUtil.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/util/TargetResourceNotFoundException.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/validation/AttributeSpec.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/validation/BaseLFValidator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/validation/LFNamesAreUniqueValidationHelper.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/validation/LFValidator.java (100%) rename org.lflang/{src => core/src/main/java}/org/lflang/validation/ValidatorErrorReporter.java (100%) diff --git a/.gitignore b/.gitignore index b075a77ad5..579afb6154 100644 --- a/.gitignore +++ b/.gitignore @@ -156,4 +156,4 @@ gradle-app.setting ### xtext artifaccts *.jar -org/lflang/model/ \ No newline at end of file +org.lflang/core/model/ \ No newline at end of file diff --git a/lfc/build.gradle b/lfc/build.gradle index 7dd8ee764b..7eb33a7223 100644 --- a/lfc/build.gradle +++ b/lfc/build.gradle @@ -41,7 +41,7 @@ dependencies { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } implementation group: 'info.picocli', name: 'picocli', version: picocliVersion - implementation project(':org.lflang') + implementation project(':org.lflang:core') } application { diff --git a/org.lflang/build.gradle b/org.lflang/core/build.gradle similarity index 90% rename from org.lflang/build.gradle rename to org.lflang/core/build.gradle index f93af170ad..92d4fb02aa 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/core/build.gradle @@ -6,13 +6,13 @@ plugins { sourceSets { main { java { - srcDirs = ['src', 'src-gen'] + srcDirs = ['src/main/java', 'src-gen'] } kotlin { - srcDirs = ['src', 'src-gen'] + srcDirs = ['src/main/java', 'src-gen'] } resources { - srcDirs = ['src-gen', 'src'] + srcDirs = ['src-gen', '../src/'] include 'lib/' include 'org/lflang/LF.xtextbin' include 'org/lflang/parser/antlr/internal/InternalLF.tokens' @@ -79,10 +79,10 @@ dependencies { tasks.register('generateXtextLanguage', JavaExec) { main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher' classpath = configurations.mwe2 - inputs.file "src/org/lflang/GenerateLinguaFranca.mwe2" - inputs.file "src/org/lflang/LinguaFranca.xtext" + inputs.file "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" + inputs.file "src/main/java/org/lflang/LinguaFranca.xtext" outputs.dir "src-gen" - args += "src/org/lflang/GenerateLinguaFranca.mwe2" + args += "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" args += "-p" args += "rootPath=/${projectDir}/.." } diff --git a/org.lflang/src/org/lflang/AttributeUtils.java b/org.lflang/core/src/main/java/org/lflang/AttributeUtils.java similarity index 100% rename from org.lflang/src/org/lflang/AttributeUtils.java rename to org.lflang/core/src/main/java/org/lflang/AttributeUtils.java diff --git a/org.lflang/src/org/lflang/CommonExtensions.kt b/org.lflang/core/src/main/java/org/lflang/CommonExtensions.kt similarity index 100% rename from org.lflang/src/org/lflang/CommonExtensions.kt rename to org.lflang/core/src/main/java/org/lflang/CommonExtensions.kt diff --git a/org.lflang/src/org/lflang/DefaultErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/DefaultErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/DefaultErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/DefaultErrorReporter.java diff --git a/org.lflang/src/org/lflang/ErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/ErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/ErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/ErrorReporter.java diff --git a/org.lflang/src/org/lflang/FileConfig.java b/org.lflang/core/src/main/java/org/lflang/FileConfig.java similarity index 100% rename from org.lflang/src/org/lflang/FileConfig.java rename to org.lflang/core/src/main/java/org/lflang/FileConfig.java diff --git a/org.lflang/src/org/lflang/FileConfigExtensions.kt b/org.lflang/core/src/main/java/org/lflang/FileConfigExtensions.kt similarity index 100% rename from org.lflang/src/org/lflang/FileConfigExtensions.kt rename to org.lflang/core/src/main/java/org/lflang/FileConfigExtensions.kt diff --git a/org.lflang/src/org/lflang/GenerateLinguaFranca.mwe2 b/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 similarity index 94% rename from org.lflang/src/org/lflang/GenerateLinguaFranca.mwe2 rename to org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 index bc16003991..c2b557c631 100644 --- a/org.lflang/src/org/lflang/GenerateLinguaFranca.mwe2 +++ b/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 @@ -4,7 +4,7 @@ import org.eclipse.xtext.xtext.generator.* import org.eclipse.xtext.xtext.generator.model.project.* var rootPath = ".." -var coreProject = "org.lflang" +var coreProject = "core" Workflow { component = XtextGenerator { @@ -15,13 +15,15 @@ Workflow { runtime = { enabled = true name = coreProject // generate core project + src = "src/main/java" } genericIde = { enabled = true name = coreProject // add into the core project + src = "src/main/java" } runtimeTest = { - enabled = true + enabled = false name = "org.lflang.tests" // generate into separate test project } // Only generate Eclipse infrastructure for the Epoch build (separate repository). diff --git a/org.lflang/src/org/lflang/InferredType.java b/org.lflang/core/src/main/java/org/lflang/InferredType.java similarity index 100% rename from org.lflang/src/org/lflang/InferredType.java rename to org.lflang/core/src/main/java/org/lflang/InferredType.java diff --git a/org.lflang/src/org/lflang/LFResourceDescriptionStrategy.java b/org.lflang/core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java similarity index 100% rename from org.lflang/src/org/lflang/LFResourceDescriptionStrategy.java rename to org.lflang/core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java diff --git a/org.lflang/src/org/lflang/LFResourceProvider.java b/org.lflang/core/src/main/java/org/lflang/LFResourceProvider.java similarity index 100% rename from org.lflang/src/org/lflang/LFResourceProvider.java rename to org.lflang/core/src/main/java/org/lflang/LFResourceProvider.java diff --git a/org.lflang/src/org/lflang/LFRuntimeModule.java b/org.lflang/core/src/main/java/org/lflang/LFRuntimeModule.java similarity index 100% rename from org.lflang/src/org/lflang/LFRuntimeModule.java rename to org.lflang/core/src/main/java/org/lflang/LFRuntimeModule.java diff --git a/org.lflang/src/org/lflang/LFStandaloneSetup.java b/org.lflang/core/src/main/java/org/lflang/LFStandaloneSetup.java similarity index 100% rename from org.lflang/src/org/lflang/LFStandaloneSetup.java rename to org.lflang/core/src/main/java/org/lflang/LFStandaloneSetup.java diff --git a/org.lflang/src/org/lflang/LFSyntaxErrorMessageProvider.java b/org.lflang/core/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java similarity index 100% rename from org.lflang/src/org/lflang/LFSyntaxErrorMessageProvider.java rename to org.lflang/core/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/core/src/main/java/org/lflang/LinguaFranca.xtext similarity index 100% rename from org.lflang/src/org/lflang/LinguaFranca.xtext rename to org.lflang/core/src/main/java/org/lflang/LinguaFranca.xtext diff --git a/org.lflang/src/org/lflang/LocalStrings.java b/org.lflang/core/src/main/java/org/lflang/LocalStrings.java similarity index 100% rename from org.lflang/src/org/lflang/LocalStrings.java rename to org.lflang/core/src/main/java/org/lflang/LocalStrings.java diff --git a/org.lflang/src/org/lflang/MainConflictChecker.java b/org.lflang/core/src/main/java/org/lflang/MainConflictChecker.java similarity index 100% rename from org.lflang/src/org/lflang/MainConflictChecker.java rename to org.lflang/core/src/main/java/org/lflang/MainConflictChecker.java diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/core/src/main/java/org/lflang/ModelInfo.java similarity index 100% rename from org.lflang/src/org/lflang/ModelInfo.java rename to org.lflang/core/src/main/java/org/lflang/ModelInfo.java diff --git a/org.lflang/src/org/lflang/StringsBundle.properties b/org.lflang/core/src/main/java/org/lflang/StringsBundle.properties similarity index 100% rename from org.lflang/src/org/lflang/StringsBundle.properties rename to org.lflang/core/src/main/java/org/lflang/StringsBundle.properties diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/core/src/main/java/org/lflang/Target.java similarity index 100% rename from org.lflang/src/org/lflang/Target.java rename to org.lflang/core/src/main/java/org/lflang/Target.java diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/core/src/main/java/org/lflang/TargetConfig.java similarity index 100% rename from org.lflang/src/org/lflang/TargetConfig.java rename to org.lflang/core/src/main/java/org/lflang/TargetConfig.java diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/core/src/main/java/org/lflang/TargetProperty.java similarity index 100% rename from org.lflang/src/org/lflang/TargetProperty.java rename to org.lflang/core/src/main/java/org/lflang/TargetProperty.java diff --git a/org.lflang/src/org/lflang/TimeUnit.java b/org.lflang/core/src/main/java/org/lflang/TimeUnit.java similarity index 100% rename from org.lflang/src/org/lflang/TimeUnit.java rename to org.lflang/core/src/main/java/org/lflang/TimeUnit.java diff --git a/org.lflang/src/org/lflang/TimeValue.java b/org.lflang/core/src/main/java/org/lflang/TimeValue.java similarity index 100% rename from org.lflang/src/org/lflang/TimeValue.java rename to org.lflang/core/src/main/java/org/lflang/TimeValue.java diff --git a/org.lflang/src/org/lflang/ast/ASTUtils.java b/org.lflang/core/src/main/java/org/lflang/ast/ASTUtils.java similarity index 100% rename from org.lflang/src/org/lflang/ast/ASTUtils.java rename to org.lflang/core/src/main/java/org/lflang/ast/ASTUtils.java diff --git a/org.lflang/src/org/lflang/ast/AstExtensions.kt b/org.lflang/core/src/main/java/org/lflang/ast/AstExtensions.kt similarity index 100% rename from org.lflang/src/org/lflang/ast/AstExtensions.kt rename to org.lflang/core/src/main/java/org/lflang/ast/AstExtensions.kt diff --git a/org.lflang/src/org/lflang/ast/AstTransformation.java b/org.lflang/core/src/main/java/org/lflang/ast/AstTransformation.java similarity index 100% rename from org.lflang/src/org/lflang/ast/AstTransformation.java rename to org.lflang/core/src/main/java/org/lflang/ast/AstTransformation.java diff --git a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java b/org.lflang/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java similarity index 100% rename from org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java rename to org.lflang/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java diff --git a/org.lflang/src/org/lflang/ast/FormattingUtils.java b/org.lflang/core/src/main/java/org/lflang/ast/FormattingUtils.java similarity index 100% rename from org.lflang/src/org/lflang/ast/FormattingUtils.java rename to org.lflang/core/src/main/java/org/lflang/ast/FormattingUtils.java diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/core/src/main/java/org/lflang/ast/IsEqual.java similarity index 100% rename from org.lflang/src/org/lflang/ast/IsEqual.java rename to org.lflang/core/src/main/java/org/lflang/ast/IsEqual.java diff --git a/org.lflang/src/org/lflang/ast/MalleableString.java b/org.lflang/core/src/main/java/org/lflang/ast/MalleableString.java similarity index 100% rename from org.lflang/src/org/lflang/ast/MalleableString.java rename to org.lflang/core/src/main/java/org/lflang/ast/MalleableString.java diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/core/src/main/java/org/lflang/ast/ToLf.java similarity index 100% rename from org.lflang/src/org/lflang/ast/ToLf.java rename to org.lflang/core/src/main/java/org/lflang/ast/ToLf.java diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/core/src/main/java/org/lflang/ast/ToText.java similarity index 100% rename from org.lflang/src/org/lflang/ast/ToText.java rename to org.lflang/core/src/main/java/org/lflang/ast/ToText.java diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/core/src/main/java/org/lflang/cli/CliBase.java similarity index 100% rename from org.lflang/src/org/lflang/cli/CliBase.java rename to org.lflang/core/src/main/java/org/lflang/cli/CliBase.java diff --git a/org.lflang/src/org/lflang/cli/LFStandaloneModule.java b/org.lflang/core/src/main/java/org/lflang/cli/LFStandaloneModule.java similarity index 100% rename from org.lflang/src/org/lflang/cli/LFStandaloneModule.java rename to org.lflang/core/src/main/java/org/lflang/cli/LFStandaloneModule.java diff --git a/org.lflang/src/org/lflang/cli/Lff.java b/org.lflang/core/src/main/java/org/lflang/cli/Lff.java similarity index 100% rename from org.lflang/src/org/lflang/cli/Lff.java rename to org.lflang/core/src/main/java/org/lflang/cli/Lff.java diff --git a/org.lflang/src/org/lflang/cli/ReportingUtil.kt b/org.lflang/core/src/main/java/org/lflang/cli/ReportingUtil.kt similarity index 100% rename from org.lflang/src/org/lflang/cli/ReportingUtil.kt rename to org.lflang/core/src/main/java/org/lflang/cli/ReportingUtil.kt diff --git a/org.lflang/src/org/lflang/cli/StandaloneErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/cli/StandaloneErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/cli/StandaloneErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/cli/StandaloneErrorReporter.java diff --git a/org.lflang/src/org/lflang/cli/StandaloneIssueAcceptor.java b/org.lflang/core/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java similarity index 100% rename from org.lflang/src/org/lflang/cli/StandaloneIssueAcceptor.java rename to org.lflang/core/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java diff --git a/org.lflang/src/org/lflang/cli/VersionProvider.java b/org.lflang/core/src/main/java/org/lflang/cli/VersionProvider.java similarity index 100% rename from org.lflang/src/org/lflang/cli/VersionProvider.java rename to org.lflang/core/src/main/java/org/lflang/cli/VersionProvider.java diff --git a/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServer.java b/org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/lsp/LFLanguageServer.java rename to org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java diff --git a/org.lflang/src/org/lflang/diagram/lsp/LFLanguageServerExtension.java b/org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/lsp/LFLanguageServerExtension.java rename to org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java diff --git a/org.lflang/src/org/lflang/diagram/lsp/LanguageDiagramServer.java b/org.lflang/core/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/lsp/LanguageDiagramServer.java rename to org.lflang/core/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java diff --git a/org.lflang/src/org/lflang/diagram/lsp/Progress.java b/org.lflang/core/src/main/java/org/lflang/diagram/lsp/Progress.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/lsp/Progress.java rename to org.lflang/core/src/main/java/org/lflang/diagram/lsp/Progress.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/SynthesisRegistration.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/SynthesisRegistration.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/AbstractAction.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/action/AbstractAction.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/FilterCycleAction.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/action/FilterCycleAction.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/action/ShowCycleAction.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/action/ShowCycleAction.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/CycleVisualization.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/CycleVisualization.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/ModeDiagrams.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/ModeDiagrams.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/ReactorIcons.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/ReactorIcons.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java diff --git a/org.lflang/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java b/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java similarity index 100% rename from org.lflang/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java rename to org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtension.java similarity index 100% rename from org.lflang/src/org/lflang/federated/extensions/CExtension.java rename to org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtension.java diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java similarity index 100% rename from org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java rename to org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java b/org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java similarity index 100% rename from org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java rename to org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java b/org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java similarity index 100% rename from org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java rename to org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java diff --git a/org.lflang/src/org/lflang/federated/extensions/PythonExtension.java b/org.lflang/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java similarity index 100% rename from org.lflang/src/org/lflang/federated/extensions/PythonExtension.java rename to org.lflang/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/core/src/main/java/org/lflang/federated/extensions/TSExtension.java similarity index 100% rename from org.lflang/src/org/lflang/federated/extensions/TSExtension.java rename to org.lflang/core/src/main/java/org/lflang/federated/extensions/TSExtension.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedASTUtils.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedConnectionInstance.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedConnectionInstance.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedEmitter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedEmitter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedEmitter.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedFileConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedFileConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedFileConfig.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedGenerator.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedGenerator.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedImportEmitter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedImportEmitter.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetConfig.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java diff --git a/org.lflang/src/org/lflang/federated/generator/FedUtils.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FedUtils.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FedUtils.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FedUtils.java diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/FederateInstance.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/FederateInstance.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/FederateInstance.java diff --git a/org.lflang/src/org/lflang/federated/generator/LineAdjustingErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/LineAdjustingErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java diff --git a/org.lflang/src/org/lflang/federated/generator/SynchronizedErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/federated/generator/SynchronizedErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java diff --git a/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/launcher/BuildConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/launcher/BuildConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/launcher/BuildConfig.java diff --git a/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/launcher/CBuildConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/launcher/CBuildConfig.java diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/core/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java rename to org.lflang/core/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java diff --git a/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java diff --git a/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/launcher/RtiConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/launcher/RtiConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/launcher/RtiConfig.java diff --git a/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java b/org.lflang/core/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java similarity index 100% rename from org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java rename to org.lflang/core/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java diff --git a/org.lflang/src/org/lflang/federated/serialization/FedNativePythonSerialization.java b/org.lflang/core/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java similarity index 100% rename from org.lflang/src/org/lflang/federated/serialization/FedNativePythonSerialization.java rename to org.lflang/core/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java diff --git a/org.lflang/src/org/lflang/federated/serialization/FedROS2CPPSerialization.java b/org.lflang/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java similarity index 100% rename from org.lflang/src/org/lflang/federated/serialization/FedROS2CPPSerialization.java rename to org.lflang/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java diff --git a/org.lflang/src/org/lflang/federated/serialization/FedSerialization.java b/org.lflang/core/src/main/java/org/lflang/federated/serialization/FedSerialization.java similarity index 100% rename from org.lflang/src/org/lflang/federated/serialization/FedSerialization.java rename to org.lflang/core/src/main/java/org/lflang/federated/serialization/FedSerialization.java diff --git a/org.lflang/src/org/lflang/federated/serialization/SupportedSerializers.java b/org.lflang/core/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java similarity index 100% rename from org.lflang/src/org/lflang/federated/serialization/SupportedSerializers.java rename to org.lflang/core/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java diff --git a/org.lflang/src/org/lflang/federated/validation/FedValidator.java b/org.lflang/core/src/main/java/org/lflang/federated/validation/FedValidator.java similarity index 100% rename from org.lflang/src/org/lflang/federated/validation/FedValidator.java rename to org.lflang/core/src/main/java/org/lflang/federated/validation/FedValidator.java diff --git a/org.lflang/src/org/lflang/formatting2/LFFormatter.java b/org.lflang/core/src/main/java/org/lflang/formatting2/LFFormatter.java similarity index 100% rename from org.lflang/src/org/lflang/formatting2/LFFormatter.java rename to org.lflang/core/src/main/java/org/lflang/formatting2/LFFormatter.java diff --git a/org.lflang/src/org/lflang/generator/ActionInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/ActionInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ActionInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/ActionInstance.java diff --git a/org.lflang/src/org/lflang/generator/CodeBuilder.java b/org.lflang/core/src/main/java/org/lflang/generator/CodeBuilder.java similarity index 100% rename from org.lflang/src/org/lflang/generator/CodeBuilder.java rename to org.lflang/core/src/main/java/org/lflang/generator/CodeBuilder.java diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/core/src/main/java/org/lflang/generator/CodeMap.java similarity index 100% rename from org.lflang/src/org/lflang/generator/CodeMap.java rename to org.lflang/core/src/main/java/org/lflang/generator/CodeMap.java diff --git a/org.lflang/src/org/lflang/generator/DeadlineInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/DeadlineInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/DeadlineInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/DeadlineInstance.java diff --git a/org.lflang/src/org/lflang/generator/DelayBodyGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/DelayBodyGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/DelayBodyGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/DelayBodyGenerator.java diff --git a/org.lflang/src/org/lflang/generator/DiagnosticReporting.java b/org.lflang/core/src/main/java/org/lflang/generator/DiagnosticReporting.java similarity index 100% rename from org.lflang/src/org/lflang/generator/DiagnosticReporting.java rename to org.lflang/core/src/main/java/org/lflang/generator/DiagnosticReporting.java diff --git a/org.lflang/src/org/lflang/generator/DockerComposeGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/DockerComposeGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/DockerComposeGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/DockerComposeGenerator.java diff --git a/org.lflang/src/org/lflang/generator/DockerData.java b/org.lflang/core/src/main/java/org/lflang/generator/DockerData.java similarity index 100% rename from org.lflang/src/org/lflang/generator/DockerData.java rename to org.lflang/core/src/main/java/org/lflang/generator/DockerData.java diff --git a/org.lflang/src/org/lflang/generator/DockerGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/DockerGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/DockerGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/DockerGenerator.java diff --git a/org.lflang/src/org/lflang/generator/FedDockerComposeGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/FedDockerComposeGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java diff --git a/org.lflang/src/org/lflang/generator/GenerationException.java b/org.lflang/core/src/main/java/org/lflang/generator/GenerationException.java similarity index 100% rename from org.lflang/src/org/lflang/generator/GenerationException.java rename to org.lflang/core/src/main/java/org/lflang/generator/GenerationException.java diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/core/src/main/java/org/lflang/generator/GeneratorBase.java similarity index 100% rename from org.lflang/src/org/lflang/generator/GeneratorBase.java rename to org.lflang/core/src/main/java/org/lflang/generator/GeneratorBase.java diff --git a/org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java b/org.lflang/core/src/main/java/org/lflang/generator/GeneratorCommandFactory.java similarity index 100% rename from org.lflang/src/org/lflang/generator/GeneratorCommandFactory.java rename to org.lflang/core/src/main/java/org/lflang/generator/GeneratorCommandFactory.java diff --git a/org.lflang/src/org/lflang/generator/GeneratorExtensions.kt b/org.lflang/core/src/main/java/org/lflang/generator/GeneratorExtensions.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/GeneratorExtensions.kt rename to org.lflang/core/src/main/java/org/lflang/generator/GeneratorExtensions.kt diff --git a/org.lflang/src/org/lflang/generator/GeneratorResult.java b/org.lflang/core/src/main/java/org/lflang/generator/GeneratorResult.java similarity index 100% rename from org.lflang/src/org/lflang/generator/GeneratorResult.java rename to org.lflang/core/src/main/java/org/lflang/generator/GeneratorResult.java diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.java similarity index 100% rename from org.lflang/src/org/lflang/generator/GeneratorUtils.java rename to org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.java diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.kt b/org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/GeneratorUtils.kt rename to org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.kt diff --git a/org.lflang/src/org/lflang/generator/HumanReadableReportingStrategy.java b/org.lflang/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java similarity index 100% rename from org.lflang/src/org/lflang/generator/HumanReadableReportingStrategy.java rename to org.lflang/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java diff --git a/org.lflang/src/org/lflang/generator/IntegratedBuilder.java b/org.lflang/core/src/main/java/org/lflang/generator/IntegratedBuilder.java similarity index 100% rename from org.lflang/src/org/lflang/generator/IntegratedBuilder.java rename to org.lflang/core/src/main/java/org/lflang/generator/IntegratedBuilder.java diff --git a/org.lflang/src/org/lflang/generator/InvalidLfSourceException.java b/org.lflang/core/src/main/java/org/lflang/generator/InvalidLfSourceException.java similarity index 100% rename from org.lflang/src/org/lflang/generator/InvalidLfSourceException.java rename to org.lflang/core/src/main/java/org/lflang/generator/InvalidLfSourceException.java diff --git a/org.lflang/src/org/lflang/generator/InvalidSourceException.java b/org.lflang/core/src/main/java/org/lflang/generator/InvalidSourceException.java similarity index 100% rename from org.lflang/src/org/lflang/generator/InvalidSourceException.java rename to org.lflang/core/src/main/java/org/lflang/generator/InvalidSourceException.java diff --git a/org.lflang/src/org/lflang/generator/LFGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/LFGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/LFGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/LFGenerator.java diff --git a/org.lflang/src/org/lflang/generator/LFGeneratorContext.java b/org.lflang/core/src/main/java/org/lflang/generator/LFGeneratorContext.java similarity index 100% rename from org.lflang/src/org/lflang/generator/LFGeneratorContext.java rename to org.lflang/core/src/main/java/org/lflang/generator/LFGeneratorContext.java diff --git a/org.lflang/src/org/lflang/generator/LFResource.java b/org.lflang/core/src/main/java/org/lflang/generator/LFResource.java similarity index 100% rename from org.lflang/src/org/lflang/generator/LFResource.java rename to org.lflang/core/src/main/java/org/lflang/generator/LFResource.java diff --git a/org.lflang/src/org/lflang/generator/LanguageRuntimeVersions.kt b/org.lflang/core/src/main/java/org/lflang/generator/LanguageRuntimeVersions.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/LanguageRuntimeVersions.kt rename to org.lflang/core/src/main/java/org/lflang/generator/LanguageRuntimeVersions.kt diff --git a/org.lflang/src/org/lflang/generator/LanguageServerErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/generator/LanguageServerErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java diff --git a/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java b/org.lflang/core/src/main/java/org/lflang/generator/LfExpressionVisitor.java similarity index 100% rename from org.lflang/src/org/lflang/generator/LfExpressionVisitor.java rename to org.lflang/core/src/main/java/org/lflang/generator/LfExpressionVisitor.java diff --git a/org.lflang/src/org/lflang/generator/MainContext.java b/org.lflang/core/src/main/java/org/lflang/generator/MainContext.java similarity index 100% rename from org.lflang/src/org/lflang/generator/MainContext.java rename to org.lflang/core/src/main/java/org/lflang/generator/MainContext.java diff --git a/org.lflang/src/org/lflang/generator/MixedRadixInt.java b/org.lflang/core/src/main/java/org/lflang/generator/MixedRadixInt.java similarity index 100% rename from org.lflang/src/org/lflang/generator/MixedRadixInt.java rename to org.lflang/core/src/main/java/org/lflang/generator/MixedRadixInt.java diff --git a/org.lflang/src/org/lflang/generator/ModeInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/ModeInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ModeInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/ModeInstance.java diff --git a/org.lflang/src/org/lflang/generator/NamedInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/NamedInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/NamedInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/NamedInstance.java diff --git a/org.lflang/src/org/lflang/generator/ParameterInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/ParameterInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ParameterInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/ParameterInstance.java diff --git a/org.lflang/src/org/lflang/generator/PortInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/PortInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/PortInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/PortInstance.java diff --git a/org.lflang/src/org/lflang/generator/Position.java b/org.lflang/core/src/main/java/org/lflang/generator/Position.java similarity index 100% rename from org.lflang/src/org/lflang/generator/Position.java rename to org.lflang/core/src/main/java/org/lflang/generator/Position.java diff --git a/org.lflang/src/org/lflang/generator/Range.java b/org.lflang/core/src/main/java/org/lflang/generator/Range.java similarity index 100% rename from org.lflang/src/org/lflang/generator/Range.java rename to org.lflang/core/src/main/java/org/lflang/generator/Range.java diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/ReactionInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ReactionInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/ReactionInstance.java diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/core/src/main/java/org/lflang/generator/ReactionInstanceGraph.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java rename to org.lflang/core/src/main/java/org/lflang/generator/ReactionInstanceGraph.java diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/ReactorInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ReactorInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/ReactorInstance.java diff --git a/org.lflang/src/org/lflang/generator/RuntimeRange.java b/org.lflang/core/src/main/java/org/lflang/generator/RuntimeRange.java similarity index 100% rename from org.lflang/src/org/lflang/generator/RuntimeRange.java rename to org.lflang/core/src/main/java/org/lflang/generator/RuntimeRange.java diff --git a/org.lflang/src/org/lflang/generator/SendRange.java b/org.lflang/core/src/main/java/org/lflang/generator/SendRange.java similarity index 100% rename from org.lflang/src/org/lflang/generator/SendRange.java rename to org.lflang/core/src/main/java/org/lflang/generator/SendRange.java diff --git a/org.lflang/src/org/lflang/generator/SubContext.java b/org.lflang/core/src/main/java/org/lflang/generator/SubContext.java similarity index 100% rename from org.lflang/src/org/lflang/generator/SubContext.java rename to org.lflang/core/src/main/java/org/lflang/generator/SubContext.java diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/core/src/main/java/org/lflang/generator/TargetTypes.java similarity index 100% rename from org.lflang/src/org/lflang/generator/TargetTypes.java rename to org.lflang/core/src/main/java/org/lflang/generator/TargetTypes.java diff --git a/org.lflang/src/org/lflang/generator/TimerInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/TimerInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/TimerInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/TimerInstance.java diff --git a/org.lflang/src/org/lflang/generator/TriggerInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/TriggerInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/TriggerInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/TriggerInstance.java diff --git a/org.lflang/src/org/lflang/generator/UnsupportedGeneratorFeatureException.java b/org.lflang/core/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java similarity index 100% rename from org.lflang/src/org/lflang/generator/UnsupportedGeneratorFeatureException.java rename to org.lflang/core/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java diff --git a/org.lflang/src/org/lflang/generator/ValidationStrategy.java b/org.lflang/core/src/main/java/org/lflang/generator/ValidationStrategy.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ValidationStrategy.java rename to org.lflang/core/src/main/java/org/lflang/generator/ValidationStrategy.java diff --git a/org.lflang/src/org/lflang/generator/Validator.java b/org.lflang/core/src/main/java/org/lflang/generator/Validator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/Validator.java rename to org.lflang/core/src/main/java/org/lflang/generator/Validator.java diff --git a/org.lflang/src/org/lflang/generator/WatchdogInstance.java b/org.lflang/core/src/main/java/org/lflang/generator/WatchdogInstance.java similarity index 100% rename from org.lflang/src/org/lflang/generator/WatchdogInstance.java rename to org.lflang/core/src/main/java/org/lflang/generator/WatchdogInstance.java diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CActionGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CActionGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CActionGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CCompiler.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CCompiler.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CCompiler.java diff --git a/org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CConstructorGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CConstructorGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java diff --git a/org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CDelayBodyGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CDockerGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CDockerGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CDockerGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CDockerGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CFileConfig.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CFileConfig.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CFileConfig.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CFileConfig.java diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CMethodGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CMethodGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CMethodGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CMethodGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CMixedRadixGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CMixedRadixGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CModesGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CModesGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CModesGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CModesGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CParameterGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CParameterGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CParameterGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CPortGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CPortGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CPortGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CPortGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CPreambleGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CReactionGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CStateGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CStateGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CStateGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CTimerGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CTimerGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CTimerGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CTracingGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CTracingGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CTypes.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CTypes.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CTypes.java diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CUtil.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CUtil.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CUtil.java diff --git a/org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/CWatchdogGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java diff --git a/org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java b/org.lflang/core/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/InteractingContainedReactors.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java similarity index 100% rename from org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java rename to org.lflang/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java diff --git a/org.lflang/src/org/lflang/generator/cpp/CppActionGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppActionGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppActionGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppActionGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppConnectionGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppConnectionGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppConnectionGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppExtensions.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppExtensions.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppFileConfig.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppFileConfig.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppFileConfig.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppFileConfig.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppInstanceGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppInstanceGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppMethodGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppMethodGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppParameterGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppParameterGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPlatformGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPlatformGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppPlatformGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPlatformGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPortGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppPortGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPortGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPreambleGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPreambleGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactionGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactionGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactorGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactorGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppRos2Generator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2Generator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppRos2Generator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2Generator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2NodeGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2NodeGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppRos2PackageGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2PackageGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppRos2PackageGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2PackageGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppStandaloneGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStateGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStateGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppTimerGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTimerGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppTimerGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTimerGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTypes.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppTypes.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTypes.kt diff --git a/org.lflang/src/org/lflang/generator/cpp/CppValidator.kt b/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppValidator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/cpp/CppValidator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/cpp/CppValidator.kt diff --git a/org.lflang/src/org/lflang/generator/python/PyFileConfig.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PyFileConfig.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PyFileConfig.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PyFileConfig.java diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PyUtil.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PyUtil.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PyUtil.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonActionGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonActionGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonActionGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonDelayBodyGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonDockerGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonDockerGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonInfoGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonInfoGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonMainFunctionGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonMainFunctionGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonMethodGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonModeGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonModeGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonModeGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonPortGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonPortGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonPortGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonReactorGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonStateGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonStateGenerator.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonTypes.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonTypes.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonTypes.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonTypes.java diff --git a/org.lflang/src/org/lflang/generator/python/PythonValidator.java b/org.lflang/core/src/main/java/org/lflang/generator/python/PythonValidator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/python/PythonValidator.java rename to org.lflang/core/src/main/java/org/lflang/generator/python/PythonValidator.java diff --git a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java b/org.lflang/core/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java rename to org.lflang/core/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java diff --git a/org.lflang/src/org/lflang/generator/rust/PortEmitter.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/PortEmitter.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/PortEmitter.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/PortEmitter.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustCargoTomlEmitter.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustCargoTomlEmitter.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustEmitter.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitter.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustEmitter.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitter.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitterBase.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitterBase.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustFileConfig.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustFileConfig.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustFileConfig.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustFileConfig.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustMainFileEmitter.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustMainFileEmitter.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustMainFileEmitter.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustMainFileEmitter.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustModel.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustModel.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustModel.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustReactorEmitter.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustReactorEmitter.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustTargetConfig.java b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustTargetConfig.java similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustTargetConfig.java rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustTargetConfig.java diff --git a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustTypes.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustTypes.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustTypes.kt diff --git a/org.lflang/src/org/lflang/generator/rust/RustValidator.kt b/org.lflang/core/src/main/java/org/lflang/generator/rust/RustValidator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/rust/RustValidator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/rust/RustValidator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSActionGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSActionGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSActionGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSActionGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSConnectionGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSConnectionGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSConnectionGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSConnectionGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSConstructorGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSConstructorGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSDelayBodyGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSDelayBodyGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java diff --git a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSExtensions.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSExtensions.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSExtensions.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSFileConfig.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSFileConfig.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSFileConfig.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSFileConfig.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSImportPreambleGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSImportPreambleGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSImportPreambleGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSImportPreambleGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSInstanceGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSInstanceGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterPreambleGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterPreambleGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSPortGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSPortGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSPortGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSPortGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactionGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactionGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactorGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactorGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSStateGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSStateGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSTimerGenerator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSTimerGenerator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSTimerGenerator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSTimerGenerator.kt diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.java b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSTypes.java similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSTypes.java rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSTypes.java diff --git a/org.lflang/src/org/lflang/generator/ts/TSValidator.kt b/org.lflang/core/src/main/java/org/lflang/generator/ts/TSValidator.kt similarity index 100% rename from org.lflang/src/org/lflang/generator/ts/TSValidator.kt rename to org.lflang/core/src/main/java/org/lflang/generator/ts/TSValidator.kt diff --git a/org.lflang/src/org/lflang/graph/DirectedGraph.java b/org.lflang/core/src/main/java/org/lflang/graph/DirectedGraph.java similarity index 100% rename from org.lflang/src/org/lflang/graph/DirectedGraph.java rename to org.lflang/core/src/main/java/org/lflang/graph/DirectedGraph.java diff --git a/org.lflang/src/org/lflang/graph/Graph.java b/org.lflang/core/src/main/java/org/lflang/graph/Graph.java similarity index 100% rename from org.lflang/src/org/lflang/graph/Graph.java rename to org.lflang/core/src/main/java/org/lflang/graph/Graph.java diff --git a/org.lflang/src/org/lflang/graph/InstantiationGraph.java b/org.lflang/core/src/main/java/org/lflang/graph/InstantiationGraph.java similarity index 100% rename from org.lflang/src/org/lflang/graph/InstantiationGraph.java rename to org.lflang/core/src/main/java/org/lflang/graph/InstantiationGraph.java diff --git a/org.lflang/src/org/lflang/graph/NodeAnnotation.java b/org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotation.java similarity index 100% rename from org.lflang/src/org/lflang/graph/NodeAnnotation.java rename to org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotation.java diff --git a/org.lflang/src/org/lflang/graph/NodeAnnotations.java b/org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotations.java similarity index 100% rename from org.lflang/src/org/lflang/graph/NodeAnnotations.java rename to org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotations.java diff --git a/org.lflang/src/org/lflang/graph/PrecedenceGraph.java b/org.lflang/core/src/main/java/org/lflang/graph/PrecedenceGraph.java similarity index 100% rename from org.lflang/src/org/lflang/graph/PrecedenceGraph.java rename to org.lflang/core/src/main/java/org/lflang/graph/PrecedenceGraph.java diff --git a/org.lflang/src/org/lflang/graph/TopologyGraph.java b/org.lflang/core/src/main/java/org/lflang/graph/TopologyGraph.java similarity index 100% rename from org.lflang/src/org/lflang/graph/TopologyGraph.java rename to org.lflang/core/src/main/java/org/lflang/graph/TopologyGraph.java diff --git a/org.lflang/src/org/lflang/ide/LFIdeModule.java b/org.lflang/core/src/main/java/org/lflang/ide/LFIdeModule.java similarity index 100% rename from org.lflang/src/org/lflang/ide/LFIdeModule.java rename to org.lflang/core/src/main/java/org/lflang/ide/LFIdeModule.java diff --git a/org.lflang/src/org/lflang/ide/LFIdeSetup.java b/org.lflang/core/src/main/java/org/lflang/ide/LFIdeSetup.java similarity index 100% rename from org.lflang/src/org/lflang/ide/LFIdeSetup.java rename to org.lflang/core/src/main/java/org/lflang/ide/LFIdeSetup.java diff --git a/org.lflang/src/org/lflang/scoping/LFGlobalScopeProvider.java b/org.lflang/core/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java similarity index 100% rename from org.lflang/src/org/lflang/scoping/LFGlobalScopeProvider.java rename to org.lflang/core/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProvider.java b/org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProvider.java similarity index 100% rename from org.lflang/src/org/lflang/scoping/LFScopeProvider.java rename to org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProvider.java diff --git a/org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java b/org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java similarity index 100% rename from org.lflang/src/org/lflang/scoping/LFScopeProviderImpl.java rename to org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java diff --git a/org.lflang/src/org/lflang/util/ArduinoUtil.java b/org.lflang/core/src/main/java/org/lflang/util/ArduinoUtil.java similarity index 100% rename from org.lflang/src/org/lflang/util/ArduinoUtil.java rename to org.lflang/core/src/main/java/org/lflang/util/ArduinoUtil.java diff --git a/org.lflang/src/org/lflang/util/Averager.java b/org.lflang/core/src/main/java/org/lflang/util/Averager.java similarity index 100% rename from org.lflang/src/org/lflang/util/Averager.java rename to org.lflang/core/src/main/java/org/lflang/util/Averager.java diff --git a/org.lflang/src/org/lflang/util/CollectionUtil.java b/org.lflang/core/src/main/java/org/lflang/util/CollectionUtil.java similarity index 100% rename from org.lflang/src/org/lflang/util/CollectionUtil.java rename to org.lflang/core/src/main/java/org/lflang/util/CollectionUtil.java diff --git a/org.lflang/src/org/lflang/util/FileUtil.java b/org.lflang/core/src/main/java/org/lflang/util/FileUtil.java similarity index 100% rename from org.lflang/src/org/lflang/util/FileUtil.java rename to org.lflang/core/src/main/java/org/lflang/util/FileUtil.java diff --git a/org.lflang/src/org/lflang/util/IteratorUtil.java b/org.lflang/core/src/main/java/org/lflang/util/IteratorUtil.java similarity index 100% rename from org.lflang/src/org/lflang/util/IteratorUtil.java rename to org.lflang/core/src/main/java/org/lflang/util/IteratorUtil.java diff --git a/org.lflang/src/org/lflang/util/LFCommand.java b/org.lflang/core/src/main/java/org/lflang/util/LFCommand.java similarity index 100% rename from org.lflang/src/org/lflang/util/LFCommand.java rename to org.lflang/core/src/main/java/org/lflang/util/LFCommand.java diff --git a/org.lflang/src/org/lflang/util/StringUtil.java b/org.lflang/core/src/main/java/org/lflang/util/StringUtil.java similarity index 100% rename from org.lflang/src/org/lflang/util/StringUtil.java rename to org.lflang/core/src/main/java/org/lflang/util/StringUtil.java diff --git a/org.lflang/src/org/lflang/util/TargetResourceNotFoundException.java b/org.lflang/core/src/main/java/org/lflang/util/TargetResourceNotFoundException.java similarity index 100% rename from org.lflang/src/org/lflang/util/TargetResourceNotFoundException.java rename to org.lflang/core/src/main/java/org/lflang/util/TargetResourceNotFoundException.java diff --git a/org.lflang/src/org/lflang/validation/AttributeSpec.java b/org.lflang/core/src/main/java/org/lflang/validation/AttributeSpec.java similarity index 100% rename from org.lflang/src/org/lflang/validation/AttributeSpec.java rename to org.lflang/core/src/main/java/org/lflang/validation/AttributeSpec.java diff --git a/org.lflang/src/org/lflang/validation/BaseLFValidator.java b/org.lflang/core/src/main/java/org/lflang/validation/BaseLFValidator.java similarity index 100% rename from org.lflang/src/org/lflang/validation/BaseLFValidator.java rename to org.lflang/core/src/main/java/org/lflang/validation/BaseLFValidator.java diff --git a/org.lflang/src/org/lflang/validation/LFNamesAreUniqueValidationHelper.java b/org.lflang/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java similarity index 100% rename from org.lflang/src/org/lflang/validation/LFNamesAreUniqueValidationHelper.java rename to org.lflang/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/core/src/main/java/org/lflang/validation/LFValidator.java similarity index 100% rename from org.lflang/src/org/lflang/validation/LFValidator.java rename to org.lflang/core/src/main/java/org/lflang/validation/LFValidator.java diff --git a/org.lflang/src/org/lflang/validation/ValidatorErrorReporter.java b/org.lflang/core/src/main/java/org/lflang/validation/ValidatorErrorReporter.java similarity index 100% rename from org.lflang/src/org/lflang/validation/ValidatorErrorReporter.java rename to org.lflang/core/src/main/java/org/lflang/validation/ValidatorErrorReporter.java diff --git a/settings.gradle b/settings.gradle index 94d44e8d96..8bfc40a9e1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = 'org.lflang' -include('org.lflang', 'lfc') +include(':org.lflang:core', 'lfc') From e715f412ae7c5551e77909fb1d547f86161a163f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 11:28:39 +0200 Subject: [PATCH 480/709] separate kotlin files --- org.lflang/core/build.gradle | 3 --- .../src/main/{java => kotlin}/org/lflang/CommonExtensions.kt | 0 .../main/{java => kotlin}/org/lflang/FileConfigExtensions.kt | 0 .../src/main/{java => kotlin}/org/lflang/ast/AstExtensions.kt | 0 .../src/main/{java => kotlin}/org/lflang/cli/ReportingUtil.kt | 0 .../org/lflang/generator/GeneratorExtensions.kt | 0 .../{java => kotlin}/org/lflang/generator/GeneratorUtils.kt | 0 .../org/lflang/generator/LanguageRuntimeVersions.kt | 0 .../org/lflang/generator/cpp/CppActionGenerator.kt | 0 .../org/lflang/generator/cpp/CppAssembleMethodGenerator.kt | 0 .../org/lflang/generator/cpp/CppConnectionGenerator.kt | 0 .../{java => kotlin}/org/lflang/generator/cpp/CppExtensions.kt | 0 .../{java => kotlin}/org/lflang/generator/cpp/CppFileConfig.kt | 0 .../{java => kotlin}/org/lflang/generator/cpp/CppGenerator.kt | 0 .../org/lflang/generator/cpp/CppInstanceGenerator.kt | 0 .../org/lflang/generator/cpp/CppMethodGenerator.kt | 0 .../org/lflang/generator/cpp/CppParameterGenerator.kt | 0 .../org/lflang/generator/cpp/CppPlatformGenerator.kt | 0 .../org/lflang/generator/cpp/CppPortGenerator.kt | 0 .../org/lflang/generator/cpp/CppPreambleGenerator.kt | 0 .../org/lflang/generator/cpp/CppReactionGenerator.kt | 0 .../org/lflang/generator/cpp/CppReactorGenerator.kt | 0 .../org/lflang/generator/cpp/CppRos2Generator.kt | 0 .../org/lflang/generator/cpp/CppRos2NodeGenerator.kt | 0 .../org/lflang/generator/cpp/CppRos2PackageGenerator.kt | 0 .../org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt | 0 .../org/lflang/generator/cpp/CppStandaloneGenerator.kt | 0 .../org/lflang/generator/cpp/CppStandaloneMainGenerator.kt | 0 .../org/lflang/generator/cpp/CppStateGenerator.kt | 0 .../org/lflang/generator/cpp/CppTimerGenerator.kt | 0 .../main/{java => kotlin}/org/lflang/generator/cpp/CppTypes.kt | 0 .../{java => kotlin}/org/lflang/generator/cpp/CppValidator.kt | 0 .../{java => kotlin}/org/lflang/generator/rust/PortEmitter.kt | 0 .../org/lflang/generator/rust/RustCargoTomlEmitter.kt | 0 .../{java => kotlin}/org/lflang/generator/rust/RustEmitter.kt | 0 .../org/lflang/generator/rust/RustEmitterBase.kt | 0 .../org/lflang/generator/rust/RustFileConfig.kt | 0 .../org/lflang/generator/rust/RustGenerator.kt | 0 .../org/lflang/generator/rust/RustMainFileEmitter.kt | 0 .../{java => kotlin}/org/lflang/generator/rust/RustModel.kt | 0 .../org/lflang/generator/rust/RustReactorEmitter.kt | 0 .../{java => kotlin}/org/lflang/generator/rust/RustTypes.kt | 0 .../org/lflang/generator/rust/RustValidator.kt | 0 .../org/lflang/generator/ts/TSActionGenerator.kt | 0 .../org/lflang/generator/ts/TSConnectionGenerator.kt | 0 .../org/lflang/generator/ts/TSConstructorGenerator.kt | 0 .../org/lflang/generator/ts/TSDelayBodyGenerator.kt | 0 .../{java => kotlin}/org/lflang/generator/ts/TSExtensions.kt | 0 .../{java => kotlin}/org/lflang/generator/ts/TSFileConfig.kt | 0 .../{java => kotlin}/org/lflang/generator/ts/TSGenerator.kt | 0 .../org/lflang/generator/ts/TSImportPreambleGenerator.kt | 0 .../org/lflang/generator/ts/TSInstanceGenerator.kt | 0 .../org/lflang/generator/ts/TSParameterGenerator.kt | 0 .../org/lflang/generator/ts/TSParameterPreambleGenerator.kt | 0 .../org/lflang/generator/ts/TSPortGenerator.kt | 0 .../org/lflang/generator/ts/TSReactionGenerator.kt | 0 .../org/lflang/generator/ts/TSReactorGenerator.kt | 0 .../org/lflang/generator/ts/TSStateGenerator.kt | 0 .../org/lflang/generator/ts/TSTimerGenerator.kt | 0 .../{java => kotlin}/org/lflang/generator/ts/TSValidator.kt | 0 60 files changed, 3 deletions(-) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/CommonExtensions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/FileConfigExtensions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/ast/AstExtensions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/cli/ReportingUtil.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/GeneratorExtensions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/GeneratorUtils.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/LanguageRuntimeVersions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppActionGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppConnectionGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppExtensions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppFileConfig.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppInstanceGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppMethodGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppParameterGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppPlatformGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppPortGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppPreambleGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppReactionGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppReactorGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppRos2Generator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppRos2NodeGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppRos2PackageGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppStandaloneGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppStateGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppTimerGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppTypes.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/cpp/CppValidator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/PortEmitter.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustCargoTomlEmitter.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustEmitter.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustEmitterBase.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustFileConfig.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustMainFileEmitter.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustModel.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustReactorEmitter.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustTypes.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/rust/RustValidator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSActionGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSConnectionGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSConstructorGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSDelayBodyGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSExtensions.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSFileConfig.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSImportPreambleGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSInstanceGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSParameterGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSParameterPreambleGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSPortGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSReactionGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSReactorGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSStateGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSTimerGenerator.kt (100%) rename org.lflang/core/src/main/{java => kotlin}/org/lflang/generator/ts/TSValidator.kt (100%) diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 92d4fb02aa..8a5a487299 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -8,9 +8,6 @@ sourceSets { java { srcDirs = ['src/main/java', 'src-gen'] } - kotlin { - srcDirs = ['src/main/java', 'src-gen'] - } resources { srcDirs = ['src-gen', '../src/'] include 'lib/' diff --git a/org.lflang/core/src/main/java/org/lflang/CommonExtensions.kt b/org.lflang/core/src/main/kotlin/org/lflang/CommonExtensions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/CommonExtensions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/CommonExtensions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/FileConfigExtensions.kt b/org.lflang/core/src/main/kotlin/org/lflang/FileConfigExtensions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/FileConfigExtensions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/FileConfigExtensions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/ast/AstExtensions.kt b/org.lflang/core/src/main/kotlin/org/lflang/ast/AstExtensions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/AstExtensions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/ast/AstExtensions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/cli/ReportingUtil.kt b/org.lflang/core/src/main/kotlin/org/lflang/cli/ReportingUtil.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/ReportingUtil.kt rename to org.lflang/core/src/main/kotlin/org/lflang/cli/ReportingUtil.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GeneratorExtensions.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GeneratorExtensions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/LanguageRuntimeVersions.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/LanguageRuntimeVersions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppActionGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppActionGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppConnectionGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppConnectionGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppExtensions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppFileConfig.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppFileConfig.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppInstanceGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppInstanceGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppMethodGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppMethodGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppParameterGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppParameterGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPlatformGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPlatformGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPortGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPortGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPreambleGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppPreambleGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactionGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppReactorGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2Generator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2Generator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2NodeGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2NodeGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2PackageGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppRos2PackageGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStateGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppStateGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTimerGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTimerGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTypes.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppTypes.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/cpp/CppValidator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/cpp/CppValidator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/PortEmitter.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/PortEmitter.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustCargoTomlEmitter.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustCargoTomlEmitter.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitter.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitter.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitterBase.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustEmitterBase.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustFileConfig.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustFileConfig.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustMainFileEmitter.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustMainFileEmitter.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustModel.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustModel.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustModel.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustModel.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustReactorEmitter.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustReactorEmitter.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustTypes.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustTypes.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustValidator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustValidator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSActionGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSActionGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSConnectionGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSConnectionGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSConstructorGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSConstructorGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSDelayBodyGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSDelayBodyGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSExtensions.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSExtensions.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSFileConfig.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSFileConfig.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSImportPreambleGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSImportPreambleGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSInstanceGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSInstanceGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterPreambleGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSParameterPreambleGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSPortGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSPortGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactionGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactorGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSReactorGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSStateGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSStateGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSTimerGenerator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSTimerGenerator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSValidator.kt b/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSValidator.kt rename to org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt From 3c0acbc84b3081ad9164df13a19bbc54f749bae7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 11:51:22 +0200 Subject: [PATCH 481/709] move all resources --- .gitmodules | 8 ++++---- org.lflang/core/build.gradle | 5 +---- .../services/de.cau.cs.kieler.klighd.IKlighdStartupHook | 0 .../{src => core/src/main/resources}/lib/c/reactor-c | 0 .../src/main/resources}/lib/cpp/3rd-party/cxxopts.hpp | 0 .../{src => core/src/main/resources}/lib/cpp/lfutil.hh | 0 .../{src => core/src/main/resources}/lib/cpp/reactor-cpp | 0 .../src/main/resources}/lib/cpp/time_parser.hh | 0 .../src/main/resources/lib/platform}/Kconfig | 0 .../src/main/resources/lib/platform}/boards/esp32.overlay | 0 .../lib/platform}/boards/nrf52dk_nrf52832_lf.conf | 0 .../src/main/resources/lib/platform}/prj_lf.conf | 0 .../resources/lib/py/lf-python-support}/lf-python-support | 0 .../{src => core/src/main/resources}/lib/rs/reactor-rs | 0 .../src/main/resources}/lib/rs/runtime-version.properties | 0 .../src/main/resources}/lib/ts/.eslintrc.json | 0 .../{src => core/src/main/resources}/lib/ts/README.md | 0 .../{src => core/src/main/resources}/lib/ts/package.json | 0 .../{src => core/src/main/resources}/lib/ts/tsconfig.json | 0 org.lflang/{src => todo}/log4j.xml | 0 20 files changed, 5 insertions(+), 8 deletions(-) rename org.lflang/{src => core/src/main/resources}/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook (100%) rename org.lflang/{src => core/src/main/resources}/lib/c/reactor-c (100%) rename org.lflang/{src => core/src/main/resources}/lib/cpp/3rd-party/cxxopts.hpp (100%) rename org.lflang/{src => core/src/main/resources}/lib/cpp/lfutil.hh (100%) rename org.lflang/{src => core/src/main/resources}/lib/cpp/reactor-cpp (100%) rename org.lflang/{src => core/src/main/resources}/lib/cpp/time_parser.hh (100%) rename org.lflang/{src/lib/platform/zephyr => core/src/main/resources/lib/platform}/Kconfig (100%) rename org.lflang/{src/lib/platform/zephyr => core/src/main/resources/lib/platform}/boards/esp32.overlay (100%) rename org.lflang/{src/lib/platform/zephyr => core/src/main/resources/lib/platform}/boards/nrf52dk_nrf52832_lf.conf (100%) rename org.lflang/{src/lib/platform/zephyr => core/src/main/resources/lib/platform}/prj_lf.conf (100%) rename org.lflang/{src/lib/py => core/src/main/resources/lib/py/lf-python-support}/lf-python-support (100%) rename org.lflang/{src => core/src/main/resources}/lib/rs/reactor-rs (100%) rename org.lflang/{src => core/src/main/resources}/lib/rs/runtime-version.properties (100%) rename org.lflang/{src => core/src/main/resources}/lib/ts/.eslintrc.json (100%) rename org.lflang/{src => core/src/main/resources}/lib/ts/README.md (100%) rename org.lflang/{src => core/src/main/resources}/lib/ts/package.json (100%) rename org.lflang/{src => core/src/main/resources}/lib/ts/tsconfig.json (100%) rename org.lflang/{src => todo}/log4j.xml (100%) diff --git a/.gitmodules b/.gitmodules index c66506c2af..0b655fae19 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ [submodule "org.lflang/src/lib/c/reactor-c"] - path = org.lflang/src/lib/c/reactor-c + path = org.lflang/core/src/main/resources/lib/c/reactor-c url = https://github.com/lf-lang/reactor-c.git [submodule "org.lflang/src/lib/cpp/reactor-cpp"] - path = org.lflang/src/lib/cpp/reactor-cpp + path = org.lflang/core/src/main/resources/lib/cpp/reactor-cpp url = https://github.com/lf-lang/reactor-cpp [submodule "org.lflang/src/lib/rs/reactor-rs"] - path = org.lflang/src/lib/rs/reactor-rs + path = org.lflang/core/src/main/resources/lib/rs/reactor-rs url = https://github.com/lf-lang/reactor-rs [submodule "org.lflang/src/lib/py/lf-python-support"] - path = org.lflang/src/lib/py/lf-python-support + path = org.lflang/core/src/main/resources/lib/py/lf-python-support/lf-python-support url = https://github.com/lf-lang/lf-python-support.git diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 8a5a487299..d2479c0795 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -9,10 +9,7 @@ sourceSets { srcDirs = ['src/main/java', 'src-gen'] } resources { - srcDirs = ['src-gen', '../src/'] - include 'lib/' - include 'org/lflang/LF.xtextbin' - include 'org/lflang/parser/antlr/internal/InternalLF.tokens' + srcDirs = ['src/main/resources', 'src-gen'] } } } diff --git a/org.lflang/src/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook b/org.lflang/core/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook similarity index 100% rename from org.lflang/src/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook rename to org.lflang/core/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/core/src/main/resources/lib/c/reactor-c similarity index 100% rename from org.lflang/src/lib/c/reactor-c rename to org.lflang/core/src/main/resources/lib/c/reactor-c diff --git a/org.lflang/src/lib/cpp/3rd-party/cxxopts.hpp b/org.lflang/core/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp similarity index 100% rename from org.lflang/src/lib/cpp/3rd-party/cxxopts.hpp rename to org.lflang/core/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp diff --git a/org.lflang/src/lib/cpp/lfutil.hh b/org.lflang/core/src/main/resources/lib/cpp/lfutil.hh similarity index 100% rename from org.lflang/src/lib/cpp/lfutil.hh rename to org.lflang/core/src/main/resources/lib/cpp/lfutil.hh diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/core/src/main/resources/lib/cpp/reactor-cpp similarity index 100% rename from org.lflang/src/lib/cpp/reactor-cpp rename to org.lflang/core/src/main/resources/lib/cpp/reactor-cpp diff --git a/org.lflang/src/lib/cpp/time_parser.hh b/org.lflang/core/src/main/resources/lib/cpp/time_parser.hh similarity index 100% rename from org.lflang/src/lib/cpp/time_parser.hh rename to org.lflang/core/src/main/resources/lib/cpp/time_parser.hh diff --git a/org.lflang/src/lib/platform/zephyr/Kconfig b/org.lflang/core/src/main/resources/lib/platform/Kconfig similarity index 100% rename from org.lflang/src/lib/platform/zephyr/Kconfig rename to org.lflang/core/src/main/resources/lib/platform/Kconfig diff --git a/org.lflang/src/lib/platform/zephyr/boards/esp32.overlay b/org.lflang/core/src/main/resources/lib/platform/boards/esp32.overlay similarity index 100% rename from org.lflang/src/lib/platform/zephyr/boards/esp32.overlay rename to org.lflang/core/src/main/resources/lib/platform/boards/esp32.overlay diff --git a/org.lflang/src/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf b/org.lflang/core/src/main/resources/lib/platform/boards/nrf52dk_nrf52832_lf.conf similarity index 100% rename from org.lflang/src/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf rename to org.lflang/core/src/main/resources/lib/platform/boards/nrf52dk_nrf52832_lf.conf diff --git a/org.lflang/src/lib/platform/zephyr/prj_lf.conf b/org.lflang/core/src/main/resources/lib/platform/prj_lf.conf similarity index 100% rename from org.lflang/src/lib/platform/zephyr/prj_lf.conf rename to org.lflang/core/src/main/resources/lib/platform/prj_lf.conf diff --git a/org.lflang/src/lib/py/lf-python-support b/org.lflang/core/src/main/resources/lib/py/lf-python-support/lf-python-support similarity index 100% rename from org.lflang/src/lib/py/lf-python-support rename to org.lflang/core/src/main/resources/lib/py/lf-python-support/lf-python-support diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/core/src/main/resources/lib/rs/reactor-rs similarity index 100% rename from org.lflang/src/lib/rs/reactor-rs rename to org.lflang/core/src/main/resources/lib/rs/reactor-rs diff --git a/org.lflang/src/lib/rs/runtime-version.properties b/org.lflang/core/src/main/resources/lib/rs/runtime-version.properties similarity index 100% rename from org.lflang/src/lib/rs/runtime-version.properties rename to org.lflang/core/src/main/resources/lib/rs/runtime-version.properties diff --git a/org.lflang/src/lib/ts/.eslintrc.json b/org.lflang/core/src/main/resources/lib/ts/.eslintrc.json similarity index 100% rename from org.lflang/src/lib/ts/.eslintrc.json rename to org.lflang/core/src/main/resources/lib/ts/.eslintrc.json diff --git a/org.lflang/src/lib/ts/README.md b/org.lflang/core/src/main/resources/lib/ts/README.md similarity index 100% rename from org.lflang/src/lib/ts/README.md rename to org.lflang/core/src/main/resources/lib/ts/README.md diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/core/src/main/resources/lib/ts/package.json similarity index 100% rename from org.lflang/src/lib/ts/package.json rename to org.lflang/core/src/main/resources/lib/ts/package.json diff --git a/org.lflang/src/lib/ts/tsconfig.json b/org.lflang/core/src/main/resources/lib/ts/tsconfig.json similarity index 100% rename from org.lflang/src/lib/ts/tsconfig.json rename to org.lflang/core/src/main/resources/lib/ts/tsconfig.json diff --git a/org.lflang/src/log4j.xml b/org.lflang/todo/log4j.xml similarity index 100% rename from org.lflang/src/log4j.xml rename to org.lflang/todo/log4j.xml From 98e2ba76c38e943ab3f52ee625a2235c0a4e6be3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 11:55:02 +0200 Subject: [PATCH 482/709] be more precise about xtext outputs --- org.lflang/core/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index d2479c0795..63b60d43e6 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -76,6 +76,8 @@ tasks.register('generateXtextLanguage', JavaExec) { inputs.file "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" inputs.file "src/main/java/org/lflang/LinguaFranca.xtext" outputs.dir "src-gen" + outputs.dir "model" + outputs.file ".antlr-generator-3.2.0-patch.jar" args += "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" args += "-p" args += "rootPath=/${projectDir}/.." From e7e586ce44122d9276e9c86d098746c8744c6506 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 13:56:14 +0200 Subject: [PATCH 483/709] create cli module --- gradle.properties | 1 + org.lflang/cli/base/build.gradle | 25 +++++++++++++++++ .../src/main/java/org/lflang/cli/CliBase.java | 0 .../org/lflang/cli/LFStandaloneModule.java | 0 .../src/main/java/org/lflang/cli/Lff.java | 0 .../lflang/cli/StandaloneErrorReporter.java | 0 .../lflang/cli/StandaloneIssueAcceptor.java | 0 .../java/org/lflang/cli/VersionProvider.java | 0 .../kotlin/org/lflang/cli/ReportingUtil.kt | 0 org.lflang/core/build.gradle | 28 ++++++++----------- settings.gradle | 4 +-- 11 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 org.lflang/cli/base/build.gradle rename org.lflang/{core => cli/base}/src/main/java/org/lflang/cli/CliBase.java (100%) rename org.lflang/{core => cli/base}/src/main/java/org/lflang/cli/LFStandaloneModule.java (100%) rename org.lflang/{core => cli/base}/src/main/java/org/lflang/cli/Lff.java (100%) rename org.lflang/{core => cli/base}/src/main/java/org/lflang/cli/StandaloneErrorReporter.java (100%) rename org.lflang/{core => cli/base}/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java (100%) rename org.lflang/{core => cli/base}/src/main/java/org/lflang/cli/VersionProvider.java (100%) rename org.lflang/{core => cli/base}/src/main/kotlin/org/lflang/cli/ReportingUtil.kt (100%) diff --git a/gradle.properties b/gradle.properties index 4b1302bdb8..abe6782af7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,7 @@ group=org.lflang version=0.4.1-SNAPSHOT [versions] +fasterxmlVersion=2.12.4 googleJavaFormatVersion=1.15.0 guiceVersion=5.1.0 gsonVersion=2.10.1 diff --git a/org.lflang/cli/base/build.gradle b/org.lflang/cli/base/build.gradle new file mode 100644 index 0000000000..717a4a6026 --- /dev/null +++ b/org.lflang/cli/base/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" + id 'java-library' +} + +compileKotlin { + kotlinOptions { + jvmTarget = kotlinJvmTarget + } +} +compileTestKotlin { + kotlinOptions { + jvmTarget = kotlinJvmTarget + } +} + +repositories { + mavenCentral() +} + +dependencies { + api "info.picocli:picocli:$picocliVersion" + + api project(':org.lflang:core') +} \ No newline at end of file diff --git a/org.lflang/core/src/main/java/org/lflang/cli/CliBase.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/CliBase.java rename to org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java diff --git a/org.lflang/core/src/main/java/org/lflang/cli/LFStandaloneModule.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/LFStandaloneModule.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/LFStandaloneModule.java rename to org.lflang/cli/base/src/main/java/org/lflang/cli/LFStandaloneModule.java diff --git a/org.lflang/core/src/main/java/org/lflang/cli/Lff.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/Lff.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/Lff.java rename to org.lflang/cli/base/src/main/java/org/lflang/cli/Lff.java diff --git a/org.lflang/core/src/main/java/org/lflang/cli/StandaloneErrorReporter.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/StandaloneErrorReporter.java rename to org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java rename to org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java diff --git a/org.lflang/core/src/main/java/org/lflang/cli/VersionProvider.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/VersionProvider.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/cli/VersionProvider.java rename to org.lflang/cli/base/src/main/java/org/lflang/cli/VersionProvider.java diff --git a/org.lflang/core/src/main/kotlin/org/lflang/cli/ReportingUtil.kt b/org.lflang/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/cli/ReportingUtil.kt rename to org.lflang/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 63b60d43e6..c8af09ec30 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -15,7 +15,6 @@ sourceSets { } compileKotlin { - destinationDir = compileJava.destinationDir kotlinOptions { jvmTarget = kotlinJvmTarget } @@ -35,27 +34,24 @@ repositories { } dependencies { - implementation "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}" - implementation "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:${xtextVersion}" - implementation "org.eclipse.xtext:org.eclipse.xtext.ide:${xtextVersion}" - // https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources - implementation group: 'org.eclipse.platform', name: 'org.eclipse.core.resources', version: "${resourcesVersion}" - // https://mvnrepository.com/artifact/org.eclipse.emf/org.eclipse.emf.mwe2.launch - implementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.mwe2.launch', version: "${mwe2LaunchVersion}" - // https://mvnrepository.com/artifact/org.eclipse.lsp4j/org.eclipse.lsp4j - implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: "${lsp4jVersion}" - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.4' - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.4' - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.4' - implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:${klighdVersion}") { + api "org.eclipse.xtext:org.eclipse.xtext:$xtextVersion" + api "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:$xtextVersion" + api "org.eclipse.xtext:org.eclipse.xtext.ide:$xtextVersion" + + implementation "org.eclipse.emf:org.eclipse.emf.mwe2.launch:$mwe2LaunchVersion" + + implementation "com.fasterxml.jackson.core:jackson-core:$fasterxmlVersion" + implementation "com.fasterxml.jackson.core:jackson-annotations:$fasterxmlVersion" + implementation "com.fasterxml.jackson.core:jackson-databind:$fasterxmlVersion" + + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:$klighdVersion") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } - implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:${klighdVersion}") { + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:$klighdVersion") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } - implementation group: 'info.picocli', name: 'picocli', version: picocliVersion } configurations { diff --git a/settings.gradle b/settings.gradle index 8bfc40a9e1..95c7b74b9e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,2 @@ rootProject.name = 'org.lflang' -include(':org.lflang:core', 'lfc') - - +include(':org.lflang:core', ':org.lflang:cli:base') From 1ed9d725dd150b9513d9a42bdacb4caa30dcf6a3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 14:04:31 +0200 Subject: [PATCH 484/709] move lfc and lff --- lfc/build.gradle | 52 ------------------- org.lflang/cli/lfc/build.gradle | 23 ++++++++ .../src/main/java}/org/lflang/cli/Lfc.java | 0 org.lflang/cli/lff/build.gradle | 23 ++++++++ .../src/main/java/org/lflang/cli/Lff.java | 0 settings.gradle | 2 +- 6 files changed, 47 insertions(+), 53 deletions(-) delete mode 100644 lfc/build.gradle create mode 100644 org.lflang/cli/lfc/build.gradle rename {lfc/src => org.lflang/cli/lfc/src/main/java}/org/lflang/cli/Lfc.java (100%) create mode 100644 org.lflang/cli/lff/build.gradle rename org.lflang/cli/{base => lff}/src/main/java/org/lflang/cli/Lff.java (100%) diff --git a/lfc/build.gradle b/lfc/build.gradle deleted file mode 100644 index 7eb33a7223..0000000000 --- a/lfc/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'java' - id 'application' -} - -sourceSets { - main { - java { - srcDirs = ['src'] - } - } -} - -repositories { - mavenCentral() - // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - } -} - -dependencies { - implementation "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}" - implementation "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:${xtextVersion}" - implementation "org.eclipse.xtext:org.eclipse.xtext.ide:${xtextVersion}" - // https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources - implementation group: 'org.eclipse.platform', name: 'org.eclipse.core.resources', version: "${resourcesVersion}" - // https://mvnrepository.com/artifact/org.eclipse.emf/org.eclipse.emf.mwe2.launch - implementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.mwe2.launch', version: "${mwe2LaunchVersion}" - // https://mvnrepository.com/artifact/org.eclipse.lsp4j/org.eclipse.lsp4j - implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: "${lsp4jVersion}" - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.4' - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.4' - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.4' - implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:${klighdVersion}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - } - implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:${klighdVersion}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - } - implementation group: 'info.picocli', name: 'picocli', version: picocliVersion - implementation project(':org.lflang:core') -} - -application { - mainClass = 'org.lflang.cli.Lfc' - tasks.run.workingDir = rootProject.projectDir -} - -build.finalizedBy installDist \ No newline at end of file diff --git a/org.lflang/cli/lfc/build.gradle b/org.lflang/cli/lfc/build.gradle new file mode 100644 index 0000000000..405f537fd7 --- /dev/null +++ b/org.lflang/cli/lfc/build.gradle @@ -0,0 +1,23 @@ +plugins { + id 'java' + id 'application' +} + +repositories { + mavenCentral() + // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. + maven { + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + } +} + +dependencies { + implementation project(':org.lflang:cli:base') +} + +application { + mainClass = 'org.lflang.cli.Lfc' + tasks.run.workingDir = rootProject.projectDir +} + +assemble.finalizedBy installDist \ No newline at end of file diff --git a/lfc/src/org/lflang/cli/Lfc.java b/org.lflang/cli/lfc/src/main/java/org/lflang/cli/Lfc.java similarity index 100% rename from lfc/src/org/lflang/cli/Lfc.java rename to org.lflang/cli/lfc/src/main/java/org/lflang/cli/Lfc.java diff --git a/org.lflang/cli/lff/build.gradle b/org.lflang/cli/lff/build.gradle new file mode 100644 index 0000000000..1d646903fd --- /dev/null +++ b/org.lflang/cli/lff/build.gradle @@ -0,0 +1,23 @@ +plugins { + id 'java' + id 'application' +} + +repositories { + mavenCentral() + // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. + maven { + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + } +} + +dependencies { + implementation project(':org.lflang:cli:base') +} + +application { + mainClass = 'org.lflang.cli.Lff' + tasks.run.workingDir = rootProject.projectDir +} + +assemble.finalizedBy installDist \ No newline at end of file diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/Lff.java b/org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java similarity index 100% rename from org.lflang/cli/base/src/main/java/org/lflang/cli/Lff.java rename to org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java diff --git a/settings.gradle b/settings.gradle index 95c7b74b9e..e6670589ce 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ rootProject.name = 'org.lflang' -include(':org.lflang:core', ':org.lflang:cli:base') +include(':org.lflang:core', ':org.lflang:cli:base', ':org.lflang:cli:lfc') From 7f92b826c4a93ab5d0bbe5e1504c1babbe7f723d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 15:12:02 +0200 Subject: [PATCH 485/709] use convention plugins --- buildSrc/build.gradle | 20 +++++++++++----- buildSrc/gradle.properties | 1 + .../groovy/org.lflang.java-application.gradle | 6 +++++ .../groovy/org.lflang.java-conventions.gradle | 11 +++++++++ ...org.lflang.java-library-conventions.gradle | 4 ++++ .../org.lflang.kotlin-conventions.gradle | 15 ++++++++++++ gradle.properties | 1 - org.lflang/cli/base/build.gradle | 19 ++------------- org.lflang/cli/lfc/build.gradle | 13 +---------- org.lflang/cli/lff/build.gradle | 11 +-------- org.lflang/core/build.gradle | 23 ++----------------- 11 files changed, 57 insertions(+), 67 deletions(-) create mode 100644 buildSrc/src/main/groovy/org.lflang.java-application.gradle create mode 100644 buildSrc/src/main/groovy/org.lflang.java-conventions.gradle create mode 100644 buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle create mode 100644 buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index d09084a499..162b911e9c 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,9 +1,17 @@ +plugins { + id 'groovy-gradle-plugin' +} + repositories { mavenCentral() - dependencies { - // https://mvnrepository.com/artifact/com.diffplug.spotless/spotless-lib - implementation group: 'com.diffplug.spotless', name: 'spotless-lib', version: spotlessLibVersion - // https://mvnrepository.com/artifact/com.diffplug.spotless/spotless-lib-extra - implementation group: 'com.diffplug.spotless', name: 'spotless-lib-extra', version: spotlessLibVersion - } + gradlePluginPortal() } + +dependencies { + // https://mvnrepository.com/artifact/com.diffplug.spotless/spotless-lib + implementation group: 'com.diffplug.spotless', name: 'spotless-lib', version: spotlessLibVersion + // https://mvnrepository.com/artifact/com.diffplug.spotless/spotless-lib-extra + implementation group: 'com.diffplug.spotless', name: 'spotless-lib-extra', version: spotlessLibVersion + + implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" +} \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties index 8591896bc2..ed9731fc68 100644 --- a/buildSrc/gradle.properties +++ b/buildSrc/gradle.properties @@ -1,2 +1,3 @@ [versions] spotlessLibVersion=2.30.0 +kotlinVersion=1.6.21 diff --git a/buildSrc/src/main/groovy/org.lflang.java-application.gradle b/buildSrc/src/main/groovy/org.lflang.java-application.gradle new file mode 100644 index 0000000000..2beb5c887c --- /dev/null +++ b/buildSrc/src/main/groovy/org.lflang.java-application.gradle @@ -0,0 +1,6 @@ +plugins { + id 'org.lflang.java-conventions' + id 'application' +} + +assemble.finalizedBy installDist \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle new file mode 100644 index 0000000000..ced3e9d24e --- /dev/null +++ b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle @@ -0,0 +1,11 @@ +plugins { + id 'java' +} + +repositories { + mavenCentral() + // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. + maven { + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle new file mode 100644 index 0000000000..a5c43751ee --- /dev/null +++ b/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle @@ -0,0 +1,4 @@ +plugins { + id 'org.lflang.java-conventions' + id 'java-library' +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle new file mode 100644 index 0000000000..d595e14b21 --- /dev/null +++ b/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle @@ -0,0 +1,15 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' +} + +compileKotlin { + kotlinOptions { + jvmTarget = kotlinJvmTarget + } +} + +compileTestKotlin { + kotlinOptions { + jvmTarget = kotlinJvmTarget + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index abe6782af7..f1290a2281 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,6 @@ jupiterVersion=5.8.2 jUnitPlatformVersion=1.8.2 jUnitVersion=4.13.2 kotlinJvmTarget=17 -kotlinVersion=1.6.20 lsp4jVersion=0.14.0 mwe2LaunchVersion=2.12.2 openTest4jVersion=1.2.0 diff --git a/org.lflang/cli/base/build.gradle b/org.lflang/cli/base/build.gradle index 717a4a6026..3623efd1a2 100644 --- a/org.lflang/cli/base/build.gradle +++ b/org.lflang/cli/base/build.gradle @@ -1,21 +1,6 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" - id 'java-library' -} - -compileKotlin { - kotlinOptions { - jvmTarget = kotlinJvmTarget - } -} -compileTestKotlin { - kotlinOptions { - jvmTarget = kotlinJvmTarget - } -} - -repositories { - mavenCentral() + id 'org.lflang.java-library-conventions' + id 'org.lflang.kotlin-conventions' } dependencies { diff --git a/org.lflang/cli/lfc/build.gradle b/org.lflang/cli/lfc/build.gradle index 405f537fd7..44416c2c47 100644 --- a/org.lflang/cli/lfc/build.gradle +++ b/org.lflang/cli/lfc/build.gradle @@ -1,14 +1,5 @@ plugins { - id 'java' - id 'application' -} - -repositories { - mavenCentral() - // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - } + id 'org.lflang.java-application' } dependencies { @@ -19,5 +10,3 @@ application { mainClass = 'org.lflang.cli.Lfc' tasks.run.workingDir = rootProject.projectDir } - -assemble.finalizedBy installDist \ No newline at end of file diff --git a/org.lflang/cli/lff/build.gradle b/org.lflang/cli/lff/build.gradle index 1d646903fd..ac8e928f06 100644 --- a/org.lflang/cli/lff/build.gradle +++ b/org.lflang/cli/lff/build.gradle @@ -1,14 +1,5 @@ plugins { - id 'java' - id 'application' -} - -repositories { - mavenCentral() - // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - } + id 'org.lflang.java-application' } dependencies { diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index c8af09ec30..f619dd967c 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" - id 'java-library' + id 'org.lflang.java-library-conventions' + id 'org.lflang.kotlin-conventions' } sourceSets { @@ -14,25 +14,6 @@ sourceSets { } } -compileKotlin { - kotlinOptions { - jvmTarget = kotlinJvmTarget - } -} -compileTestKotlin { - kotlinOptions { - jvmTarget = kotlinJvmTarget - } -} - -repositories { - mavenCentral() - // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - } -} - dependencies { api "org.eclipse.xtext:org.eclipse.xtext:$xtextVersion" api "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:$xtextVersion" From 269638d6b62f0bd8ac225cff04f5dc125a8ec1df Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 25 May 2023 07:01:00 -0700 Subject: [PATCH 486/709] Added test of documented STP_offset parameter --- test/C/src/federated/STPParameter.lf | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/C/src/federated/STPParameter.lf diff --git a/test/C/src/federated/STPParameter.lf b/test/C/src/federated/STPParameter.lf new file mode 100644 index 0000000000..0eb6788bfe --- /dev/null +++ b/test/C/src/federated/STPParameter.lf @@ -0,0 +1,57 @@ +target C { + timeout: 5 sec, + coordination: decentralized +} +import Count from "../lib/Count.lf" + +/* FIXME: inheritance not working! See issue #1733 +import TestCount from "../lib/TestCount.lf" + +reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { + timer t(0, 1 sec); + reaction(t) {= + lf_print("Timer ticked at (%lld, %d).", + lf_time_logical_elapsed(), lf_tag().microstep + ); + =} +} +* +*/ + +reactor PrintTimer(STP_offset:time = 1 sec, start: int = 1, stride: int = 1, num_inputs: int = 6) { + state count: int = start + state inputs_received: int = 0 + input in: int + + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count += self->stride; + self->inputs_received++; + =} + + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", + self->num_inputs, + self->inputs_received + ); + } + =} + + timer t(0, 1 sec); + reaction(t) {= + lf_print("Timer ticked at (%lld, %d).", + lf_time_logical_elapsed(), lf_tag().microstep + ); + =} +} + +federated reactor { + c = new Count(); + p = new PrintTimer(); + c.out -> p.in; +} From 08404b3f752d16c8057da34b845aaaa39fc49f08 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 16:21:52 +0200 Subject: [PATCH 487/709] move unit tests --- .gitignore | 1 + org.lflang/core/build.gradle | 31 +++++++++++++++++-- .../java/org/lflang/GenerateLinguaFranca.mwe2 | 6 ++-- .../java}/org/lflang/tests/Configurators.java | 0 .../java}/org/lflang/tests/LFParsingTest.java | 0 .../test/java}/org/lflang/tests/LFTest.java | 0 .../java}/org/lflang/tests/LfParsingUtil.java | 0 .../test/java}/org/lflang/tests/TestBase.java | 0 .../java}/org/lflang/tests/TestError.java | 0 .../java}/org/lflang/tests/TestRegistry.java | 0 .../tests/compiler/EquivalenceUnitTests.java | 0 .../tests/compiler/FormattingUnitTests.java | 0 .../tests/compiler/LetInferenceTests.java | 0 .../compiler/LinguaFrancaASTUtilsTest.java | 0 .../LinguaFrancaDependencyAnalysisTest.java | 0 .../compiler/LinguaFrancaParsingTest.java | 0 .../compiler/LinguaFrancaScopingTest.java | 0 .../compiler/LinguaFrancaValidationTest.java | 0 .../tests/compiler/MixedRadixIntTest.java | 0 .../tests/compiler/PortInstanceTests.java | 0 .../org/lflang/tests/compiler/RangeTests.java | 0 .../lflang/tests/compiler/RoundTripTests.java | 0 .../tests/compiler/TargetConfigTests.java | 3 +- .../org/lflang/tests/lsp/ErrorInserter.java | 0 .../java}/org/lflang/tests/lsp/LspTests.java | 0 .../lflang/tests/lsp/MockLanguageClient.java | 0 .../lflang/tests/lsp/MockReportProgress.java | 0 .../serialization/SerializationTest.java | 0 .../org/lflang/tests/util/StringUtilTest.java | 0 29 files changed, 36 insertions(+), 5 deletions(-) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/Configurators.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/LFParsingTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/LFTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/LfParsingUtil.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/TestBase.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/TestError.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/TestRegistry.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/EquivalenceUnitTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/FormattingUnitTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/LetInferenceTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/LinguaFrancaParsingTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/LinguaFrancaScopingTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/LinguaFrancaValidationTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/MixedRadixIntTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/PortInstanceTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/RangeTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/RoundTripTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/compiler/TargetConfigTests.java (98%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/lsp/ErrorInserter.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/lsp/LspTests.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/lsp/MockLanguageClient.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/lsp/MockReportProgress.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/serialization/SerializationTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/util/StringUtilTest.java (100%) diff --git a/.gitignore b/.gitignore index 579afb6154..a56607d25f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ **/build/ **/test-bin/ **/src-gen/ +**/test-gen/ **/fed-gen/ **/xtend-gen/ # Created by https://www.toptal.com/developers/gitignore/api/intellij,gradle,eclipse,maven,visualstudiocode diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index f619dd967c..8a290804a3 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -12,6 +12,11 @@ sourceSets { srcDirs = ['src/main/resources', 'src-gen'] } } + test { + java { + srcDirs = ['src/test/java', 'test-gen'] + } + } } dependencies { @@ -33,6 +38,14 @@ dependencies { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } + + testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } configurations { @@ -48,7 +61,7 @@ dependencies { } tasks.register('generateXtextLanguage', JavaExec) { - main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher' + mainClass = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher' classpath = configurations.mwe2 inputs.file "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" inputs.file "src/main/java/org/lflang/LinguaFranca.xtext" @@ -63,4 +76,18 @@ tasks.register('generateXtextLanguage', JavaExec) { compileJava.dependsOn(generateXtextLanguage) compileKotlin.dependsOn(generateXtextLanguage) processResources.dependsOn(generateXtextLanguage) -clean.dependsOn(cleanGenerateXtextLanguage) \ No newline at end of file +clean.dependsOn(cleanGenerateXtextLanguage) + +dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 b/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 index c2b557c631..3958d74d69 100644 --- a/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 +++ b/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 @@ -23,8 +23,10 @@ Workflow { src = "src/main/java" } runtimeTest = { - enabled = false - name = "org.lflang.tests" // generate into separate test project + enabled = true + name = coreProject // add into the core project + src = "src/test/java" + srcGen = "test-gen" } // Only generate Eclipse infrastructure for the Epoch build (separate repository). createEclipseMetaData = false diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang/core/src/test/java/org/lflang/tests/Configurators.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/Configurators.java rename to org.lflang/core/src/test/java/org/lflang/tests/Configurators.java diff --git a/org.lflang.tests/src/org/lflang/tests/LFParsingTest.java b/org.lflang/core/src/test/java/org/lflang/tests/LFParsingTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/LFParsingTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/LFParsingTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang/core/src/test/java/org/lflang/tests/LFTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/LFTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/LFTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/LfParsingUtil.java b/org.lflang/core/src/test/java/org/lflang/tests/LfParsingUtil.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/LfParsingUtil.java rename to org.lflang/core/src/test/java/org/lflang/tests/LfParsingUtil.java diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang/core/src/test/java/org/lflang/tests/TestBase.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/TestBase.java rename to org.lflang/core/src/test/java/org/lflang/tests/TestBase.java diff --git a/org.lflang.tests/src/org/lflang/tests/TestError.java b/org.lflang/core/src/test/java/org/lflang/tests/TestError.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/TestError.java rename to org.lflang/core/src/test/java/org/lflang/tests/TestError.java diff --git a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java b/org.lflang/core/src/test/java/org/lflang/tests/TestRegistry.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/TestRegistry.java rename to org.lflang/core/src/test/java/org/lflang/tests/TestRegistry.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/EquivalenceUnitTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/EquivalenceUnitTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaParsingTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaScopingTest.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaScopingTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/MixedRadixIntTest.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/MixedRadixIntTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/PortInstanceTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/PortInstanceTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RangeTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/RangeTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/RangeTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/RangeTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/RoundTripTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/RoundTripTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java b/org.lflang/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java similarity index 98% rename from org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java index e949ab6f9f..51f813befc 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java @@ -71,7 +71,8 @@ public void testFederation() throws Exception { parser.parse( """ target C { - tracing: true + tracing: true, + no-compile: true } reactor Foo { diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang/core/src/test/java/org/lflang/tests/lsp/ErrorInserter.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java rename to org.lflang/core/src/test/java/org/lflang/tests/lsp/ErrorInserter.java diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java b/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java rename to org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/MockLanguageClient.java b/org.lflang/core/src/test/java/org/lflang/tests/lsp/MockLanguageClient.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/lsp/MockLanguageClient.java rename to org.lflang/core/src/test/java/org/lflang/tests/lsp/MockLanguageClient.java diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java b/org.lflang/core/src/test/java/org/lflang/tests/lsp/MockReportProgress.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/lsp/MockReportProgress.java rename to org.lflang/core/src/test/java/org/lflang/tests/lsp/MockReportProgress.java diff --git a/org.lflang.tests/src/org/lflang/tests/serialization/SerializationTest.java b/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/serialization/SerializationTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/util/StringUtilTest.java b/org.lflang/core/src/test/java/org/lflang/tests/util/StringUtilTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/util/StringUtilTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/util/StringUtilTest.java From 5719ab4ea3a3b2496f39e7c2a454205778efdc87 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 25 May 2023 07:45:22 -0700 Subject: [PATCH 488/709] Formatted --- test/C/src/federated/STPParameter.lf | 44 +++++++++++++++------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/C/src/federated/STPParameter.lf b/test/C/src/federated/STPParameter.lf index 0eb6788bfe..701974748d 100644 --- a/test/C/src/federated/STPParameter.lf +++ b/test/C/src/federated/STPParameter.lf @@ -2,27 +2,30 @@ target C { timeout: 5 sec, coordination: decentralized } -import Count from "../lib/Count.lf" - -/* FIXME: inheritance not working! See issue #1733 -import TestCount from "../lib/TestCount.lf" -reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { - timer t(0, 1 sec); - reaction(t) {= - lf_print("Timer ticked at (%lld, %d).", - lf_time_logical_elapsed(), lf_tag().microstep - ); - =} -} -* -*/ +import Count from "../lib/Count.lf" -reactor PrintTimer(STP_offset:time = 1 sec, start: int = 1, stride: int = 1, num_inputs: int = 6) { +/** + * FIXME: inheritance not working! See issue #1733 import TestCount from + * "../lib/TestCount.lf" + * + * reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { timer t(0, + * 1 sec); reaction(t) {= lf_print("Timer ticked at (%lld, %d).", + * lf_time_logical_elapsed(), lf_tag().microstep ); + * =} } + */ +reactor PrintTimer( + STP_offset: time = 1 sec, + start: int = 1, + stride: int = 1, + num_inputs: int = 6 +) { state count: int = start state inputs_received: int = 0 input in: int + timer t(0, 1 sec) + reaction(in) {= lf_print("Received %d.", in->value); if (in->value != self->count) { @@ -41,17 +44,16 @@ reactor PrintTimer(STP_offset:time = 1 sec, start: int = 1, stride: int = 1, num ); } =} - - timer t(0, 1 sec); + reaction(t) {= - lf_print("Timer ticked at (%lld, %d).", + lf_print("Timer ticked at (%lld, %d).", lf_time_logical_elapsed(), lf_tag().microstep ); =} } federated reactor { - c = new Count(); - p = new PrintTimer(); - c.out -> p.in; + c = new Count() + p = new PrintTimer() + c.out -> p.in } From 0833859eddfbad5c6fa2e920934a12b45aa06cec Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 17:20:54 +0200 Subject: [PATCH 489/709] fix python submodule --- .gitmodules | 2 +- .../resources/lib/py/{lf-python-support => }/lf-python-support | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename org.lflang/core/src/main/resources/lib/py/{lf-python-support => }/lf-python-support (100%) diff --git a/.gitmodules b/.gitmodules index 0b655fae19..52c3af173b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,5 +8,5 @@ path = org.lflang/core/src/main/resources/lib/rs/reactor-rs url = https://github.com/lf-lang/reactor-rs [submodule "org.lflang/src/lib/py/lf-python-support"] - path = org.lflang/core/src/main/resources/lib/py/lf-python-support/lf-python-support + path = org.lflang/core/src/main/resources/lib/py/lf-python-support url = https://github.com/lf-lang/lf-python-support.git diff --git a/org.lflang/core/src/main/resources/lib/py/lf-python-support/lf-python-support b/org.lflang/core/src/main/resources/lib/py/lf-python-support similarity index 100% rename from org.lflang/core/src/main/resources/lib/py/lf-python-support/lf-python-support rename to org.lflang/core/src/main/resources/lib/py/lf-python-support From 306135ac0559e88c12ce302a8f755bed3502aa5e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 18:20:19 +0200 Subject: [PATCH 490/709] cli tests --- org.lflang/cli/base/build.gradle | 11 +++++++++++ .../org/lflang}/cli/CliToolTestFixture.java | 3 +-- .../java/org/lflang/cli}/TestUtils.java | 2 +- org.lflang/cli/lfc/build.gradle | 18 ++++++++++++++++++ .../test/java/org/lflang}/cli/LfcCliTest.java | 16 +++++++--------- .../org/lflang}/cli/LfcIssueReportingTest.kt | 12 ++++-------- .../test/resources/org/lflang}/cli/colors.lf | 0 .../resources/org/lflang}/cli/colors.stderr | 0 .../resources/org/lflang}/cli/emptyFile.lf | 0 .../resources/org/lflang}/cli/emptyFile.stderr | 0 .../test/resources/org/lflang}/cli/issue490.lf | 0 .../resources/org/lflang}/cli/issue490.stderr | 0 .../org/lflang}/cli/multilineWarning.lf | 0 .../org/lflang}/cli/multilineWarning.stderr | 0 .../org/lflang}/cli/multilineWarningTooBig.lf | 0 .../lflang}/cli/multilineWarningTooBig.stderr | 0 .../resources/org/lflang}/cli/simpleWarning.lf | 0 .../org/lflang}/cli/simpleWarning.stderr | 0 .../src/test/resources/org/lflang}/cli/tabs.lf | 0 .../test/resources/org/lflang}/cli/tabs.stderr | 0 .../org/lflang}/cli/twoLineWarning.lf | 0 .../org/lflang}/cli/twoLineWarning.stderr | 0 org.lflang/cli/lff/build.gradle | 17 ++++++++++++++++- .../test/java/org/lflang}/cli/LffCliTest.java | 10 ++++------ .../org/lflang/StringsBundle.properties | 0 settings.gradle | 2 +- 26 files changed, 63 insertions(+), 28 deletions(-) rename {org.lflang.tests/src/org/lflang/tests => org.lflang/cli/base/src/testFixtures/java/org/lflang}/cli/CliToolTestFixture.java (98%) rename {org.lflang.tests/src/org/lflang/tests => org.lflang/cli/base/src/testFixtures/java/org/lflang/cli}/TestUtils.java (99%) rename {org.lflang.tests/src/org/lflang/tests => org.lflang/cli/lfc/src/test/java/org/lflang}/cli/LfcCliTest.java (96%) rename {org.lflang.tests/src/org/lflang/tests => org.lflang/cli/lfc/src/test/kotlin/org/lflang}/cli/LfcIssueReportingTest.kt (94%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/colors.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/colors.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/emptyFile.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/emptyFile.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/issue490.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/issue490.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/multilineWarning.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/multilineWarning.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/multilineWarningTooBig.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/multilineWarningTooBig.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/simpleWarning.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/simpleWarning.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/tabs.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/tabs.stderr (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/twoLineWarning.lf (100%) rename {org.lflang.tests/resources/org/lflang/tests => org.lflang/cli/lfc/src/test/resources/org/lflang}/cli/twoLineWarning.stderr (100%) rename {org.lflang.tests/src/org/lflang/tests => org.lflang/cli/lff/src/test/java/org/lflang}/cli/LffCliTest.java (94%) rename org.lflang/core/src/main/{java => resources}/org/lflang/StringsBundle.properties (100%) diff --git a/org.lflang/cli/base/build.gradle b/org.lflang/cli/base/build.gradle index 3623efd1a2..e3b04fbf18 100644 --- a/org.lflang/cli/base/build.gradle +++ b/org.lflang/cli/base/build.gradle @@ -1,10 +1,21 @@ plugins { id 'org.lflang.java-library-conventions' id 'org.lflang.kotlin-conventions' + id 'java-test-fixtures' } dependencies { api "info.picocli:picocli:$picocliVersion" api project(':org.lflang:core') +} + +dependencies { + testFixturesImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testFixturesImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testFixturesImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testFixturesImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testFixturesImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } \ No newline at end of file diff --git a/org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java b/org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java similarity index 98% rename from org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java rename to org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java index 257da7ad06..eab8f1aa9c 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/CliToolTestFixture.java +++ b/org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java @@ -22,7 +22,7 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.lflang.tests.cli; +package org.lflang.cli; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,7 +33,6 @@ import java.io.PrintStream; import java.nio.file.Path; import org.hamcrest.Matcher; -import org.lflang.cli.Io; import org.opentest4j.AssertionFailedError; /** diff --git a/org.lflang.tests/src/org/lflang/tests/TestUtils.java b/org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java similarity index 99% rename from org.lflang.tests/src/org/lflang/tests/TestUtils.java rename to org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java index 9e7cb4218a..442742768f 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestUtils.java +++ b/org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java @@ -22,7 +22,7 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.lflang.tests; +package org.lflang.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/org.lflang/cli/lfc/build.gradle b/org.lflang/cli/lfc/build.gradle index 44416c2c47..a1be9d6244 100644 --- a/org.lflang/cli/lfc/build.gradle +++ b/org.lflang/cli/lfc/build.gradle @@ -1,12 +1,30 @@ plugins { id 'org.lflang.java-application' + id 'org.lflang.kotlin-conventions' } dependencies { implementation project(':org.lflang:cli:base') + + testImplementation(testFixtures(project(":org.lflang:cli:base"))) + testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } application { mainClass = 'org.lflang.cli.Lfc' tasks.run.workingDir = rootProject.projectDir } + +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + } +} \ No newline at end of file diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java b/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java similarity index 96% rename from org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java rename to org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java index d9e81a0e68..27d20c6083 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java +++ b/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java @@ -22,15 +22,15 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.lflang.tests.cli; +package org.lflang.cli; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.lflang.tests.TestUtils.TempDirBuilder.dirBuilder; -import static org.lflang.tests.TestUtils.TempDirChecker.dirChecker; -import static org.lflang.tests.TestUtils.isDirectory; -import static org.lflang.tests.TestUtils.isRegularFile; +import static org.lflang.cli.TestUtils.TempDirBuilder.dirBuilder; +import static org.lflang.cli.TestUtils.TempDirChecker.dirChecker; +import static org.lflang.cli.TestUtils.isDirectory; +import static org.lflang.cli.TestUtils.isRegularFile; import com.google.inject.Injector; import java.io.File; @@ -39,11 +39,9 @@ import java.util.Properties; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.lflang.LocalStrings; -import org.lflang.cli.Io; -import org.lflang.cli.Lfc; import org.lflang.generator.LFGeneratorContext.BuildParm; -import org.lflang.tests.TestUtils.TempDirBuilder; +import org.lflang.cli.TestUtils.TempDirBuilder; +import org.lflang.LocalStrings; /** * @author Clément Fournier diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LfcIssueReportingTest.kt b/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt similarity index 94% rename from org.lflang.tests/src/org/lflang/tests/cli/LfcIssueReportingTest.kt rename to org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt index a71af4581a..d8455bc7e9 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LfcIssueReportingTest.kt +++ b/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt @@ -21,17 +21,12 @@ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.lflang.tests.cli +package org.lflang.cli import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.lflang.LFRuntimeModule import org.lflang.LFStandaloneSetup -import org.lflang.cli.AnsiColors -import org.lflang.cli.Io -import org.lflang.cli.LFStandaloneModule -import org.lflang.cli.Lfc -import org.lflang.cli.ReportingBackend import org.opentest4j.AssertionFailedError import java.io.ByteArrayOutputStream import java.io.PrintStream @@ -124,7 +119,8 @@ class LfcIssueReportingTest { val packageName = loader.packageName.replace('.', '/') // relative to root of gradle project - val basePath = "org.lflang.tests/resources/$packageName/" + // TODO This should load the resources and copy them to a temp directory instead of reading directly + val basePath = "src/test/resources/$packageName/" val lfFile = Paths.get("$basePath/$fileBaseName.lf") val expectedPath = Paths.get("$basePath/$fileBaseName.stderr") @@ -155,6 +151,6 @@ class LfcIssueReportingTest { trim().replace(Regex("\\s+\\R"), "\n") // Replace file path with placeholder. File path is not // rendered the same on linux and windows (forward/backward slash) - .replace(lfFile.toString(), "%%%PATH.lf%%%") + .replace("%%%PATH.lf%%%", lfFile.toString()) } diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/colors.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/colors.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/colors.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/colors.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/emptyFile.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/emptyFile.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/emptyFile.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/emptyFile.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/issue490.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/issue490.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/issue490.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/issue490.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/multilineWarning.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/multilineWarning.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/multilineWarning.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/multilineWarning.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/multilineWarningTooBig.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/multilineWarningTooBig.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/multilineWarningTooBig.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/multilineWarningTooBig.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/simpleWarning.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/simpleWarning.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/simpleWarning.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/simpleWarning.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/tabs.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/tabs.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/tabs.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/tabs.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/twoLineWarning.lf b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/twoLineWarning.lf rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf diff --git a/org.lflang.tests/resources/org/lflang/tests/cli/twoLineWarning.stderr b/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr similarity index 100% rename from org.lflang.tests/resources/org/lflang/tests/cli/twoLineWarning.stderr rename to org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr diff --git a/org.lflang/cli/lff/build.gradle b/org.lflang/cli/lff/build.gradle index ac8e928f06..7d60a7eb32 100644 --- a/org.lflang/cli/lff/build.gradle +++ b/org.lflang/cli/lff/build.gradle @@ -4,6 +4,15 @@ plugins { dependencies { implementation project(':org.lflang:cli:base') + + testImplementation(testFixtures(project(":org.lflang:cli:base"))) + testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } application { @@ -11,4 +20,10 @@ application { tasks.run.workingDir = rootProject.projectDir } -assemble.finalizedBy installDist \ No newline at end of file +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + } +} \ No newline at end of file diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java b/org.lflang/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java similarity index 94% rename from org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java rename to org.lflang/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java index a9da20239f..e7523ce4fe 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java +++ b/org.lflang/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java @@ -22,12 +22,12 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.lflang.tests.cli; +package org.lflang.cli; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; -import static org.lflang.tests.TestUtils.TempDirBuilder.dirBuilder; -import static org.lflang.tests.TestUtils.TempDirChecker.dirChecker; +import static org.lflang.cli.TestUtils.TempDirBuilder.dirBuilder; +import static org.lflang.cli.TestUtils.TempDirChecker.dirChecker; import java.io.File; import java.io.IOException; @@ -35,9 +35,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.lflang.LocalStrings; -import org.lflang.cli.Io; -import org.lflang.cli.Lff; -import org.lflang.tests.cli.CliToolTestFixture.ExecutionResult; +import org.lflang.cli.CliToolTestFixture.ExecutionResult; /** * @author Clément Fournier diff --git a/org.lflang/core/src/main/java/org/lflang/StringsBundle.properties b/org.lflang/core/src/main/resources/org/lflang/StringsBundle.properties similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/StringsBundle.properties rename to org.lflang/core/src/main/resources/org/lflang/StringsBundle.properties diff --git a/settings.gradle b/settings.gradle index e6670589ce..28c7dbf725 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ rootProject.name = 'org.lflang' -include(':org.lflang:core', ':org.lflang:cli:base', ':org.lflang:cli:lfc') +include(':org.lflang:core', ':org.lflang:cli:base', ':org.lflang:cli:lfc', ':org.lflang:cli:lff') From 1c1063f6605addcbe5ea6068006e9427d2233da5 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 18:32:32 +0200 Subject: [PATCH 491/709] test conventions --- ...flang.java-application-conventions.gradle} | 1 + ...org.lflang.java-library-conventions.gradle | 1 + .../groovy/org.lflang.test-conventions.gradle | 29 +++++++++++++++++++ org.lflang/cli/base/build.gradle | 11 ------- org.lflang/cli/lfc/build.gradle | 17 +---------- org.lflang/cli/lff/build.gradle | 2 +- org.lflang/core/build.gradle | 16 +--------- 7 files changed, 34 insertions(+), 43 deletions(-) rename buildSrc/src/main/groovy/{org.lflang.java-application.gradle => org.lflang.java-application-conventions.gradle} (73%) create mode 100644 buildSrc/src/main/groovy/org.lflang.test-conventions.gradle diff --git a/buildSrc/src/main/groovy/org.lflang.java-application.gradle b/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle similarity index 73% rename from buildSrc/src/main/groovy/org.lflang.java-application.gradle rename to buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle index 2beb5c887c..d8e3f5f76a 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-application.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle @@ -1,6 +1,7 @@ plugins { id 'org.lflang.java-conventions' id 'application' + id 'org.lflang.test-conventions' } assemble.finalizedBy installDist \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle index a5c43751ee..4f3b10c399 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle @@ -1,4 +1,5 @@ plugins { id 'org.lflang.java-conventions' id 'java-library' + id 'org.lflang.test-conventions' } \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle new file mode 100644 index 0000000000..1055ca0dbc --- /dev/null +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java-test-fixtures' +} + +dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" + + testFixturesImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" + testFixturesImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" + testFixturesImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" + testFixturesImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" + testFixturesImplementation "org.opentest4j:opentest4j:$openTest4jVersion" + testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" + testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" +} + +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + } +} \ No newline at end of file diff --git a/org.lflang/cli/base/build.gradle b/org.lflang/cli/base/build.gradle index e3b04fbf18..74939fc8f5 100644 --- a/org.lflang/cli/base/build.gradle +++ b/org.lflang/cli/base/build.gradle @@ -1,7 +1,6 @@ plugins { id 'org.lflang.java-library-conventions' id 'org.lflang.kotlin-conventions' - id 'java-test-fixtures' } dependencies { @@ -9,13 +8,3 @@ dependencies { api project(':org.lflang:core') } - -dependencies { - testFixturesImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" - testFixturesImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" - testFixturesImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" - testFixturesImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" - testFixturesImplementation "org.opentest4j:opentest4j:$openTest4jVersion" - testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" - testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" -} \ No newline at end of file diff --git a/org.lflang/cli/lfc/build.gradle b/org.lflang/cli/lfc/build.gradle index a1be9d6244..ca59afece9 100644 --- a/org.lflang/cli/lfc/build.gradle +++ b/org.lflang/cli/lfc/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.lflang.java-application' + id 'org.lflang.java-application-conventions' id 'org.lflang.kotlin-conventions' } @@ -7,24 +7,9 @@ dependencies { implementation project(':org.lflang:cli:base') testImplementation(testFixtures(project(":org.lflang:cli:base"))) - testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" - testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" - testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" - testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" - testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" - testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" - testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } application { mainClass = 'org.lflang.cli.Lfc' tasks.run.workingDir = rootProject.projectDir } - -test { - useJUnitPlatform() - testLogging { - events "passed", "skipped", "failed" - showStandardStreams = true - } -} \ No newline at end of file diff --git a/org.lflang/cli/lff/build.gradle b/org.lflang/cli/lff/build.gradle index 7d60a7eb32..711eadcc46 100644 --- a/org.lflang/cli/lff/build.gradle +++ b/org.lflang/cli/lff/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.lflang.java-application' + id 'org.lflang.java-application-conventions' } dependencies { diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 8a290804a3..06a1770b62 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -76,18 +76,4 @@ tasks.register('generateXtextLanguage', JavaExec) { compileJava.dependsOn(generateXtextLanguage) compileKotlin.dependsOn(generateXtextLanguage) processResources.dependsOn(generateXtextLanguage) -clean.dependsOn(cleanGenerateXtextLanguage) - -dependencies { - testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" - testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" - testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" - testImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion" - testImplementation "org.opentest4j:opentest4j:$openTest4jVersion" - testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion" - testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" -} - -test { - useJUnitPlatform() -} \ No newline at end of file +clean.dependsOn(cleanGenerateXtextLanguage) \ No newline at end of file From 2f4826b44acbfe5a9d45690119896ba1c2aa1396 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 25 May 2023 19:22:59 +0200 Subject: [PATCH 492/709] spotless --- build.gradle | 26 +++++++++++++++++++ buildSrc/build.gradle | 1 + buildSrc/gradle.properties | 1 + .../groovy/org.lflang.java-conventions.gradle | 14 +++++++++- .../src/main/java/lfformat/LfFormatStep.java | 17 +++++------- gradle.properties | 1 - .../test/java/org/lflang/cli/LfcCliTest.java | 4 +-- org.lflang/cli/lff/build.gradle | 2 +- org.lflang/core/build.gradle | 3 ++- 9 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 build.gradle diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..87eaec93ce --- /dev/null +++ b/build.gradle @@ -0,0 +1,26 @@ +import lfformat.LfFormatStep + +plugins { + id "com.diffplug.spotless" +} + +spotless { + format 'misc', { + // define the files to apply `misc` to + target '*.gradle', '*.md', '.gitignore' + + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // or spaces. Takes an integer argument if you don't like 4 + endWithNewline() + } + + format 'linguaFranca', { + addStep(LfFormatStep.create(project.projectDir)) + target 'test/*/src/**/*.lf' // you have to set the target manually + targetExclude 'test/**/failing/**' + } + +} + +spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 162b911e9c..972fd06a06 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -14,4 +14,5 @@ dependencies { implementation group: 'com.diffplug.spotless', name: 'spotless-lib-extra', version: spotlessLibVersion implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + implementation "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion" } \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties index ed9731fc68..149718da23 100644 --- a/buildSrc/gradle.properties +++ b/buildSrc/gradle.properties @@ -1,3 +1,4 @@ [versions] +spotlessVersion=6.11.0 spotlessLibVersion=2.30.0 kotlinVersion=1.6.21 diff --git a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle index ced3e9d24e..a600ba4ef8 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'com.diffplug.spotless' } repositories { @@ -8,4 +9,15 @@ repositories { maven { url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" } -} \ No newline at end of file +} + +spotless { + java { + targetExclude 'src-gen/**', 'test-gen/**' + // The following is quoted from https://github.com/google/google-java-format + // "Note: There is no configurability as to the formatter's algorithm for formatting. + // This is a deliberate design decision to unify our code formatting on a single format." + googleJavaFormat(googleJavaFormatVersion).reflowLongStrings() + formatAnnotations() + } +} diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 4fb6806dc0..5695dc2b1e 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -53,27 +53,22 @@ public String format( /** Run the formatter on the given file and return the resulting process handle. */ private Process runFormatter(File file) throws IOException { - final Path resourcePath = projectRoot.resolve(Path.of("org.lflang", "src", "org", "lflang")); - final ResourceBundle properties = - ResourceBundle.getBundle( - "StringsBundle", - Locale.getDefault(), - new URLClassLoader(new URL[] {resourcePath.toUri().toURL()})); final Path lffPath = Path.of( "org.lflang", + "cli", + "lff", "build", - "libs", - String.format("org.lflang-%s.jar", properties.getString("VERSION"))); + "install", + "lff", + "bin", + "lff"); // It looks silly to invoke Java from Java, but it is necessary in // order to break the circularity of needing the program to be built // in order for it to be built. return new ProcessBuilder( List.of( - "java", - "-cp", lffPath.toString(), - "org.lflang.cli.Lff", "--dry-run", file.getAbsoluteFile().toString())) .start(); diff --git a/gradle.properties b/gradle.properties index f1290a2281..732e9e6c38 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,6 @@ openTest4jVersion=1.2.0 picocliVersion=4.7.0 resourcesVersion=3.16.0 shadowJarVersion=7.1.2 -spotlessVersion=6.11.0 xtextGradleVersion=3.0.0 xtextVersion=2.28.0 klighdVersion=2.2.1-SNAPSHOT diff --git a/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java b/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java index 27d20c6083..48946eba55 100644 --- a/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java +++ b/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java @@ -39,9 +39,9 @@ import java.util.Properties; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.lflang.generator.LFGeneratorContext.BuildParm; -import org.lflang.cli.TestUtils.TempDirBuilder; import org.lflang.LocalStrings; +import org.lflang.cli.TestUtils.TempDirBuilder; +import org.lflang.generator.LFGeneratorContext.BuildParm; /** * @author Clément Fournier diff --git a/org.lflang/cli/lff/build.gradle b/org.lflang/cli/lff/build.gradle index 711eadcc46..b2a597fa05 100644 --- a/org.lflang/cli/lff/build.gradle +++ b/org.lflang/cli/lff/build.gradle @@ -26,4 +26,4 @@ test { events "passed", "skipped", "failed" showStandardStreams = true } -} \ No newline at end of file +} diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 06a1770b62..21b8e562b8 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -76,4 +76,5 @@ tasks.register('generateXtextLanguage', JavaExec) { compileJava.dependsOn(generateXtextLanguage) compileKotlin.dependsOn(generateXtextLanguage) processResources.dependsOn(generateXtextLanguage) -clean.dependsOn(cleanGenerateXtextLanguage) \ No newline at end of file +clean.dependsOn(cleanGenerateXtextLanguage) +spotlessJava.mustRunAfter(generateXtextLanguage) From 6aefb0e83127b6ddfa25e2dcb82c4616bbc6654d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 25 May 2023 10:25:39 -0700 Subject: [PATCH 493/709] Give jobs descriptive names. --- .github/workflows/build-trace-tools.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/c-zephyr-tests.yml | 2 +- .github/workflows/check-format.yml | 2 +- .github/workflows/cli-tests.yml | 2 +- .github/workflows/cpp-ros2-tests.yml | 4 ++-- .github/workflows/cpp-tests.yml | 2 +- .github/workflows/extract-ref.yml | 2 +- .github/workflows/latest-release.yml | 2 +- .github/workflows/lsp-tests.yml | 2 +- .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- .github/workflows/serialization-tests.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- .github/workflows/unit-tests.yml | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-trace-tools.yml b/.github/workflows/build-trace-tools.yml index 86d8724481..207fe4deb7 100644 --- a/.github/workflows/build-trace-tools.yml +++ b/.github/workflows/build-trace-tools.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - run: + build-trace-tools: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 767df01fa1..145bbbbdac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ on: workflow_dispatch: jobs: - run: + build-toolchain: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index ceb90159bc..873c81b871 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -22,7 +22,7 @@ on: type: boolean jobs: - run: + c-arduino: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 3b7a76feee..288dd54b6d 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -18,7 +18,7 @@ on: type: string jobs: - run: + c-zephyr: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index 8c022f90a5..2ecbb389fa 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -4,7 +4,7 @@ on: workflow_call: jobs: - run: + check-format: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 2a2c3e32e4..452b08faf6 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - run: + cli: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index 93054676b5..e48ea2e360 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -11,10 +11,10 @@ on: type: string jobs: - run: + cpp-ros2: runs-on: ubuntu-latest steps: - - name: Check out lingual-franca repository + - name: Check out lingua-franca repository uses: actions/checkout@v3 with: repository: lf-lang/lingua-franca diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 4b402ed845..aa138feaaf 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -15,7 +15,7 @@ on: type: boolean jobs: - run: + cpp: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/extract-ref.yml b/.github/workflows/extract-ref.yml index 78b3470ceb..c3c738048f 100644 --- a/.github/workflows/extract-ref.yml +++ b/.github/workflows/extract-ref.yml @@ -13,7 +13,7 @@ on: value: ${{ jobs.run.outputs.ref }} jobs: - run: + extract-ref: runs-on: ubuntu-latest outputs: ref: ${{ steps.read.outputs.ref }} diff --git a/.github/workflows/latest-release.yml b/.github/workflows/latest-release.yml index 2ce4fe03da..d327f8f722 100644 --- a/.github/workflows/latest-release.yml +++ b/.github/workflows/latest-release.yml @@ -18,7 +18,7 @@ on: workflow_dispatch: jobs: - run: + get-latest-release: runs-on: ubuntu-latest outputs: ref: ${{ steps.find.outputs.ref }} diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index 76ecd3f7eb..aa2fcd7f16 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - run: + lsp: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index e8ea1eac77..c4038d27af 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -18,7 +18,7 @@ on: type: boolean jobs: - run: + py: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index dae04b2dc8..f4bc181dda 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -21,7 +21,7 @@ on: type: boolean jobs: - run: + rs: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 89f1ad735c..dffbe83e1f 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -8,7 +8,7 @@ on: type: string jobs: - run: + serialization: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index c70a356a13..22379b2f5d 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - run: + ts: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index dd7613f8af..c8cbe1fd1f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - run: + unit-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} From bf4ac760e074e418e846d2550f232f1594be3cd2 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 25 May 2023 13:41:19 -0700 Subject: [PATCH 494/709] Try qemu_riscv32 instead --- org.lflang.tests/src/org/lflang/tests/Configurators.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index a5db8f2abf..9df77e134a 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -77,7 +77,7 @@ public static boolean makeZephyrCompatible(LFTest test) { test.getContext().getArgs().setProperty("tracing", "false"); test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; test.getContext().getTargetConfig().platformOptions.flash = false; - test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + test.getContext().getTargetConfig().platformOptions.board = "qemu_riscv32"; return true; } /** From 7e34bf104b8eb10d60d9ecbc6165fa4fe5a78922 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 25 May 2023 21:28:09 -0700 Subject: [PATCH 495/709] Fix for #1785 --- .../src/org/lflang/federated/generator/FedGenerator.java | 8 +++++++- org.lflang/src/org/lflang/generator/c/CGenerator.java | 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index 08a1fcf6e8..392f1f551e 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -161,6 +161,12 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws subContexts -> { createDockerFiles(context, subContexts); generateLaunchScript(); + // If an error has occurred during codegen of any federate, report it. + subContexts.forEach(c -> { + if (c.getErrorReporter().getErrorsOccurred()) { + context.getErrorReporter().reportError("Failure during code generation of " + c.getFileConfig().srcFile); + } + }); }); context.finish(Status.COMPILED, codeMapMap); @@ -321,7 +327,7 @@ public TargetConfig getTargetConfig() { try { compileThreadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (Exception e) { - Exceptions.sneakyThrow(e); + context.getErrorReporter().reportError("Failure during code generation."); } finally { finalizer.accept(subContexts); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e8606eee9a..cc3ccecc6f 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -416,9 +416,8 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { copyTargetFiles(); generateHeaders(); code.writeToFile(targetFile); - } catch (IOException e) { - //noinspection ThrowableNotThrown,ResultOfMethodCallIgnored - Exceptions.sneakyThrow(e); + } catch (Exception e) { + errorReporter.reportError(e.getMessage()); } // Create docker file. From 55c70ba431ff6e5e2fbe2a5955bbaaff6dfd8412 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 25 May 2023 21:33:26 -0700 Subject: [PATCH 496/709] Apply formatter --- .../lflang/federated/generator/FedGenerator.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index 392f1f551e..b59a390451 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -26,7 +26,6 @@ import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.util.RuntimeIOException; -import org.eclipse.xtext.xbase.lib.Exceptions; import org.lflang.ErrorReporter; import org.lflang.FileConfig; import org.lflang.LFStandaloneSetup; @@ -162,11 +161,15 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws createDockerFiles(context, subContexts); generateLaunchScript(); // If an error has occurred during codegen of any federate, report it. - subContexts.forEach(c -> { - if (c.getErrorReporter().getErrorsOccurred()) { - context.getErrorReporter().reportError("Failure during code generation of " + c.getFileConfig().srcFile); - } - }); + subContexts.forEach( + c -> { + if (c.getErrorReporter().getErrorsOccurred()) { + context + .getErrorReporter() + .reportError( + "Failure during code generation of " + c.getFileConfig().srcFile); + } + }); }); context.finish(Status.COMPILED, codeMapMap); From f47fe6f8a596b2389476839ba779cb77215d7dee Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 25 May 2023 22:20:35 -0700 Subject: [PATCH 497/709] Add detail to error message. I am not passing the error message through the error reporter, which is messy, but I think that is OK. This fault condition "should never happen" so if we reach it then the compiler is already misbehaving. --- .../src/org/lflang/federated/generator/FedGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index b59a390451..6656a489f8 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -330,7 +330,8 @@ public TargetConfig getTargetConfig() { try { compileThreadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (Exception e) { - context.getErrorReporter().reportError("Failure during code generation."); + context.getErrorReporter().reportError("Failure during code generation: " + e.getMessage()); + e.printStackTrace(); } finally { finalizer.accept(subContexts); } From c0f8ec88a30a91c28eb46f8219bc5c4b5e9820fa Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 25 May 2023 23:14:19 -0700 Subject: [PATCH 498/709] Rethrow RuntimeException --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index cc3ccecc6f..1c8988b86d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -73,6 +73,7 @@ import org.lflang.generator.ParameterInstance; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; +import org.lflang.generator.ReactionInstance.Runtime; import org.lflang.generator.ReactorInstance; import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; @@ -416,8 +417,11 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { copyTargetFiles(); generateHeaders(); code.writeToFile(targetFile); - } catch (Exception e) { + } catch (IOException e) { + errorReporter.reportError(e.getMessage()); + } catch (RuntimeException e) { errorReporter.reportError(e.getMessage()); + throw e; } // Create docker file. From 5121d64173651bb76dd5f9f0bde6564fc362e4d9 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 25 May 2023 23:39:12 -0700 Subject: [PATCH 499/709] Apply formatter --- org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 1c8988b86d..a8aeb271b5 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -73,7 +73,6 @@ import org.lflang.generator.ParameterInstance; import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; -import org.lflang.generator.ReactionInstance.Runtime; import org.lflang.generator.ReactorInstance; import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; From 2be77e07abc636824ee3bd2ff42bb0393857d6db Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 10:27:20 +0200 Subject: [PATCH 500/709] update launch scripts, remove unneeded scripts --- bin/build-lf-cli | 1 - bin/lfc | 2 +- bin/lfc.ps1 | 2 +- bin/lff | 2 +- bin/lff.ps1 | 2 +- bin/measure-lf-time | 196 ------------------ bin/run-lf-tests | 30 --- bin/run-lf-tests.ps1 | 16 -- bin/run-multiple-times | 6 - bin/run-multiple-times.ps1 | 7 - .../src/main/java/lfformat/LfFormatStep.java | 2 +- lib/scripts/build.sh | 117 ----------- lib/scripts/include.sh | 123 ----------- lib/scripts/launch.ps1 | 71 ------- {bin => util/scripts}/bump-versions | 0 {lib => util}/scripts/launch-fedsd.sh | 0 util/scripts/launch.ps1 | 39 ++++ {lib => util}/scripts/launch.sh | 16 +- 18 files changed, 54 insertions(+), 578 deletions(-) delete mode 120000 bin/build-lf-cli delete mode 100755 bin/measure-lf-time delete mode 100755 bin/run-lf-tests delete mode 100644 bin/run-lf-tests.ps1 delete mode 100755 bin/run-multiple-times delete mode 100644 bin/run-multiple-times.ps1 delete mode 100755 lib/scripts/build.sh delete mode 100644 lib/scripts/include.sh delete mode 100644 lib/scripts/launch.ps1 rename {bin => util/scripts}/bump-versions (100%) rename {lib => util}/scripts/launch-fedsd.sh (100%) create mode 100644 util/scripts/launch.ps1 rename {lib => util}/scripts/launch.sh (87%) diff --git a/bin/build-lf-cli b/bin/build-lf-cli deleted file mode 120000 index 55c54a4b7a..0000000000 --- a/bin/build-lf-cli +++ /dev/null @@ -1 +0,0 @@ -../lib/scripts/build.sh \ No newline at end of file diff --git a/bin/lfc b/bin/lfc index c22080b02d..1a3eb8bc0d 120000 --- a/bin/lfc +++ b/bin/lfc @@ -1 +1 @@ -../lib/scripts/launch.sh \ No newline at end of file +../util/scripts/launch.sh \ No newline at end of file diff --git a/bin/lfc.ps1 b/bin/lfc.ps1 index a09c91759c..90e6f9876a 100644 --- a/bin/lfc.ps1 +++ b/bin/lfc.ps1 @@ -4,6 +4,6 @@ # Usage: Usage: lfc [options] files... #========================================================== -$launchScript="$PSScriptRoot\..\lib\scripts\launch.ps1" +$launchScript="$PSScriptRoot\..\util\scripts\launch.ps1" # PS requires spattling: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Splatting?view=powershell-7.2 . $launchScript @args diff --git a/bin/lff b/bin/lff index c22080b02d..1a3eb8bc0d 120000 --- a/bin/lff +++ b/bin/lff @@ -1 +1 @@ -../lib/scripts/launch.sh \ No newline at end of file +../util/scripts/launch.sh \ No newline at end of file diff --git a/bin/lff.ps1 b/bin/lff.ps1 index d73b7357eb..54ce9397f4 100644 --- a/bin/lff.ps1 +++ b/bin/lff.ps1 @@ -4,6 +4,6 @@ # Usage: Usage: lff [options] files... #========================================================== -$launchScript="$PSScriptRoot\..\lib\scripts\launch.ps1" +$launchScript="$PSScriptRoot\..\util\scripts\launch.ps1" # PS requires spattling: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Splatting?view=powershell-7.2 . $launchScript @args diff --git a/bin/measure-lf-time b/bin/measure-lf-time deleted file mode 100755 index 2579c99fb1..0000000000 --- a/bin/measure-lf-time +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash - -#========================================================== -# Description: Measure the execution time of a given -# Lingua Franca program. This is achieved -# by running the binary for a number of times -# Author: Soroush Bateni -# Usage: measure-lf-time [options] file... -#========================================================== - -# FIXME: This script currently looks for "Elapsed physical time (in nsec):" -# which are only produced for the C and Python targets. - -# The column number of the time value in an LF program's output line that begins -# with "---- Elapsed physical time (in nsec)". This line is currently only -# printed at the end of the execution of a C or Python target program. -# Currently, the 7th column contains the time value: -# ---- Elapsed physical time (in nsec): xxx -# ^1 ^2 ^3 ^4 ^5 ^6 ^7 -time_col=7; - -set -euo pipefail - -# Print message explaining the arguments -function usage() { - echo "Usage: measure-lf-time [options] [Binary files]" - echo "Binary files: binaries for Lingua Franca programs." - echo "Options:" - echo " -n | --number-of-executions num Run the [generated] binary num times (default is 10)." - echo " -l | --log Store the output of the commands in directory called \"logs\"." - echo " -h | --help Display this information." - echo " -c | --command cmd Run a command a number of times instead of the binary." -} - -# Exit with message and error code 1. -function error_exit() { - 1>&2 echo "compilation terminated." - exit 1 -} - -# Report error. -function error() { - 1>&2 echo -e "\e[1mmeasure-lf-time: \e[31merror: \e[0m$1" -} - -# Report fatal error. -function fatal_error() { - 1>&2 echo -e "\e[1mmeasure-lf-time: \e[31mfatal error: \e[0m$1" -} - -# Report that the given file cannot be found. -function file_not_found() { - error "$1: No such file or directory" - no_files -} - -# Report that a value is missing after a given flag. -function missing_value() { - 1>&2 echo "missing value after flag: '"$1"'" - fatal_error "malformed arguments" -} - -# Process benchmark args -number_of_executions=10 -files=() -log=false -commands=() - -while [[ "$#" -gt 0 ]]; do - case $1 in - -n | --number-of-executions ) - opt=$1 - shift - if [[ $1 == -* ]]; then - missing_value $opt - error_exit - else - number_of_executions=$1 - fi - ;; - -h | --help ) - usage - exit 0 - ;; - -l | --log ) - log=true - ;; - -c | --command ) - opt=$1 - shift - if [[ $1 == -* ]]; then - missing_value $opt - error_exit - else - commands+=( "$1" ) - fi - ;; - -* ) - 1>&2 echo "Unknown parameter passed: $1" - usage - error_exit - ;; - * ) - if [[ -f "$1" ]]; then - files+=( $1 ) - else - file_not_found $1 - usage - error_exit - fi - esac - shift -done - -entries=${#files[@]} -if [ ${#commands[@]} -lt 1 ]; then - # If command is not given by the user - # check if the given binary file exists. - # Exit if no input files are given. - if [[ ${entries} -lt 1 ]]; then - fatal_error "no input files" - usage - error_exit - fi -else - entries=${#commands[@]} -fi - - -# Create a logs directory -mkdir -p logs; - -# Run benchmark for the given file entries. -for (( i=0; i<$entries; i++ )); do \ - command_to_execute="" - if [ ! ${#commands[@]} -lt 1 ]; then - command_to_execute="${commands[$i]}" - else - command_to_execute="${files[$i]}" - fi - benchmark=$(for k in $(eval echo {1..$number_of_executions}); do - $command_to_execute - done) - if [ "$log" = true ] ; then - name_with_spaces=${command_to_execute##*/} - echo "$benchmark" &> "logs/${name_with_spaces//[[:blank:]]/}-`date +"date-%m-%d-%Y-time-%H-%M-%S"`.log" - fi - - # Print the headers - awk 'BEGIN {printf "%-40s %-15s %-15s %-15s %-15s\n", "Benchmark (in nsecs)", "Average", "Minimum", "Maximum", "Median"}' - - results=$(echo "$benchmark" | grep "Elapsed physical time (in nsec):" | - awk -v time_col="$time_col" -v command_to_execute="$command_to_execute" ' - # In the beginning - !i++{ - # Remove the , in the number - gsub(/,/,"", $time_col); - # And set initial values of min and max - min=$time_col+0; - max=$time_col+0; - } - # Then - { - # Remove the , in the number - gsub(/,/,"",$time_col); - # Add numbers in each row to sum - sum+=$time_col; - # Calculate new min - min=($time_col+0<=0+min) ? $time_col:min; - # Calculate new max - max=($time_col+0>=0+max) ? $time_col:max; - } - # Print the results in the output - END { - printf "%-40s %-15s %-15s %-15s", command_to_execute, sum/NR, min, max - } - ') - median=$(echo "$benchmark" | grep "Elapsed physical time (in nsec):" | - awk -v time_col="$time_col" ' - { - # Remove the , in the number - gsub(/,/,"",$time_col); - # Store the physical execution time in result - # for each row - result[NR]=$time_col+0; - } - END { - if (NR % 2) { - printf " %-15s\n", result[(NR + 1) / 2]; - } else { - printf " %-15s\n", (result[(NR / 2)] + result[(NR / 2) + 1]) / 2.0; - } - } - ') - echo -e "$results$median" -done \ No newline at end of file diff --git a/bin/run-lf-tests b/bin/run-lf-tests deleted file mode 100755 index d5f3a501db..0000000000 --- a/bin/run-lf-tests +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -#========================================================== -# Description: Run all tests for a given LF target. -# Author: Marten Lohstroh -# Usage: run-lf-tests [TARGET] -#========================================================== - -pushd () { - command pushd "$@" > /dev/null -} - -popd () { - command popd "$@" > /dev/null -} - -if [ "$(dirname "$0")" == '.' ]; then - base="../"; -else - suffix=${0#$(dirname "$(dirname "$0")")/}; - base="${0%$suffix}"; -fi - -if [ "$1" == '' ]; then - echo "Usage: run-lf-tests [target]"; -else - pushd "$base" - ./gradlew clean test --tests org.lflang.tests.runtime."$1"Test - popd -fi diff --git a/bin/run-lf-tests.ps1 b/bin/run-lf-tests.ps1 deleted file mode 100644 index 4cce0aab1b..0000000000 --- a/bin/run-lf-tests.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -#========================================================== -# Description: Run all tests for a given LF target. -# Author: Christian Menard -# Usage: run-lf-tests [TARGET] -#========================================================== - -$base="$PSScriptRoot\.." - -if ($args.count -ne 1) { - Write-Host "Usage: run-lf-tests [target]" -} else { - $old_pwd = $pwd - cd $base - & .\gradlew.bat clean test --tests "org.lflang.tests.runtime.${args[0]}Test" - cd $old_pwd -} \ No newline at end of file diff --git a/bin/run-multiple-times b/bin/run-multiple-times deleted file mode 100755 index e2c08be133..0000000000 --- a/bin/run-multiple-times +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# A handy bash script that will run a command multiple times -# Usage: run-multiple-time command number_of_times -for k in $(eval echo {1..$2}); do - $1 -done \ No newline at end of file diff --git a/bin/run-multiple-times.ps1 b/bin/run-multiple-times.ps1 deleted file mode 100644 index ede1ca6ace..0000000000 --- a/bin/run-multiple-times.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -# A handy script that will run a command multiple times -# Usage: run-multiple-times.ps1 command number_of_times -$executable=$args[0] -$number_of_times=$args[1] -for (($k = 0); $k -lt $number_of_times; $k++) { - Invoke-Expression $executable -} diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 5695dc2b1e..fcc15feaf1 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -46,7 +46,7 @@ public String format( } int returnCode = p.waitFor(); if (returnCode != 0) { - throw new RuntimeException("Failed to reformat file."); + throw new RuntimeException("Failed to reformat file. Exit code: " + returnCode + " Output: " + output.toString()); } return output.toString(); } diff --git a/lib/scripts/build.sh b/lib/scripts/build.sh deleted file mode 100755 index 52cc403851..0000000000 --- a/lib/scripts/build.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -#============================================================================ -# Description: Build the Lingua Franca compiler. -# Authors: Marten Lohstroh, Mehrdad Niknami, Christian Menard -# Usage: build-lfc [options] [[-r | --run] [lfc-args]] -#============================================================================ - -#============================================================================ -# Preamble -#============================================================================ - -# Find the directory in which this script resides in a way that is compatible -# with MacOS, which has a `readlink` implementation that does not support the -# necessary `-f` flag to canonicalize by following every symlink in every -# component of the given name recursively. -# This solution, adapted from an example written by Geoff Nixon, ia POSIX- -# compliant and robust to symbolic links. If a chain of more than 1000 links -# is encountered, we return. - -if [[ "$0" == *build-lfc ]]; then - echo -e "\033[33mWarning; buid-lfc is deprecated! Please use build-lf-cli instead.\033[0m" -fi - -find_dir() ( - start_dir=$PWD - cd "$(dirname "$1")" - link=$(readlink "$(basename "$1")") - count=0 - while [ "${link}" ]; do - if [[ "${count}" -lt 1000 ]]; then - cd "$(dirname "${link}")" - link=$(readlink "$(basename "$1")") - ((count++)) - else - return - fi - done - real_path="$PWD/$(basename "$1")" - cd "${start_dir}" - echo `dirname "${real_path}"` -) - -# Report fatal error and exit. -function fatal_error() { - 1>&2 echo -e "\e[1mlfc: \e[31mfatal error: \e[0m$1" - exit 1 -} - -rel_path="/lib/scripts" -abs_path="$(find_dir "$0")" - -if [[ "${abs_path}" ]]; then - base=`dirname $(dirname ${abs_path})` - source "${base}/${rel_path}/include.sh" -else - fatal_error "Unable to determine absolute path to $0." -fi -#============================================================================ - -# Check whether sources are present and exit if they are not. -if [ ! "$(get_src_dir)" ]; then - fatal_error "Cannot find the Lingua Franca sources." -fi - -# Print message explaining the CLI args. -function usage() { - echo "Usage: build-lf-cli [options] [lfc-args]]" - echo "Options:" - echo " -c | --clean Build entirely from scratch." - echo " -h | --help Display this information." - echo " -o | --offline Use cached libraries." - echo " -s | --stacktrace Provide stacktrace of build errors." -} - -flags=" "; -clean=false -run=false -args=() -while [[ "$#" -gt 0 ]]; do - case $1 in - -o | --offline ) - flags=$flags"--offline " - ;; - -s | --stacktrace ) - flags=$flags"--stacktrace " - ;; - -c | --clean ) - clean=true - ;; - -h | --help ) - usage - exit 0 - ;; - *) - usage - exit 1 - ;; - esac - shift -done - -# Perform cleanup up if requested. -if [[ "${clean}" == "true" ]]; then - echo "Performing cleanup..." - "${base}/gradlew" -p "${base}" clean; -fi - -# Check if jar is missing or out-of-date compared to the sources. -find_cmd=find -# Do not use the built-in Windows 'find' command, which is different. -if [ "${OSTYPE}" = "msys" ]; then - find_cmd="/usr/bin/${FIND}" -fi - -jar_path="$(get_jar_path)" -"${base}/gradlew" ${flags} -p "${base}" buildAll diff --git a/lib/scripts/include.sh b/lib/scripts/include.sh deleted file mode 100644 index aa0a6ef065..0000000000 --- a/lib/scripts/include.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/bash - -#============================================================================ -# Description: Initialize an environment for Lingua Franca helper scripts. -# Authors: Marten Lohstroh, Mehrdad Niknami, Christian Menard -# Usage: Source this file at the beginning of other scripts to access -# the functions and variables defined in this script. -#============================================================================ - -# Set up the environment. - -# -e: Immediately exit if any command has a non-zero exit status. -# -u: Error on referencing unset variables. -# -o pipefail: Prevents errors in a pipeline from being masked. -set -euo pipefail - -[[ $(type -t fatal_error) == function ]] || echo "Warning: function 'fatal_error' is not defined." - -[[ "${base}" ]] || fatal_error "Unable to determine absolute path to $0." - -# Paths (relative to ${base}), which is assumed to have been set. -src_pkg_name="org.lflang" -src_pkg_path="${base}/${src_pkg_name}" -jar_build_path_pattern="${src_pkg_name}/build/libs/${src_pkg_name}-*.jar" -jar_release_path_pattern="lib/jars/${src_pkg_name}-*.jar" - -# Enter directory silently (without printing). -pushd() { - command pushd "$@" > /dev/null -} - -# Leave directory silently (without printing). -popd() { - command popd "$@" > /dev/null -} - -# Check whether the first argument is a directory, and return it if true. -function is_dir() { - if [ -d "${1}" ]; then - echo "${1}" - else - return - fi -} - -# Check whether the source directory exists, and return it if true. -function get_src_dir() { - echo `is_dir "${base}/${src_pkg_name}"` -} - -# If it exists, return a path to the Lingua Franca jar. -function get_jar_path() { - if [ "$(get_src_dir)" ]; then - jar_path_pattern="${jar_build_path_pattern}" - else - jar_path_pattern="${jar_release_path_pattern}" - fi - # echo Jar path pattern: "${base}"/${jar_path_pattern} - # Is there a file that matches our pattern? If so, return it. - if ls "${base}"/${jar_path_pattern} 1> /dev/null 2>&1; then - # Yes. Determine the precise path of the jar. - # Take the newest version if there are multiple jars. - echo "$(ls "${base}"/${jar_path_pattern} | sort -V | tail -n1)" - fi -} - -# Check if the given Java command (argument 1) points to the correct Java version. -# Throw a fatal error upon failure if argument 2 is nonzero. -function check_java_cmd { - semantic_version=$("$1" -version 2>&1 | awk -F '"' '/version/ {print $2}') - java_version=$(echo "$semantic_version" | awk -F. '{printf("%03d%03d",$1,$2);}') - # echo "Semantic version: $semantic_version" - # echo "Java version: $java_version" - if [ $java_version -lt 017000 ]; then - if [ $2 -gt 0 ]; then - fatal_error "JRE $semantic_version found but 1.17 or greater is required." - fi - echo "incorrect" - return - fi - echo "correct" -} - -# Lookup the JRE. -function lookup_jre() { - if [[ $(type -p java) != "" ]]; then - #echo Found java executable in PATH - for JAVA_PATH in $(type -a java); do - if [[ $(check_java_cmd "$JAVA_PATH" 0) == "correct" ]]; then - echo $JAVA_PATH - return - fi - done - echo "java" # This will result in failure - elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then - #echo Found java executable in JAVA_HOME - echo "$JAVA_HOME/bin/java" - else - fatal_error "JRE not found." - fi -} - -# Check whether the JRE version is high enough. Exit with an error if it is not. -function get_java_cmd { - java_cmd="$(lookup_jre)" - check_java_cmd $java_cmd 1 > /dev/null - echo ${java_cmd} -} - -# Find the jar and JRE, run the jar with the provided arguments, and exit. -function run_cli_tool_with_args { - # Find the jar; report error if it was not found. - jar_path="$(get_jar_path)" - - if [[ ! "${jar_path}" ]]; then - fatal_error "Cannot find the Lingua Franca jar." - fi - - # Launch the compiler. - java_cmd="$(get_java_cmd)" - "${java_cmd}" -cp "${jar_path}" "${main_class}" "$@"; - exit $? -} diff --git a/lib/scripts/launch.ps1 b/lib/scripts/launch.ps1 deleted file mode 100644 index 6864ef7c56..0000000000 --- a/lib/scripts/launch.ps1 +++ /dev/null @@ -1,71 +0,0 @@ -#========================================================== -# Description: Launch lfc or lff depending on the invoking script. -# Authors: Christian Menard, Peter Donovan, Ruomu Xu -# Usage: Usage: launch args... -# with invoker with name same as the programme to be invoked. -#========================================================== - -# If the invoker is Z:\nkamihara\lf\bin\lfc.ps1, $invokerName will strip out "lfc.ps1" and then get "lfc". -# See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2#myinvocation -$invokerPath = $MyInvocation.PSCommandPath -$invokerName = [System.IO.Path]::GetFileNameWithoutExtension("$(Split-Path -Path $invokerPath -Leaf -Resolve)") - -$mainClassTable = @{"lfc" = "org.lflang.cli.Lfc"; "lff" = "org.lflang.cli.Lff"} -$mainClassName = $null -foreach ($k in $mainClassTable.Keys) { - if ($invokerName.EndsWith($k)) { - $mainClassName = $mainClassTable[$k] - break - } -} -if ($null -eq $mainClassName) { - throw ("$invokerName is not a known lf command. Known commands are [$($mainClassTable.Keys)]. " + - "In case you use a symbolic or hard link to one of the Lingua Franca " + - "command line tools, make sure that the link's name ends with one of [$($mainClassTable.Keys)]") -} - -# This script is in $base\lib\scripts -$base="$PSScriptRoot\..\..\" -$java_home = "$Env:JAVA_HOME" -$java_cmd = "$java_home\bin\java.exe" -$jarpath_dev="$base\org.lflang\build\libs\org.lflang-*.jar" -$jarpath_release="$base\lib\jars\org.lflang-*.jar" - -function Test-Dev { - Test-Path "$base\org.lflang" -PathType container -} - -function Get-JarPath { - if (Test-Dev) { - if (Test-Path $jarpath_dev -PathType leaf) { - $jarpath=$(Get-ChildItem $jarpath_dev).toString() - } else { - throw "Failed to find a copy of the Lingua Franca compiler matching the pattern ""$jarpath_dev"". Did you remember to build?" - } - } else { - if (Test-Path $jarpath_release -PathType leaf) { - $jarpath=$(Get-ChildItem $jarpath_release).toString() - } else { - throw "Failed to find a copy of the Lingua Franca compiler matching the pattern ""$jarpath_release""." - } - } - $jarpath -} - -# check if we can find java executable in $java_home -if (-not (Test-Path $java_cmd)) { - # otherwise, try to run java directly - if (-not (Get-Command java -errorAction SilentlyContinue)) { - throw "JRE not found" - } - $java_cmd = "java" -} - -# check for correct java version -$java_version = (Get-Command java | Select-Object -ExpandProperty Version).toString() -if ([version]$java_version -lt [version]"17.0") { - throw "JRE $java_version found but 17.0 or greater is required." -} - -# invoke lff -& $java_cmd -classpath $(Get-JarPath) $mainClassName $args diff --git a/bin/bump-versions b/util/scripts/bump-versions similarity index 100% rename from bin/bump-versions rename to util/scripts/bump-versions diff --git a/lib/scripts/launch-fedsd.sh b/util/scripts/launch-fedsd.sh similarity index 100% rename from lib/scripts/launch-fedsd.sh rename to util/scripts/launch-fedsd.sh diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 new file mode 100644 index 0000000000..6e7d50854e --- /dev/null +++ b/util/scripts/launch.ps1 @@ -0,0 +1,39 @@ +#========================================================== +# Description: Launch lfc or lff depending on the invoking script. +# Authors: Christian Menard, Peter Donovan, Ruomu Xu +# Usage: Usage: launch args... +# with invoker with name same as the programme to be invoked. +#========================================================== + +# If the invoker is Z:\nkamihara\lf\bin\lfc.ps1, $invokerName will strip out "lfc.ps1" and then get "lfc". +# See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2#myinvocation +$invokerPath = $MyInvocation.PSCommandPath +$invokerName = [System.IO.Path]::GetFileNameWithoutExtension("$(Split-Path -Path $invokerPath -Leaf -Resolve)") + +$mainClassTable = @{"lfc" = "org.lflang.cli.Lfc"; "lff" = "org.lflang.cli.Lff"} +$tool = $null +foreach ($k in $mainClassTable.Keys) { + if ($invokerName.EndsWith($k)) { + tool = $k,,, + break + } +} +if ($null -eq $tool) { + throw ("$invokerName is not a known lf command. Known commands are [$($mainClassTable.Keys)]. " + + "In case you use a symbolic or hard link to one of the Lingua Franca " + + "command line tools, make sure that the link's name ends with one of [$($mainClassTable.Keys)]") +} + +# This script is in $base\util\scripts +$base="$PSScriptRoot\..\..\" +script="${base}/org.lflang/cli/${tool}/build/install/${tool}/bin/${tool}" + + + +# check if we can find the script +if (-not (Test-Path $script)) { + throw "Could not find ${tool}! Did you build the repository? Please run './gradlew.bat assemble' or './gradlew.bat build' and try again." +} + +# invoke script +& $script $args diff --git a/lib/scripts/launch.sh b/util/scripts/launch.sh similarity index 87% rename from lib/scripts/launch.sh rename to util/scripts/launch.sh index 82747c81ef..b30f8c97ac 100755 --- a/lib/scripts/launch.sh +++ b/util/scripts/launch.sh @@ -43,12 +43,10 @@ function fatal_error() { exit 1 } -rel_path="lib/scripts" abs_path="$(find_dir "$0")" if [[ "${abs_path}" ]]; then base=`dirname $(dirname ${abs_path})` - source "${base}/${rel_path}/include.sh" else fatal_error "Unable to determine absolute path to $0." fi @@ -56,9 +54,9 @@ fi if [[ "$0" == *lfc ]]; then - main_class="org.lflang.cli.Lfc" + tool="lfc" elif [[ "$0" == *lff ]]; then - main_class="org.lflang.cli.Lff" + tool="lff" else known_commands="[lfc, lff]" echo \ @@ -69,5 +67,11 @@ else exit 2 fi -# Launch the compiler. -run_cli_tool_with_args "$@" +script="${base}/org.lflang/cli/${tool}/build/install/${tool}/bin/${tool}" + +if [[ ! -f "${script}" ]]; then + fatal_error "Could not find ${tool}! Did you build the repository? Please run './gradlew assemble' or './gradlew build' and try again." +fi + +# Launch the tool. +"$script" "$@" From 74f366c3f553b43a847725d792bc6204c48954a0 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 11:39:48 +0200 Subject: [PATCH 501/709] create a cli tools distribution --- build.gradle | 13 +++++++++++++ .../org.lflang.distribution-conventions.gradle | 8 ++++++++ .../org.lflang.java-application-conventions.gradle | 6 +++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 buildSrc/src/main/groovy/org.lflang.distribution-conventions.gradle diff --git a/build.gradle b/build.gradle index 87eaec93ce..873b7c2b55 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ import lfformat.LfFormatStep plugins { id "com.diffplug.spotless" + id "org.lflang.distribution-conventions" } spotless { @@ -24,3 +25,15 @@ spotless { } spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") + + +distributions { + clitools { + distributionBaseName.set("lf-cli") + contents { + from tasks.getByPath(':org.lflang:cli:lfc:installDist').outputs + from tasks.getByPath(':org.lflang:cli:lff:installDist').outputs + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + } +} diff --git a/buildSrc/src/main/groovy/org.lflang.distribution-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.distribution-conventions.gradle new file mode 100644 index 0000000000..4d25bbb461 --- /dev/null +++ b/buildSrc/src/main/groovy/org.lflang.distribution-conventions.gradle @@ -0,0 +1,8 @@ +plugins { + id 'distribution' +} + +tasks.withType(Tar) { + compression = Compression.GZIP + archiveExtension = 'tar.gz' +} diff --git a/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle index d8e3f5f76a..02cdc18df1 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle @@ -2,6 +2,10 @@ plugins { id 'org.lflang.java-conventions' id 'application' id 'org.lflang.test-conventions' + id "org.lflang.distribution-conventions" } -assemble.finalizedBy installDist \ No newline at end of file +tasks.withType(Tar) { + compression = Compression.GZIP + archiveExtension = 'tar.gz' +} From 56887f2785d3df0e9e834e76b919a06a30723e21 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 12:18:05 +0200 Subject: [PATCH 502/709] use gradle to run lfc and lff --- org.lflang/cli/lfc/build.gradle | 2 +- org.lflang/cli/lff/build.gradle | 2 +- util/scripts/launch.ps1 | 11 ++--------- util/scripts/launch.sh | 8 ++------ 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/org.lflang/cli/lfc/build.gradle b/org.lflang/cli/lfc/build.gradle index ca59afece9..9af526e579 100644 --- a/org.lflang/cli/lfc/build.gradle +++ b/org.lflang/cli/lfc/build.gradle @@ -11,5 +11,5 @@ dependencies { application { mainClass = 'org.lflang.cli.Lfc' - tasks.run.workingDir = rootProject.projectDir + tasks.run.workingDir = System.getProperty("user.dir") } diff --git a/org.lflang/cli/lff/build.gradle b/org.lflang/cli/lff/build.gradle index b2a597fa05..65d35a21c2 100644 --- a/org.lflang/cli/lff/build.gradle +++ b/org.lflang/cli/lff/build.gradle @@ -17,7 +17,7 @@ dependencies { application { mainClass = 'org.lflang.cli.Lff' - tasks.run.workingDir = rootProject.projectDir + tasks.run.workingDir = System.getProperty("user.dir") } test { diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index 6e7d50854e..839f022999 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -26,14 +26,7 @@ if ($null -eq $tool) { # This script is in $base\util\scripts $base="$PSScriptRoot\..\..\" -script="${base}/org.lflang/cli/${tool}/build/install/${tool}/bin/${tool}" - - - -# check if we can find the script -if (-not (Test-Path $script)) { - throw "Could not find ${tool}! Did you build the repository? Please run './gradlew.bat assemble' or './gradlew.bat build' and try again." -} +$gradlew="${base}/gradlew.bat" # invoke script -& $script $args +& "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args "$@" \ No newline at end of file diff --git a/util/scripts/launch.sh b/util/scripts/launch.sh index b30f8c97ac..03025c9914 100755 --- a/util/scripts/launch.sh +++ b/util/scripts/launch.sh @@ -67,11 +67,7 @@ else exit 2 fi -script="${base}/org.lflang/cli/${tool}/build/install/${tool}/bin/${tool}" - -if [[ ! -f "${script}" ]]; then - fatal_error "Could not find ${tool}! Did you build the repository? Please run './gradlew assemble' or './gradlew build' and try again." -fi +gradlew="${base}/gradlew" # Launch the tool. -"$script" "$@" +"${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args "$@" From 7a491675d6618f2201dba4841edbbf65761e7ded Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 12:19:29 +0200 Subject: [PATCH 503/709] update packaging workflow --- .github/scripts/package-cli.sh | 40 ---------------------------------- .github/workflows/build.yml | 6 ++--- .github/workflows/ci.yml | 2 +- build.gradle | 7 +++++- 4 files changed, 10 insertions(+), 45 deletions(-) delete mode 100755 .github/scripts/package-cli.sh diff --git a/.github/scripts/package-cli.sh b/.github/scripts/package-cli.sh deleted file mode 100755 index 7e17c1c38d..0000000000 --- a/.github/scripts/package-cli.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# build lf cli tools -./gradlew clean buildAll - -# find the version number -jar_path="org.lflang/build/libs/org.lflang-*.jar" -version="$(ls ${jar_path} | xargs -n 1 basename | sed 's/^org.lflang-\(.*\).jar$/\1/')" - -# use a different naming convention for nightly build artifacts -if [[ "$#" > 0 && "$1" = "nightly" ]]; then - echo "Packaging Lingua Franca Nightly Build" - outname="lf-cli-nightly-$(date '+%Y%m%d-%H%M%S')" -else - echo "Packaging Lingua Franca v${version}" - outname="lf-cli-${version}" -fi - -# assemble the files in a separate directory -mkdir -p "${outname}/bin" -mkdir -p "${outname}/lib/scripts" -mkdir -p "${outname}/lib/jars" - -# move the jar -mv org.lflang/build/libs/org.lflang-*.jar "${outname}/lib/jars" - -# copy the Bash scripts -cp -a lib/scripts "${outname}/lib/" -ln -s "../lib/scripts/launch.sh" "${outname}/bin/lfc" -ln -s "../lib/scripts/launch.sh" "${outname}/bin/lff" -# copy the PowerShell script -cp bin/lfc.ps1 "${outname}/bin/lfc.ps1" -cp bin/lff.ps1 "${outname}/bin/lff.ps1" - -# zip/tar everything - the files will be put into the build_upload directory -mkdir -p build_upload -zip --symlinks -r "build_upload/${outname}.zip" "${outname}" -tar zcvf "build_upload/${outname}.tar.gz" "${outname}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 767df01fa1..3e7b49e511 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,11 +24,11 @@ jobs: - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Build and package lf cli tools (nightly build) - run: .github/scripts/package-cli.sh nightly + run: ./gradlew build -Pnightly shell: bash if: ${{ inputs.nightly == true }} - name: Build and package lf cli tools (regular build) - run: .github/scripts/package-cli.sh + run: ./gradlew build shell: bash if: ${{ inputs.nightly != true }} - name: Deploy nightly release @@ -39,5 +39,5 @@ jobs: prerelease: true title: "Lingua Franca Nightly" files: | - build_upload/* + build/distributions/* if: ${{ inputs.nightly == true }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc9832cf35..01a49dd0ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: # Test the Gradle build. build: - uses: lf-lang/lingua-franca/.github/workflows/build.yml@master + uses: lf-lang/lingua-franca/.github/workflows/build.yml@gradle needs: cancel # Build the tools used for processing execution traces diff --git a/build.gradle b/build.gradle index 873b7c2b55..c1130f9e20 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,12 @@ spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") distributions { clitools { - distributionBaseName.set("lf-cli") + distributionBaseName = "lf-cli" + if (project.hasProperty('nightly')) { + def date = new Date() + def formattedDate = date.format('yyyyMMddHHmmss') + distributionClassifier = 'nightly-' + formattedDate + } contents { from tasks.getByPath(':org.lflang:cli:lfc:installDist').outputs from tasks.getByPath(':org.lflang:cli:lff:installDist').outputs From 37ff7d0ce78a7c5760e29710d705802d8d815b10 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 12:19:48 +0200 Subject: [PATCH 504/709] don't format lf files for now --- build.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index c1130f9e20..43a28acccf 100644 --- a/build.gradle +++ b/build.gradle @@ -16,15 +16,15 @@ spotless { endWithNewline() } - format 'linguaFranca', { - addStep(LfFormatStep.create(project.projectDir)) - target 'test/*/src/**/*.lf' // you have to set the target manually - targetExclude 'test/**/failing/**' - } +// format 'linguaFranca', { +// addStep(LfFormatStep.create(project.projectDir)) +// target 'test/*/src/**/*.lf' // you have to set the target manually +// targetExclude 'test/**/failing/**' +// } } -spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") +//spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") distributions { From 2a80a6f9892b105dc4f773679cfd409d45a9db98 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 12:24:34 +0200 Subject: [PATCH 505/709] no need to run unit tests and format checks separately they are included in gradle build --- .github/workflows/check-format.yml | 19 ------------------- .github/workflows/ci.yml | 9 --------- .github/workflows/unit-tests.yml | 27 --------------------------- 3 files changed, 55 deletions(-) delete mode 100644 .github/workflows/check-format.yml delete mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml deleted file mode 100644 index 8c022f90a5..0000000000 --- a/.github/workflows/check-format.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Spotless check - -on: - workflow_call: - -jobs: - run: - runs-on: ubuntu-latest - steps: - - name: Check out lingua-franca repository - uses: actions/checkout@v3 - with: - submodules: recursive - fetch-depth: 0 - - name: Prepare build environment - uses: ./.github/actions/prepare-build-env - - name: Run spotlessCheck - run: ./gradlew spotlessCheck - shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01a49dd0ca..75666c5cab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,15 +30,6 @@ jobs: uses: lf-lang/lingua-franca/.github/workflows/build-trace-tools.yml@master needs: cancel - check-format: - uses: lf-lang/lingua-franca/.github/workflows/check-format.yml@master - needs: cancel - - # Run the unit tests. - unit-tests: - uses: lf-lang/lingua-franca/.github/workflows/unit-tests.yml@master - needs: cancel - # Run tests for the standalone compiler. cli-tests: uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@master diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 1caec5c1ac..0000000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Unit tests - -on: - workflow_call: - -jobs: - run: - strategy: - matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.platform }} - steps: - - uses: actions/checkout@v3 - with: - submodules: true - fetch-depth: 0 - - name: Prepare build environment - uses: ./.github/actions/prepare-build-env - - name: Run compiler tests - run: | - ./gradlew test --tests org.lflang.tests.compiler.* - - name: Report to CodeCov - uses: codecov/codecov-action@v3.1.1 - with: - file: org.lflang.tests/build/reports/xml/jacoco - fail_ci_if_error: false - verbose: true From f55e63dbf6c1fc9d184b6a5da70ef2548dfe8c0b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 12:33:16 +0200 Subject: [PATCH 506/709] fix tracing utils --- util/tracing/makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/tracing/makefile b/util/tracing/makefile index 407b153235..590eaa698f 100644 --- a/util/tracing/makefile +++ b/util/tracing/makefile @@ -3,10 +3,10 @@ # @author: Edward A. Lee CC=gcc -CFLAGS=-I../../org.lflang/src/lib/c/reactor-c/include/core/ \ - -I../../org.lflang/src/lib/c/reactor-c/include/core/modal_models \ - -I../../org.lflang/src/lib/c/reactor-c/include/core/platform \ - -I../../org.lflang/src/lib/c/reactor-c/include/core/utils \ +CFLAGS=-I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/ \ + -I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/modal_models \ + -I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/platform \ + -I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/utils \ -DLF_UNTHREADED=1 \ -Wall DEPS= @@ -28,7 +28,7 @@ install: trace_to_csv trace_to_chrome trace_to_influxdb mv trace_to_csv ../../bin mv trace_to_chrome ../../bin mv trace_to_influxdb ../../bin - ln -f -s ../lib/scripts/launch-fedsd.sh ../../bin/fedsd + ln -f -s ../utils/scripts/launch-fedsd.sh ../../bin/fedsd chmod +x ../../bin/fedsd clean: From c650d324cb00b5541b80447de6ef0cffcc7e7d7d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 14:10:49 +0200 Subject: [PATCH 507/709] add jacoco support and merge cli tests into build --- .github/scripts/test-build.sh | 25 ---------- .github/workflows/build.yml | 28 +++++++++++ .github/workflows/ci.yml | 5 -- .github/workflows/cli-tests.yml | 46 ------------------- build.gradle | 14 ++++++ .../groovy/org.lflang.test-conventions.gradle | 28 +++++++++++ 6 files changed, 70 insertions(+), 76 deletions(-) delete mode 100755 .github/scripts/test-build.sh delete mode 100644 .github/workflows/cli-tests.yml diff --git a/.github/scripts/test-build.sh b/.github/scripts/test-build.sh deleted file mode 100755 index 36ba4011c1..0000000000 --- a/.github/scripts/test-build.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -# Exit 1 if any command returns with a non-zero exit code. -set -euo pipefail - -cd $GITHUB_WORKSPACE - -function test_with_links() { - rm -rf foo - mkdir -p foo/bar/baz - ln -s ../bin/${1} foo/link-foo - ln -s ../link-foo foo/bar/link-bar - ln -s ../link-bar foo/bar/baz/link-baz - foo/bar/baz/link-baz --help -} - -# Test the build-lf-cli executable and its flags. -bin/build-lf-cli -bin/build-lf-cli --help -bin/build-lf-cli -h -bin/build-lf-cli -c -o -s -bin/build-lf-cli --clean --offline --stacktrace - -# Ensure that build-lf-cli is robust to symbolic links. -test_with_links "build-lf-cli" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e7b49e511..6414b2500f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,24 @@ jobs: run: ./gradlew build shell: bash if: ${{ inputs.nightly != true }} + - name: Test lfc bash scripts (Linux or macOS only) + run: | + .github/scripts/test-lfc.sh + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} + - name: Test lff bash scripts (Linux or macOS only) + run: | + .github/scripts/test-lff.sh + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} + - name: Test PowerShell lfc script (Windows only) + run: | + ./gradlew buildAll + bin/lfc.ps1 --help + if: ${{ runner.os == 'Windows' }} + - name: Test PowerShell lff script (Windows only) + run: | + ./gradlew buildAll + bin/lfc.ps1 --help + if: ${{ runner.os == 'Windows' }} - name: Deploy nightly release uses: marvinpinto/action-automatic-releases@latest with: @@ -41,3 +59,13 @@ jobs: files: | build/distributions/* if: ${{ inputs.nightly == true }} + - name: Collect code coverage + run: ./gradlew jacocoTestReport + if: ${{ runner.os == 'Linux' }} + - name: Report to CodeCov + uses: codecov/codecov-action@v3.1.1 + with: + files: org.lflang/core/build/reports/xml/jacoco,org.lflang/cli/lfc/build/reports/xml/jacoco,org.lflang/cli/lff/build/reports/xml/jacoco + fail_ci_if_error: false + verbose: true + if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75666c5cab..db3dcfd08c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,11 +30,6 @@ jobs: uses: lf-lang/lingua-franca/.github/workflows/build-trace-tools.yml@master needs: cancel - # Run tests for the standalone compiler. - cli-tests: - uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@master - needs: cancel - # Run the C benchmark tests. c-benchmark-tests: uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml deleted file mode 100644 index 056e32c04c..0000000000 --- a/.github/workflows/cli-tests.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: CLI tests - -on: - workflow_call: - -jobs: - run: - strategy: - matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.platform }} - steps: - - uses: actions/checkout@v3 - with: - submodules: true - fetch-depth: 0 - - name: Prepare build environment - uses: ./.github/actions/prepare-build-env - - name: Test build bash scripts (Linux and macOS only) - run: | - .github/scripts/test-build.sh - if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - - name: Test lfc bash scripts (Linux or macOS only) - run: | - .github/scripts/test-lfc.sh - if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - - name: Test lff bash scripts (Linux or macOS only) - run: | - .github/scripts/test-lff.sh - if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - - name: Test PowerShell script (Windows only) - run: | - ./gradlew buildAll - bin/lfc.ps1 --help - if: ${{ runner.os == 'Windows' }} - - name: Run standalone cli tests - run: | - ./gradlew test --tests org.lflang.tests.cli.* --stacktrace -# NOTE: do not put other invocations for gradlew in between these steps, or coverage reporting will break. - - name: Report to CodeCov - uses: codecov/codecov-action@v3.1.1 - with: - file: org.lflang.tests/build/reports/xml/jacoco - fail_ci_if_error: false - verbose: true - if: ${{ runner.os == 'Linux' }} diff --git a/build.gradle b/build.gradle index 43a28acccf..7ac11a7cc1 100644 --- a/build.gradle +++ b/build.gradle @@ -42,3 +42,17 @@ distributions { } } } + +task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') { + description = 'Generates an aggregate report from all subprojects' + dependsOn(subprojects.test) + + additionalSourceDirs.from = files(subprojects.sourceSets.main.allSource.srcDirs) + sourceDirectories.from = files(subprojects.sourceSets.main.allSource.srcDirs) + classDirectories.from = files(subprojects.sourceSets.main.output) + executionData.from = files(subprojects.jacocoTestReport.executionData) + + reports { + html.enabled true + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 1055ca0dbc..c126c32860 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -1,7 +1,14 @@ plugins { id 'java-test-fixtures' + id 'jacoco' } +jacoco { + toolVersion = jacocoVersion +} + + + dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" @@ -26,4 +33,25 @@ test { events "passed", "skipped", "failed" showStandardStreams = true } +} + +jacocoTestReport { + reports { + xml.required = true + csv.required = false + html.destination file("${buildDir}/reports/html/jacoco") + xml.destination file("${buildDir}/reports/xml/jacoco") + } + + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, + exclude: ['**/org/lflang/services/**', + '**/org/lflang/lf/**', + '**/org/lflang/serializer/**', + '**/org/lflang/parser/antlr/**' + ] + ) + })) + } } \ No newline at end of file From 7190c8726d83c77bda2fad95039d8dd530b5eef2 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 14:41:27 +0200 Subject: [PATCH 508/709] add integration tests, but skip them in our test task --- build.gradle | 14 -------------- .../main/groovy/org.lflang.test-conventions.gradle | 6 +++++- .../kotlin/org/lflang/cli/LfcIssueReportingTest.kt | 2 +- .../test/java}/org/lflang/tests/RuntimeTest.java | 14 ++++++++++++++ .../test/java/org/lflang/tests/lsp/LspTests.java | 6 ++++++ .../org/lflang/tests/runtime/CArduinoTest.java | 2 ++ .../java}/org/lflang/tests/runtime/CCppTest.java | 2 ++ .../org/lflang/tests/runtime/CSchedulerTest.java | 2 ++ .../test/java}/org/lflang/tests/runtime/CTest.java | 13 +++++++++++++ .../org/lflang/tests/runtime/CZephyrTest.java | 3 +++ .../org/lflang/tests/runtime/CppRos2Test.java | 2 ++ .../java}/org/lflang/tests/runtime/CppTest.java | 7 +++++++ .../java}/org/lflang/tests/runtime/PythonTest.java | 9 +++++++++ .../java}/org/lflang/tests/runtime/RustTest.java | 0 .../org/lflang/tests/runtime/TypeScriptTest.java | 9 +++++++++ .../tests/serialization/SerializationTest.java | 3 +++ .../EnclaveCommunicationDelayedLocalEvents.lf | 1 + 17 files changed, 79 insertions(+), 16 deletions(-) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/RuntimeTest.java (94%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CArduinoTest.java (93%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CCppTest.java (96%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CSchedulerTest.java (97%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CTest.java (92%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CZephyrTest.java (97%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CppRos2Test.java (94%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/CppTest.java (94%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/PythonTest.java (94%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/RustTest.java (100%) rename {org.lflang.tests/src => org.lflang/core/src/test/java}/org/lflang/tests/runtime/TypeScriptTest.java (88%) diff --git a/build.gradle b/build.gradle index 7ac11a7cc1..43a28acccf 100644 --- a/build.gradle +++ b/build.gradle @@ -42,17 +42,3 @@ distributions { } } } - -task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') { - description = 'Generates an aggregate report from all subprojects' - dependsOn(subprojects.test) - - additionalSourceDirs.from = files(subprojects.sourceSets.main.allSource.srcDirs) - sourceDirectories.from = files(subprojects.sourceSets.main.allSource.srcDirs) - classDirectories.from = files(subprojects.sourceSets.main.output) - executionData.from = files(subprojects.jacocoTestReport.executionData) - - reports { - html.enabled true - } -} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index c126c32860..345b78cc88 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -28,11 +28,15 @@ dependencies { } test { - useJUnitPlatform() + useJUnitPlatform { + excludeTags 'Integration' + } testLogging { events "passed", "skipped", "failed" showStandardStreams = true } + + workingDir = rootProject.projectDir } jacocoTestReport { diff --git a/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt b/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt index d8455bc7e9..44a85a13df 100644 --- a/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt +++ b/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt @@ -120,7 +120,7 @@ class LfcIssueReportingTest { val packageName = loader.packageName.replace('.', '/') // relative to root of gradle project // TODO This should load the resources and copy them to a temp directory instead of reading directly - val basePath = "src/test/resources/$packageName/" + val basePath = "org.lflang/cli/lfc/src/test/resources/$packageName/" val lfFile = Paths.get("$basePath/$fileBaseName.lf") val expectedPath = Paths.get("$basePath/$fileBaseName.stderr") diff --git a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java b/org.lflang/core/src/test/java/org/lflang/tests/RuntimeTest.java similarity index 94% rename from org.lflang.tests/src/org/lflang/tests/RuntimeTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/RuntimeTest.java index 2dfd42d38b..c873dcd427 100644 --- a/org.lflang.tests/src/org/lflang/tests/RuntimeTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/RuntimeTest.java @@ -3,6 +3,7 @@ import java.util.EnumSet; import java.util.List; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.ast.ASTUtils; @@ -54,6 +55,7 @@ protected boolean supportsDockerOption() { } @Test + @Tag("Integration") public void runGenericTests() { runTestsForTargets( Message.DESC_GENERIC, @@ -64,6 +66,7 @@ public void runGenericTests() { } @Test + @Tag("Integration") public void runTargetSpecificTests() { runTestsForTargets( Message.DESC_TARGET_SPECIFIC, @@ -74,6 +77,7 @@ public void runTargetSpecificTests() { } @Test + @Tag("Integration") public void runMultiportTests() { runTestsForTargets( Message.DESC_MULTIPORT, @@ -84,6 +88,7 @@ public void runMultiportTests() { } @Test + @Tag("Integration") public void runTypeParameterTests() { Assumptions.assumeTrue(supportsGenericTypes(), Message.NO_GENERICS_SUPPORT); runTestsForTargets( @@ -95,6 +100,7 @@ public void runTypeParameterTests() { } @Test + @Tag("Integration") public void runAsFederated() { Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); @@ -116,6 +122,7 @@ public void runAsFederated() { } @Test + @Tag("Integration") public void runConcurrentTests() { runTestsForTargets( Message.DESC_CONCURRENT, @@ -126,6 +133,7 @@ public void runConcurrentTests() { } @Test + @Tag("Integration") public void runFederatedTests() { Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); runTestsForTargets( @@ -138,6 +146,7 @@ public void runFederatedTests() { /** Run the tests for modal reactors. */ @Test + @Tag("Integration") public void runModalTests() { runTestsForTargets( Message.DESC_MODAL, @@ -149,6 +158,7 @@ public void runModalTests() { /** Run the tests for non-inlined reaction bodies. */ @Test + @Tag("Integration") public void runNoInliningTests() { runTestsForTargets( Message.DESC_MODAL, @@ -163,6 +173,7 @@ public void runNoInliningTests() { * platform is not Linux or target does not support Docker. */ @Test + @Tag("Integration") public void runDockerTests() { Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); @@ -180,6 +191,7 @@ public void runDockerTests() { * tests. */ @Test + @Tag("Integration") public void runDockerFederatedTests() { Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); @@ -193,6 +205,7 @@ public void runDockerFederatedTests() { } @Test + @Tag("Integration") public void runWithThreadingOff() { Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); this.runTestsForTargets( @@ -205,6 +218,7 @@ public void runWithThreadingOff() { /** Run enclave tests if the target supports enclaves. */ @Test + @Tag("Integration") public void runEnclaveTests() { Assumptions.assumeTrue(supportsEnclaves(), Message.NO_ENCLAVE_SUPPORT); runTestsForTargets( diff --git a/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java b/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java index fe52d6016c..52339161ea 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java @@ -12,6 +12,7 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.lsp4j.Diagnostic; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; @@ -56,30 +57,35 @@ class LspTests { /** Test for false negatives in Python syntax-only validation. */ @Test + @Tag("Integration") void pythonValidationTestSyntaxOnly() throws IOException { targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON_SYNTAX_ONLY); } /** Test for false negatives in C++ validation. */ @Test + @Tag("Integration") void cppValidationTest() throws IOException { targetLanguageValidationTest(Target.CPP, ErrorInserter.CPP); } /** Test for false negatives in Python validation. */ @Test + @Tag("Integration") void pythonValidationTest() throws IOException { targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON); } /** Test for false negatives in Rust validation. */ @Test + @Tag("Integration") void rustValidationTest() throws IOException { targetLanguageValidationTest(Target.Rust, ErrorInserter.RUST); } /** Test for false negatives in TypeScript validation. */ @Test + @Tag("Integration") void typescriptValidationTest() throws IOException { targetLanguageValidationTest(Target.TS, ErrorInserter.TYPESCRIPT); } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CArduinoTest.java similarity index 93% rename from org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CArduinoTest.java index 95363fd30b..4758977143 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CArduinoTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CArduinoTest.java @@ -2,6 +2,7 @@ import java.util.List; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; @@ -20,6 +21,7 @@ public CArduinoTest() { } @Test + @Tag("Integration") public void buildArduinoTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); super.runTestsFor( diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CCppTest.java similarity index 96% rename from org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CCppTest.java index ba1865e870..04ea680194 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CCppTest.java @@ -1,6 +1,7 @@ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.ast.ASTUtils; @@ -26,6 +27,7 @@ public CCppTest() { /** Run C tests with the target CCpp. */ @Test + @Tag("Integration") public void runAsCCpp() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); runTestsForTargets( diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CSchedulerTest.java similarity index 97% rename from org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CSchedulerTest.java index fd2345723f..4730962ee0 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CSchedulerTest.java @@ -1,6 +1,7 @@ package org.lflang.tests.runtime; import java.util.EnumSet; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.TargetProperty.SchedulerOption; @@ -21,6 +22,7 @@ public CSchedulerTest() { * (e.g., -Dscheduler=GEDF_NP). */ @Test + @Tag("Integration") public void runWithNonDefaultSchedulers() { EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, TestCategory.MULTIPORT); diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CTest.java similarity index 92% rename from org.lflang.tests/src/org/lflang/tests/runtime/CTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CTest.java index 4902550661..63122fb4c6 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; @@ -46,6 +47,7 @@ public CTest() { } @Override + @Tag("Integration") protected boolean supportsSingleThreadedExecution() { return true; } @@ -61,12 +63,14 @@ protected boolean supportsDockerOption() { } @Test + @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test + @Tag("Integration") @Override public void runTargetSpecificTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -74,18 +78,21 @@ public void runTargetSpecificTests() { } @Test + @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test + @Tag("Integration") @Override public void runWithThreadingOff() { super.runWithThreadingOff(); } @Test + @Tag("Integration") @Disabled("TODO only 27/96 tests pass") @Override public void runAsFederated() { @@ -94,12 +101,14 @@ public void runAsFederated() { } @Test + @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test + @Tag("Integration") @Override public void runFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -107,22 +116,26 @@ public void runFederatedTests() { } @Test + @Tag("Integration") public void runModalTests() { super.runModalTests(); } @Test + @Tag("Integration") public void runNoInliningTests() { super.runNoInliningTests(); } @Test + @Tag("Integration") @Override public void runDockerTests() { super.runDockerTests(); } @Test + @Tag("Integration") @Override public void runDockerFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CZephyrTest.java similarity index 97% rename from org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CZephyrTest.java index c151c1bb76..777308b221 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CZephyrTest.java @@ -26,6 +26,7 @@ import java.util.List; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; @@ -44,6 +45,7 @@ public CZephyrTest() { } @Test + @Tag("Integration") public void buildZephyrTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor( @@ -56,6 +58,7 @@ public void buildZephyrTests() { } @Test + @Tag("Integration") public void buildGenericTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor( diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppRos2Test.java similarity index 94% rename from org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CppRos2Test.java index dc2612c14b..1a333eb145 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CppRos2Test.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppRos2Test.java @@ -1,6 +1,7 @@ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.ast.ASTUtils; @@ -23,6 +24,7 @@ public CppRos2Test() { /** Run C++ tests with the ros2 target property set */ @Test + @Tag("Integration") public void runWithRos2() { Assumptions.assumeTrue(isLinux(), "Only supported on Linux"); Element trueLiteral = LfFactory.eINSTANCE.createElement(); diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppTest.java similarity index 94% rename from org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/CppTest.java index 20973189b9..879e6cdc5b 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CppTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppTest.java @@ -26,6 +26,7 @@ ***************/ package org.lflang.tests.runtime; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; @@ -50,35 +51,41 @@ protected boolean supportsEnclaves() { } @Test + @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test + @Tag("Integration") @Override public void runTargetSpecificTests() { super.runTargetSpecificTests(); } @Test + @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test + @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test + @Tag("Integration") @Override public void runFederatedTests() { super.runFederatedTests(); } @Test + @Tag("Integration") public void runRos2Tests() {} } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/PythonTest.java similarity index 94% rename from org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/PythonTest.java index 1c258b7481..e25a3220d2 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/PythonTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/PythonTest.java @@ -27,6 +27,7 @@ import java.util.Properties; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; @@ -72,24 +73,28 @@ protected boolean supportsDockerOption() { } @Test + @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test + @Tag("Integration") @Override public void runTargetSpecificTests() { super.runTargetSpecificTests(); } @Test + @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test + @Tag("Integration") @Disabled("TODO") @Override public void runAsFederated() { @@ -98,12 +103,14 @@ public void runAsFederated() { } @Test + @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test + @Tag("Integration") @Override public void runFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -111,12 +118,14 @@ public void runFederatedTests() { } @Test + @Tag("Integration") @Override public void runDockerTests() { super.runDockerTests(); } @Test + @Tag("Integration") @Override public void runDockerFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/RustTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/RustTest.java similarity index 100% rename from org.lflang.tests/src/org/lflang/tests/runtime/RustTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/RustTest.java diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java b/org.lflang/core/src/test/java/org/lflang/tests/runtime/TypeScriptTest.java similarity index 88% rename from org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java rename to org.lflang/core/src/test/java/org/lflang/tests/runtime/TypeScriptTest.java index 036211607a..0945c3ebe3 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/TypeScriptTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/runtime/TypeScriptTest.java @@ -1,6 +1,7 @@ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; @@ -30,30 +31,35 @@ protected boolean supportsFederatedExecution() { } @Test + @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test + @Tag("Integration") @Override public void runTargetSpecificTests() { super.runTargetSpecificTests(); } @Test + @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test + @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test + @Tag("Integration") @Override public void runFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -61,12 +67,14 @@ public void runFederatedTests() { } @Test + @Tag("Integration") @Override public void runDockerTests() { super.runDockerTests(); } @Test + @Tag("Integration") @Override public void runDockerFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -74,6 +82,7 @@ public void runDockerFederatedTests() { } @Test + @Tag("Integration") @Override public void runAsFederated() {} } diff --git a/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java b/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java index 26f3ec37af..25e0983783 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java +++ b/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java @@ -2,6 +2,7 @@ import java.util.Properties; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; @@ -22,6 +23,7 @@ protected void addExtraLfcArgs(Properties args) { } @Test + @Tag("Integration") public void runSerializationTestsWithThreadingOff() { Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); runTestsForTargets( @@ -33,6 +35,7 @@ public void runSerializationTestsWithThreadingOff() { } @Test + @Tag("Integration") public void runSerializationTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); runTestsForTargets( diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf index fa9c7b25e4..aac8e34712 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf @@ -21,6 +21,7 @@ reactor Sink { auto value = *in.get(); reactor::log::Info() << "Received " << value; auto expected = 100ms * value + 50ms; + 0 = 1; if (get_elapsed_logical_time() != expected) { reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); exit(1); From 8667e9b7573dae6410e58899485a276eb6091d5e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 15:58:52 +0200 Subject: [PATCH 509/709] update ci wormflows --- .github/workflows/build.yml | 1 - .github/workflows/c-arduino-tests.yml | 8 ++- .github/workflows/c-tests.yml | 14 ++--- .github/workflows/c-zephyr-tests.yml | 8 ++- .github/workflows/ci.yml | 22 +++---- .github/workflows/cpp-ros2-tests.yml | 6 +- .github/workflows/cpp-tests.yml | 8 ++- .github/workflows/lsp-tests.yml | 14 ++--- .github/workflows/py-tests.yml | 9 ++- .github/workflows/rs-tests.yml | 8 ++- .github/workflows/serialization-tests.yml | 6 +- .github/workflows/ts-tests.yml | 7 ++- .../groovy/org.lflang.test-conventions.gradle | 32 +++++++++- org.lflang/core/build.gradle | 60 +++++++++++++++++++ 14 files changed, 150 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6414b2500f..d5aa64f6da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,4 +68,3 @@ jobs: files: org.lflang/core/build/reports/xml/jacoco,org.lflang/cli/lfc/build/reports/xml/jacoco,org.lflang/cli/lff/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 167e8f6f1c..cc21b28798 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -59,11 +59,13 @@ jobs: arduino-cli core install arduino:sam arduino-cli core install arduino:mbed - name: Perform Arduino tests for C target with default scheduler - run: ./gradlew test --tests org.lflang.tests.runtime.CArduinoTest.buildArduinoTests + run: ./gradlew integrationCArduino + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.runtime-ref && runner.os == 'Linux' }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 0764128a1b..78b0407c04 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -50,22 +50,22 @@ jobs: uses: ./.github/actions/install-rti if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform tests for C target with default scheduler - run: | - ./gradlew test --tests org.lflang.tests.runtime.CTest.* + run: ./gradlew integrationC if: ${{ !inputs.use-cpp && !inputs.scheduler }} - name: Perform tests for C target with specified scheduler (no LSP tests) run: | echo "Specified scheduler: ${{ inputs.scheduler }}" - ./gradlew test --tests org.lflang.tests.runtime.CSchedulerTest.* -Dscheduler=${{ inputs.scheduler }} + ./gradlew integrationC -Dscheduler=${{ inputs.scheduler }} if: ${{ !inputs.use-cpp && inputs.scheduler }} - name: Perform tests for CCpp target with default scheduler - run: | - ./gradlew test --tests org.lflang.tests.runtime.CCppTest.* + run: ./gradlew integrationCCpp if: ${{ inputs.use-cpp && !inputs.scheduler }} + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 3b7a76feee..490df2c5fa 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -41,12 +41,14 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler run: | - ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.build* + ./gradlew integrationCZephyr util/RunZephyrTests.sh test/C/src-gen + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.runtime-ref && runner.os == 'Linux' }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db3dcfd08c..b30e1ae23b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,27 +39,27 @@ jobs: # Run language server tests. lsp-tests: - uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@gradle needs: cancel # Run the C integration tests. c-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@gradle needs: cancel # Run the C Arduino integration tests. c-arduino-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@gradle needs: cancel # Run the C Zephyr integration tests. c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@gradle needs: cancel # Run the CCpp integration tests. ccpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@gradle with: use-cpp: true needs: cancel @@ -73,22 +73,22 @@ jobs: # Run the C++ integration tests. cpp-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cpp-tests.yml@gradle needs: cancel # Run the C++ integration tests on ROS2. cpp-ros2-tests: - uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/cpp-ros2-tests.yml@gradle needs: cancel # Run the Python integration tests. py-tests: - uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@gradle needs: cancel # Run the Rust integration tests. rs-tests: - uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/rs-tests.yml@gradle needs: cancel # Run the Rust benchmark tests. @@ -100,10 +100,10 @@ jobs: # Run the TypeScript integration tests. ts-tests: - uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/ts-tests.yml@gradle needs: cancel # Run the serialization tests serialization-tests: - uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/serialization-tests.yml@gradle needs: cancel diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index bfb3e12cb8..6424ce5316 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -34,11 +34,13 @@ jobs: - name: Run C++ tests; run: | source /opt/ros/*/setup.bash - ./gradlew test --tests org.lflang.tests.runtime.CppRos2Test.* + ./gradlew integrationCppRos2 + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 3fe74ae393..c14a0c5a56 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -43,11 +43,13 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Run C++ tests; run: | - ./gradlew test --tests org.lflang.tests.runtime.CppTest.* - - name: Report Java coverage to CodeCov + ./gradlew integrationCpp + - name: Collect code coverage + run: ./gradlew jacocoTestReport + - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index bf32254b0f..0b5346c0a4 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -64,13 +64,7 @@ jobs: with: python-version: '3.10' - name: Run language server Python tests without PyLint - run: ./gradlew test --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly - - name: Report to CodeCov - uses: codecov/codecov-action@v3.1.1 - with: - file: org.lflang.tests/build/reports/xml/jacoco - fail_ci_if_error: false - verbose: true + run: ./gradlew integration --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly - name: Install pylint run: python3 -m pip install pylint if: ${{ runner.os != 'macOS' }} @@ -78,10 +72,12 @@ jobs: run: brew install pylint if: ${{ runner.os == 'macOS' }} - name: Run language server tests - run: ./gradlew clean test --tests org.lflang.tests.lsp.LspTests.*ValidationTest + run: ./gradlew integration --tests org.lflang.tests.lsp.LspTests.*ValidationTest + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 3f6e521fd1..33729526b1 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -55,13 +55,12 @@ jobs: path: org.lflang/src/lib/py/reactor-c-py ref: ${{ inputs.reactor-c-py-ref }} if: ${{ inputs.reactor-c-py-ref }} - - name: Run Python tests - run: | - ./gradlew test --tests org.lflang.tests.runtime.PythonTest.* + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index 720efaa29c..ba8ff8923a 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -64,11 +64,13 @@ jobs: # version to the version used at runtime by LF. run: ./gradlew checkRuntimeVersionFileUpToDate - name: Run Rust tests - run: ./gradlew test --tests org.lflang.tests.runtime.RustTest.* + run: ./gradlew integrationRust + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 89f1ad735c..d27ac20b34 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,11 +31,13 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew test --tests org.lflang.tests.serialization.SerializationTest.* + ./gradlew integrationSerialization + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 4342082868..ae9eb41f78 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,10 +28,13 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" + ./gradlew integrationTypeScript -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" + - name: Collect code coverage + run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - file: org.lflang.tests/build/reports/xml/jacoco + files: org.lflang/core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true + if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 345b78cc88..890bea29f8 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -35,6 +35,9 @@ test { events "passed", "skipped", "failed" showStandardStreams = true } + maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 + + failFast = true workingDir = rootProject.projectDir } @@ -43,8 +46,8 @@ jacocoTestReport { reports { xml.required = true csv.required = false - html.destination file("${buildDir}/reports/html/jacoco") - xml.destination file("${buildDir}/reports/xml/jacoco") + html.outputLocation = file("${buildDir}/reports/html/jacoco") + xml.outputLocation = file("${buildDir}/reports/xml/jacoco") } afterEvaluate { @@ -58,4 +61,29 @@ jacocoTestReport { ) })) } +} + + + +tasks.register('integration', Test) { + if (System.getProperty('integrationInclude') != null) { + filter { + includeTestsMatching System.getProperty('integrationInclude') + } + } + useJUnitPlatform { + includeTags 'Integration' + + } + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + } + // Pass the scheduler and runtime property on to the Java VM + systemProperty 'scheduler', System.getProperty('scheduler') + systemProperty 'runtime', System.getProperty('runtime') + + failFast = true + + workingDir = rootProject.projectDir } \ No newline at end of file diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 21b8e562b8..c805927df0 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -78,3 +78,63 @@ compileKotlin.dependsOn(generateXtextLanguage) processResources.dependsOn(generateXtextLanguage) clean.dependsOn(cleanGenerateXtextLanguage) spotlessJava.mustRunAfter(generateXtextLanguage) + +tasks.register('integrationLsp') { + System.setProperty('integrationInclude', 'org.lflang.tests.lsp.**') + finalizedBy('integration') +} + +tasks.register('integrationCArduino') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CArduinoTest.*') + finalizedBy('integration') +} + +tasks.register('integrationCCpp') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CCppTest.*') + finalizedBy('integration') +} + +tasks.register('integrationCppRos2') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CppRos2Test.*') + finalizedBy('integration') +} + +tasks.register('integrationCpp') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CppTest.*') + finalizedBy('integration') +} + +tasks.register('integrationCScheduler') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CSchedulerTest.*') + finalizedBy('integration') +} + +tasks.register('integrationC') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CTest.*') + finalizedBy('integration') +} + +tasks.register('integrationCZephyr') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CZephyr.*') + finalizedBy('integration') +} + +tasks.register('integrationPython') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.PythonTest.*') + finalizedBy('integration') +} + +tasks.register('integrationRust') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.RustTest.*') + finalizedBy('integration') +} + +tasks.register('integrationTypeScript') { + System.setProperty('integrationInclude', 'org.lflang.tests.runtime.TypeScriptTest.*') + finalizedBy('integration') +} + +tasks.register('integrationSerialization') { + System.setProperty('integrationInclude', 'org.lflang.tests.serialization.SerializationTest.*') + finalizedBy('integration') +} \ No newline at end of file From df30c1b0c5651b4f0035b103b8b12b6f405bb73f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 16:06:34 +0200 Subject: [PATCH 510/709] add back cli workflow --- .github/workflows/ci.yml | 4 ++++ .github/workflows/cli-tests.yml | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/cli-tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b30e1ae23b..e2d6c432e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,10 @@ jobs: # Test the Gradle build. build: uses: lf-lang/lingua-franca/.github/workflows/build.yml@gradle + needs: cancel- # Run tests for the standalone compiler. + + cli-tests: + uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@gradle needs: cancel # Build the tools used for processing execution traces diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml new file mode 100644 index 0000000000..3789d4d800 --- /dev/null +++ b/.github/workflows/cli-tests.yml @@ -0,0 +1,36 @@ +name: CLI tests + +on: + workflow_call: + +jobs: + run: + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + fetch-depth: 0 + - name: Prepare build environment + - name: Test lfc bash scripts (Linux or macOS only) + run: | + .github/scripts/test-lfc.sh + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} + - name: Test lff bash scripts (Linux or macOS only) + run: | + .github/scripts/test-lff.sh + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} + - name: Test lfc PowerShell script (Windows only) + run: | + ./gradlew buildAll + bin/lfc.ps1 --help + if: ${{ runner.os == 'Windows' }} + - name: Test lff PowerShell script (Windows only) + run: | + ./gradlew buildAll + bin/lff.ps1 --help + if: ${{ runner.os == 'Windows' }} + From 8a176b355fb9cefc58e9d84d88d9dfa12bd0ad4d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 16:06:52 +0200 Subject: [PATCH 511/709] fix RTI install script --- .github/actions/install-rti/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/install-rti/install.sh b/.github/actions/install-rti/install.sh index 05ef9474b7..06ad67bb58 100755 --- a/.github/actions/install-rti/install.sh +++ b/.github/actions/install-rti/install.sh @@ -1,5 +1,5 @@ #!/bin/bash -cd org.lflang/src/lib/c/reactor-c/core/federated/RTI +cd org.lflang/core/src/main/resources/lib/c/reactor-c/core/federated/RTI mkdir build cd build if [[ "$OSTYPE" == "darwin"* ]]; then From f0098d0d39a20735cad7dc32beb0f6d4a33250f2 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 16:14:52 +0200 Subject: [PATCH 512/709] small fixes --- .../src/main/groovy/org.lflang.test-conventions.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 890bea29f8..336dda5ade 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -34,6 +34,7 @@ test { testLogging { events "passed", "skipped", "failed" showStandardStreams = true + exceptionFormat "full" } maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 @@ -66,6 +67,9 @@ jacocoTestReport { tasks.register('integration', Test) { + filter { + setFailOnNoMatchingTests(false) + } if (System.getProperty('integrationInclude') != null) { filter { includeTestsMatching System.getProperty('integrationInclude') @@ -78,11 +82,16 @@ tasks.register('integration', Test) { testLogging { events "passed", "skipped", "failed" showStandardStreams = true + exceptionFormat "full" } // Pass the scheduler and runtime property on to the Java VM systemProperty 'scheduler', System.getProperty('scheduler') systemProperty 'runtime', System.getProperty('runtime') + filter { + setFailOnNoMatchingTests(false) + } + failFast = true workingDir = rootProject.projectDir From 540cf3ff0d0c123e344dec2385c6bb75068f7cd3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 16:16:43 +0200 Subject: [PATCH 513/709] bugfix --- .github/workflows/ci.yml | 3 ++- .github/workflows/cli-tests.yml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2d6c432e2..4ad138903f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,9 @@ jobs: # Test the Gradle build. build: uses: lf-lang/lingua-franca/.github/workflows/build.yml@gradle - needs: cancel- # Run tests for the standalone compiler. + needs: cancel + # Test our scripts in bin. cli-tests: uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@gradle needs: cancel diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 3789d4d800..cddfc54537 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -15,6 +15,7 @@ jobs: submodules: true fetch-depth: 0 - name: Prepare build environment + uses: ./.github/actions/prepare-build-env - name: Test lfc bash scripts (Linux or macOS only) run: | .github/scripts/test-lfc.sh From 0e4d0db324dd19ae59f84f4aab7998ed7ae7551d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 16:22:24 +0200 Subject: [PATCH 514/709] bugfix in launch script --- util/scripts/launch.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index 839f022999..6f418a6a60 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -14,7 +14,7 @@ $mainClassTable = @{"lfc" = "org.lflang.cli.Lfc"; "lff" = "org.lflang.cli.Lff"} $tool = $null foreach ($k in $mainClassTable.Keys) { if ($invokerName.EndsWith($k)) { - tool = $k,,, + $tool = $k break } } From b366efdb527b952416727dca0fb0d3b9ddc81819 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 16:56:59 +0200 Subject: [PATCH 515/709] rust runtime version tasks readded --- .github/workflows/rs-tests.yml | 4 -- org.lflang/core/build.gradle | 76 +++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index ba8ff8923a..d16c556711 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -59,10 +59,6 @@ jobs: with: rust-version: ${{ matrix.rust }} components: clippy - - name: Check runtime-version.properties is up-to-date - # The following task compares the checked out submodule - # version to the version used at runtime by LF. - run: ./gradlew checkRuntimeVersionFileUpToDate - name: Run Rust tests run: ./gradlew integrationRust - name: Collect code coverage diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index c805927df0..615020ec4d 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -137,4 +137,78 @@ tasks.register('integrationTypeScript') { tasks.register('integrationSerialization') { System.setProperty('integrationInclude', 'org.lflang.tests.serialization.SerializationTest.*') finalizedBy('integration') -} \ No newline at end of file +} + +tasks.register('getSubmoduleVersions', Exec) { + description('Run a Git command to get the current status of submodules') + workingDir project.rootDir + // This will make gradle execute git submodule status every time updateRustRuntime is called + outputs.upToDateWhen { false } + + def command = "git submodule status" + if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { + commandLine 'cmd', '/c', command + } else { + commandLine 'sh', '-c', command + } + standardOutput = new ByteArrayOutputStream() + + ext.outputFile = file("$project.buildDir/submodule-status.properties") + outputs.file(outputFile) + + doLast { + def matcher = standardOutput.toString() =~ ~"(?m)^[-+ ]?([0-9a-f]+) org.lflang/core/src/main/resources/lib/\\w+/reactor-([-a-zA-Z]+)" + def properties = new StringBuilder() + while (matcher.find()) { + def rev = matcher.group(1) + def language = matcher.group(2) + properties << "$language = $rev\n" + } + outputFile.text = properties + } +} + +tasks.register('updateRustRuntime') { + description('Record the VCS revisions of the language runtimes into a properties file available at runtime.') + + dependsOn getSubmoduleVersions + // If the output of the git submodule status did not change (the getSubmoduleVersions task), then this task is considered up to date. + inputs.files(getSubmoduleVersions.outputs) + ext.outputFile = file("$project.projectDir/src/main/resources/lib/rs/runtime-version.properties") + + doLast { + def upToDateProps = new Properties() + getSubmoduleVersions.outputFile.withReader { r -> upToDateProps.load(r) } + outputFile.text = "rs = " + upToDateProps.get("rs") + "\n" + } +} + +tasks.register('checkRuntimeVersionFileUpToDate') { + description('Check that the runtime version recorded in the built Jar for LFC matches the version of the checked out submodule') + dependsOn getSubmoduleVersions + inputs.file "$project.projectDir/src/main/resources/lib/rs/runtime-version.properties" + inputs.dir "$project.projectDir/src/main/resources/lib/rs/reactor-rs" + + doLast { + def rtProps = new Properties() + updateRustRuntime.outputFile.withReader { r -> rtProps.load(r) } + def upToDateProps = new Properties() + getSubmoduleVersions.outputFile.withReader { r -> upToDateProps.load(r) } + + upToDateProps.each { language, rev -> + def actualLanguage = rtProps.get(language) + if (actualLanguage == null) + return + if (actualLanguage != rev) { + logger.error("Runtime for $language is not checked out at correct revision:\n" + + "expected: $rev\n" + + "actual: $actualLanguage\n" + + "You may need to call `./gradlew updateRustRuntime`.") + throw new GradleException("Rust runtime is not up to date") + } else { + logger.info("Success: Runtime for $language is checked out at expected revision $rev") + } + } + } +} +test.dependsOn('checkRuntimeVersionFileUpToDate') \ No newline at end of file From be36edd6d7ba948440e08a6ba9a9ca1cbff17995 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 26 May 2023 17:00:36 +0200 Subject: [PATCH 516/709] bugfix --- test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf | 1 - util/scripts/launch.ps1 | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf index aac8e34712..fa9c7b25e4 100644 --- a/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf +++ b/test/Cpp/src/enclave/EnclaveCommunicationDelayedLocalEvents.lf @@ -21,7 +21,6 @@ reactor Sink { auto value = *in.get(); reactor::log::Info() << "Received " << value; auto expected = 100ms * value + 50ms; - 0 = 1; if (get_elapsed_logical_time() != expected) { reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time(); exit(1); diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index 6f418a6a60..ffeee518ca 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -29,4 +29,4 @@ $base="$PSScriptRoot\..\..\" $gradlew="${base}/gradlew.bat" # invoke script -& "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args "$@" \ No newline at end of file +& "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args "$args" \ No newline at end of file From 7c6269737011c28ea18aecb19112b6ef0c148bd5 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 17:34:52 -0700 Subject: [PATCH 517/709] Changes to experiment with the readability of CI results --- .github/workflows/all-non-target-specific.yml | 3 ++- .github/workflows/all-targets.yml | 13 +++++++------ .github/workflows/build-trace-tools.yml | 2 +- .github/workflows/c-tests.yml | 2 +- .github/workflows/only-c.yml | 8 ++++---- .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 18102e87be..5e6d27221a 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,4 +1,5 @@ -name: CI (non-target-specific) +# Non-target-specific tests to run on PRs that are ready for review. +name: CI (main) on: workflow_dispatch: diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 16df3b7c83..682e130c44 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -1,4 +1,5 @@ -name: CI (target-specific) +# Target-specific tests to run on PRs that are ready for review. +name: CI (main) on: workflow_dispatch: @@ -19,35 +20,35 @@ concurrency: jobs: # Run the C tests. - c-tests: + c: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-c.yml with: all: true # Run the C++ tests. - cpp-tests: + cpp: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-cpp.yml with: all: true # Run the Python tests. - py-tests: + py: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-py.yml with: all: true # Run the Rust tests. - rs-tests: + rs: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-rs.yml with: all: true # Run the TypeScript tests. - ts-tests: + ts: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-ts.yml with: diff --git a/.github/workflows/build-trace-tools.yml b/.github/workflows/build-trace-tools.yml index 207fe4deb7..d451b3786c 100644 --- a/.github/workflows/build-trace-tools.yml +++ b/.github/workflows/build-trace-tools.yml @@ -1,4 +1,4 @@ -name: Build the tools for processing execution traces +name: Build trace tools on: workflow_call: diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 199fb3b8dd..47eaaf7b80 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -22,7 +22,7 @@ on: type: boolean jobs: - c-tests: + run: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index c635aba13c..7f398f75ac 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -24,28 +24,28 @@ concurrency: jobs: # Run the C benchmark tests. - c-benchmark-tests: + benchmark-tests: if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main with: target: 'C' # Run the C integration tests. - c-tests: + tests: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Arduino integration tests. - c-arduino-tests: + arduino-tests: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. - c-zephyr-tests: + zephyr-tests: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-zephyr-tests.yml diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index c4038d27af..e8ea1eac77 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -18,7 +18,7 @@ on: type: boolean jobs: - py: + run: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index f4bc181dda..dae04b2dc8 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -21,7 +21,7 @@ on: type: boolean jobs: - rs: + run: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 22379b2f5d..c70a356a13 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - ts: + run: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} From eb2b20bf63eba474e94c45c4b84f7eaf1d63fef0 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 17:44:28 -0700 Subject: [PATCH 518/709] More tweaking of labels --- .github/workflows/c-tests.yml | 2 +- .github/workflows/c-zephyr-tests.yml | 2 +- .github/workflows/only-c.yml | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 47eaaf7b80..bb00466153 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -22,7 +22,7 @@ on: type: boolean jobs: - run: + os-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 288dd54b6d..2af2d2d534 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -18,7 +18,7 @@ on: type: string jobs: - c-zephyr: + zephyr-tests: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 7f398f75ac..813913abd3 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -23,34 +23,34 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: - # Run the C benchmark tests. - benchmark-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main - with: - target: 'C' - # Run the C integration tests. - tests: + default: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} + # Run the C benchmark tests. + benchmarking: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + with: + target: 'C' + # Run the C Arduino integration tests. - arduino-tests: + arduino: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. - zephyr-tests: + zephyr: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. - ccpp-tests: + ccpp: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: From a9ea2e4d1cd151e5787347a813d9a6d79ba528ed Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 17:47:28 -0700 Subject: [PATCH 519/709] More label tweaks --- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/cpp-ros2-tests.yml | 2 +- .github/workflows/cpp-tests.yml | 2 +- .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 873c81b871..c8ba27d144 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -22,7 +22,7 @@ on: type: boolean jobs: - c-arduino: + arduino-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index e48ea2e360..7b3256f130 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -11,7 +11,7 @@ on: type: string jobs: - cpp-ros2: + cpp-ros2-tests: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index aa138feaaf..2615b76497 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -15,7 +15,7 @@ on: type: boolean jobs: - cpp: + cpp-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index e8ea1eac77..4890d96bc1 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -18,7 +18,7 @@ on: type: boolean jobs: - run: + os-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index dae04b2dc8..26de34e4fe 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -21,7 +21,7 @@ on: type: boolean jobs: - run: + os-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} From cdd0f807fbe1b21f3fcc3e8095c9ad93fb8e2f5d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 17:53:05 -0700 Subject: [PATCH 520/709] Fix bug introduced by renaming --- .github/workflows/all-non-target-specific.yml | 2 +- .github/workflows/all-targets.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 5e6d27221a..5497de8ceb 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -14,7 +14,7 @@ env: vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_path }} + group: all-non-target-specific-${{ github.ref }}-${{ github.event_path }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 682e130c44..23d21e6dde 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -14,7 +14,7 @@ env: vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0 concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_path }} + group: all-targets-${{ github.ref }}-${{ github.event_path }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: From e8379d0b2512e0d6853f7aac44c98647360ffb48 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 18:01:00 -0700 Subject: [PATCH 521/709] More labeling --- .github/workflows/cli-tests.yml | 2 +- .github/workflows/lsp-tests.yml | 2 +- .github/workflows/non-target-specific-extended.yml | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 452b08faf6..ce559792f8 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - cli: + cli-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index aa2fcd7f16..7641de9f81 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - lsp: + lsp-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 2b3bfe8c12..b8d3d5829b 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -31,30 +31,30 @@ concurrency: jobs: # Test the Gradle build. - build: + building: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/build.yml # Build the tools used for processing execution traces - build-tracing-tools: + tracing: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/build-trace-tools.yml with: all-platforms: ${{ !github.event.pull_request.draft }} - check-format: + formatting: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/check-format.yml # Run tests for the standalone compiler. - cli-tests: + cli: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/cli-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. - lsp-tests: + lsp: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/lsp-tests.yml with: From aa2790b499e435d76f23fd20e1e4b7d87f7c7a58 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 22:08:43 -0700 Subject: [PATCH 522/709] Some more label changes --- .github/workflows/all-non-target-specific.yml | 2 +- .github/workflows/all-targets.yml | 2 +- .github/workflows/cli-tests.yml | 2 +- .github/workflows/lsp-tests.yml | 2 +- .github/workflows/non-target-specific-extended.yml | 2 +- .github/workflows/non-target-specific.yml | 6 +++--- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 5497de8ceb..3d9eb80511 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,5 +1,5 @@ # Non-target-specific tests to run on PRs that are ready for review. -name: CI (main) +name: Catch-all on: workflow_dispatch: diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 23d21e6dde..0e32791c2e 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -1,5 +1,5 @@ # Target-specific tests to run on PRs that are ready for review. -name: CI (main) +name: Catch-all on: workflow_dispatch: diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index ce559792f8..7f643a1be6 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - cli-tests: + test-cli: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index 7641de9f81..bcf1609940 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - lsp-tests: + test-lsp: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index b8d3d5829b..e33902d63e 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -1,4 +1,4 @@ -name: Additional non-target-specific tests +name: Non-target-specific extended on: workflow_dispatch: diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index f662451186..2f7ecedbcd 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -1,4 +1,4 @@ -name: Non-target-specific tests +name: Non-target-specific on: workflow_dispatch: @@ -20,13 +20,13 @@ concurrency: jobs: # Run the unit tests. - unit-tests: + junit: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/unit-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the serialization tests - serialization-tests: + serialization: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/serialization-tests.yml From 3f354bd1d535f3f9a97750bf1af33711e2d1d7a4 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 22:23:18 -0700 Subject: [PATCH 523/709] Update .github/workflows/only-ts.yml --- .github/workflows/only-ts.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index f6afde4b0b..b8a48bc09e 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -1,4 +1,4 @@ -name: Rust +name: TypeScript on: workflow_dispatch: From 528e7785b78572b0f30d033c47c06ebf3f12f217 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 26 May 2023 22:23:26 -0700 Subject: [PATCH 524/709] Update .github/workflows/serialization-tests.yml --- .github/workflows/serialization-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index dffbe83e1f..53a89ffe52 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -8,7 +8,7 @@ on: type: string jobs: - serialization: + serialization-tests: runs-on: ubuntu-latest steps: - name: Check out lingua-franca repository From cc3fe2e2c8478f537bf479428621ca8af4b12c1e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 25 May 2023 22:15:32 -0700 Subject: [PATCH 525/709] First working smoke test. --- .../src/main/java/lfformat/LfFormatStep.java | 67 +++++++++++++------ .../src/main/java/org/lflang/cli/CliBase.java | 31 ++++++++- .../lff/src/main/java/org/lflang/cli/Lff.java | 28 ++++---- 3 files changed, 93 insertions(+), 33 deletions(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index fcc15feaf1..eacb08395a 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -1,11 +1,18 @@ package lfformat; +import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; import java.io.Serializable; +import java.io.Writer; +import java.lang.ProcessBuilder.Redirect; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; @@ -27,32 +34,44 @@ public static FormatterStep create(File projectRoot) { } /** Implement LF-specific formatting functionality. */ - public static class Step implements FormatterStep, Serializable { + public static class Step implements FormatterStep { // The use of the static keyword here is a workaround for serialization difficulties. /** The path to the lingua-franca repository. */ private static Path projectRoot; + private static Process formatter; + private static Writer writer; + + private static BufferedReader reader; + private static BufferedReader error; + @Override public String format( @SuppressWarnings("NullableProblems") String rawUnix, @SuppressWarnings("NullableProblems") File file) throws IOException, InterruptedException { - Process p = runFormatter(file); StringBuilder output = new StringBuilder(); - BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line; - while ((line = in.readLine()) != null) { - output.append(line).append("\n"); + getFormatter(); + try { + writer.write(file.getAbsoluteFile().toString().strip() + "\n"); + writer.flush(); + } catch (IOException e) { + getFormatter().waitFor(); + error.lines().forEach(System.out::println); + formatter = null; + throw new RuntimeException("Failed to format " + file + ".\nPlease ensure that this file passes validator checks."); } - int returnCode = p.waitFor(); - if (returnCode != 0) { - throw new RuntimeException("Failed to reformat file. Exit code: " + returnCode + " Output: " + output.toString()); + String line = reader.readLine(); + while (line != null && !line.endsWith("\0")) { + if (!output.isEmpty()) output.append("\n"); + output.append(line); + line = reader.readLine(); } return output.toString(); } - /** Run the formatter on the given file and return the resulting process handle. */ - private Process runFormatter(File file) throws IOException { + private static Process getFormatter() throws IOException { + if (formatter != null) return formatter; final Path lffPath = Path.of( "org.lflang", @@ -63,17 +82,27 @@ private Process runFormatter(File file) throws IOException { "lff", "bin", "lff"); - // It looks silly to invoke Java from Java, but it is necessary in - // order to break the circularity of needing the program to be built - // in order for it to be built. - return new ProcessBuilder( - List.of( - lffPath.toString(), - "--dry-run", - file.getAbsoluteFile().toString())) + formatter = new ProcessBuilder( + List.of( + lffPath.toString(), + "--dry-run", + "--stdin")) .start(); + writer = new BufferedWriter(new OutputStreamWriter(formatter.getOutputStream())); + reader = new BufferedReader(new InputStreamReader(formatter.getInputStream())); + error = new BufferedReader(new InputStreamReader(formatter.getErrorStream())); + return formatter; } +// /** Run the formatter on the given file and return the resulting process handle. */ +// private Process runFormatter(File file) throws IOException { +// // It looks silly to invoke Java from Java, but it is necessary in +// // order to break the circularity of needing the program to be built +// // in order for it to be built. +// var formatter = getFormatter(); +// return formatter; +// } + @SuppressWarnings("NullableProblems") @Override public String getName() { diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java index a6c1c805ed..8a92619193 100644 --- a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java +++ b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java @@ -7,8 +7,13 @@ import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -20,6 +25,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.xtext.util.CancelIndicator; +import org.eclipse.xtext.util.RuntimeIOException; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.eclipse.xtext.validation.Issue; @@ -62,6 +68,9 @@ static class MutuallyExclusive { @Option(names = "--json-file", description = "JSON file containing CLI arguments.") private Path jsonFile; + + @Option(names = "--stdin", description = "Read paths to Lingua Franca programs from stdin.") + private boolean stdin; } @ArgGroup(exclusive = true, multiplicity = "1") @@ -164,8 +173,22 @@ protected Path toAbsolutePath(Path other) { * @return Validated input paths. */ protected List getInputPaths() { - List paths = - topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); + List paths; + if (topLevelArg.stdin) { + var input = new BufferedInputStream(System.in); + var reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)); + String line; + try { + line = reader.readLine(); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + if (line == null) return List.of(); + return List.of(Path.of(line)); + } else { + paths = + topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); + } for (Path path : paths) { if (!Files.exists(path)) { @@ -176,6 +199,10 @@ protected List getInputPaths() { return paths; } + protected final boolean stdinMode() { + return topLevelArg.stdin; + } + /** * Returns the validated, normalized output path. * diff --git a/org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java b/org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java index f4f7714119..3626bc1f1c 100644 --- a/org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java +++ b/org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java @@ -80,20 +80,23 @@ public static void main(Io io, final String... args) { /** Validates all paths and invokes the formatter on the input paths. */ @Override public void doRun() { - List paths = getInputPaths(); - final Path outputRoot = getOutputRoot(); + List paths; + do { + paths = getInputPaths(); + final Path outputRoot = getOutputRoot(); - try { - // Format all files defined by the list of paths. - formatAllFiles(paths, outputRoot); + try { + // Format all files defined by the list of paths. + formatAllFiles(paths, outputRoot); - exitIfCollectedErrors(); - if (!dryRun || verbose) { - reporter.printInfo("Done formatting."); + exitIfCollectedErrors(); + if (!dryRun || verbose) { + reporter.printInfo("Done formatting."); + } + } catch (RuntimeException e) { + reporter.printFatalErrorAndExit("An unexpected error occurred:", e); } - } catch (RuntimeException e) { - reporter.printFatalErrorAndExit("An unexpected error occurred:", e); - } + } while (stdinMode() && !paths.isEmpty()); } /* @@ -155,7 +158,8 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { FormattingUtils.render(resource.getContents().get(0), lineLength); if (dryRun) { - io.getOut().print(formattedFileContents); + io.getOut().println(formattedFileContents); + io.getOut().println("\0"); } else { try { FileUtil.writeToFile(formattedFileContents, outputPath, true); From aea87a0814ccf76fea9b4a74548e7a5aaf582014 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 26 May 2023 12:33:08 -0700 Subject: [PATCH 526/709] Handle shutdown. This terminates the spawned formatter by closing its input stream. The formatter should detect that the stream is closed and understand that it will not receive any more files to format and exit gracefully. This prevents the formatter from outliving its Gradle daemon. If the daemon is terminated forcefully e.g. with a -9 SIGTERM rather than a -15 SIGKILL, then this will not work. Otherwise I believe that this should release the resource (get rid of the spawned formatter) correctly. --- .../src/main/java/lfformat/LfFormatStep.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index eacb08395a..8b147accb0 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -9,12 +9,15 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.PrintWriter; import java.io.Reader; import java.io.Serializable; import java.io.Writer; import java.lang.ProcessBuilder.Redirect; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Locale; @@ -28,16 +31,17 @@ public final class LfFormatStep { private LfFormatStep() {} /** Return a {@code FormatterStep} for LF code. */ - public static FormatterStep create(File projectRoot) { + public static FormatterStep create(File projectRoot) throws IOException { Step.projectRoot = projectRoot.toPath(); - return new Step(); + return Step.getInstance(); } /** Implement LF-specific formatting functionality. */ - public static class Step implements FormatterStep { + private static class Step implements FormatterStep { // The use of the static keyword here is a workaround for serialization difficulties. /** The path to the lingua-franca repository. */ private static Path projectRoot; + private static Step instance; private static Process formatter; private static Writer writer; @@ -45,18 +49,36 @@ public static class Step implements FormatterStep { private static BufferedReader reader; private static BufferedReader error; + public static Step getInstance() throws IOException { + if (instance == null) instance = new Step(); + return instance; + } + + private Step() throws IOException { + initializeFormatter(); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + writer.close(); + formatter.waitFor(); + reader.close(); + error.close(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + })); + } + @Override public String format( @SuppressWarnings("NullableProblems") String rawUnix, @SuppressWarnings("NullableProblems") File file) throws IOException, InterruptedException { StringBuilder output = new StringBuilder(); - getFormatter(); try { writer.write(file.getAbsoluteFile().toString().strip() + "\n"); writer.flush(); } catch (IOException e) { - getFormatter().waitFor(); + formatter.waitFor(); error.lines().forEach(System.out::println); formatter = null; throw new RuntimeException("Failed to format " + file + ".\nPlease ensure that this file passes validator checks."); @@ -70,8 +92,7 @@ public String format( return output.toString(); } - private static Process getFormatter() throws IOException { - if (formatter != null) return formatter; + private void initializeFormatter() throws IOException { final Path lffPath = Path.of( "org.lflang", @@ -91,7 +112,6 @@ private static Process getFormatter() throws IOException { writer = new BufferedWriter(new OutputStreamWriter(formatter.getOutputStream())); reader = new BufferedReader(new InputStreamReader(formatter.getInputStream())); error = new BufferedReader(new InputStreamReader(formatter.getErrorStream())); - return formatter; } // /** Run the formatter on the given file and return the resulting process handle. */ From 0a733c4319eec54c7f08354c0f937eb0c029c58f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 26 May 2023 13:45:30 -0700 Subject: [PATCH 527/709] Apply Java formatter. --- .../src/main/java/lfformat/LfFormatStep.java | 48 +++++++++---------- .../src/main/java/org/lflang/cli/CliBase.java | 4 +- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 8b147accb0..24b2df4d25 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -1,23 +1,15 @@ package lfformat; -import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Serializable; import java.io.Writer; -import java.lang.ProcessBuilder.Redirect; import java.net.URL; import java.net.URLClassLoader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Locale; @@ -41,6 +33,7 @@ private static class Step implements FormatterStep { // The use of the static keyword here is a workaround for serialization difficulties. /** The path to the lingua-franca repository. */ private static Path projectRoot; + private static Step instance; private static Process formatter; @@ -56,16 +49,19 @@ public static Step getInstance() throws IOException { private Step() throws IOException { initializeFormatter(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - writer.close(); - formatter.waitFor(); - reader.close(); - error.close(); - } catch (IOException | InterruptedException e) { - throw new RuntimeException(e); - } - })); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + try { + writer.close(); + formatter.waitFor(); + reader.close(); + error.close(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + })); } @Override @@ -114,14 +110,14 @@ private void initializeFormatter() throws IOException { error = new BufferedReader(new InputStreamReader(formatter.getErrorStream())); } -// /** Run the formatter on the given file and return the resulting process handle. */ -// private Process runFormatter(File file) throws IOException { -// // It looks silly to invoke Java from Java, but it is necessary in -// // order to break the circularity of needing the program to be built -// // in order for it to be built. -// var formatter = getFormatter(); -// return formatter; -// } + // /** Run the formatter on the given file and return the resulting process handle. */ + // private Process runFormatter(File file) throws IOException { + // // It looks silly to invoke Java from Java, but it is necessary in + // // order to break the circularity of needing the program to be built + // // in order for it to be built. + // var formatter = getFormatter(); + // return formatter; + // } @SuppressWarnings("NullableProblems") @Override diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java index 8a92619193..6c7cad18fc 100644 --- a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java +++ b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java @@ -7,7 +7,6 @@ import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; @@ -186,8 +185,7 @@ protected List getInputPaths() { if (line == null) return List.of(); return List.of(Path.of(line)); } else { - paths = - topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); + paths = topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); } for (Path path : paths) { From 9efabae1ca04c541c531ded450d8167c223ea977 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 26 May 2023 13:56:23 -0700 Subject: [PATCH 528/709] Address warnings. --- buildSrc/src/main/java/lfformat/LfFormatStep.java | 11 +---------- .../base/src/main/java/org/lflang/cli/CliBase.java | 3 +-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 24b2df4d25..9ae518c63f 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -67,7 +67,7 @@ private Step() throws IOException { @Override public String format( @SuppressWarnings("NullableProblems") String rawUnix, - @SuppressWarnings("NullableProblems") File file) + File file) throws IOException, InterruptedException { StringBuilder output = new StringBuilder(); try { @@ -110,15 +110,6 @@ private void initializeFormatter() throws IOException { error = new BufferedReader(new InputStreamReader(formatter.getErrorStream())); } - // /** Run the formatter on the given file and return the resulting process handle. */ - // private Process runFormatter(File file) throws IOException { - // // It looks silly to invoke Java from Java, but it is necessary in - // // order to break the circularity of needing the program to be built - // // in order for it to be built. - // var formatter = getFormatter(); - // return formatter; - // } - @SuppressWarnings("NullableProblems") @Override public String getName() { diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java index 6c7cad18fc..3a8724f816 100644 --- a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java +++ b/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java @@ -24,7 +24,6 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.xtext.util.CancelIndicator; -import org.eclipse.xtext.util.RuntimeIOException; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.eclipse.xtext.validation.Issue; @@ -180,7 +179,7 @@ protected List getInputPaths() { try { line = reader.readLine(); } catch (IOException e) { - throw new RuntimeIOException(e); + throw new RuntimeException(e); } if (line == null) return List.of(); return List.of(Path.of(line)); From 32e74b54987d0ec106b6d7b012d8e093f4242ce1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 26 May 2023 14:04:38 -0700 Subject: [PATCH 529/709] Apply Java formatter. --- buildSrc/src/main/java/lfformat/LfFormatStep.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 9ae518c63f..dfa788562a 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -65,9 +65,7 @@ private Step() throws IOException { } @Override - public String format( - @SuppressWarnings("NullableProblems") String rawUnix, - File file) + public String format(@SuppressWarnings("NullableProblems") String rawUnix, File file) throws IOException, InterruptedException { StringBuilder output = new StringBuilder(); try { From 433b9e66f7c912187783fad6cfcc684c788ead14 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 26 May 2023 16:00:11 -0700 Subject: [PATCH 530/709] Bugfix. --- buildSrc/src/main/java/lfformat/LfFormatStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index dfa788562a..18d709a782 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -74,7 +74,7 @@ public String format(@SuppressWarnings("NullableProblems") String rawUnix, File } catch (IOException e) { formatter.waitFor(); error.lines().forEach(System.out::println); - formatter = null; + initializeFormatter(); throw new RuntimeException("Failed to format " + file + ".\nPlease ensure that this file passes validator checks."); } String line = reader.readLine(); From fe8dfb901332f5bd7bde1a748f0fb05b566391f3 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 12:31:48 -0700 Subject: [PATCH 531/709] Work around build dependency issue. The problem was not that Gradle runs any spotlessLinguaFranca tasks as part of its other operations, but that it configures the task before starting any other operation (including clean). The solution is to start the formatter lazily -- to wait until spotlessLinguaFranca actually operates on a file before trying to start up the formatter process. --- build.gradle | 12 ++-- .../src/main/java/lfformat/LfFormatStep.java | 60 +++++++++---------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/build.gradle b/build.gradle index 43a28acccf..9164e447fc 100644 --- a/build.gradle +++ b/build.gradle @@ -16,15 +16,15 @@ spotless { endWithNewline() } -// format 'linguaFranca', { -// addStep(LfFormatStep.create(project.projectDir)) -// target 'test/*/src/**/*.lf' // you have to set the target manually -// targetExclude 'test/**/failing/**' -// } + format 'linguaFranca', { + addStep(LfFormatStep.create()) + target 'test/*/src/**/*.lf' // you have to set the target manually + targetExclude 'test/**/failing/**' + } } -//spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") +spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") distributions { diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 18d709a782..92489acbfc 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -8,12 +8,8 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; -import java.net.URL; -import java.net.URLClassLoader; import java.nio.file.Path; import java.util.List; -import java.util.Locale; -import java.util.ResourceBundle; /** * {@code LfFormatStep} is used by the Spotless Gradle plugin as a custom formatting step for @@ -23,18 +19,14 @@ public final class LfFormatStep { private LfFormatStep() {} /** Return a {@code FormatterStep} for LF code. */ - public static FormatterStep create(File projectRoot) throws IOException { - Step.projectRoot = projectRoot.toPath(); - return Step.getInstance(); + public static FormatterStep create() throws IOException, InterruptedException { + return new Step(); } /** Implement LF-specific formatting functionality. */ private static class Step implements FormatterStep { // The use of the static keyword here is a workaround for serialization difficulties. /** The path to the lingua-franca repository. */ - private static Path projectRoot; - - private static Step instance; private static Process formatter; private static Writer writer; @@ -42,31 +34,14 @@ private static class Step implements FormatterStep { private static BufferedReader reader; private static BufferedReader error; - public static Step getInstance() throws IOException { - if (instance == null) instance = new Step(); - return instance; - } - - private Step() throws IOException { - initializeFormatter(); - Runtime.getRuntime() - .addShutdownHook( - new Thread( - () -> { - try { - writer.close(); - formatter.waitFor(); - reader.close(); - error.close(); - } catch (IOException | InterruptedException e) { - throw new RuntimeException(e); - } - })); + private Step() throws IOException, InterruptedException { + terminateFormatter(); } @Override public String format(@SuppressWarnings("NullableProblems") String rawUnix, File file) throws IOException, InterruptedException { + initializeFormatter(); StringBuilder output = new StringBuilder(); try { writer.write(file.getAbsoluteFile().toString().strip() + "\n"); @@ -74,6 +49,7 @@ public String format(@SuppressWarnings("NullableProblems") String rawUnix, File } catch (IOException e) { formatter.waitFor(); error.lines().forEach(System.out::println); + formatter = null; initializeFormatter(); throw new RuntimeException("Failed to format " + file + ".\nPlease ensure that this file passes validator checks."); } @@ -86,7 +62,9 @@ public String format(@SuppressWarnings("NullableProblems") String rawUnix, File return output.toString(); } - private void initializeFormatter() throws IOException { + /** Idempotently initialize the formatter. */ + private static void initializeFormatter() throws IOException { + if (formatter != null) return; final Path lffPath = Path.of( "org.lflang", @@ -106,6 +84,26 @@ private void initializeFormatter() throws IOException { writer = new BufferedWriter(new OutputStreamWriter(formatter.getOutputStream())); reader = new BufferedReader(new InputStreamReader(formatter.getInputStream())); error = new BufferedReader(new InputStreamReader(formatter.getErrorStream())); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + try { + terminateFormatter(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + })); + } + + /** Idempotently trigger a graceful termination of the formatter. */ + private static void terminateFormatter() throws IOException, InterruptedException { + if (formatter == null) return; + writer.close(); + formatter.waitFor(); + reader.close(); + error.close(); + formatter = null; } @SuppressWarnings("NullableProblems") From 519fb5eda62de7992f5c59bd04c8f6de3040eced Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 14:46:00 -0700 Subject: [PATCH 532/709] Try to put check-diff in reusable workflow. --- .github/scripts/changed.sh | 10 ++++ .github/workflows/all-non-target-specific.yml | 46 +++++++++++++++---- .github/workflows/all-targets.yml | 22 +++++---- .github/workflows/check-diff.yml | 41 +++++++++++++++++ .../non-target-specific-extended.yml | 13 ------ .github/workflows/non-target-specific.yml | 3 -- .github/workflows/only-c.yml | 7 --- .github/workflows/only-cpp.yml | 6 --- .github/workflows/only-py.yml | 6 --- .github/workflows/only-rs.yml | 6 --- .github/workflows/only-ts.yml | 6 --- 11 files changed, 99 insertions(+), 67 deletions(-) create mode 100644 .github/scripts/changed.sh create mode 100644 .github/workflows/check-diff.yml diff --git a/.github/scripts/changed.sh b/.github/scripts/changed.sh new file mode 100644 index 0000000000..9fc3a4388e --- /dev/null +++ b/.github/scripts/changed.sh @@ -0,0 +1,10 @@ +changes() { + git diff --name-only --diff-filter=AMDR --cached origin/master +} + +if changes | grep -q $1; then + echo "::set-output name=CHANGED_$2::1" +else + echo "::set-output name=CHANGED_$2::0" +fi + diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 3d9eb80511..73b63b53e3 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -19,16 +19,42 @@ concurrency: jobs: - # Run the non-target-specific tests. - non-target-specific: - if: ${{ !github.event.pull_request.draft }} - uses: ./.github/workflows/non-target-specific.yml + junit: + uses: ./.github/workflows/unit-tests.yml with: - all: true + all-platforms: ${{ !github.event.pull_request.draft }} - # Run the non-target-specific tests. - non-target-specific-extended: - if: ${{ !github.event.pull_request.draft }} - uses: ./.github/workflows/non-target-specific-extended.yml + # Run the serialization tests + serialization: + if: ${{ github.event.pull_request.draft }} + uses: ./.github/workflows/serialization-tests.yml + + # Test the Gradle build. + building: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/build.yml + + # Build the tools used for processing execution traces + tracing: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/build-trace-tools.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + + formatting: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/check-format.yml + + # Run tests for the standalone compiler. + cli: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/cli-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + + # Run language server tests. + lsp: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/lsp-tests.yml with: - all: true + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 0e32791c2e..5257dc5d82 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -18,38 +18,40 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: + check: + uses: ./.github/workflows/check-diff.yml - # Run the C tests. c: - if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-c.yml with: all: true + needs: check + if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-c == 1 }} - # Run the C++ tests. cpp: - if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-cpp.yml with: all: true + needs: check + if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-cpp == 1 }} - # Run the Python tests. py: - if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-py.yml with: all: true + needs: check + if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-py == 1 }} - # Run the Rust tests. rs: - if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-rs.yml with: all: true + needs: check + if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-rs == 1 }} - # Run the TypeScript tests. ts: - if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/only-ts.yml with: all: true + needs: check + if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-ts == 1 }} diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml new file mode 100644 index 0000000000..9b30be2b1c --- /dev/null +++ b/.github/workflows/check-diff.yml @@ -0,0 +1,41 @@ +name: Check diff from master + +on: + workflow_call: + outputs: + changed-c: + value: ${{ jobs.check.outputs.changed-c }} + changed-cpp: + value: ${{ jobs.check.outputs.changed-cpp }} + changed-py: + value: ${{ jobs.check.outputs.changed-py }} + changed-rs: + value: ${{ jobs.check.outputs.changed-rs }} + changed-ts: + value: ${{ jobs.check.outputs.changed-ts }} + +jobs: + check: + runs-on: ubuntu-latest + outputs: + changed-c: ${{ steps.do.outputs.CHANGED_C }} + changed-cpp: ${{ steps.do.outputs.CHANGED_CPP }} + changed-py: ${{ steps.do.outputs.CHANGED_PY }} + changed-rs: ${{ steps.do.outputs.CHANGED_RS }} + changed-ts: ${{ steps.do.outputs.CHANGED_TS }} + steps: + - name: Check out lingua-franca repository + uses: actions/checkout@v3 + with: + repository: lf-lang/lingua-franca + submodules: true + fetch-depth: 0 + - id: do + run: | + wget https://raw.githubusercontent.com/lf-lang/lingua-franca/reduce-testing/.github/scripts/changed.sh + source changed.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/" C + source changed.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/" CPP + source changed.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/" PY + source changed.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/" RS + source changed.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/" TS + shell: bash diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index e33902d63e..bdfc4181aa 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -6,19 +6,6 @@ on: inputs: all: type: boolean - pull_request: - paths-ignore: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' - - 'org.lflang/src/lib/cpp/**' - - 'org.lflang/src/lib/py/**' - - 'org.lflang/src/lib/rs/**' - - 'org.lflang/src/lib/ts/**' env: # 2020.11 diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index 2f7ecedbcd..2ea4f4499d 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -6,9 +6,6 @@ on: inputs: all: type: boolean - pull_request: - branches-ignore: - - 'nightly' env: # 2020.11 diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 813913abd3..94f588c094 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -6,13 +6,6 @@ on: inputs: all: type: boolean - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/c/**' - - 'org.lflang/src/lib/c/**' - - 'org.lflang/src/lib/platform/**' env: # 2020.11 diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index 22bc7fb814..54bd85a24f 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -6,12 +6,6 @@ on: inputs: all: type: boolean - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/cpp/**' - - 'org.lflang/src/lib/cpp/**' env: # 2020.11 diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index 5adf989661..be3aa2f0f8 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -6,12 +6,6 @@ on: inputs: all: type: boolean - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/python/**' - - 'org.lflang/src/lib/py/**' env: # 2020.11 diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 1dd0dfbf56..d944a5bb2f 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -6,12 +6,6 @@ on: inputs: all: type: boolean - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/rust/**' - - 'org.lflang/src/lib/rs/**' env: # 2020.11 diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index b8a48bc09e..216b5bca9c 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -6,12 +6,6 @@ on: inputs: all: type: boolean - pull_request: - branches-ignore: - - 'nightly' - paths: - - 'org.lflang/src/org/lflang/generator/ts/**' - - 'org.lflang/src/lib/ts/**' env: # 2020.11 From 8cc809dc1e89f4fd9d30d70b1e2a76fc753b0345 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 16:40:32 -0700 Subject: [PATCH 533/709] More increases in selectivity. --- .github/workflows/all-non-target-specific.yml | 27 +++++++++---------- .github/workflows/all-targets.yml | 27 +++++++++++-------- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/c-tests.yml | 2 +- .github/workflows/check-diff.yml | 4 +++ .github/workflows/cli-tests.yml | 2 +- .github/workflows/cpp-tests.yml | 4 +-- .github/workflows/lsp-tests.yml | 2 ++ .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- .github/workflows/ts-tests.yml | 1 + .github/workflows/unit-tests.yml | 1 + 12 files changed, 44 insertions(+), 32 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 73b63b53e3..166694a51f 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -18,43 +18,42 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: + check-diff: + uses: ./.github/workflows/check-diff.yml junit: uses: ./.github/workflows/unit-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} - - # Run the serialization tests - serialization: - if: ${{ github.event.pull_request.draft }} - uses: ./.github/workflows/serialization-tests.yml + all-platforms: ${{ !github.event.pull_request.draft }} # Test the Gradle build. building: - if: ${{ inputs.all || github.event.pull_request.draft }} + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/build.yml # Build the tools used for processing execution traces tracing: - if: ${{ inputs.all || github.event.pull_request.draft }} + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-tracing == 1 }} uses: ./.github/workflows/build-trace-tools.yml + needs: + check-diff with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} formatting: - if: ${{ inputs.all || github.event.pull_request.draft }} + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/check-format.yml # Run tests for the standalone compiler. cli: - if: ${{ inputs.all || github.event.pull_request.draft }} + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/cli-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} # Run language server tests. lsp: - if: ${{ inputs.all || github.event.pull_request.draft }} + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/lsp-tests.yml with: - all-platforms: ${{ !github.event.pull_request.draft }} + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 5257dc5d82..0948665eea 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -18,40 +18,45 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: - check: + check-diff: uses: ./.github/workflows/check-diff.yml c: uses: ./.github/workflows/only-c.yml with: all: true - needs: check - if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-c == 1 }} + needs: check-diff + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-c == 1 }} cpp: uses: ./.github/workflows/only-cpp.yml with: all: true - needs: check - if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-cpp == 1 }} + needs: check-diff + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-cpp == 1 }} py: uses: ./.github/workflows/only-py.yml with: all: true - needs: check - if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-py == 1 }} + needs: check-diff + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-py == 1 }} rs: uses: ./.github/workflows/only-rs.yml with: all: true - needs: check - if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-rs == 1 }} + needs: check-diff + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-rs == 1 }} ts: uses: ./.github/workflows/only-ts.yml with: all: true - needs: check - if: ${{ !github.event.pull_request.draft || needs.check.outputs.changed-ts == 1 }} + needs: check-diff + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-ts == 1 }} + + serialization: + if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-c == 1 || needs.check-diff.outputs.changed-py == 1 || needs.check-diff.outputs.changed-ts == 1 }} + needs: check-diff + uses: ./.github/workflows/serialization-tests.yml diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index c8ba27d144..5f5358301a 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -70,4 +70,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.runtime-ref && runner.os == 'Linux' }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index bb00466153..072151d219 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -72,4 +72,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.compiler-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index 9b30be2b1c..a9d169b9c8 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -13,6 +13,8 @@ on: value: ${{ jobs.check.outputs.changed-rs }} changed-ts: value: ${{ jobs.check.outputs.changed-ts }} + changed-tracing: + value: ${{ jobs.check.outputs.changed-tracing }} jobs: check: @@ -23,6 +25,7 @@ jobs: changed-py: ${{ steps.do.outputs.CHANGED_PY }} changed-rs: ${{ steps.do.outputs.CHANGED_RS }} changed-ts: ${{ steps.do.outputs.CHANGED_TS }} + changed-tracing: ${{ steps.do.outputs.CHANGED_TRACING }} steps: - name: Check out lingua-franca repository uses: actions/checkout@v3 @@ -38,4 +41,5 @@ jobs: source changed.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/" PY source changed.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/" RS source changed.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/" TS + source changed.sh "util/tracing" TRACING shell: bash diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 7f643a1be6..40cd92ec37 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -48,4 +48,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ runner.os == 'Linux' }} + if: ${{ runner.os == 'Linux' && inputs.all-platforms }} diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 2615b76497..dbee4e2ac5 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -55,7 +55,7 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.runtime-ref && inputs.all-platforms }} # i.e., if this is part of the main repo's CI - name: Collect reactor-cpp coverage data run: | lcov --capture --directory test/Cpp --output-file coverage.info @@ -74,4 +74,4 @@ jobs: file: reactor-cpp.info fail_ci_if_error: false verbose: true - if: matrix.platform == 'ubuntu-latest' + if: ${{ runner.os == 'Linux' && inputs.all-platforms }} diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index bcf1609940..bbba12f03c 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -76,6 +76,7 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true + if: ${{ runner.os == 'Linux' && inputs.all-platforms }} - name: Install pylint run: python3 -m pip install pylint if: ${{ runner.os != 'macOS' }} @@ -90,3 +91,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true + if: ${{ runner.os == 'Linux' && inputs.all-platforms }} diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 4890d96bc1..8dc7641ed2 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -68,4 +68,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.compiler-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index 26de34e4fe..e5d0a4681e 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -75,4 +75,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true - if: ${{ !inputs.compiler-ref }} # i.e., if this is part of the main repo's CI + if: ${{ !inputs.compiler-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index c70a356a13..5afcbc231d 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -40,3 +40,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true + if: ${{ runner.os == 'Linux' && inputs.all-platforms }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c8cbe1fd1f..75dc336058 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -30,3 +30,4 @@ jobs: file: org.lflang.tests/build/reports/xml/jacoco fail_ci_if_error: false verbose: true + if: ${{ runner.os == 'Linux' && inputs.all-platforms }} From eef1f96c3cff4665994979d2a1eef3dbeb2b30ce Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 16:49:56 -0700 Subject: [PATCH 534/709] Check out the same submodule as in master. I had pushed a trivial whitespace change to main because I added yaml files to the formatter configuration, but to keep things simple I think it's better not to account for that in this branch. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 83b1cef7fd..880fb34310 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 83b1cef7fd4209b3e25b6a310ce8f964277d9692 +Subproject commit 880fb343109d150cd853208c368641863050df4f From b710023c9b24c74d5fc7e0563e64c4e4cae0371d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 16:56:34 -0700 Subject: [PATCH 535/709] Address deprecation warning. --- .github/scripts/changed.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/changed.sh b/.github/scripts/changed.sh index 9fc3a4388e..8fa9e72b1a 100644 --- a/.github/scripts/changed.sh +++ b/.github/scripts/changed.sh @@ -3,8 +3,8 @@ changes() { } if changes | grep -q $1; then - echo "::set-output name=CHANGED_$2::1" + echo "CHANGED_$2=1" >> $GITHUB_OUTPUT else - echo "::set-output name=CHANGED_$2::0" + echo "CHANGED_$2=0" >> $GITHUB_OUTPUT fi From 129c3b06bcdc410c591c20cf59928225fa672a6b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 17:53:51 -0700 Subject: [PATCH 536/709] The integration tests are also target-specific. --- .github/workflows/check-diff.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index a9d169b9c8..5848ebdb9e 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -36,10 +36,10 @@ jobs: - id: do run: | wget https://raw.githubusercontent.com/lf-lang/lingua-franca/reduce-testing/.github/scripts/changed.sh - source changed.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/" C - source changed.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/" CPP - source changed.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/" PY - source changed.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/" RS - source changed.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/" TS + source changed.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/\|test/C" C + source changed.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/\|test/Cpp" CPP + source changed.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/\|test/Python" PY + source changed.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/\|test/Rust" RS + source changed.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/\|test/TypeScript" TS source changed.sh "util/tracing" TRACING shell: bash From 4948a6aa287f84b582336453c110051472a4ea42 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 17:58:19 -0700 Subject: [PATCH 537/709] Rename changed.sh -> check-diff.sh. --- .github/scripts/{changed.sh => check-diff.sh} | 0 .github/workflows/check-diff.yml | 14 +++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) rename .github/scripts/{changed.sh => check-diff.sh} (100%) diff --git a/.github/scripts/changed.sh b/.github/scripts/check-diff.sh similarity index 100% rename from .github/scripts/changed.sh rename to .github/scripts/check-diff.sh diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index 5848ebdb9e..6be192aa02 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -35,11 +35,11 @@ jobs: fetch-depth: 0 - id: do run: | - wget https://raw.githubusercontent.com/lf-lang/lingua-franca/reduce-testing/.github/scripts/changed.sh - source changed.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/\|test/C" C - source changed.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/\|test/Cpp" CPP - source changed.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/\|test/Python" PY - source changed.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/\|test/Rust" RS - source changed.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/\|test/TypeScript" TS - source changed.sh "util/tracing" TRACING + wget https://raw.githubusercontent.com/lf-lang/lingua-franca/reduce-testing/.github/scripts/check-diff.sh + source check-diff.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/\|test/C" C + source check-diff.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/\|test/Cpp" CPP + source check-diff.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/\|test/Python" PY + source check-diff.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/\|test/Rust" RS + source check-diff.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/\|test/TypeScript" TS + source check-diff.sh "util/tracing" TRACING shell: bash From eb35efebd8b9ad5dcaacc5c28e97e8f75c8b1886 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 18:21:30 -0700 Subject: [PATCH 538/709] Rename again. --- .github/workflows/all-non-target-specific.yml | 4 ++-- .github/workflows/all-targets.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 166694a51f..2960adafa1 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,5 +1,5 @@ -# Non-target-specific tests to run on PRs that are ready for review. -name: Catch-all +# Non-target-specific tests +name: CI (misc) on: workflow_dispatch: diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 0948665eea..cb3f807d46 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -1,5 +1,5 @@ -# Target-specific tests to run on PRs that are ready for review. -name: Catch-all +# Target-specific tests +name: CI (by target) on: workflow_dispatch: From 77359b93424b24dec1d9380d9086455994c11bcc Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 19:06:25 -0700 Subject: [PATCH 539/709] Fix warnings reported on CliBase. The comparison of strings to string literals looks like a critical error which I think would have been caught by sufficient tests. One of these warnings is incorrect, but we might as well silence it with an assertion. The warning about toArray is merely a matter of best practice. A human couldn't be expected to know about this, but the warning emitted by IntelliJ is correct. --- org.lflang/src/org/lflang/cli/CliBase.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index a6c1c805ed..2186b2096b 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -285,6 +285,7 @@ private String[] jsonStringToArgs(String jsonString) { if (src == null) { reporter.printFatalErrorAndExit("JSON Parse Exception: field \"src\" not found."); } + assert src != null; argsList.add(src.getAsString()); // Append output path if given. JsonElement out = jsonObject.get("out"); @@ -306,14 +307,12 @@ private String[] jsonStringToArgs(String jsonString) { // Append option. argsList.add("--" + property); // Append argument for non-boolean options. - if (value != "true" || property == "threading") { + if (!value.equals("true") || property.equals("threading")) { argsList.add(value); } } } - // Return as String[]. - String[] args = argsList.toArray(new String[argsList.size()]); - return args; + return argsList.toArray(new String[0]); } } From ed2630e4f9e083950ca3c0f2abeb7f078956655d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 19:36:17 -0700 Subject: [PATCH 540/709] Fix use of wrong API function name. --- test/Python/src/federated/CycleDetection.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index cf9b6d6b54..f2ec8622c9 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -36,7 +36,7 @@ reactor UserInput { self.sys.stderr.write("Did not receive the expected balance. Expected: 200. Got: {}.\n".format(balance.value)) self.sys.exit(1) print("Balance: {}".format(balance.value)) - lf_request_stop() + request_stop() =} reaction(shutdown) {= print("Test passed!") =} From 3a1be9157d611fa35260c1de0c973d854c538cbc Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 27 May 2023 20:30:32 -0700 Subject: [PATCH 541/709] Possibly fix the federated tests on Unix. This might fix the issue where one failing test (that times out) causes all the remaining tests to fail. Timeouts occur when a federate dies because apparently the RTI doesn't quit when one federate dies (maybe it should), but that's a separate issue. --- org.lflang.tests/src/org/lflang/tests/TestBase.java | 2 +- .../org/lflang/federated/launcher/FedLauncherGenerator.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 9ae075780a..9d419d5644 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -520,7 +520,7 @@ private void execute(LFTest test) throws TestError { if (!p.waitFor(MAX_EXECUTION_TIME_SECONDS, TimeUnit.SECONDS)) { stdout.interrupt(); stderr.interrupt(); - p.destroyForcibly(); + p.destroy(); throw new TestError(Result.TEST_TIMEOUT); } else { if (stdoutException.get() != null || stderrException.get() != null) { diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 0a62e6496c..0f024b6499 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -296,9 +296,14 @@ private String getSetupCode() { " echo \"#### Received SIGINT signal on line $1. Invoking cleanup().\"", " cleanup", "}", + "cleanup_sigterm() {", + " echo \"#### Received SIGTERM signal on line $1. Invoking cleanup().\"", + " cleanup", + "}", "", "trap 'cleanup_err $LINENO' ERR", "trap 'cleanup_sigint $LINENO' SIGINT", + "trap 'cleanup_sigterm $LINENO' SIGTERM", "", "# Create a random 48-byte text ID for this federation.", "# The likelihood of two federations having the same ID is 1/16,777,216 (1/2^24).", From 6b2019d7852353bcb0aac22b116a928f1d767b2a Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 27 May 2023 22:11:15 -0700 Subject: [PATCH 542/709] Rename `os-tests` to `regular-tests` --- .github/workflows/c-tests.yml | 2 +- .github/workflows/cpp-tests.yml | 2 +- .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 072151d219..e8c8b935b6 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -22,7 +22,7 @@ on: type: boolean jobs: - os-tests: + regular-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index dbee4e2ac5..1964e2d9d2 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -15,7 +15,7 @@ on: type: boolean jobs: - cpp-tests: + regular-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 8dc7641ed2..e68f2682ba 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -18,7 +18,7 @@ on: type: boolean jobs: - os-tests: + regular-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index e5d0a4681e..076ccb901b 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -21,7 +21,7 @@ on: type: boolean jobs: - os-tests: + regular-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 5afcbc231d..a3ccddbb55 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -9,7 +9,7 @@ on: type: boolean jobs: - run: + regular-tests: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} From a8240db9e94c34612adf3628634b4ec5d029eb65 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 27 May 2023 22:48:05 -0700 Subject: [PATCH 543/709] Also reset when converting to draft --- .github/workflows/all-non-target-specific.yml | 4 ++-- .github/workflows/all-targets.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-non-target-specific.yml index 2960adafa1..49e232e749 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-non-target-specific.yml @@ -1,5 +1,5 @@ # Non-target-specific tests -name: CI (misc) +name: CI (misc) on: workflow_dispatch: @@ -7,7 +7,7 @@ on: branches: - master pull_request: - types: [synchronize, opened, reopened, ready_for_review] + types: [synchronize, opened, reopened, ready_for_review, converted_to_draft] env: # 2020.11 diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index cb3f807d46..092f5265a6 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -7,7 +7,7 @@ on: branches: - master pull_request: - types: [synchronize, opened, reopened, ready_for_review] + types: [synchronize, opened, reopened, ready_for_review, converted_to_draft] env: # 2020.11 From a7df998f0cb2ce817bc30053370df722a798d556 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 27 May 2023 22:53:04 -0700 Subject: [PATCH 544/709] Rename workflow --- .github/workflows/{all-non-target-specific.yml => all-misc.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{all-non-target-specific.yml => all-misc.yml} (98%) diff --git a/.github/workflows/all-non-target-specific.yml b/.github/workflows/all-misc.yml similarity index 98% rename from .github/workflows/all-non-target-specific.yml rename to .github/workflows/all-misc.yml index 49e232e749..4caa470ba9 100644 --- a/.github/workflows/all-non-target-specific.yml +++ b/.github/workflows/all-misc.yml @@ -1,5 +1,5 @@ # Non-target-specific tests -name: CI (misc) +name: CI (misc) on: workflow_dispatch: From 4983ea96e17ba9eb411e68cf48f144a68f2040b7 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 27 May 2023 23:18:27 -0700 Subject: [PATCH 545/709] Update package.json --- org.lflang/src/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index cdb127813a..fc063d791e 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#fix-federation", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From aa170d7982ca83e8472cd1df1d9749d6da99efce Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 28 May 2023 00:07:41 -0700 Subject: [PATCH 546/709] Update package.json --- org.lflang/src/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index 75c880bbc3..fc063d791e 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#minor-reorg", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From 9544c6c48fa4543d7f05facf1ac85f27e8903b7e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 28 May 2023 00:46:58 -0700 Subject: [PATCH 547/709] Update submodule --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 880fb34310..b9de0d52c0 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 880fb343109d150cd853208c368641863050df4f +Subproject commit b9de0d52c0a2b13e2ffa140c785779c9a71b49d2 From 05922ff4c902e5a20103f87a299a99003ecb731f Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun <78055940+byeong-gil@users.noreply.github.com> Date: Sun, 28 May 2023 19:37:22 +0900 Subject: [PATCH 548/709] Update ts-tests.yml --- .github/workflows/ts-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 788a0695b7..d474da7056 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -32,7 +32,7 @@ jobs: if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#fix-federation" + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: From 091e7a68646c695eeaac9d741c0850efcf8d89a1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sun, 28 May 2023 13:48:55 +0200 Subject: [PATCH 549/709] also install the root project --- build.gradle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 43a28acccf..1e7ac576ee 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,9 @@ import lfformat.LfFormatStep plugins { - id "com.diffplug.spotless" - id "org.lflang.distribution-conventions" + id 'com.diffplug.spotless' + id 'org.lflang.distribution-conventions' + id 'idea' } spotless { @@ -42,3 +43,5 @@ distributions { } } } +installDist.dependsOn('installClitoolsDist') +assemble.dependsOn('installDist') From 4eb228262b1c1a324cad6ef7629e32487bb0a2de Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sun, 28 May 2023 14:11:18 +0200 Subject: [PATCH 550/709] make the LF formatting task depend on the lff distribution files This ensures, that gradle recognizes a change in lff and reformats all lf files accordingly. --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 9164e447fc..bed0f03ce3 100644 --- a/build.gradle +++ b/build.gradle @@ -21,11 +21,11 @@ spotless { target 'test/*/src/**/*.lf' // you have to set the target manually targetExclude 'test/**/failing/**' } - } -spotlessLinguaFranca.dependsOn(":org.lflang:cli:lff:installDist") - +// Make the LF formatting task depend on lff +spotlessLinguaFranca.dependsOn(':org.lflang:cli:lff:installDist') +spotlessLinguaFranca.inputs.files(tasks.getByPath(':org.lflang:cli:lff:installDist').outputs) distributions { clitools { From ee1961e36dc3a04b74c869fa1eaf484802d0a898 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sun, 28 May 2023 14:36:19 +0200 Subject: [PATCH 551/709] clean up versions --- buildSrc/src/main/groovy/org.lflang.test-conventions.gradle | 2 -- gradle.properties | 5 ----- 2 files changed, 7 deletions(-) diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 336dda5ade..a8d4c63909 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -7,8 +7,6 @@ jacoco { toolVersion = jacocoVersion } - - dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" diff --git a/gradle.properties b/gradle.properties index 732e9e6c38..50b3771829 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,20 +5,15 @@ version=0.4.1-SNAPSHOT [versions] fasterxmlVersion=2.12.4 googleJavaFormatVersion=1.15.0 -guiceVersion=5.1.0 -gsonVersion=2.10.1 jacocoVersion=0.8.7 jupiterVersion=5.8.2 jUnitPlatformVersion=1.8.2 -jUnitVersion=4.13.2 kotlinJvmTarget=17 lsp4jVersion=0.14.0 mwe2LaunchVersion=2.12.2 openTest4jVersion=1.2.0 picocliVersion=4.7.0 resourcesVersion=3.16.0 -shadowJarVersion=7.1.2 -xtextGradleVersion=3.0.0 xtextVersion=2.28.0 klighdVersion=2.2.1-SNAPSHOT From 8ec427c2000f2f6d0fa85b344cd2b6f7e52efef9 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Sun, 28 May 2023 14:40:31 +0200 Subject: [PATCH 552/709] add runLfc and runLff tasks --- build.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build.gradle b/build.gradle index ff0921756c..fb9378249b 100644 --- a/build.gradle +++ b/build.gradle @@ -45,3 +45,12 @@ distributions { } installDist.dependsOn('installClitoolsDist') assemble.dependsOn('installDist') + + +// Alias tasks for simpler access +tasks.register('runLfc') { + dependsOn('org.lflang:cli:lfc:run') +} +tasks.register('runLff') { + dependsOn('org.lflang:cli:lff:run') +} \ No newline at end of file From e390321f93ffe7acea1065b699e3adfb7c33441a Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 28 May 2023 13:38:05 -0700 Subject: [PATCH 553/709] Update check-diff.yml --- .github/workflows/check-diff.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index 6be192aa02..af5f241cab 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -35,7 +35,7 @@ jobs: fetch-depth: 0 - id: do run: | - wget https://raw.githubusercontent.com/lf-lang/lingua-franca/reduce-testing/.github/scripts/check-diff.sh + wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh source check-diff.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/\|test/C" C source check-diff.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/\|test/Cpp" CPP source check-diff.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/\|test/Python" PY From 597cdd738a912c553379f3bbdd60339bf79f5726 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 25 May 2023 13:41:19 -0700 Subject: [PATCH 554/709] Use qemu_riscv32 with debug logging turned of for Zephyr tests --- .../src/org/lflang/tests/Configurators.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index a5db8f2abf..bbc9d315ee 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -26,6 +26,7 @@ import org.lflang.TargetProperty; import org.lflang.TargetProperty.Platform; +import org.lflang.TargetProperty.LogLevel; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -69,7 +70,10 @@ public static boolean makeZephyrCompatibleUnthreaded(LFTest test) { test.getContext().getTargetConfig().setByUser.add(TargetProperty.THREADING); test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; test.getContext().getTargetConfig().platformOptions.flash = false; - test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + test.getContext().getTargetConfig().platformOptions.board = "qemu_riscv32"; + // FIXME: Zephyr qemu emulations fails with debug log-levels. + test.getContext().getTargetConfig().logLevel = LogLevel.WARN; + test.getContext().getArgs().setProperty("logging", "warning"); return true; } @@ -77,7 +81,11 @@ public static boolean makeZephyrCompatible(LFTest test) { test.getContext().getArgs().setProperty("tracing", "false"); test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; test.getContext().getTargetConfig().platformOptions.flash = false; - test.getContext().getTargetConfig().platformOptions.board = "qemu_cortex_a53"; + test.getContext().getTargetConfig().platformOptions.board = "qemu_riscv32"; + // FIXME: Zephyr qemu emulations fails with debug log-levels. + test.getContext().getTargetConfig().logLevel = LogLevel.WARN; + test.getContext().getArgs().setProperty("logging", "warning"); + return true; } /** From ba67c0ef12b87b2fabbc322d77c63af7a314efc5 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 28 May 2023 15:18:04 -0700 Subject: [PATCH 555/709] Relaxed timing to try to reduce flakiness --- test/C/src/concurrent/DeadlineThreaded.lf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index ffc1be2701..4be8573c35 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -24,7 +24,7 @@ reactor Source(period: time = 3000 msec) { if (2 * (self->count / 2) != self->count) { // The count variable is odd. // Take time to cause a deadline violation. - lf_sleep(MSEC(210)); + lf_sleep(MSEC(1100)); } printf("Source sends: %d.\n", self->count); lf_set(y, self->count); @@ -57,6 +57,6 @@ reactor Destination(timeout: time = 1 sec) { main reactor { s = new Source() - d = new Destination(timeout = 200 msec) + d = new Destination(timeout = 1s) s.y -> d.x } From e6a4a0628343d433a76223503e6a9a13aa4f000f Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 28 May 2023 16:24:59 -0700 Subject: [PATCH 556/709] Align to reactor-c main after merge --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b9de0d52c0..c5613560e1 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b9de0d52c0a2b13e2ffa140c785779c9a71b49d2 +Subproject commit c5613560e160349154785ff5328ab8f1f764e504 From 09151c2ba867de90c0dcb6335f513b54c8ac128a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 28 May 2023 16:25:27 -0700 Subject: [PATCH 557/709] Format --- test/C/src/concurrent/DeadlineThreaded.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index 4be8573c35..c23f28266a 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -57,6 +57,6 @@ reactor Destination(timeout: time = 1 sec) { main reactor { s = new Source() - d = new Destination(timeout = 1s) + d = new Destination(timeout = 1 s) s.y -> d.x } From 3128b20430bb6c97ed2f89f5ff8a76c6a6e8ddc5 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 29 May 2023 06:05:44 +0200 Subject: [PATCH 558/709] Bump reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 98f13080c4..d43e973780 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 98f13080c4346a76aec92603509b1c5ac62abb9e +Subproject commit d43e9737804f2d984d52a99cac20d8e57adad543 From fa0fa3efd30a6281e337fb6d1957c7ab6dc483ee Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 29 May 2023 06:08:24 +0200 Subject: [PATCH 559/709] Bump reactor-c again --- .west/config | 4 ++++ org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/cpp/reactor-cpp | 2 +- test/C/lib/libapp.a | Bin 0 -> 74484 bytes 4 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .west/config create mode 100644 test/C/lib/libapp.a diff --git a/.west/config b/.west/config new file mode 100644 index 0000000000..ccd607713e --- /dev/null +++ b/.west/config @@ -0,0 +1,4 @@ +[manifest] +path = /home/erling/dev/lf-west-template/deps/zephyr +file = west.yml + diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index d43e973780..c5613560e1 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit d43e9737804f2d984d52a99cac20d8e57adad543 +Subproject commit c5613560e160349154785ff5328ab8f1f764e504 diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index b607f1f640..e80cd36ce5 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit b607f1f64083ab531e7a676b29de75f076aa1cde +Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 diff --git a/test/C/lib/libapp.a b/test/C/lib/libapp.a new file mode 100644 index 0000000000000000000000000000000000000000..d710e87c0ec4ba481729cee7abcf33a864b98114 GIT binary patch literal 74484 zcmeEv2Y6h?)%INNN?KJ*vTRE(AWQPfO=WGlfep4?u#H1=!5D)qOKVG5mV|bNZ6IKZ zNdknPkU|nVgc?eKFF@!uK!`~QB!pfWlw%u4_)Tw#VE0I^)X0%^h9I6rSwf5bsKnw08GwNf8{;(%Gktz+UTy=C*iCTW3dC zT&?TtYE^xScyF@37qY~(=?&8wrZ!B8HE(R`=z^#<+0otAOf?M}lqfcLv?Wwmd{grd z(<&NJ%`A63i451Z^mQhiTe~-IZ0TxiX6DV^J+zt7N*!Gt$&QxJjw9pE$=;6j>*Kx6 z-D?kvw?^E?bg37&da1x%?w?yEF!)X`(r z7*(x~TQDr7)Oradk?yF39$CnU<;4oZ`Wmnd)cTvhF_@C3hd|>@j!mw+VGAtw^|h~T@^A6Z4snA$@Z3HMSDx)%P5mqob_1cBhiQVx&MHB z7e5#pH(!lE@tSYgl8-<6niDM!)#QXvh%O3`Klg@dm#Le+b8L*5@d!PhY;qX&)Jp zY)Ue`EID8{1umX(2zdSLNS~Ls()~7gR$lq6%n|P;6(1nOIxRJ|y%!;Ijh{SBsG5JD{Dmw)+MX2+59J9ky@hRCH9U?Z_oLaOUM3S5~h^mI1 zUZ^7^<_v9_#?JK3oEiFokIxzT7H}aFtNh3auV`F`QiI4MBfZgI<;f8?$}2koEG%qS zPuDAglMj6s79soY{Dn9aXNP(IA}b3IL0k!AzI3Q0Zln zOACGpwIWG#dD$3NVQ^1(LPdV8dxLo&M(PTd%w`;X!LhjThSSjT0;xkd|)k5ym zt+NJwo98S${4*3GJIs@j9p?GT4nLwL+x6#bT7D7apg8Rhm;DJqw`N7;(Fo6nn0;)} zgH#am%Oa+ZNHaaIiz34`@~dJFGt-*eb%{;ycv7F-GUWfP&Y8`rM_43M;1zLD$tWt6 zQDoR48E;`EI{+%#VV>;L>PW4Z^E*FDohN-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Gs1`!pZiVDmLWgZ-NaYh5dQ2Yd4b3Cg|D zzqYpvwJZN=sUbZZ`|Y+Wty=Bqsq|n~obhYfj;^FyvGvZM#oDsHb{-Y0wTtfP$?>xH z){)dT&^Iv9#W7U6lR6g+s7}LN=|Qr-pM5Sat=QR>R9&~zq1AcQ^1bY+w~p02eh*#j z*3gcr>Y78B`q@$RmFmpt@7uWg=H9-(4gH&jEY{#KLtbm3lXa{6RbTlDR{q+|5Q%Xe zqEwxuwJv%{8I_>C-YN~6BG-mn2X5Ka)jOy+xlg}N_p8Is|NZ@cq6~FSe(Un_-HWvj zaGdDA1O0V(VabUyh^D3yn)c_LB2RU@$4QHb?Q$$w-B~Y#?dAonf5X+o9bp)hG4zFRBX{YGv3Pqduvj@K01&GVD%bwtnTp}AtBJo**O$FV~fFdq?7-pQJx zyr(Mrw@u}(iNZCH@*b;{_k|i%BfPu`rSceeKGva_QEK Date: Mon, 29 May 2023 06:53:39 +0200 Subject: [PATCH 560/709] Add ConcurrentTests to Zephyr and exclude the tracing specific concurrent tests --- .../src/org/lflang/tests/runtime/CZephyrTest.java | 12 ++++++++++++ util/RunZephyrTests.sh | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index db5eb46fc3..079c6c18b7 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -66,4 +66,16 @@ public void buildGenericTests() { TestLevel.BUILD, false); } + @Test + public void buildConcurrentTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + + super.runTestsFor( + List.of(Target.C), + Message.DESC_CONCURRENT, + TestCategory.CONCURRENT::equals, + Configurators::makeZephyrCompatible, + TestLevel.BUILD, + false); + } } diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index 742a23ef18..c1079221d5 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -9,7 +9,7 @@ num_failures=0 failed_tests="" # Skip -skip=("FileReader" "FilePkgReader") +skip=("FileReader" "FilePkgReader" "Tracing" "ThreadedThreaded") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From 05f404553622c4c43c7c733a786b5cf5d996ae64 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 29 May 2023 06:59:03 +0200 Subject: [PATCH 561/709] Print all skipped tests in RunZephyrTests.sh --- util/RunZephyrTests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index c1079221d5..ffb15198a9 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -116,8 +116,7 @@ else fi echo "Number of passes: $num_successes" echo "Number of fails: $num_failures" -echo "Skipped tests: $skip" - +echo "Skipped tests: ${skip[@]}" if [ "$overall_success" = false ]; then echo "Failed tests: $failed_tests" From a4a9feecd535ff7c285541f834cf5d2a0e85869c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 29 May 2023 07:28:44 +0200 Subject: [PATCH 562/709] spotless --- org.lflang.tests/src/org/lflang/tests/Configurators.java | 6 +++--- .../src/org/lflang/tests/runtime/CZephyrTest.java | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index bbc9d315ee..85a8465c29 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -25,8 +25,8 @@ package org.lflang.tests; import org.lflang.TargetProperty; -import org.lflang.TargetProperty.Platform; import org.lflang.TargetProperty.LogLevel; +import org.lflang.TargetProperty.Platform; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -71,12 +71,12 @@ public static boolean makeZephyrCompatibleUnthreaded(LFTest test) { test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; test.getContext().getTargetConfig().platformOptions.flash = false; test.getContext().getTargetConfig().platformOptions.board = "qemu_riscv32"; - // FIXME: Zephyr qemu emulations fails with debug log-levels. + // FIXME: Zephyr qemu emulations fails with debug log-levels. test.getContext().getTargetConfig().logLevel = LogLevel.WARN; test.getContext().getArgs().setProperty("logging", "warning"); return true; } - + public static boolean makeZephyrCompatible(LFTest test) { test.getContext().getArgs().setProperty("tracing", "false"); test.getContext().getTargetConfig().platformOptions.platform = Platform.ZEPHYR; diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index 079c6c18b7..b29c2755d1 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -66,6 +66,7 @@ public void buildGenericTests() { TestLevel.BUILD, false); } + @Test public void buildConcurrentTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); From 0d731fb926b03632cde508cedfd81656bede4de9 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 29 May 2023 08:14:02 +0200 Subject: [PATCH 563/709] Bump reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index e80cd36ce5..b607f1f640 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 +Subproject commit b607f1f64083ab531e7a676b29de75f076aa1cde From 37fdf50dc98fa7567d46bac8c06af08d7c38e73b Mon Sep 17 00:00:00 2001 From: erling Date: Mon, 29 May 2023 08:59:07 +0200 Subject: [PATCH 564/709] Update extract-ref.yml Use the new label for outputting the ref also --- .github/workflows/extract-ref.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/extract-ref.yml b/.github/workflows/extract-ref.yml index c3c738048f..cb10c29a8b 100644 --- a/.github/workflows/extract-ref.yml +++ b/.github/workflows/extract-ref.yml @@ -10,7 +10,7 @@ on: outputs: ref: description: "The extracted ref" - value: ${{ jobs.run.outputs.ref }} + value: ${{ jobs.extract-ref.outputs.ref }} jobs: extract-ref: From b779115921746ea8051575f0891e072038b45576 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 12:15:04 +0200 Subject: [PATCH 565/709] correctly pass args to run tasks --- build.gradle | 4 ++-- util/scripts/launch.ps1 | 7 ++++++- util/scripts/launch.sh | 7 ++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index fb9378249b..609bd663c2 100644 --- a/build.gradle +++ b/build.gradle @@ -48,9 +48,9 @@ assemble.dependsOn('installDist') // Alias tasks for simpler access -tasks.register('runLfc') { +tasks.register('runLfc', JavaExec) { dependsOn('org.lflang:cli:lfc:run') } -tasks.register('runLff') { +tasks.register('runLff', JavaExec) { dependsOn('org.lflang:cli:lff:run') } \ No newline at end of file diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index ffeee518ca..26e3db1d30 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -29,4 +29,9 @@ $base="$PSScriptRoot\..\..\" $gradlew="${base}/gradlew.bat" # invoke script -& "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args "$args" \ No newline at end of file +if ($args.Length == 0) { + & "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" +} else { + $argsString = $args -join " " + & "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args="${argsString}" +} \ No newline at end of file diff --git a/util/scripts/launch.sh b/util/scripts/launch.sh index 03025c9914..5c335a6fe8 100755 --- a/util/scripts/launch.sh +++ b/util/scripts/launch.sh @@ -70,4 +70,9 @@ fi gradlew="${base}/gradlew" # Launch the tool. -"${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args "$@" +if [ $# -eq 0 ]; then + "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" +else + "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args="$*" +fi + From 9600d93ffad219adfee96f5127d7ff49a13d42da Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 12:16:56 +0200 Subject: [PATCH 566/709] also format shell and ps1 scripts --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 609bd663c2..dd25fd5a9d 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { spotless { format 'misc', { // define the files to apply `misc` to - target '*.gradle', '*.md', '.gitignore' + target '*.gradle', '*.md', '.gitignore', '*.sh', '*.ps1' // define the steps to apply to those files trimTrailingWhitespace() @@ -53,4 +53,4 @@ tasks.register('runLfc', JavaExec) { } tasks.register('runLff', JavaExec) { dependsOn('org.lflang:cli:lff:run') -} \ No newline at end of file +} From d5529b32d6307ef7d3e722027621bb412d4d714a Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 13:07:52 +0200 Subject: [PATCH 567/709] fix integration tests --- .../groovy/org.lflang.test-conventions.gradle | 52 ++++++---------- org.lflang/core/build.gradle | 60 ------------------- 2 files changed, 18 insertions(+), 94 deletions(-) diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index a8d4c63909..8385720b8d 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -25,10 +25,27 @@ dependencies { testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } +def integrationTest = false +tasks.register('integration') { + integrationTest = true +} +integration.finalizedBy(test) + test { useJUnitPlatform { - excludeTags 'Integration' + if (integrationTest) { + includeTags 'Integration' + } else { + excludeTags 'Integration' + } + } + + if (integrationTest && project.hasProperty('target')) { + filter { + includeTestsMatching "org.lflang.tests.runtime.${project.property('target')}Test.*" + } } + testLogging { events "passed", "skipped", "failed" showStandardStreams = true @@ -61,36 +78,3 @@ jacocoTestReport { })) } } - - - -tasks.register('integration', Test) { - filter { - setFailOnNoMatchingTests(false) - } - if (System.getProperty('integrationInclude') != null) { - filter { - includeTestsMatching System.getProperty('integrationInclude') - } - } - useJUnitPlatform { - includeTags 'Integration' - - } - testLogging { - events "passed", "skipped", "failed" - showStandardStreams = true - exceptionFormat "full" - } - // Pass the scheduler and runtime property on to the Java VM - systemProperty 'scheduler', System.getProperty('scheduler') - systemProperty 'runtime', System.getProperty('runtime') - - filter { - setFailOnNoMatchingTests(false) - } - - failFast = true - - workingDir = rootProject.projectDir -} \ No newline at end of file diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 615020ec4d..fafadd0191 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -79,66 +79,6 @@ processResources.dependsOn(generateXtextLanguage) clean.dependsOn(cleanGenerateXtextLanguage) spotlessJava.mustRunAfter(generateXtextLanguage) -tasks.register('integrationLsp') { - System.setProperty('integrationInclude', 'org.lflang.tests.lsp.**') - finalizedBy('integration') -} - -tasks.register('integrationCArduino') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CArduinoTest.*') - finalizedBy('integration') -} - -tasks.register('integrationCCpp') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CCppTest.*') - finalizedBy('integration') -} - -tasks.register('integrationCppRos2') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CppRos2Test.*') - finalizedBy('integration') -} - -tasks.register('integrationCpp') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CppTest.*') - finalizedBy('integration') -} - -tasks.register('integrationCScheduler') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CSchedulerTest.*') - finalizedBy('integration') -} - -tasks.register('integrationC') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CTest.*') - finalizedBy('integration') -} - -tasks.register('integrationCZephyr') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.CZephyr.*') - finalizedBy('integration') -} - -tasks.register('integrationPython') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.PythonTest.*') - finalizedBy('integration') -} - -tasks.register('integrationRust') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.RustTest.*') - finalizedBy('integration') -} - -tasks.register('integrationTypeScript') { - System.setProperty('integrationInclude', 'org.lflang.tests.runtime.TypeScriptTest.*') - finalizedBy('integration') -} - -tasks.register('integrationSerialization') { - System.setProperty('integrationInclude', 'org.lflang.tests.serialization.SerializationTest.*') - finalizedBy('integration') -} - tasks.register('getSubmoduleVersions', Exec) { description('Run a Git command to get the current status of submodules') workingDir project.rootDir From 1fe39cc9fd0f61f2f359c5eda33dd1ba0c6e531d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 13:18:47 +0200 Subject: [PATCH 568/709] remove deleted workflows --- .github/workflows/all-misc.yml | 9 --------- .github/workflows/non-target-specific-extended.yml | 4 ---- .github/workflows/non-target-specific.yml | 6 ------ 3 files changed, 19 deletions(-) diff --git a/.github/workflows/all-misc.yml b/.github/workflows/all-misc.yml index 4caa470ba9..d606cf31b8 100644 --- a/.github/workflows/all-misc.yml +++ b/.github/workflows/all-misc.yml @@ -21,11 +21,6 @@ jobs: check-diff: uses: ./.github/workflows/check-diff.yml - junit: - uses: ./.github/workflows/unit-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - # Test the Gradle build. building: if: ${{ !github.event.pull_request.draft }} @@ -40,10 +35,6 @@ jobs: with: all-platforms: ${{ !github.event.pull_request.draft }} - formatting: - if: ${{ !github.event.pull_request.draft }} - uses: ./.github/workflows/check-format.yml - # Run tests for the standalone compiler. cli: if: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index bdfc4181aa..065b5dbff8 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -29,10 +29,6 @@ jobs: with: all-platforms: ${{ !github.event.pull_request.draft }} - formatting: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/check-format.yml - # Run tests for the standalone compiler. cli: if: ${{ inputs.all || github.event.pull_request.draft }} diff --git a/.github/workflows/non-target-specific.yml b/.github/workflows/non-target-specific.yml index 2ea4f4499d..179c5ee089 100644 --- a/.github/workflows/non-target-specific.yml +++ b/.github/workflows/non-target-specific.yml @@ -16,12 +16,6 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: - # Run the unit tests. - junit: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/unit-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} # Run the serialization tests serialization: From fdcb2f1a5dc84137c84b822dbdb9979cf4d1beec Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 13:28:37 +0200 Subject: [PATCH 569/709] update ci integration jobs --- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/c-tests.yml | 6 +++--- .github/workflows/c-zephyr-tests.yml | 2 +- .github/workflows/cpp-ros2-tests.yml | 2 +- .github/workflows/cpp-tests.yml | 2 +- .github/workflows/lsp-tests.yml | 4 ++-- .github/workflows/py-tests.yml | 2 ++ .github/workflows/rs-tests.yml | 2 +- .github/workflows/serialization-tests.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- 10 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 157fe67c41..6082eaa17d 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -63,7 +63,7 @@ jobs: arduino-cli core install arduino:sam arduino-cli core install arduino:mbed - name: Perform Arduino tests for C target with default scheduler - run: ./gradlew integrationCArduino + run: ./gradlew integration -Ptarget=Arduino - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 8f18c464ce..e498ebe6ad 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -54,15 +54,15 @@ jobs: uses: ./.github/actions/install-rti if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform tests for C target with default scheduler - run: ./gradlew integrationC + run: ./gradlew integration -Ptarget=C if: ${{ !inputs.use-cpp && !inputs.scheduler }} - name: Perform tests for C target with specified scheduler (no LSP tests) run: | echo "Specified scheduler: ${{ inputs.scheduler }}" - ./gradlew integrationC -Dscheduler=${{ inputs.scheduler }} + ./gradlew integration -Ptarget=C -Dscheduler=${{ inputs.scheduler }} if: ${{ !inputs.use-cpp && inputs.scheduler }} - name: Perform tests for CCpp target with default scheduler - run: ./gradlew integrationCCpp + run: ./gradlew integration -Ptarget=CCpp if: ${{ inputs.use-cpp && !inputs.scheduler }} - name: Collect code coverage run: ./gradlew jacocoTestReport diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 3d1e0b95b7..39b225b3ed 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -41,7 +41,7 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler run: | - ./gradlew integrationCZephyr + ./gradlew integration -Ptarget=CZephyr util/RunZephyrTests.sh test/C/src-gen - name: Collect code coverage run: ./gradlew jacocoTestReport diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index e1492ac329..7c23700794 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -35,7 +35,7 @@ jobs: - name: Run C++ tests; run: | source /opt/ros/*/setup.bash - ./gradlew integrationCppRos2 + ./gradlew integration -Ptarget=CppRos2 - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 926e704d4c..35b972e6c2 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -48,7 +48,7 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Run C++ tests; run: | - ./gradlew integrationCpp + ./gradlew integration -Ptarget=Cpp - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index 50d3193b86..ca82c3f41c 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -69,7 +69,7 @@ jobs: with: python-version: '3.10' - name: Run language server Python tests without PyLint - run: ./gradlew integration --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly + run: ./gradlew org.lflang:core:integration --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly - name: Install pylint run: python3 -m pip install pylint if: ${{ runner.os != 'macOS' }} @@ -77,7 +77,7 @@ jobs: run: brew install pylint if: ${{ runner.os == 'macOS' }} - name: Run language server tests - run: ./gradlew integration --tests org.lflang.tests.lsp.LspTests.*ValidationTest + run: ./gradlew org.lflang:core:integration --tests org.lflang.tests.lsp.LspTests.*ValidationTest - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index b6b323959f..436885243a 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -59,6 +59,8 @@ jobs: path: org.lflang/src/lib/py/reactor-c-py ref: ${{ inputs.reactor-c-py-ref }} if: ${{ inputs.reactor-c-py-ref }} + - name: Run Python tests + run: ./gradlew integration -Ptarget=Python - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index c3297686c9..c84b5266aa 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -64,7 +64,7 @@ jobs: rust-version: ${{ matrix.rust }} components: clippy - name: Run Rust tests - run: ./gradlew integrationRust + run: ./gradlew integration -Ptarget=Rust - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 29ab00583e..00738e99fa 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew integrationSerialization + ./gradlew org.lflang:core:integration --test org.lflang.test.serialization.SerializationTest.* - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 5f6631d6be..4b8bd1905f 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -33,7 +33,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew integrationTypeScript -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" + ./gradlew integration -Ptarget=TypeScript -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov From 0d13278e423fbce3ea6b1fa8c838e5b11b8642d1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 13:40:14 +0200 Subject: [PATCH 570/709] extended formatting --- .github/scripts/check-diff.sh | 1 - .github/scripts/test-lfc.sh | 2 +- .github/scripts/test-lff.sh | 2 +- .github/workflows/README.md | 2 +- .github/workflows/cli-tests.yml | 1 - build.gradle | 6 +- buildSrc/build.gradle | 2 +- ...org.lflang.java-library-conventions.gradle | 2 +- .../org.lflang.kotlin-conventions.gradle | 2 +- gradle/source-layout.gradle | 68 +++++++++---------- org.lflang/core/build.gradle | 2 +- .../core/src/main/resources/lib/ts/README.md | 2 +- test/Rust/src/README.md | 8 +-- test/TypeScript/README.md | 2 +- util/README.md | 2 +- util/RunZephyrTests.sh | 8 +-- util/scripts/launch-fedsd.sh | 6 +- util/scripts/launch.sh | 1 - util/tracing/README.md | 10 +-- util/tracing/visualization/README.md | 8 +-- 20 files changed, 66 insertions(+), 71 deletions(-) diff --git a/.github/scripts/check-diff.sh b/.github/scripts/check-diff.sh index 8fa9e72b1a..9a84951079 100644 --- a/.github/scripts/check-diff.sh +++ b/.github/scripts/check-diff.sh @@ -7,4 +7,3 @@ if changes | grep -q $1; then else echo "CHANGED_$2=0" >> $GITHUB_OUTPUT fi - diff --git a/.github/scripts/test-lfc.sh b/.github/scripts/test-lfc.sh index 096736f495..fe9b6e3757 100755 --- a/.github/scripts/test-lfc.sh +++ b/.github/scripts/test-lfc.sh @@ -8,7 +8,7 @@ cd $GITHUB_WORKSPACE function test_with_links() { rm -rf foo mkdir -p foo/bar/baz - ln -s ../bin/${1} foo/link-foo + ln -s ../bin/${1} foo/link-foo ln -s ../link-foo foo/bar/link-bar ln -s ../link-bar foo/bar/baz/link-${1} foo/bar/baz/link-${1} --help diff --git a/.github/scripts/test-lff.sh b/.github/scripts/test-lff.sh index b16a5ad46a..d98578a39b 100755 --- a/.github/scripts/test-lff.sh +++ b/.github/scripts/test-lff.sh @@ -8,7 +8,7 @@ cd $GITHUB_WORKSPACE function test_with_links() { rm -rf foo mkdir -p foo/bar/baz - ln -s ../bin/${1} foo/link-foo + ln -s ../bin/${1} foo/link-foo ln -s ../link-foo foo/bar/link-bar ln -s ../link-bar foo/bar/baz/link-${1} foo/bar/baz/link-${1} --help diff --git a/.github/workflows/README.md b/.github/workflows/README.md index d11093c691..a33af6b6a0 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -12,7 +12,7 @@ The [benchmark-tests.yml](https://github.com/lf-lang/lingua-franca/blob/master/. ### CLI tests The [lfc-tests.yml](https://github.com/lf-lang/lingua-franca/blob/master/.github/workflows/lfc-tests.yml) workflow tests command line access to the Lingua Franca compiler via `lfc`. ### Target-specific tests -Each target has its own [reusable workflow](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows). +Each target has its own [reusable workflow](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows). #### C/CCpp ([c-tests.yml](https://github.com/lf-lang/lingua-franca/blob/master/.github/workflows/c-tests.yml)) This workflow has the following (optional) arguments: - `compiler-ref` to specify which ref of the `lingua-franca` repository to check out; and diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 079b604fc2..9e56c40d28 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -37,4 +37,3 @@ jobs: run: | bin/lff.ps1 --help if: ${{ runner.os == 'Windows' }} - diff --git a/build.gradle b/build.gradle index 940ad39ba9..56b50afb4b 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,10 @@ plugins { spotless { format 'misc', { - // define the files to apply `misc` to - target '*.gradle', '*.md', '.gitignore', '**/*.yml' + target project.fileTree(project.rootDir) { + include '**/*.gradle', '**/*.md', '.gitignore', '**/*.yml', '**/*.sh', '**/*.psi' + exclude '**/reactor-cpp/**', '**/reactor-c/**', '**/reactor-rs/**', '**/lf-python-support' + } // define the steps to apply to those files trimTrailingWhitespace() diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 972fd06a06..09aca9525e 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -15,4 +15,4 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" implementation "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion" -} \ No newline at end of file +} diff --git a/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle index 4f3b10c399..1f30f6a700 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-library-conventions.gradle @@ -2,4 +2,4 @@ plugins { id 'org.lflang.java-conventions' id 'java-library' id 'org.lflang.test-conventions' -} \ No newline at end of file +} diff --git a/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle index d595e14b21..879412cbb5 100644 --- a/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.kotlin-conventions.gradle @@ -12,4 +12,4 @@ compileTestKotlin { kotlinOptions { jvmTarget = kotlinJvmTarget } -} \ No newline at end of file +} diff --git a/gradle/source-layout.gradle b/gradle/source-layout.gradle index 4c7d5f74c4..4507a22632 100644 --- a/gradle/source-layout.gradle +++ b/gradle/source-layout.gradle @@ -1,46 +1,46 @@ if (name.endsWith(".tests")) { - sourceSets { - main { - java.srcDirs = [] - kotlin.srcDirs = [] - resources.srcDirs = [] - } - test { - java.srcDirs = ['src', 'src-gen'] - kotlin.srcDirs = ['src', 'src-gen'] - resources.srcDirs = ['src', 'src-gen'] - } - } + sourceSets { + main { + java.srcDirs = [] + kotlin.srcDirs = [] + resources.srcDirs = [] + } + test { + java.srcDirs = ['src', 'src-gen'] + kotlin.srcDirs = ['src', 'src-gen'] + resources.srcDirs = ['src', 'src-gen'] + } + } } else { - sourceSets { - main { - java.srcDirs = ['src', 'src-gen'] - kotlin.srcDirs = ['src', 'src-gen'] - resources { - srcDirs = ['src', 'src-gen'] - exclude 'src/lib/rs/reactor-rust' // rust runtime does not need to be packed here. - } - } - test { - java.srcDirs = [] - resources.srcDirs = [] - } - } + sourceSets { + main { + java.srcDirs = ['src', 'src-gen'] + kotlin.srcDirs = ['src', 'src-gen'] + resources { + srcDirs = ['src', 'src-gen'] + exclude 'src/lib/rs/reactor-rust' // rust runtime does not need to be packed here. + } + } + test { + java.srcDirs = [] + resources.srcDirs = [] + } + } } sourceSets.all { - resources.exclude '**/*.g', '**/*.mwe2', '**/*._trace' + resources.exclude '**/*.g', '**/*.mwe2', '**/*._trace' } jar { - from('model') { - into('model') - } - manifest { - attributes 'Bundle-SymbolicName': project.name - } + from('model') { + into('model') + } + manifest { + attributes 'Bundle-SymbolicName': project.name + } } plugins.withId('war') { - webAppDirName = "WebRoot" + webAppDirName = "WebRoot" } diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index fafadd0191..2589734b8a 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -151,4 +151,4 @@ tasks.register('checkRuntimeVersionFileUpToDate') { } } } -test.dependsOn('checkRuntimeVersionFileUpToDate') \ No newline at end of file +test.dependsOn('checkRuntimeVersionFileUpToDate') diff --git a/org.lflang/core/src/main/resources/lib/ts/README.md b/org.lflang/core/src/main/resources/lib/ts/README.md index 7d273e6743..c414f3e13c 100644 --- a/org.lflang/core/src/main/resources/lib/ts/README.md +++ b/org.lflang/core/src/main/resources/lib/ts/README.md @@ -9,4 +9,4 @@ git://github.com/lf-lang/reactor-ts.git#ref ``` where `ref` could be a SHA1 hash of a particular commit or a branch name such as `my-feature-branch`. -**NOTE**: the `package.json` in this directory is used as a _default_ only; it can be overridden by a `package.json` provided alongside the LF source file. To make sure that all the tests in CI run with a particular version of the runtime, it is safer to leave this file "as is" and instead adapt `.github/workflows/ts-tests.yml` by adding a `-Druntime="git://github.com/lf-lang/reactor-ts.git#ref"` parameter to the `./gradlew test` command. \ No newline at end of file +**NOTE**: the `package.json` in this directory is used as a _default_ only; it can be overridden by a `package.json` provided alongside the LF source file. To make sure that all the tests in CI run with a particular version of the runtime, it is safer to leave this file "as is" and instead adapt `.github/workflows/ts-tests.yml` by adding a `-Druntime="git://github.com/lf-lang/reactor-ts.git#ref"` parameter to the `./gradlew test` command. diff --git a/test/Rust/src/README.md b/test/Rust/src/README.md index 0d1f4d8933..6c50ae069d 100644 --- a/test/Rust/src/README.md +++ b/test/Rust/src/README.md @@ -27,8 +27,8 @@ This is not exhaustive. Ideally each of those bullet points would have a test ca - [x] all test files: trigger dependencies trigger reactions - [x] `ActionIsPresentDouble.lf`: multiple trigger dependencies may be triggered independently - [x] uses-dependencies - - [x] `DependencyUseNonTrigger`: use dependencies do not trigger reactions - - [x] `DependencyUseAccessible`: use dependencies make the port accessible within the reaction, values are observable + - [x] `DependencyUseNonTrigger`: use dependencies do not trigger reactions + - [x] `DependencyUseAccessible`: use dependencies make the port accessible within the reaction, values are observable - [x] `DependencyUseOnLogicalAction.lf`: use dependencies may be declared on actions and timers - [x] effects-dependency - [x] all test files: effects dependencies allow mutation @@ -42,8 +42,8 @@ This is not exhaustive. Ideally each of those bullet points would have a test ca - [x] `Preamble.lf`: preamble within reactor - [ ] top-level preamble - [x] logical actions - - [x] `ActionImplicitDelay.lf`: scheduling an action with no additional delay uses its implicit delay - - [x] `ActionDelay.lf`: + - [x] `ActionImplicitDelay.lf`: scheduling an action with no additional delay uses its implicit delay + - [x] `ActionDelay.lf`: - [x] `ActionScheduleMicrostep.lf`: an action scheduled with a zero delay is only triggered on the next microstep - [x] `ActionValues.lf`: scheduling an action with a value at multiple different tags preserves each value - [x] `ActionValuesCleanup.lf`: action value is cleaned up at the end of a tag diff --git a/test/TypeScript/README.md b/test/TypeScript/README.md index c865f31894..bc01867fbe 100644 --- a/test/TypeScript/README.md +++ b/test/TypeScript/README.md @@ -21,4 +21,4 @@ lfc test/TypeScript/src/Minimal.lf --external-runtime-path ~/lf-lang/reactor-ts - To point `lfc` to a particular ref (e.g. `main`, `v0.1.0` or `f8c6d2379f278e22ad48410bf06cf0909405ecc3`) in the `lf-lang/reactor-ts` repo: ``` lfc test/TypeScript/src/Minimal.lf --runtime-version -``` \ No newline at end of file +``` diff --git a/util/README.md b/util/README.md index 57a89cb629..fd95c322f0 100644 --- a/util/README.md +++ b/util/README.md @@ -1,4 +1,4 @@ ## util This directory is intended for collecting utility programs associated with Lingua Franca -but that run and install independently of the main tool chain. \ No newline at end of file +but that run and install independently of the main tool chain. diff --git a/util/RunZephyrTests.sh b/util/RunZephyrTests.sh index 742a23ef18..2190563351 100755 --- a/util/RunZephyrTests.sh +++ b/util/RunZephyrTests.sh @@ -15,7 +15,7 @@ find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then echo "-----------------------------------------------------------------------------------------------------------" test_name=$(basename $folder) - + if [[ " ${skip[*]} " == *" $test_name "* ]]; then echo "Skipping: $test_name" else @@ -49,7 +49,7 @@ run_zephyr_test() { rm -f /tmp/procfifo rm -f res.text mkfifo /tmp/procfifo - + make run | tee res.txt > /tmp/procfifo & PID=$! SECONDS=0 @@ -91,7 +91,7 @@ run_zephyr_test() { echo "----------------------------------------------------------------" return_val=1 fi - + rm -f /tmp/procfifo popd return "$return_val" @@ -124,4 +124,4 @@ if [ "$overall_success" = false ]; then exit 1 fi -exit 0 \ No newline at end of file +exit 0 diff --git a/util/scripts/launch-fedsd.sh b/util/scripts/launch-fedsd.sh index e09c60fc1e..609f9608af 100755 --- a/util/scripts/launch-fedsd.sh +++ b/util/scripts/launch-fedsd.sh @@ -79,8 +79,8 @@ for each_lft_file in $lft_files_list # Get the file name csv=${each_lft_file%.*} if [ $csv == 'rti' ] - then - # Set the rti csv file + then + # Set the rti csv file rti_csv_file='rti.csv' else # Construct the csv file name and add it to the list @@ -97,7 +97,7 @@ if [ $rti_csv_file == '' ] then # FIXME: Support the case where no rti file is given python3 "${base}/util/tracing/visualization/fedsd.py" "-f" $csv_files_list -else +else echo Building the communication diagram for the following trace files: $lft_files_list in trace_svg.html python3 "${base}/util/tracing/visualization/fedsd.py" "-r" "$rti_csv_file" "-f" $csv_files_list fi diff --git a/util/scripts/launch.sh b/util/scripts/launch.sh index 5c335a6fe8..fc6dc83c6c 100755 --- a/util/scripts/launch.sh +++ b/util/scripts/launch.sh @@ -75,4 +75,3 @@ if [ $# -eq 0 ]; then else "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args="$*" fi - diff --git a/util/tracing/README.md b/util/tracing/README.md index 28d8db23d7..e430e47d7e 100644 --- a/util/tracing/README.md +++ b/util/tracing/README.md @@ -1,6 +1,6 @@ ## util/tracing -This directory contains the source code for utilities that are standalone executables +This directory contains the source code for utilities that are standalone executables for post-processing tracing data created by the tracing function in Lingua Franca. Utilities for visualizing the data are contained in the [visualization](visualization/README.md) @@ -8,16 +8,16 @@ directory. * trace\_to\_csv: Creates a comma-separated values text file from a binary trace file. The resulting file is suitable for analyzing in spreadsheet programs such as Excel. - + * trace\_to\_chrome: Creates a JSON file suitable for importing into Chrome's trace visualizer. Point Chrome to chrome://tracing/ and load the resulting file. - + * trace\_to\_influxdb: A preliminary implementation that takes a binary trace file and uploads its data into [InfluxDB](https://en.wikipedia.org/wiki/InfluxDB). - + ## Installing ``` make install ``` -This puts the executables in lingua-franca/bin. \ No newline at end of file +This puts the executables in lingua-franca/bin. diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md index 82861e9b2a..0121fc15b3 100644 --- a/util/tracing/visualization/README.md +++ b/util/tracing/visualization/README.md @@ -1,6 +1,6 @@ # Trace sequence diagram visualiser -This is a 1st iteration of a prototyping tool for constructing a sequence diagram +This is a 1st iteration of a prototyping tool for constructing a sequence diagram out of the traces. It operates over the csv files generated by `trace_to_csv`. @@ -16,10 +16,6 @@ The output is an html file with the svg in it. # Current problems - The collected traces are not complete. They need to be checked for correcteness as well. -- All arrows are horizontal and can be duplicated. Need further processing to derive the connections +- All arrows are horizontal and can be duplicated. Need further processing to derive the connections for that. - The scale needs exploration - - - - From b7ef452ec1d8e4810c8605e6a2cc15f70547c825 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 13:41:50 +0200 Subject: [PATCH 571/709] fix ps1 script --- util/scripts/launch.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index 26e3db1d30..97d0afd3f3 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -29,7 +29,7 @@ $base="$PSScriptRoot\..\..\" $gradlew="${base}/gradlew.bat" # invoke script -if ($args.Length == 0) { +if ($args.Length -eq 0) { & "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" } else { $argsString = $args -join " " From 1039a0c35a362accabd4c3f71b7ccb57acd99756 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 29 May 2023 13:52:35 +0200 Subject: [PATCH 572/709] fix serialization and integration tests --- .github/workflows/lsp-tests.yml | 4 ++-- .github/workflows/serialization-tests.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index ca82c3f41c..d3ae1123a5 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -69,7 +69,7 @@ jobs: with: python-version: '3.10' - name: Run language server Python tests without PyLint - run: ./gradlew org.lflang:core:integration --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly + run: ./gradlew org.lflang:core:test --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly - name: Install pylint run: python3 -m pip install pylint if: ${{ runner.os != 'macOS' }} @@ -77,7 +77,7 @@ jobs: run: brew install pylint if: ${{ runner.os == 'macOS' }} - name: Run language server tests - run: ./gradlew org.lflang:core:integration --tests org.lflang.tests.lsp.LspTests.*ValidationTest + run: ./gradlew org.lflang:core:test --tests org.lflang.tests.lsp.LspTests.*ValidationTest - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 00738e99fa..24441ff7d6 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew org.lflang:core:integration --test org.lflang.test.serialization.SerializationTest.* + ./gradlew org.lflang:core:test --test org.lflang.test.serialization.SerializationTest.* - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov From 4c05b68385f49bf5df1a53421da11cb4cff3b4e6 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 29 May 2023 10:29:13 -0700 Subject: [PATCH 573/709] Update reactor-c. --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 83b1cef7fd..89dcee3c3f 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 83b1cef7fd4209b3e25b6a310ce8f964277d9692 +Subproject commit 89dcee3c3f95bf8227162f630beada8d96f6270d From 5b8129b40ba013d54d13a066fedb9cc4c6306578 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 29 May 2023 11:59:08 -0700 Subject: [PATCH 574/709] Use a flag to indicate successful exit. For some reason, creating a trap for SIGTERM results in SIGTERM not causing the program to exit. In any case, we really do not want the program to exit without killing the RTI and federates under any circumstance unless we are sure that the program terminated successfully. Therefore, it seems safest to require positive confirmation via an EXITED_SUCCESSFULLY flag that the program really did exit successfully. --- .../launcher/FedLauncherGenerator.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java index 0f024b6499..b3be6acad0 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java @@ -205,7 +205,8 @@ public void doGenerate(List federates, RtiConfig rtiConfig) { "do", " wait $pid", "done", - "echo \"All done.\"") + "echo \"All done.\"", + "EXITED_SUCCESSFULLY=true") + "\n"); // Create bin directory for the script. @@ -281,29 +282,19 @@ private String getSetupCode() { "# Set a trap to kill all background jobs on error or control-C", "# Use two distinct traps so we can see which signal causes this.", "cleanup() {", - " printf \"Killing federate %s.\\n\" ${pids[*]}", - " # The || true clause means this is not an error if kill fails.", - " kill ${pids[@]} || true", - " printf \"#### Killing RTI %s.\\n\" ${RTI}", - " kill ${RTI} || true", - " exit 1", - "}", - "cleanup_err() {", - " echo \"#### Received ERR signal on line $1. Invoking cleanup().\"", - " cleanup", - "}", - "cleanup_sigint() {", - " echo \"#### Received SIGINT signal on line $1. Invoking cleanup().\"", - " cleanup", - "}", - "cleanup_sigterm() {", - " echo \"#### Received SIGTERM signal on line $1. Invoking cleanup().\"", - " cleanup", + " if [ \"$EXITED_SUCCESSFULLY\" = true ] ; then", + " exit 0", + " else", + " printf \"Killing federate %s.\\n\" ${pids[*]}", + " # The || true clause means this is not an error if kill fails.", + " kill ${pids[@]} || true", + " printf \"#### Killing RTI %s.\\n\" ${RTI}", + " kill ${RTI} || true", + " exit 1", + " fi", "}", "", - "trap 'cleanup_err $LINENO' ERR", - "trap 'cleanup_sigint $LINENO' SIGINT", - "trap 'cleanup_sigterm $LINENO' SIGTERM", + "trap 'cleanup; exit' EXIT", "", "# Create a random 48-byte text ID for this federation.", "# The likelihood of two federations having the same ID is 1/16,777,216 (1/2^24).", From 98e33df124a8e96f32a15af2f7a8099ff05f3483 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 29 May 2023 12:03:47 -0700 Subject: [PATCH 575/709] Replace lf_request_stop with request_stop. This replaces all instances in the test/Python/src directory. --- test/Python/src/docker/FilesPropertyContainerized.lf | 4 ++-- .../DistributedStopDecentralizedContainerized.lf | 2 +- test/Python/src/federated/DistributedSendClass.lf | 2 +- test/Python/src/federated/DistributedStop.lf | 10 +++++----- .../src/federated/DistributedStopDecentralized.lf | 2 +- test/Python/src/federated/DistributedStopZero.lf | 6 +++--- test/Python/src/federated/HelloDistributed.lf | 2 +- test/Python/src/federated/PingPongDistributed.lf | 4 ++-- test/Python/src/federated/StopAtShutdown.lf | 6 +++--- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/Python/src/docker/FilesPropertyContainerized.lf b/test/Python/src/docker/FilesPropertyContainerized.lf index c34736af48..26cf706a2b 100644 --- a/test/Python/src/docker/FilesPropertyContainerized.lf +++ b/test/Python/src/docker/FilesPropertyContainerized.lf @@ -7,7 +7,7 @@ preamble {= try: import hello except: - lf_request_stop() + request_stop() =} main reactor { @@ -15,7 +15,7 @@ main reactor { try: import hello except: - lf_request_stop() + request_stop() =} state passed = False timer t(1 msec) diff --git a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf index 11e24746cd..98f5189006 100644 --- a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -1,5 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with decentralized + * Test for request_stop() in federated execution with decentralized * coordination. * * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedSendClass.lf b/test/Python/src/federated/DistributedSendClass.lf index fd056bb0c0..9bc4a52694 100644 --- a/test/Python/src/federated/DistributedSendClass.lf +++ b/test/Python/src/federated/DistributedSendClass.lf @@ -9,7 +9,7 @@ preamble {= reactor A { input o - reaction(o) {= lf_request_stop() =} + reaction(o) {= request_stop() =} } reactor B { diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 06dfe96c36..cb32fc4e84 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -1,5 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with centralized + * Test for request_stop() in federated execution with centralized * coordination. * * @author Soroush Bateni @@ -23,16 +23,16 @@ reactor Sender { if lf.tag().microstep == 0: # Instead of having a separate reaction # for 'act' like Stop.lf, we trigger the - # same reaction to test lf_request_stop() being + # same reaction to test request_stop() being # called multiple times act.schedule(0) if tag.time == USEC(1): - # Call lf_request_stop() both at (1 usec, 0) and + # Call request_stop() both at (1 usec, 0) and # (1 usec, 1) print("Requesting stop at ({}, {}).".format( lf.time.logical_elapsed(), lf.tag().microstep)) - lf_request_stop() + request_stop() _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) if lf.tag_compare(lf.tag(), _1usec1) == 0: @@ -77,7 +77,7 @@ reactor Receiver( print("Requesting stop at ({}, {}).".format( lf.time.logical_elapsed(), lf.tag().microstep)) - lf_request_stop() + request_stop() # The receiver should receive a message at tag # (1 usec, 1) and trigger this reaction self.reaction_invoked_correctly = True diff --git a/test/Python/src/federated/DistributedStopDecentralized.lf b/test/Python/src/federated/DistributedStopDecentralized.lf index e6afa6384b..f3df5ce9f8 100644 --- a/test/Python/src/federated/DistributedStopDecentralized.lf +++ b/test/Python/src/federated/DistributedStopDecentralized.lf @@ -1,5 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with decentralized + * Test for request_stop() in federated execution with decentralized * coordination. * * @author Soroush Bateni diff --git a/test/Python/src/federated/DistributedStopZero.lf b/test/Python/src/federated/DistributedStopZero.lf index 089a839105..aef9d94f53 100644 --- a/test/Python/src/federated/DistributedStopZero.lf +++ b/test/Python/src/federated/DistributedStopZero.lf @@ -1,5 +1,5 @@ /** - * Test for lf_request_stop() in federated execution with centralized + * Test for request_stop() in federated execution with centralized * coordination at tag (0,0). * * @author Soroush Bateni @@ -29,7 +29,7 @@ reactor Sender { print("Requesting stop at ({}, {}).".format( lf.time.logical_elapsed(), lf.tag().microstep)) - lf_request_stop() + request_stop() =} reaction(shutdown) {= @@ -63,7 +63,7 @@ reactor Receiver { print("Requesting stop at ({}, {}).".format( tag.time, tag.microstep)) - lf_request_stop() + request_stop() =} reaction(shutdown) {= diff --git a/test/Python/src/federated/HelloDistributed.lf b/test/Python/src/federated/HelloDistributed.lf index ef99c3f793..e3ae0e97dc 100644 --- a/test/Python/src/federated/HelloDistributed.lf +++ b/test/Python/src/federated/HelloDistributed.lf @@ -13,7 +13,7 @@ reactor Source { reaction(startup) -> out {= print("Sending 'Hello World!' message from source federate."); out.set("Hello World!") - lf_request_stop() + request_stop() =} } diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index 0f58cbf7db..8de76609c9 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -37,7 +37,7 @@ reactor Ping(count = 10) { if self.pingsLeft > 0: serve.schedule(0) else: - lf_request_stop() + request_stop() =} } @@ -53,7 +53,7 @@ reactor Pong(expected = 10) { print("At logical time {}, Pong received {}.\n".format(lf.time.logical_elapsed(), receive.value)) send.set(receive.value) if self.count == self.expected: - lf_request_stop() + request_stop() =} reaction(shutdown) {= diff --git a/test/Python/src/federated/StopAtShutdown.lf b/test/Python/src/federated/StopAtShutdown.lf index 3179c44592..0327623fd9 100644 --- a/test/Python/src/federated/StopAtShutdown.lf +++ b/test/Python/src/federated/StopAtShutdown.lf @@ -1,5 +1,5 @@ /** - * Check that lf_request_stop() doesn't cause any issues at the shutdown tag. + * Check that request_stop() doesn't cause any issues at the shutdown tag. * * Original bug discovered by Steven Wong * @@ -16,7 +16,7 @@ reactor A { reaction(in_) {= print("Got it") =} - reaction(shutdown) {= lf_request_stop() =} + reaction(shutdown) {= request_stop() =} } reactor B { @@ -25,7 +25,7 @@ reactor B { reaction(t) -> out {= out.set(1) =} - reaction(shutdown) {= lf_request_stop() =} + reaction(shutdown) {= request_stop() =} } federated reactor { From 3f5e9443e6668a4066fe10391381bf31ab6e4b55 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 29 May 2023 15:17:24 -0700 Subject: [PATCH 576/709] Fix get_start_time issue. --- test/Python/src/federated/DistributedStop.lf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index cb32fc4e84..174ff53858 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -34,7 +34,7 @@ reactor Sender { lf.tag().microstep)) request_stop() - _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) + _1usec1 = Tag(time=USEC(1) + lf.time.start(), microstep=1) if lf.tag_compare(lf.tag(), _1usec1) == 0: # The reaction was invoked at (1 usec, 1) as expected self.reaction_invoked_correctly = True @@ -82,7 +82,7 @@ reactor Receiver( # (1 usec, 1) and trigger this reaction self.reaction_invoked_correctly = True - _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) + _1usec1 = Tag(time=USEC(1) + lf.time.start(), microstep=1) if lf.tag_compare(lf.tag(), _1usec1) > 0: self.reaction_invoked_correctly = False =} From 83cd35ab79a3b7a210ce1dfdc54d0d881d03c418 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 29 May 2023 16:20:46 -0700 Subject: [PATCH 577/709] Patch over the files property merging. This is not the right solution. The right solution is not to do the files property merging in the first place. This has been discusssed. I think everyone agrees about this, but probably it will not be fixed until the package manager is more complete. --- org.lflang/src/org/lflang/TargetProperty.java | 28 +++++++++++++++---- .../federated/generator/FedTargetConfig.java | 12 +++++++- test/Python/src/include/hello.py | 2 +- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index b3abf815a3..e9e3b0273d 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -31,6 +31,7 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -283,10 +284,6 @@ public enum TargetProperty { (config, value, err) -> { config.files = ASTUtils.elementToListOfStrings(value); }, - // FIXME: This merging of lists is potentially dangerous since - // the incoming list of files can belong to a .lf file that is - // located in a different location, and keeping just filename - // strings like this without absolute paths is incorrect. (config, value, err) -> { config.files.addAll(ASTUtils.elementToListOfStrings(value)); }), @@ -995,15 +992,34 @@ public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { * * @param config The configuration object to update. * @param properties AST node that holds all the target properties. + * @param relativePath The path from the main resource to the resource from which the new + * properties originate. */ - public static void update(TargetConfig config, List properties, ErrorReporter err) { + public static void update( + TargetConfig config, List properties, Path relativePath, ErrorReporter err) { properties.forEach( property -> { TargetProperty p = forName(property.getName()); if (p != null) { // Mark the specified target property as set by the user config.setByUser.add(p); - p.updater.parseIntoTargetConfig(config, property.getValue(), err); + var value = property.getValue(); + if (property.getName().equals("files")) { + var array = LfFactory.eINSTANCE.createArray(); + ASTUtils.elementToListOfStrings(property.getValue()).stream() + .map(relativePath::resolve) // assume all paths are relative + .map(Objects::toString) + .map( + s -> { + var element = LfFactory.eINSTANCE.createElement(); + element.setLiteral(s); + return element; + }) + .forEach(array.getElements()::add); + value = LfFactory.eINSTANCE.createElement(); + value.setArray(array); + } + p.updater.parseIntoTargetConfig(config, value, err); } }); } diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java index 3252f31a39..aa0cfccc14 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java @@ -2,6 +2,7 @@ import static org.lflang.ast.ASTUtils.convertToEmptyListIfNull; +import java.nio.file.Path; import org.eclipse.emf.ecore.resource.Resource; import org.lflang.ErrorReporter; import org.lflang.TargetConfig; @@ -57,11 +58,20 @@ private void mergeImportedConfig( if (targetProperties != null) { // Merge properties TargetProperty.update( - this, convertToEmptyListIfNull(targetProperties.getPairs()), errorReporter); + this, + convertToEmptyListIfNull(targetProperties.getPairs()), + getRelativePath(mainResource, federateResource), + errorReporter); } } } + private Path getRelativePath(Resource source, Resource target) { + return Path.of(source.getURI().toFileString()) + .getParent() + .relativize(Path.of(target.getURI().toFileString()).getParent()); + } + /** Method for the removal of things that should not appear in the target config of a federate. */ private void clearPropertiesToIgnore() { this.setByUser.remove(TargetProperty.CLOCK_SYNC); diff --git a/test/Python/src/include/hello.py b/test/Python/src/include/hello.py index 4f92cbbca6..c26b545aad 100644 --- a/test/Python/src/include/hello.py +++ b/test/Python/src/include/hello.py @@ -1,4 +1,4 @@ class hello: def __init__(self, name = "", value = 0): self.name = name - self.value = value + self.value = value From 853e0228ae2009e96625beeab86c70eba713ed93 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 09:15:54 +0200 Subject: [PATCH 578/709] hotfix: fallback to insecure protocol for fetching from kieler repo --- org.lflang/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/build.gradle b/org.lflang/build.gradle index 8d4f6a41c9..96b16f8771 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/build.gradle @@ -4,7 +4,8 @@ repositories { mavenCentral() // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + url "http://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + allowInsecureProtocol = true } } dependencies { From 0633098078a7917856347c184d4f5854e7443d02 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 09:58:59 +0200 Subject: [PATCH 579/709] also update testing gradle config --- org.lflang.tests/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/build.gradle b/org.lflang.tests/build.gradle index 97f664c1a8..e1311fc5b3 100644 --- a/org.lflang.tests/build.gradle +++ b/org.lflang.tests/build.gradle @@ -2,7 +2,8 @@ repositories { mavenCentral() // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + url "http://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" + allowInsecureProtocol = true } } dependencies { From bb37e1bee1e6b8bef4d232a094ce26096e560d8e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 12:16:12 +0200 Subject: [PATCH 580/709] be more careful about excluding files from spotlessMisc --- build.gradle | 4 +++- org.lflang/core/build.gradle | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 56b50afb4b..63aefb745b 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,9 @@ spotless { format 'misc', { target project.fileTree(project.rootDir) { include '**/*.gradle', '**/*.md', '.gitignore', '**/*.yml', '**/*.sh', '**/*.psi' - exclude '**/reactor-cpp/**', '**/reactor-c/**', '**/reactor-rs/**', '**/lf-python-support' + exclude '**/reactor-cpp/**', '**/reactor-c/**', '**/reactor-rs/**', '**/lf-python-support/**', + '**/src-gen/**', '**/fed-gen/**', '**/test-gen/**', '**/build/**', + 'test/*/include', 'test/*/bin/', 'test/*/share', 'test/*/lib' } // define the steps to apply to those files diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index 2589734b8a..ca269ace61 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -66,6 +66,7 @@ tasks.register('generateXtextLanguage', JavaExec) { inputs.file "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" inputs.file "src/main/java/org/lflang/LinguaFranca.xtext" outputs.dir "src-gen" + outputs.dir "test-gen" outputs.dir "model" outputs.file ".antlr-generator-3.2.0-patch.jar" args += "src/main/java/org/lflang/GenerateLinguaFranca.mwe2" @@ -78,6 +79,7 @@ compileKotlin.dependsOn(generateXtextLanguage) processResources.dependsOn(generateXtextLanguage) clean.dependsOn(cleanGenerateXtextLanguage) spotlessJava.mustRunAfter(generateXtextLanguage) +rootProject.spotlessMisc.mustRunAfter(generateXtextLanguage) tasks.register('getSubmoduleVersions', Exec) { description('Run a Git command to get the current status of submodules') From 80a12633c75053a086ae86f7f982608bf1610a30 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 13:54:40 +0200 Subject: [PATCH 581/709] use gradle's test suite feature to separate integration tests --- .../groovy/org.lflang.test-conventions.gradle | 40 +++++++++++-------- org.lflang/core/build.gradle | 25 +++++++----- .../java/org/lflang/tests/RuntimeTest.java | 13 ------ .../org/lflang/tests/lsp/ErrorInserter.java | 0 .../java/org/lflang/tests/lsp/LspTests.java | 5 --- .../lflang/tests/lsp/MockLanguageClient.java | 0 .../lflang/tests/lsp/MockReportProgress.java | 0 .../lflang/tests/runtime/CArduinoTest.java | 1 - .../org/lflang/tests/runtime/CCppTest.java | 1 - .../lflang/tests/runtime/CSchedulerTest.java | 1 - .../java/org/lflang/tests/runtime/CTest.java | 12 ------ .../org/lflang/tests/runtime/CZephyrTest.java | 2 - .../org/lflang/tests/runtime/CppRos2Test.java | 1 - .../org/lflang/tests/runtime/CppTest.java | 6 --- .../org/lflang/tests/runtime/PythonTest.java | 9 ----- .../org/lflang/tests/runtime/RustTest.java | 0 .../lflang/tests/runtime/TypeScriptTest.java | 8 ---- .../serialization/SerializationTest.java | 2 - .../java/org/lflang/tests/Configurators.java | 0 .../java/org/lflang/tests/LFTest.java | 0 .../java/org/lflang/tests/TestBase.java | 0 .../java/org/lflang/tests/TestError.java | 0 .../java/org/lflang/tests/TestRegistry.java | 3 +- 23 files changed, 40 insertions(+), 89 deletions(-) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/RuntimeTest.java (95%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/lsp/ErrorInserter.java (100%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/lsp/LspTests.java (98%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/lsp/MockLanguageClient.java (100%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/lsp/MockReportProgress.java (100%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CArduinoTest.java (97%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CCppTest.java (98%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CSchedulerTest.java (98%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CTest.java (93%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CZephyrTest.java (98%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CppRos2Test.java (97%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/CppTest.java (95%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/PythonTest.java (94%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/RustTest.java (100%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/runtime/TypeScriptTest.java (90%) rename org.lflang/core/src/{test => integrationTest}/java/org/lflang/tests/serialization/SerializationTest.java (96%) rename org.lflang/core/src/{test => testFixtures}/java/org/lflang/tests/Configurators.java (100%) rename org.lflang/core/src/{test => testFixtures}/java/org/lflang/tests/LFTest.java (100%) rename org.lflang/core/src/{test => testFixtures}/java/org/lflang/tests/TestBase.java (100%) rename org.lflang/core/src/{test => testFixtures}/java/org/lflang/tests/TestError.java (100%) rename org.lflang/core/src/{test => testFixtures}/java/org/lflang/tests/TestRegistry.java (99%) diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 8385720b8d..ef5a1467e3 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -25,36 +25,42 @@ dependencies { testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:$xtextVersion" } -def integrationTest = false -tasks.register('integration') { - integrationTest = true -} -integration.finalizedBy(test) -test { - useJUnitPlatform { - if (integrationTest) { - includeTags 'Integration' - } else { - excludeTags 'Integration' +testing { + suites { + test { + useJUnitJupiter() } - } - if (integrationTest && project.hasProperty('target')) { - filter { - includeTestsMatching "org.lflang.tests.runtime.${project.property('target')}Test.*" + integrationTest(JvmTestSuite) { + dependencies { + implementation project() + implementation testFixtures(project()) + } } } +} + +test { testLogging { events "passed", "skipped", "failed" showStandardStreams = true exceptionFormat "full" } - maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 + integrationTest { + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + exceptionFormat "full" + } - failFast = true + failFast = true + workingDir = rootProject.projectDir + } + maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 + failFast = true workingDir = rootProject.projectDir } diff --git a/org.lflang/core/build.gradle b/org.lflang/core/build.gradle index ca269ace61..536bed337d 100644 --- a/org.lflang/core/build.gradle +++ b/org.lflang/core/build.gradle @@ -4,19 +4,24 @@ plugins { } sourceSets { - main { - java { - srcDirs = ['src/main/java', 'src-gen'] + main { + java { + srcDirs = ['src/main/java', 'src-gen'] + } + resources { + srcDirs = ['src/main/resources', 'src-gen'] + } } - resources { - srcDirs = ['src/main/resources', 'src-gen'] + test { + java { + srcDirs = ['src/test/java', 'test-gen'] + } } - } - test { - java { - srcDirs = ['src/test/java', 'test-gen'] + testFixtures { + java { + srcDirs = ['src/testFixtures/java', 'test-gen'] + } } - } } dependencies { diff --git a/org.lflang/core/src/test/java/org/lflang/tests/RuntimeTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java similarity index 95% rename from org.lflang/core/src/test/java/org/lflang/tests/RuntimeTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java index c873dcd427..8b1db46d9e 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/RuntimeTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java @@ -55,7 +55,6 @@ protected boolean supportsDockerOption() { } @Test - @Tag("Integration") public void runGenericTests() { runTestsForTargets( Message.DESC_GENERIC, @@ -66,7 +65,6 @@ public void runGenericTests() { } @Test - @Tag("Integration") public void runTargetSpecificTests() { runTestsForTargets( Message.DESC_TARGET_SPECIFIC, @@ -77,7 +75,6 @@ public void runTargetSpecificTests() { } @Test - @Tag("Integration") public void runMultiportTests() { runTestsForTargets( Message.DESC_MULTIPORT, @@ -88,7 +85,6 @@ public void runMultiportTests() { } @Test - @Tag("Integration") public void runTypeParameterTests() { Assumptions.assumeTrue(supportsGenericTypes(), Message.NO_GENERICS_SUPPORT); runTestsForTargets( @@ -100,7 +96,6 @@ public void runTypeParameterTests() { } @Test - @Tag("Integration") public void runAsFederated() { Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); @@ -122,7 +117,6 @@ public void runAsFederated() { } @Test - @Tag("Integration") public void runConcurrentTests() { runTestsForTargets( Message.DESC_CONCURRENT, @@ -133,7 +127,6 @@ public void runConcurrentTests() { } @Test - @Tag("Integration") public void runFederatedTests() { Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); runTestsForTargets( @@ -146,7 +139,6 @@ public void runFederatedTests() { /** Run the tests for modal reactors. */ @Test - @Tag("Integration") public void runModalTests() { runTestsForTargets( Message.DESC_MODAL, @@ -158,7 +150,6 @@ public void runModalTests() { /** Run the tests for non-inlined reaction bodies. */ @Test - @Tag("Integration") public void runNoInliningTests() { runTestsForTargets( Message.DESC_MODAL, @@ -173,7 +164,6 @@ public void runNoInliningTests() { * platform is not Linux or target does not support Docker. */ @Test - @Tag("Integration") public void runDockerTests() { Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); @@ -191,7 +181,6 @@ public void runDockerTests() { * tests. */ @Test - @Tag("Integration") public void runDockerFederatedTests() { Assumptions.assumeTrue(isLinux(), Message.NO_DOCKER_TEST_SUPPORT); Assumptions.assumeTrue(supportsDockerOption(), Message.NO_DOCKER_SUPPORT); @@ -205,7 +194,6 @@ public void runDockerFederatedTests() { } @Test - @Tag("Integration") public void runWithThreadingOff() { Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); this.runTestsForTargets( @@ -218,7 +206,6 @@ public void runWithThreadingOff() { /** Run enclave tests if the target supports enclaves. */ @Test - @Tag("Integration") public void runEnclaveTests() { Assumptions.assumeTrue(supportsEnclaves(), Message.NO_ENCLAVE_SUPPORT); runTestsForTargets( diff --git a/org.lflang/core/src/test/java/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/lsp/ErrorInserter.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java similarity index 98% rename from org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java index 52339161ea..2e7b7b341a 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/lsp/LspTests.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java @@ -57,35 +57,30 @@ class LspTests { /** Test for false negatives in Python syntax-only validation. */ @Test - @Tag("Integration") void pythonValidationTestSyntaxOnly() throws IOException { targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON_SYNTAX_ONLY); } /** Test for false negatives in C++ validation. */ @Test - @Tag("Integration") void cppValidationTest() throws IOException { targetLanguageValidationTest(Target.CPP, ErrorInserter.CPP); } /** Test for false negatives in Python validation. */ @Test - @Tag("Integration") void pythonValidationTest() throws IOException { targetLanguageValidationTest(Target.Python, ErrorInserter.PYTHON); } /** Test for false negatives in Rust validation. */ @Test - @Tag("Integration") void rustValidationTest() throws IOException { targetLanguageValidationTest(Target.Rust, ErrorInserter.RUST); } /** Test for false negatives in TypeScript validation. */ @Test - @Tag("Integration") void typescriptValidationTest() throws IOException { targetLanguageValidationTest(Target.TS, ErrorInserter.TYPESCRIPT); } diff --git a/org.lflang/core/src/test/java/org/lflang/tests/lsp/MockLanguageClient.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/lsp/MockLanguageClient.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/lsp/MockReportProgress.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/lsp/MockReportProgress.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CArduinoTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java similarity index 97% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CArduinoTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java index 4758977143..e621092e51 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CArduinoTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java @@ -21,7 +21,6 @@ public CArduinoTest() { } @Test - @Tag("Integration") public void buildArduinoTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); super.runTestsFor( diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CCppTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java similarity index 98% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CCppTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java index 04ea680194..82859870ae 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java @@ -27,7 +27,6 @@ public CCppTest() { /** Run C tests with the target CCpp. */ @Test - @Tag("Integration") public void runAsCCpp() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); runTestsForTargets( diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java similarity index 98% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CSchedulerTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java index 4730962ee0..8ff3ef9314 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CSchedulerTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java @@ -22,7 +22,6 @@ public CSchedulerTest() { * (e.g., -Dscheduler=GEDF_NP). */ @Test - @Tag("Integration") public void runWithNonDefaultSchedulers() { EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, TestCategory.MULTIPORT); diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java similarity index 93% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java index 63122fb4c6..dbf173c0d1 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java @@ -47,7 +47,6 @@ public CTest() { } @Override - @Tag("Integration") protected boolean supportsSingleThreadedExecution() { return true; } @@ -63,14 +62,12 @@ protected boolean supportsDockerOption() { } @Test - @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test - @Tag("Integration") @Override public void runTargetSpecificTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -78,21 +75,18 @@ public void runTargetSpecificTests() { } @Test - @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test - @Tag("Integration") @Override public void runWithThreadingOff() { super.runWithThreadingOff(); } @Test - @Tag("Integration") @Disabled("TODO only 27/96 tests pass") @Override public void runAsFederated() { @@ -101,14 +95,12 @@ public void runAsFederated() { } @Test - @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test - @Tag("Integration") @Override public void runFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -116,26 +108,22 @@ public void runFederatedTests() { } @Test - @Tag("Integration") public void runModalTests() { super.runModalTests(); } @Test - @Tag("Integration") public void runNoInliningTests() { super.runNoInliningTests(); } @Test - @Tag("Integration") @Override public void runDockerTests() { super.runDockerTests(); } @Test - @Tag("Integration") @Override public void runDockerFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java similarity index 98% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CZephyrTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java index 777308b221..1cf5dc550f 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java @@ -45,7 +45,6 @@ public CZephyrTest() { } @Test - @Tag("Integration") public void buildZephyrTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor( @@ -58,7 +57,6 @@ public void buildZephyrTests() { } @Test - @Tag("Integration") public void buildGenericTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor( diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppRos2Test.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java similarity index 97% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CppRos2Test.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java index 1a333eb145..68c8dfc0d7 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppRos2Test.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java @@ -24,7 +24,6 @@ public CppRos2Test() { /** Run C++ tests with the ros2 target property set */ @Test - @Tag("Integration") public void runWithRos2() { Assumptions.assumeTrue(isLinux(), "Only supported on Linux"); Element trueLiteral = LfFactory.eINSTANCE.createElement(); diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java similarity index 95% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/CppTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java index 879e6cdc5b..b5bd36cf14 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/CppTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java @@ -51,41 +51,35 @@ protected boolean supportsEnclaves() { } @Test - @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test - @Tag("Integration") @Override public void runTargetSpecificTests() { super.runTargetSpecificTests(); } @Test - @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test - @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test - @Tag("Integration") @Override public void runFederatedTests() { super.runFederatedTests(); } @Test - @Tag("Integration") public void runRos2Tests() {} } diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/PythonTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java similarity index 94% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/PythonTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java index e25a3220d2..1c258b7481 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/PythonTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java @@ -27,7 +27,6 @@ import java.util.Properties; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; @@ -73,28 +72,24 @@ protected boolean supportsDockerOption() { } @Test - @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test - @Tag("Integration") @Override public void runTargetSpecificTests() { super.runTargetSpecificTests(); } @Test - @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test - @Tag("Integration") @Disabled("TODO") @Override public void runAsFederated() { @@ -103,14 +98,12 @@ public void runAsFederated() { } @Test - @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test - @Tag("Integration") @Override public void runFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -118,14 +111,12 @@ public void runFederatedTests() { } @Test - @Tag("Integration") @Override public void runDockerTests() { super.runDockerTests(); } @Test - @Tag("Integration") @Override public void runDockerFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/RustTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/RustTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/runtime/TypeScriptTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java similarity index 90% rename from org.lflang/core/src/test/java/org/lflang/tests/runtime/TypeScriptTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java index 0945c3ebe3..8494f2cad9 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/runtime/TypeScriptTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java @@ -31,35 +31,30 @@ protected boolean supportsFederatedExecution() { } @Test - @Tag("Integration") @Override public void runGenericTests() { super.runGenericTests(); } @Test - @Tag("Integration") @Override public void runTargetSpecificTests() { super.runTargetSpecificTests(); } @Test - @Tag("Integration") @Override public void runMultiportTests() { super.runMultiportTests(); } @Test - @Tag("Integration") @Override public void runConcurrentTests() { super.runConcurrentTests(); } @Test - @Tag("Integration") @Override public void runFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -67,14 +62,12 @@ public void runFederatedTests() { } @Test - @Tag("Integration") @Override public void runDockerTests() { super.runDockerTests(); } @Test - @Tag("Integration") @Override public void runDockerFederatedTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); @@ -82,7 +75,6 @@ public void runDockerFederatedTests() { } @Test - @Tag("Integration") @Override public void runAsFederated() {} } diff --git a/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java similarity index 96% rename from org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java index 25e0983783..01d08adee9 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/serialization/SerializationTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java @@ -23,7 +23,6 @@ protected void addExtraLfcArgs(Properties args) { } @Test - @Tag("Integration") public void runSerializationTestsWithThreadingOff() { Assumptions.assumeTrue(supportsSingleThreadedExecution(), Message.NO_SINGLE_THREADED_SUPPORT); runTestsForTargets( @@ -35,7 +34,6 @@ public void runSerializationTestsWithThreadingOff() { } @Test - @Tag("Integration") public void runSerializationTests() { Assumptions.assumeFalse(isWindows(), Message.NO_WINDOWS_SUPPORT); runTestsForTargets( diff --git a/org.lflang/core/src/test/java/org/lflang/tests/Configurators.java b/org.lflang/core/src/testFixtures/java/org/lflang/tests/Configurators.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/Configurators.java rename to org.lflang/core/src/testFixtures/java/org/lflang/tests/Configurators.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/LFTest.java b/org.lflang/core/src/testFixtures/java/org/lflang/tests/LFTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/LFTest.java rename to org.lflang/core/src/testFixtures/java/org/lflang/tests/LFTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/TestBase.java b/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestBase.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/TestBase.java rename to org.lflang/core/src/testFixtures/java/org/lflang/tests/TestBase.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/TestError.java b/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestError.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/TestError.java rename to org.lflang/core/src/testFixtures/java/org/lflang/tests/TestError.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/TestRegistry.java b/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java similarity index 99% rename from org.lflang/core/src/test/java/org/lflang/tests/TestRegistry.java rename to org.lflang/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java index 2c59740e0a..483448bd8f 100644 --- a/org.lflang/core/src/test/java/org/lflang/tests/TestRegistry.java +++ b/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java @@ -200,10 +200,11 @@ public String getHeader() { // Walk the tree. try { Path dir = LF_TEST_PATH.resolve(target.getDirectoryName()).resolve("src"); + System.out.println(dir.toAbsolutePath()); if (Files.exists(dir)) { new TestDirVisitor(rs, target, dir).walk(); } else { - System.out.println("WARNING: No test directory for target " + target + "\n"); + System.out.println("WARNING: No test directory for target " + target + "\n"); } } catch (IOException e) { From 41769205e26549b0c082f32fd157d08e6a8434a6 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 15:11:11 +0200 Subject: [PATCH 582/709] add a targetTest task to the root project --- build.gradle | 14 +++++++++++--- .../main/groovy/org.lflang.test-conventions.gradle | 7 +++++++ .../java/org/lflang/tests/RuntimeTest.java | 1 - .../java/org/lflang/tests/lsp/LspTests.java | 1 - .../org/lflang/tests/runtime/CArduinoTest.java | 1 - .../java/org/lflang/tests/runtime/CCppTest.java | 1 - .../org/lflang/tests/runtime/CSchedulerTest.java | 1 - .../java/org/lflang/tests/runtime/CTest.java | 1 - .../java/org/lflang/tests/runtime/CZephyrTest.java | 1 - .../java/org/lflang/tests/runtime/CppRos2Test.java | 1 - .../java/org/lflang/tests/runtime/CppTest.java | 1 - .../org/lflang/tests/runtime/TypeScriptTest.java | 1 - .../tests/serialization/SerializationTest.java | 1 - 13 files changed, 18 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 63aefb745b..7130f505d1 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { spotless { format 'misc', { - target project.fileTree(project.rootDir) { + target rootProject.fileTree(rootProject.rootDir) { include '**/*.gradle', '**/*.md', '.gitignore', '**/*.yml', '**/*.sh', '**/*.psi' exclude '**/reactor-cpp/**', '**/reactor-c/**', '**/reactor-rs/**', '**/lf-python-support/**', '**/src-gen/**', '**/fed-gen/**', '**/test-gen/**', '**/build/**', @@ -29,8 +29,8 @@ spotless { } // Make the LF formatting task depend on lff -spotlessLinguaFranca.dependsOn(':org.lflang:cli:lff:installDist') -spotlessLinguaFranca.inputs.files(tasks.getByPath(':org.lflang:cli:lff:installDist').outputs) +spotlessLinguaFranca.dependsOn('org.lflang:cli:lff:installDist') +spotlessLinguaFranca.inputs.files(tasks.getByPath('org.lflang:cli:lff:installDist').outputs) distributions { clitools { @@ -58,3 +58,11 @@ tasks.register('runLfc', JavaExec) { tasks.register('runLff', JavaExec) { dependsOn('org.lflang:cli:lff:run') } +tasks.register('targetTest') { + if (!project.hasProperty('target')) { + def testFiles = rootProject.fileTree("${rootProject.rootDir}/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime").files + def targets = testFiles.collect {it.getName().substring(0, it.getName().length() - 9);} + throw new GradleException("Please set the \'target\' project property using -Ptarget=<...>. You may chose any of $targets") + } + finalizedBy('org.lflang:core:integrationTest') +} diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index ef5a1467e3..00025fb5f1 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -49,6 +49,13 @@ test { exceptionFormat "full" } integrationTest { + + if (project.hasProperty('target')) { + filter { + includeTestsMatching "org.lflang.tests.runtime.${project.property('target')}Test.*" + } + } + testLogging { events "passed", "skipped", "failed" showStandardStreams = true diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java index 8b1db46d9e..2dfd42d38b 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java @@ -3,7 +3,6 @@ import java.util.EnumSet; import java.util.List; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.ast.ASTUtils; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java index 2e7b7b341a..fe52d6016c 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java @@ -12,7 +12,6 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.lsp4j.Diagnostic; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java index e621092e51..95363fd30b 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java @@ -2,7 +2,6 @@ import java.util.List; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java index 82859870ae..ba1865e870 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java @@ -1,7 +1,6 @@ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.ast.ASTUtils; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java index 8ff3ef9314..fd2345723f 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java @@ -1,7 +1,6 @@ package org.lflang.tests.runtime; import java.util.EnumSet; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.TargetProperty.SchedulerOption; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java index dbf173c0d1..4902550661 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java @@ -26,7 +26,6 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java index 1cf5dc550f..c151c1bb76 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java @@ -26,7 +26,6 @@ import java.util.List; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java index 68c8dfc0d7..dc2612c14b 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java @@ -1,7 +1,6 @@ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.ast.ASTUtils; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java index b5bd36cf14..20973189b9 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java @@ -26,7 +26,6 @@ ***************/ package org.lflang.tests.runtime; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java index 8494f2cad9..036211607a 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java @@ -1,7 +1,6 @@ package org.lflang.tests.runtime; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java index 01d08adee9..26f3ec37af 100644 --- a/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java @@ -2,7 +2,6 @@ import java.util.Properties; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; From 07b2563bb10f3acef9d668c46fa97b958b6aa312 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 15:20:30 +0200 Subject: [PATCH 583/709] update CI scripts --- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/c-tests.yml | 2 +- .github/workflows/c-zephyr-tests.yml | 2 +- .github/workflows/cpp-ros2-tests.yml | 2 +- .github/workflows/cpp-tests.yml | 2 +- .github/workflows/lsp-tests.yml | 4 ++-- .github/workflows/py-tests.yml | 2 +- .github/workflows/rs-tests.yml | 2 +- .github/workflows/serialization-tests.yml | 2 +- .github/workflows/ts-tests.yml | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 6082eaa17d..0495a4e2e4 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -63,7 +63,7 @@ jobs: arduino-cli core install arduino:sam arduino-cli core install arduino:mbed - name: Perform Arduino tests for C target with default scheduler - run: ./gradlew integration -Ptarget=Arduino + run: ./gradlew targetTest -Ptarget=Arduino - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index e498ebe6ad..2ab896ebf3 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -62,7 +62,7 @@ jobs: ./gradlew integration -Ptarget=C -Dscheduler=${{ inputs.scheduler }} if: ${{ !inputs.use-cpp && inputs.scheduler }} - name: Perform tests for CCpp target with default scheduler - run: ./gradlew integration -Ptarget=CCpp + run: ./gradlew targetTest -Ptarget=CCpp if: ${{ inputs.use-cpp && !inputs.scheduler }} - name: Collect code coverage run: ./gradlew jacocoTestReport diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 39b225b3ed..a8854dfa25 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -41,7 +41,7 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler run: | - ./gradlew integration -Ptarget=CZephyr + ./gradlew targetTest -Ptarget=CZephyr util/RunZephyrTests.sh test/C/src-gen - name: Collect code coverage run: ./gradlew jacocoTestReport diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index 7c23700794..da5d98523d 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -35,7 +35,7 @@ jobs: - name: Run C++ tests; run: | source /opt/ros/*/setup.bash - ./gradlew integration -Ptarget=CppRos2 + ./gradlew targetTest -Ptarget=CppRos2 - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index 35b972e6c2..b4ad00e7f6 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -48,7 +48,7 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Run C++ tests; run: | - ./gradlew integration -Ptarget=Cpp + ./gradlew targetTest -Ptarget=Cpp - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index d3ae1123a5..54d430fd9d 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -69,7 +69,7 @@ jobs: with: python-version: '3.10' - name: Run language server Python tests without PyLint - run: ./gradlew org.lflang:core:test --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly + run: ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly - name: Install pylint run: python3 -m pip install pylint if: ${{ runner.os != 'macOS' }} @@ -77,7 +77,7 @@ jobs: run: brew install pylint if: ${{ runner.os == 'macOS' }} - name: Run language server tests - run: ./gradlew org.lflang:core:test --tests org.lflang.tests.lsp.LspTests.*ValidationTest + run: ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.lsp.LspTests.*ValidationTest - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 436885243a..55a527d57c 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -60,7 +60,7 @@ jobs: ref: ${{ inputs.reactor-c-py-ref }} if: ${{ inputs.reactor-c-py-ref }} - name: Run Python tests - run: ./gradlew integration -Ptarget=Python + run: ./gradlew targetTest -Ptarget=Python - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index c84b5266aa..b444ceaa4e 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -64,7 +64,7 @@ jobs: rust-version: ${{ matrix.rust }} components: clippy - name: Run Rust tests - run: ./gradlew integration -Ptarget=Rust + run: ./gradlew targetTest -Ptarget=Rust - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 24441ff7d6..b6403c6b19 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew org.lflang:core:test --test org.lflang.test.serialization.SerializationTest.* + ./gradlew org.lflang:core:integrationTest --test org.lflang.test.serialization.SerializationTest.* - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 4b8bd1905f..9253898eeb 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -33,7 +33,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew integration -Ptarget=TypeScript -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" + ./gradlew targetTest -Ptarget=TypeScript -Druntime="git://github.com/lf-lang/reactor-ts.git#minor-reorg" - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov From 669a37ee72851d55e64bc1eaad46afe3e9990038 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 15:38:06 +0200 Subject: [PATCH 584/709] update README --- test/C/README.md | 5 ----- test/Cpp/README.md | 2 -- test/Python/README.md | 2 -- test/README.md | 35 +++++++++++++++-------------------- test/TypeScript/README.md | 24 ------------------------ 5 files changed, 15 insertions(+), 53 deletions(-) delete mode 100644 test/C/README.md delete mode 100644 test/Cpp/README.md delete mode 100644 test/Python/README.md delete mode 100644 test/TypeScript/README.md diff --git a/test/C/README.md b/test/C/README.md deleted file mode 100644 index 68d6d4a1b7..0000000000 --- a/test/C/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Library of C tests -To run the entire C test suite, in the lingua-franca directory, execute: -``` - ./gradlew test --tests "org.lflang.tests.runtime.CTest.*" -``` diff --git a/test/Cpp/README.md b/test/Cpp/README.md deleted file mode 100644 index 6a890d9ec2..0000000000 --- a/test/Cpp/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Library of C++ tests -To run the entire test suite, execute `./gradlew test --tests org.lflang.tests.runtime.CppTest.*`. diff --git a/test/Python/README.md b/test/Python/README.md deleted file mode 100644 index ceff2c3094..0000000000 --- a/test/Python/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Library of Python tests -To run the entire test suite, execute `./gradlew test --tests org.lflang.tests.runtime.PythonTest.*`. diff --git a/test/README.md b/test/README.md index d321d8dd7f..ec3ba683fd 100644 --- a/test/README.md +++ b/test/README.md @@ -1,29 +1,20 @@ -# LF system tests +# LF integration tests -**System tests** are complete Lingua Franca programs that are compiled and executed automatically. A test passes if it successfully compiles and runs to completion with normal termination (return code 0). These tests are located in a subdirectory corresponding to their target language. +**Integration tests** are complete Lingua France programs that are compiled and executed automatically. A test passes if it successfully compiles and runs to completion with normal termination (return code 0). These tests are located in a subdirectory corresponding to their target language. ### Running from the command line -The simplest way to run the regression tests is to use a Bash script called `run-lf-tests` in `$LF/bin`, which takes the target language as a parameter: +The simplest way to run integration tests for a specific target is the `targetTest` gradle task. For instance, you can use the following command to run all Rust tests: ``` -run-lf-tests C -run-lf-tests Cpp -run-lf-tests Python -run-lf-tests TypeScript +./gradlew targetTest -Ptarget=Rust ``` +You can specify any valid target. If you run the task without specifying the target property `./gradlew tagetTest` it will produce an error message and list all available targets. -You can also selectively run just some of the tests. For example, to run the system tests for an individual target language, do this: +The `targetTest` task is essentially a convenient shortcut for the following: ``` -./gradlew test --tests org.lflang.tests.runtime.CTest.* -./gradlew test --tests org.lflang.tests.runtime.CppTest.* -./gradlew test --tests org.lflang.tests.runtime.PythonTest.* -./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -``` - -To run a single test case, use the `runSingleTest` gradle task along with the path to the test source file: -``` -./gradlew runSingleTest --args test/C/src/Minimal.lf +./gradew org.lflang:core:integrationTest --test org.lflang.tests.runtime.Test.* ``` +If you prefer have more control over which tests are executed, you can also use this more verbose version. It is also possible to run a subset of the tests. For example, the C tests are organized into the following categories: @@ -32,10 +23,14 @@ It is also possible to run a subset of the tests. For example, the C tests are o * **federated** tests are `.lf` files located in `$LF/test/C/src/federated`. * **multiport** tests are `.lf` files located in `$LF/test/C/src/multiport`. -To invoke only the tests in the `concurrent` category, for example, do this: +To invoke only the C tests in the `concurrent` category, for example, do this: ``` -cd $LF -./gradlew test --tests org.lflang.tests.runtime.CTest.runConcurrentTests +./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.runtime.CTest.runConcurrentTests +``` + +To run a single test case, use the `runSingleTest` gradle task along with the path to the test source file: +``` +./gradlew runSingleTest --args test/C/src/Minimal.lf ``` ### LSP tests diff --git a/test/TypeScript/README.md b/test/TypeScript/README.md deleted file mode 100644 index bc01867fbe..0000000000 --- a/test/TypeScript/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Library of TypeScript tests -To run the entire test suite, execute `./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.*`. - -## Using an alternative runtime -To run the tests with an alternative runtime, use the `-Druntime` flag to specify where to find it. - -### Examples -- To use a local checkout of `reactor-ts` located in the local file system in the directory `~/lf-lang/reactor-ts`: -``` -./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="~/lf-lang/reactor-ts" -``` -- To point to a branch of a remote repository, use: -``` --Druntime="git://github.com/lf-lang/reactor-ts.git#branch-name -``` - -- Note that `lfc` can be pointed to an alternative runtime as well, using the `external-runtime-path` switch: -``` -lfc test/TypeScript/src/Minimal.lf --external-runtime-path ~/lf-lang/reactor-ts -``` -- To point `lfc` to a particular ref (e.g. `main`, `v0.1.0` or `f8c6d2379f278e22ad48410bf06cf0909405ecc3`) in the `lf-lang/reactor-ts` repo: -``` -lfc test/TypeScript/src/Minimal.lf --runtime-version -``` From d347c5869bfde35bb5cf6e40b2c00066478535ef Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 15:39:21 +0200 Subject: [PATCH 585/709] fix ci configs --- .github/workflows/c-tests.yml | 4 ++-- .github/workflows/serialization-tests.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 2ab896ebf3..f072385183 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -54,12 +54,12 @@ jobs: uses: ./.github/actions/install-rti if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform tests for C target with default scheduler - run: ./gradlew integration -Ptarget=C + run: ./gradlew targetTest -Ptarget=C if: ${{ !inputs.use-cpp && !inputs.scheduler }} - name: Perform tests for C target with specified scheduler (no LSP tests) run: | echo "Specified scheduler: ${{ inputs.scheduler }}" - ./gradlew integration -Ptarget=C -Dscheduler=${{ inputs.scheduler }} + ./gradlew targetTest -Ptarget=C -Dscheduler=${{ inputs.scheduler }} if: ${{ !inputs.use-cpp && inputs.scheduler }} - name: Perform tests for CCpp target with default scheduler run: ./gradlew targetTest -Ptarget=CCpp diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index b6403c6b19..0f79c49e74 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew org.lflang:core:integrationTest --test org.lflang.test.serialization.SerializationTest.* + ./gradlew org.lflang:core:integrationTest --tests org.lflang.test.serialization.SerializationTest.* - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov From eec9cd87278782dfdc9ddc70d6d07416a688503c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 30 May 2023 16:04:22 +0200 Subject: [PATCH 586/709] Remove mistaken commit --- .west/config | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .west/config diff --git a/.west/config b/.west/config deleted file mode 100644 index ccd607713e..0000000000 --- a/.west/config +++ /dev/null @@ -1,4 +0,0 @@ -[manifest] -path = /home/erling/dev/lf-west-template/deps/zephyr -file = west.yml - From 3e0f2ee23e583177c691060fc0aa9b86cf3176ef Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 16:13:24 +0200 Subject: [PATCH 587/709] add singleTest task --- build.gradle | 6 ++ .../groovy/org.lflang.test-conventions.gradle | 10 +++ org.lflang.tests/about.html | 80 ------------------- .../java/org/lflang/tests/RunSingleTest.java | 21 ++--- test/README.md | 4 +- 5 files changed, 30 insertions(+), 91 deletions(-) delete mode 100644 org.lflang.tests/about.html rename org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java => org.lflang/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java (87%) diff --git a/build.gradle b/build.gradle index 7130f505d1..88a262e1db 100644 --- a/build.gradle +++ b/build.gradle @@ -66,3 +66,9 @@ tasks.register('targetTest') { } finalizedBy('org.lflang:core:integrationTest') } +tasks.register('singleTest') { + if (!project.hasProperty('singleTest')) { + throw new GradleException('Please set the \'singleTest\' project property using -PsingleTest=<...> to specify the LF test file that you would like to run.') + } + finalizedBy('org.lflang:core:integrationTest') +} diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 00025fb5f1..021cb163a4 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -49,11 +49,21 @@ test { exceptionFormat "full" } integrationTest { + // Pass properties on to the Java VM + systemProperty 'scheduler', System.getProperty('scheduler') + systemProperty 'runtime', System.getProperty('runtime') + if (rootProject.hasProperty('singleTest')) { + systemProperty 'singleTest', rootProject.getProperty('singleTest') + } if (project.hasProperty('target')) { filter { includeTestsMatching "org.lflang.tests.runtime.${project.property('target')}Test.*" } + } else if (project.hasProperty('singleTest')) { + filter { + includeTestsMatching "org.lflang.tests.RunSingleTest.runSingleTest" + } } testLogging { diff --git a/org.lflang.tests/about.html b/org.lflang.tests/about.html deleted file mode 100644 index 2b772cc110..0000000000 --- a/org.lflang.tests/about.html +++ /dev/null @@ -1,80 +0,0 @@ - - - - - About - - -

    About This Content

    - -

    October 18, 2019

    -

    License

    - -

    - Lingua Franca is a polyglot coordination language for defining and composing reactors. -

    - -

    - For more information about Lingua-Franca, see https://github.com/icyphy/lingua-franca -

    - -

    - The Lingua-Franca toolkit is licensed under the BSD 2-Clause License: -

    - -

    - Copyright (c) 2019, Industrial Cyberphysical Systems (iCyPhy). All rights reserved. -

    - -

    - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: -

    - -
      -
    1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -
    2. -
    3. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. -
    4. -
    - -

    - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - OF SUCH DAMAGE. -

    - -

    - SPDX-License-Identifier: BSD-2-Clause -

    - - - diff --git a/org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java b/org.lflang/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java similarity index 87% rename from org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java rename to org.lflang/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java index fdb26de7f5..3746369c89 100644 --- a/org.lflang.tests/src/org/lflang/tests/RunSingleTestMain.java +++ b/org.lflang/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java @@ -24,11 +24,14 @@ package org.lflang.tests; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + import java.io.FileNotFoundException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.runtime.CCppTest; import org.lflang.tests.runtime.CTest; @@ -38,26 +41,26 @@ import org.lflang.tests.runtime.TypeScriptTest; /** - * Execute a single test case. Use it with the gradle task {@code gradle runSingleTest --args - * test/Python/src/Minimal.lf} + * Execute a single test case. Use it with the gradle task {@code ./gradlew singleTest -PsingleTest + * test/C/src/Minimal.lf} * * @author Clément Fournier */ -public class RunSingleTestMain { +public class RunSingleTest { private static final Pattern TEST_FILE_PATTERN = Pattern.compile("(test/(\\w+))/src/([^/]++/)*(\\w+.lf)"); - public static void main(String[] args) throws FileNotFoundException { - if (args.length != 1) { - throw new IllegalArgumentException("Expected 1 path to an LF file"); - } - var path = Paths.get(args[0]); + @Test + public void runSingleTest() throws FileNotFoundException { + assumeTrue(System.getProperty("singleTest") != null); + + var path = Paths.get(System.getProperty("singleTest")); if (!Files.exists(path)) { throw new FileNotFoundException("No such test file: " + path); } - Matcher matcher = TEST_FILE_PATTERN.matcher(args[0]); + Matcher matcher = TEST_FILE_PATTERN.matcher(path.toString()); if (!matcher.matches()) { throw new FileNotFoundException("Not a test: " + path); } diff --git a/test/README.md b/test/README.md index ec3ba683fd..ecfdf8e876 100644 --- a/test/README.md +++ b/test/README.md @@ -28,9 +28,9 @@ To invoke only the C tests in the `concurrent` category, for example, do this: ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.runtime.CTest.runConcurrentTests ``` -To run a single test case, use the `runSingleTest` gradle task along with the path to the test source file: +To run a single test case, use the `singleTest` gradle task along with the path to the test source file: ``` -./gradlew runSingleTest --args test/C/src/Minimal.lf +./gradlew singleTest -PsingleTest test/C/src/Minimal.lf ``` ### LSP tests From 979883d8c365e559d084e6e840969ba2fbb22c69 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 16:16:16 +0200 Subject: [PATCH 588/709] fix ci configs --- .github/workflows/c-arduino-tests.yml | 2 +- .github/workflows/serialization-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 0495a4e2e4..18d1a2962a 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -63,7 +63,7 @@ jobs: arduino-cli core install arduino:sam arduino-cli core install arduino:mbed - name: Perform Arduino tests for C target with default scheduler - run: ./gradlew targetTest -Ptarget=Arduino + run: ./gradlew targetTest -Ptarget=CArduino - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 0f79c49e74..59aea0bb31 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew org.lflang:core:integrationTest --tests org.lflang.test.serialization.SerializationTest.* + ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.serialization.SerializationTest.* - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov From 465f0bd8d5069d0fb5c4e088dc76919e4de56f61 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 17:59:17 +0200 Subject: [PATCH 589/709] fix test coverage reporting (hopefully) --- buildSrc/src/main/groovy/org.lflang.test-conventions.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 021cb163a4..2a1ec27275 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -82,6 +82,8 @@ test { } jacocoTestReport { + getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec")) + reports { xml.required = true csv.required = false From 414a45ba74e4fb4d05e65412bd060386d346ad49 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 18:50:10 +0200 Subject: [PATCH 590/709] fix single test again --- build.gradle | 4 ++-- .../src/main/groovy/org.lflang.test-conventions.gradle | 7 +++---- test/README.md | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 88a262e1db..e4039064f0 100644 --- a/build.gradle +++ b/build.gradle @@ -67,8 +67,8 @@ tasks.register('targetTest') { finalizedBy('org.lflang:core:integrationTest') } tasks.register('singleTest') { - if (!project.hasProperty('singleTest')) { - throw new GradleException('Please set the \'singleTest\' project property using -PsingleTest=<...> to specify the LF test file that you would like to run.') + if (System.getProperty('singleTest') == null) { + throw new GradleException('Please set the \'singleTest\' system property using -DsingleTest=<...> to specify the LF test file that you would like to run.') } finalizedBy('org.lflang:core:integrationTest') } diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 2a1ec27275..40950e1832 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -52,15 +52,14 @@ test { // Pass properties on to the Java VM systemProperty 'scheduler', System.getProperty('scheduler') systemProperty 'runtime', System.getProperty('runtime') - if (rootProject.hasProperty('singleTest')) { - systemProperty 'singleTest', rootProject.getProperty('singleTest') - } + systemProperty 'singleTest', System.getProperty('singleTest') if (project.hasProperty('target')) { filter { includeTestsMatching "org.lflang.tests.runtime.${project.property('target')}Test.*" } - } else if (project.hasProperty('singleTest')) { + } + if (System.getProperty('singleTest') != null) { filter { includeTestsMatching "org.lflang.tests.RunSingleTest.runSingleTest" } diff --git a/test/README.md b/test/README.md index ecfdf8e876..e06450984d 100644 --- a/test/README.md +++ b/test/README.md @@ -30,7 +30,7 @@ To invoke only the C tests in the `concurrent` category, for example, do this: To run a single test case, use the `singleTest` gradle task along with the path to the test source file: ``` -./gradlew singleTest -PsingleTest test/C/src/Minimal.lf +./gradlew singleTest -DsingleTest test/C/src/Minimal.lf ``` ### LSP tests From 849e7b5a5a2ac04c65aa8568567bc514f212bf94 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 30 May 2023 11:52:58 -0700 Subject: [PATCH 591/709] Pass LOGGING debug option to federates. --- org.lflang/src/org/lflang/TargetConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index c4794b4b1a..3535ae01a6 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -97,6 +97,7 @@ public TargetConfig(Properties cliArgs, TargetDecl target, ErrorReporter errorRe } if (cliArgs.containsKey("logging")) { this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); + this.setByUser.add(TargetProperty.LOGGING); } if (cliArgs.containsKey("workers")) { this.workers = Integer.parseInt(cliArgs.getProperty("workers")); From bc564e25e8a8ea6b0d470a5de6df95e34e06ba5e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 30 May 2023 11:58:37 -0700 Subject: [PATCH 592/709] Add setByUser for other cliArgs. --- org.lflang/src/org/lflang/TargetConfig.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 3535ae01a6..67175777b6 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -94,6 +94,7 @@ public TargetConfig(Properties cliArgs, TargetDecl target, ErrorReporter errorRe if (cliArgs.containsKey("build-type")) { this.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); + this.setByUser.add(TargetProperty.BUILD_TYPE); } if (cliArgs.containsKey("logging")) { this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); @@ -101,15 +102,19 @@ public TargetConfig(Properties cliArgs, TargetDecl target, ErrorReporter errorRe } if (cliArgs.containsKey("workers")) { this.workers = Integer.parseInt(cliArgs.getProperty("workers")); + this.setByUser.add(TargetProperty.WORKERS); } if (cliArgs.containsKey("threading")) { this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); + this.setByUser.add(TargetProperty.THREADING); } if (cliArgs.containsKey("target-compiler")) { this.compiler = cliArgs.getProperty("target-compiler"); + this.setByUser.add(TargetProperty.COMPILER); } if (cliArgs.containsKey("tracing")) { this.tracing = new TracingOptions(); + this.setByUser.add(TargetProperty.TRACING); } if (cliArgs.containsKey("scheduler")) { this.schedulerType = SchedulerOption.valueOf(cliArgs.getProperty("scheduler")); @@ -120,19 +125,24 @@ public TargetConfig(Properties cliArgs, TargetDecl target, ErrorReporter errorRe if (!cliArgs.getProperty("target-flags").isEmpty()) { this.compilerFlags.addAll(List.of(cliArgs.getProperty("target-flags").split(" "))); } + this.setByUser.add(TargetProperty.FLAGS); } if (cliArgs.containsKey("runtime-version")) { this.runtimeVersion = cliArgs.getProperty("runtime-version"); + this.setByUser.add(TargetProperty.RUNTIME_VERSION); } if (cliArgs.containsKey("external-runtime-path")) { this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); + this.setByUser.add(TargetProperty.EXTERNAL_RUNTIME_PATH); } if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { this.keepalive = Boolean.parseBoolean(cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); + this.setByUser.add(TargetProperty.KEEPALIVE); } if (cliArgs.containsKey(BuildParm.PRINT_STATISTICS.getKey())) { this.printStatistics = true; + this.setByUser.add(TargetProperty.PRINT_STATISTICS); } } From 9ca44108e5377b8281b23e14d8bf1719077f8824 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Wed, 31 May 2023 10:45:17 +0900 Subject: [PATCH 593/709] Compare elapsed logical tag --- test/Python/src/federated/DistributedStop.lf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 174ff53858..3aacf893dc 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -18,15 +18,15 @@ reactor Sender { tag = lf.tag() print("Sending 42 at ({}, {}).".format( lf.time.logical_elapsed(), - lf.tag().microstep)) + tag.microstep)) out.set(42) - if lf.tag().microstep == 0: + if tag.microstep == 0: # Instead of having a separate reaction # for 'act' like Stop.lf, we trigger the # same reaction to test request_stop() being # called multiple times act.schedule(0) - if tag.time == USEC(1): + if lf.time.logical_elapsed() == USEC(1): # Call request_stop() both at (1 usec, 0) and # (1 usec, 1) print("Requesting stop at ({}, {}).".format( From 82c55ceb2f108fbad138cd4b6c6aae9625b5dbc5 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 31 May 2023 11:14:50 +0200 Subject: [PATCH 594/709] switch back to https protocol for fetching kieler --- org.lflang.tests/build.gradle | 3 +-- org.lflang/build.gradle | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/org.lflang.tests/build.gradle b/org.lflang.tests/build.gradle index e1311fc5b3..97f664c1a8 100644 --- a/org.lflang.tests/build.gradle +++ b/org.lflang.tests/build.gradle @@ -2,8 +2,7 @@ repositories { mavenCentral() // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. maven { - url "http://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - allowInsecureProtocol = true + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" } } dependencies { diff --git a/org.lflang/build.gradle b/org.lflang/build.gradle index 96b16f8771..8d4f6a41c9 100644 --- a/org.lflang/build.gradle +++ b/org.lflang/build.gradle @@ -4,8 +4,7 @@ repositories { mavenCentral() // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. maven { - url "http://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - allowInsecureProtocol = true + url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" } } dependencies { From 0225bfd5fc3d3959a7c22e174569605cb137b7b3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 30 May 2023 19:17:08 +0200 Subject: [PATCH 595/709] make the lsp a subproject --- org.lflang/lsp/build.gradle | 16 ++++++++++++++++ .../org/lflang/diagram/lsp/LFLanguageServer.java | 0 .../diagram/lsp/LFLanguageServerExtension.java | 0 .../diagram/lsp/LanguageDiagramServer.java | 0 .../java/org/lflang/diagram/lsp/Progress.java | 0 settings.gradle | 2 +- 6 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 org.lflang/lsp/build.gradle rename org.lflang/{core => lsp}/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java (100%) rename org.lflang/{core => lsp}/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java (100%) rename org.lflang/{core => lsp}/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java (100%) rename org.lflang/{core => lsp}/src/main/java/org/lflang/diagram/lsp/Progress.java (100%) diff --git a/org.lflang/lsp/build.gradle b/org.lflang/lsp/build.gradle new file mode 100644 index 0000000000..4ba85dbff1 --- /dev/null +++ b/org.lflang/lsp/build.gradle @@ -0,0 +1,16 @@ +plugins { + id 'org.lflang.java-application-conventions' +} + +dependencies { + implementation project(':org.lflang:core') + + implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:$klighdVersion") { + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' + } +} + +application { + mainClass = 'org.lflang.diagram.lsp.LanguageDiagramServer' +} diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java b/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java rename to org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java b/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java rename to org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java b/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java rename to org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/lsp/Progress.java b/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/Progress.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/lsp/Progress.java rename to org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/Progress.java diff --git a/settings.gradle b/settings.gradle index 28c7dbf725..5c1d32d3eb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ rootProject.name = 'org.lflang' -include(':org.lflang:core', ':org.lflang:cli:base', ':org.lflang:cli:lfc', ':org.lflang:cli:lff') +include(':org.lflang:core', ':org.lflang:lsp', ':org.lflang:cli:base', ':org.lflang:cli:lfc', ':org.lflang:cli:lff') From 7b28b8d9444398de56ebbe9ec346533f7862c0dd Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 31 May 2023 16:24:47 +0200 Subject: [PATCH 596/709] don't test cli scripts in build --- .github/workflows/build.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 669b27e674..bf8932fcc0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,24 +31,6 @@ jobs: run: ./gradlew build shell: bash if: ${{ inputs.nightly != true }} - - name: Test lfc bash scripts (Linux or macOS only) - run: | - .github/scripts/test-lfc.sh - if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - - name: Test lff bash scripts (Linux or macOS only) - run: | - .github/scripts/test-lff.sh - if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - - name: Test PowerShell lfc script (Windows only) - run: | - ./gradlew buildAll - bin/lfc.ps1 --help - if: ${{ runner.os == 'Windows' }} - - name: Test PowerShell lff script (Windows only) - run: | - ./gradlew buildAll - bin/lfc.ps1 --help - if: ${{ runner.os == 'Windows' }} - name: Deploy nightly release uses: marvinpinto/action-automatic-releases@latest with: From 22f0d8a5e079f282cce09d6772355a67971522c1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 31 May 2023 19:21:51 +0200 Subject: [PATCH 597/709] Remove mistakenly checked in binary file --- test/C/lib/libapp.a | Bin 74484 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/C/lib/libapp.a diff --git a/test/C/lib/libapp.a b/test/C/lib/libapp.a deleted file mode 100644 index d710e87c0ec4ba481729cee7abcf33a864b98114..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 74484 zcmeEv2Y6h?)%INNN?KJ*vTRE(AWQPfO=WGlfep4?u#H1=!5D)qOKVG5mV|bNZ6IKZ zNdknPkU|nVgc?eKFF@!uK!`~QB!pfWlw%u4_)Tw#VE0I^)X0%^h9I6rSwf5bsKnw08GwNf8{;(%Gktz+UTy=C*iCTW3dC zT&?TtYE^xScyF@37qY~(=?&8wrZ!B8HE(R`=z^#<+0otAOf?M}lqfcLv?Wwmd{grd z(<&NJ%`A63i451Z^mQhiTe~-IZ0TxiX6DV^J+zt7N*!Gt$&QxJjw9pE$=;6j>*Kx6 z-D?kvw?^E?bg37&da1x%?w?yEF!)X`(r z7*(x~TQDr7)Oradk?yF39$CnU<;4oZ`Wmnd)cTvhF_@C3hd|>@j!mw+VGAtw^|h~T@^A6Z4snA$@Z3HMSDx)%P5mqob_1cBhiQVx&MHB z7e5#pH(!lE@tSYgl8-<6niDM!)#QXvh%O3`Klg@dm#Le+b8L*5@d!PhY;qX&)Jp zY)Ue`EID8{1umX(2zdSLNS~Ls()~7gR$lq6%n|P;6(1nOIxRJ|y%!;Ijh{SBsG5JD{Dmw)+MX2+59J9ky@hRCH9U?Z_oLaOUM3S5~h^mI1 zUZ^7^<_v9_#?JK3oEiFokIxzT7H}aFtNh3auV`F`QiI4MBfZgI<;f8?$}2koEG%qS zPuDAglMj6s79soY{Dn9aXNP(IA}b3IL0k!AzI3Q0Zln zOACGpwIWG#dD$3NVQ^1(LPdV8dxLo&M(PTd%w`;X!LhjThSSjT0;xkd|)k5ym zt+NJwo98S${4*3GJIs@j9p?GT4nLwL+x6#bT7D7apg8Rhm;DJqw`N7;(Fo6nn0;)} zgH#am%Oa+ZNHaaIiz34`@~dJFGt-*eb%{;ycv7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mZQVYp@Xo+;n}LIQ%={0sW_VSyN+k zjyX47e^XNU--7Qk&%2s6?kl+IdaY~V?mGs1`!pZiVDmLWgZ-NaYh5dQ2Yd4b3Cg|D zzqYpvwJZN=sUbZZ`|Y+Wty=Bqsq|n~obhYfj;^FyvGvZM#oDsHb{-Y0wTtfP$?>xH z){)dT&^Iv9#W7U6lR6g+s7}LN=|Qr-pM5Sat=QR>R9&~zq1AcQ^1bY+w~p02eh*#j z*3gcr>Y78B`q@$RmFmpt@7uWg=H9-(4gH&jEY{#KLtbm3lXa{6RbTlDR{q+|5Q%Xe zqEwxuwJv%{8I_>C-YN~6BG-mn2X5Ka)jOy+xlg}N_p8Is|NZ@cq6~FSe(Un_-HWvj zaGdDA1O0V(VabUyh^D3yn)c_LB2RU@$4QHb?Q$$w-B~Y#?dAonf5X+o9bp)hG4zFRBX{YGv3Pqduvj@K01&GVD%bwtnTp}AtBJo**O$FV~fFdq?7-pQJx zyr(Mrw@u}(iNZCH@*b;{_k|i%BfPu`rSceeKGva_QEK Date: Thu, 11 May 2023 16:04:28 -0700 Subject: [PATCH 598/709] Update the federate trace visualizer README file. --- util/tracing/visualization/README.md | 38 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md index 82861e9b2a..9259ec6572 100644 --- a/util/tracing/visualization/README.md +++ b/util/tracing/visualization/README.md @@ -1,25 +1,33 @@ -# Trace sequence diagram visualiser +# Trace sequence diagram visualizer -This is a 1st iteration of a prototyping tool for constructing a sequence diagram -out of the traces. -It operates over the csv files generated by `trace_to_csv`. +`fedsd` is a utility tool that reports the interactions (exchanged messages) +between federates and the RTI in a sequence-diagram-like format. +To enable `fedsd`, `tracing` target property should be set to `true`. + +# Installing + +`fedsd` is installed by calling `make install` under `lingua_franca/util/tracing`. +This utility starts by transforming each `.lft` file into a `.csv` file, by +internally running `trace_to_csv`. It then aggregates the data from all `.csv` +files to do the matching and draw the sequence diagram. # Running -Once the `.lft` files collected and tranformed into `csv` files, run: +In case the federation is launched using the `bash` script under `bin`, an `.lft` trace +file will be generated for each of the federates, in addition to `rti.lft`. This latter +contains the RTI trace. +If, however, the federation is launched manually, then running the `RTI` should +enable tracing, by adding the option `-t`: ``` -$ python3 sd_gen.py -r -f ... +$ RTI -n -t ``` -The output is an html file with the svg in it. - -# Current problems - -- The collected traces are not complete. They need to be checked for correcteness as well. -- All arrows are horizontal and can be duplicated. Need further processing to derive the connections -for that. -- The scale needs exploration - +Once the federation stopped executiong, run `fedsd` on all generated `.lft` files: +``` +$ fedsd *.lft +``` +The output is an html file named `trace_svg.html` that contains the sequence of interactions +between the federates and the RTI. From 0570fcdb4fb3037ea821e31bdb7d0a1fd166e0a0 Mon Sep 17 00:00:00 2001 From: ChadliaJerad Date: Tue, 23 May 2023 16:53:07 -0700 Subject: [PATCH 599/709] Address two remaining reviews. --- util/tracing/visualization/README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md index 9259ec6572..f339d81da7 100644 --- a/util/tracing/visualization/README.md +++ b/util/tracing/visualization/README.md @@ -4,12 +4,13 @@ between federates and the RTI in a sequence-diagram-like format. To enable `fedsd`, `tracing` target property should be set to `true`. -# Installing - -`fedsd` is installed by calling `make install` under `lingua_franca/util/tracing`. This utility starts by transforming each `.lft` file into a `.csv` file, by internally running `trace_to_csv`. It then aggregates the data from all `.csv` files to do the matching and draw the sequence diagram. +# Installing + +`fedsd` is installed by calling `make install` under `lingua_franca/util/tracing`. + # Running @@ -22,12 +23,15 @@ enable tracing, by adding the option `-t`: $ RTI -n -t ``` -Once the federation stopped executiong, run `fedsd` on all generated `.lft` files: +For convenience, the RTI and all federates should be launched from the same directory. + + +Once the federation stopped executing, run `fedsd` on all generated `.lft` files: ``` $ fedsd *.lft ``` -The output is an html file named `trace_svg.html` that contains the sequence of interactions +The output is an html file named `trace_svg.html` (in the current directory) that contains the sequence of interactions between the federates and the RTI. From 853ecacbcc2dca5771bd614f6438a354d582d640 Mon Sep 17 00:00:00 2001 From: ChadliaJerad Date: Wed, 31 May 2023 12:21:32 -0700 Subject: [PATCH 600/709] Manually add the commit suggestion by Marten. Couldn't be done from github because outdated. --- util/tracing/visualization/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md index f339d81da7..3da43d639b 100644 --- a/util/tracing/visualization/README.md +++ b/util/tracing/visualization/README.md @@ -23,7 +23,7 @@ enable tracing, by adding the option `-t`: $ RTI -n -t ``` -For convenience, the RTI and all federates should be launched from the same directory. +It is most convenient to launch the RTI and all federates from the same working directory so that they will all write their trace file to that directory. Once the federation stopped executing, run `fedsd` on all generated `.lft` files: @@ -34,4 +34,3 @@ $ fedsd *.lft The output is an html file named `trace_svg.html` (in the current directory) that contains the sequence of interactions between the federates and the RTI. - From 84494677a1dd32cf43934aa9c6b7d5883979efd9 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 12:58:40 -0700 Subject: [PATCH 601/709] Update paths used to check which CI tests to run. --- .github/workflows/check-diff.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index af5f241cab..29a2bd81b4 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -36,10 +36,10 @@ jobs: - id: do run: | wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh - source check-diff.sh "org.lflang.generator.c/\|org.lflang/src/lib/c/\|org.lflang/src/lib/platform/\|test/C" C - source check-diff.sh "org.lflang/src/org/lflang/generator/cpp/\|org.lflang/src/lib/cpp/\|test/Cpp" CPP - source check-diff.sh "org.lflang/src/org/lflang/generator/python/\|org.lflang/src/lib/py/\|test/Python" PY - source check-diff.sh "org.lflang/src/org/lflang/generator/rust/\|org.lflang/src/lib/rs/\|test/Rust" RS - source check-diff.sh "org.lflang/src/org/lflang/generator/ts/\|org.lflang/src/lib/ts/\|test/TypeScript" TS + source check-diff.sh "org.lflang/core/src/main/java/org/lflang/generator/c\|/home/peter/lingua-franca/org.lflang/core/src/main/resources/lib/c\|org.lflang/core/src/main/resources/lib/platform\|test/C" C + source check-diff.sh "org.lflang/core/src/main/kotlin/org/lflang/generator/cpp\|org.lflang/core/src/main/resources/lib/cpp\|test/Cpp" CPP + source check-diff.sh "org.lflang/core/src/main/java/org/lflang/generator/python\|org.lflang/core/src/main/resources/lib/py\|test/Python" PY + source check-diff.sh "org.lflang/core/src/main/kotlin/org/lflang/generator/rust\|org.lflang/core/src/main/java/org/lflang/generator/rust\|org.lflang/core/src/main/resources/lib/rs\|test/Rust" RS + source check-diff.sh "org.lflang/core/src/main/kotlin/org/lflang/generator/ts\|org.lflang/core/src/main/java/org/lflang/generator/ts\|org.lflang/core/src/main/resources/lib/ts\|test/TypeScript" TS source check-diff.sh "util/tracing" TRACING shell: bash From f3943aff5054b9e12eacaf59e68ff785d9176287 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 25 May 2023 14:30:00 -0700 Subject: [PATCH 602/709] Add test case. --- test/C/src/generics/ParameterAsArgument.lf | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/C/src/generics/ParameterAsArgument.lf diff --git a/test/C/src/generics/ParameterAsArgument.lf b/test/C/src/generics/ParameterAsArgument.lf new file mode 100644 index 0000000000..7560587723 --- /dev/null +++ b/test/C/src/generics/ParameterAsArgument.lf @@ -0,0 +1,29 @@ +target C; + +// Hash issue +// Header name mismatch +reactor bundle { +} + +reactor Child { + state k: T1 + input in:In; + output out:Out; + reaction(in) {= + int a = in->value; + printf("Got %d\n", a); + =} +} + +reactor Super { + input in:In; + output out:Out; + state t1:T1; + c = new Child(); + in -> c.in; + c.out -> out; +} + +main reactor { + cc = new Super(); +} From 8a942213a372b8d2a5a6e4fd818fd3f24b91437d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 12:48:02 -0700 Subject: [PATCH 603/709] Modify mechanism for resolving type parameters. --- org.lflang/src/org/lflang/ast/ASTUtils.java | 16 -------- .../org/lflang/generator/ReactorInstance.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 40 ++----------------- .../generator/c/CReactionGenerator.java | 12 +++--- .../c/CReactorHeaderFileGenerator.java | 4 +- .../src/org/lflang/generator/c/CUtil.java | 16 +++++++- .../generator/c/TypeParameterizedReactor.java | 16 ++++++-- .../org/lflang/validation/LFValidator.java | 2 +- 8 files changed, 41 insertions(+), 67 deletions(-) diff --git a/org.lflang/src/org/lflang/ast/ASTUtils.java b/org.lflang/src/org/lflang/ast/ASTUtils.java index 91ff7ac69a..078505d958 100644 --- a/org.lflang/src/org/lflang/ast/ASTUtils.java +++ b/org.lflang/src/org/lflang/ast/ASTUtils.java @@ -63,8 +63,6 @@ import org.lflang.generator.CodeMap; import org.lflang.generator.InvalidSourceException; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.c.CUtil; -import org.lflang.generator.c.TypeParameterizedReactor; import org.lflang.lf.Action; import org.lflang.lf.Assignment; import org.lflang.lf.Code; @@ -409,20 +407,6 @@ public static List allInstantiations(Reactor definition) { return ASTUtils.collectElements(definition, featurePackage.getReactor_Instantiations()); } - /** - * Given a reactor Class, return a set of include names for interacting reactors which includes - * all instantiations of base class that it extends. - * - * @param r Reactor Class - */ - public static HashSet allIncludes(Reactor r) { - var set = new HashSet(); - for (var i : allInstantiations(r)) { - set.add(CUtil.getName(new TypeParameterizedReactor(i))); - } - return set; - } - /* * Given a reactor class, return a stream of reactor classes that it instantiates. * @param definition Reactor class definition. diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 3bb132ce01..9288744d65 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -795,7 +795,7 @@ public ReactorInstance( this.reporter = reporter; this.reactorDeclaration = definition.getReactorClass(); this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - this.tpr = new TypeParameterizedReactor(definition); + this.tpr = new TypeParameterizedReactor(definition, parent == null ? null : parent.tpr); // check for recursive instantiation var currentParent = parent; diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index f3accf165a..b515538de1 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -850,46 +850,12 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { private void generateReactorDefinitions() throws IOException { var generatedReactors = new LinkedHashSet(); if (this.main != null) { - resolveTemplatedTypes(this.main, this.main.tpr); generateReactorChildren(this.main, generatedReactors); generateReactorClass(this.main.getTypeParameterizedReactor()); } // do not generate code for reactors that are not instantiated } - /** - * Recursively Resolve all Templated Types of child Reactors to their respective concrete types - * - * @param reactorInstance The Reactor Class - * @param parentTpr {@link TypeParameterizedReactor} of Parent - */ - private void resolveTemplatedTypes( - ReactorInstance reactorInstance, TypeParameterizedReactor parentTpr) { - for (var child : reactorInstance.children) { - if (parentTpr.typeArgs() != null) { - Map copy = new HashMap<>(); - child - .tpr - .typeArgs() - .forEach( - (literal, typename) -> { - var type = typename.getId(); - if (parentTpr.typeArgs().containsKey(type)) { - var basicType = parentTpr.typeArgs().get(type); - copy.put(literal, basicType); - } else { - // Typename is not inherited from Parent Reactor. Keep As Is! - copy.put(literal, typename); - } - }); - if (!copy.isEmpty()) { // If we found some templated-types update the tpr with new map - child.tpr = new TypeParameterizedReactor(child.tpr.reactor(), copy); - } - resolveTemplatedTypes(child, child.tpr); - } - } - } - private record TypeParameterizedReactorWithDecl(TypeParameterizedReactor tpr, ReactorDecl decl) {} /** Generate user-visible header files for all reactors instantiated. */ @@ -910,7 +876,7 @@ private void generateHeaders() throws IOException { .map( it -> new TypeParameterizedReactorWithDecl( - new TypeParameterizedReactor(it), it.getReactorClass())) + new TypeParameterizedReactor(it, rr), it.getReactorClass())) .collect(Collectors.toSet()) .forEach( it -> { @@ -1069,7 +1035,7 @@ protected void generateReactorClassHeaders( src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); src.pr("#include \"" + headerName + "\""); tpr.doDefines(src); - ASTUtils.allIncludes(tpr.reactor()).stream() + CUtil.allIncludes(tpr).stream() .map(name -> "#include \"" + name + ".h\"") .forEach(header::pr); } @@ -1245,7 +1211,7 @@ private void generateInteractingContainedReactors( var contained = new InteractingContainedReactors(tpr.reactor()); // Next generate the relevant code. for (Instantiation containedReactor : contained.containedReactors()) { - var containedTpr = new TypeParameterizedReactor(containedReactor); + var containedTpr = new TypeParameterizedReactor(containedReactor, tpr); // First define an _width variable in case it is a bank. var array = ""; var width = -2; diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 6fcef92dd6..e83e083191 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -202,7 +202,8 @@ public static String generateInitializationForReaction( reactionInitialization, fieldsForStructsForContainedReactors, effect.getContainer(), - (Input) variable); + (Input) variable, + tpr); } else if (variable instanceof Watchdog) { reactionInitialization.pr(generateWatchdogVariablesInReaction(effect)); } else { @@ -363,14 +364,15 @@ private static void generateVariablesForSendingToContainedReactors( CodeBuilder builder, Map structs, Instantiation definition, - Input input) { + Input input, + TypeParameterizedReactor container) { CodeBuilder structBuilder = structs.get(definition); if (structBuilder == null) { structBuilder = new CodeBuilder(); structs.put(definition, structBuilder); } String inputStructType = - CGenerator.variableStructType(input, new TypeParameterizedReactor(definition), false); + CGenerator.variableStructType(input, new TypeParameterizedReactor(definition, container), false); String defName = definition.getName(); String defWidth = generateWidthVariable(defName); String inputName = input.getName(); @@ -461,7 +463,7 @@ private static void generatePortVariablesInReaction( Output output = (Output) port.getVariable(); String portStructType = CGenerator.variableStructType( - output, new TypeParameterizedReactor(port.getContainer()), false); + output, new TypeParameterizedReactor(port.getContainer(), tpr), false); CodeBuilder structBuilder = structs.get(port.getContainer()); if (structBuilder == null) { @@ -773,7 +775,7 @@ public static String generateOutputVariablesInReaction( (effect.getContainer() == null) ? CGenerator.variableStructType(output, tpr, false) : CGenerator.variableStructType( - output, new TypeParameterizedReactor(effect.getContainer()), false); + output, new TypeParameterizedReactor(effect.getContainer(), tpr), false); if (!ASTUtils.isMultiport(output)) { // Output port is not a multiport. return outputStructType + "* " + outputName + " = &self->_lf_" + outputName + ";"; diff --git a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 4f6a29b405..b57a19d8a7 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -150,7 +150,7 @@ public static String nonInlineInitialization(Reaction r, TypeParameterizedReacto reactor.reactor().getInstantiations().stream() .filter( instantiation -> - new TypeParameterizedReactor(instantiation) + new TypeParameterizedReactor(instantiation, reactor) .equals(it.r)) .findAny() .orElseThrow(), @@ -184,7 +184,7 @@ private static Stream portVariableStream( ? new PortVariable( tv, it.getContainer() != null - ? new TypeParameterizedReactor(it.getContainer()) + ? new TypeParameterizedReactor(it.getContainer(), reactorOfReaction) : reactorOfReaction, it.getContainer()) : null) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 3a7f151a2c..875efd61a3 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -28,6 +28,7 @@ import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -36,6 +37,7 @@ import org.lflang.FileConfig; import org.lflang.InferredType; import org.lflang.TargetConfig; +import org.lflang.ast.ASTUtils; import org.lflang.generator.ActionInstance; import org.lflang.generator.GeneratorCommandFactory; import org.lflang.generator.LFGeneratorContext; @@ -554,7 +556,19 @@ public static String triggerRefNested(PortInstance port, String runtimeIndex, St + "_trigger"; } - ////////////////////////////////////////////////////// + /** + * Given a reactor Class, return a set of include names for interacting reactors which includes + * all instantiations of base class that it extends. + */ + public static HashSet allIncludes(TypeParameterizedReactor tpr) { + var set = new HashSet(); + for (var i : ASTUtils.allInstantiations(tpr.reactor())) { + set.add(getName(new TypeParameterizedReactor(i, tpr))); + } + return set; + } + + ////////////////////////////////////////////////////// //// FIXME: Not clear what the strategy is with the following inner interface. // The {@code ReportCommandErrors} interface allows the // method runBuildCommand to call a protected diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index c5e062399b..1b798e90ee 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -18,17 +18,25 @@ */ public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { - public TypeParameterizedReactor(Instantiation i) { + /** + * Construct the TPR corresponding to the given instantiation which syntactically appears within + * the definition corresponding to {@code parent}. + * @param i An instantiation of the TPR to be constructed. + * @param parent The reactor in which {@code i} appears, or {@code null} if type variables are + * permitted instead of types in this TPR. + */ + public TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent) { this( ASTUtils.toDefinition(i.getReactorClass()), - addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()))); + addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()), parent)); } - private static Map addTypeArgs(Instantiation instantiation, Reactor r) { + private static Map addTypeArgs(Instantiation instantiation, Reactor r, TypeParameterizedReactor parent) { HashMap ret = new HashMap<>(); if (instantiation.getTypeArgs() != null) { for (int i = 0; i < r.getTypeParms().size(); i++) { - ret.put(r.getTypeParms().get(i).getLiteral(), instantiation.getTypeArgs().get(i)); + var arg = instantiation.getTypeArgs().get(i); + ret.put(r.getTypeParms().get(i).getLiteral(), parent == null ? arg : parent.resolveType(arg)); } } return ret; diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 555d6d0da3..7dd7a78f7a 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -221,7 +221,7 @@ private Type portTypeIfResolvable(VarRef port) { var portType = ((Port) port.getVariable()).getType(); return port.getContainer() == null ? portType - : new TypeParameterizedReactor(port.getContainer()).resolveType(portType); + : new TypeParameterizedReactor(port.getContainer(), null).resolveType(portType); } @Check(CheckType.FAST) From d5dd302d1c84066efac506c97e6e83104be53077 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 13:49:26 -0700 Subject: [PATCH 604/709] Update test. --- test/C/src/generics/ParameterAsArgument.lf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/C/src/generics/ParameterAsArgument.lf b/test/C/src/generics/ParameterAsArgument.lf index 7560587723..1f500150fb 100644 --- a/test/C/src/generics/ParameterAsArgument.lf +++ b/test/C/src/generics/ParameterAsArgument.lf @@ -25,5 +25,8 @@ reactor Super { } main reactor { + reaction(startup) -> cc.in {= + lf_set(cc.in, 42); + =} cc = new Super(); } From 7c6c6371326a46c78de05a3168b3b311a756a5e1 Mon Sep 17 00:00:00 2001 From: ChadliaJerad Date: Wed, 31 May 2023 14:08:48 -0700 Subject: [PATCH 605/709] Manually redo the lost commits because of the force push. --- util/tracing/visualization/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md index 3da43d639b..507e7ea449 100644 --- a/util/tracing/visualization/README.md +++ b/util/tracing/visualization/README.md @@ -2,23 +2,24 @@ `fedsd` is a utility tool that reports the interactions (exchanged messages) between federates and the RTI in a sequence-diagram-like format. -To enable `fedsd`, `tracing` target property should be set to `true`. + +To use `fedsd`, you need to first obtain an execution trace. To do this, enable the tracing mechanism in your Lingua Franca program by setting the `tracing` target property to `true` and then compile and run the program. This utility starts by transforming each `.lft` file into a `.csv` file, by internally running `trace_to_csv`. It then aggregates the data from all `.csv` files to do the matching and draw the sequence diagram. -# Installing -`fedsd` is installed by calling `make install` under `lingua_franca/util/tracing`. +# Installing +To build `fedsd`, change directory to `./util/tracing` relative to the root of the `lingua-franca` repository and run `make install`. # Running In case the federation is launched using the `bash` script under `bin`, an `.lft` trace -file will be generated for each of the federates, in addition to `rti.lft`. This latter +file will be generated for each of the federates, in addition to `rti.lft`. The latter contains the RTI trace. -If, however, the federation is launched manually, then running the `RTI` should -enable tracing, by adding the option `-t`: + +If, however, the federation is launched manually, then running the `RTI` command should be passed the `-t` flag in order to make sure that it, too, has tracing enabled: ``` $ RTI -n -t ``` From 77edc337d5d25ac379ed8904ea2b072ec9d90a5d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 31 May 2023 14:17:54 -0700 Subject: [PATCH 606/709] Update util/tracing/visualization/README.md --- util/tracing/visualization/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tracing/visualization/README.md b/util/tracing/visualization/README.md index 507e7ea449..8e7a729289 100644 --- a/util/tracing/visualization/README.md +++ b/util/tracing/visualization/README.md @@ -1,6 +1,6 @@ # Trace sequence diagram visualizer -`fedsd` is a utility tool that reports the interactions (exchanged messages) +`fedsd` is a utility that reports the interactions (exchanged messages) between federates and the RTI in a sequence-diagram-like format. To use `fedsd`, you need to first obtain an execution trace. To do this, enable the tracing mechanism in your Lingua Franca program by setting the `tracing` target property to `true` and then compile and run the program. From b92f4f338f34b0e626672c5a136f4df2f0d3d7c3 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 14:21:47 -0700 Subject: [PATCH 607/709] Use something less ugly than hashcodes. --- .../src/org/lflang/generator/c/CUtil.java | 2 +- .../generator/c/TypeParameterizedReactor.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 875efd61a3..5f1651e388 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -137,7 +137,7 @@ public static String channelIndexName(PortInstance port) { * (to allow for instantiations that have the same name as the main reactor or the .lf file). */ public static String getName(TypeParameterizedReactor reactor) { - String name = reactor.reactor().getName().toLowerCase() + reactor.hashCode(); + String name = reactor.uniqueName(); if (reactor.reactor().isMain()) { return name + "_main"; } diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 1b798e90ee..4376ed16aa 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -18,6 +18,9 @@ */ public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { + private static final Map uniqueNames = new HashMap<>(); + private static final Map nameCounts = new HashMap<>(); + /** * Construct the TPR corresponding to the given instantiation which syntactically appears within * the definition corresponding to {@code parent}. @@ -84,9 +87,22 @@ public InferredType resolveType(InferredType t) { return InferredType.fromAST(resolveType(t.astType)); } + public String uniqueName() { + if (uniqueNames.containsKey(this)) return uniqueNames.get(this); + if (nameCounts.containsKey(reactor.getName())) { + int currentCount = nameCounts.get(reactor.getName()); + nameCounts.put(reactor.getName(), currentCount + 1); + uniqueNames.put(this, reactor.getName() + currentCount); + return uniqueName(); + } + nameCounts.put(reactor.getName(), 1); + uniqueNames.put(this, reactor.getName()); + return uniqueName(); + } + @Override public int hashCode() { - return Math.abs(reactor.hashCode() * 31 + typeArgs.hashCode()); + return reactor.hashCode() * 31 + typeArgs.hashCode(); } @Override From 6e3fcd784676c3729b26660c7547f0d4a8147c02 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 14:53:14 -0700 Subject: [PATCH 608/709] Fix name collison. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 4376ed16aa..ee40f46e69 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -92,11 +92,11 @@ public String uniqueName() { if (nameCounts.containsKey(reactor.getName())) { int currentCount = nameCounts.get(reactor.getName()); nameCounts.put(reactor.getName(), currentCount + 1); - uniqueNames.put(this, reactor.getName() + currentCount); + uniqueNames.put(this, "_" + reactor.getName() + currentCount); return uniqueName(); } nameCounts.put(reactor.getName(), 1); - uniqueNames.put(this, reactor.getName()); + uniqueNames.put(this, "_" + reactor.getName()); return uniqueName(); } From 3eb376648af674b94b61d98db80bdf906b13a72d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 15:26:12 -0700 Subject: [PATCH 609/709] Avoid collisions with reserved symbols. A single underscore followed by a lowercase letter is unlikely to be used in user code and is not an implementation-reserved pattern. --- org.lflang/src/org/lflang/generator/c/CUtil.java | 4 ++-- .../generator/c/TypeParameterizedReactor.java | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index 5f1651e388..aacde82f6b 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -498,9 +498,9 @@ public static String runtimeIndex(ReactorInstance reactor) { */ public static String selfType(TypeParameterizedReactor reactor) { if (reactor.reactor().isMain()) { - return "_" + CUtil.getName(reactor) + "_main_self_t"; + return CUtil.getName(reactor) + "_main_self_t"; } - return "_" + CUtil.getName(reactor) + "_self_t"; + return CUtil.getName(reactor) + "_self_t"; } /** Construct a unique type for the "self" struct of the class of the given reactor. */ diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index ee40f46e69..0d0ac91e7f 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -88,15 +88,16 @@ public InferredType resolveType(InferredType t) { } public String uniqueName() { + String name = reactor.getName().toLowerCase(); if (uniqueNames.containsKey(this)) return uniqueNames.get(this); - if (nameCounts.containsKey(reactor.getName())) { - int currentCount = nameCounts.get(reactor.getName()); - nameCounts.put(reactor.getName(), currentCount + 1); - uniqueNames.put(this, "_" + reactor.getName() + currentCount); + if (nameCounts.containsKey(name)) { + int currentCount = nameCounts.get(name); + nameCounts.put(name, currentCount + 1); + uniqueNames.put(this, "_" + name + currentCount); return uniqueName(); } - nameCounts.put(reactor.getName(), 1); - uniqueNames.put(this, "_" + reactor.getName()); + nameCounts.put(name, 1); + uniqueNames.put(this, "_" + name); return uniqueName(); } From 1c38e8d1c8dbe4a0ce8ff8130c2e97eef41f382c Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 15:59:51 -0700 Subject: [PATCH 610/709] Apply formatter. --- .../org/lflang/generator/c/CGenerator.java | 7 +----- .../generator/c/CReactionGenerator.java | 3 ++- .../src/org/lflang/generator/c/CUtil.java | 22 +++++++++---------- .../generator/c/TypeParameterizedReactor.java | 9 +++++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index b515538de1..85b755e4a1 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -40,10 +40,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -89,7 +87,6 @@ import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; -import org.lflang.lf.Type; import org.lflang.lf.Variable; import org.lflang.util.ArduinoUtil; import org.lflang.util.FileUtil; @@ -1035,9 +1032,7 @@ protected void generateReactorClassHeaders( src.pr("#include \"include/" + CReactorHeaderFileGenerator.outputPath(tpr) + "\""); src.pr("#include \"" + headerName + "\""); tpr.doDefines(src); - CUtil.allIncludes(tpr).stream() - .map(name -> "#include \"" + name + ".h\"") - .forEach(header::pr); + CUtil.allIncludes(tpr).stream().map(name -> "#include \"" + name + ".h\"").forEach(header::pr); } private void generateReactorClassBody( diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index e83e083191..824dc97ee6 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -372,7 +372,8 @@ private static void generateVariablesForSendingToContainedReactors( structs.put(definition, structBuilder); } String inputStructType = - CGenerator.variableStructType(input, new TypeParameterizedReactor(definition, container), false); + CGenerator.variableStructType( + input, new TypeParameterizedReactor(definition, container), false); String defName = definition.getName(); String defWidth = generateWidthVariable(defName); String inputName = input.getName(); diff --git a/org.lflang/src/org/lflang/generator/c/CUtil.java b/org.lflang/src/org/lflang/generator/c/CUtil.java index aacde82f6b..46f998cac0 100644 --- a/org.lflang/src/org/lflang/generator/c/CUtil.java +++ b/org.lflang/src/org/lflang/generator/c/CUtil.java @@ -556,19 +556,19 @@ public static String triggerRefNested(PortInstance port, String runtimeIndex, St + "_trigger"; } - /** - * Given a reactor Class, return a set of include names for interacting reactors which includes - * all instantiations of base class that it extends. - */ - public static HashSet allIncludes(TypeParameterizedReactor tpr) { - var set = new HashSet(); - for (var i : ASTUtils.allInstantiations(tpr.reactor())) { - set.add(getName(new TypeParameterizedReactor(i, tpr))); - } - return set; + /** + * Given a reactor Class, return a set of include names for interacting reactors which includes + * all instantiations of base class that it extends. + */ + public static HashSet allIncludes(TypeParameterizedReactor tpr) { + var set = new HashSet(); + for (var i : ASTUtils.allInstantiations(tpr.reactor())) { + set.add(getName(new TypeParameterizedReactor(i, tpr))); } + return set; + } - ////////////////////////////////////////////////////// + ////////////////////////////////////////////////////// //// FIXME: Not clear what the strategy is with the following inner interface. // The {@code ReportCommandErrors} interface allows the // method runBuildCommand to call a protected diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 0d0ac91e7f..081d57336d 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -24,9 +24,10 @@ public record TypeParameterizedReactor(Reactor reactor, Map typeAr /** * Construct the TPR corresponding to the given instantiation which syntactically appears within * the definition corresponding to {@code parent}. + * * @param i An instantiation of the TPR to be constructed. * @param parent The reactor in which {@code i} appears, or {@code null} if type variables are - * permitted instead of types in this TPR. + * permitted instead of types in this TPR. */ public TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent) { this( @@ -34,12 +35,14 @@ public TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()), parent)); } - private static Map addTypeArgs(Instantiation instantiation, Reactor r, TypeParameterizedReactor parent) { + private static Map addTypeArgs( + Instantiation instantiation, Reactor r, TypeParameterizedReactor parent) { HashMap ret = new HashMap<>(); if (instantiation.getTypeArgs() != null) { for (int i = 0; i < r.getTypeParms().size(); i++) { var arg = instantiation.getTypeArgs().get(i); - ret.put(r.getTypeParms().get(i).getLiteral(), parent == null ? arg : parent.resolveType(arg)); + ret.put( + r.getTypeParms().get(i).getLiteral(), parent == null ? arg : parent.resolveType(arg)); } } return ret; From 1d0de2aff58c80dbef27c683dbdd65117c4938b5 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Thu, 1 Jun 2023 09:21:28 +0900 Subject: [PATCH 611/709] Check whether 5 violations are detected or not --- ...tributedCountDecentralizedLateHierarchy.lf | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf index d806ab5453..9727ed74fe 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -14,7 +14,48 @@ target Python { } import Count from "../lib/Count.lf" -import ImportantActuator, Print from "DistributedCountDecentralizedLateDownstream.lf" +import Print from "DistributedCountDecentralizedLateDownstream.lf" + +reactor ImportantActuator { + input inp + # Count messages that arrive without STP violation. + state success = 0 + state success_stp_violation = 0 + # Force a timer to be invoked periodically + timer t(0, 10 usec) + # to ensure logical time will advance in the absence of incoming messages. + state c = 0 + + reaction(inp) {= + current_tag = lf.tag() + print(f"ImportantActuator: At tag ({lf.tag().time}, {lf.tag().microstep}) received {inp.value}. " + f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") + if lf.tag() == Tag((SEC(1) * self.c) + + lf.time.start(), 0): + self.success += 1 # Message was on-time + else: + self.sys.stderr.write("Normal reaction was invoked, but current tag doesn't match expected tag.") + self.sys.exit(1) + self.c += 1 + =} STP(0) {= + current_tag = lf.tag() + print(f"ImportantActuator: At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), message has violated the STP offset " + f"by ({lf.tag().time - inp.intended_tag.time}, {lf.tag().microstep - inp.intended_tag.microstep}).") + self.success_stp_violation += 1 + self.c += 1 + =} + + reaction(t) {= + # Do nothing. + =} + + reaction(shutdown) {= + if (self.success + self.success_stp_violation) != 5: + self.sys.stderr.write("Failed to detect STP violation in messages.") + self.sys.exit(1) + else: + print(f"Successfully detected STP violations ({self.success_stp_violation} violations, {self.success} on-time).") + =} +} reactor Receiver { input inp From 5fec4caabe4feca14de9cff010efbdf1ce87c183 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 17:37:27 -0700 Subject: [PATCH 612/709] Delete test output to avoid running out of memory. Only the oldest test output is deleted. --- org.lflang.tests/src/org/lflang/tests/LFTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index 58b3cbf846..61b5dc2edf 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -226,7 +226,7 @@ public static final class ExecutionLogger { /** * String buffer used to record the standard output and error streams from the input process. */ - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); /** * Return a thread responsible for recording the standard output stream of the given process. A @@ -250,7 +250,7 @@ public Thread recordStdErr(Process process) { * @param builder The builder to append to. * @param inputStream The stream to read from. */ - private Thread recordStream(StringBuffer builder, InputStream inputStream) { + private Thread recordStream(StringBuilder builder, InputStream inputStream) { return new Thread( () -> { try (Reader reader = new InputStreamReader(inputStream)) { @@ -258,6 +258,9 @@ private Thread recordStream(StringBuffer builder, InputStream inputStream) { char[] buf = new char[1024]; while ((len = reader.read(buf)) > 0) { builder.append(buf, 0, len); + if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() / 2 ) { + builder.delete(0, builder.length() / 2); + } } } catch (IOException e) { throw new RuntimeIOException(e); From adc2ea703b0da9322f57098456d459886f3da844 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 17:40:56 -0700 Subject: [PATCH 613/709] Avoid unnecessarily frequent timer triggering. This makes the test too computationally intensive and more importantly results in too much debugging output. --- .../Python/src/federated/DistributedCountDecentralizedLate.lf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Python/src/federated/DistributedCountDecentralizedLate.lf b/test/Python/src/federated/DistributedCountDecentralizedLate.lf index e3a6899e78..33e1c528d2 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLate.lf @@ -20,8 +20,8 @@ reactor Print { # STP(in, 30 msec); state success = 0 state success_stp_violation = 0 - # Force a timer to be invoke periodically - timer t(0, 10 usec) + # Force a timer to be invoked periodically + timer t(0, 1 msec) # to ensure logical time will advance in the absence of incoming messages. state c = 0 From c0a6194f41944a44c21961f1cef074c24b430f25 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 17:43:44 -0700 Subject: [PATCH 614/709] Apply formatter. --- test/C/src/generics/ParameterAsArgument.lf | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/test/C/src/generics/ParameterAsArgument.lf b/test/C/src/generics/ParameterAsArgument.lf index 1f500150fb..5be6c0b926 100644 --- a/test/C/src/generics/ParameterAsArgument.lf +++ b/test/C/src/generics/ParameterAsArgument.lf @@ -1,14 +1,13 @@ -target C; +target C -// Hash issue -// Header name mismatch -reactor bundle { +reactor bundle { // Hash issue Header name mismatch } reactor Child { state k: T1 - input in:In; - output out:Out; + input in: In + output out: Out + reaction(in) {= int a = in->value; printf("Got %d\n", a); @@ -16,17 +15,16 @@ reactor Child { } reactor Super { - input in:In; - output out:Out; - state t1:T1; - c = new Child(); - in -> c.in; - c.out -> out; + input in: In + output out: Out + state t1: T1 + c = new Child() + in -> c.in + c.out -> out } main reactor { - reaction(startup) -> cc.in {= - lf_set(cc.in, 42); - =} - cc = new Super(); + cc = new Super() + + reaction(startup) -> cc.in {= lf_set(cc.in, 42); =} } From 3f4679e363bd8f8b3ad8c95ff8ed26b21bec72a2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 31 May 2023 20:21:43 -0700 Subject: [PATCH 615/709] Fix formatting issue. --- test/C/src/generics/ParameterAsArgument.lf | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/C/src/generics/ParameterAsArgument.lf b/test/C/src/generics/ParameterAsArgument.lf index 5be6c0b926..65f91e0488 100644 --- a/test/C/src/generics/ParameterAsArgument.lf +++ b/test/C/src/generics/ParameterAsArgument.lf @@ -1,8 +1,5 @@ target C -reactor bundle { // Hash issue Header name mismatch -} - reactor Child { state k: T1 input in: In From ad65533631abf6e5464a40aeb689e1165361d4eb Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 09:55:58 +0200 Subject: [PATCH 616/709] move zephyr files like it was done on master --- .../core/src/main/resources/lib/platform/{ => zephyr}/Kconfig | 0 .../main/resources/lib/platform/{ => zephyr}/boards/esp32.overlay | 0 .../lib/platform/{ => zephyr}/boards/nrf52dk_nrf52832_lf.conf | 0 .../core/src/main/resources/lib/platform/{ => zephyr}/prj_lf.conf | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename org.lflang/core/src/main/resources/lib/platform/{ => zephyr}/Kconfig (100%) rename org.lflang/core/src/main/resources/lib/platform/{ => zephyr}/boards/esp32.overlay (100%) rename org.lflang/core/src/main/resources/lib/platform/{ => zephyr}/boards/nrf52dk_nrf52832_lf.conf (100%) rename org.lflang/core/src/main/resources/lib/platform/{ => zephyr}/prj_lf.conf (100%) diff --git a/org.lflang/core/src/main/resources/lib/platform/Kconfig b/org.lflang/core/src/main/resources/lib/platform/zephyr/Kconfig similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/Kconfig rename to org.lflang/core/src/main/resources/lib/platform/zephyr/Kconfig diff --git a/org.lflang/core/src/main/resources/lib/platform/boards/esp32.overlay b/org.lflang/core/src/main/resources/lib/platform/zephyr/boards/esp32.overlay similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/boards/esp32.overlay rename to org.lflang/core/src/main/resources/lib/platform/zephyr/boards/esp32.overlay diff --git a/org.lflang/core/src/main/resources/lib/platform/boards/nrf52dk_nrf52832_lf.conf b/org.lflang/core/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/boards/nrf52dk_nrf52832_lf.conf rename to org.lflang/core/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf diff --git a/org.lflang/core/src/main/resources/lib/platform/prj_lf.conf b/org.lflang/core/src/main/resources/lib/platform/zephyr/prj_lf.conf similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/prj_lf.conf rename to org.lflang/core/src/main/resources/lib/platform/zephyr/prj_lf.conf From ae49145831d31f1be98ecf821569c2faecb4c366 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 10:12:06 +0200 Subject: [PATCH 617/709] eliminate the org.lflang top level directory --- .gitmodules | 8 ++++---- {org.lflang/cli => cli}/base/build.gradle | 0 .../base/src/main/java/org/lflang/cli/CliBase.java | 0 .../src/main/java/org/lflang/cli/LFStandaloneModule.java | 0 .../main/java/org/lflang/cli/StandaloneErrorReporter.java | 0 .../main/java/org/lflang/cli/StandaloneIssueAcceptor.java | 0 .../src/main/java/org/lflang/cli/VersionProvider.java | 0 .../base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt | 0 .../java/org/lflang/cli/CliToolTestFixture.java | 0 .../src/testFixtures/java/org/lflang/cli/TestUtils.java | 0 {org.lflang/cli => cli}/lfc/build.gradle | 0 .../cli => cli}/lfc/src/main/java/org/lflang/cli/Lfc.java | 0 .../lfc/src/test/java/org/lflang/cli/LfcCliTest.java | 0 .../test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt | 0 .../lfc/src/test/resources/org/lflang/cli/colors.lf | 0 .../lfc/src/test/resources/org/lflang/cli/colors.stderr | 0 .../lfc/src/test/resources/org/lflang/cli/emptyFile.lf | 0 .../src/test/resources/org/lflang/cli/emptyFile.stderr | 0 .../lfc/src/test/resources/org/lflang/cli/issue490.lf | 0 .../lfc/src/test/resources/org/lflang/cli/issue490.stderr | 0 .../src/test/resources/org/lflang/cli/multilineWarning.lf | 0 .../test/resources/org/lflang/cli/multilineWarning.stderr | 0 .../resources/org/lflang/cli/multilineWarningTooBig.lf | 0 .../org/lflang/cli/multilineWarningTooBig.stderr | 0 .../src/test/resources/org/lflang/cli/simpleWarning.lf | 0 .../test/resources/org/lflang/cli/simpleWarning.stderr | 0 .../lfc/src/test/resources/org/lflang/cli/tabs.lf | 0 .../lfc/src/test/resources/org/lflang/cli/tabs.stderr | 0 .../src/test/resources/org/lflang/cli/twoLineWarning.lf | 0 .../test/resources/org/lflang/cli/twoLineWarning.stderr | 0 {org.lflang/cli => cli}/lff/build.gradle | 0 .../cli => cli}/lff/src/main/java/org/lflang/cli/Lff.java | 0 .../lff/src/test/java/org/lflang/cli/LffCliTest.java | 0 {org.lflang/core => core}/build.gradle | 0 .../java/org/lflang/tests/RunSingleTest.java | 0 .../java/org/lflang/tests/RuntimeTest.java | 0 .../java/org/lflang/tests/lsp/ErrorInserter.java | 0 .../java/org/lflang/tests/lsp/LspTests.java | 0 .../java/org/lflang/tests/lsp/MockLanguageClient.java | 0 .../java/org/lflang/tests/lsp/MockReportProgress.java | 0 .../java/org/lflang/tests/runtime/CArduinoTest.java | 0 .../java/org/lflang/tests/runtime/CCppTest.java | 0 .../java/org/lflang/tests/runtime/CSchedulerTest.java | 0 .../java/org/lflang/tests/runtime/CTest.java | 0 .../java/org/lflang/tests/runtime/CZephyrTest.java | 0 .../java/org/lflang/tests/runtime/CppRos2Test.java | 0 .../java/org/lflang/tests/runtime/CppTest.java | 0 .../java/org/lflang/tests/runtime/PythonTest.java | 0 .../java/org/lflang/tests/runtime/RustTest.java | 0 .../java/org/lflang/tests/runtime/TypeScriptTest.java | 0 .../org/lflang/tests/serialization/SerializationTest.java | 0 .../src/main/java/org/lflang/AttributeUtils.java | 0 .../src/main/java/org/lflang/DefaultErrorReporter.java | 0 .../src/main/java/org/lflang/ErrorReporter.java | 0 .../src/main/java/org/lflang/FileConfig.java | 0 .../src/main/java/org/lflang/GenerateLinguaFranca.mwe2 | 0 .../src/main/java/org/lflang/InferredType.java | 0 .../java/org/lflang/LFResourceDescriptionStrategy.java | 0 .../src/main/java/org/lflang/LFResourceProvider.java | 0 .../src/main/java/org/lflang/LFRuntimeModule.java | 0 .../src/main/java/org/lflang/LFStandaloneSetup.java | 0 .../java/org/lflang/LFSyntaxErrorMessageProvider.java | 0 .../src/main/java/org/lflang/LinguaFranca.xtext | 0 .../src/main/java/org/lflang/LocalStrings.java | 0 .../src/main/java/org/lflang/MainConflictChecker.java | 0 .../core => core}/src/main/java/org/lflang/ModelInfo.java | 0 .../core => core}/src/main/java/org/lflang/Target.java | 0 .../src/main/java/org/lflang/TargetConfig.java | 0 .../src/main/java/org/lflang/TargetProperty.java | 0 .../core => core}/src/main/java/org/lflang/TimeUnit.java | 0 .../core => core}/src/main/java/org/lflang/TimeValue.java | 0 .../src/main/java/org/lflang/ast/ASTUtils.java | 0 .../src/main/java/org/lflang/ast/AstTransformation.java | 0 .../org/lflang/ast/DelayedConnectionTransformation.java | 0 .../src/main/java/org/lflang/ast/FormattingUtils.java | 0 .../src/main/java/org/lflang/ast/IsEqual.java | 0 .../src/main/java/org/lflang/ast/MalleableString.java | 0 .../core => core}/src/main/java/org/lflang/ast/ToLf.java | 0 .../src/main/java/org/lflang/ast/ToText.java | 0 .../diagram/synthesis/AbstractSynthesisExtensions.java | 0 .../lflang/diagram/synthesis/LinguaFrancaSynthesis.java | 0 .../diagram/synthesis/ReactorParameterDisplayModes.java | 0 .../lflang/diagram/synthesis/SynthesisRegistration.java | 0 .../lflang/diagram/synthesis/action/AbstractAction.java | 0 .../synthesis/action/CollapseAllReactorsAction.java | 0 .../diagram/synthesis/action/ExpandAllReactorsAction.java | 0 .../diagram/synthesis/action/FilterCycleAction.java | 0 .../synthesis/action/MemorizingExpandCollapseAction.java | 0 .../lflang/diagram/synthesis/action/ShowCycleAction.java | 0 .../synthesis/postprocessor/ReactionPortAdjustment.java | 0 .../synthesis/styles/LinguaFrancaShapeExtensions.java | 0 .../synthesis/styles/LinguaFrancaStyleExtensions.java | 0 .../diagram/synthesis/styles/ReactorFigureComponents.java | 0 .../lflang/diagram/synthesis/util/CycleVisualization.java | 0 .../util/InterfaceDependenciesVisualization.java | 0 .../diagram/synthesis/util/LayoutPostProcessing.java | 0 .../org/lflang/diagram/synthesis/util/ModeDiagrams.java | 0 .../lflang/diagram/synthesis/util/NamedInstanceUtil.java | 0 .../org/lflang/diagram/synthesis/util/ReactorIcons.java | 0 .../diagram/synthesis/util/SynthesisErrorReporter.java | 0 .../lflang/diagram/synthesis/util/UtilityExtensions.java | 0 .../java/org/lflang/federated/extensions/CExtension.java | 0 .../org/lflang/federated/extensions/CExtensionUtils.java | 0 .../lflang/federated/extensions/FedTargetExtension.java | 0 .../federated/extensions/FedTargetExtensionFactory.java | 0 .../org/lflang/federated/extensions/PythonExtension.java | 0 .../java/org/lflang/federated/extensions/TSExtension.java | 0 .../java/org/lflang/federated/generator/FedASTUtils.java | 0 .../lflang/federated/generator/FedConnectionInstance.java | 0 .../java/org/lflang/federated/generator/FedEmitter.java | 0 .../org/lflang/federated/generator/FedFileConfig.java | 0 .../java/org/lflang/federated/generator/FedGenerator.java | 0 .../org/lflang/federated/generator/FedImportEmitter.java | 0 .../org/lflang/federated/generator/FedMainEmitter.java | 0 .../lflang/federated/generator/FedPreambleEmitter.java | 0 .../org/lflang/federated/generator/FedReactorEmitter.java | 0 .../org/lflang/federated/generator/FedTargetConfig.java | 0 .../org/lflang/federated/generator/FedTargetEmitter.java | 0 .../java/org/lflang/federated/generator/FedUtils.java | 0 .../org/lflang/federated/generator/FederateInstance.java | 0 .../federated/generator/LineAdjustingErrorReporter.java | 0 .../federated/generator/SynchronizedErrorReporter.java | 0 .../java/org/lflang/federated/launcher/BuildConfig.java | 0 .../java/org/lflang/federated/launcher/CBuildConfig.java | 0 .../lflang/federated/launcher/FedLauncherGenerator.java | 0 .../java/org/lflang/federated/launcher/PyBuildConfig.java | 0 .../java/org/lflang/federated/launcher/RtiConfig.java | 0 .../java/org/lflang/federated/launcher/TsBuildConfig.java | 0 .../serialization/FedNativePythonSerialization.java | 0 .../federated/serialization/FedROS2CPPSerialization.java | 0 .../lflang/federated/serialization/FedSerialization.java | 0 .../federated/serialization/SupportedSerializers.java | 0 .../org/lflang/federated/validation/FedValidator.java | 0 .../src/main/java/org/lflang/formatting2/LFFormatter.java | 0 .../main/java/org/lflang/generator/ActionInstance.java | 0 .../src/main/java/org/lflang/generator/CodeBuilder.java | 0 .../src/main/java/org/lflang/generator/CodeMap.java | 0 .../main/java/org/lflang/generator/DeadlineInstance.java | 0 .../java/org/lflang/generator/DelayBodyGenerator.java | 0 .../java/org/lflang/generator/DiagnosticReporting.java | 0 .../java/org/lflang/generator/DockerComposeGenerator.java | 0 .../src/main/java/org/lflang/generator/DockerData.java | 0 .../main/java/org/lflang/generator/DockerGenerator.java | 0 .../org/lflang/generator/FedDockerComposeGenerator.java | 0 .../java/org/lflang/generator/GenerationException.java | 0 .../src/main/java/org/lflang/generator/GeneratorBase.java | 0 .../org/lflang/generator/GeneratorCommandFactory.java | 0 .../main/java/org/lflang/generator/GeneratorResult.java | 0 .../main/java/org/lflang/generator/GeneratorUtils.java | 0 .../lflang/generator/HumanReadableReportingStrategy.java | 0 .../main/java/org/lflang/generator/IntegratedBuilder.java | 0 .../org/lflang/generator/InvalidLfSourceException.java | 0 .../java/org/lflang/generator/InvalidSourceException.java | 0 .../src/main/java/org/lflang/generator/LFGenerator.java | 0 .../java/org/lflang/generator/LFGeneratorContext.java | 0 .../src/main/java/org/lflang/generator/LFResource.java | 0 .../org/lflang/generator/LanguageServerErrorReporter.java | 0 .../java/org/lflang/generator/LfExpressionVisitor.java | 0 .../src/main/java/org/lflang/generator/MainContext.java | 0 .../src/main/java/org/lflang/generator/MixedRadixInt.java | 0 .../src/main/java/org/lflang/generator/ModeInstance.java | 0 .../src/main/java/org/lflang/generator/NamedInstance.java | 0 .../main/java/org/lflang/generator/ParameterInstance.java | 0 .../src/main/java/org/lflang/generator/PortInstance.java | 0 .../src/main/java/org/lflang/generator/Position.java | 0 .../src/main/java/org/lflang/generator/Range.java | 0 .../main/java/org/lflang/generator/ReactionInstance.java | 0 .../java/org/lflang/generator/ReactionInstanceGraph.java | 0 .../main/java/org/lflang/generator/ReactorInstance.java | 0 .../src/main/java/org/lflang/generator/RuntimeRange.java | 0 .../src/main/java/org/lflang/generator/SendRange.java | 0 .../src/main/java/org/lflang/generator/SubContext.java | 0 .../src/main/java/org/lflang/generator/TargetTypes.java | 0 .../src/main/java/org/lflang/generator/TimerInstance.java | 0 .../main/java/org/lflang/generator/TriggerInstance.java | 0 .../generator/UnsupportedGeneratorFeatureException.java | 0 .../java/org/lflang/generator/ValidationStrategy.java | 0 .../src/main/java/org/lflang/generator/Validator.java | 0 .../main/java/org/lflang/generator/WatchdogInstance.java | 0 .../java/org/lflang/generator/c/CActionGenerator.java | 0 .../main/java/org/lflang/generator/c/CCmakeGenerator.java | 0 .../src/main/java/org/lflang/generator/c/CCompiler.java | 0 .../org/lflang/generator/c/CConstructorGenerator.java | 0 .../main/java/org/lflang/generator/c/CCoreFilesUtils.java | 0 .../java/org/lflang/generator/c/CDelayBodyGenerator.java | 0 .../java/org/lflang/generator/c/CDockerGenerator.java | 0 .../src/main/java/org/lflang/generator/c/CFileConfig.java | 0 .../src/main/java/org/lflang/generator/c/CGenerator.java | 0 .../org/lflang/generator/c/CMainFunctionGenerator.java | 0 .../java/org/lflang/generator/c/CMethodGenerator.java | 0 .../java/org/lflang/generator/c/CMixedRadixGenerator.java | 0 .../main/java/org/lflang/generator/c/CModesGenerator.java | 0 .../java/org/lflang/generator/c/CParameterGenerator.java | 0 .../main/java/org/lflang/generator/c/CPortGenerator.java | 0 .../java/org/lflang/generator/c/CPreambleGenerator.java | 0 .../java/org/lflang/generator/c/CReactionGenerator.java | 0 .../lflang/generator/c/CReactorHeaderFileGenerator.java | 0 .../main/java/org/lflang/generator/c/CStateGenerator.java | 0 .../main/java/org/lflang/generator/c/CTimerGenerator.java | 0 .../java/org/lflang/generator/c/CTracingGenerator.java | 0 .../org/lflang/generator/c/CTriggerObjectsGenerator.java | 0 .../src/main/java/org/lflang/generator/c/CTypes.java | 0 .../src/main/java/org/lflang/generator/c/CUtil.java | 0 .../java/org/lflang/generator/c/CWatchdogGenerator.java | 0 .../lflang/generator/c/InteractingContainedReactors.java | 0 .../org/lflang/generator/c/TypeParameterizedReactor.java | 0 .../java/org/lflang/generator/python/PyFileConfig.java | 0 .../src/main/java/org/lflang/generator/python/PyUtil.java | 0 .../lflang/generator/python/PythonActionGenerator.java | 0 .../lflang/generator/python/PythonDelayBodyGenerator.java | 0 .../lflang/generator/python/PythonDockerGenerator.java | 0 .../java/org/lflang/generator/python/PythonGenerator.java | 0 .../org/lflang/generator/python/PythonInfoGenerator.java | 0 .../generator/python/PythonMainFunctionGenerator.java | 0 .../lflang/generator/python/PythonMethodGenerator.java | 0 .../org/lflang/generator/python/PythonModeGenerator.java | 0 .../lflang/generator/python/PythonParameterGenerator.java | 0 .../org/lflang/generator/python/PythonPortGenerator.java | 0 .../lflang/generator/python/PythonPreambleGenerator.java | 0 .../lflang/generator/python/PythonReactionGenerator.java | 0 .../lflang/generator/python/PythonReactorGenerator.java | 0 .../org/lflang/generator/python/PythonStateGenerator.java | 0 .../java/org/lflang/generator/python/PythonTypes.java | 0 .../java/org/lflang/generator/python/PythonValidator.java | 0 .../org/lflang/generator/rust/CargoDependencySpec.java | 0 .../java/org/lflang/generator/rust/RustTargetConfig.java | 0 .../java/org/lflang/generator/ts/TSDockerGenerator.java | 0 .../src/main/java/org/lflang/generator/ts/TSTypes.java | 0 .../src/main/java/org/lflang/graph/DirectedGraph.java | 0 .../src/main/java/org/lflang/graph/Graph.java | 0 .../main/java/org/lflang/graph/InstantiationGraph.java | 0 .../src/main/java/org/lflang/graph/NodeAnnotation.java | 0 .../src/main/java/org/lflang/graph/NodeAnnotations.java | 0 .../src/main/java/org/lflang/graph/PrecedenceGraph.java | 0 .../src/main/java/org/lflang/graph/TopologyGraph.java | 0 .../src/main/java/org/lflang/ide/LFIdeModule.java | 0 .../src/main/java/org/lflang/ide/LFIdeSetup.java | 0 .../java/org/lflang/scoping/LFGlobalScopeProvider.java | 0 .../src/main/java/org/lflang/scoping/LFScopeProvider.java | 0 .../main/java/org/lflang/scoping/LFScopeProviderImpl.java | 0 .../src/main/java/org/lflang/util/ArduinoUtil.java | 0 .../src/main/java/org/lflang/util/Averager.java | 0 .../src/main/java/org/lflang/util/CollectionUtil.java | 0 .../src/main/java/org/lflang/util/FileUtil.java | 0 .../src/main/java/org/lflang/util/IteratorUtil.java | 0 .../src/main/java/org/lflang/util/LFCommand.java | 0 .../src/main/java/org/lflang/util/StringUtil.java | 0 .../org/lflang/util/TargetResourceNotFoundException.java | 0 .../main/java/org/lflang/validation/AttributeSpec.java | 0 .../main/java/org/lflang/validation/BaseLFValidator.java | 0 .../validation/LFNamesAreUniqueValidationHelper.java | 0 .../src/main/java/org/lflang/validation/LFValidator.java | 0 .../org/lflang/validation/ValidatorErrorReporter.java | 0 .../src/main/kotlin/org/lflang/CommonExtensions.kt | 0 .../src/main/kotlin/org/lflang/FileConfigExtensions.kt | 0 .../src/main/kotlin/org/lflang/ast/AstExtensions.kt | 0 .../kotlin/org/lflang/generator/GeneratorExtensions.kt | 0 .../main/kotlin/org/lflang/generator/GeneratorUtils.kt | 0 .../org/lflang/generator/LanguageRuntimeVersions.kt | 0 .../kotlin/org/lflang/generator/cpp/CppActionGenerator.kt | 0 .../lflang/generator/cpp/CppAssembleMethodGenerator.kt | 0 .../org/lflang/generator/cpp/CppConnectionGenerator.kt | 0 .../main/kotlin/org/lflang/generator/cpp/CppExtensions.kt | 0 .../main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt | 0 .../main/kotlin/org/lflang/generator/cpp/CppGenerator.kt | 0 .../org/lflang/generator/cpp/CppInstanceGenerator.kt | 0 .../kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt | 0 .../org/lflang/generator/cpp/CppParameterGenerator.kt | 0 .../org/lflang/generator/cpp/CppPlatformGenerator.kt | 0 .../kotlin/org/lflang/generator/cpp/CppPortGenerator.kt | 0 .../org/lflang/generator/cpp/CppPreambleGenerator.kt | 0 .../org/lflang/generator/cpp/CppReactionGenerator.kt | 0 .../org/lflang/generator/cpp/CppReactorGenerator.kt | 0 .../kotlin/org/lflang/generator/cpp/CppRos2Generator.kt | 0 .../org/lflang/generator/cpp/CppRos2NodeGenerator.kt | 0 .../org/lflang/generator/cpp/CppRos2PackageGenerator.kt | 0 .../lflang/generator/cpp/CppStandaloneCmakeGenerator.kt | 0 .../org/lflang/generator/cpp/CppStandaloneGenerator.kt | 0 .../lflang/generator/cpp/CppStandaloneMainGenerator.kt | 0 .../kotlin/org/lflang/generator/cpp/CppStateGenerator.kt | 0 .../kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt | 0 .../src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt | 0 .../main/kotlin/org/lflang/generator/cpp/CppValidator.kt | 0 .../main/kotlin/org/lflang/generator/rust/PortEmitter.kt | 0 .../org/lflang/generator/rust/RustCargoTomlEmitter.kt | 0 .../main/kotlin/org/lflang/generator/rust/RustEmitter.kt | 0 .../kotlin/org/lflang/generator/rust/RustEmitterBase.kt | 0 .../kotlin/org/lflang/generator/rust/RustFileConfig.kt | 0 .../kotlin/org/lflang/generator/rust/RustGenerator.kt | 0 .../org/lflang/generator/rust/RustMainFileEmitter.kt | 0 .../main/kotlin/org/lflang/generator/rust/RustModel.kt | 0 .../org/lflang/generator/rust/RustReactorEmitter.kt | 0 .../main/kotlin/org/lflang/generator/rust/RustTypes.kt | 0 .../kotlin/org/lflang/generator/rust/RustValidator.kt | 0 .../kotlin/org/lflang/generator/ts/TSActionGenerator.kt | 0 .../org/lflang/generator/ts/TSConnectionGenerator.kt | 0 .../org/lflang/generator/ts/TSConstructorGenerator.kt | 0 .../org/lflang/generator/ts/TSDelayBodyGenerator.kt | 0 .../main/kotlin/org/lflang/generator/ts/TSExtensions.kt | 0 .../main/kotlin/org/lflang/generator/ts/TSFileConfig.kt | 0 .../main/kotlin/org/lflang/generator/ts/TSGenerator.kt | 0 .../org/lflang/generator/ts/TSImportPreambleGenerator.kt | 0 .../kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt | 0 .../org/lflang/generator/ts/TSParameterGenerator.kt | 0 .../lflang/generator/ts/TSParameterPreambleGenerator.kt | 0 .../kotlin/org/lflang/generator/ts/TSPortGenerator.kt | 0 .../kotlin/org/lflang/generator/ts/TSReactionGenerator.kt | 0 .../kotlin/org/lflang/generator/ts/TSReactorGenerator.kt | 0 .../kotlin/org/lflang/generator/ts/TSStateGenerator.kt | 0 .../kotlin/org/lflang/generator/ts/TSTimerGenerator.kt | 0 .../main/kotlin/org/lflang/generator/ts/TSValidator.kt | 0 .../services/de.cau.cs.kieler.klighd.IKlighdStartupHook | 0 .../core => core}/src/main/resources/lib/c/reactor-c | 0 .../src/main/resources/lib/cpp/3rd-party/cxxopts.hpp | 0 .../core => core}/src/main/resources/lib/cpp/lfutil.hh | 0 .../core => core}/src/main/resources/lib/cpp/reactor-cpp | 0 .../src/main/resources/lib/cpp/time_parser.hh | 0 .../src/main/resources/lib/platform/zephyr/Kconfig | 0 .../resources/lib/platform/zephyr/boards/esp32.overlay | 0 .../lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf | 0 .../src/main/resources/lib/platform/zephyr/prj_lf.conf | 0 .../src/main/resources/lib/py/lf-python-support | 0 .../core => core}/src/main/resources/lib/rs/reactor-rs | 0 .../src/main/resources/lib/rs/runtime-version.properties | 0 .../src/main/resources/lib/ts/.eslintrc.json | 0 .../core => core}/src/main/resources/lib/ts/README.md | 0 .../core => core}/src/main/resources/lib/ts/package.json | 0 .../core => core}/src/main/resources/lib/ts/tsconfig.json | 0 .../main/resources/org/lflang/StringsBundle.properties | 0 .../src/test/java/org/lflang/tests/LFParsingTest.java | 0 .../src/test/java/org/lflang/tests/LfParsingUtil.java | 0 .../org/lflang/tests/compiler/EquivalenceUnitTests.java | 0 .../org/lflang/tests/compiler/FormattingUnitTests.java | 0 .../java/org/lflang/tests/compiler/LetInferenceTests.java | 0 .../lflang/tests/compiler/LinguaFrancaASTUtilsTest.java | 0 .../compiler/LinguaFrancaDependencyAnalysisTest.java | 0 .../lflang/tests/compiler/LinguaFrancaParsingTest.java | 0 .../lflang/tests/compiler/LinguaFrancaScopingTest.java | 0 .../lflang/tests/compiler/LinguaFrancaValidationTest.java | 0 .../java/org/lflang/tests/compiler/MixedRadixIntTest.java | 0 .../java/org/lflang/tests/compiler/PortInstanceTests.java | 0 .../test/java/org/lflang/tests/compiler/RangeTests.java | 0 .../java/org/lflang/tests/compiler/RoundTripTests.java | 0 .../java/org/lflang/tests/compiler/TargetConfigTests.java | 0 .../test/java/org/lflang/tests/util/StringUtilTest.java | 0 .../testFixtures/java/org/lflang/tests/Configurators.java | 0 .../src/testFixtures/java/org/lflang/tests/LFTest.java | 0 .../src/testFixtures/java/org/lflang/tests/TestBase.java | 0 .../src/testFixtures/java/org/lflang/tests/TestError.java | 0 .../testFixtures/java/org/lflang/tests/TestRegistry.java | 0 {org.lflang/lsp => lsp}/build.gradle | 0 .../java/org/lflang/diagram/lsp/LFLanguageServer.java | 0 .../org/lflang/diagram/lsp/LFLanguageServerExtension.java | 0 .../org/lflang/diagram/lsp/LanguageDiagramServer.java | 0 .../src/main/java/org/lflang/diagram/lsp/Progress.java | 0 {org.lflang/todo => todo}/log4j.xml | 0 356 files changed, 4 insertions(+), 4 deletions(-) rename {org.lflang/cli => cli}/base/build.gradle (100%) rename {org.lflang/cli => cli}/base/src/main/java/org/lflang/cli/CliBase.java (100%) rename {org.lflang/cli => cli}/base/src/main/java/org/lflang/cli/LFStandaloneModule.java (100%) rename {org.lflang/cli => cli}/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java (100%) rename {org.lflang/cli => cli}/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java (100%) rename {org.lflang/cli => cli}/base/src/main/java/org/lflang/cli/VersionProvider.java (100%) rename {org.lflang/cli => cli}/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt (100%) rename {org.lflang/cli => cli}/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java (100%) rename {org.lflang/cli => cli}/base/src/testFixtures/java/org/lflang/cli/TestUtils.java (100%) rename {org.lflang/cli => cli}/lfc/build.gradle (100%) rename {org.lflang/cli => cli}/lfc/src/main/java/org/lflang/cli/Lfc.java (100%) rename {org.lflang/cli => cli}/lfc/src/test/java/org/lflang/cli/LfcCliTest.java (100%) rename {org.lflang/cli => cli}/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/colors.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/colors.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/emptyFile.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/issue490.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/issue490.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/tabs.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/tabs.stderr (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf (100%) rename {org.lflang/cli => cli}/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr (100%) rename {org.lflang/cli => cli}/lff/build.gradle (100%) rename {org.lflang/cli => cli}/lff/src/main/java/org/lflang/cli/Lff.java (100%) rename {org.lflang/cli => cli}/lff/src/test/java/org/lflang/cli/LffCliTest.java (100%) rename {org.lflang/core => core}/build.gradle (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/RunSingleTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/RuntimeTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java (100%) rename {org.lflang/core => core}/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/AttributeUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/DefaultErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/FileConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/InferredType.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LFResourceDescriptionStrategy.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LFResourceProvider.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LFRuntimeModule.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LFStandaloneSetup.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LinguaFranca.xtext (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/LocalStrings.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/MainConflictChecker.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ModelInfo.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/Target.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/TargetConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/TargetProperty.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/TimeUnit.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/TimeValue.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/ASTUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/AstTransformation.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/FormattingUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/IsEqual.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/MalleableString.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/ToLf.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ast/ToText.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/extensions/CExtension.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/extensions/PythonExtension.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/extensions/TSExtension.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedASTUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedEmitter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedFileConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedImportEmitter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedMainEmitter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedTargetConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FedUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/FederateInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/launcher/BuildConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/launcher/CBuildConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/launcher/RtiConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/serialization/FedSerialization.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/federated/validation/FedValidator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/formatting2/LFFormatter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ActionInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/CodeBuilder.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/CodeMap.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/DeadlineInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/DelayBodyGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/DiagnosticReporting.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/DockerComposeGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/DockerData.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/DockerGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/GenerationException.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/GeneratorBase.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/GeneratorCommandFactory.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/GeneratorResult.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/GeneratorUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/IntegratedBuilder.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/InvalidLfSourceException.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/InvalidSourceException.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/LFGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/LFGeneratorContext.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/LFResource.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/LfExpressionVisitor.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/MainContext.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/MixedRadixInt.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ModeInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/NamedInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ParameterInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/PortInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/Position.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/Range.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ReactionInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ReactionInstanceGraph.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ReactorInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/RuntimeRange.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/SendRange.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/SubContext.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/TargetTypes.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/TimerInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/TriggerInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ValidationStrategy.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/Validator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/WatchdogInstance.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CActionGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CCmakeGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CCompiler.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CConstructorGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CDockerGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CFileConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CMethodGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CModesGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CParameterGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CPortGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CPreambleGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CReactionGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CStateGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CTimerGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CTracingGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CTypes.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PyFileConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PyUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonActionGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonModeGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonPortGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonStateGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonTypes.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/python/PythonValidator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/rust/RustTargetConfig.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/generator/ts/TSTypes.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/DirectedGraph.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/Graph.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/InstantiationGraph.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/NodeAnnotation.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/NodeAnnotations.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/PrecedenceGraph.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/graph/TopologyGraph.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ide/LFIdeModule.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/ide/LFIdeSetup.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/scoping/LFScopeProvider.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/ArduinoUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/Averager.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/CollectionUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/FileUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/IteratorUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/LFCommand.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/StringUtil.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/util/TargetResourceNotFoundException.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/validation/AttributeSpec.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/validation/BaseLFValidator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/validation/LFValidator.java (100%) rename {org.lflang/core => core}/src/main/java/org/lflang/validation/ValidatorErrorReporter.java (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/CommonExtensions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/FileConfigExtensions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/ast/AstExtensions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustModel.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt (100%) rename {org.lflang/core => core}/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt (100%) rename {org.lflang/core => core}/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook (100%) rename {org.lflang/core => core}/src/main/resources/lib/c/reactor-c (100%) rename {org.lflang/core => core}/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp (100%) rename {org.lflang/core => core}/src/main/resources/lib/cpp/lfutil.hh (100%) rename {org.lflang/core => core}/src/main/resources/lib/cpp/reactor-cpp (100%) rename {org.lflang/core => core}/src/main/resources/lib/cpp/time_parser.hh (100%) rename {org.lflang/core => core}/src/main/resources/lib/platform/zephyr/Kconfig (100%) rename {org.lflang/core => core}/src/main/resources/lib/platform/zephyr/boards/esp32.overlay (100%) rename {org.lflang/core => core}/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf (100%) rename {org.lflang/core => core}/src/main/resources/lib/platform/zephyr/prj_lf.conf (100%) rename {org.lflang/core => core}/src/main/resources/lib/py/lf-python-support (100%) rename {org.lflang/core => core}/src/main/resources/lib/rs/reactor-rs (100%) rename {org.lflang/core => core}/src/main/resources/lib/rs/runtime-version.properties (100%) rename {org.lflang/core => core}/src/main/resources/lib/ts/.eslintrc.json (100%) rename {org.lflang/core => core}/src/main/resources/lib/ts/README.md (100%) rename {org.lflang/core => core}/src/main/resources/lib/ts/package.json (100%) rename {org.lflang/core => core}/src/main/resources/lib/ts/tsconfig.json (100%) rename {org.lflang/core => core}/src/main/resources/org/lflang/StringsBundle.properties (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/LFParsingTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/LfParsingUtil.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/RangeTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/RoundTripTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java (100%) rename {org.lflang/core => core}/src/test/java/org/lflang/tests/util/StringUtilTest.java (100%) rename {org.lflang/core => core}/src/testFixtures/java/org/lflang/tests/Configurators.java (100%) rename {org.lflang/core => core}/src/testFixtures/java/org/lflang/tests/LFTest.java (100%) rename {org.lflang/core => core}/src/testFixtures/java/org/lflang/tests/TestBase.java (100%) rename {org.lflang/core => core}/src/testFixtures/java/org/lflang/tests/TestError.java (100%) rename {org.lflang/core => core}/src/testFixtures/java/org/lflang/tests/TestRegistry.java (100%) rename {org.lflang/lsp => lsp}/build.gradle (100%) rename {org.lflang/lsp => lsp}/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java (100%) rename {org.lflang/lsp => lsp}/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java (100%) rename {org.lflang/lsp => lsp}/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java (100%) rename {org.lflang/lsp => lsp}/src/main/java/org/lflang/diagram/lsp/Progress.java (100%) rename {org.lflang/todo => todo}/log4j.xml (100%) diff --git a/.gitmodules b/.gitmodules index 52c3af173b..9cd89ffe1a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ [submodule "org.lflang/src/lib/c/reactor-c"] - path = org.lflang/core/src/main/resources/lib/c/reactor-c + path = core/src/main/resources/lib/c/reactor-c url = https://github.com/lf-lang/reactor-c.git [submodule "org.lflang/src/lib/cpp/reactor-cpp"] - path = org.lflang/core/src/main/resources/lib/cpp/reactor-cpp + path = core/src/main/resources/lib/cpp/reactor-cpp url = https://github.com/lf-lang/reactor-cpp [submodule "org.lflang/src/lib/rs/reactor-rs"] - path = org.lflang/core/src/main/resources/lib/rs/reactor-rs + path = core/src/main/resources/lib/rs/reactor-rs url = https://github.com/lf-lang/reactor-rs [submodule "org.lflang/src/lib/py/lf-python-support"] - path = org.lflang/core/src/main/resources/lib/py/lf-python-support + path = core/src/main/resources/lib/py/lf-python-support url = https://github.com/lf-lang/lf-python-support.git diff --git a/org.lflang/cli/base/build.gradle b/cli/base/build.gradle similarity index 100% rename from org.lflang/cli/base/build.gradle rename to cli/base/build.gradle diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java b/cli/base/src/main/java/org/lflang/cli/CliBase.java similarity index 100% rename from org.lflang/cli/base/src/main/java/org/lflang/cli/CliBase.java rename to cli/base/src/main/java/org/lflang/cli/CliBase.java diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/LFStandaloneModule.java b/cli/base/src/main/java/org/lflang/cli/LFStandaloneModule.java similarity index 100% rename from org.lflang/cli/base/src/main/java/org/lflang/cli/LFStandaloneModule.java rename to cli/base/src/main/java/org/lflang/cli/LFStandaloneModule.java diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java b/cli/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java similarity index 100% rename from org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java rename to cli/base/src/main/java/org/lflang/cli/StandaloneErrorReporter.java diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java b/cli/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java similarity index 100% rename from org.lflang/cli/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java rename to cli/base/src/main/java/org/lflang/cli/StandaloneIssueAcceptor.java diff --git a/org.lflang/cli/base/src/main/java/org/lflang/cli/VersionProvider.java b/cli/base/src/main/java/org/lflang/cli/VersionProvider.java similarity index 100% rename from org.lflang/cli/base/src/main/java/org/lflang/cli/VersionProvider.java rename to cli/base/src/main/java/org/lflang/cli/VersionProvider.java diff --git a/org.lflang/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt b/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt similarity index 100% rename from org.lflang/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt rename to cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt diff --git a/org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java b/cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java similarity index 100% rename from org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java rename to cli/base/src/testFixtures/java/org/lflang/cli/CliToolTestFixture.java diff --git a/org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java b/cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java similarity index 100% rename from org.lflang/cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java rename to cli/base/src/testFixtures/java/org/lflang/cli/TestUtils.java diff --git a/org.lflang/cli/lfc/build.gradle b/cli/lfc/build.gradle similarity index 100% rename from org.lflang/cli/lfc/build.gradle rename to cli/lfc/build.gradle diff --git a/org.lflang/cli/lfc/src/main/java/org/lflang/cli/Lfc.java b/cli/lfc/src/main/java/org/lflang/cli/Lfc.java similarity index 100% rename from org.lflang/cli/lfc/src/main/java/org/lflang/cli/Lfc.java rename to cli/lfc/src/main/java/org/lflang/cli/Lfc.java diff --git a/org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java b/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java similarity index 100% rename from org.lflang/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java rename to cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java diff --git a/org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt b/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt similarity index 100% rename from org.lflang/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt rename to cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.lf b/cli/lfc/src/test/resources/org/lflang/cli/colors.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.lf rename to cli/lfc/src/test/resources/org/lflang/cli/colors.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.stderr b/cli/lfc/src/test/resources/org/lflang/cli/colors.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/colors.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/colors.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.lf b/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.lf rename to cli/lfc/src/test/resources/org/lflang/cli/emptyFile.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr b/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/emptyFile.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf b/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf rename to cli/lfc/src/test/resources/org/lflang/cli/issue490.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr b/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf b/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf rename to cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr b/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/multilineWarning.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf b/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf rename to cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr b/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/multilineWarningTooBig.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf b/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf rename to cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr b/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/simpleWarning.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf b/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf rename to cli/lfc/src/test/resources/org/lflang/cli/tabs.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr b/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf b/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf rename to cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.lf diff --git a/org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr b/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr similarity index 100% rename from org.lflang/cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr rename to cli/lfc/src/test/resources/org/lflang/cli/twoLineWarning.stderr diff --git a/org.lflang/cli/lff/build.gradle b/cli/lff/build.gradle similarity index 100% rename from org.lflang/cli/lff/build.gradle rename to cli/lff/build.gradle diff --git a/org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java b/cli/lff/src/main/java/org/lflang/cli/Lff.java similarity index 100% rename from org.lflang/cli/lff/src/main/java/org/lflang/cli/Lff.java rename to cli/lff/src/main/java/org/lflang/cli/Lff.java diff --git a/org.lflang/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java b/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java similarity index 100% rename from org.lflang/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java rename to cli/lff/src/test/java/org/lflang/cli/LffCliTest.java diff --git a/org.lflang/core/build.gradle b/core/build.gradle similarity index 100% rename from org.lflang/core/build.gradle rename to core/build.gradle diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java b/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java rename to core/src/integrationTest/java/org/lflang/tests/RunSingleTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java rename to core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java b/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java rename to core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java b/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java rename to core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java b/core/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java rename to core/src/integrationTest/java/org/lflang/tests/lsp/MockLanguageClient.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java b/core/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java rename to core/src/integrationTest/java/org/lflang/tests/lsp/MockReportProgress.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java rename to core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java diff --git a/org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java b/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java similarity index 100% rename from org.lflang/core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java rename to core/src/integrationTest/java/org/lflang/tests/serialization/SerializationTest.java diff --git a/org.lflang/core/src/main/java/org/lflang/AttributeUtils.java b/core/src/main/java/org/lflang/AttributeUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/AttributeUtils.java rename to core/src/main/java/org/lflang/AttributeUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/DefaultErrorReporter.java b/core/src/main/java/org/lflang/DefaultErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/DefaultErrorReporter.java rename to core/src/main/java/org/lflang/DefaultErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/ErrorReporter.java b/core/src/main/java/org/lflang/ErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ErrorReporter.java rename to core/src/main/java/org/lflang/ErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/FileConfig.java b/core/src/main/java/org/lflang/FileConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/FileConfig.java rename to core/src/main/java/org/lflang/FileConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 b/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 rename to core/src/main/java/org/lflang/GenerateLinguaFranca.mwe2 diff --git a/org.lflang/core/src/main/java/org/lflang/InferredType.java b/core/src/main/java/org/lflang/InferredType.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/InferredType.java rename to core/src/main/java/org/lflang/InferredType.java diff --git a/org.lflang/core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java b/core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java rename to core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java diff --git a/org.lflang/core/src/main/java/org/lflang/LFResourceProvider.java b/core/src/main/java/org/lflang/LFResourceProvider.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LFResourceProvider.java rename to core/src/main/java/org/lflang/LFResourceProvider.java diff --git a/org.lflang/core/src/main/java/org/lflang/LFRuntimeModule.java b/core/src/main/java/org/lflang/LFRuntimeModule.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LFRuntimeModule.java rename to core/src/main/java/org/lflang/LFRuntimeModule.java diff --git a/org.lflang/core/src/main/java/org/lflang/LFStandaloneSetup.java b/core/src/main/java/org/lflang/LFStandaloneSetup.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LFStandaloneSetup.java rename to core/src/main/java/org/lflang/LFStandaloneSetup.java diff --git a/org.lflang/core/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java b/core/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java rename to core/src/main/java/org/lflang/LFSyntaxErrorMessageProvider.java diff --git a/org.lflang/core/src/main/java/org/lflang/LinguaFranca.xtext b/core/src/main/java/org/lflang/LinguaFranca.xtext similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LinguaFranca.xtext rename to core/src/main/java/org/lflang/LinguaFranca.xtext diff --git a/org.lflang/core/src/main/java/org/lflang/LocalStrings.java b/core/src/main/java/org/lflang/LocalStrings.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/LocalStrings.java rename to core/src/main/java/org/lflang/LocalStrings.java diff --git a/org.lflang/core/src/main/java/org/lflang/MainConflictChecker.java b/core/src/main/java/org/lflang/MainConflictChecker.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/MainConflictChecker.java rename to core/src/main/java/org/lflang/MainConflictChecker.java diff --git a/org.lflang/core/src/main/java/org/lflang/ModelInfo.java b/core/src/main/java/org/lflang/ModelInfo.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ModelInfo.java rename to core/src/main/java/org/lflang/ModelInfo.java diff --git a/org.lflang/core/src/main/java/org/lflang/Target.java b/core/src/main/java/org/lflang/Target.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/Target.java rename to core/src/main/java/org/lflang/Target.java diff --git a/org.lflang/core/src/main/java/org/lflang/TargetConfig.java b/core/src/main/java/org/lflang/TargetConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/TargetConfig.java rename to core/src/main/java/org/lflang/TargetConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/TargetProperty.java b/core/src/main/java/org/lflang/TargetProperty.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/TargetProperty.java rename to core/src/main/java/org/lflang/TargetProperty.java diff --git a/org.lflang/core/src/main/java/org/lflang/TimeUnit.java b/core/src/main/java/org/lflang/TimeUnit.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/TimeUnit.java rename to core/src/main/java/org/lflang/TimeUnit.java diff --git a/org.lflang/core/src/main/java/org/lflang/TimeValue.java b/core/src/main/java/org/lflang/TimeValue.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/TimeValue.java rename to core/src/main/java/org/lflang/TimeValue.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/ASTUtils.java b/core/src/main/java/org/lflang/ast/ASTUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/ASTUtils.java rename to core/src/main/java/org/lflang/ast/ASTUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/AstTransformation.java b/core/src/main/java/org/lflang/ast/AstTransformation.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/AstTransformation.java rename to core/src/main/java/org/lflang/ast/AstTransformation.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java b/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java rename to core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/FormattingUtils.java b/core/src/main/java/org/lflang/ast/FormattingUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/FormattingUtils.java rename to core/src/main/java/org/lflang/ast/FormattingUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/IsEqual.java b/core/src/main/java/org/lflang/ast/IsEqual.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/IsEqual.java rename to core/src/main/java/org/lflang/ast/IsEqual.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/MalleableString.java b/core/src/main/java/org/lflang/ast/MalleableString.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/MalleableString.java rename to core/src/main/java/org/lflang/ast/MalleableString.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/ToLf.java b/core/src/main/java/org/lflang/ast/ToLf.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/ToLf.java rename to core/src/main/java/org/lflang/ast/ToLf.java diff --git a/org.lflang/core/src/main/java/org/lflang/ast/ToText.java b/core/src/main/java/org/lflang/ast/ToText.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ast/ToText.java rename to core/src/main/java/org/lflang/ast/ToText.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java b/core/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java rename to core/src/main/java/org/lflang/diagram/synthesis/AbstractSynthesisExtensions.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java rename to core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java b/core/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java rename to core/src/main/java/org/lflang/diagram/synthesis/ReactorParameterDisplayModes.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java b/core/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java rename to core/src/main/java/org/lflang/diagram/synthesis/SynthesisRegistration.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java b/core/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java rename to core/src/main/java/org/lflang/diagram/synthesis/action/AbstractAction.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java b/core/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java rename to core/src/main/java/org/lflang/diagram/synthesis/action/CollapseAllReactorsAction.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java b/core/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java rename to core/src/main/java/org/lflang/diagram/synthesis/action/ExpandAllReactorsAction.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java b/core/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java rename to core/src/main/java/org/lflang/diagram/synthesis/action/FilterCycleAction.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java b/core/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java rename to core/src/main/java/org/lflang/diagram/synthesis/action/MemorizingExpandCollapseAction.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java b/core/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java rename to core/src/main/java/org/lflang/diagram/synthesis/action/ShowCycleAction.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java b/core/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java rename to core/src/main/java/org/lflang/diagram/synthesis/postprocessor/ReactionPortAdjustment.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java b/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java rename to core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java b/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java rename to core/src/main/java/org/lflang/diagram/synthesis/styles/LinguaFrancaStyleExtensions.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java b/core/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java rename to core/src/main/java/org/lflang/diagram/synthesis/styles/ReactorFigureComponents.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java b/core/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/CycleVisualization.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java b/core/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/InterfaceDependenciesVisualization.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java b/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java b/core/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/ModeDiagrams.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java b/core/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/NamedInstanceUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java b/core/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/ReactorIcons.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java b/core/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/SynthesisErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java b/core/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java rename to core/src/main/java/org/lflang/diagram/synthesis/util/UtilityExtensions.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtension.java b/core/src/main/java/org/lflang/federated/extensions/CExtension.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtension.java rename to core/src/main/java/org/lflang/federated/extensions/CExtension.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java rename to core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java b/core/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java rename to core/src/main/java/org/lflang/federated/extensions/FedTargetExtension.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java b/core/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java rename to core/src/main/java/org/lflang/federated/extensions/FedTargetExtensionFactory.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java b/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java rename to core/src/main/java/org/lflang/federated/extensions/PythonExtension.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/extensions/TSExtension.java b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/extensions/TSExtension.java rename to core/src/main/java/org/lflang/federated/extensions/TSExtension.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java rename to core/src/main/java/org/lflang/federated/generator/FedASTUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java b/core/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java rename to core/src/main/java/org/lflang/federated/generator/FedConnectionInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedEmitter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedEmitter.java rename to core/src/main/java/org/lflang/federated/generator/FedEmitter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedFileConfig.java b/core/src/main/java/org/lflang/federated/generator/FedFileConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedFileConfig.java rename to core/src/main/java/org/lflang/federated/generator/FedFileConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedGenerator.java rename to core/src/main/java/org/lflang/federated/generator/FedGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedImportEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedImportEmitter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedImportEmitter.java rename to core/src/main/java/org/lflang/federated/generator/FedImportEmitter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java rename to core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java rename to core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java rename to core/src/main/java/org/lflang/federated/generator/FedReactorEmitter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetConfig.java b/core/src/main/java/org/lflang/federated/generator/FedTargetConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetConfig.java rename to core/src/main/java/org/lflang/federated/generator/FedTargetConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java rename to core/src/main/java/org/lflang/federated/generator/FedTargetEmitter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FedUtils.java b/core/src/main/java/org/lflang/federated/generator/FedUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FedUtils.java rename to core/src/main/java/org/lflang/federated/generator/FedUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/FederateInstance.java b/core/src/main/java/org/lflang/federated/generator/FederateInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/FederateInstance.java rename to core/src/main/java/org/lflang/federated/generator/FederateInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java b/core/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java rename to core/src/main/java/org/lflang/federated/generator/LineAdjustingErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java b/core/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java rename to core/src/main/java/org/lflang/federated/generator/SynchronizedErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/launcher/BuildConfig.java b/core/src/main/java/org/lflang/federated/launcher/BuildConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/launcher/BuildConfig.java rename to core/src/main/java/org/lflang/federated/launcher/BuildConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/launcher/CBuildConfig.java b/core/src/main/java/org/lflang/federated/launcher/CBuildConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/launcher/CBuildConfig.java rename to core/src/main/java/org/lflang/federated/launcher/CBuildConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java b/core/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java rename to core/src/main/java/org/lflang/federated/launcher/FedLauncherGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java b/core/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java rename to core/src/main/java/org/lflang/federated/launcher/PyBuildConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/launcher/RtiConfig.java b/core/src/main/java/org/lflang/federated/launcher/RtiConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/launcher/RtiConfig.java rename to core/src/main/java/org/lflang/federated/launcher/RtiConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java b/core/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java rename to core/src/main/java/org/lflang/federated/launcher/TsBuildConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java b/core/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java rename to core/src/main/java/org/lflang/federated/serialization/FedNativePythonSerialization.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java b/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java rename to core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/serialization/FedSerialization.java b/core/src/main/java/org/lflang/federated/serialization/FedSerialization.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/serialization/FedSerialization.java rename to core/src/main/java/org/lflang/federated/serialization/FedSerialization.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java b/core/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java rename to core/src/main/java/org/lflang/federated/serialization/SupportedSerializers.java diff --git a/org.lflang/core/src/main/java/org/lflang/federated/validation/FedValidator.java b/core/src/main/java/org/lflang/federated/validation/FedValidator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/federated/validation/FedValidator.java rename to core/src/main/java/org/lflang/federated/validation/FedValidator.java diff --git a/org.lflang/core/src/main/java/org/lflang/formatting2/LFFormatter.java b/core/src/main/java/org/lflang/formatting2/LFFormatter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/formatting2/LFFormatter.java rename to core/src/main/java/org/lflang/formatting2/LFFormatter.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ActionInstance.java b/core/src/main/java/org/lflang/generator/ActionInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ActionInstance.java rename to core/src/main/java/org/lflang/generator/ActionInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/CodeBuilder.java b/core/src/main/java/org/lflang/generator/CodeBuilder.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/CodeBuilder.java rename to core/src/main/java/org/lflang/generator/CodeBuilder.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/CodeMap.java b/core/src/main/java/org/lflang/generator/CodeMap.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/CodeMap.java rename to core/src/main/java/org/lflang/generator/CodeMap.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/DeadlineInstance.java b/core/src/main/java/org/lflang/generator/DeadlineInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/DeadlineInstance.java rename to core/src/main/java/org/lflang/generator/DeadlineInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/DelayBodyGenerator.java b/core/src/main/java/org/lflang/generator/DelayBodyGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/DelayBodyGenerator.java rename to core/src/main/java/org/lflang/generator/DelayBodyGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/DiagnosticReporting.java b/core/src/main/java/org/lflang/generator/DiagnosticReporting.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/DiagnosticReporting.java rename to core/src/main/java/org/lflang/generator/DiagnosticReporting.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/DockerComposeGenerator.java b/core/src/main/java/org/lflang/generator/DockerComposeGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/DockerComposeGenerator.java rename to core/src/main/java/org/lflang/generator/DockerComposeGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/DockerData.java b/core/src/main/java/org/lflang/generator/DockerData.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/DockerData.java rename to core/src/main/java/org/lflang/generator/DockerData.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/DockerGenerator.java b/core/src/main/java/org/lflang/generator/DockerGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/DockerGenerator.java rename to core/src/main/java/org/lflang/generator/DockerGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java b/core/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java rename to core/src/main/java/org/lflang/generator/FedDockerComposeGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GenerationException.java b/core/src/main/java/org/lflang/generator/GenerationException.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GenerationException.java rename to core/src/main/java/org/lflang/generator/GenerationException.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GeneratorBase.java b/core/src/main/java/org/lflang/generator/GeneratorBase.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GeneratorBase.java rename to core/src/main/java/org/lflang/generator/GeneratorBase.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GeneratorCommandFactory.java b/core/src/main/java/org/lflang/generator/GeneratorCommandFactory.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GeneratorCommandFactory.java rename to core/src/main/java/org/lflang/generator/GeneratorCommandFactory.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GeneratorResult.java b/core/src/main/java/org/lflang/generator/GeneratorResult.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GeneratorResult.java rename to core/src/main/java/org/lflang/generator/GeneratorResult.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.java b/core/src/main/java/org/lflang/generator/GeneratorUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/GeneratorUtils.java rename to core/src/main/java/org/lflang/generator/GeneratorUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java b/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java rename to core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/IntegratedBuilder.java b/core/src/main/java/org/lflang/generator/IntegratedBuilder.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/IntegratedBuilder.java rename to core/src/main/java/org/lflang/generator/IntegratedBuilder.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/InvalidLfSourceException.java b/core/src/main/java/org/lflang/generator/InvalidLfSourceException.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/InvalidLfSourceException.java rename to core/src/main/java/org/lflang/generator/InvalidLfSourceException.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/InvalidSourceException.java b/core/src/main/java/org/lflang/generator/InvalidSourceException.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/InvalidSourceException.java rename to core/src/main/java/org/lflang/generator/InvalidSourceException.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/LFGenerator.java b/core/src/main/java/org/lflang/generator/LFGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/LFGenerator.java rename to core/src/main/java/org/lflang/generator/LFGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/LFGeneratorContext.java b/core/src/main/java/org/lflang/generator/LFGeneratorContext.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/LFGeneratorContext.java rename to core/src/main/java/org/lflang/generator/LFGeneratorContext.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/LFResource.java b/core/src/main/java/org/lflang/generator/LFResource.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/LFResource.java rename to core/src/main/java/org/lflang/generator/LFResource.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java b/core/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java rename to core/src/main/java/org/lflang/generator/LanguageServerErrorReporter.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/LfExpressionVisitor.java b/core/src/main/java/org/lflang/generator/LfExpressionVisitor.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/LfExpressionVisitor.java rename to core/src/main/java/org/lflang/generator/LfExpressionVisitor.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/MainContext.java b/core/src/main/java/org/lflang/generator/MainContext.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/MainContext.java rename to core/src/main/java/org/lflang/generator/MainContext.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/MixedRadixInt.java b/core/src/main/java/org/lflang/generator/MixedRadixInt.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/MixedRadixInt.java rename to core/src/main/java/org/lflang/generator/MixedRadixInt.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ModeInstance.java b/core/src/main/java/org/lflang/generator/ModeInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ModeInstance.java rename to core/src/main/java/org/lflang/generator/ModeInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/NamedInstance.java b/core/src/main/java/org/lflang/generator/NamedInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/NamedInstance.java rename to core/src/main/java/org/lflang/generator/NamedInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ParameterInstance.java b/core/src/main/java/org/lflang/generator/ParameterInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ParameterInstance.java rename to core/src/main/java/org/lflang/generator/ParameterInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/PortInstance.java b/core/src/main/java/org/lflang/generator/PortInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/PortInstance.java rename to core/src/main/java/org/lflang/generator/PortInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/Position.java b/core/src/main/java/org/lflang/generator/Position.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/Position.java rename to core/src/main/java/org/lflang/generator/Position.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/Range.java b/core/src/main/java/org/lflang/generator/Range.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/Range.java rename to core/src/main/java/org/lflang/generator/Range.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ReactionInstance.java b/core/src/main/java/org/lflang/generator/ReactionInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ReactionInstance.java rename to core/src/main/java/org/lflang/generator/ReactionInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ReactionInstanceGraph.java b/core/src/main/java/org/lflang/generator/ReactionInstanceGraph.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ReactionInstanceGraph.java rename to core/src/main/java/org/lflang/generator/ReactionInstanceGraph.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ReactorInstance.java b/core/src/main/java/org/lflang/generator/ReactorInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ReactorInstance.java rename to core/src/main/java/org/lflang/generator/ReactorInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/RuntimeRange.java b/core/src/main/java/org/lflang/generator/RuntimeRange.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/RuntimeRange.java rename to core/src/main/java/org/lflang/generator/RuntimeRange.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/SendRange.java b/core/src/main/java/org/lflang/generator/SendRange.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/SendRange.java rename to core/src/main/java/org/lflang/generator/SendRange.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/SubContext.java b/core/src/main/java/org/lflang/generator/SubContext.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/SubContext.java rename to core/src/main/java/org/lflang/generator/SubContext.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/TargetTypes.java b/core/src/main/java/org/lflang/generator/TargetTypes.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/TargetTypes.java rename to core/src/main/java/org/lflang/generator/TargetTypes.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/TimerInstance.java b/core/src/main/java/org/lflang/generator/TimerInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/TimerInstance.java rename to core/src/main/java/org/lflang/generator/TimerInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/TriggerInstance.java b/core/src/main/java/org/lflang/generator/TriggerInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/TriggerInstance.java rename to core/src/main/java/org/lflang/generator/TriggerInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java b/core/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java rename to core/src/main/java/org/lflang/generator/UnsupportedGeneratorFeatureException.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ValidationStrategy.java b/core/src/main/java/org/lflang/generator/ValidationStrategy.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ValidationStrategy.java rename to core/src/main/java/org/lflang/generator/ValidationStrategy.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/Validator.java b/core/src/main/java/org/lflang/generator/Validator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/Validator.java rename to core/src/main/java/org/lflang/generator/Validator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/WatchdogInstance.java b/core/src/main/java/org/lflang/generator/WatchdogInstance.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/WatchdogInstance.java rename to core/src/main/java/org/lflang/generator/WatchdogInstance.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CActionGenerator.java b/core/src/main/java/org/lflang/generator/c/CActionGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CActionGenerator.java rename to core/src/main/java/org/lflang/generator/c/CActionGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java rename to core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CCompiler.java rename to core/src/main/java/org/lflang/generator/c/CCompiler.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CConstructorGenerator.java b/core/src/main/java/org/lflang/generator/c/CConstructorGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CConstructorGenerator.java rename to core/src/main/java/org/lflang/generator/c/CConstructorGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java b/core/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java rename to core/src/main/java/org/lflang/generator/c/CCoreFilesUtils.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java b/core/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java rename to core/src/main/java/org/lflang/generator/c/CDelayBodyGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CDockerGenerator.java b/core/src/main/java/org/lflang/generator/c/CDockerGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CDockerGenerator.java rename to core/src/main/java/org/lflang/generator/c/CDockerGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CFileConfig.java b/core/src/main/java/org/lflang/generator/c/CFileConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CFileConfig.java rename to core/src/main/java/org/lflang/generator/c/CFileConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CGenerator.java rename to core/src/main/java/org/lflang/generator/c/CGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java b/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java rename to core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CMethodGenerator.java b/core/src/main/java/org/lflang/generator/c/CMethodGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CMethodGenerator.java rename to core/src/main/java/org/lflang/generator/c/CMethodGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java b/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java rename to core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CModesGenerator.java b/core/src/main/java/org/lflang/generator/c/CModesGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CModesGenerator.java rename to core/src/main/java/org/lflang/generator/c/CModesGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CParameterGenerator.java b/core/src/main/java/org/lflang/generator/c/CParameterGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CParameterGenerator.java rename to core/src/main/java/org/lflang/generator/c/CParameterGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CPortGenerator.java b/core/src/main/java/org/lflang/generator/c/CPortGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CPortGenerator.java rename to core/src/main/java/org/lflang/generator/c/CPortGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java rename to core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java b/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java rename to core/src/main/java/org/lflang/generator/c/CReactionGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java rename to core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CStateGenerator.java b/core/src/main/java/org/lflang/generator/c/CStateGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CStateGenerator.java rename to core/src/main/java/org/lflang/generator/c/CStateGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CTimerGenerator.java b/core/src/main/java/org/lflang/generator/c/CTimerGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CTimerGenerator.java rename to core/src/main/java/org/lflang/generator/c/CTimerGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java b/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java rename to core/src/main/java/org/lflang/generator/c/CTracingGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java b/core/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java rename to core/src/main/java/org/lflang/generator/c/CTriggerObjectsGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CTypes.java b/core/src/main/java/org/lflang/generator/c/CTypes.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CTypes.java rename to core/src/main/java/org/lflang/generator/c/CTypes.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CUtil.java b/core/src/main/java/org/lflang/generator/c/CUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CUtil.java rename to core/src/main/java/org/lflang/generator/c/CUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java b/core/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java rename to core/src/main/java/org/lflang/generator/c/CWatchdogGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java b/core/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java rename to core/src/main/java/org/lflang/generator/c/InteractingContainedReactors.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java rename to core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PyFileConfig.java b/core/src/main/java/org/lflang/generator/python/PyFileConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PyFileConfig.java rename to core/src/main/java/org/lflang/generator/python/PyFileConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PyUtil.java b/core/src/main/java/org/lflang/generator/python/PyUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PyUtil.java rename to core/src/main/java/org/lflang/generator/python/PyUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonActionGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonActionGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonActionGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonActionGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonDelayBodyGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonDockerGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonInfoGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonMainFunctionGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonMethodGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonModeGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonModeGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonModeGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonModeGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonParameterGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonPortGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonPortGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonPortGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonPortGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonPreambleGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonReactionGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonStateGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonStateGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonStateGenerator.java rename to core/src/main/java/org/lflang/generator/python/PythonStateGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonTypes.java b/core/src/main/java/org/lflang/generator/python/PythonTypes.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonTypes.java rename to core/src/main/java/org/lflang/generator/python/PythonTypes.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/python/PythonValidator.java b/core/src/main/java/org/lflang/generator/python/PythonValidator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/python/PythonValidator.java rename to core/src/main/java/org/lflang/generator/python/PythonValidator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java b/core/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java rename to core/src/main/java/org/lflang/generator/rust/CargoDependencySpec.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/rust/RustTargetConfig.java b/core/src/main/java/org/lflang/generator/rust/RustTargetConfig.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/rust/RustTargetConfig.java rename to core/src/main/java/org/lflang/generator/rust/RustTargetConfig.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java b/core/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java rename to core/src/main/java/org/lflang/generator/ts/TSDockerGenerator.java diff --git a/org.lflang/core/src/main/java/org/lflang/generator/ts/TSTypes.java b/core/src/main/java/org/lflang/generator/ts/TSTypes.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/generator/ts/TSTypes.java rename to core/src/main/java/org/lflang/generator/ts/TSTypes.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/DirectedGraph.java b/core/src/main/java/org/lflang/graph/DirectedGraph.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/DirectedGraph.java rename to core/src/main/java/org/lflang/graph/DirectedGraph.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/Graph.java b/core/src/main/java/org/lflang/graph/Graph.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/Graph.java rename to core/src/main/java/org/lflang/graph/Graph.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/InstantiationGraph.java b/core/src/main/java/org/lflang/graph/InstantiationGraph.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/InstantiationGraph.java rename to core/src/main/java/org/lflang/graph/InstantiationGraph.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotation.java b/core/src/main/java/org/lflang/graph/NodeAnnotation.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotation.java rename to core/src/main/java/org/lflang/graph/NodeAnnotation.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotations.java b/core/src/main/java/org/lflang/graph/NodeAnnotations.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/NodeAnnotations.java rename to core/src/main/java/org/lflang/graph/NodeAnnotations.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/PrecedenceGraph.java b/core/src/main/java/org/lflang/graph/PrecedenceGraph.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/PrecedenceGraph.java rename to core/src/main/java/org/lflang/graph/PrecedenceGraph.java diff --git a/org.lflang/core/src/main/java/org/lflang/graph/TopologyGraph.java b/core/src/main/java/org/lflang/graph/TopologyGraph.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/graph/TopologyGraph.java rename to core/src/main/java/org/lflang/graph/TopologyGraph.java diff --git a/org.lflang/core/src/main/java/org/lflang/ide/LFIdeModule.java b/core/src/main/java/org/lflang/ide/LFIdeModule.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ide/LFIdeModule.java rename to core/src/main/java/org/lflang/ide/LFIdeModule.java diff --git a/org.lflang/core/src/main/java/org/lflang/ide/LFIdeSetup.java b/core/src/main/java/org/lflang/ide/LFIdeSetup.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/ide/LFIdeSetup.java rename to core/src/main/java/org/lflang/ide/LFIdeSetup.java diff --git a/org.lflang/core/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java b/core/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java rename to core/src/main/java/org/lflang/scoping/LFGlobalScopeProvider.java diff --git a/org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProvider.java b/core/src/main/java/org/lflang/scoping/LFScopeProvider.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProvider.java rename to core/src/main/java/org/lflang/scoping/LFScopeProvider.java diff --git a/org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java b/core/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java rename to core/src/main/java/org/lflang/scoping/LFScopeProviderImpl.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/ArduinoUtil.java b/core/src/main/java/org/lflang/util/ArduinoUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/ArduinoUtil.java rename to core/src/main/java/org/lflang/util/ArduinoUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/Averager.java b/core/src/main/java/org/lflang/util/Averager.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/Averager.java rename to core/src/main/java/org/lflang/util/Averager.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/CollectionUtil.java b/core/src/main/java/org/lflang/util/CollectionUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/CollectionUtil.java rename to core/src/main/java/org/lflang/util/CollectionUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/FileUtil.java b/core/src/main/java/org/lflang/util/FileUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/FileUtil.java rename to core/src/main/java/org/lflang/util/FileUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/IteratorUtil.java b/core/src/main/java/org/lflang/util/IteratorUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/IteratorUtil.java rename to core/src/main/java/org/lflang/util/IteratorUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/LFCommand.java b/core/src/main/java/org/lflang/util/LFCommand.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/LFCommand.java rename to core/src/main/java/org/lflang/util/LFCommand.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/StringUtil.java b/core/src/main/java/org/lflang/util/StringUtil.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/StringUtil.java rename to core/src/main/java/org/lflang/util/StringUtil.java diff --git a/org.lflang/core/src/main/java/org/lflang/util/TargetResourceNotFoundException.java b/core/src/main/java/org/lflang/util/TargetResourceNotFoundException.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/util/TargetResourceNotFoundException.java rename to core/src/main/java/org/lflang/util/TargetResourceNotFoundException.java diff --git a/org.lflang/core/src/main/java/org/lflang/validation/AttributeSpec.java b/core/src/main/java/org/lflang/validation/AttributeSpec.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/validation/AttributeSpec.java rename to core/src/main/java/org/lflang/validation/AttributeSpec.java diff --git a/org.lflang/core/src/main/java/org/lflang/validation/BaseLFValidator.java b/core/src/main/java/org/lflang/validation/BaseLFValidator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/validation/BaseLFValidator.java rename to core/src/main/java/org/lflang/validation/BaseLFValidator.java diff --git a/org.lflang/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java b/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java rename to core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java diff --git a/org.lflang/core/src/main/java/org/lflang/validation/LFValidator.java b/core/src/main/java/org/lflang/validation/LFValidator.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/validation/LFValidator.java rename to core/src/main/java/org/lflang/validation/LFValidator.java diff --git a/org.lflang/core/src/main/java/org/lflang/validation/ValidatorErrorReporter.java b/core/src/main/java/org/lflang/validation/ValidatorErrorReporter.java similarity index 100% rename from org.lflang/core/src/main/java/org/lflang/validation/ValidatorErrorReporter.java rename to core/src/main/java/org/lflang/validation/ValidatorErrorReporter.java diff --git a/org.lflang/core/src/main/kotlin/org/lflang/CommonExtensions.kt b/core/src/main/kotlin/org/lflang/CommonExtensions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/CommonExtensions.kt rename to core/src/main/kotlin/org/lflang/CommonExtensions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/FileConfigExtensions.kt b/core/src/main/kotlin/org/lflang/FileConfigExtensions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/FileConfigExtensions.kt rename to core/src/main/kotlin/org/lflang/FileConfigExtensions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/ast/AstExtensions.kt b/core/src/main/kotlin/org/lflang/ast/AstExtensions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/ast/AstExtensions.kt rename to core/src/main/kotlin/org/lflang/ast/AstExtensions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt b/core/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt rename to core/src/main/kotlin/org/lflang/generator/GeneratorExtensions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt b/core/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt rename to core/src/main/kotlin/org/lflang/generator/GeneratorUtils.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt b/core/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt rename to core/src/main/kotlin/org/lflang/generator/LanguageRuntimeVersions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppActionGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppAssembleMethodGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppConnectionGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppExtensions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppFileConfig.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppMethodGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppParameterGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppPortGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppPreambleGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppReactionGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppReactorGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppRos2NodeGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppStateGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppTimerGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt rename to core/src/main/kotlin/org/lflang/generator/cpp/CppValidator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt b/core/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt rename to core/src/main/kotlin/org/lflang/generator/rust/PortEmitter.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustCargoTomlEmitter.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustEmitter.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustEmitterBase.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustFileConfig.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustMainFileEmitter.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustModel.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustModel.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustModel.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustModel.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustReactorEmitter.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustTypes.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt b/core/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt rename to core/src/main/kotlin/org/lflang/generator/rust/RustValidator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSActionGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSConnectionGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSDelayBodyGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSImportPreambleGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSParameterGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSParameterPreambleGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSPortGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSReactionGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSStateGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSTimerGenerator.kt diff --git a/org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt similarity index 100% rename from org.lflang/core/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt rename to core/src/main/kotlin/org/lflang/generator/ts/TSValidator.kt diff --git a/org.lflang/core/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook b/core/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook similarity index 100% rename from org.lflang/core/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook rename to core/src/main/resources/META-INF/services/de.cau.cs.kieler.klighd.IKlighdStartupHook diff --git a/org.lflang/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c similarity index 100% rename from org.lflang/core/src/main/resources/lib/c/reactor-c rename to core/src/main/resources/lib/c/reactor-c diff --git a/org.lflang/core/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp b/core/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp similarity index 100% rename from org.lflang/core/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp rename to core/src/main/resources/lib/cpp/3rd-party/cxxopts.hpp diff --git a/org.lflang/core/src/main/resources/lib/cpp/lfutil.hh b/core/src/main/resources/lib/cpp/lfutil.hh similarity index 100% rename from org.lflang/core/src/main/resources/lib/cpp/lfutil.hh rename to core/src/main/resources/lib/cpp/lfutil.hh diff --git a/org.lflang/core/src/main/resources/lib/cpp/reactor-cpp b/core/src/main/resources/lib/cpp/reactor-cpp similarity index 100% rename from org.lflang/core/src/main/resources/lib/cpp/reactor-cpp rename to core/src/main/resources/lib/cpp/reactor-cpp diff --git a/org.lflang/core/src/main/resources/lib/cpp/time_parser.hh b/core/src/main/resources/lib/cpp/time_parser.hh similarity index 100% rename from org.lflang/core/src/main/resources/lib/cpp/time_parser.hh rename to core/src/main/resources/lib/cpp/time_parser.hh diff --git a/org.lflang/core/src/main/resources/lib/platform/zephyr/Kconfig b/core/src/main/resources/lib/platform/zephyr/Kconfig similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/zephyr/Kconfig rename to core/src/main/resources/lib/platform/zephyr/Kconfig diff --git a/org.lflang/core/src/main/resources/lib/platform/zephyr/boards/esp32.overlay b/core/src/main/resources/lib/platform/zephyr/boards/esp32.overlay similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/zephyr/boards/esp32.overlay rename to core/src/main/resources/lib/platform/zephyr/boards/esp32.overlay diff --git a/org.lflang/core/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf b/core/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf rename to core/src/main/resources/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf diff --git a/org.lflang/core/src/main/resources/lib/platform/zephyr/prj_lf.conf b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf similarity index 100% rename from org.lflang/core/src/main/resources/lib/platform/zephyr/prj_lf.conf rename to core/src/main/resources/lib/platform/zephyr/prj_lf.conf diff --git a/org.lflang/core/src/main/resources/lib/py/lf-python-support b/core/src/main/resources/lib/py/lf-python-support similarity index 100% rename from org.lflang/core/src/main/resources/lib/py/lf-python-support rename to core/src/main/resources/lib/py/lf-python-support diff --git a/org.lflang/core/src/main/resources/lib/rs/reactor-rs b/core/src/main/resources/lib/rs/reactor-rs similarity index 100% rename from org.lflang/core/src/main/resources/lib/rs/reactor-rs rename to core/src/main/resources/lib/rs/reactor-rs diff --git a/org.lflang/core/src/main/resources/lib/rs/runtime-version.properties b/core/src/main/resources/lib/rs/runtime-version.properties similarity index 100% rename from org.lflang/core/src/main/resources/lib/rs/runtime-version.properties rename to core/src/main/resources/lib/rs/runtime-version.properties diff --git a/org.lflang/core/src/main/resources/lib/ts/.eslintrc.json b/core/src/main/resources/lib/ts/.eslintrc.json similarity index 100% rename from org.lflang/core/src/main/resources/lib/ts/.eslintrc.json rename to core/src/main/resources/lib/ts/.eslintrc.json diff --git a/org.lflang/core/src/main/resources/lib/ts/README.md b/core/src/main/resources/lib/ts/README.md similarity index 100% rename from org.lflang/core/src/main/resources/lib/ts/README.md rename to core/src/main/resources/lib/ts/README.md diff --git a/org.lflang/core/src/main/resources/lib/ts/package.json b/core/src/main/resources/lib/ts/package.json similarity index 100% rename from org.lflang/core/src/main/resources/lib/ts/package.json rename to core/src/main/resources/lib/ts/package.json diff --git a/org.lflang/core/src/main/resources/lib/ts/tsconfig.json b/core/src/main/resources/lib/ts/tsconfig.json similarity index 100% rename from org.lflang/core/src/main/resources/lib/ts/tsconfig.json rename to core/src/main/resources/lib/ts/tsconfig.json diff --git a/org.lflang/core/src/main/resources/org/lflang/StringsBundle.properties b/core/src/main/resources/org/lflang/StringsBundle.properties similarity index 100% rename from org.lflang/core/src/main/resources/org/lflang/StringsBundle.properties rename to core/src/main/resources/org/lflang/StringsBundle.properties diff --git a/org.lflang/core/src/test/java/org/lflang/tests/LFParsingTest.java b/core/src/test/java/org/lflang/tests/LFParsingTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/LFParsingTest.java rename to core/src/test/java/org/lflang/tests/LFParsingTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/LfParsingUtil.java b/core/src/test/java/org/lflang/tests/LfParsingUtil.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/LfParsingUtil.java rename to core/src/test/java/org/lflang/tests/LfParsingUtil.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java b/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java rename to core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java b/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java rename to core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java b/core/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java rename to core/src/test/java/org/lflang/tests/compiler/LetInferenceTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java rename to core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java rename to core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java rename to core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java rename to core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java rename to core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java b/core/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java rename to core/src/test/java/org/lflang/tests/compiler/MixedRadixIntTest.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java b/core/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java rename to core/src/test/java/org/lflang/tests/compiler/PortInstanceTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/RangeTests.java b/core/src/test/java/org/lflang/tests/compiler/RangeTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/RangeTests.java rename to core/src/test/java/org/lflang/tests/compiler/RangeTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/RoundTripTests.java b/core/src/test/java/org/lflang/tests/compiler/RoundTripTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/RoundTripTests.java rename to core/src/test/java/org/lflang/tests/compiler/RoundTripTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java b/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java rename to core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java diff --git a/org.lflang/core/src/test/java/org/lflang/tests/util/StringUtilTest.java b/core/src/test/java/org/lflang/tests/util/StringUtilTest.java similarity index 100% rename from org.lflang/core/src/test/java/org/lflang/tests/util/StringUtilTest.java rename to core/src/test/java/org/lflang/tests/util/StringUtilTest.java diff --git a/org.lflang/core/src/testFixtures/java/org/lflang/tests/Configurators.java b/core/src/testFixtures/java/org/lflang/tests/Configurators.java similarity index 100% rename from org.lflang/core/src/testFixtures/java/org/lflang/tests/Configurators.java rename to core/src/testFixtures/java/org/lflang/tests/Configurators.java diff --git a/org.lflang/core/src/testFixtures/java/org/lflang/tests/LFTest.java b/core/src/testFixtures/java/org/lflang/tests/LFTest.java similarity index 100% rename from org.lflang/core/src/testFixtures/java/org/lflang/tests/LFTest.java rename to core/src/testFixtures/java/org/lflang/tests/LFTest.java diff --git a/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java similarity index 100% rename from org.lflang/core/src/testFixtures/java/org/lflang/tests/TestBase.java rename to core/src/testFixtures/java/org/lflang/tests/TestBase.java diff --git a/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestError.java b/core/src/testFixtures/java/org/lflang/tests/TestError.java similarity index 100% rename from org.lflang/core/src/testFixtures/java/org/lflang/tests/TestError.java rename to core/src/testFixtures/java/org/lflang/tests/TestError.java diff --git a/org.lflang/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java similarity index 100% rename from org.lflang/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java rename to core/src/testFixtures/java/org/lflang/tests/TestRegistry.java diff --git a/org.lflang/lsp/build.gradle b/lsp/build.gradle similarity index 100% rename from org.lflang/lsp/build.gradle rename to lsp/build.gradle diff --git a/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java b/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java similarity index 100% rename from org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java rename to lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServer.java diff --git a/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java b/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java similarity index 100% rename from org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java rename to lsp/src/main/java/org/lflang/diagram/lsp/LFLanguageServerExtension.java diff --git a/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java b/lsp/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java similarity index 100% rename from org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java rename to lsp/src/main/java/org/lflang/diagram/lsp/LanguageDiagramServer.java diff --git a/org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/Progress.java b/lsp/src/main/java/org/lflang/diagram/lsp/Progress.java similarity index 100% rename from org.lflang/lsp/src/main/java/org/lflang/diagram/lsp/Progress.java rename to lsp/src/main/java/org/lflang/diagram/lsp/Progress.java diff --git a/org.lflang/todo/log4j.xml b/todo/log4j.xml similarity index 100% rename from org.lflang/todo/log4j.xml rename to todo/log4j.xml From 4f76a43cebb1315ab95fe6695f0c4d95054e5724 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 10:24:21 +0200 Subject: [PATCH 618/709] adjust all path references --- build.gradle | 18 +++++++++--------- .../src/main/java/lfformat/LfFormatStep.java | 1 - cli/base/build.gradle | 2 +- cli/lfc/build.gradle | 4 ++-- .../org/lflang/cli/LfcIssueReportingTest.kt | 2 +- cli/lff/build.gradle | 4 ++-- core/build.gradle | 2 +- lsp/build.gradle | 2 +- settings.gradle | 2 +- test/README.md | 4 ++-- util/scripts/launch.ps1 | 4 ++-- util/scripts/launch.sh | 4 ++-- 12 files changed, 24 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index e4039064f0..473bfb60f7 100644 --- a/build.gradle +++ b/build.gradle @@ -29,8 +29,8 @@ spotless { } // Make the LF formatting task depend on lff -spotlessLinguaFranca.dependsOn('org.lflang:cli:lff:installDist') -spotlessLinguaFranca.inputs.files(tasks.getByPath('org.lflang:cli:lff:installDist').outputs) +spotlessLinguaFranca.dependsOn('cli:lff:installDist') +spotlessLinguaFranca.inputs.files(tasks.getByPath('cli:lff:installDist').outputs) distributions { clitools { @@ -41,8 +41,8 @@ distributions { distributionClassifier = 'nightly-' + formattedDate } contents { - from tasks.getByPath(':org.lflang:cli:lfc:installDist').outputs - from tasks.getByPath(':org.lflang:cli:lff:installDist').outputs + from tasks.getByPath('cli:lfc:installDist').outputs + from tasks.getByPath('cli:lff:installDist').outputs duplicatesStrategy = DuplicatesStrategy.EXCLUDE } } @@ -53,22 +53,22 @@ assemble.dependsOn('installDist') // Alias tasks for simpler access tasks.register('runLfc', JavaExec) { - dependsOn('org.lflang:cli:lfc:run') + dependsOn('cli:lfc:run') } tasks.register('runLff', JavaExec) { - dependsOn('org.lflang:cli:lff:run') + dependsOn('cli:lff:run') } tasks.register('targetTest') { if (!project.hasProperty('target')) { - def testFiles = rootProject.fileTree("${rootProject.rootDir}/org.lflang/core/src/integrationTest/java/org/lflang/tests/runtime").files + def testFiles = rootProject.fileTree("${rootProject.rootDir}/core/src/integrationTest/java/org/lflang/tests/runtime").files def targets = testFiles.collect {it.getName().substring(0, it.getName().length() - 9);} throw new GradleException("Please set the \'target\' project property using -Ptarget=<...>. You may chose any of $targets") } - finalizedBy('org.lflang:core:integrationTest') + finalizedBy('core:integrationTest') } tasks.register('singleTest') { if (System.getProperty('singleTest') == null) { throw new GradleException('Please set the \'singleTest\' system property using -DsingleTest=<...> to specify the LF test file that you would like to run.') } - finalizedBy('org.lflang:core:integrationTest') + finalizedBy('core:integrationTest') } diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 92489acbfc..b466dd702c 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -67,7 +67,6 @@ private static void initializeFormatter() throws IOException { if (formatter != null) return; final Path lffPath = Path.of( - "org.lflang", "cli", "lff", "build", diff --git a/cli/base/build.gradle b/cli/base/build.gradle index 74939fc8f5..895094fcad 100644 --- a/cli/base/build.gradle +++ b/cli/base/build.gradle @@ -6,5 +6,5 @@ plugins { dependencies { api "info.picocli:picocli:$picocliVersion" - api project(':org.lflang:core') + api project('core') } diff --git a/cli/lfc/build.gradle b/cli/lfc/build.gradle index 9af526e579..6a2d65f73c 100644 --- a/cli/lfc/build.gradle +++ b/cli/lfc/build.gradle @@ -4,9 +4,9 @@ plugins { } dependencies { - implementation project(':org.lflang:cli:base') + implementation project('cli:base') - testImplementation(testFixtures(project(":org.lflang:cli:base"))) + testImplementation(testFixtures(project("cli:base"))) } application { diff --git a/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt b/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt index 44a85a13df..c2839673be 100644 --- a/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt +++ b/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt @@ -120,7 +120,7 @@ class LfcIssueReportingTest { val packageName = loader.packageName.replace('.', '/') // relative to root of gradle project // TODO This should load the resources and copy them to a temp directory instead of reading directly - val basePath = "org.lflang/cli/lfc/src/test/resources/$packageName/" + val basePath = "cli/lfc/src/test/resources/$packageName/" val lfFile = Paths.get("$basePath/$fileBaseName.lf") val expectedPath = Paths.get("$basePath/$fileBaseName.stderr") diff --git a/cli/lff/build.gradle b/cli/lff/build.gradle index 65d35a21c2..ed44366e9b 100644 --- a/cli/lff/build.gradle +++ b/cli/lff/build.gradle @@ -3,9 +3,9 @@ plugins { } dependencies { - implementation project(':org.lflang:cli:base') + implementation project('cli:base') - testImplementation(testFixtures(project(":org.lflang:cli:base"))) + testImplementation(testFixtures(project("cli:base"))) testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" diff --git a/core/build.gradle b/core/build.gradle index 536bed337d..59b91d3674 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -104,7 +104,7 @@ tasks.register('getSubmoduleVersions', Exec) { outputs.file(outputFile) doLast { - def matcher = standardOutput.toString() =~ ~"(?m)^[-+ ]?([0-9a-f]+) org.lflang/core/src/main/resources/lib/\\w+/reactor-([-a-zA-Z]+)" + def matcher = standardOutput.toString() =~ ~"(?m)^[-+ ]?([0-9a-f]+) core/src/main/resources/lib/\\w+/reactor-([-a-zA-Z]+)" def properties = new StringBuilder() while (matcher.find()) { def rev = matcher.group(1) diff --git a/lsp/build.gradle b/lsp/build.gradle index 4ba85dbff1..8b8d043b1c 100644 --- a/lsp/build.gradle +++ b/lsp/build.gradle @@ -3,7 +3,7 @@ plugins { } dependencies { - implementation project(':org.lflang:core') + implementation project('core') implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:$klighdVersion") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' diff --git a/settings.gradle b/settings.gradle index 5c1d32d3eb..b7b8588ae0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ rootProject.name = 'org.lflang' -include(':org.lflang:core', ':org.lflang:lsp', ':org.lflang:cli:base', ':org.lflang:cli:lfc', ':org.lflang:cli:lff') +include('core', 'lsp', 'cli:base', 'cli:lfc', 'cli:lff') diff --git a/test/README.md b/test/README.md index e06450984d..ef6ec66001 100644 --- a/test/README.md +++ b/test/README.md @@ -12,7 +12,7 @@ You can specify any valid target. If you run the task without specifying the tar The `targetTest` task is essentially a convenient shortcut for the following: ``` -./gradew org.lflang:core:integrationTest --test org.lflang.tests.runtime.Test.* +./gradew core:integrationTest --test org.lflang.tests.runtime.Test.* ``` If you prefer have more control over which tests are executed, you can also use this more verbose version. @@ -25,7 +25,7 @@ It is also possible to run a subset of the tests. For example, the C tests are o To invoke only the C tests in the `concurrent` category, for example, do this: ``` -./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.runtime.CTest.runConcurrentTests +./gradlew core:integrationTest --tests org.lflang.tests.runtime.CTest.runConcurrentTests ``` To run a single test case, use the `singleTest` gradle task along with the path to the test source file: diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index 97d0afd3f3..be874fd26a 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -30,8 +30,8 @@ $gradlew="${base}/gradlew.bat" # invoke script if ($args.Length -eq 0) { - & "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" + & "${gradlew}" -p "${base}" "cli:${tool}:run" } else { $argsString = $args -join " " - & "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args="${argsString}" + & "${gradlew}" -p "${base}" "cli:${tool}:run" --args="${argsString}" } \ No newline at end of file diff --git a/util/scripts/launch.sh b/util/scripts/launch.sh index fc6dc83c6c..f1e685f288 100755 --- a/util/scripts/launch.sh +++ b/util/scripts/launch.sh @@ -71,7 +71,7 @@ gradlew="${base}/gradlew" # Launch the tool. if [ $# -eq 0 ]; then - "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" + "${gradlew}" -p "${base}" "cli:${tool}:run" else - "${gradlew}" -p "${base}" "org.lflang:cli:${tool}:run" --args="$*" + "${gradlew}" -p "${base}" "cli:${tool}:run" --args="$*" fi From bbff85341b5981900289154e5ac8224cda78320a Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 10:26:33 +0200 Subject: [PATCH 619/709] adjust CI path check again --- .github/workflows/check-diff.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index 29a2bd81b4..af14720136 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -36,10 +36,10 @@ jobs: - id: do run: | wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh - source check-diff.sh "org.lflang/core/src/main/java/org/lflang/generator/c\|/home/peter/lingua-franca/org.lflang/core/src/main/resources/lib/c\|org.lflang/core/src/main/resources/lib/platform\|test/C" C - source check-diff.sh "org.lflang/core/src/main/kotlin/org/lflang/generator/cpp\|org.lflang/core/src/main/resources/lib/cpp\|test/Cpp" CPP - source check-diff.sh "org.lflang/core/src/main/java/org/lflang/generator/python\|org.lflang/core/src/main/resources/lib/py\|test/Python" PY - source check-diff.sh "org.lflang/core/src/main/kotlin/org/lflang/generator/rust\|org.lflang/core/src/main/java/org/lflang/generator/rust\|org.lflang/core/src/main/resources/lib/rs\|test/Rust" RS - source check-diff.sh "org.lflang/core/src/main/kotlin/org/lflang/generator/ts\|org.lflang/core/src/main/java/org/lflang/generator/ts\|org.lflang/core/src/main/resources/lib/ts\|test/TypeScript" TS + source check-diff.sh "core/src/main/java/generator/c\|/home/peter/lingua-franca/core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C + source check-diff.sh "core/src/main/kotlin/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP + source check-diff.sh "core/src/main/java/generator/python\|core/src/main/resources/lib/py\|test/Python" PY + source check-diff.sh "core/src/main/kotlin/generator/rust\|core/src/main/java/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS + source check-diff.sh "core/src/main/kotlin/generator/ts\|core/src/main/java/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS source check-diff.sh "util/tracing" TRACING shell: bash From 695f0318fe0c99ac88f6d67cc2736d58fdd317fb Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 10:54:24 +0200 Subject: [PATCH 620/709] fix project refs --- cli/base/build.gradle | 2 +- cli/lfc/build.gradle | 4 ++-- cli/lff/build.gradle | 4 ++-- lsp/build.gradle | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/base/build.gradle b/cli/base/build.gradle index 895094fcad..8d3df08b02 100644 --- a/cli/base/build.gradle +++ b/cli/base/build.gradle @@ -6,5 +6,5 @@ plugins { dependencies { api "info.picocli:picocli:$picocliVersion" - api project('core') + api project(':core') } diff --git a/cli/lfc/build.gradle b/cli/lfc/build.gradle index 6a2d65f73c..4d2f423584 100644 --- a/cli/lfc/build.gradle +++ b/cli/lfc/build.gradle @@ -4,9 +4,9 @@ plugins { } dependencies { - implementation project('cli:base') + implementation project(':cli:base') - testImplementation(testFixtures(project("cli:base"))) + testImplementation(testFixtures(project(':cli:base'))) } application { diff --git a/cli/lff/build.gradle b/cli/lff/build.gradle index ed44366e9b..9f2269120c 100644 --- a/cli/lff/build.gradle +++ b/cli/lff/build.gradle @@ -3,9 +3,9 @@ plugins { } dependencies { - implementation project('cli:base') + implementation project(':cli:base') - testImplementation(testFixtures(project("cli:base"))) + testImplementation(testFixtures(project(':cli:base'))) testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" testImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion" diff --git a/lsp/build.gradle b/lsp/build.gradle index 8b8d043b1c..8895c7c7ed 100644 --- a/lsp/build.gradle +++ b/lsp/build.gradle @@ -3,7 +3,7 @@ plugins { } dependencies { - implementation project('core') + implementation project(':core') implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:$klighdVersion") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*' From 696bbb73c872f6ceec6c96765e499ba2e0240ea0 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:02:50 +0200 Subject: [PATCH 621/709] update gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a56607d25f..dcb7b5f75f 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,4 @@ gradle-app.setting ### xtext artifaccts *.jar -org.lflang/core/model/ \ No newline at end of file +core/model/ \ No newline at end of file From 49f3dd75e067fe754a795fdf35a4cd10dda50ba3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:03:05 +0200 Subject: [PATCH 622/709] enable parallel garbage collection --- gradle.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gradle.properties b/gradle.properties index 50b3771829..a1fd131d68 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,3 +23,6 @@ org.eclipse.lsp4j=lsp4jVersion org.opentest4j=openTest4jVersion org.eclipse.core.resources=resourcesVersion org.junit.jupiter=jupiterVersion + +[gradleProperties] +org.gradle.jvmargs="-XX:+UseParallelGC" \ No newline at end of file From 6ea2af85f47324db0b647263d121c54eccf55e71 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:14:40 +0200 Subject: [PATCH 623/709] fix paths in CI configuration --- .github/actions/build-rti-docker/build-rti-image.sh | 2 +- .github/actions/install-rti/install.sh | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/c-arduino-tests.yml | 4 ++-- .github/workflows/c-tests.yml | 4 ++-- .github/workflows/c-zephyr-tests.yml | 4 ++-- .github/workflows/cpp-ros2-tests.yml | 4 ++-- .github/workflows/cpp-tests.yml | 4 ++-- .github/workflows/lsp-tests.yml | 8 ++++---- .github/workflows/py-tests.yml | 6 +++--- .github/workflows/rs-tests.yml | 4 ++-- .github/workflows/serialization-tests.yml | 4 ++-- .github/workflows/ts-tests.yml | 2 +- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/actions/build-rti-docker/build-rti-image.sh b/.github/actions/build-rti-docker/build-rti-image.sh index a0d9d751aa..43933ba754 100755 --- a/.github/actions/build-rti-docker/build-rti-image.sh +++ b/.github/actions/build-rti-docker/build-rti-image.sh @@ -1,3 +1,3 @@ #!/bin/bash -cd org.lflang/src/lib/c/reactor-c/core/federated/RTI +cd src/lib/c/reactor-c/core/federated/RTI docker build -t rti:rti -f rti.Dockerfile ../../../ diff --git a/.github/actions/install-rti/install.sh b/.github/actions/install-rti/install.sh index 06ad67bb58..f3560f0529 100755 --- a/.github/actions/install-rti/install.sh +++ b/.github/actions/install-rti/install.sh @@ -1,5 +1,5 @@ #!/bin/bash -cd org.lflang/core/src/main/resources/lib/c/reactor-c/core/federated/RTI +cd core/src/main/resources/lib/c/reactor-c/core/federated/RTI mkdir build cd build if [[ "$OSTYPE" == "darwin"* ]]; then diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf8932fcc0..17bfe6edc4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,6 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco,org.lflang/cli/lfc/build/reports/xml/jacoco,org.lflang/cli/lff/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco,cli/lfc/build/reports/xml/jacoco,cli/lff/build/reports/xml/jacoco fail_ci_if_error: false verbose: true diff --git a/.github/workflows/c-arduino-tests.yml b/.github/workflows/c-arduino-tests.yml index 18d1a2962a..5b9e9a6213 100644 --- a/.github/workflows/c-arduino-tests.yml +++ b/.github/workflows/c-arduino-tests.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v3 with: repository: lf-lang/reactor-c - path: org.lflang/src/lib/c/reactor-c + path: core/src/main/resources/lib/c/reactor-c ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Install dependencies OS X @@ -69,7 +69,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index f072385183..956fb4c967 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v3 with: repository: lf-lang/reactor-c - path: org.lflang/src/lib/c/reactor-c + path: core/src/main/resources/lib/c/reactor-c ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Install dependencies OS X @@ -69,7 +69,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.compiler-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index a8854dfa25..94935ec09d 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -36,7 +36,7 @@ jobs: uses: actions/checkout@v3 with: repository: lf-lang/reactor-c - path: org.lflang/src/lib/c/reactor-c + path: core/src/main/resources/lib/c/reactor-c ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler @@ -48,7 +48,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/cpp-ros2-tests.yml b/.github/workflows/cpp-ros2-tests.yml index da5d98523d..416499c832 100644 --- a/.github/workflows/cpp-ros2-tests.yml +++ b/.github/workflows/cpp-ros2-tests.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v3 with: repository: lf-lang/reactor-cpp - path: org.lflang/src/lib/cpp/reactor-cpp + path: core/src/main/resources/lib/cpp/reactor-cpp ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Setup ROS2 @@ -41,7 +41,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/cpp-tests.yml b/.github/workflows/cpp-tests.yml index b4ad00e7f6..ef59f3a794 100644 --- a/.github/workflows/cpp-tests.yml +++ b/.github/workflows/cpp-tests.yml @@ -43,7 +43,7 @@ jobs: uses: actions/checkout@v2 with: repository: lf-lang/reactor-cpp - path: org.lflang/src/lib/cpp/reactor-cpp + path: core/src/main/resources/lib/cpp/reactor-cpp ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Run C++ tests; @@ -54,7 +54,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/lsp-tests.yml b/.github/workflows/lsp-tests.yml index 54d430fd9d..9d6e22e401 100644 --- a/.github/workflows/lsp-tests.yml +++ b/.github/workflows/lsp-tests.yml @@ -49,7 +49,7 @@ jobs: uses: actions/cache@v3.2.5 with: path: ~/.pnpm-store - key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('org.lflang/src/lib/ts/package.json') }} + key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('core/src/main/resources/lib/ts/package.json') }} - name: Setup Rust uses: ATiltedTree/setup-rust@v1 with: @@ -69,7 +69,7 @@ jobs: with: python-version: '3.10' - name: Run language server Python tests without PyLint - run: ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly + run: ./gradlew core:integrationTest --tests org.lflang.tests.lsp.LspTests.pythonValidationTestSyntaxOnly - name: Install pylint run: python3 -m pip install pylint if: ${{ runner.os != 'macOS' }} @@ -77,13 +77,13 @@ jobs: run: brew install pylint if: ${{ runner.os == 'macOS' }} - name: Run language server tests - run: ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.lsp.LspTests.*ValidationTest + run: ./gradlew core:integrationTest --tests org.lflang.tests.lsp.LspTests.*ValidationTest - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ runner.os == 'Linux' && inputs.all-platforms }} diff --git a/.github/workflows/py-tests.yml b/.github/workflows/py-tests.yml index 55a527d57c..85094a5c6a 100644 --- a/.github/workflows/py-tests.yml +++ b/.github/workflows/py-tests.yml @@ -49,14 +49,14 @@ jobs: uses: actions/checkout@v2 with: repository: lf-lang/reactor-c - path: org.lflang/src/lib/c/reactor-c + path: core/src/main/resources/lib/c/reactor-c ref: ${{ inputs.reactor-c-ref }} if: ${{ inputs.reactor-c-ref }} - name: Check out specific ref of reactor-c-py uses: actions/checkout@v2 with: repository: lf-lang/reactor-c-py - path: org.lflang/src/lib/py/reactor-c-py + path: core/src/main/resources/lib/py/reactor-c-py ref: ${{ inputs.reactor-c-py-ref }} if: ${{ inputs.reactor-c-py-ref }} - name: Run Python tests @@ -66,7 +66,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.compiler-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/rs-tests.yml b/.github/workflows/rs-tests.yml index b444ceaa4e..9f9c7d6a52 100644 --- a/.github/workflows/rs-tests.yml +++ b/.github/workflows/rs-tests.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v3 with: repository: lf-lang/reactor-rs - path: org.lflang/src/lib/rs/reactor-rs + path: core/src/main/resources/lib/rs/reactor-rs ref: ${{ inputs.runtime-ref }} if: inputs.runtime-ref - name: Update runtime ref if we use a custom runtime version @@ -70,7 +70,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.compiler-ref && runner.os == 'Linux' && inputs.all-platforms }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/serialization-tests.yml b/.github/workflows/serialization-tests.yml index 59aea0bb31..ed9cfb237a 100644 --- a/.github/workflows/serialization-tests.yml +++ b/.github/workflows/serialization-tests.yml @@ -31,13 +31,13 @@ jobs: - name: Run serialization tests; run: | source /opt/ros/*/setup.bash - ./gradlew org.lflang:core:integrationTest --tests org.lflang.tests.serialization.SerializationTest.* + ./gradlew core:integrationTest --tests org.lflang.tests.serialization.SerializationTest.* - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ !inputs.runtime-ref }} # i.e., if this is part of the main repo's CI diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 9253898eeb..863fb34d5e 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -39,7 +39,7 @@ jobs: - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: - files: org.lflang/core/build/reports/xml/jacoco + files: core/build/reports/xml/jacoco fail_ci_if_error: false verbose: true if: ${{ runner.os == 'Linux' && inputs.all-platforms }} From 354491987aadf0560fb9cbaedf7b10afa2173871 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:17:24 +0200 Subject: [PATCH 624/709] remove parallel garbage collection again as it does not work in CI --- gradle.properties | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index a1fd131d68..8d2599bdf6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,7 +22,4 @@ org.eclipse.xtext=xtextVersion org.eclipse.lsp4j=lsp4jVersion org.opentest4j=openTest4jVersion org.eclipse.core.resources=resourcesVersion -org.junit.jupiter=jupiterVersion - -[gradleProperties] -org.gradle.jvmargs="-XX:+UseParallelGC" \ No newline at end of file +org.junit.jupiter=jupiterVersion \ No newline at end of file From 1527804406789ac78347dd889549b4511026a4ce Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:20:46 +0200 Subject: [PATCH 625/709] move log4j configuration file to lsp resources --- {todo => lsp/src/main/resources}/log4j.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {todo => lsp/src/main/resources}/log4j.xml (100%) diff --git a/todo/log4j.xml b/lsp/src/main/resources/log4j.xml similarity index 100% rename from todo/log4j.xml rename to lsp/src/main/resources/log4j.xml From 479276390ba5f07b73b66225f77407a5bdc9acbe Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:34:55 +0200 Subject: [PATCH 626/709] delete bump version script --- util/scripts/bump-versions | 179 ------------------------------------- 1 file changed, 179 deletions(-) delete mode 100755 util/scripts/bump-versions diff --git a/util/scripts/bump-versions b/util/scripts/bump-versions deleted file mode 100755 index fd0200cc92..0000000000 --- a/util/scripts/bump-versions +++ /dev/null @@ -1,179 +0,0 @@ -#! /bin/python3 - -import os -from os.path import join, dirname, abspath - -# Usage: see below. -# -# @author Steven Wong -def usage(): - return '''bump-versions [-h] [-p PROP] [-t TARGET] [-a] - - update the version number in config.properties. - Then, run `bump-versions --all` to update for all targets (maven and manifest files). - - You can also specify a specific target and a specific property to update using `-t` and/or `-p` - ex. bump-versions -p xtextVersion -t maven - ''' - - -findPrintStyle = '%p:\\n' -replace = '\\n' -to = ' >>> ' -parentDir = dirname(dirname(abspath(__file__))) -manifestFind = parentDir -mavenFind = join(parentDir, 'pom.xml') -excluded = ['target', 'build'] - -class colors: - RED = '\033[31m' - ENDC = '\033[m' - GREEN = '\033[32m' - YELLOW = '\033[33m' - BLUE = '\033[34m' - PURPLE = '\033[35m' - -def main(args): - import configparser - config = configparser.RawConfigParser() - config.optionxform = str - config.read(join(parentDir, 'gradle.properties')) - props = dict(config.items('versions')).keys() - - if args["prop"]: - prop = args["prop"] - if prop not in props: - print(colors.RED + "ERROR" + colors.ENDC + f": property {prop} does not exist") - return - props = [prop] - - if args["all"] and args["target"]: - print(colors.RED + "ERROR" + colors.ENDC + f": --all and --target are mutually exclusive") - return - - targetLower = args["target"].lower() if args["target"] else "" - quiet = args["quiet"] - - if args["all"]: - updateManifestPackages(config, props, quiet) - updateMavenPackages(config, props, quiet) - elif targetLower == "maven": - updateMavenPackages(config, props, quiet) - elif targetLower == "manifest": - updateManifestPackages(config, props, quiet) - -def getInput(): - return input(colors.PURPLE + "The changes are printed to the screen. Enter [Y/y] to accept, [N/n] to reject, [Q/q] to skip: " + colors.ENDC).lower() - -def updateMavenPackages(config, props, quiet): - print(colors.GREEN + "Updating versions for >>> ./pom.xml" + colors.ENDC) - propertyNameToVersion = dict(config.items('versions')) - for prop in props: - print("[MAVEN] Updating version for variable: " + colors.GREEN + prop + colors.ENDC) - os.system(generateMavenViewCommand(prop, propertyNameToVersion[prop])) - c = '' - while c != 'y' and c != 'n': - c = 'y' if quiet else getInput() - print() - if c == 'y': - os.system(generateMavenReplaceCommand(prop, propertyNameToVersion[prop])) - elif c == 'q': - return - - -def updateManifestPackages(config, props, quiet): - print(colors.GREEN + "Updating versions for >>> manifest files" + colors.ENDC) - packageToPropertyName = dict(config.items('manifestPropertyNames')) - propertyNameToVersion = dict(config.items('versions')) - - for prop in props: - manifestPackages = [package for package, propertyName in packageToPropertyName.items() if prop == propertyName] - - if len(manifestPackages) == 0 or prop not in propertyNameToVersion: - print(colors.YELLOW + "WARNING" + colors.ENDC + f": Property '{prop}' does not exist for Manifest files.\n") - - for package in manifestPackages: - print("[MANIFEST] Updating version for package: " + colors.GREEN + package + colors.ENDC) - os.system(generateManifestViewCommand(package, propertyNameToVersion[prop])) - c = '' - while c != 'y' and c != 'n': - c = 'y' if quiet else getInput() - print() - if c == 'y': - os.system(generateManifestReplaceCommand(package, propertyNameToVersion[prop])) - elif c == 'q': - return - - -def excludeFromFind(): - return ' '.join(f'! -path \"**/{it}/**\"' for it in excluded) - - -def generateManifestViewCommand(matchName, version): - return f''' - find {manifestFind} -name *.MF {excludeFromFind()} -type f -printf '{findPrintStyle}' -exec sed -n '/{matchName}.*;bundle-version/{{ - h - s/="[^"][^"]*"/="{version}"/g - H - x - s/{replace}/{to}/ - w /dev/fd/2 - x - }}' {{}} \; - ''' - - -def generateManifestReplaceCommand(matchName, version): - return f''' - find {manifestFind} -name *.MF {excludeFromFind()} -type f -exec sed -i '/{matchName}.*;bundle-version/{{ - h - s/="[^"][^"]*"/="{version}"/g - }}' {{}} \; - ''' - -def generateMavenViewCommand(matchName, version): - return f''' - find {mavenFind} -printf '{findPrintStyle}' -exec sed -n '/<{matchName}>.*<\/{matchName}>/{{ - h - s/<{matchName}>.*<\/{matchName}>/<{matchName}>{version}<\/{matchName}>/g - H - x - s/{replace}/{to}/ - w /dev/fd/2 - x - }}' {{}} \; - ''' - - -def generateMavenReplaceCommand(matchName, version): - return f''' - find {mavenFind} -exec sed -i '/<{matchName}>.*<\/{matchName}>/{{ - h - s/<{matchName}>.*<\/{matchName}>/<{matchName}>{version}<\/{matchName}>/g - }}' {{}} \; - ''' - -if __name__ == '__main__': - import argparse - import sys - - parser = argparse.ArgumentParser(usage=usage()) - targetGroup = parser.add_mutually_exclusive_group(required=True) - - # Adding optional argument - parser.add_argument("-p", "--prop", help="version property to update") - parser.add_argument("-q", "--quiet", help="default accept all of the version changes", action="store_true") - targetGroup.add_argument("-t", "--target", help="target build application to update. Can be one of 'maven' or 'manifest' (case insensitive)") - targetGroup.add_argument("-a", "--all", help="update dependencies for all targets (maven and manifest files)", action="store_true") - - if len(sys.argv) == 1: - parser.print_help() - parser.exit() - - # Read arguments from command line - args = vars(parser.parse_args()) - - if 'all' not in args and 'target' not in args: - parser.print_help() - - main(args) From 379af0496c5acf06bf00771b9bdebf19df56757b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:35:06 +0200 Subject: [PATCH 627/709] fix typo --- test/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/README.md b/test/README.md index ef6ec66001..6725982dd0 100644 --- a/test/README.md +++ b/test/README.md @@ -30,7 +30,7 @@ To invoke only the C tests in the `concurrent` category, for example, do this: To run a single test case, use the `singleTest` gradle task along with the path to the test source file: ``` -./gradlew singleTest -DsingleTest test/C/src/Minimal.lf +./gradlew singleTest -DsingleTest=test/C/src/Minimal.lf ``` ### LSP tests From 939c77fbec5d6e3247af6d8d2c314f1a8ed14bb5 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:38:45 +0200 Subject: [PATCH 628/709] fix trace tool makefile --- util/tracing/makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/tracing/makefile b/util/tracing/makefile index 590eaa698f..03a19e7455 100644 --- a/util/tracing/makefile +++ b/util/tracing/makefile @@ -3,10 +3,10 @@ # @author: Edward A. Lee CC=gcc -CFLAGS=-I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/ \ - -I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/modal_models \ - -I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/platform \ - -I../../org.lflang/core/src/main/resources/lib/c/reactor-c/include/core/utils \ +CFLAGS=-I../../core/src/main/resources/lib/c/reactor-c/include/core/ \ + -I../../core/src/main/resources/lib/c/reactor-c/include/core/modal_models \ + -I../../core/src/main/resources/lib/c/reactor-c/include/core/platform \ + -I../../core/src/main/resources/lib/c/reactor-c/include/core/utils \ -DLF_UNTHREADED=1 \ -Wall DEPS= From b24ed0a1c0be60316ab8a37e2c28c9baf25758f0 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 11:43:35 +0200 Subject: [PATCH 629/709] add legacy gradle task and print informative error message --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 473bfb60f7..39f0eec059 100644 --- a/build.gradle +++ b/build.gradle @@ -72,3 +72,11 @@ tasks.register('singleTest') { } finalizedBy('core:integrationTest') } + +// Old deprecated tasks. +tasks.register('buildAll') { + throw new GradleException('The "buildAll" task was removed. Pleas use "./gradlew build" or "./gradlew assemble instead') +} +tasks.register('runSingleTestl') { + throw new GradleException('The "runSingleTest" task was removed. Pleas use "./gradlew singleTest -DsingleTest=testFile.lf" instead') +} From 2d2cfa7717d6375c7dce9787560e2b7d8a29deed Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 12:30:23 +0200 Subject: [PATCH 630/709] don't error when loading the dummy tasks --- build.gradle | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 39f0eec059..fd225f10e2 100644 --- a/build.gradle +++ b/build.gradle @@ -75,8 +75,12 @@ tasks.register('singleTest') { // Old deprecated tasks. tasks.register('buildAll') { - throw new GradleException('The "buildAll" task was removed. Pleas use "./gradlew build" or "./gradlew assemble instead') + doLast { + throw new GradleException('The "buildAll" task was removed. Pleas use "./gradlew build" or "./gradlew assemble instead') + } } tasks.register('runSingleTestl') { - throw new GradleException('The "runSingleTest" task was removed. Pleas use "./gradlew singleTest -DsingleTest=testFile.lf" instead') + doLast { + throw new GradleException('The "runSingleTest" task was removed. Pleas use "./gradlew singleTest -DsingleTest=testFile.lf" instead') + } } From ac5cd70e479a46d14d3b09cd8315c571aad040c1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 12:30:50 +0200 Subject: [PATCH 631/709] don't create 'tmp' directory in the project root --- .../java/org/lflang/tests/compiler/TargetConfigTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java b/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java index 51f813befc..8288d17876 100644 --- a/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java +++ b/core/src/test/java/org/lflang/tests/compiler/TargetConfigTests.java @@ -3,6 +3,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import java.nio.file.Files; +import java.nio.file.Path; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.xtext.generator.JavaIoFileSystemAccess; @@ -12,6 +13,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.lflang.federated.generator.FedFileConfig; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGenerator; @@ -64,7 +66,7 @@ public void testParsing() throws Exception { * @throws Exception */ @Test - public void testFederation() throws Exception { + public void testFederation(@TempDir Path tempDir) throws Exception { fileAccess.setOutputPath("src-gen"); Model federation = @@ -82,7 +84,7 @@ public void testFederation() throws Exception { b = new Foo() } """, - URI.createFileURI("tmp/src/Federation.lf"), + URI.createURI(tempDir.resolve("src/Federation.lf").toUri().toString()), resourceSetProvider.get()); assertHasTargetProperty(federation, "tracing"); From ca1d42870035f96b2596b83d096e788b8b7a099b Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 12:47:33 +0200 Subject: [PATCH 632/709] use gradle branch for benchmark CI runs --- .github/workflows/only-c.yml | 2 +- .github/workflows/only-cpp.yml | 2 +- .github/workflows/only-rs.yml | 2 +- .github/workflows/only-ts.yml | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 94f588c094..bb4752471b 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -26,7 +26,7 @@ jobs: # Run the C benchmark tests. benchmarking: if: ${{ inputs.all || github.event.pull_request.draft }} - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: 'C' diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index 54bd85a24f..daa8e3e847 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -19,7 +19,7 @@ jobs: # Run the C++ benchmark tests. cpp-benchmark-tests: if: ${{ inputs.all || github.event.pull_request.draft }} - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: 'Cpp' diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index d944a5bb2f..8b2173b10a 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -26,6 +26,6 @@ jobs: # Run the Rust benchmark tests. rs-benchmark-tests: if: ${{ inputs.all || github.event.pull_request.draft }} - uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: 'Rust' diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index 216b5bca9c..d3798d0f32 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -16,6 +16,13 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: + # Run the TypeScript benchmark tests. + benchmarking: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle + with: + target: 'TS' + # Run the TypeScript integration tests. ts-tests: if: ${{ inputs.all || github.event.pull_request.draft }} From 5bfca09a54a8780c84628fd9d28f15684f86242f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 13:05:59 +0200 Subject: [PATCH 633/709] add shadowJar task for lsp --- buildSrc/build.gradle | 2 ++ buildSrc/gradle.properties | 1 + lsp/build.gradle | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 09aca9525e..db34ac5c23 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -15,4 +15,6 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" implementation "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion" + + implementation "gradle.plugin.com.github.johnrengelman:shadow:$shadowJarVersion" } diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties index 149718da23..217c42b57c 100644 --- a/buildSrc/gradle.properties +++ b/buildSrc/gradle.properties @@ -2,3 +2,4 @@ spotlessVersion=6.11.0 spotlessLibVersion=2.30.0 kotlinVersion=1.6.21 +shadowJarVersion=7.1.2 \ No newline at end of file diff --git a/lsp/build.gradle b/lsp/build.gradle index 8895c7c7ed..772f618db1 100644 --- a/lsp/build.gradle +++ b/lsp/build.gradle @@ -1,5 +1,6 @@ plugins { id 'org.lflang.java-application-conventions' + id 'com.github.johnrengelman.shadow' } dependencies { @@ -14,3 +15,13 @@ dependencies { application { mainClass = 'org.lflang.diagram.lsp.LanguageDiagramServer' } + +shadowJar { + // Handling of service loader registrations via META-INF/services/* + mergeServiceFiles() + + // Merge properties + transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer) { + resource = 'plugin.properties' + } +} From e441ea709abf687143e59e61a4f299d8bea73014 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 1 Jun 2023 07:45:56 -0700 Subject: [PATCH 634/709] Fixed type for delay parameter --- test/C/src/lib/InternalDelay.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/lib/InternalDelay.lf b/test/C/src/lib/InternalDelay.lf index fbbf2f0cb6..5f49ad121e 100644 --- a/test/C/src/lib/InternalDelay.lf +++ b/test/C/src/lib/InternalDelay.lf @@ -1,6 +1,6 @@ target C -reactor InternalDelay(delay: int = 10 msec) { +reactor InternalDelay(delay: time = 10 msec) { input in: int output out: int logical action d: int From 75a05787135de68580d5186e4c63bd3748defac8 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 17:31:05 +0200 Subject: [PATCH 635/709] platform specific tests should inherit from TestBase If they are based on RuntimeTest, they will inherit all the standard test methods as well. --- .../java/org/lflang/tests/runtime/CArduinoTest.java | 3 ++- .../java/org/lflang/tests/runtime/CZephyrTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java index 95363fd30b..e9c2e9f4db 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java @@ -6,6 +6,7 @@ import org.lflang.Target; import org.lflang.tests.Configurators; import org.lflang.tests.RuntimeTest; +import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -13,7 +14,7 @@ * * @author Anirudh Rengarajan */ -public class CArduinoTest extends RuntimeTest { +public class CArduinoTest extends TestBase { public CArduinoTest() { super(Target.C); diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java index b29c2755d1..ffab2509b0 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java @@ -30,6 +30,7 @@ import org.lflang.Target; import org.lflang.tests.Configurators; import org.lflang.tests.RuntimeTest; +import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -37,7 +38,7 @@ * * @author Erling Rennemo Jellum */ -public class CZephyrTest extends RuntimeTest { +public class CZephyrTest extends TestBase { public CZephyrTest() { super(Target.C); From ccb22173fe4677a6185f4c3800110b9d65b09fd4 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 17:34:54 +0200 Subject: [PATCH 636/709] formatting --- .../java/org/lflang/tests/runtime/CArduinoTest.java | 1 - .../java/org/lflang/tests/runtime/CZephyrTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java index e9c2e9f4db..b8ae804a09 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; -import org.lflang.tests.RuntimeTest; import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java index ffab2509b0..82dfb4270e 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java @@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.Configurators; -import org.lflang.tests.RuntimeTest; import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; From 3481d98512c8a4586603cecf32192188f6d351c1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 1 Jun 2023 17:53:54 +0200 Subject: [PATCH 637/709] make sure that integration tests are not run in parallel Fixes https://github.com/lf-lang/lingua-franca/issues/567 --- .../src/main/groovy/org.lflang.test-conventions.gradle | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle index 40950e1832..00be562a02 100644 --- a/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.test-conventions.gradle @@ -48,6 +48,11 @@ test { showStandardStreams = true exceptionFormat "full" } + + maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 + failFast = true + workingDir = rootProject.projectDir + integrationTest { // Pass properties on to the Java VM systemProperty 'scheduler', System.getProperty('scheduler') @@ -73,11 +78,8 @@ test { failFast = true workingDir = rootProject.projectDir + maxParallelForks = 1 } - - maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 - failFast = true - workingDir = rootProject.projectDir } jacocoTestReport { From b725fa83b7814cb4692dd3f7a2a1ec650a9e1c30 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 10:26:20 -0700 Subject: [PATCH 638/709] Try again to pass all C tests. --- org.lflang.tests/src/org/lflang/tests/LFTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index 61b5dc2edf..a8afe78bc1 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -258,8 +258,9 @@ private Thread recordStream(StringBuilder builder, InputStream inputStream) { char[] buf = new char[1024]; while ((len = reader.read(buf)) > 0) { builder.append(buf, 0, len); - if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() / 2 ) { + if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() / 3) { builder.delete(0, builder.length() / 2); + builder.trimToSize(); } } } catch (IOException e) { From 4a4526f206510b83fbf844c1b0eab87fd0f55eb7 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 10:49:39 -0700 Subject: [PATCH 639/709] Update Rust runtime. --- org.lflang/src/lib/rs/reactor-rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index 28f9460724..4ac645947b 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit 28f9460724b266c263f4fdf8146b2029f4ff9d30 +Subproject commit 4ac645947bf7916a5e4c967207573b78aa2206f7 From 3b3c51775bacb8edfedf18dd3d8a52b638cd54ab Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 10:56:19 -0700 Subject: [PATCH 640/709] Address errors in LFTest.java. --- org.lflang.tests/src/org/lflang/tests/LFTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index a8afe78bc1..6cbadd7d69 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -258,7 +258,7 @@ private Thread recordStream(StringBuilder builder, InputStream inputStream) { char[] buf = new char[1024]; while ((len = reader.read(buf)) > 0) { builder.append(buf, 0, len); - if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() / 3) { + if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() * 3 / 4) { builder.delete(0, builder.length() / 2); builder.trimToSize(); } From 4b09250805e050765f8dd8a9b88e025aca03d2db Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 11:02:34 -0700 Subject: [PATCH 641/709] Format Python tests. --- test/Python/src/federated/DistributedStop.lf | 3 +-- test/Python/src/federated/DistributedStopZero.lf | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 3aacf893dc..c793b73e14 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -1,6 +1,5 @@ /** - * Test for request_stop() in federated execution with centralized - * coordination. + * Test for request_stop() in federated execution with centralized coordination. * * @author Soroush Bateni */ diff --git a/test/Python/src/federated/DistributedStopZero.lf b/test/Python/src/federated/DistributedStopZero.lf index aef9d94f53..8557af9889 100644 --- a/test/Python/src/federated/DistributedStopZero.lf +++ b/test/Python/src/federated/DistributedStopZero.lf @@ -1,6 +1,6 @@ /** - * Test for request_stop() in federated execution with centralized - * coordination at tag (0,0). + * Test for request_stop() in federated execution with centralized coordination + * at tag (0,0). * * @author Soroush Bateni */ From 8a442ee4d79f2282572a96e2eeddafb00b15e8cd Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 11:37:42 -0700 Subject: [PATCH 642/709] Try again to address error in LFTest.java. --- org.lflang.tests/src/org/lflang/tests/LFTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index 6cbadd7d69..fed9974d33 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -260,7 +260,6 @@ private Thread recordStream(StringBuilder builder, InputStream inputStream) { builder.append(buf, 0, len); if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() * 3 / 4) { builder.delete(0, builder.length() / 2); - builder.trimToSize(); } } } catch (IOException e) { From 627f88a0e1e0525c68ae50d5fc42907adcb50ef2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 12:16:14 -0700 Subject: [PATCH 643/709] Apply formatter. --- org.lflang.tests/src/org/lflang/tests/LFTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index fed9974d33..d2a9f255a1 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -258,7 +258,8 @@ private Thread recordStream(StringBuilder builder, InputStream inputStream) { char[] buf = new char[1024]; while ((len = reader.read(buf)) > 0) { builder.append(buf, 0, len); - if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() * 3 / 4) { + if (Runtime.getRuntime().freeMemory() + < Runtime.getRuntime().totalMemory() * 3 / 4) { builder.delete(0, builder.length() / 2); } } From 1c5f7e5e5d70fc58ae46b494a9278adbfabb5f4b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 1 Jun 2023 22:22:00 -0700 Subject: [PATCH 644/709] Add comment. --- .../src/org/lflang/generator/c/TypeParameterizedReactor.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java index 081d57336d..ff4d9d5162 100644 --- a/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/org.lflang/src/org/lflang/generator/c/TypeParameterizedReactor.java @@ -90,6 +90,10 @@ public InferredType resolveType(InferredType t) { return InferredType.fromAST(resolveType(t.astType)); } + /** + * Return a name that is unique to this TypeParameterizedReactor (up to structural equality) and + * that is prefixed with exactly one underscore and that does not contain any upper-case letters. + */ public String uniqueName() { String name = reactor.getName().toLowerCase(); if (uniqueNames.containsKey(this)) return uniqueNames.get(this); From b2c70d2ed199c50ea2be458080b4d7f60f1674ad Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 10:57:20 +0200 Subject: [PATCH 645/709] make sure not to produce errors when just loading the tasks --- build.gradle | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index fd225f10e2..a6aa3d6eef 100644 --- a/build.gradle +++ b/build.gradle @@ -59,16 +59,20 @@ tasks.register('runLff', JavaExec) { dependsOn('cli:lff:run') } tasks.register('targetTest') { - if (!project.hasProperty('target')) { - def testFiles = rootProject.fileTree("${rootProject.rootDir}/core/src/integrationTest/java/org/lflang/tests/runtime").files - def targets = testFiles.collect {it.getName().substring(0, it.getName().length() - 9);} - throw new GradleException("Please set the \'target\' project property using -Ptarget=<...>. You may chose any of $targets") + doLast { + if (!project.hasProperty('target')) { + def testFiles = rootProject.fileTree("${rootProject.rootDir}/core/src/integrationTest/java/org/lflang/tests/runtime").files + def targets = testFiles.collect { it.getName().substring(0, it.getName().length() - 9); } + throw new GradleException("Please set the \'target\' project property using -Ptarget=<...>. You may chose any of $targets") + } } finalizedBy('core:integrationTest') } tasks.register('singleTest') { - if (System.getProperty('singleTest') == null) { - throw new GradleException('Please set the \'singleTest\' system property using -DsingleTest=<...> to specify the LF test file that you would like to run.') + doLast { + if (System.getProperty('singleTest') == null) { + throw new GradleException('Please set the \'singleTest\' system property using -DsingleTest=<...> to specify the LF test file that you would like to run.') + } } finalizedBy('core:integrationTest') } From 4204deb35e503d069b55adb874064d143eb205a1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 11:21:27 +0200 Subject: [PATCH 646/709] fix rust runtime version --- core/src/main/resources/lib/rs/runtime-version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/rs/runtime-version.properties b/core/src/main/resources/lib/rs/runtime-version.properties index 35b335b731..2895d16bf7 100644 --- a/core/src/main/resources/lib/rs/runtime-version.properties +++ b/core/src/main/resources/lib/rs/runtime-version.properties @@ -1 +1 @@ -rs = 28f9460724b266c263f4fdf8146b2029f4ff9d30 +rs = 4ac645947bf7916a5e4c967207573b78aa2206f7 From 514a6848af759662e1ccce1f1d9411eb7b4cb093 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 12:41:57 +0200 Subject: [PATCH 647/709] test the gradle build on all platforms --- .github/workflows/all-misc.yml | 2 ++ .github/workflows/build.yml | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/all-misc.yml b/.github/workflows/all-misc.yml index d606cf31b8..1cef721867 100644 --- a/.github/workflows/all-misc.yml +++ b/.github/workflows/all-misc.yml @@ -25,6 +25,8 @@ jobs: building: if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/build.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Build the tools used for processing execution traces tracing: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17bfe6edc4..8ecd8d16f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,10 @@ on: required: false type: boolean default: false + all-platforms: + required: false + default: false + type: boolean secrets: envPAT: required: false @@ -14,7 +18,9 @@ on: jobs: build-toolchain: - runs-on: ubuntu-latest + strategy: + matrix: + platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} steps: - name: Check out lingua-franca repository uses: actions/checkout@v3 From e881351ad019c9a81be2439dca55ca7b52f465d5 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 13:44:12 +0200 Subject: [PATCH 648/709] fix build workflow --- .github/workflows/build.yml | 1 + .github/workflows/non-target-specific-extended.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ecd8d16f3..5095a8bef9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,6 +21,7 @@ jobs: strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} + runs-on: ${{ matrix.platform }} steps: - name: Check out lingua-franca repository uses: actions/checkout@v3 diff --git a/.github/workflows/non-target-specific-extended.yml b/.github/workflows/non-target-specific-extended.yml index 065b5dbff8..465681d18d 100644 --- a/.github/workflows/non-target-specific-extended.yml +++ b/.github/workflows/non-target-specific-extended.yml @@ -21,6 +21,8 @@ jobs: building: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/build.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} # Build the tools used for processing execution traces tracing: From d5da5000756ff98224dd9bb465c55a3cc3df2547 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 14:34:17 +0200 Subject: [PATCH 649/709] use lff.bat on Windows --- buildSrc/src/main/java/lfformat/LfFormatStep.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index b466dd702c..fad30497b8 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -65,6 +65,7 @@ public String format(@SuppressWarnings("NullableProblems") String rawUnix, File /** Idempotently initialize the formatter. */ private static void initializeFormatter() throws IOException { if (formatter != null) return; + String lff = System.getProperty("os.name").startsWith("Windows") ? "lff.bat" : "lff"; final Path lffPath = Path.of( "cli", @@ -73,7 +74,7 @@ private static void initializeFormatter() throws IOException { "install", "lff", "bin", - "lff"); + lff); formatter = new ProcessBuilder( List.of( lffPath.toString(), From b62db0727cc691d577c094f518d2f3b6e640b99f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 15:24:37 +0200 Subject: [PATCH 650/709] fix strange Windows problem with long paths --- .../groovy/org.lflang.java-application-conventions.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle index 02cdc18df1..432ebacf1b 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-application-conventions.gradle @@ -9,3 +9,11 @@ tasks.withType(Tar) { compression = Compression.GZIP archiveExtension = 'tar.gz' } + +// Fix long path issue on Windows +// See https://github.com/gradle/gradle/issues/1989 +startScripts { + doLast { + windowsScript.text = windowsScript.text.replaceAll('set CLASSPATH=.*', 'set CLASSPATH=.;%APP_HOME%/lib/*') + } +} From c39b3f8ba8cf9f29e743abbdcbb2b79ccad74c20 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 15:53:32 +0200 Subject: [PATCH 651/709] Deal with Windows CLI formatting in help test --- cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 48946eba55..fd65ffad78 100644 --- a/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java +++ b/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java @@ -92,7 +92,8 @@ public void testHelpArg() { result -> { result.checkOk(); result.checkNoErrorOutput(); - result.checkStdOut(containsString("Usage: lfc")); + result.checkStdOut(containsString("Usage:")); + result.checkStdOut(containsString("lfc")); }); } From 15a4140fe1cd1f0428ee2dfc08f1dd81afc500b1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 2 Jun 2023 16:09:49 +0200 Subject: [PATCH 652/709] Also fix the Lff test --- cli/lff/src/test/java/org/lflang/cli/LffCliTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 e7523ce4fe..9610d5b69c 100644 --- a/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java +++ b/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java @@ -65,7 +65,8 @@ public void testHelpArg() { ExecutionResult result = lffTester.run("--help", "--version"); result.checkOk(); result.checkNoErrorOutput(); - result.checkStdOut(containsString("Usage: lff")); + result.checkStdOut(containsString("Usage:")); + result.checkStdOut(containsString("lff")); } @Test From 451fbc5036566811103981784c24706ad86e8094 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 2 Jun 2023 11:10:24 -0700 Subject: [PATCH 653/709] Update check-diff.sh. This is an attempt to address the issue of changes in master causing diffs to appear for files not touched by the current feature branch. --- .github/scripts/check-diff.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check-diff.sh b/.github/scripts/check-diff.sh index 9a84951079..c7bdda6d5f 100644 --- a/.github/scripts/check-diff.sh +++ b/.github/scripts/check-diff.sh @@ -1,5 +1,5 @@ changes() { - git diff --name-only --diff-filter=AMDR --cached origin/master + git diff --name-only HEAD $(git merge-base HEAD origin/master) } if changes | grep -q $1; then From bb76c0eeb47dda5a63b52f5f89a50e511266d9d4 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 2 Jun 2023 16:02:51 -0700 Subject: [PATCH 654/709] Bugfix in CI. --- .github/workflows/check-diff.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index af14720136..f714c3cd3e 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -36,7 +36,7 @@ jobs: - id: do run: | wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh - source check-diff.sh "core/src/main/java/generator/c\|/home/peter/lingua-franca/core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C + source check-diff.sh "core/src/main/java/generator/c\|core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C source check-diff.sh "core/src/main/kotlin/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP source check-diff.sh "core/src/main/java/generator/python\|core/src/main/resources/lib/py\|test/Python" PY source check-diff.sh "core/src/main/kotlin/generator/rust\|core/src/main/java/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS From 5334d4af95745342add2f93ebdea139e23694e46 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 2 Jun 2023 17:46:25 -0700 Subject: [PATCH 655/709] Go back to using StringBuffers. StringBuffers differ from StringBuilders mainly in that they are synchronized. It is not entirely clear to me where the concurrent accesses would be coming from since there is only one thread writing to this StringBuffer (right?) but it is one more thing to check. --- core/src/testFixtures/java/org/lflang/tests/LFTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/testFixtures/java/org/lflang/tests/LFTest.java b/core/src/testFixtures/java/org/lflang/tests/LFTest.java index d2a9f255a1..c38160150c 100644 --- a/core/src/testFixtures/java/org/lflang/tests/LFTest.java +++ b/core/src/testFixtures/java/org/lflang/tests/LFTest.java @@ -226,7 +226,7 @@ public static final class ExecutionLogger { /** * String buffer used to record the standard output and error streams from the input process. */ - StringBuilder buffer = new StringBuilder(); + StringBuffer buffer = new StringBuffer(); /** * Return a thread responsible for recording the standard output stream of the given process. A @@ -250,7 +250,7 @@ public Thread recordStdErr(Process process) { * @param builder The builder to append to. * @param inputStream The stream to read from. */ - private Thread recordStream(StringBuilder builder, InputStream inputStream) { + private Thread recordStream(StringBuffer builder, InputStream inputStream) { return new Thread( () -> { try (Reader reader = new InputStreamReader(inputStream)) { From 5d1ed1d22e8f87e942753f5954d90f51c9a351ed Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 3 Jun 2023 09:53:36 -0700 Subject: [PATCH 656/709] Make uniqueName thread-safe. --- .../java/org/lflang/generator/c/TypeParameterizedReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ff4d9d5162..758e1ec6cf 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -94,7 +94,7 @@ public InferredType resolveType(InferredType t) { * Return a name that is unique to this TypeParameterizedReactor (up to structural equality) and * that is prefixed with exactly one underscore and that does not contain any upper-case letters. */ - public String uniqueName() { + public synchronized String uniqueName() { String name = reactor.getName().toLowerCase(); if (uniqueNames.containsKey(this)) return uniqueNames.get(this); if (nameCounts.containsKey(name)) { From 948986db4d6cf4c32575bf0f136d30623844e082 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 3 Jun 2023 06:18:57 -0700 Subject: [PATCH 657/709] Fixed makefile for installing fedsd and added to README. --- util/tracing/README.md | 3 +++ util/tracing/makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/util/tracing/README.md b/util/tracing/README.md index e430e47d7e..900405971a 100644 --- a/util/tracing/README.md +++ b/util/tracing/README.md @@ -14,6 +14,9 @@ directory. * trace\_to\_influxdb: A preliminary implementation that takes a binary trace file and uploads its data into [InfluxDB](https://en.wikipedia.org/wiki/InfluxDB). + +* fedsd: A utility that converts trace files from a federate into sequence diagrams + showing the interactions between federates and the RTI. ## Installing diff --git a/util/tracing/makefile b/util/tracing/makefile index 03a19e7455..f414f05ef3 100644 --- a/util/tracing/makefile +++ b/util/tracing/makefile @@ -28,7 +28,7 @@ install: trace_to_csv trace_to_chrome trace_to_influxdb mv trace_to_csv ../../bin mv trace_to_chrome ../../bin mv trace_to_influxdb ../../bin - ln -f -s ../utils/scripts/launch-fedsd.sh ../../bin/fedsd + ln -f -s ../util/scripts/launch-fedsd.sh ../../bin/fedsd chmod +x ../../bin/fedsd clean: From 59f944dc902e3b8b4a8e91fbdcea61ee9dca51e6 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 3 Jun 2023 12:36:00 -0700 Subject: [PATCH 658/709] Fix formatting --- util/tracing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tracing/README.md b/util/tracing/README.md index 900405971a..2e6f0cee4a 100644 --- a/util/tracing/README.md +++ b/util/tracing/README.md @@ -14,7 +14,7 @@ directory. * trace\_to\_influxdb: A preliminary implementation that takes a binary trace file and uploads its data into [InfluxDB](https://en.wikipedia.org/wiki/InfluxDB). - + * fedsd: A utility that converts trace files from a federate into sequence diagrams showing the interactions between federates and the RTI. From b9df840ad56b661460d19aa424dc956f52163d95 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 3 Jun 2023 15:57:48 -0700 Subject: [PATCH 659/709] Fix remaining conflict --- test/C/src/concurrent/DeadlineThreaded.lf | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index 2e7ccc074e..0639d1e709 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -55,13 +55,7 @@ reactor Destination(timeout: time = 1 sec) { } main reactor { -<<<<<<< HEAD s = new Source() - d = new Destination(timeout = 200 msec) + d = new Destination(timeout = 1 s) s.y -> d.x -======= - s = new Source() - d = new Destination(timeout = 1 s) - s.y -> d.x ->>>>>>> master } From 7eee6b967b83e64a8b3a17fef245deae41a95e49 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 3 Jun 2023 16:37:40 -0700 Subject: [PATCH 660/709] Fix formatting --- test/C/src/federated/STPParameter.lf | 77 +++++++++---------- test/C/src/generics/ParameterAsArgument.lf | 30 ++++---- test/C/src/generics/TypeCheck.lf | 58 +++++++------- test/C/src/zephyr/UserThreads.lf | 58 +++++++------- ...tributedCountDecentralizedLateHierarchy.lf | 67 ++++++++-------- 5 files changed, 140 insertions(+), 150 deletions(-) diff --git a/test/C/src/federated/STPParameter.lf b/test/C/src/federated/STPParameter.lf index 701974748d..97710dec50 100644 --- a/test/C/src/federated/STPParameter.lf +++ b/test/C/src/federated/STPParameter.lf @@ -1,59 +1,52 @@ target C { - timeout: 5 sec, - coordination: decentralized + timeout: 5 sec, + coordination: decentralized } import Count from "../lib/Count.lf" /** - * FIXME: inheritance not working! See issue #1733 import TestCount from - * "../lib/TestCount.lf" + * FIXME: inheritance not working! See issue #1733 import TestCount from "../lib/TestCount.lf" * - * reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { timer t(0, - * 1 sec); reaction(t) {= lf_print("Timer ticked at (%lld, %d).", - * lf_time_logical_elapsed(), lf_tag().microstep ); + * reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { timer t(0, 1 sec); reaction(t) + * {= lf_print("Timer ticked at (%lld, %d).", lf_time_logical_elapsed(), lf_tag().microstep ); * =} } */ -reactor PrintTimer( - STP_offset: time = 1 sec, - start: int = 1, - stride: int = 1, - num_inputs: int = 6 -) { - state count: int = start - state inputs_received: int = 0 - input in: int +reactor PrintTimer(STP_offset: time = 1 sec, start: int = 1, stride: int = 1, num_inputs: int = 6) { + state count: int = start + state inputs_received: int = 0 + input in: int - timer t(0, 1 sec) + timer t(0, 1 sec) - reaction(in) {= - lf_print("Received %d.", in->value); - if (in->value != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count += self->stride; - self->inputs_received++; - =} + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count += self->stride; + self->inputs_received++; + =} - reaction(shutdown) {= - lf_print("Shutdown invoked."); - if (self->inputs_received != self->num_inputs) { - lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", - self->num_inputs, - self->inputs_received - ); - } - =} - - reaction(t) {= - lf_print("Timer ticked at (%lld, %d).", - lf_time_logical_elapsed(), lf_tag().microstep + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", + self->num_inputs, + self->inputs_received ); - =} + } + =} + + reaction(t) {= + lf_print("Timer ticked at (%lld, %d).", + lf_time_logical_elapsed(), lf_tag().microstep + ); + =} } federated reactor { - c = new Count() - p = new PrintTimer() - c.out -> p.in + c = new Count() + p = new PrintTimer() + c.out -> p.in } diff --git a/test/C/src/generics/ParameterAsArgument.lf b/test/C/src/generics/ParameterAsArgument.lf index 65f91e0488..f6d460279e 100644 --- a/test/C/src/generics/ParameterAsArgument.lf +++ b/test/C/src/generics/ParameterAsArgument.lf @@ -1,27 +1,27 @@ target C reactor Child { - state k: T1 - input in: In - output out: Out + state k: T1 + input in: In + output out: Out - reaction(in) {= - int a = in->value; - printf("Got %d\n", a); - =} + reaction(in) {= + int a = in->value; + printf("Got %d\n", a); + =} } reactor Super { - input in: In - output out: Out - state t1: T1 - c = new Child() - in -> c.in - c.out -> out + input in: In + output out: Out + state t1: T1 + c = new Child() + in -> c.in + c.out -> out } main reactor { - cc = new Super() + cc = new Super() - reaction(startup) -> cc.in {= lf_set(cc.in, 42); =} + reaction(startup) -> cc.in {= lf_set(cc.in, 42); =} } diff --git a/test/C/src/generics/TypeCheck.lf b/test/C/src/generics/TypeCheck.lf index 3080af48ea..168430bbf6 100644 --- a/test/C/src/generics/TypeCheck.lf +++ b/test/C/src/generics/TypeCheck.lf @@ -1,44 +1,44 @@ /** Check that two reactors that use generics can be connected together. */ target C { - timeout: 3 sec, - fast: true + timeout: 3 sec, + fast: true } reactor Count(offset: time = 0, period: time = 1 sec) { - state count: int = 1 - output out: int - timer t(offset, period) + state count: int = 1 + output out: int + timer t(offset, period) - reaction(t) -> out {= lf_set(out, self->count++); =} + reaction(t) -> out {= lf_set(out, self->count++); =} } reactor TestCount(start: int = 1, num_inputs: int = 1) { - state count: int = start - state inputs_received: int = 0 - input in: T + state count: int = start + state inputs_received: int = 0 + input in: T - reaction(in) {= - lf_print("Received %d.", in->value); - if (in->value != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count++; - self->inputs_received++; - =} + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count++; + self->inputs_received++; + =} - reaction(shutdown) {= - lf_print("Shutdown invoked."); - if (self->inputs_received != self->num_inputs) { - lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", - self->num_inputs, - self->inputs_received - ); - } - =} + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", + self->num_inputs, + self->inputs_received + ); + } + =} } main reactor { - count = new Count() - testcount = new TestCount(num_inputs = 4) - count.out -> testcount.in + count = new Count() + testcount = new TestCount(num_inputs = 4) + count.out -> testcount.in } diff --git a/test/C/src/zephyr/UserThreads.lf b/test/C/src/zephyr/UserThreads.lf index 115d8114a7..5c19ce6d75 100644 --- a/test/C/src/zephyr/UserThreads.lf +++ b/test/C/src/zephyr/UserThreads.lf @@ -1,39 +1,39 @@ -// Test user threads platform option for Zephyr. The application should be able -// to create exactly three threads. +// Test user threads platform option for Zephyr. The application should be able to create exactly +// three threads. target C { - platform: { - name: Zephyr, - user-threads: 3 - }, - threading: true, - workers: 2 + platform: { + name: Zephyr, + user-threads: 3 + }, + threading: true, + workers: 2 } main reactor { - preamble {= - #include "platform.h" - void func(void* arg) { - lf_print("Hello from user thread"); - } + preamble {= + #include "platform.h" + void func(void* arg) { + lf_print("Hello from user thread"); + } - lf_thread_t thread_ids[4]; - =} + lf_thread_t thread_ids[4]; + =} - reaction(startup) {= - int res; + reaction(startup) {= + int res; - for (int i = 0; i < 3; i++) { - res = lf_thread_create(&thread_ids[i], &func, NULL); - if (res != 0) { - lf_print_error_and_exit("Could not create thread"); - } + for (int i = 0; i < 3; i++) { + res = lf_thread_create(&thread_ids[i], &func, NULL); + if (res != 0) { + lf_print_error_and_exit("Could not create thread"); } + } - res = lf_thread_create(&thread_ids[3], &func, NULL); - if (res == 0) { - lf_print_error_and_exit("Could create more threads than specified."); - } else { - printf("SUCCESS: Created exactly three user threads.\n"); - } - =} + res = lf_thread_create(&thread_ids[3], &func, NULL); + if (res == 0) { + lf_print_error_and_exit("Could create more threads than specified."); + } else { + printf("SUCCESS: Created exactly three user threads.\n"); + } + =} } diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf index 95e6453df0..b0159ceac2 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -16,44 +16,41 @@ import Count from "../lib/Count.lf" import Print from "DistributedCountDecentralizedLateDownstream.lf" reactor ImportantActuator { - input inp - # Count messages that arrive without STP violation. - state success = 0 - state success_stp_violation = 0 - # Force a timer to be invoked periodically - timer t(0, 10 usec) - # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + input inp + state success = 0 # Count messages that arrive without STP violation. + state success_stp_violation = 0 + timer t(0, 10 usec) # Force a timer to be invoked periodically + state c = 0 # to ensure logical time will advance in the absence of incoming messages. - reaction(inp) {= - current_tag = lf.tag() - print(f"ImportantActuator: At tag ({lf.tag().time}, {lf.tag().microstep}) received {inp.value}. " - f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") - if lf.tag() == Tag((SEC(1) * self.c) + + lf.time.start(), 0): - self.success += 1 # Message was on-time - else: - self.sys.stderr.write("Normal reaction was invoked, but current tag doesn't match expected tag.") - self.sys.exit(1) - self.c += 1 - =} STP(0) {= - current_tag = lf.tag() - print(f"ImportantActuator: At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), message has violated the STP offset " - f"by ({lf.tag().time - inp.intended_tag.time}, {lf.tag().microstep - inp.intended_tag.microstep}).") - self.success_stp_violation += 1 - self.c += 1 - =} + reaction(inp) {= + current_tag = lf.tag() + print(f"ImportantActuator: At tag ({lf.tag().time}, {lf.tag().microstep}) received {inp.value}. " + f"Intended tag is ({inp.intended_tag.time - lf.time.start()}, {inp.intended_tag.microstep}).") + if lf.tag() == Tag((SEC(1) * self.c) + + lf.time.start(), 0): + self.success += 1 # Message was on-time + else: + self.sys.stderr.write("Normal reaction was invoked, but current tag doesn't match expected tag.") + self.sys.exit(1) + self.c += 1 + =} STP(0) {= + current_tag = lf.tag() + print(f"ImportantActuator: At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), message has violated the STP offset " + f"by ({lf.tag().time - inp.intended_tag.time}, {lf.tag().microstep - inp.intended_tag.microstep}).") + self.success_stp_violation += 1 + self.c += 1 + =} - reaction(t) {= - # Do nothing. - =} + reaction(t) {= + # Do nothing. + =} - reaction(shutdown) {= - if (self.success + self.success_stp_violation) != 5: - self.sys.stderr.write("Failed to detect STP violation in messages.") - self.sys.exit(1) - else: - print(f"Successfully detected STP violations ({self.success_stp_violation} violations, {self.success} on-time).") - =} + reaction(shutdown) {= + if (self.success + self.success_stp_violation) != 5: + self.sys.stderr.write("Failed to detect STP violation in messages.") + self.sys.exit(1) + else: + print(f"Successfully detected STP violations ({self.success_stp_violation} violations, {self.success} on-time).") + =} } reactor Receiver { From c3e69e17645a16d981827f8a8ef07e85d732aac1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 3 Jun 2023 18:28:37 -0700 Subject: [PATCH 661/709] Make name mangling stateless again. The assignment of mangled names is too complex when compiling several distinct programs in the same JAR execution because it causes them to interact with each other by changing the number of reactors that have the same name. We can patch this up, but it is safer and easier to just eliminate the global variables. It will make the generated code uglier, but maybe life is too short to worry about that. --- .../generator/c/TypeParameterizedReactor.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) 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 758e1ec6cf..a9be5739c5 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -18,9 +18,6 @@ */ public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { - private static final Map uniqueNames = new HashMap<>(); - private static final Map nameCounts = new HashMap<>(); - /** * Construct the TPR corresponding to the given instantiation which syntactically appears within * the definition corresponding to {@code parent}. @@ -94,18 +91,9 @@ public InferredType resolveType(InferredType t) { * Return a name that is unique to this TypeParameterizedReactor (up to structural equality) and * that is prefixed with exactly one underscore and that does not contain any upper-case letters. */ - public synchronized String uniqueName() { - String name = reactor.getName().toLowerCase(); - if (uniqueNames.containsKey(this)) return uniqueNames.get(this); - if (nameCounts.containsKey(name)) { - int currentCount = nameCounts.get(name); - nameCounts.put(name, currentCount + 1); - uniqueNames.put(this, "_" + name + currentCount); - return uniqueName(); - } - nameCounts.put(name, 1); - uniqueNames.put(this, "_" + name); - return uniqueName(); + public String uniqueName() { + var resolved = ASTUtils.toDefinition(reactor); + return "_" + resolved.getName().toLowerCase() + (typeArgs.hashCode() + resolved.eResource().getURI().hashCode() * 31); } @Override From c69f85ce600d7685d540905b6eb77d5f64fd03d7 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 3 Jun 2023 18:47:42 -0700 Subject: [PATCH 662/709] Bugfix. --- .../java/org/lflang/generator/c/TypeParameterizedReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a9be5739c5..77fee811e9 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -93,7 +93,7 @@ public InferredType resolveType(InferredType t) { */ public String uniqueName() { var resolved = ASTUtils.toDefinition(reactor); - return "_" + resolved.getName().toLowerCase() + (typeArgs.hashCode() + resolved.eResource().getURI().hashCode() * 31); + return ("_" + resolved.getName().toLowerCase() + (typeArgs.hashCode() + resolved.eResource().getURI().hashCode() * 31)).replace('-', '_'); } @Override From 932b8739ab60eea14d77a7a073abecaa05a189b1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 3 Jun 2023 20:18:36 -0700 Subject: [PATCH 663/709] Change uniqueName mechanism again. --- .../org/lflang/generator/c/CFileConfig.java | 30 ++++++++++++++++ .../org/lflang/generator/c/CGenerator.java | 1 + .../generator/c/TypeParameterizedReactor.java | 36 +++++++++++-------- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CFileConfig.java b/core/src/main/java/org/lflang/generator/c/CFileConfig.java index db9447a833..4ace643e91 100644 --- a/core/src/main/java/org/lflang/generator/c/CFileConfig.java +++ b/core/src/main/java/org/lflang/generator/c/CFileConfig.java @@ -1,12 +1,20 @@ package org.lflang.generator.c; +import org.eclipse.emf.common.util.URI; import java.io.IOException; import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.eclipse.emf.ecore.resource.Resource; import org.lflang.FileConfig; +import org.lflang.ast.ASTUtils; +import org.lflang.lf.Reactor; +import org.lflang.lf.ReactorDecl; public class CFileConfig extends FileConfig { private final Path includePath; + private Map> nameMap; public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { @@ -20,6 +28,28 @@ public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchic .resolve(srcFile.getFileName().toString().split("\\.")[0]); } + public void setNameMap(List reactors) { + Map countMap = new HashMap<>(); + assert nameMap == null; + nameMap = new HashMap<>(); + for (var reactor : reactors) { + var def = ASTUtils.toDefinition(reactor); + if (nameMap.containsKey(def.getName())) { + nameMap.get(def.getName()).put(def.eResource().getURI(), countMap.get(def.getName())); + countMap.put(def.getName(), countMap.get(def.getName())); + } else { + nameMap.put(def.getName(), new HashMap<>()); + nameMap.get(def.getName()).put(def.eResource().getURI(), 0); + countMap.put(def.getName(), 1); + } + } + } + + public String uniqueName(ReactorDecl decl) { + var name = decl.getName(); + return name + (nameMap.get(name).get(decl.eResource().getURI()) == 0 ? "" : nameMap.get(name)); + } + public Path getIncludePath() { return includePath; } 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 85b755e4a1..2a1562976d 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -319,6 +319,7 @@ protected CGenerator( DelayBodyGenerator delayBodyGenerator) { super(context); this.fileConfig = (CFileConfig) context.getFileConfig(); + fileConfig.setNameMap(reactors); this.CCppMode = CCppMode; this.types = types; this.cmakeGenerator = cmakeGenerator; 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 77fee811e9..1efaecec90 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -1,6 +1,7 @@ package org.lflang.generator.c; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.lflang.InferredType; @@ -9,15 +10,17 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.Reactor; import org.lflang.lf.Type; +import org.lflang.lf.TypeParm; /** * A reactor class combined with concrete type arguments bound to its type parameters. - * - * @param reactor The syntactic reactor class definition - * @param typeArgs The type arguments associated with this particular variant of the reactor class. */ -public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { - +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; + private final List typeParams; /** * Construct the TPR corresponding to the given instantiation which syntactically appears within * the definition corresponding to {@code parent}. @@ -27,19 +30,20 @@ public record TypeParameterizedReactor(Reactor reactor, Map typeAr * permitted instead of types in this TPR. */ public TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent) { - this( - ASTUtils.toDefinition(i.getReactorClass()), - addTypeArgs(i, ASTUtils.toDefinition(i.getReactorClass()), parent)); + reactor = ASTUtils.toDefinition(i.getReactorClass()); + var definition = ASTUtils.toDefinition(i.getReactorClass()); + typeParams = definition.getTypeParms().stream().map(TypeParm::getLiteral).toList(); + typeArgs = addTypeArgs(i, parent); } - private static Map addTypeArgs( - Instantiation instantiation, Reactor r, TypeParameterizedReactor parent) { + private Map addTypeArgs( + Instantiation instantiation, TypeParameterizedReactor parent) { HashMap ret = new HashMap<>(); if (instantiation.getTypeArgs() != null) { - for (int i = 0; i < r.getTypeParms().size(); i++) { + for (int i = 0; i < typeParams.size(); i++) { var arg = instantiation.getTypeArgs().get(i); ret.put( - r.getTypeParms().get(i).getLiteral(), parent == null ? arg : parent.resolveType(arg)); + typeParams.get(i), parent == null ? arg : parent.resolveType(arg)); } } return ret; @@ -91,9 +95,9 @@ public InferredType resolveType(InferredType t) { * Return a name that is unique to this TypeParameterizedReactor (up to structural equality) and * that is prefixed with exactly one underscore and that does not contain any upper-case letters. */ - public String uniqueName() { + public String uniqueName(CFileConfig fileConfig) { var resolved = ASTUtils.toDefinition(reactor); - return ("_" + resolved.getName().toLowerCase() + (typeArgs.hashCode() + resolved.eResource().getURI().hashCode() * 31)).replace('-', '_'); + return "_" + fileConfig.uniqueName(resolved) + typeParams.stream().map(it -> it + "_" + typeArgs.get(it)).collect(Collectors.joining("_")); } @Override @@ -107,4 +111,8 @@ public boolean equals(Object obj) { && reactor.equals(other.reactor) && typeArgs.equals(other.typeArgs); } + + public Reactor reactor() { + return reactor; + } } From cf8d0577335b2541af2115004330c524207e228d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 3 Jun 2023 21:19:50 -0700 Subject: [PATCH 664/709] Pass around the name assignments. --- core/src/main/java/org/lflang/ModelInfo.java | 4 +- .../synthesis/LinguaFrancaSynthesis.java | 4 +- .../federated/extensions/CExtension.java | 6 +-- .../federated/extensions/TSExtension.java | 4 +- .../federated/generator/FedGenerator.java | 2 +- .../org/lflang/generator/ReactorInstance.java | 24 ++++------ .../org/lflang/generator/c/CFileConfig.java | 23 ---------- .../org/lflang/generator/c/CGenerator.java | 5 +- .../generator/c/TypeParameterizedReactor.java | 46 ++++++++++++++++--- .../org/lflang/validation/LFValidator.java | 2 +- 10 files changed, 62 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/org/lflang/ModelInfo.java b/core/src/main/java/org/lflang/ModelInfo.java index 17ee7cfb76..db487c6308 100644 --- a/core/src/main/java/org/lflang/ModelInfo.java +++ b/core/src/main/java/org/lflang/ModelInfo.java @@ -108,12 +108,12 @@ public void update(Model model, ErrorReporter reporter) { var main = model.getReactors().stream().filter(it -> it.isMain() || it.isFederated()).findFirst(); if (main.isPresent()) { - var inst = new ReactorInstance(main.get(), reporter); + var inst = new ReactorInstance(main.get(), reporter, List.of()); // FIXME: This might work, but it breaks invariants. topLevelReactorInstances.add(inst); } else { model .getReactors() - .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter))); + .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter, List.of()))); // FIXME: This might work, but it breaks invariants. } // don't store the graph into a field, only the cycles. for (ReactorInstance top : topLevelReactorInstances) { diff --git a/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index 45f3342a0a..4858100ced 100644 --- a/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -303,7 +303,7 @@ public KNode transform(final Model model) { Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated); if (main != null) { - ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter()); + ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter(), List.of()); rootNode .getChildren() .addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>())); @@ -319,7 +319,7 @@ public KNode transform(final Model model) { for (Reactor reactor : model.getReactors()) { if (reactor == main) continue; ReactorInstance reactorInstance = - new ReactorInstance(reactor, new SynthesisErrorReporter()); + new ReactorInstance(reactor, new SynthesisErrorReporter(), List.of()); reactorNodes.addAll( createReactorNode( reactorInstance, 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 121cf5d817..687316815e 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -593,7 +593,7 @@ private String generateInitializeTriggers( var federatedReactor = FedASTUtils.findFederatedReactor(federate.instantiation.eResource()); var oldFederatedReactorName = federatedReactor.getName(); federatedReactor.setName(federate.name); - var main = new ReactorInstance(federatedReactor, errorReporter, 1); + var main = new ReactorInstance(federatedReactor, errorReporter, 1, List.of()); code.pr(CExtensionUtils.initializeTriggersForNetworkActions(federate, main)); code.pr(CExtensionUtils.initializeTriggerForControlReactions(main, main, federate)); federatedReactor.setName(oldFederatedReactorName); @@ -773,8 +773,8 @@ private String generateCodeForPhysicalActions( new ReactorInstance( FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, - 1); - var instance = new ReactorInstance(federateClass, main, errorReporter); + 1, List.of()); + var instance = new ReactorInstance(federateClass, main, errorReporter, List.of()); var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); var minDelay = TimeValue.MAX_VALUE; Output outputFound = null; 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 14df96afb5..57f6dc958d 100644 --- a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java @@ -159,8 +159,8 @@ private TimeValue getMinOutputDelay( new ReactorInstance( FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, - 1); - var instance = new ReactorInstance(federateClass, main, errorReporter); + 1, List.of()); + var instance = new ReactorInstance(federateClass, main, errorReporter, List.of()); var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); var minOutputDelay = TimeValue.MAX_VALUE; Output outputFound = null; diff --git a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java index 6656a489f8..0a83d880a4 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java +++ b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java @@ -481,7 +481,7 @@ private void replaceFederateConnectionsWithProxies(Reactor federation) { // to duplicate the rather complicated logic in that class. We specify a depth of 1, // so it only creates the reactors immediately within the top level, not reactors // that those contain. - ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter); + ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter, List.of()); for (ReactorInstance child : mainInstance.children) { for (PortInstance output : child.outputs) { diff --git a/core/src/main/java/org/lflang/generator/ReactorInstance.java b/core/src/main/java/org/lflang/generator/ReactorInstance.java index 9288744d65..b4a01665d6 100644 --- a/core/src/main/java/org/lflang/generator/ReactorInstance.java +++ b/core/src/main/java/org/lflang/generator/ReactorInstance.java @@ -1,5 +1,3 @@ -/** A data structure for a reactor instance. */ - /************* * Copyright (c) 2019-2022, The University of California at Berkeley. * @@ -91,8 +89,8 @@ public class ReactorInstance extends NamedInstance { * @param reactor The top-level reactor. * @param reporter The error reporter. */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), null, reporter, -1); + public ReactorInstance(Reactor reactor, ErrorReporter reporter, List reactors) { + this(ASTUtils.createInstantiation(reactor), null, reporter, -1, reactors); } /** @@ -103,8 +101,8 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter) { * @param reporter The error reporter. * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { - this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth); + public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth, List reactors) { + this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth, reactors); } /** @@ -115,8 +113,8 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth * @param parent The parent reactor instance. * @param reporter The error reporter. */ - public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { - this(ASTUtils.createInstantiation(reactor), parent, reporter, -1); + public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter, List reactors) { + this(ASTUtils.createInstantiation(reactor), parent, reporter, -1, reactors); } ////////////////////////////////////////////////////// @@ -790,12 +788,12 @@ protected void createWatchdogInstances() { * @param desiredDepth The depth to which to expand the hierarchy. */ public ReactorInstance( - Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth) { + Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth, List reactors) { super(definition, parent); this.reporter = reporter; this.reactorDeclaration = definition.getReactorClass(); this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - this.tpr = new TypeParameterizedReactor(definition, parent == null ? null : parent.tpr); + this.tpr = parent == null ? new TypeParameterizedReactor(definition, reactors) : new TypeParameterizedReactor(definition, parent.tpr); // check for recursive instantiation var currentParent = parent; @@ -845,7 +843,7 @@ public ReactorInstance( // Instantiate children for this reactor instance. // While doing this, assign an index offset to each. for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) { - var childInstance = new ReactorInstance(child, this, reporter, desiredDepth); + var childInstance = new ReactorInstance(child, this, reporter, desiredDepth, reactors); this.children.add(childInstance); } @@ -879,10 +877,6 @@ public ReactorInstance( } } - public TypeParameterizedReactor getTypeParameterizedReactor() { - return this.tpr; - } - ////////////////////////////////////////////////////// //// Private methods. diff --git a/core/src/main/java/org/lflang/generator/c/CFileConfig.java b/core/src/main/java/org/lflang/generator/c/CFileConfig.java index 4ace643e91..491c604222 100644 --- a/core/src/main/java/org/lflang/generator/c/CFileConfig.java +++ b/core/src/main/java/org/lflang/generator/c/CFileConfig.java @@ -14,7 +14,6 @@ public class CFileConfig extends FileConfig { private final Path includePath; - private Map> nameMap; public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { @@ -28,28 +27,6 @@ public CFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchic .resolve(srcFile.getFileName().toString().split("\\.")[0]); } - public void setNameMap(List reactors) { - Map countMap = new HashMap<>(); - assert nameMap == null; - nameMap = new HashMap<>(); - for (var reactor : reactors) { - var def = ASTUtils.toDefinition(reactor); - if (nameMap.containsKey(def.getName())) { - nameMap.get(def.getName()).put(def.eResource().getURI(), countMap.get(def.getName())); - countMap.put(def.getName(), countMap.get(def.getName())); - } else { - nameMap.put(def.getName(), new HashMap<>()); - nameMap.get(def.getName()).put(def.eResource().getURI(), 0); - countMap.put(def.getName(), 1); - } - } - } - - public String uniqueName(ReactorDecl decl) { - var name = decl.getName(); - return name + (nameMap.get(name).get(decl.eResource().getURI()) == 0 ? "" : nameMap.get(name)); - } - public Path getIncludePath() { return includePath; } 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 2a1562976d..47a65f65bf 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -319,7 +319,6 @@ protected CGenerator( DelayBodyGenerator delayBodyGenerator) { super(context); this.fileConfig = (CFileConfig) context.getFileConfig(); - fileConfig.setNameMap(reactors); this.CCppMode = CCppMode; this.types = types; this.cmakeGenerator = cmakeGenerator; @@ -849,7 +848,7 @@ private void generateReactorDefinitions() throws IOException { var generatedReactors = new LinkedHashSet(); if (this.main != null) { generateReactorChildren(this.main, generatedReactors); - generateReactorClass(this.main.getTypeParameterizedReactor()); + generateReactorClass(new TypeParameterizedReactor(this.mainDef, reactors)); } // do not generate code for reactors that are not instantiated } @@ -2096,7 +2095,7 @@ private void createMainReactorInstance() { if (this.mainDef != null) { if (this.main == null) { // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter); + this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter, reactors); var reactionInstanceGraph = this.main.assignLevels(); if (reactionInstanceGraph.nodeCount() > 0) { errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); 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 1efaecec90..6bb7d04b9f 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -3,14 +3,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableMap; +import org.eclipse.emf.common.util.URI; import org.lflang.InferredType; import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; -import org.lflang.lf.Instantiation; -import org.lflang.lf.Reactor; -import org.lflang.lf.Type; -import org.lflang.lf.TypeParm; +import org.lflang.lf.*; /** * A reactor class combined with concrete type arguments bound to its type parameters. @@ -21,6 +22,8 @@ public class TypeParameterizedReactor { /** The type arguments associated with this particular variant of the reactor class. */ private final Map typeArgs; private final List typeParams; + private final ImmutableMap> nameMap; + /** * Construct the TPR corresponding to the given instantiation which syntactically appears within * the definition corresponding to {@code parent}. @@ -30,10 +33,41 @@ public class TypeParameterizedReactor { * permitted instead of types in this TPR. */ public TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent) { + this(i, parent, parent.nameMap); + } + + public TypeParameterizedReactor(Instantiation i, List reactors) { + this(i, null, getNameMap(reactors)); + } + + private static Map> getNameMap(List reactors) { + Map> nameMap = new HashMap<>(); + Map countMap = new HashMap<>(); + for (var reactor : reactors) { + var def = ASTUtils.toDefinition(reactor); + if (nameMap.containsKey(def.getName())) { + nameMap.get(def.getName()).put(def.eResource().getURI(), countMap.get(def.getName())); + countMap.put(def.getName(), countMap.get(def.getName())); + } else { + nameMap.put(def.getName(), new HashMap<>()); + nameMap.get(def.getName()).put(def.eResource().getURI(), 0); + countMap.put(def.getName(), 1); + } + } + return nameMap; + } + + private String uniqueName(ReactorDecl decl) { + var name = decl.getName(); + return name + (Objects.requireNonNull(nameMap.get(name)).get(decl.eResource().getURI()) == 0 ? "" : nameMap.get(name)); + } + + private TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent, Map> nameMap) { reactor = ASTUtils.toDefinition(i.getReactorClass()); var definition = ASTUtils.toDefinition(i.getReactorClass()); typeParams = definition.getTypeParms().stream().map(TypeParm::getLiteral).toList(); typeArgs = addTypeArgs(i, parent); + this.nameMap = ImmutableMap.copyOf(nameMap); } private Map addTypeArgs( @@ -95,9 +129,9 @@ public InferredType resolveType(InferredType t) { * Return a name that is unique to this TypeParameterizedReactor (up to structural equality) and * that is prefixed with exactly one underscore and that does not contain any upper-case letters. */ - public String uniqueName(CFileConfig fileConfig) { + public String uniqueName() { var resolved = ASTUtils.toDefinition(reactor); - return "_" + fileConfig.uniqueName(resolved) + typeParams.stream().map(it -> it + "_" + typeArgs.get(it)).collect(Collectors.joining("_")); + return "_" + uniqueName(resolved) + typeParams.stream().map(it -> it + "_" + typeArgs.get(it)).collect(Collectors.joining("_")); } @Override diff --git a/core/src/main/java/org/lflang/validation/LFValidator.java b/core/src/main/java/org/lflang/validation/LFValidator.java index 7dd7a78f7a..d228a2dba6 100644 --- a/core/src/main/java/org/lflang/validation/LFValidator.java +++ b/core/src/main/java/org/lflang/validation/LFValidator.java @@ -221,7 +221,7 @@ private Type portTypeIfResolvable(VarRef port) { var portType = ((Port) port.getVariable()).getType(); return port.getContainer() == null ? portType - : new TypeParameterizedReactor(port.getContainer(), null).resolveType(portType); + : new TypeParameterizedReactor(port.getContainer(), List.of()).resolveType(portType); } @Check(CheckType.FAST) From 99d059239efb2961bc83ed173f6638da31b37de6 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 09:50:56 -0700 Subject: [PATCH 665/709] Fix CI. --- .github/workflows/check-diff.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index af14720136..3633344d5d 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -36,10 +36,10 @@ jobs: - id: do run: | wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh - source check-diff.sh "core/src/main/java/generator/c\|/home/peter/lingua-franca/core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C - source check-diff.sh "core/src/main/kotlin/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP - source check-diff.sh "core/src/main/java/generator/python\|core/src/main/resources/lib/py\|test/Python" PY - source check-diff.sh "core/src/main/kotlin/generator/rust\|core/src/main/java/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS - source check-diff.sh "core/src/main/kotlin/generator/ts\|core/src/main/java/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS + source check-diff.sh "core/src/main/java/org/lflang/generator/c\|core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C + source check-diff.sh "core/src/main/kotlin/org/lflang/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP + source check-diff.sh "core/src/main/java/org/lflang/generator/python\|core/src/main/resources/lib/py\|test/Python" PY + source check-diff.sh "core/src/main/kotlin/org/lflang/generator/rust\|core/src/main/java/org/lflang/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS + source check-diff.sh "core/src/main/kotlin/org/lflang/generator/ts\|core/src/main/java/org/lflang/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS source check-diff.sh "util/tracing" TRACING shell: bash From f30599a424a4205b8d67c6554382aa241ff11f00 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 09:59:25 -0700 Subject: [PATCH 666/709] Bugfix. --- .../java/org/lflang/generator/c/TypeParameterizedReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6bb7d04b9f..b0741babea 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -58,7 +58,7 @@ private static Map> getNameMap(List reactors) } private String uniqueName(ReactorDecl decl) { - var name = decl.getName(); + var name = decl.getName().toLowerCase(); return name + (Objects.requireNonNull(nameMap.get(name)).get(decl.eResource().getURI()) == 0 ? "" : nameMap.get(name)); } From 05ba9c5ad29ee370f9b09122bd8bc0efe2f07241 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 2 Jun 2023 17:16:28 -0700 Subject: [PATCH 667/709] Run all categories of C tests. I do not want to stop running tests when one category fails. I would also like to experiment with increasing the amount of parallelism. --- .github/workflows/c-tests.yml | 19 ++++++-- .github/workflows/only-c.yml | 87 ++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 956fb4c967..2bf7a3a371 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -20,9 +20,14 @@ on: required: false default: true type: boolean + selected-tests: + required: false + default: "" # "" means run all tests until failure + type: string jobs: regular-tests: + name: ${{ inputs.selected-tests }} strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} @@ -55,15 +60,23 @@ jobs: if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform tests for C target with default scheduler run: ./gradlew targetTest -Ptarget=C - if: ${{ !inputs.use-cpp && !inputs.scheduler }} + if: ${{ !inputs.use-cpp && !inputs.scheduler && inputs.selected-tests == '' }} - name: Perform tests for C target with specified scheduler (no LSP tests) run: | echo "Specified scheduler: ${{ inputs.scheduler }}" ./gradlew targetTest -Ptarget=C -Dscheduler=${{ inputs.scheduler }} - if: ${{ !inputs.use-cpp && inputs.scheduler }} + if: ${{ !inputs.use-cpp && inputs.scheduler && inputs.selected-tests == '' }} - name: Perform tests for CCpp target with default scheduler run: ./gradlew targetTest -Ptarget=CCpp - if: ${{ inputs.use-cpp && !inputs.scheduler }} + if: ${{ inputs.use-cpp && !inputs.scheduler && inputs.selected-tests == '' }} + - name: Perform tests for C target with default scheduler + run: ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CTest.${{ inputs.selected-tests }} + if: ${{ !inputs.use-cpp && !inputs.scheduler && inputs.selected-tests != '' }} + - name: Perform tests for C target with specified scheduler (no LSP tests) + run: | + echo "Specified scheduler: ${{ inputs.scheduler }}" + ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CTest.${{ inputs.selected-tests }} -Dscheduler=${{ inputs.scheduler }} + if: ${{ inputs.use-cpp && !inputs.scheduler && inputs.selected-tests != '' }} - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index bb4752471b..195624cedc 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -17,11 +17,96 @@ concurrency: jobs: # Run the C integration tests. - default: + default0: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runGenericTests + + default1: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runTargetSpecificTests + + default2: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runMultiportTests + + default3: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runTypeParameterTests + + default4: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runAsFederated + + default5: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runConcurrentTests + + default6: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runFederatedTests + + default7: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runModalTests + + default8: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runNoInliningTests + + default9: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runDockerTests + + default10: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runDockerFederatedTests + + default11: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runWithThreadingOff + + default12: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runEnclaveTests # Run the C benchmark tests. benchmarking: From 81f4b81e8ca8a10392c805ffcfb17f95fc854731 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 12:18:36 -0700 Subject: [PATCH 668/709] Fix capitalization issue. --- .../generator/c/TypeParameterizedReactor.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 b0741babea..ff0e0568bb 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -45,13 +45,14 @@ private static Map> getNameMap(List reactors) Map countMap = new HashMap<>(); for (var reactor : reactors) { var def = ASTUtils.toDefinition(reactor); - if (nameMap.containsKey(def.getName())) { - nameMap.get(def.getName()).put(def.eResource().getURI(), countMap.get(def.getName())); - countMap.put(def.getName(), countMap.get(def.getName())); + var name = def.getName().toLowerCase(); + if (nameMap.containsKey(name)) { + nameMap.get(name).put(def.eResource().getURI(), countMap.get(name)); + countMap.put(name, countMap.get(name)); } else { - nameMap.put(def.getName(), new HashMap<>()); - nameMap.get(def.getName()).put(def.eResource().getURI(), 0); - countMap.put(def.getName(), 1); + nameMap.put(name, new HashMap<>()); + nameMap.get(name).put(def.eResource().getURI(), 0); + countMap.put(name, 1); } } return nameMap; From d907fbc30975c5039da69474e50c841f9208ecb2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 13:31:47 -0700 Subject: [PATCH 669/709] Bugfix. --- .../java/org/lflang/generator/c/TypeParameterizedReactor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ff0e0568bb..9fa76d496d 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -60,7 +60,8 @@ private static Map> getNameMap(List reactors) private String uniqueName(ReactorDecl decl) { var name = decl.getName().toLowerCase(); - return name + (Objects.requireNonNull(nameMap.get(name)).get(decl.eResource().getURI()) == 0 ? "" : nameMap.get(name)); + var number = Objects.requireNonNull(nameMap.get(name)).get(decl.eResource().getURI()); + return name + (number == 0 ? "" : number); } private TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent, Map> nameMap) { From e5c178ddfa799b810101d1df5f71ff5de501e9b8 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 13:32:56 -0700 Subject: [PATCH 670/709] Run formatter. --- core/src/main/java/org/lflang/ModelInfo.java | 13 ++++++++++-- .../synthesis/LinguaFrancaSynthesis.java | 3 ++- .../federated/extensions/CExtension.java | 3 ++- .../federated/extensions/TSExtension.java | 3 ++- .../org/lflang/generator/ReactorInstance.java | 17 ++++++++++++---- .../org/lflang/generator/c/CFileConfig.java | 7 ------- .../org/lflang/generator/c/CGenerator.java | 3 ++- .../generator/c/TypeParameterizedReactor.java | 20 ++++++++++--------- 8 files changed, 43 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/lflang/ModelInfo.java b/core/src/main/java/org/lflang/ModelInfo.java index db487c6308..fd4e05d6d3 100644 --- a/core/src/main/java/org/lflang/ModelInfo.java +++ b/core/src/main/java/org/lflang/ModelInfo.java @@ -108,12 +108,21 @@ public void update(Model model, ErrorReporter reporter) { var main = model.getReactors().stream().filter(it -> it.isMain() || it.isFederated()).findFirst(); if (main.isPresent()) { - var inst = new ReactorInstance(main.get(), reporter, List.of()); // FIXME: This might work, but it breaks invariants. + var inst = + new ReactorInstance( + main.get(), + reporter, + List.of()); // FIXME: This might work, but it breaks invariants. topLevelReactorInstances.add(inst); } else { model .getReactors() - .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter, List.of()))); // FIXME: This might work, but it breaks invariants. + .forEach( + it -> + topLevelReactorInstances.add( + new ReactorInstance( + it, reporter, + List.of()))); // FIXME: This might work, but it breaks invariants. } // don't store the graph into a field, only the cycles. for (ReactorInstance top : topLevelReactorInstances) { diff --git a/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index 4858100ced..cbe57a34e6 100644 --- a/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -303,7 +303,8 @@ public KNode transform(final Model model) { Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated); if (main != null) { - ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter(), List.of()); + ReactorInstance reactorInstance = + new ReactorInstance(main, new SynthesisErrorReporter(), List.of()); rootNode .getChildren() .addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>())); 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 687316815e..d41dc823b3 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -773,7 +773,8 @@ private String generateCodeForPhysicalActions( new ReactorInstance( FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, - 1, List.of()); + 1, + List.of()); var instance = new ReactorInstance(federateClass, main, errorReporter, List.of()); var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); var minDelay = TimeValue.MAX_VALUE; 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 57f6dc958d..c04c6672d9 100644 --- a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java @@ -159,7 +159,8 @@ private TimeValue getMinOutputDelay( new ReactorInstance( FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, - 1, List.of()); + 1, + List.of()); var instance = new ReactorInstance(federateClass, main, errorReporter, List.of()); var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); var minOutputDelay = TimeValue.MAX_VALUE; diff --git a/core/src/main/java/org/lflang/generator/ReactorInstance.java b/core/src/main/java/org/lflang/generator/ReactorInstance.java index b4a01665d6..a793f39442 100644 --- a/core/src/main/java/org/lflang/generator/ReactorInstance.java +++ b/core/src/main/java/org/lflang/generator/ReactorInstance.java @@ -101,7 +101,8 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter, List re * @param reporter The error reporter. * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. */ - public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth, List reactors) { + public ReactorInstance( + Reactor reactor, ErrorReporter reporter, int desiredDepth, List reactors) { this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth, reactors); } @@ -113,7 +114,8 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth * @param parent The parent reactor instance. * @param reporter The error reporter. */ - public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter, List reactors) { + public ReactorInstance( + Reactor reactor, ReactorInstance parent, ErrorReporter reporter, List reactors) { this(ASTUtils.createInstantiation(reactor), parent, reporter, -1, reactors); } @@ -788,12 +790,19 @@ protected void createWatchdogInstances() { * @param desiredDepth The depth to which to expand the hierarchy. */ public ReactorInstance( - Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth, List reactors) { + Instantiation definition, + ReactorInstance parent, + ErrorReporter reporter, + int desiredDepth, + List reactors) { super(definition, parent); this.reporter = reporter; this.reactorDeclaration = definition.getReactorClass(); this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration); - this.tpr = parent == null ? new TypeParameterizedReactor(definition, reactors) : new TypeParameterizedReactor(definition, parent.tpr); + this.tpr = + parent == null + ? new TypeParameterizedReactor(definition, reactors) + : new TypeParameterizedReactor(definition, parent.tpr); // check for recursive instantiation var currentParent = parent; diff --git a/core/src/main/java/org/lflang/generator/c/CFileConfig.java b/core/src/main/java/org/lflang/generator/c/CFileConfig.java index 491c604222..db9447a833 100644 --- a/core/src/main/java/org/lflang/generator/c/CFileConfig.java +++ b/core/src/main/java/org/lflang/generator/c/CFileConfig.java @@ -1,16 +1,9 @@ package org.lflang.generator.c; -import org.eclipse.emf.common.util.URI; import java.io.IOException; import java.nio.file.Path; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.eclipse.emf.ecore.resource.Resource; import org.lflang.FileConfig; -import org.lflang.ast.ASTUtils; -import org.lflang.lf.Reactor; -import org.lflang.lf.ReactorDecl; public class CFileConfig extends FileConfig { private final Path includePath; 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 47a65f65bf..7bed894341 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -2095,7 +2095,8 @@ private void createMainReactorInstance() { if (this.mainDef != null) { if (this.main == null) { // Recursively build instances. - this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter, reactors); + this.main = + new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter, reactors); var reactionInstanceGraph = this.main.assignLevels(); if (reactionInstanceGraph.nodeCount() > 0) { errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); 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 9fa76d496d..ac2ce6572d 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -1,26 +1,24 @@ package org.lflang.generator.c; +import com.google.common.collect.ImmutableMap; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableMap; import org.eclipse.emf.common.util.URI; import org.lflang.InferredType; import org.lflang.ast.ASTUtils; import org.lflang.generator.CodeBuilder; import org.lflang.lf.*; -/** - * A reactor class combined with concrete type arguments bound to its type parameters. - */ +/** A reactor class combined with concrete type arguments bound to its type parameters. */ 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; + private final List typeParams; private final ImmutableMap> nameMap; @@ -64,7 +62,8 @@ private String uniqueName(ReactorDecl decl) { return name + (number == 0 ? "" : number); } - private TypeParameterizedReactor(Instantiation i, TypeParameterizedReactor parent, Map> nameMap) { + private TypeParameterizedReactor( + Instantiation i, TypeParameterizedReactor parent, Map> nameMap) { reactor = ASTUtils.toDefinition(i.getReactorClass()); var definition = ASTUtils.toDefinition(i.getReactorClass()); typeParams = definition.getTypeParms().stream().map(TypeParm::getLiteral).toList(); @@ -78,8 +77,7 @@ private Map addTypeArgs( if (instantiation.getTypeArgs() != null) { for (int i = 0; i < typeParams.size(); i++) { var arg = instantiation.getTypeArgs().get(i); - ret.put( - typeParams.get(i), parent == null ? arg : parent.resolveType(arg)); + ret.put(typeParams.get(i), parent == null ? arg : parent.resolveType(arg)); } } return ret; @@ -133,7 +131,11 @@ public InferredType resolveType(InferredType t) { */ public String uniqueName() { var resolved = ASTUtils.toDefinition(reactor); - return "_" + uniqueName(resolved) + typeParams.stream().map(it -> it + "_" + typeArgs.get(it)).collect(Collectors.joining("_")); + return "_" + + uniqueName(resolved) + + typeParams.stream() + .map(it -> it + "_" + typeArgs.get(it)) + .collect(Collectors.joining("_")); } @Override From 79fe178dd614ff6060fd0dc4c86601a510ea0dd2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 14:23:34 -0700 Subject: [PATCH 671/709] Dignify the "empty list of all reactors" hack. --- core/src/main/java/org/lflang/ModelInfo.java | 13 ++---------- .../synthesis/LinguaFrancaSynthesis.java | 5 ++--- .../federated/extensions/CExtension.java | 7 +++---- .../federated/extensions/TSExtension.java | 5 ++--- .../federated/generator/FedGenerator.java | 2 +- .../org/lflang/generator/ReactorInstance.java | 21 +++++++++++++------ .../generator/c/TypeParameterizedReactor.java | 2 +- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/lflang/ModelInfo.java b/core/src/main/java/org/lflang/ModelInfo.java index fd4e05d6d3..17ee7cfb76 100644 --- a/core/src/main/java/org/lflang/ModelInfo.java +++ b/core/src/main/java/org/lflang/ModelInfo.java @@ -108,21 +108,12 @@ public void update(Model model, ErrorReporter reporter) { var main = model.getReactors().stream().filter(it -> it.isMain() || it.isFederated()).findFirst(); if (main.isPresent()) { - var inst = - new ReactorInstance( - main.get(), - reporter, - List.of()); // FIXME: This might work, but it breaks invariants. + var inst = new ReactorInstance(main.get(), reporter); topLevelReactorInstances.add(inst); } else { model .getReactors() - .forEach( - it -> - topLevelReactorInstances.add( - new ReactorInstance( - it, reporter, - List.of()))); // FIXME: This might work, but it breaks invariants. + .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter))); } // don't store the graph into a field, only the cycles. for (ReactorInstance top : topLevelReactorInstances) { diff --git a/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index cbe57a34e6..45f3342a0a 100644 --- a/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/core/src/main/java/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -303,8 +303,7 @@ public KNode transform(final Model model) { Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated); if (main != null) { - ReactorInstance reactorInstance = - new ReactorInstance(main, new SynthesisErrorReporter(), List.of()); + ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter()); rootNode .getChildren() .addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>())); @@ -320,7 +319,7 @@ public KNode transform(final Model model) { for (Reactor reactor : model.getReactors()) { if (reactor == main) continue; ReactorInstance reactorInstance = - new ReactorInstance(reactor, new SynthesisErrorReporter(), List.of()); + new ReactorInstance(reactor, new SynthesisErrorReporter()); reactorNodes.addAll( createReactorNode( reactorInstance, 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 d41dc823b3..121cf5d817 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -593,7 +593,7 @@ private String generateInitializeTriggers( var federatedReactor = FedASTUtils.findFederatedReactor(federate.instantiation.eResource()); var oldFederatedReactorName = federatedReactor.getName(); federatedReactor.setName(federate.name); - var main = new ReactorInstance(federatedReactor, errorReporter, 1, List.of()); + var main = new ReactorInstance(federatedReactor, errorReporter, 1); code.pr(CExtensionUtils.initializeTriggersForNetworkActions(federate, main)); code.pr(CExtensionUtils.initializeTriggerForControlReactions(main, main, federate)); federatedReactor.setName(oldFederatedReactorName); @@ -773,9 +773,8 @@ private String generateCodeForPhysicalActions( new ReactorInstance( FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, - 1, - List.of()); - var instance = new ReactorInstance(federateClass, main, errorReporter, List.of()); + 1); + var instance = new ReactorInstance(federateClass, main, errorReporter); var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); var minDelay = TimeValue.MAX_VALUE; Output outputFound = null; 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 c04c6672d9..14df96afb5 100644 --- a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java @@ -159,9 +159,8 @@ private TimeValue getMinOutputDelay( new ReactorInstance( FedASTUtils.findFederatedReactor(federate.instantiation.eResource()), errorReporter, - 1, - List.of()); - var instance = new ReactorInstance(federateClass, main, errorReporter, List.of()); + 1); + var instance = new ReactorInstance(federateClass, main, errorReporter); var outputDelayMap = federate.findOutputsConnectedToPhysicalActions(instance); var minOutputDelay = TimeValue.MAX_VALUE; Output outputFound = null; diff --git a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java index 0a83d880a4..6656a489f8 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java +++ b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java @@ -481,7 +481,7 @@ private void replaceFederateConnectionsWithProxies(Reactor federation) { // to duplicate the rather complicated logic in that class. We specify a depth of 1, // so it only creates the reactors immediately within the top level, not reactors // that those contain. - ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter, List.of()); + ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter); for (ReactorInstance child : mainInstance.children) { for (PortInstance output : child.outputs) { diff --git a/core/src/main/java/org/lflang/generator/ReactorInstance.java b/core/src/main/java/org/lflang/generator/ReactorInstance.java index a793f39442..5a1fdf4b8d 100644 --- a/core/src/main/java/org/lflang/generator/ReactorInstance.java +++ b/core/src/main/java/org/lflang/generator/ReactorInstance.java @@ -91,6 +91,17 @@ public class ReactorInstance extends NamedInstance { */ public ReactorInstance(Reactor reactor, ErrorReporter reporter, List reactors) { this(ASTUtils.createInstantiation(reactor), null, reporter, -1, reactors); + assert !reactors.isEmpty(); + } + + /** + * Create a new instantiation hierarchy that starts with the given top-level reactor. + * + * @param reactor The top-level reactor. + * @param reporter The error reporter. + */ + public ReactorInstance(Reactor reactor, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), null, reporter, -1, List.of()); } /** @@ -101,9 +112,8 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter, List re * @param reporter The error reporter. * @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy. */ - public ReactorInstance( - Reactor reactor, ErrorReporter reporter, int desiredDepth, List reactors) { - this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth, reactors); + public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) { + this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth, List.of()); } /** @@ -114,9 +124,8 @@ public ReactorInstance( * @param parent The parent reactor instance. * @param reporter The error reporter. */ - public ReactorInstance( - Reactor reactor, ReactorInstance parent, ErrorReporter reporter, List reactors) { - this(ASTUtils.createInstantiation(reactor), parent, reporter, -1, reactors); + public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) { + this(ASTUtils.createInstantiation(reactor), parent, reporter, -1, List.of()); } ////////////////////////////////////////////////////// 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 ac2ce6572d..b026525e82 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -134,7 +134,7 @@ public String uniqueName() { return "_" + uniqueName(resolved) + typeParams.stream() - .map(it -> it + "_" + typeArgs.get(it)) + .map(it -> typeArgs.get(it).getId()) // FIXME: may be more than just an ID .collect(Collectors.joining("_")); } From 1e7313c871f0f12ee4f9ca6d856d6bd6eac24750 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 14:35:26 -0700 Subject: [PATCH 672/709] Add C generics tests to CI. --- .github/workflows/only-c.yml | 7 +++++++ .../java/org/lflang/tests/RuntimeTest.java | 10 ++++++++++ .../java/org/lflang/tests/runtime/CTest.java | 6 ++++++ .../testFixtures/java/org/lflang/tests/TestBase.java | 1 + 4 files changed, 24 insertions(+) diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 195624cedc..f632f43f17 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -108,6 +108,13 @@ jobs: all-platforms: ${{ !github.event.pull_request.draft }} selected-tests: runEnclaveTests + default13: + if: ${{ inputs.all || github.event.pull_request.draft }} + uses: ./.github/workflows/c-tests.yml + with: + all-platforms: ${{ !github.event.pull_request.draft }} + selected-tests: runGenericsTests + # Run the C benchmark tests. benchmarking: if: ${{ inputs.all || github.event.pull_request.draft }} diff --git a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java index 2dfd42d38b..663294ef43 100644 --- a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java @@ -63,6 +63,16 @@ public void runGenericTests() { false); } + @Test + public void runGenericsTests() { + runTestsForTargets( + Message.DESC_GENERICS, + TestCategory.GENERICS::equals, + Configurators::noChanges, + TestLevel.EXECUTION, + false); + } + @Test public void runTargetSpecificTests() { runTestsForTargets( diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java index 4902550661..87687e2376 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java @@ -66,6 +66,12 @@ public void runGenericTests() { super.runGenericTests(); } + @Test + @Override + public void runGenericsTests() { + super.runGenericsTests(); + } + @Test @Override public void runTargetSpecificTests() { diff --git a/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java index 9d419d5644..ebdab78b72 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestBase.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestBase.java @@ -140,6 +140,7 @@ public static class Message { /* Descriptions of collections of tests. */ public static final String DESC_SERIALIZATION = "Run serialization tests."; public static final String DESC_GENERIC = "Run generic tests."; + public static final String DESC_GENERICS = "Run generics tests."; public static final String DESC_TYPE_PARMS = "Run tests for reactors with type parameters."; public static final String DESC_MULTIPORT = "Run multiport tests."; public static final String DESC_AS_FEDERATED = "Run non-federated tests in federated mode."; From e3ea39b2d37b03e9cf613d6fd1537b14ee533521 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 15:20:59 -0700 Subject: [PATCH 673/709] Respond to suggestion that `build` be run always. --- .github/workflows/all-misc.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/all-misc.yml b/.github/workflows/all-misc.yml index 1cef721867..c4022d444d 100644 --- a/.github/workflows/all-misc.yml +++ b/.github/workflows/all-misc.yml @@ -23,7 +23,6 @@ jobs: # Test the Gradle build. building: - if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/build.yml with: all-platforms: ${{ !github.event.pull_request.draft }} @@ -32,8 +31,7 @@ jobs: tracing: if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-tracing == 1 }} uses: ./.github/workflows/build-trace-tools.yml - needs: - check-diff + needs: check-diff with: all-platforms: ${{ !github.event.pull_request.draft }} From 43073973eae2fe777b907570b65c4bedf4575be4 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 15:28:30 -0700 Subject: [PATCH 674/709] Update CONTRIBUTING.md. --- CONTRIBUTING.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a6065e254..4a7f948263 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,15 +76,50 @@ To address feedback from code review, implement changes and push to your feature ### Code style and formatting The Lingua Franca compiler is implemented in Java and Kotlin. The overarching advice is to use each language's most widely used idioms and conventions, which are fortunately very similar. The code base is shipped with a [Spotless](https://github.com/diffplug/spotless) configuration to check and enforce style compliance. Lingua Franca code (e.g., tests) in this repository is also automatically formatted via Spotless. + +#### Formatting + - To check that modified files are formatted correctly, run: + ``` ./gradlew spotlessCheck ``` + - To apply the changes recommended by the formatter, run: + ``` ./gradlew spotlessApply ``` +_Java code formatting in IntelliJ_ + +There is an [IntelliJ plugin](https://plugins.jetbrains.com/plugin/8527-google-java-format) for enforcing Google's Java +style guide. This plugin can be enabled by going to `File` > `Settings...` > `Plugins` > `MarketPlace` and searching for +`google-java-format`. Do not forget to update your VM options as +explained [here](https://github.com/google/google-java-format/blob/master/README.md#intellij-android-studio-and-other-jetbrains-ides) +and do not forget to enable the plugin by going +to `File` > `Settings...` > `google-java-format Settings` > `Enable google-java-format`. + +You can enable formatting on save by going to `File` > `Settings...` > `Tools` > `Actions on Save` > `Reformat Code`. If +you do this, you may choose to change the files formatted on save from "all file types" to just Java in order to avoid +unnecessary conflicts. + +_Lingua Franca code formatting in VS Code_ + +Formatting is provided by the Lingua Franca VS Code extension. + +You can enable formatting on save by going to `Settings` and searching for "format" and checking the box +`Editor: Format on Save`. This can be either a user-level or workspace-level setting. + +_Checking using Git hooks_ + +If you prefer not to use formatting on save but would still like to avoid committing unformatted code, you can add a +file `.git/hooks/pre-commit` with the contents: + +``` +./gradlew spotlessCheck +``` + #### General guidelines - _Do not copy-paste code._ If you want to reuse code, factor it out into a method and call it. - _Keep methods concise._ As a rule of thumb, a method should fit on your screen so that it can be read without scrolling. We impose no hard limit on method length, but anything above 40 lines should be considered for breaking up. From 4d6c8c83a390a75c4714513fa6244723c9f253e8 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 09:50:56 -0700 Subject: [PATCH 675/709] Fix CI. --- .github/workflows/check-diff.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index f714c3cd3e..3633344d5d 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -36,10 +36,10 @@ jobs: - id: do run: | wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh - source check-diff.sh "core/src/main/java/generator/c\|core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C - source check-diff.sh "core/src/main/kotlin/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP - source check-diff.sh "core/src/main/java/generator/python\|core/src/main/resources/lib/py\|test/Python" PY - source check-diff.sh "core/src/main/kotlin/generator/rust\|core/src/main/java/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS - source check-diff.sh "core/src/main/kotlin/generator/ts\|core/src/main/java/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS + source check-diff.sh "core/src/main/java/org/lflang/generator/c\|core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C + source check-diff.sh "core/src/main/kotlin/org/lflang/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP + source check-diff.sh "core/src/main/java/org/lflang/generator/python\|core/src/main/resources/lib/py\|test/Python" PY + source check-diff.sh "core/src/main/kotlin/org/lflang/generator/rust\|core/src/main/java/org/lflang/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS + source check-diff.sh "core/src/main/kotlin/org/lflang/generator/ts\|core/src/main/java/org/lflang/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS source check-diff.sh "util/tracing" TRACING shell: bash From 3105f2b54f1115bd739d714b9f750127ec1fdacc Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 16:03:04 -0700 Subject: [PATCH 676/709] Give reactor classes well-defined order. --- .../org/lflang/generator/c/TypeParameterizedReactor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 b026525e82..8938f5d763 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -1,6 +1,7 @@ package org.lflang.generator.c; import com.google.common.collect.ImmutableMap; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,7 +42,11 @@ public TypeParameterizedReactor(Instantiation i, List reactors) { private static Map> getNameMap(List reactors) { Map> nameMap = new HashMap<>(); Map countMap = new HashMap<>(); - for (var reactor : reactors) { + var sortedReactors = + reactors.stream() + .sorted(Comparator.comparing(a -> a.eResource().getURI().toString())) + .toList(); + for (var reactor : sortedReactors) { var def = ASTUtils.toDefinition(reactor); var name = def.getName().toLowerCase(); if (nameMap.containsKey(name)) { From 010e785f3f8e265f3030dc2d4ab3bb67ab39f77b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 16:43:43 -0700 Subject: [PATCH 677/709] Update CONTRIBUTING.md. --- CONTRIBUTING.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a7f948263..761cb6031a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -93,16 +93,11 @@ The Lingua Franca compiler is implemented in Java and Kotlin. The overarching ad _Java code formatting in IntelliJ_ -There is an [IntelliJ plugin](https://plugins.jetbrains.com/plugin/8527-google-java-format) for enforcing Google's Java -style guide. This plugin can be enabled by going to `File` > `Settings...` > `Plugins` > `MarketPlace` and searching for -`google-java-format`. Do not forget to update your VM options as -explained [here](https://github.com/google/google-java-format/blob/master/README.md#intellij-android-studio-and-other-jetbrains-ides) -and do not forget to enable the plugin by going -to `File` > `Settings...` > `google-java-format Settings` > `Enable google-java-format`. - -You can enable formatting on save by going to `File` > `Settings...` > `Tools` > `Actions on Save` > `Reformat Code`. If -you do this, you may choose to change the files formatted on save from "all file types" to just Java in order to avoid -unnecessary conflicts. +Follow the directions here to install the Spotless Gradle plugin. We are not currently aware of a way to run Spotless +automatically on file save, but it is possible to configure a keybinding. + +There is a [plugin](https://github.com/google/google-java-format) specifically for enforcing Google's style guide, but +we have found difficulty getting it to work properly. _Lingua Franca code formatting in VS Code_ From dcf7b4836d1e468881d07a031dfea8d38312cb5a Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 4 Jun 2023 23:47:38 -0700 Subject: [PATCH 678/709] Revert "Run all categories of C tests." This reverts commit 05ba9c5ad29ee370f9b09122bd8bc0efe2f07241. --- .github/workflows/c-tests.yml | 19 ++------ .github/workflows/only-c.yml | 87 +---------------------------------- 2 files changed, 4 insertions(+), 102 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 2bf7a3a371..956fb4c967 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -20,14 +20,9 @@ on: required: false default: true type: boolean - selected-tests: - required: false - default: "" # "" means run all tests until failure - type: string jobs: regular-tests: - name: ${{ inputs.selected-tests }} strategy: matrix: platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-latest"]') }} @@ -60,23 +55,15 @@ jobs: if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform tests for C target with default scheduler run: ./gradlew targetTest -Ptarget=C - if: ${{ !inputs.use-cpp && !inputs.scheduler && inputs.selected-tests == '' }} + if: ${{ !inputs.use-cpp && !inputs.scheduler }} - name: Perform tests for C target with specified scheduler (no LSP tests) run: | echo "Specified scheduler: ${{ inputs.scheduler }}" ./gradlew targetTest -Ptarget=C -Dscheduler=${{ inputs.scheduler }} - if: ${{ !inputs.use-cpp && inputs.scheduler && inputs.selected-tests == '' }} + if: ${{ !inputs.use-cpp && inputs.scheduler }} - name: Perform tests for CCpp target with default scheduler run: ./gradlew targetTest -Ptarget=CCpp - if: ${{ inputs.use-cpp && !inputs.scheduler && inputs.selected-tests == '' }} - - name: Perform tests for C target with default scheduler - run: ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CTest.${{ inputs.selected-tests }} - if: ${{ !inputs.use-cpp && !inputs.scheduler && inputs.selected-tests != '' }} - - name: Perform tests for C target with specified scheduler (no LSP tests) - run: | - echo "Specified scheduler: ${{ inputs.scheduler }}" - ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CTest.${{ inputs.selected-tests }} -Dscheduler=${{ inputs.scheduler }} - if: ${{ inputs.use-cpp && !inputs.scheduler && inputs.selected-tests != '' }} + if: ${{ inputs.use-cpp && !inputs.scheduler }} - name: Collect code coverage run: ./gradlew jacocoTestReport - name: Report to CodeCov diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index f632f43f17..993afee2b9 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -17,96 +17,11 @@ concurrency: jobs: # Run the C integration tests. - default0: + default: if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runGenericTests - - default1: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runTargetSpecificTests - - default2: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runMultiportTests - - default3: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runTypeParameterTests - - default4: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runAsFederated - - default5: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runConcurrentTests - - default6: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runFederatedTests - - default7: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runModalTests - - default8: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runNoInliningTests - - default9: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runDockerTests - - default10: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runDockerFederatedTests - - default11: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runWithThreadingOff - - default12: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runEnclaveTests default13: if: ${{ inputs.all || github.event.pull_request.draft }} From 65822907f54f109160d840d9be59ae83fb6ab582 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 5 Jun 2023 00:00:03 -0700 Subject: [PATCH 679/709] Revert another CI change. --- .github/workflows/only-c.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index 993afee2b9..bb4752471b 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -23,13 +23,6 @@ jobs: with: all-platforms: ${{ !github.event.pull_request.draft }} - default13: - if: ${{ inputs.all || github.event.pull_request.draft }} - uses: ./.github/workflows/c-tests.yml - with: - all-platforms: ${{ !github.event.pull_request.draft }} - selected-tests: runGenericsTests - # Run the C benchmark tests. benchmarking: if: ${{ inputs.all || github.event.pull_request.draft }} From 5b445caee067fd919a426270bef89a1526bbbd6d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 5 Jun 2023 09:56:08 -0700 Subject: [PATCH 680/709] Add JavaDoc. --- .../generator/c/TypeParameterizedReactor.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) 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 8938f5d763..f514141241 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -39,6 +39,10 @@ public TypeParameterizedReactor(Instantiation i, List reactors) { this(i, null, getNameMap(reactors)); } + /** + * Return a map from reactor names and URIs to integers such that no two reactor names with + * different URIs map to the same integer. + */ private static Map> getNameMap(List reactors) { Map> nameMap = new HashMap<>(); Map countMap = new HashMap<>(); @@ -61,23 +65,30 @@ private static Map> getNameMap(List reactors) return nameMap; } - private String uniqueName(ReactorDecl decl) { - var name = decl.getName().toLowerCase(); - var number = Objects.requireNonNull(nameMap.get(name)).get(decl.eResource().getURI()); + /** Return a name that is unique to the given {@code Reactor}. */ + private String uniqueName(Reactor def) { + var name = def.getName().toLowerCase(); + var number = Objects.requireNonNull(nameMap.get(name)).get(def.eResource().getURI()); return name + (number == 0 ? "" : number); } + /** + * Construct a {@code TypeParameterizedReactor} corresponding to the reactor class of the + * instantiation {@code i} within the parent {@code parent} and with the given mapping of + * definition names and URIs to integers. + */ private TypeParameterizedReactor( Instantiation i, TypeParameterizedReactor parent, Map> nameMap) { reactor = ASTUtils.toDefinition(i.getReactorClass()); var definition = ASTUtils.toDefinition(i.getReactorClass()); typeParams = definition.getTypeParms().stream().map(TypeParm::getLiteral).toList(); - typeArgs = addTypeArgs(i, parent); + typeArgs = addTypeArgs(i, parent, typeParams); this.nameMap = ImmutableMap.copyOf(nameMap); } - private Map addTypeArgs( - Instantiation instantiation, TypeParameterizedReactor parent) { + /** Return a mapping from type parameters to type arguments. */ + private static Map addTypeArgs( + Instantiation instantiation, TypeParameterizedReactor parent, List typeParams) { HashMap ret = new HashMap<>(); if (instantiation.getTypeArgs() != null) { for (int i = 0; i < typeParams.size(); i++) { From ba1268d32c390da278bf179237bef9fa0bce64f8 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 5 Jun 2023 10:08:52 -0700 Subject: [PATCH 681/709] Rename generic -> miscellaneous. The intent is to reduce confusion with the language feature "generics." --- .../java/org/lflang/tests/RuntimeTest.java | 6 +++--- .../java/org/lflang/tests/runtime/CTest.java | 4 ++-- .../java/org/lflang/tests/runtime/CZephyrTest.java | 6 +++--- .../java/org/lflang/tests/runtime/CppTest.java | 4 ++-- .../java/org/lflang/tests/runtime/PythonTest.java | 4 ++-- .../java/org/lflang/tests/runtime/TypeScriptTest.java | 4 ++-- core/src/testFixtures/java/org/lflang/tests/TestBase.java | 2 +- .../testFixtures/java/org/lflang/tests/TestRegistry.java | 8 ++++---- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java index 663294ef43..3ffe313dc2 100644 --- a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java @@ -54,10 +54,10 @@ protected boolean supportsDockerOption() { } @Test - public void runGenericTests() { + public void runMiscellaneousTests() { runTestsForTargets( - Message.DESC_GENERIC, - TestCategory.GENERIC::equals, + Message.DESC_MISCELLANEOUS, + TestCategory.MISCELLANEOUS::equals, Configurators::noChanges, TestLevel.EXECUTION, false); diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java index 87687e2376..bdd5ff2a3c 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java @@ -62,8 +62,8 @@ protected boolean supportsDockerOption() { @Test @Override - public void runGenericTests() { - super.runGenericTests(); + public void runMiscellaneousTests() { + super.runMiscellaneousTests(); } @Test diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java index 82dfb4270e..21f05cc8e0 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java @@ -56,12 +56,12 @@ public void buildZephyrTests() { } @Test - public void buildGenericTests() { + public void buildMiscellaneousTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor( List.of(Target.C), - Message.DESC_GENERIC, - TestCategory.GENERIC::equals, + Message.DESC_MISCELLANEOUS, + TestCategory.MISCELLANEOUS::equals, Configurators::makeZephyrCompatibleUnthreaded, TestLevel.BUILD, false); diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java index 20973189b9..e0b9d3cb6d 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java @@ -51,8 +51,8 @@ protected boolean supportsEnclaves() { @Test @Override - public void runGenericTests() { - super.runGenericTests(); + public void runMiscellaneousTests() { + super.runMiscellaneousTests(); } @Test diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java index 1c258b7481..aff34d6919 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java @@ -73,8 +73,8 @@ protected boolean supportsDockerOption() { @Test @Override - public void runGenericTests() { - super.runGenericTests(); + public void runMiscellaneousTests() { + super.runMiscellaneousTests(); } @Test diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java index 036211607a..a31b2a335b 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java @@ -31,8 +31,8 @@ protected boolean supportsFederatedExecution() { @Test @Override - public void runGenericTests() { - super.runGenericTests(); + public void runMiscellaneousTests() { + super.runMiscellaneousTests(); } @Test diff --git a/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java index ebdab78b72..d9062b15db 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestBase.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestBase.java @@ -139,7 +139,7 @@ public static class Message { /* Descriptions of collections of tests. */ public static final String DESC_SERIALIZATION = "Run serialization tests."; - public static final String DESC_GENERIC = "Run generic tests."; + public static final String DESC_MISCELLANEOUS = "Run miscellaneous tests."; public static final String DESC_GENERICS = "Run generics tests."; public static final String DESC_TYPE_PARMS = "Run tests for reactors with type parameters."; public static final String DESC_MULTIPORT = "Run multiport tests."; diff --git a/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java index 483448bd8f..3850c8d72f 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java @@ -118,9 +118,9 @@ public enum TestCategory { CONCURRENT(true), /** Test about enclaves */ ENCLAVE(false), - /** Generic tests, ie, tests that all targets are supposed to implement. */ - GENERIC(true), - /** Tests about generics, not to confuse with {@link #GENERIC}. */ + /** Miscellaneous tests, ie, tests that all targets are supposed to implement. */ + MISCELLANEOUS(true), + /** Tests about generics. */ GENERICS(true), /** Tests about multiports and banks of reactors. */ MULTIPORT(true), @@ -313,7 +313,7 @@ public static class TestDirVisitor extends SimpleFileVisitor { * @param srcBasePath The test sources directory */ public TestDirVisitor(ResourceSet rs, Target target, Path srcBasePath) { - stack.push(TestCategory.GENERIC); + stack.push(TestCategory.MISCELLANEOUS); this.rs = rs; this.target = target; this.srcBasePath = srcBasePath; From d8fe614e481926602641d1b012b04f95f7eaac30 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 5 Jun 2023 10:43:27 -0700 Subject: [PATCH 682/709] Rename miscellaneous -> basic. --- .../integrationTest/java/org/lflang/tests/RuntimeTest.java | 6 +++--- .../java/org/lflang/tests/runtime/CTest.java | 4 ++-- .../java/org/lflang/tests/runtime/CZephyrTest.java | 6 +++--- .../java/org/lflang/tests/runtime/CppTest.java | 4 ++-- .../java/org/lflang/tests/runtime/PythonTest.java | 4 ++-- .../java/org/lflang/tests/runtime/TypeScriptTest.java | 4 ++-- core/src/testFixtures/java/org/lflang/tests/TestBase.java | 2 +- .../testFixtures/java/org/lflang/tests/TestRegistry.java | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java index 3ffe313dc2..c4997293ec 100644 --- a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java @@ -54,10 +54,10 @@ protected boolean supportsDockerOption() { } @Test - public void runMiscellaneousTests() { + public void runBasicTests() { runTestsForTargets( - Message.DESC_MISCELLANEOUS, - TestCategory.MISCELLANEOUS::equals, + Message.DESC_BASIC, + TestCategory.BASIC::equals, Configurators::noChanges, TestLevel.EXECUTION, false); diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java index bdd5ff2a3c..8da7d6117d 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java @@ -62,8 +62,8 @@ protected boolean supportsDockerOption() { @Test @Override - public void runMiscellaneousTests() { - super.runMiscellaneousTests(); + public void runBasicTests() { + super.runBasicTests(); } @Test diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java index 21f05cc8e0..03e8b3664d 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java @@ -56,12 +56,12 @@ public void buildZephyrTests() { } @Test - public void buildMiscellaneousTests() { + public void buildBasicTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor( List.of(Target.C), - Message.DESC_MISCELLANEOUS, - TestCategory.MISCELLANEOUS::equals, + Message.DESC_BASIC, + TestCategory.BASIC::equals, Configurators::makeZephyrCompatibleUnthreaded, TestLevel.BUILD, false); diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java index e0b9d3cb6d..b284e8b7af 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java @@ -51,8 +51,8 @@ protected boolean supportsEnclaves() { @Test @Override - public void runMiscellaneousTests() { - super.runMiscellaneousTests(); + public void runBasicTests() { + super.runBasicTests(); } @Test diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java index aff34d6919..e1ffbd57b8 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java @@ -73,8 +73,8 @@ protected boolean supportsDockerOption() { @Test @Override - public void runMiscellaneousTests() { - super.runMiscellaneousTests(); + public void runBasicTests() { + super.runBasicTests(); } @Test diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java index a31b2a335b..8fb223fe07 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java @@ -31,8 +31,8 @@ protected boolean supportsFederatedExecution() { @Test @Override - public void runMiscellaneousTests() { - super.runMiscellaneousTests(); + public void runBasicTests() { + super.runBasicTests(); } @Test diff --git a/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java index d9062b15db..2067f87618 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestBase.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestBase.java @@ -139,7 +139,7 @@ public static class Message { /* Descriptions of collections of tests. */ public static final String DESC_SERIALIZATION = "Run serialization tests."; - public static final String DESC_MISCELLANEOUS = "Run miscellaneous tests."; + public static final String DESC_BASIC = "Run basic tests."; public static final String DESC_GENERICS = "Run generics tests."; public static final String DESC_TYPE_PARMS = "Run tests for reactors with type parameters."; public static final String DESC_MULTIPORT = "Run multiport tests."; diff --git a/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java index 3850c8d72f..bda0fabb1c 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java @@ -118,8 +118,8 @@ public enum TestCategory { CONCURRENT(true), /** Test about enclaves */ ENCLAVE(false), - /** Miscellaneous tests, ie, tests that all targets are supposed to implement. */ - MISCELLANEOUS(true), + /** Basic tests, i.e., tests that all targets are supposed to implement. */ + BASIC(true), /** Tests about generics. */ GENERICS(true), /** Tests about multiports and banks of reactors. */ @@ -313,7 +313,7 @@ public static class TestDirVisitor extends SimpleFileVisitor { * @param srcBasePath The test sources directory */ public TestDirVisitor(ResourceSet rs, Target target, Path srcBasePath) { - stack.push(TestCategory.MISCELLANEOUS); + stack.push(TestCategory.BASIC); this.rs = rs; this.target = target; this.srcBasePath = srcBasePath; From cae0d1e2ecf01a7a608fb5f2f02e950aea7594d7 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 5 Jun 2023 10:55:11 -0700 Subject: [PATCH 683/709] Try to pass Rust tests. --- .../java/org/lflang/tests/RuntimeTest.java | 13 +------------ .../java/org/lflang/tests/runtime/RustTest.java | 7 +++++++ .../java/org/lflang/tests/TestBase.java | 8 ++++---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java index c4997293ec..8f0ccdc8fd 100644 --- a/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java @@ -43,7 +43,7 @@ protected boolean supportsFederatedExecution() { return false; } - /** Whether to enable {@link #runTypeParameterTests()}. */ + /** Whether to enable {@link #runGenericsTests()}. */ protected boolean supportsGenericTypes() { return false; } @@ -93,17 +93,6 @@ public void runMultiportTests() { false); } - @Test - public void runTypeParameterTests() { - Assumptions.assumeTrue(supportsGenericTypes(), Message.NO_GENERICS_SUPPORT); - runTestsForTargets( - Message.DESC_TYPE_PARMS, - TestCategory.GENERICS::equals, - Configurators::noChanges, - TestLevel.EXECUTION, - false); - } - @Test public void runAsFederated() { Assumptions.assumeTrue(supportsFederatedExecution(), Message.NO_FEDERATION_SUPPORT); diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java index e41d358ac0..75c1de4e15 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java @@ -24,6 +24,7 @@ package org.lflang.tests.runtime; +import org.junit.jupiter.api.Test; import org.lflang.Target; import org.lflang.tests.RuntimeTest; @@ -34,6 +35,12 @@ public RustTest() { super(Target.Rust); } + @Test + @Override + public void runGenericsTests() { + super.runGenericsTests(); + } + @Override protected boolean supportsGenericTypes() { return true; diff --git a/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java index 2067f87618..c149c550c6 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestBase.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestBase.java @@ -517,10 +517,10 @@ private void execute(LFTest test) throws TestError { stderr.start(); stdout.start(); - - if (!p.waitFor(MAX_EXECUTION_TIME_SECONDS, TimeUnit.SECONDS)) { - stdout.interrupt(); - stderr.interrupt(); + var timeout = !p.waitFor(MAX_EXECUTION_TIME_SECONDS, TimeUnit.SECONDS); + stdout.interrupt(); + stderr.interrupt(); + if (timeout) { p.destroy(); throw new TestError(Result.TEST_TIMEOUT); } else { From e1b507575d808190092dee5a32cc0fa0b674a247 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 5 Jun 2023 14:00:34 -0700 Subject: [PATCH 684/709] Update CONTRIBUTING.md. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 761cb6031a..67ae3ec689 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -93,7 +93,7 @@ The Lingua Franca compiler is implemented in Java and Kotlin. The overarching ad _Java code formatting in IntelliJ_ -Follow the directions here to install the Spotless Gradle plugin. We are not currently aware of a way to run Spotless +Follow the directions [here](https://github.com/ragurney/spotless-intellij-gradle) to install the Spotless Gradle plugin. We are not currently aware of a way to run Spotless automatically on file save, but it is possible to configure a keybinding. There is a [plugin](https://github.com/google/google-java-format) specifically for enforcing Google's style guide, but From f83b563dcffd3eecbe8d8219787f2b5c0be21286 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 02:19:29 +0200 Subject: [PATCH 685/709] Remove odd mechanism for loading target generators dynamically (#1813) --- .../org/lflang/generator/LFGenerator.java | 128 ++++-------------- 1 file changed, 26 insertions(+), 102 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/LFGenerator.java b/core/src/main/java/org/lflang/generator/LFGenerator.java index f2881c9fb8..8427f165f6 100644 --- a/core/src/main/java/org/lflang/generator/LFGenerator.java +++ b/core/src/main/java/org/lflang/generator/LFGenerator.java @@ -2,8 +2,8 @@ import com.google.inject.Inject; import java.io.IOException; -import java.lang.reflect.Constructor; import java.nio.file.Path; +import java.util.Arrays; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.generator.AbstractGenerator; import org.eclipse.xtext.generator.IFileSystemAccess2; @@ -18,15 +18,17 @@ import org.lflang.federated.generator.FedGenerator; import org.lflang.generator.c.CFileConfig; import org.lflang.generator.c.CGenerator; +import org.lflang.generator.cpp.CppFileConfig; +import org.lflang.generator.cpp.CppGenerator; import org.lflang.generator.python.PyFileConfig; import org.lflang.generator.python.PythonGenerator; +import org.lflang.generator.rust.RustFileConfig; +import org.lflang.generator.rust.RustGenerator; +import org.lflang.generator.ts.TSFileConfig; +import org.lflang.generator.ts.TSGenerator; import org.lflang.scoping.LFGlobalScopeProvider; -/** - * Generates code from your model files on save. - * - *

    See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation - */ +/** Generates code from your model files on save. */ public class LFGenerator extends AbstractGenerator { @Inject private LFGlobalScopeProvider scopeProvider; @@ -35,19 +37,10 @@ public class LFGenerator extends AbstractGenerator { protected boolean generatorErrorsOccurred = false; /** - * Create a target-specific FileConfig object in Kotlin - * - *

    Since the CppFileConfig and TSFileConfig class are implemented in Kotlin, the classes are - * not visible from all contexts. If the RCA is run from within Eclipse via "Run as Eclipse - * Application", the Kotlin classes are unfortunately not available at runtime due to bugs in the - * Eclipse Kotlin plugin. (See - * https://stackoverflow.com/questions/68095816/is-ist-possible-to-build-mixed-kotlin-and-java-applications-with-a-recent-eclips) - * - *

    If the FileConfig class is found, this method returns an instance. Otherwise, it returns an - * Instance of FileConfig. + * Create a target-specific FileConfig object * * @return A FileConfig object in Kotlin if the class can be found. - * @throws IOException If the file config could not be created properly + * @throws RuntimeException If the file config could not be created properly */ public static FileConfig createFileConfig( Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) { @@ -55,51 +48,28 @@ public static FileConfig createFileConfig( final Target target = Target.fromDecl(ASTUtils.targetDecl(resource)); assert target != null; - // Since our Eclipse Plugin uses code injection via guice, we need to - // play a few tricks here so that FileConfig does not appear as an - // import. Instead, we look the class up at runtime and instantiate it if - // found. try { if (FedASTUtils.findFederatedReactor(resource) != null) { return new FedFileConfig(resource, srcGenBasePath, useHierarchicalBin); } - switch (target) { - case CCPP: - case C: - return new CFileConfig(resource, srcGenBasePath, useHierarchicalBin); - case Python: - return new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); - case CPP: - case Rust: - case TS: - String className = - "org.lflang.generator." - + target.packageName - + "." - + target.classNamePrefix - + "FileConfig"; - try { - return (FileConfig) - Class.forName(className) - .getDeclaredConstructor(Resource.class, Path.class, boolean.class) - .newInstance(resource, srcGenBasePath, useHierarchicalBin); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Exception instantiating " + className, e.getCause()); - } - default: - throw new RuntimeException( - "Could not find FileConfig implementation for target " + target); - } + + return switch (target) { + case CCPP, C -> new CFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case Python -> new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case CPP -> new CppFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case Rust -> new RustFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin); + }; } catch (IOException e) { throw new RuntimeException( - "Unable to create FileConfig object for target " + target + ": " + e.getStackTrace()); + "Unable to create FileConfig object for target " + + target + + ": " + + Arrays.toString(e.getStackTrace())); } } - /** - * Create a generator object for the given target. Returns null if the generator could not be - * created. - */ + /** Create a generator object for the given target. */ private GeneratorBase createGenerator(LFGeneratorContext context) { final Target target = Target.fromDecl(ASTUtils.targetDecl(context.getFileConfig().resource)); assert target != null; @@ -107,58 +77,12 @@ private GeneratorBase createGenerator(LFGeneratorContext context) { case C -> new CGenerator(context, false); case CCPP -> new CGenerator(context, true); case Python -> new PythonGenerator(context); - case CPP, TS, Rust -> createKotlinBaseGenerator(target, context); - // If no case matched, then throw a runtime exception. - default -> throw new RuntimeException("Unexpected target!"); + case CPP -> new CppGenerator(context, scopeProvider); + case TS -> new TSGenerator(context, scopeProvider); + case Rust -> new RustGenerator(context, scopeProvider); }; } - /** - * Create a code generator in Kotlin. - * - *

    Since the CppGenerator and TSGenerator class are implemented in Kotlin, the classes are not - * visible from all contexts. If the RCA is run from within Eclipse via "Run as Eclipse - * Application", the Kotlin classes are unfortunately not available at runtime due to bugs in the - * Eclipse Kotlin plugin. (See - * https://stackoverflow.com/questions/68095816/is-ist-possible-to-build-mixed-kotlin-and-java-applications-with-a-recent-eclips) - * In this case, the method returns null - * - * @return A Kotlin Generator object if the class can be found - */ - private GeneratorBase createKotlinBaseGenerator(Target target, LFGeneratorContext context) { - // Since our Eclipse Plugin uses code injection via guice, we need to - // play a few tricks here so that Kotlin FileConfig and - // Kotlin Generator do not appear as an import. Instead, we look the - // class up at runtime and instantiate it if found. - String classPrefix = - "org.lflang.generator." + target.packageName + "." + target.classNamePrefix; - try { - Class generatorClass = Class.forName(classPrefix + "Generator"); - Constructor ctor = - generatorClass.getDeclaredConstructor( - LFGeneratorContext.class, LFGlobalScopeProvider.class); - - return (GeneratorBase) ctor.newInstance(context, scopeProvider); - } catch (ReflectiveOperationException e) { - generatorErrorsOccurred = true; - context - .getErrorReporter() - .reportError( - "The code generator for the " - + target - + " target could not be found. " - + "This is likely because you built Epoch using " - + "Eclipse. The " - + target - + " code generator is written in Kotlin and, unfortunately, the plugin that" - + " Eclipse uses for compiling Kotlin code is broken. Please consider building" - + " Epoch using Maven.\n" - + "For step-by-step instructions, see: " - + "https://github.com/icyphy/lingua-franca/wiki/Running-Lingua-Franca-IDE-%28Epoch%29-with-Kotlin-based-Code-Generators-Enabled-%28without-Eclipse-Environment%29"); - return null; - } - } - @Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { final LFGeneratorContext lfContext; From ebed89e4f1206658334eabb566383fd4663379a7 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 6 Jun 2023 18:27:35 -0700 Subject: [PATCH 686/709] Fix workflow dispatch. In the version currently in master, these workflows are skipped when manually triggered. --- .github/workflows/only-c.yml | 3 ++- .github/workflows/only-cpp.yml | 3 ++- .github/workflows/only-py.yml | 13 +++++++------ .github/workflows/only-rs.yml | 3 ++- .github/workflows/only-ts.yml | 3 ++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index bb4752471b..b353474e94 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -5,6 +5,7 @@ on: workflow_call: inputs: all: + default: true type: boolean env: @@ -28,7 +29,7 @@ jobs: if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: - target: 'C' + target: "C" # Run the C Arduino integration tests. arduino: diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index daa8e3e847..d7b956742f 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -5,6 +5,7 @@ on: workflow_call: inputs: all: + default: true type: boolean env: @@ -21,7 +22,7 @@ jobs: if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: - target: 'Cpp' + target: "Cpp" # Run the C++ integration tests. cpp-tests: diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index be3aa2f0f8..f07a9ef7a0 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -5,6 +5,7 @@ on: workflow_call: inputs: all: + default: true type: boolean env: @@ -16,9 +17,9 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: - # Run the Python integration tests. - py-tests: - uses: ./.github/workflows/py-tests.yml - if: ${{ inputs.all || github.event.pull_request.draft }} - with: - all-platforms: ${{ !github.event.pull_request.draft }} + # Run the Python integration tests. + py-tests: + uses: ./.github/workflows/py-tests.yml + if: ${{ inputs.all || github.event.pull_request.draft }} + with: + all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 8b2173b10a..412f1395ba 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -5,6 +5,7 @@ on: workflow_call: inputs: all: + default: true type: boolean env: @@ -28,4 +29,4 @@ jobs: if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: - target: 'Rust' + target: "Rust" diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index d3798d0f32..c842c14023 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -5,6 +5,7 @@ on: workflow_call: inputs: all: + default: true type: boolean env: @@ -21,7 +22,7 @@ jobs: if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: - target: 'TS' + target: "TS" # Run the TypeScript integration tests. ts-tests: From 8ff0b093851e276948da0263b3cb9af2f9d0a489 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 6 Jun 2023 18:42:10 -0700 Subject: [PATCH 687/709] Fix workflow dispatch. The current behavior in master is that workflows are skipped when manually triggered. --- .github/workflows/all-targets.yml | 10 ---------- .github/workflows/only-c.yml | 9 --------- .github/workflows/only-cpp.yml | 7 ------- .github/workflows/only-py.yml | 5 ----- .github/workflows/only-rs.yml | 6 ------ .github/workflows/only-ts.yml | 6 ------ 6 files changed, 43 deletions(-) diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 092f5265a6..3768b37c50 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -23,36 +23,26 @@ jobs: c: uses: ./.github/workflows/only-c.yml - with: - all: true needs: check-diff if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-c == 1 }} cpp: uses: ./.github/workflows/only-cpp.yml - with: - all: true needs: check-diff if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-cpp == 1 }} py: uses: ./.github/workflows/only-py.yml - with: - all: true needs: check-diff if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-py == 1 }} rs: uses: ./.github/workflows/only-rs.yml - with: - all: true needs: check-diff if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-rs == 1 }} ts: uses: ./.github/workflows/only-ts.yml - with: - all: true needs: check-diff if: ${{ !github.event.pull_request.draft || needs.check-diff.outputs.changed-ts == 1 }} diff --git a/.github/workflows/only-c.yml b/.github/workflows/only-c.yml index b353474e94..2d12dd9da8 100644 --- a/.github/workflows/only-c.yml +++ b/.github/workflows/only-c.yml @@ -3,10 +3,6 @@ name: C on: workflow_dispatch: workflow_call: - inputs: - all: - default: true - type: boolean env: # 2020.11 @@ -19,33 +15,28 @@ concurrency: jobs: # Run the C integration tests. default: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C benchmark tests. benchmarking: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: "C" # Run the C Arduino integration tests. arduino: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-arduino-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C Zephyr integration tests. zephyr: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-zephyr-tests.yml # Run the CCpp integration tests. ccpp: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/c-tests.yml with: use-cpp: true diff --git a/.github/workflows/only-cpp.yml b/.github/workflows/only-cpp.yml index d7b956742f..fdac226930 100644 --- a/.github/workflows/only-cpp.yml +++ b/.github/workflows/only-cpp.yml @@ -3,10 +3,6 @@ name: C++ on: workflow_dispatch: workflow_call: - inputs: - all: - default: true - type: boolean env: # 2020.11 @@ -19,19 +15,16 @@ concurrency: jobs: # Run the C++ benchmark tests. cpp-benchmark-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: "Cpp" # Run the C++ integration tests. cpp-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the C++ integration tests on ROS2. cpp-ros2-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/cpp-ros2-tests.yml diff --git a/.github/workflows/only-py.yml b/.github/workflows/only-py.yml index f07a9ef7a0..921b1cbae5 100644 --- a/.github/workflows/only-py.yml +++ b/.github/workflows/only-py.yml @@ -3,10 +3,6 @@ name: Python on: workflow_dispatch: workflow_call: - inputs: - all: - default: true - type: boolean env: # 2020.11 @@ -20,6 +16,5 @@ jobs: # Run the Python integration tests. py-tests: uses: ./.github/workflows/py-tests.yml - if: ${{ inputs.all || github.event.pull_request.draft }} with: all-platforms: ${{ !github.event.pull_request.draft }} diff --git a/.github/workflows/only-rs.yml b/.github/workflows/only-rs.yml index 412f1395ba..ef3f31e7d9 100644 --- a/.github/workflows/only-rs.yml +++ b/.github/workflows/only-rs.yml @@ -3,10 +3,6 @@ name: Rust on: workflow_dispatch: workflow_call: - inputs: - all: - default: true - type: boolean env: # 2020.11 @@ -19,14 +15,12 @@ concurrency: jobs: # Run the Rust integration tests. rs-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/rs-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} # Run the Rust benchmark tests. rs-benchmark-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: "Rust" diff --git a/.github/workflows/only-ts.yml b/.github/workflows/only-ts.yml index c842c14023..131c06ab17 100644 --- a/.github/workflows/only-ts.yml +++ b/.github/workflows/only-ts.yml @@ -3,10 +3,6 @@ name: TypeScript on: workflow_dispatch: workflow_call: - inputs: - all: - default: true - type: boolean env: # 2020.11 @@ -19,14 +15,12 @@ concurrency: jobs: # Run the TypeScript benchmark tests. benchmarking: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@gradle with: target: "TS" # Run the TypeScript integration tests. ts-tests: - if: ${{ inputs.all || github.event.pull_request.draft }} uses: ./.github/workflows/ts-tests.yml with: all-platforms: ${{ !github.event.pull_request.draft }} From e6b5f5822e8d473d56590234cd78ae6aee91bf7c Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 6 Jun 2023 22:18:04 -0700 Subject: [PATCH 688/709] Update all-misc.yml --- .github/workflows/all-misc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/all-misc.yml b/.github/workflows/all-misc.yml index c4022d444d..7efaee5131 100644 --- a/.github/workflows/all-misc.yml +++ b/.github/workflows/all-misc.yml @@ -8,6 +8,7 @@ on: - master pull_request: types: [synchronize, opened, reopened, ready_for_review, converted_to_draft] + merge_group: env: # 2020.11 From 1be54f08cc6121a94c04b19f416d30736808c812 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 6 Jun 2023 22:18:17 -0700 Subject: [PATCH 689/709] Update all-targets.yml --- .github/workflows/all-targets.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/all-targets.yml b/.github/workflows/all-targets.yml index 3768b37c50..bc740a36b9 100644 --- a/.github/workflows/all-targets.yml +++ b/.github/workflows/all-targets.yml @@ -8,6 +8,7 @@ on: - master pull_request: types: [synchronize, opened, reopened, ready_for_review, converted_to_draft] + merge_group: env: # 2020.11 From 4caa7e46c9a234cb69af2bc1b39da14a90b1a999 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 11:06:24 +0200 Subject: [PATCH 690/709] fix lff exception handling --- cli/lff/src/main/java/org/lflang/cli/Lff.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/cli/lff/src/main/java/org/lflang/cli/Lff.java b/cli/lff/src/main/java/org/lflang/cli/Lff.java index 3626bc1f1c..d7ef31e85c 100644 --- a/cli/lff/src/main/java/org/lflang/cli/Lff.java +++ b/cli/lff/src/main/java/org/lflang/cli/Lff.java @@ -157,24 +157,26 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { final String formattedFileContents = FormattingUtils.render(resource.getContents().get(0), lineLength); - if (dryRun) { - io.getOut().println(formattedFileContents); - io.getOut().println("\0"); - } else { - try { + try { + if (dryRun) { + io.getOut().println(formattedFileContents); + io.getOut().println("\0"); + } else { FileUtil.writeToFile(formattedFileContents, outputPath, true); - } catch (IOException e) { - if (e instanceof FileAlreadyExistsException) { - // Only happens if a subdirectory is named with - // ".lf" at the end. - reporter.printFatalErrorAndExit( - "Error writing to " - + outputPath - + ": file already exists. Make sure that no file or" - + " directory within provided input paths have the" - + " same relative paths."); - } } + } catch (FileAlreadyExistsException e) { + // Only happens if a subdirectory is named with + // ".lf" at the end. + reporter.printFatalErrorAndExit( + "Error writing to " + + outputPath + + ": file already exists. Make sure that no file or" + + " directory within provided input paths have the" + + " same relative paths."); + } catch (IOException e) { + reporter.printFatalErrorAndExit( + "An unknown I/O exception occurred while processing " + outputPath); + e.printStackTrace(); } if (!ignoreErrors) { From 50da8ec65521351c6db8e8609426a75b4a71d2c4 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 11:06:52 +0200 Subject: [PATCH 691/709] add method for comparing strings with file content --- .../main/java/org/lflang/util/FileUtil.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/lflang/util/FileUtil.java b/core/src/main/java/org/lflang/util/FileUtil.java index e46a30d501..23108c7375 100644 --- a/core/src/main/java/org/lflang/util/FileUtil.java +++ b/core/src/main/java/org/lflang/util/FileUtil.java @@ -869,6 +869,21 @@ public static IResource getIResource(java.net.URI uri) { return null; } + /** + * Check if the content of a file is equal to a given string. + * + * @param text The text to compare with. + * @param path The file to compare with. + * @return true, if the given text is identical to the file content. + */ + public static boolean isSame(String text, Path path) throws IOException { + if (Files.isRegularFile(path)) { + final byte[] bytes = text.getBytes(); + return Arrays.equals(bytes, Files.readAllBytes(path)); + } + return false; + } + /** * Write text to a file. * @@ -879,14 +894,10 @@ public static IResource getIResource(java.net.URI uri) { */ public static void writeToFile(String text, Path path, boolean skipIfUnchanged) throws IOException { - Files.createDirectories(path.getParent()); - final byte[] bytes = text.getBytes(); - if (skipIfUnchanged && Files.isRegularFile(path)) { - if (Arrays.equals(bytes, Files.readAllBytes(path))) { - return; - } + if (!skipIfUnchanged || !isSame(text, path)) { + Files.createDirectories(path.getParent()); + Files.write(path, text.getBytes()); } - Files.write(path, text.getBytes()); } /** From f41fefb1ef348145bd5a28495739df30c2249a06 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 11:52:09 +0200 Subject: [PATCH 692/709] keep track of errors in reporting util --- .../main/kotlin/org/lflang/cli/ReportingUtil.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt b/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt index eb700afd58..efdd0e731f 100644 --- a/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt +++ b/cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt @@ -204,6 +204,8 @@ class ReportingBackend constructor( /** *Absolute* path to lines. */ private val fileCache = mutableMapOf?>() + private var errorsOccurred = false + private fun getLines(path: Path?): List? = if (path == null) null else fileCache.computeIfAbsent(path.toAbsolutePath()) { @@ -225,16 +227,18 @@ class ReportingBackend constructor( io.callSystemExit(1) } - /** Print a fatal error message to [Io.err] and exit with code 1. */ + /** Print a fatal error message to [Io.err]. */ @JvmOverloads fun printFatalError(message: String, cause: Throwable? = null) { io.err.println(header + colors.redAndBold("fatal error: ") + colors.bold(message)) cause?.printStackTrace(io.err) + errorsOccurred = true } /** Print an error message to [Io.err]. */ fun printError(message: String) { io.err.println(header + colors.redAndBold("error: ") + message) + errorsOccurred = true } /** Print a warning message to [Io.err]. */ @@ -418,6 +422,16 @@ class ReportingBackend constructor( } } + + /** Exit and return an error code if any errors were reported. */ + fun exit() { + if (errorsOccurred) { + io.callSystemExit(1) + } else { + io.callSystemExit(0) + } + } + companion object { const val TAB_REPLACEMENT = " " const val FENCE_WIDTH = 14 From 9e46b80e3fe7ca4ac336b9f7385bcbfdc3ed956d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 11:54:05 +0200 Subject: [PATCH 693/709] add --check option --- cli/lff/src/main/java/org/lflang/cli/Lff.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cli/lff/src/main/java/org/lflang/cli/Lff.java b/cli/lff/src/main/java/org/lflang/cli/Lff.java index d7ef31e85c..0812680254 100644 --- a/cli/lff/src/main/java/org/lflang/cli/Lff.java +++ b/cli/lff/src/main/java/org/lflang/cli/Lff.java @@ -30,6 +30,12 @@ public class Lff extends CliBase { /** Supported CLI options for Lff. */ + @Option( + names = {"-c", "--check"}, + description = + "Check mode. Exit with an error code if any files would change when applying formatting.") + private boolean check = false; + @Option( names = {"-d", "--dry-run"}, description = @@ -80,6 +86,12 @@ public static void main(Io io, final String... args) { /** Validates all paths and invokes the formatter on the input paths. */ @Override public void doRun() { + if (check && dryRun) { + reporter.printFatalErrorAndExit( + "The options --check (-c) and --dry-run (-d) are mutually exclusive. Please use only one" + + " at a time."); + } + List paths; do { paths = getInputPaths(); @@ -97,6 +109,9 @@ public void doRun() { reporter.printFatalErrorAndExit("An unexpected error occurred:", e); } } while (stdinMode() && !paths.isEmpty()); + + // return an error code if any errors were reported + reporter.exit(); } /* @@ -122,7 +137,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { } }); } catch (IOException e) { - reporter.printError("IO error: " + e); + reporter.printFatalErrorAndExit("An unknown I/O exception occurred.", e); } } else { // Simple file. @@ -158,7 +173,11 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { FormattingUtils.render(resource.getContents().get(0), lineLength); try { - if (dryRun) { + if (check) { + if (!FileUtil.isSame(formattedFileContents, outputPath)) { + reporter.printError("Would reformat " + outputPath); + } + } else if (dryRun) { io.getOut().println(formattedFileContents); io.getOut().println("\0"); } else { @@ -175,8 +194,7 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { + " same relative paths."); } catch (IOException e) { reporter.printFatalErrorAndExit( - "An unknown I/O exception occurred while processing " + outputPath); - e.printStackTrace(); + "An unknown I/O exception occurred while processing " + outputPath, e); } if (!ignoreErrors) { From a63644082c044ecd49d55d28d3d4000bd76dc156 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 11:57:11 +0200 Subject: [PATCH 694/709] unify log output --- cli/lff/src/main/java/org/lflang/cli/Lff.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/lff/src/main/java/org/lflang/cli/Lff.java b/cli/lff/src/main/java/org/lflang/cli/Lff.java index 0812680254..21a72fad16 100644 --- a/cli/lff/src/main/java/org/lflang/cli/Lff.java +++ b/cli/lff/src/main/java/org/lflang/cli/Lff.java @@ -156,11 +156,13 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { ? path // Format in place. : outputRoot.resolve(inputRoot.relativize(path)).normalize(); + Path relativePath = io.getWd().relativize(path); + final Resource resource = getResource(path); // Skip file if not an LF file. if (resource == null) { if (verbose) { - reporter.printInfo("Skipped " + path + ": not an LF file"); + reporter.printInfo("Skipped " + relativePath + ": not an LF file"); } return; } @@ -205,7 +207,7 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { // the position of the issue may be wrong in the formatted file. // issueCollector.getAllIssues().forEach(reporter::printIssue); if (verbose) { - String msg = "Formatted " + io.getWd().relativize(path); + String msg = "Formatted " + relativePath; if (path != outputPath) { msg += " -> " + io.getWd().relativize(outputPath); } From 9f24abc7f9317f306c1484a0887aa6d526a890b1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 12:05:45 +0200 Subject: [PATCH 695/709] add unit tests --- .../test/java/org/lflang/cli/LffCliTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 9610d5b69c..444486344d 100644 --- a/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java +++ b/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java @@ -150,6 +150,26 @@ public void testOutputPathWithFileArg(@TempDir Path tempDir) throws IOException dirChecker(tempDir).checkContentsOf("out/File.lf", equalTo(FILE_AFTER_REFORMAT)); } + @Test + public void testCheckAndDryRun(@TempDir Path tempDir) { + lffTester.run(tempDir, "foo.lf", "--check", "--dry-run").checkFailed(); + lffTester.run(tempDir, "foo.lf", "-c", "-d").checkFailed(); + } + + @Test + public void testCheck(@TempDir Path tempDir) throws IOException { + dirBuilder(tempDir).file("src/a/File.lf", FILE_BEFORE_REFORMAT); + dirBuilder(tempDir).file("src/b/File.lf", FILE_AFTER_REFORMAT); + + lffTester.run(tempDir, "src/a/File.lf", "--check").checkFailed(); + lffTester.run(tempDir, "src/a/File.lf", "-c").checkFailed(); + lffTester.run(tempDir, "src/b/File.lf", "--check").checkOk(); + lffTester.run(tempDir, "src/b/File.lf", "-c").checkOk(); + + dirChecker(tempDir).checkContentsOf("src/a/File.lf", equalTo(FILE_BEFORE_REFORMAT)); + dirChecker(tempDir).checkContentsOf("src/b/File.lf", equalTo(FILE_AFTER_REFORMAT)); + } + static class LffTestFixture extends CliToolTestFixture { @Override From eccfc5cabf8d47985a32cdaa0d4af18bc963dc7e Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 7 Jun 2023 16:28:57 +0200 Subject: [PATCH 696/709] Update CI to use Zephyr v3.3.0 and SDK v0.16.1 --- .github/actions/setup-zephyr/action.yml | 16 ++++++++++------ .../org/lflang/generator/c/CCmakeGenerator.java | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index e77ac6c0e4..079692d180 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -3,6 +3,10 @@ description: Install Zephyr and dependencies (Linux only) runs: using: "composite" steps: + - name: Setup environment variables + run: | + echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV + echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV - name: Dependencies run: | sudo apt-get update && sudo apt-get upgrade @@ -16,20 +20,20 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing - sudo tar xf zephyr-sdk-0.15.2_linux-x86_64.tar.gz --directory /opt/ - cd /opt/zephyr-sdk-0.15.2 + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz" + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum | shasum --check --ignore-missing + sudo tar xf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz --directory /opt/ + cd /opt/zephyr-sdk-${SDK_VERSION} sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr v3.2.0 + west init zephyrproject --mr v${ZEPHYR_VERSION} cd zephyrproject west update west zephyr-export pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-0.15.2/" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${SDK_VERSION}/" >> $GITHUB_ENV shell: bash 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 860c85a75d..fd818b45a5 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -128,8 +128,8 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("# Selecting default board"); cMakeCode.pr("set(BOARD qemu_cortex_m3)"); } - cMakeCode.pr("# We require Zephyr version 3.2.0"); - cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.2.0)"); + cMakeCode.pr("# We recommend Zephyr v3.3.0 but we are compatible with older versions also"); + cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.3.0)"); cMakeCode.newLine(); } From b12bbb407b6ba7a9cf3ee78d68e2a8e00ac6592d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 7 Jun 2023 12:56:29 +0200 Subject: [PATCH 697/709] Bumped klighd version and removed unofficial repo Fix https://github.com/lf-lang/lingua-franca/issues/1615 --- buildSrc/src/main/groovy/org.lflang.java-conventions.gradle | 4 ---- gradle.properties | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle index a600ba4ef8..4cbea8bf20 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle @@ -5,10 +5,6 @@ plugins { repositories { mavenCentral() - // TODO Replace this unofficial maven repository as soon as Klighd is released to maven central in the future. - maven { - url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/" - } } spotless { diff --git a/gradle.properties b/gradle.properties index 8d2599bdf6..e294dedf05 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ openTest4jVersion=1.2.0 picocliVersion=4.7.0 resourcesVersion=3.16.0 xtextVersion=2.28.0 -klighdVersion=2.2.1-SNAPSHOT +klighdVersion=2.3.0.v20230606 [manifestPropertyNames] org.eclipse.xtext=xtextVersion From ec70b77bf738b06b2074d91ffe71a40b96f0c0fd Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 7 Jun 2023 17:31:29 +0200 Subject: [PATCH 698/709] Fix setup-zephyr action --- .github/actions/setup-zephyr/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 079692d180..1c0505adce 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -21,15 +21,15 @@ runs: - name: Install Zephyr SDK run : | wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz" - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum | shasum --check --ignore-missing - sudo tar xf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz --directory /opt/ - cd /opt/zephyr-sdk-${SDK_VERSION} + wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum" | shasum --check --ignore-missing + sudo tar xf "zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz" --directory /opt/ + cd "/opt/zephyr-sdk-${SDK_VERSION}" sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr v${ZEPHYR_VERSION} + west init zephyrproject --mr "v${ZEPHYR_VERSION}"" cd zephyrproject west update west zephyr-export From c990231496a88fc7356c5d7bc4c2f3852dabe163 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 7 Jun 2023 18:47:31 +0200 Subject: [PATCH 699/709] Set shell --- .github/actions/setup-zephyr/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 1c0505adce..6a9d9053c3 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -7,6 +7,7 @@ runs: run: | echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV + shell: bash - name: Dependencies run: | sudo apt-get update && sudo apt-get upgrade From 22be739671960ab9bb0584d887df0920ce7b385d Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:18:25 +0200 Subject: [PATCH 700/709] Try to use environment variable --- .github/actions/setup-zephyr/action.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 6a9d9053c3..14f213050b 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -1,13 +1,11 @@ name: Install Zephyr and dependencies (Linux only) description: Install Zephyr and dependencies (Linux only) +env: + SDK_VERSION: 0.16.1 + ZEPHYR_VERSION: 3.3.0 runs: using: "composite" steps: - - name: Setup environment variables - run: | - echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV - echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV - shell: bash - name: Dependencies run: | sudo apt-get update && sudo apt-get upgrade @@ -21,20 +19,20 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz" - wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum" | shasum --check --ignore-missing - sudo tar xf "zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz" --directory /opt/ - cd "/opt/zephyr-sdk-${SDK_VERSION}" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" + wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/sha256.sum" | shasum --check --ignore-missing + sudo tar xf "zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" --directory /opt/ + cd "/opt/zephyr-sdk-$SDK_VERSION" sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr "v${ZEPHYR_VERSION}"" + west init zephyrproject --mr "v$ZEPHYR_VERSION" cd zephyrproject west update west zephyr-export pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${SDK_VERSION}/" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-$SDK_VERSION/" >> $GITHUB_ENV shell: bash From ccecb6d636183df4e129347c9aec4eae24c4e8e2 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:27:13 +0200 Subject: [PATCH 701/709] CI --- .github/actions/setup-zephyr/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 14f213050b..4cb1a235d2 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -1,9 +1,9 @@ name: Install Zephyr and dependencies (Linux only) description: Install Zephyr and dependencies (Linux only) -env: - SDK_VERSION: 0.16.1 - ZEPHYR_VERSION: 3.3.0 runs: + env: + SDK_VERSION: 0.16.1 + ZEPHYR_VERSION: 3.3.0 using: "composite" steps: - name: Dependencies From b4f897d34b7b26403b2ce293e8113c69dc4743a1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:31:15 +0200 Subject: [PATCH 702/709] CI --- .github/actions/setup-zephyr/action.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 4cb1a235d2..cd3fac8492 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -1,9 +1,9 @@ name: Install Zephyr and dependencies (Linux only) description: Install Zephyr and dependencies (Linux only) +env: + SDK_VERSION: 0.16.1 + ZEPHYR_VERSION: 3.3.0 runs: - env: - SDK_VERSION: 0.16.1 - ZEPHYR_VERSION: 3.3.0 using: "composite" steps: - name: Dependencies @@ -19,20 +19,20 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" - wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/sha256.sum" | shasum --check --ignore-missing - sudo tar xf "zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" --directory /opt/ - cd "/opt/zephyr-sdk-$SDK_VERSION" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" + wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing + sudo tar xf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" --directory /opt/ + cd "/opt/zephyr-sdk-${{env.SDK_VERSION}}" sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr "v$ZEPHYR_VERSION" + west init zephyrproject --mr "v${{env.ZEPHYR_VERSION}}" cd zephyrproject west update west zephyr-export pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-$SDK_VERSION/" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{env.SDK_VERSION}}/" >> $GITHUB_ENV shell: bash From 53cac26efcc7c5134dc6d0d6846a048e00c8fd0a Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:39:24 +0200 Subject: [PATCH 703/709] More CI --- .github/actions/setup-zephyr/action.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index cd3fac8492..8105162409 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -19,20 +19,20 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" - wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing - sudo tar xf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" --directory /opt/ - cd "/opt/zephyr-sdk-${{env.SDK_VERSION}}" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{SDK_VERSION}}/zephyr-sdk-${{SDK_VERSION}}_linux-x86_64.tar.gz" + wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing + sudo tar xf "zephyr-sdk-${{SDK_VERSION}}_linux-x86_64.tar.gz" --directory /opt/ + cd "/opt/zephyr-sdk-${{SDK_VERSION}}" sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr "v${{env.ZEPHYR_VERSION}}" + west init zephyrproject --mr "v${{ZEPHYR_VERSION}}" cd zephyrproject west update west zephyr-export pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{env.SDK_VERSION}}/" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{SDK_VERSION}}/" >> $GITHUB_ENV shell: bash From 3ad09d616c434f65b6e656c2bf22a1e7d4282a47 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:44:52 +0200 Subject: [PATCH 704/709] Go back to using GITHUB_ENV --- .github/actions/setup-zephyr/action.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 8105162409..aa486e2f27 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -1,11 +1,13 @@ name: Install Zephyr and dependencies (Linux only) description: Install Zephyr and dependencies (Linux only) -env: - SDK_VERSION: 0.16.1 - ZEPHYR_VERSION: 3.3.0 runs: using: "composite" steps: + - name: Setup environment variables + run: | + echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV + echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV + shell: vash - name: Dependencies run: | sudo apt-get update && sudo apt-get upgrade @@ -19,20 +21,20 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{SDK_VERSION}}/zephyr-sdk-${{SDK_VERSION}}_linux-x86_64.tar.gz" - wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing - sudo tar xf "zephyr-sdk-${{SDK_VERSION}}_linux-x86_64.tar.gz" --directory /opt/ - cd "/opt/zephyr-sdk-${{SDK_VERSION}}" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" + wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/sha256.sum" | shasum --check --ignore-missing + sudo tar xf "zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" --directory /opt/ + cd "/opt/zephyr-sdk-$(SDK_VERSION)" sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr "v${{ZEPHYR_VERSION}}" + west init zephyrproject --mr "v$ZEPHYR_VERSION" cd zephyrproject west update west zephyr-export pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{SDK_VERSION}}/" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-$SDK_VERSION/" >> $GITHUB_ENV shell: bash From 265cf0298f66e8eaf29318a89f09b7717d56ddaa Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:48:28 +0200 Subject: [PATCH 705/709] CI --- .github/actions/setup-zephyr/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index aa486e2f27..4f43e09c55 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -7,7 +7,7 @@ runs: run: | echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV - shell: vash + shell: bash - name: Dependencies run: | sudo apt-get update && sudo apt-get upgrade From f806f4237c92cb51ed160c77d5ba1075d2250888 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:52:19 +0200 Subject: [PATCH 706/709] CI --- .github/actions/setup-zephyr/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 4f43e09c55..dfb69eede5 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -21,7 +21,7 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/zephyr-sdk-${{SDK_VERSION}}_linux-x86_64.tar.gz" wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/sha256.sum" | shasum --check --ignore-missing sudo tar xf "zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" --directory /opt/ cd "/opt/zephyr-sdk-$(SDK_VERSION)" From 24f6cde52421f5d0d04246d9b172262344d28205 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 00:56:02 +0200 Subject: [PATCH 707/709] CI --- .github/actions/setup-zephyr/action.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index dfb69eede5..68c57680a0 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -21,20 +21,20 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/zephyr-sdk-${{SDK_VERSION}}_linux-x86_64.tar.gz" - wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$SDK_VERSION/sha256.sum" | shasum --check --ignore-missing - sudo tar xf "zephyr-sdk-$SDK_VERSION_linux-x86_64.tar.gz" --directory /opt/ - cd "/opt/zephyr-sdk-$(SDK_VERSION)" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" + wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing + sudo tar xf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" --directory /opt/ + cd "/opt/zephyr-sdk-${{env.SDK_VERSION}}" sudo ./setup.sh -t all -h -c shell: bash - name: Download and install Zephyr RTOS run: | cd $HOME - west init zephyrproject --mr "v$ZEPHYR_VERSION" + west init zephyrproject --mr "v${{env.ZEPHYR_VERSION}}" cd zephyrproject west update west zephyr-export pip install -r zephyr/scripts/requirements.txt echo "ZEPHYR_BASE=$HOME/zephyrproject/zephyr" >> $GITHUB_ENV - echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-$SDK_VERSION/" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{env.SDK_VERSION}}/" >> $GITHUB_ENV shell: bash From 225293c8c39bd088f5dbc28e9b5af4c3725c8215 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 01:02:26 +0200 Subject: [PATCH 708/709] CI --- .github/actions/setup-zephyr/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 68c57680a0..32cd307172 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -21,9 +21,9 @@ runs: shell: bash - name: Install Zephyr SDK run : | - wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" + wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.xz" wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing - sudo tar xf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.gz" --directory /opt/ + sudo tar xvf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.xz" --directory /opt/ cd "/opt/zephyr-sdk-${{env.SDK_VERSION}}" sudo ./setup.sh -t all -h -c shell: bash From d1b278e63250e4fef0c5c96a5e0a96849c6491ba Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 7 Jun 2023 17:49:27 -0700 Subject: [PATCH 709/709] Fix error in programs with no main reactor. This error only occurs when using generics. It is possibly a sign that `ReactorInstance` is being used to do too many different things. It is a little problematic to have to put in a dummy value in order to get things to work. --- core/src/main/java/org/lflang/ast/ASTUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/ast/ASTUtils.java b/core/src/main/java/org/lflang/ast/ASTUtils.java index 078505d958..60b5538372 100644 --- a/core/src/main/java/org/lflang/ast/ASTUtils.java +++ b/core/src/main/java/org/lflang/ast/ASTUtils.java @@ -1711,10 +1711,14 @@ public static Instantiation createInstantiation(Reactor reactor) { } else { inst.setName(""); } - } else { inst.setName(reactor.getName()); } + for (int i = 0; i < reactor.getTypeParms().size(); i++) { + Type t = LfFactory.eINSTANCE.createType(); + t.setId("UNSPECIFIED_TYPE"); + inst.getTypeArgs().add(t); + } return inst; }